/* DxeIplHuffmanBuildTable @ 0xffc1663a size=0x2bf */
int __fastcall DxeIplHuffmanBuildTable(int this, unsigned __int16 n0x3FB, int a3, unsigned __int16 n0x10, int a5)
{
unsigned __int16 v5; // si
unsigned __int8 n0x10_1; // al
int n15; // ecx
int v8; // edx
int n16; // esi
__int16 v10; // ax
__int16 v11; // ax
unsigned __int16 n0x10_2; // bp
int n0x10_4; // esi
char v14; // bl
char n0x10_3; // al
int n0x10_7; // edx
__int16 v17; // ax
int n0x10_5; // edx
__int16 v19; // ax
unsigned __int16 v20; // ax
int v21; // edx
int v22; // eax
unsigned int v23; // eax
int n0x3FB_4; // esi
int v25; // edi
int v26; // ecx
unsigned int n0x10_6; // edx
unsigned int v28; // ecx
unsigned __int16 v29; // bx
unsigned __int16 v30; // di
unsigned __int16 v31; // dx
int v32; // ebx
_WORD *v33; // ecx
int n0x3FB_2; // ebp
unsigned __int16 v35; // si
int n0x3FB_3; // edx
int v37; // ecx
int v39; // eax
unsigned __int16 v42; // [esp+14h] [ebp-64h]
int n0x3FB_1; // [esp+18h] [ebp-60h]
int n0x3FB_5; // [esp+1Ch] [ebp-5Ch]
unsigned __int16 v45; // [esp+20h] [ebp-58h]
unsigned __int16 v46; // [esp+28h] [ebp-50h]
int v47; // [esp+2Ch] [ebp-4Ch]
_WORD buf[18]; // [esp+30h] [ebp-48h] BYREF
_DWORD v49[8]; // [esp+54h] [ebp-24h]
__int16 v50; // [esp+76h] [ebp-2h]
memset(buf, 0, 34); /*0xffc16652*/
v5 = 0; /*0xffc16656*/
if ( n0x3FB ) /*0xffc1665f*/
{
do /*0xffc16668*/
{
n0x10_1 = *(_BYTE *)(v5 + a3); /*0xffc16668*/
if ( n0x10_1 > 0x10u ) /*0xffc1666d*/
return 0xFFFF; /*0xffc1666d*/
++buf[n0x10_1]; /*0xffc16676*/
}
while ( ++v5 < n0x3FB ); /*0xffc16668*/
}
n15 = 15; /*0xffc16681*/
v8 = 0; /*0xffc16686*/
v49[0] = 0; /*0xffc1668b*/
n16 = 16; /*0xffc1668f*/
do /*0xffc166aa*/
{
v10 = buf[++v8]; /*0xffc16691*/
v11 = *(_WORD *)((char *)v49 + v8 * 2) + (v10 << n15--); /*0xffc1669c*/
*(_WORD *)((char *)v49 + v8 * 2 + 2) = v11; /*0xffc166a2*/
--n16; /*0xffc166a7*/
}
while ( n16 ); /*0xffc166aa*/
if ( v50 ) /*0xffc166b1*/
return 0xFFFF; /*0xffc1687f*/
n0x10_2 = n0x10; /*0xffc166bc*/
n0x10_4 = 1; /*0xffc166c6*/
v14 = 16 - n0x10; /*0xffc166c8*/
buf[0] = 0; /*0xffc166cd*/
if ( !n0x10 ) /*0xffc166d5*/
goto LABEL_45; /*0xffc166d5*/
n0x10_3 = n0x10; /*0xffc166d7*/
do /*0xffc166ff*/
{
n0x10_7 = (unsigned __int16)n0x10_4; /*0xffc166de*/
*((_WORD *)v49 + (unsigned __int16)n0x10_4) >>= v14; /*0xffc166e4*/
v17 = 1 << (n0x10_3 - n0x10_4++); /*0xffc166ef*/
buf[n0x10_7] = v17; /*0xffc166f3*/
n0x10_3 = n0x10; /*0xffc166f8*/
}
while ( (unsigned __int16)n0x10_4 <= n0x10 ); /*0xffc166ff*/
if ( (unsigned __int16)n0x10_4 <= 0x10u ) /*0xffc16707*/
{
LABEL_45:
do /*0xffc16721*/
{
n0x10_5 = (unsigned __int16)n0x10_4; /*0xffc1670c*/
v19 = 1 << (16 - n0x10_4++); /*0xffc16715*/
buf[n0x10_5] = v19; /*0xffc16719*/
}
while ( (unsigned __int16)n0x10_4 <= 0x10u ); /*0xffc16721*/
n0x10_2 = n0x10; /*0xffc16723*/
}
v20 = *((_WORD *)v49 + n0x10_2 + 1) >> v14; /*0xffc16735*/
v21 = v20; /*0xffc16738*/
if ( v20 ) /*0xffc1673e*/
{
v22 = (unsigned __int16)(1 << n0x10_2); /*0xffc16747*/
if ( (unsigned __int16)v21 < (unsigned __int16)v22 ) /*0xffc1674d*/
{
v23 = 2 * (v22 - v21); /*0xffc16753*/
if ( v23 ) /*0xffc16755*/
DxeIplSetMem16((_WORD *)(a5 + 2 * v21), v23 >> 1, 0); /*0xffc16767*/
}
}
n0x3FB_1 = n0x3FB; /*0xffc16774*/
n0x3FB_4 = 0; /*0xffc16787*/
v42 = 1 << (15 - n0x10_2); /*0xffc1678c*/
v45 = 1 << n0x10_2; /*0xffc16793*/
n0x3FB_5 = 0; /*0xffc16799*/
if ( n0x3FB ) /*0xffc167a2*/
{
v25 = a5; /*0xffc167a8*/
v26 = a3; /*0xffc167b1*/
do /*0xffc168e2*/
{
n0x10_6 = *(unsigned __int8 *)((unsigned __int16)n0x3FB_4 + v26); /*0xffc167bf*/
if ( *(_BYTE *)((unsigned __int16)n0x3FB_4 + v26) && n0x10_6 < 0x11 ) /*0xffc167cf*/
{
v47 = 2 * n0x10_6; /*0xffc167d9*/
v28 = *((unsigned __int16 *)v49 + n0x10_6); /*0xffc167dd*/
v29 = v28 + buf[n0x10_6]; /*0xffc167ea*/
v46 = v29; /*0xffc167ed*/
if ( (unsigned __int16)n0x10_6 <= n0x10_2 ) /*0xffc167f4*/
{
while ( (unsigned __int16)v28 < v29 ) /*0xffc16893*/
{
if ( (unsigned __int16)v28 >= v45 ) /*0xffc16886*/
return 0xFFFF; /*0xffc168f2*/
v39 = (unsigned __int16)v28; /*0xffc16888*/
LOWORD(v28) = v28 + 1; /*0xffc1688b*/
*(_WORD *)(v25 + 2 * v39) = n0x3FB_4; /*0xffc1688c*/
}
}
else
{
v30 = *((_WORD *)v49 + n0x10_6); /*0xffc167fa*/
v31 = n0x10_6 - n0x10_2; /*0xffc167fc*/
v32 = v31; /*0xffc1680d*/
v33 = (_WORD *)(a5 + 2 * (v28 >> (16 - n0x10))); /*0xffc16810*/
if ( v31 ) /*0xffc16816*/
{
n0x3FB_2 = n0x3FB_1; /*0xffc1681c*/
v35 = v42; /*0xffc16820*/
do /*0xffc168a5*/
{
if ( !*v33 && (unsigned __int16)n0x3FB_2 < 0x3FBu ) /*0xffc16833*/
{
*(_WORD *)(this + 2 * (unsigned __int16)n0x3FB_2 + 42) = 0; /*0xffc1683e*/
*(_WORD *)(this + 2 * (unsigned __int16)n0x3FB_2 + 2080) = 0; /*0xffc16843*/
v35 = v42; /*0xffc1684b*/
*v33 = n0x3FB_2++; /*0xffc1684f*/
}
n0x3FB_3 = (unsigned __int16)*v33; /*0xffc16853*/
if ( (unsigned __int16)n0x3FB_3 < 0x3FBu ) /*0xffc1685e*/
{
v37 = this + 2 * n0x3FB_3; /*0xffc1686d*/
if ( (v30 & v35) != 0 ) /*0xffc16870*/
v33 = (_WORD *)(v37 + 2080); /*0xffc16872*/
else
v33 = (_WORD *)(v37 + 42); /*0xffc16897*/
}
v32 += 0xFFFF; /*0xffc1689a*/
v30 *= 2; /*0xffc168a0*/
}
while ( (_WORD)v32 ); /*0xffc168a5*/
n0x3FB_4 = n0x3FB_5; /*0xffc168ab*/
n0x3FB_1 = n0x3FB_2; /*0xffc168af*/
n0x10_2 = n0x10; /*0xffc168b3*/
}
v29 = v46; /*0xffc168ba*/
v25 = a5; /*0xffc168be*/
*v33 = n0x3FB_4; /*0xffc168c5*/
}
v26 = a3; /*0xffc168cc*/
*(_WORD *)((char *)v49 + v47) = v29; /*0xffc168d3*/
}
n0x3FB_5 = ++n0x3FB_4; /*0xffc168d9*/
}
while ( (unsigned __int16)n0x3FB_4 < n0x3FB ); /*0xffc168e2*/
}
return 0; /*0xffc168eb*/
}