// File: /workspace/github_c_makefile_star2_O1/sbp[P]tweetnacl-tools/tweetnacl.c
// Function: crypto_sign_ed25519_tweet_open
int crypto_sign_open(u8 *m,u64 *mlen,const u8 *sm,u64 n,const u8 *pk)
{
  int i;
  u8 t[32],h[64];
  gf p[4],q[4];

  *mlen = -1;
  if (n < 64) return -1;

  if (unpackneg(q,pk)) return -1;

  FOR(i,n) m[i] = sm[i];
  FOR(i,32) m[i+32] = pk[i];
  crypto_hash(h,m,n);
  reduce(h);
  scalarmult(p,q,h);

  scalarbase(q,sm + 32);
  add(p,q);
  pack(t,p);

  n -= 64;
  if (crypto_verify_32(sm, t)) {
    FOR(i,n) m[i] = 0;
    return -1;
  }

  FOR(i,n) m[i] = sm[i + 64];
  *mlen = n;
  return 0;
}

// Assembly:
movq $-0x1, (%rsi)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq $0x40, %rcx
jb 0x3149
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x928, %rsp            # imm = 0x928
movq %r8, %r13
movq %rdx, %r12
movq %rsi, 0x18(%rsp)
movq %rdi, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
leaq 0x2a0(%rsp), %rdi
leaq 0x16ea(%rip), %rsi      # 0x4590
movl $0x10, %ecx
rep  movsq (%rsi), %es:(%rdi)
leaq 0x220(%rsp), %rsi
xorl %eax, %eax
movzwl (%r13,%rax,2), %ecx
movq %rcx, 0x220(%rsp,%rax,8)
incq %rax
cmpq $0x10, %rax
jne 0x2eb8
andq $0x7fff, 0x298(%rsp) # imm = 0x7FFF
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
movq %rsi, %rdx
callq 0x22ad
leaq 0x181b(%rip), %rdx      # 0x4710
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x22ad
xorl %eax, %eax
movq 0x2a0(%rsp,%rax,8), %rcx
subq %rcx, 0xa0(%rsp,%rax,8)
incq %rax
cmpq $0x10, %rax
jne 0x2f04
xorl %eax, %eax
movq 0x2a0(%rsp,%rax,8), %rcx
addq %rcx, 0x20(%rsp,%rax,8)
incq %rax
cmpq $0x10, %rax
jne 0x2f1f
leaq 0x6a0(%rsp), %rbp
leaq 0x20(%rsp), %r15
movq %rbp, %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x22ad
leaq 0x620(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %rbp, %rdx
callq 0x22ad
leaq 0x5a0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x22ad
leaq 0x720(%rsp), %rbp
leaq 0xa0(%rsp), %rdx
movq %rbp, %rdi
movq %r14, %rsi
callq 0x22ad
movq %rbp, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x22ad
leaq 0x3a0(%rsp), %r15
movl $0x10, %ecx
movq %r15, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0xfb, %ebx
movq %r15, %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x22ad
cmpl $0x2, %ebx
je 0x2fe1
movq %r15, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x22ad
decl %ebx
jne 0x2fc0
leaq 0x720(%rsp), %rbx
leaq 0x3a0(%rsp), %rsi
movl $0x10, %ecx
movq %rbx, %rdi
rep  movsq (%rsi), %es:(%rdi)
leaq 0xa0(%rsp), %rbp
movq %rbx, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x22ad
leaq 0x20(%rsp), %r14
movq %rbx, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x22ad
movq %rbx, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x22ad
leaq 0x1a0(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x22ad
leaq 0x120(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x22ad
movq %rbx, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x22ad
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x367c
testl %eax, %eax
je 0x3097
leaq 0x1709(%rip), %rdx      # 0x4790
leaq 0x1a0(%rsp), %rdi
movq %rdi, %rsi
callq 0x22ad
leaq 0x120(%rsp), %rbx
leaq 0x1a0(%rsp), %rdx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x22ad
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x22ad
leaq 0xa0(%rsp), %rsi
movq %rbx, %rdi
callq 0x367c
testl %eax, %eax
jne 0x3133
movl %eax, %ebp
leaq 0x3a0(%rsp), %rbx
leaq 0x1a0(%rsp), %rsi
movq %rbx, %rdi
callq 0x23b6
movb (%rbx), %al
andb $0x1, %al
movb 0x1f(%r13), %cl
shrb $0x7, %cl
cmpb %cl, %al
jne 0x3112
xorl %eax, %eax
negq 0x1a0(%rsp,%rax,8)
incq %rax
cmpq $0x10, %rax
jne 0x3101
leaq 0x320(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
leaq 0x220(%rsp), %rdx
callq 0x22ad
testl %ebp, %ebp
je 0x314a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x928, %rsp            # imm = 0x928
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdx
cmpq $0x1, %rdx
movq %rdx, %rax
adcq $0x0, %rax
xorl %ecx, %ecx
movq 0x8(%rsp), %rsi
movb (%r12,%rcx), %dil
movb %dil, (%rsi,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x3161
xorl %eax, %eax
movb (%r13,%rax), %cl
movb %cl, 0x20(%rsi,%rax)
incq %rax
cmpq $0x20, %rax
jne 0x3173
leaq 0x120(%rsp), %rdi
callq 0x28aa
xorl %eax, %eax
movzbl 0x120(%rsp,%rax), %ecx
movq %rcx, 0x3a0(%rsp,%rax,8)
incq %rax
cmpq $0x40, %rax
jne 0x3194
xorps %xmm0, %xmm0
leaq 0x120(%rsp), %rbx
movaps %xmm0, 0x30(%rbx)
movaps %xmm0, 0x20(%rbx)
movaps %xmm0, 0x10(%rbx)
movaps %xmm0, (%rbx)
leaq 0x3a0(%rsp), %rsi
movq %rbx, %rdi
callq 0x2d6f
leaq 0x720(%rsp), %r13
leaq 0x1a0(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x32f0
leaq 0x20(%r12), %rbx
leaq 0x128f(%rip), %rax      # 0x4490
leaq 0x3a0(%rsp), %r14
movl $0x10, %ecx
movq %r14, %rdi
movq %rax, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x420(%rsp), %rdi
leaq 0x12ea(%rip), %rdx      # 0x4510
movl $0x10, %ecx
movq %rdx, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x4a0(%rsp), %rdi
leaq 0x1350(%rip), %rsi      # 0x4590
movl $0x10, %ecx
rep  movsq (%rsi), %es:(%rdi)
leaq 0x520(%rsp), %rdi
movq %rax, %rsi
callq 0x22ad
movq %rbp, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x32f0
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3401
leaq 0x3a0(%rsp), %rdi
movq %r13, %rsi
callq 0x2a9b
xorl %eax, %eax
xorl %ecx, %ecx
movb 0x3a0(%rsp,%rcx), %dl
xorb (%r12,%rcx), %dl
movzbl %dl, %edx
orq %rdx, %rax
incq %rcx
cmpq $0x20, %rcx
jne 0x3285
movq 0x10(%rsp), %rdx
addq $-0x40, %rdx
decl %eax
btl $0x8, %eax
movq 0x8(%rsp), %rdi
jb 0x32ca
testq %rdx, %rdx
je 0x3133
xorl %esi, %esi
callq 0x1060
jmp 0x3133
testq %rdx, %rdx
je 0x32e1
xorl %eax, %eax
movb 0x40(%r12,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x32d1
movq 0x18(%rsp), %rax
movq %rdx, (%rax)
xorl %eax, %eax
jmp 0x3138