decodeChunkSignaling

decompiled_code:
__int64 __fastcall decodeChunkSignaling(_QWORD *a1, int *a2, unsigned int *a3, unsigned int a4)
{
unsigned int v7; // er15
int v8; // er12
const void *v9; // rbx
__int64 v10; // r12
const char *v12; // rax
__int64 v13; // rax
void *v14; // rdi
__int64 v15[11]; // [rsp+0h] [rbp-58h] BYREF

v7 = int_rcpy(a3);
v8 = int_rcpy(a3 + 1);
*a2 = int_rcpy(a3 + 2);
if ( v8 == -1 )
{
v9 = a3 + 3;
v10 = 0LL;
}
else
{
v15[0] = 0LL;
v15[1] = 0LL;
v15[2] = 0LL;
v15[3] = 0LL;
v12 = type_name(v8);
sprintf((char *)v15, "size=%d,type=%s", v7, v12);
v13 = chunkID_set_init(v15);
v10 = v13;
if ( !v13 )
{
fwrite("Error in decoding chunkid set - not enough memory to create a chunkID set.\n", 1uLL, 0x4BuLL, stderr);
return v10;
}
v9 = (const void *)(*(__int64 (__fastcall **)(__int64, unsigned int *, _QWORD, int *))(*(_QWORD *)(v13 + 32) + 8LL))(
v13,
a3,
a4,
a2);
}
if ( *a2 )
{
v14 = malloc(*a2);
*a1 = v14;
if ( v14 )
memcpy(v14, v9, *a2);
else
*a2 = 0;
}
else
{
*a1 = 0LL;
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, int *a2, unsigned int *a3, unsigned int a4)
{
unsigned int v7; // er15
int v8; // er12
const void *v9; // rbx
__int64 v10; // r12
const char *v12; // rax
__int64 v13; // rax
void *v14; // rdi
__int64 v15[11]; // [rsp+0h] [rbp-58h] BYREF

v7 = func3(a3);
v8 = func3(a3 + 1);
*a2 = func3(a3 + 2);
if ( v8 == -1 )
{
v9 = a3 + 3;
v10 = 0LL;
}
else
{
v15[0] = 0LL;
v15[1] = 0LL;
v15[2] = 0LL;
v15[3] = 0LL;
v12 = func0(v8);
sprintf((char *)v15, "size=%d,type=%s", v7, v12);
v13 = chunkID_set_init(v15);
v10 = v13;
if ( !v13 )
{
fwrite("Error in decoding chunkid set - not enough memory to create a chunkID set.\n", 1uLL, 0x4BuLL, stderr);
return v10;
}
v9 = (const void *)(*(__int64 (__fastcall **)(__int64, unsigned int *, _QWORD, int *))(*(_QWORD *)(v13 + 32) + 8LL))(
v13,
a3,
a4,
a2);
}
if ( *a2 )
{
v14 = malloc(*a2);
*a1 = v14;
if ( v14 )
memcpy(v14, v9, *a2);
else
*a2 = 0;
}
else
{
*a1 = 0LL;
}
return v10;
}

original_code:
struct chunkID_set *decodeChunkSignaling(void **meta, int *meta_len, const uint8_t *buff, int buff_len)
{
  uint32_t size;
  uint32_t type;
  struct chunkID_set *h;
  const uint8_t *meta_p;
  size = int_rcpy(buff);
  type = int_rcpy(buff + 4);
  *meta_len = int_rcpy(buff + 8);
  if (type != -1) {
    char cfg[32];
    memset(cfg, 0, sizeof(cfg));
    sprintf(cfg, "size=%d,type=%s", size, type_name(type));
    h = chunkID_set_init(cfg);
    if (h == ((void *)0)) {
      fprintf(stderr, "Error in decoding chunkid set - not enough memory to create a chunkID set.\n");
      return ((void *)0);
    }
    meta_p = h->enc->decode(h, buff, buff_len, meta_len);
  } else {
    h = ((void *)0);
    meta_p = buff + 12;
  }
  if (*meta_len) {
    *meta = malloc(*meta_len);
    if (*meta != ((void *)0)) {
      memcpy(*meta, meta_p, *meta_len);
    } else {
      *meta_len = 0;
    }
  } else {
    *meta = ((void *)0);
  }
  return h;
}

canonical_original_code:
struct chunkID_set *decodeChunkSignaling(void **meta, int *meta_len, unsigned char *buff, int buff_len)
{
  unsigned int size;
  unsigned int type;
  struct chunkID_set *h;
  unsigned char *meta_p;
  size = int_rcpy(buff);
  type = int_rcpy(buff + 4);
  *meta_len = int_rcpy(buff + 8);
  if (type != -1) {
    char cfg[32];
    memset(cfg, 0, sizeof(cfg));
    sprintf(cfg, "size=%d,type=%s", size, type_name(type));
    h = chunkID_set_init(cfg);
    if (h == ((void *)0)) {
      fprintf(stderr, "Error in decoding chunkid set - not enough memory to create a chunkID set.\n");
      return ((void *)0);
    }
    meta_p = h->enc->decode(h, buff, buff_len, meta_len);
  } else {
    h = ((void *)0);
    meta_p = buff + 12;
  }
  if (*meta_len) {
    *meta = malloc(*meta_len);
    if (*meta != ((void *)0)) {
      memcpy(*meta, meta_p, *meta_len);
    } else {
      *meta_len = 0;
    }
  } else {
    *meta = ((void *)0);
  }
  return h;
}

variable_types:
meta
void **

variable_types:
size
unsigned int

variable_types:
cfg
char [32]

return_type: struct chunkID_set { unsigned int type; unsigned int size; unsigned int n_elements; int *elements; struct cids_ops_iface { int (*add_chunk)(struct chunkID_set *h, int chunk_id); int (*check)(struct chunkID_set *h, int chunk_id); } *ops; struct cids_encoding_iface { unsigned char *(*encode)(struct chunkID_set *h, unsigned char *buff, int buff_len, int meta_len); unsigned char *(*decode)(struct chunkID_set *h, unsigned char *buff, int buff_len, int *meta_len); } *enc; } *


dumbGrowNeighbourhood

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

if ( a1 <= 0 )
return 0xFFFFFFFFLL;
if ( do_resize )
return 0xFFFFFFFFLL;
if ( cache_size <= a1 )
a1 = cache_size;
result = (unsigned int)(a1 + cache_size);
cache_size += a1;
do_resize = 1;
return result;
}

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

if ( a1 <= 0 )
return 0xFFFFFFFFLL;
if ( do_resize )
return 0xFFFFFFFFLL;
if ( cache_size <= a1 )
a1 = cache_size;
result = (unsigned int)(a1 + cache_size);
cache_size += a1;
do_resize = 1;
return result;
}

original_code:
static int dumbGrowNeighbourhood(int n)
{
 if (n <= 0 || do_resize)
  return -1;
 n = n > cache_size ? cache_size : n;
 cache_size += n;
 do_resize = 1;
 return cache_size;
}

variable_types: n int

return_type: int


dumbShrinkNeighbourhood

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

if ( a1 <= 0 )
return 0xFFFFFFFFLL;
if ( cache_size <= a1 )
return 0xFFFFFFFFLL;
if ( do_resize )
return 0xFFFFFFFFLL;
result = (unsigned int)(cache_size - a1);
cache_size -= a1;
do_resize = 1;
return result;
}

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

if ( a1 <= 0 )
return 0xFFFFFFFFLL;
if ( cache_size <= a1 )
return 0xFFFFFFFFLL;
if ( do_resize )
return 0xFFFFFFFFLL;
result = (unsigned int)(cache_size - a1);
cache_size -= a1;
do_resize = 1;
return result;
}

original_code:
static int dumbShrinkNeighbourhood(int n)
{
 if (n <= 0 || n >= cache_size || do_resize)
  return -1;
 cache_size -= n;
 do_resize = 1;
 return cache_size;
}


dumbGetNeighbourhoodSize

decompiled_code:
__int64 dumbGetNeighbourhoodSize()
{
unsigned int i; // ebx

for ( i = 0; nodeid(local_cache, i); ++i )
;
return i;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int i; // ebx

for ( i = 0; nodeid(local_cache, i); ++i )
;
return i;
}

original_code:
static int dumbGetNeighbourhoodSize(void)
{
 int i;
 for (i = 0; nodeid(local_cache, i); i++);
 return i;
}

canonical_original_code:
static int dumbGetNeighbourhoodSize()
{
 int i;
 for (i = 0; nodeid(local_cache, i); i++);
 return i;
}

variable_types: i int


dumbGetMetadata

decompiled_code:
__int64 __fastcall dumbGetMetadata(__int64 a1)
{
return get_metadata(local_cache, a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return get_metadata(local_cache, a1);
}

original_code:
static const void *dumbGetMetadata(int *metadata_size)
{
 return get_metadata(local_cache, metadata_size);
}

canonical_original_code:
static void *dumbGetMetadata(int *metadata_size)
{
 return get_metadata(local_cache, metadata_size);
}

return_type: void *


dumbChangeMetadata

decompiled_code:
__int64 __fastcall dumbChangeMetadata(void *src, int a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( a2 )
{
if ( mdata_size == a2 )
{
memcpy(my_mdata, src, a2);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *src, int a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( a2 )
{
if ( mdata_size == a2 )
{
memcpy(my_mdata, src, a2);
result = 1LL;
}
}
return result;
}

original_code:
static int dumbChangeMetadata(void *metadata, int metadata_size)
{
 if (metadata_size && metadata_size == mdata_size) {
  memcpy(my_mdata, (uint8_t *)metadata, mdata_size);
  return 1;
 }
 else return -1;
}

canonical_original_code:
static int dumbChangeMetadata(void *metadata, int metadata_size)
{
 if (metadata_size && metadata_size == mdata_size) {
  memcpy(my_mdata, (unsigned char *)metadata, mdata_size);
  return 1;
 }
 else return -1;
}

variable_types:
metadata
void *


decompiled_code:
__int64 time_to_run()
{
__suseconds_t v0; // rax
unsigned int v1; // ecx

v0 = gettime();
v1 = 0;
if ( v0 - currtime > (unsigned __int64)period )
{
currtime += period;
v1 = 1;
}
return v1;
}

canonical_decompiled_code:
__int64 func9()
{
__suseconds_t v0; // rax
unsigned int v1; // ecx

v0 = func8();
v1 = 0;
if ( v0 - currtime > (unsigned __int64)period )
{
currtime += period;
v1 = 1;
}
return v1;
}

original_code:
static int time_to_run(void)
{
 if (gettime() - currtime > period) {
  currtime += period;
  return 1;
 }
 return 0;
}

canonical_original_code:
static int time_to_run()
{
 if (gettime() - currtime > period) {
  currtime += period;
  return 1;
 }
 return 0;
}


gettime

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

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

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

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

original_code:
static uint64_t gettime(void)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return tv.tv_usec + tv.tv_sec * 1000000ull;
}

canonical_original_code:
static unsigned long gettime()
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return tv.tv_usec + tv.tv_sec * 1000000ull;
}

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

return_type: unsigned long


topoChangeMetadata

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

result = psample_change_metadata(context, a1, a2);
if ( counter > 4 )
result = tmanChangeMetadata(a1, a2);
return result;
}

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

result = psample_change_metadata(context, a1, a2);
if ( counter > 4 )
result = tmanChangeMetadata(a1, a2);
return result;
}

original_code:
int topoChangeMetadata(void *metadata, int metadata_size)
{
 int res = psample_change_metadata(context,metadata,metadata_size);
 if (counter >= 5)
  return tmanChangeMetadata(metadata,metadata_size);
 else return res;
}

variable_types: res int


topoGetMetadata

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

if ( (unsigned int)tmanGetNeighbourhoodSize() )
result = tmanGetMetadata(a1);
else
result = psample_get_metadata(context, a1);
return result;
}

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

if ( (unsigned int)tmanGetNeighbourhoodSize() )
result = tmanGetMetadata(a1);
else
result = psample_get_metadata(context, a1);
return result;
}

original_code:
const void *topoGetMetadata(int *metadata_size)
{
 int n = tmanGetNeighbourhoodSize();
 if (n)
  return tmanGetMetadata(metadata_size);
 else
  return psample_get_metadata(context,metadata_size);
}


topoGrowNeighbourhood

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

if ( counter > 4 )
result = tmanGrowNeighbourhood();
else
result = psample_grow_cache(context, a1);
return result;
}

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

if ( counter > 4 )
result = tmanGrowNeighbourhood();
else
result = psample_grow_cache(context, a1);
return result;
}

original_code:
int topoGrowNeighbourhood(int n)
{
 if (counter < 5)
  return psample_grow_cache(context,n);
 else
   return tmanGrowNeighbourhood(n);
}


topoShrinkNeighbourhood

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

if ( counter > 4 )
result = tmanShrinkNeighbourhood();
else
result = psample_shrink_cache(context, a1);
return result;
}

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

if ( counter > 4 )
result = tmanShrinkNeighbourhood();
else
result = psample_shrink_cache(context, a1);
return result;
}

original_code:
int topoShrinkNeighbourhood(int n)
{
 if (counter < 5)
  return psample_shrink_cache(context,n);
 else
  return tmanShrinkNeighbourhood(n);
}


help

