#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 size_t ssize_t;
typedef int off_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ MAP_ANONYMOUS;
char *MAP_FAILED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_WRITE;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ _SC_PAGE_SIZE;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fstat(int, struct stat *);
char *mmap(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int sysconf(int /*<<< orphan*/);
size_t write(int /*<<< orphan*/, char *, size_t);
int main(int argc, char *argv[]) {
  char *addr;
  int fd;
  struct stat sb;
  off_t offset, pa_offset;
  size_t length;
  ssize_t s;
  int i;
  char a;
  if (argc < 3 || argc > 4) {
    fprintf(stderr, "%s file offset [length]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  fd = open(argv[1], O_RDONLY);
  if (fd == -1)
    do {
      perror("open");
      exit(EXIT_FAILURE);
    } while (0);
  if (fstat(fd, &sb) == -1)
    do {
      perror("fstat");
      exit(EXIT_FAILURE);
    } while (0);
  offset = atoi(argv[2]);
  pa_offset = offset & ~(sysconf(_SC_PAGE_SIZE) - 1);
  if (offset >= sb.st_size) {
    fprintf(stderr, "offset is past end of file\n");
    exit(EXIT_FAILURE);
  }
  if (argc == 4) {
    length = 1024 * 1024 * 128;
    if (offset + length > sb.st_size)
      length = sb.st_size - offset;
  } else {
    length = sb.st_size - offset;
  }
  addr = mmap(NULL, length + offset - pa_offset, PROT_WRITE, MAP_ANONYMOUS, fd,
              pa_offset);
  if (addr == MAP_FAILED)
    do {
      perror("mmap");
      exit(EXIT_FAILURE);
    } while (0);
  printf("mmap finished\n");
  for (i = 0; i < 1024 * 1024 * 128; i++) {
    addr[i] = 'c';
  }
  for (i = 0; i < 1024 * 1024 * 128; i += 1024) {
    a = addr[i];
    printf("1%c", a);
  }
  printf("read finished\n");
  sleep(1000);
  s = write(STDOUT_FILENO, addr + offset - pa_offset, length);
  if (s != length) {
    if (s == -1)
      do {
        perror("write");
        exit(EXIT_FAILURE);
      } while (0);
    fprintf(stderr, "partial write");
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     11da <main+0x2a>
cmpl   $0x4,-0x8(%rbp)
jle    1206 <main+0x56>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1248 <main+0x98>
jmp    122e <main+0x7e>
lea    0xde4(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10d0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    127c <main+0xcc>
jmp    1262 <main+0xb2>
lea    0xdb5(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
call   1090 <sysconf@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
sub    $0x1,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jl     12e1 <main+0x131>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cmpl   $0x4,-0x8(%rbp)
jne    1319 <main+0x169>
movq   $0x8000000,-0x30(%rbp)
08
movslq -0x24(%rbp),%rax
add    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmp    %rcx,%rax
jbe    1314 <main+0x164>
mov    -0x20(%rbp),%eax
sub    -0x24(%rbp),%eax
cltq
mov    %rax,-0x30(%rbp)
jmp    1325 <main+0x175>
mov    -0x20(%rbp),%eax
sub    -0x24(%rbp),%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
movslq -0x28(%rbp),%rax
sub    %rax,%rsi
mov    0x2c7a(%rip),%rax
mov    (%rax),%edx
mov    0x2c91(%rip),%rax
mov    (%rax),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x28(%rbp),%r9d
xor    %eax,%eax
mov    %eax,%edi
call   1040 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2c37(%rip),%rcx
cmp    (%rcx),%rax
jne    1391 <main+0x1e1>
jmp    1377 <main+0x1c7>
lea    0xcc2(%rip),%rdi
call   1080 <perror@plt>
mov    0x2c36(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xcad(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x8000000,-0x3c(%rbp)
jge    13cd <main+0x21d>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x63,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    13a6 <main+0x1f6>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x8000000,-0x3c(%rbp)
jge    1411 <main+0x261>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x3d(%rbp)
movsbl -0x3d(%rbp),%esi
lea    0xc5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x400,%eax
mov    %eax,-0x3c(%rbp)
jmp    13d4 <main+0x224>
lea    0xc40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x3e8,%edi
call   10c0 <sleep@plt>
mov    0x2bc0(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
movslq -0x28(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rsi
mov    -0x30(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     14b3 <main+0x303>
cmpq   $0xffffffffffffffff,-0x38(%rbp)
jne    148e <main+0x2de>
jmp    1474 <main+0x2c4>
lea    0xbf4(%rip),%rdi
call   1080 <perror@plt>
mov    0x2b39(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x2b33(%rip),%rax
mov    (%rax),%edi
lea    0xbc9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2b14(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x2aee(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %edi,%ebx
lea    -0x5(%rbx),%eax
cmp    $0xfffffffd,%eax
ja     1205 <main+0x35>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe04(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1243 <main+0x73>
mov    0x8(%rbp),%rdi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
jne    1225 <main+0x55>
lea    0xdf6(%rip),%rdi
jmp    123e <main+0x6e>
mov    %eax,%r15d
mov    %rsp,%rsi
mov    %eax,%edi
call   10f0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1251 <main+0x81>
lea    0xde0(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    0x10(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebp
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   10b0 <sysconf@plt>
movslq (%rsp),%rcx
cmp    %ebp,%ecx
jle    1297 <main+0xc7>
neg    %eax
and    %ebp,%eax
cmp    $0x4,%ebx
jne    12b0 <main+0xe0>
movslq %ebp,%r13
lea    0x8000000(%r13),%rdx
mov    $0x8000000,%r14d
cmp    %rcx,%rdx
jbe    12b8 <main+0xe8>
sub    %ebp,%ecx
movslq %ecx,%r14
jmp    12b8 <main+0xe8>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0xd7d(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1243 <main+0x73>
sub    %ebp,%ecx
movslq %ecx,%r14
movslq %ebp,%r13
movslq %eax,%r12
mov    %r13,%rsi
sub    %r12,%rsi
add    %r14,%rsi
mov    0x2ced(%rip),%rax
mov    (%rax),%edx
mov    0x2d04(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r15d,%r8d
mov    %r12d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbp
mov    0x2cb3(%rip),%rax
cmp    (%rax),%rbp
jne    12fe <main+0x12e>
lea    0xd47(%rip),%rdi
jmp    123e <main+0x6e>
neg    %r12
lea    0xd4f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x8000000,%edx
mov    %rbp,%rdi
mov    $0x63,%esi
call   1070 <memset@plt>
lea    0xd1f(%rip),%r15
mov    %r15,%rdi
mov    $0x63,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl 0x400(%rbp,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x400,%rbx
cmp    $0x7fffc00,%rbx
jb     1340 <main+0x170>
lea    0xcfc(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3e8,%edi
call   10e0 <sleep@plt>
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
add    %r13,%rbp
add    %r12,%rbp
mov    %rbp,%rsi
mov    %r14,%rdx
call   1040 <write@plt>
cmp    %r14,%rax
jne    13a5 <main+0x1d5>
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
cmp    $0xffffffffffffffff,%rax
jne    13b7 <main+0x1e7>
lea    0xc9f(%rip),%rdi
jmp    123e <main+0x6e>
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
lea    0xc82(%rip),%rsi
jmp    12a7 <main+0xd7>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"%s file offset [length]\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [6 x i8] c"fstat\00"
@_SC_PAGE_SIZE = global i32 0
@.str.3 = [28 x i8] c"offset is past end of file\0A\00"
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str.4 = [5 x i8] c"mmap\00"
@.str.5 = [15 x i8] c"mmap finished\0A\00"
@.str.6 = [4 x i8] c"1%c\00"
@.str.7 = [15 x i8] c"read finished\0A\00"
@STDOUT_FILENO = global i32 0
@.str.8 = [6 x i8] c"write\00"
@.str.9 = [14 x i8] c"partial write\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 3
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 4
br i1 %19, label %20, label %28
20: ; preds = %17, %2
%21 = load i32, i32* @stderr
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %17
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i32, i32* @O_RDONLY
%33 = call i32 @open(i8* %31, i32 %32)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %42
36: ; preds = %28
br label %37
37: ; preds = %36
%38 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; No predecessors!
br label %42
42: ; preds = %41, %28
%43 = load i32, i32* %7
%44 = call i32 @fstat(i32 %43, %struct.stat* %8)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %52
46: ; preds = %42
br label %47
47: ; preds = %46
%48 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; No predecessors!
br label %52
52: ; preds = %51, %42
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
%56 = call i32 @atoi(i8* %55)
store i32 %56, i32* %9
%57 = load i32, i32* %9
%58 = load i32, i32* @_SC_PAGE_SIZE
%59 = call i32 @sysconf(i32 %58)
%60 = sub nsw i32 %59, 1
%61 = xor i32 %60, -1
%62 = and i32 %57, %61
store i32 %62, i32* %10
%63 = load i32, i32* %9
%64 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%65 = load i32, i32* %64
%66 = icmp sge i32 %63, %65
br i1 %66, label %67, label %72
67: ; preds = %52
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %52
%73 = load i32, i32* %4
%74 = icmp eq i32 %73, 4
br i1 %74, label %75, label %91
75: ; preds = %72
store i64 134217728, i64* %11
%76 = load i32, i32* %9
%77 = sext i32 %76 to i64
%78 = load i64, i64* %11
%79 = add i64 %77, %78
%80 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%81 = load i32, i32* %80
%82 = sext i32 %81 to i64
%83 = icmp ugt i64 %79, %82
br i1 %83, label %84, label %90
84: ; preds = %75
%85 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%86 = load i32, i32* %85
%87 = load i32, i32* %9
%88 = sub nsw i32 %86, %87
%89 = sext i32 %88 to i64
store i64 %89, i64* %11
br label %90
90: ; preds = %84, %75
br label %97
91: ; preds = %72
%92 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%93 = load i32, i32* %92
%94 = load i32, i32* %9
%95 = sub nsw i32 %93, %94
%96 = sext i32 %95 to i64
store i64 %96, i64* %11
br label %97
97: ; preds = %91, %90
%98 = load i64, i64* %11
%99 = load i32, i32* %9
%100 = sext i32 %99 to i64
%101 = add i64 %98, %100
%102 = load i32, i32* %10
%103 = sext i32 %102 to i64
%104 = sub i64 %101, %103
%105 = load i32, i32* @PROT_WRITE
%106 = load i32, i32* @MAP_ANONYMOUS
%107 = load i32, i32* %7
%108 = load i32, i32* %10
%109 = call i8* @mmap(i32* null, i64 %104, i32 %105, i32 %106, i32 %107, i32 %108)
store i8* %109, i8** %6
%110 = load i8*, i8** %6
%111 = load i8*, i8** @MAP_FAILED
%112 = icmp eq i8* %110, %111
br i1 %112, label %113, label %119
113: ; preds = %97
br label %114
114: ; preds = %113
%115 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%116 = load i32, i32* @EXIT_FAILURE
%117 = call i32 @exit(i32 %116)
unreachable
118: ; No predecessors!
br label %119
119: ; preds = %118, %97
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %13
br label %121
121: ; preds = %129, %119
%122 = load i32, i32* %13
%123 = icmp slt i32 %122, 134217728
br i1 %123, label %124, label %132
124: ; preds = %121
%125 = load i8*, i8** %6
%126 = load i32, i32* %13
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i8, i8* %125, i64 %127
store i8 99, i8* %128
br label %129
129: ; preds = %124
%130 = load i32, i32* %13
%131 = add nsw i32 %130, 1
store i32 %131, i32* %13
br label %121
132: ; preds = %121
store i32 0, i32* %13
br label %133
133: ; preds = %145, %132
%134 = load i32, i32* %13
%135 = icmp slt i32 %134, 134217728
br i1 %135, label %136, label %148
136: ; preds = %133
%137 = load i8*, i8** %6
%138 = load i32, i32* %13
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds i8, i8* %137, i64 %139
%141 = load i8, i8* %140
store i8 %141, i8* %14
%142 = load i8, i8* %14
%143 = sext i8 %142 to i32
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %143)
br label %145
145: ; preds = %136
%146 = load i32, i32* %13
%147 = add nsw i32 %146, 1024
store i32 %147, i32* %13
br label %133
148: ; preds = %133
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%150 = call i32 @sleep(i32 1000)
%151 = load i32, i32* @STDOUT_FILENO
%152 = load i8*, i8** %6
%153 = load i32, i32* %9
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds i8, i8* %152, i64 %154
%156 = load i32, i32* %10
%157 = sext i32 %156 to i64
%158 = sub i64 0, %157
%159 = getelementptr inbounds i8, i8* %155, i64 %158
%160 = load i64, i64* %11
%161 = call i64 @write(i32 %151, i8* %159, i64 %160)
store i64 %161, i64* %12
%162 = load i64, i64* %12
%163 = load i64, i64* %11
%164 = icmp ne i64 %162, %163
br i1 %164, label %165, label %179
165: ; preds = %148
%166 = load i64, i64* %12
%167 = icmp eq i64 %166, -1
br i1 %167, label %168, label %174
168: ; preds = %165
br label %169
169: ; preds = %168
%170 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%171 = load i32, i32* @EXIT_FAILURE
%172 = call i32 @exit(i32 %171)
unreachable
173: ; No predecessors!
br label %174
174: ; preds = %173, %165
%175 = load i32, i32* @stderr
%176 = call i32 (i32, i8*, ...) @fprintf(i32 %175, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%177 = load i32, i32* @EXIT_FAILURE
%178 = call i32 @exit(i32 %177)
unreachable
179: ; preds = %148
%180 = load i32, i32* @EXIT_SUCCESS
%181 = call i32 @exit(i32 %180)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"%s file offset [length]\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [6 x i8] c"fstat\00"
@_SC_PAGE_SIZE = global i32 0
@.str.3 = [28 x i8] c"offset is past end of file\0A\00"
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str.4 = [5 x i8] c"mmap\00"
@.str.6 = [4 x i8] c"1%c\00"
@STDOUT_FILENO = global i32 0
@.str.8 = [6 x i8] c"write\00"
@.str.9 = [14 x i8] c"partial write\00"
@EXIT_SUCCESS = global i32 0
@str = [14 x i8] c"mmap finished\00"
@str.10 = [14 x i8] c"read finished\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = add i32 %0, -5
%6 = icmp ult i32 %5, -2
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 @open(i8* %15, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %13
%24 = call i32 @fstat(i32 %17, %struct.stat* %3)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %23
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = tail call i32 @atoi(i8* %32)
%34 = load i32, i32* @_SC_PAGE_SIZE
%35 = tail call i32 @sysconf(i32 %34)
%36 = sub i32 0, %35
%37 = and i32 %33, %36
%38 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%39 = load i32, i32* %38
%40 = icmp sgt i32 %39, %33
br i1 %40, label %46, label %41
41: ; preds = %30
%42 = load i32, i32* @stderr
%43 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = tail call i32 @exit(i32 %44)
unreachable
46: ; preds = %30
%47 = icmp eq i32 %0, 4
br i1 %47, label %48, label %56
48: ; preds = %46
%49 = sext i32 %33 to i64
%50 = add nsw i64 %49, 134217728
%51 = sext i32 %39 to i64
%52 = icmp ugt i64 %50, %51
br i1 %52, label %53, label %60
53: ; preds = %48
%54 = sub nsw i32 %39, %33
%55 = sext i32 %54 to i64
br label %60
56: ; preds = %46
%57 = sub nsw i32 %39, %33
%58 = sext i32 %57 to i64
%59 = sext i32 %33 to i64
br label %60
60: ; preds = %48, %53, %56
%61 = phi i64 [ %49, %48 ], [ %49, %53 ], [ %59, %56 ]
%62 = phi i64 [ 134217728, %48 ], [ %55, %53 ], [ %58, %56 ]
%63 = sext i32 %37 to i64
%64 = sub nsw i64 0, %63
%65 = sub nsw i64 %61, %63
%66 = add nsw i64 %65, %62
%67 = load i32, i32* @PROT_WRITE
%68 = load i32, i32* @MAP_ANONYMOUS
%69 = tail call i8* @mmap(i32* null, i64 %66, i32 %67, i32 %68, i32 %17, i32 %37)
%70 = load i8*, i8** @MAP_FAILED
%71 = icmp eq i8* %69, %70
br i1 %71, label %72, label %76
72: ; preds = %60
%73 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
%75 = tail call i32 @exit(i32 %74)
unreachable
76: ; preds = %60
%77 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%78 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 99)
br label %79
79: ; preds = %76, %79
%80 = phi i64 [ 1024, %76 ], [ %85, %79 ]
%81 = getelementptr inbounds i8, i8* %69, i64 %80
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %83)
%85 = add nuw nsw i64 %80, 1024
%86 = icmp ult i64 %80, 134216704
br i1 %86, label %79, label %87
87: ; preds = %79
%88 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.10, i64 0, i64 0))
%89 = tail call i32 @sleep(i32 1000)
%90 = load i32, i32* @STDOUT_FILENO
%91 = getelementptr inbounds i8, i8* %69, i64 %61
%92 = getelementptr inbounds i8, i8* %91, i64 %64
%93 = tail call i64 @write(i32 %90, i8* %92, i64 %62)
%94 = icmp eq i64 %93, %62
br i1 %94, label %106, label %95
95: ; preds = %87
%96 = icmp eq i64 %93, -1
br i1 %96, label %97, label %101
97: ; preds = %95
%98 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%99 = load i32, i32* @EXIT_FAILURE
%100 = tail call i32 @exit(i32 %99)
unreachable
101: ; preds = %95
%102 = load i32, i32* @stderr
%103 = tail call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%104 = load i32, i32* @EXIT_FAILURE
%105 = tail call i32 @exit(i32 %104)
unreachable
106: ; preds = %87
%107 = load i32, i32* @EXIT_SUCCESS
%108 = tail call i32 @exit(i32 %107)
unreachable
}