// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: integer_candidate(ul_resolve_t*, integer_t*, unsigned int, unsigned int)
void integer_candidate(ul_resolve_t *uidx, integer_t *buf, uint32_t qid, uint32_t is_hom)
{
    uint64_t k, z, m_het, m_het_occ, ref_occ, b_n, m; uint32_t vk, vz, is_circle = 0; integer_aln_t *p; ul_chain_t sc;
    ul_str_idx_t *str_idx = &(uidx->pstr); ma_ug_t *ug = uidx->l1_ug; 
    uint64_t *hid_a, hid_n; uc_block_t *xi;
    ul_str_t *str = &(str_idx->str.a[qid]);
    if(str->cn < 2) return; ///directly filter out too short UL
    kv_resize(uint64_t, buf->u, str->cn); buf->u.n = str->cn;
    for (k = m_het = m_het_occ = ref_occ = 0; k < str->cn; k++) {
        xi = &(uidx->idx->a[qid].bb.a[str->a[k]>>32]);
        assert(((xi->hid<<1)+xi->rev)==((uint32_t)str->a[k]));
        buf->u.a[k] = ug_occ_w(xi->ts, xi->te, &(ug->u.a[xi->hid]));
        assert(buf->u.a[k] > 0);
        if((!is_hom) && (!IF_HOM((((uint32_t)str->a[k])>>1), (*uidx->bub)))) {
            m_het++; m_het_occ += buf->u.a[k];///m_het_occ: how many het HiFi reads
        }
        ref_occ += buf->u.a[k];
        // fprintf(stderr, "[M::%s::k->%lu] buf->u.a[k]->%lu, ts->%u, te->%u, pchain->%u\n", __func__, k, buf->u.a[k], xi->ts, xi->te, xi->pchain);
    }
    // if((!is_hom) && (m_het < 2) && (m_het > 0)) return;///if all matched unitigs are hom, is ok
    if(m_het == 0 || m_het_occ == 0) is_hom = 1;
    // print_ul_alignment(ug, &UL_INF, 27512, "inner-0");
    for (k = 0, buf->b.n = 0; k < str->cn; k++) {
        vk = (uint32_t)str->a[k];
        hid_a = str_idx->occ.a + str_idx->idx.a[vk>>1];
        hid_n = str_idx->idx.a[(vk>>1)+1] - str_idx->idx.a[vk>>1];
        for (z = 0; z < hid_n; z++) {
            if((hid_a[z]>>32) == qid) continue;
            if(str_idx->str.a[hid_a[z]>>32].cn < 2) continue;
            vz = (uint32_t)(str_idx->str.a[hid_a[z]>>32].a[(uint32_t)hid_a[z]]);
            assert((vk>>1) == (vz>>1));
            kv_pushp(integer_aln_t, buf->b, &p);
            p->vq = vk; p->tk = (uint32_t)hid_a[z]; 
            if((vk^vz)&1) p->tk = str_idx->str.a[hid_a[z]>>32].cn - p->tk - 1;///rev
            p->tn_rev_qk = (hid_a[z]>>32); p->tn_rev_qk <<= 1; p->tn_rev_qk |= ((vk^vz)&1);
            p->tn_rev_qk <<= 32; p->tn_rev_qk += k; 
            ///set score of this pair
            p->sc = buf->u.a[k];
            xi = &(uidx->idx->a[hid_a[z]>>32].bb.a[(str_idx->str.a[hid_a[z]>>32].a[(uint32_t)hid_a[z]])>>32]);
            assert(((xi->hid<<1)+xi->rev)==vz); m = ug_occ_w(xi->ts, xi->te, &(ug->u.a[xi->hid]));
            if(p->sc > m) p->sc = m;
        }
    }
    // print_ul_alignment(ug, &UL_INF, 27512, "inner-1");
    radix_sort_integer_aln_t_srt(buf->b.a, buf->b.a + buf->b.n); 
    b_n = buf->b.n; buf->sc.n = 0;
    for (k = 1, z = 0; k <= b_n; k++) {
        if(k == b_n || (buf->b.a[z].tn_rev_qk>>32) != (buf->b.a[k].tn_rev_qk>>32)) {
            ///get the chain for <qn, tn>
            if(integer_chain(qid, buf->b.a + z, k - z, z, buf, ug, str_idx, uidx->idx, &sc) && sc.v != (uint32_t)-1) {
                if((buf->sc.n > 0) && ((buf->sc.a[buf->sc.n-1].v>>1) == (sc.v>>1))) {
                    if(buf->sc.a[buf->sc.n-1].sc < sc.sc) {
                        buf->sc.a[buf->sc.n-1] = sc;
                    }
                } else {
                    kv_push(ul_chain_t, buf->sc, sc);
                }
            }
            z = k;
        }
    }
    // print_ul_alignment(ug, &UL_INF, 27512, "inner-2");
    uint64_t *o, o_n, cns_het, cns_het_occ, ref_cns_occ, corrected = 0;
    o_n = integer_chain_dp(uidx->bub, buf, str_idx->str.a, buf->b.a, buf->sc.a, buf->sc.n, qid, is_hom, 2, &corrected);
    assert(o_n <= str->cn); 
    // if(qid == 2062 || qid == 2093) fprintf(stderr,"[M::%s::] o_n::%lu, str->cn::%u, corrected::%lu\n", __func__, o_n, str->cn, corrected);
    if(o_n <= 0) return; 
    if(corrected) return;
    // print_ul_alignment(ug, &UL_INF, 27512, "inner-3");
    
    for (k = cns_het = cns_het_occ = ref_cns_occ = 0, o = buf->o.a; k < o_n; k++) {
        if((!is_hom) && (!IF_HOM((((uint32_t)str->a[o[k]])>>1), (*uidx->bub)))) {
            cns_het++; cns_het_occ += buf->u.a[o[k]];
        }
        ref_cns_occ += buf->u.a[o[k]];     
    }
    buf->o.n = o_n;
    ///1. if the ref read only has hom unitigs, is fine
    ///2. otherwise need to have consenus het untigs
    if(!is_hom) {
        if((cns_het <= 0) || (cns_het_occ <= 0) || (cns_het_occ <= (m_het_occ*0.25))) return;
    } else {
        if(ref_cns_occ <= (ref_occ*0.25)) return;
    }
    // print_ul_alignment(ug, &UL_INF, 27512, "inner-4");
    // fprintf(stderr, "\n");
    // print_integer_seq(ug, str_idx->str.a, qid, 1);
    // print_aln_seq(ug, uidx->idx, qid, 1);
    // if(qid == 2062 || qid == 2093) print_cns_seq(ug, str, o, o_n);
    // print_ul_alignment(ug, &UL_INF, 27512, "inner-5");

    for (k = m = 0; k < buf->sc.n; k++) {
        // fprintf(stderr, "[M::%s::k->%lu] m::%lu\n", __func__, k, m);
        // if(k == 72) {
        //     print_integer_ovlps(ug, str_idx->str.a, buf->b.a, buf->b.n, buf->sc.a+k, 1, qid, o_n);
        // }
        if(refine_integer_ovlps(uidx->idx, uidx->bub, ug, str_idx->str.a, buf->b.a, 
                                                            &(buf->sc.a[k]), qid, buf, o, o_n)) {                                                
            buf->sc.a[m++] = buf->sc.a[k];
        } 
        // else {
        //     print_integer_ovlps(ug, str_idx->str.a, buf->b.a, buf->b.n, buf->sc.a+k, 1, qid, o_n);
        //     fprintf(stderr, "[M::%s::] idx->q_sidx::%u, idx->q_eidx::%u, idx->t_sidx::%u, idx->t_eidx::%u\n******************************************************\n", 
        //         __func__, buf->sc.a[k].q_sidx, buf->sc.a[k].q_eidx, buf->sc.a[k].t_sidx, buf->sc.a[k].t_eidx);
        // }
    }
    buf->sc.n = m;
    if(m <= 0) return;
    // print_ul_alignment(ug, &UL_INF, 27512, "inner-6");
    // if(m != str->cn) print_integer_ovlps(uidx->l1_ug, str_idx->str.a, buf->b.a, buf->b.n, buf->sc.a, buf->sc.n, qid, m);
    poa_cns_chain(&(buf->pg), uidx->idx, ug, str_idx->str.a, buf->sc.a, buf->sc.n, qid, buf, &is_circle);
    if(is_circle) {
        buf->n_circle++;
        return;
    }
    // print_ul_alignment(ug, &UL_INF, 27512, "inner-7");
    // print_res_seq(&(buf->pg), ug, buf->pg.srt_b.res.a, buf->pg.srt_b.res.n);
    // radix_sort_ul_chain_t_srt(buf->sc.a, buf->sc.a + buf->sc.n);
    
    // integer_phase(str_idx->str.a, buf, buf->sc.a, buf->sc.n, buf->b.a, qid);

    // radix_sort_ul_chain_t_srt(buf->sc.a, buf->sc.a + buf->sc.n);
    o = NULL; o_n = 0;
    update_raw_integer_seq(&(buf->pg), ug, buf->pg.srt_b.res.a, buf->pg.srt_b.res.n, uidx->idx, str_idx->str.a, qid, buf, buf->sc.a, buf->sc.n);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl $0x0, -0x64(%rbp)
movq -0x10(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x1c(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x2, %eax
jge 0x3361b6
jmp 0x3370ce
jmp 0x3361b8
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rax
movq -0xc8(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x3362f9
movq -0xc8(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, 0x98(%rax)
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x98(%rax)
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rcx
shrq %rcx
movq -0x18(%rbp), %rax
orq 0x98(%rax), %rcx
movq %rcx, 0x98(%rax)
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rcx
shrq $0x2, %rcx
movq -0x18(%rbp), %rax
orq 0x98(%rax), %rcx
movq %rcx, 0x98(%rax)
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rcx
shrq $0x4, %rcx
movq -0x18(%rbp), %rax
orq 0x98(%rax), %rcx
movq %rcx, 0x98(%rax)
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rcx
shrq $0x8, %rcx
movq -0x18(%rbp), %rax
orq 0x98(%rax), %rcx
movq %rcx, 0x98(%rax)
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rcx
shrq $0x10, %rcx
movq -0x18(%rbp), %rax
orq 0x98(%rax), %rcx
movq %rcx, 0x98(%rax)
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x98(%rax)
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xa0(%rax)
jmp 0x3362fb
movq -0xc8(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, 0x90(%rax)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0xc8(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x33650a
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rax
movq -0xc8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movl (%rax), %eax
shll %eax
movq -0xc0(%rbp), %rcx
movb 0x20(%rcx), %cl
shrb $0x5, %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %eax
movq -0xc8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
jne 0x3363d0
jmp 0x3363ef
leaq 0x61df1(%rip), %rdi     # 0x3981c8
leaq 0x5fddb(%rip), %rsi     # 0x3961b9
movl $0x193f, %edx           # imm = 0x193F
leaq 0x61e0c(%rip), %rcx     # 0x3981f6
callq 0x2130
movq -0xc0(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edi
movq -0xc0(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %esi
movq -0xa8(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0xc0(%rbp), %rax
movl (%rax), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdx
callq 0x327090
movq %rax, %rdx
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rax
movq -0x28(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jbe 0x336455
jmp 0x336474
leaq 0x61de2(%rip), %rdi     # 0x39823e
leaq 0x5fd56(%rip), %rsi     # 0x3961b9
movl $0x1941, %edx           # imm = 0x1941
leaq 0x61d87(%rip), %rcx     # 0x3981f6
callq 0x2130
cmpl $0x0, -0x20(%rbp)
jne 0x3364de
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq -0xc8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
ja 0x3364de
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x336339
cmpq $0x0, -0x38(%rbp)
je 0x336518
cmpq $0x0, -0x40(%rbp)
jne 0x33651f
movl $0x1, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x28(%rbp), %rax
movq -0xc8(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x33696b
movq -0xc8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x5c(%rbp)
movq -0xa0(%rbp), %rax
movq 0x28(%rax), %rax
movq -0xa0(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x5c(%rbp), %edx
shrl %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0xa0(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x5c(%rbp), %ecx
shrl %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq -0xa0(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x5c(%rbp), %edx
shrl %edx
movl %edx, %edx
subq (%rcx,%rdx,8), %rax
movq %rax, -0xb8(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jae 0x336958
movq -0xb0(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl -0x1c(%rbp), %ecx
cmpq %rcx, %rax
jne 0x336606
jmp 0x336947
movq -0xa0(%rbp), %rax
movq 0x40(%rax), %rax
movq -0xb0(%rbp), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x2, %eax
jge 0x33663d
jmp 0x336947
movq -0xa0(%rbp), %rax
movq 0x40(%rax), %rax
movq -0xb0(%rbp), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq -0xb0(%rbp), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x60(%rbp)
movl -0x5c(%rbp), %eax
shrl %eax
movl -0x60(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x33668e
jmp 0x3366ad
leaq 0x61bb9(%rip), %rdi     # 0x39824e
leaq 0x5fb1d(%rip), %rsi     # 0x3961b9
movl $0x1953, %edx           # imm = 0x1953
leaq 0x61b4e(%rip), %rcx     # 0x3981f6
callq 0x2130
jmp 0x3366af
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jne 0x33671e
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x3366e0
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
shlq %rax
movq %rax, -0x100(%rbp)
jmp 0x3366ee
movl $0x2, %eax
movq %rax, -0x100(%rbp)
jmp 0x3366ee
movq -0x100(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x18(%rbp), %rax
imulq $0x18, 0x38(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x18(%rbp), %rdx
movq 0x30(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x30(%rdx)
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movl -0x5c(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0xb0(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %ecx
movq -0x70(%rbp), %rax
movl %ecx, (%rax)
movl -0x5c(%rbp), %eax
xorl -0x60(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3367b0
movq -0xa0(%rbp), %rax
movq 0x40(%rax), %rax
movq -0xb0(%rbp), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq -0x70(%rbp), %rax
subl (%rax), %ecx
subl $0x1, %ecx
movq -0x70(%rbp), %rax
movl %ecx, (%rax)
movq -0xb0(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
shrq $0x20, %rcx
movq -0x70(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rcx
shlq %rcx
movq %rcx, 0x10(%rax)
movl -0x5c(%rbp), %eax
xorl -0x60(%rbp), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x70(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rcx
shlq $0x20, %rcx
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq -0x70(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x48(%rax), %rax
movq -0xb0(%rbp), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rax
movq -0xa0(%rbp), %rcx
movq 0x40(%rcx), %rcx
movq -0xb0(%rbp), %rdx
movq -0x30(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrq $0x20, %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movq -0xb0(%rbp), %rdx
movq -0x30(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movl (%rax), %eax
shll %eax
movq -0xc0(%rbp), %rcx
movb 0x20(%rcx), %cl
shrb $0x5, %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %eax
cmpl -0x60(%rbp), %eax
jne 0x3368d0
jmp 0x3368ef
leaq 0x6198a(%rip), %rdi     # 0x398261
leaq 0x5f8db(%rip), %rsi     # 0x3961b9
movl $0x195c, %edx           # imm = 0x195C
leaq 0x6190c(%rip), %rcx     # 0x3981f6
callq 0x2130
movq -0xc0(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edi
movq -0xc0(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %esi
movq -0xa8(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0xc0(%rbp), %rax
movl (%rax), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdx
callq 0x327090
movq %rax, -0x58(%rbp)
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
cmpq -0x58(%rbp), %rax
jbe 0x336945
movq -0x58(%rbp), %rax
movl %eax, %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x336947
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x3365d5
jmp 0x33695a
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x336533
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rsi
movq -0x18(%rbp), %rax
imulq $0x18, 0x30(%rax), %rax
addq %rax, %rsi
callq 0x310150
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0xc0(%rax)
movq $0x1, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x50(%rbp), %rax
ja 0x336bfe
movq -0x28(%rbp), %rax
cmpq -0x50(%rbp), %rax
je 0x336a08
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
shrq $0x20, %rax
movq -0x18(%rbp), %rcx
movq 0x40(%rcx), %rcx
imulq $0x18, -0x28(%rbp), %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x336beb
movl -0x1c(%rbp), %edi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rsi
imulq $0x18, -0x30(%rbp), %rax
addq %rax, %rsi
movq -0x28(%rbp), %rdx
subq -0x30(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %r8
movq -0xa8(%rbp), %r9
movq -0xa0(%rbp), %r11
movq -0x10(%rbp), %rax
movq 0x30(%rax), %r10
leaq -0x98(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x329410
cmpl $0x0, %eax
je 0x336be3
cmpl $-0x1, -0x90(%rbp)
je 0x336be3
movq -0x18(%rbp), %rax
cmpq $0x0, 0xc0(%rax)
jbe 0x336b1a
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0xc0(%rcx), %rcx
subq $0x1, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl %eax
movl -0x90(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x336b1a
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0xc0(%rcx), %rcx
subq $0x1, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
cmpq -0x88(%rbp), %rax
jae 0x336b15
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0xc0(%rax), %rax
subq $0x1, %rax
imulq $0x28, %rax, %rax
addq %rax, %rdi
leaq -0x98(%rbp), %rsi
movl $0x28, %edx
callq 0x2180
jmp 0x336be1
jmp 0x336b1c
movq -0x18(%rbp), %rax
movq 0xc0(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0xc8(%rcx), %rax
jne 0x336ba3
movq -0x18(%rbp), %rax
cmpq $0x0, 0xc8(%rax)
je 0x336b59
movq -0x18(%rbp), %rax
movq 0xc8(%rax), %rax
shlq %rax
movq %rax, -0x108(%rbp)
jmp 0x336b67
movl $0x2, %eax
movq %rax, -0x108(%rbp)
jmp 0x336b67
movq -0x108(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xc8(%rax)
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %rdi
movq -0x18(%rbp), %rax
imulq $0x28, 0xc8(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xd0(%rax)
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %rdi
movq -0x18(%rbp), %rcx
movq 0xc0(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0xc0(%rcx)
imulq $0x28, %rax, %rax
addq %rax, %rdi
leaq -0x98(%rbp), %rsi
movl $0x28, %edx
callq 0x2180
jmp 0x336be1
jmp 0x336be3
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x336bed
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x3369b7
movq $0x0, -0xf8(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0xa0(%rbp), %rax
movq 0x40(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %r8
movq -0x18(%rbp), %rax
movq 0xc0(%rax), %r9
movl -0x1c(%rbp), %eax
movl %eax, %r11d
movl -0x20(%rbp), %r10d
leaq -0xf8(%rbp), %rax
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movq $0x2, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x329f50
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq -0xc8(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
ja 0x336c92
jmp 0x336cb1
leaq 0x615e3(%rip), %rdi     # 0x39827c
leaq 0x5f519(%rip), %rsi     # 0x3961b9
movl $0x1975, %edx           # imm = 0x1975
leaq 0x6154a(%rip), %rcx     # 0x3981f6
callq 0x2130
cmpq $0x0, -0xd8(%rbp)
ja 0x336cc0
jmp 0x3370ce
cmpq $0x0, -0xf8(%rbp)
je 0x336ccf
jmp 0x3370ce
movq $0x0, -0xf0(%rbp)
movq $0x0, -0xe8(%rbp)
movq $0x0, -0xe0(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0x28(%rbp), %rax
cmpq -0xd8(%rbp), %rax
jae 0x336de8
cmpl $0x0, -0x20(%rbp)
jne 0x336dab
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq -0xc8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0xd0(%rbp), %rdx
movq -0x28(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
ja 0x336dab
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rax
movq -0xd0(%rbp), %rcx
movq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rax,%rcx,8), %rax
addq -0xe8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x18(%rbp), %rax
movq 0xa0(%rax), %rax
movq -0xd0(%rbp), %rcx
movq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rax,%rcx,8), %rax
addq -0xf0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x336d0a
movq -0xd8(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x78(%rax)
cmpl $0x0, -0x20(%rbp)
jne 0x336e6c
cmpq $0x0, -0xe0(%rbp)
jbe 0x336e65
cmpq $0x0, -0xe8(%rbp)
jbe 0x336e65
movq -0xe8(%rbp), %xmm1
movaps 0x4b1f0(%rip), %xmm3    # 0x382010
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x4b1f4(%rip), %xmm2    # 0x382020
subpd %xmm2, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movq -0x40(%rbp), %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm2, %xmm0
movsd 0x4b3f5(%rip), %xmm2    # 0x382250
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jb 0x336e6a
jmp 0x3370ce
jmp 0x336ec7
movq -0xf0(%rbp), %xmm1
movaps 0x4b195(%rip), %xmm3    # 0x382010
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x4b199(%rip), %xmm2    # 0x382020
subpd %xmm2, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movq -0x48(%rbp), %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm2, %xmm0
movsd 0x4b39a(%rip), %xmm2    # 0x382250
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jb 0x336ec5
jmp 0x3370ce
jmp 0x336ec7
movq $0x0, -0x58(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0xc0(%rcx), %rax
jae 0x336faf
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0xa8(%rbp), %rdx
movq -0xa0(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x18(%rbp), %rax
movq 0x40(%rax), %r8
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %r9
imulq $0x28, -0x28(%rbp), %rax
addq %rax, %r9
movl -0x1c(%rbp), %eax
movl %eax, %ebx
movq -0x18(%rbp), %r11
movq -0xd0(%rbp), %r10
movq -0xd8(%rbp), %rax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x32c530
cmpq $0x0, %rax
je 0x336f9c
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %rsi
imulq $0x28, -0x28(%rbp), %rax
addq %rax, %rsi
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %rdi
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
imulq $0x28, %rax, %rax
addq %rax, %rdi
movl $0x28, %edx
callq 0x2180
jmp 0x336f9e
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x336ed7
movq -0x58(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xc0(%rax)
cmpq $0x0, -0x58(%rbp)
ja 0x336fca
jmp 0x3370ce
movq -0x18(%rbp), %rdi
addq $0xf0, %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0xa8(%rbp), %rdx
movq -0xa0(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %r8
movq -0x18(%rbp), %rax
movq 0xc0(%rax), %r9
movl -0x1c(%rbp), %eax
movl %eax, %r11d
movq -0x18(%rbp), %r10
leaq -0x64(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x3341d0
cmpl $0x0, -0x64(%rbp)
je 0x337047
movq -0x18(%rbp), %rax
movq 0x320(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x320(%rax)
jmp 0x3370ce
movq $0x0, -0xd0(%rbp)
movq $0x0, -0xd8(%rbp)
movq -0x18(%rbp), %rdi
addq $0xf0, %rdi
movq -0xa8(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x180(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x170(%rax), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %r8
movq -0xa0(%rbp), %rax
movq 0x40(%rax), %r9
movl -0x1c(%rbp), %ebx
movq -0x18(%rbp), %r11
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %r10
movq -0x18(%rbp), %rax
movq 0xc0(%rax), %rax
movl %ebx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x335aa0
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %rbp
retq
nopl (%rax,%rax)