#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 */
typedef int /*<<< orphan*/ intmax_t;

/* Variables and functions */
int /*<<< orphan*/ err(int, char *);
int getpagesizes(size_t *, int);
size_t *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void test_pagesizes(void) {
  size_t *ps;
  int i, nelem;
  nelem = getpagesizes(NULL, 0);
  if (nelem == -1)
    err(1, "getpagesizes(NULL, 0)");
  ps = malloc(nelem * sizeof(size_t));
  if (ps == NULL)
    err(1, "malloc");
  nelem = getpagesizes(ps, nelem);
  if (nelem == -1)
    err(1, "getpagesizes");
  printf("Supported page sizes:");
  for (i = 0; i < nelem; i++)
    printf(" %jd", (intmax_t)ps[i]);
  printf("\n");
}


x86 assembly (clang, -O0):
<test_pagesizes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1060 <getpagesizes@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1171 <test_pagesizes+0x31>
mov    $0x1,%edi
lea    0xe94(%rip),%rsi
call   1040 <err@plt>
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a0 <test_pagesizes+0x60>
mov    $0x1,%edi
lea    0xe7b(%rip),%rsi
call   1040 <err@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1060 <getpagesizes@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11ca <test_pagesizes+0x8a>
mov    $0x1,%edi
lea    0xe58(%rip),%rsi
call   1040 <err@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1215 <test_pagesizes+0xd5>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %eax,%esi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11df <test_pagesizes+0x9f>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_pagesizes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
xor    %esi,%esi
call   1070 <getpagesizes@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1178 <test_pagesizes+0x28>
lea    0xe92(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    %ebp,%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    119b <test_pagesizes+0x4b>
lea    0xe85(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   1070 <getpagesizes@plt>
cmp    $0xffffffff,%eax
je     11e9 <test_pagesizes+0x99>
mov    %eax,%ebp
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    1208 <test_pagesizes+0xb8>
mov    %ebp,%ebp
lea    0xe79(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r15,%rbx,8),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11d0 <test_pagesizes+0x80>
jmp    1208 <test_pagesizes+0xb8>
lea    0xe2d(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
lea    0xe29(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"getpagesizes(NULL, 0)\00"
@.str.1 = [7 x i8] c"malloc\00"
@.str.2 = [13 x i8] c"getpagesizes\00"
@.str.3 = [22 x i8] c"Supported page sizes:\00"
@.str.4 = [5 x i8] c" %jd\00"
@.str.5 = [2 x i8] c"\0A\00"
define void @test_pagesizes() {
%1 = alloca i64*
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @getpagesizes(i64* null, i32 0)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @err(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 8
%13 = trunc i64 %12 to i32
%14 = call i64* @malloc(i32 %13)
store i64* %14, i64** %1
%15 = load i64*, i64** %1
%16 = icmp eq i64* %15, null
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %9
%20 = load i64*, i64** %1
%21 = load i32, i32* %3
%22 = call i32 @getpagesizes(i64* %20, i32 %21)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %29
29: ; preds = %41, %27
%30 = load i32, i32* %2
%31 = load i32, i32* %3
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %44
33: ; preds = %29
%34 = load i64*, i64** %1
%35 = load i32, i32* %2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i64, i64* %34, i64 %36
%38 = load i64, i64* %37
%39 = trunc i64 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %33
%42 = load i32, i32* %2
%43 = add nsw i32 %42, 1
store i32 %43, i32* %2
br label %29
44: ; preds = %29
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"getpagesizes(NULL, 0)\00"
@.str.1 = [7 x i8] c"malloc\00"
@.str.2 = [13 x i8] c"getpagesizes\00"
@.str.3 = [22 x i8] c"Supported page sizes:\00"
@.str.4 = [5 x i8] c" %jd\00"
define void @test_pagesizes() {
%1 = tail call i32 @getpagesizes(i64* null, i32 0)
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = shl i32 %1, 3
%7 = tail call i64* @malloc(i32 %6)
%8 = icmp eq i64* %7, null
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %5
%12 = tail call i32 @getpagesizes(i64* %7, i32 %1)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %30
17: ; preds = %11
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp sgt i32 %12, 0
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = zext i32 %12 to i64
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ 0, %20 ], [ %28, %22 ]
%24 = getelementptr inbounds i64, i64* %7, i64 %23
%25 = load i64, i64* %24
%26 = trunc i64 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = add nuw nsw i64 %23, 1
%29 = icmp eq i64 %28, %21
br i1 %29, label %30, label %22
30: ; preds = %22, %14, %17
%31 = tail call i32 @putchar(i32 10)
ret void
}