int __cdecl sub_401000(LPCSTR lpFileName, int a2, int a3)
{
unsigned int v3; // ebx@1
void *v4; // edi@1
void *v5; // ebp@1
HANDLE v6; // eax@2
DWORD v7; // eax@3
DWORD v8; // esi@3
HANDLE v9; // eax@3
int v10; // esi@5
unsigned int v11; // ebp@8
unsigned int i; // esi@8
unsigned int v13; // ecx@11
int v14; // ebp@16
int v15; // eax@25
char *v16; // ecx@25
int v18; // esi@32
unsigned int v19; // edi@40
unsigned int v20; // eax@41
int v21; // ecx@45
int v22; // eax@45
int v23; // eax@45
int v24; // eax@46
_DWORD *v25; // ecx@50
int v26; // edi@50
int v27; // esi@50
int v28; // eax@53
int v29; // ebp@53
char *v30; // eax@55
int v31; // ecx@55
int v32; // ecx@62
unsigned int v33; // esi@62
unsigned int v34; // eax@63
int v35; // [sp+10h] [bp-60h]@6
signed int v36; // [sp+10h] [bp-60h]@39
signed int v37; // [sp+10h] [bp-60h]@62
unsigned int v38; // [sp+14h] [bp-5Ch]@25
int v39; // [sp+14h] [bp-5Ch]@50
unsigned int v40; // [sp+14h] [bp-5Ch]@55
int v41; // [sp+18h] [bp-58h]@8
int v42; // [sp+18h] [bp-58h]@39
int v43; // [sp+18h] [bp-58h]@62
int v44; // [sp+1Ch] [bp-54h]@1
LPCVOID lpBaseAddress; // [sp+20h] [bp-50h]@1
int v46; // [sp+24h] [bp-4Ch]@16
int v47; // [sp+24h] [bp-4Ch]@32
int v48; // [sp+28h] [bp-48h]@32
int v49; // [sp+2Ch] [bp-44h]@7
unsigned int v50; // [sp+30h] [bp-40h]@1
int v51; // [sp+30h] [bp-40h]@32
int v52; // [sp+30h] [bp-40h]@45
int v53; // [sp+38h] [bp-38h]@46
unsigned int v54; // [sp+3Ch] [bp-34h]@1
unsigned int v55; // [sp+40h] [bp-30h]@39
unsigned int v56; // [sp+44h] [bp-2Ch]@8
unsigned __int16 v57; // [sp+4Ch] [bp-24h]@1
int v58; // [sp+54h] [bp-1Ch]@32
int v59; // [sp+58h] [bp-18h]@1
int v60; // [sp+5Ch] [bp-14h]@1
int v61; // [sp+5Ch] [bp-14h]@46
int v62; // [sp+60h] [bp-10h]@5
int v63; // [sp+64h] [bp-Ch]@1
HANDLE hObject; // [sp+68h] [bp-8h]@3
HANDLE v65; // [sp+6Ch] [bp-4h]@2
v3 = 0;
v4 = 0;
v5 = 0;
lpBaseAddress = 0;
v50 = 0;
v44 = 0;
v54 = 0;
v59 = 0;
v63 = 0;
v60 = 0;
v57 = 0;
if ( !SetFileAttributesA(lpFileName, 0x80u) )
goto LABEL_72;
v6 = CreateFileA(lpFileName, 0xC0000000, 3u, 0, 3u, 0x80u, 0);
v4 = v6;
v65 = v6;
if ( v6 == (HANDLE)-1 )
return 0;
v7 = GetFileSize(v6, 0);
v8 = v7;
v9 = CreateFileMappingA(v4, 0, 4u, 0, v7, 0);
v5 = v9;
hObject = v9;
if ( !v9 )
return 0;
lpBaseAddress = MapViewOfFile(v9, 2u, 0, 0, 0);
if ( !lpBaseAddress )
return 0;
v10 = v8 - 4;
v62 = v10;
if ( *(_WORD *)lpBaseAddress != 23117
|| (v35 = *((_DWORD *)lpBaseAddress + 15), *((_DWORD *)lpBaseAddress + 15) > v10)
|| (v49 = (int)lpBaseAddress + v35, *(_DWORD *)((char *)lpBaseAddress + v35) != 17744) )
{
LABEL_72:
UnmapViewOfFile(lpBaseAddress);
CloseHandle(v5);
LABEL_68:
CloseHandle(v4);
return 0;
}
v11 = *(_WORD *)((char *)lpBaseAddress + v35 + 6);
v56 = v11;
v41 = v49 + 248;
for ( i = 0; i < v11; ++i )
{
if ( !i )
v63 = *(_DWORD *)(v41 + 20);
*(_DWORD *)(v41 + 36) = -1040187328;
v13 = *(_DWORD *)(v49 + 128);
if ( *(_DWORD *)(v41 + 12) <= v13 )
{
if ( v50 )
{
++v50;
}
else
{
v11 = v56;
v60 = v13 + *(_DWORD *)(v41 + 20) - *(_DWORD *)(v41 + 12);
v44 = v13 + *(_DWORD *)(v41 + 20) - *(_DWORD *)(v41 + 12);
}
}
v54 = *(_DWORD *)(v49 + 128);
v41 += 40;
}
v46 = (int)lpBaseAddress + v44;
v14 = 0;
while ( *(_DWORD *)v46
|| *(_DWORD *)(v46 + 4)
|| *(_DWORD *)(v46 + 8)
|| *(_DWORD *)(v46 + 12)
|| *(_DWORD *)(v46 + 16) )
{
if ( v54 > *(_DWORD *)(v46 + 12) )
{
UnmapViewOfFile(lpBaseAddress);
CloseHandle(hObject);
goto LABEL_68;
}
v46 += 20;
++v14;
}
v15 = 0;
v38 = (unsigned int)lpBaseAddress + v44;
v16 = (char *)lpBaseAddress + v44;
while ( 1 )
{
if ( *(_DWORD *)v16 )
{
v15 = 0;
v50 = v38;
goto LABEL_30;
}
if ( v15 == 5 * v14 + 50 )
break;
++v15;
LABEL_30:
v38 += 4;
v16 = (char *)v38;
if ( v38 > (unsigned int)lpBaseAddress + v62 )
return 0;
}
v58 = v15;
v48 = v50 + 20;
v51 = v50 + 20;
v47 = (int)lpBaseAddress + v44;
v18 = 0;
while ( *(_DWORD *)v47
|| *(_DWORD *)(v47 + 4)
|| *(_DWORD *)(v47 + 8)
|| *(_DWORD *)(v47 + 12)
|| *(_DWORD *)(v47 + 16) )
{
*(_DWORD *)v48 = *(_DWORD *)v47;
*(_DWORD *)v48 = *(_DWORD *)v47;
*(_DWORD *)(v48 + 4) = *(_DWORD *)(v47 + 4);
*(_DWORD *)(v48 + 8) = *(_DWORD *)(v47 + 8);
*(_DWORD *)(v48 + 12) = *(_DWORD *)(v47 + 12);
*(_DWORD *)(v48 + 16) = *(_DWORD *)(v47 + 16);
++v18;
v47 += 20;
v48 += 20;
}
v55 = v51 - (_DWORD)lpBaseAddress;
v42 = (int)lpBaseAddress + v35;
v36 = 248;
if ( v56 > 0 )
{
v19 = v56;
do
{
v42 += v36;
v20 = *(_DWORD *)(v42 + 20);
if ( v20 + *(_DWORD *)(v42 + 16) > v55 && v55 > v20 )
v59 = v55 + *(_DWORD *)(v42 + 12) - v20;
--v19;
v36 = 40;
}
while ( v19 );
}
*(_DWORD *)(v49 + 128) = v59;
v21 = v59 + 20 * v18;
*(_DWORD *)v48 = v54 + 8;
*(_DWORD *)(v48 + 4) = 0;
*(_DWORD *)(v48 + 8) = 0;
*(_DWORD *)(v48 + 12) = v21 + 48;
*(_DWORD *)(v48 + 16) = v54;
v22 = v48 + 20;
*(_DWORD *)v22 = 0;
*(_DWORD *)(v22 + 4) = 0;
*(_DWORD *)(v22 + 8) = 0;
*(_DWORD *)(v22 + 12) = 0;
*(_DWORD *)(v22 + 16) = 0;
v52 = v59 + 20 * v18;
*(_DWORD *)((char *)lpBaseAddress + v60) = v21 + 60;
*(_DWORD *)((char *)lpBaseAddress + v60 + 4) = 0;
*(_DWORD *)((char *)lpBaseAddress + v60 + 8) = v21 + 60;
*(_DWORD *)((char *)lpBaseAddress + v60 + 12) = 0;
*(_DWORD *)(v48 + 40) = v21 + 60;
qmemcpy((void *)(v48 + 48), (const void *)a2, strlen((const char *)a2));
*(_WORD *)(v48 + 60) = 8224;
qmemcpy((void *)(v48 + 62), (const void *)a3, strlen((const char *)a3));
*(_DWORD *)(v48 + 80) = 60;
v23 = *(_DWORD *)(v49 + 208);
if ( v23 )
{
v61 = *(_DWORD *)(v49 + 208);
v53 = (int)lpBaseAddress + v23;
v24 = (int)lpBaseAddress + v23;
if ( *(_WORD *)(v24 + 4) )
{
do
{
*(_WORD *)(v24 + 4) += 8;
if ( *(_WORD *)(v24 + 4) )
v57 = *(_WORD *)(v24 + 4);
v53 += 8;
v24 = v53;
}
while ( *(_WORD *)(v53 + 4) );
}
*(_WORD *)(v24 + 4) = v57 + 40;
v39 = v53 + 8;
v25 = (_DWORD *)(v53 + 12);
v26 = 0;
v27 = 0;
while ( *(_DWORD *)v39 || *v25 )
{
v25 = (_DWORD *)(v39 + 4);
v28 = *(_DWORD *)v39;
v29 = *(_DWORD *)(v39 + 4);
*(_DWORD *)v39 = v27;
*(_DWORD *)(v39 + 4) = v26;
v27 = v28;
v26 = v29;
v39 += 8;
}
qmemcpy((char *)lpBaseAddress + v61 + v57 + 40, (const void *)a2, strlen((const char *)a2));
}
v40 = (unsigned int)lpBaseAddress + v63;
v30 = (char *)lpBaseAddress + v63;
v31 = v58;
while ( 1 )
{
if ( *(_DWORD *)v30 )
{
v31 = 0;
v52 = v40;
goto LABEL_60;
}
if ( v31 == 20 )
break;
++v31;
LABEL_60:
v40 += 4;
v30 = (char *)v40;
if ( v40 > (unsigned int)lpBaseAddress + v62 )
return 0;
}
v32 = v52 + 8;
*(_DWORD *)v32 = dword_40B040;
*(_WORD *)(v32 + 4) = word_40B044;
*(_DWORD *)(v52 + 14) = *(_DWORD *)(v49 + 52) + *(_DWORD *)(v49 + 40);
*(_DWORD *)(v52 + 18) = dword_40B048;
*(_DWORD *)(v52 + 22) = v54 + *(_DWORD *)(v49 + 52);
v43 = v49;
v33 = v52 + 8 - (_DWORD)lpBaseAddress;
v37 = 248;
do
{
v43 += v37;
v34 = *(_DWORD *)(v43 + 20);
if ( v34 + *(_DWORD *)(v43 + 16) > v33 && v33 > v34 )
break;
++v3;
v37 = 40;
}
while ( v3 <= v56 );
UnmapViewOfFile(lpBaseAddress);
CloseHandle(hObject);
CloseHandle(v65);
return 1;
}