// File: /workspace/github_c_makefile_star2_O1/ajpaulson[P]srogue11/xcrypt.c
// Function: do_des
static int do_des(unsigned int l_in,unsigned int r_in,unsigned int *l_out,unsigned int *r_out,int count)
{
	/*
	 *	l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
	 */
	unsigned int	l, r, *kl, *kr, *kl1, *kr1;
	unsigned int	f, r48l, r48r;
	int		round;

	if (count == 0) {
		return(1);
	} else if (count > 0) {
		/*
		 * Encrypting
		 */
		kl1 = en_keysl;
		kr1 = en_keysr;
	} else {
		/*
		 * Decrypting
		 */
		count = -count;
		kl1 = de_keysl;
		kr1 = de_keysr;
	}

	/*
	 *	Do initial permutation (IP).
	 */
	l = ip_maskl[0][l_in >> 24]
	  | ip_maskl[1][(l_in >> 16) & 0xff]
	  | ip_maskl[2][(l_in >> 8) & 0xff]
	  | ip_maskl[3][l_in & 0xff]
	  | ip_maskl[4][r_in >> 24]
	  | ip_maskl[5][(r_in >> 16) & 0xff]
	  | ip_maskl[6][(r_in >> 8) & 0xff]
	  | ip_maskl[7][r_in & 0xff];
	r = ip_maskr[0][l_in >> 24]
	  | ip_maskr[1][(l_in >> 16) & 0xff]
	  | ip_maskr[2][(l_in >> 8) & 0xff]
	  | ip_maskr[3][l_in & 0xff]
	  | ip_maskr[4][r_in >> 24]
	  | ip_maskr[5][(r_in >> 16) & 0xff]
	  | ip_maskr[6][(r_in >> 8) & 0xff]
	  | ip_maskr[7][r_in & 0xff];

	while (count--) {
		/*
		 * Do each round.
		 */
		kl = kl1;
		kr = kr1;
		round = 16;
		while (round--) {
			/*
			 * Expand R to 48 bits (simulate the E-box).
			 */
			r48l	= ((r & 0x00000001) << 23)
				| ((r & 0xf8000000) >> 9)
				| ((r & 0x1f800000) >> 11)
				| ((r & 0x01f80000) >> 13)
				| ((r & 0x001f8000) >> 15);

			r48r	= ((r & 0x0001f800) << 7)
				| ((r & 0x00001f80) << 5)
				| ((r & 0x000001f8) << 3)
				| ((r & 0x0000001f) << 1)
				| ((r & 0x80000000) >> 31);
			/*
			 * Do salting for crypt() and friends, and
			 * XOR with the permuted key.
			 */
			f = (r48l ^ r48r) & saltbits;
			r48l ^= f ^ *kl++;
			r48r ^= f ^ *kr++;
			/*
			 * Do sbox lookups (which shrink it back to 32 bits)
			 * and do the pbox permutation at the same time.
			 */
			f = psbox[0][m_sbox[0][r48l >> 12]]
			  | psbox[1][m_sbox[1][r48l & 0xfff]]
			  | psbox[2][m_sbox[2][r48r >> 12]]
			  | psbox[3][m_sbox[3][r48r & 0xfff]];
			/*
			 * Now that we've permuted things, complete f().
			 */
			f ^= l;
			l = r;
			r = f;
		}
		r = l;
		l = f;
	}
	/*
	 * Do final permutation (inverse of IP).
	 */
	*l_out	= fp_maskl[0][l >> 24]
		| fp_maskl[1][(l >> 16) & 0xff]
		| fp_maskl[2][(l >> 8) & 0xff]
		| fp_maskl[3][l & 0xff]
		| fp_maskl[4][r >> 24]
		| fp_maskl[5][(r >> 16) & 0xff]
		| fp_maskl[6][(r >> 8) & 0xff]
		| fp_maskl[7][r & 0xff];
	*r_out	= fp_maskr[0][l >> 24]
		| fp_maskr[1][(l >> 16) & 0xff]
		| fp_maskr[2][(l >> 8) & 0xff]
		| fp_maskr[3][l & 0xff]
		| fp_maskr[4][r >> 24]
		| fp_maskr[5][(r >> 16) & 0xff]
		| fp_maskr[6][(r >> 8) & 0xff]
		| fp_maskr[7][r & 0xff];
	return(0);
}

// Assembly:
testl %r8d, %r8d
je 0x1e1ab
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, -0x10(%rsp)
movq %rcx, -0x8(%rsp)
leaq 0x269d1(%rip), %rax     # 0x44890
leaq 0x26a0a(%rip), %r9      # 0x448d0
cmovgq %rax, %r9
leaq 0x26a3f(%rip), %rax     # 0x44910
leaq 0x26a78(%rip), %r10     # 0x44950
cmovgq %rax, %r10
movl %r8d, %edx
negl %edx
cmovsl %r8d, %edx
movl %edi, %ebx
shrl $0x18, %ebx
leaq 0x1997f(%rip), %r14     # 0x37870
movl %edi, %eax
shrl $0xe, %eax
movl $0x3fc, %r13d           # imm = 0x3FC
andl %r13d, %eax
movl 0x400(%rax,%r14), %r8d
orl (%r14,%rbx,4), %r8d
movl %edi, %r15d
shrl $0x8, %r15d
movl $0xff, %ebp
andl %ebp, %r15d
orl 0x800(%r14,%r15,4), %r8d
andl %ebp, %edi
shll $0x2, %edi
orl 0xc00(%rdi,%r14), %r8d
movl %esi, %r11d
shrl $0x18, %r11d
orl 0x1000(%r14,%r11,4), %r8d
movl %esi, %r12d
shrl $0xe, %r12d
andl %r13d, %r12d
orl 0x1400(%r12,%r14), %r8d
movl %esi, %r13d
shrl $0x8, %r13d
andl %ebp, %r13d
orl 0x1800(%r14,%r13,4), %r8d
andl %ebp, %esi
shll $0x2, %esi
orl 0x1c00(%rsi,%r14), %r8d
leaq 0x1b8fa(%rip), %r14     # 0x39870
movl 0x400(%rax,%r14), %eax
orl (%r14,%rbx,4), %eax
orl 0x800(%r14,%r15,4), %eax
orl 0xc00(%rdi,%r14), %eax
orl 0x1000(%r14,%r11,4), %eax
orl 0x1400(%r12,%r14), %eax
orl 0x1800(%r14,%r13,4), %eax
orl 0x1c00(%rsi,%r14), %eax
movl 0x155ac(%rip), %esi     # 0x33564
movl $0xfc0000, %edi         # imm = 0xFC0000
movl $0x3f000, %ebx          # imm = 0x3F000
leaq 0x157a7(%rip), %r14     # 0x33770
leaq 0x258c0(%rip), %r15     # 0x43890
movl $0xfff, %ebp            # imm = 0xFFF
movl %r8d, %r11d
xorl %r12d, %r12d
movl %eax, %r8d
movl %r11d, %eax
movl %eax, %r13d
movl %r8d, %eax
roll $0x17, %r8d
andl %edi, %r8d
movl %eax, %r11d
shrl $0xb, %r11d
andl %ebx, %r11d
orl %r8d, %r11d
movl %eax, %ecx
shrl $0xd, %ecx
andl $0xfc0, %ecx            # imm = 0xFC0
orl %r11d, %ecx
movl %eax, %r8d
shrl $0xf, %r8d
andl $0x3f, %r8d
orl %ecx, %r8d
movl %eax, %ecx
shll $0x5, %ecx
andl %ebx, %ecx
movl %eax, %r11d
shrl $0x1f, %r11d
orl %ecx, %r11d
movl %eax, %ecx
shll $0x7, %ecx
andl %edi, %ecx
orl %ecx, %r11d
movl %eax, %ecx
andl $0x1f8, %ecx            # imm = 0x1F8
leal (%r11,%rcx,8), %ecx
movl %eax, %r11d
andl $0x1f, %r11d
leal (%rcx,%r11,2), %r11d
movl %r8d, %ecx
xorl %r11d, %ecx
andl %esi, %ecx
xorl (%r9,%r12,4), %r8d
xorl %ecx, %r8d
xorl (%r10,%r12,4), %r11d
xorl %ecx, %r11d
movl %r8d, %ecx
shrl $0xc, %ecx
movzbl (%rcx,%r14), %ecx
andl %ebp, %r8d
movzbl 0x1000(%r8,%r14), %r8d
movl 0x400(%r15,%r8,4), %r8d
orl (%r15,%rcx,4), %r8d
movl %r11d, %ecx
shrl $0xc, %ecx
movzbl 0x2000(%rcx,%r14), %ecx
orl 0x800(%r15,%rcx,4), %r8d
andl %ebp, %r11d
movzbl 0x3000(%r11,%r14), %ecx
orl 0xc00(%r15,%rcx,4), %r8d
xorl %r13d, %r8d
incq %r12
cmpl $0x10, %r12d
jne 0x1dfe1
decl %edx
jne 0x1dfd5
movl %r8d, %esi
shrl $0x18, %esi
leaq 0x1d79e(%rip), %r9      # 0x3b870
movl %r8d, %edi
shrl $0xe, %edi
movl $0x3fc, %edx            # imm = 0x3FC
andl %edx, %edi
movl 0x400(%rdi,%r9), %r11d
orl (%r9,%rsi,4), %r11d
movl %r8d, %r10d
shrl $0x8, %r10d
movl $0xff, %ebx
andl %ebx, %r10d
orl 0x800(%r9,%r10,4), %r11d
andl %ebx, %r8d
shll $0x2, %r8d
orl 0xc00(%r8,%r9), %r11d
movl %eax, %ecx
shrl $0x18, %ecx
orl 0x1000(%r9,%rcx,4), %r11d
movl %eax, %r14d
shrl $0xe, %r14d
andl %edx, %r14d
orl 0x1400(%r14,%r9), %r11d
movl %eax, %edx
shrl $0x8, %edx
andl %ebx, %edx
orl 0x1800(%r9,%rdx,4), %r11d
andl %ebx, %eax
shll $0x2, %eax
orl 0x1c00(%rax,%r9), %r11d
movq -0x10(%rsp), %r9
movl %r11d, (%r9)
leaq 0x1f715(%rip), %r9      # 0x3d870
movl 0x400(%rdi,%r9), %edi
orl (%r9,%rsi,4), %edi
orl 0x800(%r9,%r10,4), %edi
orl 0xc00(%r8,%r9), %edi
orl 0x1000(%r9,%rcx,4), %edi
orl 0x1400(%r14,%r9), %edi
orl 0x1800(%r9,%rdx,4), %edi
orl 0x1c00(%rax,%r9), %edi
movq -0x8(%rsp), %rax
movl %edi, (%rax)
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %eax
retq