// File: /workspace/github_c_makefile_star2_O0/tomcatzh[P]RealityBenchmark/external/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;
    }

    return newitem;

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

    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x8d9b
jmp 0x8f1b
leaq 0x749e(%rip), %rdi      # 0x10240
callq 0x6ae0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x8db7
jmp 0x8f1b
movq -0x10(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
movq -0x20(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rax
movsd 0x30(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x30(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x8e27
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
leaq 0x743b(%rip), %rsi      # 0x10240
callq 0x8790
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x8e25
jmp 0x8f1b
jmp 0x8e27
movq -0x10(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x8e87
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x8e51
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x8e69
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
leaq 0x73e0(%rip), %rsi      # 0x10240
callq 0x8790
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x8e85
jmp 0x8f1b
jmp 0x8e87
cmpl $0x0, -0x14(%rbp)
jne 0x8e9a
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x8f33
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x8f11
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x8d60
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x8ec8
jmp 0x8f1b
cmpq $0x0, -0x30(%rbp)
je 0x8ef0
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x8f04
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x8ea6
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x8f33
cmpq $0x0, -0x20(%rbp)
je 0x8f2b
movq -0x20(%rbp), %rdi
callq 0x67e0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)