// File: /workspace/github_c_makefile_star2_O0/lengjingzju[P]json/grisu2.c
// Function: prettify_string
static inline int prettify_string(char* buffer, int length, int K)
{
    /*
     * v = buffer * 10^k
     * kk is such that 10^(kk-1) <= v < 10^kk
     * this way kk gives the position of the comma.
     */
    const int kk = length + K;
    int offset;

    if (kk <= 21) {
        if (length <= kk) {
            /*
             * 1234e7 -> 12340000000
             * the first digits are already in. Add some 0s and call it a day.
             * the 21 is a personal choice. Only 16 digits could possibly be relevant.
             * Basically we want to print 12340000000 rather than 1234.0e7 or 1.234e10
             */
            memset(&buffer[length], '0', K);
            buffer[kk] = '.';
            buffer[kk + 1] = '0';
            buffer[kk + 2] = '\0';
            return (kk + 2);
        }

        if (kk > 0) {
            /*
             * 1234e-2 -> 12.34
             * comma number. Just insert a '.' at the correct location.
             */
            memmove(&buffer[kk + 1], &buffer[kk], length - kk);
            buffer[kk] = '.';
            buffer[length + 1] = '\0';
            return length + 1;
        }

        if (kk > -6) {
            /*
             * 1234e-6 -> 0.001234
             * something like 0.000abcde.
             * add '0.' and some '0's
             */
            offset = 2 - kk;
            memmove(&buffer[offset], &buffer[0], length);
            buffer[0] = '0';
            buffer[1] = '.';
            memset(&buffer[2], '0', offset - 2);
            buffer[length + offset] = '\0';
            return length + offset;
        }
    }

    if (length == 1) {
        /*
         * 1e30
         * just add 'e...'
         * fill_positive_fixnum will terminate the string
         */
        buffer[1] = 'e';
        return (2 + fill_exponent(kk - 1, &buffer[2]));
    }

    /*
     * 1234e30 -> 1.234e33
     * leave the first digit. then add a '.' and at the end 'e...'
     * fill_fixnum will terminate the string.
     */
    memmove(&buffer[2], &buffer[1], length - 1);
    buffer[1] = '.';
    buffer[length + 1] = 'e';
    return (length + 2 + fill_exponent(kk - 1, &buffer[length + 2]));
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movl %esi, 0x14(%rsp)
movl %edx, 0x10(%rsp)
movl 0x14(%rsp), %eax
addl 0x10(%rsp), %eax
movl %eax, 0xc(%rsp)
cmpl $0x15, 0xc(%rsp)
jg 0x46cd
movl 0x14(%rsp), %eax
cmpl 0xc(%rsp), %eax
jg 0x45e2
movq 0x18(%rsp), %rdi
movslq 0x14(%rsp), %rax
addq %rax, %rdi
movslq 0x10(%rsp), %rdx
movl $0x30, %esi
callq 0x1070
movq 0x18(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x2e, (%rax,%rcx)
movq 0x18(%rsp), %rax
movl 0xc(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb $0x30, (%rax,%rcx)
movq 0x18(%rsp), %rax
movl 0xc(%rsp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x24(%rsp)
jmp 0x476c
cmpl $0x0, 0xc(%rsp)
jle 0x4648
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %eax
addl $0x1, %eax
cltq
addq %rax, %rdi
movq 0x18(%rsp), %rsi
movslq 0xc(%rsp), %rax
addq %rax, %rsi
movl 0x14(%rsp), %eax
subl 0xc(%rsp), %eax
movslq %eax, %rdx
callq 0x1090
movq 0x18(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x2e, (%rax,%rcx)
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x476c
cmpl $-0x6, 0xc(%rsp)
jle 0x46cb
movl $0x2, %eax
subl 0xc(%rsp), %eax
movl %eax, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movslq 0x8(%rsp), %rax
addq %rax, %rdi
movq 0x18(%rsp), %rsi
movslq 0x14(%rsp), %rdx
callq 0x1090
movq 0x18(%rsp), %rax
movb $0x30, (%rax)
movq 0x18(%rsp), %rax
movb $0x2e, 0x1(%rax)
movq 0x18(%rsp), %rdi
addq $0x2, %rdi
movl 0x8(%rsp), %eax
subl $0x2, %eax
movslq %eax, %rdx
movl $0x30, %esi
callq 0x1070
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
addl 0x8(%rsp), %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl 0x14(%rsp), %eax
addl 0x8(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0x476c
jmp 0x46cd
cmpl $0x1, 0x14(%rsp)
jne 0x46fb
movq 0x18(%rsp), %rax
movb $0x65, 0x1(%rax)
movl 0xc(%rsp), %edi
subl $0x1, %edi
movq 0x18(%rsp), %rsi
addq $0x2, %rsi
callq 0x4e70
addl $0x2, %eax
movl %eax, 0x24(%rsp)
jmp 0x476c
movq 0x18(%rsp), %rdi
addq $0x2, %rdi
movq 0x18(%rsp), %rsi
addq $0x1, %rsi
movl 0x14(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rdx
callq 0x1090
movq 0x18(%rsp), %rax
movb $0x2e, 0x1(%rax)
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb $0x65, (%rax,%rcx)
movl 0x14(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x4(%rsp)
movl 0xc(%rsp), %edi
subl $0x1, %edi
movq 0x18(%rsp), %rsi
movl 0x14(%rsp), %eax
addl $0x2, %eax
cltq
addq %rax, %rsi
callq 0x4e70
movl %eax, %ecx
movl 0x4(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)
nop