// File: chhylp123[P]hifiasm/Process_Read.cpp
// Function: recover_UC_Read_sub_region(char*, long, long, unsigned char, All_reads*, long)
void recover_UC_Read_sub_region(char* r, int64_t start_pos, int64_t length, uint8_t strand, All_reads* R_INF, int64_t ID)
{
	int64_t readLen = Get_READ_LENGTH((*R_INF), ID);
	int64_t end_pos = start_pos + length - 1, begLen, tailLen, offset, mn, src_i, des_i, i;
	uint8_t* src = Get_READ((*R_INF), ID);

	if(strand == 0) {
		offset = start_pos&3;
		begLen = 4-offset;
		if(begLen > length) begLen = length;
		tailLen = (length-begLen)&3;
		mn = (length - begLen - tailLen)>>2;
		src_i = start_pos; des_i = 0; i = 0;

		if(begLen > 0) {
			memcpy(r+des_i, bit_t_seq_table[src[src_i>>2]]+offset, begLen);
			des_i += begLen; src_i += begLen;
		}

		for (i = 0; i < mn; i++) {
			memcpy(r+des_i, bit_t_seq_table[src[src_i>>2]], 4);
			des_i += 4; src_i += 4;
		}

		if(tailLen > 0) {
			memcpy(r+des_i, bit_t_seq_table[src[src_i>>2]], tailLen);
			des_i += tailLen; src_i += tailLen;
		}

		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;

		begLen = (start_pos+1)&3;
		offset = 4 - begLen;
		if(begLen > length) begLen = length;
		tailLen = (length-begLen)&3;
		mn = (length - begLen - tailLen)>>2;
		src_i = start_pos; des_i = 0; i = 0;

		if(begLen > 0) {
			memcpy(r+des_i, bit_t_seq_table_rc[src[src_i>>2]]+offset, begLen);
			des_i += begLen; src_i -= begLen;
		}

		for (i = 0; i < mn; i++) {
			memcpy(r+des_i, bit_t_seq_table_rc[src[src_i>>2]], 4);
			des_i += 4; src_i -= 4;
		}

		if(tailLen > 0) {
			memcpy(r+des_i, bit_t_seq_table_rc[src[src_i>>2]], tailLen);
			des_i += tailLen; src_i -= tailLen;
		}

		/**
		if (R_INF->N_site[ID]) {
			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;
				}
			}
		}
		**/
		if (R_INF->N_site[ID]) {
			start_pos = readLen - start_pos - 1; end_pos = readLen - end_pos - 1;
			for (i = 1; i <= (long long)R_INF->N_site[ID][0]; i++) {
				offset = readLen - R_INF->N_site[ID][i] - 1;
				if(offset >= start_pos && offset <= end_pos) {
					r[offset - start_pos] = 'N';
				} else if(offset < 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 -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
addq -0x18(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x80(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jne 0x9cd3
movq -0x10(%rbp), %rax
andq $0x3, %rax
movq %rax, -0x58(%rbp)
movl $0x4, %eax
subq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x18(%rbp), %rax
jle 0x9ac4
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
subq -0x48(%rbp), %rax
andq $0x3, %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
subq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
sarq $0x2, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
cmpq $0x0, -0x48(%rbp)
jle 0x9b52
movq -0x8(%rbp), %rdi
addq -0x70(%rbp), %rdi
movq -0x80(%rbp), %rax
movq -0x68(%rbp), %rcx
sarq $0x2, %rcx
movzbl (%rax,%rcx), %eax
leaq 0x3bafaa(%rip), %rsi    # 0x3c4ad0
shlq $0x2, %rax
addq %rax, %rsi
addq -0x58(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x2180
movq -0x48(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x60(%rbp), %rax
jge 0x9bb1
movq -0x8(%rbp), %rax
movq -0x70(%rbp), %rcx
movq -0x80(%rbp), %rdx
movq -0x68(%rbp), %rsi
sarq $0x2, %rsi
movzbl (%rdx,%rsi), %edx
movl %edx, %esi
leaq 0x3baf4b(%rip), %rdx    # 0x3c4ad0
movl (%rdx,%rsi,4), %edx
movl %edx, (%rax,%rcx)
movq -0x70(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x68(%rbp)
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x9b5a
cmpq $0x0, -0x50(%rbp)
jle 0x9bff
movq -0x8(%rbp), %rdi
addq -0x70(%rbp), %rdi
movq -0x80(%rbp), %rax
movq -0x68(%rbp), %rcx
sarq $0x2, %rcx
movzbl (%rax,%rcx), %eax
leaq 0x3baef9(%rip), %rsi    # 0x3c4ad0
shlq $0x2, %rax
addq %rax, %rsi
movq -0x50(%rbp), %rdx
callq 0x2180
movq -0x50(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x9cce
movq $0x1, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpq (%rcx), %rax
jg 0x9ccc
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x10(%rbp), %rax
jl 0x9c98
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x40(%rbp), %rax
jg 0x9c98
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x78(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
subq -0x10(%rbp), %rcx
movb $0x4e, (%rax,%rcx)
jmp 0x9cb9
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x40(%rbp), %rax
jle 0x9cb7
jmp 0x9ccc
jmp 0x9cb9
jmp 0x9cbb
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x9c1d
jmp 0x9cce
jmp 0x9f24
movq -0x38(%rbp), %rax
subq -0x10(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x10(%rbp)
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
andq $0x3, %rax
movq %rax, -0x48(%rbp)
movl $0x4, %eax
subq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x18(%rbp), %rax
jle 0x9d22
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
subq -0x48(%rbp), %rax
andq $0x3, %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
subq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
sarq $0x2, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
cmpq $0x0, -0x48(%rbp)
jle 0x9db3
movq -0x8(%rbp), %rdi
addq -0x70(%rbp), %rdi
movq -0x80(%rbp), %rax
movq -0x68(%rbp), %rcx
sarq $0x2, %rcx
movzbl (%rax,%rcx), %eax
leaq 0x3bb14c(%rip), %rsi    # 0x3c4ed0
shlq $0x2, %rax
addq %rax, %rsi
addq -0x58(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x2180
movq -0x48(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rcx
movq -0x68(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x60(%rbp), %rax
jge 0x9e12
movq -0x8(%rbp), %rax
movq -0x70(%rbp), %rcx
movq -0x80(%rbp), %rdx
movq -0x68(%rbp), %rsi
sarq $0x2, %rsi
movzbl (%rdx,%rsi), %edx
movl %edx, %esi
leaq 0x3bb0ea(%rip), %rdx    # 0x3c4ed0
movl (%rdx,%rsi,4), %edx
movl %edx, (%rax,%rcx)
movq -0x70(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
subq $0x4, %rax
movq %rax, -0x68(%rbp)
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x9dbb
cmpq $0x0, -0x50(%rbp)
jle 0x9e63
movq -0x8(%rbp), %rdi
addq -0x70(%rbp), %rdi
movq -0x80(%rbp), %rax
movq -0x68(%rbp), %rcx
sarq $0x2, %rcx
movzbl (%rax,%rcx), %eax
leaq 0x3bb098(%rip), %rsi    # 0x3c4ed0
shlq $0x2, %rax
addq %rax, %rsi
movq -0x50(%rbp), %rdx
callq 0x2180
movq -0x50(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rcx
movq -0x68(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x9f22
movq -0x38(%rbp), %rax
subq -0x10(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x10(%rbp)
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
movq $0x1, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpq (%rcx), %rax
jg 0x9f20
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x78(%rbp), %rdx
subq (%rcx,%rdx,8), %rax
subq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x10(%rbp), %rax
jl 0x9f02
movq -0x58(%rbp), %rax
cmpq -0x40(%rbp), %rax
jg 0x9f02
movq -0x8(%rbp), %rax
movq -0x58(%rbp), %rcx
subq -0x10(%rbp), %rcx
movb $0x4e, (%rax,%rcx)
jmp 0x9f10
movq -0x58(%rbp), %rax
cmpq -0x10(%rbp), %rax
jge 0x9f0e
jmp 0x9f20
jmp 0x9f10
jmp 0x9f12
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x9ea1
jmp 0x9f22
jmp 0x9f24
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)