// File: /workspace/github_c_makefile_star2_O0/zecoxao[P]ps3_decrypt_tools/lib/aes.c
// Function: aes_setkey_dec
int aes_setkey_dec(aes_context *ctx, const unsigned char *key, unsigned int keysize) {
    int i, j;
    aes_context cty;
    unsigned long *RK;
    unsigned long *SK;
    int ret;

    switch (keysize) {
        case 128: ctx->nr = 10;
            break;
        case 192: ctx->nr = 12;
            break;
        case 256: ctx->nr = 14;
            break;
        default: return ( POLARSSL_ERR_AES_INVALID_KEY_LENGTH);
    }

    ctx->rk = RK = ctx->buf;

    ret = aes_setkey_enc(&cty, key, keysize);
    if (ret != 0)
        return ( ret);

    SK = cty.rk + cty.nr * 4;

    *RK++ = *SK++;
    *RK++ = *SK++;
    *RK++ = *SK++;
    *RK++ = *SK++;

    for (i = ctx->nr - 1, SK -= 8; i > 0; i--, SK -= 8) {
        for (j = 0; j < 4; j++, SK++) {
            *RK++ = RT0[ FSb[ (*SK) & 0xFF ] ] ^
                    RT1[ FSb[ (*SK >> 8) & 0xFF ] ] ^
                    RT2[ FSb[ (*SK >> 16) & 0xFF ] ] ^
                    RT3[ FSb[ (*SK >> 24) & 0xFF ] ];
        }
    }

    *RK++ = *SK++;
    *RK++ = *SK++;
    *RK++ = *SK++;
    *RK++ = *SK++;

    memset(&cty, 0, sizeof ( aes_context));

    return ( 0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x270(%rbp)
subl $0x80, %eax
je 0x1856
jmp 0x1838
movl -0x270(%rbp), %eax
subl $0xc0, %eax
je 0x1862
jmp 0x1847
movl -0x270(%rbp), %eax
subl $0x100, %eax            # imm = 0x100
je 0x186e
jmp 0x187a
movq -0x10(%rbp), %rax
movl $0xa, (%rax)
jmp 0x1886
movq -0x10(%rbp), %rax
movl $0xc, (%rax)
jmp 0x1886
movq -0x10(%rbp), %rax
movl $0xe, (%rax)
jmp 0x1886
movl $0xffffffe0, -0x4(%rbp) # imm = 0xFFFFFFE0
jmp 0x1bcb
movq -0x10(%rbp), %rcx
addq $0x10, %rcx
movq %rcx, -0x260(%rbp)
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
leaq -0x258(%rbp), %rdi
callq 0x1250
movl %eax, -0x26c(%rbp)
cmpl $0x0, -0x26c(%rbp)
je 0x18cd
movl -0x26c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1bcb
movq -0x250(%rbp), %rax
movl -0x258(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x268(%rbp)
movq -0x268(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x268(%rbp)
movq (%rax), %rcx
movq -0x260(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x260(%rbp)
movq %rcx, (%rax)
movq -0x268(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x268(%rbp)
movq (%rax), %rcx
movq -0x260(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x260(%rbp)
movq %rcx, (%rax)
movq -0x268(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x268(%rbp)
movq (%rax), %rcx
movq -0x260(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x260(%rbp)
movq %rcx, (%rax)
movq -0x268(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x268(%rbp)
movq (%rax), %rcx
movq -0x260(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x260(%rbp)
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x268(%rbp), %rax
addq $-0x40, %rax
movq %rax, -0x268(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0x1af1
movl $0x0, -0x24(%rbp)
cmpl $0x4, -0x24(%rbp)
jge 0x1acf
movq -0x268(%rbp), %rax
movq (%rax), %rcx
andq $0xff, %rcx
leaq 0xa661(%rip), %rax      # 0xc060
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0xa754(%rip), %rax      # 0xc160
movq (%rax,%rcx,8), %rcx
movq -0x268(%rbp), %rax
movq (%rax), %rdx
shrq $0x8, %rdx
andq $0xff, %rdx
leaq 0xa634(%rip), %rax      # 0xc060
movzbl (%rax,%rdx), %eax
movl %eax, %edx
leaq 0xaf27(%rip), %rax      # 0xc960
xorq (%rax,%rdx,8), %rcx
movq -0x268(%rbp), %rax
movq (%rax), %rdx
shrq $0x10, %rdx
andq $0xff, %rdx
leaq 0xa607(%rip), %rax      # 0xc060
movzbl (%rax,%rdx), %eax
movl %eax, %edx
leaq 0xb6fa(%rip), %rax      # 0xd160
xorq (%rax,%rdx,8), %rcx
movq -0x268(%rbp), %rax
movq (%rax), %rdx
shrq $0x18, %rdx
andq $0xff, %rdx
leaq 0xa5da(%rip), %rax      # 0xc060
movzbl (%rax,%rdx), %eax
movl %eax, %edx
leaq 0xbecd(%rip), %rax      # 0xd960
xorq (%rax,%rdx,8), %rcx
movq -0x260(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x260(%rbp)
movq %rcx, (%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x268(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x268(%rbp)
jmp 0x19dd
jmp 0x1ad1
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x268(%rbp), %rax
addq $-0x40, %rax
movq %rax, -0x268(%rbp)
jmp 0x19cc
movq -0x268(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x268(%rbp)
movq (%rax), %rcx
movq -0x260(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x260(%rbp)
movq %rcx, (%rax)
movq -0x268(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x268(%rbp)
movq (%rax), %rcx
movq -0x260(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x260(%rbp)
movq %rcx, (%rax)
movq -0x268(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x268(%rbp)
movq (%rax), %rcx
movq -0x260(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x260(%rbp)
movq %rcx, (%rax)
movq -0x268(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x268(%rbp)
movq (%rax), %rcx
movq -0x260(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x260(%rbp)
movq %rcx, (%rax)
leaq -0x258(%rbp), %rdi
xorl %esi, %esi
movl $0x230, %edx            # imm = 0x230
callq 0x1090
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
nopw (%rax,%rax)