// File: Eba-M[P]E3DC-Control/cJSON.c
// Function: cJSON_ParseWithLengthOpts
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated)
{
    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
    cJSON *item = NULL;

    /* reset error position */
    global_error.json = NULL;
    global_error.position = 0;

    if (value == NULL || 0 == buffer_length)
    {
        goto fail;
    }

    buffer.content = (const unsigned char*)value;
    buffer.length = buffer_length;
    buffer.offset = 0;
    buffer.hooks = global_hooks;

    item = cJSON_New_Item(&global_hooks);
    if (item == NULL) /* memory fail */
    {
        goto fail;
    }

    if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer))))
    {
        /* parse failure. ep is set. */
        goto fail;
    }

    /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
    if (require_null_terminated)
    {
        buffer_skip_whitespace(&buffer);
        if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0')
        {
            goto fail;
        }
    }
    if (return_parse_end)
    {
        *return_parse_end = (const char*)buffer_at_offset(&buffer);
    }

    return item;

fail:
    if (item != NULL)
    {
        cJSON_Delete(item);
    }

    if (value != NULL)
    {
        error local_error;
        local_error.json = (const unsigned char*)value;
        local_error.position = 0;

        if (buffer.offset < buffer.length)
        {
            local_error.position = buffer.offset;
        }
        else if (buffer.length > 0)
        {
            local_error.position = buffer.length - 1;
        }

        if (return_parse_end != NULL)
        {
            *return_parse_end = (const char*)local_error.json + local_error.position;
        }

        global_error = local_error;
    }

    return NULL;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq %rsi, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
movl %ecx, 0x64(%rsp)
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x2170
movq $0x0, 0x20(%rsp)
movq $0x0, 0x20ed9(%rip) # 0x7a218
movq $0x0, 0x20ed6(%rip) # 0x7a220
cmpq $0x0, 0x78(%rsp)
je 0x5935b
xorl %eax, %eax
cmpq 0x70(%rsp), %rax
jne 0x59360
jmp 0x5944f
movq 0x78(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movq 0x15054(%rip), %rax     # 0x6e3d8
movq %rax, 0x48(%rsp)
movq 0x15050(%rip), %rax     # 0x6e3e0
movq %rax, 0x50(%rsp)
movq 0x1504c(%rip), %rax     # 0x6e3e8
movq %rax, 0x58(%rsp)
leaq 0x15030(%rip), %rdi     # 0x6e3d8
callq 0x59500
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x593bf
jmp 0x5944f
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x59930
movq %rax, %rdi
callq 0x59830
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x59540
cmpl $0x0, %eax
jne 0x593ef
jmp 0x5944f
cmpl $0x0, 0x64(%rsp)
je 0x59423
leaq 0x28(%rsp), %rdi
callq 0x59830
movq 0x38(%rsp), %rax
cmpq 0x30(%rsp), %rax
jae 0x5941f
movq 0x28(%rsp), %rax
movq 0x38(%rsp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x59421
jmp 0x5944f
jmp 0x59423
cmpq $0x0, 0x68(%rsp)
je 0x5943d
movq 0x28(%rsp), %rcx
addq 0x38(%rsp), %rcx
movq 0x68(%rsp), %rax
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movq %rax, 0x80(%rsp)
jmp 0x594ea
cmpq $0x0, 0x20(%rsp)
je 0x59461
movq 0x20(%rsp), %rdi
callq 0x58fa0
cmpq $0x0, 0x78(%rsp)
je 0x594de
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x30(%rsp), %rax
jae 0x59494
movq 0x38(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x594ac
cmpq $0x0, 0x30(%rsp)
jbe 0x594aa
movq 0x30(%rsp), %rax
subq $0x1, %rax
movq %rax, 0x18(%rsp)
jmp 0x594ac
cmpq $0x0, 0x68(%rsp)
je 0x594c6
movq 0x10(%rsp), %rcx
addq 0x18(%rsp), %rcx
movq 0x68(%rsp), %rax
movq %rcx, (%rax)
movq 0x10(%rsp), %rax
movq %rax, 0x20d46(%rip)     # 0x7a218
movq 0x18(%rsp), %rax
movq %rax, 0x20d42(%rip)     # 0x7a220
movq $0x0, 0x80(%rsp)
movq 0x80(%rsp), %rax
addq $0x88, %rsp
retq
nopw (%rax,%rax)