#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 EVP_BytesToKey(int /*<<< orphan*/, int /*<<< orphan*/, unsigned char *,
                   unsigned char *, int, int, unsigned char *, unsigned char *);
int /*<<< orphan*/ EVP_CIPHER_CTX_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_DecryptInit_ex(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *, unsigned char *,
                                      unsigned char *);
int /*<<< orphan*/ EVP_EncryptInit_ex(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *, unsigned char *,
                                      unsigned char *);
int /*<<< orphan*/ EVP_aes_256_cbc();
int /*<<< orphan*/ EVP_sha1();
int /*<<< orphan*/ printf(char *, unsigned char, ...);
int aes_init(unsigned char *key_data, int key_data_len, unsigned char *salt,
             EVP_CIPHER_CTX *e_ctx, EVP_CIPHER_CTX *d_ctx) {
  int i, nrounds = 5;
  unsigned char key[32], iv[32];
  i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), salt, key_data,
                     key_data_len, nrounds, key, iv);
  if (i != 32) {
    printf("Key size is %d bits - should be 256 bits\n", i);
    return -1;
  }
  for (int x = 0; x < 32; ++x)
    printf("Key: %x iv: %x \n", key[x], iv[x]);
  for (int x = 0; x < 8; ++x)
    printf("salt: %x\n", salt[x]);
  EVP_CIPHER_CTX_init(e_ctx);
  EVP_EncryptInit_ex(e_ctx, EVP_aes_256_cbc(), NULL, key, iv);
  EVP_CIPHER_CTX_init(d_ctx);
  EVP_DecryptInit_ex(d_ctx, EVP_aes_256_cbc(), NULL, key, iv);
  return 0;
}


