// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: push_scaf_bases(unsigned char*, unsigned long**, All_reads*, all_ul_t*, usc_t*, long, long, long, UC_Read*, unsigned long*, ma_ug_t*)
int64_t push_scaf_bases(uint8_t *des, uint64_t** N_site, All_reads* rdb, all_ul_t *x, usc_t *z, int64_t min_arc_len, int64_t scaf_len, int64_t nlen, UC_Read *tu, 
uint64_t *rmap, ma_ug_t *raw_g)
{   
    int64_t nlen0, ff, Nocc, i; char *da = NULL;
    ff = reset_scaf_node_uinfo_srt_t(z, min_arc_len, scaf_len, &nlen0); assert(nlen0 == nlen);
    if(ff == 1) {///has an overlap longer than min_arc_len between z->raw_sid and z->raw_eid
        memset(des, 0, sizeof((*(des)))*(nlen/4+1));
        return ff;
    }
    uint32_t uv, uw, sv, sw; int64_t s, e, ul;
    uv = z->raw_sid; uw = z->raw_eid;

    sv = (uv&1?((raw_g->u.a[uv>>1].a[0]>>32)^1):(raw_g->u.a[uv>>1].a[raw_g->u.a[uv>>1].n-1]>>32));
    sw = (uw&1?((raw_g->u.a[uw>>1].a[raw_g->u.a[uw>>1].n-1]>>32)^1):(raw_g->u.a[uw>>1].a[0]>>32));
    resize_UC_Read(tu, nlen); da = tu->seq;
    assert((Get_READ_LENGTH((*rdb), (sv>>1))) > ((uint32_t)min_arc_len));
    assert((Get_READ_LENGTH((*rdb), (sw>>1))) > ((uint32_t)min_arc_len));
    ///need introduce some UL bases; 
    ///or the overlap length between sv and sw is shorter than min_arc_len
    if(ff == 2) {
        s = z->raw_sof; e = z->raw_eof; ul = e - s;
        assert(ul>=(-min_arc_len));
        // assert((Get_READ_LENGTH((*rdb), (sv>>1))) > ul);
        // assert((Get_READ_LENGTH((*rdb), (sw>>1))) > ul);
        get_end_hifi(da, sv, rdb, min_arc_len, 1);
        get_end_hifi(da+min_arc_len+ul, sw, rdb, min_arc_len, 0);    
        if(ul > 0) {///need UL
            // fprintf(stderr, "[M::%s] ulid::%u(%c), s::%ld, e::%ld, nlen::%ld, min_arc_len::%ld\n", __func__, 
            // z->ulid>>1, "+-"[z->ulid&1], s, e, nlen, min_arc_len);
            get_ul_subregion(x, da+min_arc_len, z->ulid>>1, z->ulid&1, s, e, 1);
        }
    } else {///no UL found; ff = 0
        get_end_hifi(da, sv, rdb, min_arc_len, 1);
        memset(da+min_arc_len, 'A', scaf_len);
        get_end_hifi(da+min_arc_len+scaf_len, sw, rdb, min_arc_len, 0);        
    }
    for (i = Nocc = 0; i < nlen; i++) {
        if(seq_nt6_table[(uint8_t)da[i]] >= 4) Nocc++;
    }
    ha_compress_base(des, da, nlen, N_site, Nocc);
    return ff;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r13
movq %r8, %r15
movq %rdx, %r9
movq %rdi, 0x18(%rsp)
movq 0x88(%rsp), %r14
movq 0x80(%rsp), %rax
leaq (%rax,%r13,2), %rax
movl 0x4(%r8), %ebx
cmpl $-0x1, %ebx
je 0x22151d
movl 0x10(%r15), %edx
movl 0x14(%r15), %r10d
leaq (%r10,%r13), %rdi
cmpq %rdx, %rdi
jle 0x2216ab
addq %r13, %r10
addq %r13, %r10
subq %rdx, %r10
movl $0x2, %r8d
movq %r10, %rax
jmp 0x221520
xorl %r8d, %r8d
cmpq %r14, %rax
jne 0x22177b
movq 0xa0(%rsp), %rax
movl 0x8(%r15), %edi
movl 0xc(%r15), %r10d
movl %edi, %edx
shrl %edx
movq 0x10(%rax), %rax
leaq (%rdx,%rdx,4), %rdx
testb $0x1, %dil
jne 0x22155d
movq 0x18(%rax,%rdx,8), %rdi
movl 0x10(%rax,%rdx,8), %edx
decl %edx
movl 0x4(%rdi,%rdx,8), %r12d
jmp 0x22156a
movq 0x18(%rax,%rdx,8), %rdx
movl 0x4(%rdx), %r12d
xorq $0x1, %r12
movq 0x90(%rsp), %r11
movl %r10d, %edx
shrl %edx
testb $0x1, %r10b
movl %ebx, 0x8(%rsp)
jne 0x22158f
leaq (%rdx,%rdx,4), %rdx
movq 0x18(%rax,%rdx,8), %rax
movl 0x4(%rax), %ebp
jmp 0x2215a6
leaq (%rdx,%rdx,4), %rdi
movq 0x18(%rax,%rdi,8), %rdx
movl 0x10(%rax,%rdi,8), %eax
decl %eax
movl 0x4(%rdx,%rax,8), %ebp
xorq $0x1, %rbp
movq (%r11), %rbx
cmpq %r14, 0x10(%r11)
movq %rsi, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
jge 0x2215e1
movq %rbx, %rdi
movq %r14, %rsi
movq %r9, %rbx
callq 0x2370
movq %rbx, %r9
movq %rax, %rbx
movq 0x90(%rsp), %rax
movq %rbx, (%rax)
movq %r14, 0x10(%rax)
movq 0x18(%r9), %rax
movl %r12d, %edx
shrl %edx
movl %r13d, %ecx
cmpq %rcx, (%rax,%rdx,8)
jbe 0x22179a
movl %ebp, %edx
shrl %edx
cmpq %rcx, (%rax,%rdx,8)
jbe 0x2217b9
cmpl $-0x1, 0x8(%rsp)
movq %rbp, 0x10(%rsp)
je 0x2216dc
movl 0x10(%r15), %eax
movl 0x14(%r15), %ebp
movq %rbp, 0x20(%rsp)
movq %rax, 0x28(%rsp)
subq %rax, %rbp
movq %r13, %rax
negq %rax
cmpq %rax, %rbp
jl 0x2217d8
movq %rbx, %rdi
movl %r12d, %esi
movq %r9, %rdx
movl %r13d, %ecx
movl $0x1, %r8d
movq %r9, 0x8(%rsp)
callq 0x22126e
movq %r13, %r12
addq %rbx, %r12
leaq (%r12,%rbp), %rdi
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x22126e
testq %rbp, %rbp
jle 0x22172d
movl 0x4(%r15), %ecx
movl %ecx, %edx
shrl %edx
andl $0x1, %ecx
movl $0x1, (%rsp)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
callq 0x2212bb
jmp 0x22172d
cmpq %r14, %rax
jne 0x22177b
leaq 0x3(%r14), %rdx
testq %r14, %r14
cmovnsq %r14, %rdx
sarq $0x2, %rdx
incq %rdx
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x20e0
movl $0x1, %eax
jmp 0x22176c
movq %rbx, %rdi
movl %r12d, %esi
movq %r9, %rdx
movl %r13d, %ecx
movl $0x1, %r8d
movq %r9, %r12
callq 0x22126e
movq %r13, %r15
addq %rbx, %r15
movq %r15, %rdi
movl $0x41, %esi
movq 0x80(%rsp), %rbp
movq %rbp, %rdx
callq 0x20e0
addq %rbp, %r15
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq %r12, %rdx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x22126e
xorl %r8d, %r8d
testq %r14, %r14
jle 0x221752
leaq 0x73ef4(%rip), %rax     # 0x295630
xorl %ecx, %ecx
movzbl (%rbx,%rcx), %edx
cmpb $0x4, (%rax,%rdx)
sbbq $-0x1, %r8
incq %rcx
cmpq %rcx, %r14
jne 0x22173e
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq 0x40(%rsp), %rcx
callq 0x335d2
movq 0x38(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2814b(%rip), %rdi     # 0x2498cd
leaq 0x23e80(%rip), %rsi     # 0x245609
leaq 0x2814b(%rip), %rcx     # 0x2498db
movl $0x3920, %edx           # imm = 0x3920
callq 0x2110
leaq 0x281c9(%rip), %rdi     # 0x24996a
leaq 0x23e61(%rip), %rsi     # 0x245609
leaq 0x2812c(%rip), %rcx     # 0x2498db
movl $0x392b, %edx           # imm = 0x392B
callq 0x2110
leaq 0x281e7(%rip), %rdi     # 0x2499a7
leaq 0x23e42(%rip), %rsi     # 0x245609
leaq 0x2810d(%rip), %rcx     # 0x2498db
movl $0x392c, %edx           # imm = 0x392C
callq 0x2110
leaq 0x28205(%rip), %rdi     # 0x2499e4
leaq 0x23e23(%rip), %rsi     # 0x245609
leaq 0x280ee(%rip), %rcx     # 0x2498db
movl $0x3931, %edx           # imm = 0x3931
callq 0x2110