// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aes256otrsv3/ref/OTR.c
// Function: DFunc
int DFunc(
		  const uint8 *nonce,
		  uint32 nonce_len,
		  const uint8 *ciphertext,
		  uint32 ci_len,
		  uint32 t_len,
		  uint8 *plaintext)
{
	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(ci_len != 0){
		last = ci_len % DBLOCK;
		if(last == 0) last = DBLOCK;
		ell = (ci_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(Ls,ciphertext+j,tmp);
		Encryption(KeyLen, tmp, tmp);
		xor(tmp,ciphertext+(j+BLOCK),plaintext+j);
		xor(L,plaintext+j,tmp);
		Encryption(KeyLen, tmp, tmp);
		xor(tmp,ciphertext+j,plaintext+(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,ciphertext+j,plaintext+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*/
		ozp(last-BLOCK,ciphertext+(j+BLOCK),tmp); //tmp = ozp(C[m])
		xor(Sum,tmp,Sum);
		xor(Ls,tmp,tmp);
		Encryption(KeyLen,tmp,tmp);
		xor(tmp,ciphertext+j,plaintext+j);
		xor(L,plaintext+j,tmp);
		Encryption(KeyLen,tmp,Z);
		xorp(last-BLOCK,Z,ciphertext+(j+BLOCK),plaintext+(j+BLOCK));
		xor(Sum,Z,Sum);
		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 0x19a9
movl 0x5c(%rsp), %eax
andl $0x1f, %eax
movl %eax, 0x40(%rsp)
cmpl $0x0, 0x40(%rsp)
jne 0x199a
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 0x1ae1
movq 0x60(%rsp), %rsi
movl 0x48(%rsp), %eax
addq %rax, %rsi
leaq 0x30(%rsp), %rdx
movq 0x460f(%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
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 0x455f(%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
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 0x50(%rsp), %rsi
movl 0x48(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rsi
leaq 0x10(%rsp), %rdx
callq 0x1310
movq 0x44f8(%rip), %rdx      # 0x5fa0
movq 0x4549(%rip), %rsi      # 0x5ff8
movq %rdx, %rdi
callq 0x1310
movq 0x453a(%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 0x19c3
cmpl $0x10, 0x40(%rsp)
ja 0x1b63
leaq 0x20(%rsp), %rdx
movl $0x100, %edi            # imm = 0x100
movq 0x44a7(%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 0x50(%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 0x4447(%rip), %rax      # 0x5fa0
movq %rax, 0x8(%rsp)
jmp 0x1c69
movl 0x40(%rsp), %edi
subl $0x10, %edi
movq 0x60(%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 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x1310
leaq 0x30(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq 0x444e(%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 0x50(%rsp), %rsi
movl 0x48(%rsp), %eax
addq %rax, %rsi
leaq 0x30(%rsp), %rdx
movq 0x43a3(%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
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x1310
movq 0x4394(%rip), %rax      # 0x5ff8
movq %rax, 0x8(%rsp)
cmpl $0x10, 0x40(%rsp)
je 0x1c77
cmpl $0x20, 0x40(%rsp)
jne 0x1c88
movq 0x8(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x18a0
jmp 0x1c97
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 0x4324(%rip), %rdx      # 0x5fe0
callq 0x10f0
xorl %eax, %eax
addq $0x78, %rsp
retq
nopl (%rax,%rax)