#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*/ sprintf(char *, char *, ...);
void format_axis_value(char *dest, float v) {
  char unitprefixes[9] = " KMGTPEZY";
  float remainder = v;
  if (v < 0.0001) {
    sprintf(dest, "0");
    return;
  } else if (v < 1) {
    sprintf(dest, ".%.3f", v);
    return;
  }
  int i = 0;
  for (i = 0; i < 9 && remainder >= 1000; i++)
    remainder /= 1000;
  sprintf(dest, "%-.0f%c", remainder, unitprefixes[i]);
}


x86 assembly (clang, -O0):
<format_axis_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    0xee8(%rip),%rax
mov    %rax,-0x15(%rbp)
mov    0xee6(%rip),%al
mov    %al,-0xd(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xeb0(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1171 <format_axis_value+0x61>
mov    -0x8(%rbp),%rdi
lea    0xeb4(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1233 <format_axis_value+0x123>
movss  0xe8f(%rip),%xmm0
ucomiss -0xc(%rbp),%xmm0
jbe    11a3 <format_axis_value+0x93>
mov    -0x8(%rbp),%rdi
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe84(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    1233 <format_axis_value+0x123>
jmp    11a8 <format_axis_value+0x98>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x9,-0x20(%rbp)
mov    %al,-0x21(%rbp)
jge    11db <format_axis_value+0xcb>
movss  -0x1c(%rbp),%xmm0
movss  0xe3a(%rip),%xmm1
ucomiss %xmm1,%xmm0
setae  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11eb <format_axis_value+0xdb>
jmp    120f <format_axis_value+0xff>
movss  -0x1c(%rbp),%xmm0
movss  0xe14(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b6 <format_axis_value+0xa6>
mov    -0x8(%rbp),%rdi
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movslq -0x20(%rbp),%rax
movsbl -0x15(%rbp,%rax,1),%edx
lea    0xdf5(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_axis_value>:
cvtss2sd %xmm0,%xmm1
movsd  0xee4(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    1128 <format_axis_value+0x18>
movw   $0x30,(%rdi)
ret
movss  0xed8(%rip),%xmm2
ucomiss %xmm0,%xmm2
jbe    1146 <format_axis_value+0x36>
lea    0xedd(%rip),%rsi
movaps %xmm1,%xmm0
mov    $0x1,%al
jmp    1030 <sprintf@plt>
xor    %eax,%eax
ucomiss 0xebd(%rip),%xmm0
jb     117b <format_axis_value+0x6b>
movss  0xeb3(%rip),%xmm1
nopl   0x0(%rax)
divss  %xmm1,%xmm0
mov    %eax,%ecx
add    $0x1,%rax
cmp    $0x7,%ecx
ja     1174 <format_axis_value+0x64>
ucomiss %xmm1,%xmm0
jae    1160 <format_axis_value+0x50>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
lea    0xe8e(%rip),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe92(%rip),%rsi
movaps %xmm1,%xmm0
mov    $0x1,%al
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@__const.format_axis_value.unitprefixes = [9 x i8] c" KMGTPEZY"
@.str = [2 x i8] c"0\00"
@.str.1 = [6 x i8] c".%.3f\00"
@.str.2 = [8 x i8] c"%-.0f%c\00"
define void @format_axis_value(i8* %0, float %1) {
%3 = alloca i8*
%4 = alloca float
%5 = alloca [9 x i8]
%6 = alloca float
%7 = alloca i32
store i8* %0, i8** %3
store float %1, float* %4
%8 = bitcast [9 x i8]* %5 to i8*
%9 = load float, float* %4
store float %9, float* %6
%10 = load float, float* %4
%11 = fpext float %10 to double
%12 = fcmp olt double %11, 1.000000e-04
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %50
16: ; preds = %2
%17 = load float, float* %4
%18 = fcmp olt float %17, 1.000000e+00
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = load float, float* %4
%22 = fpext float %21 to double
%23 = call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %22)
br label %50
24: ; preds = %16
br label %25
25: ; preds = %24
store i32 0, i32* %7
store i32 0, i32* %7
br label %26
26: ; preds = %37, %25
%27 = load i32, i32* %7
%28 = icmp slt i32 %27, 9
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load float, float* %6
%31 = fcmp oge float %30, 1.000000e+03
br label %32
32: ; preds = %29, %26
%33 = phi i1 [ false, %26 ], [ %31, %29 ]
br i1 %33, label %34, label %40
34: ; preds = %32
%35 = load float, float* %6
%36 = fdiv float %35, 1.000000e+03
store float %36, float* %6
br label %37
37: ; preds = %34
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %26
40: ; preds = %32
%41 = load i8*, i8** %3
%42 = load float, float* %6
%43 = fpext float %42 to double
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = call i32 (i8*, i8*, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %43, i32 %48)
br label %50
50: ; preds = %40, %19, %13
ret void
}

LLVM IR (-O2):
@__const.format_axis_value.unitprefixes = [9 x i8] c" KMGTPEZY"
@.str.1 = [6 x i8] c".%.3f\00"
@.str.2 = [8 x i8] c"%-.0f%c\00"
define void @format_axis_value(i8* nocapture writeonly %0, float %1) {
%3 = fpext float %1 to double
%4 = fcmp olt double %3, 1.000000e-04
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = bitcast i8* %0 to i16*
store i16 48, i16* %6
br label %31
7: ; preds = %2
%8 = fcmp olt float %1, 1.000000e+00
br i1 %8, label %11, label %9
9: ; preds = %7
%10 = fcmp ult float %1, 1.000000e+03
br i1 %10, label %24, label %13
11: ; preds = %7
%12 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %3)
br label %31
13: ; preds = %9, %13
%14 = phi i32 [ %17, %13 ], [ 0, %9 ]
%15 = phi float [ %16, %13 ], [ %1, %9 ]
%16 = fdiv float %15, 1.000000e+03
%17 = add nuw nsw i32 %14, 1
%18 = icmp ult i32 %14, 8
%19 = fcmp oge float %16, 1.000000e+03
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %13, label %21
21: ; preds = %13
%22 = fpext float %16 to double
%23 = zext i32 %17 to i64
br label %24
24: ; preds = %21, %9
%25 = phi double [ %22, %21 ], [ %3, %9 ]
%26 = phi i64 [ %23, %21 ], [ 0, %9 ]
%27 = getelementptr inbounds [9 x i8], [9 x i8]* @__const.format_axis_value.unitprefixes, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %25, i32 %29)
br label %31
31: ; preds = %24, %11, %5
ret void
}