#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int file_copy(const char *source_file_name, const char *dest_file_name) {
  int ch;
  FILE *source_fp;
  FILE *dest_fp;
  source_fp = fopen(source_file_name, "r");
  dest_fp = fopen(dest_file_name, "w");
  if (source_fp == NULL || dest_fp == NULL)
    return 0;
  while ((ch = fgetc(source_fp)) != EOF)
    fputc(ch, dest_fp);
  fclose(source_fp);
  fclose(dest_fp);
  return 1;
}


x86 assembly (clang, -O0):
<file_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     118e <file_copy+0x4e>
cmpq   $0x0,-0x30(%rbp)
jne    119a <file_copy+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    11e4 <file_copy+0xa4>
jmp    119f <file_copy+0x5f>
mov    -0x28(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%eax
je     11cb <file_copy+0x8b>
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1050 <fputc@plt>
jmp    119f <file_copy+0x5f>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_copy>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xea4(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
xor    %eax,%eax
test   %rbx,%rbx
je     11bc <file_copy+0x7c>
test   %r14,%r14
je     11bc <file_copy+0x7c>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    0x2e64(%rip),%r15
cmp    (%r15),%eax
je     11a7 <file_copy+0x67>
nopl   0x0(%rax)
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    1190 <file_copy+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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