decompiled_code:
int __fastcall handle_http_get(int a1, const char *a2)
{
const char *v2; // rbp
size_t v3; // rax
struct tm *v4; // rax
int v5; // eax
int v6; // ebp
int v7; // ebx
const char *v8; // rax
char *v9; // rbx
unsigned int v10; // eax
time_t timer; // [rsp+8h] [rbp-10C0h] BYREF
char s[32]; // [rsp+10h] [rbp-10B8h] BYREF
char dest[8]; // [rsp+30h] [rbp-1098h] BYREF
__int64 v15; // [rsp+38h] [rbp-1090h]
__int64 v16; // [rsp+40h] [rbp-1088h]
__int64 v17; // [rsp+48h] [rbp-1080h]
__int64 v18; // [rsp+50h] [rbp-1078h]
__int64 v19; // [rsp+58h] [rbp-1070h]
__int64 v20; // [rsp+60h] [rbp-1068h]
__int64 v21; // [rsp+68h] [rbp-1060h]
__int64 v22; // [rsp+70h] [rbp-1058h]
__int64 v23; // [rsp+78h] [rbp-1050h]
__int64 v24; // [rsp+80h] [rbp-1048h]
__int64 v25; // [rsp+88h] [rbp-1040h]
__int64 v26; // [rsp+90h] [rbp-1038h]
__int64 v27; // [rsp+98h] [rbp-1030h]
__int64 v28; // [rsp+A0h] [rbp-1028h]
__int64 v29; // [rsp+A8h] [rbp-1020h]
char buf[4120]; // [rsp+B0h] [rbp-1018h] BYREF

*(_QWORD *)dest = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
v23 = 0LL;
v24 = 0LL;
v25 = 0LL;
v26 = 0LL;
v27 = 0LL;
v28 = 0LL;
v29 = 0LL;
v2 = root;
strcpy(dest, root);
v3 = strlen(v2);
strcpy(&dest[v3], a2);
timer = time(0LL);
v4 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v4);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mresponse to client and send file: %s\n", s, dest);
v5 = open(dest, 0);
if ( v5 == -1 )
return send_to_client(a1, "HTTP/1.0 404 Not Found\r\n\r\n", 26);
v6 = v5;
send_to_client(a1, "HTTP/1.0 200 OK\r\n\r\n", 19);
while ( 1 )
{
v7 = read(v6, buf, 0x1000uLL);
if ( v7 <= 0 )
break;
if ( !strcmp(strrchr(dest, 46), ".html") )
{
v8 = (const char *)str_replace(buf, "twitterid", *(_QWORD *)(conf + 8LL));
v9 = (char *)v8;
if ( v8 )
{
v10 = (unsigned int)strstr(v8, "</html>");
send_to_client(a1, v9, v10 - (_DWORD)v9 + 7);
free(v9);
}
}
else
{
send_to_client(a1, buf, v7);
}
}
return close(v6);
}

canonical_decompiled_code:
int __fastcall func1(int a1, const char *a2)
{
const char *v2; // rbp
size_t v3; // rax
struct tm *v4; // rax
int v5; // eax
int v6; // ebp
int v7; // ebx
const char *v8; // rax
char *v9; // rbx
unsigned int v10; // eax
time_t timer; // [rsp+8h] [rbp-10C0h] BYREF
char s[32]; // [rsp+10h] [rbp-10B8h] BYREF
char dest[8]; // [rsp+30h] [rbp-1098h] BYREF
__int64 v15; // [rsp+38h] [rbp-1090h]
__int64 v16; // [rsp+40h] [rbp-1088h]
__int64 v17; // [rsp+48h] [rbp-1080h]
__int64 v18; // [rsp+50h] [rbp-1078h]
__int64 v19; // [rsp+58h] [rbp-1070h]
__int64 v20; // [rsp+60h] [rbp-1068h]
__int64 v21; // [rsp+68h] [rbp-1060h]
__int64 v22; // [rsp+70h] [rbp-1058h]
__int64 v23; // [rsp+78h] [rbp-1050h]
__int64 v24; // [rsp+80h] [rbp-1048h]
__int64 v25; // [rsp+88h] [rbp-1040h]
__int64 v26; // [rsp+90h] [rbp-1038h]
__int64 v27; // [rsp+98h] [rbp-1030h]
__int64 v28; // [rsp+A0h] [rbp-1028h]
__int64 v29; // [rsp+A8h] [rbp-1020h]
char buf[4120]; // [rsp+B0h] [rbp-1018h] BYREF

*(_QWORD *)dest = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
v23 = 0LL;
v24 = 0LL;
v25 = 0LL;
v26 = 0LL;
v27 = 0LL;
v28 = 0LL;
v29 = 0LL;
v2 = root;
strcpy(dest, root);
v3 = strlen(v2);
strcpy(&dest[v3], a2);
timer = time(0LL);
v4 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v4);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mresponse to client and send file: %s\n", s, dest);
v5 = open(dest, 0);
if ( v5 == -1 )
return func0(a1, "HTTP/1.0 404 Not Found\r\n\r\n", 26);
v6 = v5;
func0(a1, "HTTP/1.0 200 OK\r\n\r\n", 19);
while ( 1 )
{
v7 = read(v6, buf, 0x1000uLL);
if ( v7 <= 0 )
break;
if ( !strcmp(strrchr(dest, 46), ".html") )
{
v8 = (const char *)str_replace(buf, "twitterid", *(_QWORD *)(conf + 8LL));
v9 = (char *)v8;
if ( v8 )
{
v10 = (unsigned int)strstr(v8, "</html>");
func0(a1, v9, v10 - (_DWORD)v9 + 7);
free(v9);
}
}
else
{
func0(a1, buf, v7);
}
}
return close(v6);
}

original_code:
static void handle_http_get(int clntSocket, char* file) {
    char data_to_send[BUFSIZE];
    char path[128] = {'\0',};
    int bytes_read;
    int fd;
    strcpy(path, root);
    strcpy(&path[strlen(root)], file);
    do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "response to client and send file: %s" "\n", timestr, path);}while(0);
    if ((fd=open(path, 00)) != -1)
    {
        send_to_client(clntSocket, "HTTP/1.0 200 OK\r\n\r\n", 19);
        while ((bytes_read=read(fd, data_to_send, BUFSIZE)) > 0) {
            if (strcmp(strrchr(path,'.'), ".html") == 0) {
                char *replaced_id = str_replace(data_to_send, "twitterid", conf->TwitterID);
                if (replaced_id) {
                    send_to_client(clntSocket,replaced_id, strstr(replaced_id,"</html>") - replaced_id + 7);
                    free(replaced_id);
                }
            } else {
                send_to_client(clntSocket,data_to_send, bytes_read);
            }
        }
        close(fd);
    }
    else {
        send_to_client(clntSocket, "HTTP/1.0 404 Not Found\r\n\r\n", 26);
    }
}

canonical_original_code:
static void handle_http_get(int clntSocket, char *file) {
    char data_to_send[-1];
    char path[128] = {'\0',};
    int bytes_read;
    int fd;
    strcpy(path, root);
    strcpy(&path[strlen(root)], file);
    do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "response to client and send file: %s" "\n", timestr, path);}while(0);
    if ((fd=open(path, 00)) != -1)
    {
        send_to_client(clntSocket, "HTTP/1.0 200 OK\r\n\r\n", 19);
        while ((bytes_read=read(fd, data_to_send, BUFSIZE)) > 0) {
            if (strcmp(strrchr(path,'.'), ".html") == 0) {
                char *replaced_id = str_replace(data_to_send, "twitterid", conf->TwitterID);
                if (replaced_id) {
                    send_to_client(clntSocket,replaced_id, strstr(replaced_id,"</html>") - replaced_id + 7);
                    free(replaced_id);
                }
            } else {
                send_to_client(clntSocket,data_to_send, bytes_read);
            }
        }
        close(fd);
    }
    else {
        send_to_client(clntSocket, "HTTP/1.0 404 Not Found\r\n\r\n", 26);
    }
}

variable_types:
file
char *

variable_types:
path
char [128]

variable_types: fd int

variable_types: now long

variable_types:
timestr
char [20]


repo: scola/twittrouter

decompiled_code:
const char *__fastcall get_twitter_id(int fd, char *haystack, const char *a3, __int64 a4)
{
char *v5; // rax
char *v6; // rbx
char v7; // dl
__int64 v8; // rax
struct tm *v9; // rax
int v10; // er14
char *v11; // r15
struct tm *v12; // rax
signed __int64 v13; // r15
__int64 v14; // rax
struct tm *v15; // rax
struct tm *v16; // rax
struct tm *v17; // rax
struct tm *v18; // rax
char v19; // dl
struct tm *v21; // rax
time_t timer; // [rsp+18h] [rbp-1080h] BYREF
char s[32]; // [rsp+20h] [rbp-1078h] BYREF
__int64 buf[2]; // [rsp+40h] [rbp-1058h] BYREF
char v26[4080]; // [rsp+50h] [rbp-1048h] BYREF
char nptr[8]; // [rsp+1040h] [rbp-58h] BYREF
__int64 v28; // [rsp+1048h] [rbp-50h]
int v29; // [rsp+1050h] [rbp-48h]

if ( !haystack )
return 0LL;
v5 = strstr(haystack, "Content-Length");
v6 = v5;
if ( v5 )
{
*(_QWORD *)nptr = 0LL;
v28 = 0LL;
v29 = 0;
v7 = v5[16];
if ( v7 != 10 )
{
v8 = 0LL;
do
{
if ( (unsigned __int8)(v7 - 48) > 9u )
{
if ( (unsigned __int8)(v6[v8 + 15] - 48) <= 9u )
break;
}
else
{
nptr[v8] = v7;
}
v7 = v6[++v8 + 16];
}
while ( v7 != 10 );
}
timer = time(0LL);
v9 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v9);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mcontent_length_value = %s\n", s, nptr);
if ( !nptr[0] )
return 0LL;
v10 = atoi(nptr);
v6 = 0LL;
if ( v10 <= 26 )
{
v6 = strstr(haystack, "uname=");
buf[0] = 0LL;
buf[1] = 0LL;
memset(v26, 0, sizeof(v26));
v11 = strstr(haystack, "\r\n\r\n");
timer = time(0LL);
v12 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v12);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mfirst recv length = %d\n", s, a4);
if ( v11 && (v13 = v11 - haystack, !v6) && v13 + v10 + 4 <= a4 )
{
timer = time(0LL);
v15 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v15);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mexpect length = %d\n", s, v13 + v10 + 4);
}
else
{
if ( !v6 )
{
if ( recv(fd, buf, 0x1000uLL, 0) <= 0 )
{
ERROR("recv() failed");
return v6;
}
timer = time(0LL);
v16 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v16);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mget username start\n", s);
timer = time(0LL);
v17 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v17);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0m%s\n", s, (const char *)buf);
timer = time(0LL);
v18 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v18);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mget username finished\n", s);
v6 = strstr((const char *)buf, "uname=");
if ( !v6 )
return v6;
}
v14 = 0LL;
if ( v10 > 6 )
{
while ( 1 )
{
v19 = v6[v14 + 6];
if ( (unsigned __int8)(v19 - 48) > 9u && v19 != 95 && (unsigned __int8)((v19 & 0xDF) - 65) > 0x19u )
break;
a3[v14++] = v19;
if ( v10 - 6 == v14 )
{
timer = time(0LL);
v21 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v21);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0ma friend of twitter %s is verifying...\n\n", s, a3);
return a3;
}
}
}
handle_http_get(fd, "/VERIFY_FAILED.html");
v6 = 0LL;
}
}
}
return v6;
}

canonical_decompiled_code:
const char *__fastcall func2(int fd, char *haystack, const char *a3, __int64 a4)
{
char *v5; // rax
char *v6; // rbx
char v7; // dl
__int64 v8; // rax
struct tm *v9; // rax
int v10; // er14
char *v11; // r15
struct tm *v12; // rax
signed __int64 v13; // r15
__int64 v14; // rax
struct tm *v15; // rax
struct tm *v16; // rax
struct tm *v17; // rax
struct tm *v18; // rax
char v19; // dl
struct tm *v21; // rax
time_t timer; // [rsp+18h] [rbp-1080h] BYREF
char s[32]; // [rsp+20h] [rbp-1078h] BYREF
__int64 buf[2]; // [rsp+40h] [rbp-1058h] BYREF
char v26[4080]; // [rsp+50h] [rbp-1048h] BYREF
char nptr[8]; // [rsp+1040h] [rbp-58h] BYREF
__int64 v28; // [rsp+1048h] [rbp-50h]
int v29; // [rsp+1050h] [rbp-48h]

if ( !haystack )
return 0LL;
v5 = strstr(haystack, "Content-Length");
v6 = v5;
if ( v5 )
{
*(_QWORD *)nptr = 0LL;
v28 = 0LL;
v29 = 0;
v7 = v5[16];
if ( v7 != 10 )
{
v8 = 0LL;
do
{
if ( (unsigned __int8)(v7 - 48) > 9u )
{
if ( (unsigned __int8)(v6[v8 + 15] - 48) <= 9u )
break;
}
else
{
nptr[v8] = v7;
}
v7 = v6[++v8 + 16];
}
while ( v7 != 10 );
}
timer = time(0LL);
v9 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v9);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mcontent_length_value = %s\n", s, nptr);
if ( !nptr[0] )
return 0LL;
v10 = atoi(nptr);
v6 = 0LL;
if ( v10 <= 26 )
{
v6 = strstr(haystack, "uname=");
buf[0] = 0LL;
buf[1] = 0LL;
memset(v26, 0, sizeof(v26));
v11 = strstr(haystack, "\r\n\r\n");
timer = time(0LL);
v12 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v12);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mfirst recv length = %d\n", s, a4);
if ( v11 && (v13 = v11 - haystack, !v6) && v13 + v10 + 4 <= a4 )
{
timer = time(0LL);
v15 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v15);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mexpect length = %d\n", s, v13 + v10 + 4);
}
else
{
if ( !v6 )
{
if ( recv(fd, buf, 0x1000uLL, 0) <= 0 )
{
ERROR("recv() failed");
return v6;
}
timer = time(0LL);
v16 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v16);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mget username start\n", s);
timer = time(0LL);
v17 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v17);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0m%s\n", s, (const char *)buf);
timer = time(0LL);
v18 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v18);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mget username finished\n", s);
v6 = strstr((const char *)buf, "uname=");
if ( !v6 )
return v6;
}
v14 = 0LL;
if ( v10 > 6 )
{
while ( 1 )
{
v19 = v6[v14 + 6];
if ( (unsigned __int8)(v19 - 48) > 9u && v19 != 95 && (unsigned __int8)((v19 & 0xDF) - 65) > 0x19u )
break;
a3[v14++] = v19;
if ( v10 - 6 == v14 )
{
timer = time(0LL);
v21 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v21);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0ma friend of twitter %s is verifying...\n\n", s, a3);
return a3;
}
}
}
func1(fd, "/VERIFY_FAILED.html");
v6 = 0LL;
}
}
}
return v6;
}

