// File: /workspace/github_c_makefile_star2_O1/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), %r12d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0x10f0
movq %rax, %r15
movq $0x0, 0x8(%rsp)
movl $0x0, %r10d
movl $0x0, %eax
movq %rax, 0x20(%rsp)
movl $0x0, %eax
movq %rax, 0x28(%rsp)
testq %r12, %r12
je 0x25ad
movl %r12d, %eax
xorl %ebp, %ebp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
xorl %ecx, %ecx
xorl %r10d, %r10d
movq $0x0, 0x8(%rsp)
movq $0x0, 0x48(%rsp)
movq %r15, 0x38(%rsp)
movq %r14, 0x30(%rsp)
movq %rax, 0x68(%rsp)
movq %rbp, %rdx
shlq $0x4, %rdx
cmpq $0x0, (%r14,%rdx)
jne 0x25a1
addq %r14, %rdx
cmpq $0x0, 0x8(%rdx)
jne 0x25a1
testq %rcx, %rcx
movq %rdx, 0x70(%rsp)
je 0x2236
movq %rcx, 0x10(%rsp)
jmp 0x224c
movq %r10, %rdi
pushq $0x10
popq %rsi
callq 0x1180
movq %rax, %r10
pushq $0x2
popq %rax
movq %rax, 0x10(%rsp)
movq %rbp, 0x18(%rsp)
movl %ebp, (%r10)
andl $0x0, 0x4(%r10)
incq 0x28(%rsp)
xorl %r14d, %r14d
pushq $0x1
popq %rbp
movl 0x44(%rsp), %eax
subq $0x1, %rbp
jb 0x2420
movl (%r10,%rbp,8), %ecx
movl 0x4(%r10,%rbp,8), %r13d
movb $0x1, (%r15,%rcx)
cmpl %eax, %r13d
jg 0x2268
movq %rcx, %rax
shlq $0x4, %rax
movq 0x30(%rsp), %rdx
leaq (%rdx,%rax), %r11
movq (%rdx,%rax), %rax
testq %rax, %rax
jne 0x22a9
cmpq $0x0, 0x8(%r11)
je 0x235e
testq %r14, %r14
setne %cl
je 0x22ed
movq 0x8(%r11), %rdx
movq %r14, %rsi
negq %rsi
movq 0x8(%rsp), %rdi
addq $0x8, %rdi
pushq $0x1
popq %r8
cmpq %rax, -0x8(%rdi)
jne 0x22d3
cmpq %rdx, (%rdi)
je 0x22ed
cmpq %r14, %r8
setb %cl
leaq (%rsi,%r8), %r9
incq %r9
incq %r8
addq $0x10, %rdi
cmpq $0x1, %r9
jne 0x22c8
testb $0x1, %cl
jne 0x2264
movq 0x48(%rsp), %rax
cmpq %rax, %r14
jne 0x233b
leaq (%rax,%rax), %r15
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r15
movq %r15, %rsi
shlq $0x4, %rsi
movq 0x8(%rsp), %rdi
movq %r10, 0x8(%rsp)
movq %r11, %r13
callq 0x1180
movq %r13, %r11
movq 0x8(%rsp), %r10
movq %r15, 0x48(%rsp)
movq 0x38(%rsp), %r15
jmp 0x2340
movq 0x8(%rsp), %rax
leaq 0x1(%r14), %rcx
shlq $0x4, %r14
movups (%r11), %xmm0
movq %rax, 0x8(%rsp)
movups %xmm0, (%rax,%r14)
movq %rcx, %r14
jmp 0x2264
movq 0x20(%rbx), %rax
movq (%rax,%rcx,8), %rax
testl %eax, %eax
je 0x2264
movq 0x8(%rbx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
incl %r13d
movl %eax, %esi
shlq $0x4, %rdx
addq %rcx, %rdx
addq $0xc, %rdx
shlq $0x4, %rsi
xorl %r15d, %r15d
movq 0x10(%rsp), %rcx
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
cmpl $0x0, (%rdx,%r15)
js 0x2408
movl -0x4(%rdx,%r15), %edi
shrl %edi
movq 0x38(%rsp), %rax
cmpb $0x0, (%rax,%rdi)
jne 0x2408
cmpq %rcx, %rbp
jne 0x23fc
leaq (%rcx,%rcx), %r8
testq %rcx, %rcx
pushq $0x2
popq %rax
cmoveq %rax, %r8
movq %r8, 0x60(%rsp)
leaq (,%r8,8), %rsi
movq %rdi, 0x10(%rsp)
movq %r10, %rdi
callq 0x1180
movq 0x10(%rsp), %rdi
movq 0x50(%rsp), %rdx
movq 0x58(%rsp), %rsi
movq %rax, %r10
movq 0x60(%rsp), %rcx
movl %edi, (%r10,%rbp,8)
movl %r13d, 0x4(%r10,%rbp,8)
incq %rbp
addq $0x10, %r15
cmpq %r15, %rsi
jne 0x239f
movq %rcx, 0x10(%rsp)
movq 0x38(%rsp), %r15
jmp 0x2264
testq %r14, %r14
je 0x2452
movq %r10, %r13
movq %r14, %rsi
shlq $0x4, %rsi
movq 0x8(%rsp), %rbp
addq %rbp, %rsi
movq %rbp, %rdi
callq 0x8486
movq (%rbp), %rcx
movq 0x8(%rbp), %rax
cmpq $0x1, %r14
jne 0x245d
movq %r13, %r10
jmp 0x2456
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x18(%rsp), %rbp
jmp 0x24a6
decq %r14
leaq 0x18(%rbp), %rdx
movq %r13, %r10
movq 0x18(%rsp), %rbp
movq -0x8(%rdx), %rsi
movq (%rdx), %rdi
cmpq %rsi, %rcx
movq %rsi, %r8
cmovaq %rcx, %r8
cmpq %rdi, %rax
cmovbq %rax, %rdi
incq %rdi
cmpq %r8, %rdi
jb 0x249d
cmpq %rcx, %rsi
cmovbq %rsi, %rcx
movq (%rdx), %rsi
cmpq %rax, %rsi
cmovaq %rsi, %rax
addq $0x10, %rdx
decq %r14
jne 0x246c
movq %r10, %r13
movq %rcx, %rdx
orq %rax, %rdx
je 0x24cc
movq 0x70(%rsp), %rdx
movq %rcx, (%rdx)
movq %rax, 0x8(%rdx)
incq 0x20(%rsp)
movq 0x30(%rsp), %r14
jmp 0x2581
movq 0x18(%rbx), %rax
orl $0x80000000, (%rax,%rbp,4) # imm = 0x80000000
leaq (,%rbp,2), %rax
xorl %ecx, %ecx
movq 0x30(%rsp), %r14
leaq (%rcx,%rax), %rdx
movq 0x20(%rbx), %rsi
movq (%rsi,%rdx,8), %rsi
movq %rsi, %rdi
andq %r12, %rdi
je 0x256c
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 0x2564
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 0x255b
orb $-0x80, 0x3(%r10,%r11)
addq $0x10, %r11
cmpq %r11, %r9
jne 0x2549
incq %r8
cmpq %rdi, %r8
jne 0x2509
leaq 0x1(%rcx), %rdx
testq %rcx, %rcx
movq %rdx, %rcx
je 0x24e6
movq 0x18(%rsp), %rbp
movl 0x14(%rbx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %r15, %rdi
xorl %esi, %esi
callq 0x10d0
movq %r13, %r10
movq 0x68(%rsp), %rax
movq 0x10(%rsp), %rcx
incq %rbp
cmpq %rax, %rbp
jne 0x2205
movq 0xca44(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x82ef(%rip), %rsi      # 0xa8ad
leaq 0x831a(%rip), %rdx      # 0xa8df
movq 0x28(%rsp), %r13
movq %r13, %r8
movq 0x20(%rsp), %r14
subq %r14, %r8
movq %r14, %rcx
xorl %eax, %eax
movq %r10, %r12
callq 0x1120
movq %r15, %rdi
callq 0x1040
movq 0x8(%rsp), %rdi
callq 0x1040
movq %r12, %rdi
callq 0x1040
cmpq %r14, %r13
jne 0x2610
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 0x41c9