// File: /workspace/github_cpp_makefile_star2_O2/marxn[P]pupp/3rdparty/gmp/mpn/divrem.c
// Function: _gmpn_divrem
mp_limb_t
mpn_divrem (mp_ptr qp, mp_size_t qxn,
	    mp_ptr np, mp_size_t nn,
	    mp_srcptr dp, mp_size_t dn)
{
  ASSERT (qxn >= 0);
  ASSERT (nn >= dn);
  ASSERT (dn >= 1);
  ASSERT (dp[dn-1] & GMP_NUMB_HIGHBIT);
  ASSERT (! MPN_OVERLAP_P (np, nn, dp, dn));
  ASSERT (! MPN_OVERLAP_P (qp, nn-dn+qxn, np, nn) || qp==np+dn+qxn);
  ASSERT (! MPN_OVERLAP_P (qp, nn-dn+qxn, dp, dn));
  ASSERT_MPN (np, nn);
  ASSERT_MPN (dp, dn);

  if (dn == 1)
    {
      mp_limb_t ret;
      mp_ptr q2p;
      mp_size_t qn;
      TMP_DECL;

      TMP_MARK;
      q2p = TMP_ALLOC_LIMBS (nn + qxn);

      np[0] = mpn_divrem_1 (q2p, qxn, np, nn, dp[0]);
      qn = nn + qxn - 1;
      MPN_COPY (qp, q2p, qn);
      ret = q2p[qn];

      TMP_FREE;
      return ret;
    }
  else if (dn == 2)
    {
      return mpn_divrem_2 (qp, qxn, np, nn, dp);
    }
  else
    {
      mp_ptr rp, q2p;
      mp_limb_t qhl;
      mp_size_t qn;
      TMP_DECL;

      TMP_MARK;
      if (UNLIKELY (qxn != 0))
	{
	  mp_ptr n2p;
	  n2p = TMP_ALLOC_LIMBS (nn + qxn);
	  MPN_ZERO (n2p, qxn);
	  MPN_COPY (n2p + qxn, np, nn);
	  q2p = TMP_ALLOC_LIMBS (nn - dn + qxn + 1);
	  rp = TMP_ALLOC_LIMBS (dn);
	  mpn_tdiv_qr (q2p, rp, 0L, n2p, nn + qxn, dp, dn);
	  MPN_COPY (np, rp, dn);
	  qn = nn - dn + qxn;
	  MPN_COPY (qp, q2p, qn);
	  qhl = q2p[qn];
	}
      else
	{
	  q2p = TMP_ALLOC_LIMBS (nn - dn + 1);
	  rp = TMP_ALLOC_LIMBS (dn);
	  mpn_tdiv_qr (q2p, rp, 0L, np, nn, dp, dn);
	  MPN_COPY (np, rp, dn);	/* overwrite np area with remainder */
	  qn = nn - dn;
	  MPN_COPY (qp, q2p, qn);
	  qhl = q2p[qn];
	}
      TMP_FREE;
      return qhl;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r13
movq %r8, %r9
movq %rcx, %rax
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
cmpq $0x2, %r13
je 0x18445
cmpq $0x1, %r13
jne 0x18467
movq %r14, %r13
andq $0x0, -0x38(%rbp)
leaq (%rax,%rbx), %r14
leaq (,%r14,8), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
ja 0x1852c
movq %rsp, %r12
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r12
movq %r12, %rsp
movq (%r9), %r8
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %rax, %rcx
callq 0x18700
movq %rax, (%r15)
leaq -0x1(%r14), %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0x290c6
movq -0x8(%r12,%r14,8), %rbx
jmp 0x1850a
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %rax, %rcx
movq %r9, %r8
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x18920
andq $0x0, -0x38(%rbp)
testq %rbx, %rbx
jne 0x1854b
movq %rax, %rbx
subq %r13, %rbx
leaq 0x8(,%rbx,8), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
ja 0x1864a
movq %rsp, %r12
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r12
movq %r12, %rsp
movq %r14, -0x40(%rbp)
leaq (,%r13,8), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
ja 0x18669
movq %rsp, %r14
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r14
movq %r14, %rsp
subq $0x8, %rsp
movq %r12, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %rax, %r8
pushq %r13
callq 0x1b900
popq %rax
popq %rcx
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x290c6
movq -0x40(%rbp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x290c6
leaq (%r12,%rbx,8), %rax
movq (%rax), %rbx
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
jne 0x18525
movq %rbx, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x29df3
jmp 0x18513
leaq -0x38(%rbp), %rdi
movq %rax, -0x30(%rbp)
movq %r9, %r12
callq 0x29dc0
movq %r12, %r9
movq %rax, %r12
movq -0x30(%rbp), %rax
jmp 0x18415
leaq (%rax,%rbx), %rcx
leaq (,%rcx,8), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
movq %rax, -0x30(%rbp)
movq %r9, -0x48(%rbp)
movq %rcx, -0x40(%rbp)
ja 0x18688
movq %rsp, %r12
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r12
movq %r12, %rsp
leaq (,%rbx,8), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x6170
movq %r12, -0x50(%rbp)
leaq (%r12,%rbx,8), %rdi
movq %r15, %rsi
movq -0x30(%rbp), %r12
movq %r12, %rdx
callq 0x290c6
subq %r13, %r12
addq %rbx, %r12
leaq 0x8(,%r12,8), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
ja 0x18699
movq %rsp, %rbx
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %rbx
movq %rbx, %rsp
movq -0x48(%rbp), %r9
leaq (,%r13,8), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
movq %r12, -0x30(%rbp)
ja 0x186aa
movq %rsp, %r12
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r12
movq %r12, %rsp
subq $0x8, %rsp
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq -0x50(%rbp), %rcx
movq -0x40(%rbp), %r8
pushq %r13
callq 0x1b900
popq %rax
popq %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x290c6
movq %r14, %rdi
movq %rbx, %rsi
movq -0x30(%rbp), %r14
movq %r14, %rdx
callq 0x290c6
leaq (%rbx,%r14,8), %rax
jmp 0x18507
leaq -0x38(%rbp), %rdi
movq %rax, -0x30(%rbp)
movq %r9, %r12
callq 0x29dc0
movq %r12, %r9
movq %rax, %r12
movq -0x30(%rbp), %rax
jmp 0x184a1
leaq -0x38(%rbp), %rdi
movq %rax, -0x30(%rbp)
movq %r9, %r14
callq 0x29dc0
movq %r14, %r9
movq %rax, %r14
movq -0x30(%rbp), %rax
jmp 0x184cb
leaq -0x38(%rbp), %rdi
callq 0x29dc0
movq %rax, %r12
jmp 0x18581
leaq -0x38(%rbp), %rdi
callq 0x29dc0
movq %rax, %rbx
jmp 0x185d6
leaq -0x38(%rbp), %rdi
movq %r9, %r12
callq 0x29dc0
movq %r12, %r9
movq %rax, %r12
jmp 0x18604
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)