// File: /workspace/github_c_makefile_star2_O0/rikuu[P]kermit/color.c
// Function: km_propagate
void km_propagate(asg_t *g, km_color_t *colors, int max_depth)
{
	// miniasm has 2 vertices per read, 1 for each strand.
	// should we make sure to follow stranded-ness?
	uint32_t n_vtx = g->n_seq;
	// TODO: this could be optimized further, used as a bitvector
	int8_t *visited = (int8_t*) calloc(n_vtx, sizeof(int8_t));
	size_t n_uncolored = 0, n_colored = 0;
	km_color_v reachable = {0, 0, 0};
	kvec_t(queue_item_t) queue = {0, 0, 0};
	for (uint32_t v = 0; v < n_vtx; ++v) {
		if (COLORED(colors[v])) continue;
		n_uncolored++;
		queue_item_t s = {v, 0};
		kv_push(queue_item_t, queue, s);
		while (queue.n > 0) {
			s = queue.a[--(queue.n)];
			visited[s.node] = 1;
			if (s.depth > max_depth) continue;
			if (COLORED(colors[s.node])) {
				if (!contains(reachable.a, reachable.n, colors[s.node]))
					kv_push(km_color_t, reachable, colors[s.node]);
			} else {
				// push all neighbors to stack
				uint32_t nv = asg_arc_n(g, s.node);
				asg_arc_t *av = asg_arc_a(g, s.node);
				for (uint32_t j = 0; j < nv; ++j) {
					queue_item_t neighbor = {av[j].v >> 1, s.depth + 1};
					if (!av[j].del && !visited[neighbor.node])
						kv_push(queue_item_t, queue, neighbor);
				}
			}
		}
		km_color_t r = merge_colors(reachable);
		if (COLORED(r)) {
			colors[v] = r, ++n_colored;
		} else asg_seq_del(g, v);

		memset(visited, 0, g->n_seq);
		reachable.n = 0, queue.n = 0;
	}
	fprintf(stderr, "[M::%s] colored %ld, removed %ld uncolored nodes\n", __func__, n_colored, n_uncolored - n_colored);
	free(visited);
	kv_destroy(reachable);
	kv_destroy(queue);
	if (n_uncolored != n_colored)
		asg_cleanup(g);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x10e0
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x10c0
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x10c0
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x18(%rbp), %eax
jae 0xc2ec
movq -0x10(%rbp), %rax
movl -0x64(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jne 0xbf64
movq -0x10(%rbp), %rax
movl -0x64(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
je 0xbf69
jmp 0xc2de
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl $0x0, -0x68(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x58(%rbp), %rax
jne 0xbfd1
cmpq $0x0, -0x58(%rbp)
je 0xbfa3
movq -0x58(%rbp), %rax
shlq %rax
movq %rax, -0xa0(%rbp)
jmp 0xbfb1
movl $0x2, %eax
movq %rax, -0xa0(%rbp)
jmp 0xbfb1
movq -0xa0(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
shlq $0x3, %rsi
callq 0x1170
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x60(%rbp)
movq -0x6c(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0xbfee
cmpq $0x0, -0x60(%rbp)
jbe 0xc232
movq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, %rdx
addq $-0x1, %rdx
movq %rdx, -0x60(%rbp)
movq -0x8(%rax,%rcx,8), %rax
movq %rax, -0x6c(%rbp)
movq -0x20(%rbp), %rax
movl -0x6c(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movl -0x68(%rbp), %eax
cmpl -0x14(%rbp), %eax
jle 0xc02a
jmp 0xbfee
movq -0x10(%rbp), %rax
movl -0x6c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jne 0xc057
movq -0x10(%rbp), %rax
movl -0x6c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
je 0xc110
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x10(%rbp), %rax
movl -0x6c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq 0x8(%rax), %rcx
callq 0xc350
cmpl $0x0, %eax
jne 0xc10b
jmp 0xc084
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jne 0xc0d3
cmpq $0x0, -0x40(%rbp)
je 0xc0a5
movq -0x40(%rbp), %rax
shlq %rax
movq %rax, -0xa8(%rbp)
jmp 0xc0b3
movl $0x2, %eax
movq %rax, -0xa8(%rbp)
jmp 0xc0b3
movq -0xa8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
shlq $0x4, %rsi
callq 0x1170
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movl -0x6c(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0xc10b
jmp 0xc22d
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x6c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x70(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl -0x6c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x70(%rbp), %eax
jae 0xc22b
movq -0x78(%rbp), %rax
movl -0x7c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, -0x84(%rbp)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
movq -0x78(%rbp), %rax
movl -0x7c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0xc21b
movq -0x20(%rbp), %rax
movl -0x84(%rbp), %ecx
cmpb $0x0, (%rax,%rcx)
jne 0xc21b
jmp 0xc1ac
movq -0x60(%rbp), %rax
cmpq -0x58(%rbp), %rax
jne 0xc1fb
cmpq $0x0, -0x58(%rbp)
je 0xc1cd
movq -0x58(%rbp), %rax
shlq %rax
movq %rax, -0xb0(%rbp)
jmp 0xc1db
movl $0x2, %eax
movq %rax, -0xb0(%rbp)
jmp 0xc1db
movq -0xb0(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
shlq $0x3, %rsi
callq 0x1170
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x60(%rbp)
movq -0x84(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0xc21b
jmp 0xc21d
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0xc14f
jmp 0xc22d
jmp 0xbfee
leaq -0x48(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xc3d0
movq %rax, -0x98(%rbp)
movq %rdx, -0x90(%rbp)
cmpq $0x0, -0x98(%rbp)
jne 0xc276
cmpq $0x0, -0x90(%rbp)
je 0xc2a7
movq -0x10(%rbp), %rax
movl -0x64(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x98(%rbp), %rcx
movq %rcx, (%rax)
movq -0x90(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xc2b3
movq -0x8(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0xc540
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x10c0
movq $0x0, -0x48(%rbp)
movq $0x0, -0x60(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xbf2f
movq 0x6d05(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %r8
subq -0x30(%rbp), %r8
leaq 0x34ce(%rip), %rsi      # 0xf7d7
leaq 0x34f9(%rip), %rdx      # 0xf809
movb $0x0, %al
callq 0x1110
movq -0x20(%rbp), %rdi
callq 0x1040
movq -0x38(%rbp), %rdi
callq 0x1040
movq -0x50(%rbp), %rdi
callq 0x1040
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0xc345
movq -0x8(%rbp), %rdi
callq 0x35d0
addq $0xd0, %rsp
popq %rbp
retq
nop