// File: /workspace/github_c_makefile_star2_O2/ajpaulson[P]srogue11/xcrypt.c
// Function: des_init
static void des_init()
{
	int	i, j, b, k, inbit, obit;
	unsigned int	*p, *il, *ir, *fl, *fr;

	old_rawkey0 = old_rawkey1 = 0;
	saltbits = 0;
	old_salt = 0;
	bits24 = (bits28 = bits32 + 4) + 4;

	/*
	 * Invert the S-boxes, reordering the input bits.
	 */
	for (i = 0; i < 8; i++)
		for (j = 0; j < 64; j++) {
			b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf);
			u_sbox[i][j] = sbox[i][b];
		}

	/*
	 * Convert the inverted S-boxes into 4 arrays of 8 bits.
	 * Each will handle 12 bits of the S-box input.
	 */
	for (b = 0; b < 4; b++)
		for (i = 0; i < 64; i++)
			for (j = 0; j < 64; j++)
				m_sbox[b][(i << 6) | j] =
					(u_sbox[(b << 1)][i] << 4) |
					u_sbox[(b << 1) + 1][j];

	/*
	 * Set up the initial & final permutations into a useful form, and
	 * initialise the inverted key permutation.
	 */
	for (i = 0; i < 64; i++) {
		init_perm[final_perm[i] = IP[i] - 1] = i;
		inv_key_perm[i] = 255;
	}

	/*
	 * Invert the key permutation and initialise the inverted key
	 * compression permutation.
	 */
	for (i = 0; i < 56; i++) {
		inv_key_perm[key_perm[i] - 1] = i;
		inv_comp_perm[i] = 255;
	}

	/*
	 * Invert the key compression permutation.
	 */
	for (i = 0; i < 48; i++) {
		inv_comp_perm[comp_perm[i] - 1] = i;
	}

	/*
	 * Set up the OR-mask arrays for the initial and final permutations,
	 * and for the key initial and compression permutations.
	 */
	for (k = 0; k < 8; k++) {
		for (i = 0; i < 256; i++) {
			*(il = &ip_maskl[k][i]) = 0;
			*(ir = &ip_maskr[k][i]) = 0;
			*(fl = &fp_maskl[k][i]) = 0;
			*(fr = &fp_maskr[k][i]) = 0;
			for (j = 0; j < 8; j++) {
				inbit = 8 * k + j;
				if (i & bits8[j]) {
					if ((obit = init_perm[inbit]) < 32)
						*il |= bits32[obit];
					else
						*ir |= bits32[obit-32];
					if ((obit = final_perm[inbit]) < 32)
						*fl |= bits32[obit];
					else
						*fr |= bits32[obit - 32];
				}
			}
		}
		for (i = 0; i < 128; i++) {
			*(il = &key_perm_maskl[k][i]) = 0;
			*(ir = &key_perm_maskr[k][i]) = 0;
			for (j = 0; j < 7; j++) {
				inbit = 8 * k + j;
				if (i & bits8[j + 1]) {
					if ((obit = inv_key_perm[inbit]) == 255)
						continue;
					if (obit < 28)
						*il |= bits28[obit];
					else
						*ir |= bits28[obit - 28];
				}
			}
			*(il = &comp_maskl[k][i]) = 0;
			*(ir = &comp_maskr[k][i]) = 0;
			for (j = 0; j < 7; j++) {
				inbit = 7 * k + j;
				if (i & bits8[j + 1]) {
					if ((obit=inv_comp_perm[inbit]) == 255)
						continue;
					if (obit < 24)
						*il |= bits24[obit];
					else
						*ir |= bits24[obit - 24];
				}
			}
		}
	}

	/*
	 * Invert the P-box permutation, and convert into OR-masks for
	 * handling the output of the S-box arrays setup above.
	 */
	for (i = 0; i < 32; i++)
		un_pbox[pbox[i] - 1] = i;

	for (b = 0; b < 4; b++)
		for (i = 0; i < 256; i++) {
			*(p = &psbox[b][i]) = 0;
			for (j = 0; j < 8; j++) {
				if (i & bits8[j])
					*p |= bits32[un_pbox[8 * b + j]];
			}
		}

	des_initialised = 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
