// File: /workspace/github_c_makefile_star2_O3/mjosaarinen[P]brutus/crypto_aead/aescopav2/ref/encrypt.c
// Function: mac
void mac(unsigned char* out, 
		const unsigned char* in, unsigned long long len, 
		const unsigned char* LL,
		const unsigned char* k)
{
	block_t v = { 0 }, delta, block;
	unsigned int i;

	gf128_mul3(delta, LL);
	gf128_mul3(delta, delta);
	gf128_mul3(delta, delta); /* delta = 3^3*L */

	/* mac full blocks except last */
	while (len > 16) {
		xor_block(block, in, delta);
		AES_ENCRYPT(block, block, k);
		xor_block(v, v, block);

		gf128_mul2(delta, delta);

		in += 16;
		len -= 16;
	}

	if (len == 16) { /* last block full */
		gf128_mul3(delta, delta);
		xor_block(v, v, delta);
		xor_block(v, v, in);
		AES_ENCRYPT(out, v, k);
	} else { /* last block partial */
		gf128_mul3(delta, delta);
		gf128_mul3(delta, delta);
		xor_block(v, v, delta);
		for (i = 0; i < len; i++) {
			v[i] ^= in[i];
		}
		v[len] ^= 0x80; /* padding */
		AES_ENCRYPT(out, v, k);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %r8, %r14
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, 0x38(%rsp)
vpxor %xmm0, %xmm0, %xmm0
vmovdqa %xmm0, 0x10(%rsp)
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %rcx, %rsi
callq 0x1dac
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x1dac
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x1dac
cmpq $0x11, %r12
jb 0x1cf0
leaq 0x60(%rsp), %r13
leaq 0x50(%rsp), %rbp
leaq 0x40(%rsp), %rbx
movw $0x7fff, %ax            # imm = 0x7FFF
kmovd %eax, %k1
kmovw %k1, 0xe(%rsp)
vmovaps 0x20(%rsp), %xmm0
vxorps (%r15), %xmm0, %xmm0
vmovaps %xmm0, 0x50(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x10c0
movq %rbp, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x10b0
vmovaps 0x40(%rsp), %xmm0
vmovaps %xmm0, 0x50(%rsp)
vxorps 0x10(%rsp), %xmm0, %xmm0
vmovaps %xmm0, 0x10(%rsp)
movb 0x20(%rsp), %al
vmovd %eax, %xmm0
vpbroadcastb %xmm0, %xmm0
leaq 0x21(%rsp), %rcx
kmovw 0xe(%rsp), %k1
vmovdqu8 (%rcx), %xmm1 {%k1} {z}
vpalignr $0xf, %xmm0, %xmm1, %xmm0 # xmm0 = xmm0[15],xmm1[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
vpaddw %xmm0, %xmm0, %xmm0
vpsrlw $0x7, %xmm1, %xmm1
vpternlogd $0xd8, 0x1b72(%rip){1to4}, %xmm0, %xmm1 # 0x3830
vmovdqu8 %xmm1, 0x20(%rsp) {%k1}
movb 0x2f(%rsp), %cl
addb %cl, %cl
movzbl %cl, %edx
xorb $-0x79, %cl
testb %al, %al
movzbl %cl, %eax
cmovnsl %edx, %eax
movb %al, 0x2f(%rsp)
addq $0x10, %r15
addq $-0x10, %r12
cmpq $0x10, %r12
ja 0x1c44
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
callq 0x1dac
cmpq $0x10, %r12
jne 0x1d2a
vmovaps 0x20(%rsp), %xmm0
vxorps 0x10(%rsp), %xmm0, %xmm0
vmovaps %xmm0, 0x10(%rsp)
xorl %eax, %eax
movb (%r15,%rax), %cl
xorb %cl, 0x10(%rsp,%rax)
incq %rax
cmpq $0x10, %rax
jne 0x1d17
jmp 0x1d67
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x1dac
vmovaps (%rbx), %xmm0
vxorps 0x10(%rsp), %xmm0, %xmm0
vmovaps %xmm0, 0x10(%rsp)
testq %r12, %r12
je 0x1d61
xorl %eax, %eax
movb (%r15,%rax), %cl
xorb %cl, 0x10(%rsp,%rax)
incq %rax
cmpq %rax, %r12
jne 0x1d51
xorb $-0x80, 0x10(%rsp,%r12)
leaq 0x60(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x10c0
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %r14
movq %r14, %rsi
movq %rbx, %rdx
callq 0x10b0
vmovaps (%r14), %xmm0
movq 0x38(%rsp), %rax
vmovups %xmm0, (%rax)
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq