#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 */
struct timeval {
  double tv_sec;
  double tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, double);
void show_performance(struct timeval *start, struct timeval *end, int size) {
  double ssec = start->tv_sec + start->tv_usec / 1000000.0;
  double esec = end->tv_sec + end->tv_usec / 1000000.0;
  double bytes = (double)size;
  double bsec = bytes / (esec - ssec);
  printf("Time used: %.2lf seconds ==> ", esec - ssec);
  if (bsec / 1000000 > 1.0)
    printf("%.3lf MB/s\n", bsec / 1000000);
  else if (bsec / 1000 > 1.0)
    printf("%.3lf kB/s\n", bsec / 1000);
  else
    printf("%.3lf B/s\n", bsec);
}


x86 assembly (clang, -O0):
<show_performance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  0xecc(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  0xea6(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x38(%rbp),%xmm0
movsd  0xe54(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe40(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ec <show_performance+0xdc>
movsd  -0x38(%rbp),%xmm0
movsd  0xe31(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
jmp    1247 <show_performance+0x137>
movsd  -0x38(%rbp),%xmm0
movsd  0xe17(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xdfb(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1231 <show_performance+0x121>
movsd  -0x38(%rbp),%xmm0
movsd  0xdf4(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
jmp    1242 <show_performance+0x132>
movsd  -0x38(%rbp),%xmm0
lea    0xe11(%rip),%rdi
call   1030 <printf@plt>
jmp    1247 <show_performance+0x137>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_performance>:
push   %rax
movsd  (%rsi),%xmm0
movsd  0x8(%rsi),%xmm1
movhpd 0x8(%rdi),%xmm1
divpd  0xed9(%rip),%xmm1
movhpd (%rdi),%xmm0
cvtsi2sd %edx,%xmm2
addpd  %xmm1,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
subsd  %xmm1,%xmm0
divsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
lea    0xed9(%rip),%rdi
call   1030 <printf@plt>
movsd  (%rsp),%xmm1
movapd %xmm1,%xmm0
divsd  0xeab(%rip),%xmm0
ucomisd 0xeab(%rip),%xmm0
jbe    117c <show_performance+0x6c>
lea    0xed0(%rip),%rdi
pop    %rax
jmp    1030 <printf@plt>
movapd %xmm1,%xmm0
divsd  0xe98(%rip),%xmm0
ucomisd 0xe88(%rip),%xmm0
jbe    119f <show_performance+0x8f>
lea    0xeb9(%rip),%rdi
pop    %rax
jmp    1030 <printf@plt>
lea    0xeb8(%rip),%rdi
movapd %xmm1,%xmm0
pop    %rax
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.timeval = type { double, double }
@.str = [30 x i8] c"Time used: %.2lf seconds ==> \00"
@.str.1 = [12 x i8] c"%.3lf MB/s\0A\00"
@.str.2 = [12 x i8] c"%.3lf kB/s\0A\00"
@.str.3 = [11 x i8] c"%.3lf B/s\0A\00"
define void @show_performance(%struct.timeval* %0, %struct.timeval* %1, i32 %2) {
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store %struct.timeval* %0, %struct.timeval** %4
store %struct.timeval* %1, %struct.timeval** %5
store i32 %2, i32* %6
%11 = load %struct.timeval*, %struct.timeval** %4
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%13 = load double, double* %12
%14 = load %struct.timeval*, %struct.timeval** %4
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%16 = load double, double* %15
%17 = fdiv double %16, 1.000000e+06
%18 = fadd double %13, %17
store double %18, double* %7
%19 = load %struct.timeval*, %struct.timeval** %5
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 0
%21 = load double, double* %20
%22 = load %struct.timeval*, %struct.timeval** %5
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
%24 = load double, double* %23
%25 = fdiv double %24, 1.000000e+06
%26 = fadd double %21, %25
store double %26, double* %8
%27 = load i32, i32* %6
%28 = sitofp i32 %27 to double
store double %28, double* %9
%29 = load double, double* %9
%30 = load double, double* %8
%31 = load double, double* %7
%32 = fsub double %30, %31
%33 = fdiv double %29, %32
store double %33, double* %10
%34 = load double, double* %8
%35 = load double, double* %7
%36 = fsub double %34, %35
%37 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), double %36)
%38 = load double, double* %10
%39 = fdiv double %38, 1.000000e+06
%40 = fcmp ogt double %39, 1.000000e+00
br i1 %40, label %41, label %45
41: ; preds = %3
%42 = load double, double* %10
%43 = fdiv double %42, 1.000000e+06
%44 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %43)
br label %57
45: ; preds = %3
%46 = load double, double* %10
%47 = fdiv double %46, 1.000000e+03
%48 = fcmp ogt double %47, 1.000000e+00
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = load double, double* %10
%51 = fdiv double %50, 1.000000e+03
%52 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %51)
br label %56
53: ; preds = %45
%54 = load double, double* %10
%55 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %54)
br label %56
56: ; preds = %53, %49
br label %57
57: ; preds = %56, %41
ret void
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@.str = [30 x i8] c"Time used: %.2lf seconds ==> \00"
@.str.1 = [12 x i8] c"%.3lf MB/s\0A\00"
@.str.2 = [12 x i8] c"%.3lf kB/s\0A\00"
@.str.3 = [11 x i8] c"%.3lf B/s\0A\00"
define void @show_performance(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1, i32 %2) {
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%5 = load double, double* %4
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%7 = load double, double* %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%9 = load double, double* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%11 = load double, double* %10
%12 = insertelement <2 x double> poison, double %11, i64 0
%13 = insertelement <2 x double> %12, double %7, i64 1
%14 = fdiv <2 x double> %13, <double 1.000000e+06, double 1.000000e+06>
%15 = insertelement <2 x double> poison, double %9, i64 0
%16 = insertelement <2 x double> %15, double %5, i64 1
%17 = fadd <2 x double> %16, %14
%18 = sitofp i32 %2 to double
%19 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%20 = fsub <2 x double> %17, %19
%21 = extractelement <2 x double> %20, i64 0
%22 = fdiv double %18, %21
%23 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), double %21)
%24 = fdiv double %22, 1.000000e+06
%25 = fcmp ogt double %24, 1.000000e+00
br i1 %25, label %26, label %28
26: ; preds = %3
%27 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %24)
br label %35
28: ; preds = %3
%29 = fdiv double %22, 1.000000e+03
%30 = fcmp ogt double %29, 1.000000e+00
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %29)
br label %35
33: ; preds = %28
%34 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %22)
br label %35
35: ; preds = %31, %33, %26
ret void
}