#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*/ fault_rwloop(size_t, void *);
int /*<<< orphan*/ read_bytes(size_t, void *);
int /*<<< orphan*/ write_bytes(size_t, void *);
void do_page_fault(void *addr, size_t len, int fault_mode) {
  switch (fault_mode) {
  case 0x1:
    read_bytes(len, addr);
    break;
  case 0x2:
    write_bytes(len, addr);
    break;
  case 0x3:
    fault_rwloop(len, addr);
    break;
  case 0x0:
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<do_page_fault>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x3,%rax
ja     11a3 <do_page_fault+0x73>
mov    -0x20(%rbp),%rax
lea    0xea1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <read_bytes@plt>
jmp    11a8 <do_page_fault+0x78>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <write_bytes@plt>
jmp    11a8 <do_page_fault+0x78>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <fault_rwloop@plt>
jmp    11a8 <do_page_fault+0x78>
jmp    11a3 <do_page_fault+0x73>
jmp    11a8 <do_page_fault+0x78>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_page_fault>:
mov    %rdi,%rax
cmp    $0x3,%edx
je     114d <do_page_fault+0x1d>
cmp    $0x2,%edx
je     1158 <do_page_fault+0x28>
cmp    $0x1,%edx
jne    1163 <do_page_fault+0x33>
mov    %rsi,%rdi
mov    %rax,%rsi
jmp    1040 <read_bytes@plt>
mov    %rsi,%rdi
mov    %rax,%rsi
jmp    1030 <fault_rwloop@plt>
mov    %rsi,%rdi
mov    %rax,%rsi
jmp    1050 <write_bytes@plt>
ret

LLVM IR (-O0):
define void @do_page_fault(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
switch i32 %7, label %21 [
i32 1, label %8
i32 2, label %12
i32 3, label %16
i32 0, label %20
]
8: ; preds = %3
%9 = load i64, i64* %5
%10 = load i8*, i8** %4
%11 = call i32 @read_bytes(i64 %9, i8* %10)
br label %22
12: ; preds = %3
%13 = load i64, i64* %5
%14 = load i8*, i8** %4
%15 = call i32 @write_bytes(i64 %13, i8* %14)
br label %22
16: ; preds = %3
%17 = load i64, i64* %5
%18 = load i8*, i8** %4
%19 = call i32 @fault_rwloop(i64 %17, i8* %18)
br label %22
20: ; preds = %3
br label %21
21: ; preds = %3, %20
br label %22
22: ; preds = %21, %16, %12, %8
ret void
}

LLVM IR (-O2):
define void @do_page_fault(i8* %0, i64 %1, i32 %2) {
switch i32 %2, label %10 [
i32 1, label %4
i32 2, label %6
i32 3, label %8
]
4: ; preds = %3
%5 = tail call i32 @read_bytes(i64 %1, i8* %0)
br label %10
6: ; preds = %3
%7 = tail call i32 @write_bytes(i64 %1, i8* %0)
br label %10
8: ; preds = %3
%9 = tail call i32 @fault_rwloop(i64 %1, i8* %0)
br label %10
10: ; preds = %3, %8, %6, %4
ret void
}