// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/deps/lua/src/lua_cjson.c
// Function: json_append_unicode_escape
static int json_append_unicode_escape(json_parse_t *json)
{
    char utf8[4];       /* Surrogate pairs require 4 UTF-8 bytes */
    int codepoint;
    int surrogate_low;
    int len;
    int escape_len = 6;

    /* Fetch UTF-16 code unit */
    codepoint = decode_hex4(&json->data[json->index + 2]);
    if (codepoint < 0)
        return -1;

    /* UTF-16 surrogate pairs take the following 2 byte form:
     *      11011 x yyyyyyyyyy
     * When x = 0: y is the high 10 bits of the codepoint
     *      x = 1: y is the low 10 bits of the codepoint
     *
     * Check for a surrogate pair (high or low) */
    if ((codepoint & 0xF800) == 0xD800) {
        /* Error if the 1st surrogate is not high */
        if (codepoint & 0x400)
            return -1;

        /* Ensure the next code is a unicode escape */
        if (json->data[json->index + escape_len] != '\\' ||
            json->data[json->index + escape_len + 1] != 'u') {
            return -1;
        }

        /* Fetch the next codepoint */
        surrogate_low = decode_hex4(&json->data[json->index + 2 + escape_len]);
        if (surrogate_low < 0)
            return -1;

        /* Error if the 2nd code is not a low surrogate */
        if ((surrogate_low & 0xFC00) != 0xDC00)
            return -1;

        /* Calculate Unicode codepoint */
        codepoint = (codepoint & 0x3FF) << 10;
        surrogate_low &= 0x3FF;
        codepoint = (codepoint | surrogate_low) + 0x10000;
        escape_len = 12;
    }

    /* Convert codepoint to UTF-8 */
    len = codepoint_to_utf8(utf8, codepoint);
    if (!len)
        return -1;

    /* Append bytes and advance parse index */
    strbuf_append_mem_unsafe(json->tmp, utf8, len);
    json->index += escape_len;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl $0x6, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x2, %eax
cltq
addq %rax, %rdi
callq 0xa9900
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0xa97a3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa98d7
movl -0x18(%rbp), %eax
andl $0xf800, %eax           # imm = 0xF800
cmpl $0xd800, %eax           # imm = 0xD800
jne 0xa9891
movl -0x18(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0xa97cf
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa98d7
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0x24(%rbp), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5c, %eax
jne 0xa980c
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x75, %eax
je 0xa9818
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa98d7
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x2, %eax
addl -0x24(%rbp), %eax
cltq
addq %rax, %rdi
callq 0xa9900
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0xa984b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa98d7
movl -0x1c(%rbp), %eax
andl $0xfc00, %eax           # imm = 0xFC00
cmpl $0xdc00, %eax           # imm = 0xDC00
je 0xa9863
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa98d7
movl -0x18(%rbp), %eax
andl $0x3ff, %eax            # imm = 0x3FF
shll $0xa, %eax
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
orl -0x1c(%rbp), %eax
addl $0x10000, %eax          # imm = 0x10000
movl %eax, -0x18(%rbp)
movl $0xc, -0x24(%rbp)
leaq -0x14(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0xa9980
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0xa98af
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa98d7
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x14(%rbp), %rsi
movl -0x20(%rbp), %edx
callq 0xa9ab0
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq