RtlpLookupFunctionEntryForStackWalks

UINT64 *__stdcall RtlpLookupFunctionEntryForStackWalks(PVOID EndingAddress, INT64 a2){
  unsigned __int64 v4; 
  UINT64 v5; 
  unsigned int v6; 
  unsigned int *v7; 
  char *v8; 
  unsigned int *v9; 
  int v10; 
  int v11; 
  int v12; 
  unsigned __int64 v13; 
  __int64 v14; 
  int v16; 
  unsigned __int64 v17; 
  v4 = *(_QWORD *)(a2 + 8);
  if( (unsigned __int64)EndingAddress < v4 || (unsigned __int64)EndingAddress >= v4 + *(unsigned int *)(a2 + 16) )
  {
    if( (unsigned __int64)EndingAddress <= 0x7FFFFFFEFFFFi64 )
    {
      v5 = RtlpLookupUserFunctionTable(EndingAddress, a2);
    }
    else if( (unsigned __int64)EndingAddress < *(&byte_140E00020 + 1)
           || (unsigned __int64)EndingAddress >= *(&byte_140E00020 + 1) + *((unsigned int *)&byte_140E00020 + 4) )
    {
      v5 = (UINT64)RtlpxLookupFunctionTable(EndingAddress, (_INVERTED_FUNCTION_TABLE_ENTRY *)a2);
    }
    else
    {
      *(_OWORD *)a2 = *(_OWORD *)&byte_140E00020;
      *(_QWORD *)(a2 + 16) = *(&byte_140E00020 + 2);
      v5 = *(_QWORD *)a2;
    }
  }
  else
  {
    v5 = *(_QWORD *)a2;
  }
  if( v5 )
  {
    v6 = *(_DWORD *)(a2 + 20) / 0xCu;
    v7 = 0i64;
    if( v6 )
    {
      v8 = (char *)EndingAddress - *(_QWORD *)(a2 + 8);
      v9 = (unsigned int *)(v5 + 12i64 * (v6 - 1));
      if( (unsigned __int64)v8 < *v9 )
      {
        v10 = 0;
        v11 = v6 - 2;
        while( v11 >= v10 )
        {
          v12 = (v10 + v11) >> 1;
          v9 = (unsigned int *)(v5 + 12i64 * v12);
          if( (unsigned __int64)v8 >= *v9 )
          {
            if( (unsigned __int64)v8 < v9[3] )
              break;
            v10 = v12 + 1;
          }
          else
          {
            v11 = v12 - 1;
          }
        }
      }
      if( (unsigned __int64)v8 >= *v9 && (unsigned __int64)v8 < v9[1] )
        v7 = v9;
    }
    if( v7 )
    {
      v13 = *(_QWORD *)(a2 + 8);
      v14 = v7[2];
      if( (v14 & 1) != 0 )
      {
        v7 = (unsigned int *)(v14 + v13 - 1);
        if( v13 <= 0x7FFFFFFEFFFFi64 && ((unsigned __int8)v7 & 3) != 0 )
          ExRaiseDatatypeMisalignment();
      }
    }
    return(UINT64 *)v7;
  }
  else
  {
    HvlQueryConnection((PVOID *)(a2 + 8));
    if( v16 < 0
      || (v17 = *(_QWORD *)(a2 + 8), (unsigned __int64)EndingAddress < v17)
      || (unsigned __int64)EndingAddress >= v17 + 4096 )
    {
      *(_QWORD *)(a2 + 8) = 0i64;
      *(_DWORD *)(a2 + 16) = 0;
      return 0i64;
    }
    else
    {
      *(_DWORD *)(a2 + 16) = 4096;
      return 0i64;
    }
  }
}

Referenced by:

PspGetSetContextInternal
RtlpSameFunction
RtlpWalkFrameChain