#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;
char EOF;
scalar_t__ clock();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *filer;
  FILE *filew;
  char ch;
  clock_t begin, end;
  double time_spent;
  begin = clock();
  filer = fopen("big_text.txt", "r");
  if (filer == NULL) {
    printf("Cannot open file.\n");
    exit(1);
  }
  filew = fopen("big_text_copy.txt", "w");
  if (filew == NULL) {
    printf("Cannot open file.\n");
    exit(1);
  }
  int i;
  while ((ch = fgetc(filer)) != EOF) {
    fputc(ch, filew);
  }
  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    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x28(%rbp)
lea    0xe6f(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c4 <main+0x54>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe57(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fe <main+0x8e>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1203 <main+0x93>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2dc7(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1238 <main+0xc8>
mov    -0x19(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
jmp    1203 <main+0x93>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d7f(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xdb8(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
lea    0xe67(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     124f <main+0xcf>
mov    %rax,%r15
lea    0xe57(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     124f <main+0xcf>
mov    %rax,%rbx
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    0x2e01(%rip),%r12
cmp    (%r12),%al
je     1209 <main+0x89>
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%edi
mov    %rbx,%rsi
call   1080 <fputc@plt>
mov    %r15,%rdi
call   1070 <fgetc@plt>
cmp    (%r12),%al
jne    11f0 <main+0x70>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
cvtsi2sd %rax,%xmm0
mov    0x2db9(%rip),%rax
divsd  (%rax),%xmm0
lea    0xde9(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdd0(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"big_text.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Cannot open file.\0A\00"
@.str.3 = [18 x i8] c"big_text_copy.txt\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = global i8 0
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.5 = [3 x i8] c"%f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i64
%6 = alloca i64
%7 = alloca double
%8 = alloca i32
store i32 0, i32* %1
%9 = call i64 (...) @clock()
store i64 %9, i64* %5
%10 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %2
%11 = load i32*, i32** %2
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %17, i32** %3
%18 = load i32*, i32** %3
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %16
br label %24
24: ; preds = %31, %23
%25 = load i32*, i32** %2
%26 = call signext i8 @fgetc(i32* %25)
store i8 %26, i8* %4
%27 = sext i8 %26 to i32
%28 = load i8, i8* @EOF
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %27, %29
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = load i8, i8* %4
%33 = load i32*, i32** %3
%34 = call i32 @fputc(i8 signext %32, i32* %33)
br label %24
35: ; preds = %24
%36 = load i32*, i32** %2
%37 = call i32 @fclose(i32* %36)
%38 = load i32*, i32** %3
%39 = call i32 @fclose(i32* %38)
%40 = call i64 (...) @clock()
store i64 %40, i64* %6
%41 = load i64, i64* %6
%42 = load i64, i64* %5
%43 = sub nsw i64 %41, %42
%44 = sitofp i64 %43 to double
%45 = load double, double* @CLOCKS_PER_SEC
%46 = fdiv double %44, %45
store double %46, double* %7
%47 = load double, double* %7
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), double %47)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"big_text.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [18 x i8] c"big_text_copy.txt\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = global i8 0
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.5 = [3 x i8] c"%f\00"
@str.6 = [18 x i8] c"Cannot open file.\00"
define i32 @main() {
%1 = tail call i64 (...) @clock()
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call signext i8 @fgetc(i32* %2)
%12 = load i8, i8* @EOF
%13 = icmp eq i8 %11, %12
br i1 %13, label %23, label %17
14: ; preds = %7
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10, %17
%18 = phi i8 [ %20, %17 ], [ %11, %10 ]
%19 = tail call i32 @fputc(i8 signext %18, i32* %8)
%20 = tail call signext i8 @fgetc(i32* %2)
%21 = load i8, i8* @EOF
%22 = icmp eq i8 %20, %21
br i1 %22, label %23, label %17
23: ; preds = %17, %10
%24 = tail call i32 @fclose(i32* %2)
%25 = tail call i32 @fclose(i32* %8)
%26 = tail call i64 (...) @clock()
%27 = sub nsw i64 %26, %1
%28 = sitofp i64 %27 to double
%29 = load double, double* @CLOCKS_PER_SEC
%30 = fdiv double %28, %29
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), double %30)
ret i32 0
}