// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aegis128l/aesnib/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
	)
        //void aegis128L_enc_aut(unsigned char *key, unsigned char *iv, unsigned char *ad, unsigned char *plaintext,
        //unsigned char *ciphertext, unsigned char *mac, unsigned char maclen, unsigned long msglen, unsigned long adlen)
{
    unsigned long long i;  
    unsigned char plaintextblock[32], ciphertextblock[32], mac[16];
    __m128i state[8], tmp, ct0, ct1, msg0, msg1;

    //initialization stage
    aegis128L_initialization(k, npub, state); 

    //process the associated data 
    for (i = 0; (i+32) <= adlen; i = i+32)   
    {    
        msg0 = _mm_load_si128((__m128i*)(ad+i));
        msg1 = _mm_load_si128((__m128i*)(ad+i+16));

        //state update function
        tmp = state[7];
        state[7] = _mm_aesenc_si128(state[6],state[7]);
        state[6] = _mm_aesenc_si128(state[5],state[6]);
        state[5] = _mm_aesenc_si128(state[4],state[5]);
        state[4] = _mm_aesenc_si128(state[3],state[4]);
        state[3] = _mm_aesenc_si128(state[2],state[3]);
        state[2] = _mm_aesenc_si128(state[1],state[2]);
        state[1] = _mm_aesenc_si128(state[0],state[1]);
        state[0] = _mm_aesenc_si128(tmp,state[0]);

        //message is used to update the state.
        state[0] = _mm_xor_si128(state[0],msg0);
        state[4] = _mm_xor_si128(state[4],msg1);  
     }  

    // Deal with the partial block    
    // In this program, we assume that the message length is multiple of bytes.
    if (  (adlen & 0x1f) != 0 )  {
         memset(plaintextblock, 0, 32);
         memcpy(plaintextblock, ad+i, adlen & 0x1f);
         aegis128L_enc_aut_step(plaintextblock, ciphertextblock, state);
    }  


    // encrypt the message 
    for (i = 0; (i+32) <= mlen; i = i+32) 
    {   
        msg0 = _mm_load_si128((__m128i*)(m+i));
        msg1 = _mm_load_si128((__m128i*)(m+i+16));

        ct0 = _mm_xor_si128(msg0, state[6]);
        ct0 = _mm_xor_si128(ct0,  state[1]);
        ct1 = _mm_xor_si128(msg1, state[2]);
        ct1 = _mm_xor_si128(ct1,  state[5]);
        ct0 = _mm_xor_si128(ct0,  _mm_and_si128(state[2], state[3]));
        ct1 = _mm_xor_si128(ct1,  _mm_and_si128(state[6], state[7]));
    	_mm_store_si128((__m128i*)(c+i), ct0);
    	_mm_store_si128((__m128i*)(c+i+16), ct1);

        //state update function
        tmp = state[7];
        state[7] = _mm_aesenc_si128(state[6],state[7]);
        state[6] = _mm_aesenc_si128(state[5],state[6]);
        state[5] = _mm_aesenc_si128(state[4],state[5]);
        state[4] = _mm_aesenc_si128(state[3],state[4]);
        state[3] = _mm_aesenc_si128(state[2],state[3]);
        state[2] = _mm_aesenc_si128(state[1],state[2]);
        state[1] = _mm_aesenc_si128(state[0],state[1]);
        state[0] = _mm_aesenc_si128(tmp,state[0]);

        //message is used to update the state.
        state[0] = _mm_xor_si128(state[0],msg0);
        state[4] = _mm_xor_si128(state[4],msg1);  
    }  

    // Deal with the partial block    
    // In this program, we assume that the message length is multiple of bytes.
    if ( (mlen & 0x1f) != 0 )  {    
         memset(plaintextblock, 0, 32);   
         memcpy(plaintextblock, m+i, mlen & 0x1f);   
         aegis128L_enc_aut_step(plaintextblock, ciphertextblock, state);  
         memcpy(c+i, ciphertextblock, mlen & 0x1f);   
    }

    // finalization stage, we assume that the tag length is multiple of bytes
    aegis128L_tag_generation(mlen,adlen, 16, mac, state);  
    *clen = mlen + 16;  
    memcpy(c+mlen, mac, 16);  
          
    return 0; 
}

