#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*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
size_t fwrite(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main() {
  size_t res1;
  unsigned char buffer[8192];
  FILE *ofPtr = fopen("oldMast.dat", "rb");
  FILE *nfPtr = fopen("newMast.dat", "wb");
  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 -1;
        } else {
          printf("ERROR - media full!\n");
          return -1;
        }
      }
    }
    fclose(ofPtr);
    fclose(nfPtr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x2018(%rbp)
lea    0xe7c(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x2020(%rbp)
cmpq   $0x0,-0x2018(%rbp)
jne    11c5 <main+0x65>
lea    0xe63(%rip),%rdi
call   1060 <printf@plt>
jmp    12b0 <main+0x150>
cmpq   $0x0,-0x2020(%rbp)
jne    11e4 <main+0x84>
lea    0xe68(%rip),%rdi
call   1060 <printf@plt>
jmp    12ab <main+0x14b>
jmp    11e9 <main+0x89>
lea    -0x2010(%rbp),%rdi
mov    -0x2018(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2000,%edx
call   1040 <fread@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jbe    1293 <main+0x133>
lea    -0x2010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x2020(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
mov    %rax,-0x2028(%rbp)
mov    -0x2028(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    128e <main+0x12e>
mov    -0x2020(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1276 <main+0x116>
lea    0xe01(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <main+0x157>
lea    0xe0b(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <main+0x157>
jmp    11e9 <main+0x89>
mov    -0x2018(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x2020(%rbp),%rdi
call   1050 <fclose@plt>
jmp    12b0 <main+0x150>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2008,%rsp
lea    0xe8b(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xe84(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
test   %r15,%r15
je     11fb <main+0x9b>
mov    %rax,%r14
test   %rax,%rax
je     1209 <main+0xa9>
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     1217 <main+0xb7>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   1080 <fwrite@plt>
cmp    %rbx,%rax
jae    11b0 <main+0x50>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     1238 <main+0xd8>
lea    0xe39(%rip),%rdi
jmp    123f <main+0xdf>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
jmp    1227 <main+0xc7>
lea    0xe43(%rip),%rdi
call   1030 <puts@plt>
jmp    1227 <main+0xc7>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x2008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xddf(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    1229 <main+0xc9>

LLVM IR (-O0):
@.str = [12 x i8] c"oldMast.dat\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [12 x i8] c"newMast.dat\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [36 x i8] c"\22oldMast.dat\22 could not be opened.\0A\00"
@.str.5 = [36 x i8] c"\22newMast.dat\22 could not be opened.\0A\00"
@.str.6 = [34 x i8] c"ERROR - unable to write to file!\0A\00"
@.str.7 = [21 x i8] c"ERROR - media full!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [8192 x i8]
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %4
%8 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
br label %47
13: ; preds = %0
%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.5, i64 0, i64 0))
br label %46
18: ; preds = %13
br label %19
19: ; preds = %40, %18
%20 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, 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* %2
%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]* %3, i64 0, i64 0
%26 = load i64, i64* %2
%27 = load i32*, i32** %5
%28 = call i64 @fwrite(i8* %25, i32 1, i64 %26, i32* %27)
store i64 %28, i64* %6
%29 = load i64, i64* %6
%30 = load i64, i64* %2
%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.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %48
38: ; preds = %32
%39 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %48
40: ; preds = %24
br label %19
41: ; preds = %19
%42 = load i32*, i32** %4
%43 = call i32 @fclose(i32* %42)
%44 = load i32*, i32** %5
%45 = call i32 @fclose(i32* %44)
br label %46
46: ; preds = %41, %16
br label %47
47: ; preds = %46, %11
store i32 0, i32* %1
br label %48
48: ; preds = %47, %38, %36
%49 = load i32, i32* %1
ret i32 %49
}

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