#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*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ aeshw_init();
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ decrypt_cbc(int /*<<< orphan*/ *, int /*<<< orphan*/,
                               int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          int);
int /*<<< orphan*/ setkey_dec(int /*<<< orphan*/ *, int /*<<< orphan*/ const *);
void AES_CBC_decrypt_buffer(uint8_t *output, uint8_t *input, uint32_t length,
                            const uint8_t *key, const uint8_t *iv) {
  uint8_t iv_tmp[16];
  static uint8_t rk[272];
  assert(iv != NULL);
  aeshw_init();
  memcpy(iv_tmp, iv, 16);
  if (key != NULL) {
    setkey_dec(rk, key);
  }
  decrypt_cbc(rk, length, iv_tmp, input, output);
}


x86 assembly (clang, -O0):
<AES_CBC_decrypt_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    $0x0,%al
call   1060 <aeshw_init@plt>
lea    -0x70(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
cmpq   $0x0,-0x20(%rbp)
je     11b1 <AES_CBC_decrypt_buffer+0x61>
mov    -0x20(%rbp),%rsi
lea    0x2eb4(%rip),%rdi
call   1070 <setkey_dec@plt>
mov    -0x14(%rbp),%esi
lea    -0x70(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0x2e99(%rip),%rdi
call   1050 <decrypt_cbc@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AES_CBC_decrypt_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %r8,%rbp
mov    %rcx,%rbx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
test   %r8,%r8
setne  %dil
call   1030 <assert@plt>
xor    %eax,%eax
call   1060 <aeshw_init@plt>
mov    %rsp,%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
test   %rbx,%rbx
je     11a4 <AES_CBC_decrypt_buffer+0x54>
lea    0x2ec4(%rip),%rdi
mov    %rbx,%rsi
call   1070 <setkey_dec@plt>
lea    0x2eb5(%rip),%rdi
mov    %rsp,%rdx
mov    %r12d,%esi
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <decrypt_cbc@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AES_CBC_decrypt_buffer.rk = internal global [272 x i32] zeroinitializer
define void @AES_CBC_decrypt_buffer(i32* %0, i32* %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [16 x i32]
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%12 = load i32*, i32** %10
%13 = icmp ne i32* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i32 (...) @aeshw_init()
%17 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%18 = load i32*, i32** %10
%19 = call i32 @memcpy(i32* %17, i32* %18, i32 16)
%20 = load i32*, i32** %9
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %5
%23 = load i32*, i32** %9
%24 = call i32 @setkey_dec(i32* getelementptr inbounds ([272 x i32], [272 x i32]* @AES_CBC_decrypt_buffer.rk, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %22, %5
%26 = load i32, i32* %8
%27 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%28 = load i32*, i32** %7
%29 = load i32*, i32** %6
%30 = call i32 @decrypt_cbc(i32* getelementptr inbounds ([272 x i32], [272 x i32]* @AES_CBC_decrypt_buffer.rk, i64 0, i64 0), i32 %26, i32* %27, i32* %28, i32* %29)
ret void
}

LLVM IR (-O2):
@AES_CBC_decrypt_buffer.rk = internal global [272 x i32] zeroinitializer
define void @AES_CBC_decrypt_buffer(i32* %0, i32* %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca [16 x i32]
%7 = bitcast [16 x i32]* %6 to i8*
%8 = icmp ne i32* %4, null
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 (...) @aeshw_init()
%12 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 0
%13 = call i32 @memcpy(i32* %12, i32* %4, i32 16)
%14 = icmp eq i32* %3, null
br i1 %14, label %17, label %15
15: ; preds = %5
%16 = call i32 @setkey_dec(i32* getelementptr inbounds ([272 x i32], [272 x i32]* @AES_CBC_decrypt_buffer.rk, i64 0, i64 0), i32* %3)
br label %17
17: ; preds = %15, %5
%18 = call i32 @decrypt_cbc(i32* getelementptr inbounds ([272 x i32], [272 x i32]* @AES_CBC_decrypt_buffer.rk, i64 0, i64 0), i32 %2, i32* %12, i32* %1, i32* %0)
ret void
}