// File: chhylp123[P]hifiasm/htab.cpp
// Function: load_ct_index(void**, char*)
int load_ct_index(void **i_ct_idx, char* file_name)
{
	char* gfa_name = (char*)malloc(strlen(file_name)+25);
    sprintf(gfa_name, "%s.ct_flt", file_name);
    FILE* fp = fopen(gfa_name, "r");
	if (!fp) {
		free(gfa_name);
        return 0;
    }
	ha_ct_t** ct_idx = (ha_ct_t**)i_ct_idx;
	double index_time = 0;
	uint64_t flag = 0;
	int i;
	ha_ct_t *h = 0;
	ha_ct1_t *g;
	CALLOC(h, 1);

	flag += fread(&h->k, sizeof(h->k), 1, fp);
	flag += fread(&h->pre, sizeof(h->pre), 1, fp);
	flag += fread(&h->n_hash, sizeof(h->n_hash), 1, fp);
	flag += fread(&h->n_shift, sizeof(h->n_shift), 1, fp);
	flag += fread(&h->tot, sizeof(h->tot), 1, fp);
	CALLOC(h->h, 1<<h->pre);


	index_time = yak_realtime();
	for (i = 0; i < 1<<h->pre; ++i) 
	{
		g = &(h->h[i]);
		yak_ct_load(&(g->h), fp);
	}

	(*ct_idx) = h;
	fprintf(stderr, "[M::%s::%.3f] ==> Loaded count table\n", __func__, yak_realtime() - index_time);
	fprintf(stderr, "[M::%s] Index has been loaded.\n", __func__);
	free(gfa_name);
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x19, %rdi
callq 0x2270
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x200660(%rip), %rsi    # 0x38ae38
movb $0x0, %al
callq 0x2050
movq -0x20(%rbp), %rdi
leaq 0x205bec(%rip), %rsi    # 0x3903d6
callq 0x2200
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x18a80f
movq -0x20(%rbp), %rdi
callq 0x2210
movl $0x0, -0x4(%rbp)
jmp 0x18a9d5
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x50(%rbp)
movl $0x1, %edi
movl $0x28, %esi
callq 0x2140
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x28(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rdi
addq $0x4, %rdi
movq -0x28(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rdi
addq $0x8, %rdi
movq -0x28(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rdi
addq $0xc, %rdi
movq -0x28(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rdi
addq $0x10, %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rax
movl 0x4(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movslq %eax, %rdi
movl $0x10, %esi
callq 0x2140
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x20(%rax)
callq 0x1b7ca0
movsd %xmm0, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x50(%rbp), %rcx
movl 0x4(%rcx), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jge 0x18a96a
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x44(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x18a9e0
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x18a924
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq 0x239664(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x60(%rbp)
callq 0x1b7ca0
movq -0x60(%rbp), %rdi
subsd -0x38(%rbp), %xmm0
leaq 0x2004da(%rip), %rsi    # 0x38ae72
leaq 0x2004f9(%rip), %rdx    # 0x38ae98
movb $0x1, %al
callq 0x22a0
movq 0x239633(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x2004ef(%rip), %rsi    # 0x38aea6
leaq 0x2004da(%rip), %rdx    # 0x38ae98
movb $0x0, %al
callq 0x22a0
movq -0x20(%rbp), %rdi
callq 0x2210
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop