// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, -0x30(%rbp)
movq %r8, %r12
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
leaq 0x8(,%rdx,8), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
ja 0x2c8f0
movq %rsp, %rbx
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %rbx
movq %rbx, %rsp
movq %r13, -0x40(%rbp)
leaq 0x1(%r15), %rax
movq %rax, -0x38(%rbp)
leaq 0x8(%rbx), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2f106
movq $0x0, (%rbx)
movq %r15, -0x48(%rbp)
subq %r12, %r15
leaq 0x8(,%r15,8), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
ja 0x2c901
movq %rsp, %r13
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r13
movq %r13, %rsp
movq %r13, %rdi
movq %rbx, %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq %r12, %r8
movq -0x30(%rbp), %r9
callq 0x2d435
movq %rax, -0x30(%rbp)
cmpq $0x0, (%r13)
je 0x2c77b
addq $0x8, %r13
movq -0x50(%rbp), %rdi
movq %r13, %rsi
jmp 0x2c885
leaq 0x8(%r13), %rax
cmpq %r12, %r15
movq %rax, -0x38(%rbp)
movq %rbx, %rdi
jle 0x2c79a
movq %rax, %rsi
movq %r15, %rdx
movq -0x40(%rbp), %rcx
movq %r12, %r8
jmp 0x2c7a7
movq -0x40(%rbp), %rsi
movq %r12, %rdx
movq %rax, %rcx
movq %r15, %r8
callq 0x1c838
cmpq $0x0, -0x30(%rbp)
je 0x2c7cb
leaq (%rbx,%r15,8), %rdi
movq %rdi, %rsi
movq -0x40(%rbp), %rdx
movq %r12, %rcx
callq 0x1ba80
testq %rax, %rax
jne 0x2c7f1
movq -0x48(%rbp), %rax
testq %rax, %rax
jle 0x2c87d
movq -0x8(%r14,%rax,8), %rcx
leaq -0x1(%rax), %rdx
cmpq %rcx, -0x8(%rbx,%rax,8)
movq %rdx, %rax
je 0x2c7cf
jbe 0x2c87d
movq 0x8(%r13), %rax
subq $0x1, %rax
movq -0x50(%rbp), %rdi
movq %rax, (%rdi)
jae 0x2c893
cmpq $0x2, %r15
movl $0x1, %ecx
cmovgeq %r15, %rcx
decq %rcx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x2c8c7
movq 0x10(%r13,%rdx,8), %rsi
leaq 0x1(%rdx), %rax
subq $0x1, %rsi
movq %rsi, 0x8(%rdi,%rdx,8)
movq %rax, %rdx
jb 0x2c818
cmpq %rdi, -0x38(%rbp)
setne %cl
leaq 0x1(%rax), %rdx
cmpq %r15, %rdx
setl %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2c879
leaq (%rdi,%rax,8), %rdi
addq $0x8, %rdi
leaq 0x10(,%rax,8), %rsi
addq %r13, %rsi
notq %r12
addq -0x48(%rbp), %r12
subq %rax, %r12
shlq $0x3, %r12
movq %r12, %rdx
callq 0x6200
xorl %eax, %eax
jmp 0x2c8ce
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r15, %rdx
callq 0x2f106
movq -0x30(%rbp), %rbx
jmp 0x2c8d5
xorl %eax, %eax
cmpq $0x2, %r15
jl 0x2c8ce
cmpq %rdi, -0x38(%rbp)
movq -0x30(%rbp), %rbx
je 0x2c8d2
addq $0x8, %rdi
addq $0x10, %r13
notq %r12
addq -0x48(%rbp), %r12
shlq $0x3, %r12
movq %r13, %rsi
movq %r12, %rdx
callq 0x6200
xorl %eax, %eax
jmp 0x2c8d2
movq $-0x1, %rax
movq -0x30(%rbp), %rbx
addq %rax, %rbx
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
jne 0x2c912
movq %rbx, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x2fdb0
movq %rax, %rbx
jmp 0x2c6f7
leaq -0x58(%rbp), %rdi
callq 0x2fdb0
movq %rax, %r13
jmp 0x2c746
callq 0x2fde3
jmp 0x2c8de
nopl (%rax)