parse

decompiled_code:
__int64 parse()
{
_BYTE *v0; // rax
_BYTE *v1; // rbx
__int64 result; // rax
unsigned int v3; // ebp
__int64 v4[5]; // [rsp+0h] [rbp-48h] BYREF
int v5[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

v0 = filebuf;
if ( filebuflen )
{
do
{
if ( *v0 == 10 )
*v0 = 0;
++v0;
v1 = filebuf;
}
while ( v0 - (_BYTE *)filebuf < (unsigned int)filebuflen );
}
else
{
v1 = filebuf;
}
v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v5[0] = 0;
result = (unsigned int)filebuflen;
if ( v1 - (_BYTE *)filebuf < (unsigned int)filebuflen )
{
v3 = 1;
do
{
parseline(v1, v5, (__int64)v4, v3++);
for ( ; *v1; ++v1 )
;
++v1;
result = (unsigned int)filebuflen;
}
while ( v1 - (_BYTE *)filebuf < (unsigned int)filebuflen );
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
_BYTE *v0; // rax
_BYTE *v1; // rbx
__int64 result; // rax
unsigned int v3; // ebp
__int64 v4[5]; // [rsp+0h] [rbp-48h] BYREF
int v5[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

v0 = filebuf;
if ( filebuflen )
{
do
{
if ( *v0 == 10 )
*v0 = 0;
++v0;
v1 = filebuf;
}
while ( v0 - (_BYTE *)filebuf < (unsigned int)filebuflen );
}
else
{
v1 = filebuf;
}
v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v5[0] = 0;
result = (unsigned int)filebuflen;
if ( v1 - (_BYTE *)filebuf < (unsigned int)filebuflen )
{
v3 = 1;
do
{
func3(v1, v5, (__int64)v4, v3++);
for ( ; *v1; ++v1 )
;
++v1;
result = (unsigned int)filebuflen;
}
while ( v1 - (_BYTE *)filebuf < (unsigned int)filebuflen );
}
return result;
}

original_code:
void
parse(void) {
 char *p;
 unsigned int line, mode;
 struct target t;
 for(p=filebuf; p-filebuf<filebuflen; p++)
  if(*p=='\n')
   *p=0;
 memset(&t, 0, sizeof(struct target));
 for(p=filebuf, line=1, mode=0; p-filebuf<filebuflen; p++) {
  parseline(p, &mode, &t, line);
  line++;
  while(*p)
   p++;
 }
}

canonical_original_code:
void parse() {
 char *p;
 unsigned int line; unsigned int mode;
 struct target t;
 for(p=filebuf; p-filebuf<filebuflen; p++)
  if(*p=='\n')
   *p=0;
 memset(&t, 0, sizeof(struct target));
 for(p=filebuf, line=1, mode=0; p-filebuf<filebuflen; p++) {
  parseline(p, &mode, &t, line);
  line++;
  while(*p)
   p++;
 }
}

variable_types:
p
char *

variable_types:
mode
unsigned int

variable_types: struct target { int isliteral; char *name; char **deps; char **cmds; }


maketarget

repo: JuEeHa/minimake

decompiled_code:
__int64 __fastcall maketarget(char *s2)
{
__int64 v1; // rbx
__int64 v2; // rax
const char **v3; // rbx
const char *i; // rdi

if ( access(s2, 0) )
{
v1 = targetlist;
if ( targetlist )
{
while ( strcmp(*(const char **)(*(_QWORD *)v1 + 8LL), s2) )
v1 += 8LL;
v2 = *(_QWORD *)v1;
}
else
{
v2 = *(_QWORD *)xmalloc;
if ( !*(_QWORD *)xmalloc )
{
fprintf(stderr, "make: *** cannot make '%s'\n", s2);
exit(1);
}
}
v3 = *(const char ***)(v2 + 24);
for ( i = *v3; *v3; i = *v3 )
{
if ( *i == 64 )
{
system(i + 1);
}
else
{
puts(i);
system(*v3);
}
++v3;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2)
{
__int64 v1; // rbx
__int64 v2; // rax
const char **v3; // rbx
const char *i; // rdi

if ( access(s2, 0) )
{
v1 = targetlist;
if ( targetlist )
{
while ( strcmp(*(const char **)(*(_QWORD *)v1 + 8LL), s2) )
v1 += 8LL;
v2 = *(_QWORD *)v1;
}
else
{
v2 = *(_QWORD *)xmalloc;
if ( !*(_QWORD *)xmalloc )
{
fprintf(stderr, "make: *** cannot make '%s'\n", s2);
exit(1);
}
}
v3 = *(const char ***)(v2 + 24);
for ( i = *v3; *v3; i = *v3 )
{
if ( *i == 64 )
{
system(i + 1);
}
else
{
puts(i);
system(*v3);
}
++v3;
}
}
return 0LL;
}

original_code:
int
maketarget(char *targetname) {
 struct target **target;
 char **pp;
 if(!access(targetname, 0))
  return 0;
 for(target=targetlist; target && strcmp((**target).name, targetname); target++);
 if(!*target) {
   fprintf(stderr, "make: *** cannot make '%s'\n", targetname);
   exit(1);
 }
 for(pp=(**target).cmds; *pp; pp++) {
  if(**pp=='@') {
   system(*pp+1);
  } else {
   puts(*pp);
   system(*pp);
  }
 }
 return 0;
}

variable_types:
targetname
char *

variable_types: struct target { int isliteral; char *name; char **deps; char **cmds; } **

variable_types:
pp
char **

return_type: int


main

canonical_name: main

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

if ( (unsigned int)readtobuf(0) )
return -1;
v3 = 0;
parse(0LL, argv);
if ( targetlist && *(_QWORD *)targetlist )
maketarget(*(char **)(*(_QWORD *)targetlist + 8LL));
return v3;
}

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

if ( (unsigned int)func2(0) )
return -1;
v3 = 0;
func4(0LL, argv);
if ( targetlist && *(_QWORD *)targetlist )
func5(*(char **)(*(_QWORD *)targetlist + 8LL));
return v3;
}

original_code:
int
main(int argc, char **argv) {
 int fd;
 fd=0;
 if(readtobuf(fd))
  return -1;
 parse();
 if(targetlist && *targetlist)
  maketarget((**targetlist).name);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: fd int


nuevoBuffer

repo: Juancamacho/xquetzal

original_code:
Buffer nuevoBuffer(int tamano){
  Buffer buffer;
  buffer.datos = (char *)malloc(5*sizeof(char)*tamano+1);
  buffer.tamano = tamano;
  buffer.indice = 0;
  buffer.actual = 0;
  return buffer;
}

canonical_original_code:
struct _buffer nuevoBuffer(int tamano){
  struct _buffer buffer;
  buffer.datos = (char *)malloc(5*sizeof(char)*tamano+1);
  buffer.tamano = tamano;
  buffer.indice = 0;
  buffer.actual = 0;
  return buffer;
}

variable_types: tamano int

variable_types: struct _buffer { char *datos; int tamano; int indice; int actual; }


bufferLleno

decompiled_code:
_BOOL8 __fastcall bufferLleno(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9)
{
return a9 == a8;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9)
{
return a9 == a8;
}

original_code:
int bufferLleno(Buffer buffer){
  if (buffer.actual == buffer.tamano) return 1;
  else
    return 0;
}

canonical_original_code:
int bufferLleno(struct _buffer buffer){
  if (buffer.actual == buffer.tamano) return 1;
  else
    return 0;
}

user_defined_types: struct _buffer { char *datos; int tamano; int indice; int actual; }


agregarABuffer

original_code:
int agregarABuffer(Buffer *buffer, int modo, int tipo,int dato, int hora){
  int mask;
  if (bufferLleno(*buffer)) return 0;
  else{
    buffer->actual++;
    switch(modo){
    case 0:
      mask = 0x0F00;
      buffer->datos[buffer->indice] = (char)((dato & mask) >> 8);
      mask = 0x0FF;
      buffer->indice++;
      buffer->datos[buffer->indice] = (char)(dato & mask);
      buffer->indice++;
      return 1;
    case 1:
      mask = 0x3F00;
      buffer->datos[buffer->indice] = (char)(((dato & mask) >> 8) | 0x40);
      buffer->indice++;
      mask = 0x0FF;
      buffer->datos[buffer->indice] = (char)(dato & mask);
      buffer->indice++;
      return 1;
    case 2:
      buffer->datos[buffer->indice] = (char)((0x02 << 6) | ((tipo & 0x01F) << 1) | ((dato & 0x8000) >> 15)) ;
      buffer->indice++;
      buffer->datos[buffer->indice] = (char)((dato & 0x7F80) >> 7);
      buffer->indice++;
      buffer->datos[buffer->indice] = (char)(((dato & 0x7F) << 1) | ((hora & 0x10000) >> 16));
      buffer->indice++;
      buffer->datos[buffer->indice] = (char)((hora & 0x0FF00) >> 8);
      buffer->indice++;
      buffer->datos[buffer->indice] = (char)(hora & 0x0FF);
      buffer->indice++;
      return 1;
    }
  }
}

canonical_original_code:
int agregarABuffer(struct _buffer *buffer, int modo, int tipo, int dato, int hora){
  int mask;
  if (bufferLleno(*buffer)) return 0;
  else{
    buffer->actual++;
    switch(modo){
    case 0:
      mask = 0x0F00;
      buffer->datos[buffer->indice] = (char)((dato & mask) >> 8);
      mask = 0x0FF;
      buffer->indice++;
      buffer->datos[buffer->indice] = (char)(dato & mask);
      buffer->indice++;
      return 1;
    case 1:
      mask = 0x3F00;
      buffer->datos[buffer->indice] = (char)(((dato & mask) >> 8) | 0x40);
      buffer->indice++;
      mask = 0x0FF;
      buffer->datos[buffer->indice] = (char)(dato & mask);
      buffer->indice++;
      return 1;
    case 2:
      buffer->datos[buffer->indice] = (char)((0x02 << 6) | ((tipo & 0x01F) << 1) | ((dato & 0x8000) >> 15)) ;
      buffer->indice++;
      buffer->datos[buffer->indice] = (char)((dato & 0x7F80) >> 7);
      buffer->indice++;
      buffer->datos[buffer->indice] = (char)(((dato & 0x7F) << 1) | ((hora & 0x10000) >> 16));
      buffer->indice++;
      buffer->datos[buffer->indice] = (char)((hora & 0x0FF00) >> 8);
      buffer->indice++;
      buffer->datos[buffer->indice] = (char)(hora & 0x0FF);
      buffer->indice++;
      return 1;
    }
  }
}

variable_types: struct _buffer { char *datos; int tamano; int indice; int actual; } *

variable_types: modo int

variable_types: tipo int

variable_types: dato int

variable_types: hora int

variable_types: mask int


vaciarBuffer

decompiled_code:
void __fastcall vaciarBuffer(__int64 a1)
{
*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 16) = 0;
}

original_code:
void vaciarBuffer(Buffer *buffer){
  buffer->indice = 0;
  buffer->actual = 0;
}

canonical_original_code:
void vaciarBuffer(struct _buffer *buffer){
  buffer->indice = 0;
  buffer->actual = 0;
}

return_type: void


borrarBuffer

original_code:
void borrarBuffer(Buffer *buffer){
  free(buffer->datos);
  buffer->indice = 0;
  buffer->tamano = 0;
  buffer->actual = 0;
}

canonical_original_code:
void borrarBuffer(struct _buffer *buffer){
  free(buffer->datos);
  buffer->indice = 0;
  buffer->tamano = 0;
  buffer->actual = 0;
}


agregarChars

original_code:
int agregarChars(Buffer *buffer, int modo, char *datos){
  if (bufferLleno(*buffer)) return 0;
  else{
    buffer->actual++;
    if (modo == 0){
      buffer->datos[buffer->indice] = datos[0];
      buffer->indice++;
      buffer->datos[buffer->indice] = datos[1];
      buffer->indice++;
      return 1;
    } else {
      buffer->datos[buffer->indice] = datos[0];
      buffer->indice++;
      buffer->datos[buffer->indice] = datos[1];
      buffer->indice++;
      buffer->datos[buffer->indice] = datos[2];
      buffer->indice++;
      buffer->datos[buffer->indice] = datos[3];
      buffer->indice++;
      buffer->datos[buffer->indice] = datos[4];
      buffer->indice++;
      return 1;
    }
  }
  return 1;
}

canonical_original_code:
int agregarChars(struct _buffer *buffer, int modo, char *datos){
  if (bufferLleno(*buffer)) return 0;
  else{
    buffer->actual++;
    if (modo == 0){
      buffer->datos[buffer->indice] = datos[0];
      buffer->indice++;
      buffer->datos[buffer->indice] = datos[1];
      buffer->indice++;
      return 1;
    } else {
      buffer->datos[buffer->indice] = datos[0];
      buffer->indice++;
      buffer->datos[buffer->indice] = datos[1];
      buffer->indice++;
      buffer->datos[buffer->indice] = datos[2];
      buffer->indice++;
      buffer->datos[buffer->indice] = datos[3];
      buffer->indice++;
      buffer->datos[buffer->indice] = datos[4];
      buffer->indice++;
      return 1;
    }
  }
  return 1;
}

variable_types:
datos
char *


convierteHora

decompiled_code:
__int64 __fastcall convierteHora(int a1, __int16 a2, __int16 a3, char a4)
{
return (unsigned __int16)(a2 << 12) | a4 & 0x3F | (a3 << 6) & 0xFC0 | (a1 << 16) & 0x10000u;
}

original_code:
int convierteHora(int ampm, int hora, int min, int seg){
  int tiempo = 0;
  tiempo = (0x01 & ampm) << 16;
  tiempo = tiempo | (0x0F & hora) << 12;
  tiempo = tiempo | (0x3F & min) << 6;
  tiempo = tiempo | (0x3F & seg);
  return tiempo;
}

variable_types: ampm int

variable_types: min int

variable_types: seg int

variable_types: tiempo int


min

repo: JuantAldea/MandelbrotSet-MPI

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

original_code:
int min(int a, int b)
{
    return (a < b) ? a : b;
}

variable_types: a int

variable_types: b int


max

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

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

original_code:
int max(int a, int b)
{
    return (a < b) ? b : a;
}


decompiled_code:
__int64 __fastcall next_task(_DWORD *a1, _DWORD *a2, int *a3)
{
int v4; // eax
__int64 result; // rax

v4 = *a1 + a1[1];
*a3 = v4;
result = min(*a2 - v4, a1[1]);
a3[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _DWORD *a2, int *a3)
{
int v4; // eax
__int64 result; // rax

v4 = *a1 + a1[1];
*a3 = v4;
result = func0(*a2 - v4, a1[1]);
a3[1] = result;
return result;
}

original_code:
void next_task(task current, task last, task next)
{
    next[0] = current[0] + current[1];
    next[1] = min(last[0] - next[0], current[1]);
}

canonical_original_code:
void next_task(int current[2], int last[2], int next[2])
{
    next[0] = current[0] + current[1];
    next[1] = min(last[0] - next[0], current[1]);
}

variable_types:
current
int [2]

variable_types:
last
int [2]

variable_types:
next
int [2]


decompiled_code:
__int64 __fastcall first_assignment(__int64 *a1, _DWORD *a2, int *a3, int a4)
{
__int64 result; // rax
int *v7; // rbx
__int64 v8; // r12
int *v9; // rdi

result = (__int64)memset(a3, 0, 8LL * a4);
if ( a4 )
{
result = *a1;
*((_QWORD *)a3 + 1) = *a1;
if ( a4 > 2 )
{
v7 = a3 + 2;
v8 = (__int64)&a3[2 * (a4 - 3) + 4];
do
{
v9 = v7;
v7 += 2;
result = next_task(v9, a2, v7);
}
while ( v7 != (int *)v8 );
}
}
return result;
}

original_code:
void first_assignment(task current, task last, task assignment[], int n)
{
    memset(assignment, 0, sizeof(task) * n);
    if (n == 0) {
        return;
    }
    memcpy(&assignment[1], current, sizeof(task));
    for (int i = 2; i < n; i++) {
        next_task(assignment[i - 1], last, assignment[i]);
    }
}

canonical_original_code:
void first_assignment(int current[2], int last[2], int assignment[][2], int n)
{
    memset(assignment, 0, sizeof(task) * n);
    if (n == 0) {
        return;
    }
    memcpy(&assignment[1], current, sizeof(task));
    for (int i = 2; i < n; i++) {
        next_task(assignment[i - 1], last, assignment[i]);
    }
}

variable_types:
assignment
int [][2]

variable_types: n int

variable_types: i int


decompiled_code:
__int64 __fastcall set_task(__int64 a1, int a2, __int64 *a3)
{
__int64 result; // rax

result = *a3;
*(_QWORD *)(a1 + 8LL * a2) = *a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, __int64 *a3)
{
__int64 result; // rax

result = *a3;
*(_QWORD *)(a1 + 8LL * a2) = *a3;
return result;
}

original_code:
void set_task(task current_task_assignment[], int rank, task t)
{
    memcpy(&current_task_assignment[rank], t, sizeof(task));
}

canonical_original_code:
void set_task(int current_task_assignment[][2], int rank, int t[2])
{
    memcpy(&current_task_assignment[rank], t, sizeof(task));
}

variable_types: rank int

variable_types:
t
int [2]


decompiled_code:
int __fastcall print_task(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
{
printf("[%d, %d]", *v2, v2[1]);
v2 += 2;
}
while ( v2 != &a1[2 * (a2 - 1) + 2] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
{
printf("[%d, %d]", *v2, v2[1]);
v2 += 2;
}
while ( v2 != &a1[2 * (a2 - 1) + 2] );
}
return putchar(10);
}

original_code:
void print_task(task current_task_assignment[], int com_size)
{
    for (int i = 0; i < com_size; i++) {
        printf("[%d, %d]", current_task_assignment[i][0],
               current_task_assignment[i][1]);
    }
    printf("\n");
}

canonical_original_code:
void print_task(int current_task_assignment[][2], int com_size)
{
    for (int i = 0; i < com_size; i++) {
        printf("[%d, %d]", current_task_assignment[i][0],
               current_task_assignment[i][1]);
    }
    printf("\n");
}


decompiled_code:
_BOOL8 __fastcall is_last_task(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

original_code:
int is_last_task(task t)
{
    return t[1] == 0;
}

canonical_original_code:
int is_last_task(int t[2])
{
    return t[1] == 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
yyin = abrir_entrada(argc, (__int64)argv);
return yyparse();
}

original_code:
int main( int argc, char *argv[] )
{
  yyin= abrir_entrada(argc,argv) ;
  return yyparse() ;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  yyin= abrir_entrada(argc,argv) ;
  return yyparse() ;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: Jubei-Mitsuyoshi/aaa-xarchiver

decompiled_code:
int __fastcall alias_entry_cmp(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int
alias_entry_cmp (const void *v1, const void *v2)
{
  return strcmp (((XdgAlias *)v1)->alias, ((XdgAlias *)v2)->alias);
}

canonical_original_code:
static int alias_entry_cmp(void *v1, void *v2)
{
  return strcmp (((struct XdgAlias *)v1)->alias, ((struct XdgAlias *)v2)->alias);
}

user_defined_types: struct XdgAlias { char *alias; char *mime_type; }


decompiled_code:
int __fastcall parent_entry_cmp(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int
parent_entry_cmp (const void *v1, const void *v2)
{
  return strcmp (((XdgMimeParents *)v1)->mime, ((XdgMimeParents *)v2)->mime);
}

canonical_original_code:
static int parent_entry_cmp(void *v1, void *v2)
{
  return strcmp (((struct XdgMimeParents *)v1)->mime, ((struct XdgMimeParents *)v2)->mime);
}

user_defined_types: struct XdgMimeParents { char *mime; char **parents; int n_parents; }


crc

repo: JuhaniImberg/saarni

original_code:
long crc(unsigned char *octets, size_t len) {
 long crc = 0xb704ceL;
 int i;
 while (len--) {
  crc ^= (*octets++) << 16;
  for (i = 0; i < 8; i++) {
   crc <<= 1;
   if (crc & 0x1000000)
    crc ^= 0x1864cfbL;
  }
 }
 return crc & 0xffffffL;
}

canonical_original_code:
long crc(unsigned char *octets, unsigned long len) {
 long crc = 0xb704ceL;
 int i;
 while (len--) {
  crc ^= (*octets++) << 16;
  for (i = 0; i < 8; i++) {
   crc <<= 1;
   if (crc & 0x1000000)
    crc ^= 0x1864cfbL;
  }
 }
 return crc & 0xffffffL;
}

variable_types:
octets
unsigned char *

variable_types:
len
unsigned long

variable_types: crc long

return_type: long


decompiled_code:
__int64 __fastcall set_c(_BYTE *a1, int a2, int a3)
{
__int64 result; // rax

if ( a2 )
{
*a1 = -18;
a1[1] = -18;
a1[2] = -18;
}
else
{
*(_WORD *)a1 = a3;
result = BYTE2(a3);
a1[2] = BYTE2(a3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1, int a2, int a3)
{
__int64 result; // rax

if ( a2 )
{
*a1 = -18;
a1[1] = -18;
a1[2] = -18;
}
else
{
*(_WORD *)a1 = a3;
result = BYTE2(a3);
a1[2] = BYTE2(a3);
}
return result;
}

original_code:
void set_c(png_byte *ptr, int on, color C) {
 static color def;
 def.r = 238;
 def.g = 238;
 def.b = 238;
 if(!on) {
  ptr[0] = C.r;
  ptr[1] = C.g;
  ptr[2] = C.b;
 }else{
  ptr[0] = def.r;
  ptr[1] = def.g;
  ptr[2] = def.b;
 }
}

canonical_original_code:
void set_c(unsigned char *ptr, int on, struct color C) {
 static struct color def;
 def.r = 238;
 def.g = 238;
 def.b = 238;
 if(!on) {
  ptr[0] = C.r;
  ptr[1] = C.g;
  ptr[2] = C.b;
 }else{
  ptr[0] = def.r;
  ptr[1] = def.g;
  ptr[2] = def.b;
 }
}

variable_types:
ptr
unsigned char *

variable_types: on int

variable_types: struct color { unsigned char r; unsigned char g; unsigned char b; }


decompiled_code:
__int64 __fastcall set_s(__int64 a1, int a2, int a3)
{
_BYTE *v3; // rbp
_BYTE *v4; // rbx
__int64 result; // rax

v3 = (_BYTE *)(a1 + 48);
do
{
v4 = v3 - 48;
do
{
result = set_c(v4, a2, (unsigned __int16)a3 | (BYTE2(a3) << 16));
v4 += 3;
}
while ( v4 != v3 );
v3 += 384;
}
while ( v3 != (_BYTE *)(a1 + 6192) );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3)
{
_BYTE *v3; // rbp
_BYTE *v4; // rbx
__int64 result; // rax

v3 = (_BYTE *)(a1 + 48);
do
{
v4 = v3 - 48;
do
{
result = func8(v4, a2, (unsigned __int16)a3 | (BYTE2(a3) << 16));
v4 += 3;
}
while ( v4 != v3 );
v3 += 384;
}
while ( v3 != (_BYTE *)(a1 + 6192) );
return result;
}

original_code:
void set_s(png_byte *ptr, int on, color C) {
 int x, y;
  for(y = 0; y < 16; y++) {
  for(x = 0; x < 16; x++) {
   set_c(&ptr[(x+y*8*16)*3], on, C);
  }
 }
}

canonical_original_code:
void set_s(unsigned char *ptr, int on, struct color C) {
 int x; int y;
  for(y = 0; y < 16; y++) {
  for(x = 0; x < 16; x++) {
   set_c(&ptr[(x+y*8*16)*3], on, C);
  }
 }
}

variable_types: x int

variable_types: y int

user_defined_types: struct color { unsigned char r; unsigned char g; unsigned char b; }


decompiled_code:
__int64 __fastcall hex_to_char(int a1)
{
__int64 result; // rax
unsigned __int8 v2; // al
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 65) <= 5u )
{
result = (unsigned int)(a1 - 55);
}
else
{
v2 = a1 - 97;
v3 = a1 - 87;
v4 = v2 < 6u;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
__int64 result; // rax
unsigned __int8 v2; // al
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 65) <= 5u )
{
result = (unsigned int)(a1 - 55);
}
else
{
v2 = a1 - 97;
v3 = a1 - 87;
v4 = v2 < 6u;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
}
}
return result;
}

original_code:
char hex_to_char(unsigned char c)
{
  if (c >= '0' && c <= '9') return c - '0';
  if (c >= 'A' && c <= 'F') return 10 + c - 'A';
  if (c >= 'a' && c <= 'f') return 10 + c - 'a';
  return -1;
}

variable_types:
c
unsigned char

return_type: char


decompiled_code:
__int64 __fastcall create_antihex(__int64 a1, __int64 a2)
{
__int64 i; // rbx
int v3; // er13
__int64 result; // rax

for ( i = 0LL; i != 16; ++i )
{
v3 = hex_to_char(*(unsigned __int8 *)(a2 + 2 * i));
result = v3 | (16 * (unsigned int)hex_to_char(*(unsigned __int8 *)(a2 + 2 * i + 1)));
*(_BYTE *)(a1 + i) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
__int64 i; // rbx
int v3; // er13
__int64 result; // rax

for ( i = 0LL; i != 16; ++i )
{
v3 = func12(*(unsigned __int8 *)(a2 + 2 * i));
result = v3 | (16 * (unsigned int)func12(*(unsigned __int8 *)(a2 + 2 * i + 1)));
*(_BYTE *)(a1 + i) = result;
}
return result;
}

original_code:
void create_antihex(char* buffer, const char* hex) {
 int i;
 for(i = 0; i < 16; i++) {
  buffer[i] = hex_to_char(hex[i*2]) | (hex_to_char(hex[i*2+1])<<4);
 }
}

canonical_original_code:
void create_antihex(char *buffer, char *hex) {
 int i;
 for(i = 0; i < 16; i++) {
  buffer[i] = hex_to_char(hex[i*2]) | (hex_to_char(hex[i*2+1])<<4);
 }
}

variable_types:
buffer
char *

variable_types:
hex
char *


help

decompiled_code:
int help()
{
return puts("usage: saarni [-h] [-s hex_string]\n [-n number_of_random]");
}

canonical_decompiled_code:
int func14()
{
return puts("usage: saarni [-h] [-s hex_string]\n [-n number_of_random]");
}

original_code:
void help() {
 printf("usage: saarni [-h] [-s hex_string]\n"
     "              [-n number_of_random]\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v4; // rax
char v6; // al
const char *v7; // rsi
int v8; // ebp
int i; // ebx
char src; // [rsp+Fh] [rbp-69h] BYREF
char dest[48]; // [rsp+10h] [rbp-68h] BYREF
char v12[56]; // [rsp+40h] [rbp-38h] BYREF

v12[0] = 0;
dest[0] = 0;
v3 = time(0LL);
srand(v3);
mkdir("png", 0x1FDu);
if ( argc <= 1 )
goto LABEL_3;
v4 = argv[1];
if ( *v4 != 45 )
goto LABEL_3;
v6 = v4[1];
if ( v6 == 110 )
{
if ( argc == 3 )
{
v8 = atoi(argv[2]);
for ( i = 0; i < v8; ++i )
{
v12[0] = 0;
create_hash(v12);
create_png(v12);
}
}
else
{
puts("Missing number as argument 2");
}
}
else
{
if ( v6 != 115 )
{
LABEL_3:
help();
return 0;
}
if ( argc == 3 )
{
v7 = argv[2];
if ( *v7 == 45 )
{
while ( 1 )
{
src = getchar();
if ( src == -1 )
break;
strcat(dest, &src);
}
dest[32] = 0;
create_antihex((__int64)v12, (__int64)dest);
create_png(v12);
}
else
{
create_antihex((__int64)v12, (__int64)v7);
create_png(v12);
}
}
else
{
puts("Missing string or - as argument 2");
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v4; // rax
char v6; // al
const char *v7; // rsi
int v8; // ebp
int i; // ebx
char src; // [rsp+Fh] [rbp-69h] BYREF
char dest[48]; // [rsp+10h] [rbp-68h] BYREF
char v12[56]; // [rsp+40h] [rbp-38h] BYREF

v12[0] = 0;
dest[0] = 0;
v3 = time(0LL);
srand(v3);
mkdir("png", 0x1FDu);
if ( argc <= 1 )
goto LABEL_3;
v4 = argv[1];
if ( *v4 != 45 )
goto LABEL_3;
v6 = v4[1];
if ( v6 == 110 )
{
if ( argc == 3 )
{
v8 = atoi(argv[2]);
for ( i = 0; i < v8; ++i )
{
v12[0] = 0;
func11(v12);
func10(v12);
}
}
else
{
puts("Missing number as argument 2");
}
}
else
{
if ( v6 != 115 )
{
LABEL_3:
func14();
return 0;
}
if ( argc == 3 )
{
v7 = argv[2];
if ( *v7 == 45 )
{
while ( 1 )
{
src = getchar();
if ( src == -1 )
break;
strcat(dest, &src);
}
dest[32] = 0;
func13((__int64)v12, (__int64)dest);
func10(v12);
}
else
{
func13((__int64)v12, (__int64)v7);
func10(v12);
}
}
else
{
puts("Missing string or - as argument 2");
}
}
return 0;
}

original_code:
int main(int argc, const char* argv[]) {
 char buffer[17];
 char stdin_buffer[33];
 char c;
 int num_of_rand, i;
 buffer[0] = 0;
 stdin_buffer[0] = 0;
 srand (time(((void *)0)));
 mkdir("png", (0400|0200|0100) | ((0400|0200|0100) >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3));
 if(argc>1 && argv[1][0] == '-') {
  switch(argv[1][1]) {
   case 's':
    if(argc==3) {
     if(argv[2][0]== '-') {
      while((c=getchar())!= (-1)) {
       strcat(stdin_buffer, &c);
      }
      stdin_buffer[32] = 0;
      create_antihex(buffer, stdin_buffer);
      create_png(buffer);
     }else{
      create_antihex(buffer, argv[2]);
      create_png(buffer);
     }
     return 0;
    }
    printf("Missing string or - as argument 2\n");
    return 0;
   case 'n':
    if(argc==3) {
     num_of_rand = atoi(argv[2]);
     for(i = 0; i < num_of_rand; i++) {
      buffer[0] = 0;
      create_hash(buffer);
      create_png(buffer);
     }
     return 0;
    }
    printf("Missing number as argument 2\n");
    return 0;
  }
 }
 help();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 char buffer[17];
 char stdin_buffer[33];
 char c;
 int num_of_rand; int i;
 buffer[0] = 0;
 stdin_buffer[0] = 0;
 srand (time(((void *)0)));
 mkdir("png", (0400|0200|0100) | ((0400|0200|0100) >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3));
 if(argc>1 && argv[1][0] == '-') {
  switch(argv[1][1]) {
   case 's':
    if(argc==3) {
     if(argv[2][0]== '-') {
      while((c=getchar())!= (-1)) {
       strcat(stdin_buffer, &c);
      }
      stdin_buffer[32] = 0;
      create_antihex(buffer, stdin_buffer);
      create_png(buffer);
     }else{
      create_antihex(buffer, argv[2]);
      create_png(buffer);
     }
     return 0;
    }
    printf("Missing string or - as argument 2\n");
    return 0;
   case 'n':
    if(argc==3) {
     num_of_rand = atoi(argv[2]);
     for(i = 0; i < num_of_rand; i++) {
      buffer[0] = 0;
      create_hash(buffer);
      create_png(buffer);
     }
     return 0;
    }
    printf("Missing number as argument 2\n");
    return 0;
  }
 }
 help();
 return 0;
}

variable_types:
buffer
char [17]

variable_types: c char


decompiled_code:
unsigned __int64 __fastcall mu_mean(_QWORD *a1, unsigned __int64 a2)
{
_QWORD *v2; // rdx
unsigned __int64 v3; // rax

if ( a2 )
{
v2 = a1;
v3 = 0LL;
do
v3 += *v2++;
while ( v2 != &a1[a2] );
}
else
{
v3 = 0LL;
}
return v3 / a2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(_QWORD *a1, unsigned __int64 a2)
{
_QWORD *v2; // rdx
unsigned __int64 v3; // rax

if ( a2 )
{
v2 = a1;
v3 = 0LL;
do
v3 += *v2++;
while ( v2 != &a1[a2] );
}
else
{
v3 = 0LL;
}
return v3 / a2;
}

original_code:
uint64_t mu_mean(int64_t* data,
                 size_t count)
{
    size_t i;
    int64_t sum = 0;
    for( i = 0; i < count ; ++i )
    {
        sum = sum + data[i];
    }
    return sum/count;
}

canonical_original_code:
unsigned long mu_mean(long *data, unsigned long count)
{
    unsigned long i;
    long sum = 0;
    for( i = 0; i < count ; ++i )
    {
        sum = sum + data[i];
    }
    return sum/count;
}

variable_types:
data
long *

variable_types:
count
unsigned long

variable_types:
i
unsigned long

variable_types: sum long

return_type: unsigned long


decompiled_code:
unsigned __int64 __fastcall mu_deviation(_QWORD *a1, unsigned __int64 a2)
{
unsigned __int64 v3; // rax
unsigned __int64 v4; // rsi
_QWORD *v5; // rcx
_QWORD *v6; // rdi
unsigned __int64 v7; // rax
__int64 v8; // rax
double v9; // xmm0_8
double v10; // xmm0_8
unsigned __int64 result; // rax

v3 = mu_mean(a1, a2);
if ( a2 )
{
v4 = v3;
v5 = a1;
v6 = &a1[a2];
v7 = 0LL;
do
{
v7 += (*v5 - v4) * (*v5 - v4);
++v5;
}
while ( v5 != v6 );
}
else
{
v7 = 0LL;
}
v8 = v7 / a2;
if ( v8 < 0 )
v9 = (double)(int)(v8 & 1 | ((unsigned __int64)v8 >> 1)) + (double)(int)(v8 & 1 | ((unsigned __int64)v8 >> 1));
else
v9 = (double)(int)v8;
if ( v9 < 0.0 )
v10 = sqrt(v9);
else
v10 = sqrt(v9);
if ( v10 >= 9.223372036854776e18 )
result = (unsigned int)(int)(v10 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
result = (unsigned int)(int)v10;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(_QWORD *a1, unsigned __int64 a2)
{
unsigned __int64 v3; // rax
unsigned __int64 v4; // rsi
_QWORD *v5; // rcx
_QWORD *v6; // rdi
unsigned __int64 v7; // rax
__int64 v8; // rax
double v9; // xmm0_8
double v10; // xmm0_8
unsigned __int64 result; // rax

v3 = func0(a1, a2);
if ( a2 )
{
v4 = v3;
v5 = a1;
v6 = &a1[a2];
v7 = 0LL;
do
{
v7 += (*v5 - v4) * (*v5 - v4);
++v5;
}
while ( v5 != v6 );
}
else
{
v7 = 0LL;
}
v8 = v7 / a2;
if ( v8 < 0 )
v9 = (double)(int)(v8 & 1 | ((unsigned __int64)v8 >> 1)) + (double)(int)(v8 & 1 | ((unsigned __int64)v8 >> 1));
else
v9 = (double)(int)v8;
if ( v9 < 0.0 )
v10 = sqrt(v9);
else
v10 = sqrt(v9);
if ( v10 >= 9.223372036854776e18 )
result = (unsigned int)(int)(v10 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
result = (unsigned int)(int)v10;
return result;
}

original_code:
uint64_t mu_deviation(int64_t* data,
                      size_t count)
{
    size_t i;
    int64_t sqrsum = 0;
    int64_t mean = mu_mean( data, count );
    for( i = 0; i < count ; ++i )
    {
        sqrsum = sqrsum + (data[i] - mean)*(data[i] - mean);
    }
    return sqrt( sqrsum/count );
}

canonical_original_code:
unsigned long mu_deviation(long *data, unsigned long count)
{
    unsigned long i;
    long sqrsum = 0;
    long mean = mu_mean( data, count );
    for( i = 0; i < count ; ++i )
    {
        sqrsum = sqrsum + (data[i] - mean)*(data[i] - mean);
    }
    return sqrt( sqrsum/count );
}

variable_types: sqrsum long

variable_types: mean long


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

result = "Invalid error";
if ( a1 <= 4 )
result = errors[a1];
return result;
}

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

result = "Invalid error";
if ( a1 <= 4 )
result = errors[a1];
return result;
}

original_code:
const char* nmqueue_error_to_string(int err)
{
    if( err<0 || err>4 )
    {
        return invalidError;
    }
    return errors[err];
}

canonical_original_code:
char *nmqueue_error_to_string(int err)
{
    if( err<0 || err>4 )
    {
        return invalidError;
    }
    return errors[err];
}

variable_types: err int

return_type: char *


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

if ( !a1 )
_assert_fail("queue != NULL", "src/nmqueue.c", 0x22u, "nmqueue_abort");
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0x23u, "nmqueue_abort");
v2 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 >= v2 )
_assert_fail("queue->readPosition < queue->length", "src/nmqueue.c", 0x23u, "nmqueue_abort");
if ( v2 <= *(_QWORD *)(a1 + 8) )
_assert_fail("queue->writePosition < queue->length", "src/nmqueue.c", 0x23u, "nmqueue_abort");
pthread_mutex_lock((pthread_mutex_t *)(a1 + 40));
*(_QWORD *)(a1 + 24) = a2;
pthread_cond_broadcast((pthread_cond_t *)(a1 + 80));
pthread_cond_broadcast((pthread_cond_t *)(a1 + 128));
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 40));
}

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

if ( !a1 )
_assert_fail("queue != NULL", "src/nmqueue.c", 0x22u, "nmqueue_abort");
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0x23u, "nmqueue_abort");
v2 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 >= v2 )
_assert_fail("queue->readPosition < queue->length", "src/nmqueue.c", 0x23u, "nmqueue_abort");
if ( v2 <= *(_QWORD *)(a1 + 8) )
_assert_fail("queue->writePosition < queue->length", "src/nmqueue.c", 0x23u, "nmqueue_abort");
pthread_mutex_lock((pthread_mutex_t *)(a1 + 40));
*(_QWORD *)(a1 + 24) = a2;
pthread_cond_broadcast((pthread_cond_t *)(a1 + 80));
pthread_cond_broadcast((pthread_cond_t *)(a1 + 128));
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 40));
}

original_code:
void nmqueue_abort(nmqueue_t* queue,
                   void* threadId)
{
    ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/nmqueue.c", 34, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 35, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 35, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 35, __extension__ __PRETTY_FUNCTION__); }));
    pthread_mutex_lock( &queue->mutex );
    queue->abort = threadId;
    pthread_cond_broadcast( &queue->writtenCond );
    pthread_cond_broadcast( &queue->readCond );
    pthread_mutex_unlock( &queue->mutex );
}

canonical_original_code:
void nmqueue_abort(struct nmqueue_t *queue, void *threadId)
{
    ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/nmqueue.c", 34, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 35, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 35, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 35, __extension__ __PRETTY_FUNCTION__); }));
    pthread_mutex_lock( &queue->mutex );
    queue->abort = threadId;
    pthread_cond_broadcast( &queue->writtenCond );
    pthread_cond_broadcast( &queue->readCond );
    pthread_mutex_unlock( &queue->mutex );
}

variable_types: struct nmqueue_t { unsigned long readPosition; unsigned long writePosition; unsigned long length; void *abort; struct nmqueue_message_s { void *data; unsigned long dataSize; int source; } *queue; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } writtenCond; union pthread_cond_t readCond; } *

variable_types:
threadId
void *

user_defined_types: struct nmqueue_t { unsigned long readPosition; unsigned long writePosition; unsigned long length; void *abort; struct nmqueue_message_s *queue; union pthread_mutex_t mutex; union pthread_cond_t writtenCond; union pthread_cond_t readCond; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall nmqueue_initialize(__int64 a1, __int64 a2)
{
void *v2; // rax
unsigned int v3; // ebp
unsigned __int64 v4; // rax

if ( !a1 )
_assert_fail("queue != NULL", "src/nmqueue.c", 0x34u, "nmqueue_initialize");
if ( !a2 )
_assert_fail("length != 0", "src/nmqueue.c", 0x35u, "nmqueue_initialize");
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 16) = a2;
v2 = malloc(24 * a2);
*(_QWORD *)(a1 + 32) = v2;
*(_QWORD *)(a1 + 24) = 1LL;
if ( !v2 )
return 3;
if ( pthread_mutex_init((pthread_mutex_t *)(a1 + 40), 0LL) )
{
v3 = 1;
goto LABEL_18;
}
if ( pthread_cond_init((pthread_cond_t *)(a1 + 80), 0LL) )
{
LABEL_16:
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 40));
v3 = 2;
LABEL_18:
free(*(void **)(a1 + 32));
return v3;
}
v3 = pthread_cond_init((pthread_cond_t *)(a1 + 128), 0LL);
if ( v3 )
{
pthread_cond_destroy((pthread_cond_t *)(a1 + 80));
goto LABEL_16;
}
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0x4Eu, "nmqueue_initialize");
v4 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 >= v4 )
_assert_fail("queue->readPosition < queue->length", "src/nmqueue.c", 0x4Eu, "nmqueue_initialize");
if ( v4 <= *(_QWORD *)(a1 + 8) )
_assert_fail("queue->writePosition < queue->length", "src/nmqueue.c", 0x4Eu, "nmqueue_initialize");
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
void *v2; // rax
unsigned int v3; // ebp
unsigned __int64 v4; // rax

