#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 */
scalar_t__ isPageMapped(int *, int);
int /*<<< orphan*/ mapPage(int *, int, int);
scalar_t__ palloc();
scalar_t__ pavailable();
void mapUnmappedPages(int *table) {
  int page;
  page = 0;
  while (isPageMapped(table, page))
    page = page + 1;
  while (pavailable()) {
    mapPage(table, page, (int)palloc());
    page = page + 1;
  }
}


x86 assembly (clang, -O0):
<mapUnmappedPages>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <isPageMapped@plt>
cmp    $0x0,%rax
je     1177 <mapUnmappedPages+0x37>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1153 <mapUnmappedPages+0x13>
jmp    117c <mapUnmappedPages+0x3c>
mov    $0x0,%al
call   1060 <pavailable@plt>
cmp    $0x0,%rax
je     11be <mapUnmappedPages+0x7e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <palloc@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    %eax,%edx
call   1050 <mapPage@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117c <mapUnmappedPages+0x3c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapUnmappedPages>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0xffffffff,%ebp
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <isPageMapped@plt>
test   %rax,%rax
jne    1150 <mapUnmappedPages+0x10>
jmp    1186 <mapUnmappedPages+0x46>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <palloc@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1050 <mapPage@plt>
add    $0x1,%ebp
xor    %eax,%eax
call   1060 <pavailable@plt>
test   %rax,%rax
jne    1170 <mapUnmappedPages+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define void @mapUnmappedPages(i32* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i32 [ 0, %1 ], [ %6, %2 ]
%4 = tail call i64 @isPageMapped(i32* %0, i32 %3)
%5 = icmp eq i64 %4, 0
%6 = add nuw nsw i32 %3, 1
br i1 %5, label %7, label %2
7: ; preds = %2
%8 = tail call i64 (...) @pavailable()
%9 = icmp eq i64 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %7, %10
%11 = phi i32 [ %15, %10 ], [ %3, %7 ]
%12 = tail call i64 (...) @palloc()
%13 = trunc i64 %12 to i32
%14 = tail call i32 @mapPage(i32* %0, i32 %11, i32 %13)
%15 = add nuw nsw i32 %11, 1
%16 = tail call i64 (...) @pavailable()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %10, %7
ret void
}