acceptWithLogger

decompiled_code:
__int64 __fastcall acceptWithLogger(int fd)
{
int v2; // eax
int v3; // ebp
unsigned __int16 v4; // r12
char *v5; // rax
char *v7; // rdi
int v8; // er12
__int64 v9; // r14
__int64 v10; // rax
char *v11; // r13
int v12; // er12
__int64 v13; // r14
__int64 v14; // r14
__int64 v15; // rax
socklen_t len; // [rsp+Ch] [rbp-1DCh] BYREF
struct sockaddr s[16]; // [rsp+10h] [rbp-1D8h] BYREF
struct timeval timeout; // [rsp+110h] [rbp-D8h] BYREF
fd_set readfds; // [rsp+120h] [rbp-C8h] BYREF
socklen_t addr_len; // [rsp+1ACh] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+1B0h] [rbp-38h] 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));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
v2 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( v2 )
{
v3 = v2;
if ( v2 == -1 )
{
sprintf((char *)s, "Error. select was failed: %s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "acceptWithLogger", 157LL, s);
}
else
{
v3 = accept(fd, &addr, &addr_len);
if ( (unsigned int)isUseInLog("Server IP address:") )
{
len = 16;
getsockname(v3, s, &len);
v7 = inet_ntoa(*(struct in_addr *)&s[0].sa_data[2]);
v8 = strlen(v7);
v9 = getLogeW3CLog();
*(_QWORD *)(v9 + 48) = malloc(v8 + 1);
v10 = getLogeW3CLog();
strcpy(*(char **)(v10 + 48), v7);
}
if ( v3 < 0 )
{
sprintf((char *)s, "Error. DeskriptionClient wasn't opened: %s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "acceptWithLogger", 181LL, s);
v3 = -1;
}
}
}
else
{
v3 = -2;
}
if ( (unsigned int)isUseInLog("Client IP address:") )
{
v11 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
v12 = strlen(v11);
v13 = getLogeW3CLog();
*(_QWORD *)(v13 + 16) = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
v14 = getLogeW3CLog();
*(_QWORD *)(v14 + 16) = malloc(v12 + 1);
v15 = getLogeW3CLog();
strcpy(*(char **)(v15 + 16), v11);
}
v4 = _bswap_16(*(__int16 *)addr.sa_data);
v5 = 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,
v5,
v4,
(unsigned int)v3);
writeLog("workWithSockets.c", "acceptWithLogger", 199LL, s);
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd)
{
int v2; // eax
int v3; // ebp
unsigned __int16 v4; // r12
char *v5; // rax
char *v7; // rdi
int v8; // er12
__int64 v9; // r14
__int64 v10; // rax
char *v11; // r13
int v12; // er12
__int64 v13; // r14
__int64 v14; // r14
__int64 v15; // rax
socklen_t len; // [rsp+Ch] [rbp-1DCh] BYREF
struct sockaddr s[16]; // [rsp+10h] [rbp-1D8h] BYREF
struct timeval timeout; // [rsp+110h] [rbp-D8h] BYREF
fd_set readfds; // [rsp+120h] [rbp-C8h] BYREF
socklen_t addr_len; // [rsp+1ACh] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+1B0h] [rbp-38h] 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));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
v2 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( v2 )
{
v3 = v2;
if ( v2 == -1 )
{
sprintf((char *)s, "Error. select was failed: %s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "acceptWithLogger", 157LL, s);
}
else
{
v3 = accept(fd, &addr, &addr_len);
if ( (unsigned int)isUseInLog("Server IP address:") )
{
len = 16;
getsockname(v3, s, &len);
v7 = inet_ntoa(*(struct in_addr *)&s[0].sa_data[2]);
v8 = strlen(v7);
v9 = getLogeW3CLog();
*(_QWORD *)(v9 + 48) = malloc(v8 + 1);
v10 = getLogeW3CLog();
strcpy(*(char **)(v10 + 48), v7);
}
if ( v3 < 0 )
{
sprintf((char *)s, "Error. DeskriptionClient wasn't opened: %s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "acceptWithLogger", 181LL, s);
v3 = -1;
}
}
}
else
{
v3 = -2;
}
if ( (unsigned int)isUseInLog("Client IP address:") )
{
v11 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
v12 = strlen(v11);
v13 = getLogeW3CLog();
*(_QWORD *)(v13 + 16) = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
v14 = getLogeW3CLog();
*(_QWORD *)(v14 + 16) = malloc(v12 + 1);
v15 = getLogeW3CLog();
strcpy(*(char **)(v15 + 16), v11);
}
v4 = func0(*(__int16 *)addr.sa_data);
v5 = 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,
v5,
v4,
(unsigned int)v3);
writeLog("workWithSockets.c", "acceptWithLogger", 199LL, s);
return (unsigned int)v3;
}

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

repo: TarasDumin/ServerHttp

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
char s[256]; // [rsp+0h] [rbp-1B8h] BYREF
struct timeval timeout; // [rsp+100h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+110h] [rbp-A8h] 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));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
timeout.tv_sec = (int)a4;
timeout.tv_usec = 0LL;
v6 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
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
char s[256]; // [rsp+0h] [rbp-1B8h] BYREF
struct timeval timeout; // [rsp+100h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+110h] [rbp-A8h] 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));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
timeout.tv_sec = (int)a4;
timeout.tv_usec = 0LL;
v6 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
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]

return_type: int

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


sendAll

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

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

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

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

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:
char *getTimeS()
{
char *v0; // rax
int v1; // ebx
char *v2; // rbp
char *result; // rax
time_t timer; // [rsp+8h] [rbp-40h] BYREF
char dest[56]; // [rsp+10h] [rbp-38h] BYREF

timer = time(0LL);
v0 = ctime(&timer);
strcpy(dest, v0);
v1 = strlen(dest);
v2 = (char *)malloc(v1 + 1);
result = strcpy(v2, dest);
v2[v1 - 1] = 0;
return result;
}

canonical_decompiled_code:
char *func0()
{
char *v0; // rax
int v1; // ebx
char *v2; // rbp
char *result; // rax
time_t timer; // [rsp+8h] [rbp-40h] BYREF
char dest[56]; // [rsp+10h] [rbp-38h] BYREF

timer = time(0LL);
v0 = ctime(&timer);
strcpy(dest, v0);
v1 = strlen(dest);
v2 = (char *)malloc(v1 + 1);
result = strcpy(v2, dest);
v2[v1 - 1] = 0;
return result;
}

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)
{
const __int32_t **v2; // r12
unsigned __int64 v3; // rbx
size_t result; // rax

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

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

v2 = _ctype_tolower_loc();
v3 = 0LL;
do
{
*(_BYTE *)(a2 + v3) = (*v2)[s[v3]];
++v3;
result = strlen(s) + 1;
}
while ( result > v3 );
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

return_type: void


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; // ebx
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_op = 0;
v0 = semIdW3C;
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_6C8,
(const char *)qword_6B0,
(const char *)ptr,
(const char *)W3CLog,
(const char *)qword_6B8,
(const char *)qword_6C0,
(const char *)qword_6D0,
(const char *)qword_6D8,
(const char *)qword_6E0,
(const char *)qword_6E8,
(const char *)qword_6F0,
(const char *)qword_700,
(const char *)qword_710,
(const char *)qword_718,
(const char *)qword_720,
(const char *)qword_728,
(const char *)qword_730,
(const char *)qword_738,
(const char *)qword_740,
(const char *)qword_748);
if ( isUseInLog((__int64)"HTTPStatus:") )
fprintf(debugLogin, "%d ", (unsigned int)dword_6F8);
if ( isUseInLog((__int64)"BytesSent:") )
fprintf(debugLogin, "%d ", (unsigned int)dword_708);
fputc(10, debugLogin);
fclose(debugLogin);
sops.sem_op = -1;
return semop(semIdW3C, &sops, 1uLL);
}

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

