[C++] 反编译器

各种开源的decompiler都不太好用,目前最好的反编译器是IDA pro。

虽然是收费的,不过破解版很好找。

我试过5.5版本的,还不错。


我把windows notepad进行了反编译,多少算有点可读性:

/* This file has been generated by the Hex-Rays decompiler.
   Copyright (c) 2009 Hex-Rays <info@hex-rays.com>

   Detected compiler: Visual C++
*/

#include <windows.h>
#include <defs.h>

#include <stdarg.h>


//-------------------------------------------------------------------------
// Data declarations

// extern void *acmdln; weak
extern const WCHAR szOtherStuff; // idb
extern wchar_t aW[3]; // weak
extern wchar_t aA[3]; // weak
extern const WCHAR TableName[]; // idb
extern const WCHAR aCommdlg_help[]; // idb
extern const WCHAR String[]; // idb
extern wchar_t a_setup[8]; // weak
extern wchar_t aP[3]; // weak
extern wchar_t aPt[4]; // weak
extern wchar_t aSC_txtCSC_C[]; // idb
extern wchar_t aSecuritySppGen[32]; // weak
extern int dword_1002B48[2]; // weak
extern const WCHAR aIpointsize[]; // idb
extern const WCHAR aLffacename[]; // idb
extern const WCHAR aLfpitchandfami[]; // idb
extern const WCHAR aLfquality[]; // idb
extern const WCHAR aLfclipprecisio[]; // idb
extern const WCHAR aLfoutprecision[]; // idb
extern const WCHAR aLfcharset[]; // idb
extern const WCHAR aLfstrikeout[]; // idb
extern const WCHAR aLfunderline[]; // idb
extern const WCHAR aLfitalic[]; // idb
extern const WCHAR aLfweight[]; // idb
extern const WCHAR aLforientation[]; // idb
extern const WCHAR ValueName[]; // idb
extern const WCHAR SubKey[]; // idb
extern const WCHAR aIwindowposdy[]; // idb
extern const WCHAR aIwindowposdx[]; // idb
extern const WCHAR aIwindowposy[]; // idb
extern const WCHAR aIwindowposx[]; // idb
extern const WCHAR aImarginright[]; // idb
extern const WCHAR aImarginleft[]; // idb
extern const WCHAR aImarginbottom[]; // idb
extern const WCHAR aImargintop[]; // idb
extern const WCHAR aSztrailer[]; // idb
extern const WCHAR aSzheader[]; // idb
extern const WCHAR aStatusbar[]; // idb
extern const WCHAR aFwrap[]; // idb
extern const WCHAR aEdit[]; // idb
extern const WCHAR aFmle_is_broken[]; // idb
extern const WCHAR aFsavewindowpos[]; // idb
extern const WCHAR aSoftwareMicr_0[]; // idb
extern wchar_t aLucidaConsole[15]; // weak
extern const WCHAR ClassName[]; // idb
extern int dword_1003AF0[2]; // weak
extern wchar_t aTxt[4]; // weak
extern int dword_1003C74[5]; // weak
extern wchar_t a_[4]; // weak
extern const WCHAR pszPath[]; // idb
extern IID riid; // idb
extern IID rclsid; // idb
extern IID stru_100400C; // idb
extern IID stru_100401C; // idb
extern IID stru_10043D0; // idb
extern IID stru_10043E0; // idb
extern wchar_t aNull[7]; // weak
extern OLECHAR psz[]; // idb
extern wchar_t aHelp_entry_id_[27]; // weak
extern int dword_1004748[4]; // weak
extern int dword_10049F4[4]; // weak
extern int dword_1004A04[2]; // weak
extern int dword_1004AF0[4]; // weak
extern const WCHAR aSlipupacc[]; // idb
extern wchar_t aStringfileinfo[]; // idb
extern const WCHAR SubBlock[]; // idb
extern wchar_t aSppsvc_exe[12]; // weak
extern wchar_t aSlui_exe[10]; // weak
extern wchar_t aSppuinotify_dl[17]; // weak
extern const WCHAR aSppsvc[]; // idb
extern const WCHAR ServiceName[]; // idb
extern int dword_1006D38[6]; // weak
extern wchar_t aD[]; // idb
extern wchar_t a_txt_0[5]; // weak
extern int dword_10098B8; // weak
extern wchar_t asc_10098BC[3]; // weak
extern int dword_1009EE0[2]; // weak
extern struct _EXCEPTION_POINTERS ExceptionInfo; // idb
extern __int16 word_100C000; // weak
extern BYTE Data; // idb
extern int dword_100C008; // weak
extern int dword_100C00C; // weak
extern int dword_100C010; // weak
extern int dword_100C014; // weak
extern int dword_100C018; // weak
extern int dword_100C01C; // weak
extern HWND hWnd; // idb
extern HWND dword_100C024; // idb
extern HWND dword_100C028; // idb
extern BYTE dword_100C02C; // idb
extern int dword_100C030; // weak
extern WPARAM wParam; // idb
extern int dword_100C038; // weak
extern int dword_100C03C; // weak
extern int dword_100C040; // weak
extern WPARAM dword_100C044; // idb
extern LPARAM lParam; // idb
extern int nHeight; // idb
extern int nWidth; // idb
extern int X; // idb
extern int Y; // idb
extern int dword_100C05C; // weak
extern int dword_100C060; // weak
extern int dword_100C064; // weak
extern int dword_100C070; // weak
extern HANDLE hFile; // idb
extern int dword_100C078; // weak
extern int dword_100C07C; // weak
extern HACCEL hAccTable; // idb
extern int dword_100C084; // weak
extern HGDIOBJ ho; // idb
extern HINSTANCE hInstance; // idb
extern HCURSOR hCursor; // idb
extern HCURSOR dword_100C094; // idb
extern HLOCAL hMem; // idb
extern int dword_100C0A4; // weak
extern struct tagFINDREPLACEW stru_100C0C0; // idb
extern WINDOWPLACEMENT wndpl; // idb
extern struct tagPSDW stru_100C140; // idb
extern struct tagOFNW stru_100C1A0; // idb
extern LOGFONTW lf; // idb
extern volatile LONG Destination; // idb
extern int (__stdcall *off_100C26C)(int, int, int); // weak
extern int (__stdcall *off_100C288)(int, int, int); // weak
extern LPCWSTR dword_100C2B0; // idb
extern LPCWSTR dword_100C2B4; // idb
extern LPCWSTR lpString2; // idb
extern LPCVOID lpSource; // idb
extern LPCWSTR dword_100C2C4; // idb
extern LPCWSTR lpText; // idb
extern LPCWSTR szApp; // idb
extern LPCWSTR dword_100C2DC; // idb
extern int dword_100C2E0; // weak
extern LPCWSTR dword_100C2EC; // idb
extern int dword_100C2F0; // weak
extern LPCWSTR lpszHelp; // idb
extern int dword_100C2F8; // weak
extern int dword_100C2FC; // weak
extern int dword_100C300; // weak
extern char Args[]; // idb
extern int dword_100C308; // weak
extern int dword_100C30C; // weak
extern int dword_100C310; // weak
extern LPCWSTR dword_100C314; // idb
extern LPCWSTR dword_100C318; // idb
extern LPCWSTR dword_100C31C; // idb
extern LPCWSTR dword_100C320; // idb
extern LPCWSTR dword_100C324; // idb
extern wchar_t *dword_100C328; // idb
extern LPCWSTR lpCaption; // idb
extern LPCWSTR dword_100C330; // idb
extern LPARAM dword_100C334; // idb
extern LPARAM dword_100C338; // idb
extern LPARAM dword_100C33C; // idb
extern LPARAM dword_100C340; // idb
extern wchar_t *dword_100C344; // idb
extern wchar_t *Format; // idb
extern int dword_100C368; // weak
extern int dword_100C370; // weak
extern int dword_100C374; // weak
extern int dword_100C37C; // weak
extern int dword_100C3C0; // weak
extern __int16 word_100C44C; // weak
extern __int16 word_100C450; // weak
extern __int16 word_100C454; // weak
extern __int16 word_100C458; // weak
extern int dword_100C45C; // weak
extern int dword_100C460; // weak
extern int dword_100C464; // weak
extern int dword_100C468; // weak
extern int dword_100C46C; // weak
extern int dword_100C470; // weak
extern int dword_100C474; // weak
extern int dword_100C478; // weak
extern __int16 word_100C47C; // weak
extern int dword_100C480; // weak
extern int dword_100C484; // weak
extern __int16 word_100C488; // weak
extern WCHAR word_100C6A0; // idb
extern _UNKNOWN unk_100C6F0; // weak
extern const WCHAR word_100C740; // idb
extern BYTE Dst; // idb
extern wchar_t word_100C7E0; // idb
extern wchar_t Dest; // idb
extern int off_100C920[2]; // weak
extern _UNKNOWN unk_100C9DC; // weak
extern const WCHAR word_100C9E0; // idb
extern const WCHAR FileName; // idb
extern HWND dword_100CCE8; // idb
extern int dword_100CCEC; // weak
extern int dword_100CCF0; // weak
extern int dword_100CCF4; // weak
extern int (__thiscall *dword_100CD0C)(_DWORD); // weak
extern int dword_100CD10; // weak
extern int *off_100CD14; // weak
extern _UNKNOWN unk_100CD50; // weak
extern _UNKNOWN unk_100CD54; // weak
extern _UNKNOWN unk_100CD58; // weak
extern const WCHAR word_100CD60; // idb
extern const WCHAR word_100CF68; // idb
extern const WCHAR String2; // idb
extern const WCHAR word_100D378; // idb
extern int dword_100D580; // weak
extern const WCHAR word_100D588; // idb
extern LPARAM dword_100D790; // idb
extern WPARAM dword_100D794; // idb
extern int dword_100D798; // weak
extern int dword_100D79C; // weak
extern HMENU dword_100D7A0; // idb
extern volatile LONG Target; // idb
extern int dword_100D7A8; // weak
extern char dword_100D7AC[]; // idb
extern int dword_100D7B0; // weak
extern int x; // idb
extern int dword_100D7B8; // weak
extern int dword_100D7BC; // weak
extern int dword_100D7C0; // weak
extern int dword_100D7C4; // weak
extern int y; // idb
extern int dword_100D7CC; // idb
extern int dword_100D7D0; // weak
extern int dword_100D7D4; // weak
extern int dword_100D7D8; // weak
extern struct _SYSTEMTIME SystemTime; // idb
extern const WCHAR word_100D800; // idb
extern const WCHAR word_100DA08; // idb
extern const WCHAR word_100DC10; // idb
extern struct tagPOINT pt; // idb
extern int dword_100DE28; // weak
extern int dword_100DE2C; // weak
extern int dword_100DE30; // weak
extern int dword_100DE34; // weak
extern HWND hDlg; // idb
extern int dword_100DE3C; // weak
extern WCHAR pPrinterName; // idb
extern int dword_100E040; // weak
extern HMENU hMenu; // idb
extern _UNKNOWN unk_100E060; // weak
extern int dword_100E160; // weak

//-------------------------------------------------------------------------
// Function declarations

#define __thiscall __cdecl // Test compile in C mode

// LSTATUS __stdcall RegSetValueExW(HKEY hKey, LPCWSTR lpValueName, DWORD Reserved, DWORD dwType, const BYTE *lpData, DWORD cbData);
// LSTATUS __stdcall RegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData);
// LSTATUS __stdcall RegCloseKey(HKEY hKey);
// LSTATUS __stdcall RegCreateKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult);
// LSTATUS __stdcall RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult);
// BOOL __stdcall IsTextUnicode(const void *lpv, int iSize, LPINT lpiResult);
// BOOL __stdcall CloseServiceHandle(SC_HANDLE hSCObject);
// BOOL __stdcall QueryServiceConfigW(SC_HANDLE hService, LPQUERY_SERVICE_CONFIGW lpServiceConfig, DWORD cbBufSize, LPDWORD pcbBytesNeeded);
// SC_HANDLE __stdcall OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess);
// SC_HANDLE __stdcall OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess);
// int __stdcall FindNLSString(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD); weak
// HGLOBAL __stdcall GlobalAlloc(UINT uFlags, SIZE_T dwBytes);
// BOOL __stdcall GlobalUnlock(HGLOBAL hMem);
// LPVOID __stdcall GlobalLock(HGLOBAL hMem);
// int __stdcall GetTimeFormatW(LCID Locale, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpTimeStr, int cchTime);
// int __stdcall GetDateFormatW(LCID Locale, DWORD dwFlags, const SYSTEMTIME *lpDate, LPCWSTR lpFormat, LPWSTR lpDateStr, int cchDate);
// void __stdcall GetLocalTime(LPSYSTEMTIME lpSystemTime);
// LANGID __stdcall GetUserDefaultUILanguage();
// BOOL __stdcall HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem);
// LPVOID __stdcall HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes);
// HANDLE __stdcall GetProcessHeap();
// BOOL __stdcall GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation);
// LONG __stdcall InterlockedExchange(volatile LONG *Target, LONG Value);
// void __stdcall FreeLibraryAndExitThread(HMODULE hLibModule, DWORD dwExitCode);
// DWORD __stdcall GetFileAttributesW(LPCWSTR lpFileName);
// BOOL __stdcall Wow64RevertWow64FsRedirection(PVOID OlValue);
// BOOL __stdcall Wow64DisableWow64FsRedirection(PVOID *OldValue);
// BOOL __stdcall IsWow64Process(HANDLE hProcess, PBOOL Wow64Process);
// HANDLE __stdcall GetCurrentProcess();
// HANDLE __stdcall CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId);
// HMODULE __stdcall LoadLibraryW(LPCWSTR lpLibFileName);
// DWORD __stdcall GetModuleFileNameW(HMODULE hModule, LPWCH lpFilename, DWORD nSize);
// HANDLE __stdcall CreateFileMappingW(HANDLE hFile, LPSECURITY_ATTRIBUTES lpFileMappingAttributes, DWORD flProtect, DWORD dwMaximumSizeHigh, DWORD dwMaximumSizeLow, LPCWSTR lpName);
// DWORD __stdcall FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments);
// LPVOID __stdcall MapViewOfFile(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow, SIZE_T dwNumberOfBytesToMap);
// BOOL __stdcall UnmapViewOfFile(LPCVOID lpBaseAddress);
// HLOCAL __stdcall LocalReAlloc(HLOCAL hMem, SIZE_T uBytes, UINT uFlags);
// UINT __stdcall GetACP();
// BOOL __stdcall DeleteFileW(LPCWSTR lpFileName);
// BOOL __stdcall SetEndOfFile(HANDLE hFile);
// int __stdcall WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar);
// void __stdcall SetLastError(DWORD dwErrCode);
// BOOL __stdcall WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped);
// DWORD __stdcall GetLastError();
// SIZE_T __stdcall LocalSize(HLOCAL hMem);
// DWORD __stdcall GetFullPathNameW(LPCWSTR lpFileName, DWORD nBufferLength, LPWSTR lpBuffer, LPWSTR *lpFilePart);
// int __stdcall MulDiv(int nNumber, int nNumerator, int nDenominator);
// LPWSTR __stdcall GetCommandLineW();
// DWORD __stdcall GetCurrentProcessId();
// int __stdcall FoldStringW(DWORD dwMapFlags, LPCWSTR lpSrcStr, int cchSrc, LPWSTR lpDestStr, int cchDest);
// int __stdcall lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2);
// HANDLE __stdcall FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData);
// BOOL __stdcall FindClose(HANDLE hFindFile);
// BOOL __stdcall HeapSetInformation(HANDLE HeapHandle, HEAP_INFORMATION_CLASS HeapInformationClass, PVOID HeapInformation, SIZE_T HeapInformationLength);
// BOOL __stdcall TerminateProcess(HANDLE hProcess, UINT uExitCode);
// void __stdcall GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime);
// DWORD __stdcall GetCurrentThreadId();
// DWORD __stdcall GetTickCount();
// BOOL __stdcall QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount);
// HMODULE __stdcall GetModuleHandleA(LPCSTR lpModuleName);
// LPTOP_LEVEL_EXCEPTION_FILTER __stdcall SetUnhandledExceptionFilter(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter);
// void __stdcall GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo);
// LONG __stdcall InterlockedCompareExchange(volatile LONG *Destination, LONG Exchange, LONG Comperand);
// void __stdcall Sleep(DWORD dwMilliseconds);
// LPVOID __stdcall LocalLock(HLOCAL hMem);
// BOOL __stdcall LocalUnlock(HLOCAL hMem);
// int __stdcall lstrlenW(LPCWSTR lpString);
// int __stdcall GetLocaleInfoW(LCID Locale, LCTYPE LCType, LPWSTR lpLCData, int cchData);
// HGLOBAL __stdcall GlobalFree(HGLOBAL hMem);
// int __stdcall lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2);
// UINT __stdcall SetErrorMode(UINT uMode);
// HANDLE __stdcall CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
// BOOL __stdcall ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped);
// BOOL __stdcall CloseHandle(HANDLE hObject);
// HLOCAL __stdcall LocalAlloc(UINT uFlags, SIZE_T uBytes);
// LONG __stdcall InterlockedDecrement(volatile LONG *lpAddend);
// HLOCAL __stdcall LocalFree(HLOCAL hMem);
// LONG __stdcall InterlockedIncrement(volatile LONG *lpAddend);
// BOOL __stdcall GetVersionExW(LPOSVERSIONINFOW lpVersionInformation);
// LONG __stdcall UnhandledExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo);
// HFONT __stdcall CreateFontIndirectW(const LOGFONTW *lplf);
// int __stdcall SetMapMode(HDC hdc, int iMode);
// BOOL __stdcall SetViewportExtEx(HDC hdc, int x, int y, LPSIZE lpsz);
// BOOL __stdcall SetWindowExtEx(HDC hdc, int x, int y, LPSIZE lpsz);
// BOOL __stdcall LPtoDP(HDC hdc, LPPOINT lppt, int c);
// int __stdcall SetBkMode(HDC hdc, int mode);
// BOOL __stdcall GetTextMetricsW(HDC hdc, LPTEXTMETRICW lptm);
// int __stdcall SetAbortProc(HDC hdc, ABORTPROC proc);
// int __stdcall StartDocW(HDC hdc, const DOCINFOW *lpdi);
// int __stdcall StartPage(HDC hdc);
// int __stdcall EndPage(HDC hdc);
// int __stdcall AbortDoc(HDC hdc);
// int __stdcall EndDoc(HDC hdc);
// BOOL __stdcall DeleteDC(HDC hdc);
// BOOL __stdcall TextOutW(HDC hdc, int x, int y, LPCWSTR lpString, int c);
// BOOL __stdcall GetTextExtentPoint32W(HDC hdc, LPCWSTR lpString, int c, LPSIZE psizl);
// HDC __stdcall CreateDCW(LPCWSTR pwszDriver, LPCWSTR pwszDevice, LPCWSTR pszPort, const DEVMODEW *pdm);
// HGDIOBJ __stdcall SelectObject(HDC hdc, HGDIOBJ h);
// int __stdcall GetTextFaceW(HDC hdc, int c, LPWSTR lpName);
// int __stdcall EnumFontsW(HDC hdc, LPCWSTR lpLogfont, FONTENUMPROCW lpProc, LPARAM lParam);
// int __stdcall GetDeviceCaps(HDC hdc, int index);
// BOOL __stdcall DeleteObject(HGDIOBJ ho);
// HWND __stdcall SetActiveWindow(HWND hWnd);
// HKL __stdcall GetKeyboardLayout(DWORD idThread);
// void __stdcall PostQuitMessage(int nExitCode);
// LRESULT __stdcall DefWindowProcW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
// HWND __stdcall GetForegroundWindow();
// BOOL __stdcall IsIconic(HWND hWnd);
// BOOL __stdcall DestroyWindow(HWND hWnd);
// BOOL __stdcall MessageBeep(UINT uType);
// BOOL __stdcall GetWindowPlacement(HWND hWnd, WINDOWPLACEMENT *lpwndpl);
// LPWSTR __stdcall CharUpperW(LPWSTR lpsz);
// ATOM __stdcall RegisterClassExW(const WNDCLASSEXW *);
// HANDLE __stdcall LoadImageW(HINSTANCE hInst, LPCWSTR name, UINT type, int cx, int cy, UINT fuLoad);
// HCURSOR __stdcall LoadCursorW(HINSTANCE hInstance, LPCWSTR lpCursorName);
// LONG __stdcall SetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong);
// HACCEL __stdcall LoadAcceleratorsW(HINSTANCE hInstance, LPCWSTR lpTableName);
// HMENU __stdcall GetSystemMenu(HWND hWnd, BOOL bRevert);
// BOOL __stdcall SetWindowPlacement(HWND hWnd, const WINDOWPLACEMENT *lpwndpl);
// HWND __stdcall CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
// UINT __stdcall RegisterWindowMessageW(LPCWSTR lpString);
// BOOL __stdcall UpdateWindow(HWND hWnd);
// BOOL __stdcall InvalidateRect(HWND hWnd, const RECT *lpRect, BOOL bErase);
// int __stdcall SetScrollPos(HWND hWnd, int nBar, int nPos, BOOL bRedraw);
// int __stdcall GetWindowTextLengthW(HWND hWnd);
// LONG __stdcall GetWindowLongW(HWND hWnd, int nIndex);
// BOOL __stdcall PeekMessageW(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg);
// BOOL __stdcall EnableWindow(HWND hWnd, BOOL bEnable);
// INT_PTR __stdcall DialogBoxParamW(HINSTANCE hInstance, LPCWSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam);
// HWND __stdcall CreateDialogParamW(HINSTANCE hInstance, LPCWSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam);
// int __stdcall GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount);
// BOOL __stdcall SetWindowPos(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags);
// HCURSOR __stdcall SetCursor(HCURSOR hCursor);
// BOOL __stdcall SetForegroundWindow(HWND hWnd);
// HWND __stdcall FindWindowW(LPCWSTR lpClassName, LPCWSTR lpWindowName);
// int __stdcall GetSystemMetrics(int nIndex);
// BOOL __stdcall MoveWindow(HWND hWnd, int X, int Y, int nWidth, int nHeight, BOOL bRepaint);
// LRESULT __stdcall SendMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
// LPWSTR __stdcall CharNextW(LPCWSTR lpsz);
// DWORD __stdcall CheckMenuItem(HMENU hMenu, UINT uIDCheckItem, UINT uCheck);
// BOOL __stdcall CloseClipboard();
// BOOL __stdcall IsClipboardFormatAvailable(UINT format);
// BOOL __stdcall OpenClipboard(HWND hWndNewOwner);
// UINT __stdcall GetMenuState(HMENU hMenu, UINT uId, UINT uFlags);
// BOOL __stdcall EnableMenuItem(HMENU hMenu, UINT uIDEnableItem, UINT uEnable);
// HMENU __stdcall GetSubMenu(HMENU hMenu, int nPos);
// BOOL __stdcall GetClientRect(HWND hWnd, LPRECT lpRect);
// BOOL __stdcall UnhookWinEvent(HWINEVENTHOOK hWinEventHook);
// HMENU __stdcall GetMenu(HWND hWnd);
// int __stdcall MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);
// BOOL __stdcall WinHelpW(HWND hWndMain, LPCWSTR lpszHelp, UINT uCommand, ULONG_PTR dwData);
// int __stdcall GetDlgCtrlID(HWND hWnd);
// HWND __stdcall ChildWindowFromPoint(HWND hWndParent, POINT Point);
// HDC __stdcall GetDC(HWND hWnd);
// BOOL __stdcall ShowWindow(HWND hWnd, int nCmdShow);
// int __stdcall DrawTextExW(HDC hdc, LPWSTR lpchText, int cchText, LPRECT lprc, UINT format, LPDRAWTEXTPARAMS lpdtp);
// int __stdcall ReleaseDC(HWND hWnd, HDC hDC);
// HICON __stdcall LoadIconW(HINSTANCE hInstance, LPCWSTR lpIconName);
// HWINEVENTHOOK __stdcall SetWinEventHook(DWORD eventMin, DWORD eventMax, HMODULE hmodWinEventProc, WINEVENTPROC pfnWinEventProc, DWORD idProcess, DWORD idThread, DWORD dwFlags);
// BOOL __stdcall GetMessageW(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax);
// BOOL __stdcall PostMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
// BOOL __stdcall IsDialogMessageW(HWND hDlg, LPMSG lpMsg);
// int __stdcall TranslateAcceleratorW(HWND hWnd, HACCEL hAccTable, LPMSG lpMsg);
// BOOL __stdcall EndDialog(HWND hDlg, INT_PTR nResult);
// UINT __stdcall GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int cchMax);
// BOOL __stdcall SetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPCWSTR lpString);
// HWND __stdcall SetFocus(HWND hWnd);
// BOOL __stdcall SetWindowTextW(HWND hWnd, LPCWSTR lpString);
// HWND __stdcall GetParent(HWND hWnd);
// int __stdcall LoadStringW(HINSTANCE hInstance, UINT uID, LPWSTR lpBuffer, int cchBufferMax);
// LRESULT __stdcall SendDlgItemMessageW(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam);
// BOOL __stdcall GetCursorPos(LPPOINT lpPoint);
// BOOL __stdcall ScreenToClient(HWND hWnd, LPPOINT lpPoint);
// BOOL __stdcall TranslateMessage(const MSG *lpMsg);
// HWND __stdcall GetAncestor(HWND hwnd, UINT gaFlags);
// LRESULT __stdcall DispatchMessageW(const MSG *lpMsg);
// unsigned int __cdecl controlfp(unsigned int NewValue, unsigned int Mask);
// int __cdecl vsnwprintf(wchar_t *Dest, size_t Count, const wchar_t *Format, va_list Args);
// __int32 __cdecl wtol(const wchar_t *Str);
// int __cdecl iswctype(wint_t C, wctype_t Type);
// int __cdecl wcsncmp(const wchar_t *Str1, const wchar_t *Str2, size_t MaxCount);
// wchar_t *__cdecl wcsrchr(const wchar_t *Str, wchar_t Ch);
// void __cdecl exit(int Code);
// int __cdecl ismbblead(_DWORD); weak
// int cexit(void); weak
// void __cdecl exit(int Code);
// void __cdecl terminate(); weak
// HWND __stdcall ReplaceTextW(LPFINDREPLACEW);
// BOOL __stdcall PageSetupDlgW(LPPAGESETUPDLGW);
// HRESULT __stdcall PrintDlgExW(LPPRINTDLGEXW);
// HWND __stdcall FindTextW(LPFINDREPLACEW);
// BOOL __stdcall ChooseFontW(LPCHOOSEFONTW);
// BOOL __stdcall GetSaveFileNameW(LPOPENFILENAMEW);
// DWORD __stdcall CommDlgExtendedError();
// BOOL __stdcall GetOpenFileNameW(LPOPENFILENAMEW);
// __int16 __stdcall GetFileTitleW(LPCWSTR, LPWSTR Buf, WORD cchSize);
// void __stdcall DragAcceptFiles(HWND hWnd, BOOL fAccept);
// void __stdcall SHAddToRecentDocs(UINT uFlags, LPCVOID pv);
// HRESULT __stdcall SHGetFolderPathW(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath);
// int __stdcall SHCreateItemFromParsingName(_DWORD, _DWORD, _DWORD, _DWORD); weak
// BOOL __stdcall ShellExecuteExW(LPSHELLEXECUTEINFOW lpExecInfo);
// UINT __stdcall DragQueryFileW(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch);
// void __stdcall DragFinish(HDROP hDrop);
// HRESULT __stdcall CoInitializeEx(LPVOID pvReserved, DWORD dwCoInit);
// void __stdcall CoUninitialize();
// LPVOID __stdcall CoTaskMemAlloc(SIZE_T cb);
// HRESULT __stdcall CoCreateInstance(const IID *const rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, const IID *const riid, LPVOID *ppv);
// void __stdcall CoTaskMemFree(LPVOID pv);
// HRESULT __stdcall CoInitialize(LPVOID pvReserved);
// BOOL __stdcall PathIsFileSpecW(LPCWSTR pszPath);
// int __stdcall SHStrDupW(_DWORD, _DWORD); weak
// HPROPSHEETPAGE __stdcall CreatePropertySheetPageW(LPCPROPSHEETPAGEW constPropSheetPagePointer);
// INT_PTR __stdcall PropertySheetW(LPCPROPSHEETHEADERW);
// HWND __stdcall CreateStatusWindowW(LONG style, LPCWSTR lpszText, HWND hwndParent, UINT wID);
// int __stdcall COMCTL32_345(_DWORD, _DWORD, _DWORD, _DWORD); weak
// void __stdcall SysFreeString(BSTR bstrString);
// BSTR __stdcall SysAllocString(const OLECHAR *psz);
// int __stdcall RtlInitUnicodeString(_DWORD, _DWORD); weak
// int __stdcall NtQueryLicenseValue(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD); weak
WPARAM __cdecl sub_1001405(HINSTANCE hInstance);
// signed int __userpurge sub_10014DE<eax>(void *a1<ecx>, int a2<ebx>, HWND hWnd, signed int Msg, WPARAM hDrop, unsigned int lParam);
void __thiscall sub_1001564(void *this);
// void *__cdecl memset(void *Dst, int Val, size_t Size);
signed int sub_10015C3(wchar_t *Dest, unsigned int a2, const wchar_t *Format, ...);
// void __userpurge sub_1001620(int a1<ebp>, void (__stdcall *a2)(_DWORD, _DWORD, _DWORD, _DWORD)<esi>, int a3);
signed int __stdcall sub_1001664(int a1);
int __stdcall loc_100169F(int); // weak
LRESULT __stdcall sub_100170A(unsigned int a1);
int __stdcall loc_1001799(int); // weak
LRESULT __stdcall pfnWinEventProc(int a1, int a2, int a3, int a4, int a5, int a6, int a7);
// signed int __userpurge sub_1001809<eax>(void *a1<ecx>, int a2<ebx>, HWND a3, unsigned __int16 a4, int a5);
__int32 __cdecl sub_1001963();
HGLOBAL __cdecl sub_1001A1C();
// void __userpurge sub_1001A4D(const WCHAR *a1<ebx>, int a2<ebp>, int (__stdcall *a3)(_DWORD, _DWORD, _DWORD, _DWORD)<esi>, int a4);
// int __usercall sub_1001A72<eax>(int a1<ebp>);
DWORD __stdcall sub_1001AA5(HWND hWndNewOwner);
int __stdcall loc_1001C23(HWND hWndNewOwner); // weak
int __stdcall loc_1001C66(HWND hWndNewOwner); // weak
int __stdcall sub_1001E66(HINSTANCE hInstance, int, int nCmdShow); // idb
// _DWORD __usercall sub_10023D0<eax>(_DWORD ebp0<ebp>); weak
int __stdcall sub_1002409(int nWidth, int); // idb
// void *__cdecl memcpy(void *Dst, const void *Src, size_t Size);
int __stdcall sub_1002456(LPCWSTR lpString1); // idb
signed int __stdcall sub_1002558(int a1, unsigned int a2, int a3);
int __stdcall sub_10025CB(int a1);
signed int __stdcall sub_10025EF(WCHAR **a1);
int __stdcall sub_1002631(WCHAR **a1, int nCmdShow);
int __stdcall loc_100266D(int, int nCmdShow); // weak
// signed int __userpurge sub_1002689<eax>(unsigned __int16 *a1<eax>, WCHAR **a2);
signed int __stdcall sub_10026D5(wchar_t *Dest, unsigned int a2);
int __thiscall sub_1002733(int this);
int loc_10027A2(); // weak
// int __usercall sub_10027F0<eax>(unsigned int a1<eax>, int a2<ecx>);
// int __userpurge sub_1002820<eax>(int a1<ebp>, int a2, int a3);
int __stdcall loc_1002B3F(int, int); // weak
char *__cdecl sub_1002B64(int a1, int a2);
LPCWSTR __stdcall sub_1002C0D(LPWSTR lpBuffer, LPCWSTR lpFileName, DWORD nBufferLength);
LONG __thiscall sub_1002F8B(void *this);
// int __cdecl initterm(_DWORD, _DWORD); weak
int __cdecl sub_100304B();
DWORD __cdecl sub_1003053();
LSTATUS __cdecl sub_10030E2();
int __stdcall sub_100355B(HKEY hKey, LPCWSTR lpValueName, int); // idb
__int32 __stdcall sub_10035B0(HKEY Type, LPCWSTR lpValueName, const void *Src, void *Dst, DWORD cbData);
const WCHAR *__cdecl sub_100360C(LPCWSTR lpsz);
int __cdecl sub_1003660(unsigned int a1, unsigned int a2);
// int __usercall start<eax>(int a1<ebp>);
int dword_1003784(); // weak
int dword_100378C(); // weak
int dword_1003790(); // weak
int dword_100379C(); // weak
int dword_10037A0(); // weak
// ATOM __usercall sub_10037EF<ax>(HINSTANCE a1<esi>);
HLOCAL __stdcall sub_1003881(HINSTANCE hInstance);
int __stdcall sub_100392D(HINSTANCE hInstance); // idb
unsigned int __cdecl sub_1003A48();
signed int __cdecl sub_1003A60(signed int a1);
// int __userpurge sub_1003A98<eax>(int a1<ebp>, int a2);
char *__cdecl sub_1003B0C(int a1, int a2);
int __stdcall sub_1003BCD(int a1, int a2, int a3, int a4);
int __stdcall sub_1003C46(int a1);
signed int __stdcall sub_1003C61(int a1, int a2);
// int __userpurge sub_1003C89<eax>(int a1<ebx>, int a2);
int __stdcall sub_1003D1B(int a1);
int __stdcall sub_1003D6D(int, LPCWSTR pszPath, int, int); // idb
int __stdcall sub_1003E75(int, LPCWSTR pszPath); // idb
LONG __stdcall sub_1003EA6(int a1);
// int __userpurge sub_1003F21<eax>(int a1<ebx>, int a2, int a3);
// double __userpurge sub_1004038<st0>(int a1<eax>, int a2<ebp>, int a3<esi>, double result<st0>, int a5, int a6, int a7);
signed int __stdcall sub_100405A(int a1, int a2);
signed int __stdcall sub_1004073(int a1, int a2);
signed int __stdcall sub_10040C4(int a1, int a2, int a3);
LONG __stdcall sub_10040FB(int a1);
int __stdcall sub_1004116(int a1);
signed int __stdcall sub_100414E(int a1);
int __cdecl sub_1004194();
int __stdcall sub_1004240(HWND hDlg, int, int, int); // idb
int __stdcall loc_1004280(HWND hDlg, int, int, int); // weak
DWORD __cdecl sub_100432B();
int __stdcall sub_10043F5(int a1, int a2);
HRESULT __thiscall sub_100449D(void *this);
int __stdcall sub_10045A7(int a1);
// int __stdcall WinSqmAddToStream(_DWORD, _DWORD, _DWORD, _DWORD); weak
int __stdcall sub_1004628(LPCWSTR lpString); // idb
LSTATUS __stdcall sub_100478B(HKEY hKey, LPCWSTR lpValueName, LPCWSTR lpData);
signed int __stdcall sub_10047BA(int a1, int a2, int a3, int a4);
LSTATUS __stdcall sub_100498E(HKEY hKey, LPCWSTR lpValueName, BYTE Data);
// void __usercall sub_10056E3(struct _SECURITY_ATTRIBUTES *a1<ebx>, int a2<ebp>, int a3<esi>);
void __stdcall sub_10058A7(int a1, int a2);
int __stdcall loc_10058B2(int, int); // weak
int __stdcall loc_10058BD(int, int); // weak
int __stdcall loc_10058D7(int, int); // weak
int __stdcall loc_10058EB(int, int); // weak
int __stdcall loc_100590F(int, int); // weak
int __stdcall loc_1005951(int, int); // weak
int __stdcall loc_1005976(int, int); // weak
int __stdcall loc_1005A43(int, int); // weak
int __stdcall loc_1005AC7(int, int); // weak
int __stdcall loc_1005AEB(int, int); // weak
int __stdcall loc_1005B5A(int, int); // weak
int __stdcall loc_1005B65(int, int); // weak
int __stdcall loc_1005B9C(int, int); // weak
int __stdcall loc_1005BE2(int, int); // weak
int __stdcall loc_1005C0C(int, int); // weak
// void __usercall sub_1005D2A(int a1<ebp>, HWND a2<edi>);
// int __usercall sub_1006C68<eax>(int a1<ebp>);
// void __usercall sub_1006C7C(int a1<ebp>);
int loc_1006C97(); // weak
signed int __cdecl sub_1006CB4();
LONG __stdcall sub_1006DC0(int a1);
LONG __stdcall sub_1006DDA(int a1);
int __stdcall sub_1006DF4(int a1, int a2, int a3, int a4);
signed int __stdcall sub_1006E12(int a1, int a2, int a3);
int __stdcall sub_1006E32(int, LPCWSTR lpFileName); // idb
int __stdcall sub_1006F5C(int a1, const WCHAR *lpFileName);
LRESULT __stdcall sub_1006FB9(int a1);
const WCHAR *__stdcall sub_1007008(LPCWSTR lpsz);
int __stdcall sub_1007051(HWND hWnd, LPCWSTR lpCaption, LPCWSTR lpText, LPCWSTR lpString, UINT uType); // idb
__int32 __stdcall sub_10070D3(int a1);
int __stdcall sub_10071C2(const void *lpv, int iSize);
int __stdcall sub_100722E(HWND hWndParent, int, HWND hWnd, int); // idb
signed int __stdcall sub_100739B(DWORD hDlg, int a2, HWND hWnd, int a4);
signed int __stdcall DialogFunc(HWND hWnd, int a2, unsigned __int16 a3, int a4);
signed int __stdcall sub_10077F3(int a1);
signed int __stdcall sub_1007823(int a1, int *a2);
signed int __stdcall sub_10078D3(int a1, int a2, LPWSTR *a3);
// signed int __usercall sub_1007985<eax>(int a1<ebp>);
void __stdcall sub_10079E3(HDROP hDrop, HWND hWnd);
int __stdcall Proc(int a1, int a2, int a3, int a4);
// int __userpurge sub_1007A58<eax>(int result<eax>, int a2, int a3, int a4);
int __stdcall sub_1007A90(HANDLE hFile, UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar); // idb
LRESULT __cdecl sub_1007B40();
LRESULT __cdecl sub_1007BA2();
int __stdcall sub_1007BF6(LPCWSTR lpString); // idb
// signed int __userpurge sub_1007C80<eax>(int a1<eax>, int a2<edx>, int a3<ecx>, int a4, int a5);
int __stdcall sub_1007CD7(HWND hWnd, LPCWSTR lpString1, LPCWSTR lpBuffer); // idb
signed int __stdcall sub_1007F99(int a1, unsigned int a2, int a3);
signed int __stdcall sub_100800F(int a1);
int __stdcall sub_10080E4(int lpString, unsigned int a2);
int __stdcall sub_1008143(int a1, int a2, int a3, int a4, int a5);
int __stdcall sub_100818F(int a1, int a2, int a3, int a4, int a5);
signed int __stdcall sub_10081DB(int a1);
int __stdcall sub_1008383(DWORD hWnd); // idb
int __stdcall sub_10085E5(int a1, int a2, int a3, int a4);
size_t __cdecl sub_1008639();
bool __stdcall proc(int a1, int a2);
int __stdcall sub_100882E(HDC hdc); // idb
BOOL __cdecl sub_100888F();
signed int __cdecl sub_10088B6();
signed int __cdecl sub_1008987();
signed int __stdcall sub_1008A63(HWND hWnd, int a2, int a3, int a4);
signed int __stdcall sub_1008AEF(int a1, int a2, int a3, int a4);
int *__stdcall sub_1008B3E(int a1);
int __stdcall sub_1008EF2(HDC hdc, int y); // idb
signed int __stdcall sub_100900D(HDC a1);
bool __stdcall sub_10096AE(LCID Locale);
bool __stdcall sub_10096F8(int a1);
bool __stdcall sub_100973A(bool a1);
LRESULT __stdcall sub_100978A(int a1);
signed int __stdcall sub_10098C7(int a1, int a2);
BOOL __stdcall sub_100991D(const void *lpv, int iSize);
// signed int __usercall sub_1009952<eax>(int a1<eax>, int a2<edx>, int a3<edi>);
int __stdcall sub_1009989(HWND hwnd, int, __int16, int); // idb
void __stdcall StartAddress(int a1);
signed int __stdcall sub_1009CDF(int a1, int a2, int a3);
signed int __stdcall sub_1009D19(int a1, int a2, int a3);
int __cdecl sub_1009D73(int a1, int a2, int a3, int a4);
int __stdcall sub_1009D9D(int a1);
// int __cdecl XcptFilter(_DWORD, _DWORD); weak
bool __cdecl sub_1009DF0(int a1);
int __cdecl sub_1009E2A(int a1, unsigned int a2);
// int __usercall sub_1009E73<eax>(int a1<ebp>);
// int __cdecl amsg_exit(_DWORD); weak
// BOOL __usercall sub_1009F07<eax>(char _CF<cf>, char _ZF<zf>, char _SF<sf>, char _OF<of>, int a5<eax>, int a6<edx>, int a7<ecx>, int a8<ebx>, int a9<edi>, int a10<esi>, char a11);
// int __cdecl except_handler4_common(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD); weak
// BOOL __stdcall ClosePrinter(HANDLE hPrinter);
// BOOL __stdcall GetPrinterDriverW(HANDLE hPrinter, LPWSTR pEnvironment, DWORD Level, LPBYTE pDriverInfo, DWORD cbBuf, LPDWORD pcbNeeded);
// BOOL __stdcall OpenPrinterW(LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault);
// int __stdcall WinSqmIncrementDWORD(_DWORD, _DWORD, _DWORD); weak
// BOOL __stdcall VerQueryValueW(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen);
// BOOL __stdcall GetFileVersionInfoExW(DWORD dwFlags, LPCWSTR lpwstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData);
// DWORD __stdcall GetFileVersionInfoSizeExW(DWORD dwFlags, LPCWSTR lpwstrFilename, LPDWORD lpdwHandle);


