// File: /workspace/github_cpp_makefile_star2_O3/marxn[P]pupp/3rdparty/gmp/mpn/mu_div_q.c
// Function: _gmpn_mu_div_q
mp_limb_t
mpn_mu_div_q (mp_ptr qp,
	      mp_srcptr np, mp_size_t nn,
	      mp_srcptr dp, mp_size_t dn,
	      mp_ptr scratch)
{
  mp_ptr tp, rp;
  mp_size_t qn;
  mp_limb_t cy, qh;
  TMP_DECL;

  TMP_MARK;

  qn = nn - dn;

  tp = TMP_BALLOC_LIMBS (qn + 1);

  if (qn >= dn)			/* nn >= 2*dn + 1 */
    {
       /* |_______________________|   dividend
			 |________|   divisor  */

      rp = TMP_BALLOC_LIMBS (nn + 1);
      MPN_COPY (rp + 1, np, nn);
      rp[0] = 0;

      qh = mpn_cmp (rp + 1 + nn - dn, dp, dn) >= 0;
      if (qh != 0)
	mpn_sub_n (rp + 1 + nn - dn, rp + 1 + nn - dn, dp, dn);

      cy = mpn_mu_divappr_q (tp, rp, nn + 1, dp, dn, scratch);

      if (UNLIKELY (cy != 0))
	{
	  /* Since the partial remainder fed to mpn_preinv_mu_divappr_q was
	     canonically reduced, replace the returned value of B^(qn-dn)+eps
	     by the largest possible value.  */
	  mp_size_t i;
	  for (i = 0; i < qn + 1; i++)
	    tp[i] = GMP_NUMB_MAX;
	}

      /* The max error of mpn_mu_divappr_q is +4.  If the low quotient limb is
	 smaller than the max error, we cannot trust the quotient.  */
      if (tp[0] > 4)
	{
	  MPN_COPY (qp, tp + 1, qn);
	}
      else
	{
	  mp_limb_t cy;
	  mp_ptr pp;

	  pp = rp;
	  mpn_mul (pp, tp + 1, qn, dp, dn);

	  cy = (qh != 0) ? mpn_add_n (pp + qn, pp + qn, dp, dn) : 0;

	  if (cy || mpn_cmp (pp, np, nn) > 0) /* At most is wrong by one, no cycle. */
	    qh -= mpn_sub_1 (qp, tp + 1, qn, 1);
	  else /* Same as above */
	    MPN_COPY (qp, tp + 1, qn);
	}
    }
  else
    {
       /* |_______________________|   dividend
		 |________________|   divisor  */

      /* FIXME: When nn = 2dn-1, qn becomes dn-1, and the numerator size passed
	 here becomes 2dn, i.e., more than nn.  This shouldn't hurt, since only
	 the most significant dn-1 limbs will actually be read, but it is not
	 pretty.  */

      qh = mpn_mu_divappr_q (tp, np + nn - (2 * qn + 2), 2 * qn + 2,
			     dp + dn - (qn + 1), qn + 1, scratch);

      /* The max error of mpn_mu_divappr_q is +4, but we get an additional
         error from the divisor truncation.  */
      if (tp[0] > 6)
	{
	  MPN_COPY (qp, tp + 1, qn);
	}
      else
	{
	  mp_limb_t cy;

	  /* FIXME: a shorter product should be enough; we may use already
	     allocated space... */
	  rp = TMP_BALLOC_LIMBS (nn);
	  mpn_mul (rp, dp, dn, tp + 1, qn);

	  cy = (qh != 0) ? mpn_add_n (rp + qn, rp + qn, dp, dn) : 0;

	  if (cy || mpn_cmp (rp, np, nn) > 0) /* At most is wrong by one, no cycle. */
	    qh -= mpn_sub_1 (qp, tp + 1, qn, 1);
	  else /* Same as above */
	    MPN_COPY (qp, tp + 1, qn);
	}
    }

  TMP_FREE;
  return qh;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %rbp
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, 0x48(%rsp)
movq %rdi, %rbx
leaq 0x38(%rsp), %rdi
movq $0x0, (%rdi)
movq %rdx, %r12
subq %r8, %r12
leaq 0x8(,%r12,8), %rsi
callq 0x2fdb0
cmpq %r14, %r12
movq %rax, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
jge 0x2eb51
movq %rax, %rdi
leaq 0x1(%r12), %r8
movq 0x48(%rsp), %rbx
leaq (%rbx,%r13,8), %rax
leaq 0x2(,%r12,2), %rdx
movq %r12, %rsi
notq %rsi
leaq (%r15,%r14,8), %rcx
leaq (%rcx,%rsi,8), %rcx
shlq $0x4, %rsi
addq %rax, %rsi
movq %rbp, %r9
callq 0x2e348
movq 0x18(%rsp), %rdx
movq %rax, %rbp
cmpq $0x7, (%rdx)
jb 0x2ec05
addq $0x8, %rdx
movq 0x20(%rsp), %rdi
movq %rdx, %rsi
movq %r12, %rdx
callq 0x2f106
jmp 0x2ef18
movq %rbp, 0x30(%rsp)
leaq 0x1(%r13), %rax
movq %rax, 0x50(%rsp)
leaq 0x8(,%r13,8), %rsi
leaq 0x38(%rsp), %rdi
callq 0x2fdb0
movq %r13, %rbp
movq %rax, %r13
leaq 0x8(%rax), %rdi
movq 0x48(%rsp), %rbx
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2f106
movq $0x0, (%r13)
leaq 0x8(,%rbp,8), %rdi
addq %r13, %rdi
leaq (,%r14,8), %rax
subq %rax, %rdi
movq %rbp, 0x10(%rsp)
leaq (,%rbp,8), %rax
addq %r13, %rax
movq %r14, %rcx
movq %r14, %rbp
movq %r12, %r14
testq %rcx, %rcx
jle 0x2ebe1
movq (%rax), %rdx
movq -0x8(%r15,%rcx,8), %rsi
decq %rcx
addq $-0x8, %rax
cmpq %rsi, %rdx
je 0x2ebc2
jbe 0x2ed2f
movq %rdi, %rsi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x1bca0
movb $0x1, %al
movq %rax, 0x40(%rsp)
movl $0x1, %eax
movq %rax, 0x8(%rsp)
jmp 0x2ed41
movq %r13, 0x10(%rsp)
leaq (,%r13,8), %rsi
leaq 0x38(%rsp), %rdi
callq 0x2fdb0
movq %r14, %r13
movq %rbp, %r14
movq %rax, %rbp
movq 0x18(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rcx, 0x30(%rsp)
movq %r12, %r8
callq 0x1c838
movq %r14, 0x8(%rsp)
testq %r14, %r14
movq %r13, %r14
movq 0x20(%rsp), %r13
je 0x2ec74
leaq (,%r12,8), %rdi
addq %rbp, %rdi
movq %rdi, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1ba80
testq %rax, %rax
jne 0x2ec9b
movq 0x10(%rsp), %rax
testq %rax, %rax
jle 0x2ee83
movq -0x8(%rbx,%rax,8), %rcx
leaq -0x1(%rax), %rdx
cmpq %rcx, -0x8(%rbp,%rax,8)
movq %rdx, %rax
je 0x2ec79
jbe 0x2ee83
movq 0x30(%rsp), %rdi
movq (%rdi), %rax
subq $0x1, %rax
movq %rax, (%r13)
jae 0x2ee9a
cmpq $0x2, %r12
movl $0x1, %ecx
cmovgeq %r12, %rcx
decq %rcx
xorl %edx, %edx
movq 0x8(%rsp), %rbp
movq 0x18(%rsp), %r8
cmpq %rdx, %rcx
je 0x2eed1
movq 0x10(%r8,%rdx,8), %rsi
leaq 0x1(%rdx), %rax
subq $0x1, %rsi
movq %rsi, 0x8(%r13,%rdx,8)
movq %rax, %rdx
jb 0x2eccd
cmpq %r13, %rdi
setne %cl
leaq 0x1(%rax), %rdx
cmpq %r12, %rdx
setl %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2ef13
leaq 0x8(,%rax,8), %rdi
addq %r13, %rdi
leaq (%r8,%rax,8), %rsi
addq $0x10, %rsi
notq %r14
addq 0x10(%rsp), %r14
subq %rax, %r14
shlq $0x3, %r14
jmp 0x2eecc
movq $0x0, 0x8(%rsp)
movq $0x0, 0x40(%rsp)
movq %rbp, %r8
movq 0x18(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
movq 0x50(%rsp), %rbp
movq %rbp, %rdx
movq %r15, %rcx
movq %r8, 0x28(%rsp)
movq 0x30(%rsp), %r9
callq 0x2e348
testq %rax, %rax
jne 0x2ef3b
leaq 0x8(%r12), %rbp
cmpq $0x5, (%r12)
jb 0x2ed8e
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
movq %r14, %rdx
jmp 0x2ee8e
movq %r13, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movq %r15, %rcx
movq 0x28(%rsp), %r12
movq %r12, %r8
callq 0x1c838
cmpb $0x0, 0x40(%rsp)
je 0x2edcc
leaq (,%r14,8), %rdi
addq %r13, %rdi
movq %rdi, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x1ba80
testq %rax, %rax
jne 0x2edeb
movq 0x10(%rsp), %rax
testq %rax, %rax
jle 0x2ed7e
movq -0x8(%rbx,%rax,8), %rcx
leaq -0x1(%rax), %rdx
cmpq %rcx, -0x8(%r13,%rax,8)
movq %rdx, %rax
je 0x2edd1
jbe 0x2ed7e
movq (%rbp), %rax
subq $0x1, %rax
movq 0x20(%rsp), %rdi
movq %rax, (%rdi)
jae 0x2eeda
movq %rbp, %r10
cmpq $0x2, %r14
movl $0x1, %ecx
movq %r14, %r9
cmovgeq %r14, %rcx
decq %rcx
xorl %edx, %edx
movq 0x8(%rsp), %rbp
movq 0x18(%rsp), %r8
cmpq %rdx, %rcx
je 0x2eed1
movq 0x10(%r8,%rdx,8), %rsi
leaq 0x1(%rdx), %rax
subq $0x1, %rsi
movq %rsi, 0x8(%rdi,%rdx,8)
movq %rax, %rdx
jb 0x2ee23
cmpq %rdi, %r10
setne %cl
leaq 0x1(%rax), %rdx
cmpq %r9, %rdx
setl %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2ef13
leaq (%rdi,%rax,8), %rdi
addq $0x8, %rdi
leaq (%r8,%rax,8), %rsi
addq $0x10, %rsi
movq 0x28(%rsp), %rdx
notq %rdx
addq 0x10(%rsp), %rdx
subq %rax, %rdx
jmp 0x2ef0a
movq %r13, %rdi
movq 0x30(%rsp), %rsi
movq %r12, %rdx
callq 0x2f106
movq 0x8(%rsp), %rbp
jmp 0x2ef18
cmpq %r13, %rdi
sete %al
cmpq $0x2, %r12
setl %cl
orb %al, %cl
movq 0x8(%rsp), %rbp
movq 0x18(%rsp), %rsi
jne 0x2ef13
addq $0x8, %r13
addq $0x10, %rsi
notq %r14
addq 0x10(%rsp), %r14
shlq $0x3, %r14
movq %r13, %rdi
movq %r14, %rdx
jmp 0x2ef0e
movq $-0x1, %rax
jmp 0x2ef15
cmpq %rdi, %rbp
sete %al
cmpq $0x2, %r14
setl %cl
orb %al, %cl
movq 0x8(%rsp), %rbp
movq 0x18(%rsp), %rsi
jne 0x2ef13
addq $0x8, %rdi
addq $0x10, %rsi
movq 0x28(%rsp), %rdx
notq %rdx
addq 0x10(%rsp), %rdx
shlq $0x3, %rdx
callq 0x6200
xorl %eax, %eax
addq %rax, %rbp
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
jne 0x2ef34
movq %rbp, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2fde3
jmp 0x2ef22
testq %r14, %r14
js 0x2ed72
subq 0x28(%rsp), %rbp
shlq $0x3, %rbp
movq %r12, %rdi
movl $0xff, %esi
movq %rbp, %rdx
callq 0x6170
jmp 0x2ed72