#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*/ MixSubColumns(unsigned char *);
int /*<<< orphan*/ ShiftRows(unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
void aes128_encrypt_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, 4 * 4);
  AddRoundKey((uint32_t *)state, (uint32_t *)expkey);
  for (round = 1; round < 10 + 1; round++) {
    if (round < 10)
      MixSubColumns(state);
    else
      ShiftRows(state);
    AddRoundKey((uint32_t *)state, (uint32_t *)expkey + round * 4);
  }
  memcpy(out, state, sizeof(state));
}


x86 assembly (clang, -O0):
<aes128_encrypt_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   1050 <memcpy@plt>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <AddRoundKey@plt>
movl   $0x1,-0x44(%rbp)
cmpl   $0xb,-0x44(%rbp)
jae    11df <aes128_encrypt_block+0x9f>
cmpl   $0xa,-0x44(%rbp)
jae    11ac <aes128_encrypt_block+0x6c>
lea    -0x40(%rbp),%rdi
call   1060 <MixSubColumns@plt>
jmp    11b5 <aes128_encrypt_block+0x75>
lea    -0x40(%rbp),%rdi
call   1030 <ShiftRows@plt>
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   1040 <AddRoundKey@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    118a <aes128_encrypt_block+0x4a>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes128_encrypt_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   1050 <memcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <AddRoundKey@plt>
mov    %r15,%rdi
call   1060 <MixSubColumns@plt>
lea    0x10(%rbx),%rsi
mov    %r15,%rdi
call   1040 <AddRoundKey@plt>
mov    %r15,%rdi
call   1060 <MixSubColumns@plt>
lea    0x20(%rbx),%rsi
mov    %r15,%rdi
call   1040 <AddRoundKey@plt>
mov    %r15,%rdi
call   1060 <MixSubColumns@plt>
lea    0x30(%rbx),%rsi
mov    %r15,%rdi
call   1040 <AddRoundKey@plt>
mov    %r15,%rdi
call   1060 <MixSubColumns@plt>
lea    0x40(%rbx),%rsi
mov    %r15,%rdi
call   1040 <AddRoundKey@plt>
mov    %r15,%rdi
call   1060 <MixSubColumns@plt>
lea    0x50(%rbx),%rsi
mov    %r15,%rdi
call   1040 <AddRoundKey@plt>
mov    %r15,%rdi
call   1060 <MixSubColumns@plt>
lea    0x60(%rbx),%rsi
mov    %r15,%rdi
call   1040 <AddRoundKey@plt>
mov    %r15,%rdi
call   1060 <MixSubColumns@plt>
lea    0x70(%rbx),%rsi
mov    %r15,%rdi
call   1040 <AddRoundKey@plt>
mov    %r15,%rdi
call   1060 <MixSubColumns@plt>
lea    0x80(%rbx),%rsi
mov    %r15,%rdi
call   1040 <AddRoundKey@plt>
mov    %r15,%rdi
call   1060 <MixSubColumns@plt>
lea    0x90(%rbx),%rsi
mov    %r15,%rdi
call   1040 <AddRoundKey@plt>
mov    %r15,%rdi
call   1030 <ShiftRows@plt>
add    $0xa0,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <AddRoundKey@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @aes128_encrypt_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 = call i32 @AddRoundKey(i32* %17, i32* %19)
store i32 1, i32* %10
br label %21
21: ; preds = %43, %3
%22 = load i32, i32* %10
%23 = icmp ult i32 %22, 11
br i1 %23, label %24, label %46
24: ; preds = %21
%25 = load i32, i32* %10
%26 = icmp ult i32 %25, 10
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%29 = call i32 @MixSubColumns(i8* %28)
br label %33
30: ; preds = %24
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%32 = call i32 @ShiftRows(i8* %31)
br label %33
33: ; preds = %30, %27
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%35 = bitcast i8* %34 to i32*
%36 = load i8*, i8** %6
%37 = bitcast i8* %36 to i32*
%38 = load i32, i32* %10
%39 = mul i32 %38, 4
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %37, i64 %40
%42 = call i32 @AddRoundKey(i32* %35, i32* %41)
br label %43
43: ; preds = %33
%44 = load i32, i32* %10
%45 = add i32 %44, 1
store i32 %45, i32* %10
br label %21
46: ; preds = %21
%47 = load i8*, i8** %7
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%49 = call i32 @memcpy(i8* %47, i8* %48, i32 16)
ret void
}

LLVM IR (-O2):
define void @aes128_encrypt_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 = call i32 @AddRoundKey(i32* %7, i32* %8)
%10 = call i32 @MixSubColumns(i8* %5)
%11 = getelementptr inbounds i8, i8* %2, i64 16
%12 = bitcast i8* %11 to i32*
%13 = call i32 @AddRoundKey(i32* %7, i32* %12)
%14 = call i32 @MixSubColumns(i8* %5)
%15 = getelementptr inbounds i8, i8* %2, i64 32
%16 = bitcast i8* %15 to i32*
%17 = call i32 @AddRoundKey(i32* %7, i32* %16)
%18 = call i32 @MixSubColumns(i8* %5)
%19 = getelementptr inbounds i8, i8* %2, i64 48
%20 = bitcast i8* %19 to i32*
%21 = call i32 @AddRoundKey(i32* %7, i32* %20)
%22 = call i32 @MixSubColumns(i8* %5)
%23 = getelementptr inbounds i8, i8* %2, i64 64
%24 = bitcast i8* %23 to i32*
%25 = call i32 @AddRoundKey(i32* %7, i32* %24)
%26 = call i32 @MixSubColumns(i8* %5)
%27 = getelementptr inbounds i8, i8* %2, i64 80
%28 = bitcast i8* %27 to i32*
%29 = call i32 @AddRoundKey(i32* %7, i32* %28)
%30 = call i32 @MixSubColumns(i8* %5)
%31 = getelementptr inbounds i8, i8* %2, i64 96
%32 = bitcast i8* %31 to i32*
%33 = call i32 @AddRoundKey(i32* %7, i32* %32)
%34 = call i32 @MixSubColumns(i8* %5)
%35 = getelementptr inbounds i8, i8* %2, i64 112
%36 = bitcast i8* %35 to i32*
%37 = call i32 @AddRoundKey(i32* %7, i32* %36)
%38 = call i32 @MixSubColumns(i8* %5)
%39 = getelementptr inbounds i8, i8* %2, i64 128
%40 = bitcast i8* %39 to i32*
%41 = call i32 @AddRoundKey(i32* %7, i32* %40)
%42 = call i32 @MixSubColumns(i8* %5)
%43 = getelementptr inbounds i8, i8* %2, i64 144
%44 = bitcast i8* %43 to i32*
%45 = call i32 @AddRoundKey(i32* %7, i32* %44)
%46 = call i32 @ShiftRows(i8* %5)
%47 = getelementptr inbounds i8, i8* %2, i64 160
%48 = bitcast i8* %47 to i32*
%49 = call i32 @AddRoundKey(i32* %7, i32* %48)
%50 = call i32 @memcpy(i8* %0, i8* %5, i32 16)
ret void
}