// File: /workspace/github_c_makefile_star2_O2/agl[P]obstcp/curve25519/donna_c64/smult.c
// Function: fsquare
static void
fsquare(felem *output, const felem *in) {
  uint128_t t[9];

  t[0] = ((uint128_t) in[0]) * in[0];
  t[1] = ((uint128_t) in[0]) * in[1] * 2;
  t[2] = ((uint128_t) in[0]) * in[2] * 2 +
         ((uint128_t) in[1]) * in[1];
  t[3] = ((uint128_t) in[0]) * in[3] * 2 +
         ((uint128_t) in[1]) * in[2] * 2;
  t[4] = ((uint128_t) in[0]) * in[4] * 2 +
         ((uint128_t) in[3]) * in[1] * 2 +
         ((uint128_t) in[2]) * in[2];
  t[5] = ((uint128_t) in[4]) * in[1] * 2 +
         ((uint128_t) in[2]) * in[3] * 2;
  t[6] = ((uint128_t) in[4]) * in[2] * 2 +
         ((uint128_t) in[3]) * in[3];
  t[7] = ((uint128_t) in[3]) * in[4] * 2;
  t[8] = ((uint128_t) in[4]) * in[4];

  t[0] += t[5] * 19;
  t[1] += t[6] * 19;
  t[2] += t[7] * 19;
  t[3] += t[8] * 19;

  t[1] += t[0] >> 51;
  t[0] &= 0x7ffffffffffff;
  t[2] += t[1] >> 51;
  t[1] &= 0x7ffffffffffff;
  t[3] += t[2] >> 51;
  t[2] &= 0x7ffffffffffff;
  t[4] += t[3] >> 51;
  t[3] &= 0x7ffffffffffff;
  t[0] += 19 * (t[4] >> 51);
  t[4] &= 0x7ffffffffffff;
  t[1] += t[0] >> 51;
  t[0] &= 0x7ffffffffffff;

  output[0] = t[0];
  output[1] = t[1];
  output[2] = t[2];
  output[3] = t[3];
  output[4] = t[4];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq (%rsi), %rcx
movq 0x8(%rsi), %rbx
movq %rcx, %rax
mulq %rcx
movq %rax, -0x20(%rsp)
movq %rdx, %r11
leaq (%rcx,%rcx), %r8
movq %rcx, %r10
shrq $0x3f, %r10
movq %r10, %r9
imulq %rbx, %r9
movq %r8, %rax
mulq %rbx
movq %rax, -0x10(%rsp)
addq %r9, %rdx
movq %rdx, -0x28(%rsp)
movq 0x10(%rsi), %r14
imulq %r14, %r10
movq %r8, %rax
mulq %r14
movq %rax, %r8
movq %rdx, %r9
addq %r10, %r9
movq %rbx, %rax
mulq %rbx
movq %rax, %r15
addq %r8, %r15
adcq %r9, %rdx
movq %rdx, -0x30(%rsp)
movq 0x18(%rsi), %r13
movq %r13, %rax
mulq %rcx
movq %rdx, %r8
movq %rax, %rbp
movq %r14, %rax
mulq %rbx
movq %rdx, %r12
movq %rax, %r9
addq %rbp, %r9
adcq %r8, %r12
shldq $0x1, %r9, %r12
addq %r9, %r9
movq 0x20(%rsi), %rbp
movq %rbp, %rax
mulq %rcx
movq %rdx, %rcx
movq %rax, %rsi
movq %r13, %rax
mulq %rbx
movq %rdx, %r8
movq %rax, %r10
addq %rsi, %r10
adcq %rcx, %r8
shldq $0x1, %r10, %r8
addq %r10, %r10
movq %r14, %rax
mulq %r14
addq %r10, %rax
movq %rax, -0x8(%rsp)
adcq %r8, %rdx
movq %rdx, -0x18(%rsp)
movq %rbp, %rax
mulq %rbx
movq %rdx, %r8
movq %rax, %r10
movq %r13, %rax
mulq %r14
movq %rdx, %rsi
movq %rax, %rbx
addq %r10, %rbx
adcq %r8, %rsi
movq %r14, %rax
mulq %rbp
movq %rdx, %r8
movq %rax, %r10
shldq $0x1, %rax, %r8
addq %rax, %r10
movq %r13, %rax
mulq %r13
movq %rdx, %r14
movq %rax, %rcx
addq %r10, %rcx
adcq %r8, %r14
movabsq $0x26, %r10
movq %rbx, %rax
mulq %r10
movq %rax, %rbx
imulq $0x26, %rsi, %r8
addq %rdx, %r8
addq -0x20(%rsp), %rbx
adcq %r11, %r8
imulq $0x13, %r14, %r11
movabsq $0x13, %rdx
movq %rcx, %rax
mulq %rdx
movq %rax, %r14
movq %rdx, %rsi
addq %r11, %rsi
addq -0x10(%rsp), %r14
adcq -0x28(%rsp), %rsi
movq %r13, %rax
mulq %rbp
movq %rdx, %rcx
mulq %r10
movq %rax, %r11
imulq $0x26, %rcx, %r13
addq %rdx, %r13
addq %r15, %r11
adcq -0x30(%rsp), %r13
movq %rbp, %rax
mulq %rbp
movq %rdx, %rcx
movabsq $0x13, %rbp
mulq %rbp
imulq $0x13, %rcx, %r15
addq %rdx, %r15
addq %r9, %rax
adcq %r12, %r15
movq %r8, %rcx
shrq $0x33, %rcx
shldq $0xd, %rbx, %r8
addq %r14, %r8
adcq %rsi, %rcx
movabsq $0x7ffffffffffff, %rsi  # imm = 0x7FFFFFFFFFFFF
andq %rsi, %rbx
movq %rcx, %r9
shldq $0xd, %r8, %rcx
shrq $0x33, %r9
addq %r11, %rcx
adcq %r13, %r9
andq %rsi, %r8
movq %r9, %r11
shldq $0xd, %rcx, %r9
shrq $0x33, %r11
addq %rax, %r9
adcq %r15, %r11
movq %r11, %rdx
shrq $0x33, %rdx
shldq $0xd, %r9, %r11
addq -0x8(%rsp), %r11
adcq -0x18(%rsp), %rdx
movq %rdx, %rax
shldq $0xd, %r11, %rax
shrq $0x33, %rdx
imulq $0x13, %rdx, %r10
mulq %rbp
addq %rbx, %rax
adcq %r10, %rdx
shldq $0xd, %rax, %rdx
addq %r8, %rdx
andq %rsi, %rax
movq %rax, (%rdi)
movq %rdx, 0x8(%rdi)
andq %rsi, %rcx
movq %rcx, 0x10(%rdi)
andq %rsi, %r9
movq %r9, 0x18(%rdi)
andq %rsi, %r11
movq %r11, 0x20(%rdi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq