#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(int *, int **, int, int);
int /*<<< orphan*/ ByteSub_ShiftRow(int *, int);
int /*<<< orphan*/ KeySchedule(int, int *, int **);
int /*<<< orphan*/ MixColumn_AddRoundKey(int *, int, int **, int);
int encrypt(int statemt[32], int key[32], int word[4][120], int type, int nb,
            int round) {
  int i;
  KeySchedule(type, key, word);
  switch (type) {
  case 128128:
    round = 0;
    nb = 4;
    break;
  case 192128:
    round = 2;
    nb = 4;
    break;
  case 256128:
    round = 4;
    nb = 4;
    break;
  case 128192:
  case 192192:
    round = 2;
    nb = 6;
    break;
  case 256192:
    round = 4;
    nb = 6;
    break;
  case 128256:
  case 192256:
  case 256256:
    round = 4;
    nb = 8;
    break;
  }
  AddRoundKey(statemt, word, type, 0);
  for (i = 1; i <= round + 9; ++i) {
    ByteSub_ShiftRow(statemt, nb);
    MixColumn_AddRoundKey(statemt, nb, word, i);
  }
  ByteSub_ShiftRow(statemt, nb);
  AddRoundKey(statemt, word, type, i);
  return 0;
}


x86 assembly (clang, -O0):
<encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <KeySchedule@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x1f480,%eax
je     121d <encrypt+0xdd>
jmp    1185 <encrypt+0x45>
mov    -0x2c(%rbp),%eax
sub    $0x1f4c0,%eax
je     1256 <encrypt+0x116>
jmp    1198 <encrypt+0x58>
mov    -0x2c(%rbp),%eax
sub    $0x1f500,%eax
je     127c <encrypt+0x13c>
jmp    11ab <encrypt+0x6b>
mov    -0x2c(%rbp),%eax
sub    $0x2ee80,%eax
je     1230 <encrypt+0xf0>
jmp    11be <encrypt+0x7e>
mov    -0x2c(%rbp),%eax
sub    $0x2eec0,%eax
je     1256 <encrypt+0x116>
jmp    11d1 <encrypt+0x91>
mov    -0x2c(%rbp),%eax
sub    $0x2ef00,%eax
je     127c <encrypt+0x13c>
jmp    11e4 <encrypt+0xa4>
mov    -0x2c(%rbp),%eax
sub    $0x3e880,%eax
je     1243 <encrypt+0x103>
jmp    11f7 <encrypt+0xb7>
mov    -0x2c(%rbp),%eax
sub    $0x3e8c0,%eax
je     1269 <encrypt+0x129>
jmp    120a <encrypt+0xca>
mov    -0x2c(%rbp),%eax
sub    $0x3e900,%eax
je     127c <encrypt+0x13c>
jmp    128a <encrypt+0x14a>
movl   $0x0,-0x24(%rbp)
movl   $0x4,-0x20(%rbp)
jmp    128a <encrypt+0x14a>
movl   $0x2,-0x24(%rbp)
movl   $0x4,-0x20(%rbp)
jmp    128a <encrypt+0x14a>
movl   $0x4,-0x24(%rbp)
movl   $0x4,-0x20(%rbp)
jmp    128a <encrypt+0x14a>
movl   $0x2,-0x24(%rbp)
movl   $0x6,-0x20(%rbp)
jmp    128a <encrypt+0x14a>
movl   $0x4,-0x24(%rbp)
movl   $0x6,-0x20(%rbp)
jmp    128a <encrypt+0x14a>
movl   $0x4,-0x24(%rbp)
movl   $0x8,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <AddRoundKey@plt>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x9,%ecx
cmp    %ecx,%eax
jg     12e1 <encrypt+0x1a1>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <ByteSub_ShiftRow@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%ecx
call   1050 <MixColumn_AddRoundKey@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12a3 <encrypt+0x163>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <ByteSub_ShiftRow@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%ecx
call   1030 <AddRoundKey@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r12d
mov    %r8d,%ebx
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rdi,%rbp
mov    %ecx,%edi
call   1060 <KeySchedule@plt>
cmp    $0x2eebf,%r14d
jle    119b <encrypt+0x5b>
cmp    $0x3e87f,%r14d
jle    11c3 <encrypt+0x83>
cmp    $0x3e880,%r14d
je     120d <encrypt+0xcd>
cmp    $0x3e8c0,%r14d
je     121a <encrypt+0xda>
cmp    $0x3e900,%r14d
je     11f8 <encrypt+0xb8>
jmp    12c0 <encrypt+0x180>
mov    $0x4,%eax
cmp    $0x1f4ff,%r14d
jg     11da <encrypt+0x9a>
xor    %r13d,%r13d
cmp    $0x1f480,%r14d
je     1225 <encrypt+0xe5>
cmp    $0x1f4c0,%r14d
je     1205 <encrypt+0xc5>
jmp    12c0 <encrypt+0x180>
cmp    $0x2eec0,%r14d
je     1205 <encrypt+0xc5>
cmp    $0x2ef00,%r14d
je     11f8 <encrypt+0xb8>
jmp    12c0 <encrypt+0x180>
cmp    $0x1f500,%r14d
je     11f8 <encrypt+0xb8>
cmp    $0x2ee80,%r14d
jne    12c0 <encrypt+0x180>
mov    $0x2,%r13d
jmp    1225 <encrypt+0xe5>
mov    $0x4,%r13d
mov    $0x8,%eax
jmp    1225 <encrypt+0xe5>
mov    $0x2,%r13d
jmp    1220 <encrypt+0xe0>
mov    $0x4,%eax
mov    $0x4,%r13d
jmp    1225 <encrypt+0xe5>
mov    $0x4,%r13d
mov    $0x6,%eax
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
mov    %eax,%ebx
call   1030 <AddRoundKey@plt>
mov    %r13d,%r12d
add    $0x9,%r12d
cmp    $0x2,%r12d
mov    $0x1,%r13d
cmovl  %r13d,%r12d
lea    0x1(%r12),%eax
mov    %eax,0x4(%rsp)
neg    %r12d
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %ebx,%esi
call   1040 <ByteSub_ShiftRow@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
mov    %r13d,%ecx
call   1050 <MixColumn_AddRoundKey@plt>
lea    (%r12,%r13,1),%eax
add    $0x1,%eax
mov    %r13d,%ecx
add    $0x1,%ecx
mov    %ecx,%r13d
cmp    $0x1,%eax
jne    1260 <encrypt+0x120>
mov    0x4(%rsp),%r13d
mov    %rbp,%rdi
mov    %ebx,%esi
call   1040 <ByteSub_ShiftRow@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
mov    %r13d,%ecx
call   1030 <AddRoundKey@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1030 <AddRoundKey@plt>
mov    $0x1,%r13d
cmp    $0xfffffff8,%r12d
jge    123a <encrypt+0xfa>
jmp    1294 <encrypt+0x154>

