// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Process_Read.cpp
// Function: load_All_reads(All_reads*, char*)
int load_All_reads(All_reads* r, char* read_file_name)
{
    char* index_name = (char*)malloc(strlen(read_file_name)+15);
    sprintf(index_name, "%s.bin", read_file_name);
    FILE* fp = fopen(index_name, "r");
	if (!fp) {
		free(index_name);
        return 0;
    }
	int local_adapterLen;
	int f_flag;
    f_flag = fread(&local_adapterLen, sizeof(local_adapterLen), 1, fp);
    if(local_adapterLen != asm_opt.adapterLen)
    {
        fprintf(stderr, "the adapterLen of index is: %d, but the adapterLen set by user is: %d\n", 
        local_adapterLen, asm_opt.adapterLen);
		exit(1);
    }
    f_flag += fread(&r->index_size, sizeof(r->index_size), 1, fp);
	f_flag += fread(&r->name_index_size, sizeof(r->name_index_size), 1, fp);
	f_flag += fread(&r->total_reads, sizeof(r->total_reads), 1, fp);
	f_flag += fread(&r->total_reads_bases, sizeof(r->total_reads_bases), 1, fp);
	f_flag += fread(&r->total_name_length, sizeof(r->total_name_length), 1, fp);

	uint64_t i = 0;
	uint64_t zero = 0;
	r->N_site = (uint64_t**)malloc(sizeof(uint64_t*)*r->total_reads);
	for (i = 0; i < r->total_reads; i++)
	{
		f_flag += fread(&zero, sizeof(zero), 1, fp);

		if (zero)
		{
			r->N_site[i] = (uint64_t*)malloc(sizeof(uint64_t)*(zero + 1));
			r->N_site[i][0] = zero;
			if (r->N_site[i][0])
			{
				f_flag += fread(r->N_site[i]+1, sizeof(r->N_site[i][0]), r->N_site[i][0], fp);
			}
		}
		else
		{
			r->N_site[i] = NULL;
		}
	}

	r->read_length = (uint64_t*)malloc(sizeof(uint64_t)*r->total_reads);
	f_flag += fread(r->read_length, sizeof(uint64_t), r->total_reads, fp);

	r->read_size = (uint64_t*)malloc(sizeof(uint64_t)*r->total_reads);
	memcpy (r->read_size, r->read_length, sizeof(uint64_t)*r->total_reads);

	r->read_sperate = (uint8_t**)malloc(sizeof(uint8_t*)*r->total_reads);
	for (i = 0; i < r->total_reads; i++)
    {
		r->read_sperate[i] = (uint8_t*)malloc(sizeof(uint8_t)*(r->read_length[i]/4+1));
		f_flag += fread(r->read_sperate[i], sizeof(uint8_t), r->read_length[i]/4+1, fp);
	}


	r->name = (char*)malloc(sizeof(char)*r->total_name_length);
	f_flag += fread(r->name, sizeof(char), r->total_name_length, fp);

	r->name_index = (uint64_t*)malloc(sizeof(uint64_t)*r->name_index_size);
	f_flag += fread(r->name_index, sizeof(uint64_t), r->name_index_size, fp);

	/****************************may have bugs********************************/
	r->trio_flag = (uint8_t*)malloc(sizeof(uint8_t)*r->total_reads);
	f_flag += fread(r->trio_flag, sizeof(uint8_t), r->total_reads, fp);
	f_flag += fread(&(asm_opt.hom_cov), sizeof(asm_opt.hom_cov), 1, fp);
    f_flag += fread(&(asm_opt.het_cov), sizeof(asm_opt.het_cov), 1, fp);
	/****************************may have bugs********************************/

	r->cigars = (Compressed_Cigar_record*)malloc(sizeof(Compressed_Cigar_record)*r->total_reads);
	r->second_round_cigar = (Compressed_Cigar_record*)malloc(sizeof(Compressed_Cigar_record)*r->total_reads);
	for (i = 0; i < r->total_reads; i++)
	{
		r->second_round_cigar[i].size = r->cigars[i].size = 0;
		r->second_round_cigar[i].length = r->cigars[i].length = 0;
		r->second_round_cigar[i].record = r->cigars[i].record = NULL;

		r->second_round_cigar[i].lost_base_size = r->cigars[i].lost_base_size = 0;
		r->second_round_cigar[i].lost_base_length = r->cigars[i].lost_base_length = 0;
		r->second_round_cigar[i].lost_base = r->cigars[i].lost_base = NULL;
	}
	///r->pb_regions = NULL;

	uint64_t mm = 0;
	if (!feof(fp)) {
		if((fread(&mm, sizeof(mm), 1, fp)) && (mm == 1)) {
			MALLOC(r->rsc, r->total_reads);
			for (i = 0; i < r->total_reads; i++) {
				MALLOC(r->rsc[i], (r->read_length[i]/sc_bn) + ((r->read_length[i]%sc_bn)?1:0));
				f_flag += fread(r->rsc[i], sizeof(uint8_t), (r->read_length[i]/sc_bn) + ((r->read_length[i]%sc_bn)?1:0), fp);
			}
		}
	}



    free(index_name);    
    fclose(fp);
    fprintf(stderr, "Reads has been loaded.\n");

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x2090
leaq 0xf(%rax), %rdi
callq 0x2280
movq %rax, %r12
leaq 0x1dca22(%rip), %rsi    # 0x1e264b
xorl %ebp, %ebp
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x1eba78(%rip), %rsi    # 0x1f16b7
movq %r12, %rdi
callq 0x2210
testq %rax, %rax
jne 0x5c65
movq %r12, %rdi
callq 0x2220
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq %r12, 0x18(%rsp)
leaq 0x24(%rsp), %r14
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %rax, %rcx
callq 0x22f0
movl (%r14), %edx
leaq 0x24dacb(%rip), %rax    # 0x253758
movl 0x100(%rax), %ecx
cmpl %ecx, %edx
jne 0x6023
leaq 0x38(%rbx), %rdi
pushq $0x8
popq %r13
pushq $0x1
popq %r14
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x22f0
leaq 0x48(%rbx), %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x22f0
leaq 0x50(%rbx), %r12
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x22f0
leaq 0x58(%rbx), %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x22f0
leaq 0x60(%rbx), %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x22f0
leaq 0x10(%rsp), %rax
andq $0x0, (%rax)
movq 0x50(%rbx), %rbp
leaq (,%rbp,8), %rdi
callq 0x2280
movq %rax, (%rbx)
xorl %r14d, %r14d
cmpq %rbp, %r14
jae 0x5d85
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x22f0
movq 0x10(%rsp), %rbp
testq %rbp, %rbp
je 0x5d74
leaq 0x8(,%rbp,8), %rdi
callq 0x2280
movq (%rbx), %rcx
movq %rax, (%rcx,%r14,8)
movq (%rbx), %rax
movq (%rax,%r14,8), %rdi
movq %rbp, (%rdi)
addq $0x8, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x22f0
jmp 0x5d7c
movq (%rbx), %rax
andq $0x0, (%rax,%r14,8)
incq %r14
movq (%r12), %rbp
jmp 0x5d20
leaq (,%rbp,8), %rdi
callq 0x2280
movq %rax, 0x18(%rbx)
pushq $0x8
popq %rsi
movq %rax, %rdi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x22f0
movq 0x50(%rbx), %r13
leaq (,%r13,8), %r14
movq %r14, %rdi
callq 0x2280
movq %rax, 0x20(%rbx)
movq 0x18(%rbx), %rsi
movq %rax, %rdi
movq %r14, %rdx
callq 0x2160
movq %r14, %rdi
callq 0x2280
movq %rax, 0x10(%rbx)
xorl %r12d, %r12d
pushq $0x1
popq %r14
cmpq %r13, %r12
jae 0x5e2d
movq 0x18(%rbx), %rax
movq (%rax,%r12,8), %rdi
shrq $0x2, %rdi
incq %rdi
callq 0x2280
movq 0x10(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rax,%r12,8), %rdi
movq (%rcx,%r12,8), %rdx
shrq $0x2, %rdx
incq %rdx
movq %r14, %rsi
movq %r15, %rcx
callq 0x22f0
incq %r12
movq 0x50(%rbx), %r13
jmp 0x5de1
movq 0x60(%rbx), %r12
movq %r12, %rdi
callq 0x2280
movq %rax, 0x8(%rbx)
pushq $0x1
popq %r14
movq %rax, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
movq 0x48(%rbx), %r12
leaq (,%r12,8), %rdi
callq 0x2280
movq %rax, 0x40(%rbx)
pushq $0x8
popq %rsi
movq %rax, %rdi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
movq 0x50(%rbx), %r12
movq %r12, %rdi
callq 0x2280
movq %rax, 0x28(%rbx)
movq %rax, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
leaq 0x24d8b8(%rip), %r13    # 0x253758
leaq 0xd0(%r13), %rdi
pushq $0x4
popq %r12
movq %r12, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x22f0
addq $0xd4, %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x22f0
movq 0x50(%rbx), %r13
imulq $0x28, %r13, %r12
movq %r12, %rdi
callq 0x2280
movq %rax, %r14
movq %rax, 0x68(%rbx)
movq %r12, %rdi
callq 0x2280
movq %rax, 0x70(%rbx)
pushq $0x1c
popq %rcx
subq $0x1, %r13
jb 0x5f45
andl $0x0, -0x10(%r14,%rcx)
andl $0x0, -0x10(%rax,%rcx)
andl $0x0, -0x14(%r14,%rcx)
andl $0x0, -0x14(%rax,%rcx)
andq $0x0, -0x1c(%r14,%rcx)
andq $0x0, -0x1c(%rax,%rcx)
andl $0x0, (%r14,%rcx)
andl $0x0, (%rax,%rcx)
andl $0x0, -0x4(%r14,%rcx)
andl $0x0, -0x4(%rax,%rcx)
andq $0x0, -0xc(%r14,%rcx)
andq $0x0, -0xc(%rax,%rcx)
addq $0x28, %rcx
jmp 0x5ef7
andq $0x0, 0x8(%rsp)
movq %r15, %rdi
callq 0x2320
testl %eax, %eax
jne 0x5fed
leaq 0x8(%rsp), %rdi
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x22f0
testq %rax, %rax
je 0x5fed
cmpq $0x1, 0x8(%rsp)
jne 0x5fed
movq 0x50(%rbx), %r13
leaq (,%r13,8), %rdi
callq 0x2280
movq %rax, 0x30(%rbx)
xorl %r12d, %r12d
pushq $0x1
popq %r14
cmpq %r13, %r12
jae 0x5fed
movq 0x18(%rbx), %rax
movq (%rax,%r12,8), %rdi
movq %rdi, %rax
shrq %rax
andl $0x1, %edi
addq %rax, %rdi
callq 0x2280
movq 0x30(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x18(%rbx), %rax
movq 0x30(%rbx), %rcx
movq (%rcx,%r12,8), %rdi
movq (%rax,%r12,8), %rdx
movq %rdx, %rax
shrq %rax
andl $0x1, %edx
addq %rax, %rdx
movq %r14, %rsi
movq %r15, %rcx
callq 0x22f0
incq %r12
movq 0x50(%rbx), %r13
jmp 0x5f97
movq 0x18(%rsp), %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2190
movq 0x24cfda(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x1dc6a2(%rip), %rdi    # 0x1e26b2
pushq $0x17
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
pushq $0x1
popq %rbp
jmp 0x5c54
movq 0x24cfb6(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x1dc637(%rip), %rsi    # 0x1e266b
xorl %eax, %eax
callq 0x22b0
pushq $0x1
popq %rdi
callq 0x2250