#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 *, unsigned int, char *, double, char);
char *netbench_printer_tool_bandwidth(char *buff, unsigned int buffsize,
                                      double bw) {
  static char bytechar[] = {' ', 'K', 'M', 'G'};
  unsigned int i;
  i = 0;
  while (bw > 1) {
    bw /= 1024;
    i++;
  }
  snprintf(buff, buffsize, "%.2f%cB/s", bw * 1024, bytechar[i - 1]);
  return buff;
}


x86 assembly (clang, -O0):
<netbench_printer_tool_bandwidth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xec8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1166 <netbench_printer_tool_bandwidth+0x56>
movsd  -0x18(%rbp),%xmm0
movsd  0xeb9(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112b <netbench_printer_tool_bandwidth+0x1b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  0xe93(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0xe85(%rip),%rdx
lea    0x2e96(%rip),%rax
movsbl (%rax,%rcx,1),%ecx
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netbench_printer_tool_bandwidth>:
push   %rbx
mov    %rdi,%rbx
mov    $0xffffffff,%eax
ucomisd 0xedf(%rip),%xmm0
jbe    114d <netbench_printer_tool_bandwidth+0x3d>
mov    $0xffffffff,%eax
movsd  0xed8(%rip),%xmm1
movsd  0xec8(%rip),%xmm2
nopl   0x0(%rax,%rax,1)
mulsd  %xmm1,%xmm0
add    $0x1,%eax
ucomisd %xmm2,%xmm0
ja     1140 <netbench_printer_tool_bandwidth+0x30>
mulsd  0xebb(%rip),%xmm0
mov    %eax,%eax
lea    0xeba(%rip),%rcx
movsbl (%rax,%rcx,1),%ecx
lea    0xeb3(%rip),%rdx
mov    %rbx,%rdi
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@netbench_printer_tool_bandwidth.bytechar = internal global [4 x i8] c" KMG"
@.str = [10 x i8] c"%.2f%cB/s\00"
define i8* @netbench_printer_tool_bandwidth(i8* %0, i32 %1, double %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store double %2, double* %6
store i32 0, i32* %7
br label %8
8: ; preds = %11, %3
%9 = load double, double* %6
%10 = fcmp ogt double %9, 1.000000e+00
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load double, double* %6
%13 = fdiv double %12, 1.024000e+03
store double %13, double* %6
%14 = load i32, i32* %7
%15 = add i32 %14, 1
store i32 %15, i32* %7
br label %8
16: ; preds = %8
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = load double, double* %6
%20 = fmul double %19, 1.024000e+03
%21 = load i32, i32* %7
%22 = sub i32 %21, 1
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds [4 x i8], [4 x i8]* @netbench_printer_tool_bandwidth.bytechar, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @snprintf(i8* %17, i32 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %20, i8 signext %25)
%27 = load i8*, i8** %4
ret i8* %27
}

LLVM IR (-O2):
@netbench_printer_tool_bandwidth.bytechar = internal unnamed_addr constant [4 x i8] c" KMG"
@.str = [10 x i8] c"%.2f%cB/s\00"
define i8* @netbench_printer_tool_bandwidth(i8* returned %0, i32 %1, double %2) {
%4 = fcmp ogt double %2, 1.000000e+00
br i1 %4, label %5, label %11
5: ; preds = %3, %5
%6 = phi i32 [ %9, %5 ], [ 0, %3 ]
%7 = phi double [ %8, %5 ], [ %2, %3 ]
%8 = fmul double %7, 0x3F50000000000000
%9 = add i32 %6, 1
%10 = fcmp ogt double %8, 1.000000e+00
br i1 %10, label %5, label %11
11: ; preds = %5, %3
%12 = phi double [ %2, %3 ], [ %8, %5 ]
%13 = phi i32 [ -1, %3 ], [ %6, %5 ]
%14 = fmul double %12, 1.024000e+03
%15 = zext i32 %13 to i64
%16 = getelementptr inbounds [4 x i8], [4 x i8]* @netbench_printer_tool_bandwidth.bytechar, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %14, i8 signext %17)
ret i8* %0
}