original_code:
static char* get_twitter_id(int clntSocket, char *poststr, char *user, ssize_t buffer_len) {
    if(!poststr) return ((void *)0);
    char *content_length = strstr(poststr, "Content-Length");
    if(!content_length) return ((void *)0);
    int i = 0;
    char content_length_value[20] = {'\0',};
    while(*(content_length + 16 + i) != '\n') {
        if(*(content_length + 16 + i) >= '0' && *(content_length + 16 + i) <= '9') {
            content_length_value[i] = *(content_length + 16 + i);
        } else {
            if(*(content_length + 16 + i - 1) >= '0' && *(content_length + 16 + i - 1) <= '9') {
                break;
            }
        }
        i++;
    }
    do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "content_length_value = %s" "\n", timestr,content_length_value);}while(0);
    if (content_length_value[0] == '\0') return ((void *)0);
    int length = atoi(content_length_value);
    if(length - 6 > 20) {
        return ((void *)0);
    }
    char *username = strstr(poststr,"uname=");
    char buffer[BUFSIZE] = {'\0',};
    char *crlf = strstr(poststr,"\r\n\r\n");
    do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "first recv length = %d" "\n", timestr, buffer_len);}while(0);
    if(crlf != ((void *)0) && crlf - poststr + 4 + length <= buffer_len && username == ((void *)0)) {
        do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "expect length = %d" "\n", timestr, crlf - poststr + 4 + length);}while(0);
        return ((void *)0);
    }
    if(username == ((void *)0)) {
        ssize_t numBytesRcvd = recv(clntSocket, buffer, BUFSIZE, 0);
        if (numBytesRcvd <= 0){
            ERROR("recv() failed");
            return ((void *)0);
        }
        do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "get username start" "\n", timestr);}while(0);
        do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "%s" "\n", timestr,buffer);}while(0);
        do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "get username finished" "\n", timestr);}while(0);
        username = strstr(buffer,"uname=");
        if(username == ((void *)0)) return ((void *)0);
    }
    if(length <= 6) {
        handle_http_get(clntSocket, "/VERIFY_FAILED.html");
        return ((void *)0);
    }
    int j = 0;
    char *word = username + 6;
    while(j + 6 < length) {
        if(*(word + j) == '_' ||
        (*(word + j) >= '0' && *(word + j) <= '9') ||
        (*(word + j) >= 'A' && *(word + j) <= 'Z') ||
        (*(word + j) >= 'a' && *(word + j) <= 'z')) {
            user[j] = *(word + j);
            j++;
        } else {
            handle_http_get(clntSocket, "/VERIFY_FAILED.html");
            return ((void *)0);
        }
    }
    do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "a friend of twitter %s is verifying...\n" "\n", timestr, user);}while(0);
    return user;
}

canonical_original_code:
static char *get_twitter_id(int clntSocket, char *poststr, char *user, long buffer_len) {
    if(!poststr) return ((void *)0);
    char *content_length = strstr(poststr, "Content-Length");
    if(!content_length) return ((void *)0);
    int i = 0;
    char content_length_value[20] = {'\0',};
    while(*(content_length + 16 + i) != '\n') {
        if(*(content_length + 16 + i) >= '0' && *(content_length + 16 + i) <= '9') {
            content_length_value[i] = *(content_length + 16 + i);
        } else {
            if(*(content_length + 16 + i - 1) >= '0' && *(content_length + 16 + i - 1) <= '9') {
                break;
            }
        }
        i++;
    }
    do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "content_length_value = %s" "\n", timestr,content_length_value);}while(0);
    if (content_length_value[0] == '\0') return ((void *)0);
    int length = atoi(content_length_value);
    if(length - 6 > 20) {
        return ((void *)0);
    }
    char *username = strstr(poststr,"uname=");
    char buffer[-1] = {'\0',};
    char *crlf = strstr(poststr,"\r\n\r\n");
    do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "first recv length = %d" "\n", timestr, buffer_len);}while(0);
    if(crlf != ((void *)0) && crlf - poststr + 4 + length <= buffer_len && username == ((void *)0)) {
        do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "expect length = %d" "\n", timestr, crlf - poststr + 4 + length);}while(0);
        return ((void *)0);
    }
    if(username == ((void *)0)) {
        long numBytesRcvd = recv(clntSocket, buffer, BUFSIZE, 0);
        if (numBytesRcvd <= 0){
            ERROR("recv() failed");
            return ((void *)0);
        }
        do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "get username start" "\n", timestr);}while(0);
        do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "%s" "\n", timestr,buffer);}while(0);
        do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "get username finished" "\n", timestr);}while(0);
        username = strstr(buffer,"uname=");
        if(username == ((void *)0)) return ((void *)0);
    }
    if(length <= 6) {
        handle_http_get(clntSocket, "/VERIFY_FAILED.html");
        return ((void *)0);
    }
    int j = 0;
    char *word = username + 6;
    while(j + 6 < length) {
        if(*(word + j) == '_' ||
        (*(word + j) >= '0' && *(word + j) <= '9') ||
        (*(word + j) >= 'A' && *(word + j) <= 'Z') ||
        (*(word + j) >= 'a' && *(word + j) <= 'z')) {
            user[j] = *(word + j);
            j++;
        } else {
            handle_http_get(clntSocket, "/VERIFY_FAILED.html");
            return ((void *)0);
        }
    }
    do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "a friend of twitter %s is verifying...\n" "\n", timestr, user);}while(0);
    return user;
}

variable_types: clntSocket int

variable_types:
poststr
char *

variable_types:
user
char *

variable_types: i int

variable_types: length int

variable_types:
username
char *

variable_types:
buffer
char [-1]

variable_types:
crlf
char *

variable_types: numBytesRcvd long

variable_types: j int

variable_types:
word
char *

return_type: char *


SetupTCPServerSocket

decompiled_code:
__int64 __fastcall SetupTCPServerSocket(char *service)
{
struct addrinfo *v1; // rbx
unsigned int v2; // ebp
int v3; // eax
int optval; // [rsp+8h] [rbp-E0h] BYREF
socklen_t len; // [rsp+Ch] [rbp-DCh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-D8h] BYREF
struct addrinfo *pai; // [rsp+98h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+A0h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
req.ai_socktype = 1;
req.ai_protocol = 6;
if ( getaddrinfo(0LL, service, &req, &pai) )
ERROR("getaddrinfo() failed");
v1 = pai;
if ( !pai )
{
v2 = -1;
goto LABEL_13;
}
while ( 1 )
{
v3 = socket(v1->ai_family, v1->ai_socktype, v1->ai_protocol);
v2 = v3;
if ( v3 < 0 )
goto LABEL_6;
optval = 1;
setsockopt(v3, 1, 2, &optval, 4u);
if ( !bind(v2, v1->ai_addr, v1->ai_addrlen) && !listen(v2, 5) )
break;
close(v2);
v2 = -1;
LABEL_6:
v1 = v1->ai_next;
if ( !v1 )
goto LABEL_13;
}
len = 128;
if ( getsockname(v2, &addr, &len) < 0 )
ERROR("getsockname() failed");
fwrite("Binding to ", 1uLL, 0xBuLL, stdout);
PrintSocketAddress(&addr, stdout, 0LL);
fputc(10, stdout);
LABEL_13:
freeaddrinfo(pai);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *service)
{
struct addrinfo *v1; // rbx
unsigned int v2; // ebp
int v3; // eax
int optval; // [rsp+8h] [rbp-E0h] BYREF
socklen_t len; // [rsp+Ch] [rbp-DCh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-D8h] BYREF
struct addrinfo *pai; // [rsp+98h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+A0h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
req.ai_socktype = 1;
req.ai_protocol = 6;
if ( getaddrinfo(0LL, service, &req, &pai) )
ERROR("getaddrinfo() failed");
v1 = pai;
if ( !pai )
{
v2 = -1;
goto LABEL_13;
}
while ( 1 )
{
v3 = socket(v1->ai_family, v1->ai_socktype, v1->ai_protocol);
v2 = v3;
if ( v3 < 0 )
goto LABEL_6;
optval = 1;
setsockopt(v3, 1, 2, &optval, 4u);
if ( !bind(v2, v1->ai_addr, v1->ai_addrlen) && !listen(v2, 5) )
break;
close(v2);
v2 = -1;
LABEL_6:
v1 = v1->ai_next;
if ( !v1 )
goto LABEL_13;
}
len = 128;
if ( getsockname(v2, &addr, &len) < 0 )
ERROR("getsockname() failed");
fwrite("Binding to ", 1uLL, 0xBuLL, stdout);
PrintSocketAddress(&addr, stdout, 0LL);
fputc(10, stdout);
LABEL_13:
freeaddrinfo(pai);
return v2;
}

original_code:
int SetupTCPServerSocket(const char *service) {
    struct addrinfo addrCriteria;
    memset(&addrCriteria, 0, sizeof(addrCriteria));
    addrCriteria.ai_family = 2;
    addrCriteria.ai_flags = 0x0001;
    addrCriteria.ai_socktype = SOCK_STREAM;
    addrCriteria.ai_protocol = IPPROTO_TCP;
    struct addrinfo *servAddr;
    int rtnVal = getaddrinfo(((void *)0), service, &addrCriteria, &servAddr);
    if (rtnVal != 0)
        ERROR("getaddrinfo() failed");
    int servSock = -1;
    for (struct addrinfo *addr = servAddr; addr != ((void *)0); addr = addr->ai_next) {
        servSock = socket(addr->ai_family, addr->ai_socktype,
                addr->ai_protocol);
        if (servSock < 0)
            continue;
        int opt = 1;
        setsockopt(servSock, 1, 2, &opt, sizeof(opt));
        if ((bind(servSock, addr->ai_addr, addr->ai_addrlen) == 0) &&
                (listen(servSock, MAXPENDING) == 0)) {
            struct sockaddr_storage localAddr;
            socklen_t addrSize = sizeof(localAddr);
            if (getsockname(servSock, (struct sockaddr *) &localAddr, &addrSize) < 0)
                ERROR("getsockname() failed");
            fputs("Binding to ", stdout);
            PrintSocketAddress((struct sockaddr *) &localAddr, stdout, 0);
            fputc('\n', stdout);
            break;
        }
        close(servSock);
        servSock = -1;
    }
    freeaddrinfo(servAddr);
    return servSock;
}

canonical_original_code:
int SetupTCPServerSocket(char *service) {
    struct addrinfo addrCriteria;
    memset(&addrCriteria, 0, sizeof(addrCriteria));
    addrCriteria.ai_family = 2;
    addrCriteria.ai_flags = 0x0001;
    addrCriteria.ai_socktype = SOCK_STREAM;
    addrCriteria.ai_protocol = IPPROTO_TCP;
    struct addrinfo *servAddr;
    int rtnVal = getaddrinfo(((void *)0), service, &addrCriteria, &servAddr);
    if (rtnVal != 0)
        ERROR("getaddrinfo() failed");
    int servSock = -1;
    for (struct addrinfo *addr = servAddr; addr != ((void *)0); addr = addr->ai_next) {
        servSock = socket(addr->ai_family, addr->ai_socktype,
                addr->ai_protocol);
        if (servSock < 0)
            continue;
        int opt = 1;
        setsockopt(servSock, 1, 2, &opt, sizeof(opt));
        if ((bind(servSock, addr->ai_addr, addr->ai_addrlen) == 0) &&
                (listen(servSock, MAXPENDING) == 0)) {
            struct sockaddr_storage localAddr;
            unsigned int addrSize = sizeof(localAddr);
            if (getsockname(servSock, (struct sockaddr *) &localAddr, &addrSize) < 0)
                ERROR("getsockname() failed");
            fputs("Binding to ", stdout);
            PrintSocketAddress((struct sockaddr *) &localAddr, stdout, 0);
            fputc('\n', stdout);
            break;
        }
        close(servSock);
        servSock = -1;
    }
    freeaddrinfo(servAddr);
    return servSock;
}

variable_types:
service
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: rtnVal int

variable_types: servSock int

variable_types: opt int

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
addrSize
unsigned int

return_type: int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


AcceptTCPConnection

decompiled_code:
__int64 __fastcall AcceptTCPConnection(int a1)
{
int v1; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-8Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-88h] BYREF

addr_len = 128;
v1 = accept(a1, &addr, &addr_len);
if ( v1 < 0 )
ERROR("accept() failed");
fwrite("Handling client ", 1uLL, 0x10uLL, stdout);
PrintSocketAddress(&addr, stdout, 0LL);
fputc(10, stdout);
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v1; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-8Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-88h] BYREF

addr_len = 128;
v1 = accept(a1, &addr, &addr_len);
if ( v1 < 0 )
ERROR("accept() failed");
fwrite("Handling client ", 1uLL, 0x10uLL, stdout);
PrintSocketAddress(&addr, stdout, 0LL);
fputc(10, stdout);
return (unsigned int)v1;
}

original_code:
int AcceptTCPConnection(int servSock) {
    struct sockaddr_storage clntAddr;
    socklen_t clntAddrLen = sizeof(clntAddr);
    int clntSock = accept(servSock, (struct sockaddr *) &clntAddr, &clntAddrLen);
    if (clntSock < 0)
        ERROR("accept() failed");
    fputs("Handling client ", stdout);
    PrintSocketAddress((struct sockaddr *) &clntAddr, stdout,0);
    fputc('\n', stdout);
    return clntSock;
}

canonical_original_code:
int AcceptTCPConnection(int servSock) {
    struct sockaddr_storage clntAddr;
    unsigned int clntAddrLen = sizeof(clntAddr);
    int clntSock = accept(servSock, (struct sockaddr *) &clntAddr, &clntAddrLen);
    if (clntSock < 0)
        ERROR("accept() failed");
    fputs("Handling client ", stdout);
    PrintSocketAddress((struct sockaddr *) &clntAddr, stdout,0);
    fputc('\n', stdout);
    return clntSock;
}

variable_types:
clntAddrLen
unsigned int

variable_types: clntSock int

user_defined_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

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


HandleTCPClient

decompiled_code:
int __fastcall HandleTCPClient(int fd)
{
ssize_t v2; // rax
__int64 v3; // rbp
struct tm *v4; // rax
struct tm *v5; // rax
int result; // eax
char *v7; // rax
const char *v8; // rax
time_t timer; // [rsp+8h] [rbp-1040h] BYREF
char s[8]; // [rsp+10h] [rbp-1038h] BYREF
__int64 v11; // [rsp+18h] [rbp-1030h]
int v12; // [rsp+20h] [rbp-1028h]
char buf[4120]; // [rsp+30h] [rbp-1018h] BYREF

v2 = recv(fd, buf, 0x1000uLL, 0);
if ( v2 <= 0 )
{
ERROR("recv() failed");
result = close(fd);
}
else
{
v3 = v2;
timer = time(0LL);
v4 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v4);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mfirst recv start\n\n", s);
printf("%s", buf);
timer = time(0LL);
v5 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v5);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mrecv finished\n\n", s);
if ( strstr(buf, "HTTP/1.") )
{
if ( !memcmp(buf, "GET", 3uLL) )
{
strtok(buf, " \t\n");
v7 = strtok(0LL, " \t");
if ( v7 )
{
if ( strcmp(v7, "/favicon.ico") && strcmp(v7, "/twitter-logo-1.png") )
v7 = "/BASEHTML.html";
}
else
{
v7 = "/BASEHTML.html";
}
handle_http_get(fd, v7);
}
else if ( !memcmp(buf, "POST / ", 7uLL) )
{
*(_QWORD *)s = 0LL;
v11 = 0LL;
v12 = 0;
v8 = get_twitter_id(fd, buf, s, v3);
if ( v8 )
handle_http_post(fd, (__int64)v8);
}
}
else
{
send(fd, "HTTP/1.0 400 Bad Request\r\n\r\n", 0x1CuLL, 0);
}
shutdown(fd, 2);
result = close(fd);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(int fd)
{
ssize_t v2; // rax
__int64 v3; // rbp
struct tm *v4; // rax
struct tm *v5; // rax
int result; // eax
char *v7; // rax
const char *v8; // rax
time_t timer; // [rsp+8h] [rbp-1040h] BYREF
char s[8]; // [rsp+10h] [rbp-1038h] BYREF
__int64 v11; // [rsp+18h] [rbp-1030h]
int v12; // [rsp+20h] [rbp-1028h]
char buf[4120]; // [rsp+30h] [rbp-1018h] BYREF

v2 = recv(fd, buf, 0x1000uLL, 0);
if ( v2 <= 0 )
{
ERROR("recv() failed");
result = close(fd);
}
else
{
v3 = v2;
timer = time(0LL);
v4 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v4);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mfirst recv start\n\n", s);
printf("%s", buf);
timer = time(0LL);
v5 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v5);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mrecv finished\n\n", s);
if ( strstr(buf, "HTTP/1.") )
{
if ( !memcmp(buf, "GET", 3uLL) )
{
strtok(buf, " \t\n");
v7 = strtok(0LL, " \t");
if ( v7 )
{
if ( strcmp(v7, "/favicon.ico") && strcmp(v7, "/twitter-logo-1.png") )
v7 = "/BASEHTML.html";
}
else
{
v7 = "/BASEHTML.html";
}
func1(fd, v7);
}
else if ( !memcmp(buf, "POST / ", 7uLL) )
{
*(_QWORD *)s = 0LL;
v11 = 0LL;
v12 = 0;
v8 = func2(fd, buf, s, v3);
if ( v8 )
func3(fd, (__int64)v8);
}
}
else
{
send(fd, "HTTP/1.0 400 Bad Request\r\n\r\n", 0x1CuLL, 0);
}
shutdown(fd, 2);
result = close(fd);
}
return result;
}

original_code:
void HandleTCPClient(int clntSocket) {
    char buffer[BUFSIZE];
    ssize_t numBytesRcvd = recv(clntSocket, buffer, BUFSIZE, 0);
    if (numBytesRcvd <= 0){
        ERROR("recv() failed");
        close(clntSocket);
        return;
    }
    do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "first recv start\n" "\n", timestr);}while(0);
    printf("%s",buffer);
    do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "recv finished\n" "\n", timestr);}while(0);
    if (strstr(buffer, "HTTP/1.") == ((void *)0))
    {
        send(clntSocket, "HTTP/1.0 400 Bad Request\r\n\r\n", 28, 0);
    } else if (strncmp(buffer, "GET", 3) == 0) {
        char *req_file = strtok (buffer, " \t\n");
        req_file = strtok (((void *)0), " \t");
        if (req_file == ((void *)0) || (strcmp(req_file, "/favicon.ico") && strcmp(req_file, "/twitter-logo-1.png"))) {
            req_file = "/BASEHTML.html";
        }
        handle_http_get(clntSocket, req_file);
    } else if (strncmp(buffer, "POST / ", 7) == 0){
            char friend[20] = {'\0',};
            char *friend_id = get_twitter_id(clntSocket, buffer, friend, numBytesRcvd);
            if(friend_id)
                handle_http_post(clntSocket, friend_id);
    }
    shutdown(clntSocket, SHUT_RDWR);
    close(clntSocket);
}

canonical_original_code:
void HandleTCPClient(int clntSocket) {
    char buffer[-1];
    long numBytesRcvd = recv(clntSocket, buffer, BUFSIZE, 0);
    if (numBytesRcvd <= 0){
        ERROR("recv() failed");
        close(clntSocket);
        return;
    }
    do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "first recv start\n" "\n", timestr);}while(0);
    printf("%s",buffer);
    do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "recv finished\n" "\n", timestr);}while(0);
    if (strstr(buffer, "HTTP/1.") == ((void *)0))
    {
        send(clntSocket, "HTTP/1.0 400 Bad Request\r\n\r\n", 28, 0);
    } else if (strncmp(buffer, "GET", 3) == 0) {
        char *req_file = strtok (buffer, " \t\n");
        req_file = strtok (((void *)0), " \t");
        if (req_file == ((void *)0) || (strcmp(req_file, "/favicon.ico") && strcmp(req_file, "/twitter-logo-1.png"))) {
            req_file = "/BASEHTML.html";
        }
        handle_http_get(clntSocket, req_file);
    } else if (strncmp(buffer, "POST / ", 7) == 0){
            char friend[20] = {'\0',};
            char *friend_id = get_twitter_id(clntSocket, buffer, friend, numBytesRcvd);
            if(friend_id)
                handle_http_post(clntSocket, friend_id);
    }
    shutdown(clntSocket, SHUT_RDWR);
    close(clntSocket);
}

variable_types: clntSocket int

variable_types: now long

variable_types:
timestr
char [20]

variable_types:
friend
char [20]

return_type: void


WriteMemoryCallback

decompiled_code:
size_t __fastcall WriteMemoryCallback(void *src, __int64 a2, __int64 a3, __int64 *a4)
{
size_t v5; // rbp
__int64 v6; // rax
size_t v7; // rax

v5 = a3 * a2;
v6 = xrealloc(*a4, a3 * a2 + a4[1] + 1);
*a4 = v6;
if ( v6 )
{
memcpy((void *)(a4[1] + v6), src, v5);
v7 = a4[1] + v5;
a4[1] = v7;
*(_BYTE *)(*a4 + v7) = 0;
}
return v5;
}

original_code:
static size_t
WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) {
  size_t realsize = size * nmemb;
  struct MemoryStruct *mem = (struct MemoryStruct *)data;
  mem->data = (char *)xrealloc(mem->data, mem->size + realsize + 1);
  if (mem->data) {
    memcpy(&(mem->data[mem->size]), ptr, realsize);
    mem->size += realsize;
    mem->data[mem->size] = 0;
  }
  return realsize;
}

