//
// WebPMemoryWrite from 0xca717c to 0xca7268 (236 bytes)
//
// 3 xrefs:
// > ??> @ 0x7af40
// > sub_CA772C @ 0xca77c8
// > ??> @ 0x122c1b0
//
// 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
//
__int64 __fastcall WebPMemoryWrite(void *a1, size_t a2, __int64 a3)
{
__int64 v3; // x20
unsigned __int64 v5; // x19
unsigned __int64 v7; // x2
unsigned __int64 v8; // x19
void *v9; // x0
void *v10; // x23
size_t v11; // x2
v3 = *(_QWORD *)(a3 + 104);
if ( !v3 )
return 1;
v5 = *(_QWORD *)(v3 + 16);
v7 = a2 + *(_QWORD *)(v3 + 8);
if ( v7 > v5 )
{
v8 = 2 * v5;
if ( v7 >= v8 )
v8 = a2 + *(_QWORD *)(v3 + 8);
if ( v8 <= 0x1FFF )
v8 = 0x2000;
v9 = (void *)WebPSafeMalloc(v8, 1);
v10 = v9;
if ( !v9 )
return 0;
v11 = *(_QWORD *)(v3 + 8);
if ( v11 )
memcpy(v9, *(const void **)v3, v11);
WebPSafeFree(*(void **)v3);
*(_QWORD *)v3 = v10;
*(_QWORD *)(v3 + 16) = v8;
}
if ( !a2 )
return 1;
memcpy((void *)(*(_QWORD *)v3 + *(_QWORD *)(v3 + 8)), a1, a2);
*(_QWORD *)(v3 + 8) += a2;
return 1;
}