woutput_l

__int64 __fastcall woutput_l(__int64 a1, unsigned __int16 *a2, __int64 a3, __int64 a4){
  int v6; 
  int v7; 
  wchar_t *v8; 
  int *v9; 
  unsigned __int16 v10; 
  int v11; 
  __int64 v12; 
  int v13; 
  int v14; 
  unsigned __int64 v15; 
  __int64 v16; 
  __int64 v17; 
  unsigned __int16 *v18; 
  unsigned int v19; 
  int v20; 
  const char *v21; 
  wchar_t v22; 
  int v23; 
  const wchar_t *v24; 
  unsigned __int64 v25; 
  char v26; 
  char *v27; 
  int v28; 
  int v29; 
  unsigned __int64 v30; 
  char v31; 
  unsigned __int16 *v32; 
  int v33; 
  __int16 v34; 
  unsigned int v35; 
  unsigned int v36; 
  __int64 v37; 
  const char *v38; 
  int v39; 
  int v40; 
  __int64 v41; 
  unsigned __int16 v42; 
  int v43; 
  unsigned __int64 v44; 
  __int64 v45; 
  int v46; 
  int v47; 
  int v48; 
  int v50; 
  int v51; 
  int v52; 
  int v53; 
  __int16 v54[2]; 
  int v55; 
  int v56; 
  char SrcCh[4]; 
  __int16 v58[2]; 
  int v59; 
  int *v60; 
  __int64 v61; 
  int v62; 
  unsigned __int16 *v63; 
  wchar_t DstCh[512]; 

  v61 = a1;
  v62 = 0;
  v59 = 0;
  v53 = 0;
  v52 = 0;
  v50 = 0;
  v6 = 0;
  v60 = (int *)a4;
  v7 = 0;
  v8 = 0i64;
  v9 = (int *)a4;
  memset(DstCh, 0i64, sizeof(DstCh));
  v54[0] = 0;
  v55 = 0;
  if( a1 && a2 )
  {
    v10 = *a2;
    v11 = 0;
    v51 = 0;
    LODWORD(v12) = 0;
    v13 = 0;
    if( v10 )
    {
      do
      {
        v63 = ++a2;
        if( v11 < 0 )
          return(unsigned int)v11;
        if( (unsigned __int16)(v10 - 32) > 0x5Au )
          v14 = 0;
        else
          v14 = *((_BYTE *)&_lookuptable[-4] + v10) & 0xF;
        v13 = *((char *)&_lookuptable[v14] + v13) >> 4;
        v56 = v13;
        switch( v13 )
        {
          case 0:
            goto LABEL_166;
          case 1:
            v7 = -1;
            v50 = 0;
            v53 = -1;
            v6 = 0;
            v59 = 0;
            v52 = 0;
            v55 = 0;
            break;
          case 2:
            switch( v10 )
            {
              case ' ':
                v6 |= 2u;
                break;
                v6 |= 0x80u;
                break;
              case '+':
                v6 |= 1u;
                break;
              case '-':
                v6 |= 4u;
                break;
              case '0':
                v6 |= 8u;
                break;
            }
            break;
          case 3:
            if( v10 == 42 )
            {
              v46 = *v9;
              v60 = v9 + 2;
              v47 = v6 | 4;
              if( v46 >= 0 )
                v47 = v6;
              v6 = v47;
              v48 = abs32(v46);
            }
            else
            {
              v48 = v10 + 2 * (5 * v59 - 24);
            }
            v59 = v48;
            break;
          case 4:
            v7 = 0;
            v53 = 0;
            break;
          case 5:
            if( v10 != 42 )
            {
              v7 = v10 + 2 * (5 * v7 - 24);
              goto LABEL_171;
            }
            v7 = *v9;
            v60 = v9 + 2;
            v53 = v7;
            if( v7 < 0 )
            {
              v7 = -1;
LABEL_171:
              v53 = v7;
            }
            break;
          case 6:
            switch( v10 )
            {
              case 'I':
                goto LABEL_148;
              case 'h':
                v6 |= 0x20u;
                goto LABEL_192;
              case 'j':
                goto LABEL_148;
              case 'l':
                v42 = *a2;
                if( *a2 == 108 )
                  ++a2;
                v43 = 4096;
                if( v42 != 108 )
                  v43 = 16;
                v6 |= v43;
                goto LABEL_192;
              case 't':
                goto LABEL_148;
              case 'w':
                v6 |= 0x800u;
                goto LABEL_192;
              case 'z':
LABEL_148:
                v6 |= 0x8000u;
                if( v10 == 73 )
                {
                  if( *a2 == 54 && a2[1] == 52 )
                  {
                    a2 += 2;
                  }
                  else
                  {
                    if( *a2 != 51 || a2[1] != 50 )
                    {
LABEL_163:
                      v44 = *a2;
                      LOWORD(v44) = v44 - 88;
                      if( (unsigned __int16)v44 <= 0x20u )
                      {
                        v45 = 0x120821001i64;
                        if( _bittest64(&v45, v44) )
                          goto LABEL_192;
                      }
                      v56 = 0;
LABEL_166:
                      v55 = 1;
                      write_char(v10, v61, &v51);
LABEL_140:
                      v11 = v51;
                      goto LABEL_191;
                    }
                    a2 += 2;
                    v6 &= ~0x8000u;
                  }
                }
                else if( v10 != 106 )
                {
                  goto LABEL_163;
                }
                break;
            }
            break;
          case 7:
            if( v10 > 0x69u )
            {
              switch( v10 )
              {
                case 'n':
                  v60 = v9 + 2;
                  v32 = *(unsigned __int16 **)v9;
                  if( !get_printf_count_output() )
                    goto LABEL_194;
                  if( (v6 & 0x20) != 0 )
                    *v32 = v11;
                  else
                    *(_DWORD *)v32 = v11;
                  v33 = 1;
                  v50 = 1;
                  goto LABEL_111;
                case 'o':
                  v15 = 8i64;
                  if( (v6 & 0x80u) != 0 )
                    v6 |= 0x200u;
                  goto LABEL_26;
                case 'p':
                  v7 = 16;
                  v6 |= 0x8000u;
                  goto LABEL_73;
              }
              if( v10 != 115 )
              {
                if( v10 != 117 )
                {
                  if( v10 != 120 )
                    goto LABEL_110;
                  v23 = 39;
                  goto LABEL_74;
                }
LABEL_25:
                v15 = 10i64;
LABEL_26:
                v16 = (__int64)(v9 + 2);
                v60 = (int *)v16;
                if( (v6 & 0x8000) != 0 || (v6 & 0x1000) != 0 )
                {
                  v17 = *(_QWORD *)(v16 - 8);
                }
                else if( (v6 & 0x20) != 0 )
                {
                  if( (v6 & 0x40) != 0 )
                    v17 = *(__int16 *)(v16 - 8);
                  else
                    v17 = *(unsigned __int16 *)(v16 - 8);
                }
                else if( (v6 & 0x40) != 0 )
                {
                  v17 = *(int *)(v16 - 8);
                }
                else
                {
                  v17 = *(unsigned int *)(v16 - 8);
                }
                if( (v6 & 0x40) != 0 && v17 < 0 )
                {
                  v17 = -v17;
                  v6 |= 0x100u;
                }
                v25 = (unsigned int)v17;
                if( (v6 & 0x9000) != 0 )
                  v25 = v17;
                if( v7 >= 0 )
                {
                  v6 &= ~8u;
                  if( v7 > 512 )
                    v7 = 512;
                }
                else
                {
                  v7 = 1;
                }
                v26 = v62;
                v27 = (char *)&DstCh[255] + 1;
                v52 &= -(v25 != 0);
                v28 = v52;
                while( 1 )
                {
                  v29 = v7--;
                  if( v29 <= 0 && !v25 )
                    break;
                  v30 = v25 % v15;
                  v25 /= v15;
                  v31 = v30 + 48;
                  if( (int)v30 + 48 > 57 )
                    v31 = v30 + v26 + 48;
                  *v27-- = v31;
                }
                v53 = v7;
                LODWORD(v12) = (unsigned int)&DstCh[64] + 383 - (_DWORD)v27;
                v8 = (wchar_t *)(v27 + 1);
                if( (v6 & 0x200) != 0 )
                {
                  if( !(_DWORD)v12 || (v60 = (int *)v16, v52 = v28, *(_BYTE *)v8 != 48) )
                  {
                    v8 = (wchar_t *)((char *)v8 - 1);
                    v60 = (int *)v16;
                    LODWORD(v12) = v12 + 1;
                    v52 = v28;
                    *(_BYTE *)v8 = 48;
                  }
                }
                goto LABEL_110;
              }
            }
            else
            {
              if( v10 == 105 )
                goto LABEL_24;
              if( v10 == 67 )
              {
                if( (v6 & 0x830) == 0 )
                  v6 |= 0x20u;
                goto LABEL_53;
              }
              if( v10 != 83 )
              {
                if( v10 != 88 )
                {
                  if( v10 == 90 )
                  {
                    v18 = *(unsigned __int16 **)v9;
                    v60 = v9 + 2;
                    if( v18 && (v8 = (wchar_t *)*((_QWORD *)v18 + 1)) != 0i64 )
                    {
                      v19 = *v18;
                      if( v18[1] < (unsigned __int16)v19 )
                        goto LABEL_194;
                      LODWORD(v12) = *v18;
                      if( (v6 & 0x800) != 0 )
                      {
                        if( (v19 & 1) != 0 || ((unsigned __int8)v8 & 1) != 0 )
                          goto LABEL_194;
                        LODWORD(v12) = v19 >> 1;
                        v55 = 1;
                      }
                      else
                      {
                        v55 = 0;
                      }
                    }
                    else
                    {
                      v12 = -1i64;
                      v8 = (wchar_t *)"(null)";
                      do
                        ++v12;
                      while( aNull_2[v12] );
                    }
                    goto LABEL_110;
                  }
                  if( v10 != 99 )
                  {
                    if( v10 == 100 )
                    {
LABEL_24:
                      v6 |= 0x40u;
                      goto LABEL_25;
                    }
LABEL_110:
                    v33 = v50;
LABEL_111:
                    if( v33 )
                      goto LABEL_191;
                    if( (v6 & 0x40) != 0 )
                    {
                      if( (v6 & 0x100) != 0 )
                      {
                        v34 = 45;
                        goto LABEL_117;
                      }
                      if( (v6 & 1) != 0 )
                      {
                        v34 = 43;
LABEL_117:
                        v58[0] = v34;
LABEL_118:
                        v35 = 1;
                        v52 = 1;
LABEL_122:
                        v36 = v59 - v12 - v35;
                        if( (v6 & 0xC) == 0 )
                          write_multi_char(32i64, v36, v61, &v51);
                        write_string(v58, v35, v61, &v51);
                        v37 = v61;
                        if( (v6 & 0xC) == 8 )
                          write_multi_char(48i64, v36, v61, &v51);
                        if( v55 || (int)v12 <= 0 )
                        {
                          write_string(v8, (unsigned int)v12, v37, &v51);
LABEL_136:
                          v11 = v51;
                        }
                        else
                        {
                          v38 = (const char *)v8;
                          v39 = v12;
                          while( 1 )
                          {
                            --v39;
                            v40 = safecrt_mbtowc((wchar_t *)v54, v38, _mb_cur_max);
                            v41 = v40;
                            if( v40 == 2 )
                              --v39;
                            if( v40 <= 0 )
                              break;
                            write_char((unsigned __int16)v54[0], v61, &v51);
                            v38 += v41;
                            if( v39 <= 0 )
                            {
                              a2 = v63;
                              v37 = v61;
                              goto LABEL_136;
                            }
                          }
                          a2 = v63;
                          v11 = -1;
                          v37 = v61;
                          v51 = -1;
                        }
                        if( v11 >= 0 && (v6 & 4) != 0 )
                        {
                          write_multi_char(32i64, v36, v37, &v51);
                          v7 = v53;
                          goto LABEL_140;
                        }
                        v7 = v53;
LABEL_191:
                        v13 = v56;
                        break;
                      }
                      if( (v6 & 2) != 0 )
                      {
                        v58[0] = 32;
                        goto LABEL_118;
                      }
                    }
                    v35 = v52;
                    goto LABEL_122;
                  }
LABEL_53:
                  v22 = *(_WORD *)v9;
                  v54[0] = *(_WORD *)v9;
                  v55 = 1;
                  v60 = v9 + 2;
                  if( (v6 & 0x20) != 0 )
                  {
                    SrcCh[0] = v22;
                    SrcCh[1] = 0;
                    if( safecrt_mbtowc(DstCh, SrcCh, _mb_cur_max) < 0 )
                      v50 = 1;
                  }
                  else
                  {
                    DstCh[0] = v22;
                  }
                  v8 = DstCh;
                  LODWORD(v12) = 1;
                  goto LABEL_110;
                }
LABEL_73:
                v23 = 7;
LABEL_74:
                v62 = v23;
                if( (v6 & 0x80u) != 0 )
                {
                  v52 = 2;
                  v58[0] = 48;
                  v58[1] = v23 + 81;
                }
                v15 = 16i64;
                goto LABEL_26;
              }
              if( (v6 & 0x830) == 0 )
                v6 |= 0x20u;
            }
            v8 = *(wchar_t **)v9;
            v20 = v7;
            if( v7 == -1 )
              v20 = 0x7FFFFFFF;
            v60 = v9 + 2;
            if( (v6 & 0x20) != 0 )
            {
              v21 = (const char *)v8;
              if( !v8 )
              {
                v8 = (wchar_t *)"(null)";
                v21 = "(null)";
              }
              LODWORD(v12) = 0;
              if( v20 > 0 )
              {
                do
                {
                  if( !*v21 )
                    break;
                  ++v21;
                  LODWORD(v12) = v12 + 1;
                }
                while( (int)v12 < v20 );
              }
            }
            else
            {
              v55 = 1;
              v24 = L"(null)";
              if( v8 )
                v24 = v8;
              v8 = (wchar_t *)v24;
              while( v20 )
              {
                --v20;
                if( !*v24 )
                  break;
                ++v24;
              }
              LODWORD(v12) = v24 - v8;
            }
            goto LABEL_110;
        }
LABEL_192:
        v10 = *a2;
        v9 = v60;
      }
      while( *a2 );
    }
    return(unsigned int)v11;
  }
  else
  {
LABEL_194:
    xHalTimerWatchdogStop(0i64, 0i64);
    return 0xFFFFFFFFi64;
  }
}

Referenced by:

snwprintf
swprintf
vsnwprintf_l
vswprintf_l