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

/* Variables and functions */
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ closeFile(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fstat(int, struct stat *);
char *mmap(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int /*<<< orphan*/);
int openFile(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int time(int /*<<< orphan*/);
void init(char *fv, int nbyte) {
  time_t start = time(0);
  int fileDskr = openFile(fv);
  struct stat mystat;
  char *pmap;
  if (fstat(fileDskr, &mystat) < 0) {
    perror("fstat");
    closeFile(fileDskr);
    exit(1);
  }
  pmap = mmap(0, mystat.st_size, PROT_READ, MAP_SHARED, fileDskr, 0);
  if (pmap == MAP_FAILED) {
    perror("mmap");
    closeFile(fileDskr);
    exit(1);
  }
  printf("Nuskaityta %d", (int)pmap[nbyte]);
  munmap(pmap, mystat.st_size);
  closeFile(fileDskr);
  time_t end = time(0);
  printf("\nDone in %ldms\n", (end - start));
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <openFile@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10b0 <fstat@plt>
cmp    $0x0,%rax
jge    11e9 <init+0x59>
lea    0xe2e(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1070 <closeFile@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%esi
mov    0x2e05(%rip),%rax
mov    (%rax),%edx
mov    0x2dec(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2db4(%rip),%rcx
cmp    (%rcx),%rax
jne    1243 <init+0xb3>
lea    0xdda(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1070 <closeFile@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xdb5(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1080 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1070 <closeFile@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
sub    -0x10(%rbp),%esi
lea    0xd93(%rip),%rdi
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r15d
mov    %rdi,%rbx
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <openFile@plt>
mov    %eax,%r12d
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10b0 <fstat@plt>
test   %rax,%rax
js     1246 <init+0xb6>
mov    0x8(%rsp),%ebx
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
mov    0x2e0c(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebx,%esi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbp
mov    0x2dd9(%rip),%rax
cmp    (%rax),%rbp
je     124f <init+0xbf>
movslq %r15d,%rax
movsbl 0x0(%rbp,%rax,1),%esi
lea    0xe00(%rip),%rdi
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1080 <munmap@plt>
mov    %r12d,%edi
call   1070 <closeFile@plt>
xor    %edi,%edi
call   1060 <time@plt>
sub    %r14d,%eax
lea    0xde6(%rip),%rdi
mov    %eax,%esi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>
lea    0xdb3(%rip),%rdi
jmp    1256 <init+0xc6>
lea    0xdb0(%rip),%rdi
call   1090 <perror@plt>
mov    %r12d,%edi
call   1070 <closeFile@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [6 x i8] c"fstat\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.1 = [5 x i8] c"mmap\00"
@.str.2 = [14 x i8] c"Nuskaityta %d\00"
@.str.3 = [16 x i8] c"\0ADone in %ldms\0A\00"
define void @init(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = call i32 @time(i32 0)
store i32 %10, i32* %5
%11 = load i8*, i8** %3
%12 = call i32 @openFile(i8* %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = call i64 @fstat(i32 %13, %struct.stat* %7)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %6
%19 = call i32 @closeFile(i32 %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load i32, i32* @PROT_READ
%25 = load i32, i32* @MAP_SHARED
%26 = load i32, i32* %6
%27 = call i8* @mmap(i32 0, i32 %23, i32 %24, i32 %25, i32 %26, i32 0)
store i8* %27, i8** %8
%28 = load i8*, i8** %8
%29 = load i8*, i8** @MAP_FAILED
%30 = icmp eq i8* %28, %29
br i1 %30, label %31, label %36
31: ; preds = %21
%32 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32, i32* %6
%34 = call i32 @closeFile(i32 %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %21
%37 = load i8*, i8** %8
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = load i8*, i8** %8
%45 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 @munmap(i8* %44, i32 %46)
%48 = load i32, i32* %6
%49 = call i32 @closeFile(i32 %48)
%50 = call i32 @time(i32 0)
store i32 %50, i32* %9
%51 = load i32, i32* %9
%52 = load i32, i32* %5
%53 = sub nsw i32 %51, %52
%54 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %53)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [6 x i8] c"fstat\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.1 = [5 x i8] c"mmap\00"
@.str.2 = [14 x i8] c"Nuskaityta %d\00"
@.str.3 = [16 x i8] c"\0ADone in %ldms\0A\00"
define void @init(i8* %0, i32 %1) {
%3 = alloca %struct.stat
%4 = tail call i32 @time(i32 0)
%5 = tail call i32 @openFile(i8* %0)
%6 = bitcast %struct.stat* %3 to i8*
%7 = call i64 @fstat(i32 %5, %struct.stat* %3)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @closeFile(i32 %5)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = load i32, i32* @PROT_READ
%17 = load i32, i32* @MAP_SHARED
%18 = tail call i8* @mmap(i32 0, i32 %15, i32 %16, i32 %17, i32 %5, i32 0)
%19 = load i8*, i8** @MAP_FAILED
%20 = icmp eq i8* %18, %19
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @closeFile(i32 %5)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %13
%26 = sext i32 %1 to i64
%27 = getelementptr inbounds i8, i8* %18, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = tail call i32 @munmap(i8* %18, i32 %15)
%32 = tail call i32 @closeFile(i32 %5)
%33 = tail call i32 @time(i32 0)
%34 = sub nsw i32 %33, %4
%35 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %34)
ret void
}