// File: /workspace/github_cpp_makefile_star2_O1/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, 0x20(%rsp)
movq %rsi, %r12
movq %rdi, %r14
movq 0x130(%rsp), %r10
movq 0x10(%rsi), %r13
testq %rdi, %rdi
movq %rsi, 0x8(%rsp)
movq %r9, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
je 0x1baf61
movsd 0x6a6e4(%rip), %xmm1    # 0x225520
divsd %xmm0, %xmm1
minsd 0x6a6e0(%rip), %xmm1    # 0x225528
cvttsd2si %xmm1, %rax
movq %r14, 0x10(%r12)
movq %r12, %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 0x852da
addq $0x50, %rsp
movq 0x10(%r12), %rbp
cmpq %r14, %r13
jbe 0x1baf52
imulq $0xa8, %rbp, %r15
imulq $0xa8, %r14, %rbx
movq %r13, %rax
addq %rbp, %rax
subq %r14, %rax
movq %rax, 0x18(%rsp)
movl $0xa8, %eax
movq %r13, 0x10(%rsp)
cmpq %rbp, %r14
je 0x1baf3c
movq 0x8(%rsp), %rax
movq (%rax), %r12
leaq (%r12,%rbx), %r13
movl $0xa8, %edx
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x2160
addq %r15, %r12
movl $0xa8, %edx
movq %r13, %rdi
movq 0x10(%rsp), %r13
movq %r12, %rsi
movq 0x8(%rsp), %r12
callq 0x2160
movq (%r12), %rdi
addq %r15, %rdi
movl $0xa8, %edx
leaq 0x50(%rsp), %rsi
callq 0x2160
movl $0xa8, %eax
incq %rbp
incq %r14
addq %rax, %r15
addq %rax, %rbx
cmpq %r14, %r13
jne 0x1baee1
movq 0x18(%rsp), %rbp
movq 0x10(%r12), %r14
movq %rbp, 0x10(%r12)
subq %r14, %rbp
jmp 0x1baf6a
subq %r14, %r13
xorl %r14d, %r14d
movq %r13, %rbp
testq %rbp, %rbp
je 0x1bb1e1
movsd 0x6a5a5(%rip), %xmm0    # 0x225520
divsd 0x20(%rsp), %xmm0
minsd 0x6a59f(%rip), %xmm0    # 0x225528
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
cvttsd2si %xmm0, %rax
movq %rax, 0x28(%rsp)
testq %r14, %r14
je 0x1bb02c
cmpq 0x10(%r12), %r14
jae 0x1bb02c
imulq $0xa8, %r14, %rax
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
xorl %r15d, %r15d
testq %r14, %r14
je 0x1bb014
movq 0x8(%rsp), %rax
movq (%rax), %r12
addq %rbx, %r12
movq 0x18(%rsp), %rax
leaq (%r12,%rax), %r13
movl $0xa8, %edx
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x2160
movl $0xa8, %edx
movq %r13, %rdi
movq %r12, %rsi
movq 0x8(%rsp), %r12
callq 0x2160
movq (%r12), %rdi
addq %rbx, %rdi
movl $0xa8, %edx
leaq 0x50(%rsp), %rsi
callq 0x2160
addq $0xa8, %rbx
leaq (%r14,%r15), %rax
incq %rax
incq %r15
cmpq 0x10(%r12), %rax
jb 0x1bafbe
movq %rbp, 0x10(%r12)
movq %r12, %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %r8
movq 0x130(%rsp), %r9
movsd 0x20(%rsp), %xmm0
pushq 0x178(%rsp)
pushq 0x178(%rsp)
pushq 0x178(%rsp)
pushq 0x178(%rsp)
pushq 0x48(%rsp)
pushq 0x180(%rsp)
pushq 0x180(%rsp)
pushq 0x180(%rsp)
pushq 0x180(%rsp)
pushq 0x180(%rsp)
callq 0x852da
addq $0x50, %rsp
movq 0x10(%r12), %r14
movq 0x10(%rsp), %rax
cmpq %rax, %rbp
jae 0x1bb145
imulq $0xa8, %r14, %r15
imulq $0xa8, %rbp, %rbx
leaq (%rax,%r14), %rcx
subq %rbp, %rcx
movq %rcx, 0x18(%rsp)
movl $0xa8, %ecx
cmpq %r14, %rbp
je 0x1bb12f
movq 0x8(%rsp), %rax
movq (%rax), %r12
leaq (%r12,%rbx), %r13
movl $0xa8, %edx
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x2160
addq %r15, %r12
movl $0xa8, %edx
movq %r13, %rdi
movq %r12, %rsi
movq 0x8(%rsp), %r12
callq 0x2160
movq (%r12), %rdi
addq %r15, %rdi
movl $0xa8, %edx
leaq 0x50(%rsp), %rsi
callq 0x2160
movl $0xa8, %ecx
movq 0x10(%rsp), %rax
incq %r14
incq %rbp
addq %rcx, %r15
addq %rcx, %rbx
cmpq %rbp, %rax
jne 0x1bb0d4
movq 0x18(%rsp), %r14
movq 0x10(%r12), %rbp
movq %r14, 0x10(%r12)
subq %rbp, %r14
testq %rbp, %rbp
je 0x1bb1e1
cmpq 0x10(%r12), %rbp
jae 0x1bb1e1
imulq $0xa8, %rbp, %rax
movq %rax, 0x10(%rsp)
xorl %ebx, %ebx
xorl %r15d, %r15d
testq %rbp, %rbp
je 0x1bb1c9
movq 0x8(%rsp), %rax
movq (%rax), %r12
addq %rbx, %r12
movq 0x10(%rsp), %rax
leaq (%r12,%rax), %r13
movl $0xa8, %edx
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x2160
movl $0xa8, %edx
movq %r13, %rdi
movq %r12, %rsi
movq 0x8(%rsp), %r12
callq 0x2160
movq (%r12), %rdi
addq %rbx, %rdi
movl $0xa8, %edx
leaq 0x50(%rsp), %rsi
callq 0x2160
addq $0xa8, %rbx
leaq (%r15,%rbp), %rax
incq %rax
incq %r15
cmpq 0x10(%r12), %rax
jb 0x1bb173
movq %r14, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq