CmpFindSubKeyInLeafWithStatus

INT64 __fastcall CmpFindSubKeyInLeafWithStatus(
        _HHIVE *Hive,
        _CM_KEY_INDEX *KeyIndex,
        const _UNICODE_STRING *SearchName,
        UINT *Child,
        UINT *Index){
  int Count; 
  _HHIVE *v9; 
  __int64 v10; 
  INT64 result; 
  unsigned __int16 Signature; 
  UINT *v13; 
  int v14; 
  int v15; 
  _CM_KEY_INDEX *v16; 
  unsigned int v17; 
  _CM_KEY_INDEX *v18; 
  unsigned int v19; 
  unsigned int v20; 
  __int64 v21; 
  __int64 v22; 
  UINT16 v23; 
  unsigned int v24; 
  int v25; 
  int v26; 
  int v27; 
  int v28; 
  unsigned int v29; 
  unsigned int v30; 
  unsigned int v31; 
  UINT *v32; 
  int v33; 
  int v34; 
  int v35; 
  unsigned int v37; 
  unsigned int *v38; 
  Count = KeyIndex->Count;
  v37 = 0;
  v9 = Hive;
  v35 = Count - 1;
  v10 = (unsigned int)(Count - 1) >> 1;
  if( !(_WORD)Count )
  {
    *Index = -1;
    *v38 = 0;
    return 3221225524i64;
  }
  while( 1 )
  {
    Signature = KeyIndex->Signature;
    v13 = Index;
    *Index = -1;
    if( ((Signature - 26220) & 0xFDFF) != 0 )
    {
      v14 = CmpDoCompareKeyName((INT64)v9, SearchName, (WCHAR **)Child, KeyIndex->List[v10]);
      v15 = v14;
      if( v14 == 2 )
      {
        v32 = Index;
        goto LABEL_59;
      }
      if( !v14 )
        *Index = KeyIndex->List[v10];
    }
    else
    {
      v16 = &KeyIndex[v10];
      if( Signature != 26220 )
        goto LABEL_37;
      v17 = 4;
      v18 = v16 + 1;
      v19 = 0;
      while( LOBYTE(v18->Signature) )
      {
        ++v19;
        v18 = (_CM_KEY_INDEX *)((char *)v18 + 1);
        if( v19 >= 4 )
          goto LABEL_13;
      }
      v17 = v19;
LABEL_13:
      if( Child )
        v20 = *(unsigned __int16 *)Child;
      else
        v20 = SearchName->Length >> 1;
      if( v20 >= v17 )
        v20 = v17;
      v21 = 0i64;
      if( !v20 )
      {
LABEL_36:
        v13 = Index;
LABEL_37:
        v28 = CmpDoCompareKeyName((INT64)v9, SearchName, (WCHAR **)Child, v16->List[0]);
        v15 = v28;
        if( v28 == 2 )
          goto LABEL_57;
        if( !v28 )
          *v13 = v16->List[0];
        goto LABEL_40;
      }
      v22 = 0i64;
      while( 1 )
      {
        v23 = Child ? *(unsigned __int8 *)(*((_QWORD *)Child + 1) + v21) : SearchName->Buffer[v22];
        v24 = *((unsigned __int8 *)&KeyIndex[v10 + 1].Signature + (unsigned int)v21);
        if( v23 >= 0x61u )
          v25 = v23 <= 0x7Au ? v23 - 32 : NLS_UPCASE(v23);
        else
          v25 = v23;
        if( v24 >= 0x61 )
          v26 = v24 <= 0x7A ? v24 - 32 : NLS_UPCASE(v24);
        else
          v26 = v24;
        v27 = v25 - v26;
        if( v27 )
          break;
        v21 = (unsigned int)(v21 + 1);
        ++v22;
        if( (unsigned int)v21 >= v20 )
        {
          v9 = Hive;
          goto LABEL_36;
        }
      }
      v15 = 1;
      if( v27 <= 0 )
        v15 = -1;
    }
LABEL_40:
    if( v15 == 2 )
    {
LABEL_57:
      v32 = Index;
      goto LABEL_59;
    }
    if( !v15 )
    {
      *v38 = v10;
      return 0i64;
    }
    v29 = v37;
    if( v15 >= 0 )
    {
      v29 = v10;
      LODWORD(v10) = v35;
    }
    v30 = v10;
    v35 = v10;
    v31 = v10 - v29;
    v37 = v29;
    if( v31 <= 1 )
      break;
    v9 = Hive;
    v10 = v29 + (v31 >> 1);
  }
  v32 = Index;
  v33 = CmpCompareInIndex(Hive, SearchName, (UINT64)Child, (_CM_KEY_INDEX *)v29, (UINT *)KeyIndex);
  if( v33 != 2 )
  {
    if( !v33 )
    {
      *v38 = v29;
      return 0i64;
    }
    if( v33 < 0 )
    {
      *v38 = v29;
      return 3221225524i64;
    }
    v34 = CmpCompareInIndex(Hive, SearchName, (UINT64)Child, (_CM_KEY_INDEX *)v30, (UINT *)KeyIndex);
    if( v34 != 2 )
    {
      result = v34 != 0 ? 0xC0000034 : 0;
      *v38 = v30;
      return result;
    }
  }
LABEL_59:
  *v32 = -1;
  *v38 = 0x80000000;
  return 3221225626i64;
}

Referenced by:

CmpFindSubKeyByNameWithStatus
CmpFindSubKeyInLeaf
CmpMarkIndexDirty
CmpWalkOneLevel