#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 */
typedef int /*<<< orphan*/ frameinfo;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ mlock(void *, int);
int open(char *, char);
int /*<<< orphan*/ read(int, unsigned long long *, int);
void *valloc(int);
void getRealMemPage(void **vAddr, void **pAddr) {
  void *a = valloc(4096);
  ((int *)a)[0] = 1;
  mlock(a, 4096);
  *vAddr = a;
  unsigned long long frameinfo;
  int fp = open("/proc/self/pagemap", 'r');
  lseek(fp, ((int)a) / 4096 * 8, SEEK_SET);
  read(fp, &frameinfo, sizeof(frameinfo));
  *pAddr = (void *)((int)(frameinfo * 4096));
}


x86 assembly (clang, -O0):
<getRealMemPage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1000,%edi
call   1060 <valloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x1000,%esi
call   1030 <mlock@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
lea    0xe68(%rip),%rdi
mov    $0x72,%esi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    $0x1000,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
shl    $0x3,%esi
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1050 <read@plt>
mov    -0x20(%rbp),%rax
shl    $0xc,%rax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRealMemPage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x1000,%edi
call   1060 <valloc@plt>
mov    %rax,%rbx
movl   $0x1,(%rax)
mov    %rax,%rdi
mov    $0x1000,%esi
call   1030 <mlock@plt>
mov    %rbx,(%r15)
lea    0xe79(%rip),%rdi
mov    $0x72,%esi
call   1070 <open@plt>
mov    %eax,%ebp
lea    0xfff(%rbx),%esi
test   %ebx,%ebx
cmovns %ebx,%esi
sar    $0xc,%esi
shl    $0x3,%esi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1040 <lseek@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1050 <read@plt>
mov    (%rsp),%eax
shl    $0xc,%eax
cltq
mov    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/proc/self/pagemap\00"
@SEEK_SET = global i32 0
define void @getRealMemPage(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8** %0, i8*** %3
store i8** %1, i8*** %4
%8 = call i8* @valloc(i32 4096)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = bitcast i8* %9 to i32*
%11 = getelementptr inbounds i32, i32* %10, i64 0
store i32 1, i32* %11
%12 = load i8*, i8** %5
%13 = call i32 @mlock(i8* %12, i32 4096)
%14 = load i8*, i8** %5
%15 = load i8**, i8*** %3
store i8* %14, i8** %15
%16 = call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8 signext 114)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = load i8*, i8** %5
%19 = ptrtoint i8* %18 to i32
%20 = sdiv i32 %19, 4096
%21 = mul nsw i32 %20, 8
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @lseek(i32 %17, i32 %21, i32 %22)
%24 = load i32, i32* %7
%25 = call i32 @read(i32 %24, i64* %6, i32 8)
%26 = load i64, i64* %6
%27 = mul i64 %26, 4096
%28 = trunc i64 %27 to i32
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i8*
%31 = load i8**, i8*** %4
store i8* %30, i8** %31
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"/proc/self/pagemap\00"
@SEEK_SET = global i32 0
define void @getRealMemPage(i8** nocapture writeonly %0, i8** nocapture writeonly %1) {
%3 = alloca i64
%4 = tail call dereferenceable_or_null(4096) i8* @valloc(i32 4096)
%5 = bitcast i8* %4 to i32*
store i32 1, i32* %5
%6 = tail call i32 @mlock(i8* %4, i32 4096)
store i8* %4, i8** %0
%7 = bitcast i64* %3 to i8*
%8 = tail call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8 signext 114)
%9 = ptrtoint i8* %4 to i64
%10 = trunc i64 %9 to i32
%11 = sdiv i32 %10, 4096
%12 = shl nsw i32 %11, 3
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @lseek(i32 %8, i32 %12, i32 %13)
%15 = call i32 @read(i32 %8, i64* %3, i32 8)
%16 = load i64, i64* %3
%17 = trunc i64 %16 to i32
%18 = shl i32 %17, 12
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %1
ret void
}