// File: /workspace/github_cpp_makefile_star2_O3/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 $0xb8, %rsp
movq %r9, %r14
movq %r8, -0x40(%rbp)
movq %rcx, %rbx
movq %rdx, %r10
movq %rsi, %r9
movq $0x0, -0x80(%rbp)
leaq (,%r8,8), %r12
cmpq $0x7f00, %r12           # imm = 0x7F00
movq %rdi, -0x50(%rbp)
ja 0x2d17e
movq %rsp, %r15
leaq 0xf(%r12), %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
movq %r14, -0x70(%rbp)
movq %r10, %r13
movq -0x40(%rbp), %rsi
subq %rsi, %r13
leaq (%rbx,%rsi,8), %r8
cmpq %r13, %rsi
jge 0x2ccbc
movq %r15, -0x78(%rbp)
movq %rbx, -0x38(%rbp)
movq %rsi, %rcx
shlq $0x4, %rcx
leaq (%rsi,%rsi), %r11
leaq (%r10,%r10), %rdx
subq %r11, %rdx
leaq (,%r10,8), %rax
movq %rax, -0x30(%rbp)
subq %rcx, %rax
xorl %ebx, %ebx
xorl %r15d, %r15d
subq %rsi, %r15
leaq (%r15,%r13), %r14
addq %r12, %rbx
subq %r11, %rdx
subq %rcx, %rax
cmpq %rsi, %r14
jg 0x2cc21
movq -0x50(%rbp), %rsi
leaq (%rsi,%rbx), %rdi
addq %r9, %r12
cmpq $0x2, %r14
je 0x2cd48
cmpq $0x1, %r14
jne 0x2cd74
leaq (%r12,%rbx), %rax
movq -0x40(%rbp), %rcx
movq %rcx, %rdx
negq %rdx
movq %rdx, -0x60(%rbp)
leaq (%r9,%rbx), %rdi
addq $0x8, %rdi
addq %rbx, %r9
movq %rcx, %r10
movq %r9, -0x68(%rbp)
testq %r10, %r10
jle 0x2cc9c
movq (%rax), %rdx
movq -0x38(%rbp), %rsi
movq -0x8(%rsi,%r10,8), %rsi
decq %r10
addq $-0x8, %rax
cmpq %rsi, %rdx
je 0x2cc79
jbe 0x2cfc4
movq %rdi, %rsi
movq -0x38(%rbp), %rdx
movq %r8, %r14
callq 0x1bca0
movq %r14, %r8
movl $0x1, %eax
movq %rax, -0x30(%rbp)
jmp 0x2cfcc
leaq (%r9,%r10,8), %r14
movq %r13, %rax
negq %rax
leaq (,%r13,8), %rcx
subq %rcx, %r14
movq %r14, %rsi
subq %rcx, %rsi
cmpq $0x32, %r13
jle 0x2ccf6
leaq (%r8,%rax,8), %rdx
movq -0x50(%rbp), %rdi
movq %r13, %rcx
movq -0x70(%rbp), %r8
movq %r15, %r9
callq 0x2c91c
jmp 0x2cd15
leaq (,%r13,2), %rdx
leaq (%r8,%rax,8), %rcx
movq -0x70(%rbp), %rax
movq (%rax), %r9
movq -0x50(%rbp), %rdi
movq %r13, %r8
callq 0x2bb38
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rax
subq %r13, %rax
je 0x2d162
cmpq %rax, %r13
movq %rax, -0x38(%rbp)
movq %r15, %rdi
jle 0x2cdbd
movq -0x50(%rbp), %rsi
movq %r13, %rdx
movq %rbx, %rcx
movq %rax, %r8
jmp 0x2cdca
movq %r10, -0x48(%rbp)
movq %r11, %r13
movq %r9, -0x68(%rbp)
leaq (%rbx,%r12), %rdx
addq $-0x10, %rdx
addq $-0x10, %r8
movl $0x4, %ecx
movq %rdi, -0x58(%rbp)
xorl %esi, %esi
callq 0x1c700
jmp 0x2ce8f
movq %rdi, -0x58(%rbp)
movq %r10, -0x48(%rbp)
movq %r11, %r13
movq %r9, -0x68(%rbp)
movq %r9, %rsi
subq %rax, %rsi
cmpq $0x32, %r14
jle 0x2ce6e
subq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
addq %rbx, %rax
addq %rax, %rcx
movq -0x58(%rbp), %rdi
movq %rcx, %rdx
movq %r14, %rcx
movq -0x70(%rbp), %r8
movq -0x78(%rbp), %r9
callq 0x2c91c
jmp 0x2ce8f
movq %rbx, %rsi
movq %rax, %rdx
movq -0x50(%rbp), %rcx
movq %r13, %r8
callq 0x1c838
subq %r12, %r14
movq %r14, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq -0x40(%rbp), %rcx
callq 0x1bca0
movq %rax, %r15
cmpq $0x0, -0x30(%rbp)
je 0x2ce04
leaq (%r14,%r13,8), %rdi
movq %rdi, %rsi
movq %rbx, %rdx
movq -0x38(%rbp), %rcx
callq 0x1bca0
addq %rax, %r15
testq %r15, %r15
je 0x2d162
movq %rbx, -0x38(%rbp)
cmpq $0x2, %r13
movl $0x1, %ebx
cmovgeq %r13, %rbx
movq -0x40(%rbp), %r12
movq -0x50(%rbp), %r13
subq $0x1, (%r13)
jae 0x2ce43
movl $0x1, %eax
cmpq %rax, %rbx
je 0x2ce47
subq $0x1, (%r13,%rax,8)
leaq 0x1(%rax), %rax
jb 0x2ce32
xorl %eax, %eax
jmp 0x2ce4e
movq $-0x1, %rax
addq %rax, -0x30(%rbp)
movq %r14, %rdi
movq %r14, %rsi
movq -0x38(%rbp), %rdx
movq %r12, %rcx
callq 0x1ba80
subq %rax, %r15
jne 0x2ce26
jmp 0x2d162
subq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
addq %rbx, %rax
addq %rax, %rcx
movq -0x70(%rbp), %rax
movq (%rax), %r9
movq -0x58(%rbp), %rdi
movq %r14, %r8
callq 0x2bb38
movq %rax, -0x30(%rbp)
movq %r13, %rax
subq -0x48(%rbp), %rax
subq %r15, %rax
jne 0x2ceae
movq -0x40(%rbp), %r13
movq %r13, %rcx
negq %rcx
jmp 0x2d115
movq %r12, -0x48(%rbp)
cmpq %rax, %r14
movq %rax, -0x60(%rbp)
jle 0x2ced2
movq -0x78(%rbp), %r13
movq %r13, %rdi
movq -0x58(%rbp), %rsi
movq %r14, %rdx
movq -0x38(%rbp), %rcx
movq %rax, %r8
jmp 0x2cee7
movq -0x78(%rbp), %r13
movq %r13, %rdi
movq -0x38(%rbp), %rsi
movq %rax, %rdx
movq -0x58(%rbp), %rcx
movq %r14, %r8
callq 0x1c838
movq -0x68(%rbp), %r12
addq %rbx, %r12
movq %r12, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq -0x40(%rbp), %rcx
callq 0x1bca0
movq %rax, %r13
cmpq $0x0, -0x30(%rbp)
movq %r12, -0x68(%rbp)
je 0x2cf2a
leaq (%r12,%r14,8), %rdi
movq %rdi, %rsi
movq -0x38(%rbp), %rdx
movq -0x60(%rbp), %rcx
callq 0x1bca0
addq %rax, %r13
movq -0x48(%rbp), %r12
movq -0x40(%rbp), %rcx
negq %rcx
testq %r13, %r13
je 0x2d111
movq %rcx, -0x60(%rbp)
movq -0x50(%rbp), %rax
addq %rbx, %rax
addq $0x8, %rax
movq %rax, -0x48(%rbp)
cmpq $0x2, %r14
movl $0x1, %eax
cmovgeq %r14, %rax
decq %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %r14
movq -0x50(%rbp), %rax
subq $0x1, (%rax,%rbx)
movq -0x68(%rbp), %rdi
jae 0x2cf90
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
subq $0x1, %rax
jb 0x2cf94
subq $0x1, (%rcx)
leaq 0x8(%rcx), %rcx
jb 0x2cf80
xorl %eax, %eax
jmp 0x2cf9b
movq $-0x1, %rax
addq %rax, %r14
movq %rdi, %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
callq 0x1ba80
subq %rax, %r13
jne 0x2cf69
movq %r14, -0x30(%rbp)
movq -0x40(%rbp), %r13
movq -0x60(%rbp), %rcx
jmp 0x2d115
movq $0x0, -0x30(%rbp)
movq (%r12,%rbx), %rdi
movq -0x10(%rbx,%r12), %r14
movq -0x8(%rbx,%r12), %r13
movq -0x10(%r8), %rcx
movq -0x8(%r8), %r9
cmpq %r9, %rdi
je 0x2d1a5
movq -0x70(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
movq %rdi, %rax
mulq -0xe0(%rbp)
movq %rax, %rsi
movq %rdx, %r8
movq %rdi, -0xd8(%rbp)
movq %r13, -0xd0(%rbp)
addq -0xd0(%rbp), %rsi
adcq -0xd8(%rbp), %r8
movq %r8, %rax
imulq %r9, %rax
subq %rax, %r13
movq %r9, -0xc8(%rbp)
movq %rcx, -0xc0(%rbp)
subq -0xc0(%rbp), %r14
sbbq -0xc8(%rbp), %r13
movq %r8, -0xb8(%rbp)
movq %rcx, %rax
mulq -0xb8(%rbp)
movq %rdx, -0xb0(%rbp)
movq %rax, -0xa8(%rbp)
subq -0xa8(%rbp), %r14
sbbq -0xb0(%rbp), %r13
cmpq %rsi, %r13
adcq $-0x1, %r8
xorl %eax, %eax
cmpq %rsi, %r13
movl $0x0, %edx
cmovaeq %r9, %rdx
cmovaeq %rcx, %rax
incq %r8
movq %rdx, -0xa0(%rbp)
movq %rax, -0x98(%rbp)
addq -0x98(%rbp), %r14
adcq -0xa0(%rbp), %r13
cmpq %r9, %r13
movq -0x68(%rbp), %rdi
jae 0x2d1d6
movq -0x40(%rbp), %rax
cmpq $0x3, %rax
jl 0x2d0fb
movq %r9, -0x58(%rbp)
leaq -0x2(%rax), %rdx
movq -0x38(%rbp), %rsi
movq %r8, -0x48(%rbp)
movq %r8, %rcx
callq 0x2ffb0
subq %rax, %r14
sbbq $0x0, %r13
movq %r14, -0x10(%r12,%rbx)
jb 0x2d20b
movq -0x60(%rbp), %rcx
movq -0x48(%rbp), %r8
jmp 0x2d104
movq %r14, -0x10(%r12,%rbx)
movq -0x60(%rbp), %rcx
movq %r13, -0x8(%r12,%rbx)
movq -0x50(%rbp), %rax
movq %r8, (%rax,%rbx)
movq -0x40(%rbp), %r13
negq %r15
movq %rcx, %rax
shlq $0x4, %rax
addq %rax, %r12
addq %rbx, %r12
movq -0x50(%rbp), %rax
leaq (%rax,%rcx,8), %r14
shlq $0x3, %rcx
addq %rbx, %r14
movq %r14, %rdi
movq %r12, %rsi
movq -0x38(%rbp), %rdx
movq %rcx, %rbx
movq %r13, %rcx
movq -0x70(%rbp), %r8
movq -0x78(%rbp), %r9
callq 0x2c91c
movq %rbx, %rcx
subq %r13, %r15
addq %rbx, %r12
addq %rbx, %r14
testq %r15, %r15
jg 0x2d134
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
jne 0x2d19e
movq -0x30(%rbp), %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x80(%rbp), %rdi
movq %r12, %rsi
movq %r9, %r15
movq %r10, %r13
callq 0x2fdb0
movq %r13, %r10
movq %r15, %r9
movq %rax, %r15
jmp 0x2cbd8
callq 0x2fde3
jmp 0x2d16b
cmpq %rcx, %r13
jne 0x2cfeb
movq -0x68(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq $-0x1, %rcx
callq 0x2ffb0
movq $-0x1, %r8
movq -0x60(%rbp), %rcx
jmp 0x2d109
setbe %al
cmpq %rcx, %r14
setb %dl
testb %dl, %al
jne 0x2d0bd
incq %r8
movq %rcx, -0x88(%rbp)
movq %r9, -0x90(%rbp)
subq -0x88(%rbp), %r14
sbbq -0x90(%rbp), %r13
jmp 0x2d0bd
movq -0x40(%rbp), %rax
leaq -0x1(%rax), %rcx
movq -0x68(%rbp), %rdi
movq %rdi, %rsi
movq -0x38(%rbp), %rdx
callq 0x1ba80
addq -0x58(%rbp), %r13
addq %rax, %r13
movq -0x48(%rbp), %r8
subq $0x1, %r8
sbbq $0x0, -0x30(%rbp)
jmp 0x2d100