// File: /workspace/github_c_makefile_star2_O2/ajpaulson[P]srogue11/xcrypt.c
// Function: des_setkey
static int des_setkey(const char *key)
{
	unsigned int k0, k1, rawkey0, rawkey1;
	int	shifts, round;

	if (!des_initialised)
		des_init();

	rawkey0 = ntohl(*(unsigned int *) key);
	rawkey1 = ntohl(*(unsigned int *) (key + 4));

	if ((rawkey0 | rawkey1)
	    && rawkey0 == old_rawkey0
	    && rawkey1 == old_rawkey1) {
		/*
		 * Already setup for this key.
		 * This optimisation fails on a zero key (which is weak and
		 * has bad parity anyway) in order to simplify the starting
		 * conditions.
		 */
		return(0);
	}
	old_rawkey0 = rawkey0;
	old_rawkey1 = rawkey1;

	/*
	 *	Do key permutation and split into two 28-bit subkeys.
	 */
	k0 = key_perm_maskl[0][rawkey0 >> 25]
	   | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f]
	   | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f]
	   | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f]
	   | key_perm_maskl[4][rawkey1 >> 25]
	   | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f]
	   | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f]
	   | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f];
	k1 = key_perm_maskr[0][rawkey0 >> 25]
	   | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f]
	   | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f]
	   | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f]
	   | key_perm_maskr[4][rawkey1 >> 25]
	   | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f]
	   | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f]
	   | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f];
	/*
	 *	Rotate subkeys and do compression permutation.
	 */
	shifts = 0;
	for (round = 0; round < 16; round++) {
		unsigned int	t0, t1;

		shifts += key_shifts[round];

		t0 = (k0 << shifts) | (k0 >> (28 - shifts));
		t1 = (k1 << shifts) | (k1 >> (28 - shifts));

		de_keysl[15 - round] =
		en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f]
				| comp_maskl[1][(t0 >> 14) & 0x7f]
				| comp_maskl[2][(t0 >> 7) & 0x7f]
				| comp_maskl[3][t0 & 0x7f]
				| comp_maskl[4][(t1 >> 21) & 0x7f]
				| comp_maskl[5][(t1 >> 14) & 0x7f]
				| comp_maskl[6][(t1 >> 7) & 0x7f]
				| comp_maskl[7][t1 & 0x7f];

		de_keysr[15 - round] =
		en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f]
				| comp_maskr[1][(t0 >> 14) & 0x7f]
				| comp_maskr[2][(t0 >> 7) & 0x7f]
				| comp_maskr[3][t0 & 0x7f]
				| comp_maskr[4][(t1 >> 21) & 0x7f]
				| comp_maskr[5][(t1 >> 14) & 0x7f]
				| comp_maskr[6][(t1 >> 7) & 0x7f]
				| comp_maskr[7][t1 & 0x7f];
	}
	return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpb $0x0, 0x176ee(%rip)     # 0x33548
