#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*/ validptr(int *);
int page_getfree(int pages[]) {
  int i;
  int rv;
  int rv2;
  for (i = 0; i < 1000; i++) {
    validptr(pages + i);
    if (pages[i] == 0) {
      return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<page_getfree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jge    1174 <page_getfree+0x64>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1030 <validptr@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    1161 <page_getfree+0x51>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117b <page_getfree+0x6b>
jmp    1166 <page_getfree+0x56>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1123 <page_getfree+0x13>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<page_getfree>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <validptr@plt>
cmpl   $0x0,(%rbx)
je     1146 <page_getfree+0x36>
add    $0xffffffffffffffff,%r14
add    $0x4,%rbx
cmp    $0xfffffffffffffc18,%r14
jne    1120 <page_getfree+0x10>
mov    $0xffffffff,%r14d
jmp    1149 <page_getfree+0x39>
neg    %r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @page_getfree(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %4
br label %7
7: ; preds = %25, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 1000
br i1 %9, label %10, label %28
10: ; preds = %7
%11 = load i32*, i32** %3
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
%15 = call i32 @validptr(i32* %14)
%16 = load i32*, i32** %3
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %10
%23 = load i32, i32* %4
store i32 %23, i32* %2
br label %29
24: ; preds = %10
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %7
28: ; preds = %7
store i32 -1, i32* %2
br label %29
29: ; preds = %28, %22
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @page_getfree(i32* %0) {
br label %2
2: ; preds = %1, %8
%3 = phi i64 [ 0, %1 ], [ %9, %8 ]
%4 = getelementptr inbounds i32, i32* %0, i64 %3
%5 = tail call i32 @validptr(i32* %4)
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = add nuw nsw i64 %3, 1
%10 = icmp eq i64 %9, 1000
br i1 %10, label %13, label %2
11: ; preds = %2
%12 = trunc i64 %3 to i32
br label %13
13: ; preds = %8, %11
%14 = phi i32 [ %12, %11 ], [ -1, %8 ]
ret i32 %14
}