#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 */
struct page_directory {
  int dummy;
};

/* Variables and functions */
int page_directory_install_page_table(struct page_directory *, unsigned long,
                                      unsigned long, unsigned int);
int page_directory_install_page_tables(struct page_directory *pd,
                                       unsigned long pfindex,
                                       unsigned long index, unsigned long count,
                                       unsigned int flags) {
  int err;
  for (err = 0; count && !(err < 0); --count, ++index, ++pfindex) {
    err = page_directory_install_page_table(pd, pfindex, index, flags);
  }
  return err;
}


x86 assembly (clang, -O0):
<page_directory_install_page_tables>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x29(%rbp)
je     114f <page_directory_install_page_tables+0x3f>
cmpl   $0x0,-0x28(%rbp)
setl   %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    115f <page_directory_install_page_tables+0x4f>
jmp    119f <page_directory_install_page_tables+0x8f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1030 <page_directory_install_page_table@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1133 <page_directory_install_page_tables+0x23>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<page_directory_install_page_tables>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rcx,%rcx
je     1155 <page_directory_install_page_tables+0x45>
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r12
add    $0xffffffffffffffff,%r15
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r14d,%ecx
call   1030 <page_directory_install_page_table@plt>
add    $0xffffffffffffffff,%r15
jae    1157 <page_directory_install_page_tables+0x47>
add    $0x1,%rbp
add    $0x1,%rbx
test   %eax,%eax
jns    1130 <page_directory_install_page_tables+0x20>
jmp    1157 <page_directory_install_page_tables+0x47>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.page_directory = type { i32 }
define i32 @page_directory_install_page_tables(%struct.page_directory* %0, i64 %1, i64 %2, i64 %3, i32 %4) {
%6 = icmp eq i64 %3, 0
br i1 %6, label %18, label %7
7: ; preds = %5, %7
%8 = phi i64 [ %14, %7 ], [ %1, %5 ]
%9 = phi i64 [ %12, %7 ], [ %3, %5 ]
%10 = phi i64 [ %13, %7 ], [ %2, %5 ]
%11 = tail call i32 @page_directory_install_page_table(%struct.page_directory* %0, i64 %8, i64 %10, i32 %4)
%12 = add i64 %9, -1
%13 = add i64 %10, 1
%14 = add i64 %8, 1
%15 = icmp ne i64 %12, 0
%16 = icmp sgt i32 %11, -1
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %7, label %18
18: ; preds = %7, %5
%19 = phi i32 [ 0, %5 ], [ %11, %7 ]
ret i32 %19
}