//
// sub_B76764 from 0xb76764 to 0xb76af8 (916 bytes)
//
// 2 xrefs:
// > sub_B83394 @ 0xb834a4
// > sub_B839AC @ 0xb8718c
//
// 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 sub_B76764(__int64 a1, int a2)
{
const char **v4; // x19
void *v5; // x0
_QWORD *v6; // x21
const char *v7; // x25
__int64 v8; // x0
void **v9; // x21
void **v10; // x0
void **v11; // x19
_QWORD *v13; // x24
time_t v14; // x22
_QWORD *v15; // x0
time_t v16; // x2
_QWORD *v17; // x19
FILE *p_pad1; // x26
int v19; // w27
_QWORD *v20; // x19
char *v21; // x21
__int64 v22; // x0
if ( *(_QWORD *)(a1 + 1688) )
{
v4 = *(const char ***)(a1 + 2344);
if ( v4 )
{
sub_B9EA70(a1, 2, 2);
do
{
v5 = sub_B75BB0(a1, (char *)*v4, *(_BYTE **)(a1 + 2360), *(_BYTE *)(a1 + 977));
if ( v5 )
*(_QWORD *)(a1 + 2360) = v5;
else
sub_B7B528(a1, "ignoring failed cookie_init for %s\n", *v4);
v4 = (const char **)v4[1];
}
while ( v4 );
sub_BA4C54(*(_QWORD *)(a1 + 2344));
*(_QWORD *)(a1 + 2344) = 0;
sub_B9EAD0(a1, 2);
}
sub_B9EA70(a1, 2, 2);
v6 = *(_QWORD **)(a1 + 2360);
v7 = *(const char **)(a1 + 1688);
if ( v6 && v6[3] )
{
v13 = nullptr;
v14 = time(nullptr);
v15 = (_QWORD *)*v6;
if ( *v6 )
{
do
{
while ( 1 )
{
v16 = v15[6];
v17 = (_QWORD *)*v15;
if ( v14 > v16 )
{
if ( v16 )
break;
}
v13 = v15;
v15 = (_QWORD *)*v15;
if ( !v17 )
goto LABEL_26;
}
if ( v15 == (_QWORD *)*v6 )
*v6 = v17;
else
*v13 = v17;
--v6[3];
sub_B74A90((void **)v15);
v15 = v17;
}
while ( v17 );
}
LABEL_26:
if ( !strcmp(&byte_F10E40, v7) )
{
v19 = 1;
p_pad1 = (FILE *)&_sF.__pad1;
fwrite(
"# Netscape HTTP Cookie File\n"
"# https://curl.haxx.se/docs/http-cookies.html\n"
"# This file was generated by libcurl! Edit at your own risk.\n"
"\n",
1u,
0x88u,
(FILE *)&_sF.__pad1);
v20 = (_QWORD *)*v6;
if ( !*v6 )
goto LABEL_10;
do
{
LABEL_33:
if ( v20[5] )
{
v21 = (char *)sub_B8F880("%s%s%s\t%s\t%s\t%s\t%ld\t%s\t%s");
if ( !v21 )
{
sub_B8FBCC(p_pad1, "#\n# Fatal libcurl error\n");
if ( !v19 )
fclose(p_pad1);
goto LABEL_40;
}
sub_B8FBCC(p_pad1, "%s\n", v21);
off_1231008(v21);
}
v20 = (_QWORD *)*v20;
}
while ( v20 );
if ( v19 )
goto LABEL_10;
}
else
{
p_pad1 = fopen(v7, "w");
if ( !p_pad1 )
{
LABEL_40:
sub_B7B528(a1, "WARNING: failed to save cookies in %s\n", *(const char **)(a1 + 1688));
goto LABEL_10;
}
v19 = 0;
fwrite(
"# Netscape HTTP Cookie File\n"
"# https://curl.haxx.se/docs/http-cookies.html\n"
"# This file was generated by libcurl! Edit at your own risk.\n"
"\n",
1u,
0x88u,
p_pad1);
v20 = (_QWORD *)*v6;
if ( *v6 )
goto LABEL_33;
}
fclose(p_pad1);
}
}
else
{
if ( a2 )
{
v22 = *(_QWORD *)(a1 + 2344);
if ( v22 )
{
sub_BA4C54(v22);
*(_QWORD *)(a1 + 2344) = 0;
}
}
sub_B9EA70(a1, 2, 2);
}
LABEL_10:
if ( a2 )
{
v8 = *(_QWORD *)(a1 + 112);
v9 = *(void ***)(a1 + 2360);
if ( !v8 || v9 != *(void ***)(v8 + 80) )
{
if ( v9 )
{
off_1231008(v9[1]);
v10 = (void **)*v9;
if ( *v9 )
{
do
{
v11 = (void **)*v10;
sub_B74A90(v10);
v10 = v11;
}
while ( v11 );
}
off_1231008(v9);
}
}
}
return sub_B9EAD0(a1, 2);
}