#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*/ byte_sub(unsigned char *, unsigned char *);
int /*<<< orphan*/ mix_column(unsigned char *, unsigned char *);
int /*<<< orphan*/ next_key(unsigned char *, int);
int /*<<< orphan*/ shift_row(unsigned char *, unsigned char *);
int /*<<< orphan*/ xor_128(unsigned char *, unsigned char *, unsigned char *);
void aes128k128d(unsigned char *key, unsigned char *data,
                 unsigned char *ciphertext) {
  int round;
  int i;
  unsigned char intermediatea[16];
  unsigned char intermediateb[16];
  unsigned char round_key[16];
  for (i = 0; i < 16; i++)
    round_key[i] = key[i];
  for (round = 0; round < 11; round++) {
    if (round == 0) {
      xor_128(round_key, data, ciphertext);
      next_key(round_key, round);
    } else if (round == 10) {
      byte_sub(ciphertext, intermediatea);
      shift_row(intermediatea, intermediateb);
      xor_128(intermediateb, round_key, ciphertext);
    } else {
      byte_sub(ciphertext, intermediatea);
      shift_row(intermediatea, intermediateb);
      mix_column(&intermediateb[0], &intermediatea[0]);
      mix_column(&intermediateb[4], &intermediatea[4]);
      mix_column(&intermediateb[8], &intermediatea[8]);
      mix_column(&intermediateb[12], &intermediatea[12]);
      xor_128(intermediatea, round_key, ciphertext);
      next_key(round_key, round);
    }
  }
}


