#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  int c;
  FILE *fin, *fout;
  if (argc != 3) {
    fprintf(stderr, "Usage:\n\ttextcopy <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], "r")) || !(fout = fopen(argv[2], "w"))) {
    fprintf(stderr, "File(s) could not be opened!\n");
    exit(5);
  }
  while ((c = fgetc(fin)) != EOF)
    fputc(c, 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     11af <main+0x3f>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1070 <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   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11ec <main+0x7c>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1230 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    124f <main+0xdf>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x5,%edi
call   1090 <exit@plt>
jmp    1254 <main+0xe4>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d81(%rip),%rcx
cmp    (%rcx),%eax
je     1280 <main+0x110>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1050 <fputc@plt>
jmp    1254 <main+0xe4>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    122e <main+0xbe>
mov    %rsi,%r15
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     124d <main+0xdd>
lea    0xeb7(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     120f <main+0x9f>
mov    %rax,%r14
mov    0x10(%r15),%rdi
lea    0xe9e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     120f <main+0x9f>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e11(%rip),%r15
cmp    (%r15),%eax
je     11f7 <main+0x87>
nopl   0x0(%rax)
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    11e0 <main+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x5,%edi
call   1090 <exit@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"Usage:\0A\09textcopy <source> <destination>\0A\00"
@.str.1 = [46 x i8] c"Source and destination files cannot be same!\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [30 x i8] c"File(s) could not be opened!\0A\00"
@EOF = global i32 0
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*
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 ([2 x i8], [2 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 ([2 x i8], [2 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 @fgetc(i32* %46)
store i32 %47, i32* %6
%48 = load i32, i32* @EOF
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %54
50: ; preds = %45
%51 = load i32, i32* %6
%52 = load i32*, i32** %8
%53 = call i32 @fputc(i32 %51, i32* %52)
br label %45
54: ; preds = %45
%55 = load i32*, i32** %8
%56 = call i32 @fclose(i32* %55)
%57 = load i32*, i32** %7
%58 = call i32 @fclose(i32* %57)
ret i32 0
}

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