// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: gen_init_sg(int, unsigned long, long, long, long, ma_hit_t_alloc*, unsigned long*, R_to_U*, bub_label_t*, ma_sub_t**, all_ul_t*, telo_end_t*)
asg_t *gen_init_sg(int32_t min_dp, uint64_t n_read, int64_t mini_overlap_length, int64_t max_hang_length, int64_t gap_fuzz,
ma_hit_t_alloc* src, uint64_t* readLen, R_to_U* ruIndex, bub_label_t *b_mask_t, ma_sub_t** cov, all_ul_t *ul, telo_end_t *te)
{
    asg_t *sg = NULL; 
    // prt_dbg_rid_ovlp(src, -1, (char*)"c85c2e91-0490-438b-977b-b7d056973996", "1");
    if(ul) rescue_src_ul(src, n_read, UL_COV_THRES);
    // prt_dbg_rid_ovlp(src, -1, (char*)"c85c2e91-0490-438b-977b-b7d056973996", "2");
    ma_hit_sub(min_dp, src, n_read, readLen, mini_overlap_length, cov);
    // prt_dbg_rid_ovlp(src, -1, (char*)"c85c2e91-0490-438b-977b-b7d056973996", "3");
    detect_chimeric_reads(src, n_read, readLen, *cov, asm_opt.max_ov_diff_final*2.0, ul, UL_COV_THRES);
    // prt_dbg_rid_ovlp(src, -1, (char*)"c85c2e91-0490-438b-977b-b7d056973996", "4");
    ma_hit_cut(src, n_read, readLen, mini_overlap_length, cov);
    // prt_dbg_rid_ovlp(src, -1, (char*)"c85c2e91-0490-438b-977b-b7d056973996", "5");
    ma_hit_flt(src, n_read, *cov, max_hang_length, mini_overlap_length);
    // prt_dbg_rid_ovlp(src, -1, (char*)"c85c2e91-0490-438b-977b-b7d056973996", "6");
    ma_hit_contained_advance(src, n_read, *cov, ruIndex, max_hang_length, mini_overlap_length);
    // prt_dbg_rid_ovlp(src, -1, (char*)"c85c2e91-0490-438b-977b-b7d056973996", "7");

    if(!ul) {
        sg = ma_sg_gen(src, n_read, *cov, max_hang_length, mini_overlap_length);
        if(asm_opt.prt_dbg_gfa) prt_dbg_gfa(sg, "raw", *cov, src, ruIndex, max_hang_length, mini_overlap_length);        
        asg_arc_del_trans(sg, gap_fuzz);
    } else {
        ug_opt_t uopt; 
        sg = ma_sg_gen_ul(src, n_read, *cov, ruIndex, max_hang_length, mini_overlap_length, UL_COV_THRES);
        if(asm_opt.prt_dbg_gfa) prt_dbg_gfa(sg, "raw", *cov, src, ruIndex, max_hang_length, mini_overlap_length);
        gen_ug_opt_t(&uopt, src, NULL, max_hang_length, mini_overlap_length, gap_fuzz, min_dp, readLen, *cov, ruIndex, -1, -1, -1, -1, -1, b_mask_t, te);
        
        ///debug
        // asg_symm(sg);
        // dedup_contain_g(&uopt, sg);
        
        if(clean_contain_g(&uopt, sg, 0)) update_sg_uo(sg, src);
        // prt_specfic_sge(sg, 10498, 10505, "--*--");
        asg_arc_del_trans_ul(sg, gap_fuzz);
        // prt_specfic_sge(sg, 10498, 10505, "--#--");        
    }
    
    init_bub_label_t(b_mask_t, MIN(10, asm_opt.thread_num), sg->n_seq);
    asm_opt.coverage = get_coverage(src, *cov, n_read);
    return sg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, %rbx
movq %r8, 0x18(%rsp)
movq %rcx, %rbp
movq %rdx, %r13
movq %rsi, %r14
movl %edi, %r12d
movq 0xe8(%rsp), %r15
cmpq $0x0, 0xf0(%rsp)
je 0x10023a
movl $0x2, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1000fc
movl %r12d, 0x14(%rsp)
movl %r12d, %edi
movq %rbx, %rsi
movq %r14, %rdx
movq 0xd0(%rsp), %r12
movq %r12, %rcx
movq %r15, %r9
callq 0xa1f56
movq (%r15), %rcx
leaq 0x18a4f3(%rip), %rax    # 0x28a758
movsd 0xc8(%rax), %xmm0
addsd %xmm0, %xmm0
cvtsd2ss %xmm0, %xmm0
movl $0x2, %r9d
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq 0xf0(%rsp), %r12
movq %r12, %r8
callq 0xa2a05
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rcx
movq %r15, %r8
callq 0xa2c51
movq (%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %ecx
movl %r13d, %r8d
callq 0xa1dbf
movq (%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movq 0xd8(%rsp), %rcx
movl %ebp, %r8d
movl %r13d, %r9d
callq 0xa1a33
testq %r12, %r12
je 0x1003e7
movq (%r15), %rdx
movq $0x2, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq 0xd8(%rsp), %rcx
movq %rbp, %r8
movq %r13, %r9
callq 0xa32e1
movq %rax, %r12
leaq 0x18a44d(%rip), %rax    # 0x28a758
cmpl $0x0, 0x254(%rax)
jne 0x100478
movslq 0x14(%rsp), %rax
movq (%r15), %rcx
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
movaps %xmm0, (%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x50(%rdi)
movaps %xmm0, 0x60(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movq %rbx, 0x8(%rdi)
movq $0x0, 0x10(%rdi)
movl %ebp, 0x40(%rdi)
movl %r13d, 0x44(%rdi)
movq 0x18(%rsp), %r13
movq %r13, 0x50(%rdi)
movq %rax, 0x58(%rdi)
movq 0xd0(%rsp), %rax
movq %rax, 0x68(%rdi)
movq %rcx, (%rdi)
movq 0xd8(%rsp), %rax
movq %rax, 0x30(%rdi)
movq $-0x1, %rax
movq %rax, 0x18(%rdi)
movl $0xbf800000, 0x20(%rdi) # imm = 0xBF800000
movq %rax, 0x28(%rdi)
movabsq $-0x407fffff40800000, %rax # imm = 0xBF800000BF800000
movq %rax, 0x38(%rdi)
movq 0xe0(%rsp), %rbp
movq %rbp, 0x60(%rdi)
movq 0xf8(%rsp), %rax
movq %rax, 0x70(%rdi)
movq %r12, %rsi
xorl %edx, %edx
callq 0x28306
testl %eax, %eax
je 0x1003d3
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2b3f3
movq %r12, %rdi
movl %r13d, %esi
callq 0xa8e5b
leaq 0x18a373(%rip), %r13    # 0x28a758
jmp 0x10042d
movq (%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %ecx
movl %r13d, %r8d
callq 0xa30a0
movq %rax, %r12
leaq 0x18a354(%rip), %rax    # 0x28a758
cmpl $0x0, 0x254(%rax)
jne 0x1004a1
movq %r12, %rdi
movq 0x18(%rsp), %rsi
callq 0xa8c8f
leaq 0x18a333(%rip), %r13    # 0x28a758
movq 0xe0(%rsp), %rbp
movl 0x7c(%r13), %eax
cmpl $0xa, %eax
movl $0xa, %esi
cmovll %eax, %esi
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl 0x14(%r12), %edx
movq %rbp, %rdi
callq 0x9fac0
movq (%r15), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0xf1afd
movq %rax, 0x1b0(%r13)
movq %r12, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %rdx
movq %r13, (%rsp)
leaq 0x1240b0(%rip), %rsi    # 0x224536
movq %r12, %rdi
movq %rbx, %rcx
movq 0xd8(%rsp), %r8
movq %rbp, %r9
callq 0xf00f
jmp 0x100318
movq (%r15), %rdx
movq %r13, (%rsp)
leaq 0x124087(%rip), %rsi    # 0x224536
movq %r12, %rdi
movq %rbx, %rcx
movq 0xd8(%rsp), %r8
movq %rbp, %r9
callq 0xf00f
jmp 0x100411