// File: /workspace/github_c_makefile_star2_O3/ammarfaizi2[P]riyuu/src/third_party/cjson/cJSON_Utils.c
// Function: generate_merge_patch(cJSON*, cJSON*, int)
static cJSON *generate_merge_patch(cJSON * const from, cJSON * const to, const cJSON_bool case_sensitive)
{
    cJSON *from_child = NULL;
    cJSON *to_child = NULL;
    cJSON *patch = NULL;
    if (to == NULL)
    {
        /* patch to delete everything */
        return cJSON_CreateNull();
    }
    if (!cJSON_IsObject(to) || !cJSON_IsObject(from))
    {
        return cJSON_Duplicate(to, 1);
    }

    sort_object(from, case_sensitive);
    sort_object(to, case_sensitive);

    from_child = from->child;
    to_child = to->child;
    patch = cJSON_CreateObject();
    while (from_child || to_child)
    {
        int diff;
        if (from_child != NULL)
        {
            if (to_child != NULL)
            {
                diff = strcmp(from_child->string, to_child->string);
            }
            else
            {
                diff = -1;
            }
        }
        else
        {
            diff = 1;
        }

        if (diff < 0)
        {
            /* from has a value that to doesn't have -> remove */
            cJSON_AddItemToObject(patch, from_child->string, cJSON_CreateNull());

            from_child = from_child->next;
        }
        else if (diff > 0)
        {
            /* to has a value that from doesn't have -> add to patch */
            cJSON_AddItemToObject(patch, to_child->string, cJSON_Duplicate(to_child, 1));

            to_child = to_child->next;
        }
        else
        {
            /* object key exists in both objects */
            if (!compare_json(from_child, to_child, case_sensitive))
            {
                /* not identical --> generate a patch */
                cJSON_AddItemToObject(patch, to_child->string, cJSONUtils_GenerateMergePatch(from_child, to_child));
            }

            /* next key in the object */
            from_child = from_child->next;
            to_child = to_child->next;
        }
    }
    if (patch->child == NULL)
    {
        /* no patch generated */
        cJSON_Delete(patch);
        return NULL;
    }

    return patch;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rsi, %rsi
je 0x69d4
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r12
movq %rsi, %rdi
callq 0x4e9c
testl %eax, %eax
je 0x69b9
movq %r12, %rdi
callq 0x4e9c
testl %eax, %eax
je 0x69b9
testq %r12, %r12
je 0x68d9
movq 0x10(%r12), %rdi
movl %ebx, %esi
callq 0x6e82
movq %rax, 0x10(%r12)
movq 0x10(%r14), %rdi
movl %ebx, %esi
callq 0x6e82
movq %rax, %r15
movq %rax, 0x10(%r14)
movq 0x10(%r12), %r12
callq 0x4301
movq %rax, %r14
testq %r12, %r12
setne %al
testq %r15, %r15
setne %cl
movq %r12, %rdx
orq %r15, %rdx
je 0x69e7
movzbl %al, %edx
movl %edx, %eax
andl $0x1, %eax
negl %eax
orl $0x1, %eax
testb $0x1, %dl
je 0x6935
testb $0x1, %cl
je 0x6935
movq 0x38(%r12), %rdi
movq 0x38(%r15), %rsi
callq 0x2210
testl %eax, %eax
js 0x695c
je 0x697d
movq 0x38(%r15), %r13
movq %r15, %rdi
movl $0x1, %esi
callq 0x4b97
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x3b4d
jmp 0x69b1
movq 0x38(%r12), %r13
callq 0x3dc4
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x3b4d
movq (%r12), %r12
jmp 0x68f8
movq %r12, %rdi
movq %r15, %rsi
movl %ebx, %edx
callq 0x6a88
testl %eax, %eax
jne 0x69ad
movq 0x38(%r15), %r13
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x6884
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x3b4d
movq (%r12), %r12
movq (%r15), %r15
jmp 0x68f8
movq %r14, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4b97
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3dc4
cmpq $0x0, 0x10(%r14)
jne 0x69f9
movq %r14, %rdi
callq 0x2ce3
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq