decompiled_code:
void request_token_example_get()
{
char *v0; // rbp
const char *v1; // rax
const char *v2; // r12
size_t v3; // rbx
const void **v4; // r8
const void **v5; // r15
const void **v6; // r14
const char *v7; // rax
char *v8; // rdi
const char **v9; // [rsp+8h] [rbp-50h]
void *base; // [rsp+18h] [rbp-40h] 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 = v1;
base = 0LL;
printf("HTTP-reply: %s\n", v1);
v3 = (int)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 ( (int)v3 > 1 )
{
v4 = (const void **)base;
v5 = (const void **)((char *)base + 8);
v6 = (const void **)((char *)base + 8 * (unsigned int)(v3 - 1) + 8);
while ( 1 )
{
v7 = (const char *)*v4;
if ( !memcmp(*v4, "oauth_token=", 0xCuLL) )
{
v9 = (const char **)v4;
req_t_key = (__int64)strdup(v7 + 12);
v7 = *v9;
}
if ( !memcmp(v7, "oauth_token_secret=", 0x13uLL) )
req_t_secret = (__int64)strdup(v7 + 19);
v4 = v5;
if ( v6 == v5 )
break;
++v5;
}
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);
v8 = (char *)v2;
goto LABEL_16;
}
puts("Please check your network,maybe it's blocked by GFW");
FATAL("HTTP request for an oauth request-token failed.\n");
v8 = v0;
if ( v0 )
LABEL_16:
free(v8);
}

canonical_decompiled_code:
void func4()
{
char *v0; // rbp
const char *v1; // rax
const char *v2; // r12
size_t v3; // rbx
const void **v4; // r8
const void **v5; // r15
const void **v6; // r14
const char *v7; // rax
char *v8; // rdi
const char **v9; // [rsp+8h] [rbp-50h]
void *base; // [rsp+18h] [rbp-40h] 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 = v1;
base = 0LL;
printf("HTTP-reply: %s\n", v1);
v3 = (int)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 ( (int)v3 > 1 )
{
v4 = (const void **)base;
v5 = (const void **)((char *)base + 8);
v6 = (const void **)((char *)base + 8 * (unsigned int)(v3 - 1) + 8);
while ( 1 )
{
v7 = (const char *)*v4;
if ( !memcmp(*v4, "oauth_token=", 0xCuLL) )
{
v9 = (const char **)v4;
req_t_key = (__int64)strdup(v7 + 12);
v7 = *v9;
}
if ( !memcmp(v7, "oauth_token_secret=", 0x13uLL) )
req_t_secret = (__int64)strdup(v7 + 19);
v4 = v5;
if ( v6 == v5 )
break;
++v5;
}
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);
v8 = (char *)v2;
goto LABEL_16;
}
puts("Please check your network,maybe it's blocked by GFW");
FATAL("HTTP request for an oauth request-token failed.\n");
v8 = v0;
if ( v0 )
LABEL_16:
free(v8);
}

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


repo: scola/twittrouter

decompiled_code:
__int64 __fastcall access_token_example_get(const char *a1)
{
char *v1; // rbp
const char *v2; // rax
char *v3; // r12
unsigned int v4; // er13
size_t v5; // rbx
void *v6; // r15
char *v7; // rax
const char **v8; // r13
const char **v9; // r14
const char *v10; // rbx
_QWORD *v12; // rax
void *v13; // rdi
void *v14; // rdi
void *v15; // rdi
void *v16; // r15
const char *v17; // [rsp+8h] [rbp-460h]
const char *v18; // [rsp+10h] [rbp-458h]
const char *v19; // [rsp+18h] [rbp-450h]
void *base; // [rsp+28h] [rbp-440h] BYREF
char s[1080]; // [rsp+30h] [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;
v4 = 0;
printf("HTTP-reply: %s\n", v2);
v5 = (int)oauth_split_url_parameters(v3, &base);
qsort(base, v5, 8uLL, (__compar_fn_t)&oauth_cmpstringp);
printf("rc=%d rv[0]=%s rv[1]=%s\n", (unsigned int)v5, *(const char **)base, *((const char **)base + 1));
v6 = base;
if ( (int)v5 <= 1 )
goto LABEL_12;
v19 = 0LL;
v7 = (char *)(unsigned int)(v5 - 1);
v8 = (const char **)base;
v18 = 0LL;
v9 = (const char **)((char *)base + 8 * (_QWORD)v7 + 8);
v17 = 0LL;
do
{
v10 = *v8;
if ( !memcmp(*v8, "oauth_token=", 0xCuLL) )
{
v7 = strdup(v10 + 12);
v17 = v7;
}
if ( !memcmp(v10, "oauth_token_secret=", 0x13uLL) )
{
v7 = strdup(v10 + 19);
v18 = v7;
}
if ( !memcmp(v10, "screen_name=", 0xCuLL) )
{
v7 = strdup(v10 + 12);
v19 = v7;
}
++v8;
}
while ( v9 != v8 );
LOBYTE(v8) = v17 != 0LL;
LOBYTE(v7) = v18 != 0LL;
v4 = (unsigned int)v7 & (unsigned int)v8;
LOBYTE(v4) = (v19 != 0LL) & v4;
if ( (_BYTE)v4 )
{
printf("key: '%s'\nsecret: '%s'\nscreen_name: '%s'\n", v17, v18, v19);
v12 = (_QWORD *)conf;
v13 = *(void **)(conf + 8LL);
if ( v13 )
{
free(v13);
v12 = (_QWORD *)conf;
}
v14 = (void *)v12[4];
if ( v14 )
{
free(v14);
v12 = (_QWORD *)conf;
}
v15 = (void *)v12[5];
if ( v15 )
{
free(v15);
v12 = (_QWORD *)conf;
}
v16 = base;
v12[1] = v19;
v12[4] = v17;
v12[5] = v18;
free(v16);
if ( !v1 )
goto LABEL_14;
}
else
{
LABEL_12:
free(v6);
if ( !v1 )
{
LABEL_14:
free(v3);
return v4;
}
}
free(v1);
goto LABEL_14;
}
puts("Please check your network,maybe it's blocked by GFW");
FATAL("HTTP request for an oauth request-token failed.\n");
if ( v1 )
free(v1);
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
char *v1; // rbp
const char *v2; // rax
char *v3; // r12
unsigned int v4; // er13
size_t v5; // rbx
void *v6; // r15
char *v7; // rax
const char **v8; // r13
const char **v9; // r14
const char *v10; // rbx
_QWORD *v12; // rax
void *v13; // rdi
void *v14; // rdi
void *v15; // rdi
void *v16; // r15
const char *v17; // [rsp+8h] [rbp-460h]
const char *v18; // [rsp+10h] [rbp-458h]
const char *v19; // [rsp+18h] [rbp-450h]
void *base; // [rsp+28h] [rbp-440h] BYREF
char s[1080]; // [rsp+30h] [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;
v4 = 0;
printf("HTTP-reply: %s\n", v2);
v5 = (int)oauth_split_url_parameters(v3, &base);
qsort(base, v5, 8uLL, (__compar_fn_t)&oauth_cmpstringp);
printf("rc=%d rv[0]=%s rv[1]=%s\n", (unsigned int)v5, *(const char **)base, *((const char **)base + 1));
v6 = base;
if ( (int)v5 <= 1 )
goto LABEL_12;
v19 = 0LL;
v7 = (char *)(unsigned int)(v5 - 1);
v8 = (const char **)base;
v18 = 0LL;
v9 = (const char **)((char *)base + 8 * (_QWORD)v7 + 8);
v17 = 0LL;
do
{
v10 = *v8;
if ( !memcmp(*v8, "oauth_token=", 0xCuLL) )
{
v7 = strdup(v10 + 12);
v17 = v7;
}
if ( !memcmp(v10, "oauth_token_secret=", 0x13uLL) )
{
v7 = strdup(v10 + 19);
v18 = v7;
}
if ( !memcmp(v10, "screen_name=", 0xCuLL) )
{
v7 = strdup(v10 + 12);
v19 = v7;
}
++v8;
}
while ( v9 != v8 );
LOBYTE(v8) = v17 != 0LL;
LOBYTE(v7) = v18 != 0LL;
v4 = (unsigned int)v7 & (unsigned int)v8;
LOBYTE(v4) = (v19 != 0LL) & v4;
if ( (_BYTE)v4 )
{
printf("key: '%s'\nsecret: '%s'\nscreen_name: '%s'\n", v17, v18, v19);
v12 = (_QWORD *)conf;
v13 = *(void **)(conf + 8LL);
if ( v13 )
{
free(v13);
v12 = (_QWORD *)conf;
}
v14 = (void *)v12[4];
if ( v14 )
{
free(v14);
v12 = (_QWORD *)conf;
}
v15 = (void *)v12[5];
if ( v15 )
{
free(v15);
v12 = (_QWORD *)conf;
}
v16 = base;
v12[1] = v19;
v12[4] = v17;
v12[5] = v18;
free(v16);
if ( !v1 )
goto LABEL_14;
}
else
{
LABEL_12:
free(v6);
if ( !v1 )
{
LABEL_14:
free(v3);
return v4;
}
}
free(v1);
goto LABEL_14;
}
puts("Please check your network,maybe it's blocked by GFW");
FATAL("HTTP request for an oauth request-token failed.\n");
if ( v1 )
free(v1);
return 0;
}

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]

variable_types:
reply
char *


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

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

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

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

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

variable_types:
username
char *

variable_types:
friendship
char *


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

variable_types:
size
unsigned long

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

variable_types:
ptr
void *


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

variable_types:
nmemb
unsigned long


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 *

return_type: char *


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

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

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

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

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(void *a1, void *a2)
{
_BYTE *v2; // r12
_BYTE *v3; // rbp
char *v4; // r13

v2 = packstring_constprop_0(a1);
v3 = packstring_constprop_0(a2);
v4 = concatstring_constprop_0(v2, v3);
if ( v2 )
free(v2);
if ( v3 )
free(v3);
return v4;
}

