// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq %rdi, %r13
movb 0xc(%rsi), %r9b
movzbl %r9b, %esi
movl $0xa, %eax
cmpl $0x62, %esi
jle 0xfac1
cmpl $0x63, %esi
je 0xfaf0
cmpl $0x78, %esi
je 0xfaf0
cmpl $0x6f, %esi
jne 0xfaf5
movl $0x8, %edx
jmp 0xfad0
cmpl $0x58, %esi
je 0xfaf0
movl $0x2, %edx
cmpl $0x62, %esi
jne 0xfaf5
leaq -0x4d(%rbp), %r15
leaq -0x8d(%rbp), %rbx
cmpq $0x7f, %r8
seta %sil
orb %cl, %sil
xorl %r12d, %r12d
movb $0x1, %dil
movl %edx, %eax
jmp 0xfb35
movl $0x10, %eax
leaq -0x8d(%rbp), %rbx
cmpq $0x7f, %r8
seta %sil
orb %cl, %sil
cmpb $0x63, %r9b
jne 0xfb2b
leaq -0x4e(%rbp), %r15
testb %sil, %sil
je 0xfba2
movb $0x29, (%r15)
movb $0x1, %sil
movl $0x1, %r12d
xorl %edi, %edi
jmp 0xfb35
leaq -0x4d(%rbp), %r15
xorl %r12d, %r12d
movb $0x1, %dil
cmpb $0x58, %r9b
leaq 0xb739(%rip), %rdx      # 0x1b279
leaq 0xb744(%rip), %r11      # 0x1b28b
cmoveq %rdx, %r11
movl %eax, %r10d
movq %r8, %rax
xorl %edx, %edx
divq %r10
movb (%r11,%rdx), %dl
movb %dl, -0x1(%r15)
decq %r15
incl %r12d
cmpq %r10, %r8
movq %rax, %r8
jae 0xfb4e
xorl %eax, %eax
cmpb $0x1, 0x3(%r14)
jne 0xfbd2
cmpq $0x2, %r10
je 0xfbc1
cmpl $0x8, %r10d
je 0xfbb3
cmpl $0x10, %r10d
jne 0xfbd2
cmpb $0x58, %r9b
setne %al
shlb $0x5, %al
orb $0x58, %al
leaq -0x8f(%rbp), %rbx
movb %al, 0x1(%rbx)
movb $0x30, (%rbx)
jmp 0xfbcd
movb %r8b, (%r15)
movl $0x1, %r12d
xorl %edi, %edi
xorl %esi, %esi
xorl %eax, %eax
jmp 0xfbd2
leaq -0x8f(%rbp), %rbx
movw $0x6f30, (%rbx)         # imm = 0x6F30
jmp 0xfbcd
leaq -0x8f(%rbp), %rbx
movw $0x6230, (%rbx)         # imm = 0x6230
movl $0x2, %eax
movb $0x2d, %dl
testb %cl, %cl
jne 0xfbe7
movzbl 0x2(%r14), %edx
cmpl $0x2b, %edx
je 0xfbe7
cmpl $0x20, %edx
jne 0xfbf0
movb %dl, -0x1(%rbx)
decq %rbx
orl $0x1, %eax
xorb $0x1, %sil
orb %sil, %dil
jne 0xfc1d
testl %eax, %eax
je 0xfc10
movl %eax, %edx
subq %rdx, %r15
addl %eax, %r12d
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1060
movb $0x28, -0x1(%r15)
decq %r15
incl %r12d
xorl %eax, %eax
leal (%r12,%rax), %edx
movl 0x4(%r14), %esi
cmpl %edx, %esi
cmovlel %edx, %esi
movzbl 0x1(%r14), %ecx
cmpl $0x3c, %ecx
movq %rbx, -0x38(%rbp)
movq %r12, -0x40(%rbp)
je 0xfc7f
cmpl $0x5e, %ecx
jne 0xfc88
movl %esi, %ebx
shrl $0x1f, %ebx
addl %esi, %ebx
sarl %ebx
leal 0x1(%rdx), %edi
shrl $0x1f, %edi
addl %edx, %edi
incl %edi
sarl %edi
subl %edi, %ebx
leal 0x1(%rsi), %edi
shrl $0x1f, %edi
leal (%rsi,%rdi), %r12d
incl %r12d
sarl %r12d
movl %edx, %edi
shrl $0x1f, %edi
addl %edx, %edi
sarl %edi
andl %esi, %edx
andl $0x1, %edx
addl %edx, %ebx
addl %edi, %edx
subl %edx, %r12d
jmp 0xfc8f
subl %edx, %esi
xorl %ebx, %ebx
movl %esi, %r12d
jmp 0xfc8f
subl %edx, %esi
xorl %r12d, %r12d
movl %esi, %ebx
testl %eax, %eax
je 0xfca2
cmpl $0x3e, %ecx
je 0xfc9d
cmpl $0x5e, %ecx
jne 0xfcab
movl %eax, -0x30(%rbp)
jmp 0xfcc1
movl $0x0, -0x30(%rbp)
jmp 0xfcc1
movl $0x0, -0x30(%rbp)
movl %eax, %esi
movq %r13, %rdi
movq (%r13), %rax
movq -0x38(%rbp), %rdx
callq *(%rax)
movl (%r14), %eax
testb %al, %al
movl $0x20, %r14d
cmovnel %eax, %r14d
testl %ebx, %ebx
je 0xfcee
movb %r14b, -0x29(%rbp)
movq (%r13), %rax
movl $0x1, %esi
movq %r13, %rdi
leaq -0x29(%rbp), %rdx
callq *(%rax)
decl %ebx
jne 0xfcd4
movl -0x30(%rbp), %eax
testl %eax, %eax
je 0xfd04
movl %eax, %esi
movq (%r13), %rax
movq %r13, %rdi
movq -0x38(%rbp), %rdx
callq *(%rax)
movslq -0x40(%rbp), %rsi
movq (%r13), %rax
movq %r13, %rdi
movq %r15, %rdx
callq *(%rax)
testl %r12d, %r12d
je 0xfd37
leaq -0x29(%rbp), %rbx
movb %r14b, -0x29(%rbp)
movq (%r13), %rax
movl $0x1, %esi
movq %r13, %rdi
movq %rbx, %rdx
callq *(%rax)
decl %r12d
jne 0xfd1d
movb $0x1, %al
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq