#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*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  FILE *fin;
  FILE *fout;
  fin = fopen(argv[1], "r");
  fout = fopen(argv[2], "w");
  if (fin == NULL) {
    printf("Cannot open source file.\n");
  } else if (fout == NULL) {
    printf("Cannot open destination file\n");
    fclose(fin);
  } else {
    int char_buffer;
    while ((char_buffer = fgetc(fin)) != EOF) {
      fputc((char)char_buffer, fout);
    }
    fclose(fin);
    fclose(fout);
  }
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b2 <main+0x62>
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
jmp    1222 <main+0xd2>
cmpq   $0x0,-0x20(%rbp)
jne    11d7 <main+0x87>
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    121d <main+0xcd>
jmp    11dc <main+0x8c>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%eax
je     120b <main+0xbb>
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    11dc <main+0x8c>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1222 <main+0xd2>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
test   %r14,%r14
je     11c5 <main+0x75>
mov    %rax,%rbx
test   %rax,%rax
je     11d3 <main+0x83>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2e51(%rip),%r15
cmp    (%r15),%eax
je     11b8 <main+0x68>
nopl   0x0(%rax)
movsbl %al,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%eax
jne    11a0 <main+0x50>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
jmp    11e2 <main+0x92>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
jmp    11e7 <main+0x97>
lea    0xe2a(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [26 x i8] c"Cannot open source file.\0A\00"
@.str.3 = [30 x i8] c"Cannot open destination file\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 i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %45
21: ; preds = %2
%22 = load i32*, i32** %7
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
br label %44
28: ; preds = %21
br label %29
29: ; preds = %34, %28
%30 = load i32*, i32** %6
%31 = call i32 @fgetc(i32* %30)
store i32 %31, i32* %8
%32 = load i32, i32* @EOF
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = load i32, i32* %8
%36 = trunc i32 %35 to i8
%37 = load i32*, i32** %7
%38 = call i32 @fputc(i8 signext %36, i32* %37)
br label %29
39: ; preds = %29
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
br label %44
44: ; preds = %39, %24
br label %45
45: ; preds = %44, %19
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i32 0
@str = [29 x i8] c"Cannot open destination file\00"
@str.4 = [25 x i8] c"Cannot open source file.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %5, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.4, i64 0, i64 0))
br label %31
12: ; preds = %2
%13 = icmp eq i32* %8, null
br i1 %13, label %18, label %14
14: ; preds = %12
%15 = tail call i32 @fgetc(i32* %5)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %28, label %21
18: ; preds = %12
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%20 = tail call i32 @fclose(i32* %5)
br label %31
21: ; preds = %14, %21
%22 = phi i32 [ %25, %21 ], [ %15, %14 ]
%23 = trunc i32 %22 to i8
%24 = tail call i32 @fputc(i8 signext %23, i32* %8)
%25 = tail call i32 @fgetc(i32* %5)
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %21
28: ; preds = %21, %14
%29 = tail call i32 @fclose(i32* %5)
%30 = tail call i32 @fclose(i32* %8)
br label %31
31: ; preds = %18, %28, %10
ret i32 0
}