// File: /workspace/github_cpp_makefile_star2_O1/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, %r13
movq %rcx, -0x30(%rbp)
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq $0x0, -0x90(%rbp)
leaq (,%r8,8), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
movq %r8, -0x38(%rbp)
movq %rsi, -0x68(%rbp)
ja 0x2d545
movq %r8, %r11
movq %rsp, %r9
leaq 0xf(%rsi), %rax
andq $-0x10, %rax
subq %rax, %r9
movq %r9, %rsp
movq %r15, %r10
subq %r11, %r10
leaq (%r14,%r15,8), %r12
movq -0x30(%rbp), %rax
leaq (%rax,%r11,8), %r8
cmpq %r10, %r11
movq %r9, -0x80(%rbp)
jge 0x2d0a2
movq %r13, -0x70(%rbp)
movq %r12, -0x40(%rbp)
leaq (%rbx,%r10,8), %rax
movq %rax, -0x50(%rbp)
subq %r11, %r15
subq %r11, %r15
movq %r10, -0x78(%rbp)
movq -0x68(%rbp), %rax
movq %r14, %r12
movq %rbx, %r13
movq %r15, %rcx
subq %r11, %r10
addq %rax, %r14
addq %rax, %rbx
subq %r11, %r15
cmpq %r10, %r11
jl 0x2d02a
leaq (,%r10,8), %rax
subq %rax, -0x50(%rbp)
subq %rax, -0x40(%rbp)
cmpq $0x2, %r10
movq %r10, -0x58(%rbp)
je 0x2d120
cmpq $0x1, %r10
jne 0x2d148
movq -0x40(%rbp), %r9
subq -0x68(%rbp), %r9
leaq 0x8(%r9), %rdi
movq %r11, %rax
movq -0x30(%rbp), %rdx
testq %rax, %rax
jle 0x2d243
movq -0x8(%rdx,%rax,8), %rcx
leaq -0x1(%rax), %rsi
cmpq %rcx, (%r14,%rax,8)
movq %rsi, %rax
je 0x2d07f
seta %al
jmp 0x2d245
movq %r10, %rax
negq %rax
leaq (,%r10,8), %rcx
subq %rcx, %r12
movq %r12, %rsi
subq %rcx, %rsi
cmpq $0x32, %r10
movq %r10, %r14
jle 0x2d0d6
leaq (%r8,%rax,8), %rdx
movq %rbx, %rdi
movq %r14, %rcx
movq %r13, %r8
callq 0x2cd28
jmp 0x2d0ed
leaq (%r14,%r14), %rdx
leaq (%r8,%rax,8), %rcx
movq (%r13), %r9
movq %rbx, %rdi
movq %r14, %r8
callq 0x2bf54
movq %rax, %r13
movq -0x38(%rbp), %r15
subq %r14, %r15
je 0x2d527
movq %r13, -0x48(%rbp)
cmpq %r15, %r14
movq %r14, -0x78(%rbp)
jle 0x2d180
movq -0x80(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq -0x30(%rbp), %rcx
movq %r15, %r8
jmp 0x2d194
movq %rcx, -0x60(%rbp)
movq -0x40(%rbp), %rax
leaq -0x10(%rax), %rdx
addq $-0x10, %r8
movl $0x4, %ecx
movq -0x50(%rbp), %rdi
xorl %esi, %esi
movq %r10, %r14
callq 0x1cc20
jmp 0x2d3c9
movq %rcx, -0x60(%rbp)
movq %r10, %rax
negq %rax
movq -0x40(%rbp), %rcx
leaq (%rcx,%rax,8), %rsi
cmpq $0x32, %r10
jle 0x2d3ab
leaq (%r8,%rax,8), %rdx
movq -0x50(%rbp), %rdi
movq %r10, %rcx
movq -0x70(%rbp), %r8
movq %r10, %r14
callq 0x2cd28
jmp 0x2d3c9
movq -0x80(%rbp), %r13
movq %r13, %rdi
movq -0x30(%rbp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r14, %r8
callq 0x1cd58
subq -0x68(%rbp), %r12
movq %r12, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq -0x38(%rbp), %rcx
callq 0x1c1c0
movq %rax, %r14
cmpq $0x0, -0x48(%rbp)
je 0x2d1d8
movq %r12, %r13
movq -0x78(%rbp), %rax
leaq (%r12,%rax,8), %rdi
movq %rdi, %rsi
movq -0x30(%rbp), %rdx
movq %r15, %rcx
callq 0x1c1c0
addq %rax, %r14
jmp 0x2d1db
movq %r12, %r13
testq %r14, %r14
je 0x2d523
movq -0x78(%rbp), %r12
cmpq $0x2, %r12
movl $0x1, %r15d
cmovgeq %r12, %r15
movq %r13, %r12
movq -0x48(%rbp), %r13
subq $0x1, (%rbx)
movq -0x38(%rbp), %rcx
jae 0x2d21c
movl $0x1, %eax
cmpq %rax, %r15
je 0x2d220
subq $0x1, (%rbx,%rax,8)
leaq 0x1(%rax), %rax
jb 0x2d20c
xorl %eax, %eax
jmp 0x2d227
movq $-0x1, %rax
addq %rax, %r13
movq %r12, %rdi
movq %r12, %rsi
movq -0x30(%rbp), %rdx
callq 0x1bfa0
subq %rax, %r14
jne 0x2d1fd
jmp 0x2d527
movb $0x1, %al
movzbl %al, %eax
movq %rax, -0x48(%rbp)
testb %al, %al
je 0x2d26f
movq %rdi, %rsi
movq %r11, %rcx
movq %r9, %rbx
movq %r8, %r14
callq 0x1c1c0
movq %r14, %r8
movq %rbx, %r9
movq -0x58(%rbp), %r10
movq -0x38(%rbp), %r11
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rax), %r15
movq -0x8(%rax), %r14
movq -0x10(%r8), %rcx
movq -0x8(%r8), %r8
cmpq %r8, %rdi
je 0x2d564
movq -0x70(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
movq %rdi, %rax
mulq -0xf0(%rbp)
movq %rax, %rsi
movq %rdx, %rbx
movq %rdi, -0xe8(%rbp)
movq %r14, -0xe0(%rbp)
addq -0xe0(%rbp), %rsi
adcq -0xe8(%rbp), %rbx
movq %rbx, %rax
imulq %r8, %rax
subq %rax, %r14
movq %r8, -0xd8(%rbp)
movq %rcx, -0xd0(%rbp)
subq -0xd0(%rbp), %r15
sbbq -0xd8(%rbp), %r14
movq %rbx, -0xc8(%rbp)
movq %rcx, %rax
mulq -0xc8(%rbp)
movq %rdx, -0xc0(%rbp)
movq %rax, -0xb8(%rbp)
subq -0xb8(%rbp), %r15
sbbq -0xc0(%rbp), %r14
cmpq %rsi, %r14
adcq $-0x1, %rbx
xorl %eax, %eax
cmpq %rsi, %r14
movl $0x0, %edx
cmovaeq %r8, %rdx
cmovaeq %rcx, %rax
incq %rbx
movq %rdx, -0xb0(%rbp)
movq %rax, -0xa8(%rbp)
addq -0xa8(%rbp), %r15
adcq -0xb0(%rbp), %r14
cmpq %r8, %r14
jae 0x2d597
cmpq $0x3, %r11
jl 0x2d4c7
movq %r8, -0x60(%rbp)
leaq -0x2(%r11), %rdx
movq %r9, %rdi
movq -0x30(%rbp), %rsi
movq %rbx, %rcx
movq %r9, -0x88(%rbp)
callq 0x30370
subq %rax, %r15
sbbq $0x0, %r14
movq -0x40(%rbp), %rax
movq %r15, -0x10(%rax)
jb 0x2d5cc
movq -0x38(%rbp), %r11
movq -0x40(%rbp), %rax
movq -0x58(%rbp), %r10
jmp 0x2d4cf
leaq (%r10,%r10), %rdx
leaq (%r8,%rax,8), %rcx
movq -0x70(%rbp), %rax
movq (%rax), %r9
movq -0x50(%rbp), %rdi
movq %r10, %r8
movq %r10, %r14
callq 0x2bf54
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %r11
movq %r11, %rax
subq %r14, %rax
movq %r14, %r10
je 0x2d4e0
cmpq %rax, %r10
movq -0x80(%rbp), %r14
movq %rax, -0x88(%rbp)
movq %r14, %rdi
jle 0x2d403
movq -0x50(%rbp), %rsi
movq %r10, %rdx
movq -0x30(%rbp), %rcx
movq %rax, %r8
jmp 0x2d411
movq -0x30(%rbp), %rsi
movq %rax, %rdx
movq -0x50(%rbp), %rcx
movq %r10, %r8
callq 0x1cd58
movq -0x40(%rbp), %r15
subq -0x68(%rbp), %r15
movq %r15, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq -0x38(%rbp), %rcx
callq 0x1c1c0
movq %rax, %r14
cmpq $0x0, -0x48(%rbp)
movq %r15, -0x40(%rbp)
je 0x2d45c
movq -0x58(%rbp), %rax
leaq (%r15,%rax,8), %rdi
movq %rdi, %rsi
movq -0x30(%rbp), %rdx
movq -0x88(%rbp), %rcx
callq 0x1c1c0
addq %rax, %r14
movq -0x60(%rbp), %rax
testq %r14, %r14
movq -0x38(%rbp), %r11
je 0x2d4dc
cmpq $0x2, %rax
movl $0x1, %r15d
cmovgeq %rax, %r15
movq -0x50(%rbp), %rax
subq $0x1, (%rax)
jae 0x2d496
movl $0x1, %eax
cmpq %rax, %r15
je 0x2d49a
subq $0x1, (%rbx,%rax,8)
leaq 0x1(%rax), %rax
jb 0x2d486
xorl %eax, %eax
jmp 0x2d4a1
movq $-0x1, %rax
addq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq %rdi, %rsi
movq -0x30(%rbp), %rdx
movq %r11, %rcx
callq 0x1bfa0
movq -0x38(%rbp), %r11
subq %rax, %r14
movq -0x58(%rbp), %r10
jne 0x2d477
jmp 0x2d4e0
movq -0x40(%rbp), %rax
movq %r15, -0x10(%rax)
movq %r14, -0x8(%rax)
movq -0x50(%rbp), %rax
movq %rbx, (%rax)
jmp 0x2d4e0
movq -0x58(%rbp), %r10
movq -0x78(%rbp), %r14
subq %r10, %r14
movq -0x68(%rbp), %rax
negq %rax
movq -0x70(%rbp), %rbx
movq %r13, %rdi
movq %r12, %rsi
movq -0x30(%rbp), %rdx
movq %r11, %rcx
movq %rbx, %r8
movq -0x80(%rbp), %r9
movq %rax, %r15
callq 0x2cd28
movq %r15, %rax
movq -0x38(%rbp), %r11
subq %r11, %r14
addq %r15, %r12
addq %r15, %r13
testq %r14, %r14
jg 0x2d4f2
movq -0x48(%rbp), %r13
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
jne 0x2d55d
movq %r13, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x90(%rbp), %rdi
callq 0x30170
movq -0x38(%rbp), %r11
movq %rax, %r9
jmp 0x2cfed
callq 0x301a3
jmp 0x2d533
cmpq %rcx, %r14
jne 0x2d28f
movq $-0x1, %rbx
movq %r9, %rdi
movq -0x30(%rbp), %rsi
movq %r11, %rdx
movq $-0x1, %rcx
callq 0x30370
movq -0x58(%rbp), %r10
movq -0x38(%rbp), %r11
jmp 0x2d4d3
setbe %al
cmpq %rcx, %r15
setb %dl
testb %dl, %al
jne 0x2d35d
incq %rbx
movq %rcx, -0x98(%rbp)
movq %r8, -0xa0(%rbp)
subq -0x98(%rbp), %r15
sbbq -0xa0(%rbp), %r14
jmp 0x2d35d
movq -0x38(%rbp), %r15
leaq -0x1(%r15), %rcx
movq -0x88(%rbp), %rdi
movq %rdi, %rsi
movq -0x30(%rbp), %rdx
callq 0x1bfa0
movq %r15, %r11
addq -0x60(%rbp), %r14
addq %rax, %r14
subq $0x1, %rbx
sbbq $0x0, -0x48(%rbp)
jmp 0x2d39e
nop