// File: 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:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq (%rax), %rax
movq 0x40(%rsp), %rcx
addq 0x10(%rcx), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rax
movq (%rax), %rax
movq 0x40(%rsp), %rcx
addq 0x10(%rcx), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x40(%rsp), %rax
movq (%rax), %rax
movq 0x40(%rsp), %rcx
movq 0x10(%rcx), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x22, %eax
je 0x5c7c3
jmp 0x5caaf
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x30(%rsp), %rcx
movq 0x40(%rsp), %rax
movq (%rax), %rax
subq %rax, %rcx
movq 0x40(%rsp), %rdx
xorl %eax, %eax
cmpq 0x8(%rdx), %rcx
movb %al, 0xe(%rsp)
jae 0x5c808
movq 0x30(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x22, %eax
setne %al
movb %al, 0xe(%rsp)
movb 0xe(%rsp), %al
testb $0x1, %al
jne 0x5c812
jmp 0x5c872
movq 0x30(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x5c, %eax
jne 0x5c85f
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
subq %rcx, %rax
movq 0x40(%rsp), %rcx
cmpq 0x8(%rcx), %rax
jb 0x5c843
jmp 0x5caaf
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x5c7d5
movq 0x30(%rsp), %rax
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
subq %rcx, %rax
movq 0x40(%rsp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x5c89a
movq 0x30(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x22, %eax
je 0x5c89f
jmp 0x5caaf
movq 0x30(%rsp), %rax
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
movq 0x40(%rsp), %rdx
addq 0x10(%rdx), %rcx
subq %rcx, %rax
subq 0x10(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x18(%rsp), %rdi
addq $0x1, %rdi
callq *%rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x5c8e8
jmp 0x5caaf
movq 0x20(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x30(%rsp), %rax
jae 0x5ca59
movq 0x38(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x5c, %eax
je 0x5c93a
movq 0x38(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x38(%rsp)
movb (%rax), %cl
movq 0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x28(%rsp)
movb %cl, (%rax)
jmp 0x5ca54
movb $0x2, 0xf(%rsp)
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rcx, %rax
cmpq $0x1, %rax
jge 0x5c957
jmp 0x5caaf
movq 0x38(%rsp), %rax
movzbl 0x1(%rax), %eax
addl $-0x22, %eax
movl %eax, %ecx
movq %rcx, (%rsp)
subl $0x53, %eax
ja 0x5ca3d
movq (%rsp), %rax
leaq 0x5e73(%rip), %rcx      # 0x627f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x28(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rsp)
movb $0x8, (%rax)
jmp 0x5ca3f
movq 0x28(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rsp)
movb $0xc, (%rax)
jmp 0x5ca3f
movq 0x28(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rsp)
movb $0xa, (%rax)
jmp 0x5ca3f
movq 0x28(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rsp)
movb $0xd, (%rax)
jmp 0x5ca3f
movq 0x28(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rsp)
movb $0x9, (%rax)
jmp 0x5ca3f
movq 0x38(%rsp), %rax
movb 0x1(%rax), %cl
movq 0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x28(%rsp)
movb %cl, (%rax)
jmp 0x5ca3f
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x5d380
movb %al, 0xf(%rsp)
movzbl 0xf(%rsp), %eax
cmpl $0x0, %eax
jne 0x5ca3b
jmp 0x5caaf
jmp 0x5ca3f
jmp 0x5caaf
movzbl 0xf(%rsp), %ecx
movq 0x38(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x38(%rsp)
jmp 0x5c8f2
movq 0x28(%rsp), %rax
movb $0x0, (%rax)
movq 0x48(%rsp), %rax
movl $0x10, 0x18(%rax)
movq 0x20(%rsp), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x30(%rsp), %rcx
movq 0x40(%rsp), %rax
movq (%rax), %rax
subq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rax)
movl $0x1, 0x54(%rsp)
jmp 0x5caf0
cmpq $0x0, 0x20(%rsp)
je 0x5cac7
movq 0x40(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
cmpq $0x0, 0x38(%rsp)
je 0x5cae8
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %rax
movq (%rax), %rax
subq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopl (%rax)