// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Assembly.cpp
// Function: rescue_edges(ma_hit_t_alloc*, ma_hit_t_alloc*, long long, long long, float)
void rescue_edges(ma_hit_t_alloc* paf, ma_hit_t_alloc* rev_paf, 
long long readNum, long long rescue_threshold, float cluster_threshold)
{
    double startTime = Get_T();
    long long i, j, revises = 0;
    uint32_t qn, tn;

    kvec_t(uint64_t) edge_vector;
    kv_init(edge_vector);
    kvec_t(uint64_t) edge_vector_index;
    kv_init(edge_vector_index);
    uint64_t flag;
    int index;

    for (i = 0; i < readNum; i++)
    {
        edge_vector.n = 0;
        edge_vector_index.n = 0;
        for (j = 0; j < paf[i].length; j++)
        {
            qn = Get_qn(paf[i].buffer[j]);
            tn = Get_tn(paf[i].buffer[j]);
            index = get_specific_overlap(&(rev_paf[tn]), tn, qn);
            if(index != -1)
            {
                flag = tn;
                flag = flag << 32;
                flag = flag | (uint64_t)(index);
                kv_push(uint64_t, edge_vector, flag);
                kv_push(uint64_t, edge_vector_index, j);
            }
        }

        ///the read itself has these overlaps, but all related reads do not have 
        ///we need to remove all overlaps from paf[i], and then add all overlaps to rev_paf[i]
        if((long long)edge_vector.n >= rescue_threshold && 
        check_cluster(edge_vector.a, edge_vector.n, paf, cluster_threshold) == 1)
        {
            add_overlaps(&(paf[i]), &(rev_paf[i]), edge_vector_index.a, edge_vector_index.n);
            remove_overlaps(&(paf[i]), edge_vector_index.a, edge_vector_index.n);
            revises = revises + edge_vector.n;
        }

        edge_vector.n = 0;
        edge_vector_index.n = 0;
        for (j = 0; j < rev_paf[i].length; j++)
        {
            qn = Get_qn(rev_paf[i].buffer[j]);
            tn = Get_tn(rev_paf[i].buffer[j]);
            index = get_specific_overlap(&(paf[tn]), tn, qn);
            if(index != -1)
            {
                flag = tn;
                flag = flag << 32;
                flag = flag | (uint64_t)(index);
                kv_push(uint64_t, edge_vector, flag);
                kv_push(uint64_t, edge_vector_index, j);
            }
        }

        ///the read itself do not have these overlaps, but all related reads have
        ///we need to remove all overlaps from rev_paf[i], and then add all overlaps to paf[i]
        if((long long)edge_vector.n >= rescue_threshold && 
        check_cluster(edge_vector.a, edge_vector.n, paf, cluster_threshold) == 1)
        {
            remove_overlaps(&(rev_paf[i]), edge_vector_index.a, edge_vector_index.n);
            add_overlaps_from_different_sources(paf, &(paf[i]), edge_vector.a, edge_vector.n);
            revises = revises + edge_vector.n;
        }
    }


    kv_destroy(edge_vector);
    kv_destroy(edge_vector_index);

    fprintf(stderr, "[M::%s] took %0.2fs, revise edges #: %lld\n\n", __func__, Get_T()-startTime, revises);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movss %xmm0, 0x2c(%rsp)
movq %rcx, 0x58(%rsp)
movq %rdx, %rbx
movq %rsi, 0x50(%rsp)
movq %rdi, %r15
callq 0x2f3fc
movsd %xmm0, 0x60(%rsp)
movq $0x0, 0x30(%rsp)
movl $0x0, %r14d
movl $0x0, %eax
movq %rbx, 0x68(%rsp)
testq %rbx, %rbx
jle 0x455e
movq $0x0, 0x48(%rsp)
xorl %eax, %eax
movq $0x0, 0x40(%rsp)
xorl %r14d, %r14d
movq $0x0, 0x30(%rsp)
xorl %ecx, %ecx
movq %r15, 0x20(%rsp)
movq %r14, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq %rcx, 0x70(%rsp)
imulq $0x18, %rcx, %rax
leaq (%r15,%rax), %r13
movq %rax, 0x18(%rsp)
cmpl $0x0, 0xc(%r15,%rax)
movq %r13, 0x38(%rsp)
je 0x434a
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %ebx, %ebx
movq (%r13), %rax
movl 0x4(%rax,%r15), %edx
movl 0xc(%rax,%r15), %r13d
imulq $0x18, %r13, %rdi
addq 0x50(%rsp), %rdi
movl %r13d, %esi
callq 0xa0c99
movq %rax, %rbp
cmpl $-0x1, %ebp
jne 0x42a7
movq 0x38(%rsp), %r13
jmp 0x4334
cmpq 0x40(%rsp), %r14
jne 0x42d5
leaq (%r14,%r14), %rcx
testq %r14, %r14
pushq $0x2
popq %rax
cmoveq %rax, %rcx
movq %rcx, 0x40(%rsp)
leaq (,%rcx,8), %rsi
movq 0x10(%rsp), %rdi
callq 0x2370
jmp 0x42da
movq 0x10(%rsp), %rax
shlq $0x20, %r13
movslq %ebp, %rcx
orq %r13, %rcx
movq %rax, 0x10(%rsp)
movq %rcx, (%rax,%r14,8)
cmpq 0x48(%rsp), %r12
jne 0x431b
leaq (%r12,%r12), %rax
testq %r12, %r12
pushq $0x2
popq %rcx
cmoveq %rcx, %rax
movq %rax, 0x48(%rsp)
leaq (,%rax,8), %rsi
movq 0x8(%rsp), %rdi
callq 0x2370
jmp 0x4320
movq 0x8(%rsp), %rax
movq 0x38(%rsp), %r13
incq %r14
movq %rax, 0x8(%rsp)
movq %rbx, (%rax,%r12,8)
incq %r12
incq %rbx
movl 0xc(%r13), %eax
addq $0x28, %r15
cmpq %rax, %rbx
jb 0x4276
jmp 0x4350
xorl %r14d, %r14d
xorl %r12d, %r12d
cmpq 0x58(%rsp), %r14
jge 0x435e
movq 0x20(%rsp), %r15
jmp 0x43b1
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movq 0x20(%rsp), %r15
movq %r15, %rdx
movss 0x2c(%rsp), %xmm0
callq 0x3b530
testl %eax, %eax
je 0x43b1
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
leaq (%rax,%rcx), %rsi
movq %r13, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rdx
movq %r12, %rcx
callq 0xa0545
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xa0611
addq %r14, 0x30(%rsp)
movq 0x50(%rsp), %rax
movq 0x18(%rsp), %rcx
leaq (%rax,%rcx), %rbp
cmpl $0x0, 0xc(%rax,%rcx)
je 0x44d6
xorl %ebx, %ebx
movq $0x0, 0x18(%rsp)
xorl %edx, %edx
xorl %r14d, %r14d
movq %rdx, %r13
movq %rbp, %r12
movq (%rbp), %rax
movl 0x4(%rax,%rbx), %edx
movl 0xc(%rax,%rbx), %ebp
imulq $0x18, %rbp, %rdi
addq %r15, %rdi
movl %ebp, %esi
callq 0xa0c99
movq %rax, %r15
cmpl $-0x1, %r15d
jne 0x4413
movq 0x20(%rsp), %r15
movq %r12, %rbp
movq %r13, %rdx
jmp 0x44c1
movq %r13, %rdx
cmpq 0x40(%rsp), %r13
jne 0x4447
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
pushq $0x2
popq %rax
cmoveq %rax, %rcx
movq %rcx, 0x40(%rsp)
leaq (,%rcx,8), %rsi
movq 0x10(%rsp), %rdi
callq 0x2370
movq %r13, %rdx
jmp 0x444c
movq 0x10(%rsp), %rax
shlq $0x20, %rbp
movslq %r15d, %rcx
orq %rbp, %rcx
movq %rax, 0x10(%rsp)
movq %rcx, (%rax,%rdx,8)
movq 0x18(%rsp), %r15
cmpq 0x48(%rsp), %r15
jne 0x449d
leaq (%r15,%r15), %rax
testq %r15, %r15
pushq $0x2
popq %rcx
cmoveq %rcx, %rax
movq %rax, 0x48(%rsp)
leaq (,%rax,8), %rsi
movq 0x8(%rsp), %rdi
callq 0x2370
movq %r13, %rdx
movq %r15, %rcx
movq 0x20(%rsp), %r15
jmp 0x44aa
movq %r15, %rcx
movq 0x20(%rsp), %r15
movq 0x8(%rsp), %rax
movq %r12, %rbp
incq %rdx
movq %rax, 0x8(%rsp)
movq %r14, (%rax,%rcx,8)
incq %rcx
movq %rcx, 0x18(%rsp)
incq %r14
movl 0xc(%rbp), %eax
addq $0x28, %rbx
cmpq %rax, %r14
jb 0x43da
jmp 0x44e1
xorl %edx, %edx
movq $0x0, 0x18(%rsp)
cmpq 0x58(%rsp), %rdx
jge 0x44f4
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %r14
jmp 0x454b
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rdx, %r12
movq %rdx, %rsi
movq %r15, %rdx
movss 0x2c(%rsp), %xmm0
callq 0x3b530
testl %eax, %eax
je 0x4546
movq %rbp, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
callq 0xa0611
movq %r15, %rdi
movq 0x38(%rsp), %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0xa068a
movq %rbx, %rax
addq %r12, 0x30(%rsp)
jmp 0x454b
movq 0x8(%rsp), %rax
movq 0x70(%rsp), %rcx
incq %rcx
cmpq 0x68(%rsp), %rcx
jne 0x423e
movq %r14, %rdi
movq %rax, %rbx
callq 0x2220
movq %rbx, %rdi
callq 0x2220
movq 0x290a68(%rip), %rax    # 0x294fe0
movq (%rax), %rbx
callq 0x2f3fc
subsd 0x60(%rsp), %xmm0
leaq 0x22c902(%rip), %rsi    # 0x230e8f
leaq 0x22c927(%rip), %rdx    # 0x230ebb
movq %rbx, %rdi
movq 0x30(%rsp), %rcx
movb $0x1, %al
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0