// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: break_ug_contig(ma_ug_t**, asg_t*, All_reads*, ma_sub_t*, ma_hit_t_alloc*, R_to_U*, kvec_asg_arc_t_warp*, int, int, int*, int*, double)
void break_ug_contig(ma_ug_t **ug, asg_t *read_g, All_reads *RNF, ma_sub_t *coverage_cut,
ma_hit_t_alloc* sources, R_to_U* ruIndex, kvec_asg_arc_t_warp* edge, int max_hang, int min_ovlp, 
int* b_low_cov, int* b_high_cov, double m_rate)
{
    if(b_low_cov)
    {
        fprintf(stderr, "[M::%s] break potential misassemblies with <%d-fold coverage\n", 
        __func__, *b_low_cov);
    }

    if(b_high_cov)
    {
        fprintf(stderr, "[M::%s] break potential misassemblies with >%d-fold coverage\n", 
        __func__, *b_high_cov);
    }

    kvec_t_u64_warp depth;
    kv_init(depth.a);
    kvec_t_u64_warp break_points;
    kv_init(break_points.a);
    kv_in_sub_t depth_i;
    kv_init(depth_i);
    uint32_t i;
    uint8_t* primary_flag = (uint8_t*)calloc(read_g->n_seq, sizeof(uint8_t));
    ma_utg_t *u = NULL;

    for (i = 0; i < (*ug)->u.n; ++i) 
    {
        u = &((*ug)->u.a[i]);
        if(u->m == 0) continue;
        if(u->n < 2) continue;
        // detect_break_point(u, i, read_g, RNF, coverage_cut, sources, ruIndex, edge, max_hang, min_ovlp, primary_flag, &depth, &break_points, b_low_cov);
        // debug_break_point(u, i, read_g, RNF, coverage_cut, sources, ruIndex, edge, max_hang, min_ovlp, primary_flag, &depth, &break_points, b_low_cov);
        detect_break_point_advance(u, i, read_g, RNF, coverage_cut, sources, ruIndex, edge, max_hang, min_ovlp,
        primary_flag, &depth, &depth_i, &break_points, b_low_cov, b_high_cov, m_rate);
        
    }

    break_all_contigs(ug, read_g, edge, &break_points);

    kv_destroy(depth.a);
    kv_destroy(break_points.a);
    kv_destroy(depth_i);
    free(primary_flag);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movsd %xmm0, 0x78(%rsp)
movq %r9, 0x70(%rsp)
movq %r8, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq 0x140(%rsp), %r12
movq 0x138(%rsp), %rcx
movq 0x120(%rsp), %rax
movq %rax, 0x58(%rsp)
movq %rcx, 0x50(%rsp)
testq %rcx, %rcx
jne 0xbba23
testq %r12, %r12
jne 0xbba32
xorps %xmm0, %xmm0
movaps %xmm0, 0xc0(%rsp)
xorl %ebp, %ebp
movq %rbp, 0xd0(%rsp)
movq %rbp, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movq %rbp, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movl 0x14(%rbx), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl $0x1, %esi
callq 0x2120
movq %rax, %r13
movq (%r14), %rax
movq (%rax), %rcx
movl $0x0, %r15d
testq %rcx, %rcx
je 0xbb9d5
movl $0x1, %r15d
xorl %edx, %edx
leaq 0xc0(%rsp), %rbp
movq 0x10(%rax), %rsi
leaq (%rdx,%rdx,4), %rdx
cmpl $0x0, 0xc(%rsi,%rdx,8)
je 0xbb9b6
leaq (%rsi,%rdx,8), %rdi
cmpl $0x2, 0x10(%rdi)
jb 0xbb9b6
leal -0x1(%r15), %esi
movq %r12, 0x48(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0xa0(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x80(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rbp, 0x28(%rsp)
movq %r13, 0x20(%rsp)
movq 0x70(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdx
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %r9
movsd 0x78(%rsp), %xmm0
callq 0xb9f03
movq (%r14), %rax
movq (%rax), %rcx
movl %r15d, %edx
incl %r15d
cmpq %rdx, %rcx
ja 0xbb93f
movq 0xd0(%rsp), %r15
movq 0x90(%rsp), %rbp
leaq 0xa0(%rsp), %r12
movq %r14, %rdi
movq %rbx, %rsi
movq 0x58(%rsp), %rdx
movq %r12, %rcx
callq 0xbb05d
movq %r15, %rdi
callq 0x2220
movq 0x10(%r12), %rdi
callq 0x2220
movq %rbp, %rdi
callq 0x2220
movq %r13, %rdi
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220
movq 0x50(%rsp), %rdi
callq 0x103a1
jmp 0xbb8c6
movq %r12, %rdi
callq 0x103c5
jmp 0xbb8cf