canonical_decompiled_code:
char *__fastcall func2(void *a1, void *a2)
{
_BYTE *v2; // r12
_BYTE *v3; // rbp
char *v4; // r13

v2 = packstring_constprop_0(a1);
v3 = packstring_constprop_0(a2);
v4 = func1(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)
{
int v1; // ebx
char *v2; // rbp
__int64 *v3; // r13
char *v4; // r12
char *v5; // r14
const char *v6; // rdi
int v7; // eax
const char *v8; // rsi
char *v9; // r12
size_t v10; // rax
char *v11; // rax
char *v12; // r13
signed __int64 v13; // r13
char *v14; // rax
char *v15; // rbp
size_t v16; // rax
int v17; // [rsp+Ch] [rbp-7Ch]
const char *v18; // [rsp+10h] [rbp-78h]
char v20; // [rsp+20h] [rbp-68h] BYREF
__int64 v21[4]; // [rsp+28h] [rbp-60h] BYREF
const char *v22; // [rsp+48h] [rbp-40h] BYREF
char v23[56]; // [rsp+50h] [rbp-38h] BYREF

v1 = 0;
v2 = (char *)v21;
v3 = (__int64 *)&v20;
v4 = (char *)v21;
v5 = build_json_item("TwitterID", *(void **)(conf + 8LL));
v21[0] = (__int64)build_json_item("CONSUMER_KEY", *(void **)(conf + 16LL));
v21[1] = (__int64)build_json_item("CONSUMER_SECRET", *(void **)(conf + 24LL));
v21[2] = (__int64)build_json_item("OAUTH_TOKEN", *(void **)(conf + 32LL));
v21[3] = (__int64)build_json_item("OAUTH_TOKEN_SECRET", *(void **)(conf + 40LL));
v6 = v5;
v18 = build_json_item("whitelist", (void *)*conf);
v22 = v18;
while ( 1 )
{
v7 = v1 + strlen(v6);
v17 = v7;
v1 = v7;
if ( v4 == v23 )
break;
v6 = *(const char **)v4;
v4 += 8;
}
v8 = v5;
v9 = (char *)calloc(v7 + 21, 1uLL);
while ( 1 )
{
++v3;
v10 = strlen(v9);
v11 = stpcpy(&v9[v10], v8);
strcpy(v11, ",\r\n\t");
if ( &v22 == (const char **)v3 )
break;
v8 = (const char *)*v3;
}
v12 = stpcpy(v11 + 4, v18);
while ( 1 )
{
if ( v5 )
free(v5);
if ( v2 == v23 )
break;
v5 = *(char **)v2;
v2 += 8;
}
v13 = v12 - v9;
v14 = (char *)calloc(v17 + 29, 1uLL);
*(_DWORD *)v14 = 151653755;
v15 = v14;
memcpy(v14 + 4, v9, v13 + 1);
*(_DWORD *)&v15[v13 + 4] = 8194573;
free(v9);
printf("\n%s\n", v15);
v16 = strlen(v15);
dump_to_file_isra_0(v15, v16, a1);
free(v15);
}

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

return_type: void


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; // rbx
char *v2; // rax
const char *v3; // rbp
__int64 v4; // rbp
struct tm *v5; // rax
time_t timer; // [rsp+8h] [rbp-C0h] BYREF
char v8[32]; // [rsp+10h] [rbp-B8h] BYREF
char s[16]; // [rsp+30h] [rbp-98h] BYREF
__int128 v10; // [rsp+40h] [rbp-88h]
__int128 v11; // [rsp+50h] [rbp-78h]
__int128 v12; // [rsp+60h] [rbp-68h]
__int128 v13; // [rsp+70h] [rbp-58h]
__int128 v14; // [rsp+80h] [rbp-48h]
__int128 v15; // [rsp+90h] [rbp-38h]
__int128 v16; // [rsp+A0h] [rbp-28h]

*(_OWORD *)s = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
if ( strtok(a1, "\n") )
{
while ( 1 )
{
v2 = strtok(0LL, " \t\n");
v3 = v2;
if ( !v2 )
break;
if ( isValidIpAddress(v2) )
{
v1 = v3;
}
else if ( isValidMAC((__int64)v3) && !strstr((const char *)*conf, v3) )
{
v4 = arpList;
if ( !Query(arpList, v1) )
{
InsertEmptyLink_constprop_0(v4, v1);
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);
v5 = localtime(&timer);
strftime(v8, 0x14uLL, "%F %T", v5);
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; // rbx
char *v2; // rax
const char *v3; // rbp
__int64 v4; // rbp
struct tm *v5; // rax
time_t timer; // [rsp+8h] [rbp-C0h] BYREF
char v8[32]; // [rsp+10h] [rbp-B8h] BYREF
char s[16]; // [rsp+30h] [rbp-98h] BYREF
__int128 v10; // [rsp+40h] [rbp-88h]
__int128 v11; // [rsp+50h] [rbp-78h]
__int128 v12; // [rsp+60h] [rbp-68h]
__int128 v13; // [rsp+70h] [rbp-58h]
__int128 v14; // [rsp+80h] [rbp-48h]
__int128 v15; // [rsp+90h] [rbp-38h]
__int128 v16; // [rsp+A0h] [rbp-28h]

*(_OWORD *)s = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
if ( strtok(a1, "\n") )
{
while ( 1 )
{
v2 = strtok(0LL, " \t\n");
v3 = v2;
if ( !v2 )
break;
if ( func0(v2) )
{
v1 = v3;
}
else if ( func1((__int64)v3) && !strstr((const char *)*conf, v3) )
{
v4 = arpList;
if ( !func4(arpList, v1) )
{
func2(v4, v1);
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);
v5 = localtime(&timer);
strftime(v8, 0x14uLL, "%F %T", v5);
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:
// attributes: thunk
__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:
__int64 __fastcall keyboard(char a1)
{
__int64 result; // rax

if ( a1 == 27 )
exit(0);
if ( a1 == 32 )
{
if ( failed )
{
failed = 0;
level = 0;
score = 0;
result = init_level();
}
else
{
finish_level();
result = (unsigned int)failed;
if ( !failed )
result = init_level();
}
}
return result;
}

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

if ( a1 == 27 )
exit(0);
if ( a1 == 32 )
{
if ( failed )
{
failed = 0;
level = 0;
score = 0;
result = func3();
}
else
{
func4();
result = (unsigned int)failed;
if ( !failed )
result = func3();
}
}
return result;
}

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
int v3; // er12
char *v4; // r13
char *v5; // rbp
__int64 v6; // rsi
int v7; // eax
__int64 v8; // rsi
__int64 result; // rax
int v10; // eax
gcc_va_list arg; // [rsp+8h] [rbp-4F0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4D8h] BYREF

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

canonical_decompiled_code:
__int64 func8(char *format, ...)
{
int v1; // ebp
char *v2; // rbx
int v3; // er12
char *v4; // r13
char *v5; // rbp
__int64 v6; // rsi
int v7; // eax
__int64 v8; // rsi
__int64 result; // rax
int v10; // eax
gcc_va_list arg; // [rsp+8h] [rbp-4F0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4D8h] BYREF

va_start(arg, format);
v1 = vsnprintf(s, 0x400uLL, format, arg);
glLoadIdentity();
if ( v1 <= 0 )
{
v10 = glutGet(102LL);
result = glRasterPos2f(0.0 / (float)v10, 0.80000001);
}
else
{
v2 = s;
v3 = 0;
v4 = &s[v1 - 1 + 1];
v5 = s;
do
{
v6 = (unsigned int)*v5++;
v3 += glutBitmapWidth(&glutBitmapHelvetica18, v6);
}
while ( v5 != v4 );
v7 = glutGet(102LL);
glRasterPos2f((float)-v3 / (float)v7, 0.80000001);
do
{
v8 = (unsigned int)*v2++;
result = glutBitmapCharacter(&glutBitmap9By15, v8);
}
while ( v2 != v4 );
}
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 v0; // xmm0_4

timer_update();
glClearColor(0.0, 0.0, 0.0);
glClear(0x4000LL);
glColor3f(1.0, 1.0);
v0 = position();
if ( v0 <= 1.0 )
{
if ( !failed )
{
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(v0);
}
}
else
{
failed = 1;
}
print("%d", (unsigned int)score);
return glutSwapBuffers();
}

canonical_decompiled_code:
__int64 func9()
{
float v0; // xmm0_4

func6();
glClearColor(0.0, 0.0, 0.0);
glClear(0x4000LL);
glColor3f(1.0, 1.0);
v0 = func2();
if ( v0 <= 1.0 )
{
if ( !failed )
{
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(v0);
}
}
else
{
failed = 1;
}
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 **

return_type: int


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_constprop_0("Max: %d\n", argv);
printf("Max: %d\n", v3);
v4 = MaxSum2_constprop_0(1LL, 6LL);
printf("Max: %d\n", v4);
v5 = MaxSum3_constprop_0();
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 = func9("Max: %d\n", argv);
printf("Max: %d\n", v3);
v4 = func8(1LL, 6LL);
printf("Max: %d\n", v4);
v5 = func7();
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 && !_InterlockedSub64((volatile signed __int64 *)(a1 + 8), 1uLL) )
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 && !_InterlockedSub64((volatile signed __int64 *)(a1 + 8), 1uLL) )
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; // r12

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; // r12

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 *

return_type: unsigned long

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


decompiled_code:
char *__fastcall repl_str(char *haystack, char *needle, const char *a3)
{
__int64 *v3; // r12
char *v4; // rbp
__int64 v5; // r14
unsigned __int64 v6; // r15
unsigned __int64 v7; // r13
char *v8; // rax
char *v9; // rdx
__int64 *v10; // rax
size_t v11; // r15
size_t v12; // rbp
__int64 v13; // r15
char *v14; // rcx
__int64 i; // r15
char *v16; // rax
char *v17; // rdx
char *v18; // rcx
size_t v19; // rax
char *v20; // rcx
size_t v22; // [rsp+8h] [rbp-70h]
char *src; // [rsp+10h] [rbp-68h]
char *v24; // [rsp+18h] [rbp-60h]
char *dest; // [rsp+28h] [rbp-50h]
size_t v27; // [rsp+38h] [rbp-40h]

v3 = 0LL;
v4 = haystack;
v5 = 0LL;
v22 = strlen(needle);
v6 = 0LL;
v7 = 16LL;
while ( 1 )
{
v8 = strstr(v4, needle);
v9 = v8;
if ( !v8 )
break;
if ( v6 < ++v5 )
{
v6 += v7;
v24 = v8;
v10 = (__int64 *)realloc(v3, 8 * v6);
v9 = v24;
if ( !v10 )
goto LABEL_19;
v7 *= 3LL;
v3 = v10;
if ( v7 > 0x100000 )
v7 = 0x100000LL;
}
v3[v5 - 1] = v9 - haystack;
v4 = &v9[v22];
}
v11 = v4 - haystack + strlen(v4);
src = (char *)v11;
if ( v5 )
{
v12 = strlen(a3);
v27 = v11 + v5 * (v12 - v22);
dest = (char *)malloc(v27 + 1);
if ( !dest )
{
LABEL_19:
dest = 0LL;
goto LABEL_18;
}
v13 = *v3;
memcpy(dest, haystack, *v3);
v14 = &dest[v13];
for ( i = 0LL; i != v5; ++i )
{
v16 = (char *)memcpy(v14, a3, v12);
v17 = src;
v18 = v16;
v19 = v3[i] + v22;
v20 = &v18[v12];
if ( i != v5 - 1 )
v17 = (char *)v3[i + 1];
v14 = &v17[(_QWORD)memcpy(v20, &haystack[v19], (size_t)&v17[-v19]) - v19];
}
dest[v27] = 0;
}
else
{
dest = (char *)malloc(v11 + 1);
if ( dest )
strcpy(dest, haystack);
}
LABEL_18:
free(v3);
return dest;
}

canonical_decompiled_code:
char *__fastcall func2(char *haystack, char *needle, const char *a3)
{
__int64 *v3; // r12
char *v4; // rbp
__int64 v5; // r14
unsigned __int64 v6; // r15
unsigned __int64 v7; // r13
char *v8; // rax
char *v9; // rdx
__int64 *v10; // rax
size_t v11; // r15
size_t v12; // rbp
__int64 v13; // r15
char *v14; // rcx
__int64 i; // r15
char *v16; // rax
char *v17; // rdx
char *v18; // rcx
size_t v19; // rax
char *v20; // rcx
size_t v22; // [rsp+8h] [rbp-70h]
char *src; // [rsp+10h] [rbp-68h]
char *v24; // [rsp+18h] [rbp-60h]
char *dest; // [rsp+28h] [rbp-50h]
size_t v27; // [rsp+38h] [rbp-40h]

v3 = 0LL;
v4 = haystack;
v5 = 0LL;
v22 = strlen(needle);
v6 = 0LL;
v7 = 16LL;
while ( 1 )
{
v8 = strstr(v4, needle);
v9 = v8;
if ( !v8 )
break;
if ( v6 < ++v5 )
{
v6 += v7;
v24 = v8;
v10 = (__int64 *)realloc(v3, 8 * v6);
v9 = v24;
if ( !v10 )
goto LABEL_19;
v7 *= 3LL;
v3 = v10;
if ( v7 > 0x100000 )
v7 = 0x100000LL;
}
v3[v5 - 1] = v9 - haystack;
v4 = &v9[v22];
}
v11 = v4 - haystack + strlen(v4);
src = (char *)v11;
if ( v5 )
{
v12 = strlen(a3);
v27 = v11 + v5 * (v12 - v22);
dest = (char *)malloc(v27 + 1);
if ( !dest )
{
LABEL_19:
dest = 0LL;
goto LABEL_18;
}
v13 = *v3;
memcpy(dest, haystack, *v3);
v14 = &dest[v13];
for ( i = 0LL; i != v5; ++i )
{
v16 = (char *)memcpy(v14, a3, v12);
v17 = src;
v18 = v16;
v19 = v3[i] + v22;
v20 = &v18[v12];
if ( i != v5 - 1 )
v17 = (char *)v3[i + 1];
v14 = &v17[(_QWORD)memcpy(v20, &haystack[v19], (size_t)&v17[-v19]) - v19];
}
dest[v27] = 0;
}
else
{
dest = (char *)malloc(v11 + 1);
if ( dest )
strcpy(dest, haystack);
}
LABEL_18:
free(v3);
return dest;
}

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


ttmove

decompiled_code:
void __fastcall ttmove(int a1, int a2)
{
char *v2; // rax

if ( ttrow != a1 || ttcol != a2 )
{
v2 = tgoto(*((const char **)cur_term->type.Strings + 10), a2, a1);
tputs(v2, 1, (int (*)(int))&ttputc);
ttrow = a1;
ttcol = a2;
}
}

canonical_decompiled_code:
void __fastcall func4(int a1, int a2)
{
char *v2; // rax

if ( ttrow != a1 || ttcol != a2 )
{
v2 = tgoto(*((const char **)cur_term->type.Strings + 10), a2, a1);
tputs(v2, 1, (int (*)(int))&ttputc);
ttrow = a1;
ttcol = a2;
}
}

original_code:
void
ttmove(int row, int col)
{
 if (ttrow != row || ttcol != col) {
  tputs(tgoto(((TERMTYPE *)(cur_term))-> Strings[10], col, row), 1, ttputc);
  ttrow = row;
  ttcol = col;
 }
}

canonical_original_code:
void ttmove(int row, int col)
{
 if (ttrow != row || ttcol != col) {
  tputs(tgoto(((struct termtype *)(cur_term))-> Strings[10], col, row), 1, ttputc);
  ttrow = row;
  ttcol = col;
 }
}

variable_types: row int

variable_types: col int


tteeol

decompiled_code:
int tteeol()
{
char **v0; // rax
const char *v1; // rdi
int v2; // ebx

v0 = cur_term->type.Strings;
v1 = v0[6];
if ( v1 )
{
LODWORD(v0) = tputs(v1, 1, (int (*)(int))&ttputc);
}
else
{
v2 = ncol - ttcol;
if ( ncol != ttcol )
{
do
{
LODWORD(v0) = ttputc(32);
--v2;
}
while ( v2 );
}
ttcol = 1000;
ttrow = 1000;
}
return (int)v0;
}

canonical_decompiled_code:
int func5()
{
char **v0; // rax
const char *v1; // rdi
int v2; // ebx

v0 = cur_term->type.Strings;
v1 = v0[6];
if ( v1 )
{
LODWORD(v0) = tputs(v1, 1, (int (*)(int))&ttputc);
}
else
{
v2 = ncol - ttcol;
if ( ncol != ttcol )
{
do
{
LODWORD(v0) = ttputc(32);
--v2;
}
while ( v2 );
}
ttcol = 1000;
ttrow = 1000;
}
return (int)v0;
}

original_code:
void
tteeol(void)
{
 int i;
 if (((TERMTYPE *)(cur_term))-> Strings[6])
  tputs(((TERMTYPE *)(cur_term))-> Strings[6], 1, ttputc);
 else {
  i = ncol - ttcol;
  while (i--)
   ttputc(' ');
  ttrow = ttcol = 1000;
 }
}

canonical_original_code:
void tteeol()
{
 int i;
 if (((struct termtype *)(cur_term))-> Strings[6])
  tputs(((struct termtype *)(cur_term))-> Strings[6], 1, ttputc);
 else {
  i = ncol - ttcol;
  while (i--)
   ttputc(' ');
  ttrow = ttcol = 1000;
 }
}

variable_types: i int


ttbeep

decompiled_code:
__int64 ttbeep()
{
tputs(*((const char **)cur_term->type.Strings + 1), 1, (int (*)(int))&ttputc);
return ttflush();
}

canonical_decompiled_code:
__int64 func6()
{
tputs(*((const char **)cur_term->type.Strings + 1), 1, (int (*)(int))&ttputc);
return ttflush();
}

original_code:
void
ttbeep(void)
{
 tputs(((TERMTYPE *)(cur_term))-> Strings[1], 1, ttputc);
 ttflush();
}

canonical_original_code:
void ttbeep()
{
 tputs(((struct termtype *)(cur_term))-> Strings[1], 1, ttputc);
 ttflush();
}


ttwindow

decompiled_code:
int __fastcall ttwindow(int a1, int a2)
{
char **v2; // rax
const char *v4; // rdi
int v5; // er12
char *v6; // rax

v2 = cur_term->type.Strings;
v4 = v2[3];
if ( v4 && (tttop != a1 || ttbot != a2) )
{
v5 = nrow - ttrow;
v6 = tgoto(v4, a2, a1);
LODWORD(v2) = tputs(v6, v5, (int (*)(int))&ttputc);
tttop = a1;
ttrow = 1000;
ttcol = 1000;
ttbot = a2;
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2)
{
char **v2; // rax
const char *v4; // rdi
int v5; // er12
char *v6; // rax

v2 = cur_term->type.Strings;
v4 = v2[3];
if ( v4 && (tttop != a1 || ttbot != a2) )
{
v5 = nrow - ttrow;
v6 = tgoto(v4, a2, a1);
LODWORD(v2) = tputs(v6, v5, (int (*)(int))&ttputc);
tttop = a1;
ttrow = 1000;
ttcol = 1000;
ttbot = a2;
}
return (int)v2;
}

original_code:
void
ttwindow(int top, int bot)
{
 if (((TERMTYPE *)(cur_term))-> Strings[3] && (tttop != top || ttbot != bot)) {
  tputs(tgoto(((TERMTYPE *)(cur_term))-> Strings[3], bot, top), nrow - ttrow, ttputc);
  ttrow = 1000;
  ttcol = 1000;
  tttop = top;
  ttbot = bot;
 }
}

canonical_original_code:
void ttwindow(int top, int bot)
{
 if (((struct termtype *)(cur_term))-> Strings[3] && (tttop != top || ttbot != bot)) {
  tputs(tgoto(((struct termtype *)(cur_term))-> Strings[3], bot, top), nrow - ttrow, ttputc);
  ttrow = 1000;
  ttcol = 1000;
  tttop = top;
  ttbot = bot;
 }
}

variable_types: top int

variable_types: bot int


ttnowindow

decompiled_code:
int ttnowindow()
{
int result; // eax
const char *v1; // rdi
int v2; // esi
int v3; // ebp
char *v4; // rax

result = (int)cur_term;
v1 = (const char *)*((_QWORD *)cur_term->type.Strings + 3);
if ( v1 )
{
v2 = cur_term->type.Numbers[2];
v3 = nrow - ttrow;
if ( v2 < nrow )
v2 = nrow;
v4 = tgoto(v1, v2 - 1, 0);
result = tputs(v4, v3, (int (*)(int))&ttputc);
ttrow = 1000;
ttcol = 1000;
tttop = 1000;
ttbot = 1000;
}
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax
const char *v1; // rdi
int v2; // esi
int v3; // ebp
char *v4; // rax

result = (int)cur_term;
v1 = (const char *)*((_QWORD *)cur_term->type.Strings + 3);
if ( v1 )
{
v2 = cur_term->type.Numbers[2];
v3 = nrow - ttrow;
if ( v2 < nrow )
v2 = nrow;
v4 = tgoto(v1, v2 - 1, 0);
result = tputs(v4, v3, (int (*)(int))&ttputc);
ttrow = 1000;
ttcol = 1000;
tttop = 1000;
ttbot = 1000;
}
return result;
}

original_code:
void
ttnowindow(void)
{
 if (((TERMTYPE *)(cur_term))-> Strings[3]) {
  tputs(tgoto(((TERMTYPE *)(cur_term))-> Strings[3], (nrow > ((TERMTYPE *)(cur_term))-> Numbers[2] ? nrow : ((TERMTYPE *)(cur_term))-> Numbers[2]) - 1, 0), nrow - ttrow, ttputc);
  ttrow = 1000;
  ttcol = 1000;
  tttop = 1000;
  ttbot = 1000;
 }
}

canonical_original_code:
void ttnowindow()
{
 if (((struct termtype *)(cur_term))-> Strings[3]) {
  tputs(tgoto(((struct termtype *)(cur_term))-> Strings[3], (nrow > ((struct termtype *)(cur_term))-> Numbers[2] ? nrow : ((struct termtype *)(cur_term))-> Numbers[2]) - 1, 0), nrow - ttrow, ttputc);
  ttrow = 1000;
  ttcol = 1000;
  tttop = 1000;
  ttbot = 1000;
 }
}


ttinsl

decompiled_code:
int __fastcall ttinsl(int a1, int a2, int a3)
{
int v4; // er12
char **v5; // rax
int v6; // er13
char **v7; // rax
const char *v8; // rdi
char *v9; // rax
int v10; // ebp
char **v11; // rax
const char *v12; // rdi
char *v13; // rax
int v14; // ebx
int v15; // ebx

if ( a1 == a2 )
{
ttmove(a1, 0);
LODWORD(v11) = tteeol();
return (int)v11;
}
v4 = a3;
v5 = cur_term->type.Strings;
if ( !v5[3] || !v5[130] )
{
if ( !insdel )
{
LODWORD(v11) = panic("ttinsl: Can't insert/delete line");
return (int)v11;
}
ttmove(a2 + 1 - a3, 0);
v6 = nrow - ttrow;
v7 = cur_term->type.Strings;
v8 = v7[106];
if ( v8 )
{
v9 = tgoto(v8, 0, v4);
tputs(v9, v6, (int (*)(int))&ttputc);
ttmove(a1, 0);
v10 = nrow - ttrow;
v11 = cur_term->type.Strings;
v12 = v11[110];
if ( v12 )
goto LABEL_7;
if ( v4 <= 0 )
goto LABEL_8;
}
else
{
v14 = 0;
if ( v4 <= 0 )
{
ttmove(a1, 0);
v11 = cur_term->type.Strings;
v12 = v11[110];
if ( !v12 )
goto LABEL_8;
v10 = nrow - ttrow;
goto LABEL_7;
}
while ( 1 )
{
++v14;
tputs(v7[22], v6, (int (*)(int))&ttputc);
if ( v4 == v14 )
break;
v7 = cur_term->type.Strings;
}
ttmove(a1, 0);
v10 = nrow - ttrow;
v11 = cur_term->type.Strings;
v12 = v11[110];
if ( v12 )
{
LABEL_7:
v13 = tgoto(v12, 0, v4);
LODWORD(v11) = tputs(v13, v10, (int (*)(int))&ttputc);
LABEL_8:
ttrow = 1000;
ttcol = 1000;
return (int)v11;
}
}
v15 = 0;
while ( 1 )
{
++v15;
LODWORD(v11) = tputs(v11[53], v10, (int (*)(int))&ttputc);
if ( v4 <= v15 )
break;
v11 = cur_term->type.Strings;
}
goto LABEL_8;
}
ttwindow(a1, a2);
ttmove(a1, 0);
for ( ; v4; --v4 )
tputs(*((const char **)cur_term->type.Strings + 130), a2 - a1, (int (*)(int))&ttputc);
LODWORD(v11) = ttnowindow();
return (int)v11;
}

canonical_decompiled_code:
int __fastcall func9(int a1, int a2, int a3)
{
int v4; // er12
char **v5; // rax
int v6; // er13
char **v7; // rax
const char *v8; // rdi
char *v9; // rax
int v10; // ebp
char **v11; // rax
const char *v12; // rdi
char *v13; // rax
int v14; // ebx
int v15; // ebx

if ( a1 == a2 )
{
func4(a1, 0);
LODWORD(v11) = func5();
return (int)v11;
}
v4 = a3;
v5 = cur_term->type.Strings;
if ( !v5[3] || !v5[130] )
{
if ( !insdel )
{
LODWORD(v11) = panic("ttinsl: Can't insert/delete line");
return (int)v11;
}
func4(a2 + 1 - a3, 0);
v6 = nrow - ttrow;
v7 = cur_term->type.Strings;
v8 = v7[106];
if ( v8 )
{
v9 = tgoto(v8, 0, v4);
tputs(v9, v6, (int (*)(int))&ttputc);
func4(a1, 0);
v10 = nrow - ttrow;
v11 = cur_term->type.Strings;
v12 = v11[110];
if ( v12 )
goto LABEL_7;
if ( v4 <= 0 )
goto LABEL_8;
}
else
{
v14 = 0;
if ( v4 <= 0 )
{
func4(a1, 0);
v11 = cur_term->type.Strings;
v12 = v11[110];
if ( !v12 )
goto LABEL_8;
v10 = nrow - ttrow;
goto LABEL_7;
}
while ( 1 )
{
++v14;
tputs(v7[22], v6, (int (*)(int))&ttputc);
if ( v4 == v14 )
break;
v7 = cur_term->type.Strings;
}
func4(a1, 0);
v10 = nrow - ttrow;
v11 = cur_term->type.Strings;
v12 = v11[110];
if ( v12 )
{
LABEL_7:
v13 = tgoto(v12, 0, v4);
LODWORD(v11) = tputs(v13, v10, (int (*)(int))&ttputc);
LABEL_8:
ttrow = 1000;
ttcol = 1000;
return (int)v11;
}
}
v15 = 0;
while ( 1 )
{
++v15;
LODWORD(v11) = tputs(v11[53], v10, (int (*)(int))&ttputc);
if ( v4 <= v15 )
break;
v11 = cur_term->type.Strings;
}
goto LABEL_8;
}
func7(a1, a2);
func4(a1, 0);
for ( ; v4; --v4 )
tputs(*((const char **)cur_term->type.Strings + 130), a2 - a1, (int (*)(int))&ttputc);
LODWORD(v11) = func8();
return (int)v11;
}

original_code:
void
ttinsl(int row, int bot, int nchunk)
{
 int i, nl;
 if (row == bot) {
  ttmove(row, 0);
  tteeol();
  return;
 }
 if (((TERMTYPE *)(cur_term))-> Strings[3] && ((TERMTYPE *)(cur_term))-> Strings[130]) {
  nl = bot - row;
  ttwindow(row, bot);
  ttmove(row, 0);
  while (nchunk--)
   tputs(((TERMTYPE *)(cur_term))-> Strings[130], nl, ttputc);
  ttnowindow();
  return;
 } else if (insdel) {
  ttmove(1 + bot - nchunk, 0);
  nl = nrow - ttrow;
  if (((TERMTYPE *)(cur_term))-> Strings[106])
   tputs(tgoto(((TERMTYPE *)(cur_term))-> Strings[106], 0, nchunk), nl, ttputc);
  else
   for (i = 0; i < nchunk; i++)
    tputs(((TERMTYPE *)(cur_term))-> Strings[22], nl, ttputc);
  ttmove(row, 0);
  nl = nrow - ttrow;
  if (((TERMTYPE *)(cur_term))-> Strings[110])
   tputs(tgoto(((TERMTYPE *)(cur_term))-> Strings[110], 0, nchunk), nl, ttputc);
  else
   for (i = 0; i < nchunk; i++)
    tputs(((TERMTYPE *)(cur_term))-> Strings[53], nl, ttputc);
  ttrow = 1000;
  ttcol = 1000;
 } else
  panic("ttinsl: Can't insert/delete line");
}

canonical_original_code:
void ttinsl(int row, int bot, int nchunk)
{
 int i; int nl;
 if (row == bot) {
  ttmove(row, 0);
  tteeol();
  return;
 }
 if (((struct termtype *)(cur_term))-> Strings[3] && ((struct termtype *)(cur_term))-> Strings[130]) {
  nl = bot - row;
  ttwindow(row, bot);
  ttmove(row, 0);
  while (nchunk--)
   tputs(((struct termtype *)(cur_term))-> Strings[130], nl, ttputc);
  ttnowindow();
  return;
 } else if (insdel) {
  ttmove(1 + bot - nchunk, 0);
  nl = nrow - ttrow;
  if (((struct termtype *)(cur_term))-> Strings[106])
   tputs(tgoto(((struct termtype *)(cur_term))-> Strings[106], 0, nchunk), nl, ttputc);
  else
   for (i = 0; i < nchunk; i++)
    tputs(((struct termtype *)(cur_term))-> Strings[22], nl, ttputc);
  ttmove(row, 0);
  nl = nrow - ttrow;
  if (((struct termtype *)(cur_term))-> Strings[110])
   tputs(tgoto(((struct termtype *)(cur_term))-> Strings[110], 0, nchunk), nl, ttputc);
  else
   for (i = 0; i < nchunk; i++)
    tputs(((struct termtype *)(cur_term))-> Strings[53], nl, ttputc);
  ttrow = 1000;
  ttcol = 1000;
 } else
  panic("ttinsl: Can't insert/delete line");
}

variable_types: nchunk int

variable_types: nl int


ttdell

decompiled_code:
int __fastcall ttdell(int a1, int a2, int a3)
{
char **v4; // rax
int v5; // ebp
int v6; // er13
char **v7; // rax
const char *v8; // rdi
char *v9; // rax
int v10; // er12
const char *v11; // rdi
char *v12; // rax
int v13; // er12
int v14; // ebp

if ( a1 == a2 )
{
ttmove(a1, 0);
LODWORD(v4) = tteeol();
return (int)v4;
}
if ( !*((_QWORD *)cur_term->type.Strings + 3) )
{
if ( !insdel )
{
LODWORD(v4) = panic("ttdell: Can't insert/delete line");
return (int)v4;
}
ttmove(a1, 0);
v5 = a2 + 1 - a3;
v6 = nrow - ttrow;
v7 = cur_term->type.Strings;
v8 = v7[106];
if ( v8 )
{
v9 = tgoto(v8, 0, a3);
tputs(v9, v6, (int (*)(int))&ttputc);
ttmove(v5, 0);
v10 = nrow - ttrow;
v4 = cur_term->type.Strings;
v11 = v4[110];
if ( v11 )
goto LABEL_9;
if ( a3 <= 0 )
goto LABEL_10;
}
else
{
v13 = 0;
if ( a3 <= 0 )
{
ttmove(v5, 0);
v4 = cur_term->type.Strings;
v11 = v4[110];
if ( !v11 )
goto LABEL_10;
v10 = nrow - ttrow;
goto LABEL_9;
}
while ( 1 )
{
++v13;
tputs(v7[22], v6, (int (*)(int))&ttputc);
if ( a3 == v13 )
break;
v7 = cur_term->type.Strings;
}
ttmove(v5, 0);
v10 = nrow - ttrow;
v4 = cur_term->type.Strings;
v11 = v4[110];
if ( v11 )
{
LABEL_9:
v12 = tgoto(v11, 0, a3);
LODWORD(v4) = tputs(v12, v10, (int (*)(int))&ttputc);
LABEL_10:
ttrow = 1000;
ttcol = 1000;
return (int)v4;
}
}
v14 = 0;
while ( 1 )
{
++v14;
LODWORD(v4) = tputs(v4[53], v10, (int (*)(int))&ttputc);
if ( a3 <= v14 )
break;
v4 = cur_term->type.Strings;
}
goto LABEL_10;
}
ttwindow(a1, a2);
ttmove(a2, 0);
for ( ; a3; --a3 )
tputs(scroll_fwd, a2 - a1, (int (*)(int))&ttputc);
LODWORD(v4) = ttnowindow();
return (int)v4;
}

canonical_decompiled_code:
int __fastcall func10(int a1, int a2, int a3)
{
char **v4; // rax
int v5; // ebp
int v6; // er13
char **v7; // rax
const char *v8; // rdi
char *v9; // rax
int v10; // er12
const char *v11; // rdi
char *v12; // rax
int v13; // er12
int v14; // ebp

if ( a1 == a2 )
{
func4(a1, 0);
LODWORD(v4) = func5();
return (int)v4;
}
if ( !*((_QWORD *)cur_term->type.Strings + 3) )
{
if ( !insdel )
{
LODWORD(v4) = panic("ttdell: Can't insert/delete line");
return (int)v4;
}
func4(a1, 0);
v5 = a2 + 1 - a3;
v6 = nrow - ttrow;
v7 = cur_term->type.Strings;
v8 = v7[106];
if ( v8 )
{
v9 = tgoto(v8, 0, a3);
tputs(v9, v6, (int (*)(int))&ttputc);
func4(v5, 0);
v10 = nrow - ttrow;
v4 = cur_term->type.Strings;
v11 = v4[110];
if ( v11 )
goto LABEL_9;
if ( a3 <= 0 )
goto LABEL_10;
}
else
{
v13 = 0;
if ( a3 <= 0 )
{
func4(v5, 0);
v4 = cur_term->type.Strings;
v11 = v4[110];
if ( !v11 )
goto LABEL_10;
v10 = nrow - ttrow;
goto LABEL_9;
}
while ( 1 )
{
++v13;
tputs(v7[22], v6, (int (*)(int))&ttputc);
if ( a3 == v13 )
break;
v7 = cur_term->type.Strings;
}
func4(v5, 0);
v10 = nrow - ttrow;
v4 = cur_term->type.Strings;
v11 = v4[110];
if ( v11 )
{
LABEL_9:
v12 = tgoto(v11, 0, a3);
LODWORD(v4) = tputs(v12, v10, (int (*)(int))&ttputc);
LABEL_10:
ttrow = 1000;
ttcol = 1000;
return (int)v4;
}
}
v14 = 0;
while ( 1 )
{
++v14;
LODWORD(v4) = tputs(v4[53], v10, (int (*)(int))&ttputc);
if ( a3 <= v14 )
break;
v4 = cur_term->type.Strings;
}
goto LABEL_10;
}
func7(a1, a2);
func4(a2, 0);
for ( ; a3; --a3 )
tputs(scroll_fwd, a2 - a1, (int (*)(int))&ttputc);
LODWORD(v4) = func8();
return (int)v4;
}

original_code:
void
ttdell(int row, int bot, int nchunk)
{
 int i, nl;
 if (row == bot) {
  ttmove(row, 0);
  tteeol();
  return;
 }
 if (((TERMTYPE *)(cur_term))-> Strings[3]) {
  nl = bot - row;
  ttwindow(row, bot);
  ttmove(bot, 0);
  while (nchunk--)
   tputs(scroll_fwd, nl, ttputc);
  ttnowindow();
 } else if (insdel) {
  ttmove(row, 0);
  nl = nrow - ttrow;
  if (((TERMTYPE *)(cur_term))-> Strings[106])
   tputs(tgoto(((TERMTYPE *)(cur_term))-> Strings[106], 0, nchunk), nl, ttputc);
  else
   for (i = 0; i < nchunk; i++)
    tputs(((TERMTYPE *)(cur_term))-> Strings[22], nl, ttputc);
  ttmove(1 + bot - nchunk, 0);
  nl = nrow - ttrow;
  if (((TERMTYPE *)(cur_term))-> Strings[110])
   tputs(tgoto(((TERMTYPE *)(cur_term))-> Strings[110], 0, nchunk), nl, ttputc);
  else
   for (i = 0; i < nchunk; i++)
    tputs(((TERMTYPE *)(cur_term))-> Strings[53], nl, ttputc);
  ttrow = 1000;
  ttcol = 1000;
 } else
  panic("ttdell: Can't insert/delete line");
}

canonical_original_code:
void ttdell(int row, int bot, int nchunk)
{
 int i; int nl;
 if (row == bot) {
  ttmove(row, 0);
  tteeol();
  return;
 }
 if (((struct termtype *)(cur_term))-> Strings[3]) {
  nl = bot - row;
  ttwindow(row, bot);
  ttmove(bot, 0);
  while (nchunk--)
   tputs(scroll_fwd, nl, ttputc);
  ttnowindow();
 } else if (insdel) {
  ttmove(row, 0);
  nl = nrow - ttrow;
  if (((struct termtype *)(cur_term))-> Strings[106])
   tputs(tgoto(((struct termtype *)(cur_term))-> Strings[106], 0, nchunk), nl, ttputc);
  else
   for (i = 0; i < nchunk; i++)
    tputs(((struct termtype *)(cur_term))-> Strings[22], nl, ttputc);
  ttmove(1 + bot - nchunk, 0);
  nl = nrow - ttrow;
  if (((struct termtype *)(cur_term))-> Strings[110])
   tputs(tgoto(((struct termtype *)(cur_term))-> Strings[110], 0, nchunk), nl, ttputc);
  else
   for (i = 0; i < nchunk; i++)
    tputs(((struct termtype *)(cur_term))-> Strings[53], nl, ttputc);
  ttrow = 1000;
  ttcol = 1000;
 } else
  panic("ttdell: Can't insert/delete line");
}


tteeop

decompiled_code:
int tteeop()
{
char **v0; // rax
const char *v1; // rdi
int result; // eax
int v3; // ebx
int v4; // edi

v0 = cur_term->type.Strings;
v1 = v0[7];
if ( v1 )
return tputs(v1, nrow - ttrow, (int (*)(int))&ttputc);
tputs(v0[6], 1, (int (*)(int))&ttputc);
if ( insdel )
{
result = ttdell(ttrow + 1, cur_term->type.Numbers[2], cur_term->type.Numbers[2] - ttrow - 1);
}
else
{
v3 = ttrow + 1;
result = cur_term->type.Numbers[2];
if ( ttrow + 1 <= result )
{
do
{
v4 = v3++;
ttmove(v4, 0);
tteeol();
result = cur_term->type.Numbers[2];
}
while ( result >= v3 );
}
}
ttcol = 1000;
ttrow = 1000;
return result;
}

canonical_decompiled_code:
int func11()
{
char **v0; // rax
const char *v1; // rdi
int result; // eax
int v3; // ebx
int v4; // edi

v0 = cur_term->type.Strings;
v1 = v0[7];
if ( v1 )
return tputs(v1, nrow - ttrow, (int (*)(int))&ttputc);
tputs(v0[6], 1, (int (*)(int))&ttputc);
if ( insdel )
{
result = func10(ttrow + 1, cur_term->type.Numbers[2], cur_term->type.Numbers[2] - ttrow - 1);
}
else
{
v3 = ttrow + 1;
result = cur_term->type.Numbers[2];
if ( ttrow + 1 <= result )
{
do
{
v4 = v3++;
func4(v4, 0);
func5();
result = cur_term->type.Numbers[2];
}
while ( result >= v3 );
}
}
ttcol = 1000;
ttrow = 1000;
return result;
}

original_code:
void
tteeop(void)
{
 int line;
 if (((TERMTYPE *)(cur_term))-> Strings[7])
  tputs(((TERMTYPE *)(cur_term))-> Strings[7], nrow - ttrow, ttputc);
 else {
  tputs(((TERMTYPE *)(cur_term))-> Strings[6], 1, ttputc);
  if (insdel)
   ttdell(ttrow + 1, ((TERMTYPE *)(cur_term))-> Numbers[2], ((TERMTYPE *)(cur_term))-> Numbers[2] - ttrow - 1);
  else {
   for (line = ttrow + 1; line <= ((TERMTYPE *)(cur_term))-> Numbers[2]; ++line) {
    ttmove(line, 0);
    tteeol();
   }
  }
  ttrow = ttcol = 1000;
 }
}

canonical_original_code:
void tteeop()
{
 int line;
 if (((struct termtype *)(cur_term))-> Strings[7])
  tputs(((struct termtype *)(cur_term))-> Strings[7], nrow - ttrow, ttputc);
 else {
  tputs(((struct termtype *)(cur_term))-> Strings[6], 1, ttputc);
  if (insdel)
   ttdell(ttrow + 1, ((struct termtype *)(cur_term))-> Numbers[2], ((struct termtype *)(cur_term))-> Numbers[2] - ttrow - 1);
  else {
   for (line = ttrow + 1; line <= ((struct termtype *)(cur_term))-> Numbers[2]; ++line) {
    ttmove(line, 0);
    tteeol();
   }
  }
  ttrow = ttcol = 1000;
 }
}

variable_types: line int


ttcolor

decompiled_code:
int __fastcall ttcolor(int a1)
{
int result; // eax

if ( tthue != a1 )
{
if ( a1 == 1 )
{
result = tputs(*((const char **)cur_term->type.Strings + 43), 1, (int (*)(int))&ttputc);
tthue = 1;
}
else
{
if ( a1 == 2 )
result = tputs(*((const char **)cur_term->type.Strings + 35), 1, (int (*)(int))&ttputc);
tthue = a1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(int a1)
{
int result; // eax

if ( tthue != a1 )
{
if ( a1 == 1 )
{
result = tputs(*((const char **)cur_term->type.Strings + 43), 1, (int (*)(int))&ttputc);
tthue = 1;
}
else
{
if ( a1 == 2 )
result = tputs(*((const char **)cur_term->type.Strings + 35), 1, (int (*)(int))&ttputc);
tthue = a1;
}
}
return result;
}

original_code:
void
ttcolor(int color)
{
 if (color != tthue) {
  if (color == 1)
   tputs(((TERMTYPE *)(cur_term))-> Strings[43], 1, ttputc);
  else if (color == 2)
   tputs(((TERMTYPE *)(cur_term))-> Strings[35], 1, ttputc);
  tthue = color;
 }
}

canonical_original_code:
void ttcolor(int color)
{
 if (color != tthue) {
  if (color == 1)
   tputs(((struct termtype *)(cur_term))-> Strings[43], 1, ttputc);
  else if (color == 2)
   tputs(((struct termtype *)(cur_term))-> Strings[35], 1, ttputc);
  tthue = color;
 }
}

variable_types: color int


ttresize

decompiled_code:
__int64 ttresize()
{
__int64 result; // rax
__int16 v1; // [rsp+8h] [rbp-10h] BYREF

ioctl(0, 0x5413uLL, &v1);
result = vtresize(1LL);
if ( (_DWORD)result != 1 )
result = panic("vtresize failed");
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax
__int16 v1; // [rsp+8h] [rbp-10h] BYREF

ioctl(0, 0x5413uLL, &v1);
result = vtresize(1LL);
if ( (_DWORD)result != 1 )
result = panic("vtresize failed");
return result;
}

original_code:
void
ttresize(void)
{
 int newrow = 0, newcol = 0;
 struct winsize winsize;
 if (ioctl(0, 0x5413, &winsize) == 0) {
  newrow = winsize.ws_row;
  newcol = winsize.ws_col;
 }
 if ((newrow <= 0 || newcol <= 0) &&
     ((newrow = ((TERMTYPE *)(cur_term))-> Numbers[2]) <= 0 || (newcol = ((TERMTYPE *)(cur_term))-> Numbers[0]) <= 0)) {
  newrow = 24;
  newcol = 80;
 }
 if (vtresize(1, newrow, newcol) != 1)
  panic("vtresize failed");
}

canonical_original_code:
void ttresize()
{
 int newrow = 0; int newcol = 0;
 struct winsize winsize;
 if (ioctl(0, 0x5413, &winsize) == 0) {
  newrow = winsize.ws_row;
  newcol = winsize.ws_col;
 }
 if ((newrow <= 0 || newcol <= 0) &&
     ((newrow = ((struct termtype *)(cur_term))-> Numbers[2]) <= 0 || (newcol = ((struct termtype *)(cur_term))-> Numbers[0]) <= 0)) {
  newrow = 24;
  newcol = 80;
 }
 if (vtresize(1, newrow, newcol) != 1)
  panic("vtresize failed");
}

variable_types: newrow int

variable_types: newcol int

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


ttinit

decompiled_code:
__int64 ttinit()
{
char **v0; // rax
char *v1; // rdx
char **v2; // rax
const char *v3; // rdi
const char *v4; // rdi
int v5; // ebx
int v6; // ebx
_BOOL4 v7; // edx
const char *v8; // rdi
char *v10; // rdx
const char *v11; // r8
const char *v12; // rdi
bool v13; // zf
int v14[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( setupterm(0LL, 1, v14) )
panic("Terminal setup failed");
signal(28, (__sighandler_t)winchhandler);
signal(18, (__sighandler_t)winchhandler);
siginterrupt(28, 1);
v0 = cur_term->type.Strings;
v1 = v0[129];
scroll_fwd = v1;
if ( !v1 || !*v1 )
{
v10 = v0[107];
scroll_fwd = v10;
if ( !v10 || !*v10 )
{
scroll_fwd = "\n";
if ( !v0[10] )
goto LABEL_22;
LABEL_6:
if ( v0[19] )
goto LABEL_7;
goto LABEL_22;
}
}
if ( v0[10] )
goto LABEL_6;
LABEL_22:
panic("This terminal is too stupid to run mg");
LABEL_7:
ttresize();
v2 = cur_term->type.Strings;
v3 = v2[6];
if ( v3 )
{
tceeol = charcost(v3);
v2 = cur_term->type.Strings;
}
else
{
tceeol = ncol;
}
v4 = v2[3];
if ( v4 && v2[130] )
{
v5 = charcost(v4);
tcinsl = charcost(*((const char **)cur_term->type.Strings + 130)) + 2 * v5;
v2 = cur_term->type.Strings;
v4 = v2[3];
}
else
{
v11 = v2[110];
if ( v11 || (v11 = v2[53]) != 0LL )
{
tcinsl = charcost(v11);
v2 = cur_term->type.Strings;
v4 = v2[3];
if ( v4 )
goto LABEL_13;
goto LABEL_25;
}
tcinsl = ncol * nrow;
}
if ( v4 )
{
LABEL_13:
v6 = charcost(v4);
tcdell = charcost(scroll_fwd) + 2 * v6;
goto LABEL_14;
}
LABEL_25:
v12 = v2[106];
if ( !v12 )
{
v12 = v2[22];
if ( !v12 )
{
v13 = v2[53] == 0LL;
tcdell = ncol * nrow;
if ( !v13 || !v2[110] )
goto LABEL_31;
goto LABEL_35;
}
}
tcdell = charcost(v12);
LABEL_14:
v2 = cur_term->type.Strings;
if ( !v2[53] && !v2[110] )
{
LABEL_31:
v7 = 0;
goto LABEL_16;
}
v7 = 1;
if ( v2[22] )
goto LABEL_16;
LABEL_35:
v7 = v2[106] != 0LL;
LABEL_16:
v8 = v2[28];
insdel = v7;
if ( v8 )
tputs(v8, 1, (int (*)(int))&ttputc);
return ttresize();
}

canonical_decompiled_code:
__int64 func14()
{
char **v0; // rax
char *v1; // rdx
char **v2; // rax
const char *v3; // rdi
const char *v4; // rdi
int v5; // ebx
int v6; // ebx
_BOOL4 v7; // edx
const char *v8; // rdi
char *v10; // rdx
const char *v11; // r8
const char *v12; // rdi
bool v13; // zf
int v14[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( setupterm(0LL, 1, v14) )
panic("Terminal setup failed");
signal(28, (__sighandler_t)winchhandler);
signal(18, (__sighandler_t)winchhandler);
siginterrupt(28, 1);
v0 = cur_term->type.Strings;
v1 = v0[129];
scroll_fwd = v1;
if ( !v1 || !*v1 )
{
v10 = v0[107];
scroll_fwd = v10;
if ( !v10 || !*v10 )
{
scroll_fwd = "\n";
if ( !v0[10] )
goto LABEL_22;
LABEL_6:
if ( v0[19] )
goto LABEL_7;
goto LABEL_22;
}
}
if ( v0[10] )
goto LABEL_6;
LABEL_22:
panic("This terminal is too stupid to run mg");
LABEL_7:
func13();
v2 = cur_term->type.Strings;
v3 = v2[6];
if ( v3 )
{
tceeol = func2(v3);
v2 = cur_term->type.Strings;
}
else
{
tceeol = ncol;
}
v4 = v2[3];
if ( v4 && v2[130] )
{
v5 = func2(v4);
tcinsl = func2(*((const char **)cur_term->type.Strings + 130)) + 2 * v5;
v2 = cur_term->type.Strings;
v4 = v2[3];
}
else
{
v11 = v2[110];
if ( v11 || (v11 = v2[53]) != 0LL )
{
tcinsl = func2(v11);
v2 = cur_term->type.Strings;
v4 = v2[3];
if ( v4 )
goto LABEL_13;
goto LABEL_25;
}
tcinsl = ncol * nrow;
}
if ( v4 )
{
LABEL_13:
v6 = func2(v4);
tcdell = func2(scroll_fwd) + 2 * v6;
goto LABEL_14;
}
LABEL_25:
v12 = v2[106];
if ( !v12 )
{
v12 = v2[22];
if ( !v12 )
{
v13 = v2[53] == 0LL;
tcdell = ncol * nrow;
if ( !v13 || !v2[110] )
goto LABEL_31;
goto LABEL_35;
}
}
tcdell = func2(v12);
LABEL_14:
v2 = cur_term->type.Strings;
if ( !v2[53] && !v2[110] )
{
LABEL_31:
v7 = 0;
goto LABEL_16;
}
v7 = 1;
if ( v2[22] )
goto LABEL_16;
LABEL_35:
v7 = v2[106] != 0LL;
LABEL_16:
v8 = v2[28];
insdel = v7;
if ( v8 )
tputs(v8, 1, (int (*)(int))&ttputc);
return func13();
}

original_code:
void
ttinit(void)
{
 int errret;
 if (setupterm(((void *)0), 1, &errret))
  panic("Terminal setup failed");
 signal(28, winchhandler);
 signal(18, winchhandler);
 siginterrupt(28, 1);
 scroll_fwd = ((TERMTYPE *)(cur_term))-> Strings[129];
 if (scroll_fwd == ((void *)0) || *scroll_fwd == '\0') {
  scroll_fwd = ((TERMTYPE *)(cur_term))-> Strings[107];
  if (scroll_fwd == ((void *)0) || *scroll_fwd == '\0')
   scroll_fwd = "\n";
 }
 if (((TERMTYPE *)(cur_term))-> Strings[10] == ((void *)0) || ((TERMTYPE *)(cur_term))-> Strings[19] == ((void *)0))
  panic("This terminal is too stupid to run mg");
 ttresize();
 if (!((TERMTYPE *)(cur_term))-> Strings[6])
  tceeol = ncol;
 else
  tceeol = charcost(((TERMTYPE *)(cur_term))-> Strings[6]);
 if (((TERMTYPE *)(cur_term))-> Strings[3] && ((TERMTYPE *)(cur_term))-> Strings[130])
  tcinsl = charcost(((TERMTYPE *)(cur_term))-> Strings[3]) * 2 +
      charcost(((TERMTYPE *)(cur_term))-> Strings[130]);
 else if (((TERMTYPE *)(cur_term))-> Strings[110])
  tcinsl = charcost(((TERMTYPE *)(cur_term))-> Strings[110]);
 else if (((TERMTYPE *)(cur_term))-> Strings[53])
  tcinsl = charcost(((TERMTYPE *)(cur_term))-> Strings[53]);
 else
  tcinsl = nrow * ncol;
 if (((TERMTYPE *)(cur_term))-> Strings[3])
  tcdell = charcost(((TERMTYPE *)(cur_term))-> Strings[3]) * 2 +
      charcost(scroll_fwd);
 else if (((TERMTYPE *)(cur_term))-> Strings[106])
  tcdell = charcost(((TERMTYPE *)(cur_term))-> Strings[106]);
 else if (((TERMTYPE *)(cur_term))-> Strings[22])
  tcdell = charcost(((TERMTYPE *)(cur_term))-> Strings[22]);
 else
  tcdell = nrow * ncol;
 insdel = (((TERMTYPE *)(cur_term))-> Strings[53] || ((TERMTYPE *)(cur_term))-> Strings[110]) &&
     (((TERMTYPE *)(cur_term))-> Strings[22] || ((TERMTYPE *)(cur_term))-> Strings[106]);
 if (((TERMTYPE *)(cur_term))-> Strings[28])
  tputs(((TERMTYPE *)(cur_term))-> Strings[28], 1, ttputc);
 ttresize();
}

canonical_original_code:
void ttinit()
{
 int errret;
 if (setupterm(((void *)0), 1, &errret))
  panic("Terminal setup failed");
 signal(28, winchhandler);
 signal(18, winchhandler);
 siginterrupt(28, 1);
 scroll_fwd = ((struct termtype *)(cur_term))-> Strings[129];
 if (scroll_fwd == ((void *)0) || *scroll_fwd == '\0') {
  scroll_fwd = ((struct termtype *)(cur_term))-> Strings[107];
  if (scroll_fwd == ((void *)0) || *scroll_fwd == '\0')
   scroll_fwd = "\n";
 }
 if (((struct termtype *)(cur_term))-> Strings[10] == ((void *)0) || ((struct termtype *)(cur_term))-> Strings[19] == ((void *)0))
  panic("This terminal is too stupid to run mg");
 ttresize();
 if (!((struct termtype *)(cur_term))-> Strings[6])
  tceeol = ncol;
 else
  tceeol = charcost(((struct termtype *)(cur_term))-> Strings[6]);
 if (((struct termtype *)(cur_term))-> Strings[3] && ((struct termtype *)(cur_term))-> Strings[130])
  tcinsl = charcost(((struct termtype *)(cur_term))-> Strings[3]) * 2 +
      charcost(((struct termtype *)(cur_term))-> Strings[130]);
 else if (((struct termtype *)(cur_term))-> Strings[110])
  tcinsl = charcost(((struct termtype *)(cur_term))-> Strings[110]);
 else if (((struct termtype *)(cur_term))-> Strings[53])
  tcinsl = charcost(((struct termtype *)(cur_term))-> Strings[53]);
 else
  tcinsl = nrow * ncol;
 if (((struct termtype *)(cur_term))-> Strings[3])
  tcdell = charcost(((struct termtype *)(cur_term))-> Strings[3]) * 2 +
      charcost(scroll_fwd);
 else if (((struct termtype *)(cur_term))-> Strings[106])
  tcdell = charcost(((struct termtype *)(cur_term))-> Strings[106]);
 else if (((struct termtype *)(cur_term))-> Strings[22])
  tcdell = charcost(((struct termtype *)(cur_term))-> Strings[22]);
 else
  tcdell = nrow * ncol;
 insdel = (((struct termtype *)(cur_term))-> Strings[53] || ((struct termtype *)(cur_term))-> Strings[110]) &&
     (((struct termtype *)(cur_term))-> Strings[22] || ((struct termtype *)(cur_term))-> Strings[106]);
 if (((struct termtype *)(cur_term))-> Strings[28])
  tputs(((struct termtype *)(cur_term))-> Strings[28], 1, ttputc);
 ttresize();
}

variable_types: errret int


ttreinit

decompiled_code:
__int64 ttreinit()
{
char **v0; // rax
const char *v1; // rdi
const char *v2; // rdi

if ( (unsigned int)fchecktime(curbp) != 1 )
*(_BYTE *)(curbp + 91LL) |= 0x20u;
v0 = cur_term->type.Strings;
v1 = v0[28];
if ( v1 )
{
tputs(v1, 1, (int (*)(int))&ttputc);
v0 = cur_term->type.Strings;
}
v2 = v0[89];
if ( v2 )
tputs(v2, 1, (int (*)(int))&ttputc);
return ttresize();
}

canonical_decompiled_code:
__int64 func15()
{
char **v0; // rax
const char *v1; // rdi
const char *v2; // rdi

if ( (unsigned int)fchecktime(curbp) != 1 )
*(_BYTE *)(curbp + 91LL) |= 0x20u;
v0 = cur_term->type.Strings;
v1 = v0[28];
if ( v1 )
{
tputs(v1, 1, (int (*)(int))&ttputc);
v0 = cur_term->type.Strings;
}
v2 = v0[89];
if ( v2 )
tputs(v2, 1, (int (*)(int))&ttputc);
return func13();
}

original_code:
void
ttreinit(void)
{
 if (fchecktime(curbp) != 1) {
  curbp->b_flag |= 0x20;
 }
 if (((TERMTYPE *)(cur_term))-> Strings[28])
  tputs(((TERMTYPE *)(cur_term))-> Strings[28], 1, ttputc);
 if (((TERMTYPE *)(cur_term))-> Strings[89])
  tputs(((TERMTYPE *)(cur_term))-> Strings[89], 1, ttputc);
 ttresize();
}

canonical_original_code:
void ttreinit()
{
 if (fchecktime(curbp) != 1) {
  curbp->b_flag |= 0x20;
 }
 if (((struct termtype *)(cur_term))-> Strings[28])
  tputs(((struct termtype *)(cur_term))-> Strings[28], 1, ttputc);
 if (((struct termtype *)(cur_term))-> Strings[89])
  tputs(((struct termtype *)(cur_term))-> Strings[89], 1, ttputc);
 ttresize();
}


decompiled_code:
__int64 __fastcall find_autoexec(char *name)
{
__int64 v1; // rbx
int v2; // ebp
int v3; // er14
__int64 v4; // r12
__int64 v5; // rax

if ( !ready )
return 0LL;
v1 = autos;
if ( !autos )
return 0LL;
v2 = 0;
v3 = 0;
v4 = 0LL;
do
{
if ( !fnmatch(*(const char **)(v1 + 8), name, 0) )
{
if ( v2 >= v3 )
{
v4 = reallocarray(v4, v3 + 9, 8LL);
if ( !v4 )
panic("out of memory");
v3 += 8;
}
v5 = v2++;
*(_QWORD *)(v4 + 8 * v5) = *(_QWORD *)(v1 + 16);
}
v1 = *(_QWORD *)v1;
}
while ( v1 );
if ( v2 )
*(_QWORD *)(v4 + 8LL * v2) = 0LL;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *name)
{
__int64 v1; // rbx
int v2; // ebp
int v3; // er14
__int64 v4; // r12
__int64 v5; // rax

if ( !ready )
return 0LL;
v1 = autos;
if ( !autos )
return 0LL;
v2 = 0;
v3 = 0;
v4 = 0LL;
do
{
if ( !fnmatch(*(const char **)(v1 + 8), name, 0) )
{
if ( v2 >= v3 )
{
v4 = reallocarray(v4, v3 + 9, 8LL);
if ( !v4 )
panic("out of memory");
v3 += 8;
}
v5 = v2++;
*(_QWORD *)(v4 + 8 * v5) = *(_QWORD *)(v1 + 16);
}
v1 = *(_QWORD *)v1;
}
while ( v1 );
if ( v2 )
*(_QWORD *)(v4 + 8LL * v2) = 0LL;
return v4;
}

original_code:
PF *
find_autoexec(const char *fname)
{
 PF *pfl, *npfl;
 int have, used;
 struct autoexec *ae;
 if (!ready)
  return (((void *)0));
 pfl = ((void *)0);
 have = 0;
 used = 0;
 for((ae) = ((&autos)->slh_first); (ae) != ((void *)0); (ae) = ((ae)->next.sle_next)) {
  if (fnmatch(ae->pattern, fname, 0) == 0) {
   if (used >= have) {
    npfl = reallocarray(pfl, have + 8 + 1,
        sizeof(PF));
    if (npfl == ((void *)0))
     panic("out of memory");
    pfl = npfl;
    have += 8;
   }
   pfl[used++] = ae->fp;
  }
 }
 if (used)
  pfl[used] = ((void *)0);
 return (pfl);
}

canonical_original_code:
int (**find_autoexec(char *fname))(int, int)
{
 int (**pfl)(int, int); int (**npfl)(int, int);
 int have; int used;
 struct autoexec *ae;
 if (!ready)
  return (((void *)0));
 pfl = ((void *)0);
 have = 0;
 used = 0;
 for((ae) = ((&autos)->slh_first); (ae) != ((void *)0); (ae) = ((ae)->next.sle_next)) {
  if (fnmatch(ae->pattern, fname, 0) == 0) {
   if (used >= have) {
    npfl = reallocarray(pfl, have + 8 + 1,
        sizeof(PF));
    if (npfl == ((void *)0))
     panic("out of memory");
    pfl = npfl;
    have += 8;
   }
   pfl[used++] = ae->fp;
  }
 }
 if (used)
  pfl[used] = ((void *)0);
 return (pfl);
}

variable_types:
fname
char *

variable_types:
pfl
int (**)(int, int)

variable_types:
npfl
int (**)(int, int)

variable_types: have int

variable_types: used int

variable_types: struct autoexec { struct { struct autoexec *sle_next; } next; char *pattern; int (*fp)(int, int); } *

return_type: int (**)(int, int)


decompiled_code:
__int64 __fastcall add_autoexec(char *s, __int64 a2)
{
__int64 v2; // rbx
__int64 *v3; // rax
__int64 *v4; // rbp
char *v5; // rax
__int64 v6; // rax

if ( !ready )
{
autos = 0LL;
ready = 1;
}
v2 = name_function(a2);
if ( v2 )
{
v3 = (__int64 *)malloc(0x18uLL);
v4 = v3;
if ( v3 )
{
v3[2] = v2;
v5 = strdup(s);
v4[1] = (__int64)v5;
if ( v5 )
{
v6 = autos;
autos = (__int64)v4;
*v4 = v6;
return 1LL;
}
free(v4);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s, __int64 a2)
{
__int64 v2; // rbx
__int64 *v3; // rax
__int64 *v4; // rbp
char *v5; // rax
__int64 v6; // rax

if ( !ready )
{
autos = 0LL;
ready = 1;
}
v2 = name_function(a2);
if ( v2 )
{
v3 = (__int64 *)malloc(0x18uLL);
v4 = v3;
if ( v3 )
{
v3[2] = v2;
v5 = strdup(s);
v4[1] = (__int64)v5;
if ( v5 )
{
v6 = autos;
autos = (__int64)v4;
*v4 = v6;
return 1LL;
}
free(v4);
}
}
return 0LL;
}

original_code:
int
add_autoexec(const char *pattern, const char *func)
{
 PF fp;
 struct autoexec *ae;
 if (!ready) {
  { ((&autos)->slh_first) = ((void *)0); };
  ready = 1;
 }
 fp = name_function(func);
 if (fp == ((void *)0))
  return (0);
 ae = malloc(sizeof(*ae));
 if (ae == ((void *)0))
  return (0);
 ae->fp = fp;
 ae->pattern = strdup(pattern);
 if (ae->pattern == ((void *)0)) {
  free(ae);
  return (0);
 }
 do { (ae)->next.sle_next = (&autos)->slh_first; (&autos)->slh_first = (ae); } while (0);
 return (1);
}

canonical_original_code:
int add_autoexec(char *pattern, char *func)
{
 int (*fp)(int, int);
 struct autoexec *ae;
 if (!ready) {
  { ((&autos)->slh_first) = ((void *)0); };
  ready = 1;
 }
 fp = name_function(func);
 if (fp == ((void *)0))
  return (0);
 ae = malloc(sizeof(*ae));
 if (ae == ((void *)0))
  return (0);
 ae->fp = fp;
 ae->pattern = strdup(pattern);
 if (ae->pattern == ((void *)0)) {
  free(ae);
  return (0);
 }
 do { (ae)->next.sle_next = (&autos)->slh_first; (&autos)->slh_first = (ae); } while (0);
 return (1);
}

variable_types:
pattern
char *

variable_types:
func
char *

variable_types:
fp
int (*)(int, int)

user_defined_types: struct autoexec { struct { struct autoexec *sle_next; } next; char *pattern; int (*fp)(int, int); }


decompiled_code:
__int64 auto_execute()
{
char *v0; // rax
char *v1; // rbp
_BYTE *v3; // rax
__int64 v4; // [rsp+0h] [rbp-108h] BYREF
char v5[136]; // [rsp+80h] [rbp-88h] BYREF

v0 = (char *)eread("Filename pattern: ", &v4, 128LL, 24LL);
if ( !v0 )
return 2LL;
v1 = v0;
if ( !*v0 )
return 0LL;
v3 = (_BYTE *)eread("Execute: ", v5, 128LL, 25LL);
if ( !v3 )
return 2LL;
if ( !*v3 )
return 0LL;
return add_autoexec(v1, (__int64)v3);
}

canonical_decompiled_code:
__int64 func2()
{
char *v0; // rax
char *v1; // rbp
_BYTE *v3; // rax
__int64 v4; // [rsp+0h] [rbp-108h] BYREF
char v5[136]; // [rsp+80h] [rbp-88h] BYREF

v0 = (char *)eread("Filename pattern: ", &v4, 128LL, 24LL);
if ( !v0 )
return 2LL;
v1 = v0;
if ( !*v0 )
return 0LL;
v3 = (_BYTE *)eread("Execute: ", v5, 128LL, 25LL);
if ( !v3 )
return 2LL;
if ( !*v3 )
return 0LL;
return func1(v1, (__int64)v3);
}

original_code:
int
auto_execute(int f, int n)
{
 char patbuf[128], funcbuf[128], *patp, *funcp;
 int s;
 if ((patp = eread("Filename pattern: ", patbuf, sizeof(patbuf),
     0x0008 | 0x0010)) == ((void *)0))
  return (2);
 else if (patp[0] == '\0')
  return (0);
 if ((funcp = eread("Execute: ", funcbuf, sizeof(funcbuf),
     0x0008 | 0x0010 | 0x0001)) == ((void *)0))
  return (2);
 else if (funcp[0] == '\0')
  return (0);
 if ((s = add_autoexec(patp, funcp)) != 1)
  return (s);
 return (1);
}

canonical_original_code:
int auto_execute(int f, int n)
{
 char patbuf[128]; char funcbuf[128]; char *patp; char *funcp;
 int s;
 if ((patp = eread("Filename pattern: ", patbuf, sizeof(patbuf),
     0x0008 | 0x0010)) == ((void *)0))
  return (2);
 else if (patp[0] == '\0')
  return (0);
 if ((funcp = eread("Execute: ", funcbuf, sizeof(funcbuf),
     0x0008 | 0x0010 | 0x0001)) == ((void *)0))
  return (2);
 else if (funcp[0] == '\0')
  return (0);
 if ((s = add_autoexec(patp, funcp)) != 1)
  return (s);
 return (1);
}

variable_types: f int

variable_types: n int

variable_types:
patbuf
char [128]

variable_types:
funcbuf
char [128]

variable_types:
patp
char *

variable_types:
funcp
char *

variable_types: s int