#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 read_kernel_memory(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ write_kernel_memory(int, int, int /*<<< orphan*/, int);
void setup_fpga_cs1() {
  int i;
  for (i = 0; i < 16; i++) {
    write_kernel_memory(0x20e0428 + i * 4, 0xb0f1, 0, 4);
  }
  write_kernel_memory(0x20e046c, 0xb0f1, 0, 4);
  write_kernel_memory(0x20e0410, 0xb0f1, 0, 4);
  write_kernel_memory(0x20e0414, 0xb0f1, 0, 4);
  write_kernel_memory(0x20e0418, 0xb0f1, 0, 4);
  write_kernel_memory(0x20e041c, 0xb0f1, 0, 4);
  write_kernel_memory(0x20e0468, 0xb0f1, 0, 4);
  write_kernel_memory(0x20e0408, 0xb0f1, 0, 4);
  write_kernel_memory(0x20e0404, 0xb0f1, 0, 4);
  write_kernel_memory(0x20e0400, 0xb0f1, 0, 4);
  write_kernel_memory(0x21b8000 + 0x18, 0x31910BBF, 0, 4);
  write_kernel_memory(0x21b8004 + 0x18, 0x1000, 0, 4);
  write_kernel_memory(0x21b8008 + 0x18, 0x09014000, 0, 4);
  write_kernel_memory(0x21b800c + 0x18, 0x00000200, 0, 4);
  write_kernel_memory(0x21b8010 + 0x18, 0x02040400, 0, 4);
  write_kernel_memory(0x21b8090, 0x701, 0, 4);
  write_kernel_memory(0x21b8094, 0x10, 0, 4);
  write_kernel_memory(0x20e0004,
                      (read_kernel_memory(0x20e0004, 0, 4) & 0xFFFFFFC0) | 0x1B,
                      0, 4);
}


x86 assembly (clang, -O0):
<setup_fpga_cs1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x10,-0x4(%rbp)
jge    1164 <setup_fpga_cs1+0x44>
mov    -0x4(%rbp),%edi
shl    $0x2,%edi
add    $0x20e0428,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    112f <setup_fpga_cs1+0xf>
mov    $0x20e046c,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0410,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0414,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0418,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e041c,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0468,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0408,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0404,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0400,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b8018,%edi
mov    $0x31910bbf,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b801c,%edi
mov    $0x1000,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b8020,%edi
mov    $0x9014000,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b8024,%edi
mov    $0x200,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b8028,%edi
mov    $0x2040400,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b8090,%edi
mov    $0x701,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b8094,%edi
mov    $0x10,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0004,%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <read_kernel_memory@plt>
mov    %eax,%esi
and    $0xffffffc0,%esi
or     $0x1b,%esi
mov    $0x20e0004,%edi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_fpga_cs1>:
push   %rax
mov    $0x20e0428,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e042c,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0430,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0434,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0438,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e043c,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0440,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0444,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0448,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e044c,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0450,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0454,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0458,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e045c,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0460,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0464,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e046c,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0410,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0414,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0418,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e041c,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0468,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0408,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0404,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0400,%edi
mov    $0xb0f1,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b8018,%edi
mov    $0x31910bbf,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b801c,%edi
mov    $0x1000,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b8020,%edi
mov    $0x9014000,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b8024,%edi
mov    $0x200,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b8028,%edi
mov    $0x2040400,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b8090,%edi
mov    $0x701,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x21b8094,%edi
mov    $0x10,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <write_kernel_memory@plt>
mov    $0x20e0004,%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <read_kernel_memory@plt>
and    $0xffffffc0,%eax
lea    0x1b(%rax),%esi
mov    $0x20e0004,%edi
xor    %edx,%edx
mov    $0x4,%ecx
pop    %rax
jmp    1040 <write_kernel_memory@plt>

LLVM IR (-O0):
define void @setup_fpga_cs1() {
%1 = alloca i32
store i32 0, i32* %1
br label %2
2: ; preds = %10, %0
%3 = load i32, i32* %1
%4 = icmp slt i32 %3, 16
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = load i32, i32* %1
%7 = mul nsw i32 %6, 4
%8 = add nsw i32 34473000, %7
%9 = call i32 @write_kernel_memory(i32 %8, i32 45297, i32 0, i32 4)
br label %10
10: ; preds = %5
%11 = load i32, i32* %1
%12 = add nsw i32 %11, 1
store i32 %12, i32* %1
br label %2
13: ; preds = %2
%14 = call i32 @write_kernel_memory(i32 34473068, i32 45297, i32 0, i32 4)
%15 = call i32 @write_kernel_memory(i32 34472976, i32 45297, i32 0, i32 4)
%16 = call i32 @write_kernel_memory(i32 34472980, i32 45297, i32 0, i32 4)
%17 = call i32 @write_kernel_memory(i32 34472984, i32 45297, i32 0, i32 4)
%18 = call i32 @write_kernel_memory(i32 34472988, i32 45297, i32 0, i32 4)
%19 = call i32 @write_kernel_memory(i32 34473064, i32 45297, i32 0, i32 4)
%20 = call i32 @write_kernel_memory(i32 34472968, i32 45297, i32 0, i32 4)
%21 = call i32 @write_kernel_memory(i32 34472964, i32 45297, i32 0, i32 4)
%22 = call i32 @write_kernel_memory(i32 34472960, i32 45297, i32 0, i32 4)
%23 = call i32 @write_kernel_memory(i32 35356696, i32 831589311, i32 0, i32 4)
%24 = call i32 @write_kernel_memory(i32 35356700, i32 4096, i32 0, i32 4)
%25 = call i32 @write_kernel_memory(i32 35356704, i32 151076864, i32 0, i32 4)
%26 = call i32 @write_kernel_memory(i32 35356708, i32 512, i32 0, i32 4)
%27 = call i32 @write_kernel_memory(i32 35356712, i32 33817600, i32 0, i32 4)
%28 = call i32 @write_kernel_memory(i32 35356816, i32 1793, i32 0, i32 4)
%29 = call i32 @write_kernel_memory(i32 35356820, i32 16, i32 0, i32 4)
%30 = call i32 @read_kernel_memory(i32 34471940, i32 0, i32 4)
%31 = and i32 %30, -64
%32 = or i32 %31, 27
%33 = call i32 @write_kernel_memory(i32 34471940, i32 %32, i32 0, i32 4)
ret void
}

LLVM IR (-O2):
define void @setup_fpga_cs1() {
%1 = tail call i32 @write_kernel_memory(i32 34473000, i32 45297, i32 0, i32 4)
%2 = tail call i32 @write_kernel_memory(i32 34473004, i32 45297, i32 0, i32 4)
%3 = tail call i32 @write_kernel_memory(i32 34473008, i32 45297, i32 0, i32 4)
%4 = tail call i32 @write_kernel_memory(i32 34473012, i32 45297, i32 0, i32 4)
%5 = tail call i32 @write_kernel_memory(i32 34473016, i32 45297, i32 0, i32 4)
%6 = tail call i32 @write_kernel_memory(i32 34473020, i32 45297, i32 0, i32 4)
%7 = tail call i32 @write_kernel_memory(i32 34473024, i32 45297, i32 0, i32 4)
%8 = tail call i32 @write_kernel_memory(i32 34473028, i32 45297, i32 0, i32 4)
%9 = tail call i32 @write_kernel_memory(i32 34473032, i32 45297, i32 0, i32 4)
%10 = tail call i32 @write_kernel_memory(i32 34473036, i32 45297, i32 0, i32 4)
%11 = tail call i32 @write_kernel_memory(i32 34473040, i32 45297, i32 0, i32 4)
%12 = tail call i32 @write_kernel_memory(i32 34473044, i32 45297, i32 0, i32 4)
%13 = tail call i32 @write_kernel_memory(i32 34473048, i32 45297, i32 0, i32 4)
%14 = tail call i32 @write_kernel_memory(i32 34473052, i32 45297, i32 0, i32 4)
%15 = tail call i32 @write_kernel_memory(i32 34473056, i32 45297, i32 0, i32 4)
%16 = tail call i32 @write_kernel_memory(i32 34473060, i32 45297, i32 0, i32 4)
%17 = tail call i32 @write_kernel_memory(i32 34473068, i32 45297, i32 0, i32 4)
%18 = tail call i32 @write_kernel_memory(i32 34472976, i32 45297, i32 0, i32 4)
%19 = tail call i32 @write_kernel_memory(i32 34472980, i32 45297, i32 0, i32 4)
%20 = tail call i32 @write_kernel_memory(i32 34472984, i32 45297, i32 0, i32 4)
%21 = tail call i32 @write_kernel_memory(i32 34472988, i32 45297, i32 0, i32 4)
%22 = tail call i32 @write_kernel_memory(i32 34473064, i32 45297, i32 0, i32 4)
%23 = tail call i32 @write_kernel_memory(i32 34472968, i32 45297, i32 0, i32 4)
%24 = tail call i32 @write_kernel_memory(i32 34472964, i32 45297, i32 0, i32 4)
%25 = tail call i32 @write_kernel_memory(i32 34472960, i32 45297, i32 0, i32 4)
%26 = tail call i32 @write_kernel_memory(i32 35356696, i32 831589311, i32 0, i32 4)
%27 = tail call i32 @write_kernel_memory(i32 35356700, i32 4096, i32 0, i32 4)
%28 = tail call i32 @write_kernel_memory(i32 35356704, i32 151076864, i32 0, i32 4)
%29 = tail call i32 @write_kernel_memory(i32 35356708, i32 512, i32 0, i32 4)
%30 = tail call i32 @write_kernel_memory(i32 35356712, i32 33817600, i32 0, i32 4)
%31 = tail call i32 @write_kernel_memory(i32 35356816, i32 1793, i32 0, i32 4)
%32 = tail call i32 @write_kernel_memory(i32 35356820, i32 16, i32 0, i32 4)
%33 = tail call i32 @read_kernel_memory(i32 34471940, i32 0, i32 4)
%34 = and i32 %33, -64
%35 = or i32 %34, 27
%36 = tail call i32 @write_kernel_memory(i32 34471940, i32 %35, i32 0, i32 4)
ret void
}