#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 */
unsigned char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ MS_SYNC;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SEEK_SET;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ exit(int);
scalar_t__ fstat(int, struct stat *);
int lseek(int, int, int /*<<< orphan*/);
unsigned char *mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
                    int /*<<< orphan*/);
int /*<<< orphan*/ msync(unsigned char *, int, int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fdin, fdout;
  unsigned char *src, *dst;
  struct stat statbuf;
  int i, j, size, offset, pos;
  if (argc != 4) {
    printf("usage: %s <fromfile> <tofile> <offset>\n", argv[0]);
    exit(1);
  }
  if ((fdin = open(argv[1], O_RDONLY)) < 0) {
    printf("can't open %s for reading", argv[1]);
    exit(1);
  }
  if ((fdout = open(argv[2], O_RDWR | O_CREAT,
                    (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) < 0) {
    printf("can't creat %s for writing", argv[2]);
    exit(1);
  }
  if (fstat(fdin, &statbuf) < 0) {
    printf("fstat error");
    exit(1);
  }
  offset = strtoul(argv[3], NULL, 0);
  if (offset % 512) {
    printf("offset not a multiple of 512 bytes\n");
    exit(1);
  }
  size = ((statbuf.st_size + offset + 511) / 512) * 528;
  if (lseek(fdout, size - 1, SEEK_SET) == -1) {
    printf("lseek error");
    exit(1);
  }
  if (write(fdout, "", 1) != 1) {
    printf("write error");
    exit(1);
  }
  if ((src = mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, fdin, 0)) ==
      MAP_FAILED) {
    printf("mmap error for input");
    exit(1);
  }
  if ((dst = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fdout, 0)) ==
      MAP_FAILED) {
    printf("mmap error for output");
    exit(1);
  }
  for (i = 0, pos = (offset * 528 / 512); i < statbuf.st_size; i++, pos++) {
    if ((i % 512) == 0 && i)
      for (j = 0; j < 16; j++) {
        *(dst + pos) = 0xFF;
        pos++;
      }
    *(dst + pos) = *(src + i);
  }
  msync(dst, size, MS_SYNC);
  printf("finish\n");
  exit(0);
}


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   $0x4,-0x8(%rbp)
je     11cf <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1213 <main+0x83>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
mov    0x2dcd(%rip),%rax
or     (%rax),%esi
mov    0x2d54(%rip),%rax
mov    (%rax),%edx
mov    0x2d83(%rip),%rax
or     (%rax),%edx
mov    0x2d62(%rip),%rax
or     (%rax),%edx
mov    0x2d51(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1284 <main+0xf4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   10b0 <fstat@plt>
cmp    $0x0,%rax
jge    12b2 <main+0x122>
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <strtoul@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    $0x200,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12f4 <main+0x164>
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x30(%rbp),%eax
add    -0x40(%rbp),%eax
add    $0x1ff,%eax
mov    $0x200,%ecx
cltd
idiv   %ecx
imul   $0x210,%eax,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x3c(%rbp),%esi
sub    $0x1,%esi
mov    0x2c90(%rip),%rax
mov    (%rax),%edx
call   1070 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1348 <main+0x1b8>
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    0xcd5(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     137d <main+0x1ed>
lea    0xd2d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x30(%rbp),%esi
mov    0x2c69(%rip),%rax
mov    (%rax),%edx
mov    0x2c50(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1050 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    0x2bd4(%rip),%rcx
cmp    (%rcx),%rax
jne    13cd <main+0x23d>
lea    0xce9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x3c(%rbp),%esi
mov    0x2c19(%rip),%rax
mov    (%rax),%edx
mov    0x2bb0(%rip),%rax
or     (%rax),%edx
mov    0x2bf7(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1050 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    0x2b7b(%rip),%rcx
cmp    (%rcx),%rax
jne    1426 <main+0x296>
lea    0xca5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x34(%rbp)
imul   $0x210,-0x40(%rbp),%eax
mov    $0x200,%ecx
cltd
idiv   %ecx
mov    %eax,-0x44(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    14cf <main+0x33f>
mov    -0x34(%rbp),%eax
mov    $0x200,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    14a2 <main+0x312>
cmpl   $0x0,-0x34(%rbp)
je     14a2 <main+0x312>
movl   $0x0,-0x38(%rbp)
cmpl   $0x10,-0x38(%rbp)
jge    149d <main+0x30d>
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1470 <main+0x2e0>
jmp    14a2 <main+0x312>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    143f <main+0x2af>
mov    -0x28(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    0x2abb(%rip),%rax
mov    (%rax),%edx
call   1040 <msync@plt>
lea    0xbe5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    11d8 <main+0x38>
mov    0x8(%rbx),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1090 <open@plt>
test   %eax,%eax
jns    11f3 <main+0x53>
mov    0x8(%rbx),%rsi
lea    0xe52(%rip),%rdi
jmp    11e2 <main+0x42>
mov    (%rbx),%rsi
lea    0xe1e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %eax,%ebp
mov    0x2dd4(%rip),%rax
mov    0x2df5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d7a(%rip),%rax
mov    0x2dab(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d88(%rip),%rax
or     (%rax),%edx
mov    0x10(%rbx),%rdi
mov    0x2d73(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   1090 <open@plt>
test   %eax,%eax
jns    1247 <main+0xa7>
mov    0x10(%rbx),%rsi
lea    0xdfd(%rip),%rdi
jmp    11e2 <main+0x42>
mov    %eax,%r15d
mov    %rsp,%rsi
mov    %ebp,%edi
call   10c0 <fstat@plt>
test   %rax,%rax
jns    1271 <main+0xd1>
lea    0xdfd(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x18(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10a0 <strtoul@plt>
test   $0x1ff,%eax
jne    12d1 <main+0x131>
mov    %eax,%r12d
mov    (%rsp),%r13d
lea    (%r12,%r13,1),%eax
add    $0x1ff,%eax
lea    (%r12,%r13,1),%ecx
add    $0x3fe,%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x9,%ecx
imul   $0x210,%ecx,%r14d
lea    -0x1(%r14),%esi
mov    0x2cf7(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
call   1080 <lseek@plt>
cmp    $0xffffffff,%eax
jne    12e7 <main+0x147>
lea    0xd9a(%rip),%rdi
jmp    1260 <main+0xc0>
lea    0xddb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd39(%rip),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
jne    133a <main+0x19a>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edx
mov    0x2cd0(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r13d,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    0x2c57(%rip),%rbx
cmp    (%rbx),%rax
jne    1346 <main+0x1a6>
lea    0xd4c(%rip),%rdi
jmp    1260 <main+0xc0>
lea    0xd34(%rip),%rdi
jmp    1260 <main+0xc0>
mov    %rax,%rbp
mov    0x2c40(%rip),%rax
mov    (%rax),%edx
mov    0x2c97(%rip),%rax
or     (%rax),%edx
mov    0x2c7e(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
cmp    (%rbx),%rax
jne    1385 <main+0x1e5>
lea    0xd16(%rip),%rdi
jmp    1260 <main+0xc0>
test   %r13d,%r13d
jle    13e6 <main+0x246>
imul   $0x210,%r12d,%edx
lea    0x1ff(%rdx),%ecx
test   %edx,%edx
cmovns %edx,%ecx
sar    $0x9,%ecx
xor    %edx,%edx
pcmpeqd %xmm0,%xmm0
jmp    13c7 <main+0x227>
nopw   0x0(%rax,%rax,1)
movzbl 0x0(%rbp,%rdx,1),%ebx
movslq %ecx,%rcx
mov    %bl,(%rax,%rcx,1)
add    $0x1,%rdx
add    $0x1,%ecx
cmp    %rdx,%r13
je     13e6 <main+0x246>
test   %rdx,%rdx
je     13b0 <main+0x210>
mov    %edx,%esi
and    $0x1ff,%esi
test   %rsi,%rsi
jne    13b0 <main+0x210>
movslq %ecx,%rcx
movdqu %xmm0,(%rax,%rcx,1)
add    $0x10,%ecx
jmp    13b0 <main+0x210>
mov    0x2bab(%rip),%rcx
mov    (%rcx),%edx
mov    %rax,%rdi
mov    %r14d,%esi
call   1050 <msync@plt>
lea    0xcab(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [40 x i8] c"usage: %s <fromfile> <tofile> <offset>\0A\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
@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 = [36 x i8] c"offset not a multiple of 512 bytes\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [12 x i8] c"lseek error\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [12 x i8] c"write error\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.8 = [21 x i8] c"mmap error for input\00"
@PROT_WRITE = global i32 0
@.str.9 = [22 x i8] c"mmap error for output\00"
@MS_SYNC = global i32 0
@.str.10 = [8 x i8] c"finish\0A\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 %struct.stat
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 4
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_RDONLY
%29 = call i32 (i8*, i32, ...) @open(i8* %27, i32 %28)
store i32 %29, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %24
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %24
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = load i32, i32* @O_RDWR
%42 = load i32, i32* @O_CREAT
%43 = or i32 %41, %42
%44 = load i32, i32* @S_IRUSR
%45 = load i32, i32* @S_IWUSR
%46 = or i32 %44, %45
%47 = load i32, i32* @S_IRGRP
%48 = or i32 %46, %47
%49 = load i32, i32* @S_IROTH
%50 = or i32 %48, %49
%51 = call i32 (i8*, i32, ...) @open(i8* %40, i32 %43, i32 %50)
store i32 %51, i32* %7
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %37
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 2
%56 = load i8*, i8** %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %37
%60 = load i32, i32* %6
%61 = call i64 @fstat(i32 %60, %struct.stat* %10)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %59
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 3
%69 = load i8*, i8** %68
%70 = call i32 @strtoul(i8* %69, i32* null, i32 0)
store i32 %70, i32* %14
%71 = load i32, i32* %14
%72 = srem i32 %71, 512
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %66
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %66
%78 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%79 = load i32, i32* %78
%80 = load i32, i32* %14
%81 = add nsw i32 %79, %80
%82 = add nsw i32 %81, 511
%83 = sdiv i32 %82, 512
%84 = mul nsw i32 %83, 528
store i32 %84, i32* %13
%85 = load i32, i32* %7
%86 = load i32, i32* %13
%87 = sub nsw i32 %86, 1
%88 = load i32, i32* @SEEK_SET
%89 = call i32 @lseek(i32 %85, i32 %87, i32 %88)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %94
91: ; preds = %77
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %77
%95 = load i32, i32* %7
%96 = call i32 @write(i32 %95, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i32 1)
%97 = icmp ne i32 %96, 1
br i1 %97, label %98, label %101
98: ; preds = %94
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %94
%102 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%103 = load i32, i32* %102
%104 = load i32, i32* @PROT_READ
%105 = load i32, i32* @MAP_SHARED
%106 = load i32, i32* %6
%107 = call i8* @mmap(i32 0, i32 %103, i32 %104, i32 %105, i32 %106, i32 0)
store i8* %107, i8** %8
%108 = load i8*, i8** @MAP_FAILED
%109 = icmp eq i8* %107, %108
br i1 %109, label %110, label %113
110: ; preds = %101
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %101
%114 = load i32, i32* %13
%115 = load i32, i32* @PROT_READ
%116 = load i32, i32* @PROT_WRITE
%117 = or i32 %115, %116
%118 = load i32, i32* @MAP_SHARED
%119 = load i32, i32* %7
%120 = call i8* @mmap(i32 0, i32 %114, i32 %117, i32 %118, i32 %119, i32 0)
store i8* %120, i8** %9
%121 = load i8*, i8** @MAP_FAILED
%122 = icmp eq i8* %120, %121
br i1 %122, label %123, label %126
123: ; preds = %113
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%125 = call i32 @exit(i32 1)
unreachable
126: ; preds = %113
store i32 0, i32* %11
%127 = load i32, i32* %14
%128 = mul nsw i32 %127, 528
%129 = sdiv i32 %128, 512
store i32 %129, i32* %15
br label %130
130: ; preds = %167, %126
%131 = load i32, i32* %11
%132 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%133 = load i32, i32* %132
%134 = icmp slt i32 %131, %133
br i1 %134, label %135, label %172
135: ; preds = %130
%136 = load i32, i32* %11
%137 = srem i32 %136, 512
%138 = icmp eq i32 %137, 0
br i1 %138, label %139, label %157
139: ; preds = %135
%140 = load i32, i32* %11
%141 = icmp ne i32 %140, 0
br i1 %141, label %142, label %157
142: ; preds = %139
store i32 0, i32* %12
br label %143
143: ; preds = %153, %142
%144 = load i32, i32* %12
%145 = icmp slt i32 %144, 16
br i1 %145, label %146, label %156
146: ; preds = %143
%147 = load i8*, i8** %9
%148 = load i32, i32* %15
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds i8, i8* %147, i64 %149
store i8 -1, i8* %150
%151 = load i32, i32* %15
%152 = add nsw i32 %151, 1
store i32 %152, i32* %15
br label %153
153: ; preds = %146
%154 = load i32, i32* %12
%155 = add nsw i32 %154, 1
store i32 %155, i32* %12
br label %143
156: ; preds = %143
br label %157
157: ; preds = %156, %139, %135
%158 = load i8*, i8** %8
%159 = load i32, i32* %11
%160 = sext i32 %159 to i64
%161 = getelementptr inbounds i8, i8* %158, i64 %160
%162 = load i8, i8* %161
%163 = load i8*, i8** %9
%164 = load i32, i32* %15
%165 = sext i32 %164 to i64
%166 = getelementptr inbounds i8, i8* %163, i64 %165
store i8 %162, i8* %166
br label %167
167: ; preds = %157
%168 = load i32, i32* %11
%169 = add nsw i32 %168, 1
store i32 %169, i32* %11
%170 = load i32, i32* %15
%171 = add nsw i32 %170, 1
store i32 %171, i32* %15
br label %130
172: ; preds = %130
%173 = load i8*, i8** %9
%174 = load i32, i32* %13
%175 = load i32, i32* @MS_SYNC
%176 = call i32 @msync(i8* %173, i32 %174, i32 %175)
%177 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%178 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [40 x i8] c"usage: %s <fromfile> <tofile> <offset>\0A\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
@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"
@SEEK_SET = global i32 0
@.str.5 = [12 x i8] c"lseek error\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [12 x i8] c"write error\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.8 = [21 x i8] c"mmap error for input\00"
@PROT_WRITE = global i32 0
@.str.9 = [22 x i8] c"mmap error for output\00"
@MS_SYNC = global i32 0
@str = [7 x i8] c"finish\00"
@str.11 = [35 x i8] c"offset not a multiple of 512 bytes\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, 4
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %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 %20
16: ; preds = %10
%17 = load i8*, i8** %11
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %10
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDWR
%24 = load i32, i32* @O_CREAT
%25 = or i32 %24, %23
%26 = load i32, i32* @S_IRUSR
%27 = load i32, i32* @S_IWUSR
%28 = or i32 %27, %26
%29 = load i32, i32* @S_IRGRP
%30 = or i32 %28, %29
%31 = load i32, i32* @S_IROTH
%32 = or i32 %30, %31
%33 = tail call i32 (i8*, i32, ...) @open(i8* %22, i32 %25, i32 %32)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %20
%36 = load i8*, i8** %21
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %20
%40 = call i64 @fstat(i32 %14, %struct.stat* %3)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %39
%46 = getelementptr inbounds i8*, i8** %1, i64 3
%47 = load i8*, i8** %46
%48 = tail call i32 @strtoul(i8* nocapture %47, i32* null, i32 0)
%49 = and i32 %48, 511
%50 = icmp eq i32 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %45
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.11, i64 0, i64 0))
%53 = tail call i32 @exit(i32 1)
unreachable
54: ; preds = %45
%55 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%56 = load i32, i32* %55
%57 = add nuw i32 %48, 511
%58 = add i32 %57, %56
%59 = sdiv i32 %58, 512
%60 = mul nsw i32 %59, 528
%61 = add nsw i32 %60, -1
%62 = load i32, i32* @SEEK_SET
%63 = tail call i32 @lseek(i32 %33, i32 %61, i32 %62)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %68
65: ; preds = %54
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%67 = tail call i32 @exit(i32 1)
unreachable
68: ; preds = %54
%69 = tail call i32 @write(i32 %33, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i32 1)
%70 = icmp eq i32 %69, 1
br i1 %70, label %74, label %71
71: ; preds = %68
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%73 = tail call i32 @exit(i32 1)
unreachable
74: ; preds = %68
%75 = load i32, i32* @PROT_READ
%76 = load i32, i32* @MAP_SHARED
%77 = tail call i8* @mmap(i32 0, i32 %56, i32 %75, i32 %76, i32 %14, i32 0)
%78 = load i8*, i8** @MAP_FAILED
%79 = icmp eq i8* %77, %78
br i1 %79, label %80, label %83
80: ; preds = %74
%81 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%82 = tail call i32 @exit(i32 1)
unreachable
83: ; preds = %74
%84 = load i32, i32* @PROT_READ
%85 = load i32, i32* @PROT_WRITE
%86 = or i32 %85, %84
%87 = load i32, i32* @MAP_SHARED
%88 = tail call i8* @mmap(i32 0, i32 %60, i32 %86, i32 %87, i32 %33, i32 0)
%89 = load i8*, i8** @MAP_FAILED
%90 = icmp eq i8* %88, %89
br i1 %90, label %91, label %94
91: ; preds = %83
%92 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%93 = tail call i32 @exit(i32 1)
unreachable
94: ; preds = %83
%95 = icmp sgt i32 %56, 0
br i1 %95, label %96, label %120
96: ; preds = %94
%97 = mul nsw i32 %48, 528
%98 = sdiv i32 %97, 512
%99 = zext i32 %56 to i64
br label %100
100: ; preds = %96, %111
%101 = phi i64 [ 0, %96 ], [ %117, %111 ]
%102 = phi i32 [ %98, %96 ], [ %118, %111 ]
%103 = and i64 %101, 511
%104 = icmp eq i64 %103, 0
%105 = icmp ne i64 %101, 0
%106 = and i1 %105, %104
br i1 %106, label %107, label %111
107: ; preds = %100
%108 = sext i32 %102 to i64
%109 = getelementptr i8, i8* %88, i64 %108
%110 = add i32 %102, 16
br label %111
111: ; preds = %107, %100
%112 = phi i32 [ %102, %100 ], [ %110, %107 ]
%113 = getelementptr inbounds i8, i8* %77, i64 %101
%114 = load i8, i8* %113
%115 = sext i32 %112 to i64
%116 = getelementptr inbounds i8, i8* %88, i64 %115
store i8 %114, i8* %116
%117 = add nuw nsw i64 %101, 1
%118 = add nsw i32 %112, 1
%119 = icmp eq i64 %117, %99
br i1 %119, label %120, label %100
120: ; preds = %111, %94
%121 = load i32, i32* @MS_SYNC
%122 = tail call i32 @msync(i8* %88, i32 %60, i32 %121)
%123 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%124 = tail call i32 @exit(i32 0)
unreachable
}