// File: Eba-M[P]E3DC-Control/cJSON.c
// Function: cJSON_Duplicate
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse)
{
    cJSON *newitem = NULL;
    cJSON *child = NULL;
    cJSON *next = NULL;
    cJSON *newchild = NULL;

    /* Bail on bad ptr */
    if (!item)
    {
        goto fail;
    }
    /* Create new item */
    newitem = cJSON_New_Item(&global_hooks);
    if (!newitem)
    {
        goto fail;
    }
    /* Copy over all vars */
    newitem->type = item->type & (~cJSON_IsReference);
    newitem->valueint = item->valueint;
    newitem->valuedouble = item->valuedouble;
    if (item->valuestring)
    {
        newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks);
        if (!newitem->valuestring)
        {
            goto fail;
        }
    }
    if (item->string)
    {
        newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks);
        if (!newitem->string)
        {
            goto fail;
        }
    }
    /* If non-recursive, then we're done! */
    if (!recurse)
    {
        return newitem;
    }
    /* Walk the ->next chain for the child. */
    child = item->child;
    while (child != NULL)
    {
        newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */
        if (!newchild)
        {
            goto fail;
        }
        if (next != NULL)
        {
            /* If newitem->child already set, then crosswire ->prev and ->next and move on */
            next->next = newchild;
            newchild->prev = next;
            next = newchild;
        }
        else
        {
            /* Set newitem->child and move to it */
            newitem->child = newchild;
            next = newchild;
        }
        child = child->next;
    }
    if (newitem && newitem->child)
    {
        newitem->child->prev = newchild;
    }

    return newitem;

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

    return NULL;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movl %esi, 0x34(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
cmpq $0x0, 0x38(%rsp)
jne 0x5bb2e
jmp 0x5bd04
leaq 0x128a3(%rip), %rdi     # 0x6e3d8
callq 0x59500
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x5bb4c
jmp 0x5bd04
movq 0x38(%rsp), %rax
movl 0x18(%rax), %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
movq 0x28(%rsp), %rax
movl %ecx, 0x18(%rax)
movq 0x38(%rsp), %rax
movl 0x28(%rax), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x28(%rax)
movq 0x38(%rsp), %rax
movsd 0x30(%rax), %xmm0
movq 0x28(%rsp), %rax
movsd %xmm0, 0x30(%rax)
movq 0x38(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x5bbc6
movq 0x38(%rsp), %rax
movq 0x20(%rax), %rdi
leaq 0x12836(%rip), %rsi     # 0x6e3d8
callq 0x591f0
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x5bbc4
jmp 0x5bd04
jmp 0x5bbc6
movq 0x38(%rsp), %rax
cmpq $0x0, 0x38(%rax)
je 0x5bc2f
movq 0x38(%rsp), %rax
movl 0x18(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x5bbf4
movq 0x38(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x5bc0e
movq 0x38(%rsp), %rax
movq 0x38(%rax), %rdi
leaq 0x127d4(%rip), %rsi     # 0x6e3d8
callq 0x591f0
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x5bc2d
jmp 0x5bd04
jmp 0x5bc2f
cmpl $0x0, 0x34(%rsp)
jne 0x5bc45
movq 0x28(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x5bd1f
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x5bcd2
movq 0x20(%rsp), %rdi
movl $0x1, %esi
callq 0x5baf0
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0x5bc7c
jmp 0x5bd04
cmpq $0x0, 0x18(%rsp)
je 0x5bcab
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x5bcc3
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x10(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x5bc53
cmpq $0x0, 0x28(%rsp)
je 0x5bcf8
movq 0x28(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x5bcf8
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x28(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x5bd1f
cmpq $0x0, 0x28(%rsp)
je 0x5bd16
movq 0x28(%rsp), %rdi
callq 0x58fa0
movq $0x0, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopl (%rax)