// File: /workspace/github_cpp_makefile_star2_O3/marxn[P]pupp/3rdparty/gmp/mpn/sbpi1_divappr_q.c
// Function: _gmpn_sbpi1_divappr_q
mp_limb_t
mpn_sbpi1_divappr_q (mp_ptr qp,
		     mp_ptr np, mp_size_t nn,
		     mp_srcptr dp, mp_size_t dn,
		     mp_limb_t dinv)
{
  mp_limb_t qh;
  mp_size_t qn, i;
  mp_limb_t n1, n0;
  mp_limb_t d1, d0;
  mp_limb_t cy, cy1;
  mp_limb_t q;
  mp_limb_t flag;

  ASSERT (dn > 2);
  ASSERT (nn >= dn);
  ASSERT ((dp[dn-1] & GMP_NUMB_HIGHBIT) != 0);

  np += nn;

  qn = nn - dn;
  if (qn + 1 < dn)
    {
      dp += dn - (qn + 1);
      dn = qn + 1;
    }

  qh = mpn_cmp (np - dn, dp, dn) >= 0;
  if (qh != 0)
    mpn_sub_n (np - dn, np - dn, dp, dn);

  qp += qn;

  dn -= 2;			/* offset dn by 2 for main division loops,
				   saving two iterations in mpn_submul_1.  */
  d1 = dp[dn + 1];
  d0 = dp[dn + 0];

  np -= 2;

  n1 = np[1];

  for (i = qn - (dn + 2); i >= 0; i--)
    {
      np--;
      if (UNLIKELY (n1 == d1) && np[1] == d0)
	{
	  q = GMP_NUMB_MASK;
	  mpn_submul_1 (np - dn, dp, dn + 2, q);
	  n1 = np[1];		/* update n1, last loop's value will now be invalid */
	}
      else
	{
	  udiv_qr_3by2 (q, n1, n0, n1, np[1], np[0], d1, d0, dinv);

	  cy = mpn_submul_1 (np - dn, dp, dn, q);

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

	  if (UNLIKELY (cy != 0))
	    {
	      n1 += d1 + mpn_add_n (np - dn, np - dn, dp, dn + 1);
	      q--;
	    }
	}

      *--qp = q;
    }

  flag = ~CNST_LIMB(0);

  if (dn >= 0)
    {
      for (i = dn; i > 0; i--)
	{
	  np--;
	  if (UNLIKELY (n1 >= (d1 & flag)))
	    {
	      q = GMP_NUMB_MASK;
	      cy = mpn_submul_1 (np - dn, dp, dn + 2, q);

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

	      cy = mpn_submul_1 (np - dn, dp, dn, q);

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

	      if (UNLIKELY (cy != 0))
		{
		  n1 += d1 + mpn_add_n (np - dn, np - dn, dp, dn + 1);
		  q--;
		}
	    }

	  *--qp = q;

	  /* Truncate operands.  */
	  dn--;
	  dp++;
	}

      np--;
      if (UNLIKELY (n1 >= (d1 & flag)))
	{
	  q = GMP_NUMB_MASK;
	  cy = mpn_submul_1 (np, dp, 2, q);

	  if (UNLIKELY (n1 != cy))
	    {
	      if (n1 < (cy & flag))
		{
		  q--;
		  add_ssaaaa (np[1], np[0], np[1], np[0], dp[1], dp[0]);
		}
	      else
		flag = 0;
	    }
	  n1 = np[1];
	}
      else
	{
	  udiv_qr_3by2 (q, n1, n0, n1, np[1], np[0], d1, d0, dinv);

	  np[1] = n1;
	  np[0] = n0;
	}

      *--qp = q;
    }

  ASSERT_ALWAYS (np[1] == n1);

  return qh;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %r9, 0x58(%rsp)
movq %r8, %r12
movq %rsi, %rbx
movq %rdi, (%rsp)
leaq (%rsi,%rdx,8), %rdi
movq %rdx, %r14
subq %r8, %r14
leaq 0x1(%r14), %rax
movq %rax, %r8
subq %r12, %r8
movq %r12, %r13
cmovlq %rax, %r13
negq %r8
leaq (,%r13,8), %rsi
movq %rdi, %r11
movq %rsi, 0x40(%rsp)
subq %rsi, %rdi
xorl %esi, %esi
cmpq %rax, %r12
cmovgq %r8, %rsi
cmovgq %r12, %rax
leaq (%rcx,%rsi,8), %r10
addq %r12, %rax
shlq $0x3, %rax
leaq (,%rdx,8), %rsi
movq %rsi, 0x8(%rsp)
subq %rsi, %rax
addq %rcx, %rax
addq $-0x10, %rax
leaq (%rbx,%rdx,8), %rcx
addq $-0x8, %rcx
movq %r13, %r9
movq %r10, 0x18(%rsp)
movq %rdx, 0x48(%rsp)
testq %r9, %r9
jle 0x2bf0b
movq (%rcx), %rsi
movq (%rax,%r9,8), %r8
decq %r9
addq $-0x8, %rcx
cmpq %r8, %rsi
je 0x2bef1
jbe 0x2bf2c
movq %rdi, %rsi
movq %r10, %rdx
movq %r13, %rcx
movq %r11, %r15
callq 0x1bca0
movq %r15, %rcx
movq 0x18(%rsp), %r10
movl $0x1, %r15d
jmp 0x2bf32
xorl %r15d, %r15d
movq %r11, %rcx
movq -0x10(%r10,%r13,8), %r9
movq -0x8(%r10,%r13,8), %r8
movq -0x8(%rcx), %rdi
movq %r14, %rbp
subq %r13, %rbp
movq %r8, 0x10(%rsp)
movq %r9, 0x30(%rsp)
movq %r13, 0x28(%rsp)
js 0x2c1c6
movq %r15, 0x50(%rsp)
leaq -0x2(%r13), %rax
movq %rax, 0x20(%rsp)
leaq -0x1(%r13), %rax
movq %rax, 0x60(%rsp)
shlq $0x3, %r12
movq (%rsp), %r14
subq %r12, %r14
movq 0x40(%rsp), %rax
negq %rax
leaq (%rbx,%rax), %r15
addq $-0x8, %r15
addq $-0x10, %rbx
incq %rbp
movq 0x8(%rsp), %r11
cmpq %r8, %rdi
je 0x2c108
movq 0x58(%rsp), %rax
movq %rax, 0x190(%rsp)
movq %rdi, %rax
mulq 0x190(%rsp)
movq %rax, %rcx
movq %rdx, %r12
movq (%rbx,%r11), %rsi
movq %rsi, 0x180(%rsp)
movq %rdi, 0x188(%rsp)
addq 0x180(%rsp), %rcx
adcq 0x188(%rsp), %r12
movq %r12, %rax
imulq %r8, %rax
subq %rax, %rsi
movq -0x8(%rbx,%r11), %r13
movq %r8, 0x178(%rsp)
movq %r9, 0x170(%rsp)
subq 0x170(%rsp), %r13
sbbq 0x178(%rsp), %rsi
movq %r12, 0x168(%rsp)
movq %r9, %rax
mulq 0x168(%rsp)
movq %rdx, 0x160(%rsp)
movq %rax, 0x158(%rsp)
subq 0x158(%rsp), %r13
sbbq 0x160(%rsp), %rsi
cmpq %rcx, %rsi
adcq $-0x1, %r12
cmpq %rcx, %rsi
movl $0x0, %eax
cmovaeq %r8, %rax
movl $0x0, %ecx
cmovaeq %r9, %rcx
incq %r12
movq %rax, 0x150(%rsp)
movq %rcx, 0x148(%rsp)
addq 0x148(%rsp), %r13
adcq 0x150(%rsp), %rsi
movq %rsi, %rax
cmpq %r8, %rsi
movq %rbx, 0x38(%rsp)
movq %r14, (%rsp)
jae 0x2c141
movq %rax, %rbx
leaq (%r15,%r11), %r14
movq %r14, %rdi
movq %r10, %rsi
movq 0x20(%rsp), %rdx
movq %r12, %rcx
callq 0x2ffb0
movq 0x8(%rsp), %r11
subq %rax, %r13
movq %rbx, %rdi
sbbq $0x0, %rdi
movq 0x38(%rsp), %rbx
movq %r13, -0x8(%rbx,%r11)
jb 0x2c174
movq 0x10(%rsp), %r8
movq (%rsp), %r14
movq %r12, -0x8(%r14,%r11)
addq $-0x8, %r14
addq $-0x8, %rbx
addq $-0x8, %r15
decq %rbp
testq %rbp, %rbp
movq 0x30(%rsp), %r9
movq 0x18(%rsp), %r10
jg 0x2bf99
jmp 0x2c1ad
cmpq %r9, (%rbx,%r11)
jne 0x2bfa2
leaq (%r15,%r11), %rdi
movq $-0x1, %r12
movq %r10, %rsi
movq 0x28(%rsp), %rdx
movq $-0x1, %rcx
callq 0x2ffb0
movq 0x8(%rsp), %r11
movq 0x10(%rsp), %r8
movq (%rbx,%r11), %rdi
jmp 0x2c0dc
ja 0x2c14c
cmpq %r9, %r13
jb 0x2c09a
incq %r12
movq %r9, 0x138(%rsp)
movq %r8, 0x140(%rsp)
subq 0x138(%rsp), %r13
sbbq 0x140(%rsp), %rax
jmp 0x2c09a
movq %rbx, %r13
movq %rdi, %rbx
movq %r14, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
movq 0x60(%rsp), %rcx
callq 0x1ba80
movq 0x8(%rsp), %r11
movq %rbx, %rdi
movq %r13, %rbx
movq 0x10(%rsp), %r8
addq %r8, %rdi
addq %rax, %rdi
decq %r12
jmp 0x2c0d8
movq 0x48(%rsp), %rcx
leaq (%r14,%rcx,8), %rax
movq %rax, 0x38(%rsp)
leaq (%rbx,%rcx,8), %rbx
movq 0x50(%rsp), %r15
jmp 0x2c1da
movq (%rsp), %rax
leaq (%rax,%r14,8), %rax
movq %rax, 0x38(%rsp)
addq $-0x10, %rcx
movq %rcx, %rbx
movq 0x28(%rsp), %rbp
cmpq $0x2, %rbp
jl 0x2c5d9
movq $-0x1, %rcx
je 0x2c4c9
movq %r15, 0x50(%rsp)
movq %rbx, %rax
subq 0x40(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x8(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %rbx, 0x20(%rsp)
leaq (%r10,%r15), %rsi
leaq (%r12,%rbp), %r11
addq $-0x2, %r11
movq %rcx, (%rsp)
movq %rcx, %rax
andq %r8, %rax
cmpq %rax, %rdi
movq %rsi, 0x40(%rsp)
jae 0x2c38f
movq 0x58(%rsp), %rax
movq %rax, 0x130(%rsp)
movq %rdi, %rax
mulq 0x130(%rsp)
movq %rax, %rcx
movq %rdx, %r13
movq (%rbx,%r12,8), %r10
movq %r10, 0x120(%rsp)
movq %rdi, 0x128(%rsp)
addq 0x120(%rsp), %rcx
adcq 0x128(%rsp), %r13
movq %r13, %rax
imulq %r8, %rax
subq %rax, %r10
movq -0x8(%rbx,%r12,8), %rbp
movq %r8, 0x118(%rsp)
movq %r9, 0x110(%rsp)
subq 0x110(%rsp), %rbp
sbbq 0x118(%rsp), %r10
movq %r13, 0x108(%rsp)
movq %r9, %rax
mulq 0x108(%rsp)
movq %rdx, 0x100(%rsp)
movq %rax, 0xf8(%rsp)
subq 0xf8(%rsp), %rbp
sbbq 0x100(%rsp), %r10
cmpq %rcx, %r10
adcq $-0x1, %r13
cmpq %rcx, %r10
movl $0x0, %eax
cmovaeq %r8, %rax
movl $0x0, %ecx
cmovaeq %r9, %rcx
incq %r13
movq %rax, 0xf0(%rsp)
movq %rcx, 0xe8(%rsp)
addq 0xe8(%rsp), %rbp
adcq 0xf0(%rsp), %r10
movq %r10, %rbx
cmpq %r8, %r10
jae 0x2c3e2
movq 0x8(%rsp), %rdi
movq %r11, %r14
movq %r11, %rdx
movq %r13, %rcx
callq 0x2ffb0
subq %rax, %rbp
movq %rbx, %rdi
sbbq $0x0, %rdi
movq 0x20(%rsp), %rbx
movq %rbp, -0x8(%rbx,%r12,8)
jb 0x2c415
movq 0x10(%rsp), %r8
movq 0x30(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x28(%rsp), %rbp
movq (%rsp), %rcx
movq 0x38(%rsp), %rax
movq %r13, -0x8(%rax,%r12,8)
addq $0x8, %r15
decq %r12
cmpq $0x1, %r14
jg 0x2c217
jmp 0x2c4b9
movq %r11, 0x48(%rsp)
leaq (%r12,%rbp), %r14
movq $-0x1, %r13
movq %rdi, %rbx
movq 0x8(%rsp), %rdi
movq %r14, %rdx
movq $-0x1, %rcx
callq 0x2ffb0
cmpq %rax, %rbx
jne 0x2c45b
movq 0x10(%rsp), %r8
movq 0x30(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x20(%rsp), %rbx
movq (%rsp), %rcx
movq (%rbx,%r12,8), %rdi
movq 0x48(%rsp), %r14
jmp 0x2c36f
ja 0x2c3ed
cmpq %r9, %rbp
jb 0x2c32a
incq %r13
movq %r9, 0xd8(%rsp)
movq %r8, 0xe0(%rsp)
subq 0xd8(%rsp), %rbp
sbbq 0xe0(%rsp), %rbx
jmp 0x2c32a
movq 0x28(%rsp), %rbp
leaq (%r12,%rbp), %rcx
decq %rcx
movq %rdi, %rbx
movq 0x8(%rsp), %rdi
movq %rdi, %rsi
movq 0x40(%rsp), %rdx
callq 0x1ba80
movq %rbx, %rdi
movq 0x20(%rsp), %rbx
movq 0x10(%rsp), %r8
addq %r8, %rdi
addq %rax, %rdi
decq %r13
movq 0x30(%rsp), %r9
movq 0x18(%rsp), %r10
jmp 0x2c36b
movq 0x40(%rsp), %rdx
andq (%rsp), %rax
cmpq %rax, %rbx
jae 0x2c499
movq 0x8(%rsp), %rdi
movq %rdi, %rsi
movq %r14, %rcx
callq 0x1ba80
movq $-0x2, %r13
movq 0x10(%rsp), %r8
movq 0x30(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x28(%rsp), %rbp
jmp 0x2c3ce
xorl %ecx, %ecx
movq 0x10(%rsp), %r8
movq 0x30(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x28(%rsp), %rbp
movq 0x20(%rsp), %rbx
jmp 0x2c3d7
subq %r15, 0x38(%rsp)
subq %r15, %rbx
addq %r15, %r10
movq 0x50(%rsp), %r15
movq %rbx, %r13
addq $-0x8, %rbx
movq %rcx, %rax
andq %r8, %rax
cmpq %rax, %rdi
jae 0x2c5f9
movq 0x58(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq %rdi, %rax
mulq 0xc0(%rsp)
movq %rax, %rcx
movq %rdx, %r14
movq %rdi, %rax
movq (%r13), %rdi
movq %rdi, 0xb0(%rsp)
movq %rax, 0xb8(%rsp)
addq 0xb0(%rsp), %rcx
adcq 0xb8(%rsp), %r14
movq %r14, %rax
imulq %r8, %rax
subq %rax, %rdi
movq %r13, %r10
movq -0x8(%r13), %rsi
movq %r8, 0xa8(%rsp)
movq %r9, 0xa0(%rsp)
subq 0xa0(%rsp), %rsi
sbbq 0xa8(%rsp), %rdi
movq %r14, 0x98(%rsp)
movq %r9, %rax
mulq 0x98(%rsp)
movq %rdx, 0x90(%rsp)
movq %rax, 0x88(%rsp)
subq 0x88(%rsp), %rsi
sbbq 0x90(%rsp), %rdi
cmpq %rcx, %rdi
adcq $-0x1, %r14
xorl %eax, %eax
cmpq %rcx, %rdi
movl $0x0, %ecx
cmovaeq %r8, %rcx
cmovaeq %r9, %rax
incq %r14
movq %rcx, 0x80(%rsp)
movq %rax, 0x78(%rsp)
addq 0x78(%rsp), %rsi
adcq 0x80(%rsp), %rdi
movq %rdi, %rax
cmpq %r8, %rdi
jae 0x2c62c
movq %rax, %rdi
movq %rdi, (%r10)
movq %rsi, -0x8(%r10)
movq 0x38(%rsp), %rax
movq %r14, -0x8(%rax)
cmpq %rdi, 0x8(%rbx)
jne 0x2c5f4
movq %r15, %rax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x7417
movq %rcx, (%rsp)
movq $-0x1, %r14
movl $0x2, %edx
movq %rdi, %rbp
movq %rbx, %rdi
movq %r10, %rsi
movq $-0x1, %rcx
movq %r10, %r12
callq 0x2ffb0
cmpq %rax, %rbp
jne 0x2c652
movq (%r13), %rdi
jmp 0x2c5d0
ja 0x2c633
cmpq %r9, %rsi
jb 0x2c5c6
incq %r14
movq %r9, 0x68(%rsp)
movq %r8, 0x70(%rsp)
movq %rax, %rdi
subq 0x68(%rsp), %rsi
sbbq 0x70(%rsp), %rdi
jmp 0x2c5c9
andq (%rsp), %rax
cmpq %rax, %rbp
movq (%r13), %rdi
jae 0x2c5d0
movq (%r12), %rax
movq 0x8(%r12), %rcx
movq -0x8(%r13), %rdx
movq %rax, 0xc8(%rsp)
movq %rcx, 0xd0(%rsp)
addq 0xc8(%rsp), %rdx
adcq 0xd0(%rsp), %rdi
movq %rdi, (%r13)
movq %rdx, -0x8(%r13)
movq $-0x2, %r14
jmp 0x2c5d0