//
// sub_6FF874 from 0x6ff874 to 0x6ffc50 (988 bytes)
//
// 5 xrefs:
// > sub_6FFC68 @ 0x6ffcaa
// > WebPDecodeYUVInto @ 0x70009c
// > WebPDecodeYUV @ 0x700470
// > sub_7004AC @ 0x70050a
// > WebPDecode @ 0x700afa
//
// 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
//
char *__fastcall sub_6FF874(unsigned __int8 *a1, unsigned int a2, unsigned int **a3)
{
int v3; // r6
bool v4; // cc
char *result; // r0
unsigned int v6; // r4
unsigned __int8 *v8; // r5
unsigned int v9; // r10
int v10; // r0
int v11; // r9
__int64 v12; // r2
bool v13; // cf
unsigned int v14; // r11
int v15; // r11
int v16; // r8
unsigned __int8 v17; // r3
int v18; // r6
int v19; // r0
_BOOL4 v20; // r3
_BOOL4 v21; // r6
unsigned int v22; // r2
unsigned int v23; // r1
_BOOL4 v24; // r0
int *v25; // r0
int *v26; // r5
unsigned int v27; // r3
int v28; // r4
unsigned int *v29; // r3
int *v30; // r0
int *v31; // r5
int v32; // [sp+Ch] [bp-A8h]
unsigned __int8 *v33; // [sp+10h] [bp-A4h] BYREF
unsigned int v34; // [sp+14h] [bp-A0h] BYREF
int v35; // [sp+18h] [bp-9Ch] BYREF
int v36; // [sp+1Ch] [bp-98h] BYREF
int v37; // [sp+20h] [bp-94h] BYREF
int v38; // [sp+24h] [bp-90h]
int v39; // [sp+28h] [bp-8Ch]
unsigned __int8 *v40; // [sp+2Ch] [bp-88h]
unsigned __int8 *v41; // [sp+30h] [bp-84h]
unsigned int v42; // [sp+34h] [bp-80h]
int v43; // [sp+38h] [bp-7Ch]
unsigned int v44; // [sp+3Ch] [bp-78h]
int v45; // [sp+40h] [bp-74h]
int v46; // [sp+44h] [bp-70h] BYREF
unsigned int v47; // [sp+48h] [bp-6Ch]
int v48; // [sp+4Ch] [bp-68h]
int v49; // [sp+50h] [bp-64h]
unsigned __int8 *v50; // [sp+54h] [bp-60h] BYREF
unsigned int v51; // [sp+58h] [bp-5Ch] BYREF
int v52; // [sp+5Ch] [bp-58h]
unsigned int v53; // [sp+60h] [bp-54h]
int v54; // [sp+64h] [bp-50h]
int v55; // [sp+80h] [bp-34h]
unsigned __int8 *v56; // [sp+84h] [bp-30h]
v4 = a1 != nullptr;
if ( a1 )
v4 = a2 > 0xB;
v38 = a2;
if ( !v4 )
v3 = 1;
v34 = a2;
if ( v4 )
v3 = 0;
v37 = (int)a1;
v33 = a1;
v39 = 1;
v35 = 0;
v36 = 0;
if ( !v4 )
return &byte_7;
v6 = a2;
v8 = a1;
v48 = v3;
v49 = v3;
v50 = (unsigned __int8 *)v3;
v51 = v3;
v52 = v3;
v53 = v3;
v54 = v3;
v46 = (int)a1;
v47 = a2;
if ( !memcmp(a1, "RIFF", 4u) )
{
if ( memcmp(v8 + 8, "WEBP", 4u) )
return (_BYTE *)(&dword_0 + 3);
v9 = v8[4] | (v8[5] << 8) | ((v8[6] | (v8[7] << 8)) << 16);
if ( v9 - 12 > 0xFFFFFFEA )
return (_BYTE *)(&dword_0 + 3);
if ( v9 > v6 - 8 )
return &byte_7;
v6 -= 12;
v8 += 12;
v34 = v6;
v33 = v8;
v53 = v9;
if ( v6 <= 7 )
return &byte_7;
v3 = 1;
}
else
{
v9 = v3;
}
v10 = memcmp(v8, "VP8X", 4u);
if ( v10 )
{
v16 = 0;
v11 = 0;
v17 = v3 ^ 1;
v15 = 0;
LOBYTE(v10) = 1;
v35 = 0;
v36 = 0;
v32 = 0;
}
else
{
if ( (v8[4] | (v8[5] << 8) | ((v8[6] | (v8[7] << 8)) << 16)) != 0xA )
return (_BYTE *)(&dword_0 + 3);
if ( v6 <= 0x11 )
return &byte_7;
v11 = ((v8[14] << 16) | (v8[13] << 8) | v8[12]) + 1;
v32 = ((v8[17] << 16) | (v8[16] << 8) | v8[15]) + 1;
v12 = v32 * (__int64)v11;
v13 = HIDWORD(v12) != 0;
if ( HIDWORD(v12) == 1 )
v13 = 1;
v14 = v8[8] | (v8[9] << 8) | ((v8[10] | (v8[11] << 8)) << 16);
if ( v13 )
return (_BYTE *)(&dword_0 + 3);
v8 += 18;
v6 -= 18;
v33 = v8;
v34 = v6;
if ( !v3 )
return (_BYTE *)(&dword_0 + 3);
v15 = (v14 >> 1) & 1;
v35 = v11;
v36 = v32;
if ( v6 <= 3 )
goto LABEL_21;
v16 = v3;
v17 = 0;
}
if ( ((unsigned __int8)v16 & (unsigned __int8)v3) != 0 || (v17 & (unsigned __int8)v10) != 0 && !memcmp(v8, "ALPH", 4u) )
{
result = (char *)sub_6FF768(&v33, &v34, v9, &v50, &v51);
if ( result )
{
if ( result != &byte_7 )
return result;
goto LABEL_47;
}
v9 = v53;
v8 = v33;
v6 = v34;
}
v18 = memcmp(v8, "VP8 ", 4u);
v19 = memcmp(v8, "VP8L", 4u);
if ( v6 <= 7 )
{
result = &byte_7;
if ( v15 )
return byte_4;
return result;
}
v20 = v19 == 0;
if ( v18 )
v21 = v19 == 0;
else
v21 = 1;
if ( !v21 )
{
v24 = VP8LCheckSignature(v8, v6);
v22 = v34;
v52 = v34;
v23 = v34;
v54 = v24;
LABEL_49:
if ( v22 > 0xFFFFFFF6 )
return (_BYTE *)(&dword_0 + 3);
if ( v24 )
{
if ( v23 > 4 )
{
if ( !VP8LGetInfo(v33, v23, &v35, &v36, nullptr) )
return (_BYTE *)(&dword_0 + 3);
LABEL_53:
if ( !v16 || v35 == v11 && v36 == v32 )
{
v37 = v46;
v38 = v47;
v39 = v48;
v40 = &v33[-v46];
v41 = v50;
v42 = v51;
v43 = v52;
v44 = v53;
v45 = v54;
if ( v15 )
return byte_4;
sub_6FB9DC(&v46, 520);
v56 = &v40[v37];
v55 = v38 - (_DWORD)v40;
sub_6FA1A0((int)a3, &v46);
if ( v45 )
{
v30 = sub_6FE624();
v31 = v30;
if ( v30 )
{
if ( !sub_6FF430(v30, &v46) || (v28 = sub_6F6EAC(v46, v47, a3[5], *a3)) == 0 && !sub_6FF550(v31) )
v28 = *v31;
sub_6FE6D4((int)v31);
goto LABEL_62;
}
}
else
{
v25 = sub_6FB9FC();
v26 = v25;
if ( v25 )
{
v27 = v42;
v25[587] = (int)v41;
v25[588] = v27;
if ( !sub_6FBB58((int)v25, &v46)
|| (v28 = sub_6F6EAC(v46, v47, a3[5], *a3)) == 0
&& (v26[37] = sub_6F824C((int)a3[5], (int)&v37, v46),
sub_6F7E14((int)a3[5], v26),
!sub_6FC3A0((int)v26, &v46)) )
{
v28 = *v26;
}
sub_6FBA5C((int)v26);
LABEL_62:
if ( v28 )
WebPFreeDecBuffer((int)*a3);
v29 = a3[5];
if ( v29 && v29[12] )
return (char *)sub_6F6E38(*a3);
else
return (char *)v28;
}
}
return (_BYTE *)(&dword_0 + 1);
}
return (_BYTE *)(&dword_0 + 3);
}
}
else if ( v23 > 9 )
{
if ( !VP8GetInfo(v33, v23, v22, &v35, &v36) )
return (_BYTE *)(&dword_0 + 3);
goto LABEL_53;
}
LABEL_21:
if ( v15 )
return byte_4;
return &byte_7;
}
v22 = v8[4] | (v8[5] << 8) | ((v8[6] | (v8[7] << 8)) << 16);
if ( v9 > 0xB && v22 > v9 - 12 )
return (_BYTE *)(&dword_0 + 3);
v23 = v6 - 8;
if ( v22 <= v6 - 8 )
{
v24 = v19 == 0;
v52 = v8[4] | (v8[5] << 8) | ((v8[6] | (v8[7] << 8)) << 16);
v33 = v8 + 8;
v34 = v6 - 8;
v54 = v20;
goto LABEL_49;
}
result = &byte_7;
LABEL_47:
if ( v15 )
return byte_4;
return result;
}