#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 intToStr(int, char *, int);
float powd(int, int);
void ftoa(float n, char *res, int afterpoint) {
  int ipart = (int)n;
  float fpart = n - (float)ipart;
  int i = intToStr(ipart, res, 0);
  if (afterpoint != 0) {
    res[i] = '.';
    fpart = fpart * powd(10, afterpoint);
    intToStr((int)fpart, res + i + 1, afterpoint);
  }
}


x86 assembly (clang, -O0):
<ftoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cvttss2si -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
movss  -0x4(%rbp),%xmm0
cvtsi2ssl -0x18(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <intToStr@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ba <ftoa+0x9a>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x2e,(%rax,%rcx,1)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x14(%rbp),%esi
mov    $0xa,%edi
call   1030 <powd@plt>
movaps %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
cvttss2si -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
mov    -0x14(%rbp),%edx
call   1040 <intToStr@plt>
add    $0x30,%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,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <intToStr@plt>
test   %r14d,%r14d
je     1196 <ftoa+0x76>
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
movss  0xc(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0xc(%rsp)
movslq %eax,%rbp
movb   $0x2e,(%rbx,%rbp,1)
mov    $0xa,%edi
mov    %r14d,%esi
call   1030 <powd@plt>
mulss  0xc(%rsp),%xmm0
cvttss2si %xmm0,%edi
lea    (%rbx,%rbp,1),%rsi
add    $0x1,%rsi
mov    %r14d,%edx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <intToStr@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @ftoa(float %0, i8* %1, i32 %2) {
%4 = alloca float
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
%9 = alloca i32
store float %0, float* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load float, float* %4
%11 = fptosi float %10 to i32
store i32 %11, i32* %7
%12 = load float, float* %4
%13 = load i32, i32* %7
%14 = sitofp i32 %13 to float
%15 = fsub float %12, %14
store float %15, float* %8
%16 = load i32, i32* %7
%17 = load i8*, i8** %5
%18 = call i32 @intToStr(i32 %16, i8* %17, i32 0)
store i32 %18, i32* %9
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %39
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 46, i8* %25
%26 = load float, float* %8
%27 = load i32, i32* %6
%28 = call float @powd(i32 10, i32 %27)
%29 = fmul float %26, %28
store float %29, float* %8
%30 = load float, float* %8
%31 = fptosi float %30 to i32
%32 = load i8*, i8** %5
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = load i32, i32* %6
%38 = call i32 @intToStr(i32 %31, i8* %36, i32 %37)
br label %39
39: ; preds = %21, %3
ret void
}

LLVM IR (-O2):
define void @ftoa(float %0, i8* %1, i32 %2) {
%4 = fptosi float %0 to i32
%5 = tail call i32 @intToStr(i32 %4, i8* %1, i32 0)
%6 = icmp eq i32 %2, 0
br i1 %6, label %17, label %7
7: ; preds = %3
%8 = sitofp i32 %4 to float
%9 = fsub float %0, %8
%10 = sext i32 %5 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
store i8 46, i8* %11
%12 = tail call float @powd(i32 10, i32 %2)
%13 = fmul float %9, %12
%14 = fptosi float %13 to i32
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = tail call i32 @intToStr(i32 %14, i8* %15, i32 %2)
br label %17
17: ; preds = %7, %3
ret void
}