// File: /workspace/github_cpp_makefile_star2_O3/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 0xe0a48
movq %rdi, %r13
movq %rcx, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movq %r8, 0x20(%rsp)
movl %r11d, 0xc(%rsp)
movq %r9, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x40(%rsp)
movq 0x8(%rdi), %r12
movq %rsi, 0x38(%rsp)
movq 0x8(%rsi), %rbp
leaq (%r12,%rbp), %r14
movl $0x8, %esi
movq %r14, %rdi
callq 0x2120
movq %rax, %rbx
movl $0x8, %esi
movq %r14, %rdi
callq 0x2120
movq %rax, %r14
addq %r12, %rbp
je 0xe0a78
xorl %eax, %eax
movq 0x30(%rsp), %r11
movq %rax, %rsi
subq %r12, %rsi
jae 0xe0938
movq %rax, %rsi
shlq $0x5, %rsi
addq (%r13), %rsi
jmp 0xe0944
shlq $0x5, %rsi
movq 0x38(%rsp), %rcx
addq (%rcx), %rsi
movq 0x8(%rsi), %rcx
testq %rcx, %rcx
je 0xe098b
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 0xe095b
jmp 0xe098d
xorl %edi, %edi
movq %rdi, (%rbx,%rax,8)
incq %rax
cmpq %rbp, %rax
jne 0xe0923
subq $0x8, %rsp
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x20(%rsp), %r8
movl 0x14(%rsp), %r9d
pushq $0x1
pushq $0x0
pushq %r11
callq 0xb67c4
addq $0x20, %rsp
movq 0x8(%r13), %rax
xorl %ecx, %ecx
movq 0x38(%rsp), %r12
movq %rcx, %rdi
subq %rax, %rdi
jae 0xe09e8
movq %rcx, %rdi
shlq $0x5, %rdi
addq (%r13), %rdi
jmp 0xe09f0
shlq $0x5, %rdi
addq (%r12), %rdi
movq 0x8(%rdi), %rdx
testq %rdx, %rdx
je 0xe0a37
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 0xe0a07
jmp 0xe0a3a
xorl %r8d, %r8d
movq %r8, (%r14,%rcx,8)
incq %rcx
cmpq %rbp, %rcx
jne 0xe09d3
jmp 0xe0aa9
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 0xb67c4
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subq $0x8, %rsp
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x20(%rsp), %r8
movl 0x14(%rsp), %r9d
pushq $0x1
pushq $0x0
pushq 0x48(%rsp)
callq 0xb67c4
addq $0x20, %rsp
movq 0x40(%rsp), %rcx
movq (%rcx), %rax
testq %rax, %rax
je 0xe0c95
movq 0x10(%rcx), %rcx
movq 0x1507ba(%rip), %xmm0   # 0x231280
movapd 0x1507c2(%rip), %xmm1   # 0x231290
movsd 0x150832(%rip), %xmm2   # 0x231308
movl 0x8(%rcx), %edx
movq (%rbx,%rdx,8), %r8
movq (%r14,%rdx,8), %rdx
cmpq %rdx, %r8
je 0xe0bae
movl (%rcx), %esi
movl 0x4(%rcx), %edi
xorps %xmm4, %xmm4
cvtsi2sd %rsi, %xmm4
movq %r8, %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, %r8
andq %r10, %r8
orq %r9, %r8
movl %r8d, (%rcx)
cmpl %esi, %edi
ja 0xe0b59
xorpd %xmm4, %xmm4
jmp 0xe0b75
subq %rsi, %rdi
movq %rdi, %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, %rdi
movq %rdi, %r9
sarq $0x3f, %r9
subsd %xmm2, %xmm4
cvttsd2si %xmm4, %rsi
andq %r9, %rsi
orq %rdi, %rsi
addq %r8, %rsi
movl %esi, 0x4(%rcx)
movl %r8d, %edi
cmpq %rdi, %rdx
jae 0xe0ba4
movl %edx, (%rcx)
movl %esi, %esi
cmpq %rsi, %rdx
jae 0xe0bae
movl %edx, 0x4(%rcx)
movl 0x14(%rcx), %edx
movq (%rbx,%rdx,8), %rsi
movq (%r14,%rdx,8), %rdx
cmpq %rdx, %rsi
je 0xe0c88
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 0xe0c34
xorpd %xmm4, %xmm4
jmp 0xe0c50
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
mulsd %xmm4, %xmm3
cvttsd2si %xmm3, %rdi
movq %rdi, %r8
sarq $0x3f, %r8
subsd %xmm2, %xmm3
cvttsd2si %xmm3, %r9
andl %r8d, %r9d
orl %r9d, %edi
addl %esi, %edi
movl %edi, 0x10(%rcx)
movl %esi, %esi
cmpq %rsi, %rdx
jae 0xe0c7e
movl %edx, 0xc(%rcx)
movl %edi, %esi
cmpq %rsi, %rdx
jae 0xe0c88
movl %edx, 0x10(%rcx)
addq $0x30, %rcx
decq %rax
jne 0xe0ad6
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