// File: /workspace/github_c_makefile_star2_O0/janmojzis[P]mcencrypt/benes.c
// Function: apply_benes
void apply_benes(unsigned char * r, const unsigned char * bits, int rev)
{
	int i, iter, inc;

	unsigned char *r_ptr = r;
	const unsigned char *bits_ptr;

	uint64_t r_int_v[2][64];
	uint64_t r_int_h[2][64];
	uint64_t b_int_v[64];
	uint64_t b_int_h[64];

	/* // */

	if (rev) { bits_ptr = bits + 12288; inc = -1024; }
	else     { bits_ptr = bits;         inc = 0;    }
		
	for (i = 0; i < 64; i++)
	{
		r_int_v[0][i] = load8(r_ptr + i*16 + 0);
		r_int_v[1][i] = load8(r_ptr + i*16 + 8);
	}

	transpose_64x64(r_int_h[0], r_int_v[0]);
	transpose_64x64(r_int_h[1], r_int_v[1]);

	for (iter = 0; iter <= 6; iter++)
	{
		for (i = 0; i < 64; i++)
		{
			b_int_v[i] = load8(bits_ptr); bits_ptr += 8;
		}

		bits_ptr += inc;

		transpose_64x64(b_int_h, b_int_v);
	
		layer_ex(r_int_h[0], b_int_h, iter);
	}

	transpose_64x64(r_int_v[0], r_int_h[0]);
	transpose_64x64(r_int_v[1], r_int_h[1]);

	for (iter = 0; iter <= 5; iter++) 
	{
		for (i = 0; i < 64; i++) { b_int_v[i] = load8(bits_ptr); bits_ptr += 8; }
		bits_ptr += inc;

		layer_in(r_int_v, b_int_v, iter);
	}

	for (iter = 4; iter >= 0; iter--) 
	{
		for (i = 0; i < 64; i++) { b_int_v[i] = load8(bits_ptr); bits_ptr += 8; }
		bits_ptr += inc;

		layer_in(r_int_v, b_int_v, iter);
	}

	transpose_64x64(r_int_h[0], r_int_v[0]);
	transpose_64x64(r_int_h[1], r_int_v[1]);

	for (iter = 6; iter >= 0; iter--)
	{
		for (i = 0; i < 64; i++)
		{
			b_int_v[i] = load8(bits_ptr); bits_ptr += 8;
		}

		bits_ptr += inc;

		transpose_64x64(b_int_h, b_int_v);

		layer_ex(r_int_h[0], b_int_h, iter);
	}

	transpose_64x64(r_int_v[0], r_int_h[0]);
	transpose_64x64(r_int_v[1], r_int_h[1]);

	for (i = 0; i < 64; i++)
	{
		store8(r_ptr + i*16 + 0, r_int_v[0][i]);
		store8(r_ptr + i*16 + 8, r_int_v[1][i]);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc30, %rsp            # imm = 0xC30
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x15fb
movq -0x10(%rbp), %rax
addq $0x3000, %rax           # imm = 0x3000
movq %rax, -0x30(%rbp)
movl $0xfffffc00, -0x20(%rbp) # imm = 0xFFFFFC00
jmp 0x160a
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x40, -0x18(%rbp)
jge 0x166c
movq -0x28(%rbp), %rdi
movl -0x18(%rbp), %eax
shll $0x4, %eax
cltq
addq %rax, %rdi
callq 0xdf00
movq %rax, %rcx
movslq -0x18(%rbp), %rax
movq %rcx, -0x430(%rbp,%rax,8)
movq -0x28(%rbp), %rdi
movl -0x18(%rbp), %eax
shll $0x4, %eax
cltq
addq %rax, %rdi
addq $0x8, %rdi
callq 0xdf00
movq %rax, %rcx
movslq -0x18(%rbp), %rax
movq %rcx, -0x230(%rbp,%rax,8)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1611
leaq -0x830(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0xdbf0
leaq -0x830(%rbp), %rdi
addq $0x200, %rdi            # imm = 0x200
leaq -0x430(%rbp), %rsi
addq $0x200, %rsi            # imm = 0x200
callq 0xdbf0
movl $0x0, -0x1c(%rbp)
cmpl $0x6, -0x1c(%rbp)
jg 0x1735
movl $0x0, -0x18(%rbp)
cmpl $0x40, -0x18(%rbp)
jge 0x16ed
movq -0x30(%rbp), %rdi
callq 0xdf00
movq %rax, %rcx
movslq -0x18(%rbp), %rax
movq %rcx, -0xa30(%rbp,%rax,8)
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x16b8
movl -0x20(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
leaq -0xc30(%rbp), %rdi
leaq -0xa30(%rbp), %rsi
callq 0xdbf0
leaq -0x830(%rbp), %rdi
leaq -0xc30(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x19d0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x16a7
leaq -0x430(%rbp), %rdi
leaq -0x830(%rbp), %rsi
callq 0xdbf0
leaq -0x430(%rbp), %rdi
addq $0x200, %rdi            # imm = 0x200
leaq -0x830(%rbp), %rsi
addq $0x200, %rsi            # imm = 0x200
callq 0xdbf0
movl $0x0, -0x1c(%rbp)
cmpl $0x5, -0x1c(%rbp)
jg 0x17e4
movl $0x0, -0x18(%rbp)
cmpl $0x40, -0x18(%rbp)
jge 0x17b2
movq -0x30(%rbp), %rdi
callq 0xdf00
movq %rax, %rcx
movslq -0x18(%rbp), %rax
movq %rcx, -0xa30(%rbp,%rax,8)
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x177d
movl -0x20(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
leaq -0x430(%rbp), %rdi
leaq -0xa30(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x1ab0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1770
movl $0x4, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x185f
movl $0x0, -0x18(%rbp)
cmpl $0x40, -0x18(%rbp)
jge 0x182d
movq -0x30(%rbp), %rdi
callq 0xdf00
movq %rax, %rcx
movslq -0x18(%rbp), %rax
movq %rcx, -0xa30(%rbp,%rax,8)
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x17f8
movl -0x20(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
leaq -0x430(%rbp), %rdi
leaq -0xa30(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x1ab0
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x17eb
leaq -0x830(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0xdbf0
leaq -0x830(%rbp), %rdi
addq $0x200, %rdi            # imm = 0x200
leaq -0x430(%rbp), %rsi
addq $0x200, %rsi            # imm = 0x200
callq 0xdbf0
movl $0x6, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x1928
movl $0x0, -0x18(%rbp)
cmpl $0x40, -0x18(%rbp)
jge 0x18e0
movq -0x30(%rbp), %rdi
callq 0xdf00
movq %rax, %rcx
movslq -0x18(%rbp), %rax
movq %rcx, -0xa30(%rbp,%rax,8)
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x18ab
movl -0x20(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
leaq -0xc30(%rbp), %rdi
leaq -0xa30(%rbp), %rsi
callq 0xdbf0
leaq -0x830(%rbp), %rdi
leaq -0xc30(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x19d0
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x189a
leaq -0x430(%rbp), %rdi
leaq -0x830(%rbp), %rsi
callq 0xdbf0
leaq -0x430(%rbp), %rdi
addq $0x200, %rdi            # imm = 0x200
leaq -0x830(%rbp), %rsi
addq $0x200, %rsi            # imm = 0x200
callq 0xdbf0
movl $0x0, -0x18(%rbp)
cmpl $0x40, -0x18(%rbp)
jge 0x19b8
movq -0x28(%rbp), %rdi
movl -0x18(%rbp), %eax
shll $0x4, %eax
cltq
addq %rax, %rdi
movslq -0x18(%rbp), %rax
movq -0x430(%rbp,%rax,8), %rsi
callq 0xde30
movq -0x28(%rbp), %rdi
movl -0x18(%rbp), %eax
shll $0x4, %eax
cltq
addq %rax, %rdi
addq $0x8, %rdi
movslq -0x18(%rbp), %rax
movq -0x230(%rbp,%rax,8), %rsi
callq 0xde30
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1963
addq $0xc30, %rsp            # imm = 0xC30
popq %rbp
retq
nopw %cs:(%rax,%rax)