// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: if_sup_chimeric(ma_hit_t_alloc*, unsigned long, asg64_v*, int)
int32_t if_sup_chimeric(ma_hit_t_alloc* src, uint64_t rLen, asg64_v *b, int if_exact)
{
    uint32_t k, qs, qe, l[2], r[2], st, bn;
    int32_t dp, op;
    l[0] = r[0] = rLen; l[1] = r[1] = 0;
    for (k = 0; k < src->length; k++){
        if(src->buffer[k].del) continue;
        if(if_exact && !(src->buffer[k].el)) continue;

        qs = Get_qs(src->buffer[k]); qe = Get_qe(src->buffer[k]);

        ///overlaps from left side
        if(qs == 0){
            if(qs < l[0]) l[0] = qs;
            if(qe > l[1]) l[1] = qe;
        }

        ///overlaps from right side
        if(qe == rLen){
            if(qs < r[0]) r[0] = qs;
            if(qe > r[1]) r[1] = qe;
        }

        ///note: if (qs == 0 && qe == rLen)
        ///this overlap would be added to both b_left and b_right
        ///that is what we want
    }
    if (l[1] > r[0]) return 0;
    if (l[1] <= l[0] || r[1] <= r[0]) return 1;

    bn = b->n;
    if(l[1] > l[0]) {
        kv_push(uint64_t, *b, (l[0]<<1)); kv_push(uint64_t, *b, (l[1]<<1)|1);
    }
    if(r[1] > r[0]) {
        kv_push(uint64_t, *b, (r[0]<<1)); kv_push(uint64_t, *b, (r[1]<<1)|1);
    }

    ///check contained overlaps
    for (k = 0; k < src->length; k++) {
        if(src->buffer[k].del) continue;
        if(if_exact && !(src->buffer[k].el)) continue;

        qs = Get_qs(src->buffer[k]); qe = Get_qe(src->buffer[k]);
        if(qs == 0 || qe == rLen) continue;

        kv_push(uint64_t, *b, (qs<<1)); kv_push(uint64_t, *b, (qe<<1)|1);
    }
    radix_sort_srt64(b->a + bn, b->a + b->n);
    l[0] = r[0] = rLen; l[1] = r[1] = 0;

    for (k = bn, dp = st = 0; k < b->n; k++) {
        op = dp;
        ///if a[j] is qe
        if (b->a[k]&1) --dp;
        else ++dp;

        if(op < 1 && dp >= 1) {
            st = b->a[k]>>1;
        } else if(op >= 1 && dp < 1) {
            if(st == 0) l[0] = st, l[1] = b->a[k]>>1;
            if((b->a[k]>>1) == rLen) r[0] = st, r[1] = b->a[k]>>1;
        }
    }
    
    b->n = bn;
    if (l[1] > r[0]) return 0;

    return 1;
}

///remove single node
void asg_arc_cut_chimeric(asg_t *g, ma_hit_t_alloc* src, asg64_v *in, uint32_t ou_thres, telo_end_t *te)
{
	asg64_v tx = {0,0,0}, *b = NULL;
	uint32_t v, w, ei[2] = {0}, k, i, n_vtx = g->n_seq<<1;
    uint32_t nw, el_n, cnt = 0; asg_arc_t *aw;
	if(in) b = in;
    else b = &tx;
	b->n = 0;

	for (v = 0; v < n_vtx; ++v) {
        if (g->seq[v>>1].del) continue;
        if (te && te->hh[v>>1]) continue;
		if(g->seq_vis[v] == 0) {
            if((get_arcs(g, v, &(ei[0]), 1)!=1) || (get_arcs(g, v^1, &(ei[1]), 1)!=1)) continue;
            assert((g->arc[ei[0]].ul>>32) == v && (g->arc[ei[1]].ul>>32) == (v^1));
            if((get_arcs(g, g->arc[ei[0]].v^1, NULL, 0)<2) || (get_arcs(g, g->arc[ei[1]].v^1, NULL, 0)<2)) continue;
            if(g->arc[ei[0]].el) continue;       
            if(ou_thres!=(uint32_t)-1&&g->arc[ei[0]].ou>=ou_thres&&g->arc[ei[1]].ou>=ou_thres) continue;///UL
            if(!if_sup_chimeric(&(src[v>>1]), g->seq[v>>1].len, b, 1)) continue;///HiFi
            kv_push(uint64_t, *b, (((uint64_t)(g->arc[ei[0]].ol))<<32)|((uint64_t)(ei[0])));
        }
	}

    radix_sort_srt64(b->a, b->a + b->n);
    ///here all edges are inexact matches 
    for (k = 0; k < b->n; k++) {
        if(g->arc[(uint32_t)b->a[k]].del) continue;
        v = g->arc[(uint32_t)b->a[k]].ul>>32; w = g->arc[(uint32_t)b->a[k]].v^1;
        if(g->seq[v>>1].del || g->seq[w>>1].del) continue;
        aw = asg_arc_a(g, w); nw = asg_arc_n(g, w);
        if((get_arcs(g, v, &(ei[0]), 1)!=1) || (get_arcs(g, v^1, &(ei[1]), 1)!=1)) continue;
        if((get_arcs(g, g->arc[ei[0]].v^1, NULL, 0)<2) || (get_arcs(g, g->arc[ei[1]].v^1, NULL, 0)<2)) continue;

        for (i = el_n = 0; i < nw; i++) {
            if ((aw[i].del) || (aw[i].v==(v^1)) || (!aw[i].el)) continue;
            el_n++; break;
        }

        if(!el_n) continue;
        if(te && te->hh[v>>1]) continue;
        asg_seq_del(g, v>>1);
        cnt++;
    }
    // stats_sysm(g);
	if(!in) free(tx.a);
    if (cnt > 0) asg_cleanup(g);
}

void asg_arc_cut_inexact(asg_t *g, ma_hit_t_alloc* src, asg64_v *in, int32_t max_ext, uint32_t is_ou, uint32_t is_trio, uint32_t min_diff, float ou_rat/**, asg64_v *dbg**/)
{
    asg64_v tx = {0,0,0}, *b = NULL;
    uint32_t v, w, i, k, n_vtx = g->n_seq<<1;
    asg_arc_t *av, *aw, *ve, *vmax, *we; uint32_t nv, nw, kv, kw, ol_max, ou_max, to_del, cnt = 0, mm_ol, mm_ou;
    uint32_t trioF = (uint32_t)-1, ntrioF = (uint32_t)-1;
    if(in) b = in;
    else b = &tx;
	b->n = 0;

    for (v = 0; v < n_vtx; ++v) {
        if(g->seq[v>>1].del) continue;
        if(g->seq_vis[v] == 0) {
            av = asg_arc_a(g, v); nv = asg_arc_n(g, v);
            if (nv < 2) continue;

            for (i = kv = 0; i < nv; ++i) {
                if(av[i].del) continue;
                kv++;
            }
            if(kv < 2) continue;

            for (i = 0; i < nv; ++i) {
                if(av[i].del || av[i].el) continue;
                kv_push(uint64_t, *b, (uint64_t)((((uint64_t)av[i].ol)<<32)|((uint64_t)(av-g->arc+i))));   
            }
        }
	}

    radix_sort_srt64(b->a, b->a + b->n);
	for (k = 0; k < b->n; k++) {
        if(g->arc[(uint32_t)b->a[k]].del) continue;
        assert((!g->arc[(uint32_t)b->a[k]].el));

        v = g->arc[(uint32_t)b->a[k]].ul>>32; w = g->arc[(uint32_t)b->a[k]].v^1;
        if(g->seq[v>>1].del || g->seq[w>>1].del) continue;
        nv = asg_arc_n(g, v); nw = asg_arc_n(g, w);
        av = asg_arc_a(g, v); aw = asg_arc_a(g, w);
        // if(((v>>1) == 50356 && (w>>1) == 1276292)||((v>>1) == 1276292 && (w>>1) == 50356)) {
        //     fprintf(stderr, "[0]v->%u, w->%u, nv->%u, nw->%u\n", v, w, nv, nw);
        // }
        if(nv<=1 && nw <= 1) continue;
        if(is_trio) {
            if(get_arcs(g, v, NULL, 0)<=1 && get_arcs(g, w, NULL, 0)<=1) continue;///speedup
            trioF = get_tip_trio_infor(g, v^1);
            ntrioF = (trioF==FATHER? MOTHER : (trioF==MOTHER? FATHER : (uint32_t)-1));
        }
        ve = &(g->arc[(uint32_t)b->a[k]]);
		for (i = 0; i < nw; ++i) {
			if (aw[i].v == (v^1)) {
                we = &(aw[i]);
                break;
            }
        }
        ///mm_ol and mm_ou are used to make edge with long indel more easy to be cutted
        mm_ol = MIN(ve->ol, we->ol); mm_ou = MIN(ve->ou, we->ou);
        for (i = kv = ol_max = ou_max = 0, vmax = NULL; i < nv; ++i) {
            if(av[i].del) continue;
            kv++;
            if(is_trio && get_tip_trio_infor(g, av[i].v) == ntrioF) continue;
            if(ol_max < av[i].ol) ol_max = av[i].ol, vmax = &(av[i]);
            if(ou_max < av[i].ou) ou_max = av[i].ou;
        }
        // if(((v>>1) == 50356 && (w>>1) == 1276292)||((v>>1) == 1276292 && (w>>1) == 50356)) {
        //     fprintf(stderr, "[1]v->%u, w->%u, kv->%u, ve->ol->%u, ol_max->%u\n", v, w, kv, ve->ol, ol_max);
        // }
        if (kv < 1) continue;
        if (kv >= 2) {
            if (mm_ol >= ol_max) continue;
            if (is_ou && mm_ou > ou_max*ou_rat) continue;
            if ((mm_ol + min_diff) > ol_max) continue;
        }
        
        for (i = kw = ol_max = ou_max = 0; i < nw; ++i) {
            if(aw[i].del) continue;
            kw++;
            if(is_trio && get_tip_trio_infor(g, aw[i].v) == ntrioF) continue;
            if(ol_max < aw[i].ol) ol_max = aw[i].ol;
            if(ou_max < aw[i].ou) ou_max = aw[i].ou;
        }
        // if(((v>>1) == 50356 && (w>>1) == 1276292)||((v>>1) == 1276292 && (w>>1) == 50356)) {
        //     fprintf(stderr, "[1]v->%u, w->%u, kw->%u, we->ol->%u, ol_max->%u\n", v, w, kw, we->ol, ol_max);
        // }
        if (kw < 1) continue;
        if (kw >= 2) {
            if (mm_ol >= ol_max) continue;
            if (is_ou && mm_ou > ou_max*ou_rat) continue;
            if ((mm_ol + min_diff) > ol_max) continue;
        }
        if (kv <= 1 && kw <= 1) continue;

        to_del = 0;
        ///if there is an inexact edge between two good reads
        if(src[v>>1].is_fully_corrected == 1 && src[w>>1].is_fully_corrected == 1) {
            if (kv > 1 && kw > 1) {
				to_del = 1;
            } else if (kw == 1) {
                if (asg_topocut_aux(g, w^1, max_ext) < max_ext) to_del = 1;
            } else if (kv == 1) {
                if (asg_topocut_aux(g, v^1, max_ext) < max_ext) to_del = 1;
            }
        }
        ///TODO: should check if the edge wmax also works
        if(src[v>>1].is_fully_corrected == 1 && src[w>>1].is_fully_corrected == 0) {
            if(vmax && vmax->v != ve->v && vmax->el == 1 && src[vmax->v>>1].is_fully_corrected == 1) {
                if (kv > 1 && kw > 1) {
                    to_del = 1;
                } else if (kw == 1) {
                    if (asg_topocut_aux(g, w^1, max_ext) < max_ext) to_del = 1;
                } else if (kv == 1) {
                    if (asg_topocut_aux(g, v^1, max_ext) < max_ext) to_del = 1;
                }
            }
        }

        // if(((v>>1) == 50356 && (w>>1) == 1276292)||((v>>1) == 1276292 && (w>>1) == 50356)) {
        //     fprintf(stderr, "[3]v->%u, w->%u, to_del->%u, el->%u, src[v>>1].is_fully_corrected->%u, src[w>>1].is_fully_corrected->%u\n", 
        //             v, w, to_del, g->arc[(uint32_t)b->a[k]].el, src[v>>1].is_fully_corrected, src[w>>1].is_fully_corrected);
        //     fprintf(stderr, "[4]v->%u, w->%u, to_del->%u, vmax->v->%u, vmax->el->%u, src[vmax->v>>1].is_fully_corrected->%u\n", 
        //             v, w, to_del, vmax->v, vmax->el, src[vmax->v>>1].is_fully_corrected);
        // }

        if (to_del) {
            ve->del = we->del = 1, ++cnt;
            /**
            if(dbg) {
                kv_push(uint64_t, *dbg, ve - g->arc); 
                kv_push(uint64_t, *dbg, we - g->arc); 
                // if(((v>>1) == 50356 && (w>>1) == 1276292)||((v>>1) == 1276292 && (w>>1) == 50356)) {
                //     fprintf(stderr, "[5]v->%u, w->%u, (ve - g->arc)->%u, (we - g->arc)->%u\n", 
                //     v, w, (uint32_t)(ve - g->arc), (uint32_t)(we - g->arc));
                // }
            }
            **/
        }
        
    }
    // stats_sysm(g);
    if(!in) free(tx.a);
    if (cnt > 0) asg_cleanup(g);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x18(%rbp), %rax
movl %eax, -0x40(%rbp)
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x311354
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
je 0x3112ac
jmp 0x311346
cmpl $0x0, -0x24(%rbp)
je 0x3112cb
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x20(%rax)
jne 0x3112cb
jmp 0x311346
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x31131d
movl -0x2c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x31130d
movl -0x2c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jbe 0x31131b
movl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x31131d
movl -0x30(%rbp), %eax
cmpq -0x18(%rbp), %rax
jne 0x311344
movl -0x2c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0x311334
movl -0x2c(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jbe 0x311342
movl -0x30(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x311344
jmp 0x311346
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x311279
movl -0x34(%rbp), %eax
cmpl -0x40(%rbp), %eax
jbe 0x311368
movl $0x0, -0x4(%rbp)
jmp 0x311918
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jbe 0x311378
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
ja 0x311384
movl $0x1, -0x4(%rbp)
jmp 0x311918
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x48(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jbe 0x3114bf
jmp 0x31139c
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x311404
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3113c9
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x58(%rbp)
jmp 0x3113d4
movl $0x2, %eax
movq %rax, -0x58(%rbp)
jmp 0x3113d4
movq -0x58(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x38(%rbp), %eax
shll %eax
movl %eax, %eax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x31142c
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x311494
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x311459
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0x311464
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0x311464
movq -0x60(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x34(%rbp), %eax
shll %eax
orl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x3114bf
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jbe 0x3115f0
jmp 0x3114cd
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x311535
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3114fa
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x311505
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x311505
movq -0x68(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x40(%rbp), %eax
shll %eax
movl %eax, %eax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x31155d
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x3115c5
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x31158a
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x311595
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0x311595
movq -0x70(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x3c(%rbp), %eax
shll %eax
orl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x3115f0
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x3117c1
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
je 0x31162a
jmp 0x3117b3
cmpl $0x0, -0x24(%rbp)
je 0x31164c
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x20(%rax)
jne 0x31164c
jmp 0x3117b3
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x311689
movl -0x30(%rbp), %eax
cmpq -0x18(%rbp), %rax
jne 0x31168e
jmp 0x3117b3
jmp 0x311690
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x3116f8
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3116bd
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x78(%rbp)
jmp 0x3116c8
movl $0x2, %eax
movq %rax, -0x78(%rbp)
jmp 0x3116c8
movq -0x78(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x2c(%rbp), %eax
shll %eax
movl %eax, %eax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x311720
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x311788
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x31174d
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x80(%rbp)
jmp 0x311758
movl $0x2, %eax
movq %rax, -0x80(%rbp)
jmp 0x311758
movq -0x80(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x30(%rbp), %eax
shll %eax
orl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x3117b3
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x3115f7
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x48(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x20(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x30ed90
movq -0x18(%rbp), %rax
movl %eax, -0x40(%rbp)
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x28(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x3118f4
movl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x28(%rbp), %ecx
movq (%rax,%rcx,8), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x311854
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x31185d
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x1, -0x50(%rbp)
jge 0x311880
cmpl $0x1, -0x4c(%rbp)
jl 0x311880
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x28(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq %rax
movl %eax, -0x44(%rbp)
jmp 0x3118e4
cmpl $0x1, -0x50(%rbp)
jl 0x3118e2
cmpl $0x1, -0x4c(%rbp)
jge 0x3118e2
cmpl $0x0, -0x44(%rbp)
jne 0x3118ad
movl -0x44(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x28(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq %rax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x28(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq %rax
cmpq -0x18(%rbp), %rax
jne 0x3118e0
movl -0x44(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x28(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq %rax
movl %eax, -0x3c(%rbp)
jmp 0x3118e2
jmp 0x3118e4
jmp 0x3118e6
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x31181a
movl -0x48(%rbp), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl -0x34(%rbp), %eax
cmpl -0x40(%rbp), %eax
jbe 0x311911
movl $0x0, -0x4(%rbp)
jmp 0x311918
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)