// File: /workspace/github_cpp_makefile_star2_O3/marxn[P]pupp/3rdparty/gmp/mpn/dcpi1_divappr_q.c
// Function: _gmpn_dcpi1_divappr_q
mp_limb_t
mpn_dcpi1_divappr_q (mp_ptr qp, mp_ptr np, mp_size_t nn,
		     mp_srcptr dp, mp_size_t dn, gmp_pi1_t *dinv)
{
  mp_size_t qn;
  mp_limb_t qh, cy, qsave;
  mp_ptr tp;
  TMP_DECL;

  TMP_MARK;

  ASSERT (dn >= 6);
  ASSERT (nn > dn);
  ASSERT (dp[dn-1] & GMP_NUMB_HIGHBIT);

  qn = nn - dn;
  qp += qn;
  np += nn;
  dp += dn;

  if (qn >= dn)
    {
      qn++;			/* pretend we'll need an extra limb */
      /* Reduce qn mod dn without division, optimizing small operations.  */
      do
	qn -= dn;
      while (qn > dn);

      qp -= qn;			/* point at low limb of next quotient block */
      np -= qn;			/* point in the middle of partial remainder */

      tp = TMP_SALLOC_LIMBS (dn);

      /* Perform the typically smaller block first.  */
      if (qn == 1)
	{
	  mp_limb_t q, n2, n1, n0, d1, d0;

	  /* Handle qh up front, for simplicity. */
	  qh = mpn_cmp (np - dn + 1, dp - dn, dn) >= 0;
	  if (qh)
	    ASSERT_NOCARRY (mpn_sub_n (np - dn + 1, np - dn + 1, dp - dn, dn));

	  /* A single iteration of schoolbook: One 3/2 division,
	     followed by the bignum update and adjustment. */
	  n2 = np[0];
	  n1 = np[-1];
	  n0 = np[-2];
	  d1 = dp[-1];
	  d0 = dp[-2];

	  ASSERT (n2 < d1 || (n2 == d1 && n1 <= d0));

	  if (UNLIKELY (n2 == d1) && n1 == d0)
	    {
	      q = GMP_NUMB_MASK;
	      cy = mpn_submul_1 (np - dn, dp - dn, dn, q);
	      ASSERT (cy == n2);
	    }
	  else
	    {
	      udiv_qr_3by2 (q, n1, n0, n2, n1, n0, d1, d0, dinv->inv32);

	      if (dn > 2)
		{
		  mp_limb_t cy, cy1;
		  cy = mpn_submul_1 (np - dn, dp - dn, dn - 2, q);

		  cy1 = n0 < cy;
		  n0 = (n0 - cy) & GMP_NUMB_MASK;
		  cy = n1 < cy1;
		  n1 = (n1 - cy1) & GMP_NUMB_MASK;
		  np[-2] = n0;

		  if (UNLIKELY (cy != 0))
		    {
		      n1 += d1 + mpn_add_n (np - dn, np - dn, dp - dn, dn - 1);
		      qh -= (q == 0);
		      q = (q - 1) & GMP_NUMB_MASK;
		    }
		}
	      else
		np[-2] = n0;

	      np[-1] = n1;
	    }
	  qp[0] = q;
	}
      else
	{
	  if (qn == 2)
	    qh = mpn_divrem_2 (qp, 0L, np - 2, 4, dp - 2);
	  else if (BELOW_THRESHOLD (qn, DC_DIV_QR_THRESHOLD))
	    qh = mpn_sbpi1_div_qr (qp, np - qn, 2 * qn, dp - qn, qn, dinv->inv32);
	  else
	    qh = mpn_dcpi1_div_qr_n (qp, np - qn, dp - qn, qn, dinv, tp);

	  if (qn != dn)
	    {
	      if (qn > dn - qn)
		mpn_mul (tp, qp, qn, dp - dn, dn - qn);
	      else
		mpn_mul (tp, dp - dn, dn - qn, qp, qn);

	      cy = mpn_sub_n (np - dn, np - dn, tp, dn);
	      if (qh != 0)
		cy += mpn_sub_n (np - dn + qn, np - dn + qn, dp - dn, dn - qn);

	      while (cy != 0)
		{
		  qh -= mpn_sub_1 (qp, qp, qn, 1);
		  cy -= mpn_add_n (np - dn, np - dn, dp - dn, dn);
		}
	    }
	}
      qn = nn - dn - qn + 1;
      while (qn > dn)
	{
	  qp -= dn;
	  np -= dn;
	  mpn_dcpi1_div_qr_n (qp, np - dn, dp - dn, dn, dinv, tp);
	  qn -= dn;
	}

      /* Since we pretended we'd need an extra quotient limb before, we now
	 have made sure the code above left just dn-1=qn quotient limbs to
	 develop.  Develop that plus a guard limb. */
      qn--;
      qp -= qn;
      np -= dn;
      qsave = qp[qn];
      mpn_dcpi1_divappr_q_n (qp, np - dn, dp - dn, dn, dinv, tp);
      MPN_COPY_INCR (qp, qp + 1, qn);
      qp[qn] = qsave;
    }
  else    /* (qn < dn) */
    {
      mp_ptr q2p;
#if 0				/* not possible since we demand nn > dn */
      if (qn == 0)
	{
	  qh = mpn_cmp (np - dn, dp - dn, dn) >= 0;
	  if (qh)
	    mpn_sub_n (np - dn, np - dn, dp - dn, dn);
	  TMP_FREE;
	  return qh;
	}
#endif

      qp -= qn;			/* point at low limb of next quotient block */
      np -= qn;			/* point in the middle of partial remainder */

      q2p = TMP_SALLOC_LIMBS (qn + 1);
      /* Should we at all check DC_DIVAPPR_Q_THRESHOLD here, or reply on
	 callers not to be silly?  */
      if (BELOW_THRESHOLD (qn, DC_DIVAPPR_Q_THRESHOLD))
	{
	  qh = mpn_sbpi1_divappr_q (q2p, np - qn - 2, 2 * (qn + 1),
				    dp - (qn + 1), qn + 1, dinv->inv32);
	}
      else
	{
	  /* It is tempting to use qp for recursive scratch and put quotient in
	     tp, but the recursive scratch needs one limb too many.  */
	  tp = TMP_SALLOC_LIMBS (qn + 1);
	  qh = mpn_dcpi1_divappr_q_n (q2p, np - qn - 2, dp - (qn + 1), qn + 1, dinv, tp);
	}
      MPN_COPY (qp, q2p + 1, qn);
    }

  TMP_FREE;
  return qh;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r9, %r10
movq %rdx, %r9
movq %rdi, -0x60(%rbp)
movq %rdx, %r12
subq %r8, %r12
leaq (%rcx,%r8,8), %rdi
cmpq %r8, %r12
jge 0x2d4df
leaq (%rsi,%r9,8), %rax
movq %r12, %rdx
negq %rdx
leaq (,%r12,8), %rcx
subq %rcx, %rax
leaq 0x1(%r12), %r8
movq %rsp, %rbx
leaq 0x17(,%r12,8), %rcx
andq $-0x10, %rcx
subq %rcx, %rbx
movq %rbx, %rsp
movq %r12, %rcx
notq %rcx
leaq (%rdi,%rcx,8), %rcx
cmpq $0x107, %r12            # imm = 0x107
jle 0x2d5eb
leaq 0x8(,%r12,8), %rsi
movq %rsp, %r9
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r9
movq %r9, %rsp
leaq (%rax,%rdx,8), %rsi
addq $-0x10, %rsi
movq %rbx, %rdi
movq %rcx, %rdx
movq %r8, %rcx
movq %r10, %r8
callq 0x2d23c
jmp 0x2d602
movq %rdi, -0x58(%rbp)
movq %r10, -0x70(%rbp)
incq %r12
leaq (,%r8,8), %r11
leaq -0x8(,%r8,8), %rax
leaq (%r8,%r8), %rdx
movq %rdx, -0x88(%rbp)
movq %rsi, -0x78(%rbp)
leaq (%rsi,%r8,8), %rdx
movq %r9, -0x50(%rbp)
leaq (,%r9,8), %rdi
movq %r8, %r10
shlq $0x4, %r10
movq %rdi, %r9
subq %r10, %r9
addq $0x10, %r9
xorl %r14d, %r14d
movq %rdx, -0x68(%rbp)
xorl %r13d, %r13d
subq %r8, %r13
leaq (%r12,%r13), %r15
addq %r11, %r14
addq %r11, %rdx
subq %r10, %r9
cmpq %r8, %r15
jg 0x2d534
movq -0x60(%rbp), %rsi
leaq (%rsi,%r14), %r12
addq $-0x8, %r12
movq %rsp, %rbx
leaq 0xf(,%r8,8), %rsi
andq $-0x10, %rsi
subq %rsi, %rbx
movq %rbx, -0x80(%rbp)
movq %rbx, %rsp
cmpq $0x2, %r15
movq %r8, -0x48(%rbp)
movq %rcx, -0x38(%rbp)
movq %r11, -0x40(%rbp)
movq %r12, -0x90(%rbp)
je 0x2d61d
cmpq $0x1, %r15
jne 0x2d642
movq -0x78(%rbp), %rsi
leaq (%rsi,%r14), %rdi
leaq (%rsi,%r14), %r11
addq $-0x8, %r11
addq %rcx, %rax
xorl %r10d, %r10d
movq %r11, -0x50(%rbp)
leaq (%r8,%r10), %rsi
testq %rsi, %rsi
jle 0x2d5cf
movq -0x8(%rdx,%r10,8), %rsi
movq (%rax,%r10,8), %r9
decq %r10
cmpq %r9, %rsi
je 0x2d5af
jbe 0x2d7c2
movq %rdi, %rsi
movq %rcx, %rdx
movq %r8, %rcx
callq 0x1bca0
movl $0x1, %eax
movq %rax, -0x30(%rbp)
jmp 0x2d7ca
leaq (%rax,%rdx,8), %rsi
addq $-0x10, %rsi
leaq (%r8,%r8), %rdx
movq (%r10), %r9
movq %rbx, %rdi
callq 0x2be5c
movq %rax, %r14
addq $0x8, %rbx
movq -0x60(%rbp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2f106
jmp 0x2da07
movq -0x68(%rbp), %rax
leaq (%rax,%r14), %rdx
addq $-0x18, %rdx
movq -0x58(%rbp), %r8
addq $-0x10, %r8
movl $0x4, %ecx
movq %r12, %rdi
xorl %esi, %esi
callq 0x1c700
jmp 0x2d696
movq -0x78(%rbp), %rsi
subq %r9, %rsi
cmpq $0x32, %r15
jle 0x2d672
subq %rdi, %r10
addq %rcx, %r10
leaq (%r14,%r10), %rdx
addq $-0x8, %rdx
movq %r12, %rdi
movq %r15, %rcx
movq -0x70(%rbp), %r8
movq -0x80(%rbp), %r9
callq 0x2c91c
jmp 0x2d696
leaq (%r15,%r15), %rdx
subq %rdi, %r10
addq %rcx, %r10
leaq (%r14,%r10), %rcx
addq $-0x8, %rcx
movq -0x70(%rbp), %rax
movq (%rax), %r9
movq %r12, %rdi
movq %r15, %r8
callq 0x2bb38
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %r8
notq %r8
addq -0x88(%rbp), %r8
subq %r13, %r8
jne 0x2d6ba
movq -0x48(%rbp), %r8
movq -0x40(%rbp), %rdi
jmp 0x2d7b9
cmpq %r8, %r15
movq -0x80(%rbp), %rbx
movq %r8, -0x50(%rbp)
movq %rbx, %rdi
jle 0x2d6d6
movq %r12, %rsi
movq %r15, %rdx
movq -0x38(%rbp), %rcx
jmp 0x2d6e3
movq -0x38(%rbp), %rsi
movq %r8, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x1c838
movq -0x78(%rbp), %rax
leaq (%rax,%r14), %r12
addq $-0x8, %r12
movq %r12, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq -0x48(%rbp), %rcx
callq 0x1bca0
movq %rax, %rbx
cmpq $0x0, -0x30(%rbp)
je 0x2d727
leaq (%r12,%r15,8), %rdi
movq %rdi, %rsi
movq -0x38(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq 0x1bca0
addq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rbx, %rbx
movq -0x48(%rbp), %r8
je 0x2d7b9
movq -0x60(%rbp), %rax
addq %r14, %rax
movq %rax, -0x50(%rbp)
cmpq $0x2, %r15
movl $0x1, %eax
cmovgeq %r15, %rax
decq %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %r15
movq -0x60(%rbp), %rax
subq $0x1, -0x8(%rax,%r14)
movq %r12, %rdi
jae 0x2d78a
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
movq -0x38(%rbp), %rdx
subq $0x1, %rax
jb 0x2d792
subq $0x1, (%rcx)
leaq 0x8(%rcx), %rcx
jb 0x2d776
xorl %eax, %eax
jmp 0x2d799
xorl %eax, %eax
movq -0x38(%rbp), %rdx
jmp 0x2d799
movq $-0x1, %rax
addq %rax, %r15
movq %rdi, %rsi
movq %r8, %rcx
callq 0x1ba80
movq -0x48(%rbp), %r8
subq %rax, %rbx
movq -0x40(%rbp), %rdi
jne 0x2d75b
jmp 0x2d933
movq -0x30(%rbp), %r15
jmp 0x2d933
movq $0x0, -0x30(%rbp)
movq -0x68(%rbp), %rax
movq -0x8(%rax,%r14), %rdi
movq -0x18(%rax,%r14), %r15
movq -0x10(%rax,%r14), %rbx
movq -0x58(%rbp), %rax
movq -0x10(%rax), %rcx
movq -0x8(%rax), %r10
cmpq %r10, %rdi
je 0x2da19
movq -0x70(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
movq %rdi, %rax
mulq -0xf0(%rbp)
movq %rax, %rsi
movq %rdx, %r9
movq %rdi, -0xe8(%rbp)
movq %rbx, -0xe0(%rbp)
addq -0xe0(%rbp), %rsi
adcq -0xe8(%rbp), %r9
movq %r9, %rax
imulq %r10, %rax
subq %rax, %rbx
movq %r10, -0xd8(%rbp)
movq %rcx, -0xd0(%rbp)
subq -0xd0(%rbp), %r15
sbbq -0xd8(%rbp), %rbx
movq %r9, -0xc8(%rbp)
movq %rcx, %rax
mulq -0xc8(%rbp)
movq %rdx, -0xc0(%rbp)
movq %rax, -0xb8(%rbp)
subq -0xb8(%rbp), %r15
sbbq -0xc0(%rbp), %rbx
cmpq %rsi, %rbx
adcq $-0x1, %r9
xorl %eax, %eax
cmpq %rsi, %rbx
movl $0x0, %edx
cmovaeq %r10, %rdx
cmovaeq %rcx, %rax
incq %r9
movq %rdx, -0xb0(%rbp)
movq %rax, -0xa8(%rbp)
addq -0xa8(%rbp), %r15
adcq -0xb0(%rbp), %rbx
cmpq %r10, %rbx
movq -0x48(%rbp), %r8
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdi
jae 0x2da54
cmpq $0x3, %r8
jl 0x2d918
movq %r10, -0x88(%rbp)
leaq -0x2(%r8), %rdx
movq -0x50(%rbp), %r12
movq %r12, %rdi
movq %r9, -0x58(%rbp)
movq %r9, %rcx
callq 0x2ffb0
subq %rax, %r15
sbbq $0x0, %rbx
movq -0x68(%rbp), %rcx
movq %r15, -0x18(%rcx,%r14)
jb 0x2da89
movq -0x48(%rbp), %r8
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %r15
movq -0x58(%rbp), %r9
jmp 0x2d925
movq -0x68(%rbp), %rcx
movq %r15, -0x18(%rcx,%r14)
movq -0x30(%rbp), %r15
movq %rbx, -0x10(%rcx,%r14)
movq -0x60(%rbp), %rax
movq %r9, -0x8(%rax,%r14)
movq %r15, -0x30(%rbp)
negq %r13
movq %r8, %rcx
negq %rcx
cmpq %r8, %r13
jle 0x2d9a6
movq %rcx, -0x60(%rbp)
movq -0x78(%rbp), %rax
leaq (%rax,%r14), %rbx
addq $-0x8, %rbx
movq %rdi, %r14
negq %r14
movq -0x38(%rbp), %rdx
movq -0x70(%rbp), %r12
movq -0x90(%rbp), %r15
addq %r14, %r15
addq %r14, %rbx
movq %r15, %rdi
movq %rbx, %rsi
movq %r8, %rcx
movq %r12, %r8
movq -0x80(%rbp), %r9
callq 0x2c91c
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %r8
subq %r8, %r13
cmpq %r8, %r13
jg 0x2d96a
movq %r15, -0x90(%rbp)
addq -0x40(%rbp), %rbx
movq -0x60(%rbp), %rcx
jmp 0x2d9b6
movq -0x68(%rbp), %rax
leaq (%rax,%r14), %rbx
addq $-0x8, %rbx
movq -0x38(%rbp), %rdx
movl $0x1, %r14d
subq %r13, %r14
decq %r13
movq -0x90(%rbp), %r12
leaq (%r12,%r14,8), %r15
leaq (%rbx,%rcx,8), %rax
movq (%r12), %rbx
leaq (%rax,%rcx,8), %rsi
movq %r15, %rdi
movq %r8, %rcx
movq -0x70(%rbp), %r8
movq -0x80(%rbp), %r9
callq 0x2d23c
leaq (%r12,%r14,8), %rsi
addq $0x8, %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x2f106
movq %rbx, (%r12)
movq -0x30(%rbp), %r14
movq %r14, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq %rcx, %rbx
jne 0x2d7f2
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rbx
movq %rbx, %rdx
movq $-0x1, %rcx
callq 0x2ffb0
movq $-0x1, %r9
movq %rbx, %r8
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %r15
jmp 0x2d92a
setbe %al
cmpq %rcx, %r15
setb %dl
testb %dl, %al
jne 0x2d8cc
incq %r9
movq %rcx, -0x98(%rbp)
movq %r10, -0xa0(%rbp)
subq -0x98(%rbp), %r15
sbbq -0xa0(%rbp), %rbx
jmp 0x2d8cc
movq -0x48(%rbp), %r15
leaq -0x1(%r15), %rcx
movq %r12, %rdi
movq %r12, %rsi
movq -0x38(%rbp), %rdx
callq 0x1ba80
movq -0x68(%rbp), %rcx
movq %r15, %r8
addq -0x88(%rbp), %rbx
addq %rax, %rbx
movq -0x58(%rbp), %r9
subq $0x1, %r9
movq -0x30(%rbp), %r15
sbbq $0x0, %r15
movq -0x40(%rbp), %rdi
jmp 0x2d925
nop