//
// GJSmartTemplate::rotateKey from 0x9d4b84 to 0x9d4f88 (1028 bytes)
//
// 2 xrefs:
// > GJSmartTemplate::scanForPrefab @ 0x9d85b8
// > ??> @ 0x542d0
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
__int64 *__usercall GJSmartTemplate::rotateKey@(__int64 *a1@, int a2@, __int64 *a3@)
{
unsigned __int8 *v6; // x1
unsigned __int64 v7; // x2
SmartBlockType v8; // w21
SmartBlockType v9; // w23
SmartBlockType v10; // w24
SmartBlockType v11; // w25
SmartBlockType v12; // w26
SmartBlockType v13; // w27
SmartBlockType v14; // w22
SmartBlockType v15; // w4
char v16; // w22
char v17; // w21
char v18; // w0
SmartBlockType v20; // [xsp+70h] [xbp+60h]
SmartBlockType v21; // [xsp+74h] [xbp+64h]
SmartBlockType v22; // [xsp+78h] [xbp+68h]
SmartBlockType v23; // [xsp+7Ch] [xbp+6Ch]
char v24; // [xsp+80h] [xbp+70h]
SmartBlockType v25; // [xsp+88h] [xbp+78h]
char v26; // [xsp+88h] [xbp+78h]
SmartBlockType v27; // [xsp+90h] [xbp+80h]
char v28; // [xsp+90h] [xbp+80h]
SmartBlockType v29; // [xsp+98h] [xbp+88h]
char v30; // [xsp+98h] [xbp+88h]
SmartBlockType v31; // [xsp+A0h] [xbp+90h]
char v32; // [xsp+A0h] [xbp+90h]
SmartBlockType v33; // [xsp+A8h] [xbp+98h]
char v34; // [xsp+A8h] [xbp+98h]
if ( !a2 )
{
*a3 = *a1;
*a1 = (__int64)&byte_124B6C8;
return a3;
}
v6 = (unsigned __int8 *)*a1;
v7 = *(_QWORD *)(*a1 - 24);
if ( !v7 )
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 0, 0);
if ( (*((_DWORD *)v6 - 2) & 0x80000000) != 0 )
{
v8 = *v6;
if ( v7 > 1 )
{
LABEL_28:
v9 = v6[1];
if ( v7 != 2 )
{
LABEL_29:
v10 = v6[2];
if ( v7 != 3 )
{
LABEL_30:
v11 = v6[3];
if ( v7 != 4 )
{
LABEL_31:
v12 = v6[4];
if ( v7 != 5 )
{
LABEL_32:
v13 = v6[5];
if ( v7 != 6 )
{
LABEL_33:
v14 = v6[6];
if ( v7 != 7 )
goto LABEL_34;
LABEL_45:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 7u, v7);
}
LABEL_40:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 6u, v7);
}
LABEL_47:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 5u, v7);
}
LABEL_41:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 4u, v7);
}
LABEL_46:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 3u, v7);
}
LABEL_39:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 2u, v7);
}
v7 = 1;
LABEL_43:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 1u, v7);
}
sub_D176A8(a1);
v6 = (unsigned __int8 *)*a1;
v7 = *(_QWORD *)(*a1 - 24);
v8 = *(unsigned __int8 *)*a1;
if ( v7 <= 1 )
goto LABEL_43;
if ( (*((_DWORD *)v6 - 2) & 0x80000000) != 0 )
goto LABEL_28;
sub_D176A8(a1);
v6 = (unsigned __int8 *)*a1;
v7 = *(_QWORD *)(*a1 - 24);
v9 = *(unsigned __int8 *)(*a1 + 1);
if ( v7 <= 2 )
goto LABEL_39;
if ( (*((_DWORD *)v6 - 2) & 0x80000000) != 0 )
goto LABEL_29;
sub_D176A8(a1);
v6 = (unsigned __int8 *)*a1;
v7 = *(_QWORD *)(*a1 - 24);
v10 = *(unsigned __int8 *)(*a1 + 2);
if ( v7 <= 3 )
goto LABEL_46;
if ( (*((_DWORD *)v6 - 2) & 0x80000000) != 0 )
goto LABEL_30;
sub_D176A8(a1);
v6 = (unsigned __int8 *)*a1;
v7 = *(_QWORD *)(*a1 - 24);
v11 = *(unsigned __int8 *)(*a1 + 3);
if ( v7 <= 4 )
goto LABEL_41;
if ( (*((_DWORD *)v6 - 2) & 0x80000000) != 0 )
goto LABEL_31;
sub_D176A8(a1);
v6 = (unsigned __int8 *)*a1;
v7 = *(_QWORD *)(*a1 - 24);
v12 = *(unsigned __int8 *)(*a1 + 4);
if ( v7 <= 5 )
goto LABEL_47;
if ( (*((_DWORD *)v6 - 2) & 0x80000000) != 0 )
goto LABEL_32;
sub_D176A8(a1);
v6 = (unsigned __int8 *)*a1;
v7 = *(_QWORD *)(*a1 - 24);
v13 = *(unsigned __int8 *)(*a1 + 5);
if ( v7 <= 6 )
goto LABEL_40;
if ( (*((_DWORD *)v6 - 2) & 0x80000000) != 0 )
goto LABEL_33;
sub_D176A8(a1);
v6 = (unsigned __int8 *)*a1;
v7 = *(_QWORD *)(*a1 - 24);
v14 = *(unsigned __int8 *)(*a1 + 6);
if ( v7 <= 7 )
goto LABEL_45;
if ( (*((_DWORD *)v6 - 2) & 0x80000000) == 0 )
{
sub_D176A8(a1);
v6 = (unsigned __int8 *)*a1;
v7 = *(_QWORD *)(*a1 - 24);
v15 = *(unsigned __int8 *)(*a1 + 7);
if ( v7 > 8 )
{
if ( (*((_DWORD *)v6 - 2) & 0x80000000) == 0 )
{
v25 = *(unsigned __int8 *)(*a1 + 7);
sub_D176A8(a1);
v6 = (unsigned __int8 *)*a1;
v15 = v25;
}
goto LABEL_21;
}
LABEL_35:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 8u, v7);
}
LABEL_34:
v15 = v6[7];
if ( v7 == 8 )
goto LABEL_35;
LABEL_21:
switch ( a2 )
{
case 90:
v20 = v14;
v21 = v6[8];
v22 = v13;
v23 = v15;
v27 = v9;
v29 = v10;
v31 = v12;
v33 = v11;
break;
case 180:
v20 = v13;
v21 = v14;
v22 = v15;
v23 = v6[8];
v27 = v11;
v29 = v12;
v31 = v9;
v33 = v10;
break;
case 270:
v20 = v15;
v21 = v13;
v22 = v6[8];
v23 = v14;
v27 = v10;
v29 = v9;
v31 = v11;
v33 = v12;
break;
}
v16 = GJSmartTemplate::rotateBlockType(v8, a2);
v17 = GJSmartTemplate::rotateBlockType(v33, a2);
v24 = GJSmartTemplate::rotateBlockType(v31, a2);
v26 = GJSmartTemplate::rotateBlockType(v29, a2);
v28 = GJSmartTemplate::rotateBlockType(v27, a2);
v30 = GJSmartTemplate::rotateBlockType(v23, a2);
v32 = GJSmartTemplate::rotateBlockType(v22, a2);
v34 = GJSmartTemplate::rotateBlockType(v21, a2);
v18 = GJSmartTemplate::rotateBlockType(v20, a2);
GJSmartTemplate::keyFromNeighbors(v16, v17, v24, v26, v28, v30, v32, v34, a3, v18);
return a3;
}