#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__ ferror(int /*<<< orphan*/ *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
size_t fwrite(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int fileCopy(FILE *ofPtr, FILE *nfPtr) {
  size_t res1;
  unsigned char buffer[8192];
  if (ofPtr == NULL)
    printf("\"oldMast.dat\" could not be opened.\n");
  else if (nfPtr == NULL)
    printf("\"newMast.dat\" could not be opened.\n");
  else {
    while ((res1 = fread(buffer, 1, sizeof buffer, ofPtr)) > 0) {
      size_t res2 = fwrite(buffer, 1, res1, nfPtr);
      if (res2 < res1) {
        if (ferror(nfPtr)) {
          printf("ERROR - unable to write to file!\n");
          return 0;
        } else {
          printf("ERROR - media full!\n");
          return 0;
        }
      }
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<fileCopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116f <fileCopy+0x2f>
lea    0xe9b(%rip),%rdi
call   1050 <printf@plt>
jmp    123b <fileCopy+0xfb>
cmpq   $0x0,-0x18(%rbp)
jne    118b <fileCopy+0x4b>
lea    0xea3(%rip),%rdi
call   1050 <printf@plt>
jmp    1236 <fileCopy+0xf6>
jmp    1190 <fileCopy+0x50>
lea    -0x2020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2000,%edx
call   1040 <fread@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jbe    1231 <fileCopy+0xf1>
lea    -0x2020(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    %rax,-0x2028(%rbp)
mov    -0x2028(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    122c <fileCopy+0xec>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1214 <fileCopy+0xd4>
lea    0xe45(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1242 <fileCopy+0x102>
lea    0xe4f(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1242 <fileCopy+0x102>
jmp    1190 <fileCopy+0x50>
jmp    1236 <fileCopy+0xf6>
jmp    123b <fileCopy+0xfb>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileCopy>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2000,%rsp
mov    $0x1,%r14d
test   %rdi,%rdi
je     11c7 <fileCopy+0x87>
mov    %rsi,%r12
test   %rsi,%rsi
je     11d0 <fileCopy+0x90>
mov    %rdi,%rbp
mov    %rsp,%r15
mov    $0x1,%r14d
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     11dc <fileCopy+0x9c>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r12,%rcx
call   1060 <fwrite@plt>
cmp    %rbx,%rax
jae    1170 <fileCopy+0x30>
mov    %r12,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
lea    0xe49(%rip),%rax
lea    0xe56(%rip),%rdi
cmove  %rax,%rdi
xor    %r14d,%r14d
jmp    11d7 <fileCopy+0x97>
lea    0xe8a(%rip),%rdi
jmp    11d7 <fileCopy+0x97>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%eax
add    $0x2000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"\22oldMast.dat\22 could not be opened.\0A\00"
@.str.1 = [36 x i8] c"\22newMast.dat\22 could not be opened.\0A\00"
@.str.2 = [34 x i8] c"ERROR - unable to write to file!\0A\00"
@.str.3 = [21 x i8] c"ERROR - media full!\0A\00"
define i32 @fileCopy(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca [8192 x i8]
%8 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %43
13: ; preds = %2
%14 = load i32*, i32** %5
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %42
18: ; preds = %13
br label %19
19: ; preds = %40, %18
%20 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%21 = load i32*, i32** %4
%22 = call i64 @fread(i8* %20, i32 1, i32 8192, i32* %21)
store i64 %22, i64* %6
%23 = icmp ugt i64 %22, 0
br i1 %23, label %24, label %41
24: ; preds = %19
%25 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%26 = load i64, i64* %6
%27 = load i32*, i32** %5
%28 = call i64 @fwrite(i8* %25, i32 1, i64 %26, i32* %27)
store i64 %28, i64* %8
%29 = load i64, i64* %8
%30 = load i64, i64* %6
%31 = icmp ult i64 %29, %30
br i1 %31, label %32, label %40
32: ; preds = %24
%33 = load i32*, i32** %5
%34 = call i64 @ferror(i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %44
38: ; preds = %32
%39 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %44
40: ; preds = %24
br label %19
41: ; preds = %19
br label %42
42: ; preds = %41, %16
br label %43
43: ; preds = %42, %11
store i32 1, i32* %3
br label %44
44: ; preds = %43, %38, %36
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@str = [20 x i8] c"ERROR - media full!\00"
@str.4 = [33 x i8] c"ERROR - unable to write to file!\00"
@str.5 = [35 x i8] c"\22newMast.dat\22 could not be opened.\00"
@str.6 = [35 x i8] c"\22oldMast.dat\22 could not be opened.\00"
define i32 @fileCopy(i32* %0, i32* %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32* %0, null
br i1 %5, label %18, label %6
6: ; preds = %2
%7 = icmp eq i32* %1, null
br i1 %7, label %18, label %8
8: ; preds = %6, %11
%9 = call i64 @fread(i8* %4, i32 1, i32 8192, i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %8
%12 = call i64 @fwrite(i8* %4, i32 1, i64 %9, i32* %1)
%13 = icmp ult i64 %12, %9
br i1 %13, label %14, label %8
14: ; preds = %11
%15 = tail call i64 @ferror(i32* %1)
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @str.4, i64 0, i64 0)
br label %18
18: ; preds = %14, %6, %2
%19 = phi i8* [ getelementptr inbounds ([35 x i8], [35 x i8]* @str.6, i64 0, i64 0), %2 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @str.5, i64 0, i64 0), %6 ], [ %17, %14 ]
%20 = phi i32 [ 1, %2 ], [ 1, %6 ], [ 0, %14 ]
%21 = tail call i32 @puts(i8* dereferenceable(1) %19)
br label %22
22: ; preds = %8, %18
%23 = phi i32 [ %20, %18 ], [ 1, %8 ]
ret i32 %23
}