// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/icepole128v2/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;
    }
    
    initState(S, k, npub);

    /* process 128-bit secret message number */
    frameBit = 0;
    processDataBlockRev(S, c, &nsec, ICEPOLENSECLEN, frameBit);
    c += ICEPOLENSECLEN;
   
    /* 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+ICEPOLENSECLEN; /* 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)
movq %rdx, 0x10(%rsp)
pushq $-0x1
popq %rax
cmpq $0x10, %r8
jb 0x14a7
movq %r9, %r13
movq %r8, %r12
movq %rcx, %r14
movq %rsi, (%rsp)
movq 0x120(%rsp), %rsi
movq 0x118(%rsp), %rdx
movq 0x110(%rsp), %rbp
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x10c0
leaq 0x10(%rsp), %rdx
pushq $0x10
popq %rcx
movq %rbx, %rdi
movq %r14, 0x8(%rsp)
movq %r14, %rsi
xorl %r8d, %r8d
callq 0x1060
xorl %ebx, %ebx
cmpq $0x81, %rbp
setb %bl
movl $0x80, %eax
cmpq %rax, %rbp
movl $0x80, %r14d
cmovbq %rbp, %r14
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %r15, %rsi
callq 0x1110
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %r14, %rcx
movl %ebx, %r8d
callq 0x1050
addq %r14, %r13
subq %r14, %rbp
jne 0x13c7
movq (%rsp), %rbp
andq $0x0, (%rbp)
movq 0x8(%rsp), %r15
addq $0x10, %r15
addq $-0x20, %r12
leaq 0x30(%rsp), %r13
xorl %ebx, %ebx
cmpq $0x81, %r12
setae %bl
movl $0x80, %eax
cmpq %rax, %r12
movl $0x80, %r14d
cmovbq %r12, %r14
movq %r13, %rdi
movq %r13, %rsi
callq 0x1110
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 0x142b
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x10f0
vmovdqa (%rbx), %xmm0
vpxor (%r15), %xmm0, %xmm0
vptest %xmm0, %xmm0
je 0x14a5
movq (%rsp), %rax
andq $0x0, (%rax)
pushq $-0x1
popq %rax
jmp 0x14a7
xorl %eax, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)