#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int copy_file(FILE *fin, FILE *fout) {
  char buffer[100];
  int numr, numw;
  while (feof(fin) == 0) {
    if ((numr = fread(buffer, 1, sizeof(buffer), fin)) != sizeof(buffer)) {
      if (ferror(fin) != 0) {
        return -1;
      }
    }
    if ((numw = fwrite(buffer, 1, numr, fout)) != numr) {
      fprintf(stderr, "write file error.\n");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
jne    1213 <copy_file+0xc3>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x64,%edx
call   1040 <fread@plt>
mov    %eax,-0x84(%rbp)
cltq
cmp    $0x64,%rax
je     11c3 <copy_file+0x73>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11be <copy_file+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <copy_file+0xca>
jmp    11c3 <copy_file+0x73>
lea    -0x80(%rbp),%rdi
mov    -0x84(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    %eax,-0x88(%rbp)
cmp    -0x84(%rbp),%eax
je     120e <copy_file+0xbe>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <copy_file+0xca>
jmp    1163 <copy_file+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%r15
jmp    1186 <copy_file+0x36>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
cmp    %ebp,%eax
jne    11be <copy_file+0x6e>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    11da <copy_file+0x8a>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x64,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
cmp    $0x64,%eax
je     1170 <copy_file+0x20>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1170 <copy_file+0x20>
jmp    11d3 <copy_file+0x83>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    11dc <copy_file+0x8c>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"write file error.\0A\00"
define i32 @copy_file(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
br label %9
9: ; preds = %35, %2
%10 = load i32*, i32** %4
%11 = call i64 @feof(i32* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %36
13: ; preds = %9
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i32 @fread(i8* %14, i32 1, i32 100, i32* %15)
store i32 %16, i32* %7
%17 = sext i32 %16 to i64
%18 = icmp ne i64 %17, 100
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = load i32*, i32** %4
%21 = call i64 @ferror(i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 -1, i32* %3
br label %37
24: ; preds = %19
br label %25
25: ; preds = %24, %13
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%27 = load i32, i32* %7
%28 = load i32*, i32** %5
%29 = call i32 @fwrite(i8* %26, i32 1, i32 %27, i32* %28)
store i32 %29, i32* %8
%30 = load i32, i32* %7
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %37
35: ; preds = %25
br label %9
36: ; preds = %9
store i32 0, i32* %3
br label %37
37: ; preds = %36, %32, %23
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"write file error.\0A\00"
define i32 @copy_file(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %14, %2
%6 = tail call i64 @feof(i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = call i32 @fread(i8* %4, i32 1, i32 100, i32* %0)
%10 = icmp eq i32 %9, 100
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i64 @ferror(i32* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11, %8
%15 = call i32 @fwrite(i8* %4, i32 1, i32 %9, i32* %1)
%16 = icmp eq i32 %15, %9
br i1 %16, label %5, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %5, %11, %17
%21 = phi i32 [ -1, %17 ], [ 0, %5 ], [ -1, %11 ]
ret i32 %21
}