// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: mg_shortest_k(void*, asg_t const*, unsigned int, int, mg_path_dst_t*, int, int, int*)
mg_pathv_t *mg_shortest_k(void *km0, const asg_t *g, uint32_t src, int32_t n_dst, mg_path_dst_t *dst, int32_t max_dist, int32_t max_k, /** //pathint32_t ql, const char *qs, int is_rev, **/int32_t *n_pathv)
{
	sp_node_t *p, *root = 0, **out;
	sp_topk_t *q;
	khash_t(sp) *h;
	khash_t(sp2) *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;
	/** //path
	int32_t n_seeds = 0;
	uint64_t *seeds = 0;
	void *h_seeds = 0; 
	mg128_v mini = {0,0,0}; 
	**/

	if (n_pathv) *n_pathv = 0;///for us, n_pathv = NULL
	if (n_dst <= 0) return 0;///n_dst: how many candidate nodes
	for (i = 0; i < n_dst; ++i) { // initialize
		mg_path_dst_t *t = &dst[i];
		///if src and dest are at the same ref id, there are already one path
		if (t->inner)///if two chains are at the same ref id
			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 = km_init2(km0, 0x4000);

	/** //path
	///for the first time, we just check th reachability without sequence (qs);
	///but for the second round, we need to check sequence
	///qs is the sequence between two minimizers
	if (ql > 0 && qs) { // build the seed hash table for the query
		mg_sketch(km, qs, ql, MG_SHORT_KW, MG_SHORT_KK, 0, &mini);
		// mini->a[].x = hash_key<<8 | kmerSpan
		// mini->a[].y = rid<<32 | lastPos<<1 | strand
		if (is_rev)///is_rev = 1;
			for (i = 0; i < mini.n; ++i)///reverse qs[0, ql) to qs(ql, 0]
				mini.a[i].y = (ql - (((int32_t)mini.a[i].y>>1) + 1 - MG_SHORT_KK) - 1) << 1 | ((mini.a[i].y&1)^1);
		///h_seeds is the ordinary hash index
		h_seeds = mg_idx_a2h(km, mini.n, mini.a, 0, &seeds, &n_seeds);
		///h_seeds+seeds+n_seeds ----> hash index of qs[0, ql)
	}
	**/
	///dst is how many candidates
	KCALLOC(km, dst_done, n_dst);
	KMALLOC(km, dst_group, n_dst);
	// multiple dst[] may have the same dst[].v. We need to group them first.
	// in other words, one ref id may have multiple dst alignment chains
	for (i = 0; i < n_dst; ++i) 
		dst_group[i] = (uint64_t)dst[i].v<<32 | i;
	radix_sort_gfa64(dst_group, dst_group + n_dst);

	h2 = kh_init2(sp2, km); // (h2+dst_group) keeps all destinations from the same ref id
	kh_resize(sp2, h2, n_dst * 2);
	///please note that one contig in ref may have multiple alignment chains
	///so h2 is a index that helps us to query it
	///key(h2) = ref id; value(h2) = start_idx | occ
	for (i = 1, j = 0; i <= n_dst; ++i) {
		if (i == n_dst || dst_group[i]>>32 != dst_group[j]>>32) {
			k = kh_put(sp2, h2, dst_group[j]>>32, &absent);
			kh_val(h2, k) = (uint64_t)j << 32 | (i - j);
			assert(absent);
			j = i;
		}
	}

	

	h = kh_init2(sp, km); // h keeps visited vertices; path to each visited vertice
	kh_resize(sp, h, 16);

	m_out = 16, n_out = 0;///16 is just the initial size
	KMALLOC(km, out, m_out);
	
	/**
	typedef struct {
		int32_t k, mlen;//k: number of walks from src to this node
		int32_t qs, qe;
		sp_node_t *p[MG_MAX_SHORT_K]; // this forms a max-heap; all path
	} sp_topk_t;
	**/
	id = 0;
	p = gen_sp_node(km, src, 0, id++);///just malloc a node for src; the distance is 0
	p->hash = __ac_Wang_hash(src);///hash is path hash, instead of node hash
	kavl_insert(sp, &root, p, 0);///should be avl tree
	///each src corresponds to one node in the hash table <h>, but corresponds to <MG_MAX_SHORT_K> node in the AVL tree <root> 
	k = kh_put(sp, h, src, &absent);///here is a hash table
	q = &kh_val(h, k);
	///for normal graph traversal, one node just has one parental node; here each node has at most 16 parental nodes
	q->k = 1, q->p[0] = p, q->mlen = 0, q->qs = q->qe = -1;

	n_done = 0;
	///the key of avl tree: #define sp_node_cmp(a, b) (((a)->di > (b)->di) - ((a)->di < (b)->di))
	///the higher bits of (*)->di is distance to src node
	///so the key of avl tree is distance
	///in avl tree <root>, one node might be saved multipe times
	while (kavl_size(head, root) > 0) {///thr first root is src
		int32_t i, nv;
		asg_arc_t *av;
		sp_node_t *r;
		///note that one (sp_node_t->v) might be visited multiple times if there are circles
		///so there might be multipe nodes with the same (sp_node_t->v)
		///delete the first node
		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);
		///higher 32 bits might be the distance to root node
		// lower 32 bits now for position in the out[] array
		r->di = r->di>>32<<32 | n_out; ///n_out is just the id in out
		///so one node id in graph might be saved multiple times in avl tree and out[]
		out[n_out++] = r;///out[0] = src

		///r->v is the dst vertex id
		///sometimes k==kh_end(h2). Some nodes are found by graph travesal but not in linear chain alignment
		k = kh_get(sp2, h2, r->v);
		// we have reached one dst vertex
		// note that one dst vertex may have multipe alignment chains
		// we can visit some nodes in graph which are not reachable during chaining
		// h2 is used to determine if one node is reachable or not
		if (k != kh_end(h2)) { 
			///node r->v might be visited multiple times
			int32_t j, dist = r->di>>32, off = kh_val(h2, k) >> 32, cnt = (int32_t)kh_val(h2, k);
			//src can reach ref id r->v; there might be not only one alignment chain in r->v
			//so we need to scan all of them
			for (j = 0; j < cnt; ++j) {
				mg_path_dst_t *t = &dst[(int32_t)dst_group[off + j]];///t is a linear alignment at r->v
				int32_t done = 0;
				///the src and dest are at the same ref id, say we directly find the shortest path
				if (t->inner) {//usually the first node, which is same to src
					done = 1;
				} else {
					int32_t mlen = 0, copy = 0;
					///in the first round, we just check reachability without sequence
					///so h_seeds = NULL; we can assume mlen = 0
					/** //path
					mlen = h_seeds? path_mlen(out, n_out - 1, h, t->qlen) : 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,mlen=%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, mlen, r->hash);
					// note: t indicates a linear alignmnet, instead of a node in graph
					///target_dist should be the distance on query
					if (t->n_path == 0) { // means this alignment has never been visited before; keep the shortest path anyway
						copy = 1;
					 // we have a target distance; choose the closest; 
					 // there is already several paths reaching the linear alignment <t>
					} else if (t->target_dist >= 0) { 
						// we found the target path; hash is the path hash including multiple nodes, instead of node hash 
						if (dist == t->target_dist && t->check_hash && r->hash == t->target_hash) { 
							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 the new distance (d1) is smaller than the old distance (d0), update the results
							///the length of new path should be closer to t->target_dist
							if (d1 - mlen/2 < d0 - t->mlen/2) copy = 1;
						}
					}
					if (copy) {
						t->path_end = n_out - 1, t->dist = dist, t->hash = r->hash, t->mlen = mlen, t->is_0 = r->is_0;
						if (t->target_dist >= 0) {
							///src is from li from li to lj, so the dis is generally increased; dijkstra algorithm
							///target_dist should be the distance on query
							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) && (dist > (t->target_dist>>4))) done = 1;
						}
					}
					++t->n_path;///we found a path to the alignment t
					if (t->n_path >= max_k) done = 1;
				}
				if (dst_done[off + j] == 0 && done)
					dst_done[off + j] = 1, ++n_done;
			}
			///if all alignments have been settle down
			///pre-end; accelerate the loop
			if (n_done == n_dst) break;
		}

		///below is used to push new nodes to avl tree for iteration
		nv = asg_arc_n(g, r->v);
		av = asg_arc_a(g, r->v);
		for (i = 0; i < nv; ++i) { // visit all neighbors
			asg_arc_t *ai = &av[i];
			///v_lv is the (dest_length - overlap_length); it is a normal path length in string graph
			///ai->v_lv is the path length from r->v to ai->w
			///(r->di>>32)
			int32_t d = (r->di>>32) + (uint32_t)ai->ul;
			if (d > max_dist) continue; // don't probe vertices too far away
			// h keeps visited vertices; path to each visited vertice
			///ai->w is the dest ref id; we insert a new ref id, instead of an alignment chain
			k = kh_put(sp, h, ai->v, &absent);///one node might be visited multiple times
			q = &kh_val(h, k);
			if (absent) { // a new vertex visited
				///q->k: number of walks from src to ai->w
				q->k = 0, q->qs = q->qe = -1; q->mlen = 0;
				///h_seeds = NULL; so q->mlen = 0
				/** //path
				q->mlen = h_seeds && d + gfa_arc_lw(g, *ai) <= max_dist? node_mlen(km, g, ai->w, &mini, h_seeds, n_seeds, seeds, &q->qs, &q->qe) : 0;
				**/
				//if (ql && qs) fprintf(stderr, "ql=%d,src=%d\tv=%c%s[%d],n_seeds=%d,mlen=%d\n", ql, src, "><"[ai->w&1], g->seg[ai->w>>1].name, ai->w, n_seeds, q->mlen);
			}
			///if there are less than <max_k> walks from src to ai->w, directly add
			///if there are more, keep the smallest <max_k> walks
			if (q->k < max_k) { // enough room: add to the heap
				p = gen_sp_node(km, ai->v, d, id++);
				p->pre = n_out - 1;///the parent node of this one 
				p->hash = r->hash + __ac_Wang_hash(ai->v);
				p->is_0 = r->is_0;
				/** //path
				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);///adjust heap by distance
			} else if ((int32_t)(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 + __ac_Wang_hash(ai->v);
					p->is_0 = r->is_0;
					/** //path
					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);
	kh_destroy(sp, h);
	/** //path
	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;///n_path might be larger than 16
	///we can assume n_pathv = NULL for now 
	if (n_found > 0 && n_pathv) { // then generate the backtrack array
		int32_t n, *trans;
		///n_out: how many times that nodes in graph have been visited 
		///note one node might be visited multiples times
		KCALLOC(km, trans, n_out); // used to squeeze unused elements in out[]
		///n_dst: number of alignment chains
		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;///(int32_t)out[]->di: traverse track corresponds to the alignment chain dst[]
		}
		for (i = 0; (uint32_t)i < n_out; ++i) { // mark dst vertices without a target distance
			k = kh_get(sp2, 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; (uint32_t)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; (uint32_t)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
movq %r9, 0xa0(%rsp)
movq %r8, %rbx
movq %rdx, 0x80(%rsp)
movq %rsi, %rbp
movq 0xf8(%rsp), %rax
movq $0x0, 0x58(%rsp)
testq %rax, %rax
je 0x19a67c
movl $0x0, (%rax)
testl %ecx, %ecx
jle 0x19af03
movq %rcx, 0x48(%rsp)
movl %ecx, %r13d
movl 0xf0(%rsp), %eax
movq %r13, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
movl $0x80000000, %esi       # imm = 0x80000000
cmpl $0x0, 0xc(%rbx,%rdx)
js 0x19a6be
movl $0xffffffff, 0x1c(%rbx,%rdx) # imm = 0xFFFFFFFF
movl 0x14(%rbx,%rdx), %r8d
andl %esi, %r8d
jmp 0x19a6d1
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 $0x30, %rdx
cmpq %rdx, %rcx
jne 0x19a6a5
cmpl $0xf, %eax
movl $0xf, %ecx
cmovll %eax, %ecx
movl %ecx, 0x6c(%rsp)
movl $0x4000, %esi           # imm = 0x4000
movq %rdi, 0xa8(%rsp)
callq 0x1e355c
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x1e3590
movq %rax, 0x88(%rsp)
leaq (,%r13,8), %rsi
movq %r14, 0x18(%rsp)
movq %r14, %rdi
callq 0x1e36fd
movq %rax, %rdi
xorl %eax, %eax
movq %rbx, 0x30(%rsp)
movl (%rbx), %edx
shlq $0x20, %rdx
addq %rax, %rdx
movq %rdx, (%rdi,%rax,8)
incq %rax
addq $0x30, %rbx
cmpq %rax, %r13
jne 0x19a742
leaq (%rdi,%r13,8), %rsi
movq %rdi, 0x50(%rsp)
callq 0x194fef
movl $0x1, %ebx
movl $0x1, %esi
movl $0x30, %edx
movq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x1e3590
movq %r14, 0x28(%rax)
movq 0x48(%rsp), %r14
leal (%r14,%r14), %esi
movq %rax, 0x38(%rsp)
movq %rax, %rdi
callq 0x19b275
cmpl $0x2, %r14d
movl $0x1, %r15d
cmovgel %r14d, %r15d
negq %r15
xorl %eax, %eax
leaq 0x14(%rsp), %r14
movq %r13, 0x90(%rsp)
movslq %eax, %r12
cmpq %rbx, %r13
je 0x19a7da
movq 0x50(%rsp), %rdx
movq (%rdx,%r12,8), %rcx
xorq (%rdx,%rbx,8), %rcx
shrq $0x20, %rcx
je 0x19a820
movq 0x50(%rsp), %rax
movl 0x4(%rax,%r12,8), %esi
movq 0x38(%rsp), %r13
movq %r13, %rdi
movq %r14, %rdx
callq 0x19b548
movq %rbx, %rcx
subq %r12, %rcx
shlq $0x20, %r12
orq %rcx, %r12
movq 0x20(%r13), %rcx
movl %eax, %eax
movq %r12, (%rcx,%rax,8)
cmpl $0x0, 0x14(%rsp)
je 0x19b256
movl %ebx, %eax
movq 0x90(%rsp), %r13
leaq (%r15,%rbx), %rcx
incq %rcx
incq %rbx
cmpq $0x1, %rcx
jne 0x19a7bf
movl $0x1, %esi
movl $0x30, %edx
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x1e3590
movq %rax, %r15
movq %rbx, 0x28(%rax)
movq %rax, %rdi
movl $0x10, %esi
callq 0x19b6a3
movl $0x80, %esi
movq %rbx, %rdi
callq 0x1e36fd
movq %rax, 0x20(%rsp)
movl $0x30, %esi
movq %rbx, %rdi
callq 0x1e36fd
movq %rax, %r14
movq 0x80(%rsp), %rbx
movl %ebx, 0x8(%rax)
movq $0x0, (%rax)
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
movl $0x1, 0x14(%rax)
movl %ebx, %eax
shll $0xf, %eax
notl %eax
addl %ebx, %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
movl %ecx, 0x10(%r14)
leaq 0x58(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x198259
leaq 0x14(%rsp), %rdx
movq %r15, %rdi
movl %ebx, %esi
callq 0x19ba1b
movq %r15, 0x98(%rsp)
movq 0x20(%r15), %rcx
movl %eax, %eax
movq %rax, %rdx
shlq $0x7, %rdx
leaq (%rdx,%rax,8), %rax
movaps 0x946c7(%rip), %xmm0    # 0x22efd0
movups %xmm0, (%rcx,%rax)
movq %r14, 0x10(%rcx,%rax)
movl $0x10, 0x64(%rsp)
movl $0x0, 0xc(%rsp)
movl $0x1, 0x10(%rsp)
movl $0x0, 0x68(%rsp)
movq %rbp, 0x28(%rsp)
movq 0x58(%rsp), %rax
testq %rax, %rax
movq 0x50(%rsp), %rsi
je 0x19af0b
cmpl $0x0, 0x2c(%rax)
je 0x19af0b
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x19852a
movq %rax, %r14
movl 0x64(%rsp), %eax
cmpl %eax, 0xc(%rsp)
movq 0x30(%rsp), %r12
jne 0x19a9a2
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 0x20(%rsp), %rsi
callq 0x1e3800
movl %ebx, 0x64(%rsp)
jmp 0x19a9a7
movq 0x20(%rsp), %rax
movq (%r14), %r13
movl 0xc(%rsp), %edx
movl %edx, %ecx
movl %edx, (%r14)
movq %rax, 0x20(%rsp)
movq %r14, (%rax,%rcx,8)
movq 0x38(%rsp), %rax
movl (%rax), %edx
testl %edx, %edx
movq %r14, 0x40(%rsp)
je 0x19aa39
movl 0x8(%r14), %edi
leal -0x1(%rdx), %r8d
movl %r8d, %r9d
andl %edi, %r9d
movq 0x10(%rax), %r10
movl $0x1, %r11d
movl %r9d, %esi
movl %esi, %ecx
shrl $0x4, %ecx
movl (%r10,%rcx,4), %ebx
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %ebx, %ebp
shrl %cl, %ebp
testb $0x2, %bpl
jne 0x19aa2a
testb $0x1, %bpl
jne 0x19aa18
movq 0x18(%rax), %r14
movl %esi, %r15d
cmpl %edi, (%r14,%r15,4)
movq 0x40(%rsp), %r14
je 0x19aa2a
addl %r11d, %esi
andl %r8d, %esi
incl %r11d
cmpl %r9d, %esi
jne 0x19a9e7
movl %edx, %esi
jmp 0x19aa32
shrl %cl, %ebx
testb $0x3, %bl
cmovnel %edx, %esi
movq 0x28(%rsp), %rbp
jmp 0x19aa3b
xorl %esi, %esi
cmpl %edx, %esi
je 0x19ac03
movq 0x20(%rax), %rcx
movl %esi, %edx
movq (%rcx,%rdx,8), %rcx
testl %ecx, %ecx
jle 0x19abe5
shrq $0x20, %r13
movq %rcx, %rdx
sarq $0x20, %rdx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq 0x50(%rsp), %rax
leaq (%rax,%rdx,8), %rsi
addq 0x88(%rsp), %rdx
xorl %edi, %edi
movslq (%rsi,%rdi,8), %r8
leaq (%r8,%r8,2), %r8
shlq $0x4, %r8
movl 0xc(%r12,%r8), %r10d
testl %r10d, %r10d
js 0x19aacd
addq %r12, %r8
xorl %r9d, %r9d
movl 0x14(%r8), %r11d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %r11d
je 0x19aad5
movl 0x4(%r8), %ebx
testl %ebx, %ebx
js 0x19ab19
cmpl $0x40000000, %r10d      # imm = 0x40000000
jb 0x19aad9
cmpl %r13d, %ebx
jne 0x19aad9
movl 0x10(%r14), %ebp
cmpl 0x8(%r8), %ebp
jne 0x19aad9
movl $0x1, %r9d
xorl %ebx, %ebx
jmp 0x19ab12
movb $0x1, %r8b
jmp 0x19abc6
xorl %ebx, %ebx
jmp 0x19ab1b
movl 0x1c(%r8), %ebp
subl %ebx, %ebp
movl %ebp, %r14d
negl %r14d
cmovsl %ebp, %r14d
subl %r13d, %ebx
movl %ebx, %ebp
negl %ebp
cmovsl %ebx, %ebp
movl 0x20(%r8), %ebx
movl %ebx, %r15d
shrl $0x1f, %r15d
addl %ebx, %r15d
sarl %r15d
subl %r15d, %r14d
cmpl %r14d, %ebp
movq 0x40(%rsp), %r14
setge %bl
movq 0x28(%rsp), %rbp
jmp 0x19ab1b
movb $0x1, %bl
testb %bl, %bl
jne 0x19ab93
movl 0xc(%rsp), %eax
movl %eax, 0x18(%r8)
movl %r13d, 0x1c(%r8)
movl 0x10(%r14), %ebx
movl %ebx, 0x24(%r8)
movl $0x0, 0x20(%r8)
movl 0x14(%r14), %ebx
shll $0x1f, %ebx
orl %r11d, %ebx
movl %ebx, 0x14(%r8)
movl 0x4(%r8), %r11d
testl %r11d, %r11d
js 0x19ab93
cmpl $0x40000000, %r10d      # imm = 0x40000000
jb 0x19ab70
cmpl %r13d, %r11d
jne 0x19ab70
movl 0x10(%r14), %ebx
movl $0x1, %r10d
cmpl 0x8(%r8), %ebx
je 0x19ab96
leal 0x2710(%r11), %ebx
shrl $0x4, %r11d
cmpl %r13d, %r11d
movl %r9d, %r10d
movl $0x1, %eax
cmovll %eax, %r10d
cmpl %r13d, %ebx
cmovgel %r9d, %r10d
jmp 0x19ab96
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 0x6c(%rsp), %r11d
setge %r9b
testl %r10d, %r10d
setne %r8b
orb %r9b, %r8b
testb %r8b, %r8b
je 0x19abd9
cmpb $0x0, (%rdx,%rdi)
jne 0x19abd9
movb $0x1, (%rdx,%rdi)
incl 0x68(%rsp)
incq %rdi
cmpq %rdi, %rcx
jne 0x19aa79
movl $0x0, %ecx
movl 0x68(%rsp), %eax
cmpl 0x90(%rsp), %eax
movl $0xc, %eax
cmovel %eax, %ecx
je 0x19aee8
movq 0x28(%rbp), %rax
movl 0x8(%r14), %ecx
movq (%rax,%rcx,8), %rdx
xorl %ecx, %ecx
testl %edx, %edx
jle 0x19aee8
movq %rdx, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %rcx
shlq $0x3, %rcx
addq 0x8(%rbp), %rcx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %ebx, %ebx
movq %rdx, 0x78(%rsp)
movq %rcx, 0x70(%rsp)
leaq (%rbx,%rbx,2), %rax
movl 0x4(%r14), %r12d
addq (%rcx,%rax,8), %r12
movl $0x14, %r15d
cmpl 0xa0(%rsp), %r12d
jg 0x19aeca
leaq (%rcx,%rax,8), %r14
movl 0x8(%r14), %esi
movq 0x98(%rsp), %r15
movq %r15, %rdi
leaq 0x14(%rsp), %rdx
callq 0x19ba1b
movl %eax, %eax
movq %rax, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rax,8), %r13
addq 0x20(%r15), %r13
cmpl $0x0, 0x14(%rsp)
je 0x19aca3
movq $0x0, (%r13)
movq $-0x1, 0x8(%r13)
movl 0x6c(%rsp), %eax
cmpl %eax, (%r13)
jge 0x19ad87
movl 0x8(%r14), %ebp
movl $0x30, %esi
movq 0x18(%rsp), %rdi
callq 0x1e36fd
movq %rax, %r15
movl %ebp, 0x8(%rax)
shlq $0x20, %r12
movslq 0x10(%rsp), %rax
orq %r12, %rax
movq %rax, (%r15)
movl $0x1, 0x14(%r15)
movl 0xc(%rsp), %eax
movl %eax, 0xc(%r15)
movl 0x8(%r14), %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 0x40(%rsp), %r14
addl 0x10(%r14), %ecx
movl %ecx, 0x10(%r15)
movl 0x14(%r14), %eax
movl %eax, 0x14(%r15)
leaq 0x58(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x198259
movslq (%r13), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r13)
movq %r15, 0x10(%r13,%rax,8)
testq %rax, %rax
je 0x19ae44
movq (%r15), %rdx
movq 0x28(%rsp), %rbp
leaq -0x1(%rax), %rsi
movq %rsi, %rcx
shrq %rcx
movq 0x10(%r13,%rcx,8), %rdi
cmpq (%rdi), %rdx
jb 0x19ae4e
movq %rdi, 0x10(%r13,%rax,8)
movq %rcx, %rax
cmpq $0x1, %rsi
ja 0x19ad5c
jmp 0x19ae51
movq 0x10(%r13), %rsi
xorl %r15d, %r15d
cmpl %r12d, 0x4(%rsi)
jle 0x19aebb
leaq 0x58(%rsp), %rbp
movq %rbp, %rdi
xorl %edx, %edx
callq 0x19852a
testq %rax, %rax
je 0x19ae5f
leaq 0x10(%r13), %rcx
movq %rcx, 0xb0(%rsp)
shlq $0x20, %r12
movl 0x10(%rsp), %esi
movl %esi, %ecx
orq %r12, %rcx
movq %rcx, (%rax)
movl 0xc(%rsp), %ecx
movl %ecx, 0xc(%rax)
movl 0x8(%r14), %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 0x40(%rsp), %r14
addl 0x10(%r14), %edx
incl %esi
movl %esi, 0x10(%rsp)
movl %edx, 0x10(%rax)
movl 0x14(%r14), %ecx
movl %ecx, 0x14(%rax)
xorl %r15d, %r15d
movq %rbp, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x198259
movslq (%r13), %rsi
xorl %edi, %edi
movq 0xb0(%rsp), %rdx
callq 0x198a96
movq 0x28(%rsp), %rbp
jmp 0x19aec0
movq %rax, %rcx
movq 0x28(%rsp), %rbp
jmp 0x19ae51
movq %rax, %rcx
incl 0x10(%rsp)
movq %r15, 0x10(%r13,%rcx,8)
xorl %r15d, %r15d
jmp 0x19aec0
movq 0xef17a(%rip), %rax     # 0x289fe0
movq (%rax), %rdi
movl (%r13), %edx
movq 0x10(%r13), %rax
movq (%rax), %r8
movq %r8, %rcx
shrq $0x20, %rcx
subq $0x8, %rsp
leaq 0x98c75(%rip), %rsi     # 0x233afb
movl %r12d, %r9d
xorl %eax, %eax
pushq 0x50(%rsp)
pushq 0xb0(%rsp)
pushq 0x98(%rsp)
callq 0x22b0
addq $0x20, %rsp
movq 0x18(%rsp), %rdi
callq 0x1e35f4
movl $0x1, %r15d
movq 0x28(%rsp), %rbp
movq 0x40(%rsp), %r14
movq 0x78(%rsp), %rdx
movq 0x70(%rsp), %rcx
cmpl $0x14, %r15d
je 0x19aed5
testl %r15d, %r15d
jne 0x19aee5
incq %rbx
cmpq %rdx, %rbx
jne 0x19ac3e
xorl %ecx, %ecx
jmp 0x19aee8
movl %r15d, %ecx
incl 0xc(%rsp)
testl %ecx, %ecx
je 0x19a937
cmpl $0xc, %ecx
movq 0x30(%rsp), %rbx
movq 0x50(%rsp), %rsi
je 0x19af10
xorl %r12d, %r12d
jmp 0x19b241
movq 0x30(%rsp), %rbx
movq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x1e3632
movq %r14, %rdi
movq 0x88(%rsp), %rsi
callq 0x1e3632
movq 0x98(%rsp), %r15
testq %r15, %r15
je 0x19af6d
movq 0x18(%r15), %rsi
movq 0x28(%r15), %r14
movq %r14, %rdi
callq 0x1e3632
movq 0x10(%r15), %rsi
movq %r14, %rdi
callq 0x1e3632
movq 0x20(%r15), %rsi
movq %r14, %rdi
callq 0x1e3632
movq %r14, %rdi
movq %r15, %rsi
callq 0x1e3632
movq 0x48(%rsp), %rcx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rcx
xorl %edx, %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
xorl %eax, %eax
movl 0x14(%rbx,%rdx), %edi
andl %esi, %edi
cmpl $0x1, %edi
sbbl $-0x1, %eax
addq $0x30, %rdx
cmpq %rdx, %rcx
jne 0x19af8e
xorl %r12d, %r12d
cmpq $0x0, 0xf8(%rsp)
je 0x19b237
testl %eax, %eax
je 0x19b237
movl 0xc(%rsp), %r15d
movl $0x4, %edx
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x1e3590
movq 0x48(%rsp), %rdx
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
movq %rax, %r14
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rax
xorl %ecx, %ecx
movq 0x30(%rsp), %rsi
movq 0x20(%rsp), %rdi
testl $0x7fffffff, 0x14(%rsi,%rcx) # imm = 0x7FFFFFFF
je 0x19b025
cmpl $0x0, 0x4(%rsi,%rcx)
js 0x19b025
movslq 0x18(%rsi,%rcx), %rdx
testq %rdx, %rdx
js 0x19b025
movq (%rdi,%rdx,8), %rdx
movslq (%rdx), %rdx
movl $0x1, (%r14,%rdx,4)
addq $0x30, %rcx
cmpq %rcx, %rax
jne 0x19affb
cmpl $0x0, 0xc(%rsp)
je 0x19b120
leaq 0x4(%rsi), %rax
xorl %edx, %edx
movq 0x38(%rsp), %rcx
movl (%rcx), %esi
movl $0x0, %edi
testl %esi, %esi
je 0x19b0c4
movq 0x20(%rsp), %rcx
movq (%rcx,%rdx,8), %rcx
movl 0x8(%rcx), %r8d
leal -0x1(%rsi), %r9d
movl %r9d, %r10d
andl %r8d, %r10d
movq 0x38(%rsp), %rcx
movq 0x10(%rcx), %r11
movl $0x1, %ebx
movl %r10d, %edi
movl %edi, %ecx
shrl $0x4, %ecx
movl (%r11,%rcx,4), %ebp
leal (%rdi,%rdi), %ecx
andl $0x1e, %ecx
movl %ebp, %r12d
shrl %cl, %r12d
testb $0x2, %r12b
jne 0x19b0bb
testb $0x1, %r12b
jne 0x19b0ab
movq 0x38(%rsp), %r12
movq 0x18(%r12), %r12
movl %edi, %r13d
cmpl %r8d, (%r12,%r13,4)
je 0x19b0bb
addl %ebx, %edi
andl %r9d, %edi
incl %ebx
cmpl %r10d, %edi
jne 0x19b077
movl %esi, %edi
jmp 0x19b0c4
shrl %cl, %ebp
testb $0x3, %bpl
cmovnel %esi, %edi
cmpl %esi, %edi
je 0x19b114
movq 0x38(%rsp), %rcx
movq 0x20(%rcx), %rcx
movl %edi, %esi
movq (%rcx,%rsi,8), %rdi
testl %edi, %edi
jle 0x19b114
movq %rdi, %rcx
sarq $0x20, %rcx
movq %rdi, %rsi
shlq $0x20, %rsi
addq %rdi, %rsi
sarq $0x20, %rsi
leaq (%rcx,%rcx,2), %rdi
shlq $0x4, %rdi
addq %rax, %rdi
cmpl $0x0, (%rdi)
jns 0x19b108
movl $0x1, (%r14,%rdx,4)
incq %rcx
addq $0x30, %rdi
cmpq %rsi, %rcx
jl 0x19b0fb
incq %rdx
cmpq %r15, %rdx
jne 0x19b03f
movl 0xc(%rsp), %eax
decl %eax
movq 0x20(%rsp), %rdx
js 0x19b155
movl %eax, %eax
incq %rax
cmpl $0x0, -0x4(%r14,%rax,4)
je 0x19b150
movq -0x8(%rdx,%rax,8), %rcx
movslq 0xc(%rcx), %rcx
testq %rcx, %rcx
js 0x19b150
movl $0x1, (%r14,%rcx,4)
decq %rax
jg 0x19b132
cmpl $0x0, 0xc(%rsp)
je 0x19b188
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, %r15
jne 0x19b162
jmp 0x19b18a
xorl %eax, %eax
movq 0xf8(%rsp), %rcx
movl %eax, (%rcx)
cltq
shlq $0x2, %rax
leaq (%rax,%rax,2), %rsi
movq 0xa8(%rsp), %rdi
callq 0x1e36fd
movq %rax, %r12
cmpl $0x0, 0xc(%rsp)
movq 0x20(%rsp), %rdx
je 0x19b1fd
xorl %eax, %eax
movslq (%r14,%rax,4), %rcx
testq %rcx, %rcx
js 0x19b1f5
leaq (%rcx,%rcx,2), %rcx
movq (%rdx,%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 0x19b1e9
movl (%r14,%rdx,4), %edx
leaq (%r12,%rcx,4), %rcx
movl %edx, 0x8(%rcx)
movq 0x20(%rsp), %rdx
incq %rax
cmpq %rax, %r15
jne 0x19b1bc
movq 0x48(%rsp), %rcx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
movq 0x30(%rsp), %rsi
movslq 0x18(%rsi,%rcx), %rdx
testq %rdx, %rdx
js 0x19b22e
movl (%r14,%rdx,4), %edx
movl %edx, 0x18(%rsi,%rcx)
addq $0x30, %rcx
cmpq %rcx, %rax
jne 0x19b21c
movq 0x18(%rsp), %rdi
callq 0x1e35f4
movq %r12, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x98825(%rip), %rdi     # 0x233a82
leaq 0x98727(%rip), %rsi     # 0x23398b
leaq 0x9881e(%rip), %rcx     # 0x233a89
movl $0x453, %edx            # imm = 0x453
callq 0x2110