// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aegis256/aesni/encrypt.c
// Function: aegis256_tag_generation
void aegis256_tag_generation(unsigned long long msglen, unsigned long long adlen, unsigned char maclen, unsigned char *mac, __m128i *state)
{
       int i;

        __m128i  tmp;
        __m128i  msgtmp;
        unsigned char t[16], tt[16];

        for (i = 0; i < 16; i++) tt[i] = 0;
	((unsigned long long*)tt)[0] = adlen  << 3;
	((unsigned long long*)tt)[1] = msglen << 3;
	msgtmp = _mm_load_si128((__m128i*)tt);

        msgtmp = _mm_xor_si128(msgtmp, state[3]);

        for (i = 0; i < 7; i++) {  
             //state update function
             tmp = state[5];
             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]);

            //xor "msg" with state[0]
             state[0] = _mm_xor_si128(state[0], msgtmp);
        }

        state[5] = _mm_xor_si128(state[5], state[4]);
        state[5] = _mm_xor_si128(state[5], state[3]);
        state[5] = _mm_xor_si128(state[5], state[2]);
        state[5] = _mm_xor_si128(state[5], state[1]);
        state[5] = _mm_xor_si128(state[5], state[0]);

        _mm_store_si128((__m128i*)t, state[5]);
        //in this program, the mac length is assumed to be multiple of bytes
        memcpy(mac,t,maclen);
}

// Assembly:
subq $0x238, %rsp            # imm = 0x238
movb %dl, %al
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movb %al, 0x67(%rsp)
movq %rcx, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
cmpl $0x10, 0x4c(%rsp)
jge 0x1cf6
movslq 0x4c(%rsp), %rax
movb $0x0, (%rsp,%rax)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x1cd9
movq 0x68(%rsp), %rax
shlq $0x3, %rax
movq %rax, (%rsp)
movq 0x70(%rsp), %rax
shlq $0x3, %rax
movq %rax, 0x8(%rsp)
movq %rsp, %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, 0x20(%rsp)
vmovdqa 0x20(%rsp), %xmm1
movq 0x50(%rsp), %rax
vmovdqa 0x30(%rax), %xmm0
vmovdqa %xmm1, 0x150(%rsp)
vmovdqa %xmm0, 0x140(%rsp)
vmovdqa 0x150(%rsp), %xmm0
vpxor 0x140(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x20(%rsp)
movl $0x0, 0x4c(%rsp)
cmpl $0x7, 0x4c(%rsp)
jge 0x1f74
movq 0x50(%rsp), %rax
vmovdqa 0x50(%rax), %xmm0
vmovdqa %xmm0, 0x30(%rsp)
movq 0x50(%rsp), %rax
vmovdqa 0x40(%rax), %xmm1
movq 0x50(%rsp), %rax
vmovdqa 0x50(%rax), %xmm0
vmovdqa %xmm1, 0x210(%rsp)
vmovdqa %xmm0, 0x200(%rsp)
vmovdqa 0x210(%rsp), %xmm0
vmovdqa 0x200(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
movq 0x50(%rsp), %rax
vmovdqa %xmm0, 0x50(%rax)
movq 0x50(%rsp), %rax
vmovdqa 0x30(%rax), %xmm1
movq 0x50(%rsp), %rax
vmovdqa 0x40(%rax), %xmm0
vmovdqa %xmm1, 0x1f0(%rsp)
vmovdqa %xmm0, 0x1e0(%rsp)
vmovdqa 0x1f0(%rsp), %xmm0
vmovdqa 0x1e0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
movq 0x50(%rsp), %rax
vmovdqa %xmm0, 0x40(%rax)
movq 0x50(%rsp), %rax
vmovdqa 0x20(%rax), %xmm1
movq 0x50(%rsp), %rax
vmovdqa 0x30(%rax), %xmm0
vmovdqa %xmm1, 0x1d0(%rsp)
vmovdqa %xmm0, 0x1c0(%rsp)
vmovdqa 0x1d0(%rsp), %xmm0
vmovdqa 0x1c0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
movq 0x50(%rsp), %rax
vmovdqa %xmm0, 0x30(%rax)
movq 0x50(%rsp), %rax
vmovdqa 0x10(%rax), %xmm1
movq 0x50(%rsp), %rax
vmovdqa 0x20(%rax), %xmm0
vmovdqa %xmm1, 0x1b0(%rsp)
vmovdqa %xmm0, 0x1a0(%rsp)
vmovdqa 0x1b0(%rsp), %xmm0
vmovdqa 0x1a0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
movq 0x50(%rsp), %rax
vmovdqa %xmm0, 0x20(%rax)
movq 0x50(%rsp), %rax
vmovdqa (%rax), %xmm1
movq 0x50(%rsp), %rax
vmovdqa 0x10(%rax), %xmm0
vmovdqa %xmm1, 0x190(%rsp)
vmovdqa %xmm0, 0x180(%rsp)
vmovdqa 0x190(%rsp), %xmm0
vmovdqa 0x180(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
movq 0x50(%rsp), %rax
vmovdqa %xmm0, 0x10(%rax)
vmovdqa 0x30(%rsp), %xmm1
movq 0x50(%rsp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm1, 0x170(%rsp)
vmovdqa %xmm0, 0x160(%rsp)
vmovdqa 0x170(%rsp), %xmm0
vmovdqa 0x160(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
movq 0x50(%rsp), %rax
vmovdqa %xmm0, (%rax)
movq 0x50(%rsp), %rax
vmovdqa (%rax), %xmm1
vmovdqa 0x20(%rsp), %xmm0
vmovdqa %xmm1, 0x130(%rsp)
vmovdqa %xmm0, 0x120(%rsp)
vmovdqa 0x130(%rsp), %xmm0
vpxor 0x120(%rsp), %xmm0, %xmm0
movq 0x50(%rsp), %rax
vmovdqa %xmm0, (%rax)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x1d6a
movq 0x50(%rsp), %rax
vmovdqa 0x50(%rax), %xmm1
movq 0x50(%rsp), %rax
vmovdqa 0x40(%rax), %xmm0
vmovdqa %xmm1, 0x110(%rsp)
vmovdqa %xmm0, 0x100(%rsp)
vmovdqa 0x110(%rsp), %xmm0
vpxor 0x100(%rsp), %xmm0, %xmm0
movq 0x50(%rsp), %rax
vmovdqa %xmm0, 0x50(%rax)
movq 0x50(%rsp), %rax
vmovdqa 0x50(%rax), %xmm1
movq 0x50(%rsp), %rax
vmovdqa 0x30(%rax), %xmm0
vmovdqa %xmm1, 0xf0(%rsp)
vmovdqa %xmm0, 0xe0(%rsp)
vmovdqa 0xf0(%rsp), %xmm0
vpxor 0xe0(%rsp), %xmm0, %xmm0
movq 0x50(%rsp), %rax
vmovdqa %xmm0, 0x50(%rax)
movq 0x50(%rsp), %rax
vmovdqa 0x50(%rax), %xmm1
movq 0x50(%rsp), %rax
vmovdqa 0x20(%rax), %xmm0
vmovdqa %xmm1, 0xd0(%rsp)
vmovdqa %xmm0, 0xc0(%rsp)
vmovdqa 0xd0(%rsp), %xmm0
vpxor 0xc0(%rsp), %xmm0, %xmm0
movq 0x50(%rsp), %rax
vmovdqa %xmm0, 0x50(%rax)
movq 0x50(%rsp), %rax
vmovdqa 0x50(%rax), %xmm1
movq 0x50(%rsp), %rax
vmovdqa 0x10(%rax), %xmm0
vmovdqa %xmm1, 0xb0(%rsp)
vmovdqa %xmm0, 0xa0(%rsp)
vmovdqa 0xb0(%rsp), %xmm0
vpxor 0xa0(%rsp), %xmm0, %xmm0
movq 0x50(%rsp), %rax
vmovdqa %xmm0, 0x50(%rax)
movq 0x50(%rsp), %rax
vmovdqa 0x50(%rax), %xmm1
movq 0x50(%rsp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm1, 0x90(%rsp)
vmovdqa %xmm0, 0x80(%rsp)
vmovdqa 0x90(%rsp), %xmm0
vpxor 0x80(%rsp), %xmm0, %xmm0
movq 0x50(%rsp), %rax
vmovdqa %xmm0, 0x50(%rax)
leaq 0x10(%rsp), %rax
movq 0x50(%rsp), %rcx
vmovdqa 0x50(%rcx), %xmm0
movq %rax, 0x230(%rsp)
vmovdqa %xmm0, 0x220(%rsp)
vmovdqa 0x220(%rsp), %xmm0
movq 0x230(%rsp), %rax
vmovdqa %xmm0, (%rax)
movq 0x58(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movzbl 0x67(%rsp), %eax
movl %eax, %edx
callq 0x10a0
addq $0x238, %rsp            # imm = 0x238
retq