//
// sub_18003C920 from 0x18003c920 to 0x18003ccc0 (928 bytes)
//
// 7 xrefs:
// > sub_18003C030 @ 0x18003c2d0
// > sub_18003C030 @ 0x18003c381
// > ??> @ 0x1801808c4
// > ??> @ 0x1801808e4
// > ??> @ 0x1801808f4
// > ??> @ 0x1801f7de8
// > ??> @ 0x1801f7df4
//
// 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_18003C920(_DWORD *a1, _WORD *a2, int a3, unsigned int a4, int a5, int a6)
{
unsigned int v6; // r13d
int v7; // r12d
_DWORD *v9; // r15
int v10; // eax
unsigned __int8 *v11; // r14
int v12; // edi
int v13; // r11d
int v14; // r9d
__int64 v15; // rbp
unsigned int v16; // eax
unsigned int v17; // esi
__int64 v18; // r10
int v19; // r8d
int v20; // edx
int v21; // r11d
int v22; // eax
int v23; // r10d
int v24; // edi
__int64 v25; // rsi
int v26; // r8d
int v27; // eax
int v28; // eax
_DWORD *v30; // [rsp+50h] [rbp+8h]
v30 = a1;
v6 = a4;
v7 = a3;
v9 = a1;
if ( !a3 )
return 0;
v10 = a5 - 1;
while ( 1 )
{
v11 = (unsigned __int8 *)(v9 + 1);
v12 = v10;
v13 = (__int16)*v9;
--v7;
v14 = (unsigned __int8)BYTE2(*v9);
if ( (unsigned int)v14 >= 0x59 )
return 13;
v15 = 2LL * a6;
*a2 = *v9;
a2 = (_WORD *)((char *)a2 + v15);
if ( v10 )
{
do
{
v16 = *v11++;
v17 = v16;
v18 = v16 & 0xF;
v19 = word_180165450[v14];
v20 = v19 >> 3;
switch ( v16 & 0xF )
{
case 1u:
v19 >>= 2;
goto LABEL_7;
case 2u:
v20 += v19 >> 1;
break;
case 3u:
v20 += (v19 >> 2) + (v19 >> 1);
break;
case 4u:
LABEL_7:
v20 += v19;
break;
case 5u:
v20 += v19 + (v19 >> 2);
break;
case 6u:
v20 += v19 + (v19 >> 1);
break;
case 7u:
v20 += v19 + (v19 >> 2) + (v19 >> 1);
break;
case 8u:
goto LABEL_20;
case 9u:
v19 >>= 2;
goto LABEL_19;
case 0xAu:
v19 >>= 1;
goto LABEL_19;
case 0xBu:
v19 >>= 1;
v20 += word_180165450[v14] >> 2;
goto LABEL_19;
case 0xCu:
goto LABEL_19;
case 0xDu:
v20 += v19 >> 2;
goto LABEL_19;
case 0xEu:
v20 += v19 >> 1;
goto LABEL_19;
case 0xFu:
v20 += (v19 >> 1) + (v19 >> 2);
LABEL_19:
v20 += v19;
LABEL_20:
v20 = -v20;
break;
default:
break;
}
v21 = v20 + v13;
if ( (__int16)v21 != v21 )
{
v22 = 0x7FFF;
if ( v21 < -32768 )
v22 = -32768;
v21 = v22;
}
v23 = v14 + dword_180165410[v18];
if ( v23 >= 0 )
{
if ( v23 >= 89 )
v23 = 88;
}
else
{
v23 = 0;
}
*a2 = v21;
a2 = (_WORD *)((char *)a2 + v15);
v24 = v12 - 1;
if ( !v24 )
break;
v25 = v17 >> 4;
v26 = word_180165450[v23];
v27 = v26 >> 3;
switch ( (int)v25 )
{
case 1:
v26 >>= 2;
goto LABEL_32;
case 2:
v27 += v26 >> 1;
break;
case 3:
v27 += (v26 >> 2) + (v26 >> 1);
break;
case 4:
LABEL_32:
v27 += v26;
break;
case 5:
v27 += v26 + (v26 >> 2);
break;
case 6:
v27 += v26 + (v26 >> 1);
break;
case 7:
v27 += v26 + (v26 >> 2) + (v26 >> 1);
break;
case 8:
goto LABEL_45;
case 9:
v26 >>= 2;
goto LABEL_44;
case 10:
v26 >>= 1;
goto LABEL_44;
case 11:
v26 >>= 1;
v27 += word_180165450[v23] >> 2;
goto LABEL_44;
case 12:
goto LABEL_44;
case 13:
v27 += v26 >> 2;
goto LABEL_44;
case 14:
v27 += v26 >> 1;
goto LABEL_44;
case 15:
v27 += (v26 >> 1) + (v26 >> 2);
LABEL_44:
v27 += v26;
LABEL_45:
v27 = -v27;
break;
default:
break;
}
v13 = v27 + v21;
if ( (__int16)v13 != v13 )
{
v28 = 0x7FFF;
if ( v13 < -32768 )
v28 = -32768;
v13 = v28;
}
v14 = v23 + dword_180165410[v25];
if ( v14 >= 0 )
{
if ( v14 >= 89 )
v14 = 88;
}
else
{
v14 = 0;
}
*a2 = v13;
a2 = (_WORD *)((char *)a2 + v15);
v12 = v24 - 1;
}
while ( v12 );
v9 = v30;
v6 = a4;
}
v10 = a5 - 1;
v9 = (_DWORD *)((char *)v9 + v6);
v30 = v9;
if ( !v7 )
return 0;
}
}