// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x32, %rdi
shlq $0x0, %rdi
callq 0x2270
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x27a749(%rip), %rsi    # 0x387afd
movb $0x0, %al
callq 0x2050
movq -0x20(%rbp), %rdi
leaq 0x283010(%rip), %rsi    # 0x3903d6
callq 0x2200
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2210
cmpq $0x0, -0x28(%rbp)
jne 0x10d3ec
movq $0x0, -0x8(%rbp)
jmp 0x10d742
cmpq $0x0, -0x18(%rbp)
je 0x10d43a
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x101650
cmpl $0x0, %eax
jne 0x10d43a
movq 0x2b6bd4(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x27a721(%rip), %rsi    # 0x387b37
leaq 0x27a738(%rip), %rdx    # 0x387b55
movb $0x0, %al
callq 0x22a0
movq -0x28(%rbp), %rdi
callq 0x21a0
movq $0x0, -0x8(%rbp)
jmp 0x10d742
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x1, %edi
movl $0x1d0, %esi            # imm = 0x1D0
callq 0x2140
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %edi
shlq $0x0, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x38(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %edx
movq -0x28(%rbp), %rcx
movl $0x1, %esi
callq 0x22e0
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rdi
addq $0x20, %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
imulq $0x18, 0x20(%rax), %rdi
callq 0x2270
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x10d5fd
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rdi
imulq $0x18, -0x40(%rbp), %rax
addq %rax, %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdi
shlq $0x4, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x10, %esi
callq 0x22e0
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x10d518
movq -0x38(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
imulq $0x30, 0x138(%rax), %rdi
callq 0x2270
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x148(%rax)
movq -0x38(%rbp), %rax
movq 0x138(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x140(%rax)
movq -0x38(%rbp), %rax
movq 0x148(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x138(%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x30, %esi
callq 0x22e0
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
addq $0x18, %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
movq 0x150(%rax), %rdi
shlq $0x3, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x160(%rax)
movq -0x38(%rbp), %rax
movq 0x150(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x158(%rax)
movq -0x38(%rbp), %rax
movq 0x160(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x150(%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x8, %esi
callq 0x22e0
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x21a0
movq 0x2b68be(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x27a439(%rip), %rsi    # 0x387b65
leaq 0x27a422(%rip), %rdx    # 0x387b55
movb $0x0, %al
callq 0x22a0
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)