sops.sem_op = 0;
v0 = semIdW3C;
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_6C8,
(const char *)qword_6B0,
(const char *)ptr,
(const char *)W3CLog,
(const char *)qword_6B8,
(const char *)qword_6C0,
(const char *)qword_6D0,
(const char *)qword_6D8,
(const char *)qword_6E0,
(const char *)qword_6E8,
(const char *)qword_6F0,
(const char *)qword_700,
(const char *)qword_710,
(const char *)qword_718,
(const char *)qword_720,
(const char *)qword_728,
(const char *)qword_730,
(const char *)qword_738,
(const char *)qword_740,
(const char *)qword_748);
if ( func0((__int64)"HTTPStatus:") )
fprintf(debugLogin, "%d ", (unsigned int)dword_6F8);
if ( func0((__int64)"BytesSent:") )
fprintf(debugLogin, "%d ", (unsigned int)dword_708);
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_6C8 + 8 == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
return qword_6C8 + 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; // rbx
void *v1; // rbx
void *v2; // rbx
void *v3; // rbx
void *v4; // rbx
void *v5; // rbx
void *v6; // rbx
void *v7; // rbx
void *v8; // rbx
void *v9; // rbx
void *v10; // rbx
void *v11; // rbx
void *v12; // rbx
void *v13; // rbx
void *v14; // rbx
void *v15; // rbx
void *v16; // rbx
__int64 result; // rax

v0 = W3CLog;
if ( !isEmptyLogDate((__int64)W3CLog) )
{
free(v0);
W3CLog = (void *)(qword_6C8 + 8);
}
v1 = ptr;
if ( !isEmptyLogDate((__int64)ptr) )
{
free(v1);
ptr = (void *)(qword_6C8 + 8);
}
v2 = qword_6B8;
if ( !isEmptyLogDate((__int64)qword_6B8) )
{
free(v2);
qword_6B8 = (void *)(qword_6C8 + 8);
}
v3 = qword_6C0;
if ( !isEmptyLogDate((__int64)qword_6C0) )
{
free(v3);
qword_6C0 = (void *)(qword_6C8 + 8);
}
v4 = qword_6D8;
if ( !isEmptyLogDate((__int64)qword_6D8) )
{
free(v4);
qword_6D8 = (void *)(qword_6C8 + 8);
}
v5 = qword_6E0;
if ( !isEmptyLogDate((__int64)qword_6E0) )
{
free(v5);
qword_6E0 = (void *)(qword_6C8 + 8);
}
v6 = qword_6E8;
if ( !isEmptyLogDate((__int64)qword_6E8) )
{
free(v6);
qword_6E8 = (void *)(qword_6C8 + 8);
}
v7 = qword_6F0;
if ( !isEmptyLogDate((__int64)qword_6F0) )
{
free(v7);
qword_6F0 = (void *)(qword_6C8 + 8);
}
dword_6F8 = 0;
v8 = qword_700;
if ( !isEmptyLogDate((__int64)qword_700) )
{
free(v8);
qword_700 = (void *)(qword_6C8 + 8);
}
dword_708 = 0;
v9 = qword_710;
if ( !isEmptyLogDate((__int64)qword_710) )
{
free(v9);
qword_710 = (void *)(qword_6C8 + 8);
}
v10 = qword_718;
if ( !isEmptyLogDate((__int64)qword_718) )
{
free(v10);
qword_718 = (void *)(qword_6C8 + 8);
}
v11 = qword_720;
if ( !isEmptyLogDate((__int64)qword_720) )
{
free(v11);
qword_720 = (void *)(qword_6C8 + 8);
}
v12 = qword_728;
if ( !isEmptyLogDate((__int64)qword_728) )
{
free(v12);
qword_728 = (void *)(qword_6C8 + 8);
}
v13 = qword_730;
if ( !isEmptyLogDate((__int64)qword_730) )
{
free(v13);
qword_730 = (void *)(qword_6C8 + 8);
}
v14 = qword_738;
if ( !isEmptyLogDate((__int64)qword_738) )
{
free(v14);
qword_738 = (void *)(qword_6C8 + 8);
}
v15 = qword_740;
if ( !isEmptyLogDate((__int64)qword_740) )
{
free(v15);
qword_740 = (void *)(qword_6C8 + 8);
}
v16 = qword_748;
result = isEmptyLogDate((__int64)qword_748);
if ( !(_DWORD)result )
{
free(v16);
result = qword_6C8 + 8;
qword_748 = (void *)(qword_6C8 + 8);
}
return result;
}

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

v0 = W3CLog;
if ( !func4((__int64)W3CLog) )
{
free(v0);
W3CLog = (void *)(qword_6C8 + 8);
}
v1 = ptr;
if ( !func4((__int64)ptr) )
{
free(v1);
ptr = (void *)(qword_6C8 + 8);
}
v2 = qword_6B8;
if ( !func4((__int64)qword_6B8) )
{
free(v2);
qword_6B8 = (void *)(qword_6C8 + 8);
}
v3 = qword_6C0;
if ( !func4((__int64)qword_6C0) )
{
free(v3);
qword_6C0 = (void *)(qword_6C8 + 8);
}
v4 = qword_6D8;
if ( !func4((__int64)qword_6D8) )
{
free(v4);
qword_6D8 = (void *)(qword_6C8 + 8);
}
v5 = qword_6E0;
if ( !func4((__int64)qword_6E0) )
{
free(v5);
qword_6E0 = (void *)(qword_6C8 + 8);
}
v6 = qword_6E8;
if ( !func4((__int64)qword_6E8) )
{
free(v6);
qword_6E8 = (void *)(qword_6C8 + 8);
}
v7 = qword_6F0;
if ( !func4((__int64)qword_6F0) )
{
free(v7);
qword_6F0 = (void *)(qword_6C8 + 8);
}
dword_6F8 = 0;
v8 = qword_700;
if ( !func4((__int64)qword_700) )
{
free(v8);
qword_700 = (void *)(qword_6C8 + 8);
}
dword_708 = 0;
v9 = qword_710;
if ( !func4((__int64)qword_710) )
{
free(v9);
qword_710 = (void *)(qword_6C8 + 8);
}
v10 = qword_718;
if ( !func4((__int64)qword_718) )
{
free(v10);
qword_718 = (void *)(qword_6C8 + 8);
}
v11 = qword_720;
if ( !func4((__int64)qword_720) )
{
free(v11);
qword_720 = (void *)(qword_6C8 + 8);
}
v12 = qword_728;
if ( !func4((__int64)qword_728) )
{
free(v12);
qword_728 = (void *)(qword_6C8 + 8);
}
v13 = qword_730;
if ( !func4((__int64)qword_730) )
{
free(v13);
qword_730 = (void *)(qword_6C8 + 8);
}
v14 = qword_738;
if ( !func4((__int64)qword_738) )
{
free(v14);
qword_738 = (void *)(qword_6C8 + 8);
}
v15 = qword_740;
if ( !func4((__int64)qword_740) )
{
free(v15);
qword_740 = (void *)(qword_6C8 + 8);
}
v16 = qword_748;
result = func4((__int64)qword_748);
if ( !(_DWORD)result )
{
free(v16);
result = qword_6C8 + 8;
qword_748 = (void *)(qword_6C8 + 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)
{
int v6; // er13
char *v7; // r13
unsigned int v8; // eax
time_t v10; // [rsp+0h] [rbp-38h] BYREF
struct sembuf sops; // [rsp+Ah] [rbp-2Eh] BYREF

v10 = time(0LL);
sops.sem_op = 0;
v6 = semId;
semop(semId, &sops, 1uLL);
sops.sem_op = 1;
semop(v6, &sops, 1uLL);
debugLogin = fopen("debugLogFile.txt", "a+");
fflush(stdout);
v7 = ctime(&v10);
v8 = getpid();
fprintf(debugLogin, "---pid: %d | File: %s | Func: %s | line: %d -- %s%s\n", v8, a1, a2, a3, v7, 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)
{
int v6; // er13
char *v7; // r13
unsigned int v8; // eax
time_t v10; // [rsp+0h] [rbp-38h] BYREF
struct sembuf sops; // [rsp+Ah] [rbp-2Eh] BYREF

v10 = time(0LL);
sops.sem_op = 0;
v6 = semId;
semop(semId, &sops, 1uLL);
sops.sem_op = 1;
semop(v6, &sops, 1uLL);
debugLogin = fopen("debugLogFile.txt", "a+");
fflush(stdout);
v7 = ctime(&v10);
v8 = getpid();
fprintf(debugLogin, "---pid: %d | File: %s | Func: %s | line: %d -- %s%s\n", v8, a1, a2, a3, v7, 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

canonical_name: main

repo: Tatk/PasswordGenerator

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

v3 = time(0LL);
srand(v3);
puts(" For help use command '-h' ");
v4 = 0;
v18 = 1;
v5 = 8;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "hl:Anpc:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case '?':
puts("Error found !");
v18 = 0;
v5 = 0;
break;
case 'A':
v4 += 5;
break;
case 'c':
if ( atoi(_bss_start) <= 0 )
printf("Error! Please, try again!");
else
v18 = 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
v5 = atoi(_bss_start);
break;
case 'n':
v4 += 7;
break;
case 'p':
v4 += 11;
break;
default:
continue;
}
}
v7 = v18;
if ( v18 )
{
if ( v5 )
{
v15 = (__int64 *)&v15;
v17 = v18;
v9 = alloca(v18 * (__int64)v5);
puts("Your password(s): ");
if ( v7 > 0 )
{
v10 = (unsigned int)(v5 - 1);
v11 = (char *)&v15 + v10 + 1;
v12 = 0;
v16 = ~v10;
do
{
printf("%d) ", (unsigned int)++v12);
if ( v5 > 0 )
{
v13 = &v11[v16];
do
{
v14 = get_rand(v4);
*v13 = v14;
putchar(v14);
++v13;
}
while ( v13 != v11 );
}
putchar(10);
v11 += v17;
}
while ( v18 != v12 );
}
}
}
return 0;
}

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

v3 = time(0LL);
srand(v3);
puts(" For help use command '-h' ");
v4 = 0;
v18 = 1;
v5 = 8;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "hl:Anpc:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case '?':
puts("Error found !");
v18 = 0;
v5 = 0;
break;
case 'A':
v4 += 5;
break;
case 'c':
if ( atoi(_bss_start) <= 0 )
printf("Error! Please, try again!");
else
v18 = 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
v5 = atoi(_bss_start);
break;
case 'n':
v4 += 7;
break;
case 'p':
v4 += 11;
break;
default:
continue;
}
}
v7 = v18;
if ( v18 )
{
if ( v5 )
{
v15 = (__int64 *)&v15;
v17 = v18;
v9 = alloca(v18 * (__int64)v5);
puts("Your password(s): ");
if ( v7 > 0 )
{
v10 = (unsigned int)(v5 - 1);
v11 = (char *)&v15 + v10 + 1;
v12 = 0;
v16 = ~v10;
do
{
printf("%d) ", (unsigned int)++v12);
if ( v5 > 0 )
{
v13 = &v11[v16];
do
{
v14 = func10(v4);
*v13 = v14;
putchar(v14);
++v13;
}
while ( v13 != v11 );
}
putchar(10);
v11 += v17;
}
while ( v18 != v12 );
}
}
}
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; // er12
const char *v2; // rbp
__int16 v3; // r13
const char *v4; // r14
const char *v5; // rax
const char *v6; // rbx
__int64 result; // rax
const char *v8; // r13
const char *v9; // rax
__int64 v10; // rax
__int64 v11; // rbp
size_t v12; // rax
ssize_t v13; // rbp

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 )
{
v8 = " 2>&1";
if ( !discard_stderr )
v8 = (const char *)&unk_D7C;
if ( !v2 )
v2 = (const char *)&unk_D7C;
v9 = (const char *)sess_session_get_exec_locale(a1);
v6 = (const char *)g_strdup_printf("xinit %s -- :%d %s 1>/dev/null%s", v9, v1, v2, v8);
}
else
{
v4 = " 2>&1";
if ( !discard_stderr )
v4 = (const char *)&unk_D7C;
if ( !v2 )
v2 = (const char *)&unk_D7C;
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);
}
v12 = strlen(v6);
v13 = write(output_fd, v6, v12);
g_free(v6);
result = 1LL;
if ( v13 == -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; // er12
const char *v2; // rbp
__int16 v3; // r13
const char *v4; // r14
const char *v5; // rax
const char *v6; // rbx
__int64 result; // rax
const char *v8; // r13
const char *v9; // rax
__int64 v10; // rax
__int64 v11; // rbp
size_t v12; // rax
ssize_t v13; // rbp

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 )
{
v8 = " 2>&1";
if ( !discard_stderr )
v8 = (const char *)&unk_D7C;
if ( !v2 )
v2 = (const char *)&unk_D7C;
v9 = (const char *)sess_session_get_exec_locale(a1);
v6 = (const char *)g_strdup_printf("xinit %s -- :%d %s 1>/dev/null%s", v9, v1, v2, v8);
}
else
{
v4 = " 2>&1";
if ( !discard_stderr )
v4 = (const char *)&unk_D7C;
if ( !v2 )
v2 = (const char *)&unk_D7C;
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);
}
v12 = strlen(v6);
v13 = write(output_fd, v6, v12);
g_free(v6);
result = 1LL;
if ( v13 == -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


decompiled_code:
_BOOL8 __fastcall ask_for_session(_QWORD *a1, const char *a2)
{
__int64 v2; // rbx
FILE *v3; // r13
char *v4; // rax
char *v5; // r13
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // r13
_BOOL4 v9; // er15
char *v10; // rax
FILE *v11; // r13
char *v12; // rax
FILE *v13; // r13
char *v14; // rax
FILE *v15; // r13
const char *v16; // rax
char *v18; // rax
unsigned int v19; // eax
char *v20; // rax
char *v21; // rax
const char *v22; // rbx
int v23; // [rsp+Ch] [rbp-7Ch]
char *endptr; // [rsp+18h] [rbp-70h] BYREF
char s[40]; // [rsp+20h] [rbp-68h] BYREF
__int64 v26[8]; // [rsp+48h] [rbp-40h] BYREF

v26[0] = 0LL;
if ( a2 )
{
if ( *a2 )
{
v2 = sess_session_find_by_path_normalized();
v23 = 0;
}
else
{
v23 = 1;
v2 = 0LL;
}
}
else
{
v2 = 0LL;
v23 = 0;
}
while ( 1 )
{
if ( !no_clear_screen )
terminfo_clear_screen();
v11 = stdout;
v12 = dcgettext(0LL, "Welcome, please choose a session!\n", 5);
fputs(v12, v11);
if ( !no_lastsession )
{
v3 = stdout;
v4 = dcgettext(0LL, "Append '!' to the number to prevent remembering your choice.\n\n", 5);
fputs(v4, v3);
}
v13 = stdout;
v14 = dcgettext(0LL, " (0) continue using the current shell\n", 5);
fputs(v14, v13);
sess_num = 1;
g_ptr_array_foreach(*a1, display_session, 0LL);
if ( v2 )
{
v5 = *(_DWORD *)(v2 + 64) ? dcgettext(0LL, "\nYour choice [%s]: ", 5) : dcgettext(
0LL,
"\nYour choice [Text: %s]: ",
5);
v6 = sess_session_get_name_locale(v2);
g_printf(v5, v6, v7);
}
else
{
v15 = stdout;
v16 = v23 ? dcgettext(0LL, "\nYour choice [<current shell>]: ", 5) : dcgettext(0LL, "\nYour choice: ", 5);
fputs(v16, v15);
}
if ( !fgets(s, 32, stdin) )
return 0LL;
g_strchug(s);
if ( s[0] )
{
v19 = strtoul(s, &endptr, 10);
if ( endptr == s )
{
v20 = dcgettext(0LL, "Please enter a number.", 5);
puts(v20);
sleep(1u);
}
else
{
v9 = *endptr == 33;
if ( !v19 )
goto LABEL_26;
if ( *(_DWORD *)(*a1 + 8LL) < v19 )
{
v21 = dcgettext(0LL, "No such session. Please try again...", 5);
puts(v21);
sleep(1u);
}
else
{
v8 = *(_QWORD *)(*(_QWORD *)*a1 + 8LL * (v19 - 1));
LABEL_11:
if ( (unsigned int)process_session(v8) )
{
if ( no_lastsession | v9 )
return v8 != 0;
if ( v8 )
v22 = (const char *)sess_session_get_path_normalized(v8);
else
v22 = (const char *)&unk_D7C;
goto LABEL_38;
}
v10 = dcgettext(0LL, "Could not process session! Please try again...", 5);
puts(v10);
sleep(1u);
}
}
}
else
{
v8 = v2;
v9 = 0;
if ( v2 )
goto LABEL_11;
if ( v23 )
{
v9 = 0;
LABEL_26:
v8 = 0LL;
if ( no_lastsession | v9 )
return v8 != 0;
v8 = 0LL;
v22 = (const char *)&unk_D7C;
LABEL_38:
if ( (!a2 || strcmp(v22, a2)) && !(unsigned int)set_last_session(v22, v26) )
{
g_log(0LL, 16LL, "Could not save last used session: %s", *(const char **)(v26[0] + 8));
g_error_free(v26[0]);
}
return v8 != 0;
}
v18 = dcgettext(0LL, "There is no default session! Please make a choice.", 5);
puts(v18);
sleep(1u);
}
}
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_QWORD *a1, const char *a2)
{
__int64 v2; // rbx
FILE *v3; // r13
char *v4; // rax
char *v5; // r13
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // r13
_BOOL4 v9; // er15
char *v10; // rax
FILE *v11; // r13
char *v12; // rax
FILE *v13; // r13
char *v14; // rax
FILE *v15; // r13
const char *v16; // rax
char *v18; // rax
unsigned int v19; // eax
char *v20; // rax
char *v21; // rax
const char *v22; // rbx
int v23; // [rsp+Ch] [rbp-7Ch]
char *endptr; // [rsp+18h] [rbp-70h] BYREF
char s[40]; // [rsp+20h] [rbp-68h] BYREF
__int64 v26[8]; // [rsp+48h] [rbp-40h] BYREF

v26[0] = 0LL;
if ( a2 )
{
if ( *a2 )
{
v2 = sess_session_find_by_path_normalized();
v23 = 0;
}
else
{
v23 = 1;
v2 = 0LL;
}
}
else
{
v2 = 0LL;
v23 = 0;
}
while ( 1 )
{
if ( !no_clear_screen )
terminfo_clear_screen();
v11 = stdout;
v12 = dcgettext(0LL, "Welcome, please choose a session!\n", 5);
fputs(v12, v11);
if ( !no_lastsession )
{
v3 = stdout;
v4 = dcgettext(0LL, "Append '!' to the number to prevent remembering your choice.\n\n", 5);
fputs(v4, v3);
}
v13 = stdout;
v14 = dcgettext(0LL, " (0) continue using the current shell\n", 5);
fputs(v14, v13);
sess_num = 1;
g_ptr_array_foreach(*a1, display_session, 0LL);
if ( v2 )
{
v5 = *(_DWORD *)(v2 + 64) ? dcgettext(0LL, "\nYour choice [%s]: ", 5) : dcgettext(
0LL,
"\nYour choice [Text: %s]: ",
5);
v6 = sess_session_get_name_locale(v2);
g_printf(v5, v6, v7);
}
else
{
v15 = stdout;
v16 = v23 ? dcgettext(0LL, "\nYour choice [<current shell>]: ", 5) : dcgettext(0LL, "\nYour choice: ", 5);
fputs(v16, v15);
}
if ( !fgets(s, 32, stdin) )
return 0LL;
g_strchug(s);
if ( s[0] )
{
v19 = strtoul(s, &endptr, 10);
if ( endptr == s )
{
v20 = dcgettext(0LL, "Please enter a number.", 5);
puts(v20);
sleep(1u);
}
else
{
v9 = *endptr == 33;
if ( !v19 )
goto LABEL_26;
if ( *(_DWORD *)(*a1 + 8LL) < v19 )
{
v21 = dcgettext(0LL, "No such session. Please try again...", 5);
puts(v21);
sleep(1u);
}
else
{
v8 = *(_QWORD *)(*(_QWORD *)*a1 + 8LL * (v19 - 1));
LABEL_11:
if ( (unsigned int)func3(v8) )
{
if ( no_lastsession | v9 )
return v8 != 0;
if ( v8 )
v22 = (const char *)sess_session_get_path_normalized(v8);
else
v22 = (const char *)&unk_D7C;
goto LABEL_38;
}
v10 = dcgettext(0LL, "Could not process session! Please try again...", 5);
puts(v10);
sleep(1u);
}
}
}
else
{
v8 = v2;
v9 = 0;
if ( v2 )
goto LABEL_11;
if ( v23 )
{
v9 = 0;
LABEL_26:
v8 = 0LL;
if ( no_lastsession | v9 )
return v8 != 0;
v8 = 0LL;
v22 = (const char *)&unk_D7C;
LABEL_38:
if ( (!a2 || strcmp(v22, a2)) && !(unsigned int)set_last_session(v22, v26) )
{
g_log(0LL, 16LL, "Could not save last used session: %s", *(const char **)(v26[0] + 8));
g_error_free(v26[0]);
}
return v8 != 0;
}
v18 = dcgettext(0LL, "There is no default session! Please make a choice.", 5);
puts(v18);
sleep(1u);
}
}
}

original_code:
gboolean ask_for_session( SessList *session_list, gchar *last_session )
{
    GError *error = ((void *)0);
    unsigned int choice;
    char buf[32];
    char *endptr, *choice_text;
    gchar *session_name;
    SessSession *default_session = ((void *)0);
    SessSession *chosen_session;
    gboolean default_is_current_shell = (0);
    gboolean no_lastsession_override;
    if( last_session )
    {
        if( ! *last_session )
        {
            default_is_current_shell = (!(0));
        }
        else
        {
            default_session = sess_session_find_by_path_normalized( session_list,
                last_session );
        }
    }
    for( ;; )
    {
        if( ! no_clear_screen )
        {
            terminfo_clear_screen();
        }
        fputs( gettext ("Welcome, please choose a session!\n"), stdout );
        if( ! no_lastsession )
        {
            fputs( gettext ("Append '!' to the number to prevent remembering your choice.\n\n"),
                stdout );
        }
        fputs( gettext ("  (0) continue using the current shell\n"), stdout );
        chosen_session = ((void *)0);
        _sess_num = 1;
        no_lastsession_override = (0);
        g_ptr_array_foreach( session_list->list, _display_session, ((void *)0) );
        if( default_session )
        {
            choice_text = default_session->use_xinit
                ? gettext ("\nYour choice [%s]: ")
                : gettext ("\nYour choice [Text: %s]: ");
            g_printf( choice_text,
                sess_session_get_name_locale( default_session ) );
        }
        else if( default_is_current_shell )
        {
            fputs( gettext ("\nYour choice [<current shell>]: "), stdout );
        }
        else {
            fputs( gettext ("\nYour choice: "), stdout );
        }
        if( ! fgets( buf, 32, stdin ) )
        {
            return (0);
        }
        g_strchug( buf );
        if( ! *buf )
        {
            if( default_session )
            {
                chosen_session = default_session;
            }
            else if( ! default_is_current_shell )
            {
                puts( gettext ("There is no default session! Please make a choice.") );
                sleep( 1 );
                continue;
            }
            else
            {
                break;
            }
        }
        else
        {
            choice = strtoul( buf, & endptr, 10 );
            if( endptr == buf )
            {
                puts( gettext ("Please enter a number.") );
                sleep( 1 );
                continue;
            }
            else if( *endptr == '!' )
            {
                no_lastsession_override = (!(0));
            }
            if( ! choice )
            {
                break;
            }
            else if( choice > session_list->list->len )
            {
                puts( gettext ("No such session. Please try again...") );
                sleep( 1 );
                continue;
            }
            chosen_session = ((session_list->list)->pdata)[choice - 1];
        }
        if( process_session( chosen_session ) )
        {
            break;
        }
        puts( gettext ("Could not process session! Please try again...") );
        sleep( 1 );
    }
    if( ! no_lastsession && ! no_lastsession_override )
    {
        session_name = chosen_session
                ? sess_session_get_path_normalized( chosen_session )
                : "";
        if( ( ! last_session || strcmp( session_name, last_session ) != 0 ) &&
            ! set_last_session( session_name, & error ) )
        {
            g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Could not save last used session: %s", error->message);
            g_error_free( error );
        }
    }
    return chosen_session ? (!(0)) : (0);
}

canonical_original_code:
int ask_for_session(struct SessList *session_list, char *last_session)
{
    struct _GError *error = ((void *)0);
    unsigned int choice;
    char buf[32];
    char *endptr; char *choice_text;
    char *session_name;
    struct SessSession *default_session = ((void *)0);
    struct SessSession *chosen_session;
    int default_is_current_shell = (0);
    int no_lastsession_override;
    if( last_session )
    {
        if( ! *last_session )
        {
            default_is_current_shell = (!(0));
        }
        else
        {
            default_session = sess_session_find_by_path_normalized( session_list,
                last_session );
        }
    }
    for( ;; )
    {
        if( ! no_clear_screen )
        {
            terminfo_clear_screen();
        }
        fputs( gettext ("Welcome, please choose a session!\n"), stdout );
        if( ! no_lastsession )
        {
            fputs( gettext ("Append '!' to the number to prevent remembering your choice.\n\n"),
                stdout );
        }
        fputs( gettext ("  (0) continue using the current shell\n"), stdout );
        chosen_session = ((void *)0);
        _sess_num = 1;
        no_lastsession_override = (0);
        g_ptr_array_foreach( session_list->list, _display_session, ((void *)0) );
        if( default_session )
        {
            choice_text = default_session->use_xinit
                ? gettext ("\nYour choice [%s]: ")
                : gettext ("\nYour choice [Text: %s]: ");
            g_printf( choice_text,
                sess_session_get_name_locale( default_session ) );
        }
        else if( default_is_current_shell )
        {
            fputs( gettext ("\nYour choice [<current shell>]: "), stdout );
        }
        else {
            fputs( gettext ("\nYour choice: "), stdout );
        }
        if( ! fgets( buf, 32, stdin ) )
        {
            return (0);
        }
        g_strchug( buf );
        if( ! *buf )
        {
            if( default_session )
            {
                chosen_session = default_session;
            }
            else if( ! default_is_current_shell )
            {
                puts( gettext ("There is no default session! Please make a choice.") );
                sleep( 1 );
                continue;
            }
            else
            {
                break;
            }
        }
        else
        {
            choice = strtoul( buf, & endptr, 10 );
            if( endptr == buf )
            {
                puts( gettext ("Please enter a number.") );
                sleep( 1 );
                continue;
            }
            else if( *endptr == '!' )
            {
                no_lastsession_override = (!(0));
            }
            if( ! choice )
            {
                break;
            }
            else if( choice > session_list->list->len )
            {
                puts( gettext ("No such session. Please try again...") );
                sleep( 1 );
                continue;
            }
            chosen_session = ((session_list->list)->pdata)[choice - 1];
        }
        if( process_session( chosen_session ) )
        {
            break;
        }
        puts( gettext ("Could not process session! Please try again...") );
        sleep( 1 );
    }
    if( ! no_lastsession && ! no_lastsession_override )
    {
        session_name = chosen_session
                ? sess_session_get_path_normalized( chosen_session )
                : "";
        if( ( ! last_session || strcmp( session_name, last_session ) != 0 ) &&
            ! set_last_session( session_name, & error ) )
        {
            g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Could not save last used session: %s", error->message);
            g_error_free( error );
        }
    }
    return chosen_session ? (!(0)) : (0);
}

variable_types: struct SessList { struct _GPtrArray { void **pdata; unsigned int len; } *list; struct _GPtrArray *path_idx; } *

variable_types: struct _GError { unsigned int domain; int code; char *message; } *

variable_types:
choice
unsigned int

variable_types:
buf
char [32]

variable_types:
endptr
char *

user_defined_types: struct SessList { struct _GPtrArray *list; struct _GPtrArray *path_idx; }

user_defined_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; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
__int64 v4; // rbx
char *v5; // rax
const char *v6; // rbx
int v7; // er12
_QWORD *v9; // rbp
const char *v10; // rdi
const char *v11; // rdi
const char **v12; // [rsp+0h] [rbp-38h] BYREF
int v13[3]; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v14[4]; // [rsp+18h] [rbp-20h] BYREF

v13[0] = argc;
v12 = argv;
v14[0] = 0LL;
i18n_init(argc, argv, envp);
v3 = dcgettext(0LL, "- a text-based session chooser", 5);
v4 = g_option_context_new(v3);
opt_ctx = v4;
v5 = dcgettext(
0LL,
"Displays a list of available sessions and prints a command line for the chosen session to the\n"
"file descriptor given by the -o option.",
5);
g_option_context_set_summary(v4, v5);
g_option_context_set_translation_domain(opt_ctx, "sessionchooser");
g_option_context_set_help_enabled(opt_ctx, 0LL);
g_option_context_add_main_entries(opt_ctx, &options, "sessionchooser");
g_option_context_parse(opt_ctx, v13, &v12, v14);
g_option_context_free(opt_ctx);
v6 = (const char *)v14[0];
if ( v14[0] )
{
g_log(0LL, 8LL, "Could not parse options: %s", *(const char **)(v14[0] + 8));
v7 = 1;
}
else if ( isatty(0) )
{
if ( fcntl(output_fd, 1) == -1 )
{
g_log(0LL, 8LL, "File descriptor %d is invalid.", (unsigned int)output_fd);
v7 = 3;
}
else
{
v9 = (_QWORD *)sess_list_new();
v10 = (const char *)g_getenv("SESSIONCHOOSER_XPATH");
if ( !v10 )
v10 = "/usr/share/xsessions:/etc/X11/sessions";
sess_strsplit_foreach(v10, ":", 0xFFFFFFFFLL, &parse_xsession_files_in_dir, v9);
v11 = (const char *)g_getenv("SESSIONCHOOSER_TEXTPATH");
if ( !v11 )
v11 = "/etc/sessionchooser/textsessions";
sess_strsplit_foreach(v11, ":", 0xFFFFFFFFLL, &parse_textsession_files_in_dir, v9);
if ( *(_DWORD *)(*v9 + 8LL) )
{
sess_list_sort(v9);
if ( no_clear_screen || (unsigned int)terminfo_init() )
{
signal(2, sighandler);
if ( !no_lastsession )
v6 = (const char *)get_last_session();
v7 = !ask_for_session(v9, v6);
if ( !no_clear_screen )
terminfo_clear_screen();
close(output_fd);
g_free(v6);
sess_list_free(v9);
}
else
{
g_log(0LL, 8LL, "Could not initialize terminfo DB.");
v7 = 4;
}
}
else
{
sess_list_free(v9);
v7 = 1;
}
}
}
else
{
v7 = 2;
}
return v7;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
__int64 v4; // rbx
char *v5; // rax
const char *v6; // rbx
int v7; // er12
_QWORD *v9; // rbp
const char *v10; // rdi
const char *v11; // rdi
const char **v12; // [rsp+0h] [rbp-38h] BYREF
int v13[3]; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v14[4]; // [rsp+18h] [rbp-20h] BYREF

v13[0] = argc;
v12 = argv;
v14[0] = 0LL;
i18n_init(argc, argv, envp);
v3 = dcgettext(0LL, "- a text-based session chooser", 5);
v4 = g_option_context_new(v3);
opt_ctx = v4;
v5 = dcgettext(
0LL,
"Displays a list of available sessions and prints a command line for the chosen session to the\n"
"file descriptor given by the -o option.",
5);
g_option_context_set_summary(v4, v5);
g_option_context_set_translation_domain(opt_ctx, "sessionchooser");
g_option_context_set_help_enabled(opt_ctx, 0LL);
g_option_context_add_main_entries(opt_ctx, &options, "sessionchooser");
g_option_context_parse(opt_ctx, v13, &v12, v14);
g_option_context_free(opt_ctx);
v6 = (const char *)v14[0];
if ( v14[0] )
{
g_log(0LL, 8LL, "Could not parse options: %s", *(const char **)(v14[0] + 8));
v7 = 1;
}
else if ( isatty(0) )
{
if ( fcntl(output_fd, 1) == -1 )
{
g_log(0LL, 8LL, "File descriptor %d is invalid.", (unsigned int)output_fd);
v7 = 3;
}
else
{
v9 = (_QWORD *)sess_list_new();
v10 = (const char *)g_getenv("SESSIONCHOOSER_XPATH");
if ( !v10 )
v10 = "/usr/share/xsessions:/etc/X11/sessions";
sess_strsplit_foreach(v10, ":", 0xFFFFFFFFLL, &parse_xsession_files_in_dir, v9);
v11 = (const char *)g_getenv("SESSIONCHOOSER_TEXTPATH");
if ( !v11 )
v11 = "/etc/sessionchooser/textsessions";
sess_strsplit_foreach(v11, ":", 0xFFFFFFFFLL, &parse_textsession_files_in_dir, v9);
if ( *(_DWORD *)(*v9 + 8LL) )
{
sess_list_sort(v9);
if ( no_clear_screen || (unsigned int)terminfo_init() )
{
signal(2, sighandler);
if ( !no_lastsession )
v6 = (const char *)get_last_session();
v7 = !func4(v9, v6);
if ( !no_clear_screen )
terminfo_clear_screen();
close(output_fd);
g_free(v6);
sess_list_free(v9);
}
else
{
g_log(0LL, 8LL, "Could not initialize terminfo DB.");
v7 = 4;
}
}
else
{
sess_list_free(v9);
v7 = 1;
}
}
}
else
{
v7 = 2;
}
return v7;
}

original_code:
int main( int argc, char **argv )
{
    GError *error = ((void *)0);
    const gchar *temp;
    gchar *last_session = ((void *)0);
    SessList *session_list;
    int ret = 0;
    i18n_init();
    opt_ctx = g_option_context_new( gettext ("- a text-based session chooser") );
    g_option_context_set_summary( opt_ctx, gettext ("Displays a list of available " "sessions and prints a command line for the chosen session to the\n" "file descriptor given by the -o option.") );
    g_option_context_set_translation_domain( opt_ctx, "sessionchooser" );
    g_option_context_set_help_enabled( opt_ctx, (0) );
    g_option_context_add_main_entries( opt_ctx, options, "sessionchooser" );
    g_option_context_parse( opt_ctx, & argc, & argv, & error );
    g_option_context_free( opt_ctx );
    if( error )
    {
        g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "Could not parse options: %s", error->message);
        return SESS_MAIN_ERROR_OPTPARSE;
    }
    else if( ! isatty( 0 ) )
    {
        return SESS_MAIN_ERROR_NOT_A_TTY;
    }
    else if( fcntl( output_fd, 1 ) == -1 )
    {
        g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "File descriptor %d is invalid.", output_fd);
        return SESS_MAIN_ERROR_INV_OUTFD;
    }
    session_list = sess_list_new();
    temp = g_getenv( "SESSIONCHOOSER_XPATH" );
    if( ! temp )
    {
        temp = "/usr/share/xsessions:/etc/X11/sessions";
    }
    sess_strsplit_foreach( temp, ":", -1,
        parse_xsession_files_in_dir, session_list );
    temp = g_getenv( "SESSIONCHOOSER_TEXTPATH" );
    if( ! temp )
    {
        temp = "/etc/sessionchooser/textsessions";
    }
    sess_strsplit_foreach( temp, ":", -1,
        parse_textsession_files_in_dir, session_list );
    if( ! session_list->list->len )
    {
        sess_list_free( session_list );
        return 1;
    }
    sess_list_sort( session_list );
    if( ! no_clear_screen && ! terminfo_init() )
    {
        g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "Could not initialize terminfo DB.");
        return SESS_MAIN_ERROR_TERMINFO;
    }
    signal( 2, sighandler );
    if( ! no_lastsession )
    {
        last_session = get_last_session();
    }
    if( ! ask_for_session( session_list, last_session ) )
    {
        ret = 1;
    }
    if( ! no_clear_screen )
    {
        terminfo_clear_screen();
    }
    close( output_fd );
    g_free( last_session );
    sess_list_free( session_list );
    return ret;
}

