// File: marxn[P]pupp/3rdparty/gmp/mpn/dcpi1_div_q.c
// Function: _gmpn_dcpi1_div_q
mp_limb_t
mpn_dcpi1_div_q (mp_ptr qp, mp_ptr np, mp_size_t nn,
		 mp_srcptr dp, mp_size_t dn, gmp_pi1_t *dinv)
{
  mp_ptr tp, wp;
  mp_limb_t qh;
  mp_size_t qn;
  TMP_DECL;

  TMP_MARK;

  ASSERT (dn >= 6);
  ASSERT (nn - dn >= 3);
  ASSERT (dp[dn-1] & GMP_NUMB_HIGHBIT);

  tp = TMP_ALLOC_LIMBS (nn + 1);
  MPN_COPY (tp + 1, np, nn);
  tp[0] = 0;

  qn = nn - dn;
  wp = TMP_ALLOC_LIMBS (qn + 1);

  qh = mpn_dcpi1_divappr_q (wp, tp, nn + 1, dp, dn, dinv);

  if (wp[0] == 0)
    {
      mp_limb_t cy;

      if (qn > dn)
	mpn_mul (tp, wp + 1, qn, dp, dn);
      else
	mpn_mul (tp, dp, dn, wp + 1, qn);

      cy = (qh != 0) ? mpn_add_n (tp + qn, tp + qn, dp, dn) : 0;

      if (cy || mpn_cmp (tp, np, nn) > 0) /* At most is wrong by one, no cycle. */
	qh -= mpn_sub_1 (qp, wp + 1, qn, 1);
      else /* Same as below */
	MPN_COPY (qp, wp + 1, qn);
    }
  else
    MPN_COPY (qp, wp + 1, qn);

  TMP_FREE;
  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)
movq $0x0, -0x58(%rbp)
jmp 0x517fd
jmp 0x517ff
jmp 0x51801
jmp 0x51803
jmp 0x51805
movq -0x18(%rbp), %rax
addq $0x1, %rax
shlq $0x3, %rax
cmpq $0x7f00, %rax           # imm = 0x7F00
setbe %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x51851
movq -0x18(%rbp), %rax
leaq 0x17(,%rax,8), %rcx
andq $-0x10, %rcx
movq %rsp, %rax
subq %rcx, %rax
movq %rax, %rsp
movq %rax, -0x68(%rbp)
jmp 0x5186a
movq -0x18(%rbp), %rsi
addq $0x1, %rsi
shlq $0x3, %rsi
leaq -0x58(%rbp), %rdi
callq 0x56430
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x51874
jmp 0x51876
jmp 0x51878
jmp 0x5187a
jmp 0x5187c
jmp 0x5187e
jmp 0x51880
movq -0x38(%rbp), %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x554c6
jmp 0x51897
movq -0x38(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rax
subq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
shlq $0x3, %rax
cmpq $0x7f00, %rax           # imm = 0x7F00
setbe %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x518fa
movq -0x50(%rbp), %rax
leaq 0x17(,%rax,8), %rcx
andq $-0x10, %rcx
movq %rsp, %rax
subq %rcx, %rax
movq %rax, %rsp
movq %rax, -0x70(%rbp)
jmp 0x51913
movq -0x50(%rbp), %rsi
addq $0x1, %rsi
shlq $0x3, %rsi
leaq -0x58(%rbp), %rdi
callq 0x56430
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq $0x1, %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
callq 0x52c00
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x51a4e
movq -0x50(%rbp), %rax
cmpq -0x28(%rbp), %rax
jle 0x51977
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x8, %rsi
movq -0x50(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
callq 0x37f00
jmp 0x51994
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x40(%rbp), %rcx
addq $0x8, %rcx
movq -0x50(%rbp), %r8
callq 0x37f00
cmpq $0x0, -0x48(%rbp)
je 0x519cc
movq -0x38(%rbp), %rdi
movq -0x50(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x38(%rbp), %rsi
movq -0x50(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x36c80
movq %rax, -0x78(%rbp)
jmp 0x519d4
xorl %eax, %eax
movq %rax, -0x78(%rbp)
jmp 0x519d4
movq -0x78(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x519f9
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x3b060
cmpl $0x0, %eax
jle 0x51a23
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x8, %rsi
movq -0x50(%rbp), %rdx
movl $0x1, %ecx
callq 0x36e60
movq %rax, %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x51a4c
jmp 0x51a25
jmp 0x51a27
jmp 0x51a29
jmp 0x51a2b
jmp 0x51a2d
jmp 0x51a2f
jmp 0x51a31
jmp 0x51a33
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x8, %rsi
movq -0x50(%rbp), %rdx
callq 0x554c6
jmp 0x51a4a
jmp 0x51a4c
jmp 0x51a77
jmp 0x51a50
jmp 0x51a52
jmp 0x51a54
jmp 0x51a56
jmp 0x51a58
jmp 0x51a5a
jmp 0x51a5c
jmp 0x51a5e
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x8, %rsi
movq -0x50(%rbp), %rdx
callq 0x554c6
jmp 0x51a75
jmp 0x51a77
jmp 0x51a79
cmpq $0x0, -0x58(%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 0x51aa2
movq -0x58(%rbp), %rdi
callq 0x564a0
jmp 0x51aa4
movq -0x48(%rbp), %rax
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)