// File: /workspace/github_cpp_makefile_star2_O1/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 %rdi, %r15
movq %rdx, 0x8(%rdi)
movq %r9, 0x18(%rdi)
leaq 0x8(%rdx), %rax
cmpq 0x10(%rdi), %rax
jle 0x33ade
leaq 0x4(%r12), %rsi
movq %rsi, 0x10(%r15)
movq (%r15), %rdi
movq %r8, %r14
callq 0x2370
movq %r14, %r8
movq %rax, (%r15)
movq (%r15), %r15
movq 0x10(%r8), %rax
movq (%rax,%rbx,8), %r14
leaq (%r12,%r13), %r9
testb %bpl, %bpl
je 0x33b68
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 0x33bcf
movq %rbx, %rax
sarq $0x2, %rax
movzbl (%r14,%rax), %eax
leaq 0x2572f7(%rip), %rcx    # 0x28ae30
leaq (%rcx,%rax,4), %rsi
subq %r13, %rsi
addq $0x4, %rsi
movq %r15, %rdi
movq %r13, %rdx
movq %r8, 0x10(%rsp)
movq %r9, 0x8(%rsp)
callq 0x2160
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %r8
subq %r13, %rbx
jmp 0x33bd2
leaq 0x3(%r13), %rcx
testq %r13, %r13
cmovnsq %r13, %rcx
andq $-0x4, %rcx
movq %r13, %rax
subq %rcx, %rax
je 0x33c65
movq %r13, %rcx
sarq $0x2, %rcx
movzbl (%r14,%rcx), %ecx
leaq 0x256e9a(%rip), %rdx    # 0x28aa30
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 %r9, 0x8(%rsp)
callq 0x2160
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %r8
movq %rbp, %rax
addq %r13, %rax
jmp 0x33c6a
xorl %r13d, %r13d
cmpq %r12, %r13
jge 0x33bfe
leaq 0x257252(%rip), %rax    # 0x28ae30
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 0x33bde
movq (%r8), %rax
movq 0x20(%rsp), %rdx
cmpq $0x0, (%rax,%rdx,8)
movq 0x18(%rsp), %rsi
je 0x33ce9
movq (%r8), %rax
movq (%rax,%rdx,8), %rcx
cmpq $0x0, (%rcx)
jle 0x33ce9
subq %r9, %rsi
addq %rbp, %r15
xorl %eax, %eax
movq 0x8(%rcx,%rax,8), %rcx
cmpq %rsi, %rcx
jl 0x33c48
cmpq %rbp, %rcx
jge 0x33c48
notq %rcx
movb $0x4e, (%r15,%rcx)
jmp 0x33c51
cmpq %rbp, %rcx
jge 0x33ce9
movq (%r8), %rcx
movq (%rcx,%rdx,8), %rcx
incq %rax
cmpq (%rcx), %rax
jl 0x33c2f
jmp 0x33ce9
xorl %ebp, %ebp
movq %r13, %rax
cmpq %r12, %rbp
jge 0x33c96
leaq 0x256dba(%rip), %rcx    # 0x28aa30
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 0x33c76
movq (%r8), %rax
cmpq $0x0, (%rax,%rbx,8)
je 0x33ce9
movq (%r8), %rax
movq (%rax,%rbx,8), %rcx
cmpq $0x0, (%rcx)
jle 0x33ce9
xorl %eax, %eax
movq 0x8(%rcx,%rax,8), %rcx
movq %rcx, %rdx
subq %r13, %rdx
setge %sil
cmpq %r9, %rcx
setl %dil
andb %sil, %dil
cmpb $0x1, %dil
jne 0x33cd5
movb $0x4e, (%r15,%rdx)
jmp 0x33cda
cmpq %r9, %rcx
jge 0x33ce9
movq (%r8), %rcx
movq (%rcx,%rbx,8), %rcx
incq %rax
cmpq (%rcx), %rax
jl 0x33caf
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq