// File: /workspace/github_cpp_makefile_star2_O2/marxn[P]pupp/3rdparty/gmp/mpn/toom32_mul.c
// Function: _gmpn_toom32_mul
void
mpn_toom32_mul (mp_ptr pp,
		mp_srcptr ap, mp_size_t an,
		mp_srcptr bp, mp_size_t bn,
		mp_ptr scratch)
{
  mp_size_t n, s, t;
  int vm1_neg;
  mp_limb_t cy;
  mp_limb_signed_t hi;
  mp_limb_t ap1_hi, bp1_hi;

#define a0  ap
#define a1  (ap + n)
#define a2  (ap + 2 * n)
#define b0  bp
#define b1  (bp + n)

  /* Required, to ensure that s + t >= n. */
  ASSERT (bn + 2 <= an && an + 6 <= 3*bn);

  n = 1 + (2 * an >= 3 * bn ? (an - 1) / (size_t) 3 : (bn - 1) >> 1);

  s = an - 2 * n;
  t = bn - n;

  ASSERT (0 < s && s <= n);
  ASSERT (0 < t && t <= n);
  ASSERT (s + t >= n);

  /* Product area of size an + bn = 3*n + s + t >= 4*n + 2. */
#define ap1 (pp)		/* n, most significant limb in ap1_hi */
#define bp1 (pp + n)		/* n, most significant bit in bp1_hi */
#define am1 (pp + 2*n)		/* n, most significant bit in hi */
#define bm1 (pp + 3*n)		/* n */
#define v1 (scratch)		/* 2n + 1 */
#define vm1 (pp)		/* 2n + 1 */
#define scratch_out (scratch + 2*n + 1) /* Currently unused. */

  /* Scratch need: 2*n + 1 + scratch for the recursive multiplications. */

  /* FIXME: Keep v1[2*n] and vm1[2*n] in scalar variables? */

  /* Compute ap1 = a0 + a1 + a3, am1 = a0 - a1 + a3 */
  ap1_hi = mpn_add (ap1, a0, n, a2, s);
#if HAVE_NATIVE_mpn_add_n_sub_n
  if (ap1_hi == 0 && mpn_cmp (ap1, a1, n) < 0)
    {
      ap1_hi = mpn_add_n_sub_n (ap1, am1, a1, ap1, n) >> 1;
      hi = 0;
      vm1_neg = 1;
    }
  else
    {
      cy = mpn_add_n_sub_n (ap1, am1, ap1, a1, n);
      hi = ap1_hi - (cy & 1);
      ap1_hi += (cy >> 1);
      vm1_neg = 0;
    }
#else
  if (ap1_hi == 0 && mpn_cmp (ap1, a1, n) < 0)
    {
      ASSERT_NOCARRY (mpn_sub_n (am1, a1, ap1, n));
      hi = 0;
      vm1_neg = 1;
    }
  else
    {
      hi = ap1_hi - mpn_sub_n (am1, ap1, a1, n);
      vm1_neg = 0;
    }
  ap1_hi += mpn_add_n (ap1, ap1, a1, n);
#endif

  /* Compute bp1 = b0 + b1 and bm1 = b0 - b1. */
  if (t == n)
    {
#if HAVE_NATIVE_mpn_add_n_sub_n
      if (mpn_cmp (b0, b1, n) < 0)
	{
	  cy = mpn_add_n_sub_n (bp1, bm1, b1, b0, n);
	  vm1_neg ^= 1;
	}
      else
	{
	  cy = mpn_add_n_sub_n (bp1, bm1, b0, b1, n);
	}
      bp1_hi = cy >> 1;
#else
      bp1_hi = mpn_add_n (bp1, b0, b1, n);

      if (mpn_cmp (b0, b1, n) < 0)
	{
	  ASSERT_NOCARRY (mpn_sub_n (bm1, b1, b0, n));
	  vm1_neg ^= 1;
	}
      else
	{
	  ASSERT_NOCARRY (mpn_sub_n (bm1, b0, b1, n));
	}
#endif
    }
  else
    {
      /* FIXME: Should still use mpn_add_n_sub_n for the main part. */
      bp1_hi = mpn_add (bp1, b0, n, b1, t);

      if (mpn_zero_p (b0 + t, n - t) && mpn_cmp (b0, b1, t) < 0)
	{
	  ASSERT_NOCARRY (mpn_sub_n (bm1, b1, b0, t));
	  MPN_ZERO (bm1 + t, n - t);
	  vm1_neg ^= 1;
	}
      else
	{
	  ASSERT_NOCARRY (mpn_sub (bm1, b0, n, b1, t));
	}
    }

  TOOM32_MUL_N_REC (v1, ap1, bp1, n, scratch_out);
  if (ap1_hi == 1)
    {
      cy = bp1_hi + mpn_add_n (v1 + n, v1 + n, bp1, n);
    }
  else if (ap1_hi == 2)
    {
#if HAVE_NATIVE_mpn_addlsh1_n
      cy = 2 * bp1_hi + mpn_addlsh1_n (v1 + n, v1 + n, bp1, n);
#else
      cy = 2 * bp1_hi + mpn_addmul_1 (v1 + n, bp1, n, CNST_LIMB(2));
#endif
    }
  else
    cy = 0;
  if (bp1_hi != 0)
    cy += mpn_add_n (v1 + n, v1 + n, ap1, n);
  v1[2 * n] = cy;

  TOOM32_MUL_N_REC (vm1, am1, bm1, n, scratch_out);
  if (hi)
    hi = mpn_add_n (vm1+n, vm1+n, bm1, n);

  vm1[2*n] = hi;

  /* v1 <-- (v1 + vm1) / 2 = x0 + x2 */
  if (vm1_neg)
    {
#if HAVE_NATIVE_mpn_rsh1sub_n
      mpn_rsh1sub_n (v1, v1, vm1, 2*n+1);
#else
      mpn_sub_n (v1, v1, vm1, 2*n+1);
      ASSERT_NOCARRY (mpn_rshift (v1, v1, 2*n+1, 1));
#endif
    }
  else
    {
#if HAVE_NATIVE_mpn_rsh1add_n
      mpn_rsh1add_n (v1, v1, vm1, 2*n+1);
#else
      mpn_add_n (v1, v1, vm1, 2*n+1);
      ASSERT_NOCARRY (mpn_rshift (v1, v1, 2*n+1, 1));
#endif
    }

  /* We get x1 + x3 = (x0 + x2) - (x0 - x1 + x2 - x3), and hence

     y = x1 + x3 + (x0 + x2) * B
       = (x0 + x2) * B + (x0 + x2) - vm1.

     y is 3*n + 1 limbs, y = y0 + y1 B + y2 B^2. We store them as
     follows: y0 at scratch, y1 at pp + 2*n, and y2 at scratch + n
     (already in place, except for carry propagation).

     We thus add

   B^3  B^2   B    1
    |    |    |    |
   +-----+----+
 + |  x0 + x2 |
   +----+-----+----+
 +      |  x0 + x2 |
	+----------+
 -      |  vm1     |
 --+----++----+----+-
   | y2  | y1 | y0 |
   +-----+----+----+

  Since we store y0 at the same location as the low half of x0 + x2, we
  need to do the middle sum first. */

  hi = vm1[2*n];
  cy = mpn_add_n (pp + 2*n, v1, v1 + n, n);
  MPN_INCR_U (v1 + n, n + 1, cy + v1[2*n]);

  /* FIXME: Can we get rid of this second vm1_neg conditional by
     swapping the location of +1 and -1 values? */
  if (vm1_neg)
    {
      cy = mpn_add_n (v1, v1, vm1, n);
      hi += mpn_add_nc (pp + 2*n, pp + 2*n, vm1 + n, n, cy);
      MPN_INCR_U (v1 + n, n+1, hi);
    }
  else
    {
      cy = mpn_sub_n (v1, v1, vm1, n);
      hi += mpn_sub_nc (pp + 2*n, pp + 2*n, vm1 + n, n, cy);
      MPN_DECR_U (v1 + n, n+1, hi);
    }

  TOOM32_MUL_N_REC (pp, a0, b0, n, scratch_out);
  /* vinf, s+t limbs.  Use mpn_mul for now, to handle unbalanced operands */
  if (s > t)  mpn_mul (pp+3*n, a2, s, b1, t);
  else        mpn_mul (pp+3*n, b1, t, a2, s);

  /* Remaining interpolation.

     y * B + x0 + x3 B^3 - x0 B^2 - x3 B
     = (x1 + x3) B + (x0 + x2) B^2 + x0 + x3 B^3 - x0 B^2 - x3 B
     = y0 B + y1 B^2 + y3 B^3 + Lx0 + H x0 B
       + L x3 B^3 + H x3 B^4 - Lx0 B^2 - H x0 B^3 - L x3 B - H x3 B^2
     = L x0 + (y0 + H x0 - L x3) B + (y1 - L x0 - H x3) B^2
       + (y2 - (H x0 - L x3)) B^3 + H x3 B^4

	  B^4       B^3       B^2        B         1
 |         |         |         |         |         |
   +-------+                   +---------+---------+
   |  Hx3  |                   | Hx0-Lx3 |    Lx0  |
   +------+----------+---------+---------+---------+
	  |    y2    |  y1     |   y0    |
	  ++---------+---------+---------+
	  -| Hx0-Lx3 | - Lx0   |
	   +---------+---------+
		      | - Hx3  |
		      +--------+

    We must take into account the carry from Hx0 - Lx3.
  */

  cy = mpn_sub_n (pp + n, pp + n, pp+3*n, n);
  hi = scratch[2*n] + cy;

  cy = mpn_sub_nc (pp + 2*n, pp + 2*n, pp, n, cy);
  hi -= mpn_sub_nc (pp + 3*n, scratch + n, pp + n, n, cy);

  hi += mpn_add (pp + n, pp + n, 3*n, scratch, n);

  /* FIXME: Is support for s + t == n needed? */
  if (LIKELY (s + t > n))
    {
      hi -= mpn_sub (pp + 2*n, pp + 2*n, 2*n, pp + 4*n, s+t-n);

      if (hi < 0)
	MPN_DECR_U (pp + 4*n, s+t-n, -hi);
      else
	MPN_INCR_U (pp + 4*n, s+t-n, hi);
    }
  else
    ASSERT (hi == 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, %rbx
movq %rcx, 0x38(%rsp)
movq %rdx, %r9
movq %rsi, %r15
movq %rdi, %rbp
leaq (%rdx,%rdx), %rax
leaq (%r8,%r8,2), %rcx
cmpq %rcx, %rax
jge 0x1c8e4
leaq -0x1(%r8), %r13
sarq %r13
jmp 0x1c8f3
leaq -0x1(%r9), %rax
pushq $0x3
popq %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %r13
leaq 0x2(,%r13,2), %r12
incq %r13
subq %r12, %r9
subq %r13, %r8
movq %r8, 0x50(%rsp)
movq %r13, %rcx
shlq $0x4, %rcx
addq %r15, %rcx
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rcx, 0x68(%rsp)
movq %r9, 0x80(%rsp)
movq %r9, %r8
callq 0x17c54
movq %rax, %r14
movq %r15, 0x70(%rsp)
leaq (%r15,%r13,8), %r15
testq %rax, %rax
movq %rbx, 0x10(%rsp)
movq %r12, 0x48(%rsp)
jne 0x1c962
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x1ac5c
testl %eax, %eax
js 0x1ca80
leaq (,%r12,8), %rdi
addq %rbp, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x17ed0
cmpq %rax, %r14
sete 0x28(%rsp)
movl $0x0, 0x8(%rsp)
movq %rbp, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x17cf0
addq %r14, %rax
movq %rax, 0x30(%rsp)
movq %r13, %r12
leaq (,%r13,8), %rdi
addq %rbp, %rdi
movq 0x38(%rsp), %r14
leaq (%r14,%r13,8), %r15
movq 0x50(%rsp), %rbx
subq %rbx, %r12
movq %rbp, 0x40(%rsp)
movq %rdi, 0x18(%rsp)
movq %r15, 0x60(%rsp)
jne 0x1ca11
movq %r14, %rbx
movq %r14, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x17cf0
movq %rax, %r12
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x1ac5c
imulq $0x18, %r13, %rdi
addq %rbp, %rdi
testl %eax, %eax
js 0x1ca66
movq %rbx, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x17ed0
jmp 0x1ca79
movq %r14, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x17c54
movq %rax, 0x20(%rsp)
leaq (%r14,%rbx,8), %rdi
movq %r12, %rsi
callq 0x2b954
testl %eax, %eax
je 0x1ca49
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1ac5c
testl %eax, %eax
js 0x1caaa
imulq $0x18, %r13, %rdi
addq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x17dc8
jmp 0x1cae7
movq %r15, %rsi
movq %rbx, %rdx
movq %r13, %rcx
callq 0x17ed0
xorl $0x1, 0x8(%rsp)
movq 0x10(%rsp), %rbx
jmp 0x1caf1
leaq (,%r12,8), %rdi
addq %rbp, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x17ed0
movb $0x1, 0x28(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x8(%rsp)
jmp 0x1c98b
imulq $0x18, %r13, %rbp
addq 0x40(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x17ed0
leaq (,%rbx,8), %rdi
addq %rbp, %rdi
movq 0x40(%rsp), %rbp
shlq $0x3, %r12
xorl %esi, %esi
movq %r12, %rdx
callq 0x6170
xorl $0x1, 0x8(%rsp)
movq 0x10(%rsp), %rbx
movq 0x20(%rsp), %r12
movq %rbx, %rdi
movq %rbp, %rsi
movq 0x18(%rsp), %r14
movq %r14, %rdx
movq %r13, %rcx
callq 0x19500
movq 0x30(%rsp), %rax
cmpq $0x2, %rax
je 0x1cb32
cmpq $0x1, %rax
jne 0x1cb4a
leaq (%rbx,%r13,8), %rdi
movq %rdi, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x17cf0
movq %rax, %r15
addq %r12, %r15
jmp 0x1cb4d
leaq (%rbx,%r13,8), %rdi
movq %rdi, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x291c0
leaq (%rax,%r12,2), %r15
jmp 0x1cb4d
xorl %r15d, %r15d
testq %r12, %r12
je 0x1cb67
leaq (%rbx,%r13,8), %rdi
movq %rdi, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x17cf0
addq %rax, %r15
movq 0x48(%rsp), %r14
movq %r15, (%rbx,%r14,8)
leaq (,%r14,8), %rsi
addq %rbp, %rsi
leaq (%r13,%r13,2), %rax
movq %rax, 0x78(%rsp)
leaq (%rbp,%rax,8), %r12
movq %rbp, %rdi
movq %rsi, 0x30(%rsp)
movq %r12, %rdx
movq %r13, %rcx
callq 0x19500
cmpb $0x0, 0x28(%rsp)
movq %r12, 0x20(%rsp)
je 0x1cbad
xorl %eax, %eax
jmp 0x1cbc0
movq 0x18(%rsp), %rdi
movq %rdi, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x17cf0
movq 0x30(%rsp), %r12
movq %rax, (%r12)
movq %r14, %rcx
orq $0x1, %rcx
cmpl $0x0, 0x8(%rsp)
je 0x1cbe7
movq %rbx, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x29630
jmp 0x1cbf5
movq %rbx, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x294f0
movq (%r12), %rax
movq %rax, 0x58(%rsp)
leaq (%rbx,%r13,8), %r15
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x17cf0
addq (%rbx,%r14,8), %rax
movq %r15, %rcx
addq %rax, (%rcx)
jae 0x1cc2a
addq $0x1, 0x8(%rcx)
leaq 0x8(%rcx), %rcx
jb 0x1cc1f
cmpl $0x0, 0x8(%rsp)
je 0x1cc72
movq %rbx, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x17cf0
movq %r12, %rdi
movq %r12, %rsi
movq 0x18(%rsp), %rdx
movq %r13, %rcx
movq %rax, %r8
callq 0x17cd0
addq 0x58(%rsp), %rax
movq %r15, %rcx
addq %rax, (%rcx)
jae 0x1cc70
addq $0x1, 0x8(%rcx)
leaq 0x8(%rcx), %rcx
jb 0x1cc65
jmp 0x1ccb1
movq %rbx, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x17ed0
movq %r12, %rdi
movq %r12, %rsi
movq 0x18(%rsp), %rdx
movq %r13, %rcx
movq %rax, %r8
callq 0x17eb0
addq 0x58(%rsp), %rax
movq %r15, %rcx
subq %rax, (%rcx)
jae 0x1ccb1
subq $0x1, 0x8(%rcx)
leaq 0x8(%rcx), %rcx
jb 0x1cca6
movq 0x70(%rsp), %rsi
movq %rbp, %rdi
movq 0x38(%rsp), %rdx
movq %r13, %rcx
callq 0x19500
movq 0x80(%rsp), %rbx
movq 0x50(%rsp), %r14
cmpq %r14, %rbx
movq 0x20(%rsp), %r12
movq %r15, 0x28(%rsp)
movq %r12, %rdi
jle 0x1ccf7
movq 0x68(%rsp), %rsi
movq %rbx, %rdx
movq 0x60(%rsp), %rcx
movq %r14, %r8
jmp 0x1cd07
movq 0x60(%rsp), %rsi
movq %r14, %rdx
movq 0x68(%rsp), %rcx
movq %rbx, %r8
callq 0x18a58
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x17ed0
movq %rax, %r8
movq 0x48(%rsp), %rax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %r14
movq 0x30(%rsp), %r15
movq %r15, %rdi
movq %r15, %rsi
movq 0x40(%rsp), %r12
movq %r12, %rdx
movq %r13, %rcx
movq %r8, 0x8(%rsp)
callq 0x17eb0
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %rax, %r8
callq 0x17eb0
movq %rax, 0x38(%rsp)
movq %rbp, %rdi
movq %rbp, %rsi
movq 0x78(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r13, %r8
callq 0x17c54
addq 0x50(%rsp), %rbx
subq %r13, %rbx
jle 0x1cdef
movq %rax, %rbp
addq 0x8(%rsp), %r14
shlq $0x5, %r13
addq %r13, %r12
movq %r15, %rdi
movq %r15, %rsi
movq 0x48(%rsp), %rdx
movq %r12, %rcx
movq %rbx, %r8
callq 0x17dc8
addq %rbp, %r14
addq 0x38(%rsp), %rax
subq %rax, %r14
js 0x1cdd9
addq %r14, (%r12)
jae 0x1cdd7
addq $0x1, 0x8(%r12)
leaq 0x8(%r12), %r12
jb 0x1cdca
jmp 0x1cdef
negq %r14
subq %r14, (%r12)
jae 0x1cdef
subq $0x1, 0x8(%r12)
leaq 0x8(%r12), %r12
jb 0x1cde2
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)