// File: /workspace/github_c_makefile_star2_O1/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 0x28aa
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 0x2b92
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, 0x40(%r14,%rax)
incq %rax
cmpq %rax, %r13
jne 0x2b82
leaq 0x20(%r14), %rsi
movaps 0xb0(%rsp), %xmm0
movaps 0xc0(%rsp), %xmm1
movups %xmm1, 0x30(%r14)
movups %xmm0, 0x20(%r14)
addq $0x20, %r13
leaq 0x10(%rsp), %rdi
movq %rsi, 0x8(%rsp)
movq %r13, %rdx
callq 0x28aa
xorl %eax, %eax
movzbl 0x10(%rsp,%rax), %ecx
movq %rcx, 0xd0(%rsp,%rax,8)
incq %rax
cmpq $0x40, %rax
jne 0x2bc8
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r13
movaps %xmm0, 0x30(%r13)
movaps %xmm0, 0x20(%r13)
movaps %xmm0, 0x10(%r13)
movaps %xmm0, (%r13)
leaq 0xd0(%rsp), %rsi
movq %r13, %rdi
callq 0x2d6f
leaq 0x187f(%rip), %rax      # 0x4490
leaq 0xd0(%rsp), %rbp
movl $0x10, %ecx
movq %rbp, %rdi
movq %rax, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x150(%rsp), %rdi
leaq 0x18da(%rip), %rdx      # 0x4510
movl $0x10, %ecx
movq %rdx, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x1d0(%rsp), %rdi
leaq 0x1940(%rip), %rsi      # 0x4590
movl $0x10, %ecx
rep  movsq (%rsi), %es:(%rdi)
leaq 0x250(%rsp), %rdi
movq %rax, %rsi
callq 0x22ad
leaq 0x2d0(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x32f0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2a9b
movl $0x20, %eax
movb (%r15,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq $0x40, %rax
jne 0x2c8e
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x28aa
xorl %eax, %eax
movzbl 0x50(%rsp,%rax), %ecx
movq %rcx, 0xd0(%rsp,%rax,8)
incq %rax
cmpq $0x40, %rax
jne 0x2cb1
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
leaq 0xd0(%rsp), %rsi
callq 0x2d6f
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 0x2d04
xorl %eax, %eax
movzbl 0x50(%rsp,%rax), %ecx
xorl %edx, %edx
movzbl 0x90(%rsp,%rdx), %esi
imulq %rcx, %rsi
addq %rsi, (%r14,%rdx,8)
incq %rdx
cmpq $0x20, %rdx
jne 0x2d23
incq %rax
addq $0x8, %r14
cmpq $0x20, %rax
jne 0x2d1c
leaq 0xd0(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x2d6f
xorl %eax, %eax
addq $0x4d8, %rsp            # imm = 0x4D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq