// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x18, %edi
callq 0x1060
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0x10(%rax)
movl $0x1, -0x20(%rbp)
movl $0x20, %edi
callq 0x1060
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x24e0
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jbe 0x1d96
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl 0x10(%rax), %eax
movl %eax, -0x1c(%rbp)
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jg 0x1ceb
movl $0x1, -0x20(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
cmpl %ecx, %eax
jge 0x1ca6
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movl -0x2c(%rbp), %ecx
callq 0x19d0
andl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %esi
movl -0x1c(%rbp), %edx
movl -0x2c(%rbp), %ecx
callq 0x19d0
andl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1c16
cmpl $0x0, -0x20(%rbp)
je 0x1cdb
movl -0x2c(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x1c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0x2c(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movl -0x1c(%rbp), %esi
callq 0x26f0
jmp 0x1ceb
jmp 0x1cdd
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1bf8
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x1c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
cmpl %ecx, %eax
jge 0x1d88
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x1c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movslq -0x34(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x1d78
movl $0x20, %edi
callq 0x1060
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x24e0
jmp 0x1d7a
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1cf2
movq -0x18(%rbp), %rdi
callq 0x2570
jmp 0x1bd5
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)