// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movl %ecx, %ebp
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 0x331df
movq %rdi, %r14
leaq 0x4(%r12), %rsi
movq %rsi, 0x10(%rdi)
movq %r15, %rdi
movq %r8, %r15
callq 0x2370
movq %r15, %r8
movq %rax, %r15
movq %rax, (%r14)
movq 0x10(%r8), %rax
movq (%rax,%rbx,8), %r14
leaq (%r12,%r13), %r10
testb %bpl, %bpl
je 0x332f2
movq 0x18(%r8), %rax
movq %rbx, 0x20(%rsp)
movq (%rax,%rbx,8), %rbp
movq %rbp, 0x18(%rsp)
subq %r13, %rbp
leaq 0x3(%rbp), %rax
testq %rbp, %rbp
cmovnsq %rbp, %rax
leaq -0x1(%rbp), %rbx
andq $-0x4, %rax
movq %rbp, %r13
subq %rax, %r13
je 0x33264
movq %rbx, %rax
sarq $0x2, %rax
movzbl (%r14,%rax), %eax
leaq 0x262bf9(%rip), %rcx    # 0x295e30
leaq (%rcx,%rax,4), %rsi
subq %r13, %rsi
addq $0x4, %rsi
movq %r15, %rdi
movq %r13, %rdx
movq %r8, 0x10(%rsp)
movq %r10, 0x8(%rsp)
callq 0x2160
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %r8
subq %r13, %rbx
cmpq %r12, %r13
jge 0x33290
leaq 0x262bc0(%rip), %rax    # 0x295e30
movq %rbx, %rcx
sarq $0x2, %rcx
movzbl (%r14,%rcx), %ecx
movl (%rax,%rcx,4), %ecx
movl %ecx, (%r15,%r13)
addq $0x4, %r13
addq $-0x4, %rbx
cmpq %r12, %r13
jl 0x33270
movq (%r8), %rax
movq 0x20(%rsp), %rsi
movq (%rax,%rsi,8), %rdx
testq %rdx, %rdx
movq 0x18(%rsp), %rdi
je 0x333d1
cmpq $0x0, (%rdx)
jle 0x333d1
subq %r10, %rdi
addq %rbp, %r15
xorl %ecx, %ecx
movq 0x8(%rdx,%rcx,8), %rdx
cmpq %rdi, %rdx
jl 0x332d8
cmpq %rbp, %rdx
jge 0x332d8
notq %rdx
movb $0x4e, (%r15,%rdx)
movq (%r8), %rax
jmp 0x332e1
cmpq %rbp, %rdx
jge 0x333d1
movq (%rax,%rsi,8), %rdx
incq %rcx
cmpq (%rdx), %rcx
jl 0x332bc
jmp 0x333d1
leaq 0x3(%r13), %rcx
testq %r13, %r13
cmovnsq %r13, %rcx
andq $-0x4, %rcx
movq %r13, %rax
subq %rcx, %rax
je 0x33352
movq %r13, %rcx
sarq $0x2, %rcx
movzbl (%r14,%rcx), %ecx
leaq 0x262714(%rip), %rdx    # 0x295a30
leaq (%rdx,%rcx,4), %rsi
addq %rax, %rsi
movl $0x4, %ebp
subq %rax, %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 0x33357
xorl %ebp, %ebp
movq %r13, %rax
cmpq %r12, %rbp
jge 0x33383
leaq 0x2626cd(%rip), %rcx    # 0x295a30
movq %rax, %rdx
sarq $0x2, %rdx
movzbl (%r14,%rdx), %edx
movl (%rcx,%rdx,4), %edx
movl %edx, (%r15,%rbp)
addq $0x4, %rbp
addq $0x4, %rax
cmpq %r12, %rbp
jl 0x33363
movq (%r8), %rax
movq (%rax,%rbx,8), %rdx
testq %rdx, %rdx
je 0x333d1
cmpq $0x0, (%rdx)
jle 0x333d1
xorl %ecx, %ecx
movq 0x8(%rdx,%rcx,8), %rdx
movq %rdx, %rsi
subq %r13, %rsi
setge %dil
cmpq %r10, %rdx
setl %r9b
andb %dil, %r9b
cmpb $0x1, %r9b
jne 0x333c0
movb $0x4e, (%r15,%rsi)
movq (%r8), %rax
jmp 0x333c5
cmpq %r10, %rdx
jge 0x333d1
movq (%rax,%rbx,8), %rdx
incq %rcx
cmpq (%rdx), %rcx
jl 0x33397
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq