// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/norx6441v2/ref/norx.c
// Function: norx_aead_decrypt
int norx_aead_decrypt(
  unsigned char *m, size_t *mlen,
  const unsigned char *a, size_t alen,
  const unsigned char *c, size_t clen,
  const unsigned char *z, size_t zlen,
  const unsigned char *nonce,
  const unsigned char *key
)
{
    int result = -1;
    unsigned char tag[BYTES(NORX_T)];
    norx_state_t state;

    if (clen < BYTES(NORX_T)) {
        return -1;
    }

    norx_init(state, key, nonce);
    norx_absorb_data(state, a, alen, HEADER_TAG);
    norx_decrypt_data(state, m, c, clen - BYTES(NORX_T));
    norx_absorb_data(state, z, zlen, TRAILER_TAG);
    norx_finalise(state, tag);
    *mlen = clen - BYTES(NORX_T);

    result = norx_verify_tag(c + clen - BYTES(NORX_T), tag);
    if (result != 0) { /* burn decrypted plaintext on auth failure */
        burn(m, 0, clen - BYTES(NORX_T));
    }
    burn(state, 0, sizeof(norx_state_t));

    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, (%rsp)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq $0x20, %r9
jb 0x195e
movq %r9, %r14
movq %r8, %r15
movq %rcx, %r13
movq %rdx, %rbp
movq %rsi, 0x8(%rsp)
movq 0x168(%rsp), %r12
vpmovsxbq 0x8c3(%rip), %ymm0 # 0x2048
xorl %eax, %eax
vpbroadcastq 0x8b0(%rip), %ymm1 # 0x2040
vmovdqu %ymm0, 0x30(%rsp,%rax,8)
addq $0x4, %rax
vpaddq %ymm1, %ymm0, %ymm0
cmpq $0x10, %rax
jne 0x1790
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
vzeroupper
callq 0x1972
movq %rbx, %rdi
callq 0x1972
movq 0x160(%rsp), %rax
vmovups (%rax), %xmm0
vmovaps %xmm0, (%rbx)
vmovups (%r12), %ymm0
vmovups %ymm0, 0x20(%rbx)
vmovups 0x60(%rbx), %ymm0
vxorps 0x83c(%rip), %ymm0, %ymm0 # 0x2020
vmovups %ymm0, 0x60(%rbx)
movl $0x4, %r12d
movq %rbx, %rdi
vzeroupper
callq 0x1972
decq %r12
jne 0x17ef
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl $0x1, %ecx
callq 0x1060
leaq -0x20(%r14), %r13
movq %rbx, %rdi
movq (%rsp), %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x10a0
movq %rbx, %rdi
movq 0x150(%rsp), %rsi
movq 0x158(%rsp), %rdx
movl $0x4, %ecx
callq 0x1060
xorb $0x8, 0x78(%rbx)
movl $0x4, %r12d
movq %rbx, %rdi
callq 0x1972
decq %r12
jne 0x1854
movl $0x4, %ebp
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x1972
decq %rbp
jne 0x186b
leaq 0x30(%rsp), %rbx
vmovdqu (%rbx), %ymm0
vmovdqu 0x20(%rbx), %ymm1
vmovups 0x40(%rbx), %ymm2
leaq 0xb0(%rsp), %rdi
vmovups %ymm2, 0x40(%rdi)
vmovdqu %ymm1, 0x20(%rdi)
vmovdqu %ymm0, (%rdi)
vmovdqu %ymm0, 0x10(%rsp)
movq 0x255a(%rip), %rax      # 0x3e08
xorl %ebp, %ebp
movl $0x60, %edx
xorl %esi, %esi
vzeroupper
callq *%rax
movq 0x2545(%rip), %rax      # 0x3e08
movl $0x80, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq *%rax
movq 0x8(%rsp), %rax
movq %r13, (%rax)
leaq (%r15,%r14), %rax
addq $-0x20, %rax
vpxor %xmm0, %xmm0, %xmm0
movq 0x10(%rsp,%rbp), %rcx
xorq (%rax,%rbp), %rcx
vmovq %rcx, %xmm1
vpmovzxbd %xmm1, %ymm1    # ymm1 = xmm1[0],zero,zero,zero,xmm1[1],zero,zero,zero,xmm1[2],zero,zero,zero,xmm1[3],zero,zero,zero,xmm1[4],zero,zero,zero,xmm1[5],zero,zero,zero,xmm1[6],zero,zero,zero,xmm1[7],zero,zero,zero
vpor %ymm1, %ymm0, %ymm0
addq $0x8, %rbp
cmpq $0x20, %rbp
jne 0x18e3
vextracti128 $0x1, %ymm0, %xmm1
vpor %xmm1, %xmm0, %xmm0
vpshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
vpor %xmm1, %xmm0, %xmm0
vpsrlq $0x20, %xmm0, %xmm1
vpor %xmm1, %xmm0, %xmm0
vmovd %xmm0, %eax
decl %eax
xorl %ebx, %ebx
btl $0x8, %eax
adcl $-0x1, %ebx
je 0x1946
movq 0x24d0(%rip), %rax      # 0x3e08
movq (%rsp), %rdi
xorl %esi, %esi
movq %r13, %rdx
vzeroupper
callq *%rax
movq 0x24bb(%rip), %rax      # 0x3e08
leaq 0x30(%rsp), %rdi
movl $0x80, %edx
xorl %esi, %esi
vzeroupper
callq *%rax
movl %ebx, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq