#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*/ 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 c;
  FILE *fin, *fout;
  if (argc != 3) {
    fprintf(stderr, "Usage:\n\tdumbcopy <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(&c, 1, fread(&c, 1, 1, fin), fout);
  fclose(fout);
  fclose(fin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11cf <main+0x3f>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%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    120c <main+0x7c>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1250 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe1d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    126f <main+0xdf>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
jmp    1274 <main+0xe4>
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
jne    12ba <main+0x12a>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
jne    12ba <main+0x12a>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    12ca <main+0x13a>
jmp    12f7 <main+0x167>
mov    -0x20(%rbp),%rcx
lea    -0x11(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rcx
lea    -0x11(%rbp),%rdi
mov    $0x1,%esi
call   10b0 <fwrite@plt>
jmp    1274 <main+0xe4>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    129c <main+0x10c>
mov    %rsi,%r14
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     12bb <main+0x12b>
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     127d <main+0xed>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
lea    0xe77(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     127d <main+0xed>
mov    %rax,%r14
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     121c <main+0x8c>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xf(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %eax,%eax
jne    1200 <main+0x70>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %eax,%eax
jne    1200 <main+0x70>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1230 <main+0xa0>
jmp    1200 <main+0x70>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
lea    0xd54(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    0xd5e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"Usage:\0A\09dumbcopy <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 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 ([41 x i8], [41 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 = %60, %44
%46 = load i32*, i32** %7
%47 = call i32 @feof(i32* %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %58, label %49
49: ; preds = %45
%50 = load i32*, i32** %7
%51 = call i32 @ferror(i32* %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %58, label %53
53: ; preds = %49
%54 = load i32*, i32** %8
%55 = call i32 @ferror(i32* %54)
%56 = icmp ne i32 %55, 0
%57 = xor i1 %56, true
br label %58
58: ; preds = %53, %49, %45
%59 = phi i1 [ false, %49 ], [ false, %45 ], [ %57, %53 ]
br i1 %59, label %60, label %65
60: ; preds = %58
%61 = load i32*, i32** %7
%62 = call i32 @fread(i8* %6, i32 1, i32 1, i32* %61)
%63 = load i32*, i32** %8
%64 = call i32 @fwrite(i8* %6, i32 1, i32 %62, i32* %63)
br label %45
65: ; preds = %58
%66 = load i32*, i32** %8
%67 = call i32 @fclose(i32* %66)
%68 = load i32*, i32** %7
%69 = call i32 @fclose(i32* %68)
ret i32 0
}

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