#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 *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int m_copy_file(char *from, char *to) {
  FILE *fp1, *fp2;
  char buf[1024];
  int i;
  if ((fp1 = fopen(from, "r")) != NULL) {
    if ((fp2 = fopen(to, "w")) != NULL) {
      do {
        i = fread(buf, 1, 1024, fp1);
        fwrite(buf, 1, i, fp2);
      } while (i == 1024);
      fclose(fp2);
      fclose(fp1);
      return 0;
    }
    fclose(fp1);
  }
  return -1;
}


x86 assembly (clang, -O0):
<m_copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1206 <m_copy_file+0xc6>
mov    -0x18(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11fd <m_copy_file+0xbd>
jmp    1194 <m_copy_file+0x54>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x434(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x434(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
cmpl   $0x400,-0x434(%rbp)
je     1194 <m_copy_file+0x54>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    120d <m_copy_file+0xcd>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_copy_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11bd <m_copy_file+0x7d>
mov    %rax,%r14
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c4 <m_copy_file+0x84>
mov    %rax,%r15
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
cmp    $0x400,%ebp
je     1180 <m_copy_file+0x40>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
jmp    11c9 <m_copy_file+0x89>
mov    $0xffffffff,%ebx
jmp    11d1 <m_copy_file+0x91>
mov    $0xffffffff,%ebx
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebx,%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 @m_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 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %37
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %7
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %34
17: ; preds = %13
br label %18
18: ; preds = %26, %17
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%20 = load i32*, i32** %6
%21 = call i32 @fread(i8* %19, i32 1, i32 1024, i32* %20)
store i32 %21, i32* %9
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%23 = load i32, i32* %9
%24 = load i32*, i32** %7
%25 = call i32 @fwrite(i8* %22, i32 1, i32 %23, i32* %24)
br label %26
26: ; preds = %18
%27 = load i32, i32* %9
%28 = icmp eq i32 %27, 1024
br i1 %28, label %18, label %29
29: ; preds = %26
%30 = load i32*, i32** %7
%31 = call i32 @fclose(i32* %30)
%32 = load i32*, i32** %6
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %3
br label %38
34: ; preds = %13
%35 = load i32*, i32** %6
%36 = call i32 @fclose(i32* %35)
br label %37
37: ; preds = %34, %2
store i32 -1, i32* %3
br label %38
38: ; preds = %37, %29
%39 = load i32, i32* %3
ret i32 %39
}

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