#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 const *, int);
int /*<<< orphan*/ EVP_aes_128_ecb();
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ do_step_encrypt(int /*<<< orphan*/ *, unsigned char *,
                                   unsigned char *, unsigned char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ log2(int);
int /*<<< orphan*/ memxor(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ printf(char *);
void mixencrypt_macroblock(const unsigned char *macro, unsigned char *out,
                           unsigned char *buffer, const unsigned char *key,
                           const unsigned char *iv) {
  int step, outl;
  EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  if (NULL == ctx) {
    printf("Cannot allocate needed memory\n");
    exit(EXIT_FAILURE);
  }
  EVP_EncryptInit(ctx, EVP_aes_128_ecb(), key, iv);
  EVP_CIPHER_CTX_set_padding(ctx, 0);
  memxor((unsigned char *)macro, iv, 16);
  EVP_EncryptUpdate(ctx, out, &outl, macro, (4 * 1024));
  memxor((unsigned char *)macro, iv, 16);
  if (0)
    assert((4 * 1024) == outl);
  for (step = 1; step < ((int)log2(1024)) / ((int)log2((16 / 4))); ++step) {
    do_step_encrypt(ctx, buffer, out, out, step);
  }
  EVP_CIPHER_CTX_cleanup(ctx);
  EVP_CIPHER_CTX_free(ctx);
}


x86 assembly (clang, -O0):
<mixencrypt_macroblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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   10b0 <EVP_CIPHER_CTX_new@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    120d <mixencrypt_macroblock+0x4d>
lea    0xe06(%rip),%rdi
call   1050 <printf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1080 <EVP_aes_128_ecb@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   10a0 <EVP_CIPHER_CTX_set_padding@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memxor@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rcx
lea    -0x30(%rbp),%rdx
mov    $0x1000,%r8d
call   1070 <EVP_EncryptUpdate@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memxor@plt>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    $0x400,%edi
call   1030 <log2@plt>
mov    %eax,-0x48(%rbp)
mov    $0x4,%edi
call   1030 <log2@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
jge    12da <mixencrypt_macroblock+0x11a>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
call   1090 <do_step_encrypt@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1280 <mixencrypt_macroblock+0xc0>
mov    -0x38(%rbp),%rdi
call   10e0 <EVP_CIPHER_CTX_cleanup@plt>
mov    -0x38(%rbp),%rdi
call   1060 <EVP_CIPHER_CTX_free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mixencrypt_macroblock>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %rcx,%rbp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r13
xor    %eax,%eax
call   10b0 <EVP_CIPHER_CTX_new@plt>
test   %rax,%rax
je     12c9 <mixencrypt_macroblock+0x109>
mov    %rax,%r15
xor    %eax,%eax
call   1080 <EVP_aes_128_ecb@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbp,%rdx
mov    %rbx,%rcx
call   10d0 <EVP_EncryptInit@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   10a0 <EVP_CIPHER_CTX_set_padding@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memxor@plt>
lea    0x4(%rsp),%rdx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rcx
mov    $0x1000,%r8d
call   1070 <EVP_EncryptUpdate@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memxor@plt>
mov    $0x400,%edi
call   1030 <log2@plt>
mov    %rax,%rbp
mov    $0x4,%edi
call   1030 <log2@plt>
mov    %rax,%rcx
mov    %ebp,%eax
cltd
idiv   %ecx
cmp    $0x2,%eax
jl     12aa <mixencrypt_macroblock+0xea>
mov    $0x1,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %r12,%rcx
mov    %ebp,%r8d
call   1090 <do_step_encrypt@plt>
add    $0x1,%ebp
mov    $0x400,%edi
call   1030 <log2@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1030 <log2@plt>
mov    %rax,%rcx
mov    %ebx,%eax
cltd
idiv   %ecx
cmp    %eax,%ebp
jl     1270 <mixencrypt_macroblock+0xb0>
mov    %r15,%rdi
call   10e0 <EVP_CIPHER_CTX_cleanup@plt>
mov    %r15,%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    0xd30(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d04(%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_macroblock(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
%13 = 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
%14 = call i32* (...) @EVP_CIPHER_CTX_new()
store i32* %14, i32** %13
%15 = load i32*, i32** %13
%16 = icmp eq i32* null, %15
br i1 %16, label %17, label %21
17: ; preds = %5
%18 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %5
%22 = load i32*, i32** %13
%23 = call i32 (...) @EVP_aes_128_ecb()
%24 = load i8*, i8** %9
%25 = load i8*, i8** %10
%26 = call i32 @EVP_EncryptInit(i32* %22, i32 %23, i8* %24, i8* %25)
%27 = load i32*, i32** %13
%28 = call i32 @EVP_CIPHER_CTX_set_padding(i32* %27, i32 0)
%29 = load i8*, i8** %6
%30 = load i8*, i8** %10
%31 = call i32 @memxor(i8* %29, i8* %30, i32 16)
%32 = load i32*, i32** %13
%33 = load i8*, i8** %7
%34 = load i8*, i8** %6
%35 = call i32 @EVP_EncryptUpdate(i32* %32, i8* %33, i32* %12, i8* %34, i32 4096)
%36 = load i8*, i8** %6
%37 = load i8*, i8** %10
%38 = call i32 @memxor(i8* %36, i8* %37, i32 16)
store i32 1, i32* %11
br label %39
39: ; preds = %54, %21
%40 = load i32, i32* %11
%41 = call i64 @log2(i32 1024)
%42 = trunc i64 %41 to i32
%43 = call i64 @log2(i32 4)
%44 = trunc i64 %43 to i32
%45 = sdiv i32 %42, %44
%46 = icmp slt i32 %40, %45
br i1 %46, label %47, label %57
47: ; preds = %39
%48 = load i32*, i32** %13
%49 = load i8*, i8** %8
%50 = load i8*, i8** %7
%51 = load i8*, i8** %7
%52 = load i32, i32* %11
%53 = call i32 @do_step_encrypt(i32* %48, i8* %49, i8* %50, i8* %51, i32 %52)
br label %54
54: ; preds = %47
%55 = load i32, i32* %11
%56 = add nsw i32 %55, 1
store i32 %56, i32* %11
br label %39
57: ; preds = %39
%58 = load i32*, i32** %13
%59 = call i32 @EVP_CIPHER_CTX_cleanup(i32* %58)
%60 = load i32*, i32** %13
%61 = call i32 @EVP_CIPHER_CTX_free(i32* %60)
ret void
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [30 x i8] c"Cannot allocate needed memory\00"
define void @mixencrypt_macroblock(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_ecb()
%16 = tail call i32 @EVP_EncryptInit(i32* %8, i32 %15, i8* %3, i8* %4)
%17 = tail call i32 @EVP_CIPHER_CTX_set_padding(i32* %8, i32 0)
%18 = tail call i32 @memxor(i8* %0, i8* %4, i32 16)
%19 = call i32 @EVP_EncryptUpdate(i32* %8, i8* %1, i32* %6, i8* %0, i32 4096)
%20 = call i32 @memxor(i8* %0, i8* %4, i32 16)
%21 = call i64 @log2(i32 1024)
%22 = trunc i64 %21 to i32
%23 = call i64 @log2(i32 4)
%24 = trunc i64 %23 to i32
%25 = sdiv i32 %22, %24
%26 = icmp sgt i32 %25, 1
br i1 %26, label %27, label %37
27: ; preds = %14, %27
%28 = phi i32 [ %30, %27 ], [ 1, %14 ]
%29 = call i32 @do_step_encrypt(i32* %8, i8* %2, i8* %1, i8* %1, i32 %28)
%30 = add nuw nsw i32 %28, 1
%31 = call i64 @log2(i32 1024)
%32 = trunc i64 %31 to i32
%33 = call i64 @log2(i32 4)
%34 = trunc i64 %33 to i32
%35 = sdiv i32 %32, %34
%36 = icmp slt i32 %30, %35
br i1 %36, label %27, label %37
37: ; preds = %27, %14
%38 = call i32 @EVP_CIPHER_CTX_cleanup(i32* %8)
%39 = call i32 @EVP_CIPHER_CTX_free(i32* %8)
ret void
}