// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: chain_trans_ovlp(hap_cov_t*, utg_trans_t*, ma_ug_t*, asg_t*, buf_t*, unsigned int, unsigned int*)
void chain_trans_ovlp(hap_cov_t *cover, utg_trans_t *o, ma_ug_t *ug, asg_t *read_sg, buf_t* xReads, uint32_t targetBaseLen, uint32_t* xEnd)
{
    ma_hit_t_alloc* reverse_sources = (o? o->reverse_sources:cover->reverse_sources);
    ma_sub_t *coverage_cut = (o? o->coverage_cut:cover->coverage_cut);
    int max_hang = (o? o->max_hang:cover->max_hang);
    int min_ovlp = (o? o->min_ovlp:cover->min_ovlp);
    kvec_asg_arc_t_offset* u_buffer = (o? &(o->u_buffer):&(cover->u_buffer));
    kvec_t_i32_warp* tailIndex = (o? &(o->tailIndex):&(cover->tailIndex));
    kvec_t_i32_warp* prevIndex = (o? &(o->prevIndex):&(cover->prevIndex));
    uint64_t *pos_idx = (o? o->pos_idx:cover->pos_idx);
    ma_hit_t_alloc *xR = NULL;
    ma_hit_t *h = NULL;
    ma_sub_t *sq = NULL, *st = NULL;
    int32_t r;
    asg_arc_t t;
    uint32_t rId, v, w;
    uint64_t tmp;
    asg_arc_t_offset t_offset;
    u_buffer->a.n = 0;
    ///(*xEnd) = (uint32_t)-1;
    (*xEnd) = 0;
    uint32_t u_i, r_i, k, j, len, p_v, *a = xReads->b.a, uid, ori, l, m, aOcc, nv, xOcc = (uint32_t)-1;
    ma_utg_t* u = NULL;
    asg_arc_t *av  = NULL;


    for (u_i = r_i = len = aOcc = 0, xOcc = (uint32_t)-1, p_v = (uint32_t)-1; u_i < xReads->b.n; u_i++)
    {
        uid = a[u_i] >> 1;
        ori = a[u_i] & 1;
        u = &(ug->u.a[uid]);
        if(u->n == 0) continue;

        for (r_i = 0; r_i < u->n; r_i++, aOcc++)
        {
            l = 0;
            v = (ori == 1?((uint64_t)((u->a[u->n - r_i - 1])^(uint64_t)(0x100000000)))>>32:((uint64_t)(u->a[r_i]))>>32);

            if(p_v != (uint32_t)-1)
            {
                av = asg_arc_a(read_sg, p_v);
                nv = asg_arc_n(read_sg, p_v);
                
                for (k = 0; k < nv; k++)
                {
                    if(av[k].del) continue;
                    if(av[k].v == v) 
                    {
                        l = asg_arc_len(av[k]);
                        break;
                    }
                }
                if(k == nv) fprintf(stderr, "ERROR\n");
            }

            p_v = v; len += l;
            if(len >= targetBaseLen)///might be not right for centromeres 
            {
                xOcc = aOcc;
                break;
            }
        }

        if(xOcc != (uint32_t)-1) break;
    }
    if(xOcc == (uint32_t)-1) xOcc = aOcc;
    if(xOcc == 0) xOcc = 1;



    for (u_i = r_i = len = aOcc = 0, p_v = (uint32_t)-1; u_i < xReads->b.n; u_i++)
    {
        uid = a[u_i] >> 1;
        ori = a[u_i] & 1;
        u = &(ug->u.a[uid]);
        if(u->n == 0) continue;

        for (r_i = 0; r_i < u->n; r_i++, aOcc++)
        {
            if(aOcc >= xOcc) break;
            l = 0;
            v = (ori == 1?((uint64_t)((u->a[u->n - r_i - 1])^(uint64_t)(0x100000000)))>>32:((uint64_t)(u->a[r_i]))>>32);

            if(p_v != (uint32_t)-1)
            {
                av = asg_arc_a(read_sg, p_v);
                nv = asg_arc_n(read_sg, p_v);
                
                for (k = 0; k < nv; k++)
                {
                    if(av[k].del) continue;
                    if(av[k].v == v) 
                    {
                        l = asg_arc_len(av[k]);
                        break;
                    }
                }
                if(k == nv) fprintf(stderr, "ERROR\n");
            }

            p_v = v; len += l;

            xR = &(reverse_sources[v>>1]);
            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_sg->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_sg->seq[rId].del == 1) continue;
                if(pos_idx[rId] == (uint64_t)-1) continue;
                w = (uint32_t)(pos_idx[rId]);
                if(rId != (w>>1)) continue;

                tmp = get_xy_pos_by_pos(read_sg, &t, v, w, len, pos_idx[w>>1]>>32,
                                                    (uint32_t)-1, targetBaseLen, &(t.el));
                if(((tmp>>32) == (uint32_t)-1) || (((uint32_t)tmp) == (uint32_t)-1)) continue;
                if(t.el) continue; ///must

                t_offset.Off = tmp;
                t_offset.x = t;
                t_offset.weight = 1;
                kv_push(asg_arc_t_offset, u_buffer->a, t_offset); 
            }
        }

        if(aOcc >= xOcc) break;
    }

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

    qsort(u_buffer->a.a, u_buffer->a.n, sizeof(asg_arc_t_offset), cmp_hap_alignment_chaining);

    ///print_asg_arc_t_offset(u_buffer->a.a, u_buffer->a.n, "before");


    for (k = 1, l = 0, m = 0; k <= u_buffer->a.n; ++k)
    {
        if (k == u_buffer->a.n || u_buffer->a.a[k].x.el != u_buffer->a.a[l].x.el || 
                                            u_buffer->a.a[k].Off != u_buffer->a.a[l].Off) 
        {
            u_buffer->a.a[m] = u_buffer->a.a[l];
            for (l += 1; l < k; l++)
            {
                u_buffer->a.a[m].weight += u_buffer->a.a[l].weight;
                if(u_buffer->a.a[l].x.ol > u_buffer->a.a[m].x.ol)
                {
                    u_buffer->a.a[m].x = u_buffer->a.a[l].x;
                }
            }
            l = k;
            m++;
        }
    } 
    u_buffer->a.n = m;

    ///print_asg_arc_t_offset(u_buffer->a.a, u_buffer->a.n, "after");
    quick_LIS(u_buffer->a.a, u_buffer->a.n, tailIndex, prevIndex);
    if(tailIndex->a.n == 0) return;


    uint32_t xLen_thres = (uint32_t)-1;
    asg_arc_t_offset* best = &(u_buffer->a.a[tailIndex->a.a[tailIndex->a.n-1]]);
    for (u_i = r_i = len = aOcc = 0, p_v = (uint32_t)-1; u_i < xReads->b.n; u_i++)
    {
        uid = a[u_i] >> 1;
        ori = a[u_i] & 1;
        u = &(ug->u.a[uid]);
        if(u->n == 0) continue;

        for (r_i = 0; r_i < u->n; r_i++, aOcc++)
        {
            l = 0;
            v = (ori == 1?((uint64_t)((u->a[u->n - r_i - 1])^(uint64_t)(0x100000000)))>>32:((uint64_t)(u->a[r_i]))>>32);

            if(p_v != (uint32_t)-1)
            {
                av = asg_arc_a(read_sg, p_v);
                nv = asg_arc_n(read_sg, p_v);
                
                for (k = 0; k < nv; k++)
                {
                    if(av[k].del) continue;
                    if(av[k].v == v) 
                    {
                        l = asg_arc_len(av[k]);
                        break;
                    }
                }
                if(k == nv) fprintf(stderr, "ERROR\n");
            }

            p_v = v; len += l;

            if((v>>1) == (best->x.ul>>33) && xLen_thres == (uint32_t)-1)
            {
                ///cov->pos_idx[v>>1] = len; 
                xR = &(reverse_sources[v>>1]);
                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_sg->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_sg->seq[rId].del == 1) continue;
                    if(pos_idx[rId] == (uint64_t)-1) continue;
                    w = (uint32_t)(pos_idx[rId]);
                    if(rId != (w>>1)) continue;

                    tmp = get_xy_pos_by_pos(read_sg, &t, v, w, len, pos_idx[w>>1]>>32,
                                                        (uint32_t)-1, targetBaseLen, &(t.el));
                    if(((tmp>>32) == (uint32_t)-1) || (((uint32_t)tmp) == (uint32_t)-1)) continue;
                    if(t.el) continue; ///must

                    t_offset.Off = tmp;
                    t_offset.x = t;
                    t_offset.weight = 1;
                    if(t_offset.Off == best->Off && t_offset.x.v == best->x.v && t_offset.x.ul == best->x.ul)
                    {
                        xLen_thres = Get_xOff(best->Off) + targetBaseLen - Get_yOff(best->Off);
                    }
                }
            }

            if(len >= xLen_thres)
            {
                (*xEnd) = aOcc;
                return;
            }
        }
    }

    (*xEnd) = aOcc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r9, 0x48(%rsp)
