#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;
};

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int O_TRUNC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err_quit(char *);
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fstat(int, struct stat *);
scalar_t__ lseek(int, int, int /*<<< orphan*/);
char *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fdin, fdout, i;
  char *src, *dst, buf[256];
  struct stat statbuf;
  src = dst = NULL;
  if (argc != 3)
    err_quit("usage: memmap <fromfile> <tofile>");
  if ((fdin = open(argv[1], O_RDONLY)) < 0) {
    sprintf(buf, "can't open %s for reading", argv[1]);
    perror(buf);
    exit(errno);
  }
  if ((fdout = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, 0644)) < 0) {
    sprintf(buf, "can't create %s for writing", argv[2]);
    perror(buf);
    exit(errno);
  }
  if (fstat(fdin, &statbuf) < 0) {
    err_sys("Unable to stat file");
  }
  if (lseek(fdout, statbuf.st_size - 1, SEEK_SET) < 0) {
    err_sys("lseek");
  }
  if (write(fdout, "a", 1) < 0) {
    err_sys("write");
  }
  if ((src = mmap(NULL, statbuf.st_size, PROT_READ, MAP_SHARED, fdin, 0)) < 0) {
    err_sys("mmap: input");
  }
  if ((dst = mmap(NULL, statbuf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED,
                  fdout, 0)) < 0) {
    err_sys("mmap: output");
  }
  for (i = 0; i < statbuf.st_size; ++i) {
    *dst++ = *src++;
  }
  close(fdin);
  close(fdout);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11ef <main+0x3f>
