// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: renew_mg_lchains(ma_ug_t*, mg_lchain_t*, long, long)
void renew_mg_lchains(ma_ug_t *ug, mg_lchain_t *a, int64_t a_n, int64_t ulid)
{
	if (a_n <= 0) return;
	uint32_t rev = (a[0].score&1); ma_utg_t *u = &(ug->u.a[a[0].score>>1]);
	uint64_t i, l; int64_t k; utg_ct_t p; 
	// fprintf(stderr, "\n[M::%s::ulid->%ld] utg%.6d%c(%c), a_n:%ld, u->n:%u\n", __func__, ulid, 
	// 			(int32_t)(a[0].score>>1)+1, "lc"[ug->u.a[(a[0].score>>1)].circ], "+-"[(a[0].score&1)], 
	// 			a_n, u->n);
	// for (k = 0; k < a_n; k++, i++) {
	// 	fprintf(stderr, "[M::%s::ulid->%ld] utg%.6d%c(%c), k:%ld, a[k].cnt:%d\n", __func__, ulid, 
	// 	(int32_t)(a[k].score>>1)+1, "lc"[ug->u.a[(a[k].score>>1)].circ], "+-"[(a[k].score&1)], k, a[k].cnt);
	// }

	if(!rev) {
		k = 0;
		while (k < a_n) {
			for (i = l = 0; i < u->n; i++) {
				if(i == (uint64_t)a[k].cnt) break;
				l += (uint32_t)u->a[i];
			}
			assert(i < u->n);
			for (; k < a_n; k++, i++) {
				///might have self-circle, so this assertion won't work
				// assert(a[k].cnt == (int64_t)i && (a[k].v>>1) == (u->a[i]>>33)); 
				if(a[k].cnt != (int64_t)i) break;
				assert((a[k].v>>1) == (u->a[i]>>33));
				p.x = u->a[i]>>32; p.s = l; p.e = l + Get_READ_LENGTH(R_INF, (u->a[i]>>33));
				convert_mg_lchain_t(&p, &a[k]);
				l += (uint32_t)u->a[i];
			}
		}		
	} else {
		k = a_n-1;
		while(k >= 0) {
			for (i = l = 0; i < u->n; i++) {
				if(i == (uint64_t)a[k].cnt) break;
				l += (uint32_t)u->a[i];
			}
			assert(i < u->n);
			for (; k >= 0; k--, i++) {
				///might have self-circle, so this assertion won't work
				// assert(a[k].cnt == (int64_t)i && (a[k].v>>1) == (u->a[i]>>33)); 
				if(a[k].cnt != (int64_t)i) break;
				assert((a[k].v>>1) == (u->a[i]>>33));
				p.x = u->a[i]>>32; p.s = l; p.e = l + Get_READ_LENGTH(R_INF, (u->a[i]>>33));
				convert_mg_lchain_t(&p, &a[k]);
				l += (uint32_t)u->a[i];
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdx, %rdx
jle 0x1883a1
movq %rdx, %rbx
movl 0x1c(%rsi), %eax
movl %eax, %ecx
sarl %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %r13
addq 0x10(%rdi), %r13
testb $0x1, %al
movq %rsi, (%rsp)
jne 0x1882d5
xorl %ebp, %ebp
cmpq %rbx, %rbp
jge 0x1883a1
movl 0x10(%r13), %eax
imulq $0x28, %rbp, %r12
leaq (%rsi,%r12), %rcx
addq $0x4, %rcx
xorl %r14d, %r14d
xorl %r15d, %r15d
cmpq %r14, %rax
je 0x1883b0
movl (%rcx), %edx
shlq $0x21, %rdx
sarq $0x21, %rdx
cmpq %rdx, %r14
je 0x188250
movq 0x18(%r13), %rdx
addq (%rdx,%r14,8), %r15
incq %r14
jmp 0x18822b
addq (%rsp), %r12
cmpq %rbx, %rbp
jge 0x1882cc
movl 0x4(%r12), %eax
shlq $0x21, %rax
sarq $0x21, %rax
cmpq %rax, %r14
jne 0x1882cc
movl 0x8(%r12), %eax
shrl %eax
movq 0x18(%r13), %rcx
movq (%rcx,%r14,8), %rcx
movq %rcx, %rdx
shrq $0x21, %rdx
cmpl %eax, %edx
jne 0x1883ee
shrq $0x20, %rcx
movl %ecx, 0xc(%rsp)
movl %r15d, 0x10(%rsp)
leaq 0xcbf93(%rip), %rcx     # 0x254230
movq 0x18(%rcx), %rcx
movl (%rcx,%rax,8), %eax
addl %r15d, %eax
movl %eax, 0x14(%rsp)
leaq 0xc(%rsp), %rdi
movq %r12, %rsi
callq 0x18816b
movq 0x18(%r13), %rax
addq (%rax,%r14,8), %r15
incq %rbp
incq %r14
addq $0x28, %r12
jmp 0x188254
movq (%rsp), %rsi
jmp 0x18820c
decq %rbx
leaq 0xc(%rsp), %r15
testq %rbx, %rbx
js 0x1883a1
movl 0x10(%r13), %eax
imulq $0x28, %rbx, %r12
leaq (%rsi,%r12), %rcx
addq $0x4, %rcx
xorl %r14d, %r14d
xorl %ebp, %ebp
cmpq %r14, %rax
je 0x1883cf
movl (%rcx), %edx
shlq $0x21, %rdx
sarq $0x21, %rdx
cmpq %rdx, %r14
je 0x188320
movq 0x18(%r13), %rdx
addq (%rdx,%r14,8), %rbp
incq %r14
jmp 0x1882fb
addq (%rsp), %r12
testq %rbx, %rbx
js 0x188398
movl 0x4(%r12), %eax
shlq $0x21, %rax
sarq $0x21, %rax
cmpq %rax, %r14
jne 0x188398
movl 0x8(%r12), %eax
shrl %eax
movq 0x18(%r13), %rcx
movq (%rcx,%r14,8), %rcx
movq %rcx, %rdx
shrq $0x21, %rdx
cmpl %eax, %edx
jne 0x18840d
shrq $0x20, %rcx
movl %ecx, 0xc(%rsp)
movl %ebp, 0x10(%rsp)
leaq 0xcbec4(%rip), %rcx     # 0x254230
movq 0x18(%rcx), %rcx
movl (%rcx,%rax,8), %eax
addl %ebp, %eax
movl %eax, 0x14(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x18816b
movq 0x18(%r13), %rax
addq (%rax,%r14,8), %rbp
decq %rbx
incq %r14
addq $-0x28, %r12
jmp 0x188324
movq (%rsp), %rsi
jmp 0x1882dd
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6cb68(%rip), %rdi     # 0x1f4f1f
leaq 0x69765(%rip), %rsi     # 0x1f1b23
leaq 0x6cb63(%rip), %rcx     # 0x1f4f28
movl $0x3d83, %edx           # imm = 0x3D83
callq 0x2110
leaq 0x6cb49(%rip), %rdi     # 0x1f4f1f
leaq 0x69746(%rip), %rsi     # 0x1f1b23
leaq 0x6cb44(%rip), %rcx     # 0x1f4f28
movl $0x3d95, %edx           # imm = 0x3D95
callq 0x2110
leaq 0x6cb75(%rip), %rdi     # 0x1f4f6a
leaq 0x69727(%rip), %rsi     # 0x1f1b23
leaq 0x6cb25(%rip), %rcx     # 0x1f4f28
movl $0x3d88, %edx           # imm = 0x3D88
callq 0x2110
leaq 0x6cb56(%rip), %rdi     # 0x1f4f6a
leaq 0x69708(%rip), %rsi     # 0x1f1b23
leaq 0x6cb06(%rip), %rcx     # 0x1f4f28
movl $0x3d9a, %edx           # imm = 0x3D9A
callq 0x2110