// File: /workspace/github_cpp_makefile_star2_O3/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
movq %r8, %rax
movq %rcx, %rbx
movq %rsi, %r12
movq %rdi, %r14
movq 0x178(%rsp), %rsi
movq 0x170(%rsp), %r13
movq 0x158(%rsp), %rbp
movq 0x150(%rsp), %r15
movq 0x148(%rsp), %r11
movq 0x140(%rsp), %r10
movq 0x130(%rsp), %rdi
movq 0x10(%r12), %r8
testq %r14, %r14
movq %r12, 0x18(%rsp)
movq %rdx, 0x48(%rsp)
je 0x1c4d4d
movsd %xmm1, 0x10(%rsp)
movsd 0x6ca09(%rip), %xmm1    # 0x231620
divsd %xmm0, %xmm1
minsd 0x6ca05(%rip), %xmm1    # 0x231628
movq %r8, 0x8(%rsp)
movq %r9, %r8
movq %rax, %rcx
cvttsd2si %xmm1, %rax
movq %rax, 0x28(%rsp)
movq %r14, 0x10(%r12)
movq %rdi, %r9
movq %r12, %rdi
movq %rsi, %rax
movq %rdx, %rsi
movq %rbx, 0x30(%rsp)
movq %rbx, %rdx
movq %rcx, 0x38(%rsp)
movq %r8, 0x40(%rsp)
pushq %rax
pushq %r13
pushq 0x178(%rsp)
pushq 0x178(%rsp)
pushq 0x48(%rsp)
pushq %rbp
pushq %r15
pushq %r11
pushq %r10
pushq 0x180(%rsp)
callq 0x849d9
movq 0x58(%rsp), %rax
addq $0x50, %rsp
movq 0x10(%r12), %rbp
cmpq %r14, %rax
jbe 0x1c4d81
imulq $0xa8, %rbp, %rbx
imulq $0xa8, %r14, %r15
leaq (%rax,%rbp), %rcx
subq %r14, %rcx
movq %rcx, 0x20(%rsp)
movl $0xa8, %ecx
movsd 0x10(%rsp), %xmm1
movsd 0x6c959(%rip), %xmm0    # 0x231620
cmpq %rbp, %r14
je 0x1c4d30
movq 0x18(%rsp), %rax
movq (%rax), %r12
leaq (%r12,%r15), %r13
movl $0xa8, %edx
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x2160
addq %rbx, %r12
movl $0xa8, %edx
movq %r13, %rdi
movq %r12, %rsi
movq 0x18(%rsp), %r12
callq 0x2160
movq (%r12), %rdi
addq %rbx, %rdi
movl $0xa8, %edx
leaq 0x50(%rsp), %rsi
callq 0x2160
movl $0xa8, %ecx
movsd 0x6c8fb(%rip), %xmm0    # 0x231620
movq 0x8(%rsp), %rax
movsd 0x10(%rsp), %xmm1
incq %rbp
incq %r14
addq %rcx, %rbx
addq %rcx, %r15
cmpq %r14, %rax
jne 0x1c4cc7
movq 0x10(%r12), %rbp
movq 0x20(%rsp), %rax
jmp 0x1c4d92
movq %r8, %r13
subq %r14, %r13
je 0x1c505b
movq %rax, 0x38(%rsp)
movq %r9, 0x40(%rsp)
movsd 0x6c8b5(%rip), %xmm0    # 0x231620
divsd %xmm1, %xmm0
minsd 0x6c8b1(%rip), %xmm0    # 0x231628
movq %r8, 0x8(%rsp)
jmp 0x1c4eb1
movq %rbp, %rax
movsd 0x10(%rsp), %xmm1
movsd 0x6c88e(%rip), %xmm0    # 0x231620
movq %rax, 0x10(%r12)
movq %rax, %r13
subq %rbp, %r13
movq 0x30(%rsp), %rbx
je 0x1c505d
divsd %xmm1, %xmm0
minsd 0x6c874(%rip), %xmm0    # 0x231628
testq %rbp, %rbp
je 0x1c4e8c
cmpq %rbp, %rax
jbe 0x1c4e8c
imulq $0xa8, %rbp, %rcx
movq %rcx, 0x8(%rsp)
xorl %ebx, %ebx
movq %rax, 0x20(%rsp)
xorl %r14d, %r14d
movsd %xmm0, 0x28(%rsp)
testq %rbp, %rbp
je 0x1c4e45
movq (%r12), %r15
addq %rbx, %r15
movq 0x8(%rsp), %rax
leaq (%r15,%rax), %r12
movl $0xa8, %edx
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0x2160
movl $0xa8, %edx
movq %r12, %rdi
movq 0x18(%rsp), %r12
movq %r15, %rsi
callq 0x2160
movq (%r12), %rdi
addq %rbx, %rdi
movl $0xa8, %edx
leaq 0x50(%rsp), %rsi
callq 0x2160
movsd 0x28(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movq 0x10(%r12), %rax
addq $0xa8, %rbx
leaq (%r14,%rbp), %rcx
incq %rcx
incq %r14
cmpq %rax, %rcx
jb 0x1c4de2
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x140(%rsp), %r10
movq 0x148(%rsp), %r11
movq 0x150(%rsp), %r15
movq 0x158(%rsp), %rbp
movq 0x30(%rsp), %rbx
jmp 0x1c4eb1
movq %rax, 0x8(%rsp)
movq 0x140(%rsp), %r10
movq 0x148(%rsp), %r11
movq 0x150(%rsp), %r15
movq 0x158(%rsp), %rbp
cvttsd2si %xmm0, %rax
movq %r13, 0x10(%r12)
movq %r12, %rdi
movq 0x48(%rsp), %rsi
movq %rbx, %rdx
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %r8
movq 0x130(%rsp), %r9
movapd %xmm1, %xmm0
pushq 0x178(%rsp)
pushq 0x178(%rsp)
pushq 0x178(%rsp)
pushq 0x178(%rsp)
pushq %rax
pushq %rbp
pushq %r15
pushq %r11
pushq %r10
pushq 0x180(%rsp)
callq 0x849d9
addq $0x50, %rsp
movq 0x10(%r12), %r14
movq 0x8(%rsp), %rax
cmpq %rax, %r13
jae 0x1c4fbb
imulq $0xa8, %r14, %rbp
imulq $0xa8, %r13, %rbx
leaq (%rax,%r14), %rcx
subq %r13, %rcx
movl $0xa8, %edx
movq %rax, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
cmpq %r14, %r13
je 0x1c4fa3
movq (%r12), %r15
leaq (%r15,%rbx), %r12
movl $0xa8, %edx
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0x2160
addq %rbp, %r15
movl $0xa8, %edx
movq %r12, %rdi
movq 0x18(%rsp), %r12
movq %r15, %rsi
callq 0x2160
movq (%r12), %rdi
addq %rbp, %rdi
movl $0xa8, %edx
leaq 0x50(%rsp), %rsi
callq 0x2160
movl $0xa8, %edx
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rax
incq %r14
incq %r13
addq %rdx, %rbp
addq %rdx, %rbx
cmpq %r13, %rax
jne 0x1c4f47
movq 0x10(%r12), %r14
jmp 0x1c4fbe
movq %r14, %rcx
movq %rcx, 0x10(%r12)
movq %rcx, %rbp
subq %r14, %rbp
testq %r14, %r14
je 0x1c505d
cmpq %r14, %rcx
jbe 0x1c505d
imulq $0xa8, %r14, %rax
movq %rax, 0x8(%rsp)
xorl %ebx, %ebx
xorl %r13d, %r13d
testq %r14, %r14
je 0x1c5043
movq (%r12), %r15
addq %rbx, %r15
movq 0x8(%rsp), %rax
leaq (%r15,%rax), %r12
movl $0xa8, %edx
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0x2160
movl $0xa8, %edx
movq %r12, %rdi
movq 0x18(%rsp), %r12
movq %r15, %rsi
callq 0x2160
movq (%r12), %rdi
addq %rbx, %rdi
movl $0xa8, %edx
leaq 0x50(%rsp), %rsi
callq 0x2160
movq 0x10(%r12), %rcx
addq $0xa8, %rbx
leaq (%r14,%r13), %rax
incq %rax
incq %r13
cmpq %rcx, %rax
jb 0x1c4fec
jmp 0x1c505d
xorl %ebp, %ebp
movq %rbp, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq