#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 /*<<< orphan*/ PT_update(int *, int, int);
scalar_t__ TLB_purge(void *);
int /*<<< orphan*/ print(int volatile);
int /*<<< orphan*/ print_str(char *);
int /*<<< orphan*/ to_stdout(char);
int main(void) {
  int i, rsp, new_value;
  volatile int *walker;
  walker = (int *)(0x00040000 + 12 * 4096);
  if (TLB_purge((void *)walker) == 0) {
    print_str("\tpurged\n");
  } else {
    print_str("\tTLB miss\n");
  }
  new_value = (((0x00040000 + 12 * 4096) >> 12) << 6) | 0b000101;
  PT_update((int *)walker, 0, new_value);
  PT_update((int *)walker, 1, 0x0a);
  *walker = 0x55;
  if (*walker == 0x55) {
    print(*walker);
    print_str("\tseg fault not in RAM not ok\n");
  } else {
    print_str("\tseg fault not in RAM err\n");
  }
  to_stdout('\n');
  return ((int)walker);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4c000,%eax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <TLB_purge@plt>
cmp    $0x0,%rax
jne    118c <main+0x3c>
lea    0xe7e(%rip),%rdi
call   1060 <print_str@plt>
jmp    1198 <main+0x48>
lea    0xe76(%rip),%rdi
call   1060 <print_str@plt>
movl   $0x1305,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
xor    %esi,%esi
call   1070 <PT_update@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1070 <PT_update@plt>
mov    -0x18(%rbp),%rax
movl   $0x55,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    $0x55,%eax
jne    11f5 <main+0xa5>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <print@plt>
lea    0xe29(%rip),%rdi
call   1060 <print_str@plt>
jmp    1201 <main+0xb1>
lea    0xe36(%rip),%rdi
call   1060 <print_str@plt>
mov    $0xa,%edi
call   1040 <to_stdout@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x4c000,%edi
call   1030 <TLB_purge@plt>
test   %rax,%rax
lea    0xe9b(%rip),%rax
lea    0xe9d(%rip),%rdi
cmove  %rax,%rdi
call   1060 <print_str@plt>
mov    $0x4c000,%edi
xor    %esi,%esi
mov    $0x1305,%edx
call   1070 <PT_update@plt>
mov    $0x4c000,%edi
mov    $0x1,%esi
mov    $0xa,%edx
call   1070 <PT_update@plt>
movl   $0x55,0x4c000
mov    0x4c000,%eax
cmp    $0x55,%eax
jne    11c6 <main+0x76>
mov    0x4c000,%edi
call   1050 <print@plt>
lea    0xe50(%rip),%rdi
jmp    11cd <main+0x7d>
lea    0xe65(%rip),%rdi
call   1060 <print_str@plt>
mov    $0xa,%edi
call   1040 <to_stdout@plt>
mov    $0x4c000,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"\09purged\0A\00"
@.str.1 = [11 x i8] c"\09TLB miss\0A\00"
@.str.2 = [30 x i8] c"\09seg fault not in RAM not ok\0A\00"
@.str.3 = [27 x i8] c"\09seg fault not in RAM err\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
store i32* inttoptr (i64 311296 to i32*), i32** %5
%6 = load i32*, i32** %5
%7 = bitcast i32* %6 to i8*
%8 = call i64 @TLB_purge(i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @print_str(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %14
12: ; preds = %0
%13 = call i32 @print_str(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %10
store i32 4869, i32* %4
%15 = load i32*, i32** %5
%16 = load i32, i32* %4
%17 = call i32 @PT_update(i32* %15, i32 0, i32 %16)
%18 = load i32*, i32** %5
%19 = call i32 @PT_update(i32* %18, i32 1, i32 10)
%20 = load i32*, i32** %5
store volatile i32 85, i32* %20
%21 = load i32*, i32** %5
%22 = load volatile i32, i32* %21
%23 = icmp eq i32 %22, 85
br i1 %23, label %24, label %29
24: ; preds = %14
%25 = load i32*, i32** %5
%26 = load volatile i32, i32* %25
%27 = call i32 @print(i32 %26)
%28 = call i32 @print_str(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %31
29: ; preds = %14
%30 = call i32 @print_str(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
%32 = call i32 @to_stdout(i8 signext 10)
%33 = load i32*, i32** %5
%34 = ptrtoint i32* %33 to i32
ret i32 %34
}

LLVM IR (-O2):
@.str = [9 x i8] c"\09purged\0A\00"
@.str.1 = [11 x i8] c"\09TLB miss\0A\00"
@.str.2 = [30 x i8] c"\09seg fault not in RAM not ok\0A\00"
@.str.3 = [27 x i8] c"\09seg fault not in RAM err\0A\00"
define i32 @main() {
%1 = tail call i64 @TLB_purge(i8* inttoptr (i64 311296 to i8*))
%2 = icmp eq i64 %1, 0
%3 = select i1 %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0)
%4 = tail call i32 @print_str(i8* %3)
%5 = tail call i32 @PT_update(i32* inttoptr (i64 311296 to i32*), i32 0, i32 4869)
%6 = tail call i32 @PT_update(i32* inttoptr (i64 311296 to i32*), i32 1, i32 10)
store volatile i32 85, i32* inttoptr (i64 311296 to i32*)
%7 = load volatile i32, i32* inttoptr (i64 311296 to i32*)
%8 = icmp eq i32 %7, 85
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load volatile i32, i32* inttoptr (i64 311296 to i32*)
%11 = tail call i32 @print(i32 %10)
br label %12
12: ; preds = %0, %9
%13 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), %0 ]
%14 = tail call i32 @print_str(i8* %13)
%15 = tail call i32 @to_stdout(i8 signext 10)
ret i32 311296
}