#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*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int copy_file(char *from, char *to) {
  FILE *from_file, *to_file;
  int ch;
  from_file = fopen(from, "rb");
  if (from_file == NULL)
    return (1);
  to_file = fopen(to, "wb");
  if (to_file == NULL) {
    fclose(from_file);
    return (1);
  }
  while (1) {
    ch = fgetc(from_file);
    if (feof(from_file))
      break;
    fputc(ch, to_file);
  }
  fclose(from_file);
  fclose(to_file);
  return (0);
}


x86 assembly (clang, -O0):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118b <copy_file+0x3b>
movl   $0x1,-0x4(%rbp)
jmp    1212 <copy_file+0xc2>
mov    -0x18(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11bf <copy_file+0x6f>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1212 <copy_file+0xc2>
jmp    11c4 <copy_file+0x74>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11e8 <copy_file+0x98>
jmp    11f9 <copy_file+0xa9>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1050 <fputc@plt>
jmp    11c4 <copy_file+0x74>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11bf <copy_file+0x6f>
mov    %rax,%rbx
lea    0xe91(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c6 <copy_file+0x76>
mov    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    11b3 <copy_file+0x63>
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
jmp    1190 <copy_file+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
jmp    11ce <copy_file+0x7e>
mov    $0x1,%ebp
jmp    11d6 <copy_file+0x86>
mov    $0x1,%ebp
mov    %rbx,%r14
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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