//
// sub_1005BC66C from 0x1005bc66c to 0x1005bc950 (740 bytes)
//
// 2 xrefs:
// > sub_1005BB970 @ 0x1005bbc8c
// > sub_1005BB970 @ 0x1005bbe54
//
// 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
//
_BYTE *__fastcall sub_1005BC66C(__int64 a1, int a2, unsigned __int64 *a3)
{
__int64 v6; // x2
__int64 v7; // x4
_BYTE *v8; // x0
_BYTE *v9; // x19
char v10; // w24
int v11; // w23
unsigned __int64 v12; // x8
int v13; // w26
int v14; // w27
int v15; // w9
__int64 v16; // x28
int v17; // w10
int v18; // w20
unsigned __int64 v19; // x23
__int64 v20; // x4
unsigned __int64 v22; // [xsp+18h] [xbp-58h]
if ( !*(_DWORD *)(a1 + 8) )
{
v8 = sub_100588710(1, (__int64)"ec_mult.c", 195);
v9 = v8;
if ( v8 )
{
*v8 = 0;
*a3 = 1;
return v9;
}
v6 = 65;
v7 = 197;
goto LABEL_31;
}
if ( (unsigned int)(a2 - 1) >= 7 )
{
v6 = 68;
v7 = 207;
goto LABEL_31;
}
if ( *(_DWORD *)(a1 + 16) )
v10 = -1;
else
v10 = 1;
if ( !*(_QWORD *)a1 )
{
v6 = 68;
v7 = 219;
goto LABEL_31;
}
v11 = sub_1005AAC20(a1);
v9 = sub_100588710((unsigned int)(v11 + 1), (__int64)"ec_mult.c", 224);
if ( !v9 )
{
v6 = 65;
v7 = 229;
LABEL_31:
sub_1005E0E48(16, 143, v6, "ec_mult.c", v7);
v9 = nullptr;
LABEL_32:
sub_100588C44(v9);
return nullptr;
}
v12 = 0;
v13 = 1 << a2;
v14 = 2 * (1 << a2);
v22 = v11;
v15 = **(_DWORD **)a1 & (v14 - 1);
v16 = a2 + 1LL;
while ( 1 )
{
if ( v15 )
{
if ( (v15 & 1) != 0 )
{
v17 = v15;
if ( (v15 & v13) != 0 )
{
v17 = v15 - v14;
if ( v16 + v12 >= v22 )
v17 = v15 & ((v14 - 1) >> 1);
}
if ( v17 >= v13 || v17 <= -(1 << a2) || (v17 & 1) == 0 )
{
v20 = 264;
goto LABEL_38;
}
v18 = v15 - v17;
if ( v15 - v17 != v13 && v15 != v17 && v18 != v14 )
{
v20 = 276;
goto LABEL_38;
}
}
else
{
LOBYTE(v17) = 0;
v18 = v15;
}
goto LABEL_26;
}
if ( v16 + v12 >= v22 )
break;
v18 = 0;
LOBYTE(v17) = 0;
LABEL_26:
v19 = v12 + 1;
v9[v12] = v17 * v10;
v15 = ((unsigned int)sub_1005AB5F4(a1, a2 + (int)v12 + 1) << a2) + (v18 >> 1);
v12 = v19;
if ( v15 > v14 )
{
v20 = 287;
LABEL_38:
sub_1005E0E48(16, 143, 68, "ec_mult.c", v20);
goto LABEL_32;
}
}
if ( v12 > v22 + 1 )
{
v20 = 293;
goto LABEL_38;
}
*a3 = v12;
return v9;
}