#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*/ stderr;
main() {
  FILE *filer;
  FILE *filew;
  int numr, numw;
  char buffer[100];
  if ((filer = fopen("myCopy.bin", "rb")) == NULL) {
    fprintf(stderr, "open read file error.\n");
    exit(1);
  }
  if ((filew = fopen("myCwrite.bin", "wb")) == NULL) {
    fprintf(stderr, "open write file error.\n");
    exit(1);
  }
  while (feof(filer) == 0) {
    numr = fread(buffer, 1, 100, filer);
    numw = fwrite(buffer, 1, numr, filew);
    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    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11c2 <main+0x52>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe5c(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1202 <main+0x92>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1207 <main+0x97>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
jne    1282 <main+0x112>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x64,%edx
call   1030 <fread@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     127d <main+0x10d>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1207 <main+0x97>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xe7f(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1236 <main+0xc6>
mov    %rax,%rbx
lea    0xe85(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1248 <main+0xd8>
mov    %rax,%r14
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    1219 <main+0xa9>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x64,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
cmp    %ebp,%eax
je     11c0 <main+0x50>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
jmp    120a <main+0x9a>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
jmp    120a <main+0x9a>

LLVM IR (-O0):
@.str = [11 x i8] c"myCopy.bin\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 = [13 x i8] c"myCwrite.bin\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [24 x i8] c"open write file error.\0A\00"
@.str.6 = [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 [100 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 ([13 x i8], [13 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 = %40, %20
%22 = load i32*, i32** %2
%23 = call i64 @feof(i32* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %41
25: ; preds = %21
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%27 = load i32*, i32** %2
%28 = call i32 @fread(i8* %26, i32 1, i32 100, i32* %27)
store i32 %28, i32* %4
%29 = getelementptr inbounds [100 x i8], [100 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 = load i32, i32* %5
%34 = load i32, i32* %4
%35 = icmp ne i32 %33, %34
br i1 %35, label %36, label %40
36: ; preds = %25
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %25
br label %21
41: ; preds = %21
%42 = load i32*, i32** %2
%43 = call i32 @fclose(i32* %42)
%44 = load i32*, i32** %3
%45 = call i32 @fclose(i32* %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"myCopy.bin\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 = [13 x i8] c"myCwrite.bin\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [24 x i8] c"open write file error.\0A\00"
@.str.6 = [19 x i8] c"write file error.\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 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 ([13 x i8], [13 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 %27
19: ; preds = %16
%20 = call i32 @fread(i8* %2, i32 1, i32 100, i32* %3)
%21 = call i32 @fwrite(i8* %2, i32 1, i32 %20, i32* %10)
%22 = icmp eq i32 %21, %20
br i1 %22, label %16, label %23
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %16
%28 = tail call i32 @fclose(i32* %3)
%29 = tail call i32 @fclose(i32* %10)
ret i32 0
}