repo: strongwillow/proxior

decompiled_code:
char *__fastcall find_proxy(char *s2)
{
char *v1; // rbx

v1 = cfg;
while ( strcmp(v1, s2) )
{
v1 = (char *)*((_QWORD *)v1 + 6);
if ( !v1 )
{
if ( strcmp(s2, "direct") )
{
fprintf(stderr, "Cannot find proxy '%s'. Exiting\n", s2);
exit(1);
}
return v1;
}
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func0(char *s2)
{
char *v1; // rbx

v1 = cfg;
while ( strcmp(v1, s2) )
{
v1 = (char *)*((_QWORD *)v1 + 6);
if ( !v1 )
{
if ( strcmp(s2, "direct") )
{
fprintf(stderr, "Cannot find proxy '%s'. Exiting\n", s2);
exit(1);
}
return v1;
}
}
return v1;
}

original_code:
static struct proxy_t *
find_proxy(char *proxy_name) {
  struct proxy_t *node = cfg.proxy_head;
  do {
    if(strcmp(node->name, proxy_name) == 0)
      return node;
    node = node->next;
  } while (node != ((void *)0));
  if (strcmp(proxy_name, "direct") == 0)
    return ((void *)0);
  fprintf(stderr, "Cannot find proxy '%s'. Exiting\n", proxy_name);
  exit(1);
}

canonical_original_code:
static struct proxy_t *find_proxy(char *proxy_name) {
  struct proxy_t *node = cfg.proxy_head;
  do {
    if(strcmp(node->name, proxy_name) == 0)
      return node;
    node = node->next;
  } while (node != ((void *)0));
  if (strcmp(proxy_name, "direct") == 0)
    return ((void *)0);
  fprintf(stderr, "Cannot find proxy '%s'. Exiting\n", proxy_name);
  exit(1);
}

variable_types: struct proxy_t { char name[20]; char host[20]; unsigned short port; enum { PROXY_HTTP=1, PROXY_SOCKS=2 } type; struct proxy_t *next; } *


decompiled_code:
char *__fastcall set_default_proxy(char *a1)
{
char *result; // rax

result = find_proxy(a1);
*(&cfg + 3) = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1)
{
char *result; // rax

result = func0(a1);
*(&cfg + 3) = result;
return result;
}

original_code:
static void
set_default_proxy(char *proxy_name) {
  cfg.default_proxy = find_proxy(proxy_name);
}

return_type: void


decompiled_code:
char *__fastcall set_try_proxy(char *a1)
{
char *result; // rax

result = find_proxy(a1);
*(&cfg + 4) = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *a1)
{
char *result; // rax

result = func0(a1);
*(&cfg + 4) = result;
return result;
}

original_code:
static void
set_try_proxy(char *proxy_name) {
  cfg.try_proxy = find_proxy(proxy_name);
}


decompiled_code:
char *__fastcall add_proxy(char *src, char *s, unsigned __int8 a3)
{
char *v4; // rbx
char *v5; // rax
char *v6; // rax
char *result; // rax

v4 = (char *)malloc(0x38uLL);
strcpy(v4, src);
v5 = strtok(s, ":");
strcpy(v4 + 20, v5);
v6 = strtok(0LL, &byte_7C9);
*((_WORD *)v4 + 20) = atoi(v6);
*((_DWORD *)v4 + 11) = a3;
result = cfg;
*((_QWORD *)v4 + 6) = cfg;
cfg = v4;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(char *src, char *s, unsigned __int8 a3)
{
char *v4; // rbx
char *v5; // rax
char *v6; // rax
char *result; // rax

v4 = (char *)malloc(0x38uLL);
strcpy(v4, src);
v5 = strtok(s, ":");
strcpy(v4 + 20, v5);
v6 = strtok(0LL, &byte_7C9);
*((_WORD *)v4 + 20) = atoi(v6);
*((_DWORD *)v4 + 11) = a3;
result = cfg;
*((_QWORD *)v4 + 6) = cfg;
cfg = v4;
return result;
}

original_code:
static void
add_proxy(char *name, char *ap, unsigned char type)
{
  struct proxy_t *proxy = malloc(sizeof(struct proxy_t));
  strcpy(proxy->name, name);
  strcpy(proxy->host, strtok(ap, ":"));
  proxy->port = atoi(strtok(((void *)0), ""));
  proxy->type = type;
  proxy->next = cfg.proxy_head;
  cfg.proxy_head = proxy;
}

variable_types:
name
char *

variable_types:
ap
char *

variable_types:
type
unsigned char

user_defined_types: struct proxy_t { char name[20]; char host[20]; unsigned short port; enum { PROXY_HTTP=1, PROXY_SOCKS=2 } type; struct proxy_t *next; }


decompiled_code:
__int64 __fastcall set_timeout(const char *a1)
{
__int64 result; // rax

result = atoi(a1);
*(&cfg + 5) = (char *)(int)result;
*(&cfg + 6) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
__int64 result; // rax

result = atoi(a1);
*(&cfg + 5) = (char *)(int)result;
*(&cfg + 6) = 0LL;
return result;
}

original_code:
static void
set_timeout(char *time) {
  cfg.timeout.tv_sec = atoi(time);
  cfg.timeout.tv_usec = 0;
}

variable_types:
time
char *


decompiled_code:
__int64 __fastcall set_listen(char *a1)
{
char *v1; // rax
char *v2; // rax

v1 = strtok(a1, ":");
*(&cfg + 11) = strdup(v1);
v2 = strtok(0LL, &byte_7C9);
return _isoc99_sscanf(v2, "%hd", (unsigned int)((_DWORD)&cfg + 96));
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1)
{
char *v1; // rax
char *v2; // rax

v1 = strtok(a1, ":");
*(&cfg + 11) = strdup(v1);
v2 = strtok(0LL, &byte_7C9);
return _isoc99_sscanf(v2, "%hd", (unsigned int)((_DWORD)&cfg + 96));
}

original_code:
static void
set_listen(char *word) {
  cfg.listen_addr = strdup(strtok(word, ":"));
  sscanf(strtok(((void *)0), ""), "%hd", &cfg.listen_port);
}

variable_types:
word
char *


decompiled_code:
__int64 __fastcall get_rulelist(char *s2)
{
__int64 i; // rbx

for ( i = (__int64)*(&cfg + 1); i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(*(const char **)i, s2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s2)
{
__int64 i; // rbx

for ( i = (__int64)*(&cfg + 1); i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(*(const char **)i, s2) )
break;
}
return i;
}

original_code:
struct rulelist *
get_rulelist(char *listname) {
  struct rulelist *rl = cfg.rulelist_head;
  while (rl != ((void *)0)) {
    if (strcmp(rl->name, listname) == 0)
      return rl;
    else
      rl = rl->next;
  }
  return ((void *)0);
}

canonical_original_code:
struct rulelist *get_rulelist(char *listname) {
  struct rulelist *rl = cfg.rulelist_head;
  while (rl != ((void *)0)) {
    if (strcmp(rl->name, listname) == 0)
      return rl;
    else
      rl = rl->next;
  }
  return ((void *)0);
}

variable_types:
listname
char *

variable_types: struct rulelist { char *name; struct hashmap_s { unsigned int size; int end_iterator; struct hashbucket_s { struct hashentry_s { char *key; char *data; struct hashentry_s *prev; } *head; } *buckets; } *data; struct proxy_t { char name[20]; char host[20]; unsigned short port; enum { PROXY_HTTP=1, PROXY_SOCKS=2 } type; struct proxy_t *next; } *proxy; struct rulelist *next; } *

user_defined_types: struct rulelist { char *name; struct hashmap_s *data; struct proxy_t *proxy; struct rulelist *next; }

user_defined_types: struct hashmap_s { unsigned int size; int end_iterator; struct hashbucket_s *buckets; }

user_defined_types: struct hashbucket_s { struct hashentry_s *head; }


decompiled_code:
__int64 __fastcall add_to_trylist(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rdi

result = get_rulelist("trylist");
v3 = *(_QWORD *)(result + 8);
if ( v3 )
result = hashmap_insert(v3, a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rdi

result = func6("trylist");
v3 = *(_QWORD *)(result + 8);
if ( v3 )
result = hashmap_insert(v3, a1);
return result;
}

original_code:
void
add_to_trylist(char *dom) {
  struct rulelist *rl = get_rulelist("trylist");
  struct hashmap_s *map = rl->data;
  if (map == ((void *)0))
    return;
  hashmap_insert(map, dom);
}

variable_types:
dom
char *

variable_types: struct hashmap_s { unsigned int size; int end_iterator; struct hashbucket_s { struct hashentry_s { char *key; char *data; struct hashentry_s *prev; } *head; } *buckets; } *


decompiled_code:
void __fastcall update_rule(char *s1, __int64 a2)
{
__int64 i; // rbx

for ( i = (__int64)*(&cfg + 1); i; i = *(_QWORD *)(i + 24) )
{
hashmap_remove(*(_QWORD *)(i + 8), a2);
if ( !strcmp(s1, *(const char **)i) )
hashmap_insert(*(_QWORD *)(i + 8), a2);
}
}

canonical_decompiled_code:
void __fastcall func8(char *s1, __int64 a2)
{
__int64 i; // rbx

for ( i = (__int64)*(&cfg + 1); i; i = *(_QWORD *)(i + 24) )
{
hashmap_remove(*(_QWORD *)(i + 8), a2);
if ( !strcmp(s1, *(const char **)i) )
hashmap_insert(*(_QWORD *)(i + 8), a2);
}
}

original_code:
void update_rule(char *list, char *rule)
{
  struct rulelist *it = cfg.rulelist_head;
  while (it != ((void *)0)) {
    hashmap_remove(it->data, rule);
    if (strcmp(list, it->name) == 0)
      hashmap_insert(it->data, rule);
    it = it->next;
  }
}

variable_types:
list
char *

variable_types:
rule
char *

user_defined_types: struct hashentry_s { char *key; char *data; struct hashentry_s *prev; }


decompiled_code:
void __fastcall remove_rule(char *s1, __int64 a2)
{
__int64 i; // rbx

for ( i = (__int64)*(&cfg + 1); i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(s1, *(const char **)i) )
hashmap_remove(*(_QWORD *)(i + 8), a2);
}
}

canonical_decompiled_code:
void __fastcall func9(char *s1, __int64 a2)
{
__int64 i; // rbx

for ( i = (__int64)*(&cfg + 1); i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(s1, *(const char **)i) )
hashmap_remove(*(_QWORD *)(i + 8), a2);
}
}

original_code:
void remove_rule(char *list, char *rule)
{
  struct rulelist *it = cfg.rulelist_head;
  while (it != ((void *)0)) {
    if (strcmp(list, it->name) == 0)
      hashmap_remove(it->data, rule);
    it = it->next;
  }
}


decompiled_code:
char *__fastcall get_file_path(char *src)
{
strcpy(path_0, *(&cfg + 13));
strcat(path_0, src);
return path_0;
}

canonical_decompiled_code:
char *__fastcall func10(char *src)
{
strcpy(path_0, *(&cfg + 13));
strcat(path_0, src);
return path_0;
}

original_code:
char *get_file_path(char *filename)
{
  static char path[64];
  strcpy(path, cfg.path);
  strcat(path, filename);
  return path;
}

variable_types:
filename
char *

variable_types:
path
char [64]

return_type: char *


decompiled_code:
void __fastcall free_parsed_url(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void
free_parsed_url (struct parsed_url *url) {
  if (url == ((void *)0)) return;
  free(url->host);
  free(url);
}

canonical_original_code:
void free_parsed_url(struct parsed_url *url) {
  if (url == ((void *)0)) return;
  free(url->host);
  free(url);
}

variable_types: struct parsed_url { unsigned short port; char *host; } *


decompiled_code:
char *__fastcall get_domain(char *src)
{
char *v1; // rax
char *v2; // rdi
char *v3; // rbx
char *result; // rax
char *v5; // rdi
char i; // al

strcpy(url_0, src);
v1 = strstr(url_0, "//");
v2 = v1 + 2;
if ( !v1 )
v2 = url_0;
v3 = strtok(v2, "/");
result = strrchr(v3, 46);
if ( result )
{
v5 = result - 1;
for ( i = *(result - 1); v3 < v5 && i != 46; i = *v5 )
--v5;
result = strtok(&v5[i == 46], ":");
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
char *v1; // rax
char *v2; // rdi
char *v3; // rbx
char *result; // rax
char *v5; // rdi
char i; // al

strcpy(url_0, src);
v1 = strstr(url_0, "//");
v2 = v1 + 2;
if ( !v1 )
v2 = url_0;
v3 = strtok(v2, "/");
result = strrchr(v3, 46);
if ( result )
{
v5 = result - 1;
for ( i = *(result - 1); v3 < v5 && i != 46; i = *v5 )
--v5;
result = strtok(&v5[i == 46], ":");
}
return result;
}

original_code:
char *get_domain(const char *ori) {
  static char url[3600];
  strcpy(url, ori);
  char *s = strstr(url, "//\0");
  if (s == ((void *)0)) s = url;
  else s += 2;
  s = strtok(s, "/");
  char *s2 = strrchr(s, '.');
  if (s2 == ((void *)0))
    return ((void *)0);
  s2--;
  while (strncmp(s2, ".", 1) && s2 > s) s2--;
  if (*s2 == '.') s2++;
  return strtok(s2, ":");
}

canonical_original_code:
char *get_domain(char *ori) {
  static char url[3600];
  strcpy(url, ori);
  char *s = strstr(url, "//\0");
  if (s == ((void *)0)) s = url;
  else s += 2;
  s = strtok(s, "/");
  char *s2 = strrchr(s, '.');
  if (s2 == ((void *)0))
    return ((void *)0);
  s2--;
  while (strncmp(s2, ".", 1) && s2 > s) s2--;
  if (*s2 == '.') s2++;
  return strtok(s2, ":");
}

variable_types:
ori
char *

variable_types:
url
char [3600]

variable_types:
s
char *


astermatch

decompiled_code:
__int64 __fastcall astermatch(_BYTE *a1, char *a2)
{
char v3; // al
__int64 v4; // rdx
unsigned int v5; // eax

v3 = *a2;
v4 = 0LL;
if ( *a2 )
{
while ( v3 != 42 )
{
v4 = (unsigned __int8)*a1;
if ( (_BYTE)v4 != v3 || !(_BYTE)v4 )
{
LODWORD(v4) = 1;
return (unsigned int)v4;
}
++a2;
++a1;
v3 = *a2;
if ( !*a2 )
{
LODWORD(v4) = *a1 != 0;
return (unsigned int)v4;
}
}
if ( *a1 )
{
while ( 1 )
{
v5 = astermatch(a1, a2 + 1, v4);
v4 = v5;
if ( !v5 )
break;
if ( !*++a1 )
{
LODWORD(v4) = 1;
return (unsigned int)v4;
}
}
}
else
{
LODWORD(v4) = a2[1] != 0;
}
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1, char *a2)
{
char v3; // al
__int64 v4; // rdx
unsigned int v5; // eax

v3 = *a2;
v4 = 0LL;
if ( *a2 )
{
while ( v3 != 42 )
{
v4 = (unsigned __int8)*a1;
if ( (_BYTE)v4 != v3 || !(_BYTE)v4 )
{
LODWORD(v4) = 1;
return (unsigned int)v4;
}
++a2;
++a1;
v3 = *a2;
if ( !*a2 )
{
LODWORD(v4) = *a1 != 0;
return (unsigned int)v4;
}
}
if ( *a1 )
{
while ( 1 )
{
v5 = func3(a1, a2 + 1, v4);
v4 = v5;
if ( !v5 )
break;
if ( !*++a1 )
{
LODWORD(v4) = 1;
return (unsigned int)v4;
}
}
}
else
{
LODWORD(v4) = a2[1] != 0;
}
}
return (unsigned int)v4;
}

original_code:
int astermatch (char *url, char *pattern) {
  char *u = url, *p = pattern;
  if (!*p) return 0;
  while (*p) {
    if (*p == '*') {
      if (!*u && !*(p + 1)) return 0;
      while (*u)
 if (astermatch(u, p + 1))
   u++;
 else return 0;
      return 1;
    }
    else {
      if (*u && *p == *u) {
 p++;
 u++;
      }
      else return 1;
    }
  }
  if (*p == *u) return 0;
  return 1;
}

canonical_original_code:
int astermatch(char *url, char *pattern) {
  char *u = url; char *p = pattern;
  if (!*p) return 0;
  while (*p) {
    if (*p == '*') {
      if (!*u && !*(p + 1)) return 0;
      while (*u)
 if (astermatch(u, p + 1))
   u++;
 else return 0;
      return 1;
    }
    else {
      if (*u && *p == *u) {
 p++;
 u++;
      }
      else return 1;
    }
  }
  if (*p == *u) return 0;
  return 1;
}

variable_types:
url
char *

variable_types:
pattern
char *

variable_types:
u
char *

variable_types:
p
char *

return_type: int


hashfunc

original_code:
static unsigned int hashfunc(const char *str, size_t size)
{
  unsigned int hash = 0;
  unsigned int x = 0;
  while (*str) {
      hash = (hash << 4) + (*str++);
      if ((x = hash & 0xF0000000L) != 0) {
   hash ^= (x >> 24);
   hash &= ~x;
 }
    }
  return (hash & 0x7FFFFFFF) % size;
}

canonical_original_code:
static unsigned int hashfunc(char *str, unsigned long size)
{
  unsigned int hash = 0;
  unsigned int x = 0;
  while (*str) {
      hash = (hash << 4) + (*str++);
      if ((x = hash & 0xF0000000L) != 0) {
   hash ^= (x >> 24);
   hash &= ~x;
 }
    }
  return (hash & 0x7FFFFFFF) % size;
}

variable_types:
str
char *

variable_types:
size
unsigned long

variable_types:
hash
unsigned int

variable_types:
x
unsigned int

return_type: unsigned int


decompiled_code:
int __fastcall hashmap_insert(unsigned int *a1, const char *a2)
{
char *v2; // rax
const char *v3; // r14
__int64 v4; // r12
__int64 *v5; // r15
__int64 v6; // rbx
int result; // eax
char *v8; // rbx
char *v9; // rbp
_QWORD *v10; // rax
__int64 v11; // rdx
_QWORD *v12; // r12

v2 = (char *)get_domain(a2);
if ( !v2 )
return -1;
v3 = v2;
v4 = 16LL * (unsigned int)hashfunc(v2, *a1);
v5 = (__int64 *)(*((_QWORD *)a1 + 1) + v4);
v6 = *v5;
if ( *v5 )
{
while ( 1 )
{
result = strcmp(a2, *(const char **)(v6 + 8));
if ( !result )
break;
v6 = *(_QWORD *)(v6 + 24);
if ( !v6 )
goto LABEL_5;
}
}
else
{
LABEL_5:
v8 = strdup(v3);
v9 = strdup(a2);
v10 = malloc(0x20uLL);
if ( v10 )
{
*v10 = v8;
v10[1] = v9;
v10[3] = 0LL;
v11 = v5[1];
v10[2] = v11;
if ( v11 )
*(_QWORD *)(v11 + 24) = v10;
*(_QWORD *)(*((_QWORD *)a1 + 1) + v4 + 8) = v10;
v12 = (_QWORD *)(*((_QWORD *)a1 + 1) + v4);
if ( !*v12 )
*v12 = v10;
++a1[1];
result = 0;
}
else
{
free(v8);
free(v9);
result = -1;
}
}
return result;
}

original_code:
int
hashmap_insert (hashmap_t map, char *rule)
{
        struct hashentry_s *ptr;
        unsigned int hash;
        char *key_copy;
        char *data_copy;
 char *key = get_domain(rule);
 if (key == ((void *)0)) return -1;
        hash = hashfunc (key, map->size);
 struct hashentry_s *it = map->buckets[hash].head;
 while (it) {
   if (strcmp(rule, it->data) == 0)
     return 0;
   it = it->next;
 }
        key_copy = strdup (key);
        data_copy = strdup(rule);
        ptr = (struct hashentry_s *) malloc (sizeof (struct hashentry_s));
        if (!ptr) {
                free (key_copy);
                free (data_copy);
                return -1;
        }
        ptr->key = key_copy;
        ptr->data = data_copy;
        ptr->next = ((void *)0);
        ptr->prev = map->buckets[hash].tail;
        if (map->buckets[hash].tail)
                map->buckets[hash].tail->next = ptr;
        map->buckets[hash].tail = ptr;
        if (!map->buckets[hash].head)
                map->buckets[hash].head = ptr;
        map->end_iterator++;
        return 0;
}

canonical_original_code:
int hashmap_insert(struct hashmap_s *map, char *rule)
{
        struct hashentry_s *ptr;
        unsigned int hash;
        char *key_copy;
        char *data_copy;
 char *key = get_domain(rule);
 if (key == ((void *)0)) return -1;
        hash = hashfunc (key, map->size);
 struct hashentry_s *it = map->buckets[hash].head;
 while (it) {
   if (strcmp(rule, it->data) == 0)
     return 0;
   it = it->next;
 }
        key_copy = strdup (key);
        data_copy = strdup(rule);
        ptr = (struct hashentry_s *) malloc (sizeof (struct hashentry_s));
        if (!ptr) {
                free (key_copy);
                free (data_copy);
                return -1;
        }
        ptr->key = key_copy;
        ptr->data = data_copy;
        ptr->next = ((void *)0);
        ptr->prev = map->buckets[hash].tail;
        if (map->buckets[hash].tail)
                map->buckets[hash].tail->next = ptr;
        map->buckets[hash].tail = ptr;
        if (!map->buckets[hash].head)
                map->buckets[hash].head = ptr;
        map->end_iterator++;
        return 0;
}

variable_types: struct hashmap_s { unsigned int size; int end_iterator; struct hashbucket_s { struct hashentry_s { char *key; char *data; struct hashentry_s *prev; } *head; } *buckets; } *

variable_types:
key
char *


original_code:
int
hashmap_insert_ip (hashmap_t map, char *key, void *ip)
{
        struct hashentry_s *ptr;
        unsigned int hash;
        char *key_copy;
        char *data_copy = malloc(4);
        hash = hashfunc (key, map->size);
 struct hashentry_s *it = map->buckets[hash].head;
 while (it) {
   if (strcmp(key, it->data) == 0)
     return 0;
   it = it->next;
 }
        key_copy = strdup (key);
        data_copy = memcpy(data_copy, ip, 4);
        ptr = (struct hashentry_s *) malloc (sizeof (struct hashentry_s));
        if (!ptr) {
                free (key_copy);
                free (data_copy);
                return -1;
        }
        ptr->key = key_copy;
        ptr->data = data_copy;
        ptr->next = ((void *)0);
        ptr->prev = map->buckets[hash].tail;
        if (map->buckets[hash].tail)
                map->buckets[hash].tail->next = ptr;
        map->buckets[hash].tail = ptr;
        if (!map->buckets[hash].head)
                map->buckets[hash].head = ptr;
        map->end_iterator++;
        return 0;
}

canonical_original_code:
int hashmap_insert_ip(struct hashmap_s *map, char *key, void *ip)
{
        struct hashentry_s *ptr;
        unsigned int hash;
        char *key_copy;
        char *data_copy = malloc(4);
        hash = hashfunc (key, map->size);
 struct hashentry_s *it = map->buckets[hash].head;
 while (it) {
   if (strcmp(key, it->data) == 0)
     return 0;
   it = it->next;
 }
        key_copy = strdup (key);
        data_copy = memcpy(data_copy, ip, 4);
        ptr = (struct hashentry_s *) malloc (sizeof (struct hashentry_s));
        if (!ptr) {
                free (key_copy);
                free (data_copy);
                return -1;
        }
        ptr->key = key_copy;
        ptr->data = data_copy;
        ptr->next = ((void *)0);
        ptr->prev = map->buckets[hash].tail;
        if (map->buckets[hash].tail)
                map->buckets[hash].tail->next = ptr;
        map->buckets[hash].tail = ptr;
        if (!map->buckets[hash].head)
                map->buckets[hash].head = ptr;
        map->end_iterator++;
        return 0;
}

variable_types:
ip
void *

variable_types: struct hashentry_s { char *key; char *data; struct hashentry_s *prev; } *


decompiled_code:
__int64 __fastcall hashmap_find_head(unsigned int *a1, char *a2)
{
__int64 i; // rbx

i = 0LL;
if ( *a1 )
{
for ( i = *(_QWORD *)(*((_QWORD *)a1 + 1) + 16LL * (unsigned int)hashfunc(a2, *a1)); i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(*(const char **)i, a2) )
break;
}
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, char *a2)
{
__int64 i; // rbx

i = 0LL;
if ( *a1 )
{
for ( i = *(_QWORD *)(*((_QWORD *)a1 + 1) + 16LL * (unsigned int)func0(a2, *a1)); i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(*(const char **)i, a2) )
break;
}
}
return i;
}

original_code:
struct hashentry_s *
hashmap_find_head(hashmap_t map, const char *key) {
  if (map->size == 0) return ((void *)0);
  unsigned int hash = hashfunc (key, map->size);
  struct hashentry_s *it = map->buckets[hash].head;
  while (it && strcmp(it->key, key)) {
    it = it->next;
  }
  return it;
}

canonical_original_code:
struct hashentry_s *hashmap_find_head(struct hashmap_s *map, char *key) {
  if (map->size == 0) return ((void *)0);
  unsigned int hash = hashfunc (key, map->size);
  struct hashentry_s *it = map->buckets[hash].head;
  while (it && strcmp(it->key, key)) {
    it = it->next;
  }
  return it;
}

variable_types: struct hashmap_s { unsigned int size; int end_iterator; struct hashbucket_s { struct hashentry_s *head; } *buckets; } *

return_type: struct hashentry_s { char *key; char *data; struct hashentry_s *prev; } *


decompiled_code:
__int64 __fastcall hashmap_find_next(__int64 a1, const char *a2)
{
do
{
if ( !a1 )
break;
a1 = *(_QWORD *)(a1 + 24);
if ( !a1 )
break;
}
while ( strcasecmp(*(const char **)a1, a2) );
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
do
{
if ( !a1 )
break;
a1 = *(_QWORD *)(a1 + 24);
if ( !a1 )
break;
}
while ( strcasecmp(*(const char **)a1, a2) );
return a1;
}

original_code:
struct hashentry_s *
hashmap_find_next(struct hashentry_s *it, const char *key) {
  struct hashentry_s *ent = it;
  while (ent) {
    if (ent->next == ((void *)0)) return ((void *)0);
    ent = ent->next;
    if (strcasecmp(ent->key, key) == 0)
      return ent;
  }
  return ent;
}

canonical_original_code:
struct hashentry_s *hashmap_find_next(struct hashentry_s *it, char *key) {
  struct hashentry_s *ent = it;
  while (ent) {
    if (ent->next == ((void *)0)) return ((void *)0);
    ent = ent->next;
    if (strcasecmp(ent->key, key) == 0)
      return ent;
  }
  return ent;
}

variable_types:
it
struct hashentry_s *


original_code:
void
hashmap_remove (hashmap_t map, const char *rule)
{
  struct hashentry_s *it, *next;
  char *domain = get_domain(rule);
  if (map->size == 0 || domain == ((void *)0)) return;
  unsigned int hash = hashfunc (domain, map->size);
  it = map->buckets[hash].head;
  while (it) {
    if (strcasecmp(it->key, domain) ||
 strcasecmp(it->data, rule)) {
      it = it->next;
      continue;
    }
    next = it->next;
    if (it->prev)
      it->prev->next = it->next;
    if (it->next)
      it->next->prev = it->prev;
    if (map->buckets[hash].head == it)
      map->buckets[hash].head = it->next;
    if (map->buckets[hash].tail == it)
      map->buckets[hash].tail = it->prev;
    free(it->key);
    free(it->data);
    free(it);
    it = next;
  }
}

canonical_original_code:
void hashmap_remove(struct hashmap_s *map, char *rule)
{
  struct hashentry_s *it; struct hashentry_s *next;
  char *domain = get_domain(rule);
  if (map->size == 0 || domain == ((void *)0)) return;
  unsigned int hash = hashfunc (domain, map->size);
  it = map->buckets[hash].head;
  while (it) {
    if (strcasecmp(it->key, domain) ||
 strcasecmp(it->data, rule)) {
      it = it->next;
      continue;
    }
    next = it->next;
    if (it->prev)
      it->prev->next = it->next;
    if (it->next)
      it->next->prev = it->prev;
    if (map->buckets[hash].head == it)
      map->buckets[hash].head = it->next;
    if (map->buckets[hash].tail == it)
      map->buckets[hash].tail = it->prev;
    free(it->key);
    free(it->data);
    free(it);
    it = next;
  }
}

variable_types:
rule
char *

variable_types:
domain
char *


decompiled_code:
FILE *open_log()
{
const char *v0; // rax
FILE *result; // rax

v0 = (const char *)get_file_path(&unk_198);
result = fopen(v0, "a");
*((_QWORD *)&cfg + 14) = result;
return result;
}

canonical_decompiled_code:
FILE *func0()
{
const char *v0; // rax
FILE *result; // rax

v0 = (const char *)get_file_path(&unk_198);
result = fopen(v0, "a");
*((_QWORD *)&cfg + 14) = result;
return result;
}

original_code:
void open_log() {
  char *log = get_file_path("log");
  cfg.logfd = fopen (log, "a");
}

variable_types:
log
char *


decompiled_code:
int close_log()
{
return fclose(*((FILE **)&cfg + 14));
}

canonical_decompiled_code:
int func1()
{
return fclose(*((FILE **)&cfg + 14));
}

original_code:
void close_log() {
  fclose(cfg.logfd);
}

canonical_original_code:
void close_log() {
  fclose(cfg.logfd);
}


decompiled_code:
int __fastcall log_error(unsigned int a1, const char *a2, const char *a3, __int64 a4)
{
char *v6; // rbp
time_t timer; // [rsp+8h] [rbp-30h] BYREF

time(&timer);
v6 = ctime(&timer);
v6[24] = 0;
open_log();
if ( a4 )
fprintf(
*((FILE **)&cfg + 14),
"%s [%d %s] via %s(%s:%d)\n%s\n",
v6,
a1,
a2,
(const char *)a4,
(const char *)(a4 + 20),
*(unsigned __int16 *)(a4 + 40),
a3);
else
fprintf(*((FILE **)&cfg + 14), "%s [%d %s] via DIRECT CONNECTION\n%s\n", v6, a1, a2, a3);
return close_log();
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, const char *a2, const char *a3, __int64 a4)
{
char *v6; // rbp
time_t timer; // [rsp+8h] [rbp-30h] BYREF

time(&timer);
v6 = ctime(&timer);
v6[24] = 0;
func0();
if ( a4 )
fprintf(
*((FILE **)&cfg + 14),
"%s [%d %s] via %s(%s:%d)\n%s\n",
v6,
a1,
a2,
(const char *)a4,
(const char *)(a4 + 20),
*(unsigned __int16 *)(a4 + 40),
a3);
else
fprintf(*((FILE **)&cfg + 14), "%s [%d %s] via DIRECT CONNECTION\n%s\n", v6, a1, a2, a3);
return func1();
}

original_code:
void log_error(int code, char *string, char *url, struct proxy_t *proxy) {
  time_t rawtime;
  time ( &rawtime );
  char *timestr = ctime (&rawtime);
  timestr[24] = 0;
  open_log();
  if (proxy == ((void *)0))
    fprintf(cfg.logfd, "%s [%d %s] via DIRECT CONNECTION\n%s\n", timestr, code, string, url);
  else
    fprintf(cfg.logfd, "%s [%d %s] via %s(%s:%d)\n%s\n", timestr, code, string, proxy->name, proxy->host, proxy->port, url);
  close_log();
}

canonical_original_code:
void log_error(int code, char *string, char *url, struct proxy_t *proxy) {
  long rawtime;
  time ( &rawtime );
  char *timestr = ctime (&rawtime);
  timestr[24] = 0;
  open_log();
  if (proxy == ((void *)0))
    fprintf(cfg.logfd, "%s [%d %s] via DIRECT CONNECTION\n%s\n", timestr, code, string, url);
  else
    fprintf(cfg.logfd, "%s [%d %s] via %s(%s:%d)\n%s\n", timestr, code, string, proxy->name, proxy->host, proxy->port, url);
  close_log();
}

variable_types: code int

variable_types:
string
char *

variable_types:
url
char *

variable_types: struct proxy_t { char name[20]; char host[20]; unsigned short port; enum { PROXY_HTTP=1, PROXY_SOCKS=2 } type; struct proxy_t *next; } *

variable_types: rawtime long

variable_types:
timestr
char *


decompiled_code:
__int64 __fastcall match_list(char *haystack)
{
_QWORD *v2; // r13
__int64 v3; // rax
__int64 v4; // r14
__int64 v6; // rbx
const char *v7; // rbp
_DWORD *v8; // rdi

v2 = (_QWORD *)cfg[1];
v3 = get_domain();
if ( !v3 )
return cfg[3];
v4 = v3;
if ( !v2 )
return cfg[3];
while ( 1 )
{
v8 = (_DWORD *)v2[1];
if ( !*v8 )
{
v2 = (_QWORD *)v2[3];
goto LABEL_9;
}
v6 = hashmap_find_head(v8, v4);
if ( v6 )
break;
LABEL_8:
v2 = (_QWORD *)v2[3];
LABEL_9:
if ( !v2 )
return cfg[3];
}
while ( 1 )
{
printf("matching: %s\n", *(const char **)(v6 + 8));
v7 = *(const char **)(v6 + 8);
if ( strstr(haystack, v7) || !(unsigned int)astermatch(haystack, v7) )
return v2[2];
v6 = hashmap_find_next(v6, v4);
if ( !v6 )
goto LABEL_8;
}
}

canonical_decompiled_code:
__int64 __fastcall func0(char *haystack)
{
_QWORD *v2; // r13
__int64 v3; // rax
__int64 v4; // r14
__int64 v6; // rbx
const char *v7; // rbp
_DWORD *v8; // rdi

v2 = (_QWORD *)cfg[1];
v3 = get_domain();
if ( !v3 )
return cfg[3];
v4 = v3;
if ( !v2 )
return cfg[3];
while ( 1 )
{
v8 = (_DWORD *)v2[1];
if ( !*v8 )
{
v2 = (_QWORD *)v2[3];
goto LABEL_9;
}
v6 = hashmap_find_head(v8, v4);
if ( v6 )
break;
LABEL_8:
v2 = (_QWORD *)v2[3];
LABEL_9:
if ( !v2 )
return cfg[3];
}
while ( 1 )
{
printf("matching: %s\n", *(const char **)(v6 + 8));
v7 = *(const char **)(v6 + 8);
if ( strstr(haystack, v7) || !(unsigned int)astermatch(haystack, v7) )
return v2[2];
v6 = hashmap_find_next(v6, v4);
if ( !v6 )
goto LABEL_8;
}
}

original_code:
struct proxy_t *
match_list(char *url) {
  struct rulelist *node = cfg.rulelist_head;
  char *domain = get_domain(url);
  if (domain == ((void *)0)) goto def;
  while (node != ((void *)0)) {
    struct hashmap_s *map = node->data;
    if (map->size == 0) {
      node = node->next;
      continue;
    }
    struct hashentry_s *it = hashmap_find_head(map, domain);
    while (it != ((void *)0)) {
      printf("matching: %s\n", it->data);
      if (strstr(url, it->data) != ((void *)0)
   || astermatch(url, it->data) == 0)
 return node->proxy;
      it = hashmap_find_next(it, domain);
    }
    node = node->next;
  }
 def:
  return cfg.default_proxy;
}

canonical_original_code:
struct proxy_t *match_list(char *url) {
  struct rulelist *node = cfg.rulelist_head;
  char *domain = get_domain(url);
  if (domain == ((void *)0)) goto def;
  while (node != ((void *)0)) {
    struct hashmap_s *map = node->data;
    if (map->size == 0) {
      node = node->next;
      continue;
    }
    struct hashentry_s *it = hashmap_find_head(map, domain);
    while (it != ((void *)0)) {
      printf("matching: %s\n", it->data);
      if (strstr(url, it->data) != ((void *)0)
   || astermatch(url, it->data) == 0)
 return node->proxy;
      it = hashmap_find_next(it, domain);
    }
    node = node->next;
  }
 def:
  return cfg.default_proxy;
}

variable_types: struct rulelist { char *name; struct hashmap_s { unsigned int size; int end_iterator; struct hashbucket_s { struct hashentry_s { char *key; char *data; struct hashentry_s *prev; } *head; } *buckets; } *data; struct proxy_t { char name[20]; char host[20]; unsigned short port; enum { PROXY_HTTP=1, PROXY_SOCKS=2 } type; struct proxy_t *next; } *proxy; struct rulelist *next; } *


readJobs

repo: swehner/bsperf

decompiled_code:
void *__fastcall readJobs(void *a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
int i; // er12
__int64 v4; // rbx
__int64 j; // rbx
unsigned int v7; // ebp
_QWORD *v8; // [rsp+8h] [rbp-10C0h] BYREF
char s[4280]; // [rsp+10h] [rbp-10B8h] BYREF

if ( socksperthread > 0 )
{
v1 = 0LL;
do
{
v2 = bs_connect("127.0.0.1", (unsigned int)port);
*(_DWORD *)&s[4 * v1 + 256] = v2;
sprintf(s, "tube_%ld_%d", a1, (unsigned int)v1);
bs_watch(v2, s);
++v1;
}
while ( socksperthread > (int)v1 );
}
for ( i = 0; count > i; ++i )
{
for ( j = 0LL; socksperthread > (int)j; ++j )
{
v7 = *(_DWORD *)&s[4 * j + 256];
if ( !(unsigned int)bs_reserve(v7, &v8) )
{
bs_delete(v7, *v8);
bs_free_job(v8);
}
}
}
if ( socksperthread > 0 )
{
v4 = 0LL;
do
bs_disconnect(*(unsigned int *)&s[4 * v4++ + 256]);
while ( socksperthread > (int)v4 );
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
int i; // er12
__int64 v4; // rbx
__int64 j; // rbx
unsigned int v7; // ebp
_QWORD *v8; // [rsp+8h] [rbp-10C0h] BYREF
char s[4280]; // [rsp+10h] [rbp-10B8h] BYREF

if ( socksperthread > 0 )
{
v1 = 0LL;
do
{
v2 = bs_connect("127.0.0.1", (unsigned int)port);
*(_DWORD *)&s[4 * v1 + 256] = v2;
sprintf(s, "tube_%ld_%d", a1, (unsigned int)v1);
bs_watch(v2, s);
++v1;
}
while ( socksperthread > (int)v1 );
}
for ( i = 0; count > i; ++i )
{
for ( j = 0LL; socksperthread > (int)j; ++j )
{
v7 = *(_DWORD *)&s[4 * j + 256];
if ( !(unsigned int)bs_reserve(v7, &v8) )
{
bs_delete(v7, *v8);
bs_free_job(v8);
}
}
}
if ( socksperthread > 0 )
{
v4 = 0LL;
do
bs_disconnect(*(unsigned int *)&s[4 * v4++ + 256]);
while ( socksperthread > (int)v4 );
}
return 0LL;
}

original_code:
void* readJobs(void *arg) {
  int64_t t = (int64_t)arg;
  int sockets[1000];
  int is;
  char name[256];
  for (is=0; is<socksperthread; is++) {
    sockets[is] = bs_connect("127.0.0.1", port);
    sprintf(name, "tube_%""l" "d""_%d", t, is);
    bs_watch(sockets[is], name);
  }
  BSJ *job;
  int i;
  for (i=0; i < count; i++) {
    for (is=0; is<socksperthread; is++) {
      int res = bs_reserve(sockets[is], &job);
      if (res == 0){
        bs_delete(sockets[is], job->id);
        bs_free_job(job);
      }
    }
  }
  for (is=0; is<socksperthread; is++) {
    bs_disconnect(sockets[is]);
  }
  return ((void *)0);
}

canonical_original_code:
void *readJobs(void *arg) {
  long t = (int64_t)arg;
  int sockets[1000];
  int is;
  char name[256];
  for (is=0; is<socksperthread; is++) {
    sockets[is] = bs_connect("127.0.0.1", port);
    sprintf(name, "tube_%""l" "d""_%d", t, is);
    bs_watch(sockets[is], name);
  }
  struct bs_job *job;
  int i;
  for (i=0; i < count; i++) {
    for (is=0; is<socksperthread; is++) {
      int res = bs_reserve(sockets[is], &job);
      if (res == 0){
        bs_delete(sockets[is], job->id);
        bs_free_job(job);
      }
    }
  }
  for (is=0; is<socksperthread; is++) {
    bs_disconnect(sockets[is]);
  }
  return ((void *)0);
}

variable_types:
arg
void *

variable_types: t long

variable_types:
sockets
int [1000]

variable_types: is int

variable_types:
name
char [256]

variable_types: struct bs_job { long id; char *data; unsigned long size; } *

variable_types: i int

variable_types: res int

return_type: void *


enqueue

decompiled_code:
void __fastcall enqueue(void *a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
int i; // ebp
__int64 v4; // rbx
__int64 j; // rbx
int v6[1000]; // [rsp+0h] [rbp-10B8h]
char s[280]; // [rsp+FA0h] [rbp-118h] BYREF

if ( socksperthread > 0 )
{
v1 = 0LL;
do
{
v2 = bs_connect("127.0.0.1", (unsigned int)port);
v6[v1] = v2;
sprintf(s, "tube_%ld_%d", a1, (unsigned int)v1);
bs_use(v2, s);
++v1;
}
while ( socksperthread > (int)v1 );
}
for ( i = 0; count > i; ++i )
{
for ( j = 0LL; socksperthread > (int)j; ++j )
bs_put((unsigned int)v6[j], 1000LL, 0LL, 100LL, "hola", 4LL);
}
if ( socksperthread > 0 )
{
v4 = 0LL;
do
bs_disconnect((unsigned int)v6[v4++]);
while ( socksperthread > (int)v4 );
}
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
int i; // ebp
__int64 v4; // rbx
__int64 j; // rbx
int v6[1000]; // [rsp+0h] [rbp-10B8h]
char s[280]; // [rsp+FA0h] [rbp-118h] BYREF

if ( socksperthread > 0 )
{
v1 = 0LL;
do
{
v2 = bs_connect("127.0.0.1", (unsigned int)port);
v6[v1] = v2;
sprintf(s, "tube_%ld_%d", a1, (unsigned int)v1);
bs_use(v2, s);
++v1;
}
while ( socksperthread > (int)v1 );
}
for ( i = 0; count > i; ++i )
{
for ( j = 0LL; socksperthread > (int)j; ++j )
bs_put((unsigned int)v6[j], 1000LL, 0LL, 100LL, "hola", 4LL);
}
if ( socksperthread > 0 )
{
v4 = 0LL;
do
bs_disconnect((unsigned int)v6[v4++]);
while ( socksperthread > (int)v4 );
}
}

original_code:
void *enqueue(void *arg) {
  int64_t t = (int64_t)arg;
  int i;
  char name[256];
  int sockets[1000];
  int is;
  for (is=0; is<socksperthread; is++) {
    sockets[is] = bs_connect("127.0.0.1", port);
    sprintf(name, "tube_%""l" "d""_%d", t, is);
    bs_use(sockets[is], name);
  }
  for (i=0; i < count; i++) {
    for (is=0; is<socksperthread; is++) {
      bs_put(sockets[is], 1000, 0, 100, "hola", 4);
    }
  }
  for (is=0; is<socksperthread; is++) {
    bs_disconnect(sockets[is]);
  }
}

canonical_original_code:
void *enqueue(void *arg) {
  long t = (int64_t)arg;
  int i;
  char name[256];
  int sockets[1000];
  int is;
  for (is=0; is<socksperthread; is++) {
    sockets[is] = bs_connect("127.0.0.1", port);
    sprintf(name, "tube_%""l" "d""_%d", t, is);
    bs_use(sockets[is], name);
  }
  for (i=0; i < count; i++) {
    for (is=0; is<socksperthread; is++) {
      bs_put(sockets[is], 1000, 0, 100, "hola", 4);
    }
  }
  for (is=0; is<socksperthread; is++) {
    bs_disconnect(sockets[is]);
  }
}


GetMicroSeconds

decompiled_code:
__suseconds_t GetMicroSeconds()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func2()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
int64_t GetMicroSeconds() {
  struct timeval tim;
  gettimeofday(&tim, 0);
  return tim.tv_usec + (tim.tv_sec * 1000000);
}

canonical_original_code:
long GetMicroSeconds() {
  struct timeval tim;
  gettimeofday(&tim, 0);
  return tim.tv_usec + (tim.tv_sec * 1000000);
}

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

return_type: long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
int v4; // ebx
int v5; // er12
int v6; // er15
__int64 v7; // r8
void *v8; // rsp
void *v9; // rsp
pthread_t *v10; // r12
__int64 v11; // rbx
__int64 v12; // rbx
pthread_t *v13; // r12
__int64 v14; // rbx
__int64 v15; // rbx
int v16; // eax
__int64 v18; // [rsp+0h] [rbp-40h] BYREF
__suseconds_t v19; // [rsp+8h] [rbp-38h]

v3 = atoi(argv[1]);
port = v3;
v4 = atoi(argv[2]);
threads = v4;
v5 = atoi(argv[3]);
nqueues = v5;
v6 = atoi(argv[4]);
v7 = (unsigned int)(v5 / v4);
socksperthread = v7;
count = v6 / v4 / (int)v7;
printf(
"Using port %d, threads %d, queues %d, socksperthread %d each using %d jobs\n",
v3,
(unsigned int)v4,
(unsigned int)v5,
v7,
(unsigned int)(v6 / v4 / (int)v7));
v19 = GetMicroSeconds();
v8 = alloca(8LL * threads);
v9 = alloca(8LL * threads);
if ( threads > 0 )
{
v10 = (pthread_t *)&v18;
v11 = 0LL;
do
{
pthread_create(v10, 0LL, (void *(*)(void *))enqueue, (void *)(v11 % nqueues));
++v11;
++v10;
}
while ( threads > v11 );
if ( threads > 0 )
{
v12 = 0LL;
do
pthread_join(*(&v18 + v12++), 0LL);
while ( threads > v12 );
}
}
puts("Spawning readers");
if ( threads > 0 )
{
v13 = (pthread_t *)&v18;
v14 = 0LL;
do
{
pthread_create(v13, 0LL, readJobs, (void *)(v14 % nqueues));
++v14;
++v13;
}
while ( threads > v14 );
if ( threads > 0 )
{
v15 = 0LL;
do
pthread_join(*(&v18 + v15++), 0LL);
while ( threads > v15 );
}
}
v16 = GetMicroSeconds();
printf(
"Total time: %f s %f/s\n",
(double)(v16 - (int)v19) / 1000000.0,
(double)v6 / (double)(v16 - (int)v19) * 1000000.0);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
int v4; // ebx
int v5; // er12
int v6; // er15
__int64 v7; // r8
void *v8; // rsp
void *v9; // rsp
pthread_t *v10; // r12
__int64 v11; // rbx
__int64 v12; // rbx
pthread_t *v13; // r12
__int64 v14; // rbx
__int64 v15; // rbx
int v16; // eax
__int64 v18; // [rsp+0h] [rbp-40h] BYREF
__suseconds_t v19; // [rsp+8h] [rbp-38h]

v3 = atoi(argv[1]);
port = v3;
v4 = atoi(argv[2]);
threads = v4;
v5 = atoi(argv[3]);
nqueues = v5;
v6 = atoi(argv[4]);
v7 = (unsigned int)(v5 / v4);
socksperthread = v7;
count = v6 / v4 / (int)v7;
printf(
"Using port %d, threads %d, queues %d, socksperthread %d each using %d jobs\n",
v3,
(unsigned int)v4,
(unsigned int)v5,
v7,
(unsigned int)(v6 / v4 / (int)v7));
v19 = func2();
v8 = alloca(8LL * threads);
v9 = alloca(8LL * threads);
if ( threads > 0 )
{
v10 = (pthread_t *)&v18;
v11 = 0LL;
do
{
pthread_create(v10, 0LL, (void *(*)(void *))enqueue, (void *)(v11 % nqueues));
++v11;
++v10;
}
while ( threads > v11 );
if ( threads > 0 )
{
v12 = 0LL;
do
pthread_join(*(&v18 + v12++), 0LL);
while ( threads > v12 );
}
}
puts("Spawning readers");
if ( threads > 0 )
{
v13 = (pthread_t *)&v18;
v14 = 0LL;
do
{
pthread_create(v13, 0LL, readJobs, (void *)(v14 % nqueues));
++v14;
++v13;
}
while ( threads > v14 );
if ( threads > 0 )
{
v15 = 0LL;
do
pthread_join(*(&v18 + v15++), 0LL);
while ( threads > v15 );
}
}
v16 = func2();
printf(
"Total time: %f s %f/s\n",
(double)(v16 - (int)v19) / 1000000.0,
(double)v6 / (double)(v16 - (int)v19) * 1000000.0);
return 0;
}

original_code:
int main(int argc, char**argv){
  port = atoi(argv[1]);
  threads = atoi(argv[2]);
  nqueues = atoi(argv[3]);
  int total = atoi(argv[4]);
  socksperthread = nqueues/threads;
  count = total/threads/socksperthread;
  printf("Using port %d, threads %d, queues %d, socksperthread %d each using %d jobs\n", port, threads, nqueues, socksperthread, count);
  int64_t start = GetMicroSeconds();
  pthread_t threade[threads];
  pthread_t threadr[threads];
  int64_t i=0;
  for (i=0; i<threads; i++){
    pthread_create(&threade[i], ((void *)0), enqueue, (void*)(i%nqueues));
  }
  for (i=0; i<threads; i++){
    pthread_join(threade[i], ((void *)0));
  }
  printf("Spawning readers\n");
  for (i=0; i<threads; i++){
    pthread_create(&threadr[i], ((void *)0), readJobs, (void*)(i%nqueues));
  }
  for (i=0; i<threads; i++){
    pthread_join(threadr[i], ((void *)0));
  }
  int64_t tt = GetMicroSeconds() - start;
  double rate = ((double)total)/tt*1000000;
  printf("Total time: %f s %f/s\n", tt/1000000.0, rate);
}

canonical_original_code:
int main(int argc, char **argv){
  port = atoi(argv[1]);
  threads = atoi(argv[2]);
  nqueues = atoi(argv[3]);
  int total = atoi(argv[4]);
  socksperthread = nqueues/threads;
  count = total/threads/socksperthread;
  printf("Using port %d, threads %d, queues %d, socksperthread %d each using %d jobs\n", port, threads, nqueues, socksperthread, count);
  long start = GetMicroSeconds();
  unsigned long threade[-1];
  unsigned long threadr[-1];
  long i = 0;
  for (i=0; i<threads; i++){
    pthread_create(&threade[i], ((void *)0), enqueue, (void *)(i%nqueues));
  }
  for (i=0; i<threads; i++){
    pthread_join(threade[i], ((void *)0));
  }
  printf("Spawning readers\n");
  for (i=0; i<threads; i++){
    pthread_create(&threadr[i], ((void *)0), readJobs, (void *)(i%nqueues));
  }
  for (i=0; i<threads; i++){
    pthread_join(threadr[i], ((void *)0));
  }
  long tt = GetMicroSeconds() - start;
  double rate = ((double)total)/tt*1000000;
  printf("Total time: %f s %f/s\n", tt/1000000.0, rate);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: total int

variable_types: start long

variable_types:
threade
unsigned long [-1]

variable_types:
threadr
unsigned long [-1]

variable_types: i long

variable_types: tt long

variable_types: rate double


stringAlloc

repo: thomseddon/calc

decompiled_code:
void *__fastcall stringAlloc(__int64 a1, int a2)
{
void *result; // rax
int v3; // esi

result = (void *)*(unsigned int *)(a1 + 8);
if ( *(_DWORD *)(a1 + 12) + a2 >= (int)result )
{
if ( *(_DWORD *)(a1 + 16) >= a2 )
a2 = *(_DWORD *)(a1 + 16);
v3 = (_DWORD)result + a2;
*(_DWORD *)(a1 + 8) = v3;
result = realloc(*(void **)a1, v3);
*(_QWORD *)a1 = result;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, int a2)
{
void *result; // rax
int v3; // esi

result = (void *)*(unsigned int *)(a1 + 8);
if ( *(_DWORD *)(a1 + 12) + a2 >= (int)result )
{
if ( *(_DWORD *)(a1 + 16) >= a2 )
a2 = *(_DWORD *)(a1 + 16);
v3 = (_DWORD)result + a2;
*(_DWORD *)(a1 + 8) = v3;
result = realloc(*(void **)a1, v3);
*(_QWORD *)a1 = result;
}
return result;
}

original_code:
void stringAlloc(struct String *string, int required)
{
 if (string->count + required >= string->total) {
  string->total += (required > string->blockSize ? required : string->blockSize);
  string->str = realloc(string->str, string->total);
 }
}

variable_types: struct String { char *str; int total; int count; int blockSize; } *

variable_types: required int


stringAddStr

decompiled_code:
char *__fastcall stringAddStr(__int64 a1, const char *a2)
{
int v2; // ebp
char *result; // rax

v2 = strlen(a2);
stringAlloc(a1, v2);
if ( *(_DWORD *)(a1 + 12) )
result = strcat(*(char **)a1, a2);
else
result = strcpy(*(char **)a1, a2);
*(_DWORD *)(a1 + 12) += v2;
return result;
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1, const char *a2)
{
int v2; // ebp
char *result; // rax

v2 = strlen(a2);
func7(a1, v2);
if ( *(_DWORD *)(a1 + 12) )
result = strcat(*(char **)a1, a2);
else
result = strcpy(*(char **)a1, a2);
*(_DWORD *)(a1 + 12) += v2;
return result;
}

original_code:
void stringAddStr(struct String *string, char *str)
{
 int len;
 stringAlloc(string, len = strlen(str));
 string->count == 0 ? strcpy(string->str, str) : strcat(string->str, str);
 string->count += len;
}

variable_types:
str
char *

variable_types: len int

user_defined_types: struct String { char *str; int total; int count; int blockSize; }


addScope

original_code:
void addScope(struct Scope *scope, struct Scope **currentScope)
{
 if (scope == ((void *)0)) {
  scope = (struct Scope *)malloc(sizeof(struct Scope));
  scope->depth = 0;
  scope->parent = ((void *)0);
  *currentScope = scope;
 } else {
  scope->child = (struct Scope *)malloc(sizeof(struct Scope));
  scope->child->depth = scope->depth + 1;
  scope->child->parent = scope;
  *currentScope = scope->child;
 }
 (*currentScope)->child = ((void *)0);
 (*currentScope)->first = ((void *)0);
 (*currentScope)->last = ((void *)0);
}

variable_types: struct Scope { int depth; struct Scope *parent; struct Scope *child; struct Token { char type[3]; char charVal; double intVal; struct Token *previous; struct Token *next; } *first; struct Token *last; } *

variable_types:
currentScope
struct Scope **

user_defined_types: struct Scope { int depth; struct Scope *parent; struct Scope *child; struct Token *first; struct Token *last; }


freeScope

decompiled_code:
void __fastcall freeScope(void *ptr, _QWORD *a2)
{
_QWORD *v3; // rdi
__int64 i; // rbx
__int64 v5; // rax

v3 = (_QWORD *)*((_QWORD *)ptr + 3);
if ( v3 )
{
for ( i = v3[3]; i; i = *(_QWORD *)(i + 24) )
{
free(*(void **)(i + 16));
v3 = (_QWORD *)i;
}
free(v3);
}
v5 = *((_QWORD *)ptr + 1);
*a2 = v5;
if ( v5 )
free(*(void **)(v5 + 16));
else
free(ptr);
}

original_code:
void freeScope(struct Scope *scope, struct Scope **currentScope)
{
 struct Token *token = scope->first;
 if (token != ((void *)0)) {
  while(token->next != ((void *)0)) {
   token = token->next;
   free(token->previous);
  }
  free(token);
 }
 *currentScope = scope->parent;
 if (*currentScope != ((void *)0)) {
  free((*currentScope)->child);
 } else {
  free(scope);
 }
}

variable_types: struct Token { char type[3]; char charVal; double intVal; struct Token *previous; struct Token *next; } *


insertToken

original_code:
void insertToken(struct Scope *scope, char *type, char charVal, double intVal)
{
 if (scope->last == ((void *)0)) {
  scope->first = (struct Token *)malloc(sizeof(struct Token));
  scope->last = scope->first;
 } else {
  scope->last->next = (struct Token *)malloc(sizeof(struct Token));
  scope->last->next->previous = scope->last;
  scope->last = scope->last->next;
 }
 scope->last->next = ((void *)0);
 strcpy(scope->last->type, type);
 scope->last->charVal = charVal;
 scope->last->intVal = intVal;
}

variable_types:
type
char *

variable_types: charVal char

variable_types: intVal double

user_defined_types: struct Token { char type[3]; char charVal; double intVal; struct Token *previous; struct Token *next; }


freeAll

decompiled_code:
void __fastcall freeAll(void *a1)
{
void *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

for ( ptr[0] = a1; *((_QWORD *)ptr[0] + 1); a1 = ptr[0] )
freeScope(a1, ptr);
freeScope(a1, ptr);
}

canonical_decompiled_code:
void __fastcall func13(void *a1)
{
void *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

for ( ptr[0] = a1; *((_QWORD *)ptr[0] + 1); a1 = ptr[0] )
func11(a1, ptr);
func11(a1, ptr);
}

original_code:
void freeAll(struct Scope *scope)
{
 while (scope->parent != ((void *)0)) {
  freeScope(scope, &scope);
 }
 freeScope(scope, &scope);
}


strtoconst

original_code:
double strtoconst(char *nptr, char **endptr)
{
 int constantCount = 3;
 struct Constant constants[] = {
  {"e", 2.71828182845904523536, 1, 0, 1},
  {"pi", 3.14159265358979323846, 2, 0, 0},
  {"phi", (1.0 + pow(5.0, 0.5)) / 2.0, 3, 0, 0}
 };
 struct Constant *ct;
 char *s = nptr;
 int c, i, j;
 double replace = 0.0L;
 do {
  c = (unsigned char) *s++;
 } while (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace));
 for (i = 0; i < 3; i++, c = (unsigned char) *s++) {
  ct = constants;
  for (j = 0; j < constantCount ; j++, ct++) {
   if (ct->name[i] != 0 && (ct->caseSensative ? c : tolower(c)) == ct->name[i]) {
    if (ct->match == ++ct->matched) {
     replace = ct->value;
     break;
    }
   }
  }
  if (replace) {
   break;
  }
 }
 if (endptr != 0) {
  *endptr = (char *) (replace ? s : nptr);
 }
 return replace;
}

canonical_original_code:
double strtoconst(char *nptr, char **endptr)
{
 int constantCount = 3;
 struct Constant constants[] = {
  {"e", 2.71828182845904523536, 1, 0, 1},
  {"pi", 3.14159265358979323846, 2, 0, 0},
  {"phi", (1.0 + pow(5.0, 0.5)) / 2.0, 3, 0, 0}
 };
 struct Constant *ct;
 char *s = nptr;
 int c; int i; int j;
 double replace = 0.0L;
 do {
  c = (unsigned char) *s++;
 } while (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace));
 for (i = 0; i < 3; i++, c = (unsigned char) *s++) {
  ct = constants;
  for (j = 0; j < constantCount ; j++, ct++) {
   if (ct->name[i] != 0 && (ct->caseSensative ? c : tolower(c)) == ct->name[i]) {
    if (ct->match == ++ct->matched) {
     replace = ct->value;
     break;
    }
   }
  }
  if (replace) {
   break;
  }
 }
 if (endptr != 0) {
  *endptr = (char *) (replace ? s : nptr);
 }
 return replace;
}

variable_types:
nptr
char *

variable_types:
endptr
char **

variable_types: constantCount int

variable_types: struct Constant { char name[3]; double value; int match; int matched; int caseSensative; } []

variable_types: struct Constant { char name[3]; double value; int match; int matched; int caseSensative; } *

variable_types:
s
char *

variable_types: c int

variable_types: i int

variable_types: j int

variable_types: replace double

return_type: double


normalise

decompiled_code:
__int64 __fastcall normalise(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( (_BYTE)a1 != 94 )
{
if ( (char)a1 > 94 )
{
if ( (_BYTE)a1 == 120 )
result = 42LL;
}
else if ( (_BYTE)a1 == 39 )
{
result = 94LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( (_BYTE)a1 != 94 )
{
if ( (char)a1 > 94 )
{
if ( (_BYTE)a1 == 120 )
result = 42LL;
}
else if ( (_BYTE)a1 == 39 )
{
result = 94LL;
}
}
return result;
}

original_code:
char normalise(char operator)
{
 switch (operator) {
  case 'x':
  case '*':
   return '*';
  case '\'':
  case '^':
   return '^';
  default:
   return operator;
 }
}

variable_types: operator char

return_type: char


operation

decompiled_code:
double __fastcall operation(char a1, double a2, double a3)
{
double result; // xmm0_8

if ( a1 == 45 )
return a2 - a3;
if ( a1 > 45 )
{
if ( a1 == 47 )
{
result = a2 / a3;
}
else
{
if ( a1 != 94 )
goto LABEL_12;
result = pow(a2, a3);
}
}
else
{
if ( a1 != 42 )
{
if ( a1 == 43 )
return a2 + a3;
LABEL_12:
puts("Unknown operator");
exit(1);
}
result = a2 * a3;
}
return result;
}

canonical_decompiled_code:
double __fastcall func16(char a1, double a2, double a3)
{
double result; // xmm0_8

if ( a1 == 45 )
return a2 - a3;
if ( a1 > 45 )
{
if ( a1 == 47 )
{
result = a2 / a3;
}
else
{
if ( a1 != 94 )
goto LABEL_12;
result = pow(a2, a3);
}
}
else
{
if ( a1 != 42 )
{
if ( a1 == 43 )
return a2 + a3;
LABEL_12:
puts("Unknown operator");
exit(1);
}
result = a2 * a3;
}
return result;
}

original_code:
double operation(char operator, double pre, double post)
{
 switch (operator) {
  case '^': return pow(pre, post);
  case '/': return pre / post;
  case '*': return pre * post;
  case '+': return pre + post;
  case '-': return pre - post;
 }
 printf("Unknown operator\n");
 exit(1);
}

variable_types: pre double

variable_types: post double


findOperations

original_code:
void findOperations(char *operators, int numOperators, struct Scope *scope)
{
 int i;
 char *operator;
 struct Token *token = scope->first, *newNext;
 for(; token != ((void *)0) && token->next != ((void *)0); token = token->next) {
  for (i = 0, operator = operators; i < numOperators; i++, operator = &operators[i]) {
   if (strcmp(token->type, "OP") == 0 && token->charVal == *operator) {
    if (token->previous == ((void *)0) || token->next == ((void *)0) || strcmp(token->next->type, "NUM")
     || strcmp(token->previous->type, "NUM")) {
      freeAll(scope);
      printf("Sytax error.\n");
      exit(1);
    }
    token->previous->intVal = operation(token->charVal, token->previous->intVal, token->next->intVal);
    newNext = token->next->next;
    token = token->previous;
    free(token->next->next);
    free(token->next);
    token->next = newNext;
    if (token->next != ((void *)0)) {
     token->next->previous = token;
    }
    break;
   }
  }
 }
}

canonical_original_code:
void findOperations(char *operators, int numOperators, struct Scope *scope)
{
 int i;
 char *operator;
 struct Token *token = scope->first; struct Token *newNext;
 for(; token != ((void *)0) && token->next != ((void *)0); token = token->next) {
  for (i = 0, operator = operators; i < numOperators; i++, operator = &operators[i]) {
   if (strcmp(token->type, "OP") == 0 && token->charVal == *operator) {
    if (token->previous == ((void *)0) || token->next == ((void *)0) || strcmp(token->next->type, "NUM")
     || strcmp(token->previous->type, "NUM")) {
      freeAll(scope);
      printf("Sytax error.\n");
      exit(1);
    }
    token->previous->intVal = operation(token->charVal, token->previous->intVal, token->next->intVal);
    newNext = token->next->next;
    token = token->previous;
    free(token->next->next);
    free(token->next);
    token->next = newNext;
    if (token->next != ((void *)0)) {
     token->next->previous = token;
    }
    break;
   }
  }
 }
}

variable_types:
operators
char *

variable_types: numOperators int

variable_types: struct Scope { int depth; struct Scope *parent; struct Scope *child; struct Token { char type[3]; char charVal; double intVal; struct Token *previous; struct Token *next; } *first; struct Token *last; } *

variable_types:
operator
char *


evaluateScope

decompiled_code:
double __fastcall evaluateScope(void *ptr, _QWORD *a2)
{
__int64 v2; // rax
double v3; // r12

findOperations("^", 1, ptr);
findOperations("*/", 2, ptr);
findOperations("+-", 2, ptr);
v2 = *((_QWORD *)ptr + 3);
v3 = 0.0;
if ( v2 )
v3 = *(double *)(v2 + 8);
freeScope(ptr, a2);
return v3;
}

original_code:
double evaluateScope(struct Scope *scope, struct Scope **currentScope)
{
 double total;
 findOperations("^", 1, scope);
 findOperations("*/", 2, scope);
 findOperations("+-", 2, scope);
 total = scope->first == ((void *)0) ? 0 : scope->first->intVal;
 freeScope(scope, currentScope);
 return total;
}

variable_types:
currentScope
struct Scope **

variable_types: total double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
char *v4; // rbx
char v5; // r12
const unsigned __int16 **v6; // rbp
char v7; // al
char v8; // bl
void *v9; // r12
const char *v10; // rdi
double v11; // xmm0_8
char v12; // al
double v13; // xmm0_8
double v15; // [rsp+8h] [rbp-50h]
void *ptr; // [rsp+18h] [rbp-40h] BYREF
char *nptr; // [rsp+20h] [rbp-38h] BYREF
int v18; // [rsp+28h] [rbp-30h]
int v19; // [rsp+2Ch] [rbp-2Ch]
int v20; // [rsp+30h] [rbp-28h]
char *endptr[4]; // [rsp+38h] [rbp-20h] BYREF

nptr = 0LL;
v18 = 0;
v19 = 0;
v20 = 5;
ptr = 0LL;
addScope(0LL, (__int64 *)&ptr);
if ( argc == 1 )
{
while ( 1 )
{
v7 = getchar();
if ( v7 == -1 || v7 == 10 )
break;
stringAddChar((__int64)&nptr, v7);
}
}
else if ( argc > 1 )
{
v3 = argv + 1;
do
{
stringAddStr((__int64)&nptr, *v3);
stringAddChar((__int64)&nptr, 32);
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
}
v4 = nptr;
endptr[0] = nptr;
v5 = *nptr;
if ( *nptr )
{
v6 = __ctype_b_loc();
do
{
if ( ((*v6)[v5] & 0x2000) != 0 )
{
endptr[0] = v4 + 1;
}
else if ( v5 == 40 )
{
addScope((__int64)ptr, (__int64 *)&ptr);
++endptr[0];
}
else if ( v5 == 41 )
{
v11 = evaluateScope(ptr, &ptr);
insertToken((__int64)ptr, "NUM", 0, v11);
++endptr[0];
}
else
{
v15 = strtold(v4, endptr);
if ( v15 == 0.0 && (v15 = strtoconst(endptr[0], endptr), v15 == 0.0) )
{
v12 = normalise(*endptr[0]);
insertToken((__int64)ptr, "OP", v12, 0.0);
++endptr[0];
}
else
{
v8 = *v4;
if ( ((v8 - 43) & 0xFD) == 0 )
{
v9 = ptr;
v10 = (const char *)*((_QWORD *)ptr + 4);
if ( v10 )
{
if ( strcmp(v10, "OP") )
insertToken((__int64)v9, "OP", v8, 0.0);
}
}
insertToken((__int64)ptr, "NUM", 0, v15);
}
}
v4 = endptr[0];
v5 = *endptr[0];
}
while ( *endptr[0] );
}
v13 = evaluateScope(ptr, &ptr);
printf("%.15g\n", v13);
free(nptr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
char *v4; // rbx
char v5; // r12
const unsigned __int16 **v6; // rbp
char v7; // al
char v8; // bl
void *v9; // r12
const char *v10; // rdi
double v11; // xmm0_8
char v12; // al
double v13; // xmm0_8
double v15; // [rsp+8h] [rbp-50h]
void *ptr; // [rsp+18h] [rbp-40h] BYREF
char *nptr; // [rsp+20h] [rbp-38h] BYREF
int v18; // [rsp+28h] [rbp-30h]
int v19; // [rsp+2Ch] [rbp-2Ch]
int v20; // [rsp+30h] [rbp-28h]
char *endptr[4]; // [rsp+38h] [rbp-20h] BYREF

nptr = 0LL;
v18 = 0;
v19 = 0;
v20 = 5;
ptr = 0LL;
func10(0LL, (__int64 *)&ptr);
if ( argc == 1 )
{
while ( 1 )
{
v7 = getchar();
if ( v7 == -1 || v7 == 10 )
break;
func8((__int64)&nptr, v7);
}
}
else if ( argc > 1 )
{
v3 = argv + 1;
do
{
func9((__int64)&nptr, *v3);
func8((__int64)&nptr, 32);
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
}
v4 = nptr;
endptr[0] = nptr;
v5 = *nptr;
if ( *nptr )
{
v6 = __ctype_b_loc();
do
{
if ( ((*v6)[v5] & 0x2000) != 0 )
{
endptr[0] = v4 + 1;
}
else if ( v5 == 40 )
{
func10((__int64)ptr, (__int64 *)&ptr);
++endptr[0];
}
else if ( v5 == 41 )
{
v11 = func18(ptr, &ptr);
func12((__int64)ptr, "NUM", 0, v11);
++endptr[0];
}
else
{
v15 = strtold(v4, endptr);
if ( v15 == 0.0 && (v15 = func14(endptr[0], endptr), v15 == 0.0) )
{
v12 = func15(*endptr[0]);
func12((__int64)ptr, "OP", v12, 0.0);
++endptr[0];
}
else
{
v8 = *v4;
if ( ((v8 - 43) & 0xFD) == 0 )
{
v9 = ptr;
v10 = (const char *)*((_QWORD *)ptr + 4);
if ( v10 )
{
if ( strcmp(v10, "OP") )
func12((__int64)v9, "OP", v8, 0.0);
}
}
func12((__int64)ptr, "NUM", 0, v15);
}
}
v4 = endptr[0];
v5 = *endptr[0];
}
while ( *endptr[0] );
}
v13 = func18(ptr, &ptr);
printf("%.15g\n", v13);
free(nptr);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char ch, *str, *strStart;
 int i;
 double number;
 struct String input = {((void *)0), 0, 0, 5};
 struct Scope *currentScope = ((void *)0);
 addScope(currentScope, &currentScope);
 if (argc == 1) {
  while ((ch = getchar()) != '\n' && ch != (-1)) {
   stringAddChar(&input, ch);
  }
 } else {
  for (i = 1; i < argc; i++) {
   stringAddStr(&input, argv[i]);
   stringAddChar(&input, ' ');
  }
 }
 str = input.str;
 while (*str != '\0') {
  strStart = str;
  if (((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace)) {
   str++;
  } else if (*str == '(') {
   addScope(currentScope, &currentScope);
   str++;
  } else if (*str == ')') {
   insertToken(currentScope, "NUM", '\0', evaluateScope(currentScope, &currentScope));
   str++;
  } else if ((number = strtold(str, &str)) == 0.0L && (number = strtoconst(str, &str)) == 0.0L) {
   insertToken(currentScope, "OP", normalise(*str), 0);
   str++;
  } else {
   if ((*strStart == '+' || *strStart == '-')
    && currentScope->last != ((void *)0)
    && strcmp(currentScope->last->type, "OP")) {
    insertToken(currentScope, "OP", *strStart, 0);
   }
   insertToken(currentScope, "NUM", '\0', number);
  }
 }
 printf("%.15g\n", evaluateScope(currentScope, &currentScope));
 free(input.str);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char ch; char *str; char *strStart;
 int i;
 double number;
 struct String input = {((void *)0), 0, 0, 5};
 struct Scope *currentScope = ((void *)0);
 addScope(currentScope, &currentScope);
 if (argc == 1) {
  while ((ch = getchar()) != '\n' && ch != (-1)) {
   stringAddChar(&input, ch);
  }
 } else {
  for (i = 1; i < argc; i++) {
   stringAddStr(&input, argv[i]);
   stringAddChar(&input, ' ');
  }
 }
 str = input.str;
 while (*str != '\0') {
  strStart = str;
  if (((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace)) {
   str++;
  } else if (*str == '(') {
   addScope(currentScope, &currentScope);
   str++;
  } else if (*str == ')') {
   insertToken(currentScope, "NUM", '\0', evaluateScope(currentScope, &currentScope));
   str++;
  } else if ((number = strtold(str, &str)) == 0.0L && (number = strtoconst(str, &str)) == 0.0L) {
   insertToken(currentScope, "OP", normalise(*str), 0);
   str++;
  } else {
   if ((*strStart == '+' || *strStart == '-')
    && currentScope->last != ((void *)0)
    && strcmp(currentScope->last->type, "OP")) {
    insertToken(currentScope, "OP", *strStart, 0);
   }
   insertToken(currentScope, "NUM", '\0', number);
  }
 }
 printf("%.15g\n", evaluateScope(currentScope, &currentScope));
 free(input.str);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ch char

variable_types:
str
char *

variable_types:
strStart
char *

variable_types: number double

variable_types: struct String { char *str; int total; int count; int blockSize; }


INThandler

repo: tongche/oscourse

decompiled_code:
void INThandler()
{
printf("Interrupt Signal:%d\n", 2LL);
if ( isWaiting )
kill(pidWait, 2);
__sysv_signal(2, (__sighandler_t)1);
}

canonical_decompiled_code:
void func7()
{
printf("Interrupt Signal:%d\n", 2LL);
if ( isWaiting )
kill(pidWait, 2);
__sysv_signal(2, (__sighandler_t)1);
}

original_code:
void INThandler(int signum)
{
   printf("Interrupt Signal:%d\n",2);
   if(isWaiting)
      kill(pidWait,2);
   signal(2,((__sighandler_t) 1));
}

canonical_original_code:
void INThandler(int signum)
{
   printf("Interrupt Signal:%d\n",2);
   if(isWaiting)
      kill(pidWait,2);
   signal(2,((void (*)(int)) 1));
}

variable_types: signum int


warning

decompiled_code:
int __fastcall warning(const char *a1)
{
return puts(a1);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
return puts(a1);
}

original_code:
void warning(char* err)
{
  printf("%s\n",err);
  return;
}

canonical_original_code:
void warning(char *err)
{
  printf("%s\n",err);
  return;
}

variable_types:
err
char *


decompiled_code:
__int64 __fastcall builtin_cd(int a1, __int64 a2)
{
__int64 result; // rax

if ( a1 == 2 )
{
error = chdir(*(const char **)(a2 + 8));
result = 0LL;
}
else
{
warning("Wrong arguments");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, __int64 a2)
{
__int64 result; // rax

if ( a1 == 2 )
{
error = chdir(*(const char **)(a2 + 8));
result = 0LL;
}
else
{
func8("Wrong arguments");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
builtin_cd(int argc, char **argv)
{
   if(argc!=2) {
    warning("Wrong arguments");
    return -1;
}
  error=chdir(argv[1]);
  return (0);
}

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall builtin_status(__int64 a1, __int64 a2, int a3)
{
int v4; // eax
char v6[56]; // [rsp+0h] [rbp-38h] BYREF

v4 = sprintf(v6, "%d", (unsigned int)error);
write(a3, v6, v4);
if ( a3 == 1 )
putchar(10);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, int a3)
{
int v4; // eax
char v6[56]; // [rsp+0h] [rbp-38h] BYREF

v4 = sprintf(v6, "%d", (unsigned int)error);
write(a3, v6, v4);
if ( a3 == 1 )
putchar(10);
return 0LL;
}

original_code:
int
builtin_status(int argc, char **argv,int fd)
{
  char buffer[33];
  int num = 0;
  num = sprintf(buffer,"%d",error);
  write(fd,buffer,num*sizeof(char));
  if(fd==1)
  putchar('\n');
  return (0);
}

canonical_original_code:
int builtin_status(int argc, char **argv, int fd)
{
  char buffer[33];
  int num = 0;
  num = sprintf(buffer,"%d",error);
  write(fd,buffer,num*sizeof(char));
  if(fd==1)
  putchar('\n');
  return (0);
}

variable_types: fd int

variable_types:
buffer
char [33]

variable_types: num int


decompiled_code:
bool __fastcall isspace_c(char a1)
{
bool result; // al

result = 1;
if ( a1 != 9 )
result = a1 == 32;
return result;
}

canonical_decompiled_code:
bool __fastcall func12(char a1)
{
bool result; // al

result = 1;
if ( a1 != 9 )
result = a1 == 32;
return result;
}

original_code:
_Bool isspace_c(char c){
switch (c){
case ' ': return 1;
case '\t': return 1;
default: return 0;
  }
}

variable_types: c char


parseword

decompiled_code:
char *__fastcall parseword(char **a1)
{
char *i; // rbx
char *j; // rbp

for ( i = *a1; isspace_c(*i); ++i )
;
for ( j = i; !strchr(" \t;&|><\n", *j); ++j )
;
*a1 = j;
if ( i == j )
i = 0LL;
return i;
}

canonical_decompiled_code:
char *__fastcall func13(char **a1)
{
char *i; // rbx
char *j; // rbp

for ( i = *a1; func12(*i); ++i )
;
for ( j = i; !strchr(" \t;&|><\n", *j); ++j )
;
*a1 = j;
if ( i == j )
i = 0LL;
return i;
}

original_code:
static char *
parseword(char **pp)
{
 char *p = *pp;
 char *word;
 for (; isspace_c(*p); p++);
 word = p;
 for (; strchr(" \t;&|><\n", *p) == ((void *)0); p++);
 *pp = p;
 return (p != word ? word : ((void *)0));
}

canonical_original_code:
static char *parseword(char **pp)
{
 char *p = *pp;
 char *word;
 for (; isspace_c(*p); p++);
 word = p;
 for (; strchr(" \t;&|><\n", *p) == ((void *)0); p++);
 *pp = p;
 return (p != word ? word : ((void *)0));
}

variable_types:
pp
char **

variable_types:
p
char *

variable_types:
word
char *


initializeCom

original_code:
void initializeCom(command* com, char **args)
{
        com->inout[0] = 0;
        com->argc = 0;
        com->ground = 1;
        com->commandType = EXTERNAL;
 com->inout[1] = 1;
 com->argv = args;
        com->pipeToClose[0] = -1;
        com->pipeToClose[1] = -1;
        com->pipeToCloseParent = -1;
        com->runnable = 1;
}

canonical_original_code:
void initializeCom(struct command *com, char **args)
{
        com->inout[0] = 0;
        com->argc = 0;
        com->ground = 1;
        com->commandType = EXTERNAL;
 com->inout[1] = 1;
 com->argv = args;
        com->pipeToClose[0] = -1;
        com->pipeToClose[1] = -1;
        com->pipeToCloseParent = -1;
        com->runnable = 1;
}

variable_types: struct command { int pipeToClose[2]; int pipeToCloseParent; int inout[2]; enum commandType { CD=0, STATUS=1, EXIT=2, EXTERNAL=3 } commandType; char **argv; int argc; _Bool ground; _Bool runnable; } *

variable_types:
args
char **

user_defined_types: struct command { int pipeToClose[2]; int pipeToCloseParent; int inout[2]; enum commandType commandType; char **argv; int argc; _Bool ground; _Bool runnable; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[1008]; // [rsp+0h] [rbp-1408h] BYREF
char buf[4120]; // [rsp+3F0h] [rbp-1018h] BYREF

__sysv_signal(2, (__sighandler_t)1);
isWaiting = 0;
isExiting = 0;
do
{
getcwd(buf, 0x1001uLL);
printf("%s %% ", buf);
if ( !fgets(v4, 1000, _bss_start) )
return error;
__sysv_signal(2, (__sighandler_t)INThandler);
process(v4);
if ( error )
warning("The operation is Unsuccessful(exit status not 0)");
__sysv_signal(2, (__sighandler_t)1);
}
while ( !isExiting );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[1008]; // [rsp+0h] [rbp-1408h] BYREF
char buf[4120]; // [rsp+3F0h] [rbp-1018h] BYREF

__sysv_signal(2, (__sighandler_t)1);
isWaiting = 0;
isExiting = 0;
do
{
getcwd(buf, 0x1001uLL);
printf("%s %% ", buf);
if ( !fgets(v4, 1000, _bss_start) )
return error;
__sysv_signal(2, (__sighandler_t)INThandler);
func15(v4);
if ( error )
func8("The operation is Unsuccessful(exit status not 0)");
__sysv_signal(2, (__sighandler_t)1);
}
while ( !isExiting );
return 0;
}

original_code:
int
main(void)
{
        signal(2,((__sighandler_t) 1));
        char cwd[4096 +1];
 char line[1000];
 char *res;
        isWaiting = 0;
        isExiting = 0;
 for (;;) {
          getcwd(cwd, sizeof(cwd));
   printf("%s %% ", cwd);
   res = fgets(line, sizeof(line), stdin);
          if (res == ((void *)0))
  break;
          signal(2,INThandler);
          process(line);
           if(error)
           warning("The operation is Unsuccessful(exit status not 0)");
          signal(2,((__sighandler_t) 1));
          if(isExiting)
              return 0;
 }
 return (error);
}

canonical_original_code:
int main()
{
        signal(2,((void (*)(int)) 1));
        char cwd[-1];
 char line[1000];
 char *res;
        isWaiting = 0;
        isExiting = 0;
 for (;;) {
          getcwd(cwd, sizeof(cwd));
   printf("%s %% ", cwd);
   res = fgets(line, sizeof(line), stdin);
          if (res == ((void *)0))
  break;
          signal(2,INThandler);
          process(line);
           if(error)
           warning("The operation is Unsuccessful(exit status not 0)");
          signal(2,((void (*)(int)) 1));
          if(isExiting)
              return 0;
 }
 return (error);
}

variable_types:
cwd
char [-1]

variable_types:
line
char [1000]

variable_types:
res
char *


repo: travisb-ca/tachyon

decompiled_code:
__int64 __fastcall tty_new(__int64 a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // ebx
unsigned int v4; // ebp
unsigned int v5; // er12
int *v6; // rax
int *v8; // rax
unsigned int v9; // ebp
int *v10; // rax
char *v11; // rax
int v12; // er14
char *v13; // rbp
int v14; // er13
int *v15; // rax
char v16; // r12
const unsigned __int16 *v17; // rax
char **v18; // rbp
char *v19; // rax
const char *v20; // rdx
bool v21; // zf
const char *v22; // rax
const unsigned __int16 *v23; // r8
char *v24; // rax
int v25; // er9
__int64 v26; // r12
const char *v27; // rcx
unsigned int v28; // ebx
int *v29; // rax
unsigned int v30; // ebx
int *v31; // rax
char value[16]; // [rsp+10h] [rbp-448h] BYREF
char s[1024]; // [rsp+20h] [rbp-438h] BYREF
char v34; // [rsp+420h] [rbp-38h] BYREF

v2 = posix_openpt(258);
v3 = v2;
if ( v2 < 0 )
{
v5 = -1;
if ( *((int *)&cmd_options + 1) >= 0 )
{
v8 = _errno_location();
fprintf(stderr, "openpt failed %d %d\n", v3, (unsigned int)*v8);
}
goto LABEL_7;
}
close_on_exec((unsigned int)v2);
v4 = grantpt(v3);
if ( v4 )
{
v5 = -2;
if ( *((int *)&cmd_options + 1) >= 0 )
{
v6 = _errno_location();
fprintf(stderr, "granpt failed %d %d\n", v4, (unsigned int)*v6);
}
LABEL_7:
close(v3);
return v5;
}
v9 = unlockpt(v3);
if ( v9 )
{
v5 = -3;
if ( *((int *)&cmd_options + 1) >= 0 )
{
v10 = _errno_location();
fprintf(stderr, "unlockpt failed %d %d\n", v9, (unsigned int)*v10);
}
goto LABEL_7;
}
v11 = ptsname(v3);
v12 = open(v11, 2);
if ( v12 < 0 )
{
if ( *((int *)&cmd_options + 1) >= 0 )
{
v15 = _errno_location();
fprintf(stderr, "failed to open slave %d %d\n", (unsigned int)v12, (unsigned int)*v15);
}
close(v12);
v5 = -4;
goto LABEL_7;
}
if ( fork() )
{
close(v12);
v5 = v3;
}
else
{
qmemcpy(s, (const void *)(unsigned int)((_DWORD)&cmd_options + 8), sizeof(s));
v13 = s;
v14 = 1;
do
{
v16 = v13[1];
if ( !v16 )
break;
v17 = *_ctype_b_loc();
if ( (v17[*v13] & 0x2000) != 0 )
v14 += (v17[v16] & 0x2000) == 0;
++v13;
}
while ( v13 != &s[1023] );
if ( *((int *)&cmd_options + 1) > 1 )
fprintf(stderr, "Shell command had %d args\n", (unsigned int)v14);
v18 = (char **)calloc(v14 + 1, 8uLL);
if ( v18 )
{
v19 = strrchr(s, 47);
v20 = v19 + 1;
v21 = v19 == 0LL;
v22 = "unknown";
if ( !v21 )
v22 = v20;
*v18 = (char *)v22;
v23 = *_ctype_b_loc();
v24 = &s[1];
v25 = 1;
do
{
if ( (v23[*v24] & 0x2000) != 0 )
{
*v24 = 0;
}
else if ( !*(v24 - 1) && *v24 )
{
v18[v25++] = v24;
}
++v24;
}
while ( v24 != &v34 );
if ( *((int *)&cmd_options + 1) > 1 && v14 >= 0 )
{
v26 = 0LL;
do
{
v27 = v18[v26];
if ( v27 )
{
if ( *((int *)&cmd_options + 1) > 1 )
fprintf(stderr, "arg %d is '%s'\n", (unsigned int)v26, v27);
}
else if ( *((int *)&cmd_options + 1) > 1 )
{
fprintf(stderr, "arg %d is NULL\n", (unsigned int)v26);
}
++v26;
}
while ( v14 >= (int)v26 );
}
snprintf(value, 0x10uLL, "%d", a2);
setenv("WINDOW", value, 1);
setenv("TACHYON_SESSION", (const char *)(unsigned int)((_DWORD)&cmd_options + 1032), 1);
close(v3);
close(0);
close(1);
close(2);
dup(v12);
dup(v12);
dup(v12);
close(v12);
setsid();
v28 = ioctl(0, 0x540EuLL, 1LL);
if ( v28 )
{
v5 = 7;
if ( *((int *)&cmd_options + 1) >= 0 )
{
v29 = _errno_location();
fprintf(stderr, "slave failed to set controlling tty %d %d\n", v28, (unsigned int)*v29);
}
}
else
{
v30 = execv(s, v18);
v5 = 8;
if ( *((int *)&cmd_options + 1) >= 0 )
{
v31 = _errno_location();
fprintf(stderr, "slave failed to exec %d %d\n", v30, (unsigned int)*v31);
}
}
}
else
{
v5 = 9;
if ( *((int *)&cmd_options + 1) >= 0 )
fwrite("Unable to allocate arg buffer\n", 1uLL, 0x1EuLL, stderr);
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // ebx
unsigned int v4; // ebp
unsigned int v5; // er12
int *v6; // rax
int *v8; // rax
unsigned int v9; // ebp
int *v10; // rax
char *v11; // rax
int v12; // er14
char *v13; // rbp
int v14; // er13
int *v15; // rax
char v16; // r12
const unsigned __int16 *v17; // rax
char **v18; // rbp
char *v19; // rax
const char *v20; // rdx
bool v21; // zf
const char *v22; // rax
const unsigned __int16 *v23; // r8
char *v24; // rax
int v25; // er9
__int64 v26; // r12
const char *v27; // rcx
unsigned int v28; // ebx
int *v29; // rax
unsigned int v30; // ebx
int *v31; // rax
char value[16]; // [rsp+10h] [rbp-448h] BYREF
char s[1024]; // [rsp+20h] [rbp-438h] BYREF
char v34; // [rsp+420h] [rbp-38h] BYREF

v2 = posix_openpt(258);
v3 = v2;
if ( v2 < 0 )
{
v5 = -1;
if ( *((int *)&cmd_options + 1) >= 0 )
{
v8 = _errno_location();
fprintf(stderr, "openpt failed %d %d\n", v3, (unsigned int)*v8);
}
goto LABEL_7;
}
close_on_exec((unsigned int)v2);
v4 = grantpt(v3);
if ( v4 )
{
v5 = -2;
if ( *((int *)&cmd_options + 1) >= 0 )
{
v6 = _errno_location();
fprintf(stderr, "granpt failed %d %d\n", v4, (unsigned int)*v6);
}
LABEL_7:
close(v3);
return v5;
}
v9 = unlockpt(v3);
if ( v9 )
{
v5 = -3;
if ( *((int *)&cmd_options + 1) >= 0 )
{
v10 = _errno_location();
fprintf(stderr, "unlockpt failed %d %d\n", v9, (unsigned int)*v10);
}
goto LABEL_7;
}
v11 = ptsname(v3);
v12 = open(v11, 2);
if ( v12 < 0 )
{
if ( *((int *)&cmd_options + 1) >= 0 )
{
v15 = _errno_location();
fprintf(stderr, "failed to open slave %d %d\n", (unsigned int)v12, (unsigned int)*v15);
}
close(v12);
v5 = -4;
goto LABEL_7;
}
if ( fork() )
{
close(v12);
v5 = v3;
}
else
{
qmemcpy(s, (const void *)(unsigned int)((_DWORD)&cmd_options + 8), sizeof(s));
v13 = s;
v14 = 1;
do
{
v16 = v13[1];
if ( !v16 )
break;
v17 = *_ctype_b_loc();
if ( (v17[*v13] & 0x2000) != 0 )
v14 += (v17[v16] & 0x2000) == 0;
++v13;
}
while ( v13 != &s[1023] );
if ( *((int *)&cmd_options + 1) > 1 )
fprintf(stderr, "Shell command had %d args\n", (unsigned int)v14);
v18 = (char **)calloc(v14 + 1, 8uLL);
if ( v18 )
{
v19 = strrchr(s, 47);
v20 = v19 + 1;
v21 = v19 == 0LL;
v22 = "unknown";
if ( !v21 )
v22 = v20;
*v18 = (char *)v22;
v23 = *_ctype_b_loc();
v24 = &s[1];
v25 = 1;
do
{
if ( (v23[*v24] & 0x2000) != 0 )
{
*v24 = 0;
}
else if ( !*(v24 - 1) && *v24 )
{
v18[v25++] = v24;
}
++v24;
}
while ( v24 != &v34 );
if ( *((int *)&cmd_options + 1) > 1 && v14 >= 0 )
{
v26 = 0LL;
do
{
v27 = v18[v26];
if ( v27 )
{
if ( *((int *)&cmd_options + 1) > 1 )
fprintf(stderr, "arg %d is '%s'\n", (unsigned int)v26, v27);
}
else if ( *((int *)&cmd_options + 1) > 1 )
{
fprintf(stderr, "arg %d is NULL\n", (unsigned int)v26);
}
++v26;
}
while ( v14 >= (int)v26 );
}
snprintf(value, 0x10uLL, "%d", a2);
setenv("WINDOW", value, 1);
setenv("TACHYON_SESSION", (const char *)(unsigned int)((_DWORD)&cmd_options + 1032), 1);
close(v3);
close(0);
close(1);
close(2);
dup(v12);
dup(v12);
dup(v12);
close(v12);
setsid();
v28 = ioctl(0, 0x540EuLL, 1LL);
if ( v28 )
{
v5 = 7;
if ( *((int *)&cmd_options + 1) >= 0 )
{
v29 = _errno_location();
fprintf(stderr, "slave failed to set controlling tty %d %d\n", v28, (unsigned int)*v29);
}
}
else
{
v30 = execv(s, v18);
v5 = 8;
if ( *((int *)&cmd_options + 1) >= 0 )
{
v31 = _errno_location();
fprintf(stderr, "slave failed to exec %d %d\n", v30, (unsigned int)*v31);
}
}
}
else
{
v5 = 9;
if ( *((int *)&cmd_options + 1) >= 0 )
fwrite("Unable to allocate arg buffer\n", 1uLL, 0x1EuLL, stderr);
}
}
return v5;
}

original_code:
int tty_new(char *command, int bufnum) {
 int result;
 int pty_master;
 int pty_slave;
 pty_master = posix_openpt(02 | 0400);
 if (pty_master < 0) {
  do { if (cmd_options.verbose >= 0) fprintf(stderr, "openpt failed %d %d" "\n", pty_master, (*__errno_location ())); } while (0);
  result = -1;
  goto err_master;
 }
 close_on_exec(pty_master);
 result = grantpt(pty_master);
 if (result != 0) {
  do { if (cmd_options.verbose >= 0) fprintf(stderr, "granpt failed %d %d" "\n", result, (*__errno_location ())); } while (0);
  result = -2;
  goto err_master;
 }
 result = unlockpt(pty_master);
 if (result != 0) {
  do { if (cmd_options.verbose >= 0) fprintf(stderr, "unlockpt failed %d %d" "\n", result, (*__errno_location ())); } while (0);
  result = -3;
  goto err_master;
 }
 pty_slave = open(ptsname(pty_master), 02);
 if (pty_slave < 0) {
  do { if (cmd_options.verbose >= 0) fprintf(stderr, "failed to open slave %d %d" "\n", pty_slave, (*__errno_location ())); } while (0);
  result = -4;
  goto err_slave;
 }
 if (fork()) {
  close(pty_slave);
  return pty_master;
 } else {
  char *cmd_name;
  int num_args = 1;
  char buf[1024];
  char **args;
  memcpy(buf, cmd_options.new_buf_command, sizeof(buf));
  for (int i = 1; i < sizeof(buf); i++) {
   if (buf[i] == '\0')
    break;
   if (((*__ctype_b_loc ())[(int) ((buf[i-1]))] & (unsigned short int) _ISspace) && !((*__ctype_b_loc ())[(int) ((buf[i]))] & (unsigned short int) _ISspace))
    num_args++;
  }
  do { if (cmd_options.verbose >= 2) fprintf(stderr, "Shell command had %d args" "\n", num_args); } while (0);
  args = calloc(num_args + 1, sizeof(char *));
  if (!args) {
   do { if (cmd_options.verbose >= 0) fprintf(stderr, "Unable to allocate arg buffer" "\n"); } while (0);
   return 9;
  }
  cmd_name = strrchr(buf, '/');
  if (!cmd_name)
   cmd_name = "unknown";
  else
   cmd_name++;
  args[0] = cmd_name;
  for (int i = 1, n = 1; i < sizeof(buf); i++) {
   if (((*__ctype_b_loc ())[(int) ((buf[i]))] & (unsigned short int) _ISspace))
    buf[i] = '\0';
   if (buf[i - 1] == '\0' && buf[i] != '\0')
    args[n++] = &buf[i];
  }
  if (cmd_options.verbose >= 2)
   for (int i = 0; i < num_args + 1; i++)
    if (args[i])
     do { if (cmd_options.verbose >= 2) fprintf(stderr, "arg %d is '%s'" "\n", i, args[i]); } while (0);
    else
     do { if (cmd_options.verbose >= 2) fprintf(stderr, "arg %d is NULL" "\n", i); } while (0);
  {
   char bufnum_str[16];
   snprintf(bufnum_str, sizeof(bufnum_str), "%d", bufnum);
   setenv("WINDOW", bufnum_str, 1);
   setenv("TACHYON_SESSION", cmd_options.session_name, 1);
  }
  close(pty_master);
  close(0);
  close(1);
  close(2);
  dup(pty_slave);
  dup(pty_slave);
  dup(pty_slave);
  close(pty_slave);
  setsid();
  result = ioctl(0, 0x540E, 1);
  if (result != 0) {
   do { if (cmd_options.verbose >= 0) fprintf(stderr, "slave failed to set controlling tty %d %d" "\n", result, (*__errno_location ())); } while (0);
   return 7;
  }
  result = execv(buf, args);
  do { if (cmd_options.verbose >= 0) fprintf(stderr, "slave failed to exec %d %d" "\n", result, (*__errno_location ())); } while (0);
  return 8;
 }
err_slave:
 close(pty_slave);
err_master:
 close(pty_master);
 return result;
}

canonical_original_code:
int tty_new(char *command, int bufnum) {
 int result;
 int pty_master;
 int pty_slave;
 pty_master = posix_openpt(02 | 0400);
 if (pty_master < 0) {
  do { if (cmd_options.verbose >= 0) fprintf(stderr, "openpt failed %d %d" "\n", pty_master, (*__errno_location ())); } while (0);
  result = -1;
  goto err_master;
 }
 close_on_exec(pty_master);
 result = grantpt(pty_master);
 if (result != 0) {
  do { if (cmd_options.verbose >= 0) fprintf(stderr, "granpt failed %d %d" "\n", result, (*__errno_location ())); } while (0);
  result = -2;
  goto err_master;
 }
 result = unlockpt(pty_master);
 if (result != 0) {
  do { if (cmd_options.verbose >= 0) fprintf(stderr, "unlockpt failed %d %d" "\n", result, (*__errno_location ())); } while (0);
  result = -3;
  goto err_master;
 }
 pty_slave = open(ptsname(pty_master), 02);
 if (pty_slave < 0) {
  do { if (cmd_options.verbose >= 0) fprintf(stderr, "failed to open slave %d %d" "\n", pty_slave, (*__errno_location ())); } while (0);
  result = -4;
  goto err_slave;
 }
 if (fork()) {
  close(pty_slave);
  return pty_master;
 } else {
  char *cmd_name;
  int num_args = 1;
  char buf[1024];
  char **args;
  memcpy(buf, cmd_options.new_buf_command, sizeof(buf));
  for (int i = 1; i < sizeof(buf); i++) {
   if (buf[i] == '\0')
    break;
   if (((*__ctype_b_loc ())[(int) ((buf[i-1]))] & (unsigned short) _ISspace) && !((*__ctype_b_loc ())[(int) ((buf[i]))] & (unsigned short) _ISspace))
    num_args++;
  }
  do { if (cmd_options.verbose >= 2) fprintf(stderr, "Shell command had %d args" "\n", num_args); } while (0);
  args = calloc(num_args + 1, sizeof(char *));
  if (!args) {
   do { if (cmd_options.verbose >= 0) fprintf(stderr, "Unable to allocate arg buffer" "\n"); } while (0);
   return 9;
  }
  cmd_name = strrchr(buf, '/');
  if (!cmd_name)
   cmd_name = "unknown";
  else
   cmd_name++;
  args[0] = cmd_name;
  for (int i = 1; int n = 1; i < sizeof(buf); i++) {
   if (((*__ctype_b_loc ())[(int) ((buf[i]))] & (unsigned short) _ISspace))
    buf[i] = '\0';
   if (buf[i - 1] == '\0' && buf[i] != '\0')
    args[n++] = &buf[i];
  }
  if (cmd_options.verbose >= 2)
   for (int i = 0; i < num_args + 1; i++)
    if (args[i])
     do { if (cmd_options.verbose >= 2) fprintf(stderr, "arg %d is '%s'" "\n", i, args[i]); } while (0);
    else
     do { if (cmd_options.verbose >= 2) fprintf(stderr, "arg %d is NULL" "\n", i); } while (0);
  {
   char bufnum_str[16];
   snprintf(bufnum_str, sizeof(bufnum_str), "%d", bufnum);
   setenv("WINDOW", bufnum_str, 1);
   setenv("TACHYON_SESSION", cmd_options.session_name, 1);
  }
  close(pty_master);
  close(0);
  close(1);
  close(2);
  dup(pty_slave);
  dup(pty_slave);
  dup(pty_slave);
  close(pty_slave);
  setsid();
  result = ioctl(0, 0x540E, 1);
  if (result != 0) {
   do { if (cmd_options.verbose >= 0) fprintf(stderr, "slave failed to set controlling tty %d %d" "\n", result, (*__errno_location ())); } while (0);
   return 7;
  }
  result = execv(buf, args);
  do { if (cmd_options.verbose >= 0) fprintf(stderr, "slave failed to exec %d %d" "\n", result, (*__errno_location ())); } while (0);
  return 8;
 }
err_slave:
 close(pty_slave);
err_master:
 close(pty_master);
 return result;
}

variable_types:
command
char *

variable_types: bufnum int

variable_types: result int

variable_types:
buf
char [1024]

variable_types: i int

variable_types: n int


decompiled_code:
int tty_save_termstate()
{
return tcgetattr(0, &original_term_state);
}

canonical_decompiled_code:
int func1()
{
return tcgetattr(0, &original_term_state);
}

original_code:
void tty_save_termstate(void) {
 tcgetattr(0, &original_term_state);
}

canonical_original_code:
void tty_save_termstate() {
 tcgetattr(0, &original_term_state);
}


decompiled_code:
int tty_restore_termstate()
{
return tcsetattr(0, 0, &original_term_state);
}

canonical_decompiled_code:
int func2()
{
return tcsetattr(0, 0, &original_term_state);
}

original_code:
void tty_restore_termstate(void) {
 tcsetattr(0, 0, &original_term_state);
}

canonical_original_code:
void tty_restore_termstate() {
 tcsetattr(0, 0, &original_term_state);
}


decompiled_code:
__int64 tty_configure_control_tty()
{
unsigned int v0; // ebx
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

if ( tcgetattr(0, &v2) )
return (unsigned int)-1;
v2.c_lflag &= 0xFFFFFFB5;
v2.c_cc[6] = 1;
v0 = tcsetattr(0, 0, &v2);
if ( v0 )
return (unsigned int)-1;
setvbuf(stdout, 0LL, 2, 0LL);
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebx
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

if ( tcgetattr(0, &v2) )
return (unsigned int)-1;
v2.c_lflag &= 0xFFFFFFB5;
v2.c_cc[6] = 1;
v0 = tcsetattr(0, 0, &v2);
if ( v0 )
return (unsigned int)-1;
setvbuf(stdout, 0LL, 2, 0LL);
return v0;
}

original_code:
int tty_configure_control_tty(void) {
 struct termios termstate;
 if (tcgetattr(0, &termstate))
  return -1;
 termstate.c_lflag &= ~(0000002 | 0000010 | 0000100);
 termstate.c_cc[6] = 1;
 if (tcsetattr(0, 0, &termstate))
     return -1;
 setvbuf(stdout, ((void *)0), 2, 0);
 return 0;
}

canonical_original_code:
int tty_configure_control_tty() {
 struct termios termstate;
 if (tcgetattr(0, &termstate))
  return -1;
 termstate.c_lflag &= ~(0000002 | 0000010 | 0000100);
 termstate.c_cc[6] = 1;
 if (tcsetattr(0, 0, &termstate))
     return -1;
 setvbuf(stdout, ((void *)0), 2, 0);
 return 0;
}

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


decompiled_code:
__int64 __fastcall tty_set_winsize(int a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // eax
unsigned int v5; // ebx
__int16 v7[16]; // [rsp+8h] [rbp-20h] BYREF

v7[0] = a2;
v7[1] = a3;
v7[2] = 0;
v7[3] = 0;
v4 = ioctl(a1, 0x5414uLL, v7);
v5 = v4;
if ( *((int *)&cmd_options + 1) > 1 )
fprintf(stderr, "Setting winsize to %d x %d: %d\n", a2, a3, v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // eax
unsigned int v5; // ebx
__int16 v7[16]; // [rsp+8h] [rbp-20h] BYREF

v7[0] = a2;
v7[1] = a3;
v7[2] = 0;
v7[3] = 0;
v4 = ioctl(a1, 0x5414uLL, v7);
v5 = v4;
if ( *((int *)&cmd_options + 1) > 1 )
fprintf(stderr, "Setting winsize to %d x %d: %d\n", a2, a3, v4);
return v5;
}

original_code:
int tty_set_winsize(int fd, int rows, int cols) {
 int result;
 struct winsize size = {rows, cols, 0, 0};
 result = ioctl(fd, 0x5414, &size);
 do { if (cmd_options.verbose >= 2) fprintf(stderr, "Setting winsize to %d x %d: %d" "\n", rows, cols, result); } while (0);
 return result;
}

variable_types: fd int

variable_types: rows int

variable_types: cols int

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


decompiled_code:
__int64 __fastcall tty_get_winsize(int a1)
{
int *v2; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

if ( ioctl(a1, 0x5413uLL, &v3) && *((int *)&cmd_options + 1) > 0 )
{
v2 = _errno_location();
fprintf(stderr, "Unable to get window size %d\n", (unsigned int)*v2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int *v2; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

if ( ioctl(a1, 0x5413uLL, &v3) && *((int *)&cmd_options + 1) > 0 )
{
v2 = _errno_location();
fprintf(stderr, "Unable to get window size %d\n", (unsigned int)*v2);
}
return v3;
}

original_code:
struct winsize tty_get_winsize(int fd) {
 int result;
 struct winsize size;
 result = ioctl(fd, 0x5413, &size);
 if (result != 0)
  do { if (cmd_options.verbose >= 1) fprintf(stderr, "Unable to get window size %d" "\n", (*__errno_location ())); } while (0);
 return size;
}

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


usage

decompiled_code:
int usage()
{
puts("tachyon [-hHpqv] [-s shell] [-n name]");
puts("\t-h --help - Display this message");
puts("\t-p --predictor - Turn on character prediction");
puts("\t-v --verbose - increase log level (multiple allowed)");
puts("\t-s shell --shell=shell - command to run as shell for new buffer");
puts("\t-q --quiet - decrease log level (multiple allowed)");
return puts(" -n --name - Name to use for this session");
}

canonical_decompiled_code:
int func0()
{
puts("tachyon [-hHpqv] [-s shell] [-n name]");
puts("\t-h --help - Display this message");
puts("\t-p --predictor - Turn on character prediction");
puts("\t-v --verbose - increase log level (multiple allowed)");
puts("\t-s shell --shell=shell - command to run as shell for new buffer");
puts("\t-q --quiet - decrease log level (multiple allowed)");
return puts(" -n --name - Name to use for this session");
}

original_code:
static void usage(void) {
 printf("tachyon [-hHpqv] [-s shell] [-n name]\n");
 printf("	-h --help              - Display this message\n");
 printf("	-p --predictor         - Turn on character prediction\n");
 printf("	-v --verbose           - increase log level (multiple allowed)\n");
 printf("	-s shell --shell=shell - command to run as shell for new buffer\n");
 printf("	-q --quiet             - decrease log level (multiple allowed)\n");
 printf("        -n --name              - Name to use for this session\n");
}

canonical_original_code:
static void usage() {
 printf("tachyon [-hHpqv] [-s shell] [-n name]\n");
 printf("	-h --help              - Display this message\n");
 printf("	-p --predictor         - Turn on character prediction\n");
 printf("	-v --verbose           - increase log level (multiple allowed)\n");
 printf("	-s shell --shell=shell - command to run as shell for new buffer\n");
 printf("	-q --quiet             - decrease log level (multiple allowed)\n");
 printf("        -n --name              - Name to use for this session\n");
}


decompiled_code:
__int64 __fastcall process_args(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax

while ( 2 )
{
v2 = getopt_long(argc, argv, "hpqs:vn:", &parameters, 0LL);
if ( v2 == -1 )
return 0LL;
switch ( v2 )
{
case 'h':
usage();
result = 1LL;
break;
case 'n':
strncpy((char *)(unsigned int)((_DWORD)cmd_options + 1032), optarg, 0x80uLL);
continue;
case 'p':
*(_DWORD *)cmd_options = 1;
continue;
case 'q':
--*(_DWORD *)&cmd_options[4];
continue;
case 's':
strncpy((char *)(unsigned int)((_DWORD)cmd_options + 8), optarg, 0x400uLL);
continue;
case 'v':
++*(_DWORD *)&cmd_options[4];
continue;
default:
usage();
result = 2LL;
break;
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax

while ( 2 )
{
v2 = getopt_long(argc, argv, "hpqs:vn:", &parameters, 0LL);
if ( v2 == -1 )
return 0LL;
switch ( v2 )
{
case 'h':
func0();
result = 1LL;
break;
case 'n':
strncpy((char *)(unsigned int)((_DWORD)cmd_options + 1032), optarg, 0x80uLL);
continue;
case 'p':
*(_DWORD *)cmd_options = 1;
continue;
case 'q':
--*(_DWORD *)&cmd_options[4];
continue;
case 's':
strncpy((char *)(unsigned int)((_DWORD)cmd_options + 8), optarg, 0x400uLL);
continue;
case 'v':
++*(_DWORD *)&cmd_options[4];
continue;
default:
func0();
result = 2LL;
break;
}
break;
}
return result;
}

original_code:
static int process_args(int argn, char **args) {
 int flag;
 while ((flag = getopt_long(argn, args, "hpqs:vn:", parameters, ((void *)0))) != -1) {
  switch(flag) {
   case 'p':
    cmd_options.predict = 1;
    break;
   case 'v':
    cmd_options.verbose++;
    break;
   case 'q':
    cmd_options.verbose--;
    break;
   case 's':
    strncpy(cmd_options.new_buf_command, optarg,
     sizeof(cmd_options.new_buf_command));
    break;
   case 'n':
    strncpy(cmd_options.session_name, optarg,
     sizeof(cmd_options.session_name));
    break;
   case 'h':
    usage();
    return 1;
   default:
    usage();
    return 2;
  }
 }
 return 0;
}

variable_types: argn int

variable_types: flag int


decompiled_code:
__int64 set_defaults()
{
unsigned int v1; // eax

if ( !LOBYTE(cmd_options[2]) && (unsigned int)get_login_shell((char *)(unsigned int)((_DWORD)cmd_options + 8), 1024) )
return 1LL;
if ( cmd_options[1] <= 1 )
{
if ( LOBYTE(cmd_options[258]) )
return 0LL;
goto LABEL_8;
}
fprintf(stderr, "Shell is '%s'\n", (const char *)(unsigned int)((_DWORD)cmd_options + 8));
if ( !LOBYTE(cmd_options[258]) )
{
LABEL_8:
v1 = getpid();
snprintf((char *)(unsigned int)((_DWORD)cmd_options + 1032), 0x7FuLL, "tachyon-%d", v1);
}
if ( cmd_options[1] > 1 )
fprintf(stderr, "Session name is '%s'\n", (const char *)(unsigned int)((_DWORD)cmd_options + 1032));
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v1; // eax

if ( !LOBYTE(cmd_options[2]) && (unsigned int)func2((char *)(unsigned int)((_DWORD)cmd_options + 8), 1024) )
return 1LL;
if ( cmd_options[1] <= 1 )
{
if ( LOBYTE(cmd_options[258]) )
return 0LL;
goto LABEL_8;
}
fprintf(stderr, "Shell is '%s'\n", (const char *)(unsigned int)((_DWORD)cmd_options + 8));
if ( !LOBYTE(cmd_options[258]) )
{
LABEL_8:
v1 = getpid();
snprintf((char *)(unsigned int)((_DWORD)cmd_options + 1032), 0x7FuLL, "tachyon-%d", v1);
}
if ( cmd_options[1] > 1 )
fprintf(stderr, "Session name is '%s'\n", (const char *)(unsigned int)((_DWORD)cmd_options + 1032));
return 0LL;
}

original_code:
static int set_defaults(void) {
 int result;
 if (cmd_options.new_buf_command[0] == '\0') {
  result = get_login_shell(cmd_options.new_buf_command, sizeof(cmd_options.new_buf_command));
  if (result)
   return 1;
 }
 do { if (cmd_options.verbose >= 2) fprintf(stderr, "Shell is '%s'" "\n", cmd_options.new_buf_command); } while (0);
 if (cmd_options.session_name[0] == '\0') {
  snprintf(cmd_options.session_name, sizeof(cmd_options.session_name) - 1, "tachyon-%d",
    getpid());
 }
 do { if (cmd_options.verbose >= 2) fprintf(stderr, "Session name is '%s'" "\n", cmd_options.session_name); } while (0);
 return 0;
}

canonical_original_code:
static int set_defaults() {
 int result;
 if (cmd_options.new_buf_command[0] == '\0') {
  result = get_login_shell(cmd_options.new_buf_command, sizeof(cmd_options.new_buf_command));
  if (result)
   return 1;
 }
 do { if (cmd_options.verbose >= 2) fprintf(stderr, "Shell is '%s'" "\n", cmd_options.new_buf_command); } while (0);
 if (cmd_options.session_name[0] == '\0') {
  snprintf(cmd_options.session_name, sizeof(cmd_options.session_name) - 1, "tachyon-%d",
    getpid());
 }
 do { if (cmd_options.verbose >= 2) fprintf(stderr, "Session name is '%s'" "\n", cmd_options.session_name); } while (0);
 return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
unsigned int v6; // ebp
unsigned int v7; // eax
unsigned int v8; // eax
int *v9; // rax

v3 = process_args(argc, (char **)argv);
v4 = v3 - 1;
if ( !v3 )
{
v4 = set_defaults();
if ( v4 )
{
v4 = 1;
}
else
{
tty_save_termstate();
v6 = tty_configure_control_tty();
if ( cmd_options[1] > 1 )
{
v9 = _errno_location();
fprintf(stderr, "tty_configure_control_tty %d %d\n", v6, (unsigned int)*v9);
}
v7 = loop_init();
if ( cmd_options[1] > 1 )
fprintf(stderr, "loop_init %d\n", v7);
v8 = controller_init();
if ( cmd_options[1] > 1 )
fprintf(stderr, "register out %d\n", v8);
while ( run )
{
if ( !(unsigned __int8)loop_run() && cmd_options[1] >= 0 )
fwrite("Running the loop failed\n", 1uLL, 0x18uLL, stderr);
}
tty_restore_termstate();
}
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
unsigned int v6; // ebp
unsigned int v7; // eax
unsigned int v8; // eax
int *v9; // rax

v3 = func1(argc, (char **)argv);
v4 = v3 - 1;
if ( !v3 )
{
v4 = func3();
if ( v4 )
{
v4 = 1;
}
else
{
tty_save_termstate();
v6 = tty_configure_control_tty();
if ( cmd_options[1] > 1 )
{
v9 = _errno_location();
fprintf(stderr, "tty_configure_control_tty %d %d\n", v6, (unsigned int)*v9);
}
v7 = loop_init();
if ( cmd_options[1] > 1 )
fprintf(stderr, "loop_init %d\n", v7);
v8 = controller_init();
if ( cmd_options[1] > 1 )
fprintf(stderr, "register out %d\n", v8);
while ( run )
{
if ( !(unsigned __int8)loop_run() && cmd_options[1] >= 0 )
fwrite("Running the loop failed\n", 1uLL, 0x18uLL, stderr);
}
tty_restore_termstate();
}
}
return v4;
}

original_code:
int main(int argn, char **args) {
 int result;
 result = process_args(argn, args);
 if (result)
  return result - 1;
 if (set_defaults())
  return 1;
 tty_save_termstate();
 result = tty_configure_control_tty();
 do { if (cmd_options.verbose >= 2) fprintf(stderr, "tty_configure_control_tty %d %d" "\n", result, (*__errno_location ())); } while (0);
 result = loop_init();
 do { if (cmd_options.verbose >= 2) fprintf(stderr, "loop_init %d" "\n", result); } while (0);
 result = controller_init();
 do { if (cmd_options.verbose >= 2) fprintf(stderr, "register out %d" "\n", result); } while (0);
 while (run) {
  if (!loop_run())
   do { if (cmd_options.verbose >= 0) fprintf(stderr, "Running the loop failed" "\n"); } while (0);
 }
 tty_restore_termstate();
 return 0;
}

variable_types:
args
char **


original_code:
static void signal_handler(int signal, siginfo_t *siginfo, void *context) {
 int save_errno;
 if (signal < 0 || signal > (64 + 1))
  return;
 if (signal_callbacks[signal].handler) {
  signal_callbacks[signal].num_calls++;
  signal_callbacks[signal].siginfo = *siginfo;
 }
 save_errno = (*__errno_location ());
 write(signal_fd.write_fd, "1", 1);
 (*__errno_location ()) = save_errno;
}

canonical_original_code:
static void signal_handler(int signal, struct siginfo_t *siginfo, void *context) {
 int save_errno;
 if (signal < 0 || signal > (64 + 1))
  return;
 if (signal_callbacks[signal].handler) {
  signal_callbacks[signal].num_calls++;
  signal_callbacks[signal].siginfo = *siginfo;
 }
 save_errno = (*__errno_location ());
 write(signal_fd.write_fd, "1", 1);
 (*__errno_location ()) = save_errno;
}

variable_types: signal int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
context
void *

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }