#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);
int /*<<< orphan*/ memcpy(char *, char *, int);
void dtoa_milo(double value, char *buffer) {
  if (isnan(value)) {
    memcpy(buffer, "NaN", 3);
    buffer[3] = 0;
    return;
  }
  if (isinf(value)) {
    if (value < 0) {
      memcpy(buffer, "-inf", 4);
      buffer[4] = 0;
    } else {
      memcpy(buffer, "inf", 3);
      buffer[3] = 0;
    }
    return;
  }
  if (value == 0) {
    buffer[0] = '0';
    buffer[1] = 0;
  } else {
    if (value < 0) {
      *buffer++ = '-';
      value = -value;
    }
    int length, K;
    Grisu2(value, buffer, &length, &K);
    Prettify(buffer, length, K);
  }
}


x86 assembly (clang, -O0):
<dtoa_milo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
je     1197 <dtoa_milo+0x47>
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
mov    $0x3,%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x3(%rax)
jmp    128f <dtoa_milo+0x13f>
movsd  -0x8(%rbp),%xmm0
call   1070 <isinf@plt>
cmp    $0x0,%rax
je     11fd <dtoa_milo+0xad>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11db <dtoa_milo+0x8b>
mov    -0x10(%rbp),%rdi
lea    0xe40(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x4(%rax)
jmp    11f8 <dtoa_milo+0xa8>
mov    -0x10(%rbp),%rdi
lea    0xe1f(%rip),%rsi
mov    $0x3,%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x3(%rax)
jmp    128f <dtoa_milo+0x13f>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1229 <dtoa_milo+0xd9>
jp     1229 <dtoa_milo+0xd9>
mov    -0x10(%rbp),%rax
movb   $0x30,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    128f <dtoa_milo+0x13f>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    126a <dtoa_milo+0x11a>
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   1050 <Grisu2@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <Prettify@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dtoa_milo>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movapd %xmm0,0x10(%rsp)
call   1040 <isnan@plt>
test   %rax,%rax
je     1186 <dtoa_milo+0x36>
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <memcpy@plt>
movb   $0x0,0x3(%rbx)
add    $0x20,%rsp
pop    %rbx
ret
movapd 0x10(%rsp),%xmm0
call   1070 <isinf@plt>
test   %rax,%rax
je     11bc <dtoa_milo+0x6c>
xorpd  %xmm0,%xmm0
ucomisd 0x10(%rsp),%xmm0
jbe    11d5 <dtoa_milo+0x85>
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
movb   $0x0,0x4(%rbx)
jmp    1180 <dtoa_milo+0x30>
xorpd  %xmm1,%xmm1
movapd 0x10(%rsp),%xmm0
ucomisd %xmm1,%xmm0
jne    11de <dtoa_milo+0x8e>
jp     11de <dtoa_milo+0x8e>
movw   $0x30,(%rbx)
jmp    1180 <dtoa_milo+0x30>
lea    0xe39(%rip),%rsi
jmp    116f <dtoa_milo+0x1f>
ucomisd %xmm0,%xmm1
jbe    11f3 <dtoa_milo+0xa3>
movb   $0x2d,(%rbx)
add    $0x1,%rbx
xorpd  0xe0d(%rip),%xmm0
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <Grisu2@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
call   1060 <Prettify@plt>
jmp    1180 <dtoa_milo+0x30>

LLVM IR (-O0):
@.str = [4 x i8] c"NaN\00"
@.str.1 = [5 x i8] c"-inf\00"
@.str.2 = [4 x i8] c"inf\00"
define void @dtoa_milo(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 @isnan(double %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @memcpy(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 3
store i8 0, i8* %14
br label %57
15: ; preds = %2
%16 = load double, double* %3
%17 = call i64 @isinf(double %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %33
19: ; preds = %15
%20 = load double, double* %3
%21 = fcmp olt double %20, 0.000000e+00
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = call i32 @memcpy(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 4
store i8 0, i8* %26
br label %32
27: ; preds = %19
%28 = load i8*, i8** %4
%29 = call i32 @memcpy(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 3
store i8 0, i8* %31
br label %32
32: ; preds = %27, %22
br label %57
33: ; preds = %15
%34 = load double, double* %3
%35 = fcmp oeq double %34, 0.000000e+00
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i64 0
store i8 48, i8* %38
%39 = load i8*, i8** %4
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8 0, i8* %40
br label %57
41: ; preds = %33
%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 = %10, %32, %49, %36
ret void
}

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