#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*/ Grisu2(double, char *, int *, int *);
int /*<<< orphan*/ Prettify(char *, int, int);
scalar_t__ isinf(double);
scalar_t__ isnan(double);
scalar_t__ signbit(double);
int /*<<< orphan*/ strcpy(char *, char *);
void emyg_dtoa(double value, char *buffer) {
  if (isinf(value))
    strcpy(buffer, signbit(value) ? "-inf.0" : "+inf.0");
  else if (isnan(value))
    strcpy(buffer, signbit(value) ? "-nan.0" : "+nan.0");
  else if (value == 0)
    strcpy(buffer, signbit(value) ? "-0.0" : "0.0");
  else {
    if (value < 0) {
      *buffer++ = '-';
      value = -value;
    }
    int length, K;
    Grisu2(value, buffer, &length, &K);
    Prettify(buffer, length, K);
  }
}


x86 assembly (clang, -O0):
<emyg_dtoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1080 <isinf@plt>
cmp    $0x0,%rax
je     11be <emyg_dtoa+0x5e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <signbit@plt>
mov    -0x20(%rbp),%rdi
mov    %rax,%rcx
lea    0xe62(%rip),%rsi
lea    0xe54(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
call   1030 <strcpy@plt>
jmp    12cc <emyg_dtoa+0x16c>
movsd  -0x8(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
je     120b <emyg_dtoa+0xab>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <signbit@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rcx
lea    0xe23(%rip),%rsi
lea    0xe15(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
call   1030 <strcpy@plt>
jmp    12c7 <emyg_dtoa+0x167>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    125c <emyg_dtoa+0xfc>
jp     125c <emyg_dtoa+0xfc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <signbit@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rcx
lea    0xdda(%rip),%rsi
lea    0xdd2(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
call   1030 <strcpy@plt>
jmp    12c2 <emyg_dtoa+0x162>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    129d <emyg_dtoa+0x13d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x2d,(%rax)
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <Grisu2@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1070 <Prettify@plt>
jmp    12c7 <emyg_dtoa+0x167>
jmp    12cc <emyg_dtoa+0x16c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emyg_dtoa>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movaps %xmm0,0x10(%rsp)
call   1080 <isinf@plt>
test   %rax,%rax
je     1195 <emyg_dtoa+0x35>
movapd 0x10(%rsp),%xmm0
call   1050 <signbit@plt>
test   %rax,%rax
lea    0xe8b(%rip),%rax
lea    0xe7d(%rip),%rsi
jmp    11ea <emyg_dtoa+0x8a>
movaps 0x10(%rsp),%xmm0
call   1040 <isnan@plt>
test   %rax,%rax
je     11c2 <emyg_dtoa+0x62>
movapd 0x10(%rsp),%xmm0
call   1050 <signbit@plt>
test   %rax,%rax
lea    0xe6c(%rip),%rax
lea    0xe5e(%rip),%rsi
jmp    11ea <emyg_dtoa+0x8a>
xorpd  %xmm1,%xmm1
movapd 0x10(%rsp),%xmm0
ucomisd %xmm1,%xmm0
jne    11fb <emyg_dtoa+0x9b>
jp     11fb <emyg_dtoa+0x9b>
call   1050 <signbit@plt>
test   %rax,%rax
lea    0xe4a(%rip),%rax
lea    0xe42(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
add    $0x20,%rsp
pop    %rbx
jmp    1030 <strcpy@plt>
ucomisd %xmm0,%xmm1
jbe    1210 <emyg_dtoa+0xb0>
movb   $0x2d,(%rbx)
add    $0x1,%rbx
xorpd  0xdf0(%rip),%xmm0
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <Grisu2@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
call   1070 <Prettify@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"-inf.0\00"
@.str.1 = [7 x i8] c"+inf.0\00"
@.str.2 = [7 x i8] c"-nan.0\00"
@.str.3 = [7 x i8] c"+nan.0\00"
@.str.4 = [5 x i8] c"-0.0\00"
@.str.5 = [4 x i8] c"0.0\00"
define void @emyg_dtoa(double %0, i8* %1) {
%3 = alloca double
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store double %0, double* %3
store i8* %1, i8** %4
%7 = load double, double* %3
%8 = call i64 @isinf(double %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load double, double* %3
%13 = call i64 @signbit(double %12)
%14 = icmp ne i64 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0)
%17 = call i32 @strcpy(i8* %11, i8* %16)
br label %59
18: ; preds = %2
%19 = load double, double* %3
%20 = call i64 @isnan(double %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = load double, double* %3
%25 = call i64 @signbit(double %24)
%26 = icmp ne i64 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0)
%29 = call i32 @strcpy(i8* %23, i8* %28)
br label %58
30: ; preds = %18
%31 = load double, double* %3
%32 = fcmp oeq double %31, 0.000000e+00
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i8*, i8** %4
%35 = load double, double* %3
%36 = call i64 @signbit(double %35)
%37 = icmp ne i64 %36, 0
%38 = zext i1 %37 to i64
%39 = select i1 %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0)
%40 = call i32 @strcpy(i8* %34, i8* %39)
br label %57
41: ; preds = %30
%42 = load double, double* %3
%43 = fcmp olt double %42, 0.000000e+00
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %4
store i8 45, i8* %45
%47 = load double, double* %3
%48 = fneg double %47
store double %48, double* %3
br label %49
49: ; preds = %44, %41
%50 = load double, double* %3
%51 = load i8*, i8** %4
%52 = call i32 @Grisu2(double %50, i8* %51, i32* %5, i32* %6)
%53 = load i8*, i8** %4
%54 = load i32, i32* %5
%55 = load i32, i32* %6
%56 = call i32 @Prettify(i8* %53, i32 %54, i32 %55)
br label %57
57: ; preds = %49, %33
br label %58
58: ; preds = %57, %22
br label %59
59: ; preds = %58, %10
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"-inf.0\00"
@.str.1 = [7 x i8] c"+inf.0\00"
@.str.2 = [7 x i8] c"-nan.0\00"
@.str.3 = [7 x i8] c"+nan.0\00"
@.str.4 = [5 x i8] c"-0.0\00"
@.str.5 = [4 x i8] c"0.0\00"
define void @emyg_dtoa(double %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = tail call i64 @isinf(double %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = tail call i64 @signbit(double %0)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0)
%11 = tail call i32 @strcpy(i8* %1, i8* %10)
br label %41
12: ; preds = %2
%13 = tail call i64 @isnan(double %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = tail call i64 @signbit(double %0)
%17 = icmp eq i64 %16, 0
%18 = select i1 %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
%19 = tail call i32 @strcpy(i8* %1, i8* %18)
br label %41
20: ; preds = %12
%21 = fcmp oeq double %0, 0.000000e+00
br i1 %21, label %22, label %27
22: ; preds = %20
%23 = tail call i64 @signbit(double %0)
%24 = icmp eq i64 %23, 0
%25 = select i1 %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%26 = tail call i32 @strcpy(i8* %1, i8* %25)
br label %41
27: ; preds = %20
%28 = fcmp olt double %0, 0.000000e+00
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = getelementptr inbounds i8, i8* %1, i64 1
store i8 45, i8* %1
%31 = fneg double %0
br label %32
32: ; preds = %29, %27
%33 = phi double [ %31, %29 ], [ %0, %27 ]
%34 = phi i8* [ %30, %29 ], [ %1, %27 ]
%35 = bitcast i32* %3 to i8*
%36 = bitcast i32* %4 to i8*
%37 = call i32 @Grisu2(double %33, i8* %34, i32* %3, i32* %4)
%38 = load i32, i32* %3
%39 = load i32, i32* %4
%40 = call i32 @Prettify(i8* %34, i32 %38, i32 %39)
br label %41
41: ; preds = %15, %32, %22, %7
ret void
}