#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
extern int copy_file(char const *f1, char const *f2) {
  if (NULL == f1 || NULL == f2)
    return -1;
  FILE *src, *dst;
  src = fopen(f1, "r");
  dst = fopen(f2, "w");
  if (NULL == src || NULL == dst)
    return -1;
  char buff[1024];
  int n;
  while (0 < (n = fread(buff, 1, 1024, src)))
    fwrite(buff, 1, n, dst);
  fclose(src);
  fclose(dst);
  return 0;
}


x86 assembly (clang, -O0):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     116b <copy_file+0x2b>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    1177 <copy_file+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <copy_file+0xed>
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
je     11b7 <copy_file+0x77>
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    11c3 <copy_file+0x83>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <copy_file+0xed>
jmp    11c8 <copy_file+0x88>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,%ecx
mov    %ecx,-0x434(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jge    1214 <copy_file+0xd4>
lea    -0x430(%rbp),%rdi
mov    -0x434(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
jmp    11c8 <copy_file+0x88>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    $0xffffffff,%r15d
test   %rdi,%rdi
je     11ee <copy_file+0xae>
mov    %rsi,%rbp
test   %rsi,%rsi
je     11ee <copy_file+0xae>
lea    0xe91(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xe84(%rip),%rsi
mov    %rbp,%rdi
call   1050 <fopen@plt>
test   %rbx,%rbx
je     11ee <copy_file+0xae>
mov    %rax,%r14
test   %rax,%rax
je     11ee <copy_file+0xae>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    11db <copy_file+0x9b>
mov    %rsp,%rbp
nop
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jg     11b0 <copy_file+0x70>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @copy_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [1024 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = icmp eq i8* null, %10
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = icmp eq i8* null, %13
br i1 %14, label %15, label %16
15: ; preds = %12, %2
store i32 -1, i32* %3
br label %43
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i8*, i8** %5
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %6
%22 = icmp eq i32* null, %21
br i1 %22, label %26, label %23
23: ; preds = %16
%24 = load i32*, i32** %7
%25 = icmp eq i32* null, %24
br i1 %25, label %26, label %27
26: ; preds = %23, %16
store i32 -1, i32* %3
br label %43
27: ; preds = %23
br label %28
28: ; preds = %33, %27
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%30 = load i32*, i32** %6
%31 = call i32 @fread(i8* %29, i32 1, i32 1024, i32* %30)
store i32 %31, i32* %9
%32 = icmp slt i32 0, %31
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%35 = load i32, i32* %9
%36 = load i32*, i32** %7
%37 = call i32 @fwrite(i8* %34, i32 1, i32 %35, i32* %36)
br label %28
38: ; preds = %28
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
%41 = load i32*, i32** %7
%42 = call i32 @fclose(i32* %41)
store i32 0, i32* %3
br label %43
43: ; preds = %38, %26, %15
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @copy_file(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
br i1 %6, label %25, label %7
7: ; preds = %2
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %8, null
%11 = icmp eq i32* %9, null
%12 = or i1 %10, %11
br i1 %12, label %25, label %13
13: ; preds = %7
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = call i32 @fread(i8* %14, i32 1, i32 1024, i32* %8)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13, %17
%18 = phi i32 [ %20, %17 ], [ %15, %13 ]
%19 = call i32 @fwrite(i8* %14, i32 1, i32 %18, i32* %9)
%20 = call i32 @fread(i8* %14, i32 1, i32 1024, i32* %8)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %17, label %22
22: ; preds = %17, %13
%23 = tail call i32 @fclose(i32* %8)
%24 = tail call i32 @fclose(i32* %9)
br label %25
25: ; preds = %22, %7, %2
%26 = phi i32 [ -1, %2 ], [ 0, %22 ], [ -1, %7 ]
ret i32 %26
}