// File: /workspace/github_c_makefile_star2_O2/zecoxao[P]ps3_decrypt_tools/lib/des.c
// Function: des_setkey
static void des_setkey(uint32_t SK[32], const unsigned char key[DES_KEY_SIZE]) {
    int i;
    uint32_t X, Y, T;

    GET_UINT32_BE(X, key, 0);
    GET_UINT32_BE(Y, key, 4);

    /*
     * Permuted Choice 1
     */
    T = ((Y >> 4) ^ X) & 0x0F0F0F0F;
    X ^= T;
    Y ^= (T << 4);
    T = ((Y) ^ X) & 0x10101010;
    X ^= T;
    Y ^= (T);

    X = (LHs[ (X) & 0xF] << 3) | (LHs[ (X >> 8) & 0xF ] << 2)
            | (LHs[ (X >> 16) & 0xF] << 1) | (LHs[ (X >> 24) & 0xF ])
            | (LHs[ (X >> 5) & 0xF] << 7) | (LHs[ (X >> 13) & 0xF ] << 6)
            | (LHs[ (X >> 21) & 0xF] << 5) | (LHs[ (X >> 29) & 0xF ] << 4);

    Y = (RHs[ (Y >> 1) & 0xF] << 3) | (RHs[ (Y >> 9) & 0xF ] << 2)
            | (RHs[ (Y >> 17) & 0xF] << 1) | (RHs[ (Y >> 25) & 0xF ])
            | (RHs[ (Y >> 4) & 0xF] << 7) | (RHs[ (Y >> 12) & 0xF ] << 6)
            | (RHs[ (Y >> 20) & 0xF] << 5) | (RHs[ (Y >> 28) & 0xF ] << 4);

    X &= 0x0FFFFFFF;
    Y &= 0x0FFFFFFF;

    /*
     * calculate subkeys
     */
    for (i = 0; i < 16; i++) {
        if (i < 2 || i == 8 || i == 15) {
            X = ((X << 1) | (X >> 27)) & 0x0FFFFFFF;
            Y = ((Y << 1) | (Y >> 27)) & 0x0FFFFFFF;
        } else {
            X = ((X << 2) | (X >> 26)) & 0x0FFFFFFF;
            Y = ((Y << 2) | (Y >> 26)) & 0x0FFFFFFF;
        }

        *SK++ = ((X << 4) & 0x24000000) | ((X << 28) & 0x10000000)
                | ((X << 14) & 0x08000000) | ((X << 18) & 0x02080000)
                | ((X << 6) & 0x01000000) | ((X << 9) & 0x00200000)
                | ((X >> 1) & 0x00100000) | ((X << 10) & 0x00040000)
                | ((X << 2) & 0x00020000) | ((X >> 10) & 0x00010000)
                | ((Y >> 13) & 0x00002000) | ((Y >> 4) & 0x00001000)
                | ((Y << 6) & 0x00000800) | ((Y >> 1) & 0x00000400)
                | ((Y >> 14) & 0x00000200) | ((Y) & 0x00000100)
                | ((Y >> 5) & 0x00000020) | ((Y >> 10) & 0x00000010)
                | ((Y >> 3) & 0x00000008) | ((Y >> 18) & 0x00000004)
                | ((Y >> 26) & 0x00000002) | ((Y >> 24) & 0x00000001);

        *SK++ = ((X << 15) & 0x20000000) | ((X << 17) & 0x10000000)
                | ((X << 10) & 0x08000000) | ((X << 22) & 0x04000000)
                | ((X >> 2) & 0x02000000) | ((X << 1) & 0x01000000)
                | ((X << 16) & 0x00200000) | ((X << 11) & 0x00100000)
                | ((X << 3) & 0x00080000) | ((X >> 6) & 0x00040000)
                | ((X << 15) & 0x00020000) | ((X >> 4) & 0x00010000)
                | ((Y >> 2) & 0x00002000) | ((Y << 8) & 0x00001000)
                | ((Y >> 14) & 0x00000808) | ((Y >> 9) & 0x00000400)
                | ((Y) & 0x00000200) | ((Y << 7) & 0x00000100)
                | ((Y >> 7) & 0x00000020) | ((Y >> 3) & 0x00000011)
                | ((Y << 2) & 0x00000004) | ((Y >> 21) & 0x00000002);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, -0x8(%rsp)
movzbl (%rsi), %ecx
movl %ecx, %eax
shll $0x18, %eax
movzbl 0x1(%rsi), %edx
shll $0x10, %edx
orl %eax, %edx
movzbl 0x2(%rsi), %eax
shll $0x8, %eax
movzbl 0x3(%rsi), %r8d
orl %edx, %r8d
orl %eax, %r8d
movl 0x4(%rsi), %edx
bswapl %edx
movl %edx, %eax
shrl $0x4, %eax
xorl %r8d, %eax
andl $0xf0f0f0f, %eax        # imm = 0xF0F0F0F
movl %eax, %esi
xorl %r8d, %esi
shll $0x4, %eax
xorl %edx, %eax
andl $0x10101010, %r8d       # imm = 0x10101010
andl $0xefefefef, %eax       # imm = 0xEFEFEFEF
orl %r8d, %eax
movl %esi, %edx
andl $0xf, %edx
leaq 0x7b7f(%rip), %r8       # 0xbbe0
movl (%r8,%rdx,4), %edx
shll $0x3, %edx
movl %esi, %r9d
shrl $0x6, %r9d
andl $0x3c, %r9d
movl (%r9,%r8), %r9d
shll $0x2, %r9d
orl %edx, %r9d
movl %esi, %edx
shrl $0xe, %edx
andl $0x3c, %edx
movl (%rdx,%r8), %edx
addl %edx, %edx
orl %r9d, %edx
movl %esi, %r9d
shrl $0x16, %r9d
andl $0x3c, %r9d
orl (%r9,%r8), %edx
movl %esi, %r9d
shrl $0x3, %r9d
andl $0x3c, %r9d
movl (%r9,%r8), %r9d
shll $0x7, %r9d
movl %esi, %r10d
shrl $0xb, %r10d
andl $0x3c, %r10d
movl (%r10,%r8), %r10d
shll $0x6, %r10d
orl %r9d, %r10d
shrl $0x13, %esi
andl $0x3c, %esi
movl (%rsi,%r8), %esi
shll $0x5, %esi
orl %r10d, %esi
shrl $0x5, %ecx
movl (%r8,%rcx,4), %r10d
shll $0x4, %r10d
orl %esi, %r10d
movl %eax, %esi
andl $0x1e, %esi
leaq 0x7b2f(%rip), %rcx      # 0xbc20
movl (%rcx,%rsi,2), %esi
shll $0x3, %esi
movl %eax, %r8d
shrl $0x7, %r8d
andl $0x3c, %r8d
movl (%r8,%rcx), %r8d
shll $0x2, %r8d
orl %esi, %r8d
movl %eax, %esi
shrl $0xf, %esi
andl $0x3c, %esi
movl (%rsi,%rcx), %esi
addl %esi, %esi
orl %r8d, %esi
movl %eax, %r8d
shrl $0x17, %r8d
andl $0x3c, %r8d
orl (%r8,%rcx), %esi
orl %edx, %r10d
movl %eax, %edx
shrl $0x2, %edx
andl $0x3c, %edx
movl (%rdx,%rcx), %edx
shll $0x7, %edx
movl %eax, %r8d
shrl $0xa, %r8d
andl $0x3c, %r8d
movl (%r8,%rcx), %r8d
shll $0x6, %r8d
orl %edx, %r8d
movl %eax, %edx
shrl $0x12, %edx
andl $0x3c, %edx
movl (%rdx,%rcx), %edx
shll $0x5, %edx
orl %r8d, %edx
shrl $0x1c, %eax
movl (%rcx,%rax,4), %r9d
shll $0x4, %r9d
orl %edx, %r9d
orl %esi, %r9d
movl $0xfffffff, %eax        # imm = 0xFFFFFFF
andl %eax, %r10d
andl %eax, %r9d
xorl %r8d, %r8d
cmpl $0x10, %r8d
ja 0x4443
movl $0xffffffe, %ebx        # imm = 0xFFFFFFE
movl $0x8103, %eax           # imm = 0x8103
btl %r8d, %eax
movl $0x1, %eax
movl $0x1b, %edx
jae 0x443d
movl %r10d, %r15d
movl %eax, %ecx
shll %cl, %r15d
movl %edx, %ecx
shrl %cl, %r10d
movl %r15d, %r12d
andl %ebx, %r12d
movl %r12d, %r13d
orl %r10d, %r13d
movl %r9d, %r11d
movl %eax, %ecx
shll %cl, %r11d
movl %edx, %ecx
shrl %cl, %r9d
andl %r11d, %ebx
movl %ebx, %eax
orl %r9d, %eax
movl %r12d, %ecx
shll $0x4, %ecx
andl $0x24000000, %ecx       # imm = 0x24000000
andl $0x1, %r10d
shll $0x1c, %r10d
orl %ecx, %r10d
movl %r15d, %ecx
shll $0xe, %ecx
movl $0x8000000, %edx        # imm = 0x8000000
andl %edx, %ecx
orl %r10d, %ecx
movl %r13d, %edx
movl %r13d, %esi
shll $0x12, %esi
andl $0x2080000, %esi        # imm = 0x2080000
orl %ecx, %esi
movl %r15d, %ecx
shll $0x6, %ecx
andl $0x1000000, %ecx        # imm = 0x1000000
orl %esi, %ecx
movl %r15d, %esi
shll $0x9, %esi
andl $0x200000, %esi         # imm = 0x200000
orl %ecx, %esi
movl %r15d, %r10d
shrl %r10d
movl $0x100000, %ecx         # imm = 0x100000
andl %ecx, %r10d
orl %esi, %r10d
shll $0xa, %edx
movl %edx, %ecx
movl $0x40000, %esi          # imm = 0x40000
andl %esi, %ecx
leal (,%r12,4), %esi
movl $0x20000, %edi          # imm = 0x20000
andl %edi, %esi
orl %ecx, %esi
movl %r15d, %ecx
shrl $0xa, %ecx
movl $0x10000, %edi          # imm = 0x10000
andl %edi, %ecx
orl %esi, %ecx
movl %eax, %esi
andl $0x20, %esi
shll $0x6, %esi
movl %r11d, %ebp
shrl %ebp
movl $0x400, %edi            # imm = 0x400
andl %edi, %ebp
orl %esi, %ebp
shrl $0xe, %ebx
movl %ebx, %r14d
movl $0x200, %esi            # imm = 0x200
andl %esi, %r14d
orl %ebp, %r14d
movl %r11d, %esi
andl $0x100, %esi            # imm = 0x100
orl %ecx, %esi
movl %r11d, %ecx
shrl $0xd, %ecx
movl $0x2000, %edi           # imm = 0x2000
andl %edi, %ecx
orl %ecx, %esi
movl %r11d, %ecx
shrl $0x4, %ecx
andl $0x1000, %ecx           # imm = 0x1000
orl %ecx, %esi
movl %eax, %ecx
orl %r10d, %esi
movl %r11d, %r10d
shrl $0x5, %r10d
andl $0x20, %r10d
orl %r14d, %r10d
movl %r11d, %ebp
shrl $0xa, %ebp
andl $0x10, %ebp
orl %r10d, %ebp
shrl $0x3, %ecx
movl %ecx, %r10d
andl $0x8, %r10d
orl %ebp, %r10d
movl %r11d, %ebp
shrl $0x12, %ebp
andl $0x4, %ebp
orl %r10d, %ebp
orl %esi, %ebp
movl %r11d, %esi
shrl $0x1a, %esi
andl $0x2, %esi
movl %r11d, %r14d
shrl $0x18, %r14d
andl $0x1, %r14d
orl %esi, %r14d
movl %r13d, %r10d
orl %ebp, %r14d
movq -0x8(%rsp), %rdi
movl %r14d, (%rdi,%r8,8)
shll $0xf, %r10d
movl %r10d, %esi
andl $0x20000000, %esi       # imm = 0x20000000
movl %r15d, %ebp
shll $0x11, %ebp
andl $0x10000000, %ebp       # imm = 0x10000000
orl %esi, %ebp
movl $0x8000000, %esi        # imm = 0x8000000
andl %esi, %edx
orl %ebp, %edx
movl %r13d, %esi
andl $0x10, %esi
shll $0x16, %esi
orl %edx, %esi
movl %r15d, %edx
shrl $0x2, %edx
andl $0x2000000, %edx        # imm = 0x2000000
orl %esi, %edx
movl %r12d, %esi
andl $0x800000, %esi         # imm = 0x800000
leal (%rdx,%rsi,2), %esi
movl %r13d, %edx
andl $0x20, %edx
shll $0x10, %edx
orl %esi, %edx
movl %r15d, %esi
shll $0xb, %esi
movl $0x100000, %ebp         # imm = 0x100000
andl %ebp, %esi
shll $0x3, %r12d
andl $0x80000, %r12d         # imm = 0x80000
orl %esi, %r12d
movl %r15d, %esi
shrl $0x6, %esi
movl $0x40000, %ebp          # imm = 0x40000
andl %ebp, %esi
orl %r12d, %esi
movl $0x20000, %ebp          # imm = 0x20000
andl %ebp, %r10d
orl %esi, %r10d
shrl $0x4, %r15d
movl $0x10000, %esi          # imm = 0x10000
andl %esi, %r15d
orl %r10d, %r15d
andl $0x808, %ebx            # imm = 0x808
movl %r11d, %r10d
shrl $0x9, %r10d
movl $0x400, %esi            # imm = 0x400
andl %esi, %r10d
orl %ebx, %r10d
movl %r11d, %esi
movl $0x200, %ebx            # imm = 0x200
andl %ebx, %esi
orl %r15d, %esi
movl %r11d, %ebx
shrl $0x2, %ebx
movl $0x2000, %ebp           # imm = 0x2000
andl %ebp, %ebx
orl %ebx, %esi
movl %eax, %ebx
andl $0x10, %ebx
shll $0x8, %ebx
orl %ebx, %esi
orl %edx, %esi
movl %eax, %edx
andl $0x2, %edx
shll $0x7, %edx
orl %r10d, %edx
movl %r11d, %r10d
shrl $0x7, %r10d
andl $0x20, %r10d
orl %edx, %r10d
andl $0x11, %ecx
orl %r10d, %ecx
shll $0x2, %r9d
andl $0x4, %r9d
orl %ecx, %r9d
shrl $0x15, %r11d
andl $0x2, %r11d
orl %r9d, %r11d
orl %esi, %r11d
movl %r11d, 0x4(%rdi,%r8,8)
movl %r13d, %r10d
movl %eax, %r9d
incq %r8
jmp 0x4183
cmpl $0x10, %r8d
je 0x4457
movl $0xffffffc, %ebx        # imm = 0xFFFFFFC
movl $0x2, %eax
movl $0x1a, %edx
jmp 0x41ab
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq