// File: /workspace/github_c_makefile_star2_O1/ammarfaizi2[P]riyuu/src/third_party/cjson/cJSON_Utils.c
// Function: create_patches(cJSON*, unsigned char const*, cJSON*, cJSON*, int)
static void create_patches(cJSON * const patches, const unsigned char * const path, cJSON * const from, cJSON * const to, const cJSON_bool case_sensitive)
{
    if ((from == NULL) || (to == NULL))
    {
        return;
    }

    if ((from->type & 0xFF) != (to->type & 0xFF))
    {
        compose_patch(patches, (const unsigned char*)"replace", path, 0, to);
        return;
    }

    switch (from->type & 0xFF)
    {
        case cJSON_Number:
            if ((from->valueint != to->valueint) || (from->valuedouble != to->valuedouble))
            {
                compose_patch(patches, (const unsigned char*)"replace", path, NULL, to);
            }
            return;

        case cJSON_String:
            if (strcmp(from->valuestring, to->valuestring) != 0)
            {
                compose_patch(patches, (const unsigned char*)"replace", path, NULL, to);
            }
            return;

        case cJSON_Array:
        {
            size_t index = 0;
            cJSON *from_child = from->child;
            cJSON *to_child = to->child;
            unsigned char *new_path = (unsigned char*)cJSON_malloc(strlen((const char*)path) + 20 + sizeof("/")); /* Allow space for 64bit int. log10(2^64) = 20 */

            /* generate patches for all array elements that exist in both "from" and "to" */
            for (index = 0; (from_child != NULL) && (to_child != NULL); (void)(from_child = from_child->next), (void)(to_child = to_child->next), index++)
            {
                /* check if conversion to unsigned long is valid
                 * This should be eliminated at compile time by dead code elimination
                 * if size_t is an alias of unsigned long, or if it is bigger */
                if (index > ULONG_MAX)
                {
                    cJSON_free(new_path);
                    return;
                }
                sprintf((char*)new_path, "%s/%lu", path, (unsigned long)index); /* path of the current array element */
                create_patches(patches, new_path, from_child, to_child, case_sensitive);
            }

            /* remove leftover elements from 'from' that are not in 'to' */
            for (; (from_child != NULL); (void)(from_child = from_child->next))
            {
                /* check if conversion to unsigned long is valid
                 * This should be eliminated at compile time by dead code elimination
                 * if size_t is an alias of unsigned long, or if it is bigger */
                if (index > ULONG_MAX)
                {
                    cJSON_free(new_path);
                    return;
                }
                sprintf((char*)new_path, "%lu", (unsigned long)index);
                compose_patch(patches, (const unsigned char*)"remove", path, new_path, NULL);
            }
            /* add new elements in 'to' that were not in 'from' */
            for (; (to_child != NULL); (void)(to_child = to_child->next), index++)
            {
                compose_patch(patches, (const unsigned char*)"add", path, (const unsigned char*)"-", to_child);
            }
            cJSON_free(new_path);
            return;
        }

        case cJSON_Object:
        {
            cJSON *from_child = NULL;
            cJSON *to_child = NULL;
            sort_object(from, case_sensitive);
            sort_object(to, case_sensitive);

            from_child = from->child;
            to_child = to->child;
            /* for all object values in the object with more of them */
            while ((from_child != NULL) || (to_child != NULL))
            {
                int diff;
                if (from_child == NULL)
                {
                    diff = 1;
                }
                else if (to_child == NULL)
                {
                    diff = -1;
                }
                else
                {
                    diff = compare_strings((unsigned char*)from_child->string, (unsigned char*)to_child->string, case_sensitive);
                }

                if (diff == 0)
                {
                    /* both object keys are the same */
                    size_t path_length = strlen((const char*)path);
                    size_t from_child_name_length = pointer_encoded_length((unsigned char*)from_child->string);
                    unsigned char *new_path = (unsigned char*)cJSON_malloc(path_length + from_child_name_length + sizeof("/"));

                    sprintf((char*)new_path, "%s/", path);
                    encode_string_as_pointer(new_path + path_length + 1, (unsigned char*)from_child->string);

                    /* create a patch for the element */
                    create_patches(patches, new_path, from_child, to_child, case_sensitive);
                    cJSON_free(new_path);

                    from_child = from_child->next;
                    to_child = to_child->next;
                }
                else if (diff < 0)
                {
                    /* object element doesn't exist in 'to' --> remove it */
                    compose_patch(patches, (const unsigned char*)"remove", path, (unsigned char*)from_child->string, NULL);

                    from_child = from_child->next;
                }
                else
                {
                    /* object element doesn't exist in 'from' --> add it */
                    compose_patch(patches, (const unsigned char*)"add", path, (unsigned char*)to_child->string, to_child);

                    to_child = to_child->next;
                }
            }
            return;
        }

        default:
            break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, -0x2c(%rbp)
movq %rcx, %r13
testq %rdx, %rdx
sete %al
testq %rcx, %rcx
sete %cl
orb %al, %cl
je 0x6530
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movzbl 0x18(%rdx), %eax
movzbl 0x18(%r13), %ecx
cmpl %ecx, %eax
jne 0x6636
addl $-0x8, %eax
roll $0x1d, %eax
cmpl $0x7, %eax
ja 0x6521
leaq 0x1c74(%rip), %rcx      # 0x81d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %r15, -0x40(%rbp)
jmpq *%rax
movl 0x28(%r14), %eax
cmpl 0x28(%r13), %eax
jne 0x6636
movsd 0x30(%r14), %xmm0
ucomisd 0x30(%r13), %xmm0
jne 0x6636
jp 0x6636
jmp 0x6521
movq 0x10(%r14), %r15
movq 0x10(%r13), %r12
movq %rbx, -0x48(%rbp)
movq %rbx, %rdi
callq 0x2140
leaq 0x16(%rax), %rdi
callq 0x5169
testq %r15, %r15
setne %dl
testq %r12, %r12
setne %cl
andb %dl, %cl
cmpb $0x1, %cl
movq %rax, -0x38(%rbp)
jne 0x67c1
xorl %r14d, %r14d
movl -0x2c(%rbp), %r13d
movq %rax, %rbx
movq %rax, %rdi
leaq 0x1cb0(%rip), %rsi      # 0x828d
movq -0x48(%rbp), %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x22c0
movq -0x40(%rbp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
movl %r13d, %r8d
callq 0x64f9
movq (%r15), %r15
movq (%r12), %r12
incq %r14
testq %r15, %r15
je 0x67c6
testq %r12, %r12
movq -0x38(%rbp), %rax
jne 0x65d0
jmp 0x67ca
movq 0x20(%r14), %rdi
movq 0x20(%r13), %rsi
callq 0x2210
testl %eax, %eax
je 0x6521
leaq 0x1c3a(%rip), %rsi      # 0x8277
movq %r15, %rdi
movq %rbx, %rdx
xorl %ecx, %ecx
movq %r13, %r8
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x630f
movq 0x10(%r14), %rdi
movl -0x2c(%rbp), %r12d
movl %r12d, %esi
callq 0x7004
movq %rax, 0x10(%r14)
movq 0x10(%r13), %rdi
movl %r12d, %esi
callq 0x7004
movq %rax, %r12
movq %rax, 0x10(%r13)
movq 0x10(%r14), %r13
movq %r13, %rax
orq %r12, %rax
je 0x6521
testq %r13, %r13
je 0x66af
testq %r12, %r12
je 0x66b6
movq 0x38(%r13), %rdi
movq 0x38(%r12), %rsi
movl -0x2c(%rbp), %edx
callq 0x6f52
jmp 0x66bb
movl $0x1, %eax
jmp 0x66bb
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x66e4
js 0x679f
movq 0x38(%r12), %rcx
movq %r15, %rdi
leaq 0x1b98(%rip), %rsi      # 0x826c
movq %rbx, %rdx
movq %r12, %r8
callq 0x630f
jmp 0x6796
movq %rbx, %rdi
callq 0x2140
movq %rax, %r15
movq 0x38(%r13), %rax
xorl %ecx, %ecx
movzbl (%rax), %edx
cmpl $0x2f, %edx
je 0x6708
cmpl $0x7e, %edx
je 0x6708
testl %edx, %edx
jne 0x670b
jmp 0x6713
incq %rcx
incq %rax
incq %rcx
jmp 0x66f5
leaq (%r15,%rcx), %rdi
addq $0x2, %rdi
callq 0x5169
movq %rax, %r14
movq %rax, %rdi
leaq 0x1b5c(%rip), %rsi      # 0x8289
movq %rbx, %rdx
xorl %eax, %eax
callq 0x22c0
movq %r14, %rax
addq %r15, %rax
movq 0x38(%r13), %rcx
movq -0x40(%rbp), %r15
movzbl (%rcx), %edx
cmpl $0x2f, %edx
je 0x6765
cmpl $0x7e, %edx
je 0x675d
incq %rax
testl %edx, %edx
je 0x6772
movb %dl, (%rax)
jmp 0x676d
movw $0x317e, 0x1(%rax)      # imm = 0x317E
jmp 0x6769
movb $0x31, 0x2(%rax)
addq $0x2, %rax
incq %rcx
jmp 0x6745
movb $0x0, (%rax)
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r12, %rcx
movl -0x2c(%rbp), %r8d
callq 0x64f9
movq %r14, %rdi
callq 0x5174
movq (%r13), %r13
movq (%r12), %r12
jmp 0x6686
movq 0x38(%r13), %rcx
movq %r15, %rdi
leaq 0x1ac3(%rip), %rsi      # 0x8270
movq %rbx, %rdx
xorl %r8d, %r8d
callq 0x630f
movq (%r13), %r13
jmp 0x6686
xorl %r14d, %r14d
jmp 0x67ca
movq -0x38(%rbp), %rax
testq %r15, %r15
movq -0x40(%rbp), %rbx
je 0x680b
movq %rax, %r13
movq %r13, %rdi
leaq 0x1ab0(%rip), %rsi      # 0x8290
movq %r14, %rdx
xorl %eax, %eax
callq 0x22c0
movq %rbx, %rdi
leaq 0x1a7c(%rip), %rsi      # 0x8270
movq -0x48(%rbp), %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0x630f
movq (%r15), %r15
testq %r15, %r15
jne 0x67d6
testq %r12, %r12
movq -0x48(%rbp), %r13
je 0x683f
leaq 0x1a51(%rip), %r14      # 0x826c
leaq 0x1a45(%rip), %r15      # 0x8267
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x630f
movq (%r12), %r12
testq %r12, %r12
jne 0x6822
movq -0x38(%rbp), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5174