// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Process_Read.cpp
// Function: append_ul_t_compress_ovlp(all_ul_t*, unsigned long*, char*, long, char*, long, ul_ov_t*, long)
void append_ul_t_compress_ovlp(all_ul_t *x, uint64_t *rid, char* id, int64_t id_l, char* str, int64_t str_l, ul_ov_t *o, int64_t on) {
	int64_t i, mine, maxs, ovlp, end;
	ul_vec_t *p = NULL;
	nid_t *np = NULL;
	ul_ov_t *z = NULL, *zp = NULL;
	uc_block_t *b = NULL;

	if(id) {
		kv_pushp(nid_t, x->nid, &np);
		np->n = id_l; MALLOC(np->a, np->n+1); memcpy(np->a, id, id_l); np->a[id_l] = '\0';
	}

	if(str) {
		if(rid == NULL) {
			kv_pushp(ul_vec_t, *x, &p);
			memset(p, 0, sizeof(*p));
		} else {
			if((*rid) >= x->m) kv_resize(ul_vec_t, *x, (*rid) + 1);
			if((*rid) >= x->n) {
				memset(x->a+x->n, 0, sizeof(*p)*((*rid) + 1 - x->n));
				x->n = (*rid) + 1;
			}
			p = &(x->a[(*rid)]);
		}
		

		p->bb.n = p->N_site.n = p->r_base.n = 0;
		p->rlen = str_l; 
		
		if(o == NULL || on == 0) on = 0;
		for (i = end = 0, zp = NULL; i < on; i++) {
			z = &(o[i]);
			if(!z->el) continue;
			if(zp) {
				mine = MIN(zp->qe, z->qe); maxs = MAX(zp->qs, z->qs);
				ovlp = mine - maxs; 
				if(zp->qe >= z->qe && zp->qs <= z->qs) continue;
			} else {
				ovlp = -z->qs; 
			}
			if(ovlp < 0) {///push original bases
				kv_pushp(uc_block_t, p->bb, &b);
				b->hid = (uint32_t)-1/**x->mm**/; b->rev = 0; b->base = 1; b->pchain = 0;
				b->qs = end; b->qe = b->qs - ovlp;
				b->ts = p->r_base.n; b->te = b->ts + B4L(-ovlp);
				kv_resize(uint8_t, p->r_base, b->te); p->r_base.n = b->te;
				ha_encode_base(p->r_base.a+b->ts, str+b->qs, b->qe-b->qs, &(p->N_site), b->qs);
			} 

			///push ovlp bases
			kv_pushp(uc_block_t, p->bb, &b);
			b->hid = (z->tn<<1)>>1; b->rev = z->rev; b->base = 0; b->pchain = 0;
			b->qs = z->qs + (ovlp>0?ovlp:0); b->qe = z->qe;
			if(z->rev) {
				b->ts = z->ts; b->te = z->ts + (b->qe - b->qs);
			} else {
				b->ts = z->te - (b->qe - b->qs); b->te = z->te;
			}

			end = MAX(zp?zp->qe:0, z->qe);
		}
		
		if(end < str_l) {///push original bases
			kv_pushp(uc_block_t, p->bb, &b);
			b->hid = (uint32_t)-1/**x->mm**/; b->rev = 0; b->base = 1; b->pchain = 0;
			b->qs = end; b->qe = str_l;
			b->ts = p->r_base.n; b->te = b->ts + B4L(b->qe - b->qs);
			kv_resize(uint8_t, p->r_base, b->te); p->r_base.n = b->te;
			ha_encode_base(p->r_base.a+b->ts, str+b->qs, b->qe-b->qs, &(p->N_site), b->qs);		
			// push_subblock_original_bases(str, x, p, end, str_l, 321);//for debug
		}
		// char *sst = NULL; CALLOC(sst, str_l);//for debug
		// retrieve_ul_t(NULL, sst, x, rid?*rid:x->n-1, 0, 0, -1);
		// if(memcmp(sst, str, str_l)) {
		// 	fprintf(stderr, "ap-Wrong read, id: %ld, [%d, %ld)\n", (int64_t)(rid?*rid:x->n-1), 0, str_l);
		// 	for (i = 0; i < str_l; i++) {
		// 		if(sst[i] != str[i]) fprintf(stderr, "[%ld] input:%c, decompress:%c\n", i, str[i], sst[i]);
		// 	}
		// }
		// free(sst);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x8(%rsp)
movq %r8, %r12
movq %rsi, %rbx
movq %rdi, %r15
movq 0x68(%rsp), %r8
movq 0x60(%rsp), %rbp
testq %rdx, %rdx
movq %r8, (%rsp)
je 0x343c7
movq %rcx, %r13
movq %rdx, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq (%r15), %r12
cmpq 0x8(%r15), %r12
jne 0x3437f
leaq (%r12,%r12), %rax
testq %r12, %r12
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x4, %rsi
callq 0x2370
movq %rax, %rbx
movq %rax, 0x10(%r15)
movq (%r15), %r12
jmp 0x34383
movq 0x10(%r15), %rbx
leaq 0x1(%r12), %rax
movq %rax, (%r15)
shlq $0x4, %r12
movl %r13d, 0x8(%rbx,%r12)
leal 0x1(%r13), %edi
callq 0x2280
movq %rax, %r14
movq %rax, (%rbx,%r12)
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
callq 0x2160
movb $0x0, (%r14,%r13)
movq 0x20(%rsp), %r12
movq (%rsp), %r8
movq 0x18(%rsp), %rbx
testq %r12, %r12
movq 0x8(%rsp), %r13
je 0x34634
testq %rbx, %rbx
je 0x34487
movq (%rbx), %rax
movq 0x58(%r15), %rcx
cmpq %rcx, %rax
setb %dl
leaq 0x1(%rax), %rsi
cmpq %rsi, %rcx
setae %cl
orb %dl, %cl
jne 0x34449
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
incq %rcx
movq %rcx, 0x58(%r15)
movq 0x48(%r15), %rdi
imulq $0x58, %rcx, %rsi
callq 0x2370
movq (%rsp), %r8
movq %rax, 0x48(%r15)
movq (%rbx), %rax
movq 0x50(%r15), %rdx
movq %rax, %rcx
subq %rdx, %rcx
jb 0x3447d
imulq $0x58, %rdx, %rdi
addq 0x48(%r15), %rdi
imulq $0x58, %rcx, %rdx
addq $0x58, %rdx
xorl %esi, %esi
callq 0x20e0
movq (%rsp), %r8
movq (%rbx), %rax
incq %rax
movq %rax, 0x50(%r15)
movq (%rbx), %rax
imulq $0x58, %rax, %rbx
addq 0x48(%r15), %rbx
jmp 0x344f8
movq 0x50(%r15), %rcx
cmpq 0x58(%r15), %rcx
jne 0x344c0
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %ecx
cmovneq %rax, %rcx
movq %rcx, 0x58(%r15)
movq 0x48(%r15), %rdi
imulq $0x58, %rcx, %rsi
callq 0x2370
movq (%rsp), %r8
movq %rax, 0x48(%r15)
movq 0x50(%r15), %rcx
jmp 0x344c4
movq 0x48(%r15), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x50(%r15)
imulq $0x58, %rcx, %rcx
leaq (%rax,%rcx), %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rax,%rcx)
movups %xmm0, 0x30(%rax,%rcx)
movups %xmm0, 0x20(%rax,%rcx)
movups %xmm0, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movq $0x0, 0x50(%rax,%rcx)
xorl %r14d, %r14d
movq %r14, (%rbx)
movq %r14, 0x40(%rbx)
movq %r14, 0x20(%rbx)
movl %r13d, 0x18(%rbx)
testq %rbp, %rbp
sete %al
testq %r8, %r8
setle %cl
orb %al, %cl
jne 0x345f1
addq $0x18, %rbp
xorl %r14d, %r14d
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %r15d, %r15d
testb $0x40, 0x3(%rbp)
je 0x345e1
movl -0x14(%rbp), %r14d
movq 0x20(%rbx), %rcx
movq 0x30(%rbx), %rax
cmpq 0x28(%rbx), %rcx
jne 0x3457a
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x28(%rbx)
shlq $0x2, %rdx
leaq (%rdx,%rdx,8), %rsi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %r8
movq %rax, 0x30(%rbx)
movq 0x20(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rbx)
leaq (%rcx,%rcx,8), %rcx
movl -0xc(%rbp), %edx
andl %r13d, %edx
movl %edx, (%rax,%rcx,4)
movl (%rbp), %edx
movb 0x20(%rax,%rcx,4), %sil
shrl $0x1a, %edx
andb $-0x80, %sil
andb $0x20, %dl
orb %sil, %dl
movb %dl, 0x20(%rax,%rcx,4)
movl -0x14(%rbp), %edx
subl %r14d, %edx
movl %edx, 0x4(%rax,%rcx,4)
movl -0x10(%rbp), %r14d
movl %r14d, 0x8(%rax,%rcx,4)
cmpl $0x0, (%rbp)
js 0x345cd
movl -0x4(%rbp), %esi
subl %r14d, %edx
addl %esi, %edx
movl %edx, %edi
jmp 0x345d7
movl -0x8(%rbp), %edi
movl %r14d, %esi
subl %edx, %esi
addl %edi, %esi
leaq (%rax,%rcx,4), %rax
movl %edi, 0xc(%rax)
movl %esi, 0x10(%rax)
incq %r15
addq $0x1c, %rbp
cmpq %r8, %r15
jl 0x3452e
movq 0x8(%rsp), %r13
cmpq %r13, %r14
jge 0x34634
movq 0x20(%rbx), %rcx
cmpq 0x28(%rbx), %rcx
jne 0x34643
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %ecx
cmovneq %rax, %rcx
movq %rcx, 0x28(%rbx)
movq 0x30(%rbx), %rdi
shlq $0x2, %rcx
leaq (%rcx,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x30(%rbx)
movq 0x20(%rbx), %rcx
jmp 0x34647
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rbx), %rax
leaq 0x38(%rbx), %r15
leaq 0x1(%rcx), %rdx
movq %rdx, 0x20(%rbx)
leaq (%rcx,%rcx,8), %rsi
movl $0xffffffff, (%rax,%rsi,4) # imm = 0xFFFFFFFF
movb 0x20(%rax,%rsi,4), %cl
andb $-0x80, %cl
orb $0x40, %cl
movb %cl, 0x20(%rax,%rsi,4)
movl %r14d, 0x4(%rax,%rsi,4)
movl %r13d, 0x8(%rax,%rsi,4)
movl (%rbx), %edx
movl %edx, 0xc(%rax,%rsi,4)
subl %r14d, %r13d
movl %r13d, %ecx
shrl $0x2, %ecx
movl %r13d, %edi
andl $0x3, %edi
cmpl $0x1, %edi
sbbl $-0x1, %ecx
addl %edx, %ecx
movl %ecx, 0x10(%rax,%rsi,4)
cmpq %rcx, 0x8(%rbx)
jae 0x3470b
movq %r12, %r13
leaq (%rax,%rsi,4), %r12
decq %rcx
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movl 0x10(%r12), %ecx
movl 0xc(%r12), %edx
movl 0x4(%r12), %r14d
movl 0x8(%r12), %esi
movq %r13, %r12
movq %rsi, %r13
subl %r14d, %r13d
jmp 0x3470f
movq 0x10(%rbx), %rax
movq %rcx, (%rbx)
movl %edx, %edi
addq %rax, %rdi
movl %r14d, %r8d
addq %r8, %r12
movl %r13d, %edx
movq %r12, %rsi
movq %r15, %rcx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x33eca