#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *get_dev_speed(char *name, unsigned long long int oldsent,
                    unsigned long long int oldrec,
                    unsigned long long int newsent,
                    unsigned long long int newrec) {
  double downspeed, upspeed;
  char *downspeedstr, *upspeedstr;
  char *retstr;
  downspeedstr = (char *)malloc(15);
  upspeedstr = (char *)malloc(15);
  retstr = (char *)malloc(42);
  downspeed = (newrec - oldrec) / 1024.0;
  if (downspeed > 1024.0) {
    downspeed /= 1024.0;
    sprintf(downspeedstr, "%.3f MB/s", downspeed);
  } else {
    sprintf(downspeedstr, "%.2f KB/s", downspeed);
  }
  upspeed = (newsent - oldsent) / 1024.0;
  if (upspeed > 1024.0) {
    upspeed /= 1024.0;
    sprintf(upspeedstr, "%.3f MB/s", upspeed);
  } else {
    sprintf(upspeedstr, "%.2f KB/s", upspeed);
  }
  if (downspeed == 0 && upspeed == 0) {
    sprintf(retstr, "[%s]", name);
  } else {
    sprintf(retstr, "[%s D: %s ~ U: %s]", name, downspeedstr, upspeedstr);
  }
  free(downspeedstr);
  free(upspeedstr);
  return retstr;
}


