// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: load_trans_ovlp(char const*, ma_ug_t*)
trans_chain* load_trans_ovlp(const char *fn, ma_ug_t *ug)
{
    char* gfa_name = NULL; MALLOC(gfa_name, strlen(fn)+50);
    sprintf(gfa_name, "%s.trans.bin", fn);
    FILE* fp = fopen(gfa_name, "r"); free(gfa_name);
    if (!fp) return NULL;
    if(ug && (!test_dbug(ug, fp))) {
        fprintf(stderr, "[M::%s] Renew trans overlaps\n", __func__);
        fclose(fp);
        return NULL;
    }

    uint64_t flag = 0;
    trans_chain *t_ch = NULL;
    CALLOC(t_ch, 1);

    flag += fread(&t_ch->r_num, sizeof(t_ch->r_num), 1, fp);
    MALLOC(t_ch->ir_het, t_ch->r_num);
    flag += fread(t_ch->ir_het, sizeof(uint8_t), t_ch->r_num, fp);

    uint64_t i;
    flag += fread(&t_ch->bed.n, sizeof(t_ch->bed.n), 1, fp);
    MALLOC(t_ch->bed.a, t_ch->bed.n); t_ch->bed.m = t_ch->bed.n;
    for (i = 0; i < t_ch->bed.n; i++) {
        flag += fread(&t_ch->bed.a[i].n, sizeof(t_ch->bed.a[i].n), 1, fp);
        MALLOC(t_ch->bed.a[i].a, t_ch->bed.a[i].n); t_ch->bed.a[i].m = t_ch->bed.a[i].n;
        flag += fread(t_ch->bed.a[i].a, sizeof(bed_interval), t_ch->bed.a[i].n, fp);
    }

    flag += fread(&t_ch->k_trans.n, sizeof(t_ch->k_trans.n), 1, fp);
    MALLOC(t_ch->k_trans.a, t_ch->k_trans.n); t_ch->k_trans.m = t_ch->k_trans.n;
    flag += fread(t_ch->k_trans.a, sizeof(u_trans_t), t_ch->k_trans.n, fp);

    flag += fread(&t_ch->k_trans.idx.n, sizeof(t_ch->k_trans.idx.n), 1, fp);
    MALLOC(t_ch->k_trans.idx.a, t_ch->k_trans.idx.n); t_ch->k_trans.idx.m = t_ch->k_trans.idx.n;
    flag += fread(t_ch->k_trans.idx.a, sizeof(uint64_t), t_ch->k_trans.idx.n, fp);

    fclose(fp);
    fprintf(stderr, "[M::%s::] ==> Trans overlaps have been loaded\n", __func__);
    return t_ch;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %r14
callq 0x2090
leaq 0x32(%rax), %rdi
callq 0x2280
movq %rax, %r12
leaq 0x15b3a5(%rip), %rsi    # 0x1e8e12
xorl %r13d, %r13d
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x163c33(%rip), %rsi    # 0x1f16b7
movq %r12, %rdi
callq 0x2210
movq %rax, %r14
movq %r12, %rdi
callq 0x2220
testq %r14, %r14
jne 0x8daae
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r15, %r15
je 0x8daee
movq %r15, %rdi
movq %r14, %rsi
callq 0x871ea
testl %eax, %eax
jne 0x8daee
movq 0x1c5517(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x15b379(%rip), %rsi    # 0x1e8e4c
leaq 0x15b390(%rip), %rdx    # 0x1e8e6a
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x22b0
movq %r14, %rdi
callq 0x2190
jmp 0x8da9c
pushq $0x1
popq %r15
movl $0x1d0, %esi            # imm = 0x1D0
movq %r15, %rdi
callq 0x2120
movq %rax, %rbx
leaq 0x18(%rax), %rdi
pushq $0x4
popq %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x22f0
movl 0x18(%rbx), %r12d
movq %r12, %rdi
callq 0x2280
movq %rax, 0x10(%rbx)
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x22f0
leaq 0x20(%rbx), %rdi
pushq $0x8
popq %rsi
movq %r15, %r12
movq %r15, %rdx
movq %r14, %rcx
callq 0x22f0
movq 0x20(%rbx), %r15
imulq $0x18, %r15, %rdi
callq 0x2280
movq %rax, %r13
movq %rax, 0x30(%rbx)
movq %rbx, (%rsp)
movq %r15, 0x28(%rbx)
pushq $0x10
popq %rbp
subq $0x1, %r15
jb 0x8dbaf
movq %r13, %rdi
pushq $0x8
popq %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x22f0
movq (%r13), %rbx
movq %rbx, %rdi
shlq $0x4, %rdi
callq 0x2280
movq %rax, 0x10(%r13)
movq %rbx, 0x8(%r13)
movq %rax, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x22f0
addq $0x18, %r13
jmp 0x8db69
movq (%rsp), %r13
leaq 0x138(%r13), %rdi
pushq $0x8
popq %r15
pushq $0x1
popq %rbx
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x22f0
movq 0x138(%r13), %r12
imulq $0x30, %r12, %rdi
callq 0x2280
movq %rax, 0x148(%r13)
movq %r12, 0x140(%r13)
pushq $0x30
popq %rsi
movq %rax, %rdi
movq %r12, %rdx
movq %r14, %rcx
callq 0x22f0
movq %r13, %rdi
addq $0x150, %rdi            # imm = 0x150
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x22f0
movq 0x150(%r13), %rbx
leaq (,%rbx,8), %rdi
callq 0x2280
movq %rax, 0x160(%r13)
movq %rbx, 0x158(%r13)
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x22f0
movq %r14, %rdi
callq 0x2190
movq 0x1c5388(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x15b218(%rip), %rsi    # 0x1e8e7a
leaq 0x15b201(%rip), %rdx    # 0x1e8e6a
xorl %eax, %eax
callq 0x22b0
jmp 0x8da9c