#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 /*<<< orphan*/ EVP_CIPHER_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_CIPHER_CTX_new();
int EVP_EncryptInit_ex(int /*<<< orphan*/ *, int /*<<< orphan*/,
                       int /*<<< orphan*/ *, unsigned char *,
                       int /*<<< orphan*/ *);
int EVP_EncryptUpdate(int /*<<< orphan*/ *, unsigned char *, int *,
                      unsigned char *, int);
int /*<<< orphan*/ EVP_aes_256_ecb();
int /*<<< orphan*/ handleErrors();
void AES256_ECB(unsigned char *key, unsigned char *ctr, unsigned char *buffer) {
  EVP_CIPHER_CTX *ctx;
  int len;
  int ciphertext_len;
  if (!(ctx = EVP_CIPHER_CTX_new()))
    handleErrors();
  if (1 != EVP_EncryptInit_ex(ctx, EVP_aes_256_ecb(), NULL, key, NULL))
    handleErrors();
  if (1 != EVP_EncryptUpdate(ctx, buffer, &len, ctr, 16))
    handleErrors();
  ciphertext_len = len;
  EVP_CIPHER_CTX_free(ctx);
}


x86 assembly (clang, -O0):
<AES256_ECB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1080 <EVP_CIPHER_CTX_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1190 <AES256_ECB+0x30>
mov    $0x0,%al
call   1050 <handleErrors@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1060 <EVP_aes_256_ecb@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
call   1070 <EVP_EncryptInit_ex@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     11cc <AES256_ECB+0x6c>
mov    $0x0,%al
call   1050 <handleErrors@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rcx
lea    -0x24(%rbp),%rdx
mov    $0x10,%r8d
call   1040 <EVP_EncryptUpdate@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     11fd <AES256_ECB+0x9d>
mov    $0x0,%al
call   1050 <handleErrors@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <EVP_CIPHER_CTX_free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AES256_ECB>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
xor    %eax,%eax
call   1080 <EVP_CIPHER_CTX_new@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1187 <AES256_ECB+0x27>
xor    %eax,%eax
call   1050 <handleErrors@plt>
xor    %eax,%eax
call   1060 <EVP_aes_256_ecb@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    %r12,%rcx
xor    %r8d,%r8d
call   1070 <EVP_EncryptInit_ex@plt>
cmp    $0x1,%eax
je     11ac <AES256_ECB+0x4c>
xor    %eax,%eax
call   1050 <handleErrors@plt>
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
mov    $0x10,%r8d
call   1040 <EVP_EncryptUpdate@plt>
cmp    $0x1,%eax
je     11d1 <AES256_ECB+0x71>
xor    %eax,%eax
call   1050 <handleErrors@plt>
mov    %rbx,%rdi
call   1030 <EVP_CIPHER_CTX_free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @AES256_ECB(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = call i32* (...) @EVP_CIPHER_CTX_new()
store i32* %10, i32** %7
%11 = icmp ne i32* %10, null
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 (...) @handleErrors()
br label %14
14: ; preds = %12, %3
%15 = load i32*, i32** %7
%16 = call i32 (...) @EVP_aes_256_ecb()
%17 = load i8*, i8** %4
%18 = call i32 @EVP_EncryptInit_ex(i32* %15, i32 %16, i32* null, i8* %17, i32* null)
%19 = icmp ne i32 1, %18
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 (...) @handleErrors()
br label %22
22: ; preds = %20, %14
%23 = load i32*, i32** %7
%24 = load i8*, i8** %6
%25 = load i8*, i8** %5
%26 = call i32 @EVP_EncryptUpdate(i32* %23, i8* %24, i32* %8, i8* %25, i32 16)
%27 = icmp ne i32 1, %26
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 (...) @handleErrors()
br label %30
30: ; preds = %28, %22
%31 = load i32, i32* %8
store i32 %31, i32* %9
%32 = load i32*, i32** %7
%33 = call i32 @EVP_CIPHER_CTX_free(i32* %32)
ret void
}

LLVM IR (-O2):
define void @AES256_ECB(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32* (...) @EVP_CIPHER_CTX_new()
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 (...) @handleErrors()
br label %10
10: ; preds = %8, %3
%11 = tail call i32 (...) @EVP_aes_256_ecb()
%12 = tail call i32 @EVP_EncryptInit_ex(i32* %6, i32 %11, i32* null, i8* %0, i32* null)
%13 = icmp eq i32 %12, 1
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 (...) @handleErrors()
br label %16
16: ; preds = %14, %10
%17 = call i32 @EVP_EncryptUpdate(i32* %6, i8* %2, i32* %4, i8* %1, i32 16)
%18 = icmp eq i32 %17, 1
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = call i32 (...) @handleErrors()
br label %21
21: ; preds = %19, %16
%22 = call i32 @EVP_CIPHER_CTX_free(i32* %6)
ret void
}