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

/* Variables and functions */
void setup_aeskeyN(uint_fast8_t keyslot, void *keyx) {
  volatile uint32_t *aes_regs[] = {
      (volatile uint32_t *)0x10009040, (volatile uint32_t *)0x10009070,
      (volatile uint32_t *)0x100090A0, (volatile uint32_t *)0x100090D0};
  uint32_t *_keyx = (uint32_t *)keyx;
  *((volatile uint8_t *)0x10009011) =
      (*((volatile uint8_t *)0x10009011) >> 6 << 6) | keyslot | 0x80;
  if (keyslot > 3) {
    *((volatile uint32_t *)0x10009100) = _keyx[0];
    *((volatile uint32_t *)0x10009100) = _keyx[1];
    *((volatile uint32_t *)0x10009100) = _keyx[2];
    *((volatile uint32_t *)0x10009100) = _keyx[3];
  } else {
    volatile uint32_t *aes_reg = aes_regs[keyslot];
    if (0x02000000) {
      aes_reg[0] = _keyx[3];
      aes_reg[1] = _keyx[2];
      aes_reg[2] = _keyx[1];
      aes_reg[3] = _keyx[0];
    } else {
      aes_reg[0] = _keyx[0];
      aes_reg[1] = _keyx[1];
      aes_reg[2] = _keyx[2];
      aes_reg[3] = _keyx[3];
    }
  }
}


