// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
movq %r9, %rbx
movq %r8, %rbp
movq %rcx, %r14
movq %rdx, %r8
movq %rdi, (%rsp)
movq %rdx, %r12
subq %rbp, %r12
leaq 0x1(%r12), %rax
movq %rbp, %rcx
subq %rax, %rcx
jle 0x2e386
leaq (%rsi,%rcx,8), %rsi
subq %rcx, %r8
leaq (%r14,%rcx,8), %r14
jmp 0x2e3af
cmpq %rbp, %r12
jle 0x2e3ac
decq %r12
movq %r12, %rax
cqto
idivq %rbp
movq %rax, %rcx
incq %rcx
movq %r12, %rax
cqto
idivq %rcx
movq %rax, %r12
incq %r12
jmp 0x2e3d0
movq %rbp, %rax
leaq (%r12,%r12,2), %rcx
cmpq %rax, %rcx
jle 0x2e3cd
leaq -0x1(%r12), %rcx
shrq $0x3f, %rcx
addq %rcx, %r12
decq %r12
sarq %r12
incq %r12
movq %rax, %rbp
leaq (%rbx,%r12,8), %r15
leaq (%rbx,%r12,8), %r13
addq $0x8, %r13
cmpq %r12, %rbp
movq %r8, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
jne 0x2e42b
leaq 0x10(%r15), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x2f106
movq $0x1, 0x8(%r15)
leaq 0x1(%rbp), %rdx
leaq 0x8(,%rbp,8), %rcx
addq %r13, %rcx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x32773
leaq 0x8(%rbx), %rsi
movq %rbx, %rdi
movq %rbp, %rdx
jmp 0x2e513
leaq (%r14,%rbp,8), %rax
leaq 0x1(%r12), %rdx
movq %r12, %rcx
notq %rcx
leaq (%rax,%rcx,8), %rdi
movq (%rdi), %rax
incq %rax
movq %rax, (%r13)
jne 0x2e4b9
cmpq $0x2, %rdx
movl $0x1, %r8d
cmovgeq %rdx, %r8
leaq (,%r12,8), %rax
leaq (%rbx,%r12,8), %rcx
addq $0x10, %rcx
leaq (,%rbp,8), %rsi
subq %rax, %rsi
addq %r14, %rsi
decq %r8
xorl %r10d, %r10d
cmpq %r10, %r8
je 0x2e547
movq (%rsi,%r10,8), %r11
leaq 0x1(%r10), %r9
incq %r11
movq %r11, (%rcx,%r10,8)
movq %r9, %r10
je 0x2e47c
cmpq %r13, %rdi
je 0x2e4f3
leaq 0x1(%r9), %rax
cmpq %r12, %rax
jg 0x2e4f3
movq (%rsi,%r9,8), %rax
movq %rax, (%rcx,%r9,8)
incq %r9
cmpq %r12, %r9
jl 0x2e4a7
jmp 0x2e4f3
testq %r12, %r12
jle 0x2e4f3
cmpq %r13, %rdi
je 0x2e4f3
leaq (,%r12,8), %rsi
leaq (%rbx,%r12,8), %rax
addq $0x10, %rax
leaq (,%rbp,8), %rcx
subq %rsi, %rcx
addq %r14, %rcx
xorl %esi, %esi
movq (%rcx,%rsi,8), %rdi
movq %rdi, (%rax,%rsi,8)
incq %rsi
cmpq %rsi, %r12
jne 0x2e4e3
leaq 0x8(,%r12,8), %rcx
addq %r13, %rcx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x32773
leaq 0x8(%rbx), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x2f106
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rcx
movq %rbp, %r8
movq %rbx, %r9
pushq %r15
pushq %r12
callq 0x2e5b2
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r12, %r12
je 0x2e518
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x6170
jmp 0x2e518