// File: /workspace/github_cpp_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %rax
movq %rdi, %r12
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rdi
movq %r12, %rcx
callq 0x22f0
movq %r12, %rdi
callq 0x2320
testl %eax, %eax
je 0xb921
xorl %r13d, %r13d
jmp 0xbacb
pushq $0x4
popq %rsi
pushq $0x1
popq %r13
movq %r15, %rdi
movq %r13, %rdx
movq %r12, %rcx
callq 0x22f0
leaq 0x40(%r14), %rdi
pushq $0x8
popq %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x22f0
movq 0x38(%r14), %rdi
movq 0x40(%r14), %rdx
cmpq %rdx, 0x48(%r14)
jae 0xb9aa
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
pushq $0x4
popq %rsi
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 0xba1f
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 0xba23
movq 0x10(%r14), %rdi
pushq $0x1
popq %r13
movq %r13, %rsi
movq %r12, %rcx
callq 0x22f0
movl (%r15), %eax
cmpl $0x4, %eax
pushq $0x4
popq %r12
cmovbl %eax, %r12d
movq %rax, %rbp
subq %r12, %rbp
movl %ebp, %r15d
andl $0x3, %r15d
sarq $0x2, %rbp
testq %rax, %rax
je 0xba73
movq 0x10(%r14), %rax
movzbl (%rax), %eax
leaq 0x247fcc(%rip), %rcx    # 0x253a30
leaq (%rcx,%rax,4), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x2160
xorl %eax, %eax
testq %rbp, %rbp
cmovleq %rax, %rbp
movl %r12d, %ecx
shrl $0x2, %ecx
addq %r12, %rbx
shlq $0x2, %rbp
leaq 0x247fa0(%rip), %rdx    # 0x253a30
cmpq %rax, %rbp
je 0xbaac
movq 0x10(%r14), %rsi
movzbl (%rsi,%rcx), %esi
movl (%rdx,%rsi,4), %esi
movl %esi, (%rbx,%rax)
incq %rcx
addq $0x4, %rax
jmp 0xba90
testq %r15, %r15
je 0xbacb
addq %rax, %rbx
movq 0x10(%r14), %rax
movzbl (%rax,%rcx), %eax
leaq (%rdx,%rax,4), %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x2160
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq