#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 /*<<< orphan*/ st_size;
};
typedef size_t off_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ close(int);
size_t lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
char *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stat(char *, struct stat *);
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  int fd;
  char *file;
  off_t ind;
  unsigned char c, n;
  struct stat s;
  if (argc == 1) {
    puts("Usage: hread FILE");
    return EXIT_SUCCESS;
  }
  if ((fd = open(argv[1], O_RDWR)) == -1) {
    perror("open");
    return EXIT_FAILURE;
  }
  stat(argv[1], &s);
  file = mmap(NULL, s.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  ind = lseek(fd, 0, SEEK_END);
  c = file[ind];
  ind += sizeof(unsigned char);
  for (n = 0; n < c; n++) {
    puts(&file[ind]);
    ind += strlen(&file[ind]) + 1;
  }
  munmap(file, s.st_size);
  close(fd);
  return 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)
cmpl   $0x1,-0x8(%rbp)
jne    11cd <main+0x3d>
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e7 <main+0x157>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    120c <main+0x7c>
lea    0xe1c(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e7 <main+0x157>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <stat@plt>
mov    -0x30(%rbp),%esi
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
mov    0x2d88(%rip),%rax
or     (%rax),%edx
mov    0x2daf(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d77(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
movb   $0x0,-0x2a(%rbp)
movzbl -0x2a(%rbp),%eax
movzbl -0x29(%rbp),%ecx
cmp    %ecx,%eax
jge    12c7 <main+0x137>
mov    -0x20(%rbp),%rdi
add    -0x28(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x20(%rbp),%rdi
add    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x2a(%rbp),%al
add    $0x1,%al
mov    %al,-0x2a(%rbp)
jmp    1284 <main+0xf4>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1090 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    11b1 <main+0x21>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
jmp    1274 <main+0xe4>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     128c <main+0xfc>
mov    %eax,%r15d
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
call   1080 <stat@plt>
mov    (%rsp),%r14d
mov    0x2e0f(%rip),%rax
mov    0x2dc8(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2ded(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%r12
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    (%r12,%rax,1),%r13b
test   %r13b,%r13b
je     1261 <main+0xd1>
mov    %rax,%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r12,%rbx,1),%rbp
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
add    %rax,%rbx
add    $0x1,%rbx
add    $0xff,%r13b
jne    1240 <main+0xb0>
mov    %r12,%rdi
mov    %r14d,%esi
call   1090 <munmap@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd7f(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d21(%rip),%rax
jmp    127b <main+0xeb>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [18 x i8] c"Usage: hread FILE\00"
@EXIT_SUCCESS = global i32 0
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@SEEK_END = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8
%10 = alloca i8
%11 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_SUCCESS
store i32 %16, i32* %3
br label %78
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDWR
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %3
br label %78
27: ; preds = %17
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @stat(i8* %30, %struct.stat* %11)
%32 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%33 = load i32, i32* %32
%34 = load i32, i32* @PROT_READ
%35 = load i32, i32* @PROT_WRITE
%36 = or i32 %34, %35
%37 = load i32, i32* @MAP_SHARED
%38 = load i32, i32* %6
%39 = call i8* @mmap(i32* null, i32 %33, i32 %36, i32 %37, i32 %38, i32 0)
store i8* %39, i8** %7
%40 = load i32, i32* %6
%41 = load i32, i32* @SEEK_END
%42 = call i64 @lseek(i32 %40, i32 0, i32 %41)
store i64 %42, i64* %8
%43 = load i8*, i8** %7
%44 = load i64, i64* %8
%45 = getelementptr inbounds i8, i8* %43, i64 %44
%46 = load i8, i8* %45
store i8 %46, i8* %9
%47 = load i64, i64* %8
%48 = add i64 %47, 1
store i64 %48, i64* %8
store i8 0, i8* %10
br label %49
49: ; preds = %67, %27
%50 = load i8, i8* %10
%51 = zext i8 %50 to i32
%52 = load i8, i8* %9
%53 = zext i8 %52 to i32
%54 = icmp slt i32 %51, %53
br i1 %54, label %55, label %70
55: ; preds = %49
%56 = load i8*, i8** %7
%57 = load i64, i64* %8
%58 = getelementptr inbounds i8, i8* %56, i64 %57
%59 = call i32 @puts(i8* %58)
%60 = load i8*, i8** %7
%61 = load i64, i64* %8
%62 = getelementptr inbounds i8, i8* %60, i64 %61
%63 = call i64 @strlen(i8* %62)
%64 = add nsw i64 %63, 1
%65 = load i64, i64* %8
%66 = add i64 %65, %64
store i64 %66, i64* %8
br label %67
67: ; preds = %55
%68 = load i8, i8* %10
%69 = add i8 %68, 1
store i8 %69, i8* %10
br label %49
70: ; preds = %49
%71 = load i8*, i8** %7
%72 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i32 @munmap(i8* %71, i32 %73)
%75 = load i32, i32* %6
%76 = call i32 @close(i32 %75)
%77 = load i32, i32* @EXIT_SUCCESS
store i32 %77, i32* %3
br label %78
78: ; preds = %70, %24, %14
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [18 x i8] c"Usage: hread FILE\00"
@EXIT_SUCCESS = global i32 0
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@SEEK_END = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %46
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDWR
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %46
16: ; preds = %8
%17 = load i8*, i8** %9
%18 = call i32 @stat(i8* %17, %struct.stat* %3)
%19 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%20 = load i32, i32* %19
%21 = load i32, i32* @PROT_READ
%22 = load i32, i32* @PROT_WRITE
%23 = or i32 %22, %21
%24 = load i32, i32* @MAP_SHARED
%25 = tail call i8* @mmap(i32* null, i32 %20, i32 %23, i32 %24, i32 %12, i32 0)
%26 = load i32, i32* @SEEK_END
%27 = tail call i64 @lseek(i32 %12, i32 0, i32 %26)
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %43, label %31
31: ; preds = %16
%32 = add i64 %27, 1
br label %33
33: ; preds = %31, %33
%34 = phi i8 [ %41, %33 ], [ 0, %31 ]
%35 = phi i64 [ %40, %33 ], [ %32, %31 ]
%36 = getelementptr inbounds i8, i8* %25, i64 %35
%37 = tail call i32 @puts(i8* dereferenceable(1) %36)
%38 = tail call i64 @strlen(i8* dereferenceable(1) %36)
%39 = add i64 %35, 1
%40 = add i64 %39, %38
%41 = add nuw i8 %34, 1
%42 = icmp eq i8 %41, %29
br i1 %42, label %43, label %33
43: ; preds = %33, %16
%44 = tail call i32 @munmap(i8* %25, i32 %20)
%45 = tail call i32 @close(i32 %12)
br label %46
46: ; preds = %43, %14, %6
%47 = phi i32* [ @EXIT_SUCCESS, %6 ], [ @EXIT_FAILURE, %14 ], [ @EXIT_SUCCESS, %43 ]
%48 = load i32, i32* %47
ret i32 %48
}