// File: /workspace/github_cpp_makefile_star2_O1/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, 0x20(%rsp)
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %rbx
leaq 0x40(%rsp), %rdi
movq $0x0, (%rdi)
movq %rdx, %r12
subq %r8, %r12
leaq 0x8(,%r12,8), %rsi
movq %rsi, 0x50(%rsp)
callq 0x30170
movq %rax, 0x38(%rsp)
cmpq %r14, %r12
movq %rbx, 0x28(%rsp)
movq %rbp, 0x30(%rsp)
jge 0x2ef28
leaq 0x1(%r12), %r8
leaq (,%r13,8), %rax
addq %rbp, %rax
leaq 0x2(%r12,%r12), %rdx
movq %r12, %rsi
notq %rsi
leaq (%r15,%r14,8), %rcx
leaq (%rcx,%rsi,8), %rcx
shlq $0x4, %rsi
addq %rax, %rsi
movq 0x38(%rsp), %rbp
movq %rbp, %rdi
movq 0x20(%rsp), %r9
callq 0x2e6f8
movq %r14, %rbx
movq %rax, %r14
cmpq $0x7, (%rbp)
jb 0x2f00a
addq $0x8, %rbp
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x2f4c6
jmp 0x2f2bb
leaq 0x1(%r13), %rax
movq %rax, 0x48(%rsp)
leaq 0x8(,%r13,8), %rsi
leaq 0x40(%rsp), %rdi
callq 0x30170
movq %rax, %rbx
leaq 0x8(%rax), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x2f4c6
movq $0x0, (%rbx)
leaq (%rbx,%r13,8), %rdi
addq $0x8, %rdi
leaq (,%r14,8), %rax
subq %rax, %rdi
movq %r13, 0x10(%rsp)
leaq (%rbx,%r13,8), %rax
movq %r14, %rcx
movq 0x38(%rsp), %rbp
movq 0x20(%rsp), %r13
movq %r14, 0x18(%rsp)
testq %rcx, %rcx
jle 0x2efa9
movq -0x8(%r15,%rcx,8), %rdx
decq %rcx
leaq -0x8(%rax), %rsi
cmpq %rdx, (%rax)
movq %rsi, %rax
je 0x2ef8a
seta %r14b
jmp 0x2efac
movb $0x1, %r14b
testb %r14b, %r14b
je 0x2efc1
movq %rdi, %rsi
movq %r15, %rdx
movq 0x18(%rsp), %rcx
callq 0x1c1c0
movzbl %r14b, %eax
movq %rax, 0x8(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
movq 0x48(%rsp), %rdx
movq %r15, %rcx
movq 0x18(%rsp), %r8
movq %r13, %r9
callq 0x2e6f8
testq %rax, %rax
jne 0x2f2de
leaq 0x8(%rbp), %r14
cmpq $0x5, (%rbp)
jb 0x2f12e
movq 0x28(%rsp), %rdi
movq %r14, %rsi
jmp 0x2f22f
movq %r13, 0x10(%rsp)
leaq (,%r13,8), %rsi
leaq 0x40(%rsp), %rdi
callq 0x30170
movq %rax, %r13
leaq 0x8(%rbp), %rcx
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %rcx, 0x20(%rsp)
movq %r12, %r8
callq 0x1cd58
movq %r14, 0x8(%rsp)
testq %r14, %r14
movq 0x28(%rsp), %rbp
movq 0x30(%rsp), %rsi
je 0x2f075
leaq (,%r12,8), %rdi
addq %r13, %rdi
movq %rdi, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x1bfa0
movq 0x30(%rsp), %rsi
testq %rax, %rax
jne 0x2f09c
movq 0x10(%rsp), %rax
testq %rax, %rax
jle 0x2f227
movq -0x8(%rsi,%rax,8), %rcx
leaq -0x1(%rax), %rdx
cmpq %rcx, -0x8(%r13,%rax,8)
movq %rdx, %rax
je 0x2f07a
jbe 0x2f227
movq 0x20(%rsp), %rdi
movq (%rdi), %rax
subq $0x1, %rax
movq %rax, (%rbp)
jae 0x2f23e
cmpq $0x2, %r12
movl $0x1, %ecx
cmovgeq %r12, %rcx
decq %rcx
xorl %edx, %edx
movq 0x10(%rsp), %r8
movq 0x38(%rsp), %r9
cmpq %rdx, %rcx
je 0x2f273
movq 0x10(%r9,%rdx,8), %rsi
leaq 0x1(%rdx), %rax
subq $0x1, %rsi
movq %rsi, 0x8(%rbp,%rdx,8)
movq %rax, %rdx
jb 0x2f0ce
cmpq %rbp, %rdi
setne %cl
leaq 0x1(%rax), %rdx
cmpq %r12, %rdx
setl %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2f2b1
leaq 0x8(,%rax,8), %rdi
addq %rbp, %rdi
leaq (%r9,%rax,8), %rsi
addq $0x10, %rsi
notq %rbx
addq %r8, %rbx
subq %rax, %rbx
shlq $0x3, %rbx
jmp 0x2f26e
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq 0x18(%rsp), %r8
callq 0x1cd58
cmpq $0x0, 0x8(%rsp)
movq 0x30(%rsp), %rsi
je 0x2f16f
leaq (%rbx,%r12,8), %rdi
movq %rdi, %rsi
movq %r15, %rdx
movq 0x18(%rsp), %rcx
callq 0x1bfa0
movq 0x30(%rsp), %rsi
testq %rax, %rax
jne 0x2f196
movq 0x10(%rsp), %rax
testq %rax, %rax
jle 0x2effd
movq -0x8(%rsi,%rax,8), %rcx
leaq -0x1(%rax), %rdx
cmpq %rcx, -0x8(%rbx,%rax,8)
movq %rdx, %rax
je 0x2f174
jbe 0x2effd
movq (%r14), %rax
subq $0x1, %rax
movq 0x28(%rsp), %rdi
movq %rax, (%rdi)
jae 0x2f27c
cmpq $0x2, %r12
movl $0x1, %ecx
cmovgeq %r12, %rcx
decq %rcx
xorl %edx, %edx
movq 0x10(%rsp), %r8
cmpq %rdx, %rcx
je 0x2f273
movq 0x10(%rbp,%rdx,8), %rsi
leaq 0x1(%rdx), %rax
subq $0x1, %rsi
movq %rsi, 0x8(%rdi,%rdx,8)
movq %rax, %rdx
jb 0x2f1c2
cmpq %rdi, %r14
setne %cl
leaq 0x1(%rax), %rdx
cmpq %r12, %rdx
setl %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2f2b1
leaq (%rdi,%rax,8), %rdi
addq $0x8, %rdi
leaq 0x10(,%rax,8), %rsi
addq %rbp, %rsi
movq 0x18(%rsp), %rdx
notq %rdx
addq %r8, %rdx
subq %rax, %rdx
shlq $0x3, %rdx
jmp 0x2f2ac
movq %rbp, %rdi
movq 0x20(%rsp), %rsi
movq %r12, %rdx
callq 0x2f4c6
movq 0x8(%rsp), %r14
jmp 0x2f2bb
cmpq %rbp, %rdi
sete %al
cmpq $0x2, %r12
setl %cl
orb %al, %cl
movq 0x10(%rsp), %rax
movq 0x38(%rsp), %rsi
jne 0x2f2b1
addq $0x8, %rbp
addq $0x10, %rsi
notq %rbx
addq %rax, %rbx
shlq $0x3, %rbx
movq %rbp, %rdi
movq %rbx, %rdx
jmp 0x2f2ac
movq $-0x1, %rax
jmp 0x2f2b3
cmpq %rdi, %r14
sete %al
cmpq $0x2, %r12
setl %cl
orb %al, %cl
movq 0x10(%rsp), %rax
jne 0x2f2b1
addq $0x8, %rdi
addq $0x10, %rbp
movq 0x18(%rsp), %rdx
notq %rdx
addq %rax, %rdx
shlq $0x3, %rdx
movq %rbp, %rsi
callq 0x6200
xorl %eax, %eax
movq 0x8(%rsp), %r14
addq %rax, %r14
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
jne 0x2f2d7
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x301a3
jmp 0x2f2c5
testq %r12, %r12
js 0x2efee
movq %rbp, %rdi
movl $0xff, %esi
movq 0x50(%rsp), %rdx
callq 0x6170
jmp 0x2efee