decompiled_code:
int tty_raw()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, &v1);
v1.c_lflag &= 0xFFFFFFF5;
return tcsetattr(0, 0, &v1);
}

canonical_decompiled_code:
int func16()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, &v1);
v1.c_lflag &= 0xFFFFFFF5;
return tcsetattr(0, 0, &v1);
}

original_code:
void tty_raw() {
    struct termios newt;
    tcgetattr(0, &newt);
    newt.c_lflag &= ~(0000002 | 0000010);
    tcsetattr(0, 0, &newt);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


repo: TacOS-team/ted

decompiled_code:
int tty_update_winsize()
{
return ioctl(1, 0x5413uLL, &ws);
}

canonical_decompiled_code:
int func17()
{
return ioctl(1, 0x5413uLL, &ws);
}

original_code:
void tty_update_winsize() {
 ioctl(1, 0x5413, &ws);
}

return_type: void


decompiled_code:
__int64 tty_col()
{
return (unsigned __int16)word_4040C2;
}

canonical_decompiled_code:
__int64 func18()
{
return (unsigned __int16)word_4040C2;
}

original_code:
unsigned int tty_col() {
 return ws.ws_col;
}

return_type: unsigned int


decompiled_code:
__int64 tty_row()
{
return (unsigned __int16)ws;
}

canonical_decompiled_code:
__int64 func19()
{
return (unsigned __int16)ws;
}

original_code:
unsigned int tty_row() {
 return ws.ws_row;
}


decompiled_code:
int clear_screen()
{
printf("\x1B[2J");
return fflush(stdout);
}

canonical_decompiled_code:
int func20()
{
printf("\x1B[2J");
return fflush(stdout);
}

original_code:
void clear_screen() {
    printf("\033[2J");
    fflush(stdout);
}


clientServerInteraction

repo: TarasDumin/ServerHttp

decompiled_code:
__int64 __fastcall clientServerInteraction(int fd)
{
__int64 v2; // rbx
__int64 v3; // rbp
int v4; // eax
unsigned int v5; // er12
int v7; // er14
_QWORD *v8; // rax
void *v9; // rdi
char v10[256]; // [rsp-100h] [rbp-2928h] BYREF
__int128 v11; // [rsp+0h] [rbp-2828h] BYREF
char s[10224]; // [rsp+10h] [rbp-2818h] BYREF

v11 = 0LL;
memset(s, 0, sizeof(s));
sprintf(v10, "start | Deskription: %d\n", (unsigned int)fd);
writeLog("Server.c", "clientServerInteraction", 21LL, v10);
while ( 1 )
{
v2 = createRequestObject();
v3 = getTimeS();
while ( 1 )
{
v4 = readWithTimeOut((unsigned int)fd, &v11, 10240LL, *(unsigned int *)(v2 + 16));
v5 = v4;
if ( v4 <= 0 )
break;
if ( *(_DWORD *)(v2 + 56) != 200 || !(unsigned int)parseParameters(v2, &v11, (unsigned int)v4) || v5 != 10239 )
goto LABEL_16;
}
if ( v4 == -1 || v4 != -2 )
{
LABEL_16:
(*(void (__fastcall **)(__int64, _QWORD))(v2 + 72))(v2, (unsigned int)fd);
if ( !(unsigned int)isUseInLog("HTTPStatus:") )
{
LABEL_10:
if ( !(unsigned int)isUseInLog("Date:") )
goto LABEL_11;
goto LABEL_18;
}
}
else if ( !(unsigned int)isUseInLog("HTTPStatus:") )
{
goto LABEL_10;
}
v7 = *(_DWORD *)(v2 + 56);
*(_DWORD *)(getLogeW3CLog() + 88) = v7;
if ( !(unsigned int)isUseInLog("Date:") )
goto LABEL_11;
LABEL_18:
v8 = (_QWORD *)getLogeW3CLog();
if ( !(unsigned int)isEmptyLogDate(*v8) )
{
v9 = *(void **)getLogeW3CLog();
free(v9);
}
*(_QWORD *)getLogeW3CLog() = v3;
LABEL_11:
deleteRequest(v2);
if ( v5 == -2 )
break;
writeInLogFile();
clearW3CLog();
if ( !*(_DWORD *)(v2 + 12) )
goto LABEL_13;
}
clearW3CLog();
LABEL_13:
close(fd);
sprintf(v10, "End | Deskription: %d | result: %d\n", (unsigned int)fd, v5);
writeLog("Server.c", "clientServerInteraction", 78LL, v10);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
__int64 v2; // rbx
__int64 v3; // rbp
int v4; // eax
unsigned int v5; // er12
int v7; // er14
_QWORD *v8; // rax
void *v9; // rdi
char v10[256]; // [rsp-100h] [rbp-2928h] BYREF
__int128 v11; // [rsp+0h] [rbp-2828h] BYREF
char s[10224]; // [rsp+10h] [rbp-2818h] BYREF

v11 = 0LL;
memset(s, 0, sizeof(s));
sprintf(v10, "start | Deskription: %d\n", (unsigned int)fd);
writeLog("Server.c", "clientServerInteraction", 21LL, v10);
while ( 1 )
{
v2 = createRequestObject();
v3 = getTimeS();
while ( 1 )
{
v4 = readWithTimeOut((unsigned int)fd, &v11, 10240LL, *(unsigned int *)(v2 + 16));
v5 = v4;
if ( v4 <= 0 )
break;
if ( *(_DWORD *)(v2 + 56) != 200 || !(unsigned int)parseParameters(v2, &v11, (unsigned int)v4) || v5 != 10239 )
goto LABEL_16;
}
if ( v4 == -1 || v4 != -2 )
{
LABEL_16:
(*(void (__fastcall **)(__int64, _QWORD))(v2 + 72))(v2, (unsigned int)fd);
if ( !(unsigned int)isUseInLog("HTTPStatus:") )
{
LABEL_10:
if ( !(unsigned int)isUseInLog("Date:") )
goto LABEL_11;
goto LABEL_18;
}
}
else if ( !(unsigned int)isUseInLog("HTTPStatus:") )
{
goto LABEL_10;
}
v7 = *(_DWORD *)(v2 + 56);
*(_DWORD *)(getLogeW3CLog() + 88) = v7;
if ( !(unsigned int)isUseInLog("Date:") )
goto LABEL_11;
LABEL_18:
v8 = (_QWORD *)getLogeW3CLog();
if ( !(unsigned int)isEmptyLogDate(*v8) )
{
v9 = *(void **)getLogeW3CLog();
free(v9);
}
*(_QWORD *)getLogeW3CLog() = v3;
LABEL_11:
deleteRequest(v2);
if ( v5 == -2 )
break;
writeInLogFile();
clearW3CLog();
if ( !*(_DWORD *)(v2 + 12) )
goto LABEL_13;
}
clearW3CLog();
LABEL_13:
close(fd);
sprintf(v10, "End | Deskription: %d | result: %d\n", (unsigned int)fd, v5);
writeLog("Server.c", "clientServerInteraction", 78LL, v10);
return v5;
}

original_code:
int clientServerInteraction(int deskription)
{
    HTTP_REQUEST *currentReq;
    char message[(10240)] = {0};
    char* time = ((void *)0);
    int result;
    { char buffer[256]; sprintf(buffer, "start | Deskription: %d\n", deskription); writeLog("Server.c", __func__, 21, buffer); };
    do
    {
        currentReq = createRequestObject();
        time = getTimeS();
        do
        {
            result = readWithTimeOut(deskription, message, (10240), currentReq->timeOfKeapAlive);
            if(result > 0)
            {
                if((HTTP_200_OK != currentReq->status) ||
                   (!parseParameters(currentReq, message, result)))
                {
                    break;
                }
            }
            else if(result == (-1))
            {
                break;
            }
        }while(result == (10240) - 1 &&
               result != (-2));
        if(result != (-2))
        {
            currentReq->MethodHTTP(currentReq, deskription);
        }
        if(isUseInLog("HTTPStatus:"))
        {
            getLogeW3CLog()->HTTPStatus = currentReq->status;
        }
        if(isUseInLog("Date:"))
        {
            if(!isEmptyLogDate(getLogeW3CLog()->Date))
            {
                free(getLogeW3CLog()->Date);
            }
            getLogeW3CLog()->Date = time;
        }
        deleteRequest(currentReq);
        if(result != (-2))
        {
            writeInLogFile();
        }
        clearW3CLog();
    }while(result != (-2) &&
           currentReq->isKeapAliveUsing);
    close(deskription);
    { char buffer[256]; sprintf(buffer, "End | Deskription: %d | result: %d\n", deskription, result); writeLog("Server.c", __func__, 78, buffer); };
    return result;
}

canonical_original_code:
int clientServerInteraction(int deskription)
{
    struct _REQUEST *currentReq;
    char message[-1] = {0};
    char *time = ((void *)0);
    int result;
    { char buffer[256]; sprintf(buffer, "start | Deskription: %d\n", deskription); writeLog("Server.c", __func__, 21, buffer); };
    do
    {
        currentReq = createRequestObject();
        time = getTimeS();
        do
        {
            result = readWithTimeOut(deskription, message, (10240), currentReq->timeOfKeapAlive);
            if(result > 0)
            {
                if((HTTP_200_OK != currentReq->status) ||
                   (!parseParameters(currentReq, message, result)))
                {
                    break;
                }
            }
            else if(result == (-1))
            {
                break;
            }
        }while(result == (10240) - 1 &&
               result != (-2));
        if(result != (-2))
        {
            currentReq->MethodHTTP(currentReq, deskription);
        }
        if(isUseInLog("HTTPStatus:"))
        {
            getLogeW3CLog()->HTTPStatus = currentReq->status;
        }
        if(isUseInLog("Date:"))
        {
            if(!isEmptyLogDate(getLogeW3CLog()->Date))
            {
                free(getLogeW3CLog()->Date);
            }
            getLogeW3CLog()->Date = time;
        }
        deleteRequest(currentReq);
        if(result != (-2))
        {
            writeInLogFile();
        }
        clearW3CLog();
    }while(result != (-2) &&
           currentReq->isKeapAliveUsing);
    close(deskription);
    { char buffer[256]; sprintf(buffer, "End | Deskription: %d | result: %d\n", deskription, result); writeLog("Server.c", __func__, 78, buffer); };
    return result;
}

variable_types: deskription int

variable_types: struct _REQUEST { enum _HTTP_METHOD_ { HTTP_GET=0, HTTP_HEAD=1, HTTP_POST=2, HTTP_PUT=3, HTTP_DELETE=4, HTTP_OPTIONS=5, HTTP_TRACE=6, HTTP_CONNECT=7, HTTP_PATCH=8, HTTP_EXTENSION_METHOD=9 } method; enum VERSION { HTTP_1_0=0, HTTP_1_1=1, UNDEFINED_HTTP=2 } version; enum _YES_NO_QUESTION_ { NO_Q=0, YES_Q=1 } isChunkUsing; enum _YES_NO_QUESTION_ { NO_Q=0, YES_Q=1 } isKeapAliveUsing; int timeOfKeapAlive; int lenResponse; int lenURI; int lenBodyResponse; char *header; char *URI; char *body; enum STATUS { HTTP_100_CONTINUE=100, HTTP_101_SWITCHING=101, HTTP_102_PROCESSING=102, HTTP_200_OK=200, HTTP_201_Created=201, HTTP_202_Accepted=202, HTTP_203_NON_AUTHORITATIVE_INFORMATION=203, HTTP_204_NO_CONTENT=204, HTTP_206_PARTUAL_CONTENT=206, HTTP_207_MULTY_STATUS=207, HTTP_208_ALREADY_REPORTED=208, HTTP_300_MULTIPLE_CHOICES=300, HTTP_301_MOVED_PERMANENTLY=301, HTTP_302_FOUND=302, HTTP_303_SEE_OTHER=303, HTTP_304_NOT_MODIFFED=304, HTTP_305_USE_PROXY=305, HTTP_307_TEMPORARY_REDIRECT=306, HTTP_400_BAD_REQUEST=400, HTTP_401_UNAUTHORIZED=401, HTTP_402_PAYMENT_REQUIRED=402, HTTP_403_FORBIDDEN=403, HTTP_404_NOT_FOUND=404, HTTP_405_METHOD_NOT_ALLOWED=405, HTTP_406_NOT_ACCEPTABLE=406, HTTP_407_PROXY_AUTHENTICATION_REQUIRED=407, HTTP_408_REQUEST_TIMEOUT=408, HTTP_409_CONICT=409, HTTP_410_GONE=410, HTTP_411_LENGTH_REQUIRED=411, HTTP_412_PRECONDITION_FAILED=412, HTTP_413_REQUEST_ENTITY_TOO_LARGE=413, HTTP_414_REQUEST_URI_TOO_LONG=414, HTTP_415_UNSUPPORTED_MEDIA_TYPE=415, HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE=416, HTTP_417_EXPECTATION_FAILED=417, HTTP_418_IM_TEAPOT=418, HTTP_420_ENHANCE_YOUR_CALM=420, HTTP_422_UNPROCESSABLE_ENTITY=422, HTTP_423_LOCKED=423, HTTP_424_FAILED_DEPENDENCY=424, HTTP_429_TOO_MANY_REQUESTS=429, HTTP_431_REQUEST_HEADER_FIELDS_TOO_LARGE=431, HTTP_444_NO_RESPONSE=444, HTTP_449_RETRY_WITH=449, HTTP_450_BLOCKED_BY_WINDOWS=450, HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS=451, HTTP_500_INTERNAL_SERVER_ERROR=500, HTTP_501_NOT_IMPLEMENTED=501, HTTP_502_BAD_GATEWAY=502, HTTP_503_SERVICE_UNAVAILABLE=503, HTTP_504_GATEWAY_TIMEOUT=504, HTTP_505_HTTP_VERSION_NOT_SUPPORTED=505, HTTP_507_INSUFFCIENT_STORAGE=507, HTTP_508_LOOP_DETECTED=508, HTTP_509_BANDWIDTH_LIMIT_EXCEEDED=509 } status; void (*getMethodHTTP)(struct _REQUEST *, char *); void (*MethodHTTP)(struct _REQUEST *, int); } *

variable_types:
message
char [-1]

variable_types:
time
char *

variable_types: result int

variable_types:
buffer
char [256]

return_type: int

user_defined_types: struct _REQUEST { enum _HTTP_METHOD_ method; enum VERSION version; enum _YES_NO_QUESTION_ isChunkUsing; enum _YES_NO_QUESTION_ isKeapAliveUsing; int timeOfKeapAlive; int lenResponse; int lenURI; int lenBodyResponse; char *header; char *URI; char *body; enum STATUS status; void (*getMethodHTTP)(struct _REQUEST *, char *); void (*MethodHTTP)(struct _REQUEST *, int); }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // er12
int v5; // eax
int v6; // ebp
__pid_t v7; // eax
char v9[280]; // [rsp+0h] [rbp-118h] BYREF

initW3CLog(argc, argv, envp);
startDebug();
puts("Server is working now");
sprintf(v9, "Server is working now %s", (const char *)&unk_233);
writeLog("Server.c", "main", 93LL, v9);
v3 = connectToSocket();
if ( v3 == -1 )
LABEL_16:
exit(1);
v4 = v3;
while ( 1 )
{
if ( !(unsigned int)checkExit() )
{
LABEL_13:
puts("Server is stopped");
close(v4);
endDebug();
sprintf(v9, "Server is stoped%s", (const char *)&unk_233);
writeLog("Server.c", "main", 146LL, v9);
return 0;
}
v5 = acceptWithLogger(v4);
v6 = v5;
if ( v5 != -2 )
break;
LABEL_11:
if ( signal(2, (__sighandler_t)&sig_handler) == (__sighandler_t)-1LL )
{
sprintf(v9, "Error. can't catch SIGINT%s\n", " ");
writeLog("Server.c", "main", 129LL, v9);
if ( (int)doesServerHaveToWorkCommand() > 0 )
goto LABEL_13;
}
else if ( (int)doesServerHaveToWorkCommand() > 0 )
{
goto LABEL_13;
}
if ( (int)doesServerHaveToWorkConfig() > 0 )
goto LABEL_13;
}
if ( v5 == -1 )
goto LABEL_16;
v7 = fork();
if ( v7 < 0 )
{
sprintf(v9, "Error. Fork was failed%s\n", " ");
writeLog("Server.c", "main", 113LL, v9);
goto LABEL_16;
}
if ( !v7 )
{
close(v6);
goto LABEL_11;
}
close(v4);
if ( (unsigned int)clientServerInteraction(v6) == -1 )
goto LABEL_16;
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // er12
int v5; // eax
int v6; // ebp
__pid_t v7; // eax
char v9[280]; // [rsp+0h] [rbp-118h] BYREF

initW3CLog(argc, argv, envp);
startDebug();
puts("Server is working now");
sprintf(v9, "Server is working now %s", (const char *)&unk_233);
writeLog("Server.c", "main", 93LL, v9);
v3 = connectToSocket();
if ( v3 == -1 )
LABEL_16:
exit(1);
v4 = v3;
while ( 1 )
{
if ( !(unsigned int)checkExit() )
{
LABEL_13:
puts("Server is stopped");
close(v4);
endDebug();
sprintf(v9, "Server is stoped%s", (const char *)&unk_233);
writeLog("Server.c", "main", 146LL, v9);
return 0;
}
v5 = acceptWithLogger(v4);
v6 = v5;
if ( v5 != -2 )
break;
LABEL_11:
if ( signal(2, (__sighandler_t)&sig_handler) == (__sighandler_t)-1LL )
{
sprintf(v9, "Error. can't catch SIGINT%s\n", " ");
writeLog("Server.c", "main", 129LL, v9);
if ( (int)doesServerHaveToWorkCommand() > 0 )
goto LABEL_13;
}
else if ( (int)doesServerHaveToWorkCommand() > 0 )
{
goto LABEL_13;
}
if ( (int)doesServerHaveToWorkConfig() > 0 )
goto LABEL_13;
}
if ( v5 == -1 )
goto LABEL_16;
v7 = fork();
if ( v7 < 0 )
{
sprintf(v9, "Error. Fork was failed%s\n", " ");
writeLog("Server.c", "main", 113LL, v9);
goto LABEL_16;
}
if ( !v7 )
{
close(v6);
goto LABEL_11;
}
close(v4);
if ( (unsigned int)func0(v6) == -1 )
goto LABEL_16;
return 0;
}

original_code:
int main(void)
{
    int deskriptionS = 0, deskriptionC = 0;
    int pid = 0;
    initW3CLog();
    startDebug();
    printf("Server is working now\n");
    { char buffer[256]; sprintf(buffer, "Server is working now %s", ""); writeLog("Server.c", __func__, 93, buffer); };
    deskriptionS = connectToSocket();
    if(deskriptionS == (-1))
    {
        exit(1);
    }
    while(checkExit())
    {
        deskriptionC = acceptWithLogger(deskriptionS);
        if(deskriptionC != (-2))
        {
            if(deskriptionC == (-1))
            {
                exit(1);
            }
            pid = fork();
            if (pid < 0)
            {
                { char buffer[256]; sprintf(buffer, "Error. Fork was failed%s\n", " "); writeLog("Server.c", __func__, 113, buffer); };
         exit(1);
            }
            if(pid != 0)
            {
                close(deskriptionS);
                if(clientServerInteraction(deskriptionC) == (-1))
                {
                    exit(1);
                }
                return (0);
            }
            close(deskriptionC);
        }
        if (signal(2, sig_handler) == ((__sighandler_t) -1))
        {
            { char buffer[256]; sprintf(buffer, "Error. can't catch SIGINT%s\n", " "); writeLog("Server.c", __func__, 129, buffer); };
        }
        if(doesServerHaveToWorkCommand() > 0)
        {
            break;
        }
        if(doesServerHaveToWorkConfig() > 0)
 {
            break;
 }
    }
    if(pid == 0)
    {
        printf("Server is stopped\n");
        close(deskriptionS);
        endDebug();
        { char buffer[256]; sprintf(buffer, "Server is stoped%s", ""); writeLog("Server.c", __func__, 146, buffer); };
    }
    return (0);
}

canonical_original_code:
int main()
{
    int deskriptionS = 0; int deskriptionC = 0;
    int pid = 0;
    initW3CLog();
    startDebug();
    printf("Server is working now\n");
    { char buffer[256]; sprintf(buffer, "Server is working now %s", ""); writeLog("Server.c", __func__, 93, buffer); };
    deskriptionS = connectToSocket();
    if(deskriptionS == (-1))
    {
        exit(1);
    }
    while(checkExit())
    {
        deskriptionC = acceptWithLogger(deskriptionS);
        if(deskriptionC != (-2))
        {
            if(deskriptionC == (-1))
            {
                exit(1);
            }
            pid = fork();
            if (pid < 0)
            {
                { char buffer[256]; sprintf(buffer, "Error. Fork was failed%s\n", " "); writeLog("Server.c", __func__, 113, buffer); };
         exit(1);
            }
            if(pid != 0)
            {
                close(deskriptionS);
                if(clientServerInteraction(deskriptionC) == (-1))
                {
                    exit(1);
                }
                return (0);
            }
            close(deskriptionC);
        }
        if (signal(2, sig_handler) == ((__sighandler_t) -1))
        {
            { char buffer[256]; sprintf(buffer, "Error. can't catch SIGINT%s\n", " "); writeLog("Server.c", __func__, 129, buffer); };
        }
        if(doesServerHaveToWorkCommand() > 0)
        {
            break;
        }
        if(doesServerHaveToWorkConfig() > 0)
 {
            break;
 }
    }
    if(pid == 0)
    {
        printf("Server is stopped\n");
        close(deskriptionS);
        endDebug();
        { char buffer[256]; sprintf(buffer, "Server is stoped%s", ""); writeLog("Server.c", __func__, 146, buffer); };
    }
    return (0);
}

variable_types: deskriptionS int

variable_types: deskriptionC int

variable_types: pid int


checkExistenceSpecifiedAddr

decompiled_code:
__int64 __fastcall checkExistenceSpecifiedAddr(void *s2)
{
struct ifaddrs *v2; // rbp
unsigned int v3; // er12
struct sockaddr *v4; // rsi
int v5; // edi
unsigned __int16 *v6; // rax
unsigned __int16 *v7; // rsi
size_t v8; // rax
struct ifaddrs *ifap; // [rsp+8h] [rbp-150h] BYREF
char buf[48]; // [rsp+10h] [rbp-148h] BYREF
char s[280]; // [rsp+40h] [rbp-118h] BYREF

ifap = 0LL;
sprintf(s, "Start | IPadd: %p\n", s2);
writeLog("workWithSockets.c", "checkExistenceSpecifiedAddr", 32LL, s);
if ( getifaddrs(&ifap) )
{
sprintf(s, "Error. getifaddrs was failed%s\n", (const char *)&unk_8D5);
v3 = -1;
writeLog("workWithSockets.c", "checkExistenceSpecifiedAddr", 62LL, s);
}
else
{
v2 = ifap;
v3 = 0;
if ( ifap )
{
while ( 1 )
{
v4 = v2->ifa_addr;
v5 = v4->sa_family;
v6 = (unsigned __int16 *)&v4->sa_data[2];
v7 = (unsigned __int16 *)&v4->sa_data[6];
if ( (_WORD)v5 == 2 )
v7 = v6;
if ( inet_ntop(v5, v7, buf, 0x2Eu) )
{
v8 = strlen(buf);
if ( !memcmp(buf, s2, v8) )
break;
}
v2 = v2->ifa_next;
if ( !v2 )
{
v2 = ifap;
goto LABEL_9;
}
}
v2 = ifap;
v3 = 1;
}
LABEL_9:
freeifaddrs(v2);
ifap = 0LL;
}
sprintf(s, "End | result: %d\n", v3);
writeLog("workWithSockets.c", "checkExistenceSpecifiedAddr", 66LL, s);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *s2)
{
struct ifaddrs *v2; // rbp
unsigned int v3; // er12
struct sockaddr *v4; // rsi
int v5; // edi
unsigned __int16 *v6; // rax
unsigned __int16 *v7; // rsi
size_t v8; // rax
struct ifaddrs *ifap; // [rsp+8h] [rbp-150h] BYREF
char buf[48]; // [rsp+10h] [rbp-148h] BYREF
char s[280]; // [rsp+40h] [rbp-118h] BYREF

ifap = 0LL;
sprintf(s, "Start | IPadd: %p\n", s2);
writeLog("workWithSockets.c", "checkExistenceSpecifiedAddr", 32LL, s);
if ( getifaddrs(&ifap) )
{
sprintf(s, "Error. getifaddrs was failed%s\n", (const char *)&unk_8D5);
v3 = -1;
writeLog("workWithSockets.c", "checkExistenceSpecifiedAddr", 62LL, s);
}
else
{
v2 = ifap;
v3 = 0;
if ( ifap )
{
while ( 1 )
{
v4 = v2->ifa_addr;
v5 = v4->sa_family;
v6 = (unsigned __int16 *)&v4->sa_data[2];
v7 = (unsigned __int16 *)&v4->sa_data[6];
if ( (_WORD)v5 == 2 )
v7 = v6;
if ( inet_ntop(v5, v7, buf, 0x2Eu) )
{
v8 = strlen(buf);
if ( !memcmp(buf, s2, v8) )
break;
}
v2 = v2->ifa_next;
if ( !v2 )
{
v2 = ifap;
goto LABEL_9;
}
}
v2 = ifap;
v3 = 1;
}
LABEL_9:
freeifaddrs(v2);
ifap = 0LL;
}
sprintf(s, "End | result: %d\n", v3);
writeLog("workWithSockets.c", "checkExistenceSpecifiedAddr", 66LL, s);
return v3;
}

original_code:
int checkExistenceSpecifiedAddr(char *IPadd)
{
    struct ifaddrs *interfaceArray = ((void *)0), *tempIfAddr = ((void *)0);
    void *tempAddrPtr = ((void *)0);
    char addressOutputBuffer[46];
    int result;
    { char buffer[256]; sprintf(buffer, "Start | IPadd: %p\n", IPadd); writeLog("workWithSockets.c", __func__, 32, buffer); };
    if (!getifaddrs(&interfaceArray))
    {
        for(tempIfAddr = interfaceArray; tempIfAddr != ((void *)0); tempIfAddr = tempIfAddr->ifa_next)
        {
            if(tempIfAddr->ifa_addr->sa_family == 2)
            {
                tempAddrPtr = &((struct sockaddr_in *)tempIfAddr->ifa_addr)->sin_addr;
            }
            else
            {
                tempAddrPtr = &((struct sockaddr_in6 *)tempIfAddr->ifa_addr)->sin6_addr;
            }
            if(inet_ntop(tempIfAddr->ifa_addr->sa_family, tempAddrPtr, addressOutputBuffer, sizeof(addressOutputBuffer)))
            {
                if(!memcmp(addressOutputBuffer, IPadd, strlen(addressOutputBuffer)))
                {
                     result = (1);
                     break;
                }
            }
            result = (0);
        }
        freeifaddrs(interfaceArray);
        interfaceArray = ((void *)0);
    }
    else
    {
        { char buffer[256]; sprintf(buffer, "Error.  getifaddrs was failed%s\n", ""); writeLog("workWithSockets.c", __func__, 62, buffer); };
        result = (-1);
    }
    { char buffer[256]; sprintf(buffer, "End | result: %d\n", result); writeLog("workWithSockets.c", __func__, 66, buffer); };
    return result;
}

canonical_original_code:
int checkExistenceSpecifiedAddr(char *IPadd)
{
    struct ifaddrs *interfaceArray = ((void *)0); struct ifaddrs *tempIfAddr = ((void *)0);
    void *tempAddrPtr = ((void *)0);
    char addressOutputBuffer[46];
    int result;
    { char buffer[256]; sprintf(buffer, "Start | IPadd: %p\n", IPadd); writeLog("workWithSockets.c", __func__, 32, buffer); };
    if (!getifaddrs(&interfaceArray))
    {
        for(tempIfAddr = interfaceArray; tempIfAddr != ((void *)0); tempIfAddr = tempIfAddr->ifa_next)
        {
            if(tempIfAddr->ifa_addr->sa_family == 2)
            {
                tempAddrPtr = &((struct sockaddr_in *)tempIfAddr->ifa_addr)->sin_addr;
            }
            else
            {
                tempAddrPtr = &((struct sockaddr_in6 *)tempIfAddr->ifa_addr)->sin6_addr;
            }
            if(inet_ntop(tempIfAddr->ifa_addr->sa_family, tempAddrPtr, addressOutputBuffer, sizeof(addressOutputBuffer)))
            {
                if(!memcmp(addressOutputBuffer, IPadd, strlen(addressOutputBuffer)))
                {
                     result = (1);
                     break;
                }
            }
            result = (0);
        }
        freeifaddrs(interfaceArray);
        interfaceArray = ((void *)0);
    }
    else
    {
        { char buffer[256]; sprintf(buffer, "Error.  getifaddrs was failed%s\n", ""); writeLog("workWithSockets.c", __func__, 62, buffer); };
        result = (-1);
    }
    { char buffer[256]; sprintf(buffer, "End | result: %d\n", result); writeLog("workWithSockets.c", __func__, 66, buffer); };
    return result;
}

variable_types:
IPadd
char *

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

variable_types:
tempAddrPtr
void *

variable_types:
addressOutputBuffer
char [46]

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


connectToSocket

decompiled_code:
__int64 connectToSocket()
{
unsigned int v0; // er12
int v1; // edx
const void *v2; // rcx
socklen_t v3; // er8
int v5; // [rsp+8h] [rbp-140h] BYREF
int n; // [rsp+Ch] [rbp-13Ch] BYREF
char cp[48]; // [rsp+10h] [rbp-138h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

v5 = 80;
n = 5;
sprintf(s, "Start | %s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "connectToSocket", 81LL, s);
getValueForKeyNumber("config.txt", "Port to listen:", &v5);
v0 = socket(2, 1, 0);
socketADD = 0LL;
socketADD.sa_family = 2;
if ( (unsigned int)getValueForKeyString("config.txt", "Is used IP address:", cp) == 1
&& (unsigned int)checkExistenceSpecifiedAddr(cp) == 1 )
{
*(_DWORD *)&socketADD.sa_data[2] = inet_addr(cp);
}
else
{
*(_DWORD *)&socketADD.sa_data[2] = 0;
}
*(_WORD *)socketADD.sa_data = _bswap_16(v5);
if ( setsockopt(v0, 1, v1, v2, v3) == -1 )
{
sprintf(s, "Error. Setsockopt was failing. | result: %d\n", 0xFFFFFFFFLL);
v0 = -1;
writeLog("workWithSockets.c", "connectToSocket", 103LL, s);
}
else if ( bind(v0, &socketADD, 0x10u) == -1 )
{
sprintf(s, "Error. Bind was failing. | result: %d\n", 0xFFFFFFFFLL);
v0 = -1;
writeLog("workWithSockets.c", "connectToSocket", 110LL, s);
}
else
{
getValueForKeyNumber("config.txt", "Max number of connect:", &n);
if ( listen(v0, n) == -1 )
{
sprintf(s, "Error. listen was failing. | result: %d\n", 0xFFFFFFFFLL);
v0 = -1;
writeLog("workWithSockets.c", "connectToSocket", 119LL, s);
}
else
{
sprintf(s, "End | Server is working now. | deskription: %d\n", v0);
writeLog("workWithSockets.c", "connectToSocket", 123LL, s);
}
}
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // er12
int v1; // edx
const void *v2; // rcx
socklen_t v3; // er8
int v5; // [rsp+8h] [rbp-140h] BYREF
int n; // [rsp+Ch] [rbp-13Ch] BYREF
char cp[48]; // [rsp+10h] [rbp-138h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

v5 = 80;
n = 5;
sprintf(s, "Start | %s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "connectToSocket", 81LL, s);
getValueForKeyNumber("config.txt", "Port to listen:", &v5);
v0 = socket(2, 1, 0);
socketADD = 0LL;
socketADD.sa_family = 2;
if ( (unsigned int)getValueForKeyString("config.txt", "Is used IP address:", cp) == 1
&& (unsigned int)func1(cp) == 1 )
{
*(_DWORD *)&socketADD.sa_data[2] = inet_addr(cp);
}
else
{
*(_DWORD *)&socketADD.sa_data[2] = 0;
}
*(_WORD *)socketADD.sa_data = func0(v5);
if ( setsockopt(v0, 1, v1, v2, v3) == -1 )
{
sprintf(s, "Error. Setsockopt was failing. | result: %d\n", 0xFFFFFFFFLL);
v0 = -1;
writeLog("workWithSockets.c", "connectToSocket", 103LL, s);
}
else if ( bind(v0, &socketADD, 0x10u) == -1 )
{
sprintf(s, "Error. Bind was failing. | result: %d\n", 0xFFFFFFFFLL);
v0 = -1;
writeLog("workWithSockets.c", "connectToSocket", 110LL, s);
}
else
{
getValueForKeyNumber("config.txt", "Max number of connect:", &n);
if ( listen(v0, n) == -1 )
{
sprintf(s, "Error. listen was failing. | result: %d\n", 0xFFFFFFFFLL);
v0 = -1;
writeLog("workWithSockets.c", "connectToSocket", 119LL, s);
}
else
{
sprintf(s, "End | Server is working now. | deskription: %d\n", v0);
writeLog("workWithSockets.c", "connectToSocket", 123LL, s);
}
}
return v0;
}

original_code:
int connectToSocket(void)
{
    int yes = 1;
    int deskription = 0;
    int result;
    int port = (80);
    int maxConnect = (5);
    char IPaddress[46];
    { char buffer[256]; sprintf(buffer, "Start | %s\n", ""); writeLog("workWithSockets.c", __func__, 81, buffer); };
    getValueForKeyNumber("config.txt", "Port to listen:", &port);
    deskription = socket(2, SOCK_STREAM, 0);
    memset(&socketADD, 0, sizeof(socketADD));
    socketADD.sin_family = 2;
    if((1) == getValueForKeyString("config.txt", "Is used IP address:", IPaddress) && (1) == checkExistenceSpecifiedAddr(IPaddress))
    {
        socketADD.sin_addr.s_addr = inet_addr(IPaddress);
    }
    else
    {
        socketADD.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    }
    socketADD.sin_port = htons((unsigned short)port);
    if (setsockopt(deskription, 1, 2, &yes, sizeof(int)) == (-1))
    {
        result = (-1);
        { char buffer[256]; sprintf(buffer, "Error. Setsockopt was failing. | result: %d\n", result); writeLog("workWithSockets.c", __func__, 103, buffer); };
        return result;
    }
    if(bind(deskription,(struct sockaddr*)&socketADD, sizeof(socketADD)) == (-1))
    {
        result = (-1);
        { char buffer[256]; sprintf(buffer, "Error. Bind was failing. | result: %d\n", result); writeLog("workWithSockets.c", __func__, 110, buffer); };
        return result;
    }
    getValueForKeyNumber("config.txt", "Max number of connect:", &maxConnect);
    if(listen(deskription, maxConnect) == (-1))
    {
        result = (-1);
        { char buffer[256]; sprintf(buffer, "Error. listen was failing. | result: %d\n", result); writeLog("workWithSockets.c", __func__, 119, buffer); };
        return result;
    }
    result = deskription;
    { char buffer[256]; sprintf(buffer, "End | Server is working now. | deskription: %d\n", result); writeLog("workWithSockets.c", __func__, 123, buffer); };
    return result;
}

canonical_original_code:
int connectToSocket()
{
    int yes = 1;
    int deskription = 0;
    int result;
    int port = (80);
    int maxConnect = (5);
    char IPaddress[46];
    { char buffer[256]; sprintf(buffer, "Start | %s\n", ""); writeLog("workWithSockets.c", __func__, 81, buffer); };
    getValueForKeyNumber("config.txt", "Port to listen:", &port);
    deskription = socket(2, SOCK_STREAM, 0);
    memset(&socketADD, 0, sizeof(socketADD));
    socketADD.sin_family = 2;
    if((1) == getValueForKeyString("config.txt", "Is used IP address:", IPaddress) && (1) == checkExistenceSpecifiedAddr(IPaddress))
    {
        socketADD.sin_addr.s_addr = inet_addr(IPaddress);
    }
    else
    {
        socketADD.sin_addr.s_addr = ((unsigned int) 0x00000000);
    }
    socketADD.sin_port = htons((unsigned short)port);
    if (setsockopt(deskription, 1, 2, &yes, sizeof(int)) == (-1))
    {
        result = (-1);
        { char buffer[256]; sprintf(buffer, "Error. Setsockopt was failing. | result: %d\n", result); writeLog("workWithSockets.c", __func__, 103, buffer); };
        return result;
    }
    if(bind(deskription,(struct sockaddr *)&socketADD, sizeof(socketADD)) == (-1))
    {
        result = (-1);
        { char buffer[256]; sprintf(buffer, "Error. Bind was failing. | result: %d\n", result); writeLog("workWithSockets.c", __func__, 110, buffer); };
        return result;
    }
    getValueForKeyNumber("config.txt", "Max number of connect:", &maxConnect);
    if(listen(deskription, maxConnect) == (-1))
    {
        result = (-1);
        { char buffer[256]; sprintf(buffer, "Error. listen was failing. | result: %d\n", result); writeLog("workWithSockets.c", __func__, 119, buffer); };
        return result;
    }
    result = deskription;
    { char buffer[256]; sprintf(buffer, "End | Server is working now. | deskription: %d\n", result); writeLog("workWithSockets.c", __func__, 123, buffer); };
    return result;
}

variable_types: yes int

variable_types: port int

variable_types: maxConnect int

variable_types:
IPaddress
char [46]

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


acceptWithLogger

decompiled_code:
__int64 __fastcall acceptWithLogger(int fd)
{
int v2; // eax
int v3; // edi
int v4; // eax
int v5; // er13
unsigned __int16 v6; // bx
char *v7; // rax
char *v9; // rbp
int v10; // ebx
__int64 v11; // rax
__int64 v12; // r14
__int64 v13; // rax
char *v14; // rbp
int v15; // ebx
__int64 v16; // r14
__int64 v17; // rax
socklen_t addr_len; // [rsp+8h] [rbp-1D0h] BYREF
socklen_t len; // [rsp+Ch] [rbp-1CCh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-1C8h] BYREF
struct timeval timeout; // [rsp+20h] [rbp-1B8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-1A8h] BYREF
struct sockaddr s[18]; // [rsp+B0h] [rbp-128h] BYREF

addr_len = 16;
sprintf((char *)s, "Start | Deskription: %d\n", (unsigned int)fd);
writeLog("workWithSockets.c", "acceptWithLogger", 139LL, s);
memset(&readfds, 0, sizeof(readfds));
v2 = fd + 63;
v3 = fd + 1;
if ( fd >= 0 )
v2 = fd;
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
readfds.fds_bits[v2 >> 6] |= 1LL << (fd % 64);
v4 = select(v3, &readfds, 0LL, 0LL, &timeout);
if ( v4 )
{
v5 = v4;
if ( v4 == -1 )
{
sprintf((char *)s, "Error. select was failed: %s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "acceptWithLogger", 157LL, s);
}
else
{
v5 = accept(fd, &addr, &addr_len);
if ( (unsigned int)isUseInLog("Server IP address:") )
{
len = 16;
getsockname(v5, s, &len);
v14 = inet_ntoa(*(struct in_addr *)&s[0].sa_data[2]);
v15 = strlen(v14);
v16 = getLogeW3CLog();
*(_QWORD *)(v16 + 48) = malloc(v15 + 1);
v17 = getLogeW3CLog();
strcpy(*(char **)(v17 + 48), v14);
}
if ( v5 < 0 )
{
v5 = -1;
sprintf((char *)s, "Error. DeskriptionClient wasn't opened: %s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "acceptWithLogger", 181LL, s);
}
}
}
else
{
v5 = -2;
}
if ( (unsigned int)isUseInLog("Client IP address:") )
{
v9 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
v10 = strlen(v9);
v11 = getLogeW3CLog();
*(_QWORD *)(v11 + 16) = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
v12 = getLogeW3CLog();
*(_QWORD *)(v12 + 16) = malloc(v10 + 1);
v13 = getLogeW3CLog();
strcpy(*(char **)(v13 + 16), v9);
}
v6 = _bswap_16(*(__int16 *)addr.sa_data);
v7 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
sprintf(
(char *)s,
"End | Deskription: %d | IP address is: %s | port is: %d | result: %d\n",
(unsigned int)fd,
v7,
v6,
(unsigned int)v5);
writeLog("workWithSockets.c", "acceptWithLogger", 199LL, s);
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd)
{
int v2; // eax
int v3; // edi
int v4; // eax
int v5; // er13
unsigned __int16 v6; // bx
char *v7; // rax
char *v9; // rbp
int v10; // ebx
__int64 v11; // rax
__int64 v12; // r14
__int64 v13; // rax
char *v14; // rbp
int v15; // ebx
__int64 v16; // r14
__int64 v17; // rax
socklen_t addr_len; // [rsp+8h] [rbp-1D0h] BYREF
socklen_t len; // [rsp+Ch] [rbp-1CCh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-1C8h] BYREF
struct timeval timeout; // [rsp+20h] [rbp-1B8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-1A8h] BYREF
struct sockaddr s[18]; // [rsp+B0h] [rbp-128h] BYREF

addr_len = 16;
sprintf((char *)s, "Start | Deskription: %d\n", (unsigned int)fd);
writeLog("workWithSockets.c", "acceptWithLogger", 139LL, s);
memset(&readfds, 0, sizeof(readfds));
v2 = fd + 63;
v3 = fd + 1;
if ( fd >= 0 )
v2 = fd;
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
readfds.fds_bits[v2 >> 6] |= 1LL << (fd % 64);
v4 = select(v3, &readfds, 0LL, 0LL, &timeout);
if ( v4 )
{
v5 = v4;
if ( v4 == -1 )
{
sprintf((char *)s, "Error. select was failed: %s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "acceptWithLogger", 157LL, s);
}
else
{
v5 = accept(fd, &addr, &addr_len);
if ( (unsigned int)isUseInLog("Server IP address:") )
{
len = 16;
getsockname(v5, s, &len);
v14 = inet_ntoa(*(struct in_addr *)&s[0].sa_data[2]);
v15 = strlen(v14);
v16 = getLogeW3CLog();
*(_QWORD *)(v16 + 48) = malloc(v15 + 1);
v17 = getLogeW3CLog();
strcpy(*(char **)(v17 + 48), v14);
}
if ( v5 < 0 )
{
v5 = -1;
sprintf((char *)s, "Error. DeskriptionClient wasn't opened: %s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "acceptWithLogger", 181LL, s);
}
}
}
else
{
v5 = -2;
}
if ( (unsigned int)isUseInLog("Client IP address:") )
{
v9 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
v10 = strlen(v9);
v11 = getLogeW3CLog();
*(_QWORD *)(v11 + 16) = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
v12 = getLogeW3CLog();
*(_QWORD *)(v12 + 16) = malloc(v10 + 1);
v13 = getLogeW3CLog();
strcpy(*(char **)(v13 + 16), v9);
}
v6 = func0(*(__int16 *)addr.sa_data);
v7 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
sprintf(
(char *)s,
"End | Deskription: %d | IP address is: %s | port is: %d | result: %d\n",
(unsigned int)fd,
v7,
v6,
(unsigned int)v5);
writeLog("workWithSockets.c", "acceptWithLogger", 199LL, s);
return (unsigned int)v5;
}

original_code:
int acceptWithLogger(int deskription)
{
    struct sockaddr_in socketClient;
    socklen_t clientLen = sizeof(socketClient);
    int deskriptionClient;
    int result;
    fd_set fds;
    struct timeval tv;
    { char buffer[256]; sprintf(buffer, "Start | Deskription: %d\n", deskription); writeLog("workWithSockets.c", __func__, 139, buffer); };
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fds)->__fds_bits)[((deskription) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((deskription) % (8 * (int) sizeof (__fd_mask)))))));
    tv.tv_sec = (5);
    tv.tv_usec = 0;
    result = select(deskription + 1, &fds, ((void *)0), ((void *)0), &tv);
    if (result == 0)
    {
        result = (-2);
    }
    else if (result == (-1))
    {
        { char buffer[256]; sprintf(buffer, "Error. select was failed: %s\n", ""); writeLog("workWithSockets.c", __func__, 157, buffer); };
        result = (-1);
    }
    else
    {
        deskriptionClient = accept(deskription, (struct sockaddr *)&socketClient, &clientLen);
        if(isUseInLog("Server IP address:"))
        {
            struct sockaddr_in socketServer;
            socklen_t serverLen = sizeof(socketServer);
            char *IPaddr = ((void *)0);
            int lenAddr = 0;
            getsockname(deskriptionClient, (struct sockaddr*)&socketServer, &serverLen);
            IPaddr = inet_ntoa(socketServer.sin_addr);
            lenAddr = strlen(IPaddr);
            getLogeW3CLog()->ServerIPAddress = malloc(lenAddr + 1);
            sprintf(getLogeW3CLog()->ServerIPAddress,"%s", IPaddr);
        }
        if (deskriptionClient < 0)
        {
            { char buffer[256]; sprintf(buffer, "Error. DeskriptionClient wasn't opened: %s\n", ""); writeLog("workWithSockets.c", __func__, 181, buffer); };
            result = (-1);
        }
        else
        {
            result = deskriptionClient;
        }
    }
    if(isUseInLog("Client IP address:"))
    {
        char *IPaddr = inet_ntoa(socketClient.sin_addr);
        int lenAddr = strlen(IPaddr);
        getLogeW3CLog()->ClientIPAddress =inet_ntoa(socketClient.sin_addr);
        getLogeW3CLog()->ClientIPAddress = malloc(lenAddr + 1);
        sprintf(getLogeW3CLog()->ClientIPAddress,"%s", IPaddr);
    }
    { char buffer[256]; sprintf(buffer, "End | Deskription: %d | IP address is: %s | port is: %d | result: %d\n", deskription, inet_ntoa(socketClient.sin_addr), (int) ntohs(socketClient.sin_port), result); writeLog("workWithSockets.c", __func__, 199, buffer); };
    return result;
}

canonical_original_code:
int acceptWithLogger(int deskription)
{
    struct sockaddr_in socketClient;
    unsigned int clientLen = sizeof(socketClient);
    int deskriptionClient;
    int result;
    struct fd_set fds;
    struct timeval tv;
    { char buffer[256]; sprintf(buffer, "Start | Deskription: %d\n", deskription); writeLog("workWithSockets.c", __func__, 139, buffer); };
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fds)->__fds_bits)[((deskription) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((deskription) % (8 * (int) sizeof (__fd_mask)))))));
    tv.tv_sec = (5);
    tv.tv_usec = 0;
    result = select(deskription + 1, &fds, ((void *)0), ((void *)0), &tv);
    if (result == 0)
    {
        result = (-2);
    }
    else if (result == (-1))
    {
        { char buffer[256]; sprintf(buffer, "Error. select was failed: %s\n", ""); writeLog("workWithSockets.c", __func__, 157, buffer); };
        result = (-1);
    }
    else
    {
        deskriptionClient = accept(deskription, (struct sockaddr *)&socketClient, &clientLen);
        if(isUseInLog("Server IP address:"))
        {
            struct sockaddr_in socketServer;
            unsigned int serverLen = sizeof(socketServer);
            char *IPaddr = ((void *)0);
            int lenAddr = 0;
            getsockname(deskriptionClient, (struct sockaddr *)&socketServer, &serverLen);
            IPaddr = inet_ntoa(socketServer.sin_addr);
            lenAddr = strlen(IPaddr);
            getLogeW3CLog()->ServerIPAddress = malloc(lenAddr + 1);
            sprintf(getLogeW3CLog()->ServerIPAddress,"%s", IPaddr);
        }
        if (deskriptionClient < 0)
        {
            { char buffer[256]; sprintf(buffer, "Error. DeskriptionClient wasn't opened: %s\n", ""); writeLog("workWithSockets.c", __func__, 181, buffer); };
            result = (-1);
        }
        else
        {
            result = deskriptionClient;
        }
    }
    if(isUseInLog("Client IP address:"))
    {
        char *IPaddr = inet_ntoa(socketClient.sin_addr);
        int lenAddr = strlen(IPaddr);
        getLogeW3CLog()->ClientIPAddress =inet_ntoa(socketClient.sin_addr);
        getLogeW3CLog()->ClientIPAddress = malloc(lenAddr + 1);
        sprintf(getLogeW3CLog()->ClientIPAddress,"%s", IPaddr);
    }
    { char buffer[256]; sprintf(buffer, "End | Deskription: %d | IP address is: %s | port is: %d | result: %d\n", deskription, inet_ntoa(socketClient.sin_addr), (int) ntohs(socketClient.sin_port), result); writeLog("workWithSockets.c", __func__, 199, buffer); };
    return result;
}

variable_types: deskription int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
clientLen
unsigned int

variable_types: deskriptionClient int

variable_types:
fds
struct fd_set { long __fds_bits[-1]; }

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
serverLen
unsigned int

variable_types:
IPaddr
char *

variable_types: lenAddr int


readWithTimeOut

decompiled_code:
__int64 __fastcall readWithTimeOut(int fd, void *buf, unsigned int a3, unsigned int a4)
{
unsigned int v6; // eax
__int64 v7; // r14
unsigned int v8; // eax
struct timeval v10; // [rsp+0h] [rbp-1B8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-1A8h] BYREF
char s[296]; // [rsp+90h] [rbp-128h] BYREF

sprintf(s, "Start | deskript: %d | pBuffer: %p | len: %d | time wait: %d\n", (unsigned int)fd, buf, a3, a4);
writeLog("workWithSockets.c", "readWithTimeOut", 215LL, s);
memset(&readfds, 0, sizeof(readfds));
v10.tv_usec = 0LL;
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v10.tv_sec = (int)a4;
v6 = select(fd + 1, &readfds, 0LL, 0LL, &v10);
if ( v6 )
{
v7 = v6;
if ( v6 != -1 )
{
v8 = read(fd, buf, (int)a3);
v7 = v8;
*((_BYTE *)buf + (int)v8) = 0;
}
}
else
{
v7 = 4294967294LL;
}
sprintf(
s,
"End | deskript: %d | pBuffer: %p | len: %d | time wait: %d |result: %d\n",
(unsigned int)fd,
buf,
a3,
a4,
v7);
writeLog("workWithSockets.c", "readWithTimeOut", 241LL, s);
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, void *buf, unsigned int a3, unsigned int a4)
{
unsigned int v6; // eax
__int64 v7; // r14
unsigned int v8; // eax
struct timeval v10; // [rsp+0h] [rbp-1B8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-1A8h] BYREF
char s[296]; // [rsp+90h] [rbp-128h] BYREF

sprintf(s, "Start | deskript: %d | pBuffer: %p | len: %d | time wait: %d\n", (unsigned int)fd, buf, a3, a4);
writeLog("workWithSockets.c", "readWithTimeOut", 215LL, s);
memset(&readfds, 0, sizeof(readfds));
v10.tv_usec = 0LL;
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v10.tv_sec = (int)a4;
v6 = select(fd + 1, &readfds, 0LL, 0LL, &v10);
if ( v6 )
{
v7 = v6;
if ( v6 != -1 )
{
v8 = read(fd, buf, (int)a3);
v7 = v8;
*((_BYTE *)buf + (int)v8) = 0;
}
}
else
{
v7 = 4294967294LL;
}
sprintf(
s,
"End | deskript: %d | pBuffer: %p | len: %d | time wait: %d |result: %d\n",
(unsigned int)fd,
buf,
a3,
a4,
v7);
writeLog("workWithSockets.c", "readWithTimeOut", 241LL, s);
return (unsigned int)v7;
}

original_code:
int readWithTimeOut(int deskript, char *buf, int len, int timeout)
{
    fd_set fds;
    int result;
    struct timeval tv;
    { char buffer[256]; sprintf(buffer, "Start | deskript: %d | pBuffer: %p | len: %d | time wait: %d\n", deskript, buf, len, timeout); writeLog("workWithSockets.c", __func__, 215, buffer); };
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fds)->__fds_bits)[((deskript) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((deskript) % (8 * (int) sizeof (__fd_mask)))))));
    tv.tv_sec = timeout;
    tv.tv_usec = 0;
    result = select(deskript + 1, &fds, ((void *)0), ((void *)0), &tv);
    if (result == 0)
    {
        result = (-2);
    }
    else if (result == (-1))
    {
        result = (-1);
    }
    else
    {
        result = read(deskript, buf, len);
        buf[result] = 0;
    }
    { char buffer[256]; sprintf(buffer, "End | deskript: %d | pBuffer: %p | len: %d | time wait: %d |result: %d\n", deskript, buf, len, timeout, result); writeLog("workWithSockets.c", __func__, 241, buffer); };
    return result;
}

canonical_original_code:
int readWithTimeOut(int deskript, char *buf, int len, int timeout)
{
    struct fd_set fds;
    int result;
    struct timeval tv;
    { char buffer[256]; sprintf(buffer, "Start | deskript: %d | pBuffer: %p | len: %d | time wait: %d\n", deskript, buf, len, timeout); writeLog("workWithSockets.c", __func__, 215, buffer); };
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fds)->__fds_bits)[((deskript) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((deskript) % (8 * (int) sizeof (__fd_mask)))))));
    tv.tv_sec = timeout;
    tv.tv_usec = 0;
    result = select(deskript + 1, &fds, ((void *)0), ((void *)0), &tv);
    if (result == 0)
    {
        result = (-2);
    }
    else if (result == (-1))
    {
        result = (-1);
    }
    else
    {
        result = read(deskript, buf, len);
        buf[result] = 0;
    }
    { char buffer[256]; sprintf(buffer, "End | deskript: %d | pBuffer: %p | len: %d | time wait: %d |result: %d\n", deskript, buf, len, timeout, result); writeLog("workWithSockets.c", __func__, 241, buffer); };
    return result;
}

variable_types: deskript int

variable_types:
buf
char *

variable_types: len int

variable_types: timeout int

variable_types: result int

variable_types:
buffer
char [256]

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


sendAll

decompiled_code:
__int64 __fastcall sendAll(int fd, char *a2, unsigned int *a3)
{
signed int v3; // ebp
unsigned int v5; // edx
unsigned int v6; // eax
unsigned int v7; // er14
char v9[296]; // [rsp+0h] [rbp-128h] BYREF

v3 = 0;
sprintf(v9, "Start | deskript: %d | pBuffer: %p | len: %d\n", (unsigned int)fd, a2, *a3);
writeLog("workWithSockets.c", "sendAll", 256LL, v9);
v5 = *a3;
if ( (int)*a3 > 0 )
{
while ( 1 )
{
v6 = send(fd, &a2[v3], (int)(v5 - v3), 0);
v7 = v6;
if ( v6 == -1 )
break;
v5 = *a3;
v3 += v6;
if ( (int)*a3 <= v3 )
goto LABEL_6;
}
*a3 = v3;
}
else
{
LABEL_6:
*a3 = v3;
v7 = 0;
}
sprintf(v9, "End | deskript: %d | pBuffer: %p | len: %d | result: %d\n", (unsigned int)fd, a2, (unsigned int)v3, v7);
writeLog("workWithSockets.c", "sendAll", 270LL, v9);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, char *a2, unsigned int *a3)
{
signed int v3; // ebp
unsigned int v5; // edx
unsigned int v6; // eax
unsigned int v7; // er14
char v9[296]; // [rsp+0h] [rbp-128h] BYREF

v3 = 0;
sprintf(v9, "Start | deskript: %d | pBuffer: %p | len: %d\n", (unsigned int)fd, a2, *a3);
writeLog("workWithSockets.c", "sendAll", 256LL, v9);
v5 = *a3;
if ( (int)*a3 > 0 )
{
while ( 1 )
{
v6 = send(fd, &a2[v3], (int)(v5 - v3), 0);
v7 = v6;
if ( v6 == -1 )
break;
v5 = *a3;
v3 += v6;
if ( (int)*a3 <= v3 )
goto LABEL_6;
}
*a3 = v3;
}
else
{
LABEL_6:
*a3 = v3;
v7 = 0;
}
sprintf(v9, "End | deskript: %d | pBuffer: %p | len: %d | result: %d\n", (unsigned int)fd, a2, (unsigned int)v3, v7);
writeLog("workWithSockets.c", "sendAll", 270LL, v9);
return v7;
}

original_code:
int sendAll(int deskript, char *buf, int *len)
{
    int total = 0;
    int number = 0;
    int result;
    { char buffer[256]; sprintf(buffer, "Start | deskript: %d | pBuffer: %p | len: %d\n", deskript, buf, *len); writeLog("workWithSockets.c", __func__, 256, buffer); };
    while(total < *len)
    {
        number = send(deskript, buf+total, *len - total, 0);
        if (number == (-1))
        {
            break;
        }
        total += number;
    }
    *len = total;
    result = (number == (-1))? (-1) : 0;
    { char buffer[256]; sprintf(buffer, "End | deskript: %d | pBuffer: %p | len: %d | result: %d\n", deskript, buf, *len, result); writeLog("workWithSockets.c", __func__, 270, buffer); };
    return result;
}

variable_types:
len
int *

variable_types: total int

variable_types: number int


getTimeS

decompiled_code:
_DWORD *getTimeS()
{
char *v0; // rax
signed __int64 v1; // rbp
_DWORD *v2; // r8
unsigned int v3; // eax
unsigned int v5; // edx
__int64 v6; // rcx
time_t timer; // [rsp+8h] [rbp-40h] BYREF
char dest[56]; // [rsp+10h] [rbp-38h] BYREF

timer = time(0LL);
v0 = ctime(&timer);
v1 = stpcpy(dest, v0) - dest;
v2 = malloc((int)v1 + 1);
v3 = v1 + 1;
if ( (unsigned int)(v1 + 1) < 8 )
{
if ( (v3 & 4) != 0 )
{
*v2 = *(_DWORD *)dest;
*(_DWORD *)((char *)v2 + v3 - 4) = *(_DWORD *)&dest[v3 - 4];
}
else if ( (_DWORD)v1 != -1 )
{
*(_BYTE *)v2 = dest[0];
if ( (v3 & 2) != 0 )
*(_WORD *)((char *)v2 + v3 - 2) = *(_WORD *)&dest[v3 - 2];
}
goto LABEL_6;
}
*(_QWORD *)((char *)v2 + v3 - 8) = *(time_t *)((char *)&timer + v3);
if ( (unsigned int)v1 < 8 )
{
LABEL_6:
*((_BYTE *)v2 + v1 - 1) = 0;
return v2;
}
v5 = 0;
do
{
v6 = v5;
v5 += 8;
*(_QWORD *)((char *)v2 + v6) = *(_QWORD *)&dest[v6];
}
while ( v5 < ((unsigned int)v1 & 0xFFFFFFF8) );
*((_BYTE *)v2 + v1 - 1) = 0;
return v2;
}

canonical_decompiled_code:
_DWORD *func0()
{
char *v0; // rax
signed __int64 v1; // rbp
_DWORD *v2; // r8
unsigned int v3; // eax
unsigned int v5; // edx
__int64 v6; // rcx
time_t timer; // [rsp+8h] [rbp-40h] BYREF
char dest[56]; // [rsp+10h] [rbp-38h] BYREF

timer = time(0LL);
v0 = ctime(&timer);
v1 = stpcpy(dest, v0) - dest;
v2 = malloc((int)v1 + 1);
v3 = v1 + 1;
if ( (unsigned int)(v1 + 1) < 8 )
{
if ( (v3 & 4) != 0 )
{
*v2 = *(_DWORD *)dest;
*(_DWORD *)((char *)v2 + v3 - 4) = *(_DWORD *)&dest[v3 - 4];
}
else if ( (_DWORD)v1 != -1 )
{
*(_BYTE *)v2 = dest[0];
if ( (v3 & 2) != 0 )
*(_WORD *)((char *)v2 + v3 - 2) = *(_WORD *)&dest[v3 - 2];
}
goto LABEL_6;
}
*(_QWORD *)((char *)v2 + v3 - 8) = *(time_t *)((char *)&timer + v3);
if ( (unsigned int)v1 < 8 )
{
LABEL_6:
*((_BYTE *)v2 + v1 - 1) = 0;
return v2;
}
v5 = 0;
do
{
v6 = v5;
v5 += 8;
*(_QWORD *)((char *)v2 + v6) = *(_QWORD *)&dest[v6];
}
while ( v5 < ((unsigned int)v1 & 0xFFFFFFF8) );
*((_BYTE *)v2 + v1 - 1) = 0;
return v2;
}

original_code:
char* getTimeS(void){
    char buffer[(30)];
    char *tmpTime;
    int lenTime = 0;
    time_t ticks = time(((void *)0));
    strcpy(buffer, ctime(&ticks));
    lenTime = strlen(buffer);
    tmpTime = malloc((lenTime + 1) * sizeof(char));
    strcpy(tmpTime, buffer);
    tmpTime[lenTime - 1] = 0;
    return tmpTime;
}

canonical_original_code:
char *getTimeS(){
    char buffer[-1];
    char *tmpTime;
    int lenTime = 0;
    long ticks = time(((void *)0));
    strcpy(buffer, ctime(&ticks));
    lenTime = strlen(buffer);
    tmpTime = malloc((lenTime + 1) * sizeof(char));
    strcpy(tmpTime, buffer);
    tmpTime[lenTime - 1] = 0;
    return tmpTime;
}

variable_types:
buffer
char [-1]

variable_types:
tmpTime
char *

variable_types: lenTime int

variable_types: ticks long

return_type: char *


convertToLower

decompiled_code:
size_t __fastcall convertToLower(char *s, __int64 a2)
{
unsigned __int64 v2; // rbx
const __int32_t **v3; // r13
size_t result; // rax

v2 = 0LL;
v3 = _ctype_tolower_loc();
do
{
*(_BYTE *)(a2 + v2) = (*v3)[s[v2]];
++v2;
result = strlen(s) + 1;
}
while ( result > v2 );
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(char *s, __int64 a2)
{
unsigned __int64 v2; // rbx
const __int32_t **v3; // r13
size_t result; // rax

v2 = 0LL;
v3 = _ctype_tolower_loc();
do
{
*(_BYTE *)(a2 + v2) = (*v3)[s[v2]];
++v2;
result = strlen(s) + 1;
}
while ( result > v2 );
return result;
}

original_code:
void convertToLower(char *strBefor, char *strAfter)
{
    int i;
    for(i=0; i < strlen(strBefor) + 1 ; i++)
    {
        strAfter[i] = tolower(strBefor[i]);
    }
}

variable_types:
strBefor
char *

variable_types:
strAfter
char *

variable_types: i int


freeNew

decompiled_code:
void __fastcall freeNew(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
free(v2);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func2(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
free(v2);
*a1 = 0LL;
}

original_code:
void freeNew(char **member)
{
    if(*member)
    {
        free(*member);
    }
    *member = ((void *)0);
    return;
}

variable_types:
member
char **


checkExit

decompiled_code:
__int64 checkExit()
{
return (unsigned int)exitCycle;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)exitCycle;
}

original_code:
int checkExit(void)
{
    return exitCycle;
}

canonical_original_code:
int checkExit()
{
    return exitCycle;
}


decompiled_code:
void __fastcall sig_handler(int a1)
{
if ( a1 == 2 )
exitCycle = 0;
}

canonical_decompiled_code:
void __fastcall func6(int a1)
{
if ( a1 == 2 )
exitCycle = 0;
}

original_code:
void sig_handler(int signo)
{
    if (signo == (2))
    {
        exitCycle = 0;
    }
}

variable_types: signo int


isUseInLog

decompiled_code:
_BOOL8 __fastcall isUseInLog(__int64 a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

getValueForKeyString("accessLoggin.txt", a1, v2);
return v2[0] == 89;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

getValueForKeyString("accessLoggin.txt", a1, v2);
return v2[0] == 89;
}

original_code:
YES_NO_QUESTION isUseInLog(char *Key)
{
    YES_NO_QUESTION result = NO_Q;
    char parameter[(256)];
    getValueForKeyString("accessLoggin.txt", Key, parameter);
    if(parameter[0] == 'Y')
    {
        result = YES_Q;
    }
    return result;
}

canonical_original_code:
enum _YES_NO_QUESTION_ isUseInLog(char *Key)
{
    enum _YES_NO_QUESTION_ result = NO_Q;
    char parameter[-1];
    getValueForKeyString("accessLoggin.txt", Key, parameter);
    if(parameter[0] == 'Y')
    {
        result = YES_Q;
    }
    return result;
}

variable_types:
Key
char *

variable_types: enum _YES_NO_QUESTION_ { NO_Q=0, YES_Q=1 }

variable_types:
parameter
char [-1]


original_code:
void initW3CLog(void)
{
    semIdW3C = semget(((__key_t) 0), 1, 0xfff);
    W3CLog.ServerName = "HW/1.0.0";
    W3CLog.Date = &W3CLog.ServerName[8];
    W3CLog.Time = &W3CLog.ServerName[8];
    W3CLog.ClientIPAddress = &W3CLog.ServerName[8];
    W3CLog.UserName = &W3CLog.ServerName[8];
    W3CLog.ServiceNameAndInstanceNumber = &W3CLog.ServerName[8];
    W3CLog.ServerIPAddress = &W3CLog.ServerName[8];
    W3CLog.ServerPort = &W3CLog.ServerName[8];
    W3CLog.Method = &W3CLog.ServerName[8];
    W3CLog.URIStem = &W3CLog.ServerName[8];
    W3CLog.URIQuery = &W3CLog.ServerName[8];
    W3CLog.HTTPStatus = 0;
    W3CLog.Win32Status = &W3CLog.ServerName[8];
    W3CLog.BytesSent = 0;
    W3CLog.BytesReceived = &W3CLog.ServerName[8];
    W3CLog.TimeTaken = &W3CLog.ServerName[8];
    W3CLog.ProtocolVersion = &W3CLog.ServerName[8];
    W3CLog.Host = &W3CLog.ServerName[8];
    W3CLog.UserAgent = &W3CLog.ServerName[8];
    W3CLog.Cookie = &W3CLog.ServerName[8];
    W3CLog.Referrer = &W3CLog.ServerName[8];
    W3CLog.ProtocolSubstatus = &W3CLog.ServerName[8];
    return;
}

canonical_original_code:
void initW3CLog()
{
    semIdW3C = semget(((int) 0), 1, 0xfff);
    W3CLog.ServerName = "HW/1.0.0";
    W3CLog.Date = &W3CLog.ServerName[8];
    W3CLog.Time = &W3CLog.ServerName[8];
    W3CLog.ClientIPAddress = &W3CLog.ServerName[8];
    W3CLog.UserName = &W3CLog.ServerName[8];
    W3CLog.ServiceNameAndInstanceNumber = &W3CLog.ServerName[8];
    W3CLog.ServerIPAddress = &W3CLog.ServerName[8];
    W3CLog.ServerPort = &W3CLog.ServerName[8];
    W3CLog.Method = &W3CLog.ServerName[8];
    W3CLog.URIStem = &W3CLog.ServerName[8];
    W3CLog.URIQuery = &W3CLog.ServerName[8];
    W3CLog.HTTPStatus = 0;
    W3CLog.Win32Status = &W3CLog.ServerName[8];
    W3CLog.BytesSent = 0;
    W3CLog.BytesReceived = &W3CLog.ServerName[8];
    W3CLog.TimeTaken = &W3CLog.ServerName[8];
    W3CLog.ProtocolVersion = &W3CLog.ServerName[8];
    W3CLog.Host = &W3CLog.ServerName[8];
    W3CLog.UserAgent = &W3CLog.ServerName[8];
    W3CLog.Cookie = &W3CLog.ServerName[8];
    W3CLog.Referrer = &W3CLog.ServerName[8];
    W3CLog.ProtocolSubstatus = &W3CLog.ServerName[8];
    return;
}


decompiled_code:
void **getLogeW3CLog()
{
return &W3CLog;
}

canonical_decompiled_code:
void **func2()
{
return &W3CLog;
}

original_code:
W3C_LOG *getLogeW3CLog(void)
{
    return &W3CLog;
}

canonical_original_code:
struct _W3C_LOG_ *getLogeW3CLog()
{
    return &W3CLog;
}

return_type: struct _W3C_LOG_ { char *Date; char *Time; char *ClientIPAddress; char *UserName; char *ServiceNameAndInstanceNumber; char *ServerName; char *ServerIPAddress; char *ServerPort; char *Method; char *URIStem; char *URIQuery; int HTTPStatus; char *Win32Status; int BytesSent; char *BytesReceived; char *TimeTaken; char *ProtocolVersion; char *Host; char *UserAgent; char *Cookie; char *Referrer; char *ProtocolSubstatus; } *


writeInLogFile

decompiled_code:
int writeInLogFile()
{
int v0; // ebp
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

v0 = semIdW3C;
sops.sem_op = 0;
semop(semIdW3C, &sops, 1uLL);
sops.sem_op = 1;
semop(v0, &sops, 1uLL);
debugLogin = fopen("logW3C.txt", "a+");
fprintf(
debugLogin,
"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
(const char *)qword_748,
(const char *)qword_730,
(const char *)ptr,
(const char *)W3CLog,
(const char *)qword_738,
(const char *)qword_740,
(const char *)qword_750,
(const char *)qword_758,
(const char *)qword_760,
(const char *)qword_768,
(const char *)qword_770,
(const char *)qword_780,
(const char *)qword_790,
(const char *)qword_798,
(const char *)qword_7A0,
(const char *)qword_7A8,
(const char *)qword_7B0,
(const char *)qword_7B8,
(const char *)qword_7C0,
(const char *)qword_7C8);
if ( isUseInLog((__int64)"HTTPStatus:") )
{
fprintf(debugLogin, "%d ", (unsigned int)dword_778);
if ( !isUseInLog((__int64)"BytesSent:") )
goto LABEL_3;
LABEL_5:
fprintf(debugLogin, "%d ", (unsigned int)dword_788);
goto LABEL_3;
}
if ( isUseInLog((__int64)"BytesSent:") )
goto LABEL_5;
LABEL_3:
fputc(10, debugLogin);
fclose(debugLogin);
sops.sem_op = -1;
return semop(semIdW3C, &sops, 1uLL);
}

canonical_decompiled_code:
int func3()
{
int v0; // ebp
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

v0 = semIdW3C;
sops.sem_op = 0;
semop(semIdW3C, &sops, 1uLL);
sops.sem_op = 1;
semop(v0, &sops, 1uLL);
debugLogin = fopen("logW3C.txt", "a+");
fprintf(
debugLogin,
"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
(const char *)qword_748,
(const char *)qword_730,
(const char *)ptr,
(const char *)W3CLog,
(const char *)qword_738,
(const char *)qword_740,
(const char *)qword_750,
(const char *)qword_758,
(const char *)qword_760,
(const char *)qword_768,
(const char *)qword_770,
(const char *)qword_780,
(const char *)qword_790,
(const char *)qword_798,
(const char *)qword_7A0,
(const char *)qword_7A8,
(const char *)qword_7B0,
(const char *)qword_7B8,
(const char *)qword_7C0,
(const char *)qword_7C8);
if ( func0((__int64)"HTTPStatus:") )
{
fprintf(debugLogin, "%d ", (unsigned int)dword_778);
if ( !func0((__int64)"BytesSent:") )
goto LABEL_3;
LABEL_5:
fprintf(debugLogin, "%d ", (unsigned int)dword_788);
goto LABEL_3;
}
if ( func0((__int64)"BytesSent:") )
goto LABEL_5;
LABEL_3:
fputc(10, debugLogin);
fclose(debugLogin);
sops.sem_op = -1;
return semop(semIdW3C, &sops, 1uLL);
}

original_code:
void writeInLogFile(void)
{
    struct sembuf sem_command;
    sem_command.sem_op = 0;
    semop(semIdW3C, &sem_command, 1);
    sem_command.sem_op = 1;
    semop(semIdW3C, &sem_command, 1);
    debugLogin = fopen("logW3C.txt","a+");
    fprintf(debugLogin, "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
                                                              W3CLog.ServerName, W3CLog.ClientIPAddress,
                                                              W3CLog.Time, W3CLog.Date,
                                                              W3CLog.UserName, W3CLog.ServiceNameAndInstanceNumber,
                                                              W3CLog.ServerIPAddress, W3CLog.ServerPort,
                                                              W3CLog.Method, W3CLog.URIStem,
                                                              W3CLog.URIQuery, W3CLog.Win32Status,
                                                              W3CLog.BytesReceived, W3CLog.TimeTaken,
                                                              W3CLog.ProtocolVersion, W3CLog.Host,
                                                              W3CLog.UserAgent, W3CLog.Cookie,
                                                              W3CLog.Referrer, W3CLog.ProtocolSubstatus);
    if(isUseInLog("HTTPStatus:"))
    {
        fprintf(debugLogin, "%d ", W3CLog.HTTPStatus);
    }
    if(isUseInLog("BytesSent:"))
    {
        fprintf(debugLogin, "%d ", W3CLog.BytesSent);
    }
    fprintf(debugLogin, "\n");
    fclose(debugLogin);
    sem_command.sem_op = -1;
    semop(semIdW3C, &sem_command, 1);
    return;
}

canonical_original_code:
void writeInLogFile()
{
    struct sembuf sem_command;
    sem_command.sem_op = 0;
    semop(semIdW3C, &sem_command, 1);
    sem_command.sem_op = 1;
    semop(semIdW3C, &sem_command, 1);
    debugLogin = fopen("logW3C.txt","a+");
    fprintf(debugLogin, "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
                                                              W3CLog.ServerName, W3CLog.ClientIPAddress,
                                                              W3CLog.Time, W3CLog.Date,
                                                              W3CLog.UserName, W3CLog.ServiceNameAndInstanceNumber,
                                                              W3CLog.ServerIPAddress, W3CLog.ServerPort,
                                                              W3CLog.Method, W3CLog.URIStem,
                                                              W3CLog.URIQuery, W3CLog.Win32Status,
                                                              W3CLog.BytesReceived, W3CLog.TimeTaken,
                                                              W3CLog.ProtocolVersion, W3CLog.Host,
                                                              W3CLog.UserAgent, W3CLog.Cookie,
                                                              W3CLog.Referrer, W3CLog.ProtocolSubstatus);
    if(isUseInLog("HTTPStatus:"))
    {
        fprintf(debugLogin, "%d ", W3CLog.HTTPStatus);
    }
    if(isUseInLog("BytesSent:"))
    {
        fprintf(debugLogin, "%d ", W3CLog.BytesSent);
    }
    fprintf(debugLogin, "\n");
    fclose(debugLogin);
    sem_command.sem_op = -1;
    semop(semIdW3C, &sem_command, 1);
    return;
}

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


isEmptyLogDate

decompiled_code:
_BOOL8 __fastcall isEmptyLogDate(__int64 a1)
{
return qword_748 + 8 == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
return qword_748 + 8 == a1;
}

original_code:
int isEmptyLogDate(char* dateLog)
{
    return dateLog == &W3CLog.ServerName[(8)] ? (1) : (0);
}

canonical_original_code:
int isEmptyLogDate(char *dateLog)
{
    return dateLog == &W3CLog.ServerName[(8)] ? (1) : (0);
}

variable_types:
dateLog
char *


decompiled_code:
__int64 clearW3CLog()
{
void *v0; // rdi
void *v1; // rdi
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi
void *v6; // rdi
void *v7; // rdi
void *v8; // rdi
void *v9; // rdi
void *v10; // rdi
void *v11; // rdi
void *v12; // rdi
void *v13; // rdi
void *v14; // rdi
void *v15; // rdi
void *v16; // rdi
__int64 result; // rax

v0 = W3CLog;
if ( isEmptyLogDate((__int64)W3CLog) )
{
v1 = ptr;
if ( isEmptyLogDate((__int64)ptr) )
goto LABEL_3;
}
else
{
free(v0);
v1 = ptr;
W3CLog = (void *)(qword_748 + 8);
if ( isEmptyLogDate((__int64)ptr) )
{
LABEL_3:
v2 = qword_738;
if ( isEmptyLogDate((__int64)qword_738) )
goto LABEL_4;
goto LABEL_29;
}
}
free(v1);
v2 = qword_738;
ptr = (void *)(qword_748 + 8);
if ( isEmptyLogDate((__int64)qword_738) )
{
LABEL_4:
v3 = qword_740;
if ( isEmptyLogDate((__int64)qword_740) )
goto LABEL_5;
goto LABEL_30;
}
LABEL_29:
free(v2);
v3 = qword_740;
qword_738 = (void *)(qword_748 + 8);
if ( isEmptyLogDate((__int64)qword_740) )
{
LABEL_5:
v4 = qword_758;
if ( isEmptyLogDate((__int64)qword_758) )
goto LABEL_6;
goto LABEL_31;
}
LABEL_30:
free(v3);
v4 = qword_758;
qword_740 = (void *)(qword_748 + 8);
if ( isEmptyLogDate((__int64)qword_758) )
{
LABEL_6:
v5 = qword_760;
if ( isEmptyLogDate((__int64)qword_760) )
goto LABEL_7;
goto LABEL_32;
}
LABEL_31:
free(v4);
v5 = qword_760;
qword_758 = (void *)(qword_748 + 8);
if ( isEmptyLogDate((__int64)qword_760) )
{
LABEL_7:
v6 = qword_768;
if ( isEmptyLogDate((__int64)qword_768) )
goto LABEL_8;
LABEL_33:
free(v6);
v7 = qword_770;
qword_768 = (void *)(qword_748 + 8);
if ( isEmptyLogDate((__int64)qword_770) )
goto LABEL_9;
goto LABEL_34;
}
LABEL_32:
free(v5);
v6 = qword_768;
qword_760 = (void *)(qword_748 + 8);
if ( !isEmptyLogDate((__int64)qword_768) )
goto LABEL_33;
LABEL_8:
v7 = qword_770;
if ( isEmptyLogDate((__int64)qword_770) )
goto LABEL_9;
LABEL_34:
free(v7);
qword_770 = (void *)(qword_748 + 8);
LABEL_9:
v8 = qword_780;
dword_778 = 0;
if ( !isEmptyLogDate((__int64)qword_780) )
{
free(v8);
qword_780 = (void *)(qword_748 + 8);
}
v9 = qword_790;
dword_788 = 0;
if ( !isEmptyLogDate((__int64)qword_790) )
{
free(v9);
qword_790 = (void *)(qword_748 + 8);
}
v10 = qword_798;
if ( !isEmptyLogDate((__int64)qword_798) )
{
free(v10);
qword_798 = (void *)(qword_748 + 8);
}
v11 = qword_7A0;
if ( !isEmptyLogDate((__int64)qword_7A0) )
{
free(v11);
qword_7A0 = (void *)(qword_748 + 8);
}
v12 = qword_7A8;
if ( !isEmptyLogDate((__int64)qword_7A8) )
{
free(v12);
qword_7A8 = (void *)(qword_748 + 8);
}
v13 = qword_7B0;
if ( !isEmptyLogDate((__int64)qword_7B0) )
{
free(v13);
qword_7B0 = (void *)(qword_748 + 8);
}
v14 = qword_7B8;
if ( !isEmptyLogDate((__int64)qword_7B8) )
{
free(v14);
qword_7B8 = (void *)(qword_748 + 8);
}
v15 = qword_7C0;
if ( !isEmptyLogDate((__int64)qword_7C0) )
{
free(v15);
qword_7C0 = (void *)(qword_748 + 8);
}
v16 = qword_7C8;
result = isEmptyLogDate((__int64)qword_7C8);
if ( !(_DWORD)result )
{
free(v16);
result = qword_748 + 8;
qword_7C8 = (void *)(qword_748 + 8);
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
void *v0; // rdi
void *v1; // rdi
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi
void *v6; // rdi
void *v7; // rdi
void *v8; // rdi
void *v9; // rdi
void *v10; // rdi
void *v11; // rdi
void *v12; // rdi
void *v13; // rdi
void *v14; // rdi
void *v15; // rdi
void *v16; // rdi
__int64 result; // rax

v0 = W3CLog;
if ( func4((__int64)W3CLog) )
{
v1 = ptr;
if ( func4((__int64)ptr) )
goto LABEL_3;
}
else
{
free(v0);
v1 = ptr;
W3CLog = (void *)(qword_748 + 8);
if ( func4((__int64)ptr) )
{
LABEL_3:
v2 = qword_738;
if ( func4((__int64)qword_738) )
goto LABEL_4;
goto LABEL_29;
}
}
free(v1);
v2 = qword_738;
ptr = (void *)(qword_748 + 8);
if ( func4((__int64)qword_738) )
{
LABEL_4:
v3 = qword_740;
if ( func4((__int64)qword_740) )
goto LABEL_5;
goto LABEL_30;
}
LABEL_29:
free(v2);
v3 = qword_740;
qword_738 = (void *)(qword_748 + 8);
if ( func4((__int64)qword_740) )
{
LABEL_5:
v4 = qword_758;
if ( func4((__int64)qword_758) )
goto LABEL_6;
goto LABEL_31;
}
LABEL_30:
free(v3);
v4 = qword_758;
qword_740 = (void *)(qword_748 + 8);
if ( func4((__int64)qword_758) )
{
LABEL_6:
v5 = qword_760;
if ( func4((__int64)qword_760) )
goto LABEL_7;
goto LABEL_32;
}
LABEL_31:
free(v4);
v5 = qword_760;
qword_758 = (void *)(qword_748 + 8);
if ( func4((__int64)qword_760) )
{
LABEL_7:
v6 = qword_768;
if ( func4((__int64)qword_768) )
goto LABEL_8;
LABEL_33:
free(v6);
v7 = qword_770;
qword_768 = (void *)(qword_748 + 8);
if ( func4((__int64)qword_770) )
goto LABEL_9;
goto LABEL_34;
}
LABEL_32:
free(v5);
v6 = qword_768;
qword_760 = (void *)(qword_748 + 8);
if ( !func4((__int64)qword_768) )
goto LABEL_33;
LABEL_8:
v7 = qword_770;
if ( func4((__int64)qword_770) )
goto LABEL_9;
LABEL_34:
free(v7);
qword_770 = (void *)(qword_748 + 8);
LABEL_9:
v8 = qword_780;
dword_778 = 0;
if ( !func4((__int64)qword_780) )
{
free(v8);
qword_780 = (void *)(qword_748 + 8);
}
v9 = qword_790;
dword_788 = 0;
if ( !func4((__int64)qword_790) )
{
free(v9);
qword_790 = (void *)(qword_748 + 8);
}
v10 = qword_798;
if ( !func4((__int64)qword_798) )
{
free(v10);
qword_798 = (void *)(qword_748 + 8);
}
v11 = qword_7A0;
if ( !func4((__int64)qword_7A0) )
{
free(v11);
qword_7A0 = (void *)(qword_748 + 8);
}
v12 = qword_7A8;
if ( !func4((__int64)qword_7A8) )
{
free(v12);
qword_7A8 = (void *)(qword_748 + 8);
}
v13 = qword_7B0;
if ( !func4((__int64)qword_7B0) )
{
free(v13);
qword_7B0 = (void *)(qword_748 + 8);
}
v14 = qword_7B8;
if ( !func4((__int64)qword_7B8) )
{
free(v14);
qword_7B8 = (void *)(qword_748 + 8);
}
v15 = qword_7C0;
if ( !func4((__int64)qword_7C0) )
{
free(v15);
qword_7C0 = (void *)(qword_748 + 8);
}
v16 = qword_7C8;
result = func4((__int64)qword_7C8);
if ( !(_DWORD)result )
{
free(v16);
result = qword_748 + 8;
qword_7C8 = (void *)(qword_748 + 8);
}
return result;
}

original_code:
void clearW3CLog(void)
{
    if(!isEmptyLogDate(W3CLog.Date))
    {
        free(W3CLog.Date);
        W3CLog.Date = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.Time))
    {
        free(W3CLog.Time);
        W3CLog.Time = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.UserName))
    {
        free(W3CLog.UserName);
        W3CLog.UserName = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.ServiceNameAndInstanceNumber))
    {
        free(W3CLog.ServiceNameAndInstanceNumber);
        W3CLog.ServiceNameAndInstanceNumber = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.ServerPort))
    {
        free(W3CLog.ServerPort);
        W3CLog.ServerPort = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.Method))
    {
        free(W3CLog.Method);
        W3CLog.Method = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.URIStem))
    {
        free(W3CLog.URIStem);
        W3CLog.URIStem = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.URIQuery))
    {
        free(W3CLog.URIQuery);
        W3CLog.URIQuery = &W3CLog.ServerName[8];
    }
    W3CLog.HTTPStatus = 0;
    if(!isEmptyLogDate(W3CLog.Win32Status))
    {
        free(W3CLog.Win32Status);
        W3CLog.Win32Status = &W3CLog.ServerName[8];
    }
    W3CLog.BytesSent = 0;
    if(!isEmptyLogDate(W3CLog.BytesReceived))
    {
        free(W3CLog.BytesReceived);
        W3CLog.BytesReceived = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.TimeTaken))
    {
        free(W3CLog.TimeTaken);
        W3CLog.TimeTaken = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.ProtocolVersion))
    {
        free(W3CLog.ProtocolVersion);
        W3CLog.ProtocolVersion = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.Host))
    {
        free(W3CLog.Host);
        W3CLog.Host = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.UserAgent))
    {
        free(W3CLog.UserAgent);
        W3CLog.UserAgent = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.Cookie))
    {
        free(W3CLog.Cookie);
        W3CLog.Cookie = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.Referrer))
    {
        free(W3CLog.Referrer);
        W3CLog.Referrer = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.ProtocolSubstatus))
    {
        free(W3CLog.ProtocolSubstatus);
        W3CLog.ProtocolSubstatus = &W3CLog.ServerName[8];
    }
    return;
}

