// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_bub_pop1_primary_trio(asg_t*, ma_ug_t*, unsigned int, unsigned long, buf_t*, unsigned int, unsigned int, unsigned int, unsigned long*, unsigned long*, hap_cov_t*, unsigned int, unsigned int, utg_trans_t*)
uint64_t asg_bub_pop1_primary_trio(asg_t *g, ma_ug_t *utg, uint32_t v0, uint64_t max_dist, buf_t *b, 
uint32_t positive_flag, uint32_t negative_flag, uint32_t is_pop, uint64_t* path_base_len, uint64_t* path_nodes, 
hap_cov_t *cov, uint32_t is_update_chain, uint32_t keep_d, utg_trans_t *o)
{   
	uint32_t i, n_pending = 0, is_first = 1, cur_m, cur_c, cur_np, cur_nc, to_replace, n_tips, tip_end;
	uint64_t n_pop = 0;
    long long cur_weight = -1, max_weight = -1;
	///if this node has been deleted
	if (g->seq[v0>>1].del || g->seq[v0>>1].c == ALTER_LABLE) return 0; // already deleted
	///if ((uint32_t)g->idx[v0] < 2) return 0; // no bubbles
    if(get_real_length(g, v0, NULL)<2) return 0;
	///S saves nodes with all incoming edges visited
	b->S.n = b->T.n = b->b.n = b->e.n = 0;
	///for each node, b->a saves all related information
	b->a[v0].c = b->a[v0].d = b->a[v0].m = b->a[v0].nc = b->a[v0].np = 0;
	///b->S is the nodes with all incoming edges visited
	kv_push(uint32_t, b->S, v0);
    n_tips = 0;
    tip_end = (uint32_t)-1;
    uint32_t non_positive_flag = (uint32_t)-1;
    if(positive_flag == FATHER) non_positive_flag = MOTHER;
    if(positive_flag == MOTHER) non_positive_flag = FATHER;

	do {
		///v is a node that all incoming edges have been visited
		///d is the distance from v0 to v
		uint32_t v = kv_pop(b->S), d = b->a[v].d, c = b->a[v].c, m = b->a[v].m, nc = b->a[v].nc, np = b->a[v].np;
		uint32_t nv = asg_arc_n(g, v);
		asg_arc_t *av = asg_arc_a(g, v);
		///why we have this assert?
		///assert(nv > 0);
		///all out-edges of v
		for (i = 0; i < nv; ++i) { // loop through v's neighbors
			/**
			p->ul: |____________31__________|__________1___________|______________32_____________|
								qn            direction of overlap       length of this node (not overlap length)
												(in the view of query)
			p->v : |___________31___________|__________1___________|
								tn             reverse direction of overlap
											(in the view of target)
			p->ol: overlap length
			**/
            ///if this edge has been deleted
			if (av[i].del) continue;
            
			uint32_t w = av[i].v, l = (uint32_t)av[i].ul; // v->w with length l
			binfo_t *t = &b->a[w];
			///that means there is a circle, directly terminate the whole bubble poping
			///if (w == v0) goto pop_reset;
            if ((w>>1) == (v0>>1)) {
                goto pop_reset;
            }
            /****************************may have bugs********************************/
            ///important when poping at long untig graph
            if(is_first && keep_d) l = 0;
            /****************************may have bugs********************************/

			

			///push the edge
            ///high 32-bit of g->idx[v] is the start point of v's edges
            //so here is the point of this specfic edge
			kv_push(uint32_t, b->e, (g->idx[v]>>32) + i);
			///find a too far path? directly terminate the whole bubble poping
			if (d + l > max_dist) break; // too far

            ///if this node
			if (t->s == 0) { // this vertex has never been visited
				kv_push(uint32_t, b->b, w); // save it for revert
				///t->p is the parent node of 
				///t->s = 1 means w has been visited
				///d is len(v0->v), l is len(v->w), so t->d is len(v0->w)
				t->p = v, t->s = 1, t->d = d + l;
                /****************************may have bugs********************************/
                cur_c = cur_m = cur_np = 0; cur_nc = 1;
                if(utg)
                {
                    cur_c = get_num_trio_flag(utg, w>>1, positive_flag);
                    cur_m = get_num_trio_flag(utg, w>>1, negative_flag);
                    cur_np = 0; 
                    if(non_positive_flag != (uint32_t)-1) 
                    {
                        cur_np = get_num_trio_flag(utg, w>>1, non_positive_flag);
                    }
                    cur_nc = utg->u.a[(w>>1)].n;
                }
                

                t->c = c + cur_c;
                t->m = m + cur_m;
                t->nc = nc + cur_nc;
                t->np = np + cur_np;
                /****************************may have bugs********************************/
				///incoming edges of w
				///t->r = count_out(g, w^1);
                t->r = get_real_length(g, w^1, NULL);
				++n_pending;
			} else { // visited before
                /****************************may have bugs********************************/
                cur_c = cur_m = cur_np = 0; cur_nc = 1;
                if(utg)
                {
                    cur_c = get_num_trio_flag(utg, w>>1, positive_flag);
                    cur_m = get_num_trio_flag(utg, w>>1, negative_flag);
                    cur_np = 0; 
                    if(non_positive_flag != (uint32_t)-1) 
                    {
                        cur_np = get_num_trio_flag(utg, w>>1, non_positive_flag);
                    }
                    cur_nc = utg->u.a[(w>>1)].n;
                }
                ///BUG: select the path with less negative_flag, less non_positive_flag, more positive_flag, more distance
                ///FIXED: select the path with less (negative_flag+non_positive_flag), more positive_flag, more distance
                to_replace = 0;

                /****************************may have bugs********************************/
                cur_weight = (long long)(c + cur_c) - ((long long)(m + cur_m) + (long long)(np + cur_np));
                max_weight = (long long)t->c - ((long long)t->m + (long long)t->np);
                if(cur_weight > max_weight)
                {
                    to_replace = 1;
                }
                else if(cur_weight == max_weight)
                {
                    if(nc + cur_nc > t->nc)
                    {
                        to_replace = 1;
                    }
                    else if(nc + cur_nc == t->nc)
                    {
                        if(d + l > t->d)
                        {
                            to_replace = 1;
                        }
                    }
                }
                /****************************may have bugs********************************/
                if(to_replace)
                {
                    t->p = v;
                    t->m = m + cur_m;
                    t->c = c + cur_c;
                    t->nc = nc + cur_nc;
                    t->np = np + cur_np;
                }
				///c is the weight (is very likely the number of node in this edge) of the parent node
				///select the longest edge (longest meams most reads/longest edge)
                // if (c + 1 > t->c || (c + 1 == t->c && d + l > t->d)) t->p = v;
				// if (c + 1 > t->c) t->c = c + 1;
                /****************************may have bugs********************************/
				///update len(v0->w)
                ///node: t->d is not the length from this node's parent
                ///it is the shortest edge
				if (d + l < t->d) t->d = d + l; // update dist
			}
			///assert(t->r > 0);
			//if all incoming edges of w have visited
			//push it to b->S
			if (--(t->r) == 0) {
                uint32_t x = get_real_length(g, w, NULL);
                /****************************may have bugs for bubble********************************/
                if(x > 0)
                {
                    kv_push(uint32_t, b->S, w);
                }
                else
                {
                    ///at most one tip
                    if(n_tips != 0) {
                        goto pop_reset;
                    }
                    n_tips++;
                    tip_end = w;
                }
                /****************************may have bugs for bubble********************************/
				--n_pending;
			}
		}
        is_first = 0;
        //if found a tip
        /****************************may have bugs for bubble********************************/
        if(n_tips == 1)
        {
            if(tip_end != (uint32_t)-1 && n_pending == 0 && b->S.n == 0)
            {
                kv_push(uint32_t, b->S, tip_end);
                break;
            }
            else
            {
                goto pop_reset;
            }
        }
        /****************************may have bugs for bubble********************************/
		///if i < nv, that means (d + l > max_dist)
		if (i < nv || b->S.n == 0) {
            goto pop_reset;
        }
	} while (b->S.n > 1 || n_pending);


    /****************************may have bugs********************************/
    ///if(keep_d != 0) debug_asg_bub_pop1_primary_trio(g, utg, v0, max_dist, b, positive_flag, negative_flag, 1);
    /****************************may have bugs********************************/
    if(cov && utg) asg_bub_backtrack_primary_cov(utg, v0, b, cov, is_update_chain);
    if(o && utg) asg_bub_collect_ovlp(utg, v0, b, o);
	if(is_pop) asg_bub_backtrack_primary(g, v0, b);
    if(path_base_len || path_nodes) asg_bub_backtrack_primary_length(g, utg, v0, b, path_base_len, path_nodes);

    n_pop = 1;
pop_reset:

    /****************************may have bugs********************************/
    ///if(!n_pop && keep_d != 0) debug_asg_bub_pop1_primary_trio(g, utg, v0, max_dist, b, positive_flag, negative_flag, 0);
    /****************************may have bugs********************************/

	for (i = 0; i < b->b.n; ++i) { // clear the states of visited vertices
		binfo_t *t = &b->a[b->b.a[i]];
		t->s = t->c = t->d = t->m = t->nc = t->np = 0;
	}
	return n_pop;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %r9d, 0x4c(%rsp)
movq %rcx, 0xb0(%rsp)
movl %edx, %ecx
movq %rdi, 0x40(%rsp)
movq 0x20(%rdi), %rax
shrl %edx
cmpl $0x0, (%rax,%rdx,8)
js 0x84abe
cmpb $0x1, 0x4(%rax,%rdx,8)
jne 0x84ad2
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r8, %r13
movq %rsi, %r14
movq %rdx, 0x58(%rsp)
movq 0x40(%rsp), %rdi
movl %ecx, %esi
xorl %edx, %edx
movl %ecx, %ebx
callq 0xc2e7a
cmpl $0x2, %eax
movl $0x0, %eax
jl 0x84ac0
andq $0x0, 0x50(%r13)
andq $0x0, 0x38(%r13)
andq $0x0, 0x20(%r13)
andq $0x0, 0x8(%r13)
movq (%r13), %rax
movl %ebx, 0xc(%rsp)
movl %ebx, %ecx
imulq $0x1c, %rcx, %rcx
xorps %xmm0, %xmm0
andl $0x0, 0x14(%rax,%rcx)
movups %xmm0, 0x4(%rax,%rcx)
xorl %eax, %eax
cmpq %rax, 0x10(%r13)
je 0x84b36
movq 0x18(%r13), %rax
xorl %ecx, %ecx
jmp 0x84b52
movq $0x2, 0x10(%r13)
movq 0x18(%r13), %rdi
pushq $0x8
popq %rsi
callq 0x2370
movq %rax, 0x18(%r13)
movq 0x8(%r13), %rcx
movq 0x58(%rsp), %rbx
movl 0x150(%rsp), %esi
movl 0xc(%rsp), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
xorl %eax, %eax
movl 0x4c(%rsp), %edx
cmpl $0x1, %edx
sete %al
leal (%rax,%rax,2), %eax
decl %eax
cmpl $0x2, %edx
pushq $0x1
popq %rdx
cmovel %edx, %eax
movl %eax, 0x64(%rsp)
movq $0x0, 0x50(%rsp)
movb $0x1, %al
pushq $-0x1
popq %rdx
movl %edx, 0x60(%rsp)
xorl %r12d, %r12d
movq %r13, 0x38(%rsp)
movq %r14, 0x10(%rsp)
testl %esi, %esi
setne %r8b
movq (%r13), %rdx
movq 0x18(%r13), %rsi
leaq -0x1(%rcx), %rdi
movq %rdi, 0x8(%r13)
movl -0x4(%rsi,%rcx,4), %esi
imulq $0x1c, %rsi, %rcx
movl 0x4(%rdx,%rcx), %edi
movl %edi, 0x8c(%rsp)
movl 0x8(%rdx,%rcx), %edi
movl %edi, 0x70(%rsp)
movl 0xc(%rdx,%rcx), %edi
movl %edi, 0x6c(%rsp)
movl 0x14(%rdx,%rcx), %edi
movl %edi, 0x48(%rsp)
movl 0x10(%rdx,%rcx), %ecx
movl %ecx, 0x68(%rsp)
movq 0x40(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq 0x28(%rdx), %rdx
movq %rsi, 0x80(%rsp)
movq (%rdx,%rsi,8), %rdx
movl %edx, %esi
movq %rsi, 0xb8(%rsp)
shrq $0x20, %rdx
andb %al, %r8b
movb %r8b, 0x1f(%rsp)
imulq $0x18, %rdx, %rax
addq %rcx, %rax
addq $0xc, %rax
xorl %r9d, %r9d
movl $0x0, 0x2c(%rsp)
cmpq %r9, 0xb8(%rsp)
je 0x84fdc
cmpl $0x0, (%rax)
js 0x84fd0
movl -0x4(%rax), %ebp
movl %ebp, %r15d
shrl %r15d
cmpl %ebx, %r15d
je 0x85040
xorl %r14d, %r14d
cmpb $0x0, 0x1f(%rsp)
jne 0x84c6a
movl -0xc(%rax), %r14d
movq %rax, 0x90(%rsp)
imulq $0x1c, %rbp, %rbx
addq (%r13), %rbx
movq 0x50(%r13), %rcx
movq 0x60(%r13), %rax
cmpq 0x58(%r13), %rcx
movq %r9, 0x20(%rsp)
jne 0x84cb8
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x58(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x20(%rsp), %r9
movq %rax, 0x60(%r13)
movq 0x50(%r13), %rcx
movq 0x40(%rsp), %rdx
movq 0x28(%rdx), %rdx
movq 0x80(%rsp), %rsi
movl 0x4(%rdx,%rsi,8), %edx
addl %r9d, %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x50(%r13)
movl %edx, (%rax,%rcx,4)
addl 0x8c(%rsp), %r14d
cmpq 0xb0(%rsp), %r14
ja 0x8500d
movl %r12d, 0x74(%rsp)
movl 0x18(%rbx), %r13d
testl %r13d, %r13d
js 0x84daf
movq 0x38(%rsp), %r12
movq 0x38(%r12), %rcx
movq 0x48(%r12), %rax
cmpq 0x40(%r12), %rcx
jne 0x84d42
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x40(%r12)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x48(%r12)
movq 0x38(%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x38(%r12)
movl %ebp, (%rax,%rcx,4)
orb $-0x80, 0x1b(%rbx)
movq 0x80(%rsp), %rax
movl %eax, (%rbx)
movl %r14d, 0x4(%rbx)
movq 0x10(%rsp), %r14
testq %r14, %r14
je 0x84e16
movq %r14, %rdi
movl %r15d, %esi
movl 0x4c(%rsp), %edx
callq 0x80f97
movl %eax, %r12d
movq %r14, %rdi
movl %r15d, %esi
movl 0x120(%rsp), %edx
callq 0x80f97
movl %eax, %r13d
movl 0x64(%rsp), %edx
cmpl $-0x1, %edx
je 0x84e23
movq %r14, %rdi
movl %r15d, %esi
callq 0x80f97
jmp 0x84e25
movq 0x10(%rsp), %r12
testq %r12, %r12
je 0x84e88
movq %r12, %rdi
movl %r15d, %esi
movl 0x4c(%rsp), %edx
callq 0x80f97
movq %rax, 0xa8(%rsp)
movq %r12, %rdi
movl %r15d, %esi
movl 0x120(%rsp), %edx
callq 0x80f97
movl %eax, %r11d
movl 0x64(%rsp), %edx
cmpl $-0x1, %edx
je 0x84e95
movq %r12, %rdi
movl %r15d, %esi
movq %r11, 0xa0(%rsp)
callq 0x80f97
movq 0xa0(%rsp), %r11
jmp 0x84e97
xorl %eax, %eax
pushq $0x1
popq %rcx
xorl %r12d, %r12d
xorl %r13d, %r13d
jmp 0x84e31
xorl %eax, %eax
movq 0x10(%r14), %rcx
imulq $0x28, %r15, %rdx
movl 0x10(%rcx,%rdx), %ecx
addl 0x70(%rsp), %r12d
movl %r12d, 0x8(%rbx)
addl 0x6c(%rsp), %r13d
movl %r13d, 0xc(%rbx)
addl 0x48(%rsp), %ecx
movl %ecx, 0x14(%rbx)
addl 0x68(%rsp), %eax
movl %eax, 0x10(%rbx)
movl %ebp, %esi
xorl $0x1, %esi
movq 0x40(%rsp), %rdi
xorl %edx, %edx
callq 0xc2e7a
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl 0x18(%rbx), %r13d
movl $0x80000000, %ecx       # imm = 0x80000000
andl %ecx, %r13d
orl %eax, %r13d
movl 0x74(%rsp), %r12d
incl %r12d
movq 0x20(%rsp), %r9
jmp 0x84f25
xorl %eax, %eax
pushq $0x1
popq %rcx
xorl %r10d, %r10d
xorl %r11d, %r11d
jmp 0x84eb4
xorl %eax, %eax
movq 0x10(%r12), %rcx
movl %r15d, %edx
imulq $0x28, %rdx, %rdx
movl 0x10(%rcx,%rdx), %ecx
movq 0x20(%rsp), %r9
movq 0xa8(%rsp), %r10
addl 0x70(%rsp), %r10d
addl 0x6c(%rsp), %r11d
addl 0x68(%rsp), %eax
movq %r10, %rsi
subq %rax, %rsi
subq %r11, %rsi
movl 0x8(%rbx), %edx
movl 0xc(%rbx), %edi
movl 0x10(%rbx), %r8d
addq %rdi, %r8
subq %r8, %rdx
cmpq %rdx, %rsi
movl 0x74(%rsp), %r12d
jle 0x84f03
addl 0x48(%rsp), %ecx
movq 0x80(%rsp), %rdx
movl %edx, (%rbx)
movl %r11d, 0xc(%rbx)
movl %r10d, 0x8(%rbx)
movl %ecx, 0x14(%rbx)
movl %eax, 0x10(%rbx)
jmp 0x84f16
jne 0x84f16
addl 0x48(%rsp), %ecx
cmpl 0x14(%rbx), %ecx
ja 0x84ee9
jne 0x84f16
cmpl 0x4(%rbx), %r14d
ja 0x84ee9
cmpl 0x4(%rbx), %r14d
jae 0x84f20
movl %r14d, 0x4(%rbx)
movq 0x10(%rsp), %r14
leal -0x1(%r13), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl $0x80000000, %r13d      # imm = 0x80000000
orl %eax, %r13d
movl %r13d, 0x18(%rbx)
testl %eax, %eax
je 0x84f4c
movq 0x38(%rsp), %r13
movq 0x58(%rsp), %rbx
jmp 0x84fc8
movq 0x40(%rsp), %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0xc2e7a
testl %eax, %eax
movq 0x38(%rsp), %r13
movq 0x58(%rsp), %rbx
je 0x84fae
movq 0x8(%r13), %rcx
movq 0x18(%r13), %rax
cmpq 0x10(%r13), %rcx
jne 0x84f9c
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x18(%r13)
movq 0x8(%r13), %rcx
movq 0x20(%rsp), %r9
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r13)
movl %ebp, (%rax,%rcx,4)
jmp 0x84fc5
movl %ebp, 0x60(%rsp)
cmpl $0x0, 0x2c(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x2c(%rsp)
movq 0x20(%rsp), %r9
jne 0x85040
decl %r12d
movq 0x90(%rsp), %rax
incq %r9
addq $0x18, %rax
jmp 0x84c33
cmpl $0x1, 0x2c(%rsp)
movl 0x150(%rsp), %esi
je 0x85019
movq 0x8(%r13), %rcx
testq %rcx, %rcx
je 0x85040
xorl %eax, %eax
cmpq $0x1, %rcx
jne 0x84ba5
testl %r12d, %r12d
jne 0x84ba5
jmp 0x850ae
cmpl $0x1, 0x2c(%rsp)
movq 0x10(%rsp), %r14
jne 0x85037
movq $0x0, 0x50(%rsp)
movl 0x60(%rsp), %ebx
cmpl $-0x1, %ebx
je 0x85040
testl %r12d, %r12d
jne 0x85040
cmpq $0x0, 0x8(%r13)
je 0x85079
movq $0x0, 0x50(%rsp)
xorl %eax, %eax
xorps %xmm0, %xmm0
movl %eax, %eax
cmpq %rax, 0x38(%r13)
jbe 0x8506f
movq (%r13), %rcx
movq 0x48(%r13), %rdx
movl (%rdx,%rax,4), %edx
imulq $0x1c, %rdx, %rdx
movups %xmm0, 0x4(%rcx,%rdx)
andl $0x0, 0x14(%rcx,%rdx)
andb $0x7f, 0x1b(%rcx,%rdx)
incl %eax
jmp 0x85045
movq 0x50(%rsp), %rax
jmp 0x84ac0
cmpq $0x0, 0x10(%r13)
movq 0x18(%r13), %rax
je 0x85088
xorl %ecx, %ecx
jmp 0x850a3
movq $0x2, 0x10(%r13)
pushq $0x8
popq %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x18(%r13)
movq 0x8(%r13), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r13)
movl %ebx, (%rax,%rcx,4)
movq 0x140(%rsp), %rdx
testq %rdx, %rdx
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x85744
xorl %eax, %eax
cmpl $0x0, 0x148(%rsp)
je 0x850df
movq 0xa8(%rdx), %rbp
jmp 0x850e1
xorl %ebp, %ebp
movq 0x38(%r13), %rcx
xorl %edx, %edx
movq 0x10(%rsp), %r14
movl %edx, %edx
cmpq %rdx, %rcx
jbe 0x8514a
movq 0x18(%r13), %rdi
movq 0x48(%r13), %rsi
movl (%rsi,%rdx,4), %esi
shrl %esi
movl (%rdi), %edi
shrl %edi
cmpl %edi, %esi
je 0x85146
movq 0x10(%r14), %rdi
imulq $0x28, %rsi, %r8
movl 0x10(%rdi,%r8), %esi
testq %rsi, %rsi
je 0x85146
addq %r8, %rdi
movq 0x18(%rdi), %rdi
movq 0x140(%rsp), %r8
movq 0x8(%r8), %r8
xorl %r9d, %r9d
cmpq %r9, %rsi
je 0x85146
movq (%rdi,%r9,8), %r10
shrq $0x21, %r10
addl (%r8,%r10,4), %eax
incq %r9
jmp 0x85130
incl %edx
jmp 0x850ec
movq (%r13), %rcx
movq 0x18(%r13), %rsi
movl (%rsi), %edi
xorl %r8d, %r8d
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %edi, %r11d
movl %r11d, %r9d
imulq $0x1c, %r9, %r9
movl (%rcx,%r9), %r9d
cmpl %edi, %r11d
je 0x851cd
movl %r11d, %r10d
shrl %r10d
movq 0x10(%r14), %rbx
imulq $0x28, %r10, %r14
movl 0x10(%rbx,%r14), %r10d
testq %r10, %r10
je 0x851c5
addq %r14, %rbx
movq 0x18(%rbx), %r11
movq 0x140(%rsp), %r14
movq 0x8(%r14), %rbx
movq 0x30(%r14), %r14
movq 0x20(%r14), %r14
xorl %r15d, %r15d
cmpq %r15, %r10
je 0x851c8
movq (%r11,%r15,8), %r12
shrq $0x21, %r12
subl (%rbx,%r12,4), %eax
movl (%r14,%r12,8), %r12d
andl %edx, %r12d
addl %r12d, %r8d
incq %r15
jmp 0x851a5
movl %r11d, %r9d
movq 0x10(%rsp), %r14
movl %r9d, %r11d
cmpl 0xc(%rsp), %r9d
jne 0x8515f
testl %r8d, %r8d
je 0x851e3
xorl %edx, %edx
divl %r8d
jmp 0x851e5
xorl %eax, %eax
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %edi, %r8d
imulq $0x1c, %r8, %r8
movl (%rcx,%r8), %r8d
cmpl (%rsi), %edi
jne 0x85204
movl %r8d, %edi
cmpl 0xc(%rsp), %edi
jne 0x851ea
jmp 0x8525f
movl %edi, %r10d
shrl %r10d
movq 0x10(%r14), %r9
imulq $0x28, %r10, %r11
movl 0x10(%r9,%r11), %r10d
testl %r10d, %r10d
je 0x851fc
addq %r11, %r9
xorl %edi, %edi
movl %r10d, %r10d
cmpq %r10, %rdi
jae 0x851f9
movq 0x18(%r9), %r10
movq (%r10,%rdi,8), %r10
shrq $0x21, %r10
movq 0x140(%rsp), %rbx
movq 0x8(%rbx), %r11
movq 0x30(%rbx), %rbx
movq 0x20(%rbx), %rbx
movl (%rbx,%r10,8), %ebx
andl %edx, %ebx
imull %eax, %ebx
addl %ebx, (%r11,%r10,4)
incq %rdi
movl 0x10(%r9), %r10d
jmp 0x85221
testq %rbp, %rbp
je 0x85744
movq 0x10(%rsp), %rbx
movq 0x18(%rbx), %rdi
movl 0xc(%rsp), %esi
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x2, %eax
jne 0x854cc
movq 0x18(%rbx), %rdi
movq 0x18(%r13), %rax
movl (%rax), %esi
xorl $0x1, %esi
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x2, %eax
jne 0x854cc
movq 0x18(%rbx), %rdi
leaq 0x78(%rsp), %r15
movl 0xc(%rsp), %esi
movq %r15, %rdx
callq 0xc2e7a
movl (%r15), %edx
movl %edx, %ecx
shrl %ecx
movq 0x18(%r13), %rax
movl (%rax), %eax
shrl %eax
cmpl %eax, %ecx
je 0x854c2
movl 0x7c(%rsp), %ecx
shrl %ecx
cmpl %eax, %ecx
je 0x854c2
movq 0x10(%rsp), %r13
movq 0x18(%r13), %rdi
subq $0x20, %rsp
pushq $0x1
popq %r15
movl %r15d, 0x10(%rsp)
leaq 0xf8(%rsp), %rbx
movq %rbx, 0x8(%rsp)
leaq 0x100(%rsp), %r14
movq %r14, (%rsp)
andq $0x0, 0x18(%rsp)
leaq 0x50(%rsp), %rcx
leaq 0xe0(%rsp), %r8
leaq 0xb8(%rsp), %r12
xorl %esi, %esi
movq %r12, %r9
callq 0xc2ebf
addq $0x20, %rsp
movq 0x18(%r13), %rdi
movl 0x7c(%rsp), %edx
leaq 0x34(%rsp), %rcx
leaq 0xc8(%rsp), %r13
xorl %esi, %esi
movq %r13, %r8
movq %r12, %r9
pushq $0x0
pushq %r15
pushq %rbx
pushq %r14
callq 0xc2ebf
addq $0x20, %rsp
movq -0x8(%r13), %rax
movq (%r13), %rcx
addq %rcx, %rax
incq %rax
movq 0x38(%rsp), %rcx
movl 0x38(%rcx), %ecx
cmpq %rcx, %rax
jne 0x854c2
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
movl 0x30(%rsp), %esi
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x1, %eax
jne 0x854c2
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
movl 0x34(%rsp), %esi
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x1, %eax
jne 0x854c2
movq 0x10(%rsp), %r15
movq 0x18(%r15), %rdi
leaq 0x30(%rsp), %r12
movl (%r12), %esi
movq %r12, %rdx
callq 0xc2e7a
movq 0x18(%r15), %rdi
movl 0x4(%r12), %esi
leaq 0x34(%rsp), %rdx
callq 0xc2e7a
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
cmpl %eax, (%r12)
jne 0x854c2
cmpl %eax, 0x34(%rsp)
jne 0x854c2
andq $0x0, 0xa0(%rbp)
leaq 0x68(%rbp), %r10
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
movl 0x78(%rsp), %edx
xorl %r12d, %r12d
leaq 0x30(%rsp), %rcx
leaq 0xc0(%rsp), %r8
leaq 0x98(%rsp), %r9
xorl %esi, %esi
movq %r10, 0x20(%rsp)
pushq %r10
pushq $0x1
pushq %rbx
pushq %r14
callq 0xc2ebf
addq $0x20, %rsp
pushq $-0x1
popq %rax
movl %r12d, %r12d
cmpq %r12, 0xa0(%rbp)
jbe 0x85668
movq 0xb0(%rbp), %rcx
movl (%rcx,%r12,4), %ecx
movl %ecx, %esi
shrl %esi
movq 0x10(%rsp), %rdx
movq 0x10(%rdx), %rdx
imulq $0x28, %rsi, %rdi
movl 0x10(%rdx,%rdi), %esi
testl %esi, %esi
je 0x854bd
addq %rdi, %rdx
movl %eax, %edi
xorl %r8d, %r8d
movl %esi, %r9d
cmpq %r9, %r8
jae 0x854bd
addl %edi, %esi
testb $0x1, %cl
movq 0x10(%rbp), %r9
movq 0x18(%rdx), %r10
cmoveq %r8, %rsi
movq (%r10,%rsi,8), %rsi
shrq $0x21, %rsi
orb $0x2, (%r9,%rsi)
incq %r8
movl 0x10(%rdx), %esi
decl %edi
jmp 0x8548d
incl %r12d
jmp 0x85451
movq 0x38(%rsp), %r13
movq 0x10(%rsp), %rbx
movq 0x18(%rbx), %rdi
movq 0x18(%r13), %rax
movl (%rax), %ecx
movq 0x140(%rsp), %rbx
movq %rbx, %rsi
movl 0xc(%rsp), %edx
callq 0xa4f42
movq 0xa8(%rbx), %rax
movq 0x50(%rax), %rcx
testq %rcx, %rcx
je 0x85744
leaq 0x68(%rbp), %rdx
movq %rdx, 0x20(%rsp)
xorl %ebx, %ebx
pushq $-0x1
popq %r14
movq 0x10(%rsp), %r12
movl %ebx, %ebx
cmpq %rbx, %rcx
jbe 0x85744
movq 0x60(%rax), %rcx
movl (%rcx,%rbx,4), %edx
shrl %edx
movq 0x18(%r13), %rcx
movl (%rcx), %r8d
shrl %r8d
cmpl %r8d, %edx
je 0x8565d
movq 0x18(%r12), %rdi
movq 0x140(%rsp), %r15
movq %r15, %rsi
movq 0x58(%rsp), %rcx
callq 0xa48ee
movq 0xa8(%r15), %rax
cmpq $0x0, 0xa0(%rax)
je 0x8565d
movq 0x60(%rax), %rax
movl (%rax,%rbx,4), %edi
movq 0x20(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0xa54c1
movq 0xa8(%r15), %rax
movq 0x60(%rax), %rcx
movl (%rcx,%rbx,4), %ecx
movl %ecx, %esi
shrl %esi
movq 0x10(%r12), %rdx
imulq $0x28, %rsi, %rdi
movl 0x10(%rdx,%rdi), %esi
testl %esi, %esi
je 0x8565d
addq %rdi, %rdx
movl %r14d, %eax
xorl %edi, %edi
movl %esi, %r8d
cmpq %r8, %rdi
jae 0x855e1
addl %eax, %esi
testb $0x1, %cl
movq 0x10(%rbp), %r8
movq 0x18(%rdx), %r9
cmoveq %rdi, %rsi
movq (%r9,%rsi,8), %rsi
shrq $0x21, %rsi
orb $0x2, (%r8,%rsi)
incq %rdi
movl 0x10(%rdx), %esi
decl %eax
jmp 0x855b1
xorl %eax, %eax
movl %eax, %eax
cmpq %rax, 0xa0(%rbp)
jbe 0x8564e
movq 0xb0(%rbp), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, %esi
shrl %esi
movq 0x10(%rsp), %rdx
movq 0x10(%rdx), %rdx
imulq $0x28, %rsi, %rdi
movl 0x10(%rdx,%rdi), %esi
testl %esi, %esi
je 0x8564a
addq %rdi, %rdx
movl %r14d, %edi
xorl %r8d, %r8d
movl %esi, %r9d
cmpq %r9, %r8
jae 0x8564a
addl %edi, %esi
testb $0x1, %cl
movq 0x10(%rbp), %r9
movq 0x18(%rdx), %r10
cmoveq %r8, %rsi
movq (%r10,%rsi,8), %rsi
shrq $0x21, %rsi
orb $0x2, (%r9,%rsi)
incq %r8
movl 0x10(%rdx), %esi
decl %edi
jmp 0x8561a
incl %eax
jmp 0x855e3
movq 0x140(%rsp), %rax
movq 0xa8(%rax), %rax
incl %ebx
movq 0x50(%rax), %rcx
jmp 0x85512
andq $0x0, 0x108(%rbp)
leaq 0xd0(%rbp), %r10
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
movl 0x7c(%rsp), %edx
xorl %r12d, %r12d
leaq 0x98(%rsp), %r9
xorl %esi, %esi
leaq 0x34(%rsp), %rcx
movq %r13, %r8
movq %r10, %r15
pushq %r10
pushq $0x1
pushq %rbx
pushq %r14
movq %rax, %rbx
callq 0xc2ebf
addq $0x20, %rsp
pushq $-0x1
popq %rax
movl %r12d, %r12d
cmpq %r12, 0x108(%rbp)
jbe 0x8571a
movq 0x118(%rbp), %rcx
movl (%rcx,%r12,4), %ecx
movl %ecx, %esi
shrl %esi
movq 0x10(%rbx), %rdx
imulq $0x28, %rsi, %rdi
movl 0x10(%rdx,%rdi), %esi
testl %esi, %esi
je 0x85715
addq %rdi, %rdx
movl %eax, %edi
xorl %r8d, %r8d
movl %esi, %r9d
cmpq %r9, %r8
jae 0x85715
addl %edi, %esi
testb $0x1, %cl
movq 0x10(%rbp), %r9
movq 0x18(%rdx), %r10
cmoveq %r8, %rsi
movq (%r10,%rsi,8), %rsi
shrq $0x21, %rsi
orb $0x2, (%r9,%rsi)
incq %r8
movl 0x10(%rdx), %esi
decl %edi
jmp 0x856e5
incl %r12d
jmp 0x856b2
movq 0x38(%rsp), %r13
movq 0x18(%r13), %rax
movl (%rax), %ecx
xorl $0x1, %ecx
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movl 0xc(%rsp), %edx
movq %rbx, %r8
movq 0x140(%rsp), %r9
callq 0xa51ea
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
sete %al
movq 0x158(%rsp), %rcx
testq %rcx, %rcx
sete %dl
orb %al, %dl
jne 0x85770
movq %rbx, %rdi
movl 0xc(%rsp), %esi
movq %r13, %rdx
callq 0x15191a
cmpl $0x0, 0x128(%rsp)
movl 0xc(%rsp), %edx
movq 0x138(%rsp), %r14
je 0x85799
movq 0x40(%rsp), %rdi
movl %edx, %esi
movq %r13, %rdx
callq 0xa55fa
movl 0xc(%rsp), %edx
pushq $0x1
popq %rax
movq %rax, 0x50(%rsp)
movq 0x130(%rsp), %rcx
movq %rcx, %rax
orq %r14, %rax
je 0x85040
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq %rcx, %r8
movq %r13, %rcx
movq %r14, %r9
callq 0xa572a
jmp 0x85040