// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: load_scaf_base(all_ul_t*, char*, char const*)
uint32_t load_scaf_base(all_ul_t *x, char* file_name, const char *bin_file)
{
    char *gfa_name = (char*)malloc(strlen(file_name)+50);
	sprintf(gfa_name, "%s.%s.uidx.ucr.bin", file_name, bin_file);
    // fprintf(stderr, "[M::%s] open %s...\n", __func__, gfa_name);
    FILE *fp = fopen(gfa_name, "r"); free(gfa_name);
    if (!fp) return 0;
    // fprintf(stderr, "[M::%s] open sucess\n", __func__);
    uint64_t rid; uint32_t len; ul_vec_t ss, *z; memset(&ss, 0, sizeof(ss));
    while(1) {
        fread(&rid, sizeof(rid), 1, fp);
        if(feof(fp)) break;
        z = &(x->a[rid]);
        fread(&len, sizeof(len), 1, fp); assert(z->rlen == len);
        fread(&(ss.N_site.n), sizeof(ss.N_site.n), 1, fp);
        kv_resize(uint32_t, ss.N_site, ss.N_site.n);
        fread(ss.N_site.a, sizeof((*(ss.N_site.a))), ss.N_site.n, fp);
        ss.r_base.n = B4Lg(len); kv_resize(uint8_t, ss.r_base, ss.r_base.n); 
        fread(ss.r_base.a, sizeof((*(ss.r_base.a))), ss.r_base.n, fp);
        // if(rid == 37238) {
        //     fprintf(stderr, "[M::%s::37238] z->dd::%u\n", __func__, z->dd);
        // }
        // fprintf(stderr, "[M::%s::rid->%lu] z->dd::%u\n", __func__, rid, z->dd);
        if(z->dd != 4) continue;

        
        kv_resize(uint32_t, z->N_site, ss.N_site.n); z->N_site.n = ss.N_site.n;
        memcpy(z->N_site.a, ss.N_site.a, sizeof((*(z->N_site.a)))*z->N_site.n);

        kv_resize(uint8_t, z->r_base, ss.r_base.n); z->r_base.n = ss.r_base.n;
        memcpy(z->r_base.a, ss.r_base.a, sizeof((*(z->r_base.a)))*z->r_base.n);
    }
    // load_compress_base_disk(fp, &rid, des.a, &ulen, &(sl->ucr_s->u));

    fclose(fp); free(ss.N_site.a); free(ss.r_base.a);
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, 0x10(%rsp)
movq %rsi, %rdi
callq 0x2090
leaq 0x32(%rax), %rdi
callq 0x2280
movq %rax, %r12
leaq 0x298a3(%rip), %rsi     # 0x1fb7df
xorl %ebx, %ebx
movq %rax, %rdi
movq %r15, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x2050
leaq 0x1f762(%rip), %rsi     # 0x1f16b7
movq %r12, %rdi
callq 0x2210
movq %rax, %r14
movq %r12, %rdi
callq 0x2220
testq %r14, %r14
je 0x1d220d
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rax
movaps %xmm0, (%rax)
movaps %xmm0, -0x10(%rax)
movaps %xmm0, -0x20(%rax)
movaps %xmm0, -0x30(%rax)
andq $0x0, 0x10(%rax)
movaps %xmm0, -0x40(%rax)
xorl %ebx, %ebx
pushq $0x1
popq %r15
movq $0x0, (%rsp)
leaq 0x18(%rsp), %rdi
pushq $0x8
popq %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x22f0
movq %r14, %rdi
callq 0x2320
testl %eax, %eax
jne 0x1d21f1
movq %r15, %r12
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rbp
imulq $0x58, 0x18(%rsp), %r15
leaq 0xc(%rsp), %rdi
pushq $0x4
popq %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x22f0
movl 0x18(%rbp,%r15), %ebx
cmpl 0xc(%rsp), %ebx
jne 0x1d221e
leaq 0x60(%rsp), %rdi
pushq $0x8
popq %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x22f0
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %r13
cmpq %r13, 0x68(%rsp)
jae 0x1d206d
leaq -0x1(%r13), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x68(%rsp)
leaq 0x4(,%rcx,4), %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x58(%rsp)
movq %rdi, (%rsp)
pushq $0x4
popq %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x22f0
movl %ebx, %r12d
shrl $0x2, %r12d
andl $0x3, %ebx
cmpl $0x1, %ebx
sbbl $-0x1, %r12d
movq %r12, 0x20(%rsp)
movq 0x30(%rsp), %rbx
cmpq %r12, 0x28(%rsp)
jae 0x1d20ef
leaq -0x1(%r12), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x28(%rsp)
movq %rbx, %rdi
callq 0x2370
movq %rax, %rbx
movq %rax, 0x30(%rsp)
addq %r15, %rbp
movq %rbx, %rdi
pushq $0x1
popq %r15
movq %r15, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x22f0
cmpb $0x4, 0x50(%rbp)
jne 0x1d1f9f
movq 0x38(%rbp), %rdi
cmpq %r13, 0x48(%rbp)
jae 0x1d216c
leaq -0x1(%r13), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x48(%rbp)
leaq 0x4(,%rcx,4), %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x38(%rbp)
movq %r13, 0x40(%rbp)
shlq $0x2, %r13
movq (%rsp), %rsi
movq %r13, %rdx
callq 0x2160
cmpq %r12, 0x8(%rbp)
jae 0x1d21d5
leaq -0x1(%r12), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%rbp)
movq 0x10(%rbp), %rdi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x10(%rbp)
jmp 0x1d21d9
movq 0x10(%rbp), %rdi
movq %r12, (%rbp)
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2160
pushq $0x1
popq %r15
jmp 0x1d1f9f
movq %r14, %rdi
callq 0x2190
movq (%rsp), %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x2220
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x295cd(%rip), %rdi     # 0x1fb7f2
leaq 0x252ad(%rip), %rsi     # 0x1f74d9
leaq 0x295ce(%rip), %rcx     # 0x1fb801
movl $0x38b4, %edx           # imm = 0x38B4
callq 0x2110