#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_WRONLY;
int /*<<< orphan*/ SEEK_END;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ exitErr(char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
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 inFd, outFd;
  ssize_t numRead;
  char buf[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, S_IRUSR | S_IWUSR);
  if (outFd == -1)
    exitErr("open");
  while ((numRead = read(inFd, buf, 1024)) > 0) {
    if (write(outFd, buf, numRead) != numRead) {
      exitErr("write");
    }
    lseek(outFd, 10000, SEEK_END);
  }
  if (numRead == -1)
    exitErr("read");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     11c1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11cd <main+0x4d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11fe <main+0x7e>
lea    0xe0e(%rip),%rdi
call   1030 <exitErr@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
mov    0x2d92(%rip),%rax
or     (%rax),%esi
mov    0x2da1(%rip),%rax
mov    (%rax),%edx
mov    0x2da8(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    124a <main+0xca>
lea    0xdc2(%rip),%rdi
call   1030 <exitErr@plt>
jmp    124f <main+0xcf>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    12b1 <main+0x131>
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <write@plt>
cmp    -0x1c(%rbp),%eax
je     1296 <main+0x116>
lea    0xd7b(%rip),%rdi
call   1030 <exitErr@plt>
mov    -0x18(%rbp),%edi
mov    0x2d40(%rip),%rax
mov    (%rax),%edx
mov    $0x2710,%esi
call   1050 <lseek@plt>
jmp    124f <main+0xcf>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12c7 <main+0x147>
lea    0xd50(%rip),%rdi
call   1030 <exitErr@plt>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbp
cmp    $0x3,%edi
jl     11ae <main+0x2e>
mov    0x8(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11b7 <main+0x37>
mov    0x0(%rbp),%rdi
call   1080 <usage@plt>
mov    0x8(%rbp),%rdi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1090 <open@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    11df <main+0x5f>
lea    0xe2d(%rip),%rdi
call   1030 <exitErr@plt>
mov    0x10(%rbp),%rdi
mov    0x2e0e(%rip),%rax
mov    0x2db7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dc4(%rip),%rax
mov    0x2dcd(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
xor    %eax,%eax
call   1090 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1221 <main+0xa1>
lea    0xdeb(%rip),%rdi
call   1030 <exitErr@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1290 <main+0x110>
mov    %rsp,%r12
mov    0x2d9f(%rip),%r13
lea    0xdc4(%rip),%r15
jmp    1276 <main+0xf6>
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%edx
mov    %ebp,%edi
mov    $0x2710,%esi
call   1050 <lseek@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1290 <main+0x110>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
cmp    %ebx,%eax
je     1250 <main+0xd0>
mov    %r15,%rdi
call   1030 <exitErr@plt>
jmp    1250 <main+0xd0>
cmp    $0xffffffff,%ebx
jne    12a1 <main+0x121>
lea    0xd76(%rip),%rdi
call   1030 <exitErr@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
call   10a0 <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
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.2 = [6 x i8] c"write\00"
@SEEK_END = global i32 0
@.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]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %18, label %12
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %12, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @usage(i8* %21)
br label %23
23: ; preds = %18, %12
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDONLY
%28 = call i32 (i8*, i32, ...) @open(i8* %26, i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = call i32 @exitErr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %23
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = load i32, i32* @O_CREAT
%38 = load i32, i32* @O_WRONLY
%39 = or i32 %37, %38
%40 = load i32, i32* @S_IRUSR
%41 = load i32, i32* @S_IWUSR
%42 = or i32 %40, %41
%43 = call i32 (i8*, i32, ...) @open(i8* %36, i32 %39, i32 %42)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %33
%47 = call i32 @exitErr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %48
48: ; preds = %46, %33
br label %49
49: ; preds = %63, %48
%50 = load i32, i32* %6
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%52 = call i32 @read(i32 %50, i8* %51, i32 1024)
store i32 %52, i32* %8
%53 = icmp sgt i32 %52, 0
br i1 %53, label %54, label %67
54: ; preds = %49
%55 = load i32, i32* %7
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%57 = load i32, i32* %8
%58 = call i32 @write(i32 %55, i8* %56, i32 %57)
%59 = load i32, i32* %8
%60 = icmp ne i32 %58, %59
br i1 %60, label %61, label %63
61: ; preds = %54
%62 = call i32 @exitErr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %63
63: ; preds = %61, %54
%64 = load i32, i32* %7
%65 = load i32, i32* @SEEK_END
%66 = call i32 @lseek(i32 %64, i32 10000, i32 %65)
br label %49
67: ; preds = %49
%68 = load i32, i32* %8
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = call i32 @exitErr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %72
72: ; preds = %70, %67
%73 = load i32, i32* @EXIT_SUCCESS
%74 = call i32 @exit(i32 %73)
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
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.2 = [6 x i8] c"write\00"
@SEEK_END = global i32 0
@.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 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6, %2
%12 = load i8*, i8** %1
%13 = tail call i32 @usage(i8* %12)
br label %14
14: ; preds = %11, %6
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 (i8*, i32, ...) @open(i8* %16, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = tail call i32 @exitErr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %14
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_CREAT
%26 = load i32, i32* @O_WRONLY
%27 = or i32 %26, %25
%28 = load i32, i32* @S_IRUSR
%29 = load i32, i32* @S_IWUSR
%30 = or i32 %29, %28
%31 = tail call i32 (i8*, i32, ...) @open(i8* %24, i32 %27, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %22
%34 = tail call i32 @exitErr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %22
%36 = call i32 @read(i32 %18, i8* %4, i32 1024)
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %49
38: ; preds = %35, %44
%39 = phi i32 [ %47, %44 ], [ %36, %35 ]
%40 = call i32 @write(i32 %31, i8* %4, i32 %39)
%41 = icmp eq i32 %40, %39
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = tail call i32 @exitErr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
%45 = load i32, i32* @SEEK_END
%46 = tail call i32 @lseek(i32 %31, i32 10000, i32 %45)
%47 = call i32 @read(i32 %18, i8* %4, i32 1024)
%48 = icmp sgt i32 %47, 0
br i1 %48, label %38, label %49
49: ; preds = %44, %35
%50 = phi i32 [ %36, %35 ], [ %47, %44 ]
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = tail call i32 @exitErr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %52, %49
%55 = load i32, i32* @EXIT_SUCCESS
%56 = tail call i32 @exit(i32 %55)
unreachable
}