//
// sub_1004D8C48 from 0x1004d8c48 to 0x1004d8ed8 (656 bytes)
//
// 0 xrefs:
//
// 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_1004D8C48(__int64 a1, int a2, const char **a3)
{
unsigned __int64 v3; // x8
const char *v4; // x8
int v5; // w8
unsigned int v6; // w14
__int64 v7; // x10
unsigned int v8; // w9
__int64 result; // x0
unsigned int v10; // w15
__int64 v11; // x17
_QWORD **v12; // x15
__int64 v13; // x16
__int64 v14; // x17
const mach_header_64 *v15; // x0
if ( a2 )
{
v3 = *(_QWORD *)(a1 + 136);
if ( v3 <= 0x15887 )
{
if ( a3 )
{
v4 = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
goto LABEL_54;
}
return 0;
}
if ( __ROR8__(0xD4766BF908B51D9BLL * v3, 2) >= 0x6F74AE26501BDEuLL )
{
if ( a3 )
{
v4 = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
goto LABEL_54;
}
return 0;
}
v5 = *(_DWORD *)(a1 + 148);
if ( v5 )
{
if ( *(unsigned __int8 *)(*(_QWORD *)(a1 + 152) + 32LL * (unsigned int)(v5 - 1) + 8) != 170 )
{
if ( a3 )
{
v4 = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
goto LABEL_54;
}
return 0;
}
goto LABEL_6;
}
LABEL_36:
if ( a3 )
{
v4 = "cue sheet must have at least one track (the lead-out)";
goto LABEL_54;
}
return 0;
}
v5 = *(_DWORD *)(a1 + 148);
if ( !v5 )
goto LABEL_36;
LABEL_6:
v6 = 0;
v7 = *(_QWORD *)(a1 + 152);
v8 = v5 - 1;
while ( 1 )
{
v10 = *(unsigned __int8 *)(v7 + 32LL * v6 + 8);
if ( !*(_BYTE *)(v7 + 32LL * v6 + 8) )
{
if ( !a3 )
return 0;
v4 = "cue sheet may not have a track number 0";
goto LABEL_54;
}
if ( a2 && v10 >= 0x64 )
{
if ( v10 != 170 )
{
if ( !a3 )
return 0;
v4 = "CD-DA cue sheet track number must be 1-99 or 170";
goto LABEL_54;
}
}
else if ( !a2 )
{
goto LABEL_15;
}
if ( __ROR8__(0xD4766BF908B51D9BLL * *(_QWORD *)(v7 + 32LL * v6), 2) >= 0x6F74AE26501BDEuLL )
{
if ( !a3 )
return 0;
v4 = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
if ( v6 == v8 )
v4 = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
goto LABEL_54;
}
LABEL_15:
v11 = *(unsigned __int8 *)(v7 + 32LL * v6 + 23);
if ( v6 >= v8 )
{
if ( !*(_BYTE *)(v7 + 32LL * v6 + 23) )
goto LABEL_7;
goto LABEL_20;
}
if ( !*(_BYTE *)(v7 + 32LL * v6 + 23) )
{
if ( !a3 )
return 0;
v4 = "cue sheet track must have at least one index point";
goto LABEL_54;
}
if ( *(unsigned __int8 *)(*(_QWORD *)(v7 + 32LL * v6 + 24) + 8LL) >= 2u )
break;
LABEL_20:
v12 = (_QWORD **)(v7 + 32LL * v6 + 24);
if ( a2 && __ROR8__(0xD4766BF908B51D9BLL * **v12, 2) > 0x6F74AE26501BDDuLL )
goto LABEL_40;
if ( (_DWORD)v11 != 1 )
{
v13 = 0;
v14 = v11 - 1;
v15 = &_mh_execute_header;
while ( !a2 || __ROR8__(0xD4766BF908B51D9BLL * (*v12)[v13 + 2], 2) < 0x6F74AE26501BDEuLL )
{
if ( LOBYTE((*v12)[2 * (unsigned int)v15 + 1]) + 1 != LOBYTE((*v12)[v13 + 3]) )
{
if ( !a3 )
return 0;
v4 = "cue sheet track index numbers must increase by 1";
goto LABEL_54;
}
LODWORD(v15) = (_DWORD)v15 + 1;
v13 += 2;
if ( !--v14 )
goto LABEL_7;
}
LABEL_40:
if ( !a3 )
return 0;
v4 = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
goto LABEL_54;
}
LABEL_7:
++v6;
result = 1;
if ( v6 == v5 )
return result;
}
if ( !a3 )
return 0;
v4 = "cue sheet track's first index number must be 0 or 1";
LABEL_54:
result = 0;
*a3 = v4;
return result;
}