canonical_original_code:
int main(int argc, char **argv)
{
    struct _GError *error = ((void *)0);
    char *temp;
    char *last_session = ((void *)0);
    struct SessList *session_list;
    int ret = 0;
    i18n_init();
    opt_ctx = g_option_context_new( gettext ("- a text-based session chooser") );
    g_option_context_set_summary( opt_ctx, gettext ("Displays a list of available " "sessions and prints a command line for the chosen session to the\n" "file descriptor given by the -o option.") );
    g_option_context_set_translation_domain( opt_ctx, "sessionchooser" );
    g_option_context_set_help_enabled( opt_ctx, (0) );
    g_option_context_add_main_entries( opt_ctx, options, "sessionchooser" );
    g_option_context_parse( opt_ctx, & argc, & argv, & error );
    g_option_context_free( opt_ctx );
    if( error )
    {
        g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "Could not parse options: %s", error->message);
        return SESS_MAIN_ERROR_OPTPARSE;
    }
    else if( ! isatty( 0 ) )
    {
        return SESS_MAIN_ERROR_NOT_A_TTY;
    }
    else if( fcntl( output_fd, 1 ) == -1 )
    {
        g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "File descriptor %d is invalid.", output_fd);
        return SESS_MAIN_ERROR_INV_OUTFD;
    }
    session_list = sess_list_new();
    temp = g_getenv( "SESSIONCHOOSER_XPATH" );
    if( ! temp )
    {
        temp = "/usr/share/xsessions:/etc/X11/sessions";
    }
    sess_strsplit_foreach( temp, ":", -1,
        parse_xsession_files_in_dir, session_list );
    temp = g_getenv( "SESSIONCHOOSER_TEXTPATH" );
    if( ! temp )
    {
        temp = "/etc/sessionchooser/textsessions";
    }
    sess_strsplit_foreach( temp, ":", -1,
        parse_textsession_files_in_dir, session_list );
    if( ! session_list->list->len )
    {
        sess_list_free( session_list );
        return 1;
    }
    sess_list_sort( session_list );
    if( ! no_clear_screen && ! terminfo_init() )
    {
        g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "Could not initialize terminfo DB.");
        return SESS_MAIN_ERROR_TERMINFO;
    }
    signal( 2, sighandler );
    if( ! no_lastsession )
    {
        last_session = get_last_session();
    }
    if( ! ask_for_session( session_list, last_session ) )
    {
        ret = 1;
    }
    if( ! no_clear_screen )
    {
        terminfo_clear_screen();
    }
    close( output_fd );
    g_free( last_session );
    sess_list_free( session_list );
    return ret;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
