UpcaseUnicodeToUTF8NHelper

INT64 __stdcall UpcaseUnicodeToUTF8NHelper(PCHAR UTF8StringDestination, UINT32 UTF8StringMaxByteCount, INT64 a3){
  __int64 v3; 
  unsigned int v4; 
  unsigned int v5; 
  int v6; 
  __int64 v7; 
  unsigned int v11; 
  WCHAR *v12; 
  __int64 v13; 
  UINT16 v14; 
  UINT16 *v15; 
  __int64 v16; 
  UINT64 UnicodeStringByteCount; 
  int UTF8StringActualByteCount[4]; 
  WCHAR UnicodeStringSource[64]; 
  int v21; 
  v4 = v21;
  v5 = 0;
  v6 = 0;
  v7 = v3;
  if( v21 )
  {
    while( 1 )
    {
      if( !UTF8StringMaxByteCount )
        goto LABEL_15;
      UTF8StringActualByteCount[0] = 0;
      if( v4 < 0x40 )
        break;
      v11 = 64;
      if( v4 != 64 && (unsigned int)*(unsigned __int16 *)(v7 + 126) - 55296 <= 0x3FF )
      {
        v11 = 63;
LABEL_8:
        if( !v11 )
          goto LABEL_11;
      }
      v12 = UnicodeStringSource;
      v13 = v7 - (_QWORD)UnicodeStringSource;
      do
      {
        v14 = NLS_UPCASE(*(WCHAR *)((char *)v12 + v13));
        *v15 = v14;
        v12 = v15 + 1;
      }
      while( v16 != 1 );
LABEL_11:
      LODWORD(UnicodeStringByteCount) = 2 * v11;
      if( RtlUnicodeToUTF8N(
             UTF8StringDestination,
             UTF8StringMaxByteCount,
             (UINT64 *)UTF8StringActualByteCount,
             UnicodeStringSource,
             UnicodeStringByteCount) < 0 )
      {
        v6 += UTF8StringActualByteCount[0];
        v5 = -2147483643;
        goto LABEL_15;
      }
      UTF8StringDestination += (unsigned int)UTF8StringActualByteCount[0];
      UTF8StringMaxByteCount -= UTF8StringActualByteCount[0];
      v6 += UTF8StringActualByteCount[0];
      v7 += 2i64 * v11;
      v4 -= v11;
      if( !v4 )
        goto LABEL_15;
    }
    v11 = v4;
    goto LABEL_8;
  }
LABEL_15:
  if( a3 )
    *(_DWORD *)a3 = v6;
  return v5;
}

Referenced by:

RtlUpcaseUnicodeToMultiByteN
RtlUpcaseUnicodeToOemN