// File: /workspace/github_c_makefile_star2_O0/sachinites[P]CommandParser/gluethread/glthread.c
// Function: glthread_priority_insert
void
glthread_priority_insert(glthread_t *glthread_head, 
                         glthread_t *glthread,
                         int (*comp_fn)(void *, void *),
                         int offset){


    glthread_t *curr = NULL,
               *prev = NULL;

    init_glthread(glthread);

    if(IS_GLTHREAD_LIST_EMPTY(glthread_head)){
        glthread_add_next(glthread_head, glthread);
        return;
    }

    /* Only one node*/
    if(glthread_head->right && !glthread_head->right->right){
        if(comp_fn(GLTHREAD_GET_USER_DATA_FROM_OFFSET(glthread, offset),
            GLTHREAD_GET_USER_DATA_FROM_OFFSET(glthread_head->right, offset)) == -1){
            glthread_add_next(glthread_head, glthread);
        }
        else{
            glthread_add_next(glthread_head->right, glthread);
        }
        return;
    }

    ITERATE_GLTHREAD_BEGIN(glthread_head, curr){

        if(comp_fn(GLTHREAD_GET_USER_DATA_FROM_OFFSET(glthread, offset), 
                GLTHREAD_GET_USER_DATA_FROM_OFFSET(curr, offset)) != -1){
            prev = curr;
            continue;
        }

		if(!prev)
			glthread_add_next(glthread_head, glthread);
		else
			glthread_add_next(prev, glthread);

		return;

    }ITERATE_GLTHREAD_END(glthread_head, curr);

    /*Add in the end*/
    glthread_add_next(prev, glthread);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x9430
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x97a7
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x97a7
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x9460
jmp 0x98ad
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x9815
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x8(%rax)
jne 0x9815
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rdi
movslq -0x1c(%rbp), %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rdi
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rsi
movslq -0x1c(%rbp), %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rsi
callq *%rax
cmpl $-0x1, %eax
jne 0x97ff
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x9460
jmp 0x9810
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x9460
jmp 0x98ad
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x98a0
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rdi
movslq -0x1c(%rbp), %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rdi
movq -0x28(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rsi
callq *%rax
cmpl $-0x1, %eax
je 0x9871
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x9896
cmpq $0x0, -0x30(%rbp)
jne 0x9887
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x9460
jmp 0x9894
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x9460
jmp 0x98ad
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x9829
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x9460
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)