#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, x, 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 (x = 0; x < 32; ++x)
    printf("Key: %x iv: %x \n", key[x], iv[x]);
  for (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,-0x3c(%rbp)
mov    $0x0,%al
call   1040 <EVP_aes_256_cbc@plt>
mov    %eax,-0x84(%rbp)
mov    $0x0,%al
call   1050 <EVP_sha1@plt>
mov    -0x84(%rbp),%edi
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x3c(%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    12ef <aes_init+0x17f>
movl   $0x0,-0x38(%rbp)
cmpl   $0x20,-0x38(%rbp)
jge    1245 <aes_init+0xd5>
movslq -0x38(%rbp),%rax
mov    -0x60(%rbp,%rax,1),%al
movslq -0x38(%rbp),%rcx
movzbl -0x80(%rbp,%rcx,1),%edx
lea    0xdfd(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    120b <aes_init+0x9b>
movl   $0x0,-0x38(%rbp)
cmpl   $0x8,-0x38(%rbp)
jge    127e <aes_init+0x10e>
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
lea    0xdd6(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    124c <aes_init+0xdc>
mov    -0x28(%rbp),%rdi
call   1070 <EVP_CIPHER_CTX_init@plt>
mov    -0x28(%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   1090 <EVP_EncryptInit_ex@plt>
mov    -0x30(%rbp),%rdi
call   1070 <EVP_CIPHER_CTX_init@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    $0x0,%al
call   1040 <EVP_aes_256_cbc@plt>
mov    -0x90(%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 i32
%15 = alloca [32 x i8]
%16 = alloca [32 x i8]
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* %14
%17 = call i32 (...) @EVP_aes_256_cbc()
%18 = call i32 (...) @EVP_sha1()
%19 = load i8*, i8** %9
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = load i32, i32* %14
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 0
%25 = call i32 @EVP_BytesToKey(i32 %17, i32 %18, i8* %19, i8* %20, i32 %21, i32 %22, i8* %23, i8* %24)
store i32 %25, i32* %12
%26 = load i32, i32* %12
%27 = icmp ne i32 %26, 32
br i1 %27, label %28, label %32
28: ; preds = %5
%29 = load i32, i32* %12
%30 = trunc i32 %29 to i8
%31 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8 zeroext %30)
store i32 -1, i32* %6
br label %79
32: ; preds = %5
store i32 0, i32* %13
br label %33
33: ; preds = %47, %32
%34 = load i32, i32* %13
%35 = icmp slt i32 %34, 32
br i1 %35, label %36, label %50
36: ; preds = %33
%37 = load i32, i32* %13
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = load i32, i32* %13
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %40, i32 %45)
br label %47
47: ; preds = %36
%48 = load i32, i32* %13
%49 = add nsw i32 %48, 1
store i32 %49, i32* %13
br label %33
50: ; preds = %33
store i32 0, i32* %13
br label %51
51: ; preds = %61, %50
%52 = load i32, i32* %13
%53 = icmp slt i32 %52, 8
br i1 %53, label %54, label %64
54: ; preds = %51
%55 = load i8*, i8** %9
%56 = load i32, i32* %13
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %59)
br label %61
61: ; preds = %54
%62 = load i32, i32* %13
%63 = add nsw i32 %62, 1
store i32 %63, i32* %13
br label %51
64: ; preds = %51
%65 = load i32*, i32** %10
%66 = call i32 @EVP_CIPHER_CTX_init(i32* %65)
%67 = load i32*, i32** %10
%68 = call i32 (...) @EVP_aes_256_cbc()
%69 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%70 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 0
%71 = call i32 @EVP_EncryptInit_ex(i32* %67, i32 %68, i32* null, i8* %69, i8* %70)
%72 = load i32*, i32** %11
%73 = call i32 @EVP_CIPHER_CTX_init(i32* %72)
%74 = load i32*, i32** %11
%75 = call i32 (...) @EVP_aes_256_cbc()
%76 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%77 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 0
%78 = call i32 @EVP_DecryptInit_ex(i32* %74, i32 %75, i32* null, i8* %76, i8* %77)
store i32 0, i32* %6
br label %79
79: ; preds = %64, %28
%80 = load i32, i32* %6
ret i32 %80
}

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
}