// File: /workspace/github_cpp_makefile_star2_O3/Eba-M[P]E3DC-Control/cJSON.c
// Function: parse_string(cJSON*, parse_buffer*)
static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer)
{
    const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1;
    const unsigned char *input_end = buffer_at_offset(input_buffer) + 1;
    unsigned char *output_pointer = NULL;
    unsigned char *output = NULL;

    /* not a string */
    if (buffer_at_offset(input_buffer)[0] != '\"')
    {
        goto fail;
    }

    {
        /* calculate approximate size of the output (overestimate) */
        size_t allocation_length = 0;
        size_t skipped_bytes = 0;
        while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"'))
        {
            /* is escape sequence */
            if (input_end[0] == '\\')
            {
                if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length)
                {
                    /* prevent buffer overflow when last input character is a backslash */
                    goto fail;
                }
                skipped_bytes++;
                input_end++;
            }
            input_end++;
        }
        if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"'))
        {
            goto fail; /* string ended unexpectedly */
        }

        /* This is at most how much we need for the output */
        allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes;
        output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof(""));
        if (output == NULL)
        {
            goto fail; /* allocation failure */
        }
    }

    output_pointer = output;
    /* loop through the string literal */
    while (input_pointer < input_end)
    {
        if (*input_pointer != '\\')
        {
            *output_pointer++ = *input_pointer++;
        }
        /* escape sequence */
        else
        {
            unsigned char sequence_length = 2;
            if ((input_end - input_pointer) < 1)
            {
                goto fail;
            }

            switch (input_pointer[1])
            {
                case 'b':
                    *output_pointer++ = '\b';
                    break;
                case 'f':
                    *output_pointer++ = '\f';
                    break;
                case 'n':
                    *output_pointer++ = '\n';
                    break;
                case 'r':
                    *output_pointer++ = '\r';
                    break;
                case 't':
                    *output_pointer++ = '\t';
                    break;
                case '\"':
                case '\\':
                case '/':
                    *output_pointer++ = input_pointer[1];
                    break;

                /* UTF-16 literal */
                case 'u':
                    sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer);
                    if (sequence_length == 0)
                    {
                        /* failed to convert UTF16-literal to UTF-8 */
                        goto fail;
                    }
                    break;

                default:
                    goto fail;
            }
            input_pointer += sequence_length;
        }
    }

    /* zero terminate the output */
    *output_pointer = '\0';

    item->type = cJSON_String;
    item->valuestring = (char*)output;

    input_buffer->offset = (size_t) (input_end - input_buffer->content);
    input_buffer->offset++;

    return true;

fail:
    if (output != NULL)
    {
        input_buffer->hooks.deallocate(output);
    }

    if (input_pointer != NULL)
    {
        input_buffer->offset = (size_t)(input_pointer - input_buffer->content);
    }

    return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq (%rsi), %rax
