#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_DecryptInit(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                   unsigned char const *,
                                   unsigned char const *);
int /*<<< orphan*/ EVP_DecryptUpdate(int /*<<< orphan*/ *, unsigned char *,
                                     int *, unsigned char const *, int);
int /*<<< orphan*/ EVP_aes_128_ctr();
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memxor(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ mixoaep_unpad(unsigned char *, unsigned char *);
int /*<<< orphan*/ printf(char *);
void mixdecrypt_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);
  }
  EVP_DecryptInit(ctx, EVP_aes_128_ctr(), key, iv);
  EVP_CIPHER_CTX_set_padding(ctx, 0);
  EVP_DecryptUpdate(ctx, out, &outl, bimacro, (2 * (4 * 4096)));
  if (0)
    assert((2 * (4 * 4096)) == outl);
  EVP_CIPHER_CTX_cleanup(ctx);
  EVP_CIPHER_CTX_free(ctx);
  mixoaep_unpad(out, buffer);
  memxor(out, iv, 16);
}


x86 assembly (clang, -O0):
<mixdecrypt_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    11fc <mixdecrypt_bimacroblock_oaep+0x4c>
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1060 <EVP_aes_128_ctr@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <EVP_DecryptInit@plt>
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1080 <EVP_CIPHER_CTX_set_padding@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rcx
lea    -0x2c(%rbp),%rdx
mov    $0x8000,%r8d
call   10b0 <EVP_DecryptUpdate@plt>
mov    -0x38(%rbp),%rdi
call   10d0 <EVP_CIPHER_CTX_cleanup@plt>
mov    -0x38(%rbp),%rdi
call   1070 <EVP_CIPHER_CTX_free@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <mixoaep_unpad@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1030 <memxor@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mixdecrypt_bimacroblock_oaep>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%rbp
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
xor    %eax,%eax
call   10a0 <EVP_CIPHER_CTX_new@plt>
test   %rax,%rax
je     124d <mixdecrypt_bimacroblock_oaep+0x9d>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <EVP_aes_128_ctr@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1050 <EVP_DecryptInit@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <EVP_CIPHER_CTX_set_padding@plt>
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rcx
mov    $0x8000,%r8d
call   10b0 <EVP_DecryptUpdate@plt>
mov    %rbx,%rdi
call   10d0 <EVP_CIPHER_CTX_cleanup@plt>
mov    %rbx,%rdi
call   1070 <EVP_CIPHER_CTX_free@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1090 <mixoaep_unpad@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1040 <memxor@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdac(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d80(%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 @mixdecrypt_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 i32*, i32** %12
%22 = call i32 (...) @EVP_aes_128_ctr()
%23 = load i8*, i8** %9
%24 = load i8*, i8** %10
%25 = call i32 @EVP_DecryptInit(i32* %21, i32 %22, i8* %23, i8* %24)
%26 = load i32*, i32** %12
%27 = call i32 @EVP_CIPHER_CTX_set_padding(i32* %26, i32 0)
%28 = load i32*, i32** %12
%29 = load i8*, i8** %7
%30 = load i8*, i8** %6
%31 = call i32 @EVP_DecryptUpdate(i32* %28, i8* %29, i32* %11, i8* %30, i32 32768)
%32 = load i32*, i32** %12
%33 = call i32 @EVP_CIPHER_CTX_cleanup(i32* %32)
%34 = load i32*, i32** %12
%35 = call i32 @EVP_CIPHER_CTX_free(i32* %34)
%36 = load i8*, i8** %7
%37 = load i8*, i8** %8
%38 = call i32 @mixoaep_unpad(i8* %36, i8* %37)
%39 = load i8*, i8** %7
%40 = load i8*, i8** %10
%41 = call i32 @memxor(i8* %39, i8* %40, i32 16)
ret void
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [30 x i8] c"Cannot allocate needed memory\00"
define void @mixdecrypt_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 (...) @EVP_aes_128_ctr()
%16 = tail call i32 @EVP_DecryptInit(i32* %8, i32 %15, i8* %3, i8* %4)
%17 = tail call i32 @EVP_CIPHER_CTX_set_padding(i32* %8, i32 0)
%18 = call i32 @EVP_DecryptUpdate(i32* %8, i8* %1, i32* %6, i8* %0, i32 32768)
%19 = call i32 @EVP_CIPHER_CTX_cleanup(i32* %8)
%20 = call i32 @EVP_CIPHER_CTX_free(i32* %8)
%21 = call i32 @mixoaep_unpad(i8* %1, i8* %2)
%22 = call i32 @memxor(i8* %1, i8* %4, i32 16)
ret void
}