#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*/ zBuf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fossil_fatal(char *, char const *);
int /*<<< orphan*/ *fossil_fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
void file_copy(const char *zFrom, const char *zTo) {
  FILE *in, *out;
  int got;
  char zBuf[8192];
  in = fossil_fopen(zFrom, "rb");
  if (in == 0)
    fossil_fatal("cannot open \"%s\" for reading", zFrom);
  out = fossil_fopen(zTo, "wb");
  if (out == 0)
    fossil_fatal("cannot open \"%s\" for writing", zTo);
  while ((got = fread(zBuf, 1, sizeof(zBuf), in)) > 0) {
    fwrite(zBuf, 1, got, out);
  }
  fclose(in);
  fclose(out);
}


x86 assembly (clang, -O0):
<file_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1030 <fossil_fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1192 <file_copy+0x42>
mov    -0x8(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1050 <fossil_fatal@plt>
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1030 <fossil_fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c1 <file_copy+0x71>
mov    -0x10(%rbp),%rsi
lea    0xe67(%rip),%rdi
call   1050 <fossil_fatal@plt>
jmp    11c6 <file_copy+0x76>
lea    -0x2030(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2000,%edx
call   1040 <fread@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    1209 <file_copy+0xb9>
lea    -0x2030(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
jmp    11c6 <file_copy+0x76>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_copy>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2008,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe95(%rip),%rsi
call   1030 <fossil_fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1187 <file_copy+0x37>
lea    0xe84(%rip),%rdi
mov    %rbx,%rsi
call   1050 <fossil_fatal@plt>
lea    0xe92(%rip),%rsi
mov    %r15,%rdi
call   1030 <fossil_fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11ad <file_copy+0x5d>
lea    0xe7e(%rip),%rdi
mov    %r15,%rsi
call   1050 <fossil_fatal@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    11fb <file_copy+0xab>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r12,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jg     11d0 <file_copy+0x80>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %r12,%rdi
add    $0x2008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <fclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [29 x i8] c"cannot open \22%s\22 for reading\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [29 x i8] c"cannot open \22%s\22 for writing\00"
define void @file_copy(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [8192 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32* @fossil_fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call i32 @fossil_fatal(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %2
%17 = load i8*, i8** %4
%18 = call i32* @fossil_fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = call i32 @fossil_fatal(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %16
br label %25
25: ; preds = %30, %24
%26 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%27 = load i32*, i32** %5
%28 = call i32 @fread(i8* %26, i32 1, i32 8192, i32* %27)
store i32 %28, i32* %7
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%32 = load i32, i32* %7
%33 = load i32*, i32** %6
%34 = call i32 @fwrite(i8* %31, i32 1, i32 %32, i32* %33)
br label %25
35: ; preds = %25
%36 = load i32*, i32** %5
%37 = call i32 @fclose(i32* %36)
%38 = load i32*, i32** %6
%39 = call i32 @fclose(i32* %38)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [29 x i8] c"cannot open \22%s\22 for reading\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [29 x i8] c"cannot open \22%s\22 for writing\00"
define void @file_copy(i8* %0, i8* %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fossil_fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @fossil_fatal(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %2
%10 = tail call i32* @fossil_fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @fossil_fatal(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %14
14: ; preds = %12, %9
%15 = call i32 @fread(i8* %4, i32 1, i32 8192, i32* %5)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14, %17
%18 = phi i32 [ %20, %17 ], [ %15, %14 ]
%19 = call i32 @fwrite(i8* %4, i32 1, i32 %18, i32* %10)
%20 = call i32 @fread(i8* %4, i32 1, i32 8192, i32* %5)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %17, label %22
22: ; preds = %17, %14
%23 = tail call i32 @fclose(i32* %5)
%24 = tail call i32 @fclose(i32* %10)
ret void
}