// File: /workspace/github_c_makefile_star2_O3/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 $0x5c8, %rsp            # imm = 0x5C8
movq %rdi, 0x8(%rsp)
movdqu (%rsi), %xmm0
movdqu 0xf(%rsi), %xmm1
movdqu %xmm1, 0x1f(%rsp)
movdqa %xmm0, 0x10(%rsp)
movb 0x1f(%rsi), %al
andb $0x3f, %al
orb $0x40, %al
movb %al, 0x2f(%rsp)
andb $-0x8, 0x10(%rsp)
xorl %eax, %eax
movzwl (%rdx,%rax,2), %ecx
movq %rcx, 0x340(%rsp,%rax,8)
incq %rax
cmpq $0x10, %rax
jne 0x1efa
leaq 0x340(%rsp), %rsi
andq $0x7fff, 0x78(%rsi)     # imm = 0x7FFF
pxor %xmm0, %xmm0
leaq 0xc0(%rsp), %r15
movdqa %xmm0, (%r15)
movdqa %xmm0, 0x10(%r15)
movdqa %xmm0, 0x20(%r15)
movdqa %xmm0, 0x30(%r15)
movdqa %xmm0, 0x40(%r15)
movdqa %xmm0, 0x50(%r15)
movdqa %xmm0, 0x60(%r15)
movdqa %xmm0, 0x70(%r15)
leaq 0x40(%rsp), %r12
movdqa %xmm0, (%r12)
movdqa %xmm0, 0x10(%r12)
movdqa %xmm0, 0x20(%r12)
movdqa %xmm0, 0x30(%r12)
movdqa %xmm0, 0x40(%r12)
movdqa %xmm0, 0x50(%r12)
movdqa %xmm0, 0x60(%r12)
movdqa %xmm0, 0x70(%r12)
leaq 0x140(%rsp), %r13
movdqa %xmm0, 0x70(%r13)
movdqa %xmm0, 0x60(%r13)
movdqa %xmm0, 0x50(%r13)
movdqa %xmm0, 0x40(%r13)
movdqa %xmm0, 0x30(%r13)
movdqa %xmm0, 0x20(%r13)
movdqa %xmm0, 0x10(%r13)
movdqa %xmm0, (%r13)
leaq 0x1c0(%rsp), %rbp
movl $0x10, %ecx
movq %rbp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl $0x1, %eax
movq %rax, (%r13)
movq %rax, (%r12)
movl $0xfe, %r14d
leaq 0x2c0(%rsp), %rbx
movq %r14, %rax
shrq $0x3, %rax
movzbl 0x10(%rsp,%rax), %eax
movl %r14d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
movl $0x0, %eax
sbbq %rax, %rax
movq %rax, %xmm0
pshufd $0x44, %xmm0, %xmm3     # xmm3 = xmm0[0,1,0,1]
xorl %eax, %eax
movdqa 0x40(%rsp,%rax,8), %xmm0
movdqa 0x1c0(%rsp,%rax,8), %xmm1
movdqa %xmm1, %xmm2
pxor %xmm0, %xmm2
pand %xmm3, %xmm2
pxor %xmm2, %xmm0
movdqa %xmm0, 0x40(%rsp,%rax,8)
pxor %xmm1, %xmm2
movdqa %xmm2, 0x1c0(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x10, %rax
jne 0x2025
xorl %eax, %eax
movdqa 0xc0(%rsp,%rax,8), %xmm0
movdqa 0x140(%rsp,%rax,8), %xmm1
movdqa %xmm1, %xmm2
pxor %xmm0, %xmm2
pand %xmm3, %xmm2
pxor %xmm2, %xmm0
movdqa %xmm0, 0xc0(%rsp,%rax,8)
pxor %xmm1, %xmm2
movdqa %xmm2, 0x140(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x10, %rax
jne 0x2063
xorl %eax, %eax
movdqa 0xc0(%rsp,%rax,8), %xmm0
paddq 0x40(%rsp,%rax,8), %xmm0
movdqa %xmm0, 0x2c0(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x10, %rax
jne 0x20a7
xorl %eax, %eax
movdqa 0x40(%rsp,%rax,8), %xmm0
psubq 0xc0(%rsp,%rax,8), %xmm0
movdqa %xmm0, 0x40(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x10, %rax
jne 0x20cb
xorl %eax, %eax
movdqa 0x140(%rsp,%rax,8), %xmm0
paddq 0x1c0(%rsp,%rax,8), %xmm0
movdqa %xmm0, 0xc0(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x10, %rax
jne 0x20ec
movdqa %xmm3, 0x30(%rsp)
xorl %eax, %eax
movdqa 0x1c0(%rsp,%rax,8), %xmm0
psubq 0x140(%rsp,%rax,8), %xmm0
movdqa %xmm0, 0x1c0(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x10, %rax
jne 0x2119
movq %r13, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
callq 0x2393
leaq 0x240(%rsp), %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0x2393
movq %r12, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2393
movq %r15, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x2393
xorl %eax, %eax
movdqa 0xc0(%rsp,%rax,8), %xmm0
paddq 0x40(%rsp,%rax,8), %xmm0
movdqa %xmm0, 0x2c0(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x10, %rax
jne 0x217d
xorl %eax, %eax
movdqa 0x40(%rsp,%rax,8), %xmm0
psubq 0xc0(%rsp,%rax,8), %xmm0
movdqa %xmm0, 0x40(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x10, %rax
jne 0x21a1
movq %rbp, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0x2393
xorl %eax, %eax
movdqa 0x140(%rsp,%rax,8), %xmm0
psubq 0x240(%rsp,%rax,8), %xmm0
movdqa %xmm0, 0xc0(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x10, %rax
jne 0x21d0
movq %r12, %rdi
movq %r15, %rsi
leaq 0x21fe(%rip), %rdx      # 0x4400
callq 0x2393
xorl %eax, %eax
movdqa 0x140(%rsp,%rax,8), %xmm0
paddq 0x40(%rsp,%rax,8), %xmm0
movdqa %xmm0, 0x40(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x10, %rax
jne 0x2209
movq %r15, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2393
movq %r12, %rdi
movq %r13, %rsi
leaq 0x240(%rsp), %rdx
callq 0x2393
movq %r13, %rdi
movq %rbp, %rsi
leaq 0x340(%rsp), %rdx
callq 0x2393
movq %rbp, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
callq 0x2393
xorl %eax, %eax
movdqa 0x30(%rsp), %xmm3
movdqa 0x40(%rsp,%rax,8), %xmm0
movdqa 0x1c0(%rsp,%rax,8), %xmm1
movdqa %xmm1, %xmm2
pxor %xmm0, %xmm2
pand %xmm3, %xmm2
pxor %xmm2, %xmm0
movdqa %xmm0, 0x40(%rsp,%rax,8)
pxor %xmm1, %xmm2
movdqa %xmm2, 0x1c0(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x10, %rax
jne 0x2272
xorl %eax, %eax
movdqa 0xc0(%rsp,%rax,8), %xmm0
movdqa 0x140(%rsp,%rax,8), %xmm1
movdqa %xmm1, %xmm2
pxor %xmm0, %xmm2
pand %xmm3, %xmm2
pxor %xmm2, %xmm0
movdqa %xmm0, 0xc0(%rsp,%rax,8)
pxor %xmm1, %xmm2
movdqa %xmm2, 0x140(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x10, %rax
jne 0x22b0
subq $0x1, %r14
jae 0x1ffc
xorl %eax, %eax
movaps 0x40(%rsp,%rax), %xmm0
movaps %xmm0, 0x3c0(%rsp,%rax)
movaps 0xc0(%rsp,%rax), %xmm0
movaps %xmm0, 0x440(%rsp,%rax)
movaps 0x1c0(%rsp,%rax), %xmm0
movaps %xmm0, 0x4c0(%rsp,%rax)
movdqa 0x140(%rsp,%rax), %xmm0
movdqa %xmm0, 0x540(%rsp,%rax)
addq $0x10, %rax
cmpq $0x80, %rax
jne 0x22fe
leaq 0x440(%rsp), %rbx
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x2470
leaq 0x3c0(%rsp), %r14
movq %r14, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2393
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x24dd
xorl %eax, %eax
addq $0x5c8, %rsp            # imm = 0x5C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq