#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 */
long abs(long);
int /*<<< orphan*/ itoa(long, char *, int);
void ftoa(char *str, float f, const unsigned int precision) {
  long p[] = {0, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};
  char *ret = str;
  long heiltal = (long)f;
  itoa(heiltal, str, 10);
  while (*str != '\0') {
    str++;
  }
  *str++ = '.';
  long desimal = abs((long)((f - heiltal) * p[precision]));
  itoa(desimal, str, 10);
}


x86 assembly (clang, -O0):
<ftoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xeae(%rip),%rsi
mov    $0x48,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x68(%rbp)
cvttss2si -0xc(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0xa,%edx
call   1050 <itoa@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a1 <ftoa+0x71>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1180 <ftoa+0x50>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x2e,(%rax)
movss  -0xc(%rbp),%xmm0
cvtsi2ssq -0x70(%rbp),%xmm1
subss  %xmm1,%xmm0
mov    -0x10(%rbp),%eax
cvtsi2ssq -0x60(%rbp,%rax,8),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%rdi
call   1030 <abs@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0xa,%edx
call   1050 <itoa@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftoa>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
movss  %xmm0,0xc(%rsp)
cvttss2si %xmm0,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1030 <itoa@plt>
nopl   0x0(%rax)
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1140 <ftoa+0x30>
xorps  %xmm0,%xmm0
cvtsi2ss %rbp,%xmm0
movss  0xc(%rsp),%xmm1
subss  %xmm0,%xmm1
mov    %r14d,%eax
lea    0xe9b(%rip),%rcx
xorps  %xmm0,%xmm0
cvtsi2ssq (%rcx,%rax,8),%xmm0
movb   $0x2e,-0x1(%rbx)
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%rax
mov    %rax,%rdi
neg    %rdi
cmovs  %rax,%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <itoa@plt>

LLVM IR (-O0):
@__const.ftoa.p = [9 x i64] [i64 0, i64 10, i64 100, i64 1000, i64 10000, i64 100000, i64 1000000, i64 10000000, i64 100000000]
define void @ftoa(i8* %0, float %1, i32 %2) {
%4 = alloca i8*
%5 = alloca float
%6 = alloca i32
%7 = alloca [9 x i64]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %4
store float %1, float* %5
store i32 %2, i32* %6
%11 = bitcast [9 x i64]* %7 to i8*
%12 = load i8*, i8** %4
store i8* %12, i8** %8
%13 = load float, float* %5
%14 = fptosi float %13 to i64
store i64 %14, i64* %9
%15 = load i64, i64* %9
%16 = load i8*, i8** %4
%17 = call i32 @itoa(i64 %15, i8* %16, i32 10)
br label %18
18: ; preds = %23, %3
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
br label %18
26: ; preds = %18
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
store i8 46, i8* %27
%29 = load float, float* %5
%30 = load i64, i64* %9
%31 = sitofp i64 %30 to float
%32 = fsub float %29, %31
%33 = load i32, i32* %6
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [9 x i64], [9 x i64]* %7, i64 0, i64 %34
%36 = load i64, i64* %35
%37 = sitofp i64 %36 to float
%38 = fmul float %32, %37
%39 = fptosi float %38 to i64
%40 = call i64 @abs(i64 %39)
store i64 %40, i64* %10
%41 = load i64, i64* %10
%42 = load i8*, i8** %4
%43 = call i32 @itoa(i64 %41, i8* %42, i32 10)
ret void
}

LLVM IR (-O2):
@__const.ftoa.p = [9 x i64] [i64 0, i64 10, i64 100, i64 1000, i64 10000, i64 100000, i64 1000000, i64 10000000, i64 100000000]
define void @ftoa(i8* %0, float %1, i32 %2) {
%4 = fptosi float %1 to i64
%5 = tail call i32 @itoa(i64 %4, i8* %0, i32 10)
br label %6
6: ; preds = %6, %3
%7 = phi i8* [ %0, %3 ], [ %10, %6 ]
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
%10 = getelementptr inbounds i8, i8* %7, i64 1
br i1 %9, label %11, label %6
11: ; preds = %6
store i8 46, i8* %7
%12 = sitofp i64 %4 to float
%13 = fsub float %1, %12
%14 = zext i32 %2 to i64
%15 = getelementptr inbounds [9 x i64], [9 x i64]* @__const.ftoa.p, i64 0, i64 %14
%16 = load i64, i64* %15
%17 = sitofp i64 %16 to float
%18 = fmul float %13, %17
%19 = fptosi float %18 to i64
%20 = tail call i64 @llvm.abs.i64(i64 %19, i1 true)
%21 = tail call i32 @itoa(i64 %20, i8* %10, i32 10)
ret void
}