#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*/ memset(char *, char, int);
int /*<<< orphan*/ sprintf(char *, char *, float);
int /*<<< orphan*/ strcat(char *, char *);
char *format_string(char *format_string, float rate) {
  int unit;
  memset(format_string, '\0', 24);
  if (rate < 1) {
    strcat(format_string, "N/A");
    return format_string;
  }
  if (0 < rate && rate < 1000)
    unit = 1;
  if (1000 <= rate && rate < 1000000)
    unit = 1000;
  if (rate >= 1000000)
    unit = 1000000;
  rate = (rate / unit);
  sprintf(format_string, "%.1f ", rate);
  switch (unit) {
  case 1:
    strcat(format_string, "B/s");
    break;
  case 1000:
    strcat(format_string, "KB/s");
    break;
  case 1000000:
    strcat(format_string, "MB/s");
    break;
  }
  return format_string;
}


x86 assembly (clang, -O0):
<format_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
movss  0xea7(%rip),%xmm0
ucomiss -0x14(%rbp),%xmm0
jbe    1180 <format_string+0x50>
mov    -0x10(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    129a <format_string+0x16a>
movss  -0x14(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11aa <format_string+0x7a>
movss  0xe6b(%rip),%xmm0
ucomiss -0x14(%rbp),%xmm0
jbe    11aa <format_string+0x7a>
movl   $0x1,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
movss  0xe4d(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     11d9 <format_string+0xa9>
movss  0xe40(%rip),%xmm0
ucomiss -0x14(%rbp),%xmm0
jbe    11d9 <format_string+0xa9>
movl   $0x3e8,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
movss  0xe22(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     11f6 <format_string+0xc6>
movl   $0xf4240,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
cvtsi2ssl -0x18(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
movss  -0x14(%rbp),%xmm0
lea    0xdf7(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x1,%eax
je     1258 <format_string+0x128>
jmp    1232 <format_string+0x102>
mov    -0x1c(%rbp),%eax
sub    $0x3e8,%eax
je     126d <format_string+0x13d>
jmp    1245 <format_string+0x115>
mov    -0x1c(%rbp),%eax
sub    $0xf4240,%eax
je     1282 <format_string+0x152>
jmp    1292 <format_string+0x162>
mov    -0x10(%rbp),%rdi
lea    0xdb4(%rip),%rsi
call   1040 <strcat@plt>
jmp    1292 <format_string+0x162>
mov    -0x10(%rbp),%rdi
lea    0xd9e(%rip),%rsi
call   1040 <strcat@plt>
jmp    1292 <format_string+0x162>
mov    -0x10(%rbp),%rdi
lea    0xd8e(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_string>:
push   %rbp
push   %rbx
push   %rax
movss  %xmm0,0x4(%rsp)
mov    %rdi,%rbx
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
movss  0x4(%rsp),%xmm0
movss  0xeaa(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    1164 <format_string+0x34>
lea    0xeaa(%rip),%rsi
jmp    11d9 <format_string+0xa9>
movss  0xe98(%rip),%xmm1
ucomiss %xmm0,%xmm1
mov    $0x3e8,%eax
mov    $0x1,%ecx
cmovbe %ecx,%eax
ucomiss 0xe85(%rip),%xmm0
cmovb  %ecx,%eax
ucomiss %xmm1,%xmm0
mov    $0xf4240,%ebp
cmovb  %eax,%ebp
xorps  %xmm1,%xmm1
cvtsi2ss %ebp,%xmm1
divss  %xmm1,%xmm0
lea    0xe6d(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
cmp    $0x1,%ebp
je     11c9 <format_string+0x99>
cmp    $0xf4240,%ebp
je     11d2 <format_string+0xa2>
cmp    $0x3e8,%ebp
jne    11e1 <format_string+0xb1>
lea    0xe4f(%rip),%rsi
jmp    11d9 <format_string+0xa9>
lea    0xe47(%rip),%rsi
jmp    11d9 <format_string+0xa9>
lea    0xe42(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"N/A\00"
@.str.1 = [6 x i8] c"%.1f \00"
@.str.2 = [4 x i8] c"B/s\00"
@.str.3 = [5 x i8] c"KB/s\00"
@.str.4 = [5 x i8] c"MB/s\00"
define i8* @format_string(i8* %0, float %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca float
%6 = alloca i32
store i8* %0, i8** %4
store float %1, float* %5
%7 = load i8*, i8** %4
%8 = call i32 @memset(i8* %7, i8 signext 0, i32 24)
%9 = load float, float* %5
%10 = fcmp olt float %9, 1.000000e+00
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %4
store i8* %14, i8** %3
br label %53
15: ; preds = %2
%16 = load float, float* %5
%17 = fcmp olt float 0.000000e+00, %16
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load float, float* %5
%20 = fcmp olt float %19, 1.000000e+03
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 1, i32* %6
br label %22
22: ; preds = %21, %18, %15
%23 = load float, float* %5
%24 = fcmp ole float 1.000000e+03, %23
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load float, float* %5
%27 = fcmp olt float %26, 1.000000e+06
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 1000, i32* %6
br label %29
29: ; preds = %28, %25, %22
%30 = load float, float* %5
%31 = fcmp oge float %30, 1.000000e+06
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 1000000, i32* %6
br label %33
33: ; preds = %32, %29
%34 = load float, float* %5
%35 = load i32, i32* %6
%36 = sitofp i32 %35 to float
%37 = fdiv float %34, %36
store float %37, float* %5
%38 = load i8*, i8** %4
%39 = load float, float* %5
%40 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float %39)
%41 = load i32, i32* %6
switch i32 %41, label %51 [
i32 1, label %42
i32 1000, label %45
i32 1000000, label %48
]
42: ; preds = %33
%43 = load i8*, i8** %4
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %51
45: ; preds = %33
%46 = load i8*, i8** %4
%47 = call i32 @strcat(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %51
48: ; preds = %33
%49 = load i8*, i8** %4
%50 = call i32 @strcat(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %51
51: ; preds = %33, %48, %45, %42
%52 = load i8*, i8** %4
store i8* %52, i8** %3
br label %53
53: ; preds = %51, %11
%54 = load i8*, i8** %3
ret i8* %54
}

LLVM IR (-O2):
@.str = [4 x i8] c"N/A\00"
@.str.1 = [6 x i8] c"%.1f \00"
@.str.2 = [4 x i8] c"B/s\00"
@.str.3 = [5 x i8] c"KB/s\00"
@.str.4 = [5 x i8] c"MB/s\00"
define i8* @format_string(i8* returned %0, float %1) {
%3 = tail call i32 @memset(i8* %0, i8 signext 0, i32 24)
%4 = fcmp olt float %1, 1.000000e+00
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = fcmp oge float %1, 1.000000e+03
%7 = fcmp olt float %1, 1.000000e+06
%8 = and i1 %6, %7
%9 = select i1 %8, i32 1000, i32 1
%10 = fcmp ult float %1, 1.000000e+06
%11 = select i1 %10, i32 %9, i32 1000000
%12 = sitofp i32 %11 to float
%13 = fdiv float %1, %12
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float %13)
switch i32 %11, label %20 [
i32 1, label %17
i32 1000, label %15
i32 1000000, label %16
]
15: ; preds = %5
br label %17
16: ; preds = %5
br label %17
17: ; preds = %5, %2, %16, %15
%18 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %15 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %16 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %5 ]
%19 = tail call i32 @strcat(i8* %0, i8* %18)
br label %20
20: ; preds = %17, %5
ret i8* %0
}