//
// RC4 from 0xdd0d74 to 0xdd11ec (1144 bytes)
//
// 7 xrefs:
// > sub_DA8410 @ 0xda8438
// > sub_DA8694 @ 0xda8784
// > sub_DA8694 @ 0xda87dc
// > sub_DA8694 @ 0xda87fc
// > sub_DA8694 @ 0xda8870
// > sub_E5DBA4 @ 0xe5dbd0
// > ??> @ 0xaf4b8
//
// 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
//
unsigned __int8 *__fastcall RC4(unsigned __int8 *result, unsigned __int64 a2, _BYTE *a3, _BYTE *a4)
{
_BYTE *v4; // x5
unsigned __int8 v5; // w9
unsigned __int8 v6; // w4
unsigned __int64 v7; // x19
unsigned __int64 v8; // x18
unsigned __int8 v9; // w6
_BYTE *v10; // x8
_BYTE *v11; // x7
__int64 v12; // x17
__int64 v13; // x16
__int64 v14; // x15
char v15; // w21
__int64 v16; // x14
__int64 v17; // x13
unsigned __int8 v18; // w4
unsigned __int8 v19; // w11
__int64 v20; // x12
char v21; // w10
unsigned __int8 v22; // w4
char v23; // w10
unsigned __int8 v24; // w4
char v25; // w10
unsigned __int8 v26; // w4
char v27; // w10
unsigned __int8 v28; // w4
char v29; // w10
unsigned __int8 v30; // w4
char v31; // w10
unsigned __int8 v32; // w4
char v33; // w10
char v34; // w11
char v35; // w10
__int64 v36; // x1
unsigned __int8 v37; // w7
char v38; // w8
unsigned __int8 v39; // w4
char v40; // w6
char v41; // w8
char v42; // w6
char v43; // w8
char v44; // w6
char v45; // w8
char v46; // w6
char v47; // w8
char v48; // w6
bool v49; // zf
char v50; // w7
char v51; // w1
char v52; // w6
char v53; // w1
v4 = result + 2;
v5 = *result;
v6 = result[1];
v7 = a2 >> 3;
if ( a2 >> 3 )
{
v8 = a2 >> 3;
v9 = *result;
v10 = a4;
v11 = a3;
do
{
v11 += 8;
v10 += 8;
v12 = (unsigned __int8)(v9 + 1);
v13 = (unsigned __int8)(v9 + 2);
v14 = (unsigned __int8)(v9 + 3);
v15 = v4[v12];
v16 = (unsigned __int8)(v9 + 4);
v17 = (unsigned __int8)(v9 + 5);
v18 = v6 + v15;
v19 = v9 + 7;
v20 = (unsigned __int8)(v9 + 6);
v9 += 8;
--v8;
v21 = v4[v18];
v4[v12] = v21;
v4[v18] = v15;
*(v10 - 8) = v4[(unsigned __int8)(v15 + v21)] ^ *(v11 - 8);
LOBYTE(v12) = v4[v13];
v22 = v18 + v12;
v23 = v4[v22];
v4[v13] = v23;
v4[v22] = v12;
*(v10 - 7) = v4[(unsigned __int8)(v12 + v23)] ^ *(v11 - 7);
LOBYTE(v13) = v4[v14];
v24 = v22 + v13;
v25 = v4[v24];
v4[v14] = v25;
v4[v24] = v13;
*(v10 - 6) = v4[(unsigned __int8)(v13 + v25)] ^ *(v11 - 6);
LOBYTE(v14) = v4[v16];
v26 = v24 + v14;
v27 = v4[v26];
v4[v16] = v27;
v4[v26] = v14;
*(v10 - 5) = v4[(unsigned __int8)(v14 + v27)] ^ *(v11 - 5);
LOBYTE(v16) = v4[v17];
v28 = v26 + v16;
v29 = v4[v28];
v4[v17] = v29;
v4[v28] = v16;
*(v10 - 4) = v4[(unsigned __int8)(v16 + v29)] ^ *(v11 - 4);
LOBYTE(v17) = v4[v20];
v30 = v28 + v17;
v31 = v4[v30];
v4[v20] = v31;
v4[v30] = v17;
*(v10 - 3) = v4[(unsigned __int8)(v17 + v31)] ^ *(v11 - 3);
LOBYTE(v20) = v4[v19];
v32 = v30 + v20;
v33 = v4[v32];
v4[v19] = v33;
v4[v32] = v20;
*(v10 - 2) = v4[(unsigned __int8)(v20 + v33)] ^ *(v11 - 2);
v34 = v4[v9];
v6 = v32 + v34;
v35 = v4[v6];
v4[v9] = v35;
v4[v6] = v34;
*(v10 - 1) = v4[(unsigned __int8)(v34 + v35)] ^ *(v11 - 1);
}
while ( v8 );
a3 += 8 * v7;
a4 += 8 * v7;
v5 += 8 * (v7 - 1) + 8;
}
v36 = a2 & 7;
if ( !v36 )
goto LABEL_13;
v37 = v5 + 1;
v38 = v4[(unsigned __int8)(v5 + 1)];
v39 = v38 + v6;
v40 = v4[v39];
v4[(unsigned __int8)(v5 + 1)] = v40;
v4[v39] = v38;
*a4 = v4[(unsigned __int8)(v38 + v40)] ^ *a3;
if ( v36 != 1 )
{
v37 = v5 + 2;
v41 = v4[(unsigned __int8)(v5 + 2)];
v39 += v41;
v42 = v4[v39];
v4[(unsigned __int8)(v5 + 2)] = v42;
v4[v39] = v41;
a4[1] = v4[(unsigned __int8)(v41 + v42)] ^ a3[1];
if ( v36 != 2 )
{
v37 = v5 + 3;
v43 = v4[(unsigned __int8)(v5 + 3)];
v39 += v43;
v44 = v4[v39];
v4[(unsigned __int8)(v5 + 3)] = v44;
v4[v39] = v43;
a4[2] = v4[(unsigned __int8)(v43 + v44)] ^ a3[2];
if ( v36 != 3 )
{
v37 = v5 + 4;
v45 = v4[(unsigned __int8)(v5 + 4)];
v39 += v45;
v46 = v4[v39];
v4[(unsigned __int8)(v5 + 4)] = v46;
v4[v39] = v45;
a4[3] = v4[(unsigned __int8)(v45 + v46)] ^ a3[3];
if ( v36 != 4 )
{
v37 = v5 + 5;
v47 = v4[(unsigned __int8)(v5 + 5)];
v39 += v47;
v48 = v4[v39];
v4[(unsigned __int8)(v5 + 5)] = v48;
v4[v39] = v47;
a4[4] = v4[(unsigned __int8)(v47 + v48)] ^ a3[4];
if ( v36 != 5 )
{
v49 = v36 == 6;
v50 = v4[(unsigned __int8)(v5 + 6)];
v6 = v39 + v50;
v51 = v4[v6];
v4[(unsigned __int8)(v5 + 6)] = v51;
v4[v6] = v50;
a4[5] = v4[(unsigned __int8)(v50 + v51)] ^ a3[5];
if ( v49 )
{
v5 += 6;
}
else
{
v5 += 7;
v52 = v4[v5];
v6 += v52;
v53 = v4[v6];
v4[v5] = v53;
v4[v6] = v52;
a4[6] = v4[(unsigned __int8)(v52 + v53)] ^ a3[6];
}
LABEL_13:
*result = v5;
result[1] = v6;
return result;
}
}
}
}
}
result[1] = v39;
*result = v37;
return result;
}