请仔细阅读和分析下面函数,进行优化后,采用C/C++11标准,完整推导并重构可编译的全部代码
特别注意:
1.确保所有函数调用和逻辑完整保留
2.提高执行效率,降低计算复杂度
3.详细的注释,使用中文
4.不使用auto,使用显式for循环
5.结构体采用32位定义
6.不拆分函数,保持一个大函数内
7.严格保持protobuf字段映射关系
8.使用protobuf反射方式读取数据
void __fastcall HDDMTileType::allocatetileports(HDDMTileType *this)
{
__int64 n4; // rbx
char **v2; // r12
__int64 v3; // rax
HDDMTileEdge *v4; // rbp
HDDMTileEdge **qword230; // rax
bool v6; // zf
__int64 qword230_1; // rax
HDDMTileType *p_char248; // rbp
HDDMTileType *qword250; // r12
__int64 p_char248_1; // rax
int tileType_code6_high; // eax
int tileType_code6_high_2; // r13d
char *v13; // rbp
char *v14; // r14
__int64 v15; // rax
HDDMTileFace *v16; // rbp
HDDMTileEdge *v17; // rax
HDDMTileFace **qword20; // rdx
__int64 qword20_1; // rdx
HDDMTileEdge *v20; // r14
HDDMTileEdge *qword40; // r15
HDDMTileEdge *p_char38; // rbp
__int64 p_char38_1; // rax
__int64 qword28; // r15
HDDMTileEdge *qword280; // r14
HDDMTileEdge *p_char278; // rbp
__int64 p_char278_1; // rax
char **v28; // [rsp+0h] [rbp-268h]
__int64 n4_1; // [rsp+30h] [rbp-238h]
int tileType_code6_high_1; // [rsp+48h] [rbp-220h]
char v31; // [rsp+6Eh] [rbp-1FAh] BYREF
char v32; // [rsp+6Fh] [rbp-1F9h] BYREF
_QWORD v33[2]; // [rsp+70h] [rbp-1F8h] BYREF
HDDMTileEdge *v34; // [rsp+80h] [rbp-1E8h] BYREF
_QWORD v35[2]; // [rsp+90h] [rbp-1D8h] BYREF
_QWORD v36[2]; // [rsp+A0h] [rbp-1C8h] BYREF
_QWORD *v37; // [rsp+B0h] [rbp-1B8h] BYREF
_QWORD v38[2]; // [rsp+C0h] [rbp-1A8h] BYREF
char *v39; // [rsp+D0h] [rbp-198h] BYREF
char *v40; // [rsp+D8h] [rbp-190h]
__int64 v41; // [rsp+E0h] [rbp-188h]
__int64 v42; // [rsp+E8h] [rbp-180h]
__int64 v43; // [rsp+F0h] [rbp-178h]
__int64 v44; // [rsp+F8h] [rbp-170h]
__int64 v45; // [rsp+100h] [rbp-168h]
__int64 v46; // [rsp+108h] [rbp-160h]
int n16; // [rsp+118h] [rbp-150h]
char *v48; // [rsp+120h] [rbp-148h]
char *v49; // [rsp+128h] [rbp-140h]
__int64 v50; // [rsp+200h] [rbp-68h]
char v51; // [rsp+208h] [rbp-60h]
char v52; // [rsp+209h] [rbp-5Fh]
__int64 v53; // [rsp+210h] [rbp-58h]
__int64 v54; // [rsp+218h] [rbp-50h]
__int64 v55; // [rsp+220h] [rbp-48h]
__int64 v56; // [rsp+228h] [rbp-40h]
n4 = *(_QWORD *)(qword_992F660 - 24LL);
std::vector<HDDMTileEdge *>::reserve(&this->qword228, (int)n4);
if ( (int)n4 > 0 )
{
v2 = &v39;
n4_1 = 0;
while ( 1 )
{
v3 = qword_992F660;
if ( *(int *)(qword_992F660 - 8LL) >= 0 )
{
std::string::_M_leak_hard((std::string *)&qword_992F660);
v3 = qword_992F660;
}
std::string::string(v33, 1, (unsigned int)*(char *)(v3 + n4_1), v2);
v4 = (HDDMTileEdge *)operator new(0x60u);
HDDMTileEdge::HDDMTileEdge(v4, this, n4_1, (const std::string *)v33);
qword230 = (HDDMTileEdge **)this->qword230;
v6 = qword230 == (HDDMTileEdge **)this->qword238;
v34 = v4;
if ( v6 )
{
std::vector<HDDMTileEdge *>::_M_emplace_back_aux<HDDMTileEdge * const&>(&this->qword228, &v34);
}
else
{
if ( qword230 )
{
*qword230 = v4;
qword230_1 = this->qword230;
}
else
{
qword230_1 = 0;
}
this->qword230 = qword230_1 + 8;
}
p_char248 = (HDDMTileType *)&this->char248;
if ( !this->qword250 )
goto LABEL_49;
v28 = v2;
qword250 = (HDDMTileType *)this->qword250;
do
{
while ( (int)std::string::compare((std::string *)&qword250->gname, (const std::string *)v33) >= 0 )
{
p_char248 = qword250;
qword250 = *(HDDMTileType **)&qword250->tileType_code4;
if ( !qword250 )
goto LABEL_14;
}
qword250 = *(HDDMTileType **)&qword250->tileType_code6;
}
while ( qword250 );
LABEL_14:
v2 = v28;
if ( &this->char248 == (_QWORD *)p_char248
|| (int)std::string::compare((std::string *)v33, (const std::string *)&p_char248->gname) < 0 )
{
LABEL_49:
v39 = (char *)v33;
p_char248_1 = std::_Rb_tree<std::string,std::pair<std::string const,HDDMTileEdge *>,std::_Select1st<std::pair<std::string const,HDDMTileEdge *>>,std::less<std::string>,std::allocator<std::pair<std::string const,HDDMTileEdge *>>>::_M_emplace_hint_unique<std::piecewise_construct_t const&,std::tuple<std::string const&>,std::tuple<>>(
this->gap240,
p_char248,
&qword_7B6AC49,
v2,
v36);
}
else
{
p_char248_1 = (__int64)p_char248;
}
*(_QWORD *)(p_char248_1 + 40) = v34;
if ( (_DWORD)n4_1 == 4 )
break;
if ( (n4_1 & 1) != 0 )
tileType_code6_high = HIWORD(this->tileType_code6);
else
tileType_code6_high = LOWORD(this->tileType_code6);
tileType_code6_high_1 = tileType_code6_high;
if ( tileType_code6_high )
goto LABEL_21;
LABEL_42:
std::string::_Rep::_M_dispose(v33[0] - 24LL, v2);
if ( (int)n4 <= (int)++n4_1 )
return;
}
tileType_code6_high_1 = 1;
LABEL_21:
tileType_code6_high_2 = 0;
v13 = (char *)`VTT for'std::ostringstream[1];
v14 = (char *)`VTT for'std::ostringstream[2];
do
{
std::ios_base::ios_base((std::ios_base *)(v2 + 11));
v39 = v13;
v50 = 0;
v51 = 0;
v52 = 0;
v53 = 0;
v54 = 0;
v55 = 0;
v49 = (char *)&`vtable for'std::ios + 16;
v56 = 0;
*(char **)((char *)&v39 + *((_QWORD *)v13 - 3)) = v14;
std::ios::init((char *)v2 + *((_QWORD *)v39 - 3), 0);
v41 = 0;
v42 = 0;
v43 = 0;
v44 = 0;
v45 = 0;
v46 = 0;
v39 = (char *)&`vtable for'std::ostringstream + 24;
v49 = (char *)&`vtable for'std::ostringstream + 64;
v40 = (char *)&`vtable for'std::streambuf + 16;
std::locale::locale((std::locale *)(v2 + 8));
n16 = 16;
v40 = (char *)&`vtable for'std::stringbuf + 16;
v48 = (char *)&std::string::_Rep::_S_empty_rep_storage + 24;
std::ios::init(v2 + 11, v2 + 1);
v15 = std::__ostream_insert<char,std::char_traits<char>>(v2, v33[0], *(_QWORD *)(v33[0] - 24LL));
std::ostream::operator<<(v15, (unsigned int)tileType_code6_high_2);
std::stringbuf::str(v35, v2 + 1);
v16 = (HDDMTileFace *)operator new(0x30u);
HDDMTileFace::HDDMTileFace(v16, v34, tileType_code6_high_2, (const std::string *)v35);
v17 = v34;
v36[0] = v16;
qword20 = (HDDMTileFace **)v34->qword20;
if ( qword20 == (HDDMTileFace **)v34->qword28 )
{
std::vector<HDDMTileFace *>::_M_emplace_back_aux<HDDMTileFace * const&>(&v34->qword18, v36);
v20 = v34;
}
else
{
if ( qword20 )
{
*qword20 = v16;
qword20_1 = v17->qword20;
v20 = v34;
}
else
{
v20 = v34;
qword20_1 = 0;
}
v17->qword20 = qword20_1 + 8;
}
qword40 = (HDDMTileEdge *)v20->qword40;
p_char38 = (HDDMTileEdge *)&v20->char38;
if ( !qword40 )
goto LABEL_45;
do
{
while ( (int)std::string::compare((std::string *)&qword40->qword20, (const std::string *)v35) >= 0 )
{
p_char38 = qword40;
qword40 = (HDDMTileEdge *)qword40->qword10;
if ( !qword40 )
goto LABEL_31;
}
qword40 = (HDDMTileEdge *)qword40->qword18;
}
while ( qword40 );
LABEL_31:
if ( &v20->char38 == (char *)p_char38
|| (int)std::string::compare((std::string *)v35, (const std::string *)&p_char38->qword20) < 0 )
{
LABEL_45:
v37 = v35;
p_char38_1 = std::_Rb_tree<std::string,std::pair<std::string const,HDDMTileFace *>,std::_Select1st<std::pair<std::string const,HDDMTileFace *>>,std::less<std::string>,std::allocator<std::pair<std::string const,HDDMTileFace *>>>::_M_emplace_hint_unique<std::piecewise_construct_t const&,std::tuple<std::string const&>,std::tuple<>>(
v20->gap30,
p_char38,
&qword_7B6AC49,
&v37,
&v31);
}
else
{
p_char38_1 = (__int64)p_char38;
}
qword28 = v36[0];
*(_QWORD *)(p_char38_1 + 40) = v36[0];
qword280 = (HDDMTileEdge *)this->qword280;
p_char278 = (HDDMTileEdge *)&this->char278;
if ( !qword280 )
goto LABEL_44;
do
{
while ( (int)std::string::compare((std::string *)&qword280->qword20, (const std::string *)v35) >= 0 )
{
p_char278 = qword280;
qword280 = (HDDMTileEdge *)qword280->qword10;
if ( !qword280 )
goto LABEL_39;
}
qword280 = (HDDMTileEdge *)qword280->qword18;
}
while ( qword280 );
LABEL_39:
if ( p_char278 == (HDDMTileEdge *)&this->char278
|| (int)std::string::compare((std::string *)v35, (const std::string *)&p_char278->qword20) < 0 )
{
LABEL_44:
v38[0] = v35;
p_char278_1 = std::_Rb_tree<std::string,std::pair<std::string const,HDDMTileFace *>,std::_Select1st<std::pair<std::string const,HDDMTileFace *>>,std::less<std::string>,std::allocator<std::pair<std::string const,HDDMTileFace *>>>::_M_emplace_hint_unique<std::piecewise_construct_t const&,std::tuple<std::string const&>,std::tuple<>>(
this->gap270,
p_char278,
&qword_7B6AC49,
v38,
&v32);
qword28 = v36[0];
p_char278 = (HDDMTileEdge *)p_char278_1;
}
p_char278->qword28 = qword28;
++tileType_code6_high_2;
std::string::_Rep::_M_dispose(v35[0] - 24LL, v38);
v39 = (char *)&`vtable for'std::ostringstream + 24;
v49 = (char *)&`vtable for'std::ostringstream + 64;
v40 = (char *)&`vtable for'std::stringbuf + 16;
std::string::_Rep::_M_dispose(v48 - 24, v38);
v40 = (char *)&`vtable for'std::streambuf + 16;
std::locale::~locale((std::locale *)(v2 + 8));
v13 = (char *)`VTT for'std::ostringstream[1];
v14 = (char *)`VTT for'std::ostringstream[2];
v39 = v13;
*(char **)((char *)&v39 + *((_QWORD *)v13 - 3)) = v14;
v49 = (char *)&`vtable for'std::ios + 16;
std::ios_base::~ios_base((std::ios_base *)(v2 + 11));
}
while ( tileType_code6_high_2 < tileType_code6_high_1 );
goto LABEL_42;
}
}