#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 */
int AES_BLOCK_SIZE;
int EVP_EncryptFinal_ex(int /*<<< orphan*/ *, unsigned char *, int *);
int EVP_EncryptInit_ex(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *);
int EVP_EncryptUpdate(int /*<<< orphan*/ *, unsigned char *, int *,
                      unsigned char *, int);
int /*<<< orphan*/ assert(int);
unsigned char *malloc(int);
unsigned char *aes_encrypt(EVP_CIPHER_CTX *e, unsigned char *plaintext,
                           int *len, int *retlen) {
  int rc = 0;
  int c_len = *len + AES_BLOCK_SIZE, f_len = 0;
  unsigned char *ciphertext = malloc(c_len);
  rc = EVP_EncryptInit_ex(e, NULL, NULL, NULL, NULL);
  assert(rc == 1);
  rc = EVP_EncryptUpdate(e, ciphertext, &c_len, plaintext, *len);
  assert(rc == 1);
  rc = EVP_EncryptFinal_ex(e, ciphertext + c_len, &f_len);
  assert(rc == 1);
  *len = c_len + f_len;
  return ciphertext;
}


x86 assembly (clang, -O0):
<aes_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2e6c(%rip),%rcx
add    (%rcx),%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rsi
mov    %r8,%rdx
mov    %r8,%rcx
call   1070 <EVP_EncryptInit_ex@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%r8d
lea    -0x28(%rbp),%rdx
call   1040 <EVP_EncryptUpdate@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
movslq -0x28(%rbp),%rax
add    %rax,%rsi
lea    -0x2c(%rbp),%rdx
call   1060 <EVP_EncryptFinal_ex@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x28(%rbp),%ecx
add    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_encrypt>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
add    (%rdx),%edi
mov    %edi,(%rsp)
movl   $0x0,0x4(%rsp)
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <EVP_EncryptInit_ex@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1030 <assert@plt>
mov    (%r14),%r8d
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rcx
call   1040 <EVP_EncryptUpdate@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1030 <assert@plt>
movslq (%rsp),%rsi
add    %r15,%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <EVP_EncryptFinal_ex@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1030 <assert@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):
@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 i32
%12 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 0, i32* %9
%13 = load i32*, i32** %7
%14 = load i32, i32* %13
%15 = load i32, i32* @AES_BLOCK_SIZE
%16 = add nsw i32 %14, %15
store i32 %16, i32* %10
store i32 0, i32* %11
%17 = load i32, i32* %10
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %12
%19 = load i32*, i32** %5
%20 = call i32 @EVP_EncryptInit_ex(i32* %19, i32* null, i32* null, i32* null, i32* null)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = icmp eq i32 %21, 1
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i32*, i32** %5
%26 = load i8*, i8** %12
%27 = load i8*, i8** %6
%28 = load i32*, i32** %7
%29 = load i32, i32* %28
%30 = call i32 @EVP_EncryptUpdate(i32* %25, i8* %26, i32* %10, i8* %27, i32 %29)
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = icmp eq i32 %31, 1
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = load i32*, i32** %5
%36 = load i8*, i8** %12
%37 = load i32, i32* %10
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = call i32 @EVP_EncryptFinal_ex(i32* %35, i8* %39, i32* %11)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = icmp eq i32 %41, 1
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
%45 = load i32, i32* %10
%46 = load i32, i32* %11
%47 = add nsw i32 %45, %46
%48 = load i32*, i32** %7
store i32 %47, i32* %48
%49 = load i8*, i8** %12
ret i8* %49
}

LLVM IR (-O2):
@AES_BLOCK_SIZE = global i32 0
define i8* @aes_encrypt(i32* %0, i8* %1, i32* nocapture %2, i32* nocapture readnone %3) {
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %5 to i8*
%8 = load i32, i32* %2
%9 = load i32, i32* @AES_BLOCK_SIZE
%10 = add nsw i32 %9, %8
store i32 %10, i32* %5
%11 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%12 = tail call i8* @malloc(i32 %10)
%13 = tail call i32 @EVP_EncryptInit_ex(i32* %0, i32* null, i32* null, i32* null, i32* null)
%14 = icmp eq i32 %13, 1
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = load i32, i32* %2
%18 = call i32 @EVP_EncryptUpdate(i32* %0, i8* %12, i32* %5, i8* %1, i32 %17)
%19 = icmp eq i32 %18, 1
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %12, i64 %23
%25 = call i32 @EVP_EncryptFinal_ex(i32* %0, i8* %24, i32* %6)
%26 = icmp eq i32 %25, 1
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = add nsw i32 %30, %29
store i32 %31, i32* %2
ret i8* %12
}