//
// RC2_set_key from 0x82ada4 to 0x82af84 (480 bytes)
//
// 2 xrefs:
// > sub_801490 @ 0x8014c8
// > ??> @ 0x633cc
//
// 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 RC2_set_key(_BYTE *result, int a2, unsigned int a3, int a4)
{
int v4; // r5
int v5; // r7
int v6; // r12
int v7; // r6
int v8; // lr
unsigned int v9; // r9
_BOOL4 v10; // r8
bool v11; // cf
int v12; // r3
unsigned int v13; // r3
int v14; // r4
unsigned int v15; // r10
_DWORD *v16; // r9
unsigned int v17; // r8
int v18; // t1
int v19; // r8
int v20; // r4
bool v21; // zf
unsigned __int8 *v22; // r1
unsigned __int8 v23; // r3
_BYTE *v24; // r2
char v25; // t1
int v26; // r2
_BYTE *v27; // r1
unsigned __int8 *v28; // lr
int v29; // t1
_BYTE *v30; // r2
_BYTE *v31; // r12
int v32; // r1
int v33; // r3
unsigned int v34; // r8
_BYTE *v35; // r3
char v36; // t1
if ( a2 >= 128 )
a2 = 128;
v4 = 0;
*result = 0;
if ( a4 > 0 && a4 <= 1024 )
{
v8 = (a4 + 7) >> 3;
v5 = 128 - v8;
v7 = 255 >> (-(char)a4 & 7);
v4 = 128 - v8;
v6 = 127 - v8;
}
else
{
v5 = 0;
v6 = -1;
LOBYTE(v7) = -1;
v8 = 128;
}
if ( a2 <= 0 )
{
v22 = &result[a2];
v23 = *(v22 - 1);
LABEL_23:
v24 = result - 1;
do
{
v25 = *++v24;
v23 = byte_A17564[(unsigned __int8)(v23 + v25)];
*v22++ = v23;
}
while ( v22 != result + 128 );
goto LABEL_25;
}
v9 = a3 + 4;
v10 = (unsigned int)a2 > 8 && (a3 & 3) == 0;
v11 = (unsigned int)result >= v9;
if ( (unsigned int)result < v9 )
v11 = a3 >= (unsigned int)(result + 4);
v12 = v11;
if ( (v10 & v12) != 0 )
{
v13 = ((unsigned int)(a2 - 4) >> 2) + 1;
v14 = 4 * v13;
v15 = a3 - 4;
v16 = result;
v17 = 0;
do
{
++v17;
v18 = *(_DWORD *)(v15 + 4);
v15 += 4;
*v16++ = v18;
}
while ( v17 < v13 );
if ( v14 != a2 )
{
v19 = v14 + 1;
result[4 * v13] = *(_BYTE *)(a3 + 4 * v13);
if ( v14 + 1 < a2 )
{
v20 = v14 + 2;
result[v19] = *(_BYTE *)(a3 + v19);
if ( a2 > v20 )
result[v20] = *(_BYTE *)(a3 + v20);
}
}
}
else
{
v34 = a3 + a2;
v35 = result - 1;
do
{
v36 = *(_BYTE *)a3++;
*++v35 = v36;
}
while ( a3 != v34 );
}
v21 = a2 == 128;
v22 = &result[a2];
v23 = *(v22 - 1);
if ( !v21 )
goto LABEL_23;
LABEL_25:
v26 = byte_A17564[v7 & result[v4]];
result[v4] = v26;
if ( v5 )
{
v27 = &result[v6];
v28 = &result[v8 + v6];
do
{
v29 = *v28--;
LOBYTE(v26) = byte_A17564[v29 ^ v26];
*v27-- = v26;
}
while ( v27 != result - 1 );
}
v30 = result + 256;
v31 = result - 128;
do
{
v32 = (unsigned __int8)result[127];
v33 = (unsigned __int8)result[126];
result -= 2;
*((_DWORD *)v30 - 1) = v33 | (v32 << 8);
v30 -= 4;
}
while ( result != v31 );
return result;
}