// File: /workspace/github_cpp_makefile_star2_O3/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 0x22c5
movl %eax, %ecx
andl $0x6, %ecx
cmpl $0x2, %ecx
je 0x1fe6
movq %rdi, %rbx
movq (%rdi), %rdi
movq 0x8(%rbx), %rax
cmpq %rax, %rdi
je 0x1fd2
cmpb $0x1, 0x9c(%rbx)
jne 0x1ff5
movq %rbx, %rdi
callq 0x25c0
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), %r14
movq %r14, -0x38(%rbp)
movq %rax, %rcx
subq %rdi, %rcx
cmpq $0x9, %rcx
jl 0x2029
leaq -0x8(%rax), %rdx
movq -0x8(%rax), %rcx
movq %r14, -0x8(%rax)
subq %rdi, %rdx
sarq $0x3, %rdx
xorl %esi, %esi
callq 0x26fd
movq 0x8(%rbx), %rax
addq $-0x8, %rax
movq %rax, 0x8(%rbx)
cmpl $0x1, 0x1c(%r14)
jne 0x2092
movq 0x58(%rbx), %rax
movq (%r14), %rcx
movq %rcx, (%rax)
movss 0x10(%r14), %xmm0
movss %xmm0, 0x10(%rax)
movq 0x50(%rbx), %rax
cmpl $0x1, 0x1c(%rax)
je 0x2079
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2630
movq 0x50(%rbx), %rax
movq 0x58(%rbx), %rcx
movq (%rcx), %rdx
movq %rcx, 0x8(%rdx)
movq %rdx, %rcx
cmpq %rax, %rdx
jne 0x206a
movq %rbx, %rdi
callq 0x267e
movl $0x2, 0x48(%rbx)
movl $0x2, %eax
jmp 0x1fe6
movq 0x30(%rbx), %rax
cmpq %rax, 0x38(%rbx)
je 0x20a0
movq %rax, 0x38(%rbx)
leaq 0x3079(%rip), %r12      # 0x5120
xorl %r13d, %r13d
xorps %xmm0, %xmm0
leaq -0x3c(%rbp), %r15
movl 0x1c(%r14), %eax
imulq $0x54, %rax, %rax
ucomiss (%r12,%rax), %xmm0
ja 0x20d2
movl %r13d, -0x3c(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1d80
xorps %xmm0, %xmm0
incq %r13
addq $0x4, %r12
cmpq $0x15, %r13
jne 0x20b1
movq 0x30(%rbx), %r14
cmpq 0x38(%rbx), %r14
je 0x2298
leaq 0x302c(%rip), %r15      # 0x5120
movq -0x38(%rbp), %rax
movss 0x10(%rax), %xmm0
movq (%r14), %rsi
movl 0x1c(%rax), %edx
movl 0x1c(%rsi), %ecx
imulq $0x54, %rdx, %rdx
addq %r15, %rdx
addss (%rdx,%rcx,4), %xmm0
movq (%rbx), %r12
movq 0x8(%rbx), %rdx
cmpq %rdx, %r12
je 0x2137
movq (%r12), %rdi
cmpl %ecx, 0x1c(%rdi)
je 0x212d
addq $0x8, %r12
jmp 0x2119
ucomiss 0x10(%rdi), %xmm0
jae 0x21f0
movq 0x18(%rbx), %r13
movq 0x20(%rbx), %rdx
cmpq %rdx, %r13
je 0x215d
movq (%r13), %rdi
cmpl %ecx, 0x1c(%rdi)
je 0x2153
addq $0x8, %r13
jmp 0x213f
ucomiss 0x10(%rdi), %xmm0
jae 0x21f0
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), %r13
je 0x21b9
movq (%r13), %rsi
movq %rbx, %rdi
callq 0x2630
leaq 0x8(%r13), %rsi
movq 0x20(%rbx), %rdx
cmpq %rdx, %rsi
je 0x21b1
subq %rsi, %rdx
movq %r13, %rdi
callq 0x1160
movq 0x20(%rbx), %rdx
addq $-0x8, %rdx
movq %rdx, 0x20(%rbx)
movq 0x8(%rbx), %rsi
cmpq %rsi, %r12
je 0x2218
movq (%r12), %rsi
movq %rbx, %rdi
callq 0x2630
movq 0x8(%rbx), %rdx
leaq 0x8(%r12), %rsi
cmpq %rdx, %rsi
je 0x21fd
subq %rsi, %rdx
movq %r12, %rdi
callq 0x1160
movq (%rbx), %rdi
movq 0x8(%rbx), %rdx
jmp 0x2200
movq %rbx, %rdi
callq 0x2630
jmp 0x228a
movq (%rbx), %rdi
addq $-0x8, %rdx
movq %rdx, 0x8(%rbx)
movq %rdx, %rsi
leaq -0x29(%rbp), %rdx
callq 0x27c1
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2232
movq (%r14), %rax
movq %rax, (%rsi)
movq 0x8(%rbx), %rsi
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2241
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2402
movq 0x8(%rbx), %rsi
movq (%rbx), %rax
movq -0x8(%rsi), %rcx
subq %rax, %rsi
sarq $0x3, %rsi
leaq -0x1(%rsi), %rdx
cmpq $0x2, %rsi
jl 0x2286
movss 0x18(%rcx), %xmm0
leaq -0x1(%rdx), %rsi
movq %rsi, %rdi
shrq %rdi
movq (%rax,%rdi,8), %r8
movss 0x18(%r8), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x2286
movq %r8, (%rax,%rdx,8)
movq %rdi, %rdx
cmpq $0x1, %rsi
ja 0x225e
xorl %edx, %edx
movq %rcx, (%rax,%rdx,8)
addq $0x8, %r14
cmpq 0x38(%rbx), %r14
jne 0x20f4
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x22b0
movq -0x38(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x20(%rbx)
jmp 0x22bd
leaq 0x18(%rbx), %rdi
leaq -0x38(%rbp), %rdx
callq 0x2402
movl 0x48(%rbx), %eax
jmp 0x1fe6
leaq 0x103f(%rip), %rdi      # 0x330b
leaq 0xfbc(%rip), %rsi       # 0x328f
leaq 0x107e(%rip), %rcx      # 0x3358
movl $0xbc, %edx
callq 0x10a0