// File: /workspace/github_c_makefile_star2_O0/lengjingzju[P]json/dragonbox.c
// Function: dragonbox_dtoa
int dragonbox_dtoa(double num, char *buffer)
{
    diy_fp_t v;
    char *s = buffer;
    union {double d; uint64_t n;} u = {.d = num};
    int32_t signbit = u.n >> (DIY_SIGNIFICAND_SIZE - 1);
    int32_t exponent = (u.n & DP_EXPONENT_MASK) >> DP_SIGNIFICAND_SIZE; /* Exponent */
    uint64_t significand = u.n & DP_SIGNIFICAND_MASK; /* Mantissa */

    if (signbit) {
        *s++ = '-';
    }

    switch (exponent) {
    case DP_EXPONENT_MAX:
        if (significand) {
            memcpy(buffer, "nan", 4);
            return 3;
        } else {
            memcpy(s, "inf", 4);
            return signbit + 3;
        }
        break;

    case 0:
        if (significand) {
            /* no-normalized double */
            v.f = significand; /* Non-normalized double doesn't have a extra integer bit for Mantissa */
            v.e = 1 - DP_EXPONENT_OFFSET - DP_SIGNIFICAND_SIZE; /* Fixed Exponent: -1022, divisor of Mantissa: pow(2,52) */
            dragonbox_convert(&v);
        } else {
            memcpy(s, "0.0", 4);
            return signbit + 3;
        }
        break;

    default:
        /* normalized double */
        v.f = significand + DP_HIDDEN_BIT; /* Normalized double has a extra integer bit for Mantissa */
        v.e = exponent - DP_EXPONENT_OFFSET - DP_SIGNIFICAND_SIZE; /* Exponent offset: -1023, divisor of Mantissa: pow(2,52) */

        if (0 <= -v.e && -v.e <= DP_SIGNIFICAND_SIZE && ((v.f & (((uint64_t)1 << -v.e) - 1)) == 0)) {
            /* small integer. */
            v.f >>= -v.e;
            v.e = 0;
        } else if (significand == 0 && exponent > 1) {
            /* Shorter interval case; proceed like Schubfach. */
            dragonbox_convert_asymmetric(&v);
        } else {
            dragonbox_convert(&v);
        }
        break;
    }

    s = dragonbox_format(s, v.f, v.e);
    return (int)(s - buffer);
}

// Assembly:
subq $0x58, %rsp
movsd %xmm0, 0x48(%rsp)
movq %rdi, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x28(%rsp)
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x20(%rsp), %rax
shrq $0x3f, %rax
movl %eax, 0x1c(%rsp)
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
andq 0x20(%rsp), %rax
shrq $0x34, %rax
movl %eax, 0x18(%rsp)
movabsq $0xfffffffffffff, %rax  # imm = 0xFFFFFFFFFFFFF
andq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x1c(%rsp)
je 0x5088
movq 0x28(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rsp)
movb $0x2d, (%rax)
movl 0x18(%rsp), %eax
movl %eax, 0xc(%rsp)
testl %eax, %eax
je 0x50e6
jmp 0x5096
movl 0xc(%rsp), %eax
subl $0x7ff, %eax            # imm = 0x7FF
jne 0x512e
jmp 0x50a7
cmpq $0x0, 0x10(%rsp)
je 0x50c9
movq 0x40(%rsp), %rax
movl 0x20c6(%rip), %ecx      # 0x7180
movl %ecx, (%rax)
movl $0x3, 0x54(%rsp)
jmp 0x51ff
movq 0x28(%rsp), %rax
movl 0x20b0(%rip), %ecx      # 0x7184
movl %ecx, (%rax)
movl 0x1c(%rsp), %eax
addl $0x3, %eax
movl %eax, 0x54(%rsp)
jmp 0x51ff
cmpq $0x0, 0x10(%rsp)
je 0x510c
movq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0xfffffbce, 0x38(%rsp) # imm = 0xFFFFFBCE
leaq 0x30(%rsp), %rdi
callq 0x5210
jmp 0x5129
movq 0x28(%rsp), %rax
movl 0x2071(%rip), %ecx      # 0x7188
movl %ecx, (%rax)
movl 0x1c(%rsp), %eax
addl $0x3, %eax
movl %eax, 0x54(%rsp)
jmp 0x51ff
jmp 0x51d6
movabsq $0x10000000000000, %rax # imm = 0x10000000000000
addq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
movl 0x18(%rsp), %eax
subl $0x3ff, %eax            # imm = 0x3FF
subl $0x34, %eax
movl %eax, 0x38(%rsp)
xorl %ecx, %ecx
subl 0x38(%rsp), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x51ad
xorl %eax, %eax
subl 0x38(%rsp), %eax
cmpl $0x34, %eax
jg 0x51ad
movq 0x30(%rsp), %rax
xorl %ecx, %ecx
subl 0x38(%rsp), %ecx
movl %ecx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
subq $0x1, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x51ad
xorl %ecx, %ecx
subl 0x38(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, %ecx
shrq %cl, %rax
movq %rax, 0x30(%rsp)
movl $0x0, 0x38(%rsp)
jmp 0x51d4
cmpq $0x0, 0x10(%rsp)
jne 0x51c8
cmpl $0x1, 0x18(%rsp)
jle 0x51c8
leaq 0x30(%rsp), %rdi
callq 0x54d0
jmp 0x51d2
leaq 0x30(%rsp), %rdi
callq 0x5210
jmp 0x51d4
jmp 0x51d6
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movl 0x38(%rsp), %edx
callq 0x5670
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq 0x40(%rsp), %rcx
subq %rcx, %rax
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopl (%rax,%rax)