#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*/ itoa(int, char *, int);
char strlen(char *);
void ftoa(char *str, float f, char size) {
  char pos;
  char len;
  char *curr;
  int value;
  pos = 0;
  value = (int)f;
  itoa(value, str, 10);
  if (f < 0) {
    f *= -1;
    value *= -1;
  }
  len = strlen(str);
  pos = len;
  str[pos++] = '.';
  while (pos < (size + len + 1)) {
    f = f - (float)value;
    f *= 10;
    value = (int)f;
    itoa(value, curr, 10);
    str[pos++] = *curr;
  }
}


x86 assembly (clang, -O0):
<ftoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
movb   $0x0,-0xe(%rbp)
cvttss2si -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    $0xa,%edx
call   1040 <itoa@plt>
xorps  %xmm0,%xmm0
ucomiss -0xc(%rbp),%xmm0
jbe    117a <ftoa+0x5a>
movss  0xe97(%rip),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
imul   $0xffffffff,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %al,-0xf(%rbp)
mov    -0xf(%rbp),%al
mov    %al,-0xe(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xe(%rbp),%cl
mov    %cl,%dl
add    $0x1,%dl
mov    %dl,-0xe(%rbp)
movsbq %cl,%rcx
movb   $0x2e,(%rax,%rcx,1)
movsbl -0xe(%rbp),%eax
movsbl -0xd(%rbp),%ecx
movsbl -0xf(%rbp),%edx
add    %edx,%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    121e <ftoa+0xfe>
movss  -0xc(%rbp),%xmm0
cvtsi2ssl -0x1c(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xe2d(%rip),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
cvttss2si -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <itoa@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%dl
mov    -0x8(%rbp),%rax
mov    -0xe(%rbp),%cl
mov    %cl,%sil
add    $0x1,%sil
mov    %sil,-0xe(%rbp)
movsbq %cl,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11a3 <ftoa+0x83>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftoa>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r15d
mov    %rdi,%rbp
movaps %xmm0,(%rsp)
cvttss2si %xmm0,%r14d
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1040 <itoa@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
movsbq %al,%rax
movb   $0x2e,0x0(%rbp,%rax,1)
movsbl %al,%r12d
add    %r15d,%r12d
add    $0x1,%al
movsbl %al,%eax
cmp    %eax,%r12d
jl     11d6 <ftoa+0xb6>
mov    %r14d,%ebp
neg    %ebp
xorps  %xmm0,%xmm0
movaps (%rsp),%xmm3
ucomiss %xmm3,%xmm0
cmovbe %r14d,%ebp
movaps 0xe77(%rip),%xmm1
xorps  %xmm3,%xmm1
movaps %xmm3,%xmm2
cmpltss %xmm0,%xmm2
andps  %xmm2,%xmm1
andnps %xmm3,%xmm2
orps   %xmm1,%xmm2
add    $0x2,%bl
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
subss  %xmm0,%xmm2
mulss  0xe5d(%rip),%xmm2
movaps %xmm2,(%rsp)
cvttss2si %xmm2,%ebp
mov    %ebp,%edi
mov    $0xa,%edx
call   1040 <itoa@plt>
movaps (%rsp),%xmm2
movsbl %bl,%eax
lea    0x1(%rax),%ebx
cmp    %eax,%r12d
jge    11a0 <ftoa+0x80>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ftoa(i8* %0, float %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca float
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store float %1, float* %5
store i8 %2, i8* %6
store i8 0, i8* %7
%11 = load float, float* %5
%12 = fptosi float %11 to i32
store i32 %12, i32* %10
%13 = load i32, i32* %10
%14 = load i8*, i8** %4
%15 = call i32 @itoa(i32 %13, i8* %14, i32 10)
%16 = load float, float* %5
%17 = fcmp olt float %16, 0.000000e+00
br i1 %17, label %18, label %23
18: ; preds = %3
%19 = load float, float* %5
%20 = fmul float %19, -1.000000e+00
store float %20, float* %5
%21 = load i32, i32* %10
%22 = mul nsw i32 %21, -1
store i32 %22, i32* %10
br label %23
23: ; preds = %18, %3
%24 = load i8*, i8** %4
%25 = call signext i8 @strlen(i8* %24)
store i8 %25, i8* %8
%26 = load i8, i8* %8
store i8 %26, i8* %7
%27 = load i8*, i8** %4
%28 = load i8, i8* %7
%29 = add i8 %28, 1
store i8 %29, i8* %7
%30 = sext i8 %28 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8 46, i8* %31
br label %32
32: ; preds = %42, %23
%33 = load i8, i8* %7
%34 = sext i8 %33 to i32
%35 = load i8, i8* %6
%36 = sext i8 %35 to i32
%37 = load i8, i8* %8
%38 = sext i8 %37 to i32
%39 = add nsw i32 %36, %38
%40 = add nsw i32 %39, 1
%41 = icmp slt i32 %34, %40
br i1 %41, label %42, label %61
42: ; preds = %32
%43 = load float, float* %5
%44 = load i32, i32* %10
%45 = sitofp i32 %44 to float
%46 = fsub float %43, %45
store float %46, float* %5
%47 = load float, float* %5
%48 = fmul float %47, 1.000000e+01
store float %48, float* %5
%49 = load float, float* %5
%50 = fptosi float %49 to i32
store i32 %50, i32* %10
%51 = load i32, i32* %10
%52 = load i8*, i8** %9
%53 = call i32 @itoa(i32 %51, i8* %52, i32 10)
%54 = load i8*, i8** %9
%55 = load i8, i8* %54
%56 = load i8*, i8** %4
%57 = load i8, i8* %7
%58 = add i8 %57, 1
store i8 %58, i8* %7
%59 = sext i8 %57 to i64
%60 = getelementptr inbounds i8, i8* %56, i64 %59
store i8 %55, i8* %60
br label %32
61: ; preds = %32
ret void
}

LLVM IR (-O2):
define void @ftoa(i8* %0, float %1, i8 signext %2) {
%4 = fptosi float %1 to i32
%5 = tail call i32 @itoa(i32 %4, i8* %0, i32 10)
%6 = fcmp olt float %1, 0.000000e+00
%7 = tail call signext i8 @strlen(i8* %0)
%8 = sext i8 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 46, i8* %9
%10 = sext i8 %2 to i32
%11 = sext i8 %7 to i32
%12 = add nsw i32 %11, %10
%13 = add i8 %7, 1
%14 = sext i8 %13 to i32
%15 = icmp slt i32 %12, %14
br i1 %15, label %33, label %16
16: ; preds = %3
%17 = sub nsw i32 0, %4
%18 = select i1 %6, i32 %17, i32 %4
%19 = fneg float %1
%20 = select i1 %6, float %19, float %1
br label %21
21: ; preds = %16, %21
%22 = phi i8 [ %30, %21 ], [ %13, %16 ]
%23 = phi i32 [ %28, %21 ], [ %18, %16 ]
%24 = phi float [ %27, %21 ], [ %20, %16 ]
%25 = sitofp i32 %23 to float
%26 = fsub float %24, %25
%27 = fmul float %26, 1.000000e+01
%28 = fptosi float %27 to i32
%29 = tail call i32 @itoa(i32 %28, i8* undef, i32 10)
%30 = add i8 %22, 1
%31 = sext i8 %30 to i32
%32 = icmp slt i32 %12, %31
br i1 %32, label %33, label %21
33: ; preds = %21, %3
ret void
}