// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq 0x10(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x365460
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
cmpq 0x18(%rbp), %rax
jne 0x3659d4
jmp 0x3659f3
leaq 0x34be2(%rip), %rdi     # 0x39a5bd
leaq 0x307d7(%rip), %rsi     # 0x3961b9
movl $0x3920, %edx           # imm = 0x3920
leaq 0x34bdd(%rip), %rcx     # 0x39a5cb
callq 0x2130
cmpq $0x1, -0x48(%rbp)
jne 0x365a2b
movq -0x10(%rbp), %rdi
movq 0x18(%rbp), %rax
movl $0x4, %ecx
cqto
idivq %rcx
movq %rax, %rdx
addq $0x1, %rdx
shlq $0x0, %rdx
xorl %esi, %esi
callq 0x2100
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x365d93
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x365a78
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x365abf
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq 0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x64(%rbp), %edx
shrl %edx
movl %edx, %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movl %eax, -0x6c(%rbp)
movl -0x68(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x365b21
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x68(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq 0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x68(%rbp), %edx
shrl %edx
movl %edx, %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x365b49
movq 0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x68(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
shrq $0x20, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movl %eax, -0x70(%rbp)
movq 0x20(%rbp), %rdi
movq 0x18(%rbp), %rsi
callq 0xa62c0
movq 0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x6c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq -0x38(%rbp), %rcx
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x365b8b
jmp 0x365baa
leaq 0x34ac8(%rip), %rdi     # 0x39a65a
leaq 0x30620(%rip), %rsi     # 0x3961b9
movl $0x392b, %edx           # imm = 0x392B
leaq 0x34a26(%rip), %rcx     # 0x39a5cb
callq 0x2130
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x70(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq -0x38(%rbp), %rcx
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x365bca
jmp 0x365be9
leaq 0x34ac6(%rip), %rdi     # 0x39a697
leaq 0x305e1(%rip), %rsi     # 0x3961b9
movl $0x392c, %edx           # imm = 0x392C
leaq 0x349e7(%rip), %rcx     # 0x39a5cb
callq 0x2130
cmpq $0x2, -0x48(%rbp)
jne 0x365ccb
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
subq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
xorl %ecx, %ecx
subq -0x38(%rbp), %rcx
cmpq %rcx, %rax
jl 0x365c2d
jmp 0x365c4c
leaq 0x34aa0(%rip), %rdi     # 0x39a6d4
leaq 0x3057e(%rip), %rsi     # 0x3961b9
movl $0x3931, %edx           # imm = 0x3931
leaq 0x34984(%rip), %rcx     # 0x39a5cb
callq 0x2130
movq -0x60(%rbp), %rdi
movl -0x6c(%rbp), %esi
movq -0x20(%rbp), %rdx
movq -0x38(%rbp), %rax
movl %eax, %ecx
movl $0x1, %r8d
callq 0x365500
movq -0x60(%rbp), %rdi
addq -0x38(%rbp), %rdi
addq -0x88(%rbp), %rdi
movl -0x70(%rbp), %esi
movq -0x20(%rbp), %rdx
movq -0x38(%rbp), %rax
movl %eax, %ecx
xorl %r8d, %r8d
callq 0x365500
cmpq $0x0, -0x88(%rbp)
jle 0x365cc9
movq -0x28(%rbp), %rdi
movq -0x60(%rbp), %rsi
addq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rax
movl 0x4(%rax), %edx
shrl %edx
movq -0x30(%rbp), %rax
movl 0x4(%rax), %ecx
andl $0x1, %ecx
movq -0x78(%rbp), %r8
movq -0x80(%rbp), %r9
movl $0x1, (%rsp)
callq 0x3655b0
jmp 0x365d1e
movq -0x60(%rbp), %rdi
movl -0x6c(%rbp), %esi
movq -0x20(%rbp), %rdx
movq -0x38(%rbp), %rax
movl %eax, %ecx
movl $0x1, %r8d
callq 0x365500
movq -0x60(%rbp), %rdi
addq -0x38(%rbp), %rdi
movq 0x10(%rbp), %rdx
movl $0x41, %esi
callq 0x2100
movq -0x60(%rbp), %rdi
addq -0x38(%rbp), %rdi
addq 0x10(%rbp), %rdi
movl -0x70(%rbp), %esi
movq -0x20(%rbp), %rdx
movq -0x38(%rbp), %rax
movl %eax, %ecx
xorl %r8d, %r8d
callq 0x365500
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq 0x18(%rbp), %rax
jge 0x365d72
movq -0x60(%rbp), %rax
movq -0x58(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x5e903(%rip), %rax     # 0x3c4650
movzbl (%rax,%rcx), %eax
cmpl $0x4, %eax
jl 0x365d62
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x365d64
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x365d2e
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq 0x18(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x50(%rbp), %r8
callq 0xa710
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq