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


x86 assembly (clang, -O0):
<aes_invMain>:
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
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rdi
lea    -0x30(%rbp),%rsi
call   1050 <createRoundKey@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <addRoundKey@plt>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11d5 <aes_invMain+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rdi
lea    -0x30(%rbp),%rsi
call   1050 <createRoundKey@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <aes_invRound@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1198 <aes_invMain+0x48>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <createRoundKey@plt>
mov    -0x8(%rbp),%rdi
call   1060 <invShiftRows@plt>
mov    -0x8(%rbp),%rdi
call   1070 <invSubBytes@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <addRoundKey@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_invMain>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %edx,%ebx
shl    $0x4,%ebx
movslq %ebx,%rdi
add    %rsi,%rdi
mov    %rsp,%r12
mov    %r12,%rsi
call   1050 <createRoundKey@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <addRoundKey@plt>
cmp    $0x2,%ebp
jl     11c7 <aes_invMain+0x77>
mov    %ebp,%ebp
add    $0x1,%rbp
add    $0xfffffff0,%ebx
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
movslq %ebx,%rbx
lea    (%r15,%rbx,1),%rdi
mov    %r12,%rsi
call   1050 <createRoundKey@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <aes_invRound@plt>
add    $0xffffffffffffffff,%rbp
add    $0xfffffff0,%ebx
cmp    $0x2,%rbp
ja     11a0 <aes_invMain+0x50>
mov    %rsp,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <createRoundKey@plt>
mov    %r14,%rdi
call   1060 <invShiftRows@plt>
mov    %r14,%rdi
call   1070 <invSubBytes@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <addRoundKey@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @aes_invMain(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 = shl nsw i32 %2, 4
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = call i32 @createRoundKey(i8* %8, i8* %5)
%10 = call i32 @addRoundKey(i8* %0, i8* %5)
%11 = icmp sgt i32 %2, 1
br i1 %11, label %12, label %24
12: ; preds = %3
%13 = zext i32 %2 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ %13, %12 ], [ %16, %14 ]
%16 = add nsw i64 %15, -1
%17 = trunc i64 %16 to i32
%18 = shl nsw i32 %17, 4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = call i32 @createRoundKey(i8* %20, i8* %5)
%22 = call i32 @aes_invRound(i8* %0, i8* %5)
%23 = icmp ugt i64 %15, 2
br i1 %23, label %14, label %24
24: ; preds = %14, %3
%25 = call i32 @createRoundKey(i8* %1, i8* %5)
%26 = call i32 @invShiftRows(i8* %0)
%27 = call i32 @invSubBytes(i8* %0)
%28 = call i32 @addRoundKey(i8* %0, i8* %5)
ret void
}