//
// BF_set_key from 0xe74674 to 0xe7479c (296 bytes)
//
// 2 xrefs:
// > sub_E60278 @ 0xe602a8
// > ??> @ 0x984f0
//
// 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
//
int *__fastcall BF_set_key(_DWORD *a1, int a2, unsigned __int8 *a3)
{
_DWORD *v5; // x23
_DWORD *v7; // x19
_DWORD *v8; // x2
unsigned __int8 *v9; // x0
int v10; // w5
unsigned __int64 v11; // x5
unsigned __int8 *v12; // x1
int v13; // w4
unsigned __int8 *v14; // x0
int v15; // w3
unsigned __int8 *v16; // x1
int v17; // w4
int v18; // w3
int v19; // w4
int *result; // x0
int v21; // [xsp+48h] [xbp+48h] BYREF
int v22; // [xsp+4Ch] [xbp+4Ch]
v5 = a1 + 18;
v7 = a1;
memcpy(a1, &unk_F94D50, 0x1048u);
v8 = a1;
v9 = a3;
if ( a2 > 72 )
v10 = 72;
else
v10 = a2;
v11 = (unsigned __int64)&a3[v10];
do
{
v12 = v9 + 1;
v13 = *v9;
if ( v11 <= (unsigned __int64)(v9 + 1) )
v12 = a3;
v14 = v12 + 1;
if ( v11 <= (unsigned __int64)(v12 + 1) )
v14 = a3;
v15 = *v12;
v16 = v14 + 1;
v17 = v15 | (v13 << 8);
if ( v11 <= (unsigned __int64)(v14 + 1) )
v16 = a3;
v18 = *v14;
v9 = v16 + 1;
v19 = v18 | (v17 << 8);
if ( v11 <= (unsigned __int64)(v16 + 1) )
v9 = a3;
*v8++ ^= *v16 | (v19 << 8);
}
while ( v8 != v5 );
v21 = 0;
v22 = 0;
do
{
v7 += 2;
BF_encrypt(&v21, a1);
*(v7 - 2) = v21;
*(v7 - 1) = v22;
}
while ( v7 != v5 );
do
{
v7 += 2;
result = BF_encrypt(&v21, a1);
*(v7 - 2) = v21;
*(v7 - 1) = v22;
}
while ( v7 != a1 + 1042 );
return result;
}