// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/ascon128v11/ref/ascon.c
// Function: crypto_aead_encrypt
int crypto_aead_encrypt(
    unsigned char *c, unsigned long long *clen,
    const unsigned char *m, unsigned long long mlen,
    const unsigned char *ad, unsigned long long adlen,
    const unsigned char *nsec,
    const unsigned char *npub,
    const unsigned char *k) {

  int klen = CRYPTO_KEYBYTES;
  //int nlen = CRYPTO_NPUBBYTES;
  int size = 320 / 8;
  int rate = 64 / 8;
  int capacity = size - rate;
  int a = 12;
  int b = 6;
  i64 s = adlen / rate + 1;
  i64 t = mlen / rate + 1;
  i64 l = mlen % rate;

  u8 S[size];
  u8 A[s * rate];
  u8 M[t * rate];
  i64 i, j;

  // pad associated data
  for (i = 0; i < adlen; ++i)
    A[i] = ad[i];
  A[adlen] = 0x80;
  for (i = adlen + 1; i < s * rate; ++i)
    A[i] = 0;
  // pad plaintext
  for (i = 0; i < mlen; ++i)
    M[i] = m[i];
  M[mlen] = 0x80;
  for (i = mlen + 1; i < t * rate; ++i)
    M[i] = 0;

  // initialization
  S[0] = klen * 8;
  S[1] = rate * 8;
  S[2] = a;
  S[3] = b;
  for (i = 4; i < size - 2 * klen; ++i)
    S[i] = 0;
  for (i = 0; i < klen; ++i)
    S[size - 2 * klen + i] = k[i];
  for (i = 0; i < klen; ++i)
    S[size - klen + i] = npub[i];
  printstate("initial value:", S);
  permutation(S, a);
  for (i = 0; i < klen; ++i)
    S[rate + klen + i] ^= k[i];
  printstate("initialization:", S);

  // process associated data
  if (adlen != 0) {
    for (i = 0; i < s; ++i) {
      for (j = 0; j < rate; ++j)
        S[j] ^= A[i * rate + j];
      permutation(S, b);
    }
  }
  S[size - 1] ^= 1;
  printstate("process associated data:", S);

  // process plaintext
  for (i = 0; i < t - 1; ++i) {
    for (j = 0; j < rate; ++j) {
      S[j] ^= M[i * rate + j];
      c[i * rate + j] = S[j];
    }
    permutation(S, b);
  }
  for (j = 0; j < rate; ++j)
    S[j] ^= M[(t - 1) * rate + j];
  for (j = 0; j < l; ++j)
    c[(t - 1) * rate + j] = S[j];
  printstate("process plaintext:", S);

  // finalization
  for (i = 0; i < klen; ++i)
    S[rate + i] ^= k[i];
  permutation(S, a);
  for (i = 0; i < klen; ++i)
    S[rate + klen + i] ^= k[i];
  printstate("finalization:", S);

  // return tag
  for (i = 0; i < klen; ++i)
    c[mlen + i] = S[rate + klen + i];
  *clen = mlen + klen;

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x10, -0x34(%rbp)
movl $0x28, -0x38(%rbp)
movl $0x8, -0x3c(%rbp)
movl -0x38(%rbp), %eax
movl -0x3c(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x40(%rbp)
movl $0xc, -0x44(%rbp)
movl $0x6, -0x48(%rbp)
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
xorl %edx, %edx
movq %rdx, -0xb0(%rbp)
divq %rcx
movq -0xb0(%rbp), %rdx
incq %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
divq %rcx
movq -0xb0(%rbp), %rdx
incq %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
divq %rcx
movq %rdx, -0x60(%rbp)
movl -0x38(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x68(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xa8(%rbp)
movq %rcx, %rsp
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq %rcx, %rax
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xa0(%rbp)
movq %rcx, %rsp
movq %rax, -0x78(%rbp)
movq -0x58(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq %rcx, %rax
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x98(%rbp)
movq %rcx, %rsp
movq %rax, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x1821
movq -0xa0(%rbp), %rax
movq -0x28(%rbp), %rcx
movq -0x88(%rbp), %rdx
movb (%rcx,%rdx), %dl
movq -0x88(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x17e1
movq -0xa0(%rbp), %rax
movq -0x30(%rbp), %rcx
movb $-0x80, (%rax,%rcx)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq -0x50(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
imulq %rdx, %rcx
cmpq %rcx, %rax
jge 0x187d
movq -0xa0(%rbp), %rax
movq -0x88(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x183f
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x18c8
movq -0x98(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x88(%rbp), %rdx
movb (%rcx,%rdx), %dl
movq -0x88(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x1888
movq -0x98(%rbp), %rax
movq -0x20(%rbp), %rcx
movb $-0x80, (%rax,%rcx)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
imulq %rdx, %rcx
cmpq %rcx, %rax
jge 0x1924
movq -0x98(%rbp), %rax
movq -0x88(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x18e6
movq -0xa8(%rbp), %rax
movl -0x34(%rbp), %ecx
shll $0x3, %ecx
movb %cl, (%rax)
movl -0x3c(%rbp), %ecx
shll $0x3, %ecx
movb %cl, 0x1(%rax)
movl -0x44(%rbp), %ecx
movb %cl, 0x2(%rax)
movl -0x48(%rbp), %ecx
movb %cl, 0x3(%rax)
movq $0x4, -0x88(%rbp)
movq -0x88(%rbp), %rax
movl -0x38(%rbp), %ecx
movl -0x34(%rbp), %edx
shll %edx
subl %edx, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x1992
movq -0xa8(%rbp), %rax
movq -0x88(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x1953
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpq %rcx, %rax
jge 0x19ed
movq -0xa8(%rbp), %rax
movq 0x20(%rbp), %rcx
movq -0x88(%rbp), %rdx
movb (%rcx,%rdx), %dl
movl -0x38(%rbp), %ecx
movl -0x34(%rbp), %esi
shll %esi
subl %esi, %ecx
movslq %ecx, %rcx
addq -0x88(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x199d
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1a44
movq -0xa8(%rbp), %rax
movq 0x18(%rbp), %rcx
movq -0x88(%rbp), %rdx
movb (%rcx,%rdx), %dl
movl -0x38(%rbp), %ecx
subl -0x34(%rbp), %ecx
movslq %ecx, %rcx
addq -0x88(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x19f8
movq -0xa8(%rbp), %rsi
leaq 0x160d(%rip), %rdi      # 0x305f
callq 0x1070
movq -0xa8(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x1090
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1ac4
movq -0xa8(%rbp), %rax
movq 0x20(%rbp), %rcx
movq -0x88(%rbp), %rdx
movzbl (%rcx,%rdx), %esi
movl -0x3c(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
addq -0x88(%rbp), %rcx
movzbl (%rax,%rcx), %edx
xorl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x1a71
movq -0xa8(%rbp), %rsi
leaq 0x159c(%rip), %rdi      # 0x306e
callq 0x1070
cmpq $0x0, -0x30(%rbp)
je 0x1b8d
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x50(%rbp), %rax
jge 0x1b8b
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1b65
movq -0xa8(%rbp), %rax
movq -0xa0(%rbp), %rcx
movq -0x88(%rbp), %rdx
movslq -0x3c(%rbp), %rsi
imulq %rsi, %rdx
addq -0x90(%rbp), %rdx
movzbl (%rcx,%rdx), %esi
movq -0x90(%rbp), %rcx
movzbl (%rax,%rcx), %edx
xorl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x1b09
movq -0xa8(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x1090
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x1aed
jmp 0x1b8d
movq -0xa8(%rbp), %rsi
movl -0x38(%rbp), %eax
subl $0x1, %eax
cltq
movzbl (%rsi,%rax), %ecx
xorl $0x1, %ecx
movb %cl, (%rsi,%rax)
leaq 0x14d1(%rip), %rdi      # 0x307e
callq 0x1070
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq -0x58(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x1c8c
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1c66
movq -0xa8(%rbp), %rax
movq -0x98(%rbp), %rcx
movq -0x88(%rbp), %rdx
movslq -0x3c(%rbp), %rsi
imulq %rsi, %rdx
addq -0x90(%rbp), %rdx
movzbl (%rcx,%rdx), %esi
movq -0x90(%rbp), %rcx
movzbl (%rax,%rcx), %edx
xorl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x90(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movq -0x88(%rbp), %rcx
movslq -0x3c(%rbp), %rsi
imulq %rsi, %rcx
addq -0x90(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x1be0
movq -0xa8(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x1090
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x1bbd
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1cf4
movq -0xa8(%rbp), %rax
movq -0x98(%rbp), %rcx
movq -0x58(%rbp), %rdx
subq $0x1, %rdx
movslq -0x3c(%rbp), %rsi
imulq %rsi, %rdx
addq -0x90(%rbp), %rdx
movzbl (%rcx,%rdx), %esi
movq -0x90(%rbp), %rcx
movzbl (%rax,%rcx), %edx
xorl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x1c97
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x60(%rbp), %rax
jge 0x1d4f
movq -0xa8(%rbp), %rax
movq -0x90(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movq -0x58(%rbp), %rcx
subq $0x1, %rcx
movslq -0x3c(%rbp), %rsi
imulq %rsi, %rcx
addq -0x90(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x1cff
movq -0xa8(%rbp), %rsi
leaq 0x133a(%rip), %rdi      # 0x3097
callq 0x1070
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1dbb
movq -0xa8(%rbp), %rax
movq 0x20(%rbp), %rcx
movq -0x88(%rbp), %rdx
movzbl (%rcx,%rdx), %esi
movslq -0x3c(%rbp), %rcx
addq -0x88(%rbp), %rcx
movzbl (%rax,%rcx), %edx
xorl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x1d6d
movq -0xa8(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x1090
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1e28
movq -0xa8(%rbp), %rax
movq 0x20(%rbp), %rcx
movq -0x88(%rbp), %rdx
movzbl (%rcx,%rdx), %esi
movl -0x3c(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
addq -0x88(%rbp), %rcx
movzbl (%rax,%rcx), %edx
xorl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x1dd5
movq -0xa8(%rbp), %rsi
leaq 0x1274(%rip), %rdi      # 0x30aa
callq 0x1070
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1e96
movq -0xa8(%rbp), %rax
movl -0x3c(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
addq -0x88(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
addq -0x88(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x1e46
movq -0x20(%rbp), %rcx
movslq -0x34(%rbp), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x68(%rbp), %rax
movq %rax, %rsp
xorl %eax, %eax
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)