// File: /workspace/github_c_makefile_star2_O1/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 0x1a39
movq %rsi, %rbx
movq %rdi, %r14
movq $0x0, 0x8(%rsp)
movl $0x0, 0x68(%rdi)
leaq 0x80(%rdi), %rax
movq 0x80(%rdi), %rcx
cmpq %rax, %rcx
je 0x19d6
cmpl $0x0, -0x50(%rcx)
jne 0x19d1
leaq -0x98(%rcx), %rdx
movslq 0x68(%r14), %rsi
leal 0x1(%rsi), %edi
movl %edi, 0x68(%r14)
movq %rdx, 0x28(%r14,%rsi,8)
movq (%rcx), %rcx
jmp 0x19af
movl 0x68(%r14), %ecx
testq %rcx, %rcx
je 0x1b58
movq 0x78(%r14), %r12
testq %r12, %r12
je 0x1b5f
movl $0x0, 0x48(%r12)
testl %ecx, %ecx
jle 0x1a26
movslq 0x48(%r12), %rsi
movl %esi, %edx
leaq (%r12,%rsi,8), %rdi
addq $0x8, %rdi
xorl %esi, %esi
movq 0x28(%r14,%rsi,8), %r8
movq %r8, (%rdi,%rsi,8)
incq %rsi
cmpq %rsi, %rcx
jne 0x1a0e
addl %esi, %edx
movl %edx, 0x48(%r12)
movq (%rax), %rcx
cmpq %rax, %rcx
je 0x1a58
movl -0x50(%rcx), %edx
movl %edx, -0x4c(%rcx)
movq (%rcx), %rcx
jmp 0x1a29
leaq 0x6c0(%rip), %rdi       # 0x2100
leaq 0x6cf(%rip), %rsi       # 0x2116
leaq 0x75c(%rip), %rdx       # 0x21aa
movl $0xde, %ecx
jmp 0x1b80
movq 0x20(%r14), %rdi
callq 0x1d78
cmpl $0x0, 0x48(%r12)
jle 0x1a8e
leaq 0x8(%r12), %r15
xorl %r13d, %r13d
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x1ca1
incq %r13
movslq 0x48(%r12), %rax
addq $0x8, %r15
cmpq %rax, %r13
jl 0x1a71
movq 0x20(%r14), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1d13
movl %eax, %ecx
xorl %eax, %eax
cmpl $-0x2, %ecx
je 0x1b8c
leaq 0x8(%rsp), %r15
leaq 0x10(%rsp), %r12
movq 0x8(%rsp), %rax
cmpl $0x0, 0x48(%rax)
movl $0x0, %ecx
jle 0x1ae5
xorl %ecx, %ecx
movq 0x8(%rax,%rcx,8), %rdx
testq %rdx, %rdx
je 0x1b66
movl (%rdx), %edx
movl %edx, 0x10(%rsp,%rcx,4)
incq %rcx
movslq 0x48(%rax), %rdx
cmpq %rdx, %rcx
jl 0x1ac5
testq %rbx, %rbx
je 0x1afa
movq 0x70(%r14), %rdi
movq 0x8(%rsp), %rax
movl (%rax), %esi
movq %r12, %rdx
callq *%rbx
movq 0x8(%rsp), %rsi
cmpl $0x0, 0x90(%rsi)
jle 0x1b3d
movl $0x50, %r13d
xorl %ebp, %ebp
movq (%rsi,%r13), %rax
decl 0x4c(%rax)
jne 0x1b25
addq %r13, %rsi
movq 0x20(%r14), %rdi
callq 0x1ca1
incq %rbp
movq 0x8(%rsp), %rsi
movslq 0x90(%rsi), %rax
addq $0x8, %r13
cmpq %rax, %rbp
jl 0x1b10
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x1d13
movl %eax, %ecx
xorl %eax, %eax
cmpl $-0x2, %ecx
jne 0x1ab3
jmp 0x1b8c
movl $0xe6, %ecx
jmp 0x1b6b
movl $0xe9, %ecx
jmp 0x1b6b
movl $0xfc, %ecx
leaq 0x58e(%rip), %rdi       # 0x2100
leaq 0x59d(%rip), %rsi       # 0x2116
leaq 0x62a(%rip), %rdx       # 0x21aa
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
nop