// File: /workspace/github_c_makefile_star2_O1/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 0x8a6b(%rip), %r8       # 0xcbc0
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), %r13d
shll $0x4, %r13d
orl %esi, %r13d
movl %eax, %esi
andl $0x1e, %esi
leaq 0x8a1b(%rip), %rcx      # 0xcc00
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, %r13d
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), %r15d
shll $0x4, %r15d
orl %edx, %r15d
orl %esi, %r15d
movl $0xfffffff, %ecx        # imm = 0xFFFFFFF
andl %ecx, %r13d
andl %ecx, %r15d
xorl %r8d, %r8d
cmpl $0xf, %r8d
ja 0x4545
movl $0x8103, %eax           # imm = 0x8103
btl %r8d, %eax
jae 0x4545
movl $0xffffffe, %r14d       # imm = 0xFFFFFFE
movl $0x1b, %esi
movl $0x1, %edx
movl %r13d, %r11d
movl %edx, %ecx
shll %cl, %r11d
movl %esi, %ecx
shrl %cl, %r13d
movl %r11d, %ebx
andl %r14d, %ebx
movl %ebx, %ebp
orl %r13d, %ebp
movl %r15d, %eax
movl %edx, %ecx
shll %cl, %eax
movl %esi, %ecx
shrl %cl, %r15d
andl %eax, %r14d
movl %r14d, %r12d
orl %r15d, %r12d
movl %ebx, %ecx
shll $0x4, %ecx
andl $0x24000000, %ecx       # imm = 0x24000000
andl $0x1, %r13d
shll $0x1c, %r13d
orl %ecx, %r13d
movl %r11d, %ecx
shll $0xe, %ecx
movl $0x8000000, %edx        # imm = 0x8000000
andl %edx, %ecx
orl %r13d, %ecx
movl %ebp, %edx
movl %ebp, %esi
shll $0x12, %esi
andl $0x2080000, %esi        # imm = 0x2080000
orl %ecx, %esi
movl %r11d, %ecx
shll $0x6, %ecx
andl $0x1000000, %ecx        # imm = 0x1000000
orl %esi, %ecx
movl %r11d, %esi
shll $0x9, %esi
andl $0x200000, %esi         # imm = 0x200000
orl %ecx, %esi
movl %r11d, %r13d
shrl %r13d
movl $0x100000, %ecx         # imm = 0x100000
andl %ecx, %r13d
orl %esi, %r13d
shll $0xa, %edx
movl %edx, %ecx
movl $0x40000, %esi          # imm = 0x40000
andl %esi, %ecx
leal (,%rbx,4), %esi
movl $0x20000, %edi          # imm = 0x20000
andl %edi, %esi
orl %ecx, %esi
movl %r11d, %ecx
shrl $0xa, %ecx
movl $0x10000, %edi          # imm = 0x10000
andl %edi, %ecx
orl %esi, %ecx
movl %r12d, %esi
andl $0x20, %esi
shll $0x6, %esi
movl %eax, %r9d
shrl %r9d
movl $0x400, %edi            # imm = 0x400
andl %edi, %r9d
orl %esi, %r9d
shrl $0xe, %r14d
movl %r14d, %r10d
movl $0x200, %esi            # imm = 0x200
andl %esi, %r10d
orl %r9d, %r10d
movl %eax, %esi
andl $0x100, %esi            # imm = 0x100
orl %ecx, %esi
movl %eax, %ecx
shrl $0xd, %ecx
movl $0x2000, %edi           # imm = 0x2000
andl %edi, %ecx
orl %ecx, %esi
movl %eax, %ecx
shrl $0x4, %ecx
andl $0x1000, %ecx           # imm = 0x1000
orl %ecx, %esi
movl %r12d, %ecx
orl %r13d, %esi
movl %eax, %r9d
shrl $0x5, %r9d
andl $0x20, %r9d
orl %r10d, %r9d
movl %eax, %r10d
shrl $0xa, %r10d
andl $0x10, %r10d
orl %r9d, %r10d
shrl $0x3, %ecx
movl %ecx, %r9d
andl $0x8, %r9d
orl %r10d, %r9d
movl %eax, %r10d
shrl $0x12, %r10d
andl $0x4, %r10d
orl %r9d, %r10d
orl %esi, %r10d
movl %eax, %esi
shrl $0x1a, %esi
andl $0x2, %esi
movl %eax, %r9d
shrl $0x18, %r9d
andl $0x1, %r9d
orl %esi, %r9d
movl %ebp, %r13d
orl %r10d, %r9d
movq -0x8(%rsp), %rdi
movl %r9d, (%rdi,%r8,8)
shll $0xf, %r13d
movl %r13d, %esi
andl $0x20000000, %esi       # imm = 0x20000000
movl %r11d, %r9d
shll $0x11, %r9d
andl $0x10000000, %r9d       # imm = 0x10000000
orl %esi, %r9d
movl $0x8000000, %esi        # imm = 0x8000000
andl %esi, %edx
orl %r9d, %edx
movl %ebp, %esi
andl $0x10, %esi
shll $0x16, %esi
orl %edx, %esi
movl %r11d, %edx
shrl $0x2, %edx
andl $0x2000000, %edx        # imm = 0x2000000
orl %esi, %edx
movl %ebx, %esi
andl $0x800000, %esi         # imm = 0x800000
leal (%rdx,%rsi,2), %esi
movl %ebp, %edx
andl $0x20, %edx
shll $0x10, %edx
orl %esi, %edx
movl %r11d, %esi
shll $0xb, %esi
movl $0x100000, %r9d         # imm = 0x100000
andl %r9d, %esi
shll $0x3, %ebx
andl $0x80000, %ebx          # imm = 0x80000
orl %esi, %ebx
movl %r11d, %esi
shrl $0x6, %esi
movl $0x40000, %r9d          # imm = 0x40000
andl %r9d, %esi
orl %ebx, %esi
movl $0x20000, %r9d          # imm = 0x20000
andl %r9d, %r13d
orl %esi, %r13d
shrl $0x4, %r11d
movl $0x10000, %esi          # imm = 0x10000
andl %esi, %r11d
orl %r13d, %r11d
andl $0x808, %r14d           # imm = 0x808
movl %eax, %r9d
shrl $0x9, %r9d
movl $0x400, %esi            # imm = 0x400
andl %esi, %r9d
orl %r14d, %r9d
movl %eax, %esi
movl $0x200, %r10d           # imm = 0x200
andl %r10d, %esi
orl %r11d, %esi
movl %eax, %r10d
shrl $0x2, %r10d
movl $0x2000, %r11d          # imm = 0x2000
andl %r11d, %r10d
orl %r10d, %esi
movl %r12d, %r10d
andl $0x10, %r10d
shll $0x8, %r10d
orl %r10d, %esi
orl %edx, %esi
movl %r12d, %edx
andl $0x2, %edx
shll $0x7, %edx
orl %r9d, %edx
movl %eax, %r9d
shrl $0x7, %r9d
andl $0x20, %r9d
orl %edx, %r9d
andl $0x11, %ecx
orl %r9d, %ecx
shll $0x2, %r15d
andl $0x4, %r15d
orl %ecx, %r15d
shrl $0x15, %eax
andl $0x2, %eax
orl %r15d, %eax
orl %esi, %eax
movl %eax, 0x4(%rdi,%r8,8)
movl %r12d, %r15d
movl %ebp, %r13d
incq %r8
cmpl $0x10, %r8d
jne 0x4277
jmp 0x455a
movl $0xffffffc, %r14d       # imm = 0xFFFFFFC
movl $0x1a, %esi
movl $0x2, %edx
jmp 0x42a0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq