// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: load_ul_hits(mg_gres_a*, mg_dbn_t*, char const*)
int load_ul_hits(mg_gres_a *hits, mg_dbn_t *nn, const char *fn)
{
    uint64_t flag = 0;
    char *buf = (char*)calloc(strlen(fn) + 25, 1);
    sprintf(buf, "%s.ul.aln.bin", fn);

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

    kv_init(*hits);
    flag += fread(&hits->n, sizeof(hits->n), 1, fp);
    hits->m = hits->n; MALLOC(hits->a, hits->n);
	for (i = 0; i < hits->n; i++) {
		flag += fread(&hits->a[i].qid, sizeof(hits->a[i].qid), 1, fp);
		flag += fread(&hits->a[i].qlen, sizeof(hits->a[i].qlen), 1, fp);
		flag += fread(&hits->a[i].n_gc, sizeof(hits->a[i].n_gc), 1, fp);
		flag += fread(&hits->a[i].n_lc, sizeof(hits->a[i].n_lc), 1, fp);
		MALLOC(hits->a[i].gc, hits->a[i].n_gc); MALLOC(hits->a[i].lc, hits->a[i].n_lc);
		flag += fread(hits->a[i].gc, sizeof(mg_gchain_t), hits->a[i].n_gc, fp);
		flag += fread(hits->a[i].lc, sizeof(mg_lres_t), hits->a[i].n_lc, fp);
	}
    // flag += fread(hits->a, sizeof(mg_gres_t), hits->n, fp);
	flag += fread(&hits->total_pair, sizeof(hits->total_pair), 1, fp);
	flag += fread(&hits->total_base, sizeof(hits->total_base), 1, fp);

	memset(nn, 0, sizeof(*nn));
	flag += fread(&(nn->n), sizeof(nn->n), 1, fp);
	nn->m = nn->n; MALLOC(nn->a, nn->n);
	flag += fread(nn->a, sizeof(uint64_t), nn->n, fp);
	flag += fread(&(nn->tl), sizeof(nn->tl), 1, fp);
	flag += fread(&(nn->cc.n), sizeof(nn->cc.n), 1, fp);
	nn->cc.m = nn->cc.n; MALLOC(nn->cc.a, nn->cc.n);
	flag += fread(nn->cc.a, sizeof(char), nn->cc.n, fp);

    free(buf);

    // if(!test_dbug(ug, fp))
    // {
    //     free(hits->a.a);
    //     kv_init(hits->a);
    //     fclose(fp);
    //     fprintf(stderr, "[M::%s::] ==> Renew Hi-C linkages\n", __func__);
    //     return 0;
    // }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
movq %rdx, %rdi
callq 0x2090
leaq 0x19(%rax), %rdi
pushq $0x1
popq %rsi
callq 0x2120
movq %rax, %r15
leaq 0x606df(%rip), %rsi     # 0x1f63b1
xorl %ebp, %ebp
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x5b9cf(%rip), %rsi     # 0x1f16b7
movq %r15, %rdi
callq 0x2210
testq %rax, %rax
jne 0x195d0e
movq %r15, %rdi
callq 0x2220
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r13
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
andq $0x0, 0x10(%r12)
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %r12, %rdi
movq %rax, %rcx
callq 0x22f0
movq (%r12), %r14
movq %r14, 0x8(%r12)
imulq $0x28, %r14, %rdi
callq 0x2280
movq %rax, 0x10(%r12)
movq %r12, 0x10(%rsp)
jmp 0x195e3b
movq 0x10(%r12), %rax
imulq $0x28, %rbx, %rbp
leaq (%rax,%rbp), %rdi
addq $0x18, %rdi
pushq $0x8
popq %r14
movq %r14, %rsi
pushq $0x1
popq %r15
movq %r15, %rdx
movq %r13, %rcx
callq 0x22f0
movq 0x10(%r12), %rax
leaq (%rax,%rbp), %rdi
addq $0x20, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x22f0
movq 0x10(%r12), %rdi
addq %rbp, %rdi
pushq $0x4
popq %r14
movq %r14, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x22f0
movq 0x10(%r12), %rax
leaq (%rax,%rbp), %rdi
addq $0x4, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x22f0
movq 0x10(%r12), %r15
movslq (%r15,%rbp), %r14
imulq $0x48, %r14, %rdi
callq 0x2280
movq %r13, %r12
movq %rax, %r13
movq %rax, 0x8(%r15,%rbp)
movslq 0x4(%r15,%rbp), %rax
imulq $0x1c, %rax, %rdi
callq 0x2280
movq %rax, 0x10(%r15,%rbp)
movq %r13, %rdi
movq %r12, %r13
movq 0x10(%rsp), %r12
pushq $0x48
popq %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x22f0
movq 0x10(%r12), %rax
movq 0x10(%rax,%rbp), %rdi
movslq 0x4(%rax,%rbp), %rdx
pushq $0x1c
popq %rsi
movq %r13, %rcx
callq 0x22f0
leal 0x1(%rbx), %ebp
movq (%r12), %r14
movl %ebp, %ebx
cmpq %rbx, %r14
ja 0x195d5a
leaq 0x20(%r12), %rdi
pushq $0x8
popq %r14
pushq $0x1
popq %rbx
movq %r14, %rsi
movq %rbx, %rdx
movq %r13, %rcx
callq 0x22f0
addq $0x18, %r12
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %r13, %rcx
callq 0x22f0
xorps %xmm0, %xmm0
movq 0x8(%rsp), %r15
movups %xmm0, (%r15)
movups %xmm0, 0x10(%r15)
movups %xmm0, 0x20(%r15)
andq $0x0, 0x30(%r15)
leaq 0x20(%r15), %r12
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %r13, %rcx
callq 0x22f0
movq %r13, %rbp
movq (%r15), %r13
movq %r13, 0x8(%r15)
leaq (,%r13,8), %rdi
callq 0x2280
movq %rax, 0x10(%r15)
movq %rax, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x22f0
leaq 0x18(%r15), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
callq 0x22f0
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
callq 0x22f0
movq 0x20(%r15), %r14
movq %r14, 0x28(%r15)
movq %r14, %rdi
callq 0x2280
movq %rax, 0x30(%r15)
movq %rax, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x22f0
movq (%rsp), %rdi
callq 0x2220
movq %rbp, %rdi
callq 0x2190
movq 0xbd0af(%rip), %rax     # 0x252fe0
movq (%rax), %rdi
leaq 0x604c1(%rip), %rsi     # 0x1f63fc
leaq 0x604e8(%rip), %rdx     # 0x1f642a
xorl %eax, %eax
callq 0x22b0
pushq $0x1
popq %rax
jmp 0x195cff