if ( !a1 )
_assert_fail("queue != NULL", "src/nmqueue.c", 0x34u, "nmqueue_initialize");
if ( !a2 )
_assert_fail("length != 0", "src/nmqueue.c", 0x35u, "nmqueue_initialize");
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 16) = a2;
v2 = malloc(24 * a2);
*(_QWORD *)(a1 + 32) = v2;
*(_QWORD *)(a1 + 24) = 1LL;
if ( !v2 )
return 3;
if ( pthread_mutex_init((pthread_mutex_t *)(a1 + 40), 0LL) )
{
v3 = 1;
goto LABEL_18;
}
if ( pthread_cond_init((pthread_cond_t *)(a1 + 80), 0LL) )
{
LABEL_16:
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 40));
v3 = 2;
LABEL_18:
free(*(void **)(a1 + 32));
return v3;
}
v3 = pthread_cond_init((pthread_cond_t *)(a1 + 128), 0LL);
if ( v3 )
{
pthread_cond_destroy((pthread_cond_t *)(a1 + 80));
goto LABEL_16;
}
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0x4Eu, "nmqueue_initialize");
v4 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 >= v4 )
_assert_fail("queue->readPosition < queue->length", "src/nmqueue.c", 0x4Eu, "nmqueue_initialize");
if ( v4 <= *(_QWORD *)(a1 + 8) )
_assert_fail("queue->writePosition < queue->length", "src/nmqueue.c", 0x4Eu, "nmqueue_initialize");
return v3;
}