canonical_original_code:
static unsigned long WriteMemoryCallback(void *ptr, unsigned long size, unsigned long nmemb, void *data) {
  unsigned long realsize = size * nmemb;
  struct MemoryStruct *mem = (struct MemoryStruct *)data;
  mem->data = (char *)xrealloc(mem->data, mem->size + realsize + 1);
  if (mem->data) {
    memcpy(&(mem->data[mem->size]), ptr, realsize);
    mem->size += realsize;
    mem->data[mem->size] = 0;
  }
  return realsize;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
data
void *

variable_types:
realsize
unsigned long

variable_types: struct MemoryStruct { char *data; unsigned long size; unsigned long start_size; void (*callback)(void *, int, unsigned long, unsigned long); void *callback_data; } *

return_type: unsigned long


decompiled_code:
const char *__fastcall access_token_request_data(const char *a1)
{
char *v1; // rbx
const char *v2; // rax
const char *v3; // rbp
__int64 v5[19]; // [rsp+0h] [rbp-98h] BYREF

v5[0] = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
v5[4] = 0LL;
v5[5] = 0LL;
v5[6] = 0LL;
v5[7] = 0LL;
v5[8] = 0LL;
v5[9] = 0LL;
v5[10] = 0LL;
v5[11] = 0LL;
v5[12] = 0LL;
v5[13] = 0LL;
v5[14] = 0LL;
v5[15] = 0LL;
snprintf(
(char *)v5,
0x80uLL,
"https://api.twitter.com/1.1/friendships/lookup.json?screen_name=%s,%s",
*(const char **)(conf + 8LL),
a1);
v1 = (char *)oauth_sign_url2(
v5,
0LL,
0LL,
0LL,
*(_QWORD *)(conf + 16LL),
*(_QWORD *)(conf + 24LL),
*(_QWORD *)(conf + 32LL),
*(_QWORD *)(conf + 40LL));
printf("request URL:%s\n\n", v1);
v2 = (const char *)curl_http_get((__int64)v1);
v3 = v2;
if ( v2 )
printf("HTTP-reply: %s\n", v2);
else
puts("HTTP request for an oauth request-token failed.");
if ( v1 )
free(v1);
return v3;
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1)
{
char *v1; // rbx
const char *v2; // rax
const char *v3; // rbp
__int64 v5[19]; // [rsp+0h] [rbp-98h] BYREF

v5[0] = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
v5[4] = 0LL;
v5[5] = 0LL;
v5[6] = 0LL;
v5[7] = 0LL;
v5[8] = 0LL;
v5[9] = 0LL;
v5[10] = 0LL;
v5[11] = 0LL;
v5[12] = 0LL;
v5[13] = 0LL;
v5[14] = 0LL;
v5[15] = 0LL;
snprintf(
(char *)v5,
0x80uLL,
"https://api.twitter.com/1.1/friendships/lookup.json?screen_name=%s,%s",
*(const char **)(conf + 8LL),
a1);
v1 = (char *)oauth_sign_url2(
v5,
0LL,
0LL,
0LL,
*(_QWORD *)(conf + 16LL),
*(_QWORD *)(conf + 24LL),
*(_QWORD *)(conf + 32LL),
*(_QWORD *)(conf + 40LL));
printf("request URL:%s\n\n", v1);
v2 = (const char *)func0((__int64)v1);
v3 = v2;
if ( v2 )
printf("HTTP-reply: %s\n", v2);
else
puts("HTTP request for an oauth request-token failed.");
if ( v1 )
free(v1);
return v3;
}

original_code:
static char* access_token_request_data(char *username) {
    char *req_url = ((void *)0);
    char *reply;
    char friendship_url[MAXSTRINGLENGTH] = {'\0',};
    snprintf(friendship_url, MAXSTRINGLENGTH, "https://api.twitter.com/1.1/friendships/lookup.json?screen_name=%s,%s", conf->TwitterID, username);
    req_url = oauth_sign_url2(friendship_url, ((void *)0), OA_HMAC,
                              ((void *)0), conf->CONSUMER_KEY , conf->CONSUMER_SECRET ,
                              conf->OAUTH_TOKEN , conf->OAUTH_TOKEN_SECRET);
    printf("request URL:%s\n\n", req_url);
    reply = curl_http_get(req_url);
    if (!reply)
        printf("HTTP request for an oauth request-token failed.\n");
    else {
        printf("HTTP-reply: %s\n", reply);
    }
    if(req_url) free(req_url);
    if(reply) return reply;
    else return ((void *)0);
}

canonical_original_code:
static char *access_token_request_data(char *username) {
    char *req_url = ((void *)0);
    char *reply;
    char friendship_url[-1] = {'\0',};
    snprintf(friendship_url, MAXSTRINGLENGTH, "https://api.twitter.com/1.1/friendships/lookup.json?screen_name=%s,%s", conf->TwitterID, username);
    req_url = oauth_sign_url2(friendship_url, ((void *)0), OA_HMAC,
                              ((void *)0), conf->CONSUMER_KEY , conf->CONSUMER_SECRET ,
                              conf->OAUTH_TOKEN , conf->OAUTH_TOKEN_SECRET);
    printf("request URL:%s\n\n", req_url);
    reply = curl_http_get(req_url);
    if (!reply)
        printf("HTTP request for an oauth request-token failed.\n");
    else {
        printf("HTTP-reply: %s\n", reply);
    }
    if(req_url) free(req_url);
    if(reply) return reply;
    else return ((void *)0);
}

variable_types:
username
char *

variable_types:
reply
char *


decompiled_code:
bool __fastcall parser_friendship_json(char *s)
{
char *v1; // rbp
char *v2; // rdi
bool result; // al
char *v4; // rdi
char *v5; // rax

if ( !s )
return 0;
v1 = strchr(s, 123);
v2 = strrchr(s, 123);
result = v1 != v2 && v1 != 0LL;
if ( result )
{
v4 = strstr(v2, "connections");
if ( v4 )
{
v5 = strchr(v4, 58);
result = memcmp(strchr(v5, 34), "\"none", 5uLL) != 0;
}
else
{
result = 0;
}
}
return result;
}

canonical_decompiled_code:
bool __fastcall func3(char *s)
{
char *v1; // rbp
char *v2; // rdi
bool result; // al
char *v4; // rdi
char *v5; // rax

if ( !s )
return 0;
v1 = strchr(s, 123);
v2 = strrchr(s, 123);
result = v1 != v2 && v1 != 0LL;
if ( result )
{
v4 = strstr(v2, "connections");
if ( v4 )
{
v5 = strchr(v4, 58);
result = memcmp(strchr(v5, 34), "\"none", 5uLL) != 0;
}
else
{
result = 0;
}
}
return result;
}

original_code:
static _Bool parser_friendship_json(char *friendship) {
    if (!friendship) return 0;
    char *first_front = strchr(friendship,'{');
    char *second_front = strrchr(friendship,'{');
    if(first_front && first_front != second_front ) {
        char *connections = strstr(second_front,"connections");
        if(connections == ((void *)0)) {
            return 0;
        }
        char *colon = strchr(connections,':');
        if(strncmp(strchr(colon,'"'),"\"none",5) == 0)
            return 0;
        else
            return 1;
    }else {
        return 0;
    }
}

variable_types:
friendship
char *

variable_types:
connections
char *

variable_types:
colon
char *


decompiled_code:
void request_token_example_get()
{
char *v0; // r12
const char *v1; // rax
char *v2; // r13
int v3; // ebp
__int64 v4; // rbp
__int64 v5; // rbx
const void **v6; // r14
void *base; // [rsp+8h] [rbp-30h] BYREF

v0 = (char *)oauth_sign_url2(
request_token_uri,
0LL,
0LL,
0LL,
*(_QWORD *)(conf + 16LL),
*(_QWORD *)(conf + 24LL),
0LL,
0LL);
printf("request URL:%s\n\n", v0);
v1 = (const char *)curl_http_get((__int64)v0);
if ( v1 )
{
v2 = (char *)v1;
base = 0LL;
printf("HTTP-reply: %s\n", v1);
v3 = oauth_split_url_parameters(v2, &base);
qsort(base, v3, 8uLL, (__compar_fn_t)&oauth_cmpstringp);
printf("rc=%d rv[0]=%s rv[1]=%s\n", (unsigned int)v3, *(const char **)base, *((const char **)base + 1));
if ( v3 > 1 )
{
v4 = 8LL * (unsigned int)v3;
v5 = 0LL;
do
{
v6 = (const void **)((char *)base + v5);
if ( !memcmp(*(const void **)((char *)base + v5), "oauth_token=", 0xCuLL) )
req_t_key = (__int64)strdup((const char *)(*(_QWORD *)((char *)base + v5) + 12LL));
if ( !memcmp(*v6, "oauth_token_secret=", 0x13uLL) )
req_t_secret = (__int64)strdup((const char *)*v6 + 19);
v5 += 8LL;
}
while ( v5 != v4 );
printf("key: %s\nsecret: %s\n", (const char *)req_t_key, (const char *)req_t_secret);
puts("*****Please open the url below by your browser*****");
printf(" %s?oauth_token=%s\n", authorize_uri, (const char *)req_t_key);
puts("*****Please open the url above by your browser*****");
}
if ( base )
free(base);
if ( v0 )
free(v0);
free(v2);
}
else
{
puts("Please check your network,maybe it's blocked by GFW");
FATAL("HTTP request for an oauth request-token failed.\n");
if ( v0 )
free(v0);
}
}

canonical_decompiled_code:
void func4()
{
char *v0; // r12
const char *v1; // rax
char *v2; // r13
int v3; // ebp
__int64 v4; // rbp
__int64 v5; // rbx
const void **v6; // r14
void *base; // [rsp+8h] [rbp-30h] BYREF

v0 = (char *)oauth_sign_url2(
request_token_uri,
0LL,
0LL,
0LL,
*(_QWORD *)(conf + 16LL),
*(_QWORD *)(conf + 24LL),
0LL,
0LL);
printf("request URL:%s\n\n", v0);
v1 = (const char *)func0((__int64)v0);
if ( v1 )
{
v2 = (char *)v1;
base = 0LL;
printf("HTTP-reply: %s\n", v1);
v3 = oauth_split_url_parameters(v2, &base);
qsort(base, v3, 8uLL, (__compar_fn_t)&oauth_cmpstringp);
printf("rc=%d rv[0]=%s rv[1]=%s\n", (unsigned int)v3, *(const char **)base, *((const char **)base + 1));
if ( v3 > 1 )
{
v4 = 8LL * (unsigned int)v3;
v5 = 0LL;
do
{
v6 = (const void **)((char *)base + v5);
if ( !memcmp(*(const void **)((char *)base + v5), "oauth_token=", 0xCuLL) )
req_t_key = (__int64)strdup((const char *)(*(_QWORD *)((char *)base + v5) + 12LL));
if ( !memcmp(*v6, "oauth_token_secret=", 0x13uLL) )
req_t_secret = (__int64)strdup((const char *)*v6 + 19);
v5 += 8LL;
}
while ( v5 != v4 );
printf("key: %s\nsecret: %s\n", (const char *)req_t_key, (const char *)req_t_secret);
puts("*****Please open the url below by your browser*****");
printf(" %s?oauth_token=%s\n", authorize_uri, (const char *)req_t_key);
puts("*****Please open the url above by your browser*****");
}
if ( base )
free(base);
if ( v0 )
free(v0);
free(v2);
}
else
{
puts("Please check your network,maybe it's blocked by GFW");
FATAL("HTTP request for an oauth request-token failed.\n");
if ( v0 )
free(v0);
}
}

original_code:
void request_token_example_get(void) {
    char *req_url = ((void *)0);
    char *reply;
    req_url = oauth_sign_url2(request_token_uri, ((void *)0), OA_HMAC,
                              ((void *)0), conf->CONSUMER_KEY, conf->CONSUMER_SECRET, ((void *)0), ((void *)0));
    printf("request URL:%s\n\n", req_url);
    reply = curl_http_get(req_url);
    if (!reply) {
        printf("Please check your network,maybe it's blocked by GFW\n");
        FATAL("HTTP request for an oauth request-token failed.\n");
    }
    else {
        int rc;
        char **rv = ((void *)0);
        printf("HTTP-reply: %s\n", reply);
        rc = oauth_split_url_parameters(reply, &rv);
        qsort(rv, rc, sizeof(char *), oauth_cmpstringp);
        printf("rc=%d rv[0]=%s rv[1]=%s\n", rc, rv[0], rv[1]);
        if(rc>=2) {
            int i;
            for(i=0; i<rc; i++) {
                if(!strncmp(rv[i], "oauth_token=", 12))
                    req_t_key=strdup(&(rv[i][12]));
                if(!strncmp(rv[i], "oauth_token_secret=", 19))
                    req_t_secret=strdup(&(rv[i][19]));
            }
            printf("key:    %s\nsecret: %s\n",req_t_key, req_t_secret);
            printf("*****Please open the url below by your browser*****\n");
            printf("    %s?oauth_token=%s\n", authorize_uri, req_t_key);
            printf("*****Please open the url above by your browser*****\n");
        }
        if(rv) free(rv);
    }
    if(req_url) free(req_url);
    if(reply) free(reply);
}

canonical_original_code:
void request_token_example_get() {
    char *req_url = ((void *)0);
    char *reply;
    req_url = oauth_sign_url2(request_token_uri, ((void *)0), OA_HMAC,
                              ((void *)0), conf->CONSUMER_KEY, conf->CONSUMER_SECRET, ((void *)0), ((void *)0));
    printf("request URL:%s\n\n", req_url);
    reply = curl_http_get(req_url);
    if (!reply) {
        printf("Please check your network,maybe it's blocked by GFW\n");
        FATAL("HTTP request for an oauth request-token failed.\n");
    }
    else {
        int rc;
        char **rv = ((void *)0);
        printf("HTTP-reply: %s\n", reply);
        rc = oauth_split_url_parameters(reply, &rv);
        qsort(rv, rc, sizeof(char *), oauth_cmpstringp);
        printf("rc=%d rv[0]=%s rv[1]=%s\n", rc, rv[0], rv[1]);
        if(rc>=2) {
            int i;
            for(i=0; i<rc; i++) {
                if(!strncmp(rv[i], "oauth_token=", 12))
                    req_t_key=strdup(&(rv[i][12]));
                if(!strncmp(rv[i], "oauth_token_secret=", 19))
                    req_t_secret=strdup(&(rv[i][19]));
            }
            printf("key:    %s\nsecret: %s\n",req_t_key, req_t_secret);
            printf("*****Please open the url below by your browser*****\n");
            printf("    %s?oauth_token=%s\n", authorize_uri, req_t_key);
            printf("*****Please open the url above by your browser*****\n");
        }
        if(rv) free(rv);
    }
    if(req_url) free(req_url);
    if(reply) free(reply);
}

variable_types: rc int

variable_types:
rv
char **

variable_types: i int


decompiled_code:
__int64 __fastcall access_token_example_get(const char *a1)
{
char *v1; // r13
const char *v2; // rax
char *v3; // r14
int v4; // er12
unsigned int v5; // ebx
__int64 v6; // r12
__int64 v7; // rbp
const char *v8; // r15
char *v9; // rax
const char *v10; // rbx
void *v12; // rdi
void *v13; // rdi
void *v14; // rdi
__int64 v15; // rax
const char *v16; // [rsp+0h] [rbp-458h]
const char *v17; // [rsp+8h] [rbp-450h]
void *base; // [rsp+18h] [rbp-440h] BYREF
char s[1080]; // [rsp+20h] [rbp-438h] BYREF

sprintf(s, "%s?&oauth_verifier=%s", access_token_uri, a1);
printf("verifier=%s\n", s);
v1 = (char *)oauth_sign_url2(
s,
0LL,
0LL,
0LL,
*(_QWORD *)(conf + 16LL),
*(_QWORD *)(conf + 24LL),
req_t_key,
req_t_secret);
printf("request URL:%s\n\n", v1);
v2 = (const char *)curl_http_get((__int64)v1);
if ( v2 )
{
v3 = (char *)v2;
base = 0LL;
printf("HTTP-reply: %s\n", v2);
v4 = oauth_split_url_parameters(v3, &base);
qsort(base, v4, 8uLL, (__compar_fn_t)&oauth_cmpstringp);
printf("rc=%d rv[0]=%s rv[1]=%s\n", (unsigned int)v4, *(const char **)base, *((const char **)base + 1));
v5 = 0;
if ( v4 > 1 )
{
v6 = 8LL * (unsigned int)v4;
v7 = 0LL;
v8 = 0LL;
v17 = 0LL;
v16 = 0LL;
do
{
LODWORD(v9) = (_DWORD)base;
v10 = *(const char **)((char *)base + v7);
if ( !memcmp(v10, "oauth_token=", 0xCuLL) )
{
v9 = strdup(v10 + 12);
v16 = v9;
}
if ( !memcmp(v10, "oauth_token_secret=", 0x13uLL) )
{
v9 = strdup(v10 + 19);
v17 = v9;
}
if ( !memcmp(v10, "screen_name=", 0xCuLL) )
{
v9 = strdup(v10 + 12);
v8 = v9;
}
v7 += 8LL;
}
while ( v6 != v7 );
LOBYTE(v10) = v16 != 0LL;
LOBYTE(v9) = v17 != 0LL;
v5 = (unsigned int)v9 & (unsigned int)v10;
LOBYTE(v5) = (v8 != 0LL) & v5;
if ( (_BYTE)v5 )
{
printf("key: '%s'\nsecret: '%s'\nscreen_name: '%s'\n", v16, v17, v8);
v12 = *(void **)(conf + 8LL);
if ( v12 )
free(v12);
v13 = *(void **)(conf + 32LL);
if ( v13 )
free(v13);
v14 = *(void **)(conf + 40LL);
if ( v14 )
free(v14);
v15 = conf;
*(_QWORD *)(conf + 8LL) = v8;
*(_QWORD *)(v15 + 32) = v16;
*(_QWORD *)(v15 + 40) = v17;
}
}
free(base);
if ( v1 )
free(v1);
free(v3);
}
else
{
puts("Please check your network,maybe it's blocked by GFW");
FATAL("HTTP request for an oauth request-token failed.\n");
v5 = 0;
if ( v1 )
{
free(v1);
v5 = 0;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
char *v1; // r13
const char *v2; // rax
char *v3; // r14
int v4; // er12
unsigned int v5; // ebx
__int64 v6; // r12
__int64 v7; // rbp
const char *v8; // r15
char *v9; // rax
const char *v10; // rbx
void *v12; // rdi
void *v13; // rdi
void *v14; // rdi
__int64 v15; // rax
const char *v16; // [rsp+0h] [rbp-458h]
const char *v17; // [rsp+8h] [rbp-450h]
void *base; // [rsp+18h] [rbp-440h] BYREF
char s[1080]; // [rsp+20h] [rbp-438h] BYREF

sprintf(s, "%s?&oauth_verifier=%s", access_token_uri, a1);
printf("verifier=%s\n", s);
v1 = (char *)oauth_sign_url2(
s,
0LL,
0LL,
0LL,
*(_QWORD *)(conf + 16LL),
*(_QWORD *)(conf + 24LL),
req_t_key,
req_t_secret);
printf("request URL:%s\n\n", v1);
v2 = (const char *)func0((__int64)v1);
if ( v2 )
{
v3 = (char *)v2;
base = 0LL;
printf("HTTP-reply: %s\n", v2);
v4 = oauth_split_url_parameters(v3, &base);
qsort(base, v4, 8uLL, (__compar_fn_t)&oauth_cmpstringp);
printf("rc=%d rv[0]=%s rv[1]=%s\n", (unsigned int)v4, *(const char **)base, *((const char **)base + 1));
v5 = 0;
if ( v4 > 1 )
{
v6 = 8LL * (unsigned int)v4;
v7 = 0LL;
v8 = 0LL;
v17 = 0LL;
v16 = 0LL;
do
{
LODWORD(v9) = (_DWORD)base;
v10 = *(const char **)((char *)base + v7);
if ( !memcmp(v10, "oauth_token=", 0xCuLL) )
{
v9 = strdup(v10 + 12);
v16 = v9;
}
if ( !memcmp(v10, "oauth_token_secret=", 0x13uLL) )
{
v9 = strdup(v10 + 19);
v17 = v9;
}
if ( !memcmp(v10, "screen_name=", 0xCuLL) )
{
v9 = strdup(v10 + 12);
v8 = v9;
}
v7 += 8LL;
}
while ( v6 != v7 );
LOBYTE(v10) = v16 != 0LL;
LOBYTE(v9) = v17 != 0LL;
v5 = (unsigned int)v9 & (unsigned int)v10;
LOBYTE(v5) = (v8 != 0LL) & v5;
if ( (_BYTE)v5 )
{
printf("key: '%s'\nsecret: '%s'\nscreen_name: '%s'\n", v16, v17, v8);
v12 = *(void **)(conf + 8LL);
if ( v12 )
free(v12);
v13 = *(void **)(conf + 32LL);
if ( v13 )
free(v13);
v14 = *(void **)(conf + 40LL);
if ( v14 )
free(v14);
v15 = conf;
*(_QWORD *)(conf + 8LL) = v8;
*(_QWORD *)(v15 + 32) = v16;
*(_QWORD *)(v15 + 40) = v17;
}
}
free(base);
if ( v1 )
free(v1);
free(v3);
}
else
{
puts("Please check your network,maybe it's blocked by GFW");
FATAL("HTTP request for an oauth request-token failed.\n");
v5 = 0;
if ( v1 )
{
free(v1);
v5 = 0;
}
}
return v5;
}

original_code:
_Bool access_token_example_get(char *pin) {
    char *res_t_key = ((void *)0);
    char *res_t_secret = ((void *)0);
    char *screen_name = ((void *)0);
    char verifier[1024];
    char *req_url = ((void *)0);
    char *reply;
 _Bool ret = 0;
    sprintf(verifier, "%s?&oauth_verifier=%s", access_token_uri, pin);
    printf("verifier=%s\n", verifier);
    req_url = oauth_sign_url2(verifier, ((void *)0), OA_HMAC, ((void *)0),
                              conf->CONSUMER_KEY, conf->CONSUMER_SECRET,
                              req_t_key, req_t_secret);
    printf("request URL:%s\n\n", req_url);
    reply = curl_http_get(req_url);
    if (!reply) {
  printf("Please check your network,maybe it's blocked by GFW\n");
        FATAL("HTTP request for an oauth request-token failed.\n");
 }
    else {
        int rc;
        char **rv = ((void *)0);
        printf("HTTP-reply: %s\n", reply);
        rc = oauth_split_url_parameters(reply, &rv);
        qsort(rv, rc, sizeof(char *), oauth_cmpstringp);
        printf("rc=%d rv[0]=%s rv[1]=%s\n", rc, rv[0], rv[1]);
        if(rc>=2) {
            int i;
            for(i=0; i<rc; i++) {
                if(!strncmp(rv[i], "oauth_token=", 12))
                    res_t_key=strdup(&(rv[i][12]));
                if(!strncmp(rv[i], "oauth_token_secret=", 19))
                    res_t_secret=strdup(&(rv[i][19]));
                if(!strncmp(rv[i], "screen_name=", 12))
                    screen_name=strdup(&(rv[i][12]));
            }
            if(res_t_key && res_t_secret && screen_name) {
                ret = 1;
                printf("key:    '%s'\nsecret: '%s'\nscreen_name: '%s'\n", res_t_key, res_t_secret,screen_name);
                if(conf->TwitterID) free(conf->TwitterID);
                if(conf->OAUTH_TOKEN) free(conf->OAUTH_TOKEN);
                if(conf->OAUTH_TOKEN_SECRET) free(conf->OAUTH_TOKEN_SECRET);
                conf->TwitterID = screen_name;
                conf->OAUTH_TOKEN = res_t_key;
                conf->OAUTH_TOKEN_SECRET = res_t_secret;
            }
        }
        free(rv);
    }
    if(req_url) free(req_url);
    if(reply) free(reply);
 return ret;
}

variable_types:
pin
char *

variable_types:
verifier
char [1024]


decompiled_code:
__int64 __fastcall get_friendship(const char *a1)
{
char *v1; // rax
unsigned int v2; // ebp
char *v3; // rbx
unsigned int v4; // eax

v1 = (char *)access_token_request_data(a1);
v2 = 0;
if ( v1 )
{
v3 = v1;
LOBYTE(v4) = parser_friendship_json(v1);
v2 = v4;
free(v3);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
char *v1; // rax
unsigned int v2; // ebp
char *v3; // rbx
unsigned int v4; // eax

v1 = (char *)func2(a1);
v2 = 0;
if ( v1 )
{
v3 = v1;
LOBYTE(v4) = func3(v1);
v2 = v4;
free(v3);
}
return v2;
}

original_code:
_Bool get_friendship(char *username) {
    char *friendship = access_token_request_data(username);
    if(friendship != ((void *)0) && parser_friendship_json(friendship) == 1) {
        free(friendship);
        return 1;
    } else if(friendship != ((void *)0)) {
        free(friendship);
    }
    return 0;
}


decompiled_code:
__int64 __fastcall xmalloc_fatal(__int64 a1)
{
if ( a1 )
{
fwrite("Out of memory.", 1uLL, 0xEuLL, stderr);
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( a1 )
{
fwrite("Out of memory.", 1uLL, 0xEuLL, stderr);
exit(1);
}
return 0LL;
}

original_code:
static void *xmalloc_fatal(size_t size) {
  if (size==0) return ((void *)0);
  fprintf(stderr, "Out of memory.");
  exit(1);
}

canonical_original_code:
static void *xmalloc_fatal(unsigned long size) {
  if (size==0) return ((void *)0);
  fprintf(stderr, "Out of memory.");
  exit(1);
}

return_type: void *


xmalloc

decompiled_code:
__int64 __fastcall xmalloc(size_t a1)
{
__int64 result; // rax

result = (__int64)malloc(a1);
if ( !result )
result = xmalloc_fatal(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(size_t a1)
{
__int64 result; // rax

result = (__int64)malloc(a1);
if ( !result )
result = func0(a1);
return result;
}

original_code:
void *xmalloc (size_t size) {
  void *ptr = malloc (size);
  if (ptr == ((void *)0)) return xmalloc_fatal(size);
  return ptr;
}

canonical_original_code:
void *xmalloc(unsigned long size) {
  void *ptr = malloc (size);
  if (ptr == ((void *)0)) return xmalloc_fatal(size);
  return ptr;
}


xcalloc

decompiled_code:
__int64 __fastcall xcalloc(size_t a1, size_t a2)
{
__int64 result; // rax

result = (__int64)calloc(a1, a2);
if ( !result )
result = xmalloc_fatal(a2 * a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(size_t a1, size_t a2)
{
__int64 result; // rax

result = (__int64)calloc(a1, a2);
if ( !result )
result = func0(a2 * a1);
return result;
}

original_code:
void *xcalloc (size_t nmemb, size_t size) {
  void *ptr = calloc (nmemb, size);
  if (ptr == ((void *)0)) return xmalloc_fatal(nmemb*size);
  return ptr;
}

canonical_original_code:
void *xcalloc(unsigned long nmemb, unsigned long size) {
  void *ptr = calloc (nmemb, size);
  if (ptr == ((void *)0)) return xmalloc_fatal(nmemb*size);
  return ptr;
}


xrealloc

decompiled_code:
__int64 __fastcall xrealloc(void *a1, size_t a2)
{
__int64 result; // rax

result = (__int64)realloc(a1, a2);
if ( !result )
result = xmalloc_fatal(a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *a1, size_t a2)
{
__int64 result; // rax

result = (__int64)realloc(a1, a2);
if ( !result )
result = func0(a2);
return result;
}

original_code:
void *xrealloc (void *ptr, size_t size) {
  void *p = realloc (ptr, size);
  if (p == ((void *)0)) return xmalloc_fatal(size);
  return p;
}

canonical_original_code:
void *xrealloc(void *ptr, unsigned long size) {
  void *p = realloc (ptr, size);
  if (p == ((void *)0)) return xmalloc_fatal(size);
  return p;
}

variable_types:
p
void *


xstrdup

decompiled_code:
char *__fastcall xstrdup(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)xmalloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func4(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)func1(v1 + 1);
return strcpy(v2, src);
}

original_code:
char *xstrdup (const char *s) {
  void *ptr = xmalloc(strlen(s)+1);
  strcpy (ptr, s);
  return (char*) ptr;
}

canonical_original_code:
char *xstrdup(char *s) {
  void *ptr = xmalloc(strlen(s)+1);
  strcpy (ptr, s);
  return (char *) ptr;
}

variable_types:
s
char *

variable_types:
ptr
void *


decompiled_code:
__int64 __fastcall to_string(__int64 a1)
{
int v1; // eax
char *v2; // rdx
const char *v4; // rax
struct tm *v5; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

v1 = *(_DWORD *)(a1 + 8);
if ( v1 == 5 )
return ss_strndup(*(_QWORD *)(a1 + 24), *(unsigned int *)(a1 + 16));
if ( v1 == 3 )
{
v4 = (const char *)itoa(*(_QWORD *)(a1 + 16));
v2 = strdup(v4);
}
else
{
v2 = "null";
if ( v1 != 7 )
{
timer = time(0LL);
v5 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v5);
fprintf(stderr, "\x1B[01;35m %s ERROR: \x1B[0m%d\n", s, *(unsigned int *)(a1 + 8));
FATAL("Invalid config format.");
v2 = 0LL;
}
}
return (__int64)v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
char *v2; // rdx
const char *v4; // rax
struct tm *v5; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

v1 = *(_DWORD *)(a1 + 8);
if ( v1 == 5 )
return ss_strndup(*(_QWORD *)(a1 + 24), *(unsigned int *)(a1 + 16));
if ( v1 == 3 )
{
v4 = (const char *)itoa(*(_QWORD *)(a1 + 16));
v2 = strdup(v4);
}
else
{
v2 = "null";
if ( v1 != 7 )
{
timer = time(0LL);
v5 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v5);
fprintf(stderr, "\x1B[01;35m %s ERROR: \x1B[0m%d\n", s, *(unsigned int *)(a1 + 8));
FATAL("Invalid config format.");
v2 = 0LL;
}
}
return (__int64)v2;
}

original_code:
static char *to_string(const json_value *value)
{
    if (value->type == json_string)
    {
        return ss_strndup(value->u.string.ptr, value->u.string.length);
    }
    else if (value->type == json_integer)
    {
        return strdup(itoa(value->u.integer));
    }
    else if (value->type == json_null)
    {
        return "null";
    }
    else
    {
        do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;35m %s ERROR: \e[0m" "%d" "\n", timestr, value->type);}while(0);
        FATAL("Invalid config format.");
    }
    return 0;
}

canonical_original_code:
static char *to_string(struct _json_value *value)
{
    if (value->type == json_string)
    {
        return ss_strndup(value->u.string.ptr, value->u.string.length);
    }
    else if (value->type == json_integer)
    {
        return strdup(itoa(value->u.integer));
    }
    else if (value->type == json_null)
    {
        return "null";
    }
    else
    {
        do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;35m %s ERROR: \e[0m" "%d" "\n", timestr, value->type);}while(0);
        FATAL("Invalid config format.");
    }
    return 0;
}

variable_types: struct _json_value { struct _json_value *parent; enum json_type { json_none=0, json_object=1, json_array=2, json_integer=3, json_double=4, json_string=5, json_boolean=6, json_null=7 } type; union { int boolean; long integer; double dbl; struct { unsigned int length; char *ptr; } string; struct { unsigned int length; struct { char *name; struct _json_value *value; } *values; } object; struct { unsigned int length; struct _json_value **values; } array; } u; union { struct _json_value *next_alloc; void *object_mem; } _reserved; } *

variable_types: now long

variable_types:
timestr
char [20]

user_defined_types: struct _json_value { struct _json_value *parent; enum json_type type; union { int boolean; long integer; double dbl; struct { unsigned int length; char *ptr; } string; struct { unsigned int length; struct { char *name; struct _json_value *value; } *values; } object; struct { unsigned int length; struct _json_value **values; } array; } u; union { struct _json_value *next_alloc; void *object_mem; } _reserved; }


decompiled_code:
char *__fastcall build_json_item(char *a1, char *a2)
{
char *v2; // rbp
char *v3; // rbx
char *v4; // r12

v2 = packstring(a1, "\"");
v3 = packstring(a2, "\"");
v4 = concatstring(v2, ":", v3);
if ( v2 )
free(v2);
if ( v3 )
free(v3);
return v4;
}

canonical_decompiled_code:
char *__fastcall func3(char *a1, char *a2)
{
char *v2; // rbp
char *v3; // rbx
char *v4; // r12

v2 = func1(a1, "\"");
v3 = func1(a2, "\"");
v4 = func2(v2, ":", v3);
if ( v2 )
free(v2);
if ( v3 )
free(v3);
return v4;
}

original_code:
static char* build_json_item(char *key, char *value) {
    char *pack_key = packstring(key, "\"");
    char *pack_value = packstring(value, "\"");
    char *ret = concatstring(pack_key, ":", pack_value);
    if (pack_key) free(pack_key);
    if (pack_value) free(pack_value);
    return ret;
}

canonical_original_code:
static char *build_json_item(char *key, char *value) {
    char *pack_key = packstring(key, "\"");
    char *pack_value = packstring(value, "\"");
    char *ret = concatstring(pack_key, ":", pack_value);
    if (pack_key) free(pack_key);
    if (pack_value) free(pack_value);
    return ret;
}

variable_types:
key
char *

variable_types:
value
char *

variable_types:
ret
char *


decompiled_code:
void __fastcall dump_jconf(char *a1)
{
void **v1; // rbx
const char **v2; // rbp
int v3; // er13
void *v4; // rbp
const char **v5; // r12
size_t v6; // r13
char *v7; // rbx
size_t v8; // rax
const char *src; // [rsp+0h] [rbp-78h]
__int64 v10[5]; // [rsp+10h] [rbp-68h] BYREF
const char *v11; // [rsp+38h] [rbp-40h] BYREF
char v12[56]; // [rsp+40h] [rbp-38h] BYREF

v10[0] = (__int64)build_json_item("TwitterID", *(char **)(conf + 8LL));
v10[1] = (__int64)build_json_item("CONSUMER_KEY", *(char **)(conf + 16LL));
v10[2] = (__int64)build_json_item("CONSUMER_SECRET", *(char **)(conf + 24LL));
v10[3] = (__int64)build_json_item("OAUTH_TOKEN", *(char **)(conf + 32LL));
v10[4] = (__int64)build_json_item("OAUTH_TOKEN_SECRET", *(char **)(conf + 40LL));
src = build_json_item("whitelist", (char *)*conf);
v11 = src;
v1 = (void **)v10;
v2 = (const char **)v10;
v3 = 0;
do
v3 += strlen(*v2++);
while ( v2 != (const char **)v12 );
v4 = malloc(v3 + 21);
memset(v4, 0, v3 + 21);
v5 = (const char **)v10;
do
{
strcat((char *)v4, *v5);
strcat((char *)v4, ",\r\n\t");
++v5;
}
while ( v5 != &v11 );
strcat((char *)v4, src);
do
{
if ( *v1 )
free(*v1);
++v1;
}
while ( v1 != (void **)v12 );
v6 = v3 + 29;
v7 = (char *)malloc(v6);
memset(v7, 0, v6);
strcat(v7, "{\r\n\t");
strcat(v7, (const char *)v4);
*(_DWORD *)&v7[strlen(v7)] = 8194573;
free(v4);
printf("\n%s\n", v7);
v8 = strlen(v7);
dump_to_file(v7, v8, a1);
free(v7);
}

canonical_decompiled_code:
void __fastcall func5(char *a1)
{
void **v1; // rbx
const char **v2; // rbp
int v3; // er13
void *v4; // rbp
const char **v5; // r12
size_t v6; // r13
char *v7; // rbx
size_t v8; // rax
const char *src; // [rsp+0h] [rbp-78h]
__int64 v10[5]; // [rsp+10h] [rbp-68h] BYREF
const char *v11; // [rsp+38h] [rbp-40h] BYREF
char v12[56]; // [rsp+40h] [rbp-38h] BYREF

v10[0] = (__int64)func3("TwitterID", *(char **)(conf + 8LL));
v10[1] = (__int64)func3("CONSUMER_KEY", *(char **)(conf + 16LL));
v10[2] = (__int64)func3("CONSUMER_SECRET", *(char **)(conf + 24LL));
v10[3] = (__int64)func3("OAUTH_TOKEN", *(char **)(conf + 32LL));
v10[4] = (__int64)func3("OAUTH_TOKEN_SECRET", *(char **)(conf + 40LL));
src = func3("whitelist", (char *)*conf);
v11 = src;
v1 = (void **)v10;
v2 = (const char **)v10;
v3 = 0;
do
v3 += strlen(*v2++);
while ( v2 != (const char **)v12 );
v4 = malloc(v3 + 21);
memset(v4, 0, v3 + 21);
v5 = (const char **)v10;
do
{
strcat((char *)v4, *v5);
strcat((char *)v4, ",\r\n\t");
++v5;
}
while ( v5 != &v11 );
strcat((char *)v4, src);
do
{
if ( *v1 )
free(*v1);
++v1;
}
while ( v1 != (void **)v12 );
v6 = v3 + 29;
v7 = (char *)malloc(v6);
memset(v7, 0, v6);
strcat(v7, "{\r\n\t");
strcat(v7, (const char *)v4);
*(_DWORD *)&v7[strlen(v7)] = 8194573;
free(v4);
printf("\n%s\n", v7);
v8 = strlen(v7);
func4(v7, v8, a1);
free(v7);
}

original_code:
void dump_jconf(char *conf_path){
    char* jsonlist[6];
    extern jconf_t *conf;
    jsonlist[0] = build_json_item("TwitterID",conf->TwitterID);
    jsonlist[1] = build_json_item("CONSUMER_KEY",conf->CONSUMER_KEY);
    jsonlist[2] = build_json_item("CONSUMER_SECRET",conf->CONSUMER_SECRET);
    jsonlist[3] = build_json_item("OAUTH_TOKEN",conf->OAUTH_TOKEN);
    jsonlist[4] = build_json_item("OAUTH_TOKEN_SECRET",conf->OAUTH_TOKEN_SECRET);
    jsonlist[5] = build_json_item("whitelist",conf->whitelist);
    int j;
    int stringlen = 0;
    for(j = 0; j < 6; j++) {
        stringlen += strlen(jsonlist[j]);
    }
    int total_len = stringlen + 5 * 4 + 1;
    char *all_item = (char *)malloc(total_len);
    memset(all_item,0, total_len);
    for(j = 0; j < 5; j++) {
        strcat(all_item,jsonlist[j]);
        strcat(all_item,",\r\n\t");
    }
    strcat(all_item,jsonlist[5]);
    for(j = 0; j < 6; j++) {
        if (jsonlist[j]) free(jsonlist[j]);
    }
    char *final_string = (char *)malloc(total_len + 4 + 3 + 1);
    memset(final_string, 0, total_len + 4 + 3 + 1);
    strcat(final_string, "{\r\n\t");
    strcat(final_string, all_item);
    strcat(final_string, "\r\n}");
    if(all_item) free(all_item);
    printf("\n%s\n", final_string);
    dump_to_file(final_string, strlen(final_string), conf_path);
    if(final_string) free(final_string);
}

canonical_original_code:
void dump_jconf(char *conf_path){
    char *jsonlist[6];
    extern struct jconf_t *conf;
    jsonlist[0] = build_json_item("TwitterID",conf->TwitterID);
    jsonlist[1] = build_json_item("CONSUMER_KEY",conf->CONSUMER_KEY);
    jsonlist[2] = build_json_item("CONSUMER_SECRET",conf->CONSUMER_SECRET);
    jsonlist[3] = build_json_item("OAUTH_TOKEN",conf->OAUTH_TOKEN);
    jsonlist[4] = build_json_item("OAUTH_TOKEN_SECRET",conf->OAUTH_TOKEN_SECRET);
    jsonlist[5] = build_json_item("whitelist",conf->whitelist);
    int j;
    int stringlen = 0;
    for(j = 0; j < 6; j++) {
        stringlen += strlen(jsonlist[j]);
    }
    int total_len = stringlen + 5 * 4 + 1;
    char *all_item = (char *)malloc(total_len);
    memset(all_item,0, total_len);
    for(j = 0; j < 5; j++) {
        strcat(all_item,jsonlist[j]);
        strcat(all_item,",\r\n\t");
    }
    strcat(all_item,jsonlist[5]);
    for(j = 0; j < 6; j++) {
        if (jsonlist[j]) free(jsonlist[j]);
    }
    char *final_string = (char *)malloc(total_len + 4 + 3 + 1);
    memset(final_string, 0, total_len + 4 + 3 + 1);
    strcat(final_string, "{\r\n\t");
    strcat(final_string, all_item);
    strcat(final_string, "\r\n}");
    if(all_item) free(all_item);
    printf("\n%s\n", final_string);
    dump_to_file(final_string, strlen(final_string), conf_path);
    if(final_string) free(final_string);
}

variable_types:
jsonlist
char *[6]

variable_types: struct jconf_t { char *whitelist; char *TwitterID; char *CONSUMER_KEY; char *CONSUMER_SECRET; char *OAUTH_TOKEN; char *OAUTH_TOKEN_SECRET; } *

variable_types: j int

variable_types: stringlen int


isValidIpAddress

decompiled_code:
bool __fastcall isValidIpAddress(char *cp)
{
char buf[20]; // [rsp+4h] [rbp-14h] BYREF

return inet_pton(2, cp, buf) != 0;
}

canonical_decompiled_code:
bool __fastcall func0(char *cp)
{
char buf[20]; // [rsp+4h] [rbp-14h] BYREF

return inet_pton(2, cp, buf) != 0;
}

original_code:
static _Bool isValidIpAddress(char *ipAddress)
{
    struct sockaddr_in sa;
    int result = inet_pton(2, ipAddress, &(sa.sin_addr));
    return result != 0;
}

variable_types:
ipAddress
char *

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: result int

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


isValidMAC

original_code:
static _Bool isValidMAC(char *s) {
    int i;
    for(i = 0; i < 17; i++) {
        if(i % 3 != 2 && !((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISxdigit))
            return 0;
        if(i % 3 == 2 && s[i] != ':' && s[i] != '-')
            return 0;
    }
    if(s[17] != '\0')
        return 0;
    return 1;
}

canonical_original_code:
static _Bool isValidMAC(char *s) {
    int i;
    for(i = 0; i < 17; i++) {
        if(i % 3 != 2 && !((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISxdigit))
            return 0;
        if(i % 3 == 2 && s[i] != ':' && s[i] != '-')
            return 0;
    }
    if(s[17] != '\0')
        return 0;
    return 1;
}

variable_types: i int


decompiled_code:
__int64 __fastcall scan_arp_and_block(char *a1)
{
const char *v1; // rbp
char *v3; // rax
const char *v4; // rbx
__int64 v5; // rbx
struct tm *v6; // rax
time_t timer; // [rsp+8h] [rbp-C0h] BYREF
char v8[32]; // [rsp+10h] [rbp-B8h] BYREF
char s[8]; // [rsp+30h] [rbp-98h] BYREF
__int64 v10; // [rsp+38h] [rbp-90h]
__int64 v11; // [rsp+40h] [rbp-88h]
__int64 v12; // [rsp+48h] [rbp-80h]
__int64 v13; // [rsp+50h] [rbp-78h]
__int64 v14; // [rsp+58h] [rbp-70h]
__int64 v15; // [rsp+60h] [rbp-68h]
__int64 v16; // [rsp+68h] [rbp-60h]
__int64 v17; // [rsp+70h] [rbp-58h]
__int64 v18; // [rsp+78h] [rbp-50h]
__int64 v19; // [rsp+80h] [rbp-48h]
__int64 v20; // [rsp+88h] [rbp-40h]
__int64 v21; // [rsp+90h] [rbp-38h]
__int64 v22; // [rsp+98h] [rbp-30h]
__int64 v23; // [rsp+A0h] [rbp-28h]
__int64 v24; // [rsp+A8h] [rbp-20h]

*(_QWORD *)s = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
v23 = 0LL;
v24 = 0LL;
if ( strtok(a1, "\n") )
{
while ( 1 )
{
v3 = strtok(0LL, " \t\n");
v4 = v3;
if ( !v3 )
break;
if ( isValidIpAddress(v3) )
{
v1 = v4;
}
else if ( isValidMAC((__int64)v4) && !strstr((const char *)*conf, v4) )
{
v5 = arpList;
if ( !Query(arpList, v1) )
{
InsertEmptyLink(v5, v1, 1);
sprintf(s, "iptables -t nat -I PREROUTING -s %s -p tcp --dport 80 -j REDIRECT --to-ports %s", v1, servPort);
exec_cmd_shell(s);
timer = time(0LL);
v6 = localtime(&timer);
strftime(v8, 0x14uLL, "%F %T", v6);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mblocked ip addr %s \n\n", v8, v1);
}
}
}
}
return CheckList(arpList);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
const char *v1; // rbp
char *v3; // rax
const char *v4; // rbx
__int64 v5; // rbx
struct tm *v6; // rax
time_t timer; // [rsp+8h] [rbp-C0h] BYREF
char v8[32]; // [rsp+10h] [rbp-B8h] BYREF
char s[8]; // [rsp+30h] [rbp-98h] BYREF
__int64 v10; // [rsp+38h] [rbp-90h]
__int64 v11; // [rsp+40h] [rbp-88h]
__int64 v12; // [rsp+48h] [rbp-80h]
__int64 v13; // [rsp+50h] [rbp-78h]
__int64 v14; // [rsp+58h] [rbp-70h]
__int64 v15; // [rsp+60h] [rbp-68h]
__int64 v16; // [rsp+68h] [rbp-60h]
__int64 v17; // [rsp+70h] [rbp-58h]
__int64 v18; // [rsp+78h] [rbp-50h]
__int64 v19; // [rsp+80h] [rbp-48h]
__int64 v20; // [rsp+88h] [rbp-40h]
__int64 v21; // [rsp+90h] [rbp-38h]
__int64 v22; // [rsp+98h] [rbp-30h]
__int64 v23; // [rsp+A0h] [rbp-28h]
__int64 v24; // [rsp+A8h] [rbp-20h]

*(_QWORD *)s = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
v23 = 0LL;
v24 = 0LL;
if ( strtok(a1, "\n") )
{
while ( 1 )
{
v3 = strtok(0LL, " \t\n");
v4 = v3;
if ( !v3 )
break;
if ( func0(v3) )
{
v1 = v4;
}
else if ( func1((__int64)v4) && !strstr((const char *)*conf, v4) )
{
v5 = arpList;
if ( !func4(arpList, v1) )
{
func2(v5, v1, 1);
sprintf(s, "iptables -t nat -I PREROUTING -s %s -p tcp --dport 80 -j REDIRECT --to-ports %s", v1, servPort);
func6(s);
timer = time(0LL);
v6 = localtime(&timer);
strftime(v8, 0x14uLL, "%F %T", v6);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mblocked ip addr %s \n\n", v8, v1);
}
}
}
}
return CheckList(arpList);
}

original_code:
void scan_arp_and_block(char *arpOutput) {
    char *line = strtok(arpOutput,"\n");
    char *ip;
    char iptable_block_cmd[MAXSTRINGLENGTH] = {'\0',};
    while (line) {
        line = strtok(((void *)0)," \t\n");
        if (!line) break;
        if (isValidIpAddress(line)) {
            ip = line;
            continue;
        }
        if (isValidMAC(line)) {
            if(strstr(conf->whitelist,line) || Query(arpList,ip)) {
                continue;
            } else {
                InsertEmptyLink(arpList,ip,BLOCKED_FLAG);
                sprintf(iptable_block_cmd,"iptables -t nat -I PREROUTING -s %s -p tcp --dport 80 -j REDIRECT --to-ports %s", ip, servPort);
                char *block_cmd_output = exec_cmd_shell(iptable_block_cmd);
                if(!block_cmd_output) free(block_cmd_output);
                do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "blocked ip addr %s \n" "\n", timestr,ip);}while(0);
            }
        }
    }
    CheckList(arpList);
}

canonical_original_code:
void scan_arp_and_block(char *arpOutput) {
    char *line = strtok(arpOutput,"\n");
    char *ip;
    char iptable_block_cmd[-1] = {'\0',};
    while (line) {
        line = strtok(((void *)0)," \t\n");
        if (!line) break;
        if (isValidIpAddress(line)) {
            ip = line;
            continue;
        }
        if (isValidMAC(line)) {
            if(strstr(conf->whitelist,line) || Query(arpList,ip)) {
                continue;
            } else {
                InsertEmptyLink(arpList,ip,BLOCKED_FLAG);
                sprintf(iptable_block_cmd,"iptables -t nat -I PREROUTING -s %s -p tcp --dport 80 -j REDIRECT --to-ports %s", ip, servPort);
                char *block_cmd_output = exec_cmd_shell(iptable_block_cmd);
                if(!block_cmd_output) free(block_cmd_output);
                do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "blocked ip addr %s \n" "\n", timestr,ip);}while(0);
            }
        }
    }
    CheckList(arpList);
}

variable_types:
arpOutput
char *

variable_types:
line
char *

variable_types:
ip
char *


idle

decompiled_code:
__int64 idle()
{
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 func0()
{
return glutPostRedisplay();
}

original_code:
void idle() {
    glutPostRedisplay();
}

canonical_original_code:
void idle() {
    glutPostRedisplay();
}


decompiled_code:
int timer_reset()
{
the_time = 0;
return gettimeofday(&start_time, 0LL);
}

canonical_decompiled_code:
int func1()
{
the_time = 0;
return gettimeofday(&start_time, 0LL);
}

original_code:
void timer_reset() {
    the_time=0;
    gettimeofday(&start_time, ((void *)0));
}


position

decompiled_code:
float position()
{
return (float)(logf((float)((float)level * 0.050000001) + 1.0) + 0.2) * *(float *)&the_time;
}

canonical_decompiled_code:
float func2()
{
return (float)(logf((float)((float)level * 0.050000001) + 1.0) + 0.2) * *(float *)&the_time;
}

original_code:
float position() {
    float speed = 0.2f + logf(level * 0.05f + 1);
    return the_time * speed;
}

variable_types: speed float

return_type: float


decompiled_code:
__int64 init_level()
{
__int64 result; // rax

timer_reset();
++level;
failed = 0;
result = (unsigned int)(rand() % 50 + 40);
*(float *)&goal = (float)(int)result / 100.0;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax

func1();
++level;
failed = 0;
result = (unsigned int)(rand() % 50 + 40);
*(float *)&goal = (float)(int)result / 100.0;
return result;
}

original_code:
void init_level() {
    timer_reset();
    level+=1;
    failed=0;
    goal=(40+rand()%50)/100.0f;
}


decompiled_code:
void finish_level()
{
float v0; // xmm1_4

v0 = position();
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)&goal - v0) & LC5) < 0.050000001 && v0 < 1.0 )
++score;
else
failed = 1;
}

canonical_decompiled_code:
void func4()
{
float v0; // xmm1_4

v0 = func2();
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)&goal - v0) & LC5) < 0.050000001 && v0 < 1.0 )
++score;
else
failed = 1;
}

original_code:
void finish_level() {
 float pos=position();
    if( fabs(goal-pos) < 0.05f && pos < 1 ) {
        score += 1;
    } else {
        failed=1;
    }
}

canonical_original_code:
void finish_level() {
 float pos = position();
    if( fabs(goal-pos) < 0.05f && pos < 1 ) {
        score += 1;
    } else {
        failed=1;
    }
}

variable_types: pos float


keyboard

decompiled_code:
void __fastcall keyboard(char a1)
{
if ( a1 == 27 )
exit(0);
if ( a1 == 32 )
{
if ( failed )
{
failed = 0;
level = 0;
score = 0;
init_level();
}
else
{
finish_level();
if ( !failed )
init_level();
}
}
}

canonical_decompiled_code:
void __fastcall func5(char a1)
{
if ( a1 == 27 )
exit(0);
if ( a1 == 32 )
{
if ( failed )
{
failed = 0;
level = 0;
score = 0;
func3();
}
else
{
func4();
if ( !failed )
func3();
}
}
}

original_code:
void keyboard(unsigned char key, int x, int y) {
    switch(key) {
    case 27:
        exit(0);
        break;
    case ' ':
     if(failed) {
      failed=0;
      level=0;
      score=0;
      init_level();
     } else {
         finish_level();
         if(!failed) init_level();
     }
        break;
    }
}

variable_types:
key
unsigned char

variable_types: x int

variable_types: y int


decompiled_code:
__time_t timer_update()
{
__time_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
result = v1.tv_sec - start_time.tv_sec;
*(float *)&the_time = (float)((float)(LODWORD(v1.tv_usec) - LODWORD(start_time.tv_usec)) / 1000000.0)
+ (float)(LODWORD(v1.tv_sec) - LODWORD(start_time.tv_sec));
return result;
}

canonical_decompiled_code:
__time_t func6()
{
__time_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
result = v1.tv_sec - start_time.tv_sec;
*(float *)&the_time = (float)((float)(LODWORD(v1.tv_usec) - LODWORD(start_time.tv_usec)) / 1000000.0)
+ (float)(LODWORD(v1.tv_sec) - LODWORD(start_time.tv_sec));
return result;
}

original_code:
void timer_update() {
    struct timeval current_time;
    gettimeofday(&current_time, ((void *)0));
    the_time = ( (current_time.tv_sec-start_time.tv_sec) + (current_time.tv_usec-start_time.tv_usec)/1000000.0f);
}

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


quad

decompiled_code:
__int64 __fastcall quad(float a1)
{
glLoadIdentity();
glTranslatef(0.0, 0.0, -1.0);
glScalef(a1, a1, a1);
glBegin(7LL);
glVertex2f(-1.0);
glVertex2f(1.0);
glVertex2f(1.0);
glVertex2f(-1.0);
return glEnd(-1.0, 1.0);
}