decompiled_code:
size_t __fastcall help(const char *a1)
{
fprintf(stderr, "Usage: %s [options] <input> <output>\n", a1);
fwrite("options: t:u:f:rRdlavVUT\n", 1uLL, 0x19uLL, stderr);
fwrite("\t -u <port>: use the UDP chunkiser (on <port>) for input\n", 1uLL, 0x39uLL, stderr);
fwrite("\t -P <port>: use the UDP chunkiser (on <port>) for output\n", 1uLL, 0x3AuLL, stderr);
fwrite("\t -f <fmt>: use the <fmt> format for ouptut (libav-based)\n", 1uLL, 0x3AuLL, stderr);
fwrite("\t -r: use RAW output\n", 1uLL, 0x15uLL, stderr);
fwrite("\t -R: use RAW output, removing the libav payload header\n", 1uLL, 0x38uLL, stderr);
fwrite("\t -d: use the dummy chunkiser\n", 1uLL, 0x1EuLL, stderr);
fwrite("\t -l: loop\n", 1uLL, 0xBuLL, stderr);
fwrite("\t -a: audio-only in the libav ouptut\n", 1uLL, 0x25uLL, stderr);
fwrite("\t -v: video-only in the libav output\n", 1uLL, 0x25uLL, stderr);
fwrite("\t -V: audio/video in the libav output\n", 1uLL, 0x26uLL, stderr);
fwrite("\t -U: use RAW output, removing the UDP payload header\n", 1uLL, 0x36uLL, stderr);
fwrite("\t -T: use RAW output, removing the RTP payload heade\n", 1uLL, 0x35uLL, stderr);
fwrite("\t -I <config>: specify the chunkiser config\n", 1uLL, 0x2CuLL, stderr);
return fwrite("\t -O <config>: specify the dechunkiser config\n", 1uLL, 0x2EuLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
fprintf(stderr, "Usage: %s [options] <input> <output>\n", a1);
fwrite("options: t:u:f:rRdlavVUT\n", 1uLL, 0x19uLL, stderr);
fwrite("\t -u <port>: use the UDP chunkiser (on <port>) for input\n", 1uLL, 0x39uLL, stderr);
fwrite("\t -P <port>: use the UDP chunkiser (on <port>) for output\n", 1uLL, 0x3AuLL, stderr);
fwrite("\t -f <fmt>: use the <fmt> format for ouptut (libav-based)\n", 1uLL, 0x3AuLL, stderr);
fwrite("\t -r: use RAW output\n", 1uLL, 0x15uLL, stderr);
fwrite("\t -R: use RAW output, removing the libav payload header\n", 1uLL, 0x38uLL, stderr);
fwrite("\t -d: use the dummy chunkiser\n", 1uLL, 0x1EuLL, stderr);
fwrite("\t -l: loop\n", 1uLL, 0xBuLL, stderr);
fwrite("\t -a: audio-only in the libav ouptut\n", 1uLL, 0x25uLL, stderr);
fwrite("\t -v: video-only in the libav output\n", 1uLL, 0x25uLL, stderr);
fwrite("\t -V: audio/video in the libav output\n", 1uLL, 0x26uLL, stderr);
fwrite("\t -U: use RAW output, removing the UDP payload header\n", 1uLL, 0x36uLL, stderr);
fwrite("\t -T: use RAW output, removing the RTP payload heade\n", 1uLL, 0x35uLL, stderr);
fwrite("\t -I <config>: specify the chunkiser config\n", 1uLL, 0x2CuLL, stderr);
return fwrite("\t -O <config>: specify the dechunkiser config\n", 1uLL, 0x2EuLL, stderr);
}

original_code:
static void help(const char *name)
{
  fprintf(stderr, "Usage: %s [options] <input> <output>\n", name);
  fprintf(stderr, "options: t:u:f:rRdlavVUT\n");
  fprintf(stderr, "\t -u <port>: use the UDP chunkiser (on <port>) for input\n");
  fprintf(stderr, "\t -P <port>: use the UDP chunkiser (on <port>) for output\n");
  fprintf(stderr, "\t -f <fmt>: use the <fmt> format for ouptut (libav-based)\n");
  fprintf(stderr, "\t -r: use RAW output\n");
  fprintf(stderr, "\t -R: use RAW output, removing the libav payload header\n");
  fprintf(stderr, "\t -d: use the dummy chunkiser\n");
  fprintf(stderr, "\t -l: loop\n");
  fprintf(stderr, "\t -a: audio-only in the libav ouptut\n");
  fprintf(stderr, "\t -v: video-only in the libav output\n");
  fprintf(stderr, "\t -V: audio/video in the libav output\n");
  fprintf(stderr, "\t -U: use RAW output, removing the UDP payload header\n");
  fprintf(stderr, "\t -T: use RAW output, removing the RTP payload heade\n");
  fprintf(stderr, "\t -I <config>: specify the chunkiser config\n");
  fprintf(stderr, "\t -O <config>: specify the dechunkiser config\n");
}

canonical_original_code:
static void help(char *name)
{
  fprintf(stderr, "Usage: %s [options] <input> <output>\n", name);
  fprintf(stderr, "options: t:u:f:rRdlavVUT\n");
  fprintf(stderr, "\t -u <port>: use the UDP chunkiser (on <port>) for input\n");
  fprintf(stderr, "\t -P <port>: use the UDP chunkiser (on <port>) for output\n");
  fprintf(stderr, "\t -f <fmt>: use the <fmt> format for ouptut (libav-based)\n");
  fprintf(stderr, "\t -r: use RAW output\n");
  fprintf(stderr, "\t -R: use RAW output, removing the libav payload header\n");
  fprintf(stderr, "\t -d: use the dummy chunkiser\n");
  fprintf(stderr, "\t -l: loop\n");
  fprintf(stderr, "\t -a: audio-only in the libav ouptut\n");
  fprintf(stderr, "\t -v: video-only in the libav output\n");
  fprintf(stderr, "\t -V: audio/video in the libav output\n");
  fprintf(stderr, "\t -U: use RAW output, removing the UDP payload header\n");
  fprintf(stderr, "\t -T: use RAW output, removing the RTP payload heade\n");
  fprintf(stderr, "\t -I <config>: specify the chunkiser config\n");
  fprintf(stderr, "\t -O <config>: specify the dechunkiser config\n");
}

variable_types:
name
char *

return_type: void


addopt

decompiled_code:
char *__fastcall addopt(char *s, char *a2, const char *a3, const char *a4)
{
char *v4; // rbx

v4 = s;
if ( a2 != s )
{
v4 = a2 + 1;
*a2 = 44;
}
return &v4[sprintf(v4, "%s=%s", a3, a4)];
}

canonical_decompiled_code:
char *__fastcall func1(char *s, char *a2, const char *a3, const char *a4)
{
char *v4; // rbx

v4 = s;
if ( a2 != s )
{
v4 = a2 + 1;
*a2 = 44;
}
return &v4[sprintf(v4, "%s=%s", a3, a4)];
}

original_code:
static char *addopt(char *opts, char *opts_ptr, const char *tag, const char *value)
{
  if (opts_ptr != opts) {
    *opts_ptr++ = ',';
  }
  opts_ptr += sprintf(opts_ptr, "%s=%s", tag, value);
  return opts_ptr;
}

canonical_original_code:
static char *addopt(char *opts, char *opts_ptr, char *tag, char *value)
{
  if (opts_ptr != opts) {
    *opts_ptr++ = ',';
  }
  opts_ptr += sprintf(opts_ptr, "%s=%s", tag, value);
  return opts_ptr;
}

variable_types:
opts
char *

variable_types:
tag
char *

variable_types:
value
char *

return_type: char *


decompiled_code:
__int64 __fastcall tout_init(_QWORD *a1)
{
__int64 result; // rax
bool v2; // sf
__int64 v3; // rdx
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
result = tnext;
if ( v4.tv_sec != tnext )
{
if ( v4.tv_sec < tnext )
goto LABEL_3;
LABEL_6:
*a1 = 0LL;
a1[1] = 0LL;
return result;
}
if ( v4.tv_usec >= qword_A68 )
goto LABEL_6;
LABEL_3:
result = tnext - v4.tv_sec;
*a1 = tnext - v4.tv_sec;
v3 = qword_A68 - v4.tv_usec;
v2 = qword_A68 - v4.tv_usec < 0;
a1[1] = qword_A68 - v4.tv_usec;
if ( v2 )
{
*a1 = --result;
a1[1] = v3 + 1000000;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 result; // rax
bool v2; // sf
__int64 v3; // rdx
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
result = tnext;
if ( v4.tv_sec != tnext )
{
if ( v4.tv_sec < tnext )
goto LABEL_3;
LABEL_6:
*a1 = 0LL;
a1[1] = 0LL;
return result;
}
if ( v4.tv_usec >= qword_A68 )
goto LABEL_6;
LABEL_3:
result = tnext - v4.tv_sec;
*a1 = tnext - v4.tv_sec;
v3 = qword_A68 - v4.tv_usec;
v2 = qword_A68 - v4.tv_usec < 0;
a1[1] = qword_A68 - v4.tv_usec;
if ( v2 )
{
*a1 = --result;
a1[1] = v3 + 1000000;
}
return result;
}

original_code:
void tout_init(struct timeval *tv)
{
  struct timeval tnow;
  gettimeofday(&tnow, ((void *)0));
  if((((&tnow)->tv_sec == (&tnext)->tv_sec) ? ((&tnow)->tv_usec < (&tnext)->tv_usec) : ((&tnow)->tv_sec < (&tnext)->tv_sec))) {
    do { (tv)->tv_sec = (&tnext)->tv_sec - (&tnow)->tv_sec; (tv)->tv_usec = (&tnext)->tv_usec - (&tnow)->tv_usec; if ((tv)->tv_usec < 0) { --(tv)->tv_sec; (tv)->tv_usec += 1000000; } } while (0);
  } else {
    *tv = (struct timeval){0, 0};
  }
}

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


decompiled_code:
__int64 __fastcall cmdline_parse(int argc, char **argv)
{
unsigned int v2; // eax
char s[32]; // [rsp+8h] [rbp-20h] BYREF

while ( 1 )
{
v2 = getopt(argc, argv, "slP:u:f:rRdlavVxUTO:I:");
if ( v2 == -1 )
break;
switch ( v2 )
{
case 'I':
in_ptr += sprintf(in_ptr, "%s", optarg);
break;
case 'O':
out_ptr += sprintf(out_ptr, "%s", optarg);
break;
case 'P':
if ( !out_udp_port )
out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "udp");
sprintf(s, "port%d", (unsigned int)out_udp_port);
++out_udp_port;
out_ptr = addopt(out_opts, out_ptr, s, optarg);
break;
case 'R':
out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "raw");
out_ptr = addopt(out_opts, out_ptr, "payload", "avf");
break;
case 'T':
out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "raw");
out_ptr = addopt(out_opts, out_ptr, "payload", "rtp");
break;
case 'U':
out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "raw");
out_ptr = addopt(out_opts, out_ptr, "payload", "udp");
break;
case 'V':
in_ptr = addopt(in_opts, in_ptr, "chunkiser", "avf");
in_ptr = addopt(in_opts, in_ptr, "media", "av");
out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "avf");
out_ptr = addopt(out_opts, out_ptr, "media", "av");
break;
case 'a':
in_ptr = addopt(in_opts, in_ptr, "chunkiser", "avf");
in_ptr = addopt(in_opts, in_ptr, "media", "audio");
out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "avf");
out_ptr = addopt(out_opts, out_ptr, "media", "audio");
break;
case 'd':
in_ptr = addopt(in_opts, in_ptr, "chunkiser", "dummy");
break;
case 'f':
out_ptr = addopt(out_opts, out_ptr, "format", optarg);
break;
case 'l':
in_ptr = addopt(in_opts, in_ptr, "loop", "1");
break;
case 'r':
out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "raw");
break;
case 's':
timed = 1;
break;
case 't':
in_ptr = addopt(in_opts, in_ptr, "chunkiser", "ts");
break;
case 'u':
if ( !udp_port )
in_ptr = addopt(in_opts, in_ptr, "chunkiser", "udp");
sprintf(s, "port%d", (unsigned int)udp_port);
++udp_port;
in_ptr = addopt(in_opts, in_ptr, s, optarg);
break;
case 'v':
in_ptr = addopt(in_opts, in_ptr, "chunkiser", "avf");
in_ptr = addopt(in_opts, in_ptr, "media", "video");
out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "avf");
out_ptr = addopt(out_opts, out_ptr, "media", "video");
break;
case 'x':
in_ptr = addopt(in_opts, in_ptr, "chunkiser", "avf");
in_ptr = addopt(in_opts, in_ptr, "media", "av");
out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "play");
out_ptr = addopt(out_opts, out_ptr, "media", "av");
timed = 1;
break;
default:
fprintf(stderr, "Error: unknown option %c\n", v2);
exit(-1);
}
}
return (unsigned int)(optind - 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int argc, char **argv)
{
unsigned int v2; // eax
char s[32]; // [rsp+8h] [rbp-20h] BYREF

while ( 1 )
{
v2 = getopt(argc, argv, "slP:u:f:rRdlavVxUTO:I:");
if ( v2 == -1 )
break;
switch ( v2 )
{
case 'I':
in_ptr += sprintf(in_ptr, "%s", optarg);
break;
case 'O':
out_ptr += sprintf(out_ptr, "%s", optarg);
break;
case 'P':
if ( !out_udp_port )
out_ptr = func1(out_opts, out_ptr, "dechunkiser", "udp");
sprintf(s, "port%d", (unsigned int)out_udp_port);
++out_udp_port;
out_ptr = func1(out_opts, out_ptr, s, optarg);
break;
case 'R':
out_ptr = func1(out_opts, out_ptr, "dechunkiser", "raw");
out_ptr = func1(out_opts, out_ptr, "payload", "avf");
break;
case 'T':
out_ptr = func1(out_opts, out_ptr, "dechunkiser", "raw");
out_ptr = func1(out_opts, out_ptr, "payload", "rtp");
break;
case 'U':
out_ptr = func1(out_opts, out_ptr, "dechunkiser", "raw");
out_ptr = func1(out_opts, out_ptr, "payload", "udp");
break;
case 'V':
in_ptr = func1(in_opts, in_ptr, "chunkiser", "avf");
in_ptr = func1(in_opts, in_ptr, "media", "av");
out_ptr = func1(out_opts, out_ptr, "dechunkiser", "avf");
out_ptr = func1(out_opts, out_ptr, "media", "av");
break;
case 'a':
in_ptr = func1(in_opts, in_ptr, "chunkiser", "avf");
in_ptr = func1(in_opts, in_ptr, "media", "audio");
out_ptr = func1(out_opts, out_ptr, "dechunkiser", "avf");
out_ptr = func1(out_opts, out_ptr, "media", "audio");
break;
case 'd':
in_ptr = func1(in_opts, in_ptr, "chunkiser", "dummy");
break;
case 'f':
out_ptr = func1(out_opts, out_ptr, "format", optarg);
break;
case 'l':
in_ptr = func1(in_opts, in_ptr, "loop", "1");
break;
case 'r':
out_ptr = func1(out_opts, out_ptr, "dechunkiser", "raw");
break;
case 's':
timed = 1;
break;
case 't':
in_ptr = func1(in_opts, in_ptr, "chunkiser", "ts");
break;
case 'u':
if ( !udp_port )
in_ptr = func1(in_opts, in_ptr, "chunkiser", "udp");
sprintf(s, "port%d", (unsigned int)udp_port);
++udp_port;
in_ptr = func1(in_opts, in_ptr, s, optarg);
break;
case 'v':
in_ptr = func1(in_opts, in_ptr, "chunkiser", "avf");
in_ptr = func1(in_opts, in_ptr, "media", "video");
out_ptr = func1(out_opts, out_ptr, "dechunkiser", "avf");
out_ptr = func1(out_opts, out_ptr, "media", "video");
break;
case 'x':
in_ptr = func1(in_opts, in_ptr, "chunkiser", "avf");
in_ptr = func1(in_opts, in_ptr, "media", "av");
out_ptr = func1(out_opts, out_ptr, "dechunkiser", "play");
out_ptr = func1(out_opts, out_ptr, "media", "av");
timed = 1;
break;
default:
fprintf(stderr, "Error: unknown option %c\n", v2);
exit(-1);
}
}
return (unsigned int)(optind - 1);
}

