// File: /workspace/github_cpp_makefile_star2_O3/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 0x1d4a84
movq %rdx, %r14
movl 0x1c(%rsi), %eax
movl %eax, %ecx
sarl %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,4), %r13
shlq $0x3, %r13
addq 0x10(%rdi), %r13
testb $0x1, %al
movq %rsi, 0x10(%rsp)
jne 0x1d4a93
xorl %ebp, %ebp
movl 0x10(%r13), %eax
testq %rax, %rax
movq 0x10(%rsp), %r8
je 0x1d4b9b
leaq (,%rbp,4), %rcx
addq %rbp, %rcx
movl 0x4(%r8,%rcx,8), %edx
shlq $0x21, %rdx
sarq $0x21, %rdx
leaq -0x1(%rax), %rbx
cmpq %rdx, %rbx
cmovaeq %rdx, %rbx
xorl %r15d, %r15d
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x1d49fa
movq 0x18(%r13), %rdi
addq (%rdi,%rsi,8), %r15
incq %rsi
cmpq %rsi, %rax
jne 0x1d49e0
jmp 0x1d4b9b
cmpq %r14, %rbp
jge 0x1d4a7b
leaq (%r8,%rcx,8), %r12
movl 0x4(%r12), %eax
shlq $0x21, %rax
sarq $0x21, %rax
cmpq %rax, %rbx
jne 0x1d4a7b
movl 0x8(%r12), %eax
shrl %eax
movq 0x18(%r13), %rcx
movq (%rcx,%rbx,8), %rcx
movq %rcx, %rdx
shrq $0x21, %rdx
cmpl %eax, %edx
jne 0x1d4bd9
shrq $0x20, %rcx
movl %ecx, 0x4(%rsp)
movl %r15d, 0x8(%rsp)
leaq 0xc17e9(%rip), %rcx     # 0x296230
movq 0x18(%rcx), %rcx
movl (%rcx,%rax,8), %eax
addl %r15d, %eax
movl %eax, 0xc(%rsp)
leaq 0x4(%rsp), %rdi
movq %r12, %rsi
callq 0x1d48fe
movq 0x18(%r13), %rax
addq (%rax,%rbx,8), %r15
incq %rbp
incq %rbx
addq $0x28, %r12
cmpq %rbp, %r14
jne 0x1d4a03
jmp 0x1d4a84
cmpq %r14, %rbp
jl 0x1d49a6
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x10(%r13), %eax
testl %eax, %eax
je 0x1d4b7c
decq %r14
leaq 0x4(%rsp), %r15
movl %eax, %ecx
leaq (%r14,%r14,4), %rax
movl 0x4(%rsi,%rax,8), %edx
shlq $0x21, %rdx
sarq $0x21, %rdx
leaq -0x1(%rcx), %rbp
cmpq %rdx, %rbp
cmovaeq %rdx, %rbp
xorl %ebx, %ebx
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x1d4ae2
movq 0x18(%r13), %rdi
addq (%rdi,%rsi,8), %rbx
incq %rsi
cmpq %rsi, %rcx
jne 0x1d4ac8
jmp 0x1d4b7c
testq %r14, %r14
js 0x1d4a84
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
movl 0x4(%r12), %eax
shlq $0x21, %rax
sarq $0x21, %rax
cmpq %rax, %rbp
jne 0x1d4b6b
movl 0x8(%r12), %eax
shrl %eax
movq 0x18(%r13), %rcx
movq (%rcx,%rbp,8), %rcx
movq %rcx, %rdx
shrq $0x21, %rdx
cmpl %eax, %edx
jne 0x1d4bba
shrq $0x20, %rcx
movl %ecx, 0x4(%rsp)
movl %ebx, 0x8(%rsp)
leaq 0xc16fd(%rip), %rcx     # 0x296230
movq 0x18(%rcx), %rcx
movl (%rcx,%rax,8), %eax
addl %ebx, %eax
movl %eax, 0xc(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x1d48fe
movq 0x18(%r13), %rax
addq (%rax,%rbp,8), %rbx
leaq -0x1(%r14), %rax
incq %rbp
addq $-0x28, %r12
testq %r14, %r14
movq %rax, %r14
jg 0x1d4af0
jmp 0x1d4a84
movl 0x10(%r13), %eax
testl %eax, %eax
movq 0x10(%rsp), %rsi
jne 0x1d4aa7
leaq 0x6e4d4(%rip), %rdi     # 0x243057
leaq 0x6b0d1(%rip), %rsi     # 0x23fc5b
leaq 0x6e4cf(%rip), %rcx     # 0x243060
movl $0x3d95, %edx           # imm = 0x3D95
callq 0x2110
leaq 0x6e4b5(%rip), %rdi     # 0x243057
leaq 0x6b0b2(%rip), %rsi     # 0x23fc5b
leaq 0x6e4b0(%rip), %rcx     # 0x243060
movl $0x3d83, %edx           # imm = 0x3D83
callq 0x2110
leaq 0x6e4e1(%rip), %rdi     # 0x2430a2
leaq 0x6b093(%rip), %rsi     # 0x23fc5b
leaq 0x6e491(%rip), %rcx     # 0x243060
movl $0x3d9a, %edx           # imm = 0x3D9A
callq 0x2110
leaq 0x6e4c2(%rip), %rdi     # 0x2430a2
leaq 0x6b074(%rip), %rsi     # 0x23fc5b
leaq 0x6e472(%rip), %rcx     # 0x243060
movl $0x3d88, %edx           # imm = 0x3D88
callq 0x2110