// File: /workspace/github_c_makefile_star2_O2/agl[P]obstcp/curve25519/donna/smult.c
// Function: fmonty
void __attribute__((visibility ("hidden")))
fmonty(felem *x2,  /* output 2Q */
       felem *x3,  /* output Q + Q' */
       felem *x,    /* input Q */
       felem *xprime,  /* input Q' */
       const felem *qmqp /* input Q - Q' */) {
  felem *const z2 = &x2[5];
  felem *const z3 = &x3[5];
  felem *const z = &x[5];
  felem *const zprime = &xprime[5];
  felem origx[5], origxprime[5], zzz[5], xx[5], zz[5], xxprime[5],
        zzprime[5], zzzprime[5];

  memcpy(origx, x, 5 * sizeof(felem));
  fsum(x, z);
  fdifference_backwards(z, origx);  // does x - z

  memcpy(origxprime, xprime, sizeof(felem) * 5);
  fsum(xprime, zprime);
  fdifference_backwards(zprime, origxprime);
  fmul(xxprime, xprime, z);
  fmul(zzprime, x, zprime);
  memcpy(origxprime, xxprime, sizeof(felem) * 5);
  fsum(xxprime, zzprime);
  fdifference_backwards(zzprime, origxprime);
  fsquare(x3, xxprime);
  fsquare(zzzprime, zzprime);
  fmul(z3, zzzprime, qmqp);

  fsquare(xx, x);
  fsquare(zz, z);
  fmul(x2, xx, zz);
  fdifference_backwards(zz, xx);  // does zz = xx - zz
  fscalar(zzz, zz); // * 121665
  freduce_coefficients(zzz);
  fsum(zzz, xx);
  fmul(z2, zz, zzz);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %r8, 0x18(%rsp)
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, 0x8(%rsp)
movq %rdi, 0x20(%rsp)
leaq 0x28(%rdi), %rax
movq %rax, 0x28(%rsp)
leaq 0x28(%rsi), %rax
movq %rax, 0x10(%rsp)
leaq 0x28(%rdx), %r15
leaq 0x28(%rcx), %rbp
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
leaq 0x180(%rsp), %rbx
movaps %xmm0, (%rbx)
movaps %xmm1, 0x10(%rbx)
movq 0x20(%rdx), %rax
movq %rax, 0x20(%rbx)
movq %rdx, %rdi
movq %r15, %rsi
callq 0x1e77
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1615
movq 0x20(%r14), %rax
leaq 0x150(%rsp), %r13
movq %rax, 0x20(%r13)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movaps %xmm1, 0x10(%r13)
movaps %xmm0, (%r13)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1e77
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1615
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1198
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x1198
movq 0x20(%rbx), %rax
movq %rax, 0x20(%r13)
movaps (%rbx), %xmm0
movaps 0x10(%rbx), %xmm1
movaps %xmm1, 0x10(%r13)
movaps %xmm0, (%r13)
movdqa (%r14), %xmm0
paddq (%rbx), %xmm0
movdqa 0x10(%r14), %xmm1
movdqa %xmm0, (%rbx)
paddq 0x10(%rbx), %xmm1
movdqa %xmm1, 0x10(%rbx)
addq 0x20(%r14), %rax
movq %rax, 0x20(%rbx)
movq %r14, %rdi
movq %r13, %rsi
callq 0x1615
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x14c8
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x14c8
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
callq 0x1198
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x14c8
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x14c8
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1198
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1615
leaq 0x120(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1710
movq %r15, %rdi
callq 0x178c
movdqa (%rbx), %xmm0
movdqa 0x10(%rbx), %xmm1
paddq (%r15), %xmm0
movdqa %xmm0, (%r15)
paddq 0x10(%r15), %xmm1
movdqa %xmm1, 0x10(%r15)
movq 0x20(%rbx), %rax
addq %rax, 0x20(%r15)
movq 0x28(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1198
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq