#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(const char *msg, struct timeval *start, struct timeval *end,
                  int nbufs, int buflen, int lost, int seq_errors) {
  struct timeval tot_time;
  double real_time, thru;
  long tot_bytes = nbufs * buflen;
  timersub(end, start, &tot_time);
  printf("%s - %d bufs of %d bytes in %d.%02d seconds", msg, 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);
  if (lost) {
    printf(", %d lost", lost);
  }
  if (seq_errors) {
    printf(", %d out of sequence", seq_errors);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<show_results>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x20(%rbp),%eax
cltq
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <timersub@plt>
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x2c(%rbp),%eax
mov    $0x2710,%edi
cltd
idiv   %edi
mov    -0x4c(%rbp),%edx
mov    %eax,%r9d
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cvtsi2sdl -0x30(%rbp),%xmm1
mov    -0x2c(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  0xe6c(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdq -0x48(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xe3a(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe6b(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0xe18(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  0xe03(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe51(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x24(%rbp)
je     122a <show_results+0x10a>
mov    -0x24(%rbp),%esi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,0x10(%rbp)
je     1245 <show_results+0x125>
mov    0x10(%rbp),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_results>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r15d
mov    %r8d,%r13d
mov    %ecx,%ebp
mov    %rdx,%rax
mov    %rdi,%r12
mov    0x50(%rsp),%r14d
mov    %r8d,%ebx
imul   %ecx,%ebx
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1050 <timersub@plt>
mov    0x8(%rsp),%r8d
movslq 0xc(%rsp),%rax
imul   $0x68db8bad,%rax,%r9
mov    %r9,%rax
shr    $0x3f,%rax
sar    $0x2c,%r9
add    %eax,%r9d
lea    0xe96(%rip),%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
cvtsi2sdl 0x8(%rsp),%xmm0
movslq 0xc(%rsp),%rax
imul   $0x68db8bad,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%rax
add    %ecx,%eax
cvtsi2sd %eax,%xmm1
mulsd  0xe3c(%rip),%xmm1
cvtsi2sd %ebx,%xmm2
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%rsp)
movsd  0xe2a(%rip),%xmm0
mulsd  %xmm2,%xmm0
lea    0xe63(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x10(%rsp),%xmm0
mulsd  0xe12(%rip),%xmm0
divsd  0xe12(%rip),%xmm0
lea    0xe4c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
test   %r15d,%r15d
je     122a <show_results+0xfa>
lea    0xe53(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
je     1240 <show_results+0x110>
lea    0xe47(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [44 x i8] c"%s - %d bufs of %d bytes in %d.%02d 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 = [10 x i8] c", %d lost\00"
@.str.4 = [21 x i8] c", %d out of sequence\00"
@.str.5 = [2 x i8] c"\0A\00"
define void @show_results(i8* %0, %struct.timeval* %1, %struct.timeval* %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i8*
%9 = alloca %struct.timeval*
%10 = alloca %struct.timeval*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.timeval
%16 = alloca double
%17 = alloca double
%18 = alloca i64
store i8* %0, i8** %8
store %struct.timeval* %1, %struct.timeval** %9
store %struct.timeval* %2, %struct.timeval** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%19 = load i32, i32* %11
%20 = load i32, i32* %12
%21 = mul nsw i32 %19, %20
%22 = sext i32 %21 to i64
store i64 %22, i64* %18
%23 = load %struct.timeval*, %struct.timeval** %10
%24 = load %struct.timeval*, %struct.timeval** %9
%25 = call i32 @timersub(%struct.timeval* %23, %struct.timeval* %24, %struct.timeval* %15)
%26 = load i8*, i8** %8
%27 = load i32, i32* %11
%28 = load i32, i32* %12
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%32 = load i32, i32* %31
%33 = sdiv i32 %32, 10000
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %26, i32 %27, i32 %28, i32 %30, i32 %33)
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%36 = load i32, i32* %35
%37 = sitofp i32 %36 to double
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%39 = load i32, i32* %38
%40 = sdiv i32 %39, 10000
%41 = sitofp i32 %40 to double
%42 = call double @llvm.fmuladd.f64(double %41, double 1.000000e-02, double %37)
store double %42, double* %16
%43 = load i64, i64* %18
%44 = sitofp i64 %43 to double
%45 = load double, double* %16
%46 = fdiv double %44, %45
store double %46, double* %17
%47 = load double, double* %17
%48 = fdiv double %47, 1.024000e+03
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %48)
%50 = load double, double* %17
%51 = fmul double %50, 8.000000e+00
%52 = fdiv double %51, 1.000000e+06
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), double %52)
%54 = load i32, i32* %13
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %7
%57 = load i32, i32* %13
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %56, %7
%60 = load i32, i32* %14
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load i32, i32* %14
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %62, %59
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [44 x i8] c"%s - %d bufs of %d bytes in %d.%02d 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 = [10 x i8] c", %d lost\00"
@.str.4 = [21 x i8] c", %d out of sequence\00"
define void @show_results(i8* %0, %struct.timeval* %1, %struct.timeval* %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca %struct.timeval
%9 = bitcast %struct.timeval* %8 to i8*
%10 = mul nsw i32 %4, %3
%11 = call i32 @timersub(%struct.timeval* %2, %struct.timeval* %1, %struct.timeval* %8)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 1
%15 = load i32, i32* %14
%16 = sdiv i32 %15, 10000
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %3, i32 %4, i32 %13, i32 %16)
%18 = load i32, i32* %12
%19 = sitofp i32 %18 to double
%20 = load i32, i32* %14
%21 = sdiv i32 %20, 10000
%22 = sitofp i32 %21 to double
%23 = call double @llvm.fmuladd.f64(double %22, double 1.000000e-02, double %19)
%24 = sitofp i32 %10 to double
%25 = fdiv double %24, %23
%26 = fmul double %25, 0x3F50000000000000
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %26)
%28 = fmul double %25, 8.000000e+00
%29 = fdiv double %28, 1.000000e+06
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), double %29)
%31 = icmp eq i32 %5, 0
br i1 %31, label %34, label %32
32: ; preds = %7
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %5)
br label %34
34: ; preds = %32, %7
%35 = icmp eq i32 %6, 0
br i1 %35, label %38, label %36
36: ; preds = %34
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %6)
br label %38
38: ; preds = %36, %34
%39 = call i32 @putchar(i32 10)
ret void
}