// File: /workspace/github_cpp_makefile_star2_O1/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 %rsi, %rbx
andq $0x0, 0x40(%rsp)
movl 0xa0(%rsp), %ebp
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
testq %rsi, %rsi
movq %r9, 0x28(%rsp)
movq %r8, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movq %rdi, 0x8(%rsp)
movq %rcx, 0x20(%rsp)
jne 0xa686
callq 0xb0285
movq %rax, %r14
jmp 0xa7c4
cmpl $0x0, 0xa8(%rsp)
movq %rbx, %r14
je 0xa7c4
cmpq $0x0, (%rbx)
movq %rbx, %r14
je 0xa7c4
xorl %r14d, %r14d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq 0x10(%rbx), %rax
imulq $0x28, %r14, %r15
cmpl $0x0, 0xc(%rax,%r15)
je 0xa6d1
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rax
cmpb $0x1, 0x4(%rax,%r14,8)
jne 0xa7a9
movq 0x18(%rbx), %rax
movq 0x20(%rax), %rcx
orl $0x80000000, (%rcx,%r14,8) # imm = 0x80000000
leal (%r14,%r14), %ecx
xorl %edx, %edx
leaq (%rdx,%rcx), %rsi
movq 0x28(%rax), %rdi
movq (%rdi,%rsi,8), %r8
movq %r8, %rdi
andq %r12, %rdi
je 0xa76b
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 0xa763
movq 0x8(%rax), %rbp
shrq $0x20, %r11
imulq $0x18, %r10, %r10
imulq $0x18, %r11, %r11
addq %rbp, %r11
addq $0xc, %r11
xorl %ebp, %ebp
movl -0x4(%r11,%rbp), %r13d
xorl %esi, %r13d
cmpl $0x1, %r13d
jne 0xa75a
orb $-0x80, 0x3(%r11,%rbp)
addq $0x18, %rbp
cmpq %rbp, %r10
jne 0xa746
incq %r9
cmpq %rdi, %r9
jne 0xa70a
leaq 0x1(%rdx), %rsi
testq %rdx, %rdx
movq %rsi, %rdx
je 0xa6e7
movq 0x10(%rbx), %rax
cmpl $0x0, 0xc(%rax,%r15)
je 0xa7a9
leaq (%rax,%r15), %rcx
andl $0x0, 0x10(%rcx)
andl $0x0, 0xc(%rax,%r15)
movq 0x18(%rax,%r15), %rdi
callq 0x2220
movq 0x10(%rbx), %rax
andq $0x0, 0x18(%rax,%r15)
incl %r14d
cmpq %r14, (%rbx)
ja 0xa6ad
movq %rbx, %r14
movq 0x10(%rsp), %r12
movl 0xa0(%rsp), %ebp
movl 0xb0(%rsp), %r15d
testl %ebp, %ebp
je 0xa7dd
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0xb0169
testl %r15d, %r15d
je 0xa821
movl 0x98(%rsp), %eax
movl 0x90(%rsp), %r9d
subq $0x8, %rsp
leaq 0x38(%rsp), %r8
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %r12, %rcx
pushq $0x0
pushq $0x0
pushq %rax
callq 0xb5778
addq $0x20, %rsp
leaq 0x220032(%rip), %r12    # 0x22a851
jmp 0xa828
leaq 0x220036(%rip), %r12    # 0x22a85e
xorl %ebp, %ebp
testl %r15d, %r15d
setne %bpl
movq 0x27f7a8(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x21ffeb(%rip), %rdi    # 0x22a82d
pushq $0x23
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x20(%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 0x231b81(%rip), %rsi    # 0x23c3fe
movq %r15, %rdi
callq 0x2210
movq %rax, %r12
subq $0x8, %rsp
leaq 0x2252a8(%rip), %rax    # 0x22fb3b
leaq 0x280996(%rip), %rsi    # 0x28b230
movq %r14, %rdi
movq 0x10(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %r8
movq 0x30(%rsp), %r9
pushq %r12
pushq %rax
pushq %rbp
callq 0xb688e
addq $0x20, %rsp
movq %r12, %rdi
callq 0x2190
movq %r15, %rdi
callq 0x2220
testq %rbx, %rbx
jne 0xa8db
movq %r14, %rdi
callq 0xa0004
pushq $0x1
popq %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq