// File: /workspace/github_c_makefile_star2_O0/zecoxao[P]ps3_decrypt_tools/lib/aes.c
// Function: aes_crypt_cbc
int aes_crypt_cbc(aes_context *ctx,
        int mode,
        size_t length,
        unsigned char iv[16],
        const unsigned char *input,
        unsigned char *output) {
    int i;
    unsigned char temp[16];

    if (length % 16)
        return ( POLARSSL_ERR_AES_INVALID_INPUT_LENGTH);

    if (mode == AES_DECRYPT) {
        while (length > 0) {
            memcpy(temp, input, 16);
            aes_crypt_ecb(ctx, mode, input, output);

            for (i = 0; i < 16; i++)
                output[i] = (unsigned char) (output[i] ^ iv[i]);

            memcpy(iv, temp, 16);

            input += 16;
            output += 16;
            length -= 16;
        }
    } else {
        while (length > 0) {
            for (i = 0; i < 16; i++)
                output[i] = (unsigned char) (input[i] ^ iv[i]);

            aes_crypt_ecb(ctx, mode, output, output);
            memcpy(iv, output, 16);

            input += 16;
            output += 16;
            length -= 16;
        }
    }

    return ( 0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x20(%rbp), %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x2ee9
movl $0xffffffde, -0x4(%rbp) # imm = 0xFFFFFFDE
jmp 0x304f
cmpl $0x0, -0x14(%rbp)
jne 0x2fa7
jmp 0x2ef5
cmpq $0x0, -0x20(%rbp)
jbe 0x2fa2
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x1be0
movl $0x0, -0x3c(%rbp)
cmpl $0x10, -0x3c(%rbp)
jge 0x2f66
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x28(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, %dl
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2f2e
movq -0x28(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
subq $0x10, %rax
movq %rax, -0x20(%rbp)
jmp 0x2ef5
jmp 0x3048
jmp 0x2fa9
cmpq $0x0, -0x20(%rbp)
jbe 0x3046
movl $0x0, -0x3c(%rbp)
cmpl $0x10, -0x3c(%rbp)
jge 0x2ff3
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x28(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, %dl
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2fbb
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x38(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x1be0
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
subq $0x10, %rax
movq %rax, -0x20(%rbp)
jmp 0x2fa9
jmp 0x3048
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)