#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*/ map_page(int, int, unsigned int);
int map_page_range(int vpg_start, int pgcount, int ppg_start,
                   unsigned int attr) {
  int i, phys_pg;
  for (i = 0; i < pgcount; i++) {
    phys_pg = ppg_start < 0 ? -1 : ppg_start + i;
    map_page(vpg_start + i, phys_pg, attr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<map_page_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    117c <map_page_range+0x6c>
cmpl   $0x0,-0xc(%rbp)
jge    114e <map_page_range+0x3e>
mov    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1157 <map_page_range+0x47>
mov    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
add    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <map_page@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112b <map_page_range+0x1b>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<map_page_range>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    1151 <map_page_range+0x41>
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%r12d
mov    %edi,%ebp
mov    %edx,%ebx
nopl   0x0(%rax)
test   %r15d,%r15d
mov    $0xffffffff,%esi
cmovns %ebx,%esi
mov    %ebp,%edi
mov    %r14d,%edx
call   1030 <map_page@plt>
add    $0x1,%ebp
add    $0x1,%ebx
add    $0xffffffff,%r12d
jne    1130 <map_page_range+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @map_page_range(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %11
11: ; preds = %31, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
br label %23
19: ; preds = %15
%20 = load i32, i32* %7
%21 = load i32, i32* %9
%22 = add nsw i32 %20, %21
br label %23
23: ; preds = %19, %18
%24 = phi i32 [ -1, %18 ], [ %22, %19 ]
store i32 %24, i32* %10
%25 = load i32, i32* %5
%26 = load i32, i32* %9
%27 = add nsw i32 %25, %26
%28 = load i32, i32* %10
%29 = load i32, i32* %8
%30 = call i32 @map_page(i32 %27, i32 %28, i32 %29)
br label %31
31: ; preds = %23
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %11
34: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
define i32 @map_page_range(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %16
6: ; preds = %4
%7 = icmp sgt i32 %2, -1
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ 0, %6 ], [ %14, %8 ]
%10 = add nsw i32 %9, %2
%11 = select i1 %7, i32 %10, i32 -1
%12 = add nsw i32 %9, %0
%13 = tail call i32 @map_page(i32 %12, i32 %11, i32 %3)
%14 = add nuw nsw i32 %9, 1
%15 = icmp eq i32 %14, %1
br i1 %15, label %16, label %8
16: ; preds = %8, %4
ret i32 0
}