// File: /workspace/github_c_makefile_star2_O3/sbp[P]tweetnacl-tools/tweetnacl.c
// Function: crypto_sign_ed25519_tweet
int crypto_sign(u8 *sm,u64 *smlen,const u8 *m,u64 n,const u8 *sk)
{
  u8 d[64],h[64],r[64];
  i64 i,j,x[64];
  gf p[4];

  crypto_hash(d, sk, 32);
  d[0] &= 248;
  d[31] &= 127;
  d[31] |= 64;

  *smlen = n+64;
  FOR(i,n) sm[64 + i] = m[i];
  FOR(i,32) sm[32 + i] = d[32 + i];

  crypto_hash(r, sm+32, n+32);
  reduce(r);
  scalarbase(p,r);
  pack(sm,p);

  FOR(i,32) sm[i+32] = sk[i+32];
  crypto_hash(h,sm,n + 64);
  reduce(h);

  FOR(i,64) x[i] = 0;
  FOR(i,32) x[i] = (u64) r[i];
  FOR(i,32) FOR(j,32) x[i+j] += h[i] * (u64) d[j];
  modL(sm + 32,x);

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4d8, %rsp            # imm = 0x4D8
movq %r8, %r15
movq %rcx, %r13
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r14
leaq 0x90(%rsp), %r12
movl $0x20, %edx
movq %r12, %rdi
movq %r8, %rsi
callq 0x29ed
andb $-0x8, (%r12)
movb 0x1f(%r12), %al
andb $0x3f, %al
orb $0x40, %al
movb %al, 0x1f(%r12)
leaq 0x40(%r13), %r12
movq %r12, (%rbp)
testq %r13, %r13
je 0x2cd5
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, 0x40(%r14,%rax)
incq %rax
cmpq %rax, %r13
jne 0x2cc5
leaq 0x20(%r14), %rsi
movdqa 0xb0(%rsp), %xmm0
movdqa 0xc0(%rsp), %xmm1
movdqu %xmm1, 0x30(%r14)
movdqu %xmm0, 0x20(%r14)
addq $0x20, %r13
leaq 0x10(%rsp), %rdi
movq %rsi, 0x8(%rsp)
movq %r13, %rdx
callq 0x29ed
xorl %eax, %eax
movzbl 0x10(%rsp,%rax), %ecx
movq %rcx, 0xd0(%rsp,%rax,8)
incq %rax
cmpq $0x40, %rax
jne 0x2d0f
pxor %xmm0, %xmm0
leaq 0x10(%rsp), %r13
movdqa %xmm0, 0x30(%r13)
movdqa %xmm0, 0x20(%r13)
movdqa %xmm0, 0x10(%r13)
movdqa %xmm0, (%r13)
leaq 0xd0(%rsp), %rsi
movq %r13, %rdi
callq 0x2eeb
leaq 0x1743(%rip), %rax      # 0x44a0
leaq 0xd0(%rsp), %rbp
movl $0x10, %ecx
movq %rbp, %rdi
movq %rax, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x150(%rsp), %rdi
leaq 0x179e(%rip), %rdx      # 0x4520
movl $0x10, %ecx
movq %rdx, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x1d0(%rsp), %rdi
leaq 0x1804(%rip), %rsi      # 0x45a0
movl $0x10, %ecx
rep  movsq (%rsi), %es:(%rdi)
leaq 0x250(%rsp), %rdi
movq %rax, %rsi
callq 0x2393
leaq 0x2d0(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x34f0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2bde
movl $0x20, %eax
movb (%r15,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq $0x40, %rax
jne 0x2dda
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x29ed
xorl %eax, %eax
movzbl 0x50(%rsp,%rax), %ecx
movq %rcx, 0xd0(%rsp,%rax,8)
incq %rax
cmpq $0x40, %rax
jne 0x2dfd
pxor %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movdqa %xmm0, 0x30(%rdi)
movdqa %xmm0, 0x20(%rdi)
movdqa %xmm0, 0x10(%rdi)
movdqa %xmm0, (%rdi)
leaq 0xd0(%rsp), %rsi
callq 0x2eeb
leaq 0xd0(%rsp), %r14
xorl %ebx, %ebx
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
xorl %esi, %esi
callq 0x1060
movzbl 0x10(%rsp,%rbx), %eax
movq %rax, 0xd0(%rsp,%rbx,8)
incq %rbx
cmpq $0x20, %rbx
jne 0x2e55
xorl %eax, %eax
pxor %xmm0, %xmm0
movzbl 0x50(%rsp,%rax), %ecx
movd %ecx, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
xorl %ecx, %ecx
movzwl 0x90(%rsp,%rcx), %edx
movd %edx, %xmm2
punpcklbw %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1],xmm2[2],xmm0[2],xmm2[3],xmm0[3],xmm2[4],xmm0[4],xmm2[5],xmm0[5],xmm2[6],xmm0[6],xmm2[7],xmm0[7]
punpcklwd %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1],xmm2[2],xmm0[2],xmm2[3],xmm0[3]
pshufd $0xd4, %xmm2, %xmm2     # xmm2 = xmm2[0,1,1,3]
pmuludq %xmm1, %xmm2
movdqu (%r14,%rcx,8), %xmm3
paddq %xmm2, %xmm3
movdqu %xmm3, (%r14,%rcx,8)
addq $0x2, %rcx
cmpq $0x20, %rcx
jne 0x2e81
incq %rax
addq $0x8, %r14
cmpq $0x20, %rax
jne 0x2e71
leaq 0xd0(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x2eeb
xorl %eax, %eax
addq $0x4d8, %rsp            # imm = 0x4D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq