// File: 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
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0xe0(%rbp)
movq %rdi, %rax
movq %rax, -0xd8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
callq 0x7860
movq -0x10(%rbp), %rdi
callq 0x7260
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1192e
movq -0x18(%rbp), %rdi
callq 0x7800
jmp 0x11930
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movb (%rax), %al
movb %al, -0x35(%rbp)
movsbl -0x35(%rbp), %eax
cmpl $0x0, %eax
jne 0x11952
jmp 0x11c68
movsbl -0x35(%rbp), %eax
cmpl $0x5c, %eax
jne 0x11c51
movq -0x28(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x28(%rbp)
movb (%rax), %al
movb %al, -0x35(%rbp)
movsbl -0x35(%rbp), %eax
movl %eax, %ecx
movq %rcx, -0xe8(%rbp)
subl $0x78, %eax
ja 0x11af4
movq -0xe8(%rbp), %rax
leaq 0x38a32(%rip), %rcx     # 0x4a3c8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x5c, -0x35(%rbp)
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x119db
movq -0x18(%rbp), %rdi
leaq 0x38cfa(%rip), %rsi     # 0x4a6bb
callq 0x7850
jmp 0x119c8
jmp 0x119db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x11c8e
jmp 0x11c4f
movb $0x7, -0x35(%rbp)
jmp 0x11c4f
movb $0x8, -0x35(%rbp)
jmp 0x11c4f
movb $0xc, -0x35(%rbp)
jmp 0x11c4f
movb $0xa, -0x35(%rbp)
jmp 0x11c4f
movb $0xd, -0x35(%rbp)
jmp 0x11c4f
movb $0x9, -0x35(%rbp)
jmp 0x11c4f
movb $0xb, -0x35(%rbp)
jmp 0x11c4f
movq -0x28(%rbp), %rax
movsbl (%rax), %edi
callq 0x7100
cmpl $0x0, %eax
je 0x11a4f
movq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x10, %edx
callq 0x71c0
movb %al, -0x35(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x11a7f
movq -0xe0(%rbp), %rdi
movl $0x5c, %esi
callq 0x73f0
jmp 0x11a62
cmpq $0x0, -0x18(%rbp)
je 0x11a7d
movq -0x18(%rbp), %rdi
leaq 0x38c73(%rip), %rsi     # 0x4a6e7
callq 0x7850
jmp 0x11a7b
jmp 0x11a7d
jmp 0x11a7f
jmp 0x11c4f
movb -0x35(%rbp), %al
movb %al, -0x34(%rbp)
movq -0x28(%rbp), %rax
movb (%rax), %al
movb %al, -0x33(%rbp)
movq -0x28(%rbp), %rax
cmpb $0x0, (%rax)
je 0x11aac
movq -0x28(%rbp), %rax
movsbl 0x1(%rax), %eax
movl %eax, -0xec(%rbp)
jmp 0x11ab6
xorl %eax, %eax
movl %eax, -0xec(%rbp)
jmp 0x11ab6
movl -0xec(%rbp), %eax
movb %al, -0x32(%rbp)
movb $0x0, -0x31(%rbp)
leaq -0x34(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x8, %edx
callq 0x71c0
movb %al, -0x35(%rbp)
movq -0x30(%rbp), %rax
leaq -0x34(%rbp), %rcx
subq %rcx, %rax
subq $0x1, %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x11c4f
movq -0xe0(%rbp), %rdi
movl $0x5c, %esi
callq 0x73f0
jmp 0x11b07
cmpq $0x0, -0x18(%rbp)
je 0x11c4d
movsbl -0x35(%rbp), %eax
movl %eax, -0xfc(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x7a50
movl -0xfc(%rbp), %edx
movq -0xf8(%rbp), %rcx
leaq -0xc8(%rbp), %rdi
movl $0x1, %esi
callq 0xb7c0
jmp 0x11b4f
leaq -0xa8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x11660
jmp 0x11b68
leaq 0x38b92(%rip), %rsi     # 0x4a701
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
callq 0xb770
jmp 0x11b84
leaq 0x385c6(%rip), %rdx     # 0x4a151
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0xb720
jmp 0x11b9d
movq -0x18(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x7750
leaq -0x68(%rbp), %rdi
callq 0x73c0
leaq -0x88(%rbp), %rdi
callq 0x73c0
leaq -0xa8(%rbp), %rdi
callq 0x73c0
leaq -0xc8(%rbp), %rdi
callq 0x73c0
leaq -0xc9(%rbp), %rdi
callq 0x7670
jmp 0x11c4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x11c3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x11c33
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x11c27
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x73c0
leaq -0xa8(%rbp), %rdi
callq 0x73c0
leaq -0xc8(%rbp), %rdi
callq 0x73c0
leaq -0xc9(%rbp), %rdi
callq 0x7670
jmp 0x11c8e
jmp 0x11c4f
jmp 0x11c51
movq -0xe0(%rbp), %rdi
movsbl -0x35(%rbp), %esi
callq 0x73f0
jmp 0x11c63
jmp 0x11930
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x11c7e
movq -0xe0(%rbp), %rdi
callq 0x73c0
movq -0xd8(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0xe0(%rbp), %rdi
callq 0x73c0
movq -0x40(%rbp), %rdi
callq 0x7a30
nopw %cs:(%rax,%rax)