//
// sub_18003CCC0 from 0x18003ccc0 to 0x18003d0b0 (1008 bytes)
//
// 6 xrefs:
// > sub_18003C030 @ 0x18003c2f6
// > ??> @ 0x180180928
// > ??> @ 0x180180954
// > ??> @ 0x180180964
// > ??> @ 0x1801f7e18
// > ??> @ 0x1801f7e24
//
// 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_18003CCC0(_DWORD *a1, _WORD *a2, int a3, unsigned int a4, int a5)
{
_DWORD *v6; // rdx
unsigned int v7; // eax
int v8; // ecx
int *v9; // r12
unsigned int v10; // r13d
int v11; // r10d
int v12; // r9d
int v13; // edx
unsigned int v14; // eax
unsigned int *v15; // r12
int v16; // r11d
int v17; // esi
unsigned int v18; // ebp
unsigned int v19; // eax
unsigned int v20; // r14d
__int64 v21; // r15
int v22; // r8d
int v23; // eax
int v24; // eax
int v25; // r8d
int v26; // edx
int v27; // eax
int v29; // [rsp+0h] [rbp-58h]
unsigned int v30; // [rsp+4h] [rbp-54h]
_DWORD *v31; // [rsp+60h] [rbp+8h]
int v32; // [rsp+70h] [rbp+18h]
v31 = a1;
v6 = a1;
if ( !a3 )
return 0;
v7 = a5 - 1;
while ( 1 )
{
v8 = *v6;
v9 = v6 + 1;
v10 = v7;
v30 = v7;
--a3;
v11 = (__int16)*v6;
v32 = a3;
v12 = (unsigned __int8)BYTE2(*v6);
if ( (unsigned int)v12 >= 0x59 )
return 13;
v13 = *v9;
v14 = HIWORD(*v9);
v15 = (unsigned int *)(v9 + 1);
v16 = (unsigned __int8)v14;
v17 = (__int16)v13;
if ( (unsigned __int8)v14 >= 0x59u )
return 13;
*a2 = v8;
a2[1] = v13;
a2 += 2;
if ( v10 )
{
do
{
v18 = *v15;
v19 = 8;
v20 = v15[1];
v29 = 8;
if ( v10 < 8 )
{
v19 = v10;
v29 = v10;
}
v21 = v19;
do
{
v22 = word_180165450[v12];
v23 = v22 >> 3;
switch ( v18 & 0xF )
{
case 1u:
v22 >>= 2;
goto LABEL_11;
case 2u:
v23 += v22 >> 1;
break;
case 3u:
v23 += (v22 >> 2) + (v22 >> 1);
break;
case 4u:
LABEL_11:
v23 += v22;
break;
case 5u:
v23 += v22 + (v22 >> 2);
break;
case 6u:
v23 += v22 + (v22 >> 1);
break;
case 7u:
v23 += v22 + (v22 >> 2) + (v22 >> 1);
break;
case 8u:
goto LABEL_24;
case 9u:
v22 >>= 2;
goto LABEL_23;
case 0xAu:
v22 >>= 1;
goto LABEL_23;
case 0xBu:
v22 >>= 1;
v23 += word_180165450[v12] >> 2;
goto LABEL_23;
case 0xCu:
goto LABEL_23;
case 0xDu:
v23 += v22 >> 2;
goto LABEL_23;
case 0xEu:
v23 += v22 >> 1;
goto LABEL_23;
case 0xFu:
v23 += (v22 >> 1) + (v22 >> 2);
LABEL_23:
v23 += v22;
LABEL_24:
v23 = -v23;
break;
default:
break;
}
v11 += v23;
if ( (__int16)v11 != v11 )
{
v24 = 0x7FFF;
if ( v11 < -32768 )
v24 = -32768;
v11 = v24;
}
v12 += dword_180165410[v18 & 0xF];
if ( v12 >= 0 )
{
if ( v12 >= 89 )
v12 = 88;
}
else
{
v12 = 0;
}
v25 = word_180165450[v16];
v26 = v25 >> 3;
switch ( v20 & 0xF )
{
case 1u:
v25 >>= 2;
goto LABEL_35;
case 2u:
v26 += v25 >> 1;
break;
case 3u:
v26 += (v25 >> 2) + (v25 >> 1);
break;
case 4u:
LABEL_35:
v26 += v25;
break;
case 5u:
v26 += v25 + (v25 >> 2);
break;
case 6u:
v26 += v25 + (v25 >> 1);
break;
case 7u:
v26 += v25 + (v25 >> 2) + (v25 >> 1);
break;
case 8u:
goto LABEL_48;
case 9u:
v25 >>= 2;
goto LABEL_47;
case 0xAu:
v25 >>= 1;
goto LABEL_47;
case 0xBu:
v25 >>= 1;
v26 += word_180165450[v16] >> 2;
goto LABEL_47;
case 0xCu:
goto LABEL_47;
case 0xDu:
v26 += v25 >> 2;
goto LABEL_47;
case 0xEu:
v26 += v25 >> 1;
goto LABEL_47;
case 0xFu:
v26 += (v25 >> 1) + (v25 >> 2);
LABEL_47:
v26 += v25;
LABEL_48:
v26 = -v26;
break;
default:
break;
}
v17 += v26;
if ( (__int16)v17 != v17 )
{
v27 = 0x7FFF;
if ( v17 < -32768 )
v27 = -32768;
v17 = v27;
}
v16 += dword_180165410[v20 & 0xF];
if ( v16 >= 0 )
{
if ( v16 >= 89 )
v16 = 88;
}
else
{
v16 = 0;
}
*a2 = v11;
a2[1] = v17;
a2 += 2;
v18 >>= 4;
v20 >>= 4;
--v21;
}
while ( v21 );
v15 += 2;
v10 = v30 - v29;
v30 = v10;
}
while ( v10 );
a3 = v32;
}
v7 = a5 - 1;
v6 = (_DWORD *)((char *)v31 + a4);
v31 = v6;
if ( !a3 )
return 0;
}
}