jne 0x1be61
callq 0x1c442
movl (%rbx), %ecx
movl 0x4(%rbx), %eax
bswapl %ecx
bswapl %eax
movl %eax, %edx
orl %ecx, %edx
je 0x1be8f
cmpl 0x176da(%rip), %ecx     # 0x33550
jne 0x1be8f
cmpl 0x176ce(%rip), %eax     # 0x3354c
jne 0x1be8f
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, 0x176bb(%rip)     # 0x33550
movl %ecx, %edx
shrl $0x19, %edx
leaq 0x239bf(%rip), %r9      # 0x3f860
movl %ecx, %r8d
shrl $0xf, %r8d
movl $0x1fc, %ebx            # imm = 0x1FC
andl %ebx, %r8d
movl 0x200(%r8,%r9), %ebp
orl (%r9,%rdx,4), %ebp
movl %ecx, %r10d
shrl $0x7, %r10d
andl %ebx, %r10d
orl 0x400(%r10,%r9), %ebp
addl %ecx, %ecx
andl %ebx, %ecx
orl 0x600(%rcx,%r9), %ebp
movl %eax, %edi
shrl $0x19, %edi
orl 0x800(%r9,%rdi,4), %ebp
movl %eax, %r11d
shrl $0xf, %r11d
andl %ebx, %r11d
orl 0xa00(%r11,%r9), %ebp
movl %eax, 0x1764d(%rip)     # 0x3354c
movl %eax, %esi
shrl $0x7, %esi
andl %ebx, %esi
orl 0xc00(%rsi,%r9), %ebp
addl %eax, %eax
andl %ebx, %eax
orl 0xe00(%rax,%r9), %ebp
movl %ebp, 0x4(%rsp)
leaq 0x2493b(%rip), %r9      # 0x40860
movl 0x200(%r8,%r9), %r8d
orl (%r9,%rdx,4), %r8d
orl 0x400(%r10,%r9), %r8d
orl 0x600(%rcx,%r9), %r8d
orl 0x800(%r9,%rdi,4), %r8d
orl 0xa00(%r11,%r9), %r8d
orl 0xc00(%rsi,%r9), %r8d
orl 0xe00(%rax,%r9), %r8d
movl %r8d, (%rsp)
xorl %r11d, %r11d
pushq $0x10
popq %r10
leaq 0x5e5d(%rip), %r9       # 0x21dd0
xorl %eax, %eax
leaq 0x258e4(%rip), %r12     # 0x41860
subq $0x1, %r10
jb 0x1be80
movzbl (%r9), %ecx
addl %ecx, %eax
movl 0x4(%rsp), %edi
movl %edi, %esi
movl %eax, %ecx
shll %cl, %esi
movb $0x1c, %dl
subb %al, %dl
movl %edi, %r14d
movl %edx, %ecx
shrl %cl, %r14d
orl %esi, %r14d
movl (%rsp), %edi
movl %edi, %esi
movl %eax, %ecx
shll %cl, %esi
movl %edi, %r15d
movl %edx, %ecx
shrl %cl, %r15d
orl %esi, %r15d
movl %r14d, %ecx
shrl $0x13, %ecx
movq %r11, %rbx
movl $0x1fc, %r11d           # imm = 0x1FC
andl %r11d, %ecx
movl %r14d, %edx
shrl $0xc, %edx
andl %r11d, %edx
movl 0x200(%rdx,%r12), %ebp
orl (%rcx,%r12), %ebp
movl %r14d, %r13d
shrl $0x5, %r13d
andl %r11d, %r13d
orl 0x400(%r13,%r12), %ebp
andl $0x7f, %r14d
shll $0x2, %r14d
orl 0x600(%r14,%r12), %ebp
movl %r15d, %edi
shrl $0x13, %edi
andl %r11d, %edi
orl 0x800(%rdi,%r12), %ebp
movl %r15d, %esi
shrl $0xc, %esi
andl %r11d, %esi
orl 0xa00(%rsi,%r12), %ebp
movl %r15d, %r8d
shrl $0x5, %r8d
andl %r11d, %r8d
movq %rbx, %r11
orl 0xc00(%r8,%r12), %ebp
andl $0x7f, %r15d
shll $0x2, %r15d
orl 0xe00(%r15,%r12), %ebp
leaq 0x28830(%rip), %rbx     # 0x44880
movl %ebp, (%r11,%rbx)
leaq 0x28865(%rip), %rbx     # 0x448c0
movl %ebp, (%rbx,%r10,4)
leaq 0x267fa(%rip), %rbx     # 0x42860
movl 0x200(%rdx,%rbx), %edx
orl (%rcx,%rbx), %edx
orl 0x400(%r13,%rbx), %edx
orl 0x600(%r14,%rbx), %edx
orl 0x800(%rdi,%rbx), %edx
orl 0xa00(%rsi,%rbx), %edx
orl 0xc00(%r8,%rbx), %edx
orl 0xe00(%r15,%rbx), %edx
leaq 0x2885b(%rip), %rcx     # 0x44900
movl %edx, (%r11,%rcx)
leaq 0x28890(%rip), %rcx     # 0x44940
movl %edx, (%rcx,%r10,4)
addq $0x4, %r11
incq %r9
jmp 0x1bf7c