请仔细阅读和分析下面函数,进行优化后,采用C/C++11标准,完整推导并重构可编译的全部代码
特别注意:
1.保持所有原始功能不变
2.提高执行效率,降低计算复杂度
3.已经给定的结构体名字和元素不要更改,详细的中文注释
4.自动添加中文注释说明功能逻辑
5.不使用 auto,使用显式 for 循环
6.结构体采用32位定义
7.不要使用小函数,保持原始的函数定义
8.严格保持protobuf字段映射关系
函数中的 HDDMXng::TileType::TileType 映射为
message TileType
{
optional uint32 numarcs = 1;
optional uint32 gidx = 2;
optional uint32 numwires = 3;
optional sint32 xmin = 4;
optional sint32 xmax = 5;
optional sint32 ymin = 6;
optional sint32 ymax = 7;
optional uint32 xgridextent = 8;
optional uint32 ygridextent = 9;
optional string gname = 10;
optional string hwname = 11;
repeated SiteChildDef sitechilddefs = 12;
repeated sint32 sitepin2wire = 13 [packed = true];
optional uint32 numtileports = 14;
}
将 _BYTE tileType_msg[16] 映射为 HDDMXng::TileType tileType_msg;
// Alternative name is '_ZN12HDDMTileTypeC2Ev'
void __fastcall HDDMTileType::HDDMTileType(HDDMTileType *this)
{
int dword4; // eax
dword4 = this->tileType_code1;
LOBYTE(this->tileType_code) &= 0xC0u;
LOWORD(this->tileType_code) |= 0xFFC0u;
HIWORD(this->tileType_code) = 0;
this->tileType_code2 = 0x7FFFFFFF;
this->tileType_code1 = dword4 & 0xFFF00000;
HIWORD(this->tileType_code1) = -16;
this->tileType_code3 = 0x7FFFFFFF;
this->tileType_code4 = 0x7FFFFFFF;
this->tileType_code5 = 0x7FFFFFFF;
LOWORD(this->tileType_code6) = 0;
this->name = (std::string *)((char *)&std::string::_Rep::_S_empty_rep_storage + 24);
this->name1 = (std::string *)((char *)&std::string::_Rep::_S_empty_rep_storage + 24);
HIWORD(this->tileType_code6) = 0;
LOWORD(this->tileType_code7) = 0;
this->qword60 = &this->char50;
this->qword68 = &this->char50;
this->hddmSiteChildDefVec = 0;
this->hddmTilePortVec = 0;
this->qword40 = 0;
LODWORD(this->char50) = 0;
this->qword58 = 0;
this->qword70 = 0;
this->hddmSiteTypeVec = 0;
this->qword80 = 0;
this->qword88 = 0;
this->ushortVec = 0;
this->qword98 = 0;
this->qwordA0 = 0;
this->qwordA8 = 0;
this->qwordB0 = 0;
this->qwordB8 = 0;
this->qwordC0 = 0;
this->qwordC8 = 0;
this->qwordD0 = 0;
this->qwordE8 = 0;
this->qwordF0 = 0;
this->qwordF8 = 0;
this->qword100 = 0;
this->qword108 = 0;
this->qword110 = 0;
this->qword118 = 0;
this->qword120 = 0;
this->qword128 = 0;
this->qword130 = 0;
this->qword138 = 0;
this->qword140 = 0;
this->qword148 = 0;
this->qword150 = 0;
this->qword158 = 0;
this->qword160 = 0;
this->qword168 = 0;
this->qword170 = 0;
this->qword178 = 0;
this->qword180 = 0;
this->qword188 = 0;
this->qword190 = 0;
this->qword198 = 0;
this->qword1A0 = 0;
this->qword1A8 = 0;
this->qword1B0 = 0;
this->qword1B8 = 0;
LODWORD(this->gap1C0[1]) = 0;
this->gap1C0[2] = 0;
this->gap1C0[5] = 0;
this->gap1C0[3] = &this->gap1C0[1];
this->gap1C0[4] = &this->gap1C0[1];
LODWORD(this->gap1C0[7]) = 0;
this->qword200 = 0;
this->qword208 = &this->gap1C0[7];
this->qword210 = &this->gap1C0[7];
this->qword218 = 0;
this->qword228 = 0;
this->qword258 = &this->char248;
this->qword260 = &this->char248;
this->qword230 = 0;
this->qword238 = 0;
LODWORD(this->char248) = 0;
this->qword250 = 0;
this->qword268 = 0;
LODWORD(this->char278) = 0;
this->qword280 = 0;
this->qword298 = 0;
this->qword288 = &this->char278;
this->qword290 = &this->char278;
this->hddmArcVec = 0;
this->hddmWireVec = 0;
LOWORD(this->word220) = 16;
}
void __fastcall HDDMTileType::readme_pb(
HDDMTileType *this,
std::istream *stream,
HDDMDevice *hddmDevice,
__int64 a4,
__int64 a5)
{
google::protobuf::Message *v6; // rdx
__int16 v7; // dx
std::string *v8; // rsi
__int16 v9; // ax
int n0x7FFFFFFF; // edx
char v11; // al
int n0x7FFFFFFF_2; // edx
int n0x7FFFFFFF_4; // edx
bool v14; // zf
__int16 word18; // ax
int n0x7FFFFFFF_6; // edx
__int16 word1A; // ax
unsigned __int64 v18; // rbx
__int64 qwordC0; // rdx
unsigned __int64 v20; // rax
__int64 *qwordB0; // rbp
__int64 qwordA8; // rdx
unsigned __int64 v23; // rax
__int64 *qwordB0_3; // r13
__int64 *qwordB0_1; // rbx
void *p__ZNSs4_Rep20_S_empty_rep_storageE; // rdi
__int64 v27; // rbp
__int64 qword38_1; // rax
__int64 v29; // rax
_DWORD *v30; // rax
HDDMTilePort *v31; // rbx
HDDMTilePort **hddmTilePortVec; // rax
__int64 v33; // r12
int word1C_1; // ebx
__int64 v35; // rbp
__int64 v36; // rbp
int word2_1; // ebx
__int64 v38; // r12
int v39; // r13d
__int64 v40; // rbp
int word1C_2; // r12d
_WORD *ushortVec; // rdx
int v43; // eax
int v44; // esi
__int64 qword200; // rdx
char *p_char1F8; // rsi
__int64 p_char1F8_1; // rax
__int64 v48; // rdx
char v49; // al
int v50; // r14d
HDDMTileFace *v51; // rbx
const HDDMWire *v52; // rbp
HDDMTilePort *v53; // r12
HDDMTilePort **v54; // rax
__int64 v55; // rax
google::protobuf::Message *v56; // rdx
__int64 *qwordB0_2; // r14
__int64 v58; // rax
void *p__ZNSs4_Rep20_S_empty_rep_storageE_1; // rdi
int v60; // edx
unsigned int hddmDeviceb; // [rsp+0h] [rbp-1A8h]
unsigned int v64; // [rsp+10h] [rbp-198h]
__int64 v65; // [rsp+18h] [rbp-190h]
int v66; // [rsp+18h] [rbp-190h]
int v67; // [rsp+20h] [rbp-188h]
unsigned __int16 v69; // [rsp+3Ch] [rbp-16Ch]
unsigned __int16 v70; // [rsp+3Eh] [rbp-16Ah]
char v71; // [rsp+5Fh] [rbp-149h] BYREF
_QWORD v72[2]; // [rsp+60h] [rbp-148h] BYREF
_QWORD v73[2]; // [rsp+70h] [rbp-138h] BYREF
HDDMTilePort *v74[2]; // [rsp+80h] [rbp-128h] BYREF
_QWORD v75[2]; // [rsp+90h] [rbp-118h] BYREF
int v76; // [rsp+A0h] [rbp-108h]
int v77; // [rsp+A4h] [rbp-104h]
unsigned int hddmDeviceb_1; // [rsp+A8h] [rbp-100h]
unsigned int v79; // [rsp+ACh] [rbp-FCh]
int word1C_3; // [rsp+B0h] [rbp-F8h]
char v81; // [rsp+B8h] [rbp-F0h]
_BYTE tileType_msg[16]; // [rsp+C0h] [rbp-E8h] BYREF
int word2; // [rsp+D0h] [rbp-D8h]
__int16 v84; // [rsp+D4h] [rbp-D4h]
int word1C; // [rsp+D8h] [rbp-D0h]
int n0x7FFFFFFF_1; // [rsp+DCh] [rbp-CCh]
int n0x7FFFFFFF_3; // [rsp+E0h] [rbp-C8h]
int n0x7FFFFFFF_5; // [rsp+E4h] [rbp-C4h]
int n0x7FFFFFFF_7; // [rsp+E8h] [rbp-C0h]
int word18_1; // [rsp+ECh] [rbp-BCh]
std::string *v91; // [rsp+F0h] [rbp-B8h]
std::string *v92; // [rsp+F8h] [rbp-B0h]
int word1A_1; // [rsp+100h] [rbp-A8h]
int v94; // [rsp+104h] [rbp-A4h]
__int64 v95; // [rsp+108h] [rbp-A0h]
int v96; // [rsp+110h] [rbp-98h]
__int64 v97; // [rsp+140h] [rbp-68h]
int v98; // [rsp+148h] [rbp-60h]
int v99; // [rsp+168h] [rbp-40h]
if ( HDDMDeviceDump::useXngMarks )
std::istream::read(stream, HDDMDeviceDump::markBuffer, 8);
if ( !(_BYTE)byte_992F640 && __cxa_guard_acquire(&byte_992F640) )
{
dword_992F530 = HDDMTileType::createtypenamemap((HDDMTileType *)&byte_992F640);
__cxa_guard_release(&byte_992F640);
}
HDDMXng::TileType::TileType((HDDMXng::TileType *)tileType_msg);
HDDMDevice::readMessage((HDDMDevice *)stream, (std::istream *)tileType_msg, v6);
v7 = v84;
v8 = v91;
HIWORD(this->tileType_code) = word2;
v9 = (v7 << 6) | this->tileType_code & 0x3F;
n0x7FFFFFFF = 0x7FFFFFFF;
LOWORD(this->tileType_code) = v9;
LOWORD(this->tileType_code7) = word1C;
v11 = v99;
if ( (v99 & 8) != 0 )
n0x7FFFFFFF = n0x7FFFFFFF_1;
this->tileType_code2 = n0x7FFFFFFF;
n0x7FFFFFFF_2 = 0x7FFFFFFF;
if ( (v11 & 0x10) != 0 )
n0x7FFFFFFF_2 = n0x7FFFFFFF_3;
this->tileType_code3 = n0x7FFFFFFF_2;
n0x7FFFFFFF_4 = 0x7FFFFFFF;
if ( (v11 & 0x20) != 0 )
n0x7FFFFFFF_4 = n0x7FFFFFFF_5;
v14 = (v11 & 0x40) == 0;
word18 = word18_1;
this->tileType_code4 = n0x7FFFFFFF_4;
n0x7FFFFFFF_6 = 0x7FFFFFFF;
if ( !v14 )
n0x7FFFFFFF_6 = n0x7FFFFFFF_7;
LOWORD(this->tileType_code6) = word18;
word1A = word1A_1;
this->tileType_code5 = n0x7FFFFFFF_6;
HIWORD(this->tileType_code6) = word1A;
std::string::assign((std::string *)&this->name, v8);
std::string::assign((std::string *)&this->name1, v92);
HDDMTileType::settypeenum(this);
v18 = v96;
v67 = v96;
std::vector<HDDMSiteType *>::resize(&this->hddmSiteTypeVec, v96);
std::vector<unsigned short>::resize(&this->ushortVec, v18);
qwordC0 = this->qwordC0;
v20 = (this->qwordC8 - qwordC0) >> 2;
if ( v18 > v20 )
{
std::vector<std::pair<short,short>>::_M_default_append(&this->qwordC0, v18 - v20);
}
else if ( v18 < v20 )
{
this->qwordC8 = qwordC0 + 4 * v18;
}
qwordB0 = (__int64 *)this->qwordB0;
qwordA8 = this->qwordA8;
v23 = ((__int64)qwordB0 - qwordA8) >> 3;
if ( v18 > v23 )
{
std::vector<std::string>::_M_default_append(&this->qwordA8, v18 - v23);
}
else if ( v18 < v23 )
{
qwordB0_3 = (__int64 *)(qwordA8 + 8 * v18);
if ( qwordB0 != qwordB0_3 )
{
if ( &_pthread_key_create )
{
qwordB0_1 = (__int64 *)(qwordA8 + 8 * v18);
do
{
p__ZNSs4_Rep20_S_empty_rep_storageE = (void *)(*qwordB0_1 - 24);
if ( p__ZNSs4_Rep20_S_empty_rep_storageE != &std::string::_Rep::_S_empty_rep_storage
&& _InterlockedExchangeAdd((volatile signed __int32 *)(*qwordB0_1 - 8), 0xFFFFFFFF) <= 0 )
{
std::string::_Rep::_M_destroy(p__ZNSs4_Rep20_S_empty_rep_storageE, v75);
}
++qwordB0_1;
}
while ( qwordB0 != qwordB0_1 );
}
else
{
qwordB0_2 = (__int64 *)(qwordA8 + 8 * v18);
do
{
v58 = *qwordB0_2;
p__ZNSs4_Rep20_S_empty_rep_storageE_1 = (void *)(*qwordB0_2 - 24);
if ( p__ZNSs4_Rep20_S_empty_rep_storageE_1 != &std::string::_Rep::_S_empty_rep_storage )
{
v60 = *(_DWORD *)(v58 - 8);
*(_DWORD *)(v58 - 8) = v60 - 1;
if ( v60 <= 0 )
std::string::_Rep::_M_destroy(p__ZNSs4_Rep20_S_empty_rep_storageE_1, v75);
}
++qwordB0_2;
}
while ( qwordB0 != qwordB0_2 );
}
}
this->qwordB0 = qwordB0_3;
}
if ( v67 > 0 )
{
v27 = 0;
do
{
v29 = *(_QWORD *)(v95 + 8 * v27);
*(_QWORD *)(this->hddmSiteTypeVec + 8 * v27) = *(_QWORD *)(hddmDevice->qword90
+ 8LL * *(unsigned __int16 *)(v29 + 24));
*(_WORD *)(this->ushortVec + 2 * v27) = *(_DWORD *)(v29 + 28);
*(_WORD *)(this->qwordC0 + 4 * v27) = *(_DWORD *)(v29 + 32);
*(_WORD *)(this->qwordC0 + 4 * v27 + 2) = *(_DWORD *)(v29 + 36);
std::string::assign((std::string *)(this->qwordA8 + 8 * v27), *(const std::string **)(v29 + 16));
std::string::string((std::string *)v72, (const std::string *)(this->qwordA8 + 8 * v27));
v65 = *(_QWORD *)(this->hddmSiteTypeVec + 8 * v27);
v30 = (_DWORD *)operator new(0x40u);
*(_QWORD *)v30 = this;
v30[2] = (unsigned __int16)v27;
v31 = (HDDMTilePort *)v30;
std::string::string((std::string *)(v30 + 4), (const std::string *)v72);
*((_QWORD *)v31 + 5) = 0;
*((_QWORD *)v31 + 6) = 0;
*((_QWORD *)v31 + 7) = 0;
*((_QWORD *)v31 + 4) = v31;
*((_QWORD *)v31 + 3) = v65;
v74[0] = v31;
std::string::_Rep::_M_dispose(v72[0] - 24LL, v75);
hddmTilePortVec = (HDDMTilePort **)this->hddmTilePortVec;
if ( hddmTilePortVec == (HDDMTilePort **)this->qword40 )
{
std::vector<HDDMSiteChildDef *>::_M_emplace_back_aux<HDDMSiteChildDef * const&>(&this->hddmSiteChildDefVec, v74);
}
else
{
if ( hddmTilePortVec )
{
*hddmTilePortVec = v74[0];
qword38_1 = this->hddmTilePortVec;
}
else
{
qword38_1 = 0;
}
this->hddmTilePortVec = qword38_1 + 8;
}
std::string::string((std::string *)v75, (const std::string *)(this->qwordA8 + 8 * v27));
v75[1] = v74[0];
std::_Rb_tree<std::string,std::pair<std::string const,HDDMSiteChildDef *>,std::_Select1st<std::pair<std::string const,HDDMSiteChildDef *>>,std::less<std::string>,std::allocator<std::pair<std::string const,HDDMSiteChildDef *>>>::_M_insert_unique<std::pair<std::string,HDDMSiteChildDef *>>(
&this->field_48,
v75);
++v27;
std::string::_Rep::_M_dispose(v75[0] - 24LL, v73);
}
while ( v67 > (int)v27 );
}
HDDMTileType::allocatewires(this, this->tileType_code7);
v33 = 0;
word1C_1 = 0;
if ( LOWORD(this->tileType_code7) )
{
do
{
v35 = this->hddmWireVec + v33;
HDDMWire::readme_pb(v35, stream, hddmDevice, a5);
*(_WORD *)(v35 + 10) = word1C_1;
std::string::string((std::string *)v73, (const std::string *)(v35 + 32));
*(_WORD *)std::map<std::string,unsigned short>::operator[](this->gap1C0, v73) = word1C_1++;
v33 += 88;
std::string::_Rep::_M_dispose(v73[0] - 24LL, v75);
}
while ( LOWORD(this->tileType_code7) > word1C_1 );
}
HDDMTileType::allocatearcs(this, HIWORD(this->tileType_code));
v36 = 0;
word2_1 = 0;
if ( HIWORD(this->tileType_code) )
{
do
{
v38 = this->hddmArcVec + v36;
HDDMArc::readme_pb((HDDMArc *)v38, stream, hddmDevice);
*(_WORD *)(v38 + 6) = word2_1++;
v36 += 24;
}
while ( HIWORD(this->tileType_code) > word2_1 );
}
v39 = v98;
std::vector<unsigned short>::resize(&this->qword1A8, v98);
v40 = 0;
if ( v39 > 0 )
{
while ( 1 )
{
while ( 1 )
{
word1C_2 = *(_DWORD *)(v97 + 4 * v40);
if ( word1C_2 >= 0 )
break;
LABEL_59:
if ( v39 <= (int)++v40 )
goto LABEL_60;
}
*(_WORD *)(this->qword1A8 + 2 * v40) = word1C_2;
if ( (_WORD)v67 )
{
ushortVec = (_WORD *)this->ushortVec;
v43 = 1;
while ( 1 )
{
v44 = v43;
if ( (unsigned __int16)v40 >= *ushortVec
&& ((unsigned __int16)v67 == v43 || (unsigned __int16)v40 < ushortVec[1]) )
{
break;
}
++ushortVec;
++v43;
if ( (unsigned __int16)v67 <= v44 )
goto LABEL_47;
}
v70 = v43 - 1;
v69 = v40 - *ushortVec;
}
LABEL_47:
qword200 = this->qword200;
LOWORD(v75[0]) = word1C_2;
p_char1F8 = (char *)&this->gap1C0[7];
if ( !qword200 )
goto LABEL_75;
do
{
while ( (unsigned __int16)word1C_2 <= *(_WORD *)(qword200 + 32) )
{
p_char1F8 = (char *)qword200;
qword200 = *(_QWORD *)(qword200 + 16);
if ( !qword200 )
goto LABEL_52;
}
qword200 = *(_QWORD *)(qword200 + 24);
}
while ( qword200 );
LABEL_52:
if ( &this->gap1C0[7] == (_QWORD *)p_char1F8 || (unsigned __int16)word1C_2 < *((_WORD *)p_char1F8 + 16) )
{
LABEL_75:
v74[0] = (HDDMTilePort *)v75;
p_char1F8_1 = std::_Rb_tree<unsigned short,std::pair<unsigned short const,std::pair<unsigned short,unsigned short>>,std::_Select1st<std::pair<unsigned short const,std::pair<unsigned short,unsigned short>>>,std::less<unsigned short>,std::allocator<std::pair<unsigned short const,std::pair<unsigned short,unsigned short>>>>::_M_emplace_hint_unique<std::piecewise_construct_t const&,std::tuple<unsigned short &&>,std::tuple<>>(
&this->gap1C0[6],
p_char1F8,
&qword_7B6AC49,
v74,
&v71,
word1C_2);
}
else
{
p_char1F8_1 = (__int64)p_char1F8;
}
*(_WORD *)(p_char1F8_1 + 34) = v70;
*(_WORD *)(p_char1F8_1 + 36) = v69;
v48 = 0;
if ( LOWORD(this->tileType_code7) > (unsigned __int16)word1C_2 )
v48 = this->hddmWireVec + 88LL * (unsigned __int16)word1C_2;
v49 = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)(this->hddmSiteTypeVec + 8LL * v70) + 24LL) + 16LL * v69 + 5) & 0xC0;
switch ( v49 )
{
case 0:
*(_BYTE *)(v48 + 2) |= 5u;
goto LABEL_59;
case 0x80:
++v40;
*(_BYTE *)(v48 + 2) |= 6u;
if ( v39 <= (int)v40 )
goto LABEL_60;
break;
case 0x40:
++v40;
*(_BYTE *)(v48 + 2) |= 7u;
if ( v39 <= (int)v40 )
goto LABEL_60;
break;
default:
goto LABEL_59;
}
}
}
LABEL_60:
HDDMTileType::createedgeds(this);
HDDMTileType::createwirearcs(this, hddmDevice);
HDDMTileType::marknulltiles(this);
HDDMTileType::allocatetileports(this);
v66 = v94;
if ( v94 )
{
if ( HDDMDeviceDump::useXngMarks )
std::istream::read(stream, HDDMDeviceDump::markBuffer, 5);
v50 = 0;
do
{
HDDMXng::TilePort::TilePort((HDDMXng::TilePort *)v75);
HDDMDevice::readMessage((HDDMDevice *)stream, (std::istream *)v75, v56);
hddmDeviceb = hddmDeviceb_1;
v64 = v79;
if ( (v81 & 0x10) != 0 )
{
v51 = *(HDDMTileFace **)(*(_QWORD *)(*(_QWORD *)(this->qword228 + 8LL * (unsigned __int16)v76) + 24LL)
+ 8LL * (unsigned __int16)v77);
if ( (unsigned __int16)word1C_3 >= LOWORD(this->tileType_code7) )
v52 = 0;
else
v52 = (const HDDMWire *)(this->hddmWireVec + 88LL * (unsigned __int16)word1C_3);
}
else
{
v52 = 0;
v51 = *(HDDMTileFace **)(*(_QWORD *)(*(_QWORD *)(this->qword228 + 8LL * (unsigned __int16)v76) + 24LL)
+ 8LL * (unsigned __int16)v77);
}
v53 = (HDDMTilePort *)operator new(0x18u);
HDDMTilePort::HDDMTilePort(v53, v51, hddmDeviceb, v64, v52);
v74[0] = v53;
v54 = (HDDMTilePort **)*((_QWORD *)v51 + 4);
if ( v54 == *((HDDMTilePort ***)v51 + 5) )
{
std::vector<HDDMTilePort *>::_M_emplace_back_aux<HDDMTilePort * const&>((char *)v51 + 24, v74);
}
else
{
if ( v54 )
{
*v54 = v53;
v55 = *((_QWORD *)v51 + 4);
}
else
{
v55 = 0;
}
*((_QWORD *)v51 + 4) = v55 + 8;
}
if ( v52 )
HDDMWire::addtileport(v52, v74[0]);
++v50;
HDDMXng::TilePort::~TilePort((HDDMXng::TilePort *)v75);
}
while ( v50 != v66 );
}
HDDMXng::TileType::~TileType((HDDMXng::TileType *)tileType_msg);
}
最新发布