// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: load_hc_trans(char const*)
trans_chain* load_hc_trans(const char *fn)
{
    uint64_t flag = 0;
    char *buf = (char*)calloc(strlen(fn) + 25, 1);
    sprintf(buf, "%s.hic.trans.bin", fn);

    FILE* fp = NULL; 
    fp = fopen(buf, "r"); 
    if(!fp) return NULL;

    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);

    uint32_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);
    free(buf);
    fprintf(stderr, "[M::%s::] ==> Hi-C cov have been loaded\n", __func__);
    return t_ch;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x19, %rdi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x28a22c(%rip), %rsi    # 0x3874bd
movb $0x0, %al
callq 0x2050
movq $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x29312b(%rip), %rsi    # 0x3903d6
callq 0x2200
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xfd2c8
movq $0x0, -0x8(%rbp)
jmp 0xfd5da
movq $0x0, -0x30(%rbp)
movl $0x1, %edi
movl $0x1d0, %esi            # imm = 0x1D0
callq 0x2140
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %edi
shlq $0x0, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %edx
movq -0x28(%rbp), %rcx
movl $0x1, %esi
callq 0x22e0
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rdi
addq $0x20, %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rax
imulq $0x18, 0x20(%rax), %rdi
callq 0x2270
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x28(%rax)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0xfd48c
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
movl -0x34(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
shlq $0x4, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x34(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x34(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x10, %esi
callq 0x22e0
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xfd39d
movq -0x30(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rax
imulq $0x30, 0x138(%rax), %rdi
callq 0x2270
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x148(%rax)
movq -0x30(%rbp), %rax
movq 0x138(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x140(%rax)
movq -0x30(%rbp), %rax
movq 0x148(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x138(%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x30, %esi
callq 0x22e0
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
addq $0x18, %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rax
movq 0x150(%rax), %rdi
shlq $0x3, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x160(%rax)
movq -0x30(%rbp), %rax
movq 0x150(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x158(%rax)
movq -0x30(%rbp), %rax
movq 0x160(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x150(%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x8, %esi
callq 0x22e0
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rdi
callq 0x21a0
movq -0x20(%rbp), %rdi
callq 0x2210
movq 0x2c6a26(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x289f0a(%rip), %rsi    # 0x3874ce
leaq 0x289f2c(%rip), %rdx    # 0x3874f7
movb $0x0, %al
callq 0x22a0
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)