// File: /workspace/github_cpp_makefile_star2_O1/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 %r8, %r9
movq %rdx, %r8
movq %rdi, -0x70(%rbp)
movq %rdx, %r12
subq %r9, %r12
leaq (%rcx,%r9,8), %rdi
cmpq %r9, %r12
jge 0x2d8a6
leaq (%rsi,%r8,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 0x2d995
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 0x2d600
jmp 0x2d9ac
movq %rdi, -0x58(%rbp)
movq %r10, -0x68(%rbp)
incq %r12
leaq (,%r9,8), %r11
leaq -0x8(,%r9,8), %rax
leaq (%r9,%r9), %rdx
movq %rdx, -0x88(%rbp)
movq %rsi, -0x78(%rbp)
leaq (%rsi,%r9,8), %rdx
movq %r8, -0x50(%rbp)
leaq (,%r8,8), %rdi
movq %r9, %r10
shlq $0x4, %r10
movq %rdi, %r8
subq %r10, %r8
addq $0x10, %r8
xorl %r14d, %r14d
movq %rdx, -0x60(%rbp)
xorl %r13d, %r13d
subq %r9, %r13
leaq (%r12,%r13), %r15
addq %r11, %r14
addq %r11, %rdx
subq %r10, %r8
cmpq %r9, %r15
jg 0x2d8fb
movq -0x70(%rbp), %rsi
leaq (%rsi,%r14), %r12
addq $-0x8, %r12
movq %rsp, %rbx
leaq 0xf(,%r9,8), %rsi
andq $-0x10, %rsi
subq %rsi, %rbx
movq %rbx, -0x80(%rbp)
movq %rbx, %rsp
cmpq $0x2, %r15
movq %r9, -0x48(%rbp)
movq %rcx, -0x38(%rbp)
movq %r11, -0x40(%rbp)
movq %r12, -0x90(%rbp)
je 0x2d9c7
cmpq $0x1, %r15
jne 0x2d9ef
movq -0x78(%rbp), %rsi
leaq (%rsi,%r14), %rdi
leaq (%rsi,%r14), %rbx
addq $-0x8, %rbx
addq %rcx, %rax
xorl %r10d, %r10d
leaq (%r9,%r10), %rsi
testq %rsi, %rsi
jle 0x2da26
movq (%rax,%r10,8), %rsi
leaq -0x1(%r10), %r8
cmpq %rsi, -0x8(%rdx,%r10,8)
movq %r8, %r10
je 0x2d96e
seta %al
jmp 0x2da28
leaq (%rax,%rdx,8), %rsi
addq $-0x10, %rsi
leaq (%r8,%r8), %rdx
movq (%r10), %r9
movq %rbx, %rdi
callq 0x2c274
movq %rax, %r14
addq $0x8, %rbx
movq -0x70(%rbp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2f4c6
jmp 0x2ddd3
movq -0x60(%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 0x1cc20
jmp 0x2dbc1
movq -0x78(%rbp), %rsi
subq %r8, %rsi
cmpq $0x32, %r15
jle 0x2db9d
subq %rdi, %r10
addq %rcx, %r10
leaq (%r14,%r10), %rdx
addq $-0x8, %rdx
movq %r12, %rdi
movq %r15, %rcx
movq -0x68(%rbp), %r8
movq -0x80(%rbp), %r9
callq 0x2cd28
jmp 0x2dbc1
movb $0x1, %al
movq %rbx, -0x50(%rbp)
movzbl %al, %eax
movq %rax, -0x30(%rbp)
testb %al, %al
je 0x2da51
movq %rdi, %rsi
movq %rcx, %rdx
movq %r9, %rcx
callq 0x1c1c0
movq -0x40(%rbp), %r11
movq -0x38(%rbp), %rcx
movq -0x48(%rbp), %r9
movq -0x60(%rbp), %rax
movq -0x8(%rax,%r14), %rdi
movq -0x18(%rax,%r14), %r15
movq -0x10(%rax,%r14), %rbx
movq -0x58(%rbp), %rax
movq -0x10(%rax), %r12
movq -0x8(%rax), %r8
cmpq %r8, %rdi
je 0x2dde5
movq -0x68(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
movq %rdi, %rax
mulq -0xf0(%rbp)
movq %rax, %rsi
movq %rdx, %r10
movq %rdi, -0xe8(%rbp)
movq %rbx, -0xe0(%rbp)
addq -0xe0(%rbp), %rsi
adcq -0xe8(%rbp), %r10
movq %r10, %rax
imulq %r8, %rax
subq %rax, %rbx
movq %r8, -0xd8(%rbp)
movq %r12, -0xd0(%rbp)
subq -0xd0(%rbp), %r15
sbbq -0xd8(%rbp), %rbx
movq %r10, -0xc8(%rbp)
movq %r12, %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, %r10
xorl %eax, %eax
cmpq %rsi, %rbx
movl $0x0, %edx
cmovaeq %r8, %rdx
cmovaeq %r12, %rax
incq %r10
movq %rdx, -0xb0(%rbp)
movq %rax, -0xa8(%rbp)
addq -0xa8(%rbp), %r15
adcq -0xb0(%rbp), %rbx
cmpq %r8, %rbx
jae 0x2de1c
cmpq $0x3, %r9
jl 0x2dce6
movq %r8, -0x88(%rbp)
leaq -0x2(%r9), %rdx
movq -0x50(%rbp), %r12
movq %r12, %rdi
movq %rcx, %rsi
movq %r10, -0x58(%rbp)
movq %r10, %rcx
callq 0x30370
subq %rax, %r15
sbbq $0x0, %rbx
movq -0x60(%rbp), %rcx
movq %r15, -0x18(%rcx,%r14)
jb 0x2de51
movq -0x48(%rbp), %r9
movq -0x40(%rbp), %r11
movq -0x30(%rbp), %r15
movq -0x58(%rbp), %r10
jmp 0x2dcf3
leaq (%r15,%r15), %rdx
subq %rdi, %r10
addq %rcx, %r10
leaq (%r14,%r10), %rcx
addq $-0x8, %rcx
movq -0x68(%rbp), %rax
movq (%rax), %r9
movq %r12, %rdi
movq %r15, %r8
callq 0x2bf54
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rax
notq %rax
addq -0x88(%rbp), %rax
subq %r13, %rax
jne 0x2dbe5
movq -0x48(%rbp), %r9
movq -0x40(%rbp), %r11
jmp 0x2dce0
cmpq %rax, %r15
movq -0x80(%rbp), %rbx
movq %rax, -0x50(%rbp)
movq %rbx, %rdi
jle 0x2dc04
movq %r12, %rsi
movq %r15, %rdx
movq -0x38(%rbp), %rcx
movq %rax, %r8
jmp 0x2dc11
movq -0x38(%rbp), %rsi
movq %rax, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x1cd58
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 0x1c1c0
movq %rax, %rbx
cmpq $0x0, -0x30(%rbp)
je 0x2dc55
leaq (%r12,%r15,8), %rdi
movq %rdi, %rsi
movq -0x38(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq 0x1c1c0
addq %rax, %rbx
movq -0x40(%rbp), %r11
testq %rbx, %rbx
movq -0x48(%rbp), %r9
je 0x2dce0
movq -0x70(%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 -0x70(%rbp), %rax
subq $0x1, -0x8(%rax,%r14)
movq %r12, %rdi
jae 0x2dcb4
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
movq -0x38(%rbp), %rdx
subq $0x1, %rax
jb 0x2dcbc
subq $0x1, (%rcx)
leaq 0x8(%rcx), %rcx
jb 0x2dca0
xorl %eax, %eax
jmp 0x2dcc3
xorl %eax, %eax
movq -0x38(%rbp), %rdx
jmp 0x2dcc3
movq $-0x1, %rax
addq %rax, %r15
movq %rdi, %rsi
movq %r9, %rcx
callq 0x1bfa0
movq -0x48(%rbp), %r9
subq %rax, %rbx
movq -0x40(%rbp), %r11
jne 0x2dc85
jmp 0x2dd01
movq -0x30(%rbp), %r15
jmp 0x2dd01
movq -0x60(%rbp), %rcx
movq %r15, -0x18(%rcx,%r14)
movq -0x30(%rbp), %r15
movq %rbx, -0x10(%rcx,%r14)
movq -0x70(%rbp), %rax
movq %r10, -0x8(%rax,%r14)
movq %r15, -0x30(%rbp)
negq %r13
cmpq %r9, %r13
jle 0x2dd69
movq -0x78(%rbp), %rax
leaq (%rax,%r14), %rbx
addq $-0x8, %rbx
movq %r11, %r14
negq %r14
movq -0x38(%rbp), %rdx
movq -0x68(%rbp), %r12
movq -0x90(%rbp), %r15
addq %r14, %r15
addq %r14, %rbx
movq %r15, %rdi
movq %rbx, %rsi
movq %r9, %rcx
movq %r12, %r8
movq -0x80(%rbp), %r9
callq 0x2cd28
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %r9
subq %r9, %r13
cmpq %r9, %r13
jg 0x2dd2e
movq %r15, -0x90(%rbp)
movq -0x40(%rbp), %r11
addq %r11, %rbx
jmp 0x2dd79
movq -0x60(%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
subq %r11, %rbx
movq (%r12), %rax
movq %rax, -0x38(%rbp)
subq %r11, %rbx
movq %r15, %rdi
movq %rbx, %rsi
movq %r9, %rcx
movq -0x68(%rbp), %r8
movq -0x80(%rbp), %r9
callq 0x2d600
leaq (%r12,%r14,8), %rsi
addq $0x8, %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x2f4c6
movq -0x38(%rbp), %rax
movq %rax, (%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 %r12, %rbx
jne 0x2da79
movq -0x50(%rbp), %rdi
movq %rcx, %rsi
movq %r9, %rdx
movq $-0x1, %rcx
callq 0x30370
movq $-0x1, %r10
movq -0x40(%rbp), %r11
movq -0x48(%rbp), %r9
movq -0x30(%rbp), %r15
jmp 0x2dcf8
setbe %al
cmpq %r12, %r15
setb %dl
testb %dl, %al
jne 0x2db47
incq %r10
movq %r12, -0x98(%rbp)
movq %r8, -0xa0(%rbp)
subq -0x98(%rbp), %r15
sbbq -0xa0(%rbp), %rbx
jmp 0x2db47
movq -0x48(%rbp), %r15
leaq -0x1(%r15), %rcx
movq %r12, %rdi
movq %r12, %rsi
movq -0x38(%rbp), %rdx
callq 0x1bfa0
movq -0x60(%rbp), %rcx
movq %r15, %r9
addq -0x88(%rbp), %rbx
addq %rax, %rbx
movq -0x58(%rbp), %r10
subq $0x1, %r10
movq -0x30(%rbp), %r15
sbbq $0x0, %r15
movq -0x40(%rbp), %r11
jmp 0x2dcf3
nop