// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb %al, -0x19(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x8, %rax
movq -0x8(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jle 0x9fb8
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x4, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x0, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
addq -0x18(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x60(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jne 0xa1a2
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rax
movl $0x4, %ecx
cqto
idivq %rcx
movq %rdx, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0xa081
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rax
movq -0x50(%rbp), %rcx
sarq $0x2, %rcx
movzbl (%rax,%rcx), %eax
leaq 0x3baa84(%rip), %rsi    # 0x3c4ad0
shlq $0x2, %rax
addq %rax, %rsi
addq -0x68(%rbp), %rsi
movl $0x4, %edx
subq -0x68(%rbp), %rdx
callq 0x2180
movq -0x58(%rbp), %rax
addq $0x4, %rax
subq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0xa083
movq -0x58(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0xa0ce
movq -0x38(%rbp), %rax
movq -0x58(%rbp), %rcx
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rsi
sarq $0x2, %rsi
movzbl (%rdx,%rsi), %edx
movl %edx, %esi
leaq 0x3baa22(%rip), %rdx    # 0x3c4ad0
movl (%rdx,%rsi,4), %edx
movl %edx, (%rax,%rcx)
movq -0x58(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x50(%rbp)
jmp 0xa083
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0xa19d
movq $0x1, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpq (%rcx), %rax
jg 0xa19b
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x10(%rbp), %rax
jl 0xa167
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x60(%rbp), %rax
jg 0xa167
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x50(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
subq -0x10(%rbp), %rcx
movb $0x4e, (%rax,%rcx)
jmp 0xa188
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x60(%rbp), %rax
jle 0xa186
jmp 0xa19b
jmp 0xa188
jmp 0xa18a
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xa0ec
jmp 0xa19d
jmp 0xa375
movq -0x40(%rbp), %rax
subq -0x10(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x10(%rbp)
movq -0x40(%rbp), %rax
subq -0x60(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movl $0x4, %ecx
cqto
idivq %rcx
movq %rdx, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0xa23f
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rax
movq -0x50(%rbp), %rcx
sarq $0x2, %rcx
movzbl (%rax,%rcx), %eax
leaq 0x3bacc6(%rip), %rsi    # 0x3c4ed0
shlq $0x2, %rax
addq %rax, %rsi
addq $0x4, %rsi
xorl %eax, %eax
subq -0x70(%rbp), %rax
addq %rax, %rsi
movq -0x70(%rbp), %rdx
callq 0x2180
movq -0x58(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
subq -0x70(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0xa241
movq -0x58(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0xa28c
movq -0x38(%rbp), %rax
movq -0x58(%rbp), %rcx
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rsi
sarq $0x2, %rsi
movzbl (%rdx,%rsi), %edx
movl %edx, %esi
leaq 0x3bac64(%rip), %rdx    # 0x3c4ed0
movl (%rdx,%rsi,4), %edx
movl %edx, (%rax,%rcx)
movq -0x58(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
subq $0x4, %rax
movq %rax, -0x50(%rbp)
jmp 0xa241
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0xa373
movq -0x40(%rbp), %rax
subq -0x10(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x78(%rbp)
movq $0x1, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpq (%rcx), %rax
jg 0xa371
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x60(%rbp), %rax
jl 0xa33d
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x10(%rbp), %rax
jg 0xa33d
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rdx
movq (%rdx), %rdx
movq -0x30(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
movq -0x50(%rbp), %rsi
subq (%rdx,%rsi,8), %rcx
subq $0x1, %rcx
subq -0x78(%rbp), %rcx
movb $0x4e, (%rax,%rcx)
jmp 0xa35e
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x10(%rbp), %rax
jle 0xa35c
jmp 0xa371
jmp 0xa35e
jmp 0xa360
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xa2ba
jmp 0xa373
jmp 0xa375
addq $0x80, %rsp
popq %rbp
retq
nop