// File: /workspace/github_c_makefile_star2_O0/lengjingzju[P]json/jnum.c
// Function: jnum_dtoa
int jnum_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 */
    int32_t num_digits, vnum_digits;

    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;
        }

    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) */
            num_digits = ldouble_convert_n(&v, s + 1, &vnum_digits);
        } 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 (v.e >= -DP_SIGNIFICAND_SIZE && v.e <= 0 \
            && (v.f & (((uint64_t)1 << -v.e) - 1)) == 0) {
            /* small integer. */
            int32_t tz, n;
            n = fill_1_16_digits(s, v.f >> -v.e, &tz);
            memcpy(s + n, ".0", 3);
            return n + 2 + signbit;
        }
        if (v.e > 0 && v.e <= (63 - DP_SIGNIFICAND_SIZE)) {
            /* big integer. */
            int32_t tz, n;
            n = fill_1_20_digits(s, v.f << v.e, &tz);
            memcpy(s + n, ".0", 3);
            return n + 2 + signbit;
        }
        /* (-1022 - 52) <= e <= (1023 - 52) */
        num_digits = ldouble_convert(&v, s + 1, &vnum_digits);
        break;
    }

    s = ldouble_format(s, num_digits, vnum_digits, num_digits + v.e);
    *s = '\0';
    return (int)(s - buffer);
}

// Assembly:
subq $0x68, %rsp
movsd %xmm0, 0x58(%rsp)
movq %rdi, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x38(%rsp)
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x30(%rsp), %rax
shrq $0x3f, %rax
movl %eax, 0x2c(%rsp)
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
andq 0x30(%rsp), %rax
shrq $0x34, %rax
movl %eax, 0x28(%rsp)
movabsq $0xfffffffffffff, %rax  # imm = 0xFFFFFFFFFFFFF
andq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
cmpl $0x0, 0x2c(%rsp)
je 0xd048
movq 0x38(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x38(%rsp)
movb $0x2d, (%rax)
movl 0x28(%rsp), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
je 0xd0a6
jmp 0xd056
movl 0x4(%rsp), %eax
subl $0x7ff, %eax            # imm = 0x7FF
jne 0xd100
jmp 0xd067
cmpq $0x0, 0x20(%rsp)
je 0xd089
movq 0x50(%rsp), %rax
movl 0x3e66(%rip), %ecx      # 0x10ee0
movl %ecx, (%rax)
movl $0x3, 0x64(%rsp)
jmp 0xd266
movq 0x38(%rsp), %rax
movl 0x3e11(%rip), %ecx      # 0x10ea5
movl %ecx, (%rax)
movl 0x2c(%rsp), %eax
addl $0x3, %eax
movl %eax, 0x64(%rsp)
jmp 0xd266
cmpq $0x0, 0x20(%rsp)
je 0xd0de
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movl $0xfffffbce, 0x48(%rsp) # imm = 0xFFFFFBCE
movq 0x38(%rsp), %rsi
addq $0x1, %rsi
leaq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0xd270
movl %eax, 0x1c(%rsp)
jmp 0xd0fb
movq 0x38(%rsp), %rax
movl 0x3f77(%rip), %ecx      # 0x11060
movl %ecx, (%rax)
movl 0x2c(%rsp), %eax
addl $0x3, %eax
movl %eax, 0x64(%rsp)
jmp 0xd266
jmp 0xd22e
movabsq $0x10000000000000, %rax # imm = 0x10000000000000
addq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movl 0x28(%rsp), %eax
subl $0x3ff, %eax            # imm = 0x3FF
subl $0x34, %eax
movl %eax, 0x48(%rsp)
cmpl $-0x34, 0x48(%rsp)
jl 0xd1b3
cmpl $0x0, 0x48(%rsp)
jg 0xd1b3
movq 0x40(%rsp), %rax
xorl %ecx, %ecx
subl 0x48(%rsp), %ecx
movl %ecx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
subq $0x1, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
jne 0xd1b3
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
xorl %eax, %eax
subl 0x48(%rsp), %eax
movl %eax, %eax
movl %eax, %ecx
shrq %cl, %rsi
leaq 0x14(%rsp), %rdx
callq 0xd450
movl %eax, 0x10(%rsp)
movq 0x38(%rsp), %rax
movslq 0x10(%rsp), %rcx
movw 0x3ed0(%rip), %dx       # 0x11061
movw %dx, (%rax,%rcx)
movb 0x3ec8(%rip), %dl       # 0x11063
movb %dl, 0x2(%rax,%rcx)
movl 0x10(%rsp), %eax
addl $0x2, %eax
addl 0x2c(%rsp), %eax
movl %eax, 0x64(%rsp)
jmp 0xd266
cmpl $0x0, 0x48(%rsp)
jle 0xd212
cmpl $0xb, 0x48(%rsp)
jg 0xd212
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x48(%rsp), %eax
movl %eax, %ecx
shlq %cl, %rsi
leaq 0xc(%rsp), %rdx
callq 0xcc50
movl %eax, 0x8(%rsp)
movq 0x38(%rsp), %rax
movslq 0x8(%rsp), %rcx
movw 0x3e6e(%rip), %dx       # 0x11061
movw %dx, (%rax,%rcx)
movb 0x3e66(%rip), %dl       # 0x11063
movb %dl, 0x2(%rax,%rcx)
movl 0x8(%rsp), %eax
addl $0x2, %eax
addl 0x2c(%rsp), %eax
movl %eax, 0x64(%rsp)
jmp 0xd266
movq 0x38(%rsp), %rsi
addq $0x1, %rsi
leaq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0xd560
movl %eax, 0x1c(%rsp)
movq 0x38(%rsp), %rdi
movl 0x1c(%rsp), %esi
movl 0x18(%rsp), %edx
movl 0x1c(%rsp), %ecx
addl 0x48(%rsp), %ecx
callq 0xd8d0
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movb $0x0, (%rax)
movq 0x38(%rsp), %rax
movq 0x50(%rsp), %rcx
subq %rcx, %rax
movl %eax, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nop