// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: print_debug_gfa(asg_t*, ma_ug_t*, ma_sub_t*, char const*, ma_hit_t_alloc*, R_to_U*, int, int, int, int, int)
uint32_t print_debug_gfa(asg_t *read_g, ma_ug_t *ug, ma_sub_t* coverage_cut, const char* output_file_name, 
ma_hit_t_alloc* sources, R_to_U* ruIndex, int max_hang, int min_ovlp, int is_update_ou, int is_check_alter_lable, int is_seq)
{
    kvec_asg_arc_t_warp new_rtg_edges; 
    uint32_t free_ug = ((ug == NULL)?1:0);
    kv_init(new_rtg_edges.a);

    if(ug == NULL) {
        ug = ma_ug_gen(read_g);
    } else if(is_check_alter_lable) {
        uint32_t i;
        for (i = 0; i < ug->u.n; ++i) 
        {
            ma_utg_t *u = &ug->u.a[i];
            if(u->m == 0 || ug->g->seq[i].c == ALTER_LABLE)
            {
                asg_seq_del(ug->g, i);
                if(ug->u.a[i].m!=0)
                {
                    ug->u.a[i].m = ug->u.a[i].n = 0;
                    free(ug->u.a[i].a);
                    ug->u.a[i].a = NULL;
                }
            }
        }
    }

    if(is_update_ou) update_ug_ou(ug, read_g);
    if(is_seq) {
        ma_ug_seq(ug, read_g, coverage_cut, sources, &new_rtg_edges, max_hang, min_ovlp, 0, 0);
    }
    // if(is_polish) ma_ug_seq(ug, read_g, coverage_cut, sources, &new_rtg_edges, max_hang, min_ovlp, 0, 0);

    fprintf(stderr, "Writing raw unitig GFA to disk... \n");
    char* gfa_name = (char*)malloc(strlen(output_file_name)+50);
    FILE* output_file = NULL;
    
    if(is_seq) {
        sprintf(gfa_name, "%s.r_utg.gfa", output_file_name);
        output_file = fopen(gfa_name, "w");
        ma_ug_print(ug, read_g, coverage_cut, sources, ruIndex, "utg", output_file);
    } else {
        sprintf(gfa_name, "%s.r_utg.noseq.gfa", output_file_name);
        output_file = fopen(gfa_name, "w");
        ma_ug_print_simple(ug, read_g, coverage_cut, sources, ruIndex, "utg", output_file);
    }
    fclose(output_file);

    free(gfa_name);
    if(free_ug) ma_ug_destroy(ug);
    kv_destroy(new_rtg_edges.a);
    // exit(0);
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r12
movq %rdx, %rbp
movq %rsi, %rbx
andq $0x0, 0x40(%rsp)
movl 0xa0(%rsp), %r14d
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
testq %rsi, %rsi
movq %r9, 0x20(%rsp)
movq %r8, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq %rdi, (%rsp)
movq %rcx, 0x18(%rsp)
jne 0xa64a
callq 0xb10cd
movq %rax, %r13
jmp 0xa790
cmpl $0x0, 0xa8(%rsp)
movq %rbx, %r13
je 0xa790
cmpq $0x0, (%rbx)
movq %rbx, %r13
je 0xa790
movq 0x10(%rbx), %rcx
xorl %r14d, %r14d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
pushq $0x1
popq %r15
movq %rbx, 0x28(%rsp)
imulq $0x28, %r14, %rbp
cmpl $0x0, 0xc(%rcx,%rbp)
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rdx
je 0xa69d
cmpb $0x1, 0x4(%rdx,%r14,8)
jne 0xa76f
orb $-0x80, 0x3(%rdx,%r14,8)
leal (%r14,%r14), %ecx
movb $0x1, %dl
xorl %esi, %esi
orq %rcx, %rsi
movq 0x28(%rax), %rdi
movq (%rdi,%rsi,8), %r8
movq %r8, %rdi
andq %r12, %rdi
je 0xa72d
shrq $0x20, %r8
imulq $0x18, %r8, %r8
addq 0x8(%rax), %r8
xorl %r9d, %r9d
imulq $0x18, %r9, %r10
orb $-0x80, 0xf(%r8,%r10)
movl 0x8(%r8,%r10), %r10d
xorq $0x1, %r10
movq 0x28(%rax), %r11
movq (%r11,%r10,8), %r11
movq %r11, %r10
andq %r12, %r10
je 0xa725
movq 0x8(%rax), %r13
shrq $0x20, %r11
imulq $0x18, %r10, %r10
imulq $0x18, %r11, %r11
addq %r13, %r11
addq $0xc, %r11
xorl %r13d, %r13d
movl -0x4(%r11,%r13), %ebx
xorl %esi, %ebx
cmpl $0x1, %ebx
jne 0xa71c
orb $-0x80, 0x3(%r11,%r13)
addq $0x18, %r13
cmpq %r13, %r10
jne 0xa70a
incq %r9
cmpq %rdi, %r9
jne 0xa6cd
movq %r15, %rsi
testb $0x1, %dl
movl $0x0, %edx
jne 0xa6ab
movq 0x28(%rsp), %rbx
movq 0x10(%rbx), %rcx
cmpl $0x0, 0xc(%rcx,%rbp)
je 0xa76f
leaq (%rcx,%rbp), %rax
andl $0x0, 0x10(%rax)
andl $0x0, 0xc(%rcx,%rbp)
movq 0x18(%rcx,%rbp), %rdi
callq 0x2220
movq 0x10(%rbx), %rcx
andq $0x0, 0x18(%rcx,%rbp)
incl %r14d
cmpq %r14, (%rbx)
ja 0xa67e
movq %rbx, %r13
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %rbp
movl 0xa0(%rsp), %r14d
movl 0xb0(%rsp), %r15d
testl %r14d, %r14d
je 0xa7a9
movq %r13, %rdi
movq (%rsp), %rsi
callq 0xb0fb2
testl %r15d, %r15d
je 0xa7eb
movl 0x98(%rsp), %eax
movl 0x90(%rsp), %r9d
subq $0x8, %rsp
leaq 0x38(%rsp), %r8
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
movq %r12, %rcx
pushq $0x0
pushq $0x0
pushq %rax
callq 0xb67c4
addq $0x20, %rsp
leaq 0x22c258(%rip), %r12    # 0x236a41
jmp 0xa7f2
leaq 0x22c25c(%rip), %r12    # 0x236a4e
movq %r13, %r14
xorl %ebp, %ebp
testl %r15d, %r15d
setne %bpl
movq 0x28a7db(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x22c20e(%rip), %rdi    # 0x236a1d
pushq $0x23
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x18(%rsp), %r13
movq %r13, %rdi
callq 0x2090
leaq 0x32(%rax), %rdi
callq 0x2280
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x23de98(%rip), %rsi    # 0x2486e2
movq %r15, %rdi
callq 0x2210
movq %rax, %r12
subq $0x8, %rsp
leaq 0x23152b(%rip), %rax    # 0x23bd8b
leaq 0x28b9c9(%rip), %rsi    # 0x296230
movq %r14, %rdi
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %r8
movq 0x28(%rsp), %r9
pushq %r12
pushq %rax
pushq %rbp
callq 0xb7823
addq $0x20, %rsp
movq %r12, %rdi
callq 0x2190
movq %r15, %rdi
callq 0x2220
testq %rbx, %rbx
jne 0xa8a8
movq %r14, %rdi
callq 0xa0761
pushq $0x1
popq %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq