// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x2090
leaq 0xf(%rax), %rdi
callq 0x2280
movq %rax, %r14
leaq 0x1f1f8b(%rip), %rsi    # 0x22463b
xorl %ebp, %ebp
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x200ee1(%rip), %rsi    # 0x2335a7
movq %r14, %rdi
callq 0x2210
testq %rax, %rax
jne 0x326ec
movq %r14, %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 %r14, 0x18(%rsp)
leaq 0x24(%rsp), %r12
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rax, %rcx
callq 0x22f0
movl (%r12), %edi
leaq 0x25803f(%rip), %rax    # 0x28a758
movl 0x100(%rax), %esi
cmpl %esi, %edi
jne 0x32adb
leaq 0x38(%rbx), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x22f0
leaq 0x48(%rbx), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x22f0
leaq 0x50(%rbx), %r13
movl $0x8, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %r15, %rcx
callq 0x22f0
leaq 0x58(%rbx), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x22f0
leaq 0x60(%rbx), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x22f0
movq $0x0, 0x10(%rsp)
movq 0x50(%rbx), %r12
leaq (,%r12,8), %rdi
callq 0x2280
movq %rax, (%rbx)
testq %r12, %r12
je 0x3282c
xorl %r14d, %r14d
leaq 0x10(%rsp), %rbp
movl $0x8, %esi
movl $0x1, %edx
movq %rbp, %rdi
movq %r15, %rcx
callq 0x22f0
movq 0x10(%rsp), %r12
testq %r12, %r12
je 0x32815
leaq 0x8(,%r12,8), %rdi
callq 0x2280
movq (%rbx), %rcx
movq %rax, (%rcx,%r14,8)
movq (%rbx), %rax
movq (%rax,%r14,8), %rdi
movq %r12, (%rdi)
addq $0x8, %rdi
movl $0x8, %esi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
jmp 0x32820
movq (%rbx), %rax
movq $0x0, (%rax,%r14,8)
incq %r14
movq (%r13), %r12
cmpq %r12, %r14
jb 0x327c2
leaq (,%r12,8), %rdi
callq 0x2280
movq %rax, 0x18(%rbx)
movl $0x8, %esi
movq %rax, %rdi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
movq 0x50(%rbx), %r12
shlq $0x3, %r12
movq %r12, %rdi
callq 0x2280
movq %rax, 0x20(%rbx)
movq 0x18(%rbx), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x2160
movq %r12, %rdi
callq 0x2280
movq %rax, 0x10(%rbx)
cmpq $0x0, 0x50(%rbx)
je 0x328d2
xorl %r14d, %r14d
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rdi
shrq $0x2, %rdi
incq %rdi
callq 0x2280
movq 0x10(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rax,%r14,8), %rdi
movq (%rcx,%r14,8), %rdx
shrq $0x2, %rdx
incq %rdx
movl $0x1, %esi
movq %r15, %rcx
callq 0x22f0
incq %r14
cmpq 0x50(%rbx), %r14
jb 0x32889
movq 0x60(%rbx), %r12
movq %r12, %rdi
callq 0x2280
movq %rax, 0x8(%rbx)
movl $0x1, %esi
movq %rax, %rdi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
movq 0x48(%rbx), %r12
leaq (,%r12,8), %rdi
callq 0x2280
movq %rax, 0x40(%rbx)
movl $0x8, %esi
movq %rax, %rdi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
movq 0x50(%rbx), %r12
movq %r12, %rdi
callq 0x2280
movq %rax, 0x28(%rbx)
movl $0x1, %esi
movq %rax, %rdi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
leaq 0x257e11(%rip), %r14    # 0x28a758
leaq 0xd0(%r14), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x22f0
addq $0xd4, %r14
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rcx
callq 0x22f0
movq 0x50(%rbx), %r14
leaq (,%r14,8), %rax
leaq (%rax,%rax,4), %r13
movq %r13, %rdi
callq 0x2280
movq %rax, %r12
movq %rax, 0x68(%rbx)
movq %r13, %rdi
callq 0x2280
movq %rax, 0x70(%rbx)
testq %r14, %r14
je 0x329f2
movl $0x1c, %ecx
xorl %edx, %edx
movl %edx, -0x10(%r12,%rcx)
movl %edx, -0x10(%rax,%rcx)
movl %edx, -0x14(%r12,%rcx)
movl %edx, -0x14(%rax,%rcx)
movq %rdx, -0x1c(%r12,%rcx)
movq %rdx, -0x1c(%rax,%rcx)
movl %edx, (%r12,%rcx)
movl %edx, (%rax,%rcx)
movl %edx, -0x4(%r12,%rcx)
movl %edx, -0x4(%rax,%rcx)
movq %rdx, -0xc(%r12,%rcx)
movq %rdx, -0xc(%rax,%rcx)
addq $0x28, %rcx
decq %r14
jne 0x329b3
movq $0x0, 0x8(%rsp)
movq %r15, %rdi
callq 0x2320
testl %eax, %eax
jne 0x32a9f
leaq 0x8(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x22f0
testq %rax, %rax
je 0x32a9f
cmpq $0x1, 0x8(%rsp)
jne 0x32a9f
movq 0x50(%rbx), %r14
leaq (,%r14,8), %rdi
callq 0x2280
movq %rax, 0x30(%rbx)
testq %r14, %r14
je 0x32a9f
xorl %r14d, %r14d
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rdi
movq %rdi, %rax
shrq %rax
andl $0x1, %edi
addq %rax, %rdi
callq 0x2280
movq 0x30(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x18(%rbx), %rax
movq 0x30(%rbx), %rcx
movq (%rcx,%r14,8), %rdi
movq (%rax,%r14,8), %rdx
movq %rdx, %rax
shrq %rax
andl $0x1, %edx
addq %rax, %rdx
movl $0x1, %esi
movq %r15, %rcx
callq 0x22f0
incq %r14
cmpq 0x50(%rbx), %r14
jb 0x32a4c
movq 0x18(%rsp), %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2190
movq 0x257528(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x1f1be0(%rip), %rdi    # 0x2246a2
movl $0x17, %esi
movl $0x1, %edx
callq 0x2410
movl $0x1, %ebp
jmp 0x326db
callq 0x3a3d