original_code:
int nmqueue_initialize(nmqueue_t* queue,
                       size_t length)
{
    ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/nmqueue.c", 52, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((length != 0) ? 1 : 0), __extension__ ({ if (length != 0) ; else __assert_fail ("length != 0", "src/nmqueue.c", 53, __extension__ __PRETTY_FUNCTION__); }));
    queue->writePosition = 0;
    queue->readPosition = 0;
    queue->length = length;
    queue->queue = (struct nmqueue_message_s*)malloc( length*sizeof(struct nmqueue_message_s) );
    queue->abort = (void*)(1);
    if( queue->queue == ((void *)0) )
    {
        return 3;
    }
    {
        int error;
        if ( pthread_mutex_init( &queue->mutex, ((void *)0) ) == 0 )
        {
            if ( pthread_cond_init( &queue->writtenCond, ((void *)0) ) == 0 )
            {
                if ( pthread_cond_init( &queue->readCond, ((void *)0) ) == 0 )
                {
                    ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 78, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 78, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 78, __extension__ __PRETTY_FUNCTION__); }));;
                    return 0;
                }
                error = 2;
                pthread_cond_destroy( &queue->writtenCond );
            } else { error = 2; }
            pthread_mutex_destroy( &queue->mutex );
        } else { error = 1; }
        free( queue->queue );
        return error;
    }
}

