#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(unsigned char *, unsigned char *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ AES_set_encrypt_key(unsigned char *, int,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, char, int);
int strlen(unsigned char *);
int encrypt(unsigned char *in, unsigned char *out, unsigned char *key) {
  do {
  } while (0);
  if (strlen(key) < 0)
    return 0;
  unsigned char cleartext[(128 / 8)];
  unsigned char ciphertext[(128 / 8)];
  int round;
  int tail = strlen(in) % (128 / 8);
  if (tail != 0)
    round = strlen(in) / (128 / 8) + 1;
  else
    round = strlen(in) / (128 / 8);
  AES_KEY aes_key;
  AES_set_encrypt_key(key, 128, &aes_key);
  int idx = 0;
  while (idx < round) {
    memset(cleartext, '\0', (128 / 8));
    if ((idx + 1) == round)
      memcpy(cleartext, in + idx * (128 / 8), tail);
    else
      memcpy(cleartext, in + idx * (128 / 8), (128 / 8));
    do {
    } while (0);
    AES_encrypt(cleartext, ciphertext, &aes_key);
    do {
    } while (0);
    memcpy(out + idx * (128 / 8), ciphertext, (128 / 8));
    idx++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
jmp    1169 <encrypt+0x19>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jge    1187 <encrypt+0x37>
movl   $0x0,-0x4(%rbp)
jmp    12a8 <encrypt+0x158>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
je     11c1 <encrypt+0x71>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11d5 <encrypt+0x85>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x80,%esi
lea    -0x4c(%rbp),%rdx
call   1030 <AES_set_encrypt_key@plt>
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    12a1 <encrypt+0x151>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
cmp    -0x44(%rbp),%eax
jne    1239 <encrypt+0xe9>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x50(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rsi
mov    -0x48(%rbp),%edx
call   1060 <memcpy@plt>
jmp    1256 <encrypt+0x106>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x50(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
jmp    125b <encrypt+0x10b>
jmp    1260 <encrypt+0x110>
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   1070 <AES_encrypt@plt>
jmp    1276 <encrypt+0x126>
mov    -0x18(%rbp),%rdi
mov    -0x50(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rdi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    11ee <encrypt+0x9e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
js     123c <encrypt+0xec>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0xf(%r15),%eax
test   %r15d,%r15d
cmovns %r15d,%eax
and    $0xfffffff0,%eax
xor    %r13d,%r13d
sub    %eax,%r15d
setne  %r13b
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xf(%rax),%ebp
test   %eax,%eax
cmovns %eax,%ebp
sar    $0x4,%ebp
lea    0xc(%rsp),%rdx
mov    %r12,%rdi
mov    $0x80,%esi
call   1030 <AES_set_encrypt_key@plt>
add    %ebp,%r13d
jle    1235 <encrypt+0xe5>
mov    %r13d,%ebp
lea    0x20(%rsp),%r12
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
cmp    $0x1,%rbp
mov    $0x10,%edx
cmove  %r15d,%edx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <memcpy@plt>
mov    %r12,%rdi
mov    %r13,%rsi
lea    0xc(%rsp),%rdx
call   1070 <AES_encrypt@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
add    $0x10,%r14
add    $0x10,%rbx
add    $0xffffffffffffffff,%rbp
jne    11e0 <encrypt+0x90>
mov    $0x1,%eax
jmp    123e <encrypt+0xee>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @encrypt(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [16 x i8]
%9 = alloca [16 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
br label %14
14: ; preds = %3
br label %15
15: ; preds = %14
%16 = load i8*, i8** %7
%17 = call i32 @strlen(i8* %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 0, i32* %4
br label %84
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
%23 = srem i32 %22, 16
store i32 %23, i32* %11
%24 = load i32, i32* %11
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
%29 = sdiv i32 %28, 16
%30 = add nsw i32 %29, 1
store i32 %30, i32* %10
br label %35
31: ; preds = %20
%32 = load i8*, i8** %5
%33 = call i32 @strlen(i8* %32)
%34 = sdiv i32 %33, 16
store i32 %34, i32* %10
br label %35
35: ; preds = %31, %26
%36 = load i8*, i8** %7
%37 = call i32 @AES_set_encrypt_key(i8* %36, i32 128, i32* %12)
store i32 0, i32* %13
br label %38
38: ; preds = %73, %35
%39 = load i32, i32* %13
%40 = load i32, i32* %10
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %83
42: ; preds = %38
%43 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%44 = call i32 @memset(i8* %43, i8 signext 0, i32 16)
%45 = load i32, i32* %13
%46 = add nsw i32 %45, 1
%47 = load i32, i32* %10
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %58
49: ; preds = %42
%50 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%51 = load i8*, i8** %5
%52 = load i32, i32* %13
%53 = mul nsw i32 %52, 16
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
%56 = load i32, i32* %11
%57 = call i32 @memcpy(i8* %50, i8* %55, i32 %56)
br label %66
58: ; preds = %42
%59 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%60 = load i8*, i8** %5
%61 = load i32, i32* %13
%62 = mul nsw i32 %61, 16
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %60, i64 %63
%65 = call i32 @memcpy(i8* %59, i8* %64, i32 16)
br label %66
66: ; preds = %58, %49
br label %67
67: ; preds = %66
br label %68
68: ; preds = %67
%69 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%70 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%71 = call i32 @AES_encrypt(i8* %69, i8* %70, i32* %12)
br label %72
72: ; preds = %68
br label %73
73: ; preds = %72
%74 = load i8*, i8** %6
%75 = load i32, i32* %13
%76 = mul nsw i32 %75, 16
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %74, i64 %77
%79 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%80 = call i32 @memcpy(i8* %78, i8* %79, i32 16)
%81 = load i32, i32* %13
%82 = add nsw i32 %81, 1
store i32 %82, i32* %13
br label %38
83: ; preds = %38
store i32 1, i32* %4
br label %84
84: ; preds = %83, %19
%85 = load i32, i32* %4
ret i32 %85
}

LLVM IR (-O2):
define i32 @encrypt(i8* %0, i8* %1, i8* %2) {
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca i32
%7 = tail call i32 @strlen(i8* %2)
%8 = icmp slt i32 %7, 0
br i1 %8, label %38, label %9
9: ; preds = %3
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%12 = tail call i32 @strlen(i8* %0)
%13 = srem i32 %12, 16
%14 = icmp ne i32 %13, 0
%15 = tail call i32 @strlen(i8* %0)
%16 = sdiv i32 %15, 16
%17 = zext i1 %14 to i32
%18 = add nsw i32 %16, %17
%19 = bitcast i32* %6 to i8*
%20 = call i32 @AES_set_encrypt_key(i8* %2, i32 128, i32* %6)
%21 = icmp sgt i32 %18, 0
br i1 %21, label %22, label %37
22: ; preds = %9
%23 = zext i32 %18 to i64
br label %24
24: ; preds = %22, %24
%25 = phi i64 [ 0, %22 ], [ %27, %24 ]
%26 = call i32 @memset(i8* %10, i8 signext 0, i32 16)
%27 = add nuw nsw i64 %25, 1
%28 = icmp eq i64 %27, %23
%29 = shl nsw i64 %25, 4
%30 = getelementptr inbounds i8, i8* %0, i64 %29
%31 = select i1 %28, i32 %13, i32 16
%32 = call i32 @memcpy(i8* %10, i8* %30, i32 %31)
%33 = call i32 @AES_encrypt(i8* %10, i8* %11, i32* %6)
%34 = getelementptr inbounds i8, i8* %1, i64 %29
%35 = call i32 @memcpy(i8* %34, i8* %11, i32 16)
%36 = icmp eq i64 %27, %23
br i1 %36, label %37, label %24
37: ; preds = %24, %9
br label %38
38: ; preds = %3, %37
%39 = phi i32 [ 1, %37 ], [ 0, %3 ]
ret i32 %39
}