// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movl %esi, %r15d
movq %rdi, %r12
movl $0x18, %edi
callq 0x1070
movq %rax, %r13
movq $0x0, 0x10(%rax)
movl $0x20, %edi
callq 0x1070
movl %r15d, 0x10(%rax)
movq %r13, %rdi
movq %rax, %rsi
callq 0x1e34
cmpq $0x0, 0x10(%r13)
je 0x19dd
movq %r12, -0x30(%rbp)
movq %r13, -0x60(%rbp)
movq (%r13), %rax
movslq 0x10(%rax), %rbx
movl 0x28(%r12), %eax
movq %rax, -0x48(%rbp)
testl %eax, %eax
jle 0x1970
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
incq -0x48(%rbp)
movl $0x1, %ecx
movq %rbx, -0x50(%rbp)
leaq (%rcx,%rcx,2), %rax
movq -0x68(%rbp), %rdx
leaq (%rdx,%rax,8), %rdi
movq 0x10(%rdi), %rax
movq %rax, -0x38(%rbp)
testl %eax, %eax
jle 0x195e
movq %rdi, -0x70(%rbp)
movq (%rdi), %rax
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, -0x38(%rbp)
movl $0x1, %ebx
xorl %r15d, %r15d
movq %rcx, -0x58(%rbp)
movq -0x78(%rbp), %rax
movl (%rax,%r15,4), %edx
movl %edx, -0x3c(%rbp)
movq -0x30(%rbp), %r14
movq %r14, %rdi
movq -0x50(%rbp), %r12
movl %r12d, %esi
movq -0x58(%rbp), %r13
movl %r13d, %ecx
callq 0x17ac
movl %eax, -0x40(%rbp)
movq %r14, %rdi
movl -0x3c(%rbp), %esi
movl %r12d, %edx
movl %r13d, %ecx
callq 0x17ac
andl -0x40(%rbp), %ebx
andl %eax, %ebx
incq %r15
cmpq %r15, -0x38(%rbp)
jne 0x18f4
testl %ebx, %ebx
movq -0x60(%rbp), %r13
movq -0x50(%rbp), %rbx
movq -0x58(%rbp), %rcx
movq -0x70(%rbp), %rdi
jne 0x195e
incq %rcx
cmpq -0x48(%rbp), %rcx
jne 0x18b4
jmp 0x1970
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl %ecx, (%rax,%rbx,4)
movl %ebx, %esi
callq 0x1f4b
movq -0x30(%rbp), %r12
movq (%r12), %rax
leaq (%rbx,%rbx,2), %rbx
cmpl $0x0, 0x10(%rax,%rbx,8)
jle 0x19ca
leaq (%rax,%rbx,8), %rax
xorl %r14d, %r14d
movq 0x20(%r12), %rcx
movq (%rax), %rax
movslq (%rax,%r14,4), %r15
cmpl $0x0, (%rcx,%r15,4)
jne 0x19b6
movl $0x20, %edi
callq 0x1070
movl %r15d, 0x10(%rax)
movq %r13, %rdi
movq %rax, %rsi
callq 0x1e34
incq %r14
movq (%r12), %rax
leaq (%rax,%rbx,8), %rax
movslq 0x10(%rax), %rcx
cmpq %rcx, %r14
jl 0x198a
movq %r13, %rdi
callq 0x1e76
cmpq $0x0, 0x10(%r13)
jne 0x1882
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq