// File: /workspace/github_c_makefile_star2_O2/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 0x1c43c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, -0x10(%rsp)
movq %rcx, -0x8(%rsp)
leaq 0x2872d(%rip), %rax     # 0x44880
leaq 0x28766(%rip), %r9      # 0x448c0
cmovgq %rax, %r9
leaq 0x2879b(%rip), %rax     # 0x44900
leaq 0x287d4(%rip), %r10     # 0x44940
cmovgq %rax, %r10
movl %edi, %ebx
shrl $0x18, %ebx
leaq 0x1b6e4(%rip), %r14     # 0x37860
movl %edi, %eax
shrl $0xe, %eax
movl $0x3fc, %r13d           # imm = 0x3FC
andl %r13d, %eax
movl 0x400(%rax,%r14), %r11d
orl (%r14,%rbx,4), %r11d
movl %edi, %r15d
shrl $0x8, %r15d
movl $0xff, %ebp
andl %ebp, %r15d
orl 0x800(%r14,%r15,4), %r11d
andl %ebp, %edi
shll $0x2, %edi
orl 0xc00(%rdi,%r14), %r11d
movl %esi, %edx
shrl $0x18, %edx
orl 0x1000(%r14,%rdx,4), %r11d
movl %esi, %r12d
shrl $0xe, %r12d
andl %r13d, %r12d
orl 0x1400(%r12,%r14), %r11d
movl %esi, %r13d
shrl $0x8, %r13d
andl %ebp, %r13d
orl 0x1800(%r14,%r13,4), %r11d
andl %ebp, %esi
shll $0x2, %esi
orl 0x1c00(%rsi,%r14), %r11d
leaq 0x1d661(%rip), %r14     # 0x39860
movl 0x400(%rax,%r14), %ecx
orl (%r14,%rbx,4), %ecx
orl 0x800(%r14,%r15,4), %ecx
orl 0xc00(%rdi,%r14), %ecx
orl 0x1000(%r14,%rdx,4), %ecx
orl 0x1400(%r12,%r14), %ecx
orl 0x1800(%r14,%r13,4), %ecx
orl 0x1c00(%rsi,%r14), %ecx
movl %r8d, %edx
negl %edx
cmovsl %r8d, %edx
movl 0x1730a(%rip), %edi     # 0x33554
movl $0xfc0000, %r8d         # imm = 0xFC0000
movl $0x3f000, %ebx          # imm = 0x3F000
leaq 0x17504(%rip), %r14     # 0x33760
leaq 0x2761d(%rip), %r15     # 0x43880
movl $0xfff, %ebp            # imm = 0xFFF
subl $0x1, %edx
jb 0x1c356
xorl %r12d, %r12d
movl %r11d, %r13d
cmpl $0x10, %r12d
je 0x1c34e
movl %ecx, %esi
roll $0x17, %esi
andl %r8d, %esi
movl %ecx, %r11d
shrl $0xb, %r11d
andl %ebx, %r11d
orl %esi, %r11d
movl %ecx, %esi
shrl $0xd, %esi
andl $0xfc0, %esi            # imm = 0xFC0
orl %r11d, %esi
movl %ecx, %r11d
shrl $0xf, %r11d
andl $0x3f, %r11d
orl %esi, %r11d
movl %ecx, %esi
shll $0x5, %esi
andl %ebx, %esi
movl %ecx, %eax
shrl $0x1f, %eax
orl %esi, %eax
movl %ecx, %esi
shll $0x7, %esi
andl %r8d, %esi
orl %esi, %eax
movl %ecx, %esi
andl $0x1f8, %esi            # imm = 0x1F8
leal (%rax,%rsi,8), %eax
movl %ecx, %esi
andl $0x1f, %esi
leal (%rax,%rsi,2), %esi
movl %r11d, %eax
xorl %esi, %eax
andl %edi, %eax
xorl (%r9,%r12,4), %r11d
xorl %eax, %r11d
xorl (%r10,%r12,4), %esi
xorl %eax, %esi
movl %r11d, %eax
shrl $0xc, %eax
movzbl (%rax,%r14), %eax
andl %ebp, %r11d
movzbl 0x1000(%r11,%r14), %r11d
movl 0x400(%r15,%r11,4), %r11d
orl (%r15,%rax,4), %r11d
movl %esi, %eax
shrl $0xc, %eax
movzbl 0x2000(%rax,%r14), %eax
orl 0x800(%r15,%rax,4), %r11d
andl %ebp, %esi
movzbl 0x3000(%rsi,%r14), %eax
orl 0xc00(%r15,%rax,4), %r11d
xorl %r13d, %r11d
incq %r12
movl %ecx, %r13d
movl %r11d, %ecx
jmp 0x1c277
movl %r13d, %ecx
jmp 0x1c268
movl %r11d, %esi
shrl $0x18, %esi
leaq 0x1f4fd(%rip), %r8      # 0x3b860
movl %r11d, %edi
shrl $0xe, %edi
movl $0x3fc, %edx            # imm = 0x3FC
andl %edx, %edi
movl 0x400(%rdi,%r8), %r10d
orl (%r8,%rsi,4), %r10d
movl %r11d, %r9d
shrl $0x8, %r9d
movl $0xff, %ebx
andl %ebx, %r9d
orl 0x800(%r8,%r9,4), %r10d
andl %ebx, %r11d
shll $0x2, %r11d
orl 0xc00(%r11,%r8), %r10d
movl %ecx, %eax
shrl $0x18, %eax
orl 0x1000(%r8,%rax,4), %r10d
movl %ecx, %r14d
shrl $0xe, %r14d
andl %edx, %r14d
orl 0x1400(%r14,%r8), %r10d
movl %ecx, %edx
shrl $0x8, %edx
andl %ebx, %edx
orl 0x1800(%r8,%rdx,4), %r10d
andl %ebx, %ecx
shll $0x2, %ecx
orl 0x1c00(%rcx,%r8), %r10d
movq -0x10(%rsp), %r8
movl %r10d, (%r8)
leaq 0x21474(%rip), %r8      # 0x3d860
movl 0x400(%rdi,%r8), %edi
orl (%r8,%rsi,4), %edi
orl 0x800(%r8,%r9,4), %edi
orl 0xc00(%r11,%r8), %edi
orl 0x1000(%r8,%rax,4), %edi
orl 0x1400(%r14,%r8), %edi
orl 0x1800(%r8,%rdx,4), %edi
orl 0x1c00(%rcx,%r8), %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