// File: marxn[P]pupp/3rdparty/gmp/mpn/toom_eval_pm2exp.c
// Function: _gmpn_toom_eval_pm2exp
int
mpn_toom_eval_pm2exp (mp_ptr xp2, mp_ptr xm2, unsigned k,
		      mp_srcptr xp, mp_size_t n, mp_size_t hn, unsigned shift,
		      mp_ptr tp)
{
  unsigned i;
  int neg;
#if HAVE_NATIVE_mpn_addlsh_n
  mp_limb_t cy;
#endif

  ASSERT (k >= 3);
  ASSERT (shift*k < GMP_NUMB_BITS);

  ASSERT (hn > 0);
  ASSERT (hn <= n);

  /* The degree k is also the number of full-size coefficients, so
   * that last coefficient, of size hn, starts at xp + k*n. */

#if HAVE_NATIVE_mpn_addlsh_n
  xp2[n] = mpn_addlsh_n (xp2, xp, xp + 2*n, n, 2*shift);
  for (i = 4; i < k; i += 2)
    xp2[n] += mpn_addlsh_n (xp2, xp2, xp + i*n, n, i*shift);

  tp[n] = mpn_lshift (tp, xp+n, n, shift);
  for (i = 3; i < k; i+= 2)
    tp[n] += mpn_addlsh_n (tp, tp, xp+i*n, n, i*shift);

  if (k & 1)
    {
      cy = mpn_addlsh_n (tp, tp, xp+k*n, hn, k*shift);
      MPN_INCR_U (tp + hn, n+1 - hn, cy);
    }
  else
    {
      cy = mpn_addlsh_n (xp2, xp2, xp+k*n, hn, k*shift);
      MPN_INCR_U (xp2 + hn, n+1 - hn, cy);
    }

#else /* !HAVE_NATIVE_mpn_addlsh_n */
  xp2[n] = mpn_lshift (tp, xp+2*n, n, 2*shift);
  xp2[n] += mpn_add_n (xp2, xp, tp, n);
  for (i = 4; i < k; i += 2)
    {
      xp2[n] += mpn_lshift (tp, xp + i*n, n, i*shift);
      xp2[n] += mpn_add_n (xp2, xp2, tp, n);
    }

  tp[n] = mpn_lshift (tp, xp+n, n, shift);
  for (i = 3; i < k; i+= 2)
    {
      tp[n] += mpn_lshift (xm2, xp + i*n, n, i*shift);
      tp[n] += mpn_add_n (tp, tp, xm2, n);
    }

  xm2[hn] = mpn_lshift (xm2, xp + k*n, hn, k*shift);
  if (k & 1)
    mpn_add (tp, tp, n+1, xm2, hn+1);
  else
    mpn_add (xp2, xp2, n+1, xm2, hn+1);
#endif /* !HAVE_NATIVE_mpn_addlsh_n */

  neg = (mpn_cmp (xp2, tp, n + 1) < 0) ? ~0 : 0;

#if HAVE_NATIVE_mpn_add_n_sub_n
  if (neg)
    mpn_add_n_sub_n (xp2, xm2, tp, xp2, n + 1);
  else
    mpn_add_n_sub_n (xp2, xm2, xp2, tp, n + 1);
#else /* !HAVE_NATIVE_mpn_add_n_sub_n */
  if (neg)
    mpn_sub_n (xm2, tp, xp2, n + 1);
  else
    mpn_sub_n (xm2, xp2, tp, n + 1);

  mpn_add_n (xp2, xp2, tp, n + 1);
#endif /* !HAVE_NATIVE_mpn_add_n_sub_n */

  /* FIXME: the following asserts are useless if (k+1)*shift >= GMP_LIMB_BITS */
  ASSERT ((k+1)*shift >= GMP_LIMB_BITS ||
	  xp2[n] < ((CNST_LIMB(1)<<((k+1)*shift))-1)/((CNST_LIMB(1)<<shift)-1));
  ASSERT ((k+2)*shift >= GMP_LIMB_BITS ||
	  xm2[n] < ((CNST_LIMB(1)<<((k+2)*shift))-((k&1)?(CNST_LIMB(1)<<shift):1))/((CNST_LIMB(1)<<(2*shift))-1));

  return neg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
jmp 0x4a298
jmp 0x4a29a
jmp 0x4a29c
jmp 0x4a29e
jmp 0x4a2a0
jmp 0x4a2a2
jmp 0x4a2a4
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rax
shlq %rax
shlq $0x3, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rcx
movl 0x10(%rbp), %r8d
shll %r8d
callq 0x55cb0
movq %rax, %rdx
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x4, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x4a337
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x34(%rbp), %eax
imulq -0x28(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rcx
movl -0x34(%rbp), %r8d
imull 0x10(%rbp), %r8d
callq 0x55cb0
movq %rax, %rdx
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x34(%rbp)
jmp 0x4a2e4
movq 0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movq -0x28(%rbp), %rdx
movl 0x10(%rbp), %ecx
callq 0x37320
movq %rax, %rdx
movq 0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x3, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x4a3bf
movq 0x18(%rbp), %rdi
movq 0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x34(%rbp), %eax
imulq -0x28(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rcx
movl -0x34(%rbp), %r8d
imull 0x10(%rbp), %r8d
callq 0x55cb0
movq %rax, %rdx
movq 0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x34(%rbp)
jmp 0x4a36c
movl -0x14(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4a428
movq 0x18(%rbp), %rdi
movq 0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x14(%rbp), %eax
imulq -0x28(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdx
movq -0x30(%rbp), %rcx
movl -0x14(%rbp), %r8d
imull 0x10(%rbp), %r8d
callq 0x55cb0
movq %rax, -0x40(%rbp)
movq 0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq -0x40(%rbp), %rcx
addq %rcx, (%rax)
jae 0x4a41e
addq $0x1, 0x8(%rax)
leaq 0x8(%rax), %rax
jb 0x4a413
movq %rax, -0x48(%rbp)
jmp 0x4a424
jmp 0x4a426
jmp 0x4a486
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x14(%rbp), %eax
imulq -0x28(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdx
movq -0x30(%rbp), %rcx
movl -0x14(%rbp), %r8d
imull 0x10(%rbp), %r8d
callq 0x55cb0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq -0x40(%rbp), %rcx
addq %rcx, (%rax)
jae 0x4a47c
addq $0x1, 0x8(%rax)
leaq 0x8(%rax), %rax
jb 0x4a471
movq %rax, -0x50(%rbp)
jmp 0x4a482
jmp 0x4a484
jmp 0x4a486
movq -0x8(%rbp), %rdi
movq 0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
addq $0x1, %rdx
callq 0x3b060
movl %eax, %edx
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0x0, %edx
cmovll %ecx, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x4a4ce
movq -0x10(%rbp), %rdi
movq 0x18(%rbp), %rsi
movq -0x8(%rbp), %rdx
movq -0x28(%rbp), %rcx
addq $0x1, %rcx
callq 0x36fe0
jmp 0x4a4e7
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq 0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
addq $0x1, %rcx
callq 0x36fe0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq 0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
addq $0x1, %rcx
callq 0x36c80
jmp 0x4a502
jmp 0x4a504
jmp 0x4a506
movl -0x38(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop