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

  *mlen = 0;
  if (clen < CRYPTO_KEYBYTES)
    return -1;

  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 = (clen - klen) / rate + 1;
  i64 l = (clen - klen) % 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;

  // 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) {
    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) {
      M[i * rate + j] = S[j] ^ c[i * rate + j];
      S[j] = c[i * rate + j];
    }
    permutation(S, b);
  }
  for (j = 0; j < l; ++j)
    M[(t - 1) * rate + j] = S[j] ^ c[(t - 1) * rate + j];
  for (j = 0; j < l; ++j)
    S[j] = c[(t - 1) * rate + j];
  S[l] ^= 0x80;
  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 -1 if verification fails
  for (i = 0; i < klen; ++i)
    if (c[clen - klen + i] != S[rate + klen + i])
      return -1;

  // return plaintext
  *mlen = clen - klen;
  for (i = 0; i < *mlen; ++i)
    m[i] = M[i];

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
cmpq $0x10, -0x30(%rbp)
jae 0x1f0d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2718
movl $0x10, -0x3c(%rbp)
movl $0x28, -0x40(%rbp)
movl $0x8, -0x44(%rbp)
movl -0x40(%rbp), %eax
movl -0x44(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x48(%rbp)
movl $0xc, -0x4c(%rbp)
movl $0x6, -0x50(%rbp)
movq 0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
xorl %edx, %edx
movq %rdx, -0xc0(%rbp)
divq %rcx
movq -0xc0(%rbp), %rdx
incq %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
subq %rcx, %rax
movslq -0x44(%rbp), %rcx
divq %rcx
movq -0xc0(%rbp), %rdx
incq %rax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
subq %rcx, %rax
movslq -0x44(%rbp), %rcx
divq %rcx
movq %rdx, -0x68(%rbp)
movl -0x40(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x70(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xb8(%rbp)
movq %rcx, %rsp
movq %rax, -0x78(%rbp)
movq -0x58(%rbp), %rax
movslq -0x44(%rbp), %rcx
imulq %rcx, %rax
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xb0(%rbp)
movq %rcx, %rsp
movq %rax, -0x80(%rbp)
movq -0x60(%rbp), %rax
movslq -0x44(%rbp), %rcx
imulq %rcx, %rax
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xa8(%rbp)
movq %rcx, %rsp
movq %rax, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpq 0x10(%rbp), %rax
jae 0x2060
movq -0xb0(%rbp), %rax
movq -0x38(%rbp), %rcx
movq -0x90(%rbp), %rdx
movb (%rcx,%rdx), %dl
movq -0x90(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x2020
movq -0xb0(%rbp), %rax
movq 0x10(%rbp), %rcx
movb $-0x80, (%rax,%rcx)
movq 0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq -0x44(%rbp), %rdx
imulq %rdx, %rcx
cmpq %rcx, %rax
jge 0x20bc
movq -0xb0(%rbp), %rax
movq -0x90(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x207e
movq -0xb8(%rbp), %rax
movl -0x3c(%rbp), %ecx
shll $0x3, %ecx
movb %cl, (%rax)
movl -0x44(%rbp), %ecx
shll $0x3, %ecx
movb %cl, 0x1(%rax)
movl -0x4c(%rbp), %ecx
movb %cl, 0x2(%rax)
movl -0x50(%rbp), %ecx
movb %cl, 0x3(%rax)
movq $0x4, -0x90(%rbp)
movq -0x90(%rbp), %rax
movl -0x40(%rbp), %ecx
movl -0x3c(%rbp), %edx
shll %edx
subl %edx, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x212a
movq -0xb8(%rbp), %rax
movq -0x90(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x20eb
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpq %rcx, %rax
jge 0x2185
movq -0xb8(%rbp), %rax
movq 0x20(%rbp), %rcx
movq -0x90(%rbp), %rdx
movb (%rcx,%rdx), %dl
movl -0x40(%rbp), %ecx
movl -0x3c(%rbp), %esi
shll %esi
subl %esi, %ecx
movslq %ecx, %rcx
addq -0x90(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x2135
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpq %rcx, %rax
jge 0x21dc
movq -0xb8(%rbp), %rax
movq 0x18(%rbp), %rcx
movq -0x90(%rbp), %rdx
movb (%rcx,%rdx), %dl
movl -0x40(%rbp), %ecx
subl -0x3c(%rbp), %ecx
movslq %ecx, %rcx
addq -0x90(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x2190
movq -0xb8(%rbp), %rsi
leaq 0xe75(%rip), %rdi       # 0x305f
callq 0x1070
movq -0xb8(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x1090
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpq %rcx, %rax
jge 0x225c
movq -0xb8(%rbp), %rax
movq 0x20(%rbp), %rcx
movq -0x90(%rbp), %rdx
movzbl (%rcx,%rdx), %esi
movl -0x44(%rbp), %ecx
addl -0x3c(%rbp), %ecx
movslq %ecx, %rcx
addq -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 0x2209
movq -0xb8(%rbp), %rsi
leaq 0xe04(%rip), %rdi       # 0x306e
callq 0x1070
cmpq $0x0, 0x10(%rbp)
je 0x2325
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x2323
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
movslq -0x44(%rbp), %rcx
cmpq %rcx, %rax
jge 0x22fd
movq -0xb8(%rbp), %rax
movq -0xb0(%rbp), %rcx
movq -0x90(%rbp), %rdx
movslq -0x44(%rbp), %rsi
imulq %rsi, %rdx
addq -0x98(%rbp), %rdx
movzbl (%rcx,%rdx), %esi
movq -0x98(%rbp), %rcx
movzbl (%rax,%rcx), %edx
xorl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x22a1
movq -0xb8(%rbp), %rdi
movl -0x50(%rbp), %esi
callq 0x1090
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x2285
jmp 0x2325
movq -0xb8(%rbp), %rsi
movl -0x40(%rbp), %eax
subl $0x1, %eax
cltq
movzbl (%rsi,%rax), %ecx
xorl $0x1, %ecx
movb %cl, (%rsi,%rax)
leaq 0xd39(%rip), %rdi       # 0x307e
callq 0x1070
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x2446
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
movslq -0x44(%rbp), %rcx
cmpq %rcx, %rax
jge 0x2420
movq -0xb8(%rbp), %rax
movq -0xa8(%rbp), %rcx
movq -0x98(%rbp), %rdx
movzbl (%rax,%rdx), %edx
movq -0x28(%rbp), %rsi
movq -0x90(%rbp), %rdi
movslq -0x44(%rbp), %r8
imulq %r8, %rdi
addq -0x98(%rbp), %rdi
movzbl (%rsi,%rdi), %esi
xorl %esi, %edx
movb %dl, %sil
movq -0x90(%rbp), %rdx
movslq -0x44(%rbp), %rdi
imulq %rdi, %rdx
addq -0x98(%rbp), %rdx
movb %sil, (%rcx,%rdx)
movq -0x28(%rbp), %rcx
movq -0x90(%rbp), %rdx
movslq -0x44(%rbp), %rsi
imulq %rsi, %rdx
addq -0x98(%rbp), %rdx
movb (%rcx,%rdx), %dl
movq -0x98(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x2378
movq -0xb8(%rbp), %rdi
movl -0x50(%rbp), %esi
callq 0x1090
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x2355
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x68(%rbp), %rax
jge 0x24c8
movq -0xa8(%rbp), %rax
movq -0xb8(%rbp), %rcx
movq -0x98(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
movq -0x28(%rbp), %rdx
movq -0x60(%rbp), %rsi
subq $0x1, %rsi
movslq -0x44(%rbp), %rdi
imulq %rdi, %rsi
addq -0x98(%rbp), %rsi
movzbl (%rdx,%rsi), %edx
xorl %edx, %ecx
movb %cl, %dl
movq -0x60(%rbp), %rcx
subq $0x1, %rcx
movslq -0x44(%rbp), %rsi
imulq %rsi, %rcx
addq -0x98(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x2451
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x68(%rbp), %rax
jge 0x2523
movq -0xb8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq -0x60(%rbp), %rdx
subq $0x1, %rdx
movslq -0x44(%rbp), %rsi
imulq %rsi, %rdx
addq -0x98(%rbp), %rdx
movb (%rcx,%rdx), %dl
movq -0x98(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x24d3
movq -0xb8(%rbp), %rsi
movq -0x68(%rbp), %rax
movzbl (%rsi,%rax), %ecx
xorl $0x80, %ecx
movb %cl, (%rsi,%rax)
leaq 0xb55(%rip), %rdi       # 0x3097
callq 0x1070
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpq %rcx, %rax
jge 0x25a0
movq -0xb8(%rbp), %rax
movq 0x20(%rbp), %rcx
movq -0x90(%rbp), %rdx
movzbl (%rcx,%rdx), %esi
movslq -0x44(%rbp), %rcx
addq -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 0x2552
movq -0xb8(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x1090
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpq %rcx, %rax
jge 0x260d
movq -0xb8(%rbp), %rax
movq 0x20(%rbp), %rcx
movq -0x90(%rbp), %rdx
movzbl (%rcx,%rdx), %esi
movl -0x44(%rbp), %ecx
addl -0x3c(%rbp), %ecx
movslq %ecx, %rcx
addq -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 0x25ba
movq -0xb8(%rbp), %rsi
leaq 0xa8f(%rip), %rdi       # 0x30aa
callq 0x1070
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpq %rcx, %rax
jge 0x26a0
movq -0xb8(%rbp), %rcx
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rdx
movslq -0x3c(%rbp), %rsi
subq %rsi, %rdx
addq -0x90(%rbp), %rdx
movzbl (%rax,%rdx), %eax
movl -0x44(%rbp), %edx
addl -0x3c(%rbp), %edx
movslq %edx, %rdx
addq -0x90(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x268a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x9c(%rbp)
jmp 0x2711
jmp 0x268c
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x262b
movq -0x30(%rbp), %rcx
movslq -0x3c(%rbp), %rax
subq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x2700
movq -0xa8(%rbp), %rax
movq -0x90(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq -0x90(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x26bd
movl $0x0, -0x4(%rbp)
movl $0x1, -0x9c(%rbp)
movq -0x70(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq