// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: gen_scaffold_bases(kvect_sec_t*, kvect_sec_t*, ma_ug_t*, asg_t*, ma_sub_t*, ma_hit_t_alloc*, kvec_asg_arc_t_warp*, int, int, kv_u_trans_t*)
void gen_scaffold_bases(kvect_sec_t *sc0, kvect_sec_t *sc1, ma_ug_t *mg, asg_t *sg, ma_sub_t* cover, ma_hit_t_alloc* src, kvec_asg_arc_t_warp *arcs, int max_hang, int min_ovlp, kv_u_trans_t *p)
{
    if(!p) {
        ma_ug_seq(mg, sg, cover, src, arcs, max_hang, min_ovlp, 0, 1);
    } else {
        uint64_t k, kn, *l0 = NULL, *l1 = NULL, s, e; 
        kn = sc0->n + sc1->n; 
        CALLOC(l0, kn); CALLOC(l1, kn);
        for (k = 0; k < kn; k++) l0[k] = get_scp_len(((k<sc0->n)?&(sc0->a[k]):&(sc1->a[k-sc0->n])), mg);
        ma_ug_seq(mg, sg, cover, src, arcs, max_hang, min_ovlp, 0, 1);
        for (k = 0; k < kn; k++) l1[k] = get_scp_len(((k<sc0->n)?&(sc0->a[k]):&(sc1->a[k-sc0->n])), mg);

        for (k = 0; k < p->n; k++) {
            if(l0[p->a[k].qn] != l1[p->a[k].qn]) {
                s = p->a[k].qs; e = p->a[k].qe;
                p->a[k].qs = cal_offset_len(s, l0[p->a[k].qn], l1[p->a[k].qn]);
                p->a[k].qe = p->a[k].qs + cal_offset_len(((e>s)?(e-s):(0)), l0[p->a[k].qn], l1[p->a[k].qn]);
                if(p->a[k].qs > l1[p->a[k].qn]) p->a[k].qs = l1[p->a[k].qn];
                if(p->a[k].qe > l1[p->a[k].qn]) p->a[k].qe = l1[p->a[k].qn];
            }

            if(l0[p->a[k].tn] != l1[p->a[k].tn]) {
                s = p->a[k].ts; e = p->a[k].te;
                p->a[k].ts = cal_offset_len(s, l0[p->a[k].tn], l1[p->a[k].tn]);
                p->a[k].te = p->a[k].ts + cal_offset_len(((e>s)?(e-s):(0)), l0[p->a[k].tn], l1[p->a[k].tn]);
                if(p->a[k].ts > l1[p->a[k].tn]) p->a[k].ts = l1[p->a[k].tn];
                if(p->a[k].te > l1[p->a[k].tn]) p->a[k].te = l1[p->a[k].tn];
            }
        }

        free(l0); free(l1);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r15
movq 0x98(%rsp), %rax
movl 0x90(%rsp), %r10d
movl 0x88(%rsp), %r11d
movq 0x80(%rsp), %rbx
testq %rax, %rax
je 0xa32dc
movq %rdi, %r13
movq %rbx, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
movl %r11d, 0x4(%rsp)
movq %r8, 0x28(%rsp)
movq %r9, 0x30(%rsp)
movq %r10, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq %rsi, 0x8(%rsp)
movq 0x8(%rsi), %rbp
addq 0x8(%rdi), %rbp
pushq $0x8
popq %r14
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2120
movq %rax, 0x10(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2120
movq %rax, %r14
xorl %r12d, %r12d
xorl %ebx, %ebx
cmpq %rbx, %rbp
je 0xa3046
movq 0x8(%r13), %rax
cmpq %rax, %rbx
jae 0xa301a
movq %rbx, %rdi
shlq $0x5, %rdi
addq (%r13), %rdi
jmp 0xa302c
movq 0x8(%rsp), %rcx
movq (%rcx), %rdi
shlq $0x5, %rax
subq %rax, %rdi
addq %r12, %rdi
movq %r15, %rsi
callq 0xc38e6
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
addq $0x20, %r12
jmp 0xa2fff
subq $0x8, %rsp
movq %r15, %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq 0x20(%rsp), %r8
movl 0xc(%rsp), %r9d
pushq $0x1
pushq $0x0
pushq 0x50(%rsp)
callq 0x7b888
addq $0x20, %rsp
xorl %r12d, %r12d
xorl %ebx, %ebx
cmpq %rbx, %rbp
je 0xa30be
movq 0x8(%r13), %rax
cmpq %rax, %rbx
jae 0xa3097
movq %rbx, %rdi
shlq $0x5, %rdi
addq (%r13), %rdi
jmp 0xa30a9
movq 0x8(%rsp), %rcx
movq (%rcx), %rdi
shlq $0x5, %rax
subq %rax, %rdi
addq %r12, %rdi
movq %r15, %rsi
callq 0xc38e6
movq %rax, (%r14,%rbx,8)
incq %rbx
addq $0x20, %r12
jmp 0xa307c
movq 0x40(%rsp), %rbx
movq (%rbx), %rax
xorl %ecx, %ecx
movq 0x1401a0(%rip), %xmm0   # 0x1e3270
movapd 0x1401a8(%rip), %xmm1   # 0x1e3280
movsd 0x1401b8(%rip), %xmm2   # 0x1e3298
movq 0x10(%rsp), %rdi
subq $0x1, %rax
jb 0xa32c1
movq 0x10(%rbx), %rdx
movl 0x8(%rdx,%rcx), %esi
movq (%rdi,%rsi,8), %r9
movq (%r14,%rsi,8), %rsi
cmpq %rsi, %r9
je 0xa31d4
movl (%rdx,%rcx), %r15d
movl 0x4(%rdx,%rcx), %r8d
cvtsi2sd %r15, %xmm4
movq %r9, %xmm3
punpckldq %xmm0, %xmm3    # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
subpd %xmm1, %xmm3
movapd %xmm3, %xmm5
unpckhpd %xmm3, %xmm5            # xmm5 = xmm5[1],xmm3[1]
addsd %xmm3, %xmm5
movq %rsi, %xmm6
punpckldq %xmm0, %xmm6    # xmm6 = xmm6[0],xmm0[0],xmm6[1],xmm0[1]
subpd %xmm1, %xmm6
movapd %xmm6, %xmm3
unpckhpd %xmm6, %xmm3            # xmm3 = xmm3[1],xmm6[1]
addsd %xmm6, %xmm3
divsd %xmm5, %xmm3
mulsd %xmm3, %xmm4
cvttsd2si %xmm4, %r10
movq %r10, %r11
sarq $0x3f, %r11
subsd %xmm2, %xmm4
cvttsd2si %xmm4, %r9
andq %r11, %r9
orq %r10, %r9
movl %r9d, (%rdx,%rcx)
cmpl %r15d, %r8d
ja 0xa317a
xorpd %xmm4, %xmm4
jmp 0xa3196
subq %r15, %r8
movq %r8, %xmm5
punpckldq %xmm0, %xmm5    # xmm5 = xmm5[0],xmm0[0],xmm5[1],xmm0[1]
subpd %xmm1, %xmm5
movapd %xmm5, %xmm4
unpckhpd %xmm5, %xmm4            # xmm4 = xmm4[1],xmm5[1]
addsd %xmm5, %xmm4
mulsd %xmm3, %xmm4
cvttsd2si %xmm4, %r8
movq %r8, %r10
sarq $0x3f, %r10
subsd %xmm2, %xmm4
cvttsd2si %xmm4, %r11
andq %r10, %r11
orq %r8, %r11
addq %r9, %r11
movl %r11d, 0x4(%rdx,%rcx)
movl %r9d, %r8d
cmpq %r8, %rsi
jae 0xa31c8
movl %esi, (%rdx,%rcx)
movl %r11d, %r8d
cmpq %r8, %rsi
jae 0xa31d4
movl %esi, 0x4(%rdx,%rcx)
movl 0x14(%rdx,%rcx), %esi
movq (%rdi,%rsi,8), %r10
movq (%r14,%rsi,8), %rsi
cmpq %rsi, %r10
je 0xa32b8
movl 0xc(%rdx,%rcx), %r8d
movl 0x10(%rdx,%rcx), %r9d
cvtsi2sd %r8, %xmm4
movq %r10, %xmm3
punpckldq %xmm0, %xmm3    # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
subpd %xmm1, %xmm3
movapd %xmm3, %xmm5
unpckhpd %xmm3, %xmm5            # xmm5 = xmm5[1],xmm3[1]
addsd %xmm3, %xmm5
movq %rsi, %xmm6
punpckldq %xmm0, %xmm6    # xmm6 = xmm6[0],xmm0[0],xmm6[1],xmm0[1]
subpd %xmm1, %xmm6
movapd %xmm6, %xmm3
unpckhpd %xmm6, %xmm3            # xmm3 = xmm3[1],xmm6[1]
addsd %xmm6, %xmm3
divsd %xmm5, %xmm3
mulsd %xmm3, %xmm4
cvttsd2si %xmm4, %r10
movq %r10, %r11
sarq $0x3f, %r11
subsd %xmm2, %xmm4
cvttsd2si %xmm4, %r15
andq %r11, %r15
orq %r10, %r15
movl %r15d, 0xc(%rdx,%rcx)
cmpl %r8d, %r9d
ja 0xa325d
xorpd %xmm4, %xmm4
jmp 0xa3279
subq %r8, %r9
movq %r9, %xmm5
punpckldq %xmm0, %xmm5    # xmm5 = xmm5[0],xmm0[0],xmm5[1],xmm0[1]
subpd %xmm1, %xmm5
movapd %xmm5, %xmm4
unpckhpd %xmm5, %xmm4            # xmm4 = xmm4[1],xmm5[1]
addsd %xmm5, %xmm4
mulsd %xmm4, %xmm3
cvttsd2si %xmm3, %r8
movq %r8, %r9
sarq $0x3f, %r9
subsd %xmm2, %xmm3
cvttsd2si %xmm3, %r10
andl %r9d, %r10d
orl %r10d, %r8d
addl %r15d, %r8d
movl %r8d, 0x10(%rdx,%rcx)
movl %r15d, %r9d
cmpq %r9, %rsi
jae 0xa32ac
movl %esi, 0xc(%rdx,%rcx)
movl %r8d, %r8d
cmpq %r8, %rsi
jae 0xa32b8
movl %esi, 0x10(%rdx,%rcx)
addq $0x30, %rcx
jmp 0xa30e5
callq 0x2220
movq %r14, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220
subq $0x8, %rsp
movq %r15, %rdi
movq %rcx, %rsi
movq %r8, %rdx
movq %r9, %rcx
movq %rbx, %r8
movl %r11d, %r9d
pushq $0x1
pushq $0x0
pushq %r10
callq 0x7b888
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq