// File: /workspace/github_cpp_makefile_star2_O1/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 0x38679
xorl %r12d, %r12d
jmp 0x3882f
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 0x40(%r14), %rax
cmpq %rax, 0x48(%r14)
jae 0x386ff
decq %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(%r14)
movq 0x38(%r14), %rdi
leaq 0x4(,%rcx,4), %rsi
callq 0x2370
movq %rax, 0x38(%r14)
movq 0x38(%r14), %rdi
movq 0x40(%r14), %rdx
movl $0x4, %esi
movq %r12, %rcx
callq 0x22f0
movl (%r15), %ecx
movl %ecx, %eax
shrl $0x2, %eax
andl $0x3, %ecx
cmpl $0x1, %ecx
sbbl $-0x1, %eax
movq %rax, (%r14)
cmpq %rax, 0x8(%r14)
jae 0x38776
decq %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(%r14)
movq 0x10(%r14), %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rdx
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 0x387d2
movq 0x10(%r14), %rax
movzbl (%rax), %eax
leaq 0x252272(%rip), %rcx    # 0x28aa30
leaq (%rcx,%rax,4), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x2160
movq %r12, %rax
jmp 0x387d4
xorl %eax, %eax
testq %r13, %r13
jle 0x387ff
shrl $0x2, %r12d
leaq 0x25224c(%rip), %rcx    # 0x28aa30
movq 0x10(%r14), %rdx
movzbl (%rdx,%r12), %edx
movl (%rcx,%rdx,4), %edx
movl %edx, (%rbx,%rax)
addq $0x4, %rax
incq %r12
decq %r13
jne 0x387e4
movl $0x1, %r12d
testq %r15, %r15
je 0x3882f
addq %rax, %rbx
movq 0x10(%r14), %rcx
shrq $0x2, %rax
movzbl (%rcx,%rax), %eax
leaq 0x252210(%rip), %rcx    # 0x28aa30
leaq (%rcx,%rax,4), %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x2160
movq %r12, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq