// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: recover_fake_read(UC_Read*, UC_Read*, ma_utg_t*, All_reads*, ma_sub_t const*)
void recover_fake_read(UC_Read* result, UC_Read* tmp, ma_utg_t *u,
All_reads *RNF, const ma_sub_t *coverage_cut)
{
    uint32_t j, k, ori, start, l = 0, eLen, rId, readLen;
    if(result->size < u->len)
    {
        result->size = u->len;
        result->seq = (char*)realloc(result->seq,sizeof(char)*(result->size));
    }
    char* readS = NULL;

    for (j = 0; j < u->n; ++j) {
        rId = u->a[j]>>33;
        ///uId = i;
        ori = u->a[j]>>32&1;
        start = l;
        eLen = (uint32_t)u->a[j];
        l += eLen;

        if(eLen == 0) continue;

        recover_UC_Read(tmp, RNF, rId);
        readS = tmp->seq + coverage_cut[rId].s;
        readLen = coverage_cut[rId].e - coverage_cut[rId].s;
        
        
        if (!ori) // forward strand
        {
            for (k = 0; k < eLen; k++)
            {
                result->seq[start + k] = readS[k];
            }
        }
        else
        {
            for (k = 0; k < eLen; k++)
            {
                uint8_t c = (uint8_t)readS[readLen - 1 - k];
                result->seq[start + k] = c >= 128? 'N' : comp_tab[c];
            }
        }
	}
    
    result->length = u->end - u->start;
    for (j = u->start; j < u->end; j++)
    {
        result->seq[j - u->start] = result->seq[j];
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r15
movq %rcx, 0x18(%rsp)
movq %rdx, %rbp
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
movl (%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
cmpq %rsi, 0x10(%rdi)
jge 0xb3320
movq %rsi, 0x10(%r14)
movq (%r14), %rdi
callq 0x2370
movq %rax, (%r14)
cmpl $0x0, 0x10(%rbp)
je 0xb3406
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %rbp, 0x8(%rsp)
movq 0x18(%rbp), %rax
movq (%rax,%r12,8), %rbx
testl %ebx, %ebx
je 0xb33f4
movq %rbx, %rbp
shrq $0x21, %rbp
movq %rbx, 0x20(%rsp)
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq %rbp, %rdx
callq 0x333e0
leaq (,%rbp,2), %rdx
addq %rbp, %rdx
movl (%r15,%rdx,4), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq (%rbx), %rax
movq 0x20(%rsp), %rbx
addq %rcx, %rax
btq $0x20, %rbx
jb 0xb33b2
movl %ebx, %ecx
movl %r13d, %edx
xorl %esi, %esi
movq 0x8(%rsp), %rbp
movb (%rax,%rsi), %dil
movq (%r14), %r10
leal (%rdx,%rsi), %r9d
movb %dil, (%r10,%r9)
incq %rsi
cmpq %rsi, %rcx
jne 0xb3399
jmp 0xb33f4
leaq (%r15,%rdx,4), %rdx
notl %ecx
addl 0x4(%rdx), %ecx
movl %ebx, %edx
movl %r13d, %esi
movq 0x8(%rsp), %rbp
leaq 0x182a34(%rip), %r11    # 0x235e00
movl %ecx, %edi
movsbq (%rax,%rdi), %rdi
testq %rdi, %rdi
js 0xb33de
movb (%rdi,%r11), %dil
jmp 0xb33e1
movb $0x4e, %dil
movq (%r14), %r10
movl %esi, %r9d
movb %dil, (%r10,%r9)
incl %esi
decl %ecx
decq %rdx
jne 0xb33cc
addl %ebx, %r13d
incq %r12
movl 0x10(%rbp), %eax
cmpq %rax, %r12
jb 0xb3335
movl 0x4(%rbp), %eax
movl 0x8(%rbp), %ecx
subl %eax, %ecx
movq %rcx, 0x8(%r14)
jbe 0xb342f
movq (%r14), %rcx
movb (%rcx,%rax), %dl
movl 0x4(%rbp), %esi
movl %eax, %edi
subl %esi, %edi
movb %dl, (%rcx,%rdi)
incq %rax
movl 0x8(%rbp), %ecx
cmpq %rcx, %rax
jb 0xb3414
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq