//
// sub_1402B6D20 from 0x1402b6d20 to 0x1402b6f16 (502 bytes)
//
// 2 xrefs:
// > GJSmartTemplate::getTemplateState @ 0x1402b5435
// > ??> @ 0x1406d24ec
//
// 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
//
// Hidden C++ exception states: #try_helpers=1
__int64 __fastcall sub_1402B6D20(_QWORD *a1, _QWORD *a2, __int64 a3)
{
_QWORD *v5; // r10
__int64 v6; // rbx
__int64 v7; // rcx
unsigned __int64 v8; // r13
unsigned __int64 v9; // rdx
unsigned __int64 v10; // rcx
__int64 v11; // r12
_QWORD *v12; // rsi
__int64 v13; // r15
_QWORD *v14; // rdx
_QWORD *v15; // rcx
_QWORD *v16; // r8
_QWORD *v17; // rbx
_QWORD *i; // r14
_QWORD *v19; // r8
v5 = (_QWORD *)*a1;
v6 = ((__int64)a2 - *a1) / 88;
v7 = a1[1] - *a1;
if ( v7 / 88 == 0x2E8BA2E8BA2E8BALL )
sub_140062A20(v7, 0x2E8BA2E8BA2E8BALL);
v8 = v7 / 88 + 1;
v9 = (a1[2] - (_QWORD)v5) / 88LL;
if ( v9 <= 0x2E8BA2E8BA2E8BALL - (v9 >> 1) )
{
v10 = v7 / 88 + 1;
if ( (v9 >> 1) + v9 >= v8 )
v10 = (v9 >> 1) + v9;
if ( v10 > 0x2E8BA2E8BA2E8BALL )
sub_140007AB0(v10, v9, 0x2E8BA2E8BA2E8BALL);
}
else
{
v10 = 0x2E8BA2E8BA2E8BALL;
}
v11 = 11 * v10;
v12 = sub_14003AA10(88 * v10);
v13 = (__int64)&v12[11 * v6];
sub_1402B2900(v13, a3);
v14 = (_QWORD *)a1[1];
v15 = (_QWORD *)*a1;
v16 = v12;
if ( a2 != v14 )
{
sub_1402B6F60(v15, a2, v12);
v16 = (_QWORD *)(v13 + 88);
v14 = (_QWORD *)a1[1];
v15 = a2;
}
sub_1402B6F60(v15, v14, v16);
v17 = (_QWORD *)*a1;
if ( *a1 )
{
for ( i = (_QWORD *)a1[1]; v17 != i; v17 += 11 )
{
sub_14003A830((__int64)(v17 + 5));
sub_14003A830((__int64)(v17 + 1));
}
v19 = (_QWORD *)*a1;
if ( (unsigned __int64)(88 * ((a1[2] - *a1) / 88LL)) >= 0x1000 )
{
if ( (unsigned __int64)v19 - *(v19 - 1) - 8 > 0x1F )
invalid_parameter_noinfo_noreturn();
v19 = (_QWORD *)*(v19 - 1);
}
j_j_free(v19);
}
*a1 = v12;
a1[1] = &v12[11 * v8];
a1[2] = &v12[v11];
return v13;
}