// File: /workspace/github_cpp_makefile_star2_O2/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 %r9, 0x28(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, %rbp
movq %rdx, 0x18(%rsp)
movq %rsi, %rbx
movq %rdi, %r13
andq $0x0, 0x40(%rsp)
movl 0xa0(%rsp), %r15d
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
testq %rsi, %rsi
jne 0x92731
movq %r13, %rdi
callq 0x76d91
movq %rax, %r14
jmp 0x927a7
cmpl $0x0, 0xa8(%rsp)
movq %rbx, %r14
je 0x927a7
xorl %r14d, %r14d
movl %r14d, %r14d
cmpq %r14, (%rbx)
jbe 0x927a4
imulq $0x28, %r14, %r12
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rdi
cmpl $0x0, 0xc(%rax,%r12)
je 0x92769
movq 0x20(%rdi), %rax
cmpb $0x1, 0x4(%rax,%r14,8)
jne 0x9279f
movl %r14d, %esi
callq 0x6f8da
movq 0x10(%rbx), %rax
cmpl $0x0, 0xc(%rax,%r12)
je 0x9279f
leaq (%rax,%r12), %rcx
andl $0x0, 0x10(%rcx)
andl $0x0, 0xc(%rax,%r12)
movq 0x18(%rax,%r12), %rdi
callq 0x2220
movq 0x10(%rbx), %rax
andq $0x0, 0x18(%rax,%r12)
incl %r14d
jmp 0x92741
movq %rbx, %r14
movl 0xb0(%rsp), %r12d
testl %r15d, %r15d
je 0x927bf
movq %r14, %rdi
movq %r13, %rsi
callq 0x76c93
testl %r12d, %r12d
je 0x927fb
movl 0x98(%rsp), %eax
movl 0x90(%rsp), %r9d
andl $0x0, 0x10(%rsp)
andq $0x0, 0x8(%rsp)
movl %eax, (%rsp)
leaq 0x30(%rsp), %r8
movq %r14, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
callq 0x7b888
movq 0x1c07de(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x156111(%rip), %rdi    # 0x1e891d
pushq $0x23
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq %rbp, %rdi
callq 0x2090
leaq 0x32(%rax), %rdi
callq 0x2280
movq %rax, %r15
testl %r12d, %r12d
je 0x9287d
leaq 0x15610a(%rip), %rsi    # 0x1e8941
movq %r15, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x167e56(%rip), %rsi    # 0x1fa6a1
movq %r15, %rdi
callq 0x2210
movq %rax, %rbp
movq %rax, (%rsp)
leaq 0x15b41a(%rip), %r9     # 0x1edc7b
movq %r14, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %r8
callq 0x7cd23
jmp 0x928c8
leaq 0x1560ca(%rip), %rsi    # 0x1e894e
movq %r15, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x167e09(%rip), %rsi    # 0x1fa6a1
movq %r15, %rdi
callq 0x2210
movq %rax, %rbp
movq %rax, (%rsp)
leaq 0x15b3cd(%rip), %r9     # 0x1edc7b
movq %r14, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %r8
callq 0x7de8f
movq %rbp, %rdi
callq 0x2190
movq %r15, %rdi
callq 0x2220
testq %rbx, %rbx
jne 0x928e5
movq %r14, %rdi
callq 0x6921d
pushq $0x1
popq %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq