// File: lega911[P]ijson/src/json.cpp
// Function: json::unescape(Buffer&, int)
void json::unescape(Buffer &s, int start) {
    char *p = s.ptr();
    int n = start;
    bool prefix = false;
    for(int i=start;i<s.size();i++) {
        char a = p[i];
        if(prefix) {
            switch(a) {
            case 'b':
                a = 8;
                break;
            case 't':
                a = 9;
                break;
            case 'n':
                a = '\n';
                break;
            case 'f':
                a = '\f';
                break;
            case 'r':
                a  ='\r';
                break;
            case 'u':
                if(i + 4 < s.size()) {
                    Slice hex(&p[i + 1], 4);
                    i += 4;
                    auto code = hex.hextoi();
                    std::cout << code << std::endl;
                    if(code <= 0x7f) a = code;
                    else if(code <= 0x7ff) {
                        p[n++] = 0xc0 | (code >> 6);
                        a = 0x80 | (code & 0x3f);
                    } else {
                        p[n++] = 0xe0 | (code >> 12);
                        p[n++] = 0x80 | ((code >> 6) & 0x3f);
                        a = 0x80 | (code & 0x3f);
                    }
                }

                break;
            // case '"':
            // case '/':
            // case '\\':
            };
            prefix = false;
        } else if(a == '\\') {
            prefix = true;
            continue;
        }
        p[n++] = a;
    }
    s.resize(0, n);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1e6f0
movq %rax, -0x18(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x1c(%rbp)
movb $0x0, -0x1d(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1e6d0
movl %eax, %ecx
movl -0x44(%rbp), %eax
cmpl %ecx, %eax
jge 0x2358f
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x25(%rbp)
testb $0x1, -0x1d(%rbp)
je 0x23558
movsbl -0x25(%rbp), %eax
addl $-0x62, %eax
movl %eax, %ecx
movq %rcx, -0x50(%rbp)
subl $0x13, %eax
ja 0x23552
movq -0x50(%rbp), %rax
leaq 0x15737(%rip), %rcx     # 0x38b28
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x8, -0x25(%rbp)
jmp 0x23552
movb $0x9, -0x25(%rbp)
jmp 0x23552
movb $0xa, -0x25(%rbp)
jmp 0x23552
movb $0xc, -0x25(%rbp)
jmp 0x23552
movb $0xd, -0x25(%rbp)
jmp 0x23552
movl -0x24(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x54(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1e6d0
movl %eax, %ecx
movl -0x54(%rbp), %eax
cmpl %ecx, %eax
jge 0x23550
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %eax
addl $0x1, %eax
cltq
addq %rax, %rsi
leaq -0x38(%rbp), %rdi
movl $0x4, %edx
callq 0x1ea20
movl -0x24(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x24(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x23f70
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rsi
movq 0x23b4c(%rip), %rdi     # 0x46fd0
callq 0x194c0
movq %rax, %rdi
movq 0x23b1d(%rip), %rsi     # 0x46fb0
callq 0x19320
cmpq $0x7f, -0x40(%rbp)
jg 0x234ab
movq -0x40(%rbp), %rax
movb %al, -0x25(%rbp)
jmp 0x2354e
cmpq $0x7ff, -0x40(%rbp)     # imm = 0x7FF
jg 0x234ed
movq -0x40(%rbp), %rax
sarq $0x6, %rax
orq $0xc0, %rax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, -0x25(%rbp)
jmp 0x2354c
movq -0x40(%rbp), %rax
sarq $0xc, %rax
orq $0xe0, %rax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
sarq $0x6, %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, -0x25(%rbp)
jmp 0x2354e
jmp 0x23550
jmp 0x23552
movb $0x0, -0x1d(%rbp)
jmp 0x23569
movsbl -0x25(%rbp), %eax
cmpl $0x5c, %eax
jne 0x23567
movb $0x1, -0x1d(%rbp)
jmp 0x23581
jmp 0x23569
movb -0x25(%rbp), %dl
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2339c
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %edx
xorl %esi, %esi
callq 0x1f840
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)