// File: /workspace/github_c_makefile_star2_O2/sbp[P]tweetnacl-tools/tweetnacl.c
// Function: crypto_scalarmult_curve25519_tweet
int crypto_scalarmult(u8 *q,const u8 *n,const u8 *p)
{
  u8 z[32];
  i64 x[80],r,i;
  gf a,b,c,d,e,f;
  FOR(i,31) z[i]=n[i];
  z[31]=(n[31]&127)|64;
  z[0]&=248;
  unpack25519(x,p);
  FOR(i,16) {
    b[i]=x[i];
    d[i]=a[i]=c[i]=0;
  }
  a[0]=d[0]=1;
  for(i=254;i>=0;--i) {
    r=(z[i>>3]>>(i&7))&1;
    sel25519(a,b,r);
    sel25519(c,d,r);
    A(e,a,c);
    Z(a,a,c);
    A(c,b,d);
    Z(b,b,d);
    S(d,e);
    S(f,a);
    M(a,c,a);
    M(c,b,e);
    A(e,a,c);
    Z(a,a,c);
    S(b,a);
    Z(c,d,f);
    M(a,c,_121665);
    A(a,a,d);
    M(c,c,a);
    M(a,d,f);
    M(d,b,x);
    S(b,e);
    sel25519(a,b,r);
    sel25519(c,d,r);
  }
  FOR(i,16) {
    x[i+16]=a[i];
    x[i+32]=c[i];
    x[i+48]=b[i];
    x[i+64]=d[i];
  }
  inv25519(x+32,x+32);
  M(x+16,x+16,x+32);
  pack25519(q,x+16);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5b8, %rsp            # imm = 0x5B8
movq %rdi, 0x8(%rsp)
xorl %eax, %eax
cmpq $0x1f, %rax
je 0x1d07
movb (%rsi,%rax), %cl
movb %cl, 0x10(%rsp,%rax)
incq %rax
jmp 0x1cf5
movb 0x1f(%rsi), %al
andb $0x3f, %al
orb $0x40, %al
movb %al, 0x2f(%rsp)
andb $-0x8, 0x10(%rsp)
leaq 0x2b0(%rsp), %rdi
movq %rdx, %rsi
callq 0x1f9c
xorl %eax, %eax
cmpq $0x10, %rax
je 0x1d5c
movq 0x2b0(%rsp,%rax,8), %rcx
andq $0x0, 0x130(%rsp,%rax,8)
movq %rcx, 0x1b0(%rsp,%rax,8)
andq $0x0, 0x230(%rsp,%rax,8)
andq $0x0, 0x30(%rsp,%rax,8)
incq %rax
jmp 0x1d29
pushq $0x1
popq %rax
leaq 0x30(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x230(%rsp), %r15
movq %rax, (%r15)
movl $0xfe, %eax
leaq 0x130(%rsp), %r13
testq %rax, %rax
js 0x1f05
movq %rax, (%rsp)
movq (%rsp), %rax
shrq $0x3, %rax
movzbl 0x10(%rsp,%rax), %eax
movq (%rsp), %rcx
andl $0x7, %ecx
xorl %ebx, %ebx
btl %ecx, %eax
setb %bl
movq %r15, %rdi
leaq 0x1b0(%rsp), %rbp
movq %rbp, %rsi
movl %ebx, %edx
callq 0x1fba
movq %r13, %rdi
leaq 0x30(%rsp), %r12
movq %r12, %rsi
movl %ebx, %edx
callq 0x1fba
leaq 0x530(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x1fe6
movq %r15, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2000
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x1fe6
movq %rbp, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x2000
movq %r12, %rdi
movq %r14, %rsi
callq 0x201a
leaq 0xb0(%rsp), %rdi
movq %r15, %rsi
callq 0x201a
movq %r15, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x201f
movq %r13, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x201f
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x1fe6
movq %r15, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2000
movq %rbp, %rdi
movq %r15, %rsi
callq 0x201a
movq %r13, %rdi
movq %r12, %rsi
leaq 0xb0(%rsp), %rdx
callq 0x2000
movq %r15, %rdi
movq %r13, %rsi
leaq 0x2573(%rip), %rdx      # 0x4400
callq 0x201f
movq %r15, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1fe6
movq %r13, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x201f
movq %r15, %rdi
movq %r12, %rsi
leaq 0xb0(%rsp), %rdx
callq 0x201f
movq %r12, %rdi
movq %rbp, %rsi
leaq 0x2b0(%rsp), %rdx
callq 0x201f
movq %rbp, %rdi
movq %r14, %rsi
callq 0x201a
movq %r15, %rdi
movq %rbp, %rsi
movl %ebx, %edx
callq 0x1fba
movq %r13, %rdi
movq %r12, %rsi
movl %ebx, %edx
callq 0x1fba
movq (%rsp), %rax
decq %rax
jmp 0x1d7f
xorl %eax, %eax
cmpq $0x80, %rax
je 0x1f52
movq 0x230(%rsp,%rax), %rcx
movq %rcx, 0x330(%rsp,%rax)
movq 0x130(%rsp,%rax), %rcx
movq %rcx, 0x3b0(%rsp,%rax)
movq 0x1b0(%rsp,%rax), %rcx
movq %rcx, 0x430(%rsp,%rax)
movq 0x30(%rsp,%rax), %rcx
movq %rcx, 0x4b0(%rsp,%rax)
addq $0x8, %rax
jmp 0x1f07
leaq 0x3b0(%rsp), %rbx
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x20b5
leaq 0x330(%rsp), %r14
movq %r14, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x201f
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x2133
xorl %eax, %eax
addq $0x5b8, %rsp            # imm = 0x5B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq