// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movl 0x30(%rbp), %eax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rdx
xorl %eax, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovel %ecx, %eax
movl %eax, -0x54(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x115988
movq -0x8(%rbp), %rdi
callq 0xe5910
movq %rax, -0x10(%rbp)
jmp 0x115a8b
cmpl $0x0, 0x28(%rbp)
je 0x115a89
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x115a87
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x58(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x1159e6
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x58(%rbp), %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x115a77
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x58(%rbp), %esi
callq 0xd9510
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x58(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0xc(%rax)
je 0x115a75
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x58(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x58(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0xc(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x58(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rdi
callq 0x2210
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x58(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x18(%rax)
jmp 0x115a77
jmp 0x115a79
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x115999
jmp 0x115a89
jmp 0x115a8b
cmpl $0x0, 0x20(%rbp)
je 0x115a9e
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0xe5720
cmpl $0x0, 0x30(%rbp)
je 0x115ade
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl 0x10(%rbp), %r9d
movl 0x18(%rbp), %eax
leaq -0x50(%rbp), %r8
xorl %r10d, %r10d
xorl %r10d, %r10d
movl %eax, (%rsp)
movq $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0xed140
movq 0x2ae4fb(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x27195c(%rip), %rsi    # 0x38744b
movb $0x0, %al
callq 0x22a0
movq -0x20(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x32, %rdi
callq 0x2270
movq %rax, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
cmpl $0x0, 0x30(%rbp)
je 0x115b71
movq -0x68(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x271943(%rip), %rsi    # 0x38746f
movb $0x0, %al
callq 0x2050
movq -0x68(%rbp), %rdi
leaq 0x283894(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x70(%rbp), %rax
leaq 0x276e42(%rip), %r9     # 0x38c9a8
movq %rax, (%rsp)
callq 0xefa60
jmp 0x115bc3
movq -0x68(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x2718fc(%rip), %rsi    # 0x38747c
movb $0x0, %al
callq 0x2050
movq -0x68(%rbp), %rdi
leaq 0x283840(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x70(%rbp), %rax
leaq 0x276dee(%rip), %r9     # 0x38c9a8
movq %rax, (%rsp)
callq 0xf1c10
movq -0x70(%rbp), %rdi
callq 0x21a0
movq -0x68(%rbp), %rdi
callq 0x2210
cmpl $0x0, -0x54(%rbp)
je 0x115be4
movq -0x10(%rbp), %rdi
callq 0xcd6f0
movq -0x40(%rbp), %rdi
callq 0x2210
movl $0x1, %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)