// File: /workspace/github_cpp_makefile_star2_O3/rhoot[P]sp/tests/../include/sp.hpp
// Function: sp::parse_format(sp::StringView const&, sp::FormatFlags*)
inline bool parse_format(const StringView& fmt, FormatFlags* flags)
    {
        enum State {
            STATE_ALIGN,
            STATE_SIGN,
            STATE_ALTERNATE,
            STATE_WIDTH,
            STATE_PRECISION,
            STATE_TYPE,
            STATE_DONE,
        };

        auto state = STATE_ALIGN;
        auto next = fmt.ptr;
        auto term = fmt.ptr + fmt.length;
        *flags = FormatFlags{};

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

            switch (state) {
            case STATE_ALIGN: {
                const auto isAlign = [](char ch) {
                    return (ch >= '<' && ch <= '>') || ch == '^';
                };

                if (next < term && isAlign(*next)) {
                    flags->fill = ch;
                    flags->align = *next++;
                } else if (isAlign(ch)) {
                    flags->align = ch;
                } else {
                    --next;
                }

                state = STATE_SIGN;
                break;
            }

            case STATE_SIGN:
                switch (ch) {
                case '+':
                case '-':
                case ' ':
                    flags->sign = ch;
                    break;
                default:
                    --next;
                    break;
                }
                state = STATE_ALTERNATE;
                break;

            case STATE_ALTERNATE:
                if (ch == '#') {
                    flags->alternate = true;
                } else {
                    --next;
                }
                state = STATE_WIDTH;
                break;

            case STATE_WIDTH:
                if (ch >= '0' && ch <= '9') {
                    if (flags->width < 0) {
                        if (ch == '0') {
                            flags->fill = flags->fill ? flags->fill : '0';
                            flags->align = flags->align ? flags->align : '=';
                        }
                        flags->width = 0;
                    }
                    flags->width = (flags->width * 10) + (ch - '0');
                } else {
                    state = STATE_PRECISION;
                    --next;
                }
                break;

            case STATE_PRECISION: {
                const auto isDigit = [](char ch) {
                    return ch >= '0' && ch <= '9';
                };

                if (ch == '.') {
                    const char nextCh = (next < term) ? *next : 0;

                    if (flags->precision < 0 && isDigit(nextCh)) {
                        flags->precision = 0;
                        continue;
                    }
                } else if (isDigit(ch)) {
                    if (flags->precision >= 0) {
                        flags->precision = (flags->precision * 10) + (ch - '0');
                        continue;
                    }
                }

                state = STATE_TYPE;
                --next;
                break;
            }

            case STATE_TYPE:
                switch (ch) {
                case 'b':
                case 'd':
                case 'c':
                case 'e':
                case 'E':
                case 'f':
                case 'F':
                case 'g':
                case 'G':
                case 'o':
                case 's':
                case 'x':
                case 'X':
                case '%':
                    flags->type = ch;
                    break;
                default:
                    --next;
                    break;
                }
                state = STATE_DONE;
                break;

            case STATE_DONE:
                // if we get here, it means there's stuff in there after the
                // flags, in which case we should fail.
                return false;
            }
        }

        return true;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq (%rdi), %r13
movslq 0x8(%rdi), %rcx
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, (%rsi)
movl $0xffffffff, 0x8(%rsi)  # imm = 0xFFFFFFFF
movb $0x0, 0xc(%rsi)
movb $0x1, %al
testq %rcx, %rcx
jle 0xfa6e
addq %r13, %rcx
xorl %r8d, %r8d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
leaq 0x97c7(%rip), %rdx      # 0x1902c
xorl %eax, %eax
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r10d, %r10d
movabsq $0x84407e0080007, %r15  # imm = 0x84407E0080007
leaq 0x1(%r13), %rbx
cmpl $0x6, %r10d
ja 0xfa60
movb (%r13), %r9b
movzbl %r9b, %r14d
movl %r10d, %edi
movslq (%rdx,%rdi,4), %rdi
addq %rdx, %rdi
jmpq *%rdi
cmpq %rcx, %rbx
jae 0xf9f4
movzbl (%rbx), %r10d
addl $-0x3c, %r10d
cmpl $0x22, %r10d
ja 0xf9f4
movabsq $0x400000007, %rdi      # imm = 0x400000007
btq %r10, %rdi
jae 0xf9f4
movb %r9b, (%rsi)
movb 0x1(%r13), %r8b
addq $0x2, %r13
movb %r8b, 0x1(%rsi)
movl $0x1, %r10d
movl %r9d, %eax
jmp 0xfa5d
cmpb $0x2e, %r9b
jne 0xfa1d
movl $0x5, %r10d
cmpq %rcx, %rbx
jae 0xfa5d
testl %r12d, %r12d
jns 0xfa5d
movb (%rbx), %dil
addb $-0x30, %dil
cmpb $0x9, %dil
ja 0xfa5d
movl $0x0, 0x8(%rsi)
movl $0x4, %r10d
xorl %r12d, %r12d
jmp 0xfa60
movl $0x3, %r10d
cmpb $0x23, %r9b
jne 0xfa5d
movb $0x1, 0x3(%rsi)
jmp 0xfa60
leal -0x30(%r9), %r14d
movl $0x4, %r10d
cmpb $0x9, %r14b
ja 0xfa5d
testl %r11d, %r11d
jns 0xf98e
xorl %r11d, %r11d
cmpb $0x30, %r9b
jne 0xf98e
testb %al, %al
movzbl %al, %eax
movl $0x30, %edi
cmovel %edi, %eax
movb %al, (%rsi)
testb %r8b, %r8b
movzbl %r8b, %r8d
movl $0x3d, %edi
cmovel %edi, %r8d
movb %r8b, 0x1(%rsi)
leal (%r11,%r11,4), %edi
movzbl %r14b, %r9d
leal (%r9,%rdi,2), %r11d
movl %r11d, 0x4(%rsi)
movl $0x3, %r10d
jmp 0xfa60
movl $0x2, %r10d
cmpl $0x2d, %r14d
ja 0xfa5d
movl %r14d, %edi
movabsq $0x280100000000, %r14   # imm = 0x280100000000
btq %rdi, %r14
jae 0xfa5d
movb %r9b, 0x2(%rsi)
jmp 0xfa60
movl $0x6, %r10d
leal -0x45(%r14), %edi
cmpl $0x33, %edi
ja 0xfa57
btq %rdi, %r15
jae 0xfa57
movb %r9b, 0xc(%rsi)
jmp 0xfa60
movl $0x1, %r10d
addl $-0x3c, %r14d
cmpl $0x22, %r14d
ja 0xfa5d
movabsq $0x400000007, %rdi      # imm = 0x400000007
btq %r14, %rdi
jae 0xfa5d
movb %r9b, 0x1(%rsi)
movl %r9d, %r8d
jmp 0xfa60
addb $-0x30, %r9b
cmpb $0xa, %r9b
setb %dil
testl %r12d, %r12d
setns %r14b
andb %dil, %r14b
movl $0x5, %r10d
cmpb $0x1, %r14b
jne 0xfa5d
leal (%r12,%r12,4), %edi
movzbl %r9b, %r9d
leal (%r9,%rdi,2), %r12d
movl %r12d, 0x8(%rsi)
movl $0x4, %r10d
jmp 0xfa60
cmpl $0x25, %r14d
je 0xf9ee
movq %r13, %rbx
movq %rbx, %r13
cmpq %rcx, %rbx
jb 0xf87a
movb $0x1, %al
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0xfa6e