#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*/ snprintf(char *, int, char *, float, char);
char *format_traffic(float numBits, int bits, char *buf) {
  char unit;
  if (bits)
    unit = 'b';
  else
    unit = 'B';
  if (numBits < 1024) {
    snprintf(buf, 32, "%lu %c", (unsigned long)numBits, unit);
  } else if (numBits < 1048576) {
    snprintf(buf, 32, "%.2f K%c", (float)(numBits) / 1024, unit);
  } else {
    float tmpMBits = ((float)numBits) / 1048576;
    if (tmpMBits < 1024) {
      snprintf(buf, 32, "%.2f M%c", tmpMBits, unit);
    } else {
      tmpMBits /= 1024;
      if (tmpMBits < 1024) {
        snprintf(buf, 32, "%.2f G%c", tmpMBits, unit);
      } else {
        snprintf(buf, 32, "%.2f T%c", (float)(tmpMBits) / 1024, unit);
      }
    }
  }
  return (buf);
}


x86 assembly (clang, -O0):
<format_traffic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1137 <format_traffic+0x27>
movb   $0x62,-0x11(%rbp)
jmp    113b <format_traffic+0x2b>
movb   $0x42,-0x11(%rbp)
movss  0xebd(%rip),%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    11dc <format_traffic+0xcc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movss  -0x4(%rbp),%xmm0
movss  0xea6(%rip),%xmm2
movaps %xmm0,%xmm1
subss  %xmm2,%xmm1
cvttss2si %xmm1,%rcx
cvttss2si %xmm0,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x20(%rbp)
test   %rax,%rax
movss  %xmm0,-0x1c(%rbp)
js     11b9 <format_traffic+0xa9>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
movss  -0x1c(%rbp),%xmm0
mov    $0x20,%esi
lea    0xe3e(%rip),%rdx
movsbl -0x11(%rbp),%ecx
call   1030 <snprintf@plt>
jmp    12ec <format_traffic+0x1dc>
movss  0xe20(%rip),%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    121d <format_traffic+0x10d>
mov    -0x10(%rbp),%rdi
movss  -0x4(%rbp),%xmm0
movss  0xe01(%rip),%xmm1
divss  %xmm1,%xmm0
mov    $0x20,%esi
lea    0xe04(%rip),%rdx
movsbl -0x11(%rbp),%ecx
call   1030 <snprintf@plt>
jmp    12e7 <format_traffic+0x1d7>
movss  -0x4(%rbp),%xmm0
movss  0xdda(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xdc5(%rip),%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    1268 <format_traffic+0x158>
mov    -0x10(%rbp),%rdi
movss  -0x18(%rbp),%xmm0
mov    $0x20,%esi
lea    0xdc2(%rip),%rdx
movsbl -0x11(%rbp),%ecx
call   1030 <snprintf@plt>
jmp    12e2 <format_traffic+0x1d2>
movss  -0x18(%rbp),%xmm0
movss  0xd8b(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xd7a(%rip),%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    12b3 <format_traffic+0x1a3>
mov    -0x10(%rbp),%rdi
movss  -0x18(%rbp),%xmm0
mov    $0x20,%esi
lea    0xd80(%rip),%rdx
movsbl -0x11(%rbp),%ecx
call   1030 <snprintf@plt>
jmp    12dd <format_traffic+0x1cd>
mov    -0x10(%rbp),%rdi
movss  -0x18(%rbp),%xmm0
movss  0xd3c(%rip),%xmm1
divss  %xmm1,%xmm0
mov    $0x20,%esi
lea    0xd5a(%rip),%rdx
movsbl -0x11(%rbp),%ecx
call   1030 <snprintf@plt>
jmp    12e2 <format_traffic+0x1d2>
jmp    12e7 <format_traffic+0x1d7>
jmp    12ec <format_traffic+0x1dc>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_traffic>:
push   %rbx
mov    %rsi,%rbx
test   %edi,%edi
setne  %al
shl    $0x5,%al
or     $0x42,%al
movss  0xeda(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    1156 <format_traffic+0x46>
cvttss2si %xmm0,%rdx
mov    %rdx,%rsi
sar    $0x3f,%rsi
subss  0xed1(%rip),%xmm0
cvttss2si %xmm0,%rcx
and    %rsi,%rcx
or     %rdx,%rcx
js     1177 <format_traffic+0x67>
xorps  %xmm0,%xmm0
cvtsi2ss %rcx,%xmm0
jmp    118f <format_traffic+0x7f>
movss  0xea6(%rip),%xmm2
ucomiss %xmm0,%xmm2
jbe    119b <format_traffic+0x8b>
mulss  0xea1(%rip),%xmm0
movzbl %al,%ecx
lea    0xea6(%rip),%rdx
jmp    11df <format_traffic+0xcf>
mov    %rcx,%rdx
shr    %rdx
and    $0x1,%ecx
or     %rdx,%rcx
xorps  %xmm0,%xmm0
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
movzbl %al,%ecx
lea    0xe7b(%rip),%rdx
jmp    11df <format_traffic+0xcf>
mulss  0xe65(%rip),%xmm0
ucomiss %xmm0,%xmm1
jbe    11b4 <format_traffic+0xa4>
movzbl %al,%ecx
lea    0xe72(%rip),%rdx
jmp    11df <format_traffic+0xcf>
mulss  0xe50(%rip),%xmm0
ucomiss %xmm0,%xmm1
jbe    11cd <format_traffic+0xbd>
movzbl %al,%ecx
lea    0xe62(%rip),%rdx
jmp    11df <format_traffic+0xcf>
mulss  0xe37(%rip),%xmm0
movzbl %al,%ecx
lea    0xe57(%rip),%rdx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%lu %c\00"
@.str.1 = [9 x i8] c"%.2f K%c\00"
@.str.2 = [9 x i8] c"%.2f M%c\00"
@.str.3 = [9 x i8] c"%.2f G%c\00"
@.str.4 = [9 x i8] c"%.2f T%c\00"
define i8* @format_traffic(float %0, i32 %1, i8* %2) {
%4 = alloca float
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
%8 = alloca float
store float %0, float* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i8 98, i8* %7
br label %13
12: ; preds = %3
store i8 66, i8* %7
br label %13
13: ; preds = %12, %11
%14 = load float, float* %4
%15 = fcmp olt float %14, 1.024000e+03
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i8*, i8** %6
%18 = load float, float* %4
%19 = fptoui float %18 to i64
%20 = uitofp i64 %19 to float
%21 = load i8, i8* %7
%22 = call i32 @snprintf(i8* %17, i32 32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float %20, i8 signext %21)
br label %61
23: ; preds = %13
%24 = load float, float* %4
%25 = fcmp olt float %24, 0x4130000000000000
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i8*, i8** %6
%28 = load float, float* %4
%29 = fdiv float %28, 1.024000e+03
%30 = load i8, i8* %7
%31 = call i32 @snprintf(i8* %27, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), float %29, i8 signext %30)
br label %60
32: ; preds = %23
%33 = load float, float* %4
%34 = fdiv float %33, 0x4130000000000000
store float %34, float* %8
%35 = load float, float* %8
%36 = fcmp olt float %35, 1.024000e+03
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = load i8*, i8** %6
%39 = load float, float* %8
%40 = load i8, i8* %7
%41 = call i32 @snprintf(i8* %38, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), float %39, i8 signext %40)
br label %59
42: ; preds = %32
%43 = load float, float* %8
%44 = fdiv float %43, 1.024000e+03
store float %44, float* %8
%45 = load float, float* %8
%46 = fcmp olt float %45, 1.024000e+03
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = load i8*, i8** %6
%49 = load float, float* %8
%50 = load i8, i8* %7
%51 = call i32 @snprintf(i8* %48, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), float %49, i8 signext %50)
br label %58
52: ; preds = %42
%53 = load i8*, i8** %6
%54 = load float, float* %8
%55 = fdiv float %54, 1.024000e+03
%56 = load i8, i8* %7
%57 = call i32 @snprintf(i8* %53, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), float %55, i8 signext %56)
br label %58
58: ; preds = %52, %47
br label %59
59: ; preds = %58, %37
br label %60
60: ; preds = %59, %26
br label %61
61: ; preds = %60, %16
%62 = load i8*, i8** %6
ret i8* %62
}

