//
// GJSmartTemplate::flipKey from 0x9d4f88 to 0x9d53ac (1060 bytes)
//
// 5 xrefs:
// > GJSmartTemplate::scanForPrefab @ 0x9d86b8
// > GJSmartTemplate::scanForPrefab @ 0x9d8818
// > GJSmartTemplate::scanForPrefab @ 0x9d88c0
// > GJSmartTemplate::scanForPrefab @ 0x9d88d4
// > ??> @ 0x54888
//
// 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::flipKey@(
__int64 *a1@,
unsigned __int8 a2@,
unsigned __int8 a3@,
__int64 *a4@)
{
int v4; // w20
int v5; // w19
unsigned __int8 *v8; // x1
unsigned __int64 v9; // x2
SmartBlockType v10; // w25
SmartBlockType v11; // w22
SmartBlockType v12; // w26
SmartBlockType v13; // w24
SmartBlockType v14; // w27
SmartBlockType v15; // w23
SmartBlockType v16; // w8
SmartBlockType v17; // w7
char v18; // w28
char v19; // w25
char v20; // w22
char v21; // w0
SmartBlockType v23; // w3
SmartBlockType v24; // w2
SmartBlockType v25; // w1
SmartBlockType v26; // w0
SmartBlockType v27; // [xsp+78h] [xbp+68h]
SmartBlockType v28; // [xsp+80h] [xbp+70h]
char v29; // [xsp+88h] [xbp+78h]
char v30; // [xsp+90h] [xbp+80h]
char v31; // [xsp+98h] [xbp+88h]
SmartBlockType v32; // [xsp+A0h] [xbp+90h]
char v33; // [xsp+A0h] [xbp+90h]
SmartBlockType v34; // [xsp+A8h] [xbp+98h]
char v35; // [xsp+A8h] [xbp+98h]
v4 = a3;
v5 = a2;
if ( a2 < (a3 ^ 1u) )
{
*a4 = *a1;
*a1 = (__int64)&byte_124B6C8;
return a4;
}
v8 = (unsigned __int8 *)*a1;
v9 = *(_QWORD *)(*a1 - 24);
if ( !v9 )
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 0, 0);
if ( (*((_DWORD *)v8 - 2) & 0x80000000) != 0 )
{
v34 = *v8;
if ( v9 > 1 )
{
LABEL_25:
v10 = v8[1];
if ( v9 != 2 )
{
LABEL_26:
v11 = v8[2];
if ( v9 != 3 )
{
LABEL_27:
v12 = v8[3];
if ( v9 != 4 )
{
LABEL_28:
v13 = v8[4];
if ( v9 != 5 )
{
LABEL_29:
v14 = v8[5];
if ( v9 != 6 )
{
LABEL_30:
v15 = v8[6];
if ( v9 != 7 )
goto LABEL_31;
LABEL_42:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 7u, v9);
}
LABEL_38:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 6u, v9);
}
LABEL_41:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 5u, v9);
}
LABEL_39:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 4u, v9);
}
LABEL_43:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 3u, v9);
}
LABEL_37:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 2u, v9);
}
v9 = 1;
LABEL_45:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 1u, v9);
}
sub_D176A8(a1);
v8 = (unsigned __int8 *)*a1;
v9 = *(_QWORD *)(*a1 - 24);
v34 = *(unsigned __int8 *)*a1;
if ( v9 <= 1 )
goto LABEL_45;
if ( (*((_DWORD *)v8 - 2) & 0x80000000) != 0 )
goto LABEL_25;
sub_D176A8(a1);
v8 = (unsigned __int8 *)*a1;
v9 = *(_QWORD *)(*a1 - 24);
v10 = *(unsigned __int8 *)(*a1 + 1);
if ( v9 <= 2 )
goto LABEL_37;
if ( (*((_DWORD *)v8 - 2) & 0x80000000) != 0 )
goto LABEL_26;
sub_D176A8(a1);
v8 = (unsigned __int8 *)*a1;
v9 = *(_QWORD *)(*a1 - 24);
v11 = *(unsigned __int8 *)(*a1 + 2);
if ( v9 <= 3 )
goto LABEL_43;
if ( (*((_DWORD *)v8 - 2) & 0x80000000) != 0 )
goto LABEL_27;
sub_D176A8(a1);
v8 = (unsigned __int8 *)*a1;
v9 = *(_QWORD *)(*a1 - 24);
v12 = *(unsigned __int8 *)(*a1 + 3);
if ( v9 <= 4 )
goto LABEL_39;
if ( (*((_DWORD *)v8 - 2) & 0x80000000) != 0 )
goto LABEL_28;
sub_D176A8(a1);
v8 = (unsigned __int8 *)*a1;
v9 = *(_QWORD *)(*a1 - 24);
v13 = *(unsigned __int8 *)(*a1 + 4);
if ( v9 <= 5 )
goto LABEL_41;
if ( (*((_DWORD *)v8 - 2) & 0x80000000) != 0 )
goto LABEL_29;
sub_D176A8(a1);
v8 = (unsigned __int8 *)*a1;
v9 = *(_QWORD *)(*a1 - 24);
v14 = *(unsigned __int8 *)(*a1 + 5);
if ( v9 <= 6 )
goto LABEL_38;
if ( (*((_DWORD *)v8 - 2) & 0x80000000) != 0 )
goto LABEL_30;
sub_D176A8(a1);
v8 = (unsigned __int8 *)*a1;
v9 = *(_QWORD *)(*a1 - 24);
v15 = *(unsigned __int8 *)(*a1 + 6);
if ( v9 <= 7 )
goto LABEL_42;
if ( (*((_DWORD *)v8 - 2) & 0x80000000) == 0 )
{
sub_D176A8(a1);
v8 = (unsigned __int8 *)*a1;
v9 = *(_QWORD *)(*a1 - 24);
v16 = *(unsigned __int8 *)(*a1 + 7);
if ( v9 > 8 )
{
if ( (*((_DWORD *)v8 - 2) & 0x80000000) == 0 )
{
v32 = *(unsigned __int8 *)(*a1 + 7);
sub_D176A8(a1);
v8 = (unsigned __int8 *)*a1;
v16 = v32;
}
goto LABEL_21;
}
LABEL_32:
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 8u, v9);
}
LABEL_31:
v16 = v8[7];
if ( v9 == 8 )
goto LABEL_32;
LABEL_21:
v17 = v8[8];
if ( !v5 )
{
if ( v4 )
{
v23 = v14;
v24 = v15;
v25 = v13;
v26 = v10;
v14 = v17;
v15 = v16;
v13 = v12;
v10 = v11;
v17 = v23;
v16 = v24;
v12 = v25;
v11 = v26;
}
else
{
v16 = 0;
v17 = 0;
v14 = 0;
v15 = 0;
v12 = 0;
v13 = 0;
v11 = 0;
v10 = 0;
}
}
v27 = v16;
v28 = v17;
v18 = GJSmartTemplate::flipBlockType(v34, v5, v4);
v19 = GJSmartTemplate::flipBlockType(v10, v5, v4);
v20 = GJSmartTemplate::flipBlockType(v11, v5, v4);
v29 = GJSmartTemplate::flipBlockType(v13, v5, v4);
v30 = GJSmartTemplate::flipBlockType(v12, v5, v4);
v31 = GJSmartTemplate::flipBlockType(v15, v5, v4);
v33 = GJSmartTemplate::flipBlockType(v14, v5, v4);
v35 = GJSmartTemplate::flipBlockType(v28, v5, v4);
v21 = GJSmartTemplate::flipBlockType(v27, v5, v4);
GJSmartTemplate::keyFromNeighbors(v18, v19, v20, v29, v30, v31, v33, v35, a4, v21);
return a4;
}