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


x86 assembly (clang, -O0):
<_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2e87(%rip),%rcx
add    (%rcx),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%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   1060 <EVP_EncryptInit_ex@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%r8d
lea    -0x1c(%rbp),%rdx
call   1030 <EVP_EncryptUpdate@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
lea    -0x20(%rbp),%rdx
call   1050 <EVP_EncryptFinal_ex@plt>
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_encrypt>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
add    (%rdx),%edi
mov    %edi,(%rsp)
movl   $0x0,0x4(%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>
mov    (%r14),%r8d
mov    %rsp,%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rcx
call   1030 <EVP_EncryptUpdate@plt>
movslq (%rsp),%rsi
add    %rbx,%rsi
lea    0x4(%rsp),%rdx
mov    %r15,%rdi
call   1050 <EVP_EncryptFinal_ex@plt>
mov    0x4(%rsp),%eax
add    (%rsp),%eax
mov    %eax,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@AES_BLOCK_SIZE = global i32 0
define i8* @_encrypt(i32* %0, i8* %1, i32* nocapture %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* %2
%8 = load i32, i32* @AES_BLOCK_SIZE
%9 = add nsw i32 %8, %7
store i32 %9, i32* %4
%10 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%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 = load i32, i32* %2
%14 = call i32 @EVP_EncryptUpdate(i32* %0, i8* %11, i32* %4, i8* %1, i32 %13)
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %11, i64 %16
%18 = call i32 @EVP_EncryptFinal_ex(i32* %0, i8* %17, i32* %5)
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = add nsw i32 %20, %19
store i32 %21, i32* %2
ret i8* %11
}