#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);
scalar_t__ valloc(int);
void getRealMemPage(void **vAddr, void **pAddr) {
  void *a = (void *)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 i64 @valloc(i32 4096)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = bitcast i8* %10 to i32*
%12 = getelementptr inbounds i32, i32* %11, i64 0
store i32 1, i32* %12
%13 = load i8*, i8** %5
%14 = call i32 @mlock(i8* %13, i32 4096)
%15 = load i8*, i8** %5
%16 = load i8**, i8*** %3
store i8* %15, i8** %16
%17 = call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8 signext 114)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = load i8*, i8** %5
%20 = ptrtoint i8* %19 to i32
%21 = sdiv i32 %20, 4096
%22 = mul nsw i32 %21, 8
%23 = load i32, i32* @SEEK_SET
%24 = call i32 @lseek(i32 %18, i32 %22, i32 %23)
%25 = load i32, i32* %7
%26 = call i32 @read(i32 %25, i64* %6, i32 8)
%27 = load i64, i64* %6
%28 = mul i64 %27, 4096
%29 = trunc i64 %28 to i32
%30 = sext i32 %29 to i64
%31 = inttoptr i64 %30 to i8*
%32 = load i8**, i8*** %4
store i8* %31, i8** %32
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 i64 @valloc(i32 4096)
%5 = inttoptr i64 %4 to i8*
%6 = inttoptr i64 %4 to i32*
store i32 1, i32* %6
%7 = tail call i32 @mlock(i8* %5, i32 4096)
store i8* %5, i8** %0
%8 = bitcast i64* %3 to i8*
%9 = tail call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8 signext 114)
%10 = trunc i64 %4 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 %9, i32 %12, i32 %13)
%15 = call i32 @read(i32 %9, 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
}