#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*/ assert(int);
int /*<<< orphan*/ dummyassert(int);
int /*<<< orphan*/ validptr(int *);
int page_free(int ppno, int pages[], int page_protected[]) {
  assert(0 <= ppno);
  assert(ppno < 1000);
  dummyassert(pages[ppno] > 0 || page_protected[ppno] == 0);
  validptr(pages + ppno);
  return pages[ppno] == 0;
}


x86 assembly (clang, -O0):
<page_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x4(%rbp),%eax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x3e8,-0x4(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rcx
movslq -0x4(%rbp),%rdx
mov    $0x1,%al
cmpl   $0x0,(%rcx,%rdx,4)
mov    %al,-0x19(%rbp)
jg     1192 <page_free+0x62>
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <dummyassert@plt>
mov    -0x10(%rbp),%rdi
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1050 <validptr@plt>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<page_free>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
xor    %edi,%edi
cmp    $0x3e8,%ebp
setl   %dil
call   1040 <assert@plt>
movslq %ebp,%rax
lea    (%rbx,%rax,4),%r15
mov    $0x1,%edi
cmpl   $0x0,(%rbx,%rax,4)
jg     1177 <page_free+0x47>
xor    %edi,%edi
cmpl   $0x0,(%r14,%rax,4)
sete   %dil
call   1030 <dummyassert@plt>
mov    %r15,%rdi
call   1050 <validptr@plt>
xor    %eax,%eax
cmpl   $0x0,(%r15)
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @page_free(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 = icmp sle i32 0, %7
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 1000
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32*, i32** %5
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = icmp sgt i32 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %3
%22 = load i32*, i32** %6
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
br label %28
28: ; preds = %21, %3
%29 = phi i1 [ true, %3 ], [ %27, %21 ]
%30 = zext i1 %29 to i32
%31 = call i32 @dummyassert(i32 %30)
%32 = load i32*, i32** %5
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = call i32 @validptr(i32* %35)
%37 = load i32*, i32** %5
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = icmp eq i32 %41, 0
%43 = zext i1 %42 to i32
ret i32 %43
}

LLVM IR (-O2):
define i32 @page_free(i32 %0, i32* %1, i32* nocapture %2) {
%4 = xor i32 %0, -1
%5 = lshr i32 %4, 31
%6 = tail call i32 @assert(i32 %5)
%7 = icmp slt i32 %0, 1000
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = sext i32 %0 to i64
%11 = getelementptr inbounds i32, i32* %1, i64 %10
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %3
%15 = getelementptr inbounds i32, i32* %2, i64 %10
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %14, %3
%20 = phi i32 [ 1, %3 ], [ %18, %14 ]
%21 = tail call i32 @dummyassert(i32 %20)
%22 = tail call i32 @validptr(i32* %11)
%23 = load i32, i32* %11
%24 = icmp eq i32 %23, 0
%25 = zext i1 %24 to i32
ret i32 %25
}