canonical_original_code:
int nmqueue_initialize(struct nmqueue_t *queue, unsigned long length)
{
    ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/nmqueue.c", 52, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((length != 0) ? 1 : 0), __extension__ ({ if (length != 0) ; else __assert_fail ("length != 0", "src/nmqueue.c", 53, __extension__ __PRETTY_FUNCTION__); }));
    queue->writePosition = 0;
    queue->readPosition = 0;
    queue->length = length;
    queue->queue = (struct nmqueue_message_s *)malloc( length*sizeof(struct nmqueue_message_s) );
    queue->abort = (void *)(1);
    if( queue->queue == ((void *)0) )
    {
        return 3;
    }
    {
        int error;
        if ( pthread_mutex_init( &queue->mutex, ((void *)0) ) == 0 )
        {
            if ( pthread_cond_init( &queue->writtenCond, ((void *)0) ) == 0 )
            {
                if ( pthread_cond_init( &queue->readCond, ((void *)0) ) == 0 )
                {
                    ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 78, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 78, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 78, __extension__ __PRETTY_FUNCTION__); }));;
                    return 0;
                }
                error = 2;
                pthread_cond_destroy( &queue->writtenCond );
            } else { error = 2; }
            pthread_mutex_destroy( &queue->mutex );
        } else { error = 1; }
        free( queue->queue );
        return error;
    }
}

variable_types:
length
unsigned long

variable_types: error int

user_defined_types: struct nmqueue_message_s { void *data; unsigned long dataSize; int source; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
void __fastcall nmqueue_finalize(__int64 a1)
{
unsigned __int64 v1; // rax

if ( !a1 )
_assert_fail("queue != NULL", "src/nmqueue.c", 0x66u, "nmqueue_finalize");
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0x67u, "nmqueue_finalize");
v1 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 >= v1 )
_assert_fail("queue->readPosition < queue->length", "src/nmqueue.c", 0x67u, "nmqueue_finalize");
if ( v1 <= *(_QWORD *)(a1 + 8) )
_assert_fail("queue->writePosition < queue->length", "src/nmqueue.c", 0x67u, "nmqueue_finalize");
pthread_cond_destroy((pthread_cond_t *)(a1 + 80));
pthread_cond_destroy((pthread_cond_t *)(a1 + 128));
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 40));
free(*(void **)(a1 + 32));
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
unsigned __int64 v1; // rax

if ( !a1 )
_assert_fail("queue != NULL", "src/nmqueue.c", 0x66u, "nmqueue_finalize");
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0x67u, "nmqueue_finalize");
v1 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 >= v1 )
_assert_fail("queue->readPosition < queue->length", "src/nmqueue.c", 0x67u, "nmqueue_finalize");
if ( v1 <= *(_QWORD *)(a1 + 8) )
_assert_fail("queue->writePosition < queue->length", "src/nmqueue.c", 0x67u, "nmqueue_finalize");
pthread_cond_destroy((pthread_cond_t *)(a1 + 80));
pthread_cond_destroy((pthread_cond_t *)(a1 + 128));
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 40));
free(*(void **)(a1 + 32));
}

original_code:
void nmqueue_finalize(nmqueue_t* queue)
{
    ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/nmqueue.c", 102, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 103, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 103, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 103, __extension__ __PRETTY_FUNCTION__); }));;
    pthread_cond_destroy( &queue->writtenCond );
    pthread_cond_destroy( &queue->readCond );
    pthread_mutex_destroy( &queue->mutex );
    free( queue->queue );
}

canonical_original_code:
void nmqueue_finalize(struct nmqueue_t *queue)
{
    ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/nmqueue.c", 102, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 103, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 103, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 103, __extension__ __PRETTY_FUNCTION__); }));;
    pthread_cond_destroy( &queue->writtenCond );
    pthread_cond_destroy( &queue->readCond );
    pthread_mutex_destroy( &queue->mutex );
    free( queue->queue );
}


decompiled_code:
__int64 __fastcall nmqueue_send(__int64 a1, int a2, __int64 a3, __int64 a4, const void *a5)
{
unsigned __int64 v7; // rax
pthread_mutex_t *v8; // r12
__int64 v9; // rcx
__int64 result; // rax
__int64 v11; // rax
unsigned __int64 v12; // rcx

if ( !a1 )
_assert_fail("queue != NULL", "src/nmqueue.c", 0x7Du, "nmqueue_send");
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0x7Eu, "nmqueue_send");
v7 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 >= v7 )
_assert_fail("queue->readPosition < queue->length", "src/nmqueue.c", 0x7Eu, "nmqueue_send");
if ( v7 <= *(_QWORD *)(a1 + 8) )
_assert_fail("queue->writePosition < queue->length", "src/nmqueue.c", 0x7Eu, "nmqueue_send");
v8 = (pthread_mutex_t *)(a1 + 40);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 40));
if ( *(const void **)(a1 + 24) == a5 )
{
printf("ABB:%p\n", a5);
*(_QWORD *)(a1 + 24) = 0LL;
pthread_mutex_unlock(v8);
result = 4LL;
}
else
{
while ( 1 )
{
v9 = *(_QWORD *)(a1 + 8);
if ( (unsigned __int64)(v9 + 1) % *(_QWORD *)(a1 + 16) != *(_QWORD *)a1 )
break;
pthread_cond_wait((pthread_cond_t *)(a1 + 128), v8);
if ( *(const void **)(a1 + 24) == a5 )
{
*(_QWORD *)(a1 + 24) = 0LL;
pthread_mutex_unlock(v8);
return 4LL;
}
}
v11 = *(_QWORD *)(a1 + 32) + 24 * v9;
*(_DWORD *)(v11 + 16) = a2;
*(_QWORD *)v11 = a3;
*(_QWORD *)(v11 + 8) = a4;
v12 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 8) = (*(_QWORD *)(a1 + 8) + 1LL) % v12;
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0xA3u, "nmqueue_send");
if ( v12 <= *(_QWORD *)a1 )
_assert_fail("queue->readPosition < queue->length", "src/nmqueue.c", 0xA3u, "nmqueue_send");
pthread_cond_signal((pthread_cond_t *)(a1 + 80));
pthread_mutex_unlock(v8);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, __int64 a3, __int64 a4, const void *a5)
{
unsigned __int64 v7; // rax
pthread_mutex_t *v8; // r12
__int64 v9; // rcx
__int64 result; // rax
__int64 v11; // rax
unsigned __int64 v12; // rcx

if ( !a1 )
_assert_fail("queue != NULL", "src/nmqueue.c", 0x7Du, "nmqueue_send");
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0x7Eu, "nmqueue_send");
v7 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 >= v7 )
_assert_fail("queue->readPosition < queue->length", "src/nmqueue.c", 0x7Eu, "nmqueue_send");
if ( v7 <= *(_QWORD *)(a1 + 8) )
_assert_fail("queue->writePosition < queue->length", "src/nmqueue.c", 0x7Eu, "nmqueue_send");
v8 = (pthread_mutex_t *)(a1 + 40);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 40));
if ( *(const void **)(a1 + 24) == a5 )
{
printf("ABB:%p\n", a5);
*(_QWORD *)(a1 + 24) = 0LL;
pthread_mutex_unlock(v8);
result = 4LL;
}
else
{
while ( 1 )
{
v9 = *(_QWORD *)(a1 + 8);
if ( (unsigned __int64)(v9 + 1) % *(_QWORD *)(a1 + 16) != *(_QWORD *)a1 )
break;
pthread_cond_wait((pthread_cond_t *)(a1 + 128), v8);
if ( *(const void **)(a1 + 24) == a5 )
{
*(_QWORD *)(a1 + 24) = 0LL;
pthread_mutex_unlock(v8);
return 4LL;
}
}
v11 = *(_QWORD *)(a1 + 32) + 24 * v9;
*(_DWORD *)(v11 + 16) = a2;
*(_QWORD *)v11 = a3;
*(_QWORD *)(v11 + 8) = a4;
v12 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 8) = (*(_QWORD *)(a1 + 8) + 1LL) % v12;
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0xA3u, "nmqueue_send");
if ( v12 <= *(_QWORD *)a1 )
_assert_fail("queue->readPosition < queue->length", "src/nmqueue.c", 0xA3u, "nmqueue_send");
pthread_cond_signal((pthread_cond_t *)(a1 + 80));
pthread_mutex_unlock(v8);
result = 0LL;
}
return result;
}

original_code:
int nmqueue_send(nmqueue_t* queue,
                 source_t source,
                 void* data,
                 size_t dataSize,
                 void* threadId)
{
    ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/nmqueue.c", 125, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 126, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 126, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 126, __extension__ __PRETTY_FUNCTION__); }));;
    pthread_mutex_lock( &queue->mutex );
    if( queue->abort == threadId )
    {
        printf("ABB:%p\n",queue->abort);
        queue->abort = ((void *)0);
        pthread_mutex_unlock(&queue->mutex);
        return 4;
    }
    while ((queue->writePosition+1) % queue->length == queue->readPosition)
    {
        pthread_cond_wait(&queue->readCond, &queue->mutex);
        if( queue->abort == threadId )
        {
            queue->abort = ((void *)0);
            pthread_mutex_unlock(&queue->mutex);
            return 4;
        }
    }
    {
        struct nmqueue_message_s* message = &queue->queue[ queue->writePosition ];
        message->source = source;
        message->data = data;
        message->dataSize = dataSize;
    }
    queue->writePosition = (queue->writePosition+1) % queue->length;
    ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 163, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 163, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 163, __extension__ __PRETTY_FUNCTION__); }));;
    pthread_cond_signal(&queue->writtenCond);
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

canonical_original_code:
int nmqueue_send(struct nmqueue_t *queue, int source, void *data, unsigned long dataSize, void *threadId)
{
    ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/nmqueue.c", 125, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 126, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 126, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 126, __extension__ __PRETTY_FUNCTION__); }));;
    pthread_mutex_lock( &queue->mutex );
    if( queue->abort == threadId )
    {
        printf("ABB:%p\n",queue->abort);
        queue->abort = ((void *)0);
        pthread_mutex_unlock(&queue->mutex);
        return 4;
    }
    while ((queue->writePosition+1) % queue->length == queue->readPosition)
    {
        pthread_cond_wait(&queue->readCond, &queue->mutex);
        if( queue->abort == threadId )
        {
            queue->abort = ((void *)0);
            pthread_mutex_unlock(&queue->mutex);
            return 4;
        }
    }
    {
        struct nmqueue_message_s *message = &queue->queue[ queue->writePosition ];
        message->source = source;
        message->data = data;
        message->dataSize = dataSize;
    }
    queue->writePosition = (queue->writePosition+1) % queue->length;
    ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 163, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 163, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 163, __extension__ __PRETTY_FUNCTION__); }));;
    pthread_cond_signal(&queue->writtenCond);
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

variable_types: source int

variable_types:
data
void *

variable_types:
dataSize
unsigned long

variable_types: struct nmqueue_message_s { void *data; unsigned long dataSize; int source; } *


decompiled_code:
__int64 __fastcall nmqueue_receive(__int64 a1, _DWORD *a2, _QWORD *a3, _QWORD *a4, __int64 a5)
{
unsigned __int64 v7; // rax
pthread_mutex_t *v8; // r12
__int64 result; // rax
__int64 v10; // rax
unsigned __int64 v11; // rcx

if ( !a1 )
_assert_fail("queue != NULL", "src/nmqueue.c", 0xB3u, "nmqueue_receive");
if ( !a2 )
_assert_fail("source != NULL", "src/nmqueue.c", 0xB4u, "nmqueue_receive");
if ( !a3 )
_assert_fail("data != NULL", "src/nmqueue.c", 0xB5u, "nmqueue_receive");
if ( !a4 )
_assert_fail("dataSize != NULL", "src/nmqueue.c", 0xB6u, "nmqueue_receive");
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0xB7u, "nmqueue_receive");
v7 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 >= v7 )
_assert_fail("queue->readPosition < queue->length", "src/nmqueue.c", 0xB7u, "nmqueue_receive");
if ( v7 <= *(_QWORD *)(a1 + 8) )
_assert_fail("queue->writePosition < queue->length", "src/nmqueue.c", 0xB7u, "nmqueue_receive");
v8 = (pthread_mutex_t *)(a1 + 40);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 40));
if ( *(_QWORD *)(a1 + 24) == a5 )
{
LABEL_11:
*(_QWORD *)(a1 + 24) = 0LL;
pthread_mutex_unlock(v8);
result = 4LL;
}
else
{
while ( *(_QWORD *)a1 == *(_QWORD *)(a1 + 8) )
{
pthread_cond_wait((pthread_cond_t *)(a1 + 80), v8);
if ( *(_QWORD *)(a1 + 24) == a5 )
goto LABEL_11;
}
v10 = *(_QWORD *)(a1 + 32) + 24LL * *(_QWORD *)a1;
*a2 = *(_DWORD *)(v10 + 16);
*a3 = *(_QWORD *)v10;
*a4 = *(_QWORD *)(v10 + 8);
v11 = *(_QWORD *)(a1 + 16);
*(_QWORD *)a1 = (*(_QWORD *)a1 + 1LL) % v11;
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0xDDu, "nmqueue_receive");
if ( v11 <= *(_QWORD *)(a1 + 8) )
_assert_fail("queue->writePosition < queue->length", "src/nmqueue.c", 0xDDu, "nmqueue_receive");
pthread_cond_signal((pthread_cond_t *)(a1 + 128));
pthread_mutex_unlock(v8);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _DWORD *a2, _QWORD *a3, _QWORD *a4, __int64 a5)
{
unsigned __int64 v7; // rax
pthread_mutex_t *v8; // r12
__int64 result; // rax
__int64 v10; // rax
unsigned __int64 v11; // rcx

if ( !a1 )
_assert_fail("queue != NULL", "src/nmqueue.c", 0xB3u, "nmqueue_receive");
if ( !a2 )
_assert_fail("source != NULL", "src/nmqueue.c", 0xB4u, "nmqueue_receive");
if ( !a3 )
_assert_fail("data != NULL", "src/nmqueue.c", 0xB5u, "nmqueue_receive");
if ( !a4 )
_assert_fail("dataSize != NULL", "src/nmqueue.c", 0xB6u, "nmqueue_receive");
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0xB7u, "nmqueue_receive");
v7 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 >= v7 )
_assert_fail("queue->readPosition < queue->length", "src/nmqueue.c", 0xB7u, "nmqueue_receive");
if ( v7 <= *(_QWORD *)(a1 + 8) )
_assert_fail("queue->writePosition < queue->length", "src/nmqueue.c", 0xB7u, "nmqueue_receive");
v8 = (pthread_mutex_t *)(a1 + 40);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 40));
if ( *(_QWORD *)(a1 + 24) == a5 )
{
LABEL_11:
*(_QWORD *)(a1 + 24) = 0LL;
pthread_mutex_unlock(v8);
result = 4LL;
}
else
{
while ( *(_QWORD *)a1 == *(_QWORD *)(a1 + 8) )
{
pthread_cond_wait((pthread_cond_t *)(a1 + 80), v8);
if ( *(_QWORD *)(a1 + 24) == a5 )
goto LABEL_11;
}
v10 = *(_QWORD *)(a1 + 32) + 24LL * *(_QWORD *)a1;
*a2 = *(_DWORD *)(v10 + 16);
*a3 = *(_QWORD *)v10;
*a4 = *(_QWORD *)(v10 + 8);
v11 = *(_QWORD *)(a1 + 16);
*(_QWORD *)a1 = (*(_QWORD *)a1 + 1LL) % v11;
if ( !*(_QWORD *)(a1 + 32) )
_assert_fail("queue->queue != NULL", "src/nmqueue.c", 0xDDu, "nmqueue_receive");
if ( v11 <= *(_QWORD *)(a1 + 8) )
_assert_fail("queue->writePosition < queue->length", "src/nmqueue.c", 0xDDu, "nmqueue_receive");
pthread_cond_signal((pthread_cond_t *)(a1 + 128));
pthread_mutex_unlock(v8);
result = 0LL;
}
return result;
}

original_code:
int nmqueue_receive(nmqueue_t* queue,
                    source_t* source,
                    void** data,
                    size_t* dataSize,
                    void* threadId)
{
    ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/nmqueue.c", 179, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((source != ((void *)0)) ? 1 : 0), __extension__ ({ if (source != ((void *)0)) ; else __assert_fail ("source != NULL", "src/nmqueue.c", 180, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "src/nmqueue.c", 181, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((dataSize != ((void *)0)) ? 1 : 0), __extension__ ({ if (dataSize != ((void *)0)) ; else __assert_fail ("dataSize != NULL", "src/nmqueue.c", 182, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 183, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 183, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 183, __extension__ __PRETTY_FUNCTION__); }));;
    pthread_mutex_lock( &queue->mutex );
    if( queue->abort == threadId)
    {
        queue->abort = ((void *)0);
        pthread_mutex_unlock(&queue->mutex);
        return 4;
    }
    while( queue->readPosition == queue->writePosition )
    {
        pthread_cond_wait( &queue->writtenCond, &queue->mutex );
        if( queue->abort == threadId )
        {
            queue->abort = ((void *)0);
            pthread_mutex_unlock(&queue->mutex);
            return 4;
        }
    }
    {
        struct nmqueue_message_s* message = &queue->queue[ queue->readPosition ];
        *source = message->source;
        *data = message->data;
        *dataSize = message->dataSize;
        queue->readPosition = (queue->readPosition+1) % queue->length;
        ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 221, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 221, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 221, __extension__ __PRETTY_FUNCTION__); }));;
        pthread_cond_signal(&queue->readCond);
    }
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

