// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x1de4
leaq 0x1270(%rip), %rdi      # 0x302e
leaq 0x127f(%rip), %rsi      # 0x3044
leaq 0x1320(%rip), %rdx      # 0x30ec
movl $0xde, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2042
movq $0x0, -0x20(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2050
movq -0x10(%rbp), %rax
cmpl $0x0, 0x68(%rax)
jne 0x1e33
leaq 0x1221(%rip), %rdi      # 0x302e
leaq 0x1230(%rip), %rsi      # 0x3044
leaq 0x12d1(%rip), %rdx      # 0x30ec
movl $0xe6, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2042
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x1e73
leaq 0x11e1(%rip), %rdi      # 0x302e
leaq 0x11f0(%rip), %rsi      # 0x3044
leaq 0x1291(%rip), %rdx      # 0x30ec
movl $0xe9, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2042
movq -0x50(%rbp), %rax
movl $0x0, 0x48(%rax)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x68(%rcx), %eax
jge 0x1ec4
movq -0x10(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq 0x28(%rax,%rcx,8), %rdx
movq -0x50(%rbp), %rax
movq -0x50(%rbp), %rsi
movl 0x48(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x48(%rsi)
movslq %ecx, %rcx
movq %rdx, 0x8(%rax,%rcx,8)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1e85
movq -0x10(%rbp), %rdi
callq 0x2140
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x25d0
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl 0x48(%rcx), %eax
jge 0x1f18
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x50(%rbp), %rsi
addq $0x8, %rsi
movslq -0x58(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2430
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x1ee1
jmp 0x1f1a
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x2510
cmpl $-0x2, %eax
je 0x203b
movl $0x0, -0x44(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x48(%rcx), %eax
jge 0x1fb6
movq -0x20(%rbp), %rax
movslq -0x5c(%rbp), %rcx
cmpq $0x0, 0x8(%rax,%rcx,8)
jne 0x1f8b
leaq 0x10c9(%rip), %rdi      # 0x302e
leaq 0x10d8(%rip), %rsi      # 0x3044
leaq 0x1179(%rip), %rdx      # 0x30ec
movl $0xfc, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2042
movq -0x20(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movl (%rax), %ecx
movl -0x44(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x44(%rbp)
cltq
movl %ecx, -0x40(%rbp,%rax,4)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1f42
cmpq $0x0, -0x18(%rbp)
je 0x1fd8
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x70(%rcx), %rdi
movq -0x20(%rbp), %rcx
movl (%rcx), %esi
leaq -0x40(%rbp), %rdx
movl -0x44(%rbp), %ecx
callq *%rax
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x90(%rcx), %eax
jge 0x2036
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movq 0x50(%rax,%rcx,8), %rcx
movl 0x4c(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x4c(%rcx)
cmpl $0x0, %eax
jne 0x2029
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x50, %rsi
movslq -0x60(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2430
jmp 0x202b
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1fdf
jmp 0x1f1a
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)