#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 char *caddr_t;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
long atol(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *mmap(char *, int, int /*<<< orphan*/, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long, char);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fd;
  long offset;
  char *data;
  struct stat sbuf;
  if (argc != 2) {
    fprintf(stderr, "usage: mmapdemo offset\n");
    exit(1);
  }
  if ((fd = open("/faststorage/home/runef/package_problem/onefile/"
                 "131226_I114_FCC2F2MACXX_L5_SZABPI037427-15_1.fq",
                 O_RDONLY)) == -1) {
    perror("open");
    exit(1);
  }
  if (stat("/faststorage/home/runef/package_problem/onefile/"
           "131226_I114_FCC2F2MACXX_L5_SZABPI037427-15_1.fq",
           &sbuf) == -1) {
    perror("stat");
    exit(1);
  }
  offset = atol(argv[1]);
  if (offset < 0 || offset > sbuf.st_size - 1) {
    fprintf(stderr, "mmapdemo: offset must be in the range 0-%ld\n",
            sbuf.st_size - 1);
    exit(1);
  }
  if ((data = mmap((caddr_t)0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0)) ==
      (caddr_t)(-1)) {
    perror("mmap");
    exit(1);
  }
  {
    int sum = 0;
    long i;
    for (i = 0; i < offset; i++) {
      sum += data[i];
    }
  }
  printf("byte at offset %ld is '%c'\n", offset, data[offset]);
  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)
cmpl   $0x2,-0x8(%rbp)
je     11c1 <main+0x41>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
lea    0xe47(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11f8 <main+0x78>
lea    0xe8f(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe19(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    1227 <main+0xa7>
lea    0xe65(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jl     1259 <main+0xd9>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jle    1280 <main+0x100>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
sub    $0x1,%edx
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x30(%rbp),%esi
mov    0x2d6e(%rip),%rax
mov    (%rax),%edx
mov    0x2d55(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    12cf <main+0x14f>
lea    0xdef(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    130f <main+0x18f>
mov    -0x28(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    12de <main+0x15e>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
lea    0xd92(%rip),%rdi
movsbl (%rax,%rcx,1),%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1226 <main+0xa6>
mov    %rsi,%rbx
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe79(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1247 <main+0xc7>
mov    %eax,%ebp
lea    0xe62(%rip),%rdi
mov    %rsp,%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     1250 <main+0xd0>
mov    0x8(%rbx),%rdi
call   1070 <atol@plt>
movslq (%rsp),%rsi
lea    -0x1(%rsi),%rdx
test   %rax,%rax
js     1259 <main+0xd9>
mov    %rax,%rbx
cmp    %rdx,%rax
jg     1259 <main+0xd9>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
mov    0x2df3(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     127a <main+0xfa>
movsbl (%rax,%rbx,1),%edx
lea    0xe9f(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe2a(%rip),%rdi
jmp    1281 <main+0x101>
lea    0xe26(%rip),%rdi
jmp    1281 <main+0x101>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe2e(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"usage: mmapdemo offset\0A\00"
@.str.1 = [96 x i8] c"/faststorage/home/runef/package_problem/onefile/131226_I114_FCC2F2MACXX_L5_SZABPI037427-15_1.fq\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [5 x i8] c"stat\00"
@.str.4 = [45 x i8] c"mmapdemo: offset must be in the range 0-%ld\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.5 = [5 x i8] c"mmap\00"
@.str.6 = [28 x i8] c"byte at offset %ld is '%c'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca %struct.stat
%10 = alloca i32
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 %20, i32* %6
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %18
%26 = call i32 @stat(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %9)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i64 @atol(i8* %34)
store i64 %35, i64* %7
%36 = load i64, i64* %7
%37 = icmp slt i64 %36, 0
br i1 %37, label %45, label %38
38: ; preds = %31
%39 = load i64, i64* %7
%40 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%41 = load i32, i32* %40
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = icmp sgt i64 %39, %43
br i1 %44, label %45, label %52
45: ; preds = %38, %31
%46 = load i32, i32* @stderr
%47 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%48 = load i32, i32* %47
%49 = sub nsw i32 %48, 1
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i32 %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %38
%53 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%54 = load i32, i32* %53
%55 = load i32, i32* @PROT_READ
%56 = load i32, i32* @MAP_SHARED
%57 = load i32, i32* %6
%58 = call i8* @mmap(i8* null, i32 %54, i32 %55, i32 %56, i32 %57, i32 0)
store i8* %58, i8** %8
%59 = icmp eq i8* %58, inttoptr (i64 -1 to i8*)
br i1 %59, label %60, label %63
60: ; preds = %52
%61 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %52
store i32 0, i32* %10
store i64 0, i64* %11
br label %64
64: ; preds = %76, %63
%65 = load i64, i64* %11
%66 = load i64, i64* %7
%67 = icmp slt i64 %65, %66
br i1 %67, label %68, label %79
68: ; preds = %64
%69 = load i8*, i8** %8
%70 = load i64, i64* %11
%71 = getelementptr inbounds i8, i8* %69, i64 %70
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = load i32, i32* %10
%75 = add nsw i32 %74, %73
store i32 %75, i32* %10
br label %76
76: ; preds = %68
%77 = load i64, i64* %11
%78 = add nsw i64 %77, 1
store i64 %78, i64* %11
br label %64
79: ; preds = %64
%80 = load i64, i64* %7
%81 = load i8*, i8** %8
%82 = load i64, i64* %7
%83 = getelementptr inbounds i8, i8* %81, i64 %82
%84 = load i8, i8* %83
%85 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i64 %80, i8 signext %84)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"usage: mmapdemo offset\0A\00"
@.str.1 = [96 x i8] c"/faststorage/home/runef/package_problem/onefile/131226_I114_FCC2F2MACXX_L5_SZABPI037427-15_1.fq\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [5 x i8] c"stat\00"
@.str.4 = [45 x i8] c"mmapdemo: offset must be in the range 0-%ld\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.5 = [5 x i8] c"mmap\00"
@.str.6 = [28 x i8] c"byte at offset %ld is '%c'\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = call i32 @stat(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %3)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %17
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = tail call i64 @atol(i8* %25)
%27 = icmp slt i64 %26, 0
%28 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%29 = load i32, i32* %28
%30 = add nsw i32 %29, -1
%31 = sext i32 %30 to i64
%32 = icmp sgt i64 %26, %31
%33 = select i1 %27, i1 true, i1 %32
br i1 %33, label %34, label %38
34: ; preds = %23
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %23
%39 = load i32, i32* @PROT_READ
%40 = load i32, i32* @MAP_SHARED
%41 = tail call i8* @mmap(i8* null, i32 %29, i32 %39, i32 %40, i32 %12, i32 0)
%42 = icmp eq i8* %41, inttoptr (i64 -1 to i8*)
br i1 %42, label %47, label %43
43: ; preds = %38
%44 = getelementptr inbounds i8, i8* %41, i64 %26
%45 = load i8, i8* %44
%46 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i64 %26, i8 signext %45)
ret i32 0
47: ; preds = %38
%48 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%49 = tail call i32 @exit(i32 1)
unreachable
}