#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 */
int /*<<< orphan*/ IsNan(float);
scalar_t__ fcastu(float);
int sprintf(char *, char *, unsigned int);
char *SerializeFloat(float f, char *dstStr) {
  if (!IsNan(f)) {
    int numChars = sprintf(dstStr, "%.9g", f);
    return dstStr + numChars;
  } else {
    uint32_t u = fcastu(f);
    int numChars = sprintf(dstStr, "NaN(0x%8X)", (unsigned int)u);
    return dstStr + numChars;
  }
}


x86 assembly (clang, -O0):
<SerializeFloat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0xc(%rbp)
mov    %rdi,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
call   1040 <IsNan@plt>
cmp    $0x0,%eax
jne    1183 <SerializeFloat+0x53>
mov    -0x18(%rbp),%rdi
cvttss2si -0xc(%rbp),%rax
mov    %eax,%edx
lea    0xe99(%rip),%rsi
call   1050 <sprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11b9 <SerializeFloat+0x89>
movss  -0xc(%rbp),%xmm0
call   1030 <fcastu@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    %eax,%edx
lea    0xe63(%rip),%rsi
call   1050 <sprintf@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SerializeFloat>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movss  %xmm0,0xc(%rsp)
call   1040 <IsNan@plt>
test   %eax,%eax
je     1160 <SerializeFloat+0x30>
movss  0xc(%rsp),%xmm0
call   1030 <fcastu@plt>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
jmp    1171 <SerializeFloat+0x41>
cvttss2si 0xc(%rsp),%rdx
lea    0xe92(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
cltq
add    %rax,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%.9g\00"
@.str.1 = [11 x i8] c"NaN(0x%8X)\00"
define i8* @SerializeFloat(float %0, i8* %1) {
%3 = alloca i8*
%4 = alloca float
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
store float %0, float* %4
store i8* %1, i8** %5
%9 = load float, float* %4
%10 = call i32 @IsNan(float %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = load float, float* %4
%15 = fptoui float %14 to i32
%16 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %6
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8* %20, i8** %3
br label %32
21: ; preds = %2
%22 = load float, float* %4
%23 = call i64 @fcastu(float %22)
store i64 %23, i64* %7
%24 = load i8*, i8** %5
%25 = load i64, i64* %7
%26 = trunc i64 %25 to i32
%27 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %26)
store i32 %27, i32* %8
%28 = load i8*, i8** %5
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8* %31, i8** %3
br label %32
32: ; preds = %21, %12
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
@.str = [5 x i8] c"%.9g\00"
@.str.1 = [11 x i8] c"NaN(0x%8X)\00"
define i8* @SerializeFloat(float %0, i8* writeonly %1) {
%3 = tail call i32 @IsNan(float %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = fptoui float %0 to i32
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %12
8: ; preds = %2
%9 = tail call i64 @fcastu(float %0)
%10 = trunc i64 %9 to i32
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %8, %5
%13 = phi i32 [ %11, %8 ], [ %7, %5 ]
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
ret i8* %15
}