#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 */
typedef char uint8_t;
typedef int uint16_t;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dowrite(int, char *, int, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int getu16(char *, char *);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strrchr(char *, char);
int /*<<< orphan*/ writecsum(int, char *, int, char *);
int main(int argc, char *argv[]) {
  uint16_t address;
  uint16_t len;
  char *name;
  int ifd, ofd;
  uint8_t header[17];
  uint8_t buf[65536];
  int ct = 1;
  if (argc != 5) {
    fprintf(stderr, "%s: input output address length.\n", argv[0]);
    exit(1);
  }
  address = getu16(argv[0], argv[3]);
  len = getu16(argv[0], argv[4]);
  if (address + len < address || len + 2 < len) {
    fprintf(stderr, "%s: size would wrap.\n", argv[0]);
    exit(1);
  }
  if ((name = strrchr(argv[2], '/')) == NULL)
    name = argv[2];
  else
    name++;
  if (strcmp(argv[1], argv[2]) == 0) {
    fprintf(stderr, "%s: output must differ from input.\n", argv[0]);
    exit(1);
  }
  ifd = open(argv[1], O_RDONLY);
  if (ifd == -1) {
    perror(argv[1]);
    exit(1);
  }
  if (read(ifd, buf, len) != len) {
    fprintf(stderr, "%s: unable to read %d bytes from %s.\n", argv[0], len,
            argv[1]);
  }
  ofd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0666);
  if (ofd == -1) {
    perror(argv[2]);
    exit(1);
  }
  header[0] = 19;
  header[1] = 0;
  header[2] = 0;
  dowrite(ofd, header, 3, argv[2]);
  header[0] = 3;
  while (*name && ct <= 10)
    header[ct++] = *name++;
  while (ct <= 10)
    header[ct++] = ' ';
  header[11] = len;
  header[12] = len >> 8;
  header[13] = address;
  header[14] = address >> 8;
  header[15] = 0x00;
  header[16] = 0x80;
  dowrite(ofd, header, 17, argv[2]);
  writecsum(ofd, header, 17, argv[2]);
  header[0] = (len + 2);
  header[1] = (len + 2) >> 8;
  header[2] = 0xff;
  dowrite(ofd, header, 3, argv[2]);
  dowrite(ofd, buf, len, argv[2]);
  buf[len] = 0xFF;
  writecsum(ofd, buf, len + 1, argv[2]);
  close(ofd);
  close(ifd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x10044(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     1205 <main+0x55>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   10c0 <getu16@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
call   10c0 <getu16@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1251 <main+0xa1>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
cmp    -0x18(%rbp),%eax
jge    1279 <main+0xc9>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12aa <main+0xfa>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    12b6 <main+0x106>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12fd <main+0x14d>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd4c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2ccc(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1339 <main+0x189>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x24(%rbp),%edi
lea    -0x10040(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1070 <read@plt>
cmp    -0x18(%rbp),%eax
je     137d <main+0x1cd>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
lea    0xce6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2c2c(%rip),%rax
mov    (%rax),%esi
mov    0x2c63(%rip),%rax
or     (%rax),%esi
mov    0x2c52(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    13d0 <main+0x220>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movb   $0x13,-0x40(%rbp)
movb   $0x0,-0x3f(%rbp)
movb   $0x0,-0x3e(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    $0x3,%edx
call   1060 <dowrite@plt>
movb   $0x3,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x10045(%rbp)
je     1421 <main+0x271>
cmpl   $0xa,-0x10044(%rbp)
setle  %al
mov    %al,-0x10045(%rbp)
mov    -0x10045(%rbp),%al
test   $0x1,%al
jne    1434 <main+0x284>
jmp    1461 <main+0x2b1>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
mov    -0x10044(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x10044(%rbp)
cltq
mov    %cl,-0x40(%rbp,%rax,1)
jmp    13f9 <main+0x249>
jmp    1466 <main+0x2b6>
cmpl   $0xa,-0x10044(%rbp)
jg     1490 <main+0x2e0>
mov    -0x10044(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10044(%rbp)
cltq
movb   $0x20,-0x40(%rbp,%rax,1)
jmp    1466 <main+0x2b6>
mov    -0x18(%rbp),%eax
mov    %al,-0x35(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x34(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x33(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x32(%rbp)
movb   $0x0,-0x31(%rbp)
movb   $0x80,-0x30(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    $0x11,%edx
call   1060 <dowrite@plt>
mov    -0x28(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    $0x11,%edx
call   1050 <writecsum@plt>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %al,-0x40(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
sar    $0x8,%eax
mov    %al,-0x3f(%rbp)
movb   $0xff,-0x3e(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    $0x3,%edx
call   1060 <dowrite@plt>
mov    -0x28(%rbp),%edi
lea    -0x10040(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
call   1060 <dowrite@plt>
movslq -0x18(%rbp),%rax
movb   $0xff,-0x10040(%rbp,%rax,1)
ff
mov    -0x28(%rbp),%edi
lea    -0x10040(%rbp),%rsi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
call   1050 <writecsum@plt>
mov    -0x28(%rbp),%edi
call   1040 <close@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10028,%rsp
mov    %rsi,%r12
cmp    $0x5,%edi
jne    1400 <main+0x240>
mov    (%r12),%rdi
mov    0x18(%r12),%rsi
call   10d0 <getu16@plt>
mov    %eax,0x1c(%rsp)
mov    (%r12),%rdi
mov    0x20(%r12),%rsi
call   10d0 <getu16@plt>
test   %eax,%eax
js     1416 <main+0x256>
mov    %rax,%r15
mov    0x10(%r12),%rbp
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %rbp,%rbx
mov    0x8(%r12),%rdi
mov    %rbp,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     142c <main+0x26c>
mov    0x8(%r12),%rdi
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     1451 <main+0x291>
mov    %eax,%r14d
lea    0x20(%rsp),%rsi
mov    %eax,%edi
mov    %r15,%rbp
mov    %ebp,%edx
call   1080 <read@plt>
cmp    %ebp,%eax
je     1294 <main+0xd4>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
mov    0x8(%r12),%r8
lea    0xdd2(%rip),%rsi
mov    %r15,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x2d1d(%rip),%rax
mov    0x2d56(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%r12),%rdi
mov    0x2d3e(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
xor    %eax,%eax
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     1458 <main+0x298>
mov    %eax,%ebp
lea    0x2(%r15),%r13d
movw   $0x13,(%rsp)
movb   $0x0,0x2(%rsp)
mov    0x10(%r12),%rcx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1070 <dowrite@plt>
movb   $0x3,(%rsp)
mov    (%rbx),%cl
test   %cl,%cl
je     131f <main+0x15f>
mov    $0x1,%edx
nopl   (%rax)
lea    0x1(%rdx),%rax
mov    %cl,(%rsp,%rdx,1)
movzbl (%rbx,%rdx,1),%ecx
test   %cl,%cl
je     1318 <main+0x158>
cmp    $0xa,%rdx
mov    %rax,%rdx
jb     1300 <main+0x140>
cmp    $0xa,%eax
jbe    1324 <main+0x164>
jmp    133f <main+0x17f>
mov    $0x1,%eax
mov    %eax,%ecx
lea    (%rsp,%rcx,1),%rdi
mov    $0xa,%edx
sub    %eax,%edx
add    $0x1,%rdx
mov    $0x20,%esi
call   1040 <memset@plt>
mov    %r15,%rbx
mov    %bl,0xb(%rsp)
mov    %bh,0xc(%rsp)
mov    0x1c(%rsp),%eax
mov    %al,0xd(%rsp)
mov    %ah,0xe(%rsp)
movw   $0x8000,0xf(%rsp)
mov    0x10(%r12),%rcx
mov    %rsp,%r15
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x11,%edx
call   1070 <dowrite@plt>
mov    0x10(%r12),%rcx
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x11,%edx
call   1060 <writecsum@plt>
mov    %r13d,%eax
mov    %al,(%rsp)
mov    %ah,0x1(%rsp)
movb   $0xff,0x2(%rsp)
mov    0x10(%r12),%rcx
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x3,%edx
call   1070 <dowrite@plt>
mov    0x10(%r12),%rcx
lea    0x20(%rsp),%r15
mov    %ebp,%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1070 <dowrite@plt>
movslq %ebx,%rax
movb   $0xff,0x20(%rsp,%rax,1)
add    $0x1,%ebx
mov    0x10(%r12),%rcx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <writecsum@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bc1(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xbec(%rip),%rsi
jmp    1440 <main+0x280>
mov    0x2bab(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xbf8(%rip),%rsi
jmp    1440 <main+0x280>
mov    0x2b95(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xbf8(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x8(%r12),%rdi
jmp    145d <main+0x29d>
mov    0x10(%r12),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"%s: input output address length.\0A\00"
@.str.1 = [22 x i8] c"%s: size would wrap.\0A\00"
@.str.2 = [36 x i8] c"%s: output must differ from input.\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [38 x i8] c"%s: unable to read %d bytes from %s.\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
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 i32
%10 = alloca i32
%11 = alloca [17 x i8]
%12 = alloca [65536 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %13
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 5
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
%30 = call i32 @getu16(i8* %26, i8* %29)
store i32 %30, i32* %6
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 4
%36 = load i8*, i8** %35
%37 = call i32 @getu16(i8* %33, i8* %36)
store i32 %37, i32* %7
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = add nsw i32 %38, %39
%41 = load i32, i32* %6
%42 = icmp slt i32 %40, %41
br i1 %42, label %48, label %43
43: ; preds = %23
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 2
%46 = load i32, i32* %7
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %55
48: ; preds = %43, %23
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %43
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 2
%58 = load i8*, i8** %57
%59 = call i8* @strrchr(i8* %58, i8 signext 47)
store i8* %59, i8** %8
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %65
61: ; preds = %55
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 2
%64 = load i8*, i8** %63
store i8* %64, i8** %8
br label %68
65: ; preds = %55
%66 = load i8*, i8** %8
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %8
br label %68
68: ; preds = %65, %61
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 1
%71 = load i8*, i8** %70
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 2
%74 = load i8*, i8** %73
%75 = call i64 @strcmp(i8* %71, i8* %74)
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %84
77: ; preds = %68
%78 = load i32, i32* @stderr
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 0
%81 = load i8*, i8** %80
%82 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %81)
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %68
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 1
%87 = load i8*, i8** %86
%88 = load i32, i32* @O_RDONLY
%89 = call i32 (i8*, i32, ...) @open(i8* %87, i32 %88)
store i32 %89, i32* %9
%90 = load i32, i32* %9
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %98
92: ; preds = %84
%93 = load i8**, i8*** %5
%94 = getelementptr inbounds i8*, i8** %93, i64 1
%95 = load i8*, i8** %94
%96 = call i32 @perror(i8* %95)
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %84
%99 = load i32, i32* %9
%100 = getelementptr inbounds [65536 x i8], [65536 x i8]* %12, i64 0, i64 0
%101 = load i32, i32* %7
%102 = call i32 @read(i32 %99, i8* %100, i32 %101)
%103 = load i32, i32* %7
%104 = icmp ne i32 %102, %103
br i1 %104, label %105, label %115
105: ; preds = %98
%106 = load i32, i32* @stderr
%107 = load i8**, i8*** %5
%108 = getelementptr inbounds i8*, i8** %107, i64 0
%109 = load i8*, i8** %108
%110 = load i32, i32* %7
%111 = load i8**, i8*** %5
%112 = getelementptr inbounds i8*, i8** %111, i64 1
%113 = load i8*, i8** %112
%114 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %109, i32 %110, i8* %113)
br label %115
115: ; preds = %105, %98
%116 = load i8**, i8*** %5
%117 = getelementptr inbounds i8*, i8** %116, i64 2
%118 = load i8*, i8** %117
%119 = load i32, i32* @O_WRONLY
%120 = load i32, i32* @O_CREAT
%121 = or i32 %119, %120
%122 = load i32, i32* @O_TRUNC
%123 = or i32 %121, %122
%124 = call i32 (i8*, i32, ...) @open(i8* %118, i32 %123, i32 438)
store i32 %124, i32* %10
%125 = load i32, i32* %10
%126 = icmp eq i32 %125, -1
br i1 %126, label %127, label %133
127: ; preds = %115
%128 = load i8**, i8*** %5
%129 = getelementptr inbounds i8*, i8** %128, i64 2
%130 = load i8*, i8** %129
%131 = call i32 @perror(i8* %130)
%132 = call i32 @exit(i32 1)
unreachable
133: ; preds = %115
%134 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 0
store i8 19, i8* %134
%135 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 1
store i8 0, i8* %135
%136 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 2
store i8 0, i8* %136
%137 = load i32, i32* %10
%138 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 0
%139 = load i8**, i8*** %5
%140 = getelementptr inbounds i8*, i8** %139, i64 2
%141 = load i8*, i8** %140
%142 = call i32 @dowrite(i32 %137, i8* %138, i32 3, i8* %141)
%143 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 0
store i8 3, i8* %143
br label %144
144: ; preds = %154, %133
%145 = load i8*, i8** %8
%146 = load i8, i8* %145
%147 = sext i8 %146 to i32
%148 = icmp ne i32 %147, 0
br i1 %148, label %149, label %152
149: ; preds = %144
%150 = load i32, i32* %13
%151 = icmp sle i32 %150, 10
br label %152
152: ; preds = %149, %144
%153 = phi i1 [ false, %144 ], [ %151, %149 ]
br i1 %153, label %154, label %162
154: ; preds = %152
%155 = load i8*, i8** %8
%156 = getelementptr inbounds i8, i8* %155, i32 1
store i8* %156, i8** %8
%157 = load i8, i8* %155
%158 = load i32, i32* %13
%159 = add nsw i32 %158, 1
store i32 %159, i32* %13
%160 = sext i32 %158 to i64
%161 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 %160
store i8 %157, i8* %161
br label %144
162: ; preds = %152
br label %163
163: ; preds = %166, %162
%164 = load i32, i32* %13
%165 = icmp sle i32 %164, 10
br i1 %165, label %166, label %171
166: ; preds = %163
%167 = load i32, i32* %13
%168 = add nsw i32 %167, 1
store i32 %168, i32* %13
%169 = sext i32 %167 to i64
%170 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 %169
store i8 32, i8* %170
br label %163
171: ; preds = %163
%172 = load i32, i32* %7
%173 = trunc i32 %172 to i8
%174 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 11
store i8 %173, i8* %174
%175 = load i32, i32* %7
%176 = ashr i32 %175, 8
%177 = trunc i32 %176 to i8
%178 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 12
store i8 %177, i8* %178
%179 = load i32, i32* %6
%180 = trunc i32 %179 to i8
%181 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 13
store i8 %180, i8* %181
%182 = load i32, i32* %6
%183 = ashr i32 %182, 8
%184 = trunc i32 %183 to i8
%185 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 14
store i8 %184, i8* %185
%186 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 15
store i8 0, i8* %186
%187 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 16
store i8 -128, i8* %187
%188 = load i32, i32* %10
%189 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 0
%190 = load i8**, i8*** %5
%191 = getelementptr inbounds i8*, i8** %190, i64 2
%192 = load i8*, i8** %191
%193 = call i32 @dowrite(i32 %188, i8* %189, i32 17, i8* %192)
%194 = load i32, i32* %10
%195 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 0
%196 = load i8**, i8*** %5
%197 = getelementptr inbounds i8*, i8** %196, i64 2
%198 = load i8*, i8** %197
%199 = call i32 @writecsum(i32 %194, i8* %195, i32 17, i8* %198)
%200 = load i32, i32* %7
%201 = add nsw i32 %200, 2
%202 = trunc i32 %201 to i8
%203 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 0
store i8 %202, i8* %203
%204 = load i32, i32* %7
%205 = add nsw i32 %204, 2
%206 = ashr i32 %205, 8
%207 = trunc i32 %206 to i8
%208 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 1
store i8 %207, i8* %208
%209 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 2
store i8 -1, i8* %209
%210 = load i32, i32* %10
%211 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 0
%212 = load i8**, i8*** %5
%213 = getelementptr inbounds i8*, i8** %212, i64 2
%214 = load i8*, i8** %213
%215 = call i32 @dowrite(i32 %210, i8* %211, i32 3, i8* %214)
%216 = load i32, i32* %10
%217 = getelementptr inbounds [65536 x i8], [65536 x i8]* %12, i64 0, i64 0
%218 = load i32, i32* %7
%219 = load i8**, i8*** %5
%220 = getelementptr inbounds i8*, i8** %219, i64 2
%221 = load i8*, i8** %220
%222 = call i32 @dowrite(i32 %216, i8* %217, i32 %218, i8* %221)
%223 = load i32, i32* %7
%224 = sext i32 %223 to i64
%225 = getelementptr inbounds [65536 x i8], [65536 x i8]* %12, i64 0, i64 %224
store i8 -1, i8* %225
%226 = load i32, i32* %10
%227 = getelementptr inbounds [65536 x i8], [65536 x i8]* %12, i64 0, i64 0
%228 = load i32, i32* %7
%229 = add nsw i32 %228, 1
%230 = load i8**, i8*** %5
%231 = getelementptr inbounds i8*, i8** %230, i64 2
%232 = load i8*, i8** %231
%233 = call i32 @writecsum(i32 %226, i8* %227, i32 %229, i8* %232)
%234 = load i32, i32* %10
%235 = call i32 @close(i32 %234)
%236 = load i32, i32* %9
%237 = call i32 @close(i32 %236)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"%s: input output address length.\0A\00"
@.str.1 = [22 x i8] c"%s: size would wrap.\0A\00"
@.str.2 = [36 x i8] c"%s: output must differ from input.\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [38 x i8] c"%s: unable to read %d bytes from %s.\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [17 x i8]
%4 = alloca [65536 x i8]
%5 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 5
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i8*, i8** %1
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i32 @getu16(i8* %14, i8* %16)
%18 = load i8*, i8** %1
%19 = getelementptr inbounds i8*, i8** %1, i64 4
%20 = load i8*, i8** %19
%21 = tail call i32 @getu16(i8* %18, i8* %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %35, label %23
23: ; preds = %13
%24 = add nuw nsw i32 %21, 2
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i8* @strrchr(i8* dereferenceable(1) %26, i8 signext 47)
%28 = icmp eq i8* %27, null
%29 = getelementptr inbounds i8, i8* %27, i64 1
%30 = select i1 %28, i8* %26, i8* %29
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = tail call i64 @strcmp(i8* %32, i8* %26)
%34 = icmp eq i64 %33, 0
br i1 %34, label %40, label %45
35: ; preds = %13
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %1
%38 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %23
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %1
%43 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %23
%46 = load i8*, i8** %31
%47 = load i32, i32* @O_RDONLY
%48 = tail call i32 (i8*, i32, ...) @open(i8* %46, i32 %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %54
50: ; preds = %45
%51 = load i8*, i8** %31
%52 = tail call i32 @perror(i8* %51)
%53 = tail call i32 @exit(i32 1)
unreachable
54: ; preds = %45
%55 = call i32 @read(i32 %48, i8* %6, i32 %21)
%56 = icmp eq i32 %55, %21
br i1 %56, label %62, label %57
57: ; preds = %54
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %1
%60 = load i8*, i8** %31
%61 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %59, i32 %21, i8* %60)
br label %62
62: ; preds = %57, %54
%63 = load i8*, i8** %25
%64 = load i32, i32* @O_WRONLY
%65 = load i32, i32* @O_CREAT
%66 = or i32 %65, %64
%67 = load i32, i32* @O_TRUNC
%68 = or i32 %66, %67
%69 = tail call i32 (i8*, i32, ...) @open(i8* %63, i32 %68, i32 438)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %75
71: ; preds = %62
%72 = load i8*, i8** %25
%73 = tail call i32 @perror(i8* %72)
%74 = tail call i32 @exit(i32 1)
unreachable
75: ; preds = %62
store i8 19, i8* %5
%76 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 1
store i8 0, i8* %76
%77 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 2
store i8 0, i8* %77
%78 = load i8*, i8** %25
%79 = call i32 @dowrite(i32 %69, i8* %5, i32 3, i8* %78)
store i8 3, i8* %5
%80 = load i8, i8* %30
%81 = icmp eq i8 %80, 0
br i1 %81, label %85, label %92
82: ; preds = %92
%83 = trunc i64 %97 to i32
%84 = icmp ult i32 %83, 11
br i1 %84, label %85, label %103
85: ; preds = %75, %82
%86 = phi i32 [ %83, %82 ], [ 1, %75 ]
%87 = zext i32 %86 to i64
%88 = getelementptr [17 x i8], [17 x i8]* %3, i64 0, i64 %87
%89 = sub nuw nsw i32 10, %86
%90 = zext i32 %89 to i64
%91 = add nuw nsw i64 %90, 1
br label %103
92: ; preds = %75, %92
%93 = phi i64 [ %97, %92 ], [ 1, %75 ]
%94 = phi i8 [ %99, %92 ], [ %80, %75 ]
%95 = phi i8* [ %96, %92 ], [ %30, %75 ]
%96 = getelementptr inbounds i8, i8* %95, i64 1
%97 = add nuw nsw i64 %93, 1
%98 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %93
store i8 %94, i8* %98
%99 = load i8, i8* %96
%100 = icmp ne i8 %99, 0
%101 = icmp ult i64 %93, 10
%102 = select i1 %100, i1 %101, i1 false
br i1 %102, label %92, label %82
103: ; preds = %85, %82
%104 = trunc i32 %21 to i8
%105 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 11
store i8 %104, i8* %105
%106 = lshr i32 %21, 8
%107 = trunc i32 %106 to i8
%108 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 12
store i8 %107, i8* %108
%109 = trunc i32 %17 to i8
%110 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 13
store i8 %109, i8* %110
%111 = lshr i32 %17, 8
%112 = trunc i32 %111 to i8
%113 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 14
store i8 %112, i8* %113
%114 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 15
store i8 0, i8* %114
%115 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 16
store i8 -128, i8* %115
%116 = load i8*, i8** %25
%117 = call i32 @dowrite(i32 %69, i8* %5, i32 17, i8* %116)
%118 = load i8*, i8** %25
%119 = call i32 @writecsum(i32 %69, i8* %5, i32 17, i8* %118)
%120 = trunc i32 %24 to i8
store i8 %120, i8* %5
%121 = lshr i32 %24, 8
%122 = trunc i32 %121 to i8
store i8 %122, i8* %76
store i8 -1, i8* %77
%123 = load i8*, i8** %25
%124 = call i32 @dowrite(i32 %69, i8* %5, i32 3, i8* %123)
%125 = load i8*, i8** %25
%126 = call i32 @dowrite(i32 %69, i8* %6, i32 %21, i8* %125)
%127 = sext i32 %21 to i64
%128 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 %127
store i8 -1, i8* %128
%129 = add nsw i32 %21, 1
%130 = load i8*, i8** %25
%131 = call i32 @writecsum(i32 %69, i8* %6, i32 %129, i8* %130)
%132 = call i32 @close(i32 %69)
%133 = call i32 @close(i32 %48)
ret i32 0
}