#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;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ MADV_SEQUENTIAL;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ madvise(void *, int, int /*<<< orphan*/);
void *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char);
scalar_t__ stat(char *, struct stat *);
int main(int argc, char const *argv[]) {
  struct stat fileinfo;
  if (stat("/root/MAINTAINERS", &fileinfo) < 0) {
    perror("stat");
    exit(EXIT_FAILURE);
  }
  int file_size = (int)fileinfo.st_size;
  int fd = open("/root/MAINTAINERS", O_RDONLY);
  printf("%d\n", file_size);
  void *address = mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
  if (!address)
    exit(EXIT_FAILURE);
  if (madvise(address, file_size, MADV_SEQUENTIAL) < 0) {
    exit(EXIT_FAILURE);
  }
  int i;
  for (i = 0; i < file_size / sizeof(char); i++) {
    printf("%c", ((char *)address)[i]);
  }
  munmap(address, file_size);
  close(fd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe53(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jge    11da <main+0x4a>
lea    0xe4b(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
lea    0xe0f(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
lea    0xe14(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
mov    0x2da2(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    124d <main+0xbd>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2d55(%rip),%rax
mov    (%rax),%edx
call   1080 <madvise@plt>
cmp    $0x0,%rax
jge    127a <main+0xea>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shr    $0x0,%rcx
cmp    %rcx,%rax
jae    12bc <main+0x12c>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
lea    0xd76(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1281 <main+0xf1>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <munmap@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe5e(%rip),%rdi
mov    %rsp,%rsi
call   1060 <stat@plt>
test   %rax,%rax
jns    11bd <main+0x2d>
lea    0xe5c(%rip),%rdi
call   10a0 <perror@plt>
jmp    122c <main+0x9c>
mov    (%rsp),%r15
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
lea    0xe2f(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%r14d
movsbl %r15b,%esi
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
mov    0x2dc7(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r15d,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
test   %rax,%rax
je     122c <main+0x9c>
mov    %rax,%r13
mov    0x2d96(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    %r15d,%esi
call   1080 <madvise@plt>
test   %rax,%rax
jns    123a <main+0xaa>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    %r15,%rax
shl    $0x20,%rax
je     1277 <main+0xe7>
sar    $0x20,%rax
cmp    $0x2,%rax
mov    $0x1,%ebx
cmovae %rax,%rbx
xor    %ebp,%ebp
lea    0xdbe(%rip),%r12
nopl   (%rax)
movsbl 0x0(%r13,%rbp,1),%esi
mov    %r12,%rdi
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1260 <main+0xd0>
mov    %r13,%rdi
mov    %r15d,%esi
call   1070 <munmap@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [18 x i8] c"/root/MAINTAINERS\00"
@.str.1 = [5 x i8] c"stat\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [4 x i8] c"%d\0A\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MADV_SEQUENTIAL = global i32 0
@.str.3 = [3 x i8] c"%c\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i64 @stat(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.stat* %6)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%19 = load i64, i64* %18
%20 = trunc i64 %19 to i32
store i32 %20, i32* %7
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 %22, i32* %8
%23 = load i32, i32* %7
%24 = trunc i32 %23 to i8
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8 signext %24)
%26 = load i32, i32* %7
%27 = load i32, i32* @PROT_READ
%28 = load i32, i32* @MAP_PRIVATE
%29 = load i32, i32* %8
%30 = call i8* @mmap(i32* null, i32 %26, i32 %27, i32 %28, i32 %29, i32 0)
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = icmp ne i8* %31, null
br i1 %32, label %36, label %33
33: ; preds = %17
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %17
%37 = load i8*, i8** %9
%38 = load i32, i32* %7
%39 = load i32, i32* @MADV_SEQUENTIAL
%40 = call i64 @madvise(i8* %37, i32 %38, i32 %39)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %36
store i32 0, i32* %10
br label %46
46: ; preds = %60, %45
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = udiv i64 %50, 1
%52 = icmp ult i64 %48, %51
br i1 %52, label %53, label %63
53: ; preds = %46
%54 = load i8*, i8** %9
%55 = load i32, i32* %10
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 signext %58)
br label %60
60: ; preds = %53
%61 = load i32, i32* %10
%62 = add nsw i32 %61, 1
store i32 %62, i32* %10
br label %46
63: ; preds = %46
%64 = load i8*, i8** %9
%65 = load i32, i32* %7
%66 = call i32 @munmap(i8* %64, i32 %65)
%67 = load i32, i32* %8
%68 = call i32 @close(i32 %67)
%69 = load i32, i32* @EXIT_SUCCESS
%70 = call i32 @exit(i32 %69)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [18 x i8] c"/root/MAINTAINERS\00"
@.str.1 = [5 x i8] c"stat\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [4 x i8] c"%d\0A\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MADV_SEQUENTIAL = global i32 0
@.str.3 = [3 x i8] c"%c\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i64 @stat(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = trunc i64 %13 to i8
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8 signext %17)
%19 = load i32, i32* @PROT_READ
%20 = load i32, i32* @MAP_PRIVATE
%21 = call i8* @mmap(i32* null, i32 %14, i32 %19, i32 %20, i32 %16, i32 0)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %11
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %11
%27 = load i32, i32* @MADV_SEQUENTIAL
%28 = call i64 @madvise(i8* %21, i32 %14, i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %36, label %30
30: ; preds = %26
%31 = shl i64 %13, 32
%32 = icmp eq i64 %31, 0
br i1 %32, label %46, label %33
33: ; preds = %30
%34 = ashr exact i64 %31, 32
%35 = call i64 @llvm.umax.i64(i64 %34, i64 1)
br label %39
36: ; preds = %26
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %33, %39
%40 = phi i64 [ 0, %33 ], [ %44, %39 ]
%41 = getelementptr inbounds i8, i8* %21, i64 %40
%42 = load i8, i8* %41
%43 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 signext %42)
%44 = add nuw i64 %40, 1
%45 = icmp eq i64 %44, %35
br i1 %45, label %46, label %39
46: ; preds = %39, %30
%47 = call i32 @munmap(i8* %21, i32 %14)
%48 = call i32 @close(i32 %16)
%49 = load i32, i32* @EXIT_SUCCESS
%50 = call i32 @exit(i32 %49)
unreachable
}