#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*/ *);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(unsigned char *, char *, unsigned char,
                           unsigned char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(unsigned char *, unsigned char *);
int strlen(unsigned char *);
int /*<<< orphan*/ strncpy(unsigned char *, unsigned char *, unsigned int);
int aescbcencrypt(unsigned char *data, unsigned char *key, unsigned char **out,
                  unsigned int *out_len) {
  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 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("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);
  }
  *out = (unsigned char *)calloc(2 * string_len, sizeof(unsigned char));
  if (*out == NULL) {
    fprintf(stderr, "Unable to allocate memory for out\n");
    exit(-1);
  }
  AES_cbc_encrypt(input_string, encrypt_string, string_len, &aes,
                  (unsigned char *)iv, AES_ENCRYPT);
  *out_len = string_len;
  for (i = 0; i < string_len; ++i) {
    sprintf(tmp, "%x%x", (encrypt_string[i] >> 4) & 0xf,
            encrypt_string[i] & 0xf);
    strcat(*out, tmp);
  }
  free(encrypt_string);
  free(input_string);
  return 0;
}


x86 assembly (clang, -O0):
<aescbcencrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%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,-0x40(%rbp)
lea    -0x63(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1080 <memset@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    0x2dc0(%rip),%rcx
cmp    (%rcx),%eax
jae    1249 <aescbcencrypt+0x89>
mov    -0x70(%rbp),%rax
mov    -0x5c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    121e <aescbcencrypt+0x5e>
mov    -0x18(%rbp),%rdi
mov    $0x80,%esi
lea    -0x2c(%rbp),%rdx
call   1050 <AES_set_encrypt_key@plt>
cmp    $0x0,%rax
jge    128d <aescbcencrypt+0xcd>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xd8b(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    151a <aescbcencrypt+0x35a>
movl   $0x0,-0x54(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    0x2d41(%rip),%rcx
cltd
idivl  (%rcx)
cmp    $0x0,%edx
jne    12c7 <aescbcencrypt+0x107>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1309 <aescbcencrypt+0x149>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    0x2d0e(%rip),%rcx
cltd
idivl  (%rcx)
add    $0x1,%eax
mov    0x2d01(%rip),%rcx
imul   (%rcx),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%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,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1350 <aescbcencrypt+0x190>
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
lea    0xce4(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x58(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x58(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x54(%rbp),%eax
jae    138f <aescbcencrypt+0x1cf>
mov    -0x60(%rbp),%eax
mov    %al,%dl
mov    -0x48(%rbp),%rax
mov    -0x5c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1366 <aescbcencrypt+0x1a6>
lea    0xcbb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x54(%rbp),%eax
jae    13d7 <aescbcencrypt+0x217>
mov    -0x48(%rbp),%rax
mov    -0x5c(%rbp),%ecx
movzbl (%rax,%rcx,1),%esi
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    13a4 <aescbcencrypt+0x1e4>
lea    0xc81(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x54(%rbp),%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1420 <aescbcencrypt+0x260>
mov    0x2bd0(%rip),%rax
mov    (%rax),%edi
lea    0xc56(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x54(%rbp),%edi
shl    $0x1,%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    1467 <aescbcencrypt+0x2a7>
mov    0x2b89(%rip),%rax
mov    (%rax),%edi
lea    0xc3d(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x70(%rbp),%r8
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
mov    0x2b53(%rip),%rax
mov    (%rax),%r9d
lea    -0x2c(%rbp),%rcx
call   10a0 <AES_cbc_encrypt@plt>
mov    -0x54(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x54(%rbp),%eax
jae    14fa <aescbcencrypt+0x33a>
lea    -0x63(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    -0x5c(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
and    $0xf,%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    -0x5c(%rbp),%edx
movzbl (%rax,%rdx,1),%eax
and    $0xf,%eax
lea    0xbe7(%rip),%rsi
movzbl %cl,%edx
movzbl %al,%ecx
call   10d0 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    -0x63(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1499 <aescbcencrypt+0x2d9>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x68(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aescbcencrypt>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,-0x68(%rbp)
mov    %rdx,-0x48(%rbp)
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsp,%rbx
mov    0x2ddf(%rip),%r14
mov    (%r14),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
movb   $0x0,-0x2a(%rbp)
movw   $0x0,-0x2c(%rbp)
mov    (%r14),%edx
test   %rdx,%rdx
je     1239 <aescbcencrypt+0x59>
mov    %r13,%rdi
xor    %esi,%esi
call   10a0 <memset@plt>
lea    -0x3c(%rbp),%rdx
mov    %r12,%rdi
mov    $0x80,%esi
call   1070 <AES_set_encrypt_key@plt>
test   %rax,%rax
js     1298 <aescbcencrypt+0xb8>
mov    %rbx,-0x58(%rbp)
mov    %r15,%r12
mov    %r15,%rdi
call   1080 <strlen@plt>
add    $0x1,%eax
cltd
idivl  (%r14)
mov    %edx,%r15d
mov    %r12,%rdi
call   1080 <strlen@plt>
mov    %eax,%ebx
add    $0x1,%ebx
test   %r15d,%r15d
je     12b7 <aescbcencrypt+0xd7>
mov    (%r14),%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%ebx
add    $0x1,%ebx
imul   %ecx,%ebx
mov    %r12,%rdi
call   1080 <strlen@plt>
not    %eax
add    %ebx,%eax
jmp    12b7 <aescbcencrypt+0xd7>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    143a <aescbcencrypt+0x25a>
mov    %eax,-0x30(%rbp)
mov    %r13,-0x50(%rbp)
mov    %r12,%rdi
call   1080 <strlen@plt>
mov    %eax,%r14d
mov    %ebx,%edi
mov    $0x1,%esi
call   10b0 <calloc@plt>
test   %rax,%rax
je     1454 <aescbcencrypt+0x274>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1050 <strncpy@plt>
mov    %ebx,%r13d
cmp    %ebx,%r14d
mov    %r15,-0x38(%rbp)
mov    %rbx,-0x60(%rbp)
jae    132c <aescbcencrypt+0x14c>
mov    %r14d,%eax
add    %rax,%r15
not    %r14d
add    %ebx,%r14d
add    $0x1,%r14
movzbl -0x30(%rbp),%esi
mov    %r15,%rdi
mov    %r14,%rdx
call   10a0 <memset@plt>
lea    0xd88(%rip),%rdi
call   1060 <puts@plt>
jmp    1340 <aescbcencrypt+0x160>
lea    0xd7a(%rip),%rdi
call   1060 <puts@plt>
test   %ebx,%ebx
je     144c <aescbcencrypt+0x26c>
xor    %ebx,%ebx
lea    0xd08(%rip),%r14
mov    -0x38(%rbp),%r12
xor    %r15d,%r15d
movzbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1350 <aescbcencrypt+0x170>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    -0x60(%rbp),%rbx
mov    %ebx,%edi
mov    $0x1,%esi
call   10b0 <calloc@plt>
test   %rax,%rax
je     1466 <aescbcencrypt+0x286>
mov    %rax,%r12
lea    (%rbx,%rbx,1),%edi
mov    $0x1,%esi
call   10b0 <calloc@plt>
mov    -0x48(%rbp),%rcx
mov    %rax,(%rcx)
test   %rax,%rax
je     1478 <aescbcencrypt+0x298>
mov    0x2c1e(%rip),%rax
mov    (%rax),%r9d
lea    -0x3c(%rbp),%rcx
mov    -0x38(%rbp),%rdi
mov    %r12,%rsi
mov    %ebx,%edx
mov    -0x50(%rbp),%r8
call   10c0 <AES_cbc_encrypt@plt>
mov    -0x68(%rbp),%rax
mov    %ebx,(%rax)
test   %r15b,%r15b
mov    -0x48(%rbp),%r15
jne    1423 <aescbcencrypt+0x243>
xor    %r14d,%r14d
lea    -0x2c(%rbp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%r14,1),%ecx
mov    %ecx,%eax
shr    $0x4,%al
and    $0xf,%ecx
movzbl %al,%edx
mov    %rbx,%rdi
lea    0xc9e(%rip),%rsi
call   10f0 <sprintf@plt>
mov    (%r15),%rdi
mov    %rbx,%rsi
call   10e0 <strcat@plt>
add    $0x1,%r14
cmp    %r14,%r13
jne    13f0 <aescbcencrypt+0x210>
mov    %r12,%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    -0x58(%rbp),%rbx
mov    %rbx,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r15b
jmp    1368 <aescbcencrypt+0x188>
mov    0x2b7d(%rip),%rax
mov    (%rax),%edi
lea    0xbc1(%rip),%rsi
jmp    1488 <aescbcencrypt+0x2a8>
mov    0x2b6b(%rip),%rax
mov    (%rax),%edi
lea    0xbe1(%rip),%rsi
jmp    1488 <aescbcencrypt+0x2a8>
mov    0x2b59(%rip),%rax
mov    (%rax),%edi
lea    0xbfd(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1100 <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 = [16 x i8] c"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"
@.str.6 = [35 x i8] c"Unable to allocate memory for out\0A\00"
@AES_ENCRYPT = global i32 0
@.str.7 = [5 x i8] c"%x%x\00"
define i32 @aescbcencrypt(i8* %0, i8* %1, i8** %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca [3 x i8]
%20 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8** %2, i8*** %8
store i32* %3, i32** %9
%21 = load i32, i32* @AES_BLOCK_SIZE
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %11
%24 = alloca i8, i64 %22
store i64 %22, i64* %12
%25 = bitcast [3 x i8]* %19 to i8*
store i32 0, i32* %17
br label %26
26: ; preds = %34, %4
%27 = load i32, i32* %17
%28 = load i32, i32* @AES_BLOCK_SIZE
%29 = icmp ult i32 %27, %28
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = load i32, i32* %17
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %24, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %30
%35 = load i32, i32* %17
%36 = add i32 %35, 1
store i32 %36, i32* %17
br label %26
37: ; preds = %26
%38 = load i8*, i8** %7
%39 = call i64 @AES_set_encrypt_key(i8* %38, i32 128, i32* %10)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
store i32 1, i32* %20
br label %186
44: ; preds = %37
store i32 0, i32* %15
%45 = load i8*, i8** %6
%46 = call i32 @strlen(i8* %45)
%47 = add nsw i32 %46, 1
%48 = load i32, i32* @AES_BLOCK_SIZE
%49 = srem i32 %47, %48
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %44
%52 = load i8*, i8** %6
%53 = call i32 @strlen(i8* %52)
%54 = add nsw i32 %53, 1
store i32 %54, i32* %15
br label %69
55: ; preds = %44
%56 = load i8*, i8** %6
%57 = call i32 @strlen(i8* %56)
%58 = add nsw i32 %57, 1
%59 = load i32, i32* @AES_BLOCK_SIZE
%60 = sdiv i32 %58, %59
%61 = add nsw i32 %60, 1
%62 = load i32, i32* @AES_BLOCK_SIZE
%63 = mul nsw i32 %61, %62
store i32 %63, i32* %15
%64 = load i32, i32* %15
%65 = load i8*, i8** %6
%66 = call i32 @strlen(i8* %65)
%67 = add nsw i32 %66, 1
%68 = sub i32 %64, %67
store i32 %68, i32* %18
br label %69
69: ; preds = %55, %51
%70 = load i8*, i8** %6
%71 = call i32 @strlen(i8* %70)
store i32 %71, i32* %16
%72 = load i32, i32* %15
%73 = call i64 @calloc(i32 %72, i32 1)
%74 = inttoptr i64 %73 to i8*
store i8* %74, i8** %13
%75 = load i8*, i8** %13
%76 = icmp eq i8* %75, null
br i1 %76, label %77, label %81
77: ; preds = %69
%78 = load i32, i32* @stderr
%79 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%80 = call i32 @exit(i32 -1)
unreachable
81: ; preds = %69
%82 = load i8*, i8** %13
%83 = load i8*, i8** %6
%84 = load i32, i32* %16
%85 = call i32 @strncpy(i8* %82, i8* %83, i32 %84)
%86 = load i32, i32* %16
store i32 %86, i32* %17
br label %87
87: ; preds = %98, %81
%88 = load i32, i32* %17
%89 = load i32, i32* %15
%90 = icmp ult i32 %88, %89
br i1 %90, label %91, label %101
91: ; preds = %87
%92 = load i32, i32* %18
%93 = trunc i32 %92 to i8
%94 = load i8*, i8** %13
%95 = load i32, i32* %17
%96 = zext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %94, i64 %96
store i8 %93, i8* %97
br label %98
98: ; preds = %91
%99 = load i32, i32* %17
%100 = add i32 %99, 1
store i32 %100, i32* %17
br label %87
101: ; preds = %87
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %17
br label %103
103: ; preds = %115, %101
%104 = load i32, i32* %17
%105 = load i32, i32* %15
%106 = icmp ult i32 %104, %105
br i1 %106, label %107, label %118
107: ; preds = %103
%108 = load i8*, i8** %13
%109 = load i32, i32* %17
%110 = zext i32 %109 to i64
%111 = getelementptr inbounds i8, i8* %108, i64 %110
%112 = load i8, i8* %111
%113 = zext i8 %112 to i32
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %113)
br label %115
115: ; preds = %107
%116 = load i32, i32* %17
%117 = add i32 %116, 1
store i32 %117, i32* %17
br label %103
118: ; preds = %103
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%120 = load i32, i32* %15
%121 = call i64 @calloc(i32 %120, i32 1)
%122 = inttoptr i64 %121 to i8*
store i8* %122, i8** %14
%123 = load i8*, i8** %14
%124 = icmp eq i8* %123, null
br i1 %124, label %125, label %129
125: ; preds = %118
%126 = load i32, i32* @stderr
%127 = call i32 @fprintf(i32 %126, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
%128 = call i32 @exit(i32 -1)
unreachable
129: ; preds = %118
%130 = load i32, i32* %15
%131 = mul i32 2, %130
%132 = call i64 @calloc(i32 %131, i32 1)
%133 = inttoptr i64 %132 to i8*
%134 = load i8**, i8*** %8
store i8* %133, i8** %134
%135 = load i8**, i8*** %8
%136 = load i8*, i8** %135
%137 = icmp eq i8* %136, null
br i1 %137, label %138, label %142
138: ; preds = %129
%139 = load i32, i32* @stderr
%140 = call i32 @fprintf(i32 %139, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
%141 = call i32 @exit(i32 -1)
unreachable
142: ; preds = %129
%143 = load i8*, i8** %13
%144 = load i8*, i8** %14
%145 = load i32, i32* %15
%146 = load i32, i32* @AES_ENCRYPT
%147 = call i32 @AES_cbc_encrypt(i8* %143, i8* %144, i32 %145, i32* %10, i8* %24, i32 %146)
%148 = load i32, i32* %15
%149 = load i32*, i32** %9
store i32 %148, i32* %149
store i32 0, i32* %17
br label %150
150: ; preds = %178, %142
%151 = load i32, i32* %17
%152 = load i32, i32* %15
%153 = icmp ult i32 %151, %152
br i1 %153, label %154, label %181
154: ; preds = %150
%155 = getelementptr inbounds [3 x i8], [3 x i8]* %19, i64 0, i64 0
%156 = load i8*, i8** %14
%157 = load i32, i32* %17
%158 = zext i32 %157 to i64
%159 = getelementptr inbounds i8, i8* %156, i64 %158
%160 = load i8, i8* %159
%161 = zext i8 %160 to i32
%162 = ashr i32 %161, 4
%163 = and i32 %162, 15
%164 = trunc i32 %163 to i8
%165 = load i8*, i8** %14
%166 = load i32, i32* %17
%167 = zext i32 %166 to i64
%168 = getelementptr inbounds i8, i8* %165, i64 %167
%169 = load i8, i8* %168
%170 = zext i8 %169 to i32
%171 = and i32 %170, 15
%172 = trunc i32 %171 to i8
%173 = call i32 @sprintf(i8* %155, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8 zeroext %164, i8 zeroext %172)
%174 = load i8**, i8*** %8
%175 = load i8*, i8** %174
%176 = getelementptr inbounds [3 x i8], [3 x i8]* %19, i64 0, i64 0
%177 = call i32 @strcat(i8* %175, i8* %176)
br label %178
178: ; preds = %154
%179 = load i32, i32* %17
%180 = add i32 %179, 1
store i32 %180, i32* %17
br label %150
181: ; preds = %150
%182 = load i8*, i8** %14
%183 = call i32 @free(i8* %182)
%184 = load i8*, i8** %13
%185 = call i32 @free(i8* %184)
store i32 0, i32* %5
store i32 1, i32* %20
br label %186
186: ; preds = %181, %41
%187 = load i8*, i8** %11
%188 = load i32, i32* %5
ret i32 %188
}

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"
@.str.6 = [35 x i8] c"Unable to allocate memory for out\0A\00"
@AES_ENCRYPT = global i32 0
@.str.7 = [5 x i8] c"%x%x\00"
@str = [15 x i8] c"input_string: \00"
define i32 @aescbcencrypt(i8* %0, i8* %1, i8** nocapture %2, i32* nocapture writeonly %3) {
%5 = alloca i32
%6 = alloca [3 x i8]
%7 = bitcast i32* %5 to i8*
%8 = load i32, i32* @AES_BLOCK_SIZE
%9 = zext i32 %8 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%13 = load i32, i32* @AES_BLOCK_SIZE
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %4
%16 = zext i32 %13 to i64
br label %17
17: ; preds = %15, %4
%18 = call i64 @AES_set_encrypt_key(i8* %1, i32 128, i32* %5)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %113
23: ; preds = %17
%24 = call i32 @strlen(i8* %0)
%25 = add nsw i32 %24, 1
%26 = load i32, i32* @AES_BLOCK_SIZE
%27 = srem i32 %25, %26
%28 = icmp eq i32 %27, 0
%29 = call i32 @strlen(i8* %0)
%30 = add nsw i32 %29, 1
br i1 %28, label %40, label %31
31: ; preds = %23
%32 = load i32, i32* @AES_BLOCK_SIZE
%33 = sdiv i32 %30, %32
%34 = add nsw i32 %33, 1
%35 = mul nsw i32 %34, %32
%36 = call i32 @strlen(i8* %0)
%37 = xor i32 %36, -1
%38 = add i32 %35, %37
%39 = trunc i32 %38 to i8
br label %40
40: ; preds = %23, %31
%41 = phi i32 [ %35, %31 ], [ %30, %23 ]
%42 = phi i8 [ %39, %31 ], [ undef, %23 ]
%43 = call i32 @strlen(i8* %0)
%44 = call i64 @calloc(i32 %41, i32 1)
%45 = inttoptr i64 %44 to i8*
%46 = icmp eq i64 %44, 0
br i1 %46, label %47, label %51
47: ; preds = %40
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 @exit(i32 -1)
unreachable
51: ; preds = %40
%52 = call i32 @strncpy(i8* %45, i8* %0, i32 %43)
%53 = icmp ult i32 %43, %41
br i1 %53, label %54, label %62
54: ; preds = %51
%55 = zext i32 %43 to i64
%56 = getelementptr i8, i8* %45, i64 %55
%57 = xor i32 %43, -1
%58 = add i32 %41, %57
%59 = zext i32 %58 to i64
%60 = add nuw nsw i64 %59, 1
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %65
62: ; preds = %51
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%64 = icmp eq i32 %41, 0
br i1 %64, label %75, label %65
65: ; preds = %54, %62
%66 = zext i32 %41 to i64
br label %67
67: ; preds = %65, %67
%68 = phi i64 [ 0, %65 ], [ %73, %67 ]
%69 = getelementptr inbounds i8, i8* %45, i64 %68
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %71)
%73 = add nuw nsw i64 %68, 1
%74 = icmp eq i64 %73, %66
br i1 %74, label %75, label %67
75: ; preds = %67, %62
%76 = phi i1 [ true, %62 ], [ false, %67 ]
%77 = call i32 @putchar(i32 10)
%78 = call i64 @calloc(i32 %41, i32 1)
%79 = inttoptr i64 %78 to i8*
%80 = icmp eq i64 %78, 0
br i1 %80, label %81, label %85
81: ; preds = %75
%82 = load i32, i32* @stderr
%83 = call i32 @fprintf(i32 %82, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
%84 = call i32 @exit(i32 -1)
unreachable
85: ; preds = %75
%86 = shl i32 %41, 1
%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 = %85
%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 = %85
%95 = load i32, i32* @AES_ENCRYPT
%96 = call i32 @AES_cbc_encrypt(i8* %45, i8* %79, i32 %41, i32* %5, i8* %11, i32 %95)
store i32 %41, i32* %3
br i1 %76, label %110, label %97
97: ; preds = %94
%98 = zext i32 %41 to i64
br label %99
99: ; preds = %97, %99
%100 = phi i64 [ 0, %97 ], [ %108, %99 ]
%101 = getelementptr inbounds i8, i8* %79, i64 %100
%102 = load i8, i8* %101
%103 = lshr i8 %102, 4
%104 = and i8 %102, 15
%105 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8 zeroext %103, i8 zeroext %104)
%106 = load i8*, i8** %2
%107 = call i32 @strcat(i8* %106, i8* %12)
%108 = add nuw nsw i64 %100, 1
%109 = icmp eq i64 %108, %98
br i1 %109, label %110, label %99
110: ; preds = %99, %94
%111 = call i32 @free(i8* %79)
%112 = call i32 @free(i8* %45)
br label %113
113: ; preds = %110, %20
%114 = phi i32 [ -1, %20 ], [ 0, %110 ]
ret i32 %114
}