// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aes256otrpv3/ni_p8m1/encrypt.c
// Function: AFunc
__m128i AFunc(
	const uint8 *header,
	uint32 h_len)
{
	uint32 i;
	uint32 m, last;
	block tmp[PIPE], mask[PIPE + 1], ASum = _mm_setzero_si128();
	uint32 rest_len = h_len;
	const __m128i *hdp = (__m128i*)header;

	mask[0] = _mm_load_si128(&Q);
	while (rest_len > (BLOCK*PIPE)){
		mul2_PIPE(mask);
		for (i = 0; i < PIPE; i++){
			tmp[i] = _mm_xor_si128(mask[i], hdp[i]);
		}
		AES_ecb_encrypt_PIPE(tmp, encrypt_key);
		for (i = 0; i < PIPE; i++){
			ASum = _mm_xor_si128(ASum, tmp[i]);
		}
		rest_len -= (BLOCK*PIPE);
		hdp += PIPE;
		mask[0] = _mm_load_si128(&mask[PIPE]);
	}

	last = rest_len % BLOCK;
	if (last == 0) last = BLOCK;
	m = (rest_len - last) / BLOCK; //header = m blocks + last bytes

	for (i = 0; i < m; i++){
		tmp[0] = _mm_xor_si128(mask[0], hdp[i]);
		AES_encrypt(tmp[0], &tmp[0], encrypt_key);
		ASum = _mm_xor_si128(ASum, tmp[0]);
		mul2(mask[0], &mask[0]);
	}
	hdp += m;
	/* last block */
	ozp(last, (uint8*)&hdp[0], &tmp[0]);
	ASum = _mm_xor_si128(ASum, tmp[0]);
	if (last != BLOCK){
		mul3(mask[0], &mask[0]);
	}
	else{
		mul3twice(mask[0], &mask[0]);
	}
	ASum = _mm_xor_si128(ASum, mask[0]);
	AES_encrypt(ASum, &ASum, encrypt_key);
	return ASum; //TA
}

// Assembly:
subq $0x238, %rsp            # imm = 0x238
movq %rdi, 0x148(%rsp)
movl %esi, 0x144(%rsp)
vpxor %xmm0, %xmm0, %xmm0
vmovdqa %xmm0, 0x150(%rsp)
vmovdqa 0x150(%rsp), %xmm0
vmovdqa %xmm0, 0x10(%rsp)
movl 0x144(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x148(%rsp), %rax
movq %rax, (%rsp)
movq 0x58e0(%rip), %rax      # 0xbfe0
movq %rax, 0x168(%rsp)
movq 0x168(%rsp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, 0x20(%rsp)
cmpl $0x80, 0xc(%rsp)
jbe 0x689d
leaq 0x20(%rsp), %rdi
callq 0x2870
movl $0x0, 0x140(%rsp)
cmpl $0x8, 0x140(%rsp)
jae 0x67d0
movl 0x140(%rsp), %eax
movl %eax, %ecx
leaq 0x20(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
vmovdqa (%rax), %xmm1
movq (%rsp), %rax
movl 0x140(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm1, 0x220(%rsp)
vmovdqa %xmm0, 0x210(%rsp)
vmovdqa 0x220(%rsp), %xmm0
vpxor 0x210(%rsp), %xmm0, %xmm0
movl 0x140(%rsp), %eax
movl %eax, %ecx
leaq 0xb0(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
vmovdqa %xmm0, (%rax)
movl 0x140(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x140(%rsp)
jmp 0x673d
leaq 0xb0(%rsp), %rdi
movq 0x5811(%rip), %rsi      # 0xbff0
callq 0x43d0
movl $0x0, 0x140(%rsp)
cmpl $0x8, 0x140(%rsp)
jae 0x6858
vmovdqa 0x10(%rsp), %xmm1
movl 0x140(%rsp), %eax
movl %eax, %ecx
leaq 0xb0(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm1, 0x200(%rsp)
vmovdqa %xmm0, 0x1f0(%rsp)
vmovdqa 0x200(%rsp), %xmm0
vpxor 0x1f0(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x10(%rsp)
movl 0x140(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x140(%rsp)
jmp 0x67ef
movl 0xc(%rsp), %eax
subl $0x80, %eax
movl %eax, 0xc(%rsp)
movq (%rsp), %rax
addq $0x80, %rax
movq %rax, (%rsp)
leaq 0x20(%rsp), %rax
addq $0x80, %rax
movq %rax, 0x160(%rsp)
movq 0x160(%rsp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, 0x20(%rsp)
jmp 0x671a
movl 0xc(%rsp), %eax
andl $0xf, %eax
movl %eax, 0x138(%rsp)
cmpl $0x0, 0x138(%rsp)
jne 0x68c0
movl $0x10, 0x138(%rsp)
movl 0xc(%rsp), %eax
subl 0x138(%rsp), %eax
shrl $0x4, %eax
movl %eax, 0x13c(%rsp)
movl $0x0, 0x140(%rsp)
movl 0x140(%rsp), %eax
cmpl 0x13c(%rsp), %eax
jae 0x69b9
vmovdqa 0x20(%rsp), %xmm1
movq (%rsp), %rax
movl 0x140(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm1, 0x1e0(%rsp)
vmovdqa %xmm0, 0x1d0(%rsp)
vmovdqa 0x1e0(%rsp), %xmm0
vpxor 0x1d0(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0xb0(%rsp)
vmovdqa 0xb0(%rsp), %xmm0
leaq 0xb0(%rsp), %rdi
movq 0x569b(%rip), %rsi      # 0xbff0
callq 0x11e0
vmovdqa 0x10(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm0
vmovdqa %xmm1, 0x1c0(%rsp)
vmovdqa %xmm0, 0x1b0(%rsp)
vmovdqa 0x1c0(%rsp), %xmm0
vpxor 0x1b0(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x10(%rsp)
vmovdqa 0x20(%rsp), %xmm0
leaq 0x20(%rsp), %rdi
callq 0x4df0
movl 0x140(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x140(%rsp)
jmp 0x68e0
movl 0x13c(%rsp), %ecx
movq (%rsp), %rax
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, (%rsp)
movl 0x138(%rsp), %edi
movq (%rsp), %rsi
leaq 0xb0(%rsp), %rdx
callq 0x5160
vmovdqa 0x10(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm0
vmovdqa %xmm1, 0x1a0(%rsp)
vmovdqa %xmm0, 0x190(%rsp)
vmovdqa 0x1a0(%rsp), %xmm0
vpxor 0x190(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x10(%rsp)
cmpl $0x10, 0x138(%rsp)
je 0x6a3e
vmovdqa 0x20(%rsp), %xmm0
leaq 0x20(%rsp), %rdi
callq 0x4ad0
jmp 0x6a4e
vmovdqa 0x20(%rsp), %xmm0
leaq 0x20(%rsp), %rdi
callq 0x5250
vmovdqa 0x10(%rsp), %xmm1
vmovdqa 0x20(%rsp), %xmm0
vmovdqa %xmm1, 0x180(%rsp)
vmovdqa %xmm0, 0x170(%rsp)
vmovdqa 0x180(%rsp), %xmm0
vpxor 0x170(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x10(%rsp)
vmovdqa 0x10(%rsp), %xmm0
leaq 0x10(%rsp), %rdi
movq 0x555a(%rip), %rsi      # 0xbff0
callq 0x11e0
vmovdqa 0x10(%rsp), %xmm0
addq $0x238, %rsp            # imm = 0x238
retq
nopl (%rax)