// File: /workspace/github_cpp_makefile_star2_O2/rhoot[P]sp/tests/../include/sp.hpp
// Function: void sp::do_format<int>(sp::IWriter&, sp::StringView const&, int*, int&&)
void do_format(IWriter& writer, const StringView& fmt, int32_t* prevIndex, Args&&... args)
    {
        enum State {
            STATE_OPENER,
            STATE_INDEX,
            STATE_MARKER,
            STATE_FLAGS,
            STATE_CLOSER,
        };

        auto state = STATE_OPENER;
        auto next = fmt.ptr;
        auto start = fmt.ptr;
        auto term = fmt.ptr + fmt.length;

        const char* formatStart = nullptr;
        auto index = -1;
        auto opened = 0;
        auto nested = false;

        while (next < term) {
            const auto ptr = next++;
            const auto ch = *ptr;

            switch (state) {
            case STATE_OPENER:
                if (ch == '{') {
                    writer.write(int32_t(ptr - start), start);

                    if (next < term) {
                        if (*next != '{') {
                            index = -1;
                            start = ptr;
                            nested = false;
                            formatStart = nullptr;
                            state = STATE_INDEX;
                        } else {
                            start = next++;
                        }
                    }
                } else if (ch == '}') {
                    writer.write(int32_t(next - start), start);
                    if (next < term && *next == '}') {
                        ++next;
                    }
                    start = next;
                }
                break;

            case STATE_INDEX:
                if (ch >= '0' && ch <= '9') {
                    index = (index < 0)
                        ? (ch - '0')
                        : (index * 10) + (ch - '0');
                } else {
                    if (index < 0) {
                        index = *prevIndex + 1;
                    }
                    *prevIndex = index;
                    state = STATE_MARKER;
                    --next;
                }
                break;

            case STATE_MARKER:
                if (ch == ':') {
                    state = STATE_FLAGS;
                } else {
                    state = STATE_CLOSER;
                    --next;
                }
                break;

            case STATE_FLAGS:
                if (!formatStart) {
                    formatStart = ptr;
                }

                switch (ch) {
                case '{':
                    ++opened;
                    nested = true;
                    break;
                case '}':
                    if (opened > 0) {
                        --opened;
                    }
                    else {
                        state = STATE_CLOSER;
                        --next;
                    }
                    break;
                }

                break;

            case STATE_CLOSER:
                if (ch == '}') {
                    StringView format = formatStart
                        ? StringView(formatStart, int32_t(ptr - formatStart))
                        : StringView();

                    // handle nested format specifiers
                    char buffer[64];

                    if (nested) {
                        StringWriter nestedWriter(buffer, sizeof(buffer));
                        sp::do_format(nestedWriter, format, prevIndex, std::forward<Args>(args)...);
                        const auto fullLen = nestedWriter.result();
                        const auto realLen = std::min(size_t(fullLen), sizeof(buffer));
                        format = StringView(buffer, int32_t(realLen));
                    }

                    if (format_index(writer, format, index, std::forward<Args>(args)...)) {
                        start = next;
                    }
                }
                state = STATE_OPENER;
                break;
            }
        }

        // Print remaining data
        if (start != term) {
            writer.write(int32_t(term - start), start);
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, -0x58(%rbp)
movq %rdx, -0x40(%rbp)
movq %rdi, -0x38(%rbp)
movq (%rsi), %r11
movslq 0x8(%rsi), %r9
addq %r11, %r9
pushq $-0x1
popq %rax
leaq 0xaa41(%rip), %r10      # 0x19018
movl $0x0, -0x2c(%rbp)
xorl %ecx, %ecx
xorl %edx, %edx
movq %r11, %rdi
xorl %esi, %esi
movq %r9, -0x48(%rbp)
cmpq %r9, %rdi
jae 0xe8b5
movq %rdi, %r12
movq %rdx, %rbx
movl %ecx, %r15d
movl %eax, %r13d
leaq 0x1(%rdi), %r14
movq %r14, %rdi
cmpl $0x4, %esi
ja 0xe5eb
movzbl (%r12), %r8d
movl %esi, %eax
movslq (%r10,%rax,4), %rax
addq %r10, %rax
jmpq *%rax
cmpl $0x7d, %r8d
je 0xe853
movl %r13d, %eax
movl %r15d, %ecx
movq %rbx, %rdx
movq %r14, %rdi
movl $0x0, %esi
cmpl $0x7b, %r8d
jne 0xe5eb
movl %r12d, %eax
subl %r11d, %eax
movslq %eax, %rsi
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
movq %r11, %rdx
movq %r11, -0x50(%rbp)
callq *(%rax)
movq -0x50(%rbp), %r11
leaq 0xa9b7(%rip), %r10      # 0x19018
movq -0x48(%rbp), %r9
movl %r13d, %eax
movl %r15d, %ecx
movq %rbx, %rdx
movq %r14, %rdi
movl $0x0, %esi
cmpq %r9, %r14
jae 0xe5eb
xorl %ecx, %ecx
cmpb $0x7b, (%r14)
pushq $-0x1
popq %rax
movl $0x0, %edx
movq %r12, %r11
movq %r14, %rdi
pushq $0x1
popq %rsi
jne 0xe5eb
addq $0x2, %r12
movl %r13d, %eax
movl %r15d, %ecx
movq %rbx, %rdx
movq %r14, %r11
movq %r12, %rdi
xorl %esi, %esi
jmp 0xe5eb
movl %r13d, %eax
movl %r15d, %ecx
movq %rbx, %rdx
movq %r14, %rdi
movl $0x0, %esi
cmpl $0x7d, %r8d
jne 0xe5eb
movq %r11, -0x50(%rbp)
subl %ebx, %r12d
testq %rbx, %rbx
movl $0x0, %eax
cmovel %eax, %r12d
movq %rbx, -0x68(%rbp)
movl %r12d, -0x60(%rbp)
testb $0x1, %r15b
je 0xe738
leaq 0x10667(%rip), %rax     # 0x1ed60
movq %rax, -0x80(%rbp)
leaq -0xc0(%rbp), %r12
movq %r12, -0x78(%rbp)
movq $0x40, -0x70(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0xe5a3
movl -0x6c(%rbp), %eax
cmpl $0x40, %eax
pushq $0x40
popq %rcx
cmovael %ecx, %eax
movq %r12, -0x68(%rbp)
movl %eax, -0x60(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movl %r13d, %edx
movq -0x58(%rbp), %rcx
callq 0xe8de
movq %r14, %r11
testb %al, %al
jne 0xe757
movq -0x50(%rbp), %r11
movl %r13d, %eax
movl %r15d, %ecx
movq %rbx, %rdx
movq %r14, %rdi
xorl %esi, %esi
movq -0x48(%rbp), %r9
leaq 0xa8a8(%rip), %r10      # 0x19018
jmp 0xe5eb
cmpl $0x3a, %r8d
je 0xe77e
movq %r12, %r14
setne %al
movzbl %al, %esi
addl $0x3, %esi
movl %r13d, %eax
movl %r15d, %ecx
jmp 0xe7c1
testq %rbx, %rbx
cmoveq %r12, %rbx
movl %r13d, %eax
cmpl $0x7d, %r8d
je 0xe826
movl %r15d, %ecx
movq %rbx, %rdx
movq %r14, %rdi
pushq $0x3
popq %rsi
cmpl $0x7b, %r8d
jne 0xe5eb
incl -0x2c(%rbp)
movb $0x1, %cl
movl %r13d, %eax
movq %rbx, %rdx
movq %r14, %rdi
jmp 0xe5eb
addb $-0x30, %r8b
cmpb $0x9, %r8b
ja 0xe7fc
imull $0xa, %r13d, %eax
testl %r13d, %r13d
movzbl %r8b, %ecx
movl $0x0, %edx
cmovsl %edx, %eax
addl %ecx, %eax
movl %r15d, %ecx
movq %rbx, %rdx
movq %r14, %rdi
pushq $0x1
popq %rsi
jmp 0xe5eb
testl %r13d, %r13d
jns 0xe80b
movq -0x40(%rbp), %rax
movl (%rax), %r13d
incl %r13d
movq -0x40(%rbp), %rax
movl %r13d, (%rax)
movl %r13d, %eax
movl %r15d, %ecx
movq %rbx, %rdx
movq %r12, %rdi
pushq $0x2
popq %rsi
jmp 0xe5eb
movl %r15d, %ecx
movq %rbx, %rdx
movq %r12, %rdi
pushq $0x4
popq %rsi
cmpl $0x0, -0x2c(%rbp)
jle 0xe5eb
decl -0x2c(%rbp)
movl %r13d, %eax
movl %r15d, %ecx
movq %rbx, %rdx
movq %r14, %rdi
pushq $0x3
popq %rsi
jmp 0xe5eb
movl %r14d, %eax
subl %r11d, %eax
movslq %eax, %rsi
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
movq %r11, %rdx
callq *(%rax)
leaq 0xa7a9(%rip), %r10      # 0x19018
movq -0x48(%rbp), %r9
movl %r13d, %eax
movl %r15d, %ecx
movq %rbx, %rdx
movq %r14, %r11
movq %r14, %rdi
movl $0x0, %esi
cmpq %r9, %r14
jae 0xe5eb
cmpb $0x7d, 0x1(%r12)
jne 0xe89f
addq $0x2, %r12
movq %r12, %r14
movl %r13d, %eax
movl %r15d, %ecx
movq %rbx, %rdx
movq %r14, %r11
movq %r14, %rdi
xorl %esi, %esi
jmp 0xe5eb
cmpq %r9, %r11
je 0xe8cc
subl %r11d, %r9d
movslq %r9d, %rsi
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
movq %r11, %rdx
callq *(%rax)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq