#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 {
  scalar_t__ st_size;
};
typedef scalar_t__ off_t;

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int O_TRUNC;
int PROT_READ;
int PROT_WRITE;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fstat(int, struct stat *);
scalar_t__ ftruncate(int, scalar_t__);
int /*<<< orphan*/ memcpy(void *, void *, size_t);
void *mmap(int /*<<< orphan*/, size_t, int, int /*<<< orphan*/, int,
           scalar_t__);
int /*<<< orphan*/ munmap(void *, size_t);
int open(char *, int, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fdin, fdout;
  void *src, *dst;
  size_t copysz;
  struct stat sbuf;
  off_t fsz = 0;
  if (argc != 3) {
    fprintf(stderr, "usage: %s <fromfile> <tofile>", argv[0]);
    exit(1);
  }
  if ((fdin = open(argv[1], O_RDONLY)) < 0) {
    fprintf(stderr, "can't open %s for reading", argv[1]);
    exit(1);
  }
  if ((fdout = open(argv[2], O_RDWR | O_CREAT | O_TRUNC,
                    (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) < 0) {
    fprintf(stderr, "can't creat %s for writing", argv[2]);
    exit(1);
  }
  if (fstat(fdin, &sbuf) < 0) {
    fprintf(stderr, "fstat error");
    exit(1);
  }
  if (ftruncate(fdout, sbuf.st_size) < 0) {
    fprintf(stderr, "ftruncate error");
    exit(1);
  }
  while (fsz < sbuf.st_size) {
    if ((sbuf.st_size - fsz) > (1024 * 1024 * 1024))
      copysz = (1024 * 1024 * 1024);
    else
      copysz = sbuf.st_size - fsz;
    if ((src = mmap(0, copysz, PROT_READ, MAP_SHARED, fdin, fsz)) ==
        MAP_FAILED) {
      fprintf(stderr, "mmap error for input");
      exit(1);
    }
    if ((dst = mmap(0, copysz, PROT_READ | PROT_WRITE, MAP_SHARED, fdout,
                    fsz)) == MAP_FAILED) {
      fprintf(stderr, "mmap error for output");
      exit(1);
    }
    memcpy(dst, src, copysz);
    munmap(src, copysz);
    munmap(dst, copysz);
    fsz += copysz;
  }
  exit(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)
movq   $0x0,-0x40(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11d0 <main+0x50>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    121d <main+0x9d>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
mov    0x2dc3(%rip),%rax
or     (%rax),%esi
mov    0x2db2(%rip),%rax
or     (%rax),%esi
mov    0x2d41(%rip),%rax
mov    (%rax),%edx
mov    0x2d68(%rip),%rax
or     (%rax),%edx
mov    0x2d47(%rip),%rax
or     (%rax),%edx
mov    0x2d36(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    12a0 <main+0x120>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   10a0 <fstat@plt>
cmp    $0x0,%rax
jge    12d7 <main+0x157>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1040 <ftruncate@plt>
cmp    $0x0,%rax
jge    130e <main+0x18e>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1313 <main+0x193>
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jge    1447 <main+0x2c7>
mov    -0x38(%rbp),%rax
sub    -0x40(%rbp),%rax
cmp    $0x40000000,%rax
jle    1342 <main+0x1c2>
movq   $0x40000000,-0x30(%rbp)
40
jmp    134e <main+0x1ce>
mov    -0x38(%rbp),%rax
sub    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
mov    0x2c8f(%rip),%rax
mov    (%rax),%edx
mov    0x2c76(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x40(%rbp),%r9
xor    %edi,%edi
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    0x2c02(%rip),%rcx
cmp    (%rcx),%rax
jne    13a8 <main+0x228>
mov    0x2c1a(%rip),%rax
mov    (%rax),%edi
lea    0xcd8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rsi
mov    0x2c35(%rip),%rax
mov    (%rax),%edx
mov    0x2bd4(%rip),%rax
or     (%rax),%edx
mov    0x2c13(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x40(%rbp),%r9
xor    %edi,%edi
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    0x2b9f(%rip),%rcx
cmp    (%rcx),%rax
jne    140b <main+0x28b>
mov    0x2bb7(%rip),%rax
mov    (%rax),%edi
lea    0xc8a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <munmap@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <munmap@plt>
mov    -0x30(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1313 <main+0x193>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11c8 <main+0x48>
mov    0x8(%rbx),%rdi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
jns    11dd <main+0x5d>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe58(%rip),%rsi
jmp    1242 <main+0xc2>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe25(%rip),%rsi
jmp    1242 <main+0xc2>
mov    0x2de4(%rip),%rax
mov    0x2e0d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dfa(%rip),%rax
or     (%rax),%esi
mov    0x2d89(%rip),%rax
mov    0x2db2(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d8f(%rip),%rax
or     (%rax),%edx
mov    0x10(%rbx),%rdi
mov    0x2d7a(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,(%rsp)
test   %eax,%eax
jns    1253 <main+0xd3>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbx),%rdx
lea    0xdf6(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0x10(%rsp),%rsi
mov    0x4(%rsp),%edi
call   10a0 <fstat@plt>
test   %rax,%rax
jns    1278 <main+0xf8>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
jmp    129d <main+0x11d>
mov    0x10(%rsp),%rbx
mov    (%rsp),%edi
mov    %rbx,%rsi
call   1040 <ftruncate@plt>
test   %rax,%rax
jns    12ae <main+0x12e>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
test   %rbx,%rbx
jle    1380 <main+0x200>
xor    %r13d,%r13d
mov    0x2d27(%rip),%r14
mov    0x2d10(%rip),%r12
mov    0x2cb1(%rip),%r15
mov    %rbx,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
sub    %r13,%rbx
cmp    $0x40000000,%rbx
mov    $0x40000000,%eax
cmovge %rax,%rbx
mov    (%r14),%edx
mov    (%r12),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    0x4(%rsp),%r8d
mov    %r13,%r9
call   1030 <mmap@plt>
cmp    (%r15),%rax
je     1387 <main+0x207>
mov    %rax,%rbp
mov    0x2c75(%rip),%rax
mov    (%rax),%edx
or     (%r14),%edx
mov    (%r12),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    (%rsp),%r8d
mov    %r13,%r9
call   1030 <mmap@plt>
cmp    (%r15),%rax
je     139c <main+0x21c>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <munmap@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <munmap@plt>
add    %rbx,%r13
mov    0x8(%rsp),%rbx
cmp    %r13,%rbx
mov    0x2c75(%rip),%r14
mov    0x2c06(%rip),%r15
jg     12e0 <main+0x160>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2c1a(%rip),%rax
mov    (%rax),%edi
lea    0xcd8(%rip),%rsi
jmp    129d <main+0x11d>
mov    0x2c05(%rip),%rax
mov    (%rax),%edi
lea    0xcd8(%rip),%rsi
jmp    129d <main+0x11d>

LLVM IR (-O0):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [30 x i8] c"usage: %s <fromfile> <tofile>\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"can't open %s for reading\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.2 = [27 x i8] c"can't creat %s for writing\00"
@.str.3 = [12 x i8] c"fstat error\00"
@.str.4 = [16 x i8] c"ftruncate error\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [21 x i8] c"mmap error for input\00"
@PROT_WRITE = global i32 0
@.str.6 = [22 x i8] c"mmap error for output\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 i8*
%10 = alloca i64
%11 = alloca %struct.stat
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %12
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_RDONLY
%27 = call i32 (i8*, i32, ...) @open(i8* %25, i32 %26)
store i32 %27, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %22
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = load i32, i32* @O_RDWR
%41 = load i32, i32* @O_CREAT
%42 = or i32 %40, %41
%43 = load i32, i32* @O_TRUNC
%44 = or i32 %42, %43
%45 = load i32, i32* @S_IRUSR
%46 = load i32, i32* @S_IWUSR
%47 = or i32 %45, %46
%48 = load i32, i32* @S_IRGRP
%49 = or i32 %47, %48
%50 = load i32, i32* @S_IROTH
%51 = or i32 %49, %50
%52 = call i32 (i8*, i32, ...) @open(i8* %39, i32 %44, i32 %51)
store i32 %52, i32* %7
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %61
54: ; preds = %36
%55 = load i32, i32* @stderr
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 2
%58 = load i8*, i8** %57
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %58)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %36
%62 = load i32, i32* %6
%63 = call i64 @fstat(i32 %62, %struct.stat* %11)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %61
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %61
%70 = load i32, i32* %7
%71 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%72 = load i64, i64* %71
%73 = call i64 @ftruncate(i32 %70, i64 %72)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %69
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %69
br label %80
80: ; preds = %125, %79
%81 = load i64, i64* %12
%82 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%83 = load i64, i64* %82
%84 = icmp slt i64 %81, %83
br i1 %84, label %85, label %139
85: ; preds = %80
%86 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%87 = load i64, i64* %86
%88 = load i64, i64* %12
%89 = sub nsw i64 %87, %88
%90 = icmp sgt i64 %89, 1073741824
br i1 %90, label %91, label %92
91: ; preds = %85
store i64 1073741824, i64* %10
br label %97
92: ; preds = %85
%93 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%94 = load i64, i64* %93
%95 = load i64, i64* %12
%96 = sub nsw i64 %94, %95
store i64 %96, i64* %10
br label %97
97: ; preds = %92, %91
%98 = load i64, i64* %10
%99 = load i32, i32* @PROT_READ
%100 = load i32, i32* @MAP_SHARED
%101 = load i32, i32* %6
%102 = load i64, i64* %12
%103 = call i8* @mmap(i32 0, i64 %98, i32 %99, i32 %100, i32 %101, i64 %102)
store i8* %103, i8** %8
%104 = load i8*, i8** @MAP_FAILED
%105 = icmp eq i8* %103, %104
br i1 %105, label %106, label %110
106: ; preds = %97
%107 = load i32, i32* @stderr
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%109 = call i32 @exit(i32 1)
unreachable
110: ; preds = %97
%111 = load i64, i64* %10
%112 = load i32, i32* @PROT_READ
%113 = load i32, i32* @PROT_WRITE
%114 = or i32 %112, %113
%115 = load i32, i32* @MAP_SHARED
%116 = load i32, i32* %7
%117 = load i64, i64* %12
%118 = call i8* @mmap(i32 0, i64 %111, i32 %114, i32 %115, i32 %116, i64 %117)
store i8* %118, i8** %9
%119 = load i8*, i8** @MAP_FAILED
%120 = icmp eq i8* %118, %119
br i1 %120, label %121, label %125
121: ; preds = %110
%122 = load i32, i32* @stderr
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%124 = call i32 @exit(i32 1)
unreachable
125: ; preds = %110
%126 = load i8*, i8** %9
%127 = load i8*, i8** %8
%128 = load i64, i64* %10
%129 = call i32 @memcpy(i8* %126, i8* %127, i64 %128)
%130 = load i8*, i8** %8
%131 = load i64, i64* %10
%132 = call i32 @munmap(i8* %130, i64 %131)
%133 = load i8*, i8** %9
%134 = load i64, i64* %10
%135 = call i32 @munmap(i8* %133, i64 %134)
%136 = load i64, i64* %10
%137 = load i64, i64* %12
%138 = add i64 %137, %136
store i64 %138, i64* %12
br label %80
139: ; preds = %80
%140 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [30 x i8] c"usage: %s <fromfile> <tofile>\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"can't open %s for reading\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.2 = [27 x i8] c"can't creat %s for writing\00"
@.str.3 = [12 x i8] c"fstat error\00"
@.str.4 = [16 x i8] c"ftruncate error\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [21 x i8] c"mmap error for input\00"
@PROT_WRITE = global i32 0
@.str.6 = [22 x i8] c"mmap error for output\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, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 (i8*, i32, ...) @open(i8* %13, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %12
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %11
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDWR
%26 = load i32, i32* @O_CREAT
%27 = or i32 %26, %25
%28 = load i32, i32* @O_TRUNC
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IRUSR
%31 = load i32, i32* @S_IWUSR
%32 = or i32 %31, %30
%33 = load i32, i32* @S_IRGRP
%34 = or i32 %32, %33
%35 = load i32, i32* @S_IROTH
%36 = or i32 %34, %35
%37 = tail call i32 (i8*, i32, ...) @open(i8* %24, i32 %29, i32 %36)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %22
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %23
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %22
%45 = call i64 @fstat(i32 %15, %struct.stat* %3)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = tail call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%50 = tail call i32 @exit(i32 1)
unreachable
51: ; preds = %44
%52 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%53 = load i64, i64* %52
%54 = tail call i64 @ftruncate(i32 %37, i64 %53)
%55 = icmp slt i64 %54, 0
br i1 %55, label %58, label %56
56: ; preds = %51
%57 = icmp sgt i64 %53, 0
br i1 %57, label %62, label %94
58: ; preds = %51
%59 = load i32, i32* @stderr
%60 = tail call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%61 = tail call i32 @exit(i32 1)
unreachable
62: ; preds = %56, %88
%63 = phi i64 [ %92, %88 ], [ 0, %56 ]
%64 = sub nsw i64 %53, %63
%65 = icmp slt i64 %64, 1073741824
%66 = select i1 %65, i64 %64, i64 1073741824
%67 = load i32, i32* @PROT_READ
%68 = load i32, i32* @MAP_SHARED
%69 = tail call i8* @mmap(i32 0, i64 %66, i32 %67, i32 %68, i32 %15, i64 %63)
%70 = load i8*, i8** @MAP_FAILED
%71 = icmp eq i8* %69, %70
br i1 %71, label %72, label %76
72: ; preds = %62
%73 = load i32, i32* @stderr
%74 = tail call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%75 = tail call i32 @exit(i32 1)
unreachable
76: ; preds = %62
%77 = load i32, i32* @PROT_READ
%78 = load i32, i32* @PROT_WRITE
%79 = or i32 %78, %77
%80 = load i32, i32* @MAP_SHARED
%81 = tail call i8* @mmap(i32 0, i64 %66, i32 %79, i32 %80, i32 %37, i64 %63)
%82 = load i8*, i8** @MAP_FAILED
%83 = icmp eq i8* %81, %82
br i1 %83, label %84, label %88
84: ; preds = %76
%85 = load i32, i32* @stderr
%86 = tail call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%87 = tail call i32 @exit(i32 1)
unreachable
88: ; preds = %76
%89 = tail call i32 @memcpy(i8* %81, i8* %69, i64 %66)
%90 = tail call i32 @munmap(i8* %69, i64 %66)
%91 = tail call i32 @munmap(i8* %81, i64 %66)
%92 = add i64 %66, %63
%93 = icmp sgt i64 %53, %92
br i1 %93, label %62, label %94
94: ; preds = %88, %56
%95 = tail call i32 @exit(i32 0)
unreachable
}