// File: 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
subq $0xf0, %rsp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq %rcx, -0x20(%rbp)
movl $0xa, -0x24(%rbp)
movq -0x10(%rbp), %rax
movsbl 0xc(%rax), %eax
addl $-0x58, %eax
movl %eax, %ecx
movq %rcx, -0xc0(%rbp)
subl $0x20, %eax
ja 0x15e2e
movq -0xc0(%rbp), %rax
leaq 0xd440(%rip), %rcx      # 0x2324c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x2, -0x24(%rbp)
jmp 0x15e2e
movl $0x8, -0x24(%rbp)
jmp 0x15e2e
movl $0x10, -0x24(%rbp)
leaq -0x70(%rbp), %rax
addq $0x43, %rax
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
movq -0x10(%rbp), %rax
movb 0xc(%rax), %al
movb %al, -0x89(%rbp)
movsbl -0x89(%rbp), %eax
cmpl $0x63, %eax
sete %al
andb $0x1, %al
movb %al, -0x8a(%rbp)
movb $0x1, %al
cmpq $0x80, -0x20(%rbp)
movb %al, -0xc1(%rbp)
jae 0x15e97
movb -0x11(%rbp), %al
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
andb $0x1, %al
movb %al, -0x8b(%rbp)
testb $0x1, -0x8a(%rbp)
je 0x15eee
testb $0x1, -0x8b(%rbp)
je 0x15ecc
movq -0x78(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x78(%rbp)
movb $0x29, -0x1(%rax)
jmp 0x15ee4
movq -0x20(%rbp), %rax
movb %al, %cl
movq -0x78(%rbp), %rax
movq %rax, %rdx
addq $-0x1, %rdx
movq %rdx, -0x78(%rbp)
movb %cl, -0x1(%rax)
movl $0x1, -0x84(%rbp)
testb $0x1, -0x8a(%rbp)
je 0x15f04
testb $0x1, -0x8b(%rbp)
je 0x1609f
movq -0x10(%rbp), %rax
movsbl 0xc(%rax), %eax
cmpl $0x58, %eax
jne 0x15f21
leaq 0xf973(%rip), %rax      # 0x2588b
movq %rax, -0xd0(%rbp)
jmp 0x15f31
leaq 0xf975(%rip), %rax      # 0x2589d
movq %rax, -0xd0(%rbp)
jmp 0x15f31
movq -0xd0(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xa0(%rbp), %rax
movslq -0x24(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movq -0xd8(%rbp), %rax
movb (%rax,%rdx), %cl
movq -0x78(%rbp), %rax
movq %rax, %rdx
addq $-0x1, %rdx
movq %rdx, -0x78(%rbp)
movb %cl, -0x1(%rax)
movslq -0x24(%rbp), %rcx
movq -0xa0(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq %rax, -0xa0(%rbp)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
cmpq $0x0, -0xa0(%rbp)
jne 0x15f4a
movq -0x10(%rbp), %rax
testb $0x1, 0x3(%rax)
je 0x1609d
movl -0x24(%rbp), %eax
movl %eax, -0xdc(%rbp)
subl $0x2, %eax
je 0x15fef
jmp 0x15fd2
movl -0xdc(%rbp), %eax
subl $0x8, %eax
je 0x16026
jmp 0x15fdf
movl -0xdc(%rbp), %eax
subl $0x10, %eax
je 0x1605d
jmp 0x1609b
movq -0x80(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x80(%rbp)
movb $0x62, -0x1(%rax)
movq -0x80(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x80(%rbp)
movb $0x30, -0x1(%rax)
movl -0x88(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x88(%rbp)
jmp 0x1609b
movq -0x80(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x80(%rbp)
movb $0x6f, -0x1(%rax)
movq -0x80(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x80(%rbp)
movb $0x30, -0x1(%rax)
movl -0x88(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x88(%rbp)
jmp 0x1609b
movq -0x98(%rbp), %rax
movb 0x10(%rax), %cl
movq -0x80(%rbp), %rax
movq %rax, %rdx
addq $-0x1, %rdx
movq %rdx, -0x80(%rbp)
movb %cl, -0x1(%rax)
movq -0x80(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x80(%rbp)
movb $0x30, -0x1(%rax)
movl -0x88(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x88(%rbp)
jmp 0x1609d
jmp 0x1609f
testb $0x1, -0x11(%rbp)
je 0x160c9
movq -0x80(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x80(%rbp)
movb $0x2d, -0x1(%rax)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x1610d
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x2b, %eax
je 0x160e3
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x20, %eax
jne 0x1610b
movq -0x10(%rbp), %rax
movb 0x2(%rax), %cl
movq -0x80(%rbp), %rax
movq %rax, %rdx
addq $-0x1, %rdx
movq %rdx, -0x80(%rbp)
movb %cl, -0x1(%rax)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x1610d
testb $0x1, -0x8a(%rbp)
je 0x16193
testb $0x1, -0x8b(%rbp)
je 0x16193
cmpl $0x0, -0x88(%rbp)
je 0x16171
movl -0x88(%rbp), %ecx
movq -0x78(%rbp), %rax
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movl -0x88(%rbp), %eax
addl -0x84(%rbp), %eax
movl %eax, -0x84(%rbp)
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
movslq -0x88(%rbp), %rdx
callq 0x10b0
movl $0x0, -0x88(%rbp)
movq -0x78(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x78(%rbp)
movb $0x28, -0x1(%rax)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
movl $0x0, -0xa4(%rbp)
movl $0x0, -0xa8(%rbp)
movl -0x84(%rbp), %eax
movl -0x88(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rdi
addq $0x4, %rdi
leaq -0xac(%rbp), %rsi
callq 0x16480
movl (%rax), %eax
movl %eax, -0xb0(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
movl %eax, -0xe0(%rbp)
subl $0x3c, %eax
je 0x162c3
jmp 0x161f0
movl -0xe0(%rbp), %eax
addl $-0x3d, %eax
subl $0x2, %eax
jb 0x162d7
jmp 0x16204
movl -0xe0(%rbp), %eax
subl $0x5e, %eax
jne 0x162d9
jmp 0x16215
movl -0xb0(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0xe8(%rbp)
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xe8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xa4(%rbp)
movl -0xb0(%rbp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0xe4(%rbp)
movl -0xac(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xe4(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xa8(%rbp)
movl -0xb0(%rbp), %eax
andl $0x1, %eax
movl -0xac(%rbp), %ecx
andl $0x1, %ecx
andl %ecx, %eax
addl -0xa4(%rbp), %eax
movl %eax, -0xa4(%rbp)
movl -0xb0(%rbp), %ecx
andl $0x1, %ecx
movl -0xac(%rbp), %eax
andl $0x1, %eax
andl %eax, %ecx
movl -0xa8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xa8(%rbp)
jmp 0x162eb
movl -0xb0(%rbp), %eax
subl -0xac(%rbp), %eax
movl %eax, -0xa8(%rbp)
jmp 0x162eb
jmp 0x162d9
movl -0xb0(%rbp), %eax
subl -0xac(%rbp), %eax
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0x88(%rbp)
je 0x1634a
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
movl %eax, -0xec(%rbp)
addl $-0x3c, %eax
subl $0x2, %eax
jb 0x16328
jmp 0x1630c
movl -0xec(%rbp), %eax
subl $0x3e, %eax
je 0x16326
jmp 0x16319
movl -0xec(%rbp), %eax
subl $0x5e, %eax
jne 0x1632a
jmp 0x16326
jmp 0x16348
jmp 0x1632a
movq -0x8(%rbp), %rdi
movslq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
movq (%rdi), %rax
callq *(%rax)
movl $0x0, -0x88(%rbp)
jmp 0x1634a
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0x16361
movq -0x10(%rbp), %rax
movb (%rax), %al
movb %al, -0xed(%rbp)
jmp 0x1636b
movb $0x20, %al
movb %al, -0xed(%rbp)
jmp 0x1636b
movb -0xed(%rbp), %al
movb %al, -0xb1(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0xa4(%rbp)
cmpl $0x0, %eax
je 0x1639f
movq -0x8(%rbp), %rdi
movsbl -0xb1(%rbp), %esi
callq 0x13fe0
jmp 0x16377
cmpl $0x0, -0x88(%rbp)
je 0x163bc
movq -0x8(%rbp), %rdi
movslq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
movq (%rdi), %rax
callq *(%rax)
movq -0x8(%rbp), %rdi
movslq -0x84(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq (%rdi), %rax
callq *(%rax)
movl -0xa8(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0xa8(%rbp)
cmpl $0x0, %eax
je 0x163f8
movq -0x8(%rbp), %rdi
movsbl -0xb1(%rbp), %esi
callq 0x13fe0
jmp 0x163d0
movb $0x1, %al
andb $0x1, %al
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop