RtlpMuiRegAddBaseLanguage

__int64 __fastcall RtlpMuiRegAddBaseLanguage(__int64 a1, _WORD *a2, unsigned int a3, __int64 a4, wchar_t *a5){
  __int16 v5; 
  char v8; 
  WCHAR *v9; 
  unsigned __int64 v10; 
  __int64 v11; 
  wchar_t *Buffer; 
  __int64 v13; 
  int v14; 
  __int16 v15; 
  __int16 v16; 
  int v17; 
  __int64 v18; 
  int v19; 
  int LanguageSpec; 
  char v21; 
  __int16 v22; 
  __int16 v23; 
  wchar_t *v24; 
  __int64 v25; 
  __int64 v26; 
  _WORD *v27; 
  char v29; 
  char v30; 
  char v31; 
  __int16 v32[2]; 
  __int16 v33; 
  __int16 v34; 
  wchar_t *Str2; 
  int inited; 
  unsigned int v37; 
  __int64 v38; 
  _WORD *v39; 
  struct _UNICODE_STRING DestinationString; 
  __int128 v41; 
  __int64 v42; 
  int v43; 
  v5 = 0;
  Str2 = a5;
  v37 = a3;
  v39 = a2;
  v38 = a1;
  v42 = 0i64;
  v43 = 0;
  v8 = 0;
  v29 = 0;
  v30 = 0;
  v34 = 0;
  DestinationString = 0i64;
  v41 = 0i64;
  if( a1 && a2 && a4 && a3 <= 3 )
  {
    v9 = (WCHAR *)(a4 + *(unsigned int *)(a4 + 8));
    if( !*(_DWORD *)(a4 + 12) || !v9 || (v31 = 1, !*v9) )
      v31 = 0;
    v10 = (unsigned __int64)*(unsigned int *)(a4 + 16) >> 1;
    v33 = *(_WORD *)(a4 + 2 * v10 + 20);
    *(_WORD *)(a4 + 2 * v10 + 20) = 0;
    RtlInitUnicodeString(&DestinationString, (PCWSTR)(a4 + 20), a3);
    v32[0] = 0;
    if( v31 )
    {
      Buffer = DestinationString.Buffer;
      v9[(unsigned __int64)*(unsigned int *)(a4 + 12) >> 1] = 0;
      inited = RtlpMuiRegInitAnyLanguage(a1, (__int64)&v41, Buffer, 1026);
      v14 = inited;
      if( inited < 0 )
        return(unsigned int)v14;
      v15 = v33;
      v16 = ((unsigned __int8)v41 ^ (unsigned __int8)*v39) & 0x18;
      LOBYTE(v33) = 0;
      LOWORD(v41) = v16 ^ v41;
      *(_WORD *)(a4 + 2 * v10 + 20) = v15;
      v17 = 0;
      if( Str2
        && *Str2
        && RtlpLangNameInMultiSzString(v9, Str2)
        && (int)RtlpMuiRegGetLanguageSpec(v38, Str2, &v30, v13, &v34) >= 0 )
      {
        v17 = 1;
        LOBYTE(v33) = 1;
        WORD6(v41) = v34;
        WORD4(v41) = WORD4(v41) & 0xFFFC | v30 & 3;
      }
      if( v9 )
      {
        v18 = v38;
        v19 = 2 * v17;
        Str2 = (wchar_t *)&v41 + (unsigned int)v17 + 6;
        do
        {
          if( !*v9 || v19 >= 8 )
            break;
          LanguageSpec = RtlpMuiRegGetLanguageSpec(v18, v9, &v29, v13, v32);
          v8 = v29;
          v5 = v32[0];
          if( LanguageSpec >= 0 && (!(_BYTE)v33 || v30 != v29 || v34 != v32[0]) )
          {
            v21 = v19;
            v22 = WORD4(v41) & ~(3 << v19);
            ++v17;
            v19 += 2;
            v23 = (v29 & 3) << v21;
            v24 = Str2;
            WORD4(v41) = v23 | v22;
            *Str2 = v32[0];
            Str2 = v24 + 1;
          }
          v25 = -1i64;
          do
            ++v25;
          while( v9[v25] );
          v9 += v25 + 1;
        }
        while( v9 );
        v14 = inited;
      }
      if( v17 < 0 )
      {
        v5 = WORD2(v41);
        if( WORD2(v41) )
        {
          v8 = 1;
LABEL_40:
          v26 = (int)v37;
          v27 = v39;
          v39[4] = v39[4] & ~(3 << (2 * v37)) | ((v8 & 3) << (2 * v37));
          v27[v26 + 6] = v5;
          return(unsigned int)v14;
        }
        v5 = WORD3(v41);
        if( SWORD3(v41) > 0 )
        {
          v8 = 3;
          goto LABEL_40;
        }
        return(unsigned int)-1073741823;
      }
    }
    else
    {
      v14 = RtlpMuiRegGetLanguageSpec(a1, DestinationString.Buffer, &v29, v11, v32);
      if( v14 < 0 )
        return(unsigned int)v14;
      v8 = v29;
      v5 = v32[0];
    }
    if( !v31 )
      goto LABEL_40;
    LOWORD(v41) = v41 & 0xFFDF;
    v14 = RtlpMuiRegGetOrAddLangInfo((__int64 *)(v38 + 24), (__int64)&v41, v32);
    if( v14 >= 0 )
    {
      v5 = v32[0];
      v8 = 2;
      goto LABEL_40;
    }
    return(unsigned int)v14;
  }
  return 3221225485i64;
}

Referenced by:

RtlpMuiRegPopulateBaseLanguages