ethernet

decompiled_code:
int __fastcall ethernet(struct ether_addr *addr, int a2)
{
unsigned int v2; // ebp
char *v3; // rax
char *v4; // rax
__int16 v5; // ax
int result; // eax

v2 = a2 - 30;
puts("\tEthernet Header");
v3 = ether_ntoa(addr);
printf("\t\tDest MAC: %s\n", v3);
v4 = ether_ntoa(addr + 1);
printf("\t\tSource MAC: %s\n", v4);
*(_WORD *)addr[2].ether_addr_octet = _bswap_16(*(_WORD *)addr[2].ether_addr_octet);
printf("\t\tType: ");
v5 = *(_WORD *)addr[2].ether_addr_octet;
if ( v5 == 2054 )
{
puts("ARP\n");
result = arp(&addr[2].ether_addr_octet[2], v2);
}
else if ( v5 == 2048 )
{
puts("IP\n");
result = nullsub_1(&addr[2].ether_addr_octet[2], v2);
}
else
{
result = puts("Unknown\n");
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(struct ether_addr *addr, int a2)
{
unsigned int v2; // ebp
char *v3; // rax
char *v4; // rax
__int16 v5; // ax
int result; // eax

v2 = a2 - 30;
puts("\tEthernet Header");
v3 = ether_ntoa(addr);
printf("\t\tDest MAC: %s\n", v3);
v4 = ether_ntoa(addr + 1);
printf("\t\tSource MAC: %s\n", v4);
*(_WORD *)addr[2].ether_addr_octet = func0(*(_WORD *)addr[2].ether_addr_octet);
printf("\t\tType: ");
v5 = *(_WORD *)addr[2].ether_addr_octet;
if ( v5 == 2054 )
{
puts("ARP\n");
result = arp(&addr[2].ether_addr_octet[2], v2);
}
else if ( v5 == 2048 )
{
puts("IP\n");
result = nullsub_1(&addr[2].ether_addr_octet[2], v2);
}
else
{
result = puts("Unknown\n");
}
return result;
}

original_code:
void ethernet(uint8_t *packetData, int packetLength)
{
 char *destination, *source;
 uint8_t *nextFrame;
 int nextFrameLength;
 struct EthernetFrameHeader *header = (struct EthernetFrameHeader *)packetData;
 printf("\tEthernet Header\n");
 destination = ether_ntoa((struct ether_addr *)header->destinationMAC);
 printf("\t\tDest MAC: %s\n", destination);
 source = ether_ntoa((struct ether_addr *)header->sourceMAC);
 printf("\t\tSource MAC: %s\n", source);
 header->etherType = ntohs(header->etherType);
 nextFrame = packetData+sizeof(struct EthernetFrameHeader);
 nextFrameLength = packetLength-(sizeof(struct EthernetFrameHeader)+sizeof(struct EthernetFrameTrailer));
 printf("\t\tType: ");
 if (header->etherType == 0x0806) {
  printf("ARP\n\n");
  arp(nextFrame, nextFrameLength);
 }
 else if (header->etherType == 0x0800) {
  printf("IP\n\n");
  ip(nextFrame, nextFrameLength);
 }
 else {
  printf("Unknown\n\n");
 }
}

canonical_original_code:
void ethernet(unsigned char *packetData, int packetLength)
{
 char *destination; char *source;
 unsigned char *nextFrame;
 int nextFrameLength;
 struct EthernetFrameHeader *header = (struct EthernetFrameHeader *)packetData;
 printf("\tEthernet Header\n");
 destination = ether_ntoa((struct ether_addr *)header->destinationMAC);
 printf("\t\tDest MAC: %s\n", destination);
 source = ether_ntoa((struct ether_addr *)header->sourceMAC);
 printf("\t\tSource MAC: %s\n", source);
 header->etherType = ntohs(header->etherType);
 nextFrame = packetData+sizeof(struct EthernetFrameHeader);
 nextFrameLength = packetLength-(sizeof(struct EthernetFrameHeader)+sizeof(struct EthernetFrameTrailer));
 printf("\t\tType: ");
 if (header->etherType == 0x0806) {
  printf("ARP\n\n");
  arp(nextFrame, nextFrameLength);
 }
 else if (header->etherType == 0x0800) {
  printf("IP\n\n");
  ip(nextFrame, nextFrameLength);
 }
 else {
  printf("Unknown\n\n");
 }
}

variable_types:
destination
char *

variable_types:
source
char *

variable_types:
nextFrame
unsigned char *

variable_types: nextFrameLength int

variable_types: struct EthernetFrameHeader { unsigned char destinationMAC[6]; unsigned char sourceMAC[6]; unsigned short etherType; } *

user_defined_types: struct EthernetFrameTrailer { unsigned char frameCheckSequence[4]; unsigned char interframeGap[12]; }


main

canonical_name: main

repo: jtremaine/mathbot

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

v3 = integralbot(0LL, argv, envp);
printf("%d", v3);
return 0;
}

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

v3 = func7(0LL, argv, envp);
printf("%d", v3);
return 0;
}

original_code:
int main(void)
{
  int ret;
  ret = integralbot(0);
  printf("%d", ret);
  return 0;
}

canonical_original_code:
int main()
{
  int ret;
  ret = integralbot(0);
  printf("%d", ret);
  return 0;
}

variable_types: ret int

return_type: int


integralbot

decompiled_code:
__int64 __fastcall integralbot(int a1)
{
return (unsigned int)(a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return (unsigned int)(a1 + 1);
}

original_code:
int
integralbot(int param)
{
  return param + 1;
}

variable_types: param int


interpol

original_code:
int
interpol(const double *x, const double *fx, int n, double *z, double *pz,
  int m)
{
  double *coef;
  double *table;
  double term;
  int error, i, j, k;
  coef = ((void *)0);
  table = ((void *)0);
  error = 0;
  term = 0.0;
  coef = malloc(n * sizeof(double));
  if (coef == ((void *)0)) {
    error = -1;
    goto out;
  }
  table = malloc(n * sizeof(double));
  if (coef == ((void *)0)) {
    error = -1;
    goto out;
  }
  memcpy(table, x, n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < i - n; j++) {
      table[j] = (table[j + 1] - table[j]) / (x[j] - x[i]);
    }
    coef[i] = table[0];
  }
  for (i=0; i < m; i++) {
    pz[i] = coef[0];
    for (j=1; j < n; j++) {
      term = coef[j];
      for (k = 0; k < j; k++) {
 term = term * (z[i] - x[k]);
      }
      pz[i] += term;
    }
  }
 out:
  if (coef != ((void *)0))
    free(coef);
  if (table != ((void *)0))
    free(table);
  return error;
}

canonical_original_code:
int interpol(double *x, double *fx, int n, double *z, double *pz, int m)
{
  double *coef;
  double *table;
  double term;
  int error; int i; int j; int k;
  coef = ((void *)0);
  table = ((void *)0);
  error = 0;
  term = 0.0;
  coef = malloc(n * sizeof(double));
  if (coef == ((void *)0)) {
    error = -1;
    goto out;
  }
  table = malloc(n * sizeof(double));
  if (coef == ((void *)0)) {
    error = -1;
    goto out;
  }
  memcpy(table, x, n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < i - n; j++) {
      table[j] = (table[j + 1] - table[j]) / (x[j] - x[i]);
    }
    coef[i] = table[0];
  }
  for (i=0; i < m; i++) {
    pz[i] = coef[0];
    for (j=1; j < n; j++) {
      term = coef[j];
      for (k = 0; k < j; k++) {
 term = term * (z[i] - x[k]);
      }
      pz[i] += term;
    }
  }
 out:
  if (coef != ((void *)0))
    free(coef);
  if (table != ((void *)0))
    free(table);
  return error;
}

variable_types:
x
double *

variable_types:
fx
double *

variable_types: n int

variable_types:
z
double *

variable_types:
pz
double *

variable_types: m int

variable_types:
coef
double *

variable_types:
table
double *

variable_types: term double

variable_types: error int

variable_types: i int

variable_types: j int

variable_types: k int


repo: jtsui/leveldb-daemon

decompiled_code:
void *simplehttp_stats_init()
{
void *v0; // rax
int v1; // ebx
void *result; // rax

v0 = malloc(8000LL * callback_count);
v1 = callback_count;
stats = v0;
if ( 1000 * callback_count > 0 )
memset(v0, 255, 8000LL * callback_count);
stats_idx = calloc(1uLL, 4LL * v1);
result = calloc(1uLL, 8LL * callback_count);
stats_counts = result;
return result;
}

canonical_decompiled_code:
void *func1()
{
void *v0; // rax
int v1; // ebx
void *result; // rax

v0 = malloc(8000LL * callback_count);
v1 = callback_count;
stats = v0;
if ( 1000 * callback_count > 0 )
memset(v0, 255, 8000LL * callback_count);
stats_idx = calloc(1uLL, 4LL * v1);
result = calloc(1uLL, 8LL * callback_count);
stats_counts = result;
return result;
}

original_code:
void simplehttp_stats_init()
{
    int i;
    stats = malloc(1000 * callback_count * sizeof(int64_t));
    for (i = 0; i < (1000 * callback_count); i++) {
        stats[i] = -1;
    }
    stats_idx = calloc(1, callback_count * sizeof(int));
    stats_counts = calloc(1, callback_count * sizeof(uint64_t));
}

canonical_original_code:
void simplehttp_stats_init()
{
    int i;
    stats = malloc(1000 * callback_count * sizeof(long));
    for (i = 0; i < (1000 * callback_count); i++) {
        stats[i] = -1;
    }
    stats_idx = calloc(1, callback_count * sizeof(int));
    stats_counts = calloc(1, callback_count * sizeof(unsigned long));
}

return_type: void


decompiled_code:
void simplehttp_stats_destruct()
{
free(stats);
free(stats_idx);
free(stats_counts);
}

canonical_decompiled_code:
void func2()
{
free(stats);
free(stats_idx);
free(stats_counts);
}


decompiled_code:
void *simplehttp_stats_new()
{
return malloc(0x30uLL);
}

canonical_decompiled_code:
void *func3()
{
return malloc(0x30uLL);
}

original_code:
struct simplehttp_stats *simplehttp_stats_new()
{
    struct simplehttp_stats *st;
    st = malloc(sizeof(struct simplehttp_stats));
    return st;
}

variable_types: struct simplehttp_stats { unsigned long requests; unsigned long *stats_counts; unsigned long *average_requests; unsigned long *ninety_five_percents; char **stats_labels; int callback_count; } *


decompiled_code:
void __fastcall simplehttp_stats_free(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
_QWORD *v5; // rdi
__int64 v6; // rbx
void *v7; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 3);
if ( v4 )
free(v4);
v5 = (_QWORD *)*((_QWORD *)ptr + 4);
if ( v5 )
{
if ( *((int *)ptr + 10) > 0 )
{
v6 = 0LL;
do
{
v7 = (void *)v5[v6++];
free(v7);
v5 = (_QWORD *)*((_QWORD *)ptr + 4);
}
while ( *((_DWORD *)ptr + 10) > (int)v6 );
}
free(v5);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
_QWORD *v5; // rdi
__int64 v6; // rbx
void *v7; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 3);
if ( v4 )
free(v4);
v5 = (_QWORD *)*((_QWORD *)ptr + 4);
if ( v5 )
{
if ( *((int *)ptr + 10) > 0 )
{
v6 = 0LL;
do
{
v7 = (void *)v5[v6++];
free(v7);
v5 = (_QWORD *)*((_QWORD *)ptr + 4);
}
while ( *((_DWORD *)ptr + 10) > (int)v6 );
}
free(v5);
}
free(ptr);
}
}

original_code:
void simplehttp_stats_free(struct simplehttp_stats *st)
{
    int i;
    if (st) {
        if (st->stats_counts) {
            free(st->stats_counts);
        }
        if (st->average_requests) {
            free(st->average_requests);
        }
        if (st->ninety_five_percents) {
            free(st->ninety_five_percents);
        }
        if (st->stats_labels) {
            for (i = 0; i < st->callback_count; i++) {
                free(st->stats_labels[i]);
            }
            free(st->stats_labels);
        }
        free(st);
    }
}

user_defined_types: struct simplehttp_stats { unsigned long requests; unsigned long *stats_counts; unsigned long *average_requests; unsigned long *ninety_five_percents; char **stats_labels; int callback_count; }