temp
char *

variable_types: ret int

user_defined_types: struct _GError { unsigned int domain; int code; char *message; }

user_defined_types: struct _GPtrArray { void **pdata; unsigned int len; }


decompiled_code:
__int64 __fastcall sess_strsplit_foreach(__int64 a1, __int64 a2, __int64 a3, void (__fastcall *a4)(__int64, __int64), __int64 a5)
{
_QWORD *v7; // rax
_QWORD *v8; // r13
__int64 v9; // rdi
_QWORD *v10; // rbx

v7 = (_QWORD *)g_strsplit();
v8 = v7;
v9 = *v7;
if ( *v7 )
{
v10 = v7;
do
{
a4(v9, a5);
v9 = *++v10;
}
while ( *v10 );
}
return g_strfreev(v8);
}

original_code:
void sess_strsplit_foreach( const gchar *string, const gchar *delimiter,
                            gint max_tokens, GFunc func, gpointer user_data )
{
    gchar **parts = g_strsplit( string, delimiter, max_tokens );
    gchar **parts_p;
    for( parts_p = parts; *parts_p; parts_p++ )
    {
        func( *parts_p, user_data );
    }
    g_strfreev( parts );
}

canonical_original_code:
void sess_strsplit_foreach(char *string, char *delimiter, int max_tokens, void (*func)(void *data, void *user_data), void *user_data)
{
    char **parts = g_strsplit( string, delimiter, max_tokens );
    char **parts_p;
    for( parts_p = parts; *parts_p; parts_p++ )
    {
        func( *parts_p, user_data );
    }
    g_strfreev( parts );
}

