#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 fabs(scalar_t__);
scalar_t__ floor(float);
int /*<<< orphan*/ sprintf(char *, char *, float);
void float2string(char *s, float f) {
  if (fabs(f - floor(f)) < 1e-5)
    sprintf(s, "%d", (int)f);
  else
    sprintf(s, "%.5f", f);
}


x86 assembly (clang, -O0):
<float2string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
call   1050 <floor@plt>
movss  -0x10(%rbp),%xmm0
cvtsi2ss %rax,%xmm1
subss  %xmm1,%xmm0
cvttss2si %xmm0,%rdi
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe87(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a1 <float2string+0x71>
mov    -0x8(%rbp),%rdi
cvttss2si -0xc(%rbp),%eax
cvtsi2ss %eax,%xmm0
lea    0xe71(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11b6 <float2string+0x86>
mov    -0x8(%rbp),%rdi
movss  -0xc(%rbp),%xmm0
lea    0xe5a(%rip),%rsi
call   1040 <sprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<float2string>:
push   %rbx
sub    $0x10,%rsp
movaps %xmm0,(%rsp)
mov    %rdi,%rbx
call   1050 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movaps (%rsp),%xmm1
subss  %xmm0,%xmm1
cvttss2si %xmm1,%rdi
call   1030 <fabs@plt>
test   %eax,%eax
jle    116f <float2string+0x3f>
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
movaps (%rsp),%xmm0
jmp    1181 <float2string+0x51>
cvttps2dq (%rsp),%xmm0
cvtdq2ps %xmm0,%xmm0
lea    0xe82(%rip),%rsi
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <sprintf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%.5f\00"
define void @float2string(i8* %0, float %1) {
%3 = alloca i8*
%4 = alloca float
store i8* %0, i8** %3
store float %1, float* %4
%5 = load float, float* %4
%6 = load float, float* %4
%7 = call i64 @floor(float %6)
%8 = sitofp i64 %7 to float
%9 = fsub float %5, %8
%10 = fptosi float %9 to i64
%11 = call i32 @fabs(i64 %10)
%12 = sitofp i32 %11 to double
%13 = fcmp olt double %12, 1.000000e-05
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load float, float* %4
%17 = fptosi float %16 to i32
%18 = sitofp i32 %17 to float
%19 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float %18)
br label %24
20: ; preds = %2
%21 = load i8*, i8** %3
%22 = load float, float* %4
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float %22)
br label %24
24: ; preds = %20, %14
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%.5f\00"
define void @float2string(i8* nocapture writeonly %0, float %1) {
%3 = tail call i64 @floor(float %1)
%4 = sitofp i64 %3 to float
%5 = fsub float %1, %4
%6 = fptosi float %5 to i64
%7 = tail call i32 @fabs(i64 %6)
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = fptosi float %1 to i32
%11 = sitofp i32 %10 to float
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float %11)
br label %15
13: ; preds = %2
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float %1)
br label %15
15: ; preds = %13, %9
ret void
}