// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq 0x58(%rbp), %rax
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movsd %xmm0, -0x40(%rbp)
movsd %xmm1, -0x48(%rbp)
movq %rdx, -0x50(%rbp)
movq %rcx, -0x58(%rbp)
movq %r8, -0x60(%rbp)
movq %r9, -0x68(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
subq -0x30(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x2be451
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
movsd 0xc405e(%rip), %xmm1    # 0x3822a8
divsd -0x98(%rbp), %xmm1
movsd 0xc4046(%rip), %xmm0    # 0x3822a0
ucomisd %xmm1, %xmm0
jb 0x2be27a
movsd 0xc4040(%rip), %xmm0    # 0x3822a8
divsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x148(%rbp)
jmp 0x2be28c
movsd 0xc401e(%rip), %xmm0    # 0x3822a0
movsd %xmm0, -0x148(%rbp)
jmp 0x2be28c
movsd -0x148(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x90(%rbp)
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %r8
movq 0x10(%rbp), %r9
movq 0x18(%rbp), %rax
movq %rax, -0x160(%rbp)
movq 0x20(%rbp), %rax
movq %rax, -0x158(%rbp)
movq 0x28(%rbp), %r13
movq 0x30(%rbp), %r12
movq 0x38(%rbp), %r15
movsd -0x98(%rbp), %xmm0
movq -0x90(%rbp), %r14
movq 0x40(%rbp), %rbx
movq 0x48(%rbp), %r11
movq 0x50(%rbp), %r10
movq 0x58(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x160(%rbp), %rax
movq %rax, (%rsp)
movq -0x158(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x150(%rbp), %rax
movq %r13, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x9bba0
movq -0x30(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x78(%rbp), %rax
jae 0x2be426
movq -0x80(%rbp), %rax
cmpq -0x88(%rbp), %rax
je 0x2be403
movq -0x38(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x80(%rbp), %rax
addq %rax, %rsi
leaq -0x140(%rbp), %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x38(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x88(%rbp), %rax
addq %rax, %rsi
movq -0x38(%rbp), %rax
movq (%rax), %rdi
imulq $0xa8, -0x80(%rbp), %rax
addq %rax, %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x38(%rbp), %rax
movq (%rax), %rdi
imulq $0xa8, -0x88(%rbp), %rax
addq %rax, %rdi
leaq -0x140(%rbp), %rsi
movl $0xa8, %edx
callq 0x2180
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x2be36e
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x88(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
subq -0x30(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x2be83e
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
movsd 0xc3e2b(%rip), %xmm1    # 0x3822a8
divsd -0x98(%rbp), %xmm1
movsd 0xc3e13(%rip), %xmm0    # 0x3822a0
ucomisd %xmm1, %xmm0
jb 0x2be4ad
movsd 0xc3e0d(%rip), %xmm0    # 0x3822a8
divsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x168(%rbp)
jmp 0x2be4bf
movsd 0xc3deb(%rip), %xmm0    # 0x3822a0
movsd %xmm0, -0x168(%rbp)
jmp 0x2be4bf
movsd -0x168(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x2be5af
movq -0x30(%rbp), %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x80(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x2be5ad
movq -0x80(%rbp), %rax
cmpq -0x88(%rbp), %rax
je 0x2be58a
movq -0x38(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x80(%rbp), %rax
addq %rax, %rsi
leaq -0x140(%rbp), %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x38(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x88(%rbp), %rax
addq %rax, %rsi
movq -0x38(%rbp), %rax
movq (%rax), %rdi
imulq $0xa8, -0x80(%rbp), %rax
addq %rax, %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x38(%rbp), %rax
movq (%rax), %rdi
imulq $0xa8, -0x88(%rbp), %rax
addq %rax, %rdi
leaq -0x140(%rbp), %rsi
movl $0xa8, %edx
callq 0x2180
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x2be4f1
jmp 0x2be5af
movq -0x70(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %r8
movq 0x10(%rbp), %r9
movq 0x18(%rbp), %rax
movq %rax, -0x180(%rbp)
movq 0x20(%rbp), %rax
movq %rax, -0x178(%rbp)
movq 0x28(%rbp), %r13
movq 0x30(%rbp), %r12
movq 0x38(%rbp), %r15
movsd -0x98(%rbp), %xmm0
movq -0x90(%rbp), %r14
movq 0x40(%rbp), %rbx
movq 0x48(%rbp), %r11
movq 0x50(%rbp), %r10
movq 0x58(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x180(%rbp), %rax
movq %rax, (%rsp)
movq -0x178(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x170(%rbp), %rax
movq %r13, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x9bba0
movq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x78(%rbp), %rax
jae 0x2be735
movq -0x80(%rbp), %rax
cmpq -0x88(%rbp), %rax
je 0x2be712
movq -0x38(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x80(%rbp), %rax
addq %rax, %rsi
leaq -0x140(%rbp), %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x38(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x88(%rbp), %rax
addq %rax, %rsi
movq -0x38(%rbp), %rax
movq (%rax), %rdi
imulq $0xa8, -0x80(%rbp), %rax
addq %rax, %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x38(%rbp), %rax
movq (%rax), %rdi
imulq $0xa8, -0x88(%rbp), %rax
addq %rax, %rdi
leaq -0x140(%rbp), %rsi
movl $0xa8, %edx
callq 0x2180
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x2be67d
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x88(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
subq -0x70(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x2be83c
movq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x80(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x2be83a
movq -0x80(%rbp), %rax
cmpq -0x88(%rbp), %rax
je 0x2be817
movq -0x38(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x80(%rbp), %rax
addq %rax, %rsi
leaq -0x140(%rbp), %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x38(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x88(%rbp), %rax
addq %rax, %rsi
movq -0x38(%rbp), %rax
movq (%rax), %rdi
imulq $0xa8, -0x80(%rbp), %rax
addq %rax, %rdi
movl $0xa8, %edx
callq 0x2180
movq -0x38(%rbp), %rax
movq (%rax), %rdi
imulq $0xa8, -0x88(%rbp), %rax
addq %rax, %rdi
leaq -0x140(%rbp), %rsi
movl $0xa8, %edx
callq 0x2180
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x2be77e
jmp 0x2be83c
jmp 0x2be83e
movq -0x30(%rbp), %rax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)