// File: /workspace/github_c_makefile_star2_O3/Ziddykins[P]Dawn/src/util.c
// Function: priority_remove_min
void * priority_remove_min(PriorityQueue pq) {
    //save element to return for later use
    void *elem = pq->min->tree->elem;

    //remove minimum
    if (pq->min_prev) {
        pq->min_prev->next = pq->min->next;
    } else {
        pq->head = pq->min->next;
    }
    //split min tree into subtrees and insert them
    if(pq->min->tree->children) {
        pq->min->tree->last_child->next = pq->head;
        pq->head = pq->min->tree->children;
    }
    free(pq->min->tree);
    free(pq->min);

    struct priority_node **trees; //needed for cleanup algorithm
    size_t const len = (size_t)(2*ceillog2ul(pq->size)+1);
    CALLEXIT(!(trees = calloc(len, sizeof trees)));

    struct priority_node * current_node = pq->head;

    while(current_node) {
        struct priority_node * process_node = current_node;
        current_node = current_node->next;
        while(1) {
            int degree = process_node->tree->degree;
            if(trees[degree] == NULL) {
                trees[degree] = process_node;
                break;
            } else {
                if(trees[degree]->tree->priority > process_node->tree->priority) {
                    priority_add_child(process_node->tree, trees[degree]);
                } else {
                    priority_add_child(trees[degree]->tree, process_node);
                    process_node = trees[degree];
                }
                trees[degree] = NULL;
            }
        }
    }

    pq->size--;
    pq->head = NULL;
    pq->min = NULL;
    pq->min_prev = NULL;
    if(pq->size) {
        size_t i;
        for(i = 0; !trees[i]; i++);
        pq->head = trees[i];
        pq->head->next = NULL;
        pq->min = pq->head;

        for(i++; i < len; i++) {
            if(trees[i]) {
                trees[i]->next = pq->head;
                pq->head = trees[i];
                priority_update_min(pq);
            }
        }
    }

    free(trees);
    return elem;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rax
movq 0x10(%rdi), %rcx
movq (%rax), %rdi
movq 0x8(%rax), %rax
leaq 0x8(%rcx), %rdx
testq %rcx, %rcx
cmoveq %rbx, %rdx
movq (%rdi), %r14
movq %rax, (%rdx)
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x109ce
movq (%rbx), %rcx
movq 0x10(%rdi), %rdx
movq %rcx, 0x8(%rdx)
movq %rax, (%rbx)
callq 0x2240
movq 0x8(%rbx), %rdi
callq 0x2240
movq 0x18(%rbx), %r12
bsrq %r12, %r15
xorl $0x3f, %r15d
addl %r15d, %r15d
movl $0x81, %edi
subq %r15, %rdi
movl $0x8, %esi
callq 0x2110
testq %rax, %rax
je 0x10b60
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x10aa4
movq %rcx, %rdx
movq (%rcx), %rdi
movq 0x8(%rcx), %rcx
movslq 0x18(%rdi), %r8
leaq (%rax,%r8,8), %rsi
movq (%rax,%r8,8), %r9
testq %r9, %r9
je 0x10a9c
leaq 0x18(%rdi), %r10
movq (%r9), %r11
movss 0x1c(%r11), %xmm0
ucomiss 0x1c(%rdi), %xmm0
jbe 0x10a5f
movq 0x8(%rdi), %r11
movq %r11, 0x8(%r9)
movq %r9, 0x8(%rdi)
incl %r8d
movl %r8d, (%r10)
cmpq $0x0, 0x10(%rdi)
jne 0x10a7d
movq %r9, 0x10(%rdi)
jmp 0x10a7d
movq 0x8(%r11), %rdi
movq %rdi, 0x8(%rdx)
movq %rdx, 0x8(%r11)
incl 0x18(%r11)
cmpq $0x0, 0x10(%r11)
jne 0x10a7a
movq %rdx, 0x10(%r11)
movq (%rsi), %rdx
movq $0x0, (%rsi)
movq (%rdx), %rdi
leaq 0x18(%rdi), %r10
movslq 0x18(%rdi), %r8
leaq (%rax,%r8,8), %rsi
movq (%rax,%r8,8), %r9
testq %r9, %r9
jne 0x10a31
movq %rdx, (%rsi)
jmp 0x10a09
decq %r12
movq %r12, 0x18(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
je 0x10b49
movl $0x80, %ecx
leaq 0x8(%rbx), %rdx
leaq 0x10(%rbx), %rsi
subq %r15, %rcx
xorl %edi, %edi
movq (%rax,%rdi,8), %r9
incq %rdi
testq %r9, %r9
je 0x10ad1
movq %r9, (%rbx)
movq $0x0, 0x8(%r9)
movq %r9, 0x8(%rbx)
cmpq %rcx, %rdi
ja 0x10b49
decq %rdi
movq 0x8(%rax,%rdi,8), %r8
testq %r8, %r8
je 0x10b30
movq %r9, 0x8(%r8)
movq %r8, (%rbx)
movq 0x8(%rbx), %r9
testq %r9, %r9
je 0x10b21
movq (%r9), %r9
movss 0x1c(%r9), %xmm0
movq (%r8), %r9
ucomiss 0x1c(%r9), %xmm0
jbe 0x10b35
movq $0x0, (%rsi)
movq %rdx, %r9
movq %r8, (%r9)
jmp 0x10b3e
movq %r9, %r8
jmp 0x10b3e
cmpq $0x0, (%rsi)
movq %rsi, %r9
je 0x10b2b
incq %rdi
movq %r8, %r9
cmpq %rcx, %rdi
jb 0x10af4
movq %rax, %rdi
callq 0x2240
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
callq 0x30d6