// File: /workspace/github_cpp_makefile_star2_O1/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, 0x18(%rsp)
movq %rdx, %r12
subq %r8, %r12
leaq 0x1(%r12), %rbp
movq %r8, %rax
subq %rbp, %rax
jle 0x2e731
leaq (%rsi,%rax,8), %rsi
subq %rax, %rdx
leaq (%r14,%rax,8), %r14
jmp 0x2e734
movq %r8, %rbp
cmpq %rbp, %r12
movq %rdx, 0x10(%rsp)
jle 0x2e75c
decq %r12
movq %r12, %rax
cqto
idivq %rbp
movq %rax, %rcx
incq %rcx
movq %r12, %rax
cqto
idivq %rcx
movq %rax, %r12
jmp 0x2e777
leaq (%r12,%r12,2), %rax
cmpq %rbp, %rax
jle 0x2e77a
leaq -0x1(%r12), %rax
shrq $0x3f, %rax
addq %rax, %r12
decq %r12
sarq %r12
incq %r12
leaq (%rbx,%r12,8), %r15
leaq (%rbx,%r12,8), %r13
addq $0x8, %r13
cmpq %r12, %rbp
movq %rsi, 0x20(%rsp)
jne 0x2e7d7
leaq 0x10(%r15), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2f4c6
movq $0x1, 0x8(%rbx,%r12,8)
leaq 0x1(%r12), %rdx
leaq 0x8(,%r12,8), %rcx
addq %r13, %rcx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x32b48
leaq 0x8(%rbx), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x2f4c6
jmp 0x2e8ce
movq %r15, 0x8(%rsp)
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 0x2e86a
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 0x2e8fe
movq (%rsi,%r10,8), %r11
leaq 0x1(%r10), %r9
incq %r11
movq %r11, (%rcx,%r10,8)
movq %r9, %r10
je 0x2e82d
cmpq %r13, %rdi
je 0x2e8a4
leaq 0x1(%r9), %rax
cmpq %r12, %rax
jg 0x2e8a4
movq (%rsi,%r9,8), %rax
movq %rax, (%rcx,%r9,8)
incq %r9
cmpq %r12, %r9
jl 0x2e858
jmp 0x2e8a4
testq %r12, %r12
jle 0x2e8a4
cmpq %r13, %rdi
je 0x2e8a4
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 0x2e894
leaq 0x8(,%r12,8), %rcx
addq %r13, %rcx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x32b48
leaq 0x8(%rbx), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x2f4c6
movq 0x8(%rsp), %r15
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rcx
movq %rbp, %r8
movq %rbx, %r9
pushq %r15
pushq %r12
callq 0x2e96e
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r12, %r12
movq 0x8(%rsp), %r15
je 0x2e8ce
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x6170
jmp 0x2e8ce