// File: /workspace/github_c_makefile_star2_O0/janmojzis[P]mcencrypt/operations.c
// Function: crypto_kem_mceliece8192128sha512_dec
int crypto_kem_mceliece8192128sha512_dec(
       unsigned char *key,
       const unsigned char *c,
       const unsigned char *sk
)
{
	int i;

	unsigned char ret_confirm = 0;
	unsigned char ret_decrypt = 0;

	uint16_t m;

	unsigned char conf[64];
	unsigned char two_e[ 1 + SYS_N/8 ] = {2};
	unsigned char *e = two_e + 1;
	unsigned char preimage[ 1 + SYS_N/8 + (SYND_BYTES + 32) ];

	/* // */

	ret_decrypt = decrypt(e, sk + SYS_N/8, c);

	crypto_hash_sha512(conf, two_e, sizeof(two_e)); 

	for (i = 0; i < 32; i++)
		ret_confirm |= conf[i] ^ c[SYND_BYTES + i];

	m = ret_decrypt | ret_confirm;
	m -= 1;
	m >>= 8;

	{
		unsigned char *x = preimage;
		*x++ = (~m & 0) |  (m & 1);
		for (i = 0; i < SYS_N/8; i++) 
			*x++ = (~m & sk[i]) | (m & e[i]);
		for (i = 0; i < SYND_BYTES + 32; i++) 
			*x++ = c[i];
	}

	crypto_hash_sha512(key, preimage, sizeof(preimage)); 

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x980, %rsp            # imm = 0x980
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb $0x0, -0x1d(%rbp)
movb $0x0, -0x1e(%rbp)
leaq -0x470(%rbp), %rdi
xorl %esi, %esi
movl $0x401, %edx            # imm = 0x401
callq 0x1070
movb $0x2, -0x470(%rbp)
leaq -0x470(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x478(%rbp)
movq -0x478(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x400, %rsi            # imm = 0x400
movq -0x10(%rbp), %rdx
callq 0x9f50
movb %al, -0x1e(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x470(%rbp), %rsi
movl $0x401, %edx            # imm = 0x401
callq 0x9740
movl $0x0, -0x1c(%rbp)
cmpl $0x20, -0x1c(%rbp)
jge 0xbefe
movslq -0x1c(%rbp), %rax
movzbl -0x60(%rbp,%rax), %ecx
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %edx
addl $0xd0, %edx
movslq %edx, %rdx
movzbl (%rax,%rdx), %eax
xorl %eax, %ecx
movzbl -0x1d(%rbp), %eax
orl %ecx, %eax
movb %al, -0x1d(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xbec5
movzbl -0x1e(%rbp), %eax
movzbl -0x1d(%rbp), %ecx
orl %ecx, %eax
movw %ax, -0x20(%rbp)
movzwl -0x20(%rbp), %eax
subl $0x1, %eax
movw %ax, -0x20(%rbp)
movzwl -0x20(%rbp), %eax
sarl $0x8, %eax
movw %ax, -0x20(%rbp)
leaq -0x970(%rbp), %rax
movq %rax, -0x978(%rbp)
movzwl -0x20(%rbp), %eax
xorl $-0x1, %eax
andl $0x0, %eax
movzwl -0x20(%rbp), %ecx
andl $0x1, %ecx
orl %ecx, %eax
movb %al, %cl
movq -0x978(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x978(%rbp)
movb %cl, (%rax)
movl $0x0, -0x1c(%rbp)
cmpl $0x400, -0x1c(%rbp)     # imm = 0x400
jge 0xbfbc
movzwl -0x20(%rbp), %eax
xorl $-0x1, %eax
movq -0x18(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
andl %ecx, %eax
movzwl -0x20(%rbp), %ecx
movq -0x478(%rbp), %rdx
movslq -0x1c(%rbp), %rsi
movzbl (%rdx,%rsi), %edx
andl %edx, %ecx
orl %ecx, %eax
movb %al, %cl
movq -0x978(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x978(%rbp)
movb %cl, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xbf63
movl $0x0, -0x1c(%rbp)
cmpl $0xf0, -0x1c(%rbp)
jge 0xbff9
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movb (%rax,%rcx), %cl
movq -0x978(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x978(%rbp)
movb %cl, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xbfc3
movq -0x8(%rbp), %rdi
leaq -0x970(%rbp), %rsi
movl $0x4f1, %edx            # imm = 0x4F1
callq 0x9740
xorl %eax, %eax
addq $0x980, %rsp            # imm = 0x980
popq %rbp
retq
nopl (%rax)