// File: /workspace/github_cpp_makefile_star2_O3/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 0x10457d
movl $0x2, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x104449
movl %r12d, 0x14(%rsp)
movl %r12d, %edi
movq %rbx, %rsi
movq %r14, %rdx
movq 0xd0(%rsp), %r12
movq %r12, %rcx
movq %r15, %r9
callq 0xa2b4b
movq (%r15), %rcx
leaq 0x1911b0(%rip), %rax    # 0x295758
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 0xa35ec
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rcx
movq %r15, %r8
callq 0xa3833
movq (%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %ecx
movl %r13d, %r8d
callq 0xa28bc
movq (%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movq 0xd8(%rsp), %rcx
movl %ebp, %r8d
movl %r13d, %r9d
callq 0xa2432
testq %r12, %r12
je 0x10471a
movq (%r15), %rdx
movq $0x2, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq 0xd8(%rsp), %rcx
movq %rbp, %r8
movq %r13, %r9
callq 0xa40ef
movq %rax, %r12
leaq 0x19110a(%rip), %rax    # 0x295758
cmpl $0x0, 0x254(%rax)
jne 0x1047ab
movslq 0x14(%rsp), %rax
movq (%r15), %rcx
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
movups %xmm0, 0x40(%rdi)
movups %xmm0, 0x30(%rdi)
movups %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)
movsd 0x131670(%rip), %xmm0   # 0x235d40
movsd %xmm0, 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 0x278e8
testl %eax, %eax
je 0x104706
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2a96e
movq %r12, %rdi
movl %r13d, %esi
callq 0xa9eee
leaq 0x191040(%rip), %r13    # 0x295758
jmp 0x104760
movq (%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %ecx
movl %r13d, %r8d
callq 0xa3c93
movq %rax, %r12
leaq 0x191021(%rip), %rax    # 0x295758
cmpl $0x0, 0x254(%rax)
jne 0x1047d4
movq %r12, %rdi
movq 0x18(%rsp), %rsi
callq 0xa9d09
leaq 0x191000(%rip), %r13    # 0x295758
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 0xa0272
movq (%r15), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0xf3ee0
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 0x12bd8d(%rip), %rsi    # 0x230546
movq %r12, %rdi
movq %rbx, %rcx
movq 0xd8(%rsp), %r8
movq %rbp, %r9
callq 0xf23d
jmp 0x10465b
movq (%r15), %rdx
movq %r13, (%rsp)
leaq 0x12bd64(%rip), %rsi    # 0x230546
movq %r12, %rdi
movq %rbx, %rcx
movq 0xd8(%rsp), %r8
movq %rbp, %r9
callq 0xf23d
jmp 0x104744