//----- (01001405) --------------------------------------------------------
WPARAM __cdecl sub_1001405(HINSTANCE hInstance)
{
  const WCHAR *v1; // edi@1
  int v2; // eax@2
  int v3; // ST18_4@2
  HWINEVENTHOOK v4; // ebx@3
  DWORD v5; // eax@3
  struct tagMSG Msg; // [sp+8h] [bp-1Ch]@1

  Msg.hwnd = 0;
  memset(&Msg.message, 0, 0x18u);
  v1 = GetCommandLineW();
  HeapSetInformation(0, HeapEnableTerminationOnCorruption, 0, 0);
  if ( CoInitializeEx(0, 2u) >= 0 )
  {
    v2 = (int)sub_100360C(v1);
    if ( sub_1001E66(hInstance, v2, v3) )
    {
      v5 = GetCurrentProcessId();
      v4 = SetWinEventHook(0x800Bu, 0x800Bu, 0, (WINEVENTPROC)pfnWinEventProc, v5, 0, 0);
      while ( GetMessageW(&Msg, 0, 0, 0) )
      {
        if ( Msg.message == 80 )
          PostMessageW(hWnd, 0x8001u, 0, 0);
        if ( !dword_100CCE8 || !IsDialogMessageW(dword_100CCE8, &Msg) )
        {
          if ( !TranslateAcceleratorW(hWnd, hAccTable, &Msg) )
          {
            TranslateMessage(&Msg);
            DispatchMessageW(&Msg);
          }
        }
      }
      sub_1001A1C();
      if ( v4 )
        UnhookWinEvent(v4);
    }
    else
    {
      Msg.wParam = 0;
    }
    CoUninitialize();
  }
  return Msg.wParam;
}
// 1001405: could not find valid save-restore pair for ebx

//----- (010014DE) --------------------------------------------------------
signed int __userpurge sub_10014DE<eax>(void *a1<ecx>, int a2<ebx>, HWND hWnd, signed int Msg, WPARAM hDrop, unsigned int lParam)
{
  WPARAM v7; // eax@25
  LPARAM v8; // ecx@25
  WPARAM v9; // eax@29
  LRESULT (__stdcall *v10)(HWND, UINT, WPARAM, LPARAM); // edi@56
  unsigned int v11; // eax@66
  int v12; // ecx@66
  int v13; // edx@66
  HCURSOR (__stdcall *v14)(HCURSOR); // esi@67
  signed int v15; // esi@79
  unsigned int v16; // eax@87
  UINT v17; // [sp-Ch] [bp-14h]@11
  UINT v18; // [sp-Ch] [bp-14h]@33
  const WCHAR *v19; // [sp-Ch] [bp-14h]@59
  WPARAM v20; // [sp-8h] [bp-10h]@11
  WPARAM v21; // [sp-8h] [bp-10h]@33
  const WCHAR *v22; // [sp-8h] [bp-10h]@59
  LPARAM v23; // [sp-4h] [bp-Ch]@10
  LPARAM v24; // [sp-4h] [bp-Ch]@33
  HWND v25; // [sp-4h] [bp-Ch]@36
  UINT v26; // [sp-4h] [bp-Ch]@59

  if ( (unsigned int)Msg > 0x1C )
  {
    if ( Msg != 273 )
    {
      if ( Msg == 274 )
      {
        if ( !dword_100CCEC || (v16 = hDrop & 0xFFF0, v16 != 61472) && v16 != 61504 && v16 != 61520 )
          DefWindowProcW(hWnd, 0x112u, hDrop, lParam);
        return 0;
      }
      if ( Msg == 278 )
      {
        sub_1001AA5(hWnd);
        return 0;
      }
      if ( Msg == 279 )
      {
        if ( dword_100CCEC )
        {
          if ( lParam >> 16 )
            EnableMenuItem(hMenu, 0xF020u, 3u);
        }
        return 0;
      }
      if ( Msg == 563 )
      {
        sub_10079E3((HDROP)hDrop, hWnd);
        return 0;
      }
      if ( Msg != 793 )
      {
        if ( Msg != 32769 )
        {
LABEL_9:
          if ( Msg != dword_100C07C )
          {
            v23 = lParam;
LABEL_11:
            v20 = hDrop;
            v17 = Msg;
            return DefWindowProcW(hWnd, v17, v20, v23);
          }
          v12 = *(_DWORD *)(lParam + 12);
          v11 = ~(unsigned __int8)*(_DWORD *)(lParam + 12) & 1;
          v13 = (*(_DWORD *)(lParam + 12) >> 2) & 1;
          dword_100D79C = ~(unsigned __int8)*(_DWORD *)(lParam + 12) & 1;
          dword_100D798 = v13;
          if ( v12 & 8 )
          {
            v14 = SetCursor;
            SetCursor(hCursor);
          }
          else
          {
            if ( !(v12 & 0x10) )
            {
              if ( v12 & 0x20 )
              {
                if ( v11 )
                  dword_100D79C = 0;
                SetCursor(hCursor);
                SendMessageW(dword_100C028, 177u, 0, 0);
                if ( !sub_1008639() )
                {
                  do
                    sub_10070D3(0);
                  while ( sub_10081DB((int)&word_100C9E0) );
                }
                SetCursor(dword_100C094);
                SendMessageW(dword_100C028, 0xB1u, 0, 0);
                SendMessageW(dword_100C028, 0xB7u, 0, 0);
                sub_100170A(1u);
              }
              else
              {
                if ( v12 & 0x40 )
                  dword_100CCE8 = 0;
              }
              return 0;
            }
            v14 = SetCursor;
            SetCursor(hCursor);
            sub_10070D3(1);
          }
          sub_10081DB((int)&word_100C9E0);
          v14(dword_100C094);
          return 0;
        }
        v15 = 0;
        if ( ((unsigned int)GetKeyboardLayout(0) & 0x3FF) == 17 )
          v15 = 1;
        v24 = v15;
        v21 = 1;
        v18 = 216;
LABEL_34:
        SendMessageW(dword_100C028, v18, v21, v24);
        return 0;
      }
      if ( ((lParam >> 16) & 0xFFF) == 5 )
      {
        sub_1001809(a1, a2, hWnd, 0x15u, 0);
        return 0;
      }
    }
    if ( (HWND)lParam != dword_100C028
      || (v9 = hDrop >> 16, (unsigned __int16)(hDrop >> 16) != 1280) && (a1 = (void *)1281, (_WORD)v9 != 1281) )
    {
      if ( !sub_1001809(a1, a2, hWnd, hDrop, lParam) )
      {
        v23 = lParam;
        goto LABEL_11;
      }
      return 0;
    }
    if ( dword_100C030 == 1 )
    {
      dword_100C030 = 2;
      return 0;
    }
    v26 = 4112;
    v22 = szApp;
    v19 = lpText;
LABEL_60:
    MessageBoxW(::hWnd, v19, v22, v26);
    return 0;
  }
  if ( Msg == 28 )
  {
    if ( hDrop )
    {
      v7 = dword_100C044;
      v8 = ::lParam;
      if ( !dword_100C044 && !::lParam )
        return 0;
      v10 = SendMessageW;
    }
    else
    {
      v10 = SendMessageW;
      SendMessageW(dword_100C028, 176u, (WPARAM)&dword_100C044, (LPARAM)&::lParam);
      v7 = dword_100C044;
      v8 = ::lParam;
      if ( dword_100C044 == ::lParam )
      {
        dword_100C044 = 0;
        ::lParam = 0;
        return 0;
      }
    }
    v10(dword_100C028, 177u, v7, v8);
    v10(dword_100C028, 183u, 0, 0);
    return 0;
  }
  if ( Msg == 2 )
  {
    PostQuitMessage(0);
    return 0;
  }
  if ( Msg == 5 )
  {
    if ( !hDrop )
      goto LABEL_96;
    if ( hDrop == 1 )
    {
      v23 = lParam;
      v20 = 1;
      v17 = 5;
      return DefWindowProcW(hWnd, v17, v20, v23);
    }
    if ( hDrop == 2 )
LABEL_96:
      sub_1002409((signed __int16)lParam, SHIWORD(lParam));
    return 0;
  }
  if ( Msg == 6 )
  {
    if ( (_WORD)hDrop != 1 && (_WORD)hDrop != 2 || IsIconic(::hWnd) || GetForegroundWindow() != ::hWnd )
      return 0;
    v25 = GetForegroundWindow();
    goto LABEL_37;
  }
  if ( Msg == 7 )
  {
    if ( IsIconic(::hWnd) )
      return 0;
    v25 = dword_100C028;
LABEL_37:
    SetFocus(v25);
    return 0;
  }
  if ( Msg == 8 )
  {
    v24 = lParam;
    v21 = hDrop;
    v18 = 8;
    goto LABEL_34;
  }
  if ( Msg == 16 )
  {
    sub_1001963();
    if ( sub_1001664(0) )
    {
      DestroyWindow(dword_100C024);
      DestroyWindow(::hWnd);
      DeleteObject(ho);
    }
    return 0;
  }
  if ( Msg != 17 )
    goto LABEL_9;
  if ( dword_100C038 )
  {
    MessageBeep(0);
    MessageBeep(0);
    v26 = 4096;
    v22 = szApp;
    v19 = dword_100C314;
    goto LABEL_60;
  }
  return sub_1001664(1);
}
// 100C030: using guessed type int dword_100C030;
// 100C038: using guessed type int dword_100C038;
// 100C07C: using guessed type int dword_100C07C;
// 100CCEC: using guessed type int dword_100CCEC;
// 100D798: using guessed type int dword_100D798;
// 100D79C: using guessed type int dword_100D79C;

//----- (01001564) --------------------------------------------------------
void __thiscall sub_1001564(void *this)
{
  JUMPOUT((unsigned int)this, dword_100C010, *(unsigned int *)sub_1009F07);
}
// 100C010: using guessed type int dword_100C010;

//----- (010015C3) --------------------------------------------------------
signed int sub_10015C3(wchar_t *Dest, unsigned int a2, const wchar_t *Format, ...)
{
  signed int result; // eax@1
  int v4; // eax@4
  signed int v5; // ebx@4
  int v6; // esi@4
  va_list va; // [sp+14h] [bp+14h]@1

  va_start(va, Format);
  result = 0;
  if ( !a2 || a2 > 0x7FFFFFFF )
    result = -2147024809;
  if ( result >= 0 )
  {
    v6 = a2 - 1;
    v5 = 0;
    v4 = vsnwprintf(Dest, a2 - 1, Format, va);
    if ( v4 < 0 || v4 > (unsigned int)v6 )
    {
      v5 = -2147024774;
    }
    else
    {
      if ( v4 != v6 )
        return v5;
    }
    Dest[v6] = 0;
    return v5;
  }
  return result;
}

//----- (01001620) --------------------------------------------------------
void __userpurge sub_1001620(int a1<ebp>, void (__stdcall *a2)(_DWORD, _DWORD, _DWORD, _DWORD)<esi>, int a3)
{
  sub_10015C3((wchar_t *)(a1 - 260), 0x80u, Format);
  JUMPOUT((unsigned int)dword_100C024, 0, *(unsigned int *)loc_1001799);
  a2(dword_100C024, 1035, 1, a1 - 260);
  JUMPOUT(*(unsigned int *)loc_1001799);
}
// 1001799: using guessed type int __stdcall loc_1001799(int);

//----- (01001664) --------------------------------------------------------
signed int __stdcall sub_1001664(int a1)
{
  JUMPOUT(dword_100C008, 0, *(unsigned int *)sub_1001A4D);
  JUMPOUT(SendMessageW(dword_100C028, 0xEu, 0, 0), 0, *(unsigned int *)sub_1001A4D);
  return 1;
}
// 100C008: using guessed type int dword_100C008;

//----- (0100170A) --------------------------------------------------------
LRESULT __stdcall sub_100170A(unsigned int a1)
{
  LRESULT result; // eax@1
  WPARAM v2; // eax@1
  unsigned int v3; // edi@1
  LPARAM lParam; // [sp+Ch] [bp-10Ch]@1
  WPARAM wParam; // [sp+10h] [bp-108h]@1
  unsigned int v6; // [sp+114h] [bp-4h]@1
  int v7; // [sp+118h] [bp+0h]@1

  v6 = (unsigned int)&v7 ^ dword_100C010;
  SendMessageW(dword_100C028, 176u, (WPARAM)&wParam, (LPARAM)&lParam);
  v2 = SendMessageW(dword_100C028, 0xC9u, wParam, 0);
  v3 = v2 + 1;
  result = SendMessageW(dword_100C028, 0xBBu, v2, 0);
  JUMPOUT(a1, 0, *(unsigned int *)sub_1001620);
  JUMPOUT(wParam - result + 1, dword_100C01C, *(unsigned int *)sub_1001620);
  JUMPOUT(v3, dword_100C018, *(unsigned int *)sub_1001620);
  dword_100C018 = v3;
  dword_100C01C = wParam - result + 1;
  return result;
}
// 100C010: using guessed type int dword_100C010;
// 100C018: using guessed type int dword_100C018;
// 100C01C: using guessed type int dword_100C01C;

//----- (010017BB) --------------------------------------------------------
LRESULT __stdcall pfnWinEventProc(int a1, int a2, int a3, int a4, int a5, int a6, int a7)
{
  return sub_100170A(0);
}

//----- (01001809) --------------------------------------------------------
signed int __userpurge sub_1001809<eax>(void *a1<ecx>, int a2<ebx>, HWND a3, unsigned __int16 a4, int a5)
{
  int ebp0; // ebp@0
  HMENU v7; // eax@15
  HMENU v8; // ebx@15
  LPARAM v9; // eax@15
  HDC v10; // ebx@20
  int v11; // eax@21
  HFONT v12; // esi@22
  const WCHAR *v13; // eax@30
  int v14; // esi@30
  signed int v15; // eax@31
  int v16; // eax@37
  signed int v17; // esi@37
  DWORD v18; // eax@42
  HANDLE v19; // ebx@68
  HWND v20; // eax@78
  HWND v21; // eax@80
  int v22; // eax@86
  HMENU v23; // eax@92
  HMENU v24; // ebx@92
  HMENU v25; // eax@92
  HMENU v26; // eax@93
  HMENU v27; // eax@93
  signed int v28; // esi@96
  HWND v29; // [sp-10h] [bp-78h]@74
  UINT v30; // [sp-Ch] [bp-74h]@74
  UINT v31; // [sp-8h] [bp-70h]@15
  WPARAM v32; // [sp-8h] [bp-70h]@74
  UINT v33; // [sp-4h] [bp-6Ch]@15
  int v34; // [sp-4h] [bp-6Ch]@34
  LPARAM v35; // [sp-4h] [bp-6Ch]@74
  CHOOSEFONTW v36; // [sp+Ch] [bp-5Ch]@20
  struct tagRECT Rect; // [sp+48h] [bp-20h]@95
  int v38; // [sp+58h] [bp-10h]@30
  HWND hWnd; // [sp+5Ch] [bp-Ch]@1
  LPVOID lpFileName; // [sp+60h] [bp-8h]@30
  unsigned int v41; // [sp+64h] [bp-4h]@1
  int v42; // [sp+68h] [bp+0h]@1

  v41 = (unsigned int)&v42 ^ dword_100C010;
  hWnd = a3;
  JUMPOUT(a4, 0x40u, *(unsigned int *)loc_1001C23);
  if ( a4 == 64 )
  {
    sub_100449D(a1);
    return 1;
  }
  if ( (signed int)a4 > 21 )
  {
    if ( (signed int)a4 > 26 )
    {
      if ( a4 == 27 )
      {
        GetClientRect(::hWnd, &Rect);
        if ( *(_DWORD *)&dword_100C02C )
        {
          *(_DWORD *)&dword_100C02C = 0;
          ShowWindow(dword_100C024, 0);
          sub_1002409(Rect.right - Rect.left, Rect.bottom - Rect.top);
          v28 = 1;
        }
        else
        {
          v28 = 1;
          *(_DWORD *)&dword_100C02C = 1;
          sub_1002409(Rect.right - Rect.left, Rect.bottom - Rect.top);
          sub_100170A(1u);
          ShowWindow(dword_100C024, 5);
        }
        dword_100CCF0 = v28;
        return 1;
      }
      if ( a4 != 32 )
      {
        if ( a4 == 33 )
        {
          v36.lStructSize = 0;
          memset(&v36.hwndOwner, 0, 0x38u);
          v10 = GetDC(0);
          if ( v10 )
          {
            v36.lStructSize = 60;
            v36.hwndOwner = hWnd;
            v36.lpLogFont = &lf;
            v11 = GetDeviceCaps(v10, 90);
            lf.lfHeight = -MulDiv(*(int *)&Data, v11, 720);
            v36.Flags = 16777281;
            v36.nFontType = 8192;
            ReleaseDC(0, v10);
            if ( ChooseFontW(&v36) )
            {
              SetCursor(hCursor);
              v12 = CreateFontIndirectW(&lf);
              if ( v12 )
              {
                DeleteObject(ho);
                ho = v12;
                SendMessageW(dword_100C028, 0x30u, (WPARAM)v12, 1);
                *(_DWORD *)&Data = v36.iPointSize;
              }
              SetCursor(dword_100C094);
              dword_100C03C = 1;
            }
          }
          return 1;
        }
        return 0;
      }
      v22 = -(wParam != 0);
      if ( sub_1008383((v22 & 0x100000) + 1344274692) )
      {
        dword_100CCF0 = 1;
        wParam = wParam == 0;
      }
      else
      {
        MessageBoxW(::hWnd, dword_100C2EC, szApp, 0x30u);
      }
      if ( !wParam )
      {
        v26 = GetMenu(::hWnd);
        v27 = GetSubMenu(v26, 3);
        EnableMenuItem(v27, 0x1Bu, 0);
        if ( !dword_100D580 )
          return 1;
        v35 = 0;
        v32 = 27;
        v30 = 273;
        v29 = hWnd;
        goto LABEL_75;
      }
      dword_100D580 = *(_DWORD *)&dword_100C02C;
      if ( *(_DWORD *)&dword_100C02C )
        SendMessageW(hWnd, 0x111u, 0x1Bu, 0);
      v23 = GetMenu(::hWnd);
      v24 = v23;
      v25 = GetSubMenu(v23, 3);
      CheckMenuItem(v25, 0x1Bu, 0);
      v33 = 1;
      v31 = 27;
      v7 = GetSubMenu(v24, 3);
    }
    else
    {
      if ( a4 == 26 )
      {
        sub_100978A(0);
        return 1;
      }
      if ( a4 == 22 )
      {
        if ( word_100C9E0 )
        {
          sub_10081DB((int)&word_100C9E0);
          return 1;
        }
LABEL_84:
        v20 = dword_100CCE8;
        if ( !dword_100CCE8 )
        {
          stru_100C0C0.wReplaceWithLen = 0;
          stru_100C0C0.Flags = 65537;
          stru_100C0C0.lpstrReplaceWith = 0;
          stru_100C0C0.lpstrFindWhat = (LPWSTR)&word_100C9E0;
          stru_100C0C0.wFindWhatLen = 128;
          v21 = FindTextW(&stru_100C0C0);
          goto LABEL_81;
        }
        goto LABEL_79;
      }
      if ( a4 == 23 )
      {
        v20 = dword_100CCE8;
        if ( !dword_100CCE8 )
        {
          stru_100C0C0.Flags = 65552;
          stru_100C0C0.lpstrReplaceWith = (LPWSTR)&unk_100E060;
          stru_100C0C0.wReplaceWithLen = 128;
          stru_100C0C0.lpstrFindWhat = (LPWSTR)&word_100C9E0;
          stru_100C0C0.wFindWhatLen = 128;
          v21 = ReplaceTextW(&stru_100C0C0);
LABEL_81:
          dword_100CCE8 = v21;
          return 1;
        }
LABEL_79:
        SetFocus(v20);
        return 1;
      }
      if ( a4 == 24 )
      {
        if ( !DialogBoxParamW(hInstance, (LPCWSTR)0xE, ::hWnd, (DLGPROC)DialogFunc, 0) )
          sub_1006FB9(dword_100E160);
        return 1;
      }
      if ( a4 != 25 )
        return 0;
      v8 = GetMenu(::hWnd);
      v9 = SendMessageW(dword_100C028, 14u, 0, 0);
      SendMessageW(dword_100C028, 0xB1u, 0, v9);
      SendMessageW(dword_100C028, 0xB7u, 0, 0);
      v33 = 1;
      v31 = 25;
      v7 = GetSubMenu(v8, 1);
    }
    EnableMenuItem(v7, v31, v33);
    return 1;
  }
  if ( a4 == 21 )
    goto LABEL_84;
  if ( (signed int)a4 <= 5 )
  {
    if ( a4 == 5 )
    {
      if ( PageSetupDlgW(&stru_100C140) )
      {
LABEL_72:
        sub_1002558((int)&word_100C740, 0x28u, (int)&word_100C6A0);
        sub_1002558((int)&Dst, 0x28u, (int)&unk_100C6F0);
        dword_100CCF4 = 1;
      }
      else
      {
        while ( 1 )
        {
          v18 = CommDlgExtendedError();
          if ( v18 != 4107 )
          {
            if ( v18 != 4105 && v18 != 4108 )
              break;
          }
          sub_1001A1C();
          stru_100C140.hDevNames = 0;
          stru_100C140.hDevMode = 0;
          if ( PageSetupDlgW(&stru_100C140) )
            goto LABEL_72;
        }
        sub_100432B();
      }
      return 1;
    }
    if ( a4 == 1 )
    {
      sub_100800F(1);
    }
    else
    {
      if ( a4 == 2 )
      {
        if ( !sub_1001664(0) )
          return 1;
        v38 = dword_100C00C;
        v16 = sub_1003F21(a2, (int)hWnd, (int)&lpFileName);
        v17 = v16;
        if ( v16 >= 0 )
          goto LABEL_101;
        if ( v16 != -2147023673 )
          v17 = sub_1007823((int)hWnd, (int *)&lpFileName);
        if ( v17 >= 0 )
        {
LABEL_101:
          v19 = hFile;
          hFile = CreateFileW((LPCWSTR)lpFileName, 0x80000000u, 3u, 0, 3u, 0x80u, 0);
          if ( !sub_1002820(ebp0, (int)lpFileName, dword_100C00C) )
          {
            hFile = v19;
            v17 = -2147467259;
          }
          CoTaskMemFree(lpFileName);
          if ( v17 >= 0 )
            return 1;
        }
        dword_100C00C = v38;
        v34 = v17;
      }
      else
      {
        if ( a4 == 3 )
        {
          dword_100E040 = dword_100C00C;
          if ( !dword_100C008 && sub_1007CD7(::hWnd, &FileName, 0) )
            return 1;
        }
        else
        {
          if ( a4 != 4 )
            return 0;
        }
        v14 = (int)L"*.txt";
        v38 = 0;
        lpFileName = 0;
        v13 = L"*.txt";
        if ( !dword_100C008 )
          v13 = &FileName;
        v15 = sub_1003D6D((int)hWnd, v13, (int)&lpFileName, (int)&v38);
        if ( v15 >= 0 )
          goto LABEL_102;
        if ( v15 != -2147023673 )
        {
          if ( !dword_100C008 )
            v14 = (int)&FileName;
          v15 = sub_10078D3((int)hWnd, v14, (LPWSTR *)&lpFileName);
        }
        if ( v15 >= 0 )
        {
LABEL_102:
          if ( sub_1007CD7(hWnd, (LPCWSTR)lpFileName, (LPCWSTR)1) )
            sub_1002558((int)&FileName, 0x104u, (int)lpFileName);
          if ( v38 )
            (*(void (__stdcall **)(int))(*(_DWORD *)v38 + 8))(v38);
          CoTaskMemFree(lpFileName);
          return 1;
        }
        v34 = v15;
      }
      sub_1003C46(v34);
    }
    return 1;
  }
  JUMPOUT(a4 - 6, 0, *(unsigned int *)loc_1004280);
  if ( a4 == 7 )
    JUMPOUT(*(unsigned int *)loc_1001C66);
  if ( a4 == 15 )
    return 1;
  if ( a4 == 16 )
  {
    v35 = 0;
    v32 = 0;
    v30 = 199;
    v29 = dword_100C028;
LABEL_75:
    SendMessageW(v29, v30, v32, v35);
    return 1;
  }
  return 0;
}
// 1001C23: using guessed type int __stdcall loc_1001C23(HWND hWndNewOwner);
// 1001C66: using guessed type int __stdcall loc_1001C66(HWND hWndNewOwner);
// 1004280: using guessed type int __stdcall loc_1004280(HWND hDlg, int, int, int);
// 100C008: using guessed type int dword_100C008;
// 100C00C: using guessed type int dword_100C00C;
// 100C010: using guessed type int dword_100C010;
// 100C03C: using guessed type int dword_100C03C;
// 100CCF0: using guessed type int dword_100CCF0;
// 100CCF4: using guessed type int dword_100CCF4;
// 100D580: using guessed type int dword_100D580;
// 100E040: using guessed type int dword_100E040;
// 100E160: using guessed type int dword_100E160;

//----- (01001963) --------------------------------------------------------
__int32 __cdecl sub_1001963()
{
  __int32 result; // eax@1
  char v1; // zf@2
  signed int v2; // ecx@2
  char *v3; // edi@2
  char *v4; // esi@2
  WINDOWPLACEMENT wndpl; // [sp+4h] [bp-34h]@1
  int v6; // [sp+30h] [bp-8h]@1
  HKEY hKey; // [sp+34h] [bp-4h]@11

  v6 = 0;
  wndpl.length = 44;
  result = GetWindowPlacement(hWnd, &wndpl);
  if ( result )
  {
    v2 = 4;
    v3 = (char *)&wndpl.rcNormalPosition;
    v4 = (char *)&::wndpl.rcNormalPosition;
    result = 0;
    v1 = 1;
    do
    {
      if ( !v2 )
        break;
      v1 = *(_DWORD *)v4 == *(_DWORD *)v3;
      v4 += 4;
      v3 += 4;
      --v2;
    }
    while ( v1 );
    if ( !v1 )
    {
      v6 = 1;
LABEL_11:
      result = RegCreateKeyW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Notepad", &hKey);
      if ( !result )
      {
        if ( dword_100C03C )
        {
          sub_100498E(hKey, L"lfEscapement", LOBYTE(lf.lfEscapement));
          sub_100498E(hKey, L"lfOrientation", LOBYTE(lf.lfOrientation));
          sub_100498E(hKey, L"lfWeight", LOBYTE(lf.lfWeight));
          sub_100498E(hKey, L"lfItalic", lf.lfItalic);
          sub_100498E(hKey, L"lfUnderline", lf.lfUnderline);
          sub_100498E(hKey, L"lfStrikeOut", lf.lfStrikeOut);
          sub_100498E(hKey, L"lfCharSet", lf.lfCharSet);
          sub_100498E(hKey, L"lfOutPrecision", lf.lfOutPrecision);
          sub_100498E(hKey, L"lfClipPrecision", lf.lfClipPrecision);
          sub_100498E(hKey, L"lfQuality", lf.lfQuality);
          sub_100498E(hKey, L"lfPitchAndFamily", lf.lfPitchAndFamily);
          sub_100478B(hKey, L"lfFaceName", lf.lfFaceName);
          sub_100498E(hKey, L"iPointSize", Data);
        }
        if ( dword_100CCF0 )
        {
          sub_100498E(hKey, L"fWrap", wParam);
          sub_100498E(hKey, L"StatusBar", dword_100C02C);
        }
        if ( dword_100CCF4 )
        {
          sub_100478B(hKey, L"szHeader", &word_100C740);
          sub_100478B(hKey, L"szTrailer", (LPCWSTR)&Dst);
          sub_100498E(hKey, L"iMarginTop", LOBYTE(stru_100C140.rtMargin.top));
          sub_100498E(hKey, L"iMarginBottom", LOBYTE(stru_100C140.rtMargin.bottom));
          sub_100498E(hKey, L"iMarginLeft", LOBYTE(stru_100C140.rtMargin.left));
          sub_100498E(hKey, L"iMarginRight", LOBYTE(stru_100C140.rtMargin.right));
        }
        if ( v6 )
        {
          sub_100498E(hKey, L"iWindowPosX", LOBYTE(wndpl.rcNormalPosition.left));
          sub_100498E(hKey, L"iWindowPosY", LOBYTE(wndpl.rcNormalPosition.top));
          sub_100498E(hKey, L"iWindowPosDX", LOBYTE(wndpl.rcNormalPosition.right) - LOBYTE(wndpl.rcNormalPosition.left));
          sub_100498E(hKey, L"iWindowPosDY", LOBYTE(wndpl.rcNormalPosition.bottom) - LOBYTE(wndpl.rcNormalPosition.top));
        }
        result = RegCloseKey(hKey);
      }
      return result;
    }
  }
  if ( dword_100CCF4 || dword_100CCF0 || dword_100C03C )
    goto LABEL_11;
  return result;
}
// 100C03C: using guessed type int dword_100C03C;
// 100CCF0: using guessed type int dword_100CCF0;
// 100CCF4: using guessed type int dword_100CCF4;

//----- (01001A1C) --------------------------------------------------------
HGLOBAL __cdecl sub_1001A1C()
{
  HGLOBAL result; // eax@2

  if ( stru_100C140.hDevMode )
    GlobalFree(stru_100C140.hDevMode);
  result = stru_100C140.hDevNames;
  if ( stru_100C140.hDevNames )
    result = GlobalFree(stru_100C140.hDevNames);
  stru_100C140.hDevMode = 0;
  stru_100C140.hDevNames = 0;
  return result;
}

//----- (01001A4D) --------------------------------------------------------
void __userpurge sub_1001A4D(const WCHAR *a1<ebx>, int a2<ebp>, int (__stdcall *a3)(_DWORD, _DWORD, _DWORD, _DWORD)<esi>, int a4)
{
  int v4; // ST10_4@1
  const WCHAR *v5; // eax@3
  const WCHAR *v6; // edi@3
  bool v7; // esi@4
  int v8; // eax@4
  int v9; // eax@8
  signed int v10; // edi@11
  int v11; // eax@13
  const WCHAR *v12; // ST08_4@13
  const WCHAR *v13; // eax@20

  if ( a3(dword_100C028, 184, a1, v4) )
  {
    v5 = lpString2;
    v6 = &FileName;
    if ( (const WCHAR *)dword_100C008 == a1 )
      v5 = &FileName;
    v7 = 1;
    dword_100C038 = 1;
    v8 = sub_1004628(v5);
    *(_DWORD *)(a2 - 12) = v8;
    dword_100C038 = (int)a1;
    if ( v8 == 6 )
    {
      if ( (const WCHAR *)dword_100C008 != a1 )
        goto LABEL_28;
      dword_100E040 = dword_100C00C;
      v9 = sub_1007CD7(hWnd, &FileName, a1);
      v7 = v9 == 0;
      if ( !(v9 == 0) )
        goto LABEL_2;
      if ( (const WCHAR *)dword_100C008 != a1 )
LABEL_28:
        v6 = L"*.txt";
      v10 = SHStrDupW(v6, a2 - 8);
      if ( v10 < (signed int)a1 )
        goto LABEL_24;
      while ( (const WCHAR *)v7 != a1 )
      {
        v12 = *(const WCHAR **)(a2 - 8);
        *(_DWORD *)(a2 - 16) = a1;
        v11 = sub_1003D6D((int)hWnd, v12, a2 - 4, a2 - 16);
        v10 = v11;
        if ( v11 < (signed int)a1 )
        {
          if ( v11 != -2147023673 )
            v10 = sub_10078D3((int)hWnd, *(_DWORD *)(a2 - 8), (LPWSTR *)(a2 - 4));
        }
        CoTaskMemFree(*(LPVOID *)(a2 - 8));
        if ( v10 < (signed int)a1 )
          goto LABEL_24;
        if ( sub_1007CD7(hWnd, *(LPCWSTR *)(a2 - 4), (LPCWSTR)1) )
        {
          sub_1002558((int)&FileName, 0x104u, *(_DWORD *)(a2 - 4));
          dword_100C00C = dword_100E040;
          v7 = 0;
        }
        else
        {
          v10 = SHStrDupW(*(_DWORD *)(a2 - 4), a2 - 8);
        }
        v13 = *(const WCHAR **)(a2 - 16);
        if ( v13 != a1 )
          (*(void (__cdecl **)(_DWORD))(*(_DWORD *)v13 + 8))(*(_DWORD *)(a2 - 16));
        CoTaskMemFree(*(LPVOID *)(a2 - 4));
        if ( v10 < (signed int)a1 )
          break;
      }
      if ( v10 < (signed int)a1 )
      {
LABEL_24:
        *(_DWORD *)(a2 - 12) = 2;
        if ( v10 == -2147024882 )
          MessageBoxW(hWnd, lpText, szApp, 0x1010u);
      }
    }
  }
LABEL_2:
  JUMPOUT(*(unsigned int *)loc_100169F);
}
// 10013B4: using guessed type int __stdcall SHStrDupW(_DWORD, _DWORD);
// 100169F: using guessed type int __stdcall loc_100169F(int);
// 100C008: using guessed type int dword_100C008;
// 100C00C: using guessed type int dword_100C00C;
// 100C038: using guessed type int dword_100C038;
// 100E040: using guessed type int dword_100E040;

//----- (01001A72) --------------------------------------------------------
int __usercall sub_1001A72<eax>(int a1<ebp>)
{
  sub_1001564((void *)(a1 ^ *(_DWORD *)(a1 - 28)));
  return sub_10023D0(a1);
}
// 10023D0: using guessed type _DWORD __usercall sub_10023D0<eax>(_DWORD ebp0<ebp>);

//----- (01001AA5) --------------------------------------------------------
DWORD __stdcall sub_1001AA5(HWND hWndNewOwner)
{
  int v1; // eax@1
  HMENU v2; // ebx@1
  bool v3; // ST0C_4@1
  HMENU v4; // eax@1
  UINT v5; // ST0C_4@1
  HMENU v6; // eax@1
  UINT v7; // ST0C_4@1
  HMENU v8; // eax@1
  HMENU v9; // eax@1
  bool v10; // ST0C_4@4
  HMENU v11; // eax@4
  UINT v13; // ST0C_4@6
  HMENU v14; // eax@6
  UINT v15; // ST0C_4@6
  HMENU v16; // eax@6
  bool v17; // ST0C_4@6
  HMENU v18; // eax@6
  bool v19; // ST0C_4@6
  HMENU v20; // eax@6
  UINT v21; // ST0C_4@6
  HMENU v22; // eax@6
  UINT v23; // ST0C_4@6
  HMENU v24; // eax@6
  HMENU v25; // eax@8
  LPARAM lParam; // [sp+Ch] [bp-10h]@1
  WPARAM wParam; // [sp+10h] [bp-Ch]@1
  int v28; // [sp+14h] [bp-8h]@1
  UINT uEnable; // [sp+18h] [bp-4h]@1

  v28 = 0;
  v2 = GetMenu(hWnd);
  SendMessageW(dword_100C028, 0xB0u, (WPARAM)&wParam, (LPARAM)&lParam);
  v3 = wParam == lParam;
  uEnable = wParam == lParam;
  v4 = GetSubMenu(v2, 1);
  EnableMenuItem(v4, 768u, v3);
  v5 = uEnable;
  v6 = GetSubMenu(v2, 1);
  EnableMenuItem(v6, 0x301u, v5);
  v7 = uEnable;
  v8 = GetSubMenu(v2, 1);
  EnableMenuItem(v8, 0x303u, v7);
  v9 = GetSubMenu(v2, 1);
  v1 = GetMenuState(v9, 0x19u, 0);
  if ( v1 == 1 )
  {
    if ( uEnable == 1 )
    {
      v25 = GetSubMenu(v2, v1);
      EnableMenuItem(v25, 0x19u, 0);
    }
  }
  if ( OpenClipboard(hWndNewOwner) )
  {
    v28 = IsClipboardFormatAvailable(1u);
    CloseClipboard();
  }
  v10 = v28 == 0;
  v11 = GetSubMenu(v2, 1);
  EnableMenuItem(v11, 0x302u, v10);
  uEnable = 1;
  if ( SendMessageW(dword_100C028, 0xEu, 0, 0) )
    uEnable = 0;
  v13 = uEnable;
  v14 = GetSubMenu(v2, 1);
  EnableMenuItem(v14, 0x15u, v13);
  v15 = uEnable;
  v16 = GetSubMenu(v2, 1);
  EnableMenuItem(v16, 0x16u, v15);
  v17 = ::wParam != 0;
  v18 = GetSubMenu(v2, 1);
  EnableMenuItem(v18, 0x18u, v17);
  v19 = SendMessageW(dword_100C028, 0xC6u, 0, 0) == 0;
  v20 = GetSubMenu(v2, 1);
  EnableMenuItem(v20, 0x10u, v19);
  v21 = ::wParam != 0 ? 8 : 0;
  v22 = GetSubMenu(v2, 2);
  CheckMenuItem(v22, 32u, v21);
  v23 = *(_DWORD *)&dword_100C02C != 0 ? 8 : 0;
  v24 = GetSubMenu(v2, 3);
  return CheckMenuItem(v24, 0x1Bu, v23);
}

//----- (01001E66) --------------------------------------------------------
signed int __stdcall sub_1001E66(HINSTANCE hInstance, int a2, int nCmdShow)
{
  int ebp0; // ebp@0
  HACCEL v4; // eax@5
  HWND v5; // esi@7
  void *v6; // ecx@7
  int v7; // eax@16
  int v8; // edi@17
  int v9; // eax@17
  signed int v10; // eax@20
  int v11; // ecx@23
  HMENU v13; // eax@32
  HMENU v14; // eax@32
  int v15; // eax@41
  int Dst; // [sp+Ch] [bp-A8h]@10
  int v17; // [sp+28h] [bp-8Ch]@11
  int v18; // [sp+2Ch] [bp-88h]@11
  int v19; // [sp+30h] [bp-84h]@11
  int v20; // [sp+34h] [bp-80h]@11
  struct tagRECT Rect; // [sp+38h] [bp-7Ch]@13
  int v22; // [sp+48h] [bp-6Ch]@15
  int v23; // [sp+4Ch] [bp-68h]@15
  int v24; // [sp+50h] [bp-64h]@15
  int v25; // [sp+54h] [bp-60h]@15
  LPARAM lParam; // [sp+58h] [bp-5Ch]@15
  int v27; // [sp+5Ch] [bp-58h]@15
  HINSTANCE v28; // [sp+60h] [bp-54h]@1
  __int32 v29; // [sp+64h] [bp-50h]@1
  HGDIOBJ wParam; // [sp+68h] [bp-4Ch]@16
  HDC hdc; // [sp+6Ch] [bp-48h]@3
  WCHAR String1; // [sp+70h] [bp-44h]@16
  unsigned int v33; // [sp+B0h] [bp-4h]@1
  int v34; // [sp+B4h] [bp+0h]@1

  v33 = (unsigned int)&v34 ^ dword_100C010;
  v28 = hInstance;
  v29 = a2;
  dword_100C07C = RegisterWindowMessageW(L"commdlg_FindReplace");
  if ( !dword_100C07C )
    return 0;
  dword_100C078 = RegisterWindowMessageW(L"commdlg_help");
  if ( !dword_100C078 )
    return 0;
  hdc = GetDC(0);
  if ( !hdc )
    return 0;
  if ( !sub_1003881(hInstance) )
    return 0;
  dword_100C094 = LoadCursorW(0, (LPCWSTR)32513);
  hCursor = LoadCursorW(0, (LPCWSTR)0x7F02);
  v4 = LoadAcceleratorsW(hInstance, L"MainAcc");
  hAccTable = v4;
  if ( !hCursor )
    return 0;
  if ( !v4 )
    return 0;
  sub_10037EF(hInstance);
  ::hInstance = hInstance;
  stru_100C140.lStructSize = 84;
  stru_100C140.hDevMode = 0;
  stru_100C140.hDevNames = 0;
  stru_100C140.hInstance = hInstance;
  sub_1002F8B(v6);
  sub_10030E2();
  v5 = CreateWindowExW(0, L"Notepad", &szOtherStuff, 0xCF0000u, X, Y, nWidth, nHeight, 0, 0, hInstance, 0);
  hWnd = v5;
  stru_100C140.hwndOwner = v5;
  if ( !v5 )
    return 0;
  if ( Y != -2147483648 )
  {
    if ( X != -2147483648 )
    {
      memset(&Dst, 0, 0x2Cu);
      Dst = 44;
      if ( GetWindowPlacement(v5, (WINDOWPLACEMENT *)&Dst) )
      {
        memset(&wndpl, 0, 0x2Cu);
        wndpl.rcNormalPosition.left = X;
        wndpl.length = 44;
        wndpl.rcNormalPosition.right = v19 + X - v17;
        wndpl.rcNormalPosition.top = Y;
        wndpl.rcNormalPosition.bottom = v20 + Y - v18;
      }
      SetWindowPlacement(hWnd, &wndpl);
      v5 = hWnd;
    }
  }
  DragAcceptFiles(v5, 1);
  GetClientRect(hWnd, &Rect);
  dword_100C028 = CreateWindowExW(
                    0x200u,
                    L"Edit",
                    &szOtherStuff,
                    ::wParam != 0 ? 1344274692 : 1345323268,
                    0,
                    0,
                    Rect.right,
                    Rect.bottom - 100,
                    hWnd,
                    (HMENU)0xF,
                    v28,
                    0);
  if ( !dword_100C028
    || (dword_100C024 = CreateStatusWindowW(
                          (*(_DWORD *)&dword_100C02C != 0 ? 0x10000000 : 0) | 0x44800000,
                          &szOtherStuff,
                          hWnd,
                          0x401u),
        !dword_100C024) )
    return 0;
  sub_100170A(1u);
  GetClientRect(dword_100C024, (LPRECT)&v22);
  dword_100C084 = v25 - v23;
  v27 = -1;
  lParam = 3 * (v24 - v22) / 4;
  SendMessageW(dword_100C024, 1028u, 2u, (LPARAM)&lParam);
  SendMessageW(dword_100C028, 0xC8u, ::wParam, 0);
  if ( ::wParam )
  {
    v13 = GetMenu(hWnd);
    v14 = GetSubMenu(v13, 3);
    EnableMenuItem(v14, 0x1Bu, 1u);
  }
  v7 = GetDeviceCaps(hdc, 90);
  lf.lfHeight = -MulDiv(*(int *)&Data, v7, 720);
  ho = CreateFontIndirectW(&lf);
  wParam = SelectObject(hdc, ho);
  GetTextFaceW(hdc, 32, &String1);
  SelectObject(hdc, wParam);
  if ( lstrcmpiW(&String1, lf.lfFaceName) )
  {
    EnumFontsW(hdc, lf.lfFaceName, (FONTENUMPROCW)Proc, (LPARAM)&lf);
    DeleteObject(ho);
    ho = CreateFontIndirectW(&lf);
  }
  SendMessageW(dword_100C028, 0x30u, (WPARAM)ho, 0);
  ReleaseDC(0, hdc);
  word_100C9E0 = 0;
  hMem = (HLOCAL)SendMessageW(dword_100C028, 0xBDu, 0, 0);
  SendMessageW(dword_100C028, 0xC5u, 0, 0);
  sub_1002456(lpString2);
  ShowWindow(hWnd, nCmdShow);
  SetCursor(dword_100C094);
  v9 = sub_10025CB(v29);
  dword_100C05C = -1;
  v8 = v9;
  if ( !sub_1002689(L"/A", (WCHAR **)v9) )
  {
    dword_100C05C = 0;
LABEL_36:
    v8 = sub_10025CB(v8 + 4);
    goto LABEL_20;
  }
  if ( !sub_1002689(L"/W", (WCHAR **)v8) )
    dword_100C05C = 1;
  if ( dword_100C05C != -1 )
    goto LABEL_36;
LABEL_20:
  v10 = sub_10025EF((WCHAR **)v8);
  if ( v10 )
  {
    if ( v10 != 2 )
      goto LABEL_23;
  }
  else
  {
    if ( sub_1002631((WCHAR **)v8, nCmdShow) )
    {
      PostMessageW(hWnd, 0x10u, 0, 0);
      return 1;
    }
    if ( !*(_WORD *)v8 )
    {
LABEL_23:
      sub_10026D5(&Dest, 0x50u);
      sub_10026D5(&word_100C7E0, 0x50u);
      memset(&stru_100C1A0, 0, 0x58u);
      stru_100C1A0.hInstance = v28;
      stru_100C1A0.lStructSize = 88;
      memset(&stru_100C0C0, 0, sizeof(stru_100C0C0));
      stru_100C1A0.hwndOwner = hWnd;
      stru_100C1A0.nMaxFile = 260;
      stru_100C0C0.lStructSize = 40;
      stru_100C0C0.hwndOwner = stru_100C1A0.hwndOwner;
      SendMessageW(dword_100C028, 0xB0u, (WPARAM)&wParam, (LPARAM)&v29);
      SendMessageW(dword_100C028, 0xB1u, (WPARAM)wParam, v29);
      SendMessageW(dword_100C028, 0xB7u, 0, 0);
      if ( ((unsigned int)GetKeyboardLayout(0) & 0x3FF) == 17 )
        SendMessageW(dword_100C028, 0xD8u, 1u, 1);
      sub_1002733(v11);
      return 1;
    }
    sub_1002C0D((LPWSTR)&FileName, (LPCWSTR)v8, 0x104u);
    hFile = CreateFileW(&FileName, 0x80000000u, 3u, 0, 3u, 0x80u, 0);
    if ( hFile != (HANDLE)-1 )
    {
LABEL_28:
      sub_1002820(ebp0, (int)&FileName, dword_100C05C);
      goto LABEL_23;
    }
    if ( GetLastError() != 2 )
    {
      sub_1007BF6(&FileName);
      sub_1002456(lpString2);
      sub_1002558((int)&FileName, 0x104u, (int)lpString2);
      goto LABEL_30;
    }
    v15 = sub_1007051(hWnd, szApp, dword_100C2B4, &FileName, 0x33u);
    if ( v15 != 2 )
    {
      if ( v15 == 6 )
        hFile = CreateFileW(&FileName, 0xC0000000u, 3u, 0, 4u, 0x80u, 0);
LABEL_30:
      if ( hFile == (HANDLE)-1 )
        goto LABEL_23;
      goto LABEL_28;
    }
  }
  return 0;
}
// 100236C: using guessed type wchar_t aW[3];
// 1002374: using guessed type wchar_t aA[3];
// 100C010: using guessed type int dword_100C010;
// 100C05C: using guessed type int dword_100C05C;
// 100C078: using guessed type int dword_100C078;
// 100C07C: using guessed type int dword_100C07C;
// 100C084: using guessed type int dword_100C084;

//----- (010023D0) --------------------------------------------------------
#error "10023DB: positive sp value has been found (funcsize=3)"

//----- (01002409) --------------------------------------------------------
BOOL __stdcall sub_1002409(int nWidth, int a2)
{
  int v2; // eax@1
  LPARAM lParam; // [sp+0h] [bp-8h]@3
  int v5; // [sp+4h] [bp-4h]@3

  v2 = *(_DWORD *)&dword_100C02C;
  if ( *(_DWORD *)&dword_100C02C )
  {
    v5 = -1;
    lParam = 3 * nWidth / 4;
    SendMessageW(dword_100C024, 1028u, 2u, (LPARAM)&lParam);
    SendMessageW(dword_100C024, 5u, 0, 0);
    v2 = *(_DWORD *)&dword_100C02C;
  }
  return MoveWindow(dword_100C028, 0, 0, nWidth, a2 - (v2 != 0 ? dword_100C084 : 0), 1);
}
// 100C084: using guessed type int dword_100C084;

//----- (01002456) --------------------------------------------------------
BOOL __stdcall sub_1002456(LPCWSTR lpString1)
{
  WCHAR *v1; // eax@5
  char v2; // zf@5
  HANDLE v4; // edi@7
  va_list Arguments; // [sp+4h] [bp-7CCh]@5
  struct _WIN32_FIND_DATAW FindFileData; // [sp+8h] [bp-7C8h]@7
  WCHAR String; // [sp+258h] [bp-578h]@5
  WCHAR Buf; // [sp+4C4h] [bp-30Ch]@2
  wchar_t Dest[128]; // [sp+6CCh] [bp-104h]@1
  unsigned int v10; // [sp+7CCh] [bp-4h]@1
  int v11; // [sp+7D0h] [bp+0h]@1

  v10 = (unsigned int)&v11 ^ dword_100C010;
  Dest[0] = 0;
  memset(&Dest[1], 0, 0xFEu);
  if ( lstrcmpW(lpString1, lpString2) )
  {
    v4 = FindFirstFileW(lpString1, &FindFileData);
    if ( v4 == (HANDLE)-1 )
    {
      GetFileTitleW(lpString1, &Buf, 0x104u);
    }
    else
    {
      GetFileTitleW(FindFileData.cFileName, &Buf, 0x104u);
      FindClose(v4);
    }
  }
  else
  {
    sub_1002558((int)&Buf, 0x104u, (int)lpString2);
  }
  sub_10015C3(Dest, 0x80u, Format, 1, 1);
  if ( dword_100C024 )
    SendMessageW(dword_100C024, 0x40Bu, 1u, (LPARAM)Dest);
  Arguments = (va_list)&Buf;
  v2 = FormatMessageW(0x2400u, lpSource, 0, 0, &String, 0x136u, &Arguments) == 0;
  v1 = &String;
  if ( v2 )
    v1 = &Buf;
  return SetWindowTextW(hWnd, v1);
}
// 100C010: using guessed type int dword_100C010;

//----- (01002558) --------------------------------------------------------
signed int __stdcall sub_1002558(int a1, unsigned int a2, int a3)
{
  signed int result; // eax@1
  int v4; // eax@4
  signed int v5; // ebx@4
  unsigned int v6; // esi@4
  __int16 v7; // cx@6

  result = 0;
  if ( !a2 || a2 > 0x7FFFFFFF )
    result = -2147024809;
  if ( result >= 0 )
  {
    v4 = a1;
    v5 = 0;
    v6 = a2;
    if ( !a2 )
      goto LABEL_15;
    do
    {
      if ( !(2147483646 - a2 + v6) )
        break;
      v7 = *(_WORD *)(a3 - a1 + v4);
      if ( !v7 )
        break;
      *(_WORD *)v4 = v7;
      v4 += 2;
      --v6;
    }
    while ( v6 );
    if ( !v6 )
    {
LABEL_15:
      v4 -= 2;
      v5 = -2147024774;
    }
    *(_WORD *)v4 = 0;
    result = v5;
  }
  return result;
}

//----- (010025CB) --------------------------------------------------------
int __stdcall sub_10025CB(int a1)
{
  int result; // eax@1

  for ( result = a1; *(_WORD *)result == 32 || *(_WORD *)result == 9; result += 2 )
    ;
  return result;
}

//----- (010025EF) --------------------------------------------------------
signed int __stdcall sub_10025EF(WCHAR **a1)
{
  int ebp0; // ebp@0
  signed int result; // eax@2
  const WCHAR *v3; // eax@4
  DWORD v4; // eax@6
  int v5; // eax@7
  const WCHAR *v6; // [sp-Ch] [bp-1Ch]@9
  int v7; // [sp+Ch] [bp-4h]@1

  v7 = 0;
  if ( sub_1002689(L"/.SETUP", a1) )
    return 0;
  dword_100CCEC = 1;
  hMenu = GetSystemMenu(hWnd, 0);
  hAccTable = LoadAcceleratorsW(hInstance, L"SlipUpAcc");
  SetWindowLongW(hWnd, -16, 16580608);
  v3 = (const WCHAR *)sub_10025CB((int)((char *)a1 + 14));
  if ( !*v3 )
    goto LABEL_20;
  sub_1002C0D((LPWSTR)&FileName, v3, 0x104u);
  hFile = CreateFileW(&FileName, -2147483648u, 3u, 0, 3u, 128u, 0);
  if ( hFile == (HANDLE)-1 )
  {
    v4 = GetLastError() - 2;
    if ( v4 )
    {
      v5 = v4 - 3;
      if ( v5 )
        v6 = (const WCHAR *)(v5 == 118 ? dword_100C2E0 : dword_100C2B0);
      else
        v6 = dword_100C31C;
      v7 = sub_1007051(hWnd, szApp, v6, &FileName, 0x31u);
    }
    else
    {
      v7 = sub_1007051(hWnd, szApp, dword_100C2B4, &FileName, 0x33u);
      if ( v7 == 6 )
        hFile = CreateFileW(&FileName, 0xC0000000u, 3u, 0, 4u, 0x80u, 0);
    }
    if ( hFile == (HANDLE)-1 )
      return 0;
  }
  sub_1002820(ebp0, (int)&FileName, dword_100C05C);
  result = 2;
  if ( v7 != 2 )
LABEL_20:
    result = 6;
  return result;
}
// 100261C: using guessed type wchar_t a_setup[8];
// 100C05C: using guessed type int dword_100C05C;
// 100C2E0: using guessed type int dword_100C2E0;
// 100CCEC: using guessed type int dword_100CCEC;

//----- (01002631) --------------------------------------------------------
int __stdcall sub_1002631(WCHAR **a1, int nCmdShow)
{
  int v3; // eax@4
  const WCHAR *v4; // esi@6
  int v5; // eax@7
  int v6; // eax@8
  int v7; // eax@9
  unsigned int v8; // edx@9
  WCHAR v9; // cx@13
  unsigned int v10; // [sp+8h] [bp-4h]@1

  v10 = 1;
  if ( sub_1002689(L"/PT", a1) )
  {
    if ( sub_1002689(L"/P", a1) )
      return 0;
    v3 = sub_10025CB((int)(a1 + 1));
  }
  else
  {
    v3 = sub_10025CB((int)((char *)a1 + 6));
    v10 = 0;
  }
  v4 = (const WCHAR *)v3;
  if ( *(_WORD *)v3 )
  {
    ShowWindow(hWnd, nCmdShow);
    v5 = (int)(sub_1002C0D((LPWSTR)&FileName, v4, 0x104u) + 1);
    JUMPOUT(v10, 0, *(unsigned int *)sub_10056E3);
    if ( *(_WORD *)v5 )
    {
      v6 = sub_10025CB(v5);
      if ( *(_WORD *)v6 == 34 )
      {
        v7 = v6 + 2;
        v8 = 0;
        while ( 1 )
        {
          v9 = *(_WORD *)v7;
          if ( !*(_WORD *)v7 )
            break;
          if ( v9 == 34 || v8 >= 0xFF )
            break;
          *(&pPrinterName + v8++) = v9;
          v7 += 2;
        }
        *(&pPrinterName + v8) = 0;
        JUMPOUT(*(int *)sub_10056E3);
      }
    }
  }
  return 0;
}
// 1002674: using guessed type wchar_t aP[3];
// 100267C: using guessed type wchar_t aPt[4];

//----- (01002689) --------------------------------------------------------
signed int __userpurge sub_1002689<eax>(unsigned __int16 *a1<eax>, WCHAR **a2)
{
  unsigned __int16 v2; // ax@1
  unsigned __int16 *v3; // ebx@1
  __int16 v4; // di@2
  WCHAR *v5; // eax@2
  signed int result; // eax@3

  v3 = a1;
  v2 = *a1;
  if ( v2 )
  {
    while ( 1 )
    {
      v4 = (unsigned int)CharUpperW((LPWSTR)v2);
      v5 = (WCHAR *)*(_WORD *)a2;
      a2 = (WCHAR **)((char *)a2 + 2);
      ++v3;
      if ( v4 != (unsigned __int16)CharUpperW(v5) )
        break;
      v2 = *v3;
      if ( !*v3 )
        goto LABEL_5;
    }
    result = 1;
  }
  else
  {
LABEL_5:
    result = 0;
  }
  return result;
}

//----- (010026D5) --------------------------------------------------------
signed int __stdcall sub_10026D5(wchar_t *Dest, unsigned int a2)
{
  return sub_10015C3(Dest, a2, L"%s%c*.txt%c%s%c*.*%c", *(_DWORD *)Args, 0, 0, dword_100C308, 0, 0);
}
// 100C308: using guessed type int dword_100C308;

//----- (01002733) --------------------------------------------------------
int __thiscall sub_1002733(int this)
{
  int result; // eax@1
  char v2; // [sp+0h] [bp-1304h]@1
  char v3; // [sp+60h] [bp-12A4h]@1
  unsigned int v4; // [sp+6Ch] [bp-1298h]@1
  unsigned int v5; // [sp+70h] [bp-1294h]@1

  sub_10027F0(0x1320u, this);
  RtlInitUnicodeString(&v2, L"Security-SPP-GenuineLocalStatus");
  result = NtQueryLicenseValue(&v2, &v5, &v4, 4, &v3);
  if ( result >= 0 )
  {
    JUMPOUT(v5, 4u, *(unsigned int *)sub_1005D2A);
    JUMPOUT(v4, 0, *(unsigned int *)sub_1005D2A);
  }
  return result;
}
// 10013E0: using guessed type int __stdcall RtlInitUnicodeString(_DWORD, _DWORD);
// 10013E4: using guessed type int __stdcall NtQueryLicenseValue(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD);
// 10027B0: using guessed type wchar_t aSecuritySppGen[32];

//----- (010027F0) --------------------------------------------------------
int __usercall sub_10027F0<eax>(unsigned int a1<eax>, int a2<ecx>)
{
  unsigned int i; // eax@1
  int v3; // ecx@1
  int v5; // [sp-4h] [bp-4h]@1
  void *v6; // [sp+0h] [bp+0h]@1
  int v7; // [sp+0h] [bp+0h]@4

  v5 = a2;
  v3 = (unsigned int)&v6 >= a1 ? (int)((char *)&v6 - a1) : 0;
  for ( i = (unsigned int)&v5 & 0xFFFFF000; v3 < i; i -= 4096 )
    ;
  return v7;
}

//----- (01002820) --------------------------------------------------------
int __userpurge sub_1002820<eax>(int a1<ebp>, int a2, int a3)
{
  HANDLE v3; // eax@1
  unsigned int v4; // ebx@1
  unsigned int v5; // edi@1
  unsigned int v6; // eax@1
  int v7; // esi@3
  unsigned int v8; // eax@3
  HLOCAL v9; // eax@3
  void *v10; // eax@3
  unsigned __int16 *v11; // eax@5
  unsigned __int16 *v12; // ecx@6
  int v13; // edx@7
  void *v15; // ebx@10
  int v16; // eax@10

  sub_1002B64((int)dword_1002B48, 636);
  *(_DWORD *)(a1 - 568) = *(_DWORD *)(a1 + 8);
  *(_DWORD *)(a1 - 596) = 0;
  *(_DWORD *)(a1 - 580) = 0;
  *(_DWORD *)(a1 - 564) = 0;
  *(_DWORD *)(a1 - 592) = 0;
  *(_DWORD *)(a1 - 560) = 0;
  JUMPOUT((unsigned int)hFile, 0xFFFFFFFFu, *(unsigned int *)sub_10058A7);
  v6 = GetFileInformationByHandle(hFile, (LPBY_HANDLE_FILE_INFORMATION)(a1 - 652));
  v5 = *(_DWORD *)(a1 - 616);
  *(_DWORD *)(a1 - 584) = v5;
  JUMPOUT(v6, 0, *(unsigned int *)loc_10058B2);
  JUMPOUT(v5, 0x40000000u, *(unsigned int *)loc_1005C0C);
  JUMPOUT(*(_DWORD *)(a1 - 620), 0, *(unsigned int *)loc_1005C0C);
  SetCursor(hCursor);
  JUMPOUT(v5, 0, *(unsigned int *)loc_10058BD);
  v4 = 0;
  *(_DWORD *)(a1 - 576) = 0;
  v3 = CreateFileMappingW(hFile, 0, 2u, 0, v5, 0);
  *(_DWORD *)(a1 - 600) = v3;
  if ( v3 )
  {
    v4 = (unsigned int)MapViewOfFile(v3, 4u, 0, 0, v5);
    *(_DWORD *)(a1 - 576) = v4;
    CloseHandle(*(HANDLE *)(a1 - 600));
  }
  CloseHandle(hFile);
  hFile = (HANDLE)-1;
  JUMPOUT(v4, 0, *(unsigned int *)loc_10058D7);
  *(_DWORD *)(a1 - 4) = 0;
  *(_DWORD *)(a1 - 572) = v4;
  JUMPOUT(*(_DWORD *)(a1 + 12), 0xFFFFFFFFu, *(unsigned int *)loc_1005A43);
  v8 = *(_WORD *)v4;
  JUMPOUT(v8, 0xBBEFu, *(unsigned int *)loc_100590F);
  JUMPOUT(v8, 0xFEFFu, *(unsigned int *)loc_10058EB);
  *(_DWORD *)(a1 - 564) = 1;
  *(_DWORD *)(a1 - 556) = 1;
  v7 = (v5 >> 1) - 1;
  *(_DWORD *)(a1 - 552) = v7;
  JUMPOUT(*(_DWORD *)(a1 - 564), 0, *(unsigned int *)loc_1005951);
  SendMessageW(dword_100C028, 11u, 0, 0);
  SendMessageW(dword_100C028, 0xB1u, 0, 0);
  SendMessageW(dword_100C028, 0xB7u, 0, 0);
  v9 = LocalReAlloc(hMem, 2 * v7 + 2, 2u);
  *(_DWORD *)(a1 - 592) = v9;
  JUMPOUT((unsigned int)v9, 0, *(unsigned int *)loc_1005976);
  v10 = LocalLock(v9);
  *(_DWORD *)(a1 - 596) = v10;
  JUMPOUT(*(_DWORD *)(a1 - 564), 0, *(unsigned int *)loc_1005AEB);
  JUMPOUT(*(_WORD *)v4, 0xFEFFu, *(unsigned int *)loc_1005AC7);
  memcpy(v10, (const void *)(v4 + 2), 2 * v7);
  dword_100C00C = *(_DWORD *)(a1 - 556);
  *(_DWORD *)(a1 - 4) = -2;
  if ( v4 != a1 - 588 )
    UnmapViewOfFile((LPCVOID)v4);
  v11 = *(unsigned __int16 **)(a1 - 596);
  if ( v11 )
  {
    v12 = *(unsigned __int16 **)(a1 - 596);
    if ( v5 >> 1 != 1 )
    {
      v13 = (v5 >> 1) - 1;
      do
      {
        JUMPOUT(*v12, 0, *(unsigned int *)loc_1005B5A);
        ++v12;
        --v13;
      }
      while ( v13 );
    }
    v11[v7] = 0;
    JUMPOUT(*v11, 0x2Eu, *(unsigned int *)loc_1005B65);
    *(_DWORD *)(a1 - 580) = 0;
  }
  v15 = *(void **)(a1 - 592);
  LocalUnlock(*(HLOCAL *)(a1 - 592));
  hMem = v15;
  sub_1002558((int)&FileName, 0x104u, *(_DWORD *)(a1 - 568));
  sub_1002456(*(LPCWSTR *)(a1 - 568));
  dword_100C008 = 0;
  dword_100C030 = 1;
  SendMessageW(dword_100C028, 0xBCu, (WPARAM)hMem, 0);
  JUMPOUT(dword_100C030, 2u, *(unsigned int *)loc_1005B9C);
  dword_100C030 = 0;
  PostMessageW(dword_100C028, 0xC5u, 0, 0);
  JUMPOUT(*(_DWORD *)(a1 - 580), 0, *(unsigned int *)loc_1005BE2);
  v16 = SendMessageW(dword_100C028, 0x115u, 0xBEu, 0);
  SetScrollPos(hWnd, 1, v16, 1);
  SendMessageW(dword_100C028, 0xBu, 1u, 0);
  InvalidateRect(dword_100C028, 0, 1);
  UpdateWindow(dword_100C028);
  SetCursor(dword_100C094);
  return sub_1001A72(a1);
}
// 1002B48: using guessed type int dword_1002B48[2];
// 10058B2: using guessed type int __stdcall loc_10058B2(int, int);
// 10058BD: using guessed type int __stdcall loc_10058BD(int, int);
// 10058D7: using guessed type int __stdcall loc_10058D7(int, int);
// 10058EB: using guessed type int __stdcall loc_10058EB(int, int);
// 100590F: using guessed type int __stdcall loc_100590F(int, int);
// 1005951: using guessed type int __stdcall loc_1005951(int, int);
// 1005976: using guessed type int __stdcall loc_1005976(int, int);
// 1005A43: using guessed type int __stdcall loc_1005A43(int, int);
// 1005AC7: using guessed type int __stdcall loc_1005AC7(int, int);
// 1005AEB: using guessed type int __stdcall loc_1005AEB(int, int);
// 1005B5A: using guessed type int __stdcall loc_1005B5A(int, int);
// 1005B65: using guessed type int __stdcall loc_1005B65(int, int);
// 1005B9C: using guessed type int __stdcall loc_1005B9C(int, int);
// 1005BE2: using guessed type int __stdcall loc_1005BE2(int, int);
// 1005C0C: using guessed type int __stdcall loc_1005C0C(int, int);
// 100C008: using guessed type int dword_100C008;
// 100C00C: using guessed type int dword_100C00C;
// 100C030: using guessed type int dword_100C030;

//----- (01002B64) --------------------------------------------------------
char *__cdecl sub_1002B64(int a1, int a2)
{
  void *v3; // esp@1
  char v4; // [sp-8h] [bp-8h]@1

  v3 = alloca(a2);
  return &v4;
}

//----- (01002C0D) --------------------------------------------------------
LPCWSTR __stdcall sub_1002C0D(LPWSTR lpBuffer, LPCWSTR lpFileName, DWORD nBufferLength)
{
  LPCWSTR v3; // ebx@1
  LPCWSTR v4; // esi@1
  HANDLE v5; // eax@5
  const WCHAR v7; // dx@10
  unsigned int i; // ecx@10
  __int16 v9; // ax@14
  struct _WIN32_FIND_DATAW FindFileData; // [sp+Ch] [bp-45Ch]@5
  __int16 v11[260]; // [sp+25Ch] [bp-20Ch]@13
  unsigned int v12; // [sp+464h] [bp-4h]@1
  int v13; // [sp+468h] [bp+0h]@1

  v12 = (unsigned int)&v13 ^ dword_100C010;
  v4 = lpFileName;
  v3 = lpFileName;
  if ( *lpFileName == 34 || *lpFileName == 39 )
  {
    v7 = *lpFileName;
    for ( i = 0; ; ++i )
    {
      ++v4;
      v9 = *v4;
      if ( !*v4 )
        break;
      if ( v9 == v7 || i >= 0x103 )
        break;
      v11[i] = v9;
    }
    v3 = v4;
    v11[i] = 0;
    v4 = (LPCWSTR)v11;
  }
  if ( PathIsFileSpecW(v4) )
    sub_1002558((int)lpBuffer, nBufferLength, (int)v4);
  else
    GetFullPathNameW(v4, nBufferLength, lpBuffer, 0);
  v5 = FindFirstFileW(lpBuffer, &FindFileData);
  if ( v5 != (HANDLE)-1
    || (sub_10080E4((int)lpBuffer, nBufferLength), v5 = FindFirstFileW(lpBuffer, &FindFileData), v5 != (HANDLE)-1) )
    FindClose(v5);
  return v3;
}
// 100C010: using guessed type int dword_100C010;
// 1002C0D: using guessed type __int16 var_20C[260];

//----- (01002F8B) --------------------------------------------------------
LONG __thiscall sub_1002F8B(void *this)
{
  LONG result; // eax@2
  int LCData; // [sp+0h] [bp-4h]@1

  LCData = (int)this;
  stru_100C140.lpfnPageSetupHook = (LPPAGESETUPHOOK)sub_1004240;
  stru_100C140.lpPageSetupTemplateName = (LPCWSTR)12;
  GetLocaleInfoW(0x400u, 0xDu, (LPWSTR)&LCData, 2);
  if ( (_WORD)LCData == 49 )
  {
    stru_100C140.rtMargin.top = 1000;
    stru_100C140.rtMargin.bottom = 1000;
    stru_100C140.Flags = 40966;
    result = 750;
  }
  else
  {
    stru_100C140.rtMargin.top = 2500;
    stru_100C140.rtMargin.bottom = 2500;
    stru_100C140.Flags = 40970;
    result = 2000;
  }
  stru_100C140.rtMargin.right = result;
  stru_100C140.rtMargin.left = result;
  return result;
}

//----- (0100304B) --------------------------------------------------------
int __cdecl sub_100304B()
{
  return 0;
}

//----- (01003053) --------------------------------------------------------
DWORD __cdecl sub_1003053()
{
  DWORD result; // eax@2
  DWORD v1; // esi@2
  DWORD v2; // esi@2
  DWORD v3; // esi@2
  DWORD v4; // esi@2
  LARGE_INTEGER PerformanceCount; // [sp+8h] [bp-10h]@2
  struct _FILETIME SystemTimeAsFileTime; // [sp+10h] [bp-8h]@1

  SystemTimeAsFileTime.dwLowDateTime = 0;
  SystemTimeAsFileTime.dwHighDateTime = 0;
  if ( dword_100C010 != -1153374642 && dword_100C010 & 0xFFFF0000 )
  {
    result = ~dword_100C010;
    dword_100C014 = ~dword_100C010;
  }
  else
  {
    GetSystemTimeAsFileTime(&SystemTimeAsFileTime);
    v2 = GetCurrentProcessId() ^ SystemTimeAsFileTime.dwLowDateTime ^ SystemTimeAsFileTime.dwHighDateTime;
    v3 = GetCurrentThreadId() ^ v2;
    v4 = GetTickCount() ^ v3;
    QueryPerformanceCounter(&PerformanceCount);
    result = PerformanceCount.LowPart ^ PerformanceCount.HighPart;
    v1 = PerformanceCount.LowPart ^ PerformanceCount.HighPart ^ v4;
    if ( v1 == -1153374642 || !(dword_100C010 & 0xFFFF0000) )
      v1 = -1153374641;
    dword_100C010 = v1;
    dword_100C014 = ~v1;
  }
  return result;
}
// 100C010: using guessed type int dword_100C010;
// 100C014: using guessed type int dword_100C014;

//----- (010030E2) --------------------------------------------------------
LSTATUS __cdecl sub_10030E2()
{
  LSTATUS result; // eax@4
  int v1; // [sp+Ch] [bp-B0h]@1
  HKEY Type; // [sp+10h] [bp-ACh]@2
  HKEY hKey; // [sp+14h] [bp-A8h]@1
  char Dst; // [sp+1Ch] [bp-A0h]@1
  int v5; // [sp+20h] [bp-9Ch]@2
  int v6; // [sp+24h] [bp-98h]@2
  int v7; // [sp+28h] [bp-94h]@2
  unsigned __int8 v8; // [sp+2Ch] [bp-90h]@2
  unsigned __int8 v9; // [sp+2Dh] [bp-8Fh]@2
  unsigned __int8 v10; // [sp+2Eh] [bp-8Eh]@2
  unsigned __int8 v11; // [sp+2Fh] [bp-8Dh]@2
  unsigned __int8 v12; // [sp+30h] [bp-8Ch]@2
  unsigned __int8 v13; // [sp+31h] [bp-8Bh]@2
  unsigned __int8 v14; // [sp+32h] [bp-8Ah]@2
  unsigned __int8 v15; // [sp+33h] [bp-89h]@2
  char Src; // [sp+74h] [bp-48h]@1
  wchar_t v17; // [sp+90h] [bp-2Ch]@1
  char v18; // [sp+92h] [bp-2Ah]@1
  unsigned int v19; // [sp+B8h] [bp-4h]@1
  int v20; // [sp+BCh] [bp+0h]@1

  v19 = (unsigned int)&v20 ^ dword_100C010;
  memset(&Dst, 0, 0x58u);
  memcpy(&Src, L"Lucida Console", 0x1Cu);
  v17 = aLucidaConsole[14];
  memset(&v18, 0, 0x24u);
  v1 = 100;
  if ( RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Notepad", 0, 0x20019u, &hKey) )
    hKey = 0;
  lf.lfWidth = 0;
  lf.lfEscapement = sub_100355B(hKey, L"lfEscapement", v5);
  lf.lfOrientation = sub_100355B(hKey, L"lfOrientation", v6);
  lf.lfWeight = sub_100355B(hKey, L"lfWeight", v7);
  lf.lfItalic = sub_100355B(hKey, L"lfItalic", v8);
  lf.lfUnderline = sub_100355B(hKey, L"lfUnderline", v9);
  lf.lfStrikeOut = sub_100355B(hKey, L"lfStrikeOut", v10);
  lf.lfCharSet = sub_100355B(hKey, L"lfCharSet", v11);
  lf.lfOutPrecision = sub_100355B(hKey, L"lfOutPrecision", v12);
  lf.lfClipPrecision = sub_100355B(hKey, L"lfClipPrecision", v13);
  lf.lfQuality = sub_100355B(hKey, L"lfQuality", v14);
  lf.lfPitchAndFamily = sub_100355B(hKey, L"lfPitchAndFamily", v15);
  if ( !RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Notepad\\DefaultFonts", 0, 0x20019u, &Type) )
  {
    sub_10035B0(Type, L"lfFaceName", L"Lucida Console", &Src, 0x20u);
    v1 = sub_100355B(Type, L"iPointSize", 100);
    RegCloseKey(Type);
  }
  sub_10035B0(hKey, L"lfFaceName", &Src, lf.lfFaceName, 0x20u);
  *(_DWORD *)&Data = sub_100355B(hKey, L"iPointSize", v1);
  wParam = sub_100355B(hKey, L"fWrap", 0);
  *(_DWORD *)&dword_100C02C = sub_100355B(hKey, L"StatusBar", 0);
  dword_100C060 = sub_100355B(hKey, L"fSaveWindowPositions", 0);
  sub_10035B0(hKey, L"szHeader", &word_100C740, (void *)&word_100C740, 0x28u);
  sub_10035B0(hKey, L"szTrailer", &::Dst, &::Dst, 0x28u);
  stru_100C140.rtMargin.top = sub_100355B(hKey, L"iMarginTop", stru_100C140.rtMargin.top);
  stru_100C140.rtMargin.bottom = sub_100355B(hKey, L"iMarginBottom", stru_100C140.rtMargin.bottom);
  stru_100C140.rtMargin.left = sub_100355B(hKey, L"iMarginLeft", stru_100C140.rtMargin.left);
  stru_100C140.rtMargin.right = sub_100355B(hKey, L"iMarginRight", stru_100C140.rtMargin.right);
  Y = sub_100355B(hKey, L"iWindowPosY", -2147483648);
  X = sub_100355B(hKey, L"iWindowPosX", -2147483648);
  nWidth = sub_100355B(hKey, L"iWindowPosDX", -2147483648);
  nHeight = sub_100355B(hKey, L"iWindowPosDY", -2147483648);
  result = sub_100355B(hKey, L"fMLE_is_broken", 0);
  dword_100C040 = result;
  if ( hKey )
    result = RegCloseKey(hKey);
  return result;
}
// 1003538: using guessed type wchar_t aLucidaConsole[15];
// 100C010: using guessed type int dword_100C010;
// 100C040: using guessed type int dword_100C040;
// 100C060: using guessed type int dword_100C060;

//----- (0100355B) --------------------------------------------------------
int __stdcall sub_100355B(HKEY hKey, LPCWSTR lpValueName, int a3)
{
  int result; // eax@4
  DWORD cbData; // [sp+0h] [bp-Ch]@1
  BYTE Data[4]; // [sp+4h] [bp-8h]@1
  DWORD Type; // [sp+8h] [bp-4h]@1

  Type = 0;
  *(_DWORD *)Data = 1;
  cbData = 4;
  if ( !hKey || RegQueryValueExW(hKey, lpValueName, 0, &Type, Data, &cbData) || Type != 4 )
    result = a3;
  else
    result = *(_DWORD *)Data;
  return result;
}

//----- (010035B0) --------------------------------------------------------
__int32 __stdcall sub_10035B0(HKEY Type, LPCWSTR lpValueName, const void *Src, void *Dst, DWORD cbData)
{
  size_t v5; // esi@1
  __int32 result; // eax@2

  v5 = 2 * cbData;
  cbData *= 2;
  if ( !Type
    || (result = RegQueryValueExW(Type, lpValueName, 0, (LPDWORD)&Type, (LPBYTE)Dst, &cbData)) != 0
    || Type != (HKEY)1 )
    result = (__int32)memcpy(Dst, Src, v5);
  return result;
}

//----- (0100360C) --------------------------------------------------------
const WCHAR *__cdecl sub_100360C(LPCWSTR lpsz)
{
  const WCHAR *result; // eax@1
  const WCHAR v2; // cx@1
  bool i; // esi@1

  result = lpsz;
  v2 = *lpsz;
  for ( i = 0; *result; v2 = *result )
  {
    if ( (v2 == 32 || v2 == 9) && !i )
      break;
    if ( v2 == 34 )
      i = i == 0;
    result = CharNextW(result);
  }
  while ( *result == 32 || *result == 9 )
    ++result;
  return result;
}

//----- (01003660) --------------------------------------------------------
int __cdecl sub_1003660(unsigned int a1, unsigned int a2)
{
  int result; // eax@1
  unsigned int v3; // esi@1

  v3 = a1;
  result = 0;
  while ( v3 < a2 && !result )
  {
    if ( *(_DWORD *)v3 )
      result = (*(int (**)(void))v3)();
    v3 += 4;
  }
  return result;
}

//----- (01003689) --------------------------------------------------------
int __usercall start<eax>(int a1<ebp>)
{
  int v1; // eax@23
  signed int v2; // ebx@1
  LONG v3; // esi@1
  LONG v4; // eax@2
  signed int v5; // esi@3
  void *i; // esi@12
  unsigned __int8 v7; // al@13

  sub_1003053();
  sub_1003B0C((int)dword_10037A0, 88);
  v2 = 0;
  *(_DWORD *)(a1 - 28) = 0;
  *(_DWORD *)(a1 - 4) = 0;
  GetStartupInfoA((LPSTARTUPINFOA)(a1 - 104));
  *(_DWORD *)(a1 - 4) = -2;
  *(_DWORD *)(a1 - 4) = 1;
  v3 = *(_DWORD *)(*MK_FP(__FS__, 24) + 4);
  while ( 1 )
  {
    v4 = InterlockedCompareExchange(&Destination, v3, 0);
    if ( !v4 )
    {
      v5 = 1;
      goto LABEL_4;
    }
    if ( v4 == v3 )
      break;
    Sleep(0x3E8u);
  }
  v5 = 1;
  v2 = 1;
LABEL_4:
  if ( dword_100C0A4 == v5 )
  {
    amsg_exit(31);
  }
  else
  {
    if ( dword_100C0A4 )
    {
      dword_100D7A8 = v5;
    }
    else
    {
      dword_100C0A4 = v5;
      if ( sub_1003660((unsigned int)dword_1003790, (unsigned int)dword_100379C) )
      {
        *(_DWORD *)(a1 - 4) = -2;
        return sub_10023D0(a1);
      }
    }
  }
  if ( dword_100C0A4 == v5 )
  {
    initterm(dword_1003784, dword_100378C);
    dword_100C0A4 = 2;
  }
  if ( !v2 )
    InterlockedExchange(&Destination, 0);
  if ( dword_100CD0C )
  {
    if ( sub_1009E73(a1) )
      dword_100CD0C(&dword_100CD0C);
  }
  for ( i = acmdln; ; i = (char *)i + 1 )
  {
    *(_DWORD *)(a1 - 32) = i;
    v7 = *(_BYTE *)i;
    if ( *(_BYTE *)i <= 0x20u )
    {
      if ( !v7 || !*(_DWORD *)(a1 - 28) )
        break;
    }
    if ( v7 == 34 )
      *(_DWORD *)(a1 - 28) = *(_DWORD *)(a1 - 28) == 0;
    if ( ismbblead(v7) )
    {
      i = (char *)i + 1;
      *(_DWORD *)(a1 - 32) = i;
    }
  }
  while ( *(_BYTE *)i && *(_BYTE *)i <= 0x20u )
  {
    i = (char *)i + 1;
    *(_DWORD *)(a1 - 32) = i;
  }
  *(_BYTE *)(a1 - 60) & 1;
  v1 = sub_1001405((HINSTANCE)0x1000000);
  dword_100C070 = v1;
  if ( !dword_100C064 )
    exit(v1);
  if ( !dword_100D7A8 )
    cexit();
  *(_DWORD *)(a1 - 4) = -2;
  return sub_10023D0(a1);
}
// 1001310: using guessed type void *acmdln;
// 1001318: using guessed type int __cdecl ismbblead(_DWORD);
// 1001324: using guessed type int cexit(void);
// 10023D0: using guessed type _DWORD __usercall sub_10023D0<eax>(_DWORD ebp0<ebp>);
// 1003040: using guessed type int __cdecl initterm(_DWORD, _DWORD);
// 1003784: using guessed type int dword_1003784();
// 100378C: using guessed type int dword_100378C();
// 1003790: using guessed type int dword_1003790();
// 100379C: using guessed type int dword_100379C();
// 10037A0: using guessed type int dword_10037A0();
// 1009F01: using guessed type int __cdecl amsg_exit(_DWORD);
// 100C064: using guessed type int dword_100C064;
// 100C070: using guessed type int dword_100C070;
// 100C0A4: using guessed type int dword_100C0A4;
// 100CD0C: using guessed type int (__thiscall *dword_100CD0C)(_DWORD);
// 100D7A8: using guessed type int dword_100D7A8;

//----- (010037EF) --------------------------------------------------------
ATOM __usercall sub_10037EF<ax>(HINSTANCE a1<esi>)
{
  WNDCLASSEXW v2; // [sp+0h] [bp-30h]@1

  memset(&v2.style, 0, 0x2Cu);
  v2.cbSize = 48;
  v2.hCursor = LoadCursorW(0, (LPCWSTR)0x7F01);
  v2.hIcon = LoadIconW(a1, (LPCWSTR)2);
  v2.hIconSm = LoadImageW(a1, (LPCWSTR)2, 1u, 16, 16, 0);
  v2.lpszMenuName = (LPCWSTR)1;
  v2.hInstance = a1;
  v2.lpszClassName = L"Notepad";
  v2.lpfnWndProc = (WNDPROC)sub_10014DE;
  v2.hbrBackground = (HBRUSH)6;
  return RegisterClassExW(&v2);
}

//----- (01003881) --------------------------------------------------------
HLOCAL __stdcall sub_1003881(HINSTANCE hInstance)
{
  HLOCAL result; // eax@1
  WCHAR *v2; // esi@2
  int v3; // ebx@3
  UINT **v4; // edi@4
  int v5; // eax@5

  result = (HLOCAL)sub_100392D(hInstance);
  if ( result )
  {
    result = LocalAlloc(0x40u, 2 * (_DWORD)result);
    v2 = (WCHAR *)result;
    if ( result )
    {
      v3 = LocalSize(result) >> 1;
      if ( v3 )
      {
        v4 = (UINT **)off_100C920;
        while ( 1 )
        {
          v5 = LoadStringW(hInstance, **v4, v2, v3) + 1;
          **v4 = (UINT)v2;
          v2 += v5;
          if ( v5 > v3 )
            break;
          ++v4;
          v3 -= v5;
          if ( (signed int)v4 >= (signed int)&unk_100C9DC )
          {
            sub_1002558((int)&word_100C740, 0x28u, dword_100C2F8);
            sub_1002558((int)&Dst, 0x28u, dword_100C2FC);
            word_100C000 = *(_WORD *)dword_100C2F0;
            return (HLOCAL)1;
          }
        }
        result = 0;
      }
      else
      {
        result = 0;
      }
    }
  }
  return result;
}
// 100C000: using guessed type __int16 word_100C000;
// 100C2F0: using guessed type int dword_100C2F0;
// 100C2F8: using guessed type int dword_100C2F8;
// 100C2FC: using guessed type int dword_100C2FC;
// 100C920: using guessed type int off_100C920[2];

//----- (0100392D) --------------------------------------------------------
int __stdcall sub_100392D(HINSTANCE hInstance)
{
  int v1; // esi@1
  int v2; // ebx@3
  signed int v3; // edi@3
  int v4; // eax@4
  SIZE_T i; // [sp-4h] [bp-14h]@1
  WCHAR *v7; // [sp+Ch] [bp-4h]@2

  v1 = 280;
  for ( i = 560; ; i = 2 * v1 )
  {
    v7 = (WCHAR *)LocalAlloc(0x40u, i);
    if ( !v7 )
      break;
    v3 = 0;
    v2 = 0;
    do
    {
      v4 = LoadStringW(hInstance, *(_DWORD *)off_100C920[v3], v7, v1);
      if ( v4 >= v1 - 1 )
        break;
      ++v3;
      v2 += v4 + 1;
    }
    while ( v3 < 47 );
    LocalFree(v7);
    if ( v3 >= 47 )
      return v2;
    v1 *= 2;
  }
  return 0;
}
// 100C920: using guessed type int off_100C920[2];

//----- (01003A48) --------------------------------------------------------
unsigned int __cdecl sub_1003A48()
{
  return controlfp(0x10000u, 0x30000u);
}

//----- (01003A60) --------------------------------------------------------
signed int __cdecl sub_1003A60(signed int a1)
{
  int v1; // eax@1
  int ebp0; // ebp@0
  int v3; // eax@2
  __int16 v4; // ax@3
  signed int result; // eax@4

  v1 = (int)GetModuleHandleA(0);
  if ( !v1 || (v3 = sub_1003A98(ebp0, v1), !v3) )
    goto LABEL_10;
  v4 = *(_WORD *)(v3 + 92);
  if ( v4 == 2 )
    return 2;
  if ( v4 == 3 )
    result = 1;
  else
LABEL_10:
    result = a1;
  return result;
}

//----- (01003A98) --------------------------------------------------------
int __userpurge sub_1003A98<eax>(int a1<ebp>, int a2)
{
  int v2; // ecx@1
  unsigned int v3; // edx@4

  sub_1003B0C((int)dword_1003AF0, 12);
  v2 = *(_DWORD *)(a1 + 8);
  if ( v2 )
  {
    if ( v2 != -1 )
    {
      *(_DWORD *)(a1 - 4) = 0;
      if ( *(_WORD *)v2 == 23117 )
      {
        v3 = *(_DWORD *)(v2 + 60);
        if ( (signed int)v3 >= 0 )
        {
          if ( v3 < 0x10000000 )
          {
            *(_DWORD *)(a1 - 28) = v3 + v2;
            if ( *(_DWORD *)(v3 + v2) != 17744 )
              *(_DWORD *)(a1 - 28) = 0;
          }
        }
      }
      *(_DWORD *)(a1 - 4) = -2;
    }
  }
  return sub_10023D0(a1);
}
// 10023D0: using guessed type _DWORD __usercall sub_10023D0<eax>(_DWORD ebp0<ebp>);
// 1003AF0: using guessed type int dword_1003AF0[2];

//----- (01003B0C) --------------------------------------------------------
char *__cdecl sub_1003B0C(int a1, int a2)
{
  void *v3; // esp@1
  char v4; // [sp-8h] [bp-8h]@1

  v3 = alloca(a2);
  return &v4;
}

//----- (01003BCD) --------------------------------------------------------
int __stdcall sub_1003BCD(int a1, int a2, int a3, int a4)
{
  int v4; // edi@1
  int v5; // esi@1

  v5 = a2;
  v4 = (*(int (__stdcall **)(int, int))(*(_DWORD *)a2 + 68))(a2, a3);
  if ( v4 >= 0 )
  {
    v4 = (*(int (__stdcall **)(int, _DWORD))(*(_DWORD *)v5 + 88))(v5, L"txt");
    if ( v4 >= 0 )
    {
      v4 = sub_1003D1B(v5);
      if ( v4 >= 0 )
      {
        v4 = (*(int (__stdcall **)(int, int *))(*(_DWORD *)v5 + 40))(v5, &a3);
        if ( v4 >= 0 )
        {
          v4 = (*(int (__stdcall **)(int, int))(*(_DWORD *)v5 + 36))(v5, a3 | 0x40);
          if ( v4 >= 0 )
          {
            v4 = (*(int (__stdcall **)(int, int))(*(_DWORD *)v5 + 12))(v5, a1);
            if ( v4 >= 0 )
            {
              v4 = (*(int (__stdcall **)(int, int *))(*(_DWORD *)v5 + 80))(v5, &a2);
              if ( v4 >= 0 )
              {
                v4 = (*(int (__stdcall **)(int, signed int, int))(*(_DWORD *)a2 + 20))(a2, -2147123200, a4);
                (*(void (__stdcall **)(int))(*(_DWORD *)a2 + 8))(a2);
              }
            }
          }
        }
      }
    }
  }
  return v4;
}
// 1003C6C: using guessed type wchar_t aTxt[4];

//----- (01003C46) --------------------------------------------------------
int __stdcall sub_1003C46(int a1)
{
  int result; // eax@3

  if ( a1 == -2147024882 )
    result = MessageBoxW(hWnd, lpText, szApp, 0x1010u);
  return result;
}

//----- (01003C61) --------------------------------------------------------
signed int __stdcall sub_1003C61(int a1, int a2)
{
  return -2147467263;
}

//----- (01003C89) --------------------------------------------------------
int __userpurge sub_1003C89<eax>(int a1<ebx>, int a2)
{
  int v2; // edi@1

  v2 = (*(int (__stdcall **)(int, signed int, int))(*(_DWORD *)a2 + 104))(a2, 2, dword_100C368);
  if ( v2 >= 0 )
  {
    v2 = (*(int (__stdcall **)(int, signed int, int))(*(_DWORD *)a2 + 24))(a2, 1, a1);
    if ( v2 >= 0 )
    {
      v2 = (*(int (__stdcall **)(int, signed int, _DWORD, LPARAM))(*(_DWORD *)a2 + 76))(a2, 1, 0, dword_100C334);
      if ( v2 >= 0 )
      {
        v2 = (*(int (__stdcall **)(int, signed int, signed int, LPARAM))(*(_DWORD *)a2 + 76))(a2, 1, 1, dword_100C338);
        if ( v2 >= 0 )
        {
          v2 = (*(int (__stdcall **)(_DWORD, _DWORD, signed int, LPARAM))(*(_DWORD *)a2 + 76))(a2, 1, 2, dword_100C33C);
          if ( v2 >= 0 )
            v2 = (*(int (__stdcall **)(_DWORD, _DWORD, signed int, LPARAM))(*(_DWORD *)a2 + 76))(
                   a2,
                   1,
                   3,
                   dword_100C340);
        }
      }
    }
    (*(void (__cdecl **)(int))(*(_DWORD *)a2 + 108))(a2);
  }
  return v2;
}
// 1003C89: could not find valid save-restore pair for ebx
// 100C368: using guessed type int dword_100C368;

//----- (01003D1B) --------------------------------------------------------
int __stdcall sub_1003D1B(int a1)
{
  int v2; // ecx@1
  int v3; // [sp+0h] [bp-10h]@1
  int v4; // [sp+4h] [bp-Ch]@1
  int v5; // [sp+8h] [bp-8h]@1
  int v6; // [sp+Ch] [bp-4h]@1

  v3 = *(_DWORD *)Args;
  v5 = dword_100C308;
  v2 = *(_DWORD *)a1;
  v4 = (int)L"*.txt";
  v6 = (int)L"*.*";
  return (*(int (__stdcall **)(int, signed int, int *))(v2 + 16))(a1, 2, &v3);
}
// 1003D54: using guessed type wchar_t a_[4];
// 100C308: using guessed type int dword_100C308;

//----- (01003D6D) --------------------------------------------------------
int __stdcall sub_1003D6D(int a1, LPCWSTR pszPath, int a3, int a4)
{
  int v4; // esi@1
  LPVOID v6; // eax@12
  int v7; // [sp+Ch] [bp-8h]@2
  LPVOID ppv; // [sp+10h] [bp-4h]@1

  ppv = 0;
  v4 = CoCreateInstance(&rclsid, 0, 1u, &riid, &ppv);
  if ( v4 >= 0 )
  {
    *(_DWORD *)a3 = 0;
    v7 = 0;
    dword_100C038 = 1;
    (*(void (__stdcall **)(LPVOID, _DWORD, _DWORD))(*(_DWORD *)ppv + 116))(ppv, 0, 0);
    v4 = (**(int (__stdcall ***)(LPVOID, _DWORD, int *))ppv)(ppv, dword_1003C74, &v7);
    if ( v4 >= 0 )
    {
      v4 = sub_1003C89(1, v7);
      if ( v4 >= 0 )
      {
        v4 = (*(int (__stdcall **)(int, signed int, int))(*(_DWORD *)v7 + 100))(
               v7,
               1,
               dword_100C00C != -1 ? dword_100C00C : 0);
        if ( v4 >= 0 )
        {
          sub_1003E75((int)ppv, pszPath);
          v4 = sub_1003BCD(a1, (int)ppv, dword_100C310, a3);
          if ( v4 >= 0 )
          {
            v4 = (*(int (__stdcall **)(int, signed int, int *))(*(_DWORD *)v7 + 96))(v7, 1, &a3);
            if ( v4 >= 0 )
              dword_100E040 = a3;
          }
        }
      }
      (*(void (__stdcall **)(int))(*(_DWORD *)v7 + 8))(v7);
      if ( v4 >= 0 )
      {
        if ( a4 )
        {
          v6 = ppv;
          *(_DWORD *)a4 = ppv;
          (*(void (__stdcall **)(LPVOID))(*(_DWORD *)v6 + 4))(v6);
        }
      }
    }
    (*(void (__stdcall **)(LPVOID))(*(_DWORD *)ppv + 8))(ppv);
    dword_100C038 = 0;
  }
  return v4;
}
// 1003C74: using guessed type int dword_1003C74[5];
// 100C00C: using guessed type int dword_100C00C;
// 100C038: using guessed type int dword_100C038;
// 100C310: using guessed type int dword_100C310;
// 100E040: using guessed type int dword_100E040;

//----- (01003E75) --------------------------------------------------------
int __stdcall sub_1003E75(int a1, LPCWSTR pszPath)
{
  int v2; // esi@2

  if ( PathIsFileSpecW(pszPath) )
  {
    v2 = (*(int (__stdcall **)(int, LPCWSTR))(*(_DWORD *)a1 + 60))(a1, pszPath);
  }
  else
  {
    v2 = SHCreateItemFromParsingName(pszPath, 0, dword_1004AF0, &pszPath);
    if ( v2 >= 0 )
    {
      v2 = (*(int (__stdcall **)(int, LPCWSTR))(*(_DWORD *)a1 + 108))(a1, pszPath);
      (*(void (__stdcall **)(LPCWSTR))(*(_DWORD *)pszPath + 8))(pszPath);
    }
  }
  return v2;
}
// 100136C: using guessed type int __stdcall SHCreateItemFromParsingName(_DWORD, _DWORD, _DWORD, _DWORD);
// 1004AF0: using guessed type int dword_1004AF0[4];

//----- (01003EA6) --------------------------------------------------------
LONG __stdcall sub_1003EA6(int a1)
{
  LONG v1; // edi@1

  v1 = InterlockedDecrement((volatile LONG *)(a1 + 8));
  if ( !v1 )
    LocalFree((HLOCAL)a1);
  return v1;
}

//----- (01003F21) --------------------------------------------------------
int __userpurge sub_1003F21<eax>(int a1<ebx>, int a2, int a3)
{
  int v3; // esi@1
  int v5; // [sp+4h] [bp-10h]@6
  int v6; // [sp+8h] [bp-Ch]@5
  int v7; // [sp+Ch] [bp-8h]@2
  LPVOID ppv; // [sp+10h] [bp-4h]@1

  ppv = 0;
  v3 = CoCreateInstance(&stru_100401C, 0, 1u, &stru_100400C, &ppv);
  if ( v3 >= 0 )
  {
    v7 = 0;
    v3 = (**(int (__stdcall ***)(LPVOID, _DWORD, int *))ppv)(ppv, dword_1003C74, &v7);
    if ( v3 >= 0 )
    {
      v3 = sub_1003C89(a1, v7);
      if ( v3 >= 0 )
      {
        v3 = (*(int (__stdcall **)(int, signed int, int))(*(_DWORD *)v7 + 100))(
               v7,
               1,
               dword_100C00C != -1 ? dword_100C00C : 0);
        if ( v3 >= 0 )
        {
          v3 = sub_100405A((int)sub_1004038, (int)&v6);
          if ( v3 >= 0 )
          {
            v3 = (*(int (__stdcall **)(LPVOID, int, int *))(*(_DWORD *)ppv + 28))(ppv, v6, &v5);
            if ( v3 >= 0 )
            {
              v3 = sub_1003BCD(a2, (int)ppv, dword_100C30C, a3);
              (*(void (__stdcall **)(LPVOID, int))(*(_DWORD *)ppv + 32))(ppv, v5);
            }
            (*(void (__stdcall **)(int))(*(_DWORD *)v6 + 8))(v6);
          }
        }
      }
      (*(void (__stdcall **)(int))(*(_DWORD *)v7 + 8))(v7);
    }
    (*(void (__stdcall **)(LPVOID))(*(_DWORD *)ppv + 8))(ppv);
  }
  return v3;
}
// 1003C74: using guessed type int dword_1003C74[5];
// 100C00C: using guessed type int dword_100C00C;
// 100C30C: using guessed type int dword_100C30C;

//----- (01004038) --------------------------------------------------------
double __userpurge sub_1004038<st0>(int a1<eax>, int a2<ebp>, int a3<esi>, double result<st0>, int a5, int a6, int a7)
{
  *(_DWORD *)a1 = (signed int)result;
  *(_DWORD *)(a2 + 117) = a3;
  return result;
}

//----- (0100405A) --------------------------------------------------------
signed int __stdcall sub_100405A(int a1, int a2)
{
  return sub_1004073(a2, a1);
}

//----- (01004073) --------------------------------------------------------
signed int __stdcall sub_1004073(int a1, int a2)
{
  int v2; // eax@1
  signed int v3; // edi@1
  int v4; // esi@1

  v3 = -2147024882;
  v2 = (int)LocalAlloc(0x40u, 0xCu);
  v4 = v2;
  if ( v2 )
  {
    *(_DWORD *)v2 = &off_100C288;
    *(_DWORD *)(v2 + 4) = &off_100C26C;
    *(_DWORD *)(v2 + 8) = 1;
    v3 = sub_10040C4(v2, a2, a1);
    sub_1003EA6(v4);
  }
  return v3;
}
// 100C26C: using guessed type int (__stdcall *off_100C26C)(int, int, int);
// 100C288: using guessed type int (__stdcall *off_100C288)(int, int, int);

//----- (010040C4) --------------------------------------------------------
signed int __stdcall sub_10040C4(int a1, int a2, int a3)
{
  char v3; // zf@1
  signed int v4; // ecx@1
  double (__userpurge *v5)<st0>(int<eax>, int<ebp>, int<esi>, double<st0>, int, int, int); // edi@1
  int v6; // esi@1
  int v7; // eax@6
  char v9; // zf@9
  signed int v10; // ecx@9
  int v11; // edi@9
  int v12; // esi@9
  char v13; // zf@14
  signed int v14; // ecx@14
  int v15; // edi@14
  int v16; // esi@14

  v6 = a2;
  v4 = 4;
  v5 = sub_1004038;
  v3 = 1;
  do
  {
    if ( !v4 )
      break;
    v3 = *(_DWORD *)v6 == *(_DWORD *)v5;
    v6 += 4;
    v5 = (double (__userpurge *)<st0>(int<eax>, int<ebp>, int<esi>, double<st0>, int, int, int))((char *)v5 + 4);
    --v4;
  }
  while ( v3 );
  if ( v3 )
    goto LABEL_23;
  v12 = a2;
  v10 = 4;
  v11 = (int)dword_1004A04;
  v9 = 1;
  do
  {
    if ( !v10 )
      break;
    v9 = *(_DWORD *)v12 == *(_DWORD *)v11;
    v12 += 4;
    v11 += 4;
    --v10;
  }
  while ( v9 );
  if ( v9 )
  {
LABEL_23:
    v7 = a1;
    *(_DWORD *)a3 = a1;
LABEL_7:
    sub_10040FB(v7);
    return 0;
  }
  v16 = a2;
  v14 = 4;
  v15 = (int)dword_10049F4;
  v13 = 1;
  do
  {
    if ( !v14 )
      break;
    v13 = *(_DWORD *)v16 == *(_DWORD *)v15;
    v16 += 4;
    v15 += 4;
    --v14;
  }
  while ( v13 );
  if ( v13 )
  {
    v7 = a1;
    *(_DWORD *)a3 = a1 + 4;
    goto LABEL_7;
  }
  *(_DWORD *)a3 = 0;
  return -2147467262;
}
// 10049F4: using guessed type int dword_10049F4[4];
// 1004A04: using guessed type int dword_1004A04[2];

//----- (010040FB) --------------------------------------------------------
LONG __stdcall sub_10040FB(int a1)
{
  return InterlockedIncrement((volatile LONG *)(a1 + 8));
}

//----- (01004116) --------------------------------------------------------
int __stdcall sub_1004116(int a1)
{
  int result; // eax@1
  WCHAR *v2; // ecx@12
  DWORD v3; // eax@12
  const WCHAR *v4; // eax@14
  WCHAR Buffer; // [sp+0h] [bp-324h]@12
  unsigned int v6; // [sp+320h] [bp-4h]@1
  int v7; // [sp+324h] [bp+0h]@1

  v6 = (unsigned int)&v7 ^ dword_100C010;
  result = sub_100414E(a1);
  if ( result )
  {
    if ( result != -2 )
    {
      if ( result != -3 )
      {
        if ( result == -4 )
          result = 112;
        if ( result == -5 )
          result = 14;
        if ( result == -1 )
          result = GetLastError();
        if ( result )
        {
          v3 = FormatMessageW(0x1200u, 0, result, 0, &Buffer, 0x190u, 0);
          v2 = (WCHAR *)dword_100C2DC;
          if ( v3 )
            v2 = &Buffer;
          v4 = lpString2;
          if ( !dword_100C008 )
            v4 = &FileName;
          result = sub_1007051(hWnd, szApp, v2, v4, 0x30u);
        }
      }
    }
  }
  return result;
}
// 100C008: using guessed type int dword_100C008;
// 100C010: using guessed type int dword_100C010;

//----- (0100414E) --------------------------------------------------------
signed int __stdcall sub_100414E(int a1)
{
  signed int v1; // eax@2
  signed int result; // eax@4

  SetCursor(hCursor);
  if ( a1 )
  {
    if ( a1 == 2 )
      v1 = sub_1008987();
    else
      v1 = sub_10088B6();
  }
  else
  {
    v1 = sub_1004194();
  }
  if ( v1 == -1 )
  {
    SetCursor(dword_100C094);
    result = 0;
  }
  else
  {
    result = sub_100900D((HDC)v1);
  }
  return result;
}

//----- (01004194) --------------------------------------------------------
int __cdecl sub_1004194()
{
  int Dst; // [sp+Ch] [bp-58h]@3
  HWND v2; // [sp+10h] [bp-54h]@3
  HGLOBAL v3; // [sp+14h] [bp-50h]@4
  HGLOBAL v4; // [sp+18h] [bp-4Ch]@6
  int v5; // [sp+1Ch] [bp-48h]@11
  int v6; // [sp+20h] [bp-44h]@3
  int v7; // [sp+58h] [bp-Ch]@3
  int v8; // [sp+5Ch] [bp-8h]@8
  int v9; // [sp+60h] [bp-4h]@7

  if ( !stru_100C140.hDevNames )
  {
    stru_100C140.Flags |= 0x480u;
    PageSetupDlgW(&stru_100C140);
    stru_100C140.Flags &= 0xFFFFFB7Fu;
  }
  memset(&Dst, 0, 0x54u);
  v7 = -1;
  v2 = hWnd;
  Dst = 84;
  v6 = 8651020;
  if ( stru_100C140.hDevMode )
    v3 = stru_100C140.hDevMode;
  if ( stru_100C140.hDevNames )
    v4 = stru_100C140.hDevNames;
  v9 = -1;
  if ( !PrintDlgExW((LPPRINTDLGEXW)&Dst) )
  {
    if ( v8 == 1 )
    {
      v9 = v5;
    }
    else
    {
      if ( v8 != 2 )
        return v9;
    }
    if ( !stru_100C140.hDevMode )
    {
      stru_100C140.Flags |= 0x480u;
      PageSetupDlgW(&stru_100C140);
      stru_100C140.Flags &= 0xFFFFFB7Fu;
    }
    stru_100C140.hDevMode = v3;
    stru_100C140.hDevNames = v4;
  }
  return v9;
}

//----- (01004240) --------------------------------------------------------
signed int __stdcall sub_1004240(HWND hDlg, int a2, int a3, int a4)
{
  int v5; // edi@5
  WCHAR *v6; // esi@5
  const WCHAR *v7; // ebx@8
  int v8; // edi@8

  if ( a2 == 2 )
  {
    v5 = 30;
    v6 = &word_100C6A0;
    do
    {
      GetDlgItemTextW(hDlg, v5, v6, 40);
      v6 += 40;
      ++v5;
    }
    while ( (signed int)v6 <= (signed int)&unk_100C6F0 );
    return 0;
  }
  if ( a2 != 272 )
    return 0;
  v8 = 30;
  v7 = &word_100C740;
  do
  {
    SendDlgItemMessageW(hDlg, v8, 0xC5u, 0x27u, 0);
    SetDlgItemTextW(hDlg, v8, v7);
    v7 += 40;
    ++v8;
  }
  while ( (signed int)v7 <= (signed int)&Dst );
  SendDlgItemMessageW(hDlg, 30, 0xB1u, 0, 2555904);
  return 1;
}

//----- (0100432B) --------------------------------------------------------
DWORD __cdecl sub_100432B()
{
  DWORD result; // eax@1
  unsigned int v1; // edx@3
  wchar_t *v2; // ecx@3
  wchar_t Dest; // [sp+0h] [bp-194h]@8
  unsigned int v4; // [sp+190h] [bp-4h]@1
  int v5; // [sp+194h] [bp+0h]@1

  v4 = (unsigned int)&v5 ^ dword_100C010;
  result = CommDlgExtendedError();
  if ( result )
  {
    v2 = 0;
    v1 = 0;
    do
    {
      if ( result == *(int *)((char *)&dword_100CD10 + v1) )
        v2 = (wchar_t *)**(int **)((char *)&off_100CD14 + v1);
      v1 += 8;
    }
    while ( v1 < 0x40 );
    if ( !v2 )
    {
      sub_10015C3(&Dest, 0xC8u, dword_100C328, result);
      v2 = &Dest;
    }
    if ( *v2 )
      MessageBoxW(hWnd, v2, szApp, 0x1010u);
    result = 1;
  }
  return result;
}
// 100C010: using guessed type int dword_100C010;
// 100CD10: using guessed type int dword_100CD10;
// 100CD14: using guessed type int *off_100CD14;

//----- (010043F5) --------------------------------------------------------
int __stdcall sub_10043F5(int a1, int a2)
{
  int v2; // ecx@2
  int result; // eax@3

  if ( !a2 || (v2 = a2, !*(_WORD *)a2) )
    v2 = (int)L"(null)";
  result = a1;
  *(_DWORD *)(a1 + 4) = v2;
  *(_DWORD *)a1 = 2;
  return result;
}
// 1004420: using guessed type wchar_t aNull[7];

//----- (0100449D) --------------------------------------------------------
HRESULT __thiscall sub_100449D(void *this)
{
  HRESULT result; // eax@1
  OLECHAR *v2; // esi@2
  LPVOID ppv; // [sp+0h] [bp-4h]@1

  ppv = this;
  result = CoCreateInstance(&stru_10043E0, 0, 0x17u, &stru_10043D0, &ppv);
  if ( result >= 0 )
  {
    sub_10045A7((int)L"HELP_ENTRY_ID_NOTEPAD_HELP");
    v2 = SysAllocString(L"mshelp://windows/?id=5d18d5fb-e737-4a73-b6cc-dccc63720231");
    if ( v2 )
    {
      (*(void (__stdcall **)(_DWORD, _DWORD))(*(_DWORD *)ppv + 12))(ppv, v2);
      SysFreeString(v2);
    }
    result = (*(int (__stdcall **)(_DWORD))(*(_DWORD *)ppv + 8))(ppv);
  }
  return result;
}
// 100456C: using guessed type wchar_t aHelp_entry_id_[27];

//----- (010045A7) --------------------------------------------------------
int __stdcall sub_10045A7(int a1)
{
  int v2; // [sp+4h] [bp-8h]@1
  int v3; // [sp+8h] [bp-4h]@1

  v2 = 0;
  v3 = 0;
  sub_10043F5((int)&v2, a1);
  return WinSqmAddToStream(0, 911, 1, &v2);
}
// 10045E1: using guessed type int __stdcall WinSqmAddToStream(_DWORD, _DWORD, _DWORD, _DWORD);

//----- (01004628) --------------------------------------------------------
int __stdcall sub_1004628(LPCWSTR lpString)
{
  int v1; // edi@1
  int v2; // eax@4
  void *v3; // edi@4
  int v4; // esi@4
  int v6; // [sp+Ch] [bp-868h]@1
  HWND Dst; // [sp+10h] [bp-864h]@1
  HINSTANCE v8; // [sp+14h] [bp-860h]@1
  int v9; // [sp+1Ch] [bp-858h]@1
  int v10; // [sp+20h] [bp-854h]@1
  void *v11; // [sp+28h] [bp-84Ch]@5
  int v12; // [sp+30h] [bp-844h]@1
  int v13; // [sp+34h] [bp-840h]@1
  int v14; // [sp+6Ch] [bp-808h]@5
  WCHAR String; // [sp+70h] [bp-804h]@1
  unsigned int v16; // [sp+870h] [bp-4h]@1
  int v17; // [sp+874h] [bp+0h]@1

  v16 = (unsigned int)&v17 ^ dword_100C010;
  v1 = 0;
  memset(&Dst, 0, 0x5Cu);
  Dst = hWnd;
  v6 = 96;
  v8 = hInstance;
  v9 = 8;
  v10 = 3000;
  v12 = 2;
  v13 = (int)dword_1004748;
  if ( !LoadStringW(hInstance, 0xBB9u, &String, 1024) )
    goto LABEL_12;
  if ( lpString )
    v1 = lstrlenW(lpString);
  v4 = lstrlenW(&String) + v1 + 1;
  v2 = (int)LocalAlloc(0x40u, 2 * v4);
  v3 = (void *)v2;
  if ( v2 )
  {
    sub_10047BA((int)&String, (int)lpString, v2, v4);
    v11 = v3;
    if ( COMCTL32_345(&v6, &v14, 0, 0) < 0 )
      v14 = 6;
    LocalFree(v3);
  }
  else
  {
LABEL_12:
    v14 = 6;
  }
  return v14;
}
// 10013C8: using guessed type int __stdcall COMCTL32_345(_DWORD, _DWORD, _DWORD, _DWORD);
// 1004748: using guessed type int dword_1004748[4];
// 100C010: using guessed type int dword_100C010;

//----- (0100478B) --------------------------------------------------------
LSTATUS __stdcall sub_100478B(HKEY hKey, LPCWSTR lpValueName, LPCWSTR lpData)
{
  int v4; // eax@1

  v4 = lstrlenW(lpData);
  return RegSetValueExW(hKey, lpValueName, 0, 1u, (const BYTE *)lpData, 2 * v4 + 2);
}

//----- (010047BA) --------------------------------------------------------
signed int __stdcall sub_10047BA(int a1, int a2, int a3, int a4)
{
  int v4; // eax@1
  int v5; // ecx@1
  int v6; // ebx@1
  unsigned int v7; // edi@1
  __int16 v8; // dx@4
  int v10; // esi@6
  int v11; // ecx@7

  v5 = a1;
  v4 = a3;
  v7 = 0;
  v6 = a4 - 1;
  while ( *(_WORD *)v5 != word_100C000 && v7 < v6 )
  {
    *(_WORD *)v4 = *(_WORD *)v5;
    v8 = *(_WORD *)v5;
    v4 += 2;
    ++v7;
    v5 += 2;
    if ( !v8 )
      return 0;
  }
  v10 = a2;
  if ( a2 )
  {
    while ( *(_WORD *)v10 && v7 < v6 )
    {
      *(_WORD *)v4 = *(_WORD *)v10;
      v4 += 2;
      v10 += 2;
      ++v7;
    }
  }
  v11 = v5 + 4;
  while ( *(_WORD *)v11 && v7 < v6 )
  {
    *(_WORD *)v4 = *(_WORD *)v11;
    v4 += 2;
    v11 += 2;
    ++v7;
  }
  *(_WORD *)v4 = 0;
  return 1;
}
// 100C000: using guessed type __int16 word_100C000;

//----- (0100498E) --------------------------------------------------------
LSTATUS __stdcall sub_100498E(HKEY hKey, LPCWSTR lpValueName, BYTE Data)
{
  return RegSetValueExW(hKey, lpValueName, 0, 4u, &Data, 4u);
}

//----- (010056E3) --------------------------------------------------------
void __usercall sub_10056E3(struct _SECURITY_ATTRIBUTES *a1<ebx>, int a2<ebp>, int a3<esi>)
{
  HANDLE v3; // ST18_4@1
  DWORD v4; // eax@2
  int v5; // eax@3
  int v6; // eax@4
  const WCHAR *v7; // eax@6
  int v8; // [sp+0h] [bp-4h]@13

  hFile = CreateFileW((LPCWSTR)a3, 0x80000000u, 3u, a1, 3u, 0x80u, v3);
  if ( hFile == (HANDLE)-1 )
  {
    v4 = GetLastError() - 2;
    if ( v4 )
    {
      v5 = v4 - 3;
      if ( v5 && (v6 = v5 - 60) != 0 )
      {
        if ( v6 == 58 )
          v7 = (const WCHAR *)dword_100C2E0;
        else
          v7 = dword_100C2B0;
      }
      else
      {
        v7 = dword_100C31C;
      }
    }
    else
    {
      v7 = dword_100C2B4;
    }
    sub_1007051(hWnd, szApp, v7, (LPCWSTR)a3, 0x30u);
  }
  else
  {
    sub_1002820(a2, a3, dword_100C05C);
    if ( *(struct _SECURITY_ATTRIBUTES **)(a2 - 4) == a1 )
      v8 = 2;
    else
      v8 = 1;
    sub_1004116(v8);
  }
  JUMPOUT(*(unsigned int *)loc_100266D);
}
// 100266D: using guessed type int __stdcall loc_100266D(int, int nCmdShow);
// 100C05C: using guessed type int dword_100C05C;
// 100C2E0: using guessed type int dword_100C2E0;

//----- (010058A7) --------------------------------------------------------
void __stdcall sub_10058A7(int a1, int a2)
{
  LPCWSTR v2; // ST14_4@1

  sub_1007BF6(v2);
  JUMPOUT(*(unsigned int *)loc_1002B3F);
}
// 1002B3F: using guessed type int __stdcall loc_1002B3F(int, int);

//----- (01005D2A) --------------------------------------------------------
void __usercall sub_1005D2A(int a1<ebp>, HWND a2<edi>)
{
  signed int v2; // ebx@1
  HANDLE v3; // eax@1
  SC_HANDLE v4; // eax@4
  SC_HANDLE v5; // eax@5
  SIZE_T v6; // ST14_4@8
  HANDLE v7; // eax@8
  LPVOID v8; // eax@8
  void *v9; // ST14_4@13
  HANDLE v10; // eax@13
  SC_HANDLE v11; // eax@16
  SC_HANDLE v12; // eax@17
  struct _QUERY_SERVICE_CONFIGW *v13; // eax@20
  SIZE_T v14; // ST14_4@20
  HANDLE v15; // eax@20
  void *v16; // ST14_4@25
  HANDLE v17; // eax@25
  DWORD v18; // eax@32
  void *v19; // eax@33
  const void *v20; // ebx@33
  SIZE_T v21; // ST14_4@33
  HANDLE v22; // eax@33
  size_t v23; // ST14_4@39
  const wchar_t *v24; // ST10_4@39
  wchar_t *v25; // eax@39
  HANDLE v26; // eax@41
  DWORD v27; // eax@45
  DWORD v28; // ebx@45
  void *v29; // eax@46
  SIZE_T v30; // ST14_4@46
  HANDLE v31; // eax@46
  size_t v32; // ST14_4@52
  const wchar_t *v33; // ST10_4@52
  wchar_t *v34; // eax@52
  void *v35; // ST14_4@54
  HANDLE v36; // eax@54
  DWORD v37; // eax@58
  DWORD v38; // ebx@58
  void *v39; // eax@59
  SIZE_T v40; // ST14_4@59
  HANDLE v41; // eax@59
  size_t v42; // ST14_4@65
  const wchar_t *v43; // ST10_4@65
  wchar_t *v44; // eax@65
  void *v45; // ST14_4@67
  HANDLE v46; // eax@67
  signed int v47; // esi@68
  SC_HANDLE v48; // eax@71
  SC_HANDLE v49; // eax@72
  SIZE_T v50; // ST14_4@75
  HANDLE v51; // eax@75
  LPVOID v52; // eax@75
  void *v53; // ST14_4@80
  HANDLE v54; // eax@80
  SC_HANDLE v55; // eax@83
  SC_HANDLE v56; // eax@84
  struct _QUERY_SERVICE_CONFIGW *v57; // eax@87
  SIZE_T v58; // ST14_4@87
  HANDLE v59; // eax@87
  void *v60; // ST14_4@92
  HANDLE v61; // eax@92
  DWORD v62; // eax@99
  void *v63; // eax@100
  const void *v64; // ebx@100
  SIZE_T v65; // ST14_4@100
  HANDLE v66; // eax@100
  size_t v67; // ST14_4@106
  const wchar_t *v68; // ST10_4@106
  wchar_t *v69; // eax@106
  HANDLE v70; // eax@108
  DWORD v71; // eax@112
  DWORD v72; // ebx@112
  void *v73; // eax@113
  SIZE_T v74; // ST14_4@113
  HANDLE v75; // eax@113
  size_t v76; // ST14_4@119
  const wchar_t *v77; // ST10_4@119
  wchar_t *v78; // eax@119
  void *v79; // ST14_4@121
  HANDLE v80; // eax@121
  DWORD v81; // eax@125
  DWORD v82; // ebx@125
  void *v83; // eax@126
  SIZE_T v84; // ST14_4@126
  HANDLE v85; // eax@126
  size_t v86; // ST14_4@132
  const wchar_t *v87; // ST10_4@132
  wchar_t *v88; // eax@132
  void *v89; // ST14_4@134
  HANDLE v90; // eax@134
  LONG v91; // eax@139
  HWND v92; // eax@141
  DWORD v93; // eax@143
  HANDLE v94; // eax@147
  WCHAR *v95; // [sp-8h] [bp-10h]@139

  v3 = GetCurrentProcess();
  v2 = 260;
  if ( IsWow64Process(v3, (PBOOL)(a1 - 4792)) )
  {
    if ( *(HWND *)(a1 - 4792) == a2 )
    {
      *(_DWORD *)(a1 - 4748) = a2;
      v48 = OpenSCManagerW((LPCWSTR)a2, (LPCWSTR)a2, 1u);
      *(_DWORD *)(a1 - 4760) = v48;
      if ( v48 != a2 )
      {
        v49 = OpenServiceW(v48, L"sppuinotify", 1u);
        *(_DWORD *)(a1 - 4752) = v49;
        if ( v49 != a2 )
        {
          if ( !QueryServiceConfigW(
                  *(SC_HANDLE *)(a1 - 4752),
                  (LPQUERY_SERVICE_CONFIGW)a2,
                  (DWORD)a2,
                  (LPDWORD)(a1 - 4764)) )
          {
            if ( GetLastError() == 122 )
            {
              v50 = *(_DWORD *)(a1 - 4764);
              v51 = GetProcessHeap();
              v52 = HeapAlloc(v51, (DWORD)a2, v50);
              *(_DWORD *)(a1 - 4744) = v52;
              if ( v52 == a2 )
              {
                *(_DWORD *)(a1 - 4748) = 1;
              }
              else
              {
                if ( QueryServiceConfigW(
                       *(SC_HANDLE *)(a1 - 4752),
                       *(LPQUERY_SERVICE_CONFIGW *)(a1 - 4744),
                       *(_DWORD *)(a1 - 4764),
                       (LPDWORD)(a1 - 4764)) )
                {
                  if ( *(_DWORD *)(*(_DWORD *)(a1 - 4744) + 4) != 4 )
                    *(_DWORD *)(a1 - 4748) = 1;
                }
                v53 = *(void **)(a1 - 4744);
                v54 = GetProcessHeap();
                HeapFree(v54, (DWORD)a2, v53);
              }
            }
          }
          CloseServiceHandle(*(SC_HANDLE *)(a1 - 4752));
        }
        CloseServiceHandle(*(SC_HANDLE *)(a1 - 4760));
        if ( *(HWND *)(a1 - 4748) != a2 )
        {
          *(_DWORD *)(a1 - 4752) = a2;
          v55 = OpenSCManagerW((LPCWSTR)a2, (LPCWSTR)a2, 1u);
          *(_DWORD *)(a1 - 4756) = v55;
          if ( v55 != a2 )
          {
            v56 = OpenServiceW(v55, L"sppsvc", 1u);
            *(_DWORD *)(a1 - 4744) = v56;
            if ( v56 != a2 )
            {
              if ( !QueryServiceConfigW(v56, (LPQUERY_SERVICE_CONFIGW)a2, (DWORD)a2, (LPDWORD)(a1 - 4748)) )
              {
                if ( GetLastError() == 122 )
                {
                  v58 = *(_DWORD *)(a1 - 4748);
                  v59 = GetProcessHeap();
                  v57 = (struct _QUERY_SERVICE_CONFIGW *)HeapAlloc(v59, (DWORD)a2, v58);
                  *(_DWORD *)(a1 - 4760) = v57;
                  if ( v57 == a2 )
                  {
                    *(_DWORD *)(a1 - 4752) = 1;
                  }
                  else
                  {
                    if ( QueryServiceConfigW(
                           *(SC_HANDLE *)(a1 - 4744),
                           v57,
                           *(_DWORD *)(a1 - 4748),
                           (LPDWORD)(a1 - 4748)) )
                    {
                      if ( *(_DWORD *)(*(_DWORD *)(a1 - 4760) + 4) != 4 )
                        *(_DWORD *)(a1 - 4752) = 1;
                    }
                    v60 = *(void **)(a1 - 4760);
                    v61 = GetProcessHeap();
                    HeapFree(v61, (DWORD)a2, v60);
                  }
                }
              }
              CloseServiceHandle(*(SC_HANDLE *)(a1 - 4744));
            }
            CloseServiceHandle(*(SC_HANDLE *)(a1 - 4756));
            if ( *(HWND *)(a1 - 4752) != a2 )
            {
              if ( SHGetFolderPathW(a2, 37, a2, (DWORD)a2, (LPWSTR)(a1 - 1100)) >= 0 )
              {
                if ( sub_1009CDF(a1 - 3700, 260, a1 - 1100) >= 0 )
                {
                  if ( sub_1009D19(a1 - 3700, 260, (int)L"\\sppuinotify.dll") >= 0 )
                  {
                    if ( GetFileAttributesW((LPCWSTR)(a1 - 3700)) != -1 )
                    {
                      *(_DWORD *)(a1 - 4760) = a2;
                      v62 = GetFileVersionInfoSizeExW((DWORD)a2, (LPCWSTR)(a1 - 3700), (LPDWORD)(a1 - 4752));
                      *(_DWORD *)(a1 - 4756) = v62;
                      if ( v62 > (unsigned int)a2 )
                      {
                        v65 = v62;
                        v66 = GetProcessHeap();
                        v63 = HeapAlloc(v66, (DWORD)a2, v65);
                        v64 = v63;
                        if ( v63 == a2 )
                          goto LABEL_153;
                        if ( GetFileVersionInfoExW(
                               (DWORD)a2,
                               (LPCWSTR)(a1 - 3700),
                               *(_DWORD *)(a1 - 4752),
                               *(_DWORD *)(a1 - 4756),
                               v63) )
                        {
                          if ( VerQueryValueW(
                                 v64,
                                 L"\\VarFileInfo\\Translation",
                                 (LPVOID *)(a1 - 4884),
                                 (PUINT)(a1 - 4780)) )
                          {
                            if ( *(_DWORD *)(a1 - 4780) >= 4u )
                            {
                              if ( sub_10015C3(
                                     (wchar_t *)(a1 - 388),
                                     0x30u,
                                     L"\\StringFileInfo\\%04x%04x\\OriginalFilename",
                                     **(_WORD **)(a1 - 4884),
                                     *(_WORD *)(*(_DWORD *)(a1 - 4884) + 2)) >= 0 )
                              {
                                if ( VerQueryValueW(v64, (LPCWSTR)(a1 - 388), (LPVOID *)(a1 - 4848), (PUINT)(a1 - 4800)) )
                                {
                                  v67 = *(_DWORD *)(a1 - 4800);
                                  v68 = *(const wchar_t **)(a1 - 4848);
                                  v69 = wcsrchr((const wchar_t *)(a1 - 3700), 0x5Cu);
                                  if ( !wcsncmp(v69 + 1, v68, v67) )
                                    *(_DWORD *)(a1 - 4760) = 1;
                                }
                              }
                            }
                          }
                        }
                        v70 = GetProcessHeap();
                        HeapFree(v70, (DWORD)a2, (LPVOID)v64);
                        if ( *(HWND *)(a1 - 4760) != a2 )
                        {
LABEL_153:
                          if ( sub_1009CDF(a1 - 4220, 260, a1 - 1100) >= 0 )
                          {
                            if ( sub_1009D19(a1 - 4220, 260, (int)L"\\slui.exe") >= 0 )
                            {
                              if ( GetFileAttributesW((LPCWSTR)(a1 - 4220)) != -1 )
                              {
                                *(_DWORD *)(a1 - 4756) = a2;
                                v71 = GetFileVersionInfoSizeExW((DWORD)a2, (LPCWSTR)(a1 - 4220), (LPDWORD)(a1 - 4760));
                                v72 = v71;
                                if ( v71 > (unsigned int)a2 )
                                {
                                  v74 = v71;
                                  v75 = GetProcessHeap();
                                  v73 = HeapAlloc(v75, (DWORD)a2, v74);
                                  *(_DWORD *)(a1 - 4744) = v73;
                                  if ( v73 == a2 )
                                    goto LABEL_154;
                                  if ( GetFileVersionInfoExW(
                                         (DWORD)a2,
                                         (LPCWSTR)(a1 - 4220),
                                         *(_DWORD *)(a1 - 4760),
                                         v72,
                                         v73) )
                                  {
                                    if ( VerQueryValueW(
                                           *(LPCVOID *)(a1 - 4744),
                                           L"\\VarFileInfo\\Translation",
                                           (LPVOID *)(a1 - 4876),
                                           (PUINT)(a1 - 4808)) )
                                    {
                                      if ( *(_DWORD *)(a1 - 4808) >= 4u )
                                      {
                                        if ( sub_10015C3(
                                               (wchar_t *)(a1 - 580),
                                               0x30u,
                                               L"\\StringFileInfo\\%04x%04x\\OriginalFilename",
                                               **(_WORD **)(a1 - 4876),
                                               *(_WORD *)(*(_DWORD *)(a1 - 4876) + 2)) >= 0 )
                                        {
                                          if ( VerQueryValueW(
                                                 *(LPCVOID *)(a1 - 4744),
                                                 (LPCWSTR)(a1 - 580),
                                                 (LPVOID *)(a1 - 4856),
                                                 (PUINT)(a1 - 4816)) )
                                          {
                                            v76 = *(_DWORD *)(a1 - 4816);
                                            v77 = *(const wchar_t **)(a1 - 4856);
                                            v78 = wcsrchr((const wchar_t *)(a1 - 4220), 0x5Cu);
                                            if ( !wcsncmp(v78 + 1, v77, v76) )
                                              *(_DWORD *)(a1 - 4756) = 1;
                                          }
                                        }
                                      }
                                    }
                                  }
                                  v79 = *(void **)(a1 - 4744);
                                  v80 = GetProcessHeap();
                                  HeapFree(v80, (DWORD)a2, v79);
                                  if ( *(HWND *)(a1 - 4756) != a2 )
                                  {
LABEL_154:
                                    if ( sub_1009CDF(a1 - 3180, 260, a1 - 1100) >= 0 )
                                    {
                                      if ( sub_1009D19(a1 - 3180, 260, (int)L"\\sppsvc.exe") >= 0 )
                                      {
                                        if ( GetFileAttributesW((LPCWSTR)(a1 - 3180)) != -1 )
                                        {
                                          *(_DWORD *)(a1 - 4756) = a2;
                                          v81 = GetFileVersionInfoSizeExW(
                                                  (DWORD)a2,
                                                  (LPCWSTR)(a1 - 3180),
                                                  (LPDWORD)(a1 - 4824));
                                          v82 = v81;
                                          if ( v81 > (unsigned int)a2 )
                                          {
                                            v84 = v81;
                                            v85 = GetProcessHeap();
                                            v83 = HeapAlloc(v85, (DWORD)a2, v84);
                                            *(_DWORD *)(a1 - 4744) = v83;
                                            if ( v83 == a2 )
                                              goto LABEL_150;
                                            if ( GetFileVersionInfoExW(
                                                   (DWORD)a2,
                                                   (LPCWSTR)(a1 - 3180),
                                                   *(_DWORD *)(a1 - 4824),
                                                   v82,
                                                   v83) )
                                            {
                                              if ( VerQueryValueW(
                                                     *(LPCVOID *)(a1 - 4744),
                                                     L"\\VarFileInfo\\Translation",
                                                     (LPVOID *)(a1 - 4832),
                                                     (PUINT)(a1 - 4892)) )
                                              {
                                                if ( *(_DWORD *)(a1 - 4892) >= 4u )
                                                {
                                                  if ( sub_10015C3(
                                                         (wchar_t *)(a1 - 292),
                                                         0x30u,
                                                         L"\\StringFileInfo\\%04x%04x\\OriginalFilename",
                                                         **(_WORD **)(a1 - 4832),
                                                         *(_WORD *)(*(_DWORD *)(a1 - 4832) + 2)) >= 0 )
                                                  {
                                                    if ( VerQueryValueW(
                                                           *(LPCVOID *)(a1 - 4744),
                                                           (LPCWSTR)(a1 - 292),
                                                           (LPVOID *)(a1 - 4772),
                                                           (PUINT)(a1 - 4864)) )
                                                    {
                                                      v86 = *(_DWORD *)(a1 - 4864);
                                                      v87 = *(const wchar_t **)(a1 - 4772);
                                                      v88 = wcsrchr((const wchar_t *)(a1 - 3180), 0x5Cu);
                                                      if ( !wcsncmp(v88 + 1, v87, v86) )
                                                        *(_DWORD *)(a1 - 4756) = 1;
                                                    }
                                                  }
                                                }
                                              }
                                            }
                                            v89 = *(void **)(a1 - 4744);
                                            v90 = GetProcessHeap();
                                            HeapFree(v90, (DWORD)a2, v89);
                                            if ( *(HWND *)(a1 - 4756) != a2 )
LABEL_150:
                                              JUMPOUT(*(unsigned int *)loc_10027A2);
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      v47 = 0;
      goto LABEL_136;
    }
    if ( Wow64DisableWow64FsRedirection((PVOID *)(a1 - 4840)) )
    {
      *(_DWORD *)(a1 - 4768) = a2;
      v4 = OpenSCManagerW((LPCWSTR)a2, (LPCWSTR)a2, 1u);
      *(_DWORD *)(a1 - 4748) = v4;
      if ( v4 == a2 )
        goto LABEL_155;
      v5 = OpenServiceW(v4, L"sppuinotify", 1u);
      *(_DWORD *)(a1 - 4764) = v5;
      if ( v5 != a2 )
      {
        if ( !QueryServiceConfigW(
                *(SC_HANDLE *)(a1 - 4764),
                (LPQUERY_SERVICE_CONFIGW)a2,
                (DWORD)a2,
                (LPDWORD)(a1 - 4776)) )
        {
          if ( GetLastError() == 122 )
          {
            v6 = *(_DWORD *)(a1 - 4776);
            v7 = GetProcessHeap();
            v8 = HeapAlloc(v7, (DWORD)a2, v6);
            *(_DWORD *)(a1 - 4744) = v8;
            if ( v8 == a2 )
            {
              *(_DWORD *)(a1 - 4768) = 1;
            }
            else
            {
              if ( QueryServiceConfigW(
                     *(SC_HANDLE *)(a1 - 4764),
                     *(LPQUERY_SERVICE_CONFIGW *)(a1 - 4744),
                     *(_DWORD *)(a1 - 4776),
                     (LPDWORD)(a1 - 4776)) )
              {
                if ( *(_DWORD *)(*(_DWORD *)(a1 - 4744) + 4) != 4 )
                  *(_DWORD *)(a1 - 4768) = 1;
              }
              v9 = *(void **)(a1 - 4744);
              v10 = GetProcessHeap();
              HeapFree(v10, (DWORD)a2, v9);
            }
          }
        }
        CloseServiceHandle(*(SC_HANDLE *)(a1 - 4764));
      }
      CloseServiceHandle(*(SC_HANDLE *)(a1 - 4748));
      if ( *(HWND *)(a1 - 4768) == a2 )
        goto LABEL_155;
      *(_DWORD *)(a1 - 4764) = a2;
      v11 = OpenSCManagerW((LPCWSTR)a2, (LPCWSTR)a2, 1u);
      *(_DWORD *)(a1 - 4744) = v11;
      if ( v11 == a2 )
        goto LABEL_155;
      v12 = OpenServiceW(v11, L"sppsvc", 1u);
      *(_DWORD *)(a1 - 4752) = v12;
      if ( v12 != a2 )
      {
        if ( !QueryServiceConfigW(v12, (LPQUERY_SERVICE_CONFIGW)a2, (DWORD)a2, (LPDWORD)(a1 - 4768)) )
        {
          if ( GetLastError() == 122 )
          {
            v14 = *(_DWORD *)(a1 - 4768);
            v15 = GetProcessHeap();
            v13 = (struct _QUERY_SERVICE_CONFIGW *)HeapAlloc(v15, (DWORD)a2, v14);
            *(_DWORD *)(a1 - 4748) = v13;
            if ( v13 == a2 )
            {
              *(_DWORD *)(a1 - 4764) = 1;
            }
            else
            {
              if ( QueryServiceConfigW(*(SC_HANDLE *)(a1 - 4752), v13, *(_DWORD *)(a1 - 4768), (LPDWORD)(a1 - 4768)) )
              {
                if ( *(_DWORD *)(*(_DWORD *)(a1 - 4748) + 4) != 4 )
                  *(_DWORD *)(a1 - 4764) = 1;
              }
              v16 = *(void **)(a1 - 4748);
              v17 = GetProcessHeap();
              HeapFree(v17, (DWORD)a2, v16);
            }
          }
        }
        CloseServiceHandle(*(SC_HANDLE *)(a1 - 4752));
      }
      CloseServiceHandle(*(SC_HANDLE *)(a1 - 4744));
      if ( *(HWND *)(a1 - 4764) == a2 )
        goto LABEL_155;
      if ( SHGetFolderPathW(a2, 37, a2, (DWORD)a2, (LPWSTR)(a1 - 4740)) < 0 )
        goto LABEL_155;
      if ( sub_1009CDF(a1 - 2660, 260, a1 - 4740) < 0 )
        goto LABEL_155;
      if ( sub_1009D19(a1 - 2660, 260, (int)L"\\sppuinotify.dll") < 0 )
        goto LABEL_155;
      if ( GetFileAttributesW((LPCWSTR)(a1 - 2660)) == -1 )
        goto LABEL_155;
      *(_DWORD *)(a1 - 4752) = a2;
      v18 = GetFileVersionInfoSizeExW((DWORD)a2, (LPCWSTR)(a1 - 2660), (LPDWORD)(a1 - 4784));
      *(_DWORD *)(a1 - 4748) = v18;
      if ( v18 <= (unsigned int)a2 )
        goto LABEL_155;
      v21 = v18;
      v22 = GetProcessHeap();
      v19 = HeapAlloc(v22, (DWORD)a2, v21);
      v20 = v19;
      if ( v19 != a2 )
      {
        if ( GetFileVersionInfoExW((DWORD)a2, (LPCWSTR)(a1 - 2660), *(_DWORD *)(a1 - 4784), *(_DWORD *)(a1 - 4748), v19) )
        {
          if ( VerQueryValueW(v20, L"\\VarFileInfo\\Translation", (LPVOID *)(a1 - 4796), (PUINT)(a1 - 4788)) )
          {
            if ( *(_DWORD *)(a1 - 4788) >= 4u )
            {
              if ( sub_10015C3(
                     (wchar_t *)(a1 - 484),
                     0x30u,
                     L"\\StringFileInfo\\%04x%04x\\OriginalFilename",
                     **(_WORD **)(a1 - 4796),
                     *(_WORD *)(*(_DWORD *)(a1 - 4796) + 2)) >= 0 )
              {
                if ( VerQueryValueW(v20, (LPCWSTR)(a1 - 484), (LPVOID *)(a1 - 4812), (PUINT)(a1 - 4804)) )
                {
                  v23 = *(_DWORD *)(a1 - 4804);
                  v24 = *(const wchar_t **)(a1 - 4812);
                  v25 = wcsrchr((const wchar_t *)(a1 - 2660), 0x5Cu);
                  if ( !wcsncmp(v25 + 1, v24, v23) )
                    *(_DWORD *)(a1 - 4752) = 1;
                }
              }
            }
          }
        }
        v26 = GetProcessHeap();
        HeapFree(v26, (DWORD)a2, (LPVOID)v20);
        if ( *(HWND *)(a1 - 4752) == a2 )
          goto LABEL_155;
      }
      if ( sub_1009CDF(a1 - 1620, 260, a1 - 4740) < 0 )
        goto LABEL_155;
      if ( sub_1009D19(a1 - 1620, 260, (int)L"\\slui.exe") < 0 )
        goto LABEL_155;
      if ( GetFileAttributesW((LPCWSTR)(a1 - 1620)) == -1 )
        goto LABEL_155;
      *(_DWORD *)(a1 - 4748) = a2;
      v27 = GetFileVersionInfoSizeExW((DWORD)a2, (LPCWSTR)(a1 - 1620), (LPDWORD)(a1 - 4820));
      v28 = v27;
      if ( v27 <= (unsigned int)a2 )
        goto LABEL_155;
      v30 = v27;
      v31 = GetProcessHeap();
      v29 = HeapAlloc(v31, (DWORD)a2, v30);
      *(_DWORD *)(a1 - 4744) = v29;
      if ( v29 != a2 )
      {
        if ( GetFileVersionInfoExW((DWORD)a2, (LPCWSTR)(a1 - 1620), *(_DWORD *)(a1 - 4820), v28, v29) )
        {
          if ( VerQueryValueW(
                 *(LPCVOID *)(a1 - 4744),
                 L"\\VarFileInfo\\Translation",
                 (LPVOID *)(a1 - 4836),
                 (PUINT)(a1 - 4828)) )
          {
            if ( *(_DWORD *)(a1 - 4828) >= 4u )
            {
              if ( sub_10015C3(
                     (wchar_t *)(a1 - 100),
                     0x30u,
                     L"\\StringFileInfo\\%04x%04x\\OriginalFilename",
                     **(_WORD **)(a1 - 4836),
                     *(_WORD *)(*(_DWORD *)(a1 - 4836) + 2)) >= 0 )
              {
                if ( VerQueryValueW(
                       *(LPCVOID *)(a1 - 4744),
                       (LPCWSTR)(a1 - 100),
                       (LPVOID *)(a1 - 4852),
                       (PUINT)(a1 - 4844)) )
                {
                  v32 = *(_DWORD *)(a1 - 4844);
                  v33 = *(const wchar_t **)(a1 - 4852);
                  v34 = wcsrchr((const wchar_t *)(a1 - 1620), 0x5Cu);
                  if ( !wcsncmp(v34 + 1, v33, v32) )
                    *(_DWORD *)(a1 - 4748) = 1;
                }
              }
            }
          }
        }
        v35 = *(void **)(a1 - 4744);
        v36 = GetProcessHeap();
        HeapFree(v36, (DWORD)a2, v35);
        if ( *(HWND *)(a1 - 4748) == a2 )
          goto LABEL_155;
      }
      if ( sub_1009CDF(a1 - 2140, 260, a1 - 4740) < 0 )
        goto LABEL_155;
      if ( sub_1009D19(a1 - 2140, 260, (int)L"\\sppsvc.exe") < 0 )
        goto LABEL_155;
      if ( GetFileAttributesW((LPCWSTR)(a1 - 2140)) == -1 )
        goto LABEL_155;
      *(_DWORD *)(a1 - 4748) = a2;
      v37 = GetFileVersionInfoSizeExW((DWORD)a2, (LPCWSTR)(a1 - 2140), (LPDWORD)(a1 - 4860));
      v38 = v37;
      if ( v37 <= (unsigned int)a2 )
        goto LABEL_155;
      v40 = v37;
      v41 = GetProcessHeap();
      v39 = HeapAlloc(v41, (DWORD)a2, v40);
      *(_DWORD *)(a1 - 4744) = v39;
      if ( v39 == a2 )
        goto LABEL_156;
      if ( GetFileVersionInfoExW((DWORD)a2, (LPCWSTR)(a1 - 2140), *(_DWORD *)(a1 - 4860), v38, v39) )
      {
        if ( VerQueryValueW(
               *(LPCVOID *)(a1 - 4744),
               L"\\VarFileInfo\\Translation",
               (LPVOID *)(a1 - 4880),
               (PUINT)(a1 - 4872)) )
        {
          if ( *(_DWORD *)(a1 - 4872) >= 4u )
          {
            if ( sub_10015C3(
                   (wchar_t *)(a1 - 196),
                   0x30u,
                   L"\\StringFileInfo\\%04x%04x\\OriginalFilename",
                   **(_WORD **)(a1 - 4880),
                   *(_WORD *)(*(_DWORD *)(a1 - 4880) + 2)) >= 0 )
            {
              if ( VerQueryValueW(
                     *(LPCVOID *)(a1 - 4744),
                     (LPCWSTR)(a1 - 196),
                     (LPVOID *)(a1 - 4896),
                     (PUINT)(a1 - 4888)) )
              {
                v42 = *(_DWORD *)(a1 - 4888);
                v43 = *(const wchar_t **)(a1 - 4896);
                v44 = wcsrchr((const wchar_t *)(a1 - 2140), 0x5Cu);
                if ( !wcsncmp(v44 + 1, v43, v42) )
                  *(_DWORD *)(a1 - 4748) = 1;
              }
            }
          }
        }
      }
      v45 = *(void **)(a1 - 4744);
      v46 = GetProcessHeap();
      HeapFree(v46, (DWORD)a2, v45);
      if ( *(HWND *)(a1 - 4748) == a2 )
LABEL_155:
        v47 = 0;
      else
LABEL_156:
        v47 = 1;
      Wow64RevertWow64FsRedirection(*(PVOID *)(a1 - 4840));
LABEL_136:
      if ( (HWND)v47 != a2 )
        goto LABEL_150;
      v2 = 260;
      goto LABEL_138;
    }
  }
LABEL_138:
  if ( !GetSystemMetrics(67) )
  {
    WinSqmIncrementDWORD(a2, 6859, 1);
    v91 = InterlockedExchange(&Target, 1);
    v95 = (WCHAR *)(a1 - 1100);
    if ( v91 )
    {
      if ( LoadStringW((HINSTANCE)0x1000000, 0xC804u, v95, v2) )
      {
        v92 = FindWindowW((LPCWSTR)a2, (LPCWSTR)(a1 - 1100));
        if ( v92 != a2 )
          SetForegroundWindow(v92);
      }
    }
    else
    {
      v93 = GetModuleFileNameW((HMODULE)0x1000000, v95, v2);
      if ( (HWND)v93 != a2 )
      {
        if ( v93 != v2 || GetLastError() != 122 )
        {
          if ( LoadLibraryW((LPCWSTR)(a1 - 1100)) )
          {
            v94 = CreateThread(
                    (LPSECURITY_ATTRIBUTES)a2,
                    (SIZE_T)a2,
                    (LPTHREAD_START_ROUTINE)StartAddress,
                    a2,
                    (DWORD)a2,
                    (LPDWORD)(a1 - 4772));
            if ( v94 == a2 )
              InterlockedExchange(&Target, (LONG)a2);
            else
              CloseHandle(v94);
          }
        }
      }
    }
  }
  goto LABEL_150;
}
// 10027A2: using guessed type int loc_10027A2();
// 1006B98: using guessed type wchar_t aSppsvc_exe[12];
// 1006BB0: using guessed type wchar_t aSlui_exe[10];
// 1006BC4: using guessed type wchar_t aSppuinotify_dl[17];
// 100A020: using guessed type int __stdcall WinSqmIncrementDWORD(_DWORD, _DWORD, _DWORD);

//----- (01006C68) --------------------------------------------------------
int __usercall sub_1006C68<eax>(int a1<ebp>)
{
  int v1; // eax@1
  int v3; // ecx@1

  v1 = *(_DWORD *)(a1 - 20);
  v3 = **(_DWORD **)v1;
  *(_DWORD *)(a1 - 36) = v3;
  return XcptFilter(v3, v1);
}
// 1009DE5: using guessed type int __cdecl XcptFilter(_DWORD, _DWORD);

//----- (01006C7C) --------------------------------------------------------
void __usercall sub_1006C7C(int a1<ebp>)
{
  int v1; // eax@1

  v1 = *(_DWORD *)(a1 - 36);
  dword_100C070 = *(_DWORD *)(a1 - 36);
  JUMPOUT(dword_100C064, 0, *(unsigned int *)loc_1006C97);
  exit(v1);
}
// 1006C97: using guessed type int loc_1006C97();
// 100C064: using guessed type int dword_100C064;
// 100C070: using guessed type int dword_100C070;

//----- (01006CB4) --------------------------------------------------------
signed int __cdecl sub_1006CB4()
{
  return 1;
}

//----- (01006DC0) --------------------------------------------------------
LONG __stdcall sub_1006DC0(int a1)
{
  return sub_10040FB(a1 - 4);
}

//----- (01006DDA) --------------------------------------------------------
LONG __stdcall sub_1006DDA(int a1)
{
  return sub_1003EA6(a1 - 4);
}

//----- (01006DF4) --------------------------------------------------------
int __stdcall sub_1006DF4(int a1, int a2, int a3, int a4)
{
  if ( a3 == 1 )
    dword_100C00C = a4;
  return 0;
}
// 100C00C: using guessed type int dword_100C00C;

//----- (01006E12) --------------------------------------------------------
signed int __stdcall sub_1006E12(int a1, int a2, int a3)
{
  return sub_10040C4(a1 - 4, a2, a3);
}

//----- (01006E32) --------------------------------------------------------
int __stdcall sub_1006E32(int a1, LPCWSTR lpFileName)
{
  HANDLE v2; // eax@2
  UINT v4; // [sp+4h] [bp-414h]@2
  void *v5; // [sp+8h] [bp-410h]@2
  DWORD iSize; // [sp+Ch] [bp-40Ch]@3
  int v7; // [sp+10h] [bp-408h]@1
  char Buffer; // [sp+14h] [bp-404h]@3
  unsigned int v9; // [sp+414h] [bp-4h]@1
  int v10; // [sp+418h] [bp+0h]@1

  v9 = (unsigned int)&v10 ^ dword_100C010;
  v7 = a1;
  if ( lstrcmpiW(lpFileName, &String2) )
  {
    v4 = SetErrorMode(1u);
    v2 = CreateFileW(lpFileName, 0x80000000u, 1u, 0, 3u, 0x80u, 0);
    v5 = v2;
    if ( v2 != (HANDLE)-1 )
    {
      if ( ReadFile(v2, &Buffer, 0x400u, &iSize, 0) > 0 )
      {
        if ( iSize )
        {
          dword_100C00C = sub_10071C2(&Buffer, iSize);
          if ( dword_100C00C != -1 )
          {
            if ( (**(int (__stdcall ***)(int, _DWORD, int *))v7)(v7, dword_1003C74, &v7) >= 0 )
            {
              (*(void (__stdcall **)(int, signed int, int))(*(_DWORD *)v7 + 100))(v7, 1, dword_100C00C);
              (*(void (__stdcall **)(int))(*(_DWORD *)v7 + 8))(v7);
            }
          }
          sub_1002558((int)&String2, 0x104u, (int)lpFileName);
        }
      }
      CloseHandle(v5);
    }
    SetErrorMode(v4);
  }
  return 0;
}
// 1003C74: using guessed type int dword_1003C74[5];
// 100C00C: using guessed type int dword_100C00C;
// 100C010: using guessed type int dword_100C010;

//----- (01006F5C) --------------------------------------------------------
int __stdcall sub_1006F5C(int a1, const WCHAR *lpFileName)
{
  int v2; // edi@1
  int v3; // esi@1
  int v5; // [sp+8h] [bp-4h]@1

  v2 = (int)lpFileName;
  v3 = (*(int (__stdcall **)(const WCHAR *, int *))(*(_DWORD *)lpFileName + 56))(lpFileName, &v5);
  if ( v3 >= 0 )
  {
    v3 = (*(int (__stdcall **)(int, signed int, const WCHAR **))(*(_DWORD *)v5 + 20))(v5, -2147123200, &lpFileName);
    if ( v3 >= 0 )
    {
      v3 = sub_1006E32(v2, lpFileName);
      CoTaskMemFree((LPVOID)lpFileName);
    }
    (*(void (__stdcall **)(int))(*(_DWORD *)v5 + 8))(v5);
  }
  return v3;
}

//----- (01006FB9) --------------------------------------------------------
LRESULT __stdcall sub_1006FB9(int a1)
{
  LRESULT result; // eax@1

  result = SendMessageW(dword_100C028, 187u, a1 - 1, 0);
  if ( result != -1 )
  {
    SendMessageW(dword_100C028, 0xB1u, result, result);
    result = SendMessageW(dword_100C028, 0xB7u, 0, 0);
  }
  return result;
}

//----- (01007008) --------------------------------------------------------
const WCHAR *__stdcall sub_1007008(LPCWSTR lpsz)
{
  const WCHAR *v1; // eax@1
  const WCHAR v2; // cx@1
  const WCHAR *v3; // edi@1

  v2 = *lpsz;
  v3 = lpsz;
  v1 = lpsz;
  if ( *lpsz )
  {
    do
    {
      if ( v2 == 58 || v2 == 92 )
        v3 = v1;
      v1 = CharNextW(v1);
      v2 = *v1;
    }
    while ( *v1 );
    if ( v3 != lpsz )
      ++v3;
  }
  return v3;
}

//----- (01007051) --------------------------------------------------------
int __stdcall sub_1007051(HWND hWnd, LPCWSTR lpCaption, LPCWSTR lpText, LPCWSTR lpString, UINT uType)
{
  int v5; // edi@2
  int v6; // eax@4
  const WCHAR *v7; // edi@4
  int v8; // esi@4
  int v9; // esi@5

  if ( lpString )
    v5 = lstrlenW(lpString);
  else
    v5 = 0;
  v8 = lstrlenW(lpText) + v5 + 1;
  v6 = (int)LocalAlloc(0x40u, 2 * v8);
  v7 = (const WCHAR *)v6;
  if ( v6 )
  {
    sub_10047BA((int)lpText, (int)lpString, v6, v8);
    v9 = MessageBoxW(hWnd, v7, lpCaption, uType);
    LocalFree((HLOCAL)v7);
  }
  else
  {
    v9 = MessageBoxW(hWnd, lpText, lpCaption, uType);
  }
  return v9;
}

//----- (010070D3) --------------------------------------------------------
__int32 __stdcall sub_10070D3(int a1)
{
  __int32 result; // eax@1
  __int32 v2; // edi@2
  int v3; // eax@3
  void *v4; // [sp+8h] [bp-14h]@1
  int v5; // [sp+Ch] [bp-10h]@1
  int v6; // [sp+10h] [bp-Ch]@3
  LPARAM lParam; // [sp+14h] [bp-8h]@1
  WPARAM wParam; // [sp+18h] [bp-4h]@1

  wParam = 0;
  lParam = 0;
  v5 = lstrlenW(stru_100C0C0.lpstrReplaceWith);
  SendMessageW(dword_100C028, 176u, (WPARAM)&wParam, (LPARAM)&lParam);
  result = SendMessageW(dword_100C028, 0xBDu, 0, 0);
  v4 = (void *)result;
  if ( result )
  {
    result = (__int32)LocalLock((HLOCAL)result);
    v2 = result;
    if ( result )
    {
      v3 = sub_100818F(result + 2 * wParam, lParam - wParam, (int)stru_100C0C0.lpstrFindWhat, dword_100D798, (int)&v6);
      if ( v3 == v2 + 2 * wParam )
      {
        if ( v6 == lParam - wParam )
        {
          SendMessageW(dword_100C028, 0xC2u, 1u, (LPARAM)stru_100C0C0.lpstrReplaceWith);
          SendMessageW(dword_100C028, 0xB1u, wParam, wParam + v5);
          if ( a1 )
            SendMessageW(dword_100C028, 0xB7u, 0, 0);
        }
      }
      result = LocalUnlock(v4);
    }
  }
  return result;
}
// 100D798: using guessed type int dword_100D798;

//----- (010071C2) --------------------------------------------------------
int __stdcall sub_10071C2(const void *lpv, int iSize)
{
  int result; // eax@1
  int v3; // ecx@2

  result = 0;
  if ( (unsigned int)iSize > 1 )
  {
    v3 = *(_WORD *)lpv;
    if ( v3 != 48111 )
    {
      if ( v3 == 65279 )
        return 1;
      if ( v3 != 65534 )
      {
        if ( !sub_100991D(lpv, iSize) )
          return sub_10098C7((int)lpv, iSize) != 0 ? 3 : 0;
        return 1;
      }
      return 2;
    }
    if ( (unsigned int)iSize > 2 && *((_BYTE *)lpv + 2) == -65 )
      return 3;
  }
  return result;
}

//----- (0100722E) --------------------------------------------------------
signed int __stdcall sub_100722E(HWND hWndParent, int a2, HWND hWnd, int a4)
{
  LPARAM v4; // ecx@6
  HWND v5; // esi@13
  int v6; // eax@15
  int v7; // eax@18
  HWND v9; // [sp-10h] [bp-1Ch]@17
  const WCHAR *v10; // [sp-Ch] [bp-18h]@17
  UINT v11; // [sp-8h] [bp-14h]@17
  ULONG_PTR v12; // [sp-4h] [bp-10h]@17
  struct tagPOINT Point; // [sp+4h] [bp-8h]@14

  if ( a2 == 83 )
  {
    v7 = GetDlgCtrlID(*(HWND *)(a4 + 12));
    if ( v7 != 257 && v7 != 259 )
      return 0;
    v12 = (ULONG_PTR)dword_1006D38;
    v11 = 12;
    v10 = lpszHelp;
    v9 = *(HWND *)(a4 + 12);
  }
  else
  {
    if ( a2 != 123 )
    {
      if ( a2 == 272 )
      {
        SendDlgItemMessageW(hWndParent, 257, 323u, 0, dword_100C334);
        SendDlgItemMessageW(hWndParent, 257, 0x143u, 0, dword_100C338);
        SendDlgItemMessageW(hWndParent, 257, 0x143u, 0, dword_100C33C);
        SendDlgItemMessageW(hWndParent, 257, 0x143u, 0, dword_100C340);
        v4 = dword_100C334;
        dword_100E040 = dword_100C00C;
        switch ( dword_100C00C )
        {
          case 1:
            v4 = dword_100C338;
            break;
          case 2:
            v4 = dword_100C33C;
            break;
          case 3:
            v4 = dword_100C340;
            break;
        }
        SendDlgItemMessageW(hWndParent, 257, 0x14Du, 0xFFFFFFFFu, v4);
      }
      else
      {
        if ( a2 == 273 )
          dword_100E040 = SendDlgItemMessageW(hWndParent, 257, 0x147u, 0, 0);
      }
      return 0;
    }
    v5 = hWnd;
    if ( hWndParent == hWnd )
    {
      GetCursorPos(&Point);
      ScreenToClient(hWndParent, &Point);
      v5 = ChildWindowFromPoint(hWndParent, Point);
    }
    v6 = GetDlgCtrlID(v5);
    if ( v6 != 257 && v6 != 259 )
      return 0;
    v12 = (ULONG_PTR)dword_1006D38;
    v11 = 10;
    v10 = lpszHelp;
    v9 = v5;
  }
  WinHelpW(v9, v10, v11, v12);
  return 1;
}
// 1006D38: using guessed type int dword_1006D38[6];
// 100C00C: using guessed type int dword_100C00C;
// 100E040: using guessed type int dword_100E040;

//----- (0100739B) --------------------------------------------------------
signed int __stdcall sub_100739B(DWORD hDlg, int a2, HWND hWnd, int a4)
{
  HWND v4; // ebx@1
  LPARAM v5; // ecx@7
  int v6; // eax@16
  int v7; // eax@19
  HWND v9; // eax@24
  HANDLE v10; // eax@26
  int v11; // eax@29
  LPARAM v12; // ecx@29
  int v13; // eax@29
  int v14; // eax@30
  HWND v15; // [sp-10h] [bp-638h]@18
  const WCHAR *v16; // [sp-Ch] [bp-634h]@18
  UINT v17; // [sp-8h] [bp-630h]@18
  ULONG_PTR v18; // [sp-4h] [bp-62Ch]@18
  struct tagPOINT Point; // [sp+Ch] [bp-61Ch]@15
  HANDLE hObject; // [sp+14h] [bp-614h]@26
  DWORD iSize; // [sp+18h] [bp-610h]@1
  char Buffer; // [sp+1Ch] [bp-60Ch]@27
  LPARAM String1; // [sp+41Ch] [bp-20Ch]@24
  unsigned int v24; // [sp+624h] [bp-4h]@1
  int v25; // [sp+628h] [bp+0h]@1

  v24 = (unsigned int)&v25 ^ dword_100C010;
  v4 = hWnd;
  iSize = hDlg;
  if ( a2 == 78 )
  {
    if ( *(_DWORD *)(a4 + 8) == -602 )
    {
      v9 = GetParent((HWND)hDlg);
      if ( SendMessageW(v9, 0x465u, 0x104u, (LPARAM)&String1) > 0 )
      {
        if ( lstrcmpiW((LPCWSTR)&String1, &word_100D588) )
        {
          v10 = CreateFileW((LPCWSTR)&String1, 0x80000000u, 1u, 0, 3u, 0x80u, 0);
          hObject = v10;
          if ( v10 != (HANDLE)-1 )
          {
            if ( ReadFile(v10, &Buffer, 0x400u, &iSize, 0) > 0 )
            {
              if ( iSize )
              {
                v13 = sub_10071C2(&Buffer, iSize);
                v12 = dword_100C334;
                dword_100C00C = v13;
                v11 = v13 - 1;
                if ( v11 )
                {
                  v14 = v11 - 1;
                  if ( v14 )
                  {
                    if ( v14 == 1 )
                      v12 = dword_100C340;
                  }
                  else
                  {
                    v12 = dword_100C33C;
                  }
                }
                else
                {
                  v12 = dword_100C338;
                }
                SendDlgItemMessageW((HWND)hDlg, 257, 0x14Du, 0xFFFFFFFFu, v12);
                sub_1002558((int)&word_100D588, 0x104u, (int)&String1);
              }
            }
            CloseHandle(hObject);
          }
        }
      }
    }
    return 0;
  }
  if ( a2 == 83 )
  {
    v7 = GetDlgCtrlID(*(HWND *)(a4 + 12));
    if ( v7 != 257 && v7 != 259 )
      return 0;
    v18 = (ULONG_PTR)dword_1006D38;
    v17 = 12;
    v16 = lpszHelp;
    v15 = *(HWND *)(a4 + 12);
    goto LABEL_22;
  }
  if ( a2 == 123 )
  {
    if ( (HWND)hDlg == hWnd )
    {
      GetCursorPos(&Point);
      ScreenToClient((HWND)hDlg, &Point);
      v4 = ChildWindowFromPoint((HWND)hDlg, Point);
    }
    v6 = GetDlgCtrlID(v4);
    if ( v6 != 257 && v6 != 259 )
      return 0;
    v18 = (ULONG_PTR)dword_1006D38;
    v17 = 10;
    v16 = lpszHelp;
    v15 = v4;
LABEL_22:
    WinHelpW(v15, v16, v17, v18);
    return 1;
  }
  if ( a2 == 272 )
  {
    SendDlgItemMessageW((HWND)hDlg, 257, 323u, 0, dword_100C334);
    SendDlgItemMessageW((HWND)iSize, 257, 0x143u, 0, dword_100C338);
    SendDlgItemMessageW((HWND)iSize, 257, 0x143u, 0, dword_100C33C);
    SendDlgItemMessageW((HWND)iSize, 257, 0x143u, 0, dword_100C340);
    v5 = dword_100C334;
    switch ( dword_100C00C )
    {
      case 1:
        v5 = dword_100C338;
        break;
      case 2:
        v5 = dword_100C33C;
        break;
      case 3:
        v5 = dword_100C340;
        break;
    }
    SendDlgItemMessageW((HWND)iSize, 257, 0x14Du, 0xFFFFFFFFu, v5);
  }
  else
  {
    if ( a2 == 273 )
      dword_100C00C = SendDlgItemMessageW((HWND)hDlg, 257, 0x147u, 0, 0);
  }
  return 0;
}
// 1006D38: using guessed type int dword_1006D38[6];
// 100C00C: using guessed type int dword_100C00C;
// 100C010: using guessed type int dword_100C010;

//----- (0100765B) --------------------------------------------------------
signed int __stdcall DialogFunc(HWND hWnd, int a2, unsigned __int16 a3, int a4)
{
  int v4; // eax@9
  int v5; // ST10_4@9
  LRESULT v6; // eax@12
  LRESULT v8; // eax@14
  INT_PTR v9; // [sp-4h] [bp-E4h]@7
  LPARAM lParam; // [sp+Ch] [bp-D4h]@14
  WPARAM wParam; // [sp+10h] [bp-D0h]@14
  WCHAR SrcStr; // [sp+14h] [bp-CCh]@9
  unsigned int v13; // [sp+DCh] [bp-4h]@1
  int v14; // [sp+E0h] [bp+0h]@1

  v13 = (unsigned int)&v14 ^ dword_100C010;
  if ( a2 == 272 )
  {
    SendMessageW(dword_100C028, 176u, (WPARAM)&wParam, (LPARAM)&lParam);
    v8 = SendMessageW(dword_100C028, 0xC9u, wParam, 0);
    sub_10015C3(&SrcStr, 0x64u, L"%d", v8 + 1);
    SetDlgItemTextW(hWnd, 258, &SrcStr);
    SetFocus(hWnd);
    return 1;
  }
  if ( a2 != 273 )
    return 0;
  if ( a3 == 1 )
  {
    GetDlgItemTextW(hWnd, 258, &SrcStr, 100);
    FoldStringW(0x80u, &SrcStr, -1, &SrcStr, 100);
    dword_100E160 = wtol(&SrcStr);
    v4 = ((int (__thiscall *)(int, HWND, signed int, int, _DWORD))SendMessageW)(
           v5,
           dword_100C028,
           187,
           dword_100E160 - 1,
           0);
    if ( dword_100E160 && v4 != -1 )
    {
      v9 = 0;
      goto LABEL_8;
    }
    MessageBoxW(hWnd, dword_100C330, lpCaption, 0);
    v6 = SendMessageW(dword_100C028, 0xBAu, 0, 0);
    sub_10015C3(&SrcStr, 0x64u, L"%d", v6);
    SetDlgItemTextW(hWnd, 258, &SrcStr);
    SetFocus(hWnd);
    return 0;
  }
  if ( a3 == 2 )
  {
    v9 = 1;
LABEL_8:
    EndDialog(hWnd, v9);
    return 1;
  }
  if ( a3 != 258 )
    return 0;
  return 1;
}
// 100C010: using guessed type int dword_100C010;
// 100E160: using guessed type int dword_100E160;

//----- (010077F3) --------------------------------------------------------
signed int __stdcall sub_10077F3(int a1)
{
  signed int result; // eax@1

  result = 0;
  if ( !a1 )
  {
    if ( CommDlgExtendedError() )
    {
      sub_100432B();
      result = -2147467259;
    }
    else
    {
      result = -2147023673;
    }
  }
  return result;
}

//----- (01007823) --------------------------------------------------------
signed int __stdcall sub_1007823(int a1, int *a2)
{
  signed int v2; // edi@1
  WCHAR *v3; // eax@2
  int v4; // eax@3

  v2 = -2147467259;
  if ( a2 )
  {
    v3 = (WCHAR *)CoTaskMemAlloc(0x208u);
    *a2 = (int)v3;
    if ( v3 )
    {
      stru_100C1A0.lpstrFile = v3;
      sub_1002558(*a2, 0x104u, (int)L"*.txt");
      stru_100C1A0.lpstrTitle = (LPCWSTR)dword_100C30C;
      stru_100C1A0.lpstrFilter = &Dest;
      stru_100C1A0.lpstrDefExt = L"txt";
      stru_100C1A0.Flags = 8917092;
      stru_100C1A0.nFilterIndex = 1;
      stru_100C1A0.lpTemplateName = (LPCWSTR)15;
      stru_100C1A0.lpfnHook = (LPOFNHOOKPROC)sub_100739B;
      v4 = GetOpenFileNameW(&stru_100C1A0);
      v2 = sub_10077F3(v4);
      if ( v2 < 0 )
        CoTaskMemFree((LPVOID)*a2);
    }
  }
  return v2;
}
// 1003C6C: using guessed type wchar_t aTxt[4];
// 100C30C: using guessed type int dword_100C30C;

//----- (010078D3) --------------------------------------------------------
signed int __stdcall sub_10078D3(int a1, int a2, LPWSTR *a3)
{
  signed int v3; // edi@1
  int v4; // eax@2
  int v5; // eax@3

  v3 = -2147467259;
  if ( a3 )
  {
    v4 = (int)CoTaskMemAlloc(0x208u);
    *a3 = (LPWSTR)v4;
    if ( v4 )
    {
      sub_1002558(v4, 0x104u, a2);
      stru_100C1A0.lpstrFile = *a3;
      stru_100C1A0.lpstrTitle = (LPCWSTR)dword_100C310;
      stru_100C1A0.Flags = 8947814;
      stru_100C1A0.lpTemplateName = (LPCWSTR)15;
      stru_100C1A0.lpfnHook = (LPOFNHOOKPROC)sub_100722E;
      stru_100C1A0.lpstrFilter = &word_100C7E0;
      stru_100C1A0.lpstrDefExt = L"txt";
      dword_100C038 = 1;
      stru_100C1A0.nFilterIndex = 1;
      v5 = GetSaveFileNameW(&stru_100C1A0);
      v3 = sub_10077F3(v5);
      if ( v3 < 0 )
        CoTaskMemFree(*a3);
    }
  }
  return v3;
}
// 1003C6C: using guessed type wchar_t aTxt[4];
// 100C038: using guessed type int dword_100C038;
// 100C310: using guessed type int dword_100C310;

//----- (01007985) --------------------------------------------------------
signed int __usercall sub_1007985<eax>(int a1<ebp>)
{
  signed int result; // eax@1
  HANDLE v2; // edi@1

  v2 = hFile;
  result = sub_1001664(0);
  if ( result )
  {
    hFile = CreateFileW(&word_100D378, 0x80000000u, 3u, 0, 3u, 0x80u, 0);
    if ( hFile == (HANDLE)-1 )
    {
      result = sub_1007BF6(&word_100D378);
    }
    else
    {
      result = sub_1002820(a1, (int)&word_100D378, -1);
      if ( result )
        return result;
    }
    hFile = v2;
  }
  return result;
}

//----- (010079E3) --------------------------------------------------------
void __stdcall sub_10079E3(HDROP hDrop, HWND hWnd)
{
  int ebp0; // ebp@0

  if ( DragQueryFileW(hDrop, -1u, 0, 0) )
  {
    DragQueryFileW(hDrop, 0, (LPWSTR)&word_100D378, 0x104u);
    SetActiveWindow(hWnd);
    sub_1007985(ebp0);
    SHAddToRecentDocs(3u, &word_100D378);
  }
  DragFinish(hDrop);
}

//----- (01007A3C) --------------------------------------------------------
int __stdcall Proc(int a1, int a2, int a3, int a4)
{
  *(_BYTE *)(a4 + 23) = *(_BYTE *)(a1 + 23);
  return 0;
}

//----- (01007A58) --------------------------------------------------------
int __userpurge sub_1007A58<eax>(int result<eax>, int a2, int a3, int a4)
{
  int v4; // edx@1
  int v5; // ecx@2

  v4 = a4;
  if ( a4 )
  {
    result = a3;
    v5 = a2;
    do
    {
      *(_WORD *)v5 = (*(_WORD *)result << 8) ^ *(_BYTE *)(result + 1);
      v5 += 2;
      result += 2;
      --v4;
    }
    while ( v4 );
  }
  return result;
}

//----- (01007A90) --------------------------------------------------------
signed int __stdcall sub_1007A90(HANDLE hFile, UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar)
{
  int v6; // edi@5
  HLOCAL v7; // eax@6
  int v8; // esi@9
  DWORD NumberOfBytesWritten; // [sp+4h] [bp-10h]@10
  char v10; // [sp+8h] [bp-Ch]@4
  LPCVOID hMem; // [sp+Ch] [bp-8h]@6
  LPBOOL lpUsedDefaultChar; // [sp+10h] [bp-4h]@3

  if ( !cchWideChar )
    return 1;
  lpUsedDefaultChar = 0;
  if ( CodePage != 65001 )
    lpUsedDefaultChar = (LPBOOL)&v10;
  v6 = WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, 0, 0, 0, lpUsedDefaultChar);
  if ( !v6 )
    return 0;
  v7 = LocalAlloc(0x40u, v6 + 1);
  hMem = v7;
  if ( !v7 )
  {
    SetLastError(8u);
    return 0;
  }
  v8 = WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, (LPSTR)v7, v6, 0, lpUsedDefaultChar);
  if ( v8 )
    v8 = WriteFile(hFile, hMem, v6, &NumberOfBytesWritten, 0);
  LocalFree((HLOCAL)hMem);
  return v8;
}

//----- (01007B40) --------------------------------------------------------
LRESULT __cdecl sub_1007B40()
{
  LRESULT result; // eax@5

  if ( wParam )
  {
    if ( dword_100C040 )
    {
      sub_1006FB9(1);
    }
    else
    {
      SendMessageW(dword_100C028, 0xB0u, (WPARAM)&dword_100D794, (LPARAM)&dword_100D790);
      SendMessageW(dword_100C028, 0xB1u, 0, 0);
    }
    result = SendMessageW(dword_100C028, 0xC8u, 0, 0);
  }
  return result;
}
// 100C040: using guessed type int dword_100C040;

//----- (01007BA2) --------------------------------------------------------
LRESULT __cdecl sub_1007BA2()
{
  LRESULT result; // eax@1

  result = 0;
  if ( wParam )
  {
    if ( dword_100C040 )
    {
      result = sub_1008383(0x50200104u);
    }
    else
    {
      SendMessageW(dword_100C028, 200u, 1u, 0);
      result = SendMessageW(dword_100C028, 0xB1u, dword_100D794, dword_100D790);
    }
  }
  return result;
}
// 100C040: using guessed type int dword_100C040;

//----- (01007BF6) --------------------------------------------------------
int __stdcall sub_1007BF6(LPCWSTR lpString)
{
  DWORD v1; // eax@1
  int result; // eax@2
  WCHAR Text; // [sp+4h] [bp-204h]@1
  unsigned int v4; // [sp+204h] [bp-4h]@1
  int v5; // [sp+208h] [bp+0h]@1

  v4 = (unsigned int)&v5 ^ dword_100C010;
  v1 = GetLastError();
  if ( FormatMessageW(0x1200u, 0, v1, 0, &Text, 0x100u, 0) )
    result = MessageBoxW(hWnd, &Text, szApp, 0x30u);
  else
    result = sub_1007051(hWnd, szApp, dword_100C2B0, lpString, 0x30u);
  return result;
}
// 100C010: using guessed type int dword_100C010;

//----- (01007C80) --------------------------------------------------------
signed int __userpurge sub_1007C80<eax>(int a1<eax>, int a2<edx>, int a3<ecx>, int a4, int a5)
{
  signed int result; // eax@1
  int v6; // ebx@1
  int v7; // edi@1
  int v8; // esi@1

  v6 = a1;
  v8 = a2;
  result = 0;
  v7 = 0;
  if ( !a2 )
    goto LABEL_11;
  do
  {
    if ( !a5 )
      break;
    if ( !*(_WORD *)v6 )
      break;
    *(_WORD *)a3 = *(_WORD *)v6;
    a3 += 2;
    v6 += 2;
    --v8;
    --a5;
    ++v7;
  }
  while ( v8 );
  if ( !v8 )
  {
LABEL_11:
    a3 -= 2;
    --v7;
    result = -2147024774;
  }
  *(_WORD *)a3 = 0;
  if ( a4 )
    *(_DWORD *)a4 = v7;
  return result;
}

//----- (01007CD7) --------------------------------------------------------
signed int __stdcall sub_1007CD7(HWND hWnd, LPCWSTR lpString1, LPCWSTR lpBuffer)
{
  DWORD v3; // eax@1
  DWORD v5; // eax@8
  bool v6; // ecx@8
  LRESULT v7; // eax@10
  int v8; // ebx@10
  BOOL *v9; // eax@17
  DWORD v10; // edi@17
  int v11; // eax@19
  BOOL v12; // eax@24
  int v13; // edi@25
  int v14; // eax@25
  bool v15; // [sp+4h] [bp-14h]@8
  BOOL UsedDefaultChar; // [sp+8h] [bp-10h]@1
  HLOCAL hMem; // [sp+Ch] [bp-Ch]@10
  UINT CodePage; // [sp+10h] [bp-8h]@17
  DWORD NumberOfBytesWritten; // [sp+14h] [bp-4h]@15
  const void *v20; // [sp+28h] [bp+10h]@11

  v3 = 1;
  UsedDefaultChar = 0;
  if ( lpBuffer )
    v3 = 3;
  hFile = CreateFileW(lpString1, 0xC0000000u, v3, 0, 4u, 0x80u, 0);
  if ( hFile == (HANDLE)-1 )
  {
    if ( lpBuffer || GetLastError() != 5 )
      sub_1007BF6(lpString1);
    return 0;
  }
  v5 = GetLastError();
  v6 = v5 != 183;
  v15 = v5 != 183;
  if ( wParam )
    sub_1007B40();
  v8 = ((int (__thiscall *)(bool, HWND, signed int, _DWORD, _DWORD))SendMessageW)(v6, dword_100C028, 14, 0, 0);
  v7 = SendMessageW(dword_100C028, 0xBDu, 0, 0);
  hMem = (HLOCAL)v7;
  if ( !v7 || (v20 = LocalLock((HLOCAL)v7), !v20) )
    goto LABEL_30;
  if ( dword_100E040 == 1 )
  {
    WriteFile(hFile, &unk_100CD54, 2u, &NumberOfBytesWritten, 0);
    v12 = WriteFile(hFile, v20, 2 * v8, &NumberOfBytesWritten, 0);
  }
  else
  {
    if ( dword_100E040 == 2 )
    {
      v14 = WriteFile(hFile, &unk_100CD58, 2u, &NumberOfBytesWritten, 0);
      sub_1007A58(v14, (int)v20, (int)v20, v8);
      v13 = WriteFile(hFile, v20, 2 * v8, &NumberOfBytesWritten, 0);
      sub_1007A58(v13, (int)v20, (int)v20, v8);
      goto LABEL_28;
    }
    if ( dword_100E040 == 3 )
      WriteFile(hFile, &unk_100CD50, 3u, &NumberOfBytesWritten, 0);
    if ( dword_100E040 == 3 )
    {
      v9 = 0;
      CodePage = 65001;
      v10 = 0;
    }
    else
    {
      CodePage = GetACP();
      v9 = &UsedDefaultChar;
      v10 = 1024;
    }
    v11 = WideCharToMultiByte(CodePage, v10, (LPCWSTR)v20, v8, 0, 0, 0, v9);
    if ( UsedDefaultChar || v8 && !v11 )
    {
      if ( sub_1007051(hWnd, szApp, dword_100C320, lpString1, 0x31u) == 2 )
      {
LABEL_31:
        SetCursor(dword_100C094);
        CloseHandle(hFile);
        hFile = (HANDLE)-1;
        if ( hMem )
          LocalUnlock(hMem);
        if ( v15 )
          DeleteFileW(lpString1);
        if ( wParam )
          sub_1007BA2();
        return 0;
      }
      v10 = 0;
    }
    v12 = sub_1007A90(hFile, CodePage, v10, (LPCWSTR)v20, v8);
  }
  v13 = v12;
LABEL_28:
  if ( !v13 )
  {
    SetCursor(dword_100C094);
LABEL_30:
    sub_1007BF6(lpString1);
    goto LABEL_31;
  }
  SetEndOfFile(hFile);
  dword_100C00C = dword_100E040;
  SendMessageW(dword_100C028, 0xB9u, 0, 0);
  sub_1002456(lpString1);
  dword_100C008 = 0;
  CloseHandle(hFile);
  hFile = (HANDLE)-1;
  LocalUnlock(hMem);
  if ( wParam )
    sub_1007BA2();
  SetCursor(dword_100C094);
  return 1;
}
// 100C008: using guessed type int dword_100C008;
// 100C00C: using guessed type int dword_100C00C;
// 100E040: using guessed type int dword_100E040;

//----- (01007F99) --------------------------------------------------------
signed int __stdcall sub_1007F99(int a1, unsigned int a2, int a3)
{
  signed int result; // eax@1
  unsigned int v4; // edx@1
  int v5; // eax@5
  int v6; // ecx@5
  unsigned int v7; // esi@5
  signed int v8; // [sp+14h] [bp+Ch]@5

  v4 = a2;
  result = 0;
  if ( !a2 || a2 > 0x7FFFFFFF )
    result = -2147024809;
  if ( result < 0 )
  {
    v6 = 0;
  }
  else
  {
    v8 = 0;
    v6 = 0;
    v7 = v4;
    v5 = a1;
    if ( !v4 )
      goto LABEL_17;
    do
    {
      if ( !*(_WORD *)v5 )
        break;
      v5 += 2;
      --v7;
    }
    while ( v7 );
    if ( v7 )
      v6 = v4 - v7;
    else
LABEL_17:
      v8 = -2147024809;
    result = v8;
  }
  if ( result >= 0 )
    result = sub_1007C80(a3, v4 - v6, a1 + 2 * v6, 0, 2147483647);
  return result;
}

//----- (0100800F) --------------------------------------------------------
signed int __stdcall sub_100800F(int a1)
{
  signed int result; // eax@2
  HLOCAL v2; // eax@3

  if ( !a1 || (result = sub_1001664(0)) != 0 )
  {
    SendMessageW(dword_100C028, 12u, 0, (LPARAM)&szOtherStuff);
    dword_100C008 = 1;
    sub_1002558((int)&FileName, 0x104u, (int)lpString2);
    sub_1002456(&FileName);
    SendMessageW(dword_100C028, 0xB1u, 0, 0);
    SendMessageW(dword_100C028, 0xB7u, 0, 0);
    v2 = LocalReAlloc(hMem, 2u, 2u);
    if ( v2 )
      hMem = v2;
    *(_WORD *)LocalLock(hMem) = 0;
    LocalUnlock(hMem);
    SendMessageW(dword_100C028, 0xBCu, (WPARAM)hMem, 0);
    result = 0;
    word_100C9E0 = 0;
  }
  return result;
}
// 100C008: using guessed type int dword_100C008;

//----- (010080E4) --------------------------------------------------------
int __stdcall sub_10080E4(int lpString, unsigned int a2)
{
  int result; // eax@1
  unsigned int i; // ecx@1
  int v4; // edx@6

  result = lstrlenW((LPCWSTR)lpString);
  for ( i = lpString + 2 * result; ; i -= 2 )
  {
    v4 = *(_WORD *)i;
    if ( v4 == 46 )
      break;
    if ( v4 == 92 || v4 == 58 || i <= lpString )
      break;
  }
  if ( *(_WORD *)i != 46 )
  {
    result += 5;
    if ( (unsigned int)result <= 0x104 )
      result = sub_1007F99(lpString, a2, (int)L".txt");
  }
  return result;
}
// 1008134: using guessed type wchar_t a_txt_0[5];

//----- (01008143) --------------------------------------------------------
int __stdcall sub_1008143(int a1, int a2, int a3, int a4, int a5)
{
  int v5; // eax@1
  int result; // eax@3

  v5 = FindNLSString(1024, a4 == 0 | 0x800000, a1, a2, a3, -1, a5);
  if ( v5 == -1 || *(_DWORD *)a5 < 1 )
    result = 0;
  else
    result = a1 + 2 * v5;
  return result;
}
// 100102C: using guessed type int __stdcall FindNLSString(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD);

//----- (0100818F) --------------------------------------------------------
int __stdcall sub_100818F(int a1, int a2, int a3, int a4, int a5)
{
  int v5; // eax@1
  int result; // eax@3

  v5 = FindNLSString(1024, a4 == 0 | 0x400000, a1, a2, a3, -1, a5);
  if ( v5 == -1 || *(_DWORD *)a5 < 1 )
    result = 0;
  else
    result = a1 + 2 * v5;
  return result;
}
// 100102C: using guessed type int __stdcall FindNLSString(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD);

//----- (010081DB) --------------------------------------------------------
signed int __stdcall sub_10081DB(int a1)
{
  signed int result; // eax@2
  HMENU v2; // eax@3
  HMENU v3; // eax@3
  LRESULT v4; // eax@5
  int v5; // ebx@6
  int v6; // eax@9
  int v7; // eax@11
  int v8; // eax@12
  int v9; // esi@13
  HWND v10; // eax@15
  HCURSOR v11; // edi@15
  HMENU v12; // eax@19
  HMENU v13; // [sp+4h] [bp-1Ch]@3
  void *v14; // [sp+8h] [bp-18h]@5
  signed int v15; // [sp+Ch] [bp-14h]@1
  signed int v16; // [sp+10h] [bp-10h]@1
  int v17; // [sp+14h] [bp-Ch]@11
  WPARAM wParam; // [sp+18h] [bp-8h]@3
  LPARAM lParam; // [sp+1Ch] [bp-4h]@3

  v15 = 0;
  v16 = 0;
  if ( *(_WORD *)a1 )
  {
    SendMessageW(dword_100C028, 176u, (WPARAM)&wParam, (LPARAM)&lParam);
    v2 = GetMenu(hWnd);
    v13 = v2;
    v3 = GetSubMenu(v2, 1);
    if ( GetMenuState(v3, 0x19u, 0) == 1 )
    {
      v16 = 1;
      lParam = 0;
    }
    v4 = SendMessageW(dword_100C028, 0xBDu, 0, 0);
    v14 = (void *)v4;
    if ( v4 && (v5 = (int)LocalLock((HLOCAL)v4)) != 0 )
    {
      if ( dword_100D79C )
      {
        v6 = lParam;
        if ( wParam != lParam )
          v6 = lParam - 1;
        v7 = sub_1008143(v5, v6, a1, dword_100D798, (int)&v17);
      }
      else
      {
        v8 = GetWindowTextLengthW(dword_100C028);
        v7 = sub_100818F(v5 + 2 * lParam, v8 - lParam, a1, dword_100D798, (int)&v17);
      }
      v9 = v7;
      LocalUnlock(v14);
      if ( v9 )
      {
        wParam = (v9 - v5) >> 1;
        SendMessageW(dword_100C028, 0xB1u, wParam, wParam + v17);
        if ( v16 )
        {
          v12 = GetSubMenu(v13, 1);
          EnableMenuItem(v12, 0x19u, 0);
        }
        if ( !(stru_100C0C0.Flags & 0x20) )
        {
          SendMessageW(dword_100C028, 0xB7u, 0, 0);
          sub_100170A(1u);
        }
        v15 = 1;
      }
      else
      {
        if ( !(stru_100C0C0.Flags & 0x20) )
        {
          v11 = SetCursor(dword_100C094);
          v10 = dword_100CCE8;
          if ( !dword_100CCE8 )
            v10 = hWnd;
          sub_1007051(v10, szApp, dword_100C2C4, &word_100C9E0, 0x40u);
          SetCursor(v11);
        }
      }
      result = v15;
    }
    else
    {
      result = 0;
    }
  }
  else
  {
    result = 0;
  }
  return result;
}
// 100D798: using guessed type int dword_100D798;
// 100D79C: using guessed type int dword_100D79C;

//----- (01008383) --------------------------------------------------------
signed int __stdcall sub_1008383(DWORD hWnd)
{
  LONG v2; // eax@12
  struct tagRECT Rect; // [sp+Ch] [bp-38h]@8
  int v4; // [sp+1Ch] [bp-28h]@17
  int v5; // [sp+20h] [bp-24h]@17
  int v6; // [sp+24h] [bp-20h]@17
  int v7; // [sp+28h] [bp-1Ch]@17
  WPARAM wParam; // [sp+2Ch] [bp-18h]@3
  LPARAM lParam; // [sp+30h] [bp-14h]@8
  LRESULT v10; // [sp+34h] [bp-10h]@3
  DWORD v11; // [sp+38h] [bp-Ch]@1
  HCURSOR hCursor; // [sp+3Ch] [bp-8h]@1
  HLOCAL hMem; // [sp+40h] [bp-4h]@3
  HWND v14; // [sp+4Ch] [bp+8h]@8

  v11 = (hWnd >> 20) & 1;
  hCursor = SetCursor(::hCursor);
  if ( (hWnd >> 20) & 1 )
  {
    sub_1006FB9(1);
    SendMessageW(dword_100C028, 0xC8u, 0, 0);
  }
  wParam = SendMessageW(dword_100C028, 0xB8u, 0, 0) != 0;
  v10 = SendMessageW(dword_100C028, 0xEu, 0, 0);
  hMem = LocalAlloc(2u, 2 * v10 + 2);
  if ( !hMem )
  {
    if ( v11 )
      SendMessageW(dword_100C028, 0xC8u, 1u, 0);
    SetCursor(hCursor);
    return 0;
  }
  GetClientRect(::hWnd, &Rect);
  lParam = (LPARAM)LocalLock(hMem);
  SendMessageW(dword_100C028, 0xDu, v10 + 1, lParam);
  v14 = CreateWindowExW(
          0x200u,
          L"Edit",
          &szOtherStuff,
          hWnd,
          0,
          0,
          Rect.right,
          Rect.bottom,
          ::hWnd,
          (HMENU)0xF,
          hInstance,
          0);
  if ( !v14 )
  {
    SetCursor(hCursor);
    if ( v11 )
      SendMessageW(dword_100C028, 0xC8u, 1u, 0);
LABEL_11:
    LocalUnlock(hMem);
    LocalFree(hMem);
    return 0;
  }
  v2 = GetWindowLongW(dword_100C028, -20);
  SetWindowLongW(v14, -20, v2 | 0x200);
  SendMessageW(v14, 0x30u, (WPARAM)ho, 1);
  if ( !SendMessageW(v14, 0xCu, 0, lParam) )
  {
    SetCursor(hCursor);
    if ( v11 )
      SendMessageW(dword_100C028, 0xC8u, 1u, 0);
    DestroyWindow(v14);
    goto LABEL_11;
  }
  LocalUnlock(hMem);
  LocalFree(hMem);
  DestroyWindow(dword_100C028);
  dword_100C028 = v14;
  ::hMem = (HLOCAL)SendMessageW(v14, 0xBDu, 0, 0);
  PostMessageW(dword_100C028, 0xC5u, 0, 0);
  ShowWindow(::hWnd, 5);
  SendMessageW(dword_100C028, 0xB9u, wParam, 0);
  SetFocus(dword_100C028);
  SetCursor(hCursor);
  if ( *(_DWORD *)&dword_100C02C )
  {
    GetClientRect(::hWnd, (LPRECT)&v4);
    sub_1002409(v6 - v4, v7 - v5);
    sub_100170A(1u);
    ShowWindow(dword_100C024, 5);
  }
  return 1;
}

//----- (010085E5) --------------------------------------------------------
int __stdcall sub_10085E5(int a1, int a2, int a3, int a4)
{
  int v4; // eax@1
  int v5; // ebx@1
  int v6; // eax@2
  int v7; // ecx@3
  int v9; // [sp+Ch] [bp-4h]@1

  v4 = a1;
  v5 = 0;
  v9 = 0;
  *(_DWORD *)a4 = 0;
  while ( 1 )
  {
    v6 = sub_100818F(v4, a2 - ((v4 - a1) >> 1), a3, dword_100D798, (int)&v9);
    if ( !v6 )
      break;
    v7 = v9;
    ++v5;
    *(_DWORD *)a4 += v9;
    v4 = v6 + 2 * v7;
  }
  return v5;
}
// 100D798: using guessed type int dword_100D798;

//----- (01008639) --------------------------------------------------------
size_t __cdecl sub_1008639()
{
  LRESULT v0; // eax@1
  size_t result; // eax@2
  int v2; // eax@4
  int v3; // ebx@4
  int v4; // edi@4
  int v5; // eax@4
  int v6; // eax@7
  int v7; // esi@7
  int v8; // eax@7
  HGLOBAL v9; // edi@8
  int v10; // eax@11
  int v11; // ebx@11
  int v12; // eax@11
  int v13; // ST2C_4@11
  void *v14; // edi@11
  char v15; // zf@11
  void *v16; // [sp+4h] [bp-24h]@1
  LPARAM v17; // [sp+8h] [bp-20h]@4
  int v18; // [sp+10h] [bp-18h]@4
  int v19; // [sp+14h] [bp-14h]@7
  size_t Size; // [sp+18h] [bp-10h]@1
  HGLOBAL hMem; // [sp+1Ch] [bp-Ch]@8
  int v22; // [sp+20h] [bp-8h]@7
  void *Src; // [sp+24h] [bp-4h]@3

  Size = 0;
  v0 = SendMessageW(dword_100C028, 0xBDu, 0, 0);
  v16 = (void *)v0;
  if ( v0 && (Src = LocalLock((HLOCAL)v0)) != 0 )
  {
    v5 = GetWindowTextLengthW(dword_100C028);
    v4 = v5;
    v17 = v5;
    v2 = sub_10085E5((int)Src, v5, (int)&word_100C9E0, (int)&v18);
    v3 = v2;
    if ( v2 )
    {
      if ( v2 > 1 )
      {
        v8 = lstrlenW(stru_100C0C0.lpstrReplaceWith);
        v19 = v8;
        v22 = v4;
        v6 = v4 + v3 * v8 - v18;
        v7 = 2 * v6 + 2;
        if ( v7 > 0 )
        {
          v9 = GlobalAlloc(0, 2 * v6 + 2);
          hMem = v9;
          if ( v9 )
          {
            if ( v3 > 0 )
            {
              Size = 2 * v19;
              v18 = v3;
              do
              {
                v10 = sub_100818F((int)Src, v22, (int)&word_100C9E0, dword_100D798, (int)&v19);
                v11 = v10;
                v12 = (v10 - (_DWORD)Src) >> 1;
                v22 -= v12 + v19;
                v13 = 2 * v12;
                memcpy(v9, Src, 2 * v12);
                v14 = (char *)v9 + v13;
                memcpy(v14, stru_100C0C0.lpstrReplaceWith, Size);
                v9 = (char *)v14 + Size;
                v15 = v18-- == 1;
                Src = (void *)(v11 + 2 * v19);
              }
              while ( !v15 );
            }
            memcpy(v9, Src, v7 - 2 * ((signed int)(v9 - hMem) >> 1));
            SendMessageW(dword_100C028, 177u, 0, v17);
            SendMessageW(dword_100C028, 0xC2u, 1u, (LPARAM)hMem);
            GlobalFree(hMem);
            Size = 1;
          }
        }
      }
    }
    else
    {
      Size = 1;
    }
    LocalUnlock(v16);
    result = Size;
  }
  else
  {
    result = 0;
  }
  return result;
}
// 100D798: using guessed type int dword_100D798;

//----- (010087C5) --------------------------------------------------------
bool __stdcall proc(int a1, int a2)
{
  struct tagMSG Msg; // [sp+4h] [bp-1Ch]@2

  while ( !dword_100DE34 && PeekMessageW(&Msg, 0, 0, 0, 1u) )
  {
    if ( !hDlg || !IsDialogMessageW(hDlg, &Msg) )
    {
      TranslateMessage(&Msg);
      DispatchMessageW(&Msg);
    }
  }
  return dword_100DE34 == 0;
}
// 100DE34: using guessed type int dword_100DE34;

//----- (0100882E) --------------------------------------------------------
int __stdcall sub_100882E(HDC hdc)
{
  int result; // eax@1

  dword_100D7D8 = GetDeviceCaps(hdc, 8);
  dword_100D7D4 = GetDeviceCaps(hdc, 10);
  dword_100D7D0 = GetDeviceCaps(hdc, 90);
  dword_100D7CC = GetDeviceCaps(hdc, 110);
  y = GetDeviceCaps(hdc, 111);
  dword_100D7C4 = GetDeviceCaps(hdc, 112);
  result = GetDeviceCaps(hdc, 113);
  dword_100D7C0 = result;
  return result;
}
// 100D7C0: using guessed type int dword_100D7C0;
// 100D7C4: using guessed type int dword_100D7C4;
// 100D7D0: using guessed type int dword_100D7D0;
// 100D7D4: using guessed type int dword_100D7D4;
// 100D7D8: using guessed type int dword_100D7D8;

//----- (0100888F) --------------------------------------------------------
BOOL __cdecl sub_100888F()
{
  BOOL result; // eax@1

  EnableWindow(hWnd, 1);
  result = DestroyWindow(hDlg);
  hDlg = 0;
  return result;
}

//----- (010088B6) --------------------------------------------------------
signed int __cdecl sub_10088B6()
{
  signed int result; // eax@3
  const DEVMODEW *v1; // eax@4
  LPVOID v2; // esi@4
  HDC v3; // edi@6

  if ( stru_100C140.hDevNames
    || (stru_100C140.Flags |= 0x400u,
        PageSetupDlgW(&stru_100C140),
        stru_100C140.Flags &= 0xFFFFFBFFu,
        stru_100C140.hDevNames) )
  {
    v2 = GlobalLock(stru_100C140.hDevNames);
    v1 = 0;
    if ( stru_100C140.hDevMode )
      v1 = (const DEVMODEW *)GlobalLock(stru_100C140.hDevMode);
    v3 = CreateDCW((LPCWSTR)v2 + *(_WORD *)v2, (LPCWSTR)v2 + *((_WORD *)v2 + 1), 0, v1);
    GlobalUnlock(stru_100C140.hDevNames);
    if ( stru_100C140.hDevMode )
      GlobalUnlock(stru_100C140.hDevMode);
    if ( v3 )
    {
      result = (signed int)v3;
    }
    else
    {
      MessageBoxW(hWnd, dword_100C318, szApp, 0x30u);
      result = -1;
    }
  }
  else
  {
    MessageBoxW(hWnd, dword_100C318, szApp, 0x30u);
    result = -1;
  }
  return result;
}

//----- (01008987) --------------------------------------------------------
signed int __cdecl sub_1008987()
{
  HLOCAL v1; // esi@3
  HDC v2; // edi@7
  DWORD pcbNeeded; // [sp+8h] [bp-8h]@3
  HANDLE hPrinter; // [sp+Ch] [bp-4h]@1

  if ( !OpenPrinterW(&pPrinterName, &hPrinter, 0) )
    return -1;
  GetPrinterDriverW(hPrinter, 0, 1u, 0, 0, &pcbNeeded);
  v1 = LocalAlloc(0x40u, pcbNeeded);
  if ( !v1 )
    goto LABEL_6;
  if ( !GetPrinterDriverW(hPrinter, 0, 1u, (LPBYTE)v1, pcbNeeded, &pcbNeeded) )
  {
    LocalFree(v1);
LABEL_6:
    ClosePrinter(hPrinter);
    return -1;
  }
  stru_100C140.Flags |= 0x400u;
  PageSetupDlgW(&stru_100C140);
  stru_100C140.Flags &= 0xFFFFFBFFu;
  v2 = CreateDCW(*(LPCWSTR *)v1, &pPrinterName, 0, 0);
  LocalFree(v1);
  ClosePrinter(hPrinter);
  if ( !v2 )
  {
    MessageBoxW(hWnd, dword_100C318, szApp, 0x30u);
    return -1;
  }
  return (signed int)v2;
}

//----- (01008A63) --------------------------------------------------------
signed int __stdcall sub_1008A63(HWND hWnd, int a2, int a3, int a4)
{
  LPCWSTR v5; // eax@8

  if ( a2 == 272 )
  {
    dword_100D7A0 = GetSystemMenu(hWnd, 0);
    if ( dword_100C008 )
      v5 = lpString2;
    else
      v5 = sub_1007008(&FileName);
    SetDlgItemTextW(hWnd, 20, v5);
    SetFocus(hWnd);
  }
  else
  {
    if ( a2 == 273 )
    {
      dword_100DE34 = 1;
      sub_100888F();
    }
    else
    {
      if ( a2 != 278 )
        return 0;
      EnableMenuItem(dword_100D7A0, 0xF060u, 1u);
    }
  }
  return 1;
}
// 100C008: using guessed type int dword_100C008;
// 100DE34: using guessed type int dword_100DE34;

//----- (01008AEF) --------------------------------------------------------
signed int __stdcall sub_1008AEF(int a1, int a2, int a3, int a4)
{
  signed int result; // eax@1

  result = 0;
  if ( !a2 || (unsigned int)a2 > 0x7FFFFFFF )
    result = -2147024809;
  if ( result >= 0 )
  {
    if ( (unsigned int)a4 <= 0x7FFFFFFE )
    {
      result = sub_1007C80(a3, a2, a1, 0, a4);
    }
    else
    {
      result = -2147024809;
      *(_WORD *)a1 = 0;
    }
  }
  return result;
}

//----- (01008B3E) --------------------------------------------------------
int *__stdcall sub_1008B3E(int a1)
{
  const WCHAR v1; // cx@1
  int *result; // eax@2
  int *v3; // edx@4
  int v4; // edi@4
  int *v5; // ebx@6
  int v6; // edi@6
  int v7; // edx@8
  int v8; // edx@9
  __int16 v9; // cx@9
  int v10; // eax@29
  int v11; // eax@31
  int v12; // eax@32
  int v13; // edx@34
  char v14; // zf@34
  wint_t v15; // ax@35
  int v16; // edx@35
  int v17; // edx@36
  signed int v18; // ecx@50
  int v19; // edx@51
  const WCHAR *v20; // [sp-8h] [bp-238h]@30
  int v21; // [sp-4h] [bp-234h]@30
  int v22; // [sp+Ch] [bp-224h]@1
  int v23; // [sp+10h] [bp-220h]@1
  int v24; // [sp+14h] [bp-21Ch]@1
  int v25; // [sp+18h] [bp-218h]@29
  int v26; // [sp+1Ch] [bp-214h]@1
  int v27; // [sp+20h] [bp-210h]@1
  const WCHAR Buf; // [sp+24h] [bp-20Ch]@38
  unsigned int v29; // [sp+22Ch] [bp-4h]@1
  int v30; // [sp+230h] [bp+0h]@1

  v29 = (unsigned int)&v30 ^ dword_100C010;
  v1 = *(_WORD *)a1;
  v27 = a1;
  v26 = 1;
  v22 = 0;
  v23 = 0;
  v24 = 0;
  if ( v1 )
  {
    result = (int *)dword_100C300;
LABEL_5:
    if ( v1 )
      goto LABEL_3;
    while ( 1 )
    {
      v5 = &v22 + v26;
      v6 = *v5;
      if ( (unsigned int)*v5 >= 0x104 || v6 < 0 )
        return result;
      v7 = v27;
      if ( *(_WORD *)v27 == 38 )
        break;
LABEL_49:
      v1 = *(_WORD *)v7;
      if ( !*(_WORD *)v7 )
        goto LABEL_50;
LABEL_3:
      if ( v1 != 38 )
      {
        v27 += 2;
        v3 = &v22 + v26;
        v4 = *v3;
        *(&word_100D800 + *v3 + 260 * v26) = v1;
        v1 = *(_WORD *)v27;
        *v3 = v4 + 1;
        goto LABEL_5;
      }
    }
    v8 = v27 + 2;
    v9 = *(_WORD *)(v27 + 2);
    v27 += 2;
    if ( v9 == *(_WORD *)result || v9 == *((_WORD *)result + 1) )
    {
      if ( dword_100C008 )
        sub_1002558((int)&Buf, 0x104u, (int)lpString2);
      else
        GetFileTitleW(&FileName, (LPWSTR)&Buf, 0x104u);
      if ( v6 + lstrlenW(&Buf) >= 260 )
        goto LABEL_47;
      sub_1002558((int)(&word_100D800 + v6 + 260 * v26), 260 - v6, (int)&Buf);
      v11 = v6 + lstrlenW(&Buf);
      goto LABEL_46;
    }
    if ( v9 == *((_WORD *)result + 2) || v9 == *((_WORD *)result + 3) )
    {
      v25 = 0;
      v13 = v8 + 2;
      v14 = *(_WORD *)v13 == 43;
      v27 = v13;
      if ( v14 )
      {
        v16 = v13 + 2;
        v15 = *(_WORD *)v16;
        v27 = v16;
        while ( iswctype(v15, 4u) )
        {
          v17 = *(_WORD *)v27;
          v27 += 2;
          v15 = *(_WORD *)v27;
          v25 = 10 * v25 + v17 - 48;
        }
      }
      sub_10015C3((wchar_t *)&Buf, 0x104u, L"%d", v25 + *(_DWORD *)dword_100D7AC);
      if ( v6 + lstrlenW(&Buf) < 260 )
      {
        sub_1002558((int)(&word_100D800 + v6 + 260 * v26), 260 - v6, (int)&Buf);
        *v5 = v6 + lstrlenW(&Buf);
      }
      v27 -= 2;
      goto LABEL_47;
    }
    if ( v9 == *((_WORD *)result + 4) || v9 == *((_WORD *)result + 5) )
    {
      v12 = lstrlenW(&word_100CF68);
      v25 = v6 + v12;
      if ( v6 + v12 < 260 )
      {
        v21 = v12;
        v20 = &word_100CF68;
        goto LABEL_31;
      }
    }
    else
    {
      if ( v9 != *((_WORD *)result + 6) && v9 != *((_WORD *)result + 7) )
      {
        if ( v9 == 38 )
        {
          if ( v6 + 1 < 260 )
          {
            *(&word_100D800 + v6 + 260 * v26) = 38;
            *v5 = v6 + 1;
          }
        }
        else
        {
          if ( v9 == *((_WORD *)result + 8) || v9 == *((_WORD *)result + 9) )
          {
            v26 = 1;
          }
          else
          {
            if ( v9 == *((_WORD *)result + 10) || v9 == *((_WORD *)result + 11) )
            {
              v26 = 2;
            }
            else
            {
              if ( v9 == *((_WORD *)result + 12) || v9 == *((_WORD *)result + 13) )
                v26 = 0;
            }
          }
        }
        goto LABEL_48;
      }
      v10 = lstrlenW(&word_100CD60);
      v25 = v6 + v10;
      if ( v6 + v10 < 260 )
      {
        v21 = v10;
        v20 = &word_100CD60;
LABEL_31:
        sub_1008AEF((int)(&word_100D800 + v6 + 260 * v26), 260 - v6, (int)v20, v21);
        v11 = v25;
LABEL_46:
        *v5 = v11;
        goto LABEL_47;
      }
    }
LABEL_47:
    result = (int *)dword_100C300;
LABEL_48:
    v7 = v27 + 2;
    v27 += 2;
    goto LABEL_49;
  }
LABEL_50:
  v18 = 0;
  result = &v22;
  do
  {
    v19 = v18 + *result;
    v18 += 260;
    ++result;
    *(&word_100D800 + v19) = 0;
  }
  while ( v18 <= 520 );
  return result;
}
// 100C008: using guessed type int dword_100C008;
// 100C010: using guessed type int dword_100C010;
// 100C300: using guessed type int dword_100C300;

//----- (01008EF2) --------------------------------------------------------
signed int __stdcall sub_1008EF2(HDC hdc, int y)
{
  __int16 v2; // bx@1
  signed int result; // eax@2
  int v4; // eax@4
  int v5; // eax@7
  int v6; // eax@9
  int v7; // edi@9
  int v8; // eax@9
  int v9; // eax@11
  int v10; // edi@11
  int v11; // eax@11
  struct tagSIZE psizl; // [sp+4h] [bp-8h]@9
  int v13; // [sp+18h] [bp+Ch]@6

  v2 = 0;
  if ( *(&word_100C740 + 40 * y) )
  {
    sub_1008B3E((int)(&word_100C740 + 40 * y));
    if ( y )
      v4 = dword_100D7D4 - dword_100DE30 - dword_100D7B8;
    else
      v4 = dword_100D7BC;
    v13 = v4;
    if ( word_100D800 )
    {
      v5 = lstrlenW(&word_100D800);
      TextOutW(hdc, x, v13, &word_100D800, v5);
    }
    if ( word_100DA08 )
    {
      v6 = lstrlenW(&word_100DA08);
      GetTextExtentPoint32W(hdc, &word_100DA08, v6, &psizl);
      v7 = (x + dword_100D7D8 - dword_100D7B0) / 2 - psizl.cx / 2;
      v8 = lstrlenW(&word_100DA08);
      TextOutW(hdc, v7, v13, &word_100DA08, v8);
      v2 = 0;
    }
    if ( word_100DC10 != v2 )
    {
      v9 = lstrlenW(&word_100DC10);
      GetTextExtentPoint32W(hdc, &word_100DC10, v9, &psizl);
      v10 = dword_100D7D8 - dword_100D7B0 - psizl.cx;
      v11 = lstrlenW(&word_100DC10);
      TextOutW(hdc, v10, v13, &word_100DC10, v11);
    }
    result = 1;
  }
  else
  {
    result = 0;
  }
  return result;
}
// 100D7B0: using guessed type int dword_100D7B0;
// 100D7B8: using guessed type int dword_100D7B8;
// 100D7BC: using guessed type int dword_100D7BC;
// 100D7D4: using guessed type int dword_100D7D4;
// 100D7D8: using guessed type int dword_100D7D8;
// 100DE30: using guessed type int dword_100DE30;

//----- (0100900D) --------------------------------------------------------
signed int __stdcall sub_100900D(HDC a1)
{
  HFONT v1; // eax@1
  DWORD v2; // esi@1
  HDC v3; // ST0C_4@1
  HFONT v4; // eax@5
  HGDIOBJ v5; // eax@5
  __int32 v6; // eax@16
  DWORD v7; // edi@21
  LRESULT v8; // eax@22
  int v9; // ebx@31
  signed int result; // eax@59
  struct tagTEXTMETRICW tm; // [sp+Ch] [bp-3C8h]@3
  struct tagDRAWTEXTPARAMS dtp; // [sp+48h] [bp-38Ch]@34
  int v13; // [sp+5Ch] [bp-378h]@25
  WCHAR *v14; // [sp+60h] [bp-374h]@25
  int v15; // [sp+64h] [bp-370h]@25
  int v16; // [sp+68h] [bp-36Ch]@25
  int v17; // [sp+6Ch] [bp-368h]@25
  struct tagRECT rc; // [sp+70h] [bp-364h]@27
  int v19; // [sp+80h] [bp-354h]@27
  HLOCAL hMem; // [sp+84h] [bp-350h]@1
  int v21; // [sp+88h] [bp-34Ch]@1
  HGDIOBJ ho; // [sp+8Ch] [bp-348h]@1
  int v23; // [sp+90h] [bp-344h]@1
  HGDIOBJ h; // [sp+94h] [bp-340h]@1
  LPCWSTR lpchText; // [sp+98h] [bp-33Ch]@1
  HDC hdc; // [sp+9Ch] [bp-338h]@1
  LOGFONTW lf; // [sp+A0h] [bp-334h]@1
  WCHAR String; // [sp+FCh] [bp-2D8h]@24
  wchar_t Dest; // [sp+304h] [bp-D0h]@34
  unsigned int v30; // [sp+3D0h] [bp-4h]@1
  int v31; // [sp+3D4h] [bp+0h]@1

  v30 = (unsigned int)&v31 ^ dword_100C010;
  hdc = a1;
  hMem = 0;
  h = 0;
  v23 = 0;
  v21 = 0;
  lpchText = 0;
  dword_100DE34 = 0;
  hDlg = 0;
  SetCursor(hCursor);
  sub_100882E(a1);
  GetLocalTime(&SystemTime);
  GetDateFormatW(0x400u, 2u, &SystemTime, 0, (LPWSTR)&word_100CD60, 260);
  GetTimeFormatW(0x400u, 0, &SystemTime, 0, (LPWSTR)&word_100CF68, 260);
  memcpy(&lf, &::lf, sizeof(lf));
  lf.lfWidth = 0;
  lf.lfHeight = *(_DWORD *)&Data * dword_100D7D0 / -720;
  ((void (__fastcall *)(signed int, int, HDC, signed int))SetMapMode)(
    -720,
    *(_DWORD *)&Data * dword_100D7D0 % -720,
    a1,
    8);
  SetViewportExtEx(a1, dword_100D7CC, y, 0);
  SetWindowExtEx(a1, stru_100C140.ptPaperSize.x, stru_100C140.ptPaperSize.y, 0);
  pt.x = stru_100C140.rtMargin.left;
  pt.y = stru_100C140.rtMargin.top;
  *((_DWORD *)&pt + 2) = stru_100C140.rtMargin.right;
  v3 = hdc;
  *((_DWORD *)&pt + 3) = stru_100C140.rtMargin.bottom;
  LPtoDP(v3, &pt, 2);
  SetMapMode(hdc, 1);
  v1 = CreateFontIndirectW(&lf);
  ho = v1;
  v2 = 0;
  if ( !v1
    || (h = SelectObject(hdc, v1), !h)
    || (SetBkMode(hdc, 1), !GetTextMetricsW(hdc, &tm))
    || !(tm.tmPitchAndFamily & 6)
    && ((v5 = SelectObject(hdc, h),
         DeleteObject(v5),
         memset(lf.lfFaceName, 0, 0x40u),
         v4 = CreateFontIndirectW(&lf),
         ho = v4,
         !v4)
     || (h = SelectObject(hdc, v4), !h)
     || !GetTextMetricsW(hdc, &tm)) )
    goto LABEL_54;
  dword_100DE3C = 8 * tm.tmAveCharWidth;
  dword_100DE30 = tm.tmHeight + tm.tmExternalLeading;
  x = pt.x - dword_100D7C4;
  if ( pt.x - dword_100D7C4 <= 0 )
    x = 0;
  dword_100D7B0 = dword_100DE28 + dword_100D7D8 - dword_100D7CC + dword_100D7C4;
  if ( dword_100DE28 + dword_100D7D8 - dword_100D7CC + dword_100D7C4 <= 0 )
    dword_100D7B0 = 0;
  dword_100D7BC = pt.y - dword_100D7C0;
  if ( pt.y - dword_100D7C0 <= 0 )
    dword_100D7BC = 0;
  dword_100D7B8 = dword_100DE2C + dword_100D7D4 - y + dword_100D7C0;
  if ( dword_100DE2C + dword_100D7D4 - y + dword_100D7C0 <= 0 )
    dword_100D7B8 = 0;
  v6 = (dword_100D7D4 - dword_100D7B8 - dword_100D7BC) / (tm.tmHeight + tm.tmExternalLeading);
  if ( word_100C740 )
    --v6;
  if ( *(_WORD *)&Dst )
    --v6;
  if ( v6 <= 0 )
  {
LABEL_53:
    MessageBoxW(hWnd, dword_100C324, szApp, 0x30u);
    SetLastError(v2);
LABEL_54:
    v7 = GetLastError();
    goto LABEL_41;
  }
  v7 = SetAbortProc(hdc, (ABORTPROC)proc);
  if ( (signed int)v7 < 0 )
    goto LABEL_41;
  v8 = SendMessageW(dword_100C028, 0xBDu, 0, 0);
  hMem = (HLOCAL)v8;
  if ( !v8
    || (lpchText = (LPCWSTR)LocalLock((HLOCAL)v8), !lpchText)
    || (GetWindowTextW(hWnd, &String, 260),
        EnableWindow(hWnd, 0),
        hDlg = CreateDialogParamW(hInstance, (LPCWSTR)0xB, hWnd, (DLGPROC)sub_1008A63, 0),
        !hDlg) )
    goto LABEL_54;
  v13 = 20;
  v14 = &String;
  v15 = 0;
  v16 = 0;
  v17 = 0;
  SetLastError(0);
  if ( StartDocW(hdc, (const DOCINFOW *)&v13) > 0 )
  {
    v21 = 1;
    *(_DWORD *)dword_100D7AC = 1;
    rc.left = x;
    v19 = 0;
    rc.right = dword_100D7D8 - dword_100D7B0;
    rc.top = dword_100D7BC;
    v23 = 0;
    rc.bottom = dword_100D7D4 - dword_100D7B8;
    if ( word_100C740 )
      rc.top += dword_100DE30;
    if ( *(_WORD *)&Dst )
      rc.bottom = dword_100D7D4 - dword_100D7B8 - dword_100DE30;
    v9 = lstrlenW(lpchText);
    if ( GetWindowLongW(dword_100C028, -20) & 0x2000 )
      v19 = 131074;
    while ( 1 )
    {
      if ( dword_100DE34 || v9 <= 0 )
      {
        v7 = 0;
        goto LABEL_40;
      }
      sub_10015C3(&Dest, 0x65u, dword_100C344, *(_DWORD *)dword_100D7AC);
      SetDlgItemTextW(hDlg, 21, &Dest);
      sub_1008EF2(hdc, 0);
      dtp.iLeftMargin = 0;
      dtp.iRightMargin = 0;
      dtp.uiLengthDrawn = 0;
      dtp.cbSize = 20;
      dtp.iTabLength = dword_100DE3C;
      if ( StartPage(hdc) <= 0
        || (v23 = 1,
            DrawTextExW(hdc, (LPWSTR)lpchText, v9, &rc, v19 | 0x2850, &dtp),
            sub_1008EF2(hdc, 1),
            EndPage(hdc) <= 0) )
        goto LABEL_26;
      v23 = 0;
      ++*(_DWORD *)dword_100D7AC;
      if ( !dtp.uiLengthDrawn )
        break;
      lpchText += dtp.uiLengthDrawn;
      v9 -= dtp.uiLengthDrawn;
    }
    v2 = 0;
    goto LABEL_53;
  }
LABEL_26:
  v7 = GetLastError();
LABEL_40:
  v2 = 0;
LABEL_41:
  if ( h != (HGDIOBJ)v2 )
  {
    SelectObject(hdc, h);
    DeleteObject(ho);
  }
  if ( lpchText != (LPCWSTR)v2 )
    LocalUnlock(hMem);
  if ( v23 != v2 )
  {
    if ( EndPage(hdc) <= 0 )
    {
      if ( v7 == v2 )
        v7 = GetLastError();
    }
  }
  if ( v21 != v2 )
  {
    if ( dword_100DE34 == v2 )
    {
      if ( EndDoc(hdc) <= 0 )
      {
        if ( v7 == v2 )
          v7 = GetLastError();
      }
    }
    else
    {
      AbortDoc(hdc);
    }
  }
  DeleteDC(hdc);
  sub_100888F();
  SetCursor(dword_100C094);
  if ( dword_100DE34 == v2 )
    result = v7;
  else
    result = -3;
  return result;
}
// 100C010: using guessed type int dword_100C010;
// 100D7B0: using guessed type int dword_100D7B0;
// 100D7B8: using guessed type int dword_100D7B8;
// 100D7BC: using guessed type int dword_100D7BC;
// 100D7C0: using guessed type int dword_100D7C0;
// 100D7C4: using guessed type int dword_100D7C4;
// 100D7D0: using guessed type int dword_100D7D0;
// 100D7D4: using guessed type int dword_100D7D4;
// 100D7D8: using guessed type int dword_100D7D8;
// 100DE28: using guessed type int dword_100DE28;
// 100DE2C: using guessed type int dword_100DE2C;
// 100DE30: using guessed type int dword_100DE30;
// 100DE34: using guessed type int dword_100DE34;
// 100DE3C: using guessed type int dword_100DE3C;

//----- (010096AE) --------------------------------------------------------
bool __stdcall sub_10096AE(LCID Locale)
{
  WCHAR LCData; // [sp+0h] [bp-24h]@1
  int v3; // [sp+Eh] [bp-16h]@2
  unsigned int v4; // [sp+20h] [bp-4h]@1
  int v5; // [sp+24h] [bp+0h]@1

  v4 = (unsigned int)&v5 ^ dword_100C010;
  return GetLocaleInfoW(Locale, 0x58u, &LCData, 16) && v3 & 0x800;
}
// 100C010: using guessed type int dword_100C010;

//----- (010096F8) --------------------------------------------------------
bool __stdcall sub_10096F8(int a1)
{
  LANGID v1; // ax@2
  bool result; // eax@2

  if ( a1 == 1 )
  {
    v1 = GetUserDefaultUILanguage();
    result = sub_10096AE(v1);
  }
  else
  {
    result = a1 == 6 || a1 == 23 || a1 == 10 || a1 == 8;
  }
  return result;
}

//----- (0100973A) --------------------------------------------------------
bool __stdcall sub_100973A(bool a1)
{
  bool result; // eax@1
  char v2; // zf@2
  WCHAR LCData[2]; // [sp+4h] [bp-4h]@1

  *(_DWORD *)LCData = 1;
  result = sub_10096AE(0x400u);
  if ( result )
  {
    GetLocaleInfoW(0x400u, 0x20001009u, LCData, 2);
    v2 = sub_10096F8(*(int *)LCData) == 0;
    result = a1;
    if ( v2 )
      *(_DWORD *)a1 |= 0x10u;
    else
      *(_DWORD *)a1 |= 0x20u;
  }
  return result;
}

//----- (0100978A) --------------------------------------------------------
LRESULT __stdcall sub_100978A(int a1)
{
  struct _SYSTEMTIME SystemTime; // [sp+8h] [bp-3ECh]@1
  DWORD dwFlags; // [sp+18h] [bp-3DCh]@1
  WCHAR DateStr; // [sp+1Ch] [bp-3D8h]@1
  _WORD lParam[330]; // [sp+BCh] [bp-338h]@1
  WCHAR TimeStr; // [sp+350h] [bp-A4h]@1
  unsigned int v7; // [sp+3F0h] [bp-4h]@1
  int v8; // [sp+3F4h] [bp+0h]@1

  v7 = (unsigned int)&v8 ^ dword_100C010;
  lParam[0] = 0;
  memset(&lParam[1], 0, 0x292u);
  dwFlags = 1;
  GetLocalTime(&SystemTime);
  sub_100973A((bool)&dwFlags);
  GetDateFormatW(0x400u, dwFlags, &SystemTime, 0, &DateStr, 80);
  GetTimeFormatW(0x400u, 2u, &SystemTime, 0, &TimeStr, 80);
  if ( a1 )
    sub_1007F99((int)lParam, 0x14Au, (int)L"\r\n");
  sub_1007F99((int)lParam, 0x14Au, (int)&TimeStr);
  sub_1007F99((int)lParam, 0x14Au, (int)&dword_10098B8);
  sub_1007F99((int)lParam, 0x14Au, (int)&DateStr);
  if ( a1 )
    sub_1007F99((int)lParam, 0x14Au, (int)L"\r\n");
  return SendMessageW(dword_100C028, 0xC2u, 1u, (LPARAM)lParam);
}
// 10098B8: using guessed type int dword_10098B8;
// 10098BC: using guessed type wchar_t asc_10098BC[3];
// 100C010: using guessed type int dword_100C010;

//----- (010098C7) --------------------------------------------------------
signed int __stdcall sub_10098C7(int a1, int a2)
{
  int v2; // edx@1
  int v3; // ecx@1
  signed int v4; // esi@1
  unsigned __int8 v5; // al@2
  signed int result; // eax@8

  v3 = 0;
  v4 = 1;
  v2 = 0;
  if ( a2 <= 0 )
    goto LABEL_8;
  do
  {
    v5 = *(_BYTE *)(v3 + a1);
    if ( (char)v5 < 0 )
      v4 = 0;
    if ( v2 )
    {
      if ( (v5 & 0xC0) != -128 )
        goto LABEL_8;
      --v2;
    }
    else
    {
      if ( v5 >= 0x80u )
      {
        do
        {
          v5 *= 2;
          ++v2;
        }
        while ( (char)v5 < 0 );
        --v2;
        if ( !v2 )
          goto LABEL_8;
      }
    }
    ++v3;
  }
  while ( v3 < a2 );
  if ( v2 || v4 )
LABEL_8:
    result = 0;
  else
    result = 1;
  return result;
}

//----- (0100991D) --------------------------------------------------------
BOOL __stdcall sub_100991D(const void *lpv, int iSize)
{
  BOOL result; // eax@1
  int iResult; // [sp+0h] [bp-4h]@1

  iResult = -1;
  result = IsTextUnicode(lpv, iSize, &iResult);
  if ( result )
  {
    if ( iResult == 2 )
    {
      if ( iSize < 100 )
        result = 0;
    }
  }
  return result;
}

//----- (01009952) --------------------------------------------------------
signed int __usercall sub_1009952<eax>(int a1<eax>, int a2<edx>, int a3<edi>)
{
  signed int result; // eax@1
  int v4; // ecx@1
  int v5; // esi@1

  v5 = a1;
  result = 0;
  v4 = a2;
  if ( !a2 )
    goto LABEL_12;
  do
  {
    if ( !*(_WORD *)v5 )
      break;
    v5 += 2;
    --a2;
  }
  while ( a2 );
  if ( !a2 )
LABEL_12:
    result = -2147024809;
  if ( a3 )
  {
    if ( result < 0 )
      *(_DWORD *)a3 = 0;
    else
      *(_DWORD *)a3 = v4 - a2;
  }
  return result;
}

//----- (01009989) --------------------------------------------------------
signed int __stdcall sub_1009989(HWND hwnd, int a2, __int16 a3, int a4)
{
  BOOL v4; // eax@6
  signed int v5; // edi@6
  HWND v7; // eax@14
  HWND v8; // eax@14
  OLECHAR *v9; // edi@18
  int v10; // eax@22
  struct _SHELLEXECUTEINFOW ExecInfo; // [sp+Ch] [bp-368h]@12
  HWND ppv; // [sp+48h] [bp-32Ch]@1
  struct _OSVERSIONINFOW VersionInformation; // [sp+4Ch] [bp-328h]@6
  char v14; // [sp+166h] [bp-20Eh]@7
  WCHAR Buffer; // [sp+168h] [bp-20Ch]@11
  unsigned int v16; // [sp+370h] [bp-4h]@1
  int v17; // [sp+374h] [bp+0h]@1

  v16 = (unsigned int)&v17 ^ dword_100C010;
  ppv = GetAncestor(hwnd, 2u);
  if ( a2 == 78 )
  {
    v10 = *(_DWORD *)(a4 + 8);
    if ( (v10 == -4 || v10 == -2) && *(_DWORD *)(a4 + 4) == 51202 )
    {
      v5 = 1;
      if ( LoadStringW((HINSTANCE)0x1000000, 0xC808u, &Buffer, 260) )
      {
        memset(&ExecInfo.fMask, 0, 0x38u);
        ExecInfo.lpFile = &Buffer;
        ExecInfo.cbSize = 60;
        ExecInfo.nShow = 1;
        ExecInfo.fMask = 256;
        ShellExecuteExW(&ExecInfo);
      }
      return v5;
    }
    return 0;
  }
  if ( a2 == 83 )
  {
    ppv = 0;
    if ( CoInitialize(0) >= 0 )
    {
      if ( CoCreateInstance(&stru_10043E0, 0, 0x17u, &stru_10043D0, (LPVOID *)&ppv) >= 0 )
      {
        if ( LoadStringW((HINSTANCE)0x1000000, 0xC805u, &Buffer, 260) )
        {
          v9 = SysAllocString(&Buffer);
          if ( v9 )
          {
            (*(void (__stdcall **)(HWND, OLECHAR *))(*(_DWORD *)ppv + 16))(ppv, v9);
            SysFreeString(v9);
          }
        }
        (*(void (__stdcall **)(HWND))(*(_DWORD *)ppv + 8))(ppv);
      }
      CoUninitialize();
    }
    return 0;
  }
  if ( a2 == 272 )
  {
    v7 = GetParent(hwnd);
    PostMessageW(v7, 1162u, 16u, 20);
    v8 = GetParent(hwnd);
    PostMessageW(v8, 0x48Bu, 0x10u, 17);
    SetWindowPos(ppv, HWND_MESSAGE|0x2, 0, 0, 0, 0, 3u);
    return 1;
  }
  if ( a2 != 273 || a3 != -14335 )
    return 0;
  SetWindowPos(ppv, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 3u);
  VersionInformation.dwOSVersionInfoSize = 284;
  v4 = GetVersionExW(&VersionInformation);
  v5 = 1;
  if ( v4 )
    v4 = v14 == 3 || v14 == 2;
  if ( LoadStringW((HINSTANCE)0x1000000, 51207 - (v4 != 0), &Buffer, 260) )
  {
    memset(&ExecInfo.fMask, 0, 0x38u);
    ExecInfo.lpFile = &Buffer;
    ExecInfo.cbSize = 60;
    ExecInfo.nShow = 1;
    ExecInfo.fMask = 256;
    ShellExecuteExW(&ExecInfo);
  }
  PostMessageW(ppv, 0x10u, 0, 0);
  return v5;
}
// 100C010: using guessed type int dword_100C010;

//----- (01009C2A) --------------------------------------------------------
void __stdcall StartAddress(int a1)
{
  const PROPSHEETPAGEW_V3 constPropSheetPagePointer; // [sp+8h] [bp-70h]@1
  const PROPSHEETHEADERW_V2 v2; // [sp+40h] [bp-38h]@2
  HPROPSHEETPAGE v3; // [sp+74h] [bp-4h]@1

  memset(&constPropSheetPagePointer.dwFlags, 0, 0x34u);
  constPropSheetPagePointer.dwSize = 56;
  constPropSheetPagePointer.dwFlags = 4096;
  constPropSheetPagePointer.hInstance = (HINSTANCE)16777216;
  constPropSheetPagePointer.pszTemplate = (LPCWSTR)51200;
  constPropSheetPagePointer.pfnDlgProc = (DLGPROC)sub_1009989;
  constPropSheetPagePointer.pszHeaderTitle = (LPCWSTR)51203;
  constPropSheetPagePointer.lParam = 0;
  v3 = CreatePropertySheetPageW(&constPropSheetPagePointer);
  if ( v3 )
  {
    memset(&v2.dwFlags, 0, 0x30u);
    v2.ppsp = (LPCPROPSHEETPAGEW)&v3;
    v2.dwSize = 52;
    v2.dwFlags = 16416;
    v2.hwndParent = 0;
    v2.hInstance = (HINSTANCE)16777216;
    v2.pszCaption = (LPCWSTR)51204;
    v2.nPages = 1;
    PropertySheetW(&v2);
  }
  InterlockedExchange(&Target, 0);
  FreeLibraryAndExitThread((HMODULE)0x1000000, 0);
}

//----- (01009CDF) --------------------------------------------------------
signed int __stdcall sub_1009CDF(int a1, int a2, int a3)
{
  signed int result; // eax@1

  result = 0;
  if ( !a2 || (unsigned int)a2 > 0x7FFFFFFF )
    result = -2147024809;
  if ( result >= 0 )
    result = sub_1007C80(a3, a2, a1, 0, 2147483646);
  return result;
}

//----- (01009D19) --------------------------------------------------------
signed int __stdcall sub_1009D19(int a1, int a2, int a3)
{
  signed int result; // eax@1
  int v4; // ebx@4
  int v5; // ecx@5

  result = 0;
  if ( !a2 || (unsigned int)a2 > 0x7FFFFFFF )
    result = -2147024809;
  v4 = a1;
  if ( result < 0 )
  {
    v5 = 0;
  }
  else
  {
    result = sub_1009952(a1, a2, (int)&a1);
    v5 = a1;
  }
  if ( result >= 0 )
    result = sub_1007C80(a3, a2 - v5, v4 + 2 * v5, 0, 2147483647);
  return result;
}

//----- (01009D73) --------------------------------------------------------
int __cdecl sub_1009D73(int a1, int a2, int a3, int a4)
{
  return except_handler4_common(&dword_100C010, sub_1001564, a1, a2, a3, a4);
}
// 1009FF1: using guessed type int __cdecl except_handler4_common(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD);
// 100C010: using guessed type int dword_100C010;

//----- (01009D9D) --------------------------------------------------------
int __stdcall sub_1009D9D(int a1)
{
  _DWORD *v1; // eax@1
  int v2; // eax@3

  v1 = *(_DWORD **)a1;
  if ( **(_DWORD **)a1 == -529697949 )
  {
    if ( v1[4] == 3 )
    {
      v2 = v1[5];
      if ( v2 == 429065504 || v2 == 429065505 || v2 == 429065506 || v2 == 26820608 )
        terminate();
    }
  }
  return 0;
}
// 100132C: using guessed type void __cdecl terminate();

//----- (01009DF0) --------------------------------------------------------
bool __cdecl sub_1009DF0(int a1)
{
  bool result; // eax@2
  int v2; // eax@3

  if ( *(_WORD *)a1 != 23117 || (v2 = a1 + *(_DWORD *)(a1 + 60), *(_DWORD *)v2 != 17744) )
    result = 0;
  else
    result = *(_WORD *)(v2 + 24) == 267;
  return result;
}

//----- (01009E2A) --------------------------------------------------------
int __cdecl sub_1009E2A(int a1, unsigned int a2)
{
  int result; // eax@1
  unsigned int v3; // edx@1
  unsigned int v4; // esi@1
  int v5; // ecx@1
  unsigned int v6; // ecx@2

  v5 = a1 + *(_DWORD *)(a1 + 60);
  v4 = *(_WORD *)(v5 + 6);
  v3 = 0;
  result = *(_WORD *)(v5 + 20) + v5 + 24;
  if ( *(_WORD *)(v5 + 6) )
  {
    while ( 1 )
    {
      v6 = *(_DWORD *)(result + 12);
      if ( a2 >= v6 )
      {
        if ( a2 < v6 + *(_DWORD *)(result + 8) )
          break;
      }
      ++v3;
      result += 40;
      if ( v3 >= v4 )
        goto LABEL_5;
    }
  }
  else
  {
LABEL_5:
    result = 0;
  }
  return result;
}

//----- (01009E73) --------------------------------------------------------
int __usercall sub_1009E73<eax>(int a1<ebp>)
{
  sub_1003B0C((int)dword_1009EE0, 8);
  *(_DWORD *)(a1 - 4) = 0;
  if ( sub_1009DF0(16777216) && sub_1009E2A(16777216, *(_DWORD *)(a1 + 8) - 16777216) )
    *(_DWORD *)(a1 - 4) = -2;
  else
    *(_DWORD *)(a1 - 4) = -2;
  return sub_10023D0(a1);
}
// 10023D0: using guessed type _DWORD __usercall sub_10023D0<eax>(_DWORD ebp0<ebp>);
// 1009EE0: using guessed type int dword_1009EE0[2];

//----- (01009F07) --------------------------------------------------------
BOOL __usercall sub_1009F07<eax>(char _CF<cf>, char _ZF<zf>, char _SF<sf>, char _OF<of>, int a5<eax>, int a6<edx>, int a7<ecx>, int a8<ebx>, int a9<edi>, int a10<esi>, char a11)
{
  int v12; // ST04_4@1
  int v13; // ST330_4@1
  HANDLE v14; // eax@1
  int v15; // [sp+32Ch] [bp+4h]@1

  dword_100C470 = a5;
  dword_100C46C = a7;
  dword_100C468 = a6;
  dword_100C464 = a8;
  dword_100C460 = a10;
  dword_100C45C = a9;
  word_100C488 = __SS__;
  word_100C47C = __CS__;
  word_100C458 = __DS__;
  word_100C454 = __ES__;
  word_100C450 = __FS__;
  word_100C44C = __GS__;
  __asm { pushf }
  dword_100C480 = v12;
  dword_100C474 = v13;
  dword_100C478 = v15;
  dword_100C484 = (int)&a11;
  dword_100C3C0 = 65537;
  dword_100C37C = dword_100C478;
  dword_100C370 = -1073740791;
  dword_100C374 = 1;
  SetUnhandledExceptionFilter(0);
  UnhandledExceptionFilter(&ExceptionInfo);
  v14 = GetCurrentProcess();
  return TerminateProcess(v14, 0xC0000409u);
}
// 100C370: using guessed type int dword_100C370;
// 100C374: using guessed type int dword_100C374;
// 100C37C: using guessed type int dword_100C37C;
// 100C3C0: using guessed type int dword_100C3C0;
// 100C44C: using guessed type __int16 word_100C44C;
// 100C450: using guessed type __int16 word_100C450;
// 100C454: using guessed type __int16 word_100C454;
// 100C458: using guessed type __int16 word_100C458;
// 100C45C: using guessed type int dword_100C45C;
// 100C460: using guessed type int dword_100C460;
// 100C464: using guessed type int dword_100C464;
// 100C468: using guessed type int dword_100C468;
// 100C46C: using guessed type int dword_100C46C;
// 100C470: using guessed type int dword_100C470;
// 100C474: using guessed type int dword_100C474;
// 100C478: using guessed type int dword_100C478;
// 100C47C: using guessed type __int16 word_100C47C;
// 100C480: using guessed type int dword_100C480;
// 100C484: using guessed type int dword_100C484;
// 100C488: using guessed type __int16 word_100C488;

#error "There were 1 decompilation failure(s) on 140 function(s)"



阅读更多

没有更多推荐了,返回首页