// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Process_Read.cpp
// Function: retrieve_u_seq(UC_Read*, char*, ma_utg_t*, unsigned char, long, long, void*)
void retrieve_u_seq(UC_Read* i_r, char* i_s, ma_utg_t *u, uint8_t strand, int64_t s, int64_t l, void *km)
{
	if(u->m == 0 || u->n == 0) return;
	if(l < 0) l = u->len;
	char *r = NULL, *a = NULL;
	int64_t e = s + l, ssp, sep, rs, re, des_i;
	uint64_t k, rId, ori, r_l;
	if(i_r) {
        i_r->length = l; i_r->RID = 0;
        if(i_r->length > i_r->size) {
            i_r->size = i_r->length;
			if(!km) REALLOC(i_r->seq, i_r->size);
			else KREALLOC(km, i_r->seq, i_r->size);
            // i_r->seq = (char*)realloc(i_r->seq,sizeof(char)*(i_r->size));
        }
        r = i_r->seq;
    }
    if(i_s) r = i_s;

	if(strand == 1) {
		sep = u->len - s; 
        ssp = u->len - e;
        s = ssp; e = sep; 
	}
	for (k = l = des_i = 0; k < u->n; k++) {
		rId = u->a[k]>>33;
		ori = u->a[k]>>32&1;
		r_l = (uint32_t)u->a[k];
		if(r_l == 0) continue;
		ssp = l; sep = l + r_l;
		l += r_l;
		if(sep <= s) continue;
		if(ssp >= e) break;
		rs = MAX(ssp, s); re = MIN(sep, e); 
		a = r + des_i; des_i += re - rs;
		recover_UC_Read_sub_region(a, rs-ssp, re-rs, ori, &R_INF, rId);
	}
	if(strand == 1) {
		char t;
		re = (e - s);
		l = re>>1; 
		for (k = 0; k < (uint64_t)l; k++) {
			des_i = re - k - 1;
			t = r[des_i];
			r[des_i] = RC_CHAR(r[k]);
			r[k] = RC_CHAR(t);
		}
		if(re&1) r[l] = RC_CHAR(r[l]);
	}
}

// Assembly:
cmpl $0x0, 0xc(%rdx)
je 0x36d16
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
cmpl $0x0, 0x10(%rdx)
je 0x36d08
movq %r9, %r14
movq %r8, %rbx
movl %ecx, %ebp
movq %rsi, %r12
movq %rdi, %r13
testq %r9, %r9
jns 0x36b4f
movl (%r15), %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
testq %r13, %r13
je 0x36b82
movq %r14, 0x8(%r13)
movq $0x0, 0x18(%r13)
cmpq 0x10(%r13), %r14
jle 0x36b96
movq 0x50(%rsp), %rdi
movq %r14, 0x10(%r13)
movq (%r13), %rsi
testq %rdi, %rdi
je 0x36b87
movq %r14, %rdx
callq 0x1e3800
jmp 0x36b92
xorl %r10d, %r10d
jmp 0x36b9a
movq %rsi, %rdi
movq %r14, %rsi
callq 0x2370
movq %rax, (%r13)
movq (%r13), %r10
addq %rbx, %r14
testq %r12, %r12
cmovneq %r12, %r10
cmpb $0x1, %bpl
movl %ebp, 0xc(%rsp)
jne 0x36bc5
movl (%r15), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, %rcx
subq %rbx, %rcx
subq %r14, %rax
movq %rcx, %r14
movq %rax, %rbx
cmpl $0x0, 0x10(%r15)
je 0x36c70
xorl %eax, %eax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
xorl %r8d, %r8d
movq %rbx, 0x10(%rsp)
movq 0x18(%r15), %rcx
movq (%rcx,%r12,8), %rcx
movq %rcx, %rbp
andq %rdx, %rbp
je 0x36c5a
addq %rax, %rbp
cmpq %rbx, %rbp
jle 0x36c5d
cmpq %r14, %rax
jge 0x36c70
movq %rax, %rsi
cmpq %rbx, %rax
jg 0x36c0a
movq %rbx, %rsi
movq %rbp, %rdx
cmpq %r14, %rbp
jl 0x36c15
movq %r14, %rdx
movq %rcx, %r9
shrq $0x21, %r9
shrq $0x20, %rcx
leaq (%r10,%r8), %rdi
subq %rsi, %rdx
addq %rdx, %r8
subq %rax, %rsi
andl $0x1, %ecx
movq %r8, %rbx
leaq 0x2545f6(%rip), %r8     # 0x28b230
movq %r14, %r13
movq %r10, %r14
callq 0x337f7
movq %rbx, %r8
movq %r14, %r10
movq %r13, %r14
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rbx
jmp 0x36c5d
movq %rax, %rbp
incq %r12
movl 0x10(%r15), %ecx
movq %rbp, %rax
cmpq %rcx, %r12
jb 0x36be2
cmpb $0x1, 0xc(%rsp)
jne 0x36d08
movq %r10, %r15
movq %r14, %rcx
subq %rbx, %rcx
movq %rcx, %rax
sarq %rax
cmpq $0x2, %rcx
jb 0x36ce5
xorl %edx, %edx
cmpq $0x1, %rax
movl $0x0, %esi
sbbq %rax, %rsi
notq %rbx
addq %r14, %rbx
movq %r15, %r9
addq %r15, %rbx
leaq 0x25397f(%rip), %rdi    # 0x28a630
leaq 0x253a7d(%rip), %r8     # 0x28a735
movzbl (%rbx,%rdx), %r10d
movzbl (%r9), %r11d
movzbl (%r11,%rdi), %r11d
movb (%r11,%r8), %r11b
movb %r11b, (%rbx,%rdx)
movzbl (%r10,%rdi), %r10d
movb (%r10,%r8), %r10b
movb %r10b, (%r9)
decq %rdx
incq %r9
cmpq %rdx, %rsi
jne 0x36cb8
testb $0x1, %cl
je 0x36d08
movzbl (%r15,%rax), %ecx
leaq 0x25393a(%rip), %rdx    # 0x28a630
movzbl (%rcx,%rdx), %ecx
leaq 0x253a34(%rip), %rdx    # 0x28a735
movb (%rcx,%rdx), %cl
movb %cl, (%r15,%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq