#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
main() {
  FILE *filer;
  FILE *filew1, *filew2;
  int numr, numw1, numw2;
  char buffer[50];
  if ((filer = fopen("myFile.txt", "rb")) == NULL) {
    fprintf(stderr, "open read file error.\n");
    exit(1);
  }
  if ((filew1 = fopen("myCopy1.txt", "wb")) == NULL ||
      (filew2 = fopen("myCopy2.txt", "wb")) == NULL) {
    fprintf(stderr, "open write file error.\n");
    exit(1);
  }
  while (feof(filer) == 0) {
    numr = fread(buffer, 1, 50, filer);
    numw1 = fwrite(buffer, 1, numr, filew1);
    numw2 = fwrite(buffer, 1, numr, filew2);
    printf(". ");
    if (numw1 != numr || numw2 != numr) {
      fprintf(stderr, "write file error.\n");
      exit(1);
    }
  }
  fclose(filer);
  fclose(filew1);
  fclose(filew2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11cf <main+0x4f>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe4f(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1211 <main+0x91>
lea    0xe3d(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1230 <main+0xb0>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1235 <main+0xb5>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
jne    12da <main+0x15a>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x32,%edx
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    %eax,-0x28(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    %eax,-0x2c(%rbp)
lea    0xdbf(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    12b6 <main+0x136>
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     12d5 <main+0x155>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
lea    0xd7f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1235 <main+0xb5>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xe6b(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12c2 <main+0x142>
mov    %rax,%r12
lea    0xe71(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     12b0 <main+0x130>
lea    0xe5f(%rip),%rdi
lea    0xe55(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12b0 <main+0x130>
mov    %rax,%r15
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    1285 <main+0x105>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x32,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    0x8(%rsp),%rcx
call   10a0 <fwrite@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r15,%rcx
call   10a0 <fwrite@plt>
mov    %eax,%r13d
lea    0xe01(%rip),%rdi
call   1050 <printf@plt>
cmp    %ebp,%r14d
jne    1266 <main+0xe6>
cmp    %ebp,%r13d
je     1200 <main+0x80>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
jmp    1276 <main+0xf6>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
lea    0xd3c(%rip),%rsi
jmp    1276 <main+0xf6>

LLVM IR (-O0):
@.str = [11 x i8] c"myFile.txt\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"open read file error.\0A\00"
@.str.3 = [12 x i8] c"myCopy1.txt\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [12 x i8] c"myCopy2.txt\00"
@.str.6 = [24 x i8] c"open write file error.\0A\00"
@.str.7 = [3 x i8] c". \00"
@.str.8 = [19 x i8] c"write file error.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [50 x i8]
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %16, i32** %3
%17 = icmp eq i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %19, i32** %4
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %18, %15
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %18
br label %26
26: ; preds = %54, %25
%27 = load i32*, i32** %2
%28 = call i64 @feof(i32* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %55
30: ; preds = %26
%31 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%32 = load i32*, i32** %2
%33 = call i32 @fread(i8* %31, i32 1, i32 50, i32* %32)
store i32 %33, i32* %5
%34 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%35 = load i32, i32* %5
%36 = load i32*, i32** %3
%37 = call i32 @fwrite(i8* %34, i32 1, i32 %35, i32* %36)
store i32 %37, i32* %6
%38 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%39 = load i32, i32* %5
%40 = load i32*, i32** %4
%41 = call i32 @fwrite(i8* %38, i32 1, i32 %39, i32* %40)
store i32 %41, i32* %7
%42 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%43 = load i32, i32* %6
%44 = load i32, i32* %5
%45 = icmp ne i32 %43, %44
br i1 %45, label %50, label %46
46: ; preds = %30
%47 = load i32, i32* %7
%48 = load i32, i32* %5
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %54
50: ; preds = %46, %30
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %46
br label %26
55: ; preds = %26
%56 = load i32*, i32** %2
%57 = call i32 @fclose(i32* %56)
%58 = load i32*, i32** %3
%59 = call i32 @fclose(i32* %58)
%60 = load i32*, i32** %4
%61 = call i32 @fclose(i32* %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"myFile.txt\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"open read file error.\0A\00"
@.str.3 = [12 x i8] c"myCopy1.txt\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [12 x i8] c"myCopy2.txt\00"
@.str.6 = [24 x i8] c"open write file error.\0A\00"
@.str.7 = [3 x i8] c". \00"
@.str.8 = [19 x i8] c"write file error.\0A\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %12, %9
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %12, %22
%20 = tail call i64 @feof(i32* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %19
%23 = call i32 @fread(i8* %2, i32 1, i32 50, i32* %3)
%24 = call i32 @fwrite(i8* %2, i32 1, i32 %23, i32* %10)
%25 = call i32 @fwrite(i8* %2, i32 1, i32 %23, i32* %13)
%26 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%27 = icmp eq i32 %24, %23
%28 = icmp eq i32 %25, %23
%29 = and i1 %27, %28
br i1 %29, label %19, label %30
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %19
%35 = tail call i32 @fclose(i32* %3)
%36 = tail call i32 @fclose(i32* %10)
%37 = tail call i32 @fclose(i32* %13)
ret i32 0
}