#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 */
unsigned int read_from_address(int);
int /*<<< orphan*/ write_to_address(int, int);
void kernel_main(void) {
  unsigned int register_a;
  register_a = read_from_address(0x3F200010);
  register_a |= (1 << 21);
  write_to_address(0x3F200010, register_a);
  while (1) {
    for (register_a = 0; register_a < 500000; register_a++) {
      ;
    }
    write_to_address(0x3F200020, 1 << 15);
    for (register_a = 0; register_a < 500000; register_a++) {
      ;
    }
    write_to_address(0x3F20002C, 1 << 15);
  }
}


x86 assembly (clang, -O0):
<kernel_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x3f200010,%edi
call   1030 <read_from_address@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
or     $0x200000,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
mov    $0x3f200010,%edi
call   1040 <write_to_address@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x7a120,-0x4(%rbp)
jae    1174 <kernel_main+0x54>
jmp    1166 <kernel_main+0x46>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1154 <kernel_main+0x34>
mov    $0x3f200020,%edi
mov    $0x8000,%esi
call   1040 <write_to_address@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x7a120,-0x4(%rbp)
jae    11aa <kernel_main+0x8a>
jmp    119c <kernel_main+0x7c>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    118a <kernel_main+0x6a>
mov    $0x3f20002c,%edi
mov    $0x8000,%esi
call   1040 <write_to_address@plt>
jmp    114d <kernel_main+0x2d>

x86 assembly (clang, -O2):
<kernel_main>:
push   %rax
mov    $0x3f200010,%edi
call   1030 <read_from_address@plt>
or     $0x200000,%eax
mov    $0x3f200010,%edi
mov    %eax,%esi
call   1040 <write_to_address@plt>
nopl   0x0(%rax)
mov    $0x3f200020,%edi
mov    $0x8000,%esi
call   1040 <write_to_address@plt>
mov    $0x3f20002c,%edi
mov    $0x8000,%esi
call   1040 <write_to_address@plt>
jmp    1140 <kernel_main+0x20>

LLVM IR (-O0):
define void @kernel_main() {
%1 = alloca i32
%2 = call i32 @read_from_address(i32 1059061776)
store i32 %2, i32* %1
%3 = load i32, i32* %1
%4 = or i32 %3, 2097152
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = call i32 @write_to_address(i32 1059061776, i32 %5)
br label %7
7: ; preds = %0, %24
store i32 0, i32* %1
br label %8
8: ; preds = %12, %7
%9 = load i32, i32* %1
%10 = icmp ult i32 %9, 500000
br i1 %10, label %11, label %15
11: ; preds = %8
br label %12
12: ; preds = %11
%13 = load i32, i32* %1
%14 = add i32 %13, 1
store i32 %14, i32* %1
br label %8
15: ; preds = %8
%16 = call i32 @write_to_address(i32 1059061792, i32 32768)
store i32 0, i32* %1
br label %17
17: ; preds = %21, %15
%18 = load i32, i32* %1
%19 = icmp ult i32 %18, 500000
br i1 %19, label %20, label %24
20: ; preds = %17
br label %21
21: ; preds = %20
%22 = load i32, i32* %1
%23 = add i32 %22, 1
store i32 %23, i32* %1
br label %17
24: ; preds = %17
%25 = call i32 @write_to_address(i32 1059061804, i32 32768)
br label %7
}

LLVM IR (-O2):
define void @kernel_main() {
%1 = tail call i32 @read_from_address(i32 1059061776)
%2 = or i32 %1, 2097152
%3 = tail call i32 @write_to_address(i32 1059061776, i32 %2)
br label %4
4: ; preds = %4, %0
%5 = tail call i32 @write_to_address(i32 1059061792, i32 32768)
%6 = tail call i32 @write_to_address(i32 1059061804, i32 32768)
br label %4
}