// File: /workspace/github_c_makefile_star2_O1/xtanitfy[P]Murphy/src/muti_tree.c
// Function: MTREE_forward
int MTREE_forward(MTREE_s *pTree,int (*callback)(void *usr,int idCurr,int *_idPrev,int _nIdPrev))
{
	MTREE_ITEM_s *pItemTmp = NULL;
	MTREE_ITEM_s *pRoot = pTree->root;
	int idPrev[MTREE_MAX_MUX];
	int nIdPrev = 0;

	/*syncPrev ��Ҫ��������*/
	//MTREEResetSyncNext(pTree);
	MTREEResetSyncPrev(pTree);
	
	QUEUE_reset(pTree->pQForward);

	CHECK_EXPR_RET(pRoot == NULL,-1);
	if (callback != NULL) {
		callback(pTree->usr,pRoot->valCurr,NULL,0);
	}
	
	//printf("curr:%d \n",pRoot->valCurr);
	for (int i = 0;i < pRoot->nNext;i++) {
		QUEUE_enqueue(pTree->pQForward,&pRoot->next[i]);
	}
	while(QUEUE_dequeue(pTree->pQForward,&pItemTmp) != QUEUE_EMPTY) {
		nIdPrev = 0;
		for (int i = 0;i < pItemTmp->nPrev;i++) {
			CHECK_EXPR_RET(pItemTmp->prev[i] == NULL,-1);
			idPrev[nIdPrev++] = pItemTmp->prev[i]->valCurr;
		}
		if (callback != NULL) {
			callback(pTree->usr,pItemTmp->valCurr,idPrev,nIdPrev);
		}
		for (int i = 0;i < pItemTmp->nNext;i++) {
			if (--pItemTmp->next[i]->syncPrev == 0) {
				QUEUE_enqueue(pTree->pQForward,&pItemTmp->next[i]);
			}
		}
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq $0x0, 0x8(%rsp)
movq 0x8(%rdi), %r12
testq %rdi, %rdi
je 0x16ed
leaq 0x80(%r14), %rax
movq 0x80(%r14), %rcx
cmpq %rax, %rcx
je 0x170e
movl -0x8(%rcx), %edx
movl %edx, -0x4(%rcx)
movq (%rcx), %rcx
jmp 0x16dd
leaq 0xa0c(%rip), %rdi       # 0x2100
leaq 0xa1b(%rip), %rsi       # 0x2116
leaq 0xab7(%rip), %rdx       # 0x21b9
movl $0x87, %ecx
xorl %eax, %eax
callq 0x1030
movq 0x18(%r14), %rdi
callq 0x1d78
testq %r12, %r12
je 0x182d
testq %rbx, %rbx
je 0x1733
movq 0x70(%r14), %rdi
movl (%r12), %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq *%rbx
cmpl $0x0, 0x48(%r12)
jle 0x1760
leaq 0x8(%r12), %r15
xorl %r13d, %r13d
movq 0x18(%r14), %rdi
movq %r15, %rsi
callq 0x1ca1
incq %r13
movslq 0x48(%r12), %rax
addq $0x8, %r15
cmpq %rax, %r13
jl 0x1743
movq 0x18(%r14), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1d13
movl %eax, %ecx
xorl %eax, %eax
cmpl $-0x2, %ecx
je 0x185a
leaq 0x8(%rsp), %r15
leaq 0x10(%rsp), %r12
movq 0x8(%rsp), %rax
cmpl $0x0, 0x90(%rax)
movl $0x0, %ecx
jle 0x17bd
xorl %ecx, %ecx
movq 0x50(%rax,%rcx,8), %rdx
testq %rdx, %rdx
je 0x1834
movl (%rdx), %edx
movl %edx, 0x10(%rsp,%rcx,4)
incq %rcx
movslq 0x90(%rax), %rdx
cmpq %rdx, %rcx
jl 0x179a
testq %rbx, %rbx
je 0x17d2
movq 0x70(%r14), %rdi
movq 0x8(%rsp), %rax
movl (%rax), %esi
movq %r12, %rdx
callq *%rbx
movq 0x8(%rsp), %rsi
cmpl $0x0, 0x48(%rsi)
jle 0x1812
movl $0x8, %r13d
xorl %ebp, %ebp
movq (%rsi,%r13), %rax
decl 0x94(%rax)
jne 0x17fd
addq %r13, %rsi
movq 0x18(%r14), %rdi
callq 0x1ca1
incq %rbp
movq 0x8(%rsp), %rsi
movslq 0x48(%rsi), %rax
addq $0x8, %r13
cmpq %rax, %rbp
jl 0x17e5
movq 0x18(%r14), %rdi
movq %r15, %rsi
callq 0x1d13
movl %eax, %ecx
xorl %eax, %eax
cmpl $-0x2, %ecx
jne 0x1785
jmp 0x185a
movl $0xa0, %ecx
jmp 0x1839
movl $0xac, %ecx
leaq 0x8c0(%rip), %rdi       # 0x2100
leaq 0x8cf(%rip), %rsi       # 0x2116
leaq 0x92c(%rip), %rdx       # 0x217a
xorl %eax, %eax
callq 0x1030
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq