#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 *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int FormatVal(char *Name, float V, char *Text) {
  char Format[80];
  if (V > 9999.9 || V < -999.9) {
    sprintf(Text, "%6.6s = *****", Name);
    return strlen(Text);
  } else if (V > 999.99)
    strcpy(Format, "%6.6s =%6.1f");
  else if (V > 99.999)
    strcpy(Format, "%6.6s =%6.2f");
  else if (V > 9.9999)
    strcpy(Format, "%6.6s =%6.3f");
  else if (V > 0.0)
    strcpy(Format, "%6.6s =%6.4f");
  else if (V > -9.9)
    strcpy(Format, "%6.6s =%6.3f");
  else if (V > -99.9)
    strcpy(Format, "%6.6s =%6.2f");
  else
    strcpy(Format, "%6.6s =%6.1f");
  sprintf(Text, Format, Name, V);
  return strlen(Text);
}


x86 assembly (clang, -O0):
<FormatVal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xeaa(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     117b <FormatVal+0x4b>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe97(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a2 <FormatVal+0x72>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeae(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    1313 <FormatVal+0x1e3>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe5d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d2 <FormatVal+0xa2>
lea    -0x70(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12e6 <FormatVal+0x1b6>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe35(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1202 <FormatVal+0xd2>
lea    -0x70(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12e1 <FormatVal+0x1b1>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe0d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1232 <FormatVal+0x102>
lea    -0x70(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12dc <FormatVal+0x1ac>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    125d <FormatVal+0x12d>
lea    -0x70(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12d7 <FormatVal+0x1a7>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdba(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    128d <FormatVal+0x15d>
lea    -0x70(%rbp),%rdi
lea    0xddd(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12d2 <FormatVal+0x1a2>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd92(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12bd <FormatVal+0x18d>
lea    -0x70(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12cd <FormatVal+0x19d>
lea    -0x70(%rbp),%rdi
lea    0xd7e(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12d2 <FormatVal+0x1a2>
jmp    12d7 <FormatVal+0x1a7>
jmp    12dc <FormatVal+0x1ac>
jmp    12e1 <FormatVal+0x1b1>
jmp    12e6 <FormatVal+0x1b6>
jmp    12eb <FormatVal+0x1bb>
mov    -0x20(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    -0x10(%rbp),%rdx
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FormatVal>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
cvtss2sd %xmm0,%xmm2
ucomisd 0xeb5(%rip),%xmm2
ja     116e <FormatVal+0x3e>
movsd  0xeb3(%rip),%xmm1
ucomisd %xmm2,%xmm1
ja     116e <FormatVal+0x3e>
ucomisd 0xead(%rip),%xmm2
jbe    1193 <FormatVal+0x63>
lea    0xeda(%rip),%rsi
jmp    11ed <FormatVal+0xbd>
lea    0xec3(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <strlen@plt>
ucomisd 0xe7d(%rip),%xmm2
jbe    11a6 <FormatVal+0x76>
lea    0xeaf(%rip),%rsi
jmp    11ed <FormatVal+0xbd>
lea    0xeb3(%rip),%rsi
ucomisd 0xe6b(%rip),%xmm2
ja     11ed <FormatVal+0xbd>
xorpd  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11c9 <FormatVal+0x99>
lea    0xea6(%rip),%rsi
jmp    11ed <FormatVal+0xbd>
ucomisd 0xe57(%rip),%xmm2
ja     11ed <FormatVal+0xbd>
ucomisd 0xe55(%rip),%xmm2
lea    0xe71(%rip),%rax
lea    0xe5d(%rip),%rsi
cmova  %rax,%rsi
lea    0x10(%rsp),%r15
mov    %r15,%rdi
movsd  %xmm2,0x8(%rsp)
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"%6.6s = *****\00"
@.str.1 = [13 x i8] c"%6.6s =%6.1f\00"
@.str.2 = [13 x i8] c"%6.6s =%6.2f\00"
@.str.3 = [13 x i8] c"%6.6s =%6.3f\00"
@.str.4 = [13 x i8] c"%6.6s =%6.4f\00"
define i32 @FormatVal(i8* %0, float %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca float
%7 = alloca i8*
%8 = alloca [80 x i8]
store i8* %0, i8** %5
store float %1, float* %6
store i8* %2, i8** %7
%9 = load float, float* %6
%10 = fpext float %9 to double
%11 = fcmp ogt double %10, 0x40C387F333333333
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = load float, float* %6
%14 = fpext float %13 to double
%15 = fcmp olt double %14, 0xC08F3F3333333333
br i1 %15, label %16, label %22
16: ; preds = %12, %3
%17 = load i8*, i8** %7
%18 = load i8*, i8** %5
%19 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %7
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %4
br label %82
22: ; preds = %12
%23 = load float, float* %6
%24 = fpext float %23 to double
%25 = fcmp ogt double %24, 9.999900e+02
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %72
29: ; preds = %22
%30 = load float, float* %6
%31 = fpext float %30 to double
%32 = fcmp ogt double %31, 0x4058FFEF9DB22D0E
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%35 = call i32 @strcpy(i8* %34, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %71
36: ; preds = %29
%37 = load float, float* %6
%38 = fpext float %37 to double
%39 = fcmp ogt double %38, 9.999900e+00
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%42 = call i32 @strcpy(i8* %41, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %70
43: ; preds = %36
%44 = load float, float* %6
%45 = fpext float %44 to double
%46 = fcmp ogt double %45, 0.000000e+00
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%49 = call i32 @strcpy(i8* %48, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %69
50: ; preds = %43
%51 = load float, float* %6
%52 = fpext float %51 to double
%53 = fcmp ogt double %52, -9.900000e+00
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%56 = call i32 @strcpy(i8* %55, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %68
57: ; preds = %50
%58 = load float, float* %6
%59 = fpext float %58 to double
%60 = fcmp ogt double %59, -9.990000e+01
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%63 = call i32 @strcpy(i8* %62, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %67
64: ; preds = %57
%65 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%66 = call i32 @strcpy(i8* %65, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %67
67: ; preds = %64, %61
br label %68
68: ; preds = %67, %54
br label %69
69: ; preds = %68, %47
br label %70
70: ; preds = %69, %40
br label %71
71: ; preds = %70, %33
br label %72
72: ; preds = %71, %26
br label %73
73: ; preds = %72
%74 = load i8*, i8** %7
%75 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%76 = load i8*, i8** %5
%77 = load float, float* %6
%78 = fpext float %77 to double
%79 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %74, i8* %75, i8* %76, double %78)
%80 = load i8*, i8** %7
%81 = call i32 @strlen(i8* %80)
store i32 %81, i32* %4
br label %82
82: ; preds = %73, %16
%83 = load i32, i32* %4
ret i32 %83
}

LLVM IR (-O2):
@.str = [14 x i8] c"%6.6s = *****\00"
@.str.1 = [13 x i8] c"%6.6s =%6.1f\00"
@.str.2 = [13 x i8] c"%6.6s =%6.2f\00"
@.str.3 = [13 x i8] c"%6.6s =%6.3f\00"
@.str.4 = [13 x i8] c"%6.6s =%6.4f\00"
define i32 @FormatVal(i8* %0, float %1, i8* %2) {
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%6 = fpext float %1 to double
%7 = fcmp ogt double %6, 0x40C387F333333333
%8 = fcmp olt double %6, 0xC08F3F3333333333
%9 = or i1 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = tail call i32 @strlen(i8* %2)
br label %31
13: ; preds = %3
%14 = fcmp ogt double %6, 9.999900e+02
br i1 %14, label %26, label %15
15: ; preds = %13
%16 = fcmp ogt double %6, 0x4058FFEF9DB22D0E
br i1 %16, label %26, label %17
17: ; preds = %15
%18 = fcmp ogt double %6, 9.999900e+00
br i1 %18, label %26, label %19
19: ; preds = %17
%20 = fcmp ogt float %1, 0.000000e+00
br i1 %20, label %26, label %21
21: ; preds = %19
%22 = fcmp ogt double %6, -9.900000e+00
br i1 %22, label %26, label %23
23: ; preds = %21
%24 = fcmp ogt double %6, -9.990000e+01
%25 = select i1 %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0)
br label %26
26: ; preds = %23, %21, %19, %17, %15, %13
%27 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %13 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %15 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), %17 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), %19 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), %21 ], [ %25, %23 ]
%28 = call i32 @strcpy(i8* %5, i8* %27)
%29 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* %5, i8* %0, double %6)
%30 = call i32 @strlen(i8* %2)
br label %31
31: ; preds = %26, %10
%32 = phi i32 [ %12, %10 ], [ %30, %26 ]
ret i32 %32
}