movq 0x10(%rsi), %rbp
leaq (%rax,%rbp), %r15
incq %r15
cmpb $0x22, -0x1(%r15)
jne 0x2e6f7
movq 0x8(%rbx), %rcx
movq %r15, %rdx
subq %rax, %rdx
cmpq %rcx, %rdx
jae 0x2e6f7
movq %rdi, %r12
addq %rax, %rbp
movl $0x1, %r14d
xorl %edx, %edx
movq %r15, %r13
movzbl (%rbp,%r14), %esi
cmpl $0x5c, %esi
je 0x2e6cd
cmpl $0x22, %esi
jne 0x2e6e2
jmp 0x2e70f
leaq (%r14,%rbp), %rsi
incq %rsi
subq %rax, %rsi
cmpq %rcx, %rsi
jae 0x2e6f7
incq %r14
incq %rdx
leaq (%r14,%rbp), %r13
incq %r13
incq %r14
movq %r13, %rsi
subq %rax, %rsi
cmpq %rcx, %rsi
jb 0x2e6bb
subq (%rbx), %r15
xorl %eax, %eax
movq %r15, 0x10(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %rbp, %rdx
movq %r13, %rdi
subq %rdx, %rdi
incq %rdi
callq *0x20(%rbx)
testq %rax, %rax
je 0x2e6f7
movq %rax, %r10
movq %r12, 0x10(%rsp)
movq %rax, %r12
cmpq $0x2, %r14
jl 0x2e947
addq %r14, %rbp
leaq 0x438e(%rip), %r11      # 0x32ad0
movq %r10, %r12
movb (%r15), %al
cmpb $0x5c, %al
jne 0x2e78b
movq %r13, %rcx
subq %r15, %rcx
testq %rcx, %rcx
jle 0x2e96f
movb 0x1(%r15), %dl
movzbl %dl, %eax
cmpl $0x61, %eax
jg 0x2e79f
cmpl $0x22, %eax
je 0x2e77a
cmpl $0x2f, %eax
je 0x2e77a
cmpl $0x5c, %eax
jne 0x2e96f
movb %dl, (%r12)
incq %r12
movl $0x2, %eax
addq %rax, %r15
jmp 0x2e795
incq %r15
movb %al, (%r12)
incq %r12
cmpq %rbp, %r15
jb 0x2e745
jmp 0x2e947
leal -0x6e(%rax), %edx
cmpl $0x7, %edx
ja 0x2e7b7
movslq (%r11,%rdx,4), %rax
addq %r11, %rax
jmpq *%rax
movb $0xa, (%r12)
jmp 0x2e77e
cmpl $0x66, %eax
je 0x2e849
cmpl $0x62, %eax
jne 0x2e96f
movb $0x8, (%r12)
jmp 0x2e77e
cmpq $0x6, %rcx
jb 0x2e96f
movq %r10, %r14
leaq 0x2(%r15), %rdi
callq 0x2eb1d
movl %eax, %esi
andl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0xd800, %eax           # imm = 0xD800
je 0x2e853
cmpl $0xdc00, %eax           # imm = 0xDC00
movq %r14, %r10
leaq 0x42cd(%rip), %r11      # 0x32ad0
je 0x2e96f
cmpl $0x80, %esi
jb 0x2e907
movl $0x6, %eax
cmpl $0x800, %esi            # imm = 0x800
jae 0x2e91f
movl $0xc0, %ecx
movl $0x2, %edx
jmp 0x2e8d2
movb $0x9, (%r12)
jmp 0x2e77e
movb $0xd, (%r12)
jmp 0x2e77e
movb $0xc, (%r12)
jmp 0x2e77e
leaq 0x6(%r15), %rax
movq %r13, %rcx
subq %rax, %rcx
cmpq $0x6, %rcx
movq %r14, %r10
jl 0x2e96f
cmpb $0x5c, (%rax)
jne 0x2e96f
cmpb $0x75, 0x7(%r15)
jne 0x2e96f
leaq 0x8(%r15), %rdi
movq %rsi, 0x8(%rsp)
callq 0x2eb1d
movq 0x8(%rsp), %rsi
leaq 0x4238(%rip), %r11      # 0x32ad0
movq %r14, %r10
leal -0xe000(%rax), %ecx
cmpl $0xfffffc00, %ecx       # imm = 0xFFFFFC00
jb 0x2e96f
shll $0xa, %esi
andl $0xffc00, %esi          # imm = 0xFFC00
andl $0x3ff, %eax            # imm = 0x3FF
addl %eax, %esi
addl $0x10000, %esi          # imm = 0x10000
movl $0xf0, %ecx
movl $0x4, %edx
movl $0xc, %eax
movl %esi, %esi
leal -0x1(%rdx), %edi
movzbl %dil, %edi
decq %rdi
movq %rdi, %r8
movl %esi, %r9d
andb $0x3f, %r9b
orb $-0x80, %r9b
movb %r9b, 0x1(%r12,%rdi)
shrq $0x6, %rsi
decq %r8
testb %dil, %dil
movq %r8, %rdi
jne 0x2e8e1
orq %rcx, %rsi
movl %edx, %ecx
jmp 0x2e913
movl %esi, %esi
movl $0x1, %ecx
movl $0x6, %eax
movb %sil, (%r12)
addq %rcx, %r12
jmp 0x2e786
cmpl $0x10000, %esi          # imm = 0x10000
jae 0x2e933
movl $0xe0, %ecx
movl $0x3, %edx
jmp 0x2e8d2
cmpl $0x10ffff, %esi         # imm = 0x10FFFF
ja 0x2e96f
movl $0xf0, %ecx
movl $0x4, %edx
jmp 0x2e8d2
movb $0x0, (%r12)
movq 0x10(%rsp), %rax
movl $0x10, 0x18(%rax)
movq %r10, 0x20(%rax)
subq (%rbx), %r13
incq %r13
movl $0x1, %eax
movq %r13, %r15
jmp 0x2e6fc
movq %r10, %rdi
callq *0x28(%rbx)
jmp 0x2e6f7