x86 assembly (clang, -O0):
<aes_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x5,-0x38(%rbp)
mov    $0x0,%al
call   1040 <EVP_aes_256_cbc@plt>
mov    %eax,-0x8c(%rbp)
mov    $0x0,%al
call   1050 <EVP_sha1@plt>
mov    -0x8c(%rbp),%edi
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x38(%rbp),%r9d
lea    -0x60(%rbp),%r10
lea    -0x80(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <EVP_BytesToKey@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x20,-0x34(%rbp)
je     1204 <aes_init+0x94>
mov    -0x34(%rbp),%eax
lea    0xe12(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1310 <aes_init+0x1a0>
movl   $0x0,-0x84(%rbp)
cmpl   $0x20,-0x84(%rbp)
jge    1257 <aes_init+0xe7>
movslq -0x84(%rbp),%rax
mov    -0x60(%rbp,%rax,1),%al
movslq -0x84(%rbp),%rcx
movzbl -0x80(%rbp,%rcx,1),%edx
lea    0xdf1(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    120e <aes_init+0x9e>
movl   $0x0,-0x88(%rbp)
cmpl   $0x8,-0x88(%rbp)
jge    129f <aes_init+0x12f>
mov    -0x20(%rbp),%rax
movslq -0x88(%rbp),%rcx
lea    0xdbb(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1261 <aes_init+0xf1>
mov    -0x28(%rbp),%rdi
call   1070 <EVP_CIPHER_CTX_init@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    $0x0,%al
call   1040 <EVP_aes_256_cbc@plt>
mov    -0xa0(%rbp),%rdi
mov    %eax,%esi
lea    -0x60(%rbp),%rcx
lea    -0x80(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edx
call   1090 <EVP_EncryptInit_ex@plt>
mov    -0x30(%rbp),%rdi
call   1070 <EVP_CIPHER_CTX_init@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    $0x0,%al
call   1040 <EVP_aes_256_cbc@plt>
mov    -0x98(%rbp),%rdi
mov    %eax,%esi
lea    -0x60(%rbp),%rcx
lea    -0x80(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edx
call   1080 <EVP_DecryptInit_ex@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_init>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8,%r13
mov    %rcx,%r15
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <EVP_aes_256_cbc@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <EVP_sha1@plt>
lea    0x10(%rsp),%r10
lea    0x30(%rsp),%r11
mov    %ebp,%edi
mov    %eax,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %r12d,%r8d
mov    $0x5,%r9d
push   %r10
push   %r11
call   1030 <EVP_BytesToKey@plt>
add    $0x10,%rsp
cmp    $0x20,%eax
jne    12d2 <aes_init+0x162>
mov    %r13,0x8(%rsp)
lea    0xe4e(%rip),%rbx
xor    %ebp,%ebp
xchg   %ax,%ax
movzbl 0x30(%rsp,%rbp,1),%esi
movzbl 0x10(%rsp,%rbp,1),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    $0x20,%rbp
jne    11e0 <aes_init+0x70>
movzbl (%r14),%esi
lea    0xe32(%rip),%r13
xor    %r12d,%r12d
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0x1(%r14),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0x2(%r14),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0x3(%r14),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0x4(%r14),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0x5(%r14),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0x6(%r14),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0x7(%r14),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1070 <EVP_CIPHER_CTX_init@plt>
xor    %eax,%eax
call   1040 <EVP_aes_256_cbc@plt>
lea    0x30(%rsp),%r14
lea    0x10(%rsp),%rbp
mov    %r15,%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    %rbp,%r8
call   1090 <EVP_EncryptInit_ex@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <EVP_CIPHER_CTX_init@plt>
xor    %eax,%eax
call   1040 <EVP_aes_256_cbc@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    %rbp,%r8
call   1080 <EVP_DecryptInit_ex@plt>
jmp    12e9 <aes_init+0x179>
movzbl %al,%esi
lea    0xd24(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Key size is %d bits - should be 256 bits\0A\00"
@.str.1 = [17 x i8] c"Key: %x iv: %x \0A\00"
@.str.2 = [10 x i8] c"salt: %x\0A\00"
define i32 @aes_init(i8* %0, i32 %1, i8* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca [32 x i8]
%15 = alloca [32 x i8]
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32 5, i32* %13
%18 = call i32 (...) @EVP_aes_256_cbc()
%19 = call i32 (...) @EVP_sha1()
%20 = load i8*, i8** %9
%21 = load i8*, i8** %7
%22 = load i32, i32* %8
%23 = load i32, i32* %13
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %14, i64 0, i64 0
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%26 = call i32 @EVP_BytesToKey(i32 %18, i32 %19, i8* %20, i8* %21, i32 %22, i32 %23, i8* %24, i8* %25)
store i32 %26, i32* %12
%27 = load i32, i32* %12
%28 = icmp ne i32 %27, 32
br i1 %28, label %29, label %33
29: ; preds = %5
%30 = load i32, i32* %12
%31 = trunc i32 %30 to i8
%32 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8 zeroext %31)
store i32 -1, i32* %6
br label %80
33: ; preds = %5
store i32 0, i32* %16
br label %34
34: ; preds = %48, %33
%35 = load i32, i32* %16
%36 = icmp slt i32 %35, 32
br i1 %36, label %37, label %51
37: ; preds = %34
%38 = load i32, i32* %16
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %14, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = load i32, i32* %16
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %41, i32 %46)
br label %48
48: ; preds = %37
%49 = load i32, i32* %16
%50 = add nsw i32 %49, 1
store i32 %50, i32* %16
br label %34
51: ; preds = %34
store i32 0, i32* %17
br label %52
52: ; preds = %62, %51
%53 = load i32, i32* %17
%54 = icmp slt i32 %53, 8
br i1 %54, label %55, label %65
55: ; preds = %52
%56 = load i8*, i8** %9
%57 = load i32, i32* %17
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %60)
br label %62
62: ; preds = %55
%63 = load i32, i32* %17
%64 = add nsw i32 %63, 1
store i32 %64, i32* %17
br label %52
65: ; preds = %52
%66 = load i32*, i32** %10
%67 = call i32 @EVP_CIPHER_CTX_init(i32* %66)
%68 = load i32*, i32** %10
%69 = call i32 (...) @EVP_aes_256_cbc()
%70 = getelementptr inbounds [32 x i8], [32 x i8]* %14, i64 0, i64 0
%71 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%72 = call i32 @EVP_EncryptInit_ex(i32* %68, i32 %69, i32* null, i8* %70, i8* %71)
%73 = load i32*, i32** %11
%74 = call i32 @EVP_CIPHER_CTX_init(i32* %73)
%75 = load i32*, i32** %11
%76 = call i32 (...) @EVP_aes_256_cbc()
%77 = getelementptr inbounds [32 x i8], [32 x i8]* %14, i64 0, i64 0
%78 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%79 = call i32 @EVP_DecryptInit_ex(i32* %75, i32 %76, i32* null, i8* %77, i8* %78)
store i32 0, i32* %6
br label %80
80: ; preds = %65, %29
%81 = load i32, i32* %6
ret i32 %81
}

LLVM IR (-O2):
@.str = [42 x i8] c"Key size is %d bits - should be 256 bits\0A\00"
@.str.1 = [17 x i8] c"Key: %x iv: %x \0A\00"
@.str.2 = [10 x i8] c"salt: %x\0A\00"
define i32 @aes_init(i8* %0, i32 %1, i8* %2, i32* %3, i32* %4) {
%6 = alloca [32 x i8]
%7 = alloca [32 x i8]
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%10 = tail call i32 (...) @EVP_aes_256_cbc()
%11 = tail call i32 (...) @EVP_sha1()
%12 = call i32 @EVP_BytesToKey(i32 %10, i32 %11, i8* %2, i8* %0, i32 %1, i32 5, i8* %8, i8* %9)
%13 = icmp eq i32 %12, 32
br i1 %13, label %17, label %14
14: ; preds = %5
%15 = trunc i32 %12 to i8
%16 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8 zeroext %15)
br label %57
17: ; preds = %5, %17
%18 = phi i64 [ %25, %17 ], [ 0, %5 ]
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 %18
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %20, i32 %23)
%25 = add nuw nsw i64 %18, 1
%26 = icmp eq i64 %25, 32
br i1 %26, label %27, label %17
27: ; preds = %17
%28 = load i8, i8* %2
%29 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %28)
%30 = getelementptr inbounds i8, i8* %2, i64 1
%31 = load i8, i8* %30
%32 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %31)
%33 = getelementptr inbounds i8, i8* %2, i64 2
%34 = load i8, i8* %33
%35 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %34)
%36 = getelementptr inbounds i8, i8* %2, i64 3
%37 = load i8, i8* %36
%38 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %37)
%39 = getelementptr inbounds i8, i8* %2, i64 4
%40 = load i8, i8* %39
%41 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %40)
%42 = getelementptr inbounds i8, i8* %2, i64 5
%43 = load i8, i8* %42
%44 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %43)
%45 = getelementptr inbounds i8, i8* %2, i64 6
%46 = load i8, i8* %45
%47 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %46)
%48 = getelementptr inbounds i8, i8* %2, i64 7
%49 = load i8, i8* %48
%50 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %49)
%51 = call i32 @EVP_CIPHER_CTX_init(i32* %3)
%52 = call i32 (...) @EVP_aes_256_cbc()
%53 = call i32 @EVP_EncryptInit_ex(i32* %3, i32 %52, i32* null, i8* %8, i8* %9)
%54 = call i32 @EVP_CIPHER_CTX_init(i32* %4)
%55 = call i32 (...) @EVP_aes_256_cbc()
%56 = call i32 @EVP_DecryptInit_ex(i32* %4, i32 %55, i32* null, i8* %8, i8* %9)
br label %57
57: ; preds = %27, %14
%58 = phi i32 [ -1, %14 ], [ 0, %27 ]
ret i32 %58
}