// File: Eba-M[P]E3DC-Control/cJSON.c
// Function: print(cJSON const*, int, internal_hooks const*)
static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks)
{
    static const size_t default_buffer_size = 256;
    printbuffer buffer[1];
    unsigned char *printed = NULL;

    memset(buffer, 0, sizeof(buffer));

    /* create buffer */
    buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size);
    buffer->length = default_buffer_size;
    buffer->format = format;
    buffer->hooks = *hooks;
    if (buffer->buffer == NULL)
    {
        goto fail;
    }

    /* print the value */
    if (!print_value(item, buffer))
    {
        goto fail;
    }
    update_offset(buffer);

    /* check if reallocate is available */
    if (hooks->reallocate != NULL)
    {
        printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1);
        if (printed == NULL) {
            goto fail;
        }
        buffer->buffer = NULL;
    }
    else /* otherwise copy the JSON over to a new buffer */
    {
        printed = (unsigned char*) hooks->allocate(buffer->offset + 1);
        if (printed == NULL)
        {
            goto fail;
        }
        memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1));
        printed[buffer->offset] = '\0'; /* just to be sure */

        /* free the buffer */
        hooks->deallocate(buffer->buffer);
    }

    return printed;

fail:
    if (buffer->buffer != NULL)
    {
        hooks->deallocate(buffer->buffer);
    }

    if (printed != NULL)
    {
        hooks->deallocate(printed);
    }

    return NULL;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movl %esi, 0x74(%rsp)
movq %rdx, 0x68(%rsp)
movq $0x0, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x2170
movq 0x68(%rsp), %rax
movl $0x100, %edi            # imm = 0x100
callq *(%rax)
movq %rax, 0x20(%rsp)
movq $0x100, 0x28(%rsp)      # imm = 0x100
movl 0x74(%rsp), %eax
movl %eax, 0x44(%rsp)
movq 0x68(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x48(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x50(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x59abd
jmp 0x59bc6
movq 0x78(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x59d20
cmpl $0x0, %eax
jne 0x59ad6
jmp 0x59bc6
leaq 0x20(%rsp), %rdi
callq 0x5c6f0
movq 0x68(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x59b25
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x1, %rsi
callq *%rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x59b17
jmp 0x59bc6
movq $0x0, 0x20(%rsp)
jmp 0x59bb7
movq 0x68(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdi
addq $0x1, %rdi
callq *%rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x59b47
jmp 0x59bc6
movq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x59b79
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
jmp 0x59b86
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, (%rsp)
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
movq (%rsp), %rdx
callq 0x2220
movq 0x18(%rsp), %rax
movq 0x30(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x68(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x18(%rsp), %rax
movq %rax, 0x80(%rsp)
jmp 0x59c02
cmpq $0x0, 0x20(%rsp)
je 0x59bde
movq 0x68(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
cmpq $0x0, 0x18(%rsp)
je 0x59bf6
movq 0x68(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rsp), %rdi
callq *%rax
movq $0x0, 0x80(%rsp)
movq 0x80(%rsp), %rax
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)