#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ AES_KEY;

/* Variables and functions */
int /*<<< orphan*/ AES_DECRYPT;
int /*<<< orphan*/ AES_cbc_encrypt(unsigned char const *, unsigned char *, int,
                                   int /*<<< orphan*/ *, unsigned char *,
                                   int /*<<< orphan*/);
int /*<<< orphan*/ AES_set_decrypt_key(unsigned char const *, int,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
void aes_cbc_block_decrypt(const unsigned char *key, const unsigned char *iv,
                           const unsigned char *cipher, int blen, int tlen,
                           unsigned char *plain) {
  unsigned char iv_cpy[blen];
  memcpy(iv_cpy, iv, blen);
  AES_KEY key_ctx;
  AES_set_decrypt_key(key, blen * 8, &key_ctx);
  AES_cbc_encrypt(cipher, plain, tlen, &key_ctx, iv_cpy, AES_DECRYPT);
}


x86 assembly (clang, -O0):
<aes_cbc_block_decrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
shl    $0x3,%esi
lea    -0x3c(%rbp),%rdx
call   1050 <AES_set_decrypt_key@plt>
mov    -0x48(%rbp),%r8
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    0x2e3e(%rip),%rax
mov    (%rax),%r9d
lea    -0x3c(%rbp),%rcx
call   1030 <AES_cbc_encrypt@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_cbc_block_decrypt>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,-0x38(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %ecx,%ebx
mov    %rdx,%r12
mov    %rdi,%r13
mov    %ecx,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
mov    %ecx,%edx
call   1040 <memcpy@plt>
shl    $0x3,%ebx
lea    -0x3c(%rbp),%r15
mov    %r13,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
call   1050 <AES_set_decrypt_key@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%r9d
mov    %r12,%rdi
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <AES_cbc_encrypt@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AES_DECRYPT = global i32 0
define void @aes_cbc_block_decrypt(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i8* %5, i8** %12
%16 = load i32, i32* %10
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %13
%19 = alloca i8, i64 %17
store i64 %17, i64* %14
%20 = load i8*, i8** %8
%21 = load i32, i32* %10
%22 = call i32 @memcpy(i8* %19, i8* %20, i32 %21)
%23 = load i8*, i8** %7
%24 = load i32, i32* %10
%25 = mul nsw i32 %24, 8
%26 = call i32 @AES_set_decrypt_key(i8* %23, i32 %25, i32* %15)
%27 = load i8*, i8** %9
%28 = load i8*, i8** %12
%29 = load i32, i32* %11
%30 = load i32, i32* @AES_DECRYPT
%31 = call i32 @AES_cbc_encrypt(i8* %27, i8* %28, i32 %29, i32* %15, i8* %19, i32 %30)
%32 = load i8*, i8** %13
ret void
}

LLVM IR (-O2):
@AES_DECRYPT = global i32 0
define void @aes_cbc_block_decrypt(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca i32
%8 = zext i32 %3 to i64
%9 = alloca i8, i64 %8
%10 = call i32 @memcpy(i8* %9, i8* %1, i32 %3)
%11 = bitcast i32* %7 to i8*
%12 = shl nsw i32 %3, 3
%13 = call i32 @AES_set_decrypt_key(i8* %0, i32 %12, i32* %7)
%14 = load i32, i32* @AES_DECRYPT
%15 = call i32 @AES_cbc_encrypt(i8* %2, i8* %5, i32 %4, i32* %7, i8* %9, i32 %14)
ret void
}