// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Process_Read.cpp
// Function: load_compress_base_disk(_IO_FILE*, unsigned long*, char*, unsigned int*, ul_vec_t*)
int64_t load_compress_base_disk(FILE *fp, uint64_t *ul_rid, char *dest, uint32_t *len, ul_vec_t *buf)
{
	fread(ul_rid, sizeof((*ul_rid)), 1, fp);
	if(feof(fp)) return 0;
	fread(len, sizeof((*len)), 1, fp);
	fread(&buf->N_site.n, sizeof(buf->N_site.n), 1, fp);
	kv_resize(uint32_t, buf->N_site, buf->N_site.n);
	fread(buf->N_site.a, sizeof((*buf->N_site.a)), buf->N_site.n, fp);
	buf->r_base.n = B4L((*len)); kv_resize(uint8_t, buf->r_base, buf->r_base.n); 
	fread(buf->r_base.a, sizeof((*buf->r_base.a)), buf->r_base.n, fp);

	int64_t ssp, sep, sl, offset, begLen, tailLen, a_n, src_i, des_i, i;
	ssp = 0; sep = (*len); sl = sep - ssp;
	offset = ssp&3; begLen = 4-offset;
	if(begLen > sl) begLen = sl;
	tailLen = (sl-begLen)&3;
	a_n = (sl - begLen - tailLen)>>2;

	src_i = ssp; i = 0; des_i = 0;
	if(begLen > 0) {
		memcpy(dest+des_i, bit_t_seq_table[buf->r_base.a[src_i>>2]]+offset, begLen);
		des_i += begLen; src_i += begLen;
	}

	for (i = 0; i < a_n; i++) {
		memcpy(dest+des_i, bit_t_seq_table[buf->r_base.a[src_i>>2]], 4);
		des_i += 4; src_i += 4;
	}

	if(tailLen > 0) {
		memcpy(dest+des_i, bit_t_seq_table[buf->r_base.a[src_i>>2]], tailLen);
		des_i += tailLen; src_i += tailLen;
	}
	return 1;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %rax
movq %rdi, %r12
movl $0x8, %esi
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rcx
callq 0x22f0
movq %r12, %rdi
callq 0x2320
testl %eax, %eax
je 0x37c3a
xorl %r13d, %r13d
jmp 0x37df0
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r12, %rcx
callq 0x22f0
leaq 0x40(%r14), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x22f0
movq 0x38(%r14), %rdi
movq 0x40(%r14), %rdx
cmpq %rdx, 0x48(%r14)
jae 0x37cc7
decq %rdx
movq %rdx, %rax
shrq %rax
orq %rdx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x48(%r14)
leaq 0x4(,%rax,4), %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x38(%r14)
movq 0x40(%r14), %rdx
movl $0x4, %esi
movq %r12, %rcx
callq 0x22f0
movl (%r15), %eax
movl %eax, %edx
shrl $0x2, %edx
andl $0x3, %eax
cmpl $0x1, %eax
sbbl $-0x1, %edx
movq %rdx, (%r14)
cmpq %rdx, 0x8(%r14)
jae 0x37d3e
decq %rdx
movq %rdx, %rax
shrq %rax
orq %rdx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x10(%r14)
movq (%r14), %rdx
jmp 0x37d42
movq 0x10(%r14), %rdi
movl $0x1, %esi
movq %r12, %rcx
callq 0x22f0
movl (%r15), %eax
cmpl $0x4, %eax
movl $0x4, %r12d
cmovbl %eax, %r12d
movq %rax, %r13
subq %r12, %r13
movl %r13d, %r15d
andl $0x3, %r15d
sarq $0x2, %r13
testq %rax, %rax
je 0x37d92
movq 0x10(%r14), %rax
movzbl (%rax), %eax
leaq 0x25dcad(%rip), %rcx    # 0x295a30
leaq (%rcx,%rax,4), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x2160
testq %r13, %r13
jle 0x37dbf
movl %r12d, %eax
shrl $0x2, %eax
leaq 0x25dc8c(%rip), %rcx    # 0x295a30
movq 0x10(%r14), %rdx
movzbl (%rdx,%rax), %edx
movl (%rcx,%rdx,4), %edx
movl %edx, (%rbx,%r12)
addq $0x4, %r12
incq %rax
decq %r13
jne 0x37da4
movl $0x1, %r13d
testq %r15, %r15
je 0x37df0
addq %r12, %rbx
movq 0x10(%r14), %rax
shrq $0x2, %r12
movzbl (%rax,%r12), %eax
leaq 0x25dc4f(%rip), %rcx    # 0x295a30
leaq (%rcx,%rax,4), %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x2160
movq %r13, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq