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

/* Variables and functions */
void setup_aeskey(uint32_t keyno, int value, void *key) {
  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)
mov    0xeeb(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xee8(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xee5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xee2(%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    11d0 <setup_aeskey+0xd0>
cmpl   $0x3f,-0x4(%rbp)
jle    1177 <setup_aeskey+0x77>
jmp    1262 <setup_aeskey+0x162>
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    1262 <setup_aeskey+0x162>
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     1227 <setup_aeskey+0x127>
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    125d <setup_aeskey+0x15d>
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    1262 <setup_aeskey+0x162>
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_aeskey>:
mov    $0xfd7fffff,%eax
and    0x10009000,%eax
mov    %esi,%ecx
shl    $0x17,%ecx
or     %eax,%ecx
mov    %ecx,0x10009000
cmp    $0x4,%edi
jl     116a <setup_aeskey+0x6a>
cmp    $0x3f,%edi
ja     11a9 <setup_aeskey+0xa9>
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    0xe8c(%rip),%rcx
mov    (%rcx,%rax,8),%rax
test   $0x4,%sil
jne    1193 <setup_aeskey+0x93>
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    11a6 <setup_aeskey+0xa6>
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 = bitcast [4 x i32*]* %7 to i8*
%11 = load i8*, i8** %6
%12 = bitcast i8* %11 to i32*
store i32* %12, i32** %8
%13 = load volatile i32, i32* inttoptr (i64 268472320 to i32*)
%14 = and i32 %13, -41943041
%15 = load i32, i32* %5
%16 = shl i32 %15, 23
%17 = or i32 %14, %16
store volatile i32 %17, i32* inttoptr (i64 268472320 to i32*)
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 3
br i1 %19, label %20, label %43
20: ; preds = %3
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 63
br i1 %22, label %23, label %24
23: ; preds = %20
br label %94
24: ; preds = %20
%25 = load volatile i32, i32* inttoptr (i64 268472337 to i32*)
%26 = ashr i32 %25, 6
%27 = shl i32 %26, 6
%28 = load i32, i32* %4
%29 = or i32 %27, %28
%30 = or i32 %29, 128
store volatile i32 %30, i32* inttoptr (i64 268472337 to i32*)
%31 = load i32*, i32** %8
%32 = getelementptr inbounds i32, i32* %31, i64 0
%33 = load i32, i32* %32
store volatile i32 %33, i32* inttoptr (i64 268472584 to i32*)
%34 = load i32*, i32** %8
%35 = getelementptr inbounds i32, i32* %34, i64 1
%36 = load i32, i32* %35
store volatile i32 %36, i32* inttoptr (i64 268472584 to i32*)
%37 = load i32*, i32** %8
%38 = getelementptr inbounds i32, i32* %37, i64 2
%39 = load i32, i32* %38
store volatile i32 %39, i32* inttoptr (i64 268472584 to i32*)
%40 = load i32*, i32** %8
%41 = getelementptr inbounds i32, i32* %40, i64 3
%42 = load i32, i32* %41
store volatile i32 %42, i32* inttoptr (i64 268472584 to i32*)
br label %94
43: ; preds = %3
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [4 x i32*], [4 x i32*]* %7, i64 0, i64 %45
%47 = load i32*, i32** %46
store i32* %47, i32** %9
%48 = load i32, i32* %5
%49 = and i32 %48, 4
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %72
51: ; preds = %43
%52 = load i32*, i32** %8
%53 = getelementptr inbounds i32, i32* %52, i64 3
%54 = load i32, i32* %53
%55 = load i32*, i32** %9
%56 = getelementptr inbounds i32, i32* %55, i64 0
store volatile i32 %54, i32* %56
%57 = load i32*, i32** %8
%58 = getelementptr inbounds i32, i32* %57, i64 2
%59 = load i32, i32* %58
%60 = load i32*, i32** %9
%61 = getelementptr inbounds i32, i32* %60, i64 1
store volatile i32 %59, i32* %61
%62 = load i32*, i32** %8
%63 = getelementptr inbounds i32, i32* %62, i64 1
%64 = load i32, i32* %63
%65 = load i32*, i32** %9
%66 = getelementptr inbounds i32, i32* %65, i64 2
store volatile i32 %64, i32* %66
%67 = load i32*, i32** %8
%68 = getelementptr inbounds i32, i32* %67, i64 0
%69 = load i32, i32* %68
%70 = load i32*, i32** %9
%71 = getelementptr inbounds i32, i32* %70, i64 3
store volatile i32 %69, i32* %71
br label %93
72: ; preds = %43
%73 = load i32*, i32** %8
%74 = getelementptr inbounds i32, i32* %73, i64 0
%75 = load i32, i32* %74
%76 = load i32*, i32** %9
%77 = getelementptr inbounds i32, i32* %76, i64 0
store volatile i32 %75, i32* %77
%78 = load i32*, i32** %8
%79 = getelementptr inbounds i32, i32* %78, i64 1
%80 = load i32, i32* %79
%81 = load i32*, i32** %9
%82 = getelementptr inbounds i32, i32* %81, i64 1
store volatile i32 %80, i32* %82
%83 = load i32*, i32** %8
%84 = getelementptr inbounds i32, i32* %83, i64 2
%85 = load i32, i32* %84
%86 = load i32*, i32** %9
%87 = getelementptr inbounds i32, i32* %86, i64 2
store volatile i32 %85, i32* %87
%88 = load i32*, i32** %8
%89 = getelementptr inbounds i32, i32* %88, i64 3
%90 = load i32, i32* %89
%91 = load i32*, i32** %9
%92 = getelementptr inbounds i32, i32* %91, i64 3
store volatile i32 %90, i32* %92
br label %93
93: ; preds = %72, %51
br label %94
94: ; preds = %23, %93, %24
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* nocapture %2) {
%4 = bitcast i8* %2 to i32*
%5 = load volatile i32, i32* inttoptr (i64 268472320 to i32*)
%6 = and i32 %5, -41943041
%7 = shl i32 %1, 23
%8 = or i32 %6, %7
store volatile i32 %8, i32* inttoptr (i64 268472320 to i32*)
%9 = icmp sgt i32 %0, 3
br i1 %9, label %10, label %27
10: ; preds = %3
%11 = icmp ugt i32 %0, 63
br i1 %11, label %61, label %12
12: ; preds = %10
%13 = load volatile i32, i32* inttoptr (i64 268472337 to i32*)
%14 = and i32 %13, -192
%15 = or i32 %14, %0
%16 = or i32 %15, 128
store volatile i32 %16, i32* inttoptr (i64 268472337 to i32*)
%17 = load i32, i32* %4
store volatile i32 %17, i32* inttoptr (i64 268472584 to i32*)
%18 = getelementptr inbounds i8, i8* %2, i64 4
%19 = bitcast i8* %18 to i32*
%20 = load i32, i32* %19
store volatile i32 %20, i32* inttoptr (i64 268472584 to i32*)
%21 = getelementptr inbounds i8, i8* %2, i64 8
%22 = bitcast i8* %21 to i32*
%23 = load i32, i32* %22
store volatile i32 %23, i32* inttoptr (i64 268472584 to i32*)
%24 = getelementptr inbounds i8, i8* %2, i64 12
%25 = bitcast i8* %24 to i32*
%26 = load i32, i32* %25
store volatile i32 %26, i32* inttoptr (i64 268472584 to i32*)
br label %61
27: ; preds = %3
%28 = sext i32 %0 to i64
%29 = getelementptr inbounds [4 x i32*], [4 x i32*]* @__const.setup_aeskey.aes_regs, i64 0, i64 %28
%30 = load i32*, i32** %29
%31 = and i32 %1, 4
%32 = icmp eq i32 %31, 0
br i1 %32, label %47, label %33
33: ; preds = %27
%34 = getelementptr inbounds i8, i8* %2, i64 12
%35 = bitcast i8* %34 to i32*
%36 = load i32, i32* %35
store volatile i32 %36, i32* %30
%37 = getelementptr inbounds i8, i8* %2, i64 8
%38 = bitcast i8* %37 to i32*
%39 = load i32, i32* %38
%40 = getelementptr inbounds i32, i32* %30, i64 1
store volatile i32 %39, i32* %40
%41 = getelementptr inbounds i8, i8* %2, i64 4
%42 = bitcast i8* %41 to i32*
%43 = load i32, i32* %42
%44 = getelementptr inbounds i32, i32* %30, i64 2
store volatile i32 %43, i32* %44
%45 = load i32, i32* %4
%46 = getelementptr inbounds i32, i32* %30, i64 3
store volatile i32 %45, i32* %46
br label %61
47: ; preds = %27
%48 = load i32, i32* %4
store volatile i32 %48, i32* %30
%49 = getelementptr inbounds i8, i8* %2, i64 4
%50 = bitcast i8* %49 to i32*
%51 = load i32, i32* %50
%52 = getelementptr inbounds i32, i32* %30, i64 1
store volatile i32 %51, i32* %52
%53 = getelementptr inbounds i8, i8* %2, i64 8
%54 = bitcast i8* %53 to i32*
%55 = load i32, i32* %54
%56 = getelementptr inbounds i32, i32* %30, i64 2
store volatile i32 %55, i32* %56
%57 = getelementptr inbounds i8, i8* %2, i64 12
%58 = bitcast i8* %57 to i32*
%59 = load i32, i32* %58
%60 = getelementptr inbounds i32, i32* %30, i64 3
store volatile i32 %59, i32* %60
br label %61
61: ; preds = %12, %47, %33, %10
ret void
}