// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aes256otrsv3/ref/OTR.c
// Function: EFunc
int EFunc(
		  const uint8 *nonce,
		  uint32 nonce_len,
		  const uint8 *plaintext,
		  uint32 pl_len,
		  uint32 t_len,
		  uint8 *ciphertext)
{
	uint32 i,j = 0;
	uint32 ell=0; /*number of 2BLOCK-byte chunks, excl. last one*/
	uint32 last=0; /*number of bytes in the last chunks*/

	uint8 tmp[BLOCK], Z[BLOCK];
	uint8 Sum[BLOCK]={0};
	uint8 *La; 

	if(pl_len != 0){
		last = pl_len % DBLOCK;
		if(last == 0) last = DBLOCK;
		ell = (pl_len-last) / DBLOCK; /* plaintext length = 2BLOCK*ell + last (non-zero)*/
	}

	nEnc(nonce, nonce_len, t_len);

	/* 2-round Feistel for the full chunks */
	for(i = 0; i < ell; i++, j = j+DBLOCK){
		xor(L,plaintext+j,tmp);
		Encryption(KeyLen, tmp, tmp);
		xor(tmp,plaintext+(j+BLOCK),ciphertext+j);
		xor(Ls,ciphertext+j,tmp);
		Encryption(KeyLen, tmp, tmp);
		xor(tmp,plaintext+j,ciphertext+(j+BLOCK));
		xor(Sum,plaintext+(j+BLOCK),Sum);
		xor(L,Ls,L); 
		mul2(Ls,Ls); 
	}
	/* Last chunk */
	if(last <= BLOCK){ 	/*odd block, including the case pl_len = 0 (no plaintext)*/
		Encryption(KeyLen, L, Z);
		xorp(last, Z,plaintext+j,ciphertext+j);
		ozp(last,plaintext+j,tmp);
		xor(tmp,Sum,Sum);
		La = L;
	}
	else{/*even blocks, last > BLOCK always holds. 2-round Feistel with last swap*/
		xor(L,plaintext+j,tmp);
		Encryption(KeyLen,tmp,Z);
		xorp(last-BLOCK,Z,plaintext+(j+BLOCK),ciphertext+(j+BLOCK));
		ozp(last-BLOCK,ciphertext+(j+BLOCK),tmp);
		xor(Sum,Z,Sum);
		xor(Sum,tmp,Sum);
		xor(Ls,tmp,tmp);
		Encryption(KeyLen,tmp,tmp);
		xor(tmp,plaintext+j,ciphertext+j);
		La = Ls;
	}
	/* TE generation */
	if(last == BLOCK || last == DBLOCK){/*[last = 16 or 32] = integral block*/
		mul7(La,La);
	}
	else {/*partial block*/
		mul3twice(La,La);
	}
	xor(Sum, La, Sum);	/*Sum = (3^2 or 7)La xor Sum*/
	Encryption(KeyLen,Sum,TE);
	return SUCCESS;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movl %esi, 0x6c(%rsp)
movq %rdx, 0x60(%rsp)
movl %ecx, 0x5c(%rsp)
movl %r8d, 0x58(%rsp)
movq %r9, 0x50(%rsp)
movl $0x0, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, 0x40(%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1030
cmpl $0x0, 0x5c(%rsp)
je 0x14c9
movl 0x5c(%rsp), %eax
andl $0x1f, %eax
movl %eax, 0x40(%rsp)
cmpl $0x0, 0x40(%rsp)
jne 0x14ba
movl $0x20, 0x40(%rsp)
movl 0x5c(%rsp), %eax
subl 0x40(%rsp), %eax
shrl $0x5, %eax
movl %eax, 0x44(%rsp)
movq 0x70(%rsp), %rdi
movl 0x6c(%rsp), %esi
movl 0x58(%rsp), %edx
callq 0x10e0
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x44(%rsp), %eax
jae 0x1601
movq 0x60(%rsp), %rsi
movl 0x48(%rsp), %eax
addq %rax, %rsi
leaq 0x30(%rsp), %rdx
movq 0x4a97(%rip), %rdi      # 0x5fa0
callq 0x1310
leaq 0x30(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movl $0x100, %edi            # imm = 0x100
callq 0x10f0
leaq 0x30(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x48(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rsi
movq 0x50(%rsp), %rdx
movl 0x48(%rsp), %eax
addq %rax, %rdx
callq 0x1310
movq 0x50(%rsp), %rsi
movl 0x48(%rsp), %eax
addq %rax, %rsi
leaq 0x30(%rsp), %rdx
movq 0x4a97(%rip), %rdi      # 0x5ff8
callq 0x1310
leaq 0x30(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movl $0x100, %edi            # imm = 0x100
callq 0x10f0
leaq 0x30(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x48(%rsp), %eax
addq %rax, %rsi
movq 0x50(%rsp), %rdx
movl 0x48(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rdx
callq 0x1310
leaq 0x10(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x48(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rsi
leaq 0x10(%rsp), %rdx
callq 0x1310
movq 0x49d8(%rip), %rdx      # 0x5fa0
movq 0x4a29(%rip), %rsi      # 0x5ff8
movq %rdx, %rdi
callq 0x1310
movq 0x4a1a(%rip), %rsi      # 0x5ff8
movq %rsi, %rdi
callq 0x1370
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
movl 0x48(%rsp), %eax
addl $0x20, %eax
movl %eax, 0x48(%rsp)
jmp 0x14e3
cmpl $0x10, 0x40(%rsp)
ja 0x1683
leaq 0x20(%rsp), %rdx
movl $0x100, %edi            # imm = 0x100
movq 0x4987(%rip), %rsi      # 0x5fa0
callq 0x10f0
movl 0x40(%rsp), %edi
leaq 0x20(%rsp), %rsi
movq 0x60(%rsp), %rdx
movl 0x48(%rsp), %eax
addq %rax, %rdx
movq 0x50(%rsp), %rcx
movl 0x48(%rsp), %eax
addq %rax, %rcx
callq 0x17f0
movl 0x40(%rsp), %edi
movq 0x60(%rsp), %rsi
movl 0x48(%rsp), %eax
addq %rax, %rsi
leaq 0x30(%rsp), %rdx
callq 0x1850
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x1310
movq 0x4927(%rip), %rax      # 0x5fa0
movq %rax, 0x8(%rsp)
jmp 0x1789
movq 0x60(%rsp), %rsi
movl 0x48(%rsp), %eax
addq %rax, %rsi
leaq 0x30(%rsp), %rdx
movq 0x4905(%rip), %rdi      # 0x5fa0
callq 0x1310
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movl $0x100, %edi            # imm = 0x100
callq 0x10f0
movl 0x40(%rsp), %edi
subl $0x10, %edi
leaq 0x20(%rsp), %rsi
movq 0x60(%rsp), %rdx
movl 0x48(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rdx
movq 0x50(%rsp), %rcx
movl 0x48(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rcx
callq 0x17f0
movl 0x40(%rsp), %edi
subl $0x10, %edi
movq 0x50(%rsp), %rsi
movl 0x48(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rsi
leaq 0x30(%rsp), %rdx
callq 0x1850
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x1310
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x1310
leaq 0x30(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq 0x48b6(%rip), %rdi      # 0x5ff8
callq 0x1310
leaq 0x30(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movl $0x100, %edi            # imm = 0x100
callq 0x10f0
leaq 0x30(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x48(%rsp), %eax
addq %rax, %rsi
movq 0x50(%rsp), %rdx
movl 0x48(%rsp), %eax
addq %rax, %rdx
callq 0x1310
movq 0x4874(%rip), %rax      # 0x5ff8
movq %rax, 0x8(%rsp)
cmpl $0x10, 0x40(%rsp)
je 0x1797
cmpl $0x20, 0x40(%rsp)
jne 0x17a8
movq 0x8(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x18a0
jmp 0x17b7
movq 0x8(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x18f0
leaq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x1310
leaq 0x10(%rsp), %rsi
movl $0x100, %edi            # imm = 0x100
movq 0x4804(%rip), %rdx      # 0x5fe0
callq 0x10f0
xorl %eax, %eax
addq $0x78, %rsp
retq
nopl (%rax,%rax)