original_code:
static int cmdline_parse(int argc, char *argv[])
{
  int o;
  while ((o = getopt(argc, argv, "slP:u:f:rRdlavVxUTO:I:")) != -1) {
    char port[8];
    switch(o) {
      case 's':
        timed = 1;
        break;
      case 'l':
        in_ptr = addopt(in_opts, in_ptr, "loop", "1");
        break;
      case 'P':
        if (out_udp_port == 0) {
          out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "udp");
        }
        sprintf(port, "port%d", out_udp_port);
        out_udp_port++;
        out_ptr = addopt(out_opts, out_ptr, port, optarg);
        break;
      case 't':
        in_ptr = addopt(in_opts, in_ptr, "chunkiser", "ts");
        break;
      case 'u':
        if (udp_port == 0) {
          in_ptr = addopt(in_opts, in_ptr, "chunkiser", "udp");
        }
        sprintf(port, "port%d", udp_port);
        udp_port++;
        in_ptr = addopt(in_opts, in_ptr, port, optarg);
        break;
      case 'f':
        out_ptr = addopt(out_opts, out_ptr, "format", optarg);
        break;
      case 'r':
        out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "raw");
        break;
      case 'R':
        out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "raw");
        out_ptr = addopt(out_opts, out_ptr, "payload", "avf");
        break;
      case 'U':
        out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "raw");
        out_ptr = addopt(out_opts, out_ptr, "payload", "udp");
        break;
      case 'T':
        out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "raw");
        out_ptr = addopt(out_opts, out_ptr, "payload", "rtp");
        break;
      case 'd':
        in_ptr = addopt(in_opts, in_ptr, "chunkiser", "dummy");
        break;
      case 'a':
        in_ptr = addopt(in_opts, in_ptr, "chunkiser", "avf");
        in_ptr = addopt(in_opts, in_ptr, "media", "audio");
        out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "avf");
        out_ptr = addopt(out_opts, out_ptr, "media", "audio");
        break;
      case 'v':
        in_ptr = addopt(in_opts, in_ptr, "chunkiser", "avf");
        in_ptr = addopt(in_opts, in_ptr, "media", "video");
        out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "avf");
        out_ptr = addopt(out_opts, out_ptr, "media", "video");
        break;
      case 'V':
        in_ptr = addopt(in_opts, in_ptr, "chunkiser", "avf");
        in_ptr = addopt(in_opts, in_ptr, "media", "av");
        out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "avf");
        out_ptr = addopt(out_opts, out_ptr, "media", "av");
        break;
      case 'x':
        in_ptr = addopt(in_opts, in_ptr, "chunkiser", "avf");
        in_ptr = addopt(in_opts, in_ptr, "media", "av");
        out_ptr = addopt(out_opts, out_ptr, "dechunkiser", "play");
        out_ptr = addopt(out_opts, out_ptr, "media", "av");
        timed = 1;
        break;
      case 'O':
        out_ptr += sprintf(out_ptr, "%s", optarg);
        break;
      case 'I':
        in_ptr += sprintf(in_ptr, "%s", optarg);
        break;
      default:
        fprintf(stderr, "Error: unknown option %c\n", o);
        exit(-1);
    }
  }
  return optind - 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: o int

variable_types:
port
char [8]


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

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

original_code:
static int int_cmp(const void *pa, const void *pb)
{
  return (*(const int *)pa - *(const int *)pb);
}

canonical_original_code:
static int int_cmp(void *pa, void *pb)
{
  return (*(int *)pa - *(int *)pb);
}

variable_types:
pa
void *

variable_types:
pb
void *


decompiled_code:
__int64 __fastcall check_insert_pos(__int64 a1, int a2)
{
int v2; // eax
unsigned int v3; // ebx
__int64 v4; // r13
unsigned int v5; // ebp
unsigned int i; // er12
int v7; // eax
int v9[9]; // [rsp+4h] [rbp-24h] BYREF

v9[0] = a2;
v2 = *(_DWORD *)(a1 + 8);
v3 = 0;
if ( v2 )
{
v3 = v2 - 1;
v4 = *(_QWORD *)(a1 + 16);
v5 = v2 - 1;
for ( i = 0; ; v3 = (int)(i + v5) / 2 )
{
v7 = int_cmp(v9, (const void *)(v4 + 4LL * (int)v3));
if ( !v7 )
break;
if ( v7 <= 0 )
{
if ( i == v3 )
return v3;
v5 = v3;
}
else
{
if ( v3 == v5 )
return v5 + 1;
i = v3 + 1;
}
}
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // eax
unsigned int v3; // ebx
__int64 v4; // r13
unsigned int v5; // ebp
unsigned int i; // er12
int v7; // eax
int v9[9]; // [rsp+4h] [rbp-24h] BYREF

v9[0] = a2;
v2 = *(_DWORD *)(a1 + 8);
v3 = 0;
if ( v2 )
{
v3 = v2 - 1;
v4 = *(_QWORD *)(a1 + 16);
v5 = v2 - 1;
for ( i = 0; ; v3 = (int)(i + v5) / 2 )
{
v7 = func0(v9, (const void *)(v4 + 4LL * (int)v3));
if ( !v7 )
break;
if ( v7 <= 0 )
{
if ( i == v3 )
return v3;
v5 = v3;
}
else
{
if ( v3 == v5 )
return v5 + 1;
i = v3 + 1;
}
}
v3 = -1;
}
return v3;
}

original_code:
static int check_insert_pos(const struct chunkID_set *h, int id)
{
  int a, b, c, r;
  if (! h->n_elements) {
    return 0;
  }
  a = 0;
  b = c = h->n_elements - 1;
  while ((r = int_cmp(&id, &h->elements[b])) != 0) {
    if (r > 0) {
      if (b == c) {
        return b + 1;
      } else {
        a = b + 1;
      }
    } else {
      if (b == a) {
        return b;
      } else {
        c = b;
      }
    }
    b = (a + c) / 2;
  }
  return -1;
}

canonical_original_code:
static int check_insert_pos(struct chunkID_set *h, int id)
{
  int a; int b; int c; int r;
  if (! h->n_elements) {
    return 0;
  }
  a = 0;
  b = c = h->n_elements - 1;
  while ((r = int_cmp(&id, &h->elements[b])) != 0) {
    if (r > 0) {
      if (b == c) {
        return b + 1;
      } else {
        a = b + 1;
      }
    } else {
      if (b == a) {
        return b;
      } else {
        c = b;
      }
    }
    b = (a + c) / 2;
  }
  return -1;
}

variable_types: struct chunkID_set { unsigned int type; unsigned int size; unsigned int n_elements; int *elements; struct cids_ops_iface { int (*add_chunk)(struct chunkID_set *h, int chunk_id); int (*check)(struct chunkID_set *h, int chunk_id); } *ops; struct cids_encoding_iface { unsigned char *(*encode)(struct chunkID_set *h, unsigned char *buff, int buff_len, int meta_len); unsigned char *(*decode)(struct chunkID_set *h, unsigned char *buff, int buff_len, int *meta_len); } *enc; } *

variable_types: id int

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: r int

user_defined_types: struct chunkID_set { unsigned int type; unsigned int size; unsigned int n_elements; int *elements; struct cids_ops_iface *ops; struct cids_encoding_iface *enc; }


decompiled_code:
__int64 __fastcall chunkID_set_check_set(__int64 a1, int a2)
{
void *v2; // rax
__int64 result; // rax
int key[3]; // [rsp+Ch] [rbp-Ch] BYREF

key[0] = a2;
v2 = bsearch(key, *(const void **)(a1 + 16), *(unsigned int *)(a1 + 8), 4uLL, (__compar_fn_t)int_cmp);
if ( v2 )
result = ((__int64)v2 - *(_QWORD *)(a1 + 16)) >> 2;
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
void *v2; // rax
__int64 result; // rax
int key[3]; // [rsp+Ch] [rbp-Ch] BYREF

key[0] = a2;
v2 = bsearch(key, *(const void **)(a1 + 16), *(unsigned int *)(a1 + 8), 4uLL, (__compar_fn_t)int_cmp);
if ( v2 )
result = ((__int64)v2 - *(_QWORD *)(a1 + 16)) >> 2;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int chunkID_set_check_set(const struct chunkID_set *h, int chunk_id)
{
  int *p;
  p = bsearch(&chunk_id, h->elements, (size_t) h->n_elements, sizeof(h->elements[0]), int_cmp);
  return p ? p - h->elements : -1;
}

canonical_original_code:
static int chunkID_set_check_set(struct chunkID_set *h, int chunk_id)
{
  int *p;
  p = bsearch(&chunk_id, h->elements, (unsigned long) h->n_elements, sizeof(h->elements[0]), int_cmp);
  return p ? p - h->elements : -1;
}

variable_types:
p
int *

user_defined_types: struct cids_ops_iface { int (*add_chunk)(struct chunkID_set *h, int chunk_id); int (*check)(struct chunkID_set *h, int chunk_id); }

user_defined_types: struct cids_encoding_iface { unsigned char *(*encode)(struct chunkID_set *h, unsigned char *buff, int buff_len, int meta_len); unsigned char *(*decode)(struct chunkID_set *h, unsigned char *buff, int buff_len, int *meta_len); }


decompiled_code:
__int64 __fastcall chunkID_set_add_chunk_set(__int64 a1, int a2)
{
int v3; // ebp
__int64 result; // rax
int v5; // eax
int v6; // edx
__int64 v7; // rsi
void *v8; // rax

v3 = check_insert_pos(a1, a2);
result = 0LL;
if ( v3 >= 0 )
{
v5 = *(_DWORD *)(a1 + 4);
if ( *(_DWORD *)(a1 + 8) == v5 )
{
v8 = realloc(*(void **)(a1 + 16), 4LL * (unsigned int)(v5 + 32));
if ( !v8 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 4) += 32;
*(_QWORD *)(a1 + 16) = v8;
}
v6 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = v6 + 1;
v7 = *(_QWORD *)(a1 + 16) + 4LL * v3;
memmove((void *)(v7 + 4), (const void *)v7, 4LL * (unsigned int)(v6 - v3));
*(_DWORD *)(*(_QWORD *)(a1 + 16) + 4LL * v3) = a2;
result = *(unsigned int *)(a1 + 8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
int v3; // ebp
__int64 result; // rax
int v5; // eax
int v6; // edx
__int64 v7; // rsi
void *v8; // rax

v3 = func1(a1, a2);
result = 0LL;
if ( v3 >= 0 )
{
v5 = *(_DWORD *)(a1 + 4);
if ( *(_DWORD *)(a1 + 8) == v5 )
{
v8 = realloc(*(void **)(a1 + 16), 4LL * (unsigned int)(v5 + 32));
if ( !v8 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 4) += 32;
*(_QWORD *)(a1 + 16) = v8;
}
v6 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = v6 + 1;
v7 = *(_QWORD *)(a1 + 16) + 4LL * v3;
memmove((void *)(v7 + 4), (const void *)v7, 4LL * (unsigned int)(v6 - v3));
*(_DWORD *)(*(_QWORD *)(a1 + 16) + 4LL * v3) = a2;
result = *(unsigned int *)(a1 + 8);
}
return result;
}

original_code:
static int chunkID_set_add_chunk_set(struct chunkID_set *h, int chunk_id)
{
  int pos;
  pos = check_insert_pos(h, chunk_id);
  if (pos < 0){
    return 0;
  }
  if (h->n_elements == h->size) {
    int *res;
    res = realloc(h->elements, (h->size + 32) * sizeof(int));
    if (res == ((void *)0)) {
      return -1;
    }
    h->size += 32;
    h->elements = res;
  }
  memmove(&h->elements[pos + 1], &h->elements[pos] , ((h->n_elements++) - pos) * sizeof(int));
  h->elements[pos] = chunk_id;
  return h->n_elements;
}

variable_types: pos int

variable_types:
res
int *


decompiled_code:
__int64 checkIPv4Translation()
{
char *v0; // rbp
char *v1; // rbx
unsigned int v2; // ebx
__int64 v4; // [rsp+0h] [rbp-118h] BYREF
char s1[4]; // [rsp+80h] [rbp-98h] BYREF
int buf[37]; // [rsp+84h] [rbp-94h] BYREF

v0 = (char *)malloc(0x10uLL);
v1 = (char *)malloc(0x10uLL);
strcpy(v1, "10.23.23.10");
printf("\tTranslating IPv4 string %s...", v1);
v2 = inet_pton(2, v1, buf);
if ( v2
&& (printf("to network %d\n", (unsigned int)buf[0]),
printf("\tTranslating IPv4 address %d...", (unsigned int)buf[0]),
inet_ntop(2, buf, v0, 0x10u)) )
{
printf("to string %s\n", v0);
inet_pton(2, v0, (char *)&v4 + 4);
v2 = memcmp(s1, &v4, 0x80uLL);
}
else
{
perror("inet");
}
return v2;
}

canonical_decompiled_code:
__int64 func0()
{
char *v0; // rbp
char *v1; // rbx
unsigned int v2; // ebx
__int64 v4; // [rsp+0h] [rbp-118h] BYREF
char s1[4]; // [rsp+80h] [rbp-98h] BYREF
int buf[37]; // [rsp+84h] [rbp-94h] BYREF

v0 = (char *)malloc(0x10uLL);
v1 = (char *)malloc(0x10uLL);
strcpy(v1, "10.23.23.10");
printf("\tTranslating IPv4 string %s...", v1);
v2 = inet_pton(2, v1, buf);
if ( v2
&& (printf("to network %d\n", (unsigned int)buf[0]),
printf("\tTranslating IPv4 address %d...", (unsigned int)buf[0]),
inet_ntop(2, buf, v0, 0x10u)) )
{
printf("to string %s\n", v0);
inet_pton(2, v0, (char *)&v4 + 4);
v2 = memcmp(s1, &v4, 0x80uLL);
}
else
{
perror("inet");
}
return v2;
}

original_code:
int checkIPv4Translation()
{
 int res;
 const char *res1;
 struct sockaddr_storage s;
 struct sockaddr_storage c;
 char *buf = malloc(16);
 char *ipv4 = malloc(16);
 strcpy (ipv4, "10.23.23.10");
 printf("\tTranslating IPv4 string %s...",ipv4);
 res = inet_pton(2, ipv4, &((struct sockaddr_in *)&s)->sin_addr);
 if(!res)
 {
  perror ("inet");
  return res;
 }
 printf("to network %d\n", ((struct sockaddr_in *)&s)->sin_addr.s_addr);
 printf("\tTranslating IPv4 address %d...", ((struct sockaddr_in *)&s)->sin_addr.s_addr);
 res1 = inet_ntop(2, &((struct sockaddr_in *)&s)->sin_addr, buf, 16);
 if(!res1)
 {
  perror ("inet");
  return res;
 }
 printf("to string %s\n", buf);
 res = inet_pton(2, buf, &((struct sockaddr_in *)&c)->sin_addr);
 return memcmp((const void *)&s,(const void *)&c,sizeof(c));
}

canonical_original_code:
int checkIPv4Translation()
{
 int res;
 char *res1;
 struct sockaddr_storage s;
 struct sockaddr_storage c;
 char *buf = malloc(16);
 char *ipv4 = malloc(16);
 strcpy (ipv4, "10.23.23.10");
 printf("\tTranslating IPv4 string %s...",ipv4);
 res = inet_pton(2, ipv4, &((struct sockaddr_in *)&s)->sin_addr);
 if(!res)
 {
  perror ("inet");
  return res;
 }
 printf("to network %d\n", ((struct sockaddr_in *)&s)->sin_addr.s_addr);
 printf("\tTranslating IPv4 address %d...", ((struct sockaddr_in *)&s)->sin_addr.s_addr);
 res1 = inet_ntop(2, &((struct sockaddr_in *)&s)->sin_addr, buf, 16);
 if(!res1)
 {
  perror ("inet");
  return res;
 }
 printf("to string %s\n", buf);
 res = inet_pton(2, buf, &((struct sockaddr_in *)&c)->sin_addr);
 return memcmp((void *)&s,(void *)&c,sizeof(c));
}

variable_types: res int

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

variable_types:
buf
char *

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


decompiled_code:
__int64 checkIPv6Translation()
{
char *v0; // r14
unsigned int v1; // er13
char *v2; // rbx
char *v3; // rbp
__int64 v5; // [rsp+0h] [rbp-128h] BYREF
char v6[120]; // [rsp+8h] [rbp-120h] BYREF
char s1[8]; // [rsp+80h] [rbp-A8h] BYREF
char buf[16]; // [rsp+88h] [rbp-A0h] BYREF
char v9[144]; // [rsp+98h] [rbp-90h] BYREF

v0 = (char *)malloc(0x2EuLL);
printf("\tIPv6 Address string %s ", "fe80:0000:0000:0000:0223:aeff:fe54:ea0c");
v1 = inet_pton(10, "fe80:0000:0000:0000:0223:aeff:fe54:ea0c", buf);
if ( !v1 )
goto LABEL_9;
printf("to network ");
v2 = buf;
v3 = buf;
do
{
printf("%02x%02x:", (unsigned __int8)*v3, (unsigned __int8)v3[1]);
v3 += 2;
}
while ( v3 != v9 );
putchar(10);
printf("\tIPv6 Address ");
do
{
printf("%02x%02x:", (unsigned __int8)*v2, (unsigned __int8)v2[1]);
v2 += 2;
}
while ( v2 != v9 );
if ( inet_ntop(10, buf, v0, 0x2Eu) )
{
printf(" to string %s\n", v0);
inet_pton(10, v0, v6);
v1 = memcmp(s1, &v5, 0x80uLL);
}
else
{
LABEL_9:
perror("inet");
}
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
char *v0; // r14
unsigned int v1; // er13
char *v2; // rbx
char *v3; // rbp
__int64 v5; // [rsp+0h] [rbp-128h] BYREF
char v6[120]; // [rsp+8h] [rbp-120h] BYREF
char s1[8]; // [rsp+80h] [rbp-A8h] BYREF
char buf[16]; // [rsp+88h] [rbp-A0h] BYREF
char v9[144]; // [rsp+98h] [rbp-90h] BYREF

v0 = (char *)malloc(0x2EuLL);
printf("\tIPv6 Address string %s ", "fe80:0000:0000:0000:0223:aeff:fe54:ea0c");
v1 = inet_pton(10, "fe80:0000:0000:0000:0223:aeff:fe54:ea0c", buf);
if ( !v1 )
goto LABEL_9;
printf("to network ");
v2 = buf;
v3 = buf;
do
{
printf("%02x%02x:", (unsigned __int8)*v3, (unsigned __int8)v3[1]);
v3 += 2;
}
while ( v3 != v9 );
putchar(10);
printf("\tIPv6 Address ");
do
{
printf("%02x%02x:", (unsigned __int8)*v2, (unsigned __int8)v2[1]);
v2 += 2;
}
while ( v2 != v9 );
if ( inet_ntop(10, buf, v0, 0x2Eu) )
{
printf(" to string %s\n", v0);
inet_pton(10, v0, v6);
v1 = memcmp(s1, &v5, 0x80uLL);
}
else
{
LABEL_9:
perror("inet");
}
return v1;
}

original_code:
int checkIPv6Translation()
{
 int res, i;
 const char *res1;
 struct sockaddr_storage s;
 struct sockaddr_storage c;
 char *buf = malloc(46);
 const char *ipv6 = "fe80:0000:0000:0000:0223:aeff:fe54:ea0c";
 printf("\tIPv6 Address string %s ", ipv6);
 res = inet_pton(10, ipv6, &((struct sockaddr_in6 *)&s)->sin6_addr);
 if(!res)
 {
  perror ("inet");
  return res;
 }
 printf("to network ");
 for (i = 0; i < 16; i+=2)
     printf("%02x%02x:", (uint8_t) (((struct sockaddr_in6 *)&s)->sin6_addr.__in6_u.__u6_addr8[i]),(uint8_t) (((struct sockaddr_in6 *)&s)->sin6_addr.__in6_u.__u6_addr8[i+1]));
     printf("\n");
 printf("\tIPv6 Address ");
 for (i = 0; i < 16; i+=2)
      printf("%02x%02x:", (uint8_t) (((struct sockaddr_in6 *)&s)->sin6_addr.__in6_u.__u6_addr8[i]),(uint8_t) (((struct sockaddr_in6 *)&s)->sin6_addr.__in6_u.__u6_addr8[i+1]));
 res1 = inet_ntop(10, &((struct sockaddr_in6 *)&s)->sin6_addr, buf, 46);
 if(!res1)
 {
  perror ("inet");
  return res;
 }
 printf(" to string %s\n",buf);
 res = inet_pton(10, buf, &((struct sockaddr_in6 *)&c)->sin6_addr);
 return memcmp((const void *)&s,(const void *)&c,sizeof(c));
}

canonical_original_code:
int checkIPv6Translation()
{
 int res; int i;
 char *res1;
 struct sockaddr_storage s;
 struct sockaddr_storage c;
 char *buf = malloc(46);
 char *ipv6 = "fe80:0000:0000:0000:0223:aeff:fe54:ea0c";
 printf("\tIPv6 Address string %s ", ipv6);
 res = inet_pton(10, ipv6, &((struct sockaddr_in6 *)&s)->sin6_addr);
 if(!res)
 {
  perror ("inet");
  return res;
 }
 printf("to network ");
 for (i = 0; i < 16; i+=2)
     printf("%02x%02x:", (unsigned char) (((struct sockaddr_in6 *)&s)->sin6_addr.__in6_u.__u6_addr8[i]),(unsigned char) (((struct sockaddr_in6 *)&s)->sin6_addr.__in6_u.__u6_addr8[i+1]));
     printf("\n");
 printf("\tIPv6 Address ");
 for (i = 0; i < 16; i+=2)
      printf("%02x%02x:", (unsigned char) (((struct sockaddr_in6 *)&s)->sin6_addr.__in6_u.__u6_addr8[i]),(unsigned char) (((struct sockaddr_in6 *)&s)->sin6_addr.__in6_u.__u6_addr8[i+1]));
 res1 = inet_ntop(10, &((struct sockaddr_in6 *)&s)->sin6_addr, buf, 46);
 if(!res1)
 {
  perror ("inet");
  return res;
 }
 printf(" to string %s\n",buf);
 res = inet_pton(10, buf, &((struct sockaddr_in6 *)&c)->sin6_addr);
 return memcmp((void *)&s,(void *)&c,sizeof(c));
}

variable_types: i int

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

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


main

canonical_name: main

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

if ( (unsigned int)checkIPv4Translation(argc, argv, envp) )
{
puts("IPv4 Translation success");
if ( (unsigned int)checkIPv6Translation() )
{
puts("IPv6 Translation success");
result = 0;
}
else
{
fwrite("IPv6 Translation failed", 1uLL, 0x17uLL, stderr);
result = 1;
}
}
else
{
fwrite("IPv4 Translation failed", 1uLL, 0x17uLL, stderr);
result = 1;
}
return result;
}

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

if ( (unsigned int)func0(argc, argv, envp) )
{
puts("IPv4 Translation success");
if ( (unsigned int)func1() )
{
puts("IPv6 Translation success");
result = 0;
}
else
{
fwrite("IPv6 Translation failed", 1uLL, 0x17uLL, stderr);
result = 1;
}
}
else
{
fwrite("IPv4 Translation failed", 1uLL, 0x17uLL, stderr);
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 int res = 0;
 if(!checkIPv4Translation())
 {
  fprintf(stderr, "IPv4 Translation failed");
  return 1;
 }
 printf("IPv4 Translation success\n");
 if(!checkIPv6Translation())
 {
  fprintf(stderr, "IPv6 Translation failed");
  return 1;
 }
 printf("IPv6 Translation success\n");
 return res;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall ts_get_fds(__int64 a1)
{
return a1 + 40;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1 + 40;
}

original_code:
const int *ts_get_fds(const struct chunkiser_ctx *s)
{
  return s->fds;
}

canonical_original_code:
int *ts_get_fds(struct chunkiser_ctx *s)
{
  return s->fds;
}

variable_types: struct chunkiser_ctx { int loop; int pkts_per_chunk; int size; int bufsize; int pcr_period; unsigned char *buff; unsigned long old_pcr; int fds[2]; } *

return_type: int *


decompiled_code:
__int64 __fastcall ts_resync(void *src, int *a2)
{
__int64 result; // rax
__int64 v4; // rdx
_BYTE *v5; // rsi
signed __int64 v6; // rbx

result = fwrite("Resynch!\n", 1uLL, 9uLL, stderr);
v4 = *a2;
v5 = src;
v6 = 0LL;
if ( v4 <= 0 )
goto LABEL_4;
while ( *v5 != 71 )
{
v6 = ++v5 - (_BYTE *)src;
if ( v5 - (_BYTE *)src >= v4 )
goto LABEL_4;
}
if ( v4 <= v6 )
{
LABEL_4:
*a2 = 0;
}
else
{
result = (__int64)memmove(src, v5, v4 - v6);
*a2 -= v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *src, int *a2)
{
__int64 result; // rax
__int64 v4; // rdx
_BYTE *v5; // rsi
signed __int64 v6; // rbx

result = fwrite("Resynch!\n", 1uLL, 9uLL, stderr);
v4 = *a2;
v5 = src;
v6 = 0LL;
if ( v4 <= 0 )
goto LABEL_4;
while ( *v5 != 71 )
{
v6 = ++v5 - (_BYTE *)src;
if ( v5 - (_BYTE *)src >= v4 )
goto LABEL_4;
}
if ( v4 <= v6 )
{
LABEL_4:
*a2 = 0;
}
else
{
result = (__int64)memmove(src, v5, v4 - v6);
*a2 -= v6;
}
return result;
}

original_code:
static void ts_resync(uint8_t *buff, int *size)
{
  uint8_t *p = buff;
  fprintf(stderr, "Resynch!\n");
  while((p - buff < *size) && (*p != 0x47)) {
    p++;
  }
  if (p - buff < *size) {
    memmove(buff, p, *size - (p - buff));
    *size -= (p - buff);
  } else {
    *size = 0;
  }
}

canonical_original_code:
static void ts_resync(unsigned char *buff, int *size)
{
  unsigned char *p = buff;
  fprintf(stderr, "Resynch!\n");
  while((p - buff < *size) && (*p != 0x47)) {
    p++;
  }
  if (p - buff < *size) {
    memmove(buff, p, *size - (p - buff));
    *size -= (p - buff);
  } else {
    *size = 0;
  }
}

variable_types:
buff
unsigned char *

variable_types:
size
int *

variable_types:
p
unsigned char *


decompiled_code:
void __fastcall ts_close(void *ptr)
{
close(*((_DWORD *)ptr + 10));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
close(*((_DWORD *)ptr + 10));
free(ptr);
}

original_code:
static void ts_close(struct chunkiser_ctx *s)
{
  close(s->fds[0]);
  free(s);
}

user_defined_types: struct chunkiser_ctx { int loop; int pkts_per_chunk; int size; int bufsize; int pcr_period; unsigned char *buff; unsigned long old_pcr; int fds[2]; }


decompiled_code:
__int64 __fastcall int_cpy(_DWORD *a1, unsigned int a2)
{
__int64 result; // rax

result = _bswap_32(a2);
*a1 = result;
return result;
}

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

result = func8(a2);
*a1 = result;
return result;
}

original_code:
static inline void int_cpy(uint8_t *p, int v)
{
  uint32_t tmp;
  tmp = htonl(v);
  memcpy(p, &tmp, 4);
}

canonical_original_code:
static inline void int_cpy(unsigned char *p, int v)
{
  unsigned int tmp;
  tmp = htonl(v);
  memcpy(p, &tmp, 4);
}

variable_types: v int

variable_types:
tmp
unsigned int


decompiled_code:
__int64 __fastcall int_rcpy(unsigned int *a1)
{
return _bswap_32(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1)
{
return func8(*a1);
}

original_code:
static inline uint32_t int_rcpy(const uint8_t *p)
{
  uint32_t tmp;
  memcpy(&tmp, p, 4);
  tmp = ntohl(tmp);
  return tmp;
}

canonical_original_code:
static inline unsigned int int_rcpy(unsigned char *p)
{
  unsigned int tmp;
  memcpy(&tmp, p, 4);
  tmp = ntohl(tmp);
  return tmp;
}

return_type: unsigned int


encodeChunk

original_code:
int encodeChunk(const struct chunk *c, uint8_t *buff, int buff_len)
{
  uint32_t half_ts;
  if (buff_len < 20 + c->size + c->attributes_size) {
    return -1;
  }
  int_cpy(buff, c->id);
  half_ts = c->timestamp >> 32;
  int_cpy(buff + 4, half_ts);
  half_ts = c->timestamp;
  int_cpy(buff + 8, half_ts);
  int_cpy(buff + 12, c->size);
  int_cpy(buff + 16, c->attributes_size);
  memcpy(buff + 20, c->data, c->size);
  if (c->attributes_size) {
    memcpy(buff + 20 + c->size, c->attributes, c->attributes_size);
  }
  return 20 + c->size + c->attributes_size;
}

canonical_original_code:
int encodeChunk(struct chunk *c, unsigned char *buff, int buff_len)
{
  unsigned int half_ts;
  if (buff_len < 20 + c->size + c->attributes_size) {
    return -1;
  }
  int_cpy(buff, c->id);
  half_ts = c->timestamp >> 32;
  int_cpy(buff + 4, half_ts);
  half_ts = c->timestamp;
  int_cpy(buff + 8, half_ts);
  int_cpy(buff + 12, c->size);
  int_cpy(buff + 16, c->attributes_size);
  memcpy(buff + 20, c->data, c->size);
  if (c->attributes_size) {
    memcpy(buff + 20 + c->size, c->attributes, c->attributes_size);
  }
  return 20 + c->size + c->attributes_size;
}

variable_types: struct chunk { int id; int size; unsigned char *data; unsigned long timestamp; void *attributes; int attributes_size; } *


decodeChunk

original_code:
int decodeChunk(struct chunk *c, const uint8_t *buff, int buff_len)
{
  if (buff_len < 20) {
    return -1;
  }
  c->id = int_rcpy(buff);
  c->timestamp = int_rcpy(buff + 4);
  c->timestamp = c->timestamp << 32;
  c->timestamp |= int_rcpy(buff + 8);
  c->size = int_rcpy(buff + 12);
  c->attributes_size = int_rcpy(buff + 16);
  if (buff_len < c->size + 20) {
    return -2;
  }
  c->data = malloc(c->size);
  if (c->data == ((void *)0)) {
    return -3;
  }
  memcpy(c->data, buff + 20, c->size);
  if (c->attributes_size > 0) {
    if (buff_len < c->size + c->attributes_size) {
      return -4;
    }
    c->attributes = malloc(c->attributes_size);
    if (c->attributes == ((void *)0)) {
      return -5;
    }
    memcpy(c->attributes, buff + 20 + c->size, c->attributes_size);
  }
  return 20 + c->size + c->attributes_size;
}

canonical_original_code:
int decodeChunk(struct chunk *c, unsigned char *buff, int buff_len)
{
  if (buff_len < 20) {
    return -1;
  }
  c->id = int_rcpy(buff);
  c->timestamp = int_rcpy(buff + 4);
  c->timestamp = c->timestamp << 32;
  c->timestamp |= int_rcpy(buff + 8);
  c->size = int_rcpy(buff + 12);
  c->attributes_size = int_rcpy(buff + 16);
  if (buff_len < c->size + 20) {
    return -2;
  }
  c->data = malloc(c->size);
  if (c->data == ((void *)0)) {
    return -3;
  }
  memcpy(c->data, buff + 20, c->size);
  if (c->attributes_size > 0) {
    if (buff_len < c->size + c->attributes_size) {
      return -4;
    }
    c->attributes = malloc(c->attributes_size);
    if (c->attributes == ((void *)0)) {
      return -5;
    }
    memcpy(c->attributes, buff + 20 + c->size, c->attributes_size);
  }
  return 20 + c->size + c->attributes_size;
}

user_defined_types: struct chunk { int id; int size; unsigned char *data; unsigned long timestamp; void *attributes; int attributes_size; }


decompiled_code:
__int64 __fastcall udp_get_fds(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1;
}

original_code:
const int *udp_get_fds(const struct chunkiser_ctx *s)
{
  return s->fds;
}

canonical_original_code:
int *udp_get_fds(struct chunkiser_ctx *s)
{
  return s->fds;
}

variable_types: struct chunkiser_ctx { int fds[-1]; int id; unsigned long start_time; unsigned char *buff; int size; int counter; int every; } *


decompiled_code:
ssize_t __fastcall input_get_udp(void *buf, int fd)
{
ssize_t result; // rax

result = recv(fd, buf, 0x10000uLL, 0);
if ( result < 0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(void *buf, int fd)
{
ssize_t result; // rax

result = recv(fd, buf, 0x10000uLL, 0);
if ( result < 0 )
result = 0LL;
return result;
}

original_code:
static int input_get_udp(uint8_t *data, int fd)
{
  ssize_t msglen;
  msglen = recv(fd, data, 65536, 0);
  if (msglen <= 0) {
    return 0;
  }
  return msglen;
}

canonical_original_code:
static int input_get_udp(unsigned char *data, int fd)
{
  long msglen;
  msglen = recv(fd, data, 65536, 0);
  if (msglen <= 0) {
    return 0;
  }
  return msglen;
}

variable_types:
data
unsigned char *

variable_types: fd int

variable_types: msglen long


decompiled_code:
__int16 __fastcall int16_cpy(__int16 *a1, __int16 a2)
{
__int16 result; // ax

result = _bswap_16(a2);
*a1 = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func3(__int16 *a1, __int16 a2)
{
__int16 result; // ax

result = func2(a2);
*a1 = result;
return result;
}

original_code:
static inline void int16_cpy(uint8_t *p, uint16_t v)
{
  uint16_t tmp;
  tmp = htons(v);
  memcpy(p, &tmp, 2);
}

canonical_original_code:
static inline void int16_cpy(unsigned char *p, unsigned short v)
{
  unsigned short tmp;
  tmp = htons(v);
  memcpy(p, &tmp, 2);
}

variable_types:
v
unsigned short

variable_types:
tmp
unsigned short


decompiled_code:
__int16 __fastcall udp_payload_header_write(__int64 a1, __int16 a2, char a3)
{
__int16 result; // ax

result = int16_cpy((__int16 *)a1, a2);
*(_BYTE *)(a1 + 2) = a3;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func4(__int64 a1, __int16 a2, char a3)
{
__int16 result; // ax

result = func3((__int16 *)a1, a2);
*(_BYTE *)(a1 + 2) = a3;
return result;
}

original_code:
static inline void udp_payload_header_write(uint8_t *data, int size, uint8_t stream)
{
  int16_cpy(data, size);
  data[2] = stream;
}

canonical_original_code:
static inline void udp_payload_header_write(unsigned char *data, int size, unsigned char stream)
{
  int16_cpy(data, size);
  data[2] = stream;
}

variable_types: size int

variable_types:
stream
unsigned char


original_code:
static uint8_t *udp_chunkise(struct chunkiser_ctx *s, int id, int *size, uint64_t *ts, void **attr, int *attr_size)
{
  int i;
  if (s->buff == ((void *)0)) {
    s->buff = malloc(65536 + (2 + 1));
    if (s->buff == ((void *)0)) {
      *size = -1;
      return ((void *)0);
    }
  }
  for (i = 0; s->fds[i] >= 0; i++) {
    if ((*size = input_get_udp(s->buff + s->size + (2 + 1), s->fds[i]))) {
      uint8_t *res = s->buff;
      struct timeval now;
      udp_payload_header_write(s->buff + s->size, *size, i);
      *size += (2 + 1);
      s->size += *size;
      if (++s->counter % s->every) {
        *size = 0;
        return ((void *)0);
      }
      s->size = 0;
      s->counter = 0;
      s->buff = ((void *)0);
      gettimeofday(&now, ((void *)0));
      *ts = now.tv_sec * 1000000ULL + now.tv_usec;
      return res;
    }
  }
  *size = 0;
  return ((void *)0);
}

canonical_original_code:
static unsigned char *udp_chunkise(struct chunkiser_ctx *s, int id, int *size, unsigned long *ts, void **attr, int *attr_size)
{
  int i;
  if (s->buff == ((void *)0)) {
    s->buff = malloc(65536 + (2 + 1));
    if (s->buff == ((void *)0)) {
      *size = -1;
      return ((void *)0);
    }
  }
  for (i = 0; s->fds[i] >= 0; i++) {
    if ((*size = input_get_udp(s->buff + s->size + (2 + 1), s->fds[i]))) {
      unsigned char *res = s->buff;
      struct timeval now;
      udp_payload_header_write(s->buff + s->size, *size, i);
      *size += (2 + 1);
      s->size += *size;
      if (++s->counter % s->every) {
        *size = 0;
        return ((void *)0);
      }
      s->size = 0;
      s->counter = 0;
      s->buff = ((void *)0);
      gettimeofday(&now, ((void *)0));
      *ts = now.tv_sec * 1000000ULL + now.tv_usec;
      return res;
    }
  }
  *size = 0;
  return ((void *)0);
}

variable_types: id int

variable_types:
ts
unsigned long *

variable_types:
attr
void **

variable_types: i int

variable_types:
res
unsigned char *

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

return_type: unsigned char *

user_defined_types: struct chunkiser_ctx { int fds[-1]; int id; unsigned long start_time; unsigned char *buff; int size; int counter; int every; }


decompiled_code:
__int64 __fastcall listen_udp(unsigned int a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 2, 17);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
fcntl(v1, 4, 2048LL);
*(_DWORD *)&v4.sa_data[10] = 0;
v4.sa_family = 2;
*(_QWORD *)&v4.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)v4.sa_data = _bswap_16(a1);
if ( bind(v2, &v4, 0x10u) < 0 )
{
close(v2);
v2 = -1;
}
else
{
fprintf(stderr, "\topened fd:%d for port:%d\n", v2, a1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 2, 17);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
fcntl(v1, 4, 2048LL);
*(_DWORD *)&v4.sa_data[10] = 0;
v4.sa_family = 2;
*(_QWORD *)&v4.sa_data[2] = (unsigned int)func8(0);
*(_WORD *)v4.sa_data = func2(a1);
if ( bind(v2, &v4, 0x10u) < 0 )
{
close(v2);
v2 = -1;
}
else
{
fprintf(stderr, "\topened fd:%d for port:%d\n", v2, a1);
}
return v2;
}

original_code:
static int listen_udp(int port)
{
  struct sockaddr_in servaddr;
  int r;
  int fd;
  fd = socket(2, SOCK_DGRAM, IPPROTO_UDP);
  if (fd < 0) {
    return -1;
  }
  fcntl(fd, 4, 04000);
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = 2;
  servaddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  servaddr.sin_port = htons(port);
  r = bind(fd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  if (r < 0) {
    close(fd);
    return -1;
  }
  fprintf(stderr,"\topened fd:%d for port:%d\n", fd, port);
  return fd;
}

canonical_original_code:
static int listen_udp(int port)
{
  struct sockaddr_in servaddr;
  int r;
  int fd;
  fd = socket(2, SOCK_DGRAM, IPPROTO_UDP);
  if (fd < 0) {
    return -1;
  }
  fcntl(fd, 4, 04000);
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = 2;
  servaddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  servaddr.sin_port = htons(port);
  r = bind(fd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  if (r < 0) {
    close(fd);
    return -1;
  }
  fprintf(stderr,"\topened fd:%d for port:%d\n", fd, port);
  return fd;
}

variable_types: port int

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

variable_types: r int

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


original_code:
static struct chunkiser_ctx *udp_open(const char *fname, int *period, const char *config)
{
  struct chunkiser_ctx *res;
  struct timeval tv;
  int i;
  const int *ports;
  res = malloc(sizeof(struct chunkiser_ctx));
  if (res == ((void *)0)) {
    return ((void *)0);
  }
  ports = ports_parse(config);
  if (ports[0] == -1) {
    free(res);
    return ((void *)0);
  }
  for (i = 0; ports[i] >= 0; i++) {
    res->fds[i] = listen_udp(ports[i]);
    if (res->fds[i] < 0) {
      fprintf(stderr, "Cannot open port %d\n", ports[i]);
      for (; i>=0 ; i--) {
        close(res->fds[i]);
      }
      free(res);
      return ((void *)0);
    }
  }
  res->fds[i] = -1;
  gettimeofday(&tv, ((void *)0));
  res->start_time = tv.tv_usec + tv.tv_sec * 1000000ULL;
  res->id = 1;
  res->buff = ((void *)0);
  res->size = 0;
  res->counter = 0;
  res->every = 1;
  *period = 0;
  return res;
}

canonical_original_code:
static struct chunkiser_ctx *udp_open(char *fname, int *period, char *config)
{
  struct chunkiser_ctx *res;
  struct timeval tv;
  int i;
  int *ports;
  res = malloc(sizeof(struct chunkiser_ctx));
  if (res == ((void *)0)) {
    return ((void *)0);
  }
  ports = ports_parse(config);
  if (ports[0] == -1) {
    free(res);
    return ((void *)0);
  }
  for (i = 0; ports[i] >= 0; i++) {
    res->fds[i] = listen_udp(ports[i]);
    if (res->fds[i] < 0) {
      fprintf(stderr, "Cannot open port %d\n", ports[i]);
      for (; i>=0 ; i--) {
        close(res->fds[i]);
      }
      free(res);
      return ((void *)0);
    }
  }
  res->fds[i] = -1;
  gettimeofday(&tv, ((void *)0));
  res->start_time = tv.tv_usec + tv.tv_sec * 1000000ULL;
  res->id = 1;
  res->buff = ((void *)0);
  res->size = 0;
  res->counter = 0;
  res->every = 1;
  *period = 0;
  return res;
}

variable_types:
fname
char *

variable_types:
period
int *

variable_types:
config
char *

variable_types: struct chunkiser_ctx { int fds[-1]; int id; unsigned long start_time; unsigned char *buff; int size; int counter; int every; } *

variable_types:
ports
int *

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


chunkise

decompiled_code:
char *__fastcall chunkise(char *s, unsigned int a2, _DWORD *a3, _QWORD *a4)
{
sprintf(s, "Chunk %d", a2);
*a4 = (int)(40000 * a2);
*a3 = strlen(s);
return strdup(s);
}

canonical_decompiled_code:
char *__fastcall func0(char *s, unsigned int a2, _DWORD *a3, _QWORD *a4)
{
sprintf(s, "Chunk %d", a2);
*a4 = (int)(40000 * a2);
*a3 = strlen(s);
return strdup(s);
}

original_code:
static uint8_t *chunkise(struct chunkiser_ctx *s, int id, int *size, uint64_t *ts, void **attr, int *attr_size)
{
  sprintf(s->buff, "Chunk %d", id);
  *ts = 40 * id * 1000;
  *size = strlen(s->buff);
  return strdup(s->buff);
}

canonical_original_code:
static unsigned char *chunkise(struct chunkiser_ctx *s, int id, int *size, unsigned long *ts, void **attr, int *attr_size)
{
  sprintf(s->buff, "Chunk %d", id);
  *ts = 40 * id * 1000;
  *size = strlen(s->buff);
  return strdup(s->buff);
}

variable_types: struct chunkiser_ctx { char buff[80]; } *

variable_types:
size
int *


close

decompiled_code:
void __fastcall close(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
free(a1);
}

original_code:
static void close(struct chunkiser_ctx *s)
{
  free(s);
}


open

decompiled_code:
void *__fastcall open(__int64 a1, _DWORD *a2)
{
fwrite(
"WARNING: This is a dummy chunkiser, only good for debugging! Do not expect anything good from it!\n",
1uLL,
0x62uLL,
stderr);
*a2 = 40000;
return malloc(0x50uLL);
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, _DWORD *a2)
{
fwrite(
"WARNING: This is a dummy chunkiser, only good for debugging! Do not expect anything good from it!\n",
1uLL,
0x62uLL,
stderr);
*a2 = 40000;
return malloc(0x50uLL);
}

original_code:
static struct chunkiser_ctx *open(const char *fname, int *period, const char *config)
{
  fprintf(stderr, "WARNING: This is a dummy chunkiser, only good for debugging! Do not expect anything good from it!\n");
  *period = 40000;
  return malloc(sizeof(struct chunkiser_ctx));
}

canonical_original_code:
static struct chunkiser_ctx *open(char *fname, int *period, char *config)
{
  fprintf(stderr, "WARNING: This is a dummy chunkiser, only good for debugging! Do not expect anything good from it!\n");
  *period = 40000;
  return malloc(sizeof(struct chunkiser_ctx));
}

return_type: struct chunkiser_ctx { char buff[80]; } *


tmanRankFunct

decompiled_code:
int __fastcall tmanRankFunct(const void *a1, const void *a2, const void *a3)
{
size_t v4; // r14
const void *v5; // r13
int result; // eax
int v7; // edx

v4 = mymeta_size;
v5 = zero;
result = memcmp(a1, zero, mymeta_size);
if ( result )
{
if ( !memcmp(a2, v5, v4) )
{
result = memcmp(a3, v5, v4);
if ( result )
result = 2;
}
else
{
v7 = memcmp(a3, v5, v4);
result = 1;
if ( v7 )
result = userRankFunct(a1, a2, a3);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(const void *a1, const void *a2, const void *a3)
{
size_t v4; // r14
const void *v5; // r13
int result; // eax
int v7; // edx

v4 = mymeta_size;
v5 = zero;
result = memcmp(a1, zero, mymeta_size);
if ( result )
{
if ( !memcmp(a2, v5, v4) )
{
result = memcmp(a3, v5, v4);
if ( result )
result = 2;
}
else
{
v7 = memcmp(a3, v5, v4);
result = 1;
if ( v7 )
result = userRankFunct(a1, a2, a3);
}
}
return result;
}

original_code:
static int tmanRankFunct (const void *target, const void *p1, const void *p2) {
 if (memcmp(target,zero,mymeta_size) == 0 || (memcmp(p1,zero,mymeta_size) == 0 && memcmp(p2,zero,mymeta_size) == 0))
  return 0;
 if (memcmp(p1,zero,mymeta_size) == 0)
  return 2;
 if (memcmp(p2,zero,mymeta_size) == 0)
  return 1;
 return userRankFunct(target, p1, p2);
}

canonical_original_code:
static int tmanRankFunct(void *target, void *p1, void *p2) {
 if (memcmp(target,zero,mymeta_size) == 0 || (memcmp(p1,zero,mymeta_size) == 0 && memcmp(p2,zero,mymeta_size) == 0))
  return 0;
 if (memcmp(p1,zero,mymeta_size) == 0)
  return 2;
 if (memcmp(p2,zero,mymeta_size) == 0)
  return 1;
 return userRankFunct(target, p1, p2);
}

variable_types:
target
void *


decompiled_code:
__int64 time_to_send()
{
__suseconds_t v0; // rax
unsigned int v1; // ecx

v0 = gettime();
v1 = 0;
if ( v0 - currtime > (unsigned __int64)period )
{
currtime += period;
v1 = 1;
}
return v1;
}

canonical_decompiled_code:
__int64 func9()
{
__suseconds_t v0; // rax
unsigned int v1; // ecx

v0 = func8();
v1 = 0;
if ( v0 - currtime > (unsigned __int64)period )
{
currtime += period;
v1 = 1;
}
return v1;
}

original_code:
static int time_to_send(void)
{
 if (gettime() - currtime > period) {
  currtime += period;
  return 1;
 }
 return 0;
}

canonical_original_code:
static int time_to_send()
{
 if (gettime() - currtime > period) {
  currtime += period;
  return 1;
 }
 return 0;
}


tmanChangeMetadata

decompiled_code:
__int64 __fastcall tmanChangeMetadata(__int64 a1)
{
int v1; // edx
__int64 result; // rax
__int64 v3; // rbx

v1 = blist_proto_metadata_update();
result = 0xFFFFFFFFLL;
if ( v1 > 0 )
{
mymeta = a1;
result = 1LL;
if ( active >= 0 )
{
v3 = blist_cache_rank(local_cache, tmanRankFunct, 0LL, a1);
result = 1LL;
if ( v3 )
{
blist_cache_free(local_cache);
local_cache = v3;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v1; // edx
__int64 result; // rax
__int64 v3; // rbx

v1 = blist_proto_metadata_update();
result = 0xFFFFFFFFLL;
if ( v1 > 0 )
{
mymeta = a1;
result = 1LL;
if ( active >= 0 )
{
v3 = blist_cache_rank(local_cache, tmanRankFunct, 0LL, a1);
result = 1LL;
if ( v3 )
{
blist_cache_free(local_cache);
local_cache = v3;
result = 1LL;
}
}
}
return result;
}

original_code:
int tmanChangeMetadata(void *metadata, int metadata_size)
{
 return tm->changeMetadata(metadata, metadata_size);
}

variable_types:
metadata
void *


gettime

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

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

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

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

original_code:
static uint64_t gettime(void)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return tv.tv_usec + tv.tv_sec * 1000000ull;
}

canonical_original_code:
static unsigned long gettime()
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return tv.tv_usec + tv.tv_sec * 1000000ull;
}


decompiled_code:
__int16 __fastcall int16_rcpy(__int16 *a1)
{
return _bswap_16(*a1);
}

canonical_decompiled_code:
__int16 __fastcall func1(__int16 *a1)
{
return func0(*a1);
}

original_code:
static inline uint16_t int16_rcpy(const uint8_t *p)
{
  uint16_t tmp;
  memcpy(&tmp, p, 2);
  tmp = ntohs(tmp);
  return tmp;
}

canonical_original_code:
static inline unsigned short int16_rcpy(unsigned char *p)
{
  unsigned short tmp;
  memcpy(&tmp, p, 2);
  tmp = ntohs(tmp);
  return tmp;
}

variable_types:
p
unsigned char *

variable_types:
tmp
unsigned short

return_type: unsigned short


canonical_decompiled_code:
__int16 __fastcall func2(__int16 *a1, __int16 a2)
{
__int16 result; // ax

result = func0(a2);
*a1 = result;
return result;
}

variable_types:
v
unsigned short


parseChunkMsg

decompiled_code:
__int64 __fastcall parseChunkMsg(__int16 *a1, int a2, __int64 a3, __int16 *a4)
{
__int64 result; // rax
int v6; // edx

result = 0xFFFFFFFFLL;
if ( a3 )
{
v6 = decodeChunk(a3, a1 + 1, (unsigned int)(a2 - 2));
result = 0xFFFFFFFFLL;
if ( v6 >= 0 )
{
*a4 = int16_rcpy(a1);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int16 *a1, int a2, __int64 a3, __int16 *a4)
{
__int64 result; // rax
int v6; // edx

result = 0xFFFFFFFFLL;
if ( a3 )
{
v6 = decodeChunk(a3, a1 + 1, (unsigned int)(a2 - 2));
result = 0xFFFFFFFFLL;
if ( v6 >= 0 )
{
*a4 = func1(a1);
result = 1LL;
}
}
return result;
}

original_code:
int parseChunkMsg(const uint8_t *buff, int buff_len, struct chunk *c, uint16_t *transid)
{
  int res;
  if (c == ((void *)0)) {
    return -1;
  }
  res = decodeChunk(c, buff + sizeof(*transid), buff_len - sizeof(*transid));
  if (res < 0) {
    return -1;
  }
  *transid = int16_rcpy(buff);
  return 1;
}

canonical_original_code:
int parseChunkMsg(unsigned char *buff, int buff_len, struct chunk *c, unsigned short *transid)
{
  int res;
  if (c == ((void *)0)) {
    return -1;
  }
  res = decodeChunk(c, buff + sizeof(*transid), buff_len - sizeof(*transid));
  if (res < 0) {
    return -1;
  }
  *transid = int16_rcpy(buff);
  return 1;
}

variable_types:
buff
unsigned char *

variable_types: struct chunk { int id; int size; unsigned char *data; unsigned long timestamp; void *attributes; int attributes_size; } *

variable_types:
transid
unsigned short *

variable_types: res int


decompiled_code:
const char *__fastcall status_print(int a1)
{
const char *result; // rax

result = "awake";
if ( a1 != 1 )
{
result = "tired";
if ( a1 != 2 )
{
result = "Boh?";
if ( !a1 )
result = "sleeping";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

result = "awake";
if ( a1 != 1 )
{
result = "tired";
if ( a1 != 2 )
{
result = "Boh?";
if ( !a1 )
result = "sleeping";
}
}
return result;
}

original_code:
static const char *status_print(enum peer_state s)
{
  switch (s) {
    case psleep:
      return "sleeping";
    case awake:
      return "awake";
    case tired:
      return "tired";
    default:
      return "Boh?";
  }
}

canonical_original_code:
static char *status_print(enum peer_state s)
{
  switch (s) {
    case psleep:
      return "sleeping";
    case awake:
      return "awake";
    case tired:
      return "tired";
    default:
      return "Boh?";
  }
}

variable_types: enum peer_state { psleep=0, awake=1, tired=2 }


decompiled_code:
unsigned int __fastcall cmdline_parse(int argc, char **argv)
{
unsigned int result; // eax

my_attr = 1;
strcpy(dest, "red");
while ( 1 )
{
result = getopt(argc, argv, "p:i:P:I:c:ST");
if ( result == -1 )
break;
switch ( result )
{
case 'I':
my_addr = (char *)iface_addr(optarg);
break;
case 'P':
port = atoi(optarg);
break;
case 'S':
my_attr = 0;
break;
case 'T':
my_attr = 2;
break;
case 'c':
strcpy(dest, optarg);
break;
case 'i':
srv_ip = (__int64)strdup(optarg);
break;
case 'p':
srv_port = atoi(optarg);
break;
default:
fprintf(stderr, "Error: unknown option %c\n", result);
exit(-1);
}
}
return result;
}

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

my_attr = 1;
strcpy(dest, "red");
while ( 1 )
{
result = getopt(argc, argv, "p:i:P:I:c:ST");
if ( result == -1 )
break;
switch ( result )
{
case 'I':
my_addr = (char *)iface_addr(optarg);
break;
case 'P':
port = atoi(optarg);
break;
case 'S':
my_attr = 0;
break;
case 'T':
my_attr = 2;
break;
case 'c':
strcpy(dest, optarg);
break;
case 'i':
srv_ip = (__int64)strdup(optarg);
break;
case 'p':
srv_port = atoi(optarg);
break;
default:
fprintf(stderr, "Error: unknown option %c\n", result);
exit(-1);
}
}
return result;
}

original_code:
static void cmdline_parse(int argc, char *argv[])
{
  int o;
  my_attr.state = awake;
  sprintf(my_attr.colour, "red");
  while ((o = getopt(argc, argv, "p:i:P:I:c:ST")) != -1) {
    switch(o) {
      case 'p':
        srv_port = atoi(optarg);
        break;
      case 'i':
        srv_ip = strdup(optarg);
        break;
      case 'P':
        port = atoi(optarg);
        break;
      case 'I':
        my_addr = iface_addr(optarg);
        break;
      case 'c':
        strcpy(my_attr.colour, optarg);
        break;
      case 'S':
        my_attr.state = psleep;
        break;
      case 'T':
        my_attr.state = tired;
        break;
      default:
        fprintf(stderr, "Error: unknown option %c\n", o);
        exit(-1);
    }
  }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: o int


decompiled_code:
__int64 __fastcall int_rcpy(unsigned int *a1)
{
return _bswap_32(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
return func0(*a1);
}

original_code:
static inline uint32_t int_rcpy(const uint8_t *p)
{
  uint32_t tmp;
  memcpy(&tmp, p, 4);
  tmp = ntohl(tmp);
  return tmp;
}

canonical_original_code:
static inline unsigned int int_rcpy(unsigned char *p)
{
  unsigned int tmp;
  memcpy(&tmp, p, 4);
  tmp = ntohl(tmp);
  return tmp;
}

variable_types:
tmp
unsigned int


decompiled_code:
__int64 __fastcall prio_decode(__int64 a1, __int64 a2, int a3, _DWORD *a4)
{
unsigned int v4; // eax
unsigned int *v5; // rbp
__int64 i; // rbx
__int64 result; // rax

v4 = *(_DWORD *)(a1 + 4);
if ( *a4 + 4 * v4 + 12 == a3 )
{
v5 = (unsigned int *)(a2 + 12);
for ( i = 0LL; v4 > (unsigned int)i; ++v5 )
{
*(_DWORD *)(*(_QWORD *)(a1 + 16) + 4 * i) = int_rcpy(v5);
v4 = *(_DWORD *)(a1 + 4);
++i;
}
*(_DWORD *)(a1 + 8) = v4;
result = a2 + 4 * v4 + 12;
}
else
{
fwrite("Error in decoding chunkid set - wrong length.\n", 1uLL, 0x2EuLL, stderr);
chunkID_set_free(a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3, _DWORD *a4)
{
unsigned int v4; // eax
unsigned int *v5; // rbp
__int64 i; // rbx
__int64 result; // rax

v4 = *(_DWORD *)(a1 + 4);
if ( *a4 + 4 * v4 + 12 == a3 )
{
v5 = (unsigned int *)(a2 + 12);
for ( i = 0LL; v4 > (unsigned int)i; ++v5 )
{
*(_DWORD *)(*(_QWORD *)(a1 + 16) + 4 * i) = func1(v5);
v4 = *(_DWORD *)(a1 + 4);
++i;
}
*(_DWORD *)(a1 + 8) = v4;
result = a2 + 4 * v4 + 12;
}
else
{
fwrite("Error in decoding chunkid set - wrong length.\n", 1uLL, 0x2EuLL, stderr);
chunkID_set_free(a1);
result = 0LL;
}
return result;
}

original_code:
static const uint8_t *prio_decode(struct chunkID_set *h, const uint8_t *buff, int buff_len, int *meta_len)
{
  int i;
  if (buff_len != h->size * 4 + 12 + *meta_len) {
    fprintf(stderr, "Error in decoding chunkid set - wrong length.\n");
    chunkID_set_free(h);
    return ((void *)0);
  }
  for (i = 0; i < h->size; i++) {
    h->elements[i] = int_rcpy(buff + 12 + i * 4);
  }
  h->n_elements = h->size;
  return buff + 12 + h->size * 4;
}

canonical_original_code:
static unsigned char *prio_decode(struct chunkID_set *h, unsigned char *buff, int buff_len, int *meta_len)
{
  int i;
  if (buff_len != h->size * 4 + 12 + *meta_len) {
    fprintf(stderr, "Error in decoding chunkid set - wrong length.\n");
    chunkID_set_free(h);
    return ((void *)0);
  }
  for (i = 0; i < h->size; i++) {
    h->elements[i] = int_rcpy(buff + 12 + i * 4);
  }
  h->n_elements = h->size;
  return buff + 12 + h->size * 4;
}

variable_types: struct chunkID_set { unsigned int type; unsigned int size; unsigned int n_elements; int *elements; struct cids_ops_iface { int (*add_chunk)(struct chunkID_set *h, int chunk_id); int (*check)(struct chunkID_set *h, int chunk_id); } *ops; struct cids_encoding_iface { unsigned char *(*encode)(struct chunkID_set *h, unsigned char *buff, int buff_len, int meta_len); unsigned char *(*decode)(struct chunkID_set *h, unsigned char *buff, int buff_len, int *meta_len); } *enc; } *

variable_types: i int


decompiled_code:
__int64 __fastcall int_cpy(_DWORD *a1, unsigned int a2)
{
__int64 result; // rax

result = _bswap_32(a2);
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, unsigned int a2)
{
__int64 result; // rax

result = func0(a2);
*a1 = result;
return result;
}

original_code:
static inline void int_cpy(uint8_t *p, int v)
{
  uint32_t tmp;
  tmp = htonl(v);
  memcpy(p, &tmp, 4);
}

canonical_original_code:
static inline void int_cpy(unsigned char *p, int v)
{
  unsigned int tmp;
  tmp = htonl(v);
  memcpy(p, &tmp, 4);
}

variable_types: v int


decompiled_code:
__int64 __fastcall prio_encode(__int64 a1, _DWORD *a2, unsigned int a3, int a4)
{
unsigned int v6; // eax
_DWORD *v7; // rbp
__int64 v8; // rbx

int_cpy(a2, *(_DWORD *)(a1 + 8));
v6 = *(_DWORD *)(a1 + 8);
if ( a4 + 4 * v6 + 12 > a3 )
return 0LL;
if ( v6 )
{
v7 = a2 + 3;
v8 = 0LL;
do
{
int_cpy(v7, *(_DWORD *)(*(_QWORD *)(a1 + 16) + 4 * v8));
v6 = *(_DWORD *)(a1 + 8);
++v8;
++v7;
}
while ( v6 > (unsigned int)v8 );
}
return (__int64)&a2[v6 + 3];
}

original_code:
static uint8_t *prio_encode(const struct chunkID_set *h, uint8_t *buff, int buff_len, int meta_len)
{
  int i;
  int_cpy(buff, h->n_elements);
  if (buff_len < h->n_elements * 4 + 12 + meta_len) {
    return ((void *)0);
  }
  for (i = 0; i < h->n_elements; i++) {
    int_cpy(buff + 12 + i * 4, h->elements[i]);
  }
  return buff + 12 + h->n_elements * 4;
}

canonical_original_code:
static unsigned char *prio_encode(struct chunkID_set *h, unsigned char *buff, int buff_len, int meta_len)
{
  int i;
  int_cpy(buff, h->n_elements);
  if (buff_len < h->n_elements * 4 + 12 + meta_len) {
    return ((void *)0);
  }
  for (i = 0; i < h->n_elements; i++) {
    int_cpy(buff + 12 + i * 4, h->elements[i]);
  }
  return buff + 12 + h->n_elements * 4;
}


decompiled_code:
__int64 __fastcall blist_proto_metadata_update(__int64 a1, unsigned int a2)
{
__int64 v2; // rax

v2 = blist_nodeid(myEntry, 0LL);
return 2 * (unsigned int)((int)blist_cache_metadata_update(myEntry, v2, a1, a2) > 0) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
__int64 v2; // rax

v2 = blist_nodeid(myEntry, 0LL);
return 2 * (unsigned int)((int)blist_cache_metadata_update(myEntry, v2, a1, a2) > 0) - 1;
}

original_code:
int blist_proto_metadata_update(void *meta, int meta_size)
{
  if (blist_cache_metadata_update(myEntry, blist_nodeid(myEntry, 0), meta, meta_size) > 0) {
    return 1;
  }
  return -1;
}

variable_types:
meta
void *


decompiled_code:
char *__fastcall iface_addr(char *s2)
{
char *v1; // r14
struct ifaddrs *v2; // rbx
bool v3; // r12
bool v4; // r13
struct sockaddr *v5; // rbp
int v6; // eax
char *v7; // rax
char *v8; // rax
struct ifaddrs *ifap; // [rsp+8h] [rbp-40h] BYREF

if ( getifaddrs(&ifap) == -1 )
{
perror("getif_addrs");
return 0LL;
}
v2 = ifap;
if ( !ifap )
goto LABEL_18;
v3 = l3 == 0;
v4 = l3 == 1;
while ( 1 )
{
v5 = v2->ifa_addr;
if ( !v5 )
goto LABEL_6;
v6 = v5->sa_family;
if ( v6 == 2 && v3 )
break;
if ( v6 == 10 && v4 && !strcmp(v2->ifa_name, s2) )
{
v7 = (char *)malloc(0x2EuLL);
v1 = v7;
if ( v7 )
{
if ( inet_ntop(10, &v5->sa_data[6], v7, 0x2Eu) )
goto LABEL_18;
goto LABEL_15;
}
goto LABEL_20;
}
LABEL_6:
v2 = v2->ifa_next;
if ( !v2 )
goto LABEL_18;
}
if ( strcmp(v2->ifa_name, s2) )
goto LABEL_6;
v8 = (char *)malloc(0x10uLL);
v1 = v8;
if ( !v8 )
{
LABEL_20:
perror("malloc host_addr");
return v1;
}
if ( !inet_ntop(2, &v5->sa_data[2], v8, 0x10u) )
{
LABEL_15:
perror("inet_ntop");
return 0LL;
}
LABEL_18:
freeifaddrs(ifap);
return v1;
}

canonical_decompiled_code:
char *__fastcall func0(char *s2)
{
char *v1; // r14
struct ifaddrs *v2; // rbx
bool v3; // r12
bool v4; // r13
struct sockaddr *v5; // rbp
int v6; // eax
char *v7; // rax
char *v8; // rax
struct ifaddrs *ifap; // [rsp+8h] [rbp-40h] BYREF

if ( getifaddrs(&ifap) == -1 )
{
perror("getif_addrs");
return 0LL;
}
v2 = ifap;
if ( !ifap )
goto LABEL_18;
v3 = l3 == 0;
v4 = l3 == 1;
while ( 1 )
{
v5 = v2->ifa_addr;
if ( !v5 )
goto LABEL_6;
v6 = v5->sa_family;
if ( v6 == 2 && v3 )
break;
if ( v6 == 10 && v4 && !strcmp(v2->ifa_name, s2) )
{
v7 = (char *)malloc(0x2EuLL);
v1 = v7;
if ( v7 )
{
if ( inet_ntop(10, &v5->sa_data[6], v7, 0x2Eu) )
goto LABEL_18;
goto LABEL_15;
}
goto LABEL_20;
}
LABEL_6:
v2 = v2->ifa_next;
if ( !v2 )
goto LABEL_18;
}
if ( strcmp(v2->ifa_name, s2) )
goto LABEL_6;
v8 = (char *)malloc(0x10uLL);
v1 = v8;
if ( !v8 )
{
LABEL_20:
perror("malloc host_addr");
return v1;
}
if ( !inet_ntop(2, &v5->sa_data[2], v8, 0x10u) )
{
LABEL_15:
perror("inet_ntop");
return 0LL;
}
LABEL_18:
freeifaddrs(ifap);
return v1;
}

original_code:
const char *iface_addr(const char *iface)
{
    struct ifaddrs *if_addr, *ifap;
 int family;
 char *host_addr;
 int ifcount;
 if (getifaddrs(&if_addr) == -1)
 {
   perror("getif_addrs");
   return ((void *)0);
 }
 ifcount = 0;
 for (ifap = if_addr; ifap != ((void *)0); ifap = ifap->ifa_next)
 {
  if (ifap->ifa_addr == ((void *)0))
  {
   ifcount++;
   continue;
  }
  family = ifap->ifa_addr->sa_family;
  if (l3 == IPv4 && family == 2 && !strcmp (ifap->ifa_name, iface))
  {
   host_addr = malloc((size_t)16);
   if (!host_addr)
   {
    perror("malloc host_addr");
    return ((void *)0);
   }
   if (!inet_ntop(2, (void *)&(((struct sockaddr_in *)(ifap->ifa_addr))->sin_addr), host_addr, 16))
   {
    perror("inet_ntop");
    return ((void *)0);
   }
   break;
  }
  if (l3 == IPv6 && family == 10 && !strcmp (ifap->ifa_name, iface))
  {
   host_addr = malloc((size_t)46);
   if (!host_addr)
   {
    perror("malloc host_addr");
    return ((void *)0);
   }
   if (!inet_ntop(10, (void *)&(((struct sockaddr_in6 *)(ifap->ifa_addr))->sin6_addr), host_addr, 46))
   {
    perror("inet_ntop");
    return ((void *)0);
   }
   break;
  }
 }
 freeifaddrs(if_addr);
 return host_addr;
}

canonical_original_code:
char *iface_addr(char *iface)
{
    struct ifaddrs *if_addr; struct ifaddrs *ifap;
 int family;
 char *host_addr;
 int ifcount;
 if (getifaddrs(&if_addr) == -1)
 {
   perror("getif_addrs");
   return ((void *)0);
 }
 ifcount = 0;
 for (ifap = if_addr; ifap != ((void *)0); ifap = ifap->ifa_next)
 {
  if (ifap->ifa_addr == ((void *)0))
  {
   ifcount++;
   continue;
  }
  family = ifap->ifa_addr->sa_family;
  if (l3 == IPv4 && family == 2 && !strcmp (ifap->ifa_name, iface))
  {
   host_addr = malloc((unsigned long)16);
   if (!host_addr)
   {
    perror("malloc host_addr");
    return ((void *)0);
   }
   if (!inet_ntop(2, (void *)&(((struct sockaddr_in *)(ifap->ifa_addr))->sin_addr), host_addr, 16))
   {
    perror("inet_ntop");
    return ((void *)0);
   }
   break;
  }
  if (l3 == IPv6 && family == 10 && !strcmp (ifap->ifa_name, iface))
  {
   host_addr = malloc((unsigned long)46);
   if (!host_addr)
   {
    perror("malloc host_addr");
    return ((void *)0);
   }
   if (!inet_ntop(10, (void *)&(((struct sockaddr_in6 *)(ifap->ifa_addr))->sin6_addr), host_addr, 46))
   {
    perror("inet_ntop");
    return ((void *)0);
   }
   break;
  }
 }
 freeifaddrs(if_addr);
 return host_addr;
}

variable_types:
iface
char *

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

variable_types: family int

variable_types: ifcount int

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }


testRanker

decompiled_code:
__int64 __fastcall testRanker(_DWORD *a1, _DWORD *a2, _DWORD *a3)
{
signed int v5; // edx
signed int v6; // eax
unsigned int v7; // ecx

v5 = abs32(*a1 - *a2);
v6 = abs32(*a1 - *a3);
v7 = 0;
if ( v5 != v6 )
v7 = (v5 >= v6) + 1;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _DWORD *a2, _DWORD *a3)
{
signed int v5; // edx
signed int v6; // eax
unsigned int v7; // ecx

v5 = abs32(*a1 - *a2);
v6 = abs32(*a1 - *a3);
v7 = 0;
if ( v5 != v6 )
v7 = (v5 >= v6) + 1;
return v7;
}

original_code:
int testRanker (const void *tin, const void *p1in, const void *p2in) {
        const int *tt, *pp1, *pp2;
      tt = ((const int *)(tin));
      pp1 = ((const int *)(p1in));
      pp2 = ((const int *)(p2in));
        return (abs(*tt-*pp1) == abs(*tt-*pp2))?0:(abs(*tt-*pp1) < abs(*tt-*pp2))?1:2;
}

canonical_original_code:
int testRanker(void *tin, void *p1in, void *p2in) {
        int *tt; int *pp1; int *pp2;
      tt = ((int *)(tin));
      pp1 = ((int *)(p1in));
      pp2 = ((int *)(p2in));
        return (abs(*tt-*pp1) == abs(*tt-*pp2))?0:(abs(*tt-*pp1) < abs(*tt-*pp2))?1:2;
}

variable_types:
tin
void *

variable_types:
tt
int *


decompiled_code:
int __fastcall cmdline_parse(int argc, char **argv)
{
int v2; // eax

while ( 1 )
{
v2 = getopt(argc, argv, "p:i:P:I:");
if ( v2 == -1 )
break;
if ( v2 == 105 )
{
srv_ip = (__int64)strdup(optarg);
}
else if ( v2 > 105 )
{
if ( v2 != 112 )
goto LABEL_12;
srv_port = atoi(optarg);
}
else if ( v2 == 73 )
{
my_addr = (char *)iface_addr(optarg);
}
else
{
if ( v2 != 80 )
{
LABEL_12:
fprintf(stderr, "Error: unknown option %c\n", (unsigned int)v2);
exit(-1);
}
port = atoi(optarg);
}
}
if ( srv_port )
{
srand(srv_port);
srv_metadata = (int)((double)rand() / 2147483647.0 * 1000.0 + 1.0);
}
srand(port);
my_metadata = (int)((double)rand() / 2147483647.0 * 1000.0 + 1.0);
return fprintf(stderr, "\tMy metadata = %d\n", (unsigned int)my_metadata);
}

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

while ( 1 )
{
v2 = getopt(argc, argv, "p:i:P:I:");
if ( v2 == -1 )
break;
if ( v2 == 105 )
{
srv_ip = (__int64)strdup(optarg);
}
else if ( v2 > 105 )
{
if ( v2 != 112 )
goto LABEL_12;
srv_port = atoi(optarg);
}
else if ( v2 == 73 )
{
my_addr = (char *)iface_addr(optarg);
}
else
{
if ( v2 != 80 )
{
LABEL_12:
fprintf(stderr, "Error: unknown option %c\n", (unsigned int)v2);
exit(-1);
}
port = atoi(optarg);
}
}
if ( srv_port )
{
srand(srv_port);
srv_metadata = (int)((double)rand() / 2147483647.0 * 1000.0 + 1.0);
}
srand(port);
my_metadata = (int)((double)rand() / 2147483647.0 * 1000.0 + 1.0);
return fprintf(stderr, "\tMy metadata = %d\n", (unsigned int)my_metadata);
}

original_code:
static void cmdline_parse(int argc, char *argv[])
{
  int o;
  while ((o = getopt(argc, argv, "p:i:P:I:")) != -1) {
    switch(o) {
      case 'p':
        srv_port = atoi(optarg);
        break;
      case 'i':
        srv_ip = strdup(optarg);
        break;
      case 'P':
        port = atoi(optarg);
        break;
      case 'I':
        my_addr = iface_addr(optarg);
        break;
      default:
        fprintf(stderr, "Error: unknown option %c\n", o);
        exit(-1);
    }
  }
  if (srv_port) {
          srand(srv_port);
          srv_metadata = 1 + ((double)rand() / (double)2147483647)*1000;
  }
  srand(port);
  my_metadata = 1 + ((double)rand() / (double)2147483647)*1000;
  fprintf(stderr,"\tMy metadata = %d\n",my_metadata);
}


decompiled_code:
__int64 __fastcall time_to_send(__int64 a1)
{
int v1; // ebp
__suseconds_t v2; // rdx
unsigned int v3; // esi

if ( *(_BYTE *)(a1 + 24) )
v1 = *(_DWORD *)(a1 + 28);
else
v1 = *(_DWORD *)(a1 + 32);
v2 = gettime();
v3 = 0;
if ( v2 - *(_QWORD *)a1 > (unsigned __int64)v1 )
{
if ( *(_BYTE *)(a1 + 24) )
*(_QWORD *)a1 = v2;
else
*(_QWORD *)a1 += v1;
v3 = 1;
}
return v3;
}


gettime

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


decompiled_code:
__int64 __fastcall time_to_send(__int64 a1)
{
int v1; // ebp
unsigned int v2; // esi

if ( *(_BYTE *)(a1 + 24) )
v1 = *(_DWORD *)(a1 + 40);
else
v1 = *(_DWORD *)(a1 + 48);
v2 = 0;
if ( gettime() - *(_QWORD *)a1 > (unsigned __int64)v1 )
{
*(_QWORD *)a1 += v1;
v2 = 1;
}
return v2;
}


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

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


decompiled_code:
__int64 __fastcall time_to_send(__int64 a1)
{
int v1; // ebp
unsigned int v2; // esi

if ( *(_BYTE *)(a1 + 24) )
v1 = *(_DWORD *)(a1 + 28);
else
v1 = *(_DWORD *)(a1 + 36);
v2 = 0;
if ( gettime() - *(_QWORD *)a1 > (unsigned __int64)v1 )
{
*(_QWORD *)a1 += v1;
v2 = 1;
}
return v2;
}


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

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


chunkise

decompiled_code:
__int64 __fastcall chunkise(_QWORD *a1, unsigned int *a2)
{
__int64 v2; // rax
unsigned int v3; // edx

v2 = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *, unsigned int *, unsigned int *, unsigned int *))(a1[1] + 16LL))(
*a1,
*a2,
a2 + 1,
a2 + 4,
a2 + 6,
a2 + 8);
*((_QWORD *)a2 + 1) = v2;
v3 = 1;
if ( !v2 )
v3 = (int)a2[1] >> 31;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, unsigned int *a2)
{
__int64 v2; // rax
unsigned int v3; // edx

v2 = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *, unsigned int *, unsigned int *, unsigned int *))(a1[1] + 16LL))(
*a1,
*a2,
a2 + 1,
a2 + 4,
a2 + 6,
a2 + 8);
*((_QWORD *)a2 + 1) = v2;
v3 = 1;
if ( !v2 )
v3 = (int)a2[1] >> 31;
return v3;
}

original_code:
static uint8_t *chunkise(struct chunkiser_ctx *s, int id, int *size, uint64_t *ts, void **attr, int *attr_size)
{
  sprintf(s->buff, "Chunk %d", id);
  *ts = 40 * id * 1000;
  *size = strlen(s->buff);
  return strdup(s->buff);
}

variable_types: struct chunkiser_ctx { char buff[80]; } *

variable_types: id int

variable_types:
size
int *

variable_types:
ts
unsigned long *

variable_types:
attr
void **


decompiled_code:
__int64 __fastcall get_from_cloud(_QWORD *a1)
{
return (*(__int64 (__fastcall **)(_QWORD))(*a1 + 8LL))(a1[1]);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
return (*(__int64 (__fastcall **)(_QWORD))(*a1 + 8LL))(a1[1]);
}

original_code:
int get_from_cloud(void *context, const char *key, uint8_t *header_ptr,
                   int header_size, int free_header)
{
  return get_from_cloud_default(context, key, header_ptr, header_size,
                                free_header, ((void *)0), 0, 0);
}

canonical_original_code:
int get_from_cloud(void *context, char *key, unsigned char *header_ptr, int header_size, int free_header)
{
  return get_from_cloud_default(context, key, header_ptr, header_size,
                                free_header, ((void *)0), 0, 0);
}

variable_types:
context
void *

variable_types:
key
char *


decompiled_code:
__int64 __fastcall get_from_cloud(_QWORD *a1, const char *a2, __int64 a3, int a4, int a5)
{
return get_from_cloud_default(a1, a2, a3, a4, a5, 0LL, 0, 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, const char *a2, __int64 a3, int a4, int a5)
{
return func7(a1, a2, a3, a4, a5, 0LL, 0, 0);
}


decompiled_code:
__int64 prepara_socket()
{
unsigned int v0; // ebx

sock = socket(2, 1, 0);
if ( sock == -1 )
{
v0 = -1;
fwrite("Erro ao tentar abrir socket!\n", 1uLL, 0x1DuLL, stderr);
}
else
{
puts("Socket aberto!");
v0 = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebx

sock = socket(2, 1, 0);
if ( sock == -1 )
{
v0 = -1;
fwrite("Erro ao tentar abrir socket!\n", 1uLL, 0x1DuLL, stderr);
}
else
{
puts("Socket aberto!");
v0 = 0;
}
return v0;
}

original_code:
int prepara_socket()
{
 sock = socket(2, SOCK_STREAM, 0);
 if(sock == -1)
 {
  fprintf(stderr, "Erro ao tentar abrir socket!\n");
  return -1;
 }
 else
 {
  printf("Socket aberto!\n");
  return 0;
 }
}


decompiled_code:
__int64 __fastcall prepara_server(const char *a1)
{
unsigned int v1; // ebx

host = (__int64)gethostbyname(a1);
if ( host )
{
puts("Host obtido!");
endereco.sa_family = 2;
*(_DWORD *)&endereco.sa_data[2] = ***(_DWORD ***)(host + 24);
*(_WORD *)endereco.sa_data = _bswap_16(10500);
v1 = connect(sock, &endereco, 0x10u);
if ( v1 == -1 )
{
fwrite("Erro ao tentar conectar!\n", 1uLL, 0x19uLL, stderr);
}
else
{
puts("Conectado!");
memset(&servidor, 0, sizeof(servidor));
servidor.fds_bits[sock / 64] |= 1LL << (sock % 64);
v1 = 0;
}
}
else
{
fwrite("Erro ao tentar obter host!\n", 1uLL, 0x1BuLL, stderr);
v1 = -1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
unsigned int v1; // ebx

host = (__int64)gethostbyname(a1);
if ( host )
{
puts("Host obtido!");
endereco.sa_family = 2;
*(_DWORD *)&endereco.sa_data[2] = ***(_DWORD ***)(host + 24);
*(_WORD *)endereco.sa_data = func0(10500);
v1 = connect(sock, &endereco, 0x10u);
if ( v1 == -1 )
{
fwrite("Erro ao tentar conectar!\n", 1uLL, 0x19uLL, stderr);
}
else
{
puts("Conectado!");
memset(&servidor, 0, sizeof(servidor));
servidor.fds_bits[sock / 64] |= 1LL << (sock % 64);
v1 = 0;
}
}
else
{
fwrite("Erro ao tentar obter host!\n", 1uLL, 0x1BuLL, stderr);
v1 = -1;
}
return v1;
}

original_code:
int prepara_server(char *server)
{
 host = gethostbyname(server);
 if(host == ((void *)0))
 {
  fprintf(stderr, "Erro ao tentar obter host!\n");
  return -1;
 }
 else
  printf("Host obtido!\n");
 endereco.sin_family = 2;
 endereco.sin_addr = *((struct in_addr *) host->h_addr_list[0]);
 endereco.sin_port = htons(10500);
 if(connect(sock, (struct sockaddr *) &endereco, sizeof(struct sockaddr_in)) == -1)
 {
  fprintf(stderr, "Erro ao tentar conectar!\n");
  return -1;
 }
 printf("Conectado!\n");
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&servidor)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&servidor)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 return 0;
}

canonical_original_code:
int prepara_server(char *server)
{
 host = gethostbyname(server);
 if(host == ((void *)0))
 {
  fprintf(stderr, "Erro ao tentar obter host!\n");
  return -1;
 }
 else
  printf("Host obtido!\n");
 endereco.sin_family = 2;
 endereco.sin_addr = *((struct in_addr *) host->h_addr_list[0]);
 endereco.sin_port = htons(10500);
 if(connect(sock, (struct sockaddr *) &endereco, sizeof(struct sockaddr_in)) == -1)
 {
  fprintf(stderr, "Erro ao tentar conectar!\n");
  return -1;
 }
 printf("Conectado!\n");
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&servidor)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&servidor)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 return 0;
}

variable_types:
server
char *


decompiled_code:
ssize_t __fastcall envia_buffer(int a1, int a2, int a3, int a4, int a5, int a6, char buf)
{
return write(sock, &buf, 0x18uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func3(int a1, int a2, int a3, int a4, int a5, int a6, char buf)
{
return write(sock, &buf, 0x18uLL);
}

original_code:
void envia_buffer(struct Buffer buffer)
{
 write(sock, &buffer, sizeof(struct Buffer));
}

variable_types: struct Buffer { int tipo; int id; int x; int y; int angulo; int vida; }


decompiled_code:
int finaliza_rede()
{
int result; // eax

if ( close(sock) == -1 )
result = fwrite("Erro ao tentar fechar socket!\n", 1uLL, 0x1EuLL, stderr);
else
result = puts("Socket fechado!");
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax

if ( close(sock) == -1 )
result = fwrite("Erro ao tentar fechar socket!\n", 1uLL, 0x1EuLL, stderr);
else
result = puts("Socket fechado!");
return result;
}

original_code:
void finaliza_rede()
{
 if(close(sock) == -1)
  fprintf(stderr, "Erro ao tentar fechar socket!\n");
 else
  printf("Socket fechado!\n");
}


mean

repo: lucasb-eyer/OmicABEL

decompiled_code:
double __fastcall mean(double *a1, int a2)
{
double *v2; // rax
double v3; // xmm0_8

if ( a2 <= 0 )
_assert_fail("n > 0", "src/statistics.c", 0x22u, "mean");
v2 = a1;
v3 = 0.0;
do
v3 = v3 + *v2++;
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
return v3 / (double)a2;
}

canonical_decompiled_code:
double __fastcall func0(double *a1, int a2)
{
double *v2; // rax
double v3; // xmm0_8

if ( a2 <= 0 )
_assert_fail("n > 0", "src/statistics.c", 0x22u, "mean");
v2 = a1;
v3 = 0.0;
do
v3 = v3 + *v2++;
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
return v3 / (double)a2;
}

original_code:
double mean( double *v, int n )
{
 int i;
 double mean = 0.0;
 ((void) sizeof ((n > 0) ? 1 : 0), __extension__ ({ if (n > 0) ; else __assert_fail ("n > 0", "src/statistics.c", 34, __extension__ __PRETTY_FUNCTION__); }));
 for ( i = 0; i < n; i++ )
  mean += v[i];
 mean /= n;
 return mean;
}

canonical_original_code:
double mean(double *v, int n)
{
 int i;
 double mean = 0.0;
 ((void) sizeof ((n > 0) ? 1 : 0), __extension__ ({ if (n > 0) ; else __assert_fail ("n > 0", "src/statistics.c", 34, __extension__ __PRETTY_FUNCTION__); }));
 for ( i = 0; i < n; i++ )
  mean += v[i];
 mean /= n;
 return mean;
}

variable_types:
v
double *

variable_types: n int

variable_types: i int

variable_types: mean double

return_type: double