#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 intmax_t;
typedef int /*<<< orphan*/ EVP_CIPHER_CTX;

/* Variables and functions */
int /*<<< orphan*/ EVP_DecryptFinal_ex(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ EVP_DecryptInit_ex(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_DecryptUpdate(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                     int *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ *malloc(int);
uint8_t *aes_decrypt(EVP_CIPHER_CTX *e, uint8_t *ciphertext, intmax_t *len) {
  intmax_t f_len = 0;
  intmax_t p_len = *len;
  uint8_t *plaintext = malloc(*len);
  EVP_DecryptInit_ex(e, NULL, NULL, NULL, NULL);
  EVP_DecryptUpdate(e, plaintext, (int *)&p_len, ciphertext, *len);
  EVP_DecryptFinal_ex(e, plaintext + p_len, (int *)&f_len);
  *len = p_len + f_len;
  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    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%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    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%r8d
lea    -0x20(%rbp),%rdx
call   1060 <EVP_DecryptUpdate@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <EVP_DecryptFinal_ex@plt>
mov    -0x20(%rbp),%ecx
add    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

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

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

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