// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aegis128/ref/encrypt.c
// Function: aegis128_tag_generation
void aegis128_tag_generation(unsigned long long msglen, unsigned long long adlen, unsigned char maclen, unsigned char *mac, unsigned char *state)
{
       int i;

        unsigned char tmp[16];
        unsigned char msgtmp[16];

        ((unsigned long long*)msgtmp)[0] = adlen << 3;
        ((unsigned long long*)msgtmp)[1] = msglen << 3;

        XOR128(msgtmp, msgtmp, state+48);

        for (i = 0; i < 7; i++) {
             //state update function
             memcpy(tmp, state+64, 16);

             AESROUND(state+64, state+48, state+64);
             AESROUND(state+48, state+32, state+48);
             AESROUND(state+32, state+16, state+32);
             AESROUND(state+16, state+0,  state+16);
             AESROUND(state+0,  tmp,      state+0);

             //xor "msg" with state[0]
             XOR128(state, state, msgtmp);
        }

        XOR128(state+64, state+64, state+48);
        XOR128(state+64, state+64, state+32);
        XOR128(state+64, state+64, state+16);
        XOR128(state+64, state+64, state+0);

        //in this program, the mac length is assumed to be multiple of bytes
        memcpy(mac, state+64, maclen);
}

// Assembly:
subq $0x58, %rsp
movb %dl, %al
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movb %al, 0x47(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x30(%rsp)
movq 0x48(%rsp), %rax
shlq $0x3, %rax
movq %rax, (%rsp)
movq 0x50(%rsp), %rax
shlq $0x3, %rax
movq %rax, 0x8(%rsp)
movq (%rsp), %rax
movq 0x30(%rsp), %rcx
xorq 0x30(%rcx), %rax
movq %rax, (%rsp)
movq 0x8(%rsp), %rax
movq 0x30(%rsp), %rcx
xorq 0x38(%rcx), %rax
movq %rax, 0x8(%rsp)
movl $0x0, 0x2c(%rsp)
cmpl $0x7, 0x2c(%rsp)
jge 0x1702
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x48(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rdi
addq $0x40, %rdi
movq 0x30(%rsp), %rsi
addq $0x30, %rsi
movq 0x30(%rsp), %rdx
addq $0x40, %rdx
callq 0x1050
movq 0x30(%rsp), %rdi
addq $0x30, %rdi
movq 0x30(%rsp), %rsi
addq $0x20, %rsi
movq 0x30(%rsp), %rdx
addq $0x30, %rdx
callq 0x1050
movq 0x30(%rsp), %rdi
addq $0x20, %rdi
movq 0x30(%rsp), %rsi
addq $0x10, %rsi
movq 0x30(%rsp), %rdx
addq $0x20, %rdx
callq 0x1050
movq 0x30(%rsp), %rdi
addq $0x10, %rdi
movq 0x30(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq $0x10, %rdx
callq 0x1050
movq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x1050
movq 0x30(%rsp), %rax
movq (%rax), %rcx
xorq (%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, (%rax)
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rcx
xorq 0x8(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x8(%rax)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x1615
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x30(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x38(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x20(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x28(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x10(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x18(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rcx
movq 0x30(%rsp), %rax
xorq (%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x8(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x40, %rsi
movzbl 0x47(%rsp), %eax
movl %eax, %edx
callq 0x10c0
addq $0x58, %rsp
retq
nopl (%rax,%rax)