// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Process_Read.cpp
// Function: recover_UC_sub_Read(UC_Read*, long long, long long, unsigned char, All_reads*, long long)
void recover_UC_sub_Read(UC_Read* i_r, long long start_pos, long long length, uint8_t strand, All_reads* R_INF, long long ID)
{
	i_r->length = length;i_r->RID = ID;
	if (i_r->length + 8 > i_r->size)
	{
		i_r->size = i_r->length + 4;
		i_r->seq = (char*)realloc(i_r->seq,sizeof(char)*(i_r->size));
	}
	char* r = i_r->seq;
	long long readLen = Get_READ_LENGTH((*R_INF), ID);
	uint8_t* src = Get_READ((*R_INF), ID);

	long long i;
	long long copyLen;
	long long end_pos = start_pos + length - 1;

	if (strand == 0)
	{
		i = start_pos;
		copyLen = 0;

		long long initLen = start_pos % 4;

		if (initLen != 0)
		{
			memcpy(r, bit_t_seq_table[src[i>>2]] + initLen, 4 - initLen);
			copyLen = copyLen + 4 - initLen;
			i = i + copyLen;
		}

		while (copyLen < length)
		{
			memcpy(r+copyLen, bit_t_seq_table[src[i>>2]], 4);
			copyLen = copyLen + 4;
			i = i + 4;
		}

		if (R_INF->N_site[ID])
		{
			for (i = 1; i <= (long long)R_INF->N_site[ID][0]; i++)
			{
				if ((long long)R_INF->N_site[ID][i] >= start_pos && (long long)R_INF->N_site[ID][i] <= end_pos)
				{
					r[R_INF->N_site[ID][i] - start_pos] = 'N';
				}
				else if((long long)R_INF->N_site[ID][i] > end_pos)
				{
					break;
				}
			}
		}
	}
	else
	{
		start_pos = readLen - start_pos - 1;
		end_pos = readLen - end_pos - 1;

		///start_pos > end_pos
		i = start_pos;
		copyLen = 0;
		long long initLen = (start_pos + 1) % 4;

		if (initLen != 0)
		{
			memcpy(r, bit_t_seq_table_rc[src[i>>2]] + 4 - initLen, initLen);
			copyLen = copyLen + initLen;
			i = i - initLen;
		}

		while (copyLen < length)
		{
			memcpy(r+copyLen, bit_t_seq_table_rc[src[i>>2]], 4);
			copyLen = copyLen + 4;
			i = i - 4;
		}

		if (R_INF->N_site[ID])
		{
			long long offset = readLen - start_pos - 1;

			for (i = 1; i <= (long long)R_INF->N_site[ID][0]; i++)
			{
				if ((long long)R_INF->N_site[ID][i] >= end_pos && (long long)R_INF->N_site[ID][i] <= start_pos)
				{
					r[readLen - R_INF->N_site[ID][i] - 1 - offset] = 'N';
				}
				else if((long long)R_INF->N_site[ID][i] > start_pos)
				{
					break;
				}
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r14
movq %rdx, %r12
movq %rsi, %r13
movq %rdx, 0x8(%rdi)
movq %r9, 0x18(%rdi)
leaq 0x8(%rdx), %rax
movq (%rdi), %r15
cmpq 0x10(%rdi), %rax
jle 0x6f82
movq %rdi, %rbp
leaq 0x4(%r12), %rsi
movq %rsi, 0x10(%rdi)
movq %r15, %rdi
movq %r8, %rbx
movl %ecx, %r15d
callq 0x2370
movl %r15d, %ecx
movq %rbx, %r8
movq %rax, %r15
movq %rax, (%rbp)
movq 0x10(%r8), %rax
movq (%rax,%r14,8), %rbx
leaq (%r12,%r13), %r10
testb %cl, %cl
je 0x7085
movq 0x18(%r8), %rax
movq %r14, 0x20(%rsp)
movq (%rax,%r14,8), %rdi
movq %rdi, %rbp
subq %r13, %rbp
leaq -0x1(%rbp), %r14
pushq $0x4
popq %rcx
movq %rbp, %rax
cqto
idivq %rcx
movq %rdx, %r13
testq %rdx, %rdx
je 0x7009
movq %r14, %rax
sarq $0x2, %rax
movzbl (%rbx,%rax), %eax
leaq 0x24ce5e(%rip), %rcx    # 0x253e30
leaq (%rcx,%rax,4), %rsi
subq %r13, %rsi
addq $0x4, %rsi
movq %rdi, 0x18(%rsp)
movq %r15, %rdi
movq %r13, %rdx
movq %r8, 0x10(%rsp)
movq %r10, 0x8(%rsp)
callq 0x2160
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %r8
subq %r13, %r14
subq %r10, %rdi
leaq 0x24ce1d(%rip), %rax    # 0x253e30
cmpq %r12, %r13
jge 0x7034
movq %r14, %rcx
sarq $0x2, %rcx
movzbl (%rbx,%rcx), %ecx
movl (%rax,%rcx,4), %ecx
movl %ecx, (%r15,%r13)
addq $0x4, %r13
addq $-0x4, %r14
jmp 0x7013
movq (%r8), %rax
movq 0x20(%rsp), %rsi
movq (%rax,%rsi,8), %rax
testq %rax, %rax
je 0x714f
addq %rbp, %r15
pushq $0x1
popq %rcx
cmpq (%rax), %rcx
jg 0x714f
movq (%rax,%rcx,8), %rdx
cmpq %rdi, %rdx
jl 0x7077
cmpq %rbp, %rdx
jge 0x7077
notq %rdx
movb $0x4e, (%r15,%rdx)
movq (%r8), %rax
movq (%rax,%rsi,8), %rax
jmp 0x7080
cmpq %rbp, %rdx
jge 0x714f
incq %rcx
jmp 0x704f
pushq $0x4
popq %rbp
movq %r13, %rax
cqto
idivq %rbp
testq %rdx, %rdx
je 0x70d8
movq %r13, %rax
sarq $0x2, %rax
movzbl (%rbx,%rax), %eax
leaq 0x24c989(%rip), %rcx    # 0x253a30
leaq (%rcx,%rax,4), %rsi
addq %rdx, %rsi
subq %rdx, %rbp
movq %r15, %rdi
movq %rbp, %rdx
movq %r8, 0x10(%rsp)
movq %r10, 0x8(%rsp)
callq 0x2160
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %r8
movq %rbp, %rax
addq %r13, %rax
jmp 0x70dd
xorl %ebp, %ebp
movq %r13, %rax
leaq 0x24c94c(%rip), %rcx    # 0x253a30
cmpq %r12, %rbp
jge 0x7105
movq %rax, %rdx
sarq $0x2, %rdx
movzbl (%rbx,%rdx), %edx
movl (%rcx,%rdx,4), %edx
movl %edx, (%r15,%rbp)
addq $0x4, %rbp
addq $0x4, %rax
jmp 0x70e4
movq (%r8), %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x714f
pushq $0x1
popq %rcx
cmpq (%rax), %rcx
jg 0x714f
movq (%rax,%rcx,8), %rdx
movq %rdx, %rsi
subq %r13, %rsi
setge %dil
cmpq %r10, %rdx
setl %r9b
andb %dil, %r9b
cmpb $0x1, %r9b
jne 0x7145
movb $0x4e, (%r15,%rsi)
movq (%r8), %rax
movq (%rax,%r14,8), %rax
jmp 0x714a
cmpq %r10, %rdx
jge 0x714f
incq %rcx
jmp 0x7114
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq