// File: /workspace/github_c_makefile_star2_O3/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
movq %rsp, %rdi
xorl %r13d, %r13d
movl $0x88, %edx
xorl %esi, %esi
callq 0x1060
leaq 0x90(%rsp), %rdi
movl $0x88, %edx
xorl %esi, %esi
callq 0x1060
movzbl (%r14,%r13), %eax
movq %rax, 0x90(%rsp,%r13,8)
incq %r13
cmpq $0x10, %r13
jne 0x1a6f
movaps 0x25f4(%rip), %xmm0     # 0x4080
movups 0xa8(%rsp), %xmm1
movups 0xc8(%rsp), %xmm2
movups 0xe8(%rsp), %xmm3
andps %xmm0, %xmm1
movups %xmm1, 0xa8(%rsp)
andps %xmm0, %xmm2
movups %xmm2, 0xc8(%rsp)
andps %xmm0, %xmm3
movups %xmm3, 0xe8(%rsp)
andq $0xf, 0x108(%rsp)
testq %r15, %r15
je 0x1c16
leaq 0x240(%rsp), %rbp
movl $0x88, %edx
leaq 0x120(%rsp), %rdi
xorl %esi, %esi
callq 0x1060
cmpq $0x10, %r15
movl $0x10, %r13d
cmovbq %r15, %r13
xorl %eax, %eax
movzbl (%r12,%rax), %ecx
movq %rcx, 0x120(%rsp,%rax,8)
incq %rax
cmpq %rax, %r13
jne 0x1b03
movq $0x1, 0x120(%rsp,%r13,8)
addq %r13, %r12
xorl %eax, %eax
xorl %ecx, %ecx
addq (%rsp,%rcx,8), %rax
addq 0x120(%rsp,%rcx,8), %rax
movzbl %al, %edx
movq %rdx, (%rsp,%rcx,8)
shrq $0x8, %rax
incq %rcx
cmpq $0x11, %rcx
jne 0x1b2b
leaq 0x90(%rsp), %rax
xorl %ecx, %ecx
movq %rax, %rdx
xorl %edi, %edi
xorl %esi, %esi
movq (%rsp,%rdi,8), %r8
cmpq %rcx, %rdi
jbe 0x1b76
movq 0x88(%rdx), %r9
shlq $0x6, %r9
leaq (%r9,%r9,4), %r9
jmp 0x1b79
movq (%rdx), %r9
imulq %r8, %r9
addq %r9, %rsi
incq %rdi
addq $-0x8, %rdx
cmpq $0x11, %rdi
jne 0x1b5c
movq %rsi, 0x240(%rsp,%rcx,8)
incq %rcx
addq $0x8, %rax
cmpq $0x11, %rcx
jne 0x1b55
movl $0x88, %edx
movq %rsp, %rdi
movq %rbp, %rsi
callq 0x10b0
xorl %eax, %eax
xorl %ecx, %ecx
addq (%rsp,%rcx,8), %rax
movzbl %al, %edx
movq %rdx, (%rsp,%rcx,8)
shrq $0x8, %rax
incq %rcx
cmpq $0x10, %rcx
jne 0x1bb6
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
addq (%rsp,%rcx,8), %rax
movzbl %al, %edx
movq %rdx, (%rsp,%rcx,8)
shrq $0x8, %rax
incq %rcx
cmpq $0x10, %rcx
jne 0x1bed
addq %rax, 0x80(%rsp)
subq %r13, %r15
jne 0x1adf
leaq 0x1b0(%rsp), %rdi
movq %rsp, %rsi
movl $0x88, %edx
callq 0x10b0
xorl %eax, %eax
leaq 0x246c(%rip), %rcx      # 0x40a0
xorl %edx, %edx
addq (%rsp,%rax), %rdx
addq (%rax,%rcx), %rdx
movzbl %dl, %esi
movq %rsi, (%rsp,%rax)
shrq $0x8, %rdx
addq $0x8, %rax
cmpq $0x88, %rax
jne 0x1c36
movq 0x80(%rsp), %rax
shrq $0x7, %rax
negq %rax
xorl %ecx, %ecx
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
cmpq $0x11, %rcx
jne 0x1c66
xorl %eax, %eax
movzbl 0x10(%r14,%rax), %ecx
movq %rcx, 0x120(%rsp,%rax,8)
incq %rax
cmpq $0x10, %rax
jne 0x1c8a
movq $0x0, 0x1a0(%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
addq (%rsp,%rcx,8), %rax
addq 0x120(%rsp,%rcx,8), %rax
movzbl %al, %edx
movq %rdx, (%rsp,%rcx,8)
shrq $0x8, %rax
incq %rcx
cmpq $0x11, %rcx
jne 0x1cb1
xorl %eax, %eax
movb (%rsp,%rax,8), %cl
movb %cl, (%rbx,%rax)
incq %rax
cmpq $0x10, %rax
jne 0x1cd3
xorl %eax, %eax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq