calloc

decompiled_code:
void *__fastcall calloc(void *a1, __int64 a2)
{
void *v2; // rbp
void *v3; // rax

v2 = a1;
pthread_mutex_lock(&lock[1]);
v3 = malloc((_QWORD)a1 * a2);
if ( v3 )
{
v2 = v3;
memset(v3, 0, (_QWORD)a1 * a2);
}
pthread_mutex_unlock(&lock[1]);
return v2;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1, __int64 a2)
{
void *v2; // rbp
void *v3; // rax

v2 = a1;
pthread_mutex_lock(&lock[1]);
v3 = malloc((_QWORD)a1 * a2);
if ( v3 )
{
v2 = v3;
memset(v3, 0, (_QWORD)a1 * a2);
}
pthread_mutex_unlock(&lock[1]);
return v2;
}

original_code:
void *calloc(size_t nmemb, size_t size)
{
  void *new;
  pthread_mutex_lock(&lock[1]);
  new = malloc(size * nmemb);
  if (new)
    {
      memset(new, 0, (size * nmemb));
      pthread_mutex_unlock(&lock[1]);
      return (new);
    }
  pthread_mutex_unlock(&lock[1]);
}

canonical_original_code:
void *calloc(unsigned long nmemb, unsigned long size)
{
  void *new;
  pthread_mutex_lock(&lock[1]);
  new = malloc(size * nmemb);
  if (new)
    {
      memset(new, 0, (size * nmemb));
      pthread_mutex_unlock(&lock[1]);
      return (new);
    }
  pthread_mutex_unlock(&lock[1]);
}

variable_types:
nmemb
unsigned long

variable_types:
new
void *


repo: GhaisB/Malloc

decompiled_code:
void *__fastcall act_realloc(void *src, size_t size)
{
void *v2; // rbx
size_t v3; // r12
void *v4; // rax

v2 = src;
free(src);
v3 = size_link;
if ( size_link )
{
v4 = malloc(size);
v2 = memcpy(v4, src, v3);
size_link = 0LL;
}
pthread_mutex_unlock(&lock[1]);
return v2;
}

canonical_decompiled_code:
void *__fastcall func1(void *src, size_t size)
{
void *v2; // rbx
size_t v3; // r12
void *v4; // rax

v2 = src;
free(src);
v3 = size_link;
if ( size_link )
{
v4 = malloc(size);
v2 = memcpy(v4, src, v3);
size_link = 0LL;
}
pthread_mutex_unlock(&lock[1]);
return v2;
}

original_code:
void *act_realloc(void *ptr, size_t taille)
{
  void *copy;
  copy = ((void *)0);
  free(ptr);
  if (size_link == 0)
    {
      pthread_mutex_unlock(&lock[1]);
      return (ptr);
    }
  copy = malloc(taille);
  copy = memcpy(copy, ptr, size_link);
  size_link = 0;
  pthread_mutex_unlock(&lock[1]);
  return (copy);
}

canonical_original_code:
void *act_realloc(void *ptr, unsigned long taille)
{
  void *copy;
  copy = ((void *)0);
  free(ptr);
  if (size_link == 0)
    {
      pthread_mutex_unlock(&lock[1]);
      return (ptr);
    }
  copy = malloc(taille);
  copy = memcpy(copy, ptr, size_link);
  size_link = 0;
  pthread_mutex_unlock(&lock[1]);
  return (copy);
}

variable_types:
ptr
void *

variable_types:
taille
unsigned long

variable_types:
copy
void *

return_type: void *


realloc

decompiled_code:
void *__fastcall realloc(void *src, size_t size)
{
void *result; // rax

pthread_mutex_lock(&lock[1]);
if ( src )
{
if ( size )
{
result = act_realloc(src, size);
}
else
{
free(src);
pthread_mutex_unlock(&lock[1]);
result = 0LL;
}
}
else
{
pthread_mutex_unlock(&lock[1]);
result = malloc(size);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *src, size_t size)
{
void *result; // rax

pthread_mutex_lock(&lock[1]);
if ( src )
{
if ( size )
{
result = func1(src, size);
}
else
{
free(src);
pthread_mutex_unlock(&lock[1]);
result = 0LL;
}
}
else
{
pthread_mutex_unlock(&lock[1]);
result = malloc(size);
}
return result;
}

original_code:
void *realloc(void *ptr, size_t taille)
{
  t_malloc *tmp;
  pthread_mutex_lock(&lock[1]);
  if (ptr == ((void *)0))
    {
      pthread_mutex_unlock(&lock[1]);
      return (malloc(taille));
    }
  else if (taille == 0)
    free(ptr);
  else
    return (act_realloc(ptr, taille));
  pthread_mutex_unlock(&lock[1]);
  return (((void *)0));
}

canonical_original_code:
void *realloc(void *ptr, unsigned long taille)
{
  struct s_malloc *tmp;
  pthread_mutex_lock(&lock[1]);
  if (ptr == ((void *)0))
    {
      pthread_mutex_unlock(&lock[1]);
      return (malloc(taille));
    }
  else if (taille == 0)
    free(ptr);
  else
    return (act_realloc(ptr, taille));
  pthread_mutex_unlock(&lock[1]);
  return (((void *)0));
}

variable_types: struct s_malloc { struct s_malloc *next; struct s_malloc *prev; unsigned long size; char isFree; } *


repo: Ghuillaume/ChatOn

original_code:
int copier_chaine(char *dest, const char *src, int debut, int longueur)
{
 int i = debut;
 int j = 0;
 while ( (src[i] != ';') && (src[i] != '\0') && (j < longueur) )
 {
  dest[j] = src[i];
  i++;
  j++;
 }
 for(; src[i] != ';'; i++);
 dest[j] = '\0';
 return i;
}

canonical_original_code:
int copier_chaine(char *dest, char *src, int debut, int longueur)
{
 int i = debut;
 int j = 0;
 while ( (src[i] != ';') && (src[i] != '\0') && (j < longueur) )
 {
  dest[j] = src[i];
  i++;
  j++;
 }
 for(; src[i] != ';'; i++);
 dest[j] = '\0';
 return i;
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types: debut int

variable_types: longueur int

variable_types: i int

variable_types: j int

return_type: int


decompiled_code:
char *__fastcall separer_phrase(char *s, char *a2, char *a3, int a4)
{
char *result; // rax
const char *v7; // rsi
int v8; // er13

*(_QWORD *)s = 0LL;
*(_QWORD *)a2 = 0LL;
result = strtok(a3, " ");
if ( result )
{
v7 = result;
v8 = 0;
do
{
if ( a4 <= v8 )
{
strcat(a2, v7);
*(_WORD *)&a2[strlen(a2)] = 32;
}
else
{
strcat(s, v7);
*(_WORD *)&s[strlen(s)] = 32;
}
result = strtok(0LL, " ");
v7 = result;
++v8;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *s, char *a2, char *a3, int a4)
{
char *result; // rax
const char *v7; // rsi
int v8; // er13

*(_QWORD *)s = 0LL;
*(_QWORD *)a2 = 0LL;
result = strtok(a3, " ");
if ( result )
{
v7 = result;
v8 = 0;
do
{
if ( a4 <= v8 )
{
strcat(a2, v7);
*(_WORD *)&a2[strlen(a2)] = 32;
}
else
{
strcat(s, v7);
*(_WORD *)&s[strlen(s)] = 32;
}
result = strtok(0LL, " ");
v7 = result;
++v8;
}
while ( result );
}
return result;
}

original_code:
void separer_phrase(char *partie1, char *partie2, char *src, int occurence)
{
 memset(partie1, '\0', sizeof(partie1));
 memset(partie2, '\0', sizeof(partie2));
 char* mot = strtok(src, " ");
 int occurence_espace = 0;
 while((mot != ((void *)0)))
 {
  if(occurence_espace < occurence)
  {
   strcat(partie1, mot);
   strcat(partie1, " ");
  }
  else
  {
   strcat(partie2, mot);
   strcat(partie2, " ");
  }
  mot = strtok(((void *)0), " ");
  occurence_espace++;
 }
 return;
}

canonical_original_code:
void separer_phrase(char *partie1, char *partie2, char *src, int occurence)
{
 memset(partie1, '\0', sizeof(partie1));
 memset(partie2, '\0', sizeof(partie2));
 char *mot = strtok(src, " ");
 int occurence_espace = 0;
 while((mot != ((void *)0)))
 {
  if(occurence_espace < occurence)
  {
   strcat(partie1, mot);
   strcat(partie1, " ");
  }
  else
  {
   strcat(partie2, mot);
   strcat(partie2, " ");
  }
  mot = strtok(((void *)0), " ");
  occurence_espace++;
 }
 return;
}

variable_types: occurence int

variable_types:
mot
char *

return_type: void


initFile

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

debug = fopen("file_debug.txt", "w");
fwrite("Initializing queue\n", 1uLL, 0x13uLL, debug);
result = fclose(debug);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 0;
return result;
}

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

debug = fopen("file_debug.txt", "w");
fwrite("Initializing queue\n", 1uLL, 0x13uLL, debug);
result = fclose(debug);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 0;
return result;
}

original_code:
void initFile(File *file)
{
 debug = fopen("file_debug.txt", "w");
 fprintf(debug, "Initializing queue\n");
 fclose(debug);
 file->debut = ((void *)0);
 file->fin = ((void *)0);
 file->taille = 0;
}

canonical_original_code:
void initFile(struct FilePtr *file)
{
 debug = fopen("file_debug.txt", "w");
 fprintf(debug, "Initializing queue\n");
 fclose(debug);
 file->debut = ((void *)0);
 file->fin = ((void *)0);
 file->taille = 0;
}

variable_types: struct FilePtr { struct ListNode { struct message { char source[-1]; char dest[-1]; char message[-1]; int forAll; } *msg; struct ListNode *suivant; } *debut; struct ListNode *fin; int taille; } *

user_defined_types: struct FilePtr { struct ListNode *debut; struct ListNode *fin; int taille; }

user_defined_types: struct ListNode { struct message *msg; struct ListNode *suivant; }


fileDebug

decompiled_code:
int __fastcall fileDebug(__int64 a1)
{
FILE *v1; // rax
__int64 v2; // rdx
const char **v3; // rbx
unsigned int v4; // ebp

v1 = fopen("file_debug.txt", "a+");
debug = v1;
v2 = *(unsigned int *)(a1 + 16);
if ( (int)v2 < 0 )
{
fwrite(&unk_2F8, 1uLL, 0x1AuLL, v1);
}
else
{
fprintf(v1, "\t\tFile (%d) :\n", v2);
v3 = *(const char ***)a1;
if ( *(_QWORD *)a1 )
{
v4 = 1;
do
{
fprintf(debug, "\t\t\t%d. %s(from %s to %s)\n", v4, *v3 + 62, *v3, *v3 + 31);
v3 = (const char **)v3[1];
++v4;
}
while ( v3 );
}
}
return fclose(debug);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
FILE *v1; // rax
__int64 v2; // rdx
const char **v3; // rbx
unsigned int v4; // ebp

v1 = fopen("file_debug.txt", "a+");
debug = v1;
v2 = *(unsigned int *)(a1 + 16);
if ( (int)v2 < 0 )
{
fwrite(&unk_2F8, 1uLL, 0x1AuLL, v1);
}
else
{
fprintf(v1, "\t\tFile (%d) :\n", v2);
v3 = *(const char ***)a1;
if ( *(_QWORD *)a1 )
{
v4 = 1;
do
{
fprintf(debug, "\t\t\t%d. %s(from %s to %s)\n", v4, *v3 + 62, *v3, *v3 + 31);
v3 = (const char **)v3[1];
++v4;
}
while ( v3 );
}
}
return fclose(debug);
}

original_code:
void fileDebug(File* file) {
 debug = fopen("file_debug.txt", "a+");
 if(file->taille < 0) {
  fprintf(debug, "\t\tFile de taile négative\n");
 }
 else if(file->taille >= 0) {
  fprintf(debug, "\t\tFile (%d) :\n", file->taille);
  Node* current = file->debut;
  int i = 1;
  while(current != ((void *)0)) {
   fprintf(debug, "\t\t\t%d. %s(from %s to %s)\n", i, current->msg->message, current->msg->source, current->msg->dest);
   current = current->suivant;
   i++;
  }
 }
 fclose(debug);
}

canonical_original_code:
void fileDebug(struct FilePtr *file) {
 debug = fopen("file_debug.txt", "a+");
 if(file->taille < 0) {
  fprintf(debug, "\t\tFile de taile négative\n");
 }
 else if(file->taille >= 0) {
  fprintf(debug, "\t\tFile (%d) :\n", file->taille);
  struct ListNode *current = file->debut;
  int i = 1;
  while(current != ((void *)0)) {
   fprintf(debug, "\t\t\t%d. %s(from %s to %s)\n", i, current->msg->message, current->msg->source, current->msg->dest);
   current = current->suivant;
   i++;
  }
 }
 fclose(debug);
}

variable_types: struct ListNode { struct message { char source[-1]; char dest[-1]; char message[-1]; int forAll; } *msg; struct ListNode *suivant; } *


push

decompiled_code:
__int64 __fastcall push(__int64 a1, __int64 a2)
{
FILE *v2; // rbp
_QWORD *v3; // rax
__int64 result; // rax

v2 = fopen("file_debug.txt", "a+");
debug = v2;
v3 = malloc(0x10uLL);
if ( v3 )
{
*v3 = a2;
v3[1] = 0LL;
if ( *(_DWORD *)(a1 + 16) )
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = v3;
else
*(_QWORD *)a1 = v3;
*(_QWORD *)(a1 + 8) = v3;
++*(_DWORD *)(a1 + 16);
fprintf(debug, "Pushed in queue : %s\n", (const char *)(*v3 + 62LL));
fclose(debug);
fileDebug(a1);
result = 0LL;
}
else
{
fwrite("Malloc error !\n", 1uLL, 0xFuLL, v2);
fclose(debug);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
FILE *v2; // rbp
_QWORD *v3; // rax
__int64 result; // rax

v2 = fopen("file_debug.txt", "a+");
debug = v2;
v3 = malloc(0x10uLL);
if ( v3 )
{
*v3 = a2;
v3[1] = 0LL;
if ( *(_DWORD *)(a1 + 16) )
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = v3;
else
*(_QWORD *)a1 = v3;
*(_QWORD *)(a1 + 8) = v3;
++*(_DWORD *)(a1 + 16);
fprintf(debug, "Pushed in queue : %s\n", (const char *)(*v3 + 62LL));
fclose(debug);
func1(a1);
result = 0LL;
}
else
{
fwrite("Malloc error !\n", 1uLL, 0xFuLL, v2);
fclose(debug);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int push(File* file, message *msg)
{
 debug = fopen("file_debug.txt", "a+");
 Node *toPush;
 if ((toPush = (Node *) malloc (sizeof (Node))) == ((void *)0)) {
  fprintf(debug, "Malloc error !\n");
  fclose(debug);
  return -1;
 }
 toPush->msg = msg;
 toPush->suivant = ((void *)0);
 if(file->taille == 0) {
  file->debut = toPush;
 }
 else {
  file->fin->suivant = toPush;
 }
 file->fin = toPush;
 file->taille++;
 fprintf(debug, "Pushed in queue : %s\n", toPush->msg->message);
 fclose(debug);
 fileDebug(file);
 return 0;
}

canonical_original_code:
int push(struct FilePtr *file, struct message *msg)
{
 debug = fopen("file_debug.txt", "a+");
 struct ListNode *toPush;
 if ((toPush = (struct ListNode *) malloc (sizeof (Node))) == ((void *)0)) {
  fprintf(debug, "Malloc error !\n");
  fclose(debug);
  return -1;
 }
 toPush->msg = msg;
 toPush->suivant = ((void *)0);
 if(file->taille == 0) {
  file->debut = toPush;
 }
 else {
  file->fin->suivant = toPush;
 }
 file->fin = toPush;
 file->taille++;
 fprintf(debug, "Pushed in queue : %s\n", toPush->msg->message);
 fclose(debug);
 fileDebug(file);
 return 0;
}

variable_types:
msg
struct message *

user_defined_types: struct message { char source[-1]; char dest[-1]; char message[-1]; int forAll; }


repo: GitReinDa/pokusArt

decompiled_code:
__int64 suite_all()
{
++_gcov0_suite_all;
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
++_gcov0_suite_all;
return 1LL;
}

original_code:
static int suite_all(struct ctest* t) {
    return 1;
}

canonical_original_code:
static int suite_all(struct ctest *t) {
    return 1;
}

variable_types: struct ctest { char *ssname; char *ttname; void (*run)(); int skip; void *data; void (*setup)(void *); void (*teardown)(void *); unsigned int magic; } *


decompiled_code:
__int64 msg_end()
{
__int64 result; // rax
int v1; // eax

++_gcov0_msg_end;
if ( color_output )
{
++qword_11E8;
v1 = snprintf(ctest_errormsg, ctest_errorsize, "\x1B[0m");
ctest_errorsize -= v1;
ctest_errormsg += v1;
}
result = snprintf(ctest_errormsg, ctest_errorsize, "\n");
ctest_errorsize -= (int)result;
ctest_errormsg += (int)result;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
int v1; // eax

++_gcov0_msg_end;
if ( color_output )
{
++qword_11E8;
v1 = snprintf(ctest_errormsg, ctest_errorsize, "\x1B[0m");
ctest_errorsize -= v1;
ctest_errormsg += v1;
}
result = snprintf(ctest_errormsg, ctest_errorsize, "\n");
ctest_errorsize -= (int)result;
ctest_errormsg += (int)result;
return result;
}

original_code:
static void msg_end() {
    int size;
    if (color_output) {
        size = snprintf(ctest_errormsg, ctest_errorsize, "\033[0m");
        ctest_errorsize -= size;
        ctest_errormsg += size;
    }
    size = snprintf(ctest_errormsg, ctest_errorsize, "\n");
    ctest_errorsize -= size;
    ctest_errormsg += size;
}

variable_types: size int


decompiled_code:
__int64 __fastcall msg_start(const char *a1, const char *a2)
{
__int64 result; // rax
int v3; // eax

++_gcov0_msg_start;
if ( color_output )
{
++qword_11D8;
v3 = snprintf(ctest_errormsg, ctest_errorsize, "%s", a1);
ctest_errorsize -= v3;
ctest_errormsg += v3;
}
result = snprintf(ctest_errormsg, ctest_errorsize, " %s: ", a2);
ctest_errorsize -= (int)result;
ctest_errormsg += (int)result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, const char *a2)
{
__int64 result; // rax
int v3; // eax

++_gcov0_msg_start;
if ( color_output )
{
++qword_11D8;
v3 = snprintf(ctest_errormsg, ctest_errorsize, "%s", a1);
ctest_errorsize -= v3;
ctest_errormsg += v3;
}
result = snprintf(ctest_errormsg, ctest_errorsize, " %s: ", a2);
ctest_errorsize -= (int)result;
ctest_errormsg += (int)result;
return result;
}

original_code:
static void msg_start(const char* color, const char* title) {
    int size;
    if (color_output) {
        size = snprintf(ctest_errormsg, ctest_errorsize, "%s", color);
        ctest_errorsize -= size;
        ctest_errormsg += size;
    }
    size = snprintf(ctest_errormsg, ctest_errorsize, "  %s: ", title);
    ctest_errorsize -= size;
    ctest_errormsg += size;
}

canonical_original_code:
static void msg_start(char *color, char *title) {
    int size;
    if (color_output) {
        size = snprintf(ctest_errormsg, ctest_errorsize, "%s", color);
        ctest_errorsize -= size;
        ctest_errormsg += size;
    }
    size = snprintf(ctest_errormsg, ctest_errorsize, "  %s: ", title);
    ctest_errorsize -= size;
    ctest_errormsg += size;
}

variable_types:
color
char *

variable_types:
title
char *


decompiled_code:
int __fastcall color_print(const char *a1, const char *a2)
{
int result; // eax

if ( color_output )
{
++_gcov0_color_print;
result = printf("%s%s\x1B[0m\n", a1, a2);
++qword_13B0;
}
else
{
++qword_13A8;
result = puts(a2);
++qword_13B8;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(const char *a1, const char *a2)
{
int result; // eax

if ( color_output )
{
++_gcov0_color_print;
result = printf("%s%s\x1B[0m\n", a1, a2);
++qword_13B0;
}
else
{
++qword_13A8;
result = puts(a2);
++qword_13B8;
}
return result;
}

original_code:
static void color_print(const char* color, const char* text) {
    if (color_output)
        printf("%s%s""\033[0m""\n", color, text);
    else
        printf("%s\n", text);
}

canonical_original_code:
static void color_print(char *color, char *text) {
    if (color_output)
        printf("%s%s""\033[0m""\n", color, text);
    else
        printf("%s\n", text);
}

variable_types:
text
char *


decompiled_code:
_BOOL8 __fastcall suite_filter(const char **a1)
{
const char *v1; // rbp
size_t v2; // rax

++_gcov0_suite_filter;
v1 = suite_name;
v2 = strlen(suite_name);
return strncmp(v1, *a1, v2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(const char **a1)
{
const char *v1; // rbp
size_t v2; // rax

++_gcov0_suite_filter;
v1 = suite_name;
v2 = strlen(suite_name);
return strncmp(v1, *a1, v2) == 0;
}

original_code:
static int suite_filter(struct ctest* t) {
    return strncmp(suite_name, t->ssname, strlen(suite_name)) == 0;
}

canonical_original_code:
static int suite_filter(struct ctest *t) {
    return strncmp(suite_name, t->ssname, strlen(suite_name)) == 0;
}

user_defined_types: struct ctest { char *ssname; char *ttname; void (*run)(); int skip; void *data; void (*setup)(void *); void (*teardown)(void *); unsigned int magic; }


getCurrentTime

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

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

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

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

original_code:
static uint64_t getCurrentTime() {
    struct timeval now;
    gettimeofday(&now, ((void *)0));
    uint64_t now64 = now.tv_sec;
    now64 *= 1000000;
    now64 += (now.tv_usec);
    return now64;
}

canonical_original_code:
static unsigned long getCurrentTime() {
    struct timeval now;
    gettimeofday(&now, ((void *)0));
    unsigned long now64 = now.tv_sec;
    now64 *= 1000000;
    now64 += (now.tv_usec);
    return now64;
}

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

return_type: unsigned long


decompiled_code:
__int64 CTEST_LOG(char *format, ...)
{
int v1; // eax
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
++_gcov0_CTEST_LOG;
msg_start("\x1B[0;34m", "LOG");
++qword_11F8;
v1 = vsnprintf(ctest_errormsg, ctest_errorsize, format, arg);
ctest_errorsize -= v1;
ctest_errormsg += v1;
result = msg_end();
++qword_1200;
return result;
}

canonical_decompiled_code:
__int64 func7(char *format, ...)
{
int v1; // eax
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
++_gcov0_CTEST_LOG;
func3("\x1B[0;34m", "LOG");
++qword_11F8;
v1 = vsnprintf(ctest_errormsg, ctest_errorsize, format, arg);
ctest_errorsize -= v1;
ctest_errormsg += v1;
result = func2();
++qword_1200;
return result;
}

original_code:
void CTEST_LOG(char *fmt, ...)
{
    va_list argp;
    msg_start("\033[0;34m", "LOG");
    __builtin_va_start(argp,fmt);
    int size = vsnprintf(ctest_errormsg, ctest_errorsize, fmt, argp);
    ctest_errorsize -= size;
    ctest_errormsg += size;
    __builtin_va_end(argp);
    msg_end();
}

canonical_original_code:
void CTEST_LOG(char *fmt, ...)
{
    __builtin_va_list argp;
    msg_start("\033[0;34m", "LOG");
    __builtin_va_start(argp,fmt);
    int size = vsnprintf(ctest_errormsg, ctest_errorsize, fmt, argp);
    ctest_errorsize -= size;
    ctest_errormsg += size;
    __builtin_va_end(argp);
    msg_end();
}

variable_types:
fmt
char *


decompiled_code:
__int64 CTEST_ERR(char *format, ...)
{
int v1; // eax
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
++_gcov0_CTEST_ERR;
msg_start("\x1B[0;33m", "ERR");
++qword_1218;
v1 = vsnprintf(ctest_errormsg, ctest_errorsize, format, arg);
ctest_errorsize -= v1;
ctest_errormsg += v1;
result = msg_end();
++qword_1220;
return result;
}

canonical_decompiled_code:
__int64 func8(char *format, ...)
{
int v1; // eax
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
++_gcov0_CTEST_ERR;
func3("\x1B[0;33m", "ERR");
++qword_1218;
v1 = vsnprintf(ctest_errormsg, ctest_errorsize, format, arg);
ctest_errorsize -= v1;
ctest_errormsg += v1;
result = func2();
++qword_1220;
return result;
}

original_code:
void CTEST_ERR(char *fmt, ...)
{
    va_list argp;
    msg_start("\033[0;33m", "ERR");
    __builtin_va_start(argp,fmt);
    int size = vsnprintf(ctest_errormsg, ctest_errorsize, fmt, argp);
    ctest_errorsize -= size;
    ctest_errormsg += size;
    __builtin_va_end(argp);
    msg_end();
}

canonical_original_code:
void CTEST_ERR(char *fmt, ...)
{
    __builtin_va_list argp;
    msg_start("\033[0;33m", "ERR");
    __builtin_va_start(argp,fmt);
    int size = vsnprintf(ctest_errormsg, ctest_errorsize, fmt, argp);
    ctest_errorsize -= size;
    ctest_errormsg += size;
    __builtin_va_end(argp);
    msg_end();
}


decompiled_code:
char __fastcall assert_str(const char *a1, const char *a2, const char *a3, unsigned int a4)
{
int v6; // eax

LOBYTE(v6) = a2 == 0LL;
if ( (a1 == 0LL) != (a2 == 0LL) )
{
++_gcov0_assert_str;
goto LABEL_7;
}
++qword_1248;
if ( a1 )
{
if ( a2 )
{
++qword_1250;
v6 = strcmp(a1, a2);
if ( v6 )
{
++qword_1258;
LABEL_7:
CTEST_ERR("%s:%d expected '%s', got '%s'", a3, a4, a1, a2);
++qword_1260;
longjmp(ctest_err, 1);
}
}
}
return v6;
}

canonical_decompiled_code:
char __fastcall func9(const char *a1, const char *a2, const char *a3, unsigned int a4)
{
int v6; // eax

LOBYTE(v6) = a2 == 0LL;
if ( (a1 == 0LL) != (a2 == 0LL) )
{
++_gcov0_assert_str;
goto LABEL_7;
}
++qword_1248;
if ( a1 )
{
if ( a2 )
{
++qword_1250;
v6 = strcmp(a1, a2);
if ( v6 )
{
++qword_1258;
LABEL_7:
func8("%s:%d expected '%s', got '%s'", a3, a4, a1, a2);
++qword_1260;
longjmp(ctest_err, 1);
}
}
}
return v6;
}

original_code:
void assert_str(const char* exp, const char* real, const char* caller, int line) {
    if ((exp == ((void *)0) && real != ((void *)0)) ||
        (exp != ((void *)0) && real == ((void *)0)) ||
        (exp && real && strcmp(exp, real) != 0)) {
        CTEST_ERR("%s:%d  expected '%s', got '%s'", caller, line, exp, real);
        longjmp(ctest_err, 1);
    }
}

canonical_original_code:
void assert_str(char *exp, char *real, char *caller, int line) {
    if ((exp == ((void *)0) && real != ((void *)0)) ||
        (exp != ((void *)0) && real == ((void *)0)) ||
        (exp && real && strcmp(exp, real) != 0)) {
        CTEST_ERR("%s:%d  expected '%s', got '%s'", caller, line, exp, real);
        longjmp(ctest_err, 1);
    }
}

variable_types:
exp
char *

variable_types:
real
char *

variable_types:
caller
char *

variable_types: line int


decompiled_code:
void __fastcall assert_data(__int64 a1, int a2, __int64 a3, unsigned int a4, const char *a5, unsigned int a6)
{
__int64 v8; // rdx
__int64 v9; // r9
__int64 v10; // rax
char v11; // r11
unsigned __int8 v12; // cl
unsigned __int8 v13; // si

if ( a2 != a4 )
{
++_gcov0_assert_data;
CTEST_ERR("%s:%d expected %d bytes, got %d", a5, a6, (unsigned int)a2, a4);
++qword_1288;
longjmp(ctest_err, 1);
}
if ( a2 > 0 )
{
v8 = qword_1298;
v9 = (unsigned int)(a2 - 1);
v10 = 0LL;
v11 = 0;
while ( 1 )
{
v12 = *(_BYTE *)(a1 + v10);
v13 = *(_BYTE *)(a3 + v10);
if ( v12 != v13 )
{
if ( v11 )
qword_1298 = v8;
++qword_1290;
CTEST_ERR("%s:%d expected 0x%02x at offset %d got 0x%02x", a5, a6, v12, (unsigned int)v10, v13);
++qword_12A0;
longjmp(ctest_err, 1);
}
++v8;
v11 = 1;
if ( v10 == v9 )
break;
++v10;
}
qword_1298 = v8;
}
++qword_12A8;
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, int a2, __int64 a3, unsigned int a4, const char *a5, unsigned int a6)
{
__int64 v8; // rdx
__int64 v9; // r9
__int64 v10; // rax
char v11; // r11
unsigned __int8 v12; // cl
unsigned __int8 v13; // si

if ( a2 != a4 )
{
++_gcov0_assert_data;
func8("%s:%d expected %d bytes, got %d", a5, a6, (unsigned int)a2, a4);
++qword_1288;
longjmp(ctest_err, 1);
}
if ( a2 > 0 )
{
v8 = qword_1298;
v9 = (unsigned int)(a2 - 1);
v10 = 0LL;
v11 = 0;
while ( 1 )
{
v12 = *(_BYTE *)(a1 + v10);
v13 = *(_BYTE *)(a3 + v10);
if ( v12 != v13 )
{
if ( v11 )
qword_1298 = v8;
++qword_1290;
func8("%s:%d expected 0x%02x at offset %d got 0x%02x", a5, a6, v12, (unsigned int)v10, v13);
++qword_12A0;
longjmp(ctest_err, 1);
}
++v8;
v11 = 1;
if ( v10 == v9 )
break;
++v10;
}
qword_1298 = v8;
}
++qword_12A8;
}

original_code:
void assert_data(const unsigned char* exp, int expsize,
                 const unsigned char* real, int realsize,
                 const char* caller, int line) {
    int i;
    if (expsize != realsize) {
        CTEST_ERR("%s:%d  expected %d bytes, got %d", caller, line, expsize, realsize);
        longjmp(ctest_err, 1);
    }
    for (i=0; i<expsize; i++) {
        if (exp[i] != real[i]) {
            CTEST_ERR("%s:%d expected 0x%02x at offset %d got 0x%02x",
                caller, line, exp[i], i, real[i]);
            longjmp(ctest_err, 1);
        }
    }
}

canonical_original_code:
void assert_data(unsigned char *exp, int expsize, unsigned char *real, int realsize, char *caller, int line) {
    int i;
    if (expsize != realsize) {
        CTEST_ERR("%s:%d  expected %d bytes, got %d", caller, line, expsize, realsize);
        longjmp(ctest_err, 1);
    }
    for (i=0; i<expsize; i++) {
        if (exp[i] != real[i]) {
            CTEST_ERR("%s:%d expected 0x%02x at offset %d got 0x%02x",
                caller, line, exp[i], i, real[i]);
            longjmp(ctest_err, 1);
        }
    }
}

variable_types:
exp
unsigned char *

variable_types: expsize int

variable_types:
real
unsigned char *

variable_types: realsize int

variable_types: i int


decompiled_code:
void __fastcall assert_equal(__int64 a1, __int64 a2, const char *a3, unsigned int a4)
{
if ( a1 != a2 )
{
++_gcov0_assert_equal;
CTEST_ERR("%s:%d expected %ld, got %ld", a3, a4, a1, a2);
++qword_12C0;
longjmp(ctest_err, 1);
}
++qword_12B8;
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, __int64 a2, const char *a3, unsigned int a4)
{
if ( a1 != a2 )
{
++_gcov0_assert_equal;
func8("%s:%d expected %ld, got %ld", a3, a4, a1, a2);
++qword_12C0;
longjmp(ctest_err, 1);
}
++qword_12B8;
}

original_code:
void assert_equal(long exp, long real, const char* caller, int line) {
    if (exp != real) {
        CTEST_ERR("%s:%d  expected %ld, got %ld", caller, line, exp, real);
        longjmp(ctest_err, 1);
    }
}

canonical_original_code:
void assert_equal(long exp, long real, char *caller, int line) {
    if (exp != real) {
        CTEST_ERR("%s:%d  expected %ld, got %ld", caller, line, exp, real);
        longjmp(ctest_err, 1);
    }
}

variable_types: exp long

variable_types: real long


decompiled_code:
void __fastcall assert_not_equal(__int64 a1, __int64 a2, const char *a3, unsigned int a4)
{
if ( a1 == a2 )
{
++_gcov0_assert_not_equal;
CTEST_ERR("%s:%d should not be %ld", a3, a4, a2);
++qword_12E0;
longjmp(ctest_err, 1);
}
++qword_12D8;
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, __int64 a2, const char *a3, unsigned int a4)
{
if ( a1 == a2 )
{
++_gcov0_assert_not_equal;
func8("%s:%d should not be %ld", a3, a4, a2);
++qword_12E0;
longjmp(ctest_err, 1);
}
++qword_12D8;
}

original_code:
void assert_not_equal(long exp, long real, const char* caller, int line) {
    if ((exp) == (real)) {
        CTEST_ERR("%s:%d  should not be %ld", caller, line, real);
        longjmp(ctest_err, 1);
    }
}

canonical_original_code:
void assert_not_equal(long exp, long real, char *caller, int line) {
    if ((exp) == (real)) {
        CTEST_ERR("%s:%d  should not be %ld", caller, line, real);
        longjmp(ctest_err, 1);
    }
}


decompiled_code:
void __fastcall assert_null(__int64 a1, const char *a2, __int64 a3)
{
if ( a1 )
{
++_gcov0_assert_null;
CTEST_ERR("%s:%d should be NULL", a2, a3);
++qword_1300;
longjmp(ctest_err, 1);
}
++qword_12F8;
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, const char *a2, __int64 a3)
{
if ( a1 )
{
++_gcov0_assert_null;
func8("%s:%d should be NULL", a2, a3);
++qword_1300;
longjmp(ctest_err, 1);
}
++qword_12F8;
}

original_code:
void assert_null(void* real, const char* caller, int line) {
    if ((real) != ((void *)0)) {
        CTEST_ERR("%s:%d  should be NULL", caller, line);
        longjmp(ctest_err, 1);
    }
}

canonical_original_code:
void assert_null(void *real, char *caller, int line) {
    if ((real) != ((void *)0)) {
        CTEST_ERR("%s:%d  should be NULL", caller, line);
        longjmp(ctest_err, 1);
    }
}

variable_types:
real
void *


decompiled_code:
void __fastcall assert_not_null(__int64 a1, const char *a2, __int64 a3)
{
if ( !a1 )
{
++_gcov0_assert_not_null;
CTEST_ERR("%s:%d should not be NULL", a2, a3);
++qword_1320;
longjmp(ctest_err, 1);
}
++qword_1318;
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, const char *a2, __int64 a3)
{
if ( !a1 )
{
++_gcov0_assert_not_null;
func8("%s:%d should not be NULL", a2, a3);
++qword_1320;
longjmp(ctest_err, 1);
}
++qword_1318;
}

original_code:
void assert_not_null(void* real, const char* caller, int line) {
    if (real == ((void *)0)) {
        CTEST_ERR("%s:%d  should not be NULL", caller, line);
        longjmp(ctest_err, 1);
    }
}

canonical_original_code:
void assert_not_null(void *real, char *caller, int line) {
    if (real == ((void *)0)) {
        CTEST_ERR("%s:%d  should not be NULL", caller, line);
        longjmp(ctest_err, 1);
    }
}


decompiled_code:
void __fastcall assert_true(int a1, const char *a2, __int64 a3)
{
if ( !a1 )
{
++_gcov0_assert_true;
CTEST_ERR("%s:%d should be true", a2, a3);
++qword_1340;
longjmp(ctest_err, 1);
}
++qword_1338;
}

canonical_decompiled_code:
void __fastcall func15(int a1, const char *a2, __int64 a3)
{
if ( !a1 )
{
++_gcov0_assert_true;
func8("%s:%d should be true", a2, a3);
++qword_1340;
longjmp(ctest_err, 1);
}
++qword_1338;
}

original_code:
void assert_true(int real, const char* caller, int line) {
    if ((real) == 0) {
        CTEST_ERR("%s:%d  should be true", caller, line);
        longjmp(ctest_err, 1);
    }
}

canonical_original_code:
void assert_true(int real, char *caller, int line) {
    if ((real) == 0) {
        CTEST_ERR("%s:%d  should be true", caller, line);
        longjmp(ctest_err, 1);
    }
}

variable_types: real int


decompiled_code:
void __fastcall assert_false(int a1, const char *a2, __int64 a3)
{
if ( a1 )
{
++_gcov0_assert_false;
CTEST_ERR("%s:%d should be false", a2, a3);
++qword_1360;
longjmp(ctest_err, 1);
}
++qword_1358;
}

canonical_decompiled_code:
void __fastcall func16(int a1, const char *a2, __int64 a3)
{
if ( a1 )
{
++_gcov0_assert_false;
func8("%s:%d should be false", a2, a3);
++qword_1360;
longjmp(ctest_err, 1);
}
++qword_1358;
}

original_code:
void assert_false(int real, const char* caller, int line) {
    if ((real) != 0) {
        CTEST_ERR("%s:%d  should be false", caller, line);
        longjmp(ctest_err, 1);
    }
}

canonical_original_code:
void assert_false(int real, char *caller, int line) {
    if ((real) != 0) {
        CTEST_ERR("%s:%d  should be false", caller, line);
        longjmp(ctest_err, 1);
    }
}


decompiled_code:
void __fastcall __noreturn assert_fail(const char *a1, unsigned int a2)
{
++_gcov0_assert_fail;
CTEST_ERR("%s:%d shouldn't come here", a1, a2);
++qword_1378;
longjmp(ctest_err, 1);
}

canonical_decompiled_code:
void __fastcall __noreturn func17(const char *a1, unsigned int a2)
{
++_gcov0_assert_fail;
func8("%s:%d shouldn't come here", a1, a2);
++qword_1378;
longjmp(ctest_err, 1);
}

original_code:
void assert_fail(const char* caller, int line) {
    CTEST_ERR("%s:%d  shouldn't come here", caller, line);
    longjmp(ctest_err, 1);
}

canonical_original_code:
void assert_fail(char *caller, int line) {
    CTEST_ERR("%s:%d  shouldn't come here", caller, line);
    longjmp(ctest_err, 1);
}


decompiled_code:
__int64 __fastcall ctest_main(int a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rax
char **v4; // rbx
__int64 v5; // rax
char **v6; // rdx
__int64 v7; // rcx
char **v8; // rdi
int v9; // eax
void (__fastcall *v10)(_QWORD); // rax
void (__fastcall *v11)(_QWORD); // rax
__suseconds_t v12; // rax
const char *v13; // rbx
char **v15; // [rsp+0h] [rbp-68h]
__suseconds_t v16; // [rsp+8h] [rbp-60h]
char s[88]; // [rsp+10h] [rbp-58h] BYREF

++_gcov0_ctest_main;
if ( a1 == 2 )
{
++qword_13C8;
suite_name = *(char **)(a2 + 8);
filter_5 = (__int64 (*)(void))suite_filter;
}
v2 = isatty(1);
++qword_13D0;
color_output = v2;
v16 = getCurrentTime();
++qword_13D8;
v3 = qword_13E0;
v4 = _ctest_suite_test;
if ( LODWORD(_ctest_suite_test[-1]) == -559038737 )
{
do
{
++v3;
v4 -= 8;
}
while ( *((_DWORD *)v4 - 2) == -559038737 );
qword_13E0 = v3;
if ( LODWORD(_ctest_suite_test[15]) != -559038737 )
{
v6 = _ctest_suite_test;
goto LABEL_9;
}
LABEL_6:
v5 = qword_13E8 + 1;
v6 = _ctest_suite_test;
do
{
v7 = v5;
v6 += 8;
++v5;
}
while ( *((_DWORD *)v6 + 30) == -559038737 );
qword_13E8 = v7;
LABEL_9:
v15 = v6 + 8;
test_6 = (__int64)v4;
if ( v6 + 8 == v4 )
goto LABEL_17;
goto LABEL_10;
}
if ( LODWORD(_ctest_suite_test[15]) == -559038737 )
{
v4 = _ctest_suite_test;
goto LABEL_6;
}
test_6 = (__int64)_ctest_suite_test;
v15 = &_ctest_suite_test[8];
v4 = _ctest_suite_test;
LABEL_10:
v8 = v4;
do
{
if ( v8 == _ctest_suite_test )
{
++qword_13F0;
}
else
{
v9 = filter_5();
++qword_13F8;
if ( v9 )
{
++qword_1400;
++total_4;
}
}
v8 = (char **)(test_6 + 64);
test_6 = (__int64)v8;
}
while ( v8 != v15 );
LABEL_17:
test_6 = (__int64)v4;
while ( (char **)test_6 != v15 )
{
if ( (char **)test_6 == _ctest_suite_test )
{
++qword_1408;
}
else
{
++qword_1410;
if ( (unsigned int)filter_5() )
{
++qword_1418;
ctest_errorbuffer = 0;
ctest_errorsize = 4095LL;
ctest_errormsg = &ctest_errorbuffer;
printf(
"TEST %d/%d %s:%s ",
(unsigned int)index_3,
(unsigned int)total_4,
*(const char **)test_6,
*(const char **)(test_6 + 8));
++qword_1420;
fflush(stdout);
++qword_1428;
if ( *(_DWORD *)(test_6 + 24) )
{
++qword_1430;
color_print("\x1B[01;33m", "[SKIPPED]");
++num_skip_2;
}
else
{
if ( setjmp(ctest_err) )
{
++qword_1440;
color_print("\x1B[01;31m", "[FAIL]");
++qword_1488;
++num_fail_0;
}
else
{
++qword_1438;
v10 = *(void (__fastcall **)(_QWORD))(test_6 + 40);
if ( v10 )
{
++qword_1448;
v10(*(_QWORD *)(test_6 + 32));
}
if ( *(_QWORD *)(test_6 + 32) )
{
++qword_1450;
(*(void (**)(void))(test_6 + 16))();
}
else
{
++qword_1458;
(*(void (**)(void))(test_6 + 16))();
++qword_1460;
}
v11 = *(void (__fastcall **)(_QWORD))(test_6 + 48);
if ( v11 )
{
++qword_1468;
v11(*(_QWORD *)(test_6 + 32));
++qword_1478;
}
else
{
++qword_1470;
}
puts("[OK]");
++qword_1480;
++num_ok_1;
}
if ( ctest_errorsize != 4095 )
{
++qword_1490;
printf("%s", &ctest_errorbuffer);
++qword_1498;
}
}
++index_3;
++qword_14A0;
}
}
test_6 += 64LL;
++qword_14A8;
}
++qword_14B0;
v12 = getCurrentTime();
++qword_14B8;
v13 = "\x1B[01;31m";
if ( !num_fail_0 )
{
++qword_14C0;
v13 = "\x1B[0;32m";
}
sprintf(
s,
"RESULTS: %d tests (%d ok, %d failed, %d skipped) ran in %lld ms",
(unsigned int)total_4,
(unsigned int)num_ok_1,
(unsigned int)num_fail_0,
(unsigned int)num_skip_2,
(v12 - v16) / 0x3E8uLL);
++qword_14C8;
color_print(v13, s);
++qword_14D0;
return (unsigned int)num_fail_0;
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rax
char **v4; // rbx
__int64 v5; // rax
char **v6; // rdx
__int64 v7; // rcx
char **v8; // rdi
int v9; // eax
void (__fastcall *v10)(_QWORD); // rax
void (__fastcall *v11)(_QWORD); // rax
__suseconds_t v12; // rax
const char *v13; // rbx
char **v15; // [rsp+0h] [rbp-68h]
__suseconds_t v16; // [rsp+8h] [rbp-60h]
char s[88]; // [rsp+10h] [rbp-58h] BYREF

++_gcov0_ctest_main;
if ( a1 == 2 )
{
++qword_13C8;
suite_name = *(char **)(a2 + 8);
filter_5 = (__int64 (*)(void))suite_filter;
}
v2 = isatty(1);
++qword_13D0;
color_output = v2;
v16 = func6();
++qword_13D8;
v3 = qword_13E0;
v4 = _ctest_suite_test;
if ( LODWORD(_ctest_suite_test[-1]) == -559038737 )
{
do
{
++v3;
v4 -= 8;
}
while ( *((_DWORD *)v4 - 2) == -559038737 );
qword_13E0 = v3;
if ( LODWORD(_ctest_suite_test[15]) != -559038737 )
{
v6 = _ctest_suite_test;
goto LABEL_9;
}
LABEL_6:
v5 = qword_13E8 + 1;
v6 = _ctest_suite_test;
do
{
v7 = v5;
v6 += 8;
++v5;
}
while ( *((_DWORD *)v6 + 30) == -559038737 );
qword_13E8 = v7;
LABEL_9:
v15 = v6 + 8;
test_6 = (__int64)v4;
if ( v6 + 8 == v4 )
goto LABEL_17;
goto LABEL_10;
}
if ( LODWORD(_ctest_suite_test[15]) == -559038737 )
{
v4 = _ctest_suite_test;
goto LABEL_6;
}
test_6 = (__int64)_ctest_suite_test;
v15 = &_ctest_suite_test[8];
v4 = _ctest_suite_test;
LABEL_10:
v8 = v4;
do
{
if ( v8 == _ctest_suite_test )
{
++qword_13F0;
}
else
{
v9 = filter_5();
++qword_13F8;
if ( v9 )
{
++qword_1400;
++total_4;
}
}
v8 = (char **)(test_6 + 64);
test_6 = (__int64)v8;
}
while ( v8 != v15 );
LABEL_17:
test_6 = (__int64)v4;
while ( (char **)test_6 != v15 )
{
if ( (char **)test_6 == _ctest_suite_test )
{
++qword_1408;
}
else
{
++qword_1410;
if ( (unsigned int)filter_5() )
{
++qword_1418;
ctest_errorbuffer = 0;
ctest_errorsize = 4095LL;
ctest_errormsg = &ctest_errorbuffer;
printf(
"TEST %d/%d %s:%s ",
(unsigned int)index_3,
(unsigned int)total_4,
*(const char **)test_6,
*(const char **)(test_6 + 8));
++qword_1420;
fflush(stdout);
++qword_1428;
if ( *(_DWORD *)(test_6 + 24) )
{
++qword_1430;
func4("\x1B[01;33m", "[SKIPPED]");
++num_skip_2;
}
else
{
if ( setjmp(ctest_err) )
{
++qword_1440;
func4("\x1B[01;31m", "[FAIL]");
++qword_1488;
++num_fail_0;
}
else
{
++qword_1438;
v10 = *(void (__fastcall **)(_QWORD))(test_6 + 40);
if ( v10 )
{
++qword_1448;
v10(*(_QWORD *)(test_6 + 32));
}
if ( *(_QWORD *)(test_6 + 32) )
{
++qword_1450;
(*(void (**)(void))(test_6 + 16))();
}
else
{
++qword_1458;
(*(void (**)(void))(test_6 + 16))();
++qword_1460;
}
v11 = *(void (__fastcall **)(_QWORD))(test_6 + 48);
if ( v11 )
{
++qword_1468;
v11(*(_QWORD *)(test_6 + 32));
++qword_1478;
}
else
{
++qword_1470;
}
puts("[OK]");
++qword_1480;
++num_ok_1;
}
if ( ctest_errorsize != 4095 )
{
++qword_1490;
printf("%s", &ctest_errorbuffer);
++qword_1498;
}
}
++index_3;
++qword_14A0;
}
}
test_6 += 64LL;
++qword_14A8;
}
++qword_14B0;
v12 = func6();
++qword_14B8;
v13 = "\x1B[01;31m";
if ( !num_fail_0 )
{
++qword_14C0;
v13 = "\x1B[0;32m";
}
sprintf(
s,
"RESULTS: %d tests (%d ok, %d failed, %d skipped) ran in %lld ms",
(unsigned int)total_4,
(unsigned int)num_ok_1,
(unsigned int)num_fail_0,
(unsigned int)num_skip_2,
(v12 - v16) / 0x3E8uLL);
++qword_14C8;
func4(v13, s);
++qword_14D0;
return (unsigned int)num_fail_0;
}

original_code:
int ctest_main(int argc, const char *argv[])
{
    static int total = 0;
    static int num_ok = 0;
    static int num_fail = 0;
    static int num_skip = 0;
    static int index = 1;
    static filter_func filter = suite_all;
    if (argc == 2) {
        suite_name = argv[1];
        filter = suite_filter;
    }
    color_output = isatty(1);
    uint64_t t1 = getCurrentTime();
    struct ctest* ctest_begin = &__ctest_suite_test;
    struct ctest* ctest_end = &__ctest_suite_test;
    while (1) {
        struct ctest* t = ctest_begin-1;
        if (t->magic != (0xdeadbeef)) break;
        ctest_begin--;
    }
    while (1) {
        struct ctest* t = ctest_end+1;
        if (t->magic != (0xdeadbeef)) break;
        ctest_end++;
    }
    ctest_end++;
    static struct ctest* test;
    for (test = ctest_begin; test != ctest_end; test++) {
        if (test == &__ctest_suite_test) continue;
        if (filter(test)) total++;
    }
    for (test = ctest_begin; test != ctest_end; test++) {
        if (test == &__ctest_suite_test) continue;
        if (filter(test)) {
            ctest_errorbuffer[0] = 0;
            ctest_errorsize = 4096 -1;
            ctest_errormsg = ctest_errorbuffer;
            printf("TEST %d/%d %s:%s ", index, total, test->ssname, test->ttname);
            fflush(stdout);
            if (test->skip) {
                color_print("\033[01;33m", "[SKIPPED]");
                num_skip++;
            } else {
                int result = _setjmp (ctest_err);
                if (result == 0) {
                    if (test->setup) test->setup(test->data);
                    if (test->data)
                      test->run(test->data);
                    else
                      test->run();
                    if (test->teardown) test->teardown(test->data);
                    printf("[OK]\n");
                    num_ok++;
                } else {
                    color_print("\033[01;31m", "[FAIL]");
                    num_fail++;
                }
                if (ctest_errorsize != 4096 -1) printf("%s", ctest_errorbuffer);
            }
            index++;
        }
    }
    uint64_t t2 = getCurrentTime();
    const char* color = (num_fail) ? "\033[01;31m" : "\033[0;32m";
    char results[80];
    sprintf(results, "RESULTS: %d tests (%d ok, %d failed, %d skipped) ran in %lld ms", total, num_ok, num_fail, num_skip, (t2 - t1)/1000);
    color_print(color, results);
    return num_fail;
}

canonical_original_code:
int ctest_main(int argc, char *argv[])
{
    static int total = 0;
    static int num_ok = 0;
    static int num_fail = 0;
    static int num_skip = 0;
    static int index = 1;
    static int (*filter)(struct ctest *) = suite_all;
    if (argc == 2) {
        suite_name = argv[1];
        filter = suite_filter;
    }
    color_output = isatty(1);
    unsigned long t1 = getCurrentTime();
    struct ctest *ctest_begin = &__ctest_suite_test;
    struct ctest *ctest_end = &__ctest_suite_test;
    while (1) {
        struct ctest *t = ctest_begin-1;
        if (t->magic != (0xdeadbeef)) break;
        ctest_begin--;
    }
    while (1) {
        struct ctest *t = ctest_end+1;
        if (t->magic != (0xdeadbeef)) break;
        ctest_end++;
    }
    ctest_end++;
    static struct ctest *test;
    for (test = ctest_begin; test != ctest_end; test++) {
        if (test == &__ctest_suite_test) continue;
        if (filter(test)) total++;
    }
    for (test = ctest_begin; test != ctest_end; test++) {
        if (test == &__ctest_suite_test) continue;
        if (filter(test)) {
            ctest_errorbuffer[0] = 0;
            ctest_errorsize = 4096 -1;
            ctest_errormsg = ctest_errorbuffer;
            printf("TEST %d/%d %s:%s ", index, total, test->ssname, test->ttname);
            fflush(stdout);
            if (test->skip) {
                color_print("\033[01;33m", "[SKIPPED]");
                num_skip++;
            } else {
                int result = _setjmp (ctest_err);
                if (result == 0) {
                    if (test->setup) test->setup(test->data);
                    if (test->data)
                      test->run(test->data);
                    else
                      test->run();
                    if (test->teardown) test->teardown(test->data);
                    printf("[OK]\n");
                    num_ok++;
                } else {
                    color_print("\033[01;31m", "[FAIL]");
                    num_fail++;
                }
                if (ctest_errorsize != 4096 -1) printf("%s", ctest_errorbuffer);
            }
            index++;
        }
    }
    unsigned long t2 = getCurrentTime();
    char *color = (num_fail) ? "\033[01;31m" : "\033[0;32m";
    char results[80];
    sprintf(results, "RESULTS: %d tests (%d ok, %d failed, %d skipped) ran in %lld ms", total, num_ok, num_fail, num_skip, (t2 - t1)/1000);
    color_print(color, results);
    return num_fail;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: total int

variable_types: index int

variable_types: int (*)(struct ctest { char *ssname; char *ttname; void (*run)(); int skip; void *data; void (*setup)(void *); void (*teardown)(void *); unsigned int magic; } *)

variable_types: result int

variable_types:
color
char *

variable_types:
results
char [80]


main

canonical_name: main

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

++_gcov0_main;
result = ctest_main(argc, (__int64)argv);
++qword_14E8;
return result;
}

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

++_gcov0_main;
result = func18(argc, (__int64)argv);
++qword_14E8;
return result;
}

original_code:
int main(int argc, const char *argv[])
{
    return ctest_main(argc, argv);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    return ctest_main(argc, argv);
}


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

++_gcov0_nosetup_teardown;
result = CTEST_LOG("%s()", "nosetup_teardown");
++qword_1008;
return result;
}

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

++_gcov0_nosetup_teardown;
result = CTEST_LOG("%s()", "nosetup_teardown");
++qword_1008;
return result;
}

original_code:
void __attribute__ ((weak)) nosetup_teardown(struct nosetup_data* data) {
    CTEST_LOG("%s()", __func__);
}

canonical_original_code:
void nosetup_teardown(struct nosetup_data *data) {
    CTEST_LOG("%s()", __func__);
}

variable_types:
data
struct nosetup_data { int value; } *


decompiled_code:
void *__fastcall memtest_setup(const void **a1)
{
void *result; // rax

++_gcov0_memtest_setup;
CTEST_LOG("%s() data=%p buffer=%p", "memtest_setup", a1, *a1);
++qword_F58;
result = malloc(0x400uLL);
*a1 = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func16(const void **a1)
{
void *result; // rax

++_gcov0_memtest_setup;
CTEST_LOG("%s() data=%p buffer=%p", "memtest_setup", a1, *a1);
++qword_F58;
result = malloc(0x400uLL);
*a1 = result;
return result;
}

original_code:
void __attribute__ ((weak)) memtest_setup(struct memtest_data* data) {
    CTEST_LOG("%s() data=%p buffer=%p", __func__, data, data->buffer);
    data->buffer = (unsigned char*)malloc(1024);
}

canonical_original_code:
void memtest_setup(struct memtest_data *data) {
    CTEST_LOG("%s() data=%p buffer=%p", __func__, data, data->buffer);
    data->buffer = (unsigned char *)malloc(1024);
}

variable_types: struct memtest_data { unsigned char *buffer; } *


decompiled_code:
void __fastcall memtest_teardown(const void **a1)
{
void *v1; // rdi

++_gcov0_memtest_teardown;
CTEST_LOG("%s() data=%p buffer=%p", "memtest_teardown", a1, *a1);
v1 = (void *)*a1;
if ( v1 )
{
free(v1);
++qword_F70;
}
else
{
++qword_F68;
}
}

canonical_decompiled_code:
void __fastcall func17(const void **a1)
{
void *v1; // rdi

++_gcov0_memtest_teardown;
CTEST_LOG("%s() data=%p buffer=%p", "memtest_teardown", a1, *a1);
v1 = (void *)*a1;
if ( v1 )
{
free(v1);
++qword_F70;
}
else
{
++qword_F68;
}
}

original_code:
void __attribute__ ((weak)) memtest_teardown(struct memtest_data* data) {
    CTEST_LOG("%s() data=%p buffer=%p", __func__, data, data->buffer);
    if (data->buffer) free(data->buffer);
}

canonical_original_code:
void memtest_teardown(struct memtest_data *data) {
    CTEST_LOG("%s() data=%p buffer=%p", __func__, data, data->buffer);
    if (data->buffer) free(data->buffer);
}

user_defined_types: struct memtest_data { unsigned char *buffer; }


decompiled_code:
void __noreturn fail_setup()
{
++_gcov0_fail_setup;
assert_fail("mytests.c", 61LL);
}

canonical_decompiled_code:
void __noreturn func20()
{
++_gcov0_fail_setup;
assert_fail("mytests.c", 61LL);
}

original_code:
void __attribute__ ((weak)) fail_setup(struct fail_data* data) {
    assert_fail("mytests.c", 61);
}

canonical_original_code:
void fail_setup(struct fail_data *data) {
    assert_fail("mytests.c", 61);
}

variable_types:
data
struct fail_data {  } *


repo: GooseYArd/euler

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

v3 = ST_CreateTree(&unk_30, 3LL, envp);
ST_PrintTree(v3);
return 0;
}

original_code:
int main()
{
 unsigned long position;
 SUFFIX_TREE* tree = ST_CreateTree("mmm", 3);
 ST_PrintTree(tree);
}

canonical_original_code:
int main()
{
 unsigned long position;
 struct SUFFIXTREE *tree = ST_CreateTree("mmm", 3);
 ST_PrintTree(tree);
}

variable_types:
position
unsigned long

variable_types: struct SUFFIXTREE { unsigned long e; char *tree_string; unsigned long length; struct SUFFIXTREENODE { struct SUFFIXTREENODE *sons; struct SUFFIXTREENODE *right_sibling; struct SUFFIXTREENODE *left_sibling; struct SUFFIXTREENODE *father; struct SUFFIXTREENODE *suffix_link; unsigned long path_position; unsigned long edge_label_start; unsigned long edge_label_end; } *root; } *

user_defined_types: struct SUFFIXTREE { unsigned long e; char *tree_string; unsigned long length; struct SUFFIXTREENODE *root; }


smBufferedInit

original_code:
SM_STATUS smBufferedInit(BufferedMotionAxis *newAxis, smbus handle, smaddr deviceAddress, smint32 sampleRate, smint16 readParamAddr, smuint8 readDataLength )
{
    if(sampleRate<1 || sampleRate>2500)
        return recordStatus(handle,16);
    newAxis->initialized=0;
    newAxis->bushandle=handle;
    newAxis->samplerate=sampleRate;
    newAxis->deviceAddress=deviceAddress;
    newAxis->readParamAddr=readParamAddr;
    newAxis->readParamLength=readDataLength;
    newAxis->readParamInitialized=0;
    newAxis->numberOfDiscardableReturnDataPackets=0;
    newAxis->driveClock=0;
    newAxis->bufferFill=0;
    newAxis->numberOfPendingReadPackets=0;
    newAxis->driveFlagsModifiedAtInit=0;
    newAxis->deviceCapabilityFlags1=0;
    newAxis->deviceCapabilityFlags2=0;
    smSetParameter( newAxis->bushandle, newAxis->deviceAddress, 554,4);
    smRead2Parameters(newAxis->bushandle,newAxis->deviceAddress,6,&newAxis->bufferLength,3,&newAxis->smProtocolVersion);
    newAxis->bufferFreeBytes=newAxis->bufferLength;
    if(smRead1Parameter(handle,deviceAddress,567,&newAxis->driveFlagsBeforeInit)!=1)
        return getCumulativeStatus(handle);
    if(newAxis->smProtocolVersion>=28)
    {
        smRead2Parameters(newAxis->bushandle,newAxis->deviceAddress,6006,&newAxis->deviceCapabilityFlags1,6007,&newAxis->deviceCapabilityFlags2);
    }
    if(newAxis->deviceCapabilityFlags1&(1<<(20)))
    {
        smSetParameter(handle,deviceAddress,16,1);
    }
    else
    {
        if(sampleRate<2500)
        {
            smSetParameter(handle,deviceAddress,567,newAxis->driveFlagsBeforeInit|(1<<(11)));
            newAxis->driveFlagsModifiedAtInit=1;
        }
    }
    smSetParameter(handle,deviceAddress,8,10000/2500);
    smRead1Parameter(handle,deviceAddress,800,&newAxis->driveAccelerationBeforeInit);
    smSetParameter(handle,deviceAddress,800,32767);
    smSetParameter(handle,deviceAddress,8,10000/sampleRate);
    if(getCumulativeStatus(handle)==1)
        newAxis->initialized=1;
    return getCumulativeStatus(handle);
}

canonical_original_code:
int smBufferedInit(struct _BufferedMotionAxis *newAxis, long handle, unsigned char deviceAddress, int sampleRate, short readParamAddr, unsigned char readDataLength)
{
    if(sampleRate<1 || sampleRate>2500)
        return recordStatus(handle,16);
    newAxis->initialized=0;
    newAxis->bushandle=handle;
    newAxis->samplerate=sampleRate;
    newAxis->deviceAddress=deviceAddress;
    newAxis->readParamAddr=readParamAddr;
    newAxis->readParamLength=readDataLength;
    newAxis->readParamInitialized=0;
    newAxis->numberOfDiscardableReturnDataPackets=0;
    newAxis->driveClock=0;
    newAxis->bufferFill=0;
    newAxis->numberOfPendingReadPackets=0;
    newAxis->driveFlagsModifiedAtInit=0;
    newAxis->deviceCapabilityFlags1=0;
    newAxis->deviceCapabilityFlags2=0;
    smSetParameter( newAxis->bushandle, newAxis->deviceAddress, 554,4);
    smRead2Parameters(newAxis->bushandle,newAxis->deviceAddress,6,&newAxis->bufferLength,3,&newAxis->smProtocolVersion);
    newAxis->bufferFreeBytes=newAxis->bufferLength;
    if(smRead1Parameter(handle,deviceAddress,567,&newAxis->driveFlagsBeforeInit)!=1)
        return getCumulativeStatus(handle);
    if(newAxis->smProtocolVersion>=28)
    {
        smRead2Parameters(newAxis->bushandle,newAxis->deviceAddress,6006,&newAxis->deviceCapabilityFlags1,6007,&newAxis->deviceCapabilityFlags2);
    }
    if(newAxis->deviceCapabilityFlags1&(1<<(20)))
    {
        smSetParameter(handle,deviceAddress,16,1);
    }
    else
    {
        if(sampleRate<2500)
        {
            smSetParameter(handle,deviceAddress,567,newAxis->driveFlagsBeforeInit|(1<<(11)));
            newAxis->driveFlagsModifiedAtInit=1;
        }
    }
    smSetParameter(handle,deviceAddress,8,10000/2500);
    smRead1Parameter(handle,deviceAddress,800,&newAxis->driveAccelerationBeforeInit);
    smSetParameter(handle,deviceAddress,800,32767);
    smSetParameter(handle,deviceAddress,8,10000/sampleRate);
    if(getCumulativeStatus(handle)==1)
        newAxis->initialized=1;
    return getCumulativeStatus(handle);
}

variable_types: struct _BufferedMotionAxis { char initialized; char readParamInitialized; int numberOfDiscardableReturnDataPackets; int numberOfPendingReadPackets; long bushandle; unsigned char deviceAddress; int samplerate; short readParamAddr; unsigned char readParamLength; int driveFlagsBeforeInit; char driveFlagsModifiedAtInit; int driveAccelerationBeforeInit; unsigned short driveClock; int bufferLength; int bufferFreeBytes; int bufferFill; int smProtocolVersion; int deviceCapabilityFlags1; int deviceCapabilityFlags2; } *

variable_types: handle long

variable_types:
deviceAddress
unsigned char

variable_types: sampleRate int

variable_types: readParamAddr short

variable_types:
readDataLength
unsigned char


smBufferedRunAndSyncClocks

decompiled_code:
__int64 __fastcall smBufferedRunAndSyncClocks(__int64 a1)
{
return smGetBufferClock(*(_QWORD *)(a1 + 16), *(unsigned __int8 *)(a1 + 24), a1 + 48);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return smGetBufferClock(*(_QWORD *)(a1 + 16), *(unsigned __int8 *)(a1 + 24), a1 + 48);
}

original_code:
SM_STATUS smBufferedRunAndSyncClocks(BufferedMotionAxis *axis)
{
    return smGetBufferClock( axis->bushandle, axis->deviceAddress, &axis->driveClock );
}

canonical_original_code:
int smBufferedRunAndSyncClocks(struct _BufferedMotionAxis *axis)
{
    return smGetBufferClock( axis->bushandle, axis->deviceAddress, &axis->driveClock );
}

user_defined_types: struct _BufferedMotionAxis { char initialized; char readParamInitialized; int numberOfDiscardableReturnDataPackets; int numberOfPendingReadPackets; long bushandle; unsigned char deviceAddress; int samplerate; short readParamAddr; unsigned char readParamLength; int driveFlagsBeforeInit; char driveFlagsModifiedAtInit; int driveAccelerationBeforeInit; unsigned short driveClock; int bufferLength; int bufferFreeBytes; int bufferFill; int smProtocolVersion; int deviceCapabilityFlags1; int deviceCapabilityFlags2; }


smBufferedGetFree

decompiled_code:
__int64 __fastcall smBufferedGetFree(__int64 a1, int *a2)
{
int v3; // ecx
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)smRead1Parameter(*(_QWORD *)(a1 + 16), *(unsigned __int8 *)(a1 + 24), 6LL, v4) == 1 )
{
v3 = v4[0];
*(_DWORD *)(a1 + 56) = v4[0];
*(_DWORD *)(a1 + 60) = 100 * (*(_DWORD *)(a1 + 52) - v3) / *(_DWORD *)(a1 + 52);
*a2 = v3;
}
else
{
*a2 = 0;
}
return getCumulativeStatus(*(_QWORD *)(a1 + 16));
}

original_code:
SM_STATUS smBufferedGetFree(BufferedMotionAxis *axis, smint32 *numBytesFree )
{
    smint32 freebytes;
    if(smRead1Parameter(axis->bushandle,axis->deviceAddress,6,&freebytes)!=1)
    {
        *numBytesFree=0;
        return getCumulativeStatus(axis->bushandle);
    }
    axis->bufferFreeBytes=freebytes;
    axis->bufferFill=100*(axis->bufferLength-freebytes)/axis->bufferLength;
    *numBytesFree=freebytes;
    return getCumulativeStatus(axis->bushandle);
}

canonical_original_code:
int smBufferedGetFree(struct _BufferedMotionAxis *axis, int *numBytesFree)
{
    int freebytes;
    if(smRead1Parameter(axis->bushandle,axis->deviceAddress,6,&freebytes)!=1)
    {
        *numBytesFree=0;
        return getCumulativeStatus(axis->bushandle);
    }
    axis->bufferFreeBytes=freebytes;
    axis->bufferFill=100*(axis->bufferLength-freebytes)/axis->bufferLength;
    *numBytesFree=freebytes;
    return getCumulativeStatus(axis->bushandle);
}

variable_types:
numBytesFree
int *

variable_types: freebytes int


smBufferedGetMaxFillSize

decompiled_code:
__int64 __fastcall smBufferedGetMaxFillSize(__int64 a1, int a2)
{
int v2; // eax
int v3; // edx
int v4; // eax

v2 = 120;
if ( a2 <= 120 )
v2 = a2;
if ( *(_BYTE *)(a1 + 1) == 1 )
return (unsigned int)(v2 / 4);
v3 = v2 - 9;
v4 = v2 - 12;
if ( v4 < 0 )
v4 = v3;
return (unsigned int)(v4 >> 2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
int v2; // eax
int v3; // edx
int v4; // eax

v2 = 120;
if ( a2 <= 120 )
v2 = a2;
if ( *(_BYTE *)(a1 + 1) == 1 )
return (unsigned int)(v2 / 4);
v3 = v2 - 9;
v4 = v2 - 12;
if ( v4 < 0 )
v4 = v3;
return (unsigned int)(v4 >> 2);
}

original_code:
smint32 smBufferedGetMaxFillSize(BufferedMotionAxis *axis, smint32 numBytesFree )
{
    if(numBytesFree>120)
        numBytesFree=120;
    if(axis->readParamInitialized==1)
        return numBytesFree/4;
    else
        return (numBytesFree-2-3-2-3-2)/4;
}

canonical_original_code:
int smBufferedGetMaxFillSize(struct _BufferedMotionAxis *axis, int numBytesFree)
{
    if(numBytesFree>120)
        numBytesFree=120;
    if(axis->readParamInitialized==1)
        return numBytesFree/4;
    else
        return (numBytesFree-2-3-2-3-2)/4;
}

variable_types: numBytesFree int


smBufferedGetBytesConsumed

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

result = (unsigned int)(4 * a2 + 12);
if ( *(_BYTE *)(a1 + 1) == 1 )
result = (unsigned int)(4 * a2);
return result;
}

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

result = (unsigned int)(4 * a2 + 12);
if ( *(_BYTE *)(a1 + 1) == 1 )
result = (unsigned int)(4 * a2);
return result;
}

original_code:
smint32 smBufferedGetBytesConsumed(BufferedMotionAxis *axis, smint32 numFillPoints )
{
    if(axis->readParamInitialized==1)
        return numFillPoints*4;
    else
        return numFillPoints*4 +2+3+2+3+2;
}

canonical_original_code:
int smBufferedGetBytesConsumed(struct _BufferedMotionAxis *axis, int numFillPoints)
{
    if(axis->readParamInitialized==1)
        return numFillPoints*4;
    else
        return numFillPoints*4 +2+3+2+3+2;
}

variable_types: numFillPoints int


smBufferedFillAndReceive

decompiled_code:
__int64 __fastcall smBufferedFillAndReceive(__int64 a1, int a2, unsigned int *a3, _DWORD *a4, __int64 a5, int *a6)
{
int v8; // er15
unsigned int *v9; // rbp
int v10; // ebp
int v11; // eax
int v15; // [rsp+28h] [rbp-40h] BYREF
int v16[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v8 = 0;
if ( !*(_BYTE *)(a1 + 1) )
{
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 2LL, 9LL);
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 1LL, (unsigned int)*(__int16 *)(a1 + 32));
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 2LL, 10LL);
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 1LL, *(unsigned __int8 *)(a1 + 34));
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 2LL, 551LL);
*(_DWORD *)(a1 + 4) += 5;
*(_BYTE *)(a1 + 1) = 1;
v8 = 12;
}
if ( a2 > 0 )
{
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 0LL, *a3);
v8 += 4;
++*(_DWORD *)(a1 + 8);
}
if ( a2 > 1 )
{
v9 = a3 + 1;
do
{
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 0LL, *v9);
++*(_DWORD *)(a1 + 8);
++v9;
}
while ( v9 != &a3[a2 - 2 + 2] );
v8 += 4 * (a2 - 2) + 4;
}
smUploadCommandQueueToDeviceBuffer(*(_QWORD *)(a1 + 16), *(unsigned __int8 *)(a1 + 24));
smBytesReceived(*(_QWORD *)(a1 + 16), &v15);
if ( v15 <= 1 )
{
v10 = 0;
}
else
{
v10 = 0;
do
{
smGetQueuedSMCommandReturnValue(*(_QWORD *)(a1 + 16), v16);
smBytesReceived(*(_QWORD *)(a1 + 16), &v15);
v11 = *(_DWORD *)(a1 + 4);
if ( v11 > 0 )
{
*(_DWORD *)(a1 + 4) = v11 - 1;
}
else
{
*(_DWORD *)(a5 + 4LL * v10++) = v16[0];
--*(_DWORD *)(a1 + 8);
}
}
while ( v15 > 1 );
}
*a4 = v10;
*a6 = v8;
return getCumulativeStatus(*(_QWORD *)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, unsigned int *a3, _DWORD *a4, __int64 a5, int *a6)
{
int v8; // er15
unsigned int *v9; // rbp
int v10; // ebp
int v11; // eax
int v15; // [rsp+28h] [rbp-40h] BYREF
int v16[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v8 = 0;
if ( !*(_BYTE *)(a1 + 1) )
{
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 2LL, 9LL);
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 1LL, (unsigned int)*(__int16 *)(a1 + 32));
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 2LL, 10LL);
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 1LL, *(unsigned __int8 *)(a1 + 34));
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 2LL, 551LL);
*(_DWORD *)(a1 + 4) += 5;
*(_BYTE *)(a1 + 1) = 1;
v8 = 12;
}
if ( a2 > 0 )
{
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 0LL, *a3);
v8 += 4;
++*(_DWORD *)(a1 + 8);
}
if ( a2 > 1 )
{
v9 = a3 + 1;
do
{
smAppendSMCommandToQueue(*(_QWORD *)(a1 + 16), 0LL, *v9);
++*(_DWORD *)(a1 + 8);
++v9;
}
while ( v9 != &a3[a2 - 2 + 2] );
v8 += 4 * (a2 - 2) + 4;
}
smUploadCommandQueueToDeviceBuffer(*(_QWORD *)(a1 + 16), *(unsigned __int8 *)(a1 + 24));
smBytesReceived(*(_QWORD *)(a1 + 16), &v15);
if ( v15 <= 1 )
{
v10 = 0;
}
else
{
v10 = 0;
do
{
smGetQueuedSMCommandReturnValue(*(_QWORD *)(a1 + 16), v16);
smBytesReceived(*(_QWORD *)(a1 + 16), &v15);
v11 = *(_DWORD *)(a1 + 4);
if ( v11 > 0 )
{
*(_DWORD *)(a1 + 4) = v11 - 1;
}
else
{
*(_DWORD *)(a5 + 4LL * v10++) = v16[0];
--*(_DWORD *)(a1 + 8);
}
}
while ( v15 > 1 );
}
*a4 = v10;
*a6 = v8;
return getCumulativeStatus(*(_QWORD *)(a1 + 16));
}

original_code:
SM_STATUS smBufferedFillAndReceive(BufferedMotionAxis *axis, smint32 numFillPoints, smint32 *fillPoints, smint32 *numReceivedPoints, smint32 *receivedPoints, smint32 *bytesFilled )
{
    smint32 bytesUsed=0;
    if(axis->readParamInitialized==0)
    {
        smAppendSMCommandToQueue(axis->bushandle,2,9);
        smAppendSMCommandToQueue(axis->bushandle,1,axis->readParamAddr);
        smAppendSMCommandToQueue(axis->bushandle,2,10);
        smAppendSMCommandToQueue(axis->bushandle,1,axis->readParamLength);
        smAppendSMCommandToQueue(axis->bushandle,2,551);
        bytesUsed+=2+3+2+3+2;
        axis->numberOfDiscardableReturnDataPackets+=5;
        axis->readParamInitialized=1;
    }
    if(numFillPoints>=1)
    {
        smAppendSMCommandToQueue(axis->bushandle,0,fillPoints[0]);
        bytesUsed+=4;
        axis->numberOfPendingReadPackets+=1;
    }
    if(numFillPoints>=2)
    {
        int i;
        for(i=1;i<numFillPoints;i++)
        {
            smAppendSMCommandToQueue(axis->bushandle,0,fillPoints[i]);
            bytesUsed+=4;
            axis->numberOfPendingReadPackets++;
        }
    }
    smUploadCommandQueueToDeviceBuffer(axis->bushandle,axis->deviceAddress);
    {
        smint32 bufferedReturnBytesReceived,readval;
        int n=0;
        smBytesReceived(axis->bushandle,&bufferedReturnBytesReceived);
        while(bufferedReturnBytesReceived>1)
        {
            smGetQueuedSMCommandReturnValue(axis->bushandle, &readval);
            smBytesReceived(axis->bushandle,&bufferedReturnBytesReceived);
            if(axis->numberOfDiscardableReturnDataPackets>0)
            {
                axis->numberOfDiscardableReturnDataPackets--;
            }
            else
            {
                receivedPoints[n]=readval;
                n++;
                axis->numberOfPendingReadPackets--;
            }
        }
        *numReceivedPoints=n;
    }
    *bytesFilled=bytesUsed;
    return getCumulativeStatus(axis->bushandle);
}

canonical_original_code:
int smBufferedFillAndReceive(struct _BufferedMotionAxis *axis, int numFillPoints, int *fillPoints, int *numReceivedPoints, int *receivedPoints, int *bytesFilled)
{
    int bytesUsed = 0;
    if(axis->readParamInitialized==0)
    {
        smAppendSMCommandToQueue(axis->bushandle,2,9);
        smAppendSMCommandToQueue(axis->bushandle,1,axis->readParamAddr);
        smAppendSMCommandToQueue(axis->bushandle,2,10);
        smAppendSMCommandToQueue(axis->bushandle,1,axis->readParamLength);
        smAppendSMCommandToQueue(axis->bushandle,2,551);
        bytesUsed+=2+3+2+3+2;
        axis->numberOfDiscardableReturnDataPackets+=5;
        axis->readParamInitialized=1;
    }
    if(numFillPoints>=1)
    {
        smAppendSMCommandToQueue(axis->bushandle,0,fillPoints[0]);
        bytesUsed+=4;
        axis->numberOfPendingReadPackets+=1;
    }
    if(numFillPoints>=2)
    {
        int i;
        for(i=1;i<numFillPoints;i++)
        {
            smAppendSMCommandToQueue(axis->bushandle,0,fillPoints[i]);
            bytesUsed+=4;
            axis->numberOfPendingReadPackets++;
        }
    }
    smUploadCommandQueueToDeviceBuffer(axis->bushandle,axis->deviceAddress);
    {
        int bufferedReturnBytesReceived; int readval;
        int n = 0;
        smBytesReceived(axis->bushandle,&bufferedReturnBytesReceived);
        while(bufferedReturnBytesReceived>1)
        {
            smGetQueuedSMCommandReturnValue(axis->bushandle, &readval);
            smBytesReceived(axis->bushandle,&bufferedReturnBytesReceived);
            if(axis->numberOfDiscardableReturnDataPackets>0)
            {
                axis->numberOfDiscardableReturnDataPackets--;
            }
            else
            {
                receivedPoints[n]=readval;
                n++;
                axis->numberOfPendingReadPackets--;
            }
        }
        *numReceivedPoints=n;
    }
    *bytesFilled=bytesUsed;
    return getCumulativeStatus(axis->bushandle);
}

variable_types:
fillPoints
int *

variable_types:
numReceivedPoints
int *

variable_types:
receivedPoints
int *

variable_types:
bytesFilled
int *

variable_types: bytesUsed int

variable_types: i int

variable_types: bufferedReturnBytesReceived int

variable_types: readval int

variable_types: n int


smBufferedAbort

decompiled_code:
__int64 __fastcall smBufferedAbort(__int64 a1)
{
return smSetParameter(*(_QWORD *)(a1 + 16), *(unsigned __int8 *)(a1 + 24), 554LL, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return smSetParameter(*(_QWORD *)(a1 + 16), *(unsigned __int8 *)(a1 + 24), 554LL, 4LL);
}

original_code:
SM_STATUS smBufferedAbort(BufferedMotionAxis *axis)
{
    return smSetParameter( axis->bushandle, axis->deviceAddress, 554,4);
}

canonical_original_code:
int smBufferedAbort(struct _BufferedMotionAxis *axis)
{
    return smSetParameter( axis->bushandle, axis->deviceAddress, 554,4);
}

variable_types: struct _BufferedMotionAxis { char initialized; char readParamInitialized; int numberOfDiscardableReturnDataPackets; int numberOfPendingReadPackets; long bushandle; unsigned char deviceAddress; int samplerate; short readParamAddr; unsigned char readParamLength; int driveFlagsBeforeInit; char driveFlagsModifiedAtInit; int driveAccelerationBeforeInit; unsigned short driveClock; int bufferLength; int bufferFreeBytes; int bufferFill; int smProtocolVersion; int deviceCapabilityFlags1; int deviceCapabilityFlags2; } *


smBufferedDeinit

decompiled_code:
__int64 __fastcall smBufferedDeinit(__int64 a1)
{
smBufferedAbort(a1);
if ( *(_BYTE *)a1 == 1 )
{
smSetParameter(*(_QWORD *)(a1 + 16), *(unsigned __int8 *)(a1 + 24), 800LL, *(unsigned int *)(a1 + 44));
if ( *(_BYTE *)(a1 + 40) == 1 )
smSetParameter(*(_QWORD *)(a1 + 16), *(unsigned __int8 *)(a1 + 24), 567LL, *(unsigned int *)(a1 + 36));
}
*(_BYTE *)a1 = 0;
*(_BYTE *)(a1 + 1) = 0;
return getCumulativeStatus(*(_QWORD *)(a1 + 16));
}

original_code:
SM_STATUS smBufferedDeinit( BufferedMotionAxis *axis )
{
    smBufferedAbort(axis);
    if(axis->initialized==1)
    {
        smSetParameter(axis->bushandle,axis->deviceAddress,800,axis->driveAccelerationBeforeInit);
        if(axis->driveFlagsModifiedAtInit==1)
            smSetParameter(axis->bushandle,axis->deviceAddress,567,axis->driveFlagsBeforeInit);
    }
    axis->initialized=0;
    axis->readParamInitialized=0;
    return getCumulativeStatus(axis->bushandle);
}

canonical_original_code:
int smBufferedDeinit(struct _BufferedMotionAxis *axis)
{
    smBufferedAbort(axis);
    if(axis->initialized==1)
    {
        smSetParameter(axis->bushandle,axis->deviceAddress,800,axis->driveAccelerationBeforeInit);
        if(axis->driveFlagsModifiedAtInit==1)
            smSetParameter(axis->bushandle,axis->deviceAddress,567,axis->driveFlagsBeforeInit);
    }
    axis->initialized=0;
    axis->readParamInitialized=0;
    return getCumulativeStatus(axis->bushandle);
}


smBDinit

decompiled_code:
__int64 *smBDinit()
{
__int64 *result; // rax

result = &BusDevice;
do
{
*(_BYTE *)result = 0;
*((_DWORD *)result + 36) = 0;
result += 24;
}
while ( result != (__int64 *)(unsigned int)((_DWORD)&BusDevice + 1920) );
bdInitialized = 1;
return result;
}

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

result = &BusDevice;
do
{
*(_BYTE *)result = 0;
*((_DWORD *)result + 36) = 0;
result += 24;
}
while ( result != (__int64 *)(unsigned int)((_DWORD)&BusDevice + 1920) );
bdInitialized = 1;
return result;
}

