// File: /workspace/github_cpp_makefile_star2_O1/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 0x1cac98
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 0x1cab89
xorl %ebp, %ebp
movl 0x10(%r13), %ecx
testq %rcx, %rcx
setne %r9b
je 0x1caca7
leaq (,%rbp,4), %rax
addq %rbp, %rax
movl 0x4(%rsi,%rax,8), %r8d
movq %r8, %rdx
shlq $0x21, %rdx
sarq $0x21, %rdx
leaq -0x1(%rcx), %rdi
cmpq %rdx, %rdi
movq %rdx, %rbx
cmovbq %rdi, %rbx
testl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
je 0x1caae3
xorl %r9d, %r9d
xorl %r15d, %r15d
cmpq %r9, %rdi
je 0x1caca7
movq 0x18(%r13), %r8
addq (%r8,%r9,8), %r15
incq %r9
cmpq %r9, %rdx
jne 0x1caac1
cmpq %rcx, %r9
setb %r9b
jmp 0x1caae6
xorl %r15d, %r15d
testb %r9b, %r9b
je 0x1caca7
cmpq %r14, %rbp
jge 0x1cab7b
leaq (%rsi,%rax,8), %r12
movl 0x4(%r12), %eax
shlq $0x21, %rax
sarq $0x21, %rax
cmpq %rax, %rbx
jne 0x1cab76
movl 0x8(%r12), %edx
shrl %edx
movq 0x18(%r13), %rax
movq (%rax,%rbx,8), %rcx
movq %rcx, %rax
shrq $0x21, %rax
cmpq %rdx, %rax
jne 0x1cad04
shrq $0x20, %rcx
movl %ecx, 0x4(%rsp)
movl %r15d, 0x8(%rsp)
leaq 0xc06ef(%rip), %rcx     # 0x28b230
movq 0x18(%rcx), %rcx
movl (%rcx,%rax,8), %eax
addl %r15d, %eax
movl %eax, 0xc(%rsp)
leaq 0x4(%rsp), %rdi
movq %r12, %rsi
callq 0x1ca9d2
movq 0x18(%r13), %rax
addq (%rax,%rbx,8), %r15
incq %rbp
incq %rbx
addq $0x28, %r12
cmpq %rbp, %r14
jne 0x1caafc
movq %r14, %rbp
movq 0x10(%rsp), %rsi
cmpq %r14, %rbp
jl 0x1caa78
jmp 0x1cac98
decq %r14
leaq 0x4(%rsp), %r15
movl 0x10(%r13), %ecx
testq %rcx, %rcx
setne %r9b
je 0x1cacc6
leaq (%r14,%r14,4), %rax
movl 0x4(%rsi,%rax,8), %r8d
movq %r8, %rdx
shlq $0x21, %rdx
sarq $0x21, %rdx
leaq -0x1(%rcx), %rdi
cmpq %rdx, %rdi
movq %rdx, %rbx
cmovbq %rdi, %rbx
testl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
je 0x1cabf4
xorl %r9d, %r9d
xorl %ebp, %ebp
cmpq %r9, %rdi
je 0x1cacc6
movq 0x18(%r13), %r8
addq (%r8,%r9,8), %rbp
incq %r9
cmpq %r9, %rdx
jne 0x1cabd2
cmpq %rcx, %r9
setb %r9b
jmp 0x1cabf6
xorl %ebp, %ebp
testb %r9b, %r9b
je 0x1cacc6
testq %r14, %r14
js 0x1cac8f
leaq (%rsi,%rax,8), %r12
movl 0x4(%r12), %eax
shlq $0x21, %rax
sarq $0x21, %rax
cmpq %rax, %rbx
jne 0x1cac8a
movl 0x8(%r12), %edx
shrl %edx
movq 0x18(%r13), %rax
movq (%rax,%rbx,8), %rcx
movq %rcx, %rax
shrq $0x21, %rax
cmpq %rdx, %rax
jne 0x1cace5
shrq $0x20, %rcx
movl %ecx, 0x4(%rsp)
movl %ebp, 0x8(%rsp)
leaq 0xc05e0(%rip), %rcx     # 0x28b230
movq 0x18(%rcx), %rcx
movl (%rcx,%rax,8), %eax
addl %ebp, %eax
movl %eax, 0xc(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x1ca9d2
movq 0x18(%r13), %rax
addq (%rax,%rbx,8), %rbp
leaq -0x1(%r14), %rax
incq %rbx
addq $-0x28, %r12
testq %r14, %r14
movq %rax, %r14
jg 0x1cac0c
movq $-0x1, %r14
movq 0x10(%rsp), %rsi
testq %r14, %r14
jns 0x1cab91
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6c0d9(%rip), %rdi     # 0x236d87
leaq 0x68cd6(%rip), %rsi     # 0x23398b
leaq 0x6c0d4(%rip), %rcx     # 0x236d90
movl $0x3d83, %edx           # imm = 0x3D83
callq 0x2110
leaq 0x6c0ba(%rip), %rdi     # 0x236d87
leaq 0x68cb7(%rip), %rsi     # 0x23398b
leaq 0x6c0b5(%rip), %rcx     # 0x236d90
movl $0x3d95, %edx           # imm = 0x3D95
callq 0x2110
leaq 0x6c0e6(%rip), %rdi     # 0x236dd2
leaq 0x68c98(%rip), %rsi     # 0x23398b
leaq 0x6c096(%rip), %rcx     # 0x236d90
movl $0x3d9a, %edx           # imm = 0x3D9A
callq 0x2110
leaq 0x6c0c7(%rip), %rdi     # 0x236dd2
leaq 0x68c79(%rip), %rsi     # 0x23398b
leaq 0x6c077(%rip), %rcx     # 0x236d90
movl $0x3d88, %edx           # imm = 0x3D88
callq 0x2110