// File: /workspace/github_c_makefile_star2_O2/xtanitfy[P]Murphy/src/muti_tree.c
// Function: MTREE_backward
int MTREE_backward(MTREE_s *pTree,int (*callback)(void *usr,int idCurr,int *_idNext,int _nIdNext))
{
	CHECK_EXPR_RET(pTree == NULL,-1);

	MTREE_ITEM_s *pItemTmp = NULL;
	int idNext[MTREE_MAX_MUX];
	int nIdNext = 0;

	/*Need only run once after adding all items!*/
	MTREECalEndInfo(pTree);
	CHECK_EXPR_RET(pTree->nEnd == 0,-1);

	MTREE_ITEM_s *pRoot = pTree->rootInverse;
	CHECK_EXPR_RET(pRoot == NULL,-1);
	
	/*����һ���µ�root �������е�end*/
	pRoot->nNext = 0;
	for (int i = 0;i < pTree->nEnd;i++) {
		pRoot->next[pRoot->nNext++] = pTree->pEnd[i];
	}

	/*syncPrev ��Ҫ��������*/
	MTREEResetSyncNext(pTree);
	//MTREEResetSyncPrev(pTree);

	QUEUE_reset(pTree->pQBackward);
	for (int i = 0;i < pRoot->nNext;i++) {
		QUEUE_enqueue(pTree->pQBackward,&pRoot->next[i]);
	}
	while(QUEUE_dequeue(pTree->pQBackward,&pItemTmp) != QUEUE_EMPTY) {
		nIdNext = 0;
		for (int i = 0;i < pItemTmp->nNext;i++) {
			CHECK_EXPR_RET(pItemTmp->next[i] == NULL,-1);
			idNext[nIdNext++] = pItemTmp->next[i]->valCurr;
		}
		if (callback != NULL) {
			callback(pTree->usr,pItemTmp->valCurr,idNext,nIdNext);
		}
		for (int i = 0;i < pItemTmp->nPrev;i++) {
			if (--pItemTmp->prev[i]->syncNext == 0) {
				QUEUE_enqueue(pTree->pQBackward,&pItemTmp->prev[i]);
			}
		}
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
testq %rdi, %rdi
je 0x18dc
movq %rsi, %rbx
movq %rdi, %r14
andq $0x0, 0x8(%rsp)
andl $0x0, 0x68(%rdi)
leaq 0x80(%rdi), %rax
xorl %ecx, %ecx
movq %rax, %rdx
movq (%rdx), %rdx
cmpq %rax, %rdx
je 0x18a1
cmpl $0x0, -0x50(%rdx)
jne 0x187c
leaq -0x98(%rdx), %rsi
movl %ecx, %edi
incq %rcx
movl %ecx, 0x68(%r14)
movq %rsi, 0x28(%r14,%rdi,8)
jmp 0x187c
testl %ecx, %ecx
je 0x19c7
movq 0x78(%r14), %r12
testq %r12, %r12
je 0x19ff
andl $0x0, 0x48(%r12)
leaq 0x8(%r12), %r15
xorl %edx, %edx
xorl %esi, %esi
subq $0x1, %rcx
jb 0x18fb
movq 0x28(%r14,%rdx), %rdi
incl %esi
movq %rdi, (%r15,%rdx)
addq $0x8, %rdx
jmp 0x18c5
leaq 0x81d(%rip), %rdi       # 0x2100
leaq 0x82c(%rip), %rsi       # 0x2116
leaq 0x8b9(%rip), %rdx       # 0x21aa
movl $0xde, %ecx
jmp 0x1a19
movl %esi, 0x48(%r12)
movq %rax, %rcx
movq (%rcx), %rcx
cmpq %rax, %rcx
je 0x1913
movl -0x50(%rcx), %edx
movl %edx, -0x4c(%rcx)
jmp 0x1903
movq 0x20(%r14), %rdi
callq 0x1bfc
xorl %r13d, %r13d
movslq 0x48(%r12), %rax
cmpq %rax, %r13
jge 0x193e
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x1b31
incq %r13
addq $0x8, %r15
jmp 0x191f
leaq 0x8(%rsp), %r12
xorl %r15d, %r15d
movq 0x20(%r14), %rdi
movq %r12, %rsi
callq 0x1b9e
cmpl $-0x2, %eax
je 0x1a24
movq 0x8(%rsp), %rax
xorl %ecx, %ecx
movslq 0x48(%rax), %rdx
cmpq %rdx, %rcx
jge 0x1980
movq 0x8(%rax,%rcx,8), %rdx
testq %rdx, %rdx
je 0x19e3
movl (%rdx), %edx
movl %edx, 0x10(%rsp,%rcx,4)
incq %rcx
jmp 0x1962
testq %rbx, %rbx
je 0x1992
movq 0x70(%r14), %rdi
movl (%rax), %esi
leaq 0x10(%rsp), %rdx
callq *%rbx
pushq $0x50
popq %rbp
xorl %r13d, %r13d
movq 0x8(%rsp), %rsi
movslq 0x90(%rsi), %rax
cmpq %rax, %r13
jge 0x1946
movq (%rsi,%rbp), %rax
decl 0x4c(%rax)
jne 0x19be
addq %rbp, %rsi
movq 0x20(%r14), %rdi
callq 0x1b31
incq %r13
addq $0x8, %rbp
jmp 0x1998
leaq 0x732(%rip), %rdi       # 0x2100
leaq 0x741(%rip), %rsi       # 0x2116
leaq 0x7ce(%rip), %rdx       # 0x21aa
movl $0xe6, %ecx
jmp 0x1a19
leaq 0x716(%rip), %rdi       # 0x2100
leaq 0x725(%rip), %rsi       # 0x2116
leaq 0x7b2(%rip), %rdx       # 0x21aa
movl $0xfc, %ecx
jmp 0x1a19
leaq 0x6fa(%rip), %rdi       # 0x2100
leaq 0x709(%rip), %rsi       # 0x2116
leaq 0x796(%rip), %rdx       # 0x21aa
movl $0xe9, %ecx
xorl %eax, %eax
callq 0x1030
pushq $-0x1
popq %r15
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop