// File: /workspace/github_cpp_makefile_star2_O1/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 %rdi, 0x10(%rsp)
movq 0x88(%rsp), %r14
movq 0x80(%rsp), %rbp
leaq (,%r9,2), %rax
addq %rbp, %rax
cmpl $-0x1, 0x4(%r8)
je 0x21612a
movl 0x10(%r15), %r9d
movl 0x14(%r15), %r8d
leaq (%r8,%r13), %rdi
cmpq %r9, %rdi
jle 0x216133
addq %r13, %r8
addq %r13, %r8
subq %r9, %r8
movl $0x2, %ebx
movb $0x1, %r10b
xorl %edi, %edi
movq %r8, %rax
jmp 0x21613e
xorl %edi, %edi
xorl %r10d, %r10d
xorl %ebx, %ebx
jmp 0x21613e
movl $0x1, %ebx
movb $0x1, %dil
xorl %r10d, %r10d
cmpq %r14, %rax
jne 0x21638d
testb %dil, %dil
je 0x21616f
leaq 0x3(%r14), %rdx
testq %r14, %r14
cmovnsq %r14, %rdx
sarq $0x2, %rdx
incq %rdx
movq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x20e0
jmp 0x21637b
movq %rcx, 0x30(%rsp)
movq 0xa0(%rsp), %rax
movl 0x8(%r15), %edi
movl 0xc(%r15), %ecx
movl %edi, %r8d
shrl %r8d
movq 0x10(%rax), %r9
testb $0x1, %dil
movq %rsi, 0x40(%rsp)
movq %rbx, 0x38(%rsp)
leaq (%r8,%r8,4), %rsi
jne 0x2161b5
movq 0x18(%r9,%rsi,8), %rdi
movl 0x10(%r9,%rsi,8), %esi
decl %esi
movl 0x4(%rdi,%rsi,8), %r12d
jmp 0x2161c2
movq 0x18(%r9,%rsi,8), %rsi
movl 0x4(%rsi), %r12d
xorq $0x1, %r12
movq 0x90(%rsp), %r9
movl %ecx, %esi
shrl %esi
movq 0x10(%rax), %rax
testb $0x1, %cl
jne 0x2161e5
leaq (%rsi,%rsi,4), %rcx
movq 0x18(%rax,%rcx,8), %rax
movl 0x4(%rax), %edi
jmp 0x2161fc
leaq (%rsi,%rsi,4), %rcx
movq 0x18(%rax,%rcx,8), %rsi
movl 0x10(%rax,%rcx,8), %eax
decl %eax
movl 0x4(%rsi,%rax,8), %edi
xorq $0x1, %rdi
cmpq %r14, 0x10(%r9)
movq %rdi, 0x8(%rsp)
jge 0x21623a
movq (%r9), %rdi
movq %r14, %rsi
movq %rdx, %rbp
movq %r10, %rbx
callq 0x2370
movq 0x90(%rsp), %r9
movq 0x8(%rsp), %rdi
movq %rbx, %r10
movq %rbp, %rdx
movq 0x80(%rsp), %rbp
movq %rax, (%r9)
movq %r14, 0x10(%r9)
movq 0x18(%rdx), %rax
movl %r12d, %esi
shrl %esi
movl %r13d, %ecx
cmpq %rcx, (%rax,%rsi,8)
jbe 0x2163ac
movl %edi, %esi
shrl %esi
cmpq %rcx, (%rax,%rsi,8)
jbe 0x2163cb
movq (%r9), %rbx
testb %r10b, %r10b
je 0x2162f6
movl 0x10(%r15), %eax
movl 0x14(%r15), %ebp
movq %rbp, 0x18(%rsp)
movq %rax, 0x20(%rsp)
subq %rax, %rbp
movq %r13, %rax
negq %rax
cmpq %rax, %rbp
jl 0x2163ea
movq %rbx, %rdi
movl %r12d, %esi
movl %r13d, %ecx
movl $0x1, %r8d
movq %rdx, 0x28(%rsp)
callq 0x215e7e
movq %r13, %r12
addq %rbx, %r12
leaq (%r12,%rbp), %rdi
movq 0x8(%rsp), %rsi
movq 0x28(%rsp), %rdx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x215e7e
testq %rbp, %rbp
jle 0x21633c
movl 0x4(%r15), %ecx
movl %ecx, %edx
shrl %edx
andl $0x1, %ecx
movl $0x1, (%rsp)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r9
callq 0x215ecb
jmp 0x21633c
movq %rbx, %rdi
movl %r12d, %esi
movl %r13d, %ecx
movl $0x1, %r8d
movq %rdx, %r12
callq 0x215e7e
movq %r13, %r15
addq %rbx, %r15
movq %r15, %rdi
movl $0x41, %esi
movq %rbp, %rdx
callq 0x20e0
addq %rbp, %r15
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x215e7e
xorl %r8d, %r8d
testq %r14, %r14
jle 0x216361
leaq 0x742e5(%rip), %rax     # 0x28a630
xorl %ecx, %ecx
movzbl (%rbx,%rcx), %edx
cmpb $0x4, (%rax,%rdx)
sbbq $-0x1, %r8
incq %rcx
cmpq %rcx, %r14
jne 0x21634d
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq 0x40(%rsp), %rcx
callq 0x33ef7
movq 0x38(%rsp), %rbx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x27255(%rip), %rdi     # 0x23d5e9
leaq 0x22f8a(%rip), %rsi     # 0x239325
leaq 0x27255(%rip), %rcx     # 0x23d5f7
movl $0x3920, %edx           # imm = 0x3920
callq 0x2110
leaq 0x272d3(%rip), %rdi     # 0x23d686
leaq 0x22f6b(%rip), %rsi     # 0x239325
leaq 0x27236(%rip), %rcx     # 0x23d5f7
movl $0x392b, %edx           # imm = 0x392B
callq 0x2110
leaq 0x272f1(%rip), %rdi     # 0x23d6c3
leaq 0x22f4c(%rip), %rsi     # 0x239325
leaq 0x27217(%rip), %rcx     # 0x23d5f7
movl $0x392c, %edx           # imm = 0x392C
callq 0x2110
leaq 0x2730f(%rip), %rdi     # 0x23d700
leaq 0x22f2d(%rip), %rsi     # 0x239325
leaq 0x271f8(%rip), %rcx     # 0x23d5f7
movl $0x3931, %edx           # imm = 0x3931
callq 0x2110