#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 dummy;
};

/* Variables and functions */
double elapsed_time(struct timeval *, struct timeval *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int, unsigned int,
                          float, float, double);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int, unsigned int,
                            unsigned int, float, float, double);
char *print_summarystats(struct timeval *tv_first, struct timeval *tv_end,
                         unsigned int numpkts_rx, unsigned int numbytes_rx,
                         int retstr) {
  double elapsed_msec;
  float MBps;
  char *s = NULL;
  if (retstr)
    s = malloc(200);
  elapsed_msec = elapsed_time(tv_first, tv_end);
  MBps = numbytes_rx / ((elapsed_msec / 1000) * 1024 * 1024);
  if (s != NULL) {
    snprintf(s, 200,
             "packets received: %u \nbytes_received: %u \n"
             "average packets per second: %f \naverage Mega Bytes per second: "
             "%f (%f Mbps)\n"
             "duration (ms): %f \n",
             numpkts_rx, numbytes_rx, numpkts_rx / (elapsed_msec / 1000), MBps,
             MBps * 8, elapsed_msec);
  } else {
    printf("packets received: %u \nbytes_received: %u \n"
           "average packets per second: %f \naverage Mega Bytes per second: %f "
           "(%f Mbps)\n"
           "duration (ms): %f \n",
           numpkts_rx, numbytes_rx, numpkts_rx / (elapsed_msec / 1000), MBps,
           MBps * 8, elapsed_msec);
  }
  return s;
}


x86 assembly (clang, -O0):
<print_summarystats>:
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    %r8d,-0x1c(%rbp)
movq   $0x0,-0x38(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     117a <print_summarystats+0x3a>
mov    $0xc8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <elapsed_time@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe67(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xe53(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xe47(%rip),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1231 <print_summarystats+0xf1>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
mov    -0x18(%rbp),%r8d
cvtsi2sd %rax,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe14(%rip),%xmm2
divsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%r9d
movss  -0x2c(%rbp),%xmm0
movss  0xdff(%rip),%xmm1
mulss  -0x2c(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
mov    $0xc8,%esi
lea    0xded(%rip),%rdx
call   1050 <snprintf@plt>
jmp    127d <print_summarystats+0x13d>
mov    -0x14(%rbp),%eax
mov    %eax,%esi
mov    -0x18(%rbp),%edx
cvtsi2sd %rax,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xdbd(%rip),%xmm2
divsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%ecx
movss  -0x2c(%rbp),%xmm0
movss  0xda9(%rip),%xmm1
mulss  -0x2c(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
lea    0xd9c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_summarystats>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%rbx
test   %r8d,%r8d
je     1168 <print_summarystats+0x28>
mov    $0xc8,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
jmp    116b <print_summarystats+0x2b>
xor    %r12d,%r12d
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <elapsed_time@plt>
movapd %xmm0,%xmm2
mov    %r14d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movapd %xmm2,%xmm1
divsd  0xe6f(%rip),%xmm1
movsd  0xe6f(%rip),%xmm3
mov    %r15d,%eax
cvtsi2sd %rax,%xmm4
divsd  %xmm1,%xmm4
mulsd  %xmm3,%xmm1
mulsd  %xmm3,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
cvttsd2si %xmm4,%r9
movss  0xe4e(%rip),%xmm1
mulss  %xmm0,%xmm1
test   %r12,%r12
je     11e7 <print_summarystats+0xa7>
lea    0xe42(%rip),%rdx
mov    %r12,%rdi
mov    $0xc8,%esi
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1050 <snprintf@plt>
jmp    11fc <print_summarystats+0xbc>
lea    0xe26(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %r9d,%ecx
call   1040 <printf@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [138 x i8] c"packets received: %u \0Abytes_received: %u \0Aaverage packets per second: %f \0Aaverage Mega Bytes per second: %f (%f Mbps)\0Aduration (ms): %f \0A\00"
define i8* @print_summarystats(%struct.timeval* %0, %struct.timeval* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.timeval*
%7 = alloca %struct.timeval*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca float
%13 = alloca i8*
store %struct.timeval* %0, %struct.timeval** %6
store %struct.timeval* %1, %struct.timeval** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i8* null, i8** %13
%14 = load i32, i32* %10
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %5
%17 = call i8* @malloc(i32 200)
store i8* %17, i8** %13
br label %18
18: ; preds = %16, %5
%19 = load %struct.timeval*, %struct.timeval** %6
%20 = load %struct.timeval*, %struct.timeval** %7
%21 = call double @elapsed_time(%struct.timeval* %19, %struct.timeval* %20)
store double %21, double* %11
%22 = load i32, i32* %9
%23 = uitofp i32 %22 to double
%24 = load double, double* %11
%25 = fdiv double %24, 1.000000e+03
%26 = fmul double %25, 1.024000e+03
%27 = fmul double %26, 1.024000e+03
%28 = fdiv double %23, %27
%29 = fptrunc double %28 to float
store float %29, float* %12
%30 = load i8*, i8** %13
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %47
32: ; preds = %18
%33 = load i8*, i8** %13
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = load i32, i32* %8
%37 = uitofp i32 %36 to double
%38 = load double, double* %11
%39 = fdiv double %38, 1.000000e+03
%40 = fdiv double %37, %39
%41 = fptoui double %40 to i32
%42 = load float, float* %12
%43 = load float, float* %12
%44 = fmul float %43, 8.000000e+00
%45 = load double, double* %11
%46 = call i32 @snprintf(i8* %33, i32 200, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 %34, i32 %35, i32 %41, float %42, float %44, double %45)
br label %61
47: ; preds = %18
%48 = load i32, i32* %8
%49 = load i32, i32* %9
%50 = load i32, i32* %8
%51 = uitofp i32 %50 to double
%52 = load double, double* %11
%53 = fdiv double %52, 1.000000e+03
%54 = fdiv double %51, %53
%55 = fptoui double %54 to i32
%56 = load float, float* %12
%57 = load float, float* %12
%58 = fmul float %57, 8.000000e+00
%59 = load double, double* %11
%60 = call i32 @printf(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 %48, i32 %49, i32 %55, float %56, float %58, double %59)
br label %61
61: ; preds = %47, %32
%62 = load i8*, i8** %13
ret i8* %62
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [138 x i8] c"packets received: %u \0Abytes_received: %u \0Aaverage packets per second: %f \0Aaverage Mega Bytes per second: %f (%f Mbps)\0Aduration (ms): %f \0A\00"
define i8* @print_summarystats(%struct.timeval* %0, %struct.timeval* %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp eq i32 %4, 0
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call dereferenceable_or_null(200) i8* @malloc(i32 200)
br label %9
9: ; preds = %7, %5
%10 = phi i8* [ %8, %7 ], [ null, %5 ]
%11 = tail call double @elapsed_time(%struct.timeval* %0, %struct.timeval* %1)
%12 = uitofp i32 %3 to double
%13 = fdiv double %11, 1.000000e+03
%14 = fmul double %13, 1.024000e+03
%15 = fmul double %14, 1.024000e+03
%16 = fdiv double %12, %15
%17 = fptrunc double %16 to float
%18 = icmp eq i8* %10, null
%19 = uitofp i32 %2 to double
%20 = fdiv double %19, %13
%21 = fptoui double %20 to i32
%22 = fmul float %17, 8.000000e+00
br i1 %18, label %25, label %23
23: ; preds = %9
%24 = tail call i32 @snprintf(i8* %10, i32 200, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3, i32 %21, float %17, float %22, double %11)
br label %27
25: ; preds = %9
%26 = tail call i32 @printf(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3, i32 %21, float %17, float %22, double %11)
br label %27
27: ; preds = %25, %23
ret i8* %10
}