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

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
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 *, double);
int /*<<< orphan*/ stderr;
main() {
  FILE *filer;
  FILE *filew;
  int numr, numw;
  char buffer[100];
  clock_t begin, end;
  double time_spent;
  begin = clock();
  if ((filer = fopen("big_text.txt", "rb")) == NULL) {
    fprintf(stderr, "open read file error.\n");
    exit(1);
  }
  if ((filew = fopen("big_text_bin.txt", "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);
  end = clock();
  time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("%f", time_spent);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x98(%rbp)
lea    0xe49(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11f0 <main+0x60>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe30(%rip),%rdi
lea    0xe3a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1230 <main+0xa0>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1235 <main+0xa5>
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
jne    12b0 <main+0x120>
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   10b0 <fwrite@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     12ab <main+0x11b>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1235 <main+0xa5>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0xa0(%rbp)
mov    -0xa0(%rbp),%rax
sub    -0x98(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2cfe(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0xa8(%rbp),%xmm0
ff
lea    0xd4e(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
lea    0xe53(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     128e <main+0xfe>
mov    %rax,%rbx
lea    0xe5b(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12a0 <main+0x110>
mov    %rax,%r15
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    1249 <main+0xb9>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x64,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %r12,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   10b0 <fwrite@plt>
cmp    %ebp,%eax
je     11f0 <main+0x60>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
cvtsi2sd %rax,%xmm0
mov    0x2d79(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdd9(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xd72(%rip),%rsi
jmp    123a <main+0xaa>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
lea    0xd8b(%rip),%rsi
jmp    123a <main+0xaa>

LLVM IR (-O0):
@.str = [13 x i8] c"big_text.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 = [17 x i8] c"big_text_bin.txt\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"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.7 = [3 x i8] c"%f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca i64
%8 = alloca i64
%9 = alloca double
store i32 0, i32* %1
%10 = call i64 (...) @clock()
store i64 %10, i64* %7
%11 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 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* %18, i32** %3
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %17
br label %25
25: ; preds = %44, %24
%26 = load i32*, i32** %2
%27 = call i64 @feof(i32* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %45
29: ; preds = %25
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%31 = load i32*, i32** %2
%32 = call i32 @fread(i8* %30, i32 1, i32 100, i32* %31)
store i32 %32, i32* %4
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%34 = load i32, i32* %4
%35 = load i32*, i32** %3
%36 = call i32 @fwrite(i8* %33, i32 1, i32 %34, i32* %35)
store i32 %36, i32* %5
%37 = load i32, i32* %5
%38 = load i32, i32* %4
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %44
40: ; preds = %29
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %29
br label %25
45: ; preds = %25
%46 = load i32*, i32** %2
%47 = call i32 @fclose(i32* %46)
%48 = load i32*, i32** %3
%49 = call i32 @fclose(i32* %48)
%50 = call i64 (...) @clock()
store i64 %50, i64* %8
%51 = load i64, i64* %8
%52 = load i64, i64* %7
%53 = sub nsw i64 %51, %52
%54 = sitofp i64 %53 to double
%55 = load double, double* @CLOCKS_PER_SEC
%56 = fdiv double %54, %55
store double %56, double* %9
%57 = load double, double* %9
%58 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), double %57)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"big_text.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 = [17 x i8] c"big_text_bin.txt\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"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.7 = [3 x i8] c"%f\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 i64 (...) @clock()
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10, %20
%18 = tail call i64 @feof(i32* %4)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = call i32 @fread(i8* %2, i32 1, i32 100, i32* %4)
%22 = call i32 @fwrite(i8* %2, i32 1, i32 %21, i32* %11)
%23 = icmp eq i32 %22, %21
br i1 %23, label %17, label %24
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %17
%29 = tail call i32 @fclose(i32* %4)
%30 = tail call i32 @fclose(i32* %11)
%31 = tail call i64 (...) @clock()
%32 = sub nsw i64 %31, %3
%33 = sitofp i64 %32 to double
%34 = load double, double* @CLOCKS_PER_SEC
%35 = fdiv double %33, %34
%36 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), double %35)
ret i32 0
}