#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 *format_packets(float numPkts, char *buf) {
  if (numPkts < 1000) {
    snprintf(buf, 32, "%.2f", numPkts);
  } else if (numPkts < 1000000) {
    snprintf(buf, 32, "%.2f K", numPkts / 1000);
  } else {
    numPkts /= 1000000;
    snprintf(buf, 32, "%.2f M", numPkts);
  }
  return (buf);
}


x86 assembly (clang, -O0):
<format_packets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
movss  0xed7(%rip),%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    1152 <format_packets+0x42>
mov    -0x10(%rbp),%rdi
movss  -0x4(%rbp),%xmm0
mov    $0x20,%esi
lea    0xec0(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11c4 <format_packets+0xb4>
movss  0xeaa(%rip),%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    118f <format_packets+0x7f>
mov    -0x10(%rbp),%rdi
movss  -0x4(%rbp),%xmm0
movss  0xe8b(%rip),%xmm1
divss  %xmm1,%xmm0
mov    $0x20,%esi
lea    0xe88(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11bf <format_packets+0xaf>
movss  -0x4(%rbp),%xmm0
movss  0xe68(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
movss  -0x4(%rbp),%xmm0
mov    $0x20,%esi
lea    0xe5a(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11c4 <format_packets+0xb4>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_packets>:
push   %rbx
mov    %rdi,%rbx
movss  0xee4(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    112a <format_packets+0x1a>
lea    0xee0(%rip),%rdx
jmp    1157 <format_packets+0x47>
movss  0xed2(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    1148 <format_packets+0x38>
divss  0xec1(%rip),%xmm0
lea    0xec7(%rip),%rdx
jmp    1157 <format_packets+0x47>
divss  0xeb4(%rip),%xmm0
lea    0xebd(%rip),%rdx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%.2f\00"
@.str.1 = [7 x i8] c"%.2f K\00"
@.str.2 = [7 x i8] c"%.2f M\00"
define i8* @format_packets(float %0, i8* %1) {
%3 = alloca float
%4 = alloca i8*
store float %0, float* %3
store i8* %1, i8** %4
%5 = load float, float* %3
%6 = fcmp olt float %5, 1.000000e+03
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i8*, i8** %4
%9 = load float, float* %3
%10 = call i32 @snprintf(i8* %8, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), float %9)
br label %26
11: ; preds = %2
%12 = load float, float* %3
%13 = fcmp olt float %12, 1.000000e+06
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = load float, float* %3
%17 = fdiv float %16, 1.000000e+03
%18 = call i32 @snprintf(i8* %15, i32 32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), float %17)
br label %25
19: ; preds = %11
%20 = load float, float* %3
%21 = fdiv float %20, 1.000000e+06
store float %21, float* %3
%22 = load i8*, i8** %4
%23 = load float, float* %3
%24 = call i32 @snprintf(i8* %22, i32 32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), float %23)
br label %25
25: ; preds = %19, %14
br label %26
26: ; preds = %25, %7
%27 = load i8*, i8** %4
ret i8* %27
}

LLVM IR (-O2):
@.str = [5 x i8] c"%.2f\00"
@.str.1 = [7 x i8] c"%.2f K\00"
@.str.2 = [7 x i8] c"%.2f M\00"
define i8* @format_packets(float %0, i8* returned %1) {
%3 = fcmp olt float %0, 1.000000e+03
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @snprintf(i8* %1, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), float %0)
br label %14
6: ; preds = %2
%7 = fcmp olt float %0, 1.000000e+06
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = fdiv float %0, 1.000000e+03
%10 = tail call i32 @snprintf(i8* %1, i32 32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), float %9)
br label %14
11: ; preds = %6
%12 = fdiv float %0, 1.000000e+06
%13 = tail call i32 @snprintf(i8* %1, i32 32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), float %12)
br label %14
14: ; preds = %8, %11, %4
ret i8* %1
}