#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 */

/* Variables and functions */
double curtime();
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long long, double);
int fread(char *, int, int, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main() {
  long long aisz, aosz;
  double dt;
  double t0, t1, t2;
  char *buf;
  int i;
  t0 = curtime();
  aisz = 0;
  buf = malloc(1 << 20);
  while (!feof(stdin)) {
    i = fread(buf, 1, 1 << 20, stdin);
    aisz += 1 << 20;
    t1 = curtime();
    t2 = t1 - t0;
    dt = t2;
    fprintf(stderr, "%.3fMB/s %.3f   \r", (aisz / (1024.0 * 1024.0)) / dt, dt);
  }
  printf("\n");
  printf("dt=%.3fs\n", dt);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <curtime@plt>
movsd  %xmm0,-0x28(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x100000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b4 <main+0x54>
jmp    1241 <main+0xe1>
mov    -0x40(%rbp),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x100000,%edx
call   1030 <fread@plt>
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
add    $0x100000,%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1070 <curtime@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xde3(%rip),%xmm1
divsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%rdx
movsd  -0x20(%rbp),%xmm0
lea    0xdd1(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1191 <main+0x31>
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x20(%rbp),%xmm0
lea    0xdbf(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <curtime@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x100000,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    0x2e4a(%rip),%r12
mov    (%r12),%edi
call   1070 <feof@plt>
test   %eax,%eax
jne    1221 <main+0xb1>
mov    $0x100000,%ebx
mov    0x2e21(%rip),%r13
lea    0xe4a(%rip),%r14
xchg   %ax,%ax
mov    (%r12),%ecx
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
call   1040 <fread@plt>
xor    %eax,%eax
call   1080 <curtime@plt>
subsd  0x8(%rsp),%xmm0
mov    0x0(%r13),%edi
xorps  %xmm1,%xmm1
cvtsi2sd %rbx,%xmm1
mulsd  0xe09(%rip),%xmm1
divsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rdx
mov    %r14,%rsi
movsd  %xmm0,(%rsp)
call   1060 <fprintf@plt>
mov    (%r12),%edi
call   1070 <feof@plt>
add    $0x100000,%rbx
test   %eax,%eax
je     11c0 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xde8(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"%.3fMB/s %.3f \0D\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [10 x i8] c"dt=%.3fs\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %1
%10 = call double (...) @curtime()
store double %10, double* %5
store i64 0, i64* %2
%11 = call i8* @malloc(i32 1048576)
store i8* %11, i8** %8
br label %12
12: ; preds = %17, %0
%13 = load i32, i32* @stdin
%14 = call i32 @feof(i32 %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %37
17: ; preds = %12
%18 = load i8*, i8** %8
%19 = load i32, i32* @stdin
%20 = call i32 @fread(i8* %18, i32 1, i32 1048576, i32 %19)
store i32 %20, i32* %9
%21 = load i64, i64* %2
%22 = add nsw i64 %21, 1048576
store i64 %22, i64* %2
%23 = call double (...) @curtime()
store double %23, double* %6
%24 = load double, double* %6
%25 = load double, double* %5
%26 = fsub double %24, %25
store double %26, double* %7
%27 = load double, double* %7
store double %27, double* %4
%28 = load i32, i32* @stderr
%29 = load i64, i64* %2
%30 = sitofp i64 %29 to double
%31 = fdiv double %30, 0x4130000000000000
%32 = load double, double* %4
%33 = fdiv double %31, %32
%34 = fptosi double %33 to i64
%35 = load double, double* %4
%36 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %34, double %35)
br label %12
37: ; preds = %12
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%39 = load double, double* %4
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %39)
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"%.3fMB/s %.3f \0D\00"
@.str.2 = [10 x i8] c"dt=%.3fs\0A\00"
define i32 @main() {
%1 = tail call double (...) @curtime()
%2 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%3 = load i32, i32* @stdin
%4 = tail call i32 @feof(i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %22
6: ; preds = %0, %6
%7 = phi i64 [ %10, %6 ], [ 0, %0 ]
%8 = load i32, i32* @stdin
%9 = tail call i32 @fread(i8* %2, i32 1, i32 1048576, i32 %8)
%10 = add nuw nsw i64 %7, 1048576
%11 = tail call double (...) @curtime()
%12 = fsub double %11, %1
%13 = load i32, i32* @stderr
%14 = sitofp i64 %10 to double
%15 = fmul double %14, 0x3EB0000000000000
%16 = fdiv double %15, %12
%17 = fptosi double %16 to i64
%18 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %17, double %12)
%19 = load i32, i32* @stdin
%20 = tail call i32 @feof(i32 %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %6, label %22
22: ; preds = %6, %0
%23 = phi double [ undef, %0 ], [ %12, %6 ]
%24 = tail call i32 @putchar(i32 10)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %23)
ret i32 0
}