#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 {
  char st_size;
};
typedef char *caddr_t;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
char *mmap(char *, char, int /*<<< orphan*/, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, char);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int stat(char *, struct stat *);
int main(int argc, char *argv[]) {
  int fd, offset;
  char *data;
  struct stat sbuf;
  char *file = "../fixture/xephon-no-compress";
  if ((fd = open(file, O_RDONLY)) == -1) {
    perror("open");
    exit(1);
  }
  if (stat(file, &sbuf) == -1) {
    perror("stat");
    exit(1);
  }
  printf("file size %ld\n", sbuf.st_size);
  data = mmap((caddr_t)0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
  if (data == (caddr_t)(-1)) {
    perror("mmap");
    exit(1);
  }
  printf("magic number:");
  for (int i = 0; i < 8; i++) {
    printf("%c", data[i]);
  }
  printf("\n");
  printf("version is %d\n", data[8]);
  printf("time compression is %d\n", data[9]);
  printf("value compression is %d\n", data[10]);
  munmap(data, sbuf.st_size);
  close(fd);
  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)
lea    0xe63(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11d5 <main+0x55>
lea    0xe58(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    1201 <main+0x81>
lea    0xe31(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movsbl -0x28(%rbp),%esi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%al
mov    0x2ddb(%rip),%rcx
mov    (%rcx),%edx
mov    0x2dc2(%rip),%rcx
mov    (%rcx),%ecx
mov    -0x14(%rbp),%r8d
xor    %esi,%esi
mov    %esi,%edi
xor    %r9d,%r9d
movsbl %al,%esi
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x20(%rbp)
jne    1266 <main+0xe6>
lea    0xde0(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x8,-0x34(%rbp)
jge    12ad <main+0x12d>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    127b <main+0xfb>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
movsbl 0x8(%rax),%esi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
movsbl 0x9(%rax),%esi
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
movsbl 0xa(%rax),%esi
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
movsbl -0x28(%rbp),%esi
call   1070 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
lea    0xe58(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     12c8 <main+0x138>
mov    %eax,%r14d
lea    0xe40(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
je     12d1 <main+0x141>
movsbl 0x8(%rsp),%ebp
lea    0xe49(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
mov    0x2df0(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     12da <main+0x14a>
mov    %rax,%rbx
lea    0xe1f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movsbl (%rbx),%edi
call   1030 <putchar@plt>
movsbl 0x1(%rbx),%edi
call   1030 <putchar@plt>
movsbl 0x2(%rbx),%edi
call   1030 <putchar@plt>
movsbl 0x3(%rbx),%edi
call   1030 <putchar@plt>
movsbl 0x4(%rbx),%edi
call   1030 <putchar@plt>
movsbl 0x5(%rbx),%edi
call   1030 <putchar@plt>
movsbl 0x6(%rbx),%edi
call   1030 <putchar@plt>
movsbl 0x7(%rbx),%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsbl 0x8(%rbx),%esi
lea    0xdca(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movsbl 0x9(%rbx),%esi
lea    0xdc7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movsbl 0xa(%rbx),%esi
lea    0xdcd(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <munmap@plt>
mov    %r14d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd4f(%rip),%rdi
jmp    12e1 <main+0x151>
lea    0xd4b(%rip),%rdi
jmp    12e1 <main+0x151>
lea    0xd56(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i8 }
@.str = [30 x i8] c"../fixture/xephon-no-compress\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [5 x i8] c"stat\00"
@.str.3 = [15 x i8] c"file size %ld\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.4 = [5 x i8] c"mmap\00"
@.str.5 = [14 x i8] c"magic number:\00"
@.str.6 = [3 x i8] c"%c\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [15 x i8] c"version is %d\0A\00"
@.str.9 = [24 x i8] c"time compression is %d\0A\00"
@.str.10 = [25 x i8] c"value compression is %d\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 i8*
%9 = alloca %struct.stat
%10 = alloca i8*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8** %10
%12 = load i8*, i8** %10
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8*, i8** %10
%21 = call i32 @stat(i8* %20, %struct.stat* %9)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19
%27 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%32 = load i8, i8* %31
%33 = load i32, i32* @PROT_READ
%34 = load i32, i32* @MAP_SHARED
%35 = load i32, i32* %6
%36 = call i8* @mmap(i8* null, i8 signext %32, i32 %33, i32 %34, i32 %35, i32 0)
store i8* %36, i8** %8
%37 = load i8*, i8** %8
%38 = icmp eq i8* %37, inttoptr (i64 -1 to i8*)
br i1 %38, label %39, label %42
39: ; preds = %26
%40 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %26
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %11
br label %44
44: ; preds = %55, %42
%45 = load i32, i32* %11
%46 = icmp slt i32 %45, 8
br i1 %46, label %47, label %58
47: ; preds = %44
%48 = load i8*, i8** %8
%49 = load i32, i32* %11
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %47
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 1
store i32 %57, i32* %11
br label %44
58: ; preds = %44
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%60 = load i8*, i8** %8
%61 = getelementptr inbounds i8, i8* %60, i64 8
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %63)
%65 = load i8*, i8** %8
%66 = getelementptr inbounds i8, i8* %65, i64 9
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %68)
%70 = load i8*, i8** %8
%71 = getelementptr inbounds i8, i8* %70, i64 10
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i32 %73)
%75 = load i8*, i8** %8
%76 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%77 = load i8, i8* %76
%78 = call i32 @munmap(i8* %75, i8 signext %77)
%79 = load i32, i32* %6
%80 = call i32 @close(i32 %79)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i8 }
@.str = [30 x i8] c"../fixture/xephon-no-compress\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [5 x i8] c"stat\00"
@.str.3 = [15 x i8] c"file size %ld\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.4 = [5 x i8] c"mmap\00"
@.str.5 = [14 x i8] c"magic number:\00"
@.str.8 = [15 x i8] c"version is %d\0A\00"
@.str.9 = [24 x i8] c"time compression is %d\0A\00"
@.str.10 = [25 x i8] c"value compression is %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.stat
%4 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = call i32 @stat(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %11
%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 = %11
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @PROT_READ
%22 = load i32, i32* @MAP_SHARED
%23 = tail call i8* @mmap(i8* null, i8 signext %18, i32 %21, i32 %22, i32 %6, i32 0)
%24 = icmp eq i8* %23, inttoptr (i64 -1 to i8*)
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %17
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%30 = load i8, i8* %23
%31 = sext i8 %30 to i32
%32 = tail call i32 @putchar(i32 %31)
%33 = getelementptr inbounds i8, i8* %23, i64 1
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = tail call i32 @putchar(i32 %35)
%37 = getelementptr inbounds i8, i8* %23, i64 2
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = tail call i32 @putchar(i32 %39)
%41 = getelementptr inbounds i8, i8* %23, i64 3
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = tail call i32 @putchar(i32 %43)
%45 = getelementptr inbounds i8, i8* %23, i64 4
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = tail call i32 @putchar(i32 %47)
%49 = getelementptr inbounds i8, i8* %23, i64 5
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = tail call i32 @putchar(i32 %51)
%53 = getelementptr inbounds i8, i8* %23, i64 6
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = tail call i32 @putchar(i32 %55)
%57 = getelementptr inbounds i8, i8* %23, i64 7
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = tail call i32 @putchar(i32 %59)
%61 = tail call i32 @putchar(i32 10)
%62 = getelementptr inbounds i8, i8* %23, i64 8
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %64)
%66 = getelementptr inbounds i8, i8* %23, i64 9
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %68)
%70 = getelementptr inbounds i8, i8* %23, i64 10
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i32 %72)
%74 = tail call i32 @munmap(i8* %23, i8 signext %18)
%75 = tail call i32 @close(i32 %6)
ret i32 0
}