x86 assembly (clang, -O0):
<get_dev_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    $0xf,%edi
mov    %edi,-0x54(%rbp)
call   1040 <malloc@plt>
mov    -0x54(%rbp),%edi
mov    %rax,-0x40(%rbp)
call   1040 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    $0x2a,%edi
call   1040 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xe82(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xe86(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe4f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe39(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1203 <get_dev_speed+0xd3>
movsd  -0x30(%rbp),%xmm0
movsd  0xe22(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
movsd  -0x30(%rbp),%xmm0
lea    0xe39(%rip),%rsi
mov    $0x1,%al
call   1050 <sprintf@plt>
jmp    121a <get_dev_speed+0xea>
mov    -0x40(%rbp),%rdi
movsd  -0x30(%rbp),%xmm0
lea    0xe27(%rip),%rsi
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xddf(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xde3(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdac(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xd96(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12a6 <get_dev_speed+0x176>
movsd  -0x38(%rbp),%xmm0
movsd  0xd7f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x48(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xd96(%rip),%rsi
mov    $0x1,%al
call   1050 <sprintf@plt>
jmp    12bd <get_dev_speed+0x18d>
mov    -0x48(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xd84(%rip),%rsi
mov    $0x1,%al
call   1050 <sprintf@plt>
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1308 <get_dev_speed+0x1d8>
jp     1308 <get_dev_speed+0x1d8>
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1308 <get_dev_speed+0x1d8>
jp     1308 <get_dev_speed+0x1d8>
mov    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xd48(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1326 <get_dev_speed+0x1f6>
mov    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
lea    0xd2a(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dev_speed>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,%rbp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,0x8(%rsp)
mov    $0xf,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    $0xf,%edi
call   1040 <malloc@plt>
mov    %rax,%r13
mov    $0x2a,%edi
call   1040 <malloc@plt>
sub    %r12,%rbp
movq   %rbp,%xmm1
punpckldq 0xe7d(%rip),%xmm1
subpd  0xe85(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe81(%rip),%xmm0
mov    %rax,%r12
ucomisd 0xe7e(%rip),%xmm0
jbe    11bd <get_dev_speed+0x8d>
mulsd  0xe6c(%rip),%xmm0
lea    0xe75(%rip),%rsi
jmp    11c4 <get_dev_speed+0x94>
lea    0xe76(%rip),%rsi
mov    %r14,%rdi
movapd %xmm0,0x20(%rsp)
mov    $0x1,%al
call   1050 <sprintf@plt>
sub    %r15,%rbx
movq   %rbx,%xmm1
punpckldq 0xe1c(%rip),%xmm1
subpd  0xe24(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe20(%rip),%xmm0
ucomisd 0xe20(%rip),%xmm0
jbe    121b <get_dev_speed+0xeb>
mulsd  0xe0e(%rip),%xmm0
lea    0xe17(%rip),%rsi
jmp    1222 <get_dev_speed+0xf2>
lea    0xe18(%rip),%rsi
mov    %r13,%rdi
movapd %xmm0,0x10(%rsp)
mov    $0x1,%al
call   1050 <sprintf@plt>
xorpd  %xmm0,%xmm0
movapd 0x20(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    126a <get_dev_speed+0x13a>
jp     126a <get_dev_speed+0x13a>
movapd 0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    126a <get_dev_speed+0x13a>
jp     126a <get_dev_speed+0x13a>
lea    0xdeb(%rip),%rsi
mov    %r12,%rdi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    1286 <get_dev_speed+0x156>
lea    0xdd8(%rip),%rsi
mov    %r12,%rdi
mov    0x8(%rsp),%rdx
mov    %r14,%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%.3f MB/s\00"
@.str.1 = [10 x i8] c"%.2f KB/s\00"
@.str.2 = [5 x i8] c"[%s]\00"
@.str.3 = [19 x i8] c"[%s D: %s ~ U: %s]\00"
define i8* @get_dev_speed(i8* %0, i64 %1, i64 %2, i64 %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca double
%12 = alloca double
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i64 %3, i64* %9
store i64 %4, i64* %10
%16 = call i64 @malloc(i32 15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %13
%18 = call i64 @malloc(i32 15)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %14
%20 = call i64 @malloc(i32 42)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %15
%22 = load i64, i64* %10
%23 = load i64, i64* %8
%24 = sub i64 %22, %23
%25 = uitofp i64 %24 to double
%26 = fdiv double %25, 1.024000e+03
store double %26, double* %11
%27 = load double, double* %11
%28 = fcmp ogt double %27, 1.024000e+03
br i1 %28, label %29, label %35
29: ; preds = %5
%30 = load double, double* %11
%31 = fdiv double %30, 1.024000e+03
store double %31, double* %11
%32 = load i8*, i8** %13
%33 = load double, double* %11
%34 = call i32 (i8*, i8*, ...) @sprintf(i8* %32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %33)
br label %39
35: ; preds = %5
%36 = load i8*, i8** %13
%37 = load double, double* %11
%38 = call i32 (i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %37)
br label %39
39: ; preds = %35, %29
%40 = load i64, i64* %9
%41 = load i64, i64* %7
%42 = sub i64 %40, %41
%43 = uitofp i64 %42 to double
%44 = fdiv double %43, 1.024000e+03
store double %44, double* %12
%45 = load double, double* %12
%46 = fcmp ogt double %45, 1.024000e+03
br i1 %46, label %47, label %53
47: ; preds = %39
%48 = load double, double* %12
%49 = fdiv double %48, 1.024000e+03
store double %49, double* %12
%50 = load i8*, i8** %14
%51 = load double, double* %12
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %50, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %51)
br label %57
53: ; preds = %39
%54 = load i8*, i8** %14
%55 = load double, double* %12
%56 = call i32 (i8*, i8*, ...) @sprintf(i8* %54, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %55)
br label %57
57: ; preds = %53, %47
%58 = load double, double* %11
%59 = fcmp oeq double %58, 0.000000e+00
br i1 %59, label %60, label %67
60: ; preds = %57
%61 = load double, double* %12
%62 = fcmp oeq double %61, 0.000000e+00
br i1 %62, label %63, label %67
63: ; preds = %60
%64 = load i8*, i8** %15
%65 = load i8*, i8** %6
%66 = call i32 (i8*, i8*, ...) @sprintf(i8* %64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %65)
br label %73
67: ; preds = %60, %57
%68 = load i8*, i8** %15
%69 = load i8*, i8** %6
%70 = load i8*, i8** %13
%71 = load i8*, i8** %14
%72 = call i32 (i8*, i8*, ...) @sprintf(i8* %68, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %69, i8* %70, i8* %71)
br label %73
73: ; preds = %67, %63
%74 = load i8*, i8** %13
%75 = call i32 @free(i8* %74)
%76 = load i8*, i8** %14
%77 = call i32 @free(i8* %76)
%78 = load i8*, i8** %15
ret i8* %78
}

LLVM IR (-O2):
@.str = [10 x i8] c"%.3f MB/s\00"
@.str.1 = [10 x i8] c"%.2f KB/s\00"
@.str.2 = [5 x i8] c"[%s]\00"
@.str.3 = [19 x i8] c"[%s D: %s ~ U: %s]\00"
define i8* @get_dev_speed(i8* %0, i64 %1, i64 %2, i64 %3, i64 %4) {
%6 = tail call i64 @malloc(i32 15)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i64 @malloc(i32 15)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i64 @malloc(i32 42)
%11 = inttoptr i64 %10 to i8*
%12 = sub i64 %4, %2
%13 = uitofp i64 %12 to double
%14 = fmul double %13, 0x3F50000000000000
%15 = fcmp ogt double %14, 1.024000e+03
br i1 %15, label %16, label %19
16: ; preds = %5
%17 = fmul double %14, 0x3F50000000000000
%18 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %17)
br label %21
19: ; preds = %5
%20 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %14)
br label %21
21: ; preds = %19, %16
%22 = phi double [ %17, %16 ], [ %14, %19 ]
%23 = sub i64 %3, %1
%24 = uitofp i64 %23 to double
%25 = fmul double %24, 0x3F50000000000000
%26 = fcmp ogt double %25, 1.024000e+03
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = fmul double %25, 0x3F50000000000000
%29 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %28)
br label %32
30: ; preds = %21
%31 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %25)
br label %32
32: ; preds = %30, %27
%33 = phi double [ %28, %27 ], [ %25, %30 ]
%34 = fcmp oeq double %22, 0.000000e+00
%35 = fcmp oeq double %33, 0.000000e+00
%36 = and i1 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %41
39: ; preds = %32
%40 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %7, i8* %9)
br label %41
41: ; preds = %39, %37
%42 = tail call i32 @free(i8* %7)
%43 = tail call i32 @free(i8* %9)
ret i8* %11
}