// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aes256otrsv2/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], LdL[BLOCK], Llast[BLOCK], Z[BLOCK];
	uint8 Sum[BLOCK]={0};

	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(L,delta,LdL);
		xor(LdL,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);
		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,ciphertext+j,plaintext+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,delta,Llast); //Llast = L xor delta
		ozp(last-BLOCK,ciphertext+(j+BLOCK),tmp);
		xor(Sum,tmp,Sum);
		xor(Llast,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);
	}
	/* 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 0x191d
movl 0x6c(%rsp), %eax
andl $0x1f, %eax
movl %eax, 0x50(%rsp)
cmpl $0x0, 0x50(%rsp)
jne 0x190e
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 0x1a54
leaq 0x30(%rsp), %rdx
movq 0x3644(%rip), %rdi      # 0x4f98
movq 0x366d(%rip), %rsi      # 0x4fc8
callq 0x13d0
leaq 0x30(%rsp), %rdi
movq 0x70(%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
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rsi
movq 0x60(%rsp), %rdx
movl 0x58(%rsp), %eax
addq %rax, %rdx
callq 0x13d0
movq 0x60(%rsp), %rsi
movl 0x58(%rsp), %eax
addq %rax, %rsi
leaq 0x40(%rsp), %rdx
movq 0x35ca(%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
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 0x60(%rsp), %rsi
movl 0x58(%rsp), %eax
addl $0x10, %eax
movl %eax, %eax
addq %rax, %rsi
movq %rsp, %rdx
callq 0x13d0
movq 0x3567(%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 0x193a
cmpl $0x10, 0x50(%rsp)
ja 0x1ae2
leaq 0x10(%rsp), %rdx
movl $0x100, %edi            # imm = 0x100
movq 0x3528(%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 0x60(%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 0x34cc(%rip), %rax      # 0x4f98
movq (%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
jmp 0x1bea
leaq 0x20(%rsp), %rdx
movq 0x34aa(%rip), %rdi      # 0x4f98
movq 0x34d3(%rip), %rsi      # 0x4fc8
callq 0x13d0
movl 0x50(%rsp), %edi
subl $0x10, %edi
movq 0x70(%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
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
movq 0x60(%rsp), %rsi
movl 0x58(%rsp), %eax
addq %rax, %rsi
leaq 0x40(%rsp), %rdx
movq 0x340a(%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
movq %rsp, %rdi
leaq 0x10(%rsp), %rsi
movq %rsp, %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 0x1c2b
cmpl $0x20, 0x50(%rsp)
jne 0x1c3d
movq %rsp, %rdi
movq %rsp, %rdx
movq 0x3390(%rip), %rsi      # 0x4fc8
callq 0x13d0
movq %rsp, %rsi
movl $0x100, %edi            # imm = 0x100
movq 0x3394(%rip), %rdx      # 0x4fe0
callq 0x10f0
xorl %eax, %eax
addq $0x88, %rsp
retq
nopl (%rax,%rax)