leaq 0x18(%rdi), %rax
leaq 0x8(%rsi), %r11
leaq 0x20(%rdi), %r14
leaq 0x38(%rdi), %r9
leaq 0x3c(%rdi), %r10
leaq 0x40(%rdi), %r15
leaq 0x60(%rdi), %r12
leaq 0x80(%rdi), %r13
addq $0x10, %rdi
testq %rsi, %rsi
cmovneq %r11, %r14
leaq 0x110(%rsi), %r11
leaq 0x114(%rsi), %rbx
cmovneq %r11, %r9
leaq 0x20(%rsi), %r11
cmovneq %rbx, %r10
leaq 0x40(%rsi), %rbx
cmovneq %rsi, %rax
cmovneq %r11, %r15
leaq 0x60(%rsi), %r11
leaq 0xe0(%rsi), %rsi
movq (%rax), %rax
movq %rax, 0xa8(%rsp)
movq (%r14), %rbp
movl (%r9), %eax
movl %eax, 0x3c(%rsp)
movl (%r10), %eax
movl %eax, 0x38(%rsp)
cmovneq %rbx, %r12
movq %r12, 0x98(%rsp)
cmovneq %r11, %r13
movq %r13, 0xb8(%rsp)
cmovneq %rsi, %rdi
movq (%rdi), %rax
movq %rax, 0xb0(%rsp)
movq %r15, 0x10(%rsp)
andq $0x0, (%r15)
movq 0x100(%rsp), %rax
andl $0x0, (%rax)
movq %rcx, 0x18(%rsp)
movq %rdx, 0x70(%rsp)
movq %r8, 0x78(%rsp)
movq 0x48(%r8), %rax
movq %rax, 0x68(%rsp)
pushq $-0x1
popq %rax
xorl %esi, %esi
xorl %ebx, %ebx
xorl %edi, %edi
movl %esi, %esi
movq 0x78(%rsp), %rcx
cmpq %rsi, 0x38(%rcx)
jbe 0xca106
movq 0x68(%rsp), %rcx
movl (%rcx,%rsi,4), %r8d
movl %r8d, %ecx
shrl %ecx
movq 0x70(%rsp), %rdx
movq 0x10(%rdx), %r14
imulq $0x28, %rcx, %rdx
movl 0x10(%r14,%rdx), %ecx
testl %ecx, %ecx
je 0xca0da
movq %rsi, 0x30(%rsp)
addq %rdx, %r14
xorl %r13d, %r13d
movl %r8d, 0xc(%rsp)
movl %ecx, %edx
cmpq %rdx, %r13
jae 0xca0e1
movq 0x18(%r14), %rdx
testb $0x1, %r8b
jne 0xca02e
movl 0x4(%rdx,%r13,8), %r15d
jmp 0xca03e
movl %r13d, %esi
notl %esi
addl %esi, %ecx
movl 0x4(%rdx,%rcx,8), %r15d
xorq $0x1, %r15
cmpl $-0x1, %eax
je 0xca08f
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rdx
movq 0x28(%rcx), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rax
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
imulq $0x18, %rsi, %rsi
addq %rsi, %rdx
addq $0xc, %rdx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0xca0ac
cmpl $0x0, (%rdx)
js 0xca07c
cmpl %r15d, -0x4(%rdx)
je 0xca085
incq %rsi
addq $0x18, %rdx
jmp 0xca06c
movl -0xc(%rdx), %r12d
cmpl %esi, %eax
jne 0xca092
jmp 0xca0af
xorl %r12d, %r12d
addl %r12d, %ebx
cmpl 0x48(%rsp), %ebx
jae 0xca0ed
incq %r13
incl %edi
movl 0x10(%r14), %ecx
movl %r15d, %eax
jmp 0xca012
xorl %r12d, %r12d
movq 0x188f2a(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
movl %edi, 0x28(%rsp)
leaq 0x120cc0(%rip), %rdi    # 0x1ead84
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movl 0xc(%rsp), %r8d
movl 0x28(%rsp), %edi
jmp 0xca092
movl %eax, %r15d
movl %edi, %ecx
jmp 0xca0fa
movl %eax, %r15d
movl %edi, %ecx
movq 0x30(%rsp), %rsi
jmp 0xca0fa
pushq $-0x1
popq %rcx
cmpl $-0x1, %edi
movq 0x30(%rsp), %rsi
jne 0xca106
incl %esi
movl %r15d, %eax
movl %ecx, %edi
jmp 0xc9fc9
cmpl $0x1, %edi
adcl $0x0, %edi
pushq $-0x1
popq %rax
xorl %edx, %edx
movl $0x0, 0xc(%rsp)
xorl %r8d, %r8d
movq 0x10(%rsp), %rbx
movl %edi, 0x28(%rsp)
movq %rbp, 0xc0(%rsp)
movl %edx, %edx
movq 0x78(%rsp), %rcx
cmpq %rdx, 0x38(%rcx)
jbe 0xca464
movq 0x68(%rsp), %rcx
movq %rdx, 0xa0(%rsp)
movl (%rcx,%rdx,4), %ecx
movl %ecx, 0x24(%rsp)
shrl %ecx
movq 0x70(%rsp), %rdx
movq 0x10(%rdx), %rsi
imulq $0x28, %rcx, %rdx
movl 0x10(%rsi,%rdx), %ecx
testl %ecx, %ecx
je 0xca455
addq %rdx, %rsi
xorl %r9d, %r9d
movq %rsi, 0x40(%rsp)
movl %ecx, %edx
cmpq %rdx, %r9
jae 0xca446
cmpl %edi, %r8d
jae 0xca446
movq 0x18(%rsi), %rdx
testb $0x1, 0x24(%rsp)
jne 0xca19e
movl 0x4(%rdx,%r9,8), %ebx
jmp 0xca1ad
movl %r9d, %esi
notl %esi
addl %esi, %ecx
movl 0x4(%rdx,%rcx,8), %ebx
xorq $0x1, %rbx
cmpl $-0x1, %eax
movl %r8d, 0x30(%rsp)
movq %r9, 0x90(%rsp)
je 0xca211
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rdx
movq 0x28(%rcx), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rax
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
imulq $0x18, %rsi, %rsi
addq %rsi, %rdx
addq $0xc, %rdx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0xca422
cmpl $0x0, (%rdx)
js 0xca1fb
cmpl %ebx, -0x4(%rdx)
je 0xca204
incq %rsi
addq $0x18, %rdx
jmp 0xca1e8
movl -0xc(%rdx), %r14d
cmpl %esi, %eax
jne 0xca214
jmp 0xca425
xorl %r14d, %r14d
addl %r14d, 0xc(%rsp)
movl %ebx, %eax
shrl %eax
imulq $0x18, %rax, %r15
addq 0xa8(%rsp), %r15
xorl %r14d, %r14d
xorl %r12d, %r12d
movl 0xc(%r15), %eax
cmpq %rax, %r12
jae 0xca3f7
movq (%r15), %rdi
movl 0xc(%rdi,%r14), %edx
imulq $0xc, %rdx, %rcx
movl (%rbp,%rcx), %eax
testl %eax, %eax
js 0xca3eb
movq 0x18(%rsp), %rsi
movq 0x20(%rsi), %r13
cmpl $0x0, (%r13,%rdx,8)
js 0xca3eb
movl 0x4(%rdi,%r14), %edx
addq %r14, %rdi
imulq $0xc, %rdx, %rdx
addq %rbp, %rdx
addq %rbp, %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 0x1894c1(%rip), %rax    # 0x253758
movss 0x158(%rax), %xmm0
movl 0x3c(%rsp), %ecx
movl 0x38(%rsp), %r8d
leaq 0x50(%rsp), %r9
callq 0xc99c6
testl %eax, %eax
js 0xca3eb
movl 0x58(%rsp), %eax
shrl %eax
cmpl $0x0, (%r13,%rax,8)
js 0xca3eb
movq 0xb0(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
cmpq $-0x1, %rcx
je 0xca3eb
movl %ecx, %edx
shrl %edx
cmpl %edx, %eax
jne 0xca3eb
movq %rcx, %r9
shrq $0x20, %r9
subq $0x8, %rsp
movq 0x20(%rsp), %rdi
leaq 0x58(%rsp), %rsi
movl %ebx, %edx
movl 0x14(%rsp), %r8d
leaq 0x6a(%rsp), %rax
pushq %rax
pushq 0x58(%rsp)
pushq $-0x1
callq 0xc9db2
addq $0x20, %rsp
movq %rax, %r13
movabsq $-0x100000001, %rax     # imm = 0xFFFFFFFEFFFFFFFF
cmpq %rax, %r13
ja 0xca3eb
movl %r13d, %eax
cmpl $-0x1, %eax
je 0xca3eb
cmpb $0x0, 0x62(%rsp)
jne 0xca3eb
movq 0x50(%rsp), %rsi
movl 0x58(%rsp), %edi
movq 0x10(%rsp), %rbp
movq (%rbp), %rcx
movq 0x10(%rbp), %rax
cmpq 0x8(%rbp), %rcx
jne 0xca3ac
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rbp)
movq %rsi, 0x88(%rsp)
imulq $0x28, %rdx, %rsi
movl %edi, 0x80(%rsp)
movq %rax, %rdi
callq 0x2370
movl 0x80(%rsp), %edi
movq 0x88(%rsp), %rsi
movq %rax, 0x10(%rbp)
movq (%rbp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbp)
imulq $0x28, %rcx, %rcx
movq %rsi, (%rax,%rcx)
movl %edi, 0x8(%rax,%rcx)
leaq 0x62(%rsp), %rsi
movq -0x6(%rsi), %rdx
movq %rdx, 0xc(%rax,%rcx)
movl 0x2(%rsi), %edx
movl %edx, 0x14(%rax,%rcx)
movq %r13, 0x18(%rax,%rcx)
movq $0x1, 0x20(%rax,%rcx)
movq 0xc0(%rsp), %rbp
incq %r12
addq $0x28, %r14
jmp 0xca22f
movq 0x90(%rsp), %r9
incq %r9
movl 0x30(%rsp), %r8d
incl %r8d
movq 0x40(%rsp), %rsi
movl 0x10(%rsi), %ecx
movl %ebx, %eax
movq 0x10(%rsp), %rbx
movl 0x28(%rsp), %edi
jmp 0xca178
xorl %r14d, %r14d
movq 0x188bb4(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x12094e(%rip), %rdi    # 0x1ead84
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xca214
cmpl %edi, %r8d
movq 0xa0(%rsp), %rdx
jb 0xca45d
jmp 0xca464
movq 0xa0(%rsp), %rdx
incl %edx
jmp 0xca12d
movq (%rbx), %rsi
testq %rsi, %rsi
je 0xca8a1
movq 0x10(%rbx), %rdi
leaq -0x24ed(%rip), %rcx     # 0xc7f8e
pushq $0x28
popq %rdx
callq 0x23f0
xorl %edx, %edx
pushq $0x1
popq %rax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %esi, %esi
movl %eax, %r10d
movl %esi, %edi
cmpq %r10, (%rbx)
jb 0xca555
movq 0x10(%rbx), %r8
movl %edx, %r9d
je 0xca4d6
imulq $0x28, %r10, %r10
movb 0x12(%r8,%r10), %bl
imulq $0x28, %r9, %r11
cmpb 0x12(%r8,%r11), %bl
jne 0xca4d1
addq %r8, %r10
addq %r8, %r11
movq 0x18(%r10), %r10
cmpq 0x18(%r11), %r10
movq 0x10(%rsp), %rbx
jne 0xca4d6
jmp 0xca54e
movq 0x10(%rsp), %rbx
imulq $0x28, %r9, %r9
imulq $0x28, %rdi, %rdi
movq 0x20(%r8,%r9), %r10
movq %r10, 0x20(%r8,%rdi)
movups (%r8,%r9), %xmm0
movups 0x10(%r8,%r9), %xmm1
movups %xmm1, 0x10(%r8,%rdi)
movups %xmm0, (%r8,%rdi)
incl %edx
imulq $0x28, %rdx, %r8
cmpl %eax, %edx
jae 0xca54a
movq 0x10(%rbx), %r9
movq 0x20(%r9,%r8), %r10
addq %r10, 0x20(%r9,%rdi)
movl 0xc(%r9,%r8), %r10d
andl %ecx, %r10d
movl 0xc(%r9,%rdi), %r11d
andl %ecx, %r11d
cmpl %r11d, %r10d
jbe 0xca542
leaq (%r9,%r8), %r10
addq %rdi, %r9
movq 0x10(%r10), %r11
movq %r11, 0x10(%r9)
movups (%r10), %xmm0
movups %xmm0, (%r9)
incl %edx
addq $0x28, %r8
jmp 0xca504
incl %esi
movl %eax, %edx
incl %eax
jmp 0xca48f
movq %rdi, (%rbx)
movq 0x10(%rbx), %rdi
movq 0x98(%rsp), %r14
movq %r14, %rdx
movq 0xb8(%rsp), %rcx
callq 0xc9be5
movq (%r14), %rax
testq %rax, %rax
je 0xca8a1
movq 0x98(%rsp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x4(%rcx,%rax,4), %rax
imulq $0x28, %rax, %r14
addq 0x10(%rbx), %r14
movl 0x48(%rsp), %eax
movq %rax, 0x80(%rsp)
pushq $-0x1
popq %rcx
xorl %edx, %edx
movl $0x0, 0xc(%rsp)
movl %ecx, %eax
xorl %r15d, %r15d
movl %ecx, %edi
movq %r14, 0x40(%rsp)
movl %edx, %edx
movq 0x78(%rsp), %rcx
cmpq %rdx, 0x38(%rcx)
jbe 0xca896
movq 0x68(%rsp), %rcx
movq %rdx, 0x88(%rsp)
movl (%rcx,%rdx,4), %ecx
movl %ecx, 0x90(%rsp)
shrl %ecx
movq 0x70(%rsp), %rdx
movq 0x10(%rdx), %rsi
imulq $0x28, %rcx, %rdx
movl 0x10(%rsi,%rdx), %ecx
testl %ecx, %ecx
je 0xca887
addq %rdx, %rsi
xorl %r8d, %r8d
movq %rsi, 0x10(%rsp)
movl %ecx, %edx
cmpq %rdx, %r8
jae 0xca887
movq 0x18(%rsi), %rdx
testb $0x1, 0x90(%rsp)
jne 0xca62c
movl 0x4(%rdx,%r8,8), %r13d
jmp 0xca63c
movl %r8d, %esi
notl %esi
addl %esi, %ecx
movl 0x4(%rdx,%rcx,8), %r13d
xorq $0x1, %r13
cmpl $-0x1, %eax
movq %r8, 0x30(%rsp)
je 0xca69b
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rdx
movq 0x28(%rcx), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rax
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
imulq $0x18, %rsi, %rsi
addq %rsi, %rdx
addq $0xc, %rdx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0xca861
cmpl $0x0, (%rdx)
js 0xca683
cmpl %r13d, -0x4(%rdx)
je 0xca68c
incq %rsi
addq $0x18, %rdx
jmp 0xca66f
movq %rdi, %r12
movl -0xc(%rdx), %ebx
cmpl %esi, %eax
jne 0xca6a0
jmp 0xca866
movq %rdi, %r12
xorl %ebx, %ebx
addl %ebx, 0xc(%rsp)
movl %r13d, %eax
shrl %eax
movq (%r14), %rcx
shrq $0x21, %rcx
movq %r12, %rdi
cmpq %rcx, %rax
jne 0xca840
cmpl $-0x1, %edi
jne 0xca840
movl %r15d, 0x24(%rsp)
imulq $0x18, %rax, %rbx
addq 0xa8(%rsp), %rbx
xorl %r14d, %r14d
xorl %r15d, %r15d
pushq $-0x1
popq %rax
movq %rax, 0x28(%rsp)
movl 0xc(%rbx), %eax
cmpq %rax, %r15
jae 0xca831
movq (%rbx), %rdi
movl 0xc(%rdi,%r14), %edx
imulq $0xc, %rdx, %rcx
movl (%rbp,%rcx), %eax
testl %eax, %eax
js 0xca825
movq 0x18(%rsp), %rsi
movq 0x20(%rsi), %r12
cmpl $0x0, (%r12,%rdx,8)
js 0xca825
movl 0x4(%rdi,%r14), %edx
addq %r14, %rdi
imulq $0xc, %rdx, %rdx
addq %rbp, %rdx
addq %rbp, %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 0x18900e(%rip), %rax    # 0x253758
movss 0x158(%rax), %xmm0
movl 0x3c(%rsp), %ecx
movl 0x38(%rsp), %r8d
leaq 0x50(%rsp), %r9
callq 0xc99c6
testl %eax, %eax
js 0xca825
movl 0x58(%rsp), %eax
shrl %eax
cmpl $0x0, (%r12,%rax,8)
js 0xca825
movq 0xb0(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
cmpq $-0x1, %rcx
je 0xca825
movl %ecx, %edx
shrl %edx
cmpl %edx, %eax
jne 0xca825
movq %rcx, %r9
shrq $0x20, %r9
subq $0x8, %rsp
movq 0x20(%rsp), %rdi
leaq 0x58(%rsp), %rsi
movl %r13d, %edx
movl 0x14(%rsp), %r8d
leaq 0x6a(%rsp), %rax
pushq %rax
pushq 0x58(%rsp)
pushq $-0x1
callq 0xc9db2
addq $0x20, %rsp
movabsq $-0x100000001, %rcx     # imm = 0xFFFFFFFEFFFFFFFF
cmpq %rcx, %rax
ja 0xca825
movl %eax, %ecx
cmpl $-0x1, %ecx
je 0xca825
cmpb $0x0, 0x62(%rsp)
jne 0xca825
movq 0x40(%rsp), %rdx
cmpq 0x18(%rdx), %rax
jne 0xca825
movl 0x58(%rsp), %ecx
cmpl 0x8(%rdx), %ecx
jne 0xca825
movq 0x50(%rsp), %rcx
cmpq (%rdx), %rcx
jne 0xca825
movq %rax, %rdx
shrq $0x20, %rdx
movq 0x80(%rsp), %rcx
subl %eax, %ecx
addl %ecx, %edx
movq %rdx, 0x28(%rsp)
incq %r15
addq $0x28, %r14
jmp 0xca6e4
movq 0x40(%rsp), %r14
movl 0x24(%rsp), %r15d
movq 0x28(%rsp), %rdi
cmpl %edi, 0xc(%rsp)
movq 0x10(%rsp), %rsi
movq 0x30(%rsp), %r8
jae 0xca896
incq %r8
incl %r15d
movl 0x10(%rsi), %ecx
movl %r13d, %eax
jmp 0xca60c
movq %rdi, %r12
xorl %ebx, %ebx
movq 0x188773(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x12050d(%rip), %rdi    # 0x1ead84
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xca6a0
movq 0x88(%rsp), %rdx
incl %edx
jmp 0xca5be
movq 0x100(%rsp), %rax
movl %r15d, (%rax)
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq