#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 */
int /*<<< orphan*/ sprintf(char *, char *, double);
void calculate_speed(char *speedstr, unsigned long long int newval,
                     unsigned long long int oldval) {
  double speed;
  speed = (newval - oldval) / 1024.0;
  if (speed > 1024.0) {
    speed /= 1024.0;
    sprintf(speedstr, "%.3f MB/s", speed);
  } else {
    sprintf(speedstr, "%.2f KB/s", speed);
  }
}


x86 assembly (clang, -O0):
<calculate_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xed5(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xed9(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xea2(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe8c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ae <calculate_speed+0x9e>
movsd  -0x20(%rbp),%xmm0
movsd  0xe75(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
lea    0xe8c(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11c3 <calculate_speed+0xb3>
mov    -0x8(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
lea    0xe7c(%rip),%rsi
call   1030 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_speed>:
sub    %rdx,%rsi
movq   %rsi,%xmm1
punpckldq 0xee0(%rip),%xmm1
subpd  0xee8(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xee4(%rip),%xmm0
ucomisd 0xee4(%rip),%xmm0
jbe    115a <calculate_speed+0x4a>
mulsd  0xed2(%rip),%xmm0
lea    0xedb(%rip),%rsi
jmp    1030 <sprintf@plt>
lea    0xed9(%rip),%rsi
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"%.3f MB/s\00"
@.str.1 = [10 x i8] c"%.2f KB/s\00"
define void @calculate_speed(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca double
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = load i64, i64* %5
%9 = load i64, i64* %6
%10 = sub i64 %8, %9
%11 = uitofp i64 %10 to double
%12 = fdiv double %11, 1.024000e+03
store double %12, double* %7
%13 = load double, double* %7
%14 = fcmp ogt double %13, 1.024000e+03
br i1 %14, label %15, label %21
15: ; preds = %3
%16 = load double, double* %7
%17 = fdiv double %16, 1.024000e+03
store double %17, double* %7
%18 = load i8*, i8** %4
%19 = load double, double* %7
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %19)
br label %25
21: ; preds = %3
%22 = load i8*, i8** %4
%23 = load double, double* %7
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %23)
br label %25
25: ; preds = %21, %15
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"%.3f MB/s\00"
@.str.1 = [10 x i8] c"%.2f KB/s\00"
define void @calculate_speed(i8* nocapture writeonly %0, i64 %1, i64 %2) {
%4 = sub i64 %1, %2
%5 = uitofp i64 %4 to double
%6 = fmul double %5, 0x3F50000000000000
%7 = fcmp ogt double %6, 1.024000e+03
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = fmul double %6, 0x3F50000000000000
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %9)
br label %13
11: ; preds = %3
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %6)
br label %13
13: ; preds = %11, %8
ret void
}