// File: /workspace/github_cpp_makefile_star2_O2/jovermann[P]streplace/src/MiscUtils.cpp
// Function: ut1::expandUnprintable(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, char, char)
std::string expandUnprintable(const std::string& s, char quotes, char addQuotes)
{
    std::string r;
    char        buf[4];

    if (addQuotes)
    {
        r += addQuotes;
    }

    for (const char& c: s)
    {
        if (isprint(c))
        {
            if ((c == '\\') || (quotes && (c == quotes)))
            {
                // Backslashify backslash and quotes.
                r += '\\';
            }
            r += c;
        }
        else
        {
            // Unprintable char.
            r += '\\'; // Leading backslash.
            switch (c)
            {
                // Named control chars.
            case '\a': r += 'a'; break;
            case '\b': r += 'b'; break;
            case '\f': r += 'f'; break;
            case '\n': r += 'n'; break;
            case '\r': r += 'r'; break;
            case '\t': r += 't'; break;
            case '\v': r += 'v'; break;
            default:
                // Hex/octal byte.
                char next = *(&c + 1);
                if (std::isxdigit(unsigned(next)))
                {
                    // Next digit is a valid hex digit:
                    // Use 3-digit octal variant to limit the length of the numeric escape sequence.
                    std::snprintf(buf, sizeof(buf), "%03o", uint8_t(c));
                }
                else
                {
                    // Hex byte.
                    std::snprintf(buf, sizeof(buf), "x%02x", uint8_t(c));
                }
                r += buf;
                break;
            }
        }
    }

    if (addQuotes)
    {
        r += addQuotes;
    }

    return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, 0x10(%rsp)
movq %rdi, %r14
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
movq %rsi, %r15
movb $0x0, 0x10(%rdi)
movsbl %cl, %ebp
movl %ecx, 0xc(%rsp)
testb %cl, %cl
je 0x8d79
movq %r14, %rdi
movl %ebp, %esi
callq 0x53a0
movl %ebp, 0x8(%rsp)
movq (%r15), %r13
movq 0x8(%r15), %r15
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x8e4e
movsbl (%r13,%r12), %edi
callq 0x9fae
testb %al, %al
je 0x8dcc
movl 0x10(%rsp), %edx
testb %dl, %dl
setne %cl
movb (%r13,%r12), %al
cmpb %dl, %al
sete %dl
cmpb $0x5c, %al
je 0x8dba
andb %dl, %cl
je 0x8df5
movq %r14, %rdi
pushq $0x5c
popq %rsi
callq 0x53a0
movb (%r13,%r12), %al
jmp 0x8df5
movq %r14, %rdi
pushq $0x5c
popq %rsi
callq 0x53a0
movzbl (%r13,%r12), %ebp
leal -0x7(%rbp), %ecx
cmpb $0x6, %cl
ja 0x8e02
shlb $0x3, %cl
movabsq $0x7266766e746261, %rax # imm = 0x7266766E746261
shrq %cl, %rax
movsbl %al, %esi
movq %r14, %rdi
callq 0x53a0
jmp 0x8e46
movsbl 0x1(%r13,%r12), %edi
callq 0x50a0
testl %eax, %eax
leaq 0x12602(%rip), %rdx     # 0x1b418
leaq 0x12600(%rip), %rax     # 0x1b41d
cmoveq %rax, %rdx
movq %r14, %rbx
leaq 0x14(%rsp), %r14
movq %r14, %rdi
pushq $0x4
popq %rsi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x5680
movq %rbx, %rdi
movq %r14, %rsi
movq %rbx, %r14
callq 0x57c0
incq %r12
jmp 0x8d87
cmpb $0x0, 0xc(%rsp)
movl 0x8(%rsp), %esi
je 0x8e61
movq %r14, %rdi
callq 0x53a0
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8e77
jmp 0x8e7a
movq %r14, %rbx
movq %rax, %r14
movq %rbx, %rdi
callq 0x51f0
movq %r14, %rdi
callq 0x5730