// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edx, 0x44(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movl 0x14(%rdi), %r15d
movq %r15, %rdi
andq $0x7fffffff, %rdi       # imm = 0x7FFFFFFF
pushq $0x1
popq %rsi
callq 0x10f0
movq %rax, %r10
movq $0x0, 0x8(%rsp)
movl $0x0, %edi
movl $0x0, %eax
movq %rax, 0x30(%rsp)
movl $0x0, %r13d
andq $0x7fffffff, %r15       # imm = 0x7FFFFFFF
je 0x24f0
xorl %ebp, %ebp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
xorl %edi, %edi
movq $0x0, 0x8(%rsp)
movq $0x0, 0x48(%rsp)
movq %r10, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %r15, 0x50(%rsp)
movq %rbp, %rax
shlq $0x4, %rax
cmpq $0x0, (%r14,%rax)
jne 0x24e4
addq %r14, %rax
cmpq $0x0, 0x8(%rax)
jne 0x24e4
movq %rax, 0x68(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x2176
pushq $0x10
popq %rsi
callq 0x1180
movq 0x10(%rsp), %r10
movq %rax, %rdi
pushq $0x2
popq %rax
movq %rax, 0x28(%rsp)
movq %rbp, 0x20(%rsp)
movl %ebp, (%rdi)
andl $0x0, 0x4(%rdi)
incq %r13
xorl %r8d, %r8d
pushq $0x1
popq %rbp
movq %r13, 0x70(%rsp)
movl 0x44(%rsp), %eax
subq $0x1, %rbp
jb 0x234b
movl (%rdi,%rbp,8), %edx
movl 0x4(%rdi,%rbp,8), %r15d
movb $0x1, (%r10,%rdx)
cmpl %eax, %r15d
jg 0x2193
movq %rdx, %r14
shlq $0x4, %r14
movq 0x18(%rsp), %rcx
movq (%rcx,%r14), %rax
movq 0x8(%rcx,%r14), %rcx
movq %rax, %rsi
orq %rcx, %rsi
jne 0x227f
movq 0x20(%rbx), %rax
movq (%rax,%rdx,8), %rax
testl %eax, %eax
je 0x218f
movq 0x8(%rbx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
incl %r15d
movl %eax, %eax
shlq $0x4, %rdx
addq %rdx, %rcx
addq $0xc, %rcx
shlq $0x4, %rax
xorl %r13d, %r13d
movq %r8, 0x60(%rsp)
movq %rax, 0x38(%rsp)
movq %rcx, 0x58(%rsp)
cmpl $0x0, (%rcx,%r13)
js 0x2271
movl -0x4(%rcx,%r13), %r14d
shrl %r14d
cmpb $0x0, (%r10,%r14)
jne 0x2271
cmpq 0x28(%rsp), %rbp
jne 0x2265
leaq (,%rbp,2), %rcx
testq %rbp, %rbp
pushq $0x2
popq %rax
cmoveq %rax, %rcx
movq %rcx, 0x28(%rsp)
leaq (,%rcx,8), %rsi
callq 0x1180
movq 0x58(%rsp), %rcx
movq 0x60(%rsp), %r8
movq 0x10(%rsp), %r10
movq %rax, %rdi
movq 0x38(%rsp), %rax
movl %r14d, (%rdi,%rbp,8)
movl %r15d, 0x4(%rdi,%rbp,8)
incq %rbp
addq $0x10, %r13
cmpq %r13, %rax
jne 0x220d
jmp 0x218f
testq %r8, %r8
je 0x22dc
movq %r14, %r15
movq %r8, %rdx
movq %rdi, %r11
movq %r8, %r14
negq %rdx
movq 0x8(%rsp), %rsi
addq $0x8, %rsi
movb $0x1, %dil
pushq $0x1
popq %r8
cmpq %rax, -0x8(%rsi)
jne 0x22ae
cmpq %rcx, (%rsi)
je 0x22c9
cmpq %r14, %r8
setb %dil
leaq (%rdx,%r8), %r9
incq %r9
incq %r8
addq $0x10, %rsi
cmpq $0x1, %r9
jne 0x22a3
testb $0x1, %dil
movq %r11, %rdi
movq %r14, %r8
movq %r15, %r14
jne 0x218f
cmpq 0x48(%rsp), %r8
jne 0x2320
leaq (%r8,%r8), %rsi
testq %r8, %r8
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x48(%rsp)
shlq $0x4, %rsi
movq %rdi, 0x38(%rsp)
movq 0x8(%rsp), %rdi
movq %r8, %r15
callq 0x1180
movq %r15, %r8
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %rcx
jmp 0x232a
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %rax
addq %rcx, %r14
leaq 0x1(%r8), %rdx
shlq $0x4, %r8
movups (%r14), %xmm0
movq %rax, 0x8(%rsp)
movups %xmm0, (%rax,%r8)
movq %rdx, %r8
jmp 0x218f
movq %rdi, %r13
testq %r8, %r8
je 0x238f
movq %r8, %rsi
shlq $0x4, %rsi
movq 0x8(%rsp), %rbp
addq %rbp, %rsi
movq %rbp, %rdi
movq %r8, %r14
callq 0x8372
movq %r14, %r11
movq (%rbp), %rcx
movq 0x8(%rbp), %rax
cmpq $0x1, %r14
movq 0x18(%rsp), %r14
movq 0x50(%rsp), %r15
jne 0x23a4
movq 0x10(%rsp), %r10
jmp 0x239d
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x18(%rsp), %r14
movq 0x50(%rsp), %r15
movq 0x20(%rsp), %rbp
jmp 0x23ef
decq %r11
leaq 0x18(%rbp), %rdx
movq 0x10(%rsp), %r10
movq 0x20(%rsp), %rbp
movq -0x8(%rdx), %rsi
cmpq %rsi, %rcx
movq %rsi, %r8
cmovaq %rcx, %r8
movq (%rdx), %rdi
cmpq %rdi, %rax
movq %rdi, %r9
cmovbq %rax, %r9
incq %r9
cmpq %r8, %r9
jb 0x23e6
cmpq %rcx, %rsi
cmovbq %rsi, %rcx
cmpq %rax, %rdi
cmovaq %rdi, %rax
addq $0x10, %rdx
decq %r11
jne 0x23b5
movq %rcx, %rdx
orq %rax, %rdx
je 0x240d
movq 0x68(%rsp), %rdx
movq %rcx, (%rdx)
movq %rax, 0x8(%rdx)
incq 0x30(%rsp)
jmp 0x24c4
movq 0x18(%rbx), %rax
orl $0x80000000, (%rax,%rbp,4) # imm = 0x80000000
leaq (,%rbp,2), %rax
movb $0x1, %cl
xorl %edx, %edx
orq %rax, %rdx
movq 0x20(%rbx), %rsi
movq (%rsi,%rdx,8), %rsi
movq %rsi, %rdi
andq %r12, %rdi
je 0x24a9
shrq $0x1c, %rsi
andq $-0x10, %rsi
addq 0x8(%rbx), %rsi
xorl %r8d, %r8d
movq %r8, %r9
shlq $0x4, %r9
orb $-0x80, 0xf(%rsi,%r9)
movl 0x8(%rsi,%r9), %r9d
xorq $0x1, %r9
movq 0x20(%rbx), %r10
movq (%r10,%r9,8), %r10
movq %r10, %r9
andq %r12, %r9
je 0x24a1
movq 0x8(%rbx), %r11
shrq $0x20, %r10
shlq $0x4, %r9
shlq $0x4, %r10
addq %r11, %r10
addq $0xc, %r10
xorl %r11d, %r11d
movl -0x4(%r10,%r11), %ebp
xorl %edx, %ebp
cmpl $0x1, %ebp
jne 0x2498
orb $-0x80, 0x3(%r10,%r11)
addq $0x10, %r11
cmpq %r11, %r9
jne 0x2486
incq %r8
cmpq %rdi, %r8
jne 0x2446
pushq $0x1
popq %rdx
testb $0x1, %cl
movl $0x0, %ecx
jne 0x2424
movq 0x10(%rsp), %r10
movq 0x20(%rsp), %rbp
movl 0x14(%rbx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %r10, %rdi
xorl %esi, %esi
callq 0x10d0
movq 0x10(%rsp), %r10
movq %r13, %rdi
movq 0x70(%rsp), %r13
incq %rbp
cmpq %r15, %rbp
jne 0x2131
movq 0xbb01(%rip), %rax      # 0xdff8
movq %rdi, %r12
movq (%rax), %rdi
leaq 0x8379(%rip), %rsi      # 0xa87d
leaq 0x83a4(%rip), %rdx      # 0xa8af
movq %r13, %r8
movq 0x30(%rsp), %r15
subq %r15, %r8
movq %r15, %rcx
xorl %eax, %eax
movq %r10, %r14
callq 0x1120
movq %r14, %rdi
callq 0x1040
movq 0x8(%rsp), %rdi
callq 0x1040
movq %r12, %rdi
callq 0x1040
cmpq %r15, %r13
jne 0x2551
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40c7