// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aes256otrsv2/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], LdL[BLOCK], Llast[BLOCK], Z[BLOCK];
	uint8 Sum[BLOCK]={0};

	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(L,delta,LdL);
		xor(LdL,ciphertext+j,tmp);
		Encryption(KeyLen, tmp, tmp);
		xor(tmp,plaintext+j,ciphertext+(j+BLOCK));
		xor(Sum,plaintext+(j+BLOCK),Sum);
		mul2(L,L); // L <- 2L
	}
	/* 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);
		memcpy(Llast,L,BLOCK); //Llast=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));
		xor(L,delta,Llast); // Llast = L xor delta
		ozp(last-BLOCK,ciphertext+(j+BLOCK),tmp);
		xor(Sum,tmp,Sum);
		xor(Sum,Z,Sum);
		xor(Llast,tmp,tmp);
		Encryption(KeyLen,tmp,tmp);
		xor(tmp,plaintext+j,ciphertext+j);
	}
	/* TE generation */
	mul2(Llast,tmp);
	xor(Llast,tmp,Llast); //Llast = 3Llast
	xor(Sum,Llast,Sum);	//Sum = 3Llast xor Sum
	if(last == BLOCK || last == DBLOCK){//last = 16 or 32
		xor(Sum,delta,Sum);
	}
	Encryption(KeyLen,Sum,TE);
	return SUCCESS;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movl %esi, 0x7c(%rsp)
movq %rdx, 0x70(%rsp)
movl %ecx, 0x6c(%rsp)
movl %r8d, 0x68(%rsp)
movq %r9, 0x60(%rsp)
movl $0x0, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
movl $0x0, 0x50(%rsp)
movq %rsp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1030
cmpl $0x0, 0x6c(%rsp)
je 0x14ad
movl 0x6c(%rsp), %eax
andl $0x1f, %eax
movl %eax, 0x50(%rsp)
cmpl $0x0, 0x50(%rsp)
jne 0x149e
movl $0x20, 0x50(%rsp)
movl 0x6c(%rsp), %eax
subl 0x50(%rsp), %eax
shrl $0x5, %eax
movl %eax, 0x54(%rsp)
movq 0x80(%rsp), %rdi
movl 0x7c(%rsp), %esi
movl 0x68(%rsp), %edx
callq 0x10e0
movl $0x0, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0x54(%rsp), %eax
jae 0x15e4
movq 0x70(%rsp), %rsi
movl 0x58(%rsp), %eax
addq %rax, %rsi
leaq 0x40(%rsp), %rdx
movq 0x3aa8(%rip), %rdi      # 0x4f98
callq 0x13d0
leaq 0x40(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movl $0x100, %edi            # imm = 0x100
callq 0x10f0
leaq 0x40(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl 0x58(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rsi
movq 0x60(%rsp), %rdx
movl 0x58(%rsp), %eax
addq %rax, %rdx
callq 0x13d0
leaq 0x30(%rsp), %rdx
movq 0x3a5c(%rip), %rdi      # 0x4f98
movq 0x3a85(%rip), %rsi      # 0x4fc8
callq 0x13d0
leaq 0x30(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x58(%rsp), %eax
addq %rax, %rsi
leaq 0x40(%rsp), %rdx
callq 0x13d0
leaq 0x40(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movl $0x100, %edi            # imm = 0x100
callq 0x10f0
leaq 0x40(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl 0x58(%rsp), %eax
addq %rax, %rsi
movq 0x60(%rsp), %rdx
movl 0x58(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rdx
callq 0x13d0
movq %rsp, %rdi
movq 0x70(%rsp), %rsi
movl 0x58(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rsi
movq %rsp, %rdx
callq 0x13d0
movq 0x39d7(%rip), %rsi      # 0x4f98
movq %rsi, %rdi
callq 0x1270
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
movl 0x58(%rsp), %eax
addl $0x20, %eax
movl %eax, 0x58(%rsp)
jmp 0x14ca
cmpl $0x10, 0x50(%rsp)
ja 0x1672
leaq 0x10(%rsp), %rdx
movl $0x100, %edi            # imm = 0x100
movq 0x3998(%rip), %rsi      # 0x4f98
callq 0x10f0
movl 0x50(%rsp), %edi
leaq 0x10(%rsp), %rsi
movq 0x70(%rsp), %rdx
movl 0x58(%rsp), %eax
addq %rax, %rdx
movq 0x60(%rsp), %rcx
movl 0x58(%rsp), %eax
addq %rax, %rcx
callq 0x17f0
movl 0x50(%rsp), %edi
movq 0x70(%rsp), %rsi
movl 0x58(%rsp), %eax
addq %rax, %rsi
leaq 0x40(%rsp), %rdx
callq 0x1850
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
movq %rsp, %rdx
callq 0x13d0
movq 0x393c(%rip), %rax      # 0x4f98
movq (%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
jmp 0x177a
movq 0x70(%rsp), %rsi
movl 0x58(%rsp), %eax
addq %rax, %rsi
leaq 0x40(%rsp), %rdx
movq 0x390e(%rip), %rdi      # 0x4f98
callq 0x13d0
leaq 0x40(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movl $0x100, %edi            # imm = 0x100
callq 0x10f0
movl 0x50(%rsp), %edi
subl $0x10, %edi
leaq 0x10(%rsp), %rsi
movq 0x70(%rsp), %rdx
movl 0x58(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rdx
movq 0x60(%rsp), %rcx
movl 0x58(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rcx
callq 0x17f0
leaq 0x20(%rsp), %rdx
movq 0x38b6(%rip), %rdi      # 0x4f98
movq 0x38df(%rip), %rsi      # 0x4fc8
callq 0x13d0
movl 0x50(%rsp), %edi
subl $0x10, %edi
movq 0x60(%rsp), %rsi
movl 0x58(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rsi
leaq 0x40(%rsp), %rdx
callq 0x1850
movq %rsp, %rdi
leaq 0x40(%rsp), %rsi
movq %rsp, %rdx
callq 0x13d0
movq %rsp, %rdi
leaq 0x10(%rsp), %rsi
movq %rsp, %rdx
callq 0x13d0
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x13d0
leaq 0x40(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movl $0x100, %edi            # imm = 0x100
callq 0x10f0
leaq 0x40(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl 0x58(%rsp), %eax
addq %rax, %rsi
movq 0x60(%rsp), %rdx
movl 0x58(%rsp), %eax
addq %rax, %rdx
callq 0x13d0
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1270
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x13d0
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
movq %rsp, %rdx
callq 0x13d0
cmpl $0x10, 0x50(%rsp)
je 0x17bb
cmpl $0x20, 0x50(%rsp)
jne 0x17cd
movq %rsp, %rdi
movq %rsp, %rdx
movq 0x3800(%rip), %rsi      # 0x4fc8
callq 0x13d0
movq %rsp, %rsi
movl $0x100, %edi            # imm = 0x100
movq 0x3804(%rip), %rdx      # 0x4fe0
callq 0x10f0
xorl %eax, %eax
addq $0x88, %rsp
retq
nopl (%rax,%rax)