#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 */
size_t getpagesize();
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int mincore(void *, size_t, unsigned char *);
int /*<<< orphan*/ munmap(void *, size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ posix_memalign(void **, size_t, size_t);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int ret;
  void *ptr;
  unsigned char mincore_vec[5];
  size_t page_size;
  size_t size;
  size_t page_index;
  page_size = getpagesize();
  size = page_size * 5;
  posix_memalign(&ptr, page_size, size);
  memset(ptr, 0, 4096 * 2);
  ret = mincore(ptr, size, mincore_vec);
  if (ret < 0)
    perror("mincore");
  for (page_index = 0; page_index < 5; page_index++) {
    if (mincore_vec[page_index] & 1)
      printf("%lu ", (unsigned long)page_index);
  }
  printf("\n");
  memset(ptr, 0, size);
  ret = mincore(ptr, size, mincore_vec);
  if (ret < 0)
    perror("mincore");
  for (page_index = 0; page_index < 5; page_index++) {
    if (mincore_vec[page_index] & 1)
      printf("%lu ", (unsigned long)page_index);
  }
  printf("\n");
  munmap(ptr, size);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <getpagesize@plt>
mov    %rax,-0x30(%rbp)
imul   $0x5,-0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    -0x20(%rbp),%rdi
call   1090 <posix_memalign@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    -0x25(%rbp),%rdx
call   1050 <mincore@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11e5 <main+0x75>
lea    0xe20(%rip),%rdi
call   1070 <perror@plt>
movq   $0x0,-0x40(%rbp)
cmpq   $0x5,-0x40(%rbp)
jae    1235 <main+0xc5>
mov    -0x40(%rbp),%rax
movzbl -0x25(%rbp,%rax,1),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     121f <main+0xaf>
mov    -0x40(%rbp),%rsi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1224 <main+0xb4>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11ed <main+0x7d>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    -0x25(%rbp),%rdx
call   1050 <mincore@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    127c <main+0x10c>
lea    0xd89(%rip),%rdi
call   1070 <perror@plt>
movq   $0x0,-0x40(%rbp)
cmpq   $0x5,-0x40(%rbp)
jae    12cc <main+0x15c>
mov    -0x40(%rbp),%rax
movzbl -0x25(%rbp,%rax,1),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     12b6 <main+0x146>
mov    -0x40(%rbp),%rsi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12bb <main+0x14b>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1284 <main+0x114>
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <munmap@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1090 <getpagesize@plt>
lea    (%rax,%rax,4),%rbx
lea    0x8(%rsp),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   10a0 <posix_memalign@plt>
mov    0x8(%rsp),%rdi
mov    $0x2000,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x8(%rsp),%rdi
lea    0x3(%rsp),%rdx
mov    %rbx,%rsi
call   1060 <mincore@plt>
test   %eax,%eax
js     12a9 <main+0x129>
testb  $0x1,0x3(%rsp)
jne    12c0 <main+0x140>
testb  $0x1,0x4(%rsp)
jne    12db <main+0x15b>
testb  $0x1,0x5(%rsp)
jne    12f9 <main+0x179>
testb  $0x1,0x6(%rsp)
jne    1317 <main+0x197>
testb  $0x1,0x7(%rsp)
je     1211 <main+0x91>
lea    0xe03(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
mov    0x8(%rsp),%rdi
lea    0x3(%rsp),%rdx
mov    %rbx,%rsi
call   1060 <mincore@plt>
test   %eax,%eax
js     133a <main+0x1ba>
testb  $0x1,0x3(%rsp)
jne    1351 <main+0x1d1>
testb  $0x1,0x4(%rsp)
jne    136c <main+0x1ec>
testb  $0x1,0x5(%rsp)
jne    138a <main+0x20a>
testb  $0x1,0x6(%rsp)
jne    13a8 <main+0x228>
testb  $0x1,0x7(%rsp)
je     128a <main+0x10a>
lea    0xd8a(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1070 <munmap@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xd50(%rip),%rdi
call   1080 <perror@plt>
testb  $0x1,0x3(%rsp)
je     11d6 <main+0x56>
lea    0xd41(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
testb  $0x1,0x4(%rsp)
je     11e1 <main+0x61>
lea    0xd26(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
testb  $0x1,0x5(%rsp)
je     11ec <main+0x6c>
lea    0xd08(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
testb  $0x1,0x6(%rsp)
je     11f7 <main+0x77>
lea    0xcea(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
testb  $0x1,0x7(%rsp)
jne    11fe <main+0x7e>
jmp    1211 <main+0x91>
lea    0xcbf(%rip),%rdi
call   1080 <perror@plt>
testb  $0x1,0x3(%rsp)
je     124f <main+0xcf>
lea    0xcb0(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
testb  $0x1,0x4(%rsp)
je     125a <main+0xda>
lea    0xc95(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
testb  $0x1,0x5(%rsp)
je     1265 <main+0xe5>
lea    0xc77(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
testb  $0x1,0x6(%rsp)
je     1270 <main+0xf0>
lea    0xc59(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
testb  $0x1,0x7(%rsp)
jne    1277 <main+0xf7>
jmp    128a <main+0x10a>

LLVM IR (-O0):
@.str = [8 x i8] c"mincore\00"
@.str.1 = [5 x i8] c"%lu \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [5 x i8]
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i64 (...) @getpagesize()
store i64 %12, i64* %9
%13 = load i64, i64* %9
%14 = mul i64 %13, 5
store i64 %14, i64* %10
%15 = load i64, i64* %9
%16 = load i64, i64* %10
%17 = call i32 @posix_memalign(i8** %7, i64 %15, i64 %16)
%18 = load i8*, i8** %7
%19 = call i32 @memset(i8* %18, i32 0, i64 8192)
%20 = load i8*, i8** %7
%21 = load i64, i64* %10
%22 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%23 = call i32 @mincore(i8* %20, i64 %21, i8* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %2
store i64 0, i64* %11
br label %29
29: ; preds = %43, %28
%30 = load i64, i64* %11
%31 = icmp ult i64 %30, 5
br i1 %31, label %32, label %46
32: ; preds = %29
%33 = load i64, i64* %11
%34 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = and i32 %36, 1
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = load i64, i64* %11
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %40)
br label %42
42: ; preds = %39, %32
br label %43
43: ; preds = %42
%44 = load i64, i64* %11
%45 = add i64 %44, 1
store i64 %45, i64* %11
br label %29
46: ; preds = %29
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%48 = load i8*, i8** %7
%49 = load i64, i64* %10
%50 = call i32 @memset(i8* %48, i32 0, i64 %49)
%51 = load i8*, i8** %7
%52 = load i64, i64* %10
%53 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%54 = call i32 @mincore(i8* %51, i64 %52, i8* %53)
store i32 %54, i32* %6
%55 = load i32, i32* %6
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %46
%58 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %59
59: ; preds = %57, %46
store i64 0, i64* %11
br label %60
60: ; preds = %74, %59
%61 = load i64, i64* %11
%62 = icmp ult i64 %61, 5
br i1 %62, label %63, label %77
63: ; preds = %60
%64 = load i64, i64* %11
%65 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 %64
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = and i32 %67, 1
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %63
%71 = load i64, i64* %11
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %71)
br label %73
73: ; preds = %70, %63
br label %74
74: ; preds = %73
%75 = load i64, i64* %11
%76 = add i64 %75, 1
store i64 %76, i64* %11
br label %60
77: ; preds = %60
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%79 = load i8*, i8** %7
%80 = load i64, i64* %10
%81 = call i32 @munmap(i8* %79, i64 %80)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"mincore\00"
@.str.1 = [5 x i8] c"%lu \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca [5 x i8]
%5 = bitcast i8** %3 to i8*
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%7 = tail call i64 (...) @getpagesize()
%8 = mul i64 %7, 5
%9 = call i32 @posix_memalign(i8** %3, i64 %7, i64 %8)
%10 = load i8*, i8** %3
%11 = call i32 @memset(i8* %10, i32 0, i64 8192)
%12 = load i8*, i8** %3
%13 = call i32 @mincore(i8* %12, i64 %8, i8* %6)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = load i8, i8* %6
%19 = and i8 %18, 1
%20 = icmp eq i8 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 0)
br label %23
23: ; preds = %17, %21
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 1
%25 = load i8, i8* %24
%26 = and i8 %25, 1
%27 = icmp eq i8 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 1)
br label %30
30: ; preds = %28, %23
%31 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 2
%32 = load i8, i8* %31
%33 = and i8 %32, 1
%34 = icmp eq i8 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %30
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 2)
br label %37
37: ; preds = %35, %30
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 3
%39 = load i8, i8* %38
%40 = and i8 %39, 1
%41 = icmp eq i8 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %37
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 3)
br label %44
44: ; preds = %42, %37
%45 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 4
%46 = load i8, i8* %45
%47 = and i8 %46, 1
%48 = icmp eq i8 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %44
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 4)
br label %51
51: ; preds = %49, %44
%52 = call i32 @putchar(i32 10)
%53 = load i8*, i8** %3
%54 = call i32 @memset(i8* %53, i32 0, i64 %8)
%55 = load i8*, i8** %3
%56 = call i32 @mincore(i8* %55, i64 %8, i8* %6)
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %51
%59 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %60
60: ; preds = %58, %51
%61 = load i8, i8* %6
%62 = and i8 %61, 1
%63 = icmp eq i8 %62, 0
br i1 %63, label %66, label %64
64: ; preds = %60
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 0)
br label %66
66: ; preds = %60, %64
%67 = load i8, i8* %24
%68 = and i8 %67, 1
%69 = icmp eq i8 %68, 0
br i1 %69, label %72, label %70
70: ; preds = %66
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 1)
br label %72
72: ; preds = %70, %66
%73 = load i8, i8* %31
%74 = and i8 %73, 1
%75 = icmp eq i8 %74, 0
br i1 %75, label %78, label %76
76: ; preds = %72
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 2)
br label %78
78: ; preds = %76, %72
%79 = load i8, i8* %38
%80 = and i8 %79, 1
%81 = icmp eq i8 %80, 0
br i1 %81, label %84, label %82
82: ; preds = %78
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 3)
br label %84
84: ; preds = %82, %78
%85 = load i8, i8* %45
%86 = and i8 %85, 1
%87 = icmp eq i8 %86, 0
br i1 %87, label %90, label %88
88: ; preds = %84
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 4)
br label %90
90: ; preds = %88, %84
%91 = call i32 @putchar(i32 10)
%92 = load i8*, i8** %3
%93 = call i32 @munmap(i8* %92, i64 %8)
ret i32 0
}