#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 *filew;
  int numr, numw;
  char buffer[50];
  if ((filer = fopen("myFile.txt", "rb")) == NULL) {
    fprintf(stderr, "open read file error.\n");
    exit(1);
  }
  if ((filew = fopen("myCopy.txt", "wb")) == NULL) {
    fprintf(stderr, "open write file error.\n");
    exit(1);
  }
  while (feof(filer) == 0) {
    numr = fread(buffer, 1, 50, filer);
    numw = fwrite(buffer, 1, numr, filew);
    printf(". ");
    if (numw != numr) {
      fprintf(stderr, "write file error.\n");
      exit(1);
    }
  }
  fclose(filer);
  fclose(filew);
  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    0xe53(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    120f <main+0x8f>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1214 <main+0x94>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
jne    1295 <main+0x115>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x32,%edx
call   1030 <fread@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    %eax,-0x20(%rbp)
lea    0xdeb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1290 <main+0x110>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1214 <main+0x94>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%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    $0x38,%rsp
lea    0xe6b(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1264 <main+0xe4>
mov    %rax,%r13
lea    0xe71(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1276 <main+0xf6>
mov    %rax,%r14
mov    %rsp,%r15
lea    0xe75(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    1243 <main+0xc3>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x32,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   10a0 <fwrite@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <printf@plt>
cmp    %ebp,%ebx
je     11e0 <main+0x60>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
jmp    1234 <main+0xb4>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
jmp    1234 <main+0xb4>

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 = [11 x i8] c"myCopy.txt\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [24 x i8] c"open write file error.\0A\00"
@.str.6 = [3 x i8] c". \00"
@.str.7 = [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 [50 x i8]
store i32 0, i32* %1
%7 = 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* %7, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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* %14, i32** %3
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13
br label %21
21: ; preds = %41, %20
%22 = load i32*, i32** %2
%23 = call i64 @feof(i32* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %42
25: ; preds = %21
%26 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%27 = load i32*, i32** %2
%28 = call i32 @fread(i8* %26, i32 1, i32 50, i32* %27)
store i32 %28, i32* %4
%29 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%30 = load i32, i32* %4
%31 = load i32*, i32** %3
%32 = call i32 @fwrite(i8* %29, i32 1, i32 %30, i32* %31)
store i32 %32, i32* %5
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%34 = load i32, i32* %5
%35 = load i32, i32* %4
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %41
37: ; preds = %25
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %25
br label %21
42: ; preds = %21
%43 = load i32*, i32** %2
%44 = call i32 @fclose(i32* %43)
%45 = load i32*, i32** %3
%46 = call i32 @fclose(i32* %45)
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 = [11 x i8] c"myCopy.txt\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [24 x i8] c"open write file error.\0A\00"
@.str.6 = [3 x i8] c". \00"
@.str.7 = [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 ([11 x i8], [11 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 %12, label %16
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9, %19
%17 = tail call i64 @feof(i32* %3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = call i32 @fread(i8* %2, i32 1, i32 50, i32* %3)
%21 = call i32 @fwrite(i8* %2, i32 1, i32 %20, i32* %10)
%22 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%23 = icmp eq i32 %21, %20
br i1 %23, label %16, label %24
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %16
%29 = tail call i32 @fclose(i32* %3)
%30 = tail call i32 @fclose(i32* %10)
ret i32 0
}