// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x2e296
movl %esi, %ebp
movq %rdi, %r14
movl $0x40, %edi
callq *0xb16a(%rip)           # 0x39390
testq %rax, %rax
je 0x2e296
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movl $0xfffffeff, %eax       # imm = 0xFFFFFEFF
andl 0x18(%r14), %eax
movl %eax, 0x18(%rbx)
movl 0x28(%r14), %eax
movl %eax, 0x28(%rbx)
movsd 0x30(%r14), %xmm0
movsd %xmm0, 0x30(%rbx)
movq 0x20(%r14), %r15
testq %r15, %r15
je 0x2e2c5
movq %r15, %rdi
callq 0x2100
movq %rax, %r13
incq %r13
movq %r13, %rdi
callq *0xb112(%rip)           # 0x39390
testq %rax, %rax
je 0x2e2b9
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x21f0
jmp 0x2e2bc
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x2e2a5
movq %rbx, %rdi
callq 0x2c1d6
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
movq %r12, 0x20(%rbx)
testq %r12, %r12
je 0x2e298
movq 0x38(%r14), %r15
testq %r15, %r15
je 0x2e313
testb $0x2, 0x19(%r14)
jne 0x2e30a
movq %r15, %rdi
callq 0x2100
movq %rax, %r12
incq %r12
movq %r12, %rdi
callq *0xb0a4(%rip)           # 0x39390
testq %rax, %rax
je 0x2e307
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x21f0
movq %r13, %r15
jmp 0x2e30a
xorl %r15d, %r15d
movq %r15, 0x38(%rbx)
testq %r15, %r15
je 0x2e298
testl %ebp, %ebp
je 0x2e2a7
movq 0x10(%r14), %r14
testq %r14, %r14
je 0x2e358
xorl %r15d, %r15d
movq %r14, %rdi
movl $0x1, %esi
callq 0x2e202
testq %rax, %rax
je 0x2e298
testq %r15, %r15
je 0x2e347
movq %rax, (%r15)
movq %r15, 0x8(%rax)
jmp 0x2e34b
movq %rax, 0x10(%rbx)
movq (%r14), %r14
movq %rax, %r15
testq %r14, %r14
jne 0x2e323
jmp 0x2e35a
xorl %eax, %eax
movq 0x10(%rbx), %rcx
testq %rcx, %rcx
je 0x2e2a7
movq %rax, 0x8(%rcx)
jmp 0x2e2a7