// File: /workspace/github_c_makefile_star2_O1/lh3[P]minigraph/shortk.c
// Function: mg_shortest_k
mg_pathv_t *mg_shortest_k(void *km0, const gfa_t *g, uint32_t src, int32_t n_dst, mg_path_dst_t *dst, int32_t max_dist, int32_t max_k, int32_t *n_pathv)
{
	sp_node_t *p, *root = 0, **out;
	sp_topk_t *q;
	kh_sp_t *h;
	kh_sp2_t *h2;
	void *km;
	khint_t k;
	int absent;
	int32_t i, j, n_done, n_found;
	uint32_t id, n_out, m_out;
	int8_t *dst_done;
	mg_pathv_t *ret = 0;
	uint64_t *dst_group, *seeds = 0;
	void *h_seeds = 0;
	mg128_v mini = {0,0,0};

	if (n_pathv) *n_pathv = 0;
	if (n_dst <= 0) return 0;
	for (i = 0; i < n_dst; ++i) { // initialize
		mg_path_dst_t *t = &dst[i];
		if (t->inner)
			t->dist = 0, t->n_path = 1, t->path_end = -1;
		else
			t->dist = -1, t->n_path = 0, t->path_end = -1;
	}
	if (max_k > MG_MAX_SHORT_K) max_k = MG_MAX_SHORT_K;
	km = (mg_dbg_flag&MG_DBG_NO_KALLOC) && (mg_dbg_flag&MG_DBG_SHORTK)? 0 : km_init2(km0, 0x4000);

	KCALLOC(km, dst_done, n_dst);
	KMALLOC(km, dst_group, n_dst);
	for (i = 0; i < n_dst; ++i) // multiple dst[] may have the same dst[].v. We need to group them first.
		dst_group[i] = (uint64_t)dst[i].v<<32 | i;
	radix_sort_gfa64(dst_group, dst_group + n_dst);

	h2 = sp2_init2(km); // this hash table keeps all destinations
	sp2_resize(h2, n_dst * 2);
	for (i = 1, j = 0; i <= n_dst; ++i) {
		if (i == n_dst || dst_group[i]>>32 != dst_group[j]>>32) {
			k = sp2_put(h2, dst_group[j]>>32, &absent);
			kh_val(h2, k) = (uint64_t)j << 32 | (i - j);
			assert(absent);
			j = i;
		}
	}

	h = sp_init2(km); // this hash table keeps visited vertices
	sp_resize(h, 16);
	m_out = 16, n_out = 0;
	KMALLOC(km, out, m_out);

	id = 0;
	p = gen_sp_node(km, g, src, 0, id++);
	p->hash = kh_hash_uint32(src);
	kavl_insert(sp, &root, p, 0);
	k = sp_put(h, src, &absent);
	q = &kh_val(h, k);
	q->k = 1, q->p[0] = p, q->qs = q->qe = -1;

	n_done = 0;
	while (kavl_size(head, root) > 0) {
		int32_t i, nv;
		gfa_arc_t *av;
		sp_node_t *r;

		r = kavl_erase_first(sp, &root); // take out the closest vertex in the heap (as a binary tree)
		//fprintf(stderr, "XX\t%d\t%d\t%d\t%c%s[%d]\t%d\n", n_out, kavl_size(head, root), n_finished, "><"[(r->v&1)^1], g->seg[r->v>>1].name, r->v, (int32_t)(r->di>>32));
		if (n_out == m_out) KEXPAND(km, out, m_out);
		r->di = r->di>>32<<32 | n_out; // lower 32 bits now for position in the out[] array
		out[n_out++] = r;

		k = sp2_get(h2, r->v);
		if (k != kh_end(h2)) { // we have reached one dst vertex
			int32_t j, dist = r->di>>32, off = kh_val(h2, k) >> 32, cnt = (int32_t)kh_val(h2, k);
			for (j = 0; j < cnt; ++j) {
				mg_path_dst_t *t = &dst[(int32_t)dst_group[off + j]];
				int32_t done = 0;
				if (t->inner) {
					done = 1;
				} else {
					int32_t copy = 0;
					//if (mg_dbg_flag & MG_DBG_GC1) fprintf(stderr, "  src=%c%s[%d],qlen=%d\tdst=%c%s[%d]\ttarget_distx=%d,target_hash=%x\tdistx=%d,hash=%x\n", "><"[src&1], g->seg[src>>1].name, src, ql, "><"[t->v&1], g->seg[t->v>>1].name, t->v, t->target_dist - g->seg[src>>1].len, t->target_hash, dist - g->seg[src>>1].len, r->hash);
					if (t->n_path == 0) { // keep the shortest path
						copy = 1;
					} else if (t->target_dist >= 0) { // we have a target distance; choose the closest
						if (dist == t->target_dist && t->check_hash && r->hash == t->target_hash) { // we found the target path
							copy = 1, done = 1;
						} else {
							int32_t d0 = t->dist, d1 = dist;
							d0 = d0 > t->target_dist? d0 - t->target_dist : t->target_dist - d0;
							d1 = d1 > t->target_dist? d1 - t->target_dist : t->target_dist - d1;
							if (d1 < d0) copy = 1;
						}
					}
					if (copy) {
						t->path_end = n_out - 1, t->dist = dist, t->hash = r->hash, t->is_0 = r->is_0;
						if (t->target_dist >= 0) {
							if (dist == t->target_dist && t->check_hash && r->hash == t->target_hash) done = 1;
							else if (dist > t->target_dist + MG_SHORT_K_EXT) done = 1;
						}
					}
					++t->n_path;
					if (t->n_path >= max_k) done = 1;
				}
				if (dst_done[off + j] == 0 && done)
					dst_done[off + j] = 1, ++n_done;
			}
			if (n_done == n_dst) break;
		}

		nv = gfa_arc_n(g, r->v);
		av = gfa_arc_a(g, r->v);
		for (i = 0; i < nv; ++i) { // visit all neighbors
			gfa_arc_t *ai = &av[i];
			int32_t d = (r->di>>32) + (uint32_t)ai->v_lv;
			if (d > max_dist) continue; // don't probe vertices too far away
			k = sp_put(h, ai->w, &absent);
			q = &kh_val(h, k);
			if (absent) { // a new vertex visited
				q->k = 0, q->qs = q->qe = -1;
				//if (ql && qs) fprintf(stderr, "ql=%d,src=%d\tv=%c%s[%d]\n", ql, src, "><"[ai->w&1], g->seg[ai->w>>1].name, ai->w);
			}
			if (q->k < max_k) { // enough room: add to the heap
				p = gen_sp_node(km, g, ai->w, d, id++);
				p->pre = n_out - 1;
				p->hash = r->hash + kh_hash_uint32(ai->w);
				p->is_0 = r->is_0;
				if (ai->rank > 0) p->is_0 = 0;
				kavl_insert(sp, &root, p, 0);
				q->p[q->k++] = p;
				ks_heapup_sp(q->k, q->p);
			} else if (q->p[0]->di>>32 > d) { // shorter than the longest path so far: replace the longest
				p = kavl_erase(sp, &root, q->p[0], 0);
				if (p) {
					p->di = (uint64_t)d<<32 | (id++);
					p->pre = n_out - 1;
					p->hash = r->hash + kh_hash_uint32(ai->w);
					p->is_0 = r->is_0;
					if (ai->rank > 0) p->is_0 = 0;
					kavl_insert(sp, &root, p, 0);
					ks_heapdown_sp(0, q->k, q->p);
				} else {
					fprintf(stderr, "Warning: logical bug in gfa_shortest_k(): q->k=%d,q->p[0]->{d,i}={%d,%d},d=%d,src=%u,max_dist=%d,n_dst=%d\n", q->k, (int32_t)(q->p[0]->di>>32), (int32_t)q->p[0]->di, d, src, max_dist, n_dst);
					km_destroy(km);
					return 0;
				}
			} // else: the path is longer than all the existing paths ended at ai->w
		}
	}

	kfree(km, dst_group);
	kfree(km, dst_done);
	sp_destroy(h);
	mg_idx_hfree(h_seeds);
	kfree(km, seeds);
	kfree(km, mini.a);
	// NB: AVL nodes are not deallocated. When km==0, they are memory leaks.

	for (i = 0, n_found = 0; i < n_dst; ++i)
		if (dst[i].n_path > 0) ++n_found;

	if (n_found > 0 && n_pathv) { // then generate the backtrack array
		int32_t n, *trans;
		KCALLOC(km, trans, n_out); // used to squeeze unused elements in out[]
		for (i = 0; i < n_dst; ++i) { // mark dst vertices with a target distance
			mg_path_dst_t *t = &dst[i];
			if (t->n_path > 0 && t->target_dist >= 0 && t->path_end >= 0)
				trans[(int32_t)out[t->path_end]->di] = 1;
		}
		for (i = 0; i < n_out; ++i) { // mark dst vertices without a target distance
			k = sp2_get(h2, out[i]->v);
			if (k != kh_end(h2)) { // TODO: check if this is correct!
				int32_t off = kh_val(h2, k)>>32, cnt = (int32_t)kh_val(h2, k);
				for (j = off; j < off + cnt; ++j)
					if (dst[j].target_dist < 0)
						trans[i] = 1;
			}
		}
		for (i = n_out - 1; i >= 0; --i) // mark all predecessors
			if (trans[i] && out[i]->pre >= 0)
				trans[out[i]->pre] = 1;
		for (i = n = 0; i < n_out; ++i) // generate coordinate translations
			if (trans[i]) trans[i] = n++;
			else trans[i] = -1;

		*n_pathv = n;
		KMALLOC(km0, ret, n);
		for (i = 0; i < n_out; ++i) { // generate the backtrack array
			mg_pathv_t *p;
			if (trans[i] < 0) continue;
			p = &ret[trans[i]];
			p->v = out[i]->v, p->d = out[i]->di >> 32;
			p->pre = out[i]->pre < 0? out[i]->pre : trans[out[i]->pre];
		}
		for (i = 0; i < n_dst; ++i) // translate "path_end"
			if (dst[i].path_end >= 0)
				dst[i].path_end = trans[dst[i].path_end];
	}

	km_destroy(km);
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r9, 0x90(%rsp)
movq %r8, %rbx
movq %rdx, 0x78(%rsp)
movq %rsi, %r15
movq 0xe8(%rsp), %rax
movq $0x0, 0x60(%rsp)
testq %rax, %rax
je 0x10c2b
movl $0x0, (%rax)
testl %ecx, %ecx
jle 0x1163f
movl 0xe0(%rsp), %eax
movq %rcx, 0x38(%rsp)
movl %ecx, %ecx
movq %rcx, 0x8(%rsp)
leaq (,%rcx,4), %rcx
leaq (%rcx,%rcx,8), %rcx
xorl %edx, %edx
movl $0x80000000, %esi       # imm = 0x80000000
cmpl $0x0, 0xc(%rbx,%rdx)
js 0x10c72
movl $0xffffffff, 0x1c(%rbx,%rdx) # imm = 0xFFFFFFFF
movl 0x14(%rbx,%rdx), %r8d
andl %esi, %r8d
jmp 0x10c85
movl $0x0, 0x1c(%rbx,%rdx)
movl 0x14(%rbx,%rdx), %r8d
andl %esi, %r8d
incl %r8d
movl %r8d, 0x14(%rbx,%rdx)
movl $0xffffffff, 0x18(%rbx,%rdx) # imm = 0xFFFFFFFF
addq $0x24, %rdx
cmpq %rdx, %rcx
jne 0x10c59
cmpl $0xf, %eax
movl $0xf, %ecx
cmovll %eax, %ecx
movl %ecx, 0x30(%rsp)
leaq 0x219c7(%rip), %rax     # 0x32678
movl (%rax), %eax
notl %eax
testb $0x21, %al
movq %rdi, 0x98(%rsp)
jne 0x10cc6
xorl %r14d, %r14d
jmp 0x10cd3
movl $0x4000, %esi           # imm = 0x4000
callq 0x300c
movq %rax, %r14
movl $0x1, %edx
movq %r14, %rdi
movq 0x8(%rsp), %r12
movq %r12, %rsi
callq 0x3054
movq %rax, 0x80(%rsp)
leaq (,%r12,8), %rsi
movq %r14, 0x18(%rsp)
movq %r14, %rdi
callq 0x31c1
movq 0x38(%rsp), %rcx
cmpl $0x2, %ecx
movl $0x1, %edi
cmovgel %ecx, %edi
xorl %ecx, %ecx
movq %rbx, 0x48(%rsp)
movl (%rbx), %esi
shlq $0x20, %rsi
addq %rcx, %rsi
movq %rsi, (%rax,%rcx,8)
incq %rcx
addq $0x24, %rbx
cmpq %rcx, %rdi
jne 0x10d1c
movq %r15, 0xa0(%rsp)
movq 0x8(%rsp), %r15
leaq (%rax,%r15,8), %rsi
movq %rax, 0x70(%rsp)
movq %rax, %rdi
callq 0x48ff
movl $0x1, %ebx
movl $0x1, %esi
movl $0x20, %edx
movq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x3054
movq %r14, 0x18(%rax)
movq 0x38(%rsp), %r12
leal (%r12,%r12), %esi
movq %rax, 0x20(%rsp)
movq %rax, %rdi
callq 0x11b87
movl 0x34(%rsp), %eax
cmpl $0x2, %r12d
movl $0x1, %r14d
cmovgel %r12d, %r14d
incl %r14d
xorl %ecx, %ecx
movslq %ecx, %r12
cmpq %r15, %rbx
je 0x10dbf
movq 0x70(%rsp), %rsi
movq (%rsi,%r12,8), %rdx
xorq (%rsi,%rbx,8), %rdx
shrq $0x20, %rdx
je 0x10ef7
movq 0x20(%rsp), %rdi
cmpq $0x0, 0x10(%rdi)
je 0x10dd6
movb (%rdi), %cl
movl $0x1, %ebp
shll %cl, %ebp
jmp 0x10dd8
xorl %ebp, %ebp
movq 0x70(%rsp), %rax
movl 0x4(%rax,%r12,8), %r13d
movl %ebp, %eax
shrl %eax
movl %ebp, %ecx
shrl $0x2, %ecx
addl %eax, %ecx
cmpl %ecx, 0x4(%rdi)
jb 0x10e17
leal 0x1(%rbp), %esi
movq %rdi, %r15
callq 0x11b87
testl %eax, %eax
js 0x10ebd
movb (%r15), %cl
movl $0x1, %ebp
shll %cl, %ebp
movq %r15, %rdi
movq 0x8(%rsp), %r15
movl %r13d, %eax
shll $0xf, %eax
notl %eax
addl %r13d, %eax
movl %eax, %ecx
shrl $0xa, %ecx
xorl %eax, %ecx
leal (%rcx,%rcx,8), %eax
movl %eax, %ecx
shrl $0x6, %ecx
xorl %eax, %ecx
movl %ecx, %eax
shll $0xb, %eax
notl %eax
addl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
xorl %eax, %ecx
imull $0x9e3779b9, %ecx, %edx # imm = 0x9E3779B9
movb (%rdi), %al
xorl %ecx, %ecx
subb %al, %cl
shrl %cl, %edx
movl %ebp, %ecx
decl %ecx
movq 0x8(%rdi), %rax
movl %edx, %ebp
movl %ebp, %esi
shrl $0x5, %esi
movl (%rax,%rsi,4), %esi
btl %ebp, %esi
jae 0x10e81
movq 0x10(%rdi), %rsi
movl %ebp, %r8d
leaq (%r8,%r8,2), %r8
cmpl %r13d, (%rsi,%r8,4)
je 0x10e81
incl %ebp
andl %ecx, %ebp
cmpl %edx, %ebp
jne 0x10e5b
movl %ebp, %edx
shrl $0x5, %edx
movl (%rax,%rdx,4), %r8d
movl $0x1, %esi
movl %ebp, %ecx
shll %cl, %esi
btl %ebp, %r8d
jae 0x10e9f
xorl %eax, %eax
movb $0x1, %cl
jmp 0x10ecc
movq 0x10(%rdi), %rcx
movl %ebp, %r8d
leaq (%r8,%r8,2), %r8
movl %r13d, (%rcx,%r8,4)
orl %esi, (%rax,%rdx,4)
incl 0x4(%rdi)
movl $0x1, %eax
xorl %ecx, %ecx
jmp 0x10ecc
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movq %r15, %rdi
movq 0x8(%rsp), %r15
movq %r12, %rdx
shlq $0x20, %rdx
movl %ebx, %esi
subl %r12d, %esi
movslq %esi, %rsi
orq %rdx, %rsi
movq 0x10(%rdi), %rdx
movl %ebp, %edi
leaq (%rdi,%rdi,2), %rdi
movq %rsi, 0x4(%rdx,%rdi,4)
testb %cl, %cl
jne 0x119d8
movl %ebx, %ecx
incq %rbx
cmpq %r14, %rbx
jne 0x10da0
leaq 0x34(%rsp), %r13
movl %eax, (%r13)
movl $0x1, %esi
movl $0x20, %edx
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x3054
movq %rax, %r12
movq %rbx, 0x18(%rax)
movq %rax, %rdi
movl $0x10, %esi
callq 0x11df1
movl $0x80, %esi
movq %rbx, %rdi
callq 0x31c1
movq %rax, 0x40(%rsp)
movl $0x30, %esi
movq %rbx, %rdi
callq 0x31c1
movq %rax, %r14
movq 0x78(%rsp), %r15
movl %r15d, 0x8(%rax)
movq $0x0, (%rax)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, 0xc(%rax)
movl $0x1, 0x14(%rax)
movl %r15d, %eax
shll $0xf, %eax
xorl %ebx, %eax
addl %r15d, %eax
movl %eax, %ecx
shrl $0xa, %ecx
xorl %eax, %ecx
leal (%rcx,%rcx,8), %eax
movl %eax, %ecx
shrl $0x6, %ecx
xorl %eax, %ecx
movl %ecx, %eax
shll $0xb, %eax
xorl %ebx, %eax
addl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
xorl %eax, %ecx
movl %ecx, 0x10(%r14)
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x101ea
movq %r12, %rdi
movl %r15d, %esi
movq %r13, %rdx
callq 0x119fb
movq %r12, 0x88(%rsp)
movq 0x10(%r12), %rcx
movl %eax, %eax
imulq $0x8c, %rax, %rax
movabsq $-0xffffffff, %rdx      # imm = 0xFFFFFFFF00000001
movq %rdx, 0x4(%rcx,%rax)
movq %r14, 0x14(%rcx,%rax)
movl %ebx, 0xc(%rcx,%rax)
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl $0x10, 0x68(%rsp)
xorl %r13d, %r13d
movl $0x1, %ecx
movl $0x0, 0x6c(%rsp)
movl 0x30(%rsp), %r14d
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0x11647
cmpl $0x0, 0x2c(%rax)
je 0x11647
movl %ecx, 0x14(%rsp)
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x104bb
movq %rax, 0x8(%rsp)
movl 0x68(%rsp), %eax
cmpl %eax, %r13d
movq 0x48(%rsp), %r15
jne 0x11085
movl %eax, %ebx
shrl %ebx
addl %eax, %ebx
cmpl $0x4, %eax
movl $0x10, %eax
cmovbl %eax, %ebx
leaq (,%rbx,8), %rdx
movq 0x18(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x32c4
movl %ebx, 0x68(%rsp)
movq 0x20(%rsp), %r11
jmp 0x1108f
movq 0x20(%rsp), %r11
movq 0x40(%rsp), %rax
movq 0x8(%rsp), %rdx
movq (%rdx), %r12
movl %r13d, %ecx
movl %r13d, (%rdx)
movq %rax, 0x40(%rsp)
movq %rdx, (%rax,%rcx,8)
movq 0x10(%r11), %rdx
xorl %esi, %esi
movl $0x0, %edi
testq %rdx, %rdx
je 0x11151
movq 0x8(%rsp), %rax
movl 0x8(%rax), %r8d
movb (%r11), %cl
movl $0x1, %edi
shll %cl, %edi
movl %r8d, %r9d
shll $0xf, %r9d
notl %r9d
addl %r8d, %r9d
movl %r9d, %r10d
shrl $0xa, %r10d
xorl %r9d, %r10d
leal (%r10,%r10,8), %r9d
movl %r9d, %r10d
shrl $0x6, %r10d
xorl %r9d, %r10d
movl %r10d, %r9d
shll $0xb, %r9d
notl %r9d
addl %r10d, %r9d
movl %r9d, %r10d
shrl $0x10, %r10d
xorl %r9d, %r10d
imull $0x9e3779b9, %r10d, %r9d # imm = 0x9E3779B9
negb %cl
shrl %cl, %r9d
leal -0x1(%rdi), %ecx
movq 0x8(%r11), %r11
movl %r9d, %r10d
movl %r10d, %ebx
shrl $0x5, %ebx
movl (%r11,%rbx,4), %ebx
btl %r10d, %ebx
jae 0x1114c
movl %r10d, %ebx
leaq (%rbx,%rbx,2), %rbx
cmpl %r8d, (%rdx,%rbx,4)
je 0x11149
incl %r10d
andl %ecx, %r10d
cmpl %r9d, %r10d
jne 0x1111f
jmp 0x1114c
movl %r10d, %edi
movq 0x20(%rsp), %r11
testq %rdx, %rdx
je 0x11160
movb (%r11), %cl
movl $0x1, %esi
shll %cl, %esi
cmpl %esi, %edi
je 0x112f7
movl %edi, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x4(%rdx,%rcx,4), %rcx
testl %ecx, %ecx
jle 0x112dc
shrq $0x20, %r12
movq %rcx, %rdx
sarq $0x20, %rdx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq 0x70(%rsp), %rax
leaq (%rax,%rdx,8), %rsi
addq 0x80(%rsp), %rdx
xorl %edi, %edi
movslq (%rsi,%rdi,8), %r8
leaq (%r8,%r8,8), %r8
movl 0xc(%r15,%r8,4), %r10d
testl %r10d, %r10d
js 0x111ef
leaq (%r15,%r8,4), %r8
xorl %r9d, %r9d
movl 0x14(%r8), %r11d
andl %ebp, %r11d
je 0x111f7
movl 0x4(%r8), %ebx
testl %ebx, %ebx
js 0x11227
cmpl $0x40000000, %r10d      # imm = 0x40000000
jb 0x111fb
cmpl %r12d, %ebx
jne 0x111fb
movq 0x8(%rsp), %rax
movl 0x10(%rax), %ebp
cmpl 0x8(%r8), %ebp
jne 0x111fb
movl $0x1, %r9d
xorl %ebx, %ebx
jmp 0x11220
movb $0x1, %r8b
jmp 0x112bd
xorl %ebx, %ebx
jmp 0x11229
movl 0x1c(%r8), %ebp
subl %ebx, %ebp
movl %ebp, %r14d
negl %r14d
cmovsl %ebp, %r14d
subl %r12d, %ebx
movl %ebx, %ebp
negl %ebp
cmovsl %ebx, %ebp
cmpl %r14d, %ebp
movl 0x30(%rsp), %r14d
setae %bl
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
jmp 0x11229
movb $0x1, %bl
testb %bl, %bl
jne 0x1128c
movl %r13d, 0x18(%r8)
movl %r12d, 0x1c(%r8)
movq 0x8(%rsp), %rax
movl 0x10(%rax), %ebx
movl %ebx, 0x20(%r8)
movl 0x14(%rax), %ebx
shll $0x1f, %ebx
orl %r11d, %ebx
movl %ebx, 0x14(%r8)
movl 0x4(%r8), %r11d
testl %r11d, %r11d
js 0x1128c
cmpl $0x40000000, %r10d      # imm = 0x40000000
jb 0x11279
cmpl %r12d, %r11d
jne 0x11279
movq 0x8(%rsp), %rax
movl 0x10(%rax), %ebx
movl $0x1, %r10d
cmpl 0x8(%r8), %ebx
je 0x1128f
addl $0x3e8, %r11d           # imm = 0x3E8
cmpl %r12d, %r11d
movl $0x1, %eax
cmovll %eax, %r9d
movl %r9d, %r10d
movl 0x14(%r8), %r9d
leal 0x1(%r9), %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
andl $0x80000000, %r9d       # imm = 0x80000000
orl %r11d, %r9d
movl %r9d, 0x14(%r8)
cmpl %r14d, %r11d
setge %r9b
testl %r10d, %r10d
setne %r8b
orb %r9b, %r8b
testb %r8b, %r8b
je 0x112d0
cmpb $0x0, (%rdx,%rdi)
jne 0x112d0
movb $0x1, (%rdx,%rdi)
incl 0x6c(%rsp)
incq %rdi
cmpq %rdi, %rcx
jne 0x1119f
movl $0x0, %esi
movl 0x6c(%rsp), %eax
cmpl 0x38(%rsp), %eax
movl $0xc, %eax
cmovel %eax, %esi
je 0x11626
movq 0xa0(%rsp), %rdx
movq 0x58(%rdx), %rax
movq 0x8(%rsp), %rcx
movl 0x8(%rcx), %ecx
movq (%rax,%rcx,8), %r8
xorl %esi, %esi
testl %r8d, %r8d
jle 0x11626
movl %r13d, 0x2c(%rsp)
movq %r8, %r9
shrq $0x1b, %r9
andq $-0x20, %r9
addq 0x48(%rdx), %r9
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
xorl %ebp, %ebp
movq %r8, 0x58(%rsp)
movq %r9, 0x50(%rsp)
movq %rbp, %r13
shlq $0x5, %r13
movq 0x8(%rsp), %rax
movl 0x4(%rax), %r12d
addq (%r9,%r13), %r12
movl $0x14, %r15d
cmpl 0x90(%rsp), %r12d
jg 0x11598
addq %r9, %r13
movl 0x8(%r13), %esi
movq 0x88(%rsp), %rbx
movq %rbx, %rdi
leaq 0x34(%rsp), %rdx
callq 0x119fb
movq 0x10(%rbx), %rcx
movl %eax, %eax
imulq $0x8c, %rax, %rax
leaq (%rcx,%rax), %rbx
addq $0x4, %rbx
cmpl $0x0, 0x34(%rsp)
je 0x113b5
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, (%rbx)
movl $0xffffffff, 0x8(%rbx)  # imm = 0xFFFFFFFF
cmpl %r14d, (%rbx)
jge 0x114a9
movl 0x8(%r13), %r15d
movl $0x30, %esi
movq 0x18(%rsp), %rdi
callq 0x31c1
movq %rax, %r14
movl %r15d, 0x8(%rax)
shlq $0x20, %r12
movl 0x14(%rsp), %r15d
movslq %r15d, %rax
orq %r12, %rax
movq %rax, (%r14)
movl $0x1, 0x14(%r14)
movl 0x2c(%rsp), %eax
movl %eax, 0xc(%r14)
movl 0x8(%r13), %eax
movl %eax, %ecx
shll $0xf, %ecx
notl %ecx
addl %eax, %ecx
movl %ecx, %eax
shrl $0xa, %eax
xorl %ecx, %eax
leal (%rax,%rax,8), %eax
movl %eax, %ecx
shrl $0x6, %ecx
xorl %eax, %ecx
movl %ecx, %eax
shll $0xb, %eax
notl %eax
addl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
xorl %eax, %ecx
movq 0x8(%rsp), %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%r14)
movl 0x14(%rax), %eax
movl %eax, 0x14(%r14)
cmpl $0x0, 0xc(%r13)
movl $0x0, %ecx
cmovgl %ecx, %eax
movl %eax, 0x14(%r14)
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x101ea
movslq (%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%rbx)
movq %r14, 0x10(%rbx,%rax,8)
testq %rax, %rax
je 0x11571
movq (%r14), %rdx
movq 0x58(%rsp), %r8
movq 0x50(%rsp), %r9
leaq -0x1(%rax), %rsi
movq %rsi, %rcx
shrq %rcx
movq 0x10(%rbx,%rcx,8), %rdi
cmpq (%rdi), %rdx
jb 0x11580
movq %rdi, 0x10(%rbx,%rax,8)
movq %rcx, %rax
cmpq $0x1, %rsi
ja 0x1147e
jmp 0x11583
movq 0x10(%rbx), %rsi
movl 0x4(%rsi), %eax
movslq %r12d, %rcx
xorl %r15d, %r15d
cmpq %rcx, %rax
jbe 0x11565
leaq 0x60(%rsp), %r15
movq %r15, %rdi
xorl %edx, %edx
callq 0x104bb
testq %rax, %rax
je 0x115b1
shlq $0x20, %r12
movl 0x14(%rsp), %edx
movl %edx, %ecx
incl %edx
movl %edx, 0x14(%rsp)
orq %r12, %rcx
movq %rcx, (%rax)
movl 0x2c(%rsp), %ecx
movl %ecx, 0xc(%rax)
movl 0x8(%r13), %ecx
movl %ecx, %edx
shll $0xf, %edx
notl %edx
addl %ecx, %edx
movl %edx, %ecx
shrl $0xa, %ecx
xorl %edx, %ecx
leal (%rcx,%rcx,8), %ecx
movl %ecx, %edx
shrl $0x6, %edx
xorl %ecx, %edx
movl %edx, %ecx
shll $0xb, %ecx
notl %ecx
addl %edx, %ecx
movl %ecx, %edx
shrl $0x10, %edx
xorl %ecx, %edx
movq 0x8(%rsp), %rcx
addl 0x10(%rcx), %edx
movl %edx, 0x10(%rax)
movl 0x14(%rcx), %ecx
movl %ecx, 0x14(%rax)
movq %r15, %rdi
xorl %r15d, %r15d
cmpl $0x0, 0xc(%r13)
leaq 0x10(%rbx), %r14
cmovgl %r15d, %ecx
movl %ecx, 0x14(%rax)
movq %rax, %rsi
xorl %edx, %edx
callq 0x101ea
movslq (%rbx), %rsi
xorl %edi, %edi
movq %r14, %rdx
movl 0x30(%rsp), %r14d
callq 0x10a27
movq 0x58(%rsp), %r8
movq 0x50(%rsp), %r9
jmp 0x11598
movq %rax, %rcx
movq 0x58(%rsp), %r8
movq 0x50(%rsp), %r9
jmp 0x11583
movq %rax, %rcx
incl %r15d
movl %r15d, 0x14(%rsp)
movq %r14, 0x10(%rbx,%rcx,8)
xorl %r15d, %r15d
movl 0x30(%rsp), %r14d
cmpl $0x14, %r15d
je 0x115a3
testl %r15d, %r15d
jne 0x11619
incq %rbp
cmpq %r8, %rbp
jne 0x11341
jmp 0x1160b
movq 0x20a40(%rip), %rax     # 0x31ff8
movq (%rax), %rdi
movl (%rbx), %edx
movq 0x10(%rbx), %rax
movq (%rax), %r8
movq %r8, %rcx
shrq $0x20, %rcx
subq $0x8, %rsp
leaq 0x1769d(%rip), %rsi     # 0x28c73
movl %r12d, %r9d
xorl %eax, %eax
pushq 0x40(%rsp)
pushq 0xa0(%rsp)
pushq 0x90(%rsp)
callq 0x2210
addq $0x20, %rsp
movq 0x18(%rsp), %rdi
callq 0x30b8
movl $0x1, %r15d
jmp 0x11565
movl 0x2c(%rsp), %r13d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %esi, %esi
jmp 0x11626
movl %r15d, %esi
movl 0x2c(%rsp), %r13d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
incl %r13d
testl %esi, %esi
movl 0x14(%rsp), %ecx
je 0x11015
cmpl $0xc, %esi
movq 0x48(%rsp), %r15
je 0x1164c
xorl %r12d, %r12d
jmp 0x119c3
movq 0x48(%rsp), %r15
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq 0x70(%rsp), %rsi
callq 0x30f6
movq %rbx, %rdi
movq 0x80(%rsp), %rsi
callq 0x30f6
movq 0x88(%rsp), %rbx
testq %rbx, %rbx
je 0x116a2
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %r14
movq %r14, %rdi
callq 0x30f6
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0x30f6
movq %r14, %rdi
movq %rbx, %rsi
callq 0x30f6
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x153a6
movq 0x18(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x30f6
movq %r14, %rdi
xorl %esi, %esi
callq 0x30f6
movq 0x38(%rsp), %rcx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
shlq $0x2, %rax
leaq (%rax,%rax,8), %rcx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %eax, %eax
movl 0x14(%r15,%rbx), %esi
andl %edx, %esi
cmpl $0x1, %esi
sbbl $-0x1, %eax
addq $0x24, %rbx
cmpq %rbx, %rcx
jne 0x116e3
xorl %r12d, %r12d
movq 0xe8(%rsp), %r15
testq %r15, %r15
je 0x119b9
testl %eax, %eax
movq 0x18(%rsp), %rdi
je 0x119be
movl %r13d, %ebp
movl $0x4, %edx
movq %rbp, %rsi
callq 0x3054
movq 0x38(%rsp), %rdx
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
movq %rax, %r14
shlq $0x2, %rcx
leaq (%rcx,%rcx,8), %rax
xorl %ecx, %ecx
movq 0x48(%rsp), %rsi
movq 0x20(%rsp), %r11
movq 0x40(%rsp), %rdi
testl $0x7fffffff, 0x14(%rsi,%rcx) # imm = 0x7FFFFFFF
je 0x11780
cmpl $0x0, 0x4(%rsi,%rcx)
js 0x11780
movslq 0x18(%rsi,%rcx), %rdx
testq %rdx, %rdx
js 0x11780
movq (%rdi,%rdx,8), %rdx
movslq (%rdx), %rdx
movl $0x1, (%r14,%rdx,4)
addq $0x24, %rcx
cmpq %rcx, %rax
jne 0x11756
testl %r13d, %r13d
je 0x118b3
movq 0x10(%r11), %rax
leaq 0x4(%rsi), %rdx
xorl %esi, %esi
movl $0x0, %edi
testq %rax, %rax
je 0x11845
movq 0x40(%rsp), %rcx
movq (%rcx,%rsi,8), %rcx
movl 0x8(%rcx), %r8d
movb (%r11), %cl
movl $0x1, %edi
shll %cl, %edi
movl %r8d, %r9d
shll $0xf, %r9d
notl %r9d
addl %r8d, %r9d
movl %r9d, %r10d
shrl $0xa, %r10d
xorl %r9d, %r10d
leal (%r10,%r10,8), %r9d
movl %r9d, %r10d
shrl $0x6, %r10d
xorl %r9d, %r10d
movl %r10d, %r9d
shll $0xb, %r9d
notl %r9d
addl %r10d, %r9d
movl %r9d, %r10d
shrl $0x10, %r10d
xorl %r9d, %r10d
imull $0x9e3779b9, %r10d, %r9d # imm = 0x9E3779B9
negb %cl
shrl %cl, %r9d
leal -0x1(%rdi), %ecx
movq 0x8(%r11), %r11
movl %r9d, %r10d
movl %r10d, %ebx
shrl $0x5, %ebx
movl (%r11,%rbx,4), %ebx
btl %r10d, %ebx
jae 0x11840
movl %r10d, %ebx
leaq (%rbx,%rbx,2), %rbx
cmpl %r8d, (%rax,%rbx,4)
je 0x1183d
incl %r10d
andl %ecx, %r10d
cmpl %r9d, %r10d
jne 0x11813
jmp 0x11840
movl %r10d, %edi
movq 0x20(%rsp), %r11
testq %rax, %rax
je 0x11858
movb (%r11), %cl
movl $0x1, %r8d
shll %cl, %r8d
jmp 0x1185b
xorl %r8d, %r8d
cmpl %r8d, %edi
je 0x118a7
movl %edi, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x4(%rax,%rcx,4), %r8
testl %r8d, %r8d
jle 0x118a7
movq %r8, %rcx
sarq $0x20, %rcx
movq %r8, %rdi
shlq $0x20, %rdi
addq %r8, %rdi
sarq $0x20, %rdi
leaq (%rcx,%rcx,8), %r8
leaq (%rdx,%r8,4), %r8
cmpl $0x0, (%r8)
jns 0x1189b
movl $0x1, (%r14,%rsi,4)
incq %rcx
addq $0x24, %r8
cmpq %rdi, %rcx
jl 0x1188d
incq %rsi
cmpq %rbp, %rsi
jne 0x1179c
movl %r13d, %eax
decl %eax
movq 0x40(%rsp), %rdx
js 0x118e7
movl %eax, %eax
incq %rax
cmpl $0x0, -0x4(%r14,%rax,4)
je 0x118e2
movq -0x8(%rdx,%rax,8), %rcx
movslq 0xc(%rcx), %rcx
testq %rcx, %rcx
js 0x118e2
movl $0x1, (%r14,%rcx,4)
decq %rax
jg 0x118c4
testl %r13d, %r13d
je 0x11918
xorl %ecx, %ecx
xorl %edx, %edx
xorl %eax, %eax
movl (%r14,%rcx,4), %esi
cmpl $0x1, %esi
movl $0x0, %edi
sbbl %edi, %edi
cmpl $0x1, %esi
sbbl $-0x1, %eax
orl %edx, %edi
movl %edi, (%r14,%rcx,4)
incq %rcx
movl %eax, %edx
cmpq %rcx, %rbp
jne 0x118f2
jmp 0x1191a
xorl %eax, %eax
movl %eax, (%r15)
cltq
shlq $0x2, %rax
leaq (%rax,%rax,2), %rsi
movq 0x98(%rsp), %rdi
callq 0x31c1
movq %rax, %r12
testl %r13d, %r13d
movq 0x40(%rsp), %rdi
je 0x1197f
xorl %eax, %eax
movslq (%r14,%rax,4), %rcx
testq %rcx, %rcx
js 0x11977
leaq (%rcx,%rcx,2), %rcx
movq (%rdi,%rax,8), %rdx
movl 0x8(%rdx), %esi
movl %esi, (%r12,%rcx,4)
movl 0x4(%rdx), %esi
movl %esi, 0x4(%r12,%rcx,4)
movslq 0xc(%rdx), %rdx
testq %rdx, %rdx
js 0x11970
movl (%r14,%rdx,4), %edx
leaq (%r12,%rcx,4), %rcx
movl %edx, 0x8(%rcx)
incq %rax
cmpq %rax, %rbp
jne 0x11943
movq 0x38(%rsp), %rcx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
shlq $0x2, %rax
leaq (%rax,%rax,8), %rax
xorl %ecx, %ecx
movq 0x48(%rsp), %rsi
movslq 0x18(%rsi,%rcx), %rdx
testq %rdx, %rdx
js 0x119b0
movl (%r14,%rdx,4), %edx
movl %edx, 0x18(%rsi,%rcx)
addq $0x24, %rcx
cmpq %rcx, %rax
jne 0x1199e
movq 0x18(%rsp), %rdi
callq 0x30b8
movq %r12, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, 0x34(%rsp)
leaq 0x1720e(%rip), %rdi     # 0x28bf1
leaq 0x1720e(%rip), %rsi     # 0x28bf8
leaq 0x17210(%rip), %rcx     # 0x28c01
movl $0x52, %edx
callq 0x2160