#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 */
struct stat {
  scalar_t__ st_size;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ POSIX_FADV_DONTNEED;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ exiterr(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fstat(int, struct stat *);
int open(char *, int /*<<< orphan*/);
int posix_fadvise(int, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int i, n = 1;
  int fd;
  char *fn;
  struct stat st;
  if (argc == 4 && !strcmp("-n", argv[1])) {
    n = atoi(argv[2]);
    fn = argv[3];
  } else if (argc != 2) {
    fprintf(stderr,
            "usage: %s [-n <n>] <file> "
            "-- call fadvise(DONTNEED) <n> times on file\n",
            argv[0]);
    exit(1);
  } else {
    fn = argv[1];
  }
  fd = open(fn, O_RDONLY);
  if (fd == -1)
    exiterr("open");
  if (fstat(fd, &st) == -1)
    exiterr("fstat");
  if (!S_ISREG(st.st_mode)) {
    fprintf(stderr, "%s: S_ISREG: not a regular file", fn);
    return EXIT_FAILURE;
  }
  if (st.st_size == 0) {
    fprintf(stderr, "%s: file size is 0!\n", fn);
    return EXIT_FAILURE;
  }
  for (i = 0; i < n; i++)
    if (posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED) == -1)
      exiterr("posix_fadvise");
  return EXIT_SUCCESS;
}


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)
movl   $0x1,-0x18(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    11f5 <main+0x65>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe3a(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11f5 <main+0x65>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1236 <main+0xa6>
cmpl   $0x2,-0x8(%rbp)
je     1225 <main+0x95>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xded(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1236 <main+0xa6>
mov    -0x28(%rbp),%rdi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1261 <main+0xd1>
lea    0xdee(%rip),%rdi
call   1030 <exiterr@plt>
mov    -0x1c(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1282 <main+0xf2>
lea    0xdd2(%rip),%rdi
call   1030 <exiterr@plt>
mov    -0x30(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%eax
jne    12bd <main+0x12d>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdae(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    134e <main+0x1be>
cmpq   $0x0,-0x38(%rbp)
jne    12f2 <main+0x162>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd99(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    134e <main+0x1be>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1342 <main+0x1b2>
mov    -0x1c(%rbp),%edi
mov    0x2ce1(%rip),%rax
mov    (%rax),%ecx
xor    %edx,%edx
mov    %edx,%esi
call   1040 <posix_fadvise@plt>
cmp    $0xffffffff,%eax
jne    132f <main+0x19f>
lea    0xd60(%rip),%rdi
call   1030 <exiterr@plt>
jmp    1334 <main+0x1a4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12f9 <main+0x169>
mov    0x2c77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
cmp    $0x2,%edi
je     11d7 <main+0x47>
cmp    $0x4,%edi
jne    12bb <main+0x12b>
mov    0x8(%rbp),%rsi
lea    0xe48(%rip),%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    12bb <main+0x12b>
mov    0x10(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
mov    $0x3,%eax
jmp    11e1 <main+0x51>
mov    $0x1,%ebx
mov    $0x1,%eax
mov    0x0(%rbp,%rax,8),%r14
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1080 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    120a <main+0x7a>
lea    0xe45(%rip),%rdi
call   1030 <exiterr@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1225 <main+0x95>
lea    0xe2f(%rip),%rdi
call   1030 <exiterr@plt>
mov    0x8(%rsp),%edi
call   1070 <S_ISREG@plt>
test   %eax,%eax
je     1283 <main+0xf3>
cmpq   $0x0,(%rsp)
je     128c <main+0xfc>
mov    0x2d80(%rip),%r15
test   %ebx,%ebx
jle    12ab <main+0x11b>
mov    0x2da5(%rip),%r12
lea    0xe38(%rip),%r14
jmp    1265 <main+0xd5>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffff,%ebx
je     12ab <main+0x11b>
mov    (%r12),%ecx
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <posix_fadvise@plt>
cmp    $0xffffffff,%eax
jne    1260 <main+0xd0>
mov    %r14,%rdi
call   1030 <exiterr@plt>
jmp    1260 <main+0xd0>
lea    0xdcb(%rip),%rsi
jmp    1293 <main+0x103>
lea    0xde2(%rip),%rsi
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    0x2d1d(%rip),%r15
mov    (%r15),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xd34(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64, i32 }
@.str = [3 x i8] c"-n\00"
@stderr = global i32 0
@.str.1 = [71 x i8] c"usage: %s [-n <n>] <file> -- call fadvise(DONTNEED) <n> times on file\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"fstat\00"
@.str.4 = [32 x i8] c"%s: S_ISREG: not a regular file\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [21 x i8] c"%s: file size is 0!\0A\00"
@POSIX_FADV_DONTNEED = global i32 0
@.str.6 = [14 x i8] c"posix_fadvise\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 4
br i1 %12, label %13, label %27
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %27, label %19
19: ; preds = %13
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %7
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 3
%26 = load i8*, i8** %25
store i8* %26, i8** %9
br label %42
27: ; preds = %13, %2
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 2
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %27
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
store i8* %40, i8** %9
br label %41
41: ; preds = %37
br label %42
42: ; preds = %41, %19
%43 = load i8*, i8** %9
%44 = load i32, i32* @O_RDONLY
%45 = call i32 @open(i8* %43, i32 %44)
store i32 %45, i32* %8
%46 = load i32, i32* %8
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = call i32 @exiterr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %48, %42
%51 = load i32, i32* %8
%52 = call i32 @fstat(i32 %51, %struct.stat* %10)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 @exiterr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %54, %50
%57 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 1
%58 = load i32, i32* %57
%59 = call i32 @S_ISREG(i32 %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %66, label %61
61: ; preds = %56
%62 = load i32, i32* @stderr
%63 = load i8*, i8** %9
%64 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %63)
%65 = load i32, i32* @EXIT_FAILURE
store i32 %65, i32* %3
br label %93
66: ; preds = %56
%67 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%68 = load i64, i64* %67
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %66
%71 = load i32, i32* @stderr
%72 = load i8*, i8** %9
%73 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %72)
%74 = load i32, i32* @EXIT_FAILURE
store i32 %74, i32* %3
br label %93
75: ; preds = %66
store i32 0, i32* %6
br label %76
76: ; preds = %88, %75
%77 = load i32, i32* %6
%78 = load i32, i32* %7
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %91
80: ; preds = %76
%81 = load i32, i32* %8
%82 = load i32, i32* @POSIX_FADV_DONTNEED
%83 = call i32 @posix_fadvise(i32 %81, i32 0, i32 0, i32 %82)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %87
85: ; preds = %80
%86 = call i32 @exiterr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %87
87: ; preds = %85, %80
br label %88
88: ; preds = %87
%89 = load i32, i32* %6
%90 = add nsw i32 %89, 1
store i32 %90, i32* %6
br label %76
91: ; preds = %76
%92 = load i32, i32* @EXIT_SUCCESS
store i32 %92, i32* %3
br label %93
93: ; preds = %91, %70, %61
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
@.str = [3 x i8] c"-n\00"
@stderr = global i32 0
@.str.1 = [71 x i8] c"usage: %s [-n <n>] <file> -- call fadvise(DONTNEED) <n> times on file\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"fstat\00"
@.str.4 = [32 x i8] c"%s: S_ISREG: not a regular file\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [21 x i8] c"%s: file size is 0!\0A\00"
@POSIX_FADV_DONTNEED = global i32 0
@.str.6 = [14 x i8] c"posix_fadvise\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
switch i32 %0, label %14 [
i32 4, label %5
i32 2, label %19
]
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* dereferenceable(1) %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
br label %19
14: ; preds = %5, %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %2, %10
%20 = phi i64 [ 3, %10 ], [ 1, %2 ]
%21 = phi i32 [ %13, %10 ], [ 1, %2 ]
%22 = getelementptr inbounds i8*, i8** %1, i64 %20
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_RDONLY
%25 = tail call i32 @open(i8* %23, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = tail call i32 @exiterr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %19
%30 = call i32 @fstat(i32 %25, %struct.stat* %3)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = tail call i32 @exiterr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
%35 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%36 = load i32, i32* %35
%37 = tail call i32 @S_ISREG(i32 %36)
%38 = icmp eq i32 %37, 0
br i1 %38, label %55, label %39
39: ; preds = %34
%40 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%41 = load i64, i64* %40
%42 = icmp eq i64 %41, 0
br i1 %42, label %55, label %43
43: ; preds = %39
%44 = icmp sgt i32 %21, 0
br i1 %44, label %45, label %59
45: ; preds = %43, %52
%46 = phi i32 [ %53, %52 ], [ 0, %43 ]
%47 = load i32, i32* @POSIX_FADV_DONTNEED
%48 = tail call i32 @posix_fadvise(i32 %25, i32 0, i32 0, i32 %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = tail call i32 @exiterr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %52
52: ; preds = %45, %50
%53 = add nuw nsw i32 %46, 1
%54 = icmp eq i32 %53, %21
br i1 %54, label %59, label %45
55: ; preds = %39, %34
%56 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), %34 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), %39 ]
%57 = load i32, i32* @stderr
%58 = tail call i32 @fprintf(i32 %57, i8* %56, i8* %23)
br label %59
59: ; preds = %52, %55, %43
%60 = phi i32* [ @EXIT_SUCCESS, %43 ], [ @EXIT_FAILURE, %55 ], [ @EXIT_SUCCESS, %52 ]
%61 = load i32, i32* %60
ret i32 %61
}