#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*/ uint32_t;
typedef int /*<<< orphan*/ state;

/* Variables and functions */
int /*<<< orphan*/ AddRoundKey(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ InvMixSubColumns(unsigned char *);
int /*<<< orphan*/ InvShiftRows(unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
void aes128_decrypt_block(void *out_buffer, const void *inp_buffer,
                          const unsigned char *expkey) {
  unsigned char *out = (unsigned char *)out_buffer;
  unsigned char *in = (unsigned char *)inp_buffer;
  unsigned char state[4 * 4];
  unsigned round;
  memcpy(state, in, sizeof(state));
  AddRoundKey((uint32_t *)state, (uint32_t *)expkey + 10 * 4);
  InvShiftRows(state);
  for (round = 10; round--;) {
    AddRoundKey((uint32_t *)state, (uint32_t *)expkey + round * 4);
    if (round)
      InvMixSubColumns(state);
  }
  memcpy(out, state, sizeof(state));
}


x86 assembly (clang, -O0):
<aes128_decrypt_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0xa0,%rsi
call   1030 <AddRoundKey@plt>
lea    -0x40(%rbp),%rdi
call   1040 <InvShiftRows@plt>
movl   $0xa,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x44(%rbp)
cmp    $0x0,%eax
je     11e2 <aes128_decrypt_block+0xa2>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x44(%rbp),%eax
shl    $0x2,%eax
mov    %eax,%eax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <AddRoundKey@plt>
cmpl   $0x0,-0x44(%rbp)
je     11dd <aes128_decrypt_block+0x9d>
lea    -0x40(%rbp),%rdi
call   1050 <InvMixSubColumns@plt>
jmp    119a <aes128_decrypt_block+0x5a>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes128_decrypt_block>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rdi,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x10,%edx
call   1060 <memcpy@plt>
lea    0xa0(%rbx),%rsi
mov    %r15,%rdi
call   1030 <AddRoundKey@plt>
mov    %r15,%rdi
call   1040 <InvShiftRows@plt>
lea    0x90(%rbx),%rsi
mov    %r15,%rdi
call   1030 <AddRoundKey@plt>
mov    %r15,%rdi
call   1050 <InvMixSubColumns@plt>
lea    0x80(%rbx),%rsi
mov    %r15,%rdi
call   1030 <AddRoundKey@plt>
mov    %r15,%rdi
call   1050 <InvMixSubColumns@plt>
lea    0x70(%rbx),%rsi
mov    %r15,%rdi
call   1030 <AddRoundKey@plt>
mov    %r15,%rdi
call   1050 <InvMixSubColumns@plt>
lea    0x60(%rbx),%rsi
mov    %r15,%rdi
call   1030 <AddRoundKey@plt>
mov    %r15,%rdi
call   1050 <InvMixSubColumns@plt>
lea    0x50(%rbx),%rsi
mov    %r15,%rdi
call   1030 <AddRoundKey@plt>
mov    %r15,%rdi
call   1050 <InvMixSubColumns@plt>
lea    0x40(%rbx),%rsi
mov    %r15,%rdi
call   1030 <AddRoundKey@plt>
mov    %r15,%rdi
call   1050 <InvMixSubColumns@plt>
lea    0x30(%rbx),%rsi
mov    %r15,%rdi
call   1030 <AddRoundKey@plt>
mov    %r15,%rdi
call   1050 <InvMixSubColumns@plt>
lea    0x20(%rbx),%rsi
mov    %r15,%rdi
call   1030 <AddRoundKey@plt>
mov    %r15,%rdi
call   1050 <InvMixSubColumns@plt>
lea    0x10(%rbx),%rsi
mov    %r15,%rdi
call   1030 <AddRoundKey@plt>
mov    %r15,%rdi
call   1050 <InvMixSubColumns@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <AddRoundKey@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @aes128_decrypt_block(i8* %0, i8* %1, i8* %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = call i32 @memcpy(i8* %5, i8* %1, i32 16)
%7 = bitcast [16 x i8]* %4 to i32*
%8 = bitcast i8* %2 to i32*
%9 = getelementptr inbounds i8, i8* %2, i64 160
%10 = bitcast i8* %9 to i32*
%11 = call i32 @AddRoundKey(i32* %7, i32* %10)
%12 = call i32 @InvShiftRows(i8* %5)
%13 = getelementptr inbounds i8, i8* %2, i64 144
%14 = bitcast i8* %13 to i32*
%15 = call i32 @AddRoundKey(i32* %7, i32* %14)
%16 = call i32 @InvMixSubColumns(i8* %5)
%17 = getelementptr inbounds i8, i8* %2, i64 128
%18 = bitcast i8* %17 to i32*
%19 = call i32 @AddRoundKey(i32* %7, i32* %18)
%20 = call i32 @InvMixSubColumns(i8* %5)
%21 = getelementptr inbounds i8, i8* %2, i64 112
%22 = bitcast i8* %21 to i32*
%23 = call i32 @AddRoundKey(i32* %7, i32* %22)
%24 = call i32 @InvMixSubColumns(i8* %5)
%25 = getelementptr inbounds i8, i8* %2, i64 96
%26 = bitcast i8* %25 to i32*
%27 = call i32 @AddRoundKey(i32* %7, i32* %26)
%28 = call i32 @InvMixSubColumns(i8* %5)
%29 = getelementptr inbounds i8, i8* %2, i64 80
%30 = bitcast i8* %29 to i32*
%31 = call i32 @AddRoundKey(i32* %7, i32* %30)
%32 = call i32 @InvMixSubColumns(i8* %5)
%33 = getelementptr inbounds i8, i8* %2, i64 64
%34 = bitcast i8* %33 to i32*
%35 = call i32 @AddRoundKey(i32* %7, i32* %34)
%36 = call i32 @InvMixSubColumns(i8* %5)
%37 = getelementptr inbounds i8, i8* %2, i64 48
%38 = bitcast i8* %37 to i32*
%39 = call i32 @AddRoundKey(i32* %7, i32* %38)
%40 = call i32 @InvMixSubColumns(i8* %5)
%41 = getelementptr inbounds i8, i8* %2, i64 32
%42 = bitcast i8* %41 to i32*
%43 = call i32 @AddRoundKey(i32* %7, i32* %42)
%44 = call i32 @InvMixSubColumns(i8* %5)
%45 = getelementptr inbounds i8, i8* %2, i64 16
%46 = bitcast i8* %45 to i32*
%47 = call i32 @AddRoundKey(i32* %7, i32* %46)
%48 = call i32 @InvMixSubColumns(i8* %5)
%49 = call i32 @AddRoundKey(i32* %7, i32* %8)
%50 = call i32 @memcpy(i8* %0, i8* %5, i32 16)
ret void
}