#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 */

/* Variables and functions */
void *aesDecryptECB(void *, int, void *, int);
void *aesEncryptECB(void *, int, void *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
void aesCheck(char *data, char *key, char *answer) {
  int plaintextLength = strlen(data);
  int paddingLength = 16 - (plaintextLength % 16);
  int encryptedLength = plaintextLength + paddingLength;
  void *aesIn = data;
  int dataLength = plaintextLength;
  void *aesKey = key;
  int keyLength = strlen(key);
  void *encrypted = aesEncryptECB(aesIn, dataLength, aesKey, keyLength);
  void *decrypted =
      aesDecryptECB(encrypted, encryptedLength, aesKey, keyLength);
  printf("Original : %s\n", data);
  printf("Hex      : ");
  for (int i = 0; i < plaintextLength; i++) {
    printf("%02x", ((unsigned char *)data)[i]);
  }
  printf("\n");
  printf("Encrypted: ");
  for (int i = 0; i < encryptedLength; i++) {
    printf("%02x", ((unsigned char *)encrypted)[i]);
  }
  printf("\n");
  printf("Expected : %s\n", answer);
  printf("Decrypted: ");
  for (int i = 0; i < encryptedLength; i++) {
    printf("%02x", ((unsigned char *)decrypted)[i]);
  }
  printf("\n");
  printf("Plaintext: %s", (char *)decrypted);
  printf("\n\n");
}


x86 assembly (clang, -O0):
<aesCheck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    $0x10,%eax
sub    %edx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x44(%rbp),%ecx
call   1060 <aesEncryptECB@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x44(%rbp),%ecx
call   1050 <aesDecryptECB@plt>
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1229 <aesCheck+0xe9>
mov    -0x8(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11f5 <aesCheck+0xb5>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1280 <aesCheck+0x140>
mov    -0x50(%rbp),%rax
movslq -0x60(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    124c <aesCheck+0x10c>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12e9 <aesCheck+0x1a9>
mov    -0x58(%rbp),%rax
movslq -0x64(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    12b5 <aesCheck+0x175>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rsi
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aesCheck>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,%r12
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %eax,%r13d
lea    0xf(%r13),%ebx
test   %eax,%eax
cmovns %eax,%ebx
and    $0xfffffff0,%ebx
add    $0x10,%ebx
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r13d,%esi
mov    %r12,%rdx
mov    %eax,%ecx
call   1080 <aesEncryptECB@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,0xc(%rsp)
mov    %ebx,%esi
mov    %r12,%rdx
mov    %ebp,%ecx
call   1070 <aesDecryptECB@plt>
mov    %rax,%r12
lea    0xe36(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe34(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r13d,%r13d
jle    1218 <aesCheck+0xb8>
mov    %r13d,%ebx
lea    0xe2a(%rip),%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r15,%rbp,1),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1200 <aesCheck+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdf7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%r13d
test   %r13d,%r13d
jle    12ca <aesCheck+0x16a>
mov    %r13d,%ebp
lea    0xdd3(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1250 <aesCheck+0xf0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdb3(%rip),%rdi
mov    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdaf(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r13d,%r13d
jle    12f5 <aesCheck+0x195>
lea    0xd7c(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    12b0 <aesCheck+0x150>
jmp    12f5 <aesCheck+0x195>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd51(%rip),%rdi
mov    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd4d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd41(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd22(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"Original : %s\0A\00"
@.str.1 = [12 x i8] c"Hex : \00"
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [12 x i8] c"Encrypted: \00"
@.str.5 = [15 x i8] c"Expected : %s\0A\00"
@.str.6 = [12 x i8] c"Decrypted: \00"
@.str.7 = [14 x i8] c"Plaintext: %s\00"
@.str.8 = [3 x i8] c"\0A\0A\00"
define void @aesCheck(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = srem i32 %21, 16
%23 = sub nsw i32 16, %22
store i32 %23, i32* %8
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = add nsw i32 %24, %25
store i32 %26, i32* %9
%27 = load i8*, i8** %4
store i8* %27, i8** %10
%28 = load i32, i32* %7
store i32 %28, i32* %11
%29 = load i8*, i8** %5
store i8* %29, i8** %12
%30 = load i8*, i8** %5
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %13
%32 = load i8*, i8** %10
%33 = load i32, i32* %11
%34 = load i8*, i8** %12
%35 = load i32, i32* %13
%36 = call i8* @aesEncryptECB(i8* %32, i32 %33, i8* %34, i32 %35)
store i8* %36, i8** %14
%37 = load i8*, i8** %14
%38 = load i32, i32* %9
%39 = load i8*, i8** %12
%40 = load i32, i32* %13
%41 = call i8* @aesDecryptECB(i8* %37, i32 %38, i8* %39, i32 %40)
store i8* %41, i8** %15
%42 = load i8*, i8** %4
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %16
br label %45
45: ; preds = %57, %3
%46 = load i32, i32* %16
%47 = load i32, i32* %7
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %60
49: ; preds = %45
%50 = load i8*, i8** %4
%51 = load i32, i32* %16
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %49
%58 = load i32, i32* %16
%59 = add nsw i32 %58, 1
store i32 %59, i32* %16
br label %45
60: ; preds = %45
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %17
br label %63
63: ; preds = %75, %60
%64 = load i32, i32* %17
%65 = load i32, i32* %9
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %78
67: ; preds = %63
%68 = load i8*, i8** %14
%69 = load i32, i32* %17
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %67
%76 = load i32, i32* %17
%77 = add nsw i32 %76, 1
store i32 %77, i32* %17
br label %63
78: ; preds = %63
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%80 = load i8*, i8** %6
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %80)
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %18
br label %83
83: ; preds = %95, %78
%84 = load i32, i32* %18
%85 = load i32, i32* %9
%86 = icmp slt i32 %84, %85
br i1 %86, label %87, label %98
87: ; preds = %83
%88 = load i8*, i8** %15
%89 = load i32, i32* %18
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8, i8* %88, i64 %90
%92 = load i8, i8* %91
%93 = zext i8 %92 to i32
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %93)
br label %95
95: ; preds = %87
%96 = load i32, i32* %18
%97 = add nsw i32 %96, 1
store i32 %97, i32* %18
br label %83
98: ; preds = %83
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%100 = load i8*, i8** %15
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %100)
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"Original : %s\0A\00"
@.str.1 = [12 x i8] c"Hex : \00"
@.str.2 = [5 x i8] c"%02x\00"
@.str.4 = [12 x i8] c"Encrypted: \00"
@.str.5 = [15 x i8] c"Expected : %s\0A\00"
@.str.6 = [12 x i8] c"Decrypted: \00"
@.str.7 = [14 x i8] c"Plaintext: %s\00"
@str = [2 x i8] c"\0A\00"
define void @aesCheck(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = srem i32 %4, 16
%6 = sub nsw i32 16, %5
%7 = add i32 %6, %4
%8 = tail call i32 @strlen(i8* %1)
%9 = tail call i8* @aesEncryptECB(i8* %0, i32 %4, i8* %1, i32 %8)
%10 = tail call i8* @aesDecryptECB(i8* %9, i32 %7, i8* %1, i32 %8)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp sgt i32 %4, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = zext i32 %4 to i64
br label %22
16: ; preds = %22, %3
%17 = tail call i32 @putchar(i32 10)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp sgt i32 %7, 0
br i1 %19, label %20, label %44
20: ; preds = %16
%21 = zext i32 %7 to i64
br label %36
22: ; preds = %14, %22
%23 = phi i64 [ 0, %14 ], [ %28, %22 ]
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = add nuw nsw i64 %23, 1
%29 = icmp eq i64 %28, %15
br i1 %29, label %16, label %22
30: ; preds = %36
%31 = tail call i32 @putchar(i32 10)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br i1 %19, label %34, label %48
34: ; preds = %30
%35 = zext i32 %7 to i64
br label %52
36: ; preds = %20, %36
%37 = phi i64 [ 0, %20 ], [ %42, %36 ]
%38 = getelementptr inbounds i8, i8* %9, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = add nuw nsw i64 %37, 1
%43 = icmp eq i64 %42, %21
br i1 %43, label %30, label %36
44: ; preds = %16
%45 = tail call i32 @putchar(i32 10)
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %48
48: ; preds = %52, %44, %30
%49 = tail call i32 @putchar(i32 10)
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %10)
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
52: ; preds = %34, %52
%53 = phi i64 [ 0, %34 ], [ %58, %52 ]
%54 = getelementptr inbounds i8, i8* %10, i64 %53
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %56)
%58 = add nuw nsw i64 %53, 1
%59 = icmp eq i64 %58, %35
br i1 %59, label %48, label %52
}