// File: marxn[P]pupp/3rdparty/gmp/./mini-gmp/mini-gmp.c
// Function: mpz_div_qr
static int
mpz_div_qr (mpz_t q, mpz_t r,
	    const mpz_t n, const mpz_t d, enum mpz_div_round_mode mode)
{
  mp_size_t ns, ds, nn, dn, qs;
  ns = n->_mp_size;
  ds = d->_mp_size;

  if (ds == 0)
    gmp_die("mpz_div_qr: Divide by zero.");

  if (ns == 0)
    {
      if (q)
	q->_mp_size = 0;
      if (r)
	r->_mp_size = 0;
      return 0;
    }

  nn = GMP_ABS (ns);
  dn = GMP_ABS (ds);

  qs = ds ^ ns;

  if (nn < dn)
    {
      if (mode == GMP_DIV_CEIL && qs >= 0)
	{
	  /* q = 1, r = n - d */
	  if (r)
	    mpz_sub (r, n, d);
	  if (q)
	    mpz_set_ui (q, 1);
	}
      else if (mode == GMP_DIV_FLOOR && qs < 0)
	{
	  /* q = -1, r = n + d */
	  if (r)
	    mpz_add (r, n, d);
	  if (q)
	    mpz_set_si (q, -1);
	}
      else
	{
	  /* q = 0, r = d */
	  if (r)
	    mpz_set (r, n);
	  if (q)
	    q->_mp_size = 0;
	}
      return 1;
    }
  else
    {
      mp_ptr np, qp;
      mp_size_t qn, rn;
      mpz_t tq, tr;

      mpz_init_set (tr, n);
      np = tr->_mp_d;

      qn = nn - dn + 1;

      if (q)
	{
	  mpz_init2 (tq, qn * GMP_LIMB_BITS);
	  qp = tq->_mp_d;
	}
      else
	qp = NULL;

      mpn_div_qr (qp, np, nn, d->_mp_d, dn);

      if (qp)
	{
	  qn -= (qp[qn-1] == 0);

	  tq->_mp_size = qs < 0 ? -qn : qn;
	}
      rn = mpn_normalized_size (np, dn);
      tr->_mp_size = ns < 0 ? - rn : rn;

      if (mode == GMP_DIV_FLOOR && qs < 0 && rn != 0)
	{
	  if (q)
	    mpz_sub_ui (tq, tq, 1);
	  if (r)
	    mpz_add (tr, tr, d);
	}
      else if (mode == GMP_DIV_CEIL && qs >= 0 && rn != 0)
	{
	  if (q)
	    mpz_add_ui (tq, tq, 1);
	  if (r)
	    mpz_sub (tr, tr, d);
	}

      if (q)
	{
	  mpz_swap (tq, q);
	  mpz_clear (tq);
	}
      if (r)
	mpz_swap (tr, r);

      mpz_clear (tr);

      return rn != 0;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movslq 0x4(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movslq 0x4(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x534a
leaq 0xa2d3(%rip), %rdi      # 0xf618
callq 0x7b50
cmpq $0x0, -0x38(%rbp)
jne 0x5381
cmpq $0x0, -0x10(%rbp)
je 0x5363
movq -0x10(%rbp), %rax
movl $0x0, 0x4(%rax)
cmpq $0x0, -0x18(%rbp)
je 0x5375
movq -0x18(%rbp), %rax
movl $0x0, 0x4(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x56b4
cmpq $0x0, -0x38(%rbp)
jl 0x5395
movq -0x38(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0x53a2
xorl %eax, %eax
subq -0x38(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x40(%rbp)
jl 0x53c1
movq -0x40(%rbp), %rax
movq %rax, -0xb0(%rbp)
jmp 0x53ce
xorl %eax, %eax
subq -0x40(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
xorq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jge 0x54a3
cmpl $0x1, -0x2c(%rbp)
jne 0x542f
cmpq $0x0, -0x58(%rbp)
jl 0x542f
cmpq $0x0, -0x18(%rbp)
je 0x5418
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x4c50
cmpq $0x0, -0x10(%rbp)
je 0x542d
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x3350
jmp 0x5497
cmpl $0x0, -0x2c(%rbp)
jne 0x546d
cmpq $0x0, -0x58(%rbp)
jge 0x546d
cmpq $0x0, -0x18(%rbp)
je 0x5454
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x48a0
cmpq $0x0, -0x10(%rbp)
je 0x546b
movq -0x10(%rbp), %rdi
movq $-0x1, %rsi
callq 0x32f0
jmp 0x5495
cmpq $0x0, -0x18(%rbp)
je 0x5481
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3390
cmpq $0x0, -0x10(%rbp)
je 0x5493
movq -0x10(%rbp), %rax
movl $0x0, 0x4(%rax)
jmp 0x5495
jmp 0x5497
movl $0x1, -0x4(%rbp)
jmp 0x56b4
leaq -0xa0(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3550
movq -0x98(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x54f6
leaq -0x90(%rbp), %rdi
movq -0x70(%rbp), %rsi
shlq $0x6, %rsi
callq 0x3250
movq -0x88(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x54fe
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x50(%rbp), %r8
callq 0xc570
cmpq $0x0, -0x68(%rbp)
je 0x5577
movq -0x68(%rbp), %rax
movq -0x70(%rbp), %rcx
subq $0x1, %rcx
cmpq $0x0, (%rax,%rcx,8)
sete %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x70(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x58(%rbp)
jge 0x555f
xorl %eax, %eax
subq -0x70(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x556a
movq -0x70(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movl %eax, -0x8c(%rbp)
movq -0x60(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x14d0
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x38(%rbp)
jge 0x559e
xorl %eax, %eax
subq -0x78(%rbp), %rax
movq %rax, -0xc0(%rbp)
jmp 0x55a9
movq -0x78(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movl %eax, -0x9c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x5609
cmpq $0x0, -0x58(%rbp)
jge 0x5609
cmpq $0x0, -0x78(%rbp)
je 0x5609
cmpq $0x0, -0x10(%rbp)
je 0x55e9
leaq -0x90(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movl $0x1, %edx
callq 0x47c0
cmpq $0x0, -0x18(%rbp)
je 0x5607
leaq -0xa0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x48a0
jmp 0x565e
cmpl $0x1, -0x2c(%rbp)
jne 0x565c
cmpq $0x0, -0x58(%rbp)
jl 0x565c
cmpq $0x0, -0x78(%rbp)
je 0x565c
cmpq $0x0, -0x10(%rbp)
je 0x563c
leaq -0x90(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movl $0x1, %edx
callq 0x4510
cmpq $0x0, -0x18(%rbp)
je 0x565a
leaq -0xa0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x4c50
jmp 0x565c
jmp 0x565e
cmpq $0x0, -0x10(%rbp)
je 0x5681
leaq -0x90(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4480
leaq -0x90(%rbp), %rdi
callq 0x32c0
cmpq $0x0, -0x18(%rbp)
je 0x5698
leaq -0xa0(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4480
leaq -0xa0(%rbp), %rdi
callq 0x32c0
cmpq $0x0, -0x78(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq