#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_cleanup(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_CIPHER_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_CIPHER_CTX_new();
int /*<<< orphan*/ EVP_CIPHER_CTX_set_padding(int /*<<< orphan*/ *,
                                              int /*<<< orphan*/);
int /*<<< orphan*/ EVP_EncryptInit(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                   unsigned char const *,
                                   unsigned char const *);
int /*<<< orphan*/ EVP_EncryptUpdate(int /*<<< orphan*/ *, unsigned char *,
                                     int *, unsigned char *, int);
int /*<<< orphan*/ EVP_aes_128_ctr();
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ memxor(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ mixoaep_pad(unsigned char *, unsigned char *);
int /*<<< orphan*/ printf(char *);
void mixencrypt_bimacroblock_oaep(const unsigned char *bimacro,
                                  unsigned char *out, unsigned char *buffer,
                                  const unsigned char *key,
                                  const unsigned char *iv) {
  int outl;
  EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  if (!ctx) {
    printf("Cannot allocate needed memory\n");
    exit(EXIT_FAILURE);
  }
  memcpy(out, bimacro, (2 * (4 * 4096)));
  memxor(out, iv, 16);
  mixoaep_pad(out, buffer);
  EVP_EncryptInit(ctx, EVP_aes_128_ctr(), key, iv);
  EVP_CIPHER_CTX_set_padding(ctx, 0);
  EVP_EncryptUpdate(ctx, out, &outl, out, (2 * (4 * 4096)));
  if (0)
    assert((2 * (4 * 4096)) == outl);
  EVP_CIPHER_CTX_cleanup(ctx);
  EVP_CIPHER_CTX_free(ctx);
}


x86 assembly (clang, -O0):
<mixencrypt_bimacroblock_oaep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    $0x0,%al
call   10a0 <EVP_CIPHER_CTX_new@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    120c <mixencrypt_bimacroblock_oaep+0x4c>
lea    0xe07(%rip),%rdi
call   1040 <printf@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x8000,%edx
call   1080 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1030 <memxor@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <mixoaep_pad@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1050 <EVP_aes_128_ctr@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   10d0 <EVP_EncryptInit@plt>
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1090 <EVP_CIPHER_CTX_set_padding@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rcx
lea    -0x2c(%rbp),%rdx
mov    $0x8000,%r8d
call   1070 <EVP_EncryptUpdate@plt>
mov    -0x38(%rbp),%rdi
call   10e0 <EVP_CIPHER_CTX_cleanup@plt>
mov    -0x38(%rbp),%rdi
call   1060 <EVP_CIPHER_CTX_free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mixencrypt_bimacroblock_oaep>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%rbp
xor    %eax,%eax
call   10a0 <EVP_CIPHER_CTX_new@plt>
test   %rax,%rax
je     1271 <mixencrypt_bimacroblock_oaep+0xb1>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0x8000,%edx
call   1080 <memcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1040 <memxor@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   10b0 <mixoaep_pad@plt>
xor    %eax,%eax
call   1050 <EVP_aes_128_ctr@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r12,%rdx
mov    %r15,%rcx
call   10d0 <EVP_EncryptInit@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <EVP_CIPHER_CTX_set_padding@plt>
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r14,%rcx
mov    $0x8000,%r8d
call   1070 <EVP_EncryptUpdate@plt>
mov    %rbx,%rdi
call   10e0 <EVP_CIPHER_CTX_cleanup@plt>
mov    %rbx,%rdi
call   1060 <EVP_CIPHER_CTX_free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd88(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Cannot allocate needed memory\0A\00"
@EXIT_FAILURE = global i32 0
define void @mixencrypt_bimacroblock_oaep(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%13 = call i32* (...) @EVP_CIPHER_CTX_new()
store i32* %13, i32** %12
%14 = load i32*, i32** %12
%15 = icmp ne i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %5
%17 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %5
%21 = load i8*, i8** %7
%22 = load i8*, i8** %6
%23 = call i32 @memcpy(i8* %21, i8* %22, i32 32768)
%24 = load i8*, i8** %7
%25 = load i8*, i8** %10
%26 = call i32 @memxor(i8* %24, i8* %25, i32 16)
%27 = load i8*, i8** %7
%28 = load i8*, i8** %8
%29 = call i32 @mixoaep_pad(i8* %27, i8* %28)
%30 = load i32*, i32** %12
%31 = call i32 (...) @EVP_aes_128_ctr()
%32 = load i8*, i8** %9
%33 = load i8*, i8** %10
%34 = call i32 @EVP_EncryptInit(i32* %30, i32 %31, i8* %32, i8* %33)
%35 = load i32*, i32** %12
%36 = call i32 @EVP_CIPHER_CTX_set_padding(i32* %35, i32 0)
%37 = load i32*, i32** %12
%38 = load i8*, i8** %7
%39 = load i8*, i8** %7
%40 = call i32 @EVP_EncryptUpdate(i32* %37, i8* %38, i32* %11, i8* %39, i32 32768)
%41 = load i32*, i32** %12
%42 = call i32 @EVP_CIPHER_CTX_cleanup(i32* %41)
%43 = load i32*, i32** %12
%44 = call i32 @EVP_CIPHER_CTX_free(i32* %43)
ret void
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [30 x i8] c"Cannot allocate needed memory\00"
define void @mixencrypt_bimacroblock_oaep(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = tail call i32* (...) @EVP_CIPHER_CTX_new()
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %5
%15 = tail call i32 @memcpy(i8* %1, i8* %0, i32 32768)
%16 = tail call i32 @memxor(i8* %1, i8* %4, i32 16)
%17 = tail call i32 @mixoaep_pad(i8* %1, i8* %2)
%18 = tail call i32 (...) @EVP_aes_128_ctr()
%19 = tail call i32 @EVP_EncryptInit(i32* %8, i32 %18, i8* %3, i8* %4)
%20 = tail call i32 @EVP_CIPHER_CTX_set_padding(i32* %8, i32 0)
%21 = call i32 @EVP_EncryptUpdate(i32* %8, i8* %1, i32* %6, i8* %1, i32 32768)
%22 = call i32 @EVP_CIPHER_CTX_cleanup(i32* %8)
%23 = call i32 @EVP_CIPHER_CTX_free(i32* %8)
ret void
}