// File: /workspace/github_c_makefile_star2_O3/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 $0xb8, %rsp
movl %r9d, %r15d
movq %r8, %rbx
movq %rdx, 0x90(%rsp)
movq %rsi, %r10
movq 0xf8(%rsp), %rax
movq $0x0, 0x48(%rsp)
testq %rax, %rax
je 0x10fcd
movl $0x0, (%rax)
testl %ecx, %ecx
jle 0x11071
movl 0xf0(%rsp), %eax
movq %rcx, 0x68(%rsp)
movl %ecx, %esi
leaq (,%rsi,4), %rcx
leaq (%rcx,%rcx,8), %rcx
xorl %edx, %edx
movl $0x80000000, %r8d       # imm = 0x80000000
cmpl $0x0, 0xc(%rbx,%rdx)
js 0x11010
movl $0xffffffff, 0x1c(%rbx,%rdx) # imm = 0xFFFFFFFF
movl 0x14(%rbx,%rdx), %r9d
andl %r8d, %r9d
jmp 0x11023
movl $0x0, 0x1c(%rbx,%rdx)
movl 0x14(%rbx,%rdx), %r9d
andl %r8d, %r9d
incl %r9d
movl %r9d, 0x14(%rbx,%rdx)
movl $0xffffffff, 0x18(%rbx,%rdx) # imm = 0xFFFFFFFF
addq $0x24, %rdx
cmpq %rdx, %rcx
jne 0x10ff7
movq %r10, 0xb0(%rsp)
cmpl $0xf, %eax
movl $0xf, %ecx
cmovll %eax, %ecx
movl %ecx, 0x58(%rsp)
leaq 0x21621(%rip), %rax     # 0x32678
movl (%rax), %eax
notl %eax
testb $0x21, %al
movq %rsi, 0x8(%rsp)
movq %rdi, 0xa8(%rsp)
jne 0x11079
xorl %r14d, %r14d
jmp 0x1108b
xorl %r12d, %r12d
jmp 0x11cb3
movl $0x4000, %esi           # imm = 0x4000
callq 0x2f3c
movq 0x8(%rsp), %rsi
movq %rax, %r14
movl $0x1, %edx
movq %r14, %rdi
callq 0x2f84
movq %rax, 0x88(%rsp)
movq 0x8(%rsp), %rax
leaq (,%rax,8), %rsi
movq %r14, %rdi
callq 0x30e5
movq 0x8(%rsp), %rsi
xorl %edi, %edi
movq %rbx, 0x38(%rsp)
movl (%rbx), %edx
shlq $0x20, %rdx
addq %rdi, %rdx
movq %rdx, (%rax,%rdi,8)
incq %rdi
addq $0x24, %rbx
cmpq %rdi, %rsi
jne 0x110c1
movq %r15, 0x98(%rsp)
leaq (%rax,%rsi,8), %rsi
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
callq 0x47e4
movl $0x1, %ebx
movl $0x1, %esi
movl $0x20, %edx
movq %r14, %rdi
callq 0x2f84
movq %r14, 0x20(%rsp)
movq %r14, 0x18(%rax)
movq 0x68(%rsp), %r14
leal (%r14,%r14), %esi
movq %rax, 0x28(%rsp)
movq %rax, %rdi
callq 0x11ee2
movq 0x40(%rsp), %rdi
movq 0x8(%rsp), %r11
leal 0x1(%r14), %eax
movq %rax, (%rsp)
xorl %ebp, %ebp
movslq %ebp, %r12
cmpq %r11, %rbx
jne 0x11152
movq (%rdi,%r12,8), %r13
movq 0x28(%rsp), %r14
jmp 0x1116c
movq (%rdi,%r12,8), %r13
movq (%rdi,%rbx,8), %rax
xorq %r13, %rax
shrq $0x20, %rax
movq 0x28(%rsp), %r14
je 0x1129e
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x11183
movb (%r14), %cl
movl $0x1, %r15d
shll %cl, %r15d
jmp 0x11186
xorl %r15d, %r15d
movl %r15d, %ecx
shrl %ecx
movl %r15d, %edx
shrl $0x2, %edx
addl %ecx, %edx
cmpl %edx, 0x4(%r14)
jae 0x1119e
movl (%r14), %ecx
jmp 0x111c7
leal 0x1(%r15), %esi
movq %r14, %rdi
callq 0x11ee2
testl %eax, %eax
js 0x112ad
movl (%r14), %ecx
movl $0x1, %r15d
shll %cl, %r15d
movq 0x10(%r14), %rax
movq 0x8(%rsp), %r11
shrq $0x20, %r13
movl %r15d, %esi
movl %r13d, %edx
shll $0xf, %edx
notl %edx
addl %r13d, %edx
movl %edx, %edi
shrl $0xa, %edi
xorl %edx, %edi
leal (%rdi,%rdi,8), %edx
movl %edx, %edi
shrl $0x6, %edi
xorl %edx, %edi
movl %edi, %edx
shll $0xb, %edx
notl %edx
addl %edi, %edx
movl %edx, %edi
shrl $0x10, %edi
xorl %edx, %edi
imull $0x9e3779b9, %edi, %r15d # imm = 0x9E3779B9
negb %cl
shrl %cl, %r15d
decl %esi
movq 0x8(%r14), %rdx
movl %r15d, %ecx
movl %ecx, %edi
shrl $0x5, %edi
movl (%rdx,%rdi,4), %r9d
movl $0x1, %r8d
shll %cl, %r8d
btl %ecx, %r9d
jae 0x11255
movl %ecx, %r10d
leaq (%r10,%r10,2), %r10
cmpl %r13d, (%rax,%r10,4)
je 0x11255
incl %ecx
andl %esi, %ecx
cmpl %r15d, %ecx
jne 0x1120f
movl %r15d, %edi
shrl $0x5, %edi
movl $0x1, %r8d
movl %r15d, %ecx
shll %cl, %r8d
movl (%rdx,%rdi,4), %r9d
jmp 0x11258
movl %ecx, %r15d
testl %r9d, %r8d
movq 0x28(%rsp), %rsi
jne 0x11d10
movl %r15d, %ecx
leaq (%rcx,%rcx,2), %rcx
movl %r13d, (%rax,%rcx,4)
orl %r8d, (%rdx,%rdi,4)
incl 0x4(%rsi)
movl $0x1, %ecx
movq 0x40(%rsp), %rdi
shlq $0x20, %r12
movl %ebx, %edx
subl %ebp, %edx
movslq %edx, %rdx
orq %r12, %rdx
movl %r15d, %esi
leaq (%rsi,%rsi,2), %rsi
movq %rdx, 0x4(%rax,%rsi,4)
movl %ebx, %ebp
incq %rbx
cmpq (%rsp), %rbx
jne 0x1113f
jmp 0x112bd
movq 0x10(%r14), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %r11
jmp 0x1127d
leaq 0x5c(%rsp), %r14
movl %ecx, (%r14)
movl $0x1, %esi
movl $0x20, %edx
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x2f84
movq %rax, %rbp
movq %rbx, 0x18(%rax)
movq %rax, %rdi
movl $0x10, %esi
callq 0x12136
movl $0x80, %esi
movq %rbx, %rdi
callq 0x30e5
movq %rax, 0x60(%rsp)
movl $0x30, %esi
movq %rbx, %rdi
callq 0x30e5
movq %rax, %r12
movq 0x90(%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(%r12)
leaq 0x48(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x10621
movq %rbp, %rdi
movl %r15d, %esi
movq %r14, %rdx
callq 0x11d47
movq %rbp, 0xa0(%rsp)
movq 0x10(%rbp), %rcx
movl %eax, %eax
imulq $0x8c, %rax, %rax
movabsq $-0xffffffff, %rdx      # imm = 0xFFFFFFFF00000001
movq %rdx, 0x4(%rcx,%rax)
movq %r12, 0x14(%rcx,%rax)
movl %ebx, 0xc(%rcx,%rax)
movq (%r13), %rax
testq %rax, %rax
je 0x1197f
movq $0x0, 0x70(%rsp)
movl $0x1, 0x14(%rsp)
movq $0x0, 0x30(%rsp)
movl $0x10, 0x54(%rsp)
movq 0x38(%rsp), %r14
movq 0x98(%rsp), %r13
cmpl $0x0, 0x2c(%rax)
je 0x11989
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x108a4
movq %rax, (%rsp)
movl 0x54(%rsp), %eax
cmpl %eax, 0x30(%rsp)
jne 0x11447
movl %eax, %ebx
shrl %ebx
addl %eax, %ebx
cmpl $0x4, %eax
movl $0x10, %eax
cmovbl %eax, %ebx
leaq (,%rbx,8), %rdx
movq 0x20(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x31ed
movl %ebx, 0x54(%rsp)
movq 0x28(%rsp), %r10
jmp 0x11451
movq 0x28(%rsp), %r10
movq 0x60(%rsp), %rax
movq (%rsp), %rsi
movq (%rsi), %r12
movq 0x30(%rsp), %rdx
movl %edx, %ecx
movl %edx, (%rsi)
leal 0x1(%rdx), %r15d
movq %rax, 0x60(%rsp)
movq %rsi, (%rax,%rcx,8)
movl 0x8(%rsi), %edx
movq 0x10(%r10), %rsi
testq %rsi, %rsi
movq %r15, 0x18(%rsp)
je 0x116e1
movb (%r10), %cl
movl $0x1, %edi
shll %cl, %edi
movl %edx, %r8d
shll $0xf, %r8d
notl %r8d
addl %edx, %r8d
movl %r8d, %r9d
shrl $0xa, %r9d
xorl %r8d, %r9d
leal (%r9,%r9,8), %r8d
movl %r8d, %r9d
shrl $0x6, %r9d
xorl %r8d, %r9d
movl %r9d, %r8d
shll $0xb, %r8d
notl %r8d
addl %r9d, %r8d
movl %r8d, %r9d
shrl $0x10, %r9d
xorl %r8d, %r9d
imull $0x9e3779b9, %r9d, %r8d # imm = 0x9E3779B9
negb %cl
shrl %cl, %r8d
leal -0x1(%rdi), %ecx
movq 0x8(%r10), %r10
movl %r8d, %r9d
movl %r9d, %r11d
shrl $0x5, %r11d
movl (%r10,%r11,4), %r11d
btl %r9d, %r11d
jae 0x116e1
movl %r9d, %r11d
leaq (%r11,%r11,2), %rbx
cmpl %edx, (%rsi,%rbx,4)
je 0x11510
incl %r9d
andl %ecx, %r9d
cmpl %r8d, %r9d
jne 0x114df
jmp 0x116e1
cmpl %edi, %r9d
je 0x116e1
leaq (%r11,%r11,2), %rcx
movq 0x4(%rsi,%rcx,4), %rcx
testl %ecx, %ecx
movq 0x40(%rsp), %rax
jle 0x116cb
shrq $0x20, %r12
movq %rcx, %rdx
sarq $0x20, %rdx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rax,%rdx,8), %rsi
addq 0x88(%rsp), %rdx
xorl %edi, %edi
movslq (%rsi,%rdi,8), %r8
leaq (%r8,%r8,8), %r8
movl 0xc(%r14,%r8,4), %r11d
testl %r11d, %r11d
js 0x115fe
leaq (%r14,%r8,4), %r8
movl 0x4(%r8), %r14d
movl 0x14(%r8), %r9d
movl %r9d, %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
je 0x11606
testl %r14d, %r14d
js 0x11670
cmpl $0x40000000, %r11d      # imm = 0x40000000
jb 0x115b3
cmpl %r12d, %r14d
jne 0x115b3
movq %r15, %rax
movq (%rsp), %r10
movl 0x10(%r10), %r15d
movl $0x1, %r10d
movl %r12d, %ebp
cmpl 0x8(%r8), %r15d
movq %rax, %r15
je 0x1160c
movl 0x1c(%r8), %r10d
subl %r14d, %r10d
movl %r10d, %r15d
negl %r15d
cmovsl %r10d, %r15d
movl %r14d, %r10d
subl %r12d, %r10d
movq %rdx, %rax
movq %rcx, %rdx
movq %rsi, %rcx
movq %r12, %rsi
movl %r10d, %r12d
negl %r12d
cmovsl %r10d, %r12d
xorl %r10d, %r10d
movl %r14d, %ebp
cmpl %r15d, %r12d
movq %rsi, %r12
movq %rcx, %rsi
movq %rdx, %rcx
movq %rax, %rdx
movq 0x18(%rsp), %r15
jb 0x1160c
jmp 0x11673
movb $0x1, %r8b
jmp 0x116a4
xorl %r10d, %r10d
movl %r14d, %ebp
movq 0x30(%rsp), %rax
movl %eax, 0x18(%r8)
movl %r12d, 0x1c(%r8)
movq (%rsp), %rax
movl 0x10(%rax), %r9d
movl %r9d, 0x20(%r8)
movl 0x14(%rax), %r9d
shll $0x1f, %r9d
orl %ebx, %r9d
movl %r9d, 0x14(%r8)
testl %ebp, %ebp
js 0x11673
cmpl $0x40000000, %r11d      # imm = 0x40000000
jb 0x1165c
cmpl %r12d, %ebp
jne 0x1165c
movq (%rsp), %rax
movl 0x10(%rax), %r11d
cmpl 0x8(%r8), %r11d
jne 0x1165c
movl $0x1, %r10d
jmp 0x11673
addl $0x3e8, %ebp            # imm = 0x3E8
cmpl %r12d, %ebp
movl $0x1, %eax
cmovll %eax, %r10d
jmp 0x11673
xorl %r10d, %r10d
leal 0x1(%r9), %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
andl $0x80000000, %r9d       # imm = 0x80000000
orl %r11d, %r9d
movl %r9d, 0x14(%r8)
cmpl 0x58(%rsp), %r11d
setge %r9b
testl %r10d, %r10d
setne %r8b
orb %r9b, %r8b
movq 0x38(%rsp), %r14
testb %r8b, %r8b
je 0x116bf
cmpb $0x0, (%rdx,%rdi)
jne 0x116bf
movb $0x1, (%rdx,%rdi)
movq 0x70(%rsp), %rax
incl %eax
movq %rax, 0x70(%rsp)
incq %rdi
cmpq %rdi, %rcx
jne 0x1154e
movq 0x70(%rsp), %rax
cmpl 0x68(%rsp), %eax
je 0x1198e
movq (%rsp), %rax
movl 0x8(%rax), %edx
movq 0xb0(%rsp), %rsi
movq 0x58(%rsi), %rax
movl %edx, %ecx
movq (%rax,%rcx,8), %rcx
testl %ecx, %ecx
jle 0x1195d
movq %rcx, %rdx
shrq $0x1b, %rdx
andq $-0x20, %rdx
addq 0x48(%rsi), %rdx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %r15d, %r15d
movq %rcx, 0x80(%rsp)
movq %rdx, 0x78(%rsp)
movq %r15, %rbp
shlq $0x5, %rbp
movq (%rsp), %rax
movl 0x4(%rax), %r14d
addq (%rdx,%rbp), %r14
cmpl %r13d, %r14d
jg 0x11951
addq %rdx, %rbp
movl 0x8(%rbp), %esi
movq 0xa0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x5c(%rsp), %rdx
callq 0x11d47
movq 0x10(%rbx), %rcx
movl %eax, %eax
imulq $0x8c, %rax, %rax
leaq (%rcx,%rax), %r12
addq $0x4, %r12
cmpl $0x0, 0x5c(%rsp)
je 0x1178e
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, (%r12)
movl $0xffffffff, 0x8(%r12)  # imm = 0xFFFFFFFF
xorl %eax, %eax
jmp 0x11792
movl (%r12), %eax
cmpl 0x58(%rsp), %eax
jge 0x1187d
movl 0x8(%rbp), %ebx
movl $0x30, %esi
movq 0x20(%rsp), %rdi
callq 0x30e5
movq %rax, %r13
movl %ebx, 0x8(%rax)
shlq $0x20, %r14
movslq 0x14(%rsp), %rax
orq %r14, %rax
movq %rax, (%r13)
movl $0x1, 0x14(%r13)
movq 0x30(%rsp), %rax
movl %eax, 0xc(%r13)
movl 0x8(%rbp), %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 (%rsp), %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%r13)
xorl %r14d, %r14d
cmpl $0x0, 0xc(%rbp)
movl $0x0, %eax
jg 0x11822
movq (%rsp), %rax
movl 0x14(%rax), %eax
movl %eax, 0x14(%r13)
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x10621
movslq (%r12), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r12)
movq %r13, 0x10(%r12,%rax,8)
testq %rax, %rax
je 0x11933
movq (%r13), %rcx
leaq -0x1(%rax), %rdx
movq %rdx, %r14
shrq %r14
movq 0x10(%r12,%r14,8), %rsi
cmpq (%rsi), %rcx
jb 0x11930
movq %rsi, 0x10(%r12,%rax,8)
movq %r14, %rax
cmpq $0x1, %rdx
ja 0x11852
jmp 0x11933
movq 0x10(%r12), %rsi
movl 0x4(%rsi), %eax
movslq %r14d, %rcx
cmpq %rcx, %rax
jbe 0x11944
leaq 0x48(%rsp), %rdi
xorl %edx, %edx
callq 0x108a4
testq %rax, %rax
je 0x11cc8
shlq $0x20, %r14
movl 0x14(%rsp), %ecx
orq %r14, %rcx
movq %rcx, (%rax)
movq 0x30(%rsp), %rcx
movl %ecx, 0xc(%rax)
movl 0x8(%rbp), %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 (%rsp), %rcx
addl 0x10(%rcx), %edx
movl %edx, 0x10(%rax)
cmpl $0x0, 0xc(%rbp)
movl $0x0, %ecx
jg 0x11905
movq (%rsp), %rcx
movl 0x14(%rcx), %ecx
leaq 0x10(%r12), %r14
incl 0x14(%rsp)
movl %ecx, 0x14(%rax)
leaq 0x48(%rsp), %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x10621
movslq (%r12), %rsi
xorl %edi, %edi
movq %r14, %rdx
callq 0x10dbf
jmp 0x11944
movq %rax, %r14
incl 0x14(%rsp)
movq %r13, 0x10(%r12,%r14,8)
movq 0x98(%rsp), %r13
movq 0x80(%rsp), %rcx
movq 0x78(%rsp), %rdx
incq %r15
cmpq %rcx, %r15
jne 0x11720
movq 0x48(%rsp), %rax
movq 0x18(%rsp), %r15
movl %r15d, %ecx
movq %rcx, 0x30(%rsp)
testq %rax, %rax
movq 0x38(%rsp), %r14
jne 0x113ee
jmp 0x1198e
movq 0x38(%rsp), %r14
xorl %r15d, %r15d
jmp 0x1198e
movq 0x30(%rsp), %r15
movq %r15, 0x18(%rsp)
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq 0x40(%rsp), %rsi
callq 0x301f
movq %rbx, %rdi
movq 0x88(%rsp), %rsi
callq 0x301f
movq 0xa0(%rsp), %rbx
testq %rbx, %rbx
je 0x119ee
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %r14
movq %r14, %rdi
callq 0x301f
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0x301f
movq %r14, %rdi
movq 0x38(%rsp), %r14
movq %rbx, %rsi
callq 0x301f
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x15629
movq 0x20(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x301f
movq %r15, %rdi
xorl %esi, %esi
callq 0x301f
leaq 0x14(%r14), %rax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %rdx
movq 0x60(%rsp), %r13
movl (%rax), %esi
andl %ecx, %esi
cmpl $0x1, %esi
sbbl $-0x1, %ebx
addq $0x24, %rax
decq %rdx
jne 0x11a23
xorl %r12d, %r12d
movq 0xf8(%rsp), %rax
testq %rax, %rax
movq 0x18(%rsp), %rcx
je 0x11ca9
testl %ebx, %ebx
je 0x11ca9
movq %rax, %r12
movl %ecx, %ebp
movl $0x4, %edx
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x2f84
movq %rax, %r15
leaq 0x18(%r14), %rax
movq 0x8(%rsp), %rcx
movq 0x28(%rsp), %rsi
testl $0x7fffffff, -0x4(%rax) # imm = 0x7FFFFFFF
je 0x11aa6
cmpl $0x0, -0x14(%rax)
js 0x11aa6
movslq (%rax), %rdx
testq %rdx, %rdx
js 0x11aa6
movq (%r13,%rdx,8), %rdx
movslq (%rdx), %rdx
movl $0x1, (%r15,%rdx,4)
addq $0x24, %rax
decq %rcx
jne 0x11a7f
cmpl $0x0, 0x18(%rsp)
je 0x11c22
movq 0x10(%rsi), %rax
leaq 0x4(%r14), %rdx
xorl %esi, %esi
testq %rax, %rax
je 0x11bad
movq (%r13,%rsi,8), %rcx
movl 0x8(%rcx), %edi
movq 0x28(%rsp), %r11
movb (%r11), %cl
movl $0x1, %r8d
shll %cl, %r8d
movl %edi, %r9d
shll $0xf, %r9d
notl %r9d
addl %edi, %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(%r8), %ecx
movq 0x8(%r11), %r11
movl %r9d, %r10d
movl %r10d, %ebx
shrl $0x5, %ebx
movl (%r11,%rbx,4), %ebx
btl %r10d, %ebx
jae 0x11bad
movl %r10d, %ebx
leaq (%rbx,%rbx,2), %r14
cmpl %edi, (%rax,%r14,4)
je 0x11b63
incl %r10d
andl %ecx, %r10d
cmpl %r9d, %r10d
jne 0x11b39
jmp 0x11bad
cmpl %r8d, %r10d
je 0x11bad
leaq (%rbx,%rbx,2), %rcx
movq 0x4(%rax,%rcx,4), %r8
testl %r8d, %r8d
jle 0x11bad
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 0x11ba1
movl $0x1, (%r15,%rsi,4)
incq %rcx
addq $0x24, %r8
cmpq %rdi, %rcx
jl 0x11b93
incq %rsi
cmpq %rbp, %rsi
jne 0x11ac4
movq 0x18(%rsp), %rax
decl %eax
movq 0x38(%rsp), %r14
js 0x11bef
movl %eax, %eax
incq %rax
cmpl $0x0, -0x4(%r15,%rax,4)
je 0x11bea
movq -0x8(%r13,%rax,8), %rcx
movslq 0xc(%rcx), %rcx
testq %rcx, %rcx
js 0x11bea
movl $0x1, (%r15,%rcx,4)
decq %rax
jg 0x11bcc
cmpl $0x0, 0x18(%rsp)
je 0x11c22
xorl %ecx, %ecx
xorl %edx, %edx
xorl %eax, %eax
movl (%r15,%rcx,4), %esi
cmpl $0x1, %esi
movl $0x0, %edi
sbbl %edi, %edi
cmpl $0x1, %esi
sbbl $-0x1, %eax
orl %edx, %edi
movl %edi, (%r15,%rcx,4)
incq %rcx
movl %eax, %edx
cmpq %rcx, %rbp
jne 0x11bfc
jmp 0x11c24
xorl %eax, %eax
movl %eax, (%r12)
cltq
shlq $0x2, %rax
leaq (%rax,%rax,2), %rsi
movq 0xa8(%rsp), %rdi
callq 0x30e5
movq %rax, %r12
cmpl $0x0, 0x18(%rsp)
movq 0x8(%rsp), %rdi
je 0x11c8d
xorl %eax, %eax
movslq (%r15,%rax,4), %rcx
testq %rcx, %rcx
js 0x11c85
leaq (%rcx,%rcx,2), %rcx
movq (%r13,%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 0x11c7e
movl (%r15,%rdx,4), %edx
leaq (%r12,%rcx,4), %rcx
movl %edx, 0x8(%rcx)
incq %rax
cmpq %rax, %rbp
jne 0x11c50
addq $0x18, %r14
movslq (%r14), %rax
testq %rax, %rax
js 0x11ca0
movl (%r15,%rax,4), %eax
movl %eax, (%r14)
addq $0x24, %r14
decq %rdi
jne 0x11c91
movq 0x20(%rsp), %rdi
callq 0x2fe1
movq %r12, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20329(%rip), %rax     # 0x31ff8
movq (%rax), %rdi
movl (%r12), %edx
movq 0x10(%r12), %rax
movq (%rax), %r8
movq %r8, %rcx
shrq $0x20, %rcx
subq $0x8, %rsp
leaq 0x16fba(%rip), %rsi     # 0x28caa
xorl %r12d, %r12d
movl %r14d, %r9d
xorl %eax, %eax
pushq 0x70(%rsp)
pushq %r13
pushq 0xa8(%rsp)
callq 0x2210
addq $0x20, %rsp
jmp 0x11ca9
shlq $0x20, %r12
subl %ebp, %ebx
movslq %ebx, %rcx
orq %r12, %rcx
movl %r15d, %edx
leaq (%rdx,%rdx,2), %rdx
movq %rcx, 0x4(%rax,%rdx,4)
leaq 0x16ef9(%rip), %rdi     # 0x28c28
leaq 0x16ef9(%rip), %rsi     # 0x28c2f
leaq 0x16efb(%rip), %rcx     # 0x28c38
movl $0x52, %edx
callq 0x2160