int main() {
  unsigned char *firstVmem = (unsigned char *)0x91000000;
  unsigned char *secondVmem = (unsigned char *)0xDEADBEEF;
  unsigned int *volatile ar = (unsigned int *)0x80000000U;
  printf("Startup.\n");
  printf("Reading from AR: 0x%08x\n", *ar);
  printf("Filling the screen red at current vmem address.\n");
  fillScreen(firstVmem, 0xff, 0, 0);
  usleep(2 * 1000000);
  printf("Filling the screen green at new vmem address.\n");
  fillScreen(secondVmem, 0, 0xff, 0);
  usleep(2 * 1000000);
  printf("Writing to AR (this should remap the bus to 0x%08x)\n", 0xDEADBEEF);
  *ar = 0xDEADBEEF;
  printf("Reading from AR: 0x%08x\n", *ar);
  usleep(2 * 1000000);
  printf(
      "Filling the screen blue at old vmem address. NOTHING SHOULD HAPPEN!\n");
  fillScreen(firstVmem, 0, 0, 0xff);
  usleep(2 * 1000000);
  printf("Test done, looping.\n");
  while (1)
    ;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x91000000,%eax
mov    %rax,-0x10(%rbp)
mov    $0xdeadbeef,%eax
mov    %rax,-0x18(%rbp)
mov    $0x80000000,%eax
mov    %rax,-0x20(%rbp)
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0xff,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
mov    $0x0,%al
call   1030 <fillScreen@plt>
mov    $0x1e8480,%edi
mov    $0x0,%al
call   1050 <usleep@plt>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
xor    %ecx,%ecx
mov    $0xff,%edx
mov    %ecx,%esi
mov    $0x0,%al
call   1030 <fillScreen@plt>
mov    $0x1e8480,%edi
mov    $0x0,%al
call   1050 <usleep@plt>
lea    0xea4(%rip),%rdi
mov    $0xdeadbeef,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
movl   $0xdeadbeef,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1e8480,%edi
mov    $0x0,%al
call   1050 <usleep@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
mov    $0xff,%ecx
mov    %edx,%esi
mov    $0x0,%al
call   1030 <fillScreen@plt>
mov    $0x1e8480,%edi
mov    $0x0,%al
call   1050 <usleep@plt>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1251 <main+0x121>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x91000000,%ebx
lea    -0x11000000(%rbx),%rax
mov    %rax,(%rsp)
lea    0xef3(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rax
mov    (%rax),%esi
lea    0xe93(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x91000000,%edi
mov    $0xff,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <fillScreen@plt>
mov    $0x1e8480,%edi
xor    %eax,%eax
call   1060 <usleep@plt>
lea    0xedc(%rip),%rdi
call   1040 <puts@plt>
lea    0x4dadbeef(%rbx),%rdi
xor    %esi,%esi
mov    $0xff,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <fillScreen@plt>
mov    $0x1e8480,%edi
xor    %eax,%eax
call   1060 <usleep@plt>
lea    0xe3f(%rip),%rdi
mov    $0xdeadbeef,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%rax
movl   $0xdeadbeef,(%rax)
mov    (%rsp),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1e8480,%edi
xor    %eax,%eax
call   1060 <usleep@plt>
lea    0xea2(%rip),%rdi
call   1040 <puts@plt>
mov    $0x91000000,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
xor    %eax,%eax
call   1030 <fillScreen@plt>
mov    $0x1e8480,%edi
xor    %eax,%eax
call   1060 <usleep@plt>
lea    0xeb9(%rip),%rdi
call   1040 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
nop
jmp    1250 <main+0x110>

LLVM IR (-O0):
@.str = [10 x i8] c"Startup.\0A\00"
@.str.1 = [25 x i8] c"Reading from AR: 0x%08x\0A\00"
@.str.2 = [49 x i8] c"Filling the screen red at current vmem address.\0A\00"
@.str.3 = [47 x i8] c"Filling the screen green at new vmem address.\0A\00"
@.str.4 = [53 x i8] c"Writing to AR (this should remap the bus to 0x%08x)\0A\00"
@.str.5 = [69 x i8] c"Filling the screen blue at old vmem address. NOTHING SHOULD HAPPEN!\0A\00"
@.str.6 = [21 x i8] c"Test done, looping.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
store i32 0, i32* %1
store i8* inttoptr (i64 2432696320 to i8*), i8** %2
store i8* inttoptr (i64 3735928559 to i8*), i8** %3
store volatile i32* inttoptr (i64 2147483648 to i32*), i32** %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%6 = load volatile i32*, i32** %4
%7 = load i32, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%10 = load i8*, i8** %2
%11 = call i32 (i8*, i32, i32, i32, ...) bitcast (i32 (...)* @fillScreen to i32 (i8*, i32, i32, i32, ...)*)(i8* %10, i32 255, i32 0, i32 0)
%12 = call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 2000000)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
%14 = load i8*, i8** %3
%15 = call i32 (i8*, i32, i32, i32, ...) bitcast (i32 (...)* @fillScreen to i32 (i8*, i32, i32, i32, ...)*)(i8* %14, i32 0, i32 255, i32 0)
%16 = call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 2000000)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 -559038737)
%18 = load volatile i32*, i32** %4
store i32 -559038737, i32* %18
%19 = load volatile i32*, i32** %4
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 2000000)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.5, i64 0, i64 0))
%24 = load i8*, i8** %2
%25 = call i32 (i8*, i32, i32, i32, ...) bitcast (i32 (...)* @fillScreen to i32 (i8*, i32, i32, i32, ...)*)(i8* %24, i32 0, i32 0, i32 255)
%26 = call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 2000000)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %28
28: ; preds = %0, %28
br label %28
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"Reading from AR: 0x%08x\0A\00"
@.str.4 = [53 x i8] c"Writing to AR (this should remap the bus to 0x%08x)\0A\00"
@str = [9 x i8] c"Startup.\00"
@str.7 = [48 x i8] c"Filling the screen red at current vmem address.\00"
@str.8 = [46 x i8] c"Filling the screen green at new vmem address.\00"
@str.9 = [68 x i8] c"Filling the screen blue at old vmem address. NOTHING SHOULD HAPPEN!\00"
@str.10 = [20 x i8] c"Test done, looping.\00"
define i32 @main() {
%1 = alloca i32*
%2 = bitcast i32** %1 to i8*
store volatile i32* inttoptr (i64 2147483648 to i32*), i32** %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%4 = load volatile i32*, i32** %1
%5 = load i32, i32* %4
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.7, i64 0, i64 0))
%8 = tail call i32 (i8*, i32, i32, i32, ...) bitcast (i32 (...)* @fillScreen to i32 (i8*, i32, i32, i32, ...)*)(i8* inttoptr (i64 2432696320 to i8*), i32 255, i32 0, i32 0)
%9 = tail call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 2000000)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.8, i64 0, i64 0))
%11 = tail call i32 (i8*, i32, i32, i32, ...) bitcast (i32 (...)* @fillScreen to i32 (i8*, i32, i32, i32, ...)*)(i8* inttoptr (i64 3735928559 to i8*), i32 0, i32 255, i32 0)
%12 = tail call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 2000000)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 -559038737)
%14 = load volatile i32*, i32** %1
store i32 -559038737, i32* %14
%15 = load volatile i32*, i32** %1
%16 = load i32, i32* %15
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = tail call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 2000000)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str.9, i64 0, i64 0))
%20 = tail call i32 (i8*, i32, i32, i32, ...) bitcast (i32 (...)* @fillScreen to i32 (i8*, i32, i32, i32, ...)*)(i8* inttoptr (i64 2432696320 to i8*), i32 0, i32 0, i32 255)
%21 = tail call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 2000000)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.10, i64 0, i64 0))
br label %23
23: ; preds = %23, %0
br label %23
}