#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 /*<<< orphan*/ AES_ENCRYPT;
int /*<<< orphan*/ AES_cbc_encrypt(unsigned char const *, unsigned char *, int,
                                   int /*<<< orphan*/ *, unsigned char *,
                                   int /*<<< orphan*/);
int /*<<< orphan*/ AES_ecb_encrypt(unsigned char const *, unsigned char *,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ AES_set_encrypt_key(unsigned char const *, int,
                                       int /*<<< orphan*/ *);
void hash_proto_aes_encrypt(const unsigned char *key, int keysize,
                            const unsigned char *in, int len,
                            unsigned char *vec, unsigned char *out, int mode) {
  AES_KEY akey;
  AES_set_encrypt_key(key, keysize * 8, &akey);
  switch (mode) {
  case 0:
    AES_ecb_encrypt(in, out, &akey, AES_ENCRYPT);
    break;
  case 1:
    AES_cbc_encrypt(in, out, len, &akey, vec, AES_ENCRYPT);
    break;
  default:
    return;
  }
}


x86 assembly (clang, -O0):
<hash_proto_aes_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
shl    $0x3,%esi
lea    -0x34(%rbp),%rdx
call   1030 <AES_set_encrypt_key@plt>
mov    0x10(%rbp),%eax
mov    %eax,-0x38(%rbp)
test   %eax,%eax
je     1188 <hash_proto_aes_encrypt+0x58>
jmp    1177 <hash_proto_aes_encrypt+0x47>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
je     11a7 <hash_proto_aes_encrypt+0x77>
jmp    11ce <hash_proto_aes_encrypt+0x9e>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x2e49(%rip),%rax
mov    (%rax),%ecx
lea    -0x34(%rbp),%rdx
call   1050 <AES_ecb_encrypt@plt>
jmp    11d3 <hash_proto_aes_encrypt+0xa3>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%r8
mov    0x2e23(%rip),%rax
mov    (%rax),%r9d
lea    -0x34(%rbp),%rcx
call   1040 <AES_cbc_encrypt@plt>
jmp    11d3 <hash_proto_aes_encrypt+0xa3>
jmp    11d3 <hash_proto_aes_encrypt+0xa3>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_proto_aes_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    0x40(%rsp),%ebp
shl    $0x3,%esi
lea    0xc(%rsp),%rdx
call   1030 <AES_set_encrypt_key@plt>
cmp    $0x1,%ebp
je     117d <hash_proto_aes_encrypt+0x4d>
test   %ebp,%ebp
jne    119d <hash_proto_aes_encrypt+0x6d>
mov    0x2e77(%rip),%rax
mov    (%rax),%ecx
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <AES_ecb_encrypt@plt>
jmp    119d <hash_proto_aes_encrypt+0x6d>
mov    0x2e5c(%rip),%rax
mov    (%rax),%r9d
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
mov    %r15,%r8
call   1040 <AES_cbc_encrypt@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AES_ENCRYPT = global i32 0
define void @hash_proto_aes_encrypt(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i8* %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i32 %6, i32* %14
%16 = load i8*, i8** %8
%17 = load i32, i32* %9
%18 = mul nsw i32 %17, 8
%19 = call i32 @AES_set_encrypt_key(i8* %16, i32 %18, i32* %15)
%20 = load i32, i32* %14
switch i32 %20, label %33 [
i32 0, label %21
i32 1, label %26
]
21: ; preds = %7
%22 = load i8*, i8** %10
%23 = load i8*, i8** %13
%24 = load i32, i32* @AES_ENCRYPT
%25 = call i32 @AES_ecb_encrypt(i8* %22, i8* %23, i32* %15, i32 %24)
br label %34
26: ; preds = %7
%27 = load i8*, i8** %10
%28 = load i8*, i8** %13
%29 = load i32, i32* %11
%30 = load i8*, i8** %12
%31 = load i32, i32* @AES_ENCRYPT
%32 = call i32 @AES_cbc_encrypt(i8* %27, i8* %28, i32 %29, i32* %15, i8* %30, i32 %31)
br label %34
33: ; preds = %7
br label %34
34: ; preds = %33, %26, %21
ret void
}

LLVM IR (-O2):
@AES_ENCRYPT = global i32 0
define void @hash_proto_aes_encrypt(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i8* %5, i32 %6) {
%8 = alloca i32
%9 = bitcast i32* %8 to i8*
%10 = shl nsw i32 %1, 3
%11 = call i32 @AES_set_encrypt_key(i8* %0, i32 %10, i32* %8)
switch i32 %6, label %18 [
i32 0, label %12
i32 1, label %15
]
12: ; preds = %7
%13 = load i32, i32* @AES_ENCRYPT
%14 = call i32 @AES_ecb_encrypt(i8* %2, i8* %5, i32* %8, i32 %13)
br label %18
15: ; preds = %7
%16 = load i32, i32* @AES_ENCRYPT
%17 = call i32 @AES_cbc_encrypt(i8* %2, i8* %5, i32 %3, i32* %8, i8* %4, i32 %16)
br label %18
18: ; preds = %12, %15, %7
ret void
}