// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: split_ug_lalign(unsigned long, overlap_region_alloc*, double, double, Candidates_list*, ul_idx_t const*, ug_opt_t const*, char*, unsigned long, UC_Read*, UC_Read*, Correct_dumy*, bit_extz_t*, overlap_region*, long, unsigned long, unsigned long, void*)
uint64_t split_ug_lalign(uint64_t ol_h, overlap_region_alloc* ol, double errh, double errl, 
		Candidates_list *cl, const ul_idx_t *uref, const ug_opt_t *uopt, 
        char *qstr, uint64_t ql, UC_Read* qu, UC_Read* tu, Correct_dumy* dumy, bit_extz_t *exz,  
        overlap_region *aux_o, int64_t sid, uint64_t khit, uint64_t chain_cut, void *km)
{
	uint64_t ol_l = ol->length - ol_h, on0, k, m; int64_t wl; double erate; overlap_region t;
	// if(sid == 57) fprintf(stderr, "[M::%s] errh::%f, errl::%f\n", __func__, errh, errl);
	// if(sid == 57) prt_split_ovs(ol, uref->ug, ol_h, ol_l, "st");
	if(ol_h) {
		erate = errh; on0 = ol->length;
		wl = MIN((((double)THRESHOLD_MAX_SIZE)/erate), WINDOW);
		ol->length = ol_h;
		ug_lalign(ol, cl, uref, uopt, qstr, ql, qu, tu, dumy, exz, aux_o, erate, wl, sid, khit, chain_cut, km);
		for (k = ol_h, m = ol->length; k < on0; k++) {///move ovlps with ol_l
			if(k != m) {
				t = ol->list[k];
				ol->list[k] = ol->list[m];
				ol->list[m] = t;
			}
			m++;
		}
		ol_h = ol->length; ol->length = m; ol_l = ol->length - ol_h;
	}
	// if(sid == 57) prt_split_ovs(ol, uref->ug, ol_h, ol_l, "mi");
	if(ol_l) {
		erate = errl; on0 = ol->length;
		wl = MIN((((double)THRESHOLD_MAX_SIZE)/erate), WINDOW);
		if(ol_h) {///swap ol_h and ol_l
			for (k = ol_h, m = 0; k < ol->length; k++) {
				if(k != m) {
					t = ol->list[k];
					ol->list[k] = ol->list[m];
					ol->list[m] = t;
				}
				m++;
			}
		}
		// if(sid == 57) prt_split_ovs(ol, uref->ug, ol_h, ol_l, "sw");
		ol->length = ol_l;
		ug_lalign(ol, cl, uref, uopt, qstr, ql, qu, tu, dumy, exz, aux_o, erate, wl, sid, khit, chain_cut, km);
		// if(sid == 57) {
		// 	fprintf(stderr, "[M::%s::]\ton0::%lu\tol_l::%lu\tol_h::%lu\tol->length::%lu\n", __func__, 
		// 		on0, ol_l, ol_h, ol->length);
		// 	prt_split_ovs(ol, uref->ug, ol_h, ol_l, "u0");
		// }
		for (k = ol_l, m = ol->length; k < on0; k++) {///move ovlps with ol_h
			if(k != m) {
				t = ol->list[k];
				ol->list[k] = ol->list[m];
				ol->list[m] = t;
			}
			m++;
		}
		ol_l = ol->length; ol->length = m; ol_h = ol->length - ol_l;
		// if(sid == 57) prt_split_ovs(ol, uref->ug, ol_h, ol_l, "u1");
		if(ol_l) {///swap ol_h and ol_l
			for (k = ol_l, m = 0; k < ol->length; k++) {
				if(k != m) {
					t = ol->list[k];
					ol->list[k] = ol->list[m];
					ol->list[m] = t;
				}
				m++;
			}
		}
	}
	// if(sid == 57) prt_split_ovs(ol, uref->ug, ol_h, ol_l, "ed");
	return ol_h;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movsd %xmm1, 0x18(%rsp)
movq %rsi, %r15
movq %rdi, %rbp
movq 0x130(%rsp), %r10
movq 0x10(%rsi), %r14
testq %rdi, %rdi
movq %rsi, 0x8(%rsp)
movq %r9, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
je 0x1799c1
movsd 0x69cc0(%rip), %xmm1    # 0x1e3570
divsd %xmm0, %xmm1
minsd 0x69cbc(%rip), %xmm1    # 0x1e3578
movq %r14, (%rsp)
cvttsd2si %xmm1, %rax
movq %rbp, 0x10(%r15)
movq %r15, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %rcx
movq %r9, %r8
movq %r10, %r9
pushq 0x178(%rsp)
pushq 0x178(%rsp)
pushq 0x178(%rsp)
pushq 0x178(%rsp)
pushq %rax
pushq 0x180(%rsp)
pushq 0x180(%rsp)
pushq 0x180(%rsp)
pushq 0x180(%rsp)
pushq 0x180(%rsp)
callq 0x5128a
movq 0x50(%rsp), %rax
addq $0x50, %rsp
movq 0x10(%r15), %r14
imulq $0xa8, %rbp, %r13
imulq $0xa8, %r14, %rbx
movl $0xa8, %ecx
cmpq %rax, %rbp
jae 0x1799ac
cmpq %rbp, %r14
je 0x17999e
movq 0x8(%rsp), %rax
movq (%rax), %r15
leaq (%r15,%r13), %r12
movl $0xa8, %edx
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0x2160
addq %rbx, %r15
movl $0xa8, %edx
movq %r12, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %r15
callq 0x2160
movq (%r15), %rdi
addq %rbx, %rdi
movl $0xa8, %edx
leaq 0x50(%rsp), %rsi
callq 0x2160
movl $0xa8, %ecx
movq (%rsp), %rax
incq %r14
incq %rbp
addq %rcx, %r13
addq %rcx, %rbx
jmp 0x179940
movq 0x10(%r15), %rcx
movq %r14, 0x10(%r15)
movq %r14, %r13
movq %rcx, 0x10(%rsp)
subq %rcx, %r13
jmp 0x1799d0
movq %r14, %r13
subq %rbp, %r13
movq $0x0, 0x10(%rsp)
testq %r13, %r13
je 0x179c24
movq %r14, (%rsp)
movsd 0x69b8b(%rip), %xmm0    # 0x1e3570
divsd 0x18(%rsp), %xmm0
minsd 0x69b85(%rip), %xmm0    # 0x1e3578
cvttsd2si %xmm0, %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x179a92
imulq $0xa8, 0x10(%rsp), %rax
movq %rax, 0x48(%rsp)
xorl %ebx, %ebx
movq (%rsp), %rax
xorl %ebp, %ebp
movq 0x10(%rsp), %rcx
addq %rbp, %rcx
cmpq %rax, %rcx
jae 0x179a92
cmpq %rcx, %rbp
je 0x179a86
movq 0x8(%rsp), %rax
movq (%rax), %r15
addq %rbx, %r15
movq 0x48(%rsp), %rax
leaq (%r15,%rax), %r12
movl $0xa8, %edx
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x2160
movl $0xa8, %edx
movq %r12, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %r15
callq 0x2160
movq (%r15), %rdi
addq %rbx, %rdi
movl $0xa8, %edx
movq %r14, %rsi
callq 0x2160
movq 0x10(%r15), %rax
incq %rbp
addq $0xa8, %rbx
jmp 0x179a1f
movq %r13, 0x10(%r15)
movq %r15, %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %r8
movq 0x130(%rsp), %r9
movsd 0x18(%rsp), %xmm0
pushq 0x178(%rsp)
pushq 0x178(%rsp)
pushq 0x178(%rsp)
pushq 0x178(%rsp)
pushq 0x40(%rsp)
pushq 0x180(%rsp)
pushq 0x180(%rsp)
pushq 0x180(%rsp)
pushq 0x180(%rsp)
pushq 0x180(%rsp)
callq 0x5128a
addq $0x50, %rsp
movq 0x10(%r15), %rbp
imulq $0xa8, %r13, %r14
imulq $0xa8, %rbp, %rbx
movl $0xa8, %ecx
movq (%rsp), %rax
cmpq %rax, %r13
jae 0x179b8e
cmpq %r13, %rbp
je 0x179b80
movq 0x8(%rsp), %rax
movq (%rax), %r15
leaq (%r15,%r14), %r12
movl $0xa8, %edx
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0x2160
addq %rbx, %r15
movl $0xa8, %edx
movq %r12, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %r15
callq 0x2160
movq (%r15), %rdi
addq %rbx, %rdi
movl $0xa8, %edx
leaq 0x50(%rsp), %rsi
callq 0x2160
movl $0xa8, %ecx
movq (%rsp), %rax
incq %rbp
incq %r13
addq %rcx, %r14
addq %rcx, %rbx
jmp 0x179b22
movq 0x10(%r15), %r13
movq %rbp, 0x10(%r15)
movq %rbp, %rax
subq %r13, %rax
movq %rax, 0x10(%rsp)
testq %r13, %r13
je 0x179c24
imulq $0xa8, %r13, %rax
movq %rax, (%rsp)
xorl %ebx, %ebx
xorl %r14d, %r14d
leaq (%r14,%r13), %rax
cmpq %rbp, %rax
jae 0x179c24
cmpq %rax, %r14
je 0x179c18
movq 0x8(%rsp), %rax
movq (%rax), %r15
addq %rbx, %r15
movq (%rsp), %rax
leaq (%r15,%rax), %r12
movl $0xa8, %edx
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2160
movl $0xa8, %edx
movq %r12, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %r15
callq 0x2160
movq (%r15), %rdi
addq %rbx, %rdi
movl $0xa8, %edx
movq %rbp, %rsi
callq 0x2160
movq 0x10(%r15), %rbp
incq %r14
addq $0xa8, %rbx
jmp 0x179bb6
movq 0x10(%rsp), %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq