#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 long atol(char *);
int /*<<< orphan*/ confirm(unsigned long, int);
unsigned long getphyaddr(unsigned long, int *);
int /*<<< orphan*/ getpid();
unsigned long hex_to_long(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  unsigned long addr, phyaddr;
  unsigned long pid;
  int data = 0x1f13;
  if (argc < 3) {
    printf("Usage: getphyaddr <pid> <vaddr>\n");
    return -1;
  }
  pid = atol(argv[1]);
  addr = hex_to_long(argv[2]);
  phyaddr = getphyaddr(pid, (void *)addr);
  printf("linear address: %p ---> physicial address: %p\n", addr, phyaddr);
  printf("confirm address:\n");
  phyaddr = getphyaddr(getpid(), &data);
  printf("linear address: %p ---> physicial address: %p, data is %x\n", &data,
         phyaddr, data);
  confirm(phyaddr, sizeof(int));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1f13,-0x2c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11a1 <main+0x41>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123d <main+0xdd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <hex_to_long@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <getphyaddr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
movslq %eax,%rdi
lea    -0x2c(%rbp),%rsi
call   1070 <getphyaddr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
lea    0xe45(%rip),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x4,%esi
call   1060 <confirm@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x1f13,0xc(%rsp)
cmp    $0x2,%edi
jg     119b <main+0x2b>
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
jmp    1222 <main+0xb2>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1090 <atol@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
call   1060 <hex_to_long@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1080 <getphyaddr@plt>
lea    0xe38(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
movslq %eax,%rdi
lea    0xc(%rsp),%r14
mov    %r14,%rsi
call   1080 <getphyaddr@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%ecx
lea    0xe27(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1070 <confirm@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Usage: getphyaddr <pid> <vaddr>\0A\00"
@.str.1 = [47 x i8] c"linear address: %p ---> physicial address: %p\0A\00"
@.str.2 = [18 x i8] c"confirm address:\0A\00"
@.str.3 = [59 x i8] c"linear address: %p ---> physicial address: %p, data is %x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 7955, i32* %9
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %40
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @atol(i8* %17)
store i64 %18, i64* %8
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i64 @hex_to_long(i8* %21)
store i64 %22, i64* %6
%23 = load i64, i64* %8
%24 = load i64, i64* %6
%25 = inttoptr i64 %24 to i8*
%26 = bitcast i8* %25 to i32*
%27 = call i64 @getphyaddr(i64 %23, i32* %26)
store i64 %27, i64* %7
%28 = load i64, i64* %6
%29 = load i64, i64* %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i64 %28, i64 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 (...) @getpid()
%33 = sext i32 %32 to i64
%34 = call i64 @getphyaddr(i64 %33, i32* %9)
store i64 %34, i64* %7
%35 = load i64, i64* %7
%36 = load i32, i32* %9
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i32* %9, i64 %35, i32 %36)
%38 = load i64, i64* %7
%39 = call i32 @confirm(i64 %38, i32 4)
store i32 0, i32* %3
br label %40
40: ; preds = %14, %12
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str.1 = [47 x i8] c"linear address: %p ---> physicial address: %p\0A\00"
@.str.3 = [59 x i8] c"linear address: %p ---> physicial address: %p, data is %x\0A\00"
@str = [17 x i8] c"confirm address:\00"
@str.4 = [32 x i8] c"Usage: getphyaddr <pid> <vaddr>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 7955, i32* %3
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.4, i64 0, i64 0))
br label %25
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @atol(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i64 @hex_to_long(i8* %13)
%15 = inttoptr i64 %14 to i32*
%16 = tail call i64 @getphyaddr(i64 %11, i32* %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i64 %14, i64 %16)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 (...) @getpid()
%20 = sext i32 %19 to i64
%21 = call i64 @getphyaddr(i64 %20, i32* %3)
%22 = load i32, i32* %3
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i32* %3, i64 %21, i32 %22)
%24 = call i32 @confirm(i64 %21, i32 4)
br label %25
25: ; preds = %8, %6
%26 = phi i32 [ -1, %6 ], [ 0, %8 ]
ret i32 %26
}