#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 */
char *malloc(int);
int snprintf(char *, int, char *, float);
int /*<<< orphan*/ sprintf(char *, char *, float);
char *make_floatstr(float x) {
  static char scrap[128];
  char *str;
  int sz = snprintf(scrap, sizeof scrap, "%g", x);
  if (!(str = malloc(sz + 1)))
    return 0;
  sprintf(str, "%g", x);
  return str;
}


x86 assembly (clang, -O0):
<make_floatstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
lea    0x2f07(%rip),%rdi
mov    $0x80,%esi
lea    0xeab(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1183 <make_floatstr+0x53>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <make_floatstr+0x70>
mov    -0x18(%rbp),%rdi
movss  -0xc(%rbp),%xmm0
lea    0xe6d(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_floatstr>:
push   %rbx
sub    $0x10,%rsp
lea    0x2f14(%rip),%rdi
lea    0xebd(%rip),%rdx
mov    $0x80,%esi
movss  %xmm0,0xc(%rsp)
call   1030 <snprintf@plt>
lea    0x1(%rax),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1178 <make_floatstr+0x48>
lea    0xe96(%rip),%rsi
mov    %rbx,%rdi
movss  0xc(%rsp),%xmm0
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@make_floatstr.scrap = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%g\00"
define i8* @make_floatstr(float %0) {
%2 = alloca i8*
%3 = alloca float
%4 = alloca i8*
%5 = alloca i32
store float %0, float* %3
%6 = load float, float* %3
%7 = call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @make_floatstr.scrap, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = add nsw i32 %8, 1
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
store i8* null, i8** %2
br label %18
13: ; preds = %1
%14 = load i8*, i8** %4
%15 = load float, float* %3
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float %15)
%17 = load i8*, i8** %4
store i8* %17, i8** %2
br label %18
18: ; preds = %13, %12
%19 = load i8*, i8** %2
ret i8* %19
}

LLVM IR (-O2):
@make_floatstr.scrap = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%g\00"
define noalias i8* @make_floatstr(float %0) {
%2 = tail call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @make_floatstr.scrap, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float %0)
%3 = add nsw i32 %2, 1
%4 = tail call i8* @malloc(i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float %0)
br label %8
8: ; preds = %1, %6
ret i8* %4
}