canonical_original_code:
void clearW3CLog()
{
    if(!isEmptyLogDate(W3CLog.Date))
    {
        free(W3CLog.Date);
        W3CLog.Date = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.Time))
    {
        free(W3CLog.Time);
        W3CLog.Time = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.UserName))
    {
        free(W3CLog.UserName);
        W3CLog.UserName = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.ServiceNameAndInstanceNumber))
    {
        free(W3CLog.ServiceNameAndInstanceNumber);
        W3CLog.ServiceNameAndInstanceNumber = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.ServerPort))
    {
        free(W3CLog.ServerPort);
        W3CLog.ServerPort = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.Method))
    {
        free(W3CLog.Method);
        W3CLog.Method = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.URIStem))
    {
        free(W3CLog.URIStem);
        W3CLog.URIStem = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.URIQuery))
    {
        free(W3CLog.URIQuery);
        W3CLog.URIQuery = &W3CLog.ServerName[8];
    }
    W3CLog.HTTPStatus = 0;
    if(!isEmptyLogDate(W3CLog.Win32Status))
    {
        free(W3CLog.Win32Status);
        W3CLog.Win32Status = &W3CLog.ServerName[8];
    }
    W3CLog.BytesSent = 0;
    if(!isEmptyLogDate(W3CLog.BytesReceived))
    {
        free(W3CLog.BytesReceived);
        W3CLog.BytesReceived = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.TimeTaken))
    {
        free(W3CLog.TimeTaken);
        W3CLog.TimeTaken = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.ProtocolVersion))
    {
        free(W3CLog.ProtocolVersion);
        W3CLog.ProtocolVersion = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.Host))
    {
        free(W3CLog.Host);
        W3CLog.Host = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.UserAgent))
    {
        free(W3CLog.UserAgent);
        W3CLog.UserAgent = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.Cookie))
    {
        free(W3CLog.Cookie);
        W3CLog.Cookie = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.Referrer))
    {
        free(W3CLog.Referrer);
        W3CLog.Referrer = &W3CLog.ServerName[8];
    }
    if(!isEmptyLogDate(W3CLog.ProtocolSubstatus))
    {
        free(W3CLog.ProtocolSubstatus);
        W3CLog.ProtocolSubstatus = &W3CLog.ServerName[8];
    }
    return;
}


startDebug

decompiled_code:
int startDebug()
{
int result; // eax

result = semget(0, 1, 4095);
semId = result;
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

result = semget(0, 1, 4095);
semId = result;
return result;
}

original_code:
void startDebug()
{
    semId = semget(((__key_t) 0), 1, 0xfff);
    return;
}

canonical_original_code:
void startDebug()
{
    semId = semget(((int) 0), 1, 0xfff);
    return;
}


writeLog

decompiled_code:
int __fastcall writeLog(const char *a1, const char *a2, unsigned int a3, const char *a4)
{
time_t v6; // rax
int v7; // er13
char *v8; // r13
unsigned int v9; // eax
struct sembuf sops; // [rsp+2h] [rbp-36h] BYREF
time_t timer; // [rsp+8h] [rbp-30h] BYREF

v6 = time(0LL);
v7 = semId;
timer = v6;
sops.sem_op = 0;
semop(semId, &sops, 1uLL);
sops.sem_op = 1;
semop(v7, &sops, 1uLL);
debugLogin = fopen("debugLogFile.txt", "a+");
fflush(stdout);
v8 = ctime(&timer);
v9 = getpid();
fprintf(debugLogin, "---pid: %d | File: %s | Func: %s | line: %d -- %s%s\n", v9, a1, a2, a3, v8, a4);
fclose(debugLogin);
sops.sem_op = -1;
return semop(semId, &sops, 1uLL);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, const char *a2, unsigned int a3, const char *a4)
{
time_t v6; // rax
int v7; // er13
char *v8; // r13
unsigned int v9; // eax
struct sembuf sops; // [rsp+2h] [rbp-36h] BYREF
time_t timer; // [rsp+8h] [rbp-30h] BYREF

v6 = time(0LL);
v7 = semId;
timer = v6;
sops.sem_op = 0;
semop(semId, &sops, 1uLL);
sops.sem_op = 1;
semop(v7, &sops, 1uLL);
debugLogin = fopen("debugLogFile.txt", "a+");
fflush(stdout);
v8 = ctime(&timer);
v9 = getpid();
fprintf(debugLogin, "---pid: %d | File: %s | Func: %s | line: %d -- %s%s\n", v9, a1, a2, a3, v8, a4);
fclose(debugLogin);
sops.sem_op = -1;
return semop(semId, &sops, 1uLL);
}

original_code:
void writeLog(const char *nameFile,const char *nameFunc, int line, char *text)
{
    struct sembuf sem_command;
    time_t ticks = time(((void *)0));
    sem_command.sem_op = 0;
    semop(semId, &sem_command, 1);
    sem_command.sem_op = 1;
    semop(semId, &sem_command, 1);
    debugLogin = fopen("debugLogFile.txt","a+");
    fflush(stdout);
    fprintf(debugLogin, "---pid: %d | File: %s | Func: %s | line: %d -- %s%s\n", getpid(), nameFile, nameFunc, line, ctime(&ticks), text);
    fclose(debugLogin);
    sem_command.sem_op = -1;
    semop(semId, &sem_command, 1);
    return;
}

canonical_original_code:
void writeLog(char *nameFile, char *nameFunc, int line, char *text)
{
    struct sembuf sem_command;
    long ticks = time(((void *)0));
    sem_command.sem_op = 0;
    semop(semId, &sem_command, 1);
    sem_command.sem_op = 1;
    semop(semId, &sem_command, 1);
    debugLogin = fopen("debugLogFile.txt","a+");
    fflush(stdout);
    fprintf(debugLogin, "---pid: %d | File: %s | Func: %s | line: %d -- %s%s\n", getpid(), nameFile, nameFunc, line, ctime(&ticks), text);
    fclose(debugLogin);
    sem_command.sem_op = -1;
    semop(semId, &sem_command, 1);
    return;
}

variable_types:
nameFile
char *

variable_types:
nameFunc
char *

variable_types: line int

variable_types:
text
char *

user_defined_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


endDebug

decompiled_code:
void endDebug()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void endDebug()
{
    return;
}

canonical_original_code:
void endDebug()
{
    return;
}


main

repo: Tatk/PasswordGenerator

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
unsigned int v4; // er13
unsigned int v5; // eax
int v6; // eax
int v7; // ebx
void *v9; // rsp
int v10; // er14
char *v11; // r12
char *v12; // rbx
char v13; // al
__int64 *v14; // [rsp+0h] [rbp-50h] BYREF
unsigned __int64 v15; // [rsp+8h] [rbp-48h]
__int64 v16; // [rsp+10h] [rbp-40h]
int v17; // [rsp+1Ch] [rbp-34h]

v3 = 8;
v4 = 0;
v5 = time(0LL);
srand(v5);
puts(" For help use command '-h' ");
v17 = 1;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "hl:Anpc:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case '?':
v3 = 0;
puts("Error found !");
v17 = 0;
break;
case 'A':
v4 += 5;
break;
case 'c':
if ( atoi(_bss_start) <= 0 )
printf("Error! Please, try again!");
else
v17 = atoi(_bss_start);
break;
case 'h':
puts(
"Please, if you want to get password(-s), please enter:\n"
"-l N ~ length of password\n"
"-A ~ uppercase characters\n"
"-n ~ numbers\n"
"-p ~ punctuation marks\n"
"-c N ~ number of passwords\n"
" If you want any password enter 'enter' and you get password a password of 8 characters. For example: ");
break;
case 'l':
if ( atoi(_bss_start) <= 0 )
printf("Error! Enter password length. Please, try again!");
else
v3 = atoi(_bss_start);
break;
case 'n':
v4 += 7;
break;
case 'p':
v4 += 11;
break;
default:
continue;
}
}
v7 = v17;
if ( v17 )
{
if ( v3 )
{
v14 = (__int64 *)&v14;
v16 = v17;
v9 = alloca(v17 * (__int64)v3);
puts("Your password(s): ");
if ( v7 > 0 )
{
v10 = 0;
v11 = (char *)&v14 + (unsigned int)v3;
v15 = ~(unsigned __int64)(unsigned int)(v3 - 1);
do
{
printf("%d) ", (unsigned int)++v10);
if ( v3 > 0 )
{
v12 = &v11[v15];
do
{
++v12;
v13 = get_rand(v4);
*(v12 - 1) = v13;
putchar(v13);
}
while ( v12 != v11 );
}
putchar(10);
v11 += v16;
}
while ( v17 != v10 );
}
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
unsigned int v4; // er13
unsigned int v5; // eax
int v6; // eax
int v7; // ebx
void *v9; // rsp
int v10; // er14
char *v11; // r12
char *v12; // rbx
char v13; // al
__int64 *v14; // [rsp+0h] [rbp-50h] BYREF
unsigned __int64 v15; // [rsp+8h] [rbp-48h]
__int64 v16; // [rsp+10h] [rbp-40h]
int v17; // [rsp+1Ch] [rbp-34h]

v3 = 8;
v4 = 0;
v5 = time(0LL);
srand(v5);
puts(" For help use command '-h' ");
v17 = 1;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "hl:Anpc:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case '?':
v3 = 0;
puts("Error found !");
v17 = 0;
break;
case 'A':
v4 += 5;
break;
case 'c':
if ( atoi(_bss_start) <= 0 )
printf("Error! Please, try again!");
else
v17 = atoi(_bss_start);
break;
case 'h':
puts(
"Please, if you want to get password(-s), please enter:\n"
"-l N ~ length of password\n"
"-A ~ uppercase characters\n"
"-n ~ numbers\n"
"-p ~ punctuation marks\n"
"-c N ~ number of passwords\n"
" If you want any password enter 'enter' and you get password a password of 8 characters. For example: ");
break;
case 'l':
if ( atoi(_bss_start) <= 0 )
printf("Error! Enter password length. Please, try again!");
else
v3 = atoi(_bss_start);
break;
case 'n':
v4 += 7;
break;
case 'p':
v4 += 11;
break;
default:
continue;
}
}
v7 = v17;
if ( v17 )
{
if ( v3 )
{
v14 = (__int64 *)&v14;
v16 = v17;
v9 = alloca(v17 * (__int64)v3);
puts("Your password(s): ");
if ( v7 > 0 )
{
v10 = 0;
v11 = (char *)&v14 + (unsigned int)v3;
v15 = ~(unsigned __int64)(unsigned int)(v3 - 1);
do
{
printf("%d) ", (unsigned int)++v10);
if ( v3 > 0 )
{
v12 = &v11[v15];
do
{
++v12;
v13 = func10(v4);
*(v12 - 1) = v13;
putchar(v13);
}
while ( v12 != v11 );
}
putchar(10);
v11 += v16;
}
while ( v17 != v10 );
}
}
}
return 0;
}

original_code:
int main (int argc, char** argv){
 srand( time( ((void *)0) ) );
 int rez = 0;
 int N = 8;
 int M = 1;
 int i=0;
 int j=0;
 int counter=0;
printf (" For help use command '-h' \n");
while ( (rez = getopt(argc,argv,"hl:Anpc:")) != -1){
 switch (rez){
  case 'l':
   if (atoi(optarg) > 0) N = atoi(optarg);
   else printf ("Error! Enter password length. Please, try again!");
   break;
  case 'A': counter += 5; break;
  case 'n': counter += 7; break;
  case 'p': counter += 11; break;
  case 'c':
   if (atoi(optarg) > 0) M = atoi(optarg);
   else printf ("Error! Please, try again!");
   break;
  case '?': {
   printf("Error found !\n");
   M=0;
   N=0;
   }
   break;
  case 'h':
   printf ("Please, if you want to get password(-s), please enter:\n"
    "-l N ~ length of password\n"
    "-A ~ uppercase characters\n"
    "-n ~ numbers\n"
    "-p ~ punctuation marks\n"
    "-c N ~ number of passwords\n"
    " If you want any password enter 'enter' and you get password a password of 8 characters. For example: \n");
         };
};
if ((M != 0) && (N != 0)) {
 char mas[N][M];
 printf ("Your password(s): \n");
 for (i=0; i<M; i++){
  printf("%d) ",i+1);
  for (j=0; j<N; j++)
  printf("%c",mas[i][j] = get_rand(counter));
  printf ("\n");
 };
};
}

canonical_original_code:
int main(int argc, char **argv){
 srand( time( ((void *)0) ) );
 int rez = 0;
 int N = 8;
 int M = 1;
 int i = 0;
 int j = 0;
 int counter = 0;
printf (" For help use command '-h' \n");
while ( (rez = getopt(argc,argv,"hl:Anpc:")) != -1){
 switch (rez){
  case 'l':
   if (atoi(optarg) > 0) N = atoi(optarg);
   else printf ("Error! Enter password length. Please, try again!");
   break;
  case 'A': counter += 5; break;
  case 'n': counter += 7; break;
  case 'p': counter += 11; break;
  case 'c':
   if (atoi(optarg) > 0) M = atoi(optarg);
   else printf ("Error! Please, try again!");
   break;
  case '?': {
   printf("Error found !\n");
   M=0;
   N=0;
   }
   break;
  case 'h':
   printf ("Please, if you want to get password(-s), please enter:\n"
    "-l N ~ length of password\n"
    "-A ~ uppercase characters\n"
    "-n ~ numbers\n"
    "-p ~ punctuation marks\n"
    "-c N ~ number of passwords\n"
    " If you want any password enter 'enter' and you get password a password of 8 characters. For example: \n");
         };
};
if ((M != 0) && (N != 0)) {
 char mas[-1][-1];
 printf ("Your password(s): \n");
 for (i=0; i<M; i++){
  printf("%d) ",i+1);
  for (j=0; j<N; j++)
  printf("%c",mas[i][j] = get_rand(counter));
  printf ("\n");
 };
};
}

variable_types: argc int

variable_types:
argv
char **

variable_types: rez int

variable_types: N int

variable_types: M int

variable_types: j int

variable_types: counter int


DWIFreeSong

repo: Tatsh/StepMania-Utilities

decompiled_code:
void __fastcall DWIFreeSong(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi
void *v4; // rdi

if ( *((int *)ptr + 16) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 7) + 8 * v2);
if ( v3 )
free(v3);
++v2;
}
while ( *((_DWORD *)ptr + 16) > (int)v2 );
}
v4 = (void *)*((_QWORD *)ptr + 6);
if ( v4 )
free(v4);
if ( strcmp("########NOARTIST", *((const char **)ptr + 4)) )
free(*((void **)ptr + 4));
if ( strcmp("#######NOTITLE", *((const char **)ptr + 5)) )
free(*((void **)ptr + 5));
free(*((void **)ptr + 7));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi
void *v4; // rdi

if ( *((int *)ptr + 16) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 7) + 8 * v2);
if ( v3 )
free(v3);
++v2;
}
while ( *((_DWORD *)ptr + 16) > (int)v2 );
}
v4 = (void *)*((_QWORD *)ptr + 6);
if ( v4 )
free(v4);
if ( strcmp("########NOARTIST", *((const char **)ptr + 4)) )
free(*((void **)ptr + 4));
if ( strcmp("#######NOTITLE", *((const char **)ptr + 5)) )
free(*((void **)ptr + 5));
free(*((void **)ptr + 7));
free(ptr);
}

original_code:
void DWIFreeSong(DWISong *song) {
  int i;
  for (i = 0; i < song->otherSectionsCount; i++) {
    if (song->otherSections[i] != ((void *)0)) {
      free(song->otherSections[i]);
    }
  }
  if (song->CDTitlePath != ((void *)0)) {
    free(song->CDTitlePath);
  }
  if (strcmp("########NOARTIST", song->artist) != 0) {
    free(song->artist);
  }
  if (strcmp("#######NOTITLE", song->title) != 0) {
    free(song->title);
  }
  free(song->otherSections);
  free(song);
}

canonical_original_code:
void DWIFreeSong(struct _DWISong *song) {
  int i;
  for (i = 0; i < song->otherSectionsCount; i++) {
    if (song->otherSections[i] != ((void *)0)) {
      free(song->otherSections[i]);
    }
  }
  if (song->CDTitlePath != ((void *)0)) {
    free(song->CDTitlePath);
  }
  if (strcmp("########NOARTIST", song->artist) != 0) {
    free(song->artist);
  }
  if (strcmp("#######NOTITLE", song->title) != 0) {
    free(song->title);
  }
  free(song->otherSections);
  free(song);
}

variable_types: struct _DWISong { double sampleStart; double sampleLength; double initialBPM; int gap; char *artist; char *title; char *CDTitlePath; char **otherSections; int otherSectionsCount; } *

variable_types: i int


DWIInitialize

original_code:
DWISong *DWIInitialize() {
  DWISong *song = malloc(sizeof(DWISong));
  song->otherSections = malloc(sizeof(char *) * 100);
  song->otherSectionsCount = 0;
  song->sampleStart = -1;
  song->sampleLength = -1;
  song->gap = 0;
  song->artist = "########NOARTIST";
  song->title = "#######NOTITLE";
  song->CDTitlePath = ((void *)0);
  song->initialBPM = 0.0f;
  return song;
}

canonical_original_code:
struct _DWISong *DWIInitialize() {
  struct _DWISong *song = malloc(sizeof(DWISong));
  song->otherSections = malloc(sizeof(char *) * 100);
  song->otherSectionsCount = 0;
  song->sampleStart = -1;
  song->sampleLength = -1;
  song->gap = 0;
  song->artist = "########NOARTIST";
  song->title = "#######NOTITLE";
  song->CDTitlePath = ((void *)0);
  song->initialBPM = 0.0f;
  return song;
}

return_type: struct _DWISong { double sampleStart; double sampleLength; double initialBPM; int gap; char *artist; char *title; char *CDTitlePath; char **otherSections; int otherSectionsCount; } *


DWIPrintSongInformation

decompiled_code:
int __fastcall DWIPrintSongInformation(__int64 a1)
{
const char *v1; // rsi

v1 = *(const char **)(a1 + 48);
if ( !v1 )
v1 = "None";
printf("CD Title: %s\n", v1);
printf("Title: %s\n", *(const char **)(a1 + 40));
printf("Artist: %s\n", *(const char **)(a1 + 32));
printf("Initial BPM: %.2f\n", *(double *)(a1 + 16));
printf("Gap: %d\n", *(unsigned int *)(a1 + 24));
printf("Sample start: %.2f\n", *(double *)a1);
printf("Sample length: %.2f\n", *(double *)(a1 + 8));
return printf("%d other sections\n", *(unsigned int *)(a1 + 64));
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
const char *v1; // rsi

v1 = *(const char **)(a1 + 48);
if ( !v1 )
v1 = "None";
printf("CD Title: %s\n", v1);
printf("Title: %s\n", *(const char **)(a1 + 40));
printf("Artist: %s\n", *(const char **)(a1 + 32));
printf("Initial BPM: %.2f\n", *(double *)(a1 + 16));
printf("Gap: %d\n", *(unsigned int *)(a1 + 24));
printf("Sample start: %.2f\n", *(double *)a1);
printf("Sample length: %.2f\n", *(double *)(a1 + 8));
return printf("%d other sections\n", *(unsigned int *)(a1 + 64));
}

original_code:
void DWIPrintSongInformation(DWISong *song) {
  printf("CD Title: %s\n", song->CDTitlePath == ((void *)0) ? "None" : song->CDTitlePath);
  printf("Title: %s\n", song->title);
  printf("Artist: %s\n", song->artist);
  printf("Initial BPM: %.2f\n", song->initialBPM);
  printf("Gap: %d\n", song->gap);
  printf("Sample start: %.2f\n", song->sampleStart);
  printf("Sample length: %.2f\n", song->sampleLength);
  printf("%d other sections\n", song->otherSectionsCount);
}

canonical_original_code:
void DWIPrintSongInformation(struct _DWISong *song) {
  printf("CD Title: %s\n", song->CDTitlePath == ((void *)0) ? "None" : song->CDTitlePath);
  printf("Title: %s\n", song->title);
  printf("Artist: %s\n", song->artist);
  printf("Initial BPM: %.2f\n", song->initialBPM);
  printf("Gap: %d\n", song->gap);
  printf("Sample start: %.2f\n", song->sampleStart);
  printf("Sample length: %.2f\n", song->sampleLength);
  printf("%d other sections\n", song->otherSectionsCount);
}

user_defined_types: struct _DWISong { double sampleStart; double sampleLength; double initialBPM; int gap; char *artist; char *title; char *CDTitlePath; char **otherSections; int otherSectionsCount; }


sighandler

repo: Tblue/sessionchooser

decompiled_code:
void __fastcall sighandler(int a1)
{
char *v1; // rax

if ( a1 == 2 )
{
v1 = dcgettext(0LL, "\nUse EOF (e. g. ^D) to quit.", 5);
puts(v1);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
char *v1; // rax

if ( a1 == 2 )
{
v1 = dcgettext(0LL, "\nUse EOF (e. g. ^D) to quit.", 5);
puts(v1);
}
}

original_code:
void sighandler( int sig )
{
    switch( sig )
    {
        case 2:
            puts( gettext ("\nUse EOF (e. g. ^D) to quit.") );
            break;
    }
}

canonical_original_code:
void sighandler(int sig)
{
    switch( sig )
    {
        case 2:
            puts( gettext ("\nUse EOF (e. g. ^D) to quit.") );
            break;
    }
}

variable_types: sig int


decompiled_code:
__int64 __fastcall process_session(__int64 a1)
{
unsigned int v1; // er13
const char *v2; // r12
__int16 v3; // bx
const char *v4; // r14
const char *v5; // rax
const char *v6; // rbp
size_t v7; // rax
ssize_t v8; // rbx
__int64 result; // rax
__int64 v10; // rax
__int64 v11; // r12
const char *v12; // rbx
const char *v13; // rax

if ( *(_DWORD *)(a1 + 64) )
{
v1 = get_next_free_XDisplay();
if ( v1 == -1 )
{
g_log(0LL, 8LL, "Could not get a free X display to use!");
return 0LL;
}
v2 = (const char *)g_getenv("SESSIONCHOOSER_XARGS");
v3 = get_active_vt();
if ( v3 == -1 )
{
v12 = " 2>&1";
if ( !discard_stderr )
v12 = &s1;
if ( !v2 )
v2 = &s1;
v13 = (const char *)sess_session_get_exec_locale(a1);
v6 = (const char *)g_strdup_printf("xinit %s -- :%d %s 1>/dev/null%s", v13, v1, v2, v12);
}
else
{
v4 = " 2>&1";
if ( !discard_stderr )
v4 = &s1;
if ( !v2 )
v2 = &s1;
v5 = (const char *)sess_session_get_exec_locale(a1);
v6 = (const char *)g_strdup_printf("xinit %s -- :%d vt%hd %s 1>/dev/null%s", v5, v1, (unsigned int)v3, v2, v4);
}
}
else
{
v10 = ((__int64 (*)(void))sess_session_get_exec_locale)();
v11 = g_shell_quote(v10);
v6 = (const char *)g_strconcat("sh ", v11, 0LL);
g_free(v11);
}
v7 = strlen(v6);
v8 = write(output_fd, v6, v7);
g_free(v6);
result = 1LL;
if ( v8 == -1 )
{
g_log(0LL, 8LL, "Could not write() to output file descriptor (#%d)!", (unsigned int)output_fd);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v1; // er13
const char *v2; // r12
__int16 v3; // bx
const char *v4; // r14
const char *v5; // rax
const char *v6; // rbp
size_t v7; // rax
ssize_t v8; // rbx
__int64 result; // rax
__int64 v10; // rax
__int64 v11; // r12
const char *v12; // rbx
const char *v13; // rax

if ( *(_DWORD *)(a1 + 64) )
{
v1 = get_next_free_XDisplay();
if ( v1 == -1 )
{
g_log(0LL, 8LL, "Could not get a free X display to use!");
return 0LL;
}
v2 = (const char *)g_getenv("SESSIONCHOOSER_XARGS");
v3 = get_active_vt();
if ( v3 == -1 )
{
v12 = " 2>&1";
if ( !discard_stderr )
v12 = &s1;
if ( !v2 )
v2 = &s1;
v13 = (const char *)sess_session_get_exec_locale(a1);
v6 = (const char *)g_strdup_printf("xinit %s -- :%d %s 1>/dev/null%s", v13, v1, v2, v12);
}
else
{
v4 = " 2>&1";
if ( !discard_stderr )
v4 = &s1;
if ( !v2 )
v2 = &s1;
v5 = (const char *)sess_session_get_exec_locale(a1);
v6 = (const char *)g_strdup_printf("xinit %s -- :%d vt%hd %s 1>/dev/null%s", v5, v1, (unsigned int)v3, v2, v4);
}
}
else
{
v10 = ((__int64 (*)(void))sess_session_get_exec_locale)();
v11 = g_shell_quote(v10);
v6 = (const char *)g_strconcat("sh ", v11, 0LL);
g_free(v11);
}
v7 = strlen(v6);
v8 = write(output_fd, v6, v7);
g_free(v6);
result = 1LL;
if ( v8 == -1 )
{
g_log(0LL, 8LL, "Could not write() to output file descriptor (#%d)!", (unsigned int)output_fd);
result = 0LL;
}
return result;
}

original_code:
gboolean process_session( SessSession *sess )
{
    gchar *command;
    gchar *script_path;
    gshort active_vt;
    const gchar *xargs;
    gint XDisplay;
    ssize_t res;
    if( sess->use_xinit )
    {
        if( ( XDisplay = get_next_free_XDisplay() ) == -1 )
        {
            g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "Could not get a free X display to use!");
            return (0);
        }
        xargs = g_getenv( "SESSIONCHOOSER_XARGS" );
        if( ( active_vt = get_active_vt() ) != -1 )
        {
            command = g_strdup_printf( "xinit %s -- :%d vt%hd %s "
                            "1>/dev/null%s",
                        sess_session_get_exec_locale( sess ), XDisplay,
                        active_vt, xargs ? xargs : "",
                        discard_stderr ? " 2>&1" : "" );
        }
        else
        {
            command = g_strdup_printf( "xinit %s -- :%d %s "
                            "1>/dev/null%s",
                        sess_session_get_exec_locale( sess ), XDisplay,
                        xargs ? xargs : "",
                        discard_stderr ? " 2>&1" : "" );
        }
    }
    else
    {
        script_path = g_shell_quote( sess_session_get_exec_locale( sess ) );
        command = g_strconcat( "sh ", script_path, ((void *)0) );
        g_free( script_path );
    }
    res = write( output_fd, command, strlen( command ) );
    g_free( command );
    if( res == -1 )
    {
        g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "Could not write() to output file descriptor (#%d)!", output_fd);
        return (0);
    }
    return (!(0));
}

canonical_original_code:
int process_session(struct SessSession *sess)
{
    char *command;
    char *script_path;
    short active_vt;
    char *xargs;
    int XDisplay;
    long res;
    if( sess->use_xinit )
    {
        if( ( XDisplay = get_next_free_XDisplay() ) == -1 )
        {
            g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "Could not get a free X display to use!");
            return (0);
        }
        xargs = g_getenv( "SESSIONCHOOSER_XARGS" );
        if( ( active_vt = get_active_vt() ) != -1 )
        {
            command = g_strdup_printf( "xinit %s -- :%d vt%hd %s "
                            "1>/dev/null%s",
                        sess_session_get_exec_locale( sess ), XDisplay,
                        active_vt, xargs ? xargs : "",
                        discard_stderr ? " 2>&1" : "" );
        }
        else
        {
            command = g_strdup_printf( "xinit %s -- :%d %s "
                            "1>/dev/null%s",
                        sess_session_get_exec_locale( sess ), XDisplay,
                        xargs ? xargs : "",
                        discard_stderr ? " 2>&1" : "" );
        }
    }
    else
    {
        script_path = g_shell_quote( sess_session_get_exec_locale( sess ) );
        command = g_strconcat( "sh ", script_path, ((void *)0) );
        g_free( script_path );
    }
    res = write( output_fd, command, strlen( command ) );
    g_free( command );
    if( res == -1 )
    {
        g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "Could not write() to output file descriptor (#%d)!", output_fd);
        return (0);
    }
    return (!(0));
}

variable_types: struct SessSession { char *name; char *name_coll_key_case; char *name_locale; char *path; char *path_normalized; char *path_coll_key; char *exec; char *exec_locale; int use_xinit; } *

variable_types:
command
char *

variable_types:
xargs
char *

variable_types: XDisplay int

variable_types: res long