// File: /workspace/github_cpp_makefile_star2_O2/rhoot[P]sp/tests/../include/sp.hpp
// Function: sp::format_int(sp::IWriter&, sp::FormatFlags const&, bool, unsigned long)
inline bool format_int(IWriter& writer, const FormatFlags& flags, bool isNegative, uint64_t value)
    {
        // determine base
        int32_t base = 10;

        switch (flags.type) {
        case 'b':
            base = 2;
            break;
        case 'o':
            base = 8;
            break;
        case 'c':
        case 'x':
        case 'X':
            base = 16;
            break;
        }

        // count digits, and copy them to a buffer (so we don't have to repeat
        // this later)
        char buffer[67]; // max needed; 64-bit binary + sign + alternate prefix
        char* digits = buffer + sizeof(buffer);
        char* prefix = buffer + 3;
        int32_t ndigits = 0;
        int32_t nprefix = 0;
        char type = flags.type;

        const bool isChar = type == 'c';
        const bool charAsHex = (value >= 0x80 || isNegative);

        if (isChar) {
            if (charAsHex) {
                *(--digits) = ')';
            } else {
                *(--digits) = char(value);
            }
            ndigits = 1;
        }

        if (!isChar || charAsHex) {
            const auto digitchars = (flags.type == 'X')
                ? "0123456789ABCDEFX"
                : "0123456789abcdefx";

            uint64_t v = value;
            do {
                *(--digits) = digitchars[v % base];
                v /= base;
                ++ndigits;
            } while (v);

            if (flags.alternate) {
                switch (base) {
                case 2:
                    *(--prefix) = 'b';
                    *(--prefix) = '0';
                    nprefix += 2;
                    break;
                case 8:
                    *(--prefix) = 'o';
                    *(--prefix) = '0';
                    nprefix += 2;
                    break;
                case 16:
                    *(--prefix) = digitchars[16];
                    *(--prefix) = '0';
                    nprefix += 2;
                    break;
                }
            }
        }

        // determine sign
        if (isNegative) {
            *(--prefix) = '-';
            ++nprefix;
        } else if (flags.sign == '+' || flags.sign == ' ') {
            *(--prefix) = flags.sign;
            ++nprefix;
        }

        // for hex chars, the prefix should be part of the value
        if (isChar && charAsHex) {
            if (nprefix) {
                digits -= nprefix;
                ndigits += nprefix;
                memcpy(digits, prefix, nprefix);
                nprefix = 0;
            }
            *(--digits) = '(';
            ++ndigits;
        }

        // determine spacing
        int32_t leadSpace = 0;
        int32_t tailSpace = 0;
        {
            int32_t nchars = ndigits + nprefix;
            int32_t width = std::max(flags.width, nchars);

            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 '>':
            case '=':
            default:
                leadSpace = width - nchars;
                break;
            }
        }

        // print sign and alternate prefix, if they should be before the padding
        if (nprefix) {
            switch (flags.align) {
            case '^':
            case '>':
                break;
            case '<':
            case '=':
            default:
                writer.write(nprefix, prefix);
                nprefix = 0;
                break;
            }
        }

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

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

        // print the prefix, if it should be after the padding
        if (nprefix) {
            writer.write(nprefix, prefix);
        }

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

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

        return true;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r8