variable_types:
string
char *

variable_types:
delimiter
char *

variable_types:
func
void (*)(void *data, void *user_data)

variable_types:
parts
char **


decompiled_code:
__int64 get_next_free_XDisplay()
{
__int64 v0; // rax
const char *v1; // rbp
int v2; // ebx
int v3; // ebp
size_t i; // rbx
const char *v6; // r12
char *v7; // rax
int v8; // eax
glob_t v9; // [rsp+0h] [rbp-68h] BYREF

v0 = g_get_tmp_dir();
v1 = (const char *)g_build_path("/", v0, ".X[0-9]*-lock", 0LL);
v2 = glob(v1, 69, 0LL, &v9);
g_free(v1);
if ( v2 == 2 )
{
g_log(0LL, 8LL, "Could not glob() for X lock files (read error)!");
globfree(&v9);
v3 = -1;
}
else if ( v2 > 2 )
{
if ( v2 != 3 )
{
LABEL_13:
g_log(0LL, 8LL, "Unhandled glob() return value: %d", (unsigned int)v2);
globfree(&v9);
return (unsigned int)-1;
}
globfree(&v9);
v3 = 0;
}
else
{
if ( v2 )
{
if ( v2 == 1 )
{
g_log(0LL, 4LL, "Out of memory!");
while ( 1 )
;
}
goto LABEL_13;
}
v3 = -1;
for ( i = 0LL; v9.gl_pathc > i; ++i )
{
v6 = v9.gl_pathv[i];
if ( (unsigned int)g_file_test(v6, 1LL) )
{
v7 = strrchr(v6, 47);
if ( v7 )
{
v8 = g_ascii_strtoull(v7 + 3, 0LL, 10LL) + 1;
if ( v3 < v8 )
v3 = v8;
}
else
{
g_assertion_message_expr(0LL, "util.c", 106LL, "get_next_free_XDisplay", "offset != NULL");
}
}
}
globfree(&v9);
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
const char *v1; // rbp
int v2; // ebx
int v3; // ebp
size_t i; // rbx
const char *v6; // r12
char *v7; // rax
int v8; // eax
glob_t v9; // [rsp+0h] [rbp-68h] BYREF

v0 = g_get_tmp_dir();
v1 = (const char *)g_build_path("/", v0, ".X[0-9]*-lock", 0LL);
v2 = glob(v1, 69, 0LL, &v9);
g_free(v1);
if ( v2 == 2 )
{
g_log(0LL, 8LL, "Could not glob() for X lock files (read error)!");
globfree(&v9);
v3 = -1;
}
else if ( v2 > 2 )
{
if ( v2 != 3 )
{
LABEL_13:
g_log(0LL, 8LL, "Unhandled glob() return value: %d", (unsigned int)v2);
globfree(&v9);
return (unsigned int)-1;
}
globfree(&v9);
v3 = 0;
}
else
{
if ( v2 )
{
if ( v2 == 1 )
{
g_log(0LL, 4LL, "Out of memory!");
while ( 1 )
;
}
goto LABEL_13;
}
v3 = -1;
for ( i = 0LL; v9.gl_pathc > i; ++i )
{
v6 = v9.gl_pathv[i];
if ( (unsigned int)g_file_test(v6, 1LL) )
{
v7 = strrchr(v6, 47);
if ( v7 )
{
v8 = g_ascii_strtoull(v7 + 3, 0LL, 10LL) + 1;
if ( v3 < v8 )
v3 = v8;
}
else
{
g_assertion_message_expr(0LL, "util.c", 106LL, "get_next_free_XDisplay", "offset != NULL");
}
}
}
globfree(&v9);
}
return (unsigned int)v3;
}

original_code:
gint get_next_free_XDisplay( void )
{
    char *file;
    char *offset;
    size_t i;
    gint display = -1;
    gint l_display;
    glob_t matches;
    gchar *pattern = g_build_path( "/", g_get_tmp_dir(),
        ".X[0-9]*-lock", ((void *)0) );
    int res = glob( pattern, (1 << 0) | (1 << 2) | (1 << 6), ((void *)0),
        & matches );
    g_free( pattern );
    switch( res )
    {
        case 0:
            break;
        case 3:
            globfree( & matches );
            return 0;
        case 2:
            g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "Could not glob() for X lock files (read error)!");
            globfree( & matches );
            return -1;
        case 1:
            do { g_log (((gchar*) 0), G_LOG_LEVEL_ERROR, "Out of memory!"); for (;;) ; } while (0);
            break;
        default:
            g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "Unhandled glob() return value: %d", res);
            globfree( & matches );
            return -1;
    }
    for( i = 0; i < matches.gl_pathc; i++ )
    {
        file = matches.gl_pathv[i];
        if( ! g_file_test( file, G_FILE_TEST_IS_REGULAR ) )
        {
            continue;
        }
        offset = strrchr( file, '/' );
        do { if (offset != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "util.c", 106, ((const char*) (__func__)), "offset != NULL"); } while (0);
        offset += 3;
        l_display = g_ascii_strtoull( offset, ((void *)0), 10 ) + 1;
        if( l_display > display )
        {
            display = l_display;
        }
    }
    globfree( & matches );
    return display;
}