x86 assembly (clang, -O0):
<aes128k128d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x10,-0x20(%rbp)
jge    1196 <aes128k128d+0x46>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x20(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116b <aes128k128d+0x1b>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xb,-0x1c(%rbp)
jge    12a8 <aes128k128d+0x158>
cmpl   $0x0,-0x1c(%rbp)
jne    11d3 <aes128k128d+0x83>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <xor_128@plt>
lea    -0x50(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <next_key@plt>
jmp    1295 <aes128k128d+0x145>
cmpl   $0xa,-0x1c(%rbp)
jne    120d <aes128k128d+0xbd>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <byte_sub@plt>
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1060 <shift_row@plt>
lea    -0x40(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <xor_128@plt>
jmp    1290 <aes128k128d+0x140>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <byte_sub@plt>
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1060 <shift_row@plt>
lea    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <mix_column@plt>
lea    -0x40(%rbp),%rdi
add    $0x4,%rdi
lea    -0x30(%rbp),%rsi
add    $0x4,%rsi
call   1070 <mix_column@plt>
lea    -0x40(%rbp),%rdi
add    $0x8,%rdi
lea    -0x30(%rbp),%rsi
add    $0x8,%rsi
call   1070 <mix_column@plt>
lea    -0x40(%rbp),%rdi
add    $0xc,%rdi
lea    -0x30(%rbp),%rsi
add    $0xc,%rsi
call   1070 <mix_column@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <xor_128@plt>
lea    -0x50(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <next_key@plt>
jmp    1295 <aes128k128d+0x145>
jmp    129a <aes128k128d+0x14a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119d <aes128k128d+0x4d>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes128k128d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
movups (%rdi),%xmm0
movaps %xmm0,0x20(%rsp)
xor    %r12d,%r12d
lea    0x20(%rsp),%r13
lea    0x10(%rsp),%rbp
mov    %rsp,%r15
jmp    119c <aes128k128d+0x4c>
xchg   %ax,%ax
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <xor_128@plt>
xor    %esi,%esi
mov    %r13,%rdi
call   1030 <next_key@plt>
add    $0x1,%r12d
test   %r12d,%r12d
je     1180 <aes128k128d+0x30>
cmp    $0xa,%r12d
je     1208 <aes128k128d+0xb8>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <byte_sub@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1060 <shift_row@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1070 <mix_column@plt>
lea    0x4(%rsp),%rdi
lea    0x14(%rsp),%rsi
call   1070 <mix_column@plt>
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1070 <mix_column@plt>
lea    0xc(%rsp),%rdi
lea    0x1c(%rsp),%rsi
call   1070 <mix_column@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <xor_128@plt>
mov    %r12d,%esi
jmp    1190 <aes128k128d+0x40>
lea    0x10(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <byte_sub@plt>
mov    %rsp,%r14
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <shift_row@plt>
lea    0x20(%rsp),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1040 <xor_128@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @aes128k128d(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [16 x i8]
%10 = alloca [16 x i8]
%11 = alloca [16 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %8
br label %12
12: ; preds = %24, %3
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 16
br i1 %14, label %15, label %27
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 %22
store i8 %20, i8* %23
br label %24
24: ; preds = %15
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %12
27: ; preds = %12
store i32 0, i32* %7
br label %28
28: ; preds = %84, %27
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 11
br i1 %30, label %31, label %87
31: ; preds = %28
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %31
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%36 = load i8*, i8** %5
%37 = load i8*, i8** %6
%38 = call i32 @xor_128(i8* %35, i8* %36, i8* %37)
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%40 = load i32, i32* %7
%41 = call i32 @next_key(i8* %39, i32 %40)
br label %83
42: ; preds = %31
%43 = load i32, i32* %7
%44 = icmp eq i32 %43, 10
br i1 %44, label %45, label %56
45: ; preds = %42
%46 = load i8*, i8** %6
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%48 = call i32 @byte_sub(i8* %46, i8* %47)
%49 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%50 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%51 = call i32 @shift_row(i8* %49, i8* %50)
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%53 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%54 = load i8*, i8** %6
%55 = call i32 @xor_128(i8* %52, i8* %53, i8* %54)
br label %82
56: ; preds = %42
%57 = load i8*, i8** %6
%58 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%59 = call i32 @byte_sub(i8* %57, i8* %58)
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%61 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%62 = call i32 @shift_row(i8* %60, i8* %61)
%63 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%64 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%65 = call i32 @mix_column(i8* %63, i8* %64)
%66 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 4
%67 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 4
%68 = call i32 @mix_column(i8* %66, i8* %67)
%69 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 8
%70 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 8
%71 = call i32 @mix_column(i8* %69, i8* %70)
%72 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 12
%73 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 12
%74 = call i32 @mix_column(i8* %72, i8* %73)
%75 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%76 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%77 = load i8*, i8** %6
%78 = call i32 @xor_128(i8* %75, i8* %76, i8* %77)
%79 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%80 = load i32, i32* %7
%81 = call i32 @next_key(i8* %79, i32 %80)
br label %82
82: ; preds = %56, %45
br label %83
83: ; preds = %82, %34
br label %84
84: ; preds = %83
%85 = load i32, i32* %7
%86 = add nsw i32 %85, 1
store i32 %86, i32* %7
br label %28
87: ; preds = %28
ret void
}

LLVM IR (-O2):
define void @aes128k128d(i8* nocapture %0, i8* %1, i8* %2) {
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 4
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 4
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 8
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 8
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 12
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 12
br label %17
17: ; preds = %29, %3
%18 = phi i32 [ 0, %3 ], [ %32, %29 ]
switch i32 %18, label %21 [
i32 0, label %19
i32 10, label %33
]
19: ; preds = %17
%20 = call i32 @xor_128(i8* %10, i8* %1, i8* %2)
br label %29
21: ; preds = %17
%22 = call i32 @byte_sub(i8* %2, i8* %8)
%23 = call i32 @shift_row(i8* %8, i8* %9)
%24 = call i32 @mix_column(i8* %9, i8* %8)
%25 = call i32 @mix_column(i8* %11, i8* %12)
%26 = call i32 @mix_column(i8* %13, i8* %14)
%27 = call i32 @mix_column(i8* %15, i8* %16)
%28 = call i32 @xor_128(i8* %8, i8* %10, i8* %2)
br label %29
29: ; preds = %19, %21
%30 = phi i32 [ 0, %19 ], [ %18, %21 ]
%31 = call i32 @next_key(i8* %10, i32 %30)
%32 = add nuw nsw i32 %18, 1
br label %17
33: ; preds = %17
%34 = call i32 @byte_sub(i8* %2, i8* %8)
%35 = call i32 @shift_row(i8* %8, i8* %9)
%36 = call i32 @xor_128(i8* %9, i8* %10, i8* %2)
ret void
}