// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r13
movq %rdi, %r12
movq 0x10(%r8), %rax
addq %rsi, %rdx
movq %rdx, 0x18(%rsp)
movq (%rax,%r9,8), %r14
testl %ecx, %ecx
movq %r9, 0x30(%rsp)
movq %r8, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
je 0x32f99
movq 0x18(%r8), %rax
movq (%rax,%r9,8), %rax
movq %rax, 0x8(%rsp)
subq %rsi, %rax
leaq -0x1(%rax), %rbx
andl $0x3, %eax
cmpq %r13, %rax
movq %r13, %rbp
cmovlq %rax, %rbp
subq %rbp, %r13
movl %r13d, %ecx
andl $0x3, %ecx
movq %rcx, 0x10(%rsp)
sarq $0x2, %r13
leaq 0x262ec7(%rip), %r15    # 0x295e30
testq %rbp, %rbp
jle 0x32ffe
movq %rbx, %rcx
sarq $0x2, %rcx
movzbl (%r14,%rcx), %ecx
leaq (%r15,%rcx,4), %rsi
subq %rax, %rsi
addq $0x4, %rsi
movq %r12, %rdi
movq %rbp, %rdx
callq 0x2160
subq %rbp, %rbx
jmp 0x33000
movl %esi, %eax
andl $0x3, %eax
movl $0x4, %ebp
subq %rax, %rbp
cmpq %r13, %rbp
cmovgeq %r13, %rbp
movq %r13, %r15
subq %rbp, %r15
movl %r15d, %ecx
andl $0x3, %ecx
movq %rcx, 0x8(%rsp)
sarq $0x2, %r15
leaq 0x262a67(%rip), %rbx    # 0x295a30
testq %r13, %r13
jle 0x330cd
movq %rsi, %rcx
sarq $0x2, %rcx
movzbl (%r14,%rcx), %ecx
movq %rsi, %r13
leaq (%rbx,%rcx,4), %rsi
addq %rax, %rsi
movq %r12, %rdi
movq %rbp, %rdx
callq 0x2160
movq %rbp, %rax
addq %r13, %rax
jmp 0x330d2
xorl %ebp, %ebp
testq %r13, %r13
jle 0x3302d
movq 0x10(%rsp), %rdx
movq %rbx, %rax
sarq $0x2, %rax
movzbl (%r14,%rax), %eax
movl (%r15,%rax,4), %eax
movl %eax, (%r12,%rbp)
addq $0x4, %rbp
addq $-0x4, %rbx
decq %r13
jne 0x3300a
jmp 0x33032
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
je 0x3304f
addq %r12, %rbp
sarq $0x2, %rbx
movzbl (%r14,%rbx), %eax
leaq (%r15,%rax,4), %rsi
movq %rbp, %rdi
callq 0x2160
movq 0x28(%rsp), %r10
movq (%r10), %rax
movq 0x30(%rsp), %r9
movq (%rax,%r9,8), %rdx
testq %rdx, %rdx
movq 0x20(%rsp), %r11
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %r14
je 0x33182
cmpq $0x0, (%rdx)
jle 0x33182
xorl %ecx, %ecx
movq 0x8(%rdx,%rcx,8), %rdx
notq %rdx
addq %r14, %rdx
movq %rdx, %rsi
subq %r11, %rsi
setge %dil
cmpq %rbx, %rdx
setl %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
jne 0x330b3
movb $0x4e, (%r12,%rsi)
movq (%r10), %rax
jmp 0x330bc
cmpq %r11, %rdx
jl 0x33182
movq (%rax,%r9,8), %rdx
incq %rcx
cmpq (%rdx), %rcx
jl 0x33084
jmp 0x33182
xorl %ebp, %ebp
movq %rsi, %rax
testq %r15, %r15
jle 0x330fe
movq 0x8(%rsp), %rdx
movq %rax, %rcx
sarq $0x2, %rcx
movzbl (%r14,%rcx), %ecx
movl (%rbx,%rcx,4), %ecx
movl %ecx, (%r12,%rbp)
addq $0x4, %rbp
addq $0x4, %rax
decq %r15
jne 0x330dc
jmp 0x33103
movq 0x8(%rsp), %rdx
testq %rdx, %rdx
je 0x33120
addq %r12, %rbp
sarq $0x2, %rax
movzbl (%r14,%rax), %eax
leaq (%rbx,%rax,4), %rsi
movq %rbp, %rdi
callq 0x2160
movq 0x28(%rsp), %r10
movq (%r10), %rax
movq 0x30(%rsp), %r9
movq (%rax,%r9,8), %rdx
testq %rdx, %rdx
movq 0x20(%rsp), %r13
movq 0x18(%rsp), %r11
je 0x33182
cmpq $0x0, (%rdx)
jle 0x33182
xorl %ecx, %ecx
movq 0x8(%rdx,%rcx,8), %rdx
movq %rdx, %rsi
subq %r13, %rsi
setge %dil
cmpq %r11, %rdx
setl %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
jne 0x33171
movb $0x4e, (%r12,%rsi)
movq (%r10), %rax
jmp 0x33176
cmpq %r11, %rdx
jge 0x33182
movq (%rax,%r9,8), %rdx
incq %rcx
cmpq (%rdx), %rcx
jl 0x33148
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq