// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
jmp 0x54325
movq -0x18(%rbp), %rax
subq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
cmpq -0x28(%rbp), %rax
jge 0x5439b
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
addq $0x1, %rcx
subq %rcx, %rax
shlq $0x3, %rax
addq -0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rax
addq $0x1, %rax
subq %rax, %rcx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
addq $0x1, %rcx
subq %rcx, %rax
shlq $0x3, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x545a0
movq %rax, -0x40(%rbp)
jmp 0x543b0
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x40(%rbp), %rax
jne 0x54455
jmp 0x543db
jmp 0x543dd
jmp 0x543df
jmp 0x543e1
jmp 0x543e3
jmp 0x543e5
jmp 0x543e7
jmp 0x543e9
movq -0x60(%rbp), %rdi
addq $0x8, %rdi
movq -0x20(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x554c6
jmp 0x54400
movq -0x60(%rbp), %rax
movq $0x1, (%rax)
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq $0x1, %rdx
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rcx
addq $0x8, %rcx
callq 0x59cb0
jmp 0x54435
jmp 0x54437
jmp 0x54439
jmp 0x5443b
movq -0x58(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x8, %rsi
movq -0x40(%rbp), %rdx
callq 0x554c6
jmp 0x5454e
movq -0x60(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movq -0x40(%rbp), %rcx
addq $0x1, %rcx
xorl %eax, %eax
subq %rcx, %rax
shlq $0x3, %rax
addq %rax, %rsi
movq -0x40(%rbp), %rdx
addq $0x1, %rdx
movl $0x1, %ecx
callq 0x564f0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x54505
jmp 0x544b4
jmp 0x544b6
jmp 0x544b8
cmpq $0x0, -0x40(%rbp)
je 0x54501
jmp 0x544c1
movq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x544d3
jmp 0x544d5
movq -0x68(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x68(%rbp)
movq $0x0, (%rax)
movq -0x70(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, %rax
jne 0x544d5
jmp 0x544ff
jmp 0x54501
jmp 0x54503
jmp 0x5454c
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq $0x1, %rdx
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rcx
addq $0x8, %rcx
callq 0x59cb0
jmp 0x5452f
jmp 0x54531
jmp 0x54533
jmp 0x54535
movq -0x58(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x8, %rsi
movq -0x40(%rbp), %rdx
callq 0x554c6
jmp 0x5454c
jmp 0x5454e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x58(%rbp), %r9
movq -0x40(%rbp), %r10
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %r11
shlq $0x3, %r11
addq %r11, %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x54680
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)