#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 */
int /*<<< orphan*/ addRoundKey(unsigned char *, unsigned char *);
int /*<<< orphan*/ aes_round(unsigned char *, unsigned char *);
int /*<<< orphan*/ createRoundKey(unsigned char *, unsigned char *);
int /*<<< orphan*/ shiftRows(unsigned char *);
int /*<<< orphan*/ subBytes(unsigned char *);
void aes_main(unsigned char *state, unsigned char *expandedKey, int nbrRounds) {
  int i = 0;
  unsigned char roundKey[16];
  createRoundKey(expandedKey, roundKey);
  addRoundKey(state, roundKey);
  for (i = 1; i < nbrRounds; i++) {
    createRoundKey(expandedKey + 16 * i, roundKey);
    aes_round(state, roundKey);
  }
  createRoundKey(expandedKey + 16 * nbrRounds, roundKey);
  subBytes(state);
  shiftRows(state);
  addRoundKey(state, roundKey);
}


x86 assembly (clang, -O0):
<aes_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <createRoundKey@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <addRoundKey@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ca <aes_main+0x7a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rdi
lea    -0x30(%rbp),%rsi
call   1070 <createRoundKey@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <aes_round@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118b <aes_main+0x3b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rdi
lea    -0x30(%rbp),%rsi
call   1070 <createRoundKey@plt>
mov    -0x8(%rbp),%rdi
call   1050 <subBytes@plt>
mov    -0x8(%rbp),%rdi
call   1040 <shiftRows@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <addRoundKey@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsp,%rbx
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1070 <createRoundKey@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <addRoundKey@plt>
cmp    $0x2,%r15d
jl     11c0 <aes_main+0x70>
mov    %r15d,%ebx
lea    0x10(%r14),%rbp
add    $0xffffffffffffffff,%rbx
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %r13,%rsi
call   1070 <createRoundKey@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <aes_round@plt>
add    $0x10,%rbp
add    $0xffffffffffffffff,%rbx
jne    11a0 <aes_main+0x50>
shl    $0x4,%r15d
movslq %r15d,%rax
add    %rax,%r14
mov    %rsp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <createRoundKey@plt>
mov    %r12,%rdi
call   1050 <subBytes@plt>
mov    %r12,%rdi
call   1040 <shiftRows@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <addRoundKey@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @aes_main(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [16 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%9 = load i8*, i8** %5
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%11 = call i32 @createRoundKey(i8* %9, i8* %10)
%12 = load i8*, i8** %4
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%14 = call i32 @addRoundKey(i8* %12, i8* %13)
store i32 1, i32* %7
br label %15
15: ; preds = %30, %3
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %33
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = load i32, i32* %7
%22 = mul nsw i32 16, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%26 = call i32 @createRoundKey(i8* %24, i8* %25)
%27 = load i8*, i8** %4
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%29 = call i32 @aes_round(i8* %27, i8* %28)
br label %30
30: ; preds = %19
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %15
33: ; preds = %15
%34 = load i8*, i8** %5
%35 = load i32, i32* %6
%36 = mul nsw i32 16, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%40 = call i32 @createRoundKey(i8* %38, i8* %39)
%41 = load i8*, i8** %4
%42 = call i32 @subBytes(i8* %41)
%43 = load i8*, i8** %4
%44 = call i32 @shiftRows(i8* %43)
%45 = load i8*, i8** %4
%46 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%47 = call i32 @addRoundKey(i8* %45, i8* %46)
ret void
}

LLVM IR (-O2):
define void @aes_main(i8* %0, i8* %1, i32 %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = call i32 @createRoundKey(i8* %1, i8* %5)
%7 = call i32 @addRoundKey(i8* %0, i8* %5)
%8 = icmp sgt i32 %2, 1
br i1 %8, label %9, label %19
9: ; preds = %3
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 1, %9 ], [ %17, %11 ]
%13 = shl nsw i64 %12, 4
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = call i32 @createRoundKey(i8* %14, i8* %5)
%16 = call i32 @aes_round(i8* %0, i8* %5)
%17 = add nuw nsw i64 %12, 1
%18 = icmp eq i64 %17, %10
br i1 %18, label %19, label %11
19: ; preds = %11, %3
%20 = shl nsw i32 %2, 4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = call i32 @createRoundKey(i8* %22, i8* %5)
%24 = call i32 @subBytes(i8* %0)
%25 = call i32 @shiftRows(i8* %0)
%26 = call i32 @addRoundKey(i8* %0, i8* %5)
ret void
}