canonical_original_code:
int nmqueue_receive(struct nmqueue_t *queue, int *source, void **data, unsigned long *dataSize, void *threadId)
{
    ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/nmqueue.c", 179, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((source != ((void *)0)) ? 1 : 0), __extension__ ({ if (source != ((void *)0)) ; else __assert_fail ("source != NULL", "src/nmqueue.c", 180, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "src/nmqueue.c", 181, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((dataSize != ((void *)0)) ? 1 : 0), __extension__ ({ if (dataSize != ((void *)0)) ; else __assert_fail ("dataSize != NULL", "src/nmqueue.c", 182, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 183, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 183, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 183, __extension__ __PRETTY_FUNCTION__); }));;
    pthread_mutex_lock( &queue->mutex );
    if( queue->abort == threadId)
    {
        queue->abort = ((void *)0);
        pthread_mutex_unlock(&queue->mutex);
        return 4;
    }
    while( queue->readPosition == queue->writePosition )
    {
        pthread_cond_wait( &queue->writtenCond, &queue->mutex );
        if( queue->abort == threadId )
        {
            queue->abort = ((void *)0);
            pthread_mutex_unlock(&queue->mutex);
            return 4;
        }
    }
    {
        struct nmqueue_message_s *message = &queue->queue[ queue->readPosition ];
        *source = message->source;
        *data = message->data;
        *dataSize = message->dataSize;
        queue->readPosition = (queue->readPosition+1) % queue->length;
        ((void) sizeof ((queue->queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->queue != ((void *)0)) ; else __assert_fail ("queue->queue != NULL", "src/nmqueue.c", 221, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->readPosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->readPosition < queue->length) ; else __assert_fail ("queue->readPosition < queue->length", "src/nmqueue.c", 221, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof ((queue->writePosition < queue->length) ? 1 : 0), __extension__ ({ if (queue->writePosition < queue->length) ; else __assert_fail ("queue->writePosition < queue->length", "src/nmqueue.c", 221, __extension__ __PRETTY_FUNCTION__); }));;
        pthread_cond_signal(&queue->readCond);
    }
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

variable_types:
source
int *

variable_types:
data
void **

variable_types:
dataSize
unsigned long *


receiverProc

decompiled_code:
void *__fastcall receiverProc(void *a1)
{
unsigned int v2; // [rsp+Ch] [rbp-1Ch] BYREF
__int64 v3; // [rsp+10h] [rbp-18h] BYREF
__int64 v4; // [rsp+18h] [rbp-10h] BYREF

while ( !*((_DWORD *)a1 + 8) )
{
if ( !(unsigned int)nmqueue_receive(*((_QWORD *)a1 + 3), &v2, &v3, &v4, a1) )
(*((void (__fastcall **)(_QWORD, __int64, __int64, _QWORD))a1 + 1))(v2, v3, v4, *((_QWORD *)a1 + 2));
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
unsigned int v2; // [rsp+Ch] [rbp-1Ch] BYREF
__int64 v3; // [rsp+10h] [rbp-18h] BYREF
__int64 v4; // [rsp+18h] [rbp-10h] BYREF

while ( !*((_DWORD *)a1 + 8) )
{
if ( !(unsigned int)nmqueue_receive(*((_QWORD *)a1 + 3), &v2, &v3, &v4, a1) )
(*((void (__fastcall **)(_QWORD, __int64, __int64, _QWORD))a1 + 1))(v2, v3, v4, *((_QWORD *)a1 + 2));
}
return 0LL;
}

original_code:
static void * receiverProc(void * receiverT)
{
    receiverthread_t* receiverThread=(receiverthread_t*) receiverT;
    while( !receiverThread->terminated )
    {
        source_t source;
        void* data;
        size_t dataSize;
        int err;
        if( (err=nmqueue_receive(receiverThread->queue,
                                 &source,
                                 &data,
                                 &dataSize,
                                 receiverThread
                                )) == 0 )
        {
            (*receiverThread->receiverDest)(source, data, dataSize, receiverThread->receiverDestParam);
        }
    }
    return ((void *)0);
}

canonical_original_code:
static void *receiverProc(void *receiverT)
{
    struct receiverthread_t *receiverThread = (receiverthread_t*) receiverT;
    while( !receiverThread->terminated )
    {
        int source;
        void *data;
        unsigned long dataSize;
        int err;
        if( (err=nmqueue_receive(receiverThread->queue,
                                 &source,
                                 &data,
                                 &dataSize,
                                 receiverThread
                                )) == 0 )
        {
            (*receiverThread->receiverDest)(source, data, dataSize, receiverThread->receiverDestParam);
        }
    }
    return ((void *)0);
}

variable_types:
receiverT
void *

variable_types: struct receiverthread_t { unsigned long thread; void (*receiverDest)(int, void *, unsigned long, void *); void *receiverDestParam; struct nmqueue_t { unsigned long readPosition; unsigned long writePosition; unsigned long length; void *abort; struct nmqueue_message_s { void *data; unsigned long dataSize; int source; } *queue; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } writtenCond; union pthread_cond_t readCond; } *queue; int terminated; } *

return_type: void *

user_defined_types: struct receiverthread_t { unsigned long thread; void (*receiverDest)(int, void *, unsigned long, void *); void *receiverDestParam; struct nmqueue_t *queue; int terminated; }


initializeReceiver

decompiled_code:
_BOOL8 __fastcall initializeReceiver(void *arg, __int64 a2, __int64 a3, __int64 a4)
{
*((_QWORD *)arg + 3) = a2;
*((_DWORD *)arg + 8) = 0;
*((_QWORD *)arg + 1) = a3;
*((_QWORD *)arg + 2) = a4;
return pthread_create((pthread_t *)arg, 0LL, receiverProc, arg) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(void *arg, __int64 a2, __int64 a3, __int64 a4)
{
*((_QWORD *)arg + 3) = a2;
*((_DWORD *)arg + 8) = 0;
*((_QWORD *)arg + 1) = a3;
*((_QWORD *)arg + 2) = a4;
return pthread_create((pthread_t *)arg, 0LL, receiverProc, arg) != 0;
}

original_code:
int initializeReceiver(receiverthread_t* receiverThread,
                       nmqueue_t* queue,
                       receiver_dest_t receiverDest,
                       void* receiverDestParam)
{
    receiverThread->queue = queue;
    receiverThread->terminated = 0;
    receiverThread->receiverDest = receiverDest;
    receiverThread->receiverDestParam = receiverDestParam;
    if( pthread_create( &receiverThread->thread, ((void *)0), receiverProc, receiverThread ) != 0 )
    {
        return 1;
    }
    return 0;
}

canonical_original_code:
int initializeReceiver(struct receiverthread_t *receiverThread, struct nmqueue_t *queue, void (*receiverDest)(int, void *, unsigned long, void *), void *receiverDestParam)
{
    receiverThread->queue = queue;
    receiverThread->terminated = 0;
    receiverThread->receiverDest = receiverDest;
    receiverThread->receiverDestParam = receiverDestParam;
    if( pthread_create( &receiverThread->thread, ((void *)0), receiverProc, receiverThread ) != 0 )
    {
        return 1;
    }
    return 0;
}

variable_types:
queue
struct nmqueue_t *

variable_types: void (*)(int, void *, unsigned long, void *)

variable_types:
receiverDestParam
void *


finalizeReceiver

decompiled_code:
int __fastcall finalizeReceiver(__int64 a1)
{
*(_DWORD *)(a1 + 32) = 1;
nmqueue_abort(*(_QWORD *)(a1 + 24), a1);
return pthread_join(*(_QWORD *)a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
*(_DWORD *)(a1 + 32) = 1;
nmqueue_abort(*(_QWORD *)(a1 + 24), a1);
return pthread_join(*(_QWORD *)a1, 0LL);
}

original_code:
void finalizeReceiver(receiverthread_t* receiverThread)
{
    receiverThread->terminated = 1;
    nmqueue_abort( receiverThread->queue, receiverThread );
    pthread_join( receiverThread->thread, ((void *)0) );
    return;
}

canonical_original_code:
void finalizeReceiver(struct receiverthread_t *receiverThread)
{
    receiverThread->terminated = 1;
    nmqueue_abort( receiverThread->queue, receiverThread );
    pthread_join( receiverThread->thread, ((void *)0) );
    return;
}


senderProc

decompiled_code:
void *__fastcall senderProc(void *a1)
{
unsigned int v2; // [rsp+Ch] [rbp-1Ch] BYREF
__int64 v3; // [rsp+10h] [rbp-18h] BYREF
__int64 v4; // [rsp+18h] [rbp-10h] BYREF

while ( !*((_DWORD *)a1 + 8) )
{
if ( !(*((unsigned int (__fastcall **)(unsigned int *, __int64 *, __int64 *, _QWORD))a1 + 1))(
&v2,
&v3,
&v4,
*((_QWORD *)a1 + 2)) )
nmqueue_send(*((_QWORD *)a1 + 3), v2, v3, v4, a1);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
unsigned int v2; // [rsp+Ch] [rbp-1Ch] BYREF
__int64 v3; // [rsp+10h] [rbp-18h] BYREF
__int64 v4; // [rsp+18h] [rbp-10h] BYREF

while ( !*((_DWORD *)a1 + 8) )
{
if ( !(*((unsigned int (__fastcall **)(unsigned int *, __int64 *, __int64 *, _QWORD))a1 + 1))(
&v2,
&v3,
&v4,
*((_QWORD *)a1 + 2)) )
nmqueue_send(*((_QWORD *)a1 + 3), v2, v3, v4, a1);
}
return 0LL;
}

original_code:
static void* senderProc(void * senderT)
{
    senderthread_t* senderThread=(senderthread_t*)senderT;
    while( !senderThread->terminated )
    {
        source_t source;
        void* data;
        size_t dataSize;
        if( (*senderThread->dataSource)(&source, &data, &dataSize, senderThread->dataSourceParam) == 0 )
        {
            nmqueue_send(senderThread->queue, source, data, dataSize, senderThread);
        }
    }
    return ((void *)0);
}

canonical_original_code:
static void *senderProc(void *senderT)
{
    struct senderthread_t *senderThread = (senderthread_t*)senderT;
    while( !senderThread->terminated )
    {
        int source;
        void *data;
        unsigned long dataSize;
        if( (*senderThread->dataSource)(&source, &data, &dataSize, senderThread->dataSourceParam) == 0 )
        {
            nmqueue_send(senderThread->queue, source, data, dataSize, senderThread);
        }
    }
    return ((void *)0);
}

variable_types:
senderT
void *

variable_types: struct senderthread_t { unsigned long thread; int (*dataSource)(int *, void **, unsigned long *, void *); void *dataSourceParam; struct nmqueue_t { unsigned long readPosition; unsigned long writePosition; unsigned long length; void *abort; struct nmqueue_message_s { void *data; unsigned long dataSize; int source; } *queue; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } writtenCond; union pthread_cond_t readCond; } *queue; int terminated; } *

user_defined_types: struct senderthread_t { unsigned long thread; int (*dataSource)(int *, void **, unsigned long *, void *); void *dataSourceParam; struct nmqueue_t *queue; int terminated; }


initializeSender

decompiled_code:
_BOOL8 __fastcall initializeSender(void *arg, __int64 a2, __int64 a3, __int64 a4)
{
*((_QWORD *)arg + 3) = a2;
*((_DWORD *)arg + 8) = 0;
*((_QWORD *)arg + 1) = a3;
*((_QWORD *)arg + 2) = a4;
return pthread_create((pthread_t *)arg, 0LL, senderProc, arg) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(void *arg, __int64 a2, __int64 a3, __int64 a4)
{
*((_QWORD *)arg + 3) = a2;
*((_DWORD *)arg + 8) = 0;
*((_QWORD *)arg + 1) = a3;
*((_QWORD *)arg + 2) = a4;
return pthread_create((pthread_t *)arg, 0LL, senderProc, arg) != 0;
}

original_code:
int initializeSender(senderthread_t* senderThread,
                     nmqueue_t* queue,
                     sender_source_t dataSource,
                     void* dataSourceParam)
{
    senderThread->queue = queue;
    senderThread->terminated = 0;
    senderThread->dataSource = dataSource;
    senderThread->dataSourceParam = dataSourceParam;
    if ( pthread_create( &senderThread->thread, ((void *)0), senderProc, senderThread ) != 0 )
    {
        return 1;
    }
    return 0;
}

canonical_original_code:
int initializeSender(struct senderthread_t *senderThread, struct nmqueue_t *queue, int (*dataSource)(int *, void **, unsigned long *, void *), void *dataSourceParam)
{
    senderThread->queue = queue;
    senderThread->terminated = 0;
    senderThread->dataSource = dataSource;
    senderThread->dataSourceParam = dataSourceParam;
    if ( pthread_create( &senderThread->thread, ((void *)0), senderProc, senderThread ) != 0 )
    {
        return 1;
    }
    return 0;
}

variable_types: int (*)(int *, void **, unsigned long *, void *)

variable_types:
dataSourceParam
void *


finalizeSender

decompiled_code:
int __fastcall finalizeSender(__int64 a1)
{
*(_DWORD *)(a1 + 32) = 1;
nmqueue_abort(*(_QWORD *)(a1 + 24), a1);
return pthread_join(*(_QWORD *)a1, 0LL);
}

original_code:
void finalizeSender(senderthread_t* senderThread)
{
    senderThread->terminated = 1;
    nmqueue_abort( senderThread->queue, senderThread );
    pthread_join( senderThread->thread, ((void *)0) );
}

canonical_original_code:
void finalizeSender(struct senderthread_t *senderThread)
{
    senderThread->terminated = 1;
    nmqueue_abort( senderThread->queue, senderThread );
    pthread_join( senderThread->thread, ((void *)0) );
}


original_code:
uint64_t timespec_to_us(struct timespec time)
{
    return time.tv_sec*1000*1000+time.tv_nsec/1000;
}

canonical_original_code:
unsigned long timespec_to_us(struct timespec time)
{
    return time.tv_sec*1000*1000+time.tv_nsec/1000;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
unsigned __int64 __fastcall us_to_timespec(unsigned __int64 a1)
{
return a1 / 0xF4240;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int64 a1)
{
return a1 / 0xF4240;
}

original_code:
struct timespec us_to_timespec(uint64_t time)
{
    struct timespec result;
    result.tv_sec = time/(1000*1000);
    result.tv_nsec = (time % (1000*1000))*1000;
    return result;
}

canonical_original_code:
struct timespec us_to_timespec(unsigned long time)
{
    struct timespec result;
    result.tv_sec = time/(1000*1000);
    result.tv_nsec = (time % (1000*1000))*1000;
    return result;
}

variable_types:
time
unsigned long

return_type: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
__int64 __fastcall get_external_data(const void *a1)
{
sleep(1u);
printf("External...%p\n", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1)
{
sleep(1u);
printf("External...%p\n", a1);
return 0LL;
}

original_code:
int get_external_data(char * buffer, int bufferSizeInBytes)
{
    sleep(1);
    printf("External...%p\n", buffer );
    return 0;
}

canonical_original_code:
int get_external_data(char *buffer, int bufferSizeInBytes)
{
    sleep(1);
    printf("External...%p\n", buffer );
    return 0;
}

variable_types:
buffer
char *

variable_types: bufferSizeInBytes int


decompiled_code:
int __fastcall process_data(const void *a1)
{
return printf("Process...%p\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const void *a1)
{
return printf("Process...%p\n", a1);
}

original_code:
void process_data(char * buffer, int bufferSizeInBytes)
{
    printf("Process...%p\n", buffer );
    return;
}

canonical_original_code:
void process_data(char *buffer, int bufferSizeInBytes)
{
    printf("Process...%p\n", buffer );
    return;
}


producer

decompiled_code:
__int64 __fastcall producer(_DWORD *a1, const void **a2, _QWORD *a3, int a4)
{
__int64 result; // rax

*a1 = a4;
*a2 = malloc(0x400uLL);
*a3 = 1024LL;
result = get_external_data(*a2);
if ( (_DWORD)result )
{
free((void *)*a2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, const void **a2, _QWORD *a3, int a4)
{
__int64 result; // rax

*a1 = a4;
*a2 = malloc(0x400uLL);
*a3 = 1024LL;
result = func0(*a2);
if ( (_DWORD)result )
{
free((void *)*a2);
result = 1LL;
}
return result;
}

original_code:
int producer(source_t* source,
             void** data,
             size_t* dataSize,
             void* param)
{
    *source = (int)((size_t)(param));
    *data = malloc( 1024 );
    *dataSize = 1024;
    if( get_external_data( (char*)(*data) , 1024 ) != 0 )
    {
        free( *data );
        return 1;
    }
    return 0;
}

canonical_original_code:
int producer(int *source, void **data, unsigned long *dataSize, void *param)
{
    *source = (int)((unsigned long)(param));
    *data = malloc( 1024 );
    *dataSize = 1024;
    if( get_external_data( (char *)(*data) , 1024 ) != 0 )
    {
        free( *data );
        return 1;
    }
    return 0;
}

variable_types:
param
void *


consumer

decompiled_code:
void __fastcall consumer(unsigned int a1, void *a2, __int64 a3, __int64 a4)
{
printf("Consume from %i in %i\n", a1, a4);
process_data(a2);
free(a2);
}

canonical_decompiled_code:
void __fastcall func3(unsigned int a1, void *a2, __int64 a3, __int64 a4)
{
printf("Consume from %i in %i\n", a1, a4);
func2(a2);
free(a2);
}

original_code:
void consumer(source_t source,
             void* data,
             size_t dataSize,
             void* param)
{
    printf("Consume from %i in %i\n",source,(int)((size_t)(param)));
    process_data( (char*)data, dataSize );
    free( data );
}

canonical_original_code:
void consumer(int source, void *data, unsigned long dataSize, void *param)
{
    printf("Consume from %i in %i\n",source,(int)((unsigned long)(param)));
    process_data( (char *)data, dataSize );
    free( data );
}

variable_types: source int

variable_types:
data
void *

variable_types:
dataSize
unsigned long


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
__int64 v4; // rbx
char *v5; // rbp
__int64 v6; // rbx

nmqueue_initialize(&queue, 1024LL, envp);
v3 = (char *)&senderThreads;
v4 = 0LL;
while ( !(unsigned int)initializeSender(v3, &queue, producer, v4) )
{
++v4;
v3 += 40;
if ( v4 == 10 )
{
v5 = (char *)&receiverThreads;
v6 = 0LL;
while ( !(unsigned int)initializeReceiver(v5, &queue, consumer, v6) )
{
++v6;
v5 += 40;
if ( v6 == 20 )
{
while ( 1 )
sleep(1u);
}
}
perror("Receiver initialize failed\n");
exit(1);
}
}
perror("Sender initialize failed\n");
exit(1);
}

original_code:
int main(int argc, char** argv)
{
    size_t i;
    nmqueue_initialize(&queue , 1024);
    for( i=0 ; i<10 ; ++i )
    {
        if( initializeSender( &senderThreads[i], &queue, producer, (void*)i ) != 0 )
        {
            perror("Sender initialize failed\n");
            exit(1);
        }
    }
    for( i=0; i<20 ; ++i )
    {
        if( initializeReceiver( &receiverThreads[i], &queue, consumer, (void*)i ) != 0 )
        {
            perror("Receiver initialize failed\n");
            exit(1);
        }
    }
    for(;;)
    {
        sleep(1);
    }
    for( i=0 ; i<10 ; ++i )
    {
        finalizeSender( &senderThreads[i] );
    }
    for( i=0; i<20 ; ++i )
    {
        finalizeReceiver( &receiverThreads[i] );
    }
    nmqueue_finalize(&queue);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned long i;
    nmqueue_initialize(&queue , 1024);
    for( i=0 ; i<10 ; ++i )
    {
        if( initializeSender( &senderThreads[i], &queue, producer, (void *)i ) != 0 )
        {
            perror("Sender initialize failed\n");
            exit(1);
        }
    }
    for( i=0; i<20 ; ++i )
    {
        if( initializeReceiver( &receiverThreads[i], &queue, consumer, (void *)i ) != 0 )
        {
            perror("Receiver initialize failed\n");
            exit(1);
        }
    }
    for(;;)
    {
        sleep(1);
    }
    for( i=0 ; i<10 ; ++i )
    {
        finalizeSender( &senderThreads[i] );
    }
    for( i=0; i<20 ; ++i )
    {
        finalizeReceiver( &receiverThreads[i] );
    }
    nmqueue_finalize(&queue);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
i
unsigned long