// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movq %r9, -0x58(%rbp)
movsd %xmm0, -0x60(%rbp)
cmpq $0x0, 0x28(%rbp)
je 0xf628f
movq 0x2cdd6f(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq 0x28(%rbp), %rax
movl (%rax), %ecx
leaq 0x2910c1(%rip), %rsi    # 0x387342
leaq 0x2910f8(%rip), %rdx    # 0x387380
movb $0x0, %al
callq 0x22a0
cmpq $0x0, 0x30(%rbp)
je 0xf62bb
movq 0x2cdd43(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq 0x30(%rbp), %rax
movl (%rax), %ecx
leaq 0x2910e3(%rip), %rsi    # 0x387390
leaq 0x2910cc(%rip), %rdx    # 0x387380
movb $0x0, %al
callq 0x22a0
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x98(%rbp)
movq $0x0, -0xa0(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0xb0(%rbp)
movq $0x0, -0xb8(%rbp)
movq $0x0, -0xa8(%rbp)
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0xc8(%rbp)
movq $0x0, -0xd0(%rbp)
movl $0x0, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
cmpq (%rcx), %rax
jae 0xf645d
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl -0xbc(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0xf6392
jmp 0xf6449
movq -0xd0(%rbp), %rax
cmpl $0x2, 0x10(%rax)
jae 0xf63a4
jmp 0xf6449
movq -0xd0(%rbp), %rdi
movl -0xbc(%rbp), %esi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
movq -0x58(%rbp), %rax
movq 0x10(%rbp), %r10
movq %r10, -0xe0(%rbp)
movl 0x18(%rbp), %r13d
movl 0x20(%rbp), %r12d
movq -0xc8(%rbp), %r15
movq 0x28(%rbp), %r10
movq 0x30(%rbp), %r11
movq %r11, -0xd8(%rbp)
movsd -0x60(%rbp), %xmm0
leaq -0x80(%rbp), %r14
leaq -0xb8(%rbp), %rbx
leaq -0xa0(%rbp), %r11
movq %rax, (%rsp)
movq -0xe0(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0xd8(%rbp), %rax
movl %r13d, 0x10(%rsp)
movl %r12d, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0xf3a30
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0xf634b
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq 0x10(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
callq 0xf5660
movq -0x70(%rbp), %rdi
callq 0x2210
movq -0x90(%rbp), %rdi
callq 0x2210
movq -0xa8(%rbp), %rdi
callq 0x2210
movq -0xc8(%rbp), %rdi
callq 0x2210
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)