// File: /workspace/github_c_makefile_star2_O2/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)
pushq $-0x1
popq %rax
cmpq $0x10, %r8
jb 0x1476
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 0x1070
pushq $0x78
popq %rax
xorl %ebx, %ebx
cmpq $0x79, %rbp
setb %bl
cmpq $0x78, %rbp
movq %rax, %r15
movq %rax, %r14
cmovbq %rbp, %r14
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
callq 0x1110
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %r14, %rcx
movl %ebx, %r8d
callq 0x1060
addq %r14, %r13
subq %r14, %rbp
movq %r15, %rax
jne 0x13a4
movq 0x8(%rsp), %rax
andq $0x0, (%rax)
addq $-0x10, %r12
leaq 0x30(%rsp), %r13
movq 0x10(%rsp), %rbp
xorl %ebx, %ebx
cmpq $0x79, %r12
setae %bl
cmpq $0x78, %r12
movq %r15, %r14
cmovbq %r12, %r14
movq %r13, %rdi
movq %r13, %rsi
callq 0x1110
movq %r13, %rdi
movq %rbp, %rsi
leaq 0x18(%rsp), %rdx
movq %r14, %rcx
movl %ebx, %r8d
callq 0x1070
addq %r14, %rbp
movq 0x8(%rsp), %rax
addq %r14, (%rax)
subq %r14, %r12
jne 0x13ff
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x10f0
vmovdqa (%rbx), %xmm0
vpxor (%rbp), %xmm0, %xmm0
vptest %xmm0, %xmm0
je 0x1474
movq 0x8(%rsp), %rax
andq $0x0, (%rax)
pushq $-0x1
popq %rax
jmp 0x1476
xorl %eax, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq