#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 {
  int st_size;
};
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fstat(int, struct stat *);
char *getFilePath(char *, int, char *);
int getpid();
char *mmap(int /*<<< orphan*/, int, int /*<<< orphan*/, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int fd;
  char buffer[250];
  const char *file = getFilePath(buffer, sizeof(buffer), "../100mb");
  printf("%s\n", file);
  fd = open(file, O_RDONLY);
  if (!fd) {
    perror("open");
    exit(1);
  }
  struct stat buf;
  fstat(fd, &buf);
  int len = buf.st_size;
  FILE *f = fopen("/tmp/pid", "w");
  fprintf(f, "%d", getpid());
  fclose(f);
  char *addr = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0);
  printf("%d-%d", addr[0], addr[len - 1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
mov    $0xfa,%esi
lea    0xe2b(%rip),%rdx
call   1030 <getFilePath@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x118(%rbp),%rdi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    122e <main+0x7e>
lea    0xdee(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x120(%rbp),%rsi
call   10d0 <fstat@plt>
mov    -0x120(%rbp),%eax
mov    %eax,-0x124(%rbp)
lea    0xdc2(%rip),%rdi
lea    0xdc4(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x130(%rbp)
mov    -0x130(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x140(%rbp),%rdi
mov    %eax,%edx
lea    0xd98(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x130(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x124(%rbp),%esi
mov    0x2d52(%rip),%rax
mov    (%rax),%edx
mov    0x2d21(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1060 <mmap@plt>
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rax
movsbl (%rax),%esi
mov    -0x138(%rbp),%rax
mov    -0x124(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
lea    0xe2e(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0xfa,%esi
call   1030 <getFilePath@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
test   %eax,%eax
je     1295 <main+0xd5>
mov    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10e0 <fstat@plt>
movslq 0x8(%rsp),%r14
lea    0xdef(%rip),%rdi
lea    0xdf1(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xde0(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edx
mov    0x2d72(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
movsbl (%rax),%esi
movsbl -0x1(%r14,%rax,1),%edx
lea    0xd99(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd6d(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [9 x i8] c"../100mb\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [9 x i8] c"/tmp/pid\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [3 x i8] c"%d\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.6 = [6 x i8] c"%d-%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [250 x i8]
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
store i32 0, i32* %1
%9 = getelementptr inbounds [250 x i8], [250 x i8]* %3, i64 0, i64 0
%10 = call i8* @getFilePath(i8* %9, i32 250, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %4
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* %13, i32 %14)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %0
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %0
%22 = load i32, i32* %2
%23 = call i32 @fstat(i32 %22, %struct.stat* %5)
%24 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%25 = load i32, i32* %24
store i32 %25, i32* %6
%26 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %26, i32** %7
%27 = load i32*, i32** %7
%28 = call i32 (...) @getpid()
%29 = call i32 @fprintf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = load i32*, i32** %7
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %6
%33 = load i32, i32* @PROT_READ
%34 = load i32, i32* @MAP_PRIVATE
%35 = load i32, i32* %2
%36 = call i8* @mmap(i32 0, i32 %32, i32 %33, i32 %34, i32 %35, i32 0)
store i8* %36, i8** %8
%37 = load i8*, i8** %8
%38 = getelementptr inbounds i8, i8* %37, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = load i8*, i8** %8
%42 = load i32, i32* %6
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %40, i32 %47)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [9 x i8] c"../100mb\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [9 x i8] c"/tmp/pid\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [3 x i8] c"%d\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.6 = [6 x i8] c"%d-%d\00"
define i32 @main() {
%1 = alloca [250 x i8]
%2 = alloca %struct.stat
%3 = getelementptr inbounds [250 x i8], [250 x i8]* %1, i64 0, i64 0
%4 = call i8* @getFilePath(i8* %3, i32 250, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @puts(i8* dereferenceable(1) %4)
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* %4, i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = bitcast %struct.stat* %2 to i8*
%14 = call i32 @fstat(i32 %7, %struct.stat* %2)
%15 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (...) @getpid()
%19 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %18)
%20 = call i32 @fclose(i32* %17)
%21 = load i32, i32* @PROT_READ
%22 = load i32, i32* @MAP_PRIVATE
%23 = call i8* @mmap(i32 0, i32 %16, i32 %21, i32 %22, i32 %7, i32 0)
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = add nsw i32 %16, -1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %23, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %25, i32 %30)
ret i32 0
}