v49 = 0;
  if ( argc >= 2 )
  {
    v3 = (char *)argv[1];
    v63[0] = 0;
    v64 = 0;
    v65 = 15;
    v76 = -1;
    sub_407C80(v63, v3, strlen(v3));
    v76 = 1;
    v48 = v64;
    v4 = unknown_libname_5(v64);
    v5 = v48;
    v6 = v63;
    v49 = v4;
    Size = 0;
    if ( v65 >= 0x10 )
      v6 = (void **)v63[0];
    v51 = (unsigned int)v6;
    qmemcpy(v70, &unk_431950, sizeof(v70));
    if ( v48 )
    {
      v7 = v4;
      v8 = v51 - v4;
      v51 = v48;
      LOBYTE(v9) = 0;
      do
      {
        v9 = (unsigned __int8)(v9 + 1);
        ++v7;
        v10 = v70[v9];
        Size = (unsigned __int8)(Size + v10);
        v70[v9] = v70[Size];
        v70[Size] = v10;
        v11 = *(_BYTE *)(v8 + v7 - 1) ^ v70[(unsigned __int8)(v70[v9] + v10)];
        v12 = v51-- == 1;
        *(_BYTE *)(v7 - 1) = v11;
      }
      while ( !v12 );
      v5 = v48;
    }
    v13 = (_BYTE *)unknown_libname_5(4 * ((v5 + 2) / 3) + 1);
    Block = v13;
    memset(Destination, 0, 0x41u);
    strcpy_s(Destination, 0x41u, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-");
    v14 = v48;
    v15 = 0;
    Size = 0;
    for ( i = 0; i < v48; v14 = v48 )
    {
      for ( j = 0; j < 3; ++j )
      {
        if ( i >= v14 )
        {
          if ( (unsigned int)j >= 3 )
          {
            __report_rangecheckfailure();
            goto LABEL_62;
          }
          ++v15;
          v19 = 0;
          Size = v15;
        }
        else
        {
          v18 = (char *)v49++;
          ++i;
          v19 = *v18;
        }
        *(&v45 + j) = v19;
        v14 = v48;
      }
      LOBYTE(v51) = (v45 >> 2) & 0x3F;
      BYTE1(v51) = (16 * (v45 & 3)) | (v46 >> 4) & 0xF;
      HIBYTE(v51) = v47 & 0x3F;
      v20 = 0;
      v15 = Size;
      BYTE2(v51) = (4 * (v46 & 0xF)) | (v47 >> 6) & 3;
      if ( Size != 4 )
      {
        v21 = 4 - Size;
        do
        {
          v22 = *((char *)&v51 + v20++);
          *v13++ = Destination[v22];
        }
        while ( v20 < v21 );
        v15 = Size;
      }
      if ( v15 )
      {
        memset(v13, 61, v15);
        v15 = Size;
        v13 += Size;
      }
    }
    *v13 = 0;
    Src[0] = 0;
    v67 = 0;
    v68 = 15;
    LOBYTE(v76) = 1;
    sub_407C80(Src, Block, strlen((const char *)Block));
    LOBYTE(v76) = 3;
    j_j__free(Block);
    if ( v68 - v67 < 0xA )
    {
      sub_408B40(Src, 10, (int)Block, (int)".encrypted", 0xAu);
    }
    else
    {
      v23 = Src;
      if ( v68 >= 0x10 )
        v23 = (void **)Src[0];
      v24 = (char *)v23 + v67;
      v67 += 10;
      memmove(v24, ".encrypted", 0xAu);
      v24[10] = 0;
    }
    sub_4053E0(v63, (int)v72);
    memset(v59, 0, sizeof(v59));
    v54 = 8;
    v55 = *(_OWORD *)v72;
    v61 = v59;
    v56 = v73;
    v60 = 0;
    v57 = v74;
    v58 = v75;
    memset(v52, 0, sizeof(v52));
    LODWORD(v52[0]) = &unk_431A60;
    LODWORD(v52[15]) = 0;
    memset(&v52[19], 0, 12);
    LOBYTE(v76) = 4;
    v49 = 1;
    LODWORD(v52[14]) = &std::istream::`vftable';
    HIDWORD(v52[13]) = 88;
    v52[1] = 0i64;
    sub_408120((struct std::ios_base *)&v52[14], (int)&v52[2], 0);
    v76 = 6;
    *(_DWORD *)((char *)v52 + *(_DWORD *)(LODWORD(v52[0]) + 4)) = &std::ifstream::`vftable';
    *(unsigned int *)((char *)&v51 + *(_DWORD *)(LODWORD(v52[0]) + 4)) = *(_DWORD *)(LODWORD(v52[0]) + 4) - 112;
    sub_407A80();
    LOBYTE(v76) = 7;
    v26 = v63;
    if ( v65 >= 0x10 )
      v26 = (void **)v63[0];
    v12 = sub_407DF0(v26, 33, v25) == 0;
    v27 = *(_DWORD *)(LODWORD(v52[0]) + 4);
    if ( v12 )
    {
      v29 = *(_DWORD *)((char *)&v52[1] + v27 + 4) | (4 * (*(_DWORD *)((char *)&v52[7] + v27) == 0) + 2);
    }
    else
    {
      v28 = (char *)v52 + v27;
      v29 = 4;
      if ( *((_DWORD *)v28 + 14) )
        v29 = 0;
    }
    sub_4052A0(v29, 0);
    memset(v62, 0, sizeof(v62));
    v62[0] = (int)&unk_431A58;
    v62[28] = 0;
    memset(&v62[36], 0, 12);
    LOBYTE(v76) = 8;
    v49 = 5;
    v62[26] = (int)&std::ostream::`vftable';
    v62[25] = 96;
    sub_408120((struct std::ios_base *)&v62[26], (int)&v62[1], 0);
    v76 = 10;
    *(int *)((char *)v62 + *(_DWORD *)(v62[0] + 4)) = (int)&std::ofstream::`vftable';
    *(int *)((char *)&v62[-1] + *(_DWORD *)(v62[0] + 4)) = *(_DWORD *)(v62[0] + 4) - 104;
    sub_407A80();
    LOBYTE(v76) = 11;
    v31 = Src;
    if ( v68 >= 0x10 )
      v31 = (void **)Src[0];
    v12 = sub_407DF0(v31, 34, v30) == 0;
    v32 = *(_DWORD *)(v62[0] + 4);
    if ( v12 )
    {
      v34 = *(int *)((char *)&v62[3] + v32) | (4 * (*(int *)((char *)&v62[14] + v32) == 0) + 2);
    }
    else
    {
      v33 = (char *)v62 + v32;
      v34 = 4;
      if ( *((_DWORD *)v33 + 14) )
        v34 = 0;
    }
    sub_4052A0(v34, 0);
    if ( HIDWORD(v52[11]) && v62[20] )
    {
      while ( (*((_BYTE *)&v52[1] + *(_DWORD *)(LODWORD(v52[0]) + 4) + 4) & 1) == 0 )
      {
        sub_406E30(v69, v42, v43);
        v35 = v52[1];
        v36 = 0;
        if ( LODWORD(v52[1]) )
        {
          v37 = v61;
          v38 = v60;
          do
          {
            if ( !v38 )
            {
              sub_40C250(&v54, v37);
              v37 = v61;
              v38 = v60;
            }
            --v38;
            v69[v36++] ^= *v37++;
            v61 = v37;
            v60 = v38;
          }
          while ( v36 < v35 );
        }
        sub_406F90(v69, v35, 0);
      }
      sub_406F90(v71, 32, 0);
    }
    *(int *)((char *)v62 + *(_DWORD *)(v62[0] + 4)) = (int)&std::ofstream::`vftable';
    *(int *)((char *)&v62[-1] + *(_DWORD *)(v62[0] + 4)) = *(_DWORD *)(v62[0] + 4) - 104;
    sub_406A30();
    *(int *)((char *)v62 + *(_DWORD *)(v62[0] + 4)) = (int)&std::ostream::`vftable';
    *(int *)((char *)&v62[-1] + *(_DWORD *)(v62[0] + 4)) = *(_DWORD *)(v62[0] + 4) - 8;
    LOBYTE(v76) = 12;
    v62[26] = (int)&std::ios_base::`vftable';
    std::ios_base::_Ios_base_dtor((struct std::ios_base *)&v62[26]);
    *(_DWORD *)((char *)v52 + *(_DWORD *)(LODWORD(v52[0]) + 4)) = &std::ifstream::`vftable';
    *(unsigned int *)((char *)&v51 + *(_DWORD *)(LODWORD(v52[0]) + 4)) = *(_DWORD *)(LODWORD(v52[0]) + 4) - 112;
    sub_406A30();
    *(_DWORD *)((char *)v52 + *(_DWORD *)(LODWORD(v52[0]) + 4)) = &std::istream::`vftable';
    *(unsigned int *)((char *)&v51 + *(_DWORD *)(LODWORD(v52[0]) + 4)) = *(_DWORD *)(LODWORD(v52[0]) + 4) - 24;
    LOBYTE(v76) = 13;
    LODWORD(v52[14]) = &std::ios_base::`vftable';
    std::ios_base::_Ios_base_dtor((struct std::ios_base *)&v52[14]);
    if ( v68 >= 0x10 )
    {
      v39 = Src[0];
      if ( v68 + 1 >= 0x1000 )
      {
        v39 = (void *)*((_DWORD *)Src[0] - 1);
        if ( (unsigned int)(Src[0] - v39 - 4) > 0x1F )
          goto LABEL_62;
      }
      sub_40E0C5(v39);
    }
    v67 = 0;
    v68 = 15;
    LOBYTE(Src[0]) = 0;
    if ( v65 < 0x10 )
      return 0;
    v40 = v63[0];
    if ( v65 + 1 < 0x1000 || (v40 = (void *)*((_DWORD *)v63[0] - 1), (unsigned int)(v63[0] - v40 - 4) <= 0x1F) )
    {
      sub_40E0C5(v40);
      return 0;
    }
LABEL_62:
    _invalid_parameter_noinfo_noreturn();
  }
  sub_4083D0();
  sub_4083D0();
  sub_408640();
  sub_4083D0();
  return 0;
}

solve this ctf task