// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Process_Read.cpp
// Function: write_All_reads(All_reads*, char*)
void write_All_reads(All_reads* r, char* read_file_name)
{
    fprintf(stderr, "Writing reads to disk... \n");
    char* index_name = (char*)malloc(strlen(read_file_name)+15);
    sprintf(index_name, "%s.bin", read_file_name);
    FILE* fp = fopen(index_name, "w");
	fwrite(&asm_opt.adapterLen, sizeof(asm_opt.adapterLen), 1, fp);
    fwrite(&r->index_size, sizeof(r->index_size), 1, fp);
	fwrite(&r->name_index_size, sizeof(r->name_index_size), 1, fp);
	fwrite(&r->total_reads, sizeof(r->total_reads), 1, fp);
	fwrite(&r->total_reads_bases, sizeof(r->total_reads_bases), 1, fp);
	fwrite(&r->total_name_length, sizeof(r->total_name_length), 1, fp);

	uint64_t i = 0;
	uint64_t zero = 0;
	for (i = 0; i < r->total_reads; i++)
	{
		if (r->N_site[i] != NULL)
		{
			///number of Ns
			fwrite(&r->N_site[i][0], sizeof(r->N_site[i][0]), 1, fp);
			if (r->N_site[i][0])
			{
				fwrite(r->N_site[i]+1, sizeof(r->N_site[i][0]), r->N_site[i][0], fp);
			}
		}
		else
		{
			fwrite(&zero, sizeof(zero), 1, fp);
		}
	}

	fwrite(r->read_length, sizeof(uint64_t), r->total_reads, fp);
	for (i = 0; i < r->total_reads; i++)
	{
		fwrite(r->read_sperate[i], sizeof(uint8_t), r->read_length[i]/4+1, fp);
	}
	
	fwrite(r->name, sizeof(char), r->total_name_length, fp);
	fwrite(r->name_index, sizeof(uint64_t), r->name_index_size, fp);
	fwrite(r->trio_flag, sizeof(uint8_t), r->total_reads, fp);
	fwrite(&(asm_opt.hom_cov), sizeof(asm_opt.hom_cov), 1, fp);
	fwrite(&(asm_opt.het_cov), sizeof(asm_opt.het_cov), 1, fp);

	uint64_t mm = 1;
	if(asm_opt.is_sc) {
		fwrite(&mm, sizeof(mm), 1, fp);
		for (i = 0; i < r->total_reads; i++) {
			fwrite(r->rsc[i], sizeof(uint8_t), ((r->read_length[i]/sc_bn) + ((r->read_length[i]%sc_bn)?1:0)), fp);
		}
	}

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq 0x24d66d(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x1dccb3(%rip), %rdi    # 0x1e2630
pushq $0x1a
popq %rsi
pushq $0x1
popq %r13
movq %r13, %rdx
callq 0x2410
movq %r15, %rdi
callq 0x2090
leaq 0xf(%rax), %rdi
callq 0x2280
movq %rax, %r12
leaq 0x1dcca4(%rip), %rsi    # 0x1e264b
xorl %r14d, %r14d
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x1f4ce3(%rip), %rsi    # 0x1fa6a1
movq %r12, (%rsp)
movq %r12, %rdi
callq 0x2210
movq %rax, %r15
movl $0x100, %edi            # imm = 0x100
addq 0x24d5ff(%rip), %rdi    # 0x252fd8
pushq $0x4
popq %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x2410
leaq 0x38(%rbx), %rdi
pushq $0x8
popq %rbp
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x48(%rbx), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x50(%rbx), %r12
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x58(%rbx), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x60(%rbx), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x10(%rsp), %rax
andq $0x0, (%rax)
movq (%r12), %rdx
cmpq %rdx, %r14
jae 0x5aa3
movq (%rbx), %rax
movq (%rax,%r14,8), %rdi
testq %rdi, %rdi
je 0x5a8b
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2410
movq (%rbx), %rax
movq (%rax,%r14,8), %rdi
movq (%rdi), %rdx
testq %rdx, %rdx
je 0x5a9e
addq $0x8, %rdi
movq %rbp, %rsi
jmp 0x5a96
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2410
incq %r14
jmp 0x5a50
movq 0x18(%rbx), %rdi
pushq $0x8
popq %rsi
movq %r15, %rcx
callq 0x2410
xorl %r13d, %r13d
pushq $0x1
popq %r14
cmpq (%r12), %r13
jae 0x5ae6
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rax,%r13,8), %rdi
movq (%rcx,%r13,8), %rdx
shrq $0x2, %rdx
incq %rdx
movq %r14, %rsi
movq %r15, %rcx
callq 0x2410
incq %r13
jmp 0x5ab9
movq 0x8(%rbx), %rdi
movq 0x60(%rbx), %rdx
pushq $0x1
popq %r14
movq %r14, %rsi
movq %r15, %rcx
callq 0x2410
movq 0x40(%rbx), %rdi
movq 0x48(%rbx), %rdx
pushq $0x8
popq %rsi
movq %r15, %rcx
callq 0x2410
movq 0x28(%rbx), %rdi
movq 0x50(%rbx), %rdx
movq %r14, %rsi
movq %r15, %rcx
callq 0x2410
leaq 0x24dc2e(%rip), %rbp    # 0x253758
leaq 0xd0(%rbp), %rdi
pushq $0x4
popq %r13
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0xd4(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x2410
movq $0x1, 0x8(%rsp)
cmpq $0x0, 0x2b0(%rbp)
jne 0x5bae
movq (%rsp), %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2200
movq %r15, %rdi
callq 0x2190
movq 0x24d455(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x1dcabd(%rip), %rdi    # 0x1e2652
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2410
leaq 0x8(%rsp), %rdi
pushq $0x8
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
movq %r15, %rcx
callq 0x2410
xorl %r13d, %r13d
cmpq (%r12), %r13
jae 0x5b6b
movq 0x18(%rbx), %rax
movq 0x30(%rbx), %rcx
movq (%rcx,%r13,8), %rdi
movq (%rax,%r13,8), %rdx
movq %rdx, %rax
shrq %rax
andl $0x1, %edx
addq %rax, %rdx
movq %r14, %rsi
movq %r15, %rcx
callq 0x2410
incq %r13
jmp 0x5bc8