// File: /workspace/github_cpp_makefile_star2_O2/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, %rax
movq (%rdi), %rdi
movslq 0x8(%rax), %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
movq %rcx, (%rsi)
orl $-0x1, 0x8(%rsi)
addq %rdi, %rax
movb $0x0, 0xc(%rsi)
xorl %r8d, %r8d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq 0xa68d(%rip), %rcx      # 0x1902c
movl $0x2, %ebx
movl $0x0, -0x2c(%rbp)
movl %edx, %r11d
xorl %r10d, %r10d
movq %rdi, %r15
cmpq %rax, %rdi
jae 0xec04
leaq 0x1(%r15), %r13
movb (%r15), %r14b
movzbl %r14b, %r9d
movl %r10d, %edi
movslq (%rcx,%rdi,4), %r12
addq %rcx, %r12
movq %r13, %rdi
jmpq *%r12
cmpq %rax, %r13
jae 0xeb69
movzbl (%r13), %edi
addl $-0x3c, %edi
cmpl $0x22, %edi
ja 0xeb69
movabsq $0x400000007, %r10      # imm = 0x400000007
btq %rdi, %r10
jae 0xeb69
movb %r14b, (%rsi)
movb 0x1(%r15), %r8b
addq $0x2, %r15
movb %r8b, 0x1(%rsi)
movl %r14d, %edi
movl %edi, -0x2c(%rbp)
movq %r15, %rdi
movl $0x1, %r10d
jmp 0xe9b1
cmpb $0x2e, %r14b
jne 0xeba6
movq %r15, %rdi
movl $0x5, %r10d
cmpq %rax, %r13
jae 0xe9b1
movq %r15, %rdi
testl %r11d, %r11d
jns 0xe9b1
movb (%r13), %r9b
addb $-0x30, %r9b
movq %r15, %rdi
cmpb $0x9, %r9b
ja 0xe9b1
andl $0x0, 0x8(%rsi)
xorl %r11d, %r11d
jmp 0xebde
movq %r15, %rdi
movl $0x3, %r10d
cmpb $0x23, %r14b
jne 0xe9b1
movb $0x1, 0x3(%rsi)
movq %r13, %rdi
jmp 0xe9b1
leal -0x30(%r14), %r9d
movq %r15, %rdi
movl $0x4, %r10d
cmpb $0x9, %r9b
ja 0xe9b1
testl %edx, %edx
jns 0xeae0
xorl %edx, %edx
cmpb $0x30, %r14b
jne 0xeae0
movl -0x2c(%rbp), %r10d
testb %r10b, %r10b
movzbl %r10b, %r10d
movl $0x30, %edi
cmovel %edi, %r10d
movl %r10d, -0x2c(%rbp)
movb %r10b, (%rsi)
testb %r8b, %r8b
movzbl %r8b, %r8d
movl $0x3d, %edi
cmovel %edi, %r8d
movb %r8b, 0x1(%rsi)
imull $0xa, %edx, %edi
movzbl %r9b, %edx
addl %edi, %edx
movl %edx, 0x4(%rsi)
movq %r13, %rdi
movl $0x3, %r10d
jmp 0xe9b1
movq %r15, %rdi
movl %ebx, %r10d
cmpl $0x2d, %r9d
ja 0xe9b1
movl %r9d, %edi
movabsq $0x280100000000, %r9    # imm = 0x280100000000
btq %rdi, %r9
movq %r15, %rdi
movl %ebx, %r10d
jae 0xe9b1
movb %r14b, 0x2(%rsi)
movq %r13, %rdi
movl %ebx, %r10d
jmp 0xe9b1
leal -0x45(%r9), %edi
cmpl $0x33, %edi
ja 0xebec
movabsq $0x84407e0080007, %r10  # imm = 0x84407E0080007
btq %rdi, %r10
jae 0xebec
movb %r14b, 0xc(%rsi)
movq %r13, %rdi
movl $0x6, %r10d
jmp 0xe9b1
addl $-0x3c, %r9d
movq %r15, %rdi
movl $0x1, %r10d
cmpl $0x22, %r9d
ja 0xe9b1
movabsq $0x400000007, %rdi      # imm = 0x400000007
btq %r9, %rdi
movq %r15, %rdi
jae 0xe9b1
movb %r14b, 0x1(%rsi)
movl %r14d, %r8d
movq %r13, %rdi
jmp 0xe9b1
addb $-0x30, %r14b
cmpb $0xa, %r14b
setb %dil
testl %r11d, %r11d
setns %r9b
andb %dil, %r9b
movq %r15, %rdi
movl $0x5, %r10d
cmpb $0x1, %r9b
jne 0xe9b1
imull $0xa, %r11d, %edi
movzbl %r14b, %r11d
addl %edi, %r11d
movl %r11d, 0x8(%rsi)
movq %r13, %rdi
movl $0x4, %r10d
jmp 0xe9b1
movq %r15, %rdi
movl $0x6, %r10d
cmpl $0x25, %r9d
je 0xeb57
jmp 0xe9b1
cmpq %rax, %r15
setae %al
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq