//
// sub_10054D6EC from 0x10054d6ec to 0x10054dae0 (1012 bytes)
//
// 2 xrefs:
// > sub_1005587A4 @ 0x100558910
// > sub_100558DA8 @ 0x10055ba90
//
// 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_10054D6EC(_QWORD *a1, int a2)
{
int v2; // w20
void **v4; // x24
const char *v5; // x21
time_t v6; // x22
void *v7; // x25
void *v8; // x23
_QWORD *v9; // x27
time_t v10; // x8
FILE *v12; // x21
__int64 v13; // x0
void *v14; // x26
const char *v15; // x8
const char *v16; // x9
const char *v17; // x10
const char *v18; // x11
const char *v19; // x12
const char *v20; // x16
const char *v21; // x13
const char *v22; // x0
char *v23; // x24
__int64 v24; // x8
void **v25; // x20
void **v27; // x21
void **v28; // x23
char v30; // [xsp+48h] [xbp-58h]
int v31; // [xsp+4Ch] [xbp-54h]
v2 = a2;
if ( !a1[177] )
{
if ( a2 )
{
v13 = a1[244];
if ( v13 )
{
sub_100574898(v13);
a1[244] = 0;
}
}
sub_10056FCA8(a1, 2, 2);
goto LABEL_53;
}
if ( a1[244] )
sub_10054B9CC((__int64)a1);
sub_10056FCA8(a1, 2, 2);
v4 = (void **)a1[246];
if ( !v4 || !v4[3] )
goto LABEL_53;
v5 = (const char *)a1[177];
v6 = time(nullptr);
v7 = *v4;
if ( *v4 )
{
v8 = nullptr;
do
{
v9 = v8;
v8 = v7;
while ( 1 )
{
v7 = *(void **)v8;
v10 = *((_QWORD *)v8 + 6);
if ( !v10 || v10 >= v6 )
break;
if ( v8 == *v4 )
*v4 = v7;
else
*v9 = v7;
v4[3] = (char *)v4[3] - 1;
off_10085DEB8(*((void **)v8 + 7));
off_10085DEB8(*((void **)v8 + 5));
off_10085DEB8(*((void **)v8 + 3));
off_10085DEB8(*((void **)v8 + 4));
off_10085DEB8(*((void **)v8 + 1));
off_10085DEB8(*((void **)v8 + 2));
off_10085DEB8(*((void **)v8 + 10));
off_10085DEB8(*((void **)v8 + 9));
off_10085DEB8(v8);
v8 = v7;
if ( !v7 )
goto LABEL_20;
}
}
while ( v7 );
}
LABEL_20:
if ( (unsigned int)sub_1005679B0("-", v5) )
{
v31 = v2;
v12 = __stdoutp;
v30 = 1;
}
else
{
v12 = fopen(v5, "w");
if ( !v12 )
goto LABEL_52;
v30 = 0;
v31 = v2;
}
fputs(
"# 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",
v12);
v14 = *v4;
if ( !*v4 )
{
LABEL_48:
v2 = v31;
if ( (v30 & 1) == 0 )
fclose(v12);
goto LABEL_53;
}
while ( 1 )
{
v15 = *((const char **)v14 + 5);
if ( v15 )
break;
LABEL_47:
v14 = *(void **)v14;
if ( !v14 )
goto LABEL_48;
}
v16 = "#HttpOnly_";
if ( !*((_BYTE *)v14 + 90) )
v16 = "";
v17 = "";
if ( *((_BYTE *)v14 + 64) )
{
v17 = ".";
if ( *v15 == 46 )
v17 = "";
}
if ( *((_BYTE *)v14 + 64) )
v18 = "TRUE";
else
v18 = "FALSE";
v20 = *((const char **)v14 + 2);
v19 = *((const char **)v14 + 3);
if ( !v19 )
v19 = "/";
if ( *((_BYTE *)v14 + 88) )
v21 = "TRUE";
else
v21 = "FALSE";
if ( !v20 )
v20 = "";
v22 = (const char *)sub_1005628DC(
"%s%s%s\t%s\t%s\t%s\t%ld\t%s\t%s",
v16,
v17,
v15,
v18,
v19,
v21,
*((_QWORD *)v14 + 6),
*((const char **)v14 + 1),
v20);
v23 = (char *)v22;
if ( v22 )
{
sub_100562B00(v12, "%s\n", v22);
off_10085DEB8(v23);
goto LABEL_47;
}
sub_100562B00(v12, "#\n# Fatal libcurl error\n");
v2 = v31;
if ( (v30 & 1) == 0 )
fclose(v12);
LABEL_52:
sub_1005524A4(a1, "WARNING: failed to save cookies in %s\n", (const char *)a1[177]);
LABEL_53:
if ( v2 )
{
v24 = a1[14];
v25 = (void **)a1[246];
if ( v24 )
{
if ( v25 != *(void ***)(v24 + 80) && v25 != nullptr )
goto LABEL_62;
}
else if ( v25 )
{
LABEL_62:
off_10085DEB8(v25[1]);
v27 = (void **)*v25;
if ( *v25 )
{
do
{
v28 = (void **)*v27;
off_10085DEB8(v27[7]);
off_10085DEB8(v27[5]);
off_10085DEB8(v27[3]);
off_10085DEB8(v27[4]);
off_10085DEB8(v27[1]);
off_10085DEB8(v27[2]);
off_10085DEB8(v27[10]);
off_10085DEB8(v27[9]);
off_10085DEB8(v27);
v27 = v28;
}
while ( v28 );
}
off_10085DEB8(v25);
}
}
return sub_10056FCF4(a1, 2);
}