// File: rhoot[P]sp/tests/../include/sp.hpp
// Function: sp::format_string(sp::IWriter&, sp::FormatFlags const&, sp::StringView const&)
inline bool format_string(IWriter& writer, const sp::FormatFlags& flags, const StringView& str)
    {
        // determine the amount of characters to write
        auto nchars = str.length;

        if (flags.precision >= 0) {
            nchars = std::min(flags.precision, nchars);
        }

        // determine width
        const int32_t width = std::max(flags.width, nchars);

        // determine alignment
        int32_t leadSpace = 0;
        int32_t tailSpace = 0;

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

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

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

        // write string
        writer.write(nchars, str.ptr);

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

        return true;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jl 0x17b8e
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
leaq -0x1c(%rbp), %rsi
callq 0x17cf0
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x4, %rdi
leaq -0x1c(%rbp), %rsi
callq 0x16480
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
movl %eax, -0x30(%rbp)
subl $0x3c, %eax
je 0x17c67
jmp 0x17bc8
movl -0x30(%rbp), %eax
subl $0x3e, %eax
je 0x17c5c
jmp 0x17bd6
movl -0x30(%rbp), %eax
subl $0x5e, %eax
jne 0x17c69
jmp 0x17be4
movl -0x20(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x38(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x38(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x34(%rbp)
movl -0x1c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
andl $0x1, %eax
movl -0x1c(%rbp), %ecx
andl $0x1, %ecx
andl %ecx, %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %ecx
andl $0x1, %ecx
movl -0x1c(%rbp), %eax
andl $0x1, %eax
andl %eax, %ecx
movl -0x28(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x28(%rbp)
jmp 0x17c72
movl -0x20(%rbp), %eax
subl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x17c72
jmp 0x17c69
movl -0x20(%rbp), %eax
subl -0x1c(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0x17c86
movq -0x10(%rbp), %rax
movb (%rax), %al
movb %al, -0x39(%rbp)
jmp 0x17c8d
movb $0x20, %al
movb %al, -0x39(%rbp)
jmp 0x17c8d
movb -0x39(%rbp), %al
movb %al, -0x29(%rbp)
movl -0x24(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x24(%rbp)
cmpl $0x0, %eax
je 0x17cb2
movq -0x8(%rbp), %rdi
movsbl -0x29(%rbp), %esi
callq 0x13fe0
jmp 0x17c93
movq -0x8(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
movq (%rdi), %rax
callq *(%rax)
movl -0x28(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x28(%rbp)
cmpl $0x0, %eax
je 0x17ce5
movq -0x8(%rbp), %rdi
movsbl -0x29(%rbp), %esi
callq 0x13fe0
jmp 0x17cc6
movb $0x1, %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nop