// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aegis128l/ref/ecrypt.c
// Function: aegis128L_tag_generation
void aegis128L_tag_generation(unsigned long msglen, unsigned 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+32);

        for (i = 0; i < 7; i++) {
            //state update function
            memcpy(tmp, state+112, 16);
            AESROUND(state+112,state+96, state+112);
            AESROUND(state+96, state+80, state+96);
            AESROUND(state+80, state+64, state+80);
            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);

            //message is used to update the state.
            XOR128(state,    state,    msgtmp);
            XOR128(state+64, state+64, msgtmp);
        }

        XOR128(state+96, state+96, state+80);
        XOR128(state+96, state+96, state+64);
        XOR128(state+96, state+96, state+48);
        XOR128(state+96, state+96, state+32);
        XOR128(state+96, state+96, state+16);
        XOR128(state+96, state+96, state+0);

        //in this program, the mac length is assumed to be multiple of bytes
        memcpy(mac,state+96,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 0x20(%rcx), %rax
movq %rax, (%rsp)
movq 0x8(%rsp), %rax
movq 0x30(%rsp), %rcx
xorq 0x28(%rcx), %rax
movq %rax, 0x8(%rsp)
movl $0x0, 0x2c(%rsp)
cmpl $0x7, 0x2c(%rsp)
jge 0x183f
movq 0x30(%rsp), %rax
movq 0x70(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x78(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rdi
addq $0x70, %rdi
movq 0x30(%rsp), %rsi
addq $0x60, %rsi
movq 0x30(%rsp), %rdx
addq $0x70, %rdx
callq 0x1050
movq 0x30(%rsp), %rdi
addq $0x60, %rdi
movq 0x30(%rsp), %rsi
addq $0x50, %rsi
movq 0x30(%rsp), %rdx
addq $0x60, %rdx
callq 0x1050
movq 0x30(%rsp), %rdi
addq $0x50, %rdi
movq 0x30(%rsp), %rsi
addq $0x40, %rsi
movq 0x30(%rsp), %rdx
addq $0x50, %rdx
callq 0x1050
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)
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rcx
xorq (%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rcx
xorq 0x8(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x48(%rax)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x16c5
movq 0x30(%rsp), %rax
movq 0x60(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x50(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x60(%rax)
movq 0x30(%rsp), %rax
movq 0x68(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x58(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x68(%rax)
movq 0x30(%rsp), %rax
movq 0x60(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x40(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x60(%rax)
movq 0x30(%rsp), %rax
movq 0x68(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x48(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x68(%rax)
movq 0x30(%rsp), %rax
movq 0x60(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x30(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x60(%rax)
movq 0x30(%rsp), %rax
movq 0x68(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x38(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x68(%rax)
movq 0x30(%rsp), %rax
movq 0x60(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x20(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x60(%rax)
movq 0x30(%rsp), %rax
movq 0x68(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x28(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x68(%rax)
movq 0x30(%rsp), %rax
movq 0x60(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x10(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x60(%rax)
movq 0x30(%rsp), %rax
movq 0x68(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x18(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x68(%rax)
movq 0x30(%rsp), %rax
movq 0x60(%rax), %rcx
movq 0x30(%rsp), %rax
xorq (%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x60(%rax)
movq 0x30(%rsp), %rax
movq 0x68(%rax), %rcx
movq 0x30(%rsp), %rax
xorq 0x8(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x68(%rax)
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x60, %rsi
movzbl 0x47(%rsp), %eax
movl %eax, %edx
callq 0x10c0
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)