// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movl %edi, -0x1c(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq %r9, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
cmpq $0x0, 0x30(%rbp)
je 0x164510
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x2, %edx
callq 0x163f80
movl -0x1c(%rbp), %edi
movq -0x48(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq -0x30(%rbp), %r8
movq 0x28(%rbp), %r9
callq 0xd11e0
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq 0x10(%rbp), %rdx
movq 0x28(%rbp), %rax
movq (%rax), %rcx
movsd 0x21dda1(%rip), %xmm0   # 0x3822e8
leaq 0x2602aa(%rip), %rax    # 0x3c47f8
mulsd 0xc8(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x30(%rbp), %r8
movl $0x2, %r9d
callq 0xd2c50
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq 0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq 0x28(%rbp), %r8
callq 0xd3090
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq 0x28(%rbp), %rax
movq (%rax), %rdx
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %eax, %r8d
callq 0xd0fd0
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq 0x28(%rbp), %rax
movq (%rax), %rdx
movq 0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movl %eax, %r8d
movq -0x30(%rbp), %rax
movl %eax, %r9d
callq 0xd0a10
cmpq $0x0, 0x30(%rbp)
jne 0x164644
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq 0x28(%rbp), %rax
movq (%rax), %rdx
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %eax, %r8d
callq 0xd3dd0
movq %rax, -0x50(%rbp)
leaq 0x2601fc(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0x254(%rax)
je 0x164630
movq -0x50(%rbp), %rdi
movq 0x28(%rbp), %rax
movq (%rax), %rdx
movq -0x48(%rbp), %rcx
movq 0x18(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x30(%rbp), %rax
leaq 0x21cd2b(%rip), %rsi    # 0x381352
movq %rax, (%rsp)
callq 0x164080
movq -0x50(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %esi
callq 0xda630
jmp 0x164754
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq 0x28(%rbp), %rax
movq (%rax), %rdx
movq 0x18(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x30(%rbp), %r9
movq $0x2, (%rsp)
callq 0xd42d0
movq %rax, -0x50(%rbp)
leaq 0x260181(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0x254(%rax)
je 0x1646ab
movq -0x50(%rbp), %rdi
movq 0x28(%rbp), %rax
movq (%rax), %rdx
movq -0x48(%rbp), %rcx
movq 0x18(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x30(%rbp), %rax
leaq 0x21ccb0(%rip), %rsi    # 0x381352
movq %rax, (%rsp)
callq 0x164080
movq -0x48(%rbp), %rsi
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
movslq -0x1c(%rbp), %r15
movq 0x10(%rbp), %r14
movq 0x28(%rbp), %rax
movq (%rax), %rbx
movq 0x18(%rbp), %r11
movq 0x20(%rbp), %r10
movq 0x38(%rbp), %rax
leaq -0xc8(%rbp), %rdi
xorl %edx, %edx
movss 0x21a989(%rip), %xmm2   # 0x37f070
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq $-0x1, 0x20(%rsp)
movaps %xmm2, %xmm0
movq $-0x1, 0x28(%rsp)
movaps %xmm2, %xmm1
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
callq 0x163d60
movq -0x50(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
xorl %edx, %edx
callq 0x2ff3e0
cmpl $0x0, %eax
je 0x164745
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x313360
movq -0x50(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %esi
callq 0xda950
movq 0x20(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl $0xa, %eax
leaq 0x26008d(%rip), %rcx    # 0x3c47f8
cmpl 0x7c(%rcx), %eax
jg 0x16477d
movl $0xa, %eax
movl %eax, -0xd4(%rbp)
jmp 0x16478d
leaq 0x260074(%rip), %rax    # 0x3c47f8
movl 0x7c(%rax), %eax
movl %eax, -0xd4(%rbp)
movq -0xd0(%rbp), %rdi
movl -0xd4(%rbp), %esi
movq -0x50(%rbp), %rax
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
callq 0xccd40
movq -0x48(%rbp), %rdi
movq 0x28(%rbp), %rax
movq (%rax), %rsi
movq -0x28(%rbp), %rdx
callq 0x150740
movq %rax, %rcx
leaq 0x26002e(%rip), %rax    # 0x3c47f8
movq %rcx, 0x1b0(%rax)
movq -0x50(%rbp), %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)