original_code:
void smBDinit()
{
 int i;
 for(i=0;i<10;i++)
 {
  BusDevice[i].opened=0;
        BusDevice[i].txBufferUsed=0;
 }
 bdInitialized=1;
}


smIsBDHandleOpen

decompiled_code:
__int64 __fastcall smIsBDHandleOpen(unsigned __int16 a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 <= 9u )
result = LOBYTE(BusDevice[24 * (__int16)a1]);
return result;
}

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

result = 0LL;
if ( a1 <= 9u )
result = LOBYTE(BusDevice[24 * (__int16)a1]);
return result;
}

original_code:
smbool smIsBDHandleOpen( const smbusdevicehandle handle )
{
 if(handle<0) return 0;
 if(handle>=10) return 0;
 return BusDevice[handle].opened;
}

canonical_original_code:
char smIsBDHandleOpen(short handle)
{
 if(handle<0) return 0;
 if(handle>=10) return 0;
 return BusDevice[handle].opened;
}

variable_types: handle short

return_type: char


smBDClose

decompiled_code:
__int64 __fastcall smBDClose(signed __int16 a1)
{
__int64 result; // rax

result = smIsBDHandleOpen(a1);
if ( (_BYTE)result )
{
((void (__fastcall *)(__int64))BusDevice[24 * a1 + 23])(BusDevice[24 * a1 + 1]);
LOBYTE(BusDevice[24 * a1]) = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(signed __int16 a1)
{
__int64 result; // rax

result = func1(a1);
if ( (_BYTE)result )
{
((void (__fastcall *)(__int64))BusDevice[24 * a1 + 23])(BusDevice[24 * a1 + 1]);
LOBYTE(BusDevice[24 * a1]) = 0;
result = 1LL;
}
return result;
}

original_code:
smbool smBDClose( const smbusdevicehandle handle )
{
 if( smIsBDHandleOpen(handle)==0 ) return 0;
    BusDevice[handle].busCloseCallback(BusDevice[handle].busDevicePointer );
    BusDevice[handle].opened=0;
    return 1;
}

canonical_original_code:
char smBDClose(short handle)
{
 if( smIsBDHandleOpen(handle)==0 ) return 0;
    BusDevice[handle].busCloseCallback(BusDevice[handle].busDevicePointer );
    BusDevice[handle].opened=0;
    return 1;
}


smBDWrite

decompiled_code:
__int64 __fastcall smBDWrite(signed __int16 a1, unsigned __int8 a2)
{
__int64 result; // rax
int v3; // eax
__int64 v4; // rcx

result = smIsBDHandleOpen(a1);
if ( (_BYTE)result )
{
v3 = BusDevice[24 * a1 + 18];
if ( v3 <= 127 )
{
v4 = 24LL * a1;
*((_BYTE *)&BusDevice[2] + v3 + v4 * 8) = a2;
LODWORD(BusDevice[v4 + 18]) = v3 + 1;
smDebug(a1, 4LL, " Sending byte %02x\n", a2);
result = 1LL;
}
else
{
smDebug(a1, 2LL, " Sending byte %02x failed, TX buffer overflown\n", a2);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(signed __int16 a1, unsigned __int8 a2)
{
__int64 result; // rax
int v3; // eax
__int64 v4; // rcx

result = func1(a1);
if ( (_BYTE)result )
{
v3 = BusDevice[24 * a1 + 18];
if ( v3 <= 127 )
{
v4 = 24LL * a1;
*((_BYTE *)&BusDevice[2] + v3 + v4 * 8) = a2;
LODWORD(BusDevice[v4 + 18]) = v3 + 1;
smDebug(a1, 4LL, " Sending byte %02x\n", a2);
result = 1LL;
}
else
{
smDebug(a1, 2LL, " Sending byte %02x failed, TX buffer overflown\n", a2);
result = 0LL;
}
}
return result;
}

original_code:
smbool smBDWrite(const smbusdevicehandle handle, const smuint8 byte )
{
 if( smIsBDHandleOpen(handle)==0 ) return 0;
    if(BusDevice[handle].txBufferUsed<128)
    {
        BusDevice[handle].txBuffer[BusDevice[handle].txBufferUsed]=byte;
        BusDevice[handle].txBufferUsed++;
        smDebug(handle, SMDebugTrace, "  Sending byte %02x\n",byte);
        return 1;
    }
    smDebug(handle, SMDebugMid, "  Sending byte %02x failed, TX buffer overflown\n",byte);
    return 0;
}

canonical_original_code:
char smBDWrite(short handle, unsigned char byte)
{
 if( smIsBDHandleOpen(handle)==0 ) return 0;
    if(BusDevice[handle].txBufferUsed<128)
    {
        BusDevice[handle].txBuffer[BusDevice[handle].txBufferUsed]=byte;
        BusDevice[handle].txBufferUsed++;
        smDebug(handle, SMDebugTrace, "  Sending byte %02x\n",byte);
        return 1;
    }
    smDebug(handle, SMDebugMid, "  Sending byte %02x failed, TX buffer overflown\n",byte);
    return 0;
}

variable_types:
byte
unsigned char


smBDTransmit

decompiled_code:
__int64 __fastcall smBDTransmit(signed __int16 a1)
{
__int64 result; // rax

result = smIsBDHandleOpen(a1);
if ( (_BYTE)result )
{
if ( ((unsigned int (__fastcall *)(__int64, __int64 *, _QWORD))BusDevice[24 * a1 + 21])(
BusDevice[24 * a1 + 1],
&BusDevice[24 * a1 + 2],
LODWORD(BusDevice[24 * a1 + 18])) == LODWORD(BusDevice[24 * a1 + 18]) )
{
LODWORD(BusDevice[24 * a1 + 18]) = 0;
result = 1LL;
}
else
{
LODWORD(BusDevice[24 * a1 + 18]) = 0;
result = 0LL;
}
}
return result;
}

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

result = func1(a1);
if ( (_BYTE)result )
{
if ( ((unsigned int (__fastcall *)(__int64, __int64 *, _QWORD))BusDevice[24 * a1 + 21])(
BusDevice[24 * a1 + 1],
&BusDevice[24 * a1 + 2],
LODWORD(BusDevice[24 * a1 + 18])) == LODWORD(BusDevice[24 * a1 + 18]) )
{
LODWORD(BusDevice[24 * a1 + 18]) = 0;
result = 1LL;
}
else
{
LODWORD(BusDevice[24 * a1 + 18]) = 0;
result = 0LL;
}
}
return result;
}

original_code:
smbool smBDTransmit(const smbusdevicehandle handle)
{
    if( smIsBDHandleOpen(handle)==0 ) return 0;
    if(BusDevice[handle].busWriteCallback(BusDevice[handle].busDevicePointer,BusDevice[handle].txBuffer, BusDevice[handle].txBufferUsed)==BusDevice[handle].txBufferUsed)
    {
        BusDevice[handle].txBufferUsed=0;
        return 1;
    }
    else
    {
        BusDevice[handle].txBufferUsed=0;
        return 0;
    }
}

canonical_original_code:
char smBDTransmit(short handle)
{
    if( smIsBDHandleOpen(handle)==0 ) return 0;
    if(BusDevice[handle].busWriteCallback(BusDevice[handle].busDevicePointer,BusDevice[handle].txBuffer, BusDevice[handle].txBufferUsed)==BusDevice[handle].txBufferUsed)
    {
        BusDevice[handle].txBufferUsed=0;
        return 1;
    }
    else
    {
        BusDevice[handle].txBufferUsed=0;
        return 0;
    }
}


smBDRead

decompiled_code:
__int64 __fastcall smBDRead(signed __int16 a1, unsigned __int8 *a2)
{
__int64 result; // rax

result = smIsBDHandleOpen(a1);
if ( (_BYTE)result )
{
if ( ((unsigned int (__fastcall *)(__int64, unsigned __int8 *, __int64))BusDevice[24 * a1 + 20])(
BusDevice[24 * a1 + 1],
a2,
1LL) == 1 )
{
smDebug(a1, 4LL, " Got byte %02x \n", *a2);
result = 1LL;
}
else
{
smDebug(a1, 2LL, " Reading a byte from bus failed\n");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(signed __int16 a1, unsigned __int8 *a2)
{
__int64 result; // rax

result = func1(a1);
if ( (_BYTE)result )
{
if ( ((unsigned int (__fastcall *)(__int64, unsigned __int8 *, __int64))BusDevice[24 * a1 + 20])(
BusDevice[24 * a1 + 1],
a2,
1LL) == 1 )
{
smDebug(a1, 4LL, " Got byte %02x \n", *a2);
result = 1LL;
}
else
{
smDebug(a1, 2LL, " Reading a byte from bus failed\n");
result = 0LL;
}
}
return result;
}

original_code:
smbool smBDRead( const smbusdevicehandle handle, smuint8 *byte )
{
 if( smIsBDHandleOpen(handle)==0 ) return 0;
    int n;
    n=BusDevice[handle].busReadCallback(BusDevice[handle].busDevicePointer, byte, 1);
    if( n!=1 )
    {
        smDebug(handle, SMDebugMid, "  Reading a byte from bus failed\n");
        return 0;
    }
    else
    {
        smDebug(handle, SMDebugTrace, "  Got byte %02x \n",*byte);
        return 1;
    }
}

canonical_original_code:
char smBDRead(short handle, unsigned char *byte)
{
 if( smIsBDHandleOpen(handle)==0 ) return 0;
    int n;
    n=BusDevice[handle].busReadCallback(BusDevice[handle].busDevicePointer, byte, 1);
    if( n!=1 )
    {
        smDebug(handle, SMDebugMid, "  Reading a byte from bus failed\n");
        return 0;
    }
    else
    {
        smDebug(handle, SMDebugTrace, "  Got byte %02x \n",*byte);
        return 1;
    }
}

variable_types:
byte
unsigned char *


smBDMiscOperation

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

result = smIsBDHandleOpen(a1);
if ( (_BYTE)result )
{
LODWORD(BusDevice[24 * a1 + 18]) = 0;
result = ((__int64 (__fastcall *)(__int64, _QWORD))BusDevice[24 * a1 + 22])(BusDevice[24 * a1 + 1], a2);
}
return result;
}

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

result = func1(a1);
if ( (_BYTE)result )
{
LODWORD(BusDevice[24 * a1 + 18]) = 0;
result = ((__int64 (__fastcall *)(__int64, _QWORD))BusDevice[24 * a1 + 22])(BusDevice[24 * a1 + 1], a2);
}
return result;
}

original_code:
smbool smBDMiscOperation(const smbusdevicehandle handle , BusDeviceMiscOperationType operation)
{
    if( smIsBDHandleOpen(handle)==0 ) return 0;
    BusDevice[handle].txBufferUsed=0;
    return BusDevice[handle].busMiscOperationCallback(BusDevice[handle].busDevicePointer,operation);
}

canonical_original_code:
char smBDMiscOperation(short handle, enum _BusDeviceMiscOperationType operation)
{
    if( smIsBDHandleOpen(handle)==0 ) return 0;
    BusDevice[handle].txBufferUsed=0;
    return BusDevice[handle].busMiscOperationCallback(BusDevice[handle].busDevicePointer,operation);
}

variable_types: enum _BusDeviceMiscOperationType { MiscOperationFlushTX=0, MiscOperationPurgeRX=1 }


smBDOpenWithCallbacks

decompiled_code:
__int64 __fastcall smBDOpenWithCallbacks(__int64 a1, __int64 (__fastcall *a2)(__int64, _QWORD, char *), __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 *v8; // rax
int v9; // ebx
unsigned int v10; // ebp
char v14[57]; // [rsp+2Fh] [rbp-39h] BYREF

if ( !bdInitialized )
smBDinit();
v8 = BusDevice;
v9 = 0;
while ( *(_BYTE *)v8 )
{
++v9;
v8 += 24;
if ( v9 == 10 )
return (unsigned int)-1;
}
if ( v9 > 9 )
return (unsigned int)-1;
BusDevice[24 * v9 + 19] = (__int64)a2;
BusDevice[24 * v9 + 21] = a5;
BusDevice[24 * v9 + 20] = a4;
BusDevice[24 * v9 + 22] = a6;
BusDevice[24 * v9 + 23] = a3;
BusDevice[24 * v9 + 1] = a2(a1, (unsigned int)SMBusBaudrate, v14);
if ( !v14[0] )
return (unsigned int)-1;
LOBYTE(BusDevice[24 * v9]) = 1;
LODWORD(BusDevice[24 * v9 + 18]) = 0;
HIDWORD(BusDevice[24 * v9]) = 0;
v10 = v9;
if ( !(unsigned __int8)smBDMiscOperation(v9, 1u) )
{
smBDClose(v9);
v10 = -1;
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 (__fastcall *a2)(__int64, _QWORD, char *), __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 *v8; // rax
int v9; // ebx
unsigned int v10; // ebp
char v14[57]; // [rsp+2Fh] [rbp-39h] BYREF

if ( !bdInitialized )
func0();
v8 = BusDevice;
v9 = 0;
while ( *(_BYTE *)v8 )
{
++v9;
v8 += 24;
if ( v9 == 10 )
return (unsigned int)-1;
}
if ( v9 > 9 )
return (unsigned int)-1;
BusDevice[24 * v9 + 19] = (__int64)a2;
BusDevice[24 * v9 + 21] = a5;
BusDevice[24 * v9 + 20] = a4;
BusDevice[24 * v9 + 22] = a6;
BusDevice[24 * v9 + 23] = a3;
BusDevice[24 * v9 + 1] = a2(a1, (unsigned int)SMBusBaudrate, v14);
if ( !v14[0] )
return (unsigned int)-1;
LOBYTE(BusDevice[24 * v9]) = 1;
LODWORD(BusDevice[24 * v9 + 18]) = 0;
HIDWORD(BusDevice[24 * v9]) = 0;
v10 = v9;
if ( !(unsigned __int8)func6(v9, 1u) )
{
func2(v9);
v10 = -1;
}
return v10;
}

original_code:
smbusdevicehandle smBDOpenWithCallbacks(const char *devicename, BusdeviceOpen busOpenCallback, BusdeviceClose busCloseCallback , BusdeviceReadBuffer busReadCallback, BusdeviceWriteBuffer busWriteCallback, BusdeviceMiscOperation busMiscOperationCallback )
{
    int handle;
    smbool success;
    if(bdInitialized==0)
        smBDinit();
    for(handle=0;handle<10;handle++)
    {
        if(BusDevice[handle].opened==0) break;
    }
    if(handle>=10) return -1;
    BusDevice[handle].busOpenCallback=busOpenCallback;
    BusDevice[handle].busWriteCallback=busWriteCallback;
    BusDevice[handle].busReadCallback=busReadCallback;
    BusDevice[handle].busMiscOperationCallback=busMiscOperationCallback;
    BusDevice[handle].busCloseCallback=busCloseCallback;
    BusDevice[handle].busDevicePointer=BusDevice[handle].busOpenCallback( devicename, SMBusBaudrate, &success );
    if( success==0 )
    {
        return -1;
    }
    BusDevice[handle].opened=1;
    BusDevice[handle].txBufferUsed=0;
    BusDevice[handle].cumulativeSmStatus=0;
    if(smBDMiscOperation(handle,MiscOperationPurgeRX)==0)
    {
        smBDClose(handle);
        return -1;
    }
    return handle;
}

canonical_original_code:
short smBDOpenWithCallbacks(char *devicename, void *(*busOpenCallback)(char *port_device_name, int baudrate_bps, char *success), void (*busCloseCallback)(void *busdevicePointer), int (*busReadCallback)(void *busdevicePointer, unsigned char *buf, int size), int (*busWriteCallback)(void *busdevicePointer, unsigned char *buf, int size), char (*busMiscOperationCallback)(void *busdevicePointer, enum _BusDeviceMiscOperationType operation))
{
    int handle;
    char success;
    if(bdInitialized==0)
        smBDinit();
    for(handle=0;handle<10;handle++)
    {
        if(BusDevice[handle].opened==0) break;
    }
    if(handle>=10) return -1;
    BusDevice[handle].busOpenCallback=busOpenCallback;
    BusDevice[handle].busWriteCallback=busWriteCallback;
    BusDevice[handle].busReadCallback=busReadCallback;
    BusDevice[handle].busMiscOperationCallback=busMiscOperationCallback;
    BusDevice[handle].busCloseCallback=busCloseCallback;
    BusDevice[handle].busDevicePointer=BusDevice[handle].busOpenCallback( devicename, SMBusBaudrate, &success );
    if( success==0 )
    {
        return -1;
    }
    BusDevice[handle].opened=1;
    BusDevice[handle].txBufferUsed=0;
    BusDevice[handle].cumulativeSmStatus=0;
    if(smBDMiscOperation(handle,MiscOperationPurgeRX)==0)
    {
        smBDClose(handle);
        return -1;
    }
    return handle;
}

variable_types:
devicename
char *

variable_types: void *(*)(char *port_device_name, int baudrate_bps, char *success)

variable_types:
busCloseCallback
void (*)(void *busdevicePointer)

variable_types: int (*)(void *busdevicePointer, unsigned char *buf, int size)

variable_types: char (*)(void *busdevicePointer, enum _BusDeviceMiscOperationType { MiscOperationFlushTX=0, MiscOperationPurgeRX=1 } operation)

variable_types: handle int

variable_types: success char

return_type: short


smBDGetNumberOfDetectedBuses

decompiled_code:
__int64 smBDGetNumberOfDetectedBuses()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
return 0LL;
}

original_code:
smint smBDGetNumberOfDetectedBuses()
{
    return 0;
}


smBDGetBusDeviceDetails

decompiled_code:
__int64 smBDGetBusDeviceDetails()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
return 0LL;
}

original_code:
smbool smBDGetBusDeviceDetails( smint index, SM_BUS_DEVICE_INFO *info )
{
    return 0;
}

canonical_original_code:
char smBDGetBusDeviceDetails(int index, struct SM_BUS_DEVICE_INFO *info)
{
    return 0;
}

variable_types: index int

variable_types: struct SM_BUS_DEVICE_INFO { char is_simplemotion_device; char device_name[64]; char description[128]; } *


tcpipPortRead

decompiled_code:
ssize_t __fastcall tcpipPortRead(int fd, void *buf, int a3)
{
struct timeval v5; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[(unsigned int)fd >> 6] |= 1LL << fd;
v5.tv_sec = readTimeoutMs / 0x3E8u;
v5.tv_usec = 1000LL * (readTimeoutMs % 0x3E8u);
if ( select(fd + 1, &readfds, 0LL, 0LL, &v5) <= 0 )
return 0xFFFFFFFFLL;
if ( (readfds.fds_bits[fd / 64] & (1LL << (fd % 64))) != 0 )
return read(fd, buf, a3);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
ssize_t __fastcall func1(int fd, void *buf, int a3)
{
struct timeval v5; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[(unsigned int)fd >> 6] |= 1LL << fd;
v5.tv_sec = readTimeoutMs / 0x3E8u;
v5.tv_usec = 1000LL * (readTimeoutMs % 0x3E8u);
if ( select(fd + 1, &readfds, 0LL, 0LL, &v5) <= 0 )
return 0xFFFFFFFFLL;
if ( (readfds.fds_bits[fd / 64] & (1LL << (fd % 64))) != 0 )
return read(fd, buf, a3);
return 0xFFFFFFFFLL;
}

original_code:
int tcpipPortRead(smBusdevicePointer busdevicePointer, unsigned char *buf, int size)
{
    int n;
    int sockfd=(int)busdevicePointer;
    fd_set input;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&input)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&input)->__fds_bits)[(((unsigned int)sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << (((unsigned int)sockfd) % (8 * (int) sizeof (__fd_mask)))))));
    struct timeval timeout;
    timeout.tv_sec = readTimeoutMs/1000;
    timeout.tv_usec = (readTimeoutMs%1000) * 1000;
    n = select(sockfd + 1, &input, ((void *)0), ((void *)0), &timeout);
    if (n < 1)
    {
        return(-1);
    }
    if(!((((&input)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
    {
        return(-1);
    }
    n = read(sockfd, (char*)buf, size);
    return(n);
}

canonical_original_code:
int tcpipPortRead(void *busdevicePointer, unsigned char *buf, int size)
{
    int n;
    int sockfd = (int)busdevicePointer;
    struct fd_set input;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&input)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&input)->__fds_bits)[(((unsigned int)sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << (((unsigned int)sockfd) % (8 * (int) sizeof (__fd_mask)))))));
    struct timeval timeout;
    timeout.tv_sec = readTimeoutMs/1000;
    timeout.tv_usec = (readTimeoutMs%1000) * 1000;
    n = select(sockfd + 1, &input, ((void *)0), ((void *)0), &timeout);
    if (n < 1)
    {
        return(-1);
    }
    if(!((((&input)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
    {
        return(-1);
    }
    n = read(sockfd, (char *)buf, size);
    return(n);
}

variable_types:
busdevicePointer
void *

variable_types:
buf
unsigned char *

variable_types: size int

variable_types: sockfd int

variable_types:
input
struct fd_set { long __fds_bits[-1]; }

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


tcpipPortWrite

decompiled_code:
ssize_t __fastcall tcpipPortWrite(int a1, const void *a2, int a3)
{
return write(a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func2(int a1, const void *a2, int a3)
{
return write(a1, a2, a3);
}

original_code:
int tcpipPortWrite(smBusdevicePointer busdevicePointer, unsigned char *buf, int size)
{
    int sockfd=(int)busdevicePointer;
    int sent = write(sockfd, (char*)buf, size);
    if (sent != size)
    {
        return sent;
    }
    return sent;
}

canonical_original_code:
int tcpipPortWrite(void *busdevicePointer, unsigned char *buf, int size)
{
    int sockfd = (int)busdevicePointer;
    int sent = write(sockfd, (char*)buf, size);
    if (sent != size)
    {
        return sent;
    }
    return sent;
}

variable_types: sent int


tcpipMiscOperation

decompiled_code:
__int64 __fastcall tcpipMiscOperation(int fd, int a2)
{
__int64 result; // rax
int v3; // eax
struct timeval v4; // [rsp+0h] [rbp-1C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-1B8h] BYREF
char buf[312]; // [rsp+90h] [rbp-138h] BYREF

result = 1LL;
if ( a2 )
{
if ( a2 == 1 )
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[(unsigned int)fd >> 6] |= 1LL << fd;
v4.tv_sec = 0LL;
v4.tv_usec = 0LL;
v3 = select(fd + 1, &readfds, 0LL, 0LL, &v4);
if ( v3 < 0 )
return 0LL;
if ( !v3 )
return 1LL;
if ( (readfds.fds_bits[fd / 64] & (1LL << (fd % 64))) == 0 )
break;
if ( (int)read(fd, buf, 0x100uLL) <= 0 )
return 1LL;
}
result = 1LL;
}
else
{
smDebug(-1LL, 1LL, "TCP/IP: given MiscOperataion not implemented\n");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, int a2)
{
__int64 result; // rax
int v3; // eax
struct timeval v4; // [rsp+0h] [rbp-1C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-1B8h] BYREF
char buf[312]; // [rsp+90h] [rbp-138h] BYREF

result = 1LL;
if ( a2 )
{
if ( a2 == 1 )
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[(unsigned int)fd >> 6] |= 1LL << fd;
v4.tv_sec = 0LL;
v4.tv_usec = 0LL;
v3 = select(fd + 1, &readfds, 0LL, 0LL, &v4);
if ( v3 < 0 )
return 0LL;
if ( !v3 )
return 1LL;
if ( (readfds.fds_bits[fd / 64] & (1LL << (fd % 64))) == 0 )
break;
if ( (int)read(fd, buf, 0x100uLL) <= 0 )
return 1LL;
}
result = 1LL;
}
else
{
smDebug(-1LL, 1LL, "TCP/IP: given MiscOperataion not implemented\n");
result = 0LL;
}
}
return result;
}

original_code:
smbool tcpipMiscOperation(smBusdevicePointer busdevicePointer, BusDeviceMiscOperationType operation)
{
    switch(operation)
    {
    case MiscOperationPurgeRX:
        {
            int n;
            do
            {
                char discardbuf[256];
                int sockfd=(int)busdevicePointer;
                fd_set input;
                do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&input)->__fds_bits)[0]) : "memory"); } while (0);
                ((void) (((&input)->__fds_bits)[(((unsigned int)sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << (((unsigned int)sockfd) % (8 * (int) sizeof (__fd_mask)))))));
                struct timeval timeout;
                timeout.tv_sec = 0;
                timeout.tv_usec = 0;
                n = select(sockfd + 1, &input, ((void *)0), ((void *)0), &timeout);
                if (n < 0)
                {
                    return 0;
                }
                if (n == 0)
                {
                    return 1;
                }
                if(!((((&input)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
                {
                    return 1;
                }
                n = read(sockfd, (char*)discardbuf, 256);
            } while( n>0 );
            return 1;
        }
        break;
    case MiscOperationFlushTX:
        return 1;
        break;
    default:
        smDebug( -1, SMDebugLow, "TCP/IP: given MiscOperataion not implemented\n");
        return 0;
        break;
    }
}

canonical_original_code:
char tcpipMiscOperation(void *busdevicePointer, enum _BusDeviceMiscOperationType operation)
{
    switch(operation)
    {
    case MiscOperationPurgeRX:
        {
            int n;
            do
            {
                char discardbuf[256];
                int sockfd = (int)busdevicePointer;
                struct fd_set input;
                do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&input)->__fds_bits)[0]) : "memory"); } while (0);
                ((void) (((&input)->__fds_bits)[(((unsigned int)sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << (((unsigned int)sockfd) % (8 * (int) sizeof (__fd_mask)))))));
                struct timeval timeout;
                timeout.tv_sec = 0;
                timeout.tv_usec = 0;
                n = select(sockfd + 1, &input, ((void *)0), ((void *)0), &timeout);
                if (n < 0)
                {
                    return 0;
                }
                if (n == 0)
                {
                    return 1;
                }
                if(!((((&input)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
                {
                    return 1;
                }
                n = read(sockfd, (char *)discardbuf, 256);
            } while( n>0 );
            return 1;
        }
        break;
    case MiscOperationFlushTX:
        return 1;
        break;
    default:
        smDebug( -1, SMDebugLow, "TCP/IP: given MiscOperataion not implemented\n");
        return 0;
        break;
    }
}

variable_types: enum _BusDeviceMiscOperationType { MiscOperationFlushTX=0, MiscOperationPurgeRX=1 }

variable_types: n int

variable_types:
discardbuf
char [256]

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


tcpipPortClose

decompiled_code:
int __fastcall tcpipPortClose(int a1)
{
return close(a1);
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
return close(a1);
}

original_code:
void tcpipPortClose(smBusdevicePointer busdevicePointer)
{
    int sockfd=(int)busdevicePointer;
    close(sockfd);
}

canonical_original_code:
void tcpipPortClose(void *busdevicePointer)
{
    int sockfd = (int)busdevicePointer;
    close(sockfd);
}