#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*/ EVP_CIPHER_CTX;

/* Variables and functions */
scalar_t__ AES_BLOCK_SIZE;
int /*<<< orphan*/ EVP_DecryptFinal_ex(int /*<<< orphan*/ *, void *, int *);
int /*<<< orphan*/ EVP_DecryptInit_ex(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_DecryptUpdate(int /*<<< orphan*/ *, void *, int *,
                                     void const *, unsigned int);
void *malloc(scalar_t__);
void *aes_decrypt(EVP_CIPHER_CTX *decryption_ctx, const void *ciphertext,
                  unsigned int input_length, unsigned int *output_length) {
  int myoutput_length = input_length, final_length = 0;
  void *plaintext = malloc(myoutput_length + AES_BLOCK_SIZE);
  EVP_DecryptInit_ex(decryption_ctx, NULL, NULL, NULL, NULL);
  EVP_DecryptUpdate(decryption_ctx, plaintext, &myoutput_length, ciphertext,
                    input_length);
  EVP_DecryptFinal_ex(decryption_ctx, plaintext + myoutput_length,
                      &final_length);
  *output_length = myoutput_length + final_length;
  return plaintext;
}


x86 assembly (clang, -O0):
<aes_decrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movslq -0x24(%rbp),%rdi
mov    0x2e79(%rip),%rax
add    (%rax),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rsi
mov    %r8,%rdx
mov    %r8,%rcx
call   1050 <EVP_DecryptInit_ex@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
lea    -0x24(%rbp),%rdx
call   1060 <EVP_DecryptUpdate@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
lea    -0x28(%rbp),%rdx
call   1030 <EVP_DecryptFinal_ex@plt>
mov    -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_decrypt>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    %edx,0x8(%rsp)
movl   $0x0,0xc(%rsp)
movslq %edx,%r13
mov    0x2e7c(%rip),%rax
mov    (%rax),%rdi
add    %r13,%rdi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <EVP_DecryptInit_ex@plt>
lea    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rcx
mov    %r13d,%r8d
call   1060 <EVP_DecryptUpdate@plt>
movslq 0x8(%rsp),%rsi
add    %rbx,%rsi
lea    0xc(%rsp),%rdx
mov    %r15,%rdi
call   1030 <EVP_DecryptFinal_ex@plt>
mov    0xc(%rsp),%eax
add    0x8(%rsp),%eax
mov    %eax,(%r14)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@AES_BLOCK_SIZE = global i64 0
define i8* @aes_decrypt(i32* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%12 = load i32, i32* %7
store i32 %12, i32* %9
store i32 0, i32* %10
%13 = load i32, i32* %9
%14 = sext i32 %13 to i64
%15 = load i64, i64* @AES_BLOCK_SIZE
%16 = add nsw i64 %14, %15
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %11
%18 = load i32*, i32** %5
%19 = call i32 @EVP_DecryptInit_ex(i32* %18, i32* null, i32* null, i32* null, i32* null)
%20 = load i32*, i32** %5
%21 = load i8*, i8** %11
%22 = load i8*, i8** %6
%23 = load i32, i32* %7
%24 = call i32 @EVP_DecryptUpdate(i32* %20, i8* %21, i32* %9, i8* %22, i32 %23)
%25 = load i32*, i32** %5
%26 = load i8*, i8** %11
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr i8, i8* %26, i64 %28
%30 = call i32 @EVP_DecryptFinal_ex(i32* %25, i8* %29, i32* %10)
%31 = load i32, i32* %9
%32 = load i32, i32* %10
%33 = add nsw i32 %31, %32
%34 = load i32*, i32** %8
store i32 %33, i32* %34
%35 = load i8*, i8** %11
ret i8* %35
}

LLVM IR (-O2):
@AES_BLOCK_SIZE = global i64 0
define i8* @aes_decrypt(i32* %0, i8* %1, i32 %2, i32* nocapture writeonly %3) {
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %5 to i8*
store i32 %2, i32* %5
%8 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%9 = sext i32 %2 to i64
%10 = load i64, i64* @AES_BLOCK_SIZE
%11 = add nsw i64 %10, %9
%12 = tail call i8* @malloc(i64 %11)
%13 = tail call i32 @EVP_DecryptInit_ex(i32* %0, i32* null, i32* null, i32* null, i32* null)
%14 = call i32 @EVP_DecryptUpdate(i32* %0, i8* %12, i32* %5, i8* %1, i32 %2)
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr i8, i8* %12, i64 %16
%18 = call i32 @EVP_DecryptFinal_ex(i32* %0, i8* %17, i32* %6)
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = add nsw i32 %20, %19
store i32 %21, i32* %3
ret i8* %12
}