// File: /workspace/github_c_makefile_star2_O3/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 0x19e0
movq %rdi, %r14
movq $0x0, 0x8(%rsp)
movl $0x0, 0x68(%rdi)
leaq 0x80(%rdi), %rax
movq 0x80(%rdi), %rdx
cmpq %rax, %rdx
je 0x19c4
movq %rsi, %rbx
xorl %ecx, %ecx
cmpl $0x0, -0x50(%rdx)
jne 0x1970
leaq -0x98(%rdx), %rsi
movslq %ecx, %rdi
incl %ecx
movl %ecx, 0x68(%r14)
movq %rsi, 0x28(%r14,%rdi,8)
movq (%rdx), %rdx
cmpq %rax, %rdx
jne 0x1955
testl %ecx, %ecx
je 0x19c4
movq 0x78(%r14), %r12
testq %r12, %r12
je 0x1b0f
movl $0x0, 0x48(%r12)
testl %ecx, %ecx
jle 0x19b1
movl %ecx, %edx
xorl %ecx, %ecx
movq 0x28(%r14,%rcx,8), %rsi
movq %rsi, 0x8(%r12,%rcx,8)
incq %rcx
cmpq %rcx, %rdx
jne 0x199a
movl %ecx, 0x48(%r12)
movq (%rax), %rcx
cmpq %rax, %rcx
je 0x1a15
movl -0x50(%rcx), %edx
movl %edx, -0x4c(%rcx)
movq (%rcx), %rcx
jmp 0x19b4
leaq 0x735(%rip), %rdi       # 0x2100
leaq 0x744(%rip), %rsi       # 0x2116
leaq 0x7d1(%rip), %rdx       # 0x21aa
movl $0xe6, %ecx
jmp 0x19fa
leaq 0x719(%rip), %rdi       # 0x2100
leaq 0x728(%rip), %rsi       # 0x2116
leaq 0x7b5(%rip), %rdx       # 0x21aa
movl $0xde, %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
movq 0x20(%r14), %rdi
callq 0x1d2c
cmpl $0x0, 0x48(%r12)
jle 0x1a4b
leaq 0x8(%r12), %r15
xorl %r13d, %r13d
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x1c55
incq %r13
movslq 0x48(%r12), %rax
addq $0x8, %r15
cmpq %rax, %r13
jl 0x1a2e
movq 0x20(%r14), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1cc9
movl %eax, %ecx
xorl %eax, %eax
cmpl $-0x2, %ecx
je 0x1a06
leaq 0x8(%rsp), %r15
leaq 0x10(%rsp), %r12
movq 0x8(%rsp), %rsi
cmpl $0x0, 0x48(%rsi)
movl $0x0, %ecx
jle 0x1a9e
xorl %ecx, %ecx
movq 0x8(%rsi,%rcx,8), %rax
testq %rax, %rax
je 0x1b2e
movl (%rax), %eax
movl %eax, 0x10(%rsp,%rcx,4)
incq %rcx
movslq 0x48(%rsi), %rax
cmpq %rax, %rcx
jl 0x1a7e
testq %rbx, %rbx
je 0x1ab3
movq 0x70(%r14), %rdi
movl (%rsi), %esi
movq %r12, %rdx
callq *%rbx
movq 0x8(%rsp), %rsi
cmpl $0x0, 0x90(%rsi)
jle 0x1af1
movl $0x50, %r13d
xorl %ebp, %ebp
movq (%rsi,%r13), %rax
decl 0x4c(%rax)
jne 0x1ade
addq %r13, %rsi
movq 0x20(%r14), %rdi
callq 0x1c55
movq 0x8(%rsp), %rsi
incq %rbp
movslq 0x90(%rsi), %rax
addq $0x8, %r13
cmpq %rax, %rbp
jl 0x1ac4
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x1cc9
movl %eax, %ecx
xorl %eax, %eax
cmpl $-0x2, %ecx
jne 0x1a6c
jmp 0x1a06
leaq 0x5ea(%rip), %rdi       # 0x2100
leaq 0x5f9(%rip), %rsi       # 0x2116
leaq 0x686(%rip), %rdx       # 0x21aa
movl $0xe9, %ecx
jmp 0x19fa
leaq 0x5cb(%rip), %rdi       # 0x2100
leaq 0x5da(%rip), %rsi       # 0x2116
leaq 0x667(%rip), %rdx       # 0x21aa
movl $0xfc, %ecx
jmp 0x19fa
nopl (%rax)