// File: /workspace/github_c_makefile_star2_O3/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, 0x159f6(%rip)     # 0x33558
jne 0x1db69
callq 0x1e0b7
movl (%rbx), %ecx
movl 0x4(%rbx), %eax
bswapl %ecx
bswapl %eax
movl %eax, %edx
orl %ecx, %edx
je 0x1db8c
cmpl 0x159e2(%rip), %ecx     # 0x33560
jne 0x1db8c
cmpl 0x159d6(%rip), %eax     # 0x3355c
je 0x1dda0
movl %ecx, 0x159ce(%rip)     # 0x33560
movl %ecx, %edx
shrl $0x19, %edx
leaq 0x21cd2(%rip), %r9      # 0x3f870
movl %ecx, %r8d
shrl $0xf, %r8d
movl $0x1fc, %esi            # imm = 0x1FC
andl %esi, %r8d
movl 0x200(%r8,%r9), %ebp
orl (%r9,%rdx,4), %ebp
movl %ecx, %r10d
shrl $0x7, %r10d
andl %esi, %r10d
orl 0x400(%r10,%r9), %ebp
addl %ecx, %ecx
andl %esi, %ecx
orl 0x600(%rcx,%r9), %ebp
movl %eax, %r11d
shrl $0x19, %r11d
orl 0x800(%r9,%r11,4), %ebp
movl %eax, %ebx
shrl $0xf, %ebx
andl %esi, %ebx
orl 0xa00(%rbx,%r9), %ebp
movl %eax, 0x15961(%rip)     # 0x3355c
movl %eax, %edi
shrl $0x7, %edi
andl %esi, %edi
orl 0xc00(%rdi,%r9), %ebp
addl %eax, %eax
andl %esi, %eax
orl 0xe00(%rax,%r9), %ebp
movl %ebp, 0x4(%rsp)
leaq 0x22c4f(%rip), %r9      # 0x40870
movl 0x200(%r8,%r9), %r13d
orl (%r9,%rdx,4), %r13d
orl 0x400(%r10,%r9), %r13d
orl 0x600(%rcx,%r9), %r13d
orl 0x800(%r9,%r11,4), %r13d
orl 0xa00(%rbx,%r9), %r13d
orl 0xc00(%rdi,%r9), %r13d
orl 0xe00(%rax,%r9), %r13d
xorl %r9d, %r9d
movl $0xf, %r10d
leaq 0x5dc3(%rip), %r11      # 0x23a30
leaq 0x23bfc(%rip), %rbx     # 0x41870
leaq 0x24bf5(%rip), %r12     # 0x42870
xorl %eax, %eax
movzbl (%r11), %ecx
addl %ecx, %eax
movl 0x4(%rsp), %r8d
movl %r8d, %edi
movl %eax, %ecx
shll %cl, %edi
movb $0x1c, %dl
subb %al, %dl
movl %r8d, %r14d
movl %edx, %ecx
shrl %cl, %r14d
orl %edi, %r14d
movl %r13d, %r8d
movl %eax, %ecx
shll %cl, %r8d
movl %r14d, %ecx
shrl $0x13, %ecx
andl %esi, %ecx
movl %r14d, %ebp
shrl $0xc, %ebp
andl %esi, %ebp
movl 0x200(%rbp,%rbx), %r15d
orl (%rcx,%rbx), %r15d
movl 0x200(%rbp,%r12), %ebp
orl (%rcx,%r12), %ebp
movl %r14d, %ecx
shrl $0x5, %ecx
andl %esi, %ecx
orl 0x400(%rcx,%rbx), %r15d
orl 0x400(%rcx,%r12), %ebp
movl %r13d, %edi
movl %edx, %ecx
shrl %cl, %edi
andl $0x7f, %r14d
shll $0x2, %r14d
orl 0x600(%r14,%rbx), %r15d
orl %r8d, %edi
orl 0x600(%r14,%r12), %ebp
movl %edi, %ecx
shrl $0x13, %ecx
andl %esi, %ecx
orl 0x800(%rcx,%rbx), %r15d
orl 0x800(%rcx,%r12), %ebp
movl %edi, %ecx
shrl $0xc, %ecx
andl %esi, %ecx
orl 0xa00(%rcx,%rbx), %r15d
orl 0xa00(%rcx,%r12), %ebp
movl %edi, %ecx
shrl $0x5, %ecx
andl %esi, %ecx
orl 0xc00(%rcx,%rbx), %r15d
orl 0xc00(%rcx,%r12), %ebp
andl $0x7f, %edi
shll $0x2, %edi
orl 0xe00(%rdi,%rbx), %r15d
leaq 0x26b2e(%rip), %rcx     # 0x44890
movl %r15d, (%r9,%rcx)
leaq 0x26b63(%rip), %rcx     # 0x448d0
movl %r15d, (%rcx,%r10,4)
orl 0xe00(%rdi,%r12), %ebp
leaq 0x26b90(%rip), %rcx     # 0x44910
movl %ebp, (%r9,%rcx)
leaq 0x26bc5(%rip), %rcx     # 0x44950
movl %ebp, (%rcx,%r10,4)
addq $0x4, %r9
incq %r11
addq $-0x1, %r10
jb 0x1dc7d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq