#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int copyfile(char *source, char *dest) {
  FILE *from;
  FILE *to;
  char ch;
  from = fopen(source, "rb");
  if (from == NULL)
    return 0;
  to = fopen(dest, "wb");
  if (to == NULL) {
    fclose(from);
    return 0;
  }
  while (!feof(from)) {
    ch = fgetc(from);
    if (ch != EOF)
      fputc(ch, to);
  }
  fclose(from);
  fclose(to);
  return 1;
}


x86 assembly (clang, -O0):
<copyfile>:
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 <copyfile+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    1231 <copyfile+0xe1>
mov    -0x18(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11bf <copyfile+0x6f>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1231 <copyfile+0xe1>
jmp    11c4 <copyfile+0x74>
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e2 <copyfile+0x92>
jmp    1218 <copyfile+0xc8>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
mov    0x2def(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1213 <copyfile+0xc3>
mov    -0x29(%rbp),%al
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    11c4 <copyfile+0x74>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyfile>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     119d <copyfile+0x4d>
mov    %rax,%rbx
lea    0xe91(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11a1 <copyfile+0x51>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11b5 <copyfile+0x65>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%ebp
jmp    11a6 <copyfile+0x56>
xor    %ebp,%ebp
jmp    11ae <copyfile+0x5e>
xor    %ebp,%ebp
mov    %rbx,%r14
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e2c(%rip),%rbp
jmp    11cc <copyfile+0x7c>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    118e <copyfile+0x3e>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    0x0(%rbp),%al
je     11c0 <copyfile+0x70>
movsbl %al,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
jmp    11c0 <copyfile+0x70>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@EOF = global i8 0
define i32 @copyfile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8
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 0, i32* %3
br label %46
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 0, i32* %3
br label %46
22: ; preds = %14
br label %23
23: ; preds = %40, %22
%24 = load i32*, i32** %6
%25 = call i32 @feof(i32* %24)
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %28, label %41
28: ; preds = %23
%29 = load i32*, i32** %6
%30 = call signext i8 @fgetc(i32* %29)
store i8 %30, i8* %8
%31 = load i8, i8* %8
%32 = sext i8 %31 to i32
%33 = load i8, i8* @EOF
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %32, %34
br i1 %35, label %36, label %40
36: ; preds = %28
%37 = load i8, i8* %8
%38 = load i32*, i32** %7
%39 = call i32 @fputc(i8 signext %37, i32* %38)
br label %40
40: ; preds = %36, %28
br label %23
41: ; preds = %23
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
%44 = load i32*, i32** %7
%45 = call i32 @fclose(i32* %44)
store i32 1, i32* %3
br label %46
46: ; preds = %41, %19, %13
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@EOF = global i8 0
define i32 @copyfile(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 %26, 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 %22, label %8
8: ; preds = %5
%9 = tail call i32 @feof(i32* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %8, %17
%12 = tail call signext i8 @fgetc(i32* %3)
%13 = load i8, i8* @EOF
%14 = icmp eq i8 %12, %13
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @fputc(i8 signext %12, i32* %6)
br label %17
17: ; preds = %15, %11
%18 = tail call i32 @feof(i32* %3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %11, label %20
20: ; preds = %17, %8
%21 = tail call i32 @fclose(i32* %3)
br label %22
22: ; preds = %5, %20
%23 = phi i32* [ %6, %20 ], [ %3, %5 ]
%24 = phi i32 [ 1, %20 ], [ 0, %5 ]
%25 = tail call i32 @fclose(i32* %23)
br label %26
26: ; preds = %22, %2
%27 = phi i32 [ 0, %2 ], [ %24, %22 ]
ret i32 %27
}