// File: /workspace/github_c_makefile_star2_O3/mjosaarinen[P]brutus/crypto_aead/icepole256av2/ref/encrypt.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
)
{
    ICESTATE S;
    unsigned char Tcomp[ICEPOLETAGLEN]; /* computed authentication tag */
    unsigned int frameBit;
    
    /* ciphertext cannot be shorter than the tag length */
    if (clen < ICEPOLETAGLEN) {
        return -1;
    }
    
    initState256a(S, k, npub);

    /* secret message number is zero-length */
    frameBit = 0;
    processDataBlockRev(S, NULL, NULL, 0, frameBit);
   
    /* process associated data blocks */
    do {
        unsigned long long blocklen = ICEPOLEDATABLOCKLEN;
        frameBit = (adlen <= blocklen ? 1 : 0);
        if (adlen < blocklen) {
            blocklen = adlen;
        }
        /* apply the permutation to the state */
        P6(S,S);
        /* absorb a data block */
        processDataBlock(S, ad, NULL, blocklen, frameBit);
        ad += blocklen;
        adlen -= blocklen;
    } while (adlen > 0);
    
    /* process ciphertext blocks to get auth tag */
    *mlen = 0;
    clen -= ICEPOLETAGLEN; /* need to stop before auth tag*/
    do {
        unsigned long long blocklen = ICEPOLEDATABLOCKLEN;
        frameBit = (clen <= blocklen ? 0 : 1);
        if (clen < blocklen) {
            blocklen = clen;
        }
        /* apply the permutation to the state */
        P6(S,S);
        /* absorb a ciphertext block and produce a plaintext block */
        processDataBlockRev(S, c, &m, blocklen, frameBit);
        c += blocklen;
        *mlen += blocklen;
        clen -= blocklen;    
    } while (clen > 0);

    /* compare computed and received auth tags */
    generateTag(S, Tcomp);
    if (memcmp(Tcomp, c, ICEPOLETAGLEN)) {
        *mlen = 0;
        return -1;
    }
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, 0x18(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq $0x10, %r8
jb 0x145c
movq %r9, %r13
movq %r8, %r12
movq %rcx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq 0x120(%rsp), %rsi
movq 0x118(%rsp), %rdx
movq 0x110(%rsp), %rbp
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x1030
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x1060
xorl %ebx, %ebx
cmpq $0x79, %rbp
setb %bl
cmpq $0x78, %rbp
movl $0x78, %r14d
cmovbq %rbp, %r14
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %r15, %rsi
callq 0x1100
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %r14, %rcx
movl %ebx, %r8d
callq 0x1050
addq %r14, %r13
subq %r14, %rbp
jne 0x1384
movq 0x8(%rsp), %rbp
movq $0x0, (%rbp)
addq $-0x10, %r12
leaq 0x30(%rsp), %r13
movq 0x10(%rsp), %r15
xorl %ebx, %ebx
cmpq $0x79, %r12
setae %bl
cmpq $0x78, %r12
movl $0x78, %r14d
cmovbq %r12, %r14
movq %r13, %rdi
movq %r13, %rsi
callq 0x1100
movq %r13, %rdi
movq %r15, %rsi
leaq 0x18(%rsp), %rdx
movq %r14, %rcx
movl %ebx, %r8d
callq 0x1060
addq %r14, %r15
addq %r14, (%rbp)
subq %r14, %r12
jne 0x13e1
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x10e0
vmovdqa (%rbx), %xmm0
vpxor (%r15), %xmm0, %xmm0
vptest %xmm0, %xmm0
je 0x145a
movq 0x8(%rsp), %rax
movq $0x0, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x145c
xorl %eax, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop