// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: load_debug_graph(asg_t**, ma_hit_t_alloc**, ma_sub_t**, char*, ma_hit_t_alloc**, R_to_U*, all_ul_t*)
int load_debug_graph(asg_t** sg, ma_hit_t_alloc** sources, ma_sub_t** coverage_cut, 
char* output_file_name, ma_hit_t_alloc** reverse_sources, R_to_U* ruIndex, all_ul_t *ul_r_inf)
{
    FILE* fp = NULL;
    char* gfa_name = (char*)malloc(strlen(output_file_name)+55);
    sprintf(gfa_name, "%s.all.debug.source.bin", output_file_name);
    fp = fopen(gfa_name, "r"); if(!fp) return 0; fclose(fp);
    sprintf(gfa_name, "%s.all.debug.reverse.bin", output_file_name);
    fp = fopen(gfa_name, "r"); if(!fp) return 0; fclose(fp);
    if(coverage_cut) {
        sprintf(gfa_name, "%s.all.debug.coverage_cut.bin", output_file_name);
        fp = fopen(gfa_name, "r"); if(!fp) return 0; fclose(fp);
    }
    sprintf(gfa_name, "%s.all.debug.ruIndex.bin", output_file_name);
    fp = fopen(gfa_name, "r"); if(!fp) return 0; fclose(fp);
    if(sg) {
        sprintf(gfa_name, "%s.all.debug.asg_t.bin", output_file_name);
        fp = fopen(gfa_name, "r"); if(!fp) return 0; fclose(fp);
    }
    if(ul_r_inf) {
        sprintf(gfa_name, "%s.all.debug.ul.rinfor.ul.ovlp.bin", output_file_name);
        fp = fopen(gfa_name, "r"); if(!fp) return 0; fclose(fp);
    }
    
    if((sources == NULL) || (reverse_sources == NULL) || (ruIndex == NULL))
    {
        return 1;
    }

    if((*sources)!=NULL)
    {
        destory_ma_hit_t_alloc((*sources));
    }

    if((*reverse_sources)!=NULL)
    {
        destory_ma_hit_t_alloc((*reverse_sources));
    }

    if(coverage_cut && (*coverage_cut)!=NULL)
    {
        free((*coverage_cut));
    }

    if((ruIndex)!=NULL)
    {
        destory_R_to_U((ruIndex));
    }

    if(sg && (*sg)!=NULL)
    {
        asg_destroy(*sg);
    }

    

    sprintf(gfa_name, "%s.all.debug.source", output_file_name);
    if(!load_debug_ma_hit_ts(sources, gfa_name))
    {
        return 0;
    }

    sprintf(gfa_name, "%s.all.debug.reverse", output_file_name);
    if(!load_debug_ma_hit_ts(reverse_sources, gfa_name))
    {
        return 0;
    }

    if(coverage_cut) {
        sprintf(gfa_name, "%s.all.debug.coverage_cut", output_file_name);
        if(!load_coverage_cut(coverage_cut, gfa_name))
        {
            return 0;
        }
    }

    sprintf(gfa_name, "%s.all.debug.ruIndex", output_file_name);
    if(!load_ruIndex(ruIndex, gfa_name))
    {
        return 0;
    }

    if(sg) {
        sprintf(gfa_name, "%s.all.debug.asg_t", output_file_name);
        if(!load_asg_t(sg, gfa_name))
        {
            return 0;
        }
    }
    

    if(ul_r_inf) {
        sprintf(gfa_name, "%s.all.debug.ul.rinfor", output_file_name);
        if(!load_all_ul_t(ul_r_inf, gfa_name, &R_INF, NULL)) return 0;
    }

    R_INF.paf = (*sources); R_INF.reverse_paf = (*reverse_sources);

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %rbp
movq %r8, 0x8(%rsp)
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, 0x10(%rsp)
movq %rdi, %r13
movq %rcx, %rdi
callq 0x2090
leaq 0x37(%rax), %rdi
callq 0x2280
movq %rax, %r12
leaq 0x1462f5(%rip), %rsi    # 0x1ea8cb
xorl %r14d, %r14d
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x14d0ca(%rip), %rsi    # 0x1f16b7
movq %r12, %rdi
callq 0x2210
testq %rax, %rax
je 0xa48dc
movq %rax, %rdi
callq 0x2190
leaq 0x1462d6(%rip), %rsi    # 0x1ea8e3
xorl %r14d, %r14d
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x14d093(%rip), %rsi    # 0x1f16b7
movq %r12, %rdi
callq 0x2210
testq %rax, %rax
je 0xa48dc
movq %rax, %rdi
callq 0x2190
testq %rbx, %rbx
je 0xa4679
leaq 0x1462b3(%rip), %rsi    # 0x1ea8fc
xorl %r14d, %r14d
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x14d057(%rip), %rsi    # 0x1f16b7
movq %r12, %rdi
callq 0x2210
testq %rax, %rax
je 0xa48dc
movq %rax, %rdi
callq 0x2190
leaq 0x14629a(%rip), %rsi    # 0x1ea91a
xorl %r14d, %r14d
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x14d020(%rip), %rsi    # 0x1f16b7
movq %r12, %rdi
callq 0x2210
testq %rax, %rax
je 0xa48dc
movq %rax, %rdi
callq 0x2190
testq %r13, %r13
je 0xa46ec
leaq 0x146277(%rip), %rsi    # 0x1ea933
xorl %r14d, %r14d
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x14cfe4(%rip), %rsi    # 0x1f16b7
movq %r12, %rdi
callq 0x2210
testq %rax, %rax
je 0xa48dc
movq %rax, %rdi
callq 0x2190
cmpq $0x0, 0x50(%rsp)
je 0xa472b
leaq 0x14624f(%rip), %rsi    # 0x1ea94a
xorl %r14d, %r14d
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x14cfa5(%rip), %rsi    # 0x1f16b7
movq %r12, %rdi
callq 0x2210
testq %rax, %rax
je 0xa48dc
movq %rax, %rdi
callq 0x2190
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
sete %al
cmpq $0x0, 0x8(%rsp)
sete %cl
orb %al, %cl
testq %rbp, %rbp
sete %al
orb %cl, %al
pushq $0x1
popq %rax
je 0xa4756
movl %eax, %r14d
jmp 0xa48dc
movq (%rdx), %rdi
testq %rdi, %rdi
je 0xa4763
callq 0x696a3
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0xa4775
callq 0x696a3
testq %rbx, %rbx
je 0xa4782
movq (%rbx), %rdi
callq 0x2220
movq %rbp, %rdi
callq 0xb350f
testq %r13, %r13
je 0xa479d
movq (%r13), %rdi
testq %rdi, %rdi
je 0xa479d
callq 0x68f68
leaq 0x146086(%rip), %rsi    # 0x1ea82a
xorl %r14d, %r14d
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0xa3b2d
testl %eax, %eax
je 0xa48dc
leaq 0x14606e(%rip), %rsi    # 0x1ea83e
xorl %r14d, %r14d
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0xa3b2d
testl %eax, %eax
je 0xa48dc
testq %rbx, %rbx
je 0xa4824
leaq 0x146052(%rip), %rsi    # 0x1ea853
xorl %r14d, %r14d
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
movq %rbx, %rdi
movq %r12, %rsi
callq 0xb2c69
testl %eax, %eax
je 0xa48dc
leaq 0x146042(%rip), %rsi    # 0x1ea86d
xorl %r14d, %r14d
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
movq %rbp, %rdi
movq %r12, %rsi
callq 0xb2e9a
testl %eax, %eax
je 0xa48dc
testq %r13, %r13
je 0xa4879
leaq 0x146028(%rip), %rsi    # 0x1ea882
xorl %r14d, %r14d
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
movq %r13, %rdi
movq %r12, %rsi
callq 0xb3164
testl %eax, %eax
je 0xa48dc
cmpq $0x0, 0x50(%rsp)
je 0xa48b2
leaq 0x14600d(%rip), %rsi    # 0x1ea895
xorl %r14d, %r14d
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x1af991(%rip), %rdx    # 0x254230
movq 0x50(%rsp), %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x19aa47
testl %eax, %eax
je 0xa48dc
movq 0x10(%rsp), %rax
movq (%rax), %rax
leaq 0x1af96f(%rip), %rcx    # 0x254230
movq %rax, 0x78(%rcx)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x80(%rcx)
pushq $0x1
popq %rax
jmp 0xa474e
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq