// File: /workspace/github_cpp_makefile_star2_O2/marxn[P]pupp/3rdparty/gmp/mpn/dcpi1_div_qr.c
// Function: _gmpn_dcpi1_div_qr
mp_limb_t
mpn_dcpi1_div_qr (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;
  mp_ptr tp;
  TMP_DECL;

  TMP_MARK;

  ASSERT (dn >= 6);		/* to adhere to mpn_sbpi1_div_qr's limits */
  ASSERT (nn - dn >= 3);	/* to adhere to mpn_sbpi1_div_qr's limits */
  ASSERT (dp[dn-1] & GMP_NUMB_HIGHBIT);

  tp = TMP_ALLOC_LIMBS (dn);

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

  if (qn > dn)
    {
      /* 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 */

      /* 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
	{
	  /* Do a 2qn / qn division */
	  if (qn == 2)
	    qh = mpn_divrem_2 (qp, 0L, np - 2, 4, dp - 2); /* FIXME: obsolete function. Use 5/3 division? */
	  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;
      do
	{
	  qp -= dn;
	  np -= dn;
	  mpn_dcpi1_div_qr_n (qp, np - dn, dp - dn, dn, dinv, tp);
	  qn -= dn;
	}
      while (qn > 0);
    }
  else
    {
      qp -= qn;			/* point at low limb of next quotient block */
      np -= qn;			/* point in the middle of partial remainder */

      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);
	    }
	}
    }

  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, %r14
movq %r8, %rbx
movq %rcx, %r13
movq %rdx, %r15
andq $0x0, -0x90(%rbp)
movq %rsi, %r10
movq %rdi, -0x50(%rbp)
leaq (,%r8,8), %r12
cmpq $0x7f00, %r12           # imm = 0x7F00
ja 0x2768d
movq %rsp, %r9
leaq 0xf(%r12), %rax
andq $-0x10, %rax
subq %rax, %r9
movq %r9, %rsp
movq %r14, -0x68(%rbp)
movq %r15, %r14
subq %rbx, %r14
leaq (,%rbx,8), %rdi
addq %r13, %rdi
cmpq %r14, %rbx
movq %r9, -0x70(%rbp)
movq %r13, -0x30(%rbp)
jge 0x273a1
movq %rdi, -0x80(%rbp)
movq %rbx, %rcx
shlq $0x4, %rcx
leaq (%r15,%r15), %rdx
leaq (%rbx,%rbx), %r11
subq %r11, %rdx
movq %r15, -0x58(%rbp)
leaq (,%r15,8), %rax
movq %rax, %rdi
subq %rcx, %rdi
xorl %r15d, %r15d
xorl %r8d, %r8d
addq %r12, %r8
subq %rbx, %r15
leaq (%r14,%r15), %r13
subq %r11, %rdx
subq %rcx, %rdi
cmpq %rbx, %r13
jg 0x271dc
movq -0x50(%rbp), %rsi
addq %r8, %rsi
movq %rsi, -0x40(%rbp)
addq %r10, %r12
cmpq $0x2, %r13
movq %r8, -0x48(%rbp)
movq %rbx, -0x88(%rbp)
je 0x2741c
cmpq $0x1, %r13
jne 0x27446
movq %r12, -0x78(%rbp)
movq %r10, %r13
leaq (%r10,%r8), %r14
addq $0x8, %r14
movq %r14, %rdi
movq -0x30(%rbp), %r12
movq %r12, %rsi
movq %rbx, %rdx
callq 0x1ac5c
xorl %ecx, %ecx
testl %eax, %eax
setns %cl
movq %rcx, -0x38(%rbp)
js 0x2725d
movq %r14, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x17ed0
movq -0x48(%rbp), %r8
movq %r13, %rdi
addq %r8, %rdi
movq -0x78(%rbp), %r12
movq (%r12,%r8), %r9
movq -0x10(%r8,%r12), %r14
movq -0x8(%r8,%r12), %r13
movq -0x80(%rbp), %rax
movq -0x10(%rax), %rcx
movq -0x8(%rax), %r11
cmpq %r11, %r9
je 0x276b3
movq -0x68(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
movq %r9, %rax
mulq -0xf0(%rbp)
movq %rax, %rsi
movq %rdx, %r10
movq %r9, -0xe8(%rbp)
movq %r13, -0xe0(%rbp)
addq -0xe0(%rbp), %rsi
adcq -0xe8(%rbp), %r10
movq %r10, %rax
imulq %r11, %rax
subq %rax, %r13
movq %r11, -0xd8(%rbp)
movq %rcx, -0xd0(%rbp)
subq -0xd0(%rbp), %r14
sbbq -0xd8(%rbp), %r13
movq %r10, -0xc8(%rbp)
movq %rcx, %rax
mulq -0xc8(%rbp)
movq %rdx, -0xc0(%rbp)
movq %rax, -0xb8(%rbp)
subq -0xb8(%rbp), %r14
sbbq -0xc0(%rbp), %r13
cmpq %rsi, %r13
adcq $-0x1, %r10
xorl %eax, %eax
cmpq %rsi, %r13
movl $0x0, %edx
cmovaeq %r11, %rdx
cmovaeq %rcx, %rax
incq %r10
movq %rdx, -0xb0(%rbp)
movq %rax, -0xa8(%rbp)
addq -0xa8(%rbp), %r14
adcq -0xb0(%rbp), %r13
cmpq %r11, %r13
jae 0x276db
cmpq $0x3, %rbx
jl 0x27608
movq %r11, -0x58(%rbp)
leaq -0x2(%rbx), %rdx
movq -0x30(%rbp), %rsi
movq %r10, -0x40(%rbp)
movq %r10, %rcx
movq %rdi, -0x60(%rbp)
callq 0x29f90
movq -0x48(%rbp), %r8
subq %rax, %r14
sbbq $0x0, %r13
movq %r14, -0x10(%r12,%r8)
jb 0x27710
movq -0x40(%rbp), %r10
jmp 0x2760d
leaq (%r10,%r15,8), %r15
movq %r14, %rax
negq %rax
leaq (,%r14,8), %rcx
subq %rcx, %r15
movq %r15, %rsi
subq %rcx, %rsi
cmpq $0x32, %r14
jle 0x273d8
leaq (%rdi,%rax,8), %rdx
movq -0x50(%rbp), %rdi
movq %r14, %rcx
movq -0x68(%rbp), %r8
callq 0x26ef0
jmp 0x273f3
leaq (%r14,%r14), %rdx
leaq (%rdi,%rax,8), %rcx
movq -0x68(%rbp), %rax
movq (%rax), %r9
movq -0x50(%rbp), %rdi
movq %r14, %r8
callq 0x26308
movq %rax, -0x38(%rbp)
movq %rbx, %r13
subq %r14, %r13
je 0x2766b
cmpq %r13, %r14
jle 0x27482
movq -0x70(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq %r14, %rdx
movq -0x30(%rbp), %rcx
movq %r13, %r8
jmp 0x27494
movq %r11, %r14
movq %r10, -0x60(%rbp)
leaq (%r8,%r12), %rdx
addq $-0x10, %rdx
movq -0x80(%rbp), %r8
addq $-0x10, %r8
pushq $0x4
popq %rcx
movq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x18920
jmp 0x27528
movq %r11, %r14
movq %r10, -0x60(%rbp)
subq %rdi, %r10
subq %rax, %rcx
cmpq $0x32, %r13
jle 0x27508
movq -0x30(%rbp), %rax
addq %r8, %rax
addq %rax, %rcx
movq -0x40(%rbp), %rdi
movq %r10, %rsi
movq %rcx, %rdx
movq %r13, %rcx
movq -0x68(%rbp), %r8
callq 0x26ef0
jmp 0x27528
movq -0x70(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq %r13, %rdx
movq -0x50(%rbp), %rcx
movq %r14, %r8
callq 0x18a58
subq %r12, %r15
movq %r15, %rdi
movq %r15, %rsi
movq -0x70(%rbp), %rdx
movq %rbx, %rcx
callq 0x17ed0
movq %rax, %r12
cmpq $0x0, -0x38(%rbp)
je 0x274ce
leaq (%r15,%r14,8), %rdi
movq %rdi, %rsi
movq -0x30(%rbp), %rdx
movq %r13, %rcx
callq 0x17ed0
addq %rax, %r12
pushq $0x1
popq %r13
testq %r12, %r12
je 0x2766b
movq -0x50(%rbp), %rdi
movq %rdi, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x17e44
subq %rax, -0x38(%rbp)
movq %r15, %rdi
movq %r15, %rsi
movq -0x30(%rbp), %rdx
movq %rbx, %rcx
callq 0x17cf0
subq %rax, %r12
jmp 0x274d2
movq -0x30(%rbp), %rax
addq %r8, %rax
addq %rax, %rcx
movq -0x68(%rbp), %rax
movq (%rax), %r9
movq -0x40(%rbp), %rdi
movq %r10, %rsi
movq %r13, %r8
callq 0x26308
movq %rax, -0x38(%rbp)
movq %r14, %r8
subq -0x58(%rbp), %r8
subq %r15, %r8
jne 0x27544
negq %rbx
movq -0x48(%rbp), %r8
jmp 0x2761d
cmpq %r8, %r13
movq -0x70(%rbp), %r14
movq %r12, -0x78(%rbp)
movq %r8, -0x58(%rbp)
movq %r14, %rdi
jle 0x27565
movq -0x40(%rbp), %rsi
movq %r13, %rdx
movq -0x30(%rbp), %rcx
jmp 0x27573
movq -0x30(%rbp), %rsi
movq %r8, %rdx
movq -0x40(%rbp), %rcx
movq %r13, %r8
callq 0x18a58
movq -0x60(%rbp), %r12
addq -0x48(%rbp), %r12
movq %r12, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x17ed0
movq %rax, %r14
cmpq $0x0, -0x38(%rbp)
je 0x275b2
leaq (%r12,%r13,8), %rdi
movq %rdi, %rsi
movq -0x30(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x17ed0
addq %rax, %r14
negq %rbx
movq %rbx, -0x58(%rbp)
movq -0x38(%rbp), %rbx
movq -0x48(%rbp), %r8
testq %r14, %r14
je 0x275fa
movq -0x40(%rbp), %rdi
movq %rdi, %rsi
movq %r13, %rdx
pushq $0x1
popq %rcx
callq 0x17e44
subq %rax, %rbx
movq %r12, %rdi
movq %r12, %rsi
movq -0x30(%rbp), %rdx
movq -0x88(%rbp), %rcx
callq 0x17cf0
movq -0x48(%rbp), %r8
subq %rax, %r14
jmp 0x275c1
movq %rbx, -0x38(%rbp)
movq -0x78(%rbp), %r12
movq -0x58(%rbp), %rbx
jmp 0x2761d
movq %r14, -0x10(%r12,%r8)
movq %r13, -0x8(%r12,%r8)
negq %rbx
movq -0x50(%rbp), %rax
movq %r10, (%rax,%r8)
negq %r15
movq %rbx, %rax
shlq $0x4, %rax
addq %rax, %r12
addq %r8, %r12
movq -0x50(%rbp), %rax
leaq (%rax,%rbx,8), %r14
shlq $0x3, %rbx
addq %r8, %r14
movq -0x88(%rbp), %r13
movq %r14, %rdi
movq %r12, %rsi
movq -0x30(%rbp), %rdx
movq %r13, %rcx
movq -0x68(%rbp), %r8
movq -0x70(%rbp), %r9
callq 0x26ef0
subq %r13, %r15
addq %rbx, %r12
addq %rbx, %r14
testq %r15, %r15
jg 0x27643
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
movq -0x38(%rbp), %rbx
jne 0x276ac
movq %rbx, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x90(%rbp), %rdi
movq %r12, %rsi
movq %r10, -0x60(%rbp)
callq 0x29dc0
movq -0x60(%rbp), %r10
movq %rax, %r9
jmp 0x27188
callq 0x29df3
jmp 0x2767b
cmpq %rcx, %r13
jne 0x2728e
pushq $-0x1
popq %r14
movq -0x30(%rbp), %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x29f90
movq %r14, %r10
movq -0x48(%rbp), %r8
jmp 0x27612
setbe %al
cmpq %rcx, %r14
setb %dl
testb %dl, %al
jne 0x2735c
incq %r10
movq %rcx, -0x98(%rbp)
movq %r11, -0xa0(%rbp)
subq -0x98(%rbp), %r14
sbbq -0xa0(%rbp), %r13
jmp 0x2735c
leaq -0x1(%rbx), %rcx
movq -0x60(%rbp), %rdi
movq %rdi, %rsi
movq -0x30(%rbp), %rdx
callq 0x17cf0
movq -0x48(%rbp), %r8
addq -0x58(%rbp), %r13
addq %rax, %r13
movq -0x40(%rbp), %r10
subq $0x1, %r10
sbbq $0x0, -0x38(%rbp)
jmp 0x2760d
nopl (%rax)