#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 *, float);
int /*<<< orphan*/ strcmp(char *, char *);
void FormatReal(float fv, char *text) {
  if (fv == 0.0 || (fv > 0.001 && fv < 99999.0) ||
      (fv > -9999.0 && fv < -0.001)) {
    sprintf(text, "%11.4f", fv);
    if (!strcmp(text + 8, "000"))
      text[8] = 0;
    else if (!strcmp(text + 9, "00"))
      text[9] = 0;
    else if (text[10] == '0')
      text[10] = 0;
  } else {
    sprintf(text, "%11.4e", fv);
  }
}


x86 assembly (clang, -O0):
<FormatReal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1152 <FormatReal+0x32>
jp     1152 <FormatReal+0x32>
jmp    11be <FormatReal+0x9e>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe9d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1188 <FormatReal+0x68>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe8a(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     11be <FormatReal+0x9e>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe77(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    124f <FormatReal+0x12f>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe64(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    124f <FormatReal+0x12f>
mov    -0x10(%rbp),%rdi
movss  -0x4(%rbp),%xmm0
lea    0xe52(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
lea    0xe45(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11fd <FormatReal+0xdd>
mov    -0x10(%rbp),%rax
movb   $0x0,0x8(%rax)
jmp    124a <FormatReal+0x12a>
mov    -0x10(%rbp),%rdi
add    $0x9,%rdi
lea    0xe1c(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1227 <FormatReal+0x107>
mov    -0x10(%rbp),%rax
movb   $0x0,0x9(%rax)
jmp    1245 <FormatReal+0x125>
mov    -0x10(%rbp),%rax
movsbl 0xa(%rax),%eax
cmp    $0x30,%eax
jne    1240 <FormatReal+0x120>
mov    -0x10(%rbp),%rax
movb   $0x0,0xa(%rax)
jmp    1245 <FormatReal+0x125>
jmp    124a <FormatReal+0x12a>
jmp    1264 <FormatReal+0x144>
mov    -0x10(%rbp),%rdi
movss  -0x4(%rbp),%xmm0
lea    0xdcc(%rip),%rsi
call   1040 <sprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FormatReal>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1131 <FormatReal+0x11>
jnp    1166 <FormatReal+0x46>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movss  0xec0(%rip),%xmm2
ucomiss %xmm0,%xmm2
jbe    114f <FormatReal+0x2f>
ucomisd 0xebb(%rip),%xmm1
ja     1166 <FormatReal+0x46>
ucomiss 0xeae(%rip),%xmm0
jbe    11bc <FormatReal+0x9c>
movsd  0xeb0(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    11bc <FormatReal+0x9c>
lea    0xeab(%rip),%rsi
mov    %r14,%rdi
call   1040 <sprintf@plt>
lea    0x8(%r14),%rbx
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11b1 <FormatReal+0x91>
lea    0x9(%r14),%rbx
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11b1 <FormatReal+0x91>
cmpb   $0x30,0xa(%r14)
jne    11b4 <FormatReal+0x94>
movb   $0x0,0xa(%r14)
jmp    11b4 <FormatReal+0x94>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe60(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <sprintf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%11.4f\00"
@.str.1 = [4 x i8] c"000\00"
@.str.2 = [3 x i8] c"00\00"
@.str.3 = [7 x i8] c"%11.4e\00"
define void @FormatReal(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 = fpext float %5 to double
%7 = fcmp oeq double %6, 0.000000e+00
br i1 %7, label %24, label %8
8: ; preds = %2
%9 = load float, float* %3
%10 = fpext float %9 to double
%11 = fcmp ogt double %10, 1.000000e-03
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load float, float* %3
%14 = fpext float %13 to double
%15 = fcmp olt double %14, 9.999900e+04
br i1 %15, label %24, label %16
16: ; preds = %12, %8
%17 = load float, float* %3
%18 = fpext float %17 to double
%19 = fcmp ogt double %18, -9.999000e+03
br i1 %19, label %20, label %55
20: ; preds = %16
%21 = load float, float* %3
%22 = fpext float %21 to double
%23 = fcmp olt double %22, -1.000000e-03
br i1 %23, label %24, label %55
24: ; preds = %20, %12, %2
%25 = load i8*, i8** %4
%26 = load float, float* %3
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float %26)
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 8
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %24
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 8
store i8 0, i8* %34
br label %54
35: ; preds = %24
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 9
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %35
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i64 9
store i8 0, i8* %42
br label %53
43: ; preds = %35
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i64 10
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 48
br i1 %48, label %49, label %52
49: ; preds = %43
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i64 10
store i8 0, i8* %51
br label %52
52: ; preds = %49, %43
br label %53
53: ; preds = %52, %40
br label %54
54: ; preds = %53, %32
br label %59
55: ; preds = %20, %16
%56 = load i8*, i8** %4
%57 = load float, float* %3
%58 = call i32 @sprintf(i8* %56, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), float %57)
br label %59
59: ; preds = %55, %54
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%11.4f\00"
@.str.1 = [4 x i8] c"000\00"
@.str.2 = [3 x i8] c"00\00"
@.str.3 = [7 x i8] c"%11.4e\00"
define void @FormatReal(float %0, i8* nocapture %1) {
%3 = fpext float %0 to double
%4 = fcmp oeq float %0, 0.000000e+00
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = fcmp ogt double %3, 1.000000e-03
%7 = fcmp olt float %0, 9.999900e+04
%8 = and i1 %7, %6
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = fcmp ogt float %0, -9.999000e+03
%11 = fcmp olt double %3, -1.000000e-03
%12 = and i1 %10, %11
br i1 %12, label %13, label %29
13: ; preds = %9, %5, %2
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float %0)
%15 = getelementptr inbounds i8, i8* %1, i64 8
%16 = tail call i32 @strcmp(i8* %15, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store i8 0, i8* %15
br label %31
19: ; preds = %13
%20 = getelementptr inbounds i8, i8* %1, i64 9
%21 = tail call i32 @strcmp(i8* %20, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i8 0, i8* %20
br label %31
24: ; preds = %19
%25 = getelementptr inbounds i8, i8* %1, i64 10
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 48
br i1 %27, label %28, label %31
28: ; preds = %24
store i8 0, i8* %25
br label %31
29: ; preds = %9
%30 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), float %0)
br label %31
31: ; preds = %18, %24, %28, %23, %29
ret void
}