andl $0x0, 0x170f9(%rip)     # 0x3354c
andl $0x0, 0x170f6(%rip)     # 0x33550
andl $0x0, 0x170f3(%rip)     # 0x33554
andl $0x0, 0x170f0(%rip)     # 0x33558
leaq 0x170f1(%rip), %rax     # 0x33560
xorl %ecx, %ecx
leaq 0x5678(%rip), %rdx      # 0x21af0
cmpq $0x8, %rcx
je 0x1c4cb
movq %rcx, %rsi
shlq $0x6, %rsi
addq %rdx, %rsi
xorl %edi, %edi
xorl %r8d, %r8d
cmpq $0x40, %r8
je 0x1c4c2
movl %r8d, %r9d
andl $0x20, %r9d
movl %edi, %r10d
andl $0x10, %r10d
orq %r9, %r10
movl %r8d, %r9d
shrl %r9d
andl $0xf, %r9d
orq %r10, %r9
movb (%rsi,%r9), %r9b
movb %r9b, (%rax,%r8)
incq %r8
addq $0x10, %rdi
jmp 0x1c48d
incq %rcx
addq $0x40, %rax
jmp 0x1c478
leaq 0x1728e(%rip), %rax     # 0x33760
leaq 0x170c7(%rip), %rcx     # 0x335a0
xorl %edx, %edx
leaq 0x1707e(%rip), %rsi     # 0x33560
cmpq $0x4, %rdx
je 0x1c538
leaq (%rdx,%rdx), %rdi
shlq $0x6, %rdi
addq %rsi, %rdi
movq %rax, %r8
xorl %r9d, %r9d
cmpq $0x40, %r9
je 0x1c529
movb (%r9,%rdi), %r10b
shlb $0x4, %r10b
xorl %r11d, %r11d
cmpq $0x40, %r11
je 0x1c520
movb (%rcx,%r11), %bl
orb %r10b, %bl
movb %bl, (%r8,%r11)
incq %r11
jmp 0x1c50a
incq %r9
addq $0x40, %r8
jmp 0x1c4f9
incq %rdx
addq $0x1000, %rax           # imm = 0x1000
subq $-0x80, %rcx
jmp 0x1c4e2
xorl %eax, %eax
leaq 0x57af(%rip), %rcx      # 0x21cf0
leaq 0x1b298(%rip), %r10     # 0x377e0
cmpq $0x40, %rax
je 0x1c574
movb (%rax,%rcx), %dl
decb %dl
leaq 0x1b246(%rip), %rsi     # 0x377a0
movb %dl, (%rax,%rsi)
movzbl %dl, %edx
leaq 0x1b1f9(%rip), %rsi     # 0x37760
movb %al, (%rdx,%rsi)
movb $-0x1, (%rax,%r10)
incq %rax
jmp 0x1c548
xorl %eax, %eax
leaq 0x57b3(%rip), %rcx      # 0x21d30
leaq 0x1b29c(%rip), %r15     # 0x37820
cmpq $0x38, %rax
je 0x1c59d
movzbl (%rax,%rcx), %edx
movb %al, -0x1(%rdx,%r10)
movb $-0x1, (%rax,%r15)
incq %rax
jmp 0x1c584
xorl %eax, %eax
leaq 0x57ca(%rip), %rcx      # 0x21d70
cmpq $0x30, %rax
je 0x1c5ba
movzbl (%rax,%rcx), %edx
movb %al, -0x1(%rdx,%r15)
incq %rax
jmp 0x1c5a6
movq $0x0, -0x8(%rsp)
leaq 0x57d6(%rip), %rax      # 0x21da0
leaq 0x549f(%rip), %rcx      # 0x21a70
xorl %ebx, %ebx
xorl %edx, %edx
cmpq $0x8, %rdx
je 0x1c7fb
xorl %r14d, %r14d
movq %rdx, -0x10(%rsp)
cmpq $0x100, %r14            # imm = 0x100
je 0x1c6e7
shlq $0xa, %rdx
leaq 0x1b261(%rip), %rsi     # 0x37860
addq %rdx, %rsi
leaq (%rsi,%r14,4), %r12
andl $0x0, (%r12)
leaq 0x1d24e(%rip), %rsi     # 0x39860
addq %rdx, %rsi
leaq (%rsi,%r14,4), %r13
andl $0x0, (%r13)
leaq 0x1f23b(%rip), %rsi     # 0x3b860
addq %rdx, %rsi
leaq (%rsi,%r14,4), %rbp
andl $0x0, (%rbp)
leaq 0x21229(%rip), %rsi     # 0x3d860
addq %rsi, %rdx
leaq (%rdx,%r14,4), %r11
andl $0x0, (%r11)
xorl %r15d, %r15d
xorl %edx, %edx
xorl %esi, %esi
xorl %edi, %edi
xorl %r8d, %r8d
cmpq $0x8, %r8
je 0x1c6cc
movzbl (%r8,%rax), %r9d
testl %r9d, %r14d
je 0x1c6c7
leaq (%rbx,%r8), %r9
leaq 0x1b0f7(%rip), %r10     # 0x37760
movzbl (%r10,%r9), %r10d
cmpq $0x1f, %r10
ja 0x1c67e
orl (%rcx,%r10,4), %esi
movl %esi, (%r12)
jmp 0x1c695
movl $0xffffffe0, %ecx       # imm = 0xFFFFFFE0
addl %ecx, %r10d
leaq 0x53e3(%rip), %rcx      # 0x21a70
orl (%rcx,%r10,4), %edi
movl %edi, (%r13)
leaq 0x1b104(%rip), %r10     # 0x377a0
movzbl (%r10,%r9), %r9d
cmpq $0x1f, %r9
ja 0x1c6b1
orl (%rcx,%r9,4), %r15d
movl %r15d, (%rbp)
jmp 0x1c6c7
movl $0xffffffe0, %ecx       # imm = 0xFFFFFFE0
addl %ecx, %r9d
leaq 0x53b0(%rip), %rcx      # 0x21a70
orl (%rcx,%r9,4), %edx
movl %edx, (%r11)
incq %r8
jmp 0x1c64e
incq %r14
leaq 0x1b10a(%rip), %r10     # 0x377e0
leaq 0x1b143(%rip), %r15     # 0x37820
movq -0x10(%rsp), %rdx
jmp 0x1c5e7
movq %rdx, %r14
shlq $0x9, %r14
leaq 0x2316b(%rip), %rdx     # 0x3f860
leaq (%rdx,%r14), %r12
leaq 0x24160(%rip), %rdx     # 0x40860
leaq (%rdx,%r14), %r13
xorl %ebp, %ebp
cmpq $0x80, %rbp
je 0x1c7e4
leaq (%r12,%rbp,4), %rdx
andl $0x0, (%rdx)
leaq (,%rbp,4), %rsi
addq %r13, %rsi
andl $0x0, (%rsi)
xorl %edi, %edi
xorl %r8d, %r8d
xorl %r11d, %r11d
incq %r11
cmpq $0x8, %r11
je 0x1c76f
movzbl (%r11,%rax), %r9d
testl %r9d, %ebp
je 0x1c730
leaq (%rbx,%r11), %r9
movzbl -0x1(%r10,%r9), %r9d
cmpq $0xff, %r9
je 0x1c730
cmpb $0x1b, %r9b
jbe 0x1c766
orl -0x60(%rcx,%r9,4), %r8d
movl %r8d, (%rsi)
jmp 0x1c730
orl 0x10(%rcx,%r9,4), %edi
movl %edi, (%rdx)
jmp 0x1c730
leaq 0x250ea(%rip), %rdx     # 0x41860
addq %r14, %rdx
leaq (%rdx,%rbp,4), %rdx
andl $0x0, (%rdx)
leaq 0x260d9(%rip), %rsi     # 0x42860
addq %r14, %rsi
leaq (%rsi,%rbp,4), %rsi
andl $0x0, (%rsi)
xorl %edi, %edi
xorl %r8d, %r8d
xorl %r11d, %r11d
incq %r11
cmpq $0x8, %r11
je 0x1c7dc
movzbl (%r11,%rax), %r9d
testl %r9d, %ebp
je 0x1c799
movq -0x8(%rsp), %r9
addq %r11, %r9
movzbl -0x1(%r15,%r9), %r9d
cmpq $0xff, %r9
je 0x1c799
cmpb $0x17, %r9b
jbe 0x1c7d3
orl -0x40(%rcx,%r9,4), %r8d
movl %r8d, (%rsi)
jmp 0x1c799
orl 0x20(%rcx,%r9,4), %edi
movl %edi, (%rdx)
jmp 0x1c799
incq %rbp
jmp 0x1c706
movq -0x10(%rsp), %rdx
incq %rdx
addq $0x8, %rbx
addq $0x7, -0x8(%rsp)
jmp 0x1c5d5
xorl %esi, %esi
leaq 0x55ac(%rip), %rdi      # 0x21db0
leaq 0x27055(%rip), %rdx     # 0x43860
cmpq $0x20, %rsi
je 0x1c820
movzbl (%rsi,%rdi), %r8d
movb %sil, -0x1(%r8,%rdx)
incq %rsi
jmp 0x1c80b
xorl %esi, %esi
leaq 0x27057(%rip), %rdi     # 0x43880
cmpq $0x4, %rsi
je 0x1c880
movq %rsi, %r8
shlq $0xa, %r8
addq %rdi, %r8
xorl %r9d, %r9d
cmpq $0x100, %r9             # imm = 0x100
je 0x1c877
leaq (%r8,%r9,4), %r10
andl $0x0, (%r10)
xorl %r11d, %r11d
xorl %ebx, %ebx
cmpq $0x8, %rbx
je 0x1c872
movzbl (%rbx,%rax), %ebp
testl %ebp, %r9d
je 0x1c86d
movzbl (%rdx,%rbx), %r14d
orl (%rcx,%r14,4), %r11d
movl %r11d, (%r10)
incq %rbx
jmp 0x1c852
incq %r9
jmp 0x1c83c
incq %rsi
addq $0x8, %rdx
jmp 0x1c829
movb $0x1, 0x16cc1(%rip)     # 0x33548
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq