#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 */

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int nR, nW, fdR, fdW;
  char buf[4096];
  if (argc != 3) {
    fprintf(stderr, "Error in number of parameters");
  }
  fdR = open(argv[1], O_RDONLY);
  fdW = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
  if (fdR == (-1) || fdW == (-1)) {
    fprintf(stdout, "Error Opening a File.\n");
    exit(1);
  }
  while ((nR = read(fdR, buf, 4096)) > 0) {
    nW = write(fdW, buf, nR);
    if (nR != nW)
      fprintf(stderr, "Error: Read %d, Write %d).\n", nR, nW);
  }
  if (nR < 0)
    fprintf(stderr, "Write Error.\n");
  close(fdR);
  close(fdW);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119a <main+0x3a>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
mov    0x2e2b(%rip),%rax
or     (%rax),%esi
mov    0x2e1a(%rip),%rax
or     (%rax),%esi
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
mov    0x2de8(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     1208 <main+0xa8>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1229 <main+0xc9>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    122e <main+0xce>
mov    -0x1c(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1291 <main+0x131>
mov    -0x20(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     128c <main+0x12c>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    122e <main+0xce>
cmpl   $0x0,-0x14(%rbp)
jge    12b2 <main+0x152>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
je     1190 <main+0x30>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%rbx),%rdi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1070 <open@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
mov    0x2dee(%rip),%rax
mov    0x2e3f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e2c(%rip),%rax
or     (%rax),%esi
mov    0x2deb(%rip),%rax
mov    0x2dfc(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
xor    %eax,%eax
call   1070 <open@plt>
cmp    $0xffffffff,%r14d
je     125b <main+0xfb>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     125b <main+0xfb>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    127c <main+0x11c>
mov    %rsp,%rbx
mov    0x2db3(%rip),%r13
lea    0xe21(%rip),%r12
jmp    1236 <main+0xd6>
cs nopw 0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    127c <main+0x11c>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
cmp    %eax,%ebp
je     1220 <main+0xc0>
mov    0x0(%r13),%edi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1220 <main+0xc0>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
test   %ebp,%ebp
jns    1297 <main+0x137>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %r15d,%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Error in number of parameters\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@stdout = global i32 0
@.str.1 = [23 x i8] c"Error Opening a File.\0A\00"
@.str.2 = [28 x i8] c"Error: Read %d, Write %d).\0A\00"
@.str.3 = [14 x i8] c"Write Error.\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 i32
%9 = alloca i32
%10 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %13, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = call i32 (i8*, i32, ...) @open(i8* %19, i32 %20)
store i32 %21, i32* %8
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_WRONLY
%26 = load i32, i32* @O_CREAT
%27 = or i32 %25, %26
%28 = load i32, i32* @O_TRUNC
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IRUSR
%31 = load i32, i32* @S_IWUSR
%32 = or i32 %30, %31
%33 = call i32 (i8*, i32, ...) @open(i8* %24, i32 %29, i32 %32)
store i32 %33, i32* %9
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, -1
br i1 %35, label %39, label %36
36: ; preds = %16
%37 = load i32, i32* %9
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %43
39: ; preds = %36, %16
%40 = load i32, i32* @stdout
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %36
br label %44
44: ; preds = %62, %43
%45 = load i32, i32* %8
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%47 = call i32 @read(i32 %45, i8* %46, i32 4096)
store i32 %47, i32* %6
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %63
49: ; preds = %44
%50 = load i32, i32* %9
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%52 = load i32, i32* %6
%53 = call i32 @write(i32 %50, i8* %51, i32 %52)
store i32 %53, i32* %7
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = icmp ne i32 %54, %55
br i1 %56, label %57, label %62
57: ; preds = %49
%58 = load i32, i32* @stderr
%59 = load i32, i32* %6
%60 = load i32, i32* %7
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %59, i32 %60)
br label %62
62: ; preds = %57, %49
br label %44
63: ; preds = %44
%64 = load i32, i32* %6
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %66, %63
%70 = load i32, i32* %8
%71 = call i32 @close(i32 %70)
%72 = load i32, i32* %9
%73 = call i32 @close(i32 %72)
%74 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Error in number of parameters\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@stdout = global i32 0
@.str.1 = [23 x i8] c"Error Opening a File.\0A\00"
@.str.2 = [28 x i8] c"Error: Read %d, Write %d).\0A\00"
@.str.3 = [14 x i8] c"Write Error.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %6, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 (i8*, i32, ...) @open(i8* %11, i32 %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_WRONLY
%17 = load i32, i32* @O_CREAT
%18 = or i32 %17, %16
%19 = load i32, i32* @O_TRUNC
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IRUSR
%22 = load i32, i32* @S_IWUSR
%23 = or i32 %22, %21
%24 = tail call i32 (i8*, i32, ...) @open(i8* %15, i32 %20, i32 %23)
%25 = icmp eq i32 %13, -1
%26 = icmp eq i32 %24, -1
%27 = or i1 %25, %26
br i1 %27, label %31, label %28
28: ; preds = %9
%29 = call i32 @read(i32 %13, i8* %4, i32 4096)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %35, label %45
31: ; preds = %9
%32 = load i32, i32* @stdout
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %28, %42
%36 = phi i32 [ %43, %42 ], [ %29, %28 ]
%37 = call i32 @write(i32 %24, i8* %4, i32 %36)
%38 = icmp eq i32 %36, %37
br i1 %38, label %42, label %39
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %37)
br label %42
42: ; preds = %39, %35
%43 = call i32 @read(i32 %13, i8* %4, i32 4096)
%44 = icmp sgt i32 %43, 0
br i1 %44, label %35, label %45
45: ; preds = %42, %28
%46 = phi i32 [ %29, %28 ], [ %43, %42 ]
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %48, %45
%52 = tail call i32 @close(i32 %13)
%53 = tail call i32 @close(i32 %24)
%54 = tail call i32 @exit(i32 0)
unreachable
}