//
// WebPEncode from 0x732a20 to 0x7332d2 (2226 bytes)
//
// 1 xrefs:
// > sub_7279E4 @ 0x727a72
//
// 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 WebPEncode(int result, _DWORD *a2)
{
int v2; // r6
int v4; // r5
int v5; // r2
void *v6; // r0
int v7; // r2
int v8; // r7
int v9; // r8
int v10; // r9
__int64 v11; // r0
char *v12; // r0
int v13; // r10
unsigned int v14; // r5
int v15; // r1
int v16; // r2
int v17; // r11
unsigned int v18; // r2
unsigned int v19; // r0
int v20; // r3
int v21; // r2
int v22; // r3
int v23; // r3
int v24; // r2
_BOOL4 v25; // r1
_BOOL4 v26; // r2
int v27; // r2
int v28; // r4
int v29; // r3
bool v30; // cc
int v31; // r3
int v32; // r5
bool v33; // nf
int v34; // r3
int v35; // r3
int v36; // r2
_DWORD *v37; // r6
_DWORD *v38; // r4
float v39; // s15
bool v40; // r12
_BOOL4 v41; // r3
float *v42; // r5
float v43; // s15
_BOOL4 v44; // r2
unsigned __int64 v45; // r2
float v46; // s15
_BOOL4 v47; // r1
float v48; // s15
unsigned __int64 v49; // r0
_BOOL4 v50; // r3
int v51; // r1
__int64 v52; // r6
float v53; // s15
int (*v54)(void); // r3
int v55; // r5
double v56; // r0
double v57; // r0
double v58; // r0
double v59; // r0
int v60; // [sp+4h] [bp-30h]
_BOOL4 v61; // [sp+4h] [bp-30h]
int v62; // [sp+8h] [bp-2Ch]
unsigned __int64 v63; // [sp+8h] [bp-2Ch]
int v64; // [sp+10h] [bp-24h]
unsigned __int64 v65; // [sp+10h] [bp-24h]
bool v66; // [sp+10h] [bp-24h]
bool v67; // [sp+10h] [bp-24h]
__int64 v68; // [sp+18h] [bp-1Ch]
bool v69; // [sp+18h] [bp-1Ch]
bool v70; // [sp+18h] [bp-1Ch]
int v71; // [sp+20h] [bp-14h]
int v72; // [sp+28h] [bp-Ch]
_BOOL4 v73; // [sp+2Ch] [bp-8h]
if ( !a2 )
return 0;
v2 = result;
a2[23] = 0;
if ( !result )
{
a2[23] = 3;
return result;
}
v4 = WebPValidateConfig(result);
if ( !v4 )
{
a2[23] = 4;
return v4;
}
v5 = a2[2];
if ( v5 <= 0 || (unsigned int)(a2[3] - 1) > 0x3FFE || v5 >= 0x4000 )
{
a2[23] = 5;
return 0;
}
v6 = (void *)a2[22];
if ( v6 )
memset(v6, 0, 0xBCu);
v4 = *(_DWORD *)v2;
if ( !*(_DWORD *)v2 )
{
if ( !*(_DWORD *)(v2 + 96) )
WebPCleanupTransparentArea((int)a2);
if ( !*a2 && a2[4] && a2[5] && a2[6] )
goto LABEL_15;
if ( (*(_DWORD *)(v2 + 68) & 4) != 0 )
{
if ( WebPPictureSmartARGBToYUVA(a2) )
goto LABEL_15;
}
else if ( WebPPictureARGBToYUVADithered((int)a2, 0) )
{
LABEL_15:
v7 = *(_DWORD *)(v2 + 44);
v73 = *(int *)(v2 + 32) > 0 || v7 > 0;
v8 = (a2[2] + 15) >> 4;
v9 = (a2[3] + 15) >> 4;
v10 = 4 * v8 + 1;
v71 = 4 * v8 + 35;
v62 = (4 * v9 + 1) * v10;
v60 = 4 * v9 * v8;
if ( v7 )
{
v72 = 2110;
v68 = 2079;
v64 = 2079;
}
else
{
v64 = 0;
v72 = 31;
v68 = 0;
}
v11 = v68 + (unsigned int)v60 + 22671LL + (unsigned int)v62 + (unsigned int)(32 * v8 + 31) + (unsigned int)v71;
v12 = (char *)WebPSafeMalloc(v11, HIDWORD(v11), 1);
v13 = (int)v12;
if ( v12 )
{
v14 = (unsigned int)(v12 + 22671);
memset(v12, 0, 0x5870u);
v14 &= 0xFFFFFFE0;
v15 = *(_DWORD *)(v2 + 72);
v16 = v62 + v14 + v60;
*(_DWORD *)(v13 + 40) = v8;
*(_DWORD *)(v13 + 44) = v9;
*(_DWORD *)(v13 + 48) = v10;
*(_DWORD *)(v13 + 22616) = v14;
*(_DWORD *)(v13 + 22624) = ((v16 + 31) & 0xFFFFFFE0) + 4;
*(_DWORD *)(v13 + 22620) = v14 + v60 + 4 * v8 + 2;
v17 = v71 + v16;
*(_DWORD *)(v13 + 52) = 1 << v15;
v18 = (v71 + v16 + 31) & 0xFFFFFFE0;
if ( !v64 )
v18 = 0;
*(_DWORD *)v13 = v2;
v19 = (v72 + v17) & 0xFFFFFFE0;
*(_DWORD *)(v13 + 22632) = 16 * v8 + v19;
*(_DWORD *)(v13 + 22628) = v19;
*(_DWORD *)(v13 + 22636) = v18;
if ( v73 )
v20 = *(_DWORD *)(v2 + 40) != 1;
else
v20 = 2;
*(_DWORD *)(v13 + 36) = v20;
*(_DWORD *)(v13 + 4) = a2;
*(_DWORD *)(v13 + 368) = 0;
v21 = *(_DWORD *)(v2 + 8);
v22 = *(_DWORD *)(v2 + 76);
*(_DWORD *)(v13 + 22592) = v21;
v23 = 100 - v22;
if ( v21 <= 5 )
{
if ( v21 == 5 )
v24 = 2;
else
v24 = v21 > 2;
}
else
{
v24 = 3;
}
*(_DWORD *)(v13 + 22596) = v24;
*(_DWORD *)(v13 + 22600) = ((v23 * v23) << 16) / 10000;
*(_DWORD *)(v13 + 22604) = *(_DWORD *)(v2 + 84);
v25 = *(int *)(v2 + 16) > 0 || *(float *)(v2 + 20) > 0.0;
*(_DWORD *)(v13 + 22608) = v25;
if ( !*(_DWORD *)(v2 + 88) )
{
v26 = v24 != 0;
*(_DWORD *)(v13 + 22612) = v26;
if ( v26 )
*(_DWORD *)(v13 + 52) = 1;
}
sub_70AA88();
sub_73064C((_DWORD *)v13);
v27 = *(_DWORD *)(v13 + 40);
v28 = *(_DWORD *)(v13 + 22620);
v29 = *(_DWORD *)(*(_DWORD *)v13 + 24);
*(_DWORD *)(v13 + 8) = 1;
v30 = v29 <= 1;
*(_DWORD *)(v13 + 32) = 0;
*(_DWORD *)(v13 + 24) = v29;
v31 = *(_DWORD *)(v13 + 48);
v32 = !v30;
v33 = v27 < 0;
*(_DWORD *)(v13 + 12) = 0;
if ( v27 >= 0 )
v27 = ~v31;
*(_DWORD *)(v13 + 28) = v32;
*(_DWORD *)(v13 + 16) = 0;
if ( !v33 )
v27 += v28;
*(_DWORD *)(v13 + 20) = 0;
if ( !v33 )
{
v34 = -1;
do
{
*(_BYTE *)v27++ = 0;
++v34;
}
while ( v34 < 4 * *(_DWORD *)(v13 + 40) );
}
if ( *(int *)(v13 + 44) > 0 )
{
v35 = 0;
do
{
v36 = v28 + *(_DWORD *)(v13 + 48) * v35++;
*(_BYTE *)(v36 - 1) = 0;
}
while ( v35 < 4 * *(_DWORD *)(v13 + 44) );
}
*(_DWORD *)(*(_DWORD *)(v13 + 22624) - 4) = 0;
sub_701C04();
sub_71D0A4((_DWORD *)v13);
sub_72FBD8(
(_DWORD *)(v13 + 344),
(int)(float)((float)((float)((float)(*(float *)(v2 + 4) * 5.0) / 100.0) + 1.0) * (float)v60));
if ( sub_71D484((int *)v13) && sub_71D0EC(v13) )
{
if ( *(_DWORD *)(v13 + 22612) )
{
if ( sub_722E08((_DWORD *)v13) )
goto LABEL_104;
}
else if ( sub_722188((int *)v13) )
{
LABEL_104:
if ( !sub_71D128((_DWORD *)v13) )
{
v37 = *(_DWORD **)(v13 + 4);
v38 = (_DWORD *)v37[22];
if ( v38 )
{
v61 = 0;
goto LABEL_53;
}
v61 = 0;
LABEL_74:
if ( *(_DWORD *)(v13 + 368) != 100 )
{
*(_DWORD *)(v13 + 368) = 100;
v54 = (int (*)(void))v37[24];
if ( v54 )
{
if ( !v54() )
v37[23] = 10;
}
}
if ( !v61 )
sub_72F420(v13);
v55 = sub_71D160(v13);
sub_72FBF4((_DWORD *)(v13 + 344));
v4 = v55 & v61;
WebPSafeFree((void *)v13);
return v4;
}
v61 = sub_72F448((_DWORD *)v13) != 0;
LABEL_52:
v37 = *(_DWORD **)(v13 + 4);
v38 = (_DWORD *)v37[22];
if ( v38 )
{
LABEL_53:
v38[31] = *(_DWORD *)(v13 + 1092);
v39 = 99.0;
v38[27] = *(_DWORD *)(v13 + 1088);
v38[11] = *(_DWORD *)(v13 + 22532);
v38[15] = *(_DWORD *)(v13 + 22548);
v38[19] = *(_DWORD *)(v13 + 22564);
v38[32] = *(_DWORD *)(v13 + 1824);
v38[28] = *(_DWORD *)(v13 + 1820);
v38[12] = *(_DWORD *)(v13 + 22536);
v38[16] = *(_DWORD *)(v13 + 22552);
v38[20] = *(_DWORD *)(v13 + 22568);
v38[33] = *(_DWORD *)(v13 + 2556);
v38[29] = *(_DWORD *)(v13 + 2552);
v38[13] = *(_DWORD *)(v13 + 22540);
v38[17] = *(_DWORD *)(v13 + 22556);
v38[21] = *(_DWORD *)(v13 + 22572);
v38[34] = *(_DWORD *)(v13 + 3288);
v38[30] = *(_DWORD *)(v13 + 3284);
v38[14] = *(_DWORD *)(v13 + 22544);
v38[18] = *(_DWORD *)(v13 + 22560);
v38[22] = *(_DWORD *)(v13 + 22576);
v40 = *(_QWORD *)(v13 + 22520) != 0;
v41 = v40;
v63 = *(_QWORD *)(v13 + 22520);
if ( !*(_QWORD *)(v13 + 22488) )
v41 = 0;
v42 = *(float **)(*(_DWORD *)(v13 + 4) + 88);
if ( v41 )
{
v67 = *(_QWORD *)(v13 + 22520) != 0;
v59 = log10(
(double)*(unsigned __int64 *)(v13 + 22520)
* 65025.0
/ (double)*(unsigned __int64 *)(v13 + 22488));
v40 = v67;
v39 = v59 * 10.0;
}
v42[1] = v39;
v43 = 99.0;
v44 = v63 >> 2 != 0;
v65 = v63 >> 2;
if ( !*(_QWORD *)(v13 + 22496) )
v44 = 0;
if ( v44 )
{
v70 = v40;
v58 = log10((double)v65 * 65025.0 / (double)*(unsigned __int64 *)(v13 + 22496));
v40 = v70;
v43 = v58 * 10.0;
}
v42[2] = v43;
v45 = *(_QWORD *)(v13 + 22504);
v46 = 99.0;
v47 = v63 >> 2 != 0;
if ( !v45 )
v47 = 0;
if ( v47 )
{
v69 = v40;
v57 = log10((double)v65 * 65025.0 / (double)v45);
v40 = v69;
v46 = v57 * 10.0;
}
v42[3] = v46;
v48 = 99.0;
v49 = *(_QWORD *)(v13 + 22504) + *(_QWORD *)(v13 + 22496) + *(_QWORD *)(v13 + 22488);
v50 = v49 != 0;
if ( !((3 * v63) >> 1) )
v50 = 0;
if ( v50 )
{
v66 = v40;
v56 = log10((double)((3 * v63) >> 1) * 65025.0 / (double)v49);
v40 = v66;
v48 = v56 * 10.0;
}
v42[4] = v48;
v51 = v40;
LODWORD(v52) = *(_DWORD *)(v13 + 22516);
HIDWORD(v52) = *(_DWORD *)(v13 + 22512);
if ( !v52 )
v51 = 0;
if ( v51 )
v53 = log10((double)v63 * 65025.0 / (double)__PAIR64__(v52, HIDWORD(v52))) * 10.0;
else
v53 = 99.0;
v42[5] = v53;
*v38 = *(_DWORD *)(v13 + 22528);
v38[6] = *(_DWORD *)(v13 + 22580);
v38[7] = *(_DWORD *)(v13 + 22584);
v38[8] = *(_DWORD *)(v13 + 22588);
v37 = *(_DWORD **)(v13 + 4);
goto LABEL_74;
}
goto LABEL_74;
}
}
v61 = 0;
goto LABEL_52;
}
a2[23] = 1;
return v4;
}
return 0;
}
if ( !a2[13] && !WebPPictureYUVAToARGB(a2) )
return 0;
if ( !*(_DWORD *)(v2 + 96) )
sub_72BEF0(a2);
return sub_732784(v2, (int)a2);
}