#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, double);
int main(int argc, char *argv[]) {
  FILE *fp1;
  FILE *fp2;
  char buf[128];
  clock_t start, stop;
  double duration;
  fp1 = fopen("news.txt", "r");
  fp2 = fopen("copy2.txt", "w");
  start = clock();
  while (fgets(buf, 128, fp1) != NULL)
    fputs(buf, fp2);
  stop = clock();
  duration = (double)(stop - start) / CLOCKS_PER_SEC;
  printf("used time: %f\n", duration);
  fclose(fp1);
  fclose(fp2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe74(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     11e9 <main+0x89>
lea    -0xa0(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <fputs@plt>
jmp    11b5 <main+0x55>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0xb0(%rbp)
mov    -0xb0(%rbp),%rax
sub    -0xa8(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2dd7(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0xb8(%rbp),%xmm0
ff
lea    0xdeb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
lea    0xe8b(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0xe80(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11e0 <main+0x80>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <fputs@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r15,%rax
cvtsi2sd %rax,%xmm0
mov    0x2df2(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe16(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"news.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"copy2.txt\00"
@.str.3 = [2 x i8] c"w\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.4 = [15 x i8] c"used time: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [128 x i8]
%9 = alloca i64
%10 = alloca i64
%11 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %6
%13 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %13, i32** %7
%14 = call i64 (...) @clock()
store i64 %14, i64* %9
br label %15
15: ; preds = %20, %2
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%17 = load i32*, i32** %6
%18 = call i32* @fgets(i8* %16, i32 128, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%22 = load i32*, i32** %7
%23 = call i32 @fputs(i8* %21, i32* %22)
br label %15
24: ; preds = %15
%25 = call i64 (...) @clock()
store i64 %25, i64* %10
%26 = load i64, i64* %10
%27 = load i64, i64* %9
%28 = sub nsw i64 %26, %27
%29 = sitofp i64 %28 to double
%30 = load double, double* @CLOCKS_PER_SEC
%31 = fdiv double %29, %30
store double %31, double* %11
%32 = load double, double* %11
%33 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), double %32)
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
%36 = load i32*, i32** %7
%37 = call i32 @fclose(i32* %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"news.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"copy2.txt\00"
@.str.3 = [2 x i8] c"w\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.4 = [15 x i8] c"used time: %f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i64 (...) @clock()
%8 = call i32* @fgets(i8* %4, i32 128, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %2, %10
%11 = call i32 @fputs(i8* %4, i32* %6)
%12 = call i32* @fgets(i8* %4, i32 128, i32* %5)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %10
14: ; preds = %10, %2
%15 = call i64 (...) @clock()
%16 = sub nsw i64 %15, %7
%17 = sitofp i64 %16 to double
%18 = load double, double* @CLOCKS_PER_SEC
%19 = fdiv double %17, %18
%20 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), double %19)
%21 = call i32 @fclose(i32* %5)
%22 = call i32 @fclose(i32* %6)
ret i32 0
}