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

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_CUR;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ exitErr(char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
scalar_t__ memcmp(char *, char *, int);
int open(char *, int, ...);
int read(int, char *, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usage(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int outFd, inFd;
  ssize_t numRead;
  char buf[1024];
  char zeroes[1024];
  if (argc < 3 || strcmp(argv[1], "--help") == 0) {
    usage(argv[0]);
  }
  inFd = open(argv[1], O_RDONLY);
  if (inFd == -1)
    exitErr("open");
  outFd = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR);
  if (outFd == -1)
    exitErr("open");
  while ((numRead = read(inFd, buf, 1024)) > 0) {
    if (memcmp(buf, zeroes, 1024) == 0) {
      lseek(outFd, 1024, SEEK_CUR);
    } else {
      if (write(outFd, buf, numRead) != numRead) {
        exitErr("write");
      }
    }
  }
  if (numRead == -1)
    exitErr("read");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     11d1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3e(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11dd <main+0x4d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    120e <main+0x7e>
lea    0xdfe(%rip),%rdi
call   1030 <exitErr@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
mov    0x2d7a(%rip),%rax
or     (%rax),%esi
mov    0x2dc1(%rip),%rax
or     (%rax),%esi
mov    0x2d80(%rip),%rax
mov    (%rax),%edx
mov    0x2d87(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1263 <main+0xd3>
lea    0xda9(%rip),%rdi
call   1030 <exitErr@plt>
jmp    1268 <main+0xd8>
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    12f6 <main+0x166>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    $0x400,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
jne    12c5 <main+0x135>
mov    -0x14(%rbp),%edi
mov    0x2d24(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1050 <lseek@plt>
jmp    12f1 <main+0x161>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <write@plt>
cmp    -0x1c(%rbp),%eax
je     12ec <main+0x15c>
lea    0xd25(%rip),%rdi
call   1030 <exitErr@plt>
jmp    12f1 <main+0x161>
jmp    1268 <main+0xd8>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    130c <main+0x17c>
lea    0xd0b(%rip),%rdi
call   1030 <exitErr@plt>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jl     11be <main+0x2e>
mov    0x8(%rbx),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    11c6 <main+0x36>
mov    (%rbx),%rdi
call   1090 <usage@plt>
mov    0x8(%rbx),%rdi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10a0 <open@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    11ee <main+0x5e>
lea    0xe1e(%rip),%rdi
call   1030 <exitErr@plt>
mov    0x10(%rbx),%rdi
mov    0x2dff(%rip),%rax
mov    0x2da0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2de5(%rip),%rax
or     (%rax),%esi
mov    0x2da4(%rip),%rax
mov    0x2dad(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
xor    %eax,%eax
call   10a0 <open@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    123a <main+0xaa>
lea    0xdd2(%rip),%rdi
call   1030 <exitErr@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    12cb <main+0x13b>
mov    %rsp,%rbx
lea    0x400(%rsp),%r15
mov    0x2d76(%rip),%r12
jmp    1297 <main+0x107>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%edx
mov    %r13d,%edi
mov    $0x400,%esi
call   1050 <lseek@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    12cb <main+0x13b>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x400,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
je     1270 <main+0xe0>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
cmp    %ebp,%eax
je     1281 <main+0xf1>
lea    0xd48(%rip),%rdi
call   1030 <exitErr@plt>
jmp    1281 <main+0xf1>
cmp    $0xffffffff,%ebp
jne    12dc <main+0x14c>
lea    0xd3b(%rip),%rdi
call   1030 <exitErr@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@SEEK_CUR = global i32 0
@.str.2 = [6 x i8] c"write\00"
@.str.3 = [5 x i8] c"read\00"
@EXIT_SUCCESS = 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 i32
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %19, label %13
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %13, %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @usage(i8* %22)
br label %24
24: ; preds = %19, %13
%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* %7
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = call i32 @exitErr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %24
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = load i32, i32* @O_CREAT
%39 = load i32, i32* @O_WRONLY
%40 = or i32 %38, %39
%41 = load i32, i32* @O_TRUNC
%42 = or i32 %40, %41
%43 = load i32, i32* @S_IRUSR
%44 = load i32, i32* @S_IWUSR
%45 = or i32 %43, %44
%46 = call i32 (i8*, i32, ...) @open(i8* %37, i32 %42, i32 %45)
store i32 %46, i32* %6
%47 = load i32, i32* %6
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %51
49: ; preds = %34
%50 = call i32 @exitErr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %51
51: ; preds = %49, %34
br label %52
52: ; preds = %76, %51
%53 = load i32, i32* %7
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%55 = call i32 @read(i32 %53, i8* %54, i32 1024)
store i32 %55, i32* %8
%56 = icmp sgt i32 %55, 0
br i1 %56, label %57, label %77
57: ; preds = %52
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%60 = call i64 @memcmp(i8* %58, i8* %59, i32 1024)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %57
%63 = load i32, i32* %6
%64 = load i32, i32* @SEEK_CUR
%65 = call i32 @lseek(i32 %63, i32 1024, i32 %64)
br label %76
66: ; preds = %57
%67 = load i32, i32* %6
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%69 = load i32, i32* %8
%70 = call i32 @write(i32 %67, i8* %68, i32 %69)
%71 = load i32, i32* %8
%72 = icmp ne i32 %70, %71
br i1 %72, label %73, label %75
73: ; preds = %66
%74 = call i32 @exitErr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %75
75: ; preds = %73, %66
br label %76
76: ; preds = %75, %62
br label %52
77: ; preds = %52
%78 = load i32, i32* %8
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %82
80: ; preds = %77
%81 = call i32 @exitErr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %82
82: ; preds = %80, %77
%83 = load i32, i32* @EXIT_SUCCESS
%84 = call i32 @exit(i32 %83)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@SEEK_CUR = global i32 0
@.str.2 = [6 x i8] c"write\00"
@.str.3 = [5 x i8] c"read\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 3
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8, %2
%14 = load i8*, i8** %1
%15 = tail call i32 @usage(i8* %14)
br label %16
16: ; preds = %13, %8
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 (i8*, i32, ...) @open(i8* %18, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = tail call i32 @exitErr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_CREAT
%28 = load i32, i32* @O_WRONLY
%29 = or i32 %28, %27
%30 = load i32, i32* @O_TRUNC
%31 = or i32 %29, %30
%32 = load i32, i32* @S_IRUSR
%33 = load i32, i32* @S_IWUSR
%34 = or i32 %33, %32
%35 = tail call i32 (i8*, i32, ...) @open(i8* %26, i32 %31, i32 %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %24
%38 = tail call i32 @exitErr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %24
%40 = call i32 @read(i32 %20, i8* %5, i32 1024)
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %57
42: ; preds = %39, %54
%43 = phi i32 [ %55, %54 ], [ %40, %39 ]
%44 = call i64 @memcmp(i8* %5, i8* %6, i32 1024)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i32, i32* @SEEK_CUR
%48 = call i32 @lseek(i32 %35, i32 1024, i32 %47)
br label %54
49: ; preds = %42
%50 = call i32 @write(i32 %35, i8* %5, i32 %43)
%51 = icmp eq i32 %50, %43
br i1 %51, label %54, label %52
52: ; preds = %49
%53 = call i32 @exitErr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %49, %52, %46
%55 = call i32 @read(i32 %20, i8* %5, i32 1024)
%56 = icmp sgt i32 %55, 0
br i1 %56, label %42, label %57
57: ; preds = %54, %39
%58 = phi i32 [ %40, %39 ], [ %55, %54 ]
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = call i32 @exitErr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %62
62: ; preds = %60, %57
%63 = load i32, i32* @EXIT_SUCCESS
%64 = call i32 @exit(i32 %63)
unreachable
}