// File: /workspace/github_cpp_makefile_star2_O3/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 0x36264
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r12
cmpl $0x0, 0x10(%rdx)
je 0x36256
movq %r9, %r14
movq %r8, %rbx
movl %ecx, %r15d
movq %rsi, %r13
movq %rdi, %rbp
testq %r9, %r9
jns 0x3608d
movl (%r12), %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
testq %rbp, %rbp
je 0x360c0
movq %r14, 0x8(%rbp)
movq $0x0, 0x18(%rbp)
cmpq 0x10(%rbp), %r14
jle 0x360c4
movq 0x50(%rsp), %rdi
movq %r14, 0x10(%rbp)
movq (%rbp), %rsi
testq %rdi, %rdi
je 0x360ca
movq %r14, %rdx
callq 0x1ee21d
jmp 0x360d5
xorl %eax, %eax
jmp 0x360d9
movq (%rbp), %rax
jmp 0x360d9
movq %rsi, %rdi
movq %r14, %rsi
callq 0x2370
movq %rax, (%rbp)
addq %rbx, %r14
testq %r13, %r13
cmovneq %r13, %rax
cmpb $0x1, %r15b
movl %r15d, 0xc(%rsp)
jne 0x36107
movl (%r12), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %rdx, %rcx
subq %rbx, %rcx
subq %r14, %rdx
movq %rcx, %r14
movq %rdx, %rbx
movl 0x10(%r12), %edx
testl %edx, %edx
je 0x361be
xorl %r8d, %r8d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r13d, %r13d
xorl %r10d, %r10d
movq %rbx, 0x10(%rsp)
movq 0x18(%r12), %rcx
movq (%rcx,%r13,8), %rcx
movq %rcx, %rbp
andq %rsi, %rbp
je 0x361aa
addq %r8, %rbp
cmpq %rbx, %rbp
jle 0x361ad
cmpq %r14, %r8
jge 0x361be
movq %r8, %rsi
cmpq %rbx, %r8
jg 0x36150
movq %rbx, %rsi
movq %r12, %r15
movq %rbp, %rdx
cmpq %r14, %rbp
jl 0x3615e
movq %r14, %rdx
movq %rcx, %r9
shrq $0x21, %r9
shrq $0x20, %rcx
leaq (%rax,%r10), %rdi
subq %rsi, %rdx
addq %rdx, %r10
subq %r8, %rsi
andl $0x1, %ecx
leaq 0x2600b0(%rip), %r8     # 0x296230
movq %r14, %r12
movq %rax, %r14
movq %r10, %rbx
callq 0x32ef8
movq %rbx, %r10
movq %r14, %rax
movq %r12, %r14
movq %r15, %r12
movl 0x10(%r15), %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rbx
jmp 0x361ad
movq %r8, %rbp
incq %r13
movl %edx, %ecx
movq %rbp, %r8
cmpq %rcx, %r13
jb 0x36127
cmpb $0x1, 0xc(%rsp)
jne 0x36256
movq %rax, %r15
movq %r14, %rcx
subq %rbx, %rcx
movq %rcx, %rax
sarq %rax
cmpq $0x2, %rcx
jb 0x36233
xorl %edx, %edx
cmpq $0x1, %rax
movl $0x0, %esi
sbbq %rax, %rsi
notq %rbx
addq %r14, %rbx
movq %r15, %r9
addq %r15, %rbx
leaq 0x25f431(%rip), %rdi    # 0x295630
leaq 0x25f52f(%rip), %r8     # 0x295735
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 0x36206
testb $0x1, %cl
je 0x36256
movzbl (%r15,%rax), %ecx
leaq 0x25f3ec(%rip), %rdx    # 0x295630
movzbl (%rcx,%rdx), %ecx
leaq 0x25f4e6(%rip), %rdx    # 0x295735
movb (%rcx,%rdx), %cl
movb %cl, (%r15,%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq