// File: marxn[P]pupp/3rdparty/gmp/mpn/invertappr.c
// Function: mpn_bc_invertappr
static mp_limb_t
mpn_bc_invertappr (mp_ptr ip, mp_srcptr dp, mp_size_t n, mp_ptr xp)
{
  ASSERT (n > 0);
  ASSERT (dp[n-1] & GMP_NUMB_HIGHBIT);
  ASSERT (! MPN_OVERLAP_P (ip, n, dp, n));
  ASSERT (! MPN_OVERLAP_P (ip, n, xp, mpn_invertappr_itch(n)));
  ASSERT (! MPN_OVERLAP_P (dp, n, xp, mpn_invertappr_itch(n)));

  /* Compute a base value of r limbs. */
  if (n == 1)
    invert_limb (*ip, *dp);
  else {
    mp_size_t i;

    /* n > 1 here */
    i = n;
    do
      xp[--i] = GMP_NUMB_MAX;
    while (i);
    mpn_com (xp + n, dp, n);

    /* Now xp contains B^2n - {dp,n}*B^n - 1 */

    /* FIXME: if mpn_*pi1_divappr_q handles n==2, use it! */
    if (n == 2) {
      mpn_divrem_2 (ip, 0, xp, 4, dp);
    } else {
      gmp_pi1_t inv;
      invert_pi1 (inv, dp[n-1], dp[n-2]);
      if (! MAYBE_dcpi1_divappr
	  || BELOW_THRESHOLD (n, DC_DIVAPPR_Q_THRESHOLD))
	mpn_sbpi1_divappr_q (ip, xp, 2 * n, dp, n, inv.inv32);
      else
	mpn_dcpi1_divappr_q (ip, xp, 2 * n, dp, n, &inv);
      MPN_DECR_U(ip, n, CNST_LIMB (1));
      return 1;
    }
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
jmp 0x5997a
jmp 0x5997c
jmp 0x5997e
jmp 0x59980
jmp 0x59982
jmp 0x59984
jmp 0x59986
jmp 0x59988
jmp 0x5998a
cmpq $0x1, -0x20(%rbp)
jne 0x599ae
jmp 0x59993
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x55530
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x59c1e
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $-0x1, %rdx
movq %rdx, -0x30(%rbp)
movq $-0x1, -0x8(%rax,%rcx,8)
cmpq $0x0, -0x30(%rbp)
jne 0x599b6
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x37180
cmpq $0x2, -0x20(%rbp)
jne 0x59a1b
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %r8
xorl %eax, %eax
movl %eax, %esi
movl $0x4, %ecx
callq 0x37dc0
jmp 0x59c1c
jmp 0x59a1d
jmp 0x59a1f
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x55530
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
imulq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x2, %rcx
movq (%rax,%rcx,8), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rdx
subq $0x2, %rdx
cmpq (%rcx,%rdx,8), %rax
jae 0x59af9
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rdx
subq $0x1, %rdx
cmpq (%rcx,%rdx,8), %rax
setae %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
xorl %eax, %eax
subq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x60(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x60(%rbp), %rcx
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rdx
subq $0x1, %rdx
andq (%rax,%rdx,8), %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x2, %rcx
movq (%rax,%rcx,8), %rax
movq -0x40(%rbp), %rcx
movq %rcx, -0x70(%rbp)
mulq -0x70(%rbp)
movq %rax, -0x58(%rbp)
movq %rdx, -0x50(%rbp)
movq -0x50(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x59baa
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rdx
subq $0x1, %rdx
cmpq (%rcx,%rdx,8), %rax
setae %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x59ba8
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rdx
subq $0x1, %rdx
cmpq (%rcx,%rdx,8), %rax
ja 0x59b9a
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rdx
subq $0x2, %rdx
cmpq (%rcx,%rdx,8), %rax
jb 0x59ba6
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x59ba8
jmp 0x59baa
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x108, -0x20(%rbp)     # imm = 0x108
jge 0x59bde
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
shlq %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x38(%rbp), %r9
callq 0x50ac0
jmp 0x59bfe
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
shlq %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
leaq -0x38(%rbp), %r9
callq 0x52c00
jmp 0x59c00
movq -0x10(%rbp), %rax
subq $0x1, (%rax)
leaq 0x8(%rax), %rax
jb 0x59c04
movq %rax, -0x68(%rbp)
movq $0x1, -0x8(%rbp)
jmp 0x59c26
jmp 0x59c1e
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq