#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*/ getPageOfVirtualAddress(int);
scalar_t__ isVirtualAddressMapped(int *, int);
int /*<<< orphan*/ mapPage(int *, int /*<<< orphan*/, int);
scalar_t__ palloc();
int /*<<< orphan*/ storeVirtualMemory(int *, int, int);
void mapAndStoreVirtualMemory(int *table, int vaddr, int data) {
  if (isVirtualAddressMapped(table, vaddr) == 0)
    mapPage(table, getPageOfVirtualAddress(vaddr), (int)palloc());
  storeVirtualMemory(table, vaddr, data);
}


x86 assembly (clang, -O0):
<mapAndStoreVirtualMemory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <isVirtualAddressMapped@plt>
cmp    $0x0,%rax
jne    11a0 <mapAndStoreVirtualMemory+0x50>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <getPageOfVirtualAddress@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <palloc@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    %eax,%edx
call   1040 <mapPage@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <storeVirtualMemory@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapAndStoreVirtualMemory>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
call   1060 <isVirtualAddressMapped@plt>
test   %rax,%rax
jne    1187 <mapAndStoreVirtualMemory+0x37>
mov    %ebp,%edi
call   1050 <getPageOfVirtualAddress@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1030 <palloc@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %eax,%edx
call   1040 <mapPage@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <storeVirtualMemory@plt>

LLVM IR (-O0):
define void @mapAndStoreVirtualMemory(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32*, i32** %4
%8 = load i32, i32* %5
%9 = call i64 @isVirtualAddressMapped(i32* %7, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %3
%12 = load i32*, i32** %4
%13 = load i32, i32* %5
%14 = call i32 @getPageOfVirtualAddress(i32 %13)
%15 = call i64 (...) @palloc()
%16 = trunc i64 %15 to i32
%17 = call i32 @mapPage(i32* %12, i32 %14, i32 %16)
br label %18
18: ; preds = %11, %3
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = call i32 @storeVirtualMemory(i32* %19, i32 %20, i32 %21)
ret void
}

LLVM IR (-O2):
define void @mapAndStoreVirtualMemory(i32* %0, i32 %1, i32 %2) {
%4 = tail call i64 @isVirtualAddressMapped(i32* %0, i32 %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = tail call i32 @getPageOfVirtualAddress(i32 %1)
%8 = tail call i64 (...) @palloc()
%9 = trunc i64 %8 to i32
%10 = tail call i32 @mapPage(i32* %0, i32 %7, i32 %9)
br label %11
11: ; preds = %6, %3
%12 = tail call i32 @storeVirtualMemory(i32* %0, i32 %1, i32 %2)
ret void
}