/* This file has been generated by the Hex-Rays decompiler.
   Copyright (c) 2007 Hex-Rays sprl <info@hex-rays.com>

   Detected compiler: GNU C++
*/

#include <defs.h>


//-------------------------------------------------------------------------
// Data declarations

extern _UNKNOWN start;
extern _UNKNOWN sub_804B0E0;
extern _UNKNOWN sub_804C670;
extern _UNKNOWN sub_804C710;
extern _UNKNOWN sub_804C800;
extern _UNKNOWN unk_807EB08; // weak
extern char aStat_template_[18]; // weak
extern wchar_t aW[2]; // weak
extern char aCannotOpenTemp[34]; // weak
extern char aVector_m_inser[22]; // weak
extern char aUnknownCodeU[16]; // weak
extern char a3258m[6]; // weak
extern char aIg11NaticqServ[29]; // weak
extern char aLinuxBuild[13]; // weak
extern char aThreadStackSiz[24]; // weak
extern char aInternalConver[28]; // weak
extern char aBindFailedWith[30]; // weak
extern char aMemoryAllocati[27]; // weak
extern char aConnectFromSI[20]; // weak
extern char aIcqUinIsU[15]; // weak
extern char aConnectFailedA[23]; // weak
extern char aUnknown[8]; // weak
extern char aFemale[7]; // weak
extern char aMale[5]; // weak
extern char aErrorExpectedD[27]; // weak
extern char aUnknownOpcodeU[18]; // weak
extern char aDisconnectFrom[23]; // weak
extern int byte_807EDC4[]; // idb
extern int dword_807EDE0[]; // idb
extern _UNKNOWN unk_807EE20; // weak
extern char aCaughtSigpipeP[48]; // weak
extern char aCaughtSigintEx[73]; // weak
extern char aUsageSPortPath[44]; // weak
extern char aIncorrectPortN[55]; // weak
extern char aSocketFailedWi[32]; // weak
extern char aSetsockoptSo_r[48]; // weak
extern char aListenFailedWi[32]; // weak
extern char aSocketError_Ex[33]; // weak
extern char aPthread_create[40]; // weak
extern char aFinishedServin[54]; // weak
extern char aNickSFirstname[86]; // weak
extern char aThreadXUinURec[41]; // weak
extern int (__cdecl *off_807F2E8)(int); // weak
extern char aNr[5]; // weak
extern char aNr_0[6]; // weak
extern char aRes_0[7]; // weak
extern char aLtUinGt[12]; // weak
extern char aLtUinGt_0[13]; // weak
extern char aLtIndexGt[14]; // weak
extern char aLtIndexGt_0[15]; // weak
extern char aLtTitleGt[14]; // weak
extern char aLtTitleGt_0[15]; // weak
extern char aLtDescGt[13]; // weak
extern char aLtDescGt_0[14]; // weak
extern char aQuery[8]; // weak
extern char aQuery_0[9]; // weak
extern char aNotify[9]; // weak
extern char aNotify_0[10]; // weak
extern char aLtPluginidGt[17]; // weak
extern char aLtPluginidGt_0[18]; // weak
extern char aSrvmng[7]; // weak
extern char aNotifyLtSrvGtL[30]; // weak
extern char aCawaysrv[9]; // weak
extern char aLtReqGtLtIdGt[22]; // weak
extern char aAwaystat[9]; // weak
extern char aLtSenderidGt[17]; // weak
extern char aLtSenderidGt_0[18]; // weak
extern int (__cdecl *off_807F4D8)(int); // weak
extern int (__cdecl *off_807F4E8)(int); // weak
extern int (__cdecl *off_807F4F8)(int); // weak
extern int (__cdecl *off_807F508)(int); // weak
extern int (__cdecl *off_807F520)(int); // weak
extern int (__cdecl *off_807F538)(int); // weak
extern _UNKNOWN unk_807F5E8; // weak
extern char aEn[3]; // weak
extern char aUs[3]; // weak
extern char aLogin_oscar_ao[20]; // weak
extern _UNKNOWN unk_807F63F; // weak
extern char aRes[6]; // weak
extern char aLtSrvGt[12]; // weak
extern _UNKNOWN unk_807F655; // weak
extern char aLtIdGt[12]; // weak
extern char aLtSrvGt_0[13]; // weak
extern char aLtIdGtCawaysrv[30]; // weak
extern char aLtValSrv_idCaw[30]; // weak
extern char aLtRootGt[13]; // weak
extern char aLtRootGt_0[14]; // weak
extern char aLtValGt[13]; // weak
extern char aLtRetGt[13]; // weak
extern char aResNr[14]; // weak
extern _UNKNOWN unk_807F6F7; // weak
extern char aBasic_string_s[42]; // weak
extern char a0946134e4c7f11[39]; // weak
extern char a0946134e4c7f_0[39]; // weak
extern char a094613494c7f11[39]; // weak
extern char aIcqInc_Product[52]; // weak
extern char aNQueryLtQGtLtP[209]; // weak
extern char aLtSenderidGtLt[55]; // weak
extern char aScriptPlugInRe[43]; // weak
extern char aLtRetEventOnre[41]; // weak
extern char aLtValSrv_idGtU[43]; // weak
extern char aLtCasxtrasetaw[60]; // weak
extern char aLtIdGtCrandomi[36]; // weak
extern char aLtValSrv_idCra[57]; // weak
extern int stru_807FAC0[]; // idb
extern char byte_807FCE0[]; // idb
extern _UNKNOWN unk_807FD00; // weak
extern int (__cdecl *off_807FD68)(int); // weak
extern int (*off_8086EEC)(); // weak
extern int dword_8086EF4[]; // idb
extern _UNKNOWN unk_8086EF8; // weak
extern int dword_8086EFC; // weak
extern void *_gmon_start___ptr; // weak
extern _UNKNOWN unk_80871E4; // weak
extern char (*off_8087240)[65]; // weak
extern char byte_8087260[]; // idb
extern char _VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[16]; // weak
extern int stdout; // weak
extern char std__string___Rep___S_empty_rep_storage[16]; // weak
extern char byte_8087470; // weak
extern int dword_8087474; // weak
extern _UNKNOWN client_mutex; // weak
extern __int16 clientsNum; // weak
extern int path_to_stat; // weak
extern _UNKNOWN unk_80874B8; // weak
extern _UNKNOWN unk_80874BC; // weak
extern int dword_80874C0; // weak
extern int dword_80874C4; // weak
extern int finished; // weak
extern _UNKNOWN unk_80874D0; // weak

//-------------------------------------------------------------------------
// Function declarations

int __fastcall init_proc(int a1);
int *__errno_location(void); // idb
int __fastcall std____throw_length_error(_DWORD); // weak
void srand(unsigned int seed); // idb
int open(const char *file, int oflag, ...); // idb
int __cdecl __cxa_atexit(_DWORD, _DWORD, _DWORD); // weak
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate); // idb
int __fastcall std___Rb_tree_decrement(_DWORD, _DWORD); // weak
char *inet_ntoa(struct in_addr in); // idb
int shutdown(int fd, int how); // idb
int __fastcall std__ios_base__ios_base(_DWORD); // weak
int __cdecl std__string__assign(_DWORD, _DWORD); // weak
__sighandler_t signal(int sig, __sighandler_t handler); // idb
int __fastcall __gmon_start__(_DWORD, _DWORD); // weak
int __fastcall operator delete(_DWORD, _DWORD); // weak
int __printf_chk(_DWORD, const char *, ...); // weak
ssize_t recv(int fd, void *buf, size_t n, int flags); // idb
int __cxa_rethrow(void); // weak
int __cdecl std__ios_base__Init__Init(_DWORD); // weak
void tzset(void); // idb
int listen(int fd, int n); // idb
void *memset(void *s, int c, size_t n); // idb
int __cdecl std___Rb_tree_decrement(_DWORD); // weak
int __cdecl std__basic_ostringstream_char_std__char_traits_char__std__allocator_char____str(_DWORD, _DWORD); // weak
int __cdecl __memcpy_chk(_DWORD, _DWORD, _DWORD, _DWORD); // weak
int __cdecl std__string__compare(_DWORD, _DWORD); // weak
int __cdecl std__string__string(_DWORD, _DWORD); // weak
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize); // idb
int __cdecl std__string__string(_DWORD, _DWORD, _DWORD, _DWORD); // weak
int std__ios_base__Init___Init(); // weak
ssize_t read(int fd, void *buf, size_t nbytes); // idb
int __cdecl std__string__find(_DWORD, _DWORD, _DWORD); // weak
__int32 strtol(const char *nptr, char **endptr, int base); // idb
int __cdecl std__string___string(_DWORD); // weak
void free(void *ptr); // idb
int __cdecl std__string___Rep___M_destroy(_DWORD, _DWORD); // weak
int accept(int fd, struct sockaddr *addr, socklen_t *addr_len); // idb
int ioctl(int fd, unsigned __int32 request, ...); // idb
int socket(int domain, int type, int protocol); // idb
int fseek(FILE *stream, __int32 off, int whence); // idb
int pthread_mutex_unlock(pthread_mutex_t *mutex); // idb
int pthread_attr_init(pthread_attr_t *attr); // idb
int __cdecl std__string__find(_DWORD, _DWORD, _DWORD, _DWORD); // weak
int __cdecl std__string__assign(_DWORD, _DWORD, _DWORD, _DWORD); // weak
int fclose(FILE *stream); // idb
time_t mktime(struct tm *tp); // idb
void *memcpy(void *dest, const void *src, size_t n); // idb
int __cdecl std___Rb_tree_increment(_DWORD); // weak
size_t strlen(const char *s); // idb
FILE *fopen(const char *filename, const char *modes); // idb
int pthread_mutex_destroy(pthread_mutex_t *mutex); // idb
int __cdecl std__string__compare(_DWORD, _DWORD); // weak
int __cdecl std__string__string(_DWORD, _DWORD, _DWORD); // weak
char *strcpy(char *dest, const char *src); // idb
__int32 ftell(FILE *stream); // idb
int __cdecl std__locale__locale(_DWORD); // weak
int bind(int fd, const struct sockaddr *addr, socklen_t len); // idb
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr); // idb
int __fastcall operator new(_DWORD, _DWORD); // weak
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); // idb
int close(int fd); // idb
size_t fwrite(const void *ptr, size_t size, size_t n, FILE *s); // idb
int __cdecl std__basic_ios_char_std__char_traits_char____init(_DWORD, _DWORD); // weak
char *strstr(const char *haystack, const char *needle); // idb
time_t time(time_t *timer); // idb
int setvbuf(FILE *stream, char *buf, int modes, size_t n); // idb
int __cdecl std___Rb_tree_insert_and_rebalance(_DWORD, _DWORD, _DWORD, _DWORD); // weak
void *malloc(size_t size); // idb
int pthread_mutex_lock(pthread_mutex_t *mutex); // idb
int __stack_chk_fail(void); // weak
int __cdecl std__ios_base___ios_base(_DWORD); // weak
int __cdecl std__basic_ostringstream_char_std__char_traits_char__std__allocator_char_____basic_ostringstream(_DWORD); // weak
int pthread_create(pthread_t *newthread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); // idb
int __cdecl std__string__assign(_DWORD, _DWORD); // weak
unsigned int sleep(unsigned int seconds); // idb
int __cdecl std____throw_logic_error(_DWORD); // weak
int __cdecl std__string__assign(_DWORD, _DWORD, _DWORD); // weak
void *memmove(void *dest, const void *src, size_t n); // idb
ssize_t send(int fd, const void *buf, size_t n, int flags); // idb
int puts(const char *s); // idb
int __cdecl std__ostream___M_insert_unsigned_long_(_DWORD, _DWORD); // weak
int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen); // idb
int __cxa_end_catch(void); // weak
int std____throw_bad_alloc(void); // weak
int rand(void); // idb
int pthread_attr_destroy(pthread_attr_t *attr); // idb
int __fxstat(int ver, int fildes, struct stat *stat_buf); // idb
int __cdecl std__string___Rep___S_create(_DWORD, _DWORD, _DWORD); // weak
int __sprintf_chk(_DWORD, _DWORD, _DWORD, const char *, ...); // weak
int __cdecl std__string__string(_DWORD, _DWORD, _DWORD, _DWORD); // weak
int strncmp(const char *s1, const char *s2, size_t n); // idb
int __snprintf_chk(_DWORD, _DWORD, _DWORD, _DWORD, const char *, ...); // weak
int __cdecl __cxa_begin_catch(_DWORD); // weak
int __cdecl std__string__append(_DWORD, _DWORD, _DWORD); // weak
size_t fread(void *ptr, size_t size, size_t n, FILE *stream); // idb
int __cdecl std__string___M_replace_safe(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD); // weak
int __cdecl std__string__erase(_DWORD, _DWORD, _DWORD); // weak
int __cdecl std__basic_ostringstream_char_std__char_traits_char__std__allocator_char____basic_ostringstream(_DWORD, _DWORD); // weak
int getpeername(int fd, struct sockaddr *addr, socklen_t *len); // idb
int __cdecl _Unwind_Resume(_DWORD); // weak
int strcmp(const char *s1, const char *s2); // idb
int __cdecl std__locale___locale(_DWORD); // weak
void exit(int status); // idb
int __cdecl std__string___M_leak_hard(_DWORD); // weak
int __cdecl std__string__append(_DWORD, _DWORD); // weak
int __cdecl std____ostream_insert_char_std__char_traits_char__(_DWORD, _DWORD, _DWORD); // weak
pthread_t pthread_self(void); // idb
int pthread_cancel(pthread_t th); // idb
int __cdecl std__string__find_last_of(_DWORD, _DWORD, _DWORD); // weak
int __cdecl std__string__reserve(_DWORD, _DWORD); // weak
void __cdecl sub_804A5D0();
int __cdecl sub_804A630();
void __cdecl status_update();
// int __usercall sub_804A7D0<eax>(int result<eax>, int a2<edx>);
// int __usercall sub_804B030<eax>(unsigned int *a1<eax>, int *a2<edx>, unsigned int a3<ecx>);
int __cdecl sub_804B220(int a1, int a2);
signed int __cdecl sub_804B290(int a1, int a2);
int __cdecl sub_804B370(int a1, int a2);
int __fastcall sub_804B500(int a1, int a2, int a3, int a4);
int __fastcall sub_804B5E0(int a1, int a2, int a3, int a4, int a5);
// int __usercall sub_804B680<eax>(int a1<ecx>, int a2<edi>, int a3, int a4, int a5);
int __cdecl sub_804BCE0(int a1, int *a2, int a3);
int __cdecl sub_804BE30(signed int a1);
signed int __cdecl sub_804BF80(const char *a1, const char *a2);
int __cdecl sub_804C150(int a1, unsigned __int16 a2);
signed int __cdecl recv_packet(int a1, int a2, signed int a3);
__sighandler_t __cdecl sigpipe_handler();
__sighandler_t __cdecl sigint_handler();
__int16 __cdecl send_packet(int a1, int a2);
int __cdecl sub_804CB80(int a1, int a2);
signed int __cdecl main(char a1, int a2);
__int16 __cdecl sub_804D390(int a1, int a2);
int __cdecl handle_connection(int *a1);
int __cdecl sub_804FC00(int a1);
void __cdecl sub_804FE40();
void __cdecl sub_804FE50();
void __cdecl sub_804FE60();
void __cdecl sub_804FE70();
void __cdecl sub_804FE80();
void __cdecl sub_804FE90();
void __cdecl sub_804FEA0();
int __cdecl sub_804FEB0(int a1, int a2, int a3, int a4, __int16 a5, char a6, int a7, int a8);
int __fastcall sub_804FF80(int a1, int _EDX, int a3);
int __cdecl sub_8050000(int a1);
int __cdecl sub_8050070(int a1);
char *__cdecl sub_80500E0(int a1);
int __fastcall sub_8050180(int a1, int a2, int a3);
int __cdecl sub_8050EE0(int a1);
int __cdecl sub_8050F20(int a1);
int __cdecl sub_8050F60(int a1);
int __cdecl sub_8050FB0(int a1);
int __cdecl sub_8050FE0(int a1, __int16 a2);
int __cdecl sub_8051060(int a1);
int __cdecl sub_8051180(int a1);
int __cdecl sub_80511E0(int a1);
int __cdecl sub_8051230(int a1);
int __cdecl sub_8051270(int a1);
int __cdecl sub_80512C0(int a1);
int __cdecl sub_8051310(int a1);
void __cdecl sub_8051340();
void __cdecl sub_8051360();
int __cdecl sub_8051390(int a1);
int __cdecl sub_80513E0(int a1);
signed int __cdecl sub_8051410(int a1, int a2, int a3);
signed int __cdecl sub_80514B0(int a1, int a2, int a3);
signed int __cdecl sub_8051550(int a1, int a2);
int __cdecl sub_8051580(int a1);
int __cdecl sub_80515E0(int a1);
signed int __cdecl sub_8051660(int a1, int a2);
signed int __cdecl sub_8051690(int a1, int a2);
signed int __cdecl sub_80516C0(int a1, int a2, int a3);
signed int __cdecl sub_8051750(int a1, int a2);
signed int __cdecl sub_8051830(signed int a1, int a2, int a3);
int __cdecl sub_8051C40(int a1, int a2);
int __fastcall sub_8051D90(int a1, int a2, int a3);
char __fastcall sub_8051DF0(int a1, int a2, int a3, int a4);
signed int __fastcall sub_8051F30(int a1, int a2, int a3, int a4);
int __fastcall sub_80522F0(int a1, int a2, int a3);
int __fastcall sub_8052330(int a1, int a2, int a3);
int __fastcall sub_8052370(int a1, int a2, int a3);
int __fastcall sub_8052390(int a1, int a2, int a3);
int __fastcall sub_80523F0(int a1, int a2, int a3);
int __fastcall sub_8052450(int a1, int a2, int a3);
int __fastcall sub_8052480(int a1, int a2, int a3);
int __fastcall sub_80524C0(int a1, int a2, int a3);
int __fastcall sub_80524F0(int a1, int a2, int a3);
int __cdecl sub_8052530(int a1);
int __cdecl sub_80525A0(int a1, __int16 a2);
int __cdecl sub_8052610(int a1, int a2, int a3);
int __cdecl sub_80526F0(int a1, int a2, int a3);
void *__cdecl sub_80527D0(int a1, int a2, int a3);
void *__cdecl sub_80528B0(int a1, int a2, int a3);
int __cdecl sub_8052970(int a1, int a2, int a3);
int __cdecl sub_80529E0(int a1, int a2, int a3);
int __cdecl sub_8052A50(int a1, int a2, int a3);
int __cdecl sub_8052A60(int a1, int a2, int a3);
void *__cdecl sub_8052AE0(int a1, int a2, int a3);
int __cdecl sub_8052B90(int a1, int a2, int a3);
void *__cdecl sub_8052BE0(int a1, int a2, int a3);
int __cdecl sub_8053310(int a1, int a2, int a3);
signed int __cdecl sub_80535F0(int a1);
signed int __cdecl sub_80538E0(int a1);
int __fastcall sub_8053CB0(int a1, int a2, int a3);
int __fastcall sub_8053D50(int a1, int a2, int a3);
int __fastcall sub_8053DE0(int a1, int a2, int a3);
int __fastcall sub_8053E70(int a1, int a2, int a3);
int __fastcall sub_8053EA0(int a1, int a2, int a3);
int __fastcall sub_8053EE0(int a1, int a2, int a3);
int __fastcall sub_8053F10(int a1, int a2, int a3);
signed int __cdecl sub_8053F50(int a1, int a2);
signed int __cdecl sub_8054030(int a1, int a2, int a3);
signed int __cdecl sub_80541B0(int a1, int a2, int a3);
int __cdecl sub_8054260(int *a1);
int __cdecl sub_8054300(int a1);
int __cdecl sub_80543A0(int a1);
int __cdecl sub_80545E0(int a1);
int __cdecl sub_8054840(int a1);
int __fastcall sub_80548E0(int a1, int a2, int a3);
int __fastcall sub_80549C0(int a1, int a2, int a3);
void __fastcall sub_8054AA0(int a1, int a2, int a3);
signed int __cdecl sub_8054AF0(int a1, int a2, int a3);
signed int __cdecl sub_8054CC0(int a1, int a2, int a3);
signed int __fastcall sub_8054FD0(int a1, int a2, int a3, int a4, int a5);
char __cdecl sub_8055160(int a1, int a2, int a3);
signed int __fastcall sub_8055270(int a1, int a2, int a3, int a4, int a5);
signed int __fastcall sub_8055400(int a1, int a2, int a3, int a4, int a5);
signed int __cdecl sub_8055410(int a1, int a2, int a3);
signed int __cdecl sub_8055470(int a1, int a2);
signed int __cdecl sub_80555E0(int a1, int a2);
int __fastcall sub_8055740(int a1, int a2, int a3, int a4);
int __cdecl sub_8055D40(int a1, int a2);
int __fastcall sub_8056300(int a1, int a2, int a3, int a4);
int __fastcall sub_8056490(int a1, int a2, int a3);
int __fastcall sub_80564B0(int a1, int a2, int a3, const void *a4, int a5);
_DWORD __cdecl sub_8056580(_DWORD, _DWORD, _DWORD, _DWORD); // weak
int __cdecl sub_8056790(int a1, unsigned int a2, char a3);
int __fastcall sub_80567F0(int a1, int a2, int a3);
int __fastcall sub_8056830(int a1, int a2, int a3, int a4, int a5);
int __cdecl sub_8056930(int a1, int a2);
int __cdecl sub_8056B00(int a1, int a2, int a3, int a4, int a5);
int __cdecl sub_8056C30(int a1, int a2, int a3);
int __cdecl sub_8056C70(int a1, int a2);
int __fastcall sub_8057010(int a1, int a2, int a3, int a4, int a5);
int __fastcall sub_8057B40(int a1, int a2, int a3, int a4, int a5);
int __fastcall sub_8057F70(int a1, int a2, int a3, int a4);
signed int __cdecl sub_8058030(int a1, __int16 a2);
signed int __cdecl sub_8058090(int a1, __int16 a2);
signed int __cdecl sub_80580E0(int a1);
int __cdecl sub_8058150();
signed int __cdecl sub_8058180(int a1, int a2, int a3);
signed int __cdecl sub_80581D0(int a1, int a2, int a3);
signed int __cdecl sub_8058220(int a1, int a2, int a3, int a4);
signed int __cdecl sub_8058290(int a1, int a2, int a3);
_DWORD __cdecl sub_8058330(_DWORD, _DWORD); // weak
_DWORD __cdecl sub_80583F0(_DWORD, _DWORD); // weak
signed int __cdecl sub_80584B0(int a1, int a2, int a3, int a4, int a5);
signed int __cdecl sub_8058560(int a1, int a2, int a3, int a4);
int __cdecl sub_8058600(int a1, int a2, int a3);
int __cdecl sub_80589D0(int a1, int a2, int a3);
int __cdecl sub_8058C60(int a1, int a2, int a3);
void __cdecl sub_8058CF0(int a1, int a2, int a3);
int __cdecl sub_8059210(int a1, int a2, int a3);
void __cdecl sub_80592D0(int a1, int a2, int a3);
void __cdecl sub_80595B0(int a1, int a2, int a3);
signed int __cdecl sub_8059BB0(int a1);
signed int __cdecl sub_8059D50(int a1, int a2, int a3, int a4);
_DWORD __cdecl sub_8059F40(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD); // weak
signed int __cdecl sub_805A070(int a1);
int __cdecl sub_805A110(int a1);
signed int __cdecl sub_805A180(int a1, __int16 a2, __int16 a3, int a4, int a5);
char __cdecl sub_805A2D0(int a1);
char __cdecl sub_805A310(int a1);
char __cdecl sub_805A350(int a1);
char __cdecl sub_805A390(int a1, int a2);
char __cdecl sub_805A3D0(int a1, int a2);
char __cdecl sub_805A410(int a1, int a2);
char __cdecl sub_805A450(int a1, int a2);
char __cdecl sub_805A490(int a1, int a2);
char __cdecl sub_805A4D0(int a1, int a2);
char __cdecl sub_805A510(int a1, int a2);
char __cdecl sub_805A550(int a1, int a2);
signed int __cdecl sub_805A590(int a1, int a2);
signed int __cdecl sub_805A920(int a1, int a2, int a3);
signed int __cdecl sub_805A9C0(int a1, unsigned int a2, int a3);
char __cdecl sub_805AD80(int a1, int a2);
char __cdecl sub_805ADF0(int a1, int a2);
char __cdecl sub_805AE60(int a1, int a2);
char __cdecl sub_805AED0(int a1, int a2);
char __cdecl sub_805AF40(int a1, int a2);
signed int __cdecl sub_805AFB0(int a1);
signed int __cdecl sub_805B100(int a1);
signed int __cdecl sub_805B230(int a1, int a2, int a3, int a4);
signed int __cdecl sub_805B480(int a1);
_DWORD __cdecl sub_805B550(_DWORD, _DWORD, __int16); // weak
int __cdecl sub_805B650(int a1);
int __cdecl sub_805B6B0(int a1, int a2);
int __stdcall sub_805B760(int a1, int a2);
signed int __cdecl sub_805B850(int a1, int a2);
signed int __cdecl sub_805B8D0(int a1, int a2);
char __cdecl sub_805B950(int a1, int a2, __int16 a3, int a4);
char __fastcall sub_805BA30(int a1, int a2, int a3, const void **a4, const void **a5);
char __fastcall sub_805BB80(int a1, int a2, int a3, const void **a4, const void **a5, char a6);
char __fastcall sub_805BCF0(int a1, int a2, int a3);
signed int __cdecl sub_805BF30(int a1);
int __cdecl sub_805C0F0(int a1, const char **a2, int a3);
int *__fastcall sub_805C2B0(int a1, int a2, int a3, const char **a4, int a5);
int *__cdecl sub_805C4B0(int a1);
int *__cdecl sub_805C700(int a1, int a2, int a3, int a4);
int *__fastcall sub_805C750(int a1, int a2, int a3, unsigned __int8 a4, int a5);
char __fastcall sub_805C910(int a1, int a2, int a3);
signed int __cdecl sub_805C940(int a1, int a2);
signed int __cdecl sub_805CAB0(int a1, int a2, int a3, int a4, int a5);
char __cdecl sub_805D2C0(int a1);
char __cdecl sub_805DD60(int a1);
int __cdecl sub_805F070(int a1, int a2);
int __cdecl sub_805F220(int a1, __int16 a2, int a3);
int __cdecl sub_805F520(int a1, int a2, char a3);
signed int __cdecl sub_805FB00(int a1, int a2);
int __cdecl sub_805FB70(int a1, const void **a2, int a3, char a4);
signed int __cdecl sub_8060160(int a1, unsigned __int8 a2);
signed int __cdecl sub_8063EF0(int a1, int *a2, __int16 a3);
signed int __cdecl sub_8064400(int a1, int a2);
signed int __cdecl sub_8064780(int a1);
signed int __cdecl sub_8064C80(int a1, int a2);
// signed int __usercall sub_8064FC0<eax>(int a1<edi>, unsigned int a2<esi>, int a3, int a4);
// signed int __usercall sub_8065430<eax>(int a1<edx>, int a2<ecx>, int a3<edi>, unsigned int a4<esi>, int a5, int a6);
int __cdecl sub_8065530(int a1, int a2, int a3, char a4);
int __cdecl sub_8066B30(int a1);
signed int __cdecl sub_8067C80(int a1, int a2);
int __cdecl sub_80683D0(int a1, int a2, int a3);
int __cdecl sub_80684D0(int a1, int a2);
void __fastcall sub_80689D0(int a1, int a2, int a3);
void __fastcall sub_8069070(int a1, int a2, int a3);
int __cdecl sub_8069710(int a1);
int __cdecl sub_8069FF0(int a1);
int __cdecl sub_806A8E0(int a1);
signed int __cdecl sub_806B1C0(int a1, int a2, int a3);
char *__cdecl sub_806DE60(int a1, int a2, int a3);
signed int __cdecl sub_806E100(int a1, int a2, int a3);
// signed int __usercall sub_806E5C0<eax>(int a1<ebx>, int a2, int a3);
signed int __cdecl sub_806ED00(int a1, int a2, int a3, int a4, int a5);
signed int __cdecl sub_806F530(int a1, int a2, int a3, char a4);
// int __usercall sub_806FE30<eax>(signed int *a1<esi>, int a2, const void **a3, int a4);
signed int __cdecl sub_80708D0(int a1, char *a2, int a3);
char __cdecl sub_8070FF0(int a1, int a2, __int16 a3, int a4);
signed int __cdecl sub_8071410(int a1, int a2, int a3);
char __cdecl sub_8071620(int a1, int a2, int a3);
signed int __cdecl sub_8071820(int a1, int a2);
signed int __cdecl sub_8072100(int a1, int a2, int a3, int a4, int a5);
signed int __cdecl sub_80729E0(int a1, char *a2, int a3, int a4);
char __cdecl sub_8072E40(int a1, int a2, int a3, int a4);
char __cdecl sub_8073610(int a1, int a2, int a3, int a4, int a5);
// signed int __usercall sub_8073CB0<eax>(char *a1<edi>, int a2, int a3);
signed int __cdecl sub_8074E00(int a1, int a2, int a3, __int16 a4, int a5, unsigned __int8 a6);
signed int __cdecl sub_80751D0(int a1, int a2);
int __cdecl sub_80754B0(int a1, __int16 a2);
// signed int __usercall sub_8075960<eax>(int *a1<edi>, int a2, int a3);
signed int __cdecl sub_80766A0(int a1, int a2);
signed int __cdecl sub_80767E0(int a1, int a2);
void __cdecl sub_8077860();
void __cdecl sub_8077870();
void __cdecl sub_8077880();
void __cdecl sub_8077890();
void __cdecl sub_80778A0();
void __cdecl sub_80778B0();
void __cdecl sub_80778C0();
void __cdecl sub_80778D0();
int __cdecl sub_80778E0(int a1);
int __cdecl sub_8077920(int a1);
int __cdecl sub_8077A10(int a1, int a2);
int __cdecl sub_8077B20(int a1, int a2);
int __stdcall ZStplIcSt11char_traitsIcESaIcEESbIT_T0_T1_ERKS6_S8_(int a1, int a2, int a3);
int __cdecl sub_8077C60(int a1, int a2);
int __cdecl sub_8077CF0(int a1, int a2, int a3, int a4, int a5, int a6);
void __cdecl sub_8077D60(int a1, int a2);
void __cdecl sub_8077DA0(int a1);
int __fastcall sub_8077DD0(int a1, int a2, int a3);
int __fastcall sub_8077DF0(int a1, int a2, int a3);
int __cdecl sub_8077E10(int a1, int a2, int a3);
int __cdecl sub_8077E90(int a1, int a2, int a3);
_DWORD __cdecl sub_8077F10(_DWORD, _DWORD, _DWORD); // weak
int __cdecl sub_8077F50(int a1, int a2);
int __fastcall sub_80780C0(int a1, int a2, int a3, const void *a4, int a5);
void *__fastcall sub_80781A0(int a1, int a2, int a3, const void *a4, int a5);
void *__cdecl sub_8078230(int a1, const void *a2, int a3);
int __fastcall sub_8078330(int a1, int a2, int a3, unsigned int a4, unsigned int a5);
int __cdecl sub_8078490(const void *a1, const void *a2, int a3);
char __cdecl sub_8078550(int a1, int a2);
char __cdecl sub_80785A0(int a1, int a2);
int __fastcall sub_80785C0(int a1, int a2, int a3, int a4, int a5, int a6, int a7);
_DWORD __cdecl sub_8078660(_DWORD, _DWORD, _DWORD, _DWORD); // weak
_DWORD __cdecl sub_8078840(_DWORD, _DWORD, _DWORD, _DWORD); // weak
_DWORD __cdecl sub_8078A20(_DWORD, _DWORD, _DWORD, _DWORD); // weak
int __cdecl sub_8078C00(int a1, int a2, int a3, int a4);
int __cdecl sub_8078C30(int a1, int a2);
void *__cdecl sub_8078EE0(int a1, const void *a2, int a3);
void __fastcall sub_8079010(int a1, int a2, int a3);
int __fastcall sub_80790B0(unsigned int a1, int a2, int a3, int a4, int a5, int a6, int a7);
int __fastcall sub_8079290(unsigned int a1, int a2, int a3, int a4, int a5);
unsigned int __stdcall sub_8079430(unsigned int a1, unsigned int a2, int a3, unsigned int a4);
void __cdecl sub_8079710(int a1, int a2);
void __cdecl sub_8079800(int a1);
int __cdecl sub_8079830(int a1, int a2);
int __fastcall sub_807A360(int a1, int a2, int a3, int a4, unsigned int a5, int a6, int a7);
int __fastcall sub_807A480(int a1, int a2, int a3, int a4, int a5);
int __stdcall sub_807A620(int a1, int a2, int a3, int a4);
int __fastcall sub_807A900(int a1, int _EDX, int a3);
int __fastcall sub_807A980(int a1, int _EDX, int a3);
int __cdecl sub_807AA00(int a1, int a2);
int __cdecl sub_807AD50(int a1, int a2);
int __cdecl sub_807B1F0(int a1, int a2, unsigned int a3, int a4);
int __fastcall sub_807B640(int a1, int a2, int a3);
int __fastcall sub_807B980(int a1, int a2, int a3);
void __fastcall sub_807B9C0(int a1, int a2, int a3);
int __fastcall sub_807BA10(int a1, int a2, int a3, int a4, int a5);
int __cdecl sub_807BC40(int a1, int a2, int a3);
int __cdecl sub_807C2A0(int a1, int a2);
int __cdecl sub_807C300(int *a1);
int __cdecl sub_807C3F0(int a1);
int __fastcall sub_807C4D0(int a1, int a2, int a3, int a4, int a5);
int __stdcall sub_807CA40(int a1, int a2, int a3);
int __cdecl sub_807CAF0(int a1);
int __fastcall sub_807CC80(int a1, int a2, int a3, int a4, int a5);
int __cdecl std__basic_stringbuf_char_std__char_traits_char__std__allocator_char_____basic_stringbuf(int a1);
int __fastcall sub_807D5B0(int a1, int a2, int *a3);
void __cdecl sub_807D630(int a1, int a2);
void __cdecl sub_807D6A0(int a1);
int __cdecl sub_807D6D0(int a1, int a2);
int __cdecl sub_807DB50(int a1, int a2, int a3);
int __cdecl sub_807DEF0(int a1, int a2, int a3);
int __cdecl sub_807E2A0(int a1, int a2);
void __cdecl sub_807E310();
int __cdecl sub_807E370(int a1, int a2, signed int a3, int a4, char a5);
int __cdecl sub_807E820(int a1, int *a2, int *a3);
void __cdecl sub_807EA30();
signed int __fastcall sub_807EA40(int a1, int a2, int a3, int a4, int a5);
void __cdecl sub_807EA9A();
int (*__cdecl sub_807EAA0())();
void __cdecl term_proc();


//----- (08049E14) --------------------------------------------------------
int __fastcall init_proc(int a1)
{
  int v2; // [sp+0h] [bp-8h]@3

  if ( _gmon_start___ptr )
    __gmon_start__(a1, _gmon_start___ptr);
  sub_804A630();
  sub_807EAA0();
  return v2;
}

//----- (0804A5A0) --------------------------------------------------------
#error "804A5A3: positive sp value has been found (funcsize=2)"

//----- (0804A5D0) --------------------------------------------------------
void __cdecl sub_804A5D0()
{
  int v0; // edx@2
  int i; // ebx@2
  signed int v2; // eax@2

  if ( !byte_8087470 )
  {
    v0 = dword_8087474;
    v2 = (signed int)(&unk_8086EF8 - (_UNKNOWN *)dword_8086EF4) >> 2;
    for ( i = v2 - 1; dword_8087474 < (unsigned int)i; v0 = dword_8087474 )
    {
      dword_8087474 = v0 + 1;
      ((int (*)(void))dword_8086EF4[v0 + 1])();
    }
    byte_8087470 = 1;
  }
}

//----- (0804A630) --------------------------------------------------------
int __cdecl sub_804A630()
{
  int result; // eax@1

  result = dword_8086EFC;
  if ( dword_8086EFC )
    result = 0;
  return result;
}

//----- (0804A660) --------------------------------------------------------
void __cdecl status_update()
{
  FILE *v0; // eax@2
  FILE *v1; // esi@2
  __int32 v2; // eax@3
  size_t v3; // edi@3
  size_t v4; // ebx@3
  void *v5; // eax@3
  void *v6; // eax@3
  const char *v7; // esi@3
  size_t v8; // edi@3
  FILE *v9; // eax@3
  FILE *v10; // ebx@3
  void *v11; // [sp+18h] [bp-10h]@3

  if ( path_to_stat )
  {
    v0 = fopen("stat_template.txt", (const char *)&unk_807EB08);
    v1 = v0;
    if ( v0 )
    {
      fseek(v0, 0, 2);
      v2 = ftell(v1);
      v3 = v2;
      v4 = v2 + 1;
      fseek(v1, 0, 0);
      v5 = malloc(v4);
      v11 = v5;
      memset(v5, 0, v4);
      fread(v11, v3, 1u, v1);
      fclose(v1);
      v6 = malloc(v3 + 17);
      v7 = (const char *)v6;
      memset(v6, 0, v3 + 17);
      __sprintf_chk(v7, 1, -1, (const char *)v11, (unsigned __int16)clientsNum);
      v8 = strlen(v7);
      v9 = fopen((const char *)path_to_stat, (const char *)L"w");
      v10 = v9;
      fwrite(v7, v8, 1u, v9);
      fclose(v10);
      free((void *)v7);
      free(v11);
    }
    else
    {
      puts("\nCannot open template, exiting...");
    }
  }
}

//----- (0804A7D0) --------------------------------------------------------
int __usercall sub_804A7D0<eax>(int result<eax>, int a2<edx>)
{
  int v2; // ecx@1
  int v3; // ebx@1
  int v4; // esi@1
  int v5; // edi@1
  int v6; // ebx@1
  int v7; // ecx@1
  int v8; // ebx@1
  int v9; // ecx@1
  int v10; // ebx@1
  int v11; // edi@1
  int v12; // ecx@1
  int v13; // edi@1
  int v14; // edi@1
  int v15; // esi@1
  int v16; // ecx@1
  int v17; // ebx@1
  int v18; // esi@1
  int v19; // ecx@1
  int v20; // esi@1
  int v21; // ecx@1
  int v22; // ecx@1
  int v23; // ecx@1
  int v24; // ebx@1
  int v25; // ebx@1
  int v26; // ecx@1
  int v27; // edi@1
  int v28; // edi@1
  int v29; // esi@1
  int v30; // ecx@1
  int v31; // ebx@1
  int v32; // esi@1
  int v33; // esi@1
  int v34; // ecx@1
  int v35; // ecx@1
  int v36; // ebx@1
  int v37; // ecx@1
  int v38; // ebx@1
  int v39; // ebx@1
  int v40; // ecx@1
  int v41; // edi@1
  int v42; // edi@1
  int v43; // esi@1
  int v44; // ecx@1
  int v45; // ebx@1
  int v46; // esi@1
  int v47; // esi@1
  int v48; // ecx@1
  int v49; // ecx@1
  int v50; // ebx@1
  int v51; // ecx@1
  int v52; // ebx@1
  int v53; // ebx@1
  int v54; // edi@1
  int v55; // edi@1
  int v56; // ecx@1
  int v57; // edx@1
  int v58; // esi@1
  int v59; // esi@1
  int v60; // esi@1
  int v61; // edx@1
  int v62; // ebx@1
  int v63; // ebx@1
  int v64; // edi@1
  int v65; // edi@1
  int v66; // esi@1
  int v67; // esi@1
  int v68; // edx@1
  int v69; // ebx@1
  int v70; // ebx@1
  int v71; // edi@1
  int v72; // edi@1
  int v73; // esi@1
  int v74; // esi@1
  int v75; // edx@1
  int v76; // ebx@1
  int v77; // ebx@1
  int v78; // edi@1
  int v79; // edi@1
  int v80; // esi@1
  int v81; // esi@1
  int v82; // edx@1
  int v83; // ebx@1
  int v84; // ebx@1
  int v85; // edi@1
  int v86; // edi@1
  int v87; // esi@1
  int v88; // esi@1
  int v89; // edx@1
  int v90; // ecx@1
  int v91; // ebx@1
  int v92; // ebx@1
  int v93; // edi@1
  int v94; // edi@1
  int v95; // esi@1
  int v96; // esi@1
  int v97; // edx@1
  int v98; // ecx@1
  int v99; // ebx@1
  int v100; // ebx@1
  int v101; // edi@1
  int v102; // edi@1
  int v103; // esi@1
  int v104; // esi@1
  int v105; // edx@1
  int v106; // ecx@1
  int v107; // ebx@1
  int v108; // ebx@1
  int v109; // edi@1
  int v110; // edi@1
  int v111; // esi@1
  int v112; // esi@1
  int v113; // edx@1
  int v114; // ecx@1
  int v115; // ebx@1
  int v116; // ebx@1
  int v117; // edi@1
  int v118; // edi@1
  int v119; // esi@1
  int v120; // esi@1
  int v121; // edx@1
  int v122; // ecx@1
  int v123; // ebx@1
  int v124; // ebx@1
  int v125; // edi@1
  int v126; // edi@1
  int v127; // esi@1
  int v128; // esi@1
  int v129; // edx@1
  int v130; // ecx@1
  int v131; // ebx@1
  int v132; // ebx@1
  int v133; // edi@1
  int v134; // edi@1
  int v135; // esi@1
  int v136; // esi@1
  int v137; // edx@1
  int v138; // ecx@1
  int v139; // ebx@1
  int v140; // ebx@1
  int v141; // edi@1
  int v142; // edi@1
  int v143; // esi@1
  int v144; // esi@1
  int v145; // edx@1
  int v146; // ecx@1
  int v147; // ebx@1
  int v148; // ebx@1
  int v149; // edi@1
  int v150; // edi@1
  int v151; // esi@1
  int v152; // esi@1
  int v153; // ecx@1
  int v154; // edx@1
  int v155; // [sp+48h] [bp-90h]@1
  int v156; // [sp+8h] [bp-D0h]@1
  int v157; // [sp+0h] [bp-D8h]@1
  int v158; // [sp+4Ch] [bp-8Ch]@1
  int v159; // [sp+50h] [bp-88h]@1
  int v160; // [sp+54h] [bp-84h]@1
  int v161; // [sp+58h] [bp-80h]@1
  int v162; // [sp+A8h] [bp-30h]@1
  int v163; // [sp+5Ch] [bp-7Ch]@1
  int v164; // [sp+60h] [bp-78h]@1
  int v165; // [sp+64h] [bp-74h]@1
  int v166; // [sp+68h] [bp-70h]@1
  int v167; // [sp+6Ch] [bp-6Ch]@1
  int v168; // [sp+ACh] [bp-2Ch]@1
  int v169; // [sp+70h] [bp-68h]@1
  int v170; // [sp+74h] [bp-64h]@1
  int v171; // [sp+78h] [bp-60h]@1
  int v172; // [sp+7Ch] [bp-5Ch]@1
  int v173; // [sp+80h] [bp-58h]@1
  int v174; // [sp+B0h] [bp-28h]@1
  int v175; // [sp+84h] [bp-54h]@1
  int v176; // [sp+88h] [bp-50h]@1
  int v177; // [sp+B4h] [bp-24h]@1
  int v178; // [sp+8Ch] [bp-4Ch]@1
  int v179; // [sp+4h] [bp-D4h]@1
  int v180; // [sp+90h] [bp-48h]@1
  int v181; // [sp+94h] [bp-44h]@1
  int v182; // [sp+BCh] [bp-1Ch]@1
  int v183; // [sp+B8h] [bp-20h]@1
  int v184; // [sp+98h] [bp-40h]@1
  int v185; // [sp+C0h] [bp-18h]@1
  int v186; // [sp+9Ch] [bp-3Ch]@1
  int v187; // [sp+C4h] [bp-14h]@1
  int v188; // [sp+A0h] [bp-38h]@1
  int v189; // [sp+C8h] [bp-10h]@1
  int v190; // [sp+A4h] [bp-34h]@1

  v2 = *(_DWORD *)a2;
  v3 = *(_DWORD *)result;
  v4 = *(_DWORD *)(result + 8);
  v5 = *(_DWORD *)(result + 12);
  v155 = *(_DWORD *)a2;
  v6 = v3 + v2 - 680876936;
  v7 = *(_DWORD *)(result + 4);
  v156 = v6;
  v8 = (v4 & *(_DWORD *)(result + 4) | v5 & ~v7) + v6;
  v9 = *(_DWORD *)(a2 + 4);
  v8 = __ROR__(v8, 25);
  v10 = *(_DWORD *)(result + 4) + v8;
  v157 = v5 + v9 - 389564586;
  v11 = *(_DWORD *)(result + 4);
  v158 = v9;
  v156 = v10;
  v12 = *(_DWORD *)(a2 + 8);
  v13 = __ROR__((v10 & v11 | v4 & ~v10) + v157, 20);
  v14 = v10 + v13;
  v159 = *(_DWORD *)(a2 + 8);
  v15 = v4 + v12 + 606105819;
  v16 = v14 & v10 | *(_DWORD *)(result + 4) & ~v14;
  v17 = *(_DWORD *)(a2 + 12);
  v18 = v16 + v15;
  v19 = *(_DWORD *)(result + 4);
  v18 = __ROR__(v18, 15);
  v20 = v14 + v18;
  v160 = *(_DWORD *)(a2 + 12);
  v161 = v19 + v17 - 1044525330;
  v21 = __ROR__(v161 + (v14 & v20 | v156 & ~v20), 10);
  v162 = v20 + v21;
  v22 = *(_DWORD *)(a2 + 16);
  v163 = *(_DWORD *)(a2 + 16);
  v156 = v156 + v22 - 176418897;
  v23 = *(_DWORD *)(a2 + 20);
  v24 = __ROR__((v20 & v162 | v14 & ~v162) + v156, 25);
  v25 = v162 + v24;
  v157 = v14 + v23 + 1200080426;
  v164 = v23;
  v156 = v25;
  v26 = *(_DWORD *)(a2 + 24);
  v27 = __ROR__((v25 & v162 | v20 & ~v25) + v157, 20);
  v28 = v25 + v27;
  v165 = *(_DWORD *)(a2 + 24);
  v29 = v20 + v26 - 1473231341;
  v30 = v28 & v25 | v162 & ~v28;
  v31 = *(_DWORD *)(a2 + 28);
  v32 = __ROR__(v30 + v29, 15);
  v33 = v28 + v32;
  v166 = *(_DWORD *)(a2 + 28);
  v167 = v162 + v31 - 45705983;
  v34 = __ROR__(v167 + (v28 & v33 | v156 & ~v33), 10);
  v168 = v33 + v34;
  v35 = *(_DWORD *)(a2 + 32);
  v169 = *(_DWORD *)(a2 + 32);
  v36 = v156 + v35 + 1770035416;
  v156 += v35 + 1770035416;
  v37 = *(_DWORD *)(a2 + 36);
  v38 = __ROR__((v33 & v168 | v28 & ~v168) + v36, 25);
  v39 = v168 + v38;
  v157 = v28 + v37 - 1958414417;
  v170 = v37;
  v156 = v39;
  v40 = *(_DWORD *)(a2 + 40);
  v41 = __ROR__((v39 & v168 | v33 & ~v39) + v157, 20);
  v42 = v39 + v41;
  v171 = *(_DWORD *)(a2 + 40);
  v43 = v33 + v40 - 42063;
  v44 = v42 & v39 | v168 & ~v42;
  v45 = *(_DWORD *)(a2 + 44);
  v46 = __ROR__(v44 + v43, 15);
  v47 = v42 + v46;
  v172 = *(_DWORD *)(a2 + 44);
  v173 = v168 + v45 - 1990404162;
  v48 = __ROR__(v173 + (v42 & v47 | v156 & ~v47), 10);
  v174 = v47 + v48;
  v49 = *(_DWORD *)(a2 + 48);
  v175 = *(_DWORD *)(a2 + 48);
  v50 = v156 + v49 + 1804603682;
  v156 += v49 + 1804603682;
  v51 = *(_DWORD *)(a2 + 52);
  v52 = __ROR__((v47 & v174 | v42 & ~v174) + v50, 25);
  v53 = v174 + v52;
  v157 = v42 + v51 - 40341101;
  v176 = v51;
  v54 = __ROR__((v53 & v174 | v47 & ~v53) + v157, 20);
  v55 = v53 + v54;
  v177 = ~v55;
  v56 = *(_DWORD *)(a2 + 56);
  v57 = *(_DWORD *)(a2 + 60);
  v178 = v56;
  v58 = v47 + v56 - 1502002290;
  v179 = v58;
  v180 = v57;
  v59 = __ROR__((v53 & v55 | v174 & ~v55) + v58, 15);
  v60 = v55 + v59;
  v181 = v174 + v57 + 1236535329;
  v61 = __ROR__(v174 + v57 + 1236535329 + (v55 & v60 | v53 & ~v60), 10);
  v182 = v60 + v61;
  v177 = v60 & ~v55;
  v183 = (v60 + v61) & ~v60;
  v62 = __ROR__((v60 & ~v55 | v55 & (v60 + v61)) + v53 + v158 - 165796510, 27);
  v63 = v60 + v61 + v62;
  v64 = __ROR__(((v60 + v61) & ~v60 | v60 & v63) + v55 + v165 - 1069501632, 23);
  v65 = v63 + v64;
  v66 = __ROR__((v63 & ~v182 | v65 & v182) + v60 + v172 + 643717713, 18);
  v67 = v65 + v66;
  v184 = v182 + v155 - 373897302;
  v68 = __ROR__((v65 & ~v63 | v63 & v67) + v182 + v155 - 373897302, 12);
  v185 = v67 + v68;
  v69 = __ROR__((v67 & ~v65 | v65 & (v67 + v68)) + v63 + v164 - 701558691, 27);
  v70 = v67 + v68 + v69;
  v71 = __ROR__(((v67 + v68) & ~v67 | v67 & v70) + v65 + v171 + 38016083, 23);
  v72 = v70 + v71;
  v73 = __ROR__((v70 & ~v185 | v72 & v185) + v67 + v180 - 660478335, 18);
  v74 = v72 + v73;
  v186 = v185 + v163 - 405537848;
  v75 = __ROR__((v72 & ~v70 | v70 & v74) + v185 + v163 - 405537848, 12);
  v187 = v74 + v75;
  v76 = __ROR__((v74 & ~v72 | v72 & (v74 + v75)) + v70 + v170 + 568446438, 27);
  v77 = v74 + v75 + v76;
  v78 = __ROR__(((v74 + v75) & ~v74 | v74 & v77) + v72 + v56 - 1019803690, 23);
  v79 = v77 + v78;
  v80 = __ROR__((v77 & ~v187 | v79 & v187) + v74 + v160 - 187363961, 18);
  v81 = v79 + v80;
  v188 = v187 + v169 + 1163531501;
  v82 = __ROR__((v79 & ~v77 | v77 & v81) + v187 + v169 + 1163531501, 12);
  v189 = v81 + v82;
  v83 = __ROR__((v81 & ~v79 | v79 & (v81 + v82)) + v77 + v176 - 1444681467, 27);
  v84 = v81 + v82 + v83;
  v85 = __ROR__(((v81 + v82) & ~v81 | v81 & v84) + v79 + v159 - 51403784, 23);
  v86 = v84 + v85;
  v87 = __ROR__((v84 & ~v189 | v86 & v189) + v81 + v166 + 1735328473, 18);
  v88 = v86 + v87;
  v190 = v189 + v175 - 1926607734;
  v89 = __ROR__((v86 & ~v84 | v84 & v88) + v189 + v175 - 1926607734, 12);
  v90 = v89 + v88;
  v91 = __ROR__(((v89 + v88) ^ v86 ^ v88) + v84 + v164 - 378558, 28);
  v92 = v89 + v88 + v91;
  v93 = __ROR__((v92 ^ v88 ^ (v89 + v88)) + v86 + v169 - 2022574463, 21);
  v94 = v92 + v93;
  v95 = __ROR__((v94 ^ (v89 + v88) ^ v92) + v88 + v172 + 1839030562, 16);
  v96 = v94 + v95;
  v97 = __ROR__(v90 + v178 - 35309556 + (v96 ^ v92 ^ v94), 9);
  v98 = v97 + v96;
  v99 = __ROR__(((v97 + v96) ^ v94 ^ v96) + v92 + v158 - 1530992060, 28);
  v100 = v97 + v96 + v99;
  v101 = __ROR__((v100 ^ v96 ^ (v97 + v96)) + v94 + v163 + 1272893353, 21);
  v102 = v100 + v101;
  v103 = __ROR__((v102 ^ (v97 + v96) ^ v100) + v96 + v166 - 155497632, 16);
  v104 = v102 + v103;
  v105 = __ROR__(v98 + v171 - 1094730640 + (v104 ^ v100 ^ v102), 9);
  v106 = v105 + v104;
  v107 = __ROR__(((v105 + v104) ^ v102 ^ v104) + v100 + v176 + 681279174, 28);
  v108 = v105 + v104 + v107;
  v109 = __ROR__((v108 ^ v104 ^ (v105 + v104)) + v102 + v155 - 358537222, 21);
  v110 = v108 + v109;
  v111 = __ROR__((v110 ^ (v105 + v104) ^ v108) + v104 + v160 - 722521979, 16);
  v112 = v110 + v111;
  v113 = __ROR__(v106 + v165 + 76029189 + (v112 ^ v108 ^ v110), 9);
  v114 = v113 + v112;
  v115 = __ROR__(((v113 + v112) ^ v110 ^ v112) + v108 + v170 - 640364487, 28);
  v116 = v113 + v112 + v115;
  v117 = __ROR__((v116 ^ v112 ^ (v113 + v112)) + v110 + v175 - 421815835, 21);
  v118 = v116 + v117;
  v119 = __ROR__((v118 ^ (v113 + v112) ^ v116) + v112 + v180 + 530742520, 16);
  v120 = v118 + v119;
  v121 = __ROR__(v114 + v159 - 995338651 + (v120 ^ v116 ^ v118), 9);
  v122 = v121 + v120;
  v123 = __ROR__((v120 ^ ((v121 + v120) | ~v118)) + v116 + v155 - 198630844, 26);
  v124 = v121 + v120 + v123;
  v125 = __ROR__(((v121 + v120) ^ (v124 | ~v120)) + v118 + v166 + 1126891415, 22);
  v126 = v124 + v125;
  v127 = __ROR__((v124 ^ (v126 | ~(v121 + v120))) + v120 + v178 - 1416354905, 17);
  v128 = v126 + v127;
  v129 = __ROR__(v122 + v164 - 57434055 + (v126 ^ (v128 | ~v124)), 11);
  v130 = v129 + v128;
  v131 = __ROR__((v128 ^ ((v129 + v128) | ~v126)) + v124 + v175 + 1700485571, 26);
  v132 = v129 + v128 + v131;
  v133 = __ROR__(((v129 + v128) ^ (v132 | ~v128)) + v126 + v160 - 1894986606, 22);
  v134 = v132 + v133;
  v135 = __ROR__((v132 ^ (v134 | ~(v129 + v128))) + v128 + v171 - 1051523, 17);
  v136 = v134 + v135;
  v137 = __ROR__(v130 + v158 - 2054922799 + (v134 ^ (v136 | ~v132)), 11);
  v138 = v137 + v136;
  v139 = __ROR__((v136 ^ ((v137 + v136) | ~v134)) + v132 + v169 + 1873313359, 26);
  v140 = v137 + v136 + v139;
  v141 = __ROR__(((v137 + v136) ^ (v140 | ~v136)) + v134 + v180 - 30611744, 22);
  v142 = v140 + v141;
  v143 = __ROR__((v140 ^ (v142 | ~(v137 + v136))) + v136 + v165 - 1560198380, 17);
  v144 = v142 + v143;
  v145 = __ROR__(v138 + v176 + 1309151649 + (v142 ^ (v144 | ~v140)), 11);
  v146 = v145 + v144;
  v147 = __ROR__((v144 ^ ((v145 + v144) | ~v142)) + v140 + v163 - 145523070, 26);
  v148 = v145 + v144 + v147;
  v149 = __ROR__(((v145 + v144) ^ (v148 | ~v144)) + v142 + v172 - 1120210379, 22);
  v150 = v148 + v149;
  v151 = __ROR__((v148 ^ (v150 | ~(v145 + v144))) + v144 + v159 + 718787259, 17);
  v152 = v150 + v151;
  v153 = (v150 ^ (v152 | ~v148)) + v146 + v170 - 343485551;
  *(_DWORD *)result += v148;
  v153 = __ROR__(v153, 11);
  v154 = *(_DWORD *)(result + 4) + v152;
  *(_DWORD *)(result + 8) += v152;
  *(_DWORD *)(result + 12) += v150;
  *(_DWORD *)(result + 4) = v153 + v154;
  return result;
}

//----- (0804B030) --------------------------------------------------------
int __usercall sub_804B030<eax>(unsigned int *a1<eax>, int *a2<edx>, unsigned int a3<ecx>)
{
  int v3; // eax@1
  unsigned int v4; // edx@1
  int v5; // ecx@1
  unsigned int *v6; // ebx@1
  int *v7; // edi@1
  unsigned int v8; // esi@1
  int result; // eax@3
  int v10; // edx@3
  signed int v11; // ecx@7
  unsigned __int8 v12; // cf@1
  int v13; // [sp+0h] [bp-50h]@3
  _BYTE v14[76]; // [sp+4h] [bp-4Ch]@8

  v7 = a2;
  v8 = a3;
  v6 = a1;
  v4 = *a1;
  v3 = 8 * a3;
  v12 = __MKCADD__(v4, 8 * a3);
  v5 = v4 + 8 * a3;
  if ( v12 )
  {
    ++*(v6 + 1);
    v5 = v4 + v3;
  }
  *(v6 + 1) += v8 >> 29;
  v10 = (v4 >> 3) & 0x3F;
  result = (int)(v6 + 2);
  *v6 = v5;
  v13 = (int)(v6 + 2);
  while ( v8 )
  {
    result = *(_BYTE *)v7;
    *((_BYTE *)v6 + v10++ + 24) = *(_BYTE *)v7;
    if ( v10 == 64 )
    {
      v11 = 0;
      do
      {
        *(_DWORD *)&v14[v11] = (*((_BYTE *)v6 + v11 + 25) << 8) | *((_BYTE *)v6 + v11 + 24) | (*((_BYTE *)v6 + v11 + 26) << 16) | (*((_BYTE *)v6 + v11 + 27) << 24);
        v11 += 4;
      }
      while ( v11 != 64 );
      result = sub_804A7D0(v13, (int)v14);
      v10 = 0;
    }
    v7 = (int *)((char *)v7 + 1);
    --v8;
  }
  return result;
}

//----- (0804B0E0) --------------------------------------------------------
#error "804B21F: invalid basic block (funcsize=105)"

//----- (0804B220) --------------------------------------------------------
int __cdecl sub_804B220(int a1, int a2)
{
  unsigned int v2; // ebx@1
  int v3; // edi@1
  int v4; // esi@1
  int result; // eax@2
  int v6; // edx@3
  int v7; // ecx@3
  time_t v8; // eax@3
  char v9; // [sp+18h] [bp-10h]@5

  v2 = 0;
  v4 = a1;
  v3 = a2;
  while ( 1 )
  {
    result = -1227133513 * ((*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) >> 2);
    if ( v2 >= result )
      break;
    v8 = time(0);
    v6 = *(_DWORD *)v4 + 28 * v2;
    if ( v8 - *(_DWORD *)(v6 + 24) >= v3 )
      sub_804B5E0(v7, v6, (int)&v9, v4, *(_DWORD *)v4 + 28 * v2);
    else
      ++v2;
  }
  return result;
}

//----- (0804B290) --------------------------------------------------------
signed int __cdecl sub_804B290(int a1, int a2)
{
  int v2; // edx@1
  unsigned int v3; // eax@2
  int v4; // ecx@2
  int v5; // ebx@2
  __int16 v6; // si@2
  __int16 v7; // dx@5
  int v8; // edx@7
  signed int result; // eax@9
  int v10; // eax@1
  int v11; // ecx@9
  int v12; // [sp+14h] [bp-14h]@1
  char v13; // [sp+18h] [bp-10h]@9

  v2 = *(_DWORD *)a1;
  v10 = -1227133513 * ((*(_DWORD *)(a1 + 4) - *(_DWORD *)a1) >> 2);
  v12 = -1227133513 * ((*(_DWORD *)(a1 + 4) - *(_DWORD *)a1) >> 2);
  if ( v10 )
  {
    v6 = *(_WORD *)a2;
    v4 = v2;
    v3 = 0;
    v5 = 0;
    while ( 1 )
    {
      if ( *(_WORD *)v4 == v6 || !v6 )
      {
        v7 = *(_WORD *)(a2 + 2);
        if ( *(_WORD *)(v4 + 2) == v7 || !v7 )
        {
          v8 = *(_DWORD *)(a2 + 8);
          if ( *(_DWORD *)(v4 + 8) == v8 )
            break;
          if ( !v8 )
            break;
        }
      }
      ++v3;
      v5 += 28;
      v4 += 28;
      if ( v12 <= v3 )
        goto LABEL_11;
    }
    *(_WORD *)a2 = *(_WORD *)v4;
    *(_WORD *)(a2 + 2) = *(_WORD *)(v4 + 2);
    *(_WORD *)(a2 + 4) = *(_WORD *)(v4 + 4);
    *(_DWORD *)(a2 + 8) = *(_DWORD *)(v4 + 8);
    sub_804B500(v4, v8, a2 + 12, v4 + 12);
    sub_804B5E0(v11, a1, (int)&v13, a1, *(_DWORD *)a1 + v5);
    result = 1;
  }
  else
  {
LABEL_11:
    result = 0;
  }
  return result;
}

//----- (0804B370) --------------------------------------------------------
int __cdecl sub_804B370(int a1, int a2)
{
  int v2; // edx@1
  const void *v3; // ecx@1
  int v4; // ebx@1
  int v5; // edi@1
  void *v6; // esi@2
  int v7; // edx@3
  int v8; // ecx@3
  int v9; // esi@3
  int v10; // ebx@5
  int v11; // edi@5
  int v12; // edx@8
  int v13; // ebx@8
  time_t v15; // eax@1
  int v16; // eax@2
  int v17; // ebx@3
  __int16 v18; // ax@5
  __int16 v19; // ax@5
  int v20; // eax@7
  int v21; // ebx@7
  size_t v22; // ebx@7
  time_t v23; // eax@7
  int v24; // [sp+34h] [bp-14h]@1
  int v25; // [sp+30h] [bp-18h]@1
  const void *v26; // [sp+2Ch] [bp-1Ch]@1
  time_t v27; // [sp+18h] [bp-30h]@1
  __int16 v28; // [sp+20h] [bp-28h]@1
  __int16 v29; // [sp+22h] [bp-26h]@1
  __int16 v30; // [sp+24h] [bp-24h]@1
  int v31; // [sp+28h] [bp-20h]@1
  time_t v32; // [sp+38h] [bp-10h]@3

  v4 = a2;
  v15 = time(0);
  v24 = 0;
  v2 = *(_DWORD *)(v4 + 16);
  v3 = *(const void **)(v4 + 12);
  v25 = 0;
  v26 = 0;
  v27 = v15;
  v5 = v2 - (_DWORD)v3;
  v28 = *(_WORD *)v4;
  v29 = *(_WORD *)(v4 + 2);
  v30 = *(_WORD *)(v4 + 4);
  v31 = *(_DWORD *)(v4 + 8);
  if ( v2 == (_DWORD)v3 )
  {
    v6 = 0;
  }
  else
  {
    v16 = operator new(v3, v2);
    v3 = *(const void **)(v4 + 12);
    v6 = (void *)v16;
    v2 = *(_DWORD *)(v4 + 16);
  }
  v17 = v2 - (_DWORD)v3;
  v26 = v6;
  v24 = (int)((char *)v6 + v5);
  memmove(v6, v3, v2 - (_DWORD)v3);
  v7 = (int)((char *)v6 + v17);
  v25 = (int)((char *)v6 + v17);
  v32 = v27;
  v9 = *(_DWORD *)(a1 + 4);
  if ( v9 == *(_DWORD *)(a1 + 8) )
  {
    v13 = (int)&v28;
    sub_804B680(v8, v5, a1, v9, (int)&v28);
  }
  else
  {
    if ( v9 )
    {
      v18 = v28;
      v11 = 0;
      v10 = v7 - (_DWORD)v26;
      *(_DWORD *)(v9 + 16) = 0;
      *(_DWORD *)(v9 + 12) = 0;
      *(_WORD *)v9 = v18;
      v19 = v29;
      *(_DWORD *)(v9 + 20) = 0;
      *(_WORD *)(v9 + 2) = v19;
      *(_WORD *)(v9 + 4) = v30;
      *(_DWORD *)(v9 + 8) = v31;
      if ( v10 )
        v11 = operator new(v8, v7);
      v20 = v11 + v10;
      *(_DWORD *)(v9 + 12) = v11;
      *(_DWORD *)(v9 + 16) = v11;
      v21 = v25;
      *(_DWORD *)(v9 + 20) = v20;
      v22 = v21 - (_DWORD)v26;
      memmove((void *)v11, v26, v22);
      v23 = v32;
      *(_DWORD *)(v9 + 16) = v11 + v22;
      *(_DWORD *)(v9 + 24) = v23;
      v9 = *(_DWORD *)(a1 + 4);
    }
    v12 = a1;
    v13 = (int)&v28;
    *(_DWORD *)(a1 + 4) = v9 + 28;
  }
  return sub_8052330(v8, v12, v13);
}

//----- (0804B500) --------------------------------------------------------
int __fastcall sub_804B500(int a1, int a2, int a3, int a4)
{
  int v3; // esi@1
  void *v4; // edx@2
  size_t v5; // ebx@2
  const void *v6; // edi@2
  int v7; // ecx@3
  int v8; // esi@3
  size_t v10; // eax@7
  int v11; // eax@3

  v3 = a4;
  if ( a4 != a3 )
  {
    v6 = *(const void **)a4;
    v4 = *(void **)a3;
    v5 = *(_DWORD *)(a4 + 4) - *(_DWORD *)a4;
    if ( v5 <= *(_DWORD *)(a3 + 8) - *(_DWORD *)a3 )
    {
      v10 = *(_DWORD *)(a3 + 4) - (_DWORD)v4;
      if ( v5 > v10 )
      {
        memmove(*(void **)a3, v6, v10);
        memmove(
          *(void **)(a3 + 4),
          (const void *)(*(_DWORD *)v3 + *(_DWORD *)(a3 + 4) - *(_DWORD *)a3),
          *(_DWORD *)(v3 + 4) - (*(_DWORD *)v3 + *(_DWORD *)(a3 + 4) - *(_DWORD *)a3));
      }
      else
      {
        memmove(v4, v6, *(_DWORD *)(a4 + 4) - *(_DWORD *)a4);
      }
      *(_DWORD *)(a3 + 4) = *(_DWORD *)a3 + v5;
    }
    else
    {
      v11 = operator new(a1, v4);
      v8 = v11;
      memmove((void *)v11, v6, v5);
      if ( *(_DWORD *)a3 )
        operator delete(v7, a3);
      *(_DWORD *)a3 = v8;
      *(_DWORD *)(a3 + 8) = v8 + v5;
      *(_DWORD *)(a3 + 4) = *(_DWORD *)a3 + v5;
    }
  }
  return a3;
}

//----- (0804B5E0) --------------------------------------------------------
int __fastcall sub_804B5E0(int a1, int a2, int a3, int a4, int a5)
{
  int v2; // edx@1
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@2
  int result; // eax@5
  int v7; // eax@2

  v4 = a4;
  v2 = *(_DWORD *)(a4 + 4);
  v3 = a5 + 28;
  if ( v2 != a5 + 28 )
  {
    v7 = (v2 - v3) >> 2;
    v5 = -1227133513 * v7;
    if ( -1227133513 * v7 > 0 )
    {
      do
      {
        --v5;
        *(_WORD *)(v3 - 28) = *(_WORD *)v3;
        *(_WORD *)(v3 - 26) = *(_WORD *)(v3 + 2);
        *(_WORD *)(v3 - 24) = *(_WORD *)(v3 + 4);
        *(_DWORD *)(v3 - 20) = *(_DWORD *)(v3 + 8);
        sub_804B500(a1, v2, v3 - 16, v3 + 12);
        *(_DWORD *)(v3 - 4) = *(_DWORD *)(v3 + 24);
        v3 += 28;
      }
      while ( v5 > 0 );
      v2 = *(_DWORD *)(v4 + 4);
    }
  }
  *(_DWORD *)(v4 + 4) = v2 - 28;
  sub_8052330(a1, v2, v2 - 28);
  result = a3;
  *(_DWORD *)a3 = a5;
  return result;
}

//----- (0804B680) --------------------------------------------------------
int __usercall sub_804B680<eax>(int a1<ecx>, int a2<edi>, int a3, int a4, int a5)
{
  int v5; // esi@1
  int v6; // edx@3
  int v7; // ebx@3
  int v8; // edi@3
  int v9; // edx@6
  const void *v10; // ecx@6
  int v11; // ebx@6
  int v12; // esi@7
  int v13; // ecx@8
  int v14; // ebx@8
  int i; // esi@8
  int result; // eax@10
  int v17; // eax@12
  int v18; // esi@12
  int v19; // edx@13
  int v20; // edx@15
  int v21; // esi@21
  int v22; // edx@23
  int v23; // ebx@23
  int v24; // edi@23
  int v25; // ebx@28
  int v26; // esi@28
  int v27; // edx@31
  int v28; // edi@31
  int v29; // edx@32
  int v30; // esi@32
  int v31; // ebx@34
  int v32; // eax@39
  int v33; // ebx@39
  int v34; // edx@45
  int v35; // ecx@45
  int j; // ebx@45
  int v37; // eax@47
  int v38; // edx@48
  int v39; // ecx@48
  int v40; // ebx@49
  __int16 v41; // ax@3
  __int16 v42; // ax@3
  int v43; // ebx@5
  __int16 v44; // ax@6
  int v45; // eax@6
  int v46; // ebx@8
  int v47; // edx@8
  int v48; // eax@8
  int v49; // edx@9
  int v50; // ecx@10
  unsigned __int8 v51; // cf@15
  int v52; // eax@20
  __int16 v53; // ax@23
  __int16 v54; // ax@23
  int v55; // ebx@25
  int v56; // eax@26
  int v57; // eax@28
  int v58; // ebx@30
  int v59; // edx@30
  __int16 v60; // ax@34
  __int16 v61; // ax@34
  int v62; // eax@34
  int v63; // eax@36
  int v64; // eax@36
  int v65; // ebx@36
  size_t v66; // ebx@36
  int v67; // ebx@36
  int v68; // ST00_4@40
  int v69; // edx@44
  int v70; // eax@45
  int v71; // ebx@48
  int v72; // ebx@53
  int v73; // ebx@53
  int v74; // ecx@53
  int v75; // edx@53
  int v76; // [sp+24h] [bp-44h]@1
  int v77; // [sp+10h] [bp-58h]@3
  int v78; // [sp+54h] [bp-14h]@6
  int v79; // [sp+4Ch] [bp-1Ch]@6
  __int16 v80; // [sp+40h] [bp-28h]@6
  __int16 v81; // [sp+42h] [bp-26h]@6
  __int16 v82; // [sp+44h] [bp-24h]@6
  int v83; // [sp+50h] [bp-18h]@6
  int v84; // [sp+48h] [bp-20h]@6
  int v85; // [sp+58h] [bp-10h]@8
  signed int v86; // [sp+14h] [bp-54h]@15
  int v87; // [sp+34h] [bp-34h]@17
  int v88; // [sp+18h] [bp-50h]@20
  int v89; // [sp+38h] [bp-30h]@20
  int v90; // [sp+1Ch] [bp-4Ch]@20
  int v91; // [sp+2Ch] [bp-3Ch]@21
  int v92; // [sp+30h] [bp-38h]@31
  int v93; // [sp+28h] [bp-40h]@32
  int v94; // [sp+20h] [bp-48h]@34

  v76 = a4;
  v5 = *(_DWORD *)(a3 + 4);
  if ( v5 != *(_DWORD *)(a3 + 8) )
  {
    if ( v5 )
    {
      v8 = 0;
      v77 = v5 - 28;
      *(_WORD *)v5 = *(_WORD *)(v5 - 28);
      v6 = v77;
      *(_DWORD *)(v5 + 20) = 0;
      v41 = *(_WORD *)(v6 + 2);
      v7 = *(_DWORD *)(v6 + 16) - *(_DWORD *)(v6 + 12);
      *(_DWORD *)(v5 + 16) = 0;
      *(_WORD *)(v5 + 2) = v41;
      v42 = *(_WORD *)(v6 + 4);
      *(_DWORD *)(v5 + 12) = 0;
      *(_WORD *)(v5 + 4) = v42;
      *(_DWORD *)(v5 + 8) = *(_DWORD *)(v6 + 8);
      if ( v7 )
        v8 = operator new(a1, v6);
      *(_DWORD *)(v5 + 12) = v8;
      *(_DWORD *)(v5 + 16) = v8;
      *(_DWORD *)(v5 + 20) = v8 + v7;
      v43 = v8 + *(_DWORD *)(v77 + 16) - *(_DWORD *)(v77 + 12);
      memmove((void *)v8, *(const void **)(v77 + 12), *(_DWORD *)(v77 + 16) - *(_DWORD *)(v77 + 12));
      *(_DWORD *)(v5 + 16) = v43;
      *(_DWORD *)(v5 + 24) = *(_DWORD *)(v77 + 24);
      v5 = *(_DWORD *)(a3 + 4);
    }
    *(_DWORD *)(a3 + 4) = v5 + 28;
    v78 = 0;
    v44 = *(_WORD *)a5;
    v10 = *(const void **)(a5 + 12);
    v79 = 0;
    v80 = v44;
    v81 = *(_WORD *)(a5 + 2);
    v82 = *(_WORD *)(a5 + 4);
    v45 = *(_DWORD *)(a5 + 8);
    v9 = *(_DWORD *)(a5 + 16);
    v83 = 0;
    v84 = v45;
    v11 = v9 - (_DWORD)v10;
    if ( v9 == (_DWORD)v10 )
    {
      v12 = 0;
    }
    else
    {
      v12 = operator new(v10, v9);
      v10 = *(const void **)(a5 + 12);
      v9 = *(_DWORD *)(a5 + 16);
    }
    v79 = v12;
    v78 = v12 + v11;
    v46 = v12 + v9 - (_DWORD)v10;
    memmove((void *)v12, v10, v9 - (_DWORD)v10);
    v83 = v46;
    v85 = *(_DWORD *)(a5 + 24);
    v47 = *(_DWORD *)(a3 + 4);
    v14 = v47 - 28;
    v48 = (v47 - 56 - a4) >> 2;
    for ( i = -1227133513 * v48; i > 0; *(_DWORD *)(v14 + 24) = *(_DWORD *)(v14 - 4) )
    {
      v49 = v14 - 56;
      v14 -= 28;
      *(_WORD *)v14 = *(_WORD *)(v14 - 28);
      *(_WORD *)(v14 + 2) = *(_WORD *)(v14 - 26);
      *(_WORD *)(v14 + 4) = *(_WORD *)(v14 - 24);
      *(_DWORD *)(v14 + 8) = *(_DWORD *)(v14 - 20);
      sub_804B500(v13, v49 + 12, v14 + 12, v49 + 12);
      --i;
    }
    *(_WORD *)a4 = v80;
    *(_WORD *)(a4 + 2) = v81;
    *(_WORD *)(a4 + 4) = v82;
    *(_DWORD *)(a4 + 8) = v84;
    sub_804B500(v13, a4, a4 + 12, (int)&v79);
    *(_DWORD *)(a4 + 24) = v85;
    return sub_8052330(v50, a4, (int)&v80);
  }
  v18 = (v5 - *(_DWORD *)a3) >> 2;
  v17 = -1227133513 * v18;
  if ( -1227133513 * v18 == 153391689 )
  {
    v70 = std____throw_length_error(a1);
    __cxa_begin_catch(v70);
    for ( j = v88; j != a2; j += 28 )
      sub_8052330(v35, v34, j);
    v37 = __cxa_rethrow();
    while ( 1 )
    {
      v71 = _Unwind_Resume(v37);
      __cxa_end_catch();
      __cxa_begin_catch(v71);
      if ( v88 != v87 )
      {
        v40 = v87;
        do
        {
          sub_8052330(v39, v38, v40);
          v40 += 28;
        }
        while ( v88 != v40 );
      }
      if ( v87 )
        operator delete(v39, v87);
      v72 = __cxa_rethrow();
      __cxa_end_catch();
      v73 = _Unwind_Resume(v72);
      sub_8052330(v74, v75, (int)&v80);
      v37 = _Unwind_Resume(v73);
    }
  }
  v19 = -1227133513 * v18;
  if ( !v17 )
    v19 = 1;
  v51 = __MKCADD__(v17, v19);
  v20 = v17 + v19;
  v86 = v20;
  if ( v51 || (unsigned int)v20 > 0x9249249 )
  {
    v86 = 153391689;
  }
  else
  {
    v87 = 0;
    if ( !v20 )
      goto LABEL_20;
  }
  v87 = operator new(a1, v20);
LABEL_20:
  v88 = v87;
  v52 = *(_DWORD *)a3;
  v89 = v87;
  v90 = v52;
  if ( v52 != a4 )
  {
    v21 = v87;
    v91 = v87 + 28;
    do
    {
      if ( v21 )
      {
        v22 = v90;
        v24 = 0;
        *(_DWORD *)(v21 + 20) = 0;
        v53 = *(_WORD *)v22;
        v23 = *(_DWORD *)(v22 + 16) - *(_DWORD *)(v22 + 12);
        *(_DWORD *)(v21 + 16) = 0;
        *(_WORD *)v21 = v53;
        v54 = *(_WORD *)(v22 + 2);
        *(_DWORD *)(v21 + 12) = 0;
        *(_WORD *)(v21 + 2) = v54;
        *(_WORD *)(v21 + 4) = *(_WORD *)(v22 + 4);
        *(_DWORD *)(v21 + 8) = *(_DWORD *)(v22 + 8);
        if ( v23 )
          v24 = operator new(a1, v22);
        *(_DWORD *)(v21 + 12) = v24;
        *(_DWORD *)(v21 + 16) = v24;
        *(_DWORD *)(v21 + 20) = v24 + v23;
        v55 = v24 + *(_DWORD *)(v90 + 16) - *(_DWORD *)(v90 + 12);
        memmove((void *)v24, *(const void **)(v90 + 12), *(_DWORD *)(v90 + 16) - *(_DWORD *)(v90 + 12));
        *(_DWORD *)(v21 + 16) = v55;
        *(_DWORD *)(v21 + 24) = *(_DWORD *)(v90 + 24);
      }
      v56 = v91;
      v90 += 28;
      v91 += 28;
      v21 = v56;
      v89 = v56;
    }
    while ( v90 != a4 );
  }
  v88 = v89;
  if ( v89 )
  {
    v26 = 0;
    *(_WORD *)v89 = *(_WORD *)a5;
    *(_WORD *)(v89 + 2) = *(_WORD *)(a5 + 2);
    *(_WORD *)(v89 + 4) = *(_WORD *)(a5 + 4);
    *(_DWORD *)(v89 + 8) = *(_DWORD *)(a5 + 8);
    v57 = a5;
    *(_DWORD *)(v89 + 20) = 0;
    v25 = *(_DWORD *)(v57 + 16) - *(_DWORD *)(v57 + 12);
    *(_DWORD *)(v89 + 16) = 0;
    *(_DWORD *)(v89 + 12) = 0;
    if ( v25 )
      v26 = operator new(a1, v89);
    *(_DWORD *)(v89 + 12) = v26;
    *(_DWORD *)(v89 + 16) = v26;
    *(_DWORD *)(v89 + 20) = v26 + v25;
    v58 = v26 + *(_DWORD *)(a5 + 16) - *(_DWORD *)(a5 + 12);
    memmove((void *)v26, *(const void **)(a5 + 12), *(_DWORD *)(a5 + 16) - *(_DWORD *)(a5 + 12));
    v59 = a5;
    *(_DWORD *)(v89 + 16) = v58;
    *(_DWORD *)(v89 + 24) = *(_DWORD *)(v59 + 24);
  }
  v88 = v89 + 28;
  v28 = v89 + 28;
  v27 = *(_DWORD *)(a3 + 4);
  v92 = *(_DWORD *)(a3 + 4);
  if ( v27 != a4 )
  {
    v29 = v89 + 56;
    v93 = v89 + 56;
    v30 = a4;
    do
    {
      if ( v28 )
      {
        v60 = *(_WORD *)v30;
        v31 = *(_DWORD *)(v30 + 16) - *(_DWORD *)(v30 + 12);
        *(_DWORD *)(v28 + 16) = 0;
        *(_WORD *)v28 = v60;
        v61 = *(_WORD *)(v30 + 2);
        *(_DWORD *)(v28 + 12) = 0;
        *(_DWORD *)(v28 + 20) = 0;
        *(_WORD *)(v28 + 2) = v61;
        *(_WORD *)(v28 + 4) = *(_WORD *)(v30 + 4);
        v62 = *(_DWORD *)(v30 + 8);
        v94 = 0;
        *(_DWORD *)(v28 + 8) = v62;
        if ( v31 )
          v94 = operator new(a1, v29);
        v63 = v94;
        *(_DWORD *)(v28 + 12) = v94;
        *(_DWORD *)(v28 + 16) = v63;
        v64 = v31 + v63;
        v65 = *(_DWORD *)(v30 + 16);
        *(_DWORD *)(v28 + 20) = v64;
        v66 = v65 - *(_DWORD *)(v30 + 12);
        memmove((void *)v94, *(const void **)(v30 + 12), v66);
        v67 = v94 + v66;
        *(_DWORD *)(v28 + 24) = *(_DWORD *)(v30 + 24);
        *(_DWORD *)(v28 + 16) = v67;
      }
      v28 = v93;
      v30 += 28;
      v93 += 28;
    }
    while ( v92 != v30 );
    v27 = *(_DWORD *)(a3 + 4);
    v76 = *(_DWORD *)(a3 + 4);
  }
  v33 = *(_DWORD *)a3;
  v32 = v76;
  if ( *(_DWORD *)a3 != v76 )
  {
    do
    {
      v68 = v33;
      v33 += 28;
      sub_8052330(a1, v27, v68);
    }
    while ( v33 != v76 );
    v27 = a3;
    v32 = *(_DWORD *)a3;
  }
  if ( v32 )
    operator delete(a1, v27);
  v69 = v87;
  *(_DWORD *)a3 = v87;
  *(_DWORD *)(a3 + 4) = v28;
  result = v69 + 28 * v86;
  *(_DWORD *)(a3 + 8) = result;
  return result;
}

//----- (0804BCE0) --------------------------------------------------------
int __cdecl sub_804BCE0(int a1, int *a2, int a3)
{
  int i; // ecx@1
  int *v4; // ebx@1
  int v5; // esi@1
  char v6; // dl@5
  _UNKNOWN *v7; // eax@6
  int v8; // edx@9
  char v10; // dl@15
  char v11; // dl@18
  int v12; // [sp+0h] [bp-10h]@1

  v4 = a2;
  v5 = a3;
  v12 = a1;
  for ( i = *(_BYTE *)a2; i; --v5 )
  {
    v4 = (int *)((char *)v4 + 1);
    if ( (unsigned __int8)(i & 0xE0) == 192 )
    {
      v10 = *(_BYTE *)v4;
      if ( (unsigned __int8)(*(_BYTE *)v4 & 0xC0) == 128 )
      {
        v4 = (int *)((char *)v4 + 1);
        i = ((i & 0x1F) << 6) | v10 & 0x3F;
      }
    }
    else
    {
      if ( (unsigned __int8)(i & 0xF0) == 224 )
      {
        if ( (unsigned __int8)(*(_BYTE *)v4 & 0xC0) != 128
          || (v11 = *((_BYTE *)v4 + 1), (unsigned __int8)(v11 & 0xC0) != 128) )
          break;
        i = ((i & 0xF) << 12) | v11 & 0x3F | ((*(_BYTE *)v4 & 0x3F) << 6);
        v4 = (int *)((char *)v4 + 2);
      }
    }
    if ( v5 )
    {
      v6 = i;
      if ( (unsigned int)i > 0x7F )
      {
        v7 = &unk_807EE20;
        if ( i == 1040 )
        {
LABEL_20:
          v6 = *((_BYTE *)v7 + 3);
        }
        else
        {
          while ( 1 )
          {
            v7 = (char *)v7 + 6;
            v8 = *(_WORD *)v7;
            if ( !v8 )
              break;
            if ( i == v8 )
              goto LABEL_20;
          }
          v6 = i;
          if ( (unsigned __int8)i <= 0x1Fu )
            v6 = 32;
        }
      }
      *(_BYTE *)v12++ = v6;
    }
    i = *(_BYTE *)v4;
  }
  v12 -= a1;
  return v12;
}

//----- (0804BE30) --------------------------------------------------------
int __cdecl sub_804BE30(signed int a1)
{
  int v1; // eax@1
  int v2; // edx@5

  v1 = a1;
  if ( a1 == 168 )
  {
    LOWORD(v1) = 1025;
    goto LABEL_5;
  }
  if ( a1 == 170 )
  {
    LOWORD(v1) = 1028;
    goto LABEL_5;
  }
  if ( a1 == 175 )
  {
    LOWORD(v1) = 1031;
    goto LABEL_5;
  }
  if ( a1 == 184 )
  {
    LOWORD(v1) = 1105;
LABEL_5:
    v2 = v1;
    if ( (unsigned int)(v1 - 192) <= 0x3F )
      v2 = v1 + 848;
    return v2;
  }
  v2 = 1108;
  if ( a1 != 186 )
  {
    v2 = 1111;
    if ( a1 != 191 )
    {
      v2 = 1030;
      if ( a1 != 178 )
      {
        v2 = 1110;
        if ( a1 != 179 )
          goto LABEL_5;
      }
    }
  }
  return v2;
}

//----- (0804BF80) --------------------------------------------------------
signed int __cdecl sub_804BF80(const char *a1, const char *a2)
{
  signed int result; // eax@1
  signed int v3; // esi@1
  size_t v4; // ebx@2
  ssize_t v5; // ebx@3
  signed int v6; // ebx@4
  signed int v7; // eax@5
  const char *v8; // esi@5
  size_t v9; // edi@10
  void *v10; // eax@3
  size_t v11; // eax@10
  char v12; // [sp+24h] [bp-64h]@2
  size_t v13; // [sp+50h] [bp-38h]@2
  void *v14; // [sp+18h] [bp-70h]@3

  v3 = open(a2, 0, 256);
  result = -1;
  if ( v3 != -1 )
  {
    __fxstat(3, v3, (struct stat *)&v12);
    v4 = v13;
    if ( (signed int)v13 > 0 )
    {
      v10 = malloc(v13 + 1);
      v14 = v10;
      v5 = read(v3, v10, v4);
      close(v3);
      if ( v5 <= 0 || (*((_BYTE *)v14 + v5) = 0, v6 = *(_BYTE *)v14, !v6) )
      {
LABEL_14:
        free(v14);
        return 0;
      }
      v8 = (const char *)v14;
      v7 = 1;
      while ( 1 )
      {
        if ( v7 )
        {
          v11 = strlen(a1);
          v9 = v11;
          if ( !strncmp(v8, a1, v11) && (unsigned int)(v8[v9] - 48) > 9 )
          {
            free(v14);
            return 1;
          }
          v7 = 0;
          if ( v6 != 13 )
            goto LABEL_7;
LABEL_13:
          ++v8;
          v7 = 1;
          v6 = *v8;
          if ( !v6 )
            goto LABEL_14;
        }
        else
        {
          if ( v6 == 13 )
            goto LABEL_13;
LABEL_7:
          if ( v6 == 10 )
            goto LABEL_13;
          ++v8;
          v6 = *v8;
          if ( !v6 )
            goto LABEL_14;
        }
      }
    }
    close(v3);
    result = -1;
  }
  return result;
}

//----- (0804C150) --------------------------------------------------------
int __cdecl sub_804C150(int a1, unsigned __int16 a2)
{
  int result; // eax@1

  result = a2;
  if ( a2 <= 0xEu )
  {
    switch ( a2 )
    {
      case 0u:
        *(_WORD *)a1 = 19279;
        *(_BYTE *)(a1 + 2) = 0;
        break;
      case 1u:
      case 5u:
      case 6u:
      case 7u:
      case 8u:
      case 9u:
      case 0xBu:
        goto LABEL_2;
      case 2u:
        *(_DWORD *)a1 = 544501582;
        *(_DWORD *)(a1 + 4) = 1853189990;
        *(_WORD *)(a1 + 8) = 100;
        break;
      case 3u:
        *(_DWORD *)a1 = 1919708225;
        *(_DWORD *)(a1 + 4) = 2036621669;
        *(_DWORD *)(a1 + 8) = 1769497888;
        *(_WORD *)(a1 + 12) = 29811;
        *(_BYTE *)(a1 + 14) = 0;
        break;
      case 4u:
        *(_DWORD *)a1 = 2004116814;
        *(_DWORD *)(a1 + 4) = 543912559;
        *(_DWORD *)(a1 + 8) = 1869771365;
        *(_WORD *)(a1 + 12) = 114;
        break;
      case 0xAu:
        *(_DWORD *)a1 = 661545283;
        *(_DWORD *)(a1 + 4) = 1684086900;
        *(_WORD *)(a1 + 8) = 100;
        break;
      case 0xCu:
        *(_DWORD *)a1 = 1768778060;
        *(_DWORD *)(a1 + 4) = 1701978228;
        *(_DWORD *)(a1 + 8) = 1701340001;
        *(_WORD *)(a1 + 12) = 100;
        break;
      case 0xDu:
        *(_DWORD *)a1 = 1011697985;
        *(_DWORD *)(a1 + 4) = 1128873517;
        *(_DWORD *)(a1 + 8) = 1869488209;
        *(_DWORD *)(a1 + 12) = 1818304628;
        *(_DWORD *)(a1 + 16) = 1684371311;
        *(_BYTE *)(a1 + 20) = 0;
        break;
      case 0xEu:
        *(_DWORD *)a1 = 1953394499;
        *(_DWORD *)(a1 + 4) = 544498529;
        *(_DWORD *)(a1 + 8) = 1684366702;
        *(_DWORD *)(a1 + 12) = 1953849632;
        *(_WORD *)(a1 + 16) = 104;
        break;
    }
  }
  else
  {
LABEL_2:
    result = __sprintf_chk(a1, 1, -1, "Unknown code %u", a2);
  }
  return result;
}

//----- (0804C290) --------------------------------------------------------
signed int __cdecl recv_packet(int a1, int a2, signed int a3)
{
  signed int v3; // edx@1
  int v4; // esi@1
  unsigned __int16 v5; // ax@4
  size_t v6; // ebx@6
  size_t v7; // eax@8
  struct timeval *v8; // edx@9
  ssize_t v9; // eax@17
  struct timeval *v10; // edx@20
  int v11; // eax@22
  int v13; // eax@1
  ssize_t v14; // eax@3
  int v15; // eax@27
  unsigned int v16; // [sp+B8h] [bp-10h]@1
  unsigned int v17; // [sp+20h] [bp-A8h]@6
  void *v18; // [sp+24h] [bp-A4h]@6
  int v19; // [sp+28h] [bp-A0h]@6
  _DWORD v20[32]; // [sp+30h] [bp-98h]@9
  signed int v21; // [sp+B0h] [bp-18h]@10
  signed int v22; // [sp+B4h] [bp-14h]@11

  v4 = a1;
  v16 = 0;
  v13 = ioctl(a1, 0x541Bu, &v16);
  v3 = -1;
  if ( v13 )
    return v3;
  if ( v16 > 7 )
    goto LABEL_34;
  v10 = (struct timeval *)v20;
  do
  {
    v10->tv_sec = 0;
    v10 = (struct timeval *)((char *)v10 + 4);
  }
  while ( (signed int *)v10 != &v21 );
  v20[(unsigned int)v4 >> 5] |= 1 << (v4 & 0x1F);
  v22 = 10000;
  v21 = a3;
  v11 = select(v4 + 1, (fd_set *)v20, 0, 0, v10);
  if ( v11 )
  {
    if ( v11 < 0 )
      return -1;
    v3 = -1;
    if ( !((v20[(unsigned int)v4 >> 5] >> (v4 & 0x1F)) & 1)
      || (v16 = 0, v15 = ioctl(v4, 0x541Bu, &v16), v3 = -1, v15)
      || (v3 = -1, !v16) )
      return v3;
    if ( v16 > 7 )
    {
LABEL_34:
      v14 = recv(v4, (void *)a2, 8u, 0);
      v3 = -1;
      if ( v14 != 8 || (v3 = -1, v5 = *(_WORD *)(a2 + 6), v5 > 0x3FFFu) )
        return v3;
      if ( !v5 )
        return 1;
      v6 = v5;
      v17 = (unsigned int)v4 >> 5;
      v18 = (void *)(a2 + 8);
      v19 = v4 & 0x1F;
      while ( 1 )
      {
        v16 = 0;
        if ( ioctl(v4, 0x541Bu, &v16) )
          break;
        v7 = v16;
        if ( !v16 )
        {
          v8 = (struct timeval *)v20;
          do
          {
            v8->tv_sec = 0;
            v8 = (struct timeval *)((char *)v8 + 4);
          }
          while ( (signed int *)v8 != &v21 );
          v22 = 0;
          v21 = 120;
          v20[v17] |= 1 << (v4 & 0x1F);
          if ( select(v4 + 1, (fd_set *)v20, 0, 0, v8) <= 0 )
            break;
          if ( !((v20[v17] >> v19) & 1) )
            break;
          v16 = 0;
          if ( ioctl(v4, 0x541Bu, &v16) )
            break;
          v7 = v16;
          if ( !v16 )
            break;
        }
        if ( v6 < v7 )
        {
          v16 = v6;
          v7 = v6;
        }
        v9 = recv(v4, v18, v7, 0);
        if ( v9 <= 0 )
          break;
        v6 -= v9;
        if ( (signed int)v6 <= 0 )
          return 1;
        v18 = (char *)v18 + v9;
      }
      return -1;
    }
  }
  return 0;
}

//----- (0804C580) --------------------------------------------------------
__sighandler_t __cdecl sigpipe_handler()
{
  __printf_chk(1, "\nCaught SIGPIPE, probably some socket fucked-up");
  return signal(13, (void (*)(int))sigpipe_handler);
}

//----- (0804C5B0) --------------------------------------------------------
__sighandler_t __cdecl sigint_handler()
{
  __printf_chk(1, "\nCaught SIGINT, exiting... Hit Ctrl-C once more to terminate immediately");
  finished = 1;
  return signal(2, 0);
}

//----- (0804C5F0) --------------------------------------------------------
__int16 __cdecl send_packet(int a1, int a2)
{
  int v2; // edi@1
  int v3; // esi@1
  __int16 result; // ax@2
  int v5; // ebx@2
  int v6; // ST00_4@4

  v3 = a1;
  v2 = a2;
  if ( !*(_BYTE *)(a1 + 828) )
    goto LABEL_8;
  v6 = rand();
  __asm
  {
    fild    [esp+2Ch+var_2C]
    fld     ds:dbl_807F350
    fxch    st(1)
    fucompp
    fnstsw  ax
    sahf
  }
  if ( _CF | _ZF )
  {
LABEL_8:
    v5 = *(_WORD *)(v2 + 6) + 8;
    result = send(*(_DWORD *)(v3 + 308), (const void *)v2, *(_WORD *)(v2 + 6) + 8, 0);
    *(_DWORD *)(v3 + 304) += v5;
  }
  return result;
}

//----- (0804C670) --------------------------------------------------------
#error "804C70E: invalid basic block (funcsize=40)"

//----- (0804C710) --------------------------------------------------------
#error "804C7F9: invalid basic block (funcsize=56)"

//----- (0804C800) --------------------------------------------------------
#error "804CB7D: invalid basic block (funcsize=227)"

//----- (0804CB80) --------------------------------------------------------
int __cdecl sub_804CB80(int a1, int a2)
{
  int v2; // edi@1
  int v3; // edx@2
  int v4; // ecx@2
  int v5; // ebx@2
  int v6; // eax@5
  int v7; // edx@5
  int v8; // ecx@5
  int v9; // ebx@5
  int result; // eax@10
  signed int v11; // esi@10
  int v12; // edx@12
  int v13; // ecx@12
  int v14; // eax@2
  int v15; // edx@5
  int v16; // eax@9
  int v17; // edx@9
  signed int v18; // eax@10
  int v19; // eax@12

  v2 = a1;
  while ( 1 )
  {
    v18 = *(_BYTE *)a2++;
    result = sub_804BE30(v18);
    v11 = result;
    if ( !result )
      break;
    if ( result > 127 )
    {
      v4 = *(_DWORD *)v2;
      v14 = *(_DWORD *)(*(_DWORD *)v2 - 12);
      v3 = *(_DWORD *)v2 - 12;
      v5 = v14 + 1;
      if ( (unsigned int)(v14 + 1) > *(_DWORD *)(v3 + 4) || *(_DWORD *)(v3 + 8) > 0 )
      {
        std__string__reserve(v2, v5);
        v4 = *(_DWORD *)v2;
      }
      *(_BYTE *)(v4 + *(_DWORD *)(v4 - 12)) = (unsigned __int8)(v11 >> 6) | 0xC0;
      v15 = *(_DWORD *)v2 - 12;
      *(_DWORD *)(*(_DWORD *)v2 - 12) = v5;
      *(_DWORD *)(v15 + 8) = 0;
      *(_BYTE *)(v15 + v5 + 12) = 0;
      v7 = *(_DWORD *)v2;
      v8 = *(_DWORD *)(*(_DWORD *)v2 - 12);
      v6 = *(_DWORD *)v2 - 12;
      v9 = v8 + 1;
      if ( (unsigned int)(v8 + 1) > *(_DWORD *)(v6 + 4) || *(_DWORD *)(v6 + 8) > 0 )
      {
        std__string__reserve(v2, v8 + 1);
        v7 = *(_DWORD *)v2;
        v8 = *(_DWORD *)(*(_DWORD *)v2 - 12);
      }
      *(_BYTE *)(v7 + v8) = v11 & 0x3F | 0x80;
    }
    else
    {
      v13 = *(_DWORD *)v2;
      v19 = *(_DWORD *)(*(_DWORD *)v2 - 12);
      v12 = *(_DWORD *)v2 - 12;
      v9 = v19 + 1;
      if ( (unsigned int)(v19 + 1) > *(_DWORD *)(v12 + 4) || *(_DWORD *)(v12 + 8) > 0 )
      {
        std__string__reserve(v2, v9);
        v13 = *(_DWORD *)v2;
      }
      *(_BYTE *)(v13 + *(_DWORD *)(v13 - 12)) = v11;
    }
    v16 = *(_DWORD *)v2;
    v17 = *(_DWORD *)v2 - 12;
    *(_DWORD *)(v17 + 8) = 0;
    *(_DWORD *)(v16 - 12) = v9;
    *(_BYTE *)(v17 + v9 + 12) = 0;
  }
  return result;
}

//----- (0804CC80) --------------------------------------------------------
signed int __cdecl main(char a1, int a2)
{
  signed int v1; // edi@1
  int v2; // esi@1
  int v3; // edx@3
  signed int v4; // ebx@5
  signed int result; // eax@8
  int v8; // edx@19
  int v9; // ecx@19
  int v10; // eax@20
  void *v11; // edi@20
  int v12; // ecx@41
  int v13; // ecx@45
  __int32 v14; // eax@2
  unsigned int v15; // eax@3
  int v16; // eax@11
  __int16 v17; // ax@12
  int v18; // eax@19
  unsigned __int16 v19; // bx@22
  char *v20; // eax@22
  int *v21; // eax@25
  size_t v22; // eax@27
  void *v23; // eax@27
  int *v24; // eax@32
  int *v25; // eax@33
  int *v26; // eax@34
  int *v27; // eax@35
  int  r; // [sp+B0h] [bp+0h]@1
  int v41; // [sp+ACh] [bp-4h]@1
  char *v42; // [sp+98h] [bp-18h]@1
  int v43; // [sp+94h] [bp-1Ch]@1
  signed int v45; // [sp+48h] [bp-68h]@1
  __int32 v46; // [sp+24h] [bp-8Ch]@2
  const char *v47; // [sp+44h] [bp-6Ch]@3
  const char *v48; // [sp+40h] [bp-70h]@3
  const char **v49; // [sp+14h] [bp-9Ch]@3
  char v50; // [sp+4Fh] [bp-61h]@3
  const char **v51; // [sp+18h] [bp-98h]@3
  int v52; // [sp+1Ch] [bp-94h]@11
  __int16 v53; // [sp+86h] [bp-2Ah]@12
  __int16 v54; // [sp+84h] [bp-2Ch]@12
  int v55; // [sp+88h] [bp-28h]@12
  signed int v56; // [sp+3Ch] [bp-74h]@12
  signed int v57; // [sp+38h] [bp-78h]@15
  int v58; // [sp+50h] [bp-60h]@18
  int v59; // [sp+74h] [bp-3Ch]@19
  int v60; // [sp+20h] [bp-90h]@19
  int v61; // [sp+34h] [bp-7Ch]@23
  __int16 v62; // [sp+4Eh] [bp-62h]@43
  _BYTE v63[3]; // [sp+4Dh] [bp-63h]@47

  v41 =  r;
  v42 = &a1;
  v1 = a1;
  v43 = *MK_FP(__GS__, 20);
  v2 = a2;
  v45 = 16;
  if ( a1 <= 1 )
    goto LABEL_39;
  v14 = strtol(*(const char **)(a2 + 4), 0, 10);
  v46 = v14;
  if ( (unsigned int)(v14 - 2) > 0xFFFD )
  {
    v4 = -1;
    __printf_chk(1, "\nIncorrect port number. Value must be in range 2-65535");
    goto LABEL_8;
  }
  __printf_chk(1, "IG11 NatICQ server (rev %s)\n", "3258M");
  __printf_chk(1, "\nLinux build");
  __printf_chk(1, "\nThread stack size: %u\n", 65536);
  v15 = time(0);
  srand(v15);
  v47 = std__string___Rep___S_empty_rep_storage + 12;
  v48 = std__string___Rep___S_empty_rep_storage + 12;
  
  sub_807E310();
  v49 = &v47;
  sub_807E820((int)&v50, (int *)&unk_80874B8, (int *)&v47);
  v51 = &v48;
  sub_807E820((int)&v50, (int *)&unk_80874BC, (int *)&v48);
  v3 = *((_DWORD *)v47 - 3);
  if ( v3 && *((_DWORD *)v48 - 3) )
  {
    dword_80874C0 = (int)malloc(v3 + 1);
    dword_80874C4 = (int)malloc(*((_DWORD *)v48 - 3) + 1);
    strcpy((char *)dword_80874C0, v47);
    strcpy((char *)dword_80874C4, v48);
    if ( v1 == 3 )
    {
      v22 = strlen(*(const char **)(v2 + 8));
      v23 = malloc(v22 + 1);
      path_to_stat = (int)v23;
      strcpy((char *)v23, *(const char **)(v2 + 8));
    }
    setvbuf((FILE *)stdout, 0, 2, 0);
    v16 = socket(2, 1, 0);
    v52 = v16;
    if ( v16 == -1 )
    {
      v26 = __errno_location();
      __printf_chk(1, "\nsocket() failed with error: %i", *v26);
    }
    else
    {
      v17 = __ROR__(v46, 8);
      v53 = v17;
      v54 = 2;
      v55 = 0;
      v56 = 1;
      if ( setsockopt(v52, 1, 2, &v56, 4u) == -1 )
      {
        v25 = __errno_location();
        __printf_chk(1, "\nsetsockopt(SO_REUSEADDR) failed with error: %i", *v25);
      }
      if ( bind(v52, (const struct sockaddr *)&v54, 0x10u) == -1 )
      {
        v24 = __errno_location();
        __printf_chk(1, "\nbind() failed with error: %i", *v24);
      }
      else
      {
        if ( listen(v52, 5) != -1 )
        {
          signal(2, (void (*)(int))sigint_handler);
          signal(13, (void (*)(int))sigpipe_handler);
          clientsNum = 0;
          pthread_mutex_init((pthread_mutex_t *)&client_mutex, 0);
          namelen = 16;
          if ( !finished )
          {
            while ( 1 )
            {
              v18 = accept(v52, (struct sockaddr *)&v59, (socklen_t *)&v45);
              v60 = v18;
              if ( v18 == -1 )
              {
                v27 = __errno_location();
                __printf_chk(1, "\nSocket error. Exit!!!, errno=%d", *v27);
                exit(1);
              }
              v10 = operator new(v9, v8);
              v11 = (void *)v10;
              if ( !v10 )
                break;
              *(_DWORD *)(v10 + 4) = 0;
              v2 = v10 + 8;
              if ( !getpeername(v60, (struct sockaddr *)(v10 + 8), (socklen_t *)&namelen) )
              {
                v19 = __ROR__(*(_WORD *)(v2 + 2), 8);
                v20 = inet_ntoa(*(struct in_addr *)(v2 + 4));
                __printf_chk(1, "\nConnect from %s:%i", v20, v19);
              }
              *(_DWORD *)v11 = v60;
              
              pthread_attr_init((pthread_attr_t *)&v58);
              pthread_attr_setstacksize((pthread_attr_t *)&v58, 0x10000u);
              pthread_attr_setdetachstate((pthread_attr_t *)&v58, 1);
              
              if ( pthread_create((pthread_t *)&v61, (const pthread_attr_t *)&v58, (void *(*)(void *))handle_connection, v11) )
              {
                __printf_chk(1, "\npthread_create() failed with error: %i", 1);
              }
              else
              {
                pthread_mutex_lock((pthread_mutex_t *)&client_mutex);
                ++clientsNum;
                status_update();
                pthread_mutex_unlock((pthread_mutex_t *)&client_mutex);
              }
              pthread_attr_destroy((pthread_attr_t *)&v58);
              if ( finished )
                goto LABEL_29;
            }
            __printf_chk(1, "\n memory allocation error!");
          }
LABEL_29:
          __printf_chk(1, "\nFinished serving. Closing sockets and cleaning up...");
          shutdown(v52, 2);
          pthread_mutex_destroy((pthread_mutex_t *)&client_mutex);
          if ( path_to_stat )
            free((void *)path_to_stat);
          v4 = 0;
          free((void *)dword_80874C0);
          free((void *)dword_80874C4);
          goto LABEL_6;
        }
        v21 = __errno_location();
        __printf_chk(1, "\nlisten() failed with error: %i", *v21);
      }
    }
    v4 = -1;
  }
  else
  {
    __printf_chk(1, "\nInternal conversion fuckup");
    v4 = 0;
  }
LABEL_6:
  _EDX = (int)(v48 - 12);
  if ( std__string___Rep___S_empty_rep_storage != v48 - 12 )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v12 = _EAX;
    }
    else
    {
      v12 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v12 - 1;
    }
    if ( v12 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v62);
  }
  _EDX = (int)(v47 - 12);
  if ( std__string___Rep___S_empty_rep_storage != v47 - 12 )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v13 = _EAX;
    }
    else
    {
      v13 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v13 - 1;
    }
    if ( v13 <= 0 )
      std__string___Rep___M_destroy(_EDX, v63);
  }
LABEL_8:
  while ( 1 )
  {
    result = v4;
    if ( !(*MK_FP(__GS__, 20) ^ v43) )
      break;
    __stack_chk_fail();
LABEL_39:
    v4 = -1;
    __printf_chk(1, "\nUsage: %s PORT [/path/to/statistic/output]", *(_DWORD *)v2);
  }
  return result;
}

//----- (0804D390) --------------------------------------------------------
__int16 __cdecl sub_804D390(int a1, int a2)
{
  signed int v3; // ebx@1
  unsigned int v4; // esi@1
  signed int v5; // eax@3
  __int16 result; // ax@8
  int v7; // eax@9
  signed int v8; // edx@9
  unsigned int v9; // edi@14
  int v10; // edx@18
  int v11; // ecx@18
  _UNKNOWN *v12; // eax@19
  int v13; // edx@22
  int v14; // eax@30
  int v15; // edx@33
  int v17; // ecx@40
  int v18; // edx@10
  int v19; // ecx@10
  int v20; // eax@13
  int v21; // ecx@15
  int v22; // eax@18
  int v23; // eax@35
  int v36; // [sp+4148h] [bp-10h]@1
  int v37; // [sp+18h] [bp-4140h]@1
  int v38; // [sp+14h] [bp-4144h]@1
  int v39; // [sp+138h] [bp-4020h]@1
  __int32 v40; // [sp+140h] [bp-4018h]@2
  int v41; // [sp+10h] [bp-4148h]@2
  char v42; // [sp+148h] [bp-4010h]@7
  __int16 v43; // [sp+146h] [bp-4012h]@7
  __int16 v44; // [sp+144h] [bp-4014h]@8
  unsigned int v45; // [sp+20h] [bp-4138h]@13
  int v46; // [sp+28h] [bp-4130h]@14
  signed int v47; // [sp+24h] [bp-4134h]@14
  int v48; // [sp+1Ch] [bp-413Ch]@15
  signed int v49; // [sp+34h] [bp-4124h]@33
  signed int v50; // [sp+38h] [bp-4120h]@33
  signed int v51; // [sp+3Ch] [bp-411Ch]@33
  signed int v52; // [sp+40h] [bp-4118h]@33
  signed int v53; // [sp+44h] [bp-4114h]@33
  signed int v54; // [sp+48h] [bp-4110h]@33
  signed int v55; // [sp+4Ch] [bp-410Ch]@33
  signed int v56; // [sp+50h] [bp-4108h]@33
  signed int v57; // [sp+54h] [bp-4104h]@33
  signed int v58; // [sp+58h] [bp-4100h]@33
  signed int v59; // [sp+5Ch] [bp-40FCh]@33
  signed int v60; // [sp+60h] [bp-40F8h]@33
  __int16 v61; // [sp+64h] [bp-40F4h]@33
  char v62; // [sp+66h] [bp-40F2h]@33
  char v63; // [sp+67h] [bp-40F1h]@33
  char v64; // [sp+68h] [bp-40F0h]@33
  char v65; // [sp+69h] [bp-40EFh]@33
  char v66; // [sp+6Ah] [bp-40EEh]@33
  __int16 v67; // [sp+6Ch] [bp-40ECh]@33
  char v68; // [sp+6Eh] [bp-40EAh]@33
  signed int v69; // [sp+70h] [bp-40E8h]@33
  __int16 v70; // [sp+74h] [bp-40E4h]@33
  char v71; // [sp+76h] [bp-40E2h]@33
  char v72; // [sp+77h] [bp-40E1h]@33
  char v73; // [sp+78h] [bp-40E0h]@33
  char v74; // [sp+79h] [bp-40DFh]@33
  char v75; // [sp+7Ah] [bp-40DEh]@33
  signed int v76; // [sp+7Ch] [bp-40DCh]@33
  signed int v77; // [sp+80h] [bp-40D8h]@33
  __int16 v78; // [sp+84h] [bp-40D4h]@33
  char v79; // [sp+86h] [bp-40D2h]@33
  char v80; // [sp+87h] [bp-40D1h]@33
  __int16 v81; // [sp+88h] [bp-40D0h]@33
  int v82; // [sp+8Ch] [bp-40CCh]@33
  int v83; // [sp+90h] [bp-40C8h]@33
  int v84; // [sp+94h] [bp-40C4h]@33
  char v85; // [sp+98h] [bp-40C0h]@33
  __int16 v86; // [sp+9Ah] [bp-40BEh]@33
  signed int v87; // [sp+9Ch] [bp-40BCh]@33
  signed int v88; // [sp+A0h] [bp-40B8h]@33
  signed int v89; // [sp+A4h] [bp-40B4h]@33
  signed int v90; // [sp+A8h] [bp-40B0h]@33
  signed int v91; // [sp+ACh] [bp-40ACh]@33
  signed int v92; // [sp+B0h] [bp-40A8h]@33
  signed int v93; // [sp+B4h] [bp-40A4h]@33
  __int16 v94; // [sp+B8h] [bp-40A0h]@33
  signed int v95; // [sp+BCh] [bp-409Ch]@33
  signed int v96; // [sp+C0h] [bp-4098h]@33
  signed int v97; // [sp+C4h] [bp-4094h]@33
  __int16 v98; // [sp+C8h] [bp-4090h]@33
  signed int v99; // [sp+CCh] [bp-408Ch]@33
  signed int v100; // [sp+D0h] [bp-4088h]@33
  __int16 v101; // [sp+D4h] [bp-4084h]@33
  signed int v102; // [sp+D8h] [bp-4080h]@33
  __int16 v103; // [sp+DCh] [bp-407Ch]@33
  signed int v104; // [sp+E0h] [bp-4078h]@33
  __int16 v105; // [sp+E4h] [bp-4074h]@33
  signed int v106; // [sp+E8h] [bp-4070h]@33
  __int16 v107; // [sp+ECh] [bp-406Ch]@33
  signed int v108; // [sp+F0h] [bp-4068h]@33
  __int16 v109; // [sp+F4h] [bp-4064h]@33
  signed int v110; // [sp+F8h] [bp-4060h]@33
  __int16 v111; // [sp+FCh] [bp-405Ch]@33
  signed int v112; // [sp+100h] [bp-4058h]@33
  __int16 v113; // [sp+104h] [bp-4054h]@33
  signed int v114; // [sp+108h] [bp-4050h]@33
  __int16 v115; // [sp+10Ch] [bp-404Ch]@33
  signed int v116; // [sp+110h] [bp-4048h]@33
  __int16 v117; // [sp+114h] [bp-4044h]@33
  signed int v118; // [sp+118h] [bp-4040h]@33
  __int16 v119; // [sp+11Ch] [bp-403Ch]@33
  signed int v120; // [sp+120h] [bp-4038h]@33
  __int16 v121; // [sp+124h] [bp-4034h]@33
  __int16 v122; // [sp+126h] [bp-4032h]@33
  signed int v123; // [sp+128h] [bp-4030h]@33
  char v124; // [sp+12Ch] [bp-402Ch]@33
  int v125; // [sp+134h] [bp-4024h]@33
  char v126; // [sp+130h] [bp-4028h]@35
  char v127; // [sp+13Fh] [bp-4019h]@42
  char v128; // [sp+13Eh] [bp-401Ah]@47

  v36 = *MK_FP(__GS__, 20);
  v4 = a2 + 12;
  v37 = a1;
  v38 = a2;
  std__string__string(&v39, a2 + 12);
  v3 = sub_805B8D0(v37, (int)&v39);
  _EDX = v39 - 12;
  if ( v39 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
    goto LABEL_39;
  while ( 1 )
  {
    v41 = (int)&v40;
    if ( v3 < 0 )
    {
      v49 = 134771820;
      v50 = 134771820;
      v51 = 134771820;
      v52 = 134771820;
      v53 = 134771820;
      v54 = 134771820;
      v55 = 134771820;
      v56 = 134771820;
      v57 = 134771820;
      v58 = 134771820;
      v59 = 134771820;
      v60 = 134771820;
      v61 = 0;
      v62 = 0;
      v63 = 0;
      v64 = 0;
      v65 = 0;
      v66 = 0;
      v67 = 0;
      v68 = 0;
      v69 = 134771820;
      v70 = 0;
      v71 = 0;
      v72 = 0;
      v73 = 0;
      v74 = 0;
      v75 = 0;
      v76 = 134771820;
      v77 = 134771820;
      v78 = 0;
      v79 = 0;
      v80 = 0;
      v81 = 0;
      v82 = 0;
      v83 = 0;
      v84 = 0;
      v85 = 0;
      v86 = 0;
      v87 = 134771820;
      v88 = 134771820;
      v89 = 134771820;
      v90 = 134771820;
      v91 = 134771820;
      v92 = 134771820;
      v93 = 134771820;
      v94 = 0;
      v95 = 134771820;
      v96 = 134771820;
      v97 = 134771820;
      v98 = 0;
      v99 = 134771820;
      v100 = 134771820;
      v101 = 0;
      v102 = 134771820;
      v103 = 0;
      v104 = 134771820;
      v105 = 0;
      v106 = 134771820;
      v107 = 0;
      v108 = 134771820;
      v109 = 0;
      v110 = 134771820;
      v111 = 0;
      v112 = 134771820;
      v113 = 0;
      v114 = 134771820;
      v115 = 0;
      v116 = 134771820;
      v117 = 0;
      v118 = 134771820;
      v119 = 0;
      v120 = 134771820;
      v121 = 0;
      v122 = 0;
      v123 = 134771820;
      v124 = 0;
      std__string__string(&v125, v4);
      v3 = sub_806F530(v37, (int)&v125, (int)&v49, 1);
      _ECX = v125 - 12;
      if ( std__string___Rep___S_empty_rep_storage != (char *)(v125 - 12) )
      {
        if ( pthread_cancel )
        {
          _EAX = -1;
          __asm { lock xadd [ecx+8], eax }
          v15 = _EAX;
        }
        else
        {
          v15 = *(_DWORD *)(_ECX + 8);
          *(_DWORD *)(_ECX + 8) = v15 - 1;
        }
        if ( v15 <= 0 )
          std__string___Rep___M_destroy(_ECX, &v128);
      }
      v41 = (int)&v40;
      if ( (_BYTE)v3 )
      {
        v3 = (signed int)&v126;
        std__string__string(&v126, v4);
        sub_8065430(v37, _ECX, (int)&v49, v4, v37, (int)&v126);
        std__string___string(&v126);
        v40 = strtol(*(const char **)(v38 + 12), 0, 10);
        v23 = *(_DWORD *)(v50 - 12);
        v43 = *(_DWORD *)(v50 - 12);
        v41 = (int)&v40;
        __memcpy_chk(&v42, v50, v23, 16384);
        v44 = 7;
        send_packet(v37, v41);
      }
      sub_8050180(_ECX, v15, (int)&v49);
    }
    v5 = *(_DWORD *)(v38 + 28);
    if ( v5 == 1 )
      goto LABEL_30;
    if ( v5 <= 1 )
    {
      if ( v5 )
        goto LABEL_8;
LABEL_30:
      v14 = *(_DWORD *)(v38 + 16);
      v4 = *(_DWORD *)(v14 - 4);
      v3 = *(_DWORD *)(v14 - 12);
      if ( (signed int)v4 >= 0 )
      {
        std__string___M_leak_hard(v38 + 16);
        v14 = *(_DWORD *)(v38 + 16);
      }
      __memcpy_chk(&v42, v14, v3, 16384);
      v43 = v3;
      goto LABEL_8;
    }
    if ( v5 == 2 )
    {
      v4 = *(_DWORD *)(v38 + 16);
      v20 = *(_DWORD *)(v4 - 12) >> 1;
      v45 = *(_DWORD *)(v4 - 12) >> 1;
      if ( v20 )
      {
        v9 = 0;
        v46 = v38 + 16;
        v47 = 1;
        do
        {
          v21 = *(_DWORD *)(v4 - 4);
          v48 = 2 * v9;
          if ( v21 < 0 )
          {
            v3 = *(_BYTE *)(v4 + v47);
          }
          else
          {
            std__string___M_leak_hard(v46);
            v4 = *(_DWORD *)(v38 + 16);
            v3 = *(_BYTE *)(v4 + v47);
            if ( *(_DWORD *)(v4 - 4) >= 0 )
            {
              std__string___M_leak_hard(v46);
              v4 = *(_DWORD *)(v38 + 16);
            }
          }
          v22 = *(_BYTE *)(v4 + v48) << 8;
          v11 = v22 + v3;
          v10 = v22 + v3;
          if ( (unsigned int)(v22 + v3) > 0x7F )
          {
            v12 = &unk_807EE20;
            if ( v11 == 1040 )
            {
LABEL_28:
              LOBYTE(v10) = *((_BYTE *)v12 + 3);
            }
            else
            {
              while ( 1 )
              {
                v12 = (char *)v12 + 6;
                v13 = *(_WORD *)v12;
                if ( !v13 )
                  break;
                if ( v11 == v13 )
                  goto LABEL_28;
              }
              LOBYTE(v10) = v11;
              if ( (unsigned __int8)v11 <= 0x1Fu )
                LOBYTE(v10) = 32;
            }
          }
          *(_BYTE *)(v41 + v9++ + 8) = v10;
          v47 += 2;
        }
        while ( v45 > v9 );
      }
      v43 = v45;
    }
    else
    {
      if ( v5 == 3 )
        v43 = sub_804BCE0((int)&v42, *(int **)(v38 + 16), 16383);
    }
LABEL_8:
    v44 = 3;
    v40 = strtol(*(const char **)(v38 + 12), 0, 10);
    result = send_packet(v37, v41);
    if ( *(_BYTE *)(v38 + 8) )
    {
      v7 = v37;
      v8 = *(_DWORD *)(v37 + 312);
      if ( v8 == 32 )
      {
        LOBYTE(v8) = 31;
        memcpy((void *)(v37 + 316), (const void *)(v37 + 332), 0x1F0u);
        v4 = v7 + 828;
        *(_DWORD *)(v37 + 312) = 31;
      }
      *(_DWORD *)(v37 + 16 * v8 + 316) = *(_DWORD *)(v37 + 304);
      *(_DWORD *)(v37 + 16 * *(_DWORD *)(v37 + 312) + 320) = v40;
      v18 = v37 + 16 * *(_DWORD *)(v37 + 312) + 304;
      v19 = v38;
      *(_DWORD *)(v37 + 16 * *(_DWORD *)(v37 + 312) + 324) = *(_DWORD *)v38;
      *(_DWORD *)(v18 + 24) = *(_DWORD *)(v19 + 4);
      result = v37;
      ++*(_DWORD *)(v37 + 312);
    }
    if ( !(*MK_FP(__GS__, 20) ^ v36) )
      return result;
    __stack_chk_fail();
LABEL_39:
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v17 = _EAX;
    }
    else
    {
      v17 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v17 - 1;
    }
    if ( v17 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v127);
  }
}

//----- (0804DBA0) --------------------------------------------------------
int __cdecl handle_connection(int *a1)
{
  char *v1; // ecx@5
  int v2; // edx@6
  signed int v5; // eax@14
  int v6; // edx@17
  int v7; // ebx@18
  int v8; // edx@20
  signed int v9; // eax@21
  int v10; // edi@21
  int v11; // ebx@23
  signed int v12; // esi@23
  int result; // eax@28
  char *v15; // ecx@30
  int v16; // edx@31
  signed int v17; // eax@36
  signed int v18; // eax@38
  char *v19; // ecx@54
  int v20; // edx@55
  signed int v21; // eax@62
  signed int v22; // esi@67
  char *v23; // ecx@70
  int v24; // edx@71
  char *v25; // ecx@76
  int v26; // edx@77
  char *v27; // edi@86
  signed int v28; // esi@88
  char *v29; // ecx@91
  int v30; // edx@92
  int v31; // esi@97
  char *v32; // edx@101
  int v33; // esi@104
  int v34; // edx@108
  __int16 v35; // cx@108
  signed int v36; // esi@108
  int v37; // eax@109
  int v38; // ecx@129
  int v39; // ecx@134
  int v40; // ecx@138
  int v41; // ecx@1
  int v42; // eax@6
  __int16 v43; // ax@19
  __int16 v44; // ax@25
  int v45; // edx@26
  unsigned __int16 v46; // bx@27
  char *v47; // eax@27
  pthread_t v48; // eax@27
  int v49; // edx@27
  int v50; // eax@31
  __int16 v51; // ax@45
  int v52; // ST00_4@47
  int v58; // eax@55
  signed int v59; // esi@64
  __int32 v60; // eax@68
  __int16 v61; // ax@69
  int v62; // eax@71
  int v63; // eax@77
  signed int v64; // esi@85
  __int32 v65; // eax@89
  __int16 v66; // ax@90
  int v67; // eax@92
  __int16 v68; // ax@102
  int v69; // ecx@102
  int v70; // edx@102
  __int16 v71; // si@112
  __int16 v72; // si@115
  __int16 v73; // ax@120
  __int16 v74; // si@122
  int v93; // [sp+460Ch] [bp-10h]@1
  unsigned __int16 v94; // [sp+530h] [bp-40ECh]@1
  int *v95; // [sp+44h] [bp-45D8h]@1
  int v96; // [sp+48h] [bp-45D4h]@1
  int (__cdecl **v97)(int); // [sp+50h] [bp-45CCh]@1
  signed int v98; // [sp+390h] [bp-428Ch]@1
  char v99; // [sp+38Ch] [bp-4290h]@1
  int v100; // [sp+184h] [bp-4498h]@1
  unsigned __int16 v101; // [sp+550h] [bp-40CCh]@2
  __int32 v102; // [sp+54Ch] [bp-40D0h]@3
  _BYTE v103[4]; // [sp+554h] [bp-40C8h]@5
  __int16 v104; // [sp+552h] [bp-40CAh]@5
  char v105; // [sp+55Ch] [bp-40C0h]@5
  char v106; // [sp+B0h] [bp-456Ch]@8
  __int16 *v107; // [sp+34h] [bp-45E8h]@11
  int v108; // [sp+528h] [bp-40F4h]@11
  char v109; // [sp+54Bh] [bp-40D1h]@11
  char v110; // [sp+E4h] [bp-4538h]@11
  int v111; // [sp+524h] [bp-40F8h]@12
  char v112; // [sp+54Ah] [bp-40D2h]@12
  char v113; // [sp+CCh] [bp-4550h]@12
  signed int v114; // [sp+168h] [bp-44B4h]@13
  int v115; // [sp+180h] [bp-449Ch]@13
  int v116; // [sp+17Ch] [bp-44A0h]@13
  int v117; // [sp+188h] [bp-4494h]@13
  unsigned __int8 v118; // [sp+178h] [bp-44A4h]@15
  int v119; // [sp+60h] [bp-45BCh]@17
  _DWORD v120[19]; // [sp+64h] [bp-45B8h]@17
  int v121; // [sp+54h] [bp-45C8h]@20
  int v122; // [sp+58h] [bp-45C4h]@20
  int v123; // [sp+C8h] [bp-4554h]@30
  time_t v124; // [sp+4Ch] [bp-45D0h]@35
  char v125; // [sp+558h] [bp-40C4h]@50
  char v126; // [sp+45ECh] [bp-30h]@52
  char v127; // [sp+490h] [bp-418Ch]@52
  char v128; // [sp+535h] [bp-40E7h]@52
  int *v129; // [sp+4BCh] [bp-4160h]@62
  int *v130; // [sp+4B8h] [bp-4164h]@62
  char v131; // [sp+45CCh] [bp-50h]@62
  const char *v132; // [sp+38h] [bp-45E4h]@62
  unsigned __int16 v133; // [sp+52Eh] [bp-40EEh]@62
  int **v134; // [sp+3Ch] [bp-45E0h]@62
  int **v135; // [sp+40h] [bp-45DCh]@62
  char v136; // [sp+4B4h] [bp-4168h]@64
  char v137; // [sp+539h] [bp-40E3h]@64
  char v138; // [sp+4A4h] [bp-4178h]@65
  char v139; // [sp+537h] [bp-40E5h]@65
  char v140; // [sp+498h] [bp-4184h]@65
  char v141; // [sp+49Ch] [bp-4180h]@65
  char v142; // [sp+4A0h] [bp-417Ch]@65
  char v143; // [sp+536h] [bp-40E6h]@65
  char v144; // [sp+494h] [bp-4188h]@67
  char v145; // [sp+4DCh] [bp-4140h]@80
  char v146; // [sp+4E0h] [bp-413Ch]@80
  int v147; // [sp+BCh] [bp-4560h]@80
  char v148; // [sp+4E4h] [bp-4138h]@82
  char v149; // [sp+53Dh] [bp-40DFh]@82
  char v150; // [sp+4E8h] [bp-4134h]@82
  char v151; // [sp+53Eh] [bp-40DEh]@82
  char v152; // [sp+4D8h] [bp-4144h]@85
  char v153; // [sp+53Ch] [bp-40E0h]@85
  char v154; // [sp+4C4h] [bp-4158h]@86
  char v155; // [sp+4C8h] [bp-4154h]@86
  char v156; // [sp+53Ah] [bp-40E2h]@86
  char v157; // [sp+4C0h] [bp-415Ch]@88
  _DWORD v158[128]; // [sp+18Ch] [bp-4490h]@97
  char v159; // [sp+504h] [bp-4118h]@100
  char v160; // [sp+543h] [bp-40D9h]@100
  char v161; // [sp+394h] [bp-4288h]@101
  char v162; // [sp+4F4h] [bp-4128h]@101
  char v163; // [sp+541h] [bp-40DBh]@101
  unsigned __int8 v164; // [sp+3CEh] [bp-424Eh]@101
  int v165; // [sp+398h] [bp-4284h]@102
  int v166; // [sp+39Ch] [bp-4280h]@102
  int v167; // [sp+3A0h] [bp-427Ch]@102
  unsigned __int16 v168; // [sp+3CCh] [bp-4250h]@102
  int v169; // [sp+3A8h] [bp-4274h]@102
  int v170; // [sp+430h] [bp-41ECh]@102
  char v171; // [sp+500h] [bp-411Ch]@103
  char v172; // [sp+542h] [bp-40DAh]@103
  char v173; // [sp+4F8h] [bp-4124h]@105
  char v174; // [sp+C4h] [bp-4558h]@105
  char v175; // [sp+4FCh] [bp-4120h]@105
  char v176; // [sp+C0h] [bp-455Ch]@105
  char v177; // [sp+520h] [bp-40FCh]@108
  char v178; // [sp+549h] [bp-40D3h]@108
  char v179; // [sp+518h] [bp-4104h]@112
  char v180; // [sp+51Ch] [bp-4100h]@112
  char v181; // [sp+548h] [bp-40D4h]@112
  char v182; // [sp+45A4h] [bp-78h]@112
  char v183; // [sp+508h] [bp-4114h]@115
  char v184; // [sp+544h] [bp-40D8h]@115
  char v185; // [sp+50Ch] [bp-4110h]@115
  char v186; // [sp+545h] [bp-40D7h]@115
  char v187; // [sp+4554h] [bp-C8h]@115
  char v188; // [sp+4ECh] [bp-4130h]@116
  char v189; // [sp+53Fh] [bp-40DDh]@116
  char v190; // [sp+4F0h] [bp-412Ch]@116
  char v191; // [sp+540h] [bp-40DCh]@116
  char v192; // [sp+510h] [bp-410Ch]@122
  char v193; // [sp+546h] [bp-40D6h]@122
  char v194; // [sp+514h] [bp-4108h]@122
  char v195; // [sp+547h] [bp-40D5h]@122
  char v196; // [sp+457Ch] [bp-A0h]@122
  char v197; // [sp+4CCh] [bp-4150h]@124
  char v198; // [sp+4D0h] [bp-414Ch]@124
  char v199; // [sp+4D4h] [bp-4148h]@124
  char v200; // [sp+53Bh] [bp-40E1h]@124
  char v201; // [sp+4A8h] [bp-4174h]@125
  char v202; // [sp+4ACh] [bp-4170h]@125
  char v203; // [sp+4B0h] [bp-416Ch]@125
  char v204; // [sp+538h] [bp-40E4h]@125
  char v205; // [sp+532h] [bp-40EAh]@131
  char v206; // [sp+533h] [bp-40E9h]@136
  char v207; // [sp+534h] [bp-40E8h]@140

  v93 = *MK_FP(__GS__, 20);
  v94 = 0;
  v41 = *a1;
  v95 = a1;
  v96 = v41;
  sub_8069070(v41, 0, (int)&v97);
  v97 = &off_807F2E8;
  v98 = 134771820;
  v99 = 0;
  v100 = v96;
  while ( recv_packet(v96, (int)&v102, 60) > 0 )
  {
    if ( v101 == 32 )
    {
      v1 = v103;
      v103[v104] = 0;
      v105 = 0;
      do
      {
        v42 = *(_DWORD *)v1;
        v1 += 4;
        v2 = ~v42 & (v42 - 16843009) & 0x80808080;
      }
      while ( !v2 );
      if ( !(v2 & 0x8080) )
      {
        v2 = (unsigned int)v2 >> 16;
        v1 += 2;
      }
      std__string__assign(&v106, v103, &v1[-__MKCADD__(v2, v2) - 3] - v103);
      if ( strstr(v103, (const char *)dword_80874C0) || !strcmp(&v125, (const char *)dword_80874C4) )
        v99 = 1;
      if ( v101 == 1 )
      {
LABEL_11:
        v103[v104] = 0;
        v107 = (__int16 *)v103;
        std__string__string(&v108, v103, &v109);
        std__string__assign(&v110, &v108);
        _EDX = v108 - 12;
        if ( std__string___Rep___S_empty_rep_storage != (char *)(v108 - 12) )
        {
          if ( pthread_cancel )
          {
            _EAX = -1;
            __asm { lock xadd [edx+8], eax }
            v40 = _EAX;
          }
          else
          {
            v40 = *(_DWORD *)(_EDX + 8);
            *(_DWORD *)(_EDX + 8) = v40 - 1;
          }
          if ( v40 <= 0 )
            std__string___Rep___M_destroy(_EDX, &v207);
        }
        __sprintf_chk(v103, 1, 16384, &aUnknownCodeU[13], v102);
        std__string__string(&v111, v103, &v112);
        std__string__assign(&v113, &v111);
        _EDX = v111 - 12;
        if ( std__string___Rep___S_empty_rep_storage != (char *)(v111 - 12) )
        {
          if ( pthread_cancel )
          {
            _EAX = -1;
            __asm { lock xadd [edx+8], eax }
            v39 = _EAX;
          }
          else
          {
            v39 = *(_DWORD *)(_EDX + 8);
            *(_DWORD *)(_EDX + 8) = v39 - 1;
          }
          if ( v39 <= 0 )
            std__string___Rep___M_destroy(_EDX, &v206);
        }
        *(v95 + 1) = v102;
        __printf_chk(1, "\nICQ UIN is %u");
        v114 = 400;
        v115 = 0;
        v116 = 0;
        v117 = 0;
        if ( (unsigned __int8)sub_80751D0((int)&v97, 0) )
        {
          v104 = 0;
          v101 = 4;
          send_packet((int)&v97, (int)&v102);
          v5 = 0;
          do
          {
            if ( byte_807EDC4[v5] == v118 )
              break;
            ++v5;
          }
          while ( v5 != 5 );
          v103[0] = v5;
          v104 = 1;
          v101 = 31;
          send_packet((int)&v97, (int)&v102);
          v6 = v119;
          if ( (_DWORD)v120 - v119 > 7 )
          {
            v7 = 0;
            do
            {
              v102 = *(_WORD *)(v6 + 8 * v7);
              v43 = sub_804BCE0((int)v103, *(int **)(v6 + 8 * v7 + 4), 16383);
              v101 = 20;
              v104 = v43;
              send_packet((int)&v97, (int)&v102);
              v6 = v119;
              ++v7;
            }
            while ( v7 < ((_DWORD)v120 - v119) >> 3 );
          }
          v8 = v121;
          if ( v122 - v121 > 127 )
          {
            v10 = 0;
            v9 = -1;
            while ( 1 )
            {
              v11 = v10 << 7;
              v12 = *(_WORD *)(v8 + (v10 << 7) + 8);
              if ( v12 != v9 )
              {
                v102 = *(_WORD *)(v8 + (v10 << 7) + 8);
                v104 = 0;
                v101 = 21;
                send_packet((int)&v97, (int)&v102);
                v8 = v121;
              }
              v102 = strtol(*(const char **)(v8 + v11), 0, 10);
              v44 = sub_804BCE0((int)v103, *(int **)(v121 + v11 + 4), 16383);
              v101 = 7;
              v104 = v44;
              send_packet((int)&v97, (int)&v102);
              v8 = v121;
              ++v10;
              if ( v10 >= (v122 - v121) >> 7 )
                break;
              v9 = v12;
            }
          }
          v102 = 0;
          v104 = 0;
          v101 = 7;
          send_packet((int)&v97, (int)&v102);
          if ( sub_805C910((int)&v97, v45, (int)&v97) )
          {
            v124 = time(0) + 300;
            goto LABEL_36;
          }
        }
        else
        {
          __sprintf_chk(v103, 1, 16384, "Connect failed at %d%%", v123);
          v15 = v103;
          do
          {
            v50 = *(_DWORD *)v15;
            v15 += 4;
            v16 = ~v50 & (v50 - 16843009) & 0x80808080;
          }
          while ( !v16 );
          if ( !(v16 & 0x8080) )
          {
            v16 = (unsigned int)v16 >> 16;
            v15 += 2;
          }
          v102 = 0;
          v104 = &v15[-__MKCADD__(v16, v16) - 3] - (char *)v107;
          v101 = 6;
          send_packet((int)&v97, (int)&v102);
          sleep(1u);
        }
        goto LABEL_27;
      }
    }
    else
    {
      if ( v101 == 1 )
        goto LABEL_11;
    }
  }
  
  while ( 1 )
  {
LABEL_27:
    v46 = __ROR__(*((_WORD *)v95 + 5), 8);
    v47 = inet_ntoa((struct in_addr)*(v95 + 3));
    __printf_chk(1, "\nDisconnect from %s:%i", v47, v46);
    v48 = pthread_self();
    __printf_chk(1, "\nThread %X (uin %u) received disconnect!", v48, *(v95 + 1));
    shutdown(v96, 2);
    close(v96);
    operator delete(v95, v49);
    pthread_mutex_lock((pthread_mutex_t *)&client_mutex);
    --clientsNum;
    status_update();
    pthread_mutex_unlock((pthread_mutex_t *)&client_mutex);
    v97 = &off_807F2E8;
    _EDX = v98 - 12;
    if ( std__string___Rep___S_empty_rep_storage != (char *)(v98 - 12) )
    {
      if ( pthread_cancel )
      {
        _EAX = -1;
        __asm { lock xadd [edx+8], eax }
        v38 = _EAX;
      }
      else
      {
        v38 = *(_DWORD *)(_EDX + 8);
        *(_DWORD *)(_EDX + 8) = v38 - 1;
      }
      if ( v38 <= 0 )
        std__string___Rep___M_destroy(_EDX, &v205);
    }
    sub_8069710((int)&v97);
    result = 0;
    if ( !(*MK_FP(__GS__, 20) ^ v93) )
      return result;
    __stack_chk_fail();
LABEL_122:
    v74 = v34;
    std__string__string(&v192, v103, &v193);
    std__string__string(&v194, v132, &v195);
    sub_804FEB0((int)&v196, (int)&v194, (int)&v192, 3, 0, 0, 0, 0);
    LOBYTE(v74) = sub_8063EF0((int)&v97, (int *)&v196, v74);
    sub_80500E0((int)&v196);
    std__string___string(&v194);
    std__string___string(&v192);
    if ( !(_BYTE)v74 )
    {
LABEL_114:
      v35 = v116;
LABEL_115:
      v72 = v35;
      std__string__string(&v183, v103, &v184);
      std__string__string(&v185, v132, &v186);
      sub_804FEB0((int)&v187, (int)&v185, (int)&v183, 1, 0, 0, 0, 0);
      sub_8063EF0((int)&v97, (int *)&v187, v72);
      sub_80500E0((int)&v187);
      std__string___string(&v185);
      std__string___string(&v183);
    }
LABEL_36:
    while ( 1 )
    {
      v17 = sub_80767E0((int)&v97, 1);
      if ( v17 != -2 )
      {
        if ( v17 != 1 )
          break;
      }
      v18 = recv_packet(v96, (int)&v102, 0);
      if ( v18 < 0 )
        goto LABEL_41;
      if ( v18 )
      {
        v124 = time(0) + 300;
        if ( !v99 )
          goto LABEL_146;
        v52 = rand();
        __asm
        {
          fild    [esp+461Ch+var_461C]
          fld     ds:dbl_807F350
          fxch    st(1)
          fucompp
          fnstsw  ax
          sahf
        }
        if ( _CF | _ZF )
        {
LABEL_146:
          if ( v101 <= 0x21u )
          {
            switch ( v101 )
            {
              case 0u:
                continue;
              case 1u:
              case 3u:
              case 4u:
              case 5u:
              case 6u:
              case 7u:
              case 8u:
              case 9u:
              case 0xDu:
              case 0x10u:
              case 0x11u:
              case 0x13u:
              case 0x14u:
              case 0x15u:
              case 0x19u:
              case 0x1Cu:
              case 0x1Du:
              case 0x1Fu:
              case 0x20u:
                goto LABEL_45;
              case 2u:
                v132 = &v131;
                __sprintf_chk(&v131, 1, 32, &aUnknownCodeU[13], v102);
                std__string__string(&v177, v132, &v178);
                v36 = sub_805B8D0((int)&v97, (int)&v177);
                std__string___string(&v177);
                v34 = ((_WORD)v116 + 1) & 0x7FFF;
                v103[v104] = 0;
                v35 = v34;
                v116 = v34;
                if ( v36 < 0 || (v37 = v121 + (v36 << 7), !*(_BYTE *)(v37 + 93)) || *(_DWORD *)(v37 + 68) == -1 )
                  goto LABEL_115;
                if ( !*(_BYTE *)(v37 + 94) )
                  goto LABEL_122;
                v129 = (int *)(std__string___Rep___S_empty_rep_storage + 12);
                v134 = &v129;
                sub_804CB80((int)&v129, (int)v103);
                v71 = v116;
                std__string__string(&v179, v134);
                std__string__string(&v180, v132, &v181);
                sub_804FEB0((int)&v182, (int)&v180, (int)&v179, 3, 0, 0, 0, 0);
                LOBYTE(v71) = sub_8063EF0((int)&v97, (int *)&v182, v71);
                sub_80500E0((int)&v182);
                std__string___string(&v180);
                std__string___string(&v179);
                if ( (_BYTE)v71 )
                  goto LABEL_75;
                std__string___string(v134);
                goto LABEL_114;
              case 0xAu:
                v103[v104] = 0;
                v132 = &v131;
                __sprintf_chk(&v131, 1, 32, &aUnknownCodeU[13], v102);
                std__string__string(&v188, &aResNr[13], &v189);
                std__string__string(&v190, v132, &v191);
                sub_80683D0((int)&v97, (int)&v190, (int)&v188);
                std__string___string(&v190);
                std__string___string(&v188);
                continue;
              case 0xBu:
                sub_804FC00((int)&v161);
                __sprintf_chk(v103, 1, 16384, &aUnknownCodeU[13], v102);
                std__string__string(&v162, v103, &v163);
                sub_806F530((int)&v97, (int)&v162, (int)&v161, 1);
                std__string___string(&v162);
                v32 = "Unknown";
                if ( (unsigned __int8)(v164 - 1) <= 1u )
                {
                  v32 = "Male";
                  if ( v164 != 2 )
                    v32 = "Female";
                }
                v68 = __snprintf_chk(
                        v103,
                        16383,
                        1,
                        16384,
                        "Nick: %s\r\nFirstname: %s\r\nLastname: %s\r\nAge: %d\r\nGender: %s\r\nHomecity: %s\r\nNotes: %s\r\n",
                        v165,
                        v166,
                        v167,
                        v168,
                        v32,
                        v169,
                        v170);
                v101 = 3;
                v104 = v68;
                send_packet((int)&v97, (int)&v102);
                sub_8050180(v69, v70, (int)&v161);
                continue;
              case 0xCu:
                v130 = (int *)(std__string___Rep___S_empty_rep_storage + 12);
                v129 = (int *)(std__string___Rep___S_empty_rep_storage + 12);
                v103[v104] = 0;
                v132 = &v131;
                v133 = 0;
                __sprintf_chk(&v131, 1, 32, &aUnknownCodeU[13], v102);
                if ( ((_DWORD)v120 - v119) >> 3 )
                {
                  v135 = &v130;
                  v134 = &v129;
                  std__string__assign(&v130, v119 + 4);
                }
                else
                {
                  v135 = &v130;
                  v134 = &v129;
                  std__string__assign(&v130, &aResNr[13]);
                }
                v134 = &v129;
                sub_804CB80((int)&v129, (int)v103);
                std__string__string(&v152, v132, &v153);
                v64 = sub_805B8D0((int)&v97, (int)&v152);
                std__string___string(&v152);
                if ( v64 < 0 )
                {
                  v27 = &v197;
                  std__string__string(&v197, v135);
                  std__string__string(&v198, v134);
                  std__string__string(&v199, v132, &v200);
                  sub_8073610((int)&v97, (int)&v199, (int)&v198, (int)&v197, (int)&v133);
                  std__string___string(&v199);
                  std__string___string(&v198);
                }
                else
                {
                  v27 = &v154;
                  std__string__string(&v154, v134);
                  std__string__string(&v155, v132, &v156);
                  sub_8072E40((int)&v97, (int)&v155, (int)&v154, (int)&v133);
                  std__string___string(&v155);
                }
                std__string___string(v27);
                if ( !v133 )
                {
                  std__string__string(&v157, v135);
                  v28 = sub_805B850((int)&v97, (int)&v157);
                  std__string___string(&v157);
                  if ( v28 >= 0 )
                  {
                    v65 = *(_WORD *)(v119 + 8 * v28);
                    v104 = 0;
                    v101 = 21;
                    v102 = v65;
                    send_packet((int)&v97, (int)&v102);
                  }
                  v102 = strtol(v132, 0, 10);
                  v66 = sub_804BCE0((int)v103, v129, 16383);
                  v101 = 7;
                  v104 = v66;
                  send_packet((int)&v97, (int)&v102);
                  v102 = 0;
                  v104 = 0;
                  v101 = 7;
                  send_packet((int)&v97, (int)&v102);
                }
                sub_804C150((int)v103, v133);
                v29 = v103;
                v102 = 0;
                v101 = 13;
                do
                {
                  v67 = *(_DWORD *)v29;
                  v29 += 4;
                  v30 = ~v67 & (v67 - 16843009) & 0x80808080;
                }
                while ( !v30 );
                if ( !(v30 & 0x8080) )
                {
                  v30 = (unsigned int)v30 >> 16;
                  v29 += 2;
                }
                v104 = &v29[-__MKCADD__(v30, v30) - 3] - (char *)v107;
                send_packet((int)&v97, (int)&v102);
                std__string___string(v134);
                std__string___string(v135);
                continue;
              case 0xEu:
                v103[v104] = 0;
                v132 = &v131;
                __sprintf_chk(&v131, 1, 32, &aUnknownCodeU[13], v102);
                std__string__string(&v148, &aResNr[13], &v149);
                std__string__string(&v150, v132, &v151);
                sub_8065530((int)&v97, (int)&v150, (int)&v148, 1);
                std__string___string(&v150);
                std__string___string(&v148);
                continue;
              case 0xFu:
                if ( (char)v103 <= 12 )
                  sub_805FB00((int)&v97, dword_807EDE0[(char)v103]);
                continue;
              case 0x12u:
                v101 = 19;
                goto LABEL_59;
              case 0x16u:
                v33 = (char)v103;
                if ( (unsigned int)(char)v103 <= 0x22 )
                {
                  std__string__string(&v173, &v174);
                  std__string__string(&v175, &v176);
                  sub_805C700((int)&v97, v33, (int)&v175, (int)&v173);
                  std__string___string(&v175);
                  std__string___string(&v173);
                }
                continue;
              case 0x17u:
                if ( v117 <= 0 )
                  continue;
                v31 = 0;
                if ( (_DWORD)v158 == v102 )
                  goto LABEL_100;
                break;
              case 0x18u:
                __sprintf_chk(v103, 1, 16384, &aUnknownCodeU[13], v102);
                std__string__string(&v171, v103, &v172);
                sub_80684D0((int)&v97, (int)&v171);
                std__string___string(&v171);
                continue;
              case 0x1Au:
                v129 = (int *)(std__string___Rep___S_empty_rep_storage + 12);
                v130 = (int *)(std__string___Rep___S_empty_rep_storage + 12);
                v103[v104] = 0;
                v134 = &v129;
                v135 = &v130;
                sub_804CB80((int)&v129, (int)v103);
                v25 = v103;
                do
                {
                  v63 = *(_DWORD *)v25;
                  v25 += 4;
                  v26 = ~v63 & (v63 - 16843009) & 0x80808080;
                }
                while ( !v26 );
                if ( !(v26 & 0x8080) )
                {
                  v26 = (unsigned int)v26 >> 16;
                  v25 += 2;
                }
                v135 = &v130;
                sub_804CB80((int)&v130, (int)&v25[-__MKCADD__(v26, v26) - 2]);
                std__string__string(&v145, v135);
                std__string__string(&v146, v134);
                sub_805C700((int)&v97, v147, (int)&v146, (int)&v145);
                std__string___string(&v146);
                std__string___string(&v145);
                std__string___string(v135);
                std__string___string(v134);
                continue;
              case 0x1Bu:
                v129 = (int *)(std__string___Rep___S_empty_rep_storage + 12);
                v130 = (int *)(std__string___Rep___S_empty_rep_storage + 12);
                v103[v104] = 0;
                v132 = &v131;
                v133 = 0;
                __sprintf_chk(&v131, 1, 32, &aUnknownCodeU[13], v102);
                v134 = &v129;
                v135 = &v130;
                v21 = sub_8058090((int)&v97, (__int16)v103);
                if ( v21 < 0 )
                {
                  if ( ((_DWORD)v120 - v119) >> 3 )
                  {
                    v134 = &v129;
                    v135 = &v130;
                    std__string__assign(&v129, v119 + 4);
                  }
                  else
                  {
                    v134 = &v129;
                    v135 = &v130;
                    std__string__assign(&v129, &aResNr[13]);
                  }
                }
                else
                {
                  v135 = &v130;
                  v134 = &v129;
                  std__string__assign(&v129, v119 + 8 * v21 + 4);
                }
                v135 = &v130;
                sub_804CB80((int)&v130, (int)&v125);
                std__string__string(&v136, v132, &v137);
                v59 = sub_805B8D0((int)&v97, (int)&v136);
                std__string___string(&v136);
                if ( v59 < 0 )
                {
                  std__string__string(&v201, v134);
                  std__string__string(&v202, v135);
                  std__string__string(&v203, v132, &v204);
                  sub_8073610((int)&v97, (int)&v203, (int)&v202, (int)&v201, (int)&v133);
                  std__string___string(&v203);
                  std__string___string(&v202);
                  std__string___string(&v201);
                }
                else
                {
                  std__string__string(&v138, v132, &v139);
                  sub_8071620((int)&v97, (int)&v138, (int)&v133);
                  std__string___string(&v138);
                  std__string__string(&v140, v134);
                  std__string__string(&v141, v135);
                  std__string__string(&v142, v132, &v143);
                  sub_8073610((int)&v97, (int)&v142, (int)&v141, (int)&v140, (int)&v133);
                  std__string___string(&v142);
                  std__string___string(&v141);
                  std__string___string(&v140);
                }
                if ( !v133 )
                {
                  std__string__string(&v144, v134);
                  v22 = sub_805B850((int)&v97, (int)&v144);
                  std__string___string(&v144);
                  if ( v22 >= 0 )
                  {
                    v60 = *(_WORD *)(v119 + 8 * v22);
                    v104 = 0;
                    v101 = 21;
                    v102 = v60;
                    send_packet((int)&v97, (int)&v102);
                  }
                  v102 = strtol(v132, 0, 10);
                  v61 = sub_804BCE0((int)v103, v130, 16383);
                  v101 = 7;
                  v104 = v61;
                  send_packet((int)&v97, (int)&v102);
                  v102 = 0;
                  v104 = 0;
                  v101 = 7;
                  send_packet((int)&v97, (int)&v102);
                }
                sub_804C150((int)v103, v133);
                v23 = v103;
                v102 = 0;
                v101 = 13;
                do
                {
                  v62 = *(_DWORD *)v23;
                  v23 += 4;
                  v24 = ~v62 & (v62 - 16843009) & 0x80808080;
                }
                while ( !v24 );
                if ( !(v24 & 0x8080) )
                {
                  v24 = (unsigned int)v24 >> 16;
                  v23 += 2;
                }
                v104 = &v23[-__MKCADD__(v24, v24) - 3] - (char *)v107;
                send_packet((int)&v97, (int)&v102);
                std__string___string(v135);
LABEL_75:
                std__string___string(v134);
                continue;
              case 0x1Eu:
                if ( (char)v103 <= 4 )
                  sub_8060160((int)&v97, LOBYTE(byte_807EDC4[(char)v103]));
                continue;
              case 0x21u:
                v103[v104] = 0;
                __sprintf_chk(&v126, 1, 32, &aUnknownCodeU[13], v102);
                std__string__string(&v127, &v126, &v128);
                sub_8071620((int)&v97, (int)&v127, (int)&v94);
                std__string___string(&v127);
                if ( v94 )
                {
                  v73 = __sprintf_chk(v103, 1, 16384, "Error! Expected %d, got %d", 0, v94);
                  v101 = 6;
                  v104 = v73;
                }
                else
                {
                  v101 = 34;
                  v104 = 0;
                }
                send_packet((int)&v97, (int)&v102);
                sub_804C150((int)v103, v94);
                v19 = v103;
                v102 = 0;
                v101 = 13;
                do
                {
                  v58 = *(_DWORD *)v19;
                  v19 += 4;
                  v20 = ~v58 & (v58 - 16843009) & 0x80808080;
                }
                while ( !v20 );
                if ( !(v20 & 0x8080) )
                {
                  v20 = (unsigned int)v20 >> 16;
                  v19 += 2;
                }
                v104 = &v19[-__MKCADD__(v20, v20) - 3] - (char *)v107;
LABEL_59:
                send_packet((int)&v97, (int)&v102);
                continue;
            }
            while ( 1 )
            {
              ++v31;
              if ( v31 >= v117 )
                break;
              if ( v158[4 * v31] == v102 )
              {
LABEL_100:
                __sprintf_chk(v103, 1, 16384, &aUnknownCodeU[13], *(&v119 + 4 * (v31 + 19)));
                std__string__string(&v159, v103, &v160);
                sub_805FB70((int)&v97, (const void **)&v159, (int)&v120[4 * (v31 + 19)], 1);
                std__string___string(&v159);
                memmove(&v158[4 * v31], &v158[4 * v31 + 4], 16 * (31 - v31));
                --v117;
                goto LABEL_36;
              }
            }
          }
          else
          {
LABEL_45:
            v51 = __sprintf_chk(v103, 1, 16384, "Unknown opcode %u", v101);
            v101 = 6;
            v104 = v51;
            send_packet((int)&v97, (int)&v102);
          }
        }
        else
        {
          if ( v101 == 2 )
            v116 = ((_WORD)v116 + 1) & 0x7FFF;
        }
      }
      else
      {
        if ( v124 <= time(0) )
        {
LABEL_41:
          sub_805B650((int)&v97);
          goto LABEL_27;
        }
      }
    }
  }
}

//----- (0804FC00) --------------------------------------------------------
int __cdecl sub_804FC00(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)a1 = 134771820;
  *(_DWORD *)(a1 + 4) = 134771820;
  *(_DWORD *)(a1 + 8) = 134771820;
  *(_DWORD *)(a1 + 12) = 134771820;
  *(_DWORD *)(a1 + 16) = 134771820;
  *(_DWORD *)(a1 + 20) = 134771820;
  *(_DWORD *)(a1 + 24) = 134771820;
  *(_DWORD *)(a1 + 28) = 134771820;
  *(_DWORD *)(a1 + 32) = 134771820;
  *(_DWORD *)(a1 + 36) = 134771820;
  *(_DWORD *)(a1 + 40) = 134771820;
  *(_DWORD *)(a1 + 44) = 134771820;
  *(_WORD *)(a1 + 48) = 0;
  *(_BYTE *)(a1 + 50) = 0;
  *(_BYTE *)(a1 + 51) = 0;
  *(_BYTE *)(a1 + 52) = 0;
  *(_BYTE *)(a1 + 53) = 0;
  *(_BYTE *)(a1 + 54) = 0;
  *(_WORD *)(a1 + 56) = 0;
  *(_BYTE *)(a1 + 58) = 0;
  *(_DWORD *)(a1 + 60) = 134771820;
  *(_WORD *)(a1 + 64) = 0;
  *(_BYTE *)(a1 + 66) = 0;
  *(_BYTE *)(a1 + 67) = 0;
  *(_BYTE *)(a1 + 68) = 0;
  *(_BYTE *)(a1 + 69) = 0;
  *(_BYTE *)(a1 + 70) = 0;
  *(_DWORD *)(a1 + 72) = 134771820;
  *(_DWORD *)(a1 + 76) = 134771820;
  *(_WORD *)(a1 + 80) = 0;
  *(_BYTE *)(a1 + 82) = 0;
  *(_BYTE *)(a1 + 83) = 0;
  *(_WORD *)(a1 + 84) = 0;
  *(_DWORD *)(a1 + 88) = 0;
  *(_DWORD *)(a1 + 92) = 0;
  *(_DWORD *)(a1 + 96) = 0;
  *(_BYTE *)(a1 + 100) = 0;
  *(_WORD *)(a1 + 102) = 0;
  *(_DWORD *)(a1 + 104) = 134771820;
  *(_DWORD *)(a1 + 108) = 134771820;
  *(_DWORD *)(a1 + 112) = 134771820;
  *(_DWORD *)(a1 + 116) = 134771820;
  *(_DWORD *)(a1 + 120) = 134771820;
  *(_DWORD *)(a1 + 124) = 134771820;
  *(_DWORD *)(a1 + 128) = 134771820;
  *(_WORD *)(a1 + 132) = 0;
  *(_DWORD *)(a1 + 136) = 134771820;
  *(_DWORD *)(a1 + 140) = 134771820;
  *(_DWORD *)(a1 + 144) = 134771820;
  *(_WORD *)(a1 + 148) = 0;
  *(_DWORD *)(a1 + 152) = 134771820;
  *(_DWORD *)(a1 + 156) = 134771820;
  *(_WORD *)(a1 + 160) = 0;
  *(_DWORD *)(a1 + 164) = 134771820;
  *(_WORD *)(a1 + 168) = 0;
  *(_DWORD *)(a1 + 172) = 134771820;
  *(_WORD *)(a1 + 176) = 0;
  *(_DWORD *)(a1 + 180) = 134771820;
  *(_WORD *)(a1 + 184) = 0;
  *(_DWORD *)(a1 + 188) = 134771820;
  *(_WORD *)(a1 + 192) = 0;
  *(_DWORD *)(a1 + 196) = 134771820;
  *(_WORD *)(a1 + 200) = 0;
  *(_DWORD *)(a1 + 204) = 134771820;
  *(_WORD *)(a1 + 208) = 0;
  *(_DWORD *)(a1 + 212) = 134771820;
  *(_WORD *)(a1 + 216) = 0;
  *(_DWORD *)(a1 + 220) = 134771820;
  *(_WORD *)(a1 + 224) = 0;
  *(_DWORD *)(a1 + 228) = 134771820;
  *(_WORD *)(a1 + 232) = 0;
  *(_DWORD *)(a1 + 236) = 134771820;
  *(_WORD *)(a1 + 240) = 0;
  *(_WORD *)(a1 + 242) = 0;
  *(_DWORD *)(a1 + 244) = 134771820;
  *(_BYTE *)(a1 + 248) = 0;
  return result;
}

//----- (0804FE40) --------------------------------------------------------
void __cdecl sub_804FE40()
{
  ;
}

//----- (0804FE50) --------------------------------------------------------
void __cdecl sub_804FE50()
{
  ;
}

//----- (0804FE60) --------------------------------------------------------
void __cdecl sub_804FE60()
{
  ;
}

//----- (0804FE70) --------------------------------------------------------
void __cdecl sub_804FE70()
{
  ;
}

//----- (0804FE80) --------------------------------------------------------
void __cdecl sub_804FE80()
{
  ;
}

//----- (0804FE90) --------------------------------------------------------
void __cdecl sub_804FE90()
{
  ;
}

//----- (0804FEA0) --------------------------------------------------------
void __cdecl sub_804FEA0()
{
  ;
}

//----- (0804FEB0) --------------------------------------------------------
int __cdecl sub_804FEB0(int a1, int a2, int a3, int a4, __int16 a5, char a6, int a7, int a8)
{
  int v8; // ebx@1
  int result; // eax@5
  char v10; // dl@1
  int v11; // eax@1
  int v12; // esi@1
  int v13; // edx@1
  __int16 v14; // [sp+1Ah] [bp-Eh]@1
  char v15; // [sp+19h] [bp-Fh]@1

  v8 = a1;
  v10 = a6;
  v14 = a5;
  v11 = a2;
  *(_DWORD *)(a1 + 12) = 134771820;
  v12 = a1 + 16;
  *(_DWORD *)(a1 + 16) = 134771820;
  v15 = v10;
  std__string__assign(a1 + 12, v11);
  std__string__assign(v12, a3);
  v13 = a7;
  *(_DWORD *)(v8 + 28) = a4;
  *(_WORD *)(v8 + 32) = v14;
  if ( v13 )
    *(_DWORD *)(v8 + 20) = *(_DWORD *)a7;
  else
    *(_DWORD *)(v8 + 20) = 0;
  if ( a8 )
  {
    *(_DWORD *)(v8 + 24) = *(_DWORD *)a8;
  }
  else
  {
    *(_DWORD *)(v8 + 24) = -1;
    *(_BYTE *)(v8 + 27) = 0;
  }
  result = (unsigned __int8)v15;
  *(_BYTE *)(v8 + 34) = v15;
  return result;
}

//----- (0804FF80) --------------------------------------------------------
int __fastcall sub_804FF80(int a1, int _EDX, int a3)
{
  int *v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  int result; // eax@2
  char v12; // [sp+1Bh] [bp-Dh]@11

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 4);
  v3 = *(int **)a3;
  if ( v5 != *(_DWORD *)a3 )
  {
    do
    {
      result = *v3;
      _EDX = *v3 - 12;
      if ( _EDX != (_DWORD)std__string___Rep___S_empty_rep_storage )
      {
        if ( pthread_cancel )
        {
          _EAX = -1;
          __asm { lock xadd [edx+8], eax }
          a1 = result;
        }
        else
        {
          a1 = *(_DWORD *)(_EDX + 8);
          result = a1 - 1;
          *(_DWORD *)(_EDX + 8) = a1 - 1;
        }
        if ( a1 <= 0 )
          result = std__string___Rep___M_destroy(_EDX, &v12);
      }
      v3 += 2;
    }
    while ( v5 != (_DWORD)v3 );
    v5 = *(_DWORD *)v4;
  }
  if ( v5 )
    result = operator delete(a1, _EDX);
  return result;
}

//----- (08050000) --------------------------------------------------------
int __cdecl sub_8050000(int a1)
{
  int v2; // ebx@1
  int v4; // ecx@4
  int v5; // eax@1
  int v6; // ecx@2
  int v7; // edx@2
  char v14; // [sp+23h] [bp-5h]@6

  v2 = a1;
  v5 = *(_DWORD *)(a1 + 832);
  *(_DWORD *)a1 = &off_807F2E8;
  _EDX = v5 - 12;
  if ( v5 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v4 = _EAX;
    }
    else
    {
      v4 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v4 - 1;
    }
    if ( v4 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v14);
  }
  sub_8069710(v2);
  return operator delete(v6, v7);
}

//----- (08050070) --------------------------------------------------------
int __cdecl sub_8050070(int a1)
{
  int v2; // ebx@1
  int v4; // ecx@4
  int v5; // eax@1
  char v12; // [sp+23h] [bp-5h]@6

  v2 = a1;
  v5 = *(_DWORD *)(a1 + 832);
  *(_DWORD *)a1 = &off_807F2E8;
  _EDX = v5 - 12;
  if ( v5 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v4 = _EAX;
    }
    else
    {
      v4 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v4 - 1;
    }
    if ( v4 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v12);
  }
  return sub_8069710(v2);
}

//----- (080500E0) --------------------------------------------------------
char *__cdecl sub_80500E0(int a1)
{
  int v2; // ebx@1
  char *result; // eax@2
  int v5; // ecx@5
  char *v6; // ecx@9
  int v7; // eax@1
  char v19; // [sp+23h] [bp-5h]@7
  char v20; // [sp+22h] [bp-6h]@11

  v2 = a1;
  v7 = *(_DWORD *)(a1 + 16);
  _EDX = v7 - 12;
  if ( v7 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v5 = _EAX;
    }
    else
    {
      v5 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v5 - 1;
    }
    if ( v5 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v19);
  }
  _EDX = *(_DWORD *)(v2 + 12) - 12;
  result = std__string___Rep___S_empty_rep_storage;
  if ( std__string___Rep___S_empty_rep_storage != (char *)_EDX )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v6 = result;
    }
    else
    {
      v6 = *(char **)(_EDX + 8);
      result = v6 - 1;
      *(_DWORD *)(_EDX + 8) = v6 - 1;
    }
    if ( (signed int)v6 <= 0 )
      result = (char *)std__string___Rep___M_destroy(_EDX, &v20);
  }
  return result;
}

//----- (08050180) --------------------------------------------------------
int __fastcall sub_8050180(int a1, int a2, int a3)
{
  int v25; // ebx@24
  int v26; // esi@24
  int result; // eax@44
  int v44; // ecx@87
  int v45; // ecx@95
  int v46; // ecx@103
  int v47; // ecx@111
  int v48; // ecx@119
  int v49; // ecx@127
  int v50; // ecx@135
  int v51; // ecx@143
  int v52; // ecx@151
  int v53; // ecx@159
  int v54; // ecx@167
  int v55; // ecx@175
  int v56; // ecx@183
  int v57; // ecx@191
  int v58; // ecx@199
  int v59; // eax@1
  int v60; // eax@2
  int v61; // eax@3
  int v62; // eax@4
  int v63; // eax@5
  int v64; // eax@6
  int v65; // eax@7
  int v66; // eax@8
  int v67; // eax@9
  int v68; // eax@10
  int v69; // eax@11
  int v70; // eax@12
  int v71; // eax@13
  int v72; // eax@14
  int v73; // eax@15
  int v74; // eax@16
  int v75; // eax@17
  int v76; // eax@18
  int v77; // eax@19
  int v78; // eax@20
  int v79; // eax@21
  int v80; // eax@22
  int v81; // eax@23
  int v82; // eax@30
  int v83; // eax@31
  int v84; // eax@32
  int v85; // eax@33
  int v86; // eax@34
  int v87; // eax@35
  int v88; // eax@36
  int v89; // eax@37
  int v90; // eax@38
  int v91; // eax@39
  int v92; // eax@40
  int v93; // eax@41
  int v94; // eax@42
  int v95; // eax@43
  char v329; // [sp+24h] [bp-24h]@49
  char v330; // [sp+25h] [bp-23h]@53
  char v331; // [sp+26h] [bp-22h]@57
  char v332; // [sp+27h] [bp-21h]@61
  char v333; // [sp+29h] [bp-1Fh]@65
  char v334; // [sp+28h] [bp-20h]@69
  char v335; // [sp+2Ah] [bp-1Eh]@73
  char v336; // [sp+2Bh] [bp-1Dh]@77
  char v337; // [sp+3Bh] [bp-Dh]@81
  char v338; // [sp+33h] [bp-15h]@85
  char v339; // [sp+1Ch] [bp-2Ch]@89
  char v340; // [sp+2Fh] [bp-19h]@93
  char v341; // [sp+18h] [bp-30h]@97
  char v342; // [sp+37h] [bp-11h]@101
  char v343; // [sp+20h] [bp-28h]@105
  char v344; // [sp+2Dh] [bp-1Bh]@109
  char v345; // [sp+16h] [bp-32h]@113
  char v346; // [sp+35h] [bp-13h]@117
  char v347; // [sp+1Eh] [bp-2Ah]@121
  char v348; // [sp+31h] [bp-17h]@125
  char v349; // [sp+1Ah] [bp-2Eh]@129
  char v350; // [sp+39h] [bp-Fh]@133
  char v351; // [sp+22h] [bp-26h]@137
  char v352; // [sp+2Ch] [bp-1Ch]@141
  char v353; // [sp+15h] [bp-33h]@145
  char v354; // [sp+34h] [bp-14h]@149
  char v355; // [sp+1Dh] [bp-2Bh]@153
  char v356; // [sp+30h] [bp-18h]@157
  char v357; // [sp+19h] [bp-2Fh]@161
  char v358; // [sp+38h] [bp-10h]@165
  char v359; // [sp+21h] [bp-27h]@169
  char v360; // [sp+2Eh] [bp-1Ah]@173
  char v361; // [sp+17h] [bp-31h]@177
  char v362; // [sp+36h] [bp-12h]@181
  char v363; // [sp+1Fh] [bp-29h]@185
  char v364; // [sp+32h] [bp-16h]@189
  char v365; // [sp+1Bh] [bp-2Dh]@193
  char v366; // [sp+3Ah] [bp-Eh]@197
  char v367; // [sp+23h] [bp-25h]@201

  v59 = *(_DWORD *)(a3 + 244);
  _EDX = v59 - 12;
  if ( v59 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v337);
  }
  v60 = *(_DWORD *)(a3 + 236);
  _EDX = v60 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v60 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v366);
  }
  v61 = *(_DWORD *)(a3 + 228);
  _EDX = v61 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v61 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v350);
  }
  v62 = *(_DWORD *)(a3 + 220);
  _EDX = v62 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v62 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v358);
  }
  v63 = *(_DWORD *)(a3 + 212);
  _EDX = v63 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v63 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v342);
  }
  v64 = *(_DWORD *)(a3 + 204);
  _EDX = v64 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v64 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v362);
  }
  v65 = *(_DWORD *)(a3 + 196);
  _EDX = v65 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v65 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v346);
  }
  v66 = *(_DWORD *)(a3 + 188);
  _EDX = v66 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v66 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v354);
  }
  v67 = *(_DWORD *)(a3 + 180);
  _EDX = v67 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v67 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v338);
  }
  v68 = *(_DWORD *)(a3 + 172);
  _EDX = v68 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v68 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v364);
  }
  v69 = *(_DWORD *)(a3 + 164);
  _EDX = v69 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v69 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v348);
  }
  v70 = *(_DWORD *)(a3 + 156);
  _EDX = v70 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v70 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v356);
  }
  v71 = *(_DWORD *)(a3 + 152);
  _EDX = v71 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v71 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v340);
  }
  v72 = *(_DWORD *)(a3 + 144);
  _EDX = v72 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v72 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v360);
  }
  v73 = *(_DWORD *)(a3 + 140);
  _EDX = v73 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v73 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v344);
  }
  v74 = *(_DWORD *)(a3 + 136);
  _EDX = v74 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v74 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v352);
  }
  v75 = *(_DWORD *)(a3 + 128);
  _EDX = v75 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v75 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v336);
  }
  v76 = *(_DWORD *)(a3 + 124);
  _EDX = v76 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v76 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v335);
  }
  v77 = *(_DWORD *)(a3 + 120);
  _EDX = v77 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v77 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v333);
  }
  v78 = *(_DWORD *)(a3 + 116);
  _EDX = v78 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v78 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v334);
  }
  v79 = *(_DWORD *)(a3 + 112);
  _EDX = v79 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v79 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v332);
  }
  v80 = *(_DWORD *)(a3 + 108);
  _EDX = v80 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v80 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v331);
  }
  v81 = *(_DWORD *)(a3 + 104);
  _EDX = v81 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v81 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v330);
  }
  v26 = *(_DWORD *)(a3 + 92);
  v25 = *(_DWORD *)(a3 + 88);
  if ( v26 != v25 )
  {
    do
    {
      _EDX = *(_DWORD *)v25 - 12;
      if ( std__string___Rep___S_empty_rep_storage != (char *)_EDX )
      {
        if ( pthread_cancel )
        {
          _EAX = -1;
          __asm { lock xadd [edx+8], eax }
          a1 = _EAX;
        }
        else
        {
          a1 = *(_DWORD *)(_EDX + 8);
          *(_DWORD *)(_EDX + 8) = a1 - 1;
        }
        if ( a1 <= 0 )
          std__string___Rep___M_destroy(_EDX, &v329);
      }
      v25 += 8;
    }
    while ( v26 != v25 );
    _EDX = a3;
    v26 = *(_DWORD *)(a3 + 88);
  }
  if ( v26 )
    operator delete(a1, _EDX);
  v82 = *(_DWORD *)(a3 + 76);
  _EDX = v82 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v82 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v58 = _EAX;
    }
    else
    {
      v58 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v58 - 1;
    }
    if ( v58 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v367);
  }
  v83 = *(_DWORD *)(a3 + 72);
  _EDX = v83 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v83 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v50 = _EAX;
    }
    else
    {
      v50 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v50 - 1;
    }
    if ( v50 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v351);
  }
  v84 = *(_DWORD *)(a3 + 60);
  _EDX = v84 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v84 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v54 = _EAX;
    }
    else
    {
      v54 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v54 - 1;
    }
    if ( v54 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v359);
  }
  v85 = *(_DWORD *)(a3 + 44);
  _EDX = v85 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v85 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v46 = _EAX;
    }
    else
    {
      v46 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v46 - 1;
    }
    if ( v46 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v343);
  }
  v86 = *(_DWORD *)(a3 + 40);
  _EDX = v86 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v86 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v56 = _EAX;
    }
    else
    {
      v56 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v56 - 1;
    }
    if ( v56 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v363);
  }
  v87 = *(_DWORD *)(a3 + 36);
  _EDX = v87 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v87 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v48 = _EAX;
    }
    else
    {
      v48 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v48 - 1;
    }
    if ( v48 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v347);
  }
  v88 = *(_DWORD *)(a3 + 32);
  _EDX = v88 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v88 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v52 = _EAX;
    }
    else
    {
      v52 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v52 - 1;
    }
    if ( v52 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v355);
  }
  v89 = *(_DWORD *)(a3 + 28);
  _EDX = v89 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v89 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v44 = _EAX;
    }
    else
    {
      v44 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v44 - 1;
    }
    if ( v44 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v339);
  }
  v90 = *(_DWORD *)(a3 + 24);
  _EDX = v90 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v90 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v57 = _EAX;
    }
    else
    {
      v57 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v57 - 1;
    }
    if ( v57 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v365);
  }
  v91 = *(_DWORD *)(a3 + 20);
  _EDX = v91 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v91 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v49 = _EAX;
    }
    else
    {
      v49 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v49 - 1;
    }
    if ( v49 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v349);
  }
  v92 = *(_DWORD *)(a3 + 16);
  _EDX = v92 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v92 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v53 = _EAX;
    }
    else
    {
      v53 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v53 - 1;
    }
    if ( v53 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v357);
  }
  v93 = *(_DWORD *)(a3 + 12);
  _EDX = v93 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v93 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v45 = _EAX;
    }
    else
    {
      v45 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v45 - 1;
    }
    if ( v45 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v341);
  }
  v94 = *(_DWORD *)(a3 + 8);
  _EDX = v94 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v94 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v55 = _EAX;
    }
    else
    {
      v55 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v55 - 1;
    }
    if ( v55 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v361);
  }
  v95 = *(_DWORD *)(a3 + 4);
  _EDX = v95 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v95 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v47 = _EAX;
    }
    else
    {
      v47 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v47 - 1;
    }
    if ( v47 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v345);
  }
  result = *(_DWORD *)a3;
  _EDX = *(_DWORD *)a3 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)_EDX )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v51 = result;
    }
    else
    {
      v51 = *(_DWORD *)(_EDX + 8);
      result = v51 - 1;
      *(_DWORD *)(_EDX + 8) = v51 - 1;
    }
    if ( v51 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v353);
  }
  return result;
}

//----- (08050EE0) --------------------------------------------------------
int __cdecl sub_8050EE0(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)(a1 + 4) = 0;
  *(_DWORD *)(a1 + 8) = 0;
  *(_DWORD *)(a1 + 12) = 0;
  return result;
}

//----- (08050F20) --------------------------------------------------------
int __cdecl sub_8050F20(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)(a1 + 12) = 0;
  *(_DWORD *)(a1 + 16) = 0;
  *(_DWORD *)(a1 + 20) = 0;
  return result;
}

//----- (08050F60) --------------------------------------------------------
int __cdecl sub_8050F60(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)(a1 + 4) = 0;
  *(_DWORD *)(a1 + 8) = 0;
  *(_DWORD *)(a1 + 12) = 0;
  return result;
}

//----- (08050FB0) --------------------------------------------------------
int __cdecl sub_8050FB0(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)a1 = &off_807F538;
  *(_DWORD *)(a1 + 4) = 0;
  *(_DWORD *)(a1 + 8) = 0;
  *(_DWORD *)(a1 + 12) = 0;
  return result;
}

//----- (08050FE0) --------------------------------------------------------
int __cdecl sub_8050FE0(int a1, __int16 a2)
{
  int v2; // ebx@1
  int v3; // esi@1
  int v4; // edx@3
  unsigned int v5; // ecx@3
  __int16 v7; // ax@4

  v3 = *(_DWORD *)(a1 + 4);
  v2 = (*(_DWORD *)(a1 + 8) - v3) >> 4;
  if ( !v2 )
    return 0;
  if ( *(_WORD *)v3 != a2 )
  {
    v4 = v3 + 16;
    v5 = 0;
    while ( 1 )
    {
      ++v5;
      if ( v5 >= v2 )
        break;
      v7 = *(_WORD *)v4;
      v3 = v4;
      v4 += 16;
      if ( v7 == a2 )
        return v3;
    }
    return 0;
  }
  return v3;
}

//----- (08051060) --------------------------------------------------------
int __cdecl sub_8051060(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)(a1 + 4) = 0;
  *(_DWORD *)(a1 + 8) = 0;
  *(_DWORD *)(a1 + 12) = 0;
  *(_DWORD *)a1 = &off_807F520;
  return result;
}

//----- (08051180) --------------------------------------------------------
int __cdecl sub_8051180(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)(a1 + 16) = 134771820;
  *(_DWORD *)(a1 + 20) = 0;
  *(_DWORD *)(a1 + 24) = 0;
  *(_DWORD *)(a1 + 28) = 0;
  *(_DWORD *)a1 = &off_807F4E8;
  return result;
}

//----- (080511E0) --------------------------------------------------------
int __cdecl sub_80511E0(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)(a1 + 16) = 134771820;
  *(_DWORD *)(a1 + 20) = 0;
  *(_DWORD *)(a1 + 24) = 0;
  *(_DWORD *)(a1 + 28) = 0;
  *(_DWORD *)a1 = &off_807F4D8;
  return result;
}

//----- (08051230) --------------------------------------------------------
int __cdecl sub_8051230(int a1)
{
  int result; // eax@1

  result = a1;
  *(_WORD *)a1 = 3;
  *(_WORD *)(a1 + 2) = 0;
  *(_DWORD *)(a1 + 4) = 134771820;
  return result;
}

//----- (08051270) --------------------------------------------------------
int __cdecl sub_8051270(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)(a1 + 8) = 134771820;
  *(_BYTE *)(a1 + 4) = 1;
  *(_BYTE *)(a1 + 5) = 1;
  return result;
}

//----- (080512C0) --------------------------------------------------------
int __cdecl sub_80512C0(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)(a1 + 4) = 134771820;
  *(_DWORD *)(a1 + 16) = 0;
  *(_DWORD *)(a1 + 20) = 0;
  *(_DWORD *)(a1 + 24) = 0;
  return result;
}

//----- (08051310) --------------------------------------------------------
int __cdecl sub_8051310(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)(a1 + 8) = 0;
  *(_DWORD *)(a1 + 12) = 0;
  *(_DWORD *)(a1 + 16) = 0;
  return result;
}

//----- (08051340) --------------------------------------------------------
void __cdecl sub_8051340()
{
  ;
}

//----- (08051360) --------------------------------------------------------
void __cdecl sub_8051360()
{
  ;
}

//----- (08051390) --------------------------------------------------------
int __cdecl sub_8051390(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)a1 = 134771820;
  *(_BYTE *)(a1 + 4) = 1;
  *(_BYTE *)(a1 + 9) = 16;
  return result;
}

//----- (080513E0) --------------------------------------------------------
int __cdecl sub_80513E0(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)a1 = 134771820;
  *(_DWORD *)(a1 + 24) = 0;
  *(_DWORD *)(a1 + 28) = 0;
  *(_DWORD *)(a1 + 32) = 0;
  return result;
}

//----- (08051410) --------------------------------------------------------
signed int __cdecl sub_8051410(int a1, int a2, int a3)
{
  int v3; // ecx@1
  signed int v4; // ebx@1
  int v5; // edi@1
  __int16 v7; // ax@2
  int v9; // eax@2
  int v10; // ecx@2

  v5 = a2;
  v3 = a3;
  v4 = 0;
  if ( a3 + 16 <= (unsigned int)(*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) )
  {
    v4 = 1;
    v7 = __ROR__(*(_WORD *)(*(_DWORD *)a2 + a3), 8);
    *(_WORD *)a1 = v7;
    __asm { bswap   eax }
    *(_DWORD *)(a1 + 4) = _EAX;
    LOWORD(_EAX) = __ROR__(*(_WORD *)(v3 + *(_DWORD *)v5 + 6), 8);
    *(_WORD *)(a1 + 8) = _EAX;
    LOWORD(_EAX) = __ROR__(*(_WORD *)(v3 + *(_DWORD *)v5 + 8), 8);
    *(_WORD *)(a1 + 10) = _EAX;
    v9 = v3 + *(_DWORD *)v5;
    v10 = *(_DWORD *)v5 + v3;
    LOWORD(v9) = __ROR__(*(_WORD *)(v9 + 10), 8);
    *(_WORD *)(a1 + 12) = v9;
    LOWORD(v9) = __ROR__(*(_WORD *)(v10 + 12), 8);
    *(_WORD *)(a1 + 14) = v9;
  }
  return v4;
}

//----- (080514B0) --------------------------------------------------------
signed int __cdecl sub_80514B0(int a1, int a2, int a3)
{
  int v3; // ecx@1
  signed int v4; // ebx@1
  int v5; // edi@1
  __int16 v7; // ax@2
  __int16 v8; // ax@2
  __int16 v9; // ax@2
  int v10; // ecx@2

  v5 = a2;
  v3 = a3;
  v4 = 0;
  if ( a3 + 10 <= (unsigned int)(*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) )
  {
    v4 = 1;
    v7 = __ROR__(*(_WORD *)(*(_DWORD *)a2 + a3), 8);
    *(_WORD *)a1 = v7;
    v8 = __ROR__(*(_WORD *)(v3 + *(_DWORD *)v5 + 2), 8);
    *(_WORD *)(a1 + 2) = v8;
    v9 = __ROR__(*(_WORD *)(v3 + *(_DWORD *)v5 + 4), 8);
    *(_WORD *)(a1 + 4) = v9;
    v10 = *(_DWORD *)v5 + v3;
    __asm { bswap   eax }
    *(_DWORD *)(a1 + 8) = _EAX;
    sub_80564B0(v10, *(_DWORD *)(v5 + 4), a1 + 12, (const void *)(v10 + 10), *(_DWORD *)(v5 + 4));
  }
  return v4;
}

//----- (08051550) --------------------------------------------------------
signed int __cdecl sub_8051550(int a1, int a2)
{
  std__string__assign(a2, *(_DWORD *)(a1 + 4), *(_DWORD *)(a1 + 8) - *(_DWORD *)(a1 + 4));
  return 1;
}

//----- (08051580) --------------------------------------------------------
int __cdecl sub_8051580(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)(a1 + 20) = -1;
  *(_DWORD *)(a1 + 12) = 134771820;
  *(_DWORD *)(a1 + 24) = 134771820;
  *(_DWORD *)(a1 + 48) = 134771820;
  *(_DWORD *)(a1 + 52) = 134771820;
  *(_DWORD *)(a1 + 56) = 134771820;
  *(_DWORD *)(a1 + 64) = 134771820;
  *(_DWORD *)(a1 + 68) = 134771820;
  *(_DWORD *)(a1 + 16) = 0;
  *(_BYTE *)(a1 + 23) = 0;
  return result;
}

//----- (080515E0) --------------------------------------------------------
int __cdecl sub_80515E0(int a1)
{
  a1 += 52;
  return sub_8051580(a1);
}

//----- (08051660) --------------------------------------------------------
signed int __cdecl sub_8051660(int a1, int a2)
{
  signed int v2; // edx@1
  int v4; // edx@2

  v2 = 0;
  if ( (unsigned int)(*(_DWORD *)(a1 + 8) - *(_DWORD *)(a1 + 4)) > 3 )
  {
    v4 = a2;
    __asm { bswap   eax }
    *(_DWORD *)v4 = _EAX;
    v2 = 1;
  }
  return v2;
}

//----- (08051690) --------------------------------------------------------
signed int __cdecl sub_8051690(int a1, int a2)
{
  signed int v2; // edx@1
  int v3; // ecx@1
  __int16 v5; // ax@2

  v2 = 0;
  v3 = *(_DWORD *)(a1 + 4);
  if ( (unsigned int)(*(_DWORD *)(a1 + 8) - v3) > 1 )
  {
    v5 = __ROR__(*(_WORD *)v3, 8);
    *(_WORD *)a2 = v5;
    v2 = 1;
  }
  return v2;
}

//----- (080516C0) --------------------------------------------------------
signed int __cdecl sub_80516C0(int a1, int a2, int a3)
{
  int v3; // ecx@1
  int v4; // esi@1
  signed int result; // eax@2
  unsigned __int16 v6; // ax@4
  int v7; // eax@4
  int v8; // edx@4
  int v9; // [sp+18h] [bp-20h]@4
  __int16 v10; // [sp+2Ah] [bp-Eh]@4

  v4 = a3 + 4;
  v3 = *(_DWORD *)(a2 + 4) - *(_DWORD *)a2;
  if ( a3 + 4 > (unsigned int)v3
    || (v7 = a3 + *(_DWORD *)a2, v9 = a3 + *(_DWORD *)a2, LOWORD(v7) = *(_WORD *)v7, v8 = *(_DWORD *)a2 + a3, v10 = v7, LOWORD(v7) = __ROR__(v7, 8), *(_WORD *)a1 = v7, LOWORD(v7) = *(_WORD *)(v8 + 2), v10 = *(_WORD *)(v8 + 2), v6 = __ROR__(v7, 8), (unsigned int)v6 + v4 > v3) )
  {
    result = 0;
  }
  else
  {
    sub_80564B0(v3, v9 + 4, a1 + 4, (const void *)(v9 + 4), v9 + 4 + v6);
    result = 1;
  }
  return result;
}

//----- (08051750) --------------------------------------------------------
signed int __cdecl sub_8051750(int a1, int a2)
{
  int v2; // ebx@1
  int v3; // esi@1
  int v4; // edi@2
  unsigned int v5; // edx@3
  int v6; // ecx@3
  int v8; // edx@8
  unsigned __int16 v9; // dx@9
  int v10; // ebx@10
  __int16 v11; // ax@4
  int v12; // edx@9
  __int16 v13; // ax@9
  int v14; // eax@10
  __int16 v15; // [sp+1Ah] [bp-Eh]@9

  v2 = *(_DWORD *)a2;
  v3 = (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 4;
  if ( !v3 )
    return 0;
  v4 = 0;
  if ( *(_WORD *)v2 != 5 )
  {
    v6 = v2 + 16;
    v5 = 0;
    do
    {
      ++v5;
      if ( v5 >= v3 )
        return 0;
      v11 = *(_WORD *)v6;
      v2 = v6;
      v4 = 16 * v5;
      v6 += 16;
    }
    while ( v11 != 5 );
  }
  v8 = *(_DWORD *)(v2 + 4);
  if ( (unsigned int)(*(_DWORD *)(v2 + 8) - v8) <= 8 )
    return 0;
  *(_DWORD *)a1 = *(_DWORD *)v8;
  v12 = *(_DWORD *)(*(_DWORD *)a2 + v4 + 4);
  *(_BYTE *)(a1 + 4) = *(_BYTE *)(v12 + 4);
  *(_BYTE *)(a1 + 5) = *(_BYTE *)(v12 + 5);
  v13 = *(_WORD *)(v12 + 6);
  v9 = *(_WORD *)(v12 + 6);
  v15 = v13;
  if ( !v13 || (v14 = *(_DWORD *)a2 + v4, v10 = *(_DWORD *)(v14 + 4), (unsigned int)v9 + 8 > *(_DWORD *)(v14 + 8) - v10) )
    return 0;
  std__string__assign(a1 + 8, v10 + 8, v9 - 1);
  return 1;
}

//----- (08051830) --------------------------------------------------------
signed int __cdecl sub_8051830(signed int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ecx@1
  int v5; // ebx@1
  signed int result; // eax@2
  int v7; // edi@6
  int v8; // ecx@7
  char v9; // zf@8
  signed int v10; // ecx@8
  int *v11; // edi@8
  int v12; // esi@8
  int v13; // esi@14
  int v14; // ecx@15
  int v15; // edi@15
  int v16; // esi@16
  int v17; // edx@17
  int v18; // ecx@17
  int v19; // edi@17
  char v20; // al@18
  char v21; // al@27
  int v22; // edx@31
  int v23; // ecx@31
  char v24; // zf@33
  signed int v25; // ecx@33
  char *v26; // edi@33
  int v27; // esi@33
  int v28; // edx@38
  int v29; // edi@38
  int v30; // edx@40
  int v31; // ecx@40
  int v32; // esi@40
  int v33; // eax@41
  int v34; // edx@42
  int v35; // ecx@42
  int v36; // edi@42
  int v37; // esi@42
  int v38; // edx@43
  int v39; // eax@44
  int v40; // ecx@46
  int v41; // edi@47
  int v42; // edx@48
  int v43; // ecx@48
  int v44; // esi@48
  int v45; // eax@49
  int v46; // edx@1
  __int16 v47; // ax@5
  int v48; // esi@7
  int v49; // esi@7
  int v50; // esi@8
  __int16 v51; // ax@32
  int v52; // edx@33
  __int16 v53; // ax@39
  int v54; // eax@43
  int v55; // esi@47
  int v56; // [sp+68h] [bp-10h]@1
  signed int v57; // [sp+14h] [bp-64h]@1
  __int16 v58; // [sp+46h] [bp-32h]@5
  int v59; // [sp+20h] [bp-58h]@6
  int v60; // [sp+58h] [bp-20h]@7
  int v61; // [sp+5Ch] [bp-1Ch]@7
  int v62; // [sp+60h] [bp-18h]@7
  int v63; // [sp+64h] [bp-14h]@7
  int v64; // [sp+1Ch] [bp-5Ch]@7
  unsigned int v65; // [sp+18h] [bp-60h]@7
  unsigned __int16 v66; // [sp+44h] [bp-34h]@18
  int v67; // [sp+24h] [bp-54h]@27
  int v68; // [sp+28h] [bp-50h]@32
  __int16 v69; // [sp+42h] [bp-36h]@32
  char v70; // [sp+48h] [bp-30h]@33
  char v71; // [sp+49h] [bp-2Fh]@33
  char v72; // [sp+4Ah] [bp-2Eh]@33
  char v73; // [sp+4Bh] [bp-2Dh]@33
  char v74; // [sp+4Ch] [bp-2Ch]@33
  char v75; // [sp+4Dh] [bp-2Bh]@33
  char v76; // [sp+4Eh] [bp-2Ah]@33
  char v77; // [sp+4Fh] [bp-29h]@33
  char v78; // [sp+50h] [bp-28h]@33
  char v79; // [sp+51h] [bp-27h]@33
  char v80; // [sp+52h] [bp-26h]@33
  char v81; // [sp+53h] [bp-25h]@33
  char v82; // [sp+54h] [bp-24h]@33
  char v83; // [sp+55h] [bp-23h]@33
  char v84; // [sp+56h] [bp-22h]@33
  char v85; // [sp+57h] [bp-21h]@33
  int v86; // [sp+3Ch] [bp-3Ch]@41
  int v87; // [sp+38h] [bp-40h]@43
  int v88; // [sp+34h] [bp-44h]@44

  v5 = a2;
  v56 = *MK_FP(__GS__, 20);
  v4 = *(_DWORD *)a2;
  v46 = *(_DWORD *)(a2 + 4);
  v57 = a1;
  v3 = v46 - v4;
  if ( a3 + 2 > (unsigned int)v3 )
    goto LABEL_2;
  v47 = *(_WORD *)(v4 + a3);
  v58 = *(_WORD *)(v4 + a3);
  if ( v47 != 27 )
    goto LABEL_2;
  v7 = a3 + 4;
  v59 = a3 + 4;
  if ( a3 + 4 > (unsigned int)v3 )
    goto LABEL_2;
  *(_WORD *)v57 = *(_WORD *)(v4 + a3 + 2);
  v60 = 0;
  v61 = 0;
  v62 = 0;
  v63 = 0;
  v8 = *(_DWORD *)v5;
  v48 = *(_DWORD *)(v5 + 4);
  v64 = *(_DWORD *)v5;
  v49 = v48 - v8;
  v65 = v49;
  if ( a3 + 20 > (unsigned int)v49 )
    goto LABEL_2;
  v50 = v8;
  v10 = 16;
  v9 = v7 + v50 == 0;
  v12 = v7 + v50;
  v11 = &v60;
  do
  {
    if ( !v10 )
      break;
    v9 = *(_BYTE *)v12++ == *(_BYTE *)v11;
    v11 = (int *)((char *)v11 + 1);
    --v10;
  }
  while ( v9 );
  if ( !v9
    || a3 + 33 > v65
    || (*(_WORD *)(v57 + 2) = *(_WORD *)(v64 + a3 + 31), v13 = a3 + 47, a3 + 47 > (unsigned int)(*(_DWORD *)(v5 + 4)
                                                                                               - *(_DWORD *)v5))
    || (v15 = a3, v14 = a3 + 49, *(_BYTE *)(v57 + 4) = *(_BYTE *)(*(_DWORD *)v5 + a3 + 45), *(_BYTE *)(v57 + 5) = *(_BYTE *)(*(_DWORD *)v5 + v15 + 46), v14 > (unsigned int)(*(_DWORD *)(v5 + 4) - *(_DWORD *)v5))
    || (*(_WORD *)(v57 + 6) = *(_WORD *)(*(_DWORD *)v5 + v13), v16 = v15 + 51, v15 + 51 > (unsigned int)(*(_DWORD *)(v5 + 4) - *(_DWORD *)v5))
    || (*(_WORD *)(v57 + 8) = *(_WORD *)(*(_DWORD *)v5 + v14), v17 = *(_DWORD *)(v5 + 4), v18 = *(_DWORD *)v5, v19 = a3 + 53, a3 + 53 > (unsigned int)(v17 - *(_DWORD *)v5))
    || (v66 = *(_WORD *)(v18 + v16), v20 = *(_BYTE *)(v57 + 4), v20 != 1)
    && v20 != 26
    && v20 != -24
    && v20 != -23
    && v20 != -22
    && v20 != -21
    && v20 != -20
    || !v66
    || v19 + (unsigned int)v66 > v17 - v18 )
    goto LABEL_2;
  std__string__assign(v57 + 12, v18 + v19, v66 - 1);
  v67 = v19 + v66;
  v21 = *(_BYTE *)(v57 + 4);
  if ( v21 != 1 )
  {
    if ( v21 == 26 )
      goto LABEL_31;
    goto LABEL_29;
  }
  v40 = v67 + 4;
  if ( v67 + 4 > (unsigned int)(*(_DWORD *)(v5 + 4) - *(_DWORD *)v5)
    || (v55 = v67, *(_DWORD *)(v57 + 16) = *(_DWORD *)(*(_DWORD *)v5 + v67), v41 = v55 + 8, v55 + 8 > (unsigned int)(*(_DWORD *)(v5 + 4) - *(_DWORD *)v5))
    || (*(_DWORD *)(v57 + 20) = *(_DWORD *)(*(_DWORD *)v5 + v40), v44 = *(_DWORD *)v5, v43 = v67 + 12, v42 = *(_DWORD *)(v5 + 4) - *(_DWORD *)v5, v67 + 12 > (unsigned int)v42)
    || (v45 = *(_DWORD *)(v44 + v41), v86 = *(_DWORD *)(v44 + v41), v5 = v45, v43 + v45 > (unsigned int)v42) )
  {
LABEL_29:
    result = 1;
    goto LABEL_3;
  }
  std__string__assign(v57 + 24, v44 + v43, v45);
  result = 1;
LABEL_3:
  while ( *MK_FP(__GS__, 20) ^ v56 )
  {
    __stack_chk_fail();
LABEL_31:
    v22 = *(_DWORD *)v5;
    v23 = *(_DWORD *)(v5 + 4) - *(_DWORD *)v5;
    if ( v67 + 2 > (unsigned int)v23 )
      goto LABEL_2;
    v51 = *(_WORD *)(v22 + v67);
    v68 = v67 + 18;
    v69 = v51;
    if ( v67 + 18 > (unsigned int)v23 )
      goto LABEL_2;
    v52 = v67 + 2 + v22;
    v25 = 16;
    *(_DWORD *)(v57 + 28) = *(_DWORD *)v52;
    v24 = v57 == -28;
    v27 = v57 + 28;
    *(_DWORD *)(v57 + 32) = *(_DWORD *)(v52 + 4);
    *(_DWORD *)(v57 + 36) = *(_DWORD *)(v52 + 8);
    *(_DWORD *)(v57 + 40) = *(_DWORD *)(v52 + 12);
    v70 = 59;
    v26 = &v70;
    v71 = 96;
    v72 = -77;
    v73 = -17;
    v74 = -40;
    v75 = 42;
    v76 = 108;
    v77 = 69;
    v78 = -92;
    v79 = -32;
    v80 = -100;
    v81 = 90;
    v82 = 94;
    v83 = 103;
    v84 = -24;
    v85 = 101;
    do
    {
      if ( !v25 )
        break;
      v24 = *(_BYTE *)v27++ == *v26++;
      --v25;
    }
    while ( v24 );
    if ( v24
      && (v28 = *(_DWORD *)v5, v29 = v67 + 20, v67 + 20 <= (unsigned int)(*(_DWORD *)(v5 + 4) - *(_DWORD *)v5))
      && (v53 = *(_WORD *)(v28 + v68), *(_WORD *)(v57 + 44) = *(_WORD *)(v28 + v68), v53 == 8)
      && (v30 = *(_DWORD *)(v5 + 4), v31 = *(_DWORD *)v5, v32 = v67 + 24, v67 + 24 <= (unsigned int)(v30 - *(_DWORD *)v5))
      && (v33 = *(_DWORD *)(v31 + v29), v86 = *(_DWORD *)(v31 + v29), v32 + v33 <= (unsigned int)(v30 - v31))
      && (std__string__assign(v57 + 48, v31 + v32, v33), v34 = v32 + v86 + 15, v37 = *(_DWORD *)v5, v36 = v34 + 4, v35 = *(_DWORD *)(v5 + 4) - *(_DWORD *)v5, v34 + 4 <= (unsigned int)v35)
      && (v54 = *(_DWORD *)(v37 + v34), v38 = v34 + 8, v87 = v54, v38 <= (unsigned int)v35)
      && (v39 = *(_DWORD *)(v37 + v36), v88 = *(_DWORD *)(v37 + v36), v5 = v39, v38 + v39 <= (unsigned int)v35) )
    {
      std__string__assign(v57 + 52, v37 + v38, v39);
      result = 1;
    }
    else
    {
LABEL_2:
      result = 0;
    }
  }
  return result;
}

//----- (08051C40) --------------------------------------------------------
int __cdecl sub_8051C40(int a1, int a2)
{
  int v2; // ebx@1
  int v3; // esi@1
  int v4; // ecx@4
  int v5; // esi@4
  int v6; // edx@5
  int v7; // ecx@5
  int v8; // edi@5
  int result; // eax@10
  int v10; // edi@11
  int v11; // edx@13
  int v12; // eax@17
  int v13; // edx@18
  int v14; // ecx@21
  int v15; // edx@22
  int v16; // edx@2
  int v17; // [sp+8h] [bp-10h]@2
  int v18; // [sp+4h] [bp-14h]@17

  v3 = a2;
  v2 = *(_DWORD *)a2;
  if ( *(_DWORD *)(*(_DWORD *)a2 - 4) < 0 )
  {
    v17 = v2 + *(_DWORD *)(v2 - 12);
  }
  else
  {
    std__string___M_leak_hard(a2);
    v2 = *(_DWORD *)v3;
    v16 = *(_DWORD *)(*(_DWORD *)v3 - 4);
    v17 = *(_DWORD *)v3 + *(_DWORD *)(*(_DWORD *)v3 - 12);
    if ( v16 >= 0 )
    {
      std__string___M_leak_hard(v3);
      v2 = *(_DWORD *)v3;
    }
  }
  v4 = *(_DWORD *)(a1 + 4);
  v5 = v17 - v2;
  if ( v17 - v2 <= (unsigned int)(*(_DWORD *)(a1 + 12) - v4) )
  {
    v10 = *(_DWORD *)(a1 + 8);
    result = v10 - v4;
    if ( v5 > (unsigned int)(v10 - v4) )
    {
      v12 = v2 + result;
      v18 = v12;
      if ( v12 - v2 > 0 )
      {
        v13 = 0;
        do
        {
          *(_BYTE *)(v4 + v13) = *(_BYTE *)(v2 + v13);
          ++v13;
        }
        while ( v13 != v12 - v2 );
        v10 = *(_DWORD *)(a1 + 8);
      }
      result = v10;
      v14 = v17 - v18;
      if ( v17 - v18 > 0 )
      {
        v15 = 0;
        do
        {
          *(_BYTE *)(v10 + v15) = *(_BYTE *)(v18 + v15);
          ++v15;
        }
        while ( v15 != v14 );
        result = v10 + v15;
      }
      *(_DWORD *)(a1 + 8) = result;
    }
    else
    {
      if ( v5 > 0 )
      {
        v11 = 0;
        do
        {
          result = *(_BYTE *)(v2 + v11);
          *(_BYTE *)(v4 + v11) = *(_BYTE *)(v2 + v11);
          ++v11;
        }
        while ( v5 != v11 );
        v4 += v5;
      }
      *(_DWORD *)(a1 + 8) = v4;
    }
  }
  else
  {
    v8 = operator new(v4, a1);
    if ( v5 > 0 )
    {
      v6 = 0;
      do
      {
        *(_BYTE *)(v8 + v6) = *(_BYTE *)(v2 + v6);
        ++v6;
      }
      while ( v5 != v6 );
    }
    if ( *(_DWORD *)(a1 + 4) )
      operator delete(v7, v6);
    *(_DWORD *)(a1 + 4) = v8;
    result = v8 + v5;
    *(_DWORD *)(a1 + 8) = v8 + v5;
    *(_DWORD *)(a1 + 12) = v8 + v5;
  }
  return result;
}

//----- (08051D90) --------------------------------------------------------
int __fastcall sub_8051D90(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  int v7; // [sp+0h] [bp-18h]@3

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 8);
  v3 = *(_DWORD *)(a3 + 4);
  *(_DWORD *)a3 = &off_807F538;
  if ( v5 != v3 )
  {
    do
    {
      if ( *(_DWORD *)(v3 + 4) )
      {
        v7 = *(_DWORD *)(v3 + 4);
        operator delete(a1, a2);
      }
      v3 += 16;
    }
    while ( v5 != v3 );
    v5 = *(_DWORD *)(v4 + 4);
  }
  if ( v5 )
  {
    v7 = v5;
    operator delete(a1, a2);
  }
  a3 = v4;
  return operator delete(a1, a2);
}

//----- (08051DF0) --------------------------------------------------------
char __fastcall sub_8051DF0(int a1, int a2, int a3, int a4)
{
  int v4; // ebx@1
  int v5; // esi@1
  void *v6; // edx@2
  int v7; // ecx@2
  int v8; // edx@3
  const void *v9; // ecx@3
  int v10; // edx@5
  int v11; // ecx@5
  int v12; // ebx@5
  ssize_t v13; // edi@5
  int v14; // esi@5
  int v16; // eax@1
  int v17; // eax@2
  __int16 v18; // ax@3
  __int16 v19; // ax@3
  int v20; // [sp+24h] [bp-14h]@1
  int v21; // [sp+20h] [bp-18h]@1
  void *v22; // [sp+1Ch] [bp-1Ch]@1
  __int16 v23; // [sp+2Ah] [bp-Eh]@3
  __int16 v24; // [sp+28h] [bp-10h]@3

  v5 = a3;
  v20 = 0;
  v16 = *(_DWORD *)(a3 + 8) - *(_DWORD *)(a3 + 4);
  v21 = 0;
  v22 = 0;
  v4 = v16 + 6;
  if ( v16 == -6 )
  {
    v6 = 0;
    v7 = 0;
  }
  else
  {
    v17 = operator new(a1, a2);
    v6 = (void *)v17;
    v7 = v17;
  }
  v20 = (int)((char *)v6 + v4);
  v22 = v6;
  memset(v6, 0, (size_t)(v6 + v4 - v7));
  v21 = v20;
  *(_BYTE *)v22 = 42;
  *((_BYTE *)v22 + 1) = *(_BYTE *)v5;
  v18 = __ROR__(*(_WORD *)(v5 + 2), 8);
  v23 = v18;
  *((_WORD *)v22 + 1) = v18;
  v19 = __ROR__(*(_DWORD *)(v5 + 8) - *(_DWORD *)(v5 + 4), 8);
  v24 = v19;
  *((_WORD *)v22 + 2) = v19;
  v8 = *(_DWORD *)(v5 + 8);
  v9 = *(const void **)(v5 + 4);
  if ( v8 != (_DWORD)v9 )
  {
    memcpy((char *)v22 + 6, v9, v8 - (_DWORD)v9);
    v9 = *(const void **)(v5 + 4);
    v8 = *(_DWORD *)(v5 + 8);
  }
  *(_DWORD *)(v5 + 16) = -1;
  v13 = send(a4, v22, v8 - (_DWORD)v9 + 6, 0);
  v12 = *(_DWORD *)(v5 + 8);
  v14 = *(_DWORD *)(v5 + 4);
  if ( v22 )
    operator delete(v11, v10);
  return v13 == v12 - v14 + 6;
}

//----- (08051F30) --------------------------------------------------------
signed int __fastcall sub_8051F30(int a1, int a2, int a3, int a4)
{
  int v4; // ecx@1
  int v5; // eax@3
  int v6; // eax@5
  int v7; // edi@5
  unsigned int v8; // esi@5
  int v9; // edx@11
  signed int v10; // ebx@11
  size_t v12; // esi@18
  void *v13; // edi@19
  size_t v14; // eax@21
  int v15; // eax@22
  ssize_t v16; // eax@30
  int v17; // eax@1
  int v18; // ecx@1
  __int16 v19; // ax@18
  unsigned __int16 v20; // ax@18
  int v21; // [sp+B8h] [bp-20h]@1
  int v22; // [sp+B0h] [bp-28h]@1
  unsigned int v23; // [sp+C4h] [bp-14h]@1
  int v24; // [sp+B4h] [bp-24h]@1
  _DWORD v25[32]; // [sp+30h] [bp-A8h]@3
  signed int v26; // [sp+C0h] [bp-18h]@5
  signed int v27; // [sp+BCh] [bp-1Ch]@5
  unsigned __int16 v28; // [sp+CAh] [bp-Eh]@18
  unsigned int v29; // [sp+20h] [bp-B8h]@19
  signed int v30; // [sp+28h] [bp-B0h]@19
  int v31; // [sp+24h] [bp-B4h]@19

  v17 = operator new(a1, a2);
  v21 = v17 + 6;
  v22 = v17;
  *(_DWORD *)v17 = 0;
  *(_WORD *)(v17 + 4) = 0;
  v18 = a4;
  v23 = 0;
  v24 = v21;
  *(_DWORD *)(a3 + 16) = -1;
  if ( ioctl(v4, 0x541Bu, &v23) )
    goto LABEL_13;
  if ( v23 <= 5 )
  {
    v5 = (int)v25;
    do
    {
      *(_DWORD *)v5 = 0;
      v5 += 4;
    }
    while ( v5 != (_DWORD)&v22 );
    v26 = 300000;
    v27 = 0;
    v7 = a4 & 0x1F;
    v8 = (unsigned int)a4 >> 5;
    v25[(unsigned int)a4 >> 5] |= 1 << v7;
    v6 = select(a4 + 1, (fd_set *)v25, 0, 0, (struct timeval *)&v27);
    if ( !v6 )
      goto LABEL_11;
    if ( v6 < 0 || (v4 = v7, !((v25[v8] >> v7) & 1)) || (v23 = 0, ioctl(a4, 0x541Bu, &v23)) || !v23 )
      goto LABEL_13;
    if ( v23 <= 5 )
    {
LABEL_11:
      v4 = a3;
      v10 = 0;
      v9 = v22;
      *(_DWORD *)(a3 + 16) = -2;
      goto LABEL_14;
    }
  }
  if ( recv(a4, (void *)v22, 6u, 0) != 6 )
  {
LABEL_13:
    v9 = v22;
    v10 = 0;
    goto LABEL_14;
  }
  v9 = v22;
  v10 = 0;
  if ( *(_BYTE *)v22 == 42 )
  {
    *(_BYTE *)a3 = *(_BYTE *)(v22 + 1);
    v19 = __ROR__(*(_WORD *)(v9 + 2), 8);
    *(_WORD *)(a3 + 2) = v19;
    v20 = __ROR__(*(_WORD *)(v9 + 4), 8);
    v28 = v20;
    sub_8056790(a3 + 4, v20, 0);
    v12 = v28;
    if ( v28 )
    {
      v13 = *(void **)(a3 + 4);
      v29 = (unsigned int)a4 >> 5;
      v30 = 1 << (a4 & 0x1F);
      v31 = a4 & 0x1F;
      while ( 1 )
      {
        v23 = 0;
        if ( ioctl(a4, 0x541Bu, &v23) )
          goto LABEL_13;
        v14 = v23;
        if ( !v23 )
        {
          v15 = (int)v25;
          do
          {
            *(_DWORD *)v15 = 0;
            v15 += 4;
          }
          while ( v15 != (_DWORD)&v22 );
          v26 = 0;
          v27 = 30;
          v25[v29] |= v30;
          if ( select(a4 + 1, (fd_set *)v25, 0, 0, (struct timeval *)&v27) <= 0 )
            goto LABEL_13;
          v4 = (unsigned __int8)v31;
          if ( !((v25[v29] >> v31) & 1) )
            goto LABEL_13;
          v23 = 0;
          if ( ioctl(a4, 0x541Bu, &v23) )
            goto LABEL_13;
          v14 = v23;
          if ( !v23 )
            goto LABEL_13;
        }
        if ( v12 < v14 )
        {
          v23 = v12;
          v14 = v12;
        }
        v16 = recv(a4, v13, v14, 0);
        if ( v16 <= 0 )
          goto LABEL_13;
        v12 -= v16;
        if ( (signed int)v12 <= 0 )
          break;
        v13 = (char *)v13 + v16;
      }
    }
    v9 = v22;
    v10 = 1;
  }
LABEL_14:
  if ( v9 )
    operator delete(v4, v9);
  return v10;
}

//----- (080522F0) --------------------------------------------------------
int __fastcall sub_80522F0(int a1, int a2, int a3)
{
  int result; // eax@1

  result = *(_DWORD *)(a3 + 4);
  if ( result )
  {
    a3 = *(_DWORD *)(a3 + 4);
    result = operator delete(a1, a2);
  }
  return result;
}

//----- (08052330) --------------------------------------------------------
int __fastcall sub_8052330(int a1, int a2, int a3)
{
  int result; // eax@1

  result = *(_DWORD *)(a3 + 12);
  if ( result )
  {
    a3 = *(_DWORD *)(a3 + 12);
    result = operator delete(a1, a2);
  }
  return result;
}

//----- (08052370) --------------------------------------------------------
int __fastcall sub_8052370(int a1, int a2, int a3)
{
  int result; // eax@1

  result = *(_DWORD *)(a3 + 4);
  if ( result )
  {
    a3 = *(_DWORD *)(a3 + 4);
    result = operator delete(a1, a2);
  }
  return result;
}

//----- (08052390) --------------------------------------------------------
int __fastcall sub_8052390(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  int result; // eax@2
  int v7; // [sp+0h] [bp-18h]@3

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 8);
  v3 = *(_DWORD *)(a3 + 4);
  *(_DWORD *)a3 = &off_807F538;
  if ( v5 != v3 )
  {
    do
    {
      result = *(_DWORD *)(v3 + 4);
      if ( result )
      {
        v7 = *(_DWORD *)(v3 + 4);
        result = operator delete(a1, a2);
      }
      v3 += 16;
    }
    while ( v5 != v3 );
    v5 = *(_DWORD *)(v4 + 4);
  }
  if ( v5 )
  {
    a3 = v5;
    result = operator delete(a1, a2);
  }
  return result;
}

//----- (080523F0) --------------------------------------------------------
int __fastcall sub_80523F0(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  int result; // eax@2
  int v7; // [sp+0h] [bp-18h]@3

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 8);
  v3 = *(_DWORD *)(a3 + 4);
  *(_DWORD *)a3 = &off_807F538;
  if ( v5 != v3 )
  {
    do
    {
      result = *(_DWORD *)(v3 + 4);
      if ( result )
      {
        v7 = *(_DWORD *)(v3 + 4);
        result = operator delete(a1, a2);
      }
      v3 += 16;
    }
    while ( v5 != v3 );
    v5 = *(_DWORD *)(v4 + 4);
  }
  if ( v5 )
  {
    a3 = v5;
    result = operator delete(a1, a2);
  }
  return result;
}

//----- (08052450) --------------------------------------------------------
int __fastcall sub_8052450(int a1, int a2, int a3)
{
  int v4; // ebx@1
  int v5; // ecx@1
  int v6; // edx@1

  v4 = a3;
  *(_DWORD *)a3 = &off_807F508;
  sub_80523F0(a1, a2, a3);
  a3 = v4;
  return operator delete(v5, v6);
}

//----- (08052480) --------------------------------------------------------
int __fastcall sub_8052480(int a1, int a2, int a3)
{
  *(_DWORD *)a3 = &off_807F508;
  return sub_80523F0(a1, a2, a3);
}

//----- (080524C0) --------------------------------------------------------
int __fastcall sub_80524C0(int a1, int a2, int a3)
{
  int v4; // ebx@1
  int v5; // ecx@1
  int v6; // edx@1

  v4 = a3;
  *(_DWORD *)a3 = &off_807F520;
  sub_80523F0(a1, a2, a3);
  a3 = v4;
  return operator delete(v5, v6);
}

//----- (080524F0) --------------------------------------------------------
int __fastcall sub_80524F0(int a1, int a2, int a3)
{
  *(_DWORD *)a3 = &off_807F520;
  return sub_80523F0(a1, a2, a3);
}

//----- (08052530) --------------------------------------------------------
int __cdecl sub_8052530(int a1)
{
  int v2; // edx@1
  int v3; // ebx@1
  int v4; // esi@1
  int result; // eax@3
  char v7; // [sp+1Fh] [bp-9h]@1
  int v8; // [sp+18h] [bp-10h]@1

  v4 = a1;
  v7 = 0;
  __asm { bswap   eax }
  v3 = *(_DWORD *)(a1 + 8);
  v2 = *(_DWORD *)(a1 + 4);
  v8 = _EAX;
  if ( (unsigned int)(v3 - v2) <= 4 )
  {
    sub_8056580(a1 + 4, v3, 4 - (v3 - v2), &v7);
    v2 = *(_DWORD *)(v4 + 4);
  }
  else
  {
    *(_DWORD *)(a1 + 8) = v2 + 4;
  }
  result = v8;
  *(_DWORD *)v2 = v8;
  return result;
}

//----- (080525A0) --------------------------------------------------------
int __cdecl sub_80525A0(int a1, __int16 a2)
{
  int v2; // edx@1
  int v3; // ebx@1
  int v4; // esi@1
  int result; // eax@3
  unsigned __int16 v6; // ax@1
  char v7; // [sp+1Fh] [bp-9h]@1
  unsigned __int16 v8; // [sp+1Ch] [bp-Ch]@1

  v4 = a1;
  v7 = 0;
  v6 = __ROR__(a2, 8);
  v3 = *(_DWORD *)(a1 + 8);
  v2 = *(_DWORD *)(a1 + 4);
  v8 = v6;
  if ( (unsigned int)(v3 - v2) <= 2 )
  {
    sub_8056580(a1 + 4, v3, 2 - (v3 - v2), &v7);
    v2 = *(_DWORD *)(v4 + 4);
  }
  else
  {
    *(_DWORD *)(a1 + 8) = v2 + 2;
  }
  result = v8;
  *(_WORD *)v2 = v8;
  return result;
}

//----- (08052610) --------------------------------------------------------
int __cdecl sub_8052610(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ecx@1
  int v5; // ebx@1
  int v6; // edi@1
  int v7; // esi@1
  int result; // eax@2
  int v9; // eax@1
  int v10; // ebx@2
  int v11; // ebx@2
  __int16 v12; // ax@2
  int v13; // ebx@2
  int v14; // [sp+18h] [bp-20h]@1
  int v15; // [sp+14h] [bp-24h]@1
  char v16; // [sp+2Bh] [bp-Dh]@3

  v7 = a1;
  v6 = a2;
  v3 = *(_DWORD *)a2;
  v5 = *(_DWORD *)(*(_DWORD *)a1 - 12);
  v9 = *(_DWORD *)(a2 + 4);
  v14 = *(_DWORD *)(a2 + 4);
  v15 = v9 - v3;
  v4 = a3 + v5 + *(_BYTE *)(a1 + 9) + 6;
  if ( v4 > (unsigned int)(v9 - v3) )
  {
    v16 = 0;
    sub_8056580(a2, v14, v4 - v15, &v16);
    v3 = *(_DWORD *)v6;
    v5 = *(_DWORD *)(*(_DWORD *)v7 - 12);
  }
  *(_BYTE *)(v3 + a3) = v5;
  v10 = a3 + 1;
  memcpy((void *)(*(_DWORD *)v6 + a3 + 1), *(const void **)v7, *(_DWORD *)(*(_DWORD *)v7 - 12));
  v11 = *(_DWORD *)(*(_DWORD *)v7 - 12) + v10;
  *(_BYTE *)(*(_DWORD *)v6 + v11) = *(_BYTE *)(v7 + 4);
  v12 = __ROR__(*(_WORD *)(v7 + 6), 8);
  *(_WORD *)(v11 + *(_DWORD *)v6 + 1) = v12;
  *(_BYTE *)(*(_DWORD *)v6 + v11 + 3) = *(_BYTE *)(v7 + 8);
  *(_BYTE *)(*(_DWORD *)v6 + v11 + 4) = *(_BYTE *)(v7 + 9);
  v13 = *(_DWORD *)v6 + v11 + 5;
  *(_DWORD *)v13 = *(_DWORD *)(v7 + 10);
  *(_DWORD *)(v13 + 4) = *(_DWORD *)(v7 + 14);
  *(_DWORD *)(v13 + 8) = *(_DWORD *)(v7 + 18);
  result = *(_DWORD *)(v7 + 22);
  *(_DWORD *)(v13 + 12) = *(_DWORD *)(v7 + 22);
  return result;
}

//----- (080526F0) --------------------------------------------------------
int __cdecl sub_80526F0(int a1, int a2, int a3)
{
  int v3; // ecx@1
  int v4; // ebx@1
  int v5; // edi@1
  int v6; // esi@1
  int result; // eax@2
  __int16 v8; // ax@2
  char v10; // [sp+2Bh] [bp-Dh]@3

  v4 = a2;
  v6 = a3;
  v5 = *(_DWORD *)(a2 + 4);
  v3 = *(_DWORD *)(a2 + 4) - *(_DWORD *)a2;
  if ( a3 + 16 > (unsigned int)v3 )
  {
    v10 = 0;
    sub_8056580(a2, v5, a3 + 16 - v3, &v10);
  }
  v8 = __ROR__(*(_WORD *)a1, 8);
  *(_WORD *)(*(_DWORD *)v4 + v6) = v8;
  __asm { bswap   eax }
  *(_DWORD *)(v6 + *(_DWORD *)v4 + 2) = _EAX;
  LOWORD(_EAX) = __ROR__(*(_WORD *)(a1 + 8), 8);
  *(_WORD *)(v6 + *(_DWORD *)v4 + 6) = _EAX;
  LOWORD(_EAX) = __ROR__(*(_WORD *)(a1 + 10), 8);
  *(_WORD *)(v6 + *(_DWORD *)v4 + 8) = _EAX;
  LOWORD(_EAX) = __ROR__(*(_WORD *)(a1 + 12), 8);
  *(_WORD *)(v6 + *(_DWORD *)v4 + 10) = _EAX;
  LOWORD(_EAX) = __ROR__(*(_WORD *)(a1 + 14), 8);
  *(_WORD *)(v6 + *(_DWORD *)v4 + 12) = _EAX;
  *(_BYTE *)(*(_DWORD *)v4 + v6 + 14) = 0;
  result = *(_DWORD *)v4;
  *(_BYTE *)(*(_DWORD *)v4 + v6 + 15) = 0;
  return result;
}

//----- (080527D0) --------------------------------------------------------
void *__cdecl sub_80527D0(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ebx@1
  int v5; // edi@1
  int v6; // esi@1
  void *result; // eax@2
  int v8; // edx@2
  const void *v9; // ecx@2
  int v11; // eax@2
  __int16 v12; // dx@2
  __int16 v13; // bx@2
  __int16 v14; // cx@2
  int v15; // [sp+18h] [bp-20h]@1
  void *v16; // [sp+20h] [bp-18h]@2
  __int16 v17; // [sp+28h] [bp-10h]@2
  __int16 v18; // [sp+26h] [bp-12h]@2
  __int16 v19; // [sp+24h] [bp-14h]@2
  char v20; // [sp+2Bh] [bp-Dh]@5

  v5 = a2;
  v6 = a1;
  v4 = *(_DWORD *)(a2 + 4);
  v15 = *(_DWORD *)(a2 + 4) - *(_DWORD *)a2;
  v3 = *(_DWORD *)(a1 + 16) - *(_DWORD *)(a1 + 12) + a3 + 10;
  if ( v3 > (unsigned int)v15 )
  {
    v20 = 0;
    sub_8056580(a2, v4, v3 - v15, &v20);
  }
  __asm { bswap   eax }
  v16 = _EAX;
  v11 = *(_DWORD *)v5 + a3;
  v12 = *(_WORD *)(v6 + 4);
  v13 = __ROR__(*(_WORD *)v6, 8);
  v14 = __ROR__(*(_WORD *)(v6 + 2), 8);
  v17 = v13;
  v18 = v14;
  v12 = __ROR__(v12, 8);
  v19 = v12;
  *(_WORD *)v11 = v13;
  *(_WORD *)(*(_DWORD *)v5 + a3 + 2) = v18;
  *(_WORD *)(*(_DWORD *)v5 + a3 + 4) = v19;
  result = v16;
  *(_DWORD *)(*(_DWORD *)v5 + a3 + 6) = v16;
  v8 = *(_DWORD *)(v6 + 16);
  v9 = *(const void **)(v6 + 12);
  if ( v8 != (_DWORD)v9 )
    result = memcpy((void *)(*(_DWORD *)v5 + a3 + 10), v9, v8 - (_DWORD)v9);
  return result;
}

//----- (080528B0) --------------------------------------------------------
void *__cdecl sub_80528B0(int a1, int a2, int a3)
{
  int v3; // eax@1
  int v4; // edx@1
  int v5; // ebx@1
  int v6; // edi@1
  int v7; // esi@1
  void *result; // eax@2
  const void *v9; // edx@2
  int v10; // ecx@2
  __int16 v11; // dx@2
  unsigned __int16 v12; // ax@2
  int v13; // eax@2
  int v14; // [sp+18h] [bp-20h]@1
  unsigned __int16 v15; // [sp+26h] [bp-12h]@2
  __int16 v16; // [sp+28h] [bp-10h]@2
  char v17; // [sp+2Bh] [bp-Dh]@5

  v6 = a2;
  v5 = a1;
  v7 = *(_DWORD *)(a2 + 4);
  v14 = *(_DWORD *)(a2 + 4) - *(_DWORD *)a2;
  v3 = *(_DWORD *)(a1 + 8) - *(_DWORD *)(a1 + 4);
  v4 = v3 + a3 + 4;
  if ( v4 > (unsigned int)v14 )
  {
    v17 = 0;
    sub_8056580(a2, v7, v4 - v14, &v17);
    v3 = *(_DWORD *)(v5 + 8) - *(_DWORD *)(v5 + 4);
  }
  v11 = *(_WORD *)v5;
  v12 = __ROR__(v3, 8);
  v15 = v12;
  v13 = *(_DWORD *)v6 + a3;
  v11 = __ROR__(v11, 8);
  v16 = v11;
  *(_WORD *)v13 = v11;
  result = (void *)v15;
  *(_WORD *)(*(_DWORD *)v6 + a3 + 2) = v15;
  v10 = *(_DWORD *)(v5 + 8);
  v9 = *(const void **)(v5 + 4);
  if ( v10 != (_DWORD)v9 )
    result = memcpy((void *)(*(_DWORD *)v6 + a3 + 4), v9, v10 - (_DWORD)v9);
  return result;
}

//----- (08052970) --------------------------------------------------------
int __cdecl sub_8052970(int a1, int a2, int a3)
{
  int result; // eax@1
  int v4; // edx@1
  int v5; // edi@1
  unsigned int v6; // esi@2
  unsigned int v7; // ebx@3

  v5 = a3;
  v4 = *(_DWORD *)(a1 + 20);
  result = (*(_DWORD *)(a1 + 24) - v4) >> 4;
  if ( result )
  {
    v6 = 0;
    do
    {
      v7 = v6++;
      v7 *= 16;
      sub_80528B0(v4 + v7, a2, v5);
      v4 = *(_DWORD *)(a1 + 20);
      v5 += *(_DWORD *)(v4 + v7 + 8) - *(_DWORD *)(v4 + v7 + 4) + 4;
      result = (*(_DWORD *)(a1 + 24) - v4) >> 4;
    }
    while ( v6 < result );
  }
  return result;
}

//----- (080529E0) --------------------------------------------------------
int __cdecl sub_80529E0(int a1, int a2, int a3)
{
  int result; // eax@1
  int v4; // edx@1
  int v5; // edi@1
  unsigned int v6; // esi@2
  unsigned int v7; // ebx@3

  v5 = a3;
  v4 = *(_DWORD *)(a1 + 4);
  result = (*(_DWORD *)(a1 + 8) - v4) >> 4;
  if ( result )
  {
    v6 = 0;
    do
    {
      v7 = v6++;
      v7 *= 16;
      sub_80528B0(v4 + v7, a2, v5);
      v4 = *(_DWORD *)(a1 + 4);
      v5 += *(_DWORD *)(v4 + v7 + 8) - *(_DWORD *)(v4 + v7 + 4) + 4;
      result = (*(_DWORD *)(a1 + 8) - v4) >> 4;
    }
    while ( v6 < result );
  }
  return result;
}

//----- (08052A50) --------------------------------------------------------
int __cdecl sub_8052A50(int a1, int a2, int a3)
{
  return sub_80529E0(a1, a2, a3);
}

//----- (08052A60) --------------------------------------------------------
int __cdecl sub_8052A60(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ecx@1
  int v5; // ebx@1
  int v6; // edi@1
  int v7; // esi@1
  char v9; // [sp+2Bh] [bp-Dh]@3

  v6 = a2;
  v5 = a3;
  v4 = *(_DWORD *)(a2 + 4);
  v7 = a3 + 4;
  v3 = *(_DWORD *)(a2 + 4) - *(_DWORD *)a2;
  if ( a3 + 4 > (unsigned int)v3 )
  {
    v9 = 0;
    sub_8056580(a2, v4, v7 - v3, &v9);
  }
  *(_DWORD *)(*(_DWORD *)v6 + v5) = 16777216;
  return sub_80529E0(a1, v6, v7);
}

//----- (08052AE0) --------------------------------------------------------
void *__cdecl sub_8052AE0(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ecx@1
  int v5; // ebx@1
  int v6; // edi@1
  int v7; // esi@1
  int v9; // ecx@1
  int v10; // edx@2
  int v11; // edx@2
  __int16 v12; // ax@2
  int v13; // [sp+18h] [bp-20h]@1
  __int16 v14; // [sp+28h] [bp-10h]@2
  char v15; // [sp+2Bh] [bp-Dh]@3

  v5 = a2;
  v7 = a1;
  v6 = a3;
  v9 = *(_DWORD *)(a2 + 4);
  v13 = *(_DWORD *)(a2 + 4);
  v4 = v9 - *(_DWORD *)a2;
  v3 = a3 + *(_DWORD *)(*(_DWORD *)(a1 + 16) - 12) + 11;
  if ( v3 > (unsigned int)v4 )
  {
    v15 = 0;
    sub_8056580(a2, v13, v3 - v4, &v15);
  }
  v10 = *(_DWORD *)v5 + v6;
  *(_DWORD *)v10 = *(_DWORD *)(v7 + 4);
  *(_DWORD *)(v10 + 4) = *(_DWORD *)(v7 + 8);
  v11 = *(_DWORD *)v5;
  v12 = __ROR__(*(_WORD *)(v7 + 12), 8);
  v14 = v12;
  *(_WORD *)(v6 + v11 + 8) = v12;
  *(_BYTE *)(*(_DWORD *)v5 + v6 + 10) = *(_DWORD *)(*(_DWORD *)(v7 + 16) - 12);
  return memcpy((void *)(*(_DWORD *)v5 + v6 + 11), *(const void **)(v7 + 16), *(_DWORD *)(*(_DWORD *)(v7 + 16) - 12));
}

//----- (08052B90) --------------------------------------------------------
int __cdecl sub_8052B90(int a1, int a2, int a3)
{
  int v4; // ebx@1
  int v5; // esi@1
  int v6; // edi@1
  int v7; // eax@1

  v4 = a3;
  v5 = a1;
  v6 = a2;
  sub_8052AE0(a1, a2, a3);
  v7 = *(_DWORD *)(*(_DWORD *)(v5 + 16) - 12);
  a2 = v6;
  a1 = v5;
  a3 = v4 + v7 + 11;
  return sub_8052970(a1, a2, a3);
}

//----- (08052BE0) --------------------------------------------------------
void *__cdecl sub_8052BE0(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ecx@1
  int v5; // ebx@1
  int v6; // edi@1
  int v7; // esi@1
  int v8; // edx@2
  int v9; // ecx@2
  int v10; // ebx@2
  int v11; // edx@3
  int v12; // ecx@3
  int v13; // esi@3
  int v14; // edx@5
  int v15; // ecx@5
  int v16; // ebx@5
  unsigned int v17; // eax@7
  int v18; // edx@7
  int v19; // edx@9
  int v20; // ecx@9
  int v21; // esi@9
  int v22; // edx@11
  int v23; // ecx@11
  int v24; // esi@11
  int v25; // edx@12
  int v26; // ecx@12
  int v27; // ebx@12
  int v28; // edx@13
  int v29; // ecx@13
  int v30; // esi@13
  int v31; // edx@14
  int v32; // ecx@14
  int v33; // ebx@14
  int v34; // edx@15
  size_t v35; // ecx@15
  int v36; // ebx@15
  int v37; // esi@15
  void *result; // eax@17
  int v39; // ebx@17
  int v40; // esi@29
  int v41; // ebx@30
  int v42; // edx@31
  int v43; // esi@32
  int v44; // esi@36
  int v45; // edx@37
  int v46; // ecx@37
  int v47; // ebx@37
  int v48; // esi@39
  int v49; // ebx@40
  int v50; // edx@41
  int v51; // ecx@41
  int v52; // esi@41
  int v53; // edx@43
  int v54; // ecx@43
  int v55; // ebx@43
  int v56; // esi@43
  int v57; // ebx@45
  int v58; // esi@46
  int v59; // edx@47
  int v60; // ecx@47
  int v61; // ebx@47
  int v62; // eax@5
  int v63; // edx@14
  int v64; // eax@14
  int v65; // esi@17
  int v66; // ecx@39
  int v67; // edx@39
  int v68; // edx@40
  int v69; // eax@45
  int v70; // eax@45
  __int16 v71; // [sp+3Ah] [bp-Eh]@1
  size_t v72; // [sp+30h] [bp-18h]@3
  int v73; // [sp+14h] [bp-34h]@9
  int v74; // [sp+18h] [bp-30h]@14
  unsigned __int16 v75; // [sp+38h] [bp-10h]@14
  __int16 v76; // [sp+36h] [bp-12h]@36
  size_t v77; // [sp+2Ch] [bp-1Ch]@40
  size_t v78; // [sp+28h] [bp-20h]@45
  int v79; // [sp+24h] [bp-24h]@45

  v6 = a2;
  v5 = a3;
  v71 = 27;
  v4 = *(_DWORD *)(a2 + 4);
  v7 = a3 + 2;
  v3 = *(_DWORD *)(a2 + 4) - *(_DWORD *)a2;
  if ( a3 + 2 > (unsigned int)v3 )
  {
    LOBYTE(v72) = 0;
    sub_8056580(a2, v4, v7 - v3, &v72);
  }
  *(_WORD *)(*(_DWORD *)v6 + v5) = v71;
  v9 = *(_DWORD *)(v6 + 4);
  v10 = v7 + 2;
  v8 = *(_DWORD *)(v6 + 4) - *(_DWORD *)v6;
  if ( v7 + 2 > (unsigned int)v8 )
  {
    LOBYTE(v72) = 0;
    sub_8056580(v6, v9, v10 - v8, &v72);
  }
  *(_WORD *)(*(_DWORD *)v6 + v7) = *(_WORD *)a1;
  v13 = v7 + 18;
  LOBYTE(v72) = 0;
  v12 = *(_DWORD *)(v6 + 4);
  v11 = v12 - *(_DWORD *)v6;
  if ( v10 + 16 >= (unsigned int)v11 )
    sub_8056580(v6, v12, v13 - v11, &v72);
  else
    *(_DWORD *)(v6 + 4) = v13 + *(_DWORD *)v6;
  v62 = *(_DWORD *)v6 + v10;
  v16 = v10 + 41;
  *(_DWORD *)v62 = 0;
  *(_DWORD *)(v62 + 4) = 0;
  *(_DWORD *)(v62 + 8) = 0;
  *(_DWORD *)(v62 + 12) = 0;
  LOBYTE(v72) = 0;
  v15 = *(_DWORD *)(v6 + 4);
  v14 = v15 - *(_DWORD *)v6;
  if ( v13 + 25 >= (unsigned int)v14 )
    sub_8056580(v6, v15, v16 - v14, &v72);
  else
    *(_DWORD *)(v6 + 4) = v16 + *(_DWORD *)v6;
  v17 = 0;
  v18 = *(_DWORD *)v6 + v13;
  do
  {
    *(_DWORD *)(v18 + v17) = 0;
    v17 += 4;
  }
  while ( v17 < 0x18 );
  *(_BYTE *)(v18 + v17) = 0;
  *(_BYTE *)(*(_DWORD *)v6 + v13 + 2) = 3;
  *(_BYTE *)(*(_DWORD *)v6 + v13 + 6) = 4;
  *(_BYTE *)(*(_DWORD *)v6 + v13 + 9) = 14;
  v20 = *(_DWORD *)(v6 + 4);
  v21 = v13 + 26;
  v73 = v16 + 1;
  v19 = v20 - *(_DWORD *)v6;
  if ( v16 + 1 > (unsigned int)v19 )
  {
    LOBYTE(v72) = 0;
    sub_8056580(v6, v20, v21 - v19, &v72);
  }
  *(_BYTE *)(*(_DWORD *)v6 + v16) = *(_BYTE *)(a1 + 4);
  v23 = *(_DWORD *)(v6 + 4);
  v22 = *(_DWORD *)(v6 + 4) - *(_DWORD *)v6;
  v24 = v73 + 1;
  if ( v73 + 1 > (unsigned int)v22 )
  {
    LOBYTE(v72) = 0;
    sub_8056580(v6, v23, v24 - v22, &v72);
  }
  v73 += *(_DWORD *)v6;
  *(_BYTE *)v73 = *(_BYTE *)(a1 + 5);
  v26 = *(_DWORD *)(v6 + 4);
  v27 = v24 + 2;
  v25 = *(_DWORD *)(v6 + 4) - *(_DWORD *)v6;
  if ( v24 + 2 > (unsigned int)v25 )
  {
    LOBYTE(v72) = 0;
    sub_8056580(v6, v26, v27 - v25, &v72);
  }
  *(_WORD *)(*(_DWORD *)v6 + v24) = *(_WORD *)(a1 + 6);
  v29 = *(_DWORD *)(v6 + 4);
  v30 = v24 + 4;
  v28 = *(_DWORD *)(v6 + 4) - *(_DWORD *)v6;
  if ( v27 + 2 > (unsigned int)v28 )
  {
    LOBYTE(v72) = 0;
    sub_8056580(v6, v29, v30 - v28, &v72);
  }
  v63 = a1;
  *(_WORD *)(*(_DWORD *)v6 + v27) = *(_WORD *)(a1 + 8);
  v64 = *(_DWORD *)(v63 + 12);
  v33 = v27 + 4;
  v32 = *(_DWORD *)(v6 + 4);
  v74 = v30 + 2;
  v31 = v32 - *(_DWORD *)v6;
  v75 = *(_WORD *)(v64 - 12) + 1;
  if ( v30 + 2 > (unsigned int)v31 )
  {
    LOBYTE(v72) = 0;
    sub_8056580(v6, v32, v33 - v31, &v72);
  }
  *(_WORD *)(*(_DWORD *)v6 + v30) = v75;
  v35 = v75;
  LOBYTE(v72) = 0;
  v37 = *(_DWORD *)(v6 + 4);
  v34 = v75 + v74;
  v36 = v37 - *(_DWORD *)v6;
  if ( v34 >= (unsigned int)v36 )
  {
    sub_8056580(v6, v37, v34 - v36, &v72);
    v35 = v75;
  }
  else
  {
    *(_DWORD *)(v6 + 4) = v34 + *(_DWORD *)v6;
  }
  v65 = a1;
  memcpy((void *)(*(_DWORD *)v6 + v74), *(const void **)(a1 + 12), v35);
  v39 = v75 + v74;
  result = (void *)*(_BYTE *)(v65 + 4);
  if ( (_BYTE)result == 1 )
  {
    v40 = v39 + 4;
    if ( v39 + 4 > (unsigned int)(*(_DWORD *)(v6 + 4) - *(_DWORD *)v6) )
      sub_8056790(v6, v39 + 4, 0);
    *(_DWORD *)(*(_DWORD *)v6 + v39) = *(_DWORD *)(a1 + 16);
    v41 = v39 + 8;
    if ( v40 + 4 > (unsigned int)(*(_DWORD *)(v6 + 4) - *(_DWORD *)v6) )
      sub_8056790(v6, v40 + 4, 0);
    v42 = a1;
    *(_DWORD *)(*(_DWORD *)v6 + v40) = *(_DWORD *)(a1 + 20);
    result = *(void **)(*(_DWORD *)(v42 + 24) - 12);
    if ( result )
    {
      v72 = *(_DWORD *)(*(_DWORD *)(v42 + 24) - 12);
      v43 = v41 + 4;
      if ( v41 + 4 > (unsigned int)(*(_DWORD *)(v6 + 4) - *(_DWORD *)v6) )
        sub_8056790(v6, v41 + 4, 0);
      *(_DWORD *)(*(_DWORD *)v6 + v41) = v72;
      if ( v72 + v43 > *(_DWORD *)(v6 + 4) - *(_DWORD *)v6 )
        sub_8056790(v6, v72 + v43, 0);
      result = memcpy((void *)(*(_DWORD *)v6 + v43), *(const void **)(a1 + 24), v72);
    }
  }
  else
  {
    if ( (_BYTE)result == 26 )
    {
      v44 = v39 + 2;
      v76 = *(_WORD *)(*(_DWORD *)(a1 + 48) - 12) + 37;
      if ( v39 + 2 > (unsigned int)(*(_DWORD *)(v6 + 4) - *(_DWORD *)v6) )
        sub_8056790(v6, v39 + 2, 0);
      *(_WORD *)(*(_DWORD *)v6 + v39) = v76;
      v47 = v39 + 18;
      LOBYTE(v72) = 0;
      v46 = *(_DWORD *)(v6 + 4);
      v45 = v46 - *(_DWORD *)v6;
      if ( v44 + 16 >= (unsigned int)v45 )
        sub_8056580(v6, v46, v47 - v45, &v72);
      else
        *(_DWORD *)(v6 + 4) = v47 + *(_DWORD *)v6;
      v66 = *(_DWORD *)v6 + v44;
      v48 = v44 + 18;
      v67 = a1 + 28;
      *(_DWORD *)v66 = *(_DWORD *)(a1 + 28);
      *(_DWORD *)(v66 + 4) = *(_DWORD *)(v67 + 4);
      *(_DWORD *)(v66 + 8) = *(_DWORD *)(v67 + 8);
      *(_DWORD *)(v66 + 12) = *(_DWORD *)(v67 + 12);
      if ( v47 + 2 > (unsigned int)(*(_DWORD *)(v6 + 4) - *(_DWORD *)v6) )
        sub_8056790(v6, v47 + 2, 0);
      v68 = a1;
      *(_WORD *)(*(_DWORD *)v6 + v47) = *(_WORD *)(a1 + 44);
      v49 = v47 + 6;
      v77 = *(_DWORD *)(*(_DWORD *)(v68 + 48) - 12);
      if ( v48 + 4 > (unsigned int)(*(_DWORD *)(v6 + 4) - *(_DWORD *)v6) )
        sub_8056790(v6, v48 + 4, 0);
      *(_DWORD *)(*(_DWORD *)v6 + v48) = v77;
      LOBYTE(v72) = 0;
      v52 = *(_DWORD *)(v6 + 4);
      v50 = v77 + v49;
      v51 = v52 - *(_DWORD *)v6;
      if ( v77 + v49 >= v51 )
        sub_8056580(v6, v52, v50 - v51, &v72);
      else
        *(_DWORD *)(v6 + 4) = v50 + *(_DWORD *)v6;
      memcpy((void *)(*(_DWORD *)v6 + v49), *(const void **)(a1 + 48), v77);
      LOBYTE(v72) = 0;
      v54 = *(_DWORD *)(v6 + 4);
      v55 = v77 + v49;
      v56 = v55 + 15;
      v53 = v54 - *(_DWORD *)v6;
      if ( v55 + 15 >= (unsigned int)v53 )
        sub_8056580(v6, v54, v56 - v53, &v72);
      else
        *(_DWORD *)(v6 + 4) = v56 + *(_DWORD *)v6;
      v69 = *(_DWORD *)v6 + v55;
      *(_DWORD *)v69 = 0;
      *(_DWORD *)(v69 + 4) = 0;
      *(_DWORD *)(v69 + 8) = 0;
      *(_WORD *)(v69 + 12) = 0;
      *(_BYTE *)(v69 + 14) = 0;
      *(_BYTE *)(*(_DWORD *)v6 + v55 + 2) = 1;
      v57 = v55 + 19;
      v70 = *(_DWORD *)(*(_DWORD *)(a1 + 52) - 12);
      v78 = *(_DWORD *)(*(_DWORD *)(a1 + 52) - 12);
      v79 = v70 + 4;
      if ( v56 + 4 > (unsigned int)(*(_DWORD *)(v6 + 4) - *(_DWORD *)v6) )
        sub_8056790(v6, v56 + 4, 0);
      *(_DWORD *)(*(_DWORD *)v6 + v56) = v79;
      v58 = v56 + 8;
      if ( v57 + 4 > (unsigned int)(*(_DWORD *)(v6 + 4) - *(_DWORD *)v6) )
        sub_8056790(v6, v57 + 4, 0);
      *(_DWORD *)(*(_DWORD *)v6 + v57) = v78;
      LOBYTE(v72) = 0;
      v61 = *(_DWORD *)(v6 + 4);
      v59 = v78 + v58;
      v60 = v61 - *(_DWORD *)v6;
      if ( v78 + v58 >= v60 )
        sub_8056580(v6, v61, v59 - v60, &v72);
      else
        *(_DWORD *)(v6 + 4) = v59 + *(_DWORD *)v6;
      result = memcpy((void *)(*(_DWORD *)v6 + v58), *(const void **)(a1 + 52), v78);
    }
  }
  return result;
}

//----- (08053310) --------------------------------------------------------
int __cdecl sub_8053310(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ecx@1
  int v5; // ebx@1
  int v6; // esi@1
  unsigned __int16 v7; // ax@2
  size_t v8; // ecx@3
  unsigned int v9; // ebx@3
  int v10; // edi@3
  int v11; // edx@5
  int v12; // ecx@5
  int v13; // edi@5
  int v14; // edx@6
  int v15; // ecx@6
  int v16; // ebx@6
  int v17; // edx@7
  int v18; // ecx@7
  int v19; // eax@8
  int v20; // esi@8
  unsigned int v21; // ecx@9
  int v22; // ebx@9
  int v23; // edx@11
  int v24; // ecx@11
  int v25; // edi@11
  int result; // eax@12
  int v27; // edx@12
  unsigned int v28; // esi@13
  unsigned __int16 *v29; // ecx@2
  int v30; // ebx@2
  __int16 v31; // ax@2
  int v32; // ebx@4
  int v33; // ebx@6
  int v34; // esi@6
  __int16 v35; // ax@6
  int v36; // edi@7
  __int16 v37; // ax@7
  int v38; // ecx@8
  int v39; // ebx@8
  __int16 v40; // ax@8
  int v41; // eax@8
  unsigned int v42; // edx@10
  __int16 v43; // ax@12
  unsigned int v44; // ebx@14
  __int16 v45; // [sp+28h] [bp-10h]@2
  __int16 v46; // [sp+26h] [bp-12h]@6
  __int16 v47; // [sp+24h] [bp-14h]@7
  int v48; // [sp+18h] [bp-20h]@7
  __int16 v49; // [sp+22h] [bp-16h]@8
  __int16 v50; // [sp+20h] [bp-18h]@12
  char v51; // [sp+2Bh] [bp-Dh]@16

  v5 = a3;
  v4 = *(_DWORD *)(a2 + 4);
  v6 = a3 + 2;
  v3 = *(_DWORD *)(a2 + 4) - *(_DWORD *)a2;
  if ( a3 + 2 > (unsigned int)v3 )
  {
    v51 = 0;
    sub_8056580(a2, v4, v6 - v3, &v51);
  }
  v29 = (unsigned __int16 *)a1;
  v30 = *(_DWORD *)a2 + v5;
  v31 = *(_DWORD *)(*(_DWORD *)(a1 + 4) - 12);
  *(_WORD *)a1 = v31;
  v31 = __ROR__(v31, 8);
  v45 = v31;
  *(_WORD *)v30 = v31;
  v7 = *v29;
  if ( *v29 )
  {
    v8 = v7;
    v10 = *(_DWORD *)(a2 + 4);
    v9 = *(_DWORD *)(a2 + 4) - *(_DWORD *)a2;
    if ( v6 + (unsigned int)v7 > v9 )
    {
      v51 = 0;
      sub_8056580(a2, v10, v6 + v7 - v9, &v51);
      v8 = *(_WORD *)a1;
    }
    v32 = a1;
    memcpy((void *)(*(_DWORD *)a2 + v6), *(const void **)(a1 + 4), v8);
    v6 += *(_WORD *)v32;
  }
  v13 = v6 + 2;
  v12 = *(_DWORD *)(a2 + 4);
  v11 = *(_DWORD *)(a2 + 4) - *(_DWORD *)a2;
  if ( v6 + 2 > (unsigned int)v11 )
  {
    v51 = 0;
    sub_8056580(a2, v12, v13 - v11, &v51);
  }
  v33 = a2;
  v34 = *(_DWORD *)a2 + v6;
  v35 = __ROR__(*(_WORD *)(a1 + 8), 8);
  v46 = v35;
  *(_WORD *)v34 = v35;
  v15 = *(_DWORD *)(v33 + 4);
  v14 = *(_DWORD *)(v33 + 4) - *(_DWORD *)v33;
  v16 = v13 + 2;
  if ( v13 + 2 > (unsigned int)v14 )
  {
    v51 = 0;
    sub_8056580(a2, v15, v16 - v14, &v51);
  }
  v36 = *(_DWORD *)a2 + v13;
  v37 = __ROR__(*(_WORD *)(a1 + 10), 8);
  v47 = v37;
  *(_WORD *)v36 = v37;
  v18 = *(_DWORD *)(a2 + 4);
  v17 = *(_DWORD *)(a2 + 4) - *(_DWORD *)a2;
  v48 = v16 + 2;
  if ( v16 + 2 > (unsigned int)v17 )
  {
    v51 = 0;
    sub_8056580(a2, v18, v48 - v17, &v51);
  }
  v38 = a1;
  v39 = *(_DWORD *)a2 + v16;
  v40 = __ROR__(*(_WORD *)(a1 + 12), 8);
  v49 = v40;
  *(_WORD *)v39 = v40;
  v20 = *(_DWORD *)(v38 + 16);
  v41 = *(_DWORD *)(v38 + 20);
  *(_WORD *)(v38 + 14) = 0;
  v19 = (v41 - v20) >> 4;
  if ( v19 )
  {
    v21 = 0;
    v22 = 0;
    do
    {
      v42 = v21++;
      v22 += *(_DWORD *)(v20 + 16 * v42 + 8) - *(_DWORD *)(v20 + 16 * v42 + 4) + 4;
      *(_WORD *)(a1 + 14) = v22;
    }
    while ( v21 < v19 );
  }
  v24 = *(_DWORD *)(a2 + 4);
  v25 = v48 + 2;
  v23 = *(_DWORD *)(a2 + 4) - *(_DWORD *)a2;
  if ( v48 + 2 > (unsigned int)v23 )
  {
    v51 = 0;
    sub_8056580(a2, v24, v25 - v23, &v51);
  }
  v48 += *(_DWORD *)a2;
  v43 = __ROR__(*(_WORD *)(a1 + 14), 8);
  v50 = v43;
  *(_WORD *)v48 = v43;
  v27 = *(_DWORD *)(a1 + 16);
  result = (*(_DWORD *)(a1 + 20) - v27) >> 4;
  if ( result )
  {
    v28 = 0;
    do
    {
      v44 = v28++;
      v44 *= 16;
      sub_80528B0(v27 + v44, a2, v25);
      v27 = *(_DWORD *)(a1 + 16);
      v25 += *(_DWORD *)(v27 + v44 + 8) - *(_DWORD *)(v27 + v44 + 4) + 4;
      result = (*(_DWORD *)(a1 + 20) - v27) >> 4;
    }
    while ( v28 < result );
  }
  return result;
}

//----- (080535F0) --------------------------------------------------------
signed int __cdecl sub_80535F0(int a1)
{
  int v1; // ebx@1
  int v2; // eax@5
  int v3; // eax@6
  int v4; // edi@6
  int v5; // esi@6
  int v6; // eax@7
  int v7; // eax@8
  int v8; // edi@8
  int v9; // esi@8
  int v10; // eax@9
  int v11; // eax@10
  int v12; // edi@10
  int v13; // esi@10
  int v14; // eax@11
  int v15; // eax@12
  int v16; // esi@12
  signed int v17; // ebx@13
  char v19; // [sp+28h] [bp-10h]@7
  const char *v20; // [sp+24h] [bp-14h]@9
  char v21; // [sp+20h] [bp-18h]@11
  char v22; // [sp+1Ch] [bp-1Ch]@13

  v1 = a1 + 52;
  if ( std__string__find(a1 + 52, "<NR>", 0, 4) == -1
    || std__string__find(v1, "</NR>", 0, 5) == -1
    || std__string__find(v1, "<RES>", 0, 5) == -1
    || std__string__find(v1, "</RES>", 0, 6) == -1
    || (v2 = std__string__find(v1, "&lt;uin&gt;", 0), v2 == -1)
    || (v5 = v2 + 11, v3 = std__string__find(v1, "&lt;/uin&gt;", v2 + 11), v4 = v3, v3 == -1)
    || (std__string__string(&v19, v1, v5, v3 - v5), std__string__assign(a1 + 56, &v19), std__string___string(&v19), v6 = std__string__find(v1, "&lt;index&gt;", v4 + 12), v6 == -1)
    || (v9 = v6 + 13, v7 = std__string__find(v1, "&lt;/index&gt;", v6 + 13), v8 = v7, v7 == -1) )
  {
    v17 = 0;
  }
  else
  {
    std__string__string(&v20, v1, v9, v7 - v9);
    *(_DWORD *)(a1 + 60) = strtol(v20, 0, 10);
    v10 = std__string__find(v1, "&lt;title&gt;", v8 + 14);
    if ( v10 == -1
      || (v13 = v10 + 13, v11 = std__string__find(v1, "&lt;/title&gt;", v10 + 13), v12 = v11, v11 == -1)
      || (std__string__string(&v21, v1, v13, v11 - v13), std__string__assign(a1 + 64, &v21), std__string___string(&v21), v14 = std__string__find(v1, "&lt;desc&gt;", v12 + 14), v14 == -1)
      || (v16 = v14 + 12, v15 = std__string__find(v1, "&lt;/desc&gt;", v14 + 12), v15 == -1) )
    {
      v17 = 0;
    }
    else
    {
      std__string__string(&v22, v1, v16, v15 - v16);
      std__string__assign(a1 + 68, &v22);
      std__string___string(&v22);
      v17 = 1;
    }
    std__string___string(&v20);
  }
  return v17;
}

//----- (080538E0) --------------------------------------------------------
signed int __cdecl sub_80538E0(int a1)
{
  int v1; // ebx@1
  int v2; // eax@5
  int v3; // eax@6
  int v4; // edi@6
  int v5; // esi@6
  int v6; // eax@8
  int v7; // eax@9
  int v8; // edi@9
  int v9; // esi@9
  int v10; // eax@11
  int v11; // eax@12
  int v12; // edi@12
  int v13; // esi@12
  int v14; // eax@14
  int v15; // eax@15
  int v16; // esi@15
  signed int v17; // ebx@16
  char v19; // [sp+28h] [bp-10h]@7
  char v20; // [sp+24h] [bp-14h]@10
  char v21; // [sp+20h] [bp-18h]@13
  char v22; // [sp+1Ch] [bp-1Ch]@16

  v1 = a1 + 52;
  if ( std__string__find(a1 + 52, "<QUERY>", 0, 7) == -1
    || std__string__find(v1, "</QUERY>", 0, 8) == -1
    || std__string__find(v1, "<NOTIFY>", 0, 8) == -1
    || std__string__find(v1, "</NOTIFY>", 0, 9) == -1
    || (v2 = std__string__find(v1, "&lt;PluginID&gt;", 0), v2 == -1)
    || (v5 = v2 + 16, v3 = std__string__find(v1, "&lt;/PluginID&gt;", v2 + 16), v4 = v3, v3 == -1) )
  {
    v17 = 0;
  }
  else
  {
    std__string__string(&v19, v1, v5, v3 - v5);
    if ( std__string__compare(&v19, "srvMng")
      || (v6 = std__string__find(v1, "<NOTIFY>&lt;srv&gt;&lt;id&gt;", v4 + 17), v6 == -1)
      || (v9 = v6 + 29, v7 = std__string__find(v1, "&lt;/id&gt;", v6 + 29), v8 = v7, v7 == -1) )
    {
      v17 = 0;
    }
    else
    {
      std__string__string(&v20, v1, v9, v7 - v9);
      if ( std__string__compare(&v20, "cAwaySrv")
        || (v10 = std__string__find(v1, "&lt;req&gt;&lt;id&gt;", v8 + 11), v10 == -1)
        || (v13 = v10 + 21, v11 = std__string__find(v1, "&lt;/id&gt;", v10 + 21), v12 = v11, v11 == -1) )
      {
        v17 = 0;
      }
      else
      {
        std__string__string(&v21, v1, v13, v11 - v13);
        if ( std__string__compare(&v21, "AwayStat")
          || (v14 = std__string__find(v1, "&lt;senderId&gt;", v12 + 11), v14 == -1)
          || (v16 = v14 + 16, v15 = std__string__find(v1, "&lt;/senderId&gt;", v14 + 16), v15 == -1) )
        {
          v17 = 0;
        }
        else
        {
          std__string__string(&v22, v1, v16, v15 - v16);
          std__string__assign(a1 + 56, &v22);
          std__string___string(&v22);
          v17 = 1;
        }
        std__string___string(&v21);
      }
      std__string___string(&v20);
    }
    std__string___string(&v19);
  }
  return v17;
}

//----- (08053CB0) --------------------------------------------------------
int __fastcall sub_8053CB0(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  int v8; // eax@8
  char v15; // [sp+1Bh] [bp-Dh]@13

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 24);
  v3 = *(_DWORD *)(a3 + 20);
  *(_DWORD *)a3 = &off_807F4F8;
  if ( v5 != v3 )
  {
    do
    {
      if ( *(_DWORD *)(v3 + 4) )
        operator delete(a1, a2);
      v3 += 16;
    }
    while ( v5 != v3 );
    v5 = *(_DWORD *)(v4 + 20);
  }
  if ( v5 )
    operator delete(a1, a2);
  v8 = *(_DWORD *)(v4 + 16);
  _EDX = v8 - 12;
  if ( v8 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v15);
  }
  return operator delete(a1, _EDX);
}

//----- (08053D50) --------------------------------------------------------
int __fastcall sub_8053D50(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  int result; // eax@8
  int v8; // ecx@11
  char v14; // [sp+1Bh] [bp-Dh]@13

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 24);
  v3 = *(_DWORD *)(a3 + 20);
  *(_DWORD *)a3 = &off_807F4F8;
  if ( v5 != v3 )
  {
    do
    {
      if ( *(_DWORD *)(v3 + 4) )
        operator delete(a1, a2);
      v3 += 16;
    }
    while ( v5 != v3 );
    v5 = *(_DWORD *)(v4 + 20);
  }
  if ( v5 )
    operator delete(a1, a2);
  result = *(_DWORD *)(v4 + 16);
  _EDX = result - 12;
  if ( result - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v8 = result;
    }
    else
    {
      v8 = *(_DWORD *)(_EDX + 8);
      result = v8 - 1;
      *(_DWORD *)(_EDX + 8) = v8 - 1;
    }
    if ( v8 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v14);
  }
  return result;
}

//----- (08053DE0) --------------------------------------------------------
int __fastcall sub_8053DE0(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  int result; // eax@8
  int v8; // ecx@11
  char v14; // [sp+1Bh] [bp-Dh]@13

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 24);
  v3 = *(_DWORD *)(a3 + 20);
  *(_DWORD *)a3 = &off_807F4F8;
  if ( v5 != v3 )
  {
    do
    {
      if ( *(_DWORD *)(v3 + 4) )
        operator delete(a1, a2);
      v3 += 16;
    }
    while ( v5 != v3 );
    v5 = *(_DWORD *)(v4 + 20);
  }
  if ( v5 )
    operator delete(a1, a2);
  result = *(_DWORD *)(v4 + 16);
  _EDX = result - 12;
  if ( result - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v8 = result;
    }
    else
    {
      v8 = *(_DWORD *)(_EDX + 8);
      result = v8 - 1;
      *(_DWORD *)(_EDX + 8) = v8 - 1;
    }
    if ( v8 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v14);
  }
  return result;
}

//----- (08053E70) --------------------------------------------------------
int __fastcall sub_8053E70(int a1, int a2, int a3)
{
  int v4; // ebx@1
  int v5; // ecx@1
  int v6; // edx@1

  v4 = a3;
  *(_DWORD *)a3 = &off_807F4D8;
  sub_8053DE0(a1, a2, a3);
  a3 = v4;
  return operator delete(v5, v6);
}

//----- (08053EA0) --------------------------------------------------------
int __fastcall sub_8053EA0(int a1, int a2, int a3)
{
  *(_DWORD *)a3 = &off_807F4D8;
  return sub_8053DE0(a1, a2, a3);
}

//----- (08053EE0) --------------------------------------------------------
int __fastcall sub_8053EE0(int a1, int a2, int a3)
{
  int v4; // ebx@1
  int v5; // ecx@1
  int v6; // edx@1

  v4 = a3;
  *(_DWORD *)a3 = &off_807F4E8;
  sub_8053DE0(a1, a2, a3);
  a3 = v4;
  return operator delete(v5, v6);
}

//----- (08053F10) --------------------------------------------------------
int __fastcall sub_8053F10(int a1, int a2, int a3)
{
  *(_DWORD *)a3 = &off_807F4E8;
  return sub_8053DE0(a1, a2, a3);
}

//----- (08053F50) --------------------------------------------------------
signed int __cdecl sub_8053F50(int a1, int a2)
{
  int v2; // ebx@1
  int v3; // esi@1
  int v4; // edx@3
  unsigned int v5; // ecx@3
  unsigned int v7; // ecx@8
  int v8; // ebx@8
  unsigned __int16 v9; // ax@9
  int v10; // edi@9
  __int16 v11; // ax@4
  int v12; // eax@10
  __int16 v13; // ax@11
  __int16 v14; // ax@11
  int v15; // [sp+14h] [bp-24h]@9
  unsigned __int16 v16; // [sp+2Ah] [bp-Eh]@10
  unsigned __int16 v17; // [sp+1Ah] [bp-1Eh]@10
  unsigned __int16 v18; // [sp+28h] [bp-10h]@11

  v3 = *(_DWORD *)a2;
  v2 = (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 4;
  if ( !v2 )
    return 0;
  if ( *(_WORD *)v3 != 2 )
  {
    v4 = v3 + 16;
    v5 = 0;
    do
    {
      ++v5;
      if ( v5 >= v2 )
        return 0;
      v11 = *(_WORD *)v4;
      v3 = v4;
      v4 += 16;
    }
    while ( v11 != 2 );
  }
  v8 = *(_DWORD *)(v3 + 4);
  v7 = *(_DWORD *)(v3 + 8) - v8;
  if ( v7 <= 0xB )
    return 0;
  v9 = __ROR__(*(_WORD *)(v8 + 2), 8);
  v10 = v9;
  v15 = v9 + 12;
  if ( (unsigned int)v9 + 12 > v7
    || (v16 = v9, v12 = *(_WORD *)(v8 + v9 + 6), LOWORD(v12) = __ROR__(v12, 8), v17 = v12 - 4, v10
                                                                                             + (unsigned int)(unsigned __int16)(v12 - 4)
                                                                                             + 12 > v7) )
    return 0;
  v18 = v17;
  v13 = __ROR__(*(_WORD *)(v8 + v10 + 8), 8);
  *(_WORD *)a1 = v13;
  v14 = __ROR__(*(_WORD *)(v8 + v10 + 10), 8);
  *(_WORD *)(a1 + 2) = v14;
  sub_8056C30(a1 + 4, v8 + v15, v8 + v15 + v18);
  return 1;
}

//----- (08054030) --------------------------------------------------------
signed int __cdecl sub_8054030(int a1, int a2, int a3)
{
  int v3; // eax@1
  int v4; // edx@1
  int v5; // ecx@1
  int v6; // edi@1
  int v7; // esi@2
  signed int result; // eax@3
  int v9; // ecx@5
  int v10; // ebx@5
  int v11; // edx@7
  int v12; // ecx@7
  int v13; // eax@11
  int v14; // edx@11
  unsigned int v15; // ebx@11
  int v16; // esi@11
  int v17; // ecx@12
  int v18; // eax@5
  int v19; // ST08_4@5
  int v20; // edx@6
  __int16 v21; // ax@6
  int v22; // edx@10
  int v23; // edx@11
  int v24; // [sp+18h] [bp-20h]@2
  char v25; // [sp+14h] [bp-24h]@5

  v6 = a2;
  v5 = *(_DWORD *)a2;
  v4 = a3 + 1;
  v3 = *(_DWORD *)(a2 + 4) - *(_DWORD *)a2;
  if ( a3 + 1 > (unsigned int)v3
    || (v7 = *(_BYTE *)(v5 + a3), v24 = v7 + v4, v7 + v4 > (unsigned int)v3)
    || (v18 = *(_DWORD *)a1, v19 = *(_DWORD *)(*(_DWORD *)a1 - 12) + *(_DWORD *)a1, v10 = a1, v25 = 0, sub_8056B00(a1, v18, v19, v4 + v5, v4 + v5 + v7), v9 = *(_DWORD *)v6, v24 + 2 > (unsigned int)(*(_DWORD *)(v6 + 4) - *(_DWORD *)v6))
    || (v20 = v24 + 3, v21 = __ROR__(*(_WORD *)(v9 + v24), 8), *(_WORD *)(v10 + 4) = v21, v20 > (unsigned int)(*(_DWORD *)(v6 + 4) - v9))
    || (*(_BYTE *)(a1 + 6) = *(_BYTE *)(v9 + v24 + 2), v11 = *(_DWORD *)v6, v12 = *(_DWORD *)(v6 + 4) - *(_DWORD *)v6, v24 + 4 > (unsigned int)v12)
    || *(_BYTE *)(v11 + v24 + 3) != 16
    || v24 + 20 > (unsigned int)v12
    || (v22 = v24 + 4 + v11, *(_DWORD *)(a1 + 7) = *(_DWORD *)v22, *(_DWORD *)(a1 + 11) = *(_DWORD *)(v22 + 4), *(_DWORD *)(a1 + 15) = *(_DWORD *)(v22 + 8), *(_DWORD *)(a1 + 19) = *(_DWORD *)(v22 + 12), v24 + 21 > (unsigned int)(*(_DWORD *)(v6 + 4) - *(_DWORD *)v6))
    || (v23 = v24, *(_BYTE *)(a1 + 23) = *(_BYTE *)(*(_DWORD *)v6 + v24 + 20), v16 = *(_DWORD *)v6, v13 = v23 + 41, v14 = v24 + 43, v15 = *(_DWORD *)(v6 + 4) - *(_DWORD *)v6, v24 + 43 > v15)
    || (v17 = *(_WORD *)(v16 + v13), LOWORD(v17) = __ROR__(v17, 8), (unsigned int)(unsigned __int16)v17 + v14 > v15) )
  {
    result = 0;
  }
  else
  {
    sub_80564B0(
      v17,
      v16 + v14 + (unsigned __int16)v17,
      a1 + 24,
      (const void *)(v16 + v14),
      v16 + v14 + (unsigned __int16)v17);
    result = 1;
  }
  return result;
}

//----- (080541B0) --------------------------------------------------------
signed int __cdecl sub_80541B0(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  signed int result; // eax@2
  int v7; // edi@4
  int v8; // edx@4
  __int16 v9; // ax@4

  v5 = a2;
  v4 = a3;
  v3 = a3 + 11;
  if ( a3 + 11 > (unsigned int)(*(_DWORD *)(a2 + 4) - *(_DWORD *)a2)
    || (v8 = a3 + *(_DWORD *)a2, *(_DWORD *)(a1 + 4) = *(_DWORD *)v8, *(_DWORD *)(a1 + 8) = *(_DWORD *)(v8 + 4), v9 = __ROR__(*(_WORD *)(v4 + *(_DWORD *)v5 + 8), 8), *(_WORD *)(a1 + 12) = v9, v7 = *(_BYTE *)(*(_DWORD *)v5 + v4 + 10), v7 + v3 > (unsigned int)(*(_DWORD *)(v5 + 4) - *(_DWORD *)v5)) )
  {
    result = 0;
  }
  else
  {
    sub_8056B00(
      a1 + 16,
      *(_DWORD *)(a1 + 16),
      *(_DWORD *)(*(_DWORD *)(a1 + 16) - 12) + *(_DWORD *)(a1 + 16),
      v3 + *(_DWORD *)v5,
      v3 + *(_DWORD *)v5 + v7);
    result = 1;
  }
  return result;
}

//----- (08054260) --------------------------------------------------------
int __cdecl sub_8054260(int *a1)
{
  int result; // eax@1
  int v3; // ecx@4
  char v9; // [sp+17h] [bp-1h]@6

  result = *a1;
  _EDX = *a1 - 12;
  if ( _EDX != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v3 = result;
    }
    else
    {
      v3 = *(_DWORD *)(_EDX + 8);
      result = v3 - 1;
      *(_DWORD *)(_EDX + 8) = v3 - 1;
    }
    if ( v3 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v9);
  }
  return result;
}

//----- (08054300) --------------------------------------------------------
int __cdecl sub_8054300(int a1)
{
  int result; // eax@1
  int v3; // ecx@4
  char v9; // [sp+17h] [bp-1h]@6

  result = *(_DWORD *)(a1 + 8);
  _EDX = result - 12;
  if ( result - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v3 = result;
    }
    else
    {
      v3 = *(_DWORD *)(_EDX + 8);
      result = v3 - 1;
      *(_DWORD *)(_EDX + 8) = v3 - 1;
    }
    if ( v3 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v9);
  }
  return result;
}

//----- (080543A0) --------------------------------------------------------
int __cdecl sub_80543A0(int a1)
{
  int v2; // ebx@1
  int result; // eax@7
  int v10; // ecx@10
  int v11; // ecx@14
  int v12; // ecx@18
  int v13; // ecx@22
  int v14; // ecx@26
  int v15; // ecx@30
  int v16; // ecx@34
  int v17; // eax@1
  int v18; // eax@2
  int v19; // eax@3
  int v20; // eax@4
  int v21; // eax@5
  int v22; // eax@6
  char v64; // [sp+1Fh] [bp-9h]@12
  char v65; // [sp+19h] [bp-Fh]@16
  char v66; // [sp+1Ah] [bp-Eh]@20
  char v67; // [sp+1Bh] [bp-Dh]@24
  char v68; // [sp+1Dh] [bp-Bh]@28
  char v69; // [sp+1Ch] [bp-Ch]@32
  char v70; // [sp+1Eh] [bp-Ah]@36

  v2 = a1;
  v17 = *(_DWORD *)(a1 + 68);
  _EDX = v17 - 12;
  if ( v17 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v10 = _EAX;
    }
    else
    {
      v10 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v10 - 1;
    }
    if ( v10 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v64);
  }
  v18 = *(_DWORD *)(v2 + 64);
  _EDX = v18 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v18 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v16 = _EAX;
    }
    else
    {
      v16 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v16 - 1;
    }
    if ( v16 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v70);
  }
  v19 = *(_DWORD *)(v2 + 56);
  _EDX = v19 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v19 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v14 = _EAX;
    }
    else
    {
      v14 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v14 - 1;
    }
    if ( v14 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v68);
  }
  v20 = *(_DWORD *)(v2 + 52);
  _EDX = v20 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v20 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v15 = _EAX;
    }
    else
    {
      v15 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v15 - 1;
    }
    if ( v15 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v69);
  }
  v21 = *(_DWORD *)(v2 + 48);
  _EDX = v21 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v21 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v13 = _EAX;
    }
    else
    {
      v13 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v13 - 1;
    }
    if ( v13 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v67);
  }
  v22 = *(_DWORD *)(v2 + 24);
  _EDX = v22 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v22 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v12 = _EAX;
    }
    else
    {
      v12 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v12 - 1;
    }
    if ( v12 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v66);
  }
  result = *(_DWORD *)(v2 + 12);
  _EDX = result - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(result - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v11 = result;
    }
    else
    {
      v11 = *(_DWORD *)(_EDX + 8);
      result = v11 - 1;
      *(_DWORD *)(_EDX + 8) = v11 - 1;
    }
    if ( v11 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v65);
  }
  return result;
}

//----- (080545E0) --------------------------------------------------------
int __cdecl sub_80545E0(int a1)
{
  a1 += 52;
  return sub_80543A0(a1);
}

//----- (08054840) --------------------------------------------------------
int __cdecl sub_8054840(int a1)
{
  int result; // eax@1
  int v3; // ecx@4
  char v9; // [sp+17h] [bp-1h]@6

  result = *(_DWORD *)(a1 + 4);
  _EDX = result - 12;
  if ( result - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v3 = result;
    }
    else
    {
      v3 = *(_DWORD *)(_EDX + 8);
      result = v3 - 1;
      *(_DWORD *)(_EDX + 8) = v3 - 1;
    }
    if ( v3 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v9);
  }
  return result;
}

//----- (080548E0) --------------------------------------------------------
int __fastcall sub_80548E0(int a1, int a2, int a3)
{
  int *v3; // ebx@1
  int result; // eax@3
  int v6; // ecx@6
  char v12; // [sp+23h] [bp-5h]@8

  v3 = (int *)a3;
  if ( *(_DWORD *)(a3 + 24) )
    operator delete(a1, a2);
  result = *v3;
  _EDX = *v3 - 12;
  if ( _EDX != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v6 = result;
    }
    else
    {
      v6 = *(_DWORD *)(_EDX + 8);
      result = v6 - 1;
      *(_DWORD *)(_EDX + 8) = v6 - 1;
    }
    if ( v6 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v12);
  }
  return result;
}

//----- (080549C0) --------------------------------------------------------
int __fastcall sub_80549C0(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  int result; // eax@8
  int v8; // ecx@11
  char v14; // [sp+1Bh] [bp-Dh]@13

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 20);
  v3 = *(_DWORD *)(a3 + 16);
  if ( v5 != v3 )
  {
    do
    {
      if ( *(_DWORD *)(v3 + 4) )
        operator delete(a1, a2);
      v3 += 16;
    }
    while ( v5 != v3 );
    v5 = *(_DWORD *)(v4 + 16);
  }
  if ( v5 )
    operator delete(a1, a2);
  result = *(_DWORD *)(v4 + 4);
  _EDX = result - 12;
  if ( result - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v8 = result;
    }
    else
    {
      v8 = *(_DWORD *)(_EDX + 8);
      result = v8 - 1;
      *(_DWORD *)(_EDX + 8) = v8 - 1;
    }
    if ( v8 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v14);
  }
  return result;
}

//----- (08054AA0) --------------------------------------------------------
void __fastcall sub_8054AA0(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  int v6; // ST00_4@2

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 12);
  v3 = *(_DWORD *)(a3 + 8);
  if ( v5 != v3 )
  {
    do
    {
      v6 = v3;
      v3 += 28;
      sub_80549C0(a1, a2, v6);
    }
    while ( v5 != v3 );
    v5 = *(_DWORD *)(v4 + 8);
  }
  if ( v5 )
  {
    a3 = v5;
    operator delete(a1, a2);
  }
}

//----- (08054AF0) --------------------------------------------------------
signed int __cdecl sub_8054AF0(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  signed int result; // eax@2
  unsigned __int16 v6; // ax@4
  int v7; // esi@4
  int v8; // ecx@5
  int v9; // esi@8
  int v10; // ebx@12
  int v11; // eax@13
  int v12; // ecx@15
  __int16 v13; // ax@6
  __int16 v14; // ax@7
  __int16 v15; // ax@8
  unsigned __int16 v16; // dx@9
  int v17; // ecx@13
  int v18; // edx@13
  int v19; // [sp+18h] [bp-20h]@10
  char v20; // [sp+1Ch] [bp-1Ch]@13
  int v21; // [sp+24h] [bp-14h]@13
  int v22; // [sp+20h] [bp-18h]@13
  int v23; // [sp+28h] [bp-10h]@15

  v4 = a2;
  v3 = a3 + 2;
  if ( a3 + 2 > (unsigned int)(*(_DWORD *)(a2 + 4) - *(_DWORD *)a2)
    || (v6 = __ROR__(*(_WORD *)(*(_DWORD *)a2 + a3), 8), v7 = *(_DWORD *)a2, *(_WORD *)a1 = v6, (unsigned int)v6 + v3 > *(_DWORD *)(v4 + 4) - v7)
    || (std__string__assign(a1 + 4, v7 + v3, v6), v8 = *(_DWORD *)(*(_DWORD *)(a1 + 4) - 12) + v3, v8 + 2 > (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4))
    || (v13 = __ROR__(*(_WORD *)(*(_DWORD *)v4 + v8), 8), *(_WORD *)(a1 + 8) = v13, v8 + 4 > (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4))
    || (v14 = __ROR__(*(_WORD *)(*(_DWORD *)v4 + v8 + 2), 8), *(_WORD *)(a1 + 10) = v14, v8 + 6 > (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4))
    || (v9 = v8 + 8, v15 = __ROR__(*(_WORD *)(*(_DWORD *)v4 + v8 + 4), 8), *(_WORD *)(a1 + 12) = v15, v8 + 8 > (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4))
    || (v16 = __ROR__(*(_WORD *)(*(_DWORD *)v4 + v8 + 6), 8), *(_WORD *)(a1 + 14) = v16, v9 + (unsigned int)v16 > *(_DWORD *)(v4 + 4) - *(_DWORD *)v4)
    || (v19 = a1 + 16, sub_80567F0(v8, a1 + 16, a1 + 16), v9 > v9 + (unsigned int)*(_WORD *)(a1 + 14)) )
  {
LABEL_2:
    result = 0;
  }
  else
  {
    if ( *(_WORD *)(a1 + 14) )
    {
      v10 = v9;
      while ( 1 )
      {
        v22 = 0;
        v21 = 0;
        v23 = 0;
        if ( !(unsigned __int8)sub_80516C0((int)&v20, v4, v10) )
          break;
        sub_8057F70(v12, v19, v19, (int)&v20);
        v10 += v21 - v22 + 4;
        sub_8056490(v17, v18, (int)&v22);
        v11 = v9 + *(_WORD *)(a1 + 14);
        if ( v11 < (unsigned int)v10 )
          goto LABEL_2;
        if ( v11 == v10 )
          goto LABEL_17;
      }
      sub_8056490(v12, (int)&v22, (int)&v22);
      result = 0;
    }
    else
    {
LABEL_17:
      result = 1;
    }
  }
  return result;
}

//----- (08054CC0) --------------------------------------------------------
signed int __cdecl sub_8054CC0(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // esi@1
  int v5; // ecx@2
  signed int result; // eax@3
  int v7; // edx@7
  int v8; // ecx@7
  int v9; // ebx@8
  unsigned int v10; // eax@10
  int v11; // ecx@10
  int v12; // ebx@10
  int v13; // ecx@13
  int v14; // edi@14
  int v15; // ebx@16
  int v16; // esi@16
  int v17; // edx@27
  int v18; // ecx@27
  int v19; // ebx@27
  int v20; // edx@29
  int v21; // ebx@29
  int v22; // edx@2
  int v23; // eax@2
  __int16 v24; // ax@5
  char v25; // zf@8
  int v26; // ebx@10
  __int16 v27; // ax@10
  signed int v28; // eax@10
  int v29; // esi@13
  int v30; // eax@13
  int v31; // eax@13
  __int16 v32; // ax@16
  int v33; // eax@18
  int v34; // ebx@18
  size_t v35; // ebx@18
  int v37; // eax@27
  int v38; // eax@28
  int v39; // [sp+34h] [bp-34h]@2
  int v40; // [sp+1Ch] [bp-4Ch]@6
  signed int v41; // [sp+20h] [bp-48h]@6
  signed int v42; // [sp+44h] [bp-24h]@7
  int v43; // [sp+50h] [bp-18h]@7
  int v44; // [sp+54h] [bp-14h]@7
  int v45; // [sp+58h] [bp-10h]@7
  unsigned __int16 v46; // [sp+40h] [bp-28h]@7
  int v47; // [sp+30h] [bp-38h]@8
  int v48; // [sp+24h] [bp-44h]@10
  __int16 v49; // [sp+48h] [bp-20h]@10
  __int16 v50; // [sp+4Ah] [bp-1Eh]@10
  __int16 v51; // [sp+4Ch] [bp-1Ch]@10
  unsigned __int16 v52; // [sp+4Eh] [bp-1Ah]@10
  int v53; // [sp+2Ch] [bp-3Ch]@10
  int v54; // [sp+38h] [bp-30h]@13
  int v55; // [sp+28h] [bp-40h]@13

  v4 = a2;
  v3 = a3 + 1;
  if ( a3 + 1 > (unsigned int)(*(_DWORD *)(a2 + 4) - *(_DWORD *)a2)
    || (v22 = a3 + 3, *(_BYTE *)a1 = *(_BYTE *)(*(_DWORD *)a2 + a3), v5 = *(_DWORD *)v4, v23 = *(_DWORD *)(v4 + 4), v39 = v22, v22 > (unsigned int)(v23 - v5)) )
    return 0;
  v24 = __ROR__(*(_WORD *)(v5 + v3), 8);
  *(_WORD *)(a1 + 2) = v24;
  if ( v24 )
  {
    v40 = a1 + 8;
    v41 = 0;
    while ( 1 )
    {
      v42 = 134771820;
      v43 = 0;
      v44 = 0;
      v45 = 0;
      if ( !(unsigned __int8)sub_8054AF0((int)&v46, a2, v39) )
        break;
      v9 = *(_DWORD *)(a1 + 12);
      v25 = v9 == *(_DWORD *)(a1 + 16);
      v47 = *(_DWORD *)(a1 + 12);
      if ( v25 )
      {
        sub_8057010((int)&v46, v7, v40, v47, (int)&v46);
      }
      else
      {
        if ( v9 )
        {
          *(_WORD *)v9 = v46;
          v26 = v9 + 4;
          v48 = v26;
          std__string__string(v26, &v42);
          v12 = 0;
          v27 = v49;
          *(_DWORD *)(v47 + 24) = 0;
          *(_WORD *)(v47 + 8) = v27;
          *(_WORD *)(v47 + 10) = v50;
          *(_WORD *)(v47 + 12) = v51;
          *(_WORD *)(v47 + 14) = v52;
          v28 = v44 - v43;
          *(_DWORD *)(v47 + 20) = 0;
          *(_DWORD *)(v47 + 16) = 0;
          v10 = v28 >> 4;
          v53 = 0;
          if ( v10 )
          {
            if ( v10 > 0xFFFFFFF )
            {
              v37 = std____throw_bad_alloc();
              __cxa_begin_catch(v37);
              v19 = v53;
              while ( v19 != v54 )
              {
                v38 = v19 + 4;
                v19 += 16;
                sub_8056490(v18, v17, v38);
              }
              v21 = __cxa_rethrow();
              std__string___string(v48);
              while ( 1 )
              {
                sub_80549C0((int)&v46, v20, (int)&v46);
                v21 = _Unwind_Resume(v21);
              }
            }
            v12 = 16 * v10;
            v53 = operator new(v11, v47);
          }
          v29 = v53;
          v13 = v47;
          v30 = v12 + v53;
          *(_DWORD *)(v47 + 20) = v53;
          *(_DWORD *)(v47 + 24) = v30;
          v31 = v44;
          *(_DWORD *)(v47 + 16) = v29;
          v54 = v29;
          v55 = v31;
          if ( v31 != v43 )
          {
            v14 = v43;
            do
            {
              if ( v54 )
              {
                v16 = 0;
                v15 = *(_DWORD *)(v14 + 8) - *(_DWORD *)(v14 + 4);
                v32 = *(_WORD *)v14;
                *(_DWORD *)(v54 + 4) = 0;
                *(_WORD *)v54 = v32;
                *(_DWORD *)(v54 + 8) = 0;
                *(_DWORD *)(v54 + 12) = 0;
                if ( v15 )
                  v16 = operator new(v13, v54);
                v33 = v16 + v15;
                *(_DWORD *)(v54 + 4) = v16;
                *(_DWORD *)(v54 + 8) = v16;
                v34 = *(_DWORD *)(v14 + 8);
                *(_DWORD *)(v54 + 12) = v33;
                v35 = v34 - *(_DWORD *)(v14 + 4);
                memmove((void *)v16, *(const void **)(v14 + 4), v35);
                *(_DWORD *)(v54 + 8) = v16 + v35;
              }
              v54 += 16;
              v14 += 16;
            }
            while ( v55 != v14 );
          }
          *(_DWORD *)(v47 + 20) = v54;
          v8 = *(_DWORD *)(a1 + 12);
          v47 = *(_DWORD *)(a1 + 12);
        }
        *(_DWORD *)(a1 + 12) = v47 + 28;
      }
      v39 += v46 + v52 + 10;
      sub_80549C0(v8, v52, (int)&v46);
      ++v41;
      if ( *(_WORD *)(a1 + 2) <= v41 )
        goto LABEL_23;
    }
    sub_80549C0((int)&v46, v7, (int)&v46);
    result = 0;
  }
  else
  {
LABEL_23:
    if ( v39 + 4 > (unsigned int)(*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) )
      return 0;
    __asm { bswap   eax }
    *(_DWORD *)(a1 + 4) = _EAX;
    result = 1;
  }
  return result;
}

//----- (08054FD0) --------------------------------------------------------
signed int __fastcall sub_8054FD0(int a1, int a2, int a3, int a4, int a5)
{
  int v4; // edx@1
  int v5; // edi@1
  int v6; // esi@1
  int v7; // ebx@2
  int v8; // ebx@8
  int v9; // edi@8
  int v10; // ecx@10
  int v11; // esi@10
  int v12; // edx@11
  const void *v13; // ebx@12
  int v14; // esi@12
  int v15; // edx@16
  int v16; // edx@17
  int v17; // ebx@19
  __int16 v19; // ax@8
  int v20; // eax@10
  int v21; // ebx@10
  size_t v22; // ebx@10
  int v23; // [sp+18h] [bp-20h]@1
  int v24; // [sp+24h] [bp-14h]@8
  const void *v25; // [sp+20h] [bp-18h]@8
  __int16 v26; // [sp+1Ch] [bp-1Ch]@8
  int v27; // [sp+28h] [bp-10h]@16

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 20);
  v6 = *(_DWORD *)(a3 + 24);
  v23 = a3 + 20;
  if ( v5 != v6 )
  {
    v7 = v5;
    do
    {
      if ( *(_DWORD *)(v7 + 4) )
        operator delete(a1, v4);
      v7 += 16;
    }
    while ( v6 != v7 );
  }
  *(_DWORD *)(a3 + 24) = v5;
  while ( 1 )
  {
    if ( a5 >= (unsigned int)(*(_DWORD *)(a4 + 4) - *(_DWORD *)a4) )
      return 1;
    v25 = 0;
    v24 = 0;
    v27 = 0;
    if ( !(unsigned __int8)sub_80516C0((int)&v26, a4, a5) )
      break;
    v16 = v23;
    v11 = *(_DWORD *)(v23 + 4);
    if ( v11 == *(_DWORD *)(v23 + 8) )
    {
      sub_8057B40(v10, v23, v23, v11, (int)&v26);
    }
    else
    {
      if ( v11 )
      {
        v9 = 0;
        v8 = v24 - (_DWORD)v25;
        v19 = v26;
        *(_DWORD *)(v11 + 4) = 0;
        *(_DWORD *)(v11 + 8) = 0;
        *(_WORD *)v11 = v19;
        *(_DWORD *)(v11 + 12) = 0;
        if ( v8 )
          v9 = operator new(v10, v16);
        v20 = v9 + v8;
        *(_DWORD *)(v11 + 4) = v9;
        *(_DWORD *)(v11 + 8) = v9;
        v21 = v24;
        *(_DWORD *)(v11 + 12) = v20;
        v22 = v21 - (_DWORD)v25;
        memmove((void *)v9, v25, v22);
        *(_DWORD *)(v11 + 8) = v9 + v22;
        v11 = *(_DWORD *)(v23 + 4);
      }
      v12 = v23;
      *(_DWORD *)(v23 + 4) = v11 + 16;
    }
    v13 = v25;
    v14 = v24;
    if ( v25 )
      operator delete(v10, v12);
    a5 += v14 - (_DWORD)v13 + 4;
  }
  v17 = 0;
  if ( !v25 )
    return v17;
  operator delete(v10, v15);
  return 0;
}

//----- (08055160) --------------------------------------------------------
char __cdecl sub_8055160(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  char result; // al@2
  int v6; // ecx@4
  int v7; // esi@5
  signed int v8; // ebx@6
  int v9; // edx@10
  unsigned __int16 v10; // ax@5
  unsigned __int16 v11; // [sp+3Ah] [bp-Eh]@5
  int v12; // [sp+30h] [bp-18h]@7
  int v13; // [sp+2Ch] [bp-1Ch]@7
  int v14; // [sp+34h] [bp-14h]@10
  char v15; // [sp+28h] [bp-20h]@10

  v4 = a2;
  v3 = a3;
  if ( a3 + 15 <= (unsigned int)(*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) && (unsigned __int8)sub_80541B0(a1, a2, a3) )
  {
    v7 = v3 + *(_DWORD *)(*(_DWORD *)(a1 + 16) - 12) + 15;
    v10 = __ROR__(*(_WORD *)(*(_DWORD *)v4 + v3 + *(_DWORD *)(*(_DWORD *)(a1 + 16) - 12) + 13), 8);
    v11 = v10;
    if ( v10 )
    {
      v8 = 0;
      while ( 1 )
      {
        v13 = 0;
        v12 = 0;
        v14 = 0;
        if ( !(unsigned __int8)sub_80516C0((int)&v15, v4, v7) )
          break;
        v7 += v12 - v13 + 4;
        if ( v13 )
          operator delete(v6, v13);
        ++v8;
        if ( v11 <= v8 )
          goto LABEL_12;
      }
      sub_8056490(v6, v9, (int)&v13);
      result = 0;
    }
    else
    {
LABEL_12:
      result = (unsigned __int8)sub_8054FD0(v6, a1, a1, v4, v7) != 0;
    }
  }
  else
  {
    result = 0;
  }
  return result;
}

//----- (08055270) --------------------------------------------------------
signed int __fastcall sub_8055270(int a1, int a2, int a3, int a4, int a5)
{
  int v4; // edx@1
  int v5; // edi@1
  int v6; // esi@1
  int v7; // ebx@2
  int v8; // ebx@8
  int v9; // edi@8
  int v10; // ecx@10
  int v11; // esi@10
  int v12; // edx@11
  const void *v13; // ebx@12
  int v14; // esi@12
  int v15; // edx@16
  int v16; // edx@17
  int v17; // ebx@19
  __int16 v19; // ax@8
  int v20; // eax@10
  int v21; // ebx@10
  size_t v22; // ebx@10
  int v23; // [sp+18h] [bp-20h]@1
  int v24; // [sp+24h] [bp-14h]@8
  const void *v25; // [sp+20h] [bp-18h]@8
  __int16 v26; // [sp+1Ch] [bp-1Ch]@8
  int v27; // [sp+28h] [bp-10h]@16

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 4);
  v6 = *(_DWORD *)(a3 + 8);
  v23 = a3 + 4;
  if ( v5 != v6 )
  {
    v7 = v5;
    do
    {
      if ( *(_DWORD *)(v7 + 4) )
        operator delete(a1, v4);
      v7 += 16;
    }
    while ( v6 != v7 );
  }
  *(_DWORD *)(a3 + 8) = v5;
  while ( 1 )
  {
    if ( a5 >= (unsigned int)(*(_DWORD *)(a4 + 4) - *(_DWORD *)a4) )
      return 1;
    v25 = 0;
    v24 = 0;
    v27 = 0;
    if ( !(unsigned __int8)sub_80516C0((int)&v26, a4, a5) )
      break;
    v16 = v23;
    v11 = *(_DWORD *)(v23 + 4);
    if ( v11 == *(_DWORD *)(v23 + 8) )
    {
      sub_8057B40(v10, v23, v23, v11, (int)&v26);
    }
    else
    {
      if ( v11 )
      {
        v9 = 0;
        v8 = v24 - (_DWORD)v25;
        v19 = v26;
        *(_DWORD *)(v11 + 4) = 0;
        *(_DWORD *)(v11 + 8) = 0;
        *(_WORD *)v11 = v19;
        *(_DWORD *)(v11 + 12) = 0;
        if ( v8 )
          v9 = operator new(v10, v16);
        v20 = v9 + v8;
        *(_DWORD *)(v11 + 4) = v9;
        *(_DWORD *)(v11 + 8) = v9;
        v21 = v24;
        *(_DWORD *)(v11 + 12) = v20;
        v22 = v21 - (_DWORD)v25;
        memmove((void *)v9, v25, v22);
        *(_DWORD *)(v11 + 8) = v9 + v22;
        v11 = *(_DWORD *)(v23 + 4);
      }
      v12 = v23;
      *(_DWORD *)(v23 + 4) = v11 + 16;
    }
    v13 = v25;
    v14 = v24;
    if ( v25 )
      operator delete(v10, v12);
    a5 += v14 - (_DWORD)v13 + 4;
  }
  v17 = 0;
  if ( !v25 )
    return v17;
  operator delete(v10, v15);
  return 0;
}

//----- (08055400) --------------------------------------------------------
signed int __fastcall sub_8055400(int a1, int a2, int a3, int a4, int a5)
{
  return sub_8055270(a1, a2, a3, a4, a5);
}

//----- (08055410) --------------------------------------------------------
signed int __cdecl sub_8055410(int a1, int a2, int a3)
{
  signed int result; // eax@2

  if ( a3 + 4 > (unsigned int)(*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) )
    goto LABEL_8;
  __asm { bswap   eax }
  if ( _EAX != 1 )
LABEL_8:
    result = 0;
  else
    result = sub_8055270(a2, *(_DWORD *)a2, a1, a2, a3 + 4);
  return result;
}

//----- (08055470) --------------------------------------------------------
signed int __cdecl sub_8055470(int a1, int a2)
{
  int v2; // edx@1
  int v3; // ebx@1
  int v4; // edi@1
  signed int v5; // ebx@3
  int v7; // esi@5
  int v8; // edx@6
  int v9; // ecx@6
  int v10; // eax@7
  int v11; // eax@9
  int v12; // eax@11
  __int16 v13; // ax@2
  int (__cdecl **v14)(int); // [sp+1Ch] [bp-1Ch]@6
  int v15; // [sp+20h] [bp-18h]@6
  int v16; // [sp+24h] [bp-14h]@6
  int v17; // [sp+28h] [bp-10h]@6

  v3 = a2;
  v4 = a1;
  v2 = *(_DWORD *)a2;
  if ( (unsigned int)(*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) <= 1
    || (v13 = __ROR__(*(_WORD *)v2, 8), *(_WORD *)a1 = v13, (unsigned int)(*(_DWORD *)(v3 + 4) - v2) <= 9)
    || (*(_DWORD *)(a1 + 2) = *(_DWORD *)(v2 + 2), *(_DWORD *)(a1 + 6) = *(_DWORD *)(v2 + 6), v7 = *(_DWORD *)v3, (unsigned int)(*(_DWORD *)(v3 + 4) - *(_DWORD *)v3) <= 0x19) )
  {
    v5 = 0;
  }
  else
  {
    *(_DWORD *)(a1 + 10) = *(_DWORD *)(v7 + 10);
    *(_DWORD *)(a1 + 14) = *(_DWORD *)(v7 + 14);
    *(_DWORD *)(a1 + 18) = *(_DWORD *)(v7 + 18);
    *(_DWORD *)(a1 + 22) = *(_DWORD *)(v7 + 22);
    v14 = &off_807F538;
    v15 = 0;
    v16 = 0;
    v17 = 0;
    if ( !(unsigned __int8)sub_8055270(a1 + 10, v7 + 10, (int)&v14, v3, 26)
      || (v10 = sub_8050FE0((int)&v14, 4), v10) && !(unsigned __int8)sub_8051660(v10, v4 + 28)
      || (v11 = sub_8050FE0((int)&v14, 5), v11) && !(unsigned __int8)sub_8051690(v11, v4 + 32)
      || (v12 = sub_8050FE0((int)&v14, 10001), !v12)
      || (v5 = 1, !(unsigned __int8)sub_8051830(v4 + 36, v12 + 4, 0)) )
      v5 = 0;
    sub_8052390(v9, v8, (int)&v14);
  }
  return v5;
}

//----- (080555E0) --------------------------------------------------------
signed int __cdecl sub_80555E0(int a1, int a2)
{
  int v2; // eax@1
  int v3; // ebx@1
  int v4; // edx@2
  int v5; // ecx@2
  int v6; // eax@3
  int v7; // eax@5
  int v8; // eax@7
  int v9; // eax@9
  signed int v10; // ebx@10
  char v12; // al@10
  int (__cdecl **v13)(int); // [sp+10h] [bp-18h]@1
  int v14; // [sp+14h] [bp-14h]@1
  int v15; // [sp+18h] [bp-10h]@1
  int v16; // [sp+1Ch] [bp-Ch]@1

  v3 = a1;
  v13 = &off_807F538;
  v14 = 0;
  v15 = 0;
  v16 = 0;
  sub_8056C70((int)&v14, a2);
  *(_WORD *)v3 = 0;
  v2 = sub_8050FE0((int)&v13, 1);
  if ( v2 && !(unsigned __int8)sub_8051690(v2, v3)
    || (*(_DWORD *)(v3 + 4) = 0, v6 = sub_8050FE0((int)&v13, 6), v6) && !(unsigned __int8)sub_8051660(v6, v3 + 4)
    || (*(_DWORD *)(v3 + 8) = 0, v7 = sub_8050FE0((int)&v13, 15), v7) && !(unsigned __int8)sub_8051660(v7, v3 + 8)
    || (*(_DWORD *)(v3 + 12) = 0, v8 = sub_8050FE0((int)&v13, 3), v8) && !(unsigned __int8)sub_8051660(v8, v3 + 12)
    || (v9 = sub_8050FE0((int)&v13, 5), !v9)
    || (v12 = sub_8055470(v3 + 16, v9 + 4), v10 = 1, !v12) )
    v10 = 0;
  sub_8052390(v5, v4, (int)&v13);
  return v10;
}

//----- (08055740) --------------------------------------------------------
int __fastcall sub_8055740(int a1, int a2, int a3, int a4)
{
  void *v3; // edx@1
  int v4; // ebx@1
  int v5; // esi@1
  int v6; // ecx@2
  int v8; // ecx@3
  int v10; // edi@5
  int v11; // esi@5
  int v12; // ebx@6
  int v13; // edx@10
  int v14; // ebx@12
  int v15; // esi@12
  int v16; // edx@16
  int v17; // esi@16
  int v18; // ebx@18
  int v19; // edi@18
  int v20; // edx@21
  int result; // eax@26
  int v22; // eax@1
  signed int v23; // eax@1
  int v24; // eax@2
  __int16 v25; // ax@3
  __int16 v26; // ax@3
  __int16 v27; // ax@3
  char v28; // zf@10
  __int16 v29; // ax@12
  int v30; // eax@14
  int v31; // ebx@14
  size_t v32; // ebx@14
  __int16 v33; // ax@18
  int v34; // eax@20
  int v35; // ebx@20
  size_t v36; // ebx@20
  int v49; // [sp+68h] [bp-10h]@1
  int v50; // [sp+3Ch] [bp-3Ch]@1
  int v51; // [sp+18h] [bp-60h]@1
  int v52; // [sp+40h] [bp-38h]@1
  int v53; // [sp+44h] [bp-34h]@1
  signed int v54; // [sp+5Bh] [bp-1Dh]@3
  signed int v55; // [sp+5Fh] [bp-19h]@3
  signed int v56; // [sp+63h] [bp-15h]@3
  char v57; // [sp+67h] [bp-11h]@3
  __int16 v58; // [sp+56h] [bp-22h]@3
  __int16 v59; // [sp+54h] [bp-24h]@3
  __int16 v60; // [sp+52h] [bp-26h]@3
  const void *v61; // [sp+30h] [bp-48h]@3
  int v62; // [sp+34h] [bp-44h]@3
  int v63; // [sp+38h] [bp-40h]@3
  __int16 v64; // [sp+2Ch] [bp-4Ch]@3
  int v65; // [sp+4Ch] [bp-2Ch]@3
  char v66; // [sp+5Ah] [bp-1Eh]@3
  const void *v67; // [sp+20h] [bp-58h]@3
  int v68; // [sp+24h] [bp-54h]@3
  int v69; // [sp+28h] [bp-50h]@3
  int v70; // [sp+48h] [bp-30h]@3
  __int16 v71; // [sp+1Ch] [bp-5Ch]@3
  char v72; // [sp+58h] [bp-20h]@36
  char v73; // [sp+59h] [bp-1Fh]@41

  v5 = a3;
  v49 = *MK_FP(__GS__, 20);
  v3 = 0;
  v50 = 0;
  v51 = a4;
  v22 = *(_DWORD *)(a3 + 4);
  v52 = 0;
  v53 = 0;
  v23 = *(_DWORD *)(v22 - 12);
  v4 = v23 + 13;
  if ( v23 == -13 )
  {
    v6 = 0;
  }
  else
  {
    v24 = operator new(a1, 0);
    v3 = (void *)v24;
    v6 = v24;
  }
  v53 = (int)((char *)v3 + v4);
  v50 = (int)v3;
  memset(v3, 0, (size_t)(v3 + v4 - v6));
  v54 = 16777477;
  v52 = v53;
  v55 = 65793;
  v56 = -16777190;
  v57 = -1;
  *(_DWORD *)v50 = 16777477;
  *(_DWORD *)(v50 + 4) = v55;
  *(_DWORD *)(v50 + 8) = v56;
  *(_BYTE *)(v50 + 12) = v57;
  v25 = __ROR__(*(_WORD *)(*(_DWORD *)(v5 + 4) - 12) + 4, 8);
  v58 = v25;
  *(_WORD *)(v50 + 7) = v25;
  v26 = __ROR__(*(_WORD *)v5, 8);
  v59 = v26;
  *(_WORD *)(v50 + 9) = v26;
  v27 = __ROR__(*(_WORD *)(v5 + 2), 8);
  v60 = v27;
  *(_WORD *)(v50 + 11) = v27;
  memcpy((void *)(v50 + 13), *(const void **)(v5 + 4), *(_DWORD *)(*(_DWORD *)(v5 + 4) - 12));
  v61 = 0;
  v62 = 0;
  v63 = 0;
  sub_804B500(v8, (int)&v61, (int)&v61, (int)&v50);
  v64 = 2;
  std__string__string(&v65, &aResNr[13], &v66);
  v67 = 0;
  v68 = 0;
  v69 = 0;
  std__string__string(&v70, &v65);
  sub_8051C40((int)&v71, (int)&v70);
  _EDX = v70 - 12;
  if ( v70 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
    goto LABEL_38;
  while ( 1 )
  {
    v71 = 6;
    _EDX = v65 - 12;
    if ( std__string___Rep___S_empty_rep_storage != (char *)(v65 - 12) )
    {
      if ( pthread_cancel )
      {
        _EAX = -1;
        __asm { lock xadd [edx+8], eax }
        v8 = _EAX;
      }
      else
      {
        v8 = *(_DWORD *)(_EDX + 8);
        *(_DWORD *)(_EDX + 8) = v8 - 1;
      }
      if ( v8 <= 0 )
        std__string___Rep___M_destroy(_EDX, &v72);
    }
    v10 = *(_DWORD *)v51;
    v11 = *(_DWORD *)(v51 + 4);
    if ( *(_DWORD *)v51 != v11 )
    {
      v12 = *(_DWORD *)v51;
      do
      {
        if ( *(_DWORD *)(v12 + 4) )
          operator delete(v8, _EDX);
        v12 += 16;
      }
      while ( v11 != v12 );
    }
    v13 = v51;
    v28 = v10 == *(_DWORD *)(v51 + 8);
    *(_DWORD *)(v51 + 4) = v10;
    if ( v28 )
    {
      sub_8057B40(v8, (int)&v71, v51, v10, (int)&v71);
    }
    else
    {
      if ( v10 )
      {
        v15 = 0;
        v14 = v68 - (_DWORD)v67;
        v29 = v71;
        *(_DWORD *)(v10 + 4) = 0;
        *(_DWORD *)(v10 + 8) = 0;
        *(_WORD *)v10 = v29;
        *(_DWORD *)(v10 + 12) = 0;
        if ( v14 )
          v15 = operator new(v8, v13);
        v30 = v15 + v14;
        *(_DWORD *)(v10 + 4) = v15;
        *(_DWORD *)(v10 + 8) = v15;
        v31 = v68;
        *(_DWORD *)(v10 + 12) = v30;
        v32 = v31 - (_DWORD)v67;
        memmove((void *)v15, v67, v32);
        *(_DWORD *)(v10 + 8) = v15 + v32;
      }
      *(_DWORD *)(v51 + 4) += 16;
    }
    v16 = v51;
    v17 = *(_DWORD *)(v51 + 4);
    if ( v17 == *(_DWORD *)(v51 + 8) )
    {
      sub_8057B40(v8, v51, v51, v17, (int)&v64);
    }
    else
    {
      if ( v17 )
      {
        v19 = 0;
        v18 = v62 - (_DWORD)v61;
        v33 = v64;
        *(_DWORD *)(v17 + 4) = 0;
        *(_DWORD *)(v17 + 8) = 0;
        *(_WORD *)v17 = v33;
        *(_DWORD *)(v17 + 12) = 0;
        if ( v18 )
          v19 = operator new(v8, v16);
        v34 = v19 + v18;
        *(_DWORD *)(v17 + 4) = v19;
        *(_DWORD *)(v17 + 8) = v19;
        v35 = v62;
        *(_DWORD *)(v17 + 12) = v34;
        v36 = v35 - (_DWORD)v61;
        memmove((void *)v19, v61, v36);
        *(_DWORD *)(v17 + 8) = v19 + v36;
        v17 = *(_DWORD *)(v51 + 4);
      }
      v20 = v51;
      *(_DWORD *)(v51 + 4) = v17 + 16;
    }
    if ( v67 )
      operator delete(v8, v20);
    if ( v61 )
      operator delete(v8, v20);
    result = v50;
    if ( v50 )
      result = operator delete(v8, v20);
    if ( !(*MK_FP(__GS__, 20) ^ v49) )
      break;
    __stack_chk_fail();
LABEL_38:
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v8 = _EAX;
    }
    else
    {
      v8 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v8 - 1;
    }
    if ( v8 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v73);
  }
  return result;
}

//----- (08055D40) --------------------------------------------------------
int __cdecl sub_8055D40(int a1, int a2)
{
  int v2; // edx@1
  int v3; // ecx@1
  int v4; // ebx@1
  int v5; // edx@3
  int v6; // ecx@3
  int v7; // esi@3
  int v8; // ebx@5
  int v9; // edi@5
  int v10; // edx@11
  int v11; // ecx@11
  int v12; // esi@11
  int v13; // ebx@13
  int v14; // edi@13
  int v15; // edx@19
  int v16; // ecx@19
  int v17; // esi@19
  int v18; // ebx@21
  int v19; // edi@21
  int v20; // esi@27
  int v21; // edx@33
  int v22; // ecx@33
  int v23; // esi@33
  int v24; // ebx@35
  int v25; // edi@35
  int result; // eax@41
  int v27; // edx@41
  int v28; // ecx@41
  int v29; // esi@3
  __int16 v30; // ax@3
  int v31; // edx@3
  int v32; // ebx@3
  int v33; // eax@7
  int v34; // ebx@7
  size_t v35; // ebx@7
  int v36; // eax@15
  int v37; // ebx@15
  size_t v38; // ebx@15
  int v39; // eax@23
  int v40; // ebx@23
  size_t v41; // ebx@23
  const void *v42; // eax@29
  int v43; // ebx@29
  size_t v44; // ebx@29
  int v45; // eax@37
  int v46; // ebx@37
  size_t v47; // ebx@37
  int v48; // [sp+7Ch] [bp-1Ch]@1
  int v49; // [sp+80h] [bp-18h]@1
  int v50; // [sp+84h] [bp-14h]@1
  char v51; // [sp+8Bh] [bp-Dh]@1
  __int16 v52; // [sp+88h] [bp-10h]@3
  int (__cdecl **v53)(int); // [sp+6Ch] [bp-2Ch]@3
  int v54; // [sp+70h] [bp-28h]@3
  int v55; // [sp+74h] [bp-24h]@3
  int v56; // [sp+78h] [bp-20h]@3
  const void *v57; // [sp+60h] [bp-38h]@3
  int v58; // [sp+64h] [bp-34h]@3
  int v59; // [sp+68h] [bp-30h]@3
  __int16 v60; // [sp+5Ch] [bp-3Ch]@3
  const void *v61; // [sp+50h] [bp-48h]@11
  int v62; // [sp+54h] [bp-44h]@11
  int v63; // [sp+58h] [bp-40h]@11
  __int16 v64; // [sp+4Ch] [bp-4Ch]@11
  const void *v65; // [sp+40h] [bp-58h]@19
  int v66; // [sp+44h] [bp-54h]@19
  int v67; // [sp+48h] [bp-50h]@19
  __int16 v68; // [sp+3Ch] [bp-5Ch]@19
  const void *v69; // [sp+30h] [bp-68h]@27
  int v70; // [sp+38h] [bp-60h]@27
  int v71; // [sp+34h] [bp-64h]@27
  __int16 v72; // [sp+2Ch] [bp-6Ch]@27
  const void *v73; // [sp+20h] [bp-78h]@33
  int v74; // [sp+24h] [bp-74h]@33
  int v75; // [sp+28h] [bp-70h]@33
  __int16 v76; // [sp+1Ch] [bp-7Ch]@33

  v48 = 0;
  v49 = 0;
  v50 = 0;
  sub_8052BE0(a1 + 36, (int)&v48, 0);
  v51 = 0;
  v4 = *(_DWORD *)(a2 + 4);
  v2 = *(_DWORD *)a2;
  v3 = v4 - *(_DWORD *)a2;
  if ( (unsigned int)v3 <= 0x1A )
  {
    sub_8056580(a2, v4, 26 - v3, &v51);
    v2 = *(_DWORD *)a2;
  }
  else
  {
    *(_DWORD *)(a2 + 4) = v2 + 26;
  }
  v29 = a1;
  v30 = __ROR__(*(_WORD *)a1, 8);
  v52 = v30;
  *(_WORD *)v2 = v30;
  v31 = *(_DWORD *)a2;
  *(_DWORD *)(*(_DWORD *)a2 + 2) = *(_DWORD *)(v29 + 2);
  *(_DWORD *)(v5 + 6) = *(_DWORD *)(v29 + 6);
  v32 = *(_DWORD *)a2;
  *(_DWORD *)(*(_DWORD *)a2 + 10) = *(_DWORD *)(v29 + 10);
  *(_DWORD *)(v32 + 14) = *(_DWORD *)(v29 + 14);
  *(_DWORD *)(v32 + 18) = *(_DWORD *)(v29 + 18);
  *(_DWORD *)(v32 + 22) = *(_DWORD *)(v29 + 22);
  v53 = &off_807F538;
  v54 = 0;
  v55 = 0;
  v56 = 0;
  v57 = 0;
  v58 = 0;
  v59 = 0;
  sub_8052530((int)&v60);
  v7 = v55;
  v60 = 3;
  if ( v55 == v56 )
  {
    sub_8057B40(v6, v5, (int)&v54, v55, (int)&v60);
  }
  else
  {
    if ( v55 )
    {
      v9 = 0;
      v8 = v58 - (_DWORD)v57;
      *(_WORD *)v55 = 3;
      *(_DWORD *)(v55 + 4) = 0;
      *(_DWORD *)(v55 + 8) = 0;
      *(_DWORD *)(v55 + 12) = 0;
      if ( v8 )
        v9 = operator new(v6, v5);
      v33 = v9 + v8;
      *(_DWORD *)(v7 + 4) = v9;
      *(_DWORD *)(v7 + 8) = v9;
      v34 = v58;
      *(_DWORD *)(v7 + 12) = v33;
      v35 = v34 - (_DWORD)v57;
      memmove((void *)v9, v57, v35);
      *(_DWORD *)(v7 + 8) = v9 + v35;
      v7 = v55;
    }
    v55 = v7 + 16;
  }
  if ( v57 )
    operator delete(v6, v5);
  v61 = 0;
  v62 = 0;
  v63 = 0;
  sub_80525A0((int)&v64, *(_WORD *)(a1 + 32));
  v12 = v55;
  v64 = 5;
  if ( v55 == v56 )
  {
    sub_8057B40(v11, v10, (int)&v54, v55, (int)&v64);
  }
  else
  {
    if ( v55 )
    {
      v14 = 0;
      v13 = v62 - (_DWORD)v61;
      *(_WORD *)v55 = 5;
      *(_DWORD *)(v55 + 4) = 0;
      *(_DWORD *)(v55 + 8) = 0;
      *(_DWORD *)(v55 + 12) = 0;
      if ( v13 )
        v14 = operator new(v11, v10);
      v36 = v14 + v13;
      *(_DWORD *)(v12 + 4) = v14;
      *(_DWORD *)(v12 + 8) = v14;
      v37 = v62;
      *(_DWORD *)(v12 + 12) = v36;
      v38 = v37 - (_DWORD)v61;
      memmove((void *)v14, v61, v38);
      *(_DWORD *)(v12 + 8) = v14 + v38;
      v12 = v55;
    }
    v55 = v12 + 16;
  }
  if ( v61 )
    operator delete(v11, v10);
  v65 = 0;
  v66 = 0;
  v67 = 0;
  sub_80525A0((int)&v68, 1);
  v17 = v55;
  v68 = 10;
  if ( v55 == v56 )
  {
    sub_8057B40(v16, v15, (int)&v54, v55, (int)&v68);
  }
  else
  {
    if ( v55 )
    {
      v19 = 0;
      v18 = v66 - (_DWORD)v65;
      *(_WORD *)v55 = 10;
      *(_DWORD *)(v55 + 4) = 0;
      *(_DWORD *)(v55 + 8) = 0;
      *(_DWORD *)(v55 + 12) = 0;
      if ( v18 )
        v19 = operator new(v16, v15);
      v39 = v19 + v18;
      *(_DWORD *)(v17 + 4) = v19;
      *(_DWORD *)(v17 + 8) = v19;
      v40 = v66;
      *(_DWORD *)(v17 + 12) = v39;
      v41 = v40 - (_DWORD)v65;
      memmove((void *)v19, v65, v41);
      *(_DWORD *)(v17 + 8) = v19 + v41;
      v17 = v55;
    }
    v55 = v17 + 16;
  }
  if ( v65 )
    operator delete(v16, v15);
  v20 = v55;
  v69 = 0;
  v70 = 0;
  v71 = 0;
  v72 = 15;
  if ( v55 == v56 )
  {
    sub_8057B40(v16, v15, (int)&v54, v55, (int)&v72);
  }
  else
  {
    if ( v55 )
    {
      *(_DWORD *)(v55 + 4) = 0;
      v42 = v69;
      *(_DWORD *)(v55 + 8) = 0;
      v43 = v71;
      *(_WORD *)v55 = 15;
      *(_DWORD *)(v55 + 12) = 0;
      v44 = v43 - (_DWORD)v42;
      memmove(0, v42, v44);
      *(_DWORD *)(v20 + 8) = v44;
      v20 = v55;
    }
    v55 = v20 + 16;
  }
  if ( v69 )
    operator delete(v16, v15);
  v73 = 0;
  v74 = 0;
  v75 = 0;
  sub_804B500(v16, v15, (int)&v73, (int)&v48);
  v23 = v55;
  v76 = 10001;
  if ( v55 == v56 )
  {
    sub_8057B40(v22, v21, (int)&v54, v55, (int)&v76);
  }
  else
  {
    if ( v55 )
    {
      v25 = 0;
      v24 = v74 - (_DWORD)v73;
      *(_WORD *)v55 = 10001;
      *(_DWORD *)(v55 + 4) = 0;
      *(_DWORD *)(v55 + 8) = 0;
      *(_DWORD *)(v55 + 12) = 0;
      if ( v24 )
        v25 = operator new(v22, v21);
      v45 = v25 + v24;
      *(_DWORD *)(v23 + 4) = v25;
      *(_DWORD *)(v23 + 8) = v25;
      v46 = v74;
      *(_DWORD *)(v23 + 12) = v45;
      v47 = v46 - (_DWORD)v73;
      memmove((void *)v25, v73, v47);
      *(_DWORD *)(v23 + 8) = v25 + v47;
      v23 = v55;
    }
    v55 = v23 + 16;
  }
  if ( v73 )
    operator delete(v22, v21);
  sub_80529E0((int)&v53, a2, 26);
  sub_8052390(v28, v27, (int)&v53);
  result = v48;
  if ( v48 )
    result = operator delete(v28, v27);
  return result;
}

//----- (08056300) --------------------------------------------------------
int __fastcall sub_8056300(int a1, int a2, int a3, int a4)
{
  int v4; // edi@1
  int v5; // esi@1
  int v6; // ebx@2
  int v7; // edx@6
  int v8; // ecx@6
  int v9; // esi@6
  int v10; // ebx@8
  int v11; // edi@8
  int v12; // edx@11
  int result; // eax@14
  int v14; // eax@10
  int v15; // ebx@10
  size_t v16; // ebx@10
  int v17; // [sp+30h] [bp-18h]@6
  int v18; // [sp+34h] [bp-14h]@6
  int v19; // [sp+38h] [bp-10h]@6
  const void *v20; // [sp+24h] [bp-24h]@6
  int v21; // [sp+28h] [bp-20h]@6
  int v22; // [sp+2Ch] [bp-1Ch]@6
  __int16 v23; // [sp+20h] [bp-28h]@6

  v4 = *(_DWORD *)a4;
  v5 = *(_DWORD *)(a4 + 4);
  if ( *(_DWORD *)a4 != v5 )
  {
    v6 = *(_DWORD *)a4;
    do
    {
      if ( *(_DWORD *)(v6 + 4) )
        operator delete(a1, a2);
      v6 += 16;
    }
    while ( v5 != v6 );
  }
  v17 = 0;
  v18 = 0;
  v19 = 0;
  *(_DWORD *)(a4 + 4) = v4;
  sub_8055D40(a3 + 16, (int)&v17);
  v20 = 0;
  v21 = 0;
  v22 = 0;
  sub_804B500(v8, (int)&v17, (int)&v20, (int)&v17);
  v7 = a4;
  v23 = 5;
  v9 = *(_DWORD *)(a4 + 4);
  if ( v9 == *(_DWORD *)(a4 + 8) )
  {
    sub_8057B40(v8, a4, a4, v9, (int)&v23);
  }
  else
  {
    if ( v9 )
    {
      v11 = 0;
      v10 = v21 - (_DWORD)v20;
      *(_WORD *)v9 = 5;
      *(_DWORD *)(v9 + 4) = 0;
      *(_DWORD *)(v9 + 8) = 0;
      *(_DWORD *)(v9 + 12) = 0;
      if ( v10 )
        v11 = operator new(v8, v7);
      v14 = v11 + v10;
      *(_DWORD *)(v9 + 4) = v11;
      *(_DWORD *)(v9 + 8) = v11;
      v15 = v21;
      *(_DWORD *)(v9 + 12) = v14;
      v16 = v15 - (_DWORD)v20;
      memmove((void *)v11, v20, v16);
      *(_DWORD *)(v9 + 8) = v11 + v16;
      v9 = *(_DWORD *)(a4 + 4);
    }
    v12 = a4;
    *(_DWORD *)(a4 + 4) = v9 + 16;
  }
  if ( v20 )
    operator delete(v8, v12);
  result = v17;
  if ( v17 )
    result = operator delete(v8, v12);
  return result;
}

//----- (08056490) --------------------------------------------------------
int __fastcall sub_8056490(int a1, int a2, int a3)
{
  int result; // eax@1

  result = *(_DWORD *)a3;
  if ( *(_DWORD *)a3 )
  {
    a3 = *(_DWORD *)a3;
    result = operator delete(a1, a2);
  }
  return result;
}

//----- (080564B0) --------------------------------------------------------
int __fastcall sub_80564B0(int a1, int a2, int a3, const void *a4, int a5)
{
  size_t v5; // ebx@1
  int v6; // edi@1
  void *v7; // esi@1
  int v8; // edx@2
  int v9; // ecx@2
  int v10; // esi@2
  int result; // eax@4
  size_t v12; // eax@6
  int v13; // eax@2
  const void *v14; // ebx@7
  int v15; // esi@7
  void *v16; // ST00_4@7
  int v17; // [sp+18h] [bp-10h]@7

  v6 = a3;
  v5 = a5 - (_DWORD)a4;
  v7 = *(void **)a3;
  if ( a5 - (_DWORD)a4 <= (unsigned int)(*(_DWORD *)(a3 + 8) - *(_DWORD *)a3) )
  {
    v12 = *(_DWORD *)(a3 + 4) - (_DWORD)v7;
    if ( v5 <= v12 )
    {
      memmove(v7, a4, a5 - (_DWORD)a4);
      result = (int)((char *)v7 + v5);
      *(_DWORD *)(v6 + 4) = (char *)v7 + v5;
    }
    else
    {
      v14 = (char *)a4 + v12;
      memmove(*(void **)a3, a4, v12);
      v15 = *(_DWORD *)(v6 + 4);
      v16 = *(void **)(v6 + 4);
      v17 = a5 - (_DWORD)v14;
      result = (int)memmove(v16, v14, a5 - (_DWORD)v14);
      *(_DWORD *)(v6 + 4) = v17 + v15;
    }
  }
  else
  {
    v13 = operator new(a1, a2);
    v10 = v13;
    memmove((void *)v13, a4, v5);
    if ( *(_DWORD *)v6 )
      operator delete(v9, v8);
    result = v10 + v5;
    *(_DWORD *)v6 = v10;
    *(_DWORD *)(v6 + 4) = v10 + v5;
    *(_DWORD *)(v6 + 8) = v10 + v5;
  }
  return result;
}

//----- (08056580) --------------------------------------------------------
#error "805678F: invalid basic block (funcsize=172)"

//----- (08056790) --------------------------------------------------------
int __cdecl sub_8056790(int a1, unsigned int a2, char a3)
{
  int v3; // ecx@1
  int result; // eax@2
  char v5; // [sp+1Ch] [bp-Ch]@1

  v5 = a3;
  v3 = *(_DWORD *)(a1 + 4) - *(_DWORD *)a1;
  if ( a2 >= v3 )
  {
    result = sub_8056580(a1, *(_DWORD *)(a1 + 4), a2 - v3, &v5);
  }
  else
  {
    result = a2 + *(_DWORD *)a1;
    *(_DWORD *)(a1 + 4) = result;
  }
  return result;
}

//----- (080567F0) --------------------------------------------------------
int __fastcall sub_80567F0(int a1, int a2, int a3)
{
  int v3; // edi@1
  int v4; // esi@1
  int v5; // ebx@2
  int result; // eax@6
  int v7; // [sp+0h] [bp-18h]@4

  v3 = *(_DWORD *)a3;
  v4 = *(_DWORD *)(a3 + 4);
  if ( *(_DWORD *)a3 != v4 )
  {
    v5 = *(_DWORD *)a3;
    do
    {
      if ( *(_DWORD *)(v5 + 4) )
      {
        v7 = *(_DWORD *)(v5 + 4);
        operator delete(a1, a2);
      }
      v5 += 16;
    }
    while ( v4 != v5 );
  }
  result = a3;
  *(_DWORD *)(a3 + 4) = v3;
  return result;
}

//----- (08056830) --------------------------------------------------------
int __fastcall sub_8056830(int a1, int a2, int a3, int a4, int a5)
{
  int v4; // edi@2
  int v5; // edx@4
  int v6; // ebx@4
  int v7; // esi@4
  __int16 v9; // ax@4
  int v10; // edx@6
  int v11; // eax@6
  int v12; // ebx@6
  int v13; // [sp+14h] [bp-14h]@2
  int v14; // [sp+18h] [bp-10h]@2

  if ( a3 != a4 )
  {
    v4 = a5;
    v13 = a5 + 16;
    v14 = a5 + 16;
    do
    {
      if ( v4 )
      {
        v5 = a3;
        v7 = 0;
        *(_DWORD *)(v4 + 12) = 0;
        v6 = *(_DWORD *)(v5 + 8) - *(_DWORD *)(v5 + 4);
        v9 = *(_WORD *)v5;
        *(_DWORD *)(v4 + 4) = 0;
        *(_DWORD *)(v4 + 8) = 0;
        *(_WORD *)v4 = v9;
        if ( v6 )
          v7 = operator new(a1, v5);
        v10 = a3;
        *(_DWORD *)(v4 + 4) = v7;
        *(_DWORD *)(v4 + 8) = v7;
        *(_DWORD *)(v4 + 12) = v7 + v6;
        v11 = *(_DWORD *)(v10 + 4);
        v12 = v7 + *(_DWORD *)(v10 + 8) - v11;
        memmove((void *)v7, *(const void **)(v10 + 4), *(_DWORD *)(v10 + 8) - v11);
        *(_DWORD *)(v4 + 8) = v12;
      }
      a3 += 16;
      v4 = v14;
      v14 += 16;
    }
    while ( a4 != a3 );
    a5 = v4;
  }
  return a5;
}

//----- (08056930) --------------------------------------------------------
int __cdecl sub_8056930(int a1, int a2)
{
  unsigned int v2; // eax@1
  int v3; // ecx@1
  int v4; // ebx@1
  int v5; // esi@1
  int v6; // eax@4
  int v7; // edi@5
  int v8; // ebx@7
  int v9; // esi@7
  int v10; // eax@10
  int result; // eax@12
  int v12; // edx@13
  int v13; // ecx@13
  int v14; // ebx@15
  int v15; // ecx@16
  __int16 v16; // ax@1
  signed int v17; // eax@1
  int v18; // edx@4
  int v19; // edx@4
  __int16 v20; // ax@7
  int v21; // eax@9
  int v22; // ebx@9
  size_t v23; // ebx@9
  int v24; // eax@13
  int v25; // [sp+14h] [bp-24h]@1
  int v26; // [sp+1Ch] [bp-1Ch]@1
  int v27; // [sp+20h] [bp-18h]@4
  int v28; // [sp+18h] [bp-20h]@4
  int v29; // [sp+24h] [bp-14h]@5
  int v30; // [sp+28h] [bp-10h]@5

  v4 = 0;
  v5 = a2;
  *(_WORD *)a1 = *(_WORD *)a2;
  v25 = a1 + 4;
  std__string__string(a1 + 4, v5 + 4);
  v16 = *(_WORD *)(v5 + 8);
  v26 = 0;
  *(_DWORD *)(a1 + 24) = 0;
  *(_WORD *)(a1 + 8) = v16;
  *(_WORD *)(a1 + 10) = *(_WORD *)(v5 + 10);
  *(_WORD *)(a1 + 12) = *(_WORD *)(v5 + 12);
  *(_WORD *)(a1 + 14) = *(_WORD *)(v5 + 14);
  v17 = *(_DWORD *)(v5 + 20) - *(_DWORD *)(v5 + 16);
  *(_DWORD *)(a1 + 20) = 0;
  *(_DWORD *)(a1 + 16) = 0;
  v2 = v17 >> 4;
  if ( v2 )
  {
    if ( v2 > 0xFFFFFFF )
    {
      v24 = std____throw_bad_alloc();
      __cxa_begin_catch(v24);
      v12 = v30;
      if ( v26 != v30 )
      {
        do
        {
          sub_8056490(v13, v12, v27 + 4);
          v27 += 16;
          v12 = v27;
        }
        while ( v30 != v27 );
      }
      v14 = __cxa_rethrow();
      while ( 1 )
      {
        do
        {
          std__string___string(v25);
          v14 = _Unwind_Resume(v14);
          __cxa_end_catch();
        }
        while ( !*(_DWORD *)(a1 + 16) );
        operator delete(v15, a1);
      }
    }
    v4 = 16 * v2;
    v26 = operator new(v3, a1);
  }
  v18 = v26;
  *(_DWORD *)(a1 + 16) = v26;
  *(_DWORD *)(a1 + 20) = v18;
  *(_DWORD *)(a1 + 24) = v4 + v18;
  v19 = *(_DWORD *)(v5 + 20);
  v27 = v26;
  v6 = *(_DWORD *)(v5 + 16);
  v28 = v19;
  if ( v19 != v6 )
  {
    v7 = v6;
    v29 = v26 + 16;
    v30 = v26;
    do
    {
      if ( v30 )
      {
        v9 = 0;
        v8 = *(_DWORD *)(v7 + 8) - *(_DWORD *)(v7 + 4);
        v20 = *(_WORD *)v7;
        *(_DWORD *)(v30 + 4) = 0;
        *(_WORD *)v30 = v20;
        *(_DWORD *)(v30 + 8) = 0;
        *(_DWORD *)(v30 + 12) = 0;
        if ( v8 )
          v9 = operator new(v3, v30);
        *(_DWORD *)(v30 + 4) = v9;
        *(_DWORD *)(v30 + 8) = v9;
        v21 = v9 + v8;
        v22 = *(_DWORD *)(v7 + 8);
        *(_DWORD *)(v30 + 12) = v21;
        v23 = v22 - *(_DWORD *)(v7 + 4);
        memmove((void *)v9, *(const void **)(v7 + 4), v23);
        *(_DWORD *)(v30 + 8) = v9 + v23;
      }
      v10 = v29;
      v7 += 16;
      v29 += 16;
      v30 = v10;
    }
    while ( v28 != v7 );
    v27 = v10;
  }
  result = v27;
  *(_DWORD *)(a1 + 20) = v27;
  return result;
}

//----- (08056B00) --------------------------------------------------------
int __cdecl sub_8056B00(int a1, int a2, int a3, int a4, int a5)
{
  int v5; // edi@1
  int v6; // edx@2
  int v7; // ecx@2
  int v8; // ebx@2
  int v9; // esi@2
  unsigned int v10; // edx@5
  int v11; // ecx@5
  int v12; // ebx@5
  int v15; // ecx@11
  int v16; // eax@2
  char v17; // al@3
  int v18; // eax@4
  int v25; // [sp+18h] [bp-20h]@2
  char v26; // [sp+2Bh] [bp-Dh]@2
  int v27; // [sp+24h] [bp-14h]@5
  char v28; // [sp+2Ah] [bp-Eh]@13

  v5 = a5;
  if ( a5 == a4 )
  {
    v9 = 134771820;
  }
  else
  {
    v25 = a5 - a4;
    v16 = std__string___Rep___S_create(a5 - a4, 0, &v26);
    v6 = a4;
    v9 = v16 + 12;
    v8 = v16;
    v7 = v16 + 12;
    do
    {
      v17 = *(_BYTE *)v6++;
      *(_BYTE *)v7++ = v17;
    }
    while ( v5 != v6 );
    v18 = v25;
    *(_DWORD *)(v8 + 8) = 0;
    *(_DWORD *)v8 = v18;
    *(_BYTE *)(v8 + v18 + 12) = 0;
  }
  v27 = v9;
  v12 = a3 - a2;
  v10 = *(_DWORD *)(v9 - 12);
  v11 = *(_DWORD *)a1;
  if ( v10 > a3 - a2 - *(_DWORD *)(*(_DWORD *)a1 - 12) + 1073741820 )
  {
    std____throw_length_error(v11);
  }
  else
  {
    a2 -= v11;
    v12 = std__string___M_replace_safe(a1, a2, v12, v9, v10);
    _EDX = v27 - 12;
    if ( v27 - 12 == (_DWORD)std__string___Rep___S_empty_rep_storage )
      return v12;
  }
  if ( pthread_cancel )
  {
    _EAX = -1;
    __asm { lock xadd [edx+8], eax }
    v15 = _EAX;
  }
  else
  {
    v15 = *(_DWORD *)(_EDX + 8);
    *(_DWORD *)(_EDX + 8) = v15 - 1;
  }
  if ( v15 <= 0 )
    std__string___Rep___M_destroy(_EDX, &v28);
  return v12;
}

//----- (08056C30) --------------------------------------------------------
int __cdecl sub_8056C30(int a1, int a2, int a3)
{
  return sub_8056B00(a1, *(_DWORD *)a1, *(_DWORD *)(*(_DWORD *)a1 - 12) + *(_DWORD *)a1, a2, a3);
}

//----- (08056C70) --------------------------------------------------------
int __cdecl sub_8056C70(int a1, int a2)
{
  int v2; // edx@2
  int v3; // ebx@2
  int v4; // edi@2
  int v5; // eax@3
  int v6; // ecx@3
  int v7; // esi@5
  signed int v9; // esi@15
  int v10; // edi@19
  int v11; // edx@21
  int v12; // ebx@21
  int v13; // esi@21
  int v14; // eax@27
  int v15; // edx@27
  int v16; // ebx@30
  int v17; // esi@30
  int v18; // ecx@34
  int v19; // ebx@34
  int v20; // esi@34
  int v21; // edx@43
  int v22; // ecx@43
  int v23; // ebx@43
  int v24; // edx@45
  int v25; // ecx@45
  int v26; // edx@48
  int v27; // ecx@48
  int v28; // eax@50
  int v29; // edx@2
  int v30; // edx@2
  int v31; // eax@6
  int v32; // ST04_4@6
  int v33; // eax@6
  signed int v34; // eax@15
  int v35; // eax@16
  int v36; // ST04_4@16
  int v37; // eax@16
  __int16 v38; // ax@21
  int v39; // ecx@23
  int v40; // eax@23
  int v41; // ebx@23
  __int16 v42; // ax@30
  int v43; // eax@32
  int v44; // ebx@32
  size_t v45; // ebx@32
  int v46; // eax@43
  int v47; // eax@44
  int v48; // eax@45
  int v49; // ebx@48
  int v50; // ebx@51
  int v51; // [sp+3Ch] [bp-1Ch]@2
  unsigned int v52; // [sp+24h] [bp-34h]@2
  int v53; // [sp+28h] [bp-30h]@2
  int v54; // [sp+20h] [bp-38h]@3
  int v55; // [sp+38h] [bp-20h]@12
  int v56; // [sp+30h] [bp-28h]@18
  int v57; // [sp+34h] [bp-24h]@18
  int v58; // [sp+1Ch] [bp-3Ch]@19
  int v59; // [sp+44h] [bp-14h]@19
  int v60; // [sp+48h] [bp-10h]@27
  int v61; // [sp+40h] [bp-18h]@28
  int v62; // [sp+2Ch] [bp-2Ch]@28

  if ( a2 != a1 )
  {
    v29 = *(_DWORD *)(a2 + 4);
    v51 = *(_DWORD *)(a2 + 4);
    v4 = *(_DWORD *)a2;
    v30 = (v29 - *(_DWORD *)a2) >> 4;
    v52 = v30;
    v53 = v30;
    v3 = *(_DWORD *)a1;
    v2 = *(_DWORD *)a1;
    if ( v52 > (*(_DWORD *)(a1 + 8) - *(_DWORD *)a1) >> 4 )
    {
      if ( v52 > 0xFFFFFFF )
      {
        v46 = std____throw_bad_alloc();
        __cxa_begin_catch(v46);
        v23 = v60;
        while ( v23 != v62 )
        {
          v47 = v23 + 4;
          v23 += 16;
          sub_8056490(v22, v21, v47);
        }
        v48 = __cxa_rethrow();
        __cxa_begin_catch(v48);
        if ( v54 != v4 )
        {
          while ( 1 )
          {
            sub_8056490(v25, v24, v56 + 4);
            v25 = v58;
            v56 = v58;
            if ( v4 == v58 )
              break;
            v58 += 16;
          }
        }
        v49 = __cxa_rethrow();
        __cxa_end_catch();
        __cxa_begin_catch(v49);
        if ( v60 )
          operator delete(v27, v26);
        v28 = __cxa_rethrow();
        while ( 1 )
        {
          v50 = v28;
          __cxa_end_catch();
          v28 = _Unwind_Resume(v50);
        }
      }
      v55 = 16 * v52;
      v14 = operator new(a2, v2);
      v60 = v14;
      if ( v51 != v4 )
      {
        v15 = v60;
        v61 = v14 + 16;
        v62 = v60;
        do
        {
          if ( v62 )
          {
            v17 = 0;
            v16 = *(_DWORD *)(v4 + 8) - *(_DWORD *)(v4 + 4);
            v42 = *(_WORD *)v4;
            *(_DWORD *)(v62 + 4) = 0;
            *(_WORD *)v62 = v42;
            *(_DWORD *)(v62 + 8) = 0;
            *(_DWORD *)(v62 + 12) = 0;
            if ( v16 )
              v17 = operator new(v62, v15);
            *(_DWORD *)(v62 + 4) = v17;
            *(_DWORD *)(v62 + 8) = v17;
            v43 = v17 + v16;
            v44 = *(_DWORD *)(v4 + 8);
            *(_DWORD *)(v62 + 12) = v43;
            v45 = v44 - *(_DWORD *)(v4 + 4);
            memmove((void *)v17, *(const void **)(v4 + 4), v45);
            *(_DWORD *)(v62 + 8) = v17 + v45;
          }
          v15 = v61;
          v4 += 16;
          v61 += 16;
          v62 = v15;
        }
        while ( v51 != v4 );
      }
      v18 = a1;
      v20 = *(_DWORD *)(a1 + 4);
      v19 = *(_DWORD *)a1;
      if ( v20 != *(_DWORD *)a1 )
      {
        do
        {
          if ( *(_DWORD *)(v19 + 4) )
            operator delete(v18, v15);
          v19 += 16;
        }
        while ( v20 != v19 );
        v15 = a1;
        v19 = *(_DWORD *)a1;
      }
      if ( v19 )
        operator delete(v18, v15);
      *(_DWORD *)a1 = v60;
      *(_DWORD *)(a1 + 8) = v55 + v60;
      goto LABEL_13;
    }
    v6 = *(_DWORD *)(a1 + 4);
    v5 = (v6 - v3) >> 4;
    v54 = *(_DWORD *)(a1 + 4);
    if ( v52 > v5 )
    {
      v34 = 16 * v5;
      v9 = v34 >> 4;
      if ( v34 >> 4 > 0 )
      {
        do
        {
          --v9;
          *(_WORD *)v3 = *(_WORD *)v4;
          v35 = v4 + 4;
          v4 += 16;
          v36 = v35;
          v37 = v3 + 4;
          v3 += 16;
          sub_804B500(v6, v2, v37, v36);
        }
        while ( v9 > 0 );
        v51 = *(_DWORD *)(a2 + 4);
        v4 = *(_DWORD *)a2;
        v6 = *(_DWORD *)(a1 + 4);
        v2 = *(_DWORD *)a1;
        v54 = *(_DWORD *)(a1 + 4);
      }
      v56 = v54;
      v57 = v4 + ((v54 - v2) & 0xFFFFFFF0);
      if ( v4 + ((v54 - v2) & 0xFFFFFFF0) == v51 )
      {
        v55 = 16 * v52;
        goto LABEL_13;
      }
      v10 = v54;
      v58 = v54 + 16;
      v59 = v54 + 16;
      do
      {
        if ( v10 )
        {
          v11 = v57;
          v13 = 0;
          *(_DWORD *)(v10 + 12) = 0;
          v12 = *(_DWORD *)(v11 + 8) - *(_DWORD *)(v11 + 4);
          v38 = *(_WORD *)v11;
          *(_DWORD *)(v10 + 4) = 0;
          *(_DWORD *)(v10 + 8) = 0;
          *(_WORD *)v10 = v38;
          if ( v12 )
            v13 = operator new(v6, v11);
          v39 = v57;
          *(_DWORD *)(v10 + 4) = v13;
          *(_DWORD *)(v10 + 8) = v13;
          *(_DWORD *)(v10 + 12) = v13 + v12;
          v40 = *(_DWORD *)(v39 + 4);
          v41 = v13 + *(_DWORD *)(v39 + 8) - v40;
          memmove((void *)v13, *(const void **)(v6 + 4), *(_DWORD *)(v6 + 8) - v40);
          *(_DWORD *)(v10 + 8) = v41;
        }
        v57 += 16;
        v10 = v59;
        v59 += 16;
      }
      while ( v51 != v57 );
    }
    else
    {
      if ( (signed int)v52 > 0 )
      {
        v7 = v3;
        do
        {
          *(_WORD *)v7 = *(_WORD *)v4;
          v31 = v4 + 4;
          v4 += 16;
          v32 = v31;
          v33 = v7 + 4;
          v7 += 16;
          sub_804B500(v6, v2, v33, v32);
          --v53;
        }
        while ( v53 > 0 );
        v3 += 16 * v52;
      }
      if ( v3 != v54 )
      {
        do
        {
          if ( *(_DWORD *)(v3 + 4) )
            operator delete(v6, v2);
          v3 += 16;
        }
        while ( v54 != v3 );
        v55 = 16 * v52;
        goto LABEL_13;
      }
    }
    v55 = 16 * v52;
LABEL_13:
    v55 += *(_DWORD *)a1;
    *(_DWORD *)(a1 + 4) = v55;
  }
  return a1;
}

//----- (08057010) --------------------------------------------------------
int __fastcall sub_8057010(int a1, int a2, int a3, int a4, int a5)
{
  int v4; // edx@1
  unsigned int v5; // eax@3
  int v6; // ecx@3
  int v7; // ebx@3
  int v8; // esi@3
  int v9; // eax@6
  int v10; // edi@7
  int v11; // ebx@9
  int v12; // esi@9
  int v13; // eax@12
  int v14; // eax@15
  int v15; // edx@15
  int v16; // ecx@15
  int v17; // ebx@15
  int v18; // edi@19
  int v19; // ebx@21
  int v20; // esi@21
  int v21; // eax@24
  int v22; // ebx@26
  int i; // esi@26
  int result; // eax@28
  int v25; // eax@29
  int v26; // edx@30
  int v27; // edx@32
  int v28; // ebx@36
  int v29; // eax@39
  int v30; // ebx@39
  int v31; // eax@42
  int v32; // edi@43
  int v33; // ebx@45
  int v34; // esi@45
  int v35; // edx@53
  unsigned int v36; // eax@56
  int v37; // ebx@56
  int v38; // eax@59
  int v39; // edi@60
  int v40; // ebx@62
  int v41; // esi@62
  int v42; // eax@69
  int v43; // ebx@69
  int v44; // edx@78
  int v45; // ecx@78
  int v46; // ebx@78
  int v47; // eax@80
  int v48; // edx@81
  int v49; // ecx@81
  int v50; // ebx@82
  int v51; // edx@88
  int v52; // ecx@88
  int v53; // ebx@88
  int v54; // ebx@90
  int v55; // edx@91
  int v56; // ecx@91
  int v57; // ebx@93
  int v58; // ecx@95
  int v59; // edx@97
  int v60; // ecx@97
  int v61; // edx@3
  __int16 v62; // ax@3
  signed int v63; // eax@3
  int v64; // edx@6
  int v65; // edx@6
  __int16 v66; // ax@9
  int v67; // eax@11
  int v68; // ebx@11
  size_t v69; // ebx@11
  int v70; // eax@15
  __int16 v71; // ax@21
  int v72; // eax@23
  int v73; // ebx@23
  size_t v74; // ebx@23
  int v75; // edx@26
  int v76; // eax@26
  int v77; // edi@27
  int v78; // ecx@28
  int v79; // edx@28
  unsigned __int8 v80; // cf@32
  char v81; // zf@36
  int v82; // edx@42
  __int16 v83; // ax@45
  int v84; // eax@47
  int v85; // ebx@47
  size_t v86; // ebx@47
  signed int v87; // eax@56
  int v88; // edx@59
  __int16 v89; // ax@62
  int v90; // eax@64
  int v91; // ebx@64
  size_t v92; // ebx@64
  int v93; // ST00_4@70
  int v94; // eax@78
  int v95; // ST00_4@79
  int v96; // ebx@81
  int v97; // ST00_4@83
  int v98; // eax@88
  int v99; // eax@89
  int v100; // eax@91
  int v101; // [sp+5Ch] [bp-5Ch]@1
  signed int v102; // [sp+60h] [bp-58h]@1
  int v103; // [sp+20h] [bp-98h]@3
  int v104; // [sp+28h] [bp-90h]@3
  int v105; // [sp+2Ch] [bp-8Ch]@6
  int v106; // [sp+24h] [bp-94h]@6
  int v107; // [sp+68h] [bp-50h]@7
  int v108; // [sp+88h] [bp-30h]@7
  __int16 v109; // [sp+90h] [bp-28h]@15
  char v110; // [sp+94h] [bp-24h]@15
  int v111; // [sp+A8h] [bp-10h]@15
  __int16 v112; // [sp+98h] [bp-20h]@15
  __int16 v113; // [sp+9Ah] [bp-1Eh]@15
  __int16 v114; // [sp+9Ch] [bp-1Ch]@15
  __int16 v115; // [sp+9Eh] [bp-1Ah]@15
  int v116; // [sp+A0h] [bp-18h]@15
  int v117; // [sp+A4h] [bp-14h]@15
  int v118; // [sp+30h] [bp-88h]@15
  int v119; // [sp+10h] [bp-A8h]@15
  int v120; // [sp+34h] [bp-84h]@18
  int v121; // [sp+64h] [bp-54h]@19
  int v122; // [sp+84h] [bp-34h]@19
  signed int v123; // [sp+14h] [bp-A4h]@32
  int v124; // [sp+18h] [bp-A0h]@35
  int v125; // [sp+1Ch] [bp-9Ch]@36
  int v126; // [sp+3Ch] [bp-7Ch]@36
  int v127; // [sp+74h] [bp-44h]@37
  int v128; // [sp+38h] [bp-80h]@37
  int v129; // [sp+40h] [bp-78h]@39
  int v130; // [sp+48h] [bp-70h]@39
  int v131; // [sp+44h] [bp-74h]@42
  int v132; // [sp+80h] [bp-38h]@42
  int v133; // [sp+7Ch] [bp-3Ch]@53
  int v134; // [sp+78h] [bp-40h]@53
  int v135; // [sp+6Ch] [bp-4Ch]@54
  int v136; // [sp+70h] [bp-48h]@54
  int v137; // [sp+4Ch] [bp-6Ch]@56
  int v138; // [sp+54h] [bp-64h]@56
  int v139; // [sp+50h] [bp-68h]@59
  int v140; // [sp+58h] [bp-60h]@59

  v101 = a4;
  v4 = *(_DWORD *)(a3 + 4);
  v102 = *(_DWORD *)(a3 + 4);
  if ( v4 != *(_DWORD *)(a3 + 8) )
  {
    if ( v4 )
    {
      v7 = v4 - 28;
      *(_WORD *)v4 = *(_WORD *)(v4 - 28);
      v61 = v4 + 4;
      v103 = v61;
      std__string__string(v61, v102 - 24);
      v8 = 0;
      v62 = *(_WORD *)(v7 + 8);
      *(_DWORD *)(v102 + 24) = 0;
      *(_WORD *)(v102 + 8) = v62;
      *(_WORD *)(v102 + 10) = *(_WORD *)(v7 + 10);
      *(_WORD *)(v102 + 12) = *(_WORD *)(v7 + 12);
      *(_WORD *)(v102 + 14) = *(_WORD *)(v7 + 14);
      v63 = *(_DWORD *)(v7 + 20) - *(_DWORD *)(v7 + 16);
      *(_DWORD *)(v102 + 20) = 0;
      *(_DWORD *)(v102 + 16) = 0;
      v5 = v63 >> 4;
      v104 = 0;
      if ( v5 )
      {
        if ( v5 > 0xFFFFFFF )
        {
          v57 = std____throw_bad_alloc();
          __cxa_end_catch();
          if ( v116 )
            operator delete(v60, v59);
          std__string___string(&v110);
          goto LABEL_88;
        }
        v8 = 16 * v5;
        v104 = operator new(v6, v102);
      }
      v64 = v104;
      *(_DWORD *)(v102 + 16) = v104;
      *(_DWORD *)(v102 + 20) = v64;
      *(_DWORD *)(v102 + 24) = v8 + v64;
      v65 = *(_DWORD *)(v7 + 20);
      v105 = v104;
      v9 = *(_DWORD *)(v7 + 16);
      v106 = v65;
      if ( v65 != v9 )
      {
        v10 = v9;
        v107 = v104 + 16;
        v108 = v104;
        do
        {
          if ( v108 )
          {
            v12 = 0;
            v11 = *(_DWORD *)(v10 + 8) - *(_DWORD *)(v10 + 4);
            v66 = *(_WORD *)v10;
            *(_DWORD *)(v108 + 4) = 0;
            *(_WORD *)v108 = v66;
            *(_DWORD *)(v108 + 8) = 0;
            *(_DWORD *)(v108 + 12) = 0;
            if ( v11 )
              v12 = operator new(v6, v108);
            *(_DWORD *)(v108 + 4) = v12;
            *(_DWORD *)(v108 + 8) = v12;
            v67 = v12 + v11;
            v68 = *(_DWORD *)(v10 + 8);
            *(_DWORD *)(v108 + 12) = v67;
            v69 = v68 - *(_DWORD *)(v10 + 4);
            memmove((void *)v12, *(const void **)(v10 + 4), v69);
            *(_DWORD *)(v108 + 8) = v12 + v69;
          }
          v13 = v107;
          v10 += 16;
          v107 += 16;
          v108 = v13;
        }
        while ( v106 != v10 );
        v105 = v13;
      }
      *(_DWORD *)(v102 + 20) = v105;
      v102 = *(_DWORD *)(a3 + 4);
    }
    v17 = 0;
    *(_DWORD *)(a3 + 4) = v102 + 28;
    v109 = *(_WORD *)a5;
    std__string__string(&v110, a5 + 4);
    v111 = 0;
    v112 = *(_WORD *)(a5 + 8);
    v113 = *(_WORD *)(a5 + 10);
    v114 = *(_WORD *)(a5 + 12);
    v115 = *(_WORD *)(a5 + 14);
    v15 = *(_DWORD *)(a5 + 16);
    v70 = *(_DWORD *)(a5 + 20);
    v116 = 0;
    v117 = 0;
    v118 = 0;
    v119 = v70;
    v14 = (v70 - v15) >> 4;
    if ( !v14 )
    {
LABEL_18:
      v116 = v118;
      v117 = v118;
      v111 = v17 + v118;
      v120 = v118;
      if ( v119 != v15 )
      {
        v18 = v15;
        v121 = v118 + 16;
        v122 = v118;
        do
        {
          if ( v122 )
          {
            v20 = 0;
            v19 = *(_DWORD *)(v18 + 8) - *(_DWORD *)(v18 + 4);
            v71 = *(_WORD *)v18;
            *(_DWORD *)(v122 + 4) = 0;
            *(_WORD *)v122 = v71;
            *(_DWORD *)(v122 + 8) = 0;
            *(_DWORD *)(v122 + 12) = 0;
            if ( v19 )
              v20 = operator new(v16, v122);
            *(_DWORD *)(v122 + 4) = v20;
            *(_DWORD *)(v122 + 8) = v20;
            v72 = v20 + v19;
            v73 = *(_DWORD *)(v18 + 8);
            *(_DWORD *)(v122 + 12) = v72;
            v74 = v73 - *(_DWORD *)(v18 + 4);
            memmove((void *)v20, *(const void **)(v18 + 4), v74);
            *(_DWORD *)(v122 + 8) = v20 + v74;
          }
          v21 = v121;
          v18 += 16;
          v121 += 16;
          v122 = v21;
        }
        while ( v119 != v18 );
        v120 = v21;
      }
      v117 = v120;
      v75 = *(_DWORD *)(a3 + 4);
      v22 = v75 - 28;
      v76 = (v75 - 56 - a4) >> 2;
      for ( i = -1227133513 * v76; i > 0; --i )
      {
        v77 = v22 - 56;
        v22 -= 28;
        *(_WORD *)v22 = *(_WORD *)(v22 - 28);
        std__string__assign(v22 + 4, v77 + 4);
        *(_WORD *)(v22 + 8) = *(_WORD *)(v22 - 20);
        *(_WORD *)(v22 + 10) = *(_WORD *)(v22 - 18);
        *(_WORD *)(v22 + 12) = *(_WORD *)(v22 - 16);
        *(_WORD *)(v22 + 14) = *(_WORD *)(v22 - 14);
        sub_8056C70(v22 + 16, v77 + 16);
      }
      *(_WORD *)a4 = v109;
      std__string__assign(a4 + 4, &v110);
      *(_WORD *)(a4 + 8) = v112;
      *(_WORD *)(a4 + 10) = v113;
      *(_WORD *)(a4 + 12) = v114;
      *(_WORD *)(a4 + 14) = v115;
      sub_8056C70(a4 + 16, (int)&v116);
      return sub_80549C0(v78, v79, (int)&v109);
    }
    if ( (unsigned int)v14 <= 0xFFFFFFF )
    {
      v17 = 16 * v14;
      v118 = operator new(v16, v15);
      v15 = *(_DWORD *)(a5 + 16);
      v119 = *(_DWORD *)(a5 + 20);
      goto LABEL_18;
    }
    v57 = std____throw_bad_alloc();
    __cxa_end_catch();
    if ( *(_DWORD *)(v102 + 16) )
      operator delete(v58, v102);
    std__string___string(v103);
LABEL_88:
    v98 = _Unwind_Resume(v57);
    __cxa_begin_catch(v98);
    v53 = v138;
    while ( v140 != v53 )
    {
      v99 = v53 + 4;
      v53 += 16;
      sub_8056490(v52, v51, v99);
    }
    v54 = __cxa_rethrow();
    __cxa_end_catch();
    v94 = _Unwind_Resume(v54);
    __cxa_begin_catch(v94);
    v46 = v125;
    while ( v133 != v46 )
    {
      v95 = v46;
      v46 += 28;
      sub_80549C0(v45, v44, v95);
    }
    v47 = __cxa_rethrow();
    while ( 1 )
    {
      v96 = v47;
      __cxa_end_catch();
      __cxa_begin_catch(v96);
      if ( v125 != v124 )
      {
        v50 = v124;
        do
        {
          v97 = v50;
          v50 += 28;
          sub_80549C0(v49, v48, v97);
        }
        while ( v125 != v50 );
      }
      if ( v124 )
        operator delete(v49, v124);
      v47 = __cxa_rethrow();
    }
  }
  v102 -= *(_DWORD *)a3;
  v102 >>= 2;
  v25 = -1227133513 * v102;
  if ( -1227133513 * v102 == 153391689 )
  {
    v100 = std____throw_length_error(a1);
    __cxa_begin_catch(v100);
    v55 = v108;
    if ( v104 != v108 )
    {
      do
      {
        sub_8056490(v56, v55, v105 + 4);
        v105 += 16;
      }
      while ( v105 != v108 );
    }
    v57 = __cxa_rethrow();
    goto LABEL_88;
  }
  v26 = -1227133513 * v102;
  if ( !v25 )
    v26 = 1;
  v80 = __MKCADD__(v25, v26);
  v27 = v25 + v26;
  v123 = v27;
  if ( v80 || (unsigned int)v27 > 0x9249249 )
  {
    v123 = 153391689;
    goto LABEL_77;
  }
  v124 = 0;
  if ( v27 )
LABEL_77:
    v124 = operator new(a1, v27);
  v125 = v124;
  v28 = v124;
  v81 = *(_DWORD *)a3 == a4;
  v126 = *(_DWORD *)a3;
  if ( !v81 )
  {
    v127 = v124 + 28;
    v128 = v124;
    do
    {
      if ( v128 )
      {
        *(_WORD *)v128 = *(_WORD *)v126;
        v129 = v128 + 4;
        std__string__string(v128 + 4, v126 + 4);
        v30 = 0;
        *(_WORD *)(v128 + 8) = *(_WORD *)(v126 + 8);
        *(_WORD *)(v128 + 10) = *(_WORD *)(v126 + 10);
        *(_WORD *)(v128 + 12) = *(_WORD *)(v126 + 12);
        *(_WORD *)(v128 + 14) = *(_WORD *)(v126 + 14);
        v29 = (*(_DWORD *)(v126 + 20) - *(_DWORD *)(v126 + 16)) >> 4;
        *(_DWORD *)(v128 + 16) = 0;
        *(_DWORD *)(v128 + 20) = 0;
        *(_DWORD *)(v128 + 24) = 0;
        v130 = 0;
        if ( v29 )
        {
          if ( (unsigned int)v29 > 0xFFFFFFF )
          {
            std____throw_bad_alloc();
LABEL_76:
            std____throw_bad_alloc();
            goto LABEL_77;
          }
          v30 = 16 * v29;
          v130 = operator new(a1, v128);
        }
        v82 = v130;
        *(_DWORD *)(v128 + 16) = v130;
        *(_DWORD *)(v128 + 20) = v82;
        *(_DWORD *)(v128 + 24) = v30 + v82;
        v131 = *(_DWORD *)(v126 + 20);
        v31 = *(_DWORD *)(v126 + 16);
        v132 = v130;
        if ( v131 != v31 )
        {
          v32 = v31;
          do
          {
            a1 = v132;
            if ( v132 )
            {
              v34 = 0;
              v33 = *(_DWORD *)(v32 + 8) - *(_DWORD *)(v32 + 4);
              v83 = *(_WORD *)v32;
              *(_DWORD *)(v132 + 4) = 0;
              *(_WORD *)v132 = v83;
              *(_DWORD *)(v132 + 8) = 0;
              *(_DWORD *)(v132 + 12) = 0;
              if ( v33 )
                v34 = operator new(v132, v132);
              *(_DWORD *)(v132 + 4) = v34;
              *(_DWORD *)(v132 + 8) = v34;
              v84 = v34 + v33;
              v85 = *(_DWORD *)(v32 + 8);
              *(_DWORD *)(v132 + 12) = v84;
              v86 = v85 - *(_DWORD *)(v32 + 4);
              memmove((void *)v34, *(const void **)(v32 + 4), v86);
              *(_DWORD *)(v132 + 8) = v34 + v86;
            }
            v132 += 16;
            v32 += 16;
          }
          while ( v131 != v32 );
        }
        *(_DWORD *)(v128 + 20) = v132;
      }
      v126 += 28;
      v28 = v127;
      v127 += 28;
      v128 = v28;
    }
    while ( a4 != v126 );
  }
  v125 = v28;
  if ( v28 )
    sub_8056930(v28, a5);
  v125 = v28 + 28;
  v35 = *(_DWORD *)(a3 + 4);
  v133 = v28 + 28;
  v134 = v35;
  if ( v35 != a4 )
  {
    v135 = a4;
    v136 = v28 + 56;
    do
    {
      if ( v133 )
      {
        *(_WORD *)v133 = *(_WORD *)v135;
        v137 = v133 + 4;
        std__string__string(v133 + 4, v135 + 4);
        v37 = 0;
        *(_WORD *)(v133 + 8) = *(_WORD *)(v135 + 8);
        *(_WORD *)(v133 + 10) = *(_WORD *)(v135 + 10);
        *(_WORD *)(v133 + 12) = *(_WORD *)(v135 + 12);
        *(_WORD *)(v133 + 14) = *(_WORD *)(v135 + 14);
        v87 = *(_DWORD *)(v135 + 20) - *(_DWORD *)(v135 + 16);
        v138 = 0;
        v36 = v87 >> 4;
        *(_DWORD *)(v133 + 16) = 0;
        *(_DWORD *)(v133 + 20) = 0;
        *(_DWORD *)(v133 + 24) = 0;
        if ( v36 )
        {
          if ( v36 > 0xFFFFFFF )
            goto LABEL_76;
          v37 = 16 * v36;
          v138 = operator new(a1, v133);
        }
        v88 = v138;
        *(_DWORD *)(v133 + 16) = v138;
        *(_DWORD *)(v133 + 20) = v88;
        *(_DWORD *)(v133 + 24) = v37 + v88;
        v139 = *(_DWORD *)(v135 + 20);
        v38 = *(_DWORD *)(v135 + 16);
        v140 = v138;
        if ( v139 != v38 )
        {
          v39 = v38;
          do
          {
            if ( v140 )
            {
              v41 = 0;
              v40 = *(_DWORD *)(v39 + 8) - *(_DWORD *)(v39 + 4);
              v89 = *(_WORD *)v39;
              *(_DWORD *)(v140 + 4) = 0;
              *(_WORD *)v140 = v89;
              *(_DWORD *)(v140 + 8) = 0;
              *(_DWORD *)(v140 + 12) = 0;
              if ( v40 )
                v41 = operator new(a1, v140);
              *(_DWORD *)(v140 + 4) = v41;
              *(_DWORD *)(v140 + 8) = v41;
              v90 = v41 + v40;
              v91 = *(_DWORD *)(v39 + 8);
              *(_DWORD *)(v140 + 12) = v90;
              v92 = v91 - *(_DWORD *)(v39 + 4);
              memmove((void *)v41, *(const void **)(v39 + 4), v92);
              *(_DWORD *)(v140 + 8) = v41 + v92;
            }
            v140 += 16;
            v39 += 16;
          }
          while ( v139 != v39 );
        }
        *(_DWORD *)(v133 + 20) = v140;
      }
      v135 += 28;
      v133 = v136;
      v136 += 28;
    }
    while ( v134 != v135 );
    v35 = *(_DWORD *)(a3 + 4);
    v101 = *(_DWORD *)(a3 + 4);
  }
  v43 = *(_DWORD *)a3;
  v42 = v101;
  if ( *(_DWORD *)a3 != v101 )
  {
    do
    {
      v93 = v43;
      v43 += 28;
      sub_80549C0(a1, v35, v93);
    }
    while ( v43 != v101 );
    v35 = a3;
    v42 = *(_DWORD *)a3;
  }
  if ( v42 )
    operator delete(a1, v35);
  *(_DWORD *)a3 = v124;
  *(_DWORD *)(a3 + 4) = v133;
  result = v124 + 28 * v123;
  *(_DWORD *)(a3 + 8) = v124 + 28 * v123;
  return result;
}

//----- (08057B40) --------------------------------------------------------
int __fastcall sub_8057B40(int a1, int a2, int a3, int a4, int a5)
{
  int v4; // esi@1
  int v5; // edx@3
  int v6; // ebx@3
  int v7; // edi@3
  int v8; // edx@6
  const void *v9; // ecx@6
  int v10; // ebx@6
  int v11; // esi@7
  int v12; // ecx@8
  int v13; // ebx@8
  int i; // esi@8
  int result; // eax@10
  int v16; // edx@10
  int v17; // ecx@10
  int v18; // eax@14
  int v19; // edx@14
  int v20; // edx@16
  int v21; // eax@21
  int v22; // ecx@21
  int v23; // esi@21
  int v24; // edx@22
  int v25; // ebx@22
  int v26; // edi@22
  int v27; // edi@26
  int v28; // ebx@28
  int v29; // esi@28
  int v30; // eax@33
  int v31; // edx@33
  int v32; // ebx@33
  int v33; // ebx@5
  __int16 v34; // ax@6
  int v35; // ebx@8
  int v36; // eax@8
  int v37; // eax@9
  int v38; // edx@9
  unsigned __int8 v39; // cf@16
  __int16 v40; // ax@22
  int v41; // ebx@24
  int v42; // edx@25
  __int16 v43; // ax@28
  int v44; // eax@30
  int v45; // ebx@30
  size_t v46; // ebx@30
  int v47; // [sp+28h] [bp-30h]@1
  int v48; // [sp+1Ch] [bp-3Ch]@3
  int v49; // [sp+48h] [bp-10h]@6
  int v50; // [sp+40h] [bp-18h]@6
  int v51; // [sp+44h] [bp-14h]@6
  __int16 v52; // [sp+3Ch] [bp-1Ch]@6
  signed int v53; // [sp+20h] [bp-38h]@16
  int v54; // [sp+34h] [bp-24h]@18
  int v55; // [sp+24h] [bp-34h]@21
  int v56; // [sp+Ch] [bp-4Ch]@21
  int v57; // [sp+38h] [bp-20h]@25
  int v58; // [sp+30h] [bp-28h]@25
  int v59; // [sp+2Ch] [bp-2Ch]@26

  v47 = a4;
  v4 = *(_DWORD *)(a3 + 4);
  if ( v4 != *(_DWORD *)(a3 + 8) )
  {
    if ( v4 )
    {
      v7 = 0;
      v48 = v4 - 16;
      *(_WORD *)v4 = *(_WORD *)(v4 - 16);
      v5 = v48;
      *(_DWORD *)(v4 + 12) = 0;
      v6 = *(_DWORD *)(v5 + 8) - *(_DWORD *)(v5 + 4);
      *(_DWORD *)(v4 + 8) = 0;
      *(_DWORD *)(v4 + 4) = 0;
      if ( v6 )
        v7 = operator new(a1, v5);
      *(_DWORD *)(v4 + 4) = v7;
      *(_DWORD *)(v4 + 8) = v7;
      *(_DWORD *)(v4 + 12) = v7 + v6;
      v33 = v7 + *(_DWORD *)(v48 + 8) - *(_DWORD *)(v48 + 4);
      memmove((void *)v7, *(const void **)(v48 + 4), *(_DWORD *)(v48 + 8) - *(_DWORD *)(v48 + 4));
      *(_DWORD *)(v4 + 8) = v33;
      v4 = *(_DWORD *)(a3 + 4);
    }
    *(_DWORD *)(a3 + 4) = v4 + 16;
    v49 = 0;
    v9 = *(const void **)(a5 + 4);
    v34 = *(_WORD *)a5;
    v8 = *(_DWORD *)(a5 + 8);
    v50 = 0;
    v51 = 0;
    v52 = v34;
    v10 = v8 - (_DWORD)v9;
    if ( v8 == (_DWORD)v9 )
    {
      v11 = 0;
    }
    else
    {
      v11 = operator new(v9, v8);
      v9 = *(const void **)(a5 + 4);
      v8 = *(_DWORD *)(a5 + 8);
    }
    v50 = v11;
    v49 = v11 + v10;
    v35 = v11 + v8 - (_DWORD)v9;
    memmove((void *)v11, v9, v8 - (_DWORD)v9);
    v51 = v35;
    v36 = *(_DWORD *)(a3 + 4);
    v13 = v36 - 16;
    for ( i = (v36 - 32 - a4) >> 4; i > 0; --i )
    {
      v37 = v13 - 32;
      v13 -= 16;
      v38 = *(_WORD *)(v13 - 16);
      *(_WORD *)v13 = v38;
      sub_804B500(v12, v38, v13 + 4, v37 + 4);
    }
    *(_WORD *)a4 = v52;
    sub_804B500(v12, a4, a4 + 4, (int)&v50);
    result = v50;
    if ( v50 )
      result = operator delete(v17, v16);
    return result;
  }
  v18 = (v4 - *(_DWORD *)a3) >> 4;
  v19 = (v4 - *(_DWORD *)a3) >> 4;
  if ( !v18 )
    v19 = 1;
  v39 = __MKCADD__(v18, v19);
  v20 = v18 + v19;
  v53 = v20;
  if ( v39 || (unsigned int)v20 > 0xFFFFFFF )
  {
    v53 = 268435455;
  }
  else
  {
    v54 = 0;
    if ( !v20 )
      goto LABEL_21;
  }
  v54 = operator new(a1, v20);
LABEL_21:
  v55 = v54;
  v56 = a3;
  v21 = sub_8056830(a1, a3, *(_DWORD *)a3, a4, v54);
  v23 = v21;
  v55 = v21;
  if ( v21 )
  {
    v24 = a5;
    v26 = 0;
    *(_DWORD *)(v21 + 12) = 0;
    v25 = *(_DWORD *)(v24 + 8) - *(_DWORD *)(v24 + 4);
    v40 = *(_WORD *)v24;
    *(_DWORD *)(v23 + 4) = 0;
    *(_DWORD *)(v23 + 8) = 0;
    *(_WORD *)v23 = v40;
    if ( v25 )
      v26 = operator new(v22, v24);
    *(_DWORD *)(v23 + 4) = v26;
    *(_DWORD *)(v23 + 8) = v26;
    *(_DWORD *)(v23 + 12) = v26 + v25;
    v41 = v26 + *(_DWORD *)(a5 + 8) - *(_DWORD *)(a5 + 4);
    memmove((void *)v26, *(const void **)(a5 + 4), *(_DWORD *)(a5 + 8) - *(_DWORD *)(a5 + 4));
    *(_DWORD *)(v23 + 8) = v41;
  }
  v55 = v23 + 16;
  v42 = *(_DWORD *)(a3 + 4);
  v57 = v23 + 16;
  v58 = v42;
  if ( v42 != a4 )
  {
    v27 = a4;
    v59 = v23 + 32;
    do
    {
      if ( v57 )
      {
        v29 = 0;
        v28 = *(_DWORD *)(v27 + 8) - *(_DWORD *)(v27 + 4);
        v43 = *(_WORD *)v27;
        *(_DWORD *)(v57 + 4) = 0;
        *(_WORD *)v57 = v43;
        *(_DWORD *)(v57 + 8) = 0;
        *(_DWORD *)(v57 + 12) = 0;
        if ( v28 )
          v29 = operator new(v22, v57);
        *(_DWORD *)(v57 + 4) = v29;
        *(_DWORD *)(v57 + 8) = v29;
        v44 = v29 + v28;
        v45 = *(_DWORD *)(v27 + 8);
        *(_DWORD *)(v57 + 12) = v44;
        v46 = v45 - *(_DWORD *)(v27 + 4);
        memmove((void *)v29, *(const void **)(v27 + 4), v46);
        *(_DWORD *)(v57 + 8) = v29 + v46;
      }
      v27 += 16;
      v57 = v59;
      v59 += 16;
    }
    while ( v58 != v27 );
    v47 = *(_DWORD *)(a3 + 4);
  }
  v31 = a3;
  v30 = v47;
  v32 = *(_DWORD *)a3;
  if ( *(_DWORD *)a3 != v47 )
  {
    do
    {
      if ( *(_DWORD *)(v32 + 4) )
        operator delete(v22, v31);
      v32 += 16;
    }
    while ( v32 != v47 );
    v31 = a3;
    v30 = *(_DWORD *)a3;
  }
  if ( v30 )
    operator delete(v22, v31);
  *(_DWORD *)a3 = v54;
  *(_DWORD *)(a3 + 4) = v57;
  v53 *= 16;
  result = v53 + v54;
  *(_DWORD *)(a3 + 8) = v53 + v54;
  return result;
}

//----- (08057F70) --------------------------------------------------------
int __fastcall sub_8057F70(int a1, int a2, int a3, int a4)
{
  int v3; // esi@1
  int v4; // edx@3
  int v5; // ebx@3
  int v6; // edi@3
  int result; // eax@6
  __int16 v8; // ax@3
  int v9; // ebx@5

  v3 = *(_DWORD *)(a3 + 4);
  if ( v3 == *(_DWORD *)(a3 + 8) )
  {
    result = sub_8057B40(a1, a3, a3, *(_DWORD *)(a3 + 4), a4);
  }
  else
  {
    if ( v3 )
    {
      v4 = a4;
      v6 = 0;
      *(_DWORD *)(v3 + 12) = 0;
      v5 = *(_DWORD *)(v4 + 8) - *(_DWORD *)(v4 + 4);
      v8 = *(_WORD *)v4;
      *(_DWORD *)(v3 + 4) = 0;
      *(_DWORD *)(v3 + 8) = 0;
      *(_WORD *)v3 = v8;
      if ( v5 )
        v6 = operator new(a1, v4);
      *(_DWORD *)(v3 + 4) = v6;
      *(_DWORD *)(v3 + 8) = v6;
      *(_DWORD *)(v3 + 12) = v6 + v5;
      v9 = v6 + *(_DWORD *)(a4 + 8) - *(_DWORD *)(a4 + 4);
      memmove((void *)v6, *(const void **)(a4 + 4), *(_DWORD *)(a4 + 8) - *(_DWORD *)(a4 + 4));
      *(_DWORD *)(v3 + 8) = v9;
      v3 = *(_DWORD *)(a3 + 4);
    }
    result = v3 + 16;
    *(_DWORD *)(a3 + 4) = v3 + 16;
  }
  return result;
}

//----- (08058030) --------------------------------------------------------
signed int __cdecl sub_8058030(int a1, __int16 a2)
{
  int v2; // ebx@1
  signed int result; // eax@2
  unsigned int v4; // edx@2
  int v5; // ecx@2
  __int16 v6; // ax@4

  v2 = (*(_DWORD *)(a1 + 8) - *(_DWORD *)(a1 + 4)) >> 7;
  if ( !v2 )
    return -1;
  v5 = *(_DWORD *)(a1 + 4);
  result = 0;
  v4 = 0;
  if ( *(_WORD *)(v5 + 16) != a2 )
  {
    while ( 1 )
    {
      ++v4;
      if ( v4 >= v2 )
        break;
      v6 = *(_WORD *)(v5 + 144);
      v5 += 128;
      if ( v6 == a2 )
        return v4;
    }
    return -1;
  }
  return result;
}

//----- (08058090) --------------------------------------------------------
signed int __cdecl sub_8058090(int a1, __int16 a2)
{
  int v2; // edx@1
  int v3; // ecx@1
  signed int result; // eax@2
  int v5; // ebx@2

  v3 = *(_DWORD *)(a1 + 16);
  v2 = (*(_DWORD *)(a1 + 20) - v3) >> 3;
  if ( v2 )
  {
    result = 0;
    v5 = 0;
    if ( *(_WORD *)v3 == a2 )
      return v5;
    while ( 1 )
    {
      ++result;
      if ( result >= (unsigned int)v2 )
        break;
      if ( *(_WORD *)(v3 + 8 * result) == a2 )
        return result;
    }
  }
  return -1;
}

//----- (080580E0) --------------------------------------------------------
signed int __cdecl sub_80580E0(int a1)
{
  signed int result; // eax@1
  int v2; // ecx@1
  int v3; // ebx@1
  unsigned int v4; // edx@2

  v2 = *(_DWORD *)(a1 + 16);
  result = 1;
  v3 = (*(_DWORD *)(a1 + 20) - v2) >> 3;
  if ( v3 )
  {
    while ( 1 )
    {
      v4 = 0;
      if ( *(_WORD *)v2 != (_WORD)result )
        break;
LABEL_7:
      ++result;
      if ( (_WORD)result == -2 )
        return 0;
    }
    while ( 1 )
    {
      ++v4;
      if ( v4 >= v3 )
        break;
      if ( *(_WORD *)(v2 + 8 * v4) == (_WORD)result )
        goto LABEL_7;
    }
  }
  return result;
}

//----- (08058150) --------------------------------------------------------
int __cdecl sub_8058150()
{
  std__ios_base__Init__Init(&unk_80874D0);
  return __cxa_atexit(std__ios_base__Init___Init, &unk_80874D0, &unk_80871E4);
}

//----- (08058180) --------------------------------------------------------
signed int __cdecl sub_8058180(int a1, int a2, int a3)
{
  int v3; // edx@1
  unsigned int *v4; // ecx@1
  signed int result; // eax@3

  v3 = *(_DWORD *)(a3 + 4);
  v4 = *(unsigned int **)a3;
  if ( v3 != *(_DWORD *)a3 && (unsigned int)*(_BYTE *)v4 + 1 <= v3 - (_DWORD)v4 )
  {
    std__string__assign(a2, (char *)v4 + 1, *(_BYTE *)v4);
    result = 1;
  }
  else
  {
    result = 0;
  }
  return result;
}

//----- (080581D0) --------------------------------------------------------
signed int __cdecl sub_80581D0(int a1, int a2, int a3)
{
  int v3; // edx@1
  unsigned int *v4; // ecx@1
  signed int result; // eax@3

  v3 = *(_DWORD *)(a3 + 4);
  v4 = *(unsigned int **)a3;
  if ( v3 != *(_DWORD *)a3 && (unsigned int)*(_BYTE *)v4 + 1 <= v3 - (_DWORD)v4 )
  {
    std__string__assign(a2, (char *)v4 + 1, *(_BYTE *)v4);
    result = 1;
  }
  else
  {
    result = 0;
  }
  return result;
}

//----- (08058220) --------------------------------------------------------
signed int __cdecl sub_8058220(int a1, int a2, int a3, int a4)
{
  int v4; // edx@1
  int v5; // ecx@1
  int v6; // esi@1
  int v7; // ebx@2
  signed int result; // eax@3
  __int16 v9; // ax@4

  v6 = a4;
  v5 = *(_DWORD *)a4;
  v4 = *(_DWORD *)(a4 + 4) - *(_DWORD *)a4;
  if ( (unsigned int)v4 > 0xC && (v7 = *(_BYTE *)(v5 + 10), v7 + 13 <= (unsigned int)v4) )
  {
    std__string__assign(a2, v5 + 11, *(_BYTE *)(v5 + 10));
    v9 = __ROR__(*(_WORD *)(*(_DWORD *)v6 + v7 + 11), 8);
    *(_WORD *)a3 = v9;
    result = 1;
  }
  else
  {
    result = 0;
  }
  return result;
}

//----- (08058290) --------------------------------------------------------
signed int __cdecl sub_8058290(int a1, int a2, int a3)
{
  char v3; // zf@5
  signed int v4; // ecx@5
  int *v5; // edi@5
  int v6; // esi@5
  int v8; // edx@1
  int v9; // eax@1
  unsigned int v10; // eax@1
  int v11; // [sp+Ch] [bp-18h]@1
  unsigned int v12; // [sp+10h] [bp-14h]@1
  unsigned int v13; // [sp+14h] [bp-10h]@2
  signed int v14; // [sp+0h] [bp-24h]@3
  int v15; // [sp+4h] [bp-20h]@3

  v8 = *(_DWORD *)a2;
  v9 = *(_DWORD *)(a2 + 4);
  *(_DWORD *)a3 = 0;
  v11 = v8;
  v10 = (unsigned int)(v9 - v8) >> 4;
  v12 = v10;
  if ( v10 )
  {
    v13 = 0;
    do
    {
      v14 = 0;
      v15 = v11 + 16 * v13;
      do
      {
        v4 = 16;
        v6 = v15;
        v3 = &stru_807FAC0[4 * v14] == 0;
        v5 = &stru_807FAC0[4 * v14];
        do
        {
          if ( !v4 )
            break;
          v3 = *(_BYTE *)v6++ == *(_BYTE *)v5;
          v5 = (int *)((char *)v5 + 1);
          --v4;
        }
        while ( v3 );
        if ( v3 )
        {
          *(_DWORD *)a3 = v14 + 1;
          return 1;
        }
        ++v14;
      }
      while ( v14 != 34 );
      ++v13;
    }
    while ( v12 > v13 );
  }
  return 0;
}

//----- (08058330) --------------------------------------------------------
#error "80583EC: invalid basic block (funcsize=61)"

//----- (080583F0) --------------------------------------------------------
#error "80584AC: invalid basic block (funcsize=61)"

//----- (080584B0) --------------------------------------------------------
signed int __cdecl sub_80584B0(int a1, int a2, int a3, int a4, int a5)
{
  int v5; // eax@1
  int v6; // edx@1
  int v7; // esi@1
  int v8; // ebx@2
  signed int result; // eax@3
  unsigned int v10; // edx@5
  int v11; // ebx@5
  int v12; // edi@5
  unsigned __int16 v13; // cx@6
  char v14; // al@5
  int v15; // [sp+18h] [bp-20h]@2

  v7 = a5;
  v6 = *(_DWORD *)(a5 + 4);
  v5 = *(_DWORD *)a5;
  if ( v6 == *(_DWORD *)a5
    || (v8 = *(_BYTE *)v5, v15 = v8 + 2, v8 + 2 > (unsigned int)(v6 - v5))
    || (std__string__assign(a2, v5 + 1, v8), v14 = *(_BYTE *)(*(_DWORD *)v7 + v8 + 1), v11 = v8 + 4, *(_BYTE *)a4 = v14, v12 = *(_DWORD *)v7, v10 = *(_DWORD *)(v7 + 4) - *(_DWORD *)v7, v11 > v10)
    || (v13 = __ROR__(*(_WORD *)(v12 + v15), 8), (unsigned int)v13 + v11 > v10) )
  {
    result = 0;
  }
  else
  {
    std__string__assign(a3, v12 + v11, v13);
    result = 1;
  }
  return result;
}

//----- (08058560) --------------------------------------------------------
signed int __cdecl sub_8058560(int a1, int a2, int a3, int a4)
{
  int *v4; // eax@1
  int v5; // edx@1
  int v6; // esi@1
  int v7; // ebx@2
  int v8; // edi@2
  signed int result; // eax@3
  int v10; // eax@5
  unsigned int v11; // edx@5
  int v12; // ebx@5
  unsigned __int16 v13; // cx@6
  int v14; // edx@5
  int v15; // [sp+18h] [bp-20h]@5

  v6 = a4;
  v5 = *(_DWORD *)(a4 + 4);
  v4 = *(int **)a4;
  if ( v5 == *(_DWORD *)a4
    || (v7 = *(_BYTE *)v4, v8 = v7 + 1, v7 + 1 > (unsigned int)(v5 - (_DWORD)v4))
    || (v12 = v7 + 3, std__string__assign(a2, (char *)v4 + 1, *(_BYTE *)v4), v10 = *(_DWORD *)v6, v14 = *(_DWORD *)(v6 + 4), v15 = *(_DWORD *)v6, v11 = v14 - v10, v12 > v11)
    || (v13 = __ROR__(*(_WORD *)(v10 + v8), 8), (unsigned int)v13 + v12 > v11) )
  {
    result = 0;
  }
  else
  {
    std__string__assign(a3, v12 + v15, v13);
    result = 1;
  }
  return result;
}

//----- (08058600) --------------------------------------------------------
int __cdecl sub_8058600(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ebx@1
  int result; // eax@3
  int v6; // edx@4
  int v7; // ecx@4
  int v8; // edi@5
  unsigned __int16 v9; // si@5
  int v10; // edi@8
  int v11; // edx@9
  int v12; // ecx@9
  int v13; // esi@9
  unsigned __int16 v14; // di@10
  int v15; // edx@13
  int v16; // edi@13
  int v17; // edx@14
  int v18; // esi@14
  unsigned __int16 v19; // cx@15
  int v20; // edi@15
  int v21; // edx@18
  int v22; // edi@18
  int v23; // edx@19
  int v24; // esi@19
  unsigned __int16 v25; // cx@20
  int v26; // edi@20
  int v27; // edx@23
  int v28; // edi@23
  int v29; // edx@24
  int v30; // esi@24
  unsigned __int16 v31; // cx@25
  int v32; // edi@25
  int v33; // edx@28
  int v34; // ecx@28
  int v35; // edx@29
  int v36; // edi@29
  int v37; // esi@29
  unsigned __int16 v38; // cx@30
  int v39; // ebx@30
  unsigned __int16 v40; // ax@5
  unsigned __int16 v41; // ax@10
  unsigned __int16 v42; // ax@15
  unsigned __int16 v43; // ax@20
  unsigned __int16 v44; // ax@25
  unsigned __int16 v45; // ax@30
  unsigned __int16 v46; // [sp+3Ah] [bp-Eh]@5
  int v47; // [sp+18h] [bp-30h]@10
  int v48; // [sp+1Ch] [bp-2Ch]@14
  int v49; // [sp+20h] [bp-28h]@19
  int v50; // [sp+24h] [bp-24h]@24
  int v51; // [sp+28h] [bp-20h]@28

  v4 = a2;
  v3 = *(_DWORD *)a2;
  if ( *(_BYTE *)(*(_DWORD *)a2 + 16) == 10 )
  {
    result = *(_DWORD *)(a2 + 4) - v3;
    if ( (unsigned int)result > 0x13 )
    {
      result = *(_WORD *)(v3 + 18);
      *(_WORD *)(a3 + 192) = result;
      v7 = *(_DWORD *)v4;
      v6 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
      if ( (unsigned int)v6 > 0x15 )
      {
        v40 = *(_WORD *)(v7 + 20);
        v8 = v40;
        v9 = *(_WORD *)(v7 + 20);
        v46 = *(_WORD *)(v7 + 20);
        result = v40 + 22;
        if ( result <= (unsigned int)v6 )
        {
          if ( v9 <= 1u )
            std__string__assign(a3 + 196, &aResNr[13]);
          else
            std__string__assign(a3 + 196, v7 + 22, v8 - 1);
          v10 = v46 + 24;
          result = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
          if ( v10 <= (unsigned int)result )
          {
            result = *(_WORD *)(*(_DWORD *)v4 + v46 + 22);
            v13 = v46 + 26;
            *(_WORD *)(a3 + 200) = result;
            v12 = *(_DWORD *)v4;
            v11 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
            if ( v13 <= (unsigned int)v11 )
            {
              v41 = *(_WORD *)(v12 + v10);
              v46 = *(_WORD *)(v12 + v10);
              v14 = v41;
              v47 = v41;
              result = v13 + v41;
              if ( result <= (unsigned int)v11 )
              {
                if ( v14 <= 1u )
                  std__string__assign(a3 + 204, &aResNr[13]);
                else
                  std__string__assign(a3 + 204, v12 + v13, v47 - 1);
                v15 = v13 + v46;
                v16 = v15 + 2;
                result = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
                if ( v15 + 2 <= (unsigned int)result )
                {
                  result = *(_WORD *)(*(_DWORD *)v4 + v15);
                  *(_WORD *)(a3 + 208) = result;
                  v18 = *(_DWORD *)v4;
                  v48 = v15 + 4;
                  v17 = *(_DWORD *)(v4 + 4) - v18;
                  if ( v48 <= (unsigned int)v17 )
                  {
                    v42 = *(_WORD *)(v18 + v16);
                    v20 = v42;
                    v19 = v42;
                    v46 = v42;
                    result = v42 + v48;
                    if ( result <= (unsigned int)v17 )
                    {
                      if ( v19 <= 1u )
                        std__string__assign(a3 + 212, &aResNr[13]);
                      else
                        std__string__assign(a3 + 212, v18 + v48, v20 - 1);
                      v21 = v48 + v46 + 1;
                      v22 = v48 + v46 + 3;
                      result = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
                      if ( v22 <= (unsigned int)result )
                      {
                        result = *(_WORD *)(*(_DWORD *)v4 + v21);
                        *(_WORD *)(a3 + 216) = result;
                        v24 = *(_DWORD *)v4;
                        v49 = v21 + 4;
                        v23 = *(_DWORD *)(v4 + 4) - v24;
                        if ( v49 <= (unsigned int)v23 )
                        {
                          v43 = *(_WORD *)(v24 + v22);
                          v26 = v43;
                          v25 = v43;
                          v46 = v43;
                          result = v43 + v49;
                          if ( result <= (unsigned int)v23 )
                          {
                            if ( v25 <= 1u )
                              std__string__assign(a3 + 220, &aResNr[13]);
                            else
                              std__string__assign(a3 + 220, v24 + v49, v26 - 1);
                            v27 = v46 + v49;
                            v28 = v27 + 2;
                            result = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
                            if ( v27 + 2 <= (unsigned int)result )
                            {
                              result = *(_WORD *)(*(_DWORD *)v4 + v27);
                              *(_WORD *)(a3 + 224) = result;
                              v30 = *(_DWORD *)v4;
                              v50 = v27 + 4;
                              v29 = *(_DWORD *)(v4 + 4) - v30;
                              if ( v50 <= (unsigned int)v29 )
                              {
                                v44 = *(_WORD *)(v30 + v28);
                                v32 = v44;
                                v31 = v44;
                                v46 = v44;
                                result = v44 + v50;
                                if ( result <= (unsigned int)v29 )
                                {
                                  if ( v31 <= 1u )
                                    std__string__assign(a3 + 228, &aResNr[13]);
                                  else
                                    std__string__assign(a3 + 228, v30 + v50, v32 - 1);
                                  v34 = *(_DWORD *)v4;
                                  v33 = v46 + v50;
                                  v51 = v33 + 2;
                                  result = *(_DWORD *)(v4 + 4) - v34;
                                  if ( v33 + 2 <= (unsigned int)result )
                                  {
                                    result = *(_WORD *)(v34 + v33);
                                    v37 = v33 + 4;
                                    *(_WORD *)(a3 + 232) = result;
                                    v36 = *(_DWORD *)v4;
                                    v35 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
                                    if ( v37 <= (unsigned int)v35 )
                                    {
                                      v45 = *(_WORD *)(v36 + v51);
                                      v39 = v45;
                                      v38 = *(_WORD *)(v36 + v51);
                                      v46 = *(_WORD *)(v36 + v51);
                                      result = v37 + v45;
                                      if ( result <= (unsigned int)v35 )
                                      {
                                        if ( v38 <= 1u )
                                          result = std__string__assign(a3 + 236, &aResNr[13]);
                                        else
                                          result = std__string__assign(a3 + 236, v36 + v37, v39 - 1);
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  return result;
}

//----- (080589D0) --------------------------------------------------------
int __cdecl sub_80589D0(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ebx@1
  int result; // eax@3
  int v6; // edx@4
  int v7; // ecx@4
  int v8; // edi@5
  unsigned __int16 v9; // si@5
  int v10; // edi@8
  int v11; // edx@9
  int v12; // ecx@9
  int v13; // esi@9
  unsigned __int16 v14; // di@10
  int v15; // edx@13
  int v16; // edi@13
  int v17; // edx@14
  int v18; // esi@14
  unsigned __int16 v19; // cx@15
  int v20; // edi@15
  int v21; // edx@18
  int v22; // ecx@18
  int v23; // edx@19
  int v24; // edi@19
  int v25; // esi@19
  unsigned __int16 v26; // cx@20
  int v27; // ebx@20
  unsigned __int16 v28; // ax@5
  unsigned __int16 v29; // ax@10
  unsigned __int16 v30; // ax@15
  unsigned __int16 v31; // ax@20
  unsigned __int16 v32; // [sp+2Ah] [bp-Eh]@5
  int v33; // [sp+10h] [bp-28h]@10
  int v34; // [sp+14h] [bp-24h]@14
  int v35; // [sp+18h] [bp-20h]@18

  v4 = a2;
  v3 = *(_DWORD *)a2;
  if ( *(_BYTE *)(*(_DWORD *)a2 + 16) == 10 )
  {
    result = *(_DWORD *)(a2 + 4) - v3;
    if ( (unsigned int)result > 0x13 )
    {
      result = *(_WORD *)(v3 + 18);
      *(_WORD *)(a3 + 160) = result;
      v7 = *(_DWORD *)v4;
      v6 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
      if ( (unsigned int)v6 > 0x15 )
      {
        v28 = *(_WORD *)(v7 + 20);
        v8 = v28;
        v9 = *(_WORD *)(v7 + 20);
        v32 = *(_WORD *)(v7 + 20);
        result = v28 + 22;
        if ( result <= (unsigned int)v6 )
        {
          if ( v9 <= 1u )
            std__string__assign(a3 + 164, &aResNr[13]);
          else
            std__string__assign(a3 + 164, v7 + 22, v8 - 1);
          v10 = v32 + 24;
          result = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
          if ( v10 <= (unsigned int)result )
          {
            result = *(_WORD *)(*(_DWORD *)v4 + v32 + 22);
            v13 = v32 + 26;
            *(_WORD *)(a3 + 168) = result;
            v12 = *(_DWORD *)v4;
            v11 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
            if ( v13 <= (unsigned int)v11 )
            {
              v29 = *(_WORD *)(v12 + v10);
              v32 = *(_WORD *)(v12 + v10);
              v14 = v29;
              v33 = v29;
              result = v13 + v29;
              if ( result <= (unsigned int)v11 )
              {
                if ( v14 <= 1u )
                  std__string__assign(a3 + 172, &aResNr[13]);
                else
                  std__string__assign(a3 + 172, v12 + v13, v33 - 1);
                v15 = v13 + v32;
                v16 = v15 + 2;
                result = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
                if ( v15 + 2 <= (unsigned int)result )
                {
                  result = *(_WORD *)(*(_DWORD *)v4 + v15);
                  *(_WORD *)(a3 + 176) = result;
                  v18 = *(_DWORD *)v4;
                  v34 = v15 + 4;
                  v17 = *(_DWORD *)(v4 + 4) - v18;
                  if ( v34 <= (unsigned int)v17 )
                  {
                    v30 = *(_WORD *)(v18 + v16);
                    v20 = v30;
                    v19 = v30;
                    v32 = v30;
                    result = v30 + v34;
                    if ( result <= (unsigned int)v17 )
                    {
                      if ( v19 <= 1u )
                        std__string__assign(a3 + 180, &aResNr[13]);
                      else
                        std__string__assign(a3 + 180, v18 + v34, v20 - 1);
                      v22 = *(_DWORD *)v4;
                      v21 = v32 + v34;
                      v35 = v21 + 2;
                      result = *(_DWORD *)(v4 + 4) - v22;
                      if ( v21 + 2 <= (unsigned int)result )
                      {
                        result = *(_WORD *)(v22 + v21);
                        v25 = v21 + 4;
                        *(_WORD *)(a3 + 184) = result;
                        v24 = *(_DWORD *)v4;
                        v23 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
                        if ( v25 <= (unsigned int)v23 )
                        {
                          v31 = *(_WORD *)(v24 + v35);
                          v27 = v31;
                          v26 = *(_WORD *)(v24 + v35);
                          v32 = *(_WORD *)(v24 + v35);
                          result = v25 + v31;
                          if ( result <= (unsigned int)v23 )
                          {
                            if ( v26 <= 1u )
                              result = std__string__assign(a3 + 188, &aResNr[13]);
                            else
                              result = std__string__assign(a3 + 188, v24 + v25, v27 - 1);
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  return result;
}

//----- (08058C60) --------------------------------------------------------
int __cdecl sub_8058C60(int a1, int a2, int a3)
{
  int result; // eax@1
  int v4; // ecx@1
  int v5; // edx@3
  unsigned __int16 v6; // bx@4
  int v7; // esi@4
  unsigned __int16 v8; // ax@4
  __int16 v9; // [sp+1Eh] [bp-Ah]@4

  result = a2;
  v4 = *(_DWORD *)a2;
  if ( *(_BYTE *)(*(_DWORD *)a2 + 16) == 10 )
  {
    v5 = *(_DWORD *)(a2 + 4) - v4;
    if ( (unsigned int)v5 > 0x12 )
    {
      v8 = *(_WORD *)(v4 + 17);
      v7 = v8;
      v6 = *(_WORD *)(v4 + 17);
      v9 = *(_WORD *)(v4 + 17);
      result = v8 + 19;
      if ( result <= (unsigned int)v5 )
      {
        if ( v6 <= 1u )
          result = std__string__assign(a3 + 156, &aResNr[13]);
        else
          result = std__string__assign(a3 + 156, v4 + 19, v7 - 1);
      }
    }
  }
  return result;
}

//----- (08058CF0) --------------------------------------------------------
void __cdecl sub_8058CF0(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // edi@1
  unsigned int v5; // ecx@3
  unsigned __int16 v6; // ax@4
  unsigned __int16 v7; // bx@4
  unsigned int v8; // edx@7
  int v9; // ecx@7
  int v10; // ebx@7
  int v11; // esi@7
  unsigned __int16 v12; // ax@8
  int v13; // eax@11
  unsigned int v14; // edx@11
  int v15; // ecx@11
  int v16; // ebx@11
  unsigned __int16 v17; // ax@12
  int v18; // eax@15
  unsigned int v19; // edx@15
  int v20; // ecx@15
  int v21; // ebx@15
  unsigned __int16 v22; // ax@16
  int v23; // eax@19
  unsigned int v24; // edx@19
  int v25; // ebx@19
  unsigned __int16 v26; // ax@20
  int v27; // eax@23
  unsigned int v28; // edx@23
  int v29; // ebx@23
  unsigned __int16 v30; // ax@24
  int v31; // edx@27
  int v32; // esi@27
  unsigned int v33; // edx@28
  int v34; // ebx@28
  unsigned __int16 v35; // ax@29
  int v36; // eax@32
  unsigned int v37; // edx@32
  int v38; // ebx@32
  unsigned __int16 v39; // ax@33
  int v40; // eax@36
  unsigned int v41; // edx@36
  int v42; // ebx@36
  unsigned __int16 v43; // ax@37
  int v44; // edx@40
  int v45; // ecx@40
  unsigned int v46; // edx@41
  int v47; // ebx@41
  int v48; // esi@41
  unsigned __int16 v49; // ax@42
  unsigned __int16 v50; // cx@42
  unsigned __int16 v51; // [sp+4Ah] [bp-Eh]@4
  int v52; // [sp+20h] [bp-38h]@8
  int v53; // [sp+1Ch] [bp-3Ch]@12
  int v54; // [sp+18h] [bp-40h]@16
  int v55; // [sp+24h] [bp-34h]@19
  int v56; // [sp+28h] [bp-30h]@23
  int v57; // [sp+2Ch] [bp-2Ch]@28
  int v58; // [sp+30h] [bp-28h]@32
  int v59; // [sp+34h] [bp-24h]@36
  int v60; // [sp+38h] [bp-20h]@40

  v4 = a2;
  v3 = *(_DWORD *)a2;
  if ( *(_BYTE *)(*(_DWORD *)a2 + 16) == 10 )
  {
    v5 = *(_DWORD *)(a2 + 4) - v3;
    if ( v5 > 0x12 )
    {
      v6 = *(_WORD *)(v3 + 17);
      v7 = *(_WORD *)(v3 + 17);
      v51 = *(_WORD *)(v3 + 17);
      if ( (unsigned int)v6 + 19 <= v5 )
      {
        if ( v7 <= 1u )
          std__string__assign(a3 + 108, &aResNr[13]);
        else
          std__string__assign(a3 + 108, v3 + 19, v6 - 1);
        v9 = *(_DWORD *)v4;
        v10 = v51 + 21;
        v11 = v51 + 19;
        v8 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
        if ( v10 <= v8 )
        {
          v12 = *(_WORD *)(v9 + v11);
          v51 = *(_WORD *)(v9 + v11);
          v52 = v12;
          if ( v10 + (unsigned int)v12 <= v8 )
          {
            if ( v12 <= 1u )
              std__string__assign(a3 + 112, &aResNr[13]);
            else
              std__string__assign(a3 + 112, v9 + v10, v52 - 1);
            v15 = *(_DWORD *)v4;
            v13 = v10 + v51;
            v16 = v13 + 2;
            v14 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
            if ( v13 + 2 <= v14 )
            {
              v17 = *(_WORD *)(v15 + v13);
              v51 = v17;
              v53 = v17;
              if ( v16 + (unsigned int)v17 <= v14 )
              {
                if ( v17 <= 1u )
                  std__string__assign(a3 + 116, &aResNr[13]);
                else
                  std__string__assign(a3 + 116, v15 + v16, v53 - 1);
                v20 = *(_DWORD *)v4;
                v18 = v16 + v51;
                v21 = v18 + 2;
                v19 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
                if ( v18 + 2 <= v19 )
                {
                  v22 = *(_WORD *)(v20 + v18);
                  v51 = v22;
                  v54 = v22;
                  if ( v21 + (unsigned int)v22 <= v19 )
                  {
                    if ( v22 <= 1u )
                      std__string__assign(a3 + 120, &aResNr[13]);
                    else
                      std__string__assign(a3 + 120, v20 + v21, v54 - 1);
                    v23 = v21 + v51;
                    v25 = *(_DWORD *)v4;
                    v55 = v23 + 2;
                    v24 = *(_DWORD *)(v4 + 4) - v25;
                    if ( v23 + 2 <= v24 )
                    {
                      v26 = *(_WORD *)(v25 + v23);
                      v51 = v26;
                      if ( (unsigned int)v26 + v55 <= v24 )
                      {
                        if ( v26 <= 1u )
                          std__string__assign(a3 + 124, &aResNr[13]);
                        else
                          std__string__assign(a3 + 124, v25 + v55, v26 - 1);
                        v27 = v55 + v51;
                        v29 = *(_DWORD *)v4;
                        v56 = v27 + 2;
                        v28 = *(_DWORD *)(v4 + 4) - v29;
                        if ( v27 + 2 <= v28 )
                        {
                          v30 = *(_WORD *)(v29 + v27);
                          v51 = v30;
                          if ( (unsigned int)v30 + v56 <= v28 )
                          {
                            if ( v30 <= 1u )
                              std__string__assign(a3 + 128, &aResNr[13]);
                            else
                              std__string__assign(a3 + 128, v29 + v56, v30 - 1);
                            v31 = v51 + v56;
                            v32 = v31 + 2;
                            if ( v31 + 2 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
                            {
                              *(_WORD *)(a3 + 132) = *(_WORD *)(*(_DWORD *)v4 + v31);
                              v34 = *(_DWORD *)v4;
                              v57 = v31 + 4;
                              v33 = *(_DWORD *)(v4 + 4) - v34;
                              if ( v57 <= v33 )
                              {
                                v35 = *(_WORD *)(v34 + v32);
                                v51 = *(_WORD *)(v34 + v32);
                                if ( (unsigned int)v35 + v57 <= v33 )
                                {
                                  if ( v35 <= 1u )
                                    std__string__assign(a3 + 136, &aResNr[13]);
                                  else
                                    std__string__assign(a3 + 136, v34 + v57, v35 - 1);
                                  v38 = *(_DWORD *)v4;
                                  v36 = v57 + v51;
                                  v37 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
                                  v58 = v36 + 2;
                                  if ( v36 + 2 <= v37 )
                                  {
                                    v39 = *(_WORD *)(v38 + v36);
                                    v51 = v39;
                                    if ( (unsigned int)v39 + v58 <= v37 )
                                    {
                                      if ( v39 <= 1u )
                                        std__string__assign(a3 + 140, &aResNr[13]);
                                      else
                                        std__string__assign(a3 + 140, v38 + v58, v39 - 1);
                                      v42 = *(_DWORD *)v4;
                                      v40 = v58 + v51;
                                      v41 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
                                      v59 = v40 + 2;
                                      if ( v40 + 2 <= v41 )
                                      {
                                        v43 = *(_WORD *)(v42 + v40);
                                        v51 = v43;
                                        if ( (unsigned int)v43 + v59 <= v41 )
                                        {
                                          if ( v43 <= 1u )
                                            std__string__assign(a3 + 144, &aResNr[13]);
                                          else
                                            std__string__assign(a3 + 144, v42 + v59, v43 - 1);
                                          v45 = *(_DWORD *)v4;
                                          v44 = v51 + v59;
                                          v60 = v44 + 2;
                                          if ( v44 + 2 <= (unsigned int)(*(_DWORD *)(v4 + 4) - v45) )
                                          {
                                            v47 = v44 + 4;
                                            *(_WORD *)(a3 + 148) = *(_WORD *)(v45 + v44);
                                            v48 = *(_DWORD *)v4;
                                            v46 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
                                            if ( v47 <= v46 )
                                            {
                                              v49 = *(_WORD *)(v48 + v60);
                                              v50 = *(_WORD *)(v48 + v60);
                                              v51 = *(_WORD *)(v48 + v60);
                                              if ( v47 + (unsigned int)v49 <= v46 )
                                              {
                                                if ( v50 <= 1u )
                                                  std__string__assign(a3 + 152, &aResNr[13]);
                                                else
                                                  std__string__assign(a3 + 152, v48 + v47, v49 - 1);
                                              }
                                            }
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

//----- (08059210) --------------------------------------------------------
int __cdecl sub_8059210(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ecx@1
  int result; // eax@3
  int v6; // edx@5
  int v7; // ebx@5
  unsigned __int16 v8; // cx@6
  int v9; // esi@6
  unsigned __int16 v10; // ax@6
  __int16 v11; // [sp+1Eh] [bp-Ah]@6

  v4 = a2;
  v3 = *(_DWORD *)a2;
  if ( *(_BYTE *)(*(_DWORD *)a2 + 16) == 10 )
  {
    result = *(_DWORD *)(a2 + 4) - v3;
    if ( (unsigned int)result > 0x11 )
    {
      *(_BYTE *)(a3 + 100) = *(_BYTE *)(v3 + 17);
      result = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
      if ( (unsigned int)result > 0x13 )
      {
        result = *(_WORD *)(*(_DWORD *)v4 + 18);
        *(_WORD *)(a3 + 102) = result;
        v7 = *(_DWORD *)v4;
        v6 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
        if ( (unsigned int)v6 > 0x15 )
        {
          v10 = *(_WORD *)(v7 + 20);
          v9 = v10;
          v8 = *(_WORD *)(v7 + 20);
          v11 = *(_WORD *)(v7 + 20);
          result = v10 + 22;
          if ( result <= (unsigned int)v6 )
          {
            if ( v8 <= 1u )
              result = std__string__assign(a3 + 104, &aResNr[13]);
            else
              result = std__string__assign(a3 + 104, v7 + 22, v9 - 1);
          }
        }
      }
    }
  }
  return result;
}

//----- (080592D0) --------------------------------------------------------
void __cdecl sub_80592D0(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ebx@1
  unsigned int v5; // edx@5
  int v6; // ecx@5
  unsigned __int16 v7; // ax@6
  unsigned __int16 v8; // si@6
  int v9; // ecx@9
  int v10; // edi@9
  int v11; // eax@15
  unsigned int v12; // edx@15
  int v13; // esi@15
  unsigned __int16 v14; // ax@16
  int v15; // eax@19
  unsigned int v16; // ecx@19
  int v17; // esi@19
  unsigned __int16 v18; // ax@20
  int v19; // edx@23
  int v20; // edx@15
  int v21; // ecx@15
  unsigned __int16 v22; // [sp+2Ah] [bp-Eh]@6
  int v23; // [sp+14h] [bp-24h]@15
  int v24; // [sp+18h] [bp-20h]@19

  v4 = a2;
  v3 = *(_DWORD *)a2;
  if ( *(_BYTE *)(*(_DWORD *)a2 + 16) == 10 )
  {
    if ( (unsigned int)(*(_DWORD *)(a2 + 4) - v3) > 0x12 )
    {
      *(_WORD *)(a3 + 56) = *(_WORD *)(v3 + 17);
      if ( (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) > 0x13 )
      {
        *(_BYTE *)(a3 + 58) = *(_BYTE *)(*(_DWORD *)v4 + 19);
        v6 = *(_DWORD *)v4;
        v5 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
        if ( v5 > 0x15 )
        {
          v7 = *(_WORD *)(v6 + 20);
          v8 = *(_WORD *)(v6 + 20);
          v22 = *(_WORD *)(v6 + 20);
          if ( (unsigned int)v7 + 22 <= v5 )
          {
            if ( v8 <= 1u )
              std__string__assign(a3 + 60, &aResNr[13]);
            else
              std__string__assign(a3 + 60, v6 + 22, v7 - 1);
            v9 = v22;
            v10 = v22 + 24;
            if ( v10 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
            {
              *(_WORD *)(a3 + 64) = *(_WORD *)(*(_DWORD *)v4 + v22 + 22);
              if ( v9 + 25 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
              {
                *(_BYTE *)(a3 + 66) = *(_BYTE *)(*(_DWORD *)v4 + v10);
                if ( v9 + 26 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
                {
                  *(_BYTE *)(a3 + 67) = *(_BYTE *)(*(_DWORD *)v4 + v9 + 25);
                  if ( v9 + 27 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
                  {
                    *(_BYTE *)(a3 + 68) = *(_BYTE *)(*(_DWORD *)v4 + v9 + 26);
                    if ( v9 + 28 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
                    {
                      *(_BYTE *)(a3 + 69) = *(_BYTE *)(*(_DWORD *)v4 + v9 + 27);
                      if ( v9 + 29 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
                      {
                        *(_BYTE *)(a3 + 70) = *(_BYTE *)(*(_DWORD *)v4 + v9 + 28);
                        v13 = *(_DWORD *)v4;
                        v11 = v9 + 31;
                        v20 = *(_DWORD *)(v4 + 4);
                        v21 = v9 + 33;
                        v23 = v21;
                        v12 = v20 - v13;
                        if ( v21 <= v12 )
                        {
                          v14 = *(_WORD *)(v13 + v11);
                          v22 = v14;
                          if ( (unsigned int)v14 + v23 <= v12 )
                          {
                            if ( v14 <= 1u )
                              std__string__assign(a3 + 72, &aResNr[13]);
                            else
                              std__string__assign(a3 + 72, v13 + v23, v14 - 1);
                            v17 = *(_DWORD *)v4;
                            v15 = v23 + v22;
                            v16 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
                            v24 = v15 + 2;
                            if ( v15 + 2 <= v16 )
                            {
                              v18 = *(_WORD *)(v17 + v15);
                              v22 = v18;
                              if ( (unsigned int)v18 + v24 <= v16 )
                              {
                                if ( v18 <= 1u )
                                  std__string__assign(a3 + 76, &aResNr[13]);
                                else
                                  std__string__assign(a3 + 76, v17 + v24, v18 - 1);
                                v19 = v22 + v24;
                                if ( v19 + 2 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
                                {
                                  *(_WORD *)(a3 + 80) = *(_WORD *)(*(_DWORD *)v4 + v19);
                                  if ( v19 + 3 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
                                  {
                                    *(_BYTE *)(a3 + 82) = *(_BYTE *)(*(_DWORD *)v4 + v19 + 2);
                                    if ( v19 + 4 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
                                    {
                                      *(_BYTE *)(a3 + 83) = *(_BYTE *)(*(_DWORD *)v4 + v19 + 3);
                                      if ( v19 + 6 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
                                        *(_WORD *)(a3 + 84) = *(_WORD *)(*(_DWORD *)v4 + v19 + 4);
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

//----- (080595B0) --------------------------------------------------------
void __cdecl sub_80595B0(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // edi@1
  unsigned int v5; // ecx@3
  unsigned __int16 v6; // ax@4
  unsigned __int16 v7; // bx@4
  unsigned int v8; // edx@7
  int v9; // ecx@7
  int v10; // ebx@7
  int v11; // esi@7
  unsigned __int16 v12; // ax@8
  int v13; // eax@11
  unsigned int v14; // edx@11
  int v15; // ecx@11
  int v16; // ebx@11
  unsigned __int16 v17; // ax@12
  int v18; // eax@15
  unsigned int v19; // edx@15
  int v20; // ecx@15
  int v21; // ebx@15
  unsigned __int16 v22; // ax@16
  int v23; // eax@19
  unsigned int v24; // edx@19
  int v25; // ebx@19
  unsigned __int16 v26; // ax@20
  int v27; // eax@23
  unsigned int v28; // edx@23
  int v29; // ebx@23
  unsigned __int16 v30; // ax@24
  int v31; // eax@27
  unsigned int v32; // edx@27
  int v33; // ebx@27
  unsigned __int16 v34; // ax@28
  int v35; // eax@31
  unsigned int v36; // edx@31
  int v37; // ebx@31
  unsigned __int16 v38; // ax@32
  int v39; // eax@35
  unsigned int v40; // edx@35
  int v41; // ebx@35
  unsigned __int16 v42; // ax@36
  int v43; // eax@39
  unsigned int v44; // edx@39
  int v45; // ebx@39
  unsigned __int16 v46; // ax@40
  int v47; // eax@43
  unsigned int v48; // edx@43
  int v49; // ebx@43
  unsigned __int16 v50; // ax@44
  int v51; // edx@47
  unsigned __int16 v52; // [sp+4Ah] [bp-Eh]@4
  int v53; // [sp+1Ch] [bp-3Ch]@8
  int v54; // [sp+18h] [bp-40h]@12
  int v55; // [sp+14h] [bp-44h]@16
  int v56; // [sp+20h] [bp-38h]@19
  int v57; // [sp+24h] [bp-34h]@23
  int v58; // [sp+28h] [bp-30h]@27
  int v59; // [sp+2Ch] [bp-2Ch]@31
  int v60; // [sp+30h] [bp-28h]@35
  int v61; // [sp+34h] [bp-24h]@39
  int v62; // [sp+38h] [bp-20h]@43

  v4 = a2;
  v3 = *(_DWORD *)a2;
  if ( *(_BYTE *)(*(_DWORD *)a2 + 16) == 10 )
  {
    v5 = *(_DWORD *)(a2 + 4) - v3;
    if ( v5 > 0x12 )
    {
      v6 = *(_WORD *)(v3 + 17);
      v7 = *(_WORD *)(v3 + 17);
      v52 = *(_WORD *)(v3 + 17);
      if ( (unsigned int)v6 + 19 <= v5 )
      {
        if ( v7 <= 1u )
          std__string__assign(a3 + 4, &aResNr[13]);
        else
          std__string__assign(a3 + 4, v3 + 19, v6 - 1);
        v9 = *(_DWORD *)v4;
        v10 = v52 + 21;
        v11 = v52 + 19;
        v8 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
        if ( v10 <= v8 )
        {
          v12 = *(_WORD *)(v9 + v11);
          v52 = *(_WORD *)(v9 + v11);
          v53 = v12;
          if ( v10 + (unsigned int)v12 <= v8 )
          {
            if ( v12 <= 1u )
              std__string__assign(a3 + 8, &aResNr[13]);
            else
              std__string__assign(a3 + 8, v9 + v10, v53 - 1);
            v15 = *(_DWORD *)v4;
            v13 = v10 + v52;
            v16 = v13 + 2;
            v14 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
            if ( v13 + 2 <= v14 )
            {
              v17 = *(_WORD *)(v15 + v13);
              v52 = v17;
              v54 = v17;
              if ( v16 + (unsigned int)v17 <= v14 )
              {
                if ( v17 <= 1u )
                  std__string__assign(a3 + 12, &aResNr[13]);
                else
                  std__string__assign(a3 + 12, v15 + v16, v54 - 1);
                v20 = *(_DWORD *)v4;
                v18 = v16 + v52;
                v21 = v18 + 2;
                v19 = *(_DWORD *)(v4 + 4) - *(_DWORD *)v4;
                if ( v18 + 2 <= v19 )
                {
                  v22 = *(_WORD *)(v20 + v18);
                  v52 = v22;
                  v55 = v22;
                  if ( v21 + (unsigned int)v22 <= v19 )
                  {
                    if ( v22 <= 1u )
                      std__string__assign(a3 + 16, &aResNr[13]);
                    else
                      std__string__assign(a3 + 16, v20 + v21, v55 - 1);
                    v23 = v21 + v52;
                    v25 = *(_DWORD *)v4;
                    v56 = v23 + 2;
                    v24 = *(_DWORD *)(v4 + 4) - v25;
                    if ( v23 + 2 <= v24 )
                    {
                      v26 = *(_WORD *)(v25 + v23);
                      v52 = v26;
                      if ( (unsigned int)v26 + v56 <= v24 )
                      {
                        if ( v26 <= 1u )
                          std__string__assign(a3 + 20, &aResNr[13]);
                        else
                          std__string__assign(a3 + 20, v25 + v56, v26 - 1);
                        v27 = v56 + v52;
                        v29 = *(_DWORD *)v4;
                        v57 = v27 + 2;
                        v28 = *(_DWORD *)(v4 + 4) - v29;
                        if ( v27 + 2 <= v28 )
                        {
                          v30 = *(_WORD *)(v29 + v27);
                          v52 = v30;
                          if ( (unsigned int)v30 + v57 <= v28 )
                          {
                            if ( v30 <= 1u )
                              std__string__assign(a3 + 24, &aResNr[13]);
                            else
                              std__string__assign(a3 + 24, v29 + v57, v30 - 1);
                            v31 = v57 + v52;
                            v33 = *(_DWORD *)v4;
                            v58 = v31 + 2;
                            v32 = *(_DWORD *)(v4 + 4) - v33;
                            if ( v31 + 2 <= v32 )
                            {
                              v34 = *(_WORD *)(v33 + v31);
                              v52 = v34;
                              if ( (unsigned int)v34 + v58 <= v32 )
                              {
                                if ( v34 <= 1u )
                                  std__string__assign(a3 + 28, &aResNr[13]);
                                else
                                  std__string__assign(a3 + 28, v33 + v58, v34 - 1);
                                v35 = v58 + v52;
                                v37 = *(_DWORD *)v4;
                                v59 = v35 + 2;
                                v36 = *(_DWORD *)(v4 + 4) - v37;
                                if ( v35 + 2 <= v36 )
                                {
                                  v38 = *(_WORD *)(v37 + v35);
                                  v52 = v38;
                                  if ( (unsigned int)v38 + v59 <= v36 )
                                  {
                                    if ( v38 <= 1u )
                                      std__string__assign(a3 + 32, &aResNr[13]);
                                    else
                                      std__string__assign(a3 + 32, v37 + v59, v38 - 1);
                                    v39 = v59 + v52;
                                    v41 = *(_DWORD *)v4;
                                    v60 = v39 + 2;
                                    v40 = *(_DWORD *)(v4 + 4) - v41;
                                    if ( v39 + 2 <= v40 )
                                    {
                                      v42 = *(_WORD *)(v41 + v39);
                                      v52 = v42;
                                      if ( (unsigned int)v42 + v60 <= v40 )
                                      {
                                        if ( v42 <= 1u )
                                          std__string__assign(a3 + 36, &aResNr[13]);
                                        else
                                          std__string__assign(a3 + 36, v41 + v60, v42 - 1);
                                        v43 = v60 + v52;
                                        v45 = *(_DWORD *)v4;
                                        v61 = v43 + 2;
                                        v44 = *(_DWORD *)(v4 + 4) - v45;
                                        if ( v43 + 2 <= v44 )
                                        {
                                          v46 = *(_WORD *)(v45 + v43);
                                          v52 = v46;
                                          if ( (unsigned int)v46 + v61 <= v44 )
                                          {
                                            if ( v46 <= 1u )
                                              std__string__assign(a3 + 40, &aResNr[13]);
                                            else
                                              std__string__assign(a3 + 40, v45 + v61, v46 - 1);
                                            v47 = v61 + v52;
                                            v49 = *(_DWORD *)v4;
                                            v62 = v47 + 2;
                                            v48 = *(_DWORD *)(v4 + 4) - v49;
                                            if ( v47 + 2 <= v48 )
                                            {
                                              v50 = *(_WORD *)(v49 + v47);
                                              v52 = v50;
                                              if ( (unsigned int)v50 + v62 <= v48 )
                                              {
                                                if ( v50 <= 1u )
                                                  std__string__assign(a3 + 44, &aResNr[13]);
                                                else
                                                  std__string__assign(a3 + 44, v49 + v62, v50 - 1);
                                                v51 = v52 + v62;
                                                if ( v51 + 2 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
                                                {
                                                  *(_WORD *)(a3 + 48) = *(_WORD *)(*(_DWORD *)v4 + v51);
                                                  if ( v51 + 3 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
                                                  {
                                                    *(_BYTE *)(a3 + 50) = *(_BYTE *)(*(_DWORD *)v4 + v51 + 2);
                                                    if ( v51 + 4 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
                                                    {
                                                      *(_BYTE *)(a3 + 51) = *(_BYTE *)(*(_DWORD *)v4 + v51 + 3);
                                                      if ( v51 + 5 <= (unsigned int)(*(_DWORD *)(v4 + 4) - *(_DWORD *)v4) )
                                                      {
                                                        *(_BYTE *)(a3 + 52) = *(_BYTE *)(*(_DWORD *)v4 + v51 + 4);
                                                        if ( v51 + 6 <= (unsigned int)(*(_DWORD *)(v4 + 4)
                                                                                     - *(_DWORD *)v4) )
                                                        {
                                                          *(_BYTE *)(a3 + 53) = *(_BYTE *)(*(_DWORD *)v4 + v51 + 5);
                                                          if ( v51 + 7 <= (unsigned int)(*(_DWORD *)(v4 + 4)
                                                                                       - *(_DWORD *)v4) )
                                                            *(_BYTE *)(a3 + 54) = *(_BYTE *)(*(_DWORD *)v4 + v51 + 6);
                                                        }
                                                      }
                                                    }
                                                  }
                                                }
                                              }
                                            }
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

//----- (08059BB0) --------------------------------------------------------
signed int __cdecl sub_8059BB0(int a1)
{
  int v1; // edi@1
  signed int v2; // esi@1
  int v3; // eax@3
  int v4; // ebx@3
  unsigned int v5; // edx@4
  int v6; // ecx@4
  int v7; // eax@8
  int v8; // ebx@8
  unsigned int v9; // edx@9
  int v10; // ecx@9
  int v11; // eax@13
  int v12; // ebx@13
  unsigned int v13; // edx@14
  int v14; // ecx@14
  int v15; // eax@18
  int v16; // ebx@18
  unsigned int v17; // edx@19
  int v18; // ecx@19
  int v19; // eax@23
  int v20; // ebx@23
  unsigned int v21; // edx@24
  int v22; // ecx@24
  int v23; // eax@28
  __int16 v25; // ax@6
  __int16 v26; // ax@11
  __int16 v27; // ax@16
  __int16 v28; // ax@21
  __int16 v29; // ax@26
  int v30; // [sp+8h] [bp-10h]@1

  v1 = a1;
  v30 = a1 + 260;
  v2 = 1;
  do
  {
    if ( *(_WORD *)(v1 + 298) == (_WORD)v2 )
      goto LABEL_32;
    v3 = *(_DWORD *)(v1 + 4);
    v4 = (*(_DWORD *)(v1 + 8) - v3) >> 7;
    if ( v4 )
    {
      v5 = 0;
      v6 = *(_DWORD *)(v1 + 4);
      if ( *(_WORD *)(v3 + 16) == (_WORD)v2 )
        goto LABEL_32;
      while ( 1 )
      {
        ++v5;
        if ( v5 >= v4 )
          break;
        v25 = *(_WORD *)(v6 + 144);
        v6 += 128;
        if ( v25 == (_WORD)v2 )
          goto LABEL_32;
      }
    }
    v7 = *(_DWORD *)(v1 + 28);
    v8 = (*(_DWORD *)(v1 + 32) - v7) >> 7;
    if ( v8 )
    {
      v9 = 0;
      v10 = *(_DWORD *)(v1 + 28);
      if ( *(_WORD *)(v7 + 16) == (_WORD)v2 )
        goto LABEL_32;
      while ( 1 )
      {
        ++v9;
        if ( v9 >= v8 )
          break;
        v26 = *(_WORD *)(v10 + 144);
        v10 += 128;
        if ( v26 == (_WORD)v2 )
          goto LABEL_32;
      }
    }
    v11 = *(_DWORD *)(v1 + 40);
    v12 = (*(_DWORD *)(v1 + 44) - v11) >> 7;
    if ( v12 )
    {
      v13 = 0;
      v14 = *(_DWORD *)(v1 + 40);
      if ( *(_WORD *)(v11 + 16) == (_WORD)v2 )
        goto LABEL_32;
      while ( 1 )
      {
        ++v13;
        if ( v13 >= v12 )
          break;
        v27 = *(_WORD *)(v14 + 144);
        v14 += 128;
        if ( v27 == (_WORD)v2 )
          goto LABEL_32;
      }
    }
    v15 = *(_DWORD *)(v1 + 52);
    v16 = (*(_DWORD *)(v1 + 56) - v15) >> 7;
    if ( v16 )
    {
      v17 = 0;
      v18 = *(_DWORD *)(v1 + 52);
      if ( *(_WORD *)(v15 + 16) == (_WORD)v2 )
        goto LABEL_32;
      while ( 1 )
      {
        ++v17;
        if ( v17 >= v16 )
          break;
        v28 = *(_WORD *)(v18 + 144);
        v18 += 128;
        if ( v28 == (_WORD)v2 )
          goto LABEL_32;
      }
    }
    v19 = *(_DWORD *)(v1 + 64);
    v20 = (*(_DWORD *)(v1 + 68) - v19) >> 7;
    if ( v20 )
    {
      v21 = 0;
      v22 = *(_DWORD *)(v1 + 64);
      if ( *(_WORD *)(v19 + 16) == (_WORD)v2 )
        goto LABEL_32;
      while ( 1 )
      {
        ++v21;
        if ( v21 >= v20 )
          break;
        v29 = *(_WORD *)(v22 + 144);
        v22 += 128;
        if ( v29 == (_WORD)v2 )
          goto LABEL_32;
      }
    }
    v23 = *(_DWORD *)(v1 + 268);
    if ( v23 == v30 )
      return v2;
    while ( *(_WORD *)(v23 + 16) != (_WORD)v2 )
    {
      v23 = std___Rb_tree_increment(v23);
      if ( v23 == v30 )
        return v2;
    }
LABEL_32:
    ++v2;
  }
  while ( (_WORD)v2 != -2 );
  return 0;
}

//----- (08059D50) --------------------------------------------------------
signed int __cdecl sub_8059D50(int a1, int a2, int a3, int a4)
{
  int v4; // edx@1
  int v5; // edi@1
  int v6; // esi@1
  signed int v7; // ebx@2
  signed int result; // eax@3
  int v9; // ecx@5
  time_t v10; // eax@1
  int v11; // eax@5
  int v12; // edx@6
  int v13; // eax@6
  int v14; // ebx@7
  char v15; // al@9
  int v16; // [sp+1Ch] [bp-6Ch]@1
  int v17; // [sp+18h] [bp-70h]@1
  int v18; // [sp+78h] [bp-10h]@1
  int v19; // [sp+20h] [bp-68h]@6
  int v20; // [sp+24h] [bp-64h]@7
  int (__cdecl *v21)(_DWORD, _DWORD, _DWORD); // [sp+28h] [bp-60h]@7
  char v22; // [sp+2Ch] [bp-5Ch]@7
  char v23; // [sp+30h] [bp-58h]@8
  char v24; // [sp+34h] [bp-54h]@9
  char v25; // [sp+3Ch] [bp-4Ch]@12
  char v26; // [sp+48h] [bp-40h]@12
  int v27; // [sp+40h] [bp-48h]@14
  int v28; // [sp+44h] [bp-44h]@14

  v6 = a2;
  v5 = a4;
  v16 = a1;
  v17 = a3;
  v18 = *MK_FP(__GS__, 20);
  v10 = time(0);
  v4 = *(_DWORD *)v5;
  *(_BYTE *)(v6 + 8) = 0;
  *(_DWORD *)(v6 + 36) = v10;
  if ( (unsigned int)(*(_DWORD *)(v5 + 4) - v4) <= 0xA
    || (*(_DWORD *)v6 = *(_DWORD *)v4, v11 = *(_DWORD *)(v4 + 4), *(_BYTE *)(v6 + 8) = 1, *(_DWORD *)(v6 + 4) = v11, v9 = *(_DWORD *)v5, *(_BYTE *)(*(_DWORD *)v5 + 9) != 2)
    || (v12 = *(_BYTE *)(v9 + 10), v13 = *(_DWORD *)(v5 + 4), v19 = *(_BYTE *)(v9 + 10), v12 + 14 > (unsigned int)(v13 - v9))
    || (v20 = v6 + 12, std__string__assign(v6 + 12, v9 + 11, v19), v14 = *(_DWORD *)v5, v21 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD))(*(_DWORD *)v16 + 60), std__string__string(&v22, v20), v21(v16, &v22, v14), std__string___string(&v22), *(_BYTE *)(*(_DWORD *)v5 + v19 + 12) != 3) )
  {
    v7 = 0;
    goto LABEL_3;
  }
  sub_8051580((int)&v23);
  if ( (unsigned __int8)sub_8051830((signed int)&v23, v5, v19 + 13) )
  {
    v15 = v24;
    *(_BYTE *)v17 = v24;
    if ( (unsigned __int8)(v15 + 24) <= 4u )
    {
      std__string__assign(v6 + 16, &v25);
      v7 = (signed int)&v26;
      if ( std__string__compare(&v26, "{0946134E-4C7F-11D1-8222-444553540000}") )
        goto LABEL_16;
      goto LABEL_13;
    }
  }
  v7 = 0;
  while ( 1 )
  {
    sub_80543A0((int)&v23);
LABEL_3:
    result = v7;
    if ( !(*MK_FP(__GS__, 20) ^ v18) )
      break;
    __stack_chk_fail();
LABEL_16:
    if ( std__string__compare(v7, "{0946134e-4c7f-11d1-8222-444553540000}") )
      *(_DWORD *)(v6 + 28) = 1;
    else
LABEL_13:
      *(_DWORD *)(v6 + 28) = 3;
    v7 = 1;
    *(_DWORD *)(v6 + 20) = v27;
    *(_DWORD *)(v6 + 24) = v28;
  }
  return result;
}

//----- (08059F40) --------------------------------------------------------
#error "805A069: invalid basic block (funcsize=93)"

//----- (0805A070) --------------------------------------------------------
signed int __cdecl sub_805A070(int a1)
{
  int v1; // edx@1
  int v2; // ecx@1
  int v3; // ebx@1
  signed int v4; // ebx@2
  __int16 v6; // ax@1
  char v7; // [sp+1Ch] [bp-1Ch]@1
  __int16 v8; // [sp+1Eh] [bp-1Ah]@1
  signed int v9; // [sp+2Ch] [bp-Ch]@2

  v3 = a1;
  sub_8050EE0((int)&v7);
  v7 = 5;
  v6 = *(_WORD *)(v3 + 168);
  v8 = *(_WORD *)(v3 + 168);
  *(_WORD *)(v3 + 168) = v6 + 1;
  (*(int (__cdecl **)(int))(*(_DWORD *)v3 + 8))(v3);
  if ( sub_8051DF0(v2, v1, (int)&v7, *(_DWORD *)(v3 + 164)) )
  {
    *(_DWORD *)(v3 + 288) = time(0);
    v4 = 1;
  }
  else
  {
    v4 = v9;
  }
  sub_80522F0(v2, v1, (int)&v7);
  return v4;
}

//----- (0805A110) --------------------------------------------------------
int __cdecl sub_805A110(int a1)
{
  int v2; // ebx@1
  __int16 v3; // ax@1
  int v4; // ecx@1
  int v5; // edx@1
  int v6; // eax@1
  int v7; // ebx@1
  int v8; // ecx@1
  int v9; // edx@1
  char v10; // [sp+1Ch] [bp-1Ch]@1
  __int16 v11; // [sp+1Eh] [bp-1Ah]@1

  v2 = a1;
  sub_8050EE0((int)&v10);
  v10 = 4;
  v3 = *(_WORD *)(v2 + 168);
  v11 = *(_WORD *)(v2 + 168);
  *(_WORD *)(v2 + 168) = v3 + 1;
  LOBYTE(v6) = sub_8051DF0(v4, v5, (int)&v10, *(_DWORD *)(v2 + 164));
  v7 = v6;
  sub_80522F0(v8, v9, (int)&v10);
  return v7;
}

//----- (0805A180) --------------------------------------------------------
signed int __cdecl sub_805A180(int a1, __int16 a2, __int16 a3, int a4, int a5)
{
  int v5; // edx@1
  int v6; // ecx@1
  int v7; // ebx@1
  int v8; // ecx@5
  signed int v9; // ebx@7
  __int16 v11; // si@1
  __int16 v12; // di@1
  __int16 v13; // ax@1
  int v14; // eax@1
  char v15; // zf@1
  int v16; // ecx@8
  char v17; // [sp+38h] [bp-20h]@1
  __int16 v18; // [sp+3Ah] [bp-1Eh]@1
  __int16 v19; // [sp+20h] [bp-38h]@1
  __int16 v20; // [sp+22h] [bp-36h]@1
  __int16 v21; // [sp+24h] [bp-34h]@1
  int v22; // [sp+28h] [bp-30h]@1
  char v23; // [sp+2Ch] [bp-2Ch]@2
  char v24; // [sp+3Ch] [bp-1Ch]@5
  signed int v25; // [sp+48h] [bp-10h]@7

  v7 = a1;
  v11 = a2;
  v12 = a3;
  sub_8050EE0((int)&v17);
  v17 = 2;
  v13 = *(_WORD *)(v7 + 168);
  v18 = *(_WORD *)(v7 + 168);
  *(_WORD *)(v7 + 168) = v13 + 1;
  sub_8050F20((int)&v19);
  v14 = *(_DWORD *)(v7 + 172);
  v19 = v11;
  v20 = v12;
  v21 = 0;
  v22 = v14;
  v15 = a5 == 0;
  *(_DWORD *)(v7 + 172) = v14 + 1;
  if ( !v15 )
    sub_804B500(v6, v5, (int)&v23, a5);
  if ( a4 )
    *(_DWORD *)a4 = v22;
  sub_80527D0((int)&v19, (int)&v24, 0);
  (*(int (__cdecl **)(int))(*(_DWORD *)v7 + 8))(v7);
  if ( *(_BYTE *)(v7 + 284) )
  {
    *(_BYTE *)(v7 + 284) = 0;
    v9 = -2;
  }
  else
  {
    if ( sub_8051DF0(v8, (int)&v17, (int)&v17, *(_DWORD *)(v7 + 164)) )
    {
      *(_DWORD *)(v7 + 288) = time(0);
      v9 = 1;
    }
    else
    {
      v9 = v25;
    }
  }
  sub_8052330(v8, (int)&v19, (int)&v19);
  sub_80522F0(v16, (int)&v17, (int)&v17);
  return v9;
}

//----- (0805A2D0) --------------------------------------------------------
char __cdecl sub_805A2D0(int a1)
{
  return sub_805A180(a1, 19, 18, 0, 0) == 1;
}

//----- (0805A310) --------------------------------------------------------
char __cdecl sub_805A310(int a1)
{
  return sub_805A180(a1, 19, 17, 0, 0) == 1;
}

//----- (0805A350) --------------------------------------------------------
char __cdecl sub_805A350(int a1)
{
  return sub_805A180(a1, 19, 7, 0, 0) == 1;
}

//----- (0805A390) --------------------------------------------------------
char __cdecl sub_805A390(int a1, int a2)
{
  return sub_805A180(a1, 19, 4, a2, 0) == 1;
}

//----- (0805A3D0) --------------------------------------------------------
char __cdecl sub_805A3D0(int a1, int a2)
{
  return sub_805A180(a1, 19, 2, a2, 0) == 1;
}

//----- (0805A410) --------------------------------------------------------
char __cdecl sub_805A410(int a1, int a2)
{
  return sub_805A180(a1, 9, 2, a2, 0) == 1;
}

//----- (0805A450) --------------------------------------------------------
char __cdecl sub_805A450(int a1, int a2)
{
  return sub_805A180(a1, 4, 4, a2, 0) == 1;
}

//----- (0805A490) --------------------------------------------------------
char __cdecl sub_805A490(int a1, int a2)
{
  return sub_805A180(a1, 3, 2, a2, 0) == 1;
}

//----- (0805A4D0) --------------------------------------------------------
char __cdecl sub_805A4D0(int a1, int a2)
{
  return sub_805A180(a1, 2, 2, a2, 0) == 1;
}

//----- (0805A510) --------------------------------------------------------
char __cdecl sub_805A510(int a1, int a2)
{
  return sub_805A180(a1, 1, 14, a2, 0) == 1;
}

//----- (0805A550) --------------------------------------------------------
char __cdecl sub_805A550(int a1, int a2)
{
  return sub_805A180(a1, 1, 6, a2, 0) == 1;
}

//----- (0805A590) --------------------------------------------------------
signed int __cdecl sub_805A590(int a1, int a2)
{
  int v2; // edi@1
  int v3; // esi@1
  int v4; // edx@2
  int v5; // ecx@2
  signed int v6; // ebx@5
  int v9; // edx@16
  __int16 v10; // ax@20
  int v11; // eax@22
  int v12; // edx@26
  unsigned __int16 v13; // ax@27
  int v14; // ebx@28
  int v15; // edx@31
  int v16; // eax@32
  int v17; // eax@34
  __int16 v18; // ax@24
  int v19; // ecx@24
  int v20; // edx@24
  int v21; // ecx@24
  int v22; // edx@24
  int v23; // ecx@31
  int (__cdecl *v24)(_DWORD, _DWORD, _DWORD); // ebx@36
  char v25; // [sp+3Ch] [bp-3Ch]@2
  signed int v26; // [sp+4Ch] [bp-2Ch]@5
  unsigned __int16 v27; // [sp+24h] [bp-54h]@14
  char v28; // [sp+40h] [bp-38h]@14
  __int16 v29; // [sp+28h] [bp-50h]@15
  __int16 v30; // [sp+26h] [bp-52h]@20
  int v31; // [sp+2Ch] [bp-4Ch]@22
  void *v32; // [sp+30h] [bp-48h]@24
  void *v33; // [sp+14h] [bp-64h]@26
  int v34; // [sp+34h] [bp-44h]@26
  unsigned __int16 v35; // [sp+6Ah] [bp-Eh]@27
  int v36; // [sp+18h] [bp-60h]@27
  char v37; // [sp+50h] [bp-28h]@31
  signed int v38; // [sp+64h] [bp-14h]@34
  signed int *v39; // [sp+10h] [bp-68h]@34
  char v40; // [sp+60h] [bp-18h]@36

  v2 = a1;
  v3 = *(_DWORD *)(a1 + 280);
  sub_804B220(*(_DWORD *)(a1 + 252), 300);
  if ( (unsigned __int8)sub_804B290(*(_DWORD *)(v2 + 252), a2) )
  {
    (*(int (__cdecl **)(int))(*(_DWORD *)v2 + 8))(v2);
    return 1;
  }
  while ( 1 )
  {
    sub_8050EE0((int)&v25);
    while ( 1 )
    {
      if ( *(_BYTE *)(v2 + 284) )
      {
        *(_BYTE *)(v2 + 284) = 0;
        v6 = -2;
LABEL_7:
        sub_80522F0(v5, (int)&v25, (int)&v25);
        return v6;
      }
      if ( (unsigned __int8)sub_8051F30((int)&v25, v4, (int)&v25, *(_DWORD *)(v2 + 164)) )
        break;
      v6 = v26;
      if ( v26 == -2 )
      {
        --v3;
        if ( v3 )
          continue;
      }
      goto LABEL_7;
    }
    if ( !v3 )
    {
      v6 = -2;
      goto LABEL_7;
    }
    if ( v25 == 4 )
    {
      sub_8050FB0((int)&v37);
      if ( (unsigned __int8)sub_8055270(v23, (int)&v37, (int)&v37, (int)&v28, 0) )
      {
        v35 = 0;
        v16 = sub_8050FE0((int)&v37, 9);
        if ( v16 )
          sub_8051690(v16, (int)&v35);
        v38 = 134771820;
        v17 = sub_8050FE0((int)&v37, 11);
        v39 = &v38;
        if ( v17 )
        {
          v39 = &v38;
          sub_8051550(v17, (int)&v38);
        }
        v24 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD))(*(_DWORD *)v2 + 56);
        std__string__string(&v40, v39);
        v24(v2, v35, &v40);
        std__string___string(&v40);
        std__string___string(v39);
      }
      sub_8052390((int)&v37, v15, (int)&v37);
      v6 = 0;
      goto LABEL_7;
    }
    if ( v25 != 2 )
      goto LABEL_13;
    sub_8050F20((int)&v27);
    if ( (unsigned __int8)sub_80514B0((int)&v27, (int)&v28, 0) )
      break;
LABEL_19:
    sub_8052330((int)&v27, v4, (int)&v27);
LABEL_13:
    sub_80522F0((int)&v25, v4, (int)&v25);
  }
  if ( v29 < 0 )
  {
    v33 = v32;
    v12 = v34;
    if ( (unsigned int)(v34 - (_DWORD)v32) > 1 )
    {
      v13 = __ROR__(*(_WORD *)v33, 8);
      v35 = v13;
      v36 = v34;
      if ( (unsigned int)v13 + 2 <= v34 - (_DWORD)v32 )
      {
        v14 = (int)(v33 + v13 + 2);
        if ( v34 != v14 )
        {
          memmove(v33, v33 + v13 + 2, v34 - v14);
          v12 = v34;
          v36 = v14;
        }
        v34 = (int)((char *)v33 + v12 - v36);
      }
    }
  }
  v9 = v27;
  if ( v27 != *(_WORD *)a2 && *(_WORD *)a2
    || (v10 = *(_WORD *)(a2 + 2), v30 != v10) && v10
    || (v11 = *(_DWORD *)(a2 + 8), v31 != v11) && v11 )
  {
    sub_804B370(*(_DWORD *)(v2 + 252), (int)&v27);
    goto LABEL_19;
  }
  v18 = v30;
  *(_WORD *)a2 = v27;
  *(_WORD *)(a2 + 2) = v18;
  *(_WORD *)(a2 + 4) = v29;
  *(_DWORD *)(a2 + 8) = v31;
  sub_804B500(a2, v9, a2 + 12, (int)&v32);
  sub_8052330(v19, v20, (int)&v27);
  v6 = 1;
  sub_80522F0(v21, v22, (int)&v25);
  return v6;
}

//----- (0805A920) --------------------------------------------------------
signed int __cdecl sub_805A920(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ecx@1
  signed int v5; // ebx@1
  int v6; // edi@1
  int v8; // ebx@3
  __int16 v9; // ax@6
  __int16 v10; // [sp+24h] [bp-24h]@1
  __int16 v11; // [sp+26h] [bp-22h]@1
  int v12; // [sp+2Ch] [bp-1Ch]@1
  int v13; // [sp+30h] [bp-18h]@3
  int v14; // [sp+34h] [bp-14h]@3

  v6 = a2;
  sub_8050F20((int)&v10);
  v10 = 19;
  v11 = 14;
  v12 = a3;
  v5 = 0;
  if ( sub_805A590(a1, (int)&v10) == 1 )
  {
    v8 = v13;
    if ( (unsigned int)(v14 - v13) >> 1 )
    {
      v3 = 0;
      v4 = (unsigned int)(v14 - v13) >> 1;
      do
      {
        v9 = __ROR__(*(_WORD *)(v8 + 2 * v3), 8);
        *(_WORD *)v6 = v9;
        if ( v9 )
          break;
        ++v3;
      }
      while ( v4 > (unsigned int)v3 );
    }
    v5 = 1;
  }
  sub_8052330(v4, v3, (int)&v10);
  return v5;
}

//----- (0805A9C0) --------------------------------------------------------
signed int __cdecl sub_805A9C0(int a1, unsigned int a2, int a3)
{
  int v3; // edx@1
  int v4; // ecx@1
  signed int v5; // ebx@1
  unsigned int v7; // edx@3
  int v8; // ecx@3
  unsigned __int16 v9; // ax@9
  unsigned __int16 v10; // ax@12
  int v11; // eax@14
  int v12; // ebx@14
  unsigned __int16 v13; // ax@15
  int v14; // eax@17
  int v15; // ebx@17
  unsigned __int16 v16; // ax@18
  int v17; // ebx@20
  int v18; // eax@22
  __int16 v19; // [sp+1Ch] [bp-3Ch]@1
  __int16 v20; // [sp+1Eh] [bp-3Ah]@1
  int v21; // [sp+24h] [bp-34h]@1
  __int16 v22; // [sp+34h] [bp-24h]@3
  char v23; // [sp+28h] [bp-30h]@3
  int v24; // [sp+38h] [bp-20h]@7
  int v25; // [sp+3Ch] [bp-1Ch]@7
  unsigned __int16 v26; // [sp+4Ah] [bp-Eh]@9
  int v27; // [sp+10h] [bp-48h]@11
  unsigned __int16 v28; // [sp+48h] [bp-10h]@12
  int v29; // [sp+14h] [bp-44h]@14
  unsigned __int16 v30; // [sp+46h] [bp-12h]@15
  int v31; // [sp+18h] [bp-40h]@17
  unsigned __int16 v32; // [sp+44h] [bp-14h]@18

  sub_8050F20((int)&v19);
  v19 = 21;
  v20 = 3;
  v21 = a3;
  v5 = 0;
  if ( sub_805A590(a1, (int)&v19) == 1 )
  {
    sub_8050F60((int)&v22);
    if ( (unsigned __int8)sub_80516C0((int)&v22, (int)&v23, 0)
      && v22 == 1
      && (v8 = v24, v7 = v25 - v24, (unsigned int)(v25 - v24) > 0xE)
      && *(_BYTE *)(v24 + 12) == 10
      && (v9 = *(_WORD *)(v24 + 13), v26 = *(_WORD *)(v24 + 13), v9)
      && (unsigned int)v9 + 15 <= v7
      && (std__string__assign(a2 + 4, v24 + 15, v9 - 1), v8 = v26 + 15, v27 = v26 + 17, v7 = v25 - v24, (unsigned int)v26 + 17 <= v25 - v24)
      && (v10 = *(_WORD *)(v24 + v8), v28 = *(_WORD *)(v24 + v8), v10)
      && (v8 = v10, (unsigned int)v10 + v27 <= v7)
      && (std__string__assign(a2 + 8, v24 + v27, v10 - 1), v8 = v24, v11 = v27 + v28, v29 = v24, v12 = v11 + 2, v7 = v25 - v24, v11 + 2 <= (unsigned int)(v25 - v24))
      && (v13 = *(_WORD *)(v24 + v11), v30 = v13, v13)
      && (v8 = v13, v12 + (unsigned int)v13 <= v7)
      && (std__string__assign(a2 + 12, v12 + v29, v13 - 1), v31 = v24, v7 = v25 - v24, v14 = v12 + v30, v15 = v14 + 2, v14 + 2 <= (unsigned int)(v25 - v24))
      && (v8 = v31, v16 = *(_WORD *)(v31 + v14), v32 = v16, v16)
      && (v8 = v16, v15 + (unsigned int)v16 <= v7)
      && (std__string__assign(a2 + 16, v15 + v31, v16 - 1), v8 = v15 + v32, v17 = v24, v7 = v25 - v24, v8 + 1 <= (unsigned int)(v25 - v24))
      && (*(_BYTE *)(a2 + 24) = *(_BYTE *)(v24 + v8) != 0, v8 + 3 <= v7) )
    {
      v18 = *(_BYTE *)(v17 + v8 + 2);
      v5 = 1;
      v7 = a2;
      *(_DWORD *)(a2 + 20) = v18;
    }
    else
    {
      v5 = 0;
    }
    sub_8052370(v4, v3, (int)&v22);
  }
  sub_8052330(v4, v3, (int)&v19);
  return v5;
}

//----- (0805AD80) --------------------------------------------------------
char __cdecl sub_805AD80(int a1, int a2)
{
  signed int v3; // ebx@1
  int v4; // ecx@1
  int v5; // edx@1
  __int16 v6; // [sp+18h] [bp-20h]@1
  __int16 v7; // [sp+1Ah] [bp-1Eh]@1
  int v8; // [sp+20h] [bp-18h]@1

  sub_8050F20((int)&v6);
  v6 = 19;
  v7 = 3;
  v8 = a2;
  v3 = sub_805A590(a1, (int)&v6);
  sub_8052330(v4, v5, (int)&v6);
  return v3 == 1;
}

//----- (0805ADF0) --------------------------------------------------------
char __cdecl sub_805ADF0(int a1, int a2)
{
  signed int v3; // ebx@1
  int v4; // ecx@1
  int v5; // edx@1
  __int16 v6; // [sp+18h] [bp-20h]@1
  __int16 v7; // [sp+1Ah] [bp-1Eh]@1
  int v8; // [sp+20h] [bp-18h]@1

  sub_8050F20((int)&v6);
  v6 = 9;
  v7 = 3;
  v8 = a2;
  v3 = sub_805A590(a1, (int)&v6);
  sub_8052330(v4, v5, (int)&v6);
  return v3 == 1;
}

//----- (0805AE60) --------------------------------------------------------
char __cdecl sub_805AE60(int a1, int a2)
{
  signed int v3; // ebx@1
  int v4; // ecx@1
  int v5; // edx@1
  __int16 v6; // [sp+18h] [bp-20h]@1
  __int16 v7; // [sp+1Ah] [bp-1Eh]@1
  int v8; // [sp+20h] [bp-18h]@1

  sub_8050F20((int)&v6);
  v6 = 3;
  v7 = 3;
  v8 = a2;
  v3 = sub_805A590(a1, (int)&v6);
  sub_8052330(v4, v5, (int)&v6);
  return v3 == 1;
}

//----- (0805AED0) --------------------------------------------------------
char __cdecl sub_805AED0(int a1, int a2)
{
  signed int v3; // ebx@1
  int v4; // ecx@1
  int v5; // edx@1
  __int16 v6; // [sp+18h] [bp-20h]@1
  __int16 v7; // [sp+1Ah] [bp-1Eh]@1
  int v8; // [sp+20h] [bp-18h]@1

  sub_8050F20((int)&v6);
  v6 = 2;
  v7 = 3;
  v8 = a2;
  v3 = sub_805A590(a1, (int)&v6);
  sub_8052330(v4, v5, (int)&v6);
  return v3 == 1;
}

//----- (0805AF40) --------------------------------------------------------
char __cdecl sub_805AF40(int a1, int a2)
{
  signed int v3; // ebx@1
  int v4; // ecx@1
  int v5; // edx@1
  __int16 v6; // [sp+18h] [bp-20h]@1
  __int16 v7; // [sp+1Ah] [bp-1Eh]@1
  int v8; // [sp+20h] [bp-18h]@1

  sub_8050F20((int)&v6);
  v6 = 1;
  v7 = 15;
  v8 = a2;
  v3 = sub_805A590(a1, (int)&v6);
  sub_8052330(v4, v5, (int)&v6);
  return v3 == 1;
}

//----- (0805AFB0) --------------------------------------------------------
signed int __cdecl sub_805AFB0(int a1)
{
  int v1; // ecx@1
  int v2; // edi@2
  signed int v3; // ebx@4
  int v4; // esi@4
  char v5; // zf@7
  int v6; // eax@7
  __int16 v7; // dx@10
  int v8; // edx@11
  signed int v9; // ebx@13
  __int16 v11; // dx@10
  __int16 v12; // ax@11
  __int16 v13; // [sp+1Ch] [bp-2Ch]@1
  __int16 v14; // [sp+1Eh] [bp-2Ah]@1
  int v15; // [sp+24h] [bp-24h]@1
  int v16; // [sp+2Ch] [bp-1Ch]@2
  int v17; // [sp+28h] [bp-20h]@2
  int v18; // [sp+18h] [bp-30h]@4
  int v19; // [sp+34h] [bp-14h]@6
  __int16 v20; // [sp+3Ah] [bp-Eh]@10
  __int16 v21; // [sp+38h] [bp-10h]@11

  sub_8050F20((int)&v13);
  v13 = 1;
  v14 = 24;
  v15 = 0;
  if ( sub_805A590(a1, (int)&v13) == 1 )
  {
    v2 = v16;
    v1 = v17;
    *(_DWORD *)(a1 + 180) = *(_DWORD *)(a1 + 176);
    if ( v2 == v1 )
    {
LABEL_15:
      v9 = 1;
      goto LABEL_14;
    }
    if ( v2 - v1 != 1 )
    {
      v3 = 2;
      v4 = 0;
      v18 = a1 + 176;
      do
      {
        v11 = *(_WORD *)(v1 + v4);
        v4 = v3 + 2;
        v7 = __ROR__(v11, 8);
        v20 = v7;
        if ( v2 - v1 < (unsigned int)(v3 + 2) )
          break;
        v12 = __ROR__(*(_WORD *)(v1 + v3), 8);
        v21 = v12;
        HIWORD(v19) = v12;
        LOWORD(v19) = v7;
        v8 = *(_DWORD *)(a1 + 180);
        if ( v8 != *(_DWORD *)(a1 + 184) )
        {
          if ( v8 )
          {
            *(_DWORD *)v8 = v19;
            v1 = v17;
            v2 = v16;
          }
          *(_DWORD *)(a1 + 180) = v8 + 4;
          v6 = v2 - v1;
          v5 = v2 - v1 == v4;
          if ( v2 - v1 < (unsigned int)v4 )
            break;
        }
        else
        {
          sub_8078330(v1, v18, v18, *(_DWORD *)(a1 + 180), (unsigned int)&v19);
          v2 = v16;
          v1 = v17;
          v6 = v16 - v17;
          v5 = v16 - v17 == v4;
          if ( v16 - v17 < (unsigned int)v4 )
            break;
        }
        if ( v5 )
          goto LABEL_15;
        v3 += 4;
      }
      while ( v6 >= (unsigned int)v3 );
    }
  }
  v9 = 0;
LABEL_14:
  sub_8052330(v1, (int)&v13, (int)&v13);
  return v9;
}

//----- (0805B100) --------------------------------------------------------
signed int __cdecl sub_805B100(int a1)
{
  int v1; // edx@1
  int v2; // ecx@1
  int v3; // edi@1
  int v4; // esi@2
  int v5; // edx@4
  int v6; // ebx@4
  char v7; // zf@7
  unsigned int v8; // edx@11
  signed int v9; // ebx@13
  int v11; // eax@7
  __int16 v12; // ax@11
  char v13; // zf@11
  __int16 v14; // [sp+1Ch] [bp-2Ch]@1
  __int16 v15; // [sp+1Eh] [bp-2Ah]@1
  int v16; // [sp+24h] [bp-24h]@1
  int v17; // [sp+2Ch] [bp-1Ch]@2
  int v18; // [sp+28h] [bp-20h]@2
  int v19; // [sp+18h] [bp-30h]@4
  int v20; // [sp+36h] [bp-12h]@6
  __int16 v21; // [sp+3Ah] [bp-Eh]@11

  v3 = a1;
  sub_8050F20((int)&v14);
  v14 = 1;
  v15 = 3;
  v16 = 0;
  if ( sub_805A590(v3, (int)&v14) == 1 )
  {
    v4 = v17;
    v2 = v18;
    *(_DWORD *)(v3 + 180) = *(_DWORD *)(v3 + 176);
    if ( v4 == v2 )
    {
LABEL_15:
      v9 = 1;
      goto LABEL_14;
    }
    if ( v4 - v2 != 1 )
    {
      v6 = 2;
      v19 = v3 + 176;
      v5 = 0;
      while ( 1 )
      {
        v12 = *(_WORD *)(v2 + v5);
        v8 = *(_DWORD *)(v3 + 180);
        v12 = __ROR__(v12, 8);
        v13 = v8 == *(_DWORD *)(v3 + 184);
        v21 = v12;
        LOWORD(v20) = v12;
        HIWORD(v20) = 1;
        if ( !v13 )
        {
          if ( v8 )
          {
            *(_DWORD *)v8 = v20;
            v2 = v18;
            v4 = v17;
          }
          v11 = v8 + 4;
          v1 = v4 - v2;
          v7 = v4 - v2 == v6;
          *(_DWORD *)(v3 + 180) = v11;
          if ( v4 - v2 < (unsigned int)v6 )
            break;
        }
        else
        {
          sub_8078330(v2, v8, v19, v8, (unsigned int)&v20);
          v4 = v17;
          v2 = v18;
          v1 = v17 - v18;
          v7 = v17 - v18 == v6;
          if ( v17 - v18 < (unsigned int)v6 )
            break;
        }
        if ( v7 )
          goto LABEL_15;
        if ( v6 + 2 > (unsigned int)v1 )
          break;
        v5 = v6;
        v6 += 2;
      }
    }
  }
  v9 = 0;
LABEL_14:
  sub_8052330(v2, v1, (int)&v14);
  return v9;
}

//----- (0805B230) --------------------------------------------------------
signed int __cdecl sub_805B230(int a1, int a2, int a3, int a4)
{
  int v4; // edx@1
  int v5; // ecx@1
  signed int v6; // ebx@1
  int v7; // esi@1
  int v9; // ecx@9
  int v10; // eax@10
  int v11; // eax@11
  int v12; // eax@16
  int v13; // eax@18
  int v14; // ebx@18
  int v15; // eax@20
  int v16; // ecx@20
  char v17; // [sp+20h] [bp-38h]@1
  signed int v18; // [sp+30h] [bp-28h]@3
  char v19; // [sp+34h] [bp-24h]@9
  char v20; // [sp+24h] [bp-34h]@9
  signed int v21; // [sp+48h] [bp-10h]@17
  const char *v22; // [sp+44h] [bp-14h]@20

  v7 = a1;
  sub_8050EE0((int)&v17);
  v6 = *(_DWORD *)(v7 + 280);
  while ( 1 )
  {
    if ( (unsigned __int8)sub_8051F30(v5, v4, (int)&v17, *(_DWORD *)(v7 + 164)) )
    {
      if ( !v6 || v17 != 4 )
      {
LABEL_5:
        v6 = 0;
        goto LABEL_6;
      }
      sub_8050FB0((int)&v19);
      if ( (unsigned __int8)sub_8055270(v9, (int)&v19, (int)&v19, (int)&v20, 0) )
      {
        v10 = sub_8050FE0((int)&v19, 8);
        if ( v10 )
        {
          sub_8051690(v10, v7 + 100);
          v11 = sub_8050FE0((int)&v19, 4);
          if ( v11 )
            sub_8051550(v11, v7 + 104);
        }
        else
        {
          v12 = sub_8050FE0((int)&v19, 5);
          if ( v12 )
          {
            v21 = 134771820;
            if ( (unsigned __int8)sub_8051550(v12, (int)&v21)
              && (v13 = std__string__find(&v21, &unk_807F5E8, 0), v14 = v13, v13 != -1)
              && v13 < (unsigned int)(*(_DWORD *)(v21 - 12) - 1)
              && (std__string__assign(a2, &v21, 0, v13), std__string__string(&v22, &v21, v14 + 1, -1), *(_DWORD *)a3 = strtol(v22, 0, 10), std__string___string(&v22), v15 = sub_8050FE0((int)&v19, 6), v15) )
            {
              sub_804B500(v16, a4, a4, v15 + 4);
              v6 = 1;
            }
            else
            {
              v6 = 0;
            }
            std__string___string(&v21);
            goto LABEL_14;
          }
        }
      }
      v6 = 0;
LABEL_14:
      sub_8052390(v5, (int)&v19, (int)&v19);
      goto LABEL_6;
    }
    if ( v18 != -2 )
      break;
    --v6;
    if ( !v6 )
      goto LABEL_5;
  }
  LOBYTE(v6) = v18 != 0;
LABEL_6:
  sub_80522F0(v5, v4, (int)&v17);
  return v6;
}

//----- (0805B480) --------------------------------------------------------
signed int __cdecl sub_805B480(int a1)
{
  signed int v1; // ebx@1
  int v2; // esi@1
  int v3; // edx@4
  int v4; // ecx@4
  char v6; // [sp+28h] [bp-30h]@1
  signed int v7; // [sp+38h] [bp-20h]@2
  char v8; // [sp+3Ch] [bp-1Ch]@9
  char v9; // [sp+2Ch] [bp-2Ch]@9

  v1 = 300;
  v2 = a1;
  sub_8050EE0((int)&v6);
  while ( 1 )
  {
    (*(int (__cdecl **)(int))(*(_DWORD *)v2 + 8))(v2);
    if ( (unsigned __int8)sub_8051F30(v4, v3, (int)&v6, *(_DWORD *)(v2 + 164)) )
      break;
    if ( v7 == -2 )
    {
      --v1;
      if ( v1 )
        continue;
    }
    goto LABEL_7;
  }
  if ( !v1 || v6 != 1 )
  {
LABEL_7:
    v1 = 0;
    goto LABEL_8;
  }
  sub_8051060((int)&v8);
  LOBYTE(v1) = (unsigned __int8)sub_8055410((int)&v8, (int)&v9, 0) != 0;
  sub_80524F0(v4, v3, (int)&v8);
LABEL_8:
  sub_80522F0(v4, v3, (int)&v6);
  return v1;
}

//----- (0805B550) --------------------------------------------------------
#error "805B64E: invalid basic block (funcsize=64)"

//----- (0805B650) --------------------------------------------------------
int __cdecl sub_805B650(int a1)
{
  int v1; // eax@1
  int v2; // ebx@1
  int v3; // edx@3
  int result; // eax@6

  v2 = a1;
  v1 = *(_DWORD *)(a1 + 248);
  if ( v1 )
  {
    if ( a1 != v1 )
    {
      sub_805B650(*(_DWORD *)(a1 + 248));
      v3 = *(_DWORD *)(v2 + 248);
      if ( v3 )
        (*(int (__cdecl **)(_DWORD))(*(_DWORD *)v3 + 4))(*(_DWORD *)(v2 + 248));
      *(_DWORD *)(v2 + 248) = 0;
    }
  }
  result = *(_DWORD *)(v2 + 164);
  if ( result >= 0 )
  {
    result = close(*(_DWORD *)(v2 + 164));
    *(_DWORD *)(v2 + 164) = -1;
  }
  return result;
}

//----- (0805B6B0) --------------------------------------------------------
int __cdecl sub_805B6B0(int a1, int a2)
{
  int v2; // edx@1
  int v3; // ecx@1
  int v4; // ebx@1
  __int16 v6; // [sp+24h] [bp-34h]@1
  __int16 v7; // [sp+26h] [bp-32h]@1
  int v8; // [sp+2Ch] [bp-2Ch]@1
  char v9; // [sp+3Ch] [bp-1Ch]@3
  char v10; // [sp+30h] [bp-28h]@3

  sub_8050F20((int)&v6);
  v6 = 4;
  v7 = 5;
  v8 = a2;
  v4 = 0;
  if ( sub_805A590(a1, (int)&v6) == 1 )
  {
    sub_8051340();
    LOBYTE(v4) = (unsigned __int8)sub_8051410((int)&v9, (int)&v10, 0) != 0;
    sub_8051360();
  }
  sub_8052330(v3, v2, (int)&v6);
  return v4;
}

//----- (0805B760) --------------------------------------------------------
int __stdcall sub_805B760(int a1, int a2)
{
  int v1; // eax@1
  int v2; // edx@1
  unsigned int v3; // edi@1
  int v4; // eax@4
  int v5; // edx@4
  int v6; // ebx@4
  unsigned __int8 v7; // si@4
  int v9; // edx@7
  char v10; // [sp+2Bh] [bp-Dh]@1
  char v12; // [sp+1Bh] [bp-1Dh]@4

  std__string__string(a1, &aResNr[13], &v10);
  v3 = 0;
  v1 = *(_DWORD *)a2;
  v2 = *(_DWORD *)a2 - 12;
  if ( *(_DWORD *)(*(_DWORD *)a2 - 12) )
  {
    do
    {
      if ( *(_DWORD *)(v2 + 8) >= 0 )
      {
        std__string___M_leak_hard(a2);
        v1 = *(_DWORD *)a2;
      }
      v7 = *(_BYTE *)(v1 + v3);
      v4 = *(_DWORD *)a1;
      v12 = byte_807FCE0[v3];
      v5 = *(_DWORD *)(v4 - 12);
      v6 = v5 + 1;
      if ( (unsigned int)(v5 + 1) > *(_DWORD *)(v4 - 12 + 4) || *(_DWORD *)(v4 - 12 + 8) > 0 )
      {
        std__string__reserve(a1, v5 + 1);
        v4 = *(_DWORD *)a1;
        v5 = *(_DWORD *)(*(_DWORD *)a1 - 12);
      }
      ++v3;
      *(_BYTE *)(v4 + v5) = v12 ^ v7;
      v9 = *(_DWORD *)a1 - 12;
      *(_DWORD *)(*(_DWORD *)a1 - 12) = v6;
      *(_DWORD *)(v9 + 8) = 0;
      *(_BYTE *)(v9 + v6 + 12) = 0;
      v1 = *(_DWORD *)a2;
      v2 = *(_DWORD *)a2 - 12;
    }
    while ( v3 < *(_DWORD *)(*(_DWORD *)a2 - 12) );
  }
  return a1;
}

//----- (0805B850) --------------------------------------------------------
signed int __cdecl sub_805B850(int a1, int a2)
{
  int v2; // ebx@2
  int v3; // esi@4
  char v4; // zf@5
  int v5; // ecx@5
  int v6; // edi@5
  signed int result; // eax@10
  int v8; // edx@1
  int v9; // eax@1
  int v10; // eax@1
  int v11; // ecx@2
  int v12; // [sp+Ch] [bp-14h]@1
  int v13; // [sp+0h] [bp-20h]@1
  signed int v14; // [sp+4h] [bp-1Ch]@2
  int v15; // [sp+10h] [bp-10h]@2

  v8 = *(_DWORD *)(a1 + 16);
  v9 = *(_DWORD *)(a1 + 20);
  v12 = *(_DWORD *)(a1 + 16);
  v10 = (v9 - v8) >> 3;
  v13 = v10;
  if ( v10 )
  {
    v14 = 0;
    v11 = *(_DWORD *)a2;
    v15 = *(_DWORD *)a2;
    v2 = *(_DWORD *)(v11 - 12);
    while ( 1 )
    {
      v3 = *(_DWORD *)(v12 + 8 * v14 + 4);
      if ( v2 == *(_DWORD *)(v3 - 12) )
      {
        v6 = v15;
        v4 = 1;
        v5 = v2;
        do
        {
          if ( !v5 )
            break;
          v4 = *(_BYTE *)v3++ == *(_BYTE *)v6++;
          --v5;
        }
        while ( v4 );
        if ( v4 )
          break;
      }
      ++v14;
      if ( v14 >= (unsigned int)v13 )
        goto LABEL_11;
    }
    result = v14;
  }
  else
  {
LABEL_11:
    result = -1;
  }
  return result;
}

//----- (0805B8D0) --------------------------------------------------------
signed int __cdecl sub_805B8D0(int a1, int a2)
{
  int v2; // edx@1
  signed int v3; // ebx@2
  int v4; // ecx@4
  int v5; // esi@4
  char v6; // cf@5
  unsigned __int8 v7; // zf@5
  int v8; // edi@5
  signed int result; // eax@10
  int v10; // edi@2
  int v11; // [sp+4h] [bp-1Ch]@2
  int v12; // [sp+10h] [bp-10h]@2
  int v13; // [sp+0h] [bp-20h]@2

  v2 = (*(_DWORD *)(a1 + 8) - *(_DWORD *)(a1 + 4)) >> 7;
  if ( v2 )
  {
    v3 = 0;
    v11 = *(_DWORD *)(a1 + 4);
    v10 = *(_DWORD *)(*(_DWORD *)a2 - 12);
    v12 = *(_DWORD *)a2;
    v13 = v10;
    while ( 1 )
    {
      v4 = v13;
      v5 = *(_DWORD *)v11;
      if ( v13 == *(_DWORD *)(*(_DWORD *)v11 - 12) )
      {
        v8 = v12;
        v6 = v13 < (unsigned int)v13;
        v7 = 1;
        do
        {
          if ( !v4 )
            break;
          v6 = *(_BYTE *)v5 < *(_BYTE *)v8;
          v7 = *(_BYTE *)v5++ == *(_BYTE *)v8++;
          --v4;
        }
        while ( v7 );
        if ( !(v6 | v7) == v6 )
          break;
      }
      ++v3;
      v11 += 128;
      if ( v3 >= (unsigned int)v2 )
        goto LABEL_11;
    }
    result = v3;
  }
  else
  {
LABEL_11:
    result = -1;
  }
  return result;
}

//----- (0805B950) --------------------------------------------------------
char __cdecl sub_805B950(int a1, int a2, __int16 a3, int a4)
{
  int v4; // edx@1
  int v5; // ecx@1
  signed int v6; // ebx@1
  int v8; // ebx@1
  __int16 v9; // di@1
  __int16 v10; // ax@1
  char v11; // [sp+24h] [bp-34h]@1
  char v12; // [sp+28h] [bp-30h]@1
  __int16 v13; // [sp+2Eh] [bp-2Ah]@1
  __int16 v14; // [sp+30h] [bp-28h]@1
  int v15; // [sp+40h] [bp-18h]@1
  __int16 v16; // [sp+2Ch] [bp-2Ch]@1
  int v17; // [sp+44h] [bp-14h]@1
  int v18; // [sp+48h] [bp-10h]@1

  v8 = a2;
  v9 = a3;
  sub_80512C0((int)&v11);
  std__string__assign(&v12, v8 + 4);
  v10 = *(_WORD *)v8;
  v13 = 0;
  v14 = 1;
  v15 = 0;
  v16 = v10;
  v17 = 0;
  v18 = 0;
  sub_8053310((int)&v11, (int)&v15, 0);
  v6 = sub_805A180(a1, 19, v9, a4, (int)&v15);
  if ( v15 )
    operator delete(v5, v4);
  sub_80549C0(v5, v4, (int)&v11);
  return v6 == 1;
}

//----- (0805BA30) --------------------------------------------------------
char __fastcall sub_805BA30(int a1, int a2, int a3, const void **a4, const void **a5)
{
  const void *v4; // edx@1
  int v5; // ebx@1
  const void **v6; // edi@1
  const void **v7; // esi@1
  void *v8; // edx@2
  int v9; // ecx@2
  int v10; // edx@3
  int v11; // ecx@3
  signed int v12; // ebx@3
  const void *v14; // eax@1
  int v15; // eax@1
  int v16; // eax@2
  const void *v17; // eax@3
  __int16 v18; // dx@3
  void *v19; // [sp+1Ch] [bp-1Ch]@1
  int v20; // [sp+20h] [bp-18h]@1
  int v21; // [sp+24h] [bp-14h]@1
  __int16 v22; // [sp+2Ah] [bp-Eh]@3

  v7 = a4;
  v6 = a5;
  v19 = 0;
  v20 = 0;
  v14 = *a4;
  v4 = *a5;
  v21 = 0;
  v15 = *((_DWORD *)v4 - 3) + *((_DWORD *)v14 - 3);
  v5 = v15 + 5;
  if ( v15 == -5 )
  {
    v8 = 0;
    v9 = 0;
  }
  else
  {
    v16 = operator new(a1, v4);
    v8 = (void *)v16;
    v9 = v16;
  }
  v21 = (int)((char *)v8 + v5);
  v19 = v8;
  memset(v8, 0, (size_t)(v8 + v5 - v9));
  v20 = v21;
  *(_BYTE *)v19 = *((_DWORD *)*v7 - 3);
  memcpy((char *)v19 + 1, *v7, *((_DWORD *)*v7 - 3));
  v17 = *v7;
  v18 = __ROR__(*((_DWORD *)*v6 - 3), 8);
  v22 = v18;
  *(_WORD *)(v19 + *((_DWORD *)v17 - 3) + 1) = v10;
  memcpy((char *)v19 + *((_DWORD *)*v7 - 3) + 3, *v6, *((_DWORD *)*v6 - 3));
  *(_WORD *)(v19 + *((_DWORD *)*v6 - 3) + *((_DWORD *)*v7 - 3) + 3) = 0;
  v12 = sub_805A180(a3, 19, 24, 0, (int)&v19);
  if ( v19 )
    operator delete(v11, v10);
  return v12 == 1;
}

//----- (0805BB80) --------------------------------------------------------
char __fastcall sub_805BB80(int a1, int a2, int a3, const void **a4, const void **a5, char a6)
{
  const void *v5; // edx@1
  int v6; // ebx@1
  const void **v7; // edi@1
  const void **v8; // esi@1
  void *v9; // edx@2
  int v10; // ecx@2
  int v11; // edx@3
  int v12; // ecx@3
  signed int v13; // ebx@3
  const void *v15; // eax@1
  int v16; // eax@1
  int v17; // eax@2
  const void *v18; // eax@3
  __int16 v19; // dx@3
  void *v20; // [sp+1Ch] [bp-1Ch]@1
  char v21; // [sp+1Bh] [bp-1Dh]@1
  int v22; // [sp+20h] [bp-18h]@1
  int v23; // [sp+24h] [bp-14h]@1
  __int16 v24; // [sp+2Ah] [bp-Eh]@3

  v8 = a4;
  v7 = a5;
  v20 = 0;
  v21 = a6;
  v15 = *a4;
  v5 = *a5;
  v22 = 0;
  v23 = 0;
  v16 = *((_DWORD *)v5 - 3) + *((_DWORD *)v15 - 3);
  v6 = v16 + 6;
  if ( v16 == -6 )
  {
    v9 = 0;
    v10 = 0;
  }
  else
  {
    v17 = operator new(a1, v5);
    v9 = (void *)v17;
    v10 = v17;
  }
  v23 = (int)((char *)v9 + v6);
  v20 = v9;
  memset(v9, 0, (size_t)(v9 + v6 - v10));
  v22 = v23;
  *(_BYTE *)v20 = *((_DWORD *)*v8 - 3);
  memcpy((char *)v20 + 1, *v8, *((_DWORD *)*v8 - 3));
  *((_BYTE *)v20 + *((_DWORD *)*v8 - 3) + 1) = v21;
  v18 = *v8;
  v19 = __ROR__(*((_DWORD *)*v7 - 3), 8);
  v24 = v19;
  *(_WORD *)(v20 + *((_DWORD *)v18 - 3) + 2) = v11;
  memcpy((char *)v20 + *((_DWORD *)*v8 - 3) + 4, *v7, *((_DWORD *)*v7 - 3));
  *(_WORD *)(v20 + *((_DWORD *)*v7 - 3) + *((_DWORD *)*v8 - 3) + 4) = 0;
  v13 = sub_805A180(a3, 19, 26, 0, (int)&v20);
  if ( v20 )
    operator delete(v12, v11);
  return v13 == 1;
}

//----- (0805BCF0) --------------------------------------------------------
char __fastcall sub_805BCF0(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // esi@1
  void *v5; // edx@2
  int v6; // ecx@2
  unsigned int v7; // ecx@3
  int v8; // ebx@3
  int v9; // edx@5
  int v10; // ecx@5
  signed int v11; // ebx@5
  int v13; // eax@1
  int v14; // eax@2
  int v15; // edx@4
  __int16 v16; // ax@4
  void *v17; // [sp+20h] [bp-18h]@1
  void *v18; // [sp+24h] [bp-14h]@1
  int v19; // [sp+28h] [bp-10h]@1
  __int16 v20; // [sp+2Eh] [bp-Ah]@4

  v4 = a3;
  v17 = 0;
  v18 = 0;
  v19 = 0;
  v13 = *(_DWORD *)(a3 + 192) - *(_DWORD *)(a3 + 188);
  v3 = v13 & 0xFFFFFFFE;
  if ( v13 & 0xFFFFFFFE )
  {
    v14 = operator new(a1, a2);
    v5 = (void *)v14;
    v6 = v14;
  }
  else
  {
    v5 = 0;
    v6 = 0;
  }
  v19 = (int)((char *)v5 + v3);
  v17 = v5;
  v18 = v5;
  memset(v5, 0, (size_t)(v5 + v3 - v6));
  v7 = 0;
  v8 = *(_DWORD *)(v4 + 188);
  v18 = (void *)v19;
  if ( (unsigned int)(*(_DWORD *)(v4 + 192) - v8) >> 1 )
  {
    do
    {
      v15 = 2 * v7;
      v16 = *(_WORD *)(v8 + 2 * v7++);
      v16 = __ROR__(v16, 8);
      v20 = v16;
      *(_WORD *)((char *)v17 + v15) = v16;
      v8 = *(_DWORD *)(v4 + 188);
    }
    while ( v7 < (*(_DWORD *)(v4 + 192) - v8) >> 1 );
  }
  v11 = sub_805A180(v4, 1, 8, 0, (int)&v17);
  if ( v17 )
    operator delete(v10, v9);
  return v11 == 1;
}

//----- (0805BF30) --------------------------------------------------------
signed int __cdecl sub_805BF30(int a1)
{
  int v1; // edx@1
  int v2; // ecx@1
  int v3; // ebx@1
  signed int v4; // ebx@2
  signed int v6; // eax@7
  __int16 v7; // [sp+20h] [bp-28h]@1
  signed int v8; // [sp+24h] [bp-24h]@1
  __int16 v9; // [sp+28h] [bp-20h]@1
  __int16 v10; // [sp+2Ah] [bp-1Eh]@1
  __int16 v11; // [sp+2Ch] [bp-1Ch]@1
  __int16 v12; // [sp+2Eh] [bp-1Ah]@1
  int v13; // [sp+30h] [bp-18h]@1
  int v14; // [sp+34h] [bp-14h]@1
  int v15; // [sp+38h] [bp-10h]@1

  v3 = a1;
  sub_8051340();
  v7 = 1;
  v8 = 11;
  v9 = 8000;
  v10 = 999;
  v11 = 999;
  v12 = 0;
  v13 = 0;
  v14 = 0;
  v15 = 0;
  sub_80526F0((int)&v7, (int)&v13, 0);
  if ( sub_805A180(v3, 4, 2, 0, (int)&v13) != 1
    || (v7 = 2, v8 = 3, v9 = 8000, v14 = v13, v10 = 999, v11 = 999, v12 = 0, sub_80526F0((int)&v7, (int)&v13, 0), sub_805A180(v3, 4, 2, 0, (int)&v13) != 1)
    || (v7 = 4, v8 = 3, v9 = 8000, v14 = v13, v10 = 999, v11 = 999, v12 = 0, sub_80526F0((int)&v7, (int)&v13, 0), v6 = sub_805A180(v3, 4, 2, 0, (int)&v13), v4 = 1, v6 != 1) )
    v4 = 0;
  if ( v13 )
    operator delete(v2, v1);
  sub_8051360();
  return v4;
}

//----- (0805C0F0) --------------------------------------------------------
int __cdecl sub_805C0F0(int a1, const char **a2, int a3)
{
  int v3; // ecx@1
  const char *v4; // ebx@1
  int v5; // edi@1
  int result; // eax@3
  int v7; // edx@3
  int v8; // ecx@3
  signed int v9; // ebx@3
  char v10; // zf@7
  const char *v11; // esi@7
  int v12; // ebx@13
  int v13; // edx@14
  int v14; // ecx@14
  const char **v15; // ebx@1
  const char *v16; // eax@1
  __int32 v17; // eax@1
  char v18; // zf@1
  __int32 v19; // eax@3
  int v20; // eax@3
  int v21; // ebx@3
  int v22; // ecx@13
  int v23; // edx@13
  char v24; // [sp+44h] [bp-24h]@1
  char v25; // [sp+45h] [bp-23h]@1
  int v26; // [sp+28h] [bp-40h]@1
  char v27; // [sp+46h] [bp-22h]@1
  char v28; // [sp+47h] [bp-21h]@1
  char v29; // [sp+48h] [bp-20h]@1
  char v30; // [sp+49h] [bp-1Fh]@1
  signed int v31; // [sp+4Ah] [bp-1Eh]@1
  char v32; // [sp+4Eh] [bp-1Ah]@1
  char v33; // [sp+4Fh] [bp-19h]@1
  char v34; // [sp+50h] [bp-18h]@1
  char v35; // [sp+51h] [bp-17h]@1
  char v36; // [sp+52h] [bp-16h]@1
  char v37; // [sp+53h] [bp-15h]@1
  signed int v38; // [sp+54h] [bp-14h]@1
  int v39; // [sp+58h] [bp-10h]@1
  int v40; // [sp+24h] [bp-44h]@1
  __int32 v41; // [sp+40h] [bp-28h]@1
  const char *v42; // [sp+20h] [bp-48h]@1
  __int32 v43; // [sp+3Ch] [bp-2Ch]@3
  int v44; // [sp+30h] [bp-38h]@3
  int v45; // [sp+38h] [bp-30h]@3
  int v46; // [sp+34h] [bp-34h]@3

  v24 = 0;
  v15 = a2;
  v25 = 1;
  v26 = a1;
  v27 = 0;
  v28 = 16;
  v29 = 14;
  v30 = 0;
  v31 = -1;
  v32 = -48;
  v33 = 7;
  v34 = 1;
  v35 = 0;
  v36 = -1;
  v37 = -1;
  v38 = -1;
  v16 = *(const char **)(a1 + 124);
  v39 = *MK_FP(__GS__, 20);
  v40 = a3;
  v17 = strtol(v16, 0, 10);
  v31 = v17;
  v4 = *v15;
  v5 = *(_DWORD *)(v26 + 124);
  v41 = v17;
  v3 = *((_DWORD *)v4 - 3);
  v18 = v3 == *(_DWORD *)(v5 - 12);
  v42 = v4;
  if ( !v18 )
    goto LABEL_18;
  v10 = 1;
  v11 = v4;
  do
  {
    if ( !v3 )
      break;
    v10 = *v11++ == *(_BYTE *)v5++;
    --v3;
  }
  while ( v10 );
  if ( v10 )
  {
    v36 = -78;
    v37 = 4;
  }
  else
  {
LABEL_18:
    v36 = -48;
    v37 = 4;
  }
  v19 = strtol(v42, 0, 10);
  v43 = v19;
  v38 = v19;
  v20 = operator new(v8, v7);
  v21 = v20 + 20;
  v44 = v20;
  v45 = v20 + 20;
  memmove((void *)v20, &v24, 0x14u);
  v46 = v21;
  v9 = sub_805A180(v26, 21, 2, v40, (int)&v44);
  result = v44;
  if ( v44 )
    result = operator delete(v8, v7);
  LOBYTE(result) = v9 == 1;
  if ( *MK_FP(__GS__, 20) ^ v39 )
  {
    v12 = __stack_chk_fail();
    sub_8056490(v22, v23, (int)&v44);
    while ( 1 )
    {
      do
        v12 = _Unwind_Resume(v12);
      while ( !v44 );
      operator delete(v14, v13);
    }
  }
  return result;
}

//----- (0805C2B0) --------------------------------------------------------
int *__fastcall sub_805C2B0(int a1, int a2, int a3, const char **a4, int a5)
{
  int v4; // edx@1
  int v5; // ecx@1
  int *v6; // ebx@1
  int *result; // eax@3
  int v8; // edx@5
  int v9; // ecx@5
  const char **v10; // esi@1
  int v11; // eax@1
  int v12; // ebx@1
  __int32 v13; // eax@1
  __int32 v14; // eax@1
  int v15; // edx@1
  int v16; // ecx@1
  char v17; // [sp+58h] [bp-20h]@1
  int v18; // [sp+28h] [bp-50h]@1
  int v19; // [sp+24h] [bp-54h]@1
  int v20; // [sp+68h] [bp-10h]@1
  char v21; // [sp+59h] [bp-1Fh]@1
  char v22; // [sp+5Ah] [bp-1Eh]@1
  char v23; // [sp+5Bh] [bp-1Dh]@1
  char v24; // [sp+5Ch] [bp-1Ch]@1
  char v25; // [sp+5Dh] [bp-1Bh]@1
  char v26; // [sp+5Eh] [bp-1Ah]@1
  char v27; // [sp+5Fh] [bp-19h]@1
  char v28; // [sp+60h] [bp-18h]@1
  char v29; // [sp+61h] [bp-17h]@1
  char v30; // [sp+62h] [bp-16h]@1
  char v31; // [sp+63h] [bp-15h]@1
  char v32; // [sp+64h] [bp-14h]@1
  char v33; // [sp+65h] [bp-13h]@1
  char v34; // [sp+66h] [bp-12h]@1
  char v35; // [sp+67h] [bp-11h]@1
  int v36; // [sp+4Ch] [bp-2Ch]@1
  int v37; // [sp+44h] [bp-34h]@1
  int v38; // [sp+48h] [bp-30h]@1
  int v39; // [sp+38h] [bp-40h]@1
  __int32 v40; // [sp+54h] [bp-24h]@1
  __int32 v41; // [sp+50h] [bp-28h]@1
  int v42; // [sp+3Ch] [bp-3Ch]@1
  int v43; // [sp+40h] [bp-38h]@1
  __int16 v44; // [sp+34h] [bp-44h]@1
  int v45; // [sp+20h] [bp-58h]@5

  v10 = a4;
  v17 = 14;
  v18 = a3;
  v19 = a5;
  v20 = *MK_FP(__GS__, 20);
  v21 = 0;
  v22 = -1;
  v23 = -1;
  v24 = -1;
  v25 = -1;
  v26 = -48;
  v27 = 7;
  v28 = -1;
  v29 = -1;
  v30 = -70;
  v31 = 4;
  v32 = -1;
  v33 = -1;
  v34 = -1;
  v35 = -1;
  v11 = operator new(a1, a5);
  v12 = v11 + 16;
  v36 = v11 + 16;
  v37 = v11;
  memmove((void *)v11, &v17, 0x10u);
  v38 = v12;
  v6 = &v39;
  v13 = strtol(*(const char **)(v18 + 124), 0, 10);
  v40 = v13;
  *(_DWORD *)(v37 + 2) = v13;
  v14 = strtol(*v10, 0, 10);
  v41 = v14;
  *(_DWORD *)(v37 + 12) = v14;
  v15 = *(_WORD *)(v18 + 168);
  *(_WORD *)(v37 + 8) = *(_WORD *)(v18 + 168);
  v39 = 0;
  v42 = 0;
  v43 = 0;
  sub_804B500(v16, v15, (int)&v39, (int)&v37);
  v44 = 1;
  v38 = v37;
  sub_80528B0((int)&v44, (int)&v37, 0);
  LOBYTE(v6) = sub_805A180(v18, 21, 2, v19, (int)&v37) == 1;
  sub_8052370(v5, v4, (int)&v44);
  if ( v37 )
    operator delete(v5, v4);
  result = v6;
  if ( *MK_FP(__GS__, 20) ^ v20 )
  {
    v45 = __stack_chk_fail();
    while ( 1 )
    {
      sub_8056490(v9, v8, (int)&v37);
      v45 = _Unwind_Resume(v45);
      sub_8052370(v9, v8, (int)&v44);
    }
  }
  return result;
}

//----- (0805C4B0) --------------------------------------------------------
int *__cdecl sub_805C4B0(int a1)
{
  int v1; // ecx@1
  signed int v2; // ebx@1
  size_t v3; // edx@4
  int v4; // eax@6
  int v5; // edx@6
  int v6; // edx@8
  int v7; // ecx@8
  int *v8; // ebx@8
  int *result; // eax@10
  int v10; // edi@10
  int v11; // edx@14
  int v12; // ecx@14
  int v13; // edx@15
  int v14; // ecx@15
  int v15; // ebx@15
  int v16; // eax@1
  int v17; // ebx@1
  int v18; // [sp+A8h] [bp-10h]@1
  char v19; // [sp+48h] [bp-70h]@1
  char *v20; // [sp+20h] [bp-98h]@1
  int v21; // [sp+28h] [bp-90h]@1
  int v22; // [sp+44h] [bp-74h]@1
  int v23; // [sp+3Ch] [bp-7Ch]@1
  int v24; // [sp+40h] [bp-78h]@1
  int v25; // [sp+30h] [bp-88h]@8
  int v26; // [sp+34h] [bp-84h]@8
  int v27; // [sp+38h] [bp-80h]@8
  __int16 v28; // [sp+2Ch] [bp-8Ch]@8
  int v29; // [sp+24h] [bp-94h]@14

  v18 = *MK_FP(__GS__, 20);
  v20 = &v19;
  v21 = a1;
  memcpy(&v19, &unk_807FD00, 0x60u);
  v16 = operator new(0, 0);
  v17 = v16 + 96;
  v22 = v16 + 96;
  v23 = v16;
  memmove((void *)v16, &v19, 0x60u);
  v24 = v17;
  v1 = *(_DWORD *)(v21 + 96);
  v2 = *(_DWORD *)(v1 - 12);
  if ( v2 <= 0 )
  {
    *(_DWORD *)(v23 + 88) = 1852534357;
    *(_DWORD *)(v23 + 92) = 560887663;
  }
  else
  {
    if ( *(_DWORD *)(v1 - 12 + 8) >= 0 )
    {
      std__string___M_leak_hard(v21 + 96);
      v1 = *(_DWORD *)(v21 + 96);
    }
    v3 = v2;
    if ( v2 > 8 )
      v3 = 8;
    memcpy((void *)(v23 + 88), (const void *)v1, v3);
  }
  v4 = *(_DWORD *)(v21 + 108);
  v5 = v4 - 1;
  if ( (unsigned int)(v4 - 1) <= 0x21 )
    sub_8078840(&v23, v24, &stru_807FAC0[4 * v5], &stru_807FAC0[4 * v4]);
  v8 = &v25;
  v25 = 0;
  v26 = 0;
  v27 = 0;
  sub_804B500(v1, v5, (int)&v25, (int)&v23);
  v28 = 5;
  v24 = v23;
  sub_80528B0((int)&v28, (int)&v23, 0);
  LOBYTE(v8) = sub_805A180(v21, 2, 4, 0, (int)&v23) == 1;
  sub_8052370(v7, v6, (int)&v28);
  if ( v23 )
    operator delete(v7, v6);
  v10 = *MK_FP(__GS__, 20) ^ v18;
  result = v8;
  if ( *MK_FP(__GS__, 20) ^ v18 )
  {
    v29 = __stack_chk_fail();
    while ( 1 )
    {
      sub_8056490(v12, v11, v10);
      v15 = _Unwind_Resume(v29);
      if ( v23 )
        operator delete(v14, v13);
      v29 = _Unwind_Resume(v15);
      sub_8052370(v12, v11, (int)&v28);
    }
  }
  return result;
}

//----- (0805C700) --------------------------------------------------------
int *__cdecl sub_805C700(int a1, int a2, int a3, int a4)
{
  int v5; // ebx@1
  int v6; // esi@1

  v5 = a1;
  v6 = a4;
  *(_DWORD *)(a1 + 108) = a2;
  std__string__assign(a1 + 112, a3);
  std__string__assign(v5 + 116, v6);
  a1 = v5;
  return sub_805C4B0(a1);
}

//----- (0805C750) --------------------------------------------------------
int *__fastcall sub_805C750(int a1, int a2, int a3, unsigned __int8 a4, int a5)
{
  int v4; // edx@1
  int v5; // ecx@1
  int *v6; // ebx@1
  int *result; // eax@3
  int v8; // edx@5
  int v9; // ecx@5
  int v10; // edi@5
  int v11; // edi@1
  int v12; // esi@1
  int v13; // eax@1
  int v14; // ebx@1
  const char *v15; // eax@1
  __int32 v16; // eax@1
  int v17; // ecx@1
  int v18; // [sp+48h] [bp-10h]@1
  int v19; // [sp+18h] [bp-40h]@1
  char v20; // [sp+3Eh] [bp-1Ah]@1
  char v21; // [sp+3Fh] [bp-19h]@1
  char v22; // [sp+40h] [bp-18h]@1
  char v23; // [sp+41h] [bp-17h]@1
  char v24; // [sp+42h] [bp-16h]@1
  char v25; // [sp+43h] [bp-15h]@1
  char v26; // [sp+44h] [bp-14h]@1
  char v27; // [sp+45h] [bp-13h]@1
  char v28; // [sp+46h] [bp-12h]@1
  char v29; // [sp+47h] [bp-11h]@1
  int v30; // [sp+30h] [bp-28h]@1
  int v31; // [sp+34h] [bp-24h]@1
  int v32; // [sp+2Ch] [bp-2Ch]@1
  int v33; // [sp+20h] [bp-38h]@1
  __int32 v34; // [sp+38h] [bp-20h]@1
  int v35; // [sp+24h] [bp-34h]@1
  int v36; // [sp+28h] [bp-30h]@1
  __int16 v37; // [sp+1Ch] [bp-3Ch]@1

  v11 = a3;
  v12 = a4;
  v18 = *MK_FP(__GS__, 20);
  v19 = a5;
  v20 = 8;
  v21 = 0;
  v22 = -1;
  v23 = -1;
  v24 = -1;
  v25 = -1;
  v26 = -1;
  v27 = 0;
  v28 = -1;
  v29 = -1;
  v30 = 0;
  v13 = operator new(a1, 0);
  v14 = v13 + 10;
  v31 = v13 + 10;
  v32 = v13;
  memmove((void *)v13, &v20, 0xAu);
  v15 = *(const char **)(v11 + 124);
  v30 = v14;
  v6 = &v33;
  v16 = strtol(v15, 0, 10);
  v34 = v16;
  *(_DWORD *)(v32 + 2) = v16;
  *(_WORD *)(v32 + 8) = *(_WORD *)(v11 + 168);
  *(_BYTE *)(v32 + 6) = v12;
  v33 = 0;
  v35 = 0;
  v36 = 0;
  sub_804B500(v17, v12, (int)&v33, (int)&v32);
  v37 = 1;
  v30 = v32;
  sub_80528B0((int)&v37, (int)&v32, 0);
  LOBYTE(v6) = sub_805A180(v11, 21, 2, v19, (int)&v32) == 1;
  sub_8052370(v5, v4, (int)&v37);
  if ( v32 )
    operator delete(v5, v4);
  result = v6;
  if ( *MK_FP(__GS__, 20) ^ v18 )
  {
    v10 = __stack_chk_fail();
    while ( 1 )
    {
      sub_8056490(v9, v8, (int)&v32);
      v10 = _Unwind_Resume(v10);
      sub_8052370(v9, v8, (int)&v37);
    }
  }
  return result;
}

//----- (0805C910) --------------------------------------------------------
char __fastcall sub_805C910(int a1, int a2, int a3)
{
  return (unsigned __int8)sub_805C750(a1, a3, a3, 0x3Cu, a3 + 160) != 0;
}

//----- (0805C940) --------------------------------------------------------
signed int __cdecl sub_805C940(int a1, int a2)
{
  int v2; // edx@1
  int v3; // ecx@1
  int v4; // esi@1
  int v5; // edi@2
  int v6; // ebx@3
  int v7; // esi@6
  int v8; // eax@8
  int v9; // esi@14
  signed int v10; // ebx@16
  unsigned __int16 v12; // ax@3
  unsigned __int16 v13; // ax@13
  __int16 v14; // [sp+1Ch] [bp-2Ch]@1
  __int16 v15; // [sp+1Eh] [bp-2Ah]@1
  int v16; // [sp+24h] [bp-24h]@1
  int v17; // [sp+28h] [bp-20h]@2
  int v18; // [sp+2Ch] [bp-1Ch]@2
  int v19; // [sp+14h] [bp-34h]@2
  unsigned __int16 v20; // [sp+3Ah] [bp-Eh]@3
  int v21; // [sp+18h] [bp-30h]@6
  __int16 v22; // [sp+38h] [bp-10h]@13
  unsigned __int16 v23; // [sp+36h] [bp-12h]@13

  sub_8050F20((int)&v14);
  v4 = a1;
  v14 = 1;
  v15 = 7;
  v16 = a2;
  if ( sub_805A590(a1, (int)&v14) == 1 )
  {
    v5 = v17;
    v2 = v18 - v17;
    v19 = v18;
    if ( (unsigned int)(v18 - v17) > 1 )
    {
      v12 = __ROR__(*(_WORD *)v17, 8);
      v20 = v12;
      v3 = 35 * v12;
      v6 = v3 + 2;
      if ( v3 + 2 <= (unsigned int)v2 )
      {
        *(_DWORD *)(v4 + 192) = *(_DWORD *)(v4 + 188);
        if ( v3 + 2 == v2 )
        {
LABEL_18:
          v10 = 1;
          goto LABEL_17;
        }
        if ( v2 >= (unsigned int)(v3 + 6) )
        {
          v21 = v4 + 188;
          v7 = v3 + 6;
          do
          {
            v2 = *(_WORD *)(v5 + v6);
            LOWORD(v2) = __ROR__(v2, 8);
            v22 = v2;
            v3 = v19 - v5;
            v13 = __ROR__(*(_WORD *)(v17 + v6 + 2), 8);
            v23 = v13;
            v6 = v7 + 4 * v13;
            if ( v6 > (unsigned int)(v19 - v5) )
              break;
            v9 = a1;
            v8 = *(_DWORD *)(a1 + 192);
            if ( v8 != *(_DWORD *)(a1 + 196) )
            {
              if ( v8 )
              {
                *(_WORD *)v8 = v2;
                v5 = v17;
                v19 = v18;
                v8 = *(_DWORD *)(v9 + 192);
                v3 = v18 - v17;
              }
              v2 = a1;
              *(_DWORD *)(a1 + 192) = v8 + 2;
            }
            else
            {
              sub_8078EE0(v21, *(const void **)(a1 + 192), (int)&v22);
              v2 = v18;
              v5 = v17;
              v19 = v18;
              v3 = v18 - v17;
            }
            if ( v6 > (unsigned int)v3 )
              break;
            if ( v6 == v3 )
              goto LABEL_18;
            v7 = v6 + 4;
          }
          while ( v6 + 4 <= (unsigned int)v3 );
        }
      }
    }
  }
  v10 = 0;
LABEL_17:
  sub_8052330(v3, v2, (int)&v14);
  return v10;
}

//----- (0805CAB0) --------------------------------------------------------
signed int __cdecl sub_805CAB0(int a1, int a2, int a3, int a4, int a5)
{
  int v5; // edx@1
  int *v6; // ecx@1
  int v7; // esi@1
  int v8; // ebx@2
  signed int result; // eax@3
  int v10; // ecx@6
  int v11; // ecx@11
  int v12; // edx@12
  int v13; // ecx@15
  unsigned int v14; // ebx@35
  int v15; // ebx@37
  int v16; // ebx@42
  int v17; // ebx@43
  int v18; // ebx@45
  int v19; // eax@46
  int v20; // ebx@6
  unsigned __int16 v21; // ax@7
  int v22; // eax@8
  int v23; // ebx@22
  time_t v24; // eax@22
  unsigned __int16 v25; // dx@22
  unsigned __int16 v26; // ax@27
  char v28; // al@36
  int v29; // edx@46
  signed int v30; // eax@46
  char v31; // al@48
  int v33; // [sp+1Ch] [bp-7Ch]@1
  int v34; // [sp+20h] [bp-78h]@1
  int v35; // [sp+24h] [bp-74h]@1
  int v36; // [sp+88h] [bp-10h]@1
  int v37; // [sp+18h] [bp-80h]@1
  int v38; // [sp+38h] [bp-60h]@6
  unsigned __int16 v39; // [sp+76h] [bp-22h]@7
  int v40; // [sp+70h] [bp-28h]@7
  int v41; // [sp+6Ch] [bp-2Ch]@7
  int v42; // [sp+68h] [bp-30h]@7
  char v43; // [sp+64h] [bp-34h]@7
  signed int v44; // [sp+28h] [bp-70h]@7
  signed int v45; // [sp+2Ch] [bp-6Ch]@10
  signed int v46; // [sp+34h] [bp-64h]@10
  unsigned int v47; // [sp+14h] [bp-84h]@10
  __int16 v48; // [sp+48h] [bp-50h]@11
  int v49; // [sp+4Ch] [bp-4Ch]@12
  int v50; // [sp+50h] [bp-48h]@12
  int v51; // [sp+30h] [bp-68h]@12
  __int16 v52; // [sp+74h] [bp-24h]@27
  char v53; // [sp+78h] [bp-20h]@34
  char v54; // [sp+79h] [bp-1Fh]@34
  char v55; // [sp+7Ah] [bp-1Eh]@34
  char v56; // [sp+7Bh] [bp-1Dh]@34
  char v57; // [sp+7Ch] [bp-1Ch]@34
  char v58; // [sp+7Dh] [bp-1Bh]@34
  char v59; // [sp+7Eh] [bp-1Ah]@34
  char v60; // [sp+7Fh] [bp-19h]@34
  char v61; // [sp+80h] [bp-18h]@34
  char v62; // [sp+81h] [bp-17h]@34
  char v63; // [sp+82h] [bp-16h]@34
  char v64; // [sp+83h] [bp-15h]@34
  char v65; // [sp+84h] [bp-14h]@34
  char v66; // [sp+85h] [bp-13h]@34
  char v67; // [sp+86h] [bp-12h]@34
  char v68; // [sp+87h] [bp-11h]@34
  int v69; // [sp+58h] [bp-40h]@34
  int v70; // [sp+5Ch] [bp-3Ch]@34
  int v71; // [sp+60h] [bp-38h]@34
  char v72; // [sp+10h] [bp-88h]@36

  v33 = a4;
  v7 = a2;
  v34 = a3;
  v5 = *(_DWORD *)(a4 + 4);
  v6 = *(int **)a4;
  v35 = a1;
  v36 = *MK_FP(__GS__, 20);
  v37 = a5;
  if ( v5 != (_DWORD)v6 )
  {
    v8 = *(_BYTE *)v6;
    if ( v8 + 1 <= (unsigned int)(v5 - (_DWORD)v6) )
    {
      std__string__assign(a2, (char *)v6 + 1, *(_BYTE *)v6);
      v10 = v8 + 3;
      v20 = v8 + 5;
      v38 = v20;
      if ( v20 <= (unsigned int)(*(_DWORD *)(v33 + 4) - *(_DWORD *)v33) )
      {
        v21 = __ROR__(*(_WORD *)(*(_DWORD *)v33 + v10), 8);
        v39 = v21;
        *(_DWORD *)v34 = 0;
        v40 = 0;
        v41 = 0;
        v42 = 0;
        std__string__string(&v43, v7);
        v44 = sub_805B8D0(v35, (int)&v43);
        std__string___string(&v43);
        if ( v44 >= 0 )
        {
          v22 = *(_DWORD *)(v35 + 4);
          *(_BYTE *)(v22 + (v44 << 7) + 32) = 0;
          *(_BYTE *)(v22 + (v44 << 7) + 93) = 0;
          *(_BYTE *)(v22 + (v44 << 7) + 94) = 0;
          *(_DWORD *)(v22 + (v44 << 7) + 124) = 0;
        }
        if ( !v39 )
          goto LABEL_52;
        v45 = 0;
        v46 = v44 << 7;
        v47 = (unsigned int)~v44 >> 31;
        goto LABEL_11;
      }
    }
  }
  result = 0;
LABEL_4:
  while ( *MK_FP(__GS__, 20) ^ v36 )
  {
    __stack_chk_fail();
LABEL_66:
    if ( sub_80785A0(*(_DWORD *)(v35 + 4) + v46 + 88, (int)&aResNr[13]) )
    {
      v19 = *(_DWORD *)(v35 + 4) + v46;
      goto LABEL_47;
    }
    while ( 1 )
    {
      sub_8052370((int)&v48, v12, (int)&v48);
      ++v45;
      if ( v39 <= v45 )
        break;
      v38 += v51 + 4;
LABEL_11:
      sub_8050F60((int)&v48);
      if ( !(unsigned __int8)sub_80516C0((int)&v48, v33, v38) )
      {
LABEL_32:
        sub_8052370(v11, (int)&v48, (int)&v48);
        result = 0;
        goto LABEL_4;
      }
      v12 = v49;
      v11 = v50 - v49;
      v51 = v50 - v49;
      switch ( v48 )
      {
        case 6:
          if ( !(unsigned __int8)sub_8051660((int)&v48, v34) )
            goto LABEL_32;
          break;
        case 0xC:
          if ( (unsigned int)v51 <= 0xA )
            goto LABEL_32;
          v40 = *(_DWORD *)v49;
          if ( v44 >= 0 )
          {
            v26 = *(_WORD *)(v49 + 9);
            v12 = *(_DWORD *)(v35 + 4);
            v52 = *(_WORD *)(v49 + 9);
            v26 = __ROR__(v26, 8);
            *(_DWORD *)(v12 + v46 + 124) = v26;
          }
          __asm { bswap   eax }
          v41 = _EAX;
          break;
        case 0xA:
          if ( (unsigned int)v51 <= 3 )
            goto LABEL_32;
          v42 = *(_DWORD *)v49;
          break;
        default:
          v13 = (unsigned __int8)v47;
          if ( v48 == 25 )
          {
            if ( (_BYTE)v13 )
            {
              v53 = 9;
              v54 = 70;
              v55 = -1;
              v56 = -1;
              v57 = 76;
              v58 = 127;
              v59 = 17;
              v60 = -47;
              v61 = -126;
              v62 = 34;
              v63 = 68;
              v64 = 69;
              v65 = 83;
              v66 = 84;
              v67 = 0;
              v68 = 0;
              v69 = 0;
              v70 = 0;
              v71 = 0;
              if ( v49 != v50 )
              {
                v14 = 0;
                do
                {
                  v55 = *(_BYTE *)(v12 + v14);
                  v28 = *(_BYTE *)(v12 + v14 + 1);
                  v72 = 0;
                  v56 = v28;
                  sub_8078660(&v69, v70, &v53, &v36);
                  v12 = v49;
                  v14 += 2;
                }
                while ( v14 < v50 - v49 );
              }
              v12 = v35;
              v15 = *(_DWORD *)(v35 + 4) + v46;
              if ( !*(_BYTE *)(v15 + 93) )
              {
                v31 = sub_80583F0(v35, &v69);
                v13 = v35;
                *(_BYTE *)(v15 + 93) = v31;
                v15 = *(_DWORD *)(v13 + 4) + v46;
              }
              if ( !*(_BYTE *)(v15 + 94) )
                *(_BYTE *)(v15 + 94) = sub_8058330(v35, &v69);
              if ( v69 )
                operator delete(v13, v12);
            }
          }
          else
          {
            if ( (_BYTE)v13 )
            {
              if ( v48 == 13 )
              {
                v16 = *(_DWORD *)(v35 + 4) + v46;
                if ( !*(_BYTE *)(v16 + 93) )
                  *(_BYTE *)(v16 + 93) = sub_80583F0(v35, &v49);
                v17 = *(_DWORD *)(v35 + 4) + v46;
                if ( !*(_BYTE *)(v17 + 94) )
                  *(_BYTE *)(v17 + 94) = sub_8058330(v35, &v49);
                v18 = v37;
                if ( !(unsigned __int8)sub_8058290(v35, (int)&v49, v37) )
                {
                  v29 = v35;
                  v30 = v46;
                  *(_DWORD *)v18 = 0;
                  v19 = *(_DWORD *)(v29 + 4) + v30;
                  if ( *(_DWORD *)(v19 + 80) )
                  {
LABEL_47:
                    std__string__assign(v19 + 84, &aResNr[13]);
                    std__string__assign(*(_DWORD *)(v35 + 4) + v46 + 88, &aResNr[13]);
                    continue;
                  }
                  if ( sub_80785A0(v19 + 84, (int)&aResNr[13]) )
                  {
                    v19 = *(_DWORD *)(v35 + 4) + v46;
                    goto LABEL_47;
                  }
                  goto LABEL_66;
                }
              }
              else
              {
                if ( v48 != 3 || (unsigned int)v51 <= 3 )
                {
                  if ( (_BYTE)v13 )
                  {
                    if ( v48 == 4 )
                    {
                      if ( (unsigned int)v51 > 1 )
                      {
                        v23 = *(_DWORD *)(v35 + 4);
                        v24 = time(0);
                        v25 = __ROR__(*(_WORD *)v49, 8);
                        v12 = v24 + -60 * v25;
                        *(_DWORD *)(v23 + v46 + 120) = v12;
                      }
                    }
                  }
                }
                else
                {
                  __asm { bswap   eax }
                  v12 = *(_DWORD *)(v35 + 4);
                  *(_DWORD *)(v12 + v46 + 116) = _EAX;
                }
              }
            }
          }
          break;
      }
    }
    if ( !v40 && !v41 && !v42 )
      goto LABEL_70;
    if ( v44 < 0 )
      goto LABEL_70;
LABEL_52:
    if ( v40 )
      *(_DWORD *)((v44 << 7) + *(_DWORD *)(v35 + 4) + 20) = v40;
    if ( v41 )
      *(_DWORD *)((v44 << 7) + *(_DWORD *)(v35 + 4) + 24) = v41;
    if ( v42 )
    {
      v44 <<= 7;
      *(_DWORD *)(*(_DWORD *)(v35 + 4) + v44 + 28) = v42;
      result = 1;
    }
    else
    {
LABEL_70:
      result = 1;
    }
  }
  return result;
}

//----- (0805D2C0) --------------------------------------------------------
char __cdecl sub_805D2C0(int a1)
{
  int v1; // edx@1
  int v2; // ecx@1
  int v3; // ebx@1
  int v4; // edi@1
  unsigned int v5; // eax@2
  __int16 v6; // si@2
  unsigned int v7; // eax@7
  int v8; // ecx@11
  unsigned int v9; // eax@12
  int v10; // ecx@16
  unsigned int v11; // eax@17
  int v12; // ecx@21
  unsigned int v13; // eax@22
  int v14; // ecx@26
  unsigned int v15; // eax@27
  int v16; // ecx@31
  unsigned int v17; // eax@32
  int v18; // edx@36
  int v19; // ecx@36
  unsigned int v20; // eax@37
  int v21; // edx@41
  int v22; // ecx@41
  signed int v23; // ebx@41
  int v25; // eax@45
  int v26; // eax@49
  int v27; // eax@53
  int v28; // eax@57
  int v29; // eax@63
  int v30; // eax@67
  int v31; // eax@71
  int v32; // eax@75
  int v33; // eax@81
  int v34; // eax@85
  int v35; // eax@89
  int v36; // eax@93
  int v37; // eax@99
  int v38; // eax@103
  int v39; // eax@107
  int v40; // eax@111
  int v41; // eax@117
  int v42; // eax@121
  int v43; // eax@125
  int v44; // eax@129
  int v45; // eax@135
  int v46; // eax@139
  int v47; // eax@143
  int v48; // eax@147
  int v49; // eax@153
  int v50; // eax@157
  int v51; // eax@161
  int v52; // eax@165
  int v53; // eax@171
  int v54; // eax@175
  int v55; // eax@179
  int v56; // eax@183
  int v57; // [sp+20h] [bp-38h]@1
  int v58; // [sp+24h] [bp-34h]@1
  int v59; // [sp+28h] [bp-30h]@1
  int v60; // [sp+18h] [bp-40h]@1
  char v61; // [sp+33h] [bp-25h]@44
  char v62; // [sp+32h] [bp-26h]@48
  char v63; // [sp+31h] [bp-27h]@52
  char v64; // [sp+30h] [bp-28h]@56
  char v65; // [sp+43h] [bp-15h]@62
  char v66; // [sp+42h] [bp-16h]@66
  char v67; // [sp+41h] [bp-17h]@70
  char v68; // [sp+40h] [bp-18h]@74
  char v69; // [sp+47h] [bp-11h]@80
  char v70; // [sp+46h] [bp-12h]@84
  char v71; // [sp+45h] [bp-13h]@88
  char v72; // [sp+44h] [bp-14h]@92
  char v73; // [sp+4Bh] [bp-Dh]@98
  char v74; // [sp+4Ah] [bp-Eh]@102
  char v75; // [sp+49h] [bp-Fh]@106
  char v76; // [sp+48h] [bp-10h]@110
  char v77; // [sp+3Bh] [bp-1Dh]@116
  char v78; // [sp+3Ah] [bp-1Eh]@120
  char v79; // [sp+39h] [bp-1Fh]@124
  char v80; // [sp+38h] [bp-20h]@128
  char v81; // [sp+3Fh] [bp-19h]@134
  char v82; // [sp+3Eh] [bp-1Ah]@138
  char v83; // [sp+3Dh] [bp-1Bh]@142
  char v84; // [sp+3Ch] [bp-1Ch]@146
  char v85; // [sp+37h] [bp-21h]@152
  char v86; // [sp+36h] [bp-22h]@156
  char v87; // [sp+35h] [bp-23h]@160
  char v88; // [sp+34h] [bp-24h]@164
  char v89; // [sp+2Fh] [bp-29h]@170
  char v90; // [sp+2Eh] [bp-2Ah]@174
  char v91; // [sp+2Dh] [bp-2Bh]@178
  char v92; // [sp+2Ch] [bp-2Ch]@182

  v57 = 0;
  v58 = 0;
  v59 = 0;
  v4 = *(_DWORD *)(a1 + 180);
  v1 = *(_DWORD *)(a1 + 176);
  v60 = (int)&v57;
  v2 = (v4 - v1) >> 2;
  v3 = (v4 - v1) >> 2;
  if ( v2 )
  {
    v6 = *(_WORD *)v1;
    v5 = 0;
    if ( *(_WORD *)v1 == 1 )
    {
LABEL_98:
      v73 = 0;
      if ( v58 == v59 )
      {
        v60 = (int)&v57;
        sub_8078230((int)&v57, (const void *)v58, (int)&v73);
      }
      else
      {
        v37 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v37 = v58;
        }
        v58 = v37 + 1;
        v60 = (int)&v57;
      }
      v74 = 1;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v74);
      }
      else
      {
        v38 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 1;
          v38 = v58;
        }
        v58 = v38 + 1;
      }
      v75 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v75);
      }
      else
      {
        v39 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v39 = v58;
        }
        v58 = v39 + 1;
      }
      v76 = 4;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v76);
      }
      else
      {
        v40 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 4;
          v40 = v58;
        }
        v58 = v40 + 1;
      }
      v4 = *(_DWORD *)(a1 + 180);
      v1 = *(_DWORD *)(a1 + 176);
      v3 = (v4 - v1) >> 2;
      if ( !v3 )
        goto LABEL_41;
      v6 = *(_WORD *)v1;
    }
    else
    {
      while ( 1 )
      {
        ++v5;
        if ( v5 >= v2 )
          break;
        if ( *(_WORD *)(v1 + 4 * v5) == 1 )
          goto LABEL_98;
      }
      v60 = (int)&v57;
    }
    v7 = 0;
    if ( v6 == 19 )
    {
LABEL_80:
      v69 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v69);
      }
      else
      {
        v33 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v33 = v58;
        }
        v58 = v33 + 1;
      }
      v70 = 19;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v70);
      }
      else
      {
        v34 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 19;
          v34 = v58;
        }
        v58 = v34 + 1;
      }
      v71 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v71);
      }
      else
      {
        v35 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v35 = v58;
        }
        v58 = v35 + 1;
      }
      v72 = 4;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v72);
      }
      else
      {
        v36 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 4;
          v36 = v58;
        }
        v58 = v36 + 1;
      }
      v4 = *(_DWORD *)(a1 + 180);
      v1 = *(_DWORD *)(a1 + 176);
      v8 = (v4 - v1) >> 2;
      if ( !v8 )
        goto LABEL_41;
    }
    else
    {
      while ( 1 )
      {
        ++v7;
        if ( v7 >= v3 )
          break;
        if ( *(_WORD *)(v1 + 4 * v7) == 19 )
          goto LABEL_80;
      }
      v8 = (v4 - v1) >> 2;
    }
    v9 = 0;
    if ( *(_WORD *)v1 == 2 )
    {
LABEL_62:
      v65 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v65);
      }
      else
      {
        v29 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v29 = v58;
        }
        v58 = v29 + 1;
      }
      v66 = 2;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v66);
      }
      else
      {
        v30 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 2;
          v30 = v58;
        }
        v58 = v30 + 1;
      }
      v67 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v67);
      }
      else
      {
        v31 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v31 = v58;
        }
        v58 = v31 + 1;
      }
      v68 = 1;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v68);
      }
      else
      {
        v32 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 1;
          v32 = v58;
        }
        v58 = v32 + 1;
      }
      v4 = *(_DWORD *)(a1 + 180);
      v1 = *(_DWORD *)(a1 + 176);
      v10 = (v4 - v1) >> 2;
      if ( !v10 )
        goto LABEL_41;
    }
    else
    {
      while ( 1 )
      {
        ++v9;
        if ( v9 >= v8 )
          break;
        if ( *(_WORD *)(v1 + 4 * v9) == 2 )
          goto LABEL_62;
      }
      v10 = (v4 - v1) >> 2;
    }
    v11 = 0;
    if ( *(_WORD *)v1 == 3 )
    {
LABEL_134:
      v81 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v81);
      }
      else
      {
        v45 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v45 = v58;
        }
        v58 = v45 + 1;
      }
      v82 = 3;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v82);
      }
      else
      {
        v46 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 3;
          v46 = v58;
        }
        v58 = v46 + 1;
      }
      v83 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v83);
      }
      else
      {
        v47 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v47 = v58;
        }
        v58 = v47 + 1;
      }
      v84 = 1;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v84);
      }
      else
      {
        v48 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 1;
          v48 = v58;
        }
        v58 = v48 + 1;
      }
      v4 = *(_DWORD *)(a1 + 180);
      v1 = *(_DWORD *)(a1 + 176);
      v12 = (v4 - v1) >> 2;
      if ( !v12 )
        goto LABEL_41;
    }
    else
    {
      while ( 1 )
      {
        ++v11;
        if ( v11 >= v10 )
          break;
        if ( *(_WORD *)(v1 + 4 * v11) == 3 )
          goto LABEL_134;
      }
      v12 = (v4 - v1) >> 2;
    }
    v13 = 0;
    if ( *(_WORD *)v1 == 21 )
    {
LABEL_116:
      v77 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v77);
      }
      else
      {
        v41 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v41 = v58;
        }
        v58 = v41 + 1;
      }
      v78 = 21;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v78);
      }
      else
      {
        v42 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 21;
          v42 = v58;
        }
        v58 = v42 + 1;
      }
      v79 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v79);
      }
      else
      {
        v43 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v43 = v58;
        }
        v58 = v43 + 1;
      }
      v80 = 1;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v80);
      }
      else
      {
        v44 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 1;
          v44 = v58;
        }
        v58 = v44 + 1;
      }
      v4 = *(_DWORD *)(a1 + 180);
      v1 = *(_DWORD *)(a1 + 176);
      v14 = (v4 - v1) >> 2;
      if ( !v14 )
        goto LABEL_41;
    }
    else
    {
      while ( 1 )
      {
        ++v13;
        if ( v13 >= v12 )
          break;
        if ( *(_WORD *)(v1 + 4 * v13) == 21 )
          goto LABEL_116;
      }
      v14 = (v4 - v1) >> 2;
    }
    v15 = 0;
    if ( *(_WORD *)v1 == 4 )
    {
LABEL_152:
      v85 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v85);
      }
      else
      {
        v49 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v49 = v58;
        }
        v58 = v49 + 1;
      }
      v86 = 4;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v86);
      }
      else
      {
        v50 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 4;
          v50 = v58;
        }
        v58 = v50 + 1;
      }
      v87 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v87);
      }
      else
      {
        v51 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v51 = v58;
        }
        v58 = v51 + 1;
      }
      v88 = 1;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v88);
      }
      else
      {
        v52 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 1;
          v52 = v58;
        }
        v58 = v52 + 1;
      }
      v4 = *(_DWORD *)(a1 + 180);
      v1 = *(_DWORD *)(a1 + 176);
      v16 = (v4 - v1) >> 2;
      if ( !v16 )
        goto LABEL_41;
    }
    else
    {
      while ( 1 )
      {
        ++v15;
        if ( v15 >= v14 )
          break;
        if ( *(_WORD *)(v1 + 4 * v15) == 4 )
          goto LABEL_152;
      }
      v16 = (v4 - v1) >> 2;
    }
    v17 = 0;
    if ( *(_WORD *)v1 == 9 )
    {
LABEL_44:
      v61 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v61);
      }
      else
      {
        v25 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v25 = v58;
        }
        v58 = v25 + 1;
      }
      v62 = 9;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v62);
      }
      else
      {
        v26 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 9;
          v26 = v58;
        }
        v58 = v26 + 1;
      }
      v63 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v63);
      }
      else
      {
        v27 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v27 = v58;
        }
        v58 = v27 + 1;
      }
      v64 = 1;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v64);
      }
      else
      {
        v28 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 1;
          v28 = v58;
        }
        v58 = v28 + 1;
      }
      v19 = *(_DWORD *)(a1 + 176);
      v18 = (*(_DWORD *)(a1 + 180) - v19) >> 2;
      if ( !v18 )
        goto LABEL_41;
    }
    else
    {
      while ( 1 )
      {
        ++v17;
        if ( v17 >= v16 )
          break;
        if ( *(_WORD *)(v1 + 4 * v17) == 9 )
          goto LABEL_44;
      }
      v19 = v1;
      v18 = (v4 - v1) >> 2;
    }
    v20 = 0;
    if ( *(_WORD *)v19 == 16 )
    {
LABEL_170:
      v89 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v89);
      }
      else
      {
        v53 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v53 = v58;
        }
        v58 = v53 + 1;
      }
      v90 = 16;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v90);
      }
      else
      {
        v54 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 16;
          v54 = v58;
        }
        v58 = v54 + 1;
      }
      v91 = 0;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v91);
      }
      else
      {
        v55 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 0;
          v55 = v58;
        }
        v58 = v55 + 1;
      }
      v92 = 1;
      if ( v58 == v59 )
      {
        sub_8078230(v60, (const void *)v58, (int)&v92);
      }
      else
      {
        v56 = 0;
        if ( v58 )
        {
          *(_BYTE *)v58 = 1;
          v56 = v58;
        }
        v58 = v56 + 1;
      }
    }
    else
    {
      while ( 1 )
      {
        ++v20;
        if ( v20 >= v18 )
          break;
        if ( *(_WORD *)(v19 + 4 * v20) == 16 )
          goto LABEL_170;
      }
    }
  }
LABEL_41:
  v23 = sub_805A180(a1, 1, 23, 0, v60);
  if ( v57 )
    operator delete(v22, v21);
  return v23 == 1;
}

//----- (0805DD60) --------------------------------------------------------
char __cdecl sub_805DD60(int a1)
{
  int v1; // ecx@1
  int v2; // ebx@1
  int v3; // edi@1
  int v4; // esi@1
  unsigned int v5; // eax@2
  int v6; // edx@8
  unsigned int v7; // ecx@8
  int v8; // ebx@11
  int v9; // edi@11
  int v10; // edx@13
  unsigned int v11; // ecx@13
  int v12; // ebx@16
  int v13; // edi@16
  int v14; // edx@18
  unsigned int v15; // ecx@18
  int v16; // ebx@21
  int v17; // edi@21
  int v18; // edx@23
  unsigned int v19; // ecx@23
  int v20; // ebx@26
  int v21; // edi@26
  int v22; // edx@28
  unsigned int v23; // ecx@28
  int v24; // ebx@31
  int v25; // edi@31
  int v26; // edx@33
  unsigned int v27; // ecx@33
  int v28; // ebx@36
  int v29; // esi@36
  int v30; // edx@38
  unsigned int v31; // ecx@38
  int v32; // edx@41
  int v33; // ecx@41
  signed int v34; // ebx@41
  __int16 v36; // bx@44
  int v37; // eax@45
  int v38; // eax@49
  int v39; // eax@53
  int v40; // eax@57
  int v41; // eax@61
  int v42; // eax@65
  int v43; // eax@69
  int v44; // eax@73
  __int16 v45; // bx@78
  int v46; // eax@79
  int v47; // eax@83
  int v48; // eax@87
  int v49; // eax@91
  int v50; // eax@95
  int v51; // eax@99
  int v52; // eax@103
  int v53; // eax@107
  __int16 v54; // bx@110
  int v55; // eax@111
  int v56; // eax@115
  int v57; // eax@119
  int v58; // eax@123
  int v59; // eax@127
  int v60; // eax@131
  int v61; // eax@135
  int v62; // eax@139
  __int16 v63; // bx@144
  int v64; // eax@145
  int v65; // eax@149
  int v66; // eax@153
  int v67; // eax@157
  int v68; // eax@161
  int v69; // eax@165
  int v70; // eax@169
  int v71; // eax@173
  __int16 v72; // bx@178
  int v73; // eax@179
  int v74; // eax@183
  int v75; // eax@187
  int v76; // eax@191
  int v77; // eax@195
  int v78; // eax@199
  int v79; // eax@203
  int v80; // eax@207
  __int16 v81; // bx@212
  int v82; // eax@213
  int v83; // eax@217
  int v84; // eax@221
  int v85; // eax@225
  int v86; // eax@229
  int v87; // eax@233
  int v88; // eax@237
  int v89; // eax@241
  __int16 v90; // bx@246
  int v91; // eax@247
  int v92; // eax@251
  int v93; // eax@255
  int v94; // eax@259
  int v95; // eax@263
  int v96; // eax@267
  int v97; // eax@271
  int v98; // eax@275
  __int16 v99; // bx@281
  int v100; // eax@282
  int v101; // eax@286
  int v102; // eax@290
  int v103; // eax@294
  int v104; // eax@298
  int v105; // eax@302
  int v106; // eax@306
  int v107; // eax@310
  int v108; // eax@1
  __int16 v109; // ax@9
  __int16 v110; // ax@14
  __int16 v111; // ax@19
  __int16 v112; // ax@24
  __int16 v113; // ax@29
  __int16 v114; // ax@34
  __int16 v115; // ax@39
  int v116; // [sp+30h] [bp-58h]@1
  int v117; // [sp+34h] [bp-54h]@1
  int v118; // [sp+38h] [bp-50h]@1
  int v119; // [sp+24h] [bp-64h]@1
  int v120; // [sp+20h] [bp-68h]@1
  __int16 v121; // [sp+2Ah] [bp-5Eh]@2
  char v122; // [sp+4Bh] [bp-3Dh]@44
  char v123; // [sp+4Ah] [bp-3Eh]@48
  char v124; // [sp+49h] [bp-3Fh]@52
  char v125; // [sp+48h] [bp-40h]@56
  char v126; // [sp+47h] [bp-41h]@60
  char v127; // [sp+46h] [bp-42h]@64
  char v128; // [sp+45h] [bp-43h]@68
  char v129; // [sp+44h] [bp-44h]@72
  char v130; // [sp+43h] [bp-45h]@78
  char v131; // [sp+42h] [bp-46h]@82
  char v132; // [sp+41h] [bp-47h]@86
  char v133; // [sp+40h] [bp-48h]@90
  char v134; // [sp+3Fh] [bp-49h]@94
  char v135; // [sp+3Eh] [bp-4Ah]@98
  char v136; // [sp+3Dh] [bp-4Bh]@102
  char v137; // [sp+3Ch] [bp-4Ch]@106
  char v138; // [sp+53h] [bp-35h]@110
  char v139; // [sp+52h] [bp-36h]@114
  char v140; // [sp+51h] [bp-37h]@118
  char v141; // [sp+50h] [bp-38h]@122
  char v142; // [sp+4Fh] [bp-39h]@126
  char v143; // [sp+4Eh] [bp-3Ah]@130
  char v144; // [sp+4Dh] [bp-3Bh]@134
  char v145; // [sp+4Ch] [bp-3Ch]@138
  char v146; // [sp+5Bh] [bp-2Dh]@144
  char v147; // [sp+5Ah] [bp-2Eh]@148
  char v148; // [sp+59h] [bp-2Fh]@152
  char v149; // [sp+58h] [bp-30h]@156
  char v150; // [sp+57h] [bp-31h]@160
  char v151; // [sp+56h] [bp-32h]@164
  char v152; // [sp+55h] [bp-33h]@168
  char v153; // [sp+54h] [bp-34h]@172
  char v154; // [sp+63h] [bp-25h]@178
  char v155; // [sp+62h] [bp-26h]@182
  char v156; // [sp+61h] [bp-27h]@186
  char v157; // [sp+60h] [bp-28h]@190
  char v158; // [sp+5Fh] [bp-29h]@194
  char v159; // [sp+5Eh] [bp-2Ah]@198
  char v160; // [sp+5Dh] [bp-2Bh]@202
  char v161; // [sp+5Ch] [bp-2Ch]@206
  char v162; // [sp+6Bh] [bp-1Dh]@212
  char v163; // [sp+6Ah] [bp-1Eh]@216
  char v164; // [sp+69h] [bp-1Fh]@220
  char v165; // [sp+68h] [bp-20h]@224
  char v166; // [sp+67h] [bp-21h]@228
  char v167; // [sp+66h] [bp-22h]@232
  char v168; // [sp+65h] [bp-23h]@236
  char v169; // [sp+64h] [bp-24h]@240
  char v170; // [sp+73h] [bp-15h]@246
  char v171; // [sp+72h] [bp-16h]@250
  char v172; // [sp+71h] [bp-17h]@254
  char v173; // [sp+70h] [bp-18h]@258
  char v174; // [sp+6Fh] [bp-19h]@262
  char v175; // [sp+6Eh] [bp-1Ah]@266
  char v176; // [sp+6Dh] [bp-1Bh]@270
  char v177; // [sp+6Ch] [bp-1Ch]@274
  char v178; // [sp+7Bh] [bp-Dh]@281
  char v179; // [sp+7Ah] [bp-Eh]@285
  char v180; // [sp+79h] [bp-Fh]@289
  char v181; // [sp+78h] [bp-10h]@293
  char v182; // [sp+77h] [bp-11h]@297
  char v183; // [sp+76h] [bp-12h]@301
  char v184; // [sp+75h] [bp-13h]@305
  char v185; // [sp+74h] [bp-14h]@309

  v116 = 0;
  v117 = 0;
  v118 = 0;
  v4 = *(_DWORD *)(a1 + 176);
  v108 = *(_DWORD *)(a1 + 180);
  v3 = *(_DWORD *)(a1 + 176);
  v1 = (v108 - v4) >> 2;
  v119 = *(_DWORD *)(a1 + 180);
  v2 = (v108 - v4) >> 2;
  v120 = (int)&v116;
  if ( v1 )
  {
    v121 = *(_WORD *)v4;
    v5 = 0;
    if ( v121 != 1 )
    {
      do
      {
        ++v5;
        if ( v5 >= v1 )
        {
          v120 = (int)&v116;
          goto LABEL_7;
        }
      }
      while ( *(_WORD *)(v4 + 4 * v5) != 1 );
      v3 = v4 + 4 * v5;
    }
    v99 = *(_WORD *)(v3 + 2);
    v178 = 0;
    if ( v117 == v118 )
    {
      v120 = (int)&v116;
      sub_8078230((int)&v116, (const void *)v117, (int)&v178);
    }
    else
    {
      v100 = 0;
      if ( v117 )
      {
        *(_BYTE *)v117 = 0;
        v100 = v117;
      }
      v117 = v100 + 1;
      v120 = (int)&v116;
    }
    v179 = 1;
    if ( v117 == v118 )
    {
      sub_8078230(v120, (const void *)v117, (int)&v179);
    }
    else
    {
      v101 = 0;
      if ( v117 )
      {
        *(_BYTE *)v117 = 1;
        v101 = v117;
      }
      v117 = v101 + 1;
    }
    v180 = 0;
    if ( v117 == v118 )
    {
      sub_8078230(v120, (const void *)v117, (int)&v180);
    }
    else
    {
      v102 = 0;
      if ( v117 )
      {
        *(_BYTE *)v117 = 0;
        v102 = v117;
      }
      v117 = v102 + 1;
    }
    v181 = v99;
    if ( v117 == v118 )
    {
      sub_8078230(v120, (const void *)v117, (int)&v181);
    }
    else
    {
      v103 = 0;
      if ( v117 )
      {
        *(_BYTE *)v117 = v99;
        v103 = v117;
      }
      v117 = v103 + 1;
    }
    v182 = 1;
    if ( v117 == v118 )
    {
      sub_8078230(v120, (const void *)v117, (int)&v182);
    }
    else
    {
      v104 = 0;
      if ( v117 )
      {
        *(_BYTE *)v117 = 1;
        v104 = v117;
      }
      v117 = v104 + 1;
    }
    v183 = 16;
    if ( v117 == v118 )
    {
      sub_8078230(v120, (const void *)v117, (int)&v183);
    }
    else
    {
      v105 = 0;
      if ( v117 )
      {
        *(_BYTE *)v117 = 16;
        v105 = v117;
      }
      v117 = v105 + 1;
    }
    v184 = 8;
    if ( v117 == v118 )
    {
      sub_8078230(v120, (const void *)v117, (int)&v184);
    }
    else
    {
      v106 = 0;
      if ( v117 )
      {
        *(_BYTE *)v117 = 8;
        v106 = v117;
      }
      v117 = v106 + 1;
    }
    v185 = -28;
    if ( v117 == v118 )
    {
      sub_8078230(v120, (const void *)v117, (int)&v185);
    }
    else
    {
      v107 = 0;
      if ( v117 )
      {
        *(_BYTE *)v117 = -28;
        v107 = v117;
      }
      v117 = v107 + 1;
    }
    v4 = *(_DWORD *)(a1 + 176);
    v3 = *(_DWORD *)(a1 + 176);
    v2 = (*(_DWORD *)(a1 + 180) - v4) >> 2;
    v119 = *(_DWORD *)(a1 + 180);
    if ( v2 )
    {
      v121 = *(_WORD *)v4;
LABEL_7:
      if ( v121 == 19 )
      {
LABEL_246:
        v90 = *(_WORD *)(v3 + 2);
        v170 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v170);
        }
        else
        {
          v91 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v91 = v117;
          }
          v117 = v91 + 1;
        }
        v171 = 19;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v171);
        }
        else
        {
          v92 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 19;
            v92 = v117;
          }
          v117 = v92 + 1;
        }
        v172 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v172);
        }
        else
        {
          v93 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v93 = v117;
          }
          v117 = v93 + 1;
        }
        v173 = v90;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v173);
        }
        else
        {
          v94 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = v90;
            v94 = v117;
          }
          v117 = v94 + 1;
        }
        v174 = 1;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v174);
        }
        else
        {
          v95 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 1;
            v95 = v117;
          }
          v117 = v95 + 1;
        }
        v175 = 16;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v175);
        }
        else
        {
          v96 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 16;
            v96 = v117;
          }
          v117 = v96 + 1;
        }
        v176 = 8;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v176);
        }
        else
        {
          v97 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 8;
            v97 = v117;
          }
          v117 = v97 + 1;
        }
        v177 = -28;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v177);
        }
        else
        {
          v98 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = -28;
            v98 = v117;
          }
          v117 = v98 + 1;
        }
        v4 = *(_DWORD *)(a1 + 176);
        v9 = *(_DWORD *)(a1 + 176);
        v8 = (*(_DWORD *)(a1 + 180) - v4) >> 2;
        v119 = *(_DWORD *)(a1 + 180);
        if ( !v8 )
          goto LABEL_41;
      }
      else
      {
        v6 = v4 + 4;
        v7 = 0;
        while ( 1 )
        {
          ++v7;
          if ( v7 >= v2 )
            break;
          v109 = *(_WORD *)v6;
          v3 = v6;
          v6 += 4;
          if ( v109 == 19 )
            goto LABEL_246;
        }
        v9 = v4;
        v8 = (v119 - v4) >> 2;
      }
      if ( *(_WORD *)v4 == 2 )
      {
LABEL_212:
        v81 = *(_WORD *)(v9 + 2);
        v162 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v162);
        }
        else
        {
          v82 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v82 = v117;
          }
          v117 = v82 + 1;
        }
        v163 = 2;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v163);
        }
        else
        {
          v83 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 2;
            v83 = v117;
          }
          v117 = v83 + 1;
        }
        v164 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v164);
        }
        else
        {
          v84 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v84 = v117;
          }
          v117 = v84 + 1;
        }
        v165 = v81;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v165);
        }
        else
        {
          v85 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = v81;
            v85 = v117;
          }
          v117 = v85 + 1;
        }
        v166 = 1;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v166);
        }
        else
        {
          v86 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 1;
            v86 = v117;
          }
          v117 = v86 + 1;
        }
        v167 = 16;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v167);
        }
        else
        {
          v87 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 16;
            v87 = v117;
          }
          v117 = v87 + 1;
        }
        v168 = 8;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v168);
        }
        else
        {
          v88 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 8;
            v88 = v117;
          }
          v117 = v88 + 1;
        }
        v169 = -28;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v169);
        }
        else
        {
          v89 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = -28;
            v89 = v117;
          }
          v117 = v89 + 1;
        }
        v4 = *(_DWORD *)(a1 + 176);
        v13 = *(_DWORD *)(a1 + 176);
        v12 = (*(_DWORD *)(a1 + 180) - v4) >> 2;
        v119 = *(_DWORD *)(a1 + 180);
        if ( !v12 )
          goto LABEL_41;
      }
      else
      {
        v10 = v4 + 4;
        v11 = 0;
        while ( 1 )
        {
          ++v11;
          if ( v11 >= v8 )
            break;
          v110 = *(_WORD *)v10;
          v9 = v10;
          v10 += 4;
          if ( v110 == 2 )
            goto LABEL_212;
        }
        v13 = v4;
        v12 = (v119 - v4) >> 2;
      }
      if ( *(_WORD *)v4 == 3 )
      {
LABEL_178:
        v72 = *(_WORD *)(v13 + 2);
        v154 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v154);
        }
        else
        {
          v73 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v73 = v117;
          }
          v117 = v73 + 1;
        }
        v155 = 3;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v155);
        }
        else
        {
          v74 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 3;
            v74 = v117;
          }
          v117 = v74 + 1;
        }
        v156 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v156);
        }
        else
        {
          v75 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v75 = v117;
          }
          v117 = v75 + 1;
        }
        v157 = v72;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v157);
        }
        else
        {
          v76 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = v72;
            v76 = v117;
          }
          v117 = v76 + 1;
        }
        v158 = 1;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v158);
        }
        else
        {
          v77 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 1;
            v77 = v117;
          }
          v117 = v77 + 1;
        }
        v159 = 16;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v159);
        }
        else
        {
          v78 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 16;
            v78 = v117;
          }
          v117 = v78 + 1;
        }
        v160 = 8;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v160);
        }
        else
        {
          v79 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 8;
            v79 = v117;
          }
          v117 = v79 + 1;
        }
        v161 = -28;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v161);
        }
        else
        {
          v80 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = -28;
            v80 = v117;
          }
          v117 = v80 + 1;
        }
        v4 = *(_DWORD *)(a1 + 176);
        v17 = *(_DWORD *)(a1 + 176);
        v16 = (*(_DWORD *)(a1 + 180) - v4) >> 2;
        v119 = *(_DWORD *)(a1 + 180);
        if ( !v16 )
          goto LABEL_41;
      }
      else
      {
        v14 = v4 + 4;
        v15 = 0;
        while ( 1 )
        {
          ++v15;
          if ( v15 >= v12 )
            break;
          v111 = *(_WORD *)v14;
          v13 = v14;
          v14 += 4;
          if ( v111 == 3 )
            goto LABEL_178;
        }
        v17 = v4;
        v16 = (v119 - v4) >> 2;
      }
      if ( *(_WORD *)v4 == 21 )
      {
LABEL_144:
        v63 = *(_WORD *)(v17 + 2);
        v146 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v146);
        }
        else
        {
          v64 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v64 = v117;
          }
          v117 = v64 + 1;
        }
        v147 = 21;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v147);
        }
        else
        {
          v65 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 21;
            v65 = v117;
          }
          v117 = v65 + 1;
        }
        v148 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v148);
        }
        else
        {
          v66 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v66 = v117;
          }
          v117 = v66 + 1;
        }
        v149 = v63;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v149);
        }
        else
        {
          v67 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = v63;
            v67 = v117;
          }
          v117 = v67 + 1;
        }
        v150 = 1;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v150);
        }
        else
        {
          v68 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 1;
            v68 = v117;
          }
          v117 = v68 + 1;
        }
        v151 = 16;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v151);
        }
        else
        {
          v69 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 16;
            v69 = v117;
          }
          v117 = v69 + 1;
        }
        v152 = 8;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v152);
        }
        else
        {
          v70 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 8;
            v70 = v117;
          }
          v117 = v70 + 1;
        }
        v153 = -28;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v153);
        }
        else
        {
          v71 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = -28;
            v71 = v117;
          }
          v117 = v71 + 1;
        }
        v4 = *(_DWORD *)(a1 + 176);
        v21 = *(_DWORD *)(a1 + 176);
        v20 = (*(_DWORD *)(a1 + 180) - v4) >> 2;
        v119 = *(_DWORD *)(a1 + 180);
        if ( !v20 )
          goto LABEL_41;
      }
      else
      {
        v18 = v4 + 4;
        v19 = 0;
        while ( 1 )
        {
          ++v19;
          if ( v19 >= v16 )
            break;
          v112 = *(_WORD *)v18;
          v17 = v18;
          v18 += 4;
          if ( v112 == 21 )
            goto LABEL_144;
        }
        v21 = v4;
        v20 = (v119 - v4) >> 2;
      }
      if ( *(_WORD *)v4 == 4 )
      {
LABEL_110:
        v54 = *(_WORD *)(v21 + 2);
        v138 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v138);
        }
        else
        {
          v55 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v55 = v117;
          }
          v117 = v55 + 1;
        }
        v139 = 4;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v139);
        }
        else
        {
          v56 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 4;
            v56 = v117;
          }
          v117 = v56 + 1;
        }
        v140 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v140);
        }
        else
        {
          v57 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v57 = v117;
          }
          v117 = v57 + 1;
        }
        v141 = v54;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v141);
        }
        else
        {
          v58 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = v54;
            v58 = v117;
          }
          v117 = v58 + 1;
        }
        v142 = 1;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v142);
        }
        else
        {
          v59 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 1;
            v59 = v117;
          }
          v117 = v59 + 1;
        }
        v143 = 16;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v143);
        }
        else
        {
          v60 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 16;
            v60 = v117;
          }
          v117 = v60 + 1;
        }
        v144 = 8;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v144);
        }
        else
        {
          v61 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 8;
            v61 = v117;
          }
          v117 = v61 + 1;
        }
        v145 = -28;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v145);
        }
        else
        {
          v62 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = -28;
            v62 = v117;
          }
          v117 = v62 + 1;
        }
        v4 = *(_DWORD *)(a1 + 176);
        v25 = *(_DWORD *)(a1 + 176);
        v24 = (*(_DWORD *)(a1 + 180) - v4) >> 2;
        v119 = *(_DWORD *)(a1 + 180);
        if ( !v24 )
          goto LABEL_41;
      }
      else
      {
        v22 = v4 + 4;
        v23 = 0;
        while ( 1 )
        {
          ++v23;
          if ( v23 >= v20 )
            break;
          v113 = *(_WORD *)v22;
          v21 = v22;
          v22 += 4;
          if ( v113 == 4 )
            goto LABEL_110;
        }
        v25 = v4;
        v24 = (v119 - v4) >> 2;
      }
      if ( *(_WORD *)v4 == 9 )
      {
LABEL_44:
        v36 = *(_WORD *)(v25 + 2);
        v122 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v122);
        }
        else
        {
          v37 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v37 = v117;
          }
          v117 = v37 + 1;
        }
        v123 = 9;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v123);
        }
        else
        {
          v38 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 9;
            v38 = v117;
          }
          v117 = v38 + 1;
        }
        v124 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v124);
        }
        else
        {
          v39 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v39 = v117;
          }
          v117 = v39 + 1;
        }
        v125 = v36;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v125);
        }
        else
        {
          v40 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = v36;
            v40 = v117;
          }
          v117 = v40 + 1;
        }
        v126 = 1;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v126);
        }
        else
        {
          v41 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 1;
            v41 = v117;
          }
          v117 = v41 + 1;
        }
        v127 = 16;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v127);
        }
        else
        {
          v42 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 16;
            v42 = v117;
          }
          v117 = v42 + 1;
        }
        v128 = 8;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v128);
        }
        else
        {
          v43 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 8;
            v43 = v117;
          }
          v117 = v43 + 1;
        }
        v129 = -28;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v129);
        }
        else
        {
          v44 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = -28;
            v44 = v117;
          }
          v117 = v44 + 1;
        }
        v28 = *(_DWORD *)(a1 + 176);
        v29 = (*(_DWORD *)(a1 + 180) - v28) >> 2;
        if ( !v29 )
          goto LABEL_41;
      }
      else
      {
        v26 = v4 + 4;
        v27 = 0;
        while ( 1 )
        {
          ++v27;
          if ( v27 >= v24 )
            break;
          v114 = *(_WORD *)v26;
          v25 = v26;
          v26 += 4;
          if ( v114 == 9 )
            goto LABEL_44;
        }
        v28 = v4;
        v29 = (v119 - v4) >> 2;
      }
      if ( *(_WORD *)v28 == 16 )
      {
LABEL_78:
        v45 = *(_WORD *)(v28 + 2);
        v130 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v130);
        }
        else
        {
          v46 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v46 = v117;
          }
          v117 = v46 + 1;
        }
        v131 = 16;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v131);
        }
        else
        {
          v47 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 16;
            v47 = v117;
          }
          v117 = v47 + 1;
        }
        v132 = 0;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v132);
        }
        else
        {
          v48 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 0;
            v48 = v117;
          }
          v117 = v48 + 1;
        }
        v133 = v45;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v133);
        }
        else
        {
          v49 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = v45;
            v49 = v117;
          }
          v117 = v49 + 1;
        }
        v134 = 1;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v134);
        }
        else
        {
          v50 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 1;
            v50 = v117;
          }
          v117 = v50 + 1;
        }
        v135 = 16;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v135);
        }
        else
        {
          v51 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 16;
            v51 = v117;
          }
          v117 = v51 + 1;
        }
        v136 = 8;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v136);
        }
        else
        {
          v52 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = 8;
            v52 = v117;
          }
          v117 = v52 + 1;
        }
        v137 = -28;
        if ( v117 == v118 )
        {
          sub_8078230(v120, (const void *)v117, (int)&v137);
        }
        else
        {
          v53 = 0;
          if ( v117 )
          {
            *(_BYTE *)v117 = -28;
            v53 = v117;
          }
          v117 = v53 + 1;
        }
      }
      else
      {
        v30 = v28 + 4;
        v31 = 0;
        while ( 1 )
        {
          ++v31;
          if ( v31 >= v29 )
            break;
          v115 = *(_WORD *)v30;
          v28 = v30;
          v30 += 4;
          if ( v115 == 16 )
            goto LABEL_78;
        }
      }
    }
  }
LABEL_41:
  v34 = sub_805A180(a1, 1, 2, 0, v120);
  if ( v116 )
    operator delete(v33, v32);
  return v34 == 1;
}

//----- (0805F070) --------------------------------------------------------
int __cdecl sub_805F070(int a1, int a2)
{
  int v2; // edx@1
  int v3; // ecx@1
  int v4; // esi@1
  int v5; // ebx@3
  int v6; // edi@3
  int v7; // ebx@6
  __int16 v9; // ax@1
  int v10; // eax@5
  int v11; // ebx@5
  size_t v12; // ebx@5
  int v13; // ecx@7
  int v14; // eax@7
  int v15; // ebx@7
  int v16; // ecx@7
  int v17; // edx@7
  char v18; // [sp+28h] [bp-40h]@1
  __int16 v19; // [sp+2Ah] [bp-3Eh]@1
  char v20; // [sp+4Ch] [bp-1Ch]@1
  const void *v21; // [sp+40h] [bp-28h]@1
  int v22; // [sp+44h] [bp-24h]@1
  int v23; // [sp+48h] [bp-20h]@1
  int v24; // [sp+54h] [bp-14h]@1
  __int16 v25; // [sp+3Ch] [bp-2Ch]@1
  int v26; // [sp+58h] [bp-10h]@1
  char v27; // [sp+2Ch] [bp-3Ch]@7
  char v28; // [sp+50h] [bp-18h]@8

  sub_8050EE0((int)&v18);
  v18 = 1;
  v9 = *(_WORD *)(a1 + 168);
  v19 = *(_WORD *)(a1 + 168);
  *(_WORD *)(a1 + 168) = v9 + 1;
  sub_8051060((int)&v20);
  v21 = 0;
  v22 = 0;
  v23 = 0;
  sub_804B500(v3, v2, (int)&v21, a2);
  v4 = v24;
  v25 = 6;
  if ( v24 == v26 )
  {
    v7 = (int)&v25;
    sub_8057B40(v3, v2, (int)&v28, v24, (int)&v25);
  }
  else
  {
    if ( v24 )
    {
      v6 = 0;
      v5 = v22 - (_DWORD)v21;
      *(_WORD *)v24 = 6;
      *(_DWORD *)(v24 + 4) = 0;
      *(_DWORD *)(v24 + 8) = 0;
      *(_DWORD *)(v24 + 12) = 0;
      if ( v5 )
        v6 = operator new(v3, v2);
      v10 = v6 + v5;
      *(_DWORD *)(v4 + 4) = v6;
      *(_DWORD *)(v4 + 8) = v6;
      v11 = v22;
      *(_DWORD *)(v4 + 12) = v10;
      v12 = v11 - (_DWORD)v21;
      memmove((void *)v6, v21, v12);
      *(_DWORD *)(v4 + 8) = v6 + v12;
      v4 = v24;
    }
    v24 = v4 + 16;
    v7 = (int)&v25;
  }
  sub_8052370(v3, v2, v7);
  sub_8052A60((int)&v20, (int)&v27, 0);
  LOBYTE(v14) = sub_8051DF0(v13, a1, (int)&v18, *(_DWORD *)(a1 + 164));
  v15 = v14;
  sub_80524F0(v13, (int)&v20, (int)&v20);
  sub_80522F0(v16, v17, (int)&v18);
  return v15;
}

//----- (0805F220) --------------------------------------------------------
int __cdecl sub_805F220(int a1, __int16 a2, int a3)
{
  __int16 v3; // bx@1
  __int16 v4; // di@1
  signed int v5; // eax@2
  int v6; // ecx@2
  int v7; // edx@3
  int v8; // ecx@3
  unsigned int v9; // ebx@4
  int v10; // eax@6
  int v11; // edx@8
  int v12; // esi@8
  int v13; // edi@9
  int v14; // ebx@11
  int v15; // esi@11
  int v16; // edx@15
  int v17; // ecx@15
  signed int v18; // ebx@15
  int v19; // ebx@17
  int v21; // edx@19
  unsigned int v22; // ebx@20
  __int16 v23; // ax@7
  __int16 v24; // ax@11
  int v25; // eax@13
  int v26; // ebx@13
  size_t v27; // ebx@13
  int v28; // eax@19
  __int16 v29; // ax@21
  char v30; // [sp+20h] [bp-48h]@1
  __int16 v31; // [sp+28h] [bp-40h]@1
  __int16 v32; // [sp+2Ah] [bp-3Eh]@1
  __int16 v33; // [sp+2Ch] [bp-3Ch]@1
  char v34; // [sp+24h] [bp-44h]@3
  const void *v35; // [sp+40h] [bp-28h]@3
  int v36; // [sp+48h] [bp-20h]@3
  int v37; // [sp+44h] [bp-24h]@3
  __int16 v38; // [sp+3Ch] [bp-2Ch]@3
  __int16 v39; // [sp+5Ah] [bp-Eh]@7
  char v40; // [sp+5Ch] [bp-Ch]@7
  int v41; // [sp+34h] [bp-34h]@9
  int v42; // [sp+38h] [bp-30h]@9
  int v43; // [sp+4Ch] [bp-1Ch]@15
  int v44; // [sp+50h] [bp-18h]@15
  int v45; // [sp+54h] [bp-14h]@15
  char v46; // [sp+30h] [bp-38h]@24

  v3 = a2;
  sub_80512C0((int)&v30);
  v4 = v3;
  v31 = v3;
  v32 = 0;
  v33 = 1;
  if ( v3 )
  {
    v5 = sub_8058090(a1, v3);
    if ( v5 < 0 )
    {
      v19 = 0;
      goto LABEL_18;
    }
    std__string__assign(&v34, *(_DWORD *)(a1 + 16) + 8 * v5 + 4);
    v35 = 0;
    v36 = 0;
    v37 = 0;
    v8 = *(_DWORD *)(a1 + 8);
    v7 = *(_DWORD *)(a1 + 4);
    v38 = 200;
    if ( (v8 - v7) >> 7 )
    {
      v9 = 0;
      do
      {
        while ( 1 )
        {
          v10 = v7 + (v9 << 7);
          if ( *(_WORD *)(v10 + 8) == v4 )
            break;
          ++v9;
          if ( v9 >= (v8 - v7) >> 7 )
            goto LABEL_8;
        }
        v23 = __ROR__(*(_WORD *)(v10 + 16), 8);
        v39 = v23;
        sub_8078660(&v35, v37, &v39, &v40);
        ++v9;
        v7 = *(_DWORD *)(a1 + 4);
        v8 = *(_DWORD *)(a1 + 8);
      }
      while ( v9 < (v8 - v7) >> 7 );
    }
  }
  else
  {
    v8 = a1;
    v35 = 0;
    v36 = 0;
    v37 = 0;
    v21 = *(_DWORD *)(a1 + 16);
    v28 = *(_DWORD *)(a1 + 20);
    v38 = 200;
    if ( (v28 - v21) >> 3 )
    {
      v22 = 0;
      do
      {
        v29 = __ROR__(*(_WORD *)(v21 + 8 * v22), 8);
        v39 = v29;
        sub_8078660(&v35, v37, &v39, &v40);
        v8 = a1;
        ++v22;
        v21 = *(_DWORD *)(a1 + 16);
      }
      while ( v22 < (*(_DWORD *)(a1 + 20) - v21) >> 3 );
    }
  }
LABEL_8:
  v11 = v37;
  v12 = (int)&v38;
  if ( v37 != (_DWORD)v35 )
  {
    v13 = v41;
    if ( v41 == v42 )
    {
      v12 = (int)&v38;
      sub_8057B40(v8, v37, (int)&v46, v41, (int)&v38);
    }
    else
    {
      if ( v41 )
      {
        v24 = v38;
        v15 = 0;
        v14 = v37 - (_DWORD)v35;
        *(_DWORD *)(v41 + 8) = 0;
        *(_DWORD *)(v41 + 4) = 0;
        *(_WORD *)v41 = v24;
        *(_DWORD *)(v41 + 12) = 0;
        if ( v14 )
          v15 = operator new(v8, v11);
        v25 = v15 + v14;
        *(_DWORD *)(v13 + 4) = v15;
        *(_DWORD *)(v13 + 8) = v15;
        v26 = v37;
        *(_DWORD *)(v13 + 12) = v25;
        v27 = v26 - (_DWORD)v35;
        memmove((void *)v15, v35, v27);
        *(_DWORD *)(v13 + 8) = v15 + v27;
        v13 = v41;
      }
      v41 = v13 + 16;
      v12 = (int)&v38;
    }
  }
  v43 = 0;
  v44 = 0;
  v45 = 0;
  sub_8053310((int)&v30, (int)&v43, 0);
  v18 = sub_805A180(a1, 19, 9, a3, (int)&v43);
  if ( v43 )
    operator delete(v17, v16);
  sub_8052370(v6, v16, v12);
  v19 = v18 - 1;
  LOBYTE(v19) = v19 == 0;
LABEL_18:
  sub_80549C0(v6, (int)&v30, (int)&v30);
  return v19;
}

//----- (0805F520) --------------------------------------------------------
int __cdecl sub_805F520(int a1, int a2, char a3)
{
  int v3; // edx@1
  int v4; // ecx@1
  int v5; // esi@1
  int v6; // ebx@3
  int v7; // edi@3
  int v8; // ecx@7
  int v9; // edx@8
  int v10; // ecx@8
  int v11; // esi@8
  int v12; // ebx@10
  int v13; // edi@10
  int v14; // edx@15
  int v15; // ecx@15
  int v16; // esi@15
  int v17; // ebx@17
  int v18; // edi@17
  int v19; // ebx@20
  int v20; // edx@22
  int v21; // ecx@22
  int v22; // esi@22
  int v23; // ebx@24
  int v24; // edi@24
  int v25; // edx@29
  int v26; // ecx@29
  int v27; // esi@29
  int result; // eax@31
  int v29; // edx@37
  int v30; // ecx@37
  int v31; // ebx@37
  int v32; // esi@37
  int v33; // eax@5
  int v34; // ebx@5
  size_t v35; // ebx@5
  int v36; // eax@12
  int v37; // ebx@12
  size_t v38; // ebx@12
  int v39; // eax@19
  int v40; // ebx@19
  size_t v41; // ebx@19
  int v42; // eax@26
  int v43; // ebx@26
  size_t v44; // ebx@26
  int v45; // eax@29
  int v46; // ecx@38
  int v47; // edx@38
  int v48; // [sp+74h] [bp-44h]@1
  char v49; // [sp+17h] [bp-A1h]@1
  int v50; // [sp+18h] [bp-A0h]@1
  int v51; // [sp+78h] [bp-40h]@1
  int v52; // [sp+A8h] [bp-10h]@1
  int v53; // [sp+7Ch] [bp-3Ch]@1
  char v54; // [sp+64h] [bp-54h]@1
  const void *v55; // [sp+58h] [bp-60h]@1
  int v56; // [sp+5Ch] [bp-5Ch]@1
  int v57; // [sp+60h] [bp-58h]@1
  __int16 v58; // [sp+54h] [bp-64h]@1
  int v59; // [sp+6Ch] [bp-4Ch]@1
  int v60; // [sp+70h] [bp-48h]@1
  const void *v61; // [sp+48h] [bp-70h]@8
  int v62; // [sp+4Ch] [bp-6Ch]@8
  int v63; // [sp+50h] [bp-68h]@8
  __int16 v64; // [sp+44h] [bp-74h]@8
  char v65; // [sp+83h] [bp-35h]@15
  char v66; // [sp+84h] [bp-34h]@15
  char v67; // [sp+85h] [bp-33h]@15
  char v68; // [sp+86h] [bp-32h]@15
  char v69; // [sp+87h] [bp-31h]@15
  char v70; // [sp+88h] [bp-30h]@15
  char v71; // [sp+89h] [bp-2Fh]@15
  char v72; // [sp+8Ah] [bp-2Eh]@15
  char v73; // [sp+8Bh] [bp-2Dh]@15
  char v74; // [sp+8Ch] [bp-2Ch]@15
  char v75; // [sp+8Dh] [bp-2Bh]@15
  char v76; // [sp+8Eh] [bp-2Ah]@15
  char v77; // [sp+8Fh] [bp-29h]@15
  char v78; // [sp+90h] [bp-28h]@15
  char v79; // [sp+91h] [bp-27h]@15
  char v80; // [sp+92h] [bp-26h]@15
  char v81; // [sp+93h] [bp-25h]@15
  char v82; // [sp+94h] [bp-24h]@15
  char v83; // [sp+95h] [bp-23h]@15
  char v84; // [sp+96h] [bp-22h]@15
  char v85; // [sp+97h] [bp-21h]@15
  char v86; // [sp+98h] [bp-20h]@15
  char v87; // [sp+99h] [bp-1Fh]@15
  char v88; // [sp+9Ah] [bp-1Eh]@15
  char v89; // [sp+9Bh] [bp-1Dh]@15
  char v90; // [sp+9Ch] [bp-1Ch]@15
  char v91; // [sp+9Dh] [bp-1Bh]@15
  char v92; // [sp+9Eh] [bp-1Ah]@15
  char v93; // [sp+9Fh] [bp-19h]@15
  char v94; // [sp+A0h] [bp-18h]@15
  char v95; // [sp+A1h] [bp-17h]@15
  char v96; // [sp+A2h] [bp-16h]@15
  char v97; // [sp+A3h] [bp-15h]@15
  char v98; // [sp+A4h] [bp-14h]@15
  char v99; // [sp+A5h] [bp-13h]@15
  char v100; // [sp+A6h] [bp-12h]@15
  char v101; // [sp+A7h] [bp-11h]@15
  const void *v102; // [sp+38h] [bp-80h]@15
  int v103; // [sp+3Ch] [bp-7Ch]@15
  int v104; // [sp+40h] [bp-78h]@15
  __int16 v105; // [sp+34h] [bp-84h]@15
  const void *v106; // [sp+28h] [bp-90h]@22
  int v107; // [sp+2Ch] [bp-8Ch]@22
  int v108; // [sp+30h] [bp-88h]@22
  __int16 v109; // [sp+24h] [bp-94h]@22
  char v110; // [sp+68h] [bp-50h]@33

  v48 = 0;
  v49 = a3;
  v50 = a1;
  v51 = 0;
  v52 = *MK_FP(__GS__, 20);
  v53 = 0;
  sub_8050FB0((int)&v54);
  v55 = 0;
  v56 = 0;
  v57 = 0;
  sub_8052530((int)&v58);
  v5 = v59;
  v58 = 6;
  if ( v59 == v60 )
  {
    sub_8057B40(v4, (int)&v58, (int)&v110, v59, (int)&v58);
  }
  else
  {
    if ( v59 )
    {
      v7 = 0;
      v6 = v56 - (_DWORD)v55;
      *(_WORD *)v59 = 6;
      *(_DWORD *)(v59 + 4) = 0;
      *(_DWORD *)(v59 + 8) = 0;
      *(_DWORD *)(v59 + 12) = 0;
      if ( v6 )
        v7 = operator new(v4, v3);
      v33 = v7 + v6;
      *(_DWORD *)(v5 + 4) = v7;
      *(_DWORD *)(v5 + 8) = v7;
      v34 = v56;
      *(_DWORD *)(v5 + 12) = v33;
      v35 = v34 - (_DWORD)v55;
      memmove((void *)v7, v55, v35);
      *(_DWORD *)(v5 + 8) = v7 + v35;
      v5 = v59;
    }
    v59 = v5 + 16;
  }
  sub_8052370(v4, (int)&v58, (int)&v58);
  if ( v49 )
  {
    v61 = 0;
    v62 = 0;
    v63 = 0;
    sub_80525A0((int)&v64, 0);
    v11 = v59;
    v64 = 8;
    if ( v59 == v60 )
    {
      sub_8057B40(v10, (int)&v64, (int)&v110, v59, (int)&v64);
    }
    else
    {
      if ( v59 )
      {
        v13 = 0;
        v12 = v62 - (_DWORD)v61;
        *(_WORD *)v59 = 8;
        *(_DWORD *)(v59 + 4) = 0;
        *(_DWORD *)(v59 + 8) = 0;
        *(_DWORD *)(v59 + 12) = 0;
        if ( v12 )
          v13 = operator new(v10, v9);
        v36 = v13 + v12;
        *(_DWORD *)(v11 + 4) = v13;
        *(_DWORD *)(v11 + 8) = v13;
        v37 = v62;
        *(_DWORD *)(v11 + 12) = v36;
        v38 = v37 - (_DWORD)v61;
        memmove((void *)v13, v61, v38);
        *(_DWORD *)(v11 + 8) = v13 + v38;
        v11 = v59;
      }
      v59 = v11 + 16;
    }
    sub_8052370(v8, (int)&v64, (int)&v64);
  }
  v65 = 0;
  v66 = 0;
  v67 = 0;
  v68 = 0;
  v69 = 0;
  v70 = 0;
  v71 = 0;
  v72 = 0;
  v73 = 4;
  v74 = 0;
  v75 = 9;
  v76 = 10;
  v77 = 11;
  v78 = 51;
  v79 = 69;
  v80 = 0;
  v81 = 0;
  v82 = 11;
  v83 = -11;
  v84 = 0;
  v85 = 0;
  v86 = 0;
  v87 = 1;
  v88 = 0;
  v89 = 0;
  v90 = 0;
  v91 = 0;
  v92 = 0;
  v93 = 0;
  v94 = 0;
  v95 = 0;
  v96 = 0;
  v97 = 0;
  v98 = 0;
  v99 = 0;
  v100 = 0;
  v101 = 0;
  v102 = 0;
  v103 = 0;
  v104 = 0;
  sub_80780C0(v8, (int)&v65, (int)&v102, &v65, (int)&v52);
  v16 = v59;
  v105 = 12;
  if ( v59 == v60 )
  {
    v19 = (int)&v105;
    sub_8057B40(v15, v14, (int)&v110, v59, (int)&v105);
  }
  else
  {
    if ( v59 )
    {
      v18 = 0;
      v17 = v103 - (_DWORD)v102;
      *(_WORD *)v59 = 12;
      *(_DWORD *)(v59 + 4) = 0;
      *(_DWORD *)(v59 + 8) = 0;
      *(_DWORD *)(v59 + 12) = 0;
      if ( v17 )
        v18 = operator new(v15, v14);
      v39 = v18 + v17;
      *(_DWORD *)(v16 + 4) = v18;
      *(_DWORD *)(v16 + 8) = v18;
      v40 = v103;
      *(_DWORD *)(v16 + 12) = v39;
      v41 = v40 - (_DWORD)v102;
      memmove((void *)v18, v102, v41);
      *(_DWORD *)(v16 + 8) = v18 + v41;
      v16 = v59;
    }
    v59 = v16 + 16;
    v19 = (int)&v105;
  }
  sub_8052370(v15, v14, v19);
  if ( v49 )
  {
    v106 = 0;
    v107 = 0;
    v108 = 0;
    sub_80525A0((int)&v109, 0);
    v22 = v59;
    v109 = 31;
    if ( v59 == v60 )
    {
      sub_8057B40(v21, (int)&v109, (int)&v110, v59, (int)&v109);
    }
    else
    {
      if ( v59 )
      {
        v24 = 0;
        v23 = v107 - (_DWORD)v106;
        *(_WORD *)v59 = 31;
        *(_DWORD *)(v59 + 4) = 0;
        *(_DWORD *)(v59 + 8) = 0;
        *(_DWORD *)(v59 + 12) = 0;
        if ( v23 )
          v24 = operator new(v21, v20);
        v42 = v24 + v23;
        *(_DWORD *)(v22 + 4) = v24;
        *(_DWORD *)(v22 + 8) = v24;
        v43 = v107;
        *(_DWORD *)(v22 + 12) = v42;
        v44 = v43 - (_DWORD)v106;
        memmove((void *)v24, v106, v44);
        *(_DWORD *)(v22 + 8) = v24 + v44;
        v22 = v59;
      }
      v59 = v22 + 16;
    }
    sub_8052370(v21, (int)&v109, (int)&v109);
  }
  sub_80529E0((int)&v54, (int)&v48, 0);
  v45 = sub_805A180(v50, 1, 30, 0, (int)&v48) - 1;
  LOBYTE(v45) = v45 == 0;
  v27 = v45;
  sub_8052390(v26, (int)&v54, (int)&v54);
  if ( v48 )
    operator delete(v26, v25);
  result = v27;
  if ( *MK_FP(__GS__, 20) ^ v52 )
  {
    v32 = __stack_chk_fail();
    v31 = (int)&v48;
    sub_8052370(v30, v29, (int)&v109);
    while ( 1 )
    {
      sub_8052390(v30, v29, (int)&v54);
      sub_8056490(v46, v47, v31);
      v32 = _Unwind_Resume(v32);
      v31 = (int)&v48;
      sub_8052370(v30, v29, (int)&v64);
    }
  }
  return result;
}

//----- (0805FB00) --------------------------------------------------------
signed int __cdecl sub_805FB00(int a1, int a2)
{
  int v2; // ebx@1
  int v3; // esi@1
  signed int result; // eax@2

  v2 = a1;
  v3 = a2;
  if ( (unsigned __int8)sub_805F520(a1, a2, 0) && sub_805AF40(v2, 0) )
  {
    *(_DWORD *)(v2 + 292) = v3;
    result = 1;
  }
  else
  {
    result = 0;
  }
  return result;
}

//----- (0805FB70) --------------------------------------------------------
int __cdecl sub_805FB70(int a1, const void **a2, int a3, char a4)
{
  int v4; // edx@1
  int v5; // eax@3
  int v6; // edx@3
  size_t v7; // ebx@3
  const void *v8; // esi@3
  int v9; // edx@5
  int v10; // ebx@5
  int v11; // edi@5
  int v12; // edx@12
  int v13; // ecx@12
  int result; // eax@14
  int v15; // ecx@27
  int v16; // ebx@27
  int v17; // ebx@1
  int v18; // [sp+30h] [bp-68h]@1
  int v19; // [sp+28h] [bp-70h]@1
  const void **v20; // [sp+24h] [bp-74h]@1
  int v21; // [sp+88h] [bp-10h]@1
  int v22; // [sp+34h] [bp-64h]@1
  char v23; // [sp+23h] [bp-75h]@1
  int v24; // [sp+38h] [bp-60h]@1
  char v25; // [sp+3Fh] [bp-59h]@1
  __int16 v26; // [sp+40h] [bp-58h]@7
  __int16 v27; // [sp+42h] [bp-56h]@7
  __int16 v28; // [sp+46h] [bp-52h]@7
  char v29; // [sp+44h] [bp-54h]@7
  __int16 v30; // [sp+48h] [bp-50h]@7
  char v31; // [sp+45h] [bp-53h]@11
  char v32; // [sp+4Ch] [bp-4Ch]@11

  v17 = a3;
  v18 = 0;
  v19 = a1;
  v20 = a2;
  v21 = *MK_FP(__GS__, 20);
  v22 = 0;
  v23 = a4;
  v24 = 0;
  v25 = 0;
  sub_8056580(&v18, 0, 8, &v25);
  *(_DWORD *)v18 = *(_DWORD *)v17;
  *(_DWORD *)(v18 + 4) = *(_DWORD *)(v17 + 4);
  v4 = v18;
  v25 = 0;
  if ( (unsigned int)(v22 - v18) <= 0xB )
  {
    sub_8056580(&v18, v22, 11 - (v22 - v18), &v25);
    v4 = v18;
  }
  else
  {
    v22 = v18 + 11;
  }
  *(_BYTE *)(v4 + 8) = 0;
  *(_BYTE *)(v18 + 9) = 2;
  *(_BYTE *)(v18 + 10) = *((_DWORD *)*v20 - 3);
  v6 = v18;
  v8 = *v20;
  v7 = *((_DWORD *)*v20 - 3);
  v25 = 0;
  v5 = v7 + 11;
  if ( v7 + 11 >= v22 - v18 )
  {
    sub_8056580(&v18, v22, v5 - (v22 - v18), &v25);
    v8 = *v20;
    v6 = v18;
    v7 = *((_DWORD *)*v20 - 3);
  }
  else
  {
    v22 = v18 + v5;
  }
  memcpy((void *)(v6 + 11), v8, v7);
  v9 = v18;
  v10 = *((_DWORD *)*v20 - 3);
  v25 = 0;
  v11 = v10 + 13;
  if ( v10 + 13 >= (unsigned int)(v22 - v18) )
  {
    sub_8056580(&v18, v22, v11 - (v22 - v18), &v25);
    v9 = v18;
  }
  else
  {
    v22 = v18 + v11;
  }
  *(_BYTE *)(v9 + v10 + 11) = 0;
  *(_BYTE *)(v18 + v10 + 11 + 1) = 3;
  sub_8051580((int)&v26);
  v26 = 9;
  v27 = 0;
  v28 = 0;
  v29 = v23;
  v30 = 0;
  if ( v23 == -23 )
  {
    v31 = 3;
    std__string__assign(&v32, v19 + 80);
  }
  else
  {
    if ( (unsigned __int8)v23 <= 0xE9u )
    {
      if ( v23 == 1 )
      {
        v31 = 0;
        std__string__assign(&v32, &aResNr[13], 0);
      }
      else
      {
        if ( v23 == -24 )
        {
          v31 = 3;
          std__string__assign(&v32, v19 + 76);
        }
      }
    }
    else
    {
      if ( v23 == -21 )
      {
        v31 = 3;
        std__string__assign(&v32, v19 + 88);
      }
      else
      {
        if ( (unsigned __int8)v23 >= 0xEBu )
        {
          if ( v23 == -20 )
          {
            v31 = 3;
            std__string__assign(&v32, v19 + 92);
          }
        }
        else
        {
          v31 = 3;
          std__string__assign(&v32, v19 + 84);
        }
      }
    }
  }
  sub_8052BE0((int)&v26, (int)&v18, v10 + 13);
  LOBYTE(v10) = sub_805A180(v19, 4, 11, 0, (int)&v18) == 1;
  sub_80543A0((int)&v26);
  if ( v18 )
    operator delete(v13, v12);
  result = v10;
  if ( *MK_FP(__GS__, 20) ^ v21 )
  {
    v16 = __stack_chk_fail();
    sub_80543A0((int)&v26);
    while ( 1 )
    {
      sub_8056490(v15, (int)&v18, (int)&v18);
      v16 = _Unwind_Resume(v16);
    }
  }
  return result;
}

//----- (08060160) --------------------------------------------------------
signed int __cdecl sub_8060160(int a1, unsigned __int8 a2)
{
  signed int v2; // ebx@1
  int v4; // edx@3
  int v5; // ecx@3
  int v6; // esi@3
  int v7; // ebx@5
  int v8; // edi@5
  int v9; // ebx@8
  __int16 v10; // bx@10
  int v11; // edx@11
  int v12; // ecx@11
  int v13; // eax@7
  int v14; // ebx@7
  size_t v15; // ebx@7
  char v16; // [sp+1Bh] [bp-4Dh]@1
  char v17; // [sp+1Ch] [bp-4Ch]@3
  char v18; // [sp+20h] [bp-48h]@3
  __int16 v19; // [sp+24h] [bp-44h]@3
  __int16 v20; // [sp+28h] [bp-40h]@3
  const void *v21; // [sp+3Ch] [bp-2Ch]@3
  int v22; // [sp+40h] [bp-28h]@3
  int v23; // [sp+44h] [bp-24h]@3
  char v24; // [sp+5Bh] [bp-Dh]@3
  int v25; // [sp+30h] [bp-38h]@3
  __int16 v26; // [sp+38h] [bp-30h]@3
  int v27; // [sp+34h] [bp-34h]@3
  __int16 v28; // [sp+26h] [bp-42h]@10
  int v29; // [sp+48h] [bp-20h]@11
  int v30; // [sp+4Ch] [bp-1Ch]@11
  int v31; // [sp+50h] [bp-18h]@11
  int v32; // [sp+54h] [bp-14h]@11
  __int16 v33; // [sp+58h] [bp-10h]@16
  char v34; // [sp+2Ch] [bp-3Ch]@20

  v2 = 0;
  v16 = a2;
  if ( (unsigned __int8)(a2 - 1) <= 4u )
  {
    sub_80512C0((int)&v17);
    std__string__assign(&v18, &aResNr[13], 0);
    v19 = 0;
    v20 = 4;
    v21 = 0;
    v22 = 0;
    v23 = 0;
    v24 = 0;
    sub_8056580(&v21, 0, 1, &v24);
    v4 = (unsigned __int8)v16;
    *(_BYTE *)v21 = v16;
    v6 = v25;
    v26 = 202;
    if ( v25 == v27 )
    {
      v9 = (int)&v26;
      sub_8057B40(v5, v4, (int)&v34, v25, (int)&v26);
    }
    else
    {
      if ( v25 )
      {
        v8 = 0;
        v7 = v22 - (_DWORD)v21;
        *(_WORD *)v25 = 202;
        *(_DWORD *)(v25 + 4) = 0;
        *(_DWORD *)(v25 + 8) = 0;
        *(_DWORD *)(v25 + 12) = 0;
        if ( v7 )
          v8 = operator new(v5, v4);
        v13 = v8 + v7;
        *(_DWORD *)(v6 + 4) = v8;
        *(_DWORD *)(v6 + 8) = v8;
        v14 = v22;
        *(_DWORD *)(v6 + 12) = v13;
        v15 = v14 - (_DWORD)v21;
        memmove((void *)v8, v21, v15);
        *(_DWORD *)(v6 + 8) = v8 + v15;
        v6 = v25;
      }
      v25 = v6 + 16;
      v9 = (int)&v26;
    }
    sub_8052370(v5, v4, v9);
    if ( *(_WORD *)(a1 + 298) )
    {
      v28 = *(_WORD *)(a1 + 298);
      v10 = 9;
    }
    else
    {
      v28 = sub_8059BB0(a1);
      v10 = 8;
    }
    v29 = 0;
    v30 = 0;
    v31 = 0;
    sub_8053310((int)&v17, (int)&v29, 0);
    if ( sub_805A180(a1, 19, v10, (int)&v32, (int)&v29) != 1 || !(unsigned __int8)sub_805A920(a1, (int)&v33, v32) || v33 )
    {
      v2 = 0;
    }
    else
    {
      v2 = 1;
      *(_BYTE *)(a1 + 296) = v16;
      v11 = a1;
      *(_WORD *)(a1 + 298) = v28;
    }
    if ( v29 )
      operator delete(v12, v11);
    sub_80549C0(v12, (int)&v17, (int)&v17);
  }
  return v2;
}

//----- (08063EF0) --------------------------------------------------------
signed int __cdecl sub_8063EF0(int a1, int *a2, __int16 a3)
{
  signed int v4; // ebx@1
  int v5; // edi@1
  int *v6; // esi@1
  int v7; // eax@3
  signed int v8; // edx@4
  signed int result; // eax@8
  signed int v10; // eax@10
  signed int v11; // eax@12
  int v12; // ebx@19
  int v13; // edx@24
  int v14; // ecx@24
  int v15; // ecx@29
  int v16; // ecx@16
  int v17; // edx@16
  __int16 v18; // ax@19
  int v19; // ecx@19
  int v20; // edx@19
  __int16 v21; // ax@21
  int v22; // ecx@21
  int v23; // edx@21
  __int16 v24; // ax@27
  int v25; // ecx@27
  int v26; // edx@27
  int v33; // [sp+F8h] [bp-10h]@1
  int v34; // [sp+24h] [bp-E4h]@1
  __int16 v35; // [sp+28h] [bp-E0h]@1
  int v36; // [sp+44h] [bp-C4h]@1
  char v37; // [sp+C8h] [bp-40h]@12
  char v38; // [sp+D8h] [bp-30h]@12
  signed int v39; // [sp+CCh] [bp-3Ch]@12
  signed int v40; // [sp+D0h] [bp-38h]@12
  int v41; // [sp+30h] [bp-D8h]@16
  int v42; // [sp+34h] [bp-D4h]@16
  int v43; // [sp+38h] [bp-D0h]@16
  __int16 v44; // [sp+3Ch] [bp-CCh]@19
  char v45; // [sp+40h] [bp-C8h]@19
  __int16 v46; // [sp+D4h] [bp-34h]@19
  __int16 v47; // [sp+3Eh] [bp-CAh]@19
  char v48; // [sp+DCh] [bp-2Ch]@19
  char v49; // [sp+4Ch] [bp-BCh]@23
  signed int v50; // [sp+E8h] [bp-20h]@23
  signed int v51; // [sp+ECh] [bp-1Ch]@23
  signed int v52; // [sp+66h] [bp-A2h]@23
  signed int v53; // [sp+F0h] [bp-18h]@23
  signed int v54; // [sp+6Ah] [bp-9Eh]@23
  signed int v55; // [sp+F4h] [bp-14h]@23
  signed int v56; // [sp+6Eh] [bp-9Ah]@23
  __int16 v57; // [sp+5Ch] [bp-ACh]@23
  signed int v58; // [sp+5Eh] [bp-AAh]@23
  signed int v59; // [sp+62h] [bp-A6h]@23
  signed int v60; // [sp+72h] [bp-96h]@23
  signed int v61; // [sp+78h] [bp-90h]@23
  __int16 v62; // [sp+7Ch] [bp-8Ch]@23
  __int16 v63; // [sp+80h] [bp-88h]@23
  char v64; // [sp+84h] [bp-84h]@23
  char v65; // [sp+85h] [bp-83h]@23
  __int16 v66; // [sp+86h] [bp-82h]@23
  __int16 v67; // [sp+88h] [bp-80h]@23
  char v68; // [sp+8Ch] [bp-7Ch]@23
  int v69; // [sp+90h] [bp-78h]@23
  int v70; // [sp+94h] [bp-74h]@23
  char v71; // [sp+98h] [bp-70h]@24
  char v72; // [sp+4Bh] [bp-BDh]@31

  v6 = a2;
  v33 = *MK_FP(__GS__, 20);
  v34 = a1;
  v5 = (int)(a2 + 3);
  v35 = a3;
  std__string__string(&v36, a2 + 3);
  v4 = sub_805B8D0(v34, (int)&v36);
  _EDX = v36 - 12;
  if ( v36 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v15 = _EAX;
    }
    else
    {
      v15 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v15 - 1;
    }
    if ( v15 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v72);
  }
  if ( v4 < 0 || (v7 = *(_DWORD *)(v34 + 4) + (v4 << 7), *(_DWORD *)(v7 + 68) == -1) )
  {
    v10 = *(v6 + 7);
    if ( v10 != 1 && v10 )
      goto LABEL_7;
    goto LABEL_12;
  }
  v8 = *(v6 + 7);
  if ( v8 != 2 )
  {
    if ( v8 == 3 && !*(_BYTE *)(v7 + 93) )
      goto LABEL_7;
LABEL_12:
    sub_8051180((int)&v37);
    std__string__assign(&v38, v5);
    v39 = -1414812757;
    v40 = -1414812757;
    v11 = *(v6 + 7);
    if ( v11 == 1 )
    {
      v12 = (int)&v44;
      sub_8051230((int)&v44);
      std__string__assign(&v45, v6 + 4);
      v44 = 3;
      v18 = *((_WORD *)v6 + 16);
      v46 = 1;
      v47 = v18;
      sub_8055740(v19, v20, (int)&v44, (int)&v48);
    }
    else
    {
      if ( v11 <= 1 )
      {
        if ( v11 )
          goto LABEL_16;
        v12 = (int)&v44;
        sub_8051230((int)&v44);
        std__string__assign(&v45, v6 + 4);
        v44 = 0;
        v24 = *((_WORD *)v6 + 16);
        v46 = 1;
        v47 = v24;
        sub_8055740(v25, v26, (int)&v44, (int)&v48);
      }
      else
      {
        if ( v11 != 2 )
        {
          if ( v11 == 3 )
            goto LABEL_23;
          goto LABEL_16;
        }
        v12 = (int)&v44;
        sub_8051230((int)&v44);
        std__string__assign(&v45, v6 + 4);
        v44 = 2;
        v21 = *((_WORD *)v6 + 16);
        v46 = 1;
        v47 = v21;
        sub_8055740(v22, v23, (int)&v44, (int)&v48);
      }
    }
    sub_8054840(v12);
    goto LABEL_16;
  }
  if ( *(_BYTE *)(v7 + 94) )
    goto LABEL_12;
LABEL_7:
  v4 = 0;
  while ( 1 )
  {
    result = v4;
    if ( !(*MK_FP(__GS__, 20) ^ v33) )
      break;
    __stack_chk_fail();
LABEL_23:
    sub_80515E0((int)&v49);
    v50 = 1225999881;
    v51 = -787382452;
    v52 = 1225999881;
    v53 = 1162093186;
    v54 = -787382452;
    v55 = 21587;
    v56 = 1162093186;
    v57 = 0;
    v58 = 1499027801;
    v59 = 1499027801;
    v60 = 21587;
    v61 = 16777343;
    v62 = 8716;
    v63 = 8;
    v64 = 1;
    v65 = 0;
    v66 = 0;
    v67 = 1;
    std__string__assign(&v68, v6 + 4);
    v69 = *(v6 + 5);
    v70 = *(v6 + 6);
    if ( *(_BYTE *)(*(_DWORD *)(v34 + 4) + (v4 << 7) + 94) )
      std__string__assign(&v71, "{0946134E-4C7F-11D1-8222-444553540000}");
    else
      std__string__assign(&v71, "{09461349-4C7F-11D1-8222-444553540000}");
    v46 = 2;
    sub_8056300(v14, v13, (int)&v49, (int)&v48);
    sub_80545E0((int)&v49);
LABEL_16:
    v6 = &v41;
    v41 = 0;
    v42 = 0;
    v43 = 0;
    LOWORD(v40) = v35;
    sub_8052B90((int)&v37, (int)&v41, 0);
    v4 = v42 - v41;
    sub_8056790((int)&v41, v42 - v41 + 4, 0);
    *(_BYTE *)(v41 + v4) = 0;
    *(_BYTE *)(v41 + v4 + 1) = 3;
    *(_BYTE *)(v41 + v4 + 2) = 0;
    *(_BYTE *)(v41 + v4 + 3) = 0;
    LOBYTE(v4) = sub_805A180(v34, 4, 6, 0, (int)&v41) == 1;
    sub_8056490(v16, v17, (int)&v41);
    sub_8053F10(v16, v17, (int)&v37);
  }
  return result;
}

//----- (08064400) --------------------------------------------------------
signed int __cdecl sub_8064400(int a1, int a2)
{
  signed int v2; // ebx@1
  int v3; // edi@1
  int v4; // esi@1
  signed int result; // eax@2
  int v6; // edx@4
  int v7; // ecx@4
  __int16 v8; // ax@9
  unsigned __int16 v9; // ax@12
  __int16 v10; // bx@12
  int v11; // eax@12
  int v12; // eax@12
  int (__cdecl *v13)(_DWORD, _DWORD); // esi@14
  int v14; // ecx@14
  int v15; // [sp+17Ch] [bp-10h]@1
  __int16 v16; // [sp+104h] [bp-88h]@4
  int v17; // [sp+108h] [bp-84h]@8
  int v18; // [sp+10Ch] [bp-80h]@8
  __int16 v19; // [sp+128h] [bp-64h]@9
  int v20; // [sp+120h] [bp-6Ch]@12
  int v21; // [sp+F8h] [bp-94h]@12
  __int16 v22; // [sp+126h] [bp-66h]@12
  int v23; // [sp+ECh] [bp-A0h]@12
  int v24; // [sp+E8h] [bp-A4h]@12
  int v25; // [sp+E4h] [bp-A8h]@12
  int v26; // [sp+E0h] [bp-ACh]@12
  int v27; // [sp+D8h] [bp-B4h]@12
  int v28; // [sp+DCh] [bp-B0h]@12
  __int16 v29; // [sp+124h] [bp-68h]@12
  char v30; // [sp+11Ch] [bp-70h]@14
  char v31; // [sp+12Bh] [bp-61h]@14
  char v32; // [sp+24h] [bp-168h]@14
  char v33; // [sp+114h] [bp-78h]@14
  char v34; // [sp+118h] [bp-74h]@14
  signed int v35; // [sp+160h] [bp-2Ch]@14
  signed int v36; // [sp+164h] [bp-28h]@14
  signed int v37; // [sp+16Ch] [bp-20h]@14
  signed int v38; // [sp+170h] [bp-1Ch]@14
  __int16 v39; // [sp+174h] [bp-18h]@14
  int v40; // [sp+168h] [bp-24h]@14
  char v41; // [sp+176h] [bp-16h]@14
  time_t v42; // [sp+178h] [bp-14h]@14
  char v43; // [sp+12Ch] [bp-60h]@14
  char v44; // [sp+154h] [bp-38h]@14

  v4 = a2;
  v3 = a1;
  v2 = 0;
  v15 = *MK_FP(__GS__, 20);
  if ( *(_DWORD *)(a2 + 8) == *(_DWORD *)(a1 + 160) )
  {
    sub_8050F60((int)&v16);
    if ( !(unsigned __int8)sub_80516C0((int)&v16, v4 + 12, 0)
      || v16 != 1
      || (v7 = v17, v6 = v18 - v17, (unsigned int)(v18 - v17) <= 9) )
      goto LABEL_6;
    v8 = *(_WORD *)(v17 + 6);
    v19 = *(_WORD *)(v17 + 6);
    if ( v8 == 66 )
      goto LABEL_16;
    if ( v8 != 65
      || (unsigned int)v6 <= 0x18
      || (v20 = *(_DWORD *)(v17 + 10), v11 = *(_WORD *)(v17 + 14), v21 = 0, v22 = v11, v23 = v11 - 1900, v24 = *(_BYTE *)(v17 + 16) - 1, v25 = *(_BYTE *)(v17 + 17), v26 = *(_BYTE *)(v17 + 18), v12 = *(_BYTE *)(v17 + 19), v27 = 0, v28 = v12, v9 = *(_WORD *)(v17 + 22), v10 = *(_WORD *)(v17 + 22), v29 = *(_WORD *)(v17 + 22), (unsigned int)v9 + 24 > v6)
      || !v10 )
      goto LABEL_6;
    std__string__string(&v30, v17 + 24, v9 - 1, &v31);
    std__basic_ostringstream_char_std__char_traits_char__std__allocator_char____basic_ostringstream(&v32, 16);
    std__ostream___M_insert_unsigned_long_(&v32, v20);
    std__string__string(&v33, &v30);
    std__basic_ostringstream_char_std__char_traits_char__std__allocator_char____str(&v34, &v32);
    v35 = 134771820;
    v36 = 134771820;
    std__string__assign(&v35, &v34);
    std__string__assign(&v36, &v33);
    v37 = -1;
    v38 = 1;
    v39 = 0;
    v40 = 0;
    BYTE3(v37) = 0;
    v41 = 1;
    std__string___string(&v34);
    std__string___string(&v33);
    v42 = mktime((struct tm *)&v27);
    v13 = *(int (__cdecl **)(_DWORD, _DWORD))(*(_DWORD *)v3 + 16);
    sub_8077A10((int)&v43, (int)&v44);
    v13(v3, &v43);
    sub_80500E0((int)&v43);
    sub_80500E0((int)&v44);
    std__basic_ostringstream_char_std__char_traits_char__std__allocator_char_____basic_ostringstream(&v32);
    std__string___string(&v30);
    v2 = 1;
    sub_8052370(v14, (int)&v16, (int)&v16);
  }
  while ( 1 )
  {
    result = v2;
    if ( !(*MK_FP(__GS__, 20) ^ v15) )
      break;
    __stack_chk_fail();
LABEL_16:
    v2 = 1;
    if ( !(unsigned __int8)sub_805C750(v7, v6, v3, 0x3Eu, v3 + 160) )
LABEL_6:
      v2 = 0;
    sub_8052370(v7, v6, (int)&v16);
  }
  return result;
}

//----- (08064780) --------------------------------------------------------
signed int __cdecl sub_8064780(int a1)
{
  int v1; // ebx@5
  int v2; // edi@5
  int v3; // esi@7
  int v5; // ecx@9
  int v6; // esi@10
  int v7; // ebx@12
  int v8; // edi@12
  int v9; // edx@16
  int v10; // ecx@16
  int v11; // edx@19
  int v12; // ecx@19
  int v13; // edx@22
  int v14; // ecx@22
  int v15; // edx@25
  int v16; // ecx@25
  int v18; // edx@30
  int v19; // ecx@30
  int v20; // eax@7
  int v21; // ebx@7
  size_t v22; // ebx@7
  __int16 v23; // ax@12
  int v24; // eax@14
  int v25; // ebx@14
  size_t v26; // ebx@14
  unsigned int v27; // ebx@22
  int v28; // eax@22
  int v29; // edx@22
  int v30; // ecx@22
  int v31; // eax@22
  unsigned int v38; // [sp+18h] [bp-70h]@3
  int v39; // [sp+30h] [bp-58h]@4
  int v40; // [sp+50h] [bp-38h]@5
  const void *v41; // [sp+4Ch] [bp-3Ch]@5
  __int16 v42; // [sp+48h] [bp-40h]@8
  int v43; // [sp+14h] [bp-74h]@8
  int v44; // [sp+74h] [bp-14h]@9
  char v45; // [sp+7Bh] [bp-Dh]@9
  const void *v46; // [sp+3Ch] [bp-4Ch]@9
  int v47; // [sp+40h] [bp-48h]@9
  int v48; // [sp+44h] [bp-44h]@9
  char v49; // [sp+70h] [bp-18h]@9
  __int16 v50; // [sp+38h] [bp-50h]@9
  int v51; // [sp+34h] [bp-54h]@10
  int v52; // [sp+58h] [bp-30h]@16
  int v53; // [sp+5Ch] [bp-2Ch]@16
  int v54; // [sp+60h] [bp-28h]@16
  char v55; // [sp+1Ch] [bp-6Ch]@16
  int v56; // [sp+64h] [bp-24h]@19
  char v57; // [sp+20h] [bp-68h]@22
  int v58; // [sp+68h] [bp-20h]@22
  int v59; // [sp+6Ch] [bp-1Ch]@22
  __int16 v60; // [sp+24h] [bp-64h]@22
  __int16 v61; // [sp+28h] [bp-60h]@22
  __int16 v62; // [sp+26h] [bp-62h]@22
  int v63; // [sp+54h] [bp-34h]@22
  char v64; // [sp+2Ch] [bp-5Ch]@23
  char v65; // [sp+7Ah] [bp-Eh]@37

  if ( !sub_805A310(a1) )
    return 0;
  if ( !((*(_DWORD *)(a1 + 32) - *(_DWORD *)(a1 + 28)) >> 7) )
  {
LABEL_25:
    if ( sub_805A2D0(a1) )
    {
      sub_807B980(v16, v15, a1 + 28);
      return 1;
    }
    return 0;
  }
  v38 = 0;
  while ( 1 )
  {
    sub_80512C0((int)&v55);
    v27 = v38 << 7;
    std__string__assign(&v57, *(_DWORD *)(a1 + 28) + (v38 << 7));
    v56 = 0;
    v58 = 0;
    v59 = 0;
    v28 = *(_DWORD *)(a1 + 28);
    v29 = *(_WORD *)(v28 + (v38 << 7) + 8);
    v60 = *(_WORD *)(v28 + (v38 << 7) + 8);
    LOWORD(v28) = *(_WORD *)(v28 + (v38 << 7) + 16);
    v61 = 20;
    v62 = v28;
    v31 = operator new(v30, v13);
    v56 = v31;
    v59 = v31 + 2;
    *(_WORD *)v31 = 0;
    v58 = v59;
    *(_BYTE *)v56 = *(_BYTE *)(*(_DWORD *)(a1 + 28) + v27 + 36);
    *(_BYTE *)(v56 + 1) = 16;
    sub_8078660(&v56, v58, *(_DWORD *)(a1 + 28) + v27 + 37, *(_DWORD *)(a1 + 28) + v27 + 53);
    v41 = 0;
    v40 = 0;
    v63 = 0;
    sub_804B500(v14, (int)&v56, (int)&v41, (int)&v56);
    v3 = v39;
    v42 = 213;
    if ( v39 != v51 )
    {
      if ( v39 )
      {
        v2 = 0;
        v1 = v40 - (_DWORD)v41;
        *(_WORD *)v39 = 213;
        *(_DWORD *)(v39 + 4) = 0;
        *(_DWORD *)(v39 + 8) = 0;
        *(_DWORD *)(v39 + 12) = 0;
        if ( v1 )
          v2 = operator new(v14, v13);
        v20 = v2 + v1;
        *(_DWORD *)(v3 + 4) = v2;
        *(_DWORD *)(v3 + 8) = v2;
        v21 = v40;
        *(_DWORD *)(v3 + 12) = v20;
        v22 = v21 - (_DWORD)v41;
        memmove((void *)v2, v41, v22);
        *(_DWORD *)(v3 + 8) = v2 + v22;
        v3 = v39;
      }
      v39 = v3 + 16;
      v43 = (int)&v42;
    }
    else
    {
      v43 = (int)&v42;
      sub_8057B40(v14, v13, (int)&v64, v39, (int)&v42);
    }
    std__string__string(&v44, &aResNr[13], &v45);
    v46 = 0;
    v47 = 0;
    v48 = 0;
    std__string__string(&v49, &v44);
    sub_8051C40((int)&v50, (int)&v49);
    std__string___string(&v49);
    v50 = 305;
    _EDX = v44 - 12;
    if ( v44 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
    {
      if ( pthread_cancel )
      {
        _EAX = -1;
        __asm { lock xadd [edx+8], eax }
        v5 = _EAX;
      }
      else
      {
        v5 = *(_DWORD *)(_EDX + 8);
        *(_DWORD *)(_EDX + 8) = v5 - 1;
      }
      if ( v5 <= 0 )
        std__string___Rep___M_destroy(_EDX, &v65);
    }
    v6 = v39;
    if ( v39 == v51 )
    {
      sub_8057B40(v5, _EDX, (int)&v64, v39, (int)&v50);
    }
    else
    {
      if ( v39 )
      {
        v8 = 0;
        v7 = v47 - (_DWORD)v46;
        v23 = v50;
        *(_DWORD *)(v39 + 4) = 0;
        *(_DWORD *)(v39 + 8) = 0;
        *(_WORD *)v39 = v23;
        *(_DWORD *)(v39 + 12) = 0;
        if ( v7 )
          v8 = operator new(v5, _EDX);
        v24 = v8 + v7;
        *(_DWORD *)(v6 + 4) = v8;
        *(_DWORD *)(v6 + 8) = v8;
        v25 = v47;
        *(_DWORD *)(v6 + 12) = v24;
        v26 = v25 - (_DWORD)v46;
        memmove((void *)v8, v46, v26);
        *(_DWORD *)(v6 + 8) = v8 + v26;
        v6 = v39;
      }
      v39 = v6 + 16;
    }
    v52 = 0;
    v53 = 0;
    v54 = 0;
    sub_8053310((int)&v55, (int)&v52, 0);
    if ( sub_805A180(a1, 19, 10, 0, (int)&v52) != 1 )
      break;
    if ( v52 )
      operator delete(v10, v9);
    sub_8052370(v10, (int)&v50, (int)&v50);
    sub_8052370(v12, v11, v43);
    if ( v56 )
      operator delete(v12, v11);
    sub_80549C0(v12, v11, (int)&v55);
    ++v38;
    if ( v38 >= (*(_DWORD *)(a1 + 32) - *(_DWORD *)(a1 + 28)) >> 7 )
      goto LABEL_25;
  }
  if ( v52 )
    operator delete(v10, v9);
  sub_8052370(v10, v9, (int)&v50);
  sub_8052370(v19, v43, v43);
  if ( v56 )
    operator delete(v19, v18);
  sub_80549C0(v19, (int)&v55, (int)&v55);
  return 0;
}

//----- (08064C80) --------------------------------------------------------
signed int __cdecl sub_8064C80(int a1, int a2)
{
  int v2; // ebx@1
  int v3; // eax@6
  int v4; // edx@6
  int v5; // edi@6
  int v6; // edx@8
  int v7; // ecx@8
  unsigned int v8; // ebx@9
  int v10; // ecx@11
  signed int v11; // esi@11
  signed int v12; // ebx@16
  int v14; // eax@1
  int v15; // eax@6
  int v22; // [sp+38h] [bp-20h]@1
  int v23; // [sp+3Ch] [bp-1Ch]@1
  int v24; // [sp+40h] [bp-18h]@1
  int v25; // [sp+18h] [bp-40h]@1
  int v26; // [sp+20h] [bp-38h]@2
  unsigned int v27; // [sp+24h] [bp-34h]@2
  char v28; // [sp+4Bh] [bp-Dh]@6
  int v29; // [sp+1Ch] [bp-3Ch]@9
  int v30; // [sp+44h] [bp-14h]@11
  char v31; // [sp+28h] [bp-30h]@14
  char v32; // [sp+4Ah] [bp-Eh]@24

  v22 = 0;
  v23 = 0;
  v2 = *(_DWORD *)a2;
  v14 = *(_DWORD *)(a2 + 4);
  v24 = 0;
  v25 = (int)&v22;
  if ( (v14 - v2) >> 2 )
  {
    v26 = 0;
    v27 = 0;
    v25 = (int)&v22;
    while ( 1 )
    {
      v4 = v22;
      v5 = 4 * v27;
      v15 = *(_DWORD *)(*(_DWORD *)(v2 + 4 * v27) - 12);
      v28 = 0;
      v3 = v26 + v15 + 1;
      if ( v3 < (unsigned int)(v23 - v22) )
      {
        v23 = v22 + v3;
      }
      else
      {
        sub_8056580(v25, v23, v3 - (v23 - v22), &v28);
        v4 = v22;
        v2 = *(_DWORD *)a2;
      }
      *(_BYTE *)(v4 + v26) = *(_DWORD *)(*(_DWORD *)(v2 + v5) - 12);
      memcpy(
        (void *)(v22 + v26 + 1),
        *(const void **)(*(_DWORD *)a2 + v5),
        *(_DWORD *)(*(_DWORD *)(*(_DWORD *)a2 + v5) - 12));
      ++v27;
      v2 = *(_DWORD *)a2;
      if ( v27 >= (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 2 )
        break;
      v26 += *(_DWORD *)(*(_DWORD *)(*(_DWORD *)a2 + v5) - 12) + 1;
    }
  }
  if ( sub_805A180(a1, 3, 5, 0, v25) == 1 )
  {
    v8 = 0;
    v29 = a1 + 4;
    while ( 1 )
    {
      v7 = a2;
      v6 = *(_DWORD *)a2;
      if ( v8 >= (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 2 )
        break;
      std__string__string(&v30, v6 + 4 * v8);
      v11 = sub_805B8D0(a1, (int)&v30);
      _EDX = v30 - 12;
      if ( v30 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
      {
        if ( pthread_cancel )
        {
          _EAX = -1;
          __asm { lock xadd [edx+8], eax }
          v10 = _EAX;
        }
        else
        {
          v10 = *(_DWORD *)(_EDX + 8);
          *(_DWORD *)(_EDX + 8) = v10 - 1;
        }
        if ( v10 <= 0 )
          std__string___Rep___M_destroy(_EDX, &v32);
      }
      if ( v11 >= 0 && *(_BYTE *)(*(_DWORD *)(a1 + 4) + (v11 << 7) + 92) )
        sub_807BA10(v10, v29, (int)&v31, v29, *(_DWORD *)(a1 + 4) + (v11 << 7));
      else
        ++v8;
    }
    v12 = 1;
  }
  else
  {
    v12 = 0;
  }
  if ( v22 )
    operator delete(v7, v6);
  return v12;
}

//----- (08064FC0) --------------------------------------------------------
signed int __usercall sub_8064FC0<eax>(int a1<edi>, unsigned int a2<esi>, int a3, int a4)
{
  int v4; // ebx@1
  int v5; // eax@6
  int v6; // edx@6
  int v7; // edx@8
  int v8; // ecx@8
  signed int v10; // ebx@12
  int v11; // eax@14
  int v12; // edx@17
  signed int result; // eax@22
  int v14; // eax@1
  int v15; // eax@6
  int v22; // [sp+C8h] [bp-10h]@1
  int v23; // [sp+34h] [bp-A4h]@1
  int v24; // [sp+1Ch] [bp-BCh]@1
  int v25; // [sp+18h] [bp-C0h]@1
  int v26; // [sp+38h] [bp-A0h]@1
  int v27; // [sp+3Ch] [bp-9Ch]@1
  int v28; // [sp+14h] [bp-C4h]@1
  int v29; // [sp+24h] [bp-B4h]@2
  unsigned int v30; // [sp+28h] [bp-B0h]@2
  char v31; // [sp+47h] [bp-91h]@6
  int v32; // [sp+20h] [bp-B8h]@10
  int v33; // [sp+40h] [bp-98h]@12
  signed int v34; // [sp+48h] [bp-90h]@14
  signed int v35; // [sp+4Ch] [bp-8Ch]@14
  signed int v36; // [sp+54h] [bp-84h]@14
  int v37; // [sp+80h] [bp-58h]@14
  int v38; // [sp+84h] [bp-54h]@14
  int v39; // [sp+88h] [bp-50h]@14
  signed int v40; // [sp+9Ch] [bp-3Ch]@14
  signed int v41; // [sp+A0h] [bp-38h]@14
  signed int v42; // [sp+A8h] [bp-30h]@14
  signed int v43; // [sp+ACh] [bp-2Ch]@14
  signed int v44; // [sp+B0h] [bp-28h]@14
  signed int v45; // [sp+B4h] [bp-24h]@14
  signed int v46; // [sp+B8h] [bp-20h]@14
  __int16 v47; // [sp+50h] [bp-88h]@14
  __int16 v48; // [sp+58h] [bp-80h]@14
  char v49; // [sp+5Ah] [bp-7Eh]@14
  int v50; // [sp+5Ch] [bp-7Ch]@14
  int v51; // [sp+60h] [bp-78h]@14
  int v52; // [sp+64h] [bp-74h]@14
  char v53; // [sp+68h] [bp-70h]@14
  __int16 v54; // [sp+6Ah] [bp-6Eh]@14
  char v55; // [sp+6Ch] [bp-6Ch]@14
  int v56; // [sp+6Dh] [bp-6Bh]@14
  int v57; // [sp+71h] [bp-67h]@14
  int v58; // [sp+75h] [bp-63h]@14
  int v59; // [sp+79h] [bp-5Fh]@14
  signed int v60; // [sp+8Ch] [bp-4Ch]@14
  int v61; // [sp+90h] [bp-48h]@14
  char v62; // [sp+94h] [bp-44h]@14
  int v63; // [sp+98h] [bp-40h]@14
  char v64; // [sp+A4h] [bp-34h]@14
  char v65; // [sp+A5h] [bp-33h]@14
  char v66; // [sp+A6h] [bp-32h]@14
  int v67; // [sp+BCh] [bp-1Ch]@14
  int v68; // [sp+C0h] [bp-18h]@14
  char v69; // [sp+46h] [bp-92h]@29

  v22 = *MK_FP(__GS__, 20);
  v23 = 0;
  v4 = *(_DWORD *)a4;
  v24 = a3;
  v14 = *(_DWORD *)(a4 + 4);
  v25 = a4;
  v26 = 0;
  v27 = 0;
  v28 = (int)&v23;
  if ( (v14 - v4) >> 2 )
  {
    v29 = 0;
    v30 = 0;
    v28 = (int)&v23;
    while ( 1 )
    {
      a2 = v26;
      v6 = v23;
      a1 = 4 * v30;
      v15 = *(_DWORD *)(*(_DWORD *)(v4 + 4 * v30) - 12);
      v31 = 0;
      v5 = v29 + v15 + 1;
      if ( v5 < (unsigned int)(v26 - v23) )
      {
        v26 = v23 + v5;
      }
      else
      {
        sub_8056580(v28, v26, v5 - (v26 - v23), &v31);
        v6 = v23;
        v4 = *(_DWORD *)v25;
      }
      *(_BYTE *)(v6 + v29) = *(_DWORD *)(*(_DWORD *)(v4 + a1) - 12);
      memcpy(
        (void *)(v23 + v29 + 1),
        *(const void **)(*(_DWORD *)v25 + a1),
        *(_DWORD *)(*(_DWORD *)(*(_DWORD *)v25 + a1) - 12));
      ++v30;
      v4 = *(_DWORD *)v25;
      if ( v30 >= (*(_DWORD *)(v25 + 4) - *(_DWORD *)v25) >> 2 )
        break;
      v29 += *(_DWORD *)(*(_DWORD *)(*(_DWORD *)v25 + a1) - 12) + 1;
    }
  }
  if ( sub_805A180(v24, 3, 15, 0, v28) != 1 )
  {
    v10 = 0;
    goto LABEL_20;
  }
  v7 = *(_DWORD *)v25;
  if ( !((*(_DWORD *)(v25 + 4) - *(_DWORD *)v25) >> 2) )
    goto LABEL_19;
  a2 = 0;
  v32 = v24 + 4;
  do
  {
    a1 = 4 * a2;
    std__string__string(&v33, v7 + 4 * a2);
    v10 = sub_805B8D0(v24, (int)&v33);
    _EDX = v33 - 12;
    if ( v33 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
    {
      if ( !pthread_cancel )
        goto LABEL_31;
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v8 = _EAX;
LABEL_28:
      if ( v8 <= 0 )
        std__string___Rep___M_destroy(_EDX, &v69);
    }
    if ( v10 < 0 )
    {
      v34 = 134771820;
      v35 = 134771820;
      v36 = 134771820;
      v37 = 0;
      v38 = 0;
      v39 = 0;
      v40 = 134771820;
      v41 = 134771820;
      v42 = 134771820;
      v43 = 134771820;
      v44 = 134771820;
      v45 = 134771820;
      v46 = 134771820;
      v47 = 0;
      v48 = 0;
      v49 = 0;
      v50 = 0;
      v51 = 0;
      v52 = 0;
      v53 = 0;
      v54 = 0;
      v55 = 0;
      v56 = 0;
      v57 = 0;
      v58 = 0;
      v59 = 0;
      v60 = -1;
      v61 = 0;
      v62 = 0;
      v63 = 0;
      v64 = 0;
      v65 = 0;
      v66 = 0;
      v67 = 0;
      v68 = 0;
      a1 += *(_DWORD *)v25;
      std__string__assign(&v34, a1);
      v64 = 1;
      v11 = *(_DWORD *)(v24 + 8);
      if ( v11 == *(_DWORD *)(v24 + 12) )
      {
        sub_807BC40(v32, *(_DWORD *)(v24 + 8), (int)&v34);
      }
      else
      {
        if ( v11 )
        {
          sub_8078C30(v11, (int)&v34);
          v11 = *(_DWORD *)(v24 + 8);
        }
        v12 = v24;
        *(_DWORD *)(v24 + 8) = v11 + 128;
      }
      sub_807B640((int)&v34, v12, (int)&v34);
    }
    ++a2;
    v7 = *(_DWORD *)v25;
  }
  while ( a2 < (*(_DWORD *)(v25 + 4) - *(_DWORD *)v25) >> 2 );
LABEL_19:
  v10 = 1;
LABEL_20:
  if ( v23 )
    operator delete(v8, v7);
  result = v10;
  if ( *MK_FP(__GS__, 20) ^ v22 )
  {
    __stack_chk_fail();
LABEL_31:
    v8 = *(_DWORD *)(_EDX + 8);
    *(_DWORD *)(_EDX + 8) = v8 - 1;
    goto LABEL_28;
  }
  return result;
}

//----- (08065430) --------------------------------------------------------
signed int __usercall sub_8065430<eax>(int a1<edx>, int a2<ecx>, int a3<edi>, unsigned int a4<esi>, int a5, int a6)
{
  int v6; // eax@1
  int v7; // edx@3
  int v8; // ecx@3
  int v9; // ebx@3
  signed int v10; // edi@3
  int v11; // esi@3
  signed int v13; // eax@3
  int v14; // [sp+20h] [bp-18h]@1
  int v15; // [sp+24h] [bp-14h]@1
  int v16; // [sp+28h] [bp-10h]@1

  v6 = operator new(a2, a1);
  v14 = v6;
  v15 = v6;
  v16 = v6 + 4;
  if ( v6 )
    std__string__string(v6, a6);
  v15 = v16;
  v13 = sub_8064FC0(a3, a4, a5, (int)&v14);
  v11 = v15;
  v10 = v13;
  v9 = v14;
  if ( v15 != v14 )
  {
    do
    {
      std__string___string(v9);
      v9 += 4;
    }
    while ( v11 != v9 );
    v11 = v14;
  }
  if ( v11 )
    operator delete(v8, v7);
  return v10;
}

//----- (08065530) --------------------------------------------------------
int __cdecl sub_8065530(int a1, int a2, int a3, char a4)
{
  int v5; // ebx@1
  int v8; // ecx@5
  int v9; // ecx@9
  char v10; // si@1
  int v11; // ecx@1
  int v12; // edx@1
  int v13; // eax@1
  int v26; // [sp+20h] [bp-18h]@1
  int v27; // [sp+24h] [bp-14h]@1
  char v28; // [sp+2Bh] [bp-Dh]@7
  char v29; // [sp+2Ah] [bp-Eh]@11

  v10 = a4;
  std__string__string(&v26, a3);
  std__string__string(&v27, a2);
  LOBYTE(v13) = sub_805BB80(v11, v12, a1, (const void **)&v27, (const void **)&v26, v10);
  v5 = v13;
  _EDX = v27 - 12;
  if ( v27 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v8 = _EAX;
    }
    else
    {
      v8 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v8 - 1;
    }
    if ( v8 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v28);
  }
  _EDX = v26 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v26 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v9 = _EAX;
    }
    else
    {
      v9 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v9 - 1;
    }
    if ( v9 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v29);
  }
  return v5;
}

//----- (08066B30) --------------------------------------------------------
int __cdecl sub_8066B30(int a1)
{
  int v1; // edx@1
  int v2; // ebx@1
  int v3; // edx@3
  int v4; // ecx@3
  int v5; // esi@3
  int v6; // ebx@5
  int v7; // edi@5
  int v9; // edx@10
  int v10; // ecx@10
  int v11; // esi@10
  int v12; // ebx@12
  int v13; // edi@12
  int v16; // edx@18
  int v17; // ecx@18
  int v18; // esi@18
  int v19; // ebx@20
  int v20; // edi@20
  int v22; // edx@25
  int v23; // ecx@25
  int v24; // esi@25
  int v25; // ebx@27
  int v26; // edi@27
  int v27; // edx@31
  int v28; // ecx@31
  int v29; // esi@31
  int v30; // ebx@33
  int v31; // edi@33
  int v32; // edx@37
  int v33; // ecx@37
  int v34; // esi@37
  int v35; // ebx@39
  int v36; // edi@39
  int v37; // edx@43
  int v38; // ecx@43
  int v39; // esi@43
  int v40; // ebx@45
  int v41; // edi@45
  int v42; // edx@49
  int v43; // ecx@49
  int v44; // esi@49
  int v45; // ebx@51
  int v46; // edi@51
  int v47; // edx@55
  int v48; // ecx@55
  int v49; // esi@55
  int v50; // ebx@57
  int v51; // edi@57
  int v52; // edx@61
  int v53; // ecx@61
  int v54; // esi@61
  int v55; // ebx@63
  int v56; // edi@63
  int v57; // edx@67
  int v58; // ecx@67
  int v59; // esi@67
  int v60; // ebx@69
  int v61; // edi@69
  int v62; // edx@73
  const void *v63; // edi@73
  int v64; // esi@73
  int v65; // edx@75
  int v66; // ecx@75
  int v67; // ebx@75
  int v69; // ecx@92
  int v70; // ecx@96
  int v71; // ecx@100
  int v72; // ecx@104
  __int16 v73; // ax@1
  int v74; // eax@7
  int v75; // ebx@7
  size_t v76; // ebx@7
  int v77; // eax@14
  int v78; // ebx@14
  size_t v79; // ebx@14
  int v80; // eax@22
  int v81; // ebx@22
  size_t v82; // ebx@22
  int v83; // eax@29
  int v84; // ebx@29
  size_t v85; // ebx@29
  int v86; // eax@35
  int v87; // ebx@35
  size_t v88; // ebx@35
  int v89; // eax@41
  int v90; // ebx@41
  size_t v91; // ebx@41
  int v92; // eax@47
  int v93; // ebx@47
  size_t v94; // ebx@47
  int v95; // eax@53
  int v96; // ebx@53
  size_t v97; // ebx@53
  int v98; // eax@59
  int v99; // ebx@59
  size_t v100; // ebx@59
  int v101; // eax@65
  int v102; // ebx@65
  size_t v103; // ebx@65
  int v104; // eax@71
  int v105; // ebx@71
  size_t v106; // ebx@71
  int v107; // eax@75
  int v108; // ecx@77
  char v133; // [sp+ECh] [bp-5Ch]@1
  char v134; // [sp+28h] [bp-120h]@1
  int v135; // [sp+30h] [bp-118h]@1
  int v136; // [sp+2Ch] [bp-11Ch]@1
  __int16 v137; // [sp+2Ah] [bp-11Eh]@1
  char v138; // [sp+134h] [bp-14h]@1
  int v139; // [sp+130h] [bp-18h]@3
  const void *v140; // [sp+E0h] [bp-68h]@3
  int v141; // [sp+E4h] [bp-64h]@3
  int v142; // [sp+E8h] [bp-60h]@3
  char v143; // [sp+118h] [bp-30h]@3
  __int16 v144; // [sp+DCh] [bp-6Ch]@3
  int v145; // [sp+F4h] [bp-54h]@3
  int v146; // [sp+F8h] [bp-50h]@3
  int v147; // [sp+12Ch] [bp-1Ch]@10
  int v148; // [sp+128h] [bp-20h]@10
  const void *v149; // [sp+D0h] [bp-78h]@10
  int v150; // [sp+D4h] [bp-74h]@10
  int v151; // [sp+D8h] [bp-70h]@10
  char v152; // [sp+114h] [bp-34h]@10
  __int16 v153; // [sp+CCh] [bp-7Ch]@10
  int v154; // [sp+124h] [bp-24h]@18
  char v155; // [sp+13Bh] [bp-Dh]@18
  const void *v156; // [sp+C0h] [bp-88h]@18
  int v157; // [sp+C4h] [bp-84h]@18
  int v158; // [sp+C8h] [bp-80h]@18
  char v159; // [sp+110h] [bp-38h]@18
  __int16 v160; // [sp+BCh] [bp-8Ch]@18
  const void *v161; // [sp+B0h] [bp-98h]@25
  int v162; // [sp+B4h] [bp-94h]@25
  int v163; // [sp+B8h] [bp-90h]@25
  __int16 v164; // [sp+ACh] [bp-9Ch]@25
  const void *v165; // [sp+A0h] [bp-A8h]@31
  int v166; // [sp+A4h] [bp-A4h]@31
  int v167; // [sp+A8h] [bp-A0h]@31
  __int16 v168; // [sp+9Ch] [bp-ACh]@31
  const void *v169; // [sp+90h] [bp-B8h]@37
  int v170; // [sp+94h] [bp-B4h]@37
  int v171; // [sp+98h] [bp-B0h]@37
  __int16 v172; // [sp+8Ch] [bp-BCh]@37
  const void *v173; // [sp+80h] [bp-C8h]@43
  int v174; // [sp+84h] [bp-C4h]@43
  int v175; // [sp+88h] [bp-C0h]@43
  __int16 v176; // [sp+7Ch] [bp-CCh]@43
  const void *v177; // [sp+70h] [bp-D8h]@49
  int v178; // [sp+74h] [bp-D4h]@49
  int v179; // [sp+78h] [bp-D0h]@49
  __int16 v180; // [sp+6Ch] [bp-DCh]@49
  const void *v181; // [sp+60h] [bp-E8h]@55
  int v182; // [sp+64h] [bp-E4h]@55
  int v183; // [sp+68h] [bp-E0h]@55
  __int16 v184; // [sp+5Ch] [bp-ECh]@55
  char v185; // [sp+120h] [bp-28h]@61
  char v186; // [sp+13Ah] [bp-Eh]@61
  const void *v187; // [sp+50h] [bp-F8h]@61
  int v188; // [sp+54h] [bp-F4h]@61
  int v189; // [sp+58h] [bp-F0h]@61
  char v190; // [sp+10Ch] [bp-3Ch]@61
  __int16 v191; // [sp+4Ch] [bp-FCh]@61
  char v192; // [sp+11Ch] [bp-2Ch]@67
  char v193; // [sp+139h] [bp-Fh]@67
  const void *v194; // [sp+40h] [bp-108h]@67
  int v195; // [sp+44h] [bp-104h]@67
  int v196; // [sp+48h] [bp-100h]@67
  char v197; // [sp+108h] [bp-40h]@67
  __int16 v198; // [sp+3Ch] [bp-10Ch]@67
  const void *v199; // [sp+FCh] [bp-4Ch]@73
  int v200; // [sp+100h] [bp-48h]@73
  int v201; // [sp+104h] [bp-44h]@73
  int v202; // [sp+18h] [bp-130h]@73
  char v203; // [sp+F0h] [bp-58h]@80
  char v204; // [sp+138h] [bp-10h]@94
  char v205; // [sp+136h] [bp-12h]@98
  char v206; // [sp+137h] [bp-11h]@102
  char v207; // [sp+135h] [bp-13h]@106

  sub_8050FB0((int)&v133);
  sub_8050EE0((int)&v134);
  v134 = 1;
  v2 = v135;
  v1 = v136;
  v73 = *(_WORD *)(a1 + 168);
  v137 = *(_WORD *)(a1 + 168);
  *(_WORD *)(a1 + 168) = v73 + 1;
  v138 = 0;
  if ( (unsigned int)(v2 - v1) <= 4 )
  {
    sub_8056580(&v136, v2, 4 - (v2 - v1), &v138);
    v1 = v136;
  }
  else
  {
    v135 = v1 + 4;
  }
  *(_BYTE *)(v1 + 3) = 1;
  std__string__string(&v139, a1 + 124);
  v140 = 0;
  v141 = 0;
  v142 = 0;
  std__string__string(&v143, &v139);
  sub_8051C40((int)&v144, (int)&v143);
  std__string___string(&v143);
  v5 = v145;
  v144 = 1;
  if ( v145 == v146 )
  {
    sub_8057B40(v4, v3, (int)&v203, v145, (int)&v144);
  }
  else
  {
    if ( v145 )
    {
      v7 = 0;
      v6 = v141 - (_DWORD)v140;
      *(_WORD *)v145 = 1;
      *(_DWORD *)(v145 + 4) = 0;
      *(_DWORD *)(v145 + 8) = 0;
      *(_DWORD *)(v145 + 12) = 0;
      if ( v6 )
        v7 = operator new(v4, v3);
      v74 = v7 + v6;
      *(_DWORD *)(v5 + 4) = v7;
      *(_DWORD *)(v5 + 8) = v7;
      v75 = v141;
      *(_DWORD *)(v5 + 12) = v74;
      v76 = v75 - (_DWORD)v140;
      memmove((void *)v7, v140, v76);
      *(_DWORD *)(v5 + 8) = v7 + v76;
      v5 = v145;
    }
    v145 = v5 + 16;
  }
  sub_8052370((int)&v144, v3, (int)&v144);
  _EDX = v139 - 12;
  if ( v139 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v69 = _EAX;
    }
    else
    {
      v69 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v69 - 1;
    }
    if ( v69 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v204);
  }
  std__string__string(&v147, a1 + 148);
  sub_805B760((int)&v148, (int)&v147);
  v149 = 0;
  v150 = 0;
  v151 = 0;
  std__string__string(&v152, &v148);
  sub_8051C40((int)&v153, (int)&v152);
  std__string___string(&v152);
  v11 = v145;
  v153 = 2;
  if ( v145 == v146 )
  {
    sub_8057B40(v10, v9, (int)&v203, v145, (int)&v153);
  }
  else
  {
    if ( v145 )
    {
      v13 = 0;
      v12 = v150 - (_DWORD)v149;
      *(_WORD *)v145 = 2;
      *(_DWORD *)(v145 + 4) = 0;
      *(_DWORD *)(v145 + 8) = 0;
      *(_DWORD *)(v145 + 12) = 0;
      if ( v12 )
        v13 = operator new(v10, v9);
      v77 = v13 + v12;
      *(_DWORD *)(v11 + 4) = v13;
      *(_DWORD *)(v11 + 8) = v13;
      v78 = v150;
      *(_DWORD *)(v11 + 12) = v77;
      v79 = v78 - (_DWORD)v149;
      memmove((void *)v13, v149, v79);
      *(_DWORD *)(v11 + 8) = v13 + v79;
      v11 = v145;
    }
    v145 = v11 + 16;
  }
  sub_8052370((int)&v153, v9, (int)&v153);
  _EDX = v148 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v148 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v71 = _EAX;
    }
    else
    {
      v71 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v71 - 1;
    }
    if ( v71 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v206);
  }
  _EDX = v147 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v147 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v70 = _EAX;
    }
    else
    {
      v70 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v70 - 1;
    }
    if ( v70 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v205);
  }
  std__string__string(&v154, "ICQ Inc. - Product of ICQ (TM).2003b.5.56.1.3916.85", &v155);
  v156 = 0;
  v157 = 0;
  v158 = 0;
  std__string__string(&v159, &v154);
  sub_8051C40((int)&v160, (int)&v159);
  std__string___string(&v159);
  v18 = v145;
  v160 = 3;
  if ( v145 == v146 )
  {
    sub_8057B40(v17, v16, (int)&v203, v145, (int)&v160);
  }
  else
  {
    if ( v145 )
    {
      v20 = 0;
      v19 = v157 - (_DWORD)v156;
      *(_WORD *)v145 = 3;
      *(_DWORD *)(v145 + 4) = 0;
      *(_DWORD *)(v145 + 8) = 0;
      *(_DWORD *)(v145 + 12) = 0;
      if ( v19 )
        v20 = operator new(v17, v16);
      v80 = v20 + v19;
      *(_DWORD *)(v18 + 4) = v20;
      *(_DWORD *)(v18 + 8) = v20;
      v81 = v157;
      *(_DWORD *)(v18 + 12) = v80;
      v82 = v81 - (_DWORD)v156;
      memmove((void *)v20, v156, v82);
      *(_DWORD *)(v18 + 8) = v20 + v82;
      v18 = v145;
    }
    v145 = v18 + 16;
  }
  sub_8052370((int)&v160, v16, (int)&v160);
  _EDX = v154 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v154 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v72 = _EAX;
    }
    else
    {
      v72 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v72 - 1;
    }
    if ( v72 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v207);
  }
  v161 = 0;
  v162 = 0;
  v163 = 0;
  sub_80525A0((int)&v164, 266);
  v24 = v145;
  v164 = 22;
  if ( v145 == v146 )
  {
    sub_8057B40(v23, (int)&v164, (int)&v203, v145, (int)&v164);
  }
  else
  {
    if ( v145 )
    {
      v26 = 0;
      v25 = v162 - (_DWORD)v161;
      *(_WORD *)v145 = 22;
      *(_DWORD *)(v145 + 4) = 0;
      *(_DWORD *)(v145 + 8) = 0;
      *(_DWORD *)(v145 + 12) = 0;
      if ( v25 )
        v26 = operator new(v23, v22);
      v83 = v26 + v25;
      *(_DWORD *)(v24 + 4) = v26;
      *(_DWORD *)(v24 + 8) = v26;
      v84 = v162;
      *(_DWORD *)(v24 + 12) = v83;
      v85 = v84 - (_DWORD)v161;
      memmove((void *)v26, v161, v85);
      *(_DWORD *)(v24 + 8) = v26 + v85;
      v24 = v145;
    }
    v145 = v24 + 16;
  }
  sub_8052370(v23, v22, (int)&v164);
  v165 = 0;
  v166 = 0;
  v167 = 0;
  sub_80525A0((int)&v168, 5);
  v29 = v145;
  v168 = 23;
  if ( v145 == v146 )
  {
    sub_8057B40((int)&v168, v27, (int)&v203, v145, (int)&v168);
  }
  else
  {
    if ( v145 )
    {
      v31 = 0;
      v30 = v166 - (_DWORD)v165;
      *(_WORD *)v145 = 23;
      *(_DWORD *)(v145 + 4) = 0;
      *(_DWORD *)(v145 + 8) = 0;
      *(_DWORD *)(v145 + 12) = 0;
      if ( v30 )
        v31 = operator new(v28, v27);
      v86 = v31 + v30;
      *(_DWORD *)(v29 + 4) = v31;
      *(_DWORD *)(v29 + 8) = v31;
      v87 = v166;
      *(_DWORD *)(v29 + 12) = v86;
      v88 = v87 - (_DWORD)v165;
      memmove((void *)v31, v165, v88);
      *(_DWORD *)(v29 + 8) = v31 + v88;
      v29 = v145;
    }
    v145 = v29 + 16;
  }
  sub_8052370(v28, (int)&v168, (int)&v168);
  v169 = 0;
  v170 = 0;
  v171 = 0;
  sub_80525A0((int)&v172, 37);
  v34 = v145;
  v172 = 24;
  if ( v145 == v146 )
  {
    sub_8057B40(v33, v32, (int)&v203, v145, (int)&v172);
  }
  else
  {
    if ( v145 )
    {
      v36 = 0;
      v35 = v170 - (_DWORD)v169;
      *(_WORD *)v145 = 24;
      *(_DWORD *)(v145 + 4) = 0;
      *(_DWORD *)(v145 + 8) = 0;
      *(_DWORD *)(v145 + 12) = 0;
      if ( v35 )
        v36 = operator new(v33, v32);
      v89 = v36 + v35;
      *(_DWORD *)(v34 + 4) = v36;
      *(_DWORD *)(v34 + 8) = v36;
      v90 = v170;
      *(_DWORD *)(v34 + 12) = v89;
      v91 = v90 - (_DWORD)v169;
      memmove((void *)v36, v169, v91);
      *(_DWORD *)(v34 + 8) = v36 + v91;
      v34 = v145;
    }
    v145 = v34 + 16;
  }
  sub_8052370((int)&v172, v32, (int)&v172);
  v173 = 0;
  v174 = 0;
  v175 = 0;
  sub_80525A0((int)&v176, 1);
  v39 = v145;
  v176 = 25;
  if ( v145 == v146 )
  {
    sub_8057B40(v38, (int)&v176, (int)&v203, v145, (int)&v176);
  }
  else
  {
    if ( v145 )
    {
      v41 = 0;
      v40 = v174 - (_DWORD)v173;
      *(_WORD *)v145 = 25;
      *(_DWORD *)(v145 + 4) = 0;
      *(_DWORD *)(v145 + 8) = 0;
      *(_DWORD *)(v145 + 12) = 0;
      if ( v40 )
        v41 = operator new(v38, v37);
      v92 = v41 + v40;
      *(_DWORD *)(v39 + 4) = v41;
      *(_DWORD *)(v39 + 8) = v41;
      v93 = v174;
      *(_DWORD *)(v39 + 12) = v92;
      v94 = v93 - (_DWORD)v173;
      memmove((void *)v41, v173, v94);
      *(_DWORD *)(v39 + 8) = v41 + v94;
      v39 = v145;
    }
    v145 = v39 + 16;
  }
  sub_8052370(v38, v37, (int)&v176);
  v177 = 0;
  v178 = 0;
  v179 = 0;
  sub_80525A0((int)&v180, 3728);
  v44 = v145;
  v180 = 26;
  if ( v145 == v146 )
  {
    sub_8057B40((int)&v180, v42, (int)&v203, v145, (int)&v180);
  }
  else
  {
    if ( v145 )
    {
      v46 = 0;
      v45 = v178 - (_DWORD)v177;
      *(_WORD *)v145 = 26;
      *(_DWORD *)(v145 + 4) = 0;
      *(_DWORD *)(v145 + 8) = 0;
      *(_DWORD *)(v145 + 12) = 0;
      if ( v45 )
        v46 = operator new(v43, v42);
      v95 = v46 + v45;
      *(_DWORD *)(v44 + 4) = v46;
      *(_DWORD *)(v44 + 8) = v46;
      v96 = v178;
      *(_DWORD *)(v44 + 12) = v95;
      v97 = v96 - (_DWORD)v177;
      memmove((void *)v46, v177, v97);
      *(_DWORD *)(v44 + 8) = v46 + v97;
      v44 = v145;
    }
    v145 = v44 + 16;
  }
  sub_8052370(v43, (int)&v180, (int)&v180);
  v181 = 0;
  v182 = 0;
  v183 = 0;
  sub_8052530((int)&v184);
  v49 = v145;
  v184 = 20;
  if ( v145 == v146 )
  {
    sub_8057B40(v48, v47, (int)&v203, v145, (int)&v184);
  }
  else
  {
    if ( v145 )
    {
      v51 = 0;
      v50 = v182 - (_DWORD)v181;
      *(_WORD *)v145 = 20;
      *(_DWORD *)(v145 + 4) = 0;
      *(_DWORD *)(v145 + 8) = 0;
      *(_DWORD *)(v145 + 12) = 0;
      if ( v50 )
        v51 = operator new(v48, v47);
      v98 = v51 + v50;
      *(_DWORD *)(v49 + 4) = v51;
      *(_DWORD *)(v49 + 8) = v51;
      v99 = v182;
      *(_DWORD *)(v49 + 12) = v98;
      v100 = v99 - (_DWORD)v181;
      memmove((void *)v51, v181, v100);
      *(_DWORD *)(v49 + 8) = v51 + v100;
      v49 = v145;
    }
    v145 = v49 + 16;
  }
  sub_8052370((int)&v184, v47, (int)&v184);
  std__string__string(&v185, "en", &v186);
  v187 = 0;
  v188 = 0;
  v189 = 0;
  std__string__string(&v190, &v185);
  sub_8051C40((int)&v191, (int)&v190);
  std__string___string(&v190);
  v54 = v145;
  v191 = 15;
  if ( v145 == v146 )
  {
    sub_8057B40(v53, v52, (int)&v203, v145, (int)&v191);
  }
  else
  {
    if ( v145 )
    {
      v56 = 0;
      v55 = v188 - (_DWORD)v187;
      *(_WORD *)v145 = 15;
      *(_DWORD *)(v145 + 4) = 0;
      *(_DWORD *)(v145 + 8) = 0;
      *(_DWORD *)(v145 + 12) = 0;
      if ( v55 )
        v56 = operator new(v53, v52);
      v101 = v56 + v55;
      *(_DWORD *)(v54 + 4) = v56;
      *(_DWORD *)(v54 + 8) = v56;
      v102 = v188;
      *(_DWORD *)(v54 + 12) = v101;
      v103 = v102 - (_DWORD)v187;
      memmove((void *)v56, v187, v103);
      *(_DWORD *)(v54 + 8) = v56 + v103;
      v54 = v145;
    }
    v145 = v54 + 16;
  }
  sub_8052370((int)&v191, v52, (int)&v191);
  std__string___string(&v185);
  std__string__string(&v192, "us", &v193);
  v194 = 0;
  v195 = 0;
  v196 = 0;
  std__string__string(&v197, &v192);
  sub_8051C40((int)&v198, (int)&v197);
  std__string___string(&v197);
  v59 = v145;
  v198 = 14;
  if ( v145 == v146 )
  {
    sub_8057B40((int)&v198, v57, (int)&v203, v145, (int)&v198);
  }
  else
  {
    if ( v145 )
    {
      v61 = 0;
      v60 = v195 - (_DWORD)v194;
      *(_WORD *)v145 = 14;
      *(_DWORD *)(v145 + 4) = 0;
      *(_DWORD *)(v145 + 8) = 0;
      *(_DWORD *)(v145 + 12) = 0;
      if ( v60 )
        v61 = operator new(v58, v57);
      v104 = v61 + v60;
      *(_DWORD *)(v59 + 4) = v61;
      *(_DWORD *)(v59 + 8) = v61;
      v105 = v195;
      *(_DWORD *)(v59 + 12) = v104;
      v106 = v105 - (_DWORD)v194;
      memmove((void *)v61, v194, v106);
      *(_DWORD *)(v59 + 8) = v61 + v106;
      v59 = v145;
    }
    v145 = v59 + 16;
  }
  sub_8052370(v58, (int)&v198, (int)&v198);
  std__string___string(&v192);
  v199 = 0;
  v200 = 0;
  v201 = 0;
  sub_80529E0((int)&v133, (int)&v199, 0);
  v64 = v200;
  v63 = v199;
  v62 = v136;
  v202 = v135;
  v138 = 0;
  if ( __MKCADD__(v135 - v136, v200 - (_DWORD)v199) )
  {
    v135 = v136 + v135 - v136 + v200 - (_DWORD)v199;
  }
  else
  {
    sub_8056580(&v136, v202, v200 - (_DWORD)v199, &v138);
    v62 = v136;
    v63 = v199;
    v64 = v200;
  }
  memcpy((void *)(v62 + 4), v63, v64 - (_DWORD)v63);
  LOBYTE(v107) = sub_8051DF0((int)&v134, a1, (int)&v134, *(_DWORD *)(a1 + 164));
  v67 = v107;
  if ( v199 )
    operator delete(v66, v65);
  sub_80522F0((int)&v134, v65, (int)&v134);
  sub_8052390(v108, (int)&v133, (int)&v133);
  return v67;
}

//----- (08067C80) --------------------------------------------------------
signed int __cdecl sub_8067C80(int a1, int a2)
{
  int v2; // edi@1
  int v3; // edx@3
  int v4; // ecx@3
  __int16 v5; // ax@4
  __int16 v6; // dx@6
  __int16 v7; // si@6
  int v8; // ecx@7
  unsigned int v9; // ebx@7
  signed int v10; // eax@13
  signed int result; // eax@15
  signed int v12; // eax@17
  int v13; // [sp+18h] [bp-40h]@2
  int v14; // [sp+1Ch] [bp-3Ch]@2
  int v15; // [sp+20h] [bp-38h]@2
  unsigned __int16 v16; // [sp+30h] [bp-28h]@3
  unsigned __int16 v17; // [sp+3Eh] [bp-1Ah]@4
  unsigned __int16 v18; // [sp+16h] [bp-42h]@4
  __int16 v19; // [sp+3Ch] [bp-1Ch]@4
  unsigned __int16 v20; // [sp+14h] [bp-44h]@4
  __int16 v21; // [sp+38h] [bp-20h]@6
  int v22; // [sp+10h] [bp-48h]@7
  char v23; // [sp+24h] [bp-34h]@12
  char v24; // [sp+28h] [bp-30h]@16
  __int16 v25; // [sp+3Ah] [bp-1Eh]@17

  v2 = a1;
  if ( *(_DWORD *)(a2 + 4) == *(_DWORD *)a2 )
  {
LABEL_15:
    result = 1;
  }
  else
  {
    v13 = a1 + 4;
    v14 = a1 + 16;
    v15 = 0;
    while ( 1 )
    {
      sub_80512C0((int)&v16);
      if ( !(unsigned __int8)sub_8054AF0((int)&v16, a2, v15) )
        break;
      v18 = v17;
      v5 = v19;
      v20 = v16;
      if ( !v19 )
      {
        while ( 1 )
        {
          v12 = sub_8058030(v2, v25);
          if ( v12 < 0 )
            break;
          sub_807BA10(v4, v13, (int)&v24, v13, *(_DWORD *)(v2 + 4) + (v12 << 7));
        }
        v5 = v19;
      }
      if ( v5 == 1 )
      {
        v7 = v21;
        v6 = v21;
        if ( v21 )
        {
          v9 = 0;
          v8 = *(_DWORD *)(v2 + 4);
          v22 = *(_DWORD *)(v2 + 8);
          if ( (unsigned int)((v22 - v8) >> 7) > 0 )
          {
            do
            {
              if ( v7 == *(_WORD *)(v8 + (v9 << 7) + 8) )
              {
                sub_807BA10(v8, v13, (int)&v24, v13, v8 + (v9 << 7));
                v7 = v21;
                v8 = *(_DWORD *)(v2 + 4);
                v22 = *(_DWORD *)(v2 + 8);
                v6 = v21;
              }
              else
              {
                ++v9;
                v6 = v7;
              }
            }
            while ( v9 < (v22 - v8) >> 7 );
          }
          while ( 1 )
          {
            v10 = sub_8058090(v2, v6);
            if ( v10 < 0 )
              break;
            sub_807CA40((int)&v23, v14, *(_DWORD *)(v2 + 16) + 8 * v10);
            v6 = v21;
          }
        }
      }
      v15 += v20 + v18 + 10;
      sub_80549C0(v4, v18, (int)&v16);
      if ( v15 >= (unsigned int)(*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) )
        goto LABEL_15;
    }
    sub_80549C0(v4, v3, (int)&v16);
    result = 0;
  }
  return result;
}

//----- (080683D0) --------------------------------------------------------
int __cdecl sub_80683D0(int a1, int a2, int a3)
{
  int v4; // ebx@1
  int v7; // ecx@5
  int v8; // ecx@9
  int v9; // ecx@1
  int v10; // edx@1
  int v11; // eax@1
  int v24; // [sp+20h] [bp-18h]@1
  int v25; // [sp+24h] [bp-14h]@1
  char v26; // [sp+2Bh] [bp-Dh]@7
  char v27; // [sp+2Ah] [bp-Eh]@11

  std__string__string(&v24, a3);
  std__string__string(&v25, a2);
  LOBYTE(v11) = sub_805BA30(v9, v10, a1, (const void **)&v25, (const void **)&v24);
  v4 = v11;
  _EDX = v25 - 12;
  if ( v25 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v26);
  }
  _EDX = v24 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v24 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v8 = _EAX;
    }
    else
    {
      v8 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v8 - 1;
    }
    if ( v8 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v27);
  }
  return v4;
}

//----- (080684D0) --------------------------------------------------------
int __cdecl sub_80684D0(int a1, int a2)
{
  int v3; // ecx@1
  int v4; // edi@1
  int v6; // edx@3
  int v7; // ecx@3
  int result; // eax@7
  int v11; // ecx@11
  int v12; // ecx@15
  int v13; // ebx@1
  int v14; // eax@1
  int v15; // ecx@7
  int v16; // edx@7
  int v41; // [sp+108h] [bp-10h]@1
  char v42; // [sp+C8h] [bp-50h]@1
  __int16 v43; // [sp+D4h] [bp-44h]@1
  char v44; // [sp+D8h] [bp-40h]@1
  signed int v45; // [sp+CCh] [bp-4Ch]@1
  signed int v46; // [sp+D0h] [bp-48h]@1
  __int16 v47; // [sp+4Ch] [bp-CCh]@1
  signed int v48; // [sp+F8h] [bp-20h]@1
  int v49; // [sp+50h] [bp-C8h]@1
  signed int v50; // [sp+FCh] [bp-1Ch]@1
  signed int v51; // [sp+66h] [bp-B2h]@1
  signed int v52; // [sp+100h] [bp-18h]@1
  signed int v53; // [sp+6Ah] [bp-AEh]@1
  signed int v54; // [sp+104h] [bp-14h]@1
  signed int v55; // [sp+6Eh] [bp-AAh]@1
  int v56; // [sp+54h] [bp-C4h]@1
  int v57; // [sp+58h] [bp-C0h]@1
  signed int v58; // [sp+72h] [bp-A6h]@1
  __int16 v59; // [sp+5Ch] [bp-BCh]@1
  int v60; // [sp+78h] [bp-A0h]@1
  __int16 v61; // [sp+7Ch] [bp-9Ch]@1
  signed int v62; // [sp+5Eh] [bp-BAh]@1
  signed int v63; // [sp+62h] [bp-B6h]@1
  int v64; // [sp+40h] [bp-D8h]@1
  char v65; // [sp+4Bh] [bp-CDh]@1
  int v66; // [sp+3Ch] [bp-DCh]@1
  char v67; // [sp+4Ah] [bp-CEh]@1
  signed int v68; // [sp+E8h] [bp-30h]@1
  signed int v69; // [sp+ECh] [bp-2Ch]@1
  signed int v70; // [sp+F0h] [bp-28h]@1
  signed int v71; // [sp+F4h] [bp-24h]@1
  __int16 v72; // [sp+80h] [bp-98h]@1
  __int16 v73; // [sp+82h] [bp-96h]@1
  char v74; // [sp+84h] [bp-94h]@1
  char v75; // [sp+85h] [bp-93h]@1
  __int16 v76; // [sp+86h] [bp-92h]@1
  __int16 v77; // [sp+88h] [bp-90h]@1
  char v78; // [sp+8Ch] [bp-8Ch]@1
  __int16 v79; // [sp+ACh] [bp-6Ch]@1
  signed int v80; // [sp+9Ch] [bp-7Ch]@1
  signed int v81; // [sp+A0h] [bp-78h]@1
  signed int v82; // [sp+A4h] [bp-74h]@1
  signed int v83; // [sp+A8h] [bp-70h]@1
  char v84; // [sp+B0h] [bp-68h]@1
  int v85; // [sp+38h] [bp-E0h]@1
  int v86; // [sp+34h] [bp-E4h]@1
  char v87; // [sp+B4h] [bp-64h]@1
  char v88; // [sp+DCh] [bp-3Ch]@3
  int v89; // [sp+28h] [bp-F0h]@3
  int v90; // [sp+2Ch] [bp-ECh]@3
  int v91; // [sp+30h] [bp-E8h]@3
  char v92; // [sp+46h] [bp-D2h]@13
  char v93; // [sp+47h] [bp-D1h]@17
  char v94; // [sp+48h] [bp-D0h]@21
  char v95; // [sp+49h] [bp-CFh]@25

  v13 = a2;
  v41 = *MK_FP(__GS__, 20);
  v4 = a1;
  sub_8051180((int)&v42);
  v43 = 2;
  std__string__assign(&v44, v13);
  v45 = -1414812757;
  v46 = -1414812757;
  sub_80515E0((int)&v47);
  v14 = *(_DWORD *)(v4 + 292);
  v48 = 1225999881;
  v49 = v14 | 0x1000000;
  v50 = -787382452;
  v51 = 1225999881;
  v52 = 1162093186;
  v53 = -787382452;
  v54 = 21587;
  v55 = 1162093186;
  v47 = 80;
  v56 = 0;
  v57 = 0;
  v58 = 21587;
  v59 = 0;
  v60 = 0;
  v61 = 0;
  v62 = v45;
  v63 = v46;
  std__string__string(
    &v64,
    "<N><QUERY>&lt;Q&gt;&lt;PluginID&gt;srvMng&lt;/PluginID&gt;&lt;/Q&gt;</QUERY><NOTIFY>&lt;srv&gt;&lt;id&gt;cAwaySrv&lt;/id&gt;&lt;req&gt;&lt;id&gt;AwayStat&lt;/id&gt;&lt;trans&gt;1&lt;/trans&gt;&lt;senderId&gt;",
    &v65);
  std__string__string(&v66, "&lt;/senderId&gt;&lt;/req&gt;&lt;/srv&gt;</NOTIFY></N>", &v67);
  v68 = -273457093;
  v69 = 1164716760;
  v70 = 1520230564;
  v71 = 1709729630;
  v72 = 9;
  v73 = 0;
  v74 = 26;
  v75 = 0;
  v76 = 0;
  v77 = 0;
  std__string__assign(&v78, &aResNr[13], 0);
  v79 = 8;
  v80 = v68;
  v81 = v69;
  v82 = v70;
  v83 = v71;
  std__string__assign(&v84, "Script Plug-in: Remote Notification Arrive", 42);
  ZStplIcSt11char_traitsIcESaIcEESbIT_T0_T1_ERKS6_S8_((int)&v85, (int)&v64, v4 + 124);
  ZStplIcSt11char_traitsIcESaIcEESbIT_T0_T1_ERKS6_S8_((int)&v86, (int)&v85, (int)&v66);
  std__string__assign(&v87, &v86);
  _EDX = v86 - 12;
  if ( v86 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v3 = _EAX;
    }
    else
    {
      v3 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v3 - 1;
    }
    if ( v3 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v95);
  }
  _EDX = v85 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v85 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v3 = _EAX;
    }
    else
    {
      v3 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v3 - 1;
    }
    if ( v3 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v94);
  }
  sub_8056300(v3, _EDX, (int)&v47, (int)&v88);
  v89 = 0;
  v90 = 0;
  v91 = 0;
  sub_8052B90((int)&v42, (int)&v89, 0);
  sub_805A180(v4, 4, 6, 0, (int)&v89);
  if ( v89 )
    operator delete(v7, v6);
  _EDX = v66 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v66 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v12 = _EAX;
    }
    else
    {
      v12 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v12 - 1;
    }
    if ( v12 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v93);
  }
  _EDX = v64 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v64 - 12) )
    goto LABEL_10;
  while ( 1 )
  {
    sub_80545E0((int)&v47);
    sub_8053F10(v15, v16, (int)&v42);
    result = *MK_FP(__GS__, 20) ^ v41;
    if ( !(*MK_FP(__GS__, 20) ^ v41) )
      break;
    __stack_chk_fail();
LABEL_10:
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v11 = _EAX;
    }
    else
    {
      v11 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v11 - 1;
    }
    if ( v11 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v92);
  }
  return result;
}

//----- (080689D0) --------------------------------------------------------
void __fastcall sub_80689D0(int a1, int a2, int a3)
{
  int v4; // ebx@1
  int v8; // ecx@7
  int v9; // ecx@11
  int v10; // ecx@15
  int v11; // ecx@19
  int v12; // eax@1
  int v13; // eax@1
  int v14; // eax@4
  int v39; // [sp+40h] [bp-18h]@1
  char v40; // [sp+4Bh] [bp-Dh]@1
  int v41; // [sp+3Ch] [bp-1Ch]@1
  char v42; // [sp+4Ah] [bp-Eh]@1
  int v43; // [sp+38h] [bp-20h]@1
  char v44; // [sp+49h] [bp-Fh]@1
  int v45; // [sp+20h] [bp-38h]@1
  int v46; // [sp+1Ch] [bp-3Ch]@1
  int v47; // [sp+24h] [bp-34h]@1
  int v48; // [sp+34h] [bp-24h]@4
  char v49; // [sp+48h] [bp-10h]@4
  char v50; // [sp+47h] [bp-11h]@9
  char v51; // [sp+44h] [bp-14h]@13
  char v52; // [sp+45h] [bp-13h]@17
  char v53; // [sp+46h] [bp-12h]@21

  v4 = a3;
  *(_DWORD *)a3 = &off_807FD68;
  *(_DWORD *)(a3 + 4) = 0;
  *(_DWORD *)(a3 + 8) = 0;
  *(_DWORD *)(a3 + 12) = 0;
  *(_DWORD *)(a3 + 16) = 0;
  *(_DWORD *)(a3 + 20) = 0;
  *(_DWORD *)(a3 + 24) = 0;
  *(_DWORD *)(a3 + 28) = 0;
  *(_DWORD *)(a3 + 32) = 0;
  *(_DWORD *)(a3 + 36) = 0;
  *(_DWORD *)(a3 + 40) = 0;
  *(_DWORD *)(a3 + 44) = 0;
  *(_DWORD *)(a3 + 48) = 0;
  *(_DWORD *)(a3 + 52) = 0;
  *(_DWORD *)(a3 + 56) = 0;
  *(_DWORD *)(a3 + 60) = 0;
  *(_DWORD *)(a3 + 64) = 0;
  *(_DWORD *)(a3 + 68) = 0;
  *(_DWORD *)(a3 + 72) = 0;
  *(_DWORD *)(a3 + 76) = 134771820;
  *(_DWORD *)(a3 + 80) = 134771820;
  *(_DWORD *)(a3 + 84) = 134771820;
  *(_DWORD *)(a3 + 88) = 134771820;
  *(_DWORD *)(a3 + 92) = 134771820;
  *(_DWORD *)(a3 + 96) = 134771820;
  *(_DWORD *)(a3 + 104) = 134771820;
  *(_DWORD *)(a3 + 108) = 0;
  *(_DWORD *)(a3 + 112) = 134771820;
  *(_DWORD *)(a3 + 212) = a3 + 204;
  *(_DWORD *)(a3 + 216) = a3 + 204;
  *(_DWORD *)(a3 + 236) = a3 + 228;
  *(_DWORD *)(a3 + 240) = a3 + 228;
  *(_DWORD *)(a3 + 116) = 134771820;
  *(_DWORD *)(a3 + 120) = 0;
  *(_DWORD *)(a3 + 124) = 134771820;
  *(_DWORD *)(a3 + 128) = 134771820;
  *(_DWORD *)(a3 + 136) = 134771820;
  *(_DWORD *)(a3 + 140) = 134771820;
  *(_DWORD *)(a3 + 148) = 134771820;
  *(_DWORD *)(a3 + 152) = 134771820;
  *(_DWORD *)(a3 + 164) = -1;
  *(_WORD *)(a3 + 168) = 1;
  *(_DWORD *)(a3 + 172) = 1;
  *(_DWORD *)(a3 + 176) = 0;
  *(_DWORD *)(a3 + 180) = 0;
  *(_DWORD *)(a3 + 184) = 0;
  *(_DWORD *)(a3 + 188) = 0;
  *(_DWORD *)(a3 + 192) = 0;
  *(_DWORD *)(a3 + 196) = 0;
  *(_DWORD *)(a3 + 220) = 0;
  *(_DWORD *)(a3 + 204) = 0;
  *(_DWORD *)(a3 + 208) = 0;
  *(_DWORD *)(a3 + 244) = 0;
  *(_DWORD *)(a3 + 228) = 0;
  *(_DWORD *)(a3 + 232) = 0;
  *(_DWORD *)(a3 + 248) = 0;
  *(_DWORD *)(a3 + 276) = 0;
  *(_DWORD *)(a3 + 260) = 0;
  *(_DWORD *)(a3 + 264) = 0;
  *(_DWORD *)(a3 + 268) = a3 + 260;
  *(_DWORD *)(a3 + 272) = a3 + 260;
  *(_DWORD *)(a3 + 280) = -1;
  *(_BYTE *)(a3 + 284) = 0;
  *(_DWORD *)(a3 + 292) = -1;
  *(_BYTE *)(a3 + 296) = 1;
  *(_WORD *)(a3 + 298) = 0;
  v12 = operator new(a1, a2);
  *(_DWORD *)v12 = 0;
  *(_DWORD *)(v12 + 4) = 0;
  *(_DWORD *)(v12 + 8) = 0;
  *(_DWORD *)(v4 + 252) = v12;
  std__string__string(&v39, &aResNr[13], &v40);
  std__string__string(&v41, &aResNr[13], &v42);
  std__string__string(&v43, &aResNr[13], &v44);
  v45 = v4 + 128;
  std__string__assign(v4 + 128, &v43);
  *(_DWORD *)(v4 + 132) = 0;
  v46 = v4 + 136;
  std__string__assign(v4 + 136, &v41);
  v47 = v4 + 140;
  std__string__assign(v4 + 140, &v39);
  v13 = v43;
  *(_DWORD *)(v4 + 144) = 0;
  _EDX = v13 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v13 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v8 = _EAX;
    }
    else
    {
      v8 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v8 - 1;
    }
    if ( v8 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v50);
  }
  _EDX = v41 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v41 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v11 = _EAX;
    }
    else
    {
      v11 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v11 - 1;
    }
    if ( v11 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v53);
  }
  _EDX = v39 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v39 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v10 = _EAX;
    }
    else
    {
      v10 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v10 - 1;
    }
    if ( v10 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v52);
  }
  std__string__string(&v48, "login.oscar.aol.com", &v49);
  std__string__assign(v4 + 152, &v48);
  v14 = v48;
  *(_DWORD *)(v4 + 156) = 5190;
  _EDX = v14 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v14 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v9 = _EAX;
    }
    else
    {
      v9 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v9 - 1;
    }
    if ( v9 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v51);
  }
  *(_DWORD *)(v4 + 288) = time(0);
  tzset();
}

//----- (08069070) --------------------------------------------------------
void __fastcall sub_8069070(int a1, int a2, int a3)
{
  int v4; // ebx@1
  int v8; // ecx@7
  int v9; // ecx@11
  int v10; // ecx@15
  int v11; // ecx@19
  int v12; // eax@1
  int v13; // eax@1
  int v14; // eax@4
  int v39; // [sp+40h] [bp-18h]@1
  char v40; // [sp+4Bh] [bp-Dh]@1
  int v41; // [sp+3Ch] [bp-1Ch]@1
  char v42; // [sp+4Ah] [bp-Eh]@1
  int v43; // [sp+38h] [bp-20h]@1
  char v44; // [sp+49h] [bp-Fh]@1
  int v45; // [sp+20h] [bp-38h]@1
  int v46; // [sp+1Ch] [bp-3Ch]@1
  int v47; // [sp+24h] [bp-34h]@1
  int v48; // [sp+34h] [bp-24h]@4
  char v49; // [sp+48h] [bp-10h]@4
  char v50; // [sp+47h] [bp-11h]@9
  char v51; // [sp+44h] [bp-14h]@13
  char v52; // [sp+45h] [bp-13h]@17
  char v53; // [sp+46h] [bp-12h]@21

  v4 = a3;
  *(_DWORD *)a3 = &off_807FD68;
  *(_DWORD *)(a3 + 4) = 0;
  *(_DWORD *)(a3 + 8) = 0;
  *(_DWORD *)(a3 + 12) = 0;
  *(_DWORD *)(a3 + 16) = 0;
  *(_DWORD *)(a3 + 20) = 0;
  *(_DWORD *)(a3 + 24) = 0;
  *(_DWORD *)(a3 + 28) = 0;
  *(_DWORD *)(a3 + 32) = 0;
  *(_DWORD *)(a3 + 36) = 0;
  *(_DWORD *)(a3 + 40) = 0;
  *(_DWORD *)(a3 + 44) = 0;
  *(_DWORD *)(a3 + 48) = 0;
  *(_DWORD *)(a3 + 52) = 0;
  *(_DWORD *)(a3 + 56) = 0;
  *(_DWORD *)(a3 + 60) = 0;
  *(_DWORD *)(a3 + 64) = 0;
  *(_DWORD *)(a3 + 68) = 0;
  *(_DWORD *)(a3 + 72) = 0;
  *(_DWORD *)(a3 + 76) = 134771820;
  *(_DWORD *)(a3 + 80) = 134771820;
  *(_DWORD *)(a3 + 84) = 134771820;
  *(_DWORD *)(a3 + 88) = 134771820;
  *(_DWORD *)(a3 + 92) = 134771820;
  *(_DWORD *)(a3 + 96) = 134771820;
  *(_DWORD *)(a3 + 104) = 134771820;
  *(_DWORD *)(a3 + 108) = 0;
  *(_DWORD *)(a3 + 112) = 134771820;
  *(_DWORD *)(a3 + 212) = a3 + 204;
  *(_DWORD *)(a3 + 216) = a3 + 204;
  *(_DWORD *)(a3 + 236) = a3 + 228;
  *(_DWORD *)(a3 + 240) = a3 + 228;
  *(_DWORD *)(a3 + 116) = 134771820;
  *(_DWORD *)(a3 + 120) = 0;
  *(_DWORD *)(a3 + 124) = 134771820;
  *(_DWORD *)(a3 + 128) = 134771820;
  *(_DWORD *)(a3 + 136) = 134771820;
  *(_DWORD *)(a3 + 140) = 134771820;
  *(_DWORD *)(a3 + 148) = 134771820;
  *(_DWORD *)(a3 + 152) = 134771820;
  *(_DWORD *)(a3 + 164) = -1;
  *(_WORD *)(a3 + 168) = 1;
  *(_DWORD *)(a3 + 172) = 1;
  *(_DWORD *)(a3 + 176) = 0;
  *(_DWORD *)(a3 + 180) = 0;
  *(_DWORD *)(a3 + 184) = 0;
  *(_DWORD *)(a3 + 188) = 0;
  *(_DWORD *)(a3 + 192) = 0;
  *(_DWORD *)(a3 + 196) = 0;
  *(_DWORD *)(a3 + 220) = 0;
  *(_DWORD *)(a3 + 204) = 0;
  *(_DWORD *)(a3 + 208) = 0;
  *(_DWORD *)(a3 + 244) = 0;
  *(_DWORD *)(a3 + 228) = 0;
  *(_DWORD *)(a3 + 232) = 0;
  *(_DWORD *)(a3 + 248) = 0;
  *(_DWORD *)(a3 + 276) = 0;
  *(_DWORD *)(a3 + 260) = 0;
  *(_DWORD *)(a3 + 264) = 0;
  *(_DWORD *)(a3 + 268) = a3 + 260;
  *(_DWORD *)(a3 + 272) = a3 + 260;
  *(_DWORD *)(a3 + 280) = -1;
  *(_BYTE *)(a3 + 284) = 0;
  *(_DWORD *)(a3 + 292) = -1;
  *(_BYTE *)(a3 + 296) = 1;
  *(_WORD *)(a3 + 298) = 0;
  v12 = operator new(a1, a2);
  *(_DWORD *)v12 = 0;
  *(_DWORD *)(v12 + 4) = 0;
  *(_DWORD *)(v12 + 8) = 0;
  *(_DWORD *)(v4 + 252) = v12;
  std__string__string(&v39, &aResNr[13], &v40);
  std__string__string(&v41, &aResNr[13], &v42);
  std__string__string(&v43, &aResNr[13], &v44);
  v45 = v4 + 128;
  std__string__assign(v4 + 128, &v43);
  *(_DWORD *)(v4 + 132) = 0;
  v46 = v4 + 136;
  std__string__assign(v4 + 136, &v41);
  v47 = v4 + 140;
  std__string__assign(v4 + 140, &v39);
  v13 = v43;
  *(_DWORD *)(v4 + 144) = 0;
  _EDX = v13 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v13 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v8 = _EAX;
    }
    else
    {
      v8 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v8 - 1;
    }
    if ( v8 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v50);
  }
  _EDX = v41 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v41 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v11 = _EAX;
    }
    else
    {
      v11 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v11 - 1;
    }
    if ( v11 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v53);
  }
  _EDX = v39 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v39 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v10 = _EAX;
    }
    else
    {
      v10 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v10 - 1;
    }
    if ( v10 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v52);
  }
  std__string__string(&v48, "login.oscar.aol.com", &v49);
  std__string__assign(v4 + 152, &v48);
  v14 = v48;
  *(_DWORD *)(v4 + 156) = 5190;
  _EDX = v14 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v14 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v9 = _EAX;
    }
    else
    {
      v9 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v9 - 1;
    }
    if ( v9 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v51);
  }
  *(_DWORD *)(v4 + 288) = time(0);
  tzset();
}

//----- (08069710) --------------------------------------------------------
int __cdecl sub_8069710(int a1)
{
  int v1; // edx@1
  int v2; // ecx@1
  int v3; // edi@1
  int v4; // eax@2
  int v5; // ebx@2
  int v6; // esi@2
  int v7; // ecx@8
  int v23; // ebx@27
  int v24; // esi@27
  int v25; // ebx@32
  int v26; // esi@32
  int v27; // ebx@37
  int v28; // esi@37
  int v29; // ebx@42
  int v30; // esi@42
  int v31; // ebx@47
  int v32; // esi@47
  int result; // eax@52
  int v34; // ebx@52
  int v35; // esi@52
  int v36; // eax@12
  int v37; // eax@13
  int v38; // eax@14
  int v39; // eax@15
  int v40; // eax@16
  int v41; // eax@17
  int v42; // eax@18
  int v43; // eax@19
  int v44; // eax@20
  int v45; // eax@21
  int v46; // eax@22
  int v47; // eax@23
  int v48; // eax@24
  int v49; // eax@25
  int v50; // eax@26
  int v51; // ST00_4@28
  int v52; // ST00_4@33
  int v53; // ST00_4@38
  int v54; // ST00_4@43
  int v55; // ST00_4@53
  char v146; // [sp+2Bh] [bp-Dh]@61
  char v147; // [sp+1Dh] [bp-1Bh]@65
  char v148; // [sp+23h] [bp-15h]@69
  char v149; // [sp+1Fh] [bp-19h]@73
  char v150; // [sp+27h] [bp-11h]@77
  char v151; // [sp+1Eh] [bp-1Ah]@81
  char v152; // [sp+25h] [bp-13h]@85
  char v153; // [sp+21h] [bp-17h]@89
  char v154; // [sp+29h] [bp-Fh]@93
  char v155; // [sp+20h] [bp-18h]@97
  char v156; // [sp+24h] [bp-14h]@101
  char v157; // [sp+22h] [bp-16h]@105
  char v158; // [sp+28h] [bp-10h]@109
  char v159; // [sp+26h] [bp-12h]@113
  char v160; // [sp+2Ah] [bp-Eh]@117

  *(_DWORD *)a1 = &off_807FD68;
  sub_805B650(a1);
  v1 = a1;
  v3 = *(_DWORD *)(a1 + 252);
  if ( v3 )
  {
    v4 = *(_DWORD *)v3;
    v6 = *(_DWORD *)(v3 + 4);
    v5 = *(_DWORD *)v3;
    if ( v6 != *(_DWORD *)v3 )
    {
      do
      {
        sub_8052330(v2, v1, v5);
        v5 += 28;
      }
      while ( v6 != v5 );
      v4 = *(_DWORD *)v3;
    }
    if ( v4 )
      operator delete(v2, v1);
    operator delete(v2, v1);
  }
  sub_8077D60(a1 + 256, *(_DWORD *)(a1 + 264));
  sub_807D630(a1 + 224, *(_DWORD *)(a1 + 232));
  sub_8079710(a1 + 200, *(_DWORD *)(a1 + 208));
  if ( *(_DWORD *)(a1 + 188) )
    operator delete(v7, a1);
  if ( *(_DWORD *)(a1 + 176) )
    operator delete(v7, a1);
  v36 = *(_DWORD *)(a1 + 152);
  _EDX = v36 - 12;
  if ( v36 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v146);
  }
  v37 = *(_DWORD *)(a1 + 148);
  _EDX = v37 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v37 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v160);
  }
  v38 = *(_DWORD *)(a1 + 140);
  _EDX = v38 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v38 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v154);
  }
  v39 = *(_DWORD *)(a1 + 136);
  _EDX = v39 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v39 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v158);
  }
  v40 = *(_DWORD *)(a1 + 128);
  _EDX = v40 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v40 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v150);
  }
  v41 = *(_DWORD *)(a1 + 124);
  _EDX = v41 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v41 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v159);
  }
  v42 = *(_DWORD *)(a1 + 116);
  _EDX = v42 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v42 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v152);
  }
  v43 = *(_DWORD *)(a1 + 112);
  _EDX = v43 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v43 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v156);
  }
  v44 = *(_DWORD *)(a1 + 104);
  _EDX = v44 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v44 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v148);
  }
  v45 = *(_DWORD *)(a1 + 96);
  _EDX = v45 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v45 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v157);
  }
  v46 = *(_DWORD *)(a1 + 92);
  _EDX = v46 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v46 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v153);
  }
  v47 = *(_DWORD *)(a1 + 88);
  _EDX = v47 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v47 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v155);
  }
  v48 = *(_DWORD *)(a1 + 84);
  _EDX = v48 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v48 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v149);
  }
  v49 = *(_DWORD *)(a1 + 80);
  _EDX = v49 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v49 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v151);
  }
  v50 = *(_DWORD *)(a1 + 76);
  _EDX = v50 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v50 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v147);
  }
  v24 = *(_DWORD *)(a1 + 68);
  v23 = *(_DWORD *)(a1 + 64);
  if ( v24 != v23 )
  {
    do
    {
      v51 = v23;
      v23 += 128;
      sub_807B640(v7, _EDX, v51);
    }
    while ( v24 != v23 );
    _EDX = a1;
    v24 = *(_DWORD *)(a1 + 64);
  }
  if ( v24 )
    operator delete(v7, _EDX);
  v26 = *(_DWORD *)(a1 + 56);
  v25 = *(_DWORD *)(a1 + 52);
  if ( v26 != v25 )
  {
    do
    {
      v52 = v25;
      v25 += 128;
      sub_807B640(v7, _EDX, v52);
    }
    while ( v26 != v25 );
    _EDX = a1;
    v26 = *(_DWORD *)(a1 + 52);
  }
  if ( v26 )
    operator delete(v7, _EDX);
  v28 = *(_DWORD *)(a1 + 44);
  v27 = *(_DWORD *)(a1 + 40);
  if ( v28 != v27 )
  {
    do
    {
      v53 = v27;
      v27 += 128;
      sub_807B640(v7, _EDX, v53);
    }
    while ( v28 != v27 );
    _EDX = a1;
    v28 = *(_DWORD *)(a1 + 40);
  }
  if ( v28 )
    operator delete(v7, _EDX);
  v30 = *(_DWORD *)(a1 + 32);
  v29 = *(_DWORD *)(a1 + 28);
  if ( v30 != v29 )
  {
    do
    {
      v54 = v29;
      v29 += 128;
      sub_807B640(v7, _EDX, v54);
    }
    while ( v30 != v29 );
    _EDX = a1;
    v30 = *(_DWORD *)(a1 + 28);
  }
  if ( v30 )
    operator delete(v7, _EDX);
  v32 = *(_DWORD *)(a1 + 20);
  v31 = *(_DWORD *)(a1 + 16);
  if ( v32 != v31 )
  {
    do
    {
      std__string___string(v31 + 4);
      v31 += 8;
    }
    while ( v32 != v31 );
    _EDX = a1;
    v32 = *(_DWORD *)(a1 + 16);
  }
  if ( v32 )
    operator delete(v7, _EDX);
  result = a1;
  v35 = *(_DWORD *)(a1 + 8);
  v34 = *(_DWORD *)(a1 + 4);
  if ( v35 != v34 )
  {
    do
    {
      v55 = v34;
      v34 += 128;
      result = sub_807B640(v7, _EDX, v55);
    }
    while ( v35 != v34 );
    _EDX = a1;
    v35 = *(_DWORD *)(a1 + 4);
  }
  if ( v35 )
    result = operator delete(v7, _EDX);
  return result;
}

//----- (08069FF0) --------------------------------------------------------
int __cdecl sub_8069FF0(int a1)
{
  int v1; // edx@1
  int v2; // ecx@1
  int v3; // edi@1
  int v4; // eax@2
  int v5; // ebx@2
  int v6; // esi@2
  int v7; // ecx@8
  int v23; // ebx@27
  int v24; // esi@27
  int v25; // ebx@32
  int v26; // esi@32
  int v27; // ebx@37
  int v28; // esi@37
  int v29; // ebx@42
  int v30; // esi@42
  int v31; // ebx@47
  int v32; // esi@47
  int v33; // ebx@52
  int v34; // esi@52
  int v36; // eax@12
  int v37; // eax@13
  int v38; // eax@14
  int v39; // eax@15
  int v40; // eax@16
  int v41; // eax@17
  int v42; // eax@18
  int v43; // eax@19
  int v44; // eax@20
  int v45; // eax@21
  int v46; // eax@22
  int v47; // eax@23
  int v48; // eax@24
  int v49; // eax@25
  int v50; // eax@26
  int v51; // ST00_4@28
  int v52; // ST00_4@33
  int v53; // ST00_4@38
  int v54; // ST00_4@43
  int v55; // ST00_4@53
  char v146; // [sp+2Bh] [bp-Dh]@61
  char v147; // [sp+1Dh] [bp-1Bh]@65
  char v148; // [sp+23h] [bp-15h]@69
  char v149; // [sp+1Fh] [bp-19h]@73
  char v150; // [sp+27h] [bp-11h]@77
  char v151; // [sp+1Eh] [bp-1Ah]@81
  char v152; // [sp+25h] [bp-13h]@85
  char v153; // [sp+21h] [bp-17h]@89
  char v154; // [sp+29h] [bp-Fh]@93
  char v155; // [sp+20h] [bp-18h]@97
  char v156; // [sp+24h] [bp-14h]@101
  char v157; // [sp+22h] [bp-16h]@105
  char v158; // [sp+28h] [bp-10h]@109
  char v159; // [sp+26h] [bp-12h]@113
  char v160; // [sp+2Ah] [bp-Eh]@117

  *(_DWORD *)a1 = &off_807FD68;
  sub_805B650(a1);
  v1 = a1;
  v3 = *(_DWORD *)(a1 + 252);
  if ( v3 )
  {
    v4 = *(_DWORD *)v3;
    v6 = *(_DWORD *)(v3 + 4);
    v5 = *(_DWORD *)v3;
    if ( v6 != *(_DWORD *)v3 )
    {
      do
      {
        sub_8052330(v2, v1, v5);
        v5 += 28;
      }
      while ( v6 != v5 );
      v4 = *(_DWORD *)v3;
    }
    if ( v4 )
      operator delete(v2, v1);
    operator delete(v2, v1);
  }
  sub_8077D60(a1 + 256, *(_DWORD *)(a1 + 264));
  sub_807D630(a1 + 224, *(_DWORD *)(a1 + 232));
  sub_8079710(a1 + 200, *(_DWORD *)(a1 + 208));
  if ( *(_DWORD *)(a1 + 188) )
    operator delete(v7, a1);
  if ( *(_DWORD *)(a1 + 176) )
    operator delete(v7, a1);
  v36 = *(_DWORD *)(a1 + 152);
  _EDX = v36 - 12;
  if ( v36 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v146);
  }
  v37 = *(_DWORD *)(a1 + 148);
  _EDX = v37 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v37 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v160);
  }
  v38 = *(_DWORD *)(a1 + 140);
  _EDX = v38 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v38 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v154);
  }
  v39 = *(_DWORD *)(a1 + 136);
  _EDX = v39 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v39 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v158);
  }
  v40 = *(_DWORD *)(a1 + 128);
  _EDX = v40 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v40 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v150);
  }
  v41 = *(_DWORD *)(a1 + 124);
  _EDX = v41 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v41 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v159);
  }
  v42 = *(_DWORD *)(a1 + 116);
  _EDX = v42 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v42 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v152);
  }
  v43 = *(_DWORD *)(a1 + 112);
  _EDX = v43 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v43 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v156);
  }
  v44 = *(_DWORD *)(a1 + 104);
  _EDX = v44 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v44 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v148);
  }
  v45 = *(_DWORD *)(a1 + 96);
  _EDX = v45 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v45 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v157);
  }
  v46 = *(_DWORD *)(a1 + 92);
  _EDX = v46 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v46 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v153);
  }
  v47 = *(_DWORD *)(a1 + 88);
  _EDX = v47 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v47 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v155);
  }
  v48 = *(_DWORD *)(a1 + 84);
  _EDX = v48 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v48 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v149);
  }
  v49 = *(_DWORD *)(a1 + 80);
  _EDX = v49 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v49 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v151);
  }
  v50 = *(_DWORD *)(a1 + 76);
  _EDX = v50 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v50 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v147);
  }
  v24 = *(_DWORD *)(a1 + 68);
  v23 = *(_DWORD *)(a1 + 64);
  if ( v24 != v23 )
  {
    do
    {
      v51 = v23;
      v23 += 128;
      sub_807B640(v7, _EDX, v51);
    }
    while ( v24 != v23 );
    _EDX = a1;
    v24 = *(_DWORD *)(a1 + 64);
  }
  if ( v24 )
    operator delete(v7, _EDX);
  v26 = *(_DWORD *)(a1 + 56);
  v25 = *(_DWORD *)(a1 + 52);
  if ( v26 != v25 )
  {
    do
    {
      v52 = v25;
      v25 += 128;
      sub_807B640(v7, _EDX, v52);
    }
    while ( v26 != v25 );
    _EDX = a1;
    v26 = *(_DWORD *)(a1 + 52);
  }
  if ( v26 )
    operator delete(v7, _EDX);
  v28 = *(_DWORD *)(a1 + 44);
  v27 = *(_DWORD *)(a1 + 40);
  if ( v28 != v27 )
  {
    do
    {
      v53 = v27;
      v27 += 128;
      sub_807B640(v7, _EDX, v53);
    }
    while ( v28 != v27 );
    _EDX = a1;
    v28 = *(_DWORD *)(a1 + 40);
  }
  if ( v28 )
    operator delete(v7, _EDX);
  v30 = *(_DWORD *)(a1 + 32);
  v29 = *(_DWORD *)(a1 + 28);
  if ( v30 != v29 )
  {
    do
    {
      v54 = v29;
      v29 += 128;
      sub_807B640(v7, _EDX, v54);
    }
    while ( v30 != v29 );
    _EDX = a1;
    v30 = *(_DWORD *)(a1 + 28);
  }
  if ( v30 )
    operator delete(v7, _EDX);
  v32 = *(_DWORD *)(a1 + 20);
  v31 = *(_DWORD *)(a1 + 16);
  if ( v32 != v31 )
  {
    do
    {
      std__string___string(v31 + 4);
      v31 += 8;
    }
    while ( v32 != v31 );
    _EDX = a1;
    v32 = *(_DWORD *)(a1 + 16);
  }
  if ( v32 )
    operator delete(v7, _EDX);
  v34 = *(_DWORD *)(a1 + 8);
  v33 = *(_DWORD *)(a1 + 4);
  if ( v34 != v33 )
  {
    do
    {
      v55 = v33;
      v33 += 128;
      sub_807B640(v7, _EDX, v55);
    }
    while ( v34 != v33 );
    _EDX = a1;
    v34 = *(_DWORD *)(a1 + 4);
  }
  if ( v34 )
    operator delete(v7, _EDX);
  return operator delete(v7, _EDX);
}

//----- (0806A8E0) --------------------------------------------------------
int __cdecl sub_806A8E0(int a1)
{
  int v1; // edx@1
  int v2; // ecx@1
  int v3; // edi@1
  int v4; // eax@2
  int v5; // ebx@2
  int v6; // esi@2
  int v7; // ecx@8
  int v23; // ebx@27
  int v24; // esi@27
  int v25; // ebx@32
  int v26; // esi@32
  int v27; // ebx@37
  int v28; // esi@37
  int v29; // ebx@42
  int v30; // esi@42
  int v31; // ebx@47
  int v32; // esi@47
  int result; // eax@52
  int v34; // ebx@52
  int v35; // esi@52
  int v36; // eax@12
  int v37; // eax@13
  int v38; // eax@14
  int v39; // eax@15
  int v40; // eax@16
  int v41; // eax@17
  int v42; // eax@18
  int v43; // eax@19
  int v44; // eax@20
  int v45; // eax@21
  int v46; // eax@22
  int v47; // eax@23
  int v48; // eax@24
  int v49; // eax@25
  int v50; // eax@26
  int v51; // ST00_4@28
  int v52; // ST00_4@33
  int v53; // ST00_4@38
  int v54; // ST00_4@43
  int v55; // ST00_4@53
  char v146; // [sp+2Bh] [bp-Dh]@61
  char v147; // [sp+1Dh] [bp-1Bh]@65
  char v148; // [sp+23h] [bp-15h]@69
  char v149; // [sp+1Fh] [bp-19h]@73
  char v150; // [sp+27h] [bp-11h]@77
  char v151; // [sp+1Eh] [bp-1Ah]@81
  char v152; // [sp+25h] [bp-13h]@85
  char v153; // [sp+21h] [bp-17h]@89
  char v154; // [sp+29h] [bp-Fh]@93
  char v155; // [sp+20h] [bp-18h]@97
  char v156; // [sp+24h] [bp-14h]@101
  char v157; // [sp+22h] [bp-16h]@105
  char v158; // [sp+28h] [bp-10h]@109
  char v159; // [sp+26h] [bp-12h]@113
  char v160; // [sp+2Ah] [bp-Eh]@117

  *(_DWORD *)a1 = &off_807FD68;
  sub_805B650(a1);
  v1 = a1;
  v3 = *(_DWORD *)(a1 + 252);
  if ( v3 )
  {
    v4 = *(_DWORD *)v3;
    v6 = *(_DWORD *)(v3 + 4);
    v5 = *(_DWORD *)v3;
    if ( v6 != *(_DWORD *)v3 )
    {
      do
      {
        sub_8052330(v2, v1, v5);
        v5 += 28;
      }
      while ( v6 != v5 );
      v4 = *(_DWORD *)v3;
    }
    if ( v4 )
      operator delete(v2, v1);
    operator delete(v2, v1);
  }
  sub_8077D60(a1 + 256, *(_DWORD *)(a1 + 264));
  sub_807D630(a1 + 224, *(_DWORD *)(a1 + 232));
  sub_8079710(a1 + 200, *(_DWORD *)(a1 + 208));
  if ( *(_DWORD *)(a1 + 188) )
    operator delete(v7, a1);
  if ( *(_DWORD *)(a1 + 176) )
    operator delete(v7, a1);
  v36 = *(_DWORD *)(a1 + 152);
  _EDX = v36 - 12;
  if ( v36 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v146);
  }
  v37 = *(_DWORD *)(a1 + 148);
  _EDX = v37 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v37 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v160);
  }
  v38 = *(_DWORD *)(a1 + 140);
  _EDX = v38 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v38 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v154);
  }
  v39 = *(_DWORD *)(a1 + 136);
  _EDX = v39 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v39 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v158);
  }
  v40 = *(_DWORD *)(a1 + 128);
  _EDX = v40 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v40 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v150);
  }
  v41 = *(_DWORD *)(a1 + 124);
  _EDX = v41 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v41 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v159);
  }
  v42 = *(_DWORD *)(a1 + 116);
  _EDX = v42 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v42 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v152);
  }
  v43 = *(_DWORD *)(a1 + 112);
  _EDX = v43 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v43 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v156);
  }
  v44 = *(_DWORD *)(a1 + 104);
  _EDX = v44 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v44 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v148);
  }
  v45 = *(_DWORD *)(a1 + 96);
  _EDX = v45 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v45 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v157);
  }
  v46 = *(_DWORD *)(a1 + 92);
  _EDX = v46 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v46 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v153);
  }
  v47 = *(_DWORD *)(a1 + 88);
  _EDX = v47 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v47 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v155);
  }
  v48 = *(_DWORD *)(a1 + 84);
  _EDX = v48 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v48 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v149);
  }
  v49 = *(_DWORD *)(a1 + 80);
  _EDX = v49 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v49 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v151);
  }
  v50 = *(_DWORD *)(a1 + 76);
  _EDX = v50 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v50 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v147);
  }
  v24 = *(_DWORD *)(a1 + 68);
  v23 = *(_DWORD *)(a1 + 64);
  if ( v24 != v23 )
  {
    do
    {
      v51 = v23;
      v23 += 128;
      sub_807B640(v7, _EDX, v51);
    }
    while ( v24 != v23 );
    _EDX = a1;
    v24 = *(_DWORD *)(a1 + 64);
  }
  if ( v24 )
    operator delete(v7, _EDX);
  v26 = *(_DWORD *)(a1 + 56);
  v25 = *(_DWORD *)(a1 + 52);
  if ( v26 != v25 )
  {
    do
    {
      v52 = v25;
      v25 += 128;
      sub_807B640(v7, _EDX, v52);
    }
    while ( v26 != v25 );
    _EDX = a1;
    v26 = *(_DWORD *)(a1 + 52);
  }
  if ( v26 )
    operator delete(v7, _EDX);
  v28 = *(_DWORD *)(a1 + 44);
  v27 = *(_DWORD *)(a1 + 40);
  if ( v28 != v27 )
  {
    do
    {
      v53 = v27;
      v27 += 128;
      sub_807B640(v7, _EDX, v53);
    }
    while ( v28 != v27 );
    _EDX = a1;
    v28 = *(_DWORD *)(a1 + 40);
  }
  if ( v28 )
    operator delete(v7, _EDX);
  v30 = *(_DWORD *)(a1 + 32);
  v29 = *(_DWORD *)(a1 + 28);
  if ( v30 != v29 )
  {
    do
    {
      v54 = v29;
      v29 += 128;
      sub_807B640(v7, _EDX, v54);
    }
    while ( v30 != v29 );
    _EDX = a1;
    v30 = *(_DWORD *)(a1 + 28);
  }
  if ( v30 )
    operator delete(v7, _EDX);
  v32 = *(_DWORD *)(a1 + 20);
  v31 = *(_DWORD *)(a1 + 16);
  if ( v32 != v31 )
  {
    do
    {
      std__string___string(v31 + 4);
      v31 += 8;
    }
    while ( v32 != v31 );
    _EDX = a1;
    v32 = *(_DWORD *)(a1 + 16);
  }
  if ( v32 )
    operator delete(v7, _EDX);
  result = a1;
  v35 = *(_DWORD *)(a1 + 8);
  v34 = *(_DWORD *)(a1 + 4);
  if ( v35 != v34 )
  {
    do
    {
      v55 = v34;
      v34 += 128;
      result = sub_807B640(v7, _EDX, v55);
    }
    while ( v35 != v34 );
    _EDX = a1;
    v35 = *(_DWORD *)(a1 + 4);
  }
  if ( v35 )
    result = operator delete(v7, _EDX);
  return result;
}

//----- (0806B1C0) --------------------------------------------------------
signed int __cdecl sub_806B1C0(int a1, int a2, int a3)
{
  int v3; // edi@1
  int v4; // esi@1
  int v5; // ebx@2
  int v6; // ecx@5
  int v7; // edx@8
  signed int v8; // ebx@10
  char v10; // al@15
  signed int *v11; // ebx@21
  int v13; // edx@23
  unsigned int v14; // ecx@23
  int v15; // esi@23
  unsigned __int16 v16; // ax@24
  unsigned __int16 v17; // bx@24
  int v18; // ebx@27
  int v19; // edi@27
  unsigned __int16 v20; // ax@28
  int v21; // ecx@28
  int v22; // eax@31
  int v23; // edi@31
  unsigned __int16 v24; // ax@32
  int v25; // ecx@32
  int v26; // eax@35
  int v27; // edi@35
  unsigned __int16 v28; // ax@36
  int v29; // ebx@36
  int v30; // ecx@39
  int v31; // ebx@40
  int v32; // ebx@43
  int v33; // ecx@56
  int v34; // ecx@11
  int v35; // edx@11
  int v36; // edx@19
  int v37; // edx@47
  int v38; // edx@49
  __int16 v45; // [sp+120h] [bp-38h]@1
  __int16 v46; // [sp+108h] [bp-50h]@1
  __int16 v47; // [sp+10Ah] [bp-4Eh]@1
  int v48; // [sp+110h] [bp-48h]@1
  char v49; // [sp+114h] [bp-44h]@6
  int v50; // [sp+124h] [bp-34h]@8
  int v51; // [sp+128h] [bp-30h]@8
  signed int v52; // [sp+E4h] [bp-74h]@18
  signed int v53; // [sp+E8h] [bp-70h]@18
  signed int v54; // [sp+ECh] [bp-6Ch]@18
  signed int v55; // [sp+F0h] [bp-68h]@18
  signed int v56; // [sp+F4h] [bp-64h]@18
  int v57; // [sp+13Ch] [bp-1Ch]@19
  int v58; // [sp+14h] [bp-144h]@19
  char v59; // [sp+D0h] [bp-88h]@19
  signed int v60; // [sp+5Ch] [bp-FCh]@19
  int v61; // [sp+CCh] [bp-8Ch]@19
  signed int v62; // [sp+30h] [bp-128h]@19
  char v63; // [sp+D1h] [bp-87h]@19
  int v64; // [sp+D4h] [bp-84h]@19
  int v65; // [sp+D8h] [bp-80h]@19
  int v66; // [sp+DCh] [bp-7Ch]@19
  int v67; // [sp+E0h] [bp-78h]@19
  signed int v68; // [sp+34h] [bp-124h]@19
  int v69; // [sp+38h] [bp-120h]@19
  int v70; // [sp+3Ch] [bp-11Ch]@19
  const void *v71; // [sp+40h] [bp-118h]@19
  const void *v72; // [sp+44h] [bp-114h]@19
  const void *v73; // [sp+48h] [bp-110h]@19
  int v74; // [sp+4Ch] [bp-10Ch]@19
  char v75; // [sp+50h] [bp-108h]@19
  signed int v76; // [sp+54h] [bp-104h]@19
  signed int v77; // [sp+58h] [bp-100h]@19
  signed int v78; // [sp+138h] [bp-20h]@19
  char v79; // [sp+Ch] [bp-14Ch]@21
  char v80; // [sp+14Bh] [bp-Dh]@21
  int v81; // [sp+134h] [bp-24h]@21
  unsigned __int16 v82; // [sp+146h] [bp-12h]@24
  unsigned __int16 v83; // [sp+144h] [bp-14h]@28
  int v84; // [sp+20h] [bp-138h]@28
  unsigned __int16 v85; // [sp+142h] [bp-16h]@32
  int v86; // [sp+1Ch] [bp-13Ch]@32
  unsigned __int16 v87; // [sp+140h] [bp-18h]@36
  int v88; // [sp+18h] [bp-140h]@36
  char v89; // [sp+FCh] [bp-5Ch]@40
  int v90; // [sp+100h] [bp-58h]@41
  int v91; // [sp+F8h] [bp-60h]@42
  __int16 v92; // [sp+104h] [bp-54h]@43
  int v93; // [sp+28h] [bp-130h]@45
  char v94; // [sp+14Ah] [bp-Eh]@48
  int v95; // [sp+130h] [bp-28h]@48
  char v96; // [sp+149h] [bp-Fh]@58

  sub_8050F60((int)&v45);
  sub_8050F20((int)&v46);
  v46 = 21;
  v47 = 3;
  v48 = a3;
  v3 = *(_DWORD *)a2;
  v4 = *(_DWORD *)(a2 + 4);
  if ( *(_DWORD *)a2 != v4 )
  {
    v5 = *(_DWORD *)a2;
    do
    {
      std__string___string(v5 + 16);
      std__string___string(v5 + 12);
      std__string___string(v5 + 8);
      std__string___string(v5 + 4);
      std__string___string(v5);
      v5 += 36;
    }
    while ( v4 != v5 );
  }
  *(_DWORD *)(a2 + 4) = v3;
  while ( 1 )
  {
    if ( sub_805A590(a1, (int)&v46) != 1
      || !(unsigned __int8)sub_80516C0((int)&v45, (int)&v49, 0)
      || v45 != 1
      || (v7 = v50, (unsigned int)(v51 - v50) <= 0xC)
      || *(_BYTE *)(v50 + 6) != -38
      || *(_BYTE *)(v50 + 7) != 7
      || *(_BYTE *)(v50 + 11) != 1 )
      goto LABEL_10;
    if ( *(_BYTE *)(v50 + 12) == 10 )
    {
      v52 = 134771820;
      v53 = 134771820;
      v54 = 134771820;
      v55 = 134771820;
      v56 = 134771820;
      if ( (unsigned int)(v51 - v50) <= 0x12 )
      {
        v58 = (int)&v52;
        goto LABEL_50;
      }
      v57 = *(_DWORD *)(v50 + 15);
      v58 = (int)&v52;
      std__ios_base__ios_base(v6);
      v59 = 0;
      v60 = 134771496;
      v61 = 0;
      v36 = *(_DWORD *)(*(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[4]
                      - 12);
      v62 = *(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[4];
      v63 = 0;
      v64 = 0;
      *(signed int *)((char *)&v62 + v36) = *(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[8];
      v65 = 0;
      v66 = 0;
      v67 = 0;
      std__basic_ios_char_std__char_traits_char____init((char *)&v62 + *(_DWORD *)(v62 - 12), 0);
      v62 = 134771532;
      v60 = 134771552;
      v68 = 134771752;
      v69 = 0;
      v70 = 0;
      v71 = 0;
      v72 = 0;
      v73 = 0;
      v74 = 0;
      std__locale__locale(&v75);
      v68 = 134771432;
      v76 = 16;
      v77 = 134771820;
      std__basic_ios_char_std__char_traits_char____init(&v60, &v68);
      v58 = (int)&v52;
      std__ostream___M_insert_unsigned_long_(&v62, v57);
      v78 = 134771820;
      if ( v73 )
      {
        if ( v73 <= v71 )
        {
          v11 = &v78;
          v79 = 0;
          v95 = sub_8078490(v72, v71, (int)&v94);
          std__string__assign(&v78, &v95);
          std__string___string(&v95);
        }
        else
        {
          v11 = &v78;
          v79 = 0;
          v81 = sub_8078490(v72, v73, (int)&v80);
          std__string__assign(&v78, &v81);
          std__string___string(&v81);
        }
      }
      else
      {
        v11 = &v78;
        std__string__assign(&v78, &v77);
      }
      v58 = (int)&v52;
      std__string__assign(&v52, v11);
      _EDX = v78 - 12;
      if ( std__string___Rep___S_empty_rep_storage != (char *)(v78 - 12) )
      {
        if ( pthread_cancel )
        {
          _EAX = -1;
          __asm { lock xadd [edx+8], eax }
          v33 = _EAX;
        }
        else
        {
          v33 = *(_DWORD *)(_EDX + 8);
          *(_DWORD *)(_EDX + 8) = v33 - 1;
        }
        if ( v33 <= 0 )
          std__string___Rep___M_destroy(_EDX, &v96);
      }
      v15 = v51;
      v13 = v50;
      v14 = v51 - v50;
      if ( (unsigned int)(v51 - v50) <= 0x14 )
        goto LABEL_62;
      v16 = *(_WORD *)(v50 + 19);
      v17 = *(_WORD *)(v50 + 19);
      v82 = *(_WORD *)(v50 + 19);
      if ( (unsigned int)v16 + 21 > v14 )
        goto LABEL_62;
      if ( v17 > 1u )
      {
        std__string__assign(&v53, v50 + 21, v16 - 1);
        v15 = v51;
        v13 = v50;
        v14 = v51 - v50;
      }
      v19 = v82 + 23;
      v18 = v82 + 21;
      if ( v19 > v14 )
        goto LABEL_62;
      v20 = *(_WORD *)(v13 + v18);
      v21 = v15 - v13;
      v83 = *(_WORD *)(v13 + v18);
      v84 = v20;
      if ( v19 + (unsigned int)v20 > v15 - v13 )
        goto LABEL_62;
      if ( v20 > 1u )
      {
        std__string__assign(&v54, v13 + v19, v84 - 1);
        v15 = v51;
        v13 = v50;
        v21 = v51 - v50;
      }
      v22 = v19 + v83;
      v23 = v22 + 2;
      if ( v22 + 2 > (unsigned int)v21 )
        goto LABEL_62;
      v24 = *(_WORD *)(v13 + v22);
      v25 = v15 - v13;
      v85 = v24;
      v86 = v24;
      if ( v23 + (unsigned int)v24 > v15 - v13 )
        goto LABEL_62;
      if ( v24 > 1u )
      {
        std__string__assign(&v55, v13 + v23, v86 - 1);
        v15 = v51;
        v13 = v50;
        v25 = v51 - v50;
      }
      v26 = v23 + v85;
      v27 = v26 + 2;
      if ( v26 + 2 > (unsigned int)v25 )
        goto LABEL_62;
      v28 = *(_WORD *)(v13 + v26);
      v29 = v15 - v13;
      v87 = v28;
      v88 = v28;
      if ( v27 + (unsigned int)v28 > v15 - v13 )
        goto LABEL_62;
      if ( v28 > 1u )
      {
        std__string__assign(&v56, v13 + v27, v88 - 1);
        v15 = v51;
        v13 = v50;
        v29 = v51 - v50;
      }
      v30 = v27 + v87;
      if ( v29 < (unsigned int)(v30 + 1)
        || (v89 = *(_BYTE *)(v13 + v30) == 1, v31 = v15 - v13, v30 + 3 > (unsigned int)(v15 - v13))
        || (v90 = (*(_BYTE *)(v13 + v30 + 1) == 1) - 1, v30 + 4 > (unsigned int)v31)
        || (v91 = *(_BYTE *)(v13 + v30 + 3), v30 + 6 > (unsigned int)v31) )
      {
LABEL_62:
        v62 = 134771532;
        v60 = 134771552;
        v68 = 134771432;
        std__string___string(&v77);
        v68 = 134771752;
        std__locale___locale(&v75);
        v38 = *(_DWORD *)(*(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[4]
                        - 12);
        v62 = *(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[4];
        *(signed int *)((char *)&v62 + v38) = *(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[8];
        v60 = 134771496;
        std__ios_base___ios_base(&v60);
LABEL_50:
        std__string___string(&v56);
        std__string___string(&v55);
        std__string___string(&v54);
        std__string___string(&v53);
        std__string___string(v58);
LABEL_10:
        v8 = 0;
        goto LABEL_11;
      }
      v92 = *(_WORD *)(v13 + v30 + 4);
      v32 = *(_DWORD *)(a2 + 4);
      if ( v32 == *(_DWORD *)(a2 + 8) )
      {
        sub_807CC80(v30, a2, a2, *(_DWORD *)(a2 + 4), v58);
      }
      else
      {
        if ( v32 )
        {
          std__string__string(*(_DWORD *)(a2 + 4), v58);
          v93 = v32 + 4;
          std__string__string(v32 + 4, &v53);
          std__string__string(v32 + 8, &v54);
          std__string__string(v32 + 12, &v55);
          std__string__string(v32 + 16, &v56);
          *(_DWORD *)(v32 + 20) = v91;
          *(_BYTE *)(v32 + 24) = v89;
          *(_DWORD *)(v32 + 28) = v90;
          *(_WORD *)(v32 + 32) = v92;
          v32 = *(_DWORD *)(a2 + 4);
        }
        *(_DWORD *)(a2 + 4) = v32 + 36;
      }
      v62 = 134771532;
      v60 = 134771552;
      v68 = 134771432;
      std__string___string(&v77);
      v68 = 134771752;
      std__locale___locale(&v75);
      v37 = *(_DWORD *)(*(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[4]
                      - 12);
      v62 = *(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[4];
      *(signed int *)((char *)&v62 + v37) = *(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[8];
      v60 = 134771496;
      std__ios_base___ios_base(&v60);
      std__string___string(&v56);
      std__string___string(&v55);
      std__string___string(&v54);
      std__string___string(&v53);
      std__string___string(v58);
      v7 = v50;
    }
    v10 = *(_BYTE *)(v7 + 10);
    if ( v10 == -82 )
      break;
    if ( v10 != -92 )
      goto LABEL_10;
  }
  v8 = 1;
LABEL_11:
  sub_8052330(v6, (int)&v46, (int)&v46);
  sub_8052370(v34, v35, (int)&v45);
  return v8;
}

//----- (0806DE60) --------------------------------------------------------
char *__cdecl sub_806DE60(int a1, int a2, int a3)
{
  char *result; // eax@1
  int v4; // edi@1
  int v5; // esi@1
  int v6; // ebx@2
  int v8; // ecx@5
  int v9; // esi@5
  int v10; // ebx@7
  int v11; // edx@10
  int v12; // esi@10
  int v13; // ebx@12
  int v15; // esi@19
  unsigned __int16 v16; // ax@20
  unsigned __int16 v17; // dx@20
  char *v18; // ecx@25
  int v19; // ecx@31
  unsigned __int8 v20; // al@8
  char v21; // al@19
  signed int v33; // [sp+30h] [bp-18h]@8
  signed int *v34; // [sp+10h] [bp-38h]@8
  unsigned __int8 v35; // [sp+3Bh] [bp-Dh]@8
  unsigned int v36; // [sp+18h] [bp-30h]@10
  int v37; // [sp+14h] [bp-34h]@10
  unsigned __int16 v38; // [sp+36h] [bp-12h]@12
  int v39; // [sp+28h] [bp-20h]@12
  char v40; // [sp+3Ah] [bp-Eh]@12
  char v41; // [sp+2Ch] [bp-1Ch]@12
  char v42; // [sp+39h] [bp-Fh]@27
  char v43; // [sp+38h] [bp-10h]@33

  result = (char *)a3;
  v4 = *(_DWORD *)(a3 + 88);
  v5 = *(_DWORD *)(a3 + 92);
  if ( v4 != v5 )
  {
    v6 = *(_DWORD *)(a3 + 88);
    do
    {
      _EDX = *(_DWORD *)v6 - 12;
      result = std__string___Rep___S_empty_rep_storage;
      if ( std__string___Rep___S_empty_rep_storage != (char *)_EDX )
      {
        if ( pthread_cancel )
        {
          _EAX = -1;
          __asm { lock xadd [edx+8], eax }
          v18 = result;
        }
        else
        {
          v18 = *(char **)(_EDX + 8);
          result = v18 - 1;
          *(_DWORD *)(_EDX + 8) = v18 - 1;
        }
        if ( (signed int)v18 <= 0 )
          result = (char *)std__string___Rep___M_destroy(_EDX, &v42);
      }
      v6 += 8;
    }
    while ( v5 != v6 );
  }
  v9 = a2;
  v8 = *(_DWORD *)a2;
  *(_DWORD *)(a3 + 92) = v4;
  if ( *(_BYTE *)(v8 + 16) == 10 )
  {
    v10 = *(_DWORD *)(v9 + 4);
    if ( (unsigned int)(v10 - v8) > 0x11 )
    {
      v20 = *(_BYTE *)(v8 + 17);
      v33 = 134771820;
      v34 = &v33;
      v35 = v20;
      if ( v20 )
      {
        v34 = &v33;
        if ( (unsigned int)(v10 - v8) > 0x12 )
        {
          v12 = 18;
          v36 = 0;
          v34 = &v33;
          v37 = a3 + 88;
          v11 = 19;
          do
          {
            v21 = *(_BYTE *)(v8 + v12);
            v15 = v11 + 2;
            v40 = v21;
            if ( v11 + 2 > (unsigned int)(v10 - v8) )
              break;
            v16 = *(_WORD *)(v8 + v11);
            v17 = *(_WORD *)(v8 + v11);
            v38 = v16;
            if ( v15 + (unsigned int)v16 > v10 - v8 )
              break;
            if ( v17 > 1u )
              std__string__assign(v34, v8 + v15, v16 - 1);
            else
              std__string__assign(v34, &aResNr[13], 0);
            v12 = v38 + v15;
            std__string__string(&v39, v34);
            v41 = v40;
            v13 = *(_DWORD *)(a3 + 92);
            if ( v13 == *(_DWORD *)(a3 + 96) )
            {
              sub_807DB50(v37, v13, (int)&v39);
            }
            else
            {
              if ( v13 )
              {
                std__string__string(v13, &v39);
                *(_BYTE *)(v13 + 4) = v41;
                v13 = *(_DWORD *)(a3 + 92);
              }
              *(_DWORD *)(a3 + 92) = v13 + 8;
            }
            _EDX = v39 - 12;
            if ( std__string___Rep___S_empty_rep_storage != (char *)(v39 - 12) )
            {
              if ( pthread_cancel )
              {
                _EAX = -1;
                __asm { lock xadd [edx+8], eax }
                v19 = _EAX;
              }
              else
              {
                v19 = *(_DWORD *)(_EDX + 8);
                *(_DWORD *)(_EDX + 8) = v19 - 1;
              }
              if ( v19 <= 0 )
                std__string___Rep___M_destroy(_EDX, &v43);
            }
            ++v36;
            if ( v35 <= v36 )
              goto LABEL_29;
            v10 = *(_DWORD *)(a2 + 4);
            v8 = *(_DWORD *)a2;
            v11 = v12 + 1;
          }
          while ( v12 + 1 <= (unsigned int)(v10 - *(_DWORD *)a2) );
        }
        result = (char *)std__string___string(v34);
      }
      else
      {
LABEL_29:
        result = (char *)std__string___string(v34);
      }
    }
  }
  return result;
}

//----- (0806E100) --------------------------------------------------------
signed int __cdecl sub_806E100(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ecx@1
  signed int v5; // ebx@6
  char v7; // zf@8
  __int32 *v8; // edi@9
  int v9; // esi@9
  char v10; // al@16
  const char *v11; // eax@1
  __int16 v12; // [sp+20h] [bp-28h]@1
  int v13; // [sp+28h] [bp-20h]@1
  __int16 v14; // [sp+22h] [bp-26h]@1
  __int16 v15; // [sp+24h] [bp-24h]@1
  __int32 v16; // [sp+38h] [bp-10h]@1
  __int32 *v17; // [sp+18h] [bp-30h]@1
  int v18; // [sp+30h] [bp-18h]@4
  int v19; // [sp+2Ch] [bp-1Ch]@4

  sub_8050F20((int)&v12);
  v13 = a3;
  v11 = *(const char **)(a1 + 124);
  v12 = 21;
  v14 = 3;
  v15 = 1;
  v17 = &v16;
  v16 = strtol(v11, 0, 10);
LABEL_2:
  while ( v15 & 1 )
  {
    while ( 1 )
    {
      if ( sub_805A590(a1, (int)&v12) != 1 )
        goto LABEL_43;
      if ( (unsigned int)(v18 - v19) <= 0x10 )
        goto LABEL_43;
      if ( *(_BYTE *)v19 )
        goto LABEL_43;
      v7 = *(_BYTE *)(v19 + 1) == 1;
      if ( *(_BYTE *)(v19 + 1) != 1 )
        goto LABEL_43;
      v8 = v17;
      v9 = v19 + 6;
      v4 = 4;
      do
      {
        if ( !v4 )
          break;
        v7 = *(_BYTE *)v9++ == *(_BYTE *)v8;
        v8 = (__int32 *)((char *)v8 + 1);
        --v4;
      }
      while ( v7 );
      if ( !v7 || *(_BYTE *)(v19 + 10) != -38 || *(_BYTE *)(v19 + 11) != 7 )
      {
LABEL_43:
        v5 = 0;
        goto LABEL_7;
      }
      v10 = *(_BYTE *)(v19 + 14);
      if ( v10 == -56 )
        break;
      if ( v10 == -36 )
      {
        if ( !*(_BYTE *)(v19 + 15) )
          sub_80592D0(a1, (int)&v19, a2);
        goto LABEL_2;
      }
      if ( v10 != -21 )
      {
        switch ( v10 )
        {
          case 0xE:
            if ( *(_BYTE *)(v19 + 15) == 1 )
              sub_8059210(a1, (int)&v19, a2);
            break;
          case 0xD2:
            if ( !*(_BYTE *)(v19 + 15) )
              sub_8058CF0(a1, (int)&v19, a2);
            break;
          case 0xE6:
            if ( !*(_BYTE *)(v19 + 15) )
              sub_8058C60(a1, (int)&v19, a2);
            break;
          case 0xF0:
            if ( !*(_BYTE *)(v19 + 15) )
              sub_80589D0(a1, (int)&v19, a2);
            break;
          case 0xFA:
            if ( !*(_BYTE *)(v19 + 15) )
              sub_8058600(a1, (int)&v19, a2);
            break;
        }
        goto LABEL_2;
      }
      if ( *(_BYTE *)(v19 + 15) )
        goto LABEL_2;
      sub_806DE60(a1, (int)&v19, a2);
      if ( !(v15 & 1) )
        goto LABEL_21;
    }
    if ( !*(_BYTE *)(v19 + 15) )
      sub_80595B0(a1, (int)&v19, a2);
  }
LABEL_21:
  v5 = 1;
LABEL_7:
  sub_8052330(v4, v3, (int)&v12);
  return v5;
}

//----- (0806E5C0) --------------------------------------------------------
signed int __usercall sub_806E5C0<eax>(int a1<ebx>, int a2, int a3)
{
  int v3; // edx@6
  int v4; // ecx@6
  __int16 v5; // ax@7
  int v6; // ecx@7
  int v7; // edx@8
  int v8; // ecx@8
  signed int v9; // eax@14
  int v10; // ecx@15
  signed int v11; // eax@18
  int v13; // eax@25
  int v14; // edx@29
  signed int result; // eax@33
  int v16; // edx@36
  unsigned int v17; // esi@36
  signed int v18; // eax@37
  int v19; // edx@43
  int v20; // ecx@43
  int v21; // esi@43
  int v22; // edx@15
  int v23; // eax@19
  int v30; // [sp+D8h] [bp-10h]@1
  int v31; // [sp+14h] [bp-D4h]@1
  int v32; // [sp+18h] [bp-D0h]@1
  int v33; // [sp+28h] [bp-C0h]@2
  int v34; // [sp+20h] [bp-C8h]@2
  int v35; // [sp+24h] [bp-C4h]@2
  __int16 v36; // [sp+38h] [bp-B0h]@4
  unsigned __int16 v37; // [sp+1Ch] [bp-CCh]@5
  unsigned __int16 v38; // [sp+1Eh] [bp-CAh]@5
  unsigned __int16 v39; // [sp+30h] [bp-B8h]@5
  __int16 v40; // [sp+3Ch] [bp-ACh]@7
  unsigned __int16 v41; // [sp+3Eh] [bp-AAh]@7
  signed int v42; // [sp+58h] [bp-90h]@8
  signed int v43; // [sp+5Ch] [bp-8Ch]@8
  signed int v44; // [sp+64h] [bp-84h]@8
  int v45; // [sp+90h] [bp-58h]@8
  int v46; // [sp+94h] [bp-54h]@8
  int v47; // [sp+98h] [bp-50h]@8
  signed int v48; // [sp+ACh] [bp-3Ch]@8
  signed int v49; // [sp+B0h] [bp-38h]@8
  signed int v50; // [sp+B8h] [bp-30h]@8
  signed int v51; // [sp+BCh] [bp-2Ch]@8
  signed int v52; // [sp+C0h] [bp-28h]@8
  signed int v53; // [sp+C4h] [bp-24h]@8
  signed int v54; // [sp+C8h] [bp-20h]@8
  __int16 v55; // [sp+60h] [bp-88h]@8
  __int16 v56; // [sp+68h] [bp-80h]@8
  char v57; // [sp+6Ah] [bp-7Eh]@8
  int v58; // [sp+6Ch] [bp-7Ch]@8
  int v59; // [sp+70h] [bp-78h]@8
  int v60; // [sp+74h] [bp-74h]@8
  char v61; // [sp+78h] [bp-70h]@8
  __int16 v62; // [sp+7Ah] [bp-6Eh]@8
  char v63; // [sp+7Ch] [bp-6Ch]@8
  int v64; // [sp+7Dh] [bp-6Bh]@8
  int v65; // [sp+81h] [bp-67h]@8
  int v66; // [sp+85h] [bp-63h]@8
  int v67; // [sp+89h] [bp-5Fh]@8
  signed int v68; // [sp+9Ch] [bp-4Ch]@8
  int v69; // [sp+A0h] [bp-48h]@8
  char v70; // [sp+A4h] [bp-44h]@8
  int v71; // [sp+A8h] [bp-40h]@8
  char v72; // [sp+B4h] [bp-34h]@8
  char v73; // [sp+B5h] [bp-33h]@8
  char v74; // [sp+B6h] [bp-32h]@8
  int v75; // [sp+CCh] [bp-1Ch]@8
  int v76; // [sp+D0h] [bp-18h]@8
  char v77; // [sp+34h] [bp-B4h]@8
  __int16 v78; // [sp+3Ah] [bp-AEh]@8
  int v79; // [sp+44h] [bp-A4h]@8
  int v80; // [sp+40h] [bp-A8h]@8
  int v81; // [sp+D4h] [bp-14h]@15
  signed int v82; // [sp+50h] [bp-98h]@18
  __int16 v83; // [sp+4Ch] [bp-9Ch]@18
  char v84; // [sp+57h] [bp-91h]@24

  v30 = *MK_FP(__GS__, 20);
  v31 = a3;
  v32 = a2;
  if ( *(_DWORD *)a3 == *(_DWORD *)(a3 + 4) )
  {
LABEL_36:
    v17 = 0;
    v16 = *(_DWORD *)(v32 + 4);
    if ( (*(_DWORD *)(v32 + 8) - v16) >> 7 )
    {
      do
      {
        a1 = v17 << 7;
        v18 = sub_8058090(v32, *(_WORD *)(v16 + (v17 << 7) + 8));
        if ( v18 >= 0 )
        {
          a1 += *(_DWORD *)(v32 + 4);
          std__string__assign(a1 + 12, *(_DWORD *)(v32 + 16) + 8 * v18 + 4);
        }
        ++v17;
        v16 = *(_DWORD *)(v32 + 4);
      }
      while ( v17 < (*(_DWORD *)(v32 + 8) - v16) >> 7 );
    }
    result = 1;
  }
  else
  {
    v33 = 0;
    v34 = v32 + 4;
    v35 = v32 + 16;
    while ( 1 )
    {
      sub_80512C0((int)&v39);
      if ( !(unsigned __int8)sub_8054AF0((int)&v39, v31, v33) )
        break;
      v5 = v40;
      v6 = v41;
      v37 = v39;
      v38 = v41;
      if ( !v40 )
      {
        v42 = 134771820;
        v43 = 134771820;
        v44 = 134771820;
        v45 = 0;
        v46 = 0;
        v47 = 0;
        v48 = 134771820;
        v49 = 134771820;
        v50 = 134771820;
        v51 = 134771820;
        v52 = 134771820;
        v53 = 134771820;
        v54 = 134771820;
        v55 = 0;
        v56 = 0;
        v57 = 0;
        v58 = 0;
        v59 = 0;
        v60 = 0;
        v61 = 0;
        v62 = 0;
        v63 = 0;
        v64 = 0;
        v65 = 0;
        v66 = 0;
        v67 = 0;
        v68 = -1;
        v69 = 0;
        v70 = 0;
        v71 = 0;
        v72 = 0;
        v73 = 0;
        v74 = 0;
        v75 = 0;
        v76 = 0;
        std__string__assign(&v42, &v77);
        v55 = v36;
        v56 = v78;
        std__string__assign(&v43, &aResNr[13], 0);
        std__string__assign(&v44, &aResNr[13], 0);
        v8 = v79;
        v7 = v80;
        v57 = 0;
        if ( (v79 - v80) >> 4 )
        {
          a1 = 0;
          do
          {
            while ( 1 )
            {
              if ( *(_WORD *)(v7 + 16 * a1) == 305 )
              {
                sub_8051550(v7 + 16 * a1, (int)&v43);
                v7 = v80;
                v8 = v79;
              }
              if ( *(_WORD *)(v7 + 16 * a1) == 102 )
                break;
              ++a1;
              if ( a1 >= (unsigned int)((v8 - v7) >> 4) )
                goto LABEL_14;
            }
            ++a1;
            v57 = 1;
          }
          while ( a1 < (unsigned int)((v8 - v7) >> 4) );
        }
LABEL_14:
        v9 = sub_8058030(v32, v56);
        if ( v9 < 0 )
        {
          v13 = *(_DWORD *)(v32 + 8);
          if ( v13 == *(_DWORD *)(v32 + 12) )
          {
            sub_807BC40(v34, v13, (int)&v42);
          }
          else
          {
            if ( v13 )
            {
              sub_8078C30(v13, (int)&v42);
              v13 = *(_DWORD *)(v32 + 8);
            }
            v10 = v32;
            *(_DWORD *)(v32 + 8) = v13 + 128;
          }
        }
        else
        {
          a1 = *(_DWORD *)(v32 + 4) + (v9 << 7);
          std__string__assign(*(_DWORD *)(v32 + 4) + (v9 << 7), &v42);
          std__string__assign(a1 + 4, &v43);
          *(_WORD *)(a1 + 8) = v55;
          std__string__assign(a1 + 12, &v44);
          *(_WORD *)(a1 + 16) = v56;
          *(_BYTE *)(a1 + 18) = v57;
          *(_DWORD *)(a1 + 20) = v58;
          *(_DWORD *)(a1 + 24) = v59;
          *(_DWORD *)(a1 + 28) = v60;
          *(_BYTE *)(a1 + 32) = v61;
          *(_WORD *)(a1 + 34) = v62;
          *(_BYTE *)(a1 + 36) = v63;
          *(_DWORD *)(a1 + 37) = v64;
          *(_DWORD *)(a1 + 41) = v65;
          *(_DWORD *)(a1 + 45) = v66;
          *(_DWORD *)(a1 + 49) = v67;
          sub_804B500(v10, v22, a1 + 56, (int)&v45);
          *(_DWORD *)(a1 + 68) = v68;
          *(_DWORD *)(a1 + 72) = v69;
          *(_BYTE *)(a1 + 76) = v70;
          *(_DWORD *)(a1 + 80) = v71;
          std__string__assign(a1 + 84, &v48);
          std__string__assign(a1 + 88, &v49);
          *(_BYTE *)(a1 + 92) = v72;
          *(_BYTE *)(a1 + 93) = v73;
          *(_BYTE *)(a1 + 94) = v74;
          std__string__assign(a1 + 96, &v50);
          std__string__assign(a1 + 100, &v51);
          std__string__assign(a1 + 104, &v52);
          std__string__assign(a1 + 108, &v53);
          std__string__assign(a1 + 112, &v54);
          *(_DWORD *)(a1 + 116) = v75;
          *(_DWORD *)(a1 + 120) = v76;
          *(_DWORD *)(a1 + 124) = v81;
        }
        sub_807B640(v6, (int)&v42, (int)&v42);
        v5 = v40;
      }
      if ( v5 == 1 )
      {
        if ( v36 )
        {
          a1 = (int)&v82;
          v82 = 134771820;
          v83 = v36;
          std__string__assign(&v82, &v77);
          v11 = sub_8058090(v32, v83);
          if ( v11 < 0 )
          {
            v6 = v32;
            v14 = *(_DWORD *)(v32 + 20);
            if ( v14 == *(_DWORD *)(v32 + 24) )
            {
              sub_807DEF0(v35, v14, (int)&v83);
            }
            else
            {
              if ( v14 )
              {
                *(_WORD *)v14 = v83;
                std__string__string(v14 + 4, &v82);
                v14 = *(_DWORD *)(v32 + 20);
              }
              *(_DWORD *)(v32 + 20) = v14 + 8;
            }
          }
          else
          {
            v23 = *(_DWORD *)(v32 + 16) + 8 * v11;
            *(_WORD *)v23 = v83;
            std__string__assign(v23 + 4, &v82);
          }
          _EDX = v82 - 12;
          if ( std__string___Rep___S_empty_rep_storage != (char *)(v82 - 12) )
          {
            if ( pthread_cancel )
            {
              _EAX = -1;
              __asm { lock xadd [edx+8], eax }
              v6 = _EAX;
            }
            else
            {
              v6 = *(_DWORD *)(_EDX + 8);
              *(_DWORD *)(_EDX + 8) = v6 - 1;
            }
            if ( v6 <= 0 )
              std__string___Rep___M_destroy(_EDX, &v84);
          }
        }
      }
      v33 += v37 + v38 + 10;
      sub_80549C0(v6, (int)&v39, (int)&v39);
      if ( v33 >= (unsigned int)(*(_DWORD *)(v31 + 4) - *(_DWORD *)v31) )
        goto LABEL_36;
    }
    sub_80549C0(v4, v3, (int)&v39);
    result = 0;
  }
  if ( *MK_FP(__GS__, 20) ^ v30 )
  {
    v21 = __stack_chk_fail();
    sub_807B640(v20, v19, (int)&v42);
    while ( 1 )
    {
      sub_80549C0(v20, v19, (int)&v39);
      v21 = _Unwind_Resume(v21);
      std__string___string(a1);
    }
  }
  return result;
}

//----- (0806ED00) --------------------------------------------------------
signed int __cdecl sub_806ED00(int a1, int a2, int a3, int a4, int a5)
{
  int v6; // edx@4
  int v7; // ecx@4
  signed int v8; // ebx@4
  int v9; // edx@5
  int v10; // ecx@5
  int v12; // edx@8
  int v14; // ecx@21
  unsigned int v15; // eax@1
  int v16; // ST00_4@1
  __int16 v17; // ax@1
  int v18; // ecx@1
  int v19; // edx@1
  int v20; // ecx@3
  int v27; // [sp+134h] [bp-38h]@1
  int v28; // [sp+138h] [bp-34h]@1
  int v29; // [sp+13Ch] [bp-30h]@1
  signed int v30; // [sp+154h] [bp-18h]@1
  __int16 v31; // [sp+3Ah] [bp-132h]@1
  __int16 v32; // [sp+38h] [bp-134h]@1
  __int64 v33; // [sp+2Ch] [bp-140h]@1
  int v34; // [sp+28h] [bp-144h]@1
  __int16 v35; // [sp+158h] [bp-14h]@1
  char v36; // [sp+15Ah] [bp-12h]@1
  int v37; // [sp+128h] [bp-44h]@1
  int v38; // [sp+12Ch] [bp-40h]@1
  int v39; // [sp+130h] [bp-3Ch]@1
  __int16 v40; // [sp+124h] [bp-48h]@1
  int v41; // [sp+150h] [bp-1Ch]@2
  int v42; // [sp+118h] [bp-54h]@2
  int v43; // [sp+11Ch] [bp-50h]@2
  int v44; // [sp+120h] [bp-4Ch]@2
  char v45; // [sp+140h] [bp-2Ch]@2
  __int16 v46; // [sp+114h] [bp-58h]@2
  int v47; // [sp+14Ch] [bp-20h]@4
  __int16 v48; // [sp+FCh] [bp-70h]@8
  __int16 v49; // [sp+FEh] [bp-6Eh]@8
  int v50; // [sp+104h] [bp-68h]@8
  int v51; // [sp+108h] [bp-64h]@12
  int v52; // [sp+10Ch] [bp-60h]@12
  int v53; // [sp+148h] [bp-24h]@19
  char v54; // [sp+48h] [bp-124h]@19
  char v55; // [sp+144h] [bp-28h]@19
  char v56; // [sp+15Bh] [bp-11h]@23

  v27 = 0;
  v28 = 0;
  v29 = 0;
  v15 = time(0);
  srand(v15);
  v30 = 0;
  v16 = rand();
  __asm
  {
    fild    [esp+16Ch+var_16C]
    fmul    ds:flt_807FDC0
    fnstcw  [ebp+var_132]
  }
  LOBYTE(v17) = v31;
  __asm { fmul    ds:flt_807FDC4 }
  HIBYTE(v17) = 12;
  v32 = v17;
  __asm
  {
    fldcw   [ebp+var_134]
    fistp   [ebp+var_140]
    fldcw   [ebp+var_132]
  }
  v34 = v33;
  sub_8078660(&v27, v28, &v30, &v35);
  v35 = 40;
  sub_8078660(&v27, v28, &v35, &v36);
  v35 = 0;
  sub_8078660(&v27, v28, &v35, &v36);
  v30 = 0;
  sub_8078660(&v27, v28, &v30, &v35);
  v30 = 0;
  sub_8078660(&v27, v28, &v30, &v35);
  v30 = v33;
  sub_8078660(&v27, v28, &v30, &v35);
  v30 = v33;
  sub_8078660(&v27, v28, &v30, &v35);
  v30 = 0;
  sub_8078660(&v27, v28, &v30, &v35);
  v30 = 0;
  sub_8078660(&v27, v28, &v30, &v35);
  v30 = 0;
  sub_8078660(&v27, v28, &v30, &v35);
  v30 = 0;
  sub_8078660(&v27, v28, &v30, &v35);
  v35 = (unsigned __int16)*(_DWORD *)(*(_DWORD *)a3 - 12) + 1;
  sub_8078660(&v27, v28, &v35, &v36);
  sub_8078660(&v27, v28, *(_DWORD *)a3, *(_DWORD *)a3 + *(_DWORD *)(*(_DWORD *)a3 - 12) + 1);
  v30 = v33;
  sub_8078660(&v27, v28, &v30, &v35);
  v30 = 30474240;
  sub_8078660(&v27, v28, &v30, &v35);
  v37 = 0;
  v38 = 0;
  v39 = 0;
  sub_804B500(v18, v19, (int)&v37, (int)&v27);
  v40 = 1;
  v28 = v27;
  sub_80528B0((int)&v40, (int)&v27, 0);
  if ( a5 )
  {
    std__string__string(&v41, a5);
    v42 = 0;
    v43 = 0;
    v44 = 0;
    std__string__string(&v45, &v41);
    sub_8051C40((int)&v46, (int)&v45);
    std__string___string(&v45);
    v46 = 9;
    _EDX = v41 - 12;
    if ( v41 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
    {
      if ( pthread_cancel )
      {
        _EAX = -1;
        __asm { lock xadd [edx+8], eax }
        v14 = _EAX;
      }
      else
      {
        v14 = *(_DWORD *)(_EDX + 8);
        *(_DWORD *)(_EDX + 8) = v14 - 1;
      }
      if ( v14 <= 0 )
        std__string___Rep___M_destroy(_EDX, &v56);
    }
    sub_80528B0((int)&v46, (int)&v27, v28 - v27);
    sub_8052370(v20, (int)&v46, (int)&v46);
  }
  v8 = 0;
  if ( sub_805A180(a2, 23, 4, (int)&v47, (int)&v27) == 1 )
  {
    sub_8050F20((int)&v48);
    v48 = 23;
    v49 = 0;
    v50 = v47;
    if ( sub_805A590(a2, (int)&v48) != 1
      || v49 != 5
      || (v12 = v51, (unsigned int)(v52 - v51) <= 0x35)
      || *(_BYTE *)v51
      || *(_BYTE *)(v51 + 1) != 1
      || *(_BYTE *)(v51 + 10) != 45
      || *(_BYTE *)(v51 + 11)
      || *(_BYTE *)(v51 + 12)
      || *(_BYTE *)(v51 + 13) )
    {
      v8 = 0;
    }
    else
    {
      v53 = *(_DWORD *)(v51 + 46);
      std__basic_ostringstream_char_std__char_traits_char__std__allocator_char____basic_ostringstream(&v54, 16);
      std__ostream___M_insert_unsigned_long_(&v54, v53);
      std__basic_ostringstream_char_std__char_traits_char__std__allocator_char____str(&v55, &v54);
      std__string__assign(a4, &v55);
      std__string___string(&v55);
      std__basic_ostringstream_char_std__char_traits_char__std__allocator_char_____basic_ostringstream(&v54);
      v8 = 1;
    }
    sub_8052330(v7, v6, (int)&v48);
  }
  sub_8052370(v7, v6, (int)&v40);
  if ( v27 )
    operator delete(v10, v9);
  return v8;
}

//----- (0806F530) --------------------------------------------------------
signed int __cdecl sub_806F530(int a1, int a2, int a3, char a4)
{
  int v4; // eax@3
  unsigned int v5; // ecx@5
  unsigned int v6; // ebx@5
  int v7; // esi@5
  char v8; // cf@7
  unsigned __int8 v9; // zf@7
  int v10; // edi@7
  int v11; // eax@11
  int v12; // eax@16
  int v13; // edx@16
  unsigned int v14; // ecx@16
  unsigned int v15; // ebx@16
  unsigned int v16; // esi@16
  char v17; // cf@17
  unsigned __int8 v18; // zf@17
  int v19; // edi@17
  int v20; // esi@17
  int v21; // eax@21
  char v23; // bl@25
  signed int result; // eax@27
  int v25; // ecx@35
  int v26; // ecx@1
  unsigned int v27; // edi@2
  int v28; // edi@4
  char v29; // dl@11
  char v30; // dl@21
  int v31; // esi@32
  int v32; // edi@32
  int v33; // eax@32
  char v40; // [sp+2Bh] [bp-2Dh]@1
  int v41; // [sp+2Ch] [bp-2Ch]@1
  int v42; // [sp+14h] [bp-44h]@1
  int v43; // [sp+38h] [bp-20h]@2
  int v44; // [sp+30h] [bp-28h]@2
  unsigned int v45; // [sp+34h] [bp-24h]@2
  int v46; // [sp+10h] [bp-48h]@16
  int v47; // [sp+40h] [bp-18h]@25
  int v48; // [sp+44h] [bp-14h]@25
  char v49; // [sp+4Bh] [bp-Dh]@37

  v26 = *(_DWORD *)(a1 + 232);
  v40 = a4;
  v41 = a1 + 228;
  v42 = v26;
  if ( v26 )
  {
    v43 = a1 + 228;
    v27 = *(_DWORD *)(*(_DWORD *)a2 - 12);
    v44 = *(_DWORD *)a2;
    v45 = v27;
    while ( 1 )
    {
      v7 = *(_DWORD *)(v42 + 16);
      v6 = *(_DWORD *)(v7 - 12);
      v5 = *(_DWORD *)(v7 - 12);
      if ( v6 > v45 )
        v5 = v45;
      v10 = v44;
      v8 = v5 < v5;
      v9 = 1;
      do
      {
        if ( !v5 )
          break;
        v8 = *(_BYTE *)v7 < *(_BYTE *)v10;
        v9 = *(_BYTE *)v7++ == *(_BYTE *)v10++;
        --v5;
      }
      while ( v9 );
      v29 = !(v8 | v9) - v8;
      v11 = v29;
      if ( !v29 )
        v11 = v6 - v45;
      if ( v11 >= 0 )
      {
        v4 = *(_DWORD *)(v42 + 8);
        if ( !v4 )
          goto LABEL_15;
      }
      else
      {
        v4 = *(_DWORD *)(v42 + 12);
        v42 = v43;
        if ( !v4 )
          goto LABEL_15;
      }
      v28 = v42;
      v42 = v4;
      v43 = v28;
    }
  }
  v42 = v41;
LABEL_15:
  if ( v42 == v41 )
    goto LABEL_41;
  v13 = *(_DWORD *)a2;
  v12 = *(_DWORD *)(v42 + 16);
  v16 = *(_DWORD *)(*(_DWORD *)a2 - 12);
  v15 = *(_DWORD *)(v12 - 12);
  v46 = *(_DWORD *)(*(_DWORD *)a2 - 12);
  v14 = v15;
  if ( v15 > v16 )
    v14 = v16;
  v20 = v13;
  v19 = v12;
  v17 = v14 < v14;
  v18 = 1;
  do
  {
    if ( !v14 )
      break;
    v17 = *(_BYTE *)v20 < *(_BYTE *)v19;
    v18 = *(_BYTE *)v20++ == *(_BYTE *)v19++;
    --v14;
  }
  while ( v18 );
  v30 = !(v17 | v18) - v17;
  v21 = v30;
  if ( !v30 )
    v21 = v46 - v15;
  if ( v21 < 0 || v40 )
  {
LABEL_41:
    std__string__string(&v47, a2);
    v23 = sub_805C0F0(a1, (const char **)&v47, (int)&v48);
    _EDX = v47 - 12;
    if ( v47 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
    {
      if ( pthread_cancel )
      {
        _EAX = -1;
        __asm { lock xadd [edx+8], eax }
        v25 = _EAX;
      }
      else
      {
        v25 = *(_DWORD *)(_EDX + 8);
        *(_DWORD *)(_EDX + 8) = v25 - 1;
      }
      if ( v25 <= 0 )
        std__string___Rep___M_destroy(_EDX, &v49);
    }
    if ( v23 && (unsigned __int8)sub_806E100(a1, a3, v48) )
    {
      v31 = a2;
      v32 = a3;
      std__string__assign(a3, a2);
      v33 = sub_807D6D0(a1 + 224, v31);
      sub_807AD50(v33, v32);
      result = 1;
    }
    else
    {
      result = 0;
    }
  }
  else
  {
    sub_807AD50(a3, v42 + 20);
    result = 1;
  }
  return result;
}

//----- (0806FE30) --------------------------------------------------------
int __usercall sub_806FE30<eax>(signed int *a1<esi>, int a2, const void **a3, int a4)
{
  int result; // eax@1
  int v5; // ebx@1
  const void **v6; // edi@1
  int v7; // edx@4
  int v8; // eax@6
  int v9; // edx@6
  const void *v10; // ecx@6
  int v11; // edx@8
  int v12; // ebx@8
  int v13; // ecx@9
  signed int *v15; // ebx@12
  int v17; // edx@14
  int v18; // ecx@14
  int v20; // ecx@18
  int v21; // ecx@27
  int v22; // ecx@31
  int v23; // eax@6
  int v24; // edx@10
  int v25; // eax@10
  int v26; // ebx@10
  int v27; // eax@10
  int v28; // eax@10
  int v29; // eax@10
  int v30; // edx@14
  int v49; // [sp+158h] [bp-10h]@1
  int v50; // [sp+24h] [bp-144h]@1
  int v51; // [sp+E0h] [bp-88h]@4
  int v52; // [sp+E4h] [bp-84h]@4
  int v53; // [sp+E8h] [bp-80h]@4
  char v54; // [sp+FFh] [bp-69h]@4
  int v55; // [sp+28h] [bp-140h]@8
  signed int v56; // [sp+2Ch] [bp-13Ch]@10
  char v57; // [sp+CCh] [bp-9Ch]@10
  signed int v58; // [sp+58h] [bp-110h]@10
  int v59; // [sp+C8h] [bp-A0h]@10
  char v60; // [sp+CDh] [bp-9Bh]@10
  int v61; // [sp+D0h] [bp-98h]@10
  int v62; // [sp+D4h] [bp-94h]@10
  int v63; // [sp+D8h] [bp-90h]@10
  int v64; // [sp+DCh] [bp-8Ch]@10
  signed int v65; // [sp+30h] [bp-138h]@10
  int v66; // [sp+34h] [bp-134h]@10
  int v67; // [sp+38h] [bp-130h]@10
  const void *v68; // [sp+3Ch] [bp-12Ch]@10
  const void *v69; // [sp+40h] [bp-128h]@10
  const void *v70; // [sp+44h] [bp-124h]@10
  int v71; // [sp+48h] [bp-120h]@10
  char v72; // [sp+4Ch] [bp-11Ch]@10
  signed int v73; // [sp+50h] [bp-118h]@10
  signed int v74; // [sp+54h] [bp-114h]@10
  signed int v75; // [sp+148h] [bp-20h]@10
  signed int v76; // [sp+14Ch] [bp-1Ch]@10
  signed int v77; // [sp+150h] [bp-18h]@10
  signed int v78; // [sp+154h] [bp-14h]@10
  __int16 v79; // [sp+100h] [bp-68h]@10
  __int16 v80; // [sp+102h] [bp-66h]@10
  char v81; // [sp+104h] [bp-64h]@10
  char v82; // [sp+105h] [bp-63h]@10
  __int16 v83; // [sp+106h] [bp-62h]@10
  __int16 v84; // [sp+108h] [bp-60h]@10
  char v85; // [sp+10Ch] [bp-5Ch]@10
  __int16 v86; // [sp+12Ch] [bp-3Ch]@10
  signed int v87; // [sp+11Ch] [bp-4Ch]@10
  signed int v88; // [sp+120h] [bp-48h]@10
  signed int v89; // [sp+124h] [bp-44h]@10
  signed int v90; // [sp+128h] [bp-40h]@10
  char v91; // [sp+130h] [bp-38h]@10
  signed int v92; // [sp+F4h] [bp-74h]@10
  char v93; // [sp+FDh] [bp-6Bh]@12
  int v94; // [sp+ECh] [bp-7Ch]@12
  char v95; // [sp+134h] [bp-34h]@13
  char v96; // [sp+FEh] [bp-6Ah]@16
  int v97; // [sp+F0h] [bp-78h]@16
  char v98; // [sp+FCh] [bp-6Ch]@20
  char v99; // [sp+FAh] [bp-6Eh]@29
  char v100; // [sp+FBh] [bp-6Dh]@33

  v49 = *MK_FP(__GS__, 20);
  v6 = a3;
  v5 = a4;
  v50 = a2;
  result = *(_DWORD *)(a2 + 108) - 1;
  if ( (unsigned int)result <= 0x21 )
  {
    v51 = 0;
    v52 = 0;
    v53 = 0;
    v54 = 0;
    sub_8056580(&v51, 0, 8, &v54);
    *(_DWORD *)v51 = *(_DWORD *)v5;
    *(_DWORD *)(v51 + 4) = *(_DWORD *)(v5 + 4);
    v7 = v51;
    v54 = 0;
    if ( (unsigned int)(v52 - v51) <= 0xB )
    {
      sub_8056580(&v51, v52, 11 - (v52 - v51), &v54);
      v7 = v51;
    }
    else
    {
      v52 = v51 + 11;
    }
    *(_BYTE *)(v7 + 8) = 0;
    *(_BYTE *)(v51 + 9) = 2;
    *(_BYTE *)(v51 + 10) = *((_DWORD *)*v6 - 3);
    v10 = *v6;
    v9 = v51;
    v23 = *((_DWORD *)*v6 - 3);
    v54 = 0;
    v8 = v23 + 11;
    if ( v8 >= (unsigned int)(v52 - v51) )
    {
      sub_8056580(&v51, v52, v8 - (v52 - v51), &v54);
      v9 = v51;
      v10 = *v6;
    }
    else
    {
      v52 = v51 + v8;
    }
    memcpy((void *)(v9 + 11), v10, *((_DWORD *)v10 - 3));
    v12 = *((_DWORD *)*v6 - 3);
    v54 = 0;
    v55 = v12 + 13;
    v11 = v51;
    if ( v12 + 13 >= (unsigned int)(v52 - v51) )
    {
      sub_8056580(&v51, v52, v55 - (v52 - v51), &v54);
      v11 = v51;
    }
    else
    {
      v13 = v55;
      v52 = v51 + v55;
    }
    *(_BYTE *)(v11 + v12 + 11) = 0;
    *(_BYTE *)(v51 + v12 + 11 + 1) = 3;
    std__ios_base__ios_base(v13);
    a1 = &v56;
    v57 = 0;
    v58 = 134771496;
    v59 = 0;
    v24 = *(_DWORD *)(*(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[4]
                    - 12);
    v56 = *(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[4];
    v60 = 0;
    v61 = 0;
    *(signed int *)((char *)&v56 + v24) = *(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[8];
    v62 = 0;
    v63 = 0;
    v64 = 0;
    std__basic_ios_char_std__char_traits_char____init((char *)&v56 + *(_DWORD *)(v56 - 12), 0);
    v56 = 134771532;
    v58 = 134771552;
    v65 = 134771752;
    v66 = 0;
    v67 = 0;
    v68 = 0;
    v69 = 0;
    v70 = 0;
    v71 = 0;
    std__locale__locale(&v72);
    v65 = 134771432;
    v73 = 16;
    v74 = 134771820;
    std__basic_ios_char_std__char_traits_char____init(&v58, &v65);
    std____ostream_insert_char_std__char_traits_char__(&v56, &unk_807F63F, 9);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;ret event='OnRemoteNotification'&gt;", 40);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;srv&gt;", 11);
    std____ostream_insert_char_std__char_traits_char__(&v56, &unk_807F655, 21);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;val srv_id=''&gt;undefined&lt;/val&gt;", 42);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;/srv&gt;", 12);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;srv&gt;", 11);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;id&gt;cAwaySrv&lt;/id&gt;", 29);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;val srv_id='cAwaySrv'&gt;", 29);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;Root&gt;", 12);
    std____ostream_insert_char_std__char_traits_char__(
      &v56,
      "&lt;CASXtraSetAwayMessage&gt;&lt;/CASXtraSetAwayMessage&gt;",
      59);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;uin&gt;", 11);
    v25 = std____ostream_insert_char_std__char_traits_char__(
            &v56,
            *(_DWORD *)(v50 + 124),
            *(_DWORD *)(*(_DWORD *)(v50 + 124) - 12));
    std____ostream_insert_char_std__char_traits_char__(v25, "&lt;/uin&gt;", 12);
    v26 = *(_DWORD *)(v50 + 108);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;index&gt;", 13);
    v27 = std__ostream___M_insert_unsigned_long_(&v56, v26);
    std____ostream_insert_char_std__char_traits_char__(v27, "&lt;/index&gt;", 14);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;title&gt;", 13);
    v28 = std____ostream_insert_char_std__char_traits_char__(
            &v56,
            *(_DWORD *)(v50 + 112),
            *(_DWORD *)(*(_DWORD *)(v50 + 112) - 12));
    std____ostream_insert_char_std__char_traits_char__(v28, "&lt;/title&gt;", 14);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;desc&gt;", 12);
    v29 = std____ostream_insert_char_std__char_traits_char__(
            &v56,
            *(_DWORD *)(v50 + 116),
            *(_DWORD *)(*(_DWORD *)(v50 + 116) - 12));
    std____ostream_insert_char_std__char_traits_char__(v29, "&lt;/desc&gt;", 13);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;/Root&gt;", 13);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;/val&gt;", 12);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;/srv&gt;", 12);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;srv&gt;", 11);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;id&gt;cRandomizerSrv&lt;/id&gt;", 35);
    std____ostream_insert_char_std__char_traits_char__(
      &v56,
      "&lt;val srv_id='cRandomizerSrv'&gt;undefined&lt;/val&gt;",
      56);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;/srv&gt;", 12);
    std____ostream_insert_char_std__char_traits_char__(&v56, "&lt;/ret&gt;", 12);
    std____ostream_insert_char_std__char_traits_char__(&v56, "</RES></NR>\r\n", 13);
    v75 = -273457093;
    v76 = 1164716760;
    v77 = 1520230564;
    v78 = 1709729630;
    sub_8051580((int)&v79);
    v79 = 9;
    v80 = 0;
    v81 = 26;
    v82 = 0;
    v83 = 0;
    v84 = 0;
    std__string__assign(&v85, 134739702, 0);
    v86 = 8;
    v87 = v75;
    v88 = v76;
    v89 = v77;
    v90 = v78;
    std__string__assign(&v91, "Script Plug-in: Remote Notification Arrive", 42);
    v92 = 134771820;
    if ( v70 )
    {
      if ( v70 > v68 )
      {
        v15 = &v92;
        v97 = sub_8078490(v69, v70, (int)&v96);
        std__string__assign(&v92, &v97);
        _EDX = v97 - 12;
        if ( std__string___Rep___S_empty_rep_storage != (char *)(v97 - 12) )
        {
          if ( pthread_cancel )
          {
            _EAX = -1;
            __asm { lock xadd [edx+8], eax }
            v20 = _EAX;
          }
          else
          {
            v20 = *(_DWORD *)(_EDX + 8);
            *(_DWORD *)(_EDX + 8) = v20 - 1;
          }
          if ( v20 <= 0 )
            std__string___Rep___M_destroy(_EDX, &v98);
        }
      }
      else
      {
        v15 = &v92;
        v94 = sub_8078490(v69, v68, (int)&v93);
        std__string__assign(&v92, &v94);
        _EDX = v94 - 12;
        if ( std__string___Rep___S_empty_rep_storage != (char *)(v94 - 12) )
        {
          if ( pthread_cancel )
          {
            _EAX = -1;
            __asm { lock xadd [edx+8], eax }
            v22 = _EAX;
          }
          else
          {
            v22 = *(_DWORD *)(_EDX + 8);
            *(_DWORD *)(_EDX + 8) = v22 - 1;
          }
          if ( v22 <= 0 )
            std__string___Rep___M_destroy(_EDX, &v100);
        }
      }
    }
    else
    {
      v15 = &v92;
      std__string__assign(&v92, &v74);
    }
    std__string__assign(&v95, v15);
    _EDX = v92 - 12;
    if ( std__string___Rep___S_empty_rep_storage != (char *)(v92 - 12) )
      goto LABEL_26;
    goto LABEL_14;
  }
  while ( *MK_FP(__GS__, 20) ^ v49 )
  {
    __stack_chk_fail();
LABEL_26:
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v21 = _EAX;
    }
    else
    {
      v21 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v21 - 1;
    }
    if ( v21 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v99);
LABEL_14:
    sub_8052BE0((int)&v79, (int)&v51, v55);
    sub_805A180(v50, 4, 11, 0, (int)&v51);
    sub_80543A0((int)&v79);
    v56 = 134771532;
    v58 = 134771552;
    v65 = 134771432;
    std__string___string(&v74);
    v65 = 134771752;
    std__locale___locale(&v72);
    v30 = *(_DWORD *)(*(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[4]
                    - 12);
    v56 = *(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[4];
    *(signed int *)((char *)a1 + v17) = *(_DWORD *)&_VTT_for_std__basic_ostringstream_char_std__char_traits_char__std__allocator_char__[8];
    v58 = 134771496;
    std__ios_base___ios_base(&v58);
    result = v51;
    if ( v51 )
      result = operator delete(v18, v17);
  }
  return result;
}

//----- (080708D0) --------------------------------------------------------
signed int __cdecl sub_80708D0(int a1, char *a2, int a3)
{
  int v3; // edx@1
  int v4; // ecx@1
  int v5; // edi@1
  char *v6; // esi@1
  signed int v7; // ebx@5
  signed int result; // eax@6
  int v9; // eax@9
  int v10; // ebx@9
  int v11; // eax@17
  int v12; // eax@54
  int v13; // ebx@1
  time_t v14; // eax@1
  int v15; // eax@41
  char v16; // bl@53
  int v17; // [sp+158h] [bp-10h]@1
  char v18; // [sp+138h] [bp-30h]@1
  __int16 v19; // [sp+144h] [bp-24h]@2
  char v20; // [sp+38h] [bp-130h]@8
  char v21; // [sp+14Ch] [bp-1Ch]@8
  int v22; // [sp+24h] [bp-144h]@9
  char v23; // [sp+148h] [bp-20h]@9
  int v24; // [sp+14h] [bp-154h]@9
  char v25; // [sp+40h] [bp-128h]@9
  unsigned __int8 v26; // [sp+3Ch] [bp-12Ch]@9
  __int16 v27; // [sp+44h] [bp-124h]@20
  char v28; // [sp+48h] [bp-120h]@21
  __int16 v29; // [sp+46h] [bp-122h]@25
  char v30; // [sp+74h] [bp-F4h]@26
  char v31; // [sp+B4h] [bp-B4h]@27
  char v32; // [sp+ACh] [bp-BCh]@27
  char v33; // [sp+A8h] [bp-C0h]@33
  char v34; // [sp+E0h] [bp-88h]@34
  char v35; // [sp+6Ch] [bp-FCh]@35
  int v36; // [sp+13Ch] [bp-2Ch]@35
  char v37; // [sp+C0h] [bp-A8h]@39
  int v38; // [sp+B8h] [bp-B0h]@41
  int v39; // [sp+BCh] [bp-ACh]@41
  int v40; // [sp+140h] [bp-28h]@41
  char v41; // [sp+F0h] [bp-78h]@43
  char v42; // [sp+124h] [bp-44h]@43
  char v43; // [sp+128h] [bp-40h]@44
  char v44; // [sp+50h] [bp-118h]@46
  char v45; // [sp+54h] [bp-114h]@47
  int (__cdecl *v46)(_DWORD, _DWORD, _DWORD, _DWORD); // [sp+28h] [bp-140h]@47
  char v47; // [sp+58h] [bp-110h]@47
  char v48; // [sp+5Ch] [bp-10Ch]@49
  int (__cdecl *v49)(_DWORD, _DWORD, _DWORD, _DWORD); // [sp+20h] [bp-148h]@49
  char v50; // [sp+60h] [bp-108h]@49
  char v51; // [sp+64h] [bp-104h]@50
  int (__cdecl *v52)(_DWORD, _DWORD, _DWORD); // [sp+1Ch] [bp-14Ch]@50
  char v53; // [sp+68h] [bp-100h]@50
  char v54; // [sp+70h] [bp-F8h]@53
  char v55; // [sp+4Ch] [bp-11Ch]@59

  v13 = a3;
  v6 = a2;
  v5 = a1;
  v17 = *MK_FP(__GS__, 20);
  v14 = time(0);
  *(v6 + 8) = 0;
  *((_DWORD *)v6 + 9) = v14;
  sub_80511E0((int)&v18);
  if ( !sub_8055160((int)&v18, v13, 0) )
    goto LABEL_5;
  if ( v19 == 1 )
  {
    v5 = (int)&v27;
    sub_8051230((int)&v27);
    if ( !(unsigned __int8)sub_8053F50((int)&v27, (int)&v21) )
      goto LABEL_62;
    std__string__assign(v6 + 12, &v23);
    std__string__assign(v6 + 16, &v28);
    if ( v27 == 2 )
    {
      *((_DWORD *)v6 + 7) = 2;
      goto LABEL_25;
    }
    if ( v27 == 3 )
      goto LABEL_52;
    if ( v27 )
    {
LABEL_62:
      v7 = 0;
      goto LABEL_32;
    }
    *((_DWORD *)v6 + 7) = 0;
    goto LABEL_25;
  }
  if ( v19 == 2 )
  {
    sub_80515E0((int)&v30);
    if ( (unsigned __int8)sub_80555E0((int)&v30, (int)&v21) )
    {
      v24 = (int)&v23;
      std__string__assign(v6 + 12, &v23);
      std__string__assign(v6 + 16, &v31);
      if ( v32 == 1 )
      {
        if ( std__string__compare(&v37, "{0946134E-4C7F-11D1-8222-444553540000}")
          && std__string__compare(&v37, "{0946134e-4c7f-11d1-8222-444553540000}") )
          *((_DWORD *)v6 + 7) = 1;
        else
          *((_DWORD *)v6 + 7) = 3;
        v7 = 1;
        *((_DWORD *)v6 + 5) = v38;
        *((_DWORD *)v6 + 6) = v39;
        *(_DWORD *)v6 = v36;
        v15 = v40;
        *(v6 + 8) = 1;
        *((_DWORD *)v6 + 1) = v15;
        goto LABEL_37;
      }
      if ( (unsigned __int8)(v32 + 24) < 4u | v32 == -20 )
      {
        v6 = &v54;
        v16 = v32;
        std__string__string(&v54, v24);
        sub_805FB70(v5, (const void **)&v54, (int)&v36, v16);
        std__string___string(&v54);
      }
      else
      {
        if ( v32 != 26 )
        {
          sub_80545E0((int)&v30);
          goto LABEL_5;
        }
        if ( (unsigned __int8)sub_80538E0((int)&v33) )
        {
          if ( sub_8078550(v24, (int)&v34) )
          {
            std__string__string(&v35, v24);
            sub_806FE30((signed int *)v6, v5, (const void **)&v35, (int)&v36);
            std__string___string(&v35);
          }
        }
      }
    }
    v7 = 0;
LABEL_37:
    sub_80545E0((int)&v30);
    goto LABEL_6;
  }
  if ( v19 != 4 )
  {
LABEL_5:
    v7 = 0;
    goto LABEL_6;
  }
  sub_8051270((int)&v20);
  v7 = 0;
  if ( (unsigned __int8)sub_8051750((int)&v20, (int)&v21) )
  {
    v22 = (int)(v6 + 12);
    v24 = (int)&v23;
    std__string__assign(v6 + 12, &v23);
    v10 = (int)(v6 + 16);
    std__string__assign(v6 + 16, &v25);
    v9 = v26;
    if ( v26 == 4
      || (_BYTE)v9 == 6
      || (_BYTE)v9 == 7
      || (_BYTE)v9 == 8
      || (_BYTE)v9 == 9
      || (_BYTE)v9 == 12
      || (_BYTE)v9 == 13
      || (_BYTE)v9 == 14 )
    {
      v12 = std__string__find_last_of(v6 + 16, &unk_807F6F7, -1);
      if ( v12 != -1 )
        std__string__erase(v6 + 16, 0, v12);
      v9 = v26;
    }
    v11 = v9 - 6;
    if ( (_BYTE)v11 <= 0x14u )
    {
      switch ( (unsigned __int8)v11 )
      {
        case 0u:
          v6 = &v51;
          v52 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD))(*(_DWORD *)v5 + 20);
          std__string__string(&v51, v10);
          std__string__string(&v53, v22);
          v52(v5, &v53, &v51);
          std__string___string(&v53);
          goto LABEL_48;
        case 1u:
          v6 = &v48;
          v49 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD, _DWORD))(*(_DWORD *)v5 + 24);
          std__string__string(&v48, v10);
          std__string__string(&v50, v22);
          v49(v5, &v50, &v48, 0);
          std__string___string(&v50);
          goto LABEL_48;
        case 2u:
          v6 = &v45;
          v46 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD, _DWORD))(*(_DWORD *)v5 + 24);
          std__string__string(&v45, v10);
          std__string__string(&v47, v22);
          v46(v5, &v47, &v45, 1);
          std__string___string(&v47);
LABEL_48:
          std__string___string(v6);
          v7 = 0;
          break;
        case 3u:
        case 4u:
        case 5u:
        case 7u:
        case 8u:
        case 9u:
        case 0xAu:
        case 0xBu:
        case 0xCu:
        case 0xDu:
        case 0xEu:
        case 0xFu:
        case 0x10u:
        case 0x11u:
        case 0x12u:
        case 0x13u:
          goto LABEL_18;
        case 6u:
          v6 = *(char **)(*(_DWORD *)v5 + 36);
          std__string__string(&v44, v22);
          ((int (__cdecl *)(int, char *))v6)(v5, &v44);
          std__string___string(&v44);
          v7 = 0;
          break;
        case 0x14u:
          v6 = &v41;
          sub_8051580((int)&v41);
          std__string__assign(&v42, v10);
          if ( (unsigned __int8)sub_80538E0((int)&v41) )
          {
            if ( sub_8078550(v24, (int)&v43) )
            {
              std__string__string(&v55, v24);
              sub_806FE30((signed int *)&v41, v5, (const void **)&v55, (int)&v36);
              std__string___string(&v55);
            }
          }
          sub_80543A0((int)&v41);
          v7 = 0;
          break;
      }
    }
    else
    {
LABEL_18:
      v7 = 1;
    }
  }
  sub_8054300((int)&v20);
LABEL_6:
  while ( 1 )
  {
    sub_8053EA0(v4, v3, (int)&v18);
    result = v7;
    if ( !(*MK_FP(__GS__, 20) ^ v17) )
      break;
    __stack_chk_fail();
LABEL_52:
    *((_DWORD *)v6 + 7) = 1;
LABEL_25:
    v7 = 1;
    *((_WORD *)v6 + 16) = v29;
LABEL_32:
    sub_8054840(v5);
  }
  return result;
}

//----- (08070FF0) --------------------------------------------------------
char __cdecl sub_8070FF0(int a1, int a2, __int16 a3, int a4)
{
  int v4; // ebx@1
  int v6; // ecx@3
  int v7; // esi@4
  int v8; // ebx@6
  int v9; // edi@6
  int v10; // edx@11
  int v11; // ecx@11
  signed int v12; // ebx@11
  int v15; // ecx@14
  int v16; // esi@15
  int v17; // ebx@17
  int v18; // edi@17
  __int16 v19; // ax@1
  __int16 v20; // ax@6
  int v21; // eax@8
  int v22; // ebx@8
  size_t v23; // ebx@8
  __int16 v24; // ax@17
  int v25; // eax@19
  int v26; // ebx@19
  size_t v27; // ebx@19
  __int16 v40; // [sp+1Ah] [bp-5Eh]@1
  char v41; // [sp+20h] [bp-58h]@1
  char v42; // [sp+24h] [bp-54h]@1
  __int16 v43; // [sp+28h] [bp-50h]@1
  __int16 v44; // [sp+2Ch] [bp-4Ch]@1
  __int16 v45; // [sp+2Ah] [bp-4Eh]@1
  int v46; // [sp+60h] [bp-18h]@3
  char v47; // [sp+6Bh] [bp-Dh]@3
  const void *v48; // [sp+40h] [bp-38h]@3
  int v49; // [sp+44h] [bp-34h]@3
  int v50; // [sp+48h] [bp-30h]@3
  char v51; // [sp+58h] [bp-20h]@3
  __int16 v52; // [sp+3Ch] [bp-3Ch]@3
  int v53; // [sp+14h] [bp-64h]@3
  int v54; // [sp+34h] [bp-44h]@4
  int v55; // [sp+38h] [bp-40h]@4
  int v56; // [sp+4Ch] [bp-2Ch]@11
  int v57; // [sp+50h] [bp-28h]@11
  int v58; // [sp+54h] [bp-24h]@11
  int v59; // [sp+64h] [bp-14h]@14
  char v60; // [sp+5Ch] [bp-1Ch]@14
  char v61; // [sp+30h] [bp-48h]@22
  char v62; // [sp+69h] [bp-Fh]@26
  char v63; // [sp+6Ah] [bp-Eh]@31

  v40 = a3;
  sub_80512C0((int)&v41);
  std__string__assign(&v42, a2);
  v4 = a2 + 4;
  v43 = *(_WORD *)(a2 + 8);
  v19 = *(_WORD *)(a2 + 16);
  v44 = 0;
  v45 = v19;
  if ( std__string__compare(a2 + 4, 134739702) )
  {
    std__string__string(&v59, v4);
    v48 = 0;
    v49 = 0;
    v50 = 0;
    std__string__string(&v60, &v59);
    v53 = (int)&v52;
    sub_8051C40((int)&v52, (int)&v60);
    std__string___string(&v60);
    v52 = 305;
    _EDX = v59 - 12;
    if ( v59 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
    {
      if ( pthread_cancel )
      {
        _EAX = -1;
        __asm { lock xadd [edx+8], eax }
        v15 = _EAX;
      }
      else
      {
        v15 = *(_DWORD *)(_EDX + 8);
        *(_DWORD *)(_EDX + 8) = v15 - 1;
      }
      if ( v15 <= 0 )
        std__string___Rep___M_destroy(_EDX, &v63);
    }
    v16 = v54;
    if ( v54 == v55 )
    {
      sub_8057B40(v15, v53, (int)&v61, v54, v53);
    }
    else
    {
      if ( v54 )
      {
        v18 = 0;
        v17 = v49 - (_DWORD)v48;
        v24 = v52;
        *(_DWORD *)(v54 + 4) = 0;
        *(_DWORD *)(v54 + 8) = 0;
        *(_WORD *)v54 = v24;
        *(_DWORD *)(v54 + 12) = 0;
        if ( v17 )
          v18 = operator new(v15, _EDX);
        v25 = v18 + v17;
        *(_DWORD *)(v16 + 4) = v18;
        *(_DWORD *)(v16 + 8) = v18;
        v26 = v49;
        *(_DWORD *)(v16 + 12) = v25;
        v27 = v26 - (_DWORD)v48;
        memmove((void *)v18, v48, v27);
        *(_DWORD *)(v16 + 8) = v18 + v27;
        v16 = v54;
      }
      v54 = v16 + 16;
    }
    sub_8052370(v15, v53, v53);
  }
  if ( *(_BYTE *)(a2 + 18) )
  {
    std__string__string(&v46, 134739702, &v47);
    v48 = 0;
    v49 = 0;
    v50 = 0;
    std__string__string(&v51, &v46);
    v53 = (int)&v52;
    sub_8051C40((int)&v52, (int)&v51);
    std__string___string(&v51);
    v52 = 102;
    _EDX = v46 - 12;
    if ( v46 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
    {
      if ( pthread_cancel )
      {
        _EAX = -1;
        __asm { lock xadd [edx+8], eax }
        v6 = _EAX;
      }
      else
      {
        v6 = *(_DWORD *)(_EDX + 8);
        *(_DWORD *)(_EDX + 8) = v6 - 1;
      }
      if ( v6 <= 0 )
        std__string___Rep___M_destroy(_EDX, &v62);
    }
    v7 = v54;
    if ( v54 == v55 )
    {
      sub_8057B40(v6, _EDX, (int)&v61, v54, v53);
    }
    else
    {
      if ( v54 )
      {
        v9 = 0;
        v8 = v49 - (_DWORD)v48;
        v20 = v52;
        *(_DWORD *)(v54 + 4) = 0;
        *(_DWORD *)(v54 + 8) = 0;
        *(_WORD *)v54 = v20;
        *(_DWORD *)(v54 + 12) = 0;
        if ( v8 )
          v9 = operator new(v6, _EDX);
        v21 = v9 + v8;
        *(_DWORD *)(v7 + 4) = v9;
        *(_DWORD *)(v7 + 8) = v9;
        v22 = v49;
        *(_DWORD *)(v7 + 12) = v21;
        v23 = v22 - (_DWORD)v48;
        memmove((void *)v9, v48, v23);
        *(_DWORD *)(v7 + 8) = v9 + v23;
        v7 = v54;
      }
      v54 = v7 + 16;
    }
    sub_8052370(v6, _EDX, v53);
  }
  v56 = 0;
  v57 = 0;
  v58 = 0;
  sub_8053310((int)&v41, (int)&v56, 0);
  v12 = sub_805A180(a1, 19, v40, a4, (int)&v56);
  if ( v56 )
    operator delete(v11, v10);
  sub_80549C0(v11, (int)&v41, (int)&v41);
  return v12 == 1;
}

//----- (08071410) --------------------------------------------------------
signed int __cdecl sub_8071410(int a1, int a2, int a3)
{
  signed int v4; // ebx@1
  int v5; // edi@1
  signed int result; // eax@5
  int v7; // ecx@10
  int v8; // ecx@20
  int v9; // ebx@3
  signed int v10; // eax@3
  int v11; // ecx@3
  int v12; // edx@3
  int v19; // [sp+A8h] [bp-10h]@1
  int v20; // [sp+10h] [bp-A8h]@1
  int v21; // [sp+20h] [bp-98h]@1
  int v22; // [sp+14h] [bp-A4h]@3
  char v23; // [sp+28h] [bp-90h]@3
  int v24; // [sp+1Ch] [bp-9Ch]@3
  __int16 v25; // [sp+24h] [bp-94h]@10
  char v26; // [sp+18h] [bp-A0h]@17
  char v27; // [sp+27h] [bp-91h]@22

  v19 = *MK_FP(__GS__, 20);
  v5 = a3;
  v20 = a1;
  std__string__string(&v21, a2);
  v4 = sub_805B8D0(v20, (int)&v21);
  _EDX = v21 - 12;
  if ( v21 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
    goto LABEL_19;
  while ( 1 )
  {
    if ( v4 < 0 )
    {
      if ( v5 )
      {
        *(_WORD *)v5 = 2;
        result = 0;
        goto LABEL_6;
      }
      goto LABEL_13;
    }
    v9 = v4 << 7;
    v22 = v9;
    sub_8078C30((int)&v23, *(_DWORD *)(v20 + 4) + v9);
    LOBYTE(v10) = sub_8070FF0(v20, (int)&v23, 10, (int)&v24);
    v4 = v10;
    sub_807B640(v11, v12, (int)&v23);
    if ( !(_BYTE)v4 )
    {
      if ( v5 )
      {
        *(_WORD *)v5 = 4;
        result = 0;
        goto LABEL_6;
      }
LABEL_13:
      result = 0;
      goto LABEL_6;
    }
    result = sub_805A920(v20, (int)&v25, v24);
    if ( !(_BYTE)result )
    {
      if ( v5 )
      {
        *(_WORD *)v5 = 4;
        goto LABEL_6;
      }
      goto LABEL_13;
    }
    if ( v5 )
      *(_WORD *)v5 = v25;
    result = 1;
    if ( !v25 )
    {
      v22 += *(_DWORD *)(v20 + 4);
      sub_807BA10(v7, (int)&v26, (int)&v26, v20 + 4, v22);
      result = 1;
    }
LABEL_6:
    if ( !(*MK_FP(__GS__, 20) ^ v19) )
      return result;
    __stack_chk_fail();
LABEL_19:
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v8 = _EAX;
    }
    else
    {
      v8 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v8 - 1;
    }
    if ( v8 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v27);
  }
}

//----- (08071620) --------------------------------------------------------
char __cdecl sub_8071620(int a1, int a2, int a3)
{
  int v3; // edi@1
  char result; // al@3
  signed int v6; // ebx@5
  char v8; // bl@8
  int v9; // ecx@22
  int v10; // ecx@26
  int v23; // [sp+24h] [bp-14h]@5
  __int16 v24; // [sp+1Ah] [bp-1Eh]@6
  int v25; // [sp+20h] [bp-18h]@8
  int v26; // [sp+1Ch] [bp-1Ch]@11
  __int16 v27; // [sp+28h] [bp-10h]@18
  char v28; // [sp+2Ah] [bp-Eh]@24
  char v29; // [sp+2Bh] [bp-Dh]@28

  v3 = a1;
  if ( !sub_805A310(a1) )
  {
LABEL_2:
    if ( a3 )
    {
      *(_WORD *)a3 = 4;
      return 0;
    }
    return 0;
  }
  std__string__string(&v23, a2);
  v6 = sub_805B8D0(v3, (int)&v23);
  _EDX = v23 - 12;
  if ( v23 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v10 = _EAX;
    }
    else
    {
      v10 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v10 - 1;
    }
    if ( v10 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v29);
  }
  v24 = 0;
  if ( v6 >= 0 )
    v24 = *(_WORD *)(*(_DWORD *)(v3 + 4) + (v6 << 7) + 8);
  std__string__string(&v25, a2);
  v8 = sub_8071410(v3, (int)&v25, a3);
  _EDX = v25 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v25 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v9 = _EAX;
    }
    else
    {
      v9 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v9 - 1;
    }
    if ( v9 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v28);
  }
  if ( !v8 )
  {
    if ( !sub_805A2D0(v3) )
      goto LABEL_2;
    return 0;
  }
  if ( !v24 )
    goto LABEL_33;
  result = sub_805F220(v3, v24, (int)&v26);
  if ( !result )
  {
    if ( a3 )
    {
      *(_WORD *)a3 = 4;
      return result;
    }
    return 0;
  }
  if ( (unsigned __int8)sub_805A920(v3, (int)&v27, v26) )
  {
LABEL_33:
    if ( sub_805A2D0(v3) )
      return a3 == 0;
    goto LABEL_2;
  }
  if ( !a3 )
    return 0;
  *(_WORD *)a3 = v27;
  return 0;
}

//----- (08071820) --------------------------------------------------------
signed int __cdecl sub_8071820(int a1, int a2)
{
  int v2; // ebx@2
  unsigned int v3; // edx@3
  int v4; // ecx@3
  int v6; // edx@6
  unsigned int v7; // edi@7
  signed int v9; // ebx@8
  int v10; // edx@10
  int v11; // ebx@10
  int v12; // esi@10
  int v13; // eax@12
  char v14; // cl@12
  int v15; // eax@16
  int v16; // eax@19
  unsigned int v17; // esi@21
  int v19; // ebx@24
  signed int v20; // ebx@29
  int v21; // ebx@30
  unsigned int v22; // edx@31
  int v23; // ecx@31
  int v24; // ecx@38
  int v25; // ecx@42
  int v26; // ebx@45
  unsigned int v27; // edx@46
  int v28; // ecx@46
  int v29; // ebx@49
  unsigned int v30; // edx@50
  int v31; // ecx@50
  __int16 v32; // si@50
  unsigned int v33; // eax@4
  int v34; // eax@6
  signed int v35; // esi@10
  int v36; // ebx@22
  unsigned int v37; // eax@32
  unsigned int v50; // eax@47
  unsigned int v51; // eax@51
  int v52; // [sp+38h] [bp-30h]@6
  int *v53; // [sp+1Ch] [bp-4Ch]@6
  int v54; // [sp+40h] [bp-28h]@6
  int *v55; // [sp+44h] [bp-24h]@6
  int v56; // [sp+48h] [bp-20h]@6
  int v57; // [sp+3Ch] [bp-2Ch]@6
  char v58; // [sp+34h] [bp-34h]@6
  int v59; // [sp+20h] [bp-48h]@6
  int v60; // [sp+54h] [bp-14h]@8
  int v61; // [sp+24h] [bp-44h]@10
  char v62; // [sp+28h] [bp-40h]@18
  int v63; // [sp+50h] [bp-18h]@22
  int v64; // [sp+4Ch] [bp-1Ch]@25
  __int16 v65; // [sp+58h] [bp-10h]@26
  char v66; // [sp+5Bh] [bp-Dh]@40
  char v67; // [sp+5Ah] [bp-Eh]@44

  if ( !sub_805A310(a1) )
  {
    v2 = *(_DWORD *)a2;
    if ( (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 4 )
    {
      v3 = 0;
      v4 = (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 4;
      do
      {
        v33 = v3++;
        *(_WORD *)(v2 + 16 * v33 + 12) = 4;
      }
      while ( v3 < v4 );
    }
    return 0;
  }
  v53 = &v52;
  v54 = (int)&v52;
  v55 = &v52;
  v56 = 0;
  v52 = 0;
  v57 = 0;
  v6 = *(_DWORD *)a2;
  v34 = *(_DWORD *)(a2 + 4);
  v59 = (int)&v58;
  if ( (v34 - v6) >> 4 )
  {
    v7 = 0;
    v59 = (int)&v58;
    while ( 1 )
    {
      std__string__string(&v60, v6 + 16 * v7);
      v9 = sub_805B8D0(a1, (int)&v60);
      _EDX = v60 - 12;
      if ( v60 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
      {
        if ( pthread_cancel )
        {
          _EAX = -1;
          __asm { lock xadd [edx+8], eax }
          v24 = _EAX;
        }
        else
        {
          v24 = *(_DWORD *)(_EDX + 8);
          *(_DWORD *)(_EDX + 8) = v24 - 1;
        }
        if ( v24 <= 0 )
          std__string___Rep___M_destroy(_EDX, &v66);
      }
      if ( v9 < 0 )
        goto LABEL_19;
      v35 = v9 << 7;
      v11 = (int)&v52;
      v12 = *(_DWORD *)(a1 + 4) + v35;
      v61 = v12 + 8;
      v10 = v57;
      if ( !v57 )
        goto LABEL_35;
      while ( *(_WORD *)(v10 + 16) > *(_WORD *)(v12 + 8) )
      {
        v13 = *(_DWORD *)(v10 + 8);
        v14 = 1;
        if ( !v13 )
          goto LABEL_16;
LABEL_13:
        v10 = v13;
      }
      v13 = *(_DWORD *)(v10 + 12);
      v14 = 0;
      if ( v13 )
        goto LABEL_13;
LABEL_16:
      v11 = v10;
      v15 = v10;
      if ( !v14 )
        goto LABEL_17;
LABEL_35:
      if ( v11 == v54 )
        goto LABEL_57;
      v15 = std___Rb_tree_decrement(v11);
LABEL_17:
      if ( *(_WORD *)(v15 + 16) < *(_WORD *)(v12 + 8) )
LABEL_57:
        sub_80785C0(v61, (int)&v62, (int)&v62, v59, 0, v11, v61);
LABEL_19:
      ++v7;
      v6 = *(_DWORD *)a2;
      v16 = (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 4;
      if ( v7 >= v16 )
      {
        if ( v16 )
        {
          v17 = 0;
          do
          {
            v36 = v6 + 16 * v17 + 12;
            std__string__string(&v63, v6 + 16 * v17);
            sub_8071410(a1, (int)&v63, v36);
            _EDX = v63 - 12;
            if ( v63 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
            {
              if ( pthread_cancel )
              {
                _EAX = -1;
                __asm { lock xadd [edx+8], eax }
                v25 = _EAX;
              }
              else
              {
                v25 = *(_DWORD *)(_EDX + 8);
                *(_DWORD *)(_EDX + 8) = v25 - 1;
              }
              if ( v25 <= 0 )
                std__string___Rep___M_destroy(_EDX, &v67);
            }
            ++v17;
            v6 = *(_DWORD *)a2;
          }
          while ( v17 < (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 4 );
        }
        break;
      }
    }
  }
  v19 = v54;
  while ( v19 != (_DWORD)v53 )
  {
    if ( !(unsigned __int8)sub_805F220(a1, *(_WORD *)(v19 + 16), (int)&v64) )
    {
      v26 = *(_DWORD *)a2;
      if ( (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 4 )
      {
        v27 = 0;
        v28 = (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 4;
        do
        {
          v50 = v27++;
          *(_WORD *)(v26 + 16 * v50 + 12) = 4;
        }
        while ( v27 < v28 );
      }
      goto LABEL_33;
    }
    if ( !(unsigned __int8)sub_805A920(a1, (int)&v65, v64) )
    {
      v29 = *(_DWORD *)a2;
      if ( (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 4 )
      {
        v32 = v65;
        v30 = 0;
        v31 = (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 4;
        do
        {
          v51 = v30++;
          *(_WORD *)(v29 + 16 * v51 + 12) = v32;
        }
        while ( v30 < v31 );
      }
      goto LABEL_33;
    }
    v19 = std___Rb_tree_increment(v19);
  }
  v20 = 1;
  if ( sub_805A2D0(a1) )
    goto LABEL_34;
  v21 = *(_DWORD *)a2;
  if ( (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 4 )
  {
    v22 = 0;
    v23 = (*(_DWORD *)(a2 + 4) - *(_DWORD *)a2) >> 4;
    do
    {
      v37 = v22++;
      *(_WORD *)(v21 + 16 * v37 + 12) = 4;
    }
    while ( v22 < v23 );
  }
LABEL_33:
  v20 = 0;
LABEL_34:
  sub_8077D60(v59, v57);
  return v20;
}

//----- (08072100) --------------------------------------------------------
signed int __cdecl sub_8072100(int a1, int a2, int a3, int a4, int a5)
{
  signed int v6; // ebx@1
  int v7; // edi@1
  int v8; // esi@1
  int v9; // edx@3
  int v10; // ecx@3
  signed int result; // eax@7
  int v12; // ecx@23
  int v13; // eax@3
  __int16 v14; // ax@3
  char v15; // bl@11
  char v22; // bl@26
  int v23; // [sp+18h] [bp-1A0h]@1
  int v24; // [sp+1A8h] [bp-10h]@1
  int v25; // [sp+14h] [bp-1A4h]@1
  int v26; // [sp+20h] [bp-198h]@1
  signed int v27; // [sp+128h] [bp-90h]@3
  signed int v28; // [sp+12Ch] [bp-8Ch]@3
  signed int v29; // [sp+134h] [bp-84h]@3
  int v30; // [sp+160h] [bp-58h]@3
  int v31; // [sp+164h] [bp-54h]@3
  int v32; // [sp+168h] [bp-50h]@3
  signed int v33; // [sp+17Ch] [bp-3Ch]@3
  signed int v34; // [sp+180h] [bp-38h]@3
  signed int v35; // [sp+188h] [bp-30h]@3
  signed int v36; // [sp+18Ch] [bp-2Ch]@3
  signed int v37; // [sp+190h] [bp-28h]@3
  signed int v38; // [sp+194h] [bp-24h]@3
  signed int v39; // [sp+198h] [bp-20h]@3
  __int16 v40; // [sp+130h] [bp-88h]@3
  __int16 v41; // [sp+138h] [bp-80h]@3
  char v42; // [sp+13Ah] [bp-7Eh]@3
  int v43; // [sp+13Ch] [bp-7Ch]@3
  int v44; // [sp+140h] [bp-78h]@3
  int v45; // [sp+144h] [bp-74h]@3
  char v46; // [sp+148h] [bp-70h]@3
  __int16 v47; // [sp+14Ah] [bp-6Eh]@3
  char v48; // [sp+14Ch] [bp-6Ch]@3
  int v49; // [sp+14Dh] [bp-6Bh]@3
  int v50; // [sp+151h] [bp-67h]@3
  int v51; // [sp+155h] [bp-63h]@3
  int v52; // [sp+159h] [bp-5Fh]@3
  signed int v53; // [sp+16Ch] [bp-4Ch]@3
  int v54; // [sp+170h] [bp-48h]@3
  char v55; // [sp+174h] [bp-44h]@3
  int v56; // [sp+178h] [bp-40h]@3
  char v57; // [sp+184h] [bp-34h]@3
  char v58; // [sp+185h] [bp-33h]@3
  char v59; // [sp+186h] [bp-32h]@3
  int v60; // [sp+19Ch] [bp-1Ch]@3
  int v61; // [sp+1A0h] [bp-18h]@3
  char v62; // [sp+A8h] [bp-110h]@11
  int v63; // [sp+1Ch] [bp-19Ch]@11
  __int16 v64; // [sp+24h] [bp-194h]@15
  char v65; // [sp+27h] [bp-191h]@25
  char v66; // [sp+28h] [bp-190h]@26

  v8 = a1;
  v7 = a5;
  v23 = a2;
  v24 = *MK_FP(__GS__, 20);
  v25 = a3;
  std__string__string(&v26, a4);
  v6 = sub_805B850(v8, (int)&v26);
  _EDX = v26 - 12;
  if ( v26 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
    goto LABEL_22;
  while ( 1 )
  {
    if ( v6 >= 0 )
    {
      v27 = 134771820;
      v28 = 134771820;
      v29 = 134771820;
      v30 = 0;
      v31 = 0;
      v32 = 0;
      v33 = 134771820;
      v34 = 134771820;
      v35 = 134771820;
      v36 = 134771820;
      v37 = 134771820;
      v38 = 134771820;
      v39 = 134771820;
      v40 = 0;
      v41 = 0;
      v42 = 0;
      v43 = 0;
      v44 = 0;
      v45 = 0;
      v46 = 0;
      v47 = 0;
      v48 = 0;
      v49 = 0;
      v50 = 0;
      v51 = 0;
      v52 = 0;
      v53 = -1;
      v54 = 0;
      v55 = 0;
      v56 = 0;
      v57 = 0;
      v58 = 0;
      v59 = 0;
      v60 = 0;
      v61 = 0;
      std__string__assign(&v27, v23);
      std__string__assign(&v28, v25);
      v13 = *(_DWORD *)(v8 + 16) + 8 * v6;
      v40 = *(_WORD *)v13;
      std__string__assign(&v29, v13 + 4);
      v14 = sub_8059BB0(v8);
      v41 = v14;
      if ( v14 )
      {
        v42 = 0;
        sub_8078C30((int)&v62, (int)&v27);
        v15 = sub_8070FF0(v8, (int)&v62, 8, (int)&v63);
        sub_807B640(v10, v9, (int)&v62);
        if ( v15 )
        {
          if ( (unsigned __int8)sub_805A920(v8, (int)&v64, v63) )
          {
            if ( v64 != 14
              || (v42 = 1, sub_8078C30((int)&v66, (int)&v27), v22 = sub_8070FF0(v8, (int)&v66, 8, (int)&v63), sub_807B640(v10, (int)&v66, (int)&v66), v22)
              && (unsigned __int8)sub_805A920(v8, (int)&v64, v63) )
            {
              if ( v7 )
                *(_WORD *)v7 = v64;
              v6 = 1;
              if ( !v64 )
              {
                sub_807C2A0(v8 + 4, (int)&v27);
                v6 = 1;
              }
              goto LABEL_6;
            }
          }
        }
        if ( v7 )
        {
          *(_WORD *)v7 = 4;
          v6 = 0;
          goto LABEL_6;
        }
      }
      else
      {
        if ( v7 )
        {
          *(_WORD *)v7 = 12;
          v6 = 0;
LABEL_6:
          sub_807B640(v10, v9, (int)&v27);
          goto LABEL_7;
        }
      }
      v6 = 0;
      goto LABEL_6;
    }
    v6 = 0;
    if ( v7 )
    {
      *(_WORD *)v7 = 2;
      v6 = 0;
    }
LABEL_7:
    result = v6;
    if ( !(*MK_FP(__GS__, 20) ^ v24) )
      return result;
    __stack_chk_fail();
LABEL_22:
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v12 = _EAX;
    }
    else
    {
      v12 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v12 - 1;
    }
    if ( v12 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v65);
  }
}

//----- (080729E0) --------------------------------------------------------
signed int __cdecl sub_80729E0(int a1, char *a2, int a3, int a4)
{
  signed int v5; // ebx@1
  int v6; // edi@1
  char *v7; // esi@1
  int v8; // eax@3
  int v9; // edx@4
  int v10; // ecx@4
  signed int result; // eax@8
  char v13; // bl@10
  int v15; // ecx@15
  int v16; // ecx@31
  int v17; // ecx@35
  int v18; // ebx@3
  char v19; // bl@4
  char *v20; // ST04_4@12
  int v39; // [sp+20h] [bp-148h]@1
  int v40; // [sp+24h] [bp-144h]@1
  int v41; // [sp+158h] [bp-10h]@1
  int v42; // [sp+4Ch] [bp-11Ch]@1
  int v43; // [sp+28h] [bp-140h]@3
  char v44; // [sp+D8h] [bp-90h]@4
  char v45; // [sp+DCh] [bp-8Ch]@4
  char v46; // [sp+58h] [bp-110h]@4
  int v47; // [sp+34h] [bp-134h]@4
  int v48; // [sp+48h] [bp-120h]@10
  int v49; // [sp+44h] [bp-124h]@10
  char v50; // [sp+38h] [bp-130h]@12
  char v51; // [sp+3Ch] [bp-12Ch]@12
  char v52; // [sp+40h] [bp-128h]@12
  char v53; // [sp+55h] [bp-113h]@17
  __int16 v54; // [sp+52h] [bp-116h]@21
  char v55; // [sp+57h] [bp-111h]@33
  char v56; // [sp+56h] [bp-112h]@37

  v6 = a1;
  v7 = a2;
  v39 = a4;
  v40 = a3;
  v41 = *MK_FP(__GS__, 20);
  std__string__string(&v42, a2);
  v5 = sub_805B8D0(v6, (int)&v42);
  _EDX = v42 - 12;
  if ( v42 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
    goto LABEL_30;
  while ( 1 )
  {
    if ( v5 < 0 )
    {
      v5 = 0;
      if ( v39 )
      {
        v5 = 0;
        *(_WORD *)v39 = 2;
      }
    }
    else
    {
      v18 = v5 << 7;
      v8 = *(_DWORD *)(v6 + 4) + v18;
      v43 = v18;
      if ( !*(_BYTE *)(v8 + 18) )
      {
        sub_8078C30((int)&v44, v8);
        std__string__assign(&v45, v40);
        v7 = &v46;
        sub_8078C30((int)&v46, (int)&v44);
        v19 = sub_8070FF0(v6, (int)&v46, 9, (int)&v47);
        sub_807B640(v10, v9, (int)&v46);
        if ( v19 )
        {
          if ( (unsigned __int8)sub_805A920(v6, (int)&v54, v47) )
          {
            if ( v39 )
            {
              v9 = v39;
              *(_WORD *)v39 = v54;
            }
            v5 = 1;
            if ( v54 )
            {
              v43 += *(_DWORD *)(v6 + 4);
              sub_8077F50(v43, (int)&v44);
              v5 = 1;
            }
            goto LABEL_7;
          }
          if ( v39 )
          {
            v9 = v39;
            v5 = 0;
            *(_WORD *)v39 = 4;
            goto LABEL_7;
          }
        }
        else
        {
          if ( v39 )
          {
            v5 = 0;
            *(_WORD *)v39 = 4;
LABEL_7:
            sub_807B640(v10, v9, (int)&v44);
            goto LABEL_8;
          }
        }
        v5 = 0;
        goto LABEL_7;
      }
      std__string__string(&v48, v8 + 12);
      std__string__string(&v49, v7);
      v13 = sub_8071410(v6, (int)&v49, v39);
      _EDX = v49 - 12;
      if ( std__string___Rep___S_empty_rep_storage != (char *)(v49 - 12) )
      {
        if ( pthread_cancel )
        {
          _EAX = -1;
          __asm { lock xadd [edx+8], eax }
          v17 = _EAX;
        }
        else
        {
          v17 = *(_DWORD *)(_EDX + 8);
          *(_DWORD *)(_EDX + 8) = v17 - 1;
        }
        if ( v17 <= 0 )
          std__string___Rep___M_destroy(_EDX, &v56);
      }
      if ( !v13 )
      {
        v5 = 0;
      }
      else
      {
        std__string__string(&v50, &v48);
        std__string__string(&v51, v40);
        v20 = v7;
        v7 = &v52;
        std__string__string(&v52, v20);
        v5 = sub_8072100(v6, (int)&v52, (int)&v51, (int)&v50, v39);
        std__string___string(&v52);
        std__string___string(&v51);
        std__string___string(&v50);
      }
      _EDX = v48 - 12;
      if ( std__string___Rep___S_empty_rep_storage != (char *)(v48 - 12) )
      {
        if ( pthread_cancel )
        {
          _EAX = -1;
          __asm { lock xadd [edx+8], eax }
          v15 = _EAX;
        }
        else
        {
          v15 = *(_DWORD *)(_EDX + 8);
          *(_DWORD *)(_EDX + 8) = v15 - 1;
        }
        if ( v15 <= 0 )
          std__string___Rep___M_destroy(_EDX, &v53);
      }
    }
LABEL_8:
    result = v5;
    if ( !(*MK_FP(__GS__, 20) ^ v41) )
      return result;
    __stack_chk_fail();
LABEL_30:
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v16 = _EAX;
    }
    else
    {
      v16 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v16 - 1;
    }
    if ( v16 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v55);
  }
}

//----- (08072E40) --------------------------------------------------------
char __cdecl sub_8072E40(int a1, int a2, int a3, int a4)
{
  int v4; // edi@1
  char result; // al@3
  signed int v7; // ebx@5
  char v9; // bl@8
  signed int v11; // esi@15
  int v12; // edx@16
  int v13; // ecx@24
  int v14; // ecx@28
  int v15; // ecx@32
  int v34; // [sp+30h] [bp-18h]@5
  __int16 v35; // [sp+1Ah] [bp-2Eh]@6
  int v36; // [sp+28h] [bp-20h]@8
  int v37; // [sp+2Ch] [bp-1Ch]@8
  char v38; // [sp+24h] [bp-24h]@15
  int v39; // [sp+20h] [bp-28h]@17
  __int16 v40; // [sp+36h] [bp-12h]@18
  char v41; // [sp+3Bh] [bp-Dh]@26
  char v42; // [sp+3Ah] [bp-Eh]@30
  char v43; // [sp+39h] [bp-Fh]@34

  v4 = a1;
  if ( !sub_805A310(a1) )
  {
LABEL_2:
    if ( a4 )
    {
      *(_WORD *)a4 = 4;
      return 0;
    }
    return 0;
  }
  std__string__string(&v34, a2);
  v7 = sub_805B8D0(v4, (int)&v34);
  _EDX = v34 - 12;
  if ( v34 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v13 = _EAX;
    }
    else
    {
      v13 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v13 - 1;
    }
    if ( v13 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v41);
  }
  v35 = 0;
  if ( v7 >= 0 )
    v35 = *(_WORD *)(*(_DWORD *)(v4 + 4) + (v7 << 7) + 16);
  std__string__string(&v36, a3);
  std__string__string(&v37, a2);
  v9 = sub_80729E0(v4, (char *)&v37, (int)&v36, a4);
  _EDX = v37 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v37 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v14 = _EAX;
    }
    else
    {
      v14 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v14 - 1;
    }
    if ( v14 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v42);
  }
  _EDX = v36 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v36 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v15 = _EAX;
    }
    else
    {
      v15 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v15 - 1;
    }
    if ( v15 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v43);
  }
  if ( !v9 )
  {
    result = sub_805A2D0(v4);
    if ( !result )
      goto LABEL_12;
    return 0;
  }
  std__string__string(&v38, a2);
  v11 = sub_805B8D0(v4, (int)&v38);
  std__string___string(&v38);
  if ( v11 < 0 || (v12 = *(_DWORD *)(v4 + 4) + (v11 << 7), v35 == *(_WORD *)(v12 + 16)) )
    goto LABEL_40;
  result = sub_805F220(v4, *(_WORD *)(v12 + 8), (int)&v39);
  if ( !result )
  {
LABEL_12:
    if ( a4 )
    {
      *(_WORD *)a4 = 4;
      return result;
    }
    return 0;
  }
  if ( (unsigned __int8)sub_805A920(v4, (int)&v40, v39) )
  {
LABEL_40:
    if ( !sub_805A2D0(v4) )
      goto LABEL_2;
    result = a4 == 0;
  }
  else
  {
    if ( !a4 )
      return 0;
    *(_WORD *)a4 = v40;
    result = 0;
  }
  return result;
}

//----- (08073610) --------------------------------------------------------
char __cdecl sub_8073610(int a1, int a2, int a3, int a4, int a5)
{
  char result; // al@1
  char v7; // si@5
  signed int v10; // esi@9
  int v11; // ecx@21
  int v12; // ecx@25
  int v13; // ecx@29
  int v32; // [sp+28h] [bp-20h]@5
  int v33; // [sp+2Ch] [bp-1Ch]@5
  int v34; // [sp+30h] [bp-18h]@5
  char v35; // [sp+24h] [bp-24h]@9
  int v36; // [sp+20h] [bp-28h]@10
  __int16 v37; // [sp+36h] [bp-12h]@17
  char v38; // [sp+3Bh] [bp-Dh]@23
  char v39; // [sp+3Ah] [bp-Eh]@27
  char v40; // [sp+39h] [bp-Fh]@31

  result = sub_805A310(a1);
  if ( !result )
  {
LABEL_2:
    if ( a5 )
    {
      *(_WORD *)a5 = 4;
      return result;
    }
    return 0;
  }
  std__string__string(&v32, a4);
  std__string__string(&v33, a3);
  std__string__string(&v34, a2);
  v7 = sub_8072100(a1, (int)&v34, (int)&v33, (int)&v32, a5);
  _EDX = v34 - 12;
  if ( v34 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v11 = _EAX;
    }
    else
    {
      v11 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v11 - 1;
    }
    if ( v11 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v38);
  }
  _EDX = v33 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v33 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v12 = _EAX;
    }
    else
    {
      v12 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v12 - 1;
    }
    if ( v12 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v39);
  }
  _EDX = v32 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v32 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v13 = _EAX;
    }
    else
    {
      v13 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v13 - 1;
    }
    if ( v13 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v40);
  }
  if ( !v7 )
  {
    if ( !sub_805A2D0(a1) )
    {
LABEL_11:
      if ( a5 )
      {
        *(_WORD *)a5 = 4;
        return 0;
      }
      return 0;
    }
    return 0;
  }
  std__string__string(&v35, a2);
  v10 = sub_805B8D0(a1, (int)&v35);
  std__string___string(&v35);
  if ( v10 >= 0 )
  {
    if ( !(unsigned __int8)sub_805F220(a1, *(_WORD *)(*(_DWORD *)(a1 + 4) + (v10 << 7) + 8), (int)&v36) )
      goto LABEL_11;
    if ( !(unsigned __int8)sub_805A920(a1, (int)&v37, v36) )
    {
      if ( a5 )
      {
        *(_WORD *)a5 = v37;
        return 0;
      }
      return 0;
    }
  }
  result = sub_805A2D0(a1);
  if ( !result )
    goto LABEL_2;
  return a5 == 0;
}

//----- (08073CB0) --------------------------------------------------------
signed int __usercall sub_8073CB0<eax>(char *a1<edi>, int a2, int a3)
{
  int v3; // edx@3
  signed int v4; // ebx@5
  signed int result; // eax@6
  int v6; // edx@8
  int v7; // ecx@8
  unsigned int v8; // ebx@8
  int v9; // eax@10
  int v10; // edi@12
  int v11; // esi@12
  int v12; // ebx@13
  int v14; // edx@16
  int v15; // edi@16
  int v16; // esi@16
  int v17; // ebx@17
  int v18; // ecx@19
  int v19; // edi@19
  int v20; // esi@19
  int v21; // ebx@20
  int v22; // edx@22
  int v23; // ecx@22
  int v24; // edi@22
  int v25; // esi@22
  int v26; // ebx@23
  int v27; // edx@25
  int v28; // edi@25
  int v29; // esi@25
  int v30; // ebx@26
  unsigned int v31; // esi@28
  int v32; // ebx@30
  int v33; // edx@31
  int v34; // esi@31
  int v35; // eax@33
  char v36; // cl@33
  int v37; // edx@41
  unsigned int v38; // ebx@42
  int v39; // edx@46
  unsigned int v40; // ecx@47
  int v41; // edx@49
  int v42; // eax@50
  int v43; // edx@52
  unsigned int v44; // ebx@53
  int v45; // edx@57
  unsigned int v46; // ebx@58
  int v47; // eax@60
  int v48; // edx@64
  int v49; // ecx@64
  signed int v50; // eax@66
  int v51; // edx@69
  unsigned int v52; // ebx@70
  int v53; // eax@72
  int v54; // ecx@72
  int v55; // ebx@72
  int v56; // esi@72
  int v57; // edx@77
  unsigned int v58; // ebx@78
  int v59; // eax@80
  int v60; // eax@81
  int v61; // eax@84
  int v62; // edx@87
  int v63; // eax@90
  int v64; // eax@94
  int v65; // ecx@97
  int v66; // eax@99
  int v67; // edx@107
  int v69; // ecx@113
  int v70; // ecx@6
  int v71; // eax@14
  int v72; // ST00_4@18
  int v73; // ST00_4@21
  int v74; // ST00_4@24
  int v75; // ST00_4@27
  int v76; // eax@28
  int v77; // edx@28
  __int16 v78; // ax@107
  int v91; // [sp+118h] [bp-10h]@1
  int v92; // [sp+1Ch] [bp-10Ch]@1
  __int16 v93; // [sp+50h] [bp-D8h]@1
  __int16 v94; // [sp+52h] [bp-D6h]@1
  __int16 v95; // [sp+54h] [bp-D4h]@1
  int v96; // [sp+58h] [bp-D0h]@1
  char v97; // [sp+68h] [bp-C0h]@1
  char v98; // [sp+5Ch] [bp-CCh]@4
  int v99; // [sp+20h] [bp-108h]@8
  int v100; // [sp+28h] [bp-100h]@19
  int v101; // [sp+2Ch] [bp-FCh]@22
  int v102; // [sp+30h] [bp-F8h]@25
  int v103; // [sp+40h] [bp-E8h]@28
  int v104; // [sp+74h] [bp-B4h]@28
  unsigned int v105; // [sp+70h] [bp-B8h]@28
  int v106; // [sp+3Ch] [bp-ECh]@28
  int v107; // [sp+14h] [bp-114h]@28
  unsigned int v108; // [sp+38h] [bp-F0h]@29
  int v109; // [sp+24h] [bp-104h]@29
  int v110; // [sp+34h] [bp-F4h]@31
  signed int v111; // [sp+98h] [bp-90h]@41
  int v112; // [sp+18h] [bp-110h]@41
  signed int v113; // [sp+9Ch] [bp-8Ch]@41
  signed int v114; // [sp+A4h] [bp-84h]@41
  int v115; // [sp+D0h] [bp-58h]@41
  int v116; // [sp+D4h] [bp-54h]@41
  int v117; // [sp+D8h] [bp-50h]@41
  signed int v118; // [sp+ECh] [bp-3Ch]@41
  signed int v119; // [sp+F0h] [bp-38h]@41
  signed int v120; // [sp+F8h] [bp-30h]@41
  signed int v121; // [sp+FCh] [bp-2Ch]@41
  signed int v122; // [sp+100h] [bp-28h]@41
  signed int v123; // [sp+104h] [bp-24h]@41
  signed int v124; // [sp+108h] [bp-20h]@41
  __int16 v125; // [sp+A0h] [bp-88h]@41
  __int16 v126; // [sp+A8h] [bp-80h]@41
  char v127; // [sp+AAh] [bp-7Eh]@41
  int v128; // [sp+ACh] [bp-7Ch]@41
  int v129; // [sp+B0h] [bp-78h]@41
  int v130; // [sp+B4h] [bp-74h]@41
  char v131; // [sp+B8h] [bp-70h]@41
  __int16 v132; // [sp+BAh] [bp-6Eh]@41
  char v133; // [sp+BCh] [bp-6Ch]@41
  int v134; // [sp+BDh] [bp-6Bh]@41
  int v135; // [sp+C1h] [bp-67h]@41
  int v136; // [sp+C5h] [bp-63h]@41
  int v137; // [sp+C9h] [bp-5Fh]@41
  signed int v138; // [sp+DCh] [bp-4Ch]@41
  int v139; // [sp+E0h] [bp-48h]@41
  char v140; // [sp+E4h] [bp-44h]@41
  int v141; // [sp+E8h] [bp-40h]@41
  char v142; // [sp+F4h] [bp-34h]@41
  char v143; // [sp+F5h] [bp-33h]@41
  char v144; // [sp+F6h] [bp-32h]@41
  int v145; // [sp+10Ch] [bp-1Ch]@41
  int v146; // [sp+110h] [bp-18h]@41
  int v147; // [sp+7Ch] [bp-ACh]@69
  int v148; // [sp+80h] [bp-A8h]@69
  int v149; // [sp+84h] [bp-A4h]@69
  signed int v150; // [sp+90h] [bp-98h]@69
  char v151; // [sp+48h] [bp-E0h]@103
  char v152; // [sp+44h] [bp-E4h]@106
  signed int v153; // [sp+8Ch] [bp-9Ch]@107
  __int16 v154; // [sp+88h] [bp-A0h]@107
  char v155; // [sp+96h] [bp-92h]@115
  char v156; // [sp+97h] [bp-91h]@124

  v91 = *MK_FP(__GS__, 20);
  v92 = a2;
  sub_8050F20((int)&v93);
  v93 = 19;
  v94 = 6;
  v95 = 1;
  v96 = a3;
  sub_8051310((int)&v97);
  while ( v95 & 1 )
  {
    if ( sub_805A590(v92, (int)&v93) != 1 || !(unsigned __int8)sub_8054CC0((int)&v97, (int)&v98, 0) )
    {
      v4 = 0;
      goto LABEL_6;
    }
  }
  v8 = 0;
  v7 = *(_DWORD *)(v92 + 8);
  v6 = *(_DWORD *)(v92 + 4);
  v99 = v92 + 4;
  while ( v8 < (v7 - v6) >> 7 )
  {
    while ( 1 )
    {
      v9 = v6 + (v8 << 7);
      if ( !*(_BYTE *)(v9 + 92) )
        break;
      ++v8;
      if ( v8 >= (v7 - v6) >> 7 )
        goto LABEL_12;
    }
    sub_807BA10(v7, v99, (int)&v151, v99, v9);
    v7 = *(_DWORD *)(v92 + 8);
    v6 = *(_DWORD *)(v92 + 4);
  }
LABEL_12:
  v10 = *(_DWORD *)(v92 + 16);
  v11 = *(_DWORD *)(v92 + 20);
  if ( v10 != v11 )
  {
    v12 = *(_DWORD *)(v92 + 16);
    do
    {
      v71 = *(_DWORD *)(v12 + 4);
      _EDX = v71 - 12;
      if ( v71 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
      {
        if ( pthread_cancel )
        {
          _EAX = -1;
          __asm { lock xadd [edx+8], eax }
          v7 = _EAX;
        }
        else
        {
          v7 = *(_DWORD *)(_EDX + 8);
          *(_DWORD *)(_EDX + 8) = v7 - 1;
        }
        if ( v7 <= 0 )
          std__string___Rep___M_destroy(_EDX, &v156);
      }
      v12 += 8;
    }
    while ( v11 != v12 );
  }
  v14 = v92;
  *(_DWORD *)(v92 + 20) = v10;
  v16 = *(_DWORD *)(v92 + 32);
  v15 = *(_DWORD *)(v92 + 28);
  if ( v15 != v16 )
  {
    v17 = *(_DWORD *)(v92 + 28);
    do
    {
      v72 = v17;
      v17 += 128;
      sub_807B640(v7, v14, v72);
    }
    while ( v16 != v17 );
  }
  *(_DWORD *)(v92 + 32) = v15;
  v18 = v92 + 40;
  v19 = *(_DWORD *)(v92 + 40);
  v20 = *(_DWORD *)(v92 + 44);
  v100 = v92 + 40;
  if ( v19 != v20 )
  {
    v21 = v19;
    do
    {
      v73 = v21;
      v21 += 128;
      sub_807B640(v18, v14, v73);
    }
    while ( v20 != v21 );
  }
  v23 = v92;
  *(_DWORD *)(v92 + 44) = v19;
  v22 = v92 + 52;
  v24 = *(_DWORD *)(v92 + 52);
  v25 = *(_DWORD *)(v92 + 56);
  v101 = v92 + 52;
  if ( v24 != v25 )
  {
    v26 = v24;
    do
    {
      v74 = v26;
      v26 += 128;
      sub_807B640(v23, v22, v74);
    }
    while ( v25 != v26 );
  }
  v27 = v92;
  *(_DWORD *)(v92 + 56) = v24;
  v28 = *(_DWORD *)(v92 + 64);
  v29 = *(_DWORD *)(v92 + 68);
  v102 = v92 + 64;
  if ( v28 != v29 )
  {
    v30 = v28;
    do
    {
      v75 = v30;
      v30 += 128;
      sub_807B640(v23, v27, v75);
    }
    while ( v29 != v30 );
  }
  v76 = *(_DWORD *)(v92 + 264);
  *(_DWORD *)(v92 + 68) = v28;
  v103 = v92 + 256;
  sub_8077D60(v92 + 256, v76);
  v77 = v104;
  v31 = v105;
  *(_DWORD *)(v92 + 268) = v92 + 260;
  *(_DWORD *)(v92 + 264) = 0;
  *(_DWORD *)(v92 + 272) = v92 + 260;
  *(_DWORD *)(v92 + 276) = 0;
  v106 = v92 + 260;
  v107 = v77;
  if ( !(-1227133513 * ((signed int)(v77 - v31) >> 2)) )
    goto LABEL_64;
  a1 = 0;
  v108 = 0;
  v109 = v92 + 16;
  do
  {
    v32 = (int)&a1[v31];
    if ( *(_WORD *)&a1[v31 + 12] <= 0xEu )
    {
      switch ( *(_WORD *)(v32 + 12) )
      {
        case 0:
          v112 = (int)&v111;
          v111 = 134771820;
          v113 = 134771820;
          v114 = 134771820;
          v115 = 0;
          v116 = 0;
          v117 = 0;
          v118 = 134771820;
          v119 = 134771820;
          v120 = 134771820;
          v121 = 134771820;
          v122 = 134771820;
          v123 = 134771820;
          v124 = 134771820;
          v125 = 0;
          v126 = 0;
          v127 = 0;
          v128 = 0;
          v129 = 0;
          v130 = 0;
          v131 = 0;
          v132 = 0;
          v133 = 0;
          v134 = 0;
          v135 = 0;
          v136 = 0;
          v137 = 0;
          v138 = -1;
          v139 = 0;
          v140 = 0;
          v141 = 0;
          v142 = 0;
          v143 = 0;
          v144 = 0;
          v145 = 0;
          v146 = 0;
          std__string__assign(&v111, &a1[v105 + 4]);
          v125 = *(_WORD *)&a1[v105 + 8];
          v126 = *(_WORD *)&a1[v105 + 10];
          std__string__assign(&v113, 134739702, 0);
          std__string__assign(&v114, 134739702, 0);
          v127 = 0;
          v57 = *(_DWORD *)&a1[v105 + 16];
          if ( (*(_DWORD *)&a1[v105 + 20] - v57) >> 4 )
          {
            v58 = 0;
            do
            {
              v59 = v57 + 16 * v58;
              if ( *(_WORD *)v59 == 305 )
                sub_8051550(v59, (int)&v113);
              v60 = *(_DWORD *)&a1[v105 + 16];
              if ( *(_WORD *)(v60 + 16 * v58) == 102 )
                v127 = 1;
              v57 = v60;
              ++v58;
            }
            while ( v58 < (*(_DWORD *)&a1[v105 + 20] - v60) >> 4 );
          }
          v128 = 0;
          v129 = 0;
          v130 = 0;
          v61 = *(_DWORD *)(v92 + 8);
          if ( v61 == *(_DWORD *)(v92 + 12) )
          {
            sub_807BC40(v99, *(_DWORD *)(v92 + 8), v112);
          }
          else
          {
            if ( v61 )
            {
              sub_8078C30(*(_DWORD *)(v92 + 8), v112);
              v61 = *(_DWORD *)(v92 + 8);
            }
            v62 = v92;
            *(_DWORD *)(v92 + 8) = v61 + 128;
          }
          goto LABEL_88;
        case 1:
          if ( !*(_WORD *)(v32 + 8) )
            goto LABEL_63;
          v78 = *(_WORD *)&a1[v31 + 8];
          v153 = 134771820;
          v154 = v78;
          std__string__assign(&v153, &a1[v105 + 4]);
          v67 = *(_DWORD *)(v92 + 20);
          if ( v67 == *(_DWORD *)(v92 + 24) )
            goto LABEL_126;
          if ( v67 )
          {
            *(_WORD *)v67 = v154;
            std__string__string(v67 + 4, &v153);
            v67 = *(_DWORD *)(v92 + 20);
          }
          *(_DWORD *)(v92 + 20) = v67 + 8;
          goto LABEL_111;
        case 2:
          v111 = 134771820;
          v113 = 134771820;
          v114 = 134771820;
          v115 = 0;
          v116 = 0;
          v117 = 0;
          v118 = 134771820;
          v119 = 134771820;
          v120 = 134771820;
          v121 = 134771820;
          v122 = 134771820;
          v123 = 134771820;
          v124 = 134771820;
          v125 = 0;
          v126 = 0;
          v127 = 0;
          v128 = 0;
          v129 = 0;
          v130 = 0;
          v131 = 0;
          v132 = 0;
          v133 = 0;
          v112 = (int)&v111;
          v134 = 0;
          v135 = 0;
          v136 = 0;
          v137 = 0;
          v138 = -1;
          v139 = 0;
          v140 = 0;
          v141 = 0;
          v142 = 0;
          v143 = 0;
          v144 = 0;
          v145 = 0;
          v146 = 0;
          std__string__assign(&v111, &a1[v105 + 4]);
          v125 = *(_WORD *)&a1[v105 + 8];
          v126 = *(_WORD *)&a1[v105 + 10];
          v45 = *(_DWORD *)&a1[v105 + 16];
          if ( (*(_DWORD *)&a1[v105 + 20] - v45) >> 4 )
          {
            v46 = 0;
            do
            {
              v47 = v45 + 16 * v46;
              if ( *(_WORD *)v47 == 305 )
                sub_8051550(v47, (int)&v113);
              ++v46;
              v45 = *(_DWORD *)&a1[v105 + 16];
            }
            while ( v46 < (*(_DWORD *)&a1[v105 + 20] - v45) >> 4 );
          }
          v63 = *(_DWORD *)(v100 + 4);
          if ( v63 == *(_DWORD *)(v100 + 8) )
          {
            sub_807BC40(v100, *(_DWORD *)(v100 + 4), v112);
          }
          else
          {
            if ( v63 )
            {
              sub_8078C30(*(_DWORD *)(v100 + 4), v112);
              v63 = *(_DWORD *)(v100 + 4);
            }
            v62 = v100;
            *(_DWORD *)(v100 + 4) = v63 + 128;
          }
LABEL_88:
          sub_807B640(v112, v62, v112);
          goto LABEL_89;
        case 3:
          v111 = 134771820;
          v113 = 134771820;
          v114 = 134771820;
          v115 = 0;
          v116 = 0;
          v117 = 0;
          v118 = 134771820;
          v119 = 134771820;
          v120 = 134771820;
          v121 = 134771820;
          v122 = 134771820;
          v123 = 134771820;
          v124 = 134771820;
          v125 = 0;
          v126 = 0;
          v127 = 0;
          v128 = 0;
          v129 = 0;
          v130 = 0;
          v131 = 0;
          v132 = 0;
          v133 = 0;
          v112 = (int)&v111;
          v134 = 0;
          v135 = 0;
          v136 = 0;
          v137 = 0;
          v138 = -1;
          v139 = 0;
          v140 = 0;
          v141 = 0;
          v142 = 0;
          v143 = 0;
          v144 = 0;
          v145 = 0;
          v146 = 0;
          std__string__assign(&v111, &a1[v105 + 4]);
          v125 = *(_WORD *)&a1[v105 + 8];
          v126 = *(_WORD *)&a1[v105 + 10];
          v43 = *(_DWORD *)&a1[v105 + 16];
          if ( (*(_DWORD *)&a1[v105 + 20] - v43) >> 4 )
          {
            v44 = 0;
            do
            {
              if ( *(_WORD *)(v43 + 16 * v44) == 305 )
                sub_8051550(v43 + 16 * v44, (int)&v113);
              ++v44;
              v43 = *(_DWORD *)&a1[v105 + 16];
            }
            while ( v44 < (*(_DWORD *)&a1[v105 + 20] - v43) >> 4 );
          }
          v64 = *(_DWORD *)(v101 + 4);
          if ( v64 == *(_DWORD *)(v101 + 8) )
          {
            sub_807BC40(v101, *(_DWORD *)(v101 + 4), v112);
          }
          else
          {
            if ( v64 )
            {
              sub_8078C30(*(_DWORD *)(v101 + 4), v112);
              v64 = *(_DWORD *)(v101 + 4);
            }
            v65 = v101;
            *(_DWORD *)(v101 + 4) = v64 + 128;
          }
          goto LABEL_98;
        case 4:
          *(_WORD *)(v92 + 298) = *(_WORD *)(v32 + 10);
          v39 = *(_DWORD *)&a1[v105 + 16];
          if ( (*(_DWORD *)&a1[v105 + 20] - v39) >> 4 )
          {
            v40 = 0;
            do
            {
              v41 = 16 * v40 + v39;
              if ( *(_WORD *)v41 == 202 )
              {
                v42 = *(_DWORD *)(v41 + 4);
                if ( *(_DWORD *)(v41 + 8) != v42 )
                  *(_BYTE *)(v92 + 296) = *(_BYTE *)v42;
              }
              ++v40;
              v39 = *(_DWORD *)&a1[v105 + 16];
            }
            while ( v40 < (*(_DWORD *)&a1[v105 + 20] - v39) >> 4 );
          }
          break;
        case 5:
        case 6:
        case 7:
        case 8:
        case 9:
        case 0xA:
        case 0xB:
        case 0xC:
        case 0xD:
          goto LABEL_31;
        case 0xE:
          v112 = (int)&v111;
          v111 = 134771820;
          v113 = 134771820;
          v114 = 134771820;
          v115 = 0;
          v116 = 0;
          v117 = 0;
          v118 = 134771820;
          v119 = 134771820;
          v120 = 134771820;
          v121 = 134771820;
          v122 = 134771820;
          v123 = 134771820;
          v124 = 134771820;
          v125 = 0;
          v126 = 0;
          v127 = 0;
          v128 = 0;
          v129 = 0;
          v130 = 0;
          v131 = 0;
          v132 = 0;
          v133 = 0;
          v134 = 0;
          v135 = 0;
          v136 = 0;
          v137 = 0;
          v138 = -1;
          v139 = 0;
          v140 = 0;
          v141 = 0;
          v142 = 0;
          v143 = 0;
          v144 = 0;
          v145 = 0;
          v146 = 0;
          std__string__assign(&v111, &a1[v105 + 4]);
          v125 = *(_WORD *)&a1[v105 + 8];
          v126 = *(_WORD *)&a1[v105 + 10];
          v37 = *(_DWORD *)&a1[v105 + 16];
          if ( (*(_DWORD *)&a1[v105 + 20] - v37) >> 4 )
          {
            v38 = 0;
            do
            {
              if ( *(_WORD *)(v37 + 16 * v38) == 305 )
                sub_8051550(v37 + 16 * v38, (int)&v113);
              ++v38;
              v37 = *(_DWORD *)&a1[v105 + 16];
            }
            while ( v38 < (*(_DWORD *)&a1[v105 + 20] - v37) >> 4 );
          }
          v66 = *(_DWORD *)(v102 + 4);
          if ( v66 == *(_DWORD *)(v102 + 8) )
          {
            sub_807BC40(v102, *(_DWORD *)(v102 + 4), v112);
          }
          else
          {
            if ( v66 )
            {
              sub_8078C30(*(_DWORD *)(v102 + 4), v112);
              v66 = *(_DWORD *)(v102 + 4);
            }
            v65 = v102;
            *(_DWORD *)(v102 + 4) = v66 + 128;
          }
LABEL_98:
          sub_807B640(v65, v112, v112);
          v31 = v105;
          v107 = v104;
          break;
      }
      goto LABEL_63;
    }
LABEL_31:
    v110 = v32 + 10;
    v34 = v106;
    v33 = *(_DWORD *)(v92 + 264);
    if ( !v33 )
    {
LABEL_104:
      if ( v34 == *(_DWORD *)(v92 + 268) )
      {
        sub_80785C0(v103, v110, (int)&v152, v103, 0, v34, v110);
        v31 = v105;
        v107 = v104;
        goto LABEL_63;
      }
      if ( *(_WORD *)(std___Rb_tree_decrement(v34) + 16) < *(_WORD *)(v32 + 10) )
        goto LABEL_106;
LABEL_39:
      v31 = v105;
      v107 = v104;
      goto LABEL_63;
    }
    while ( *(_WORD *)(v32 + 10) < *(_WORD *)(v33 + 16) )
    {
      v35 = *(_DWORD *)(v33 + 8);
      v36 = 1;
      if ( !v35 )
        goto LABEL_37;
LABEL_34:
      v33 = v35;
    }
    v35 = *(_DWORD *)(v33 + 12);
    v36 = 0;
    if ( v35 )
      goto LABEL_34;
LABEL_37:
    v34 = v33;
    if ( v36 )
      goto LABEL_104;
    if ( *(_WORD *)(v33 + 16) >= *(_WORD *)(v32 + 10) )
      goto LABEL_39;
LABEL_106:
    sub_80785C0(v110, v103, (int)&v152, v103, 0, v34, v110);
    v31 = v105;
    v107 = v104;
LABEL_63:
    a1 += 28;
    ++v108;
  }
  while ( v108 < -1227133513 * ((signed int)(v107 - v31) >> 2) );
LABEL_64:
  v49 = *(_DWORD *)(v92 + 8);
  v48 = *(_DWORD *)(v92 + 4);
  if ( (v49 - v48) >> 7 )
  {
    v31 = 0;
    do
    {
      v50 = sub_8058090(v92, *(_WORD *)(v48 + (v31 << 7) + 8));
      if ( v50 >= 0 )
        std__string__assign(*(_DWORD *)(v92 + 4) + (v31 << 7) + 12, *(_DWORD *)(v92 + 16) + 8 * v50 + 4);
      ++v31;
      v49 = *(_DWORD *)(v92 + 8);
      v48 = *(_DWORD *)(v92 + 4);
    }
    while ( v31 < (v49 - v48) >> 7 );
  }
  a1 = (char *)&v147;
  v147 = 0;
  v148 = 0;
  v149 = 0;
  v150 = 134771820;
  sub_807B1F0((int)&v147, 0, (v49 - v48) >> 7, (int)&v150);
  std__string___string(&v150);
  v51 = *(_DWORD *)(v92 + 4);
  if ( (*(_DWORD *)(v92 + 8) - v51) >> 7 )
  {
    v52 = 0;
    do
    {
      std__string__assign(v147 + 4 * v52, v51 + (v52 << 7));
      ++v52;
      v51 = *(_DWORD *)(v92 + 4);
    }
    while ( v52 < (*(_DWORD *)(v92 + 8) - v51) >> 7 );
  }
  sub_8064FC0((int)&v147, v31, v92, (int)&v147);
  v53 = v147;
  v56 = v148;
  v55 = v147;
  if ( v148 != v147 )
  {
    do
    {
      std__string___string(v55);
      v55 += 4;
    }
    while ( v56 != v55 );
    v53 = v147;
  }
  v4 = 1;
  if ( v53 )
  {
    v4 = 1;
    operator delete(v54, v3);
  }
LABEL_6:
  sub_8054AA0((int)&v97, v3, (int)&v97);
  sub_8052330(v70, (int)&v93, (int)&v93);
  result = v4;
  if ( *MK_FP(__GS__, 20) ^ v91 )
  {
    __stack_chk_fail();
LABEL_126:
    sub_807DEF0(v109, v67, (int)&v154);
LABEL_111:
    _EDX = v153 - 12;
    if ( std__string___Rep___S_empty_rep_storage == (char *)(v153 - 12) )
    {
LABEL_89:
      v31 = v105;
      v107 = v104;
      goto LABEL_63;
    }
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v69 = _EAX;
    }
    else
    {
      v69 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v69 - 1;
    }
    if ( v69 <= 0 )
    {
      std__string___Rep___M_destroy(_EDX, &v155);
      v31 = v105;
      v107 = v104;
      goto LABEL_63;
    }
    goto LABEL_39;
  }
  return result;
}

//----- (08074E00) --------------------------------------------------------
signed int __cdecl sub_8074E00(int a1, int a2, int a3, __int16 a4, int a5, unsigned __int8 a6)
{
  int v7; // ebx@1
  char *v8; // edi@1
  signed int result; // eax@2
  int v10; // edx@9
  int v11; // ecx@9
  int v12; // ecx@36
  int v13; // eax@1
  int v20; // [sp+44h] [bp-14h]@1
  int v21; // [sp+40h] [bp-18h]@8
  int v22; // [sp+3Ch] [bp-1Ch]@12
  int v23; // [sp+38h] [bp-20h]@13
  int v24; // [sp+34h] [bp-24h]@14
  int v25; // [sp+30h] [bp-28h]@15
  int v26; // [sp+2Ch] [bp-2Ch]@16
  int v27; // [sp+28h] [bp-30h]@17
  int v28; // [sp+24h] [bp-34h]@18
  char v29; // [sp+4Bh] [bp-Dh]@38

  v7 = a1;
  v13 = a3;
  v8 = (char *)a6;
  *(_DWORD *)(a1 + 120) = 14;
  std__string__string(&v20, v13);
  *(_DWORD *)(v7 + 164) = sub_805B550(v7, &v20, a4);
  _EDX = v20 - 12;
  if ( v20 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v12 = _EAX;
    }
    else
    {
      v12 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v12 - 1;
    }
    if ( v12 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v29);
  }
  result = 0;
  if ( *(_DWORD *)(v7 + 164) >= 0 )
  {
    *(_DWORD *)(v7 + 120) += 3;
    if ( (unsigned __int8)sub_805B480(v7) )
    {
      *(_DWORD *)(v7 + 120) += 3;
      if ( (unsigned __int8)sub_805F070(v7, a5) )
      {
        *(_DWORD *)(v7 + 120) += 4;
        if ( (unsigned __int8)sub_805B100(v7) )
        {
          *(_DWORD *)(v7 + 120) += 4;
          if ( sub_805D2C0(v7) )
          {
            *(_DWORD *)(v7 + 120) += 3;
            if ( (unsigned __int8)sub_805AFB0(v7) )
            {
              *(_DWORD *)(v7 + 120) += 3;
              if ( sub_805A550(v7, (int)&v21) )
              {
                *(_DWORD *)(v7 + 120) += 4;
                if ( (unsigned __int8)sub_805C940(v7, v21) )
                {
                  *(_DWORD *)(v7 + 120) += 4;
                  if ( sub_805BCF0(v11, v10, v7) )
                  {
                    *(_DWORD *)(v7 + 120) += 3;
                    if ( (_BYTE)v8 )
                      goto LABEL_30;
                    if ( sub_805A510(v7, (int)&v22) )
                    {
                      ++*(_DWORD *)(v7 + 120);
                      if ( sub_805A3D0(v7, (int)&v23) )
                      {
                        *(_DWORD *)(v7 + 120) += 3;
                        if ( sub_805A390(v7, (int)&v24) )
                        {
                          *(_DWORD *)(v7 + 120) += 3;
                          if ( sub_805A4D0(v7, (int)&v25) )
                          {
                            *(_DWORD *)(v7 + 120) += 3;
                            if ( sub_805A490(v7, (int)&v26) )
                            {
                              *(_DWORD *)(v7 + 120) += 3;
                              if ( sub_805A450(v7, (int)&v27) )
                              {
                                *(_DWORD *)(v7 + 120) += 3;
                                if ( sub_805A410(v7, (int)&v28) )
                                {
                                  *(_DWORD *)(v7 + 120) += 3;
                                  if ( sub_805AED0(v7, v25) )
                                  {
                                    *(_DWORD *)(v7 + 120) += 3;
                                    if ( sub_805AE60(v7, v26) )
                                    {
                                      *(_DWORD *)(v7 + 120) += 3;
                                      if ( (unsigned __int8)sub_805B6B0(v7, v27) )
                                      {
                                        *(_DWORD *)(v7 + 120) += 4;
                                        if ( sub_805ADF0(v7, v28) )
                                        {
                                          *(_DWORD *)(v7 + 120) += 3;
                                          if ( sub_805AD80(v7, v23) )
                                          {
                                            *(_DWORD *)(v7 + 120) += 4;
                                            if ( (unsigned __int8)sub_8073CB0(v8, v7, v24) )
                                            {
                                              *(_DWORD *)(v7 + 120) += 3;
                                              if ( (unsigned __int8)sub_805C4B0(v7) )
                                              {
                                                *(_DWORD *)(v7 + 120) += 4;
                                                if ( sub_805AF40(v7, v22) )
                                                {
                                                  ++*(_DWORD *)(v7 + 120);
                                                  if ( (unsigned __int8)sub_805BF30(v7) )
                                                  {
                                                    *(_DWORD *)(v7 + 120) += 4;
                                                    if ( (unsigned __int8)sub_805F520(v7, a2, 1) )
                                                    {
                                                      *(_DWORD *)(v7 + 292) = a2;
LABEL_30:
                                                      if ( sub_805DD60(v7) )
                                                      {
                                                        *(_DWORD *)(v7 + 120) += 3;
                                                        if ( (_BYTE)v8 )
                                                        {
LABEL_32:
                                                          *(_DWORD *)(v7 + 120) = 100;
                                                          return 1;
                                                        }
                                                        if ( sub_805A350(v7) )
                                                        {
                                                          *(_DWORD *)(v7 + 120) += 4;
                                                          if ( (unsigned __int8)sub_805F520(v7, a2, 0) )
                                                          {
                                                            *(_DWORD *)(v7 + 292) = a2;
                                                            goto LABEL_32;
                                                          }
                                                        }
                                                      }
                                                      goto LABEL_33;
                                                    }
                                                  }
                                                }
                                              }
                                            }
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
LABEL_33:
    close(*(_DWORD *)(v7 + 164));
    result = 0;
    *(_DWORD *)(v7 + 164) = -1;
  }
  return result;
}

//----- (080751D0) --------------------------------------------------------
signed int __cdecl sub_80751D0(int a1, int a2)
{
  int v3; // esi@1
  int v4; // ecx@2
  signed int v5; // ebx@5
  int v8; // ecx@22
  int v9; // edi@1
  int v10; // ST00_4@4
  signed int *v11; // eax@16
  __int16 v12; // bx@16
  int v25; // [sp+30h] [bp-38h]@1
  int v26; // [sp+24h] [bp-44h]@1
  int v27; // [sp+3Ch] [bp-2Ch]@1
  int v28; // [sp+40h] [bp-28h]@1
  int v29; // [sp+44h] [bp-24h]@1
  signed int v30; // [sp+54h] [bp-14h]@1
  int v31; // [sp+34h] [bp-34h]@1
  int v32; // [sp+38h] [bp-30h]@1
  signed int *v33; // [sp+28h] [bp-40h]@1
  int v34; // [sp+4Ch] [bp-1Ch]@1
  int v35; // [sp+50h] [bp-18h]@13
  char v36; // [sp+48h] [bp-20h]@16
  char v37; // [sp+5Ah] [bp-Eh]@20
  char v38; // [sp+5Bh] [bp-Dh]@24

  v3 = a1;
  *(_WORD *)(a1 + 100) = 0;
  std__string__assign(a1 + 104, 134739702, 0);
  v9 = *(_DWORD *)(v3 + 156);
  *(_DWORD *)(v3 + 120) = 0;
  v26 = (int)&v25;
  v27 = 0;
  v28 = 0;
  v29 = 0;
  v30 = 134771820;
  v25 = 0;
  v31 = 0;
  v32 = 0;
  v33 = &v30;
  std__string__string(&v34, v3 + 152);
  *(_DWORD *)(v3 + 164) = sub_805B550(v3, &v34, v9);
  _EDX = v34 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v34 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v8 = _EAX;
    }
    else
    {
      v8 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v8 - 1;
    }
    if ( v8 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v38);
  }
  v4 = *(_DWORD *)(v3 + 164);
  if ( v4 < 0 )
  {
    v5 = 0;
  }
  else
  {
    *(_DWORD *)(v3 + 120) += 2;
    v26 = (int)&v25;
    v33 = &v30;
    if ( !(unsigned __int8)sub_805B480(v3)
      || (*(_DWORD *)(v3 + 120) += 2, v26 = (int)&v25, v33 = &v30, !(unsigned __int8)sub_8066B30(v3)) )
    {
      v10 = *(_DWORD *)(v3 + 164);
      v26 = (int)&v25;
      v33 = &v30;
      close(v10);
LABEL_5:
      *(_DWORD *)(v3 + 164) = -1;
      v5 = 0;
      goto LABEL_6;
    }
    *(_DWORD *)(v3 + 120) += 8;
    v26 = (int)&v25;
    v33 = &v30;
    if ( !(unsigned __int8)sub_805B230(v3, (int)&v30, (int)&v35, (int)&v25) )
    {
      close(*(_DWORD *)(v3 + 164));
      goto LABEL_5;
    }
    *(_DWORD *)(v3 + 120) += 2;
    sub_805A110(v3);
    close(*(_DWORD *)(v3 + 164));
    v11 = v33;
    *(_DWORD *)(v3 + 164) = -1;
    v12 = v35;
    std__string__string(&v36, v11);
    v5 = sub_8074E00(v3, a2, (int)&v36, v12, v26, 0);
    std__string___string(&v36);
  }
LABEL_6:
  if ( v25 )
    operator delete(v4, _EDX);
  _EDX = v30 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v30 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v4 = _EAX;
    }
    else
    {
      v4 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v4 - 1;
    }
    if ( v4 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v37);
  }
  if ( v27 )
    operator delete(v4, _EDX);
  return v5;
}

//----- (080754B0) --------------------------------------------------------
int __cdecl sub_80754B0(int a1, __int16 a2)
{
  int v2; // edx@1
  int v3; // ecx@1
  int v4; // ebx@1
  unsigned int v5; // eax@2
  int v6; // edx@6
  int v7; // ecx@6
  __int16 *v8; // edi@6
  int v9; // esi@6
  int v11; // ecx@10
  int v12; // ecx@13
  char v13; // zf@14
  int v14; // eax@14
  int v15; // esi@15
  int v16; // eax@22
  int v17; // edx@23
  int v18; // ecx@23
  int v19; // ecx@25
  int v20; // ebx@25
  unsigned int v21; // eax@26
  __int16 v22; // dx@26
  int v23; // edx@1
  __int16 v24; // ax@6
  int v25; // eax@6
  int v26; // edx@13
  int v27; // eax@23
  int v28; // eax@24
  int v29; // ecx@24
  int v30; // edx@24
  int v31; // eax@24
  int v32; // edx@24
  int v33; // ebx@24
  __int16 v34; // [sp+38h] [bp-70h]@1
  int v35; // [sp+6Ch] [bp-3Ch]@6
  int v36; // [sp+74h] [bp-34h]@6
  int v37; // [sp+70h] [bp-38h]@6
  int v38; // [sp+98h] [bp-10h]@6
  __int16 v39; // [sp+44h] [bp-64h]@10
  __int16 v40; // [sp+46h] [bp-62h]@10
  int v41; // [sp+4Ch] [bp-5Ch]@10
  char v42; // [sp+5Ch] [bp-4Ch]@13
  char v43; // [sp+50h] [bp-58h]@13
  signed int v44; // [sp+94h] [bp-14h]@23
  int v45; // [sp+34h] [bp-74h]@23
  char v46; // [sp+90h] [bp-18h]@24
  char v47; // [sp+8Ch] [bp-1Ch]@24
  int v48; // [sp+28h] [bp-80h]@24
  char v49; // [sp+88h] [bp-20h]@24
  int v50; // [sp+2Ch] [bp-7Ch]@24
  char v51; // [sp+7Ch] [bp-2Ch]@24
  char v52; // [sp+80h] [bp-28h]@24
  int v53; // [sp+30h] [bp-78h]@24
  char v54; // [sp+84h] [bp-24h]@24
  int v55; // [sp+24h] [bp-84h]@24
  char v56; // [sp+78h] [bp-30h]@24

  v4 = a1;
  v3 = *(_DWORD *)(a1 + 176);
  v23 = *(_DWORD *)(a1 + 180);
  v34 = a2;
  v2 = (v23 - v3) >> 2;
  if ( v2 )
  {
    v5 = 0;
    if ( *(_WORD *)v3 == a2 )
      return v4;
    while ( 1 )
    {
      ++v5;
      if ( v5 >= v2 )
        break;
      if ( *(_WORD *)(v3 + 4 * v5) == a2 )
        return v4;
    }
  }
  v24 = __ROR__(v34, 8);
  v34 = v24;
  v25 = operator new(v3, v2);
  v35 = v25;
  v8 = &v34;
  v36 = v25 + 2;
  *(_WORD *)v25 = 0;
  v37 = v36;
  *(_WORD *)v35 = v34;
  v9 = 0;
  if ( sub_805A180(v4, 1, 4, (int)&v38, (int)&v35) == 1 )
  {
    sub_8050F20((int)&v39);
    v39 = 1;
    v40 = 5;
    v41 = v38;
    v9 = 0;
    if ( sub_805A590(v4, (int)&v39) == 1 )
    {
      sub_8050FB0((int)&v42);
      if ( !(unsigned __int8)sub_8055270(v12, v26, (int)&v42, (int)&v43, 0) )
        goto LABEL_33;
      v14 = sub_8050FE0((int)&v42, 13);
      v13 = v14 == 0;
      if ( !v14 )
        goto LABEL_33;
      v15 = *(_DWORD *)(v14 + 4);
      v12 = 2;
      do
      {
        if ( !v12 )
          break;
        v13 = *(_BYTE *)v15++ == *(_BYTE *)v8;
        v8 = (__int16 *)((char *)v8 + 1);
        --v12;
      }
      while ( v13 );
      if ( v13 && (v16 = sub_8050FE0((int)&v42, 5), v16) )
      {
        v44 = 134771820;
        sub_8051550(v16, (int)&v44);
        v27 = sub_8050FE0((int)&v42, 6);
        v9 = 0;
        v45 = v27;
        if ( v27 )
        {
          v28 = operator new(v18, v17);
          v9 = v28;
          sub_80689D0(v29, v30, v28);
          std__string__string(&v46, v4 + 124);
          std__string__assign(v9 + 124, &v46);
          std__string___string(&v46);
          std__string__string(&v47, v4 + 148);
          std__string__assign(v9 + 148, &v47);
          std__string___string(&v47);
          v48 = *(_DWORD *)(v4 + 156);
          std__string__string(&v49, v4 + 152);
          std__string__assign(v9 + 152, &v49);
          *(_DWORD *)(v9 + 156) = v48;
          std__string___string(&v49);
          v50 = *(_DWORD *)(v4 + 144);
          std__string__string(&v51, v4 + 140);
          std__string__string(&v52, v4 + 136);
          v53 = *(_DWORD *)(v4 + 132);
          std__string__string(&v54, v4 + 128);
          sub_8077CF0(v9, (int)&v54, v53, (int)&v52, (int)&v51, v50);
          std__string___string(&v54);
          std__string___string(&v52);
          std__string___string(&v51);
          v31 = *(_DWORD *)(v4 + 280);
          v32 = v45;
          v33 = *(_DWORD *)(v4 + 156);
          *(_DWORD *)(v9 + 280) = v31;
          v55 = v32 + 4;
          std__string__string(&v56, &v44);
          LOBYTE(v33) = sub_8074E00(v9, 0, (int)&v56, v33, v55, 1u);
          std__string___string(&v56);
          if ( (_BYTE)v33 && (v20 = *(_DWORD *)(v9 + 176), v19 = (*(_DWORD *)(v9 + 180) - v20) >> 2, v19) )
          {
            v21 = 0;
            v22 = __ROR__(v34, 8);
            while ( *(_WORD *)(v20 + 4 * v21) != v22 )
            {
              ++v21;
              if ( v21 >= v19 )
                goto LABEL_30;
            }
          }
          else
          {
LABEL_30:
            sub_805B650(v9);
            (*(int (__cdecl **)(int))(*(_DWORD *)v9 + 4))(v9);
            v9 = 0;
          }
        }
        std__string___string(&v44);
      }
      else
      {
LABEL_33:
        v9 = 0;
      }
      sub_8052390(v11, (int)&v42, (int)&v42);
    }
    sub_8052330(v7, (int)&v39, (int)&v39);
    v4 = v9;
    if ( v35 )
      goto LABEL_8;
  }
  else
  {
    v4 = 0;
    if ( v35 )
    {
LABEL_8:
      v4 = v9;
      operator delete(v7, v6);
      return v4;
    }
  }
  return v4;
}

//----- (08075960) --------------------------------------------------------
signed int __usercall sub_8075960<eax>(int *a1<edi>, int a2, int a3)
{
  signed int v3; // ebx@1
  int v4; // esi@1
  int v5; // edx@2
  int v6; // edx@3
  int v7; // ecx@3
  signed int v8; // eax@4
  signed int result; // eax@12
  int v10; // ecx@16
  signed int v11; // eax@17
  int v12; // edx@19
  int v13; // edx@26
  int v14; // ecx@26
  int v15; // eax@3
  int v16; // eax@14
  int v17; // [sp+88h] [bp-10h]@1
  char v18; // [sp+6Ch] [bp-2Ch]@3
  int v19; // [sp+18h] [bp-80h]@3
  __int16 v20; // [sp+72h] [bp-26h]@3
  char v21; // [sp+74h] [bp-24h]@3
  int v22; // [sp+76h] [bp-22h]@3
  int v23; // [sp+7Ah] [bp-1Eh]@3
  int v24; // [sp+7Eh] [bp-1Ah]@3
  int v25; // [sp+38h] [bp-60h]@3
  int v26; // [sp+3Ch] [bp-5Ch]@3
  int v27; // [sp+40h] [bp-58h]@3
  int v28; // [sp+82h] [bp-16h]@3
  int v29; // [sp+44h] [bp-54h]@3
  __int16 v30; // [sp+20h] [bp-78h]@16
  __int16 v31; // [sp+22h] [bp-76h]@16
  int v32; // [sp+28h] [bp-70h]@16
  char v33; // [sp+48h] [bp-50h]@26
  char v34; // [sp+2Ch] [bp-6Ch]@26
  char v35; // [sp+60h] [bp-38h]@27

  v4 = a3;
  v17 = *MK_FP(__GS__, 20);
  v3 = a2;
  if ( *(_BYTE *)(a3 + 32) )
  {
    v5 = *(_DWORD *)(a2 + 248);
    if ( v5 || (v16 = sub_80754B0(a2, 16), v5 = v16, *(_DWORD *)(v3 + 248) = v16, v16) )
    {
      a1 = (int *)&v18;
      v19 = *(_DWORD *)(v5 + 280);
      *(_DWORD *)(v5 + 280) = *(_DWORD *)(v3 + 280);
      sub_8051390((int)&v18);
      std__string__assign(&v18, v4);
      v20 = *(_WORD *)(v4 + 34);
      v21 = *(_BYTE *)(v4 + 36);
      v22 = *(_DWORD *)(v4 + 37);
      v23 = *(_DWORD *)(v4 + 41);
      v24 = *(_DWORD *)(v4 + 45);
      v15 = *(_DWORD *)(v4 + 49);
      v25 = 0;
      v26 = 0;
      v27 = 0;
      v28 = v15;
      sub_8052610((int)&v18, (int)&v25, 0);
      if ( sub_805A180(*(_DWORD *)(v3 + 248), 16, 6, (int)&v29, (int)&v25) != 1 )
      {
        v8 = *(_DWORD *)(v3 + 248);
        if ( v8 && v3 != v8 )
        {
          sub_805B650(*(_DWORD *)(v3 + 248));
          v6 = *(_DWORD *)(v3 + 248);
          if ( v6 )
            (*(int (__cdecl **)(_DWORD))(*(_DWORD *)v6 + 4))(*(_DWORD *)(v3 + 248));
          *(_DWORD *)(v3 + 248) = 0;
          v3 = 0;
        }
        else
        {
          v3 = 0;
        }
        goto LABEL_9;
      }
      sub_8050F20((int)&v30);
      v30 = 16;
      v31 = 7;
      v32 = v29;
      if ( sub_805A590(*(_DWORD *)(v3 + 248), (int)&v30) != 1 )
      {
        v11 = *(_DWORD *)(v3 + 248);
        if ( v11 && v3 != v11 )
        {
          sub_805B650(*(_DWORD *)(v3 + 248));
          v12 = *(_DWORD *)(v3 + 248);
          if ( v12 )
            (*(int (__cdecl **)(_DWORD))(*(_DWORD *)v12 + 4))(*(_DWORD *)(v3 + 248));
          *(_DWORD *)(v3 + 248) = 0;
          v3 = 0;
        }
        else
        {
          v3 = 0;
        }
        goto LABEL_22;
      }
      goto LABEL_26;
    }
  }
  v3 = 0;
  while ( 1 )
  {
    result = v3;
    if ( !(*MK_FP(__GS__, 20) ^ v17) )
      break;
    __stack_chk_fail();
LABEL_26:
    *(_DWORD *)(*(_DWORD *)(v3 + 248) + 280) = v19;
    sub_80513E0((int)&v33);
    v3 = 0;
    if ( (unsigned __int8)sub_8054030((int)&v33, (int)&v34, 0) )
    {
      sub_804B500(v14, v13, v4 + 56, (int)&v35);
      v3 = 1;
    }
    sub_80548E0(v10, (int)&v33, (int)&v33);
LABEL_22:
    sub_8052330(v7, (int)&v30, (int)&v30);
LABEL_9:
    if ( v25 )
      operator delete(v7, v6);
    sub_8054260(a1);
  }
  return result;
}

//----- (080766A0) --------------------------------------------------------
signed int __cdecl sub_80766A0(int a1, int a2)
{
  int v2; // edx@1
  int v3; // ecx@1
  int v4; // esi@1
  int v5; // ebx@2
  signed int v6; // ebx@3
  int v10; // ecx@9
  int v11; // ecx@13
  int v12; // esi@6
  int (__cdecl *v13)(_DWORD, _DWORD, _DWORD); // edi@6
  signed int v26; // [sp+24h] [bp-14h]@1
  int v27; // [sp+20h] [bp-18h]@6
  char v28; // [sp+2Ah] [bp-Eh]@11
  char v29; // [sp+2Bh] [bp-Dh]@15

  v4 = a2;
  v26 = 134771820;
  v3 = *(_DWORD *)a2;
  v2 = *(_DWORD *)(a2 + 4) - *(_DWORD *)a2;
  if ( (unsigned int)v2 > 0xA && (v5 = *(_BYTE *)(v3 + 10), v5 + 11 <= (unsigned int)v2) )
  {
    std__string__assign(&v26, v3 + 11, v5);
    v12 = *(_DWORD *)v4;
    v13 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD))(*(_DWORD *)a1 + 64);
    std__string__string(&v27, &v26);
    v13(a1, &v27, v12);
    _EDX = v27 - 12;
    if ( std__string___Rep___S_empty_rep_storage == (char *)(v27 - 12) )
      goto LABEL_20;
    if ( !pthread_cancel )
    {
      v11 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v11 - 1;
    }
    else
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v11 = _EAX;
    }
    if ( v11 > 0 )
    {
LABEL_20:
      v6 = 1;
    }
    else
    {
      v6 = 1;
      std__string___Rep___M_destroy(_EDX, &v29);
    }
  }
  else
  {
    v6 = 0;
  }
  _EDX = v26 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v26 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v10 = _EAX;
    }
    else
    {
      v10 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v10 - 1;
    }
    if ( v10 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v28);
  }
  return v6;
}

//----- (080767E0) --------------------------------------------------------
signed int __cdecl sub_80767E0(int a1, int a2)
{
  int v2; // ebx@1
  int v3; // esi@1
  int v4; // ecx@2
  int v5; // eax@20
  signed int v6; // eax@22
  int v7; // edx@24
  signed int result; // eax@27
  signed int v9; // edi@40
  char v10; // al@54
  int v11; // eax@64
  signed int v12; // edi@64
  int v13; // edx@65
  signed int v14; // ecx@65
  signed int v15; // edi@70
  int v16; // eax@71
  signed int v17; // edx@71
  char *v18; // ebx@72
  signed int v19; // edi@75
  signed int v20; // eax@2
  int v21; // edi@17
  int (__cdecl *v22)(_DWORD, _DWORD); // edi@31
  int v23; // edi@43
  int v24; // eax@66
  int v25; // ebx@67
  int v26; // eax@72
  int (__cdecl *v27)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD); // edi@72
  int v28; // edi@76
  int v29; // edi@79
  int (__cdecl *v30)(_DWORD, _DWORD); // edi@82
  int v31; // edi@92
  int (__cdecl *v32)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD); // edi@93
  int v33; // [sp+158h] [bp-10h]@1
  signed int v34; // [sp+64h] [bp-104h]@2
  int v35; // [sp+6Ch] [bp-FCh]@2
  signed int v36; // [sp+48h] [bp-120h]@2
  signed int v37; // [sp+A4h] [bp-C4h]@16
  signed int *v38; // [sp+24h] [bp-144h]@16
  unsigned __int16 v39; // [sp+DEh] [bp-8Ah]@16
  char v40; // [sp+70h] [bp-F8h]@16
  int (__cdecl *v41)(_DWORD, _DWORD, _DWORD); // [sp+40h] [bp-128h]@17
  char v42; // [sp+A8h] [bp-C0h]@17
  char v43; // [sp+108h] [bp-60h]@30
  int v44; // [sp+20h] [bp-148h]@30
  char v45; // [sp+130h] [bp-38h]@31
  signed int v46; // [sp+9Ch] [bp-CCh]@35
  signed int *v47; // [sp+28h] [bp-140h]@35
  signed int v48; // [sp+98h] [bp-D0h]@35
  int v49; // [sp+A0h] [bp-C8h]@35
  char v50; // [sp+D8h] [bp-90h]@40
  char v51; // [sp+114h] [bp-54h]@40
  char v52; // [sp+118h] [bp-50h]@42
  int (__cdecl *v53)(_DWORD, _DWORD, _DWORD); // [sp+2Ch] [bp-13Ch]@43
  char v54; // [sp+E0h] [bp-88h]@43
  int v55; // [sp+C4h] [bp-A4h]@57
  unsigned __int8 v56; // [sp+57h] [bp-111h]@58
  int v57; // [sp+38h] [bp-130h]@58
  int v58; // [sp+50h] [bp-118h]@58
  char v59; // [sp+C0h] [bp-A8h]@64
  int v60; // [sp+4Ch] [bp-11Ch]@64
  int (__cdecl *v61)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD); // [sp+3Ch] [bp-12Ch]@67
  char v62; // [sp+BCh] [bp-ACh]@67
  char v63; // [sp+B8h] [bp-B0h]@70
  char v64; // [sp+B0h] [bp-B8h]@72
  int (__cdecl *v65)(_DWORD, _DWORD, _DWORD); // [sp+30h] [bp-138h]@74
  char v66; // [sp+D0h] [bp-98h]@74
  char v67; // [sp+D4h] [bp-94h]@74
  char v68; // [sp+94h] [bp-D4h]@75
  int (__cdecl *v69)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD); // [sp+58h] [bp-110h]@76
  char v70; // [sp+7Ch] [bp-ECh]@76
  char v71; // [sp+80h] [bp-E8h]@76
  char v72; // [sp+84h] [bp-E4h]@76
  int (__cdecl *v73)(_DWORD, _DWORD, _DWORD, _DWORD); // [sp+34h] [bp-134h]@79
  char v74; // [sp+C8h] [bp-A0h]@79
  char v75; // [sp+CCh] [bp-9Ch]@79
  char v76; // [sp+ACh] [bp-BCh]@82
  int (__cdecl *v77)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD); // [sp+44h] [bp-124h]@92
  char v78; // [sp+88h] [bp-E0h]@92
  char v79; // [sp+8Ch] [bp-DCh]@92
  char v80; // [sp+90h] [bp-D8h]@92
  char v81; // [sp+B4h] [bp-B4h]@93

  v3 = a1;
  v33 = *MK_FP(__GS__, 20);
  v2 = *(_DWORD *)(a1 + 280);
  *(_DWORD *)(a1 + 280) = a2;
  if ( time(0) - *(_DWORD *)(a1 + 288) > 60 )
    sub_805A070(v3);
  sub_8050F20((int)&v34);
  v34 = 0;
  v35 = 0;
  v20 = sub_805A590(v3, (int)&v34);
  v36 = v20;
  *(_DWORD *)(v3 + 280) = v2;
  if ( v20 != 1 )
    goto LABEL_27;
  if ( v34 == 196629 )
  {
    sub_8064400(v3, (int)&v34);
    goto LABEL_20;
  }
  if ( v34 == 458756 )
  {
    v44 = (int)&v43;
    sub_80778E0((int)&v43);
    if ( !(unsigned __int8)sub_80708D0(v3, (char *)v44, (int)&v40) )
    {
      sub_80500E0(v44);
      v36 = -2;
      goto LABEL_27;
    }
    v22 = *(int (__cdecl **)(_DWORD, _DWORD))(*(_DWORD *)v3 + 16);
    sub_8077A10((int)&v45, v44);
    v22(v3, &v45);
    sub_80500E0((int)&v45);
    sub_80500E0(v44);
    goto LABEL_20;
  }
  if ( v34 == 786436 )
  {
    if ( !(unsigned __int8)sub_80766A0(v3, (int)&v40) )
    {
LABEL_33:
      v36 = -2;
      goto LABEL_27;
    }
    goto LABEL_20;
  }
  if ( v34 == 720900 )
  {
    v44 = (int)&v43;
    sub_80778E0((int)&v43);
    if ( (unsigned __int8)sub_8059D50(v3, v44, (int)&v39, (int)&v40) )
    {
      std__string__string(&v50, &v51);
      v9 = sub_805B8D0(v3, (int)&v50);
      std__string___string(&v50);
      if ( v9 >= 0 )
      {
        switch ( (_BYTE)v39 + 24 )
        {
          case 4:
            if ( !sub_8078550(*(_DWORD *)(v3 + 4) + (v9 << 7) + 112, (int)&v52) )
              std__string__assign(*(_DWORD *)(v3 + 4) + (v9 << 7) + 112, &v52);
            break;
          case 3:
            if ( !sub_8078550(*(_DWORD *)(v3 + 4) + (v9 << 7) + 108, (int)&v52) )
              std__string__assign(*(_DWORD *)(v3 + 4) + (v9 << 7) + 108, &v52);
            break;
          case 2:
            if ( !sub_8078550(*(_DWORD *)(v3 + 4) + (v9 << 7) + 104, (int)&v52) )
              std__string__assign(*(_DWORD *)(v3 + 4) + (v9 << 7) + 104, &v52);
            break;
          case 0:
            if ( !sub_8078550(*(_DWORD *)(v3 + 4) + (v9 << 7) + 96, (int)&v52) )
              std__string__assign(*(_DWORD *)(v3 + 4) + (v9 << 7) + 96, &v52);
            break;
          case 1:
            if ( !sub_8078550(*(_DWORD *)(v3 + 4) + (v9 << 7) + 100, (int)&v52) )
              std__string__assign(*(_DWORD *)(v3 + 4) + (v9 << 7) + 100, &v52);
            break;
          default:
            break;
        }
      }
      v23 = (unsigned __int8)v39;
      v53 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD))(*(_DWORD *)v3 + 52);
      sub_8077A10((int)&v54, v44);
      v53(v3, &v54, v23);
      sub_80500E0((int)&v54);
      sub_80500E0(v44);
      goto LABEL_20;
    }
    sub_80500E0(v44);
    v47 = &v46;
    v37 = 134771820;
    v46 = 134771820;
    v48 = 134771820;
    v38 = &v37;
    if ( (unsigned __int8)sub_8059F40(v3, &v37, &v49, &v46, &v48, &v40) )
    {
      std__string__string(&v68, v38);
      v19 = sub_805B8D0(v3, (int)&v68);
      std__string___string(&v68);
      if ( v19 < 0 )
      {
        v77 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD))(*(_DWORD *)v3 + 44);
        std__string__string(&v78, &v48);
        std__string__string(&v79, v47);
        v31 = v49;
        std__string__string(&v80, v38);
        v77(v3, &v80, v31, &v79, &v78);
        std__string___string(&v80);
        std__string___string(&v79);
        std__string___string(&v78);
      }
      else
      {
        *(_DWORD *)(*(_DWORD *)(v3 + 4) + (v19 << 7) + 80) = v49;
        std__string__assign(*(_DWORD *)(v3 + 4) + (v19 << 7) + 84, v47);
        std__string__assign(*(_DWORD *)(v3 + 4) + (v19 << 7) + 88, &v48);
        v69 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD))(*(_DWORD *)v3 + 44);
        std__string__string(&v70, &v48);
        std__string__string(&v71, v47);
        v28 = v49;
        std__string__string(&v72, v38);
        v69(v3, &v72, v28, &v71, &v70);
        std__string___string(&v72);
        std__string___string(&v71);
        std__string___string(&v70);
      }
      std__string___string(&v48);
      std__string___string(v47);
      goto LABEL_18;
    }
    std__string___string(&v48);
    std__string___string(v47);
LABEL_37:
    std__string___string(v38);
    goto LABEL_33;
  }
  if ( v34 == 1638419 )
  {
    v37 = 134771820;
    v46 = 134771820;
    v47 = &v46;
    v38 = &v37;
    if ( (unsigned __int8)sub_8058560(v3, (int)&v37, (int)&v46, (int)&v40) )
    {
      v65 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD))(*(_DWORD *)v3 + 20);
      std__string__string(&v66, v47);
      std__string__string(&v67, v38);
      v65(v3, &v67, &v66);
      std__string___string(&v67);
      std__string___string(&v66);
      std__string___string(v47);
      goto LABEL_18;
    }
    std__string___string(v47);
    goto LABEL_37;
  }
  if ( v34 == 1769491 )
  {
    v46 = 134771820;
    v37 = 134771820;
    v38 = &v37;
    v47 = &v46;
    if ( (unsigned __int8)sub_80584B0(v3, (int)&v46, (int)&v37, (int)&v39, (int)&v40) )
      goto LABEL_79;
    std__string___string(v38);
    std__string___string(v47);
    goto LABEL_33;
  }
  if ( v34 == 720899 )
  {
    v37 = 134771820;
    v49 = 0;
    v38 = &v37;
    if ( (unsigned __int8)sub_805CAB0(v3, (int)&v37, (int)&v55, (int)&v40, (int)&v49) )
    {
      v56 = 0;
      v57 = v55;
      v58 = (unsigned __int16)v55;
      if ( BYTE1(v55) & 1 )
      {
        v56 = 1;
        v58 = v57 & 0xF0FF;
      }
      switch ( v58 )
      {
        case 5:
          v58 = 4;
          break;
        case 0x11:
          v58 = 16;
          break;
        case 0x13:
          v58 = 2;
          break;
      }
      std__string__string(&v59, v38);
      v12 = sub_805B8D0(v3, (int)&v59);
      std__string___string(&v59);
      HIWORD(v11) = HIWORD(v57);
      LOWORD(v11) = 0;
      v60 = v11;
      if ( v12 >= 0 )
      {
        v14 = v12 << 7;
        v13 = *(_DWORD *)(v3 + 4) + (v12 << 7);
        if ( *(_DWORD *)(v13 + 72) == v11
          && *(_DWORD *)(v13 + 68) == v58
          && *(_BYTE *)(v13 + 76) == v56
          && *(_DWORD *)(v13 + 80) == v49 )
          goto LABEL_68;
        *(_DWORD *)(v13 + 72) = v60;
        v24 = *(_DWORD *)(v3 + 4);
        *(_DWORD *)(v24 + v14 + 68) = v58;
        *(_BYTE *)(v24 + v14 + 76) = v56;
        *(_DWORD *)(v24 + v14 + 80) = v49;
      }
      v25 = v49;
      v61 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD))(*(_DWORD *)v3 + 28);
      std__string__string(&v62, v38);
      v61(v3, &v62, v60, v58, v56, v25);
      std__string___string(&v62);
LABEL_68:
      std__string___string(v38);
      goto LABEL_20;
    }
LABEL_95:
    std__string___string(v38);
    goto LABEL_33;
  }
  if ( v34 == 786435 )
  {
    v37 = 134771820;
    v38 = &v37;
    if ( (unsigned __int8)sub_80581D0(v3, (int)&v37, (int)&v40) )
    {
      std__string__string(&v63, v38);
      v15 = sub_805B8D0(v3, (int)&v63);
      std__string___string(&v63);
      if ( v15 < 0 )
      {
        v18 = &v81;
        v32 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD))(*(_DWORD *)v3 + 28);
        std__string__string(&v81, v38);
        v32(v3, &v81, 0, -1, 0, 0);
      }
      else
      {
        v17 = v15 << 7;
        v16 = *(_DWORD *)(v3 + 4) + (v15 << 7);
        if ( !*(_DWORD *)(v16 + 72) && *(_DWORD *)(v16 + 68) == -1 && !*(_BYTE *)(v16 + 76) )
          goto LABEL_18;
        *(_DWORD *)(v16 + 72) = 0;
        v26 = *(_DWORD *)(v3 + 4);
        v18 = &v64;
        *(_DWORD *)(v26 + v17 + 68) = -1;
        *(_BYTE *)(v26 + v17 + 76) = 0;
        *(_BYTE *)(v26 + v17 + 93) = 0;
        *(_BYTE *)(v26 + v17 + 94) = 0;
        v27 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD))(*(_DWORD *)v3 + 28);
        std__string__string(&v64, v38);
        v27(v3, &v64, 0, -1, 0, 0);
      }
      std__string___string(v18);
LABEL_18:
      std__string___string(v38);
      goto LABEL_20;
    }
    goto LABEL_37;
  }
  if ( v34 == 524307 || v34 == 589843 )
  {
    v10 = sub_806E5C0(v2, v3, (int)&v40);
  }
  else
  {
    if ( v34 != 655379 )
    {
      if ( v34 != 1835027 )
      {
        if ( v34 != 1310724 )
          goto LABEL_20;
        v37 = 134771820;
        v38 = &v37;
        if ( (unsigned __int8)sub_8058220(v3, (int)&v37, (int)&v39, (int)&v40) )
        {
          v21 = v39;
          v41 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD))(*(_DWORD *)v3 + 12);
          std__string__string(&v42, v38);
          v41(v3, &v42, v21);
          std__string___string(&v42);
          goto LABEL_18;
        }
        goto LABEL_37;
      }
      v37 = 134771820;
      v38 = &v37;
      if ( (unsigned __int8)sub_8058180(v3, (int)&v37, (int)&v40) )
      {
        v30 = *(int (__cdecl **)(_DWORD, _DWORD))(*(_DWORD *)v3 + 36);
        std__string__string(&v76, v38);
        v30(v3, &v76);
        std__string___string(&v76);
        goto LABEL_68;
      }
      goto LABEL_95;
    }
    v10 = sub_8067C80(v3, (int)&v40);
  }
  if ( !v10 )
    goto LABEL_33;
  (*(int (__cdecl **)(int))(*(_DWORD *)v3 + 32))(v3);
  while ( 1 )
  {
LABEL_20:
    v5 = *(_DWORD *)(v3 + 248);
    if ( v5 )
    {
      if ( v3 != v5 )
      {
        v6 = sub_80767E0(*(_DWORD *)(v3 + 248), a2);
        if ( v6 != 1 )
        {
          if ( v6 != -2 )
          {
            sub_805B650(*(_DWORD *)(v3 + 248));
            v7 = *(_DWORD *)(v3 + 248);
            if ( v7 )
              (*(int (__cdecl **)(_DWORD))(*(_DWORD *)v7 + 4))(*(_DWORD *)(v3 + 248));
            *(_DWORD *)(v3 + 248) = 0;
          }
        }
      }
    }
LABEL_27:
    sub_8052330(v4, (int)&v34, (int)&v34);
    result = v36;
    if ( !(*MK_FP(__GS__, 20) ^ v33) )
      break;
    __stack_chk_fail();
LABEL_79:
    v29 = (unsigned __int8)v39;
    v73 = *(int (__cdecl **)(_DWORD, _DWORD, _DWORD, _DWORD))(*(_DWORD *)v3 + 24);
    std__string__string(&v74, v38);
    std__string__string(&v75, v47);
    v73(v3, &v75, &v74, v29);
    std__string___string(&v75);
    std__string___string(&v74);
    std__string___string(v38);
    std__string___string(v47);
  }
  return result;
}

//----- (08077860) --------------------------------------------------------
void __cdecl sub_8077860()
{
  ;
}

//----- (08077870) --------------------------------------------------------
void __cdecl sub_8077870()
{
  ;
}

//----- (08077880) --------------------------------------------------------
void __cdecl sub_8077880()
{
  ;
}

//----- (08077890) --------------------------------------------------------
void __cdecl sub_8077890()
{
  ;
}

//----- (080778A0) --------------------------------------------------------
void __cdecl sub_80778A0()
{
  ;
}

//----- (080778B0) --------------------------------------------------------
void __cdecl sub_80778B0()
{
  ;
}

//----- (080778C0) --------------------------------------------------------
void __cdecl sub_80778C0()
{
  ;
}

//----- (080778D0) --------------------------------------------------------
void __cdecl sub_80778D0()
{
  ;
}

//----- (080778E0) --------------------------------------------------------
int __cdecl sub_80778E0(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)(a1 + 24) = -1;
  *(_DWORD *)(a1 + 12) = 134771820;
  *(_DWORD *)(a1 + 16) = 134771820;
  *(_DWORD *)(a1 + 28) = 1;
  *(_WORD *)(a1 + 32) = 0;
  *(_DWORD *)(a1 + 20) = 0;
  *(_BYTE *)(a1 + 27) = 0;
  *(_BYTE *)(a1 + 34) = 0;
  return result;
}

//----- (08077920) --------------------------------------------------------
int __cdecl sub_8077920(int a1)
{
  int result; // eax@1

  result = a1;
  *(_DWORD *)a1 = 134771820;
  *(_DWORD *)(a1 + 4) = 134771820;
  *(_DWORD *)(a1 + 12) = 134771820;
  *(_DWORD *)(a1 + 56) = 0;
  *(_DWORD *)(a1 + 60) = 0;
  *(_DWORD *)(a1 + 64) = 0;
  *(_DWORD *)(a1 + 84) = 134771820;
  *(_DWORD *)(a1 + 88) = 134771820;
  *(_DWORD *)(a1 + 96) = 134771820;
  *(_DWORD *)(a1 + 100) = 134771820;
  *(_DWORD *)(a1 + 104) = 134771820;
  *(_DWORD *)(a1 + 108) = 134771820;
  *(_DWORD *)(a1 + 112) = 134771820;
  *(_WORD *)(a1 + 8) = 0;
  *(_WORD *)(a1 + 16) = 0;
  *(_BYTE *)(a1 + 18) = 0;
  *(_DWORD *)(a1 + 20) = 0;
  *(_DWORD *)(a1 + 24) = 0;
  *(_DWORD *)(a1 + 28) = 0;
  *(_BYTE *)(a1 + 32) = 0;
  *(_WORD *)(a1 + 34) = 0;
  *(_BYTE *)(a1 + 36) = 0;
  *(_DWORD *)(a1 + 37) = 0;
  *(_DWORD *)(a1 + 41) = 0;
  *(_DWORD *)(a1 + 45) = 0;
  *(_DWORD *)(a1 + 49) = 0;
  *(_DWORD *)(a1 + 68) = -1;
  *(_DWORD *)(a1 + 72) = 0;
  *(_BYTE *)(a1 + 76) = 0;
  *(_DWORD *)(a1 + 80) = 0;
  *(_BYTE *)(a1 + 92) = 0;
  *(_BYTE *)(a1 + 93) = 0;
  *(_BYTE *)(a1 + 94) = 0;
  *(_DWORD *)(a1 + 116) = 0;
  *(_DWORD *)(a1 + 120) = 0;
  return result;
}

//----- (08077A10) --------------------------------------------------------
int __cdecl sub_8077A10(int a1, int a2)
{
  int result; // eax@1
  int v3; // edi@1
  int v4; // esi@1
  char v5; // dl@1
  char v6; // cl@1
  char v7; // bl@1
  char v8; // al@1
  char v9; // dl@1
  char v10; // cl@1
  char v11; // bl@1
  char v12; // al@1
  char v13; // dl@1
  char v14; // cl@1
  char v15; // bl@1
  int v16; // eax@1
  char v17; // [sp+1Bh] [bp-Dh]@1
  char v18; // [sp+1Ah] [bp-Eh]@1
  char v19; // [sp+19h] [bp-Fh]@1
  char v20; // [sp+18h] [bp-10h]@1
  int v21; // [sp+14h] [bp-14h]@1

  v3 = a2;
  v4 = a1;
  v5 = *(_BYTE *)(a2 + 6);
  v6 = *(_BYTE *)(a2 + 5);
  v7 = *(_BYTE *)(a2 + 4);
  v17 = *(_BYTE *)(a2 + 3);
  v18 = *(_BYTE *)(a2 + 2);
  v19 = *(_BYTE *)(a2 + 1);
  v20 = *(_BYTE *)a2;
  v8 = *(_BYTE *)(a2 + 7);
  *(_BYTE *)(a1 + 6) = v5;
  *(_BYTE *)(a1 + 5) = v6;
  *(_BYTE *)(a1 + 4) = v7;
  *(_BYTE *)(a1 + 7) = v8;
  *(_BYTE *)(a1 + 3) = v17;
  *(_BYTE *)(a1 + 2) = v18;
  *(_BYTE *)(a1 + 1) = v19;
  *(_BYTE *)a1 = v20;
  *(_BYTE *)(a1 + 8) = *(_BYTE *)(v3 + 8);
  v21 = a1 + 12;
  std__string__string(a1 + 12, v3 + 12);
  std__string__string(v4 + 16, v3 + 16);
  v9 = *(_BYTE *)(v3 + 22);
  v10 = *(_BYTE *)(v3 + 21);
  v11 = *(_BYTE *)(v3 + 20);
  *(_BYTE *)(v4 + 23) = *(_BYTE *)(v3 + 23);
  v12 = *(_BYTE *)(v3 + 27);
  *(_BYTE *)(v4 + 22) = v9;
  v13 = *(_BYTE *)(v3 + 26);
  *(_BYTE *)(v4 + 21) = v10;
  v14 = *(_BYTE *)(v3 + 25);
  *(_BYTE *)(v4 + 20) = v11;
  v15 = *(_BYTE *)(v3 + 24);
  *(_BYTE *)(v4 + 27) = v12;
  v16 = *(_DWORD *)(v3 + 28);
  *(_BYTE *)(v4 + 26) = v13;
  *(_BYTE *)(v4 + 25) = v14;
  *(_BYTE *)(v4 + 24) = v15;
  *(_DWORD *)(v4 + 28) = v16;
  *(_WORD *)(v4 + 32) = *(_WORD *)(v3 + 32);
  *(_BYTE *)(v4 + 34) = *(_BYTE *)(v3 + 34);
  result = *(_DWORD *)(v3 + 36);
  *(_DWORD *)(v4 + 36) = *(_DWORD *)(v3 + 36);
  return result;
}

//----- (08077B20) --------------------------------------------------------
int __cdecl sub_8077B20(int a1, int a2)
{
  int result; // eax@1
  int v3; // ebx@1
  int v4; // esi@1
  int v5; // [sp+14h] [bp-14h]@1
  int v6; // [sp+18h] [bp-10h]@1

  v3 = a2;
  v4 = a1;
  std__string__string(a1, a2);
  v5 = v4 + 4;
  std__string__string(v4 + 4, v3 + 4);
  v6 = v4 + 8;
  std__string__string(v4 + 8, v3 + 8);
  std__string__string(v4 + 12, v3 + 12);
  std__string__string(v4 + 16, v3 + 16);
  *(_DWORD *)(v4 + 20) = *(_DWORD *)(v3 + 20);
  *(_BYTE *)(v4 + 24) = *(_BYTE *)(v3 + 24);
  *(_DWORD *)(v4 + 28) = *(_DWORD *)(v3 + 28);
  result = *(_WORD *)(v3 + 32);
  *(_WORD *)(v4 + 32) = *(_WORD *)(v3 + 32);
  return result;
}

//----- (08077C10) --------------------------------------------------------
int __stdcall ZStplIcSt11char_traitsIcESaIcEESbIT_T0_T1_ERKS6_S8_(int a1, int a2, int a3)
{
  int v2; // esi@1

  v2 = a1;
  std__string__string(a1, a2);
  std__string__append(v2, a3);
  return v2;
}

//----- (08077C60) --------------------------------------------------------
int __cdecl sub_8077C60(int a1, int a2)
{
  int v3; // ebx@1
  int v4; // esi@1

  v3 = a1;
  v4 = a2;
  std__string__assign(a1, a2);
  std__string__assign(v3 + 4, v4 + 4);
  std__string__assign(v3 + 8, v4 + 8);
  std__string__assign(v3 + 12, v4 + 12);
  std__string__assign(v3 + 16, v4 + 16);
  *(_DWORD *)(v3 + 20) = *(_DWORD *)(v4 + 20);
  *(_BYTE *)(v3 + 24) = *(_BYTE *)(v4 + 24);
  *(_DWORD *)(v3 + 28) = *(_DWORD *)(v4 + 28);
  *(_WORD *)(v3 + 32) = *(_WORD *)(v4 + 32);
  return v3;
}

//----- (08077CF0) --------------------------------------------------------
int __cdecl sub_8077CF0(int a1, int a2, int a3, int a4, int a5, int a6)
{
  int result; // eax@1
  int v7; // ebx@1

  v7 = a1;
  std__string__assign(a1 + 128, a2);
  *(_DWORD *)(v7 + 132) = a3;
  std__string__assign(v7 + 136, a4);
  std__string__assign(v7 + 140, a5);
  result = a6;
  *(_DWORD *)(v7 + 144) = a6;
  return result;
}

//----- (08077D60) --------------------------------------------------------
void __cdecl sub_8077D60(int a1, int a2)
{
  int v2; // edi@1
  int v3; // esi@1
  int v4; // ebx@2
  int v5; // ecx@2
  int v6; // edx@2

  v3 = a2;
  v2 = a1;
  if ( a2 )
  {
    do
    {
      sub_8077D60(v2, *(_DWORD *)(v3 + 12));
      v4 = *(_DWORD *)(v3 + 8);
      operator delete(v5, v6);
      v3 = v4;
    }
    while ( v4 );
  }
}

//----- (08077DA0) --------------------------------------------------------
void __cdecl sub_8077DA0(int a1)
{
  sub_8077D60(a1, *(_DWORD *)(a1 + 8));
}

//----- (08077DD0) --------------------------------------------------------
int __fastcall sub_8077DD0(int a1, int a2, int a3)
{
  int result; // eax@1

  result = *(_DWORD *)a3;
  if ( *(_DWORD *)a3 )
  {
    a3 = *(_DWORD *)a3;
    result = operator delete(a1, a2);
  }
  return result;
}

//----- (08077DF0) --------------------------------------------------------
int __fastcall sub_8077DF0(int a1, int a2, int a3)
{
  int result; // eax@1

  result = *(_DWORD *)a3;
  if ( *(_DWORD *)a3 )
  {
    a3 = *(_DWORD *)a3;
    result = operator delete(a1, a2);
  }
  return result;
}

//----- (08077E10) --------------------------------------------------------
int __cdecl sub_8077E10(int a1, int a2, int a3)
{
  int v3; // esi@1
  int v4; // ebx@2
  int v5; // edi@2
  int result; // eax@4

  v3 = a2;
  if ( a2 )
  {
    v5 = a1;
    v4 = a1 + 4;
    do
    {
      if ( v5 )
        result = std__string__string(v5, a3);
      v5 = v4;
      v4 += 4;
      --v3;
    }
    while ( v3 );
  }
  return result;
}

//----- (08077E90) --------------------------------------------------------
int __cdecl sub_8077E90(int a1, int a2, int a3)
{
  int v3; // esi@1
  int v4; // ebx@2
  int v5; // edi@2

  v3 = a1;
  if ( a1 != a2 )
  {
    v5 = a3;
    v4 = a3 + 4;
    do
    {
      if ( v5 )
        std__string__string(v5, v3);
      v3 += 4;
      v5 = v4;
      v4 += 4;
    }
    while ( a2 != v3 );
    a3 = v5;
  }
  return a3;
}

//----- (08077F10) --------------------------------------------------------
#error "8077F4F: invalid basic block (funcsize=31)"

//----- (08077F50) --------------------------------------------------------
int __cdecl sub_8077F50(int a1, int a2)
{
  int v3; // esi@1
  int v4; // ebx@1
  int v5; // ecx@1
  int v6; // edx@1

  v3 = a1;
  v4 = a2;
  std__string__assign(a1, a2);
  std__string__assign(v3 + 4, v4 + 4);
  *(_WORD *)(v3 + 8) = *(_WORD *)(v4 + 8);
  std__string__assign(v3 + 12, v4 + 12);
  *(_WORD *)(v3 + 16) = *(_WORD *)(v4 + 16);
  *(_BYTE *)(v3 + 18) = *(_BYTE *)(v4 + 18);
  *(_DWORD *)(v3 + 20) = *(_DWORD *)(v4 + 20);
  *(_DWORD *)(v3 + 24) = *(_DWORD *)(v4 + 24);
  *(_DWORD *)(v3 + 28) = *(_DWORD *)(v4 + 28);
  *(_BYTE *)(v3 + 32) = *(_BYTE *)(v4 + 32);
  *(_WORD *)(v3 + 34) = *(_WORD *)(v4 + 34);
  *(_BYTE *)(v3 + 36) = *(_BYTE *)(v4 + 36);
  *(_DWORD *)(v3 + 37) = *(_DWORD *)(v4 + 37);
  *(_DWORD *)(v3 + 41) = *(_DWORD *)(v4 + 41);
  *(_DWORD *)(v3 + 45) = *(_DWORD *)(v4 + 45);
  *(_DWORD *)(v3 + 49) = *(_DWORD *)(v4 + 49);
  sub_804B500(v5, v6, v3 + 56, v4 + 56);
  *(_DWORD *)(v3 + 68) = *(_DWORD *)(v4 + 68);
  *(_DWORD *)(v3 + 72) = *(_DWORD *)(v4 + 72);
  *(_BYTE *)(v3 + 76) = *(_BYTE *)(v4 + 76);
  *(_DWORD *)(v3 + 80) = *(_DWORD *)(v4 + 80);
  std__string__assign(v3 + 84, v4 + 84);
  std__string__assign(v3 + 88, v4 + 88);
  *(_BYTE *)(v3 + 92) = *(_BYTE *)(v4 + 92);
  *(_BYTE *)(v3 + 93) = *(_BYTE *)(v4 + 93);
  *(_BYTE *)(v3 + 94) = *(_BYTE *)(v4 + 94);
  std__string__assign(v3 + 96, v4 + 96);
  std__string__assign(v3 + 100, v4 + 100);
  std__string__assign(v3 + 104, v4 + 104);
  std__string__assign(v3 + 108, v4 + 108);
  std__string__assign(v3 + 112, v4 + 112);
  *(_DWORD *)(v3 + 116) = *(_DWORD *)(v4 + 116);
  *(_DWORD *)(v3 + 120) = *(_DWORD *)(v4 + 120);
  *(_DWORD *)(v3 + 124) = *(_DWORD *)(v4 + 124);
  return v3;
}

//----- (080780C0) --------------------------------------------------------
int __fastcall sub_80780C0(int a1, int a2, int a3, const void *a4, int a5)
{
  size_t v5; // ebx@1
  void *v6; // edi@1
  int v7; // ecx@2
  int v8; // esi@2
  int result; // eax@4
  size_t v10; // eax@6
  int v11; // eax@2
  const void *v12; // esi@7
  int v13; // ebx@7

  v6 = *(void **)a3;
  v5 = a5 - (_DWORD)a4;
  if ( a5 - (_DWORD)a4 <= (unsigned int)(*(_DWORD *)(a3 + 8) - *(_DWORD *)a3) )
  {
    v10 = *(_DWORD *)(a3 + 4) - (_DWORD)v6;
    if ( v5 <= v10 )
    {
      memmove(v6, a4, a5 - (_DWORD)a4);
      result = (int)((char *)v6 + v5);
      *(_DWORD *)(a3 + 4) = (char *)v6 + v5;
    }
    else
    {
      v12 = (char *)a4 + v10;
      memmove(*(void **)a3, a4, v10);
      v13 = a5 - (_DWORD)v12 + *(_DWORD *)(a3 + 4);
      memmove(*(void **)(a3 + 4), v12, a5 - (_DWORD)v12);
      result = a3;
      *(_DWORD *)(a3 + 4) = v13;
    }
  }
  else
  {
    v11 = operator new(a1, a2);
    v8 = v11;
    memmove((void *)v11, a4, v5);
    if ( *(_DWORD *)a3 )
      operator delete(v7, a3);
    *(_DWORD *)a3 = v8;
    result = v8 + v5;
    *(_DWORD *)(a3 + 4) = v8 + v5;
    *(_DWORD *)(a3 + 8) = v8 + v5;
  }
  return result;
}

//----- (080781A0) --------------------------------------------------------
void *__fastcall sub_80781A0(int a1, int a2, int a3, const void *a4, int a5)
{
  int v5; // edi@1
  size_t v6; // esi@1
  int v7; // eax@2
  void *result; // eax@3
  char v9; // zf@1
  const void *v10; // edx@3
  int v11; // ebx@3

  v5 = a3;
  v6 = a5 - (_DWORD)a4;
  v9 = a5 == (_DWORD)a4;
  *(_DWORD *)a3 = 0;
  *(_DWORD *)(a3 + 4) = 0;
  *(_DWORD *)(a3 + 8) = 0;
  if ( v9 )
    v7 = 0;
  else
    v7 = operator new(a1, a2);
  v10 = a4;
  v11 = v7 + v6;
  *(_DWORD *)(v5 + 8) = v7 + v6;
  *(_DWORD *)v5 = v7;
  result = memmove((void *)v7, v10, v6);
  *(_DWORD *)(v5 + 4) = v11;
  return result;
}

//----- (08078230) --------------------------------------------------------
void *__cdecl sub_8078230(int a1, const void *a2, int a3)
{
  int v3; // edx@1
  int v4; // edi@1
  const void *v5; // esi@1
  int v6; // ecx@2
  void *result; // eax@4
  int v8; // edx@6
  int v9; // edx@7
  void *v10; // edx@9
  int v11; // ecx@9
  int v12; // ebx@9
  char v13; // bl@4
  int v14; // eax@6
  int v15; // ebx@7
  int v16; // ebx@9
  int v17; // edx@9
  size_t v18; // ebx@9
  int v19; // ecx@11
  int v20; // [sp+14h] [bp-14h]@6
  int v21; // [sp+10h] [bp-18h]@6
  int v22; // [sp+18h] [bp-10h]@9

  v4 = a1;
  v5 = a2;
  v3 = *(_DWORD *)(a1 + 4);
  if ( v3 == *(_DWORD *)(a1 + 8) )
  {
    v14 = sub_8077F10(a1, 1, "vector::_M_insert_aux");
    v20 = 0;
    v21 = v14;
    if ( v14 )
      v20 = operator new(v21, v8);
    v15 = (int)((char *)v5 - *(_DWORD *)v4);
    memmove((void *)v20, *(const void **)v4, (size_t)((char *)v5 - *(_DWORD *)v4));
    v9 = v15 + v20;
    if ( v15 + v20 )
      *(_BYTE *)v9 = *(_BYTE *)a3;
    v16 = *(_DWORD *)(v4 + 4);
    v17 = v9 + 1;
    v22 = v17;
    v18 = v16 - (_DWORD)v5;
    memmove(v10, v5, v18);
    v12 = v22 + v18;
    if ( *(_DWORD *)v4 )
      operator delete(v11, v10);
    v19 = v20;
    *(_DWORD *)(v4 + 4) = v12;
    result = (void *)(v21 + v19);
    *(_DWORD *)v4 = v19;
    *(_DWORD *)(v4 + 8) = result;
  }
  else
  {
    v6 = 0;
    if ( v3 )
    {
      *(_BYTE *)v3 = *(_BYTE *)(v3 - 1);
      v6 = *(_DWORD *)(v4 + 4);
    }
    *(_DWORD *)(v4 + 4) = v6 + 1;
    v13 = *(_BYTE *)a3;
    result = memmove((void *)(v6 - (v6 - 1 - (_DWORD)v5)), v5, v6 - 1 - (_DWORD)v5);
    *(_BYTE *)v5 = v13;
  }
  return result;
}

//----- (08078330) --------------------------------------------------------
int __fastcall sub_8078330(int a1, int a2, int a3, unsigned int a4, unsigned int a5)
{
  int v4; // edx@1
  unsigned int v5; // edi@1
  int v6; // esi@1
  int result; // eax@4
  int v8; // ecx@4
  int v9; // ebx@4
  int v10; // esi@4
  int v11; // edx@5
  unsigned int v12; // eax@9
  int v13; // eax@10
  unsigned int v14; // edx@11
  int v15; // ecx@11
  int v16; // ebx@11
  unsigned int v17; // ebx@18
  unsigned int v18; // ecx@19
  signed int v19; // eax@9
  int v20; // eax@11
  unsigned int v21; // ebx@23
  int v22; // edx@26
  int v23; // [sp+Ch] [bp-1Ch]@9
  int v24; // [sp+0h] [bp-28h]@11
  int v25; // [sp+10h] [bp-18h]@11
  unsigned int v26; // [sp+14h] [bp-14h]@11
  int v27; // [sp+18h] [bp-10h]@18

  v6 = a3;
  v5 = a4;
  v4 = *(_DWORD *)(a3 + 4);
  if ( v4 == *(_DWORD *)(a3 + 8) )
  {
    v19 = v4 - *(_DWORD *)a3;
    v23 = 1;
    v12 = v19 >> 2;
    if ( v12 && ((v4 = 2 * v12, v23 = 2 * v12, !(v12 < 2 * v12 | v12 == 0)) || (unsigned int)v4 > 0x3FFFFFFF) )
    {
      v23 = 1073741823;
      v13 = -4;
    }
    else
    {
      v13 = 4 * v23;
    }
    v24 = v13;
    v20 = operator new(a1, v4);
    v25 = v20;
    v16 = v20;
    v26 = *(_DWORD *)v6;
    v14 = v26;
    v15 = v20;
    if ( v26 != v5 )
    {
      do
      {
        if ( v15 )
          *(_DWORD *)v15 = *(_DWORD *)v14;
        v14 += 4;
        v15 += 4;
      }
      while ( v14 != v5 );
      v15 = v25;
      v14 = v5 - (v26 + 4);
      v16 = v25 + 4 * (v14 >> 2) + 4;
    }
    if ( v16 )
    {
      v14 = a5;
      *(_DWORD *)v16 = *(_DWORD *)a5;
    }
    v27 = v16 + 4;
    v17 = *(_DWORD *)(v6 + 4);
    if ( v17 != v5 )
    {
      v14 = v27;
      v18 = v5;
      do
      {
        if ( v14 )
          *(_DWORD *)v14 = *(_DWORD *)v18;
        v18 += 4;
        v14 += 4;
      }
      while ( v17 != v18 );
      v21 = (v17 - (v5 + 4)) >> 2;
      v15 = v27 + 4 * v21 + 4;
      v27 += 4 * v21 + 4;
    }
    if ( v26 )
      operator delete(v15, v14);
    v22 = v25;
    *(_DWORD *)v6 = v25;
    *(_DWORD *)(v6 + 4) = v27;
    result = v22 + 4 * v23;
    *(_DWORD *)(v6 + 8) = v22 + 4 * v23;
  }
  else
  {
    if ( v4 )
      *(_DWORD *)v4 = *(_DWORD *)(v4 - 4);
    v9 = v4 - 4;
    *(_DWORD *)(v6 + 4) = v4 + 4;
    result = a5;
    v8 = (signed int)(v4 - 4 - v5) >> 2;
    v10 = *(_DWORD *)a5;
    if ( v8 > 0 )
    {
      v11 = v4 - 8;
      while ( 1 )
      {
        result = *(_DWORD *)v11;
        --v8;
        v11 -= 4;
        *(_DWORD *)v9 = result;
        if ( v8 <= 0 )
          break;
        v9 -= 4;
      }
    }
    *(_DWORD *)v5 = v10;
  }
  return result;
}

//----- (08078490) --------------------------------------------------------
int __cdecl sub_8078490(const void *a1, const void *a2, int a3)
{
  int v3; // ebx@1
  int v4; // eax@3
  size_t v5; // edi@3
  int v6; // esi@3
  int v8; // eax@10

  v3 = 134771820;
  if ( a1 != a2 )
  {
    if ( a1 )
    {
      v5 = a2 - a1;
      v4 = std__string___Rep___S_create(a2 - a1, 0, a3);
      v6 = v4;
      v3 = v4 + 12;
      if ( v5 == 1 )
      {
        *(_BYTE *)(v4 + 12) = *(_BYTE *)a1;
        goto LABEL_5;
      }
    }
    else
    {
      if ( a2 )
        std____throw_logic_error("basic_string::_S_construct NULL not valid");
      v5 = 0;
      v8 = std__string___Rep___S_create(0, 0, a3);
      v6 = v8;
      v3 = v8 + 12;
    }
    memcpy((void *)v3, a1, v5);
LABEL_5:
    *(_DWORD *)(v6 + 8) = 0;
    *(_DWORD *)v6 = v5;
    *(_BYTE *)(v3 + v5) = 0;
  }
  return v3;
}

//----- (08078550) --------------------------------------------------------
char __cdecl sub_8078550(int a1, int a2)
{
  char result; // al@1
  int v3; // ecx@1
  int v4; // edi@1
  int v5; // esi@1
  char v6; // zf@3

  v5 = *(_DWORD *)a1;
  v3 = *(_DWORD *)(*(_DWORD *)a1 - 12);
  v4 = *(_DWORD *)a2;
  result = 0;
  if ( v3 == *(_DWORD *)(*(_DWORD *)a2 - 12) )
  {
    v6 = 1;
    do
    {
      if ( !v3 )
        break;
      v6 = *(_BYTE *)v5++ == *(_BYTE *)v4++;
      --v3;
    }
    while ( v6 );
    result = v6;
  }
  return result;
}

//----- (080785A0) --------------------------------------------------------
char __cdecl sub_80785A0(int a1, int a2)
{
  return std__string__compare(a1, a2) != 0;
}

//----- (080785C0) --------------------------------------------------------
int __fastcall sub_80785C0(int a1, int a2, int a3, int a4, int a5, int a6, int a7)
{
  int v2; // edx@1
  int v3; // esi@1
  bool v4; // edi@2
  int v5; // eax@3
  int v6; // ebx@3
  int result; // eax@5
  int v10; // [sp+18h] [bp-10h]@1

  v2 = a5;
  v3 = a4;
  v10 = a4 + 4;
  if ( a5 || a6 == a4 + 4 )
  {
    v4 = 1;
  }
  else
  {
    v2 = a6;
    v4 = *(_WORD *)a7 < *(_WORD *)(a6 + 16);
  }
  v5 = operator new(a1, v2);
  v6 = v5;
  if ( v5 != -16 )
    *(_WORD *)(v5 + 16) = *(_WORD *)a7;
  std___Rb_tree_insert_and_rebalance(v4, v5, a6, v10);
  result = a3;
  ++*(_DWORD *)(v3 + 20);
  *(_DWORD *)result = v6;
  return result;
}

//----- (08078660) --------------------------------------------------------
#error "807883F: invalid basic block (funcsize=154)"

//----- (08078840) --------------------------------------------------------
#error "8078A1F: invalid basic block (funcsize=154)"

//----- (08078A20) --------------------------------------------------------
#error "8078BFF: invalid basic block (funcsize=154)"

//----- (08078C00) --------------------------------------------------------
int __cdecl sub_8078C00(int a1, int a2, int a3, int a4)
{
  return sub_8078A20(a1, a2, a3, a4);
}

//----- (08078C30) --------------------------------------------------------
int __cdecl sub_8078C30(int a1, int a2)
{
  int v2; // ecx@1
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  int result; // eax@3
  __int16 v7; // ax@1
  int v8; // eax@3
  int v9; // ebx@3
  size_t v10; // ebx@3
  int v11; // [sp+14h] [bp-24h]@1
  int v12; // [sp+18h] [bp-20h]@1
  int v13; // [sp+1Ch] [bp-1Ch]@3
  int v14; // [sp+20h] [bp-18h]@3
  int v15; // [sp+24h] [bp-14h]@3
  int v16; // [sp+28h] [bp-10h]@3

  v4 = a2;
  std__string__string(a1, a2);
  v11 = a1 + 4;
  std__string__string(a1 + 4, v4 + 4);
  *(_WORD *)(a1 + 8) = *(_WORD *)(v4 + 8);
  v12 = a1 + 12;
  std__string__string(a1 + 12, v4 + 12);
  v5 = 0;
  v7 = *(_WORD *)(v4 + 16);
  v3 = *(_DWORD *)(v4 + 60) - *(_DWORD *)(v4 + 56);
  *(_DWORD *)(a1 + 60) = 0;
  *(_WORD *)(a1 + 16) = v7;
  LOBYTE(v7) = *(_BYTE *)(v4 + 18);
  *(_DWORD *)(a1 + 56) = 0;
  *(_DWORD *)(a1 + 64) = 0;
  *(_BYTE *)(a1 + 18) = v7;
  *(_DWORD *)(a1 + 20) = *(_DWORD *)(v4 + 20);
  *(_DWORD *)(a1 + 24) = *(_DWORD *)(v4 + 24);
  *(_DWORD *)(a1 + 28) = *(_DWORD *)(v4 + 28);
  *(_BYTE *)(a1 + 32) = *(_BYTE *)(v4 + 32);
  *(_WORD *)(a1 + 34) = *(_WORD *)(v4 + 34);
  *(_BYTE *)(a1 + 36) = *(_BYTE *)(v4 + 36);
  *(_DWORD *)(a1 + 37) = *(_DWORD *)(v4 + 37);
  *(_DWORD *)(a1 + 41) = *(_DWORD *)(v4 + 41);
  *(_DWORD *)(a1 + 45) = *(_DWORD *)(v4 + 45);
  *(_DWORD *)(a1 + 49) = *(_DWORD *)(v4 + 49);
  if ( v3 )
    v5 = operator new(v2, a1);
  *(_DWORD *)(a1 + 56) = v5;
  *(_DWORD *)(a1 + 60) = v5;
  v8 = v5 + v3;
  v9 = *(_DWORD *)(v4 + 60);
  *(_DWORD *)(a1 + 64) = v8;
  v10 = v9 - *(_DWORD *)(v4 + 56);
  memmove((void *)v5, *(const void **)(v4 + 56), v10);
  *(_DWORD *)(a1 + 60) = v5 + v10;
  *(_DWORD *)(a1 + 68) = *(_DWORD *)(v4 + 68);
  *(_DWORD *)(a1 + 72) = *(_DWORD *)(v4 + 72);
  *(_BYTE *)(a1 + 76) = *(_BYTE *)(v4 + 76);
  *(_DWORD *)(a1 + 80) = *(_DWORD *)(v4 + 80);
  v13 = a1 + 84;
  std__string__string(a1 + 84, v4 + 84);
  v14 = a1 + 88;
  std__string__string(a1 + 88, v4 + 88);
  *(_BYTE *)(a1 + 92) = *(_BYTE *)(v4 + 92);
  *(_BYTE *)(a1 + 93) = *(_BYTE *)(v4 + 93);
  *(_BYTE *)(a1 + 94) = *(_BYTE *)(v4 + 94);
  v15 = a1 + 96;
  std__string__string(a1 + 96, v4 + 96);
  v16 = a1 + 100;
  std__string__string(a1 + 100, v4 + 100);
  std__string__string(a1 + 104, v4 + 104);
  std__string__string(a1 + 108, v4 + 108);
  std__string__string(a1 + 112, v4 + 112);
  *(_DWORD *)(a1 + 116) = *(_DWORD *)(v4 + 116);
  *(_DWORD *)(a1 + 120) = *(_DWORD *)(v4 + 120);
  result = *(_DWORD *)(v4 + 124);
  *(_DWORD *)(a1 + 124) = *(_DWORD *)(v4 + 124);
  return result;
}

//----- (08078EE0) --------------------------------------------------------
void *__cdecl sub_8078EE0(int a1, const void *a2, int a3)
{
  int v3; // edx@1
  int v4; // edi@1
  const void *v5; // esi@1
  void *result; // eax@4
  int v7; // eax@6
  int v8; // edx@6
  int v9; // edx@8
  void *v10; // edx@10
  int v11; // ecx@10
  int v12; // ebx@10
  __int16 v13; // bx@4
  int v14; // eax@8
  int v15; // ebx@8
  int v16; // ebx@10
  int v17; // edx@10
  int v18; // ebx@10
  int v19; // ecx@12
  signed int v20; // [sp+18h] [bp-10h]@7
  int v21; // [sp+10h] [bp-18h]@8
  int v22; // [sp+14h] [bp-14h]@10

  v4 = a1;
  v5 = a2;
  v3 = *(_DWORD *)(a1 + 4);
  if ( v3 == *(_DWORD *)(a1 + 8) )
  {
    v8 = 1;
    v7 = (*(_DWORD *)(a1 + 4) - *(_DWORD *)a1) >> 1;
    if ( v7
      && ((v8 = 2 * v7, (*(_DWORD *)(a1 + 4) - *(_DWORD *)a1) >> 1 > (unsigned int)(2
                                                                                  * ((*(_DWORD *)(a1 + 4) - *(_DWORD *)a1) >> 1)))
       || (unsigned int)v8 > 0x7FFFFFFF) )
    {
      v20 = -2;
    }
    else
    {
      v8 *= 2;
      v20 = v8;
    }
    v14 = operator new(v20, v8);
    v21 = v14;
    v15 = (unsigned int)((char *)v5 - *(_DWORD *)v4) & 0xFFFFFFFE;
    memmove((void *)v14, *(const void **)v4, (unsigned int)((char *)v5 - *(_DWORD *)v4) & 0xFFFFFFFE);
    v9 = v15 + v21;
    if ( v15 + v21 )
      *(_WORD *)v9 = *(_WORD *)a3;
    v16 = *(_DWORD *)(v4 + 4);
    v17 = v9 + 2;
    v22 = v17;
    v18 = (v16 - (_DWORD)v5) & 0xFFFFFFFE;
    memmove(v10, v5, v18);
    v12 = v22 + v18;
    if ( *(_DWORD *)v4 )
      operator delete(v11, v10);
    v19 = v21;
    *(_DWORD *)(v4 + 4) = v12;
    result = (void *)(v20 + v19);
    *(_DWORD *)v4 = v19;
    *(_DWORD *)(v4 + 8) = result;
  }
  else
  {
    if ( v3 )
      *(_WORD *)v3 = *(_WORD *)(v3 - 2);
    *(_DWORD *)(v4 + 4) = v3 + 2;
    v13 = *(_WORD *)a3;
    result = memmove((void *)(v3 - ((v3 - 2 - (_DWORD)v5) & 0xFFFFFFFE)), v5, (v3 - 2 - (_DWORD)v5) & 0xFFFFFFFE);
    *(_WORD *)v5 = v13;
  }
  return result;
}

//----- (08079010) --------------------------------------------------------
void __fastcall sub_8079010(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 4);
  v3 = *(_DWORD *)a3;
  if ( v5 != *(_DWORD *)a3 )
  {
    do
    {
      std__string___string(v3 + 8);
      std__string___string(v3 + 4);
      std__string___string(v3);
      v3 += 16;
    }
    while ( v5 != v3 );
    v5 = *(_DWORD *)v4;
  }
  if ( v5 )
  {
    a3 = v5;
    operator delete(a1, a2);
  }
}

//----- (080790B0) --------------------------------------------------------
int __fastcall sub_80790B0(unsigned int a1, int a2, int a3, int a4, int a5, int a6, int a7)
{
  int v3; // eax@3
  int v4; // ebx@3
  int result; // eax@5
  int v6; // eax@7
  unsigned int v7; // ebx@7
  char v8; // cf@9
  unsigned __int8 v9; // zf@9
  int v10; // edi@9
  int v11; // esi@9
  unsigned int v12; // eax@13
  int v13; // eax@3
  char v14; // zf@3
  int v15; // edx@4
  int v16; // edi@5
  unsigned __int8 v18; // [sp+30h] [bp-38h]@2
  int v19; // [sp+20h] [bp-48h]@3
  int v21; // [sp+44h] [bp-24h]@4
  int v22; // [sp+48h] [bp-20h]@4
  int v23; // [sp+4Ch] [bp-1Ch]@4
  unsigned int v26; // [sp+1Ch] [bp-4Ch]@7

  if ( a5 || a6 == a4 + 4 )
  {
    v18 = 1;
  }
  else
  {
    a2 = *(_DWORD *)a7;
    v6 = *(_DWORD *)(a6 + 16);
    v7 = *(_DWORD *)(v6 - 12);
    v26 = *(_DWORD *)(*(_DWORD *)a7 - 12);
    a1 = v7;
    if ( v7 > v26 )
      a1 = v26;
    v11 = a2;
    v10 = v6;
    v8 = a1 < a1;
    v9 = 1;
    do
    {
      if ( !a1 )
        break;
      v8 = *(_BYTE *)v11 < *(_BYTE *)v10;
      v9 = *(_BYTE *)v11++ == *(_BYTE *)v10++;
      --a1;
    }
    while ( v9 );
    LOBYTE(a2) = !(v8 | v9) - v8;
    v12 = (char)a2;
    if ( !(char)a2 )
      v12 = v26 - v7;
    v18 = v12 >> 31;
  }
  v13 = operator new(a1, a2);
  v4 = v13;
  v14 = v13 == -16;
  v3 = v13 + 16;
  v19 = v3;
  if ( !v14 )
  {
    std__string__string(v3, a7);
    v21 = v4 + 20;
    std__string__string(v4 + 20, a7 + 4);
    v22 = v4 + 24;
    std__string__string(v4 + 24, a7 + 8);
    v23 = v4 + 28;
    std__string__string(v4 + 28, a7 + 12);
    std__string__string(v4 + 32, a7 + 16);
    std__string__string(v4 + 36, a7 + 20);
    v15 = a7;
    *(_DWORD *)(v4 + 40) = *(_DWORD *)(a7 + 24);
    *(_BYTE *)(v4 + 44) = *(_BYTE *)(v15 + 28);
    *(_DWORD *)(v4 + 48) = *(_DWORD *)(v15 + 32);
    *(_WORD *)(v4 + 52) = *(_WORD *)(v15 + 36);
  }
  std___Rb_tree_insert_and_rebalance(v18, v4, a6, a4 + 4);
  v16 = a3;
  ++*(_DWORD *)(a4 + 20);
  result = v16;
  *(_DWORD *)v16 = v4;
  return result;
}

//----- (08079290) --------------------------------------------------------
int __fastcall sub_8079290(unsigned int a1, int a2, int a3, int a4, int a5)
{
  int v2; // eax@3
  char v3; // dl@3
  unsigned int v4; // ebx@5
  int v5; // edi@5
  char v6; // cf@7
  unsigned __int8 v7; // zf@7
  int v8; // esi@7
  int v9; // eax@11
  unsigned int v10; // ecx@18
  unsigned int v11; // ebx@18
  int v12; // esi@18
  char v13; // cf@19
  unsigned __int8 v14; // zf@19
  int v15; // edi@19
  int v16; // eax@23
  int result; // eax@27
  int v18; // eax@1
  unsigned int v19; // esi@2
  char v20; // dl@11
  int v21; // eax@17
  int v22; // edx@17
  unsigned int v23; // esi@17
  char v24; // dl@23
  int v25; // edi@26
  int v26; // eax@31
  int v28; // [sp+20h] [bp-28h]@1
  int v30; // [sp+2Ch] [bp-1Ch]@2
  unsigned int v31; // [sp+30h] [bp-18h]@2
  int v32; // [sp+1Ch] [bp-2Ch]@15
  int v33; // [sp+34h] [bp-14h]@15
  int v34; // [sp+38h] [bp-10h]@29

  v18 = *(_DWORD *)(a4 + 8);
  v28 = *(_DWORD *)(a4 + 8);
  if ( v18 )
  {
    v19 = *(_DWORD *)(*(_DWORD *)a5 - 12);
    v30 = *(_DWORD *)a5;
    v31 = v19;
    while ( 1 )
    {
      a1 = v31;
      v5 = *(_DWORD *)(v28 + 16);
      v4 = *(_DWORD *)(v5 - 12);
      if ( v31 > v4 )
        a1 = *(_DWORD *)(v5 - 12);
      v8 = v30;
      v6 = a1 < a1;
      v7 = 1;
      do
      {
        if ( !a1 )
          break;
        v6 = *(_BYTE *)v8 < *(_BYTE *)v5;
        v7 = *(_BYTE *)v8++ == *(_BYTE *)v5++;
        --a1;
      }
      while ( v7 );
      v20 = !(v6 | v7) - v6;
      v9 = v20;
      if ( !v20 )
        v9 = v31 - v4;
      if ( v9 < 0 )
      {
        v3 = 1;
        v2 = *(_DWORD *)(v28 + 8);
        if ( !v2 )
          goto LABEL_15;
      }
      else
      {
        v2 = *(_DWORD *)(v28 + 12);
        v3 = 0;
        if ( !v2 )
        {
LABEL_15:
          v32 = v28;
          v33 = v28;
          if ( v3 )
            goto LABEL_16;
LABEL_18:
          v10 = v31;
          v12 = *(_DWORD *)(v32 + 16);
          v11 = *(_DWORD *)(v12 - 12);
          if ( v31 > v11 )
            v10 = *(_DWORD *)(v12 - 12);
          v15 = v30;
          v13 = v10 < v10;
          v14 = 1;
          do
          {
            if ( !v10 )
              break;
            v13 = *(_BYTE *)v12 < *(_BYTE *)v15;
            v14 = *(_BYTE *)v12++ == *(_BYTE *)v15++;
            --v10;
          }
          while ( v14 );
          v24 = !(v13 | v14) - v13;
          v16 = v24;
          if ( !v24 )
            v16 = v11 - v31;
          if ( v16 >= 0 )
          {
            v25 = v32;
            *(_BYTE *)(a3 + 4) = 0;
            *(_DWORD *)a3 = v25;
            return a3;
          }
          sub_80790B0(v10, a5, (int)&v34, a4, 0, v33, a5);
          *(_DWORD *)a3 = v34;
          result = a3;
          *(_BYTE *)(a3 + 4) = 1;
          return result;
        }
      }
      v28 = v2;
    }
  }
  v33 = a4 + 4;
LABEL_16:
  if ( v33 != *(_DWORD *)(a4 + 12) )
  {
    v21 = std___Rb_tree_decrement(v33);
    v22 = *(_DWORD *)a5;
    v32 = v21;
    v23 = *(_DWORD *)(v22 - 12);
    v30 = v22;
    v31 = v23;
    goto LABEL_18;
  }
  sub_80790B0(a1, a5, (int)&v34, a4, 0, v33, a5);
  v26 = v34;
  *(_BYTE *)(a3 + 4) = 1;
  *(_DWORD *)a3 = v26;
  return a3;
}

//----- (08079430) --------------------------------------------------------
unsigned int __stdcall sub_8079430(unsigned int a1, unsigned int a2, int a3, unsigned int a4)
{
  unsigned int v1; // ecx@2
  unsigned int v2; // ebx@2
  char v3; // cf@3
  unsigned __int8 v4; // zf@3
  unsigned int v5; // ecx@3
  int v6; // edi@3
  unsigned int v7; // esi@3
  int v8; // eax@7
  char v9; // cf@10
  unsigned __int8 v10; // zf@10
  unsigned int v11; // ecx@10
  unsigned int v12; // edi@10
  int v13; // esi@10
  int v14; // eax@14
  int v16; // eax@20
  int v17; // edx@20
  int v18; // eax@21
  int v19; // edx@21
  unsigned int v20; // ecx@21
  unsigned int v21; // ebx@21
  unsigned int v22; // edi@21
  char v23; // cf@22
  unsigned __int8 v24; // zf@22
  int v25; // esi@22
  int v26; // eax@26
  int v27; // ST08_4@30
  int v28; // ST0C_4@30
  int v29; // ST10_4@30
  unsigned int v30; // ecx@33
  int v31; // ebx@37
  int v32; // edi@37
  unsigned int v33; // ecx@42
  int v34; // ST08_4@42
  int v35; // ST0C_4@42
  int v36; // ST10_4@42
  int v37; // esi@2
  char v38; // dl@7
  char v39; // dl@14
  int v40; // eax@21
  int v41; // eax@37
  unsigned int v45; // [sp+20h] [bp-38h]@2
  int v46; // [sp+24h] [bp-34h]@2
  unsigned int v47; // [sp+3Ch] [bp-1Ch]@2
  unsigned int v48; // [sp+1Ch] [bp-3Ch]@2
  int v49; // [sp+38h] [bp-20h]@21
  int v50; // [sp+40h] [bp-18h]@34

  if ( a3 == a2 + 4 )
  {
    v19 = *(_DWORD *)(a2 + 20);
    if ( v19 && std__string__compare(*(_DWORD *)(a2 + 16) + 16, a4) < 0 )
    {
      sub_80790B0(v30, v19, a1, a2, 0, *(_DWORD *)(a2 + 16), a4);
      return a1;
    }
    goto LABEL_34;
  }
  v37 = *(_DWORD *)(a3 + 16);
  v1 = *(_DWORD *)(*(_DWORD *)a4 - 12);
  v2 = *(_DWORD *)(v37 - 12);
  v45 = *(_DWORD *)a4;
  v46 = v37;
  v47 = v1;
  v48 = v2;
  if ( v2 > v1 )
    v48 = v1;
  v7 = v45;
  v5 = v48;
  v3 = v48 < v48;
  v4 = 1;
  v6 = v46;
  do
  {
    if ( !v5 )
      break;
    v3 = *(_BYTE *)v7 < *(_BYTE *)v6;
    v4 = *(_BYTE *)v7++ == *(_BYTE *)v6++;
    --v5;
  }
  while ( v4 );
  v38 = !(v3 | v4) - v3;
  v8 = v38;
  if ( !v38 )
    v8 = v47 - v2;
  if ( v8 >= 0 )
  {
    v13 = v46;
    v12 = v45;
    v9 = v48 < v48;
    v10 = 1;
    v11 = v48;
    do
    {
      if ( !v11 )
        break;
      v9 = *(_BYTE *)v13 < *(_BYTE *)v12;
      v10 = *(_BYTE *)v13++ == *(_BYTE *)v12++;
      --v11;
    }
    while ( v10 );
    v39 = !(v9 | v10) - v9;
    v14 = v39;
    if ( !v39 )
      v14 = v2 - v47;
    if ( v14 >= 0 )
    {
      *(_DWORD *)a1 = a3;
      return a1;
    }
    v16 = a2;
    v17 = a3;
    if ( *(_DWORD *)(a2 + 16) != a3 )
    {
      v32 = a3;
      v41 = std___Rb_tree_increment(a3);
      v31 = v41;
      if ( std__string__compare(a4, v41 + 16) < 0 )
      {
        if ( !*(_DWORD *)(v32 + 12) )
        {
          sub_80790B0(a2, a4, a1, a2, 0, v32, a4);
          return a1;
        }
        v28 = v31;
        v27 = v31;
        v29 = a4;
        goto LABEL_31;
      }
      goto LABEL_34;
    }
    v33 = a4;
    v35 = a3;
    v34 = 0;
    v36 = a4;
LABEL_43:
    sub_80790B0(v33, v17, a1, v16, v34, v35, v36);
    return a1;
  }
  v16 = a2;
  v17 = a3;
  if ( *(_DWORD *)(a2 + 12) == a3 )
  {
    v33 = a4;
    v35 = a3;
    v34 = a3;
    v36 = a4;
    goto LABEL_43;
  }
  v40 = std___Rb_tree_decrement(v5, a3);
  v22 = *(_DWORD *)a4;
  v49 = v40;
  v18 = *(_DWORD *)(v40 + 16);
  v21 = *(_DWORD *)(v22 - 12);
  v45 = *(_DWORD *)(v18 - 12);
  v20 = v21;
  if ( v21 > v45 )
    v20 = v45;
  v25 = v18;
  v23 = v20 < v20;
  v24 = 1;
  do
  {
    if ( !v20 )
      break;
    v23 = *(_BYTE *)v25 < *(_BYTE *)v22;
    v24 = *(_BYTE *)v25++ == *(_BYTE *)v22++;
    --v20;
  }
  while ( v24 );
  LOBYTE(v19) = !(v23 | v24) - v23;
  v26 = (char)v19;
  if ( !(char)v19 )
    v26 = v45 - v21;
  if ( v26 < 0 )
  {
    if ( !*(_DWORD *)(v49 + 12) )
    {
      sub_80790B0(a1, a2, a1, a2, 0, v49, a4);
      return a1;
    }
    v29 = a4;
    v28 = a3;
    v27 = a3;
LABEL_31:
    sub_80790B0(v20, a1, a1, a2, v27, v28, v29);
    return a1;
  }
LABEL_34:
  sub_8079290(a4, v19, (int)&v50, a2, a4);
  *(_DWORD *)a1 = v50;
  return a1;
}

//----- (08079710) --------------------------------------------------------
void __cdecl sub_8079710(int a1, int a2)
{
  int v2; // ebx@1
  int v3; // edi@1
  int v4; // esi@2
  int v5; // ecx@2
  int v6; // edx@2

  v2 = a2;
  v3 = a1;
  if ( a2 )
  {
    do
    {
      sub_8079710(v3, *(_DWORD *)(v2 + 12));
      v4 = *(_DWORD *)(v2 + 8);
      std__string___string(v2 + 36);
      std__string___string(v2 + 32);
      std__string___string(v2 + 28);
      std__string___string(v2 + 24);
      std__string___string(v2 + 20);
      std__string___string(v2 + 16);
      v2 = v4;
      operator delete(v5, v6);
    }
    while ( v4 );
  }
}

//----- (08079800) --------------------------------------------------------
void __cdecl sub_8079800(int a1)
{
  sub_8079710(a1, *(_DWORD *)(a1 + 8));
}

//----- (08079830) --------------------------------------------------------
int __cdecl sub_8079830(int a1, int a2)
{
  int v2; // eax@1
  int v3; // ecx@1
  int v4; // ebx@1
  int v5; // ebx@5
  int v6; // edi@5
  int v7; // esi@5
  int result; // eax@10
  int v9; // edx@4
  int v10; // edx@4
  int v11; // [sp+1Ch] [bp-9Ch]@1
  int v12; // [sp+20h] [bp-98h]@1
  int v13; // [sp+24h] [bp-94h]@1
  int v14; // [sp+28h] [bp-90h]@1
  int v15; // [sp+2Ch] [bp-8Ch]@1
  int v16; // [sp+30h] [bp-88h]@1
  int v17; // [sp+34h] [bp-84h]@1
  int v18; // [sp+38h] [bp-80h]@1
  int v19; // [sp+3Ch] [bp-7Ch]@1
  int v20; // [sp+40h] [bp-78h]@1
  int v21; // [sp+44h] [bp-74h]@1
  int v22; // [sp+48h] [bp-70h]@1
  int v23; // [sp+4Ch] [bp-6Ch]@1
  int v24; // [sp+50h] [bp-68h]@1
  int v25; // [sp+A4h] [bp-14h]@1
  int v26; // [sp+A8h] [bp-10h]@4
  int v27; // [sp+A0h] [bp-18h]@4
  int v28; // [sp+54h] [bp-64h]@10
  int v29; // [sp+58h] [bp-60h]@10
  int v30; // [sp+5Ch] [bp-5Ch]@10
  int v31; // [sp+60h] [bp-58h]@10
  int v32; // [sp+64h] [bp-54h]@10
  int v33; // [sp+68h] [bp-50h]@10
  int v34; // [sp+6Ch] [bp-4Ch]@10
  int v35; // [sp+70h] [bp-48h]@10
  int v36; // [sp+74h] [bp-44h]@10
  int v37; // [sp+78h] [bp-40h]@10
  int v38; // [sp+7Ch] [bp-3Ch]@10
  int v39; // [sp+80h] [bp-38h]@10
  int v40; // [sp+84h] [bp-34h]@10
  int v41; // [sp+88h] [bp-30h]@10
  int v42; // [sp+8Ch] [bp-2Ch]@10
  int v43; // [sp+90h] [bp-28h]@10
  int v44; // [sp+94h] [bp-24h]@10
  int v45; // [sp+98h] [bp-20h]@10
  int v46; // [sp+9Ch] [bp-1Ch]@10
  int v47; // [sp+18h] [bp-A0h]@11

  std__string__string(a1, a2);
  v11 = a1 + 4;
  std__string__string(a1 + 4, a2 + 4);
  v12 = a1 + 8;
  std__string__string(a1 + 8, a2 + 8);
  v13 = a1 + 12;
  std__string__string(a1 + 12, a2 + 12);
  v14 = a1 + 16;
  std__string__string(a1 + 16, a2 + 16);
  v15 = a1 + 20;
  std__string__string(a1 + 20, a2 + 20);
  v16 = a1 + 24;
  std__string__string(a1 + 24, a2 + 24);
  v17 = a1 + 28;
  std__string__string(a1 + 28, a2 + 28);
  v18 = a1 + 32;
  std__string__string(a1 + 32, a2 + 32);
  v19 = a1 + 36;
  std__string__string(a1 + 36, a2 + 36);
  v20 = a1 + 40;
  std__string__string(a1 + 40, a2 + 40);
  v21 = a1 + 44;
  std__string__string(a1 + 44, a2 + 44);
  *(_WORD *)(a1 + 48) = *(_WORD *)(a2 + 48);
  *(_BYTE *)(a1 + 50) = *(_BYTE *)(a2 + 50);
  *(_BYTE *)(a1 + 51) = *(_BYTE *)(a2 + 51);
  *(_BYTE *)(a1 + 52) = *(_BYTE *)(a2 + 52);
  *(_BYTE *)(a1 + 53) = *(_BYTE *)(a2 + 53);
  *(_BYTE *)(a1 + 54) = *(_BYTE *)(a2 + 54);
  *(_WORD *)(a1 + 56) = *(_WORD *)(a2 + 56);
  *(_BYTE *)(a1 + 58) = *(_BYTE *)(a2 + 58);
  v22 = a1 + 60;
  std__string__string(a1 + 60, a2 + 60);
  *(_WORD *)(a1 + 64) = *(_WORD *)(a2 + 64);
  *(_BYTE *)(a1 + 66) = *(_BYTE *)(a2 + 66);
  *(_BYTE *)(a1 + 67) = *(_BYTE *)(a2 + 67);
  *(_BYTE *)(a1 + 68) = *(_BYTE *)(a2 + 68);
  *(_BYTE *)(a1 + 69) = *(_BYTE *)(a2 + 69);
  *(_BYTE *)(a1 + 70) = *(_BYTE *)(a2 + 70);
  v23 = a1 + 72;
  std__string__string(a1 + 72, a2 + 72);
  v24 = a1 + 76;
  std__string__string(a1 + 76, a2 + 76);
  v4 = 0;
  *(_WORD *)(a1 + 80) = *(_WORD *)(a2 + 80);
  *(_BYTE *)(a1 + 82) = *(_BYTE *)(a2 + 82);
  *(_BYTE *)(a1 + 83) = *(_BYTE *)(a2 + 83);
  v25 = 0;
  *(_WORD *)(a1 + 84) = *(_WORD *)(a2 + 84);
  v2 = (*(_DWORD *)(a2 + 92) - *(_DWORD *)(a2 + 88)) >> 3;
  *(_DWORD *)(a1 + 88) = 0;
  *(_DWORD *)(a1 + 92) = 0;
  *(_DWORD *)(a1 + 96) = 0;
  if ( v2 )
  {
    if ( (unsigned int)v2 > 0x1FFFFFFF )
    {
      v47 = std____throw_bad_alloc();
      std__string___string(v23);
      while ( 1 )
      {
        std__string___string(v22);
        std__string___string(v21);
        std__string___string(v20);
        std__string___string(v19);
        std__string___string(v18);
        std__string___string(v17);
        std__string___string(v16);
        std__string___string(v15);
        std__string___string(v14);
        std__string___string(v13);
        std__string___string(v12);
        std__string___string(v11);
        std__string___string(a1);
        v47 = _Unwind_Resume(v47);
      }
    }
    v4 = 8 * v2;
    v25 = operator new(v3, a1);
  }
  v9 = v25;
  *(_DWORD *)(a1 + 88) = v25;
  *(_DWORD *)(a1 + 92) = v9;
  *(_DWORD *)(a1 + 96) = v4 + v9;
  v10 = *(_DWORD *)(a2 + 92);
  v26 = v25;
  v27 = v10;
  if ( v10 != *(_DWORD *)(a2 + 88) )
  {
    v5 = *(_DWORD *)(a2 + 88);
    v7 = v25;
    v6 = v25 + 8;
    do
    {
      if ( v7 )
      {
        std__string__string(v7, v5);
        *(_BYTE *)(v7 + 4) = *(_BYTE *)(v5 + 4);
      }
      v5 += 8;
      v7 = v6;
      v6 += 8;
    }
    while ( v27 != v5 );
    v26 = v7;
  }
  *(_DWORD *)(a1 + 92) = v26;
  *(_BYTE *)(a1 + 100) = *(_BYTE *)(a2 + 100);
  *(_WORD *)(a1 + 102) = *(_WORD *)(a2 + 102);
  v28 = a1 + 104;
  std__string__string(a1 + 104, a2 + 104);
  v29 = a1 + 108;
  std__string__string(a1 + 108, a2 + 108);
  v30 = a1 + 112;
  std__string__string(a1 + 112, a2 + 112);
  v31 = a1 + 116;
  std__string__string(a1 + 116, a2 + 116);
  v32 = a1 + 120;
  std__string__string(a1 + 120, a2 + 120);
  v33 = a1 + 124;
  std__string__string(a1 + 124, a2 + 124);
  v34 = a1 + 128;
  std__string__string(a1 + 128, a2 + 128);
  *(_WORD *)(a1 + 132) = *(_WORD *)(a2 + 132);
  v35 = a1 + 136;
  std__string__string(a1 + 136, a2 + 136);
  v36 = a1 + 140;
  std__string__string(a1 + 140, a2 + 140);
  v37 = a1 + 144;
  std__string__string(a1 + 144, a2 + 144);
  *(_WORD *)(a1 + 148) = *(_WORD *)(a2 + 148);
  v38 = a1 + 152;
  std__string__string(a1 + 152, a2 + 152);
  v39 = a1 + 156;
  std__string__string(a1 + 156, a2 + 156);
  *(_WORD *)(a1 + 160) = *(_WORD *)(a2 + 160);
  v40 = a1 + 164;
  std__string__string(a1 + 164, a2 + 164);
  *(_WORD *)(a1 + 168) = *(_WORD *)(a2 + 168);
  v41 = a1 + 172;
  std__string__string(a1 + 172, a2 + 172);
  *(_WORD *)(a1 + 176) = *(_WORD *)(a2 + 176);
  v42 = a1 + 180;
  std__string__string(a1 + 180, a2 + 180);
  *(_WORD *)(a1 + 184) = *(_WORD *)(a2 + 184);
  v43 = a1 + 188;
  std__string__string(a1 + 188, a2 + 188);
  *(_WORD *)(a1 + 192) = *(_WORD *)(a2 + 192);
  v44 = a1 + 196;
  std__string__string(a1 + 196, a2 + 196);
  *(_WORD *)(a1 + 200) = *(_WORD *)(a2 + 200);
  v45 = a1 + 204;
  std__string__string(a1 + 204, a2 + 204);
  *(_WORD *)(a1 + 208) = *(_WORD *)(a2 + 208);
  v46 = a1 + 212;
  std__string__string(a1 + 212, a2 + 212);
  *(_WORD *)(a1 + 216) = *(_WORD *)(a2 + 216);
  std__string__string(a1 + 220, a2 + 220);
  *(_WORD *)(a1 + 224) = *(_WORD *)(a2 + 224);
  std__string__string(a1 + 228, a2 + 228);
  *(_WORD *)(a1 + 232) = *(_WORD *)(a2 + 232);
  std__string__string(a1 + 236, a2 + 236);
  *(_WORD *)(a1 + 240) = *(_WORD *)(a2 + 240);
  *(_WORD *)(a1 + 242) = *(_WORD *)(a2 + 242);
  std__string__string(a1 + 244, a2 + 244);
  result = *(_BYTE *)(a2 + 248);
  *(_BYTE *)(a1 + 248) = *(_BYTE *)(a2 + 248);
  return result;
}

//----- (0807A360) --------------------------------------------------------
int __fastcall sub_807A360(int a1, int a2, int a3, int a4, unsigned int a5, int a6, int a7)
{
  unsigned int v2; // ecx@1
  unsigned int v3; // edi@2
  int v4; // eax@3
  int v5; // ebx@3
  int result; // eax@5
  int v7; // eax@7
  unsigned int v8; // ebx@7
  int v9; // edi@7
  unsigned int v10; // esi@7
  char v11; // cf@9
  unsigned __int8 v12; // zf@9
  int v13; // esi@9
  unsigned int v14; // eax@13
  int v19; // [sp+10h] [bp-18h]@7

  v2 = a5;
  if ( a5 || a6 == a4 + 4 )
  {
    LOBYTE(v3) = 1;
  }
  else
  {
    v7 = *(_DWORD *)a7;
    a2 = a6;
    v10 = *(_DWORD *)(*(_DWORD *)a7 - 12);
    v9 = *(_DWORD *)(a6 + 16);
    v19 = *(_DWORD *)(*(_DWORD *)a7 - 12);
    v8 = *(_DWORD *)(v9 - 12);
    v2 = *(_DWORD *)(v9 - 12);
    if ( v8 > v10 )
      v2 = v10;
    v13 = v7;
    v11 = v2 < v2;
    v12 = 1;
    do
    {
      if ( !v2 )
        break;
      v11 = *(_BYTE *)v13 < *(_BYTE *)v9;
      v12 = *(_BYTE *)v13++ == *(_BYTE *)v9++;
      --v2;
    }
    while ( v12 );
    LOBYTE(a2) = !(v11 | v12) - v11;
    v14 = (char)a2;
    if ( !(char)a2 )
      v14 = v19 - v8;
    v3 = v14 >> 31;
  }
  v4 = operator new(v2, a2);
  v5 = v4;
  if ( v4 != -16 )
  {
    std__string__string(v4 + 16, a7);
    sub_8079830(v5 + 20, a7 + 4);
  }
  std___Rb_tree_insert_and_rebalance((unsigned __int8)v3, v5, a6, a4 + 4);
  result = a3;
  ++*(_DWORD *)(a4 + 20);
  *(_DWORD *)result = v5;
  return result;
}

//----- (0807A480) --------------------------------------------------------
int __fastcall sub_807A480(int a1, int a2, int a3, int a4, int a5)
{
  int v2; // eax@3
  char v3; // dl@3
  unsigned int v4; // ebx@5
  int v5; // edi@5
  char v6; // cf@7
  unsigned __int8 v7; // zf@7
  int v8; // esi@7
  int v9; // eax@11
  int v10; // ecx@18
  unsigned int v11; // ebx@18
  int v12; // esi@18
  char v13; // cf@19
  unsigned __int8 v14; // zf@19
  int v15; // edi@19
  int v16; // eax@23
  int result; // eax@27
  int v18; // eax@1
  int v19; // esi@2
  char v20; // dl@11
  int v21; // eax@17
  int v22; // edx@17
  int v23; // esi@17
  char v24; // dl@23
  int v25; // edi@26
  int v26; // eax@31
  int v28; // [sp+20h] [bp-28h]@1
  int v30; // [sp+2Ch] [bp-1Ch]@2
  int v31; // [sp+30h] [bp-18h]@2
  int v32; // [sp+1Ch] [bp-2Ch]@15
  int v33; // [sp+34h] [bp-14h]@15
  int v34; // [sp+38h] [bp-10h]@29

  v18 = *(_DWORD *)(a4 + 8);
  v28 = *(_DWORD *)(a4 + 8);
  if ( v18 )
  {
    v19 = *(_DWORD *)(*(_DWORD *)a5 - 12);
    v30 = *(_DWORD *)a5;
    v31 = v19;
    while ( 1 )
    {
      a1 = v31;
      v5 = *(_DWORD *)(v28 + 16);
      v4 = *(_DWORD *)(v5 - 12);
      if ( v31 > v4 )
        a1 = *(_DWORD *)(v5 - 12);
      v8 = v30;
      v6 = a1 < (unsigned int)a1;
      v7 = 1;
      do
      {
        if ( !a1 )
          break;
        v6 = *(_BYTE *)v8 < *(_BYTE *)v5;
        v7 = *(_BYTE *)v8++ == *(_BYTE *)v5++;
        --a1;
      }
      while ( v7 );
      v20 = !(v6 | v7) - v6;
      v9 = v20;
      if ( !v20 )
        v9 = v31 - v4;
      if ( v9 < 0 )
      {
        v3 = 1;
        v2 = *(_DWORD *)(v28 + 8);
        if ( !v2 )
          goto LABEL_15;
      }
      else
      {
        v2 = *(_DWORD *)(v28 + 12);
        v3 = 0;
        if ( !v2 )
        {
LABEL_15:
          v32 = v28;
          v33 = v28;
          if ( v3 )
            goto LABEL_16;
LABEL_18:
          v10 = v31;
          v12 = *(_DWORD *)(v32 + 16);
          v11 = *(_DWORD *)(v12 - 12);
          if ( v31 > v11 )
            v10 = *(_DWORD *)(v12 - 12);
          v15 = v30;
          v13 = v10 < (unsigned int)v10;
          v14 = 1;
          do
          {
            if ( !v10 )
              break;
            v13 = *(_BYTE *)v12 < *(_BYTE *)v15;
            v14 = *(_BYTE *)v12++ == *(_BYTE *)v15++;
            --v10;
          }
          while ( v14 );
          v24 = !(v13 | v14) - v13;
          v16 = v24;
          if ( !v24 )
            v16 = v11 - v31;
          if ( v16 >= 0 )
          {
            v25 = v32;
            *(_BYTE *)(a3 + 4) = 0;
            *(_DWORD *)a3 = v25;
            return a3;
          }
          sub_807A360(v10, a5, (int)&v34, a4, 0, v33, a5);
          *(_DWORD *)a3 = v34;
          result = a3;
          *(_BYTE *)(a3 + 4) = 1;
          return result;
        }
      }
      v28 = v2;
    }
  }
  v33 = a4 + 4;
LABEL_16:
  if ( v33 != *(_DWORD *)(a4 + 12) )
  {
    v21 = std___Rb_tree_decrement(v33);
    v22 = *(_DWORD *)a5;
    v32 = v21;
    v23 = *(_DWORD *)(v22 - 12);
    v30 = v22;
    v31 = v23;
    goto LABEL_18;
  }
  sub_807A360(a1, a5, (int)&v34, a4, 0, v33, a5);
  v26 = v34;
  *(_BYTE *)(a3 + 4) = 1;
  *(_DWORD *)a3 = v26;
  return a3;
}

//----- (0807A620) --------------------------------------------------------
int __stdcall sub_807A620(int a1, int a2, int a3, int a4)
{
  unsigned int v1; // ecx@2
  unsigned int v2; // ebx@2
  char v3; // cf@3
  unsigned __int8 v4; // zf@3
  unsigned int v5; // ecx@3
  int v6; // edi@3
  int v7; // esi@3
  int v8; // eax@7
  char v9; // cf@10
  unsigned __int8 v10; // zf@10
  unsigned int v11; // ecx@10
  int v12; // edi@10
  int v13; // esi@10
  int v14; // eax@14
  int v16; // eax@20
  int v17; // edx@20
  int v18; // eax@21
  int v19; // edx@21
  int v20; // ecx@21
  int v21; // ebx@21
  int v22; // edi@21
  char v23; // cf@22
  unsigned __int8 v24; // zf@22
  int v25; // esi@22
  int v26; // eax@26
  unsigned int v27; // ST08_4@30
  int v28; // ST0C_4@30
  int v29; // ST10_4@30
  int v30; // ecx@33
  int v31; // ebx@37
  int v32; // edi@37
  int v33; // ecx@42
  unsigned int v34; // ST08_4@42
  int v35; // ST0C_4@42
  int v36; // ST10_4@42
  int v37; // esi@2
  char v38; // dl@7
  char v39; // dl@14
  int v40; // eax@21
  int v41; // eax@37
  int v45; // [sp+20h] [bp-38h]@2
  int v46; // [sp+24h] [bp-34h]@2
  unsigned int v47; // [sp+3Ch] [bp-1Ch]@2
  unsigned int v48; // [sp+1Ch] [bp-3Ch]@2
  int v49; // [sp+38h] [bp-20h]@21
  int v50; // [sp+40h] [bp-18h]@34

  if ( a3 == a2 + 4 )
  {
    v19 = *(_DWORD *)(a2 + 20);
    if ( v19 && std__string__compare(*(_DWORD *)(a2 + 16) + 16, a4) < 0 )
    {
      sub_807A360(v30, v19, a1, a2, 0, *(_DWORD *)(a2 + 16), a4);
      return a1;
    }
    goto LABEL_34;
  }
  v37 = *(_DWORD *)(a3 + 16);
  v1 = *(_DWORD *)(*(_DWORD *)a4 - 12);
  v2 = *(_DWORD *)(v37 - 12);
  v45 = *(_DWORD *)a4;
  v46 = v37;
  v47 = v1;
  v48 = v2;
  if ( v2 > v1 )
    v48 = v1;
  v7 = v45;
  v5 = v48;
  v3 = v48 < v48;
  v4 = 1;
  v6 = v46;
  do
  {
    if ( !v5 )
      break;
    v3 = *(_BYTE *)v7 < *(_BYTE *)v6;
    v4 = *(_BYTE *)v7++ == *(_BYTE *)v6++;
    --v5;
  }
  while ( v4 );
  v38 = !(v3 | v4) - v3;
  v8 = v38;
  if ( !v38 )
    v8 = v47 - v2;
  if ( v8 >= 0 )
  {
    v13 = v46;
    v12 = v45;
    v9 = v48 < v48;
    v10 = 1;
    v11 = v48;
    do
    {
      if ( !v11 )
        break;
      v9 = *(_BYTE *)v13 < *(_BYTE *)v12;
      v10 = *(_BYTE *)v13++ == *(_BYTE *)v12++;
      --v11;
    }
    while ( v10 );
    v39 = !(v9 | v10) - v9;
    v14 = v39;
    if ( !v39 )
      v14 = v2 - v47;
    if ( v14 >= 0 )
    {
      *(_DWORD *)a1 = a3;
      return a1;
    }
    v16 = a2;
    v17 = a3;
    if ( *(_DWORD *)(a2 + 16) != a3 )
    {
      v32 = a3;
      v41 = std___Rb_tree_increment(a3);
      v31 = v41;
      if ( std__string__compare(a4, v41 + 16) < 0 )
      {
        if ( !*(_DWORD *)(v32 + 12) )
        {
          sub_807A360(a2, a4, a1, a2, 0, v32, a4);
          return a1;
        }
        v28 = v31;
        v27 = v31;
        v29 = a4;
        goto LABEL_31;
      }
      goto LABEL_34;
    }
    v33 = a4;
    v35 = a3;
    v34 = 0;
    v36 = a4;
LABEL_43:
    sub_807A360(v33, v17, a1, v16, v34, v35, v36);
    return a1;
  }
  v16 = a2;
  v17 = a3;
  if ( *(_DWORD *)(a2 + 12) == a3 )
  {
    v33 = a4;
    v35 = a3;
    v34 = a3;
    v36 = a4;
    goto LABEL_43;
  }
  v40 = std___Rb_tree_decrement(v5, a3);
  v22 = *(_DWORD *)a4;
  v49 = v40;
  v18 = *(_DWORD *)(v40 + 16);
  v21 = *(_DWORD *)(v22 - 12);
  v45 = *(_DWORD *)(v18 - 12);
  v20 = v21;
  if ( v21 > (unsigned int)v45 )
    v20 = v45;
  v25 = v18;
  v23 = v20 < (unsigned int)v20;
  v24 = 1;
  do
  {
    if ( !v20 )
      break;
    v23 = *(_BYTE *)v25 < *(_BYTE *)v22;
    v24 = *(_BYTE *)v25++ == *(_BYTE *)v22++;
    --v20;
  }
  while ( v24 );
  LOBYTE(v19) = !(v23 | v24) - v23;
  v26 = (char)v19;
  if ( !(char)v19 )
    v26 = v45 - v21;
  if ( v26 < 0 )
  {
    if ( !*(_DWORD *)(v49 + 12) )
    {
      sub_807A360(a1, a2, a1, a2, 0, v49, a4);
      return a1;
    }
    v29 = a4;
    v28 = a3;
    v27 = a3;
LABEL_31:
    sub_807A360(v20, a1, a1, a2, v27, v28, v29);
    return a1;
  }
LABEL_34:
  sub_807A480(a4, v19, (int)&v50, a2, a4);
  *(_DWORD *)a1 = v50;
  return a1;
}

//----- (0807A900) --------------------------------------------------------
int __fastcall sub_807A900(int a1, int _EDX, int a3)
{
  int v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  int result; // eax@2
  char v12; // [sp+1Bh] [bp-Dh]@11

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 4);
  v3 = *(_DWORD *)a3;
  if ( v5 != *(_DWORD *)a3 )
  {
    do
    {
      result = *(_DWORD *)(v3 + 4);
      _EDX = result - 12;
      if ( result - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
      {
        if ( pthread_cancel )
        {
          _EAX = -1;
          __asm { lock xadd [edx+8], eax }
          a1 = result;
        }
        else
        {
          a1 = *(_DWORD *)(_EDX + 8);
          result = a1 - 1;
          *(_DWORD *)(_EDX + 8) = a1 - 1;
        }
        if ( a1 <= 0 )
          result = std__string___Rep___M_destroy(_EDX, &v12);
      }
      v3 += 8;
    }
    while ( v5 != v3 );
    v5 = *(_DWORD *)v4;
  }
  if ( v5 )
    result = operator delete(a1, _EDX);
  return result;
}

//----- (0807A980) --------------------------------------------------------
int __fastcall sub_807A980(int a1, int _EDX, int a3)
{
  int *v3; // ebx@1
  int v4; // edi@1
  int v5; // esi@1
  int result; // eax@2
  char v12; // [sp+1Bh] [bp-Dh]@11

  v4 = a3;
  v5 = *(_DWORD *)(a3 + 4);
  v3 = *(int **)a3;
  if ( v5 != *(_DWORD *)a3 )
  {
    do
    {
      result = *v3;
      _EDX = *v3 - 12;
      if ( _EDX != (_DWORD)std__string___Rep___S_empty_rep_storage )
      {
        if ( pthread_cancel )
        {
          _EAX = -1;
          __asm { lock xadd [edx+8], eax }
          a1 = result;
        }
        else
        {
          a1 = *(_DWORD *)(_EDX + 8);
          result = a1 - 1;
          *(_DWORD *)(_EDX + 8) = a1 - 1;
        }
        if ( a1 <= 0 )
          result = std__string___Rep___M_destroy(_EDX, &v12);
      }
      ++v3;
    }
    while ( v5 != (_DWORD)v3 );
    v5 = *(_DWORD *)v4;
  }
  if ( v5 )
    result = operator delete(a1, _EDX);
  return result;
}

//----- (0807AA00) --------------------------------------------------------
int __cdecl sub_807AA00(int a1, int a2)
{
  char *v2; // esi@1
  int v3; // edx@2
  int v4; // edi@2
  int v5; // eax@3
  int v6; // ebx@5
  int v7; // esi@5
  int (*i)(pthread_t); // ebx@9
  int v11; // ebx@15
  int v12; // ebx@18
  int v13; // edi@19
  int v14; // esi@19
  int v15; // eax@25
  int v17; // ebx@26
  int v18; // edi@26
  int v19; // esi@26
  int v20; // ecx@30
  int v21; // ebx@30
  int v22; // esi@30
  int v23; // ecx@39
  int v24; // eax@2
  int v25; // eax@2
  int v26; // eax@3
  char v27; // al@6
  int v28; // edx@16
  int v29; // eax@18
  int v30; // eax@36
  int v43; // eax@46
  int v44; // [sp+38h] [bp-20h]@2
  int v45; // [sp+2Ch] [bp-2Ch]@2
  unsigned int v46; // [sp+20h] [bp-38h]@2
  int v47; // [sp+28h] [bp-30h]@2
  int v48; // [sp+1Ch] [bp-3Ch]@3
  char v49; // [sp+4Ah] [bp-Eh]@9
  int v50; // [sp+34h] [bp-24h]@12
  int v51; // [sp+30h] [bp-28h]@18
  int v52; // [sp+24h] [bp-34h]@25
  char v53; // [sp+4Bh] [bp-Dh]@45

  v2 = (char *)a2;
  if ( a2 != a1 )
  {
    v24 = *(_DWORD *)(a2 + 4);
    v44 = *(_DWORD *)(a2 + 4);
    v25 = (v24 - *(_DWORD *)a2) >> 3;
    v45 = *(_DWORD *)a2;
    v46 = v25;
    v47 = v25;
    v4 = *(_DWORD *)a1;
    v3 = *(_DWORD *)a1;
    if ( v25 > (unsigned int)((*(_DWORD *)(a1 + 8) - *(_DWORD *)a1) >> 3) )
    {
      if ( v46 > 0x1FFFFFFF )
      {
        v43 = std____throw_bad_alloc();
        __cxa_begin_catch(v43);
        for ( i = (int (*)(pthread_t))v52; v4 != (_DWORD)i; i = (int (*)(pthread_t))((char *)i + 8) )
          std__string___string(i);
        __cxa_rethrow();
        goto LABEL_49;
      }
      v50 = 8 * v46;
      v15 = operator new(a1, v3);
      _EDX = v45;
      v52 = v15;
      if ( v44 != v45 )
      {
        v18 = v15;
        v19 = v15 + 8;
        v17 = v45;
        do
        {
          if ( v18 )
          {
            std__string__string(v18, v17);
            *(_BYTE *)(v18 + 4) = *(_BYTE *)(v17 + 4);
          }
          v17 += 8;
          v18 = v19;
          v19 += 8;
        }
        while ( v44 != v17 );
      }
      v20 = a1;
      v22 = *(_DWORD *)(a1 + 4);
      v21 = *(_DWORD *)a1;
      if ( v22 != *(_DWORD *)a1 )
      {
        do
        {
          _EDX = *(_DWORD *)v21 - 12;
          if ( _EDX != (_DWORD)std__string___Rep___S_empty_rep_storage )
          {
            if ( pthread_cancel )
            {
              _EAX = -1;
              __asm { lock xadd [edx+8], eax }
              v20 = _EAX;
            }
            else
            {
              v20 = *(_DWORD *)(_EDX + 8);
              *(_DWORD *)(_EDX + 8) = v20 - 1;
            }
            if ( v20 <= 0 )
              std__string___Rep___M_destroy(_EDX, &v53);
          }
          v21 += 8;
        }
        while ( v22 != v21 );
        v21 = *(_DWORD *)a1;
      }
      if ( v21 )
        operator delete(v20, _EDX);
      v30 = v52;
      *(_DWORD *)a1 = v52;
      *(_DWORD *)(a1 + 8) = v50 + v30;
      goto LABEL_13;
    }
    v26 = *(_DWORD *)(a1 + 4);
    v48 = *(_DWORD *)(a1 + 4);
    v5 = (v26 - v4) >> 3;
    if ( v46 > v5 )
    {
      v11 = 8 * v5 >> 3;
      if ( v11 > 0 )
      {
        do
        {
          --v11;
          std__string__assign(v4, v45);
          v28 = v45 + 8;
          *(_BYTE *)(v4 + 4) = *(_BYTE *)(v45 + 4);
          v4 += 8;
          v45 = v28;
        }
        while ( v11 > 0 );
        v44 = *((_DWORD *)v2 + 1);
        v45 = *(_DWORD *)v2;
        v3 = *(_DWORD *)a1;
        v48 = *(_DWORD *)(a1 + 4);
      }
      v51 = v48;
      v29 = (v48 - v3) & 0xFFFFFFF8;
      v12 = v29 + v45;
      if ( v44 != v29 + v45 )
      {
        v13 = v48;
        v14 = v48 + 8;
        do
        {
          if ( v13 )
          {
            std__string__string(v13, v12);
            *(_BYTE *)(v13 + 4) = *(_BYTE *)(v12 + 4);
          }
          v12 += 8;
          v13 = v14;
          v14 += 8;
        }
        while ( v44 != v12 );
LABEL_12:
        v50 = 8 * v46;
LABEL_13:
        v50 += *(_DWORD *)a1;
        *(_DWORD *)(a1 + 4) = v50;
        return a1;
      }
    }
    else
    {
      if ( (signed int)v46 > 0 )
      {
        v7 = v45;
        v6 = v4;
        do
        {
          std__string__assign(v6, v7);
          v27 = *(_BYTE *)(v7 + 4);
          v7 += 8;
          *(_BYTE *)(v6 + 4) = v27;
          v6 += 8;
          --v47;
        }
        while ( v47 > 0 );
        v4 += 8 * v46;
      }
      if ( v4 != v48 )
      {
        i = pthread_cancel;
        v2 = &v49;
        do
        {
          _EDX = *(_DWORD *)v4 - 12;
          if ( _EDX != (_DWORD)std__string___Rep___S_empty_rep_storage )
          {
            if ( i )
            {
              _EAX = -1;
              __asm { lock xadd [edx+8], eax }
              v23 = _EAX;
            }
            else
            {
LABEL_49:
              v23 = *(_DWORD *)(_EDX + 8);
              *(_DWORD *)(_EDX + 8) = v23 - 1;
            }
            if ( v23 <= 0 )
              std__string___Rep___M_destroy(_EDX, v2);
          }
          v4 += 8;
        }
        while ( v48 != v4 );
        goto LABEL_12;
      }
    }
    v50 = 8 * v46;
    goto LABEL_13;
  }
  return a1;
}

//----- (0807AD50) --------------------------------------------------------
int __cdecl sub_807AD50(int a1, int a2)
{
  int v3; // ebx@1
  int v4; // esi@1

  v3 = a1;
  v4 = a2;
  std__string__assign(a1, a2);
  std__string__assign(v3 + 4, v4 + 4);
  std__string__assign(v3 + 8, v4 + 8);
  std__string__assign(v3 + 12, v4 + 12);
  std__string__assign(v3 + 16, v4 + 16);
  std__string__assign(v3 + 20, v4 + 20);
  std__string__assign(v3 + 24, v4 + 24);
  std__string__assign(v3 + 28, v4 + 28);
  std__string__assign(v3 + 32, v4 + 32);
  std__string__assign(v3 + 36, v4 + 36);
  std__string__assign(v3 + 40, v4 + 40);
  std__string__assign(v3 + 44, v4 + 44);
  *(_WORD *)(v3 + 48) = *(_WORD *)(v4 + 48);
  *(_BYTE *)(v3 + 50) = *(_BYTE *)(v4 + 50);
  *(_BYTE *)(v3 + 51) = *(_BYTE *)(v4 + 51);
  *(_BYTE *)(v3 + 52) = *(_BYTE *)(v4 + 52);
  *(_BYTE *)(v3 + 53) = *(_BYTE *)(v4 + 53);
  *(_BYTE *)(v3 + 54) = *(_BYTE *)(v4 + 54);
  *(_WORD *)(v3 + 56) = *(_WORD *)(v4 + 56);
  *(_BYTE *)(v3 + 58) = *(_BYTE *)(v4 + 58);
  std__string__assign(v3 + 60, v4 + 60);
  *(_WORD *)(v3 + 64) = *(_WORD *)(v4 + 64);
  *(_BYTE *)(v3 + 66) = *(_BYTE *)(v4 + 66);
  *(_BYTE *)(v3 + 67) = *(_BYTE *)(v4 + 67);
  *(_BYTE *)(v3 + 68) = *(_BYTE *)(v4 + 68);
  *(_BYTE *)(v3 + 69) = *(_BYTE *)(v4 + 69);
  *(_BYTE *)(v3 + 70) = *(_BYTE *)(v4 + 70);
  std__string__assign(v3 + 72, v4 + 72);
  std__string__assign(v3 + 76, v4 + 76);
  *(_WORD *)(v3 + 80) = *(_WORD *)(v4 + 80);
  *(_BYTE *)(v3 + 82) = *(_BYTE *)(v4 + 82);
  *(_BYTE *)(v3 + 83) = *(_BYTE *)(v4 + 83);
  *(_WORD *)(v3 + 84) = *(_WORD *)(v4 + 84);
  sub_807AA00(v3 + 88, v4 + 88);
  *(_BYTE *)(v3 + 100) = *(_BYTE *)(v4 + 100);
  *(_WORD *)(v3 + 102) = *(_WORD *)(v4 + 102);
  std__string__assign(v3 + 104, v4 + 104);
  std__string__assign(v3 + 108, v4 + 108);
  std__string__assign(v3 + 112, v4 + 112);
  std__string__assign(v3 + 116, v4 + 116);
  std__string__assign(v3 + 120, v4 + 120);
  std__string__assign(v3 + 124, v4 + 124);
  std__string__assign(v3 + 128, v4 + 128);
  *(_WORD *)(v3 + 132) = *(_WORD *)(v4 + 132);
  std__string__assign(v3 + 136, v4 + 136);
  std__string__assign(v3 + 140, v4 + 140);
  std__string__assign(v3 + 144, v4 + 144);
  *(_WORD *)(v3 + 148) = *(_WORD *)(v4 + 148);
  std__string__assign(v3 + 152, v4 + 152);
  std__string__assign(v3 + 156, v4 + 156);
  *(_WORD *)(v3 + 160) = *(_WORD *)(v4 + 160);
  std__string__assign(v3 + 164, v4 + 164);
  *(_WORD *)(v3 + 168) = *(_WORD *)(v4 + 168);
  std__string__assign(v3 + 172, v4 + 172);
  *(_WORD *)(v3 + 176) = *(_WORD *)(v4 + 176);
  std__string__assign(v3 + 180, v4 + 180);
  *(_WORD *)(v3 + 184) = *(_WORD *)(v4 + 184);
  std__string__assign(v3 + 188, v4 + 188);
  *(_WORD *)(v3 + 192) = *(_WORD *)(v4 + 192);
  std__string__assign(v3 + 196, v4 + 196);
  *(_WORD *)(v3 + 200) = *(_WORD *)(v4 + 200);
  std__string__assign(v3 + 204, v4 + 204);
  *(_WORD *)(v3 + 208) = *(_WORD *)(v4 + 208);
  std__string__assign(v3 + 212, v4 + 212);
  *(_WORD *)(v3 + 216) = *(_WORD *)(v4 + 216);
  std__string__assign(v3 + 220, v4 + 220);
  *(_WORD *)(v3 + 224) = *(_WORD *)(v4 + 224);
  std__string__assign(v3 + 228, v4 + 228);
  *(_WORD *)(v3 + 232) = *(_WORD *)(v4 + 232);
  std__string__assign(v3 + 236, v4 + 236);
  *(_WORD *)(v3 + 240) = *(_WORD *)(v4 + 240);
  *(_WORD *)(v3 + 242) = *(_WORD *)(v4 + 242);
  std__string__assign(v3 + 244, v4 + 244);
  *(_BYTE *)(v3 + 248) = *(_BYTE *)(v4 + 248);
  return v3;
}

//----- (0807B1F0) --------------------------------------------------------
int __cdecl sub_807B1F0(int a1, int a2, unsigned int a3, int a4)
{
  int result; // eax@1
  int v5; // edx@2
  int v6; // edx@3
  int v7; // ecx@3
  int v8; // eax@5
  int v9; // edi@9
  unsigned int v10; // ebx@10
  int v11; // esi@10
  int v12; // edx@14
  int v13; // esi@14
  int v14; // ebx@15
  int v15; // ebx@20
  int v17; // ebx@30
  int v18; // edi@30
  int i; // ebx@31
  int v20; // esi@31
  int v21; // esi@33
  int v22; // ebx@34
  int v23; // ebx@39
  int v24; // esi@39
  int v25; // ebx@45
  int v26; // ecx@49
  int v27; // edx@26
  int v28; // esi@44
  int v29; // eax@44
  int v36; // [sp+14h] [bp-34h]@5
  int v37; // [sp+20h] [bp-28h]@8
  int v38; // [sp+28h] [bp-20h]@9
  int v39; // [sp+18h] [bp-30h]@10
  int v40; // [sp+24h] [bp-24h]@10
  int v41; // [sp+1Ch] [bp-2Ch]@14
  char v42; // [sp+34h] [bp-14h]@30
  int v43; // [sp+10h] [bp-38h]@31
  int v44; // [sp+Ch] [bp-3Ch]@31
  char v45; // [sp+3Bh] [bp-Dh]@51

  result = a3;
  if ( a3 )
  {
    v5 = *(_DWORD *)(a1 + 4);
    if ( a3 > (*(_DWORD *)(a1 + 8) - v5) >> 2 )
    {
      v7 = a1;
      v6 = (v5 - *(_DWORD *)a1) >> 2;
      if ( a3 > 1073741823 - v6 )
      {
        std____throw_length_error(a1);
        goto LABEL_8;
      }
      if ( v6 < a3 )
      {
        v8 = v6 + a3;
        v36 = v6 + a3;
        if ( !__MKCADD__(v6, a3) )
        {
LABEL_6:
          if ( (unsigned int)v8 <= 0x3FFFFFFF )
          {
            v37 = 0;
            if ( !v8 )
              goto LABEL_38;
            goto LABEL_8;
          }
          goto LABEL_7;
        }
      }
      else
      {
        v8 = 2 * v6;
        v36 = 2 * v6;
        if ( !__MKCADD__(v6, v6) )
          goto LABEL_6;
      }
LABEL_7:
      v36 = 1073741823;
LABEL_8:
      v37 = operator new(v7, v6);
LABEL_38:
      v39 = v37;
      v9 = *(_DWORD *)a1;
      if ( *(_DWORD *)a1 == a2 )
      {
        v9 = a2;
        v38 = v37;
      }
      else
      {
        v24 = v37;
        v23 = v37 + 4;
        do
        {
          if ( v24 )
            std__string__string(v24, v9);
          v9 += 4;
          v24 = v23;
          v38 = v23;
          v23 += 4;
        }
        while ( a2 != v9 );
      }
      v10 = a3;
      v39 = v38;
      v11 = v38 + 4;
      v40 = v38;
      do
      {
        if ( v40 )
          std__string__string(v40, a4);
        v40 = v11;
        v11 += 4;
        --v10;
      }
      while ( v10 );
      v39 = v38 + 4 * a3;
      v13 = v38 + 4 * a3;
      v12 = *(_DWORD *)(a1 + 4);
      v41 = *(_DWORD *)(a1 + 4);
      if ( v12 != v9 )
      {
        v14 = v9;
        do
        {
          if ( v13 )
            std__string__string(v13, v14);
          v13 += 4;
          v14 += 4;
        }
        while ( v41 != v14 );
        v41 = *(_DWORD *)(a1 + 4);
      }
      v15 = *(_DWORD *)a1;
      if ( *(_DWORD *)a1 != v41 )
      {
        do
        {
          _EDX = *(_DWORD *)v15 - 12;
          if ( std__string___Rep___S_empty_rep_storage != (char *)_EDX )
          {
            if ( pthread_cancel )
            {
              _EAX = -1;
              __asm { lock xadd [edx+8], eax }
              v26 = _EAX;
            }
            else
            {
              v26 = *(_DWORD *)(_EDX + 8);
              *(_DWORD *)(_EDX + 8) = v26 - 1;
            }
            if ( v26 <= 0 )
              std__string___Rep___M_destroy(_EDX, &v45);
          }
          v15 += 4;
        }
        while ( v15 != v41 );
        v12 = *(_DWORD *)a1;
        v41 = *(_DWORD *)a1;
      }
      if ( v41 )
        operator delete(v41, v12);
      v27 = v37;
      *(_DWORD *)a1 = v37;
      *(_DWORD *)(a1 + 4) = v13;
      result = v27 + 4 * v36;
      *(_DWORD *)(a1 + 8) = result;
      return result;
    }
    std__string__string(&v42, a4);
    v18 = *(_DWORD *)(a1 + 4);
    v17 = (*(_DWORD *)(a1 + 4) - a2) >> 2;
    if ( a3 >= v17 )
    {
      v28 = a3 - v17;
      v44 = a1;
      sub_8077E10(v18, a3 - v17, (int)&v42);
      v29 = *(_DWORD *)(a1 + 4) + 4 * v28;
      *(_DWORD *)(a1 + 4) += 4 * v28;
      v44 = a1;
      sub_8077E90(a2, v18, v29);
      *(_DWORD *)(a1 + 4) += 4 * v17;
      if ( v18 != a2 )
      {
        v25 = a2;
        do
        {
          std__string__assign(v25, &v42);
          v25 += 4;
        }
        while ( v18 != v25 );
      }
    }
    else
    {
      v43 = 4 * a3;
      v20 = v18 - 4 * a3;
      v44 = a1;
      sub_8077E90(v18 - 4 * a3, v18, v18);
      *(_DWORD *)(a1 + 4) += v43;
      for ( i = (v20 - a2) >> 2; i > 0; --i )
      {
        v20 -= 4;
        v18 -= 4;
        std__string__assign(v18, v20);
      }
      v21 = v43 + a2;
      if ( v43 )
      {
        v22 = a2;
        do
        {
          std__string__assign(v22, &v42);
          v22 += 4;
        }
        while ( v21 != v22 );
      }
    }
    result = std__string___string(&v42);
  }
  return result;
}

//----- (0807B640) --------------------------------------------------------
int __fastcall sub_807B640(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int result; // eax@12
  int v14; // ecx@19
  int v15; // ecx@23
  int v16; // ecx@39
  int v17; // eax@1
  int v18; // eax@2
  int v19; // eax@3
  int v20; // eax@4
  int v21; // eax@5
  int v22; // eax@6
  int v23; // eax@7
  int v24; // eax@10
  int v25; // eax@11
  char v85; // [sp+1Fh] [bp-9h]@17
  char v86; // [sp+16h] [bp-12h]@21
  char v87; // [sp+17h] [bp-11h]@25
  char v88; // [sp+1Bh] [bp-Dh]@29
  char v89; // [sp+19h] [bp-Fh]@33
  char v90; // [sp+1Dh] [bp-Bh]@37
  char v91; // [sp+18h] [bp-10h]@41
  char v92; // [sp+1Ch] [bp-Ch]@45
  char v93; // [sp+1Ah] [bp-Eh]@49
  char v94; // [sp+1Eh] [bp-Ah]@53

  v3 = a3;
  v17 = *(_DWORD *)(a3 + 112);
  _EDX = v17 - 12;
  if ( v17 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v85);
  }
  v18 = *(_DWORD *)(v3 + 108);
  _EDX = v18 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v18 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v94);
  }
  v19 = *(_DWORD *)(v3 + 104);
  _EDX = v19 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v19 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v90);
  }
  v20 = *(_DWORD *)(v3 + 100);
  _EDX = v20 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v20 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v92);
  }
  v21 = *(_DWORD *)(v3 + 96);
  _EDX = v21 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v21 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v88);
  }
  v22 = *(_DWORD *)(v3 + 88);
  _EDX = v22 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v22 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v93);
  }
  v23 = *(_DWORD *)(v3 + 84);
  _EDX = v23 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v23 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      a1 = _EAX;
    }
    else
    {
      a1 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = a1 - 1;
    }
    if ( a1 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v89);
  }
  if ( *(_DWORD *)(v3 + 56) )
    operator delete(a1, _EDX);
  v24 = *(_DWORD *)(v3 + 12);
  _EDX = v24 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v24 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v16 = _EAX;
    }
    else
    {
      v16 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v16 - 1;
    }
    if ( v16 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v91);
  }
  v25 = *(_DWORD *)(v3 + 4);
  _EDX = v25 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v25 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v15 = _EAX;
    }
    else
    {
      v15 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v15 - 1;
    }
    if ( v15 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v87);
  }
  result = *(_DWORD *)v3;
  _EDX = *(_DWORD *)v3 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)_EDX )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v14 = result;
    }
    else
    {
      v14 = *(_DWORD *)(_EDX + 8);
      result = v14 - 1;
      *(_DWORD *)(_EDX + 8) = v14 - 1;
    }
    if ( v14 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v86);
  }
  return result;
}

//----- (0807B980) --------------------------------------------------------
int __fastcall sub_807B980(int a1, int a2, int a3)
{
  int v3; // edi@1
  int v4; // esi@1
  int v5; // ebx@2
  int result; // eax@4
  int v7; // ST00_4@3

  v3 = *(_DWORD *)a3;
  v4 = *(_DWORD *)(a3 + 4);
  if ( *(_DWORD *)a3 != v4 )
  {
    v5 = *(_DWORD *)a3;
    do
    {
      v7 = v5;
      v5 += 128;
      sub_807B640(a1, a2, v7);
    }
    while ( v4 != v5 );
  }
  result = a3;
  *(_DWORD *)(a3 + 4) = v3;
  return result;
}

//----- (0807B9C0) --------------------------------------------------------
void __fastcall sub_807B9C0(int a1, int a2, int a3)
{
  int v3; // ebx@1
  int *v4; // edi@1
  int v5; // esi@1
  int v6; // ST00_4@2

  v4 = (int *)a3;
  v5 = *(_DWORD *)(a3 + 4);
  v3 = *(_DWORD *)a3;
  if ( v5 != *(_DWORD *)a3 )
  {
    do
    {
      v6 = v3;
      v3 += 128;
      sub_807B640(a1, a2, v6);
    }
    while ( v5 != v3 );
    v5 = *v4;
  }
  if ( v5 )
  {
    a3 = v5;
    operator delete(a1, a2);
  }
}

//----- (0807BA10) --------------------------------------------------------
int __fastcall sub_807BA10(int a1, int a2, int a3, int a4, int a5)
{
  int v2; // eax@1
  int v3; // edi@2
  int v4; // esi@3
  int result; // eax@6
  int v6; // edx@4
  int v7; // eax@6

  v2 = *(_DWORD *)(a4 + 4);
  if ( v2 != a5 + 128 )
  {
    v3 = (v2 - (a5 + 128)) >> 7;
    if ( v3 > 0 )
    {
      v4 = a5;
      do
      {
        --v3;
        std__string__assign(v4, v4 + 128);
        std__string__assign(v4 + 4, v4 + 132);
        *(_WORD *)(v4 + 8) = *(_WORD *)(v4 + 136);
        std__string__assign(v4 + 12, v4 + 140);
        *(_WORD *)(v4 + 16) = *(_WORD *)(v4 + 144);
        *(_BYTE *)(v4 + 18) = *(_BYTE *)(v4 + 146);
        *(_DWORD *)(v4 + 20) = *(_DWORD *)(v4 + 148);
        *(_DWORD *)(v4 + 24) = *(_DWORD *)(v4 + 152);
        *(_DWORD *)(v4 + 28) = *(_DWORD *)(v4 + 156);
        *(_BYTE *)(v4 + 32) = *(_BYTE *)(v4 + 160);
        *(_WORD *)(v4 + 34) = *(_WORD *)(v4 + 162);
        *(_BYTE *)(v4 + 36) = *(_BYTE *)(v4 + 164);
        *(_DWORD *)(v4 + 37) = *(_DWORD *)(v4 + 165);
        *(_DWORD *)(v4 + 41) = *(_DWORD *)(v4 + 169);
        *(_DWORD *)(v4 + 45) = *(_DWORD *)(v4 + 173);
        *(_DWORD *)(v4 + 49) = *(_DWORD *)(v4 + 177);
        sub_804B500(a1, v6, v4 + 56, v4 + 184);
        *(_DWORD *)(v4 + 68) = *(_DWORD *)(v4 + 196);
        *(_DWORD *)(v4 + 72) = *(_DWORD *)(v4 + 200);
        *(_BYTE *)(v4 + 76) = *(_BYTE *)(v4 + 204);
        *(_DWORD *)(v4 + 80) = *(_DWORD *)(v4 + 208);
        std__string__assign(v4 + 84, v4 + 212);
        std__string__assign(v4 + 88, v4 + 216);
        *(_BYTE *)(v4 + 92) = *(_BYTE *)(v4 + 220);
        *(_BYTE *)(v4 + 93) = *(_BYTE *)(v4 + 221);
        *(_BYTE *)(v4 + 94) = *(_BYTE *)(v4 + 222);
        std__string__assign(v4 + 96, v4 + 224);
        std__string__assign(v4 + 100, v4 + 228);
        std__string__assign(v4 + 104, v4 + 232);
        std__string__assign(v4 + 108, v4 + 236);
        std__string__assign(v4 + 112, v4 + 240);
        *(_DWORD *)(v4 + 116) = *(_DWORD *)(v4 + 244);
        *(_DWORD *)(v4 + 120) = *(_DWORD *)(v4 + 248);
        *(_DWORD *)(v4 + 124) = *(_DWORD *)(v4 + 252);
        v4 += 128;
      }
      while ( v3 > 0 );
      v2 = *(_DWORD *)(a4 + 4);
    }
  }
  v7 = v2 - 128;
  *(_DWORD *)(a4 + 4) = v7;
  sub_807B640(a1, a4, v7);
  result = a3;
  *(_DWORD *)a3 = a5;
  return result;
}

//----- (0807BC40) --------------------------------------------------------
int __cdecl sub_807BC40(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // eax@4
  int v5; // edi@4
  int v6; // ebx@5
  int result; // eax@8
  int v8; // eax@10
  int v9; // edx@10
  int v10; // ecx@10
  int v11; // edx@12
  int v12; // esi@17
  int v13; // ebx@18
  int v14; // edi@18
  int v15; // edx@24
  int v16; // ecx@24
  int v17; // esi@24
  int v18; // ebx@25
  int v19; // edi@25
  int v20; // eax@30
  int v21; // ebx@30
  int v22; // esi@6
  int v23; // ecx@6
  int v24; // edx@6
  int v25; // edx@7
  unsigned __int8 v26; // cf@12
  char v27; // zf@17
  int v28; // eax@24
  int v29; // ST00_4@31
  int v30; // eax@36
  int v31; // ebx@36
  int v32; // [sp+C8h] [bp-10h]@1
  int v33; // [sp+20h] [bp-B8h]@1
  int v34; // [sp+1Ch] [bp-BCh]@1
  int v35; // [sp+2Ch] [bp-ACh]@1
  char v36; // [sp+48h] [bp-90h]@4
  char v37; // [sp+4Ch] [bp-8Ch]@7
  __int16 v38; // [sp+50h] [bp-88h]@7
  char v39; // [sp+54h] [bp-84h]@7
  __int16 v40; // [sp+58h] [bp-80h]@7
  char v41; // [sp+5Ah] [bp-7Eh]@7
  int v42; // [sp+5Ch] [bp-7Ch]@7
  int v43; // [sp+60h] [bp-78h]@7
  int v44; // [sp+64h] [bp-74h]@7
  char v45; // [sp+68h] [bp-70h]@7
  __int16 v46; // [sp+6Ah] [bp-6Eh]@7
  char v47; // [sp+6Ch] [bp-6Ch]@7
  int v48; // [sp+6Dh] [bp-6Bh]@7
  int v49; // [sp+71h] [bp-67h]@7
  int v50; // [sp+75h] [bp-63h]@7
  int v51; // [sp+79h] [bp-5Fh]@7
  char v52; // [sp+80h] [bp-58h]@7
  int v53; // [sp+8Ch] [bp-4Ch]@7
  int v54; // [sp+90h] [bp-48h]@7
  char v55; // [sp+94h] [bp-44h]@7
  int v56; // [sp+98h] [bp-40h]@7
  char v57; // [sp+9Ch] [bp-3Ch]@7
  char v58; // [sp+A0h] [bp-38h]@7
  char v59; // [sp+A4h] [bp-34h]@7
  char v60; // [sp+A5h] [bp-33h]@7
  char v61; // [sp+A6h] [bp-32h]@7
  char v62; // [sp+A8h] [bp-30h]@7
  char v63; // [sp+ACh] [bp-2Ch]@7
  char v64; // [sp+B0h] [bp-28h]@7
  char v65; // [sp+B4h] [bp-24h]@7
  char v66; // [sp+B8h] [bp-20h]@7
  int v67; // [sp+BCh] [bp-1Ch]@7
  int v68; // [sp+C0h] [bp-18h]@7
  int v69; // [sp+C4h] [bp-14h]@7
  signed int v70; // [sp+24h] [bp-B4h]@12
  int v71; // [sp+34h] [bp-A4h]@14
  int v72; // [sp+28h] [bp-B0h]@17
  int v73; // [sp+38h] [bp-A0h]@17
  int v74; // [sp+30h] [bp-A8h]@24

  v32 = *MK_FP(__GS__, 20);
  v33 = a1;
  v34 = a3;
  v35 = a2;
  v3 = *(_DWORD *)(a1 + 4);
  if ( v3 == *(_DWORD *)(a1 + 8) )
  {
    v10 = v33;
    v8 = (v3 - *(_DWORD *)v33) >> 7;
    v9 = (v3 - *(_DWORD *)v33) >> 7;
    if ( !v8 )
      v9 = 1;
    v26 = __MKCADD__(v8, v9);
    v11 = v8 + v9;
    v70 = v11;
    if ( v26 || (unsigned int)v11 > 0x1FFFFFF )
    {
      v70 = 33554431;
    }
    else
    {
      v71 = 0;
      if ( !v11 )
        goto LABEL_17;
    }
    goto LABEL_14;
  }
  if ( v3 )
  {
    sub_8078C30(v3, v3 - 128);
    v3 = *(_DWORD *)(v33 + 4);
  }
  *(_DWORD *)(v33 + 4) = v3 + 128;
  sub_8078C30((int)&v36, v34);
  v4 = *(_DWORD *)(v33 + 4);
  v5 = (v4 - 256 - a2) >> 7;
  if ( v5 > 0 )
  {
    v6 = v4 - 128;
    do
    {
      v22 = v6 - 256;
      v6 -= 128;
      std__string__assign(v6, v22);
      std__string__assign(v6 + 4, v22 + 4);
      *(_WORD *)(v6 + 8) = *(_WORD *)(v6 - 120);
      std__string__assign(v6 + 12, v22 + 12);
      *(_WORD *)(v6 + 16) = *(_WORD *)(v6 - 112);
      *(_BYTE *)(v6 + 18) = *(_BYTE *)(v6 - 110);
      *(_DWORD *)(v6 + 20) = *(_DWORD *)(v6 - 108);
      *(_DWORD *)(v6 + 24) = *(_DWORD *)(v6 - 104);
      *(_DWORD *)(v6 + 28) = *(_DWORD *)(v6 - 100);
      *(_BYTE *)(v6 + 32) = *(_BYTE *)(v6 - 96);
      *(_WORD *)(v6 + 34) = *(_WORD *)(v6 - 94);
      *(_BYTE *)(v6 + 36) = *(_BYTE *)(v6 - 92);
      *(_DWORD *)(v6 + 37) = *(_DWORD *)(v6 - 91);
      *(_DWORD *)(v6 + 41) = *(_DWORD *)(v6 - 87);
      *(_DWORD *)(v6 + 45) = *(_DWORD *)(v6 - 83);
      *(_DWORD *)(v6 + 49) = *(_DWORD *)(v6 - 79);
      sub_804B500(v23, v24, v6 + 56, v22 + 56);
      *(_DWORD *)(v6 + 68) = *(_DWORD *)(v6 - 60);
      *(_DWORD *)(v6 + 72) = *(_DWORD *)(v6 - 56);
      *(_BYTE *)(v6 + 76) = *(_BYTE *)(v6 - 52);
      *(_DWORD *)(v6 + 80) = *(_DWORD *)(v6 - 48);
      std__string__assign(v6 + 84, v22 + 84);
      std__string__assign(v6 + 88, v22 + 88);
      *(_BYTE *)(v6 + 92) = *(_BYTE *)(v6 - 36);
      *(_BYTE *)(v6 + 93) = *(_BYTE *)(v6 - 35);
      *(_BYTE *)(v6 + 94) = *(_BYTE *)(v6 - 34);
      std__string__assign(v6 + 96, v22 + 96);
      std__string__assign(v6 + 100, v22 + 100);
      std__string__assign(v6 + 104, v22 + 104);
      std__string__assign(v6 + 108, v22 + 108);
      std__string__assign(v6 + 112, v22 + 112);
      --v5;
      *(_DWORD *)(v6 + 116) = *(_DWORD *)(v6 - 12);
      *(_DWORD *)(v6 + 120) = *(_DWORD *)(v6 - 8);
      *(_DWORD *)(v6 + 124) = *(_DWORD *)(v6 - 4);
    }
    while ( v5 > 0 );
  }
  std__string__assign(a2, &v36);
  std__string__assign(a2 + 4, &v37);
  *(_WORD *)(a2 + 8) = v38;
  std__string__assign(a2 + 12, &v39);
  *(_WORD *)(a2 + 16) = v40;
  *(_BYTE *)(a2 + 18) = v41;
  *(_DWORD *)(a2 + 20) = v42;
  *(_DWORD *)(a2 + 24) = v43;
  *(_DWORD *)(a2 + 28) = v44;
  *(_BYTE *)(a2 + 32) = v45;
  *(_WORD *)(a2 + 34) = v46;
  *(_BYTE *)(a2 + 36) = v47;
  *(_DWORD *)(a2 + 37) = v48;
  *(_DWORD *)(a2 + 41) = v49;
  *(_DWORD *)(a2 + 45) = v50;
  *(_DWORD *)(a2 + 49) = v51;
  sub_804B500(a2, v25, a2 + 56, (int)&v52);
  *(_DWORD *)(a2 + 68) = v53;
  *(_DWORD *)(a2 + 72) = v54;
  *(_BYTE *)(a2 + 76) = v55;
  *(_DWORD *)(a2 + 80) = v56;
  std__string__assign(a2 + 84, &v57);
  std__string__assign(a2 + 88, &v58);
  *(_BYTE *)(a2 + 92) = v59;
  *(_BYTE *)(a2 + 93) = v60;
  *(_BYTE *)(a2 + 94) = v61;
  std__string__assign(a2 + 96, &v62);
  std__string__assign(a2 + 100, &v63);
  std__string__assign(a2 + 104, &v64);
  std__string__assign(a2 + 108, &v65);
  std__string__assign(a2 + 112, &v66);
  *(_DWORD *)(a2 + 116) = v67;
  *(_DWORD *)(a2 + 120) = v68;
  *(_DWORD *)(a2 + 124) = v69;
  sub_807B640((int)&v36, a2, (int)&v36);
  while ( 1 )
  {
    result = *MK_FP(__GS__, 20) ^ v32;
    if ( !(*MK_FP(__GS__, 20) ^ v32) )
      break;
    v30 = __stack_chk_fail();
    v31 = _Unwind_Resume(v30);
    sub_807B640(v10, v11, (int)&v36);
    _Unwind_Resume(v31);
LABEL_14:
    v71 = operator new(v10, v11);
LABEL_17:
    v72 = v71;
    v12 = *(_DWORD *)v33;
    v27 = *(_DWORD *)v33 == a2;
    v73 = v71;
    if ( !v27 )
    {
      v14 = v71;
      v13 = v71 + 128;
      do
      {
        if ( v14 )
          sub_8078C30(v14, v12);
        v12 += 128;
        v14 = v13;
        v73 = v13;
        v13 += 128;
      }
      while ( a2 != v12 );
    }
    v72 = v73;
    if ( v73 )
      sub_8078C30(v73, v34);
    v15 = a2;
    v16 = v73 + 128;
    v72 = v73 + 128;
    v28 = *(_DWORD *)(v33 + 4);
    v17 = v73 + 128;
    v74 = *(_DWORD *)(v33 + 4);
    if ( v28 != a2 )
    {
      v18 = a2;
      v19 = v73 + 256;
      do
      {
        if ( v17 )
          sub_8078C30(v17, v18);
        v18 += 128;
        v17 = v19;
        v19 += 128;
      }
      while ( v74 != v18 );
      v16 = *(_DWORD *)(v33 + 4);
      v35 = *(_DWORD *)(v33 + 4);
    }
    v21 = *(_DWORD *)v33;
    v20 = v35;
    if ( *(_DWORD *)v33 != v35 )
    {
      do
      {
        v29 = v21;
        v21 += 128;
        sub_807B640(v16, v15, v29);
      }
      while ( v35 != v21 );
      v15 = v33;
      v20 = *(_DWORD *)v33;
    }
    if ( v20 )
      operator delete(v16, v15);
    *(_DWORD *)v33 = v71;
    *(_DWORD *)(v33 + 4) = v17;
    v70 <<= 7;
    *(_DWORD *)(v33 + 8) = v70 + v71;
  }
  return result;
}

//----- (0807C2A0) --------------------------------------------------------
int __cdecl sub_807C2A0(int a1, int a2)
{
  int v2; // eax@1
  int v3; // ebx@1
  int result; // eax@4

  v3 = a1;
  v2 = *(_DWORD *)(a1 + 4);
  if ( v2 == *(_DWORD *)(a1 + 8) )
  {
    result = sub_807BC40(a1, *(_DWORD *)(a1 + 4), a2);
  }
  else
  {
    if ( v2 )
    {
      sub_8078C30(*(_DWORD *)(a1 + 4), a2);
      v2 = *(_DWORD *)(v3 + 4);
    }
    result = v2 + 128;
    *(_DWORD *)(v3 + 4) = result;
  }
  return result;
}

//----- (0807C300) --------------------------------------------------------
int __cdecl sub_807C300(int *a1)
{
  int result; // eax@1
  int v3; // ecx@4
  int *v4; // ebx@1
  char v10; // [sp+1Fh] [bp-9h]@6

  v4 = a1;
  std__string___string(a1 + 5);
  std__string___string(v4 + 4);
  std__string___string(v4 + 3);
  std__string___string(v4 + 2);
  std__string___string(v4 + 1);
  result = *v4;
  _EDX = *v4 - 12;
  if ( _EDX != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v3 = result;
    }
    else
    {
      v3 = *(_DWORD *)(_EDX + 8);
      result = v3 - 1;
      *(_DWORD *)(_EDX + 8) = v3 - 1;
    }
    if ( v3 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v10);
  }
  return result;
}

//----- (0807C3F0) --------------------------------------------------------
int __cdecl sub_807C3F0(int a1)
{
  int v2; // ebx@1
  int result; // eax@3
  int v6; // ecx@6
  int v7; // ecx@10
  int v8; // ecx@14
  int v9; // eax@1
  int v10; // eax@2
  char v28; // [sp+1Fh] [bp-9h]@8
  char v29; // [sp+1Dh] [bp-Bh]@12
  char v30; // [sp+1Eh] [bp-Ah]@16

  v2 = a1;
  v9 = *(_DWORD *)(a1 + 8);
  _EDX = v9 - 12;
  if ( v9 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v6 = _EAX;
    }
    else
    {
      v6 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v6 - 1;
    }
    if ( v6 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v28);
  }
  v10 = *(_DWORD *)(v2 + 4);
  _EDX = v10 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v10 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v8 = _EAX;
    }
    else
    {
      v8 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v8 - 1;
    }
    if ( v8 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v30);
  }
  result = *(_DWORD *)v2;
  _EDX = *(_DWORD *)v2 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)_EDX )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = result;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      result = v7 - 1;
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v29);
  }
  return result;
}

//----- (0807C4D0) --------------------------------------------------------
int __fastcall sub_807C4D0(int a1, int a2, int a3, int a4, int a5)
{
  int v4; // ebx@1
  int v5; // ebx@4
  int i; // edi@4
  int result; // eax@6
  int v8; // eax@7
  int v9; // edx@7
  int v10; // edx@9
  int v11; // ebx@14
  int v12; // edi@15
  int v13; // esi@15
  int v14; // esi@21
  int v15; // ebx@22
  int v16; // eax@27
  int v17; // edx@27
  int v18; // ebx@27
  int v19; // eax@4
  int v20; // esi@5
  unsigned __int8 v21; // cf@9
  char v22; // zf@14
  int v23; // eax@21
  int v24; // ST00_4@28
  int v25; // edx@32
  int v26; // [sp+28h] [bp-30h]@1
  char v27; // [sp+3Ch] [bp-1Ch]@4
  char v28; // [sp+40h] [bp-18h]@4
  char v29; // [sp+44h] [bp-14h]@4
  __int16 v30; // [sp+48h] [bp-10h]@4
  signed int v31; // [sp+1Ch] [bp-3Ch]@9
  int v32; // [sp+38h] [bp-20h]@11
  int v33; // [sp+20h] [bp-38h]@14
  int v34; // [sp+34h] [bp-24h]@14
  int v35; // [sp+24h] [bp-34h]@17
  int v36; // [sp+30h] [bp-28h]@21
  int v37; // [sp+2Ch] [bp-2Ch]@22

  v26 = a4;
  v4 = *(_DWORD *)(a3 + 4);
  if ( v4 != *(_DWORD *)(a3 + 8) )
  {
    if ( v4 )
    {
      std__string__string(v4, v4 - 16);
      std__string__string(v4 + 4, v4 - 16 + 4);
      std__string__string(v4 + 8, v4 - 16 + 8);
      *(_WORD *)(v4 + 12) = *(_WORD *)(v4 - 16 + 12);
      v4 = *(_DWORD *)(a3 + 4);
    }
    *(_DWORD *)(a3 + 4) = v4 + 16;
    std__string__string(&v27, a5);
    std__string__string(&v28, a5 + 4);
    std__string__string(&v29, a5 + 8);
    v30 = *(_WORD *)(a5 + 12);
    v19 = *(_DWORD *)(a3 + 4);
    v5 = v19 - 16;
    for ( i = (v19 - 32 - a4) >> 4; i > 0; *(_WORD *)(v5 + 12) = *(_WORD *)(v5 - 4) )
    {
      v20 = v5 - 32;
      v5 -= 16;
      std__string__assign(v5, v20);
      std__string__assign(v5 + 4, v20 + 4);
      std__string__assign(v5 + 8, v20 + 8);
      --i;
    }
    std__string__assign(a4, &v27);
    std__string__assign(a4 + 4, &v28);
    std__string__assign(a4 + 8, &v29);
    *(_WORD *)(a4 + 12) = v30;
    std__string___string(&v29);
    std__string___string(&v28);
    return std__string___string(&v27);
  }
  v8 = (v4 - *(_DWORD *)a3) >> 4;
  v9 = (v4 - *(_DWORD *)a3) >> 4;
  if ( !v8 )
    v9 = 1;
  v21 = __MKCADD__(v8, v9);
  v10 = v8 + v9;
  v31 = v10;
  if ( v21 || (unsigned int)v10 > 0xFFFFFFF )
  {
    v31 = 268435455;
  }
  else
  {
    v32 = 0;
    if ( !v10 )
      goto LABEL_14;
  }
  v32 = operator new(a1, v10);
LABEL_14:
  v33 = v32;
  v11 = *(_DWORD *)a3;
  v22 = *(_DWORD *)a3 == a4;
  v34 = v32;
  if ( !v22 )
  {
    v13 = v32;
    v12 = v32 + 16;
    do
    {
      if ( v13 )
      {
        std__string__string(v13, v11);
        v35 = v13 + 4;
        std__string__string(v13 + 4, v11 + 4);
        std__string__string(v13 + 8, v11 + 8);
        *(_WORD *)(v13 + 12) = *(_WORD *)(v11 + 12);
      }
      v11 += 16;
      v13 = v12;
      v34 = v12;
      v12 += 16;
    }
    while ( a4 != v11 );
  }
  v33 = v34;
  if ( v34 )
  {
    std__string__string(v34, a5);
    std__string__string(v34 + 4, a5 + 4);
    std__string__string(v34 + 8, a5 + 8);
    *(_WORD *)(v34 + 12) = *(_WORD *)(a5 + 12);
  }
  v33 = v34 + 16;
  v14 = v34 + 16;
  v23 = *(_DWORD *)(a3 + 4);
  v36 = *(_DWORD *)(a3 + 4);
  if ( v23 != a4 )
  {
    v15 = a4;
    v37 = v34 + 32;
    do
    {
      if ( v14 )
      {
        std__string__string(v14, v15);
        std__string__string(v14 + 4, v15 + 4);
        std__string__string(v14 + 8, v15 + 8);
        *(_WORD *)(v14 + 12) = *(_WORD *)(v15 + 12);
      }
      v14 = v37;
      v15 += 16;
      v37 += 16;
    }
    while ( v36 != v15 );
    v26 = *(_DWORD *)(a3 + 4);
  }
  v17 = a3;
  v16 = v26;
  v18 = *(_DWORD *)a3;
  if ( v26 != *(_DWORD *)a3 )
  {
    do
    {
      std__string___string(v18 + 8);
      std__string___string(v18 + 4);
      v24 = v18;
      v18 += 16;
      std__string___string(v24);
    }
    while ( v26 != v18 );
    v17 = a3;
    v16 = *(_DWORD *)a3;
  }
  if ( v16 )
    operator delete(a1, v17);
  v25 = v32;
  *(_DWORD *)a3 = v32;
  *(_DWORD *)(a3 + 4) = v14;
  v31 *= 16;
  result = v31 + v25;
  *(_DWORD *)(a3 + 8) = v31 + v25;
  return result;
}

//----- (0807CA40) --------------------------------------------------------
int __stdcall sub_807CA40(int a1, int a2, int a3)
{
  int v1; // eax@1
  int v2; // ebx@1
  int v3; // edi@1
  int v4; // esi@2
  int result; // eax@6
  int v7; // ecx@8
  int v8; // ST04_4@3
  int v9; // eax@3
  int v10; // eax@5
  int v11; // eax@5
  char v20; // [sp+1Bh] [bp-Dh]@10

  v3 = a2;
  v1 = *(_DWORD *)(a2 + 4);
  v2 = a3 + 8;
  if ( v1 != a3 + 8 )
  {
    v4 = (v1 - v2) >> 3;
    if ( v4 > 0 )
    {
      do
      {
        --v4;
        *(_WORD *)(v2 - 8) = *(_WORD *)v2;
        v8 = v2 + 4;
        v9 = v2 - 4;
        v2 += 8;
        std__string__assign(v9, v8);
      }
      while ( v4 > 0 );
      v1 = *(_DWORD *)(v3 + 4);
    }
  }
  v10 = v1 - 8;
  *(_DWORD *)(v3 + 4) = v10;
  v11 = *(_DWORD *)(v10 + 4);
  _EDX = v11 - 12;
  if ( v11 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v7 = _EAX;
    }
    else
    {
      v7 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v7 - 1;
    }
    if ( v7 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v20);
  }
  result = a1;
  *(_DWORD *)a1 = a3;
  return result;
}

//----- (0807CAF0) --------------------------------------------------------
int __cdecl sub_807CAF0(int a1)
{
  int v2; // ebx@1
  int result; // eax@5
  int v8; // ecx@8
  int v9; // ecx@12
  int v10; // ecx@16
  int v11; // ecx@20
  int v12; // ecx@24
  int v13; // eax@1
  int v14; // eax@2
  int v15; // eax@3
  int v16; // eax@4
  char v46; // [sp+1Fh] [bp-9h]@10
  char v47; // [sp+1Bh] [bp-Dh]@14
  char v48; // [sp+1Dh] [bp-Bh]@18
  char v49; // [sp+1Ch] [bp-Ch]@22
  char v50; // [sp+1Eh] [bp-Ah]@26

  v2 = a1;
  v13 = *(_DWORD *)(a1 + 16);
  _EDX = v13 - 12;
  if ( v13 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v8 = _EAX;
    }
    else
    {
      v8 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v8 - 1;
    }
    if ( v8 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v46);
  }
  v14 = *(_DWORD *)(v2 + 12);
  _EDX = v14 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v14 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v12 = _EAX;
    }
    else
    {
      v12 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v12 - 1;
    }
    if ( v12 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v50);
  }
  v15 = *(_DWORD *)(v2 + 8);
  _EDX = v15 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v15 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v10 = _EAX;
    }
    else
    {
      v10 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v10 - 1;
    }
    if ( v10 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v48);
  }
  v16 = *(_DWORD *)(v2 + 4);
  _EDX = v16 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)(v16 - 12) )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v11 = _EAX;
    }
    else
    {
      v11 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v11 - 1;
    }
    if ( v11 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v49);
  }
  result = *(_DWORD *)v2;
  _EDX = *(_DWORD *)v2 - 12;
  if ( std__string___Rep___S_empty_rep_storage != (char *)_EDX )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v9 = result;
    }
    else
    {
      v9 = *(_DWORD *)(_EDX + 8);
      result = v9 - 1;
      *(_DWORD *)(_EDX + 8) = v9 - 1;
    }
    if ( v9 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v47);
  }
  return result;
}

//----- (0807CC80) --------------------------------------------------------
int __fastcall sub_807CC80(int a1, int a2, int a3, int a4, int a5)
{
  int v4; // ebx@1
  int v5; // ebx@4
  int i; // edi@4
  int result; // eax@6
  int v8; // eax@7
  int v9; // ebx@7
  int v10; // edx@8
  int v11; // edx@10
  int v12; // ebx@15
  int v13; // edi@16
  int v14; // esi@16
  int v15; // edx@22
  int v16; // esi@22
  int v17; // ebx@23
  int v18; // eax@28
  int v19; // ebx@28
  int v20; // edx@4
  int v21; // eax@4
  int v22; // esi@5
  unsigned __int8 v23; // cf@10
  char v24; // zf@15
  int v25; // eax@22
  int v26; // ST00_4@29
  int v27; // [sp+38h] [bp-50h]@1
  int v28; // [sp+1Ch] [bp-6Ch]@3
  int v29; // [sp+20h] [bp-68h]@3
  char v30; // [sp+58h] [bp-30h]@4
  char v31; // [sp+5Ch] [bp-2Ch]@4
  char v32; // [sp+60h] [bp-28h]@4
  char v33; // [sp+64h] [bp-24h]@4
  char v34; // [sp+68h] [bp-20h]@4
  int v35; // [sp+6Ch] [bp-1Ch]@4
  char v36; // [sp+70h] [bp-18h]@4
  int v37; // [sp+74h] [bp-14h]@4
  __int16 v38; // [sp+78h] [bp-10h]@4
  signed int v39; // [sp+14h] [bp-74h]@10
  int v40; // [sp+44h] [bp-44h]@12
  int v41; // [sp+18h] [bp-70h]@15
  int v42; // [sp+48h] [bp-40h]@15
  int v43; // [sp+24h] [bp-64h]@18
  int v44; // [sp+28h] [bp-60h]@18
  int v45; // [sp+2Ch] [bp-5Ch]@18
  int v46; // [sp+40h] [bp-48h]@22
  int v47; // [sp+3Ch] [bp-4Ch]@23
  int v48; // [sp+30h] [bp-58h]@25
  int v49; // [sp+34h] [bp-54h]@25
  int v50; // [sp+10h] [bp-78h]@34

  v27 = a4;
  v4 = *(_DWORD *)(a3 + 4);
  if ( v4 != *(_DWORD *)(a3 + 8) )
  {
    if ( v4 )
    {
      std__string__string(v4, v4 - 36);
      v28 = v4 + 4;
      std__string__string(v4 + 4, v4 - 36 + 4);
      v29 = v4 + 8;
      std__string__string(v4 + 8, v4 - 36 + 8);
      std__string__string(v4 + 12, v4 - 36 + 12);
      std__string__string(v4 + 16, v4 - 36 + 16);
      *(_DWORD *)(v4 + 20) = *(_DWORD *)(v4 - 36 + 20);
      *(_BYTE *)(v4 + 24) = *(_BYTE *)(v4 - 36 + 24);
      *(_DWORD *)(v4 + 28) = *(_DWORD *)(v4 - 36 + 28);
      *(_WORD *)(v4 + 32) = *(_WORD *)(v4 - 36 + 32);
      v4 = *(_DWORD *)(a3 + 4);
    }
    *(_DWORD *)(a3 + 4) = v4 + 36;
    std__string__string(&v30, a5);
    std__string__string(&v31, a5 + 4);
    std__string__string(&v32, a5 + 8);
    std__string__string(&v33, a5 + 12);
    std__string__string(&v34, a5 + 16);
    v35 = *(_DWORD *)(a5 + 20);
    v36 = *(_BYTE *)(a5 + 24);
    v37 = *(_DWORD *)(a5 + 28);
    v38 = *(_WORD *)(a5 + 32);
    v20 = *(_DWORD *)(a3 + 4);
    v5 = v20 - 36;
    v21 = (v20 - 72 - a4) >> 2;
    for ( i = 954437177 * v21; i > 0; *(_WORD *)(v5 + 32) = *(_WORD *)(v5 - 4) )
    {
      v22 = v5 - 72;
      v5 -= 36;
      std__string__assign(v5, v22);
      std__string__assign(v5 + 4, v22 + 4);
      std__string__assign(v5 + 8, v22 + 8);
      std__string__assign(v5 + 12, v22 + 12);
      std__string__assign(v5 + 16, v22 + 16);
      --i;
      *(_DWORD *)(v5 + 20) = *(_DWORD *)(v5 - 16);
      *(_BYTE *)(v5 + 24) = *(_BYTE *)(v5 - 12);
      *(_DWORD *)(v5 + 28) = *(_DWORD *)(v5 - 8);
    }
    std__string__assign(a4, &v30);
    std__string__assign(a4 + 4, &v31);
    std__string__assign(a4 + 8, &v32);
    std__string__assign(a4 + 12, &v33);
    std__string__assign(a4 + 16, &v34);
    *(_DWORD *)(a4 + 20) = v35;
    *(_BYTE *)(a4 + 24) = v36;
    *(_DWORD *)(a4 + 28) = v37;
    *(_WORD *)(a4 + 32) = v38;
    std__string___string(&v34);
    std__string___string(&v33);
    std__string___string(&v32);
    std__string___string(&v31);
    return std__string___string(&v30);
  }
  v9 = (v4 - *(_DWORD *)a3) >> 2;
  v8 = 954437177 * v9;
  if ( 954437177 * v9 == 119304647 )
  {
    v50 = std____throw_length_error(a1);
    while ( 1 )
    {
      std__string___string(&v30);
      v50 = _Unwind_Resume(v50);
      std__string___string(&v31);
    }
  }
  v10 = 954437177 * v9;
  if ( !v8 )
    v10 = 1;
  v23 = __MKCADD__(v8, v10);
  v11 = v8 + v10;
  v39 = v11;
  if ( v23 || (unsigned int)v11 > 0x71C71C7 )
  {
    v39 = 119304647;
  }
  else
  {
    v40 = 0;
    if ( !v11 )
      goto LABEL_15;
    v11 = v39;
  }
  v40 = operator new(a1, v11);
LABEL_15:
  v41 = v40;
  v12 = *(_DWORD *)a3;
  v24 = *(_DWORD *)a3 == a4;
  v42 = v40;
  if ( !v24 )
  {
    v14 = v40;
    v13 = v40 + 36;
    do
    {
      if ( v14 )
      {
        std__string__string(v14, v12);
        v43 = v14 + 4;
        std__string__string(v14 + 4, v12 + 4);
        v44 = v14 + 8;
        std__string__string(v14 + 8, v12 + 8);
        v45 = v14 + 12;
        std__string__string(v14 + 12, v12 + 12);
        std__string__string(v14 + 16, v12 + 16);
        *(_DWORD *)(v14 + 20) = *(_DWORD *)(v12 + 20);
        *(_BYTE *)(v14 + 24) = *(_BYTE *)(v12 + 24);
        *(_DWORD *)(v14 + 28) = *(_DWORD *)(v12 + 28);
        *(_WORD *)(v14 + 32) = *(_WORD *)(v12 + 32);
      }
      v12 += 36;
      v14 = v13;
      v42 = v13;
      v13 += 36;
    }
    while ( a4 != v12 );
  }
  v41 = v42;
  if ( v42 )
  {
    std__string__string(v42, a5);
    std__string__string(v42 + 4, a5 + 4);
    std__string__string(v42 + 8, a5 + 8);
    std__string__string(v42 + 12, a5 + 12);
    std__string__string(v42 + 16, a5 + 16);
    *(_DWORD *)(v42 + 20) = *(_DWORD *)(a5 + 20);
    *(_BYTE *)(v42 + 24) = *(_BYTE *)(a5 + 24);
    *(_DWORD *)(v42 + 28) = *(_DWORD *)(a5 + 28);
    *(_WORD *)(v42 + 32) = *(_WORD *)(a5 + 32);
  }
  v41 = v42 + 36;
  v16 = v42 + 36;
  v25 = *(_DWORD *)(a3 + 4);
  v15 = a4;
  v46 = *(_DWORD *)(a3 + 4);
  if ( v25 != a4 )
  {
    v17 = a4;
    v47 = v42 + 72;
    do
    {
      if ( v16 )
      {
        std__string__string(v16, v17);
        v48 = v16 + 4;
        std__string__string(v16 + 4, v17 + 4);
        v49 = v16 + 8;
        std__string__string(v16 + 8, v17 + 8);
        std__string__string(v16 + 12, v17 + 12);
        std__string__string(v16 + 16, v17 + 16);
        *(_DWORD *)(v16 + 20) = *(_DWORD *)(v17 + 20);
        *(_BYTE *)(v16 + 24) = *(_BYTE *)(v17 + 24);
        *(_DWORD *)(v16 + 28) = *(_DWORD *)(v17 + 28);
        *(_WORD *)(v16 + 32) = *(_WORD *)(v17 + 32);
      }
      v16 = v47;
      v17 += 36;
      v47 += 36;
    }
    while ( v46 != v17 );
    v15 = *(_DWORD *)(a3 + 4);
    v27 = *(_DWORD *)(a3 + 4);
  }
  v19 = *(_DWORD *)a3;
  v18 = v27;
  if ( *(_DWORD *)a3 != v27 )
  {
    do
    {
      std__string___string(v19 + 16);
      std__string___string(v19 + 12);
      std__string___string(v19 + 8);
      std__string___string(v19 + 4);
      v26 = v19;
      v19 += 36;
      std__string___string(v26);
    }
    while ( v27 != v19 );
    v15 = a3;
    v18 = *(_DWORD *)a3;
  }
  if ( v18 )
    operator delete(a1, v15);
  *(_DWORD *)a3 = v40;
  *(_DWORD *)(a3 + 4) = v16;
  result = v40 + 36 * v39;
  *(_DWORD *)(a3 + 8) = v40 + 36 * v39;
  return result;
}

//----- (0807D540) --------------------------------------------------------
int __cdecl std__basic_stringbuf_char_std__char_traits_char__std__allocator_char_____basic_stringbuf(int a1)
{
  int v2; // ebx@1
  int v4; // ecx@4
  int v5; // eax@1
  char v12; // [sp+23h] [bp-5h]@6

  v2 = a1;
  v5 = *(_DWORD *)(a1 + 36);
  *(_DWORD *)a1 = 134771432;
  _EDX = v5 - 12;
  if ( v5 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v4 = _EAX;
    }
    else
    {
      v4 = *(_DWORD *)(_EDX + 8);
      *(_DWORD *)(_EDX + 8) = v4 - 1;
    }
    if ( v4 <= 0 )
      std__string___Rep___M_destroy(_EDX, &v12);
  }
  *(_DWORD *)v2 = 134771752;
  return std__locale___locale(v2 + 28);
}

//----- (0807D5B0) --------------------------------------------------------
int __fastcall sub_807D5B0(int a1, int a2, int *a3)
{
  int result; // eax@1
  int v5; // ecx@4
  int *v6; // esi@1
  char v12; // [sp+1Fh] [bp-9h]@6

  v6 = a3;
  sub_8050180(a1, a2, (int)(a3 + 1));
  result = *v6;
  _EDX = *v6 - 12;
  if ( _EDX != (_DWORD)std__string___Rep___S_empty_rep_storage )
  {
    if ( pthread_cancel )
    {
      _EAX = -1;
      __asm { lock xadd [edx+8], eax }
      v5 = result;
    }
    else
    {
      v5 = *(_DWORD *)(_EDX + 8);
      result = v5 - 1;
      *(_DWORD *)(_EDX + 8) = v5 - 1;
    }
    if ( v5 <= 0 )
      result = std__string___Rep___M_destroy(_EDX, &v12);
  }
  return result;
}

//----- (0807D630) --------------------------------------------------------
void __cdecl sub_807D630(int a1, int a2)
{
  int v2; // ebx@1
  int v3; // edi@1
  int v4; // esi@2
  int v5; // ecx@2
  int v6; // edx@2
  int v7; // ecx@2
  int v8; // edx@2

  v2 = a2;
  v3 = a1;
  if ( a2 )
  {
    do
    {
      sub_807D630(v3, *(_DWORD *)(v2 + 12));
      v4 = *(_DWORD *)(v2 + 8);
      sub_8050180(v5, v6, v2 + 20);
      std__string___string(v2 + 16);
      v2 = v4;
      operator delete(v7, v8);
    }
    while ( v4 );
  }
}

//----- (0807D6A0) --------------------------------------------------------
void __cdecl sub_807D6A0(int a1)
{
  sub_807D630(a1, *(_DWORD *)(a1 + 8));
}

//----- (0807D6D0) --------------------------------------------------------
int __cdecl sub_807D6D0(int a1, int a2)
{
  int v2; // eax@3
  unsigned int v3; // ecx@5
  unsigned int v4; // ebx@5
  int v5; // esi@5
  char v6; // cf@7
  unsigned __int8 v7; // zf@7
  int v8; // edi@7
  int v9; // eax@11
  int v10; // eax@16
  unsigned int v11; // ecx@16
  unsigned int v12; // ebx@16
  int v13; // edi@16
  unsigned int v14; // esi@16
  char v15; // cf@17
  unsigned __int8 v16; // zf@17
  int v17; // esi@17
  int v18; // eax@21
  int v20; // edx@1
  unsigned int v21; // edi@2
  int v22; // edx@4
  char v23; // dl@11
  char v24; // dl@21
  int v25; // ebx@26
  int v26; // ecx@26
  int v27; // edx@26
  int v28; // ecx@26
  int v29; // edx@26
  int v30; // [sp+2Ch] [bp-21Ch]@1
  int v31; // [sp+30h] [bp-218h]@1
  int v32; // [sp+34h] [bp-214h]@2
  int v33; // [sp+28h] [bp-220h]@2
  unsigned int v34; // [sp+14h] [bp-234h]@2
  int v35; // [sp+24h] [bp-224h]@16
  int v36; // [sp+10h] [bp-238h]@16
  signed int v37; // [sp+140h] [bp-108h]@26
  signed int v38; // [sp+144h] [bp-104h]@26
  signed int v39; // [sp+148h] [bp-100h]@26
  signed int v40; // [sp+14Ch] [bp-FCh]@26
  signed int v41; // [sp+150h] [bp-F8h]@26
  signed int v42; // [sp+154h] [bp-F4h]@26
  signed int v43; // [sp+158h] [bp-F0h]@26
  signed int v44; // [sp+15Ch] [bp-ECh]@26
  signed int v45; // [sp+160h] [bp-E8h]@26
  signed int v46; // [sp+164h] [bp-E4h]@26
  signed int v47; // [sp+168h] [bp-E0h]@26
  signed int v48; // [sp+16Ch] [bp-DCh]@26
  __int16 v49; // [sp+170h] [bp-D8h]@26
  char v50; // [sp+172h] [bp-D6h]@26
  char v51; // [sp+173h] [bp-D5h]@26
  char v52; // [sp+174h] [bp-D4h]@26
  char v53; // [sp+175h] [bp-D3h]@26
  char v54; // [sp+176h] [bp-D2h]@26
  __int16 v55; // [sp+178h] [bp-D0h]@26
  char v56; // [sp+17Ah] [bp-CEh]@26
  signed int v57; // [sp+17Ch] [bp-CCh]@26
  __int16 v58; // [sp+180h] [bp-C8h]@26
  char v59; // [sp+182h] [bp-C6h]@26
  char v60; // [sp+183h] [bp-C5h]@26
  char v61; // [sp+184h] [bp-C4h]@26
  char v62; // [sp+185h] [bp-C3h]@26
  char v63; // [sp+186h] [bp-C2h]@26
  signed int v64; // [sp+188h] [bp-C0h]@26
  signed int v65; // [sp+18Ch] [bp-BCh]@26
  __int16 v66; // [sp+190h] [bp-B8h]@26
  char v67; // [sp+192h] [bp-B6h]@26
  char v68; // [sp+193h] [bp-B5h]@26
  __int16 v69; // [sp+194h] [bp-B4h]@26
  int v70; // [sp+198h] [bp-B0h]@26
  int v71; // [sp+19Ch] [bp-ACh]@26
  int v72; // [sp+1A0h] [bp-A8h]@26
  char v73; // [sp+1A4h] [bp-A4h]@26
  __int16 v74; // [sp+1A6h] [bp-A2h]@26
  signed int v75; // [sp+1A8h] [bp-A0h]@26
  signed int v76; // [sp+1ACh] [bp-9Ch]@26
  signed int v77; // [sp+1B0h] [bp-98h]@26
  signed int v78; // [sp+1B4h] [bp-94h]@26
  signed int v79; // [sp+1B8h] [bp-90h]@26
  signed int v80; // [sp+1BCh] [bp-8Ch]@26
  signed int v81; // [sp+1C0h] [bp-88h]@26
  __int16 v82; // [sp+1C4h] [bp-84h]@26
  signed int v83; // [sp+1C8h] [bp-80h]@26
  signed int v84; // [sp+1CCh] [bp-7Ch]@26
  signed int v85; // [sp+1D0h] [bp-78h]@26
  __int16 v86; // [sp+1D4h] [bp-74h]@26
  signed int v87; // [sp+1D8h] [bp-70h]@26
  signed int v88; // [sp+1DCh] [bp-6Ch]@26
  __int16 v89; // [sp+1E0h] [bp-68h]@26
  signed int v90; // [sp+1E4h] [bp-64h]@26
  __int16 v91; // [sp+1E8h] [bp-60h]@26
  signed int v92; // [sp+1ECh] [bp-5Ch]@26
  __int16 v93; // [sp+1F0h] [bp-58h]@26
  signed int v94; // [sp+1F4h] [bp-54h]@26
  __int16 v95; // [sp+1F8h] [bp-50h]@26
  signed int v96; // [sp+1FCh] [bp-4Ch]@26
  __int16 v97; // [sp+200h] [bp-48h]@26
  signed int v98; // [sp+204h] [bp-44h]@26
  __int16 v99; // [sp+208h] [bp-40h]@26
  signed int v100; // [sp+20Ch] [bp-3Ch]@26
  __int16 v101; // [sp+210h] [bp-38h]@26
  signed int v102; // [sp+214h] [bp-34h]@26
  __int16 v103; // [sp+218h] [bp-30h]@26
  signed int v104; // [sp+21Ch] [bp-2Ch]@26
  __int16 v105; // [sp+220h] [bp-28h]@26
  signed int v106; // [sp+224h] [bp-24h]@26
  __int16 v107; // [sp+228h] [bp-20h]@26
  signed int v108; // [sp+22Ch] [bp-1Ch]@26
  __int16 v109; // [sp+230h] [bp-18h]@26
  __int16 v110; // [sp+232h] [bp-16h]@26
  signed int v111; // [sp+234h] [bp-14h]@26
  char v112; // [sp+238h] [bp-10h]@26
  char v113; // [sp+40h] [bp-208h]@26
  char v114; // [sp+44h] [bp-204h]@26
  int v115; // [sp+38h] [bp-210h]@26

  v20 = *(_DWORD *)(a1 + 8);
  v30 = a1 + 4;
  v31 = v20;
  if ( v20 )
  {
    v32 = a1 + 4;
    v21 = *(_DWORD *)(*(_DWORD *)a2 - 12);
    v33 = *(_DWORD *)a2;
    v34 = v21;
    while ( 1 )
    {
      v5 = *(_DWORD *)(v31 + 16);
      v4 = *(_DWORD *)(v5 - 12);
      v3 = *(_DWORD *)(v5 - 12);
      if ( v4 > v34 )
        v3 = v34;
      v8 = v33;
      v6 = v3 < v3;
      v7 = 1;
      do
      {
        if ( !v3 )
          break;
        v6 = *(_BYTE *)v5 < *(_BYTE *)v8;
        v7 = *(_BYTE *)v5++ == *(_BYTE *)v8++;
        --v3;
      }
      while ( v7 );
      v23 = !(v6 | v7) - v6;
      v9 = v23;
      if ( !v23 )
        v9 = v4 - v34;
      if ( v9 >= 0 )
      {
        v2 = *(_DWORD *)(v31 + 8);
        if ( !v2 )
          goto LABEL_15;
      }
      else
      {
        v2 = *(_DWORD *)(v31 + 12);
        v31 = v32;
        if ( !v2 )
          goto LABEL_15;
      }
      v22 = v31;
      v31 = v2;
      v32 = v22;
    }
  }
  v31 = v30;
LABEL_15:
  if ( v31 == v30 )
    goto LABEL_30;
  v35 = v31;
  v10 = *(_DWORD *)a2;
  v14 = *(_DWORD *)(*(_DWORD *)a2 - 12);
  v13 = *(_DWORD *)(v31 + 16);
  v36 = *(_DWORD *)(*(_DWORD *)a2 - 12);
  v12 = *(_DWORD *)(v13 - 12);
  v11 = *(_DWORD *)(v13 - 12);
  if ( v12 > v14 )
    v11 = v14;
  v17 = v10;
  v15 = v11 < v11;
  v16 = 1;
  do
  {
    if ( !v11 )
      break;
    v15 = *(_BYTE *)v17 < *(_BYTE *)v13;
    v16 = *(_BYTE *)v17++ == *(_BYTE *)v13++;
    --v11;
  }
  while ( v16 );
  v24 = !(v15 | v16) - v15;
  v18 = v24;
  if ( !v24 )
    v18 = v36 - v12;
  if ( v18 < 0 )
  {
LABEL_30:
    v37 = 134771820;
    v38 = 134771820;
    v39 = 134771820;
    v40 = 134771820;
    v41 = 134771820;
    v42 = 134771820;
    v43 = 134771820;
    v44 = 134771820;
    v45 = 134771820;
    v46 = 134771820;
    v47 = 134771820;
    v48 = 134771820;
    v49 = 0;
    v50 = 0;
    v51 = 0;
    v52 = 0;
    v53 = 0;
    v54 = 0;
    v55 = 0;
    v56 = 0;
    v57 = 134771820;
    v58 = 0;
    v59 = 0;
    v60 = 0;
    v61 = 0;
    v62 = 0;
    v63 = 0;
    v64 = 134771820;
    v65 = 134771820;
    v66 = 0;
    v67 = 0;
    v68 = 0;
    v69 = 0;
    v70 = 0;
    v71 = 0;
    v72 = 0;
    v73 = 0;
    v74 = 0;
    v75 = 134771820;
    v76 = 134771820;
    v77 = 134771820;
    v78 = 134771820;
    v79 = 134771820;
    v80 = 134771820;
    v81 = 134771820;
    v82 = 0;
    v83 = 134771820;
    v84 = 134771820;
    v85 = 134771820;
    v86 = 0;
    v87 = 134771820;
    v88 = 134771820;
    v89 = 0;
    v90 = 134771820;
    v91 = 0;
    v92 = 134771820;
    v93 = 0;
    v94 = 134771820;
    v95 = 0;
    v96 = 134771820;
    v97 = 0;
    v98 = 134771820;
    v99 = 0;
    v100 = 134771820;
    v101 = 0;
    v102 = 134771820;
    v103 = 0;
    v104 = 134771820;
    v105 = 0;
    v106 = 134771820;
    v107 = 0;
    v108 = 134771820;
    v109 = 0;
    v110 = 0;
    v111 = 134771820;
    v112 = 0;
    std__string__string(&v113, a2);
    sub_8079830((int)&v114, (int)&v37);
    sub_807A620((int)&v115, a1, v31, (int)&v113);
    v25 = v115;
    sub_8050180(v26, v27, (int)&v114);
    std__string___string(&v113);
    sub_8050180(v28, v29, (int)&v37);
    v35 = v25;
  }
  return v35 + 20;
}

//----- (0807DB50) --------------------------------------------------------
int __cdecl sub_807DB50(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // ebx@1
  int v5; // eax@4
  int v6; // esi@4
  int v7; // ebx@5
  int result; // eax@7
  unsigned int v10; // eax@9
  int v11; // esi@10
  int v12; // ebx@11
  int v13; // edi@11
  int v14; // ecx@17
  int v15; // esi@17
  int v16; // ebx@18
  int v17; // edi@18
  int v18; // eax@23
  int v19; // edx@23
  int v20; // ebx@23
  int v22; // ecx@37
  int v23; // eax@6
  signed int v24; // eax@9
  int v25; // eax@10
  char v26; // zf@10
  int v27; // edx@17
  int v39; // [sp+1Ch] [bp-2Ch]@1
  int v40; // [sp+30h] [bp-18h]@4
  char v41; // [sp+34h] [bp-14h]@4
  int v42; // [sp+14h] [bp-34h]@9
  int v43; // [sp+24h] [bp-24h]@10
  int v44; // [sp+18h] [bp-30h]@10
  int v45; // [sp+28h] [bp-20h]@10
  int v46; // [sp+20h] [bp-28h]@17
  char v47; // [sp+3Ah] [bp-Eh]@35
  char v48; // [sp+3Bh] [bp-Dh]@39

  v3 = a1;
  v39 = a2;
  v4 = *(_DWORD *)(a1 + 4);
  if ( v4 == *(_DWORD *)(a1 + 8) )
  {
    v24 = v4 - *(_DWORD *)a1;
    v42 = 1;
    v10 = v24 >> 3;
    if ( v10 )
    {
      v3 = 2 * v10;
      v42 = 2 * v10;
      if ( !(v10 < 2 * v10 | v10 == 0) || (unsigned int)v3 > 0x1FFFFFFF )
        v42 = 536870911;
    }
    v25 = operator new(a1, v3);
    v43 = v25;
    v44 = v25;
    v11 = *(_DWORD *)a1;
    v26 = *(_DWORD *)a1 == a2;
    v45 = v25;
    if ( !v26 )
    {
      v13 = v43;
      v12 = v43 + 8;
      do
      {
        if ( v13 )
        {
          std__string__string(v13, v11);
          *(_BYTE *)(v13 + 4) = *(_BYTE *)(v11 + 4);
        }
        v11 += 8;
        v13 = v12;
        v45 = v12;
        v12 += 8;
      }
      while ( a2 != v11 );
    }
    v44 = v45;
    if ( v45 )
    {
      std__string__string(v45, a3);
      *(_BYTE *)(v45 + 4) = *(_BYTE *)(a3 + 4);
    }
    v14 = a2;
    v44 = v45 + 8;
    v27 = *(_DWORD *)(a1 + 4);
    v15 = v45 + 8;
    v46 = *(_DWORD *)(a1 + 4);
    if ( v27 != a2 )
    {
      v16 = a2;
      v17 = v45 + 16;
      do
      {
        if ( v15 )
        {
          std__string__string(v15, v16);
          *(_BYTE *)(v15 + 4) = *(_BYTE *)(v16 + 4);
        }
        v16 += 8;
        v15 = v17;
        v17 += 8;
      }
      while ( v46 != v16 );
      v39 = *(_DWORD *)(a1 + 4);
    }
    v19 = a1;
    v18 = v39;
    v20 = *(_DWORD *)a1;
    if ( *(_DWORD *)a1 != v39 )
    {
      do
      {
        _EDX = *(_DWORD *)v20 - 12;
        if ( _EDX != (_DWORD)std__string___Rep___S_empty_rep_storage )
        {
          if ( pthread_cancel )
          {
            _EAX = -1;
            __asm { lock xadd [edx+8], eax }
            v14 = _EAX;
          }
          else
          {
            v14 = *(_DWORD *)(_EDX + 8);
            *(_DWORD *)(_EDX + 8) = v14 - 1;
          }
          if ( v14 <= 0 )
            std__string___Rep___M_destroy(_EDX, &v47);
        }
        v20 += 8;
      }
      while ( v39 != v20 );
      v19 = a1;
      v18 = *(_DWORD *)a1;
    }
    if ( v18 )
      operator delete(v14, v19);
    *(_DWORD *)a1 = v43;
    *(_DWORD *)(a1 + 4) = v15;
    result = v43 + 8 * v42;
    *(_DWORD *)(a1 + 8) = v43 + 8 * v42;
  }
  else
  {
    if ( v4 )
    {
      std__string__string(v4, v4 - 8);
      *(_BYTE *)(v4 + 4) = *(_BYTE *)(v4 - 8 + 4);
      v4 = *(_DWORD *)(a1 + 4);
    }
    *(_DWORD *)(a1 + 4) = v4 + 8;
    std__string__string(&v40, a3);
    v41 = *(_BYTE *)(a3 + 4);
    v5 = *(_DWORD *)(a1 + 4);
    v6 = (v5 - 16 - a2) >> 3;
    if ( v6 > 0 )
    {
      v7 = v5 - 8;
      do
      {
        v23 = v7 - 16;
        v7 -= 8;
        std__string__assign(v7, v23);
        --v6;
        *(_BYTE *)(v7 + 4) = *(_BYTE *)(v7 - 4);
      }
      while ( v6 > 0 );
    }
    std__string__assign(a2, &v40);
    *(_BYTE *)(a2 + 4) = v41;
    result = v40;
    _EDX = v40 - 12;
    if ( v40 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
    {
      if ( pthread_cancel )
      {
        _EAX = -1;
        __asm { lock xadd [edx+8], eax }
        v22 = result;
      }
      else
      {
        v22 = *(_DWORD *)(_EDX + 8);
        result = v22 - 1;
        *(_DWORD *)(_EDX + 8) = v22 - 1;
      }
      if ( v22 <= 0 )
        result = std__string___Rep___M_destroy(_EDX, &v48);
    }
  }
  return result;
}

//----- (0807DEF0) --------------------------------------------------------
int __cdecl sub_807DEF0(int a1, int a2, int a3)
{
  int v3; // edx@1
  int v4; // eax@4
  int v5; // esi@4
  int v6; // ebx@5
  int result; // eax@7
  int v9; // eax@9
  int v10; // edx@9
  int v11; // edx@11
  int v12; // esi@15
  int v13; // ebx@16
  int v14; // edi@16
  int v15; // ecx@22
  int v16; // esi@22
  int v17; // ebx@23
  int v18; // edi@23
  int v19; // eax@28
  int v20; // edx@28
  int v21; // ebx@28
  int v23; // ecx@40
  int v24; // eax@6
  unsigned __int8 v25; // cf@11
  char v26; // zf@15
  int v27; // edx@21
  int v28; // edx@22
  int v29; // eax@29
  int v41; // [sp+1Ch] [bp-2Ch]@1
  __int16 v42; // [sp+30h] [bp-18h]@4
  int v43; // [sp+34h] [bp-14h]@4
  signed int v44; // [sp+14h] [bp-34h]@11
  int v45; // [sp+24h] [bp-24h]@14
  int v46; // [sp+18h] [bp-30h]@15
  int v47; // [sp+28h] [bp-20h]@15
  int v48; // [sp+20h] [bp-28h]@22
  char v49; // [sp+3Ah] [bp-Eh]@38
  char v50; // [sp+3Bh] [bp-Dh]@42

  v41 = a2;
  v3 = *(_DWORD *)(a1 + 4);
  if ( v3 != *(_DWORD *)(a1 + 8) )
  {
    if ( v3 )
    {
      *(_WORD *)v3 = *(_WORD *)(v3 - 8);
      std__string__string(v3 + 4, v3 - 4);
      v3 = *(_DWORD *)(a1 + 4);
    }
    *(_DWORD *)(a1 + 4) = v3 + 8;
    v42 = *(_WORD *)a3;
    std__string__string(&v43, a3 + 4);
    v4 = *(_DWORD *)(a1 + 4);
    v5 = (v4 - 16 - a2) >> 3;
    if ( v5 > 0 )
    {
      v6 = v4 - 8;
      do
      {
        v24 = v6 - 16;
        v6 -= 8;
        *(_WORD *)v6 = *(_WORD *)(v6 - 8);
        std__string__assign(v6 + 4, v24 + 4);
        --v5;
      }
      while ( v5 > 0 );
    }
    *(_WORD *)a2 = v42;
    std__string__assign(a2 + 4, &v43);
    result = v43;
    _EDX = v43 - 12;
    if ( v43 - 12 != (_DWORD)std__string___Rep___S_empty_rep_storage )
    {
      if ( pthread_cancel )
      {
        _EAX = -1;
        __asm { lock xadd [edx+8], eax }
        v23 = result;
      }
      else
      {
        v23 = *(_DWORD *)(_EDX + 8);
        result = v23 - 1;
        *(_DWORD *)(_EDX + 8) = v23 - 1;
      }
      if ( v23 <= 0 )
        result = std__string___Rep___M_destroy(_EDX, &v50);
    }
    return result;
  }
  v9 = (v3 - *(_DWORD *)a1) >> 3;
  v10 = (v3 - *(_DWORD *)a1) >> 3;
  if ( !v9 )
    v10 = 1;
  v25 = __MKCADD__(v9, v10);
  v11 = v9 + v10;
  v44 = v11;
  if ( v25 || (unsigned int)v11 > 0x1FFFFFFF )
  {
    v44 = 536870911;
LABEL_43:
    v45 = operator new(a1, v11);
    goto LABEL_15;
  }
  v45 = 0;
  if ( v11 )
    goto LABEL_43;
LABEL_15:
  v46 = v45;
  v12 = *(_DWORD *)a1;
  v26 = *(_DWORD *)a1 == a2;
  v47 = v45;
  if ( !v26 )
  {
    v14 = v45;
    v13 = v45 + 8;
    do
    {
      if ( v14 )
      {
        *(_WORD *)v14 = *(_WORD *)v12;
        std__string__string(v14 + 4, v12 + 4);
      }
      v12 += 8;
      v14 = v13;
      v47 = v13;
      v13 += 8;
    }
    while ( a2 != v12 );
  }
  v46 = v47;
  if ( v47 )
  {
    v27 = a3;
    *(_WORD *)v47 = *(_WORD *)a3;
    std__string__string(v47 + 4, v27 + 4);
  }
  v15 = a2;
  v46 = v47 + 8;
  v28 = *(_DWORD *)(a1 + 4);
  v16 = v47 + 8;
  v48 = *(_DWORD *)(a1 + 4);
  if ( v28 != a2 )
  {
    v17 = a2;
    v18 = v47 + 16;
    do
    {
      if ( v16 )
      {
        *(_WORD *)v16 = *(_WORD *)v17;
        std__string__string(v16 + 4, v17 + 4);
      }
      v17 += 8;
      v16 = v18;
      v18 += 8;
    }
    while ( v48 != v17 );
    v41 = *(_DWORD *)(a1 + 4);
  }
  v20 = a1;
  v19 = v41;
  v21 = *(_DWORD *)a1;
  if ( *(_DWORD *)a1 != v41 )
  {
    do
    {
      v29 = *(_DWORD *)(v21 + 4);
      _EDX = v29 - 12;
      if ( std__string___Rep___S_empty_rep_storage != (char *)(v29 - 12) )
      {
        if ( pthread_cancel )
        {
          _EAX = -1;
          __asm { lock xadd [edx+8], eax }
          v15 = _EAX;
        }
        else
        {
          v15 = *(_DWORD *)(_EDX + 8);
          *(_DWORD *)(_EDX + 8) = v15 - 1;
        }
        if ( v15 <= 0 )
          std__string___Rep___M_destroy(_EDX, &v49);
      }
      v21 += 8;
    }
    while ( v21 != v41 );
    v20 = a1;
    v19 = *(_DWORD *)a1;
  }
  if ( v19 )
    operator delete(v15, v20);
  *(_DWORD *)a1 = v45;
  *(_DWORD *)(a1 + 4) = v16;
  result = v45 + 8 * v44;
  *(_DWORD *)(a1 + 8) = v45 + 8 * v44;
  return result;
}

//----- (0807E2A0) --------------------------------------------------------
int __cdecl sub_807E2A0(int a1, int a2)
{
  int v2; // edx@1
  int v3; // ecx@1
  int v4; // ebx@1
  int result; // eax@4

  v4 = a1;
  v3 = a2;
  v2 = *(_DWORD *)(a1 + 4);
  if ( v2 == *(_DWORD *)(a1 + 8) )
  {
    result = sub_807DEF0(a1, v2, a2);
  }
  else
  {
    if ( v2 )
    {
      *(_WORD *)v2 = *(_WORD *)a2;
      std__string__string(v2 + 4, v3 + 4);
      v2 = *(_DWORD *)(v4 + 4);
    }
    result = v2 + 8;
    *(_DWORD *)(v4 + 4) = v2 + 8;
  }
  return result;
}

//----- (0807E310) --------------------------------------------------------
void __cdecl sub_807E310()
{
  ;
}

//----- (0807E370) --------------------------------------------------------
int __cdecl sub_807E370(int a1, int a2, signed int a3, int a4, char a5)
{
  int result; // eax@1
  signed int v6; // ebx@1
  int v7; // esi@1
  int v8; // edi@2
  int v9; // edx@4
  int v10; // ecx@4
  int v11; // ebx@4
  int v12; // eax@7
  int v13; // edx@7
  int v14; // ebx@7
  int v15; // eax@10
  int v16; // edx@10
  int v17; // ebx@10
  int v18; // eax@13
  int v19; // edx@13
  int v20; // ebx@13
  int v21; // edx@23
  int v22; // ecx@23
  int v23; // ebx@23
  int v24; // eax@26
  int v25; // edx@26
  int v26; // ebx@26
  int v27; // edx@31
  int v28; // ecx@31
  int v29; // ebx@31
  int v30; // eax@34
  int v31; // edx@34
  int v32; // ebx@34
  int v33; // eax@37
  int v34; // edx@37
  int v35; // ebx@37
  int v36; // eax@4
  int v37; // edx@7
  int v38; // edx@10
  int v39; // edx@13
  int v40; // eax@16
  int v41; // edx@16
  int v42; // eax@23
  int v43; // edx@26
  int v44; // eax@29
  int v45; // edx@29
  int v46; // eax@31
  int v47; // edx@34
  int v48; // edx@37
  int v49; // eax@40
  int v50; // edx@40
  char v51; // [sp+19h] [bp-1Fh]@1
  signed int v52; // [sp+28h] [bp-10h]@2
  unsigned int v53; // [sp+20h] [bp-18h]@2
  unsigned int v54; // [sp+14h] [bp-24h]@2
  char v55; // [sp+26h] [bp-12h]@4
  char v56; // [sp+27h] [bp-11h]@7
  char v57; // [sp+1Eh] [bp-1Ah]@10
  char v58; // [sp+1Fh] [bp-19h]@13
  char v59; // [sp+1Ah] [bp-1Eh]@23
  char v60; // [sp+1Bh] [bp-1Dh]@26
  char v61; // [sp+25h] [bp-13h]@31
  char v62; // [sp+1Ch] [bp-1Ch]@34
  char v63; // [sp+1Dh] [bp-1Bh]@37

  v6 = a3;
  v7 = a4;
  v51 = a5;
  result = std__string__assign(a4, 134739702, 0);
  if ( v6 )
  {
    v8 = a2;
    v52 = v6;
    v53 = 0;
    v54 = v6 - 3 - 3 * (v6 - 1) / 3u;
    while ( 1 )
    {
      if ( v51 )
      {
        if ( v53 )
        {
          if ( !(v53 % 0x4C) )
            std__string__append(v7, 134739701, 1);
        }
      }
      if ( v52 == 1 )
      {
        v59 = (*off_8087240)[((signed int)*(_BYTE *)v8 >> 2) & 0x3F];
        v21 = *(_DWORD *)v7;
        v42 = *(_DWORD *)(*(_DWORD *)v7 - 12);
        v22 = *(_DWORD *)v7 - 12;
        v23 = v42 + 1;
        if ( (unsigned int)(v42 + 1) > *(_DWORD *)(v22 + 4) || *(_DWORD *)(v22 + 8) > 0 )
        {
          std__string__reserve(v7, v23);
          v21 = *(_DWORD *)v7;
        }
        *(_BYTE *)(v21 + *(_DWORD *)(v21 - 12)) = v59;
        v43 = *(_DWORD *)v7 - 12;
        *(_DWORD *)(*(_DWORD *)v7 - 12) = v23;
        *(_DWORD *)(v43 + 8) = 0;
        *(_BYTE *)(v43 + v23 + 12) = 0;
        v24 = *(_DWORD *)v7;
        v60 = (*off_8087240)[16 * *(_BYTE *)v8 & 0x30];
        v25 = *(_DWORD *)(v24 - 12);
        v26 = v25 + 1;
        if ( (unsigned int)(v25 + 1) > *(_DWORD *)(v24 - 12 + 4) || *(_DWORD *)(v24 - 12 + 8) > 0 )
        {
          std__string__reserve(v7, v25 + 1);
          v24 = *(_DWORD *)v7;
          v25 = *(_DWORD *)(*(_DWORD *)v7 - 12);
        }
        v8 += 3;
        *(_BYTE *)(v24 + v25) = v60;
        v44 = *(_DWORD *)v7;
        v45 = *(_DWORD *)v7 - 12;
        *(_DWORD *)(v45 + 8) = 0;
        *(_DWORD *)(v44 - 12) = v26;
        *(_BYTE *)(v45 + v26 + 12) = 0;
        std__string__append(v7, 134736743, 2);
        result = v54;
        v52 -= 3;
        if ( v52 == v54 )
          return result;
      }
      else
      {
        if ( v52 == 2 )
        {
          v61 = (*off_8087240)[((signed int)*(_BYTE *)v8 >> 2) & 0x3F];
          v27 = *(_DWORD *)v7;
          v46 = *(_DWORD *)(*(_DWORD *)v7 - 12);
          v28 = *(_DWORD *)v7 - 12;
          v29 = v46 + 1;
          if ( (unsigned int)(v46 + 1) > *(_DWORD *)(v28 + 4) || *(_DWORD *)(v28 + 8) > 0 )
          {
            std__string__reserve(v7, v29);
            v27 = *(_DWORD *)v7;
          }
          *(_BYTE *)(v27 + *(_DWORD *)(v27 - 12)) = v61;
          v47 = *(_DWORD *)v7 - 12;
          *(_DWORD *)(*(_DWORD *)v7 - 12) = v29;
          *(_DWORD *)(v47 + 8) = 0;
          *(_BYTE *)(v47 + v29 + 12) = 0;
          v30 = *(_DWORD *)v7;
          v62 = *(&(*off_8087240)[((signed int)*(_BYTE *)(v8 + 1) >> 4) & 0xF] + (16 * *(_BYTE *)v8 & 0x30));
          v31 = *(_DWORD *)(v30 - 12);
          v32 = v31 + 1;
          if ( (unsigned int)(v31 + 1) > *(_DWORD *)(v30 - 12 + 4) || *(_DWORD *)(v30 - 12 + 8) > 0 )
          {
            std__string__reserve(v7, v31 + 1);
            v30 = *(_DWORD *)v7;
            v31 = *(_DWORD *)(*(_DWORD *)v7 - 12);
          }
          *(_BYTE *)(v30 + v31) = v62;
          v48 = *(_DWORD *)v7 - 12;
          *(_DWORD *)(*(_DWORD *)v7 - 12) = v32;
          *(_DWORD *)(v48 + 8) = 0;
          *(_BYTE *)(v48 + v32 + 12) = 0;
          v33 = *(_DWORD *)v7;
          v63 = (*off_8087240)[4 * *(_BYTE *)(v8 + 1) & 0x3C];
          v34 = *(_DWORD *)(v33 - 12);
          v35 = v34 + 1;
          if ( (unsigned int)(v34 + 1) > *(_DWORD *)(v33 - 12 + 4) || *(_DWORD *)(v33 - 12 + 8) > 0 )
          {
            std__string__reserve(v7, v34 + 1);
            v33 = *(_DWORD *)v7;
            v34 = *(_DWORD *)(*(_DWORD *)v7 - 12);
          }
          *(_BYTE *)(v33 + v34) = v63;
          v49 = *(_DWORD *)v7;
          v50 = *(_DWORD *)v7 - 12;
          *(_DWORD *)(v50 + 8) = 0;
          *(_DWORD *)(v49 - 12) = v35;
          *(_BYTE *)(v50 + v35 + 12) = 0;
          std__string__append(v7, 134736744, 1);
        }
        else
        {
          v55 = (*off_8087240)[((signed int)*(_BYTE *)v8 >> 2) & 0x3F];
          v9 = *(_DWORD *)v7;
          v36 = *(_DWORD *)(*(_DWORD *)v7 - 12);
          v10 = *(_DWORD *)v7 - 12;
          v11 = v36 + 1;
          if ( (unsigned int)(v36 + 1) > *(_DWORD *)(v10 + 4) || *(_DWORD *)(v10 + 8) > 0 )
          {
            std__string__reserve(v7, v11);
            v9 = *(_DWORD *)v7;
          }
          *(_BYTE *)(v9 + *(_DWORD *)(v9 - 12)) = v55;
          v37 = *(_DWORD *)v7 - 12;
          *(_DWORD *)(*(_DWORD *)v7 - 12) = v11;
          *(_DWORD *)(v37 + 8) = 0;
          *(_BYTE *)(v37 + v11 + 12) = 0;
          v12 = *(_DWORD *)v7;
          v56 = *(&(*off_8087240)[((signed int)*(_BYTE *)(v8 + 1) >> 4) & 0xF] + (16 * *(_BYTE *)v8 & 0x30));
          v13 = *(_DWORD *)(v12 - 12);
          v14 = v13 + 1;
          if ( (unsigned int)(v13 + 1) > *(_DWORD *)(v12 - 12 + 4) || *(_DWORD *)(v12 - 12 + 8) > 0 )
          {
            std__string__reserve(v7, v13 + 1);
            v12 = *(_DWORD *)v7;
            v13 = *(_DWORD *)(*(_DWORD *)v7 - 12);
          }
          *(_BYTE *)(v12 + v13) = v56;
          v38 = *(_DWORD *)v7 - 12;
          *(_DWORD *)(*(_DWORD *)v7 - 12) = v14;
          *(_DWORD *)(v38 + 8) = 0;
          *(_BYTE *)(v38 + v14 + 12) = 0;
          v15 = *(_DWORD *)v7;
          v57 = *(&(*off_8087240)[((signed int)*(_BYTE *)(v8 + 2) >> 6) & 3] + (4 * *(_BYTE *)(v8 + 1) & 0x3C));
          v16 = *(_DWORD *)(v15 - 12);
          v17 = v16 + 1;
          if ( (unsigned int)(v16 + 1) > *(_DWORD *)(v15 - 12 + 4) || *(_DWORD *)(v15 - 12 + 8) > 0 )
          {
            std__string__reserve(v7, v16 + 1);
            v15 = *(_DWORD *)v7;
            v16 = *(_DWORD *)(*(_DWORD *)v7 - 12);
          }
          *(_BYTE *)(v15 + v16) = v57;
          v39 = *(_DWORD *)v7 - 12;
          *(_DWORD *)(*(_DWORD *)v7 - 12) = v17;
          *(_DWORD *)(v39 + 8) = 0;
          *(_BYTE *)(v39 + v17 + 12) = 0;
          v18 = *(_DWORD *)v7;
          v58 = (*off_8087240)[*(_BYTE *)(v8 + 2) & 0x3F];
          v19 = *(_DWORD *)(v18 - 12);
          v20 = v19 + 1;
          if ( (unsigned int)(v19 + 1) > *(_DWORD *)(v18 - 12 + 4) || *(_DWORD *)(v18 - 12 + 8) > 0 )
          {
            std__string__reserve(v7, v19 + 1);
            v18 = *(_DWORD *)v7;
            v19 = *(_DWORD *)(*(_DWORD *)v7 - 12);
          }
          *(_BYTE *)(v18 + v19) = v58;
          v40 = *(_DWORD *)v7;
          v41 = *(_DWORD *)v7 - 12;
          *(_DWORD *)(v41 + 8) = 0;
          *(_DWORD *)(v40 - 12) = v20;
          *(_BYTE *)(v41 + v20 + 12) = 0;
        }
        v52 -= 3;
        v8 += 3;
        result = v54;
        if ( v52 == v54 )
          return result;
      }
      v53 += 4;
    }
  }
  return result;
}

//----- (0807E820) --------------------------------------------------------
int __cdecl sub_807E820(int a1, int *a2, int *a3)
{
  int result; // eax@1
  unsigned int v4; // ebx@1
  int v5; // edx@2
  int v6; // ecx@2
  int v7; // eax@5
  int v8; // edx@5
  int v9; // ecx@5
  unsigned int v10; // edi@5
  int v11; // esi@5
  char v12; // dl@8
  int v13; // eax@9
  int v14; // edx@9
  int v15; // ecx@9
  char v16; // di@9
  int v17; // esi@9
  char v18; // dl@13
  int v19; // eax@14
  int v20; // edx@14
  int v21; // ecx@14
  char v22; // di@14
  int v23; // esi@14
  char v24; // al@5
  char v25; // cf@5
  unsigned __int8 v26; // zf@5
  int v27; // eax@8
  int v28; // edx@8
  int v29; // edx@12
  int v30; // edx@17
  unsigned int v31; // [sp+4Ch] [bp-1Ch]@1
  int v32; // [sp+28h] [bp-40h]@5
  char v33; // [sp+27h] [bp-41h]@5
  int v34; // [sp+1Ch] [bp-4Ch]@5
  int v35; // [sp+2Ch] [bp-3Ch]@8
  char v36; // [sp+30h] [bp-38h]@9
  char v37; // [sp+4Bh] [bp-1Dh]@14

  v4 = 0;
  v31 = *(_DWORD *)(*a2 - 12);
  result = std__string__assign(a3, 134739702, 0);
  if ( v31 > 0 )
  {
    do
    {
      v6 = *a2;
      v5 = *a2 + v4;
      while ( 1 )
      {
        result = *(_BYTE *)v5;
        if ( (_BYTE)result != 13 )
        {
          if ( (_BYTE)result != 10 )
            break;
        }
        ++v4;
        ++v5;
        if ( v4 >= v31 )
          return result;
      }
      v24 = byte_8087260[(char)result];
      v32 = v4 + 1;
      v33 = v24;
      v10 = byte_8087260[*(_BYTE *)(v6 + v4 + 1)];
      v8 = *a3;
      v9 = *(_DWORD *)(*a3 - 12);
      v7 = *a3 - 12;
      v11 = v9 + 1;
      v25 = (unsigned int)(v9 + 1) < *(_DWORD *)(v7 + 4);
      v26 = v9 + 1 == *(_DWORD *)(v7 + 4);
      v34 = *(_DWORD *)(*a3 - 12);
      if ( !(v25 | v26) || *(_DWORD *)(v7 + 8) > 0 )
      {
        std__string__reserve(a3, v9 + 1);
        v8 = *a3;
        v34 = *(_DWORD *)(*a3 - 12);
      }
      *(_BYTE *)(v8 + v34) = ((v10 >> 4) & 3) + 4 * v33;
      v27 = *a3;
      v28 = *a3 - 12;
      *(_DWORD *)(v28 + 8) = 0;
      *(_DWORD *)(v27 - 12) = v11;
      *(_BYTE *)(v28 + v11 + 12) = 0;
      v35 = v4 + 2;
      result = *a2;
      v12 = *(_BYTE *)(*a2 + v4 + 2);
      if ( v12 != 61 )
      {
        v16 = byte_8087260[*(_BYTE *)(result + v32)];
        v36 = byte_8087260[v12];
        v14 = *a3;
        v15 = *(_DWORD *)(*a3 - 12);
        v13 = *a3 - 12;
        v17 = v15 + 1;
        if ( (unsigned int)(v15 + 1) > *(_DWORD *)(v13 + 4) || *(_DWORD *)(v13 + 8) > 0 )
        {
          std__string__reserve(a3, v15 + 1);
          v14 = *a3;
          v15 = *(_DWORD *)(*a3 - 12);
        }
        *(_BYTE *)(v14 + v15) = 16 * v16 + (((unsigned int)(unsigned __int8)v36 >> 2) & 0xF);
        v29 = *a3 - 12;
        *(_DWORD *)(*a3 - 12) = v17;
        *(_DWORD *)(v29 + 8) = 0;
        *(_BYTE *)(v29 + v17 + 12) = 0;
        result = *a2;
      }
      v18 = *(_BYTE *)(result + v4 + 3);
      if ( v18 != 61 )
      {
        v22 = byte_8087260[*(_BYTE *)(result + v35)];
        v37 = byte_8087260[v18];
        v20 = *a3;
        v21 = *(_DWORD *)(*a3 - 12);
        v19 = *a3 - 12;
        v23 = v21 + 1;
        if ( (unsigned int)(v21 + 1) > *(_DWORD *)(v19 + 4) || *(_DWORD *)(v19 + 8) > 0 )
        {
          std__string__reserve(a3, v21 + 1);
          v20 = *a3;
          v21 = *(_DWORD *)(*a3 - 12);
        }
        *(_BYTE *)(v20 + v21) = v37 + (v22 << 6);
        result = *a3;
        v30 = *a3 - 12;
        *(_DWORD *)(v30 + 8) = 0;
        *(_DWORD *)(result - 12) = v23;
        *(_BYTE *)(v30 + v23 + 12) = 0;
      }
      v4 += 4;
    }
    while ( v31 > v4 );
  }
  return result;
}

//----- (0807EA30) --------------------------------------------------------
void __cdecl sub_807EA30()
{
  ;
}

//----- (0807EA40) --------------------------------------------------------
signed int __fastcall sub_807EA40(int a1, int a2, int a3, int a4, int a5)
{
  init_proc(a1);
  return 134770403;
}

//----- (0807EA9A) --------------------------------------------------------
void __cdecl sub_807EA9A()
{
  ;
}

//----- (0807EAA0) --------------------------------------------------------
int (*__cdecl sub_807EAA0())()
{
  int (*result)(); // eax@1
  int (**v1)(); // ebx@2

  result = off_8086EEC;
  if ( off_8086EEC != (int (*)())-1 )
  {
    v1 = &off_8086EEC;
    do
    {
      --v1;
      result();
      result = *v1;
    }
    while ( *v1 != (int (*)())-1 );
  }
  return result;
}

//----- (0807EACC) --------------------------------------------------------
void __cdecl term_proc()
{
  sub_804A5D0();
}

#error "There were 14 decompilation failure(s) on 335 function(s)"