LLVM IR (-O2):
@.str = [7 x i8] c"%lu %c\00"
@.str.1 = [9 x i8] c"%.2f K%c\00"
@.str.2 = [9 x i8] c"%.2f M%c\00"
@.str.3 = [9 x i8] c"%.2f G%c\00"
@.str.4 = [9 x i8] c"%.2f T%c\00"
define i8* @format_traffic(float %0, i32 %1, i8* returned %2) {
%4 = icmp eq i32 %1, 0
%5 = select i1 %4, i8 66, i8 98
%6 = fcmp olt float %0, 1.024000e+03
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = fptoui float %0 to i64
%9 = uitofp i64 %8 to float
%10 = tail call i32 @snprintf(i8* %2, i32 32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float %9, i8 signext %5)
br label %29
11: ; preds = %3
%12 = fcmp olt float %0, 0x4130000000000000
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = fmul float %0, 0x3F50000000000000
%15 = tail call i32 @snprintf(i8* %2, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), float %14, i8 signext %5)
br label %29
16: ; preds = %11
%17 = fmul float %0, 0x3EB0000000000000
%18 = fcmp olt float %17, 1.024000e+03
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @snprintf(i8* %2, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), float %17, i8 signext %5)
br label %29
21: ; preds = %16
%22 = fmul float %17, 0x3F50000000000000
%23 = fcmp olt float %22, 1.024000e+03
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 @snprintf(i8* %2, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), float %22, i8 signext %5)
br label %29
26: ; preds = %21
%27 = fmul float %22, 0x3F50000000000000
%28 = tail call i32 @snprintf(i8* %2, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), float %27, i8 signext %5)
br label %29
29: ; preds = %19, %26, %24, %13, %7
ret i8* %2
}