#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 */
typedef scalar_t__ uint32_t;

/* Variables and functions */
float floorf(float);
float powf(float, float);
int /*<<< orphan*/ sprintf(char *, char *, char *, scalar_t__, int, int,
                           scalar_t__);
char *ftostr(float value, int places) {
  static char buffer[100];
  uint32_t whole;
  uint32_t fraction;
  char sign[2] = "";
  if (value < 0) {
    value = -value;
    sign[0] = '-';
    sign[1] = '\0';
  }
  whole = (uint32_t)value;
  fraction =
      (uint32_t)((value - floorf(value)) * powf(10.0f, (float)places) + 0.5f);
  sprintf(buffer, "%s%lu.%*.*lu", sign, whole, places, places, fraction);
  return buffer;
}


x86 assembly (clang, -O0):
<ftostr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
lea    -0x1a(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1040 <memset@plt>
xorps  %xmm0,%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    118c <ftostr+0x4c>
movss  -0x4(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
movb   $0x2d,-0x1a(%rbp)
movb   $0x0,-0x19(%rbp)
cvttss2si -0x4(%rbp),%rax
mov    %rax,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x4(%rbp),%xmm0
call   1050 <floorf@plt>
movaps %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
cvtsi2ssl -0x8(%rbp),%xmm1
movss  0xe3c(%rip),%xmm0
call   1030 <powf@plt>
movaps %xmm0,%xmm1
movss  -0x20(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  0xe1f(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%rax
mov    %rax,-0x18(%rbp)
lea    -0x1a(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8d
mov    -0x8(%rbp),%r9d
mov    -0x18(%rbp),%rax
lea    0x2e47(%rip),%rdi
lea    0xdf8(%rip),%rsi
mov    %rax,(%rsp)
call   1060 <sprintf@plt>
lea    0x2e30(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftostr>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
movw   $0x0,0xe(%rsp)
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jbe    1158 <ftostr+0x28>
xorps  0xeaf(%rip),%xmm0
movw   $0x2d,0xe(%rsp)
movaps %xmm0,0x10(%rsp)
cvttss2si %xmm0,%r14
call   1040 <floorf@plt>
movaps 0x10(%rsp),%xmm1
subss  %xmm0,%xmm1
movaps %xmm1,0x10(%rsp)
xorps  %xmm1,%xmm1
cvtsi2ss %ebx,%xmm1
movss  0xe8c(%rip),%xmm0
call   1030 <powf@plt>
mulss  0x10(%rsp),%xmm0
addss  0xe7d(%rip),%xmm0
cvttss2si %xmm0,%rax
mov    %rax,(%rsp)
lea    0x2ea9(%rip),%r15
lea    0xe6a(%rip),%rsi
lea    0xe(%rsp),%rdx
mov    %r15,%rdi
mov    %r14,%rcx
mov    %ebx,%r8d
mov    %ebx,%r9d
call   1050 <sprintf@plt>
mov    %r15,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ftostr.buffer = internal global [100 x i8] zeroinitializer
@.str = [13 x i8] c"%s%lu.%*.*lu\00"
define i8* @ftostr(float %0, i32 %1) {
%3 = alloca float
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca [2 x i8]
store float %0, float* %3
store i32 %1, i32* %4
%8 = bitcast [2 x i8]* %7 to i8*
%9 = load float, float* %3
%10 = fcmp olt float %9, 0.000000e+00
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load float, float* %3
%13 = fneg float %12
store float %13, float* %3
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
store i8 45, i8* %14
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
store i8 0, i8* %15
br label %16
16: ; preds = %11, %2
%17 = load float, float* %3
%18 = fptosi float %17 to i64
store i64 %18, i64* %5
%19 = load float, float* %3
%20 = load float, float* %3
%21 = call float @llvm.floor.f32(float %20)
%22 = fsub float %19, %21
%23 = load i32, i32* %4
%24 = sitofp i32 %23 to float
%25 = call float @powf(float 1.000000e+01, float %24)
%26 = call float @llvm.fmuladd.f32(float %22, float %25, float 5.000000e-01)
%27 = fptosi float %26 to i64
store i64 %27, i64* %6
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%29 = load i64, i64* %5
%30 = load i32, i32* %4
%31 = load i32, i32* %4
%32 = load i64, i64* %6
%33 = call i32 @sprintf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @ftostr.buffer, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %28, i64 %29, i32 %30, i32 %31, i64 %32)
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @ftostr.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@ftostr.buffer = internal global [100 x i8] zeroinitializer
@.str = [13 x i8] c"%s%lu.%*.*lu\00"
define i8* @ftostr(float %0, i32 %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to i8*
store i16 0, i16* %3
%5 = fcmp olt float %0, 0.000000e+00
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = bitcast i16* %3 to [2 x i8]*
%8 = fneg float %0
store i8 45, i8* %4
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
store i8 0, i8* %9
br label %10
10: ; preds = %6, %2
%11 = phi float [ %8, %6 ], [ %0, %2 ]
%12 = fptosi float %11 to i64
%13 = tail call float @llvm.floor.f32(float %11)
%14 = fsub float %11, %13
%15 = sitofp i32 %1 to float
%16 = tail call float @powf(float 1.000000e+01, float %15)
%17 = tail call float @llvm.fmuladd.f32(float %14, float %16, float 5.000000e-01)
%18 = fptosi float %17 to i64
%19 = call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([100 x i8], [100 x i8]* @ftostr.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %4, i64 %12, i32 %1, i32 %1, i64 %18)
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @ftostr.buffer, i64 0, i64 0)
}