#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 */
typedef int uint_fast8_t;
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
void setup_aeskey(uint_fast8_t keyno, int value, void *key) {
  if (!key)
    return;
  volatile uint32_t *aes_regs[] = {
      (volatile uint32_t *)0x19009060, (volatile uint32_t *)0x10009090,
      (volatile uint32_t *)0x100090C0, (volatile uint32_t *)0x100090F0};
  uint32_t *_key = (uint32_t *)key;
  *((volatile uint32_t *)0x10009000) =
      (*((volatile uint32_t *)0x10009000) & ~(0x00800000 | 0x02000000)) |
      (value << 23);
  if (keyno > 3) {
    if (keyno > 0x3F)
      return;
    *((volatile uint8_t *)0x10009011) =
        (*((volatile uint8_t *)0x10009011) >> 6 << 6) | (uint8_t)keyno | 0x80;
    *((volatile uint32_t *)0x10009108) = _key[0];
    *((volatile uint32_t *)0x10009108) = _key[1];
    *((volatile uint32_t *)0x10009108) = _key[2];
    *((volatile uint32_t *)0x10009108) = _key[3];
  } else {
    volatile uint32_t *aes_reg = aes_regs[keyno];
    if (value & 0x4) {
      aes_reg[0] = _key[3];
      aes_reg[1] = _key[2];
      aes_reg[2] = _key[1];
      aes_reg[3] = _key[0];
    } else {
      aes_reg[0] = _key[0];
      aes_reg[1] = _key[1];
      aes_reg[2] = _key[2];
      aes_reg[3] = _key[3];
    }
  }
}


