#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, long *, long *, char *,
                          int *);
scalar_t__ getpagesize();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  FILE *f = fopen(argv[1], "r");
  int access_flag = atoi(argv[2]);
  if (!f) {
    fprintf(stderr, "cannot open file %s\n", argv[1]);
    return 0;
  }
  long int low = 0, high = 0, size = 0;
  int tid;
  char desc[64];
  char *ptr = (char *)NULL;
  int i;
  while (!feof(f)) {
    fscanf(f, "%lx %lx %s %d", &low, &high, desc, &tid);
    if (feof(f))
      break;
    size = high - low;
    fprintf(stdout, "%lx\n", size);
    assert(size > 0);
    for (i = 0; i < size; i += getpagesize()) {
      ptr = (char *)(low + i);
      if (access_flag)
        *ptr = 0;
      fprintf(stdout, "%lx\n", (low + i));
    }
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe58(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f7 <main+0x77>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1347 <main+0x1c7>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x88(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1239 <main+0xb9>
jmp    1337 <main+0x1b7>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%r8
lea    0xdcf(%rip),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x3c(%rbp),%r9
call   1040 <fscanf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1271 <main+0xf1>
jmp    1337 <main+0x1b7>
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xd94(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmpq   $0x0,-0x38(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x0,-0x8c(%rbp)
movslq -0x8c(%rbp),%rax
cmp    -0x38(%rbp),%rax
jge    1332 <main+0x1b2>
mov    -0x28(%rbp),%rax
movslq -0x8c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x88(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12ee <main+0x16e>
mov    -0x88(%rbp),%rax
movb   $0x0,(%rax)
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
movslq -0x8c(%rbp),%rax
add    %rax,%rdx
lea    0xd19(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x0,%al
call   10a0 <getpagesize@plt>
mov    %rax,%rcx
movslq -0x8c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8c(%rbp)
jmp    12b4 <main+0x134>
jmp    121a <main+0x9a>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
call   1090 <atoi@plt>
test   %rbx,%rbx
je     11dc <main+0x5c>
mov    %eax,%ebp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     1208 <main+0x88>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11f7 <main+0x77>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe12(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc9(%rip),%r13
lea    0xe0f(%rip),%r15
mov    %rbx,0x10(%rsp)
jmp    1232 <main+0xb2>
nopl   (%rax)
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11d2 <main+0x52>
mov    %rbx,%rdi
lea    0xddb(%rip),%rsi
mov    %rsp,%rdx
lea    0x8(%rsp),%rcx
lea    0x20(%rsp),%r8
lea    0x1c(%rsp),%r9
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11d2 <main+0x52>
mov    0x8(%rsp),%r12
mov    0x0(%r13),%edi
mov    (%rsp),%rbx
mov    %r12,%r14
sub    %rbx,%r14
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %edi,%edi
test   %r14,%r14
setg   %dil
call   1050 <assert@plt>
sub    %rbx,%r12
jle    1220 <main+0xa0>
xor    %ebx,%ebx
jmp    12ca <main+0x14a>
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    (%rsp),%rdx
add    %rbx,%rdx
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
call   10a0 <getpagesize@plt>
add    %ebx,%eax
movslq %eax,%rbx
cmp    %r12,%rbx
jge    1220 <main+0xa0>
test   %ebp,%ebp
je     12a0 <main+0x120>
mov    (%rsp),%rax
movb   $0x0,(%rax,%rbx,1)
jmp    12a0 <main+0x120>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"cannot open file %s\0A\00"
@.str.2 = [14 x i8] c"%lx %lx %s %d\00"
@stdout = global i32 0
@.str.3 = [5 x i8] c"%lx\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca [64 x i8]
%13 = alloca i8*
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %7
%23 = load i32*, i32** %6
%24 = icmp ne i32* %23, null
br i1 %24, label %31, label %25
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %29)
store i32 0, i32* %3
br label %88
31: ; preds = %2
store i64 0, i64* %8
store i64 0, i64* %9
store i64 0, i64* %10
store i8* null, i8** %13
br label %32
32: ; preds = %84, %31
%33 = load i32*, i32** %6
%34 = call i64 @feof(i32* %33)
%35 = icmp ne i64 %34, 0
%36 = xor i1 %35, true
br i1 %36, label %37, label %85
37: ; preds = %32
%38 = load i32*, i32** %6
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%40 = call i32 @fscanf(i32* %38, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i64* %8, i64* %9, i8* %39, i32* %11)
%41 = load i32*, i32** %6
%42 = call i64 @feof(i32* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %37
br label %85
45: ; preds = %37
%46 = load i64, i64* %9
%47 = load i64, i64* %8
%48 = sub nsw i64 %46, %47
store i64 %48, i64* %10
%49 = load i32, i32* @stdout
%50 = load i64, i64* %10
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %50)
%52 = load i64, i64* %10
%53 = icmp sgt i64 %52, 0
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
store i32 0, i32* %14
br label %56
56: ; preds = %78, %45
%57 = load i32, i32* %14
%58 = sext i32 %57 to i64
%59 = load i64, i64* %10
%60 = icmp slt i64 %58, %59
br i1 %60, label %61, label %84
61: ; preds = %56
%62 = load i64, i64* %8
%63 = load i32, i32* %14
%64 = sext i32 %63 to i64
%65 = add nsw i64 %62, %64
%66 = inttoptr i64 %65 to i8*
store i8* %66, i8** %13
%67 = load i32, i32* %7
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %61
%70 = load i8*, i8** %13
store i8 0, i8* %70
br label %71
71: ; preds = %69, %61
%72 = load i32, i32* @stdout
%73 = load i64, i64* %8
%74 = load i32, i32* %14
%75 = sext i32 %74 to i64
%76 = add nsw i64 %73, %75
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %76)
br label %78
78: ; preds = %71
%79 = call i64 (...) @getpagesize()
%80 = load i32, i32* %14
%81 = sext i32 %80 to i64
%82 = add nsw i64 %81, %79
%83 = trunc i64 %82 to i32
store i32 %83, i32* %14
br label %56
84: ; preds = %56
br label %32
85: ; preds = %44, %32
%86 = load i32*, i32** %6
%87 = call i32 @fclose(i32* %86)
store i32 0, i32* %3
br label %88
88: ; preds = %85, %25
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"cannot open file %s\0A\00"
@.str.2 = [14 x i8] c"%lx %lx %s %d\00"
@stdout = global i32 0
@.str.3 = [5 x i8] c"%lx\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca [64 x i8]
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp eq i32* %9, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %7
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %61
18: ; preds = %2
%19 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%20 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%21 = bitcast i32* %5 to i8*
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%23 = call i64 @feof(i32* %9)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %59
25: ; preds = %18
%26 = icmp eq i32 %12, 0
br label %30
27: ; preds = %49, %34
%28 = call i64 @feof(i32* %9)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %59
30: ; preds = %25, %27
%31 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i64* %3, i64* %4, i8* %22, i32* %5)
%32 = call i64 @feof(i32* %9)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %59
34: ; preds = %30
%35 = load i64, i64* %4
%36 = load i64, i64* %3
%37 = sub nsw i64 %35, %36
%38 = load i32, i32* @stdout
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %37)
%40 = icmp sgt i64 %37, 0
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
br i1 %40, label %43, label %27
43: ; preds = %34, %49
%44 = phi i64 [ %57, %49 ], [ 0, %34 ]
br i1 %26, label %49, label %45
45: ; preds = %43
%46 = load i64, i64* %3
%47 = add nsw i64 %46, %44
%48 = inttoptr i64 %47 to i8*
store i8 0, i8* %48
br label %49
49: ; preds = %45, %43
%50 = load i32, i32* @stdout
%51 = load i64, i64* %3
%52 = add nsw i64 %51, %44
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %52)
%54 = call i64 (...) @getpagesize()
%55 = add nsw i64 %54, %44
%56 = shl i64 %55, 32
%57 = ashr exact i64 %56, 32
%58 = icmp slt i64 %57, %37
br i1 %58, label %43, label %27
59: ; preds = %27, %30, %18
%60 = call i32 @fclose(i32* %9)
br label %61
61: ; preds = %59, %14
ret i32 0
}