#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 */
unsigned int AES_BLOCK_SIZE;
int /*<<< orphan*/ EVP_EncryptFinal_ex(int /*<<< orphan*/ *, void *, int *);
int /*<<< orphan*/ EVP_EncryptInit_ex(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_EncryptUpdate(int /*<<< orphan*/ *, void *, int *,
                                     void const *, unsigned int);
void *malloc(int);
void *aes_encrypt(EVP_CIPHER_CTX *encryption_ctx, const void *plaintext,
                  unsigned int input_length, unsigned int *output_length) {
  int cipher_length = input_length + AES_BLOCK_SIZE, final_length = 0;
  void *ciphertext = malloc(cipher_length);
  EVP_EncryptInit_ex(encryption_ctx, NULL, NULL, NULL, NULL);
  EVP_EncryptUpdate(encryption_ctx, ciphertext, &cipher_length, plaintext,
                    input_length);
  EVP_EncryptFinal_ex(encryption_ctx, ciphertext + cipher_length,
                      &final_length);
  *output_length = cipher_length + final_length;
  return ciphertext;
}


x86 assembly (clang, -O0):
<aes_encrypt>:
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    0x2e87(%rip),%rcx
add    (%rcx),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%edi
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   1060 <EVP_EncryptInit_ex@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
lea    -0x24(%rbp),%rdx
call   1030 <EVP_EncryptUpdate@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
lea    -0x28(%rbp),%rdx
call   1050 <EVP_EncryptFinal_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_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%r12
mov    %rdi,%r15
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
add    %edx,%edi
mov    %edi,0x8(%rsp)
movl   $0x0,0xc(%rsp)
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <EVP_EncryptInit_ex@plt>
lea    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rcx
mov    %ebp,%r8d
call   1030 <EVP_EncryptUpdate@plt>
movslq 0x8(%rsp),%rsi
add    %rbx,%rsi
lea    0xc(%rsp),%rdx
mov    %r15,%rdi
call   1050 <EVP_EncryptFinal_ex@plt>
mov    0xc(%rsp),%eax
add    0x8(%rsp),%eax
mov    %eax,(%r14)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AES_BLOCK_SIZE = global i32 0
define i8* @aes_encrypt(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
%13 = load i32, i32* @AES_BLOCK_SIZE
%14 = add i32 %12, %13
store i32 %14, i32* %9
store i32 0, i32* %10
%15 = load i32, i32* %9
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %11
%17 = load i32*, i32** %5
%18 = call i32 @EVP_EncryptInit_ex(i32* %17, i32* null, i32* null, i32* null, i32* null)
%19 = load i32*, i32** %5
%20 = load i8*, i8** %11
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = call i32 @EVP_EncryptUpdate(i32* %19, i8* %20, i32* %9, i8* %21, i32 %22)
%24 = load i32*, i32** %5
%25 = load i8*, i8** %11
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr i8, i8* %25, i64 %27
%29 = call i32 @EVP_EncryptFinal_ex(i32* %24, i8* %28, i32* %10)
%30 = load i32, i32* %9
%31 = load i32, i32* %10
%32 = add nsw i32 %30, %31
%33 = load i32*, i32** %8
store i32 %32, i32* %33
%34 = load i8*, i8** %11
ret i8* %34
}

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