// File: /workspace/github_c_makefile_star2_O2/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 0x603e
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
movq %rsi, %rdi
callq 0x48e0
testl %eax, %eax
je 0x6025
movq %r15, %rdi
callq 0x48e0
testl %eax, %eax
je 0x6025
movq %r15, %rdi
movl %ebx, %esi
callq 0x5de0
movq %r14, %rdi
movl %ebx, -0x2c(%rbp)
movl %ebx, %esi
callq 0x5de0
movq 0x10(%r15), %r15
movq 0x10(%r14), %r12
callq 0x4079
movq %rax, %r14
movq %r15, %rax
negq %rax
movl $0x0, %r13d
sbbl %r13d, %r13d
orl $0x1, %r13d
movq %r15, %rax
orq %r12, %rax
je 0x6051
movl %r13d, %eax
testq %r15, %r15
je 0x5fa6
movl %r13d, %eax
testq %r12, %r12
je 0x5fa6
movq 0x38(%r15), %rdi
movq 0x38(%r12), %rsi
callq 0x2220
testl %eax, %eax
js 0x5fd0
je 0x5fe9
movq 0x38(%r12), %rbx
movq %r12, %rdi
pushq $0x1
popq %rsi
callq 0x466e
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3afb
movq (%r12), %r12
jmp 0x5f7c
movq 0x38(%r15), %rbx
callq 0x3cb3
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3afb
jmp 0x601d
movq %r15, %rdi
movq %r12, %rsi
movl -0x2c(%rbp), %edx
callq 0x60f5
testl %eax, %eax
jne 0x6019
movq 0x38(%r12), %rbx
movq %r15, %rdi
movq %r12, %rsi
callq 0x5efa
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3afb
movq (%r12), %r12
movq (%r15), %r15
jmp 0x5f69
pushq $0x1
popq %rsi
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x466e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3cb3
cmpq $0x0, 0x10(%r14)
jne 0x6063
movq %r14, %rdi
callq 0x2c35
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq