// File: /workspace/github_c_makefile_star2_O2/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, 0x2c(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movl 0x14(%rdi), %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
pushq $0x1
popq %rsi
movq %r13, %rdi
callq 0x10f0
movq %rax, %r15
xorl %ecx, %ecx
movq $0x0, 0x38(%rsp)
movq $0x0, 0x10(%rsp)
xorl %eax, %eax
movq $0x0, (%rsp)
movq $0x0, 0x30(%rsp)
xorl %r12d, %r12d
movq %r15, 0x50(%rsp)
movq %r14, 0x18(%rsp)
movq %r13, 0x40(%rsp)
cmpq %r13, %rcx
je 0x71d5
movq %rcx, %rdx
shlq $0x4, %rdx
cmpq $0x0, (%r14,%rdx)
jne 0x7128
addq %r14, %rdx
cmpq $0x0, 0x8(%rdx)
jne 0x7128
cmpq $0x0, (%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x70(%rsp)
jne 0x6ebb
movq %rax, %rdi
pushq $0x10
popq %rsi
callq 0x1180
movq 0x20(%rsp), %rcx
pushq $0x2
popq %rdx
movq %rdx, (%rsp)
movl %ecx, (%rax)
movq %rax, 0x8(%rsp)
andl $0x0, 0x4(%rax)
incq %r12
movq %r12, 0x48(%rsp)
pushq $-0x1
popq %rbp
xorl %r13d, %r13d
pushq $0x1
popq %r14
movq 0x10(%rsp), %rdi
leaq 0x8(%rdi), %r8
movq %rdi, 0x10(%rsp)
movq 0x50(%rsp), %r15
movl 0x2c(%rsp), %eax
movq 0x8(%rsp), %rcx
subq $0x1, %r14
jb 0x706c
movl (%rcx,%r14,8), %edx
movl 0x4(%rcx,%r14,8), %r12d
movb $0x1, (%r15,%rdx)
cmpl %eax, %r12d
jg 0x6ef4
movq %rdx, %r15
shlq $0x4, %r15
movq 0x18(%rsp), %rdi
movq (%rdi,%r15), %rax
movq 0x8(%rdi,%r15), %rcx
movq %rax, %rsi
orq %rcx, %rsi
je 0x6f62
addq %rdi, %r15
movq %r8, %rsi
xorl %edx, %edx
movq 0x10(%rsp), %rdi
cmpq %rdx, %r13
je 0x7026
cmpq %rax, -0x8(%rsi)
jne 0x6f4f
cmpq %rcx, (%rsi)
je 0x6f58
incq %rdx
addq $0x10, %rsi
jmp 0x6f3b
cmpq %r13, %rdx
jb 0x6ee6
jmp 0x7026
movq 0x8(%rbx), %rax
movq 0x20(%rbx), %rcx
movq (%rcx,%rdx,8), %rcx
incl %r12d
movl %ecx, %edx
shlq $0x4, %rdx
shrq $0x1c, %rcx
andq $-0x10, %rcx
leaq (%rax,%rcx), %rsi
addq $0xc, %rsi
xorl %r9d, %r9d
movq 0x8(%rsp), %rdi
movq (%rsp), %rcx
movq %r8, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
cmpq %r9, %rdx
je 0x7018
cmpl $0x0, (%rsi,%r9)
js 0x7012
movl -0x4(%rsi,%r9), %r15d
shrl %r15d
movq 0x50(%rsp), %rax
cmpb $0x0, (%rax,%r15)
jne 0x7012
cmpq %rcx, %r14
jne 0x7006
leaq (%rcx,%rcx), %r10
testq %rcx, %rcx
pushq $0x2
popq %rax
cmoveq %rax, %r10
movq %r10, (%rsp)
leaq (,%r10,8), %rsi
movq %r9, 0x8(%rsp)
callq 0x1180
movq 0x8(%rsp), %r9
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %r8
movq %rax, %rdi
movq (%rsp), %rcx
movl %r15d, (%rdi,%r14,8)
movl %r12d, 0x4(%rdi,%r14,8)
incq %r14
addq $0x10, %r9
jmp 0x6fa2
movq %rcx, (%rsp)
movq %rdi, 0x8(%rsp)
jmp 0x6ee6
cmpq 0x38(%rsp), %r13
jne 0x7050
leaq (,%r13,2), %rsi
testq %r13, %r13
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x38(%rsp)
shlq $0x4, %rsi
callq 0x1180
movq %rax, %rdi
leaq 0x1(%r13), %rax
shlq $0x4, %r13
movups (%r15), %xmm0
movups %xmm0, (%rdi,%r13)
incq %rbp
movq %rax, %r13
jmp 0x6edd
testq %r13, %r13
je 0x70df
shlq $0x4, %r13
movq 0x10(%rsp), %r14
addq %r14, %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x6a4d
movq (%r14), %rcx
movq 0x8(%r14), %rax
leaq 0x18(%r14), %rdx
movq 0x48(%rsp), %r12
movq 0x18(%rsp), %r14
movq 0x40(%rsp), %r13
subq $0x1, %rbp
jb 0x70f2
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 0x70d9
cmpq %rcx, %rsi
cmovbq %rsi, %rcx
cmpq %rax, %rdi
cmovaq %rdi, %rax
addq $0x10, %rdx
jmp 0x70a2
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x48(%rsp), %r12
movq 0x18(%rsp), %r14
movq 0x40(%rsp), %r13
movq %rcx, %rdx
orq %rax, %rdx
movq 0x70(%rsp), %rdx
je 0x7130
movq %rcx, (%rdx)
movq %rax, 0x8(%rdx)
incq 0x30(%rsp)
movl 0x14(%rbx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %r15, %rdi
xorl %esi, %esi
callq 0x10d0
movq 0x8(%rsp), %rax
movq 0x20(%rsp), %rcx
incq %rcx
jmp 0x6e6a
movq 0x18(%rbx), %rax
movq 0x20(%rsp), %rcx
orl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
leaq (%rcx,%rcx), %rax
xorl %ecx, %ecx
cmpq $0x2, %rcx
je 0x710b
movq %rcx, %rdx
orq %rax, %rdx
movq 0x20(%rbx), %rsi
movq (%rsi,%rdx,8), %rdi
movl %edi, %esi
shrq $0x1c, %rdi
andq $-0x10, %rdi
addq 0x8(%rbx), %rdi
xorl %r8d, %r8d
cmpq %rsi, %r8
je 0x71cd
movq %r8, %r9
shlq $0x4, %r9
orb $-0x80, 0xf(%rdi,%r9)
movl 0x8(%rdi,%r9), %r9d
xorq $0x1, %r9
movq 0x8(%rbx), %r10
movq 0x20(%rbx), %r11
movq (%r11,%r9,8), %r11
movl %r11d, %r9d
shrq $0x1c, %r11
andq $-0x10, %r11
addq %r11, %r10
addq $0xc, %r10
shlq $0x4, %r9
xorl %r11d, %r11d
cmpq %r11, %r9
je 0x71c8
movl -0x4(%r10,%r11), %ebp
xorl %edx, %ebp
cmpl $0x1, %ebp
jne 0x71c2
orb $-0x80, 0x3(%r10,%r11)
addq $0x10, %r11
jmp 0x71ab
incq %r8
jmp 0x716b
incq %rcx
jmp 0x7146
movq 0x6e1c(%rip), %rcx      # 0xdff8
movq (%rcx), %rdi
leaq 0x2697(%rip), %rsi      # 0x987d
leaq 0x26c2(%rip), %rdx      # 0x98af
movq %r12, %r8
movq 0x30(%rsp), %r14
subq %r14, %r8
movq %rax, %r13
movq %r14, %rcx
xorl %eax, %eax
callq 0x1120
movq %r15, %rdi
callq 0x1040
movq 0x10(%rsp), %rdi
callq 0x1040
movq %r13, %rdi
callq 0x1040
cmpq %r14, %r12
jne 0x7233
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 0x2447
nopl (%rax)