#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 _fpconv_grisu2(double, char *, int *);
scalar_t__ emit_digits(char *, int, char *, int, int);
int filter_special(double, char *);
int get_dbits(double);
int _fpconv_dtoa(double d, char dest[24]) {
  char digits[18];
  int str_len = 0;
  bool neg = false;
  if (get_dbits(d) & 0x8000000000000000U) {
    dest[0] = '-';
    str_len++;
    neg = true;
  }
  int spec = filter_special(d, dest + str_len);
  if (spec) {
    return str_len + spec;
  }
  int K = 0;
  int ndigits = _fpconv_grisu2(d, digits, &K);
  str_len += emit_digits(digits, ndigits, dest + str_len, K, neg);
  return str_len;
}


x86 assembly (clang, -O0):
<_fpconv_dtoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <get_dbits@plt>
cltq
movabs $0x8000000000000000,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     1199 <_fpconv_dtoa+0x59>
mov    -0x18(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
call   1030 <filter_special@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11c9 <_fpconv_dtoa+0x89>
mov    -0x34(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1216 <_fpconv_dtoa+0xd6>
movl   $0x0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <_fpconv_grisu2@plt>
mov    %eax,-0x44(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x44(%rbp),%esi
mov    -0x18(%rbp),%rdx
movslq -0x34(%rbp),%rax
add    %rax,%rdx
mov    -0x40(%rbp),%ecx
mov    -0x38(%rbp),%r8d
call   1060 <emit_digits@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_fpconv_dtoa>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movsd  %xmm0,0x8(%rsp)
call   1040 <get_dbits@plt>
xor    %ebp,%ebp
test   %eax,%eax
jns    1164 <_fpconv_dtoa+0x24>
movb   $0x2d,(%rbx)
mov    $0x1,%ebp
mov    %ebp,%eax
add    %rax,%rbx
movsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
call   1030 <filter_special@plt>
test   %eax,%eax
jne    11af <_fpconv_dtoa+0x6f>
movl   $0x0,0x4(%rsp)
lea    0x10(%rsp),%r14
lea    0x4(%rsp),%rsi
movsd  0x8(%rsp),%xmm0
mov    %r14,%rdi
call   1050 <_fpconv_grisu2@plt>
mov    0x4(%rsp),%ecx
mov    %r14,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
mov    %ebp,%r8d
call   1060 <emit_digits@plt>
add    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_fpconv_dtoa(double %0, i8* %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca i8*
%6 = alloca [18 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store double %0, double* %4
store i8* %1, i8** %5
store i32 0, i32* %7
store i32 0, i32* %8
%12 = load double, double* %4
%13 = call i32 @get_dbits(double %12)
%14 = sext i32 %13 to i64
%15 = and i64 %14, -9223372036854775808
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 45, i8* %19
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
store i32 1, i32* %8
br label %22
22: ; preds = %17, %2
%23 = load double, double* %4
%24 = load i8*, i8** %5
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = call i32 @filter_special(double %23, i8* %27)
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %22
%32 = load i32, i32* %7
%33 = load i32, i32* %9
%34 = add nsw i32 %32, %33
store i32 %34, i32* %3
br label %53
35: ; preds = %22
store i32 0, i32* %10
%36 = load double, double* %4
%37 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 0
%38 = call i32 @_fpconv_grisu2(double %36, i8* %37, i32* %10)
store i32 %38, i32* %11
%39 = getelementptr inbounds [18 x i8], [18 x i8]* %6, i64 0, i64 0
%40 = load i32, i32* %11
%41 = load i8*, i8** %5
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i32, i32* %10
%46 = load i32, i32* %8
%47 = call i64 @emit_digits(i8* %39, i32 %40, i8* %44, i32 %45, i32 %46)
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = add nsw i64 %49, %47
%51 = trunc i64 %50 to i32
store i32 %51, i32* %7
%52 = load i32, i32* %7
store i32 %52, i32* %3
br label %53
53: ; preds = %35, %31
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
define i32 @_fpconv_dtoa(double %0, i8* %1) {
%3 = alloca [18 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @get_dbits(double %0)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %9, label %8
8: ; preds = %2
store i8 45, i8* %1
br label %9
9: ; preds = %8, %2
%10 = phi i32 [ 1, %8 ], [ 0, %2 ]
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = tail call i32 @filter_special(double %0, i8* %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%17 = call i32 @_fpconv_grisu2(double %0, i8* %5, i32* %4)
%18 = load i32, i32* %4
%19 = call i64 @emit_digits(i8* %5, i32 %17, i8* %12, i32 %18, i32 %10)
%20 = trunc i64 %19 to i32
br label %21
21: ; preds = %9, %15
%22 = phi i32 [ %20, %15 ], [ %13, %9 ]
%23 = add i32 %22, %10
ret i32 %23
}