RtlMultiByteToUnicodeN

NTSTATUS __stdcall RtlMultiByteToUnicodeN(
        UINT32 MaxBytesInUnicodeString,
        PULONG BytesInUnicodeString,
        INT8 *MultiByteString,
        UINT32 BytesInMultiByteString){
  WCHAR *v4; 
  const CHAR *v5; 
  unsigned int v7; 
  ULONG v8; 
  ULONG v9; 
  INT64 v10; 
  __int64 v11; 
  __int64 v12; 
  INT8 *v14; 
  __int64 v15; 
  int v16; 
  ULONG v17; 
  int v18; 
  __int64 v19; 
  __int64 v20; 
  UINT64 UTF8StringByteCount; 
  char v22; 
  ULONG BytesInMultiByteStringa; 
  v4 = *(WCHAR **)&MaxBytesInUnicodeString;
  v5 = *(const CHAR **)&BytesInMultiByteString;
  v7 = (unsigned int)BytesInUnicodeString;
  if( RtlpIsUtf8Process(0) )
  {
    v14 = &v22;
    if( MultiByteString )
      v14 = MultiByteString;
    if( BytesInMultiByteStringa )
    {
      LODWORD(UTF8StringByteCount) = BytesInMultiByteStringa;
      RtlUTF8ToUnicodeN(v4, v7, (UINT64 *)v14, v5, UTF8StringByteCount);
    }
    else
    {
      *(_DWORD *)v14 = 0;
    }
  }
  else
  {
    v8 = v7 >> 1;
    if( (_BYTE)NlsMbCodePageTag )
    {
      v15 = NlsMbAnsiCodePageTables;
      v16 = (int)v4;
      if( v8 )
      {
        v17 = BytesInMultiByteStringa;
        v18 = (int)v4;
        while( v17 )
        {
          v19 = *(unsigned __int8 *)v5;
          --v8;
          --v17;
          v20 = *((unsigned __int16 *)&NlsLeadByteInfoTable + v19);
          if( (_WORD)v20 )
          {
            if( !v17 )
            {
              *v4 = 0;
              LODWORD(v4) = v18 + 2;
              break;
            }
            *v4++ = *(_WORD *)(v15 + 2 * (v20 + *(unsigned __int8 *)++v5));
            --v17;
          }
          else
          {
            *v4++ = *(_WORD *)(NlsAnsiToUnicodeData + 2 * v19);
          }
          ++v5;
          v18 = (int)v4;
          if( !v8 )
            break;
        }
      }
      if( MultiByteString )
        *(_DWORD *)MultiByteString = (_DWORD)v4 - v16;
    }
    else
    {
      v9 = BytesInMultiByteStringa;
      if( v8 < BytesInMultiByteStringa )
        v9 = v8;
      if( MultiByteString )
        *(_DWORD *)MultiByteString = 2 * v9;
      v10 = NlsAnsiToUnicodeData;
      if( v9 )
      {
        v11 = v9;
        do
        {
          v12 = *(unsigned __int8 *)v5++;
          *v4++ = *(_WORD *)(v10 + 2 * v12);
          --v11;
        }
        while( v11 );
      }
    }
  }
  return 0;
}

Referenced by:

RtlAnsiStringToUnicodeString
mbstowcs