#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 BUFSIZ;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ ferror(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[BUFSIZ];
  FILE *fin, *fout;
  if (argc != 3) {
    fprintf(stderr, "Usage:\n\tsmartcopy <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) && !ferror(fin) && !ferror(fout))
    fwrite(buf, 1, fread(buf, 1, BUFSIZ, fin), fout);
  fclose(fout);
  fclose(fin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11fb <main+0x6b>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1238 <main+0xa8>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe11(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     127c <main+0xec>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdf2(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    129b <main+0x10b>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
jmp    12a0 <main+0x110>
mov    -0x28(%rbp),%rdi
call   1080 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
jne    12e6 <main+0x156>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
jne    12e6 <main+0x156>
mov    -0x30(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    12f6 <main+0x166>
jmp    132a <main+0x19a>
mov    -0x38(%rbp),%rdi
mov    0x2cd7(%rip),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
jmp    12a0 <main+0x110>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e36(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
cmp    $0x3,%edi
jne    1298 <main+0x108>
mov    %rsi,%r15
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     12b7 <main+0x127>
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1279 <main+0xe9>
mov    %rax,%rbx
mov    0x10(%r15),%rdi
lea    0xe5a(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1279 <main+0xe9>
mov    %rax,%r15
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    125a <main+0xca>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %eax,%eax
jne    125a <main+0xca>
mov    %r15,%rdi
call   1030 <ferror@plt>
test   %eax,%eax
jne    125a <main+0xca>
mov    (%r12),%edx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   10b0 <fwrite@plt>
jmp    120e <main+0x7e>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xd63(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"Usage:\0A\09smartcopy <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 i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @strcmp(i8* %23, i8* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %20
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %20
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %37, i32** %8
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %45
39: ; preds = %33
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %43, i32** %9
%44 = icmp ne i32* %43, null
br i1 %44, label %49, label %45
45: ; preds = %39, %33
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @exit(i32 5)
unreachable
49: ; preds = %39
br label %50
50: ; preds = %65, %49
%51 = load i32*, i32** %8
%52 = call i32 @feof(i32* %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %63, label %54
54: ; preds = %50
%55 = load i32*, i32** %8
%56 = call i32 @ferror(i32* %55)
%57 = icmp ne i32 %56, 0
br i1 %57, label %63, label %58
58: ; preds = %54
%59 = load i32*, i32** %9
%60 = call i32 @ferror(i32* %59)
%61 = icmp ne i32 %60, 0
%62 = xor i1 %61, true
br label %63
63: ; preds = %58, %54, %50
%64 = phi i1 [ false, %54 ], [ false, %50 ], [ %62, %58 ]
br i1 %64, label %65, label %71
65: ; preds = %63
%66 = load i32, i32* @BUFSIZ
%67 = load i32*, i32** %8
%68 = call i32 @fread(i8* %13, i32 1, i32 %66, i32* %67)
%69 = load i32*, i32** %9
%70 = call i32 @fwrite(i8* %13, i32 1, i32 %68, i32* %69)
br label %50
71: ; preds = %63
%72 = load i32*, i32** %9
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %8
%75 = call i32 @fclose(i32* %74)
store i32 0, i32* %3
%76 = load i8*, i8** %6
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"Usage:\0A\09smartcopy <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 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp eq i32 %0, 3
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %13, i8* dereferenceable(1) %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 2)
unreachable
22: ; preds = %11
%23 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %32, label %25
25: ; preds = %22
%26 = load i8*, i8** %14
%27 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = tail call i32 @feof(i32* %23)
%31 = icmp eq i32 %30, 0
br i1 %31, label %36, label %48
32: ; preds = %25, %22
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%35 = tail call i32 @exit(i32 5)
unreachable
36: ; preds = %29, %42
%37 = tail call i32 @ferror(i32* %23)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %36
%40 = tail call i32 @ferror(i32* %27)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %39
%43 = load i32, i32* @BUFSIZ
%44 = call i32 @fread(i8* %5, i32 1, i32 %43, i32* %23)
%45 = call i32 @fwrite(i8* %5, i32 1, i32 %44, i32* %27)
%46 = tail call i32 @feof(i32* %23)
%47 = icmp eq i32 %46, 0
br i1 %47, label %36, label %48
48: ; preds = %39, %36, %42, %29
%49 = tail call i32 @fclose(i32* %27)
%50 = tail call i32 @fclose(i32* %23)
ret i32 0
}