// File: chhylp123[P]hifiasm/inter.cpp
// Function: debug_intermediate_chain(ma_ug_t*, mg_lchain_t*, long, long, long)
void debug_intermediate_chain(ma_ug_t *ug, mg_lchain_t *a, int64_t a_n, int64_t is_uovlp, int64_t debug_i)
{
	int64_t k; mg_lchain_t *p, *c;
	int64_t prs, pre, pqs, pqe, crs, cre, cqs, cqe;
	int64_t tot = 0, fal = 0;
	for (k = a_n-1; k >= 0; k--) {
		c = &(a[k]); 
		if(c->v!=(uint32_t)-1) {
			fprintf(stderr, "+(%ld) [M::utg%.6u%c::%c] qs:%d, qe:%d, rs:%d, re:%d, off:%d\n", k, (c->v>>1)+1, "lc"[ug->u.a[c->v>>1].circ], "+-"[c->v&1],
			c->qs, c->qe, c->rs, c->re, c->off);
		}
		
		
		if(c->hash_pre != (uint32_t)-1) {
			p = &(a[c->hash_pre]); tot++;
			if(is_uovlp) {
				get_u_offset(ug, p, &prs, &pre, &pqs, &pqe);
			} else {
				get_r_offset(ug, p, &prs, &pre, &pqs, &pqe);
			}
			if(is_uovlp) {
				get_u_offset(ug, c, &crs, &cre, &cqs, &cqe);
			} else {
				get_r_offset(ug, c, &crs, &cre, &cqs, &cqe);
			}

			fprintf(stderr, "cur (%ld) [M::utg%.6u%c::%c] qs:%ld, qe:%ld, rs:%ld, re:%ld, pidx:%u\n", 
			k, (c->v>>1)+1, "lc"[ug->u.a[c->v>>1].circ], "+-"[c->v&1], cqs, cqe, crs, cre, c->hash_pre);

			fprintf(stderr, "pre (%ld) [M::utg%.6u%c::%c] qs:%ld, qe:%ld, rs:%ld, re:%ld, pidx:%u\n", 
			k, (p->v>>1)+1, "lc"[ug->u.a[p->v>>1].circ], "+-"[p->v&1], pqs, pqe, prs, pre, p->hash_pre);
			
			if((!(prs<=crs&&pre<=cre&&pqs<=cqs&&pqe<=cqe)) || (!(prs<=pre&&pqs<=pqe&&crs<=cre&&cqs<=cqe))) {
				fal++;
				// fprintf(stderr, "[M::%s::a_n->%ld, k->%ld]p->dist_pre:%d, c->dist_pre:%d, c->pre_idx:%u\n", __func__, a_n, k, p->dist_pre, c->dist_pre, c->hash_pre);
				// fprintf(stderr, "[M::%s::]prs->%ld, pre->%ld, pqs->%ld, pqe->%ld, crs->%ld, cre->%ld, cqs->%ld, cqe->%ld\n", 
				// __func__, prs, pre, pqs, pqe, crs, cre, cqs, cqe);
			}
			assert(prs<=pre&&pqs<=pqe&&crs<=cre&&cqs<=cqe);
			// assert(prs<=crs&&pre<=cre&&pqs<=cqs&&pqe<=cqe);
		}
	}	
	if(fal) fprintf(stderr, "[M::%s::tot->%ld, fal->%ld] ulid->%ld\n", __func__, tot, fal, debug_i);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xc0, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq $0x0, -0x98(%rbp)
movq $0x0, -0xa0(%rbp)
movq -0x28(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jl 0x29a092
movq -0x20(%rbp), %rax
imulq $0x28, -0x40(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpl $-0x1, 0x8(%rax)
je 0x299d89
movq 0x12a2fc(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x40(%rbp), %rdx
movq -0x50(%rbp), %rax
movl 0x8(%rax), %ecx
shrl %ecx
addl $0x1, %ecx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rsi
movl 0x8(%rsi), %esi
shrl %esi
movl %esi, %esi
imulq $0x28, %rsi, %rsi
addq %rsi, %rax
movl (%rax), %eax
shrl $0x1f, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0xeb5e2(%rip), %rax     # 0x385303
movsbl (%rax,%rsi), %r8d
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0xe9160(%rip), %rax     # 0x382e9b
movsbl (%rax,%rsi), %r9d
movq -0x50(%rbp), %rax
movl 0x14(%rax), %r14d
movq -0x50(%rbp), %rax
movl 0x18(%rax), %ebx
movq -0x50(%rbp), %rax
movl 0xc(%rax), %r11d
movq -0x50(%rbp), %rax
movl 0x10(%rax), %r10d
movq -0x50(%rbp), %rax
movl (%rax), %eax
leaq 0xf7a91(%rip), %rsi     # 0x3917fd
movl %r14d, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movb $0x0, %al
callq 0x22a0
movq -0x50(%rbp), %rax
cmpl $-0x1, 0x24(%rax)
je 0x29a07f
movq -0x20(%rbp), %rax
movq -0x50(%rbp), %rcx
movl 0x24(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x299de5
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq -0x58(%rbp), %rdx
leaq -0x60(%rbp), %rcx
leaq -0x68(%rbp), %r8
leaq -0x70(%rbp), %r9
callq 0x2985f0
jmp 0x299e02
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq -0x58(%rbp), %rdx
leaq -0x60(%rbp), %rcx
leaq -0x68(%rbp), %r8
leaq -0x70(%rbp), %r9
callq 0x2984d0
cmpq $0x0, -0x30(%rbp)
je 0x299e2e
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq -0x78(%rbp), %rdx
leaq -0x80(%rbp), %rcx
leaq -0x88(%rbp), %r8
leaq -0x90(%rbp), %r9
callq 0x2985f0
jmp 0x299e51
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq -0x78(%rbp), %rdx
leaq -0x80(%rbp), %rcx
leaq -0x88(%rbp), %r8
leaq -0x90(%rbp), %r9
callq 0x2984d0
movq 0x12a188(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x40(%rbp), %rdx
movq -0x50(%rbp), %rax
movl 0x8(%rax), %ecx
shrl %ecx
addl $0x1, %ecx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rsi
movl 0x8(%rsi), %esi
shrl %esi
movl %esi, %esi
imulq $0x28, %rsi, %rsi
addq %rsi, %rax
movl (%rax), %eax
shrl $0x1f, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0xeb46e(%rip), %rax     # 0x385303
movsbl (%rax,%rsi), %r8d
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0xe8fec(%rip), %rax     # 0x382e9b
movsbl (%rax,%rsi), %r9d
movq -0x88(%rbp), %r14
movq -0x90(%rbp), %rbx
movq -0x78(%rbp), %r11
movq -0x80(%rbp), %r10
movq -0x50(%rbp), %rax
movl 0x24(%rax), %eax
leaq 0xf7963(%rip), %rsi     # 0x39183b
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movb $0x0, %al
callq 0x22a0
movq 0x12a0e3(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rax
movl 0x8(%rax), %ecx
shrl %ecx
addl $0x1, %ecx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rsi
movl 0x8(%rsi), %esi
shrl %esi
movl %esi, %esi
imulq $0x28, %rsi, %rsi
addq %rsi, %rax
movl (%rax), %eax
shrl $0x1f, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0xeb3c9(%rip), %rax     # 0x385303
movsbl (%rax,%rsi), %r8d
movq -0x48(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0xe8f47(%rip), %rax     # 0x382e9b
movsbl (%rax,%rsi), %r9d
movq -0x68(%rbp), %r14
movq -0x70(%rbp), %rbx
movq -0x58(%rbp), %r11
movq -0x60(%rbp), %r10
movq -0x48(%rbp), %rax
movl 0x24(%rax), %eax
leaq 0xf790a(%rip), %rsi     # 0x391881
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movb $0x0, %al
callq 0x22a0
movq -0x58(%rbp), %rax
cmpq -0x78(%rbp), %rax
jg 0x299ff1
movq -0x60(%rbp), %rax
cmpq -0x80(%rbp), %rax
jg 0x299ff1
movq -0x68(%rbp), %rax
cmpq -0x88(%rbp), %rax
jg 0x299ff1
movq -0x70(%rbp), %rax
cmpq -0x90(%rbp), %rax
jg 0x299ff1
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
jg 0x299ff1
movq -0x68(%rbp), %rax
cmpq -0x70(%rbp), %rax
jg 0x299ff1
movq -0x78(%rbp), %rax
cmpq -0x80(%rbp), %rax
jg 0x299ff1
movq -0x88(%rbp), %rax
cmpq -0x90(%rbp), %rax
jle 0x29a003
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
movq -0x58(%rbp), %rcx
xorl %eax, %eax
cmpq -0x60(%rbp), %rcx
movb %al, -0xa1(%rbp)
jg 0x29a050
movq -0x68(%rbp), %rcx
xorl %eax, %eax
cmpq -0x70(%rbp), %rcx
movb %al, -0xa1(%rbp)
jg 0x29a050
movq -0x78(%rbp), %rcx
xorl %eax, %eax
cmpq -0x80(%rbp), %rcx
movb %al, -0xa1(%rbp)
jg 0x29a050
movq -0x88(%rbp), %rax
cmpq -0x90(%rbp), %rax
setle %al
movb %al, -0xa1(%rbp)
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0x29a05c
jmp 0x29a05e
jmp 0x29a07d
leaq 0xf7862(%rip), %rdi     # 0x3918c7
leaq 0xf67c3(%rip), %rsi     # 0x39082f
movl $0x1286, %edx           # imm = 0x1286
leaq 0xf7876(%rip), %rcx     # 0x3918ee
callq 0x2130
jmp 0x29a07f
jmp 0x29a081
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x299cb4
cmpq $0x0, -0xa0(%rbp)
je 0x29a0cd
movq 0x129f3d(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x98(%rbp), %rcx
movq -0xa0(%rbp), %r8
movq -0x38(%rbp), %r9
leaq 0xf7882(%rip), %rsi     # 0x391941
leaq 0xf78a2(%rip), %rdx     # 0x391968
movb $0x0, %al
callq 0x22a0
addq $0xc0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax)