#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*/ AES_KEY;

/* Variables and functions */
int AES_BLOCK_SIZE;
int /*<<< orphan*/ AES_ENCRYPT;
int /*<<< orphan*/ AES_cbc_encrypt(unsigned char *, unsigned char *,
                                   unsigned int, int /*<<< orphan*/ *,
                                   unsigned char *, int /*<<< orphan*/);
scalar_t__ AES_set_encrypt_key(unsigned char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ base64encrypt(unsigned char *, unsigned int,
                                 unsigned char *);
scalar_t__ calloc(unsigned int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int strlen(unsigned char *);
int /*<<< orphan*/ strncpy(unsigned char *, unsigned char *, unsigned int);
int aesbase64encrypt(unsigned char *data, unsigned char *key,
                     unsigned char **out) {
  AES_KEY aes;
  unsigned char iv[AES_BLOCK_SIZE];
  unsigned char *input_string;
  unsigned char *encrypt_string;
  unsigned int string_len;
  unsigned int data_len;
  unsigned int bstr_len;
  unsigned int i;
  unsigned int pad;
  unsigned char tmp[3] = {'\0'};
  for (i = 0; i < AES_BLOCK_SIZE; ++i) {
    iv[i] = 0;
  }
  if (AES_set_encrypt_key(key, 128, &aes) < 0) {
    fprintf(stderr, "Unable to set encryption key in AES\n");
    return -1;
  }
  string_len = 0;
  if ((strlen(data) + 1) % AES_BLOCK_SIZE == 0) {
    string_len = strlen(data) + 1;
  } else {
    string_len = ((strlen(data) + 1) / AES_BLOCK_SIZE + 1) * AES_BLOCK_SIZE;
    pad = string_len - (strlen(data) + 1);
  }
  data_len = strlen(data);
  input_string = (unsigned char *)calloc(string_len, sizeof(unsigned char));
  if (input_string == NULL) {
    fprintf(stderr, "Unable to allocate memory for input_string\n");
    exit(-1);
  }
  strncpy(input_string, data, data_len);
  for (i = data_len; i < string_len; i++) {
    input_string[i] = pad;
  }
  printf("-DEBUG- input_string: \n");
  for (i = 0; i < string_len; i++) {
    printf("%02x ", input_string[i]);
  }
  printf("\n");
  encrypt_string = (unsigned char *)calloc(string_len, sizeof(unsigned char));
  if (encrypt_string == NULL) {
    fprintf(stderr, "Unable to allocate memory for encrypt_string\n");
    exit(-1);
  }
  AES_cbc_encrypt(input_string, encrypt_string, string_len, &aes,
                  (unsigned char *)iv, AES_ENCRYPT);
  bstr_len = (string_len / 3 + 1) * 4;
  *out = (unsigned char *)calloc(bstr_len, sizeof(unsigned char));
  if (*out == NULL) {
    fprintf(stderr, "Unable to allocate memory for out\n");
    exit(-1);
  }
  base64encrypt(encrypt_string, string_len, *out);
  free(encrypt_string);
  free(input_string);
  return 0;
}


x86 assembly (clang, -O0):
<aesbase64encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
lea    -0x5f(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1080 <memset@plt>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2dd4(%rip),%rcx
cmp    (%rcx),%eax
jae    1235 <aesbase64encrypt+0x85>
mov    -0x70(%rbp),%rax
mov    -0x58(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    120a <aesbase64encrypt+0x5a>
mov    -0x18(%rbp),%rdi
mov    $0x80,%esi
lea    -0x24(%rbp),%rdx
call   1050 <AES_set_encrypt_key@plt>
cmp    $0x0,%rax
jge    1279 <aesbase64encrypt+0xc9>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    14ba <aesbase64encrypt+0x30a>
movl   $0x0,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    0x2d55(%rip),%rcx
cltd
idivl  (%rcx)
cmp    $0x0,%edx
jne    12b3 <aesbase64encrypt+0x103>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    12f5 <aesbase64encrypt+0x145>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    0x2d22(%rip),%rcx
cltd
idivl  (%rcx)
add    $0x1,%eax
mov    0x2d15(%rip),%rcx
imul   (%rcx),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x74(%rbp),%eax
add    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x50(%rbp)
mov    -0x4c(%rbp),%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    133c <aesbase64encrypt+0x18c>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
lea    0xcf8(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x50(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x50(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jae    137b <aesbase64encrypt+0x1cb>
mov    -0x5c(%rbp),%eax
mov    %al,%dl
mov    -0x40(%rbp),%rax
mov    -0x58(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1352 <aesbase64encrypt+0x1a2>
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jae    13c3 <aesbase64encrypt+0x213>
mov    -0x40(%rbp),%rax
mov    -0x58(%rbp),%ecx
movzbl (%rax,%rcx,1),%esi
lea    0xcbb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1390 <aesbase64encrypt+0x1e0>
lea    0xc9d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x4c(%rbp),%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    140c <aesbase64encrypt+0x25c>
mov    0x2be4(%rip),%rax
mov    (%rax),%edi
lea    0xc72(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x70(%rbp),%r8
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x4c(%rbp),%edx
mov    0x2bae(%rip),%rax
mov    (%rax),%r9d
lea    -0x24(%rbp),%rcx
call   10a0 <AES_cbc_encrypt@plt>
mov    -0x4c(%rbp),%eax
mov    $0x3,%ecx
xor    %edx,%edx
div    %ecx
add    $0x1,%eax
shl    $0x2,%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1487 <aesbase64encrypt+0x2d7>
mov    0x2b69(%rip),%rax
mov    (%rax),%edi
lea    0xc25(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x48(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
call   10d0 <base64encrypt@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aesbase64encrypt>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%r13
mov    0x2df4(%rip),%rcx
mov    (%rcx),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%rcx),%edx
test   %rdx,%rdx
je     1218 <aesbase64encrypt+0x48>
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <memset@plt>
lea    -0x2c(%rbp),%rdx
mov    %r15,%rdi
mov    $0x80,%esi
call   1070 <AES_set_encrypt_key@plt>
test   %rax,%rax
js     128f <aesbase64encrypt+0xbf>
mov    %r12,-0x48(%rbp)
mov    %r13,-0x38(%rbp)
mov    %r14,%r13
mov    %r14,%rdi
call   1080 <strlen@plt>
add    $0x1,%eax
cltd
mov    0x2d9c(%rip),%r14
idivl  (%r14)
mov    %edx,%r15d
mov    %r13,%rdi
call   1080 <strlen@plt>
mov    %eax,%r12d
add    $0x1,%r12d
test   %r15d,%r15d
mov    %rbx,-0x40(%rbp)
je     12ae <aesbase64encrypt+0xde>
mov    (%r14),%ecx
mov    %r12d,%eax
cltd
idiv   %ecx
mov    %eax,%r12d
add    $0x1,%r12d
imul   %ecx,%r12d
mov    %r13,%rdi
call   1080 <strlen@plt>
mov    %eax,%ebx
not    %ebx
add    %r12d,%ebx
jmp    12ae <aesbase64encrypt+0xde>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xd61(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    13dc <aesbase64encrypt+0x20c>
mov    %r13,%rdi
call   1080 <strlen@plt>
mov    %eax,%r15d
mov    %r12d,%edi
mov    $0x1,%esi
call   10b0 <calloc@plt>
test   %rax,%rax
je     13ee <aesbase64encrypt+0x21e>
mov    %r13,%rsi
mov    %rax,%r13
mov    %rax,%rdi
mov    %r15d,%edx
call   1050 <strncpy@plt>
mov    %r12d,%r14d
cmp    %r12d,%r15d
jae    1314 <aesbase64encrypt+0x144>
mov    %r15d,%eax
mov    %r13,%rdi
add    %rax,%rdi
not    %r15d
add    %r12d,%r15d
add    $0x1,%r15
movzbl %bl,%esi
mov    %r15,%rdx
call   10a0 <memset@plt>
lea    0xd9b(%rip),%rdi
call   1060 <puts@plt>
jmp    1325 <aesbase64encrypt+0x155>
lea    0xd8d(%rip),%rdi
call   1060 <puts@plt>
test   %r12d,%r12d
je     1349 <aesbase64encrypt+0x179>
lea    0xd25(%rip),%r15
xor    %ebx,%ebx
xchg   %ax,%ax
movzbl 0x0(%r13,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1330 <aesbase64encrypt+0x160>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r12d,%edi
mov    $0x1,%esi
call   10b0 <calloc@plt>
test   %rax,%rax
je     1400 <aesbase64encrypt+0x230>
mov    %rax,%rbx
mov    0x2c5d(%rip),%rax
mov    (%rax),%r9d
lea    -0x2c(%rbp),%rcx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
mov    -0x40(%rbp),%r8
call   10c0 <AES_cbc_encrypt@plt>
mov    $0xaaaaaaab,%eax
imul   %r14,%rax
shr    $0x20,%rax
and    $0xfffffffe,%eax
lea    (%rax,%rax,1),%edi
add    $0x4,%edi
mov    $0x1,%esi
call   10b0 <calloc@plt>
mov    -0x48(%rbp),%rcx
mov    %rax,(%rcx)
test   %rax,%rax
je     1412 <aesbase64encrypt+0x242>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %rax,%rdx
call   10f0 <base64encrypt@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    -0x38(%rbp),%r13
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2be3(%rip),%rax
mov    (%rax),%edi
lea    0xc27(%rip),%rsi
jmp    1422 <aesbase64encrypt+0x252>
mov    0x2bd1(%rip),%rax
mov    (%rax),%edi
lea    0xc47(%rip),%rsi
jmp    1422 <aesbase64encrypt+0x252>
mov    0x2bbf(%rip),%rax
mov    (%rax),%edi
lea    0xc63(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@AES_BLOCK_SIZE = global i32 0
@stderr = global i32 0
@.str = [37 x i8] c"Unable to set encryption key in AES\0A\00"
@.str.1 = [44 x i8] c"Unable to allocate memory for input_string\0A\00"
@.str.2 = [24 x i8] c"-DEBUG- input_string: \0A\00"
@.str.3 = [6 x i8] c"%02x \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [46 x i8] c"Unable to allocate memory for encrypt_string\0A\00"
@AES_ENCRYPT = global i32 0
@.str.6 = [35 x i8] c"Unable to allocate memory for out\0A\00"
define i32 @aesbase64encrypt(i8* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca [3 x i8]
%19 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%20 = load i32, i32* @AES_BLOCK_SIZE
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %9
%23 = alloca i8, i64 %21
store i64 %21, i64* %10
%24 = bitcast [3 x i8]* %18 to i8*
store i32 0, i32* %16
br label %25
25: ; preds = %33, %3
%26 = load i32, i32* %16
%27 = load i32, i32* @AES_BLOCK_SIZE
%28 = icmp ult i32 %26, %27
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = load i32, i32* %16
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %23, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %29
%34 = load i32, i32* %16
%35 = add i32 %34, 1
store i32 %35, i32* %16
br label %25
36: ; preds = %25
%37 = load i8*, i8** %6
%38 = call i64 @AES_set_encrypt_key(i8* %37, i32 128, i32* %8)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
store i32 1, i32* %19
br label %159
43: ; preds = %36
store i32 0, i32* %13
%44 = load i8*, i8** %5
%45 = call i32 @strlen(i8* %44)
%46 = add nsw i32 %45, 1
%47 = load i32, i32* @AES_BLOCK_SIZE
%48 = srem i32 %46, %47
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %43
%51 = load i8*, i8** %5
%52 = call i32 @strlen(i8* %51)
%53 = add nsw i32 %52, 1
store i32 %53, i32* %13
br label %68
54: ; preds = %43
%55 = load i8*, i8** %5
%56 = call i32 @strlen(i8* %55)
%57 = add nsw i32 %56, 1
%58 = load i32, i32* @AES_BLOCK_SIZE
%59 = sdiv i32 %57, %58
%60 = add nsw i32 %59, 1
%61 = load i32, i32* @AES_BLOCK_SIZE
%62 = mul nsw i32 %60, %61
store i32 %62, i32* %13
%63 = load i32, i32* %13
%64 = load i8*, i8** %5
%65 = call i32 @strlen(i8* %64)
%66 = add nsw i32 %65, 1
%67 = sub i32 %63, %66
store i32 %67, i32* %17
br label %68
68: ; preds = %54, %50
%69 = load i8*, i8** %5
%70 = call i32 @strlen(i8* %69)
store i32 %70, i32* %14
%71 = load i32, i32* %13
%72 = call i64 @calloc(i32 %71, i32 1)
%73 = inttoptr i64 %72 to i8*
store i8* %73, i8** %11
%74 = load i8*, i8** %11
%75 = icmp eq i8* %74, null
br i1 %75, label %76, label %80
76: ; preds = %68
%77 = load i32, i32* @stderr
%78 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%79 = call i32 @exit(i32 -1)
unreachable
80: ; preds = %68
%81 = load i8*, i8** %11
%82 = load i8*, i8** %5
%83 = load i32, i32* %14
%84 = call i32 @strncpy(i8* %81, i8* %82, i32 %83)
%85 = load i32, i32* %14
store i32 %85, i32* %16
br label %86
86: ; preds = %97, %80
%87 = load i32, i32* %16
%88 = load i32, i32* %13
%89 = icmp ult i32 %87, %88
br i1 %89, label %90, label %100
90: ; preds = %86
%91 = load i32, i32* %17
%92 = trunc i32 %91 to i8
%93 = load i8*, i8** %11
%94 = load i32, i32* %16
%95 = zext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %93, i64 %95
store i8 %92, i8* %96
br label %97
97: ; preds = %90
%98 = load i32, i32* %16
%99 = add i32 %98, 1
store i32 %99, i32* %16
br label %86
100: ; preds = %86
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %16
br label %102
102: ; preds = %114, %100
%103 = load i32, i32* %16
%104 = load i32, i32* %13
%105 = icmp ult i32 %103, %104
br i1 %105, label %106, label %117
106: ; preds = %102
%107 = load i8*, i8** %11
%108 = load i32, i32* %16
%109 = zext i32 %108 to i64
%110 = getelementptr inbounds i8, i8* %107, i64 %109
%111 = load i8, i8* %110
%112 = zext i8 %111 to i32
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %112)
br label %114
114: ; preds = %106
%115 = load i32, i32* %16
%116 = add i32 %115, 1
store i32 %116, i32* %16
br label %102
117: ; preds = %102
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%119 = load i32, i32* %13
%120 = call i64 @calloc(i32 %119, i32 1)
%121 = inttoptr i64 %120 to i8*
store i8* %121, i8** %12
%122 = load i8*, i8** %12
%123 = icmp eq i8* %122, null
br i1 %123, label %124, label %128
124: ; preds = %117
%125 = load i32, i32* @stderr
%126 = call i32 @fprintf(i32 %125, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
%127 = call i32 @exit(i32 -1)
unreachable
128: ; preds = %117
%129 = load i8*, i8** %11
%130 = load i8*, i8** %12
%131 = load i32, i32* %13
%132 = load i32, i32* @AES_ENCRYPT
%133 = call i32 @AES_cbc_encrypt(i8* %129, i8* %130, i32 %131, i32* %8, i8* %23, i32 %132)
%134 = load i32, i32* %13
%135 = udiv i32 %134, 3
%136 = add i32 %135, 1
%137 = mul i32 %136, 4
store i32 %137, i32* %15
%138 = load i32, i32* %15
%139 = call i64 @calloc(i32 %138, i32 1)
%140 = inttoptr i64 %139 to i8*
%141 = load i8**, i8*** %7
store i8* %140, i8** %141
%142 = load i8**, i8*** %7
%143 = load i8*, i8** %142
%144 = icmp eq i8* %143, null
br i1 %144, label %145, label %149
145: ; preds = %128
%146 = load i32, i32* @stderr
%147 = call i32 @fprintf(i32 %146, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
%148 = call i32 @exit(i32 -1)
unreachable
149: ; preds = %128
%150 = load i8*, i8** %12
%151 = load i32, i32* %13
%152 = load i8**, i8*** %7
%153 = load i8*, i8** %152
%154 = call i32 @base64encrypt(i8* %150, i32 %151, i8* %153)
%155 = load i8*, i8** %12
%156 = call i32 @free(i8* %155)
%157 = load i8*, i8** %11
%158 = call i32 @free(i8* %157)
store i32 0, i32* %4
store i32 1, i32* %19
br label %159
159: ; preds = %149, %40
%160 = load i8*, i8** %9
%161 = load i32, i32* %4
ret i32 %161
}

LLVM IR (-O2):
@AES_BLOCK_SIZE = global i32 0
@stderr = global i32 0
@.str = [37 x i8] c"Unable to set encryption key in AES\0A\00"
@.str.1 = [44 x i8] c"Unable to allocate memory for input_string\0A\00"
@.str.3 = [6 x i8] c"%02x \00"
@.str.5 = [46 x i8] c"Unable to allocate memory for encrypt_string\0A\00"
@AES_ENCRYPT = global i32 0
@.str.6 = [35 x i8] c"Unable to allocate memory for out\0A\00"
@str = [23 x i8] c"-DEBUG- input_string: \00"
define i32 @aesbase64encrypt(i8* %0, i8* %1, i8** nocapture writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = load i32, i32* @AES_BLOCK_SIZE
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = load i32, i32* @AES_BLOCK_SIZE
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = zext i32 %10 to i64
br label %14
14: ; preds = %12, %3
%15 = call i64 @AES_set_encrypt_key(i8* %1, i32 128, i32* %4)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %98
20: ; preds = %14
%21 = call i32 @strlen(i8* %0)
%22 = add nsw i32 %21, 1
%23 = load i32, i32* @AES_BLOCK_SIZE
%24 = srem i32 %22, %23
%25 = icmp eq i32 %24, 0
%26 = call i32 @strlen(i8* %0)
%27 = add nsw i32 %26, 1
br i1 %25, label %37, label %28
28: ; preds = %20
%29 = load i32, i32* @AES_BLOCK_SIZE
%30 = sdiv i32 %27, %29
%31 = add nsw i32 %30, 1
%32 = mul nsw i32 %31, %29
%33 = call i32 @strlen(i8* %0)
%34 = xor i32 %33, -1
%35 = add i32 %32, %34
%36 = trunc i32 %35 to i8
br label %37
37: ; preds = %20, %28
%38 = phi i32 [ %32, %28 ], [ %27, %20 ]
%39 = phi i8 [ %36, %28 ], [ undef, %20 ]
%40 = call i32 @strlen(i8* %0)
%41 = call i64 @calloc(i32 %38, i32 1)
%42 = inttoptr i64 %41 to i8*
%43 = icmp eq i64 %41, 0
br i1 %43, label %44, label %48
44: ; preds = %37
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @exit(i32 -1)
unreachable
48: ; preds = %37
%49 = call i32 @strncpy(i8* %42, i8* %0, i32 %40)
%50 = icmp ult i32 %40, %38
br i1 %50, label %51, label %59
51: ; preds = %48
%52 = zext i32 %40 to i64
%53 = getelementptr i8, i8* %42, i64 %52
%54 = xor i32 %40, -1
%55 = add i32 %38, %54
%56 = zext i32 %55 to i64
%57 = add nuw nsw i64 %56, 1
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %62
59: ; preds = %48
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%61 = icmp eq i32 %38, 0
br i1 %61, label %72, label %62
62: ; preds = %51, %59
%63 = zext i32 %38 to i64
br label %64
64: ; preds = %62, %64
%65 = phi i64 [ 0, %62 ], [ %70, %64 ]
%66 = getelementptr inbounds i8, i8* %42, i64 %65
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %68)
%70 = add nuw nsw i64 %65, 1
%71 = icmp eq i64 %70, %63
br i1 %71, label %72, label %64
72: ; preds = %64, %59
%73 = call i32 @putchar(i32 10)
%74 = call i64 @calloc(i32 %38, i32 1)
%75 = inttoptr i64 %74 to i8*
%76 = icmp eq i64 %74, 0
br i1 %76, label %77, label %81
77: ; preds = %72
%78 = load i32, i32* @stderr
%79 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
%80 = call i32 @exit(i32 -1)
unreachable
81: ; preds = %72
%82 = load i32, i32* @AES_ENCRYPT
%83 = call i32 @AES_cbc_encrypt(i8* %42, i8* %75, i32 %38, i32* %4, i8* %9, i32 %82)
%84 = udiv i32 %38, 3
%85 = shl i32 %84, 2
%86 = add i32 %85, 4
%87 = call i64 @calloc(i32 %86, i32 1)
%88 = inttoptr i64 %87 to i8*
store i8* %88, i8** %2
%89 = icmp eq i64 %87, 0
br i1 %89, label %90, label %94
90: ; preds = %81
%91 = load i32, i32* @stderr
%92 = call i32 @fprintf(i32 %91, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
%93 = call i32 @exit(i32 -1)
unreachable
94: ; preds = %81
%95 = call i32 @base64encrypt(i8* %75, i32 %38, i8* %88)
%96 = call i32 @free(i8* %75)
%97 = call i32 @free(i8* %42)
br label %98
98: ; preds = %94, %17
%99 = phi i32 [ -1, %17 ], [ 0, %94 ]
ret i32 %99
}