#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 EINVAL;
int ENOMEM;
int /*<<< orphan*/ aes_add_round_key(unsigned char *, unsigned char *);
int aes_get_num_rounds(int const);
int /*<<< orphan*/ aes_inv_key_expand(unsigned char *, unsigned char *,
                                      int const, unsigned char *, int);
int /*<<< orphan*/ aes_inv_mix_columns(unsigned char *);
int /*<<< orphan*/ aes_inv_shift_rows(unsigned char *);
int /*<<< orphan*/ aes_inv_sub_bytes(unsigned char *);
int /*<<< orphan*/ aes_key_expand(unsigned char *, unsigned char *, int const,
                                  unsigned char *, int);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(int const);
int /*<<< orphan*/ printf(char *);
int aes_decrypt_block(const unsigned char *cipher_text,
                      const unsigned char *key, const int key_len,
                      unsigned char *plain_text) {
  int num_rounds = aes_get_num_rounds(key_len);
  if (num_rounds < 0) {
    printf("ERROR: aes_get_num_rounds() failed\n");
    return -EINVAL;
  }
  unsigned char rcon;
  unsigned char state[16];
  unsigned char round_key[16];
  unsigned char *full_key =
      (unsigned char *)malloc(key_len * sizeof(unsigned char));
  if (full_key == NULL) {
    printf("ERROR: malloc() failed\n");
    return -ENOMEM;
  }
  for (int i = 0; i < 16; i++) {
    state[i] = cipher_text[i];
  }
  for (int i = 0; i < key_len; i++) {
    full_key[i] = key[i];
  }
  for (int i = 0; i < 16; i++) {
    round_key[i] = full_key[i];
  }
  rcon = 0;
  for (int j = 0; j < num_rounds; j++) {
    aes_key_expand(round_key, full_key, key_len, &rcon, j);
  }
  rcon = 0;
  aes_add_round_key(state, round_key);
  for (int j = 0; j < num_rounds; j++) {
    aes_inv_sub_bytes(state);
    aes_inv_shift_rows(state);
    if (j < (num_rounds - 1)) {
      aes_inv_mix_columns(state);
    }
    aes_inv_key_expand(round_key, full_key, key_len, &rcon, j);
    if (j < (num_rounds - 1)) {
      aes_inv_mix_columns(round_key);
    }
    aes_add_round_key(state, round_key);
  }
  for (int i = 0; i < 16; i++) {
    plain_text[i] = state[i];
  }
  free(full_key);
  return 0;
}


x86 assembly (clang, -O0):
<aes_decrypt_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   10a0 <aes_get_num_rounds@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11eb <aes_decrypt_block+0x4b>
lea    0xe2d(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
mov    0x2df7(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    13df <aes_decrypt_block+0x23f>
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1228 <aes_decrypt_block+0x88>
lea    0xe14(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
mov    0x2dc2(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    13df <aes_decrypt_block+0x23f>
movl   $0x0,-0x5c(%rbp)
cmpl   $0x10,-0x5c(%rbp)
jge    125a <aes_decrypt_block+0xba>
mov    -0x10(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x5c(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    122f <aes_decrypt_block+0x8f>
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1291 <aes_decrypt_block+0xf1>
mov    -0x18(%rbp),%rax
movslq -0x60(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x58(%rbp),%rax
movslq -0x60(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1261 <aes_decrypt_block+0xc1>
movl   $0x0,-0x64(%rbp)
cmpl   $0x10,-0x64(%rbp)
jge    12c3 <aes_decrypt_block+0x123>
mov    -0x58(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x64(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1298 <aes_decrypt_block+0xf8>
movb   $0x0,-0x2d(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1300 <aes_decrypt_block+0x160>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x68(%rbp),%r8d
lea    -0x2d(%rbp),%rcx
call   1040 <aes_key_expand@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    12ce <aes_decrypt_block+0x12e>
movb   $0x0,-0x2d(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1050 <aes_add_round_key@plt>
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    139d <aes_decrypt_block+0x1fd>
lea    -0x40(%rbp),%rdi
call   10c0 <aes_inv_sub_bytes@plt>
lea    -0x40(%rbp),%rdi
call   1070 <aes_inv_shift_rows@plt>
mov    -0x6c(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1350 <aes_decrypt_block+0x1b0>
lea    -0x40(%rbp),%rdi
call   1090 <aes_inv_mix_columns@plt>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x6c(%rbp),%r8d
lea    -0x2d(%rbp),%rcx
call   10b0 <aes_inv_key_expand@plt>
mov    -0x6c(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1382 <aes_decrypt_block+0x1e2>
lea    -0x50(%rbp),%rdi
call   1090 <aes_inv_mix_columns@plt>
lea    -0x40(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1050 <aes_add_round_key@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1318 <aes_decrypt_block+0x178>
movl   $0x0,-0x70(%rbp)
cmpl   $0x10,-0x70(%rbp)
jge    13cf <aes_decrypt_block+0x22f>
movslq -0x70(%rbp),%rax
mov    -0x40(%rbp,%rax,1),%dl
mov    -0x28(%rbp),%rax
movslq -0x70(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    13a4 <aes_decrypt_block+0x204>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_decrypt_block>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r15
mov    %edx,%r12d
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %edx,%edi
call   10a0 <aes_get_num_rounds@plt>
mov    %rax,0x8(%rsp)
test   %eax,%eax
js     1367 <aes_decrypt_block+0x1c7>
mov    %r12d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     137c <aes_decrypt_block+0x1dc>
mov    %rax,%rbx
mov    %r15,0x30(%rsp)
movups (%r14),%xmm0
movaps %xmm0,0x20(%rsp)
test   %r12d,%r12d
mov    0x8(%rsp),%r15
jle    128c <aes_decrypt_block+0xec>
mov    %r12d,%r9d
cmp    $0x8,%r12d
jb     1221 <aes_decrypt_block+0x81>
lea    (%r9,%rbp,1),%rcx
cmp    %rbx,%rcx
jbe    13ca <aes_decrypt_block+0x22a>
lea    (%rbx,%r9,1),%rcx
cmp    %rbp,%rcx
jbe    13ca <aes_decrypt_block+0x22a>
xor    %ecx,%ecx
mov    %rcx,%rdx
not    %rdx
add    %r9,%rdx
mov    %r9,%rsi
and    $0x3,%rsi
je     1252 <aes_decrypt_block+0xb2>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x0(%rbp,%rcx,1),%eax
mov    %al,(%rbx,%rcx,1)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rsi
jne    1240 <aes_decrypt_block+0xa0>
cmp    $0x3,%rdx
jb     128c <aes_decrypt_block+0xec>
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%rbp,%rcx,1),%eax
mov    %al,(%rbx,%rcx,1)
movzbl 0x1(%rbp,%rcx,1),%eax
mov    %al,0x1(%rbx,%rcx,1)
movzbl 0x2(%rbp,%rcx,1),%eax
mov    %al,0x2(%rbx,%rcx,1)
movzbl 0x3(%rbp,%rcx,1),%eax
mov    %al,0x3(%rbx,%rcx,1)
add    $0x4,%rcx
cmp    %rcx,%r9
jne    1260 <aes_decrypt_block+0xc0>
movups (%rbx),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x7(%rsp)
test   %r15d,%r15d
jle    1395 <aes_decrypt_block+0x1f5>
xor    %ebp,%ebp
lea    0x10(%rsp),%r14
lea    0x7(%rsp),%r13
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
mov    %r13,%rcx
mov    %ebp,%r8d
call   1040 <aes_key_expand@plt>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    12b0 <aes_decrypt_block+0x110>
movb   $0x0,0x7(%rsp)
lea    0x20(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1060 <aes_add_round_key@plt>
test   %r15d,%r15d
jle    13a4 <aes_decrypt_block+0x204>
mov    0x8(%rsp),%rax
lea    -0x1(%rax),%r15d
xor    %ebp,%ebp
lea    0x20(%rsp),%r13
lea    0x10(%rsp),%r14
jmp    132a <aes_decrypt_block+0x18a>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
lea    0x7(%rsp),%rcx
mov    %ebp,%r8d
call   10b0 <aes_inv_key_expand@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1060 <aes_add_round_key@plt>
add    $0x1,%ebp
cmp    %ebp,0x8(%rsp)
je     13a4 <aes_decrypt_block+0x204>
mov    %r13,%rdi
call   10c0 <aes_inv_sub_bytes@plt>
mov    %r13,%rdi
call   1070 <aes_inv_shift_rows@plt>
cmp    %r15d,%ebp
jge    1300 <aes_decrypt_block+0x160>
mov    %r13,%rdi
call   1090 <aes_inv_mix_columns@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
lea    0x7(%rsp),%rcx
mov    %ebp,%r8d
call   10b0 <aes_inv_key_expand@plt>
mov    %r14,%rdi
call   1090 <aes_inv_mix_columns@plt>
jmp    1316 <aes_decrypt_block+0x176>
lea    0xca9(%rip),%rdi
call   1050 <puts@plt>
mov    0x2c5e(%rip),%rcx
jmp    138f <aes_decrypt_block+0x1ef>
lea    0xc7d(%rip),%rdi
call   1050 <puts@plt>
mov    0x2c51(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    13bb <aes_decrypt_block+0x21b>
lea    0x20(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1060 <aes_add_round_key@plt>
movaps 0x20(%rsp),%xmm0
mov    0x30(%rsp),%rax
movups %xmm0,(%rax)
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x20,%r12d
jae    13d7 <aes_decrypt_block+0x237>
xor    %ecx,%ecx
jmp    14be <aes_decrypt_block+0x31e>
mov    %r9d,%ecx
and    $0xffffffe0,%ecx
lea    -0x20(%rcx),%rdx
mov    %rdx,%rsi
shr    $0x5,%rsi
add    $0x1,%rsi
mov    %esi,%r8d
and    $0x3,%r8d
cmp    $0x60,%rdx
jae    13fd <aes_decrypt_block+0x25d>
xor    %edi,%edi
jmp    1469 <aes_decrypt_block+0x2c9>
and    $0xfffffffffffffffc,%rsi
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movups 0x0(%rbp,%rdi,1),%xmm0
movups 0x10(%rbp,%rdi,1),%xmm1
movups %xmm0,(%rbx,%rdi,1)
movups %xmm1,0x10(%rbx,%rdi,1)
movups 0x20(%rbp,%rdi,1),%xmm0
movups 0x30(%rbp,%rdi,1),%xmm1
movups %xmm0,0x20(%rbx,%rdi,1)
movups %xmm1,0x30(%rbx,%rdi,1)
movups 0x40(%rbp,%rdi,1),%xmm0
movups 0x50(%rbp,%rdi,1),%xmm1
movups %xmm0,0x40(%rbx,%rdi,1)
movups %xmm1,0x50(%rbx,%rdi,1)
movups 0x60(%rbp,%rdi,1),%xmm0
movups 0x70(%rbp,%rdi,1),%xmm1
movups %xmm0,0x60(%rbx,%rdi,1)
movups %xmm1,0x70(%rbx,%rdi,1)
sub    $0xffffffffffffff80,%rdi
add    $0xfffffffffffffffc,%rsi
jne    1410 <aes_decrypt_block+0x270>
test   %r8,%r8
je     14ab <aes_decrypt_block+0x30b>
lea    (%rbx,%rdi,1),%rsi
add    $0x10,%rsi
add    %rbp,%rdi
add    $0x10,%rdi
shl    $0x5,%r8
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movups -0x10(%rdi,%rdx,1),%xmm0
movups (%rdi,%rdx,1),%xmm1
movups %xmm0,-0x10(%rsi,%rdx,1)
movups %xmm1,(%rsi,%rdx,1)
add    $0x20,%rdx
cmp    %rdx,%r8
jne    1490 <aes_decrypt_block+0x2f0>
cmp    %r9,%rcx
je     128c <aes_decrypt_block+0xec>
test   $0x18,%r9b
je     1223 <aes_decrypt_block+0x83>
mov    %rcx,%rdx
mov    %r9d,%ecx
and    $0xfffffff8,%ecx
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp,%rdx,1),%rsi
mov    %rsi,(%rbx,%rdx,1)
add    $0x8,%rdx
cmp    %rdx,%rcx
jne    14d0 <aes_decrypt_block+0x330>
cmp    %r9,%rcx
je     128c <aes_decrypt_block+0xec>
jmp    1223 <aes_decrypt_block+0x83>

LLVM IR (-O0):
@.str = [36 x i8] c"ERROR: aes_get_num_rounds() failed\0A\00"
@EINVAL = global i32 0
@.str.1 = [24 x i8] c"ERROR: malloc() failed\0A\00"
@ENOMEM = global i32 0
define i32 @aes_decrypt_block(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8
%12 = alloca [16 x i8]
%13 = alloca [16 x i8]
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%21 = load i32, i32* %8
%22 = call i32 @aes_get_num_rounds(i32 %21)
store i32 %22, i32* %10
%23 = load i32, i32* %10
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %4
%26 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%27 = load i32, i32* @EINVAL
%28 = sub nsw i32 0, %27
store i32 %28, i32* %5
br label %165
29: ; preds = %4
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 1
%33 = trunc i64 %32 to i32
%34 = call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %14
%36 = load i8*, i8** %14
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %42
38: ; preds = %29
%39 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* @ENOMEM
%41 = sub nsw i32 0, %40
store i32 %41, i32* %5
br label %165
42: ; preds = %29
store i32 0, i32* %15
br label %43
43: ; preds = %55, %42
%44 = load i32, i32* %15
%45 = icmp slt i32 %44, 16
br i1 %45, label %46, label %58
46: ; preds = %43
%47 = load i8*, i8** %6
%48 = load i32, i32* %15
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8, i8* %50
%52 = load i32, i32* %15
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 %53
store i8 %51, i8* %54
br label %55
55: ; preds = %46
%56 = load i32, i32* %15
%57 = add nsw i32 %56, 1
store i32 %57, i32* %15
br label %43
58: ; preds = %43
store i32 0, i32* %16
br label %59
59: ; preds = %73, %58
%60 = load i32, i32* %16
%61 = load i32, i32* %8
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %76
63: ; preds = %59
%64 = load i8*, i8** %7
%65 = load i32, i32* %16
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i8, i8* %67
%69 = load i8*, i8** %14
%70 = load i32, i32* %16
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
store i8 %68, i8* %72
br label %73
73: ; preds = %63
%74 = load i32, i32* %16
%75 = add nsw i32 %74, 1
store i32 %75, i32* %16
br label %59
76: ; preds = %59
store i32 0, i32* %17
br label %77
77: ; preds = %89, %76
%78 = load i32, i32* %17
%79 = icmp slt i32 %78, 16
br i1 %79, label %80, label %92
80: ; preds = %77
%81 = load i8*, i8** %14
%82 = load i32, i32* %17
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %81, i64 %83
%85 = load i8, i8* %84
%86 = load i32, i32* %17
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 %87
store i8 %85, i8* %88
br label %89
89: ; preds = %80
%90 = load i32, i32* %17
%91 = add nsw i32 %90, 1
store i32 %91, i32* %17
br label %77
92: ; preds = %77
store i8 0, i8* %11
store i32 0, i32* %18
br label %93
93: ; preds = %103, %92
%94 = load i32, i32* %18
%95 = load i32, i32* %10
%96 = icmp slt i32 %94, %95
br i1 %96, label %97, label %106
97: ; preds = %93
%98 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%99 = load i8*, i8** %14
%100 = load i32, i32* %8
%101 = load i32, i32* %18
%102 = call i32 @aes_key_expand(i8* %98, i8* %99, i32 %100, i8* %11, i32 %101)
br label %103
103: ; preds = %97
%104 = load i32, i32* %18
%105 = add nsw i32 %104, 1
store i32 %105, i32* %18
br label %93
106: ; preds = %93
store i8 0, i8* %11
%107 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%108 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%109 = call i32 @aes_add_round_key(i8* %107, i8* %108)
store i32 0, i32* %19
br label %110
110: ; preds = %143, %106
%111 = load i32, i32* %19
%112 = load i32, i32* %10
%113 = icmp slt i32 %111, %112
br i1 %113, label %114, label %146
114: ; preds = %110
%115 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%116 = call i32 @aes_inv_sub_bytes(i8* %115)
%117 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%118 = call i32 @aes_inv_shift_rows(i8* %117)
%119 = load i32, i32* %19
%120 = load i32, i32* %10
%121 = sub nsw i32 %120, 1
%122 = icmp slt i32 %119, %121
br i1 %122, label %123, label %126
123: ; preds = %114
%124 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%125 = call i32 @aes_inv_mix_columns(i8* %124)
br label %126
126: ; preds = %123, %114
%127 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%128 = load i8*, i8** %14
%129 = load i32, i32* %8
%130 = load i32, i32* %19
%131 = call i32 @aes_inv_key_expand(i8* %127, i8* %128, i32 %129, i8* %11, i32 %130)
%132 = load i32, i32* %19
%133 = load i32, i32* %10
%134 = sub nsw i32 %133, 1
%135 = icmp slt i32 %132, %134
br i1 %135, label %136, label %139
136: ; preds = %126
%137 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%138 = call i32 @aes_inv_mix_columns(i8* %137)
br label %139
139: ; preds = %136, %126
%140 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%141 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%142 = call i32 @aes_add_round_key(i8* %140, i8* %141)
br label %143
143: ; preds = %139
%144 = load i32, i32* %19
%145 = add nsw i32 %144, 1
store i32 %145, i32* %19
br label %110
146: ; preds = %110
store i32 0, i32* %20
br label %147
147: ; preds = %159, %146
%148 = load i32, i32* %20
%149 = icmp slt i32 %148, 16
br i1 %149, label %150, label %162
150: ; preds = %147
%151 = load i32, i32* %20
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 %152
%154 = load i8, i8* %153
%155 = load i8*, i8** %9
%156 = load i32, i32* %20
%157 = sext i32 %156 to i64
%158 = getelementptr inbounds i8, i8* %155, i64 %157
store i8 %154, i8* %158
br label %159
159: ; preds = %150
%160 = load i32, i32* %20
%161 = add nsw i32 %160, 1
store i32 %161, i32* %20
br label %147
162: ; preds = %147
%163 = load i8*, i8** %14
%164 = call i32 @free(i8* %163)
store i32 0, i32* %5
br label %165
165: ; preds = %162, %38, %25
%166 = load i32, i32* %5
ret i32 %166
}

LLVM IR (-O2):
@EINVAL = global i32 0
@ENOMEM = global i32 0
@str = [23 x i8] c"ERROR: malloc() failed\00"
@str.2 = [35 x i8] c"ERROR: aes_get_num_rounds() failed\00"
define i32 @aes_decrypt_block(i8* nocapture %0, i8* nocapture %1, i32 %2, i8* nocapture writeonly %3) {
%5 = alloca i8
%6 = alloca [16 x i8]
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%8 = alloca <16 x i8>
%9 = tail call i32 @aes_get_num_rounds(i32 %2)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.2, i64 0, i64 0))
%13 = load i32, i32* @EINVAL
%14 = sub nsw i32 0, %13
br label %205
15: ; preds = %4
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%17 = getelementptr inbounds <16 x i8>, <16 x i8>* %8, i64 0, i64 0
%18 = tail call i64 @malloc(i32 %2)
%19 = inttoptr i64 %18 to i8*
%20 = icmp eq i64 %18, 0
br i1 %20, label %23, label %21
21: ; preds = %15
%22 = icmp sgt i32 %2, 0
br i1 %22, label %27, label %152
23: ; preds = %15
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%25 = load i32, i32* @ENOMEM
%26 = sub nsw i32 0, %25
br label %203
27: ; preds = %21
%28 = zext i32 %2 to i64
%29 = icmp ult i32 %2, 8
br i1 %29, label %134, label %30
30: ; preds = %27
%31 = getelementptr i8, i8* %19, i64 %28
%32 = getelementptr i8, i8* %1, i64 %28
%33 = icmp ugt i8* %32, %19
%34 = icmp ugt i8* %31, %1
%35 = and i1 %33, %34
br i1 %35, label %134, label %36
36: ; preds = %30
%37 = icmp ult i32 %2, 32
br i1 %37, label %120, label %38
38: ; preds = %36
%39 = and i64 %28, 4294967264
%40 = add nsw i64 %39, -32
%41 = lshr exact i64 %40, 5
%42 = add nuw nsw i64 %41, 1
%43 = and i64 %42, 3
%44 = icmp ult i64 %40, 96
br i1 %44, label %96, label %45
45: ; preds = %38
%46 = and i64 %42, 1152921504606846972
br label %47
47: ; preds = %47, %45
%48 = phi i64 [ 0, %45 ], [ %93, %47 ]
%49 = phi i64 [ 0, %45 ], [ %94, %47 ]
%50 = getelementptr inbounds i8, i8* %1, i64 %48
%51 = bitcast i8* %50 to <16 x i8>*
%52 = load <16 x i8>, <16 x i8>* %51
%53 = getelementptr inbounds i8, i8* %50, i64 16
%54 = bitcast i8* %53 to <16 x i8>*
%55 = load <16 x i8>, <16 x i8>* %54
%56 = getelementptr inbounds i8, i8* %19, i64 %48
%57 = bitcast i8* %56 to <16 x i8>*
store <16 x i8> %52, <16 x i8>* %57
%58 = getelementptr inbounds i8, i8* %56, i64 16
%59 = bitcast i8* %58 to <16 x i8>*
store <16 x i8> %55, <16 x i8>* %59
%60 = or i64 %48, 32
%61 = getelementptr inbounds i8, i8* %1, i64 %60
%62 = bitcast i8* %61 to <16 x i8>*
%63 = load <16 x i8>, <16 x i8>* %62
%64 = getelementptr inbounds i8, i8* %61, i64 16
%65 = bitcast i8* %64 to <16 x i8>*
%66 = load <16 x i8>, <16 x i8>* %65
%67 = getelementptr inbounds i8, i8* %19, i64 %60
%68 = bitcast i8* %67 to <16 x i8>*
store <16 x i8> %63, <16 x i8>* %68
%69 = getelementptr inbounds i8, i8* %67, i64 16
%70 = bitcast i8* %69 to <16 x i8>*
store <16 x i8> %66, <16 x i8>* %70
%71 = or i64 %48, 64
%72 = getelementptr inbounds i8, i8* %1, i64 %71
%73 = bitcast i8* %72 to <16 x i8>*
%74 = load <16 x i8>, <16 x i8>* %73
%75 = getelementptr inbounds i8, i8* %72, i64 16
%76 = bitcast i8* %75 to <16 x i8>*
%77 = load <16 x i8>, <16 x i8>* %76
%78 = getelementptr inbounds i8, i8* %19, i64 %71
%79 = bitcast i8* %78 to <16 x i8>*
store <16 x i8> %74, <16 x i8>* %79
%80 = getelementptr inbounds i8, i8* %78, i64 16
%81 = bitcast i8* %80 to <16 x i8>*
store <16 x i8> %77, <16 x i8>* %81
%82 = or i64 %48, 96
%83 = getelementptr inbounds i8, i8* %1, i64 %82
%84 = bitcast i8* %83 to <16 x i8>*
%85 = load <16 x i8>, <16 x i8>* %84
%86 = getelementptr inbounds i8, i8* %83, i64 16
%87 = bitcast i8* %86 to <16 x i8>*
%88 = load <16 x i8>, <16 x i8>* %87
%89 = getelementptr inbounds i8, i8* %19, i64 %82
%90 = bitcast i8* %89 to <16 x i8>*
store <16 x i8> %85, <16 x i8>* %90
%91 = getelementptr inbounds i8, i8* %89, i64 16
%92 = bitcast i8* %91 to <16 x i8>*
store <16 x i8> %88, <16 x i8>* %92
%93 = add nuw i64 %48, 128
%94 = add i64 %49, 4
%95 = icmp eq i64 %94, %46
br i1 %95, label %96, label %47
96: ; preds = %47, %38
%97 = phi i64 [ 0, %38 ], [ %93, %47 ]
%98 = icmp eq i64 %43, 0
br i1 %98, label %115, label %99
99: ; preds = %96, %99
%100 = phi i64 [ %112, %99 ], [ %97, %96 ]
%101 = phi i64 [ %113, %99 ], [ 0, %96 ]
%102 = getelementptr inbounds i8, i8* %1, i64 %100
%103 = bitcast i8* %102 to <16 x i8>*
%104 = load <16 x i8>, <16 x i8>* %103
%105 = getelementptr inbounds i8, i8* %102, i64 16
%106 = bitcast i8* %105 to <16 x i8>*
%107 = load <16 x i8>, <16 x i8>* %106
%108 = getelementptr inbounds i8, i8* %19, i64 %100
%109 = bitcast i8* %108 to <16 x i8>*
store <16 x i8> %104, <16 x i8>* %109
%110 = getelementptr inbounds i8, i8* %108, i64 16
%111 = bitcast i8* %110 to <16 x i8>*
store <16 x i8> %107, <16 x i8>* %111
%112 = add nuw i64 %100, 32
%113 = add i64 %101, 1
%114 = icmp eq i64 %113, %43
br i1 %114, label %115, label %99
115: ; preds = %99, %96
%116 = icmp eq i64 %39, %28
br i1 %116, label %152, label %117
117: ; preds = %115
%118 = and i64 %28, 24
%119 = icmp eq i64 %118, 0
br i1 %119, label %134, label %120
120: ; preds = %36, %117
%121 = phi i64 [ %39, %117 ], [ 0, %36 ]
%122 = and i64 %28, 4294967288
br label %123
123: ; preds = %123, %120
%124 = phi i64 [ %121, %120 ], [ %130, %123 ]
%125 = getelementptr inbounds i8, i8* %1, i64 %124
%126 = bitcast i8* %125 to <8 x i8>*
%127 = load <8 x i8>, <8 x i8>* %126
%128 = getelementptr inbounds i8, i8* %19, i64 %124
%129 = bitcast i8* %128 to <8 x i8>*
store <8 x i8> %127, <8 x i8>* %129
%130 = add nuw i64 %124, 8
%131 = icmp eq i64 %130, %122
br i1 %131, label %132, label %123
132: ; preds = %123
%133 = icmp eq i64 %122, %28
br i1 %133, label %152, label %134
134: ; preds = %30, %27, %117, %132
%135 = phi i64 [ 0, %27 ], [ 0, %30 ], [ %39, %117 ], [ %122, %132 ]
%136 = xor i64 %135, -1
%137 = add nsw i64 %136, %28
%138 = and i64 %28, 3
%139 = icmp eq i64 %138, 0
br i1 %139, label %149, label %140
140: ; preds = %134, %140
%141 = phi i64 [ %146, %140 ], [ %135, %134 ]
%142 = phi i64 [ %147, %140 ], [ 0, %134 ]
%143 = getelementptr inbounds i8, i8* %1, i64 %141
%144 = load i8, i8* %143
%145 = getelementptr inbounds i8, i8* %19, i64 %141
store i8 %144, i8* %145
%146 = add nuw nsw i64 %141, 1
%147 = add i64 %142, 1
%148 = icmp eq i64 %147, %138
br i1 %148, label %149, label %140
149: ; preds = %140, %134
%150 = phi i64 [ %135, %134 ], [ %146, %140 ]
%151 = icmp ult i64 %137, 3
br i1 %151, label %152, label %158
152: ; preds = %149, %158, %115, %132, %21
%153 = inttoptr i64 %18 to <16 x i8>*
%154 = load <16 x i8>, <16 x i8>* %153
store <16 x i8> %154, <16 x i8>* %8
store i8 0, i8* %5
%155 = icmp sgt i32 %9, 0
br i1 %155, label %181, label %156
156: ; preds = %152
%157 = call i32 @aes_add_round_key(i8* %16, i8* %17)
br label %186
158: ; preds = %149, %158
%159 = phi i64 [ %175, %158 ], [ %150, %149 ]
%160 = getelementptr inbounds i8, i8* %1, i64 %159
%161 = load i8, i8* %160
%162 = getelementptr inbounds i8, i8* %19, i64 %159
store i8 %161, i8* %162
%163 = add nuw nsw i64 %159, 1
%164 = getelementptr inbounds i8, i8* %1, i64 %163
%165 = load i8, i8* %164
%166 = getelementptr inbounds i8, i8* %19, i64 %163
store i8 %165, i8* %166
%167 = add nuw nsw i64 %159, 2
%168 = getelementptr inbounds i8, i8* %1, i64 %167
%169 = load i8, i8* %168
%170 = getelementptr inbounds i8, i8* %19, i64 %167
store i8 %169, i8* %170
%171 = add nuw nsw i64 %159, 3
%172 = getelementptr inbounds i8, i8* %1, i64 %171
%173 = load i8, i8* %172
%174 = getelementptr inbounds i8, i8* %19, i64 %171
store i8 %173, i8* %174
%175 = add nuw nsw i64 %159, 4
%176 = icmp eq i64 %175, %28
br i1 %176, label %152, label %158
177: ; preds = %181
store i8 0, i8* %5
%178 = call i32 @aes_add_round_key(i8* %16, i8* %17)
br i1 %155, label %179, label %186
179: ; preds = %177
%180 = add nsw i32 %9, -1
br label %188
181: ; preds = %152, %181
%182 = phi i32 [ %184, %181 ], [ 0, %152 ]
%183 = call i32 @aes_key_expand(i8* %17, i8* %19, i32 %2, i8* %5, i32 %182)
%184 = add nuw nsw i32 %182, 1
%185 = icmp eq i32 %184, %9
br i1 %185, label %177, label %181
186: ; preds = %199, %156, %177
%187 = call i32 @free(i8* %19)
br label %203
188: ; preds = %179, %199
%189 = phi i32 [ 0, %179 ], [ %201, %199 ]
%190 = call i32 @aes_inv_sub_bytes(i8* %16)
%191 = call i32 @aes_inv_shift_rows(i8* %16)
%192 = icmp slt i32 %189, %180
br i1 %192, label %193, label %197
193: ; preds = %188
%194 = call i32 @aes_inv_mix_columns(i8* %16)
%195 = call i32 @aes_inv_key_expand(i8* %17, i8* %19, i32 %2, i8* %5, i32 %189)
%196 = call i32 @aes_inv_mix_columns(i8* %17)
br label %199
197: ; preds = %188
%198 = call i32 @aes_inv_key_expand(i8* %17, i8* %19, i32 %2, i8* %5, i32 %189)
br label %199
199: ; preds = %197, %193
%200 = call i32 @aes_add_round_key(i8* %16, i8* %17)
%201 = add nuw nsw i32 %189, 1
%202 = icmp eq i32 %201, %9
br i1 %202, label %186, label %188
203: ; preds = %186, %23
%204 = phi i32 [ %26, %23 ], [ 0, %186 ]
br label %205
205: ; preds = %203, %11
%206 = phi i32 [ %14, %11 ], [ %204, %203 ]
ret i32 %206
}