lea    0xe16(%rip),%rdi
call   1080 <err_quit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1248 <main+0x98>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdf9(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x130(%rbp),%rdi
call   10a0 <perror@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
mov    0x2d98(%rip),%rax
or     (%rax),%esi
mov    0x2d87(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    12b8 <main+0x108>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xda3(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x130(%rbp),%rdi
call   10a0 <perror@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x138(%rbp),%rsi
call   10d0 <fstat@plt>
cmp    $0x0,%rax
jge    12dd <main+0x12d>
lea    0xd80(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x18(%rbp),%edi
mov    -0x138(%rbp),%esi
sub    $0x1,%esi
mov    0x2cb8(%rip),%rax
mov    (%rax),%edx
call   1060 <lseek@plt>
cmp    $0x0,%rax
jge    130d <main+0x15d>
lea    0xd64(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x18(%rbp),%edi
lea    0xd5b(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    1337 <main+0x187>
lea    0xd42(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x138(%rbp),%esi
mov    0x2ca4(%rip),%rax
mov    (%rax),%edx
mov    0x2c8b(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jae    1379 <main+0x1c9>
lea    0xd06(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x138(%rbp),%esi
mov    0x2c62(%rip),%rax
mov    (%rax),%edx
mov    0x2c11(%rip),%rax
or     (%rax),%edx
mov    0x2c40(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jae    13c4 <main+0x214>
lea    0xcc7(%rip),%rdi
call   1030 <err_sys@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x138(%rbp),%eax
jge    140a <main+0x25a>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13cb <main+0x21b>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
je     11d5 <main+0x25>
lea    0xe30(%rip),%rdi
call   1080 <err_quit@plt>
mov    0x8(%rbx),%rdi
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1090 <open@plt>
test   %eax,%eax
js     154e <main+0x39e>
mov    %eax,%r12d
mov    0x2dcd(%rip),%rax
mov    0x2df6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%rbx),%rdi
mov    0x2ddf(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
xor    %eax,%eax
call   1090 <open@plt>
test   %eax,%eax
js     155b <main+0x3ab>
mov    %eax,%r14d
lea    0x20(%rsp),%rsi
mov    %r12d,%edi
call   10d0 <fstat@plt>
test   %rax,%rax
jns    1248 <main+0x98>
lea    0xe15(%rip),%rdi
call   1030 <err_sys@plt>
mov    0x20(%rsp),%r13d
lea    -0x1(%r13),%esi
mov    0x2d50(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
mov    %rsi,0x18(%rsp)
call   1060 <lseek@plt>
test   %rax,%rax
jns    1278 <main+0xc8>
lea    0xdf9(%rip),%rdi
call   1030 <err_sys@plt>
lea    0xdf3(%rip),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    129d <main+0xed>
lea    0xddc(%rip),%rdi
call   1030 <err_sys@plt>
mov    0x2d44(%rip),%rbx
mov    (%rbx),%edx
mov    0x2d2b(%rip),%r15
mov    (%r15),%ecx
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %edi,%edi
mov    %r13d,%esi
mov    %r12d,0x14(%rsp)
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbp
mov    0x2cca(%rip),%rax
mov    (%rax),%edx
or     (%rbx),%edx
mov    (%r15),%ecx
xor    %edi,%edi
mov    %r13d,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
test   %r13d,%r13d
jle    13cf <main+0x21f>
mov    0x18(%rsp),%r8
cmp    $0x7,%r8d
jb     1323 <main+0x173>
lea    (%r8,%rbp,1),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jae    13f4 <main+0x244>
lea    (%rax,%r8,1),%rcx
add    $0x1,%rcx
cmp    %rcx,%rbp
jae    13f4 <main+0x244>
mov    %rax,%rcx
mov    %rbp,%rsi
mov    %r13d,%edx
mov    0x8(%rsp),%r8
sub    %r8d,%edx
mov    %r8d,%ebp
not    %ebp
add    %r13d,%ebp
and    $0x7,%edx
je     136d <main+0x1bd>
neg    %edx
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rsi),%eax
add    $0x1,%rsi
mov    %al,(%rcx)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rdi
cmp    %edi,%edx
jne    1350 <main+0x1a0>
sub    %edi,%r8d
mov    %r8,0x8(%rsp)
cmp    $0x7,%ebp
jb     13cf <main+0x21f>
sub    0x8(%rsp),%r13d
xor    %eax,%eax
nopl   0x0(%rax)
movzbl (%rsi,%rax,1),%edx
mov    %dl,(%rcx,%rax,1)
movzbl 0x1(%rsi,%rax,1),%edx
mov    %dl,0x1(%rcx,%rax,1)
movzbl 0x2(%rsi,%rax,1),%edx
mov    %dl,0x2(%rcx,%rax,1)
movzbl 0x3(%rsi,%rax,1),%edx
mov    %dl,0x3(%rcx,%rax,1)
movzbl 0x4(%rsi,%rax,1),%edx
mov    %dl,0x4(%rcx,%rax,1)
movzbl 0x5(%rsi,%rax,1),%edx
mov    %dl,0x5(%rcx,%rax,1)
movzbl 0x6(%rsi,%rax,1),%edx
mov    %dl,0x6(%rcx,%rax,1)
movzbl 0x7(%rsi,%rax,1),%edx
mov    %dl,0x7(%rcx,%rax,1)
add    $0x8,%rax
cmp    %eax,%r13d
jne    1380 <main+0x1d0>
mov    0x14(%rsp),%edi
call   1070 <close@plt>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movabs $0x1ffffffe0,%rbx
cmp    $0x1f,%r8d
jae    140b <main+0x25b>
xor    %edx,%edx
jmp    14f2 <main+0x342>
add    $0x1,%r8
mov    %r8,%rdx
mov    %rbx,%r10
and    %rbx,%rdx
lea    -0x20(%rdx),%rcx
mov    %rcx,%rdi
shr    $0x5,%rdi
add    $0x1,%rdi
mov    %edi,%r9d
and    $0x3,%r9d
cmp    $0x60,%rcx
jae    1438 <main+0x288>
xor    %ecx,%ecx
jmp    1499 <main+0x2e9>
and    $0xfffffffffffffffc,%rdi
xor    %ecx,%ecx
xchg   %ax,%ax
movups 0x0(%rbp,%rcx,1),%xmm0
movups 0x10(%rbp,%rcx,1),%xmm1
movups %xmm0,(%rax,%rcx,1)
movups %xmm1,0x10(%rax,%rcx,1)
movups 0x20(%rbp,%rcx,1),%xmm0
movups 0x30(%rbp,%rcx,1),%xmm1
movups %xmm0,0x20(%rax,%rcx,1)
movups %xmm1,0x30(%rax,%rcx,1)
movups 0x40(%rbp,%rcx,1),%xmm0
movups 0x50(%rbp,%rcx,1),%xmm1
movups %xmm0,0x40(%rax,%rcx,1)
movups %xmm1,0x50(%rax,%rcx,1)
movups 0x60(%rbp,%rcx,1),%xmm0
movups 0x70(%rbp,%rcx,1),%xmm1
movups %xmm0,0x60(%rax,%rcx,1)
movups %xmm1,0x70(%rax,%rcx,1)
sub    $0xffffffffffffff80,%rcx
add    $0xfffffffffffffffc,%rdi
jne    1440 <main+0x290>
test   %r9,%r9
je     14db <main+0x32b>
lea    (%rcx,%rbp,1),%rdi
add    $0x10,%rdi
add    %rax,%rcx
add    $0x10,%rcx
shl    $0x5,%r9
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movups -0x10(%rdi,%rsi,1),%xmm0
movups (%rdi,%rsi,1),%xmm1
movups %xmm0,-0x10(%rcx,%rsi,1)
movups %xmm1,(%rcx,%rsi,1)
add    $0x20,%rsi
cmp    %rsi,%r9
jne    14c0 <main+0x310>
cmp    %rdx,%r8
je     13cf <main+0x21f>
test   $0x18,%r8b
je     1538 <main+0x388>
mov    %r10,%rbx
mov    0x18(%rsp),%r8
add    $0x1,%r8
add    $0x18,%rbx
and    %r8,%rbx
mov    %rax,%rcx
add    %rbx,%rcx
mov    %rbp,%rsi
add    %rbx,%rsi
nopl   0x0(%rax)
mov    0x0(%rbp,%rdx,1),%rdi
mov    %rdi,(%rax,%rdx,1)
add    $0x8,%rdx
cmp    %rdx,%rbx
jne    1510 <main+0x360>
mov    %rbx,%rax
mov    %rbx,0x8(%rsp)
cmp    %rbx,%r8
jne    1329 <main+0x179>
jmp    13cf <main+0x21f>
add    %rdx,%rbp
add    %rdx,%rax
mov    %rax,%rcx
mov    %rbp,%rsi
mov    %rdx,0x8(%rsp)
jmp    1329 <main+0x179>
mov    0x8(%rbx),%rdx
lea    0xac9(%rip),%rsi
jmp    1566 <main+0x3b6>
mov    0x10(%rbx),%rdx
lea    0xad6(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   10a0 <perror@plt>
mov    0x2a2e(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [34 x i8] c"usage: memmap <fromfile> <tofile>\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"can't open %s for reading\00"
@errno = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [28 x i8] c"can't create %s for writing\00"
@.str.3 = [20 x i8] c"Unable to stat file\00"
@SEEK_SET = global i32 0
@.str.4 = [6 x i8] c"lseek\00"
@.str.5 = [2 x i8] c"a\00"
@.str.6 = [6 x i8] c"write\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.7 = [12 x i8] c"mmap: input\00"
@PROT_WRITE = global i32 0
@.str.8 = [13 x i8] c"mmap: 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 i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [256 x i8]
%12 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %10
store i8* null, i8** %9
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @err_quit(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = call i32 (i8*, i32, ...) @open(i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %17
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%31 = call i32 @perror(i8* %30)
%32 = load i32, i32* @errno
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %17
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = load i32, i32* @O_RDWR
%39 = load i32, i32* @O_CREAT
%40 = or i32 %38, %39
%41 = load i32, i32* @O_TRUNC
%42 = or i32 %40, %41
%43 = call i32 (i8*, i32, ...) @open(i8* %37, i32 %42, i32 420)
store i32 %43, i32* %7
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %55
45: ; preds = %34
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i32 @sprintf(i8* %46, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %49)
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%52 = call i32 @perror(i8* %51)
%53 = load i32, i32* @errno
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %34
%56 = load i32, i32* %6
%57 = call i64 @fstat(i32 %56, %struct.stat* %12)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 @err_sys(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %59, %55
%62 = load i32, i32* %7
%63 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%64 = load i32, i32* %63
%65 = sub nsw i32 %64, 1
%66 = load i32, i32* @SEEK_SET
%67 = call i64 @lseek(i32 %62, i32 %65, i32 %66)
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %61
%70 = call i32 @err_sys(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %71
71: ; preds = %69, %61
%72 = load i32, i32* %7
%73 = call i64 @write(i32 %72, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %71
%76 = call i32 @err_sys(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %77
77: ; preds = %75, %71
%78 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%79 = load i32, i32* %78
%80 = load i32, i32* @PROT_READ
%81 = load i32, i32* @MAP_SHARED
%82 = load i32, i32* %6
%83 = call i8* @mmap(i32* null, i32 %79, i32 %80, i32 %81, i32 %82, i32 0)
store i8* %83, i8** %9
%84 = icmp ult i8* %83, null
br i1 %84, label %85, label %87
85: ; preds = %77
%86 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %87
87: ; preds = %85, %77
%88 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%89 = load i32, i32* %88
%90 = load i32, i32* @PROT_READ
%91 = load i32, i32* @PROT_WRITE
%92 = or i32 %90, %91
%93 = load i32, i32* @MAP_SHARED
%94 = load i32, i32* %7
%95 = call i8* @mmap(i32* null, i32 %89, i32 %92, i32 %93, i32 %94, i32 0)
store i8* %95, i8** %10
%96 = icmp ult i8* %95, null
br i1 %96, label %97, label %99
97: ; preds = %87
%98 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
br label %99
99: ; preds = %97, %87
store i32 0, i32* %8
br label %100
100: ; preds = %111, %99
%101 = load i32, i32* %8
%102 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%103 = load i32, i32* %102
%104 = icmp slt i32 %101, %103
br i1 %104, label %105, label %114
105: ; preds = %100
%106 = load i8*, i8** %9
%107 = getelementptr inbounds i8, i8* %106, i32 1
store i8* %107, i8** %9
%108 = load i8, i8* %106
%109 = load i8*, i8** %10
%110 = getelementptr inbounds i8, i8* %109, i32 1
store i8* %110, i8** %10
store i8 %108, i8* %109
br label %111
111: ; preds = %105
%112 = load i32, i32* %8
%113 = add nsw i32 %112, 1
store i32 %113, i32* %8
br label %100
114: ; preds = %100
%115 = load i32, i32* %6
%116 = call i32 @close(i32 %115)
%117 = load i32, i32* %7
%118 = call i32 @close(i32 %117)
%119 = load i32, i32* %3
ret i32 %119
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [34 x i8] c"usage: memmap <fromfile> <tofile>\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"can't open %s for reading\00"
@errno = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [28 x i8] c"can't create %s for writing\00"
@.str.3 = [20 x i8] c"Unable to stat file\00"
@SEEK_SET = global i32 0
@.str.4 = [6 x i8] c"lseek\00"
@.str.5 = [2 x i8] c"a\00"
@.str.6 = [6 x i8] c"write\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@PROT_WRITE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @err_quit(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 (i8*, i32, ...) @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %10
%17 = load i8*, i8** %11
%18 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 @perror(i8* %5)
%20 = load i32, i32* @errno
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %10
%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 = tail call i32 (i8*, i32, ...) @open(i8* %24, i32 %29, i32 420)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %22
%33 = load i8*, i8** %23
%34 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = call i32 @perror(i8* %5)
%36 = load i32, i32* @errno
%37 = tail call i32 @exit(i32 %36)
unreachable
38: ; preds = %22
%39 = call i64 @fstat(i32 %14, %struct.stat* %4)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = tail call i32 @err_sys(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
%44 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%45 = load i32, i32* %44
%46 = add nsw i32 %45, -1
%47 = load i32, i32* @SEEK_SET
%48 = tail call i64 @lseek(i32 %30, i32 %46, i32 %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %43
%51 = tail call i32 @err_sys(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %50, %43
%53 = tail call i64 @write(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = tail call i32 @err_sys(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %57
57: ; preds = %55, %52
%58 = load i32, i32* @PROT_READ
%59 = load i32, i32* @MAP_SHARED
%60 = tail call i8* @mmap(i32* null, i32 %45, i32 %58, i32 %59, i32 %14, i32 0)
%61 = load i32, i32* @PROT_READ
%62 = load i32, i32* @PROT_WRITE
%63 = or i32 %62, %61
%64 = load i32, i32* @MAP_SHARED
%65 = tail call i8* @mmap(i32* null, i32 %45, i32 %63, i32 %64, i32 %30, i32 0)
%66 = icmp sgt i32 %45, 0
br i1 %66, label %67, label %243
67: ; preds = %57
%68 = add i32 %45, -1
%69 = zext i32 %68 to i64
%70 = add nuw nsw i64 %69, 1
%71 = icmp ult i32 %68, 7
br i1 %71, label %188, label %72
72: ; preds = %67
%73 = add i32 %45, -1
%74 = zext i32 %73 to i64
%75 = add nuw nsw i64 %74, 1
%76 = getelementptr i8, i8* %65, i64 %75
%77 = getelementptr i8, i8* %60, i64 %75
%78 = icmp ult i8* %65, %77
%79 = icmp ult i8* %60, %76
%80 = and i1 %78, %79
br i1 %80, label %188, label %81
81: ; preds = %72
%82 = icmp ult i32 %68, 31
br i1 %82, label %168, label %83
83: ; preds = %81
%84 = and i64 %70, 8589934560
%85 = add nsw i64 %84, -32
%86 = lshr exact i64 %85, 5
%87 = add nuw nsw i64 %86, 1
%88 = and i64 %87, 3
%89 = icmp ult i64 %85, 96
br i1 %89, label %141, label %90
90: ; preds = %83
%91 = and i64 %87, 1152921504606846972
br label %92
92: ; preds = %92, %90
%93 = phi i64 [ 0, %90 ], [ %138, %92 ]
%94 = phi i64 [ 0, %90 ], [ %139, %92 ]
%95 = getelementptr i8, i8* %65, i64 %93
%96 = getelementptr i8, i8* %60, i64 %93
%97 = bitcast i8* %96 to <16 x i8>*
%98 = load <16 x i8>, <16 x i8>* %97
%99 = getelementptr i8, i8* %96, i64 16
%100 = bitcast i8* %99 to <16 x i8>*
%101 = load <16 x i8>, <16 x i8>* %100
%102 = bitcast i8* %95 to <16 x i8>*
store <16 x i8> %98, <16 x i8>* %102
%103 = getelementptr i8, i8* %95, i64 16
%104 = bitcast i8* %103 to <16 x i8>*
store <16 x i8> %101, <16 x i8>* %104
%105 = or i64 %93, 32
%106 = getelementptr i8, i8* %65, i64 %105
%107 = getelementptr i8, i8* %60, i64 %105
%108 = bitcast i8* %107 to <16 x i8>*
%109 = load <16 x i8>, <16 x i8>* %108
%110 = getelementptr i8, i8* %107, i64 16
%111 = bitcast i8* %110 to <16 x i8>*
%112 = load <16 x i8>, <16 x i8>* %111
%113 = bitcast i8* %106 to <16 x i8>*
store <16 x i8> %109, <16 x i8>* %113
%114 = getelementptr i8, i8* %106, i64 16
%115 = bitcast i8* %114 to <16 x i8>*
store <16 x i8> %112, <16 x i8>* %115
%116 = or i64 %93, 64
%117 = getelementptr i8, i8* %65, i64 %116
%118 = getelementptr i8, i8* %60, i64 %116
%119 = bitcast i8* %118 to <16 x i8>*
%120 = load <16 x i8>, <16 x i8>* %119
%121 = getelementptr i8, i8* %118, i64 16
%122 = bitcast i8* %121 to <16 x i8>*
%123 = load <16 x i8>, <16 x i8>* %122
%124 = bitcast i8* %117 to <16 x i8>*
store <16 x i8> %120, <16 x i8>* %124
%125 = getelementptr i8, i8* %117, i64 16
%126 = bitcast i8* %125 to <16 x i8>*
store <16 x i8> %123, <16 x i8>* %126
%127 = or i64 %93, 96
%128 = getelementptr i8, i8* %65, i64 %127
%129 = getelementptr i8, i8* %60, i64 %127
%130 = bitcast i8* %129 to <16 x i8>*
%131 = load <16 x i8>, <16 x i8>* %130
%132 = getelementptr i8, i8* %129, i64 16
%133 = bitcast i8* %132 to <16 x i8>*
%134 = load <16 x i8>, <16 x i8>* %133
%135 = bitcast i8* %128 to <16 x i8>*
store <16 x i8> %131, <16 x i8>* %135
%136 = getelementptr i8, i8* %128, i64 16
%137 = bitcast i8* %136 to <16 x i8>*
store <16 x i8> %134, <16 x i8>* %137
%138 = add nuw i64 %93, 128
%139 = add i64 %94, 4
%140 = icmp eq i64 %139, %91
br i1 %140, label %141, label %92
141: ; preds = %92, %83
%142 = phi i64 [ 0, %83 ], [ %138, %92 ]
%143 = icmp eq i64 %88, 0
br i1 %143, label %160, label %144
144: ; preds = %141, %144
%145 = phi i64 [ %157, %144 ], [ %142, %141 ]
%146 = phi i64 [ %158, %144 ], [ 0, %141 ]
%147 = getelementptr i8, i8* %65, i64 %145
%148 = getelementptr i8, i8* %60, i64 %145
%149 = bitcast i8* %148 to <16 x i8>*
%150 = load <16 x i8>, <16 x i8>* %149
%151 = getelementptr i8, i8* %148, i64 16
%152 = bitcast i8* %151 to <16 x i8>*
%153 = load <16 x i8>, <16 x i8>* %152
%154 = bitcast i8* %147 to <16 x i8>*
store <16 x i8> %150, <16 x i8>* %154
%155 = getelementptr i8, i8* %147, i64 16
%156 = bitcast i8* %155 to <16 x i8>*
store <16 x i8> %153, <16 x i8>* %156
%157 = add nuw i64 %145, 32
%158 = add i64 %146, 1
%159 = icmp eq i64 %158, %88
br i1 %159, label %160, label %144
160: ; preds = %144, %141
%161 = icmp eq i64 %70, %84
br i1 %161, label %243, label %162
162: ; preds = %160
%163 = trunc i64 %84 to i32
%164 = getelementptr i8, i8* %60, i64 %84
%165 = getelementptr i8, i8* %65, i64 %84
%166 = and i64 %70, 24
%167 = icmp eq i64 %166, 0
br i1 %167, label %188, label %168
168: ; preds = %81, %162
%169 = phi i64 [ %84, %162 ], [ 0, %81 ]
%170 = add i32 %45, -1
%171 = zext i32 %170 to i64
%172 = add nuw nsw i64 %171, 1
%173 = and i64 %172, 8589934584
%174 = getelementptr i8, i8* %65, i64 %173
%175 = getelementptr i8, i8* %60, i64 %173
%176 = trunc i64 %173 to i32
br label %177
177: ; preds = %177, %168
%178 = phi i64 [ %169, %168 ], [ %184, %177 ]
%179 = getelementptr i8, i8* %65, i64 %178
%180 = getelementptr i8, i8* %60, i64 %178
%181 = bitcast i8* %180 to <8 x i8>*
%182 = load <8 x i8>, <8 x i8>* %181
%183 = bitcast i8* %179 to <8 x i8>*
store <8 x i8> %182, <8 x i8>* %183
%184 = add nuw i64 %178, 8
%185 = icmp eq i64 %184, %173
br i1 %185, label %186, label %177
186: ; preds = %177
%187 = icmp eq i64 %172, %173
br i1 %187, label %243, label %188
188: ; preds = %72, %67, %162, %186
%189 = phi i8* [ %65, %67 ], [ %65, %72 ], [ %165, %162 ], [ %174, %186 ]
%190 = phi i8* [ %60, %67 ], [ %60, %72 ], [ %164, %162 ], [ %175, %186 ]
%191 = phi i32 [ 0, %67 ], [ 0, %72 ], [ %163, %162 ], [ %176, %186 ]
%192 = sub i32 %45, %191
%193 = xor i32 %191, -1
%194 = add i32 %45, %193
%195 = and i32 %192, 7
%196 = icmp eq i32 %195, 0
br i1 %196, label %208, label %197
197: ; preds = %188, %197
%198 = phi i8* [ %204, %197 ], [ %189, %188 ]
%199 = phi i8* [ %202, %197 ], [ %190, %188 ]
%200 = phi i32 [ %205, %197 ], [ %191, %188 ]
%201 = phi i32 [ %206, %197 ], [ 0, %188 ]
%202 = getelementptr inbounds i8, i8* %199, i64 1
%203 = load i8, i8* %199
%204 = getelementptr inbounds i8, i8* %198, i64 1
store i8 %203, i8* %198
%205 = add nuw nsw i32 %200, 1
%206 = add i32 %201, 1
%207 = icmp eq i32 %206, %195
br i1 %207, label %208, label %197
208: ; preds = %197, %188
%209 = phi i8* [ %189, %188 ], [ %204, %197 ]
%210 = phi i8* [ %190, %188 ], [ %202, %197 ]
%211 = phi i32 [ %191, %188 ], [ %205, %197 ]
%212 = icmp ult i32 %194, 7
br i1 %212, label %243, label %213
213: ; preds = %208, %213
%214 = phi i8* [ %240, %213 ], [ %209, %208 ]
%215 = phi i8* [ %238, %213 ], [ %210, %208 ]
%216 = phi i32 [ %241, %213 ], [ %211, %208 ]
%217 = getelementptr inbounds i8, i8* %215, i64 1
%218 = load i8, i8* %215
%219 = getelementptr inbounds i8, i8* %214, i64 1
store i8 %218, i8* %214
%220 = getelementptr inbounds i8, i8* %215, i64 2
%221 = load i8, i8* %217
%222 = getelementptr inbounds i8, i8* %214, i64 2
store i8 %221, i8* %219
%223 = getelementptr inbounds i8, i8* %215, i64 3
%224 = load i8, i8* %220
%225 = getelementptr inbounds i8, i8* %214, i64 3
store i8 %224, i8* %222
%226 = getelementptr inbounds i8, i8* %215, i64 4
%227 = load i8, i8* %223
%228 = getelementptr inbounds i8, i8* %214, i64 4
store i8 %227, i8* %225
%229 = getelementptr inbounds i8, i8* %215, i64 5
%230 = load i8, i8* %226
%231 = getelementptr inbounds i8, i8* %214, i64 5
store i8 %230, i8* %228
%232 = getelementptr inbounds i8, i8* %215, i64 6
%233 = load i8, i8* %229
%234 = getelementptr inbounds i8, i8* %214, i64 6
store i8 %233, i8* %231
%235 = getelementptr inbounds i8, i8* %215, i64 7
%236 = load i8, i8* %232
%237 = getelementptr inbounds i8, i8* %214, i64 7
store i8 %236, i8* %234
%238 = getelementptr inbounds i8, i8* %215, i64 8
%239 = load i8, i8* %235
%240 = getelementptr inbounds i8, i8* %214, i64 8
store i8 %239, i8* %237
%241 = add nuw nsw i32 %216, 8
%242 = icmp eq i32 %241, %45
br i1 %242, label %243, label %213
243: ; preds = %208, %213, %160, %186, %57
%244 = tail call i32 @close(i32 %14)
%245 = tail call i32 @close(i32 %30)
ret i32 0
}