#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*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int test(int, int);
int main() {
  int PAGE_SIZE, result;
  printf("writing to %s\n", "test.out");
  for (PAGE_SIZE = 16384; PAGE_SIZE >= 4; PAGE_SIZE /= 2) {
    printf("trying page size %d...\n", PAGE_SIZE);
    result = test(PAGE_SIZE, PAGE_SIZE);
    if (result) {
      puts("failure");
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeb2(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x4000,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     11cc <main+0x8c>
mov    -0x8(%rbp),%esi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <test@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11b4 <main+0x74>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11b9 <main+0x79>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    116b <main+0x2b>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeb8(%rip),%rdi
lea    0xec0(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebb(%rip),%rdi
mov    $0x4000,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x4000,%edi
mov    $0x4000,%esi
call   1060 <test@plt>
test   %eax,%eax
jne    136c <main+0x22c>
lea    0xe91(%rip),%rdi
mov    $0x2000,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2000,%edi
mov    $0x2000,%esi
call   1060 <test@plt>
test   %eax,%eax
jne    136c <main+0x22c>
lea    0xe67(%rip),%rdi
mov    $0x1000,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1000,%edi
mov    $0x1000,%esi
call   1060 <test@plt>
test   %eax,%eax
jne    136c <main+0x22c>
lea    0xe3d(%rip),%rdi
mov    $0x800,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x800,%edi
mov    $0x800,%esi
call   1060 <test@plt>
test   %eax,%eax
jne    136c <main+0x22c>
lea    0xe13(%rip),%rdi
mov    $0x400,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x400,%edi
mov    $0x400,%esi
call   1060 <test@plt>
test   %eax,%eax
jne    136c <main+0x22c>
lea    0xde9(%rip),%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x200,%edi
mov    $0x200,%esi
call   1060 <test@plt>
test   %eax,%eax
jne    136c <main+0x22c>
lea    0xdbf(%rip),%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x100,%edi
mov    $0x100,%esi
call   1060 <test@plt>
test   %eax,%eax
jne    136c <main+0x22c>
lea    0xd95(%rip),%rdi
mov    $0x80,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x80,%edi
mov    $0x80,%esi
call   1060 <test@plt>
test   %eax,%eax
jne    136c <main+0x22c>
lea    0xd6b(%rip),%rdi
mov    $0x40,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x40,%edi
mov    $0x40,%esi
call   1060 <test@plt>
test   %eax,%eax
jne    136c <main+0x22c>
lea    0xd41(%rip),%rdi
mov    $0x20,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x20,%edi
mov    $0x20,%esi
call   1060 <test@plt>
test   %eax,%eax
jne    136c <main+0x22c>
lea    0xd1b(%rip),%rdi
mov    $0x10,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x10,%edi
mov    $0x10,%esi
call   1060 <test@plt>
test   %eax,%eax
jne    136c <main+0x22c>
lea    0xcf5(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x8,%edi
mov    $0x8,%esi
call   1060 <test@plt>
test   %eax,%eax
jne    136c <main+0x22c>
lea    0xccf(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x4,%edi
mov    $0x4,%esi
call   1060 <test@plt>
test   %eax,%eax
jne    136c <main+0x22c>
xor    %eax,%eax
pop    %rcx
ret
lea    0xcbd(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"writing to %s\0A\00"
@.str.1 = [9 x i8] c"test.out\00"
@.str.2 = [24 x i8] c"trying page size %d...\0A\00"
@.str.3 = [8 x i8] c"failure\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 16384, i32* %2
br label %5
5: ; preds = %20, %0
%6 = load i32, i32* %2
%7 = icmp sge i32 %6, 4
br i1 %7, label %8, label %23
8: ; preds = %5
%9 = load i32, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %2
%12 = load i32, i32* %2
%13 = call i32 @test(i32 %11, i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %8
br label %20
20: ; preds = %19
%21 = load i32, i32* %2
%22 = sdiv i32 %21, 2
store i32 %22, i32* %2
br label %5
23: ; preds = %5
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [15 x i8] c"writing to %s\0A\00"
@.str.1 = [9 x i8] c"test.out\00"
@.str.2 = [24 x i8] c"trying page size %d...\0A\00"
@.str.3 = [8 x i8] c"failure\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 16384)
%3 = tail call i32 @test(i32 16384, i32 16384)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %54
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 8192)
%7 = tail call i32 @test(i32 8192, i32 8192)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %54
9: ; preds = %5
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 4096)
%11 = tail call i32 @test(i32 4096, i32 4096)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %54
13: ; preds = %9
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 2048)
%15 = tail call i32 @test(i32 2048, i32 2048)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %54
17: ; preds = %13
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 1024)
%19 = tail call i32 @test(i32 1024, i32 1024)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %54
21: ; preds = %17
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 512)
%23 = tail call i32 @test(i32 512, i32 512)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %54
25: ; preds = %21
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 256)
%27 = tail call i32 @test(i32 256, i32 256)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %54
29: ; preds = %25
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 128)
%31 = tail call i32 @test(i32 128, i32 128)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %54
33: ; preds = %29
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 64)
%35 = tail call i32 @test(i32 64, i32 64)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %54
37: ; preds = %33
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 32)
%39 = tail call i32 @test(i32 32, i32 32)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %54
41: ; preds = %37
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 16)
%43 = tail call i32 @test(i32 16, i32 16)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %54
45: ; preds = %41
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 8)
%47 = tail call i32 @test(i32 8, i32 8)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %45
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 4)
%51 = tail call i32 @test(i32 4, i32 4)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %49
ret i32 0
54: ; preds = %49, %45, %41, %37, %33, %29, %25, %21, %17, %13, %9, %5, %0
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%56 = tail call i32 @exit(i32 1)
unreachable
}