canonical_decompiled_code:
__int64 __fastcall func7(float a1)
{
glLoadIdentity();
glTranslatef(0.0, 0.0, -1.0);
glScalef(a1, a1, a1);
glBegin(7LL);
glVertex2f(-1.0);
glVertex2f(1.0);
glVertex2f(1.0);
glVertex2f(-1.0);
return glEnd(-1.0, 1.0);
}

original_code:
void quad(float scale) {
 glLoadIdentity();
 glTranslatef(0,0,-1);
 glScalef(scale, scale, scale);
    glBegin(0x0007);
    glVertex2f(-1,-1);
    glVertex2f( 1,-1);
    glVertex2f( 1, 1);
    glVertex2f(-1, 1);
    glEnd();
}

variable_types: scale float


print

decompiled_code:
__int64 print(char *format, ...)
{
int v1; // ebp
char *v2; // rbx
char *v3; // r13
char *v4; // rbp
int v5; // er12
int v6; // eax
__int64 result; // rax
int v8; // eax
char v9[1032]; // [rsp+0h] [rbp-4F8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-F0h] BYREF

va_start(arg, format);
v1 = vsnprintf(v9, 0x400uLL, format, arg);
glLoadIdentity();
if ( v1 <= 0 )
{
v8 = glutGet(102LL);
result = glRasterPos2f(0.0 / (float)v8, 0.80000001);
}
else
{
v2 = v9;
v3 = &v9[v1 - 1 + 1];
v4 = v9;
v5 = 0;
do
v5 += glutBitmapWidth(&glutBitmapHelvetica18, (unsigned int)*v4++);
while ( v4 != v3 );
v6 = glutGet(102LL);
glRasterPos2f((float)-v5 / (float)v6, 0.80000001);
do
result = glutBitmapCharacter(&glutBitmap9By15, (unsigned int)*v2++);
while ( v2 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 func8(char *format, ...)
{
int v1; // ebp
char *v2; // rbx
char *v3; // r13
char *v4; // rbp
int v5; // er12
int v6; // eax
__int64 result; // rax
int v8; // eax
char v9[1032]; // [rsp+0h] [rbp-4F8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-F0h] BYREF

va_start(arg, format);
v1 = vsnprintf(v9, 0x400uLL, format, arg);
glLoadIdentity();
if ( v1 <= 0 )
{
v8 = glutGet(102LL);
result = glRasterPos2f(0.0 / (float)v8, 0.80000001);
}
else
{
v2 = v9;
v3 = &v9[v1 - 1 + 1];
v4 = v9;
v5 = 0;
do
v5 += glutBitmapWidth(&glutBitmapHelvetica18, (unsigned int)*v4++);
while ( v4 != v3 );
v6 = glutGet(102LL);
glRasterPos2f((float)-v5 / (float)v6, 0.80000001);
do
result = glutBitmapCharacter(&glutBitmap9By15, (unsigned int)*v2++);
while ( v2 != v3 );
}
return result;
}

original_code:
void print(char *str, ...) {
 va_list args;
 int i, len;
 char temp[1024];
 int width;
 __builtin_va_start(args,str);
 len=vsnprintf(temp, 1024, str, args);
 glLoadIdentity();
 width=0;
 for(i=0; i < len; i++) {
  width+=glutBitmapWidth( (&glutBitmapHelvetica18) , temp[i]);
 }
 glRasterPos2f( -width/(float)glutGet(((GLenum) 102)) , 0.8f);
 for(i=0; i < len; i++) {
  glutBitmapCharacter( (&glutBitmap9By15) , temp[i]);
 }
 __builtin_va_end(args);
}

canonical_original_code:
void print(char *str, ...) {
 __builtin_va_list args;
 int i; int len;
 char temp[1024];
 int width;
 __builtin_va_start(args,str);
 len=vsnprintf(temp, 1024, str, args);
 glLoadIdentity();
 width=0;
 for(i=0; i < len; i++) {
  width+=glutBitmapWidth( (&glutBitmapHelvetica18) , temp[i]);
 }
 glRasterPos2f( -width/(float)glutGet(((unsigned int) 102)) , 0.8f);
 for(i=0; i < len; i++) {
  glutBitmapCharacter( (&glutBitmap9By15) , temp[i]);
 }
 __builtin_va_end(args);
}

variable_types:
str
char *

variable_types: len int

variable_types:
temp
char [1024]

variable_types: width int


display

decompiled_code:
__int64 display()
{
float v1; // [rsp+Ch] [rbp-Ch]

timer_update();
glClearColor(0.0, 0.0, 0.0);
glClear(0x4000LL);
glColor3f(1.0, 1.0);
v1 = position();
if ( v1 > 1.0 )
{
failed = 1;
LABEL_3:
print("%d", (unsigned int)score);
return glutSwapBuffers();
}
if ( failed )
goto LABEL_3;
glColor3f(1.0, 0.0);
quad(*(float *)&goal + 0.050000001);
glColor3f(0.0, 0.0);
quad(*(float *)&goal - 0.050000001);
glColor3f(1.0, 1.0);
quad(v1);
print("%d", (unsigned int)score);
return glutSwapBuffers();
}

canonical_decompiled_code:
__int64 func9()
{
float v1; // [rsp+Ch] [rbp-Ch]

func6();
glClearColor(0.0, 0.0, 0.0);
glClear(0x4000LL);
glColor3f(1.0, 1.0);
v1 = func2();
if ( v1 > 1.0 )
{
failed = 1;
LABEL_3:
func8("%d", (unsigned int)score);
return glutSwapBuffers();
}
if ( failed )
goto LABEL_3;
glColor3f(1.0, 0.0);
func7(*(float *)&goal + 0.050000001);
glColor3f(0.0, 0.0);
func7(*(float *)&goal - 0.050000001);
glColor3f(1.0, 1.0);
func7(v1);
func8("%d", (unsigned int)score);
return glutSwapBuffers();
}

original_code:
void display() {
    timer_update();
    glClearColor(0,0,0,0);
    glClear(0x00004000);
 glColor3f(1,1,1);
    float pos = position();
 if( pos > 1) failed=1;
    if(failed) {
  print("%d", score);
     glutSwapBuffers();
        return;
    }
    glColor3f(1,0,0);
    quad(goal+0.05f);
    glColor3f(0,0,0);
    quad(goal-0.05f);
    glColor3f(1,1,1);
    quad(pos);
 print("%d", score);
    glutSwapBuffers();
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = argc;
glutInitDisplayMode(2LL, argv, envp);
glutInit(v4, argv);
glutCreateWindow("redgate");
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutIdleFunc(idle);
init_level();
level = 0;
score = 0;
failed = 0;
glutMainLoop();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = argc;
glutInitDisplayMode(2LL, argv, envp);
glutInit(v4, argv);
glutCreateWindow("redgate");
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutIdleFunc(idle);
func3();
level = 0;
score = 0;
failed = 0;
glutMainLoop();
return 0;
}

original_code:
int main(int argc, char **argv) {
    glutInitDisplayMode(0|2);
    glutInit(&argc, argv);
    glutCreateWindow("redgate");
    glutKeyboardFunc(&keyboard);
    glutDisplayFunc(&display);
    glutIdleFunc(&idle);
    init_level();
    level=0;
    score=0;
    failed=0;
    glutMainLoop();
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax

v3 = MaxSum1(a, 6);
printf("Max: %d\n", v3);
v4 = MaxSum2((__int64)a, 1, 6);
printf("Max: %d\n", v4);
v5 = MaxSum3(a, 6);
printf("Max: %d\n", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax

v3 = func7(a, 6);
printf("Max: %d\n", v3);
v4 = func8((__int64)a, 1, 6);
printf("Max: %d\n", v4);
v5 = func9(a, 6);
printf("Max: %d\n", v5);
return 0;
}

original_code:
int main()
{
    printf("Max: %d\n", MaxSum1(a, 6));
    printf("Max: %d\n", MaxSum2(a, 1, 6));
    printf("Max: %d\n", MaxSum3(a, 6));
    return 0;
}


repo: scorpp/db-vk

decompiled_code:
__int64 __fastcall json_error_to_g_error(unsigned int *a1, __int64 *a2)
{
unsigned int v2; // er13
unsigned int v3; // er12
unsigned int v4; // eax
__int64 result; // rax

v2 = a1[1];
v3 = *a1;
v4 = g_quark_from_static_string("vkontakte api for deadbeef");
result = g_error_new(v4, 0LL, "%s. Line: %d, column %d", (const char *)a1 + 92, v3, v2);
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, __int64 *a2)
{
unsigned int v2; // er13
unsigned int v3; // er12
unsigned int v4; // eax
__int64 result; // rax

v2 = a1[1];
v3 = *a1;
v4 = g_quark_from_static_string("vkontakte api for deadbeef");
result = g_error_new(v4, 0LL, "%s. Line: %d, column %d", (const char *)a1 + 92, v3, v2);
*a2 = result;
return result;
}

original_code:
static void
json_error_to_g_error(json_error_t *json_error, GError **error) {
    *error = g_error_new (
            g_quark_from_static_string ("vkontakte api for deadbeef"),
            0,
            "%s. Line: %d, column %d",
            json_error->text,
            json_error->line,
            json_error->column
    );
}

canonical_original_code:
static void json_error_to_g_error(struct json_error_t *json_error, struct _GError **error) {
    *error = g_error_new (
            g_quark_from_static_string ("vkontakte api for deadbeef"),
            0,
            "%s. Line: %d, column %d",
            json_error->text,
            json_error->line,
            json_error->column
    );
}

variable_types: struct json_error_t { int line; int column; int position; char source[80]; char text[160]; } *

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


decompiled_code:
__int64 __fastcall json_decref(__int64 a1)
{
__int64 result; // rax

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

original_code:
static inline
void json_decref(json_t *json)
{
    if(json && json->refcount != (size_t)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

canonical_original_code:
static inline void json_decref(struct json_t *json)
{
    if(json && json->refcount != (unsigned long)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

variable_types: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *

user_defined_types: struct json_t { enum json_type type; unsigned long refcount; }


decompiled_code:
__int64 __fastcall vk_auth_data_free(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
g_free(*a1);
result = g_free(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
g_free(*a1);
result = g_free(a1);
}
return result;
}

original_code:
void
vk_auth_data_free (VkAuthData *vk_auth_data) {
    if (vk_auth_data != ((void *)0)) {
        g_free ((gchar *) vk_auth_data->access_token);
        g_free (vk_auth_data);
    }
}

canonical_original_code:
void vk_auth_data_free(struct VkAuthData *vk_auth_data) {
    if (vk_auth_data != ((void *)0)) {
        g_free ((char *) vk_auth_data->access_token);
        g_free (vk_auth_data);
    }
}

variable_types: struct VkAuthData { char *access_token; long user_id; long expires_in; } *


decompiled_code:
__int64 __fastcall http_write_data(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rbx

v4 = a3 * a2;
g_string_append_len(a4, a1, a3 * a2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rbx

v4 = a3 * a2;
g_string_append_len(a4, a1, a3 * a2);
return v4;
}

original_code:
static size_t
http_write_data (char *ptr, size_t size, size_t nmemb, void *userdata) {
    g_string_append_len ((GString *) userdata, ptr, size * nmemb);
    return size * nmemb;
}

canonical_original_code:
static unsigned long http_write_data(char *ptr, unsigned long size, unsigned long nmemb, void *userdata) {
    g_string_append_len ((struct _GString *) userdata, ptr, size * nmemb);
    return size * nmemb;
}

variable_types:
ptr
char *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
userdata
void *

user_defined_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; }


original_code:
char *
repl_str(const char *str, const char *from, const char *to) {
    size_t cache_sz_inc = 16;
    const size_t cache_sz_inc_factor = 3;
    const size_t cache_sz_inc_max = 1048576;
    char *pret, *ret = ((void *)0);
    const char *pstr2, *pstr = str;
    size_t i, count = 0;
    uintptr_t *pos_cache_tmp, *pos_cache = ((void *)0);
    size_t cache_sz = 0;
    size_t cpylen, orglen, retlen, tolen, fromlen = strlen(from);
    while ((pstr2 = strstr(pstr, from)) != ((void *)0)) {
        count++;
        if (cache_sz < count) {
            cache_sz += cache_sz_inc;
            pos_cache_tmp = realloc(pos_cache, sizeof(*pos_cache) * cache_sz);
            if (pos_cache_tmp == ((void *)0)) {
                goto end_repl_str;
            } else pos_cache = pos_cache_tmp;
            cache_sz_inc *= cache_sz_inc_factor;
            if (cache_sz_inc > cache_sz_inc_max) {
                cache_sz_inc = cache_sz_inc_max;
            }
        }
        pos_cache[count-1] = pstr2 - str;
        pstr = pstr2 + fromlen;
    }
    orglen = pstr - str + strlen(pstr);
    if (count > 0) {
        tolen = strlen(to);
        retlen = orglen + (tolen - fromlen) * count;
    } else retlen = orglen;
    ret = malloc(retlen + 1);
    if (ret == ((void *)0)) {
        goto end_repl_str;
    }
    if (count == 0) {
        strcpy(ret, str);
    } else {
        pret = ret;
        memcpy(pret, str, pos_cache[0]);
        pret += pos_cache[0];
        for (i = 0; i < count; i++) {
            memcpy(pret, to, tolen);
            pret += tolen;
            pstr = str + pos_cache[i] + fromlen;
            cpylen = (i == count-1 ? orglen : pos_cache[i+1]) - pos_cache[i] - fromlen;
            memcpy(pret, pstr, cpylen);
            pret += cpylen;
        }
        ret[retlen] = '\0';
    }
    end_repl_str:
    free(pos_cache);
    return ret;
}

canonical_original_code:
char *repl_str(char *str, char *from, char *to) {
    unsigned long cache_sz_inc = 16;
    unsigned long cache_sz_inc_factor = 3;
    unsigned long cache_sz_inc_max = 1048576;
    char *pret; char *ret = ((void *)0);
    char *pstr2; char *pstr = str;
    unsigned long i; unsigned long count = 0;
    unsigned long *pos_cache_tmp; unsigned long *pos_cache = ((void *)0);
    unsigned long cache_sz = 0;
    unsigned long cpylen; unsigned long orglen; unsigned long retlen; unsigned long tolen; unsigned long fromlen = strlen(from);
    while ((pstr2 = strstr(pstr, from)) != ((void *)0)) {
        count++;
        if (cache_sz < count) {
            cache_sz += cache_sz_inc;
            pos_cache_tmp = realloc(pos_cache, sizeof(*pos_cache) * cache_sz);
            if (pos_cache_tmp == ((void *)0)) {
                goto end_repl_str;
            } else pos_cache = pos_cache_tmp;
            cache_sz_inc *= cache_sz_inc_factor;
            if (cache_sz_inc > cache_sz_inc_max) {
                cache_sz_inc = cache_sz_inc_max;
            }
        }
        pos_cache[count-1] = pstr2 - str;
        pstr = pstr2 + fromlen;
    }
    orglen = pstr - str + strlen(pstr);
    if (count > 0) {
        tolen = strlen(to);
        retlen = orglen + (tolen - fromlen) * count;
    } else retlen = orglen;
    ret = malloc(retlen + 1);
    if (ret == ((void *)0)) {
        goto end_repl_str;
    }
    if (count == 0) {
        strcpy(ret, str);
    } else {
        pret = ret;
        memcpy(pret, str, pos_cache[0]);
        pret += pos_cache[0];
        for (i = 0; i < count; i++) {
            memcpy(pret, to, tolen);
            pret += tolen;
            pstr = str + pos_cache[i] + fromlen;
            cpylen = (i == count-1 ? orglen : pos_cache[i+1]) - pos_cache[i] - fromlen;
            memcpy(pret, pstr, cpylen);
            pret += cpylen;
        }
        ret[retlen] = '\0';
    }
    end_repl_str:
    free(pos_cache);
    return ret;
}

variable_types:
from
char *

variable_types:
to
char *

variable_types:
pret
char *

variable_types:
ret
char *

variable_types:
pstr
char *

variable_types:
i
unsigned long

variable_types:
count
unsigned long

variable_types:
cpylen
unsigned long

variable_types:
orglen
unsigned long

variable_types:
retlen
unsigned long

variable_types:
tolen
unsigned long

variable_types:
fromlen
unsigned long


decompiled_code:
size_t __fastcall strip_prefix(__int64 a1, const char *a2)
{
int v2; // edx
size_t result; // rax

v2 = g_str_has_prefix();
result = 0LL;
if ( v2 )
result = a1 + strlen(a2);
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(__int64 a1, const char *a2)
{
int v2; // edx
size_t result; // rax

v2 = g_str_has_prefix();
result = 0LL;
if ( v2 )
result = a1 + strlen(a2);
return result;
}

original_code:
const gchar *
strip_prefix(const gchar *haystack, const gchar *needle) {
    if (g_str_has_prefix (haystack, needle)) {
        return haystack + strlen (needle);
    }
    return ((void *)0);
}

canonical_original_code:
char *strip_prefix(char *haystack, char *needle) {
    if (g_str_has_prefix (haystack, needle)) {
        return haystack + strlen (needle);
    }
    return ((void *)0);
}

variable_types:
haystack
char *

variable_types:
needle
char *


winchhandler

repo: scott-parker/mg-openbsd

decompiled_code:
void winchhandler()
{
winch_flag = 1;
}

canonical_decompiled_code:
void func0()
{
winch_flag = 1;
}

original_code:
static void
winchhandler(int sig)
{
 winch_flag = 1;
}

variable_types: sig int


fakec

decompiled_code:
__int64 fakec()
{
++cci;
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
++cci;
return 0LL;
}

original_code:
static int
fakec(int c)
{
 cci++;
 return (0);
}

variable_types: c int


charcost

decompiled_code:
__int64 __fastcall charcost(const char *a1)
{
cci = 0;
tputs(a1, nrow, (int (*)(int))fakec);
return (unsigned int)cci;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
cci = 0;
tputs(a1, nrow, (int (*)(int))fakec);
return (unsigned int)cci;
}

original_code:
static int
charcost(const char *s)
{
 cci = 0;
 tputs(s, nrow, fakec);
 return (cci);
}

canonical_original_code:
static int charcost(char *s)
{
 cci = 0;
 tputs(s, nrow, fakec);
 return (cci);
}

variable_types:
s
char *


tttidy

decompiled_code:
int tttidy()
{
char **v0; // rax
const char *v1; // rdi

ttykeymaptidy();
v0 = cur_term->type.Strings;
v1 = v0[40];
if ( v1 )
LODWORD(v0) = tputs(v1, 1, (int (*)(int))&ttputc);
return (int)v0;
}

canonical_decompiled_code:
int func3()
{
char **v0; // rax
const char *v1; // rdi

ttykeymaptidy();
v0 = cur_term->type.Strings;
v1 = v0[40];
if ( v1 )
LODWORD(v0) = tputs(v1, 1, (int (*)(int))&ttputc);
return (int)v0;
}

original_code:
void
tttidy(void)
{
 ttykeymaptidy();
 if (((TERMTYPE *)(cur_term))-> Strings[40])
  tputs(((TERMTYPE *)(cur_term))-> Strings[40], 1, ttputc);
}

canonical_original_code:
void tttidy()
{
 ttykeymaptidy();
 if (((struct termtype *)(cur_term))-> Strings[40])
  tputs(((struct termtype *)(cur_term))-> Strings[40], 1, ttputc);
}

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