// File: /workspace/github_c_makefile_star2_O1/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 0x6b3d
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r12
movq %rsi, %rdi
callq 0x4f71
testl %eax, %eax
je 0x6b22
movq %r12, %rdi
callq 0x4f71
testl %eax, %eax
je 0x6b22
testq %r12, %r12
je 0x6a42
movq 0x10(%r12), %rdi
movl %ebx, %esi
callq 0x7004
movq %rax, 0x10(%r12)
movq 0x10(%r14), %rdi
movl %ebx, %esi
callq 0x7004
movq %rax, %r15
movq %rax, 0x10(%r14)
movq 0x10(%r12), %r12
callq 0x43b2
movq %rax, %r14
testq %r12, %r12
setne %al
testq %r15, %r15
setne %cl
movq %r12, %rdx
orq %r15, %rdx
je 0x6b50
movzbl %al, %edx
movl %edx, %eax
andl $0x1, %eax
negl %eax
orl $0x1, %eax
testb $0x1, %dl
je 0x6a9e
testb $0x1, %cl
je 0x6a9e
movq 0x38(%r12), %rdi
movq 0x38(%r15), %rsi
callq 0x2210
testl %eax, %eax
js 0x6ac5
je 0x6ae6
movq 0x38(%r15), %r13
movq %r15, %rdi
movl $0x1, %esi
callq 0x4c70
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x3bde
jmp 0x6b1a
movq 0x38(%r12), %r13
callq 0x3e75
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x3bde
movq (%r12), %r12
jmp 0x6a61
movq %r12, %rdi
movq %r15, %rsi
movl %ebx, %edx
callq 0x6c06
testl %eax, %eax
jne 0x6b16
movq 0x38(%r15), %r13
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x69ed
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x3bde
movq (%r12), %r12
movq (%r15), %r15
jmp 0x6a61
movq %r14, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4c70
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3e75
cmpq $0x0, 0x10(%r14)
jne 0x6b62
movq %r14, %rdi
callq 0x2cdd
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq