#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*/ aes256_add_round_key(unsigned char *, unsigned char *);
int /*<<< orphan*/ aes256_inv_full_round(unsigned char *);
int /*<<< orphan*/ aes256_inv_initial_round(unsigned char *, unsigned char *);
int /*<<< orphan*/ aes256_key_schedule(unsigned char const *, unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
void aes256_decrypt_block(const unsigned char *state, const unsigned char *key,
                          unsigned char *out) {
  int i;
  unsigned char key_schedule[240];
  memcpy(out, state, 16);
  aes256_key_schedule(key, key_schedule);
  aes256_inv_initial_round(out, key_schedule + 224);
  for (i = 13; i > 0; i--) {
    aes256_add_round_key(out, key_schedule + (16 * i));
    aes256_inv_full_round(out);
  }
  aes256_add_round_key(out, key_schedule);
}


x86 assembly (clang, -O0):
<aes256_decrypt_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x10,%edx
call   1070 <memcpy@plt>
mov    -0x10(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1050 <aes256_key_schedule@plt>
mov    -0x18(%rbp),%rdi
lea    -0x110(%rbp),%rsi
add    $0xe0,%rsi
call   1040 <aes256_inv_initial_round@plt>
movl   $0xd,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11e3 <aes256_decrypt_block+0x93>
mov    -0x18(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rsi
call   1030 <aes256_add_round_key@plt>
mov    -0x18(%rbp),%rdi
call   1060 <aes256_inv_full_round@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a7 <aes256_decrypt_block+0x57>
mov    -0x18(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1030 <aes256_add_round_key@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes256_decrypt_block>:
push   %r15
push   %r14
push   %rbx
sub    $0xf0,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rsi
mov    %rdx,%rdi
mov    $0x10,%edx
call   1070 <memcpy@plt>
mov    %rsp,%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <aes256_key_schedule@plt>
lea    0xe0(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <aes256_inv_initial_round@plt>
lea    0xd0(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <aes256_add_round_key@plt>
mov    %rbx,%rdi
call   1060 <aes256_inv_full_round@plt>
lea    0xc0(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <aes256_add_round_key@plt>
mov    %rbx,%rdi
call   1060 <aes256_inv_full_round@plt>
lea    0xb0(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <aes256_add_round_key@plt>
mov    %rbx,%rdi
call   1060 <aes256_inv_full_round@plt>
lea    0xa0(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <aes256_add_round_key@plt>
mov    %rbx,%rdi
call   1060 <aes256_inv_full_round@plt>
lea    0x90(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <aes256_add_round_key@plt>
mov    %rbx,%rdi
call   1060 <aes256_inv_full_round@plt>
lea    0x80(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <aes256_add_round_key@plt>
mov    %rbx,%rdi
call   1060 <aes256_inv_full_round@plt>
lea    0x70(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <aes256_add_round_key@plt>
mov    %rbx,%rdi
call   1060 <aes256_inv_full_round@plt>
lea    0x60(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <aes256_add_round_key@plt>
mov    %rbx,%rdi
call   1060 <aes256_inv_full_round@plt>
lea    0x50(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <aes256_add_round_key@plt>
mov    %rbx,%rdi
call   1060 <aes256_inv_full_round@plt>
lea    0x40(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <aes256_add_round_key@plt>
mov    %rbx,%rdi
call   1060 <aes256_inv_full_round@plt>
lea    0x30(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <aes256_add_round_key@plt>
mov    %rbx,%rdi
call   1060 <aes256_inv_full_round@plt>
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <aes256_add_round_key@plt>
mov    %rbx,%rdi
call   1060 <aes256_inv_full_round@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <aes256_add_round_key@plt>
mov    %rbx,%rdi
call   1060 <aes256_inv_full_round@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <aes256_add_round_key@plt>
add    $0xf0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @aes256_decrypt_block(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [240 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = load i8*, i8** %4
%11 = call i32 @memcpy(i8* %9, i8* %10, i32 16)
%12 = load i8*, i8** %5
%13 = getelementptr inbounds [240 x i8], [240 x i8]* %8, i64 0, i64 0
%14 = call i32 @aes256_key_schedule(i8* %12, i8* %13)
%15 = load i8*, i8** %6
%16 = getelementptr inbounds [240 x i8], [240 x i8]* %8, i64 0, i64 0
%17 = getelementptr inbounds i8, i8* %16, i64 224
%18 = call i32 @aes256_inv_initial_round(i8* %15, i8* %17)
store i32 13, i32* %7
br label %19
19: ; preds = %32, %3
%20 = load i32, i32* %7
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %19
%23 = load i8*, i8** %6
%24 = getelementptr inbounds [240 x i8], [240 x i8]* %8, i64 0, i64 0
%25 = load i32, i32* %7
%26 = mul nsw i32 16, %25
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
%29 = call i32 @aes256_add_round_key(i8* %23, i8* %28)
%30 = load i8*, i8** %6
%31 = call i32 @aes256_inv_full_round(i8* %30)
br label %32
32: ; preds = %22
%33 = load i32, i32* %7
%34 = add nsw i32 %33, -1
store i32 %34, i32* %7
br label %19
35: ; preds = %19
%36 = load i8*, i8** %6
%37 = getelementptr inbounds [240 x i8], [240 x i8]* %8, i64 0, i64 0
%38 = call i32 @aes256_add_round_key(i8* %36, i8* %37)
ret void
}

LLVM IR (-O2):
define void @aes256_decrypt_block(i8* %0, i8* %1, i8* %2) {
%4 = alloca [240 x i8]
%5 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @memcpy(i8* %2, i8* %0, i32 16)
%7 = call i32 @aes256_key_schedule(i8* %1, i8* %5)
%8 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 224
%9 = call i32 @aes256_inv_initial_round(i8* %2, i8* %8)
%10 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 208
%11 = call i32 @aes256_add_round_key(i8* %2, i8* %10)
%12 = call i32 @aes256_inv_full_round(i8* %2)
%13 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 192
%14 = call i32 @aes256_add_round_key(i8* %2, i8* %13)
%15 = call i32 @aes256_inv_full_round(i8* %2)
%16 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 176
%17 = call i32 @aes256_add_round_key(i8* %2, i8* %16)
%18 = call i32 @aes256_inv_full_round(i8* %2)
%19 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 160
%20 = call i32 @aes256_add_round_key(i8* %2, i8* %19)
%21 = call i32 @aes256_inv_full_round(i8* %2)
%22 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 144
%23 = call i32 @aes256_add_round_key(i8* %2, i8* %22)
%24 = call i32 @aes256_inv_full_round(i8* %2)
%25 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 128
%26 = call i32 @aes256_add_round_key(i8* %2, i8* %25)
%27 = call i32 @aes256_inv_full_round(i8* %2)
%28 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 112
%29 = call i32 @aes256_add_round_key(i8* %2, i8* %28)
%30 = call i32 @aes256_inv_full_round(i8* %2)
%31 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 96
%32 = call i32 @aes256_add_round_key(i8* %2, i8* %31)
%33 = call i32 @aes256_inv_full_round(i8* %2)
%34 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 80
%35 = call i32 @aes256_add_round_key(i8* %2, i8* %34)
%36 = call i32 @aes256_inv_full_round(i8* %2)
%37 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 64
%38 = call i32 @aes256_add_round_key(i8* %2, i8* %37)
%39 = call i32 @aes256_inv_full_round(i8* %2)
%40 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 48
%41 = call i32 @aes256_add_round_key(i8* %2, i8* %40)
%42 = call i32 @aes256_inv_full_round(i8* %2)
%43 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 32
%44 = call i32 @aes256_add_round_key(i8* %2, i8* %43)
%45 = call i32 @aes256_inv_full_round(i8* %2)
%46 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 16
%47 = call i32 @aes256_add_round_key(i8* %2, i8* %46)
%48 = call i32 @aes256_inv_full_round(i8* %2)
%49 = call i32 @aes256_add_round_key(i8* %2, i8* %5)
ret void
}