// File: /workspace/github_c_makefile_star2_O2/jalalium[P]graph_algorithms_task/src_ranking/main_rank.c
// Function: rank
void	rank(t_graph *g, int root)
{
	t_queue_int *kyou = (t_queue_int*)malloc(sizeof(t_queue_int));
	kyou->size = 0;
	int			front;
	int			doable = 1;
	t_qlayer_int *tmp = (t_qlayer_int*)malloc(sizeof(t_qlayer));

	tmp->node = root;
	push_q_i(kyou, tmp);

	while (kyou->size > 0)
	{
		front = kyou->head->node;
		for (int  pos_rank = 1; pos_rank <= g->vertx; pos_rank++)
		{
			doable = 1;
			// checks if it is doable to assign this rank to this node with all vertices of the same rank
			for (int j = 0; j < (int)g->ranked[pos_rank].used; j++)
			{
				doable &= all_paths_are_good(g, front, g->ranked[pos_rank].tab[j], pos_rank);
				doable &= all_paths_are_good(g, g->ranked[pos_rank].tab[j], front, pos_rank);
			}
			if (doable)
			{
				g->rank[front] = pos_rank;
				push_back(&(g->ranked[pos_rank]), front);
				break;
			}
		}
		for (int i = 0; i < (int)g->adj[front].used; i++)
		{
			if (g->rank[g->adj[front].tab[i]] == 0)
			{
				t_qlayer_int *tt = (t_qlayer_int*)malloc(sizeof(t_qlayer));
				tt->node = g->adj[front].tab[i];
				push_q_i(kyou, tt);
			}
		}
		pop_q_i(kyou);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %r15d
movq %rdi, %r12
pushq $0x18
popq %rdi
callq 0x1070
movq %rax, %rbx
andq $0x0, 0x10(%rax)
pushq $0x20
popq %rdi
callq 0x1070
movl %r15d, 0x10(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1d0c
movq %r12, -0x30(%rbp)
movq %rbx, -0x50(%rbp)
movq -0x30(%rbp), %r13
cmpq $0x0, 0x10(%rbx)
je 0x18f3
movq (%rbx), %rax
movslq 0x10(%rax), %rbx
movl 0x28(%r12), %ecx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
incl %ecx
movq %rcx, -0x60(%rbp)
pushq $0x1
popq %rcx
movq %rbx, -0x38(%rbp)
cmpq -0x60(%rbp), %rcx
je 0x189a
movq 0x10(%r12), %rax
movq %rcx, -0x40(%rbp)
imulq $0x18, %rcx, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, -0x58(%rbp)
movl 0x10(%rax,%rcx), %ecx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
movq %rcx, -0x68(%rbp)
xorl %ecx, %ecx
pushq $0x1
popq %r12
cmpq %rcx, -0x68(%rbp)
je 0x1862
movq -0x58(%rbp), %rax
movq (%rax), %rax
movl (%rax,%rcx,4), %r14d
movq %r13, %rdi
movq -0x38(%rbp), %r15
movl %r15d, %esi
movl %r14d, %edx
movq -0x40(%rbp), %rbx
movq %rcx, -0x70(%rbp)
movl %ebx, %ecx
callq 0x16e4
movl %eax, -0x44(%rbp)
movq %r13, %rdi
movl %r14d, %esi
movl %r15d, %edx
movl %ebx, %ecx
callq 0x16e4
movq -0x70(%rbp), %rcx
andl -0x44(%rbp), %eax
andl %eax, %r12d
incq %rcx
jmp 0x1813
testl %r12d, %r12d
jne 0x187b
movq -0x40(%rbp), %rcx
incq %rcx
movq -0x30(%rbp), %r12
movq -0x38(%rbp), %rbx
jmp 0x17dc
movq -0x30(%rbp), %r12
movq 0x20(%r12), %rax
movq -0x38(%rbp), %rbx
movq -0x40(%rbp), %rcx
movl %ecx, (%rax,%rbx,4)
movq -0x58(%rbp), %rdi
movl %ebx, %esi
callq 0x1e19
imulq $0x18, %rbx, %rbx
xorl %r14d, %r14d
movq (%r12), %rax
movslq 0x10(%rax,%rbx), %rcx
cmpq %rcx, %r14
jge 0x18e2
addq %rbx, %rax
movq 0x20(%r12), %rcx
movq (%rax), %rax
movslq (%rax,%r14,4), %r15
cmpl $0x0, (%rcx,%r15,4)
jne 0x18dd
pushq $0x20
popq %rdi
callq 0x1070
movl %r15d, 0x10(%rax)
movq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x1d0c
incq %r14
jmp 0x18a1
movq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x1d4e
jmp 0x17ae
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq