// File: /workspace/github_c_makefile_star2_O1/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, %rbp
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), %r13
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
leaq 0x180(%rsp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm1, 0x10(%rsi)
movq 0x20(%rdx), %rax
movq %rax, 0x20(%rsi)
movdqu (%rdx), %xmm0
movdqu 0x10(%rdx), %xmm1
movdqu 0x28(%rdx), %xmm2
paddq %xmm0, %xmm2
movdqu 0x38(%rdx), %xmm0
paddq %xmm1, %xmm0
movdqu %xmm2, (%rdx)
movdqu %xmm0, 0x10(%rdx)
movq 0x48(%rdx), %rax
addq %rax, 0x20(%rdx)
movq %r15, %rdi
callq 0x1615
movq 0x20(%rbp), %rax
leaq 0x150(%rsp), %r14
movq %rax, 0x20(%r14)
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movaps %xmm1, 0x10(%r14)
movaps %xmm0, (%r14)
movdqu (%rbp), %xmm0
movdqu 0x10(%rbp), %xmm1
movdqu 0x28(%rbp), %xmm2
paddq %xmm0, %xmm2
movdqu 0x38(%rbp), %xmm0
paddq %xmm1, %xmm0
movdqu %xmm2, (%rbp)
movdqu %xmm0, 0x10(%rbp)
movq 0x48(%rbp), %rax
addq %rax, 0x20(%rbp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x1615
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x1198
leaq 0x60(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1198
movq 0x20(%rbx), %rax
movq %rax, 0x20(%r14)
movaps (%rbx), %xmm0
movaps 0x10(%rbx), %xmm1
movaps %xmm1, 0x10(%r14)
movaps %xmm0, (%r14)
movdqa (%rbp), %xmm0
paddq (%rbx), %xmm0
movdqa 0x10(%rbp), %xmm1
movdqa %xmm0, (%rbx)
paddq 0x10(%rbx), %xmm1
movdqa %xmm1, 0x10(%rbx)
addq 0x20(%rbp), %rax
movq %rax, 0x20(%rbx)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1615
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x14c8
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %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