x86 assembly (clang, -O0):
<setup_aeskeyN>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeee(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeeb(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xee8(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xee5(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x10009011,%eax
mov    (%rax),%ecx
sar    $0x6,%ecx
shl    $0x6,%ecx
mov    -0x4(%rbp),%eax
or     %eax,%ecx
or     $0x80,%ecx
mov    $0x10009011,%eax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
cmp    $0x3,%eax
jle    11a6 <setup_aeskeyN+0xa6>
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
mov    $0x10009100,%eax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%ecx
mov    $0x10009100,%eax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%ecx
mov    $0x10009100,%eax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    0xc(%rax),%ecx
mov    $0x10009100,%eax
mov    %ecx,(%rax)
jmp    11ea <setup_aeskeyN+0xea>
mov    -0x4(%rbp),%eax
cltq
mov    -0x30(%rbp,%rax,8),%rax
mov    %rax,-0x40(%rbp)
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)
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_aeskeyN>:
mov    %edi,-0x4(%rsp)
mov    $0xffffff40,%eax
and    0x10009011,%eax
or     -0x4(%rsp),%eax
or     $0x80,%eax
mov    %eax,0x10009011
mov    -0x4(%rsp),%eax
cmp    $0x4,%eax
jl     1151 <setup_aeskeyN+0x51>
mov    (%rsi),%eax
mov    %eax,0x10009100
mov    0x4(%rsi),%eax
mov    %eax,0x10009100
mov    0x8(%rsi),%eax
mov    %eax,0x10009100
mov    0xc(%rsi),%eax
mov    %eax,0x10009100
ret
movslq -0x4(%rsp),%rax
lea    0xea3(%rip),%rcx
mov    (%rcx,%rax,8),%rax
mov    0xc(%rsi),%ecx
mov    %ecx,(%rax)
mov    0x8(%rsi),%ecx
mov    %ecx,0x4(%rax)
mov    0x4(%rsi),%ecx
mov    %ecx,0x8(%rax)
mov    (%rsi),%ecx
mov    %ecx,0xc(%rax)
ret

LLVM IR (-O0):
@__const.setup_aeskeyN.aes_regs = [4 x i32*] [i32* inttoptr (i64 268472384 to i32*), i32* inttoptr (i64 268472432 to i32*), i32* inttoptr (i64 268472480 to i32*), i32* inttoptr (i64 268472528 to i32*)]
define void @setup_aeskeyN(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [4 x i32*]
%6 = alloca i32*
%7 = alloca i32*
store volatile i32 %0, i32* %3
store i8* %1, i8** %4
%8 = bitcast [4 x i32*]* %5 to i8*
%9 = load i8*, i8** %4
%10 = bitcast i8* %9 to i32*
store i32* %10, i32** %6
%11 = load volatile i32, i32* inttoptr (i64 268472337 to i32*)
%12 = ashr i32 %11, 6
%13 = shl i32 %12, 6
%14 = load volatile i32, i32* %3
%15 = or i32 %13, %14
%16 = or i32 %15, 128
store volatile i32 %16, i32* inttoptr (i64 268472337 to i32*)
%17 = load volatile i32, i32* %3
%18 = icmp sgt i32 %17, 3
br i1 %18, label %19, label %32
19: ; preds = %2
%20 = load i32*, i32** %6
%21 = getelementptr inbounds i32, i32* %20, i64 0
%22 = load i32, i32* %21
store volatile i32 %22, i32* inttoptr (i64 268472576 to i32*)
%23 = load i32*, i32** %6
%24 = getelementptr inbounds i32, i32* %23, i64 1
%25 = load i32, i32* %24
store volatile i32 %25, i32* inttoptr (i64 268472576 to i32*)
%26 = load i32*, i32** %6
%27 = getelementptr inbounds i32, i32* %26, i64 2
%28 = load i32, i32* %27
store volatile i32 %28, i32* inttoptr (i64 268472576 to i32*)
%29 = load i32*, i32** %6
%30 = getelementptr inbounds i32, i32* %29, i64 3
%31 = load i32, i32* %30
store volatile i32 %31, i32* inttoptr (i64 268472576 to i32*)
br label %57
32: ; preds = %2
%33 = load volatile i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [4 x i32*], [4 x i32*]* %5, i64 0, i64 %34
%36 = load i32*, i32** %35
store i32* %36, i32** %7
%37 = load i32*, i32** %6
%38 = getelementptr inbounds i32, i32* %37, i64 3
%39 = load i32, i32* %38
%40 = load i32*, i32** %7
%41 = getelementptr inbounds i32, i32* %40, i64 0
store volatile i32 %39, i32* %41
%42 = load i32*, i32** %6
%43 = getelementptr inbounds i32, i32* %42, i64 2
%44 = load i32, i32* %43
%45 = load i32*, i32** %7
%46 = getelementptr inbounds i32, i32* %45, i64 1
store volatile i32 %44, i32* %46
%47 = load i32*, i32** %6
%48 = getelementptr inbounds i32, i32* %47, i64 1
%49 = load i32, i32* %48
%50 = load i32*, i32** %7
%51 = getelementptr inbounds i32, i32* %50, i64 2
store volatile i32 %49, i32* %51
%52 = load i32*, i32** %6
%53 = getelementptr inbounds i32, i32* %52, i64 0
%54 = load i32, i32* %53
%55 = load i32*, i32** %7
%56 = getelementptr inbounds i32, i32* %55, i64 3
store volatile i32 %54, i32* %56
br label %57
57: ; preds = %32, %19
ret void
}

LLVM IR (-O2):
@__const.setup_aeskeyN.aes_regs = [4 x i32*] [i32* inttoptr (i64 268472384 to i32*), i32* inttoptr (i64 268472432 to i32*), i32* inttoptr (i64 268472480 to i32*), i32* inttoptr (i64 268472528 to i32*)]
define void @setup_aeskeyN(i32 %0, i8* nocapture %1) {
%3 = alloca i32
store volatile i32 %0, i32* %3
%4 = bitcast i8* %1 to i32*
%5 = load volatile i32, i32* inttoptr (i64 268472337 to i32*)
%6 = and i32 %5, -192
%7 = load volatile i32, i32* %3
%8 = or i32 %7, %6
%9 = or i32 %8, 128
store volatile i32 %9, i32* inttoptr (i64 268472337 to i32*)
%10 = load volatile i32, i32* %3
%11 = icmp sgt i32 %10, 3
br i1 %11, label %12, label %23
12: ; preds = %2
%13 = load i32, i32* %4
store volatile i32 %13, i32* inttoptr (i64 268472576 to i32*)
%14 = getelementptr inbounds i8, i8* %1, i64 4
%15 = bitcast i8* %14 to i32*
%16 = load i32, i32* %15
store volatile i32 %16, i32* inttoptr (i64 268472576 to i32*)
%17 = getelementptr inbounds i8, i8* %1, i64 8
%18 = bitcast i8* %17 to i32*
%19 = load i32, i32* %18
store volatile i32 %19, i32* inttoptr (i64 268472576 to i32*)
%20 = getelementptr inbounds i8, i8* %1, i64 12
%21 = bitcast i8* %20 to i32*
%22 = load i32, i32* %21
store volatile i32 %22, i32* inttoptr (i64 268472576 to i32*)
br label %41
23: ; preds = %2
%24 = load volatile i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [4 x i32*], [4 x i32*]* @__const.setup_aeskeyN.aes_regs, i64 0, i64 %25
%27 = load i32*, i32** %26
%28 = getelementptr inbounds i8, i8* %1, i64 12
%29 = bitcast i8* %28 to i32*
%30 = load i32, i32* %29
store volatile i32 %30, i32* %27
%31 = getelementptr inbounds i8, i8* %1, i64 8
%32 = bitcast i8* %31 to i32*
%33 = load i32, i32* %32
%34 = getelementptr inbounds i32, i32* %27, i64 1
store volatile i32 %33, i32* %34
%35 = getelementptr inbounds i8, i8* %1, i64 4
%36 = bitcast i8* %35 to i32*
%37 = load i32, i32* %36
%38 = getelementptr inbounds i32, i32* %27, i64 2
store volatile i32 %37, i32* %38
%39 = load i32, i32* %4
%40 = getelementptr inbounds i32, i32* %27, i64 3
store volatile i32 %39, i32* %40
br label %41
41: ; preds = %23, %12
ret void
}