// File: /workspace/github_c_makefile_star2_O0/janmojzis[P]mcencrypt/decrypt.c
// Function: decrypt
int decrypt(unsigned char *e, const unsigned char *sk, const unsigned char *c)
{
	int i, w = 0; 
	uint16_t check;	

	unsigned char r[ SYS_N/8 ];

	gf g[ SYS_T+1 ];
	gf L[ SYS_N ];

	gf s[ SYS_T*2 ];
	gf s_cmp[ SYS_T*2 ];
	gf locator[ SYS_T+1 ];
	gf images[ SYS_N ];

	gf t;

	/* // */

	for (i = 0; i < SYND_BYTES; i++)       r[i] = c[i];
	for (i = SYND_BYTES; i < SYS_N/8; i++) r[i] = 0;

	for (i = 0; i < SYS_T; i++) { g[i] = load2(sk); g[i] &= GFMASK; sk += 2; } g[ SYS_T ] = 1;

	support_gen(L, sk);

	synd(s, g, L, r);

	bm(locator, s);

	root(images, locator, L);

	/* // */
	
	for (i = 0; i < SYS_N/8; i++) 
		e[i] = 0;

	for (i = 0; i < SYS_N; i++)
	{
		t = gf_iszero(images[i]) & 1;

		e[ i/8 ] |= t << (i%8);
		w += t;

	}

	synd(s_cmp, g, L, e);

	/* // */

	check = w;
	check ^= SYS_T;

	for (i = 0; i < SYS_T*2; i++)
		check |= s[i] ^ s_cmp[i]; 

	check -= 1;
	check >>= 15;

	return check ^ 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8a60, %rsp           # imm = 0x8A60
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0xd0, -0x1c(%rbp)
jge 0x9f9f
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movb (%rax,%rcx), %cl
movslq -0x1c(%rbp), %rax
movb %cl, -0x430(%rbp,%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x9f75
movl $0xd0, -0x1c(%rbp)
cmpl $0x400, -0x1c(%rbp)     # imm = 0x400
jge 0x9fc6
movslq -0x1c(%rbp), %rax
movb $0x0, -0x430(%rbp,%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x9fa6
movl $0x0, -0x1c(%rbp)
cmpl $0x80, -0x1c(%rbp)
jge 0xa01f
movq -0x10(%rbp), %rdi
callq 0xddf0
movw %ax, %cx
movslq -0x1c(%rbp), %rax
movw %cx, -0x540(%rbp,%rax,2)
movslq -0x1c(%rbp), %rax
movzwl -0x540(%rbp,%rax,2), %ecx
andl $0x1fff, %ecx           # imm = 0x1FFF
movw %cx, -0x540(%rbp,%rax,2)
movq -0x10(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x10(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x9fcd
movw $0x1, -0x440(%rbp)
leaq -0x4540(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1c20
leaq -0x4740(%rbp), %rdi
leaq -0x540(%rbp), %rsi
leaq -0x4540(%rbp), %rdx
leaq -0x430(%rbp), %rcx
callq 0xda90
leaq -0x4a50(%rbp), %rdi
leaq -0x4740(%rbp), %rsi
callq 0x1e30
leaq -0x8a50(%rbp), %rdi
leaq -0x4a50(%rbp), %rsi
leaq -0x4540(%rbp), %rdx
callq 0xd5f0
movl $0x0, -0x1c(%rbp)
cmpl $0x400, -0x1c(%rbp)     # imm = 0x400
jge 0xa0ad
movq -0x8(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa08d
movl $0x0, -0x1c(%rbp)
cmpl $0x2000, -0x1c(%rbp)    # imm = 0x2000
jge 0xa134
movslq -0x1c(%rbp), %rax
movzwl -0x8a50(%rbp,%rax,2), %edi
callq 0xb1e0
movzwl %ax, %eax
andl $0x1, %eax
movw %ax, -0x8a52(%rbp)
movzwl -0x8a52(%rbp), %esi
movl -0x1c(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %edx, %ecx
shll %cl, %esi
movq -0x8(%rbp), %rax
movq %rax, -0x8a60(%rbp)
movl -0x1c(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x8a60(%rbp), %rax
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movzwl -0x8a52(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa0b4
leaq -0x4940(%rbp), %rdi
leaq -0x540(%rbp), %rsi
leaq -0x4540(%rbp), %rdx
movq -0x8(%rbp), %rcx
callq 0xda90
movl -0x20(%rbp), %eax
movw %ax, -0x22(%rbp)
movzwl -0x22(%rbp), %eax
xorl $0x80, %eax
movw %ax, -0x22(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x100, -0x1c(%rbp)     # imm = 0x100
jge 0xa1a5
movslq -0x1c(%rbp), %rax
movzwl -0x4740(%rbp,%rax,2), %ecx
movslq -0x1c(%rbp), %rax
movzwl -0x4940(%rbp,%rax,2), %eax
xorl %eax, %ecx
movzwl -0x22(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x22(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa16d
movzwl -0x22(%rbp), %eax
subl $0x1, %eax
movw %ax, -0x22(%rbp)
movzwl -0x22(%rbp), %eax
sarl $0xf, %eax
movw %ax, -0x22(%rbp)
movzwl -0x22(%rbp), %eax
xorl $0x1, %eax
addq $0x8a60, %rsp           # imm = 0x8A60
popq %rbp
retq
nopl (%rax,%rax)