#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, char *);
int file_copy(char *destination_file, char *source_file) {
  int result = 1;
  FILE *inf, *ouf;
  printf("util: Copying %s to %s.\n", source_file, destination_file);
  inf = fopen(source_file, "rb");
  if (inf) {
    ouf = fopen(destination_file, "wb");
    if (ouf) {
      while (!feof(inf)) {
        char ch = fgetc(inf);
        if (!feof(inf)) {
          if (fputc(ch, ouf) == EOF) {
            result = 0;
            break;
          }
        }
      }
      fclose(ouf);
    } else {
      result = 0;
    }
    fclose(inf);
  } else {
    result = 0;
  }
  return result;
}


x86 assembly (clang, -O0):
<file_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1262 <file_copy+0x102>
mov    -0x8(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     124d <file_copy+0xed>
jmp    11ce <file_copy+0x6e>
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ec <file_copy+0x8c>
jmp    123f <file_copy+0xdf>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x29(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
jne    123a <file_copy+0xda>
mov    -0x29(%rbp),%al
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
mov    0x2dc8(%rip),%rcx
cmp    (%rcx),%rax
jne    1235 <file_copy+0xd5>
movl   $0x0,-0x14(%rbp)
jmp    123f <file_copy+0xdf>
jmp    123a <file_copy+0xda>
jmp    11ce <file_copy+0x6e>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1254 <file_copy+0xf4>
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1269 <file_copy+0x109>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_copy>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xe8b(%rip),%rdi
mov    %rbx,%rdx
call   1040 <printf@plt>
lea    0xe95(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11c7 <file_copy+0x67>
mov    %rax,%rbp
lea    0xe81(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11cc <file_copy+0x6c>
mov    %rax,%r15
mov    %rbp,%rdi
call   1070 <feof@plt>
mov    $0x1,%r14d
test   %eax,%eax
je     11e3 <file_copy+0x83>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    11cf <file_copy+0x6f>
xor    %r14d,%r14d
jmp    11d7 <file_copy+0x77>
xor    %r14d,%r14d
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dfe(%rip),%r12
jmp    11fc <file_copy+0x9c>
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11bd <file_copy+0x5d>
mov    %rbp,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11f0 <file_copy+0x90>
movsbl %bl,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
cmp    (%r12),%rax
jne    11f0 <file_copy+0x90>
xor    %r14d,%r14d
jmp    11bd <file_copy+0x5d>

LLVM IR (-O0):
@.str = [25 x i8] c"util: Copying %s to %s.\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
@EOF = global i64 0
define i32 @file_copy(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 1, i32* %5
%9 = load i8*, i8** %4
%10 = load i8*, i8** %3
%11 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10)
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %49
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %45
21: ; preds = %16
br label %22
22: ; preds = %41, %21
%23 = load i32*, i32** %6
%24 = call i32 @feof(i32* %23)
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
br i1 %26, label %27, label %42
27: ; preds = %22
%28 = load i32*, i32** %6
%29 = call signext i8 @fgetc(i32* %28)
store i8 %29, i8* %8
%30 = load i32*, i32** %6
%31 = call i32 @feof(i32* %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %41, label %33
33: ; preds = %27
%34 = load i8, i8* %8
%35 = load i32*, i32** %7
%36 = call i64 @fputc(i8 signext %34, i32* %35)
%37 = load i64, i64* @EOF
%38 = icmp eq i64 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 0, i32* %5
br label %42
40: ; preds = %33
br label %41
41: ; preds = %40, %27
br label %22
42: ; preds = %39, %22
%43 = load i32*, i32** %7
%44 = call i32 @fclose(i32* %43)
br label %46
45: ; preds = %16
store i32 0, i32* %5
br label %46
46: ; preds = %45, %42
%47 = load i32*, i32** %6
%48 = call i32 @fclose(i32* %47)
br label %50
49: ; preds = %2
store i32 0, i32* %5
br label %50
50: ; preds = %49, %46
%51 = load i32, i32* %5
ret i32 %51
}

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