decompiled_code:
unsigned __int64 __fastcall simplehttp_stats_get(__int64 a1)
{
__int64 v2; // rax
void *v3; // rax
size_t v4; // rbp
const void *v5; // rsi
void *v6; // rax
__int64 v7; // rsi
unsigned __int64 result; // rax
__int64 v9; // rbp
__int64 v10; // rbx
__int64 v11; // rsi
char *v12; // rdi
_QWORD *v13; // rdx
unsigned __int64 *v14; // r13

*(_QWORD *)a1 = request_count;
v2 = callback_count;
*(_DWORD *)(a1 + 40) = callback_count;
v3 = malloc(8 * v2);
v4 = callback_count;
v5 = stats_counts;
*(_QWORD *)(a1 + 8) = v3;
v4 *= 8LL;
memcpy(v3, v5, v4);
v6 = calloc(1uLL, v4);
v7 = callback_count;
*(_QWORD *)(a1 + 16) = v6;
*(_QWORD *)(a1 + 24) = calloc(1uLL, 8 * v7);
*(_QWORD *)(a1 + 32) = simplehttp_callback_names();
result = callback_count;
if ( callback_count > 0 )
{
v9 = 0LL;
v10 = 0LL;
do
{
v11 = 0LL;
result = 0LL;
v12 = (char *)stats + v9;
v13 = (char *)stats + v9;
while ( *v13 != -1LL )
{
v11 = (unsigned int)(v11 + 1);
result += *v13++;
if ( (_DWORD)v11 == 1000 )
goto LABEL_9;
}
if ( !(_DWORD)v11 )
goto LABEL_7;
LABEL_9:
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v10) = result / (int)v11;
v14 = (unsigned __int64 *)(*(_QWORD *)(a1 + 24) + 8 * v10);
result = ninety_five_percent(v12, v11, result % (int)v11);
*v14 = result;
LABEL_7:
++v10;
v9 += 8000LL;
}
while ( callback_count > (int)v10 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(__int64 a1)
{
__int64 v2; // rax
void *v3; // rax
size_t v4; // rbp
const void *v5; // rsi
void *v6; // rax
__int64 v7; // rsi
unsigned __int64 result; // rax
__int64 v9; // rbp
__int64 v10; // rbx
__int64 v11; // rsi
char *v12; // rdi
_QWORD *v13; // rdx
unsigned __int64 *v14; // r13

*(_QWORD *)a1 = request_count;
v2 = callback_count;
*(_DWORD *)(a1 + 40) = callback_count;
v3 = malloc(8 * v2);
v4 = callback_count;
v5 = stats_counts;
*(_QWORD *)(a1 + 8) = v3;
v4 *= 8LL;
memcpy(v3, v5, v4);
v6 = calloc(1uLL, v4);
v7 = callback_count;
*(_QWORD *)(a1 + 16) = v6;
*(_QWORD *)(a1 + 24) = calloc(1uLL, 8 * v7);
*(_QWORD *)(a1 + 32) = simplehttp_callback_names();
result = callback_count;
if ( callback_count > 0 )
{
v9 = 0LL;
v10 = 0LL;
do
{
v11 = 0LL;
result = 0LL;
v12 = (char *)stats + v9;
v13 = (char *)stats + v9;
while ( *v13 != -1LL )
{
v11 = (unsigned int)(v11 + 1);
result += *v13++;
if ( (_DWORD)v11 == 1000 )
goto LABEL_9;
}
if ( !(_DWORD)v11 )
goto LABEL_7;
LABEL_9:
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v10) = result / (int)v11;
v14 = (unsigned __int64 *)(*(_QWORD *)(a1 + 24) + 8 * v10);
result = ninety_five_percent(v12, v11, result % (int)v11);
*v14 = result;
LABEL_7:
++v10;
v9 += 8000LL;
}
while ( callback_count > (int)v10 );
}
return result;
}

original_code:
void simplehttp_stats_get(struct simplehttp_stats *st)
{
    uint64_t request_total;
    int i, j, c, request_array_end;
    st->requests = request_count;
    st->callback_count = callback_count;
    st->stats_counts = malloc(callback_count * sizeof(uint64_t));
    memcpy(st->stats_counts, stats_counts, callback_count * sizeof(uint64_t));
    st->average_requests = calloc(1, callback_count * sizeof(uint64_t));
    st->ninety_five_percents = calloc(1, callback_count * sizeof(uint64_t));
    st->stats_labels = simplehttp_callback_names();
    for (i = 0; i < callback_count; i++) {
        request_total = 0;
        for (j = (i * 1000), request_array_end = j + 1000, c = 0;
                (j < request_array_end) && (stats[j] != -1); j++, c++) {
            request_total += stats[j];
        }
        if (c) {
            st->average_requests[i] = request_total / c;
            st->ninety_five_percents[i] = ninety_five_percent(stats + (i * 1000), c);
        }
    }
}

canonical_original_code:
void simplehttp_stats_get(struct simplehttp_stats *st)
{
    unsigned long request_total;
    int i; int j; int c; int request_array_end;
    st->requests = request_count;
    st->callback_count = callback_count;
    st->stats_counts = malloc(callback_count * sizeof(unsigned long));
    memcpy(st->stats_counts, stats_counts, callback_count * sizeof(unsigned long));
    st->average_requests = calloc(1, callback_count * sizeof(unsigned long));
    st->ninety_five_percents = calloc(1, callback_count * sizeof(unsigned long));
    st->stats_labels = simplehttp_callback_names();
    for (i = 0; i < callback_count; i++) {
        request_total = 0;
        for (j = (i * 1000), request_array_end = j + 1000, c = 0;
                (j < request_array_end) && (stats[j] != -1); j++, c++) {
            request_total += stats[j];
        }
        if (c) {
            st->average_requests[i] = request_total / c;
            st->ninety_five_percents[i] = ninety_five_percent(stats + (i * 1000), c);
        }
    }
}

variable_types: c int


decompiled_code:
void __fastcall init_async_connection_pool(int a1)
{
request_logging = a1;
connection_pool = 0LL;
*(&connection_pool + 1) = &connection_pool;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
request_logging = a1;
connection_pool = 0LL;
*(&connection_pool + 1) = &connection_pool;
}

original_code:
void init_async_connection_pool(int enable_request_logging)
{
    request_logging = enable_request_logging;
    do { (&connection_pool)->tqh_first = ((void *)0); (&connection_pool)->tqh_last = &(&connection_pool)->tqh_first; } while (0);
}


decompiled_code:
__int64 __fastcall get_uid(const char *a1)
{
struct passwd *v1; // rax
__int64 result; // rax

v1 = getpwnam(a1);
if ( v1 )
result = v1->pw_uid;
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
struct passwd *v1; // rax
__int64 result; // rax

v1 = getpwnam(a1);
if ( v1 )
result = v1->pw_uid;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int get_uid(char *user)
{
    int retcode;
    struct passwd *pw;
    pw = getpwnam(user);
    if (pw == ((void *)0)) {
        retcode = -1;
    } else {
        retcode = (unsigned) pw->pw_uid;
    }
    return retcode;
}

canonical_original_code:
int get_uid(char *user)
{
    int retcode;
    struct passwd *pw;
    pw = getpwnam(user);
    if (pw == ((void *)0)) {
        retcode = -1;
    } else {
        retcode = (unsigned int) pw->pw_uid;
    }
    return retcode;
}

variable_types:
user
char *

variable_types: retcode int

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
__int64 __fastcall get_gid(const char *a1)
{
struct group *v1; // rax
__int64 result; // rax

v1 = getgrnam(a1);
if ( v1 )
result = v1->gr_gid;
else
result = 0xFFFFFFFFLL;
return result;
}

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

v1 = getgrnam(a1);
if ( v1 )
result = v1->gr_gid;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int get_gid(char *group)
{
    int retcode;
    struct group *grent;
    grent = getgrnam(group);
    if (grent == ((void *)0)) {
        retcode = -1;
    } else {
        retcode = grent->gr_gid;
    }
    return retcode;
}

variable_types:
group
char *

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *


decompiled_code:
__int64 __fastcall get_user_gid(const char *a1)
{
struct passwd *v1; // rax
__int64 result; // rax

v1 = getpwnam(a1);
if ( v1 )
result = v1->pw_gid;
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
struct passwd *v1; // rax
__int64 result; // rax

v1 = getpwnam(a1);
if ( v1 )
result = v1->pw_gid;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int get_user_gid(char *user)
{
    int retcode;
    struct passwd *pw;
    pw = getpwnam(user);
    if (pw == ((void *)0)) {
        retcode = -1;
    } else {
        retcode = pw->pw_gid;
    }
    return retcode;
}

user_defined_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; }


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

if ( !current_base )
result = event_init();
callbacks = 0LL;
*(&callbacks + 1) = &callbacks;
simplehttp_reqs = 0LL;
*(&simplehttp_reqs + 1) = (__int64)&simplehttp_reqs;
return result;
}

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

if ( !current_base )
result = event_init();
callbacks = 0LL;
*(&callbacks + 1) = &callbacks;
simplehttp_reqs = 0LL;
*(&simplehttp_reqs + 1) = (__int64)&simplehttp_reqs;
return result;
}

original_code:
void simplehttp_init()
{
    if (!current_base) {
        event_init();
    }
    do { (&callbacks)->tqh_first = ((void *)0); (&callbacks)->tqh_last = &(&callbacks)->tqh_first; } while (0);
    do { (&simplehttp_reqs)->tqh_first = ((void *)0); (&simplehttp_reqs)->tqh_last = &(&simplehttp_reqs)->tqh_first; } while (0);
}


decompiled_code:
__int64 define_simplehttp_options()
{
option_define_str("address", 0LL, "0.0.0.0", 0LL, 0LL, "address to listen on");
option_define_int("port", 0LL, 8080LL, 0LL, 0LL, "port to listen on");
option_define_bool("enable_logging", 0LL, 0LL, 0LL, 0LL, "request logging");
option_define_bool("daemon", 0LL, 0LL, 0LL, 0LL, "daemonize process");
option_define_str("root", 0LL, 0LL, 0LL, 0LL, "chdir and run from this directory");
option_define_str("user", 0LL, 0LL, 0LL, 0LL, "run as this user");
return option_define_str("group", 0LL, 0LL, 0LL, 0LL, "run as this group");
}

canonical_decompiled_code:
__int64 func10()
{
option_define_str("address", 0LL, "0.0.0.0", 0LL, 0LL, "address to listen on");
option_define_int("port", 0LL, 8080LL, 0LL, 0LL, "port to listen on");
option_define_bool("enable_logging", 0LL, 0LL, 0LL, 0LL, "request logging");
option_define_bool("daemon", 0LL, 0LL, 0LL, 0LL, "daemonize process");
option_define_str("root", 0LL, 0LL, 0LL, 0LL, "chdir and run from this directory");
option_define_str("user", 0LL, 0LL, 0LL, 0LL, "run as this user");
return option_define_str("group", 0LL, 0LL, 0LL, 0LL, "run as this group");
}

original_code:
void define_simplehttp_options()
{
    option_define_str("address", OPT_OPTIONAL, "0.0.0.0", ((void *)0), ((void *)0), "address to listen on");
    option_define_int("port", OPT_OPTIONAL, 8080, ((void *)0), ((void *)0), "port to listen on");
    option_define_bool("enable_logging", OPT_OPTIONAL, 0, ((void *)0), ((void *)0), "request logging");
    option_define_bool("daemon", OPT_OPTIONAL, 0, ((void *)0), ((void *)0), "daemonize process");
    option_define_str("root", OPT_OPTIONAL, ((void *)0), ((void *)0), ((void *)0), "chdir and run from this directory");
    option_define_str("user", OPT_OPTIONAL, ((void *)0), ((void *)0), ((void *)0), "run as this user");
    option_define_str("group", OPT_OPTIONAL, ((void *)0), ((void *)0), ((void *)0), "run as this group");
}


decompiled_code:
__int64 simplehttp_listen()
{
const char *v0; // r12
unsigned int v1; // er13
int v2; // ebx
const char *v3; // r14
const char *v4; // rbp
const char *v5; // r15
__gid_t v6; // ebx
__pid_t v8; // eax
int *v9; // rax
char *v10; // rax
__uid_t uid; // [rsp+Ch] [rbp-3Ch]

v0 = (const char *)option_get_str("address");
v1 = option_get_int("port");
v2 = option_get_int("daemon");
v3 = (const char *)option_get_str("root");
v4 = (const char *)option_get_str("user");
v5 = (const char *)option_get_str("group");
simplehttp_logging = option_get_int("enable_logging");
if ( !v2 )
goto LABEL_2;
v8 = fork();
if ( v8 < 0 )
return 0LL;
if ( v8 )
exit(0);
umask(0);
if ( setsid() >= 0 )
{
LABEL_2:
if ( v4 )
{
uid = get_uid(v4);
v6 = get_user_gid(v4);
if ( !uid )
err(1, "invalid user");
}
else
{
uid = 0;
v6 = 0;
}
if ( v5 )
v6 = get_gid(v5);
if ( v3 && (chroot(v3) || chdir("/")) )
{
v9 = _errno_location();
v10 = strerror(*v9);
err(1, v10);
}
if ( !getuid() )
{
if ( v4 )
{
if ( initgroups(v4, v6) )
err(1, "initgroups() failed");
}
else if ( setgroups(0LL, 0LL) )
{
err(1, "setgroups() failed");
}
if ( getgid() != v6 && setgid(v6) )
err(1, "setgid() failed");
if ( setuid(uid) )
err(1, "setuid() failed");
}
signal(2, termination_handler);
signal(3, termination_handler);
signal(15, termination_handler);
event_set(&pipe_ev, 13LL, 24LL, ignore_cb, 0LL);
event_add(&pipe_ev, 0LL);
simplehttp_stats_init();
httpd = evhttp_start(v0, (unsigned __int16)v1);
if ( httpd )
{
printf("listening on %s:%d\n", v0, v1);
evhttp_set_gencb(httpd, generic_request_handler, 0LL);
return 1LL;
}
printf("could not bind to %s:%d\n", v0, v1);
return 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
const char *v0; // r12
unsigned int v1; // er13
int v2; // ebx
const char *v3; // r14
const char *v4; // rbp
const char *v5; // r15
__gid_t v6; // ebx
__pid_t v8; // eax
int *v9; // rax
char *v10; // rax
__uid_t uid; // [rsp+Ch] [rbp-3Ch]

v0 = (const char *)option_get_str("address");
v1 = option_get_int("port");
v2 = option_get_int("daemon");
v3 = (const char *)option_get_str("root");
v4 = (const char *)option_get_str("user");
v5 = (const char *)option_get_str("group");
simplehttp_logging = option_get_int("enable_logging");
if ( !v2 )
goto LABEL_2;
v8 = fork();
if ( v8 < 0 )
return 0LL;
if ( v8 )
exit(0);
umask(0);
if ( setsid() >= 0 )
{
LABEL_2:
if ( v4 )
{
uid = func3(v4);
v6 = func5(v4);
if ( !uid )
err(1, "invalid user");
}
else
{
uid = 0;
v6 = 0;
}
if ( v5 )
v6 = func4(v5);
if ( v3 && (chroot(v3) || chdir("/")) )
{
v9 = _errno_location();
v10 = strerror(*v9);
err(1, v10);
}
if ( !getuid() )
{
if ( v4 )
{
if ( initgroups(v4, v6) )
err(1, "initgroups() failed");
}
else if ( setgroups(0LL, 0LL) )
{
err(1, "setgroups() failed");
}
if ( getgid() != v6 && setgid(v6) )
err(1, "setgid() failed");
if ( setuid(uid) )
err(1, "setuid() failed");
}
signal(2, termination_handler);
signal(3, termination_handler);
signal(15, termination_handler);
event_set(&pipe_ev, 13LL, 24LL, ignore_cb, 0LL);
event_add(&pipe_ev, 0LL);
simplehttp_stats_init();
httpd = evhttp_start(v0, (unsigned __int16)v1);
if ( httpd )
{
printf("listening on %s:%d\n", v0, v1);
evhttp_set_gencb(httpd, generic_request_handler, 0LL);
return 1LL;
}
printf("could not bind to %s:%d\n", v0, v1);
return 0LL;
}
return 0LL;
}

original_code:
int simplehttp_listen()
{
    uid_t uid = 0;
    gid_t gid = 0;
    pid_t pid, sid;
    int (*__errno_location ());
    char *address = option_get_str("address");
    int port = option_get_int("port");
    int daemon = option_get_int("daemon");
    char *root = option_get_str("root");
    char *user = option_get_str("user");
    char *group = option_get_str("group");
    simplehttp_logging = option_get_int("enable_logging");
    if (daemon) {
        pid = fork();
        if (pid < 0) {
            return 0;
        } else if (pid > 0) {
            exit(0);
        }
        umask(0);
        sid = setsid();
        if (sid < 0) {
            return 0;
        }
    }
    if (user != ((void *)0)) {
        uid = get_uid(user);
        gid = get_user_gid(user);
        if (uid < 0) {
            uid = atoi(user);
            user = ((void *)0);
        }
        if (uid == 0) {
            err(1, "invalid user");
        }
    }
    if (group != ((void *)0)) {
        gid = get_gid(group);
        if (gid < 0) {
            gid = atoi(group);
            if (gid == 0) {
                err(1, "invalid group");
            }
        }
    }
    if (root != ((void *)0)) {
        if (chroot(root) != 0) {
            err(1, strerror((*__errno_location ())));
        }
        if (chdir("/") != 0) {
            err(1, strerror((*__errno_location ())));
        }
    }
    if (getuid() == 0) {
        if (user != ((void *)0)) {
            if (initgroups(user, (int) gid) != 0) {
                err(1, "initgroups() failed");
            }
        } else {
            if (setgroups(0, ((void *)0)) != 0) {
                err(1, "setgroups() failed");
            }
        }
        if (gid != getgid() && setgid(gid) != 0) {
            err(1, "setgid() failed");
        }
        if (setuid(uid) != 0) {
            err(1, "setuid() failed");
        }
    }
    signal(2, termination_handler);
    signal(3, termination_handler);
    signal(15, termination_handler);
    event_set((&pipe_ev), (13), 0x08|0x10, (ignore_cb), (((void *)0)));
    event_add((&pipe_ev), (((void *)0)));
    simplehttp_stats_init();
    httpd = evhttp_start(address, port);
    if (!httpd) {
        printf("could not bind to %s:%d\n", address, port);
        return 0;
    }
    printf("listening on %s:%d\n", address, port);
    evhttp_set_gencb(httpd, generic_request_handler, ((void *)0));
    return 1;
}

canonical_original_code:
int simplehttp_listen()
{
    unsigned int uid = 0;
    unsigned int gid = 0;
    int pid; int sid;
    int *__errno_location();
    char *address = option_get_str("address");
    int port = option_get_int("port");
    int daemon = option_get_int("daemon");
    char *root = option_get_str("root");
    char *user = option_get_str("user");
    char *group = option_get_str("group");
    simplehttp_logging = option_get_int("enable_logging");
    if (daemon) {
        pid = fork();
        if (pid < 0) {
            return 0;
        } else if (pid > 0) {
            exit(0);
        }
        umask(0);
        sid = setsid();
        if (sid < 0) {
            return 0;
        }
    }
    if (user != ((void *)0)) {
        uid = get_uid(user);
        gid = get_user_gid(user);
        if (uid < 0) {
            uid = atoi(user);
            user = ((void *)0);
        }
        if (uid == 0) {
            err(1, "invalid user");
        }
    }
    if (group != ((void *)0)) {
        gid = get_gid(group);
        if (gid < 0) {
            gid = atoi(group);
            if (gid == 0) {
                err(1, "invalid group");
            }
        }
    }
    if (root != ((void *)0)) {
        if (chroot(root) != 0) {
            err(1, strerror((*__errno_location ())));
        }
        if (chdir("/") != 0) {
            err(1, strerror((*__errno_location ())));
        }
    }
    if (getuid() == 0) {
        if (user != ((void *)0)) {
            if (initgroups(user, (int) gid) != 0) {
                err(1, "initgroups() failed");
            }
        } else {
            if (setgroups(0, ((void *)0)) != 0) {
                err(1, "setgroups() failed");
            }
        }
        if (gid != getgid() && setgid(gid) != 0) {
            err(1, "setgid() failed");
        }
        if (setuid(uid) != 0) {
            err(1, "setuid() failed");
        }
    }
    signal(2, termination_handler);
    signal(3, termination_handler);
    signal(15, termination_handler);
    event_set((&pipe_ev), (13), 0x08|0x10, (ignore_cb), (((void *)0)));
    event_add((&pipe_ev), (((void *)0)));
    simplehttp_stats_init();
    httpd = evhttp_start(address, port);
    if (!httpd) {
        printf("could not bind to %s:%d\n", address, port);
        return 0;
    }
    printf("listening on %s:%d\n", address, port);
    evhttp_set_gencb(httpd, generic_request_handler, ((void *)0));
    return 1;
}

variable_types:
uid
unsigned int

variable_types:
gid
unsigned int

variable_types: pid int

variable_types: sid int

variable_types:
address
char *

variable_types: port int

variable_types: daemon int

variable_types:
root
char *


decompiled_code:
// attributes: thunk
__int64 simplehttp_run()
{
return event_dispatch();
}

canonical_decompiled_code:
__int64 func12()
{
return event_dispatch();
}

original_code:
void simplehttp_run()
{
    event_dispatch();
}


decompiled_code:
__int64 simplehttp_main()
{
int v0; // er8
__int64 result; // rax

v0 = simplehttp_listen();
result = 1LL;
if ( v0 )
{
simplehttp_run();
simplehttp_free();
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
int v0; // er8
__int64 result; // rax

v0 = func11();
result = 1LL;
if ( v0 )
{
func12();
func8();
result = 0LL;
}
return result;
}

original_code:
int simplehttp_main()
{
    if (!simplehttp_listen()) {
        return 1;
    }
    simplehttp_run();
    simplehttp_free();
    return 0;
}


decompiled_code:
void ignore_cb()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void ignore_cb(int sig, short what, void *arg)
{
}

variable_types: sig int

variable_types: what short

variable_types:
arg
void *


decompiled_code:
// attributes: thunk
void __fastcall termination_handler(int a1)
{
event_loopbreak(a1);
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
event_loopbreak(a1);
}

original_code:
void termination_handler(int signum)
{
    event_loopbreak();
}

variable_types: signum int


decompiled_code:
// attributes: thunk
void __fastcall pubsubclient_termination_handler(int a1)
{
event_loopbreak(a1);
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
event_loopbreak(a1);
}

original_code:
void pubsubclient_termination_handler(int signum)
{
    event_loopbreak();
}


decompiled_code:
__int64 pubsubclient_connect()
{
unsigned int v0; // er12
__int64 v1; // rax
__int64 v2; // rdi

fprintf(
stdout,
"CONNECTING TO SOURCE http://%s:%d%s\n",
*((const char **)data + 3),
*((unsigned int *)data + 8),
*((const char **)data + 5));
v0 = chunked;
if ( chunked )
{
if ( evhttp_source_connection )
((void (*)(void))evhttp_connection_free)();
evhttp_source_connection = evhttp_connection_new(*((_QWORD *)data + 3), *((unsigned __int16 *)data + 16));
if ( !evhttp_source_connection )
{
v0 = 0;
fprintf(
stderr,
"ERROR: evhttp_connection_new() failed for %s:%d\n",
*((const char **)data + 3),
*((unsigned int *)data + 8));
return v0;
}
v1 = evhttp_request_new(pubsubclient_source_request_done, data);
v2 = *(_QWORD *)(v1 + 40);
evhttp_source_request = v1;
evhttp_add_header(v2, "Host", *((_QWORD *)data + 3));
evhttp_request_set_chunked_cb(evhttp_source_request, pubsubclient_source_callback);
if ( (unsigned int)evhttp_make_request(evhttp_source_connection, evhttp_source_request, 1LL, *((_QWORD *)data + 5)) == -1 )
{
v0 = 0;
fprintf(stderr, "ERROR: evhttp_make_request() failed for %s\n", *((const char **)data + 5));
evhttp_connection_free(evhttp_source_connection);
return v0;
}
}
else
{
if ( stream_request )
free_stream_request();
stream_request = new_stream_request(
"GET",
*((_QWORD *)data + 3),
*((unsigned int *)data + 8),
*((_QWORD *)data + 5),
0LL,
pubsubclient_source_readcb,
pubsubclient_errorcb,
data);
if ( !stream_request )
{
fprintf(
stderr,
"ERROR: new_stream_request() failed for %s:%d%s\n",
*((const char **)data + 3),
*((unsigned int *)data + 8),
*((const char **)data + 5));
return v0;
}
}
return 1;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // er12
__int64 v1; // rax
__int64 v2; // rdi

fprintf(
stdout,
"CONNECTING TO SOURCE http://%s:%d%s\n",
*((const char **)data + 3),
*((unsigned int *)data + 8),
*((const char **)data + 5));
v0 = chunked;
if ( chunked )
{
if ( evhttp_source_connection )
((void (*)(void))evhttp_connection_free)();
evhttp_source_connection = evhttp_connection_new(*((_QWORD *)data + 3), *((unsigned __int16 *)data + 16));
if ( !evhttp_source_connection )
{
v0 = 0;
fprintf(
stderr,
"ERROR: evhttp_connection_new() failed for %s:%d\n",
*((const char **)data + 3),
*((unsigned int *)data + 8));
return v0;
}
v1 = evhttp_request_new(pubsubclient_source_request_done, data);
v2 = *(_QWORD *)(v1 + 40);
evhttp_source_request = v1;
evhttp_add_header(v2, "Host", *((_QWORD *)data + 3));
evhttp_request_set_chunked_cb(evhttp_source_request, pubsubclient_source_callback);
if ( (unsigned int)evhttp_make_request(evhttp_source_connection, evhttp_source_request, 1LL, *((_QWORD *)data + 5)) == -1 )
{
v0 = 0;
fprintf(stderr, "ERROR: evhttp_make_request() failed for %s\n", *((const char **)data + 5));
evhttp_connection_free(evhttp_source_connection);
return v0;
}
}
else
{
if ( stream_request )
free_stream_request();
stream_request = new_stream_request(
"GET",
*((_QWORD *)data + 3),
*((unsigned int *)data + 8),
*((_QWORD *)data + 5),
0LL,
pubsubclient_source_readcb,
pubsubclient_errorcb,
data);
if ( !stream_request )
{
fprintf(
stderr,
"ERROR: new_stream_request() failed for %s:%d%s\n",
*((const char **)data + 3),
*((unsigned int *)data + 8),
*((const char **)data + 5));
return v0;
}
}
return 1;
}

original_code:
int pubsubclient_connect()
{
    fprintf(stdout, "CONNECTING TO SOURCE http://%s:%d%s\n", data->source_address, data->source_port, data->path);
    if (chunked) {
        if (evhttp_source_connection) {
            evhttp_connection_free(evhttp_source_connection);
        }
        evhttp_source_connection = evhttp_connection_new(data->source_address, data->source_port);
        if (evhttp_source_connection == ((void *)0)) {
            fprintf(stderr, "ERROR: evhttp_connection_new() failed for %s:%d\n", data->source_address, data->source_port);
            return 0;
        }
        evhttp_source_request = evhttp_request_new(pubsubclient_source_request_done, data);
        evhttp_add_header(evhttp_source_request->output_headers, "Host", data->source_address);
        evhttp_request_set_chunked_cb(evhttp_source_request, pubsubclient_source_callback);
        if (evhttp_make_request(evhttp_source_connection, evhttp_source_request, EVHTTP_REQ_GET, data->path) == -1) {
            fprintf(stderr, "ERROR: evhttp_make_request() failed for %s\n", data->path);
            evhttp_connection_free(evhttp_source_connection);
            return 0;
        }
    } else {
        if (stream_request) {
            free_stream_request(stream_request);
        }
        stream_request = new_stream_request("GET", data->source_address, data->source_port, data->path,
                                            ((void *)0), pubsubclient_source_readcb, pubsubclient_errorcb, data);
        if (!stream_request) {
            fprintf(stderr, "ERROR: new_stream_request() failed for %s:%d%s\n", data->source_address, data->source_port, data->path);
            return 0;
        }
    }
    return 1;
}


decompiled_code:
__int64 __fastcall pubsubclient_init(const char *a1, unsigned int a2, const char *a3, __int64 a4, __int64 a5, __int64 a6)
{
_QWORD *v11; // rax
FILE *v12; // rdi
__int64 result; // rax

signal(2, pubsubclient_termination_handler);
signal(3, pubsubclient_termination_handler);
signal(15, pubsubclient_termination_handler);
signal(1, pubsubclient_termination_handler);
if ( !current_base )
event_init();
v11 = calloc(1uLL, 0x30uLL);
*v11 = a4;
v12 = stdout;
v11[1] = a5;
v11[2] = a6;
v11[3] = a1;
*((_DWORD *)v11 + 8) = a2;
v11[5] = a3;
data = v11;
fprintf(v12, "AUTODETECTING ENCODING FOR http://%s:%d%s\n", a1, a2, a3);
result = new_stream_request("HEAD", a1, a2, a3, pubsubclient_autodetect_headercb, 0LL, pubsubclient_errorcb, data);
autodetect_sr = result;
if ( !result )
{
fprintf(stderr, "ERROR: new_stream_request() failed for %s:%d%s\n", a1, a2, a3);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, unsigned int a2, const char *a3, __int64 a4, __int64 a5, __int64 a6)
{
_QWORD *v11; // rax
FILE *v12; // rdi
__int64 result; // rax

signal(2, pubsubclient_termination_handler);
signal(3, pubsubclient_termination_handler);
signal(15, pubsubclient_termination_handler);
signal(1, pubsubclient_termination_handler);
if ( !current_base )
event_init();
v11 = calloc(1uLL, 0x30uLL);
*v11 = a4;
v12 = stdout;
v11[1] = a5;
v11[2] = a6;
v11[3] = a1;
*((_DWORD *)v11 + 8) = a2;
v11[5] = a3;
data = v11;
fprintf(v12, "AUTODETECTING ENCODING FOR http://%s:%d%s\n", a1, a2, a3);
result = new_stream_request("HEAD", a1, a2, a3, pubsubclient_autodetect_headercb, 0LL, pubsubclient_errorcb, data);
autodetect_sr = result;
if ( !result )
{
fprintf(stderr, "ERROR: new_stream_request() failed for %s:%d%s\n", a1, a2, a3);
exit(1);
}
return result;
}

original_code:
void pubsubclient_init(const char *source_address, int source_port, const char *path,
                       void (*message_cb)(char *data, void *arg),
                       void (*error_cb)(int status_code, void *arg),
                       void *cbarg)
{
    signal(2, pubsubclient_termination_handler);
    signal(3, pubsubclient_termination_handler);
    signal(15, pubsubclient_termination_handler);
    signal(1, pubsubclient_termination_handler);
    if (!current_base) {
        event_init();
    }
    data = calloc(1, sizeof(struct GlobalData));
    data->message_cb = message_cb;
    data->error_cb = error_cb;
    data->cbarg = cbarg;
    data->source_address = source_address;
    data->source_port = source_port;
    data->path = path;
    fprintf(stdout, "AUTODETECTING ENCODING FOR http://%s:%d%s\n", source_address, source_port, path);
    autodetect_sr = new_stream_request("HEAD", source_address, source_port, path,
                                       pubsubclient_autodetect_headercb, ((void *)0), pubsubclient_errorcb, data);
    if (!autodetect_sr) {
        fprintf(stderr, "ERROR: new_stream_request() failed for %s:%d%s\n", source_address, source_port, path);
        exit(1);
    }
}

canonical_original_code:
void pubsubclient_init(char *source_address, int source_port, char *path, void (*message_cb)(char *data, void *arg), void (*error_cb)(int status_code, void *arg), void *cbarg)
{
    signal(2, pubsubclient_termination_handler);
    signal(3, pubsubclient_termination_handler);
    signal(15, pubsubclient_termination_handler);
    signal(1, pubsubclient_termination_handler);
    if (!current_base) {
        event_init();
    }
    data = calloc(1, sizeof(struct GlobalData));
    data->message_cb = message_cb;
    data->error_cb = error_cb;
    data->cbarg = cbarg;
    data->source_address = source_address;
    data->source_port = source_port;
    data->path = path;
    fprintf(stdout, "AUTODETECTING ENCODING FOR http://%s:%d%s\n", source_address, source_port, path);
    autodetect_sr = new_stream_request("HEAD", source_address, source_port, path,
                                       pubsubclient_autodetect_headercb, ((void *)0), pubsubclient_errorcb, data);
    if (!autodetect_sr) {
        fprintf(stderr, "ERROR: new_stream_request() failed for %s:%d%s\n", source_address, source_port, path);
        exit(1);
    }
}

variable_types:
path
char *

variable_types:
cbarg
void *

user_defined_types: struct GlobalData { void (*message_cb)(char *data, void *cbarg); void (*error_cb)(int status_code, void *cbarg); void *cbarg; char *source_address; int source_port; char *path; }


decompiled_code:
// attributes: thunk
__int64 pubsubclient_run()
{
return event_dispatch();
}

canonical_decompiled_code:
__int64 func7()
{
return event_dispatch();
}

original_code:
void pubsubclient_run()
{
    event_dispatch();
}


decompiled_code:
void pubsubclient_free()
{
free_stream_request(autodetect_sr);
if ( chunked )
evhttp_connection_free(evhttp_source_connection);
else
free_stream_request(stream_request);
free(data);
}

canonical_decompiled_code:
void func8()
{
free_stream_request(autodetect_sr);
if ( chunked )
evhttp_connection_free(evhttp_source_connection);
else
free_stream_request(stream_request);
free(data);
}

original_code:
void pubsubclient_free()
{
    free_stream_request(autodetect_sr);
    if (chunked) {
        evhttp_connection_free(evhttp_source_connection);
    } else {
        free_stream_request(stream_request);
    }
    free(data);
}


decompiled_code:
__int64 __fastcall pubsubclient_main(const char *a1, unsigned int a2, const char *a3, __int64 a4, __int64 a5, __int64 a6)
{
pubsubclient_init(a1, a2, a3, a4, a5, a6);
event_dispatch();
pubsubclient_free();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, unsigned int a2, const char *a3, __int64 a4, __int64 a5, __int64 a6)
{
func6(a1, a2, a3, a4, a5, a6);
event_dispatch();
func8();
return 0LL;
}

original_code:
int pubsubclient_main(const char *source_address, int source_port, const char *path,
                      void (*message_cb)(char *data, void *arg),
                      void (*error_cb)(int status_code, void *arg),
                      void *cbarg)
{
    pubsubclient_init(source_address, source_port, path, message_cb, error_cb, cbarg);
    event_dispatch();
    pubsubclient_free();
    return 0;
}

canonical_original_code:
int pubsubclient_main(char *source_address, int source_port, char *path, void (*message_cb)(char *data, void *arg), void (*error_cb)(int status_code, void *arg), void *cbarg)
{
    pubsubclient_init(source_address, source_port, path, message_cb, error_cb, cbarg);
    event_dispatch();
    pubsubclient_free();
    return 0;
}


decompiled_code:
__int64 __fastcall stream_request_connect(char *name, unsigned int a2)
{
sockaddr *v2; // rbp
socklen_t v3; // er13
int v4; // eax
unsigned int v5; // er12
struct addrinfo *pai; // [rsp+0h] [rbp-70h] BYREF
char s[32]; // [rsp+8h] [rbp-68h] BYREF
struct addrinfo req; // [rsp+28h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_family = 0x100000002LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
snprintf(s, 0x20uLL, "%d", a2);
if ( getaddrinfo(name, s, &req, &pai) )
{
v5 = -1;
fwrite("ERROR: getaddrinfo() failed\n", 1uLL, 0x1CuLL, stderr);
}
else
{
v2 = pai->ai_addr;
v3 = pai->ai_addrlen;
v4 = socket(2, 1, 0);
v5 = v4;
if ( v4 == -1 )
{
fwrite("ERROR: socket() failed\n", 1uLL, 0x17uLL, stderr);
}
else if ( fcntl(v4, 4, 2048LL) == -1 )
{
v5 = -1;
fwrite("ERROR: fcntl(O_NONBLOCK) failed\n", 1uLL, 0x20uLL, stderr);
}
else if ( connect(v5, v2, v3) == -1 && *_errno_location() != 115 )
{
v5 = -1;
fwrite("ERROR: connect() failed\n", 1uLL, 0x18uLL, stderr);
}
else
{
freeaddrinfo(pai);
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *name, unsigned int a2)
{
sockaddr *v2; // rbp
socklen_t v3; // er13
int v4; // eax
unsigned int v5; // er12
struct addrinfo *pai; // [rsp+0h] [rbp-70h] BYREF
char s[32]; // [rsp+8h] [rbp-68h] BYREF
struct addrinfo req; // [rsp+28h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_family = 0x100000002LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
snprintf(s, 0x20uLL, "%d", a2);
if ( getaddrinfo(name, s, &req, &pai) )
{
v5 = -1;
fwrite("ERROR: getaddrinfo() failed\n", 1uLL, 0x1CuLL, stderr);
}
else
{
v2 = pai->ai_addr;
v3 = pai->ai_addrlen;
v4 = socket(2, 1, 0);
v5 = v4;
if ( v4 == -1 )
{
fwrite("ERROR: socket() failed\n", 1uLL, 0x17uLL, stderr);
}
else if ( fcntl(v4, 4, 2048LL) == -1 )
{
v5 = -1;
fwrite("ERROR: fcntl(O_NONBLOCK) failed\n", 1uLL, 0x20uLL, stderr);
}
else if ( connect(v5, v2, v3) == -1 && *_errno_location() != 115 )
{
v5 = -1;
fwrite("ERROR: connect() failed\n", 1uLL, 0x18uLL, stderr);
}
else
{
freeaddrinfo(pai);
}
}
return v5;
}

original_code:
int stream_request_connect(const char *address, int port)
{
    struct addrinfo ai, *aitop;
    char strport[32];
    struct sockaddr *sa;
    int slen;
    int fd;
    memset(&ai, 0, sizeof(struct addrinfo));
    ai.ai_family = 2;
    ai.ai_socktype = SOCK_STREAM;
    snprintf(strport, sizeof(strport), "%d", port);
    if (getaddrinfo(address, strport, &ai, &aitop) != 0) {
        fprintf(stderr, "ERROR: getaddrinfo() failed\n");
        return -1;
    }
    sa = aitop->ai_addr;
    slen = aitop->ai_addrlen;
    fd = socket(2, SOCK_STREAM, 0);
    if (fd == -1) {
        fprintf(stderr, "ERROR: socket() failed\n");
        return -1;
    }
    if (fcntl(fd, 4, 04000) == -1) {
        fprintf(stderr, "ERROR: fcntl(O_NONBLOCK) failed\n");
        return -1;
    }
    if (connect(fd, sa, slen) == -1) {
        if ((*__errno_location ()) != 115) {
            fprintf(stderr, "ERROR: connect() failed\n");
            return -1;
        }
    }
    freeaddrinfo(aitop);
    return fd;
}

canonical_original_code:
int stream_request_connect(char *address, int port)
{
    struct addrinfo ai; struct addrinfo *aitop;
    char strport[32];
    struct sockaddr *sa;
    int slen;
    int fd;
    memset(&ai, 0, sizeof(struct addrinfo));
    ai.ai_family = 2;
    ai.ai_socktype = SOCK_STREAM;
    snprintf(strport, sizeof(strport), "%d", port);
    if (getaddrinfo(address, strport, &ai, &aitop) != 0) {
        fprintf(stderr, "ERROR: getaddrinfo() failed\n");
        return -1;
    }
    sa = aitop->ai_addr;
    slen = aitop->ai_addrlen;
    fd = socket(2, SOCK_STREAM, 0);
    if (fd == -1) {
        fprintf(stderr, "ERROR: socket() failed\n");
        return -1;
    }
    if (fcntl(fd, 4, 04000) == -1) {
        fprintf(stderr, "ERROR: fcntl(O_NONBLOCK) failed\n");
        return -1;
    }
    if (connect(fd, sa, slen) == -1) {
        if ((*__errno_location ()) != 115) {
            fprintf(stderr, "ERROR: connect() failed\n");
            return -1;
        }
    }
    freeaddrinfo(aitop);
    return fd;
}

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

variable_types:
strport
char [32]

variable_types: slen int

variable_types: fd int

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


decompiled_code:
// attributes: thunk
__int64 stream_request_disconnect()
{
return evutil_closesocket();
}

canonical_decompiled_code:
__int64 func3()
{
return evutil_closesocket();
}

original_code:
int stream_request_disconnect(int fd)
{
    evutil_closesocket(fd);
}


decompiled_code:
__int64 __fastcall ninety_five_percent(void *src, int a2)
{
void *v2; // rbp
double v3; // xmm0_8
__m128d v4; // xmm3
__m128d v5; // xmm1
int v6; // eax
__int64 v7; // r12

v2 = calloc(1uLL, 8LL * a2);
memcpy(v2, src, 8LL * a2);
qsort(v2, a2, 8uLL, (__compar_fn_t)int_cmp);
v3 = (double)a2 * 0.95 + 0.5;
if ( COERCE_DOUBLE(*(_QWORD *)&v3 & LC3) < 4.503599627370496e15 )
{
v4.m128d_f64[0] = (double)a2 * 0.95 + 0.5;
v5.m128d_f64[0] = (double)(int)v3;
*(_QWORD *)&v3 = COERCE_UNSIGNED_INT64(v5.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v4, v5) & LC4)) | ~LC3 & *(_QWORD *)&v3;
}
v6 = (int)v3;
if ( a2 <= (int)v3 )
v6 = a2 - 1;
v7 = *((_QWORD *)v2 + v6);
free(v2);
return v7;
}

original_code:
uint64_t ninety_five_percent(int64_t *int_array, int length)
{
    uint64_t value;
    int64_t *sorted_requests;
    int index_of_95;
    sorted_requests = calloc(1, length * sizeof(int64_t));
    memcpy(sorted_requests, int_array, length * sizeof(int64_t));
    qsort(sorted_requests, length, sizeof(int64_t), int_cmp);
    index_of_95 = (int)ceil(((95.0 / 100.0) * length) + 0.5);
    if (index_of_95 >= length) {
        index_of_95 = length - 1;
    }
    value = sorted_requests[index_of_95];
    free(sorted_requests);
    return value;
}

canonical_original_code:
unsigned long ninety_five_percent(long *int_array, int length)
{
    unsigned long value;
    long *sorted_requests;
    int index_of_95;
    sorted_requests = calloc(1, length * sizeof(long));
    memcpy(sorted_requests, int_array, length * sizeof(long));
    qsort(sorted_requests, length, sizeof(long), int_cmp);
    index_of_95 = (int)ceil(((95.0 / 100.0) * length) + 0.5);
    if (index_of_95 >= length) {
        index_of_95 = length - 1;
    }
    value = sorted_requests[index_of_95];
    free(sorted_requests);
    return value;
}

variable_types: length int

variable_types:
value
unsigned long

return_type: unsigned long


original_code:
int simplehttp_parse_url(const char *endpoint, size_t endpoint_len, char **address, int *port, char **path)
{
    const char *address_p, *path_p, *tmp_pointer, *tmp_port;
    size_t address_len;
    size_t path_len;
    if (endpoint_len < 9) {
        return 0;
    }
    address_p = strchr(endpoint, '/');
    if (!address_p) {
        return 0;
    }
    address_p += 2;
    tmp_pointer = strchr(address_p, ':');
    path_p = strchr(address_p, '/');
    if (!path_p) {
        return 0;
    }
    if (tmp_pointer) {
        address_len = tmp_pointer - address_p;
        tmp_port = address_p + address_len + 1;
        *port = atoi(tmp_port);
    } else {
        address_len = path_p - address_p;
        *port = 80;
    }
    path_len = (endpoint + endpoint_len) - path_p;
    *address = strndup(address_p, address_len);
    *path = strndup(path_p, path_len);
    return 1;
}

canonical_original_code:
int simplehttp_parse_url(char *endpoint, unsigned long endpoint_len, char **address, int *port, char **path)
{
    char *address_p; char *path_p; char *tmp_pointer; char *tmp_port;
    unsigned long address_len;
    unsigned long path_len;
    if (endpoint_len < 9) {
        return 0;
    }
    address_p = strchr(endpoint, '/');
    if (!address_p) {
        return 0;
    }
    address_p += 2;
    tmp_pointer = strchr(address_p, ':');
    path_p = strchr(address_p, '/');
    if (!path_p) {
        return 0;
    }
    if (tmp_pointer) {
        address_len = tmp_pointer - address_p;
        tmp_port = address_p + address_len + 1;
        *port = atoi(tmp_port);
    } else {
        address_len = path_p - address_p;
        *port = 80;
    }
    path_len = (endpoint + endpoint_len) - path_p;
    *address = strndup(address_p, address_len);
    *path = strndup(path_p, path_len);
    return 1;
}

variable_types:
endpoint
char *

variable_types:
address
char **

variable_types:
port
int *

variable_types:
path
char **


decompiled_code:
char *__fastcall simplehttp_encode_uri(const char *a1)
{
unsigned __int8 *v1; // rbx
size_t v2; // rax
char *v3; // r12
unsigned __int8 v4; // al
char *i; // rbp

v1 = (unsigned __int8 *)a1;
v2 = strlen(a1);
v3 = (char *)malloc(3 * v2 + 1);
v4 = *a1;
for ( i = v3; v4; i += 3 )
{
while ( uri_chars[v4] )
{
++v1;
*i++ = v4;
v4 = *v1;
if ( !*v1 )
goto LABEL_6;
}
sprintf(i, "%%%02X", v4);
v4 = *++v1;
}
LABEL_6:
*i = 0;
return v3;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1)
{
unsigned __int8 *v1; // rbx
size_t v2; // rax
char *v3; // r12
unsigned __int8 v4; // al
char *i; // rbp

v1 = (unsigned __int8 *)a1;
v2 = strlen(a1);
v3 = (char *)malloc(3 * v2 + 1);
v4 = *a1;
for ( i = v3; v4; i += 3 )
{
while ( uri_chars[v4] )
{
++v1;
*i++ = v4;
v4 = *v1;
if ( !*v1 )
goto LABEL_6;
}
sprintf(i, "%%%02X", v4);
v4 = *++v1;
}
LABEL_6:
*i = 0;
return v3;
}

original_code:
char *simplehttp_encode_uri(const char *uri)
{
    char *buf, *cur;
    char *p;
    buf = malloc(strlen(uri) * 3 + 1);
    cur = buf;
    for (p = (char *)uri; *p != '\0'; p++) {
        if (uri_chars[(unsigned char)(*p)]) {
            *cur++ = *p;
        } else {
            sprintf(cur, "%%%02X", (unsigned char)(*p));
            cur += 3;
        }
    }
    *cur = '\0';
    return buf;
}

canonical_original_code:
char *simplehttp_encode_uri(char *uri)
{
    char *buf; char *cur;
    char *p;
    buf = malloc(strlen(uri) * 3 + 1);
    cur = buf;
    for (p = (char *)uri; *p != '\0'; p++) {
        if (uri_chars[(unsigned char)(*p)]) {
            *cur++ = *p;
        } else {
            sprintf(cur, "%%%02X", (unsigned char)(*p));
            cur += 3;
        }
    }
    *cur = '\0';
    return buf;
}

variable_types:
uri
char *

variable_types:
buf
char *

variable_types:
cur
char *

variable_types:
p
char *

return_type: char *


decompiled_code:
const char *__fastcall simplehttp_strnstr(const char *a1, char *a2, __int64 a3)
{
char v4; // bp
size_t v6; // rbx
size_t v7; // r15
const char *v10; // r14
char v11; // al

v4 = *a2;
if ( *a2 )
{
v6 = a3 - 1;
v7 = strlen(a2 + 1);
if ( a3 )
{
do
{
v10 = a1;
v11 = *a1++;
if ( !v11 )
break;
if ( v4 == v11 )
{
if ( v6 < v7 )
break;
if ( !strncmp(a1, a2 + 1, v7) )
return v10;
}
}
while ( v6-- != 0 );
}
a1 = 0LL;
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func4(const char *a1, char *a2, __int64 a3)
{
char v4; // bp
size_t v6; // rbx
size_t v7; // r15
const char *v10; // r14
char v11; // al

v4 = *a2;
if ( *a2 )
{
v6 = a3 - 1;
v7 = strlen(a2 + 1);
if ( a3 )
{
do
{
v10 = a1;
v11 = *a1++;
if ( !v11 )
break;
if ( v4 == v11 )
{
if ( v6 < v7 )
break;
if ( !strncmp(a1, a2 + 1, v7) )
return v10;
}
}
while ( v6-- != 0 );
}
a1 = 0LL;
}
return a1;
}

original_code:
char *simplehttp_strnstr(const char *s, const char *find, size_t slen)
{
    char c, sc;
    size_t len;
    if ((c = *find++) != '\0') {
        len = strlen(find);
        do {
            do {
                if (slen-- < 1 || (sc = *s++) == '\0') {
                    return ((void *)0);
                }
            } while (sc != c);
            if (len > slen) {
                return ((void *)0);
            }
        } while (strncmp(s, find, len) != 0);
        s--;
    }
    return (char *)s;
}

canonical_original_code:
char *simplehttp_strnstr(char *s, char *find, unsigned long slen)
{
    char c; char sc;
    unsigned long len;
    if ((c = *find++) != '\0') {
        len = strlen(find);
        do {
            do {
                if (slen-- < 1 || (sc = *s++) == '\0') {
                    return ((void *)0);
                }
            } while (sc != c);
            if (len > slen) {
                return ((void *)0);
            }
        } while (strncmp(s, find, len) != 0);
        s--;
    }
    return (char *)s;
}

variable_types:
s
char *

variable_types:
find
char *

variable_types:
slen
unsigned long

variable_types: c char

variable_types: sc char

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall int_cmp(const void *a1, const void *a2)
{
return (unsigned int)*(_QWORD *)a1 - *(_DWORD *)a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return (unsigned int)*(_QWORD *)a1 - *(_DWORD *)a2;
}

original_code:
int int_cmp(const void *a, const void *b)
{
    const uint64_t *ia = (const uint64_t *)a;
    const uint64_t *ib = (const uint64_t *)b;
    return *ia - *ib;
}

canonical_original_code:
int int_cmp(void *a, void *b)
{
    unsigned long *ia = (const uint64_t *)a;
    unsigned long *ib = (const uint64_t *)b;
    return *ia - *ib;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
ia
unsigned long *

variable_types:
ib
unsigned long *


decompiled_code:
int __fastcall simplehttp_ts_get(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

original_code:
void simplehttp_ts_get(struct timeval *ts)
{
    gettimeofday(ts, ((void *)0));
}

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


decompiled_code:
__int64 __fastcall simplehttp_ts_diff(int a1, __int64 a2, int a3, __int64 a4)
{
int v4; // edx
int v5; // eax

v4 = a3 - a1;
v5 = a4 - a2;
if ( a4 - a2 < 0 )
{
--v4;
v5 = a4 + 1000000 - a2;
}
return (unsigned int)(1000000 * v4 + v5);
}

original_code:
unsigned int simplehttp_ts_diff(struct timeval start, struct timeval end)
{
    struct timeval temp;
    if ((end.tv_usec - start.tv_usec) < 0) {
        temp.tv_sec = end.tv_sec - start.tv_sec - 1;
        temp.tv_usec = 1000000 + end.tv_usec - start.tv_usec;
    } else {
        temp.tv_sec = end.tv_sec - start.tv_sec;
        temp.tv_usec = end.tv_usec - start.tv_usec;
    }
    return (temp.tv_sec * 1000000) + temp.tv_usec;
}

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

variable_types:
end
struct timeval

return_type: unsigned int


decompiled_code:
_BOOL8 __fastcall get_argument_format(__int64 a1)
{
unsigned __int8 *v1; // rdx
_BOOL8 result; // rax
int v3; // eax

v1 = (unsigned __int8 *)evhttp_find_header(a1, "format");
result = 0LL;
if ( v1 )
{
v3 = *v1 - 116;
if ( *v1 == 116 )
{
v3 = v1[1] - 120;
if ( v1[1] == 120 )
v3 = v1[2] - 116;
}
result = v3 == 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
unsigned __int8 *v1; // rdx
_BOOL8 result; // rax
int v3; // eax

v1 = (unsigned __int8 *)evhttp_find_header(a1, "format");
result = 0LL;
if ( v1 )
{
v3 = *v1 - 116;
if ( *v1 == 116 )
{
v3 = v1[1] - 120;
if ( v1[1] == 120 )
v3 = v1[2] - 116;
}
result = v3 == 0;
}
return result;
}

original_code:
int get_argument_format(struct evkeyvalq *args)
{
    int format_code = json_format;
    const char *format = evhttp_find_header(args, "format");
    if (format && !strncmp(format, "txt", 3)) {
        format_code = txt_format;
    }
    return format_code;
}

canonical_original_code:
int get_argument_format(struct evkeyvalq *args)
{
    int format_code = json_format;
    char *format = evhttp_find_header(args, "format");
    if (format && !strncmp(format, "txt", 3)) {
        format_code = txt_format;
    }
    return format_code;
}

variable_types: struct evkeyvalq { struct evkeyval { struct { struct evkeyval *tqe_next; struct evkeyval **tqe_prev; } next; char *key; char *value; } *tqh_first; struct evkeyval **tqh_last; } *

variable_types:
format
char *

user_defined_types: struct evkeyvalq { struct evkeyval *tqh_first; struct evkeyval **tqh_last; }


decompiled_code:
int __fastcall get_int_argument(__int64 a1, __int64 a2, int a3)
{
const char *v4; // rdi
int result; // eax

if ( a2 && (v4 = (const char *)evhttp_find_header(a1, a2)) != 0LL )
result = atoi(v4);
else
result = a3;
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2, int a3)
{
const char *v4; // rdi
int result; // eax

if ( a2 && (v4 = (const char *)evhttp_find_header(a1, a2)) != 0LL )
result = atoi(v4);
else
result = a3;
return result;
}

original_code:
int get_int_argument(struct evkeyvalq *args, const char *key, int default_value)
{
    const char *tmp;
    if (!key) {
        return default_value;
    }
    tmp = evhttp_find_header(args, key);
    if (tmp) {
        return atoi(tmp);
    }
    return default_value;
}

canonical_original_code:
int get_int_argument(struct evkeyvalq *args, char *key, int default_value)
{
    char *tmp;
    if (!key) {
        return default_value;
    }
    tmp = evhttp_find_header(args, key);
    if (tmp) {
        return atoi(tmp);
    }
    return default_value;
}

variable_types:
key
char *

variable_types:
tmp
char *

user_defined_types: struct evkeyval { struct { struct evkeyval *tqe_next; struct evkeyval **tqe_prev; } next; char *key; char *value; }


decompiled_code:
void __fastcall get_double_argument(__int64 a1, __int64 a2)
{
const char *v2; // rdi

if ( a2 )
{
v2 = (const char *)evhttp_find_header(a1, a2);
if ( v2 )
atof(v2);
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, __int64 a2)
{
const char *v2; // rdi

if ( a2 )
{
v2 = (const char *)evhttp_find_header(a1, a2);
if ( v2 )
atof(v2);
}
}

original_code:
double get_double_argument(struct evkeyvalq *args, const char *key, double default_value)
{
    const char *tmp;
    if (!key) {
        return default_value;
    }
    tmp = evhttp_find_header(args, key);
    if (tmp) {
        return atof(tmp);
    }
    return default_value;
}

canonical_original_code:
double get_double_argument(struct evkeyvalq *args, char *key, double default_value)
{
    char *tmp;
    if (!key) {
        return default_value;
    }
    tmp = evhttp_find_header(args, key);
    if (tmp) {
        return atof(tmp);
    }
    return default_value;
}

return_type: double


repo: juanitaLara/FisicaComputacional

original_code:
float funcion_x(float x, float y, float z){
    return 10.0*(y-x);
}

variable_types: x float

variable_types: y float

variable_types: z float

return_type: float


decompiled_code:
float __fastcall funcion_y(float a1, float a2, float a3)
{
return (28.0 - a3) * a1 - a2;
}

canonical_decompiled_code:
float __fastcall func8(float a1, float a2, float a3)
{
return (28.0 - a3) * a1 - a2;
}

original_code:
float funcion_y(float x, float y, float z){
    return x*(28.0-z)-y;
}


decompiled_code:
float __fastcall funcion_z(float a1, float a2, float a3)
{
return (float)(a1 * a2) - a3 * 2.666666666666667;
}

canonical_decompiled_code:
float __fastcall func9(float a1, float a2, float a3)
{
return (float)(a1 * a2) - a3 * 2.666666666666667;
}

original_code:
float funcion_z(float x, float y, float z){
    return x*y-(8.0/3.0)*z;
}


repo: judnich/TupleMarkup

original_code:
enum FILE_TYPE file_type(const char *filename)
{
 int len = strlen(filename);
 if (len < 4) return FILE_UNKNOWN;
 const char *ext = filename + len - 4;
 if (ext[0] == '.' && tolower(ext[1]) == 'x' && tolower(ext[2]) == 'm' && tolower(ext[3]) == 'l' ) return FILE_XML;
 if (ext[0] == '.' && tolower(ext[1]) == 't' && tolower(ext[2]) == 'm' && tolower(ext[3]) == 'l' ) return FILE_TML;
 return FILE_UNKNOWN;
}

canonical_original_code:
enum FILE_TYPE file_type(char *filename)
{
 int len = strlen(filename);
 if (len < 4) return FILE_UNKNOWN;
 char *ext = filename + len - 4;
 if (ext[0] == '.' && tolower(ext[1]) == 'x' && tolower(ext[2]) == 'm' && tolower(ext[3]) == 'l' ) return FILE_XML;
 if (ext[0] == '.' && tolower(ext[1]) == 't' && tolower(ext[2]) == 'm' && tolower(ext[3]) == 'l' ) return FILE_TML;
 return FILE_UNKNOWN;
}

variable_types:
filename
char *

variable_types: len int

variable_types:
ext
char *

return_type: enum FILE_TYPE { FILE_XML=0, FILE_TML=1, FILE_UNKNOWN=2 }


error

decompiled_code:
__int64 __fastcall error(const char *a1)
{
puts("\n(XML-TML Conversion Tool)");
printf("%s\n\n", a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
puts("\n(XML-TML Conversion Tool)");
printf("%s\n\n", a1);
return 1LL;
}

original_code:
int error(const char *msg)
{
 printf("\n(XML-TML Conversion Tool)\n");
 printf("%s\n\n", msg);
 return 1;
}

canonical_original_code:
int error(char *msg)
{
 printf("\n(XML-TML Conversion Tool)\n");
 printf("%s\n\n", msg);
 return 1;
}

variable_types:
msg
char *


datetime

repo: juhakaja/status-foobar

decompiled_code:
size_t __fastcall datetime(char *s)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
return strftime(s, 0x3E8uLL, "%a, %b %d %H:%M:%S %Z %Y", v1);
}

canonical_decompiled_code:
size_t __fastcall func0(char *s)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
return strftime(s, 0x3E8uLL, "%a, %b %d %H:%M:%S %Z %Y", v1);
}

original_code:
void datetime(char *current_time)
{
  time_t now = time(((void *)0));
  struct tm * dts = localtime(&now);
  strftime(current_time, 1000, "%a, %b %d %H:%M:%S %Z %Y", dts);
}

canonical_original_code:
void datetime(char *current_time)
{
  long now = time(((void *)0));
  struct tm *dts = localtime(&now);
  strftime(current_time, 1000, "%a, %b %d %H:%M:%S %Z %Y", dts);
}

variable_types: now long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


host

decompiled_code:
int __fastcall host(char *a1)
{
return gethostname(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(char *a1)
{
return gethostname(a1, 0LL);
}

original_code:
void host(char *hostname)
{
  size_t len;
  gethostname(hostname, len);
}

canonical_original_code:
void host(char *hostname)
{
  unsigned long len;
  gethostname(hostname, len);
}

variable_types:
hostname
char *

variable_types:
len
unsigned long


decompiled_code:
Display *launch_statusbar()
{
Display *result; // rax

result = XOpenDisplay(0LL);
display = result;
return result;
}

canonical_decompiled_code:
Display *func0()
{
Display *result; // rax

result = XOpenDisplay(0LL);
display = result;
return result;
}

original_code:
void launch_statusbar()
{
  display = XOpenDisplay(((void *)0));
}


decompiled_code:
int close_statusbar()
{
return XCloseDisplay(display);
}

canonical_decompiled_code:
int func1()
{
return XCloseDisplay(display);
}

original_code:
void close_statusbar()
{
  XCloseDisplay(display);
}


status

decompiled_code:
int __fastcall status(char *a1, const char *a2, const char *a3, const char *a4)
{
return sprintf(a1, "host: %s | battery: %s | %s", a2, a3, a4);
}

canonical_decompiled_code:
int __fastcall func2(char *a1, const char *a2, const char *a3, const char *a4)
{
return sprintf(a1, "host: %s | battery: %s | %s", a2, a3, a4);
}

original_code:
void status(char *status_string, char *hostname, char *battery_remain, char *current_time)
{
  sprintf(status_string, "host: %s | battery: %s | %s", hostname, battery_remain, current_time);
}


statusbar

decompiled_code:
int __fastcall statusbar(char *a1)
{
XStoreName(display, display->screens[(__int64)display->default_screen].root, a1);
return XSync(display, 0);
}

canonical_decompiled_code:
int __fastcall func3(char *a1)
{
XStoreName(display, display->screens[(__int64)display->default_screen].root, a1);
return XSync(display, 0);
}

original_code:
void statusbar(char *status_string)
{
  XStoreName(display, ((&((_XPrivDisplay)(display))->screens[(((_XPrivDisplay)(display))->default_screen)])->root), status_string);
  XSync(display, 0);
}


decompiled_code:
int __fastcall battery_status(char *s)
{
float v1; // xmm0_4
float v3; // [rsp+Ch] [rbp-Ch]

v3 = energy_now();
v1 = energy_full();
return sprintf(s, "%d%%", (unsigned int)(int)(float)((float)(v3 / v1) * 100.0));
}

canonical_decompiled_code:
int __fastcall func2(char *s)
{
float v1; // xmm0_4
float v3; // [rsp+Ch] [rbp-Ch]

v3 = func1();
v1 = func0();
return sprintf(s, "%d%%", (unsigned int)(int)(float)((float)(v3 / v1) * 100.0));
}

original_code:
void battery_status(char *battery_remain) {
  int status;
  status = (int)(energy_now() / energy_full() * 100);
  sprintf(battery_remain, "%d%%", status);
}

variable_types: status int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
void *v4; // rbp

v3 = 1000;
v4 = (void *)create_timekeeper(1000LL, 0LL, 0LL);
do
{
get_start_time(v4);
get_stop_time(v4);
--v3;
}
while ( v3 );
print_timekeeper(v4);
destroy_timekeeper(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
void *v4; // rbp

v3 = 1000;
v4 = (void *)create_timekeeper(1000LL, 0LL, 0LL);
do
{
func10(v4);
func11(v4);
--v3;
}
while ( v3 );
func12(v4);
func9(v4);
return 0;
}

original_code:
int main() {
 int i;
 timekeeper *tk;
 tk = create_timekeeper(1000, ((void *)0), ((void *)0));
 for (i=0; i<1000; i++) {
  get_start_time(tk);
  get_stop_time(tk);
 }
 print_timekeeper(tk);
 destroy_timekeeper(tk);
 return 0;
}

canonical_original_code:
int main() {
 int i;
 struct _timekeeper *tk;
 tk = create_timekeeper(1000, ((void *)0), ((void *)0));
 for (i=0; i<1000; i++) {
  get_start_time(tk);
  get_stop_time(tk);
 }
 print_timekeeper(tk);
 destroy_timekeeper(tk);
 return 0;
}

variable_types: i int

variable_types: struct _timekeeper { struct timeval { long tv_sec; long tv_usec; } *start; struct timeval *stop; int max_times; int start_t_num; int stop_t_num; char *timefile; char gr_hook[-1]; } *

user_defined_types: struct _timekeeper { struct timeval *start; struct timeval *stop; int max_times; int start_t_num; int stop_t_num; char *timefile; char gr_hook[-1]; }


decompiled_code:
void *__fastcall err_malloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "malloc(): failed to allocate %u bytes\n", (unsigned int)a1);
exit(-1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "malloc(): failed to allocate %u bytes\n", (unsigned int)a1);
exit(-1);
}
return result;
}

original_code:
void * err_malloc(size_t len) {
 void *buff;
 if( !(buff = malloc(len)) ) {
  fprintf(stderr, "malloc(): failed to allocate %u bytes\n", (unsigned int)len);
  exit(-1);
 }
 return buff;
}

canonical_original_code:
void *err_malloc(unsigned long len) {
 void *buff;
 if( !(buff = malloc(len)) ) {
  fprintf(stderr, "malloc(): failed to allocate %u bytes\n", (unsigned int)len);
  exit(-1);
 }
 return buff;
}

variable_types:
buff
void *

return_type: void *


decompiled_code:
void *__fastcall clr_malloc(size_t a1)
{
void *result; // rax

result = calloc(a1, 1uLL);
if ( !result )
{
fprintf(stderr, "malloc(): failed to allocate %u bytes\n", (unsigned int)a1);
exit(-1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(size_t a1)
{
void *result; // rax

result = calloc(a1, 1uLL);
if ( !result )
{
fprintf(stderr, "malloc(): failed to allocate %u bytes\n", (unsigned int)a1);
exit(-1);
}
return result;
}

original_code:
void * clr_malloc(size_t len) {
 void *buff;
 if( !(buff = calloc(len, sizeof(char))) ) {
  fprintf(stderr, "malloc(): failed to allocate %u bytes\n", (unsigned int)len);
  exit(-1);
 }
 return buff;
}

canonical_original_code:
void *clr_malloc(unsigned long len) {
 void *buff;
 if( !(buff = calloc(len, sizeof(char))) ) {
  fprintf(stderr, "malloc(): failed to allocate %u bytes\n", (unsigned int)len);
  exit(-1);
 }
 return buff;
}


decompiled_code:
void __fastcall destroy_timekeeper(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 4));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 4));
free(ptr);
}

original_code:
void destroy_timekeeper(timekeeper *tk) {
 free(tk->start);
 free(tk->stop);
 free(tk->timefile);
 free(tk);
 tk = ((void *)0);
}

canonical_original_code:
void destroy_timekeeper(struct _timekeeper *tk) {
 free(tk->start);
 free(tk->stop);
 free(tk->timefile);
 free(tk);
 tk = ((void *)0);
}

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


decompiled_code:
int __fastcall get_start_time(__int64 a1)
{
__int64 v1; // rax
int v2; // edx
struct timeval *v3; // rax

if ( !a1 )
__assert_fail("tk", "timekeeper.c", 0x5Cu, "get_start_time");
v1 = *(int *)(a1 + 20);
if ( (_DWORD)v1 != *(_DWORD *)(a1 + 24) )
return fwrite("get_start_time(): previous timer not stopped!\n", 1uLL, 0x2EuLL, stderr);
if ( (int)v1 >= *(_DWORD *)(a1 + 16) )
return fwrite("get_start_time(): timekeeper full!\n", 1uLL, 0x23uLL, stderr);
v2 = v1 + 1;
v3 = (struct timeval *)(*(_QWORD *)a1 + 16 * v1);
*(_DWORD *)(a1 + 20) = v2;
return gettimeofday(v3, 0LL);
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
__int64 v1; // rax
int v2; // edx
struct timeval *v3; // rax

if ( !a1 )
__assert_fail("tk", "timekeeper.c", 0x5Cu, "get_start_time");
v1 = *(int *)(a1 + 20);
if ( (_DWORD)v1 != *(_DWORD *)(a1 + 24) )
return fwrite("get_start_time(): previous timer not stopped!\n", 1uLL, 0x2EuLL, stderr);
if ( (int)v1 >= *(_DWORD *)(a1 + 16) )
return fwrite("get_start_time(): timekeeper full!\n", 1uLL, 0x23uLL, stderr);
v2 = v1 + 1;
v3 = (struct timeval *)(*(_QWORD *)a1 + 16 * v1);
*(_DWORD *)(a1 + 20) = v2;
return gettimeofday(v3, 0LL);
}

original_code:
void get_start_time(timekeeper *tk) {
 ((void) sizeof ((tk) ? 1 : 0), __extension__ ({ if (tk) ; else __assert_fail ("tk", "timekeeper.c", 92, __extension__ __PRETTY_FUNCTION__); }));
 if (tk->start_t_num != tk->stop_t_num) {
  fprintf(stderr, "get_start_time(): previous timer not stopped!\n");
  return;
 }
 if (tk->start_t_num >= tk->max_times) {
  fprintf(stderr, "get_start_time(): timekeeper full!\n");
  return;
 }
 gettimeofday(&tk->start[tk->start_t_num++], ((void *)0));
}

canonical_original_code:
void get_start_time(struct _timekeeper *tk) {
 ((void) sizeof ((tk) ? 1 : 0), __extension__ ({ if (tk) ; else __assert_fail ("tk", "timekeeper.c", 92, __extension__ __PRETTY_FUNCTION__); }));
 if (tk->start_t_num != tk->stop_t_num) {
  fprintf(stderr, "get_start_time(): previous timer not stopped!\n");
  return;
 }
 if (tk->start_t_num >= tk->max_times) {
  fprintf(stderr, "get_start_time(): timekeeper full!\n");
  return;
 }
 gettimeofday(&tk->start[tk->start_t_num++], ((void *)0));
}


decompiled_code:
int __fastcall get_stop_time(__int64 a1)
{
__int64 v1; // rax

if ( !a1 )
__assert_fail("tk", "timekeeper.c", 0x70u, "get_stop_time");
v1 = *(int *)(a1 + 24);
if ( *(_DWORD *)(a1 + 20) != (_DWORD)v1 + 1 )
return fwrite("get_stop_time(): timer not started!\n", 1uLL, 0x24uLL, stderr);
if ( (int)v1 >= *(_DWORD *)(a1 + 16) )
__assert_fail("tk->stop_t_num < tk->max_times", "timekeeper.c", 0x75u, "get_stop_time");
*(_DWORD *)(a1 + 24) = v1 + 1;
return gettimeofday((struct timeval *)(*(_QWORD *)(a1 + 8) + 16 * v1), 0LL);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
__int64 v1; // rax

if ( !a1 )
__assert_fail("tk", "timekeeper.c", 0x70u, "get_stop_time");
v1 = *(int *)(a1 + 24);
if ( *(_DWORD *)(a1 + 20) != (_DWORD)v1 + 1 )
return fwrite("get_stop_time(): timer not started!\n", 1uLL, 0x24uLL, stderr);
if ( (int)v1 >= *(_DWORD *)(a1 + 16) )
__assert_fail("tk->stop_t_num < tk->max_times", "timekeeper.c", 0x75u, "get_stop_time");
*(_DWORD *)(a1 + 24) = v1 + 1;
return gettimeofday((struct timeval *)(*(_QWORD *)(a1 + 8) + 16 * v1), 0LL);
}

original_code:
void get_stop_time(timekeeper *tk) {
 ((void) sizeof ((tk) ? 1 : 0), __extension__ ({ if (tk) ; else __assert_fail ("tk", "timekeeper.c", 112, __extension__ __PRETTY_FUNCTION__); }));
 if (tk->start_t_num != tk->stop_t_num+1) {
  fprintf(stderr, "get_stop_time(): timer not started!\n");
  return;
 }
 ((void) sizeof ((tk->stop_t_num < tk->max_times) ? 1 : 0), __extension__ ({ if (tk->stop_t_num < tk->max_times) ; else __assert_fail ("tk->stop_t_num < tk->max_times", "timekeeper.c", 117, __extension__ __PRETTY_FUNCTION__); }));
 gettimeofday(&tk->stop[tk->stop_t_num++], ((void *)0));
}

canonical_original_code:
void get_stop_time(struct _timekeeper *tk) {
 ((void) sizeof ((tk) ? 1 : 0), __extension__ ({ if (tk) ; else __assert_fail ("tk", "timekeeper.c", 112, __extension__ __PRETTY_FUNCTION__); }));
 if (tk->start_t_num != tk->stop_t_num+1) {
  fprintf(stderr, "get_stop_time(): timer not started!\n");
  return;
 }
 ((void) sizeof ((tk->stop_t_num < tk->max_times) ? 1 : 0), __extension__ ({ if (tk->stop_t_num < tk->max_times) ; else __assert_fail ("tk->stop_t_num < tk->max_times", "timekeeper.c", 117, __extension__ __PRETTY_FUNCTION__); }));
 gettimeofday(&tk->stop[tk->stop_t_num++], ((void *)0));
}


repo: jukaiser/sscs

decompiled_code:
int dump_qs()
{
if ( !qs )
_assert_fail("qs", "queue.c", 0x1Bu, "dump_qs");
return printf("\nQ-Dump [%d, %d]\n", (unsigned int)current, (unsigned int)max);
}

canonical_decompiled_code:
int func0()
{
if ( !qs )
_assert_fail("qs", "queue.c", 0x1Bu, "dump_qs");
return printf("\nQ-Dump [%d, %d]\n", (unsigned int)current, (unsigned int)max);
}

original_code:
void dump_qs ()
{
  int i;
  ((void) sizeof ((qs) ? 1 : 0), __extension__ ({ if (qs) ; else __assert_fail ("qs", "queue.c", 27, __extension__ __PRETTY_FUNCTION__); }));
  printf ("\nQ-Dump [%d, %d]\n", current, max);
return;
  for (i = current; i <= max; i++)
    {
      printf ("q [%d]: ", i);
      entry *e = qs [i];
      if (!e)
 printf (" is empty");
      else while (e)
 {
   printf ("%p->(%p,%p) ", e, e->value, e->next);
   e = e->next;
 }
      printf ("\n");
    }
}

canonical_original_code:
void dump_qs()
{
  int i;
  ((void) sizeof ((qs) ? 1 : 0), __extension__ ({ if (qs) ; else __assert_fail ("qs", "queue.c", 27, __extension__ __PRETTY_FUNCTION__); }));
  printf ("\nQ-Dump [%d, %d]\n", current, max);
return;
  for (i = current; i <= max; i++)
    {
      printf ("q [%d]: ", i);
      struct _entry *e = qs [i];
      if (!e)
 printf (" is empty");
      else while (e)
 {
   printf ("%p->(%p,%p) ", e, e->value, e->next);
   e = e->next;
 }
      printf ("\n");
    }
}

variable_types: struct _entry { void *value; struct _entry *next; } *


decompiled_code:
void *queue_init()
{
void *v0; // r12
void **v1; // rbx
void **v2; // rbp
void *result; // rax

v0 = qs;
if ( qs )
{
if ( max >= 0 )
{
v1 = (void **)qs;
v2 = (void **)((char *)qs + 8 * max + 8);
do
{
if ( *v1 )
{
free(*v1);
*v1 = 0LL;
}
++v1;
}
while ( v1 != v2 );
}
free(v0);
}
result = calloc(8uLL, MAXCOST);
qs = result;
if ( !result )
{
perror("queue_init () - calloc()");
exit(1);
}
current = 0;
max = -1;
return result;
}

canonical_decompiled_code:
void *func1()
{
void *v0; // r12
void **v1; // rbx
void **v2; // rbp
void *result; // rax

v0 = qs;
if ( qs )
{
if ( max >= 0 )
{
v1 = (void **)qs;
v2 = (void **)((char *)qs + 8 * max + 8);
do
{
if ( *v1 )
{
free(*v1);
*v1 = 0LL;
}
++v1;
}
while ( v1 != v2 );
}
free(v0);
}
result = calloc(8uLL, MAXCOST);
qs = result;
if ( !result )
{
perror("queue_init () - calloc()");
exit(1);
}
current = 0;
max = -1;
return result;
}

original_code:
void queue_init (void)
{
  if (qs)
    {
      int i;
      for (i = 0; i <= max; i++)
 {
   if (qs [i])
     {
       free (qs [i]);
       qs [i] = ((void *)0);
     }
 }
      free (qs);
    }
  qs = calloc (sizeof (entry *), MAXCOST);
  if (!qs)
    {
      perror ("queue_init () - calloc()");
      exit (1);
    }
  current = 0;
  max = -1;
}

canonical_original_code:
void queue_init()
{
  if (qs)
    {
      int i;
      for (i = 0; i <= max; i++)
 {
   if (qs [i])
     {
       free (qs [i]);
       qs [i] = ((void *)0);
     }
 }
      free (qs);
    }
  qs = calloc (sizeof (struct _entry *), MAXCOST);
  if (!qs)
    {
      perror ("queue_init () - calloc()");
      exit (1);
    }
  current = 0;
  max = -1;
}

user_defined_types: struct _entry { void *value; struct _entry *next; }


decompiled_code:
__int64 __fastcall queue_insert(int a1, __int64 a2)
{
char *v2; // r12
_QWORD *v3; // rax
char *v4; // rdx

v2 = (char *)qs;
if ( !qs )
_assert_fail("qs", "queue.c", 0x50u, "queue_insert");
if ( current > a1 )
return 0LL;
if ( max < a1 )
{
if ( MAXCOST <= a1 )
return 0LL;
max = a1;
}
v3 = malloc(0x10uLL);
if ( v3 )
{
v4 = &v2[8 * a1];
*v3 = a2;
v3[1] = *(_QWORD *)v4;
*(_QWORD *)v4 = v3;
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
char *v2; // r12
_QWORD *v3; // rax
char *v4; // rdx

v2 = (char *)qs;
if ( !qs )
_assert_fail("qs", "queue.c", 0x50u, "queue_insert");
if ( current > a1 )
return 0LL;
if ( max < a1 )
{
if ( MAXCOST <= a1 )
return 0LL;
max = a1;
}
v3 = malloc(0x10uLL);
if ( v3 )
{
v4 = &v2[8 * a1];
*v3 = a2;
v3[1] = *(_QWORD *)v4;
*(_QWORD *)v4 = v3;
return 1LL;
}
return 0LL;
}

original_code:
_Bool queue_insert (int cost, void *val)
{
  ((void) sizeof ((qs) ? 1 : 0), __extension__ ({ if (qs) ; else __assert_fail ("qs", "queue.c", 80, __extension__ __PRETTY_FUNCTION__); }));
  if (cost < current)
    return 0;
  if (cost > max)
    {
      if (cost >= MAXCOST)
 return 0;
      max = cost;
    }
  entry *e = (entry *) malloc (sizeof (entry));
  if (!e) return 0;
  e->value = val;
  e->next = qs [cost];
  qs [cost] = e;
  return 1;
}

canonical_original_code:
_Bool queue_insert(int cost, void *val)
{
  ((void) sizeof ((qs) ? 1 : 0), __extension__ ({ if (qs) ; else __assert_fail ("qs", "queue.c", 80, __extension__ __PRETTY_FUNCTION__); }));
  if (cost < current)
    return 0;
  if (cost > max)
    {
      if (cost >= MAXCOST)
 return 0;
      max = cost;
    }
  struct _entry *e = (entry *) malloc (sizeof (entry));
  if (!e) return 0;
  e->value = val;
  e->next = qs [cost];
  qs [cost] = e;
  return 1;
}

variable_types: cost int

variable_types:
val
void *


decompiled_code:
__int64 queue_grabfront()
{
int v0; // eax
__int64 **v1; // rdx
char i; // si
__int64 *v3; // rdi
__int64 v4; // r12

if ( !qs )
_assert_fail("qs", "queue.c", 0x6Du, "queue_grabfront");
v0 = current;
if ( max < current )
return 0LL;
v1 = (__int64 **)((char *)qs + 8 * current);
for ( i = 0; ; i = 1 )
{
v3 = *v1;
if ( *v1 )
break;
++v0;
++v1;
if ( v0 > max )
{
current = v0;
return 0LL;
}
}
if ( i )
current = v0;
v4 = *v3;
*v1 = (__int64 *)v3[1];
free(v3);
return v4;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
__int64 **v1; // rdx
char i; // si
__int64 *v3; // rdi
__int64 v4; // r12

if ( !qs )
_assert_fail("qs", "queue.c", 0x6Du, "queue_grabfront");
v0 = current;
if ( max < current )
return 0LL;
v1 = (__int64 **)((char *)qs + 8 * current);
for ( i = 0; ; i = 1 )
{
v3 = *v1;
if ( *v1 )
break;
++v0;
++v1;
if ( v0 > max )
{
current = v0;
return 0LL;
}
}
if ( i )
current = v0;
v4 = *v3;
*v1 = (__int64 *)v3[1];
free(v3);
return v4;
}

original_code:
void *queue_grabfront (void)
{
  ((void) sizeof ((qs) ? 1 : 0), __extension__ ({ if (qs) ; else __assert_fail ("qs", "queue.c", 109, __extension__ __PRETTY_FUNCTION__); }));
  while (current <= max && !qs [current])
     {
     current++;
     }
  if (current > max) return ((void *)0);
  entry *e = qs [current];
  void *v = e->value;
  qs [current] = e->next;
  free (e);
  return v;
}

canonical_original_code:
void *queue_grabfront()
{
  ((void) sizeof ((qs) ? 1 : 0), __extension__ ({ if (qs) ; else __assert_fail ("qs", "queue.c", 109, __extension__ __PRETTY_FUNCTION__); }));
  while (current <= max && !qs [current])
     {
     current++;
     }
  if (current > max) return ((void *)0);
  struct _entry *e = qs [current];
  void *v = e->value;
  qs [current] = e->next;
  free (e);
  return v;
}

variable_types:
v
void *


decompiled_code:
__int64 __fastcall parse_constant(const char *a1, char **a2)
{
char *v2; // r15
__int64 v3; // rbx
__int64 v4; // r13
int v5; // er14
const __int32_t *v6; // rax
const char *v7; // rdi
char **v8; // rbx
__int64 result; // rax
const unsigned __int16 *v10; // [rsp+0h] [rbp-58h]
char s2[67]; // [rsp+15h] [rbp-43h] BYREF

v2 = *a2;
v3 = **a2;
if ( (_BYTE)v3 )
{
v4 = 0LL;
v10 = *__ctype_b_loc();
do
{
v5 = v4;
if ( (v10[v3] & 8) == 0 )
break;
if ( v4 == 10 )
{
v5 = 10;
break;
}
++v2;
v5 = v4 + 1;
v6 = *__ctype_toupper_loc();
*a2 = v2;
s2[v4] = v6[*(v2 - 1)];
v3 = *v2;
++v4;
}
while ( (_BYTE)v3 );
}
else
{
v5 = 0;
}
s2[v5] = 0;
if ( *v2 )
fprintf(stderr, "config: Variable '%s': ignoring trailing junk after value (%s)!\n", a1, s2);
v7 = constants;
if ( constants )
{
v8 = &constants;
while ( strcmp(v7, s2) )
{
v7 = v8[2];
v8 += 2;
if ( !v7 )
goto LABEL_14;
}
result = *((unsigned int *)v8 + 2);
}
else
{
LABEL_14:
fprintf(stderr, "config: Variable '%s': constant %s unknown!\n", a1, s2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, char **a2)
{
char *v2; // r15
__int64 v3; // rbx
__int64 v4; // r13
int v5; // er14
const __int32_t *v6; // rax
const char *v7; // rdi
char **v8; // rbx
__int64 result; // rax
const unsigned __int16 *v10; // [rsp+0h] [rbp-58h]
char s2[67]; // [rsp+15h] [rbp-43h] BYREF

v2 = *a2;
v3 = **a2;
if ( (_BYTE)v3 )
{
v4 = 0LL;
v10 = *__ctype_b_loc();
do
{
v5 = v4;
if ( (v10[v3] & 8) == 0 )
break;
if ( v4 == 10 )
{
v5 = 10;
break;
}
++v2;
v5 = v4 + 1;
v6 = *__ctype_toupper_loc();
*a2 = v2;
s2[v4] = v6[*(v2 - 1)];
v3 = *v2;
++v4;
}
while ( (_BYTE)v3 );
}
else
{
v5 = 0;
}
s2[v5] = 0;
if ( *v2 )
fprintf(stderr, "config: Variable '%s': ignoring trailing junk after value (%s)!\n", a1, s2);
v7 = constants;
if ( constants )
{
v8 = &constants;
while ( strcmp(v7, s2) )
{
v7 = v8[2];
v8 += 2;
if ( !v7 )
goto LABEL_14;
}
result = *((unsigned int *)v8 + 2);
}
else
{
LABEL_14:
fprintf(stderr, "config: Variable '%s': constant %s unknown!\n", a1, s2);
result = 0LL;
}
return result;
}

original_code:
static int parse_constant (const char *var, const char **val)
{
  char buf [11];
  int i = 0;
  named_const *c;
  while (**val && ((*__ctype_b_loc ())[(int) ((**val))] & (unsigned short int) _ISalnum) && i < 10)
    buf [i++] = toupper (*((*val)++));
  buf [i] = '\0';
  if (**val)
    fprintf (stderr, "config: Variable '%s': ignoring trailing junk after value (%s)!\n", var, buf);
  for (c = constants; c->name; c++)
    if (strcmp (c->name, buf) == 0)
      return c->value;
  fprintf (stderr, "config: Variable '%s': constant %s unknown!\n", var, buf);
  return 0;
}

canonical_original_code:
static int parse_constant(char *var, char **val)
{
  char buf[11];
  int i = 0;
  struct named_const *c;
  while (**val && ((*__ctype_b_loc ())[(int) ((**val))] & (unsigned short) _ISalnum) && i < 10)
    buf [i++] = toupper (*((*val)++));
  buf [i] = '\0';
  if (**val)
    fprintf (stderr, "config: Variable '%s': ignoring trailing junk after value (%s)!\n", var, buf);
  for (c = constants; c->name; c++)
    if (strcmp (c->name, buf) == 0)
      return c->value;
  fprintf (stderr, "config: Variable '%s': constant %s unknown!\n", var, buf);
  return 0;
}

variable_types:
var
char *

variable_types:
val
char **

variable_types:
buf
char [11]

variable_types: struct named_const { char *name; int value; } *


decompiled_code:
unsigned int __fastcall handle_num(const char *a1, unsigned int *a2, char *a3)
{
const char *v3; // rbp
__int64 v4; // r13
unsigned int result; // eax
char *v6; // rcx
char *v7; // [rsp+8h] [rbp-40h] BYREF
char *endptr; // [rsp+18h] [rbp-30h] BYREF

v3 = a3;
v7 = a3;
if ( (*a3 & 0xDF) == 80 )
{
v3 = a3 + 1;
v7 = a3 + 1;
}
else
{
v4 = *a3;
if ( ((*__ctype_b_loc())[v4] & 0x400) != 0 )
{
result = parse_constant(a1, &v7);
*a2 = result;
return result;
}
}
result = strtol(v3, &endptr, 0);
v6 = endptr;
*a2 = result;
if ( *v6 )
result = fprintf(stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", a1, v6, result);
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func8(const char *a1, unsigned int *a2, char *a3)
{
const char *v3; // rbp
__int64 v4; // r13
unsigned int result; // eax
char *v6; // rcx
char *v7; // [rsp+8h] [rbp-40h] BYREF
char *endptr; // [rsp+18h] [rbp-30h] BYREF

v3 = a3;
v7 = a3;
if ( (*a3 & 0xDF) == 80 )
{
v3 = a3 + 1;
v7 = a3 + 1;
}
else
{
v4 = *a3;
if ( ((*__ctype_b_loc())[v4] & 0x400) != 0 )
{
result = func7(a1, &v7);
*a2 = result;
return result;
}
}
result = strtol(v3, &endptr, 0);
v6 = endptr;
*a2 = result;
if ( *v6 )
result = fprintf(stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", a1, v6, result);
return result;
}

original_code:
static void handle_num (const char *var, int *v_ptr, const char *val)
{
  char *end;
  if (*val == 'p' || *val == 'P')
    val++;
  else if (((*__ctype_b_loc ())[(int) ((*val))] & (unsigned short int) _ISalpha))
    {
      *v_ptr = parse_constant (var, &val);
      return;
    }
  *v_ptr = strtol (val, &end, 0);
  if (*end)
    fprintf (stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", var, end, *v_ptr);
}

canonical_original_code:
static void handle_num(char *var, int *v_ptr, char *val)
{
  char *end;
  if (*val == 'p' || *val == 'P')
    val++;
  else if (((*__ctype_b_loc ())[(int) ((*val))] & (unsigned short) _ISalpha))
    {
      *v_ptr = parse_constant (var, &val);
      return;
    }
  *v_ptr = strtol (val, &end, 0);
  if (*end)
    fprintf (stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", var, end, *v_ptr);
}

variable_types:
val
char *

variable_types:
end
char *


decompiled_code:
__int64 __fastcall handle_bool(const char *a1, bool *a2, char *a3)
{
const char *v3; // rbp
__int64 v4; // r12
bool v5; // zf
char *v6; // rax
__int64 result; // rax
char *nptr; // [rsp+8h] [rbp-40h] BYREF
char *endptr; // [rsp+18h] [rbp-30h] BYREF

v3 = a3;
nptr = a3;
if ( (*a3 & 0xDF) == 80 )
{
v3 = a3 + 1;
nptr = a3 + 1;
}
else
{
v4 = *a3;
if ( ((*__ctype_b_loc())[v4] & 0x400) != 0 )
{
result = parse_constant(a1, &nptr);
*a2 = (_DWORD)result != 0;
return result;
}
}
v5 = strtol(v3, &endptr, 0) == 0;
v6 = endptr;
*a2 = !v5;
if ( !*v6 )
fprintf(stderr, "config: Variable '%s': ignoring trailing junk after value (%d)!\n", a1, !v5);
result = strtol(nptr, 0LL, 10);
*a2 = result != 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, bool *a2, char *a3)
{
const char *v3; // rbp
__int64 v4; // r12
bool v5; // zf
char *v6; // rax
__int64 result; // rax
char *nptr; // [rsp+8h] [rbp-40h] BYREF
char *endptr; // [rsp+18h] [rbp-30h] BYREF

v3 = a3;
nptr = a3;
if ( (*a3 & 0xDF) == 80 )
{
v3 = a3 + 1;
nptr = a3 + 1;
}
else
{
v4 = *a3;
if ( ((*__ctype_b_loc())[v4] & 0x400) != 0 )
{
result = func7(a1, &nptr);
*a2 = (_DWORD)result != 0;
return result;
}
}
v5 = strtol(v3, &endptr, 0) == 0;
v6 = endptr;
*a2 = !v5;
if ( !*v6 )
fprintf(stderr, "config: Variable '%s': ignoring trailing junk after value (%d)!\n", a1, !v5);
result = strtol(nptr, 0LL, 10);
*a2 = result != 0;
return result;
}

original_code:
static void handle_bool (const char *var, _Bool *v_ptr, const char *val)
{
  char *end;
  if (*val == 'p' || *val == 'P')
    val++;
  else if (((*__ctype_b_loc ())[(int) ((*val))] & (unsigned short int) _ISalpha))
    {
      *v_ptr = parse_constant (var, &val);
      return;
    }
  *v_ptr = strtol (val, &end, 0);
  if (!*end)
    fprintf (stderr, "config: Variable '%s': ignoring trailing junk after value (%d)!\n", var, *v_ptr);
  *v_ptr = (strtol (val, ((void *)0), 10) != 0);
}

canonical_original_code:
static void handle_bool(char *var, _Bool *v_ptr, char *val)
{
  char *end;
  if (*val == 'p' || *val == 'P')
    val++;
  else if (((*__ctype_b_loc ())[(int) ((*val))] & (unsigned short) _ISalpha))
    {
      *v_ptr = parse_constant (var, &val);
      return;
    }
  *v_ptr = strtol (val, &end, 0);
  if (!*end)
    fprintf (stderr, "config: Variable '%s': ignoring trailing junk after value (%d)!\n", var, *v_ptr);
  *v_ptr = (strtol (val, ((void *)0), 10) != 0);
}


decompiled_code:
int __fastcall handle_array(const char *a1, char **a2, int *a3, __int64 a4)
{
char *v6; // rbp
size_t v7; // rax
char *v8; // rax
__int64 v9; // rbx
const unsigned __int16 **v10; // r15
int v11; // eax
char *v12; // rdx
char *v13; // rdi
int v14; // er8
__int64 v15; // rax
int v16; // ebx
char *v17; // rax
const char *v18; // rcx
int v19; // er15
char *v20; // rax
char *v21; // rax
char *v22; // rdi
int v23; // er8
int v24; // esi
int v25; // eax
int v26; // et2
char *v28[2]; // [rsp+8h] [rbp-50h] BYREF
char *endptr; // [rsp+18h] [rbp-40h] BYREF

v6 = (char *)a4;
v28[0] = (char *)a4;
if ( *(_BYTE *)a4 == 91 )
{
v16 = strtol((const char *)(a4 + 1), v28, 0);
if ( v16 > 0 )
{
v17 = skip_ws(v28[0]);
v28[0] = v17;
v18 = v17;
if ( *v17 != 37 )
goto LABEL_20;
v19 = strtol(v17 + 1, v28, 0);
if ( v16 < v19 )
{
v20 = skip_ws(v28[0]);
v28[0] = v20;
v18 = v20;
if ( *v20 == 93 )
{
if ( v20[1] )
fprintf(stderr, "config: Variable '%s': ignoring trailing garbage ('%s')!\n", a1, v20 + 1);
v21 = (char *)calloc(v19, 4uLL);
*a2 = v21;
v22 = v21;
if ( v21 )
{
v23 = v16;
v24 = 1;
do
{
v25 = v16;
v16 += v23;
v26 = v25 % v19;
LODWORD(v8) = v25 / v19;
*(_DWORD *)&v22[4 * v26] = v24++;
}
while ( v19 >= v24 );
*a3 = v19;
return (int)v8;
}
LABEL_21:
perror("config::handle_array() - calloc");
exit(1);
}
LABEL_20:
LODWORD(v8) = fprintf(stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", a1, v18);
return (int)v8;
}
}
v18 = v28[0];
goto LABEL_20;
}
v7 = strlen((const char *)a4);
v8 = (char *)calloc((v7 >> 1) + 1, 4uLL);
*a2 = v8;
if ( !v8 )
goto LABEL_21;
*a3 = 0;
endptr = v6;
v9 = *v6;
if ( (_BYTE)v9 )
{
v10 = __ctype_b_loc();
while ( ((*v10)[v9] & 0x800) != 0 )
{
v11 = strtol(v6, &endptr, 0);
v12 = *a2;
v13 = endptr;
v14 = v11;
v15 = *a3;
*a3 = v15 + 1;
*(_DWORD *)&v12[4 * v15] = v14;
v8 = skip_ws(v13);
endptr = v8;
v9 = *v8;
v6 = v8;
if ( !(_BYTE)v9 )
return (int)v8;
}
LODWORD(v8) = fprintf(stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", a1, v6, *a2);
}
return (int)v8;
}

canonical_decompiled_code:
int __fastcall func12(const char *a1, char **a2, int *a3, __int64 a4)
{
char *v6; // rbp
size_t v7; // rax
char *v8; // rax
__int64 v9; // rbx
const unsigned __int16 **v10; // r15
int v11; // eax
char *v12; // rdx
char *v13; // rdi
int v14; // er8
__int64 v15; // rax
int v16; // ebx
char *v17; // rax
const char *v18; // rcx
int v19; // er15
char *v20; // rax
char *v21; // rax
char *v22; // rdi
int v23; // er8
int v24; // esi
int v25; // eax
int v26; // et2
char *v28[2]; // [rsp+8h] [rbp-50h] BYREF
char *endptr; // [rsp+18h] [rbp-40h] BYREF

v6 = (char *)a4;
v28[0] = (char *)a4;
if ( *(_BYTE *)a4 == 91 )
{
v16 = strtol((const char *)(a4 + 1), v28, 0);
if ( v16 > 0 )
{
v17 = func11(v28[0]);
v28[0] = v17;
v18 = v17;
if ( *v17 != 37 )
goto LABEL_20;
v19 = strtol(v17 + 1, v28, 0);
if ( v16 < v19 )
{
v20 = func11(v28[0]);
v28[0] = v20;
v18 = v20;
if ( *v20 == 93 )
{
if ( v20[1] )
fprintf(stderr, "config: Variable '%s': ignoring trailing garbage ('%s')!\n", a1, v20 + 1);
v21 = (char *)calloc(v19, 4uLL);
*a2 = v21;
v22 = v21;
if ( v21 )
{
v23 = v16;
v24 = 1;
do
{
v25 = v16;
v16 += v23;
v26 = v25 % v19;
LODWORD(v8) = v25 / v19;
*(_DWORD *)&v22[4 * v26] = v24++;
}
while ( v19 >= v24 );
*a3 = v19;
return (int)v8;
}
LABEL_21:
perror("config::handle_array() - calloc");
exit(1);
}
LABEL_20:
LODWORD(v8) = fprintf(stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", a1, v18);
return (int)v8;
}
}
v18 = v28[0];
goto LABEL_20;
}
v7 = strlen((const char *)a4);
v8 = (char *)calloc((v7 >> 1) + 1, 4uLL);
*a2 = v8;
if ( !v8 )
goto LABEL_21;
*a3 = 0;
endptr = v6;
v9 = *v6;
if ( (_BYTE)v9 )
{
v10 = __ctype_b_loc();
while ( ((*v10)[v9] & 0x800) != 0 )
{
v11 = strtol(v6, &endptr, 0);
v12 = *a2;
v13 = endptr;
v14 = v11;
v15 = *a3;
*a3 = v15 + 1;
*(_DWORD *)&v12[4 * v15] = v14;
v8 = func11(v13);
endptr = v8;
v9 = *v8;
v6 = v8;
if ( !(_BYTE)v9 )
return (int)v8;
}
LODWORD(v8) = fprintf(stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", a1, v6, *a2);
}
return (int)v8;
}

original_code:
static void handle_array (const char *var, int **v_ptr, int *n_ptr, char *val)
{
  char *end;
  if (*val == '[')
    {
      int step, nLanes, k;
      step = strtol (val+1, &val, 0);
      if (step <= 0)
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      val = skip_ws (val);
      if (*val != '%')
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      nLanes = strtol (val+1, &val, 0);
      if (nLanes <= step)
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      val = skip_ws (val);
      if (*val != ']')
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      if (val [1])
 fprintf (stderr, "config: Variable '%s': ignoring trailing garbage ('%s')!\n", var, val+1);
      *v_ptr = calloc (nLanes, sizeof (int));
      if (!*v_ptr)
 {
   perror ("config::handle_array() - calloc");
   exit (1);
 }
      for (k = 1; k <= nLanes; k++)
 (*v_ptr) [(k*step)%nLanes] = k;
      *n_ptr = nLanes;
      return;
    }
  *v_ptr = calloc (1+strlen (val)/2, sizeof (int));
  if (!*v_ptr)
    {
      perror ("config::handle_array() - calloc");
      exit (1);
    }
  *n_ptr = 0;
  end = val;
  while (*end)
    {
      if (!((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short int) _ISdigit))
 {
   fprintf (stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", var, end, *v_ptr);
   return;
 }
      (*v_ptr) [(*n_ptr)++] = strtol (end, &end, 0);
      end = skip_ws (end);
    }
}

canonical_original_code:
static void handle_array(char *var, int **v_ptr, int *n_ptr, char *val)
{
  char *end;
  if (*val == '[')
    {
      int step; int nLanes; int k;
      step = strtol (val+1, &val, 0);
      if (step <= 0)
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      val = skip_ws (val);
      if (*val != '%')
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      nLanes = strtol (val+1, &val, 0);
      if (nLanes <= step)
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      val = skip_ws (val);
      if (*val != ']')
 {
   fprintf (stderr, "config: Variable '%s': illeagal use of [9 %% 31] notation ->%s!\n", var, val);
   return;
 }
      if (val [1])
 fprintf (stderr, "config: Variable '%s': ignoring trailing garbage ('%s')!\n", var, val+1);
      *v_ptr = calloc (nLanes, sizeof (int));
      if (!*v_ptr)
 {
   perror ("config::handle_array() - calloc");
   exit (1);
 }
      for (k = 1; k <= nLanes; k++)
 (*v_ptr) [(k*step)%nLanes] = k;
      *n_ptr = nLanes;
      return;
    }
  *v_ptr = calloc (1+strlen (val)/2, sizeof (int));
  if (!*v_ptr)
    {
      perror ("config::handle_array() - calloc");
      exit (1);
    }
  *n_ptr = 0;
  end = val;
  while (*end)
    {
      if (!((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short) _ISdigit))
 {
   fprintf (stderr, "config: Variable '%s': ignoring trailing junk '%s' after value (%d)!\n", var, end, *v_ptr);
   return;
 }
      (*v_ptr) [(*n_ptr)++] = strtol (end, &end, 0);
      end = skip_ws (end);
    }
}

variable_types: step int

variable_types: nLanes int

variable_types: k int