// File: /workspace/github_c_makefile_star2_O3/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
leaq 0x80(%rdi), %rax
movq 0x80(%rdi), %rcx
cmpq %rax, %rcx
je 0x169d
movl -0x8(%rcx), %edx
movl %edx, -0x4(%rcx)
movq (%rcx), %rcx
jmp 0x168d
movq 0x18(%r14), %rdi
callq 0x1d2c
testq %r12, %r12
je 0x17b7
testq %rbx, %rbx
je 0x16c2
movq 0x70(%r14), %rdi
movl (%r12), %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq *%rbx
cmpl $0x0, 0x48(%r12)
jle 0x16ef
leaq 0x8(%r12), %r15
xorl %r13d, %r13d
movq 0x18(%r14), %rdi
movq %r15, %rsi
callq 0x1c55
incq %r13
movslq 0x48(%r12), %rax
addq $0x8, %r15
cmpq %rax, %r13
jl 0x16d2
movq 0x18(%r14), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1cc9
movl %eax, %ecx
xorl %eax, %eax
cmpl $-0x2, %ecx
je 0x17f9
leaq 0x8(%rsp), %r15
leaq 0x10(%rsp), %r12
movq 0x8(%rsp), %rsi
cmpl $0x0, 0x90(%rsi)
movl $0x0, %ecx
jle 0x174c
xorl %ecx, %ecx
movq 0x50(%rsi,%rcx,8), %rax
testq %rax, %rax
je 0x17d3
movl (%rax), %eax
movl %eax, 0x10(%rsp,%rcx,4)
incq %rcx
movslq 0x90(%rsi), %rax
cmpq %rax, %rcx
jl 0x1729
testq %rbx, %rbx
je 0x1761
movq 0x70(%r14), %rdi
movl (%rsi), %esi
movq %r12, %rdx
callq *%rbx
movq 0x8(%rsp), %rsi
cmpl $0x0, 0x48(%rsi)
jle 0x179c
movl $0x8, %r13d
xorl %ebp, %ebp
movq (%rsi,%r13), %rax
decl 0x94(%rax)
jne 0x178c
addq %r13, %rsi
movq 0x18(%r14), %rdi
callq 0x1c55
movq 0x8(%rsp), %rsi
incq %rbp
movslq 0x48(%rsi), %rax
addq $0x8, %r13
cmpq %rax, %rbp
jl 0x176f
movq 0x18(%r14), %rdi
movq %r15, %rsi
callq 0x1cc9
movl %eax, %ecx
xorl %eax, %eax
cmpl $-0x2, %ecx
jne 0x1714
jmp 0x17f9
leaq 0x942(%rip), %rdi       # 0x2100
leaq 0x951(%rip), %rsi       # 0x2116
leaq 0x9ae(%rip), %rdx       # 0x217a
movl $0xa0, %ecx
jmp 0x17ed
leaq 0x926(%rip), %rdi       # 0x2100
leaq 0x935(%rip), %rsi       # 0x2116
leaq 0x992(%rip), %rdx       # 0x217a
movl $0xac, %ecx
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