// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/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->ptr + 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->ptr + escape_len) != '\\' ||
            *(json->ptr + escape_len + 1) != 'u') {
            return -1;
        }

        /* Fetch the next codepoint */
        surrogate_low = decode_hex4(json->ptr + 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->ptr += 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 0x8(%rax), %rdi
addq $0x2, %rdi
callq 0xca810
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0xca6b9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xca7dd
movl -0x18(%rbp), %eax
andl $0xf800, %eax           # imm = 0xF800
cmpl $0xd800, %eax           # imm = 0xD800
jne 0xca78f
movl -0x18(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0xca6e5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xca7dd
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5c, %eax
jne 0xca710
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x24(%rbp), %rcx
movsbl 0x1(%rax,%rcx), %eax
cmpl $0x75, %eax
je 0xca71c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xca7dd
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x2, %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
callq 0xca810
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0xca749
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xca7dd
movl -0x1c(%rbp), %eax
andl $0xfc00, %eax           # imm = 0xFC00
cmpl $0xdc00, %eax           # imm = 0xDC00
je 0xca761
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xca7dd
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 0xca890
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0xca7ad
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xca7dd
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x14(%rbp), %rsi
movl -0x20(%rbp), %edx
callq 0xca9c0
movl -0x24(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)