// File: rhoot[P]sp/tests/../include/sp.hpp
// Function: bool sp::format_float<float>(sp::IWriter&, sp::StringView const&, float)
bool format_float(IWriter& writer, const StringView& format, F value)
    {
        FormatFlags flags;

        if (!parse_format(format, &flags)) {
            return false;
        }

        // I *really* have no interest in serializing floats/doubles... so
        // let's not. Instead, let's build a format string for snprintf to do
        // the heavy work, and we'll just do alignment and stuff.
        const char* suffix = "";
        int32_t precision;
        char type;

        switch (flags.type) {
        case 'f':
        case 'F':
        case 'e':
        case 'E':
            precision = flags.precision >= 0 ? flags.precision : 6;
            type = flags.type;
            break;
        case 'g':
        case 'G':
            precision = (flags.precision != 0)
                ? (flags.precision > 0 ? flags.precision : 6)
                : 1;
            type = flags.type;
            break;
        case '%':
            precision = flags.precision >= 0 ? flags.precision : 6;
            type = 'f';
            value *= 100;
            suffix = "%%";
            break;
        default:
            precision = flags.precision >= 0 ? flags.precision : std::numeric_limits<F>::digits10;
            type = 'g';
            break;
        }

        // produce the formatted value
        char buffer[512];
        const char* digits = buffer;
        int32_t ndigits = 0;

        if (std::isnan(value)) {
            const char* str = std::isupper(flags.type) ? "NAN" : "nan";
            strncpy(buffer, str, 3);
            ndigits = 3;
        } else if (std::isinf(value)) {
            const char* str = std::isupper(flags.type) ? "INF" : "inf";
            strncpy(buffer, str, 3);
            ndigits = 3;
        } else {
            char numFormat[17];
            snprintf(numFormat, sizeof(numFormat), "%%+.%d%c%s", precision, type, suffix);

            // produce the formatted value
    #if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER < 1900)
            unsigned int prevOutputFormat = _set_output_format(_TWO_DIGIT_EXPONENT);
    #endif

            ndigits = snprintf(buffer, sizeof(buffer), numFormat, value) - 1;
            digits = buffer + 1;

    #if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER < 1900)
            _set_output_format(prevOutputFormat);
    #endif
        }

        // determine sign
        char sign = 0;

        if (value < 0) {
            sign = '-';
        } else if (flags.sign == '+' || flags.sign == ' ') {
            sign = flags.sign;
        }

        // determine width
        const int nchars = sign ? ndigits + 1 : ndigits;
        const int32_t width = std::max(flags.width, nchars);

        // determine alignment
        int32_t leadSpace = 0;
        int32_t tailSpace = 0;

        switch (flags.align) {
        case '^':
            leadSpace = (width / 2) - ((nchars + 1) / 2); // nchars rounded up
            tailSpace = ((width + 1) / 2) - (nchars / 2); // width rounded up
            leadSpace += (width & 1) & (nchars & 1); // if both are odd, we need to add one for correction
            tailSpace -= (width & 1) & (nchars & 1); // if both are odd, we need to remove one for correction
            break;
        case '<':
            tailSpace = width - nchars;
            break;
        case '>':
        default:
            leadSpace = width - nchars;
            break;
        }

        // print sign, if it should be before the padding
        if (sign && flags.align == '=') {
            write_char(writer, sign);
        }

        // apply leading padding
        const char fill = flags.fill ? flags.fill : ' ';

        while (leadSpace--) {
            write_char(writer, fill);
        }

        // print sign, if it should be after the padding
        if (sign && flags.align != '=') {
            write_char(writer, sign);
        }

        // write string
        writer.write(ndigits, digits);

        // apply tailing padding
        while (tailSpace--) {
            write_char(writer, fill);
        }

        return true;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movss %xmm0, -0x1c(%rbp)
leaq -0x2c(%rbp), %rdi
callq 0x15a20
movq -0x18(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x15a50
testb $0x1, %al
jne 0x1752b
movb $0x0, -0x1(%rbp)
jmp 0x17a35
leaq 0xc2eb(%rip), %rax      # 0x2381d
movq %rax, -0x38(%rbp)
movsbl -0x20(%rbp), %eax
addl $-0x25, %eax
movl %eax, %ecx
movq %rcx, -0x2a0(%rbp)
subl $0x42, %eax
ja 0x17632
movq -0x2a0(%rbp), %rax
leaq 0xbdaf(%rip), %rcx      # 0x2330c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, -0x24(%rbp)
jl 0x17577
movl -0x24(%rbp), %eax
movl %eax, -0x2a4(%rbp)
jmp 0x17584
movl $0x6, %eax
movl %eax, -0x2a4(%rbp)
jmp 0x17584
movl -0x2a4(%rbp), %eax
movl %eax, -0x3c(%rbp)
movb -0x20(%rbp), %al
movb %al, -0x3d(%rbp)
jmp 0x1765d
cmpl $0x0, -0x24(%rbp)
je 0x175ca
cmpl $0x0, -0x24(%rbp)
jle 0x175af
movl -0x24(%rbp), %eax
movl %eax, -0x2a8(%rbp)
jmp 0x175bc
movl $0x6, %eax
movl %eax, -0x2a8(%rbp)
jmp 0x175bc
movl -0x2a8(%rbp), %eax
movl %eax, -0x2ac(%rbp)
jmp 0x175d7
movl $0x1, %eax
movl %eax, -0x2ac(%rbp)
jmp 0x175d7
movl -0x2ac(%rbp), %eax
movl %eax, -0x3c(%rbp)
movb -0x20(%rbp), %al
movb %al, -0x3d(%rbp)
jmp 0x1765d
cmpl $0x0, -0x24(%rbp)
jl 0x175f9
movl -0x24(%rbp), %eax
movl %eax, -0x2b0(%rbp)
jmp 0x17606
movl $0x6, %eax
movl %eax, -0x2b0(%rbp)
jmp 0x17606
movl -0x2b0(%rbp), %eax
movl %eax, -0x3c(%rbp)
movb $0x66, -0x3d(%rbp)
movss 0xba2d(%rip), %xmm0     # 0x23048
mulss -0x1c(%rbp), %xmm0
movss %xmm0, -0x1c(%rbp)
leaq 0xe28b(%rip), %rax      # 0x258b7
movq %rax, -0x38(%rbp)
jmp 0x1765d
cmpl $0x0, -0x24(%rbp)
jl 0x17643
movl -0x24(%rbp), %eax
movl %eax, -0x2b4(%rbp)
jmp 0x17650
movl $0x6, %eax
movl %eax, -0x2b4(%rbp)
jmp 0x17650
movl -0x2b4(%rbp), %eax
movl %eax, -0x3c(%rbp)
movb $0x67, -0x3d(%rbp)
leaq -0x240(%rbp), %rax
movq %rax, -0x248(%rbp)
movl $0x0, -0x24c(%rbp)
movss -0x1c(%rbp), %xmm0
callq 0x17a50
testb $0x1, %al
jne 0x17685
jmp 0x176e8
movsbl -0x20(%rbp), %edi
callq 0x10a0
cmpl $0x0, %eax
je 0x176a3
leaq 0xd71e(%rip), %rax      # 0x24db8
movq %rax, -0x2c0(%rbp)
jmp 0x176b3
leaq 0xd6da(%rip), %rax      # 0x24d84
movq %rax, -0x2c0(%rbp)
jmp 0x176b3
movq -0x2c0(%rbp), %rax
movq %rax, -0x258(%rbp)
leaq -0x240(%rbp), %rdi
movq -0x258(%rbp), %rsi
movl $0x3, %edx
callq 0x1060
movl $0x3, -0x24c(%rbp)
jmp 0x177be
movss -0x1c(%rbp), %xmm0
callq 0x17a70
testb $0x1, %al
jne 0x176f8
jmp 0x17758
movsbl -0x20(%rbp), %edi
callq 0x10a0
cmpl $0x0, %eax
je 0x17716
leaq 0xd762(%rip), %rax      # 0x24e6f
movq %rax, -0x2c8(%rbp)
jmp 0x17726
leaq 0xd721(%rip), %rax      # 0x24e3e
movq %rax, -0x2c8(%rbp)
jmp 0x17726
movq -0x2c8(%rbp), %rax
movq %rax, -0x260(%rbp)
leaq -0x240(%rbp), %rdi
movq -0x260(%rbp), %rsi
movl $0x3, %edx
callq 0x1060
movl $0x3, -0x24c(%rbp)
jmp 0x177bc
leaq -0x280(%rbp), %rdi
movl -0x3c(%rbp), %ecx
movsbl -0x3d(%rbp), %r8d
movq -0x38(%rbp), %r9
movl $0x11, %esi
leaq 0xe143(%rip), %rdx      # 0x258ba
movb $0x0, %al
callq 0x1120
leaq -0x240(%rbp), %rdi
leaq -0x280(%rbp), %rdx
movss -0x1c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movl $0x200, %esi            # imm = 0x200
movb $0x1, %al
callq 0x1120
subl $0x1, %eax
movl %eax, -0x24c(%rbp)
leaq -0x240(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x248(%rbp)
jmp 0x177be
movb $0x0, -0x281(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x1c(%rbp), %xmm0
jbe 0x177d7
movb $0x2d, -0x281(%rbp)
jmp 0x177f4
movsbl -0x2a(%rbp), %eax
cmpl $0x2b, %eax
je 0x177e9
movsbl -0x2a(%rbp), %eax
cmpl $0x20, %eax
jne 0x177f2
movb -0x2a(%rbp), %al
movb %al, -0x281(%rbp)
jmp 0x177f4
cmpb $0x0, -0x281(%rbp)
je 0x1780e
movl -0x24c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2cc(%rbp)
jmp 0x1781a
movl -0x24c(%rbp), %eax
movl %eax, -0x2cc(%rbp)
movl -0x2cc(%rbp), %eax
movl %eax, -0x288(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x16480
movl (%rax), %eax
movl %eax, -0x28c(%rbp)
movl $0x0, -0x290(%rbp)
movl $0x0, -0x294(%rbp)
movsbl -0x2b(%rbp), %eax
movl %eax, -0x2d0(%rbp)
subl $0x3c, %eax
je 0x17937
jmp 0x17867
movl -0x2d0(%rbp), %eax
subl $0x3e, %eax
je 0x1794b
jmp 0x17878
movl -0x2d0(%rbp), %eax
subl $0x5e, %eax
jne 0x1794d
jmp 0x17889
movl -0x28c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x2d8(%rbp)
movl -0x288(%rbp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x2d8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x290(%rbp)
movl -0x28c(%rbp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x2d4(%rbp)
movl -0x288(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x2d4(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x294(%rbp)
movl -0x28c(%rbp), %eax
andl $0x1, %eax
movl -0x288(%rbp), %ecx
andl $0x1, %ecx
andl %ecx, %eax
addl -0x290(%rbp), %eax
movl %eax, -0x290(%rbp)
movl -0x28c(%rbp), %ecx
andl $0x1, %ecx
movl -0x288(%rbp), %eax
andl $0x1, %eax
andl %eax, %ecx
movl -0x294(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x294(%rbp)
jmp 0x1795f
movl -0x28c(%rbp), %eax
subl -0x288(%rbp), %eax
movl %eax, -0x294(%rbp)
jmp 0x1795f
jmp 0x1794d
movl -0x28c(%rbp), %eax
subl -0x288(%rbp), %eax
movl %eax, -0x290(%rbp)
cmpb $0x0, -0x281(%rbp)
je 0x17981
movsbl -0x2b(%rbp), %eax
cmpl $0x3d, %eax
jne 0x17981
movq -0x10(%rbp), %rdi
movsbl -0x281(%rbp), %esi
callq 0x13fe0
cmpb $0x0, -0x2c(%rbp)
je 0x17992
movb -0x2c(%rbp), %al
movb %al, -0x2d9(%rbp)
jmp 0x1799c
movb $0x20, %al
movb %al, -0x2d9(%rbp)
jmp 0x1799c
movb -0x2d9(%rbp), %al
movb %al, -0x295(%rbp)
movl -0x290(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x290(%rbp)
cmpl $0x0, %eax
je 0x179d0
movq -0x10(%rbp), %rdi
movsbl -0x295(%rbp), %esi
callq 0x13fe0
jmp 0x179a8
cmpb $0x0, -0x281(%rbp)
je 0x179f2
movsbl -0x2b(%rbp), %eax
cmpl $0x3d, %eax
je 0x179f2
movq -0x10(%rbp), %rdi
movsbl -0x281(%rbp), %esi
callq 0x13fe0
movq -0x10(%rbp), %rdi
movslq -0x24c(%rbp), %rsi
movq -0x248(%rbp), %rdx
movq (%rdi), %rax
callq *(%rax)
movl -0x294(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x294(%rbp)
cmpl $0x0, %eax
je 0x17a31
movq -0x10(%rbp), %rdi
movsbl -0x295(%rbp), %esi
callq 0x13fe0
jmp 0x17a09
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)