canonical_original_code:
int get_next_free_XDisplay()
{
    char *file;
    char *offset;
    unsigned long i;
    int display = -1;
    int l_display;
    struct glob_t matches;
    char *pattern = g_build_path( "/", g_get_tmp_dir(),
        ".X[0-9]*-lock", ((void *)0) );
    int res = glob( pattern, (1 << 0) | (1 << 2) | (1 << 6), ((void *)0),
        & matches );
    g_free( pattern );
    switch( res )
    {
        case 0:
            break;
        case 3:
            globfree( & matches );
            return 0;
        case 2:
            g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "Could not glob() for X lock files (read error)!");
            globfree( & matches );
            return -1;
        case 1:
            do { g_log (((char *) 0), G_LOG_LEVEL_ERROR, "Out of memory!"); for (;;) ; } while (0);
            break;
        default:
            g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "Unhandled glob() return value: %d", res);
            globfree( & matches );
            return -1;
    }
    for( i = 0; i < matches.gl_pathc; i++ )
    {
        file = matches.gl_pathv[i];
        if( ! g_file_test( file, G_FILE_TEST_IS_REGULAR ) )
        {
            continue;
        }
        offset = strrchr( file, '/' );
        do { if (offset != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "util.c", 106, ((char *) (__func__)), "offset != NULL"); } while (0);
        offset += 3;
        l_display = g_ascii_strtoull( offset, ((void *)0), 10 ) + 1;
        if( l_display > display )
        {
            display = l_display;
        }
    }
    globfree( & matches );
    return display;
}

variable_types:
file
char *

variable_types:
offset
char *

variable_types:
i
unsigned long

variable_types: display int

variable_types: struct glob_t { unsigned long gl_pathc; char **gl_pathv; unsigned long gl_offs; int gl_flags; void (*gl_closedir)(void *); void *(*gl_readdir)(void *); void *(*gl_opendir)(char *); int (*gl_lstat)(char *, void *); int (*gl_stat)(char *, void *); }

variable_types:
pattern
char *

variable_types: res int


decompiled_code:
__int64 get_active_vt()
{
__int64 result; // rax
unsigned __int16 v1[7]; // [rsp+Ah] [rbp-Eh] BYREF

if ( ioctl(0, 0x5603uLL, v1) == -1 )
result = 0xFFFFFFFFLL;
else
result = v1[0];
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
unsigned __int16 v1[7]; // [rsp+Ah] [rbp-Eh] BYREF

if ( ioctl(0, 0x5603uLL, v1) == -1 )
result = 0xFFFFFFFFLL;
else
result = v1[0];
return result;
}

original_code:
gshort get_active_vt( void )
{
    struct vt_stat vtstat;
    if( ioctl( 0, 0x5603, & vtstat ) == -1 )
    {
        return -1;
    }
    return vtstat.v_active;
}

canonical_original_code:
short get_active_vt()
{
    struct vt_stat vtstat;
    if( ioctl( 0, 0x5603, & vtstat ) == -1 )
    {
        return -1;
    }
    return vtstat.v_active;
}

variable_types: struct vt_stat { unsigned short v_active; unsigned short v_signal; unsigned short v_state; }

return_type: short


decompiled_code:
_BOOL8 terminfo_init()
{
return setupterm(0LL, 1, 0LL) != -1;
}

canonical_decompiled_code:
_BOOL8 func4()
{
return setupterm(0LL, 1, 0LL) != -1;
}

original_code:
gboolean terminfo_init( void )
{
    if( setupterm( ((void *)0), 1, ((void *)0) ) == (-1) )
    {
        return 0;
    }
    return 1;
}

canonical_original_code:
int terminfo_init()
{
    if( setupterm( ((void *)0), 1, ((void *)0) ) == (-1) )
    {
        return 0;
    }
    return 1;
}


decompiled_code:
int terminfo_clear_screen()
{
return putp(*((const char **)cur_term->type.Strings + 5));
}

canonical_decompiled_code:
int func5()
{
return putp(*((const char **)cur_term->type.Strings + 5));
}

original_code:
void terminfo_clear_screen( void )
{
    putp( ((TERMTYPE *)(cur_term))-> Strings[5] );
}

canonical_original_code:
void terminfo_clear_screen()
{
    putp( ((struct termtype *)(cur_term))-> Strings[5] );
}

user_defined_types: struct termtype { char *term_names; char *str_table; char *Booleans; short *Numbers; char **Strings; char *ext_str_table; char **ext_Names; unsigned short num_Booleans; unsigned short num_Numbers; unsigned short num_Strings; unsigned short ext_Booleans; unsigned short ext_Numbers; unsigned short ext_Strings; }


decompiled_code:
__int64 get_last_session()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v0 = g_get_home_dir();
v1 = g_build_filename(v0, ".lastsession", 0LL);
v3 = 0LL;
g_file_get_contents(v1, &v3, 0LL, 0LL);
g_free(v1);
return v3;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v0 = g_get_home_dir();
v1 = g_build_filename(v0, ".lastsession", 0LL);
v3 = 0LL;
g_file_get_contents(v1, &v3, 0LL, 0LL);
g_free(v1);
return v3;
}

original_code:
gchar *get_last_session( void )
{
    gchar *file = g_build_filename( g_get_home_dir(), ".lastsession",
        ((void *)0) );
    gchar *last_session = ((void *)0);
    g_file_get_contents( file, & last_session, ((void *)0), ((void *)0) );
    g_free( file );
    return last_session;
}

canonical_original_code:
char *get_last_session()
{
    char *file = g_build_filename( g_get_home_dir(), ".lastsession",
        ((void *)0) );
    char *last_session = ((void *)0);
    g_file_get_contents( file, & last_session, ((void *)0), ((void *)0) );
    g_free( file );
    return last_session;
}


decompiled_code:
__int64 __fastcall set_last_session(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 result; // rax
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = g_get_home_dir();
v3 = g_build_filename(v2, ".lastsession", 0LL);
v5[0] = 0LL;
g_file_set_contents(v3, a1, -1LL, v5);
g_free(v3);
result = 1LL;
if ( v5[0] )
{
g_propagate_error(a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 result; // rax
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = g_get_home_dir();
v3 = g_build_filename(v2, ".lastsession", 0LL);
v5[0] = 0LL;
g_file_set_contents(v3, a1, -1LL, v5);
g_free(v3);
result = 1LL;
if ( v5[0] )
{
g_propagate_error(a2);
result = 0LL;
}
return result;
}

original_code:
gboolean set_last_session( const gchar *sess_name, GError **error )
{
    gchar *file = g_build_filename( g_get_home_dir(), ".lastsession",
        ((void *)0) );
    GError *int_error = ((void *)0);
    g_file_set_contents( file, sess_name, -1, & int_error );
    g_free( file );
    if( int_error )
    {
        g_propagate_error( error, int_error );
        return 0;
    }
    return 1;
}

canonical_original_code:
int set_last_session(char *sess_name, struct _GError **error)
{
    char *file = g_build_filename( g_get_home_dir(), ".lastsession",
        ((void *)0) );
    struct _GError *int_error = ((void *)0);
    g_file_set_contents( file, sess_name, -1, & int_error );
    g_free( file );
    if( int_error )
    {
        g_propagate_error( error, int_error );
        return 0;
    }
    return 1;
}

variable_types: struct _GError { unsigned int domain; int code; char *message; } **