// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: hap_alignment_advance_worker(void*, long, int)
static void hap_alignment_advance_worker(void *_data, long eid, int tid)
{
    hap_alignment_struct_pip* hap_buf = (hap_alignment_struct_pip*)_data;
    ma_ug_t *ug = hap_buf->ug;
    asg_t *read_g = hap_buf->read_g;
    ma_hit_t_alloc* sources = hap_buf->sources;
    ma_hit_t_alloc* reverse_sources = hap_buf->reverse_sources;
    R_to_U* ruIndex = hap_buf->ruIndex;
    ma_sub_t *coverage_cut = hap_buf->coverage_cut;
    uint64_t* position_index = hap_buf->position_index;
    float Hap_rate = hap_buf->Hap_rate/**MIN(hap_buf->Hap_rate, 0.2)**/, sim;
    int max_hang = hap_buf->max_hang;
    int min_ovlp = hap_buf->min_ovlp;
    float chain_rate = hap_buf->chain_rate;
    hap_overlaps_list* all_ovlp = hap_buf->all_ovlp;
    uint32_t Input_uId = eid;
    uint64_t* vote_counting = hap_buf->buf[tid].vote_counting;
    uint8_t* visit = hap_buf->buf[tid].visit;
    kvec_t_u64_warp* u_vecs = &(hap_buf->buf[tid].u_vecs);
    kvec_asg_arc_t_offset* u_buffer = &(hap_buf->buf[tid].u_buffer);
    kvec_hap_candidates* u_can = &(hap_buf->buf[tid].u_can);
    kvec_t_i32_warp* score_vc = &(hap_buf->buf[tid].u_buffer_tailIndex);
    kvec_t_i32_warp* prevIndex_vec = &(hap_buf->buf[tid].u_buffer_prevIndex);
    kvec_t_i32_warp* begIndex_vec = &(hap_buf->buf[tid].u_buffer_beg);
    kvec_t_u8_warp* flag_vec = &(hap_buf->buf[tid].u_buffer_flag);
    uint64_t cov_threshold = hap_buf->cov_threshold;
    hap_cov_t *cov = hap_buf->cov;
    uint8_t *hh = hap_buf->hh, hhc;
    if(hap_buf->cov_threshold < 0) cov_threshold = (uint64_t)-1;
    ma_utg_t *xReads = NULL, *yReads = NULL;
    ma_hit_t_alloc *xR = NULL;
    ma_hit_t *h = NULL;
    ma_sub_t *sq = NULL, *st = NULL;
    asg_t* nsg = ug->g;
    uint32_t i, j, v, rId, k, is_Unitig, Hap_uId, xUid, yUid, seedOcc;
    uint64_t tmp, max_weight, m;
    long long r_x_pos_beg, r_x_pos_end, r_y_pos_beg, r_y_pos_end, max_score;
    int32_t r;
    asg_arc_t t;
    asg_arc_t_offset t_offset;
    hap_overlaps hap_align;
    hap_overlaps *hap_align_x = NULL;
    xUid = Input_uId;
    if(nsg->seq[xUid].del || nsg->seq[xUid].c == ALTER_LABLE) return;
    memset(vote_counting, 0, sizeof(uint64_t)*nsg->n_seq);
    memset(visit, 0, nsg->n_seq);
    u_vecs->a.n = 0;
    u_can->a.n = 0;

    xReads = &(ug->u.a[xUid]);
    for (i = 0; i < xReads->n; i++)
    {
        xR = &(reverse_sources[xReads->a[i]>>33]);
        
        for (k = 0; k < xR->length; k++)
        {
            rId = Get_tn(xR->buffer[k]);
        
            if(read_g->seq[rId].del == 1)
            {
                ///get the id of read that contains it 
                get_R_to_U(ruIndex, rId, &rId, &is_Unitig);
                if(rId == (uint32_t)-1 || is_Unitig == 1 || read_g->seq[rId].del == 1) continue;
            }

            ///there are two cases: 
            ///1. read at primary contigs, get_R_to_U() return its corresponding contig Id  
            ///2. read at alternative contigs, get_R_to_U() return (uint32_t)-1
            get_R_to_U(ruIndex, rId, &Hap_uId, &is_Unitig);
            if(is_Unitig == 0 || Hap_uId == (uint32_t)-1) continue;
            ///here rId is the id of the read coming from the different haplotype
            ///Hap_cId is the id of the corresponding contig (note here is the contig, instead of untig)
            if(visit[Hap_uId]!=0) continue; ///one read only has one vote for one hap unitig
            visit[Hap_uId] = 1;
            if(vote_counting[Hap_uId] < UINT64_MAX) vote_counting[Hap_uId]++;
        }

        clean_visit_flag(visit, read_g, ruIndex, nsg->n_seq, xR);
    }



    u_vecs->a.n = 0;
    for (i = 0; i < nsg->n_seq; i++)
    {
        if(i == xUid) continue;
        if(vote_counting[i] == 0) continue;
        tmp = vote_counting[i]; tmp = tmp << 32; tmp = tmp | (uint64_t)i;
        kv_push(uint64_t, u_vecs->a, tmp);
    }

    if(u_vecs->a.n == 0) return;
    sort_kvec_t_u64_warp(u_vecs, 1);


    ///scan each candidate unitig
    for (i = 0; i < u_vecs->a.n; i++)
    {
        yUid = (uint32_t)u_vecs->a.a[i];
        seedOcc = u_vecs->a.a[i]>>32;
        xReads = &(ug->u.a[xUid]);
        yReads = &(ug->u.a[yUid]);
        u_buffer->a.n = 0;

        for (k = 0; k < xReads->n; k++)
        {
            xR = &(reverse_sources[xReads->a[k]>>33]);
            hhc = hh[xReads->a[k]>>33];
            for (j = 0; j < xR->length; j++)
            {
                h = &(xR->buffer[j]);
                sq = &(coverage_cut[Get_qn(*h)]);
                st = &(coverage_cut[Get_tn(*h)]);
                if(st->del || read_g->seq[Get_tn(*h)].del) continue;

                r = ma_hit2arc(h, sq->e - sq->s, st->e - st->s, max_hang, 
                                asm_opt.max_hang_rate, min_ovlp, &t);
                ///if it is a contained overlap, skip
                if(r < 0) continue;

                rId = t.v>>1;
                if(read_g->seq[rId].del == 1) continue;
                ///there are two cases: 
                ///1. read at primary contigs, get_R_to_U() return its corresponding contig Id  
                ///2. read at alternative contigs, get_R_to_U() return (uint32_t)-1
                get_R_to_U(ruIndex, rId, &Hap_uId, &is_Unitig);
                if(is_Unitig == 0 || Hap_uId == (uint32_t)-1) continue;
                if(Hap_uId != yUid) continue;

                v = xReads->a[k]>>32;
                get_R_to_U(ruIndex, v>>1, &Hap_uId, &is_Unitig);
                if(is_Unitig == 0 || Hap_uId == (uint32_t)-1) continue;
                if(Hap_uId != xUid) continue;
                if((uint32_t)(position_index[v>>1]) != k) continue;

                if(asm_opt.purge_level_primary <= 2 &&
                    (prefilter((uint32_t)(position_index[v>>1]), (uint32_t)(position_index[rId]), 
                    xReads->n, yReads->n, 0, Hap_rate, seedOcc)==NON_PLOID) && 
                   (prefilter((uint32_t)(position_index[v>>1]), (uint32_t)(position_index[rId]), 
                    xReads->n, yReads->n, 1, Hap_rate, seedOcc)==NON_PLOID))
                {
                    continue;
                }
            
                t_offset.Off = get_xy_pos(read_g, &t, v, (yReads->a[(uint32_t)(position_index[rId])])>>32, 
                xReads->len, yReads->len, position_index, &(t.el));
                if(((t_offset.Off>>32) == (uint32_t)-1) || (((uint32_t)t_offset.Off) == (uint32_t)-1)) continue;

                t_offset.x = t;
                t_offset.weight = hhc;

                kv_push(asg_arc_t_offset, u_buffer->a, t_offset);
            }

            deduplicate_edge(u_buffer);
        }

        if(u_buffer->a.n == 0) continue;

        
        get_candidate_hap_alignment(u_can, u_buffer, score_vc, prevIndex_vec, begIndex_vec,
        flag_vec, chain_rate, 50, xReads->len, yReads->len);

        if(u_can->a.n == 0) continue;
        
        qsort(u_can->a.a, u_can->a.n, sizeof(hap_candidates), cmp_hap_candidates);

        memset(&hap_align, 0, sizeof(hap_overlaps));    
        m = all_ovlp->x[xUid].a.n;     
        max_weight = 0; max_score = 0;
        for (k = 0; k < u_can->a.n; k++)
        {
            if(u_can->a.a[k].weight < max_weight*0.33) continue;
            if(calculate_pair_hap_similarity_advance(&(u_can->a.a[k]), position_index, xUid, yUid, 
            xReads, yReads, sources, reverse_sources, read_g, ruIndex, coverage_cut, Hap_rate,
            (asm_opt.purge_level_primary<=2? 0:1), max_hang, min_ovlp, cov_threshold, u_buffer, 
            score_vc, prevIndex_vec, cov, &r_x_pos_beg, &r_x_pos_end, &r_y_pos_beg, &r_y_pos_end, &sim)!=PLOID)
            {
                continue;
            }
            ///max_weight == 0 means the first matched chain
            if(max_weight == 0 || max_score < u_can->a.a[k].score) max_score = u_can->a.a[k].score;
            if(max_weight < u_can->a.a[k].weight) max_weight = u_can->a.a[k].weight;
            ///if one is positive and another one is negative, it is wrong
            if(!filter_secondary_chain(max_score, u_can->a.a[k].score, CHAIN_FILTER_RATE)) continue;
                            
            hap_align.rev = Get_rev(u_can->a.a[k]);
            hap_align.type = Get_type(u_can->a.a[k]);
            hap_align.x_beg_id = Get_x_beg(u_can->a.a[k]);
            hap_align.x_end_id = Get_x_end(u_can->a.a[k]) + 1;
            hap_align.y_beg_id = Get_y_beg(u_can->a.a[k]);
            hap_align.y_end_id = Get_y_end(u_can->a.a[k]) + 1;
            hap_align.weight = Get_match(u_can->a.a[k]);
            hap_align.score = u_can->a.a[k].score;
            hap_align.x_beg_pos = r_x_pos_beg;
            hap_align.x_end_pos = r_x_pos_end + 1;
            if(hap_align.rev == 0)
            {
                hap_align.y_beg_pos = r_y_pos_beg;
                hap_align.y_end_pos = r_y_pos_end + 1;
            }
            else
            {
                hap_align.y_beg_pos = yReads->len - r_y_pos_end - 1;
                hap_align.y_end_pos = yReads->len - r_y_pos_beg - 1 + 1;
            }
            hap_align.xUid = xUid;
            hap_align.yUid = yUid;
            hap_align.status = SELF_EXIST;
            hap_align.s = sim;
            kv_push(hap_overlaps, all_ovlp->x[hap_align.xUid].a, hap_align);
        }
        /**
        ///chains with same xUid && yUid
        for (k = m; k < all_ovlp->x[xUid].a.n; k++)
        {
            if(!filter_secondary_chain(max_score, 
                        all_ovlp->x[xUid].a.a[k].score, CHAIN_FILTER_RATE))
            {
                continue;
            } 
            all_ovlp->x[xUid].a.a[m] = all_ovlp->x[xUid].a.a[k];
            m++;
        }
        all_ovlp->x[xUid].a.n = m;
        **/

        hap_align_x = NULL;
        for (k = m; k < all_ovlp->x[xUid].a.n; k++)
        {
            if(all_ovlp->x[xUid].a.a[k].score != max_score) continue;
            if(hap_align_x == NULL || all_ovlp->x[xUid].a.a[k].weight > hap_align_x->weight)
            {
                hap_align_x = &(all_ovlp->x[xUid].a.a[k]);
            }
            else if(all_ovlp->x[xUid].a.a[k].weight == hap_align_x->weight)
            {
                if((all_ovlp->x[xUid].a.a[k].x_end_pos 
                            - all_ovlp->x[xUid].a.a[k].x_beg_pos) < 
                    (hap_align_x->x_end_pos - hap_align_x->x_beg_pos))
                {
                    hap_align_x = &(all_ovlp->x[xUid].a.a[k]);
                }
            }
        }
        if(hap_align_x)
        {
            all_ovlp->x[xUid].a.a[m] = (*hap_align_x);
            all_ovlp->x[xUid].a.n = m + 1;
        }
    }
    // filter_secondary_ovlp(&all_ovlp->x[xUid], u_vecs, hap_buf->Hap_rate, 0.7);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq 0x18(%rdi), %rcx
movq 0x68(%rdi), %rax
testq %rax, %rax
pushq $-0x1
popq %r8
cmovnsq %rax, %r8
movq %r8, 0x140(%rsp)
movq %rcx, 0xd0(%rsp)
movq 0x18(%rcx), %rbp
movq 0x20(%rbp), %rax
movq %rsi, 0xb0(%rsp)
movl %esi, %ecx
movq %rcx, 0x88(%rsp)
cmpl $0x0, (%rax,%rcx,8)
js 0xd20c7
movq 0x88(%rsp), %rcx
cmpb $0x1, 0x4(%rax,%rcx,8)
je 0xd20c7
movq 0x20(%rdi), %rax
movq %rax, 0x58(%rsp)
movq 0x30(%rdi), %rax
movq %rax, 0xa8(%rsp)
movq 0x38(%rdi), %rax
movq %rax, 0x50(%rsp)
movq 0x40(%rdi), %r13
movq 0x48(%rdi), %rax
movq %rax, 0x98(%rsp)
movss 0x50(%rdi), %xmm0
movss %xmm0, 0x44(%rsp)
movslq %edx, %rax
imulq $0xf0, %rax, %rax
movq (%rdi), %rcx
leaq (%rcx,%rax), %rdx
movq %rdx, 0x20(%rsp)
leaq (%rcx,%rax), %r14
addq $0x10, %r14
leaq 0x30(%rcx,%rax), %rdx
movq %rdx, 0x68(%rsp)
leaq 0xd0(%rcx,%rax), %rbx
leaq 0x50(%rcx,%rax), %rdx
movq %rdx, 0xe8(%rsp)
leaq 0x70(%rcx,%rax), %rdx
movq %rdx, 0xe0(%rsp)
leaq 0xb0(%rcx,%rax), %rdx
movq %rdx, 0x108(%rsp)
leaq 0x90(%rcx,%rax), %rax
movq %rax, 0x100(%rsp)
movl 0x54(%rdi), %eax
movl %eax, 0x7c(%rsp)
movss 0x5c(%rdi), %xmm0
movss %xmm0, 0xb8(%rsp)
movl 0x58(%rdi), %eax
movl %eax, 0x78(%rsp)
movq 0x60(%rdi), %rax
movq %rax, 0x48(%rsp)
movq 0x10(%rdi), %rax
movq %rax, 0x148(%rsp)
movq 0x70(%rdi), %rax
movq %rax, 0x138(%rsp)
movl 0x14(%rbp), %edx
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
andq %r15, %rdx
shlq $0x3, %rdx
movq -0x10(%r14), %rdi
movq -0x8(%r14), %r12
movq %rdi, 0x10(%rsp)
xorl %esi, %esi
callq 0x20e0
movl 0x14(%rbp), %edx
andq %r15, %rdx
movq %r12, %r15
movq %r12, %rdi
xorl %esi, %esi
callq 0x20e0
xorl %edx, %edx
movq %r14, 0x80(%rsp)
andq $0x0, (%r14)
movq %rbx, 0xf0(%rsp)
andq $0x0, (%rbx)
imulq $0x28, 0x88(%rsp), %rcx
movq 0xd0(%rsp), %rax
movq 0x10(%rax), %rsi
movq %rcx, 0x118(%rsp)
addq %rcx, %rsi
leaq 0x8(%rsp), %rbx
movq %rbp, 0x70(%rsp)
movq %rsi, 0x28(%rsp)
movl 0x10(%rsi), %eax
cmpq %rax, %rdx
jae 0xd16e9
movq 0x18(%rsi), %rax
movq %rdx, 0x30(%rsp)
movq (%rax,%rdx,8), %rax
shrq $0x21, %rax
imulq $0x18, %rax, %r12
addq 0xa8(%rsp), %r12
pushq $0xc
popq %rbp
xorl %r14d, %r14d
movl 0xc(%r12), %eax
cmpq %rax, %r14
jae 0xd16b3
movq (%r12), %rax
movl (%rax,%rbp), %esi
movl %esi, 0x1c(%rsp)
movq 0x58(%rsp), %rax
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%rsi,8)
js 0xd166d
movq 0x50(%rsp), %rdi
leaq 0xc(%rsp), %rdx
movq %rbx, %rcx
callq 0x6c2a2
cmpl $0x0, 0x8(%rsp)
sete %cl
movl 0xc(%rsp), %eax
cmpl $-0x1, %eax
sete %dl
orb %cl, %dl
jne 0xd16a7
movl %eax, %eax
cmpb $0x0, (%r15,%rax)
jne 0xd16a7
movb $0x1, (%r15,%rax)
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
cmpq $-0x1, %rcx
je 0xd16a7
incq %rcx
movq 0x10(%rsp), %rdx
movq %rcx, (%rdx,%rax,8)
jmp 0xd16a7
movq 0x50(%rsp), %rdi
leaq 0x1c(%rsp), %rdx
movq %rbx, %rcx
callq 0x6c2a2
movl 0x1c(%rsp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rsi
je 0xd16a7
cmpl $0x1, 0x8(%rsp)
je 0xd16a7
movq 0x58(%rsp), %rax
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%rsi,8)
jns 0xd161a
incq %r14
addq $0x28, %rbp
jmp 0xd15f2
movq 0x70(%rsp), %rbp
movl 0x14(%rbp), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movq %r15, %rdi
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %r12, %r8
callq 0xd4234
movq 0x30(%rsp), %rdx
incq %rdx
movq 0x28(%rsp), %rsi
jmp 0xd15c3
movq 0x20(%rsp), %rsi
andq $0x0, 0x10(%rsi)
xorl %ebx, %ebx
movl 0x14(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rbx
jae 0xd177a
cmpq %rbx, 0x88(%rsp)
je 0xd1772
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %r14
testq %r14, %r14
je 0xd1772
movq 0x10(%rsi), %rcx
movq 0x20(%rsi), %rax
cmpq 0x18(%rsi), %rcx
jne 0xd1758
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq 0x20(%rsp), %rcx
movq %rsi, 0x18(%rcx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x20(%rsp), %rsi
movq %rax, 0x20(%rsi)
movq 0x10(%rsi), %rcx
shlq $0x20, %r14
addq %rbx, %r14
leaq 0x1(%rcx), %rdx
movq 0x80(%rsp), %rdi
movq %rdx, (%rdi)
movq %r14, (%rax,%rcx,8)
incq %rbx
jmp 0xd16f5
movq 0x80(%rsp), %rax
cmpq $0x0, (%rax)
je 0xd20c7
pushq $0x1
popq %rsi
movq 0x80(%rsp), %rdi
callq 0x68eff
xorl %ecx, %ecx
movl %ecx, %ecx
movq 0x80(%rsp), %rax
cmpq %rcx, (%rax)
movq 0x20(%rsp), %rdx
jbe 0xd20c7
movq 0x20(%rdx), %rax
movq %rcx, 0x130(%rsp)
movq (%rax,%rcx,8), %rsi
movq %rsi, %rax
shrq $0x20, %rax
movq %rax, 0x90(%rsp)
movq 0xd0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x118(%rsp), %rcx
leaq (%rax,%rcx), %r15
movq %rsi, 0x70(%rsp)
movl %esi, %ecx
imulq $0x28, %rcx, %rcx
addq %rax, %rcx
movq %rcx, 0x60(%rsp)
andq $0x0, 0x30(%rdx)
xorl %ecx, %ecx
movq %r15, 0x30(%rsp)
movl 0x10(%r15), %eax
cmpq %rax, %rcx
jae 0xd1b61
movq 0x18(%r15), %rax
movq %rcx, 0x10(%rsp)
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
imulq $0x18, %rax, %r14
addq 0xa8(%rsp), %r14
movq 0x148(%rsp), %rcx
movzbl (%rcx,%rax), %eax
movq %rax, 0xa0(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
movl 0xc(%r14), %eax
cmpq %rax, %rbp
jae 0xd1b45
movq (%r14), %rdi
movl 0xc(%rdi,%r12), %edx
imulq $0xc, %rdx, %rcx
movl (%r13,%rcx), %eax
testl %eax, %eax
js 0xd1b39
movq 0x58(%rsp), %rsi
movq 0x20(%rsi), %rbx
cmpl $0x0, (%rbx,%rdx,8)
js 0xd1b39
movl 0x4(%rdi,%r12), %edx
addq %r12, %rdi
imulq $0xc, %rdx, %rdx
addq %r13, %rdx
addq %r13, %rcx
movl 0x4(%rdx), %esi
movl (%rdx), %edx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %edx
subl %edx, %esi
movl 0x4(%rcx), %edx
subl %eax, %edx
leaq 0x181ea2(%rip), %rax    # 0x253758
movss 0x158(%rax), %xmm0
movl 0x7c(%rsp), %ecx
movl 0x78(%rsp), %r8d
leaq 0x150(%rsp), %r9
callq 0xc99c6
testl %eax, %eax
js 0xd1b39
movl 0x158(%rsp), %esi
shrl %esi
movl %esi, 0x1c(%rsp)
cmpl $0x0, (%rbx,%rsi,8)
js 0xd1b39
movq 0x50(%rsp), %rdi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0x6c2a2
cmpl $0x0, 0x8(%rsp)
je 0xd1b39
movl 0xc(%rsp), %eax
cmpl $-0x1, %eax
je 0xd1b39
cmpl 0x70(%rsp), %eax
jne 0xd1b39
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rbx
movq %rbx, %r15
shrq $0x21, %r15
movq 0x50(%rsp), %rdi
movl %r15d, %esi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0x6c2a2
cmpl $0x0, 0x8(%rsp)
je 0xd1b39
movl 0xc(%rsp), %eax
cmpl $-0x1, %eax
je 0xd1b39
cmpl 0xb0(%rsp), %eax
jne 0xd1b39
movl %r15d, %eax
movq 0x98(%rsp), %rcx
movq (%rcx,%rax,8), %r15
movl %r15d, %eax
cmpq %rax, 0x10(%rsp)
jne 0xd1b39
leaq 0x181db6(%rip), %rax    # 0x253758
cmpl $0x2, 0x130(%rax)
movl 0x1c(%rsp), %eax
movq 0x98(%rsp), %rcx
movl (%rcx,%rax,8), %esi
jg 0xd1a32
movq 0x30(%rsp), %rax
movl 0x10(%rax), %edx
movq 0x60(%rsp), %rax
movl 0x10(%rax), %ecx
movl %r15d, %edi
movq %rsi, 0x28(%rsp)
movq 0x28(%rsp), %rsi
movl %edx, 0x40(%rsp)
movl %ecx, 0x3c(%rsp)
xorl %r8d, %r8d
movss 0x44(%rsp), %xmm0
movq 0x90(%rsp), %r9
callq 0xc7d16
movq 0x28(%rsp), %rsi
testl %eax, %eax
je 0xd1a32
movl %r15d, %edi
movq 0x28(%rsp), %rsi
movl 0x40(%rsp), %edx
movl 0x3c(%rsp), %ecx
pushq $0x1
popq %r8
movss 0x44(%rsp), %xmm0
movq 0x90(%rsp), %r9
callq 0xc7d16
movq 0x28(%rsp), %rsi
testl %eax, %eax
jne 0xd1b39
shrq $0x20, %rbx
movq 0x60(%rsp), %rdx
movq 0x18(%rdx), %rax
movl 0x4(%rax,%rsi,8), %ecx
movq 0x30(%rsp), %rax
movl (%rax), %r8d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %r8d
movl (%rdx), %r9d
andl %eax, %r9d
movq 0x58(%rsp), %rdi
leaq 0x150(%rsp), %rsi
movl %ebx, %edx
leaq 0x162(%rsp), %rax
pushq %rax
pushq 0xa0(%rsp)
callq 0xd3d59
popq %rcx
popq %rdx
movq %rax, %rbx
movabsq $-0x100000001, %rax     # imm = 0xFFFFFFFEFFFFFFFF
cmpq %rax, %rbx
seta %al
cmpl $-0x1, %ebx
sete %cl
orb %al, %cl
jne 0xd1b39
movq 0x160(%rsp), %rax
movq %rax, 0x190(%rsp)
movups 0x150(%rsp), %xmm0
movaps %xmm0, 0x180(%rsp)
movq 0x20(%rsp), %rsi
movq 0x30(%rsi), %rcx
movq 0x40(%rsi), %rax
cmpq 0x38(%rsi), %rcx
jne 0xd1afc
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x38(%rsi)
movq %rsi, %r15
imulq $0x28, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x40(%r15)
movq 0x30(%r15), %rcx
leaq 0x1(%rcx), %rdx
movq 0x68(%rsp), %rsi
movq %rdx, (%rsi)
imulq $0x28, %rcx, %rcx
movq 0x190(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx)
movapd 0x180(%rsp), %xmm0
movupd %xmm0, (%rax,%rcx)
movq %rbx, 0x18(%rax,%rcx)
movq 0xa0(%rsp), %rdx
movq %rdx, 0x20(%rax,%rcx)
incq %rbp
addq $0x28, %r12
jmp 0xd184f
movq 0x68(%rsp), %rdi
callq 0xc7de6
movq 0x10(%rsp), %rcx
incq %rcx
movq 0x30(%rsp), %r15
jmp 0xd180c
movq 0x68(%rsp), %rax
cmpq $0x0, (%rax)
je 0xd20b8
movl (%r15), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andq %rcx, %rax
movq 0x60(%rsp), %rdx
movl (%rdx), %r10d
andq %rcx, %r10
subq $0x8, %rsp
movq 0xf8(%rsp), %rbx
movq %rbx, %rdi
movq 0x70(%rsp), %rsi
movq 0xf0(%rsp), %rdx
movq 0xe8(%rsp), %rcx
movq 0x110(%rsp), %r8
movq 0x108(%rsp), %r9
movss 0xc0(%rsp), %xmm0
pushq %r10
pushq %rax
pushq $0x32
callq 0xcd276
addq $0x20, %rsp
movq (%rbx), %rsi
testq %rsi, %rsi
je 0xd20b8
movq 0x20(%rsp), %rax
movq 0xe0(%rax), %rdi
pushq $0x48
popq %rdx
leaq -0x9c24(%rip), %rcx     # 0xc7fcf
callq 0x23f0
movq 0x48(%rsp), %rcx
movq (%rcx), %rax
imulq $0x18, 0x88(%rsp), %rdx
movq %rdx, 0xd8(%rsp)
movq (%rax,%rdx), %rax
movq %rax, 0x110(%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
xorl %r12d, %r12d
movl %r14d, %r14d
movq 0xf0(%rsp), %rax
cmpq %r14, (%rax)
jbe 0xd2002
movq 0x20(%rsp), %rax
movq 0xe0(%rax), %rdi
imulq $0x48, %r14, %rbx
movsd (%rdi,%rbx), %xmm0
movsd 0x11161a(%rip), %xmm2   # 0x1e3270
unpcklps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x11161f(%rip), %xmm3   # 0x1e3280
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movq %rbp, %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm3, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
mulsd 0x119916(%rip), %xmm2   # 0x1eb5a8
ucomisd %xmm1, %xmm2
ja 0xd1ffa
addq %rbx, %rdi
xorl %eax, %eax
leaq 0x181ab0(%rip), %rcx    # 0x253758
cmpl $0x3, 0x130(%rcx)
setge %al
subq $0x90, %rsp
leaq 0x15c(%rsp), %rcx
movq %rcx, 0x88(%rsp)
leaq 0x1f8(%rsp), %rcx
movq %rcx, 0x80(%rsp)
leaq 0x188(%rsp), %rcx
movq %rcx, 0x78(%rsp)
leaq 0x200(%rsp), %rcx
movq %rcx, 0x70(%rsp)
leaq 0x208(%rsp), %rcx
movq %rcx, 0x68(%rsp)
movq 0x1c8(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movq 0x170(%rsp), %rcx
movq %rcx, 0x58(%rsp)
movq 0x178(%rsp), %rcx
movq %rcx, 0x50(%rsp)
movq 0xf8(%rsp), %rcx
movq %rcx, 0x48(%rsp)
movq 0x1d0(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movl 0x108(%rsp), %ecx
movl %ecx, 0x38(%rsp)
movl 0x10c(%rsp), %ecx
movl %ecx, 0x30(%rsp)
movq %r13, 0x20(%rsp)
movq 0xe0(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq 0xe8(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq 0x138(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movl %eax, 0x28(%rsp)
movq 0x128(%rsp), %rsi
movq 0x140(%rsp), %rdx
movq 0x100(%rsp), %rcx
movq %r15, %r8
movq 0xf0(%rsp), %r9
movss 0xd4(%rsp), %xmm0
callq 0xcc3e7
addq $0x90, %rsp
testl %eax, %eax
je 0xd1dcd
movq 0x48(%rsp), %rcx
jmp 0xd1ffa
movq 0x20(%rsp), %rax
movq 0xe0(%rax), %rax
movq 0x20(%rax,%rbx), %rdi
cmpq %rdi, %r12
cmovleq %rdi, %r12
movq (%rax,%rbx), %r8
testq %rbp, %rbp
cmoveq %rdi, %r12
cmpq %r8, %rbp
cmovbeq %r8, %rbp
movq %r12, %rcx
subq %rdi, %rcx
jle 0xd1e21
movq %r12, %rdx
negq %rdx
cmovsq %r12, %rdx
cvtsi2sd %rcx, %xmm0
cvtsi2sd %rdx, %xmm1
mulsd 0x119795(%rip), %xmm1   # 0x1eb5b0
ucomisd %xmm1, %xmm0
jae 0xd1dc3
addq %rbx, %rax
movb 0x28(%rax), %r9b
movl 0x168(%rsp), %ebx
testb %r9b, %r9b
movq %r12, 0x10(%rsp)
movq %rbp, 0x28(%rsp)
je 0xd1e5e
movq 0x60(%rsp), %rcx
movl (%rcx), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
notl %ebx
addl %ecx, %ebx
subl 0xf8(%rsp), %ecx
movl %ebx, %r10d
movl %ecx, %ebx
jmp 0xd1e68
movl 0xf8(%rsp), %r10d
incl %ebx
movb 0x1c(%rax), %cl
movb %cl, 0x3c(%rsp)
movl 0x8(%rax), %ecx
movl %ecx, 0x40(%rsp)
movl 0xc(%rax), %ecx
movl %ecx, 0xa0(%rsp)
movl 0x10(%rax), %ecx
movl %ecx, 0x90(%rsp)
movl 0x14(%rax), %r11d
movl 0x178(%rsp), %eax
movl %eax, 0xc8(%rsp)
movl 0x170(%rsp), %ebp
movss 0xcc(%rsp), %xmm0
movq 0x48(%rsp), %r15
movq (%r15), %rcx
movq 0xd8(%rsp), %r12
movq (%rcx,%r12), %rax
cmpq 0x8(%rcx,%r12), %rax
jne 0xd1f57
leaq (%rax,%rax), %rsi
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rsi
leaq (%rcx,%r12), %rax
movq %rsi, 0x8(%rcx,%r12)
movq %rdi, 0x128(%rsp)
movq 0x10(%rax), %rdi
shlq $0x6, %rsi
movq %r8, 0x120(%rsp)
movb %r9b, 0x7(%rsp)
movl %r10d, 0xc4(%rsp)
movss %xmm0, 0xc0(%rsp)
movl %r11d, 0xbc(%rsp)
callq 0x2370
movl 0xbc(%rsp), %r11d
movss 0xc0(%rsp), %xmm0
movl 0xc4(%rsp), %r10d
movb 0x7(%rsp), %r9b
movq 0x120(%rsp), %r8
movq 0x128(%rsp), %rdi
movq (%r15), %rcx
movq %rax, 0x10(%rcx,%r12)
movq (%rcx,%r12), %rax
movq 0x10(%rcx,%r12), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, (%rcx,%r12)
shlq $0x6, %rax
movb %r9b, (%rdx,%rax)
movb 0x3c(%rsp), %cl
movb %cl, 0x1(%rdx,%rax)
andw $0x0, 0x2(%rdx,%rax)
movl 0xc8(%rsp), %ecx
movl %ecx, 0x4(%rdx,%rax)
incl %ebp
movl %ebp, 0x8(%rdx,%rax)
movl %r10d, 0xc(%rdx,%rax)
movl %ebx, 0x10(%rdx,%rax)
movl 0x40(%rsp), %ecx
movl %ecx, 0x14(%rdx,%rax)
movl 0xa0(%rsp), %ecx
incl %ecx
movl %ecx, 0x18(%rdx,%rax)
movl 0x90(%rsp), %ecx
movl %ecx, 0x1c(%rdx,%rax)
incl %r11d
movl %r11d, 0x20(%rdx,%rax)
movq 0xb0(%rsp), %rcx
movl %ecx, 0x24(%rdx,%rax)
movq 0x70(%rsp), %rcx
movl %ecx, 0x28(%rdx,%rax)
movl %r8d, 0x2c(%rdx,%rax)
movq %rdi, 0x30(%rdx,%rax)
movss %xmm0, 0x38(%rdx,%rax)
andl $0x0, 0x3c(%rdx,%rax)
movq 0x48(%rsp), %rcx
movq 0x30(%rsp), %r15
movq 0x10(%rsp), %r12
movq 0x28(%rsp), %rbp
incl %r14d
jmp 0xd1c25
movq (%rcx), %rax
movq 0xd8(%rsp), %r10
movq (%rax,%r10), %rdx
addq %r10, %rax
movq 0x110(%rsp), %r11
movl %r11d, %esi
xorl %ecx, %ecx
movl %esi, %esi
cmpq %rsi, %rdx
jbe 0xd206f
movq 0x10(%rax), %rdi
movq %rsi, %r8
shlq $0x6, %r8
cmpq %r12, 0x30(%rdi,%r8)
jne 0xd204f
addq %r8, %rdi
testq %rcx, %rcx
je 0xd204c
movl 0x2c(%rcx), %r8d
cmpl %r8d, 0x2c(%rdi)
jbe 0xd2053
movq %rdi, %rcx
incl %esi
jmp 0xd2021
jne 0xd204f
movl 0x8(%rdi), %r8d
subl 0x4(%rdi), %r8d
movl 0x8(%rcx), %r9d
subl 0x4(%rcx), %r9d
cmpl %r9d, %r8d
jb 0xd204c
movq %rcx, %rdi
jmp 0xd204c
testq %rcx, %rcx
je 0xd20b8
movq 0x10(%rax), %rax
movq %r11, %rdx
shlq $0x6, %rdx
movupd (%rcx), %xmm0
movupd 0x10(%rcx), %xmm1
movupd 0x20(%rcx), %xmm2
movupd 0x30(%rcx), %xmm3
movupd %xmm3, 0x30(%rax,%rdx)
movupd %xmm2, 0x20(%rax,%rdx)
movupd %xmm1, 0x10(%rax,%rdx)
movupd %xmm0, (%rax,%rdx)
incq %r11
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %r11, (%rax,%r10)
movq 0x130(%rsp), %rcx
incl %ecx
jmp 0xd179e
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq