#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int FileProxy_CopyFile(char *filename, char *newname) {
  FILE *fpSrc = NULL;
  FILE *fpDst = NULL;
  int ret = 1;
  char ch;
  fpSrc = fopen(filename, "rb");
  fpDst = fopen(newname, "wb");
  if ((fpSrc != NULL) && (fpDst != NULL)) {
    while (!feof(fpSrc)) {
      fread(&ch, sizeof(char), 1, fpSrc);
      fwrite(&ch, sizeof(char), 1, fpDst);
    }
    fflush(fpDst);
    ret = 0;
  } else {
    ret = 1;
  }
  if (fpSrc != NULL) {
    fclose(fpSrc);
    fpSrc = NULL;
  }
  if (fpDst != NULL) {
    fclose(fpDst);
    fpDst = NULL;
  }
  return (ret);
}


x86 assembly (clang, -O0):
<FileProxy_CopyFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     122a <FileProxy_CopyFile+0xca>
cmpq   $0x0,-0x20(%rbp)
je     122a <FileProxy_CopyFile+0xca>
jmp    11ca <FileProxy_CopyFile+0x6a>
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e8 <FileProxy_CopyFile+0x88>
jmp    1215 <FileProxy_CopyFile+0xb5>
mov    -0x18(%rbp),%rcx
lea    -0x25(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rcx
lea    -0x25(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1080 <fwrite@plt>
jmp    11ca <FileProxy_CopyFile+0x6a>
mov    -0x20(%rbp),%rdi
call   1060 <fflush@plt>
movl   $0x0,-0x24(%rbp)
jmp    1231 <FileProxy_CopyFile+0xd1>
movl   $0x1,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     124d <FileProxy_CopyFile+0xed>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1269 <FileProxy_CopyFile+0x109>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileProxy_CopyFile>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe82(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    $0x1,%ebp
test   %rbx,%rbx
je     11e8 <FileProxy_CopyFile+0x88>
test   %r14,%r14
je     11e8 <FileProxy_CopyFile+0x88>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11de <FileProxy_CopyFile+0x7e>
lea    0xf(%rsp),%rbp
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
movsbl 0xf(%rsp),%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11b0 <FileProxy_CopyFile+0x50>
mov    %r14,%rdi
call   1070 <fflush@plt>
xor    %ebp,%ebp
test   %rbx,%rbx
je     11f5 <FileProxy_CopyFile+0x95>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %r14,%r14
je     1202 <FileProxy_CopyFile+0xa2>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x10,%rsp
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 @FileProxy_CopyFile(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* null, i32** %5
store i32* null, i32** %6
store i32 1, i32* %7
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %5
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %32
15: ; preds = %2
%16 = load i32*, i32** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %32
18: ; preds = %15
br label %19
19: ; preds = %24, %18
%20 = load i32*, i32** %5
%21 = call i32 @feof(i32* %20)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i32*, i32** %5
%26 = call i32 @fread(i8* %8, i32 1, i32 1, i32* %25)
%27 = load i32*, i32** %6
%28 = call i32 @fwrite(i8* %8, i32 1, i32 1, i32* %27)
br label %19
29: ; preds = %19
%30 = load i32*, i32** %6
%31 = call i32 @fflush(i32* %30)
store i32 0, i32* %7
br label %33
32: ; preds = %15, %2
store i32 1, i32* %7
br label %33
33: ; preds = %32, %29
%34 = load i32*, i32** %5
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32*, i32** %5
%38 = call i32 @fclose(i32* %37)
store i32* null, i32** %5
br label %39
39: ; preds = %36, %33
%40 = load i32*, i32** %6
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
store i32* null, i32** %6
br label %45
45: ; preds = %42, %39
%46 = load i32, i32* %7
ret i32 %46
}

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