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

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

    kv_init(link->a);
    flag += fread(&link->a.n, sizeof(link->a.n), 1, fp);
    link->a.m = link->a.n; CALLOC(link->a.a, link->a.n);
    for (k = 0; k < link->a.n; k++)
    {
        flag += fread(&link->a.a[k].e.n, sizeof(link->a.a[k].e.n), 1, fp);
        link->a.a[k].e.m = link->a.a[k].e.n; MALLOC(link->a.a[k].e.a, link->a.a[k].e.n);
        flag += fread(link->a.a[k].e.a, sizeof(hc_edge), link->a.a[k].e.n, fp);

        flag += fread(&link->a.a[k].f.n, sizeof(link->a.a[k].f.n), 1, fp);
        link->a.a[k].f.m = link->a.a[k].f.n; MALLOC(link->a.a[k].f.a, link->a.a[k].f.n);
        flag += fread(link->a.a[k].f.a, sizeof(hc_edge), link->a.a[k].f.n, fp);
    }

    kv_init(link->enzymes);
    flag += fread(&link->enzymes.n, sizeof(link->enzymes.n), 1, fp);
    link->enzymes.m = link->enzymes.n; MALLOC(link->enzymes.a, link->enzymes.n);
    flag += fread(link->enzymes.a, sizeof(uint64_t), link->enzymes.n, fp);

    fclose(fp);
    free(buf);
    fprintf(stderr, "[M::%s::] ==> Hi-C linkages have been loaded\n", __func__);
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x19, %rdi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x1b8231(%rip), %rsi    # 0x38c3c6
movb $0x0, %al
callq 0x2050
movq $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x1bc227(%rip), %rsi    # 0x3903d6
callq 0x2200
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x1d41d4
movq -0x30(%rbp), %rdi
callq 0x2210
movl $0x0, -0x4(%rbp)
jmp 0x1d44c1
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x30, %esi
callq 0x2140
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1d43f0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
imulq $0x30, -0x20(%rbp), %rax
addq %rax, %rdi
movq -0x38(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x20(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
imulq $0x28, (%rax), %rdi
callq 0x2270
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x20(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq -0x38(%rbp), %rcx
movl $0x28, %esi
callq 0x22e0
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
imulq $0x30, -0x20(%rbp), %rax
addq %rax, %rdi
addq $0x18, %rdi
movq -0x38(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x20(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
imulq $0x28, 0x18(%rax), %rdi
callq 0x2270
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x20(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rdx
movq -0x38(%rbp), %rcx
movl $0x28, %esi
callq 0x22e0
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x1d4249
movq -0x10(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x38(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
shlq $0x3, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x38(%rbp), %rcx
movl $0x8, %esi
callq 0x22e0
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rdi
callq 0x21a0
movq -0x30(%rbp), %rdi
callq 0x2210
movq 0x1efb3e(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1b7f68(%rip), %rsi    # 0x38c414
leaq 0x1b7f8f(%rip), %rdx    # 0x38c442
movb $0x0, %al
callq 0x22a0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)