// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x60(%rbp)
movb %cl, %al
movb %dl, %cl
movq %rdi, %rdx
movq %rdx, -0x58(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %cl, -0x11(%rbp)
movb %al, -0x12(%rbp)
movb $0x0, -0x13(%rbp)
callq 0x7860
cmpb $0x0, -0x12(%rbp)
je 0x116bf
movq -0x60(%rbp), %rdi
movsbl -0x12(%rbp), %esi
callq 0x73f0
jmp 0x116a3
jmp 0x116bf
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x73c0
jmp 0x118d7
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x75a0
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0x7aa0
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x13cf0
testb $0x1, %al
jne 0x116f7
jmp 0x118a3
leaq -0x38(%rbp), %rdi
callq 0x13d30
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movsbl (%rax), %edi
callq 0x13d50
testb $0x1, %al
jne 0x11716
jmp 0x11760
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5c, %eax
je 0x11737
cmpb $0x0, -0x11(%rbp)
je 0x11749
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
movsbl -0x11(%rbp), %ecx
cmpl %ecx, %eax
jne 0x11749
movq -0x60(%rbp), %rdi
movl $0x5c, %esi
callq 0x73f0
jmp 0x11747
jmp 0x11749
movq -0x60(%rbp), %rdi
movq -0x48(%rbp), %rax
movsbl (%rax), %esi
callq 0x73f0
jmp 0x1175b
jmp 0x11893
movq -0x60(%rbp), %rdi
movl $0x5c, %esi
callq 0x73f0
jmp 0x11770
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
addl $-0x7, %eax
movl %eax, %ecx
movq %rcx, -0x68(%rbp)
subl $0x6, %eax
ja 0x1182a
movq -0x68(%rbp), %rax
leaq 0x38c18(%rip), %rcx     # 0x4a3ac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x60(%rbp), %rdi
movl $0x61, %esi
callq 0x73f0
jmp 0x117ad
jmp 0x11891
movq -0x60(%rbp), %rdi
movl $0x62, %esi
callq 0x73f0
jmp 0x117c2
jmp 0x11891
movq -0x60(%rbp), %rdi
movl $0x66, %esi
callq 0x73f0
jmp 0x117d7
jmp 0x11891
movq -0x60(%rbp), %rdi
movl $0x6e, %esi
callq 0x73f0
jmp 0x117ec
jmp 0x11891
movq -0x60(%rbp), %rdi
movl $0x72, %esi
callq 0x73f0
jmp 0x11801
jmp 0x11891
movq -0x60(%rbp), %rdi
movl $0x74, %esi
callq 0x73f0
jmp 0x11816
jmp 0x11891
movq -0x60(%rbp), %rdi
movl $0x76, %esi
callq 0x73f0
jmp 0x11828
jmp 0x11891
movq -0x48(%rbp), %rax
movb 0x1(%rax), %al
movb %al, -0x49(%rbp)
movsbl -0x49(%rbp), %edi
callq 0x7100
cmpl $0x0, %eax
je 0x11862
leaq -0x17(%rbp), %rdi
movq -0x48(%rbp), %rax
movzbl (%rax), %ecx
movl $0x4, %esi
leaq 0x38e57(%rip), %rdx     # 0x4a6b0
movb $0x0, %al
callq 0x7930
jmp 0x11880
leaq -0x17(%rbp), %rdi
movq -0x48(%rbp), %rax
movzbl (%rax), %ecx
movl $0x4, %esi
leaq 0x38e3c(%rip), %rdx     # 0x4a6b5
movb $0x0, %al
callq 0x7930
movq -0x60(%rbp), %rdi
leaq -0x17(%rbp), %rsi
callq 0x75b0
jmp 0x1188f
jmp 0x11891
jmp 0x11893
jmp 0x11895
leaq -0x38(%rbp), %rdi
callq 0x13d80
jmp 0x116e1
cmpb $0x0, -0x12(%rbp)
je 0x118ba
movq -0x60(%rbp), %rdi
movsbl -0x12(%rbp), %esi
callq 0x73f0
jmp 0x118b8
jmp 0x118ba
movb $0x1, -0x13(%rbp)
testb $0x1, -0x13(%rbp)
jne 0x118cd
movq -0x60(%rbp), %rdi
callq 0x73c0
movq -0x58(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x7a30