x86 assembly (clang, -O0):
<setup_aeskey>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    111e <setup_aeskey+0x1e>
jmp    1272 <setup_aeskey+0x172>
mov    0xedb(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed8(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xed5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xed2(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x10009000,%eax
mov    (%rax),%ecx
and    $0xfd7fffff,%ecx
mov    -0x8(%rbp),%eax
shl    $0x17,%eax
or     %eax,%ecx
mov    $0x10009000,%eax
mov    %ecx,(%rax)
cmpl   $0x3,-0x4(%rbp)
jle    11e0 <setup_aeskey+0xe0>
cmpl   $0x3f,-0x4(%rbp)
jle    1187 <setup_aeskey+0x87>
jmp    1272 <setup_aeskey+0x172>
mov    $0x10009011,%eax
mov    (%rax),%ecx
sar    $0x6,%ecx
shl    $0x6,%ecx
or     -0x4(%rbp),%ecx
or     $0x80,%ecx
mov    $0x10009011,%eax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
mov    $0x10009108,%eax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%ecx
mov    $0x10009108,%eax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%ecx
mov    $0x10009108,%eax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    0xc(%rax),%ecx
mov    $0x10009108,%eax
mov    %ecx,(%rax)
jmp    1272 <setup_aeskey+0x172>
movslq -0x4(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1237 <setup_aeskey+0x137>
mov    -0x38(%rbp),%rax
mov    0xc(%rax),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,0xc(%rax)
jmp    126d <setup_aeskey+0x16d>
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x38(%rbp),%rax
mov    0xc(%rax),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,0xc(%rax)
jmp    1272 <setup_aeskey+0x172>
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_aeskey>:
test   %rdx,%rdx
je     11b2 <setup_aeskey+0xb2>
mov    $0xfd7fffff,%eax
and    0x10009000,%eax
mov    %esi,%ecx
shl    $0x17,%ecx
or     %eax,%ecx
mov    %ecx,0x10009000
cmp    $0x4,%edi
jl     1173 <setup_aeskey+0x73>
cmp    $0x3f,%edi
ja     11b2 <setup_aeskey+0xb2>
mov    $0xffffff40,%eax
and    0x10009011,%eax
or     %edi,%eax
or     $0x80,%eax
mov    %eax,0x10009011
mov    (%rdx),%eax
mov    %eax,0x10009108
mov    0x4(%rdx),%eax
mov    %eax,0x10009108
mov    0x8(%rdx),%eax
mov    %eax,0x10009108
mov    0xc(%rdx),%eax
mov    %eax,0x10009108
ret
movslq %edi,%rax
lea    0xe83(%rip),%rcx
mov    (%rcx,%rax,8),%rax
test   $0x4,%sil
jne    119c <setup_aeskey+0x9c>
mov    (%rdx),%ecx
mov    %ecx,(%rax)
mov    0x4(%rdx),%ecx
mov    %ecx,0x4(%rax)
mov    0x8(%rdx),%ecx
mov    %ecx,0x8(%rax)
mov    0xc(%rdx),%ecx
jmp    11af <setup_aeskey+0xaf>
mov    0xc(%rdx),%ecx
mov    %ecx,(%rax)
mov    0x8(%rdx),%ecx
mov    %ecx,0x4(%rax)
mov    0x4(%rdx),%ecx
mov    %ecx,0x8(%rax)
mov    (%rdx),%ecx
mov    %ecx,0xc(%rax)
ret

LLVM IR (-O0):
@__const.setup_aeskey.aes_regs = [4 x i32*] [i32* inttoptr (i64 419467360 to i32*), i32* inttoptr (i64 268472464 to i32*), i32* inttoptr (i64 268472512 to i32*), i32* inttoptr (i64 268472560 to i32*)]
define void @setup_aeskey(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [4 x i32*]
%8 = alloca i32*
%9 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %3
br label %98
13: ; preds = %3
%14 = bitcast [4 x i32*]* %7 to i8*
%15 = load i8*, i8** %6
%16 = bitcast i8* %15 to i32*
store i32* %16, i32** %8
%17 = load volatile i32, i32* inttoptr (i64 268472320 to i32*)
%18 = and i32 %17, -41943041
%19 = load i32, i32* %5
%20 = shl i32 %19, 23
%21 = or i32 %18, %20
store volatile i32 %21, i32* inttoptr (i64 268472320 to i32*)
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, 3
br i1 %23, label %24, label %47
24: ; preds = %13
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 63
br i1 %26, label %27, label %28
27: ; preds = %24
br label %98
28: ; preds = %24
%29 = load volatile i32, i32* inttoptr (i64 268472337 to i32*)
%30 = ashr i32 %29, 6
%31 = shl i32 %30, 6
%32 = load i32, i32* %4
%33 = or i32 %31, %32
%34 = or i32 %33, 128
store volatile i32 %34, i32* inttoptr (i64 268472337 to i32*)
%35 = load i32*, i32** %8
%36 = getelementptr inbounds i32, i32* %35, i64 0
%37 = load i32, i32* %36
store volatile i32 %37, i32* inttoptr (i64 268472584 to i32*)
%38 = load i32*, i32** %8
%39 = getelementptr inbounds i32, i32* %38, i64 1
%40 = load i32, i32* %39
store volatile i32 %40, i32* inttoptr (i64 268472584 to i32*)
%41 = load i32*, i32** %8
%42 = getelementptr inbounds i32, i32* %41, i64 2
%43 = load i32, i32* %42
store volatile i32 %43, i32* inttoptr (i64 268472584 to i32*)
%44 = load i32*, i32** %8
%45 = getelementptr inbounds i32, i32* %44, i64 3
%46 = load i32, i32* %45
store volatile i32 %46, i32* inttoptr (i64 268472584 to i32*)
br label %98
47: ; preds = %13
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [4 x i32*], [4 x i32*]* %7, i64 0, i64 %49
%51 = load i32*, i32** %50
store i32* %51, i32** %9
%52 = load i32, i32* %5
%53 = and i32 %52, 4
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %76
55: ; preds = %47
%56 = load i32*, i32** %8
%57 = getelementptr inbounds i32, i32* %56, i64 3
%58 = load i32, i32* %57
%59 = load i32*, i32** %9
%60 = getelementptr inbounds i32, i32* %59, i64 0
store volatile i32 %58, i32* %60
%61 = load i32*, i32** %8
%62 = getelementptr inbounds i32, i32* %61, i64 2
%63 = load i32, i32* %62
%64 = load i32*, i32** %9
%65 = getelementptr inbounds i32, i32* %64, i64 1
store volatile i32 %63, i32* %65
%66 = load i32*, i32** %8
%67 = getelementptr inbounds i32, i32* %66, i64 1
%68 = load i32, i32* %67
%69 = load i32*, i32** %9
%70 = getelementptr inbounds i32, i32* %69, i64 2
store volatile i32 %68, i32* %70
%71 = load i32*, i32** %8
%72 = getelementptr inbounds i32, i32* %71, i64 0
%73 = load i32, i32* %72
%74 = load i32*, i32** %9
%75 = getelementptr inbounds i32, i32* %74, i64 3
store volatile i32 %73, i32* %75
br label %97
76: ; preds = %47
%77 = load i32*, i32** %8
%78 = getelementptr inbounds i32, i32* %77, i64 0
%79 = load i32, i32* %78
%80 = load i32*, i32** %9
%81 = getelementptr inbounds i32, i32* %80, i64 0
store volatile i32 %79, i32* %81
%82 = load i32*, i32** %8
%83 = getelementptr inbounds i32, i32* %82, i64 1
%84 = load i32, i32* %83
%85 = load i32*, i32** %9
%86 = getelementptr inbounds i32, i32* %85, i64 1
store volatile i32 %84, i32* %86
%87 = load i32*, i32** %8
%88 = getelementptr inbounds i32, i32* %87, i64 2
%89 = load i32, i32* %88
%90 = load i32*, i32** %9
%91 = getelementptr inbounds i32, i32* %90, i64 2
store volatile i32 %89, i32* %91
%92 = load i32*, i32** %8
%93 = getelementptr inbounds i32, i32* %92, i64 3
%94 = load i32, i32* %93
%95 = load i32*, i32** %9
%96 = getelementptr inbounds i32, i32* %95, i64 3
store volatile i32 %94, i32* %96
br label %97
97: ; preds = %76, %55
br label %98
98: ; preds = %12, %27, %97, %28
ret void
}

LLVM IR (-O2):
@__const.setup_aeskey.aes_regs = [4 x i32*] [i32* inttoptr (i64 419467360 to i32*), i32* inttoptr (i64 268472464 to i32*), i32* inttoptr (i64 268472512 to i32*), i32* inttoptr (i64 268472560 to i32*)]
define void @setup_aeskey(i32 %0, i32 %1, i8* %2) {
%4 = icmp eq i8* %2, null
br i1 %4, label %63, label %5
5: ; preds = %3
%6 = bitcast i8* %2 to i32*
%7 = load volatile i32, i32* inttoptr (i64 268472320 to i32*)
%8 = and i32 %7, -41943041
%9 = shl i32 %1, 23
%10 = or i32 %8, %9
store volatile i32 %10, i32* inttoptr (i64 268472320 to i32*)
%11 = icmp sgt i32 %0, 3
br i1 %11, label %12, label %29
12: ; preds = %5
%13 = icmp ugt i32 %0, 63
br i1 %13, label %63, label %14
14: ; preds = %12
%15 = load volatile i32, i32* inttoptr (i64 268472337 to i32*)
%16 = and i32 %15, -192
%17 = or i32 %16, %0
%18 = or i32 %17, 128
store volatile i32 %18, i32* inttoptr (i64 268472337 to i32*)
%19 = load i32, i32* %6
store volatile i32 %19, i32* inttoptr (i64 268472584 to i32*)
%20 = getelementptr inbounds i8, i8* %2, i64 4
%21 = bitcast i8* %20 to i32*
%22 = load i32, i32* %21
store volatile i32 %22, i32* inttoptr (i64 268472584 to i32*)
%23 = getelementptr inbounds i8, i8* %2, i64 8
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
store volatile i32 %25, i32* inttoptr (i64 268472584 to i32*)
%26 = getelementptr inbounds i8, i8* %2, i64 12
%27 = bitcast i8* %26 to i32*
%28 = load i32, i32* %27
store volatile i32 %28, i32* inttoptr (i64 268472584 to i32*)
br label %63
29: ; preds = %5
%30 = sext i32 %0 to i64
%31 = getelementptr inbounds [4 x i32*], [4 x i32*]* @__const.setup_aeskey.aes_regs, i64 0, i64 %30
%32 = load i32*, i32** %31
%33 = and i32 %1, 4
%34 = icmp eq i32 %33, 0
br i1 %34, label %49, label %35
35: ; preds = %29
%36 = getelementptr inbounds i8, i8* %2, i64 12
%37 = bitcast i8* %36 to i32*
%38 = load i32, i32* %37
store volatile i32 %38, i32* %32
%39 = getelementptr inbounds i8, i8* %2, i64 8
%40 = bitcast i8* %39 to i32*
%41 = load i32, i32* %40
%42 = getelementptr inbounds i32, i32* %32, i64 1
store volatile i32 %41, i32* %42
%43 = getelementptr inbounds i8, i8* %2, i64 4
%44 = bitcast i8* %43 to i32*
%45 = load i32, i32* %44
%46 = getelementptr inbounds i32, i32* %32, i64 2
store volatile i32 %45, i32* %46
%47 = load i32, i32* %6
%48 = getelementptr inbounds i32, i32* %32, i64 3
store volatile i32 %47, i32* %48
br label %63
49: ; preds = %29
%50 = load i32, i32* %6
store volatile i32 %50, i32* %32
%51 = getelementptr inbounds i8, i8* %2, i64 4
%52 = bitcast i8* %51 to i32*
%53 = load i32, i32* %52
%54 = getelementptr inbounds i32, i32* %32, i64 1
store volatile i32 %53, i32* %54
%55 = getelementptr inbounds i8, i8* %2, i64 8
%56 = bitcast i8* %55 to i32*
%57 = load i32, i32* %56
%58 = getelementptr inbounds i32, i32* %32, i64 2
store volatile i32 %57, i32* %58
%59 = getelementptr inbounds i8, i8* %2, i64 12
%60 = bitcast i8* %59 to i32*
%61 = load i32, i32* %60
%62 = getelementptr inbounds i32, i32* %32, i64 3
store volatile i32 %61, i32* %62
br label %63
63: ; preds = %12, %35, %49, %14, %3
ret void
}