// File: /workspace/github_cpp_makefile_star2_O2/jovermann[P]streplace/src/MiscUtils.cpp
// Function: ut1::compileCString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*)
std::string compileCString(const std::string& s, std::string* errorMessageOut)
{
    std::string r;
    const char* p = s.c_str();
    const char* end;
    char        buf[4];

    if (errorMessageOut)
    {
        errorMessageOut->clear();
    }
    for (;;)
    {
        char c = *(p++);
        if (c == 0)
        {
            break;
        }
        if (c == '\\')
        {
            // Escape sequence.
            c = *(p++);
            switch (c)
            {
                // End of string in escape sequence: Emit verbatim backslash.
            case 0:
                c = '\\';
                p--;
                if (errorMessageOut)
                {
                    *errorMessageOut = "unexpected end of string in escape sequence";
                }
                break;

                // Named control chars.
            case 'a': c = '\a'; break;
            case 'b': c = '\b'; break;
            case 'f': c = '\f'; break;
            case 'n': c = '\n'; break;
            case 'r': c = '\r'; break;
            case 't': c = '\t'; break;
            case 'v':
                c = '\v';
                break;

                // Hex.
            case 'x':
                if (std::isxdigit(unsigned(p[0])))
                {
                    c = char(std::strtoul(p, const_cast<char**>(&end), 16));
                    p = end;
                }
                else
                {
                    r += '\\';
                    if (errorMessageOut)
                    {
                        *errorMessageOut = "non hex char following \\x";
                    }
                }
                break;

                // Octal.
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
                // Copy octal number.
                buf[0] = c;
                buf[1] = p[0];
                buf[2] = p[0] ? p[1] : 0;
                buf[3] = 0;
                c      = char(std::strtoul(buf, const_cast<char**>(&end), 8));
                p += end - buf - 1;
                break;

                // Known backslash sequence: Leave escape sequence intact.
            default:
                r += '\\';
                if (errorMessageOut)
                {
                    *errorMessageOut = "unknown backslash sequence '\\" + expandUnprintable(std::string(1, c)) + "'";
                }
                break;
            }
        }
        r += c;
    }
    return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
movq (%rsi), %rax
testq %rdx, %rdx
je 0x8ec4
andq $0x0, 0x8(%rdx)
movq (%rdx), %rcx
movb $0x0, (%rcx)
movq %rdx, 0x10(%rsp)
leaq 0xc(%rsp), %r15
notq %r15
movq %r15, 0x20(%rsp)
leaq 0x48(%rsp), %r12
leaq 0x124ea(%rip), %r15     # 0x1b3cc
leaq 0x1(%rax), %rbp
movzbl (%rax), %r13d
cmpl $0x5c, %r13d
je 0x8efe
testl %r13d, %r13d
jne 0x8fa4
jmp 0x90f3
leaq 0x2(%rax), %r14
movb 0x1(%rax), %r13b
movzbl %r13b, %ecx
leal -0x30(%rcx), %edx
cmpl $0x8, %edx
jb 0x8f28
leal -0x6e(%rcx), %eax
cmpl $0xa, %eax
ja 0x8f3d
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movb $0xa, %r13b
jmp 0x8fa1
movb %r13b, 0xc(%rsp)
movb (%r14), %cl
movb %cl, 0xd(%rsp)
testb %cl, %cl
je 0x8f77
movb 0x3(%rax), %al
jmp 0x8f79
cmpl $0x66, %ecx
je 0x90ab
cmpl $0x61, %ecx
je 0x90bb
cmpl $0x62, %ecx
je 0x90b3
testl %ecx, %ecx
jne 0x8fb8
movb $0x5c, %r13b
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x8fa4
leaq 0x124b3(%rip), %rsi     # 0x1b423
callq 0x57e0
jmp 0x8fa4
xorl %eax, %eax
movb %al, 0xe(%rsp)
movb $0x0, 0xf(%rsp)
leaq 0xc(%rsp), %rdi
leaq 0x18(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x5140
movq %rax, %r13
addq 0x20(%rsp), %r14
addq 0x18(%rsp), %r14
movq %r14, %rbp
movsbl %r13b, %esi
movq %rbx, %rdi
callq 0x53a0
movq %rbp, %rax
jmp 0x8ee2
movq %rbx, %rdi
pushq $0x5c
popq %rsi
callq 0x53a0
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x8fa1
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movsbl %r13b, %edx
leaq 0x28(%rsp), %r15
movq %r15, %rdi
pushq $0x1
popq %rsi
callq 0x54d0
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x8d3c
leaq 0x68(%rsp), %r15
movq %r15, %rdi
leaq 0x12460(%rip), %rsi     # 0x1b469
movq %r12, %rdx
callq 0x7717
leaq 0x88(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
leaq 0x12147(%rip), %rdx     # 0x1b16d
callq 0x76f8
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x5500
movq %rbp, %rdi
callq 0x51f0
movq %r15, %rdi
callq 0x51f0
movq %r12, %rdi
callq 0x51f0
leaq 0x28(%rsp), %rdi
callq 0x51f0
movq %r14, %rbp
leaq 0x12368(%rip), %r15     # 0x1b3cc
jmp 0x8fa4
movb $0xb, %r13b
jmp 0x8fa1
movb $0x9, %r13b
jmp 0x8fa1
movb $0xd, %r13b
jmp 0x8fa1
movsbl (%r14), %edi
callq 0x50a0
testl %eax, %eax
je 0x90c3
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x5140
movq %rax, %r13
movq 0x18(%rsp), %rbp
jmp 0x8fa4
movb $0xc, %r13b
jmp 0x8fa1
movb $0x8, %r13b
jmp 0x8fa1
movb $0x7, %r13b
jmp 0x8fa1
movq %rbx, %rdi
pushq $0x5c
popq %rsi
callq 0x53a0
movb $0x78, %r13b
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x8fa1
leaq 0x12369(%rip), %rsi     # 0x1b44f
callq 0x57e0
movq %r14, %rbp
jmp 0x8fa4
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9137
movq %rax, %r14
jmp 0x9121
movq %rax, %r14
jmp 0x912b
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x51f0
leaq 0x48(%rsp), %rdi
callq 0x51f0
leaq 0x28(%rsp), %rdi
callq 0x51f0
jmp 0x913a
movq %rax, %r14
movq %rbx, %rdi
callq 0x51f0
movq %r14, %rdi
callq 0x5730