// File: /workspace/github_c_makefile_star2_O2/ammarfaizi2[P]riyuu/src/third_party/cjson/cJSON_Utils.c
// Function: sort_list(cJSON*, int)
static cJSON *sort_list(cJSON *list, const cJSON_bool case_sensitive)
{
    cJSON *first = list;
    cJSON *second = list;
    cJSON *current_item = list;
    cJSON *result = list;
    cJSON *result_tail = NULL;

    if ((list == NULL) || (list->next == NULL))
    {
        /* One entry is sorted already. */
        return result;
    }

    while ((current_item != NULL) && (current_item->next != NULL) && (compare_strings((unsigned char*)current_item->string, (unsigned char*)current_item->next->string, case_sensitive) < 0))
    {
        /* Test for list sorted. */
        current_item = current_item->next;
    }
    if ((current_item == NULL) || (current_item->next == NULL))
    {
        /* Leave sorted lists unmodified. */
        return result;
    }

    /* reset pointer to the beginning */
    current_item = list;
    while (current_item != NULL)
    {
        /* Walk two pointers to find the middle. */
        second = second->next;
        current_item = current_item->next;
        /* advances current_item two steps at a time */
        if (current_item != NULL)
        {
            current_item = current_item->next;
        }
    }
    if ((second != NULL) && (second->prev != NULL))
    {
        /* Split the lists */
        second->prev->next = NULL;
        second->prev = NULL;
    }

    /* Recursively sort the sub-lists. */
    first = sort_list(first, case_sensitive);
    second = sort_list(second, case_sensitive);
    result = NULL;

    /* Merge the sub-lists */
    while ((first != NULL) && (second != NULL))
    {
        cJSON *smaller = NULL;
        if (compare_strings((unsigned char*)first->string, (unsigned char*)second->string, case_sensitive) < 0)
        {
            smaller = first;
        }
        else
        {
            smaller = second;
        }

        if (result == NULL)
        {
            /* start merged list with the smaller element */
            result_tail = smaller;
            result = smaller;
        }
        else
        {
            /* add smaller element to the list */
            result_tail->next = smaller;
            smaller->prev = result_tail;
            result_tail = smaller;
        }

        if (first == smaller)
        {
            first = first->next;
        }
        else
        {
            second = second->next;
        }
    }

    if (first != NULL)
    {
        /* Append rest of first list. */
        if (result == NULL)
        {
            return first;
        }
        result_tail->next = first;
        first->prev = result_tail;
    }
    if (second != NULL)
    {
        /* Append rest of second list */
        if (result == NULL)
        {
            return second;
        }
        result_tail->next = second;
        second->prev = result_tail;
    }

    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x64a5
movq %rdi, %r14
movq (%rdi), %rax
testq %rax, %rax
je 0x64a8
movl %esi, %ebx
movq %r14, %rcx
testq %rax, %rax
je 0x64a8
movq %rax, %r15
movq 0x38(%rcx), %rdi
movq 0x38(%rax), %rsi
movl %ebx, %edx
callq 0x63d2
testl %eax, %eax
jns 0x64ba
movq (%r15), %rax
movq %r15, %rcx
jmp 0x6482
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %r15
movq %r14, %rax
testq %rax, %rax
je 0x64da
movq (%r15), %r15
movq (%rax), %rcx
movl $0x0, %eax
testq %rcx, %rcx
je 0x64c0
movq (%rcx), %rax
jmp 0x64c0
testq %r15, %r15
je 0x64f1
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x64f1
andq $0x0, (%rax)
andq $0x0, 0x8(%r15)
movq %r14, %rdi
movl %ebx, %esi
callq 0x645f
movq %rax, %r12
movq %r15, %rdi
movl %ebx, %esi
callq 0x645f
movq %rax, %r15
xorl %eax, %eax
xorl %ecx, %ecx
movq %rax, %r14
movq %rcx, %r13
testq %r12, %r12
je 0x655c
testq %r15, %r15
je 0x655c
movq 0x38(%r12), %rdi
movq 0x38(%r15), %rsi
movl %ebx, %edx
callq 0x63d2
movq %r12, %rcx
testl %eax, %eax
js 0x6539
movq %r15, %rcx
movq %rcx, %rax
testq %r14, %r14
je 0x654c
movq %rcx, (%r13)
movq %r13, 0x8(%rcx)
movq %r14, %rax
cmpq %rcx, %r12
je 0x6556
movq (%r15), %r15
jmp 0x650f
movq (%r12), %r12
jmp 0x650f
testq %r12, %r12
je 0x656f
testq %r14, %r14
je 0x658a
movq %r12, (%r13)
movq %r13, 0x8(%r12)
testq %r15, %r15
je 0x64a8
testq %r14, %r14
je 0x6592
movq %r15, (%r13)
movq %r13, 0x8(%r15)
jmp 0x64a8
movq %r12, %r14
jmp 0x64a8
movq %r15, %r14
jmp 0x64a8
nop