RtlpNameprepAsciiRealWorker

INT64 __fastcall RtlpNameprepAsciiRealWorker(
        INT64 a1,
        WCHAR *a2,
        INT64 a3,
        UINT8 *a4,
        INT64 *a5,
        CHAR a6,
        WCHAR *pInput,
        CHAR a8,
        WCHAR *pOutput,
        UINT8 bAllowEmail){
  __int16 v10; 
  int v12; 
  WCHAR *v13; 
  INT64 *v14; 
  int v15; 
  UINT8 v16; 
  bool v17; 
  UINT8 v18; 
  int v19; 
  INT64 result; 
  int v21; 
  int v22; 
  WCHAR *v23; 
  int v24; 
  unsigned int EmailAt; 
  WCHAR *v26; 
  bool v27; 
  bool v28; 
  WCHAR v29; 
  WCHAR v30; 
  WCHAR *v31; 
  int v32; 
  bool v33; 
  __int64 v34; 
  UINT8 bUseStd3Rules; 
  size_t pcchLength; 
  int v37; 
  INT64 DestinationStringLength; 
  v10 = 0;
  v12 = a3;
  v13 = a2;
  if( a2 )
  {
    if( (int)a3 >= -1 )
    {
      v14 = a5;
      if( a5 )
      {
        v15 = *(_DWORD *)a5;
        if( *(int *)a5 >= 0 && (v15 <= 0 || a4) && (a1 & 0xFFFFFFF8) == 0 )
        {
          a8 = 0;
          v37 = a1 & 1;
          LODWORD(DestinationStringLength) = a1 & 4;
          v16 = (_DWORD)DestinationStringLength != 0;
          v17 = (a1 & 2) != 0;
          bAllowEmail = (_DWORD)DestinationStringLength != 0;
          if( (_DWORD)a3 != -1 )
          {
LABEL_11:
            if( v12 > 0 && v13[v12 - 1] == v10 )
            {
              a8 = 1;
              --v12;
            }
            v18 = RtlpValidateAsciiStd3AndLength(v13, (unsigned int)v12, v16, v17);
            v19 = 0;
            if( v18 )
            {
              if( !v12 )
                return 3221227286i64;
              v21 = v12 + 1;
              if( !a8 )
                v21 = v12;
              goto LABEL_65;
            }
            v22 = 0;
            v23 = pInput;
            v24 = 511;
            v21 = 0;
            if( !(_DWORD)DestinationStringLength )
              goto LABEL_28;
            EmailAt = FindEmailAt(v13, (unsigned int)v12);
            LODWORD(pcchLength) = EmailAt;
            if( !EmailAt )
              goto LABEL_55;
            LODWORD(DestinationStringLength) = 511;
            result = RtlNormalizeString(1ui64, v13, EmailAt, v26, &DestinationStringLength);
            v21 = DestinationStringLength;
            v19 = 0;
            v27 = (_DWORD)result == 0;
            if( (int)result >= 0 )
            {
              if( (_DWORD)DestinationStringLength )
              {
                v22 = pcchLength;
                v23 = &pInput[(int)DestinationStringLength];
                v24 = 511 - DestinationStringLength;
LABEL_28:
                if( v22 >= v12 )
                {
LABEL_32:
                  if( v21 > 0 )
                  {
                    v29 = pInput[v21 - 1];
                    if( v29 == 46 )
                    {
                      v30 = v13[v12 - 1];
                      if( v30 != 46 && v30 != 12290 && v30 != 0xFF0E && v30 != 0xFF61 )
                        goto LABEL_55;
                    }
                    if( !v29 )
                      goto LABEL_55;
                  }
                  v13 = pInput;
                  bUseStd3Rules = v17;
                  v31 = pOutput;
                  LODWORD(DestinationStringLength) = 515;
                  result = punycode_encode(
                             pInput,
                             (unsigned int)v21,
                             pOutput,
                             &DestinationStringLength,
                             bAllowEmail,
                             bUseStd3Rules);
                  v32 = DestinationStringLength;
                  v19 = 0;
                  if( (_DWORD)DestinationStringLength )
                  {
                    if( a6 )
                    {
                      if( !a8 )
                        goto LABEL_44;
                      if( (int)DestinationStringLength < 515 )
                      {
                        v31[(int)DestinationStringLength] = 0;
                        ++v32;
LABEL_44:
                        if( a4 && v15 )
                        {
                          if( v32 > v15 )
                          {
LABEL_68:
                            result = 3221225507i64;
                            goto LABEL_56;
                          }
                          memmove(a4, (UINT8 *)v31, 2i64 * v32);
                        }
                        *(_DWORD *)v14 = v32;
                        return 0i64;
                      }
                      goto LABEL_55;
                    }
                    if( !a8 )
                    {
LABEL_65:
                      if( a4 && v15 )
                      {
                        if( v21 > v15 )
                          goto LABEL_68;
                        memmove(a4, (UINT8 *)v13, 2i64 * v21);
                      }
                      *(_DWORD *)v14 = v21;
                      return 0i64;
                    }
                    if( v21 <= 511 )
                    {
                      v34 = v21++;
                      v13[v34] = 0;
                      goto LABEL_65;
                    }
LABEL_55:
                    result = 3221227286i64;
                  }
LABEL_56:
                  *(_DWORD *)v14 = v19;
                  return result;
                }
                LODWORD(DestinationStringLength) = v24;
                result = RtlNormalizeString(
                           ((v37 ^ 1u) << 8) + 13,
                           &v13[v22],
                           (unsigned int)(v12 - v22),
                           v23,
                           &DestinationStringLength);
                v19 = 0;
                v28 = (_DWORD)result == 0;
                if( (int)result >= 0 )
                {
                  if( (_DWORD)DestinationStringLength )
                  {
                    v21 += DestinationStringLength;
                    goto LABEL_32;
                  }
                  v28 = (_DWORD)result == 0;
                }
                if( v28 || (_DWORD)result == -1073741789 || (_DWORD)result == -1073740009 )
                  goto LABEL_55;
                v33 = (int)DestinationStringLength <= 0;
LABEL_54:
                if( !v33 )
                  goto LABEL_55;
                goto LABEL_56;
              }
              v27 = (_DWORD)result == 0;
            }
            if( v27 || (_DWORD)result == -1073741789 || (_DWORD)result == -1073740009 )
              goto LABEL_55;
            v33 = (int)DestinationStringLength <= 0;
            goto LABEL_54;
          }
          pcchLength = 0i64;
          if( RtlStringCchLengthW(v13, 0x7FFFFFFFui64, &pcchLength) >= 0 )
          {
            v16 = bAllowEmail;
            v12 = pcchLength + 1;
            goto LABEL_11;
          }
        }
      }
    }
  }
  return 3221225485i64;
}

Referenced by:

RtlpNameprepAsciiWorker