// File: /workspace/github_cpp_makefile_star2_O1/rilutham[P]gotojakarta/./stlastar.h
// Function: AStarSearch<PathSearchNode>::SearchStep()
unsigned int SearchStep()
	{
		// Firstly break if the user has not initialised the search
		assert( (m_State > SEARCH_STATE_NOT_INITIALISED) &&
				(m_State < SEARCH_STATE_INVALID) );

		// Next I want it to be safe to do a searchstep once the search has succeeded...
		if( (m_State == SEARCH_STATE_SUCCEEDED) ||
			(m_State == SEARCH_STATE_FAILED) 
		  )
		{
			return m_State; 
		}

		// Failure is defined as emptying the open list as there is nothing left to 
		// search...
		// New: Allow user abort
		if( m_OpenList.empty() || m_CancelRequest )
		{
			FreeAllNodes();
			m_State = SEARCH_STATE_FAILED;
			return m_State;
		}
		
		// Incremement step count
		m_Steps ++;

		// Pop the best node (the one with the lowest f) 
		Node *n = m_OpenList.front(); // get pointer to the node
		pop_heap( m_OpenList.begin(), m_OpenList.end(), HeapCompare_f() );
		m_OpenList.pop_back();

		// Check for the goal, once we pop that we're done
		if( n->m_UserState.IsGoal( m_Goal->m_UserState ) )
		{
			// The user is going to use the Goal Node he passed in 
			// so copy the parent pointer of n 
			m_Goal->parent = n->parent;
			m_Goal->g = n->g;

			// A special case is that the goal was passed in as the start state
			// so handle that here
			if( false == n->m_UserState.IsSameState( m_Start->m_UserState ) )
			{
				FreeNode( n );

				// set the child pointers in each node (except Goal which has no child)
				Node *nodeChild = m_Goal;
				Node *nodeParent = m_Goal->parent;

				do 
				{
					nodeParent->child = nodeChild;

					nodeChild = nodeParent;
					nodeParent = nodeParent->parent;
				
				} 
				while( nodeChild != m_Start ); // Start is always the first node by definition

			}

			// delete nodes that aren't needed for the solution
			FreeUnusedNodes();

			m_State = SEARCH_STATE_SUCCEEDED;

			return m_State;
		}
		else // not goal
		{

			// We now need to generate the successors of this node
			// The user helps us to do this, and we keep the new nodes in
			// m_Successors ...

			m_Successors.clear(); // empty vector of successor nodes to n

			// User provides this functions and uses AddSuccessor to add each successor of
			// node 'n' to m_Successors
			bool ret = n->m_UserState.GetSuccessors( this, n->parent ? &n->parent->m_UserState : NULL ); 

			if( !ret )
			{

			    typename vector< Node * >::iterator successor;

				// free the nodes that may previously have been added 
				for( successor = m_Successors.begin(); successor != m_Successors.end(); successor ++ )
				{
					FreeNode( (*successor) );
				}

				m_Successors.clear(); // empty vector of successor nodes to n

				// free up everything else we allocated
				FreeAllNodes();

				m_State = SEARCH_STATE_OUT_OF_MEMORY;
				return m_State;
			}
			
			// Now handle each successor to the current node ...
			for( typename vector< Node * >::iterator successor = m_Successors.begin(); successor != m_Successors.end(); successor ++ )
			{

				// 	The g value for this successor ...
				float newg = n->g + n->m_UserState.GetCost( (*successor)->m_UserState );

				// Now we need to find whether the node is on the open or closed lists
				// If it is but the node that is already on them is better (lower g)
				// then we can forget about this successor

				// First linear search of open list to find node

				typename vector< Node * >::iterator openlist_result;

				for( openlist_result = m_OpenList.begin(); openlist_result != m_OpenList.end(); openlist_result ++ )
				{
					if( (*openlist_result)->m_UserState.IsSameState( (*successor)->m_UserState ) )
					{
						break;					
					}
				}

				if( openlist_result != m_OpenList.end() )
				{

					// we found this state on open

					if( (*openlist_result)->g <= newg )
					{
						FreeNode( (*successor) );

						// the one on Open is cheaper than this one
						continue;
					}
				}

				typename vector< Node * >::iterator closedlist_result;

				for( closedlist_result = m_ClosedList.begin(); closedlist_result != m_ClosedList.end(); closedlist_result ++ )
				{
					if( (*closedlist_result)->m_UserState.IsSameState( (*successor)->m_UserState ) )
					{
						break;					
					}
				}

				if( closedlist_result != m_ClosedList.end() )
				{

					// we found this state on closed

					if( (*closedlist_result)->g <= newg )
					{
						// the one on Closed is cheaper than this one
						FreeNode( (*successor) );

						continue;
					}
				}

				// This node is the best node so far with this particular state
				// so lets keep it and set up its AStar specific data ...

				(*successor)->parent = n;
				(*successor)->g = newg;
				(*successor)->h = (*successor)->m_UserState.GoalDistanceEstimate( m_Goal->m_UserState );
				(*successor)->f = (*successor)->g + (*successor)->h;

				// Remove successor from closed if it was on it

				if( closedlist_result != m_ClosedList.end() )
				{
					// remove it from Closed
					FreeNode(  (*closedlist_result) ); 
					m_ClosedList.erase( closedlist_result );

					// Fix thanks to ...
					// Greg Douglas <gregdouglasmail@gmail.com>
					// who noticed that this code path was incorrect
					// Here we have found a new state which is already CLOSED
					// anus
					
				}

				// Update old version of this node
				if( openlist_result != m_OpenList.end() )
				{	   

					FreeNode( (*openlist_result) ); 
			   		m_OpenList.erase( openlist_result );

					// re-make the heap 
					// make_heap rather than sort_heap is an essential bug fix
					// thanks to Mike Ryynanen for pointing this out and then explaining
					// it in detail. sort_heap called on an invalid heap does not work
					make_heap( m_OpenList.begin(), m_OpenList.end(), HeapCompare_f() );
			
				}

				// heap now unsorted
				m_OpenList.push_back( (*successor) );

				// sort back element into heap
				push_heap( m_OpenList.begin(), m_OpenList.end(), HeapCompare_f() );

			}

			// push n onto Closed, as we have expanded it now

			m_ClosedList.push_back( n );

		} // end else (not goal so expand)

 		return m_State; // Succeeded bool is false at this point. 

	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x48(%rdi), %eax
leal -0x1(%rax), %ecx
cmpl $0x4, %ecx
jae 0x2327
movl %eax, %ecx
andl $0x6, %ecx
cmpl $0x2, %ecx
je 0x2028
movq %rdi, %rbx
movq (%rdi), %rdi
movq 0x8(%rbx), %rax
cmpq %rax, %rdi
je 0x2014
cmpb $0x1, 0x9c(%rbx)
jne 0x2037
movq %rbx, %rdi
callq 0x2660
movl $0x3, 0x48(%rbx)
movl $0x3, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incl 0x4c(%rbx)
movq (%rdi), %rcx
movq %rcx, -0x38(%rbp)
movq %rax, %rcx
subq %rdi, %rcx
cmpq $0x9, %rcx
jl 0x206a
leaq -0x8(%rax), %rdx
movq -0x8(%rax), %rcx
movq (%rdi), %rsi
movq %rsi, -0x8(%rax)
subq %rdi, %rdx
sarq $0x3, %rdx
xorl %esi, %esi
callq 0x27a0
addq $-0x8, 0x8(%rbx)
movq -0x38(%rbp), %rdi
cmpl $0x1, 0x1c(%rdi)
jne 0x20dc
movq 0x58(%rbx), %rax
movq (%rdi), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rsi
movss 0x10(%rsi), %xmm0
movss %xmm0, 0x10(%rax)
movq 0x50(%rbx), %rax
movl 0x1c(%rsi), %ecx
cmpl 0x1c(%rax), %ecx
je 0x20c3
decl 0x98(%rbx)
leaq 0x68(%rbx), %rdi
callq 0x2864
movq 0x50(%rbx), %rax
movq 0x58(%rbx), %rcx
movq (%rcx), %rdx
movq %rcx, 0x8(%rdx)
movq %rdx, %rcx
cmpq %rax, %rdx
jne 0x20b4
movq %rbx, %rdi
callq 0x2704
movl $0x2, 0x48(%rbx)
movl $0x2, %eax
jmp 0x2028
addq $0x1c, %rdi
movq 0x30(%rbx), %rax
cmpq %rax, 0x38(%rbx)
je 0x20ee
movq %rax, 0x38(%rbx)
movq %rbx, %rsi
callq 0x1410
movq 0x30(%rbx), %r14
cmpq 0x38(%rbx), %r14
je 0x22fa
leaq 0x68(%rbx), %r15
movq -0x38(%rbp), %rax
movss 0x10(%rax), %xmm0
movq (%r14), %rsi
movl 0x1c(%rax), %edx
movl 0x1c(%rsi), %ecx
imulq $0x54, %rdx, %rdx
leaq 0x2ffb(%rip), %rdi      # 0x5120
addq %rdi, %rdx
addss (%rdx,%rcx,4), %xmm0
movq (%rbx), %r13
movq 0x8(%rbx), %rdi
cmpq %rdi, %r13
sete %dl
je 0x2176
movq (%r13), %r8
cmpl %ecx, 0x1c(%r8)
je 0x2164
addq $0x8, %r13
cmpq %rdi, %r13
sete %dl
je 0x2176
movq (%r13), %r8
addq $0x8, %r13
cmpl %ecx, 0x1c(%r8)
jne 0x214a
addq $-0x8, %r13
testb %dl, %dl
jne 0x2176
movq (%r13), %rdx
ucomiss 0x10(%rdx), %xmm0
jae 0x22de
movq 0x18(%rbx), %r12
movq 0x20(%rbx), %rdi
cmpq %rdi, %r12
sete %dl
je 0x21c0
movq (%r12), %r8
cmpl %ecx, 0x1c(%r8)
je 0x21ae
addq $0x8, %r12
cmpq %rdi, %r12
sete %dl
je 0x21c0
movq (%r12), %r8
addq $0x8, %r12
cmpl %ecx, 0x1c(%r8)
jne 0x2194
addq $-0x8, %r12
testb %dl, %dl
jne 0x21c0
movq (%r12), %rcx
ucomiss 0x10(%rcx), %xmm0
jae 0x22de
movq %rax, (%rsi)
movq (%r14), %rdi
movss %xmm0, 0x10(%rdi)
addq $0x1c, %rdi
callq 0x137a
movq (%r14), %rax
movss %xmm0, 0x14(%rax)
addss 0x10(%rax), %xmm0
movss %xmm0, 0x18(%rax)
cmpq 0x20(%rbx), %r12
je 0x221c
movq (%r12), %rsi
decl 0x98(%rbx)
movq %r15, %rdi
callq 0x2864
leaq 0x8(%r12), %rsi
movq 0x20(%rbx), %rdx
cmpq %rdx, %rsi
je 0x2217
subq %rsi, %rdx
movq %r12, %rdi
callq 0x1160
addq $-0x8, 0x20(%rbx)
cmpq 0x8(%rbx), %r13
je 0x2264
movq (%r13), %rsi
decl 0x98(%rbx)
movq %r15, %rdi
callq 0x2864
leaq 0x8(%r13), %rsi
movq 0x8(%rbx), %rdx
cmpq %rdx, %rsi
je 0x224c
subq %rsi, %rdx
movq %r13, %rdi
callq 0x1160
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
addq $-0x8, %rsi
movq %rsi, 0x8(%rbx)
leaq -0x29(%rbp), %rdx
callq 0x28b3
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x227b
movq (%r14), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x2286
movq %rbx, %rdi
movq %r14, %rdx
callq 0x24a2
movq (%rbx), %rax
movq 0x8(%rbx), %rsi
movq -0x8(%rsi), %rcx
subq %rax, %rsi
sarq $0x3, %rsi
leaq -0x1(%rsi), %rdx
cmpq $0x2, %rsi
jl 0x22d5
movss 0x18(%rcx), %xmm0
leaq -0x1(%rdx), %rsi
shrq $0x3f, %rsi
addq %rdx, %rsi
decq %rsi
sarq %rsi
movq (%rax,%rsi,8), %rdi
movss 0x18(%rdi), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x22d5
movq %rdi, (%rax,%rdx,8)
cmpq $0x2, %rdx
movq %rsi, %rdx
jg 0x22a7
jmp 0x22d8
movq %rdx, %rsi
movq %rcx, (%rax,%rsi,8)
jmp 0x22ec
decl 0x98(%rbx)
movq %r15, %rdi
callq 0x2864
addq $0x8, %r14
cmpq 0x38(%rbx), %r14
jne 0x2108
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x2312
movq -0x38(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x20(%rbx)
jmp 0x231f
leaq 0x18(%rbx), %rdi
leaq -0x38(%rbp), %rdx
callq 0x24a2
movl 0x48(%rbx), %eax
jmp 0x2028
leaq 0xfdd(%rip), %rdi       # 0x330b
leaq 0xf5a(%rip), %rsi       # 0x328f
leaq 0x101c(%rip), %rcx      # 0x3358
movl $0xbc, %edx
callq 0x10a0