#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 time_t;
struct timeval {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, int);
int /*<<< orphan*/ stderr;
int time(int /*<<< orphan*/ *);
void speed_statistics(int bytes) {
  static time_t last_clock;
  static int bytes_since_clock = 0;
  struct timeval t;
  if (!last_clock)
    last_clock = time(NULL);
  bytes_since_clock += bytes;
  if (bytes_since_clock > 10 * 1000 * 1000) {
    time_t cur = time(NULL);
    fprintf(stderr, "Last %d MB in %d seconds at %d kbps\n",
            bytes_since_clock / 1000 / 1000, (int)(cur - last_clock),
            (int)((bytes_since_clock / 1024) / (cur - last_clock)));
    last_clock = cur;
    bytes_since_clock = 0;
  }
}


x86 assembly (clang, -O0):
<speed_statistics>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,0x2f02(%rip)
jne    1147 <speed_statistics+0x27>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,0x2eed(%rip)
mov    -0x4(%rbp),%eax
add    0x2ee8(%rip),%eax
mov    %eax,0x2ee2(%rip)
cmpl   $0x989680,0x2ed8(%rip)
jle    11dc <speed_statistics+0xbc>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    0x2eb7(%rip),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%ecx
sub    0x2e97(%rip),%ecx
mov    0x2e95(%rip),%eax
mov    $0x400,%esi
cltd
idiv   %esi
mov    -0xc(%rbp),%esi
sub    0x2e80(%rip),%esi
cltd
idiv   %esi
mov    -0x10(%rbp),%edx
mov    %eax,%r8d
lea    0xe3c(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,0x2e62(%rip)
movl   $0x0,0x2e5c(%rip)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<speed_statistics>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
cmpl   $0x0,0x2f08(%rip)
jne    113b <speed_statistics+0x1b>
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0x2ef9(%rip)
add    0x2ef7(%rip),%ebx
mov    %ebx,0x2ef1(%rip)
cmp    $0x989681,%ebx
jl     11b7 <speed_statistics+0x97>
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%ebp
mov    0x2e81(%rip),%rdx
movslq 0x2ed2(%rip),%rsi
imul   $0x431bde83,%rsi,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x32,%rbx
add    %eax,%ebx
mov    %ebp,%ecx
sub    0x2eb2(%rip),%ecx
lea    0x3ff(%rsi),%eax
test   %rsi,%rsi
cmovns %esi,%eax
mov    (%rdx),%edi
sar    $0xa,%eax
cltd
idiv   %ecx
lea    0xe63(%rip),%rsi
mov    %ebx,%edx
mov    %eax,%r8d
call   1030 <fprintf@plt>
mov    %ebp,0x2e87(%rip)
movl   $0x0,0x2e81(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@speed_statistics.last_clock = internal global i32 0
@speed_statistics.bytes_since_clock = internal global i32 0
@stderr = global i32 0
@.str = [37 x i8] c"Last %d MB in %d seconds at %d kbps\0A\00"
define void @speed_statistics(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* @speed_statistics.last_clock
%6 = icmp ne i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32 @time(i32* null)
store i32 %8, i32* @speed_statistics.last_clock
br label %9
9: ; preds = %7, %1
%10 = load i32, i32* %2
%11 = load i32, i32* @speed_statistics.bytes_since_clock
%12 = add nsw i32 %11, %10
store i32 %12, i32* @speed_statistics.bytes_since_clock
%13 = load i32, i32* @speed_statistics.bytes_since_clock
%14 = icmp sgt i32 %13, 10000000
br i1 %14, label %15, label %32
15: ; preds = %9
%16 = call i32 @time(i32* null)
store i32 %16, i32* %4
%17 = load i32, i32* @stderr
%18 = load i32, i32* @speed_statistics.bytes_since_clock
%19 = sdiv i32 %18, 1000
%20 = sdiv i32 %19, 1000
%21 = load i32, i32* %4
%22 = load i32, i32* @speed_statistics.last_clock
%23 = sub nsw i32 %21, %22
%24 = load i32, i32* @speed_statistics.bytes_since_clock
%25 = sdiv i32 %24, 1024
%26 = load i32, i32* %4
%27 = load i32, i32* @speed_statistics.last_clock
%28 = sub nsw i32 %26, %27
%29 = sdiv i32 %25, %28
%30 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %23, i32 %29)
%31 = load i32, i32* %4
store i32 %31, i32* @speed_statistics.last_clock
store i32 0, i32* @speed_statistics.bytes_since_clock
br label %32
32: ; preds = %15, %9
ret void
}

LLVM IR (-O2):
@speed_statistics.last_clock = internal unnamed_addr global i32 0
@speed_statistics.bytes_since_clock = internal unnamed_addr global i32 0
@stderr = global i32 0
@.str = [37 x i8] c"Last %d MB in %d seconds at %d kbps\0A\00"
define void @speed_statistics(i32 %0) {
%2 = load i32, i32* @speed_statistics.last_clock
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* @speed_statistics.last_clock
br label %6
6: ; preds = %4, %1
%7 = load i32, i32* @speed_statistics.bytes_since_clock
%8 = add nsw i32 %7, %0
store i32 %8, i32* @speed_statistics.bytes_since_clock
%9 = icmp sgt i32 %8, 10000000
br i1 %9, label %10, label %20
10: ; preds = %6
%11 = tail call i32 @time(i32* null)
%12 = load i32, i32* @stderr
%13 = load i32, i32* @speed_statistics.bytes_since_clock
%14 = sdiv i32 %13, 1000000
%15 = load i32, i32* @speed_statistics.last_clock
%16 = sub nsw i32 %11, %15
%17 = sdiv i32 %13, 1024
%18 = sdiv i32 %17, %16
%19 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %16, i32 %18)
store i32 %11, i32* @speed_statistics.last_clock
store i32 0, i32* @speed_statistics.bytes_since_clock
br label %20
20: ; preds = %10, %6
ret void
}