// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/aes256otrpv3/ni_p8m1/encrypt.c
// Function: AFuncS
__m128i AFuncS(
	const uint8 *header,
	uint32 h_len)
{
	uint32 i;
	uint32 m, last;
	block chain = _mm_setzero_si128(), tmp, mask;
	const __m128i *hdp = (__m128i*)header;

	last = h_len % BLOCK;
	if (last == 0) last = BLOCK;
	m = (h_len - last) / BLOCK; //header = m blocks + last bytes

	for (i = 0; i < m; i++){
		chain = _mm_xor_si128(chain, hdp[i]);
		AES_encrypt(chain, &chain, encrypt_key);
	}
	hdp += m;
	/* last block */
	ozp(last, (uint8*)&hdp[0], &tmp);
	chain = _mm_xor_si128(tmp, chain);
	if (last != BLOCK){
		mul2(Q, &mask);
	}
	else{
		mul4(Q, &mask);
	}
	chain = _mm_xor_si128(chain, mask);
	AES_encrypt(chain, &chain, encrypt_key);
	return chain; //TA
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
movl %esi, %ebp
andl $0xf, %ebp
movl $0x10, %eax
cmovnel %ebp, %eax
subl %eax, %esi
movl %esi, %ecx
shrl $0x4, %ecx
vpxor %xmm15, %xmm15, %xmm15
cmpl $0x10, %esi
jb 0x2e7e
movq 0x5235(%rip), %rdx      # 0x7ff0
vmovdqa (%rdx), %xmm0
vmovdqa 0x10(%rdx), %xmm1
vmovdqa 0x20(%rdx), %xmm2
vmovdqa 0x30(%rdx), %xmm3
vmovdqa 0x40(%rdx), %xmm4
vmovdqa 0x50(%rdx), %xmm5
vmovdqa 0x60(%rdx), %xmm6
vmovdqa 0x70(%rdx), %xmm7
vmovdqa 0x80(%rdx), %xmm8
vmovdqa 0x90(%rdx), %xmm9
vmovdqa 0xa0(%rdx), %xmm10
vmovdqa 0xb0(%rdx), %xmm11
vmovdqa 0xc0(%rdx), %xmm12
vmovdqa 0xd0(%rdx), %xmm13
vmovdqa 0xe0(%rdx), %xmm14
cmpl $0x1, %ecx
movl %ecx, %edx
adcl $0x0, %edx
shll $0x4, %edx
xorl %esi, %esi
vpternlogq $0x96, (%rbx,%rsi), %xmm0, %xmm15
vaesenc %xmm1, %xmm15, %xmm15
vaesenc %xmm2, %xmm15, %xmm15
vaesenc %xmm3, %xmm15, %xmm15
vaesenc %xmm4, %xmm15, %xmm15
vaesenc %xmm5, %xmm15, %xmm15
vaesenc %xmm6, %xmm15, %xmm15
vaesenc %xmm7, %xmm15, %xmm15
vaesenc %xmm8, %xmm15, %xmm15
vaesenc %xmm9, %xmm15, %xmm15
vaesenc %xmm10, %xmm15, %xmm15
vaesenc %xmm11, %xmm15, %xmm15
vaesenc %xmm12, %xmm15, %xmm15
vaesenc %xmm13, %xmm15, %xmm15
vaesenclast %xmm14, %xmm15, %xmm15
addq $0x10, %rsi
cmpq %rsi, %rdx
jne 0x2e27
vmovdqa %xmm15, (%rsp)
shll $0x4, %ecx
addq %rcx, %rbx
movl %eax, %r14d
movl $0x11, %edx
subq %r14, %rdx
leaq (%rsp,%r14), %r15
addq $0x10, %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x1030
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x10a0
movb $-0x80, (%r15)
vmovdqa (%r12), %xmm0
movq 0x5116(%rip), %rax      # 0x7fe0
vmovdqa (%rax), %xmm1
vpshufb 0x1129(%rip), %xmm1, %xmm2 # 0x4000
vpshufd $0x93, %xmm2, %xmm1     # xmm1 = xmm2[3,0,1,2]
vpsrad $0x1f, %xmm1, %xmm1
vpaddd %xmm2, %xmm2, %xmm2
vpternlogd $0x6c, 0x1160(%rip), %xmm2, %xmm1 # 0x4050
testl %ebp, %ebp
jne 0x2f0d
vpshufd $0x93, %xmm2, %xmm2     # xmm2 = xmm2[3,0,1,2]
vpsrad $0x1f, %xmm2, %xmm2
vpaddd %xmm1, %xmm1, %xmm1
vpternlogd $0x78, 0x1143(%rip), %xmm2, %xmm1 # 0x4050
vmovdqa (%rsp), %xmm2
vpshufb 0x10e5(%rip), %xmm1, %xmm1 # 0x4000
movq 0x50ce(%rip), %rax      # 0x7ff0
vpxor %xmm2, %xmm0, %xmm0
vpternlogq $0x96, (%rax), %xmm1, %xmm0
vaesenc 0x10(%rax), %xmm0, %xmm0
vaesenc 0x20(%rax), %xmm0, %xmm0
vaesenc 0x30(%rax), %xmm0, %xmm0
vaesenc 0x40(%rax), %xmm0, %xmm0
vaesenc 0x50(%rax), %xmm0, %xmm0
vaesenc 0x60(%rax), %xmm0, %xmm0
vaesenc 0x70(%rax), %xmm0, %xmm0
vaesenc 0x80(%rax), %xmm0, %xmm0
vaesenc 0x90(%rax), %xmm0, %xmm0
vaesenc 0xa0(%rax), %xmm0, %xmm0
vaesenc 0xb0(%rax), %xmm0, %xmm0
vaesenc 0xc0(%rax), %xmm0, %xmm0
vaesenc 0xd0(%rax), %xmm0, %xmm0
vaesenclast 0xe0(%rax), %xmm0, %xmm0
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq