// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/icepole256av2/ref/encrypt.c
// Function: crypto_aead_encrypt
int crypto_aead_encrypt(
	unsigned char *c,unsigned long long *clen,
	const unsigned char *m,unsigned long long mlen,
	const unsigned char *ad,unsigned long long adlen,
	const unsigned char *nsec,
	const unsigned char *npub,
	const unsigned char *k )
{
    ICESTATE S;
    unsigned int frameBit;
    
    /* initialize the state with secret key and nonce */
    initState256a(S, k, npub);

    /* ciphertext length is plaintext len + size of tag and nsec */
    *clen = mlen + ICEPOLETAGLEN; 
    
    /* secret message number is zero length */
    processDataBlock(S, NULL, NULL, 0, 0);
    
    /* process auth-only associated data blocks */
    do {
        unsigned long long blocklen = ICEPOLEDATABLOCKLEN;
        frameBit = (adlen <= blocklen ? 1 : 0); /* is it the last block? */
        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 plaintext blocks to get the ciphertext */
    do {
        unsigned long long blocklen = ICEPOLEDATABLOCKLEN;
        frameBit = (mlen <=blocklen ? 0 : 1);
        if (mlen < blocklen) {
            blocklen = mlen;
        }
        /* apply the permutation to the state */
        P6(S,S);
        /* absorb a data block and produce a ciphertext block */
        processDataBlock(S, m, &c, blocklen, frameBit);
        m += blocklen;
        mlen -= blocklen;    
    } while (mlen > 0);

    /* store authentication tag at the end of the ciphertext */
    generateTag(S, c);
    return 0;
}

// Assembly:
subq $0xf8, %rsp
movq 0x110(%rsp), %rax
movq 0x108(%rsp), %rax
movq 0x100(%rsp), %rax
movq %rdi, 0xf0(%rsp)
movq %rsi, 0xe8(%rsp)
movq %rdx, 0xe0(%rsp)
movq %rcx, 0xd8(%rsp)
movq %r8, 0xd0(%rsp)
movq %r9, 0xc8(%rsp)
leaq 0x20(%rsp), %rdi
movq 0x110(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0x1030
movq 0xd8(%rsp), %rcx
addq $0x10, %rcx
movq 0xe8(%rsp), %rax
movq %rcx, (%rax)
leaq 0x20(%rsp), %rdi
xorl %eax, %eax
movl %eax, %ecx
xorl %r8d, %r8d
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x1060
movq $0x78, 0x10(%rsp)
movq 0xc8(%rsp), %rdx
movq 0x10(%rsp), %rsi
xorl %eax, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmovbel %ecx, %eax
movl %eax, 0x1c(%rsp)
movq 0xc8(%rsp), %rax
cmpq 0x10(%rsp), %rax
jae 0x131a
movq 0xc8(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x1110
leaq 0x20(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq 0x10(%rsp), %rcx
movl 0x1c(%rsp), %r8d
xorl %eax, %eax
movl %eax, %edx
callq 0x1060
movq 0x10(%rsp), %rax
addq 0xd0(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0x10(%rsp), %rcx
movq 0xc8(%rsp), %rax
subq %rcx, %rax
movq %rax, 0xc8(%rsp)
cmpq $0x0, 0xc8(%rsp)
ja 0x12d7
jmp 0x1387
movq $0x78, 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 0x13ca
movq 0xd8(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x1110
leaq 0x20(%rsp), %rdi
movq 0xe0(%rsp), %rsi
movq 0x8(%rsp), %rcx
movl 0x1c(%rsp), %r8d
leaq 0xf0(%rsp), %rdx
callq 0x1060
movq 0x8(%rsp), %rax
addq 0xe0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x8(%rsp), %rcx
movq 0xd8(%rsp), %rax
subq %rcx, %rax
movq %rax, 0xd8(%rsp)
cmpq $0x0, 0xd8(%rsp)
ja 0x1387
leaq 0x20(%rsp), %rdi
movq 0xf0(%rsp), %rsi
callq 0x10f0
xorl %eax, %eax
addq $0xf8, %rsp
retq
nopw %cs:(%rax,%rax)