#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int source, destination, nread;
  char buffer[1024];
  if (argc != 3) {
    printf("Number of Arguements provided != 3 \n");
    printf("Arguements Required: \n");
    printf("Filename \n");
    printf("Newfile \n");
    exit(-1);
  }
  if ((source = open(argv[1], O_RDONLY)) == -1) {
    perror(argv[1]);
    exit(-1);
  }
  if ((destination = creat(argv[2], 0644)) == -1) {
    perror(argv[1]);
    exit(-1);
  }
  while ((nread = read(source, buffer, 1024)) > 0) {
    if (write(destination, buffer, nread) == -1) {
      printf("Can't Write. \n");
      exit(-1);
    }
  }
  close(source);
  close(destination);
  return 0;
}


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)
je     11dd <main+0x5d>
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1216 <main+0x96>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x1a4,%esi
call   1090 <creat@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    124b <main+0xcb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    1250 <main+0xd0>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    12a6 <main+0x126>
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    12a1 <main+0x121>
lea    0xdbf(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    1250 <main+0xd0>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
cmp    $0x3,%edi
jne    123d <main+0xbd>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     122a <main+0xaa>
mov    %eax,%r15d
mov    0x10(%r14),%rdi
mov    $0x1a4,%esi
call   1090 <creat@plt>
cmp    $0xffffffff,%eax
je     122a <main+0xaa>
mov    %eax,%ebp
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    120b <main+0x8b>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    11d0 <main+0x50>
lea    0xe04(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%r14),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xdca(%rip),%rdi
call   1030 <puts@plt>
lea    0xde2(%rip),%rdi
call   1030 <puts@plt>
lea    0xdec(%rip),%rdi
call   1030 <puts@plt>
lea    0xdea(%rip),%rdi
jmp    11fc <main+0x7c>

LLVM IR (-O0):
@.str = [37 x i8] c"Number of Arguements provided != 3 \0A\00"
@.str.1 = [23 x i8] c"Arguements Required: \0A\00"
@.str.2 = [11 x i8] c"Filename \0A\00"
@.str.3 = [10 x i8] c"Newfile \0A\00"
@O_RDONLY = global i32 0
@.str.4 = [15 x i8] c"Can't Write. \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 [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 ne i32 %10, 3
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %6
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %31
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @perror(i8* %28)
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %18
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @creat(i8* %34, i32 420)
store i32 %35, i32* %7
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %43
37: ; preds = %31
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @perror(i8* %40)
%42 = call i32 @exit(i32 -1)
unreachable
43: ; preds = %31
br label %44
44: ; preds = %58, %43
%45 = load i32, i32* %6
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%47 = call i32 @read(i32 %45, i8* %46, i32 1024)
store i32 %47, i32* %8
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %59
49: ; preds = %44
%50 = load i32, i32* %7
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%52 = load i32, i32* %8
%53 = call i32 @write(i32 %50, i8* %51, i32 %52)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %49
%56 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%57 = call i32 @exit(i32 -1)
unreachable
58: ; preds = %49
br label %44
59: ; preds = %44
%60 = load i32, i32* %6
%61 = call i32 @close(i32 %60)
%62 = load i32, i32* %7
%63 = call i32 @close(i32 %62)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@str = [14 x i8] c"Can't Write. \00"
@str.5 = [36 x i8] c"Number of Arguements provided != 3 \00"
@str.6 = [22 x i8] c"Arguements Required: \00"
@str.7 = [10 x i8] c"Filename \00"
@str.8 = [9 x i8] c"Newfile \00"
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 eq i32 %0, 3
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.7, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.8, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* %14, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = load i8*, i8** %13
%20 = tail call i32 @perror(i8* %19)
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %12
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i32 @creat(i8* %24, i32 420)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i8*, i8** %13
%29 = tail call i32 @perror(i8* %28)
%30 = tail call i32 @exit(i32 -1)
unreachable
31: ; preds = %22, %34
%32 = call i32 @read(i32 %16, i8* %4, i32 1024)
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = call i32 @write(i32 %25, i8* %4, i32 %32)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %31
37: ; preds = %34
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%39 = tail call i32 @exit(i32 -1)
unreachable
40: ; preds = %31
%41 = tail call i32 @close(i32 %16)
%42 = tail call i32 @close(i32 %25)
ret i32 0
}