#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*/ add_round_key(unsigned char **, unsigned char **);
int /*<<< orphan*/ compute_key_schedule(unsigned char const *, int,
                                        unsigned char **);
int /*<<< orphan*/ mix_columns(unsigned char **);
int /*<<< orphan*/ shift_rows(unsigned char **);
int /*<<< orphan*/ subsitute_bytes(unsigned char **);
void aes_block_encrypt(const unsigned char *input_block,
                       unsigned char *output_block, const unsigned char *key,
                       int key_size) {
  int i;
  int j;
  int round;
  int number;
  unsigned char state[4][4];
  unsigned char w[60][4];
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 4; j++) {
      state[i][j] = input_block[i + (4 * j)];
    }
  }
  number = (key_size >> 2) + 6;
  compute_key_schedule(key, key_size, w);
  add_round_key(state, &w[0]);
  for (round = 0; round < number; round++) {
    subsitute_bytes(state);
    shift_rows(state);
    if (round < (number - 1)) {
      mix_columns(state);
    }
    add_round_key(state, &w[(round + 1) * 4]);
  }
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 4; j++) {
      output_block[i + (4 * j)] = state[i][j];
    }
  }
}


x86 assembly (clang, -O0):
<aes_block_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    11d8 <aes_block_encrypt+0x88>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    11c5 <aes_block_encrypt+0x75>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%edx
shl    $0x2,%edx
add    %edx,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
movslq -0x20(%rbp),%rcx
lea    -0x40(%rbp),%rax
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1182 <aes_block_encrypt+0x32>
jmp    11ca <aes_block_encrypt+0x7a>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1171 <aes_block_encrypt+0x21>
mov    -0x1c(%rbp),%eax
sar    $0x2,%eax
add    $0x6,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x130(%rbp),%rdx
call   1050 <compute_key_schedule@plt>
lea    -0x40(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1070 <add_round_key@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1276 <aes_block_encrypt+0x126>
lea    -0x40(%rbp),%rdi
call   1030 <subsitute_bytes@plt>
lea    -0x40(%rbp),%rdi
call   1060 <shift_rows@plt>
mov    -0x28(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1246 <aes_block_encrypt+0xf6>
lea    -0x40(%rbp),%rdi
call   1040 <mix_columns@plt>
lea    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%eax
add    $0x1,%eax
shl    $0x2,%eax
cltq
lea    -0x130(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
call   1070 <add_round_key@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    120e <aes_block_encrypt+0xbe>
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    12e4 <aes_block_encrypt+0x194>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    12d1 <aes_block_encrypt+0x181>
movslq -0x20(%rbp),%rcx
lea    -0x40(%rbp),%rax
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%esi
shl    $0x2,%esi
add    %esi,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    128e <aes_block_encrypt+0x13e>
jmp    12d6 <aes_block_encrypt+0x186>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    127d <aes_block_encrypt+0x12d>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_block_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %ecx,%r15d
mov    %rsi,%r14
movdqu (%rdi),%xmm0
pxor   %xmm3,%xmm3
movdqa %xmm0,%xmm1
punpckhbw %xmm3,%xmm1
pshufd $0xe7,%xmm1,%xmm2
pshuflw $0x72,%xmm2,%xmm2
punpcklbw %xmm3,%xmm0
pshufd $0xe7,%xmm0,%xmm3
pshuflw $0x72,%xmm3,%xmm3
punpckldq %xmm2,%xmm3
pshufd $0xe8,%xmm1,%xmm1
pshuflw $0xd8,%xmm1,%xmm1
pshufd $0xe8,%xmm0,%xmm0
pshuflw $0xd8,%xmm0,%xmm0
punpckldq %xmm1,%xmm0
packuswb %xmm3,%xmm0
movdqa %xmm0,(%rsp)
lea    0x10(%rsp),%rbx
mov    %rdx,%rdi
mov    %ecx,%esi
mov    %rbx,%rdx
call   1050 <compute_key_schedule@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1070 <add_round_key@plt>
cmp    $0xffffffec,%r15d
jl     1227 <aes_block_encrypt+0xd7>
sar    $0x2,%r15d
lea    0x5(%r15),%r13d
add    $0x6,%r15d
lea    0x20(%rsp),%rbx
xor    %ebp,%ebp
mov    %rsp,%r12
jmp    1208 <aes_block_encrypt+0xb8>
nop
add    $0x1,%rbp
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <add_round_key@plt>
add    $0x10,%rbx
cmp    %rbp,%r15
je     1227 <aes_block_encrypt+0xd7>
mov    %r12,%rdi
call   1030 <subsitute_bytes@plt>
mov    %r12,%rdi
call   1060 <shift_rows@plt>
cmp    %r13,%rbp
jae    11f0 <aes_block_encrypt+0xa0>
mov    %r12,%rdi
call   1040 <mix_columns@plt>
jmp    11f0 <aes_block_encrypt+0xa0>
movdqa (%rsp),%xmm0
movdqa %xmm0,%xmm1
pxor   %xmm3,%xmm3
punpckhbw %xmm3,%xmm1
pshufd $0xe7,%xmm1,%xmm2
pshuflw $0x72,%xmm2,%xmm2
punpcklbw %xmm3,%xmm0
pshufd $0xe7,%xmm0,%xmm3
pshuflw $0x72,%xmm3,%xmm3
punpckldq %xmm2,%xmm3
pshufd $0xe8,%xmm1,%xmm1
pshuflw $0xd8,%xmm1,%xmm1
pshufd $0xe8,%xmm0,%xmm0
pshuflw $0xd8,%xmm0,%xmm0
punpckldq %xmm1,%xmm0
packuswb %xmm3,%xmm0
movdqu %xmm0,(%r14)
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @aes_block_encrypt(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [4 x [4 x i8]]
%14 = alloca [60 x [4 x i8]]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %15
15: ; preds = %41, %4
%16 = load i32, i32* %9
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %44
18: ; preds = %15
store i32 0, i32* %10
br label %19
19: ; preds = %37, %18
%20 = load i32, i32* %10
%21 = icmp slt i32 %20, 4
br i1 %21, label %22, label %40
22: ; preds = %19
%23 = load i8*, i8** %5
%24 = load i32, i32* %9
%25 = load i32, i32* %10
%26 = mul nsw i32 4, %25
%27 = add nsw i32 %24, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %23, i64 %28
%30 = load i8, i8* %29
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [4 x [4 x i8]], [4 x [4 x i8]]* %13, i64 0, i64 %32
%34 = load i32, i32* %10
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [4 x i8], [4 x i8]* %33, i64 0, i64 %35
store i8 %30, i8* %36
br label %37
37: ; preds = %22
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %19
40: ; preds = %19
br label %41
41: ; preds = %40
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %15
44: ; preds = %15
%45 = load i32, i32* %8
%46 = ashr i32 %45, 2
%47 = add nsw i32 %46, 6
store i32 %47, i32* %12
%48 = load i8*, i8** %7
%49 = load i32, i32* %8
%50 = getelementptr inbounds [60 x [4 x i8]], [60 x [4 x i8]]* %14, i64 0, i64 0
%51 = bitcast [4 x i8]* %50 to i8**
%52 = call i32 @compute_key_schedule(i8* %48, i32 %49, i8** %51)
%53 = getelementptr inbounds [4 x [4 x i8]], [4 x [4 x i8]]* %13, i64 0, i64 0
%54 = bitcast [4 x i8]* %53 to i8**
%55 = getelementptr inbounds [60 x [4 x i8]], [60 x [4 x i8]]* %14, i64 0, i64 0
%56 = bitcast [4 x i8]* %55 to i8**
%57 = call i32 @add_round_key(i8** %54, i8** %56)
store i32 0, i32* %11
br label %58
58: ; preds = %87, %44
%59 = load i32, i32* %11
%60 = load i32, i32* %12
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %90
62: ; preds = %58
%63 = getelementptr inbounds [4 x [4 x i8]], [4 x [4 x i8]]* %13, i64 0, i64 0
%64 = bitcast [4 x i8]* %63 to i8**
%65 = call i32 @subsitute_bytes(i8** %64)
%66 = getelementptr inbounds [4 x [4 x i8]], [4 x [4 x i8]]* %13, i64 0, i64 0
%67 = bitcast [4 x i8]* %66 to i8**
%68 = call i32 @shift_rows(i8** %67)
%69 = load i32, i32* %11
%70 = load i32, i32* %12
%71 = sub nsw i32 %70, 1
%72 = icmp slt i32 %69, %71
br i1 %72, label %73, label %77
73: ; preds = %62
%74 = getelementptr inbounds [4 x [4 x i8]], [4 x [4 x i8]]* %13, i64 0, i64 0
%75 = bitcast [4 x i8]* %74 to i8**
%76 = call i32 @mix_columns(i8** %75)
br label %77
77: ; preds = %73, %62
%78 = getelementptr inbounds [4 x [4 x i8]], [4 x [4 x i8]]* %13, i64 0, i64 0
%79 = bitcast [4 x i8]* %78 to i8**
%80 = load i32, i32* %11
%81 = add nsw i32 %80, 1
%82 = mul nsw i32 %81, 4
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [60 x [4 x i8]], [60 x [4 x i8]]* %14, i64 0, i64 %83
%85 = bitcast [4 x i8]* %84 to i8**
%86 = call i32 @add_round_key(i8** %79, i8** %85)
br label %87
87: ; preds = %77
%88 = load i32, i32* %11
%89 = add nsw i32 %88, 1
store i32 %89, i32* %11
br label %58
90: ; preds = %58
store i32 0, i32* %9
br label %91
91: ; preds = %117, %90
%92 = load i32, i32* %9
%93 = icmp slt i32 %92, 4
br i1 %93, label %94, label %120
94: ; preds = %91
store i32 0, i32* %10
br label %95
95: ; preds = %113, %94
%96 = load i32, i32* %10
%97 = icmp slt i32 %96, 4
br i1 %97, label %98, label %116
98: ; preds = %95
%99 = load i32, i32* %9
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [4 x [4 x i8]], [4 x [4 x i8]]* %13, i64 0, i64 %100
%102 = load i32, i32* %10
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [4 x i8], [4 x i8]* %101, i64 0, i64 %103
%105 = load i8, i8* %104
%106 = load i8*, i8** %6
%107 = load i32, i32* %9
%108 = load i32, i32* %10
%109 = mul nsw i32 4, %108
%110 = add nsw i32 %107, %109
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8, i8* %106, i64 %111
store i8 %105, i8* %112
br label %113
113: ; preds = %98
%114 = load i32, i32* %10
%115 = add nsw i32 %114, 1
store i32 %115, i32* %10
br label %95
116: ; preds = %95
br label %117
117: ; preds = %116
%118 = load i32, i32* %9
%119 = add nsw i32 %118, 1
store i32 %119, i32* %9
br label %91
120: ; preds = %91
ret void
}

LLVM IR (-O2):
define void @aes_block_encrypt(i8* nocapture %0, i8* nocapture writeonly %1, i8* %2, i32 %3) {
%5 = alloca <16 x i8>
%6 = alloca [60 x [4 x i8]]
%7 = getelementptr inbounds <16 x i8>, <16 x i8>* %5, i64 0, i64 0
%8 = getelementptr inbounds [60 x [4 x i8]], [60 x [4 x i8]]* %6, i64 0, i64 0, i64 0
%9 = bitcast i8* %0 to <16 x i8>*
%10 = load <16 x i8>, <16 x i8>* %9
%11 = shufflevector <16 x i8> %10, <16 x i8> poison, <16 x i32> <i32 0, i32 4, i32 8, i32 12, i32 1, i32 5, i32 9, i32 13, i32 2, i32 6, i32 10, i32 14, i32 3, i32 7, i32 11, i32 15>
store <16 x i8> %11, <16 x i8>* %5
%12 = bitcast [60 x [4 x i8]]* %6 to i8**
%13 = call i32 @compute_key_schedule(i8* %2, i32 %3, i8** %12)
%14 = bitcast <16 x i8>* %5 to i8**
%15 = call i32 @add_round_key(i8** %14, i8** %12)
%16 = icmp sgt i32 %3, -21
br i1 %16, label %17, label %23
17: ; preds = %4
%18 = ashr i32 %3, 2
%19 = add nsw i32 %18, 5
%20 = zext i32 %19 to i64
%21 = add nsw i32 %18, 6
%22 = zext i32 %21 to i64
br label %27
23: ; preds = %34, %4
%24 = load <16 x i8>, <16 x i8>* %5
%25 = shufflevector <16 x i8> %24, <16 x i8> poison, <16 x i32> <i32 0, i32 4, i32 8, i32 12, i32 1, i32 5, i32 9, i32 13, i32 2, i32 6, i32 10, i32 14, i32 3, i32 7, i32 11, i32 15>
%26 = bitcast i8* %1 to <16 x i8>*
store <16 x i8> %25, <16 x i8>* %26
ret void
27: ; preds = %17, %34
%28 = phi i64 [ 0, %17 ], [ %35, %34 ]
%29 = call i32 @subsitute_bytes(i8** %14)
%30 = call i32 @shift_rows(i8** %14)
%31 = icmp ult i64 %28, %20
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @mix_columns(i8** %14)
br label %34
34: ; preds = %32, %27
%35 = add nuw nsw i64 %28, 1
%36 = shl nsw i64 %35, 2
%37 = getelementptr inbounds [60 x [4 x i8]], [60 x [4 x i8]]* %6, i64 0, i64 %36
%38 = bitcast [4 x i8]* %37 to i8**
%39 = call i32 @add_round_key(i8** %14, i8** %38)
%40 = icmp eq i64 %35, %22
br i1 %40, label %23, label %27
}