// File: /workspace/github_c_makefile_star2_O3/mjosaarinen[P]brutus/crypto_aead/aes256otrsv3/ref/OTR.c
// Function: AFunc
int AFunc(
		  const uint8 *header,
		  uint32 h_len)
{
	uint32 i,j = 0;
	uint32 m, last;
	uint8 ASum[BLOCK]={0}, tmp[BLOCK], Qt[BLOCK];

	last = h_len % BLOCK;
	if(last == 0) last = BLOCK;
	m = (h_len-last) / BLOCK; /*header = m blocks + last bytes*/

	memcpy(Qt,Q,BLOCK);
	/* XE */
	for(i = 0; i < m; i++, j=j+BLOCK){
		xor(Qt,header+j,tmp);
		Encryption(KeyLen,tmp,tmp);
		xor(ASum,tmp,ASum);
		mul2(Qt,Qt);
	}
	/* last block */
	ozp(last,header+j,tmp);
	xor(ASum,tmp,ASum);

	if(last != BLOCK ){/*partial block*/
		mul3(Qt,Qt);
	}
	else{/*integral block*/
		mul3twice(Qt,Qt);
	}
	xor(ASum,Qt,ASum);
	Encryption(KeyLen,ASum,TA);
    return SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %esi, %ebp
movq %rdi, %rbx
vxorps %xmm0, %xmm0, %xmm0
vmovaps %xmm0, 0x30(%rsp)
movl %esi, %r15d
andl $0xf, %r15d
movl $0x10, %ecx
cmovnel %r15d, %ecx
subl %ecx, %ebp
movq 0x3386(%rip), %rax      # 0x4fc0
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, 0x10(%rsp)
cmpl $0x10, %ebp
jae 0x1c51
xorl %r13d, %r13d
jmp 0x1d19
movl %ecx, 0x48(%rsp)
movl %r15d, 0x4c(%rsp)
shrl $0x4, %ebp
leaq 0x11(%rsp), %r15
xorl %r13d, %r13d
leaq 0x20(%rsp), %r14
movw $0x7fff, %ax            # imm = 0x7FFF
kmovd %eax, %k1
kmovw %k1, 0xe(%rsp)
leaq 0x13a1(%rip), %r12      # 0x3020
vmovups (%rbx,%r13), %xmm0
vxorps 0x10(%rsp), %xmm0, %xmm0
vmovaps %xmm0, 0x20(%rsp)
movl $0x100, %edi            # imm = 0x100
movq %r14, %rsi
movq %r14, %rdx
callq 0x1100
vmovaps 0x20(%rsp), %xmm0
vxorps 0x30(%rsp), %xmm0, %xmm0
vmovaps %xmm0, 0x30(%rsp)
movzbl 0x10(%rsp), %eax
vmovd %eax, %xmm0
vpbroadcastb %xmm0, %xmm0
kmovw 0xe(%rsp), %k1
vmovdqu8 (%r15), %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]
vpsrlw $0x7, %xmm1, %xmm1
vpaddw %xmm0, %xmm0, %xmm0
vpternlogd $0xe4, 0x1319(%rip){1to4}, %xmm1, %xmm0 # 0x3000
vmovdqu8 %xmm0, 0x10(%rsp) {%k1}
shrl $0x7, %eax
movb 0x1f(%rsp), %cl
addb %cl, %cl
xorb (%rax,%r12), %cl
movb %cl, 0x1f(%rsp)
addq $0x10, %r13
decl %ebp
jne 0x1c7f
andl $-0x10, %r13d
movl 0x4c(%rsp), %r15d
movl 0x48(%rsp), %ecx
addq %r13, %rbx
movl %ecx, %r14d
movl $0x10, %eax
subq %r14, %rax
xorl %edx, %edx
testl %r15d, %r15d
cmovneq %rax, %rdx
leaq (%rsp,%r14), %rdi
addq $0x20, %rdi
xorl %esi, %esi
callq 0x1030
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1110
testl %r15d, %r15d
je 0x1d7b
movb $-0x80, 0x20(%rsp,%r14)
vmovaps 0x20(%rsp), %xmm0
vxorps 0x30(%rsp), %xmm0, %xmm0
vmovaps %xmm0, 0x30(%rsp)
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
callq 0x130c
jmp 0x1daf
vmovaps 0x20(%rsp), %xmm0
vxorps 0x30(%rsp), %xmm0, %xmm0
vmovaps %xmm0, 0x30(%rsp)
leaq 0x10(%rsp), %rbx
leaq 0x50(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1f57
vmovaps (%r14), %xmm0
vxorps (%rbx), %xmm0, %xmm0
vmovaps %xmm0, (%rbx)
vmovaps 0x10(%rsp), %xmm0
leaq 0x30(%rsp), %rsi
vxorps (%rsi), %xmm0, %xmm0
vmovaps %xmm0, (%rsi)
movq 0x321f(%rip), %rdx      # 0x4fe8
movl $0x100, %edi            # imm = 0x100
callq 0x1100
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq