#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 {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
void show_results(struct timeval *start, struct timeval *end, int nbufs,
                  int buflen) {
  struct timeval tot_time;
  long tot_bytes = nbufs * buflen;
  double real_time, thru;
  timersub(end, start, &tot_time);
  printf("SOURCE complete - %d bufs of %d bytes in %ld.%02ld seconds", nbufs,
         buflen, tot_time.tv_sec, tot_time.tv_usec / 10000);
  real_time = tot_time.tv_sec + ((tot_time.tv_usec / 10000) * .01);
  thru = tot_bytes / real_time;
  printf(" - %.2f KB/S", thru / 1024.0);
  printf(" - %.4f Mbit/S (M = 10^6)", thru * 8.0 / 1000000.0);
  printf("\n");
}


x86 assembly (clang, -O0):
<show_results>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <timersub@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%eax
mov    $0x2710,%edi
cltd
idiv   %edi
mov    -0x3c(%rbp),%edx
mov    %eax,%r8d
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cvtsi2sdl -0x20(%rbp),%xmm1
mov    -0x1c(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  0xe7d(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdq -0x28(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe4b(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe8b(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0xe29(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  0xe14(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe71(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_results>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rdi,%rax
mov    %ecx,%ebx
imul   %edx,%ebx
mov    %rsp,%rdx
mov    %rsi,%rdi
mov    %rax,%rsi
call   1050 <timersub@plt>
mov    (%rsp),%ecx
movslq 0x4(%rsp),%rax
imul   $0x68db8bad,%rax,%r8
mov    %r8,%rax
shr    $0x3f,%rax
sar    $0x2c,%r8
add    %eax,%r8d
lea    0xea9(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cvtsi2sdl (%rsp),%xmm0
movslq 0x4(%rsp),%rax
imul   $0x68db8bad,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%rax
add    %ecx,%eax
cvtsi2sd %eax,%xmm1
mulsd  0xe53(%rip),%xmm1
cvtsi2sd %ebx,%xmm2
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  0xe41(%rip),%xmm0
mulsd  %xmm2,%xmm0
lea    0xe89(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
mulsd  0xe29(%rip),%xmm0
divsd  0xe29(%rip),%xmm0
lea    0xe72(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [59 x i8] c"SOURCE complete - %d bufs of %d bytes in %ld.%02ld seconds\00"
@.str.1 = [13 x i8] c" - %.2f KB/S\00"
@.str.2 = [26 x i8] c" - %.4f Mbit/S (M = 10^6)\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @show_results(%struct.timeval* %0, %struct.timeval* %1, i32 %2, i32 %3) {
%5 = alloca %struct.timeval*
%6 = alloca %struct.timeval*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.timeval
%10 = alloca i64
%11 = alloca double
%12 = alloca double
store %struct.timeval* %0, %struct.timeval** %5
store %struct.timeval* %1, %struct.timeval** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = mul nsw i32 %13, %14
%16 = sext i32 %15 to i64
store i64 %16, i64* %10
%17 = load %struct.timeval*, %struct.timeval** %6
%18 = load %struct.timeval*, %struct.timeval** %5
%19 = call i32 @timersub(%struct.timeval* %17, %struct.timeval* %18, %struct.timeval* %9)
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%25 = load i32, i32* %24
%26 = sdiv i32 %25, 10000
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21, i32 %23, i32 %26)
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%29 = load i32, i32* %28
%30 = sitofp i32 %29 to double
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%32 = load i32, i32* %31
%33 = sdiv i32 %32, 10000
%34 = sitofp i32 %33 to double
%35 = call double @llvm.fmuladd.f64(double %34, double 1.000000e-02, double %30)
store double %35, double* %11
%36 = load i64, i64* %10
%37 = sitofp i64 %36 to double
%38 = load double, double* %11
%39 = fdiv double %37, %38
store double %39, double* %12
%40 = load double, double* %12
%41 = fdiv double %40, 1.024000e+03
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %41)
%43 = load double, double* %12
%44 = fmul double %43, 8.000000e+00
%45 = fdiv double %44, 1.000000e+06
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), double %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [59 x i8] c"SOURCE complete - %d bufs of %d bytes in %ld.%02ld seconds\00"
@.str.1 = [13 x i8] c" - %.2f KB/S\00"
@.str.2 = [26 x i8] c" - %.4f Mbit/S (M = 10^6)\00"
define void @show_results(%struct.timeval* %0, %struct.timeval* %1, i32 %2, i32 %3) {
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %5 to i8*
%7 = mul nsw i32 %3, %2
%8 = call i32 @timersub(%struct.timeval* %1, %struct.timeval* %0, %struct.timeval* %5)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%12 = load i32, i32* %11
%13 = sdiv i32 %12, 10000
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3, i32 %10, i32 %13)
%15 = load i32, i32* %9
%16 = sitofp i32 %15 to double
%17 = load i32, i32* %11
%18 = sdiv i32 %17, 10000
%19 = sitofp i32 %18 to double
%20 = call double @llvm.fmuladd.f64(double %19, double 1.000000e-02, double %16)
%21 = sitofp i32 %7 to double
%22 = fdiv double %21, %20
%23 = fmul double %22, 0x3F50000000000000
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %23)
%25 = fmul double %22, 8.000000e+00
%26 = fdiv double %25, 1.000000e+06
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), double %26)
%28 = call i32 @putchar(i32 10)
ret void
}