LLVM IR (-O0):
define i32 @encrypt(i32* %0, i32* %1, [120 x i32]* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [120 x i32]*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store [120 x i32]* %2, [120 x i32]** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%14 = load i32, i32* %10
%15 = load i32*, i32** %8
%16 = load [120 x i32]*, [120 x i32]** %9
%17 = bitcast [120 x i32]* %16 to i32**
%18 = call i32 @KeySchedule(i32 %14, i32* %15, i32** %17)
%19 = load i32, i32* %10
switch i32 %19, label %26 [
i32 128128, label %20
i32 192128, label %21
i32 256128, label %22
i32 128192, label %23
i32 192192, label %23
i32 256192, label %24
i32 128256, label %25
i32 192256, label %25
i32 256256, label %25
]
20: ; preds = %6
store i32 0, i32* %12
store i32 4, i32* %11
br label %26
21: ; preds = %6
store i32 2, i32* %12
store i32 4, i32* %11
br label %26
22: ; preds = %6
store i32 4, i32* %12
store i32 4, i32* %11
br label %26
23: ; preds = %6, %6
store i32 2, i32* %12
store i32 6, i32* %11
br label %26
24: ; preds = %6
store i32 4, i32* %12
store i32 6, i32* %11
br label %26
25: ; preds = %6, %6, %6
store i32 4, i32* %12
store i32 8, i32* %11
br label %26
26: ; preds = %6, %25, %24, %23, %22, %21, %20
%27 = load i32*, i32** %7
%28 = load [120 x i32]*, [120 x i32]** %9
%29 = bitcast [120 x i32]* %28 to i32**
%30 = load i32, i32* %10
%31 = call i32 @AddRoundKey(i32* %27, i32** %29, i32 %30, i32 0)
store i32 1, i32* %13
br label %32
32: ; preds = %47, %26
%33 = load i32, i32* %13
%34 = load i32, i32* %12
%35 = add nsw i32 %34, 9
%36 = icmp sle i32 %33, %35
br i1 %36, label %37, label %50
37: ; preds = %32
%38 = load i32*, i32** %7
%39 = load i32, i32* %11
%40 = call i32 @ByteSub_ShiftRow(i32* %38, i32 %39)
%41 = load i32*, i32** %7
%42 = load i32, i32* %11
%43 = load [120 x i32]*, [120 x i32]** %9
%44 = bitcast [120 x i32]* %43 to i32**
%45 = load i32, i32* %13
%46 = call i32 @MixColumn_AddRoundKey(i32* %41, i32 %42, i32** %44, i32 %45)
br label %47
47: ; preds = %37
%48 = load i32, i32* %13
%49 = add nsw i32 %48, 1
store i32 %49, i32* %13
br label %32
50: ; preds = %32
%51 = load i32*, i32** %7
%52 = load i32, i32* %11
%53 = call i32 @ByteSub_ShiftRow(i32* %51, i32 %52)
%54 = load i32*, i32** %7
%55 = load [120 x i32]*, [120 x i32]** %9
%56 = bitcast [120 x i32]* %55 to i32**
%57 = load i32, i32* %10
%58 = load i32, i32* %13
%59 = call i32 @AddRoundKey(i32* %54, i32** %56, i32 %57, i32 %58)
ret i32 0
}

LLVM IR (-O2):
define i32 @encrypt(i32* %0, i32* %1, [120 x i32]* %2, i32 %3, i32 %4, i32 %5) {
%7 = bitcast [120 x i32]* %2 to i32**
%8 = tail call i32 @KeySchedule(i32 %3, i32* %1, i32** %7)
switch i32 %3, label %18 [
i32 128128, label %14
i32 192128, label %9
i32 256128, label %10
i32 128192, label %11
i32 192192, label %11
i32 256192, label %12
i32 128256, label %13
i32 192256, label %13
i32 256256, label %13
]
9: ; preds = %6
br label %14
10: ; preds = %6
br label %14
11: ; preds = %6, %6
br label %14
12: ; preds = %6
br label %14
13: ; preds = %6, %6, %6
br label %14
14: ; preds = %13, %12, %11, %10, %9, %6
%15 = phi i32 [ 4, %9 ], [ 4, %10 ], [ 6, %11 ], [ 6, %12 ], [ 8, %13 ], [ 4, %6 ]
%16 = phi i32 [ 2, %9 ], [ 4, %10 ], [ 2, %11 ], [ 4, %12 ], [ 4, %13 ], [ 0, %6 ]
%17 = tail call i32 @AddRoundKey(i32* %0, i32** %7, i32 %3, i32 0)
br label %21
18: ; preds = %6
%19 = tail call i32 @AddRoundKey(i32* %0, i32** %7, i32 %3, i32 0)
%20 = icmp slt i32 %5, -8
br i1 %20, label %33, label %21
21: ; preds = %14, %18
%22 = phi i32 [ %16, %14 ], [ %5, %18 ]
%23 = phi i32 [ %15, %14 ], [ %4, %18 ]
%24 = add i32 %22, 9
%25 = call i32 @llvm.smax.i32(i32 %24, i32 1)
%26 = add nuw i32 %25, 1
br label %27
27: ; preds = %21, %27
%28 = phi i32 [ %31, %27 ], [ 1, %21 ]
%29 = tail call i32 @ByteSub_ShiftRow(i32* %0, i32 %23)
%30 = tail call i32 @MixColumn_AddRoundKey(i32* %0, i32 %23, i32** %7, i32 %28)
%31 = add nuw i32 %28, 1
%32 = icmp eq i32 %28, %25
br i1 %32, label %33, label %27
33: ; preds = %27, %18
%34 = phi i32 [ %4, %18 ], [ %23, %27 ]
%35 = phi i32 [ 1, %18 ], [ %26, %27 ]
%36 = tail call i32 @ByteSub_ShiftRow(i32* %0, i32 %34)
%37 = tail call i32 @AddRoundKey(i32* %0, i32** %7, i32 %3, i32 %35)
ret i32 0
}