// File: /workspace/github_cpp_makefile_star2_O1/jstaursky[P]hutch/src/Sleigh/address.cc
// Function: power2Divide(int, unsigned long, unsigned long&, unsigned long&)
int4 power2Divide(int4 n,uint8 divisor,uint8 &q,uint8 &r)

{
  if (divisor == 0) return 2;
  uint8 power = 1;
  if (n < 64) {
    power <<= n;
    q = power / divisor;
    r = power % divisor;
    return 0;
  }
  // Divide numerand and divisor by 2^(n-63) to get approximation of result
  uint8 y = divisor >> (n-64);	// Most of the way on divisor
  if (y == 0) return 1;		// Check if result will be too big
  y >>= 1;			// Divide divisor by final bit
  power <<= 63;
  uint8 max;
  if (y == 0) {
    max = 0;
    max -= 1;			// Could be maximal
    // Check if divisor is a power of 2
    if ((((uint8)1) << (n-64)) == divisor)
      return 1;
  }
  else
    max = power / y + 1;
  uint8 min = power / (y+1);
  if (min != 0)
    min -= 1;
  uint8 fullpower[2];
  fullpower[1] = ((uint8)1)<<(n-64);
  fullpower[0] = 0;
  uint8 mult[2];
  mult[0] = 0;
  mult[1] = 0;
  uint8 tmpq = 0;
  while(max > min+1) {
    tmpq = max + min;
    if (tmpq < min) {
      tmpq = (tmpq>>1) + 0x8000000000000000L;
    }
    else
      tmpq >>= 1;
    mult64to128(mult,divisor,tmpq);
    if (unsignedCompare128(fullpower,mult) < 0)
      max = tmpq-1;
    else
      min = tmpq;
  }
  // min is now our putative quotient
  if (tmpq != min)
    mult64to128(mult,divisor,min);
  unsignedSubtract128(fullpower,mult); // Calculate remainder
  // min might be 1 too small
  if (fullpower[1] != 0 || fullpower[0] >= divisor) {
    q = min + 1;
    r = fullpower[0] - divisor;
  }
  else {
    q = min;
    r = fullpower[0];
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
testq %rsi, %rsi
je 0x44109
movq %rcx, %r8
movq %rdx, %r9
movl %edi, %ecx
cmpl $0x3f, %edi
jg 0x44110
movl $0x1, %eax
shlq %cl, %rax
xorl %edx, %edx
divq %rsi
movq %rax, (%r9)
movq %rdx, (%r8)
xorl %eax, %eax
jmp 0x44143
movl $0x2, %eax
jmp 0x44143
movq %rsi, %rdx
shrq %cl, %rdx
movl $0x1, %eax
testq %rdx, %rdx
je 0x44143
addl $-0x40, %ecx
movq %rdx, %r10
shrq %r10
cmpq $0x1, %rdx
jne 0x4414e
movl $0x1, %edx
shlq %cl, %rdx
movq $-0x1, %rdi
cmpq %rsi, %rdx
jne 0x44163
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
xorl %edx, %edx
divq %r10
movq %rax, %rdi
incq %rdi
incq %r10
xorl %ebx, %ebx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
xorl %edx, %edx
divq %r10
leaq -0x1(%rax), %r10
movl $0x1, %r11d
shlq %cl, %r11
cmpq %rax, %rdi
jbe 0x4422e
movl %esi, %edx
movq %rsi, %r14
shrq $0x20, %r14
leaq (%r10,%rdi), %rax
shrq %rax
movq %rax, %r15
btsq $0x3f, %r15
movq %r10, %rcx
addq %rdi, %rcx
cmovaeq %rax, %r15
movl %r15d, %ebx
movq %r15, %rax
shrq $0x20, %rax
movq %rbx, %r13
imulq %rdx, %r13
movq %rax, %r12
imulq %rdx, %r12
imulq %r14, %rbx
imulq %r14, %rax
movl %r13d, %ecx
shrq $0x20, %r13
movl %r12d, %ebp
addq %r13, %rbp
movl %ebx, %r13d
addq %rbp, %r13
movq %r13, %rbp
shrq $0x20, %rbp
shrq $0x20, %r12
addq %rax, %r12
shrq $0x20, %rbx
addq %r12, %rbx
addq %rbp, %rbx
shlq $0x20, %r13
xorl %eax, %eax
orq %r13, %rcx
setne %al
xorl %ebp, %ebp
cmpq %rbx, %r11
setb %bpl
cmovnel %ebp, %eax
testb %al, %al
jne 0x4421b
movq %r15, %r10
jmp 0x4421f
leaq -0x1(%r15), %rdi
leaq 0x1(%r10), %rax
cmpq %rax, %rdi
ja 0x44196
jmp 0x44233
xorl %ecx, %ecx
xorl %r15d, %r15d
cmpq %r10, %r15
je 0x44290
movl %esi, %edx
movq %rsi, %rcx
shrq $0x20, %rcx
movl %r10d, %ebx
movq %r10, %rdi
shrq $0x20, %rdi
movq %rbx, %r14
imulq %rdx, %r14
imulq %rdi, %rdx
imulq %rcx, %rbx
imulq %rcx, %rdi
movl %r14d, %ecx
shrq $0x20, %r14
movl %edx, %r15d
addq %r14, %r15
movl %ebx, %r14d
addq %r15, %r14
movq %r14, %r15
shrq $0x20, %r15
shrq $0x20, %rdx
addq %rdi, %rdx
shrq $0x20, %rbx
addq %rdx, %rbx
addq %r15, %rbx
shlq $0x20, %r14
orq %r14, %rcx
xorl %edi, %edi
negq %rcx
sbbq %rdi, %rdi
movq %rcx, %rdx
subq %rsi, %rdx
jae 0x440ff
subq %rbx, %rdi
negq %r11
cmpq %r11, %rdi
jne 0x440ff
movq %r10, (%r9)
movq %rcx, %rdx
jmp 0x44102