#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(int, int /*<<< orphan*/ *);
void file_copy(char *dest, char *src) {
  FILE *file_src = fopen(src, "r");
  FILE *file_dst = fopen(dest, "w");
  int character;
  if (!file_src || !file_dst)
    return;
  while ((character = fgetc(file_src)) != EOF)
    fputc(character, file_dst);
  fclose(file_dst);
  fclose(file_src);
}


x86 assembly (clang, -O0):
<file_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118e <file_copy+0x4e>
cmpq   $0x0,-0x20(%rbp)
jne    1193 <file_copy+0x53>
jmp    11d6 <file_copy+0x96>
jmp    1198 <file_copy+0x58>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e3d(%rip),%rcx
cmp    (%rcx),%eax
je     11c4 <file_copy+0x84>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <fputc@plt>
jmp    1198 <file_copy+0x58>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_copy>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xeae(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %r14,%r14
je     11bc <file_copy+0x7c>
mov    %rax,%rbx
test   %rax,%rax
je     11bc <file_copy+0x7c>
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e60(%rip),%r15
cmp    (%r15),%eax
je     11a7 <file_copy+0x67>
nopl   (%rax)
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    1190 <file_copy+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
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"
@EOF = global i32 0
define void @file_copy(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14, %2
br label %33
18: ; preds = %14
br label %19
19: ; preds = %24, %18
%20 = load i32*, i32** %5
%21 = call i32 @fgetc(i32* %20)
store i32 %21, i32* %7
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i32, i32* %7
%26 = load i32*, i32** %6
%27 = call i32 @fputc(i32 %25, i32* %26)
br label %19
28: ; preds = %19
%29 = load i32*, i32** %6
%30 = call i32 @fclose(i32* %29)
%31 = load i32*, i32** %5
%32 = call i32 @fclose(i32* %31)
br label %33
33: ; preds = %28, %17
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i32 0
define void @file_copy(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp ne i32* %3, null
%6 = icmp ne i32* %4, null
%7 = and i1 %5, %6
br i1 %7, label %8, label %21
8: ; preds = %2
%9 = tail call i32 @fgetc(i32* %3)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %18, label %12
12: ; preds = %8, %12
%13 = phi i32 [ %15, %12 ], [ %9, %8 ]
%14 = tail call i32 @fputc(i32 %13, i32* %4)
%15 = tail call i32 @fgetc(i32* %3)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %12
18: ; preds = %12, %8
%19 = tail call i32 @fclose(i32* %4)
%20 = tail call i32 @fclose(i32* %3)
br label %21
21: ; preds = %2, %18
ret void
}