// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
jg 0x2dab54
jmp 0x2daf1b
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x1c(%rcx), %ecx
sarl %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x2dad55
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x2dad50
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x2dac09
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
imulq $0x28, -0x48(%rbp), %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
shll %ecx
sarl %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jne 0x2dabe1
jmp 0x2dac09
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2dabb0
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x2dac1b
jmp 0x2dac3a
leaq 0xb9009(%rip), %rdi     # 0x393c2b
leaq 0xb5c06(%rip), %rsi     # 0x39082f
movl $0x3d83, %edx           # imm = 0x3D83
leaq 0xb8fff(%rip), %rcx     # 0x393c34
callq 0x2130
jmp 0x2dac3c
movq -0x48(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x2dad4b
movq -0x10(%rbp), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
shll %eax
sarl %eax
cltq
cmpq -0x38(%rbp), %rax
je 0x2dac6a
jmp 0x2dad4b
movq -0x10(%rbp), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
movq -0x30(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
cmpq %rcx, %rax
jne 0x2dac98
jmp 0x2dacb7
leaq 0xb8fd7(%rip), %rdi     # 0x393c76
leaq 0xb5b89(%rip), %rsi     # 0x39082f
movl $0x3d88, %edx           # imm = 0x3D88
leaq 0xb8f82(%rip), %rcx     # 0x393c34
callq 0x2130
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x54(%rbp)
movq -0x40(%rbp), %rax
movl %eax, -0x50(%rbp)
movq -0x40(%rbp), %rax
leaq 0xea5f0(%rip), %rcx     # 0x3c52d0
movq 0x18(%rcx), %rcx
movq -0x30(%rbp), %rdx
movq 0x18(%rdx), %rdx
movq -0x38(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrq $0x21, %rdx
addq (%rcx,%rdx,8), %rax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rsi
imulq $0x28, -0x48(%rbp), %rax
addq %rax, %rsi
leaq -0x54(%rbp), %rdi
callq 0x2daa10
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2dac3c
jmp 0x2dab92
jmp 0x2daf1b
movq -0x18(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jl 0x2daf19
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x2dadd5
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
imulq $0x28, -0x48(%rbp), %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
shll %ecx
sarl %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jne 0x2dadad
jmp 0x2dadd5
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2dad7c
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x2dade7
jmp 0x2dae06
leaq 0xb8e3d(%rip), %rdi     # 0x393c2b
leaq 0xb5a3a(%rip), %rsi     # 0x39082f
movl $0x3d95, %edx           # imm = 0x3D95
leaq 0xb8e33(%rip), %rcx     # 0x393c34
callq 0x2130
jmp 0x2dae08
cmpq $0x0, -0x48(%rbp)
jl 0x2daf14
movq -0x10(%rbp), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
shll %eax
sarl %eax
cltq
cmpq -0x38(%rbp), %rax
je 0x2dae33
jmp 0x2daf14
movq -0x10(%rbp), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, %eax
movq -0x30(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
cmpq %rcx, %rax
jne 0x2dae61
jmp 0x2dae80
leaq 0xb8e0e(%rip), %rdi     # 0x393c76
leaq 0xb59c0(%rip), %rsi     # 0x39082f
movl $0x3d9a, %edx           # imm = 0x3D9A
leaq 0xb8db9(%rip), %rcx     # 0x393c34
callq 0x2130
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x54(%rbp)
movq -0x40(%rbp), %rax
movl %eax, -0x50(%rbp)
movq -0x40(%rbp), %rax
leaq 0xea427(%rip), %rcx     # 0x3c52d0
movq 0x18(%rcx), %rcx
movq -0x30(%rbp), %rdx
movq 0x18(%rdx), %rdx
movq -0x38(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrq $0x21, %rdx
addq (%rcx,%rdx,8), %rax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rsi
imulq $0x28, -0x48(%rbp), %rax
addq %rax, %rsi
leaq -0x54(%rbp), %rdi
callq 0x2daa10
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2dae08
jmp 0x2dad61
jmp 0x2daf1b
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)