// File: /workspace/github_c_makefile_star2_O0/lengjingzju[P]json/json.c
// Function: utf16_literal_to_utf8
static int utf16_literal_to_utf8(const unsigned char *start_str, const unsigned char *finish_str, unsigned char **pptr)
{ /* copy from cJSON */
    const unsigned char *str = start_str;
    unsigned char *ptr = *pptr;

    int seq_len = 0;
    int i = 0;
    unsigned long uc = 0;
    unsigned int  uc1 = 0, uc2 = 0;
    unsigned char len = 0;
    unsigned char first_byte_mark = 0;

    /* converts a UTF-16 literal to UTF-8, A literal can be one or two sequences of the form \uXXXX */
    if ((finish_str - str) < 6)                             /* input ends unexpectedly */
        goto fail;
    str += 2;
    uc1 = _parse_hex4(str);                                 /* get the first utf16 sequence */
    if (((uc1 >= 0xDC00) && (uc1 <= 0xDFFF)))               /* check first_code is valid */
        goto fail;
    if ((uc1 >= 0xD800) && (uc1 <= 0xDBFF)) {               /* UTF16 surrogate pair */
        str += 4;
        seq_len = 12;                                       /* \uXXXX\uXXXX */
        if ((finish_str - str) < 6)                         /* input ends unexpectedly */
            goto fail;
        if ((str[0] != '\\') || (str[1] != 'u'))            /* missing second half of the surrogate pair */
            goto fail;
        str += 2;
        uc2 = _parse_hex4(str);                             /* get the second utf16 sequence */
        if ((uc2 < 0xDC00) || (uc2 > 0xDFFF))               /* check second_code is valid */
            goto fail;
        uc = 0x10000 + (((uc1 & 0x3FF) << 10) | (uc2 & 0x3FF)); /* calculate the unicode uc from the surrogate pair */
    } else {
        seq_len = 6;                                        /* \uXXXX */
        uc = uc1;
    }

    /* encode as UTF-8 takes at maximum 4 bytes to encode: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
    if (uc < 0x80) {                                        /* normal ascii, encoding 0xxxxxxx */
        len = 1;
    } else if (uc < 0x800) {                                /* two bytes, encoding 110xxxxx 10xxxxxx */
        len = 2;
        first_byte_mark = 0xC0;                             /* 11000000 */
    } else if (uc < 0x10000) {                              /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */
        len = 3;
        first_byte_mark = 0xE0;                             /* 11100000 */
    } else if (uc <= 0x10FFFF) {                            /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */
        len = 4;
        first_byte_mark = 0xF0;                             /* 11110000 */
    }  else {                                               /* invalid unicode */
        goto fail;
    }
    for (i = len - 1; i > 0; --i) {                         /* encode as utf8 */
        ptr[i] = (unsigned char)((uc | 0x80) & 0xBF);       /* 10xxxxxx */
        uc >>= 6;
    }
    if (len > 1) {                                          /* encode first byte */
        ptr[0] = (unsigned char)((uc | first_byte_mark) & 0xFF);
    } else {
        ptr[0] = (unsigned char)(uc & 0x7F);
    }

    *pptr += len;
    return seq_len;

fail:
    return 0;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movl $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
movb $0x0, 0xf(%rsp)
movb $0x0, 0xe(%rsp)
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rcx
subq %rcx, %rax
cmpq $0x6, %rax
jge 0xb705
jmp 0xb91a
movq 0x30(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
callq 0xb930
movl %eax, 0x14(%rsp)
cmpl $0xdc00, 0x14(%rsp)     # imm = 0xDC00
jb 0xb73a
cmpl $0xdfff, 0x14(%rsp)     # imm = 0xDFFF
ja 0xb73a
jmp 0xb91a
cmpl $0xd800, 0x14(%rsp)     # imm = 0xD800
jb 0xb7ff
cmpl $0xdbff, 0x14(%rsp)     # imm = 0xDBFF
ja 0xb7ff
movq 0x30(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x30(%rsp)
movl $0xc, 0x24(%rsp)
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rcx
subq %rcx, %rax
cmpq $0x6, %rax
jge 0xb784
jmp 0xb91a
movq 0x30(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x5c, %eax
jne 0xb79f
movq 0x30(%rsp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x75, %eax
je 0xb7a4
jmp 0xb91a
movq 0x30(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
callq 0xb930
movl %eax, 0x10(%rsp)
cmpl $0xdc00, 0x10(%rsp)     # imm = 0xDC00
jb 0xb7d4
cmpl $0xdfff, 0x10(%rsp)     # imm = 0xDFFF
jbe 0xb7d9
jmp 0xb91a
movl 0x14(%rsp), %eax
andl $0x3ff, %eax            # imm = 0x3FF
shll $0xa, %eax
movl 0x10(%rsp), %ecx
andl $0x3ff, %ecx            # imm = 0x3FF
orl %ecx, %eax
addl $0x10000, %eax          # imm = 0x10000
movl %eax, %eax
movq %rax, 0x18(%rsp)
jmp 0xb810
movl $0x6, 0x24(%rsp)
movl 0x14(%rsp), %eax
movq %rax, 0x18(%rsp)
cmpq $0x80, 0x18(%rsp)
jae 0xb822
movb $0x1, 0xf(%rsp)
jmp 0xb872
cmpq $0x800, 0x18(%rsp)      # imm = 0x800
jae 0xb839
movb $0x2, 0xf(%rsp)
movb $-0x40, 0xe(%rsp)
jmp 0xb870
cmpq $0x10000, 0x18(%rsp)    # imm = 0x10000
jae 0xb850
movb $0x3, 0xf(%rsp)
movb $-0x20, 0xe(%rsp)
jmp 0xb86e
cmpq $0x10ffff, 0x18(%rsp)   # imm = 0x10FFFF
ja 0xb867
movb $0x4, 0xf(%rsp)
movb $-0x10, 0xe(%rsp)
jmp 0xb86c
jmp 0xb91a
jmp 0xb86e
jmp 0xb870
jmp 0xb872
movzbl 0xf(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x20(%rsp)
cmpl $0x0, 0x20(%rsp)
jle 0xb8c0
movq 0x18(%rsp), %rax
orq $0x80, %rax
andq $0xbf, %rax
movb %al, %dl
movq 0x28(%rsp), %rax
movslq 0x20(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x18(%rsp), %rax
shrq $0x6, %rax
movq %rax, 0x18(%rsp)
movl 0x20(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0xb87e
movzbl 0xf(%rsp), %eax
cmpl $0x1, %eax
jle 0xb8e8
movq 0x18(%rsp), %rax
movzbl 0xe(%rsp), %ecx
orq %rcx, %rax
andq $0xff, %rax
movb %al, %cl
movq 0x28(%rsp), %rax
movb %cl, (%rax)
jmp 0xb8fa
movq 0x18(%rsp), %rax
andq $0x7f, %rax
movb %al, %cl
movq 0x28(%rsp), %rax
movb %cl, (%rax)
movzbl 0xf(%rsp), %edx
movq 0x38(%rsp), %rax
movq (%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, (%rax)
movl 0x24(%rsp), %eax
movl %eax, 0x54(%rsp)
jmp 0xb922
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopl (%rax,%rax)