movl %edx, %ecx
movq %rsi, %rbx
movq %rdi, %r12
movzbl 0xc(%rsi), %r10d
cmpl $0x58, %r10d
je 0xec58
cmpl $0x62, %r10d
je 0xec5c
cmpl $0x63, %r10d
je 0xec58
cmpl $0x78, %r10d
je 0xec58
cmpl $0x6f, %r10d
jne 0xec77
pushq $0x8
jmp 0xec5e
pushq $0x10
jmp 0xec79
pushq $0x2
popq %rax
leaq -0x4d(%rbp), %r15
cmpq $0x7f, %r8
seta %sil
leaq -0x8d(%rbp), %r13
orb %cl, %sil
jmp 0xecb2
pushq $0xa
popq %rax
leaq -0x8d(%rbp), %r13
cmpq $0x7f, %r8
seta %sil
orb %cl, %sil
cmpb $0x63, %r10b
jne 0xecae
leaq -0x4e(%rbp), %r15
testb %sil, %sil
je 0xed28
movb $0x29, (%r15)
movb $0x1, %sil
pushq $0x1
popq %r14
xorl %edi, %edi
jmp 0xecb8
leaq -0x4d(%rbp), %r15
xorl %r14d, %r14d
movb $0x1, %dil
cmpb $0x58, %r10b
leaq 0xc5c6(%rip), %rdx      # 0x1b289
leaq 0xc5d1(%rip), %r9       # 0x1b29b
cmoveq %rdx, %r9
movl %eax, %r11d
movq %r8, %rax
xorl %edx, %edx
divq %r11
movb (%r9,%rdx), %dl
movb %dl, -0x1(%r15)
decq %r15
incl %r14d
cmpq %r11, %r8
movq %rax, %r8
jae 0xecd1
xorl %r9d, %r9d
cmpb $0x1, 0x3(%rbx)
jne 0xed5a
cmpq $0x2, %r11
je 0xed48
cmpl $0x8, %r11d
je 0xed38
cmpl $0x10, %r11d
jne 0xed5a
cmpb $0x58, %r10b
setne %al
shlb $0x5, %al
orb $0x58, %al
leaq -0x8f(%rbp), %r13
movb %al, 0x1(%r13)
movb $0x30, (%r13)
jmp 0xed56
pushq $0x1
popq %r14
movb %r8b, (%r15)
xorl %edi, %edi
xorl %esi, %esi
xorl %r9d, %r9d
jmp 0xed5a
leaq -0x8f(%rbp), %r13
movw $0x6f30, (%r13)         # imm = 0x6F30
jmp 0xed56
leaq -0x8f(%rbp), %r13
movw $0x6230, (%r13)         # imm = 0x6230
pushq $0x2
popq %r9
movb $0x2d, %al
testb %cl, %cl
jne 0xed6e
movzbl 0x2(%rbx), %eax
cmpl $0x2b, %eax
je 0xed6e
cmpl $0x20, %eax
jne 0xed79
movb %al, -0x1(%r13)
decq %r13
orl $0x1, %r9d
xorb $0x1, %sil
orb %sil, %dil
jne 0xeda9
testl %r9d, %r9d
je 0xed9b
movl %r9d, %edx
subq %rdx, %r15
addl %r9d, %r14d
movq %r15, %rdi
movq %r13, %rsi
callq 0x1070
movb $0x28, -0x1(%r15)
decq %r15
incl %r14d
xorl %r9d, %r9d
leal (%r14,%r9), %ecx
movl 0x4(%rbx), %esi
cmpl %ecx, %esi
cmovlel %ecx, %esi
movzbl 0x1(%rbx), %r10d
cmpl $0x3c, %r10d
movq %r12, -0x38(%rbp)
movq %r13, -0x40(%rbp)
je 0xee0e
cmpl $0x5e, %r10d
jne 0xee18
pushq $0x2
popq %r8
movl %esi, %eax
cltd
idivl %r8d
movl %eax, %edi
leal 0x1(%rcx), %eax
pushq $-0x2
popq %r11
cltd
idivl %r11d
movl %eax, %r12d
leal 0x1(%rsi), %eax
cltd
idivl %r8d
movl %eax, %r8d
movl %ecx, %eax
cltd
idivl %r11d
movl %eax, %r13d
andl %esi, %ecx
andl $0x1, %ecx
addl %ecx, %r12d
addl %edi, %r12d
subl %ecx, %r13d
addl %r8d, %r13d
jmp 0xee20
subl %ecx, %esi
xorl %r12d, %r12d
movl %esi, %r13d
jmp 0xee20
subl %ecx, %esi
xorl %r13d, %r13d
movl %esi, %r12d
testl %r9d, %r9d
je 0xee37
cmpl $0x3e, %r10d
je 0xee31
cmpl $0x5e, %r10d
jne 0xee40
movl %r9d, -0x30(%rbp)
jmp 0xee57
movl $0x0, -0x30(%rbp)
jmp 0xee57
movl $0x0, -0x30(%rbp)
movl %r9d, %esi
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
movq -0x40(%rbp), %rdx
callq *(%rax)
movl (%rbx), %eax
testb %al, %al
pushq $0x20
popq %rbx
cmovnel %eax, %ebx
subl $0x1, %r12d
jb 0xee7c
movb %bl, -0x29(%rbp)
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
pushq $0x1
popq %rsi
leaq -0x29(%rbp), %rdx
callq *(%rax)
jmp 0xee61
movl -0x30(%rbp), %eax
testl %eax, %eax
movq -0x38(%rbp), %r12
je 0xee96
movl %eax, %esi
movq (%r12), %rax
movq %r12, %rdi
movq -0x40(%rbp), %rdx
callq *(%rax)
movslq %r14d, %rsi
movq (%r12), %rax
movq %r12, %rdi
movq %r15, %rdx
callq *(%rax)
pushq $0x1
popq %r14
leaq -0x29(%rbp), %r15
subl $0x1, %r13d
jb 0xeec7
movb %bl, -0x29(%rbp)
movq (%r12), %rax
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq *(%rax)
jmp 0xeead
movb $0x1, %al
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq