// File: /workspace/github_c_makefile_star2_O2/sbp[P]tweetnacl-tools/tweetnacl.c
// Function: crypto_onetimeauth_poly1305_tweet
int crypto_onetimeauth(u8 *out,const u8 *m,u64 n,const u8 *k)
{
  u32 s,i,j,u,x[17],r[17],h[17],c[17],g[17];

  FOR(j,17) r[j]=h[j]=0;
  FOR(j,16) r[j]=k[j];
  r[3]&=15;
  r[4]&=252;
  r[7]&=15;
  r[8]&=252;
  r[11]&=15;
  r[12]&=252;
  r[15]&=15;

  while (n > 0) {
    FOR(j,17) c[j] = 0;
    for (j = 0;(j < 16) && (j < n);++j) c[j] = m[j];
    c[j] = 1;
    m += j; n -= j;
    add1305(h,c);
    FOR(i,17) {
      x[i] = 0;
      FOR(j,17) x[i] += h[j] * ((j <= i) ? r[i - j] : 320 * r[i + 17 - j]);
    }
    FOR(i,17) h[i] = x[i];
    u = 0;
    FOR(j,16) {
      u += h[j];
      h[j] = u & 255;
      u >>= 8;
    }
    u += h[16]; h[16] = u & 3;
    u = 5 * (u >> 2);
    FOR(j,16) {
      u += h[j];
      h[j] = u & 255;
      u >>= 8;
    }
    u += h[16]; h[16] = u;
  }

  FOR(j,17) g[j] = h[j];
  add1305(h,minusp);
  s = -(h[16] >> 7);
  FOR(j,17) h[j] ^= s & (g[j] ^ h[j]);

  FOR(j,16) c[j] = k[j + 16];
  c[16] = 0;
  add1305(h,c);
  FOR(j,16) out[j] = h[j];
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2c8, %rsp            # imm = 0x2C8
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
xorl %eax, %eax
cmpq $0x11, %rax
je 0x1982
andq $0x0, (%rsp,%rax,8)
andq $0x0, 0x120(%rsp,%rax,8)
incq %rax
jmp 0x1969
xorl %eax, %eax
cmpq $0x10, %rax
je 0x199c
movzbl (%r14,%rax), %ecx
movq %rcx, 0x120(%rsp,%rax,8)
incq %rax
jmp 0x1984
movaps 0x26dd(%rip), %xmm0     # 0x4080
leaq 0x120(%rsp), %r13
movups 0x18(%r13), %xmm1
movups 0x38(%r13), %xmm2
movups 0x58(%r13), %xmm3
andps %xmm0, %xmm1
movups %xmm1, 0x18(%r13)
andps %xmm0, %xmm2
movups %xmm2, 0x38(%r13)
andps %xmm0, %xmm3
movups %xmm3, 0x58(%r13)
andq $0xf, 0x78(%r13)
xorl %eax, %eax
testq %r15, %r15
je 0x1b17
cmpq $0x11, %rax
je 0x19f6
andq $0x0, 0x90(%rsp,%rax,8)
incq %rax
jmp 0x19e2
cmpq $0x10, %r15
pushq $0x10
popq %rbp
cmovbq %r15, %rbp
xorl %eax, %eax
cmpq %rax, %rbp
je 0x1a1a
movzbl (%r12,%rax), %ecx
movq %rcx, 0x90(%rsp,%rax,8)
incq %rax
jmp 0x1a03
movq $0x1, 0x90(%rsp,%rbp,8)
addq %rbp, %r12
movq %rsp, %rdi
leaq 0x90(%rsp), %rsi
callq 0x1bbd
movq %r13, %rax
xorl %ecx, %ecx
cmpq $0x11, %rcx
je 0x1a88
movq %rax, %rsi
xorl %edx, %edx
xorl %edi, %edi
cmpq $0x11, %rdi
je 0x1a77
cmpq %rcx, %rdi
jbe 0x1a63
imulq $0x140, 0x88(%rsi), %r8 # imm = 0x140
jmp 0x1a66
movq (%rsi), %r8
imulq (%rsp,%rdi,8), %r8
addq %r8, %rdx
incq %rdi
addq $-0x8, %rsi
jmp 0x1a4b
movq %rdx, 0x240(%rsp,%rcx,8)
incq %rcx
addq $0x8, %rax
jmp 0x1a3e
xorl %eax, %eax
cmpq $0x11, %rax
je 0x1aa1
movq 0x240(%rsp,%rax,8), %rcx
movq %rcx, (%rsp,%rax,8)
incq %rax
jmp 0x1a8a
xorl %ecx, %ecx
xorl %eax, %eax
cmpq $0x10, %rcx
je 0x1abf
addq (%rsp,%rcx,8), %rax
movzbl %al, %edx
movq %rdx, (%rsp,%rcx,8)
shrq $0x8, %rax
incq %rcx
jmp 0x1aa5
addq 0x80(%rsp), %rax
movl %eax, %ecx
andl $0x3, %ecx
movq %rcx, 0x80(%rsp)
shrq $0x2, %rax
leaq (%rax,%rax,4), %rax
xorl %ecx, %ecx
cmpq $0x10, %rcx
je 0x1af8
addq (%rsp,%rcx,8), %rax
movzbl %al, %edx
movq %rdx, (%rsp,%rcx,8)
shrq $0x8, %rax
incq %rcx
jmp 0x1ade
subq %rbp, %r15
addq %rax, 0x80(%rsp)
jmp 0x19d7
movq (%rsp,%rax,8), %rcx
movq %rcx, 0x1b0(%rsp,%rax,8)
incq %rax
cmpq $0x11, %rax
jne 0x1b08
leaq 0x257c(%rip), %rsi      # 0x40a0
movq %rsp, %r15
movq %r15, %rdi
callq 0x1bbd
movq 0x80(%r15), %rax
shrq $0x7, %rax
negq %rax
xorl %ecx, %ecx
cmpq $0x11, %rcx
je 0x1b63
movq (%rsp,%rcx,8), %rdx
movq 0x1b0(%rsp,%rcx,8), %rsi
xorq %rdx, %rsi
andq %rax, %rsi
xorq %rdx, %rsi
movq %rsi, (%rsp,%rcx,8)
incq %rcx
jmp 0x1b3f
xorl %eax, %eax
cmpq $0x10, %rax
je 0x1b7e
movzbl 0x10(%r14,%rax), %ecx
movq %rcx, 0x90(%rsp,%rax,8)
incq %rax
jmp 0x1b65
leaq 0x90(%rsp), %rsi
andq $0x0, 0x80(%rsi)
movq %rsp, %rdi
callq 0x1bbd
xorl %eax, %eax
cmpq $0x10, %rax
je 0x1ba9
movb (%rsp,%rax,8), %cl
movb %cl, (%rbx,%rax)
incq %rax
jmp 0x1b98
xorl %eax, %eax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq