Mostly portable 128 by 64 bit division
The original code seemed too complicated for this so I set out to write a simpler version. Should be fairly portable too, and fast as it is just bit shifts and subtraction.

(It works similarly to how one would accomplish division in assembly language on a processor without hardware division.)

// 128-bit / 64-bit unsigned divide

#include &lt;stdio.h&gt;
#include &lt;stdint.h&gt;

int main(void)
{
  // numerator
  uint64_t a_lo = 1234567;
  uint64_t a_hi = 0;

  // denominator
  uint64_t b = 10;

  // quotient
  uint64_t q = a_lo &lt;&lt; 1;

  // remainder
  uint64_t rem = a_hi;

  uint64_t carry = a_lo &gt;&gt; 63;
  uint64_t temp_carry = 0;
  int i;

  for(i = 0; i &lt; 64; i++)
  {
    temp_carry = rem &gt;&gt; 63;
    rem &lt;&lt;= 1;
    rem |= carry;
    carry = temp_carry;

    if(carry == 0)
    {
      if(rem &gt;= b)
      {
        carry = 1;
      }
      else
      {
        temp_carry = q &gt;&gt; 63;
        q &lt;&lt;= 1;
        q |= carry;
        carry = temp_carry;
        continue;
      }
    }

    rem -= b;
    rem -= (1 - carry);
    carry = 1;
    temp_carry = q &gt;&gt; 63;
    q &lt;&lt;= 1;
    q |= carry;
    carry = temp_carry;
  }

  printf("quotient = %llu\n", (long long unsigned int)q);
  printf("remainder = %llu\n", (long long unsigned int)rem);
  return 0;
}