#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  char buf[4096];
  FILE *fin, *fout;
  if (argc != 3) {
    fprintf(stderr, "Usage:\n\tcpy <source> <destination>\n");
    exit(1);
  }
  if (!strcmp(argv[1], argv[2])) {
    fprintf(stderr, "Source and destination files cannot be same!\n");
    exit(2);
  }
  if (!(fin = fopen(argv[1], "rb")) || !(fout = fopen(argv[2], "wb"))) {
    fprintf(stderr, "File(s) could not be opened!\n");
    exit(5);
  }
  while (!feof(fin))
    fwrite(buf, 1, fread(buf, 1, 4096, fin), fout);
  fclose(fout);
  fclose(fin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11c2 <main+0x42>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11ff <main+0x7f>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe44(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x1018(%rbp)
cmp    $0x0,%rax
je     1249 <main+0xc9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe22(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x1020(%rbp)
cmp    $0x0,%rax
jne    1268 <main+0xe8>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x5,%edi
call   1090 <exit@plt>
jmp    126d <main+0xed>
mov    -0x1018(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    128e <main+0x10e>
jmp    12d8 <main+0x158>
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1028(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x1018(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    -0x1028(%rbp),%rdi
mov    %eax,%edx
mov    -0x1020(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
jmp    126d <main+0xed>
mov    -0x1020(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1018(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
cmp    $0x3,%edi
jne    1271 <main+0xf1>
mov    %rsi,%r14
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1290 <main+0x110>
lea    0xe9b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1252 <main+0xd2>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1252 <main+0xd2>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1233 <main+0xb3>
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     1200 <main+0x80>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x5,%edi
call   1090 <exit@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xd7f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Usage:\0A\09cpy <source> <destination>\0A\00"
@.str.1 = [46 x i8] c"Source and destination files cannot be same!\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [30 x i8] c"File(s) could not be opened!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i32*
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @strcmp(i8* %18, i8* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %15
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 2)
unreachable
28: ; preds = %15
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %7
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %40
34: ; preds = %28
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %38, i32** %8
%39 = icmp ne i32* %38, null
br i1 %39, label %44, label %40
40: ; preds = %34, %28
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 @exit(i32 5)
unreachable
44: ; preds = %34
br label %45
45: ; preds = %50, %44
%46 = load i32*, i32** %7
%47 = call i32 @feof(i32* %46)
%48 = icmp ne i32 %47, 0
%49 = xor i1 %48, true
br i1 %49, label %50, label %57
50: ; preds = %45
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%53 = load i32*, i32** %7
%54 = call i32 @fread(i8* %52, i32 1, i32 4096, i32* %53)
%55 = load i32*, i32** %8
%56 = call i32 @fwrite(i8* %51, i32 1, i32 %54, i32* %55)
br label %45
57: ; preds = %45
%58 = load i32*, i32** %8
%59 = call i32 @fclose(i32* %58)
%60 = load i32*, i32** %7
%61 = call i32 @fclose(i32* %60)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Usage:\0A\09cpy <source> <destination>\0A\00"
@.str.1 = [46 x i8] c"Source and destination files cannot be same!\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [30 x i8] c"File(s) could not be opened!\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 %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(1) %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 2)
unreachable
21: ; preds = %10
%22 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %31, label %24
24: ; preds = %21
%25 = load i8*, i8** %13
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = tail call i32 @feof(i32* %22)
%30 = icmp eq i32 %29, 0
br i1 %30, label %35, label %40
31: ; preds = %24, %21
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%34 = tail call i32 @exit(i32 5)
unreachable
35: ; preds = %28, %35
%36 = call i32 @fread(i8* %4, i32 1, i32 4096, i32* %22)
%37 = call i32 @fwrite(i8* %4, i32 1, i32 %36, i32* %26)
%38 = tail call i32 @feof(i32* %22)
%39 = icmp eq i32 %38, 0
br i1 %39, label %35, label %40
40: ; preds = %35, %28
%41 = tail call i32 @fclose(i32* %26)
%42 = tail call i32 @fclose(i32* %22)
ret i32 0
}