// File: /workspace/github_cpp_makefile_star2_O2/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, %rbp
movq %rcx, 0x20(%rsp)
movq %rdx, %rbx
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
movl (%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
cmpq %rsi, 0x10(%rdi)
jge 0x78707
movq %rsi, 0x10(%r14)
movq (%r14), %rdi
callq 0x2370
movq %rax, (%r14)
xorl %r12d, %r12d
xorl %r11d, %r11d
movq %rbx, 0x10(%rsp)
movq 0x18(%rsp), %r15
movl 0x10(%rbx), %eax
cmpq %rax, %r12
jae 0x787f0
movq 0x18(%rbx), %rax
movq (%rax,%r12,8), %r13
testl %r13d, %r13d
je 0x787e5
movl %r11d, 0xc(%rsp)
movq %rbp, %rbx
movq %r13, %rbp
shrq $0x21, %rbp
movq %r15, %rdi
movq 0x20(%rsp), %rsi
movq %rbp, %rdx
callq 0x715e
imulq $0xc, %rbp, %rdx
movq %rbx, %rbp
movl (%rbx,%rdx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq (%r15), %rax
addq %rcx, %rax
btq $0x20, %r13
jb 0x7879b
movl %r13d, %ecx
movl 0xc(%rsp), %r11d
movl %r11d, %edx
xorl %esi, %esi
movq 0x10(%rsp), %rbx
cmpq %rsi, %rcx
je 0x787e5
movb (%rax,%rsi), %dil
movq (%r14), %r8
leal (%rdx,%rsi), %r9d
movb %dil, (%r8,%r9)
incq %rsi
jmp 0x78782
addq %rbp, %rdx
notl %ecx
addl 0x4(%rdx), %ecx
movl %r13d, %edx
movl 0xc(%rsp), %r11d
movl %r11d, %esi
movq 0x10(%rsp), %rbx
leaq 0x16f546(%rip), %r10    # 0x1e7d00
subq $0x1, %rdx
jb 0x787e5
movl %ecx, %edi
movsbq (%rax,%rdi), %rdi
testq %rdi, %rdi
js 0x787d2
movb (%rdi,%r10), %dil
jmp 0x787d5
movb $0x4e, %dil
movq (%r14), %r8
movl %esi, %r9d
movb %dil, (%r8,%r9)
incl %esi
decl %ecx
jmp 0x787ba
addl %r13d, %r11d
incq %r12
jmp 0x78717
movl 0x4(%rbx), %eax
movl 0x8(%rbx), %ecx
movl %ecx, %edx
subl %eax, %edx
movq %rdx, 0x8(%r14)
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x7881d
movq (%r14), %rcx
movb (%rcx,%rax), %dl
movl 0x4(%rbx), %esi
movl %eax, %edi
subl %esi, %edi
movb %dl, (%rcx,%rdi)
incq %rax
movl 0x8(%rbx), %ecx
jmp 0x787fe
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq