// File: /workspace/github_cpp_makefile_star2_O2/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 0xc14e2
pushq $0x2
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xc11c2
movl %r12d, 0x14(%rsp)
movl %r12d, %edi
movq %rbx, %rsi
movq %r14, %rdx
movq 0xd0(%rsp), %r12
movq %r12, %rcx
movq %r15, %r9
callq 0x6ad91
movq (%r15), %rcx
leaq 0x19224b(%rip), %rax    # 0x253758
movsd 0xc8(%rax), %xmm0
addsd %xmm0, %xmm0
cvtsd2ss %xmm0, %xmm0
pushq $0x2
popq %r9
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq 0xf0(%rsp), %r12
movq %r12, %r8
callq 0x6b9fe
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rcx
movq %r15, %r8
callq 0x6bc31
movq (%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %ecx
movl %r13d, %r8d
callq 0x6ac23
movq (%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movq 0xd8(%rsp), %rcx
movl %ebp, %r8d
movl %r13d, %r9d
callq 0x6a8ea
testq %r12, %r12
je 0xc1695
movq (%r15), %rdx
movq $0x2, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq 0xd8(%rsp), %rcx
movq %rbp, %r8
movq %r13, %r9
callq 0x6c5d4
movq %rax, %r12
leaq 0x1921a7(%rip), %rax    # 0x253758
cmpl $0x0, 0x254(%rax)
je 0xc15de
movq (%r15), %rdx
movq %r13, (%rsp)
leaq 0x120f7e(%rip), %rsi    # 0x1e2546
movq %r12, %rdi
movq %rbx, %rcx
movq 0xd8(%rsp), %r8
movq %rbp, %r9
callq 0xc1226
movq (%r15), %rax
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
movups %xmm0, 0x40(%rdi)
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movq %rbx, 0x8(%rdi)
andq $0x0, 0x10(%rdi)
movslq 0x14(%rsp), %rcx
movl %ebp, 0x40(%rdi)
movl %r13d, 0x44(%rdi)
movq 0x18(%rsp), %r15
movq %r15, 0x50(%rdi)
movq %rcx, 0x58(%rdi)
movq 0xd0(%rsp), %rcx
movq %rcx, 0x68(%rdi)
movq %rax, (%rdi)
movq 0xd8(%rsp), %rax
movq %rax, 0x30(%rdi)
orq $-0x1, 0x18(%rdi)
movl $0xbf800000, 0x20(%rdi) # imm = 0xBF800000
orq $-0x1, 0x28(%rdi)
movsd 0x1265f5(%rip), %xmm0   # 0x1e7c40
movsd %xmm0, 0x38(%rdi)
movq 0xe0(%rsp), %r13
movq %r13, 0x60(%rdi)
movq 0xf8(%rsp), %rax
movq %rax, 0x70(%rdi)
movq %r12, %rsi
xorl %edx, %edx
callq 0x19b92c
testl %eax, %eax
je 0xc1681
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1a64c2
movq %r12, %rdi
movl %r15d, %esi
callq 0x70377
leaq 0x1920c5(%rip), %r15    # 0x253758
jmp 0xc16fb
movq (%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %ecx
movl %r13d, %r8d
callq 0x6c2ce
movq %rax, %r12
leaq 0x1920a6(%rip), %rax    # 0x253758
cmpl $0x0, 0x254(%rax)
je 0xc16df
movq (%r15), %rdx
movq %r13, (%rsp)
leaq 0x120e7d(%rip), %rsi    # 0x1e2546
movq %r12, %rdi
movq %rbx, %rcx
movq 0xd8(%rsp), %r8
movq %rbp, %r9
callq 0xc1226
movq %r12, %rdi
movq 0x18(%rsp), %rsi
callq 0x701c4
leaq 0x192065(%rip), %r15    # 0x253758
movq 0xe0(%rsp), %r13
movl 0x7c(%r15), %eax
cmpl $0xa, %eax
pushq $0xa
popq %rsi
cmovll %eax, %esi
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl 0x14(%r12), %edx
movq %r13, %rdi
callq 0x68d88
movq 0xe8(%rsp), %rax
movq (%rax), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0xb4bca
movq %rax, 0x1b0(%r15)
movq %r12, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq