// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x8c7d
cmpq $0x0, -0x20(%rbp)
jne 0x8c82
jmp 0x90b0
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
andl $0xff, %eax
movq -0x20(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0xff, %ecx
cmpl %ecx, %eax
je 0x8cc0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %r8
leaq 0x36ad(%rip), %rsi      # 0xc35f
xorl %eax, %eax
movl %eax, %ecx
callq 0x8a60
jmp 0x90b0
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %eax
movl %eax, -0x7c(%rbp)
subl $0x8, %eax
je 0x8cfb
jmp 0x8cd2
movl -0x7c(%rbp), %eax
subl $0x10, %eax
je 0x8d44
jmp 0x8cdc
movl -0x7c(%rbp), %eax
subl $0x20, %eax
je 0x8d7f
jmp 0x8cea
movl -0x7c(%rbp), %eax
subl $0x40, %eax
je 0x8f00
jmp 0x90ae
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jne 0x8d23
movq -0x18(%rbp), %rax
movsd 0x30(%rax), %xmm0
movq -0x20(%rbp), %rax
ucomisd 0x30(%rax), %xmm0
jne 0x8d23
jp 0x8d23
jmp 0x8d3f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %r8
leaq 0x3629(%rip), %rsi      # 0xc35f
xorl %eax, %eax
movl %eax, %ecx
callq 0x8a60
jmp 0x90b0
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x2250
cmpl $0x0, %eax
je 0x8d7a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %r8
leaq 0x35ee(%rip), %rsi      # 0xc35f
xorl %eax, %eax
movl %eax, %ecx
callq 0x8a60
jmp 0x90b0
movq $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2160
movq %rax, %rdi
addq $0x14, %rdi
addq $0x2, %rdi
callq 0x6200
movq %rax, -0x48(%rbp)
movq $0x0, -0x30(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x38(%rbp)
movb %al, -0x7d(%rbp)
je 0x8ddb
cmpq $0x0, -0x40(%rbp)
setne %al
movb %al, -0x7d(%rbp)
movb -0x7d(%rbp), %al
testb $0x1, %al
jne 0x8de4
jmp 0x8e53
cmpq $-0x1, -0x30(%rbp)
jbe 0x8df9
movq -0x48(%rbp), %rdi
callq 0x6220
jmp 0x90b0
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
leaq 0x3569(%rip), %rsi      # 0xc375
movb $0x0, %al
callq 0x22f0
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl -0x24(%rbp), %r8d
callq 0x8c50
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x8dc4
jmp 0x8e55
cmpq $0x0, -0x38(%rbp)
je 0x8eb1
cmpq $-0x1, -0x30(%rbp)
jbe 0x8e71
movq -0x48(%rbp), %rdi
callq 0x6220
jmp 0x90b0
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x34f8(%rip), %rsi      # 0xc378
movb $0x0, %al
callq 0x22f0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x48(%rbp), %rcx
leaq 0x34be(%rip), %rsi      # 0xc358
xorl %eax, %eax
movl %eax, %r8d
callq 0x8a60
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x8e55
jmp 0x8eb3
cmpq $0x0, -0x40(%rbp)
je 0x8ef2
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x40(%rbp), %r8
leaq 0x3487(%rip), %rsi      # 0xc354
leaq 0x347b(%rip), %rcx      # 0xc34f
callq 0x8a60
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x8eb3
movq -0x48(%rbp), %rdi
callq 0x6220
jmp 0x90b0
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x9150
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x9150
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
movb $0x1, %al
cmpq $0x0, -0x50(%rbp)
movb %al, -0x7e(%rbp)
jne 0x8f57
cmpq $0x0, -0x58(%rbp)
setne %al
movb %al, -0x7e(%rbp)
movb -0x7e(%rbp), %al
testb $0x1, %al
jne 0x8f63
jmp 0x90ac
cmpq $0x0, -0x50(%rbp)
jne 0x8f73
movl $0x1, -0x5c(%rbp)
jmp 0x8fa0
cmpq $0x0, -0x58(%rbp)
jne 0x8f83
movl $0xffffffff, -0x5c(%rbp) # imm = 0xFFFFFFFF
jmp 0x8f9e
movq -0x50(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x58(%rbp), %rax
movq 0x38(%rax), %rsi
movl -0x24(%rbp), %edx
callq 0xa030
movl %eax, -0x5c(%rbp)
jmp 0x8fa0
cmpl $0x0, -0x5c(%rbp)
jne 0x9046
movq -0x10(%rbp), %rdi
callq 0x2160
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x8090
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
addq -0x70(%rbp), %rdi
addq $0x2, %rdi
callq 0x6200
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x3385(%rip), %rsi      # 0xc371
movb $0x0, %al
callq 0x22f0
movq -0x78(%rbp), %rdi
addq -0x68(%rbp), %rdi
addq $0x1, %rdi
movq -0x50(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x8100
movq -0x8(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x58(%rbp), %rcx
movl -0x24(%rbp), %r8d
callq 0x8c50
movq -0x78(%rbp), %rdi
callq 0x6220
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x90a7
cmpl $0x0, -0x5c(%rbp)
jge 0x907a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x50(%rbp), %rax
movq 0x38(%rax), %rcx
leaq 0x32f5(%rip), %rsi      # 0xc358
xorl %eax, %eax
movl %eax, %r8d
callq 0x8a60
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x90a5
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x58(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x58(%rbp), %r8
leaq 0x32bf(%rip), %rsi      # 0xc354
callq 0x8a60
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x90a7
jmp 0x8f40
jmp 0x90b0
jmp 0x90b0
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)