// File: /workspace/github_cpp_makefile_star2_O2/marxn[P]pupp/3rdparty/gmp/mpn/mu_divappr_q.c
// Function: _gmpn_mu_divappr_q
mp_limb_t
mpn_mu_divappr_q (mp_ptr qp,
		  mp_srcptr np,
		  mp_size_t nn,
		  mp_srcptr dp,
		  mp_size_t dn,
		  mp_ptr scratch)
{
  mp_size_t qn, in;
  mp_limb_t cy, qh;
  mp_ptr ip, tp;

  ASSERT (dn > 1);

  qn = nn - dn;

  /* If Q is smaller than D, truncate operands. */
  if (qn + 1 < dn)
    {
      np += dn - (qn + 1);
      nn -= dn - (qn + 1);
      dp += dn - (qn + 1);
      dn = qn + 1;
    }

  /* Compute the inverse size.  */
  in = mpn_mu_divappr_q_choose_in (qn, dn, 0);
  ASSERT (in <= dn);

#if 1
  /* This alternative inverse computation method gets slightly more accurate
     results.  FIXMEs: (1) Temp allocation needs not analysed (2) itch function
     not adapted (3) mpn_invertappr scratch needs not met.  */
  ip = scratch;
  tp = scratch + in + 1;

  /* compute an approximate inverse on (in+1) limbs */
  if (dn == in)
    {
      MPN_COPY (tp + 1, dp, in);
      tp[0] = 1;
      mpn_invertappr (ip, tp, in + 1, tp + in + 1);
      MPN_COPY_INCR (ip, ip + 1, in);
    }
  else
    {
      cy = mpn_add_1 (tp, dp + dn - (in + 1), in + 1, 1);
      if (UNLIKELY (cy != 0))
	MPN_ZERO (ip, in);
      else
	{
	  mpn_invertappr (ip, tp, in + 1, tp + in + 1);
	  MPN_COPY_INCR (ip, ip + 1, in);
	}
    }
#else
  /* This older inverse computation method gets slightly worse results than the
     one above.  */
  ip = scratch;
  tp = scratch + in;

  /* Compute inverse of D to in+1 limbs, then round to 'in' limbs.  Ideally the
     inversion function should do this automatically.  */
  if (dn == in)
    {
      tp[in + 1] = 0;
      MPN_COPY (tp + in + 2, dp, in);
      mpn_invertappr (tp, tp + in + 1, in + 1, NULL);
    }
  else
    {
      mpn_invertappr (tp, dp + dn - (in + 1), in + 1, NULL);
    }
  cy = mpn_sub_1 (tp, tp, in + 1, GMP_NUMB_HIGHBIT);
  if (UNLIKELY (cy != 0))
    MPN_ZERO (tp + 1, in);
  MPN_COPY (ip, tp + 1, in);
#endif

  qh = mpn_preinv_mu_divappr_q (qp, np, nn, dp, dn, ip, in, scratch + in);

  return qh;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %rbx
movq %rcx, %r14
movq %rdi, 0x20(%rsp)
movq %rdx, %rdi
subq %r8, %rdi
leaq 0x1(%rdi), %rbp
movq %r8, %rax
subq %rbp, %rax
jle 0x2866a
leaq (%rsi,%rax,8), %rsi
movq %rsi, 0x18(%rsp)
subq %rax, %rdx
movq %rdx, 0x10(%rsp)
leaq (%r14,%rax,8), %r14
jmp 0x28677
movq %rdx, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
movq %r8, %rbp
movq %rbp, %rsi
xorl %edx, %edx
callq 0x28775
movq %rax, %r13
leaq (%rbx,%rax,8), %r15
leaq (%rbx,%rax,8), %r12
addq $0x8, %r12
cmpq %rax, %rbp
jne 0x286d4
leaq 0x10(%r15), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x290c6
movq $0x1, 0x8(%r15)
leaq 0x1(%rbp), %rdx
leaq (%r12,%rbp,8), %rcx
addq $0x8, %rcx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2bf2e
leaq 0x8(%rbx), %rsi
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x290c6
jmp 0x28728
movq %r14, 0x8(%rsp)
leaq (%r14,%rbp,8), %rax
leaq 0x1(%r13), %r14
movq %r13, %rcx
notq %rcx
leaq (%rax,%rcx,8), %rsi
pushq $0x1
popq %rcx
movq %r12, %rdi
movq %r14, %rdx
callq 0x29e1c
testq %rax, %rax
jne 0x28758
leaq (%r12,%r13,8), %rcx
addq $0x8, %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2bf2e
leaq 0x8(%rbx), %rsi
movq %rbx, %rdi
movq %r13, %rdx
callq 0x290c6
movq 0x8(%rsp), %r14
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rcx
movq %rbp, %r8
movq %rbx, %r9
pushq %r15
pushq %r13
callq 0x287c1
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r13, %r13
movq 0x8(%rsp), %r14
je 0x28728
movq %r13, %rdx
shlq $0x3, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6170
jmp 0x28728