// Assembly:
subq $0x548, %rsp            # imm = 0x548
movq 0x560(%rsp), %rax
movq 0x558(%rsp), %rax
movq 0x550(%rsp), %rax
movq %rdi, 0x158(%rsp)
movq %rsi, 0x150(%rsp)
movq %rdx, 0x148(%rsp)
movq %rcx, 0x140(%rsp)
movq %r8, 0x138(%rsp)
movq %r9, 0x130(%rsp)
movq 0x560(%rsp), %rdi
movq 0x558(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x1040
movq $0x0, 0x128(%rsp)
movq 0x128(%rsp), %rax
addq $0x20, %rax
cmpq 0x130(%rsp), %rax
ja 0x3151
movq 0x138(%rsp), %rax
addq 0x128(%rsp), %rax
movq %rax, 0x178(%rsp)
movq 0x178(%rsp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, 0x10(%rsp)
movq 0x138(%rsp), %rax
addq 0x128(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x170(%rsp)
movq 0x170(%rsp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, (%rsp)
vmovdqa 0xc0(%rsp), %xmm0
vmovdqa %xmm0, 0x40(%rsp)
vmovdqa 0xb0(%rsp), %xmm1
vmovdqa 0xc0(%rsp), %xmm0
vmovdqa %xmm1, 0x4b0(%rsp)
vmovdqa %xmm0, 0x4a0(%rsp)
vmovdqa 0x4b0(%rsp), %xmm0
vmovdqa 0x4a0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0xc0(%rsp)
vmovdqa 0xa0(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm0
vmovdqa %xmm1, 0x490(%rsp)
vmovdqa %xmm0, 0x480(%rsp)
vmovdqa 0x490(%rsp), %xmm0
vmovdqa 0x480(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0xb0(%rsp)
vmovdqa 0x90(%rsp), %xmm1
vmovdqa 0xa0(%rsp), %xmm0
vmovdqa %xmm1, 0x470(%rsp)
vmovdqa %xmm0, 0x460(%rsp)
vmovdqa 0x470(%rsp), %xmm0
vmovdqa 0x460(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0xa0(%rsp)
vmovdqa 0x80(%rsp), %xmm1
vmovdqa 0x90(%rsp), %xmm0
vmovdqa %xmm1, 0x450(%rsp)
vmovdqa %xmm0, 0x440(%rsp)
vmovdqa 0x450(%rsp), %xmm0
vmovdqa 0x440(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0x90(%rsp)
vmovdqa 0x70(%rsp), %xmm1
vmovdqa 0x80(%rsp), %xmm0
vmovdqa %xmm1, 0x430(%rsp)
vmovdqa %xmm0, 0x420(%rsp)
vmovdqa 0x430(%rsp), %xmm0
vmovdqa 0x420(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0x80(%rsp)
vmovdqa 0x60(%rsp), %xmm1
vmovdqa 0x70(%rsp), %xmm0
vmovdqa %xmm1, 0x410(%rsp)
vmovdqa %xmm0, 0x400(%rsp)
vmovdqa 0x410(%rsp), %xmm0
vmovdqa 0x400(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0x70(%rsp)
vmovdqa 0x50(%rsp), %xmm1
vmovdqa 0x60(%rsp), %xmm0
vmovdqa %xmm1, 0x3f0(%rsp)
vmovdqa %xmm0, 0x3e0(%rsp)
vmovdqa 0x3f0(%rsp), %xmm0
vmovdqa 0x3e0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0x60(%rsp)
vmovdqa 0x40(%rsp), %xmm1
vmovdqa 0x50(%rsp), %xmm0
vmovdqa %xmm1, 0x3d0(%rsp)
vmovdqa %xmm0, 0x3c0(%rsp)
vmovdqa 0x3d0(%rsp), %xmm0
vmovdqa 0x3c0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0x50(%rsp)
vmovdqa 0x50(%rsp), %xmm1
vmovdqa 0x10(%rsp), %xmm0
vmovdqa %xmm1, 0x2b0(%rsp)
vmovdqa %xmm0, 0x2a0(%rsp)
vmovdqa 0x2b0(%rsp), %xmm0
vpxor 0x2a0(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x50(%rsp)
vmovdqa 0x90(%rsp), %xmm1
vmovdqa (%rsp), %xmm0
vmovdqa %xmm1, 0x290(%rsp)
vmovdqa %xmm0, 0x280(%rsp)
vmovdqa 0x290(%rsp), %xmm0
vpxor 0x280(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x90(%rsp)
movq 0x128(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x128(%rsp)
jmp 0x2e45
movq 0x130(%rsp), %rax
andq $0x1f, %rax
cmpq $0x0, %rax
je 0x31ba
leaq 0x100(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1030
leaq 0x100(%rsp), %rdi
movq 0x138(%rsp), %rsi
addq 0x128(%rsp), %rsi
movq 0x130(%rsp), %rdx
andq $0x1f, %rdx
callq 0x10b0
leaq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x1060
movq $0x0, 0x128(%rsp)
movq 0x128(%rsp), %rax
addq $0x20, %rax
cmpq 0x140(%rsp), %rax
ja 0x36f4
movq 0x148(%rsp), %rax
addq 0x128(%rsp), %rax
movq %rax, 0x168(%rsp)
movq 0x168(%rsp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, 0x10(%rsp)
movq 0x148(%rsp), %rax
addq 0x128(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x160(%rsp)
movq 0x160(%rsp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, (%rsp)
vmovdqa 0x10(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm0
vmovdqa %xmm1, 0x270(%rsp)
vmovdqa %xmm0, 0x260(%rsp)
vmovdqa 0x270(%rsp), %xmm0
vpxor 0x260(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x30(%rsp)
vmovdqa 0x30(%rsp), %xmm1
vmovdqa 0x60(%rsp), %xmm0
vmovdqa %xmm1, 0x250(%rsp)
vmovdqa %xmm0, 0x240(%rsp)
vmovdqa 0x250(%rsp), %xmm0
vpxor 0x240(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x30(%rsp)
vmovdqa (%rsp), %xmm1
vmovdqa 0x70(%rsp), %xmm0
vmovdqa %xmm1, 0x230(%rsp)
vmovdqa %xmm0, 0x220(%rsp)
vmovdqa 0x230(%rsp), %xmm0
vpxor 0x220(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x20(%rsp)
vmovdqa 0x20(%rsp), %xmm1
vmovdqa 0xa0(%rsp), %xmm0
vmovdqa %xmm1, 0x210(%rsp)
vmovdqa %xmm0, 0x200(%rsp)
vmovdqa 0x210(%rsp), %xmm0
vpxor 0x200(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x20(%rsp)
vmovdqa 0x30(%rsp), %xmm1
vmovdqa 0x70(%rsp), %xmm2
vmovdqa 0x80(%rsp), %xmm0
vmovdqa %xmm2, 0x530(%rsp)
vmovdqa %xmm0, 0x520(%rsp)
vmovdqa 0x530(%rsp), %xmm0
vpand 0x520(%rsp), %xmm0, %xmm0
vmovdqa %xmm1, 0x1f0(%rsp)
vmovdqa %xmm0, 0x1e0(%rsp)
vmovdqa 0x1f0(%rsp), %xmm0
vpxor 0x1e0(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x30(%rsp)
vmovdqa 0x20(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm2
vmovdqa 0xc0(%rsp), %xmm0
vmovdqa %xmm2, 0x510(%rsp)
vmovdqa %xmm0, 0x500(%rsp)
vmovdqa 0x510(%rsp), %xmm0
vpand 0x500(%rsp), %xmm0, %xmm0
vmovdqa %xmm1, 0x1d0(%rsp)
vmovdqa %xmm0, 0x1c0(%rsp)
vmovdqa 0x1d0(%rsp), %xmm0
vpxor 0x1c0(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x20(%rsp)
movq 0x158(%rsp), %rax
addq 0x128(%rsp), %rax
vmovdqa 0x30(%rsp), %xmm0
movq %rax, 0x4f8(%rsp)
vmovdqa %xmm0, 0x4e0(%rsp)
vmovdqa 0x4e0(%rsp), %xmm0
movq 0x4f8(%rsp), %rax
vmovdqa %xmm0, (%rax)
movq 0x158(%rsp), %rax
addq 0x128(%rsp), %rax
addq $0x10, %rax
vmovdqa 0x20(%rsp), %xmm0
movq %rax, 0x4d8(%rsp)
vmovdqa %xmm0, 0x4c0(%rsp)
vmovdqa 0x4c0(%rsp), %xmm0
movq 0x4d8(%rsp), %rax
vmovdqa %xmm0, (%rax)
vmovdqa 0xc0(%rsp), %xmm0
vmovdqa %xmm0, 0x40(%rsp)
vmovdqa 0xb0(%rsp), %xmm1
vmovdqa 0xc0(%rsp), %xmm0
vmovdqa %xmm1, 0x3b0(%rsp)
vmovdqa %xmm0, 0x3a0(%rsp)
vmovdqa 0x3b0(%rsp), %xmm0
vmovdqa 0x3a0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0xc0(%rsp)
vmovdqa 0xa0(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm0
vmovdqa %xmm1, 0x390(%rsp)
vmovdqa %xmm0, 0x380(%rsp)
vmovdqa 0x390(%rsp), %xmm0
vmovdqa 0x380(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0xb0(%rsp)
vmovdqa 0x90(%rsp), %xmm1
vmovdqa 0xa0(%rsp), %xmm0
vmovdqa %xmm1, 0x370(%rsp)
vmovdqa %xmm0, 0x360(%rsp)
vmovdqa 0x370(%rsp), %xmm0
vmovdqa 0x360(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0xa0(%rsp)
vmovdqa 0x80(%rsp), %xmm1
vmovdqa 0x90(%rsp), %xmm0
vmovdqa %xmm1, 0x350(%rsp)
vmovdqa %xmm0, 0x340(%rsp)
vmovdqa 0x350(%rsp), %xmm0
vmovdqa 0x340(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0x90(%rsp)
vmovdqa 0x70(%rsp), %xmm1
vmovdqa 0x80(%rsp), %xmm0
vmovdqa %xmm1, 0x330(%rsp)
vmovdqa %xmm0, 0x320(%rsp)
vmovdqa 0x330(%rsp), %xmm0
vmovdqa 0x320(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0x80(%rsp)
vmovdqa 0x60(%rsp), %xmm1
vmovdqa 0x70(%rsp), %xmm0
vmovdqa %xmm1, 0x310(%rsp)
vmovdqa %xmm0, 0x300(%rsp)
vmovdqa 0x310(%rsp), %xmm0
vmovdqa 0x300(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0x70(%rsp)
vmovdqa 0x50(%rsp), %xmm1
vmovdqa 0x60(%rsp), %xmm0
vmovdqa %xmm1, 0x2f0(%rsp)
vmovdqa %xmm0, 0x2e0(%rsp)
vmovdqa 0x2f0(%rsp), %xmm0
vmovdqa 0x2e0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0x60(%rsp)
vmovdqa 0x40(%rsp), %xmm1
vmovdqa 0x50(%rsp), %xmm0
vmovdqa %xmm1, 0x2d0(%rsp)
vmovdqa %xmm0, 0x2c0(%rsp)
vmovdqa 0x2d0(%rsp), %xmm0
vmovdqa 0x2c0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0x50(%rsp)
vmovdqa 0x50(%rsp), %xmm1
vmovdqa 0x10(%rsp), %xmm0
vmovdqa %xmm1, 0x1b0(%rsp)
vmovdqa %xmm0, 0x1a0(%rsp)
vmovdqa 0x1b0(%rsp), %xmm0
vpxor 0x1a0(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x50(%rsp)
vmovdqa 0x90(%rsp), %xmm1
vmovdqa (%rsp), %xmm0
vmovdqa %xmm1, 0x190(%rsp)
vmovdqa %xmm0, 0x180(%rsp)
vmovdqa 0x190(%rsp), %xmm0
vpxor 0x180(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x90(%rsp)
movq 0x128(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x128(%rsp)
jmp 0x31c6
movq 0x140(%rsp), %rax
andq $0x1f, %rax
cmpq $0x0, %rax
je 0x378a
leaq 0x100(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1030
leaq 0x100(%rsp), %rdi
movq 0x148(%rsp), %rsi
addq 0x128(%rsp), %rsi
movq 0x140(%rsp), %rdx
andq $0x1f, %rdx
callq 0x10b0
leaq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x1060
movq 0x158(%rsp), %rdi
addq 0x128(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
movq 0x140(%rsp), %rdx
andq $0x1f, %rdx
callq 0x10b0
movq 0x140(%rsp), %rdi
movq 0x130(%rsp), %rsi
leaq 0xd0(%rsp), %rcx
leaq 0x50(%rsp), %r8
movl $0x10, %edx
callq 0x1070
movq 0x140(%rsp), %rcx
addq $0x10, %rcx
movq 0x150(%rsp), %rax
movq %rcx, (%rax)
movq 0x158(%rsp), %rax
movq 0x140(%rsp), %rcx
movq 0xd0(%rsp), %rdx
movq %rdx, (%rax,%rcx)
movq 0xd8(%rsp), %rdx
movq %rdx, 0x8(%rax,%rcx)
xorl %eax, %eax
addq $0x548, %rsp            # imm = 0x548
retq
nopl (%rax,%rax)