// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x108, %rsp            # imm = 0x108
movq 0x120(%rsp), %rax
movq 0x118(%rsp), %rax
movq 0x110(%rsp), %rax
movq %rdi, 0xf8(%rsp)
movq %rsi, 0xf0(%rsp)
movq %rdx, 0xe8(%rsp)
movq %rcx, 0xe0(%rsp)
movq %r8, 0xd8(%rsp)
movq %r9, 0xd0(%rsp)
cmpq $0x10, 0xd8(%rsp)
jae 0x14da
movl $0xffffffff, 0x104(%rsp) # imm = 0xFFFFFFFF
jmp 0x1729
leaq 0x30(%rsp), %rdi
movq 0x120(%rsp), %rsi
movq 0x118(%rsp), %rdx
callq 0x10c0
movl $0x0, 0x1c(%rsp)
leaq 0x30(%rsp), %rdi
movq 0xe0(%rsp), %rsi
movl 0x1c(%rsp), %r8d
leaq 0xe8(%rsp), %rdx
movl $0x10, %ecx
callq 0x1060
movq 0xe0(%rsp), %rax
addq $0x10, %rax
movq %rax, 0xe0(%rsp)
movq $0x80, 0x10(%rsp)
movq 0x110(%rsp), %rdx
movq 0x10(%rsp), %rsi
xorl %eax, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmovbel %ecx, %eax
movl %eax, 0x1c(%rsp)
movq 0x110(%rsp), %rax
cmpq 0x10(%rsp), %rax
jae 0x1577
movq 0x110(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x1110
leaq 0x30(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq 0x10(%rsp), %rcx
movl 0x1c(%rsp), %r8d
xorl %eax, %eax
movl %eax, %edx
callq 0x1050
movq 0x10(%rsp), %rax
addq 0xd0(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0x10(%rsp), %rcx
movq 0x110(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x110(%rsp)
cmpq $0x0, 0x110(%rsp)
ja 0x1534
movq 0xf0(%rsp), %rax
movq $0x0, (%rax)
movq 0xd8(%rsp), %rax
subq $0x20, %rax
movq %rax, 0xd8(%rsp)
movq $0x80, 0x8(%rsp)
movq 0xd8(%rsp), %rdx
movq 0x8(%rsp), %rsi
movl $0x1, %eax
xorl %ecx, %ecx
cmpq %rsi, %rdx
cmovbel %ecx, %eax
movl %eax, 0x1c(%rsp)
movq 0xd8(%rsp), %rax
cmpq 0x8(%rsp), %rax
jae 0x1648
movq 0xd8(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x1110
leaq 0x30(%rsp), %rdi
movq 0xe0(%rsp), %rsi
movq 0x8(%rsp), %rcx
movl 0x1c(%rsp), %r8d
leaq 0xf8(%rsp), %rdx
callq 0x1060
movq 0x8(%rsp), %rax
addq 0xe0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x8(%rsp), %rcx
movq 0xf0(%rsp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq 0x8(%rsp), %rcx
movq 0xd8(%rsp), %rax
subq %rcx, %rax
movq %rax, 0xd8(%rsp)
cmpq $0x0, 0xd8(%rsp)
ja 0x1605
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x10f0
leaq 0x20(%rsp), %rax
movq 0xe0(%rsp), %rcx
vmovdqu (%rcx), %xmm1
vmovdqu (%rax), %xmm0
vpxor %xmm1, %xmm0, %xmm0
vptest %xmm0, %xmm0
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x171e
movq 0xf0(%rsp), %rax
movq $0x0, (%rax)
movl $0xffffffff, 0x104(%rsp) # imm = 0xFFFFFFFF
jmp 0x1729
movl $0x0, 0x104(%rsp)
movl 0x104(%rsp), %eax
addq $0x108, %rsp            # imm = 0x108
retq
nopl (%rax,%rax)