// File: /workspace/github_cpp_makefile_star2_O1/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 0xdf929
movq %rdi, %r13
movq %rbx, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
movl %r11d, 0xc(%rsp)
movq %r8, 0x28(%rsp)
movq %r9, 0x30(%rsp)
movq %rax, 0x40(%rsp)
movq 0x8(%rdi), %r12
movq %rsi, 0x10(%rsp)
movq 0x8(%rsi), %rbp
leaq (%r12,%rbp), %r14
movl $0x8, %esi
movq %r14, %rdi
movq %r10, 0x38(%rsp)
callq 0x2120
movq %rax, %rbx
movl $0x8, %esi
movq %r14, %rdi
callq 0x2120
movq 0x38(%rsp), %r11
movq %rax, %r14
addq %r12, %rbp
je 0xdf630
xorl %eax, %eax
movq %rax, %rsi
subq %r12, %rsi
jae 0xdf5cf
movq %rax, %rsi
shlq $0x5, %rsi
addq (%r13), %rsi
jmp 0xdf5db
shlq $0x5, %rsi
movq 0x10(%rsp), %rcx
addq (%rcx), %rsi
movq 0x8(%rsi), %rcx
testq %rcx, %rcx
je 0xdf622
movq 0x10(%r15), %rdx
movq 0x18(%rsi), %rsi
xorl %r9d, %r9d
xorl %r8d, %r8d
movq (%rsi,%r8,8), %rdi
movl %edi, %r10d
shrl %r10d
leaq (%r10,%r10,4), %r10
movl (%rdx,%r10,8), %r10d
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
shrq $0x20, %rdi
addq %r9, %rdi
addq %r10, %rdi
incq %r8
movq %rdi, %r9
cmpq %r8, %rcx
jne 0xdf5f2
jmp 0xdf624
xorl %edi, %edi
movq %rdi, (%rbx,%rax,8)
incq %rax
cmpq %rbp, %rax
jne 0xdf5ba
subq $0x8, %rsp
movq %r15, %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq 0x20(%rsp), %r8
movl 0x14(%rsp), %r9d
pushq $0x1
pushq $0x0
pushq %r11
callq 0xb5778
addq $0x20, %rsp
testq %rbp, %rbp
movq 0x10(%rsp), %r12
je 0xdf6e2
movq 0x8(%r13), %rax
xorl %ecx, %ecx
movq %rcx, %rdi
subq %rax, %rdi
jae 0xdf684
movq %rcx, %rdi
shlq $0x5, %rdi
addq (%r13), %rdi
jmp 0xdf68c
shlq $0x5, %rdi
addq (%r12), %rdi
movq 0x8(%rdi), %rdx
testq %rdx, %rdx
je 0xdf6d3
movq 0x10(%r15), %rsi
movq 0x18(%rdi), %rdi
xorl %r10d, %r10d
xorl %r9d, %r9d
movq (%rdi,%r9,8), %r8
movl %r8d, %r11d
shrl %r11d
leaq (%r11,%r11,4), %r11
movl (%rsi,%r11,8), %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
shrq $0x20, %r8
addq %r10, %r8
addq %r11, %r8
incq %r9
movq %r8, %r10
cmpq %r9, %rdx
jne 0xdf6a3
jmp 0xdf6d6
xorl %r8d, %r8d
movq %r8, (%r14,%rcx,8)
incq %rcx
cmpq %rbp, %rcx
jne 0xdf66f
movq 0x40(%rsp), %rcx
movq (%rcx), %rax
testq %rax, %rax
je 0xdf90b
movq 0x10(%rcx), %rcx
movq 0x145b41(%rip), %xmm0   # 0x225240
movapd 0x145b49(%rip), %xmm1   # 0x225250
movsd 0x145b59(%rip), %xmm2   # 0x225268
movl 0x8(%rcx), %edx
movq (%rbx,%rdx,8), %rsi
movq (%r14,%rdx,8), %rdx
cmpq %rdx, %rsi
je 0xdf821
movl (%rcx), %edi
movl 0x4(%rcx), %r8d
xorps %xmm3, %xmm3
cvtsi2sd %rdi, %xmm3
movq %rsi, %xmm4
punpckldq %xmm0, %xmm4    # xmm4 = xmm4[0],xmm0[0],xmm4[1],xmm0[1]
subpd %xmm1, %xmm4
movapd %xmm4, %xmm5
unpckhpd %xmm4, %xmm5            # xmm5 = xmm5[1],xmm4[1]
addsd %xmm4, %xmm5
movq %rdx, %xmm4
punpckldq %xmm0, %xmm4    # xmm4 = xmm4[0],xmm0[0],xmm4[1],xmm0[1]
subpd %xmm1, %xmm4
movapd %xmm4, %xmm6
unpckhpd %xmm4, %xmm6            # xmm6 = xmm6[1],xmm4[1]
addsd %xmm4, %xmm6
divsd %xmm5, %xmm6
mulsd %xmm3, %xmm6
cvttsd2si %xmm6, %r9
movq %r9, %r10
sarq $0x3f, %r10
subsd %xmm2, %xmm6
cvttsd2si %xmm6, %rsi
andq %r10, %rsi
orq %r9, %rsi
movl %esi, (%rcx)
cmpl %edi, %r8d
ja 0xdf793
xorpd %xmm3, %xmm3
jmp 0xdf7af
subq %rdi, %r8
movq %r8, %xmm4
punpckldq %xmm0, %xmm4    # xmm4 = xmm4[0],xmm0[0],xmm4[1],xmm0[1]
subpd %xmm1, %xmm4
movapd %xmm4, %xmm3
unpckhpd %xmm4, %xmm3            # xmm3 = xmm3[1],xmm4[1]
addsd %xmm4, %xmm3
movl 0x8(%rcx), %edi
movq (%rbx,%rdi,8), %xmm4
punpckldq %xmm0, %xmm4    # xmm4 = xmm4[0],xmm0[0],xmm4[1],xmm0[1]
subpd %xmm1, %xmm4
movapd %xmm4, %xmm5
unpckhpd %xmm4, %xmm5            # xmm5 = xmm5[1],xmm4[1]
addsd %xmm4, %xmm5
movq (%r14,%rdi,8), %xmm4
punpckldq %xmm0, %xmm4    # xmm4 = xmm4[0],xmm0[0],xmm4[1],xmm0[1]
subpd %xmm1, %xmm4
movapd %xmm4, %xmm6
unpckhpd %xmm4, %xmm6            # xmm6 = xmm6[1],xmm4[1]
addsd %xmm4, %xmm6
divsd %xmm5, %xmm6
mulsd %xmm3, %xmm6
cvttsd2si %xmm6, %rdi
movq %rdi, %r8
sarq $0x3f, %r8
subsd %xmm2, %xmm6
cvttsd2si %xmm6, %r9
andl %r8d, %r9d
orl %r9d, %edi
addl %esi, %edi
movl %edi, 0x4(%rcx)
movl %esi, %esi
cmpq %rsi, %rdx
jae 0xdf816
movl %edx, (%rcx)
movl 0x4(%rcx), %esi
cmpq %rsi, %rdx
jae 0xdf821
movl %edx, 0x4(%rcx)
movl 0x14(%rcx), %edx
movq (%rbx,%rdx,8), %rsi
movq (%r14,%rdx,8), %rdx
cmpq %rdx, %rsi
je 0xdf8fe
movl 0xc(%rcx), %edi
movl 0x10(%rcx), %r8d
xorps %xmm4, %xmm4
cvtsi2sd %rdi, %xmm4
movq %rsi, %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 %rdx, %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, %r9
movq %r9, %r10
sarq $0x3f, %r10
subsd %xmm2, %xmm4
cvttsd2si %xmm4, %rsi
andq %r10, %rsi
orq %r9, %rsi
movl %esi, 0xc(%rcx)
cmpl %edi, %r8d
ja 0xdf8a7
xorpd %xmm4, %xmm4
jmp 0xdf8c3
subq %rdi, %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
movl %esi, %edi
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 %esi, %r8d
movl %r8d, 0x10(%rcx)
cmpq %rdi, %rdx
jae 0xdf8f3
movl %edx, 0xc(%rcx)
movl 0x10(%rcx), %esi
cmpq %rsi, %rdx
jae 0xdf8fe
movl %edx, 0x10(%rcx)
addq $0x30, %rcx
decq %rax
jne 0xdf70f
movq %rbx, %rdi
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 0xb5778
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq