//
// sub_180039980 from 0x180039980 to 0x18003a305 (2437 bytes)
//
// 5 xrefs:
// > sub_18003AC00 @ 0x18003aff3
// > ??> @ 0x180180734
// > ??> @ 0x180180744
// > ??> @ 0x180180764
// > ??> @ 0x1801f7cc8
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 10:53:08 +0000
//
__int64 __fastcall sub_180039980(__int64 a1)
{
__int64 v2; // rcx
unsigned __int64 v3; // rbx
__int64 result; // rax
int v5; // eax
int i; // r13d
__int64 v7; // rcx
int v8; // ebx
int v9; // edi
int v10; // ecx
int v11; // ebx
char *v12; // r9
int v13; // ebx
int v14; // edi
int v15; // ecx
int v16; // ebx
char *v17; // r9
int v18; // ebx
int v19; // edi
int v20; // ecx
int v21; // ebx
char *v22; // r9
int v23; // ebx
int v24; // edi
int v25; // ecx
int v26; // ebx
char *v27; // r9
int v28; // ebx
int v29; // edi
int v30; // ecx
int v31; // ebx
char *v32; // r9
int v33; // r12d
const wchar_t *v34; // r15
int v35; // esi
int v36; // edi
int v37; // eax
int v38; // edx
wchar_t *v39; // r9
int v40; // [rsp+20h] [rbp-79h]
int v41; // [rsp+40h] [rbp-59h] BYREF
unsigned __int16 v42; // [rsp+44h] [rbp-55h] BYREF
unsigned __int16 v43; // [rsp+48h] [rbp-51h] BYREF
unsigned __int16 v44; // [rsp+4Ch] [rbp-4Dh] BYREF
int v45; // [rsp+50h] [rbp-49h] BYREF
int v46; // [rsp+54h] [rbp-45h] BYREF
int v47; // [rsp+58h] [rbp-41h] BYREF
int v48; // [rsp+5Ch] [rbp-3Dh] BYREF
int v49; // [rsp+60h] [rbp-39h] BYREF
unsigned __int16 v50; // [rsp+64h] [rbp-35h] BYREF
unsigned __int64 v51; // [rsp+68h] [rbp-31h]
unsigned int v52; // [rsp+70h] [rbp-29h] BYREF
int v53; // [rsp+74h] [rbp-25h] BYREF
__int64 v54; // [rsp+80h] [rbp-19h]
unsigned __int64 v55; // [rsp+88h] [rbp-11h]
__int64 v56; // [rsp+90h] [rbp-9h] BYREF
__int64 v57; // [rsp+98h] [rbp-1h]
__int64 v58; // [rsp+A0h] [rbp+7h]
_QWORD v59[2]; // [rsp+A8h] [rbp+Fh] BYREF
__int64 v60; // [rsp+B8h] [rbp+1Fh]
v2 = *(_QWORD *)(a1 + 368);
v3 = 0;
v51 = 0;
result = (*(__int64 (__fastcall **)(__int64, unsigned int *))(*(_QWORD *)v2 + 16LL))(v2, &v52);
if ( !(_DWORD)result )
{
v55 = v52;
while ( 1 )
{
result = sub_1800B3990(*(_QWORD *)(a1 + 368), (unsigned int)v3, 0);
if ( (_DWORD)result )
break;
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)v59, 1, 24, (__int64)&v41);
if ( (_DWORD)result || v41 != 24 )
break;
if ( v59[0] == 0x11CF668E75B22630LL && v59[1] == 0x6CCE6200AA00D9A6LL )
{
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&v53, 1, 6, (__int64)&v41);
if ( (_DWORD)result || v41 != 6 )
return result;
v5 = 30;
v54 = 30;
for ( i = 0; i < v53; v54 += v58 )
{
result = sub_1800B3990(*(_QWORD *)(a1 + 368), (unsigned int)(v5 + v3), 0);
if ( (_DWORD)result )
return result;
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&v56, 1, 24, (__int64)&v41);
if ( (_DWORD)result || v41 != 24 )
return result;
if ( v56 == 0x11CF668E75B22633LL && v57 == 0x6CCE6200AA00D9A6LL )
{
v7 = *(_QWORD *)(a1 + 368);
v45 = 0;
v46 = 0;
v47 = 0;
v48 = 0;
v49 = 0;
result = sub_1800B3470(v7, (unsigned int)&v45, 2, 1, (__int64)&v41);
if ( (_DWORD)result )
return result;
if ( v41 != 1 )
return result;
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&v46, 2, 1, (__int64)&v41);
if ( (_DWORD)result )
return result;
if ( v41 != 1 )
return result;
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&v47, 2, 1, (__int64)&v41);
if ( (_DWORD)result )
return result;
if ( v41 != 1 )
return result;
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&v48, 2, 1, (__int64)&v41);
if ( (_DWORD)result )
return result;
if ( v41 != 1 )
return result;
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&v49, 2, 1, (__int64)&v41);
if ( (_DWORD)result || v41 != 1 )
return result;
if ( v45 )
{
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&word_1801C5E50, 1, v45, (__int64)&v41);
if ( (_DWORD)result || v41 != v45 )
return result;
v8 = v45 / 2;
v9 = v8 - 1;
v10 = wcstombs(Dest, &word_1801C5E50, 0x1000u);
if ( v10 == v8 - 1 )
v11 = v8 - 1;
else
v11 = v45 - 2;
v12 = Dest;
if ( v10 != v9 )
v12 = (char *)&word_1801C5E50;
result = sub_180012590(a1, 6, (int)"TITLE", (int)v12, v11, (unsigned int)(v10 != v9) + 3, 0);
if ( (_DWORD)result )
return result;
}
if ( v46 )
{
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&word_1801C5E50, 1, v46, (__int64)&v41);
if ( (_DWORD)result || v41 != v46 )
return result;
v13 = v46 / 2;
v14 = v13 - 1;
v15 = wcstombs(Dest, &word_1801C5E50, 0x1000u);
if ( v15 == v13 - 1 )
v16 = v13 - 1;
else
v16 = v46 - 2;
v17 = Dest;
if ( v15 != v14 )
v17 = (char *)&word_1801C5E50;
result = sub_180012590(a1, 6, (int)"AUTHOR", (int)v17, v16, (unsigned int)(v15 != v14) + 3, 0);
if ( (_DWORD)result )
return result;
}
if ( v47 )
{
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&word_1801C5E50, 1, v47, (__int64)&v41);
if ( (_DWORD)result || v41 != v47 )
return result;
v18 = v47 / 2;
v19 = v18 - 1;
v20 = wcstombs(Dest, &word_1801C5E50, 0x1000u);
if ( v20 == v18 - 1 )
v21 = v18 - 1;
else
v21 = v47 - 2;
v22 = Dest;
if ( v20 != v19 )
v22 = (char *)&word_1801C5E50;
result = sub_180012590(a1, 6, (int)"COPYRIGHT", (int)v22, v21, (unsigned int)(v20 != v19) + 3, 0);
if ( (_DWORD)result )
return result;
}
if ( v48 )
{
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&word_1801C5E50, 1, v48, (__int64)&v41);
if ( (_DWORD)result || v41 != v48 )
return result;
v23 = v48 / 2;
v24 = v23 - 1;
v25 = wcstombs(Dest, &word_1801C5E50, 0x1000u);
if ( v25 == v23 - 1 )
v26 = v23 - 1;
else
v26 = v48 - 2;
v27 = Dest;
if ( v25 != v24 )
v27 = (char *)&word_1801C5E50;
result = sub_180012590(a1, 6, (int)"DESCRIPTION", (int)v27, v26, (unsigned int)(v25 != v24) + 3, 0);
if ( (_DWORD)result )
return result;
}
if ( v49 )
{
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&word_1801C5E50, 1, v49, (__int64)&v41);
if ( (_DWORD)result || v41 != v49 )
return result;
v28 = v49 / 2;
v29 = v28 - 1;
v30 = wcstombs(Dest, &word_1801C5E50, 0x1000u);
v31 = v30 == v28 - 1 ? v28 - 1 : v49 - 2;
v32 = Dest;
if ( v30 != v29 )
v32 = (char *)&word_1801C5E50;
result = sub_180012590(a1, 6, (int)"RATING", (int)v32, v31, (unsigned int)(v30 != v29) + 3, 0);
if ( (_DWORD)result )
return result;
}
LABEL_101:
v3 = v51;
}
else if ( v56 == 0x11D2E307D2D0A440LL && v57 == 0x50A85EC9A000F097LL )
{
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&v44, 2, 1, (__int64)&v41);
if ( (_DWORD)result || v41 != 1 )
return result;
v33 = 0;
if ( v44 )
{
while ( 1 )
{
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&v43, 2, 1, (__int64)&v41);
if ( (_DWORD)result )
return result;
if ( v41 != 1 )
return result;
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)word_1801C8E80, 1, v43, (__int64)&v41);
if ( (_DWORD)result )
return result;
if ( v41 != v43 )
return result;
wcstombs(byte_1801C7E70, word_1801C8E80, 0x1000u);
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&v50, 2, 1, (__int64)&v41);
if ( (_DWORD)result )
return result;
if ( v41 != 1 )
return result;
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (unsigned int)&v42, 2, 1, (__int64)&v41);
if ( (_DWORD)result || v41 != 1 )
return result;
v34 = (const wchar_t *)sub_1800B6880(
*((_QWORD *)off_1801AED20 + 52),
v42,
(unsigned int)"C:\\buildagent1\\work\\570ad728b1678096\\core_api\\src\\fmod_codec_tag.cpp",
1069,
0);
if ( !v34 )
return 38;
result = sub_1800B3470(*(_QWORD *)(a1 + 368), (_DWORD)v34, 1, v42, (__int64)&v41);
if ( (_DWORD)result || v41 != v42 )
return result;
if ( v50 )
{
if ( v50 == 2 )
{
result = sub_180012590(a1, 6, (int)byte_1801C7E70, (int)v34, v42, 0, 0);
}
else if ( v50 == 3 || (unsigned int)v50 - 4 < 2 )
{
result = sub_180012590(a1, 6, (int)byte_1801C7E70, (int)v34, v42, 1, 0);
}
else
{
result = sub_180012590(a1, 6, (int)byte_1801C7E70, (int)v34, v42, 3, 0);
}
if ( (_DWORD)result )
return result;
}
else
{
v35 = v42;
v36 = v42 >> 1;
v37 = wcstombs((char *)word_1801C8E80, v34, 0x1000u);
v38 = v36 - 1;
v39 = word_1801C8E80;
if ( v37 != v36 - 1 )
{
LODWORD(v39) = (_DWORD)v34;
v38 = v35 - 2;
}
result = sub_180012590(
a1,
6,
(int)byte_1801C7E70,
(int)v39,
v38,
(unsigned int)(v37 != v36 - 1) + 3,
0);
if ( (_DWORD)result )
return result;
}
LOBYTE(v40) = 1;
sub_1800B6AA0(
*((_QWORD *)off_1801AED20 + 52),
v34,
"C:\\buildagent1\\work\\570ad728b1678096\\core_api\\src\\fmod_codec_tag.cpp",
1130,
v40);
if ( ++v33 >= v44 )
goto LABEL_101;
}
}
}
++i;
v5 = v58 + v54;
}
}
v3 += v60;
v51 = v3;
if ( v3 >= v55 || !v60 )
return 0;
}
}
return result;
}