decompiled_code:
__int64 type_new()
{
return (unsigned int)id_0++;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)id_0++;
}

original_code:
type_t type_new(void) {
 static type_t id = 4;
 return id++;
}

canonical_original_code:
unsigned int type_new() {
 static unsigned int id = 4;
 return id++;
}

variable_types:
id
unsigned int


repo: uOptim/rubic-enseirb

decompiled_code:
_QWORD *stack_new()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
}
else
{
perror("malloc");
result = 0LL;
}
return result;
}

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

result = malloc(0x18uLL);
if ( result )
{
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
}
else
{
perror("malloc");
result = 0LL;
}
return result;
}

original_code:
struct stack * stack_new()
{
 struct stack *s = malloc(sizeof *s);
 if (s == ((void *)0)) {
  perror("malloc");
 } else {
  s->size = 0;
  s->head = ((void *)0);
  s->cursor = ((void *)0);
 }
 return s;
}

canonical_original_code:
struct stack *stack_new()
{
 struct stack *s = malloc(sizeof *s);
 if (s == ((void *)0)) {
  perror("malloc");
 } else {
  s->size = 0;
  s->head = ((void *)0);
  s->cursor = ((void *)0);
 }
 return s;
}

variable_types: struct stack { int size; struct elt { void *data; struct elt *next; } *head; struct elt *cursor; } *

user_defined_types: struct stack { int size; struct elt *head; struct elt *cursor; }


decompiled_code:
void __fastcall stack_free(__int64 *a1, void (__fastcall *a2)(__int64))
{
stack_clear(*a1, a2);
free((void *)*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(__int64 *a1, void (__fastcall *a2)(__int64))
{
func2(*a1, a2);
free((void *)*a1);
*a1 = 0LL;
}

original_code:
void stack_free(struct stack **s, void (*free_data)(void *))
{
 stack_clear(*s, free_data);
 free(*s);
 *s = ((void *)0);
}

variable_types: struct stack { int size; struct elt { void *data; struct elt *next; } *head; struct elt *cursor; } **

return_type: void


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

v2 = malloc(0x10uLL);
if ( v2 )
{
v3 = *(_QWORD *)(a1 + 8);
if ( !v3 )
*(_QWORD *)(a1 + 16) = v2;
++*(_DWORD *)a1;
*v2 = a2;
v2[1] = v3;
*(_QWORD *)(a1 + 8) = v2;
result = 0LL;
}
else
{
perror("malloc");
result = 0xFFFFFFFFLL;
}
return result;
}

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

v2 = malloc(0x10uLL);
if ( v2 )
{
v3 = *(_QWORD *)(a1 + 8);
if ( !v3 )
*(_QWORD *)(a1 + 16) = v2;
++*(_DWORD *)a1;
*v2 = a2;
v2[1] = v3;
*(_QWORD *)(a1 + 8) = v2;
result = 0LL;
}
else
{
perror("malloc");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int stack_push(struct stack *s, void *d)
{
 struct elt *e = malloc(sizeof *e);
 if (e == ((void *)0)) {
  perror("malloc");
  return -1;
 }
 if (s->head == ((void *)0)) {
  s->cursor = e;
 }
 e->data = d;
 e->next = s->head;
 s->head = e;
 s->size++;
 return 0;
}

variable_types:
d
void *

variable_types: struct elt { void *data; struct elt *next; } *

return_type: int


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

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

original_code:
int stack_size(struct stack *s) {
 return s->size;
}

user_defined_types: struct elt { void *data; struct elt *next; }


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

result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 16) = result;
return result;
}

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

result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void stack_rewind(struct stack *s)
{
 s->cursor = s->head;
}


original_code:
void * stack_next(struct stack *s)
{
 void *d = ((void *)0);
 if (s->cursor != ((void *)0)) {
  d = s->cursor->data;
  s->cursor = s->cursor->next;
 } else {
  stack_rewind(s);
 }
 return d;
}

canonical_original_code:
void *stack_next(struct stack *s)
{
 void *d = ((void *)0);
 if (s->cursor != ((void *)0)) {
  d = s->cursor->data;
  s->cursor = s->cursor->next;
 } else {
  stack_rewind(s);
 }
 return d;
}

return_type: void *


restoreTerm

repo: uaarg/telemetry-over-wifi

decompiled_code:
int __fastcall restoreTerm(struct termios *termios_p)
{
int v2; // edi
int result; // eax

printf("\x1B[32mRestoring terminal settings\x1B[00m\n %p", termios_p);
if ( termios_p )
{
v2 = termios_p[2].c_cflag;
if ( v2 == -1 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/sigHandling.c", "restoreTerm", 25LL);
result = fwrite("File fd wasn't opened well", 1uLL, 0x1AuLL, stderr);
}
else
{
tcsetattr(v2, 0, termios_p);
result = tcflush(termios_p[2].c_cflag, 1);
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/sigHandling.c", "restoreTerm", 31LL);
result = fwrite("termStorage is NULL", 1uLL, 0x13uLL, stderr);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(struct termios *termios_p)
{
int v2; // edi
int result; // eax

printf("\x1B[32mRestoring terminal settings\x1B[00m\n %p", termios_p);
if ( termios_p )
{
v2 = termios_p[2].c_cflag;
if ( v2 == -1 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/sigHandling.c", "restoreTerm", 25LL);
result = fwrite("File fd wasn't opened well", 1uLL, 0x1AuLL, stderr);
}
else
{
tcsetattr(v2, 0, termios_p);
result = tcflush(termios_p[2].c_cflag, 1);
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/sigHandling.c", "restoreTerm", 31LL);
result = fwrite("termStorage is NULL", 1uLL, 0x13uLL, stderr);
}
return result;
}

original_code:
void restoreTerm(void *termStorage) {
  printf("\033[32mRestoring terminal settings\033[00m\n %p", termStorage);
  if (termStorage != ((void *)0)) {
    TermPair *tp = (TermPair *)termStorage;
    if (tp->fd == -1) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/sigHandling.c", __func__, 25); fprintf(stderr, "File fd wasn't opened well"); };
    } else {
      tcsetattr(tp->fd, 0, &(tp->origTerm));
      tcflush(tp->fd, 1);
    }
  } else {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/sigHandling.c", __func__, 31); fprintf(stderr, "termStorage is NULL"); };
  }
}

canonical_original_code:
void restoreTerm(void *termStorage) {
  printf("\033[32mRestoring terminal settings\033[00m\n %p", termStorage);
  if (termStorage != ((void *)0)) {
    struct TermPair *tp = (TermPair *)termStorage;
    if (tp->fd == -1) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/sigHandling.c", __func__, 25); fprintf(stderr, "File fd wasn't opened well"); };
    } else {
      tcsetattr(tp->fd, 0, &(tp->origTerm));
      tcflush(tp->fd, 1);
    }
  } else {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/sigHandling.c", __func__, 31); fprintf(stderr, "termStorage is NULL"); };
  }
}

variable_types:
termStorage
void *

variable_types: struct TermPair { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } origTerm; struct termios newTerm; struct BaudRatePair { unsigned int inBaudRate; unsigned int outBaudRate; } baudRatePair; int fd; } *

user_defined_types: struct TermPair { struct termios origTerm; struct termios newTerm; struct BaudRatePair baudRatePair; int fd; }


closeAndFreeFP

decompiled_code:
void __fastcall closeAndFreeFP(void *ptr)
{
if ( ptr )
{
close(*(_DWORD *)ptr);
free(ptr);
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/sigHandling.c", "closeAndFreeFP", 40LL);
fwrite("File descriptor to be closed cannot be NULL", 1uLL, 0x2BuLL, stderr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
close(*(_DWORD *)ptr);
free(ptr);
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/sigHandling.c", "closeAndFreeFP", 40LL);
fwrite("File descriptor to be closed cannot be NULL", 1uLL, 0x2BuLL, stderr);
}
}

original_code:
void closeAndFreeFP(void *fd) {
  if (fd != ((void *)0)) {
    close(*((int *)fd));
    free(fd);
  } else {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/sigHandling.c", __func__, 40); fprintf(stderr, "File descriptor to be closed cannot be NULL"); };
  }
}

variable_types:
fd
void *


terminate

decompiled_code:
void __noreturn terminate()
{
freeSList(resourcesList);
fwrite("Exiting...\n", 1uLL, 0xBuLL, stderr);
exit(-1);
}

canonical_decompiled_code:
void __noreturn func2()
{
freeSList(resourcesList);
fwrite("Exiting...\n", 1uLL, 0xBuLL, stderr);
exit(-1);
}

original_code:
void terminate() {
  freeSList(resourcesList);
  fprintf(stderr, "Exiting...\n");
  exit(-1);
}


shutDown

decompiled_code:
void __noreturn shutDown()
{
fwrite("Shutting down...\n", 1uLL, 0x11uLL, stderr);
freeSList(resourcesList);
exit(0);
}

canonical_decompiled_code:
void __noreturn func3()
{
fwrite("Shutting down...\n", 1uLL, 0x11uLL, stderr);
freeSList(resourcesList);
exit(0);
}

original_code:
void shutDown() {
  fprintf(stderr, "Shutting down...\n");
  freeSList(resourcesList);
  exit(0);
}


sigHandler

decompiled_code:
int __fastcall sigHandler(__int64 a1, __int64 a2)
{
if ( (_DWORD)a1 == 2 )
terminate();
if ( (_DWORD)a1 == 15 )
shutDown(a1, a2, (unsigned int)a1);
return fprintf(stderr, "\x1B[31mUnhandled signal %d\n\x1B[00m", (unsigned int)a1);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2)
{
if ( (_DWORD)a1 == 2 )
func2();
if ( (_DWORD)a1 == 15 )
func3(a1, a2, (unsigned int)a1);
return fprintf(stderr, "\x1B[31mUnhandled signal %d\n\x1B[00m", (unsigned int)a1);
}

original_code:
void sigHandler(const int signalNum) {
  switch(signalNum) {
    case 2: {
        terminate();
        break;
    }
    case 15: {
        shutDown();
        break;
    }
    default: {
        fprintf(stderr, "\033[31mUnhandled signal %d\n\033[00m", signalNum);
        break;
    }
  }
}

canonical_original_code:
void sigHandler(int signalNum) {
  switch(signalNum) {
    case 2: {
        terminate();
        break;
    }
    case 15: {
        shutDown();
        break;
    }
    default: {
        fprintf(stderr, "\033[31mUnhandled signal %d\n\033[00m", signalNum);
        break;
    }
  }
}

variable_types: signalNum int


setSigHandler

decompiled_code:
__int64 setSigHandler()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)sigHandler;
sigaction(2, &v1, 0LL);
resourcesList = createSList();
return initSList(resourcesList, &pseudoArgPass, restoreTerm, &freeNode);
}

canonical_decompiled_code:
__int64 func5()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)sigHandler;
sigaction(2, &v1, 0LL);
resourcesList = createSList();
return initSList(resourcesList, &pseudoArgPass, restoreTerm, &freeNode);
}

original_code:
void setSigHandler() {
  struct sigaction theAction;
  theAction.__sigaction_handler.sa_handler = sigHandler;
  sigaction(2, &theAction, ((void *)0));
  resourcesList = createSList();
  initSList(resourcesList, pseudoArgPass, restoreTerm, freeNode);
}

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

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

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


addToTrackedResources

decompiled_code:
__int64 __fastcall addToTrackedResources(__int64 a1)
{
__int64 v1; // r12

v1 = (unsigned int)addToList(resourcesList, a1);
printf("Add Status :%d\n", v1);
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // r12

v1 = (unsigned int)addToList(resourcesList, a1);
printf("Add Status :%d\n", v1);
return (unsigned int)v1;
}

original_code:
int addToTrackedResources(void *termToTrack) {
  int addStatus = addToList(resourcesList, termToTrack);
  printf("Add Status :%d\n", addStatus);
  return addStatus;
}

variable_types:
termToTrack
void *

variable_types: addStatus int


decompiled_code:
__pid_t sigchld_handler()
{
__pid_t result; // eax

do
result = waitpid(-1, 0LL, 1);
while ( result > 0 );
return result;
}

canonical_decompiled_code:
__pid_t func7()
{
__pid_t result; // eax

do
result = waitpid(-1, 0LL, 1);
while ( result > 0 );
return result;
}

original_code:
void sigchld_handler(const int s) {
  while(waitpid(-1, ((void *)0), 1) > 0);
}

canonical_original_code:
void sigchld_handler(int s) {
  while(waitpid(-1, ((void *)0), 1) > 0);
}

variable_types: s int


createSList

decompiled_code:
_QWORD *createSList()
{
_QWORD *result; // rax

result = malloc(0x30uLL);
if ( !result )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "createSList", 20LL);
fwrite("Run-out of memory, please release or debug memory allocations", 1uLL, 0x3DuLL, stderr);
exit(-2);
}
*(_DWORD *)result = 0;
result[2] = 0LL;
result[1] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
return result;
}

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

result = malloc(0x30uLL);
if ( !result )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "createSList", 20LL);
fwrite("Run-out of memory, please release or debug memory allocations", 1uLL, 0x3DuLL, stderr);
exit(-2);
}
*(_DWORD *)result = 0;
result[2] = 0LL;
result[1] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
return result;
}

original_code:
SList *createSList(void) {
  SList *newSL = ((void *)0);
  if ((newSL = (SList *)malloc(sizeof(SList))) == ((void *)0)) {
    { { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 20); fprintf(stderr, "Run-out of memory, please release or debug memory allocations"); }; exit(-2); };
  }
  newSL->size = 0;
  newSL->head = newSL->tail = ((void *)0);
  newSL->copyData = ((void *)0);
  newSL->freeData = ((void *)0);
  newSL->freeNode = ((void *)0);
  return newSL;
}

canonical_original_code:
struct SList *createSList() {
  struct SList *newSL = ((void *)0);
  if ((newSL = (struct SList *)malloc(sizeof(SList))) == ((void *)0)) {
    { { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 20); fprintf(stderr, "Run-out of memory, please release or debug memory allocations"); }; exit(-2); };
  }
  newSL->size = 0;
  newSL->head = newSL->tail = ((void *)0);
  newSL->copyData = ((void *)0);
  newSL->freeData = ((void *)0);
  newSL->freeNode = ((void *)0);
  return newSL;
}

variable_types: struct SList { int size; struct Node_ { void *data; int visits; void (*freeFunc)(void *); void *(*dataCopier)(void *); struct Node_ *next; } *head; void *(*copyData)(void *); void (*freeData)(void *); int (*freeNode)(struct Node_ *, void (*)(void *)); } *

user_defined_types: struct SList { int size; struct Node_ *head; void *(*copyData)(void *); void (*freeData)(void *); int (*freeNode)(struct Node_ *, void (*)(void *)); }


freeNode

decompiled_code:
__int64 __fastcall freeNode(void *ptr, void (__fastcall *a2)(_QWORD))
{
void (__fastcall *v2)(_QWORD); // r13
_QWORD *v3; // rbx
unsigned int v4; // er12
_QWORD *v5; // rbp
__int64 result; // rax

if ( ptr )
{
v2 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 2);
v3 = ptr;
if ( !v2 )
{
if ( !a2 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "freeNode", 48LL);
fwrite("DataFree function cannot be NULL", 1uLL, 0x20uLL, stderr);
return 0LL;
}
v2 = a2;
}
v4 = 0;
do
{
v5 = v3;
v3 = (_QWORD *)v3[4];
++v4;
v2(*v5);
free(v5);
}
while ( v3 );
result = v4;
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "freeNode", 63LL);
fwrite("NULL node cannot be freed", 1uLL, 0x19uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr, void (__fastcall *a2)(_QWORD))
{
void (__fastcall *v2)(_QWORD); // r13
_QWORD *v3; // rbx
unsigned int v4; // er12
_QWORD *v5; // rbp
__int64 result; // rax

if ( ptr )
{
v2 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 2);
v3 = ptr;
if ( !v2 )
{
if ( !a2 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "freeNode", 48LL);
fwrite("DataFree function cannot be NULL", 1uLL, 0x20uLL, stderr);
return 0LL;
}
v2 = a2;
}
v4 = 0;
do
{
v5 = v3;
v3 = (_QWORD *)v3[4];
++v4;
v2(*v5);
free(v5);
}
while ( v3 );
result = v4;
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "freeNode", 63LL);
fwrite("NULL node cannot be freed", 1uLL, 0x19uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int freeNode(Node *n, void (*freeData)(void *)) {
  int freeCount = 0;
  if (n != ((void *)0)) {
    void (*dataFreer)(void *) = freeData;
    if (n->freeFunc != ((void *)0))
      dataFreer = n->freeFunc;
    if (dataFreer == ((void *)0)) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 48); fprintf(stderr, "DataFree function cannot be NULL"); };
    } else {
      while (n != ((void *)0)) {
 Node *tmp = n->next;
 dataFreer(n->data);
 free(n);
 n = tmp;
 ++freeCount;
      }
    }
  } else {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 63); fprintf(stderr, "NULL node cannot be freed"); };
  }
  return freeCount;
}

canonical_original_code:
int freeNode(struct Node_ *n, void (*freeData)(void *)) {
  int freeCount = 0;
  if (n != ((void *)0)) {
    void (*dataFreer)(void *) = freeData;
    if (n->freeFunc != ((void *)0))
      dataFreer = n->freeFunc;
    if (dataFreer == ((void *)0)) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 48); fprintf(stderr, "DataFree function cannot be NULL"); };
    } else {
      while (n != ((void *)0)) {
 struct Node_ *tmp = n->next;
 dataFreer(n->data);
 free(n);
 n = tmp;
 ++freeCount;
      }
    }
  } else {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 63); fprintf(stderr, "NULL node cannot be freed"); };
  }
  return freeCount;
}

variable_types: struct Node_ { void *data; int visits; void (*freeFunc)(void *); void *(*dataCopier)(void *); struct Node_ *next; } *

variable_types:
freeData
void (*)(void *)

variable_types: freeCount int

variable_types:
dataFreer
void (*)(void *)


freeSList

decompiled_code:
__int64 __fastcall freeSList(void *ptr)
{
__int64 v1; // rbx

if ( !ptr )
return 0LL;
v1 = (*((unsigned int (__fastcall **)(_QWORD, _QWORD))ptr + 5))(*((_QWORD *)ptr + 1), *((_QWORD *)ptr + 4));
printf("nFrees: %d\n", v1);
if ( *(_DWORD *)ptr != (_DWORD)v1 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "freeSList", 78LL);
fwrite("Number of freed nodes is not equal to the SL size", 1uLL, 0x31uLL, stderr);
}
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
__int64 v1; // rbx

if ( !ptr )
return 0LL;
v1 = (*((unsigned int (__fastcall **)(_QWORD, _QWORD))ptr + 5))(*((_QWORD *)ptr + 1), *((_QWORD *)ptr + 4));
printf("nFrees: %d\n", v1);
if ( *(_DWORD *)ptr != (_DWORD)v1 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "freeSList", 78LL);
fwrite("Number of freed nodes is not equal to the SL size", 1uLL, 0x31uLL, stderr);
}
free(ptr);
return 0LL;
}

original_code:
int freeSList(SList *sl) {
  int freeCount = 0;
  if (sl != ((void *)0)) {
    int nFrees = sl->freeNode(sl->head, sl->freeData);
    printf("nFrees: %d\n", nFrees);
    if (nFrees != sl->size) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 78); fprintf(stderr, "Number of freed nodes is not equal to the SL size"); };
    }
    sl->size = 0;
    free(sl);
    sl = ((void *)0);
  }
  return freeCount;
}

canonical_original_code:
int freeSList(struct SList *sl) {
  int freeCount = 0;
  if (sl != ((void *)0)) {
    int nFrees = sl->freeNode(sl->head, sl->freeData);
    printf("nFrees: %d\n", nFrees);
    if (nFrees != sl->size) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 78); fprintf(stderr, "Number of freed nodes is not equal to the SL size"); };
    }
    sl->size = 0;
    free(sl);
    sl = ((void *)0);
  }
  return freeCount;
}

variable_types: nFrees int

user_defined_types: struct Node_ { void *data; int visits; void (*freeFunc)(void *); void *(*dataCopier)(void *); struct Node_ *next; }


pseudoArgPass

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

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

original_code:
void *pseudoArgPass(void *arg) {
  return arg;
}

variable_types:
arg
void *


addToListWithFuncs

decompiled_code:
__int64 __fastcall addToListWithFuncs(__int64 a1, const void *a2, __int64 (__fastcall *a3)(const void *), __int64 a4)
{
_QWORD *v4; // rax
__int64 v5; // rdx
__int64 result; // rax
_QWORD *v7; // rax

if ( a1 )
{
if ( a3 || (a3 = *(__int64 (__fastcall **)(const void *))(a1 + 24)) != 0LL )
{
if ( *(_QWORD *)(a1 + 8) )
{
v4 = addNodeAndFunc(*(_QWORD *)(a1 + 16), a2, a3, a4);
v5 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 16) = v4;
if ( v4 != *(_QWORD **)(v5 + 32) )
*(_QWORD *)(v5 + 32) = v4;
}
else
{
v7 = addNodeAndFunc(0LL, a2, a3, a4);
*(_QWORD *)(a1 + 8) = v7;
*(_QWORD *)(a1 + 16) = v7[4];
}
++*(_DWORD *)a1;
result = 1LL;
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "addToListWithFuncs", 194LL);
fwrite("copyData function of SL is NULL. Please initialize it first", 1uLL, 0x3BuLL, stderr);
result = 0LL;
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "addToListWithFuncs", 183LL);
fwrite("NULL SL passed in. First create SL", 1uLL, 0x22uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const void *a2, __int64 (__fastcall *a3)(const void *), __int64 a4)
{
_QWORD *v4; // rax
__int64 v5; // rdx
__int64 result; // rax
_QWORD *v7; // rax

if ( a1 )
{
if ( a3 || (a3 = *(__int64 (__fastcall **)(const void *))(a1 + 24)) != 0LL )
{
if ( *(_QWORD *)(a1 + 8) )
{
v4 = addNodeAndFunc(*(_QWORD *)(a1 + 16), a2, a3, a4);
v5 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 16) = v4;
if ( v4 != *(_QWORD **)(v5 + 32) )
*(_QWORD *)(v5 + 32) = v4;
}
else
{
v7 = addNodeAndFunc(0LL, a2, a3, a4);
*(_QWORD *)(a1 + 8) = v7;
*(_QWORD *)(a1 + 16) = v7[4];
}
++*(_DWORD *)a1;
result = 1LL;
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "addToListWithFuncs", 194LL);
fwrite("copyData function of SL is NULL. Please initialize it first", 1uLL, 0x3BuLL, stderr);
result = 0LL;
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "addToListWithFuncs", 183LL);
fwrite("NULL SL passed in. First create SL", 1uLL, 0x22uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int addToListWithFuncs(
  SList *sl, void *data, void *(*copier)(void *), void (*dataFreer)(void *)
) {
  if (sl == ((void *)0)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 183); fprintf(stderr, "NULL SL passed in. First create SL"); };
    return 0;
  } else {
    void * (*copyingFunc)(void *) = sl->copyData;
    if (copier != ((void *)0))
      copyingFunc = copier;
    if (copyingFunc == ((void *)0)) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 194); fprintf(stderr, "copyData function of SL is NULL. Please initialize it first"); };
      return 0;
    }
    if (sl->head == ((void *)0)) {
      sl->head = addNodeAndFunc(sl->head, data, copyingFunc, dataFreer);
      sl->tail = sl->head->next;
    } else {
      sl->tail = addNodeAndFunc(sl->tail, data, copyingFunc, dataFreer);
    }
    if (sl->head->next != sl->tail)
      sl->head->next = sl->tail;
    ++(sl->size);
    return 1;
  }
}

canonical_original_code:
int addToListWithFuncs(struct SList *sl, void *data, void *(*copier)(void *), void (*dataFreer)(void *)) {
  if (sl == ((void *)0)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 183); fprintf(stderr, "NULL SL passed in. First create SL"); };
    return 0;
  } else {
    void *(*copyingFunc)(void *) = sl->copyData;
    if (copier != ((void *)0))
      copyingFunc = copier;
    if (copyingFunc == ((void *)0)) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 194); fprintf(stderr, "copyData function of SL is NULL. Please initialize it first"); };
      return 0;
    }
    if (sl->head == ((void *)0)) {
      sl->head = addNodeAndFunc(sl->head, data, copyingFunc, dataFreer);
      sl->tail = sl->head->next;
    } else {
      sl->tail = addNodeAndFunc(sl->tail, data, copyingFunc, dataFreer);
    }
    if (sl->head->next != sl->tail)
      sl->head->next = sl->tail;
    ++(sl->size);
    return 1;
  }
}

variable_types:
data
void *

variable_types:
copier
void *(*)(void *)

variable_types:
copyingFunc
void *(*)(void *)


addToList

decompiled_code:
__int64 __fastcall addToList(__int64 a1, const void *a2)
{
return addToListWithFuncs(a1, a2, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const void *a2)
{
return func5(a1, a2, 0LL, 0LL);
}

original_code:
int addToList(SList *sl, void *data) {
  return addToListWithFuncs(sl, data, ((void *)0), ((void *)0));
}

canonical_original_code:
int addToList(struct SList *sl, void *data) {
  return addToListWithFuncs(sl, data, ((void *)0), ((void *)0));
}


strCopier

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

if ( a1 )
result = strdup(a1);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = strdup(a1);
else
result = 0LL;
return result;
}

original_code:
void *strCopier(void *data) {
  return data == ((void *)0) ? ((void *)0) : (void *)strdup((char *)data);
}


peek

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

if ( a1 )
result = getData(*(_QWORD *)(a1 + 8));
else
result = 0LL;
return result;
}

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

if ( a1 )
result = getData(*(_QWORD *)(a1 + 8));
else
result = 0LL;
return result;
}

original_code:
inline void *peek(SList *sl) {
  return sl == ((void *)0) ? ((void *)0) : getData(sl->head);
}

canonical_original_code:
inline void *peek(struct SList *sl) {
  return sl == ((void *)0) ? ((void *)0) : getData(sl->head);
}


pop

decompiled_code:
__int64 __fastcall pop(__int64 a1)
{
void *v1; // rbp
__int64 v2; // r12

if ( !(unsigned int)getSize() )
{
v2 = 0LL;
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "pop", 240LL);
fwrite("Cannot pop from a NULL sl", 1uLL, 0x19uLL, stderr);
return v2;
}
v1 = *(void **)(a1 + 8);
if ( v1 )
{
v2 = getData(*(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = getNext(v1);
free(v1);
--*(_DWORD *)a1;
return v2;
}
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "pop", 256LL);
fwrite("Trying to pop from an empty node", 1uLL, 0x20uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
void *v1; // rbp
__int64 v2; // r12

if ( !(unsigned int)getSize() )
{
v2 = 0LL;
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "pop", 240LL);
fwrite("Cannot pop from a NULL sl", 1uLL, 0x19uLL, stderr);
return v2;
}
v1 = *(void **)(a1 + 8);
if ( v1 )
{
v2 = getData(*(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = getNext(v1);
free(v1);
--*(_DWORD *)a1;
return v2;
}
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "pop", 256LL);
fwrite("Trying to pop from an empty node", 1uLL, 0x20uLL, stderr);
return 0LL;
}

original_code:
void *pop(SList *sl) {
  if (! getSize(sl)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 240); fprintf(stderr, "Cannot pop from a NULL sl"); };
    return ((void *)0);
  } else {
    Node *prevHead = sl->head;
    if (sl->head != ((void *)0)) {
      void *copiedData = getData(sl->head);
      sl->head = getNext(sl->head);
      free(prevHead);
      prevHead = ((void *)0);
      --sl->size;
      return copiedData;
    } else {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 256); fprintf(stderr, "Trying to pop from an empty node"); };
      return ((void *)0);
    }
  }
}

canonical_original_code:
void *pop(struct SList *sl) {
  if (! getSize(sl)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 240); fprintf(stderr, "Cannot pop from a NULL sl"); };
    return ((void *)0);
  } else {
    struct Node_ *prevHead = sl->head;
    if (sl->head != ((void *)0)) {
      void *copiedData = getData(sl->head);
      sl->head = getNext(sl->head);
      free(prevHead);
      prevHead = ((void *)0);
      --sl->size;
      return copiedData;
    } else {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 256); fprintf(stderr, "Trying to pop from an empty node"); };
      return ((void *)0);
    }
  }
}

variable_types:
copiedData
void *


matchBaudRate

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

if ( a1 == 1200 )
return 9LL;
if ( a1 > 1200 )
{
if ( a1 == 19200 )
return 14LL;
if ( a1 <= 19200 )
{
result = 12LL;
if ( a1 != 4800 )
{
if ( a1 <= 4800 )
{
result = 10LL;
if ( a1 != 1800 )
{
if ( a1 == 2400 )
return 11LL;
goto LABEL_12;
}
}
else
{
result = 13LL;
if ( a1 != 9600 )
goto LABEL_12;
}
}
}
else
{
result = 4098LL;
if ( a1 != 115200 )
{
if ( a1 <= 115200 )
{
result = 15LL;
if ( a1 != 38400 )
{
if ( a1 == 57600 )
return 4097LL;
goto LABEL_12;
}
}
else
{
result = 4099LL;
if ( a1 != 230400 )
goto LABEL_12;
}
}
}
}
else
{
if ( a1 == 134 )
return 4LL;
if ( a1 <= 134 )
{
result = 2LL;
if ( a1 != 75 )
{
if ( a1 <= 75 )
{
result = 0LL;
if ( a1 )
{
if ( a1 == 50 )
return 1LL;
goto LABEL_12;
}
}
else
{
result = 3LL;
if ( a1 != 110 )
goto LABEL_12;
}
}
}
else
{
result = 7LL;
if ( a1 == 300 )
return result;
if ( a1 > 300 )
{
result = 8LL;
if ( a1 == 600 )
return result;
LABEL_12:
printf("bad baudrate %d\n", (unsigned int)a1);
return 0xFFFFFFFFLL;
}
result = 5LL;
if ( a1 != 150 )
{
if ( a1 == 200 )
return 6LL;
goto LABEL_12;
}
}
}
return result;
}

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

if ( a1 == 1200 )
return 9LL;
if ( a1 > 1200 )
{
if ( a1 == 19200 )
return 14LL;
if ( a1 <= 19200 )
{
result = 12LL;
if ( a1 != 4800 )
{
if ( a1 <= 4800 )
{
result = 10LL;
if ( a1 != 1800 )
{
if ( a1 == 2400 )
return 11LL;
goto LABEL_12;
}
}
else
{
result = 13LL;
if ( a1 != 9600 )
goto LABEL_12;
}
}
}
else
{
result = 4098LL;
if ( a1 != 115200 )
{
if ( a1 <= 115200 )
{
result = 15LL;
if ( a1 != 38400 )
{
if ( a1 == 57600 )
return 4097LL;
goto LABEL_12;
}
}
else
{
result = 4099LL;
if ( a1 != 230400 )
goto LABEL_12;
}
}
}
}
else
{
if ( a1 == 134 )
return 4LL;
if ( a1 <= 134 )
{
result = 2LL;
if ( a1 != 75 )
{
if ( a1 <= 75 )
{
result = 0LL;
if ( a1 )
{
if ( a1 == 50 )
return 1LL;
goto LABEL_12;
}
}
else
{
result = 3LL;
if ( a1 != 110 )
goto LABEL_12;
}
}
}
else
{
result = 7LL;
if ( a1 == 300 )
return result;
if ( a1 > 300 )
{
result = 8LL;
if ( a1 == 600 )
return result;
LABEL_12:
printf("bad baudrate %d\n", (unsigned int)a1);
return 0xFFFFFFFFLL;
}
result = 5LL;
if ( a1 != 150 )
{
if ( a1 == 200 )
return 6LL;
goto LABEL_12;
}
}
}
return result;
}

original_code:
speed_t matchBaudRate(const int speed) {
  speed_t theBaudRate;
  switch (speed) {
    case 0:
      theBaudRate = 0000000;
      break;
    case 50:
      theBaudRate = 0000001;
      break;
    case 75:
      theBaudRate = 0000002;
      break;
    case 110:
      theBaudRate = 0000003;
      break;
    case 134:
      theBaudRate = 0000004;
      break;
    case 150:
      theBaudRate = 0000005;
      break;
    case 200:
      theBaudRate = 0000006;
      break;
    case 300:
      theBaudRate = 0000007;
      break;
    case 600:
      theBaudRate = 0000010;
      break;
    case 1200:
      theBaudRate = 0000011;
      break;
    case 1800:
      theBaudRate = 0000012;
      break;
    case 2400:
      theBaudRate = 0000013;
      break;
    case 4800:
      theBaudRate = 0000014;
      break;
    case 9600:
      theBaudRate = 0000015;
      break;
    case 19200:
      theBaudRate = 0000016;
      break;
    case 38400:
      theBaudRate = 0000017;
      break;
    case 57600:
      theBaudRate = 0010001;
      break;
    case 115200:
      theBaudRate = 0010002;
      break;
    case 230400:
      theBaudRate = 0010003;
      break;
    default:
      printf("bad baudrate %d\n", speed);
      theBaudRate = -1;
  }
  return theBaudRate;
}

canonical_original_code:
unsigned int matchBaudRate(int speed) {
  unsigned int theBaudRate;
  switch (speed) {
    case 0:
      theBaudRate = 0000000;
      break;
    case 50:
      theBaudRate = 0000001;
      break;
    case 75:
      theBaudRate = 0000002;
      break;
    case 110:
      theBaudRate = 0000003;
      break;
    case 134:
      theBaudRate = 0000004;
      break;
    case 150:
      theBaudRate = 0000005;
      break;
    case 200:
      theBaudRate = 0000006;
      break;
    case 300:
      theBaudRate = 0000007;
      break;
    case 600:
      theBaudRate = 0000010;
      break;
    case 1200:
      theBaudRate = 0000011;
      break;
    case 1800:
      theBaudRate = 0000012;
      break;
    case 2400:
      theBaudRate = 0000013;
      break;
    case 4800:
      theBaudRate = 0000014;
      break;
    case 9600:
      theBaudRate = 0000015;
      break;
    case 19200:
      theBaudRate = 0000016;
      break;
    case 38400:
      theBaudRate = 0000017;
      break;
    case 57600:
      theBaudRate = 0010001;
      break;
    case 115200:
      theBaudRate = 0010002;
      break;
    case 230400:
      theBaudRate = 0010003;
      break;
    default:
      printf("bad baudrate %d\n", speed);
      theBaudRate = -1;
  }
  return theBaudRate;
}

variable_types: speed int

variable_types:
theBaudRate
unsigned int

return_type: unsigned int


decompiled_code:
int __fastcall c_init_serialFD(struct termios *termios_p, int a2, int a3)
{
speed_t v5; // eax
int v6; // edi
speed_t v7; // ebp
tcflag_t v8; // eax
__m128i v9; // xmm0
__m128i v10; // xmm1
__m128i v11; // xmm2
speed_t v12; // edx
tcflag_t v13; // eax
tcflag_t v14; // eax
tcflag_t v15; // eax

if ( !termios_p )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/cserial.c", "c_init_serialFD", 148LL);
fwrite("A non-NULL termios pair is needed to store the new term attributes", 1uLL, 0x42uLL, stderr);
exit(-2);
}
v5 = matchBaudRate(a2);
v6 = termios_p[2].c_cflag;
v7 = v5;
if ( v6 == -1 )
{
perror("opening modem serial device : fd < 0");
v6 = termios_p[2].c_cflag;
}
tcgetattr(v6, termios_p);
v8 = termios_p->c_iflag;
v9 = _mm_loadu_si128((const __m128i *)termios_p);
v10 = _mm_loadu_si128((const __m128i *)&termios_p->c_line);
*(_QWORD *)&termios_p[1].c_cc[31] = *(_QWORD *)&termios_p->c_cc[31];
v11 = _mm_loadu_si128((const __m128i *)&termios_p->c_cc[15]);
v12 = termios_p->c_ospeed;
*(__m128i *)&termios_p[1].c_iflag = v9;
*(__m128i *)&termios_p[1].c_line = v10;
termios_p[1].c_iflag = v8 & 0xFFFFC200 | 2;
v13 = termios_p[1].c_cflag;
termios_p[1].c_oflag &= 0xFFFFFFC2;
termios_p[1].c_ospeed = v12;
*(__m128i *)&termios_p[1].c_cc[15] = v11;
if ( a3 )
v14 = v13 & 0xFFFFF00F | 0x800008B0;
else
v14 = v13 & 0x7FFFF00F | 0x8B0;
termios_p[1].c_cflag = v14;
v15 = termios_p[1].c_lflag & 0xFFFF2FF4;
LOBYTE(v15) = termios_p[1].c_lflag & 0xF4 | 0x80;
termios_p[1].c_lflag = v15;
cfsetspeed(termios_p + 1, v7);
return tcsetattr(termios_p[2].c_cflag, 1, termios_p + 1);
}

canonical_decompiled_code:
int __fastcall func1(struct termios *termios_p, int a2, int a3)
{
speed_t v5; // eax
int v6; // edi
speed_t v7; // ebp
tcflag_t v8; // eax
__m128i v9; // xmm0
__m128i v10; // xmm1
__m128i v11; // xmm2
speed_t v12; // edx
tcflag_t v13; // eax
tcflag_t v14; // eax
tcflag_t v15; // eax

if ( !termios_p )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/cserial.c", "c_init_serialFD", 148LL);
fwrite("A non-NULL termios pair is needed to store the new term attributes", 1uLL, 0x42uLL, stderr);
exit(-2);
}
v5 = func0(a2);
v6 = termios_p[2].c_cflag;
v7 = v5;
if ( v6 == -1 )
{
perror("opening modem serial device : fd < 0");
v6 = termios_p[2].c_cflag;
}
tcgetattr(v6, termios_p);
v8 = termios_p->c_iflag;
v9 = _mm_loadu_si128((const __m128i *)termios_p);
v10 = _mm_loadu_si128((const __m128i *)&termios_p->c_line);
*(_QWORD *)&termios_p[1].c_cc[31] = *(_QWORD *)&termios_p->c_cc[31];
v11 = _mm_loadu_si128((const __m128i *)&termios_p->c_cc[15]);
v12 = termios_p->c_ospeed;
*(__m128i *)&termios_p[1].c_iflag = v9;
*(__m128i *)&termios_p[1].c_line = v10;
termios_p[1].c_iflag = v8 & 0xFFFFC200 | 2;
v13 = termios_p[1].c_cflag;
termios_p[1].c_oflag &= 0xFFFFFFC2;
termios_p[1].c_ospeed = v12;
*(__m128i *)&termios_p[1].c_cc[15] = v11;
if ( a3 )
v14 = v13 & 0xFFFFF00F | 0x800008B0;
else
v14 = v13 & 0x7FFFF00F | 0x8B0;
termios_p[1].c_cflag = v14;
v15 = termios_p[1].c_lflag & 0xFFFF2FF4;
LOBYTE(v15) = termios_p[1].c_lflag & 0xF4 | 0x80;
termios_p[1].c_lflag = v15;
cfsetspeed(termios_p + 1, v7);
return tcsetattr(termios_p[2].c_cflag, 1, termios_p + 1);
}

variable_types: struct TermPair { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } origTerm; struct termios newTerm; struct BaudRatePair { unsigned int inBaudRate; unsigned int outBaudRate; } baudRatePair; int fd; } *

variable_types:
selectedBaudRate
unsigned int


decompiled_code:
int __fastcall c_init_serial(struct termios *termios_p, char *file, int a3, int a4)
{
if ( !termios_p )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/cserial.c", "c_init_serial", 136LL);
fwrite("The storage for the file descriptor must not be NULL", 1uLL, 0x34uLL, stderr);
exit(-2);
}
termios_p[2].c_cflag = open(file, 2050);
return c_init_serialFD(termios_p, a3, a4);
}

canonical_decompiled_code:
int __fastcall func2(struct termios *termios_p, char *file, int a3, int a4)
{
if ( !termios_p )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/cserial.c", "c_init_serial", 136LL);
fwrite("The storage for the file descriptor must not be NULL", 1uLL, 0x34uLL, stderr);
exit(-2);
}
termios_p[2].c_cflag = open(file, 2050);
return func1(termios_p, a3, a4);
}

original_code:
void c_init_serial(
  TermPair *termStorage, const char *devicePath,
  const int speed, const Bool hw_flow_control
) {
  if (termStorage == ((void *)0)) {
    { { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/cserial.c", __func__, 136); fprintf(stderr, "The storage for the file descriptor must not be NULL"); }; exit(-2); };
  }
  termStorage->fd = open(devicePath, 02|04000);
  c_init_serialFD(termStorage, speed, hw_flow_control);
}

canonical_original_code:
void c_init_serial(struct TermPair *termStorage, char *devicePath, int speed, enum Bool hw_flow_control) {
  if (termStorage == ((void *)0)) {
    { { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/cserial.c", __func__, 136); fprintf(stderr, "The storage for the file descriptor must not be NULL"); }; exit(-2); };
  }
  termStorage->fd = open(devicePath, 02|04000);
  c_init_serialFD(termStorage, speed, hw_flow_control);
}

variable_types:
devicePath
char *

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

user_defined_types: struct BaudRatePair { unsigned int inBaudRate; unsigned int outBaudRate; }


decompiled_code:
__int64 __fastcall c_set_dtr(int fd, int a2)
{
int v2; // eax
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

ioctl(fd, 0x5415uLL, v4);
if ( a2 )
v2 = v4[0] | 2;
else
v2 = v4[0] & 0xFFFFFFFD;
v4[0] = v2;
ioctl(fd, 0x5418uLL, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, int a2)
{
int v2; // eax
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

ioctl(fd, 0x5415uLL, v4);
if ( a2 )
v2 = v4[0] | 2;
else
v2 = v4[0] & 0xFFFFFFFD;
v4[0] = v2;
ioctl(fd, 0x5418uLL, v4);
return 0LL;
}

original_code:
int c_set_dtr(int fd, Bool val_bit) {
  int status;
  ioctl(fd, 0x5415, &status);
  if (val_bit)
    status |= 0x002;
  else
    status &= ~0x002;
  ioctl(fd, 0x5418, &status);
  return 0;
}

canonical_original_code:
int c_set_dtr(int fd, enum Bool val_bit) {
  int status;
  ioctl(fd, 0x5415, &status);
  if (val_bit)
    status |= 0x002;
  else
    status &= ~0x002;
  ioctl(fd, 0x5418, &status);
  return 0;
}

variable_types: fd int

variable_types: status int


decompiled_code:
__int64 __fastcall c_serial_set_baudrate(int fd, int a2)
{
speed_t v2; // er12
struct termios v4; // [rsp+0h] [rbp-58h] BYREF

v2 = matchBaudRate(a2);
if ( tcgetattr(fd, &v4) < 0 )
puts("tcgetattr");
v4.c_lflag &= 0xFFFFFF84;
*(_QWORD *)&v4.c_iflag = 0LL;
v4.c_cflag = 2224;
*(_WORD *)&v4.c_cc[5] = 261;
cfsetispeed(&v4, v2);
cfsetospeed(&v4, v2);
if ( tcsetattr(fd, 2, &v4) < 0 )
puts("tcsetattr");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, int a2)
{
speed_t v2; // er12
struct termios v4; // [rsp+0h] [rbp-58h] BYREF

v2 = func0(a2);
if ( tcgetattr(fd, &v4) < 0 )
puts("tcgetattr");
v4.c_lflag &= 0xFFFFFF84;
*(_QWORD *)&v4.c_iflag = 0LL;
v4.c_cflag = 2224;
*(_WORD *)&v4.c_cc[5] = 261;
cfsetispeed(&v4, v2);
cfsetospeed(&v4, v2);
if ( tcsetattr(fd, 2, &v4) < 0 )
puts("tcsetattr");
return 0LL;
}

original_code:
int c_serial_set_baudrate(int fd, const int speed) {
  struct termios tio;
  speed_t br = matchBaudRate(speed);
  if (tcgetattr(fd, &tio) < 0) {
    printf("tcgetattr\n");
  }
  tio.c_iflag = 0;
  tio.c_oflag = 0;
  tio.c_cflag = 0000060 | 0000200 | 0004000;
  tio.c_cc[6] = 1;
  tio.c_cc[5] = 5;
  tio.c_lflag &= ~(0000002 | 0000001 | 0000010 | 0000100 | 0000020 | 0000040);
  cfsetispeed(&tio, br);
  cfsetospeed(&tio, br);
  if (tcsetattr(fd, 0 | 2, &tio) < 0) {
    printf("tcsetattr\n");
  }
  return 0;
}

canonical_original_code:
int c_serial_set_baudrate(int fd, int speed) {
  struct termios tio;
  unsigned int br = matchBaudRate(speed);
  if (tcgetattr(fd, &tio) < 0) {
    printf("tcgetattr\n");
  }
  tio.c_iflag = 0;
  tio.c_oflag = 0;
  tio.c_cflag = 0000060 | 0000200 | 0004000;
  tio.c_cc[6] = 1;
  tio.c_cc[5] = 5;
  tio.c_lflag &= ~(0000002 | 0000001 | 0000010 | 0000100 | 0000020 | 0000040);
  cfsetispeed(&tio, br);
  cfsetospeed(&tio, br);
  if (tcsetattr(fd, 0 | 2, &tio) < 0) {
    printf("tcsetattr\n");
  }
  return 0;
}

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

variable_types:
br
unsigned int


dTest

decompiled_code:
int *__fastcall dTest(int *a1)
{
int *result; // rax

result = a1;
if ( *a1 > 0 )
{
result = 0LL;
--*a1;
}
return result;
}

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

result = a1;
if ( *a1 > 0 )
{
result = 0LL;
--*a1;
}
return result;
}

original_code:
void *dTest(void *data) {
  int *tP = (int *)data;
  if (*tP > 0) {
    --(*tP);
    return ((void *)0);
  }
  return tP;
}

variable_types:
tP
int *


initPollThStruct

original_code:
void initPollThStruct(
  pollThStruct *pTSt, double timeOut,
  void *errorValue, Comparison comp(void *, void *)
) {
  if (pTSt != ((void *)0)) {
    pTSt->tryCount = INIT_TRY_COUNT;
    pTSt->timeOut = timeOut;
    pTSt->errorValue = errorValue;
    pTSt->valComp = comp;
  }
}

canonical_original_code:
void initPollThStruct(struct pollThStruct *pTSt, double timeOut, void *errorValue, enum Comparison comp(void *, void *)) {
  if (pTSt != ((void *)0)) {
    pTSt->tryCount = INIT_TRY_COUNT;
    pTSt->timeOut = timeOut;
    pTSt->errorValue = errorValue;
    pTSt->valComp = comp;
  }
}

variable_types: struct pollThStruct { void *arg; void *errorValue; void *savSuccess; double timeOut; unsigned int tryCount; void *(*funcToRun)(void *data); enum Comparison { LT=-1, EQ=0, GT=1 } (*valComp)(void *, void *); } *

variable_types: timeOut double

variable_types:
errorValue
void *

variable_types: enum Comparison { LT=-1, EQ=0, GT=1 } (void *, void *)

user_defined_types: struct pollThStruct { void *arg; void *errorValue; void *savSuccess; double timeOut; unsigned int tryCount; void *(*funcToRun)(void *data); enum Comparison (*valComp)(void *, void *); }


pollTill

decompiled_code:
size_t __fastcall pollTill(__int64 a1)
{
double i; // r14
FILE *v3; // rdi
__int64 v4; // rdx
__int64 v5; // rax
__int64 v6; // rsi
size_t result; // rax

if ( a1 )
{
for ( i = *(double *)(a1 + 24); ; sleep((int)i) )
{
v5 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 40))(*(_QWORD *)a1);
v6 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 16) = v5;
if ( (*(unsigned int (__fastcall **)(__int64, __int64))(a1 + 48))(v5, v6) )
break;
clearCursorLine(stderr);
v3 = stderr;
v4 = (unsigned int)(*(_DWORD *)(a1 + 32) + 1);
*(_DWORD *)(a1 + 32) = v4;
fprintf(v3, "Try Count: %d Sleeping for %1.2f seconds\r", v4, i);
}
result = fwrite("\x1B[33mDone Polling as condition met\n\x1B[00m", 1uLL, 0x28uLL, stderr);
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/polling.c", "pollTill", 35LL);
result = fwrite("NULL pollThStruct passed in", 1uLL, 0x1BuLL, stderr);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func2(__int64 a1)
{
double i; // r14
FILE *v3; // rdi
__int64 v4; // rdx
__int64 v5; // rax
__int64 v6; // rsi
size_t result; // rax

if ( a1 )
{
for ( i = *(double *)(a1 + 24); ; sleep((int)i) )
{
v5 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 40))(*(_QWORD *)a1);
v6 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 16) = v5;
if ( (*(unsigned int (__fastcall **)(__int64, __int64))(a1 + 48))(v5, v6) )
break;
clearCursorLine(stderr);
v3 = stderr;
v4 = (unsigned int)(*(_DWORD *)(a1 + 32) + 1);
*(_DWORD *)(a1 + 32) = v4;
fprintf(v3, "Try Count: %d Sleeping for %1.2f seconds\r", v4, i);
}
result = fwrite("\x1B[33mDone Polling as condition met\n\x1B[00m", 1uLL, 0x28uLL, stderr);
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/polling.c", "pollTill", 35LL);
result = fwrite("NULL pollThStruct passed in", 1uLL, 0x1BuLL, stderr);
}
return result;
}

original_code:
void pollTill(pollThStruct *pollTST) {
  if (pollTST == ((void *)0)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/polling.c", __func__, 35); fprintf(stderr, "NULL pollThStruct passed in"); };
    return;
  }
  const double timeOutSecs = pollTST->timeOut;
  while (1) {
    pollTST->savSuccess = pollTST->funcToRun(pollTST->arg);
    Comparison vComparison = pollTST->valComp(
      pollTST->savSuccess, pollTST->errorValue
    );
    if (vComparison != EQ) {
      fprintf(stderr, "\033[33mDone Polling as condition met\n\033[00m");
      break;
    } else {
      clearCursorLine(stderr);
      fprintf(stderr, "Try Count: %d Sleeping for %1.2f seconds\r",
        ++(pollTST->tryCount), timeOutSecs);
    }
    sleep(timeOutSecs);
  }
}

canonical_original_code:
void pollTill(struct pollThStruct *pollTST) {
  if (pollTST == ((void *)0)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/polling.c", __func__, 35); fprintf(stderr, "NULL pollThStruct passed in"); };
    return;
  }
  double timeOutSecs = pollTST->timeOut;
  while (1) {
    pollTST->savSuccess = pollTST->funcToRun(pollTST->arg);
    enum Comparison vComparison = pollTST->valComp(
      pollTST->savSuccess, pollTST->errorValue
    );
    if (vComparison != EQ) {
      fprintf(stderr, "\033[33mDone Polling as condition met\n\033[00m");
      break;
    } else {
      clearCursorLine(stderr);
      fprintf(stderr, "Try Count: %d Sleeping for %1.2f seconds\r",
        ++(pollTST->tryCount), timeOutSecs);
    }
    sleep(timeOutSecs);
  }
}

variable_types: timeOutSecs double

variable_types:
vComparison
enum Comparison { LT=-1, EQ=0, GT=1 }


intPtrComp

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

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 >= *a2) - 1;
return result;
}

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

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 >= *a2) - 1;
return result;
}

canonical_original_code:
enum Comparison intPtrComp(void *a, void *b) {
  int *aInt = (int *)a;
  int *bInt = (int *)b;
  if (*aInt != *bInt) {
    return *aInt < *bInt ? LT : GT;
  }
  return EQ;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
aInt
int *

variable_types:
bInt
int *

return_type: enum Comparison { LT=-1, EQ=0, GT=1 }


getChars

decompiled_code:
__int64 __fastcall getChars(int fd, _BYTE *a2, int a3, _DWORD *a4)
{
int v4; // ebx
_BYTE *v6; // r15
int v7; // er14
int v8; // eax
__int64 result; // rax
char buf[57]; // [rsp+Fh] [rbp-39h] BYREF

if ( a2 )
{
if ( fd == -1 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/ioLib.c", "getChars", 29LL);
fwrite("NULL file descriptor cannot be read from.", 1uLL, 0x29uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v4 = a3;
v6 = a2;
v7 = 0;
if ( a3 > 0 )
{
while ( 1 )
{
v8 = read(fd, buf, 1uLL);
if ( !v8 )
break;
if ( v8 == -1 )
goto LABEL_9;
++v7;
*v6++ = buf[0];
if ( v4 == v7 )
goto LABEL_12;
}
*a4 = 1;
LABEL_9:
if ( !v7 )
goto LABEL_10;
v4 = v7;
LABEL_12:
a2[v4] = 0;
result = (unsigned int)v4;
}
else
{
LABEL_10:
result = 0LL;
}
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/ioLib.c", "getChars", 23LL);
fwrite("NULL string storage passed in.", 1uLL, 0x1EuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, _BYTE *a2, int a3, _DWORD *a4)
{
int v4; // ebx
_BYTE *v6; // r15
int v7; // er14
int v8; // eax
__int64 result; // rax
char buf[57]; // [rsp+Fh] [rbp-39h] BYREF

if ( a2 )
{
if ( fd == -1 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/ioLib.c", "getChars", 29LL);
fwrite("NULL file descriptor cannot be read from.", 1uLL, 0x29uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v4 = a3;
v6 = a2;
v7 = 0;
if ( a3 > 0 )
{
while ( 1 )
{
v8 = read(fd, buf, 1uLL);
if ( !v8 )
break;
if ( v8 == -1 )
goto LABEL_9;
++v7;
*v6++ = buf[0];
if ( v4 == v7 )
goto LABEL_12;
}
*a4 = 1;
LABEL_9:
if ( !v7 )
goto LABEL_10;
v4 = v7;
LABEL_12:
a2[v4] = 0;
result = (unsigned int)v4;
}
else
{
LABEL_10:
result = 0LL;
}
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/ioLib.c", "getChars", 23LL);
fwrite("NULL string storage passed in.", 1uLL, 0x1EuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int getChars(int fd, char *destStr, const int len, int *eofState) {
  if (destStr == ((void *)0)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/ioLib.c", __func__, 23); fprintf(stderr, "NULL string storage passed in."); };
    return -1;
  }
  if (fd == ERROR_SOCKFD_VALUE) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/ioLib.c", __func__, 29); fprintf(stderr, "NULL file descriptor cannot be read from."); };
    return -1;
  }
  char c;
  int nAdded = 0;
  for (; nAdded < len; ++nAdded) {
    int readResult = read(fd, &c, 1);
    if (readResult == 0) {
      *eofState = True;
      break;
    } else if (readResult == -1)
        break;
    destStr[nAdded] = c;
  }
  if (nAdded)
    destStr[nAdded] = '\0';
  return nAdded;
}

canonical_original_code:
int getChars(int fd, char *destStr, int len, int *eofState) {
  if (destStr == ((void *)0)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/ioLib.c", __func__, 23); fprintf(stderr, "NULL string storage passed in."); };
    return -1;
  }
  if (fd == ERROR_SOCKFD_VALUE) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/ioLib.c", __func__, 29); fprintf(stderr, "NULL file descriptor cannot be read from."); };
    return -1;
  }
  char c;
  int nAdded = 0;
  for (; nAdded < len; ++nAdded) {
    int readResult = read(fd, &c, 1);
    if (readResult == 0) {
      *eofState = True;
      break;
    } else if (readResult == -1)
        break;
    destStr[nAdded] = c;
  }
  if (nAdded)
    destStr[nAdded] = '\0';
  return nAdded;
}

variable_types:
destStr
char *

variable_types: len int

variable_types:
eofState
int *

variable_types: c char

variable_types: nAdded int

variable_types: readResult int


freeWord

decompiled_code:
__int64 __fastcall freeWord(void *a1)
{
if ( !a1 )
return 0LL;
free(a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *a1)
{
if ( !a1 )
return 0LL;
free(a1);
return 1LL;
}

canonical_original_code:
enum Bool freeWord(char *w) {
  if (w == ((void *)0)) return False;
  free(w);
  w = ((void *)0);
  return True;
}

variable_types:
w
char *

return_type: enum Bool { False=0, True=1 }


flushTermSettings

decompiled_code:
__int64 __fastcall flushTermSettings(const struct termios *a1)
{
int v1; // er8
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = a1[2].c_cflag;
result = 0LL;
if ( v1 != -1 )
{
tcsetattr(v1, 0, a1 + 1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const struct termios *a1)
{
int v1; // er8
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = a1[2].c_cflag;
result = 0LL;
if ( v1 != -1 )
{
tcsetattr(v1, 0, a1 + 1);
result = 1LL;
}
return result;
}

original_code:
Bool flushTermSettings(TermPair *tP) {
  if (tP == ((void *)0)) return False;
  if (tP->fd == ERROR_SOCKFD_VALUE) return False;
  tcsetattr(tP->fd, 0, &(tP->newTerm));
  return True;
}

canonical_original_code:
enum Bool flushTermSettings(struct TermPair *tP) {
  if (tP == ((void *)0)) return False;
  if (tP->fd == ERROR_SOCKFD_VALUE) return False;
  tcsetattr(tP->fd, 0, &(tP->newTerm));
  return True;
}

variable_types: struct TermPair { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } origTerm; struct termios newTerm; struct BaudRatePair { unsigned int inBaudRate; unsigned int outBaudRate; } baudRatePair; int fd; } *


setBaudRate

decompiled_code:
__int64 __fastcall setBaudRate(struct termios *a1, __int64 a2)
{
__int64 result; // rax
struct termios *v3; // r12

if ( !a1 )
return 0LL;
result = 0LL;
if ( a1[2].c_cflag != -1 )
{
v3 = a1 + 1;
if ( (_DWORD)a2 == -1 )
{
if ( HIDWORD(a2) == -1 )
{
LABEL_5:
tcsetattr(a1[2].c_cflag, 0, v3);
return 1LL;
}
}
else
{
cfsetispeed(a1 + 1, a2);
if ( HIDWORD(a2) == -1 )
goto LABEL_5;
}
cfsetospeed(v3, HIDWORD(a2));
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(struct termios *a1, __int64 a2)
{
__int64 result; // rax
struct termios *v3; // r12

if ( !a1 )
return 0LL;
result = 0LL;
if ( a1[2].c_cflag != -1 )
{
v3 = a1 + 1;
if ( (_DWORD)a2 == -1 )
{
if ( HIDWORD(a2) == -1 )
{
LABEL_5:
tcsetattr(a1[2].c_cflag, 0, v3);
return 1LL;
}
}
else
{
cfsetispeed(a1 + 1, a2);
if ( HIDWORD(a2) == -1 )
goto LABEL_5;
}
cfsetospeed(v3, HIDWORD(a2));
goto LABEL_5;
}
return result;
}

original_code:
Bool setBaudRate(TermPair *tP, const BaudRatePair newBP) {
  if (tP == ((void *)0) || tP->fd == ERROR_SOCKFD_VALUE) return False;
  if (newBP.inBaudRate != ERROR_BAUD_RATE)
    cfsetispeed(&(tP->newTerm), newBP.inBaudRate);
  if (newBP.outBaudRate != ERROR_BAUD_RATE)
    cfsetospeed(&(tP->newTerm), newBP.outBaudRate);
  tcsetattr(tP->fd, 0, &(tP->newTerm));
  return True;
}

canonical_original_code:
enum Bool setBaudRate(struct TermPair *tP, struct BaudRatePair newBP) {
  if (tP == ((void *)0) || tP->fd == ERROR_SOCKFD_VALUE) return False;
  if (newBP.inBaudRate != ERROR_BAUD_RATE)
    cfsetispeed(&(tP->newTerm), newBP.inBaudRate);
  if (newBP.outBaudRate != ERROR_BAUD_RATE)
    cfsetospeed(&(tP->newTerm), newBP.outBaudRate);
  tcsetattr(tP->fd, 0, &(tP->newTerm));
  return True;
}

variable_types:
newBP
struct BaudRatePair


revertTermSettings

decompiled_code:
_BOOL8 __fastcall revertTermSettings(struct termios *termios_p)
{
int v2; // edi
_BOOL8 result; // rax

if ( !termios_p )
return 0LL;
v2 = termios_p[2].c_cflag;
result = 0LL;
if ( v2 != -1 )
result = tcsetattr(v2, 0, termios_p) != -1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(struct termios *termios_p)
{
int v2; // edi
_BOOL8 result; // rax

if ( !termios_p )
return 0LL;
v2 = termios_p[2].c_cflag;
result = 0LL;
if ( v2 != -1 )
result = tcsetattr(v2, 0, termios_p) != -1;
return result;
}

original_code:
Bool revertTermSettings(TermPair *tP) {
  if (tP == ((void *)0) || tP->fd == ERROR_SOCKFD_VALUE) return False;
  return tcsetattr(tP->fd, 0, &(tP->origTerm)) != ERROR_SETATTR_RESULT;
}

canonical_original_code:
enum Bool revertTermSettings(struct TermPair *tP) {
  if (tP == ((void *)0) || tP->fd == ERROR_SOCKFD_VALUE) return False;
  return tcsetattr(tP->fd, 0, &(tP->origTerm)) != ERROR_SETATTR_RESULT;
}


initTermPair

decompiled_code:
int __fastcall initTermPair(int fd, struct termios *a2)
{
int result; // eax

if ( fd != -1 )
{
if ( a2 )
{
tcgetattr(fd, a2);
result = tcsetattr(fd, 0, a2 + 1);
a2[2].c_cflag = fd;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(int fd, struct termios *a2)
{
int result; // eax

if ( fd != -1 )
{
if ( a2 )
{
tcgetattr(fd, a2);
result = tcsetattr(fd, 0, a2 + 1);
a2[2].c_cflag = fd;
}
}
return result;
}

original_code:
void initTermPair(const int fd, TermPair *tP) {
  if (fd != ERROR_SOCKFD_VALUE && tP != ((void *)0)) {
    tcgetattr(fd, &(tP->origTerm));
    tcsetattr(fd, 0, &(tP->newTerm));
    tP->fd = fd;
  }
}

canonical_original_code:
void initTermPair(int fd, struct TermPair *tP) {
  if (fd != ERROR_SOCKFD_VALUE && tP != ((void *)0)) {
    tcgetattr(fd, &(tP->origTerm));
    tcsetattr(fd, 0, &(tP->newTerm));
    tP->fd = fd;
  }
}

variable_types: fd int


initBaudRatePair

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

if ( !a1 )
return 0LL;
*a1 = a2;
result = 1LL;
a1[1] = a3;
return result;
}

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

if ( !a1 )
return 0LL;
*a1 = a2;
result = 1LL;
a1[1] = a3;
return result;
}

original_code:
Bool initBaudRatePair(
  BaudRatePair *bP, const speed_t inSpeed, const speed_t outSpeed
) {
  if (bP == ((void *)0)) return False;
  bP->inBaudRate = inSpeed;
  bP->outBaudRate = outSpeed;
  return True;
}

canonical_original_code:
enum Bool initBaudRatePair(struct BaudRatePair *bP, unsigned int inSpeed, unsigned int outSpeed) {
  if (bP == ((void *)0)) return False;
  bP->inBaudRate = inSpeed;
  bP->outBaudRate = outSpeed;
  return True;
}

variable_types: struct BaudRatePair { unsigned int inBaudRate; unsigned int outBaudRate; } *

variable_types:
inSpeed
unsigned int

variable_types:
outSpeed
unsigned int


initTBaudRatePair

decompiled_code:
__int64 __fastcall initTBaudRatePair(__int64 a1, int a2, int a3)
{
return initBaudRatePair((_DWORD *)(a1 + 120), a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, int a3)
{
return func7((_DWORD *)(a1 + 120), a2, a3);
}

original_code:
Bool initTBaudRatePair(
  TermPair *tP, const speed_t inBaudRate, const speed_t outBaudRate
) {
  return initBaudRatePair(&(tP->baudRatePair), inBaudRate, outBaudRate);
}

canonical_original_code:
enum Bool initTBaudRatePair(struct TermPair *tP, unsigned int inBaudRate, unsigned int outBaudRate) {
  return initBaudRatePair(&(tP->baudRatePair), inBaudRate, outBaudRate);
}

variable_types:
inBaudRate
unsigned int

variable_types:
outBaudRate
unsigned int


sendData

decompiled_code:
__int64 __fastcall sendData(int *a1, __time_t a2, __suseconds_t a3)
{
int v3; // eax
int v4; // er14
size_t v5; // rbx
__int64 v6; // rbp
__int64 v7; // r12
_BYTE *v8; // r15
size_t i; // r13
int v10; // eax
int v11; // eax
__int64 v13; // [rsp+0h] [rbp-E8h]
int v14; // [rsp+8h] [rbp-E0h]
int fd; // [rsp+Ch] [rbp-DCh]
struct timeval timeout; // [rsp+10h] [rbp-D8h] BYREF
char buf; // [rsp+2Fh] [rbp-B9h] BYREF
fd_set readfds; // [rsp+30h] [rbp-B8h] BYREF

v3 = a1[1];
v4 = *a1;
timeout.tv_sec = a2;
fd = v3;
timeout.tv_usec = a3;
memset(&readfds, 0, sizeof(readfds));
v5 = (unsigned int)a1[2];
v6 = v4 / 64;
v7 = 1LL << (v4 % 64);
readfds.fds_bits[v6] |= v7;
select(v4 + 1, &readfds, 0LL, 0LL, &timeout);
v13 = 0LL;
do
{
LABEL_2:
v8 = malloc(v5);
if ( !v8 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/connections.c", "sendData", 169LL);
fwrite("sendBuf != NULL", 1uLL, 0xFuLL, stderr);
exit(-2);
}
for ( i = 0LL; ; ++i )
{
do
{
if ( i == v5 )
{
LABEL_9:
i = (int)i;
v8[(int)i] = 0;
if ( !(_DWORD)i )
{
fprintf(stderr, "\x1B[3mTotal bytes sent: %lld\x1B[00m\r", v13);
freeWord(v8);
goto LABEL_2;
}
v14 = 0;
goto LABEL_13;
}
}
while ( (readfds.fds_bits[v6] & v7) == 0 );
v10 = read(v4, &buf, 1uLL);
if ( !v10 )
break;
if ( v10 == -1 )
goto LABEL_9;
v8[i] = buf;
}
v8[i] = 0;
if ( !(_DWORD)i )
{
freeWord(v8);
break;
}
v14 = 1;
LABEL_13:
v11 = send(fd, v8, i, 0);
if ( v11 == -1 )
perror("send");
else
v13 += v11;
fprintf(stderr, "\x1B[3mTotal bytes sent: %lld\x1B[00m\r", v13);
freeWord(v8);
}
while ( v14 != 1 );
putchar(10);
clearCursorLine(stdout);
puts("Done reading");
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, __time_t a2, __suseconds_t a3)
{
int v3; // eax
int v4; // er14
size_t v5; // rbx
__int64 v6; // rbp
__int64 v7; // r12
_BYTE *v8; // r15
size_t i; // r13
int v10; // eax
int v11; // eax
__int64 v13; // [rsp+0h] [rbp-E8h]
int v14; // [rsp+8h] [rbp-E0h]
int fd; // [rsp+Ch] [rbp-DCh]
struct timeval timeout; // [rsp+10h] [rbp-D8h] BYREF
char buf; // [rsp+2Fh] [rbp-B9h] BYREF
fd_set readfds; // [rsp+30h] [rbp-B8h] BYREF

v3 = a1[1];
v4 = *a1;
timeout.tv_sec = a2;
fd = v3;
timeout.tv_usec = a3;
memset(&readfds, 0, sizeof(readfds));
v5 = (unsigned int)a1[2];
v6 = v4 / 64;
v7 = 1LL << (v4 % 64);
readfds.fds_bits[v6] |= v7;
select(v4 + 1, &readfds, 0LL, 0LL, &timeout);
v13 = 0LL;
do
{
LABEL_2:
v8 = malloc(v5);
if ( !v8 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/connections.c", "sendData", 169LL);
fwrite("sendBuf != NULL", 1uLL, 0xFuLL, stderr);
exit(-2);
}
for ( i = 0LL; ; ++i )
{
do
{
if ( i == v5 )
{
LABEL_9:
i = (int)i;
v8[(int)i] = 0;
if ( !(_DWORD)i )
{
fprintf(stderr, "\x1B[3mTotal bytes sent: %lld\x1B[00m\r", v13);
freeWord(v8);
goto LABEL_2;
}
v14 = 0;
goto LABEL_13;
}
}
while ( (readfds.fds_bits[v6] & v7) == 0 );
v10 = read(v4, &buf, 1uLL);
if ( !v10 )
break;
if ( v10 == -1 )
goto LABEL_9;
v8[i] = buf;
}
v8[i] = 0;
if ( !(_DWORD)i )
{
freeWord(v8);
break;
}
v14 = 1;
LABEL_13:
v11 = send(fd, v8, i, 0);
if ( v11 == -1 )
perror("send");
else
v13 += v11;
fprintf(stderr, "\x1B[3mTotal bytes sent: %lld\x1B[00m\r", v13);
freeWord(v8);
}
while ( v14 != 1 );
putchar(10);
clearCursorLine(stdout);
puts("Done reading");
return v13;
}

original_code:
LLInt sendData(fdPair *fDP, struct timeval timerStruct) {
  LLInt totalSentByteCount = 0;
  int to = fDP->toFD;
  int from = fDP->fromFD;
  fd_set descriptorSet;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&descriptorSet)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&descriptorSet)->__fds_bits)[((from) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((from) % (8 * (int) sizeof (__fd_mask)))))));
  unsigned int BUF_SIZ = fDP->bufSize;
  select(from+1, &descriptorSet, ((void *)0), ((void *)0), &timerStruct);
  int eofState = False;
  while (1) {
    char *sendBuf = (char *)malloc(sizeof(char)*BUF_SIZ);
    { if (! (sendBuf != ((void *)0))) { { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/connections.c", __func__, 169); fprintf(stderr, "sendBuf != NULL"); }; exit(-2); }; };
    int nRead = 0;
    char c;
    while (nRead < BUF_SIZ) {
      if (((((&descriptorSet)->__fds_bits)[((from) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((from) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        int readResult = read(from, &c, 1);
        if (readResult == 0) {
            eofState = True;
            break;
        } else if (readResult == -1) break;
            sendBuf[nRead] = c;
            ++nRead;
      } else {
        continue;
      }
    }
    sendBuf[nRead] = '\0';
    if ((nRead == 0) && (eofState == True)) {
      freeWord(sendBuf);
      break;
    }
    if (! nRead) {
    } else {
      int sentByteCount = send(to, sendBuf, nRead, 0);
      if (sentByteCount == -1) perror("send");
      else totalSentByteCount += sentByteCount;
    }
    fprintf(
      stderr, "\033[3mTotal bytes sent: %lld\033[00m\r", totalSentByteCount
    );
    if (sendBuf != ((void *)0)) {
      freeWord(sendBuf);
    }
    if (eofState == True) break;
  }
  printf("\n");
  clearCursorLine(stdout);
  printf("Done reading\n");
  return totalSentByteCount;
}

canonical_original_code:
long long sendData(struct fdPair *fDP, struct timeval timerStruct) {
  long long totalSentByteCount = 0;
  int to = fDP->toFD;
  int from = fDP->fromFD;
  struct fd_set descriptorSet;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&descriptorSet)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&descriptorSet)->__fds_bits)[((from) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((from) % (8 * (int) sizeof (__fd_mask)))))));
  unsigned int BUF_SIZ = fDP->bufSize;
  select(from+1, &descriptorSet, ((void *)0), ((void *)0), &timerStruct);
  int eofState = False;
  while (1) {
    char *sendBuf = (char *)malloc(sizeof(char)*BUF_SIZ);
    { if (! (sendBuf != ((void *)0))) { { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/connections.c", __func__, 169); fprintf(stderr, "sendBuf != NULL"); }; exit(-2); }; };
    int nRead = 0;
    char c;
    while (nRead < BUF_SIZ) {
      if (((((&descriptorSet)->__fds_bits)[((from) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((from) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        int readResult = read(from, &c, 1);
        if (readResult == 0) {
            eofState = True;
            break;
        } else if (readResult == -1) break;
            sendBuf[nRead] = c;
            ++nRead;
      } else {
        continue;
      }
    }
    sendBuf[nRead] = '\0';
    if ((nRead == 0) && (eofState == True)) {
      freeWord(sendBuf);
      break;
    }
    if (! nRead) {
    } else {
      int sentByteCount = send(to, sendBuf, nRead, 0);
      if (sentByteCount == -1) perror("send");
      else totalSentByteCount += sentByteCount;
    }
    fprintf(
      stderr, "\033[3mTotal bytes sent: %lld\033[00m\r", totalSentByteCount
    );
    if (sendBuf != ((void *)0)) {
      freeWord(sendBuf);
    }
    if (eofState == True) break;
  }
  printf("\n");
  clearCursorLine(stdout);
  printf("Done reading\n");
  return totalSentByteCount;
}

variable_types: struct fdPair { int fromFD; int toFD; unsigned int bufSize; enum DataState { Invalid=0, Sending=1, Receiving=2 } state; } *

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

variable_types:
totalSentByteCount
long long

variable_types: to int

variable_types: from int

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

variable_types: eofState int

variable_types:
sendBuf
char *

variable_types: nRead int

variable_types: sentByteCount int

return_type: long long

user_defined_types: struct fdPair { int fromFD; int toFD; unsigned int bufSize; enum DataState state; }


recvData

decompiled_code:
__int64 __fastcall recvData(int *a1, __time_t a2, __suseconds_t a3)
{
int v3; // er15
int v4; // er13
__int64 v5; // r12
char *v6; // rax
char *v7; // r14
ssize_t v8; // rbx
size_t v9; // rbp
__int64 v11; // [rsp+8h] [rbp-D0h]
struct timeval timeout; // [rsp+10h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-B8h] BYREF

v3 = a1[1];
v4 = *a1;
timeout.tv_sec = a2;
timeout.tv_usec = a3;
memset(&readfds, 0, sizeof(readfds));
v5 = 0LL;
v11 = v4 / 64;
readfds.fds_bits[v11] |= 1LL << (v4 % 64);
select(v4 + 1, &readfds, 0LL, 0LL, &timeout);
while ( 1 )
{
if ( (readfds.fds_bits[v11] & (1LL << (v4 % 64))) == 0 )
{
while ( 1 )
;
}
v6 = (char *)malloc(0x20uLL);
v7 = v6;
if ( !v6 )
{
fwrite("Run out-of memory!!\n", 1uLL, 0x14uLL, stderr);
exit(-1);
}
v8 = recv(v4, v6, 0x1FuLL, 0);
if ( !v8 )
break;
v9 = strlen(v7);
if ( write(v3, v7, v9) != v9 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/connections.c", "recvData", 276LL);
fwrite("Write error", 1uLL, 0xBuLL, stderr);
}
v5 += v8;
free(v7);
}
freeWord(v7);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, __time_t a2, __suseconds_t a3)
{
int v3; // er15
int v4; // er13
__int64 v5; // r12
char *v6; // rax
char *v7; // r14
ssize_t v8; // rbx
size_t v9; // rbp
__int64 v11; // [rsp+8h] [rbp-D0h]
struct timeval timeout; // [rsp+10h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-B8h] BYREF

v3 = a1[1];
v4 = *a1;
timeout.tv_sec = a2;
timeout.tv_usec = a3;
memset(&readfds, 0, sizeof(readfds));
v5 = 0LL;
v11 = v4 / 64;
readfds.fds_bits[v11] |= 1LL << (v4 % 64);
select(v4 + 1, &readfds, 0LL, 0LL, &timeout);
while ( 1 )
{
if ( (readfds.fds_bits[v11] & (1LL << (v4 % 64))) == 0 )
{
while ( 1 )
;
}
v6 = (char *)malloc(0x20uLL);
v7 = v6;
if ( !v6 )
{
fwrite("Run out-of memory!!\n", 1uLL, 0x14uLL, stderr);
exit(-1);
}
v8 = recv(v4, v6, 0x1FuLL, 0);
if ( !v8 )
break;
v9 = strlen(v7);
if ( write(v3, v7, v9) != v9 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/connections.c", "recvData", 276LL);
fwrite("Write error", 1uLL, 0xBuLL, stderr);
}
v5 += v8;
free(v7);
}
freeWord(v7);
return v5;
}

original_code:
LLInt recvData(fdPair *fDP, struct timeval tv) {
  fd_set monitorFDS;
  int toFD = fDP->toFD;
  int sockfd = fDP->fromFD;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&monitorFDS)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&monitorFDS)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
  select(sockfd+1, &monitorFDS, ((void *)0), ((void *)0), &tv);
  int bufferedReads = 0;
  LLInt totalBytesIn=0, nRecvdBytes=0;
  while (1) {
    if (((((&monitorFDS)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    } else {
      continue;
    }
    char *buf = (char *)malloc(sizeof(char)*MAX_BUF_LENGTH);
    if (buf == ((void *)0)) {
      fprintf(stderr, "Run out-of memory!!\n");
      exit(-1);
    }
    nRecvdBytes = recv(sockfd, buf, MAX_BUF_LENGTH - 1, 0);
    Bool breakTrue = nRecvdBytes ? False : True;
    if (breakTrue) {
      freeWord(buf);
      break;
    }
    ssize_t expectedWriteResult = strlen(buf);
    if (write(toFD, buf, expectedWriteResult) != expectedWriteResult) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/connections.c", __func__, 276); fprintf(stderr, "Write error"); };
    }
    free(buf);
    ++bufferedReads;
    totalBytesIn += nRecvdBytes;
  }
  return totalBytesIn;
}

canonical_original_code:
long long recvData(struct fdPair *fDP, struct timeval tv) {
  struct fd_set monitorFDS;
  int toFD = fDP->toFD;
  int sockfd = fDP->fromFD;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&monitorFDS)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&monitorFDS)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
  select(sockfd+1, &monitorFDS, ((void *)0), ((void *)0), &tv);
  int bufferedReads = 0;
  long long totalBytesIn = 0; long long nRecvdBytes = 0;
  while (1) {
    if (((((&monitorFDS)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    } else {
      continue;
    }
    char *buf = (char *)malloc(sizeof(char)*MAX_BUF_LENGTH);
    if (buf == ((void *)0)) {
      fprintf(stderr, "Run out-of memory!!\n");
      exit(-1);
    }
    nRecvdBytes = recv(sockfd, buf, MAX_BUF_LENGTH - 1, 0);
    enum Bool breakTrue = nRecvdBytes ? False : True;
    if (breakTrue) {
      freeWord(buf);
      break;
    }
    long expectedWriteResult = strlen(buf);
    if (write(toFD, buf, expectedWriteResult) != expectedWriteResult) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/connections.c", __func__, 276); fprintf(stderr, "Write error"); };
    }
    free(buf);
    ++bufferedReads;
    totalBytesIn += nRecvdBytes;
  }
  return totalBytesIn;
}

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

variable_types: toFD int

variable_types: sockfd int

variable_types: bufferedReads int

variable_types:
totalBytesIn
long long

variable_types:
nRecvdBytes
long long

variable_types:
buf
char *

variable_types:
breakTrue
enum Bool { False=0, True=1 }

variable_types: expectedWriteResult long

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

user_defined_types: enum DataState { Invalid=0, Sending=1, Receiving=2 }


socketConnection

decompiled_code:
__int64 __fastcall socketConnection(char *name, char *service)
{
int v2; // eax
struct addrinfo *v3; // rbx
int v4; // eax
unsigned int v5; // er12
_WORD *v6; // rax
socklen_t v7; // ecx
const char *v9; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-80h] BYREF
char buf[48]; // [rsp+10h] [rbp-78h] BYREF
struct addrinfo req; // [rsp+40h] [rbp-48h] BYREF

if ( !name || !service || (atoi(service) & 0x8000u) != 0 )
return (unsigned int)-1;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_canonname = 0LL;
v2 = getaddrinfo(name, service, &req, &pai);
if ( v2 )
{
v5 = -1;
v9 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo: %s\n", v9);
return v5;
}
v3 = pai;
if ( !pai )
{
LABEL_12:
fwrite("client: failed to connect\n", 1uLL, 0x1AuLL, stderr);
return (unsigned int)-1;
}
while ( 1 )
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v5 = v4;
if ( v4 != -1 )
break;
perror("Client socket binding");
LABEL_11:
v3 = v3->ai_next;
if ( !v3 )
goto LABEL_12;
}
if ( connect(v4, v3->ai_addr, v3->ai_addrlen) == -1 )
{
close(v5);
perror("Client socket connecting");
goto LABEL_11;
}
v6 = get_in_addr(&v3->ai_addr->sa_family);
inet_ntop(v3->ai_family, v6, buf, v7);
freeaddrinfo(pai);
printf("Client: connected to %s\n", buf);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *name, char *service)
{
int v2; // eax
struct addrinfo *v3; // rbx
int v4; // eax
unsigned int v5; // er12
_WORD *v6; // rax
socklen_t v7; // ecx
const char *v9; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-80h] BYREF
char buf[48]; // [rsp+10h] [rbp-78h] BYREF
struct addrinfo req; // [rsp+40h] [rbp-48h] BYREF

if ( !name || !service || (atoi(service) & 0x8000u) != 0 )
return (unsigned int)-1;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_canonname = 0LL;
v2 = getaddrinfo(name, service, &req, &pai);
if ( v2 )
{
v5 = -1;
v9 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo: %s\n", v9);
return v5;
}
v3 = pai;
if ( !pai )
{
LABEL_12:
fwrite("client: failed to connect\n", 1uLL, 0x1AuLL, stderr);
return (unsigned int)-1;
}
while ( 1 )
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v5 = v4;
if ( v4 != -1 )
break;
perror("Client socket binding");
LABEL_11:
v3 = v3->ai_next;
if ( !v3 )
goto LABEL_12;
}
if ( connect(v4, v3->ai_addr, v3->ai_addrlen) == -1 )
{
close(v5);
perror("Client socket connecting");
goto LABEL_11;
}
v6 = get_in_addr(&v3->ai_addr->sa_family);
inet_ntop(v3->ai_family, v6, buf, v7);
freeaddrinfo(pai);
printf("Client: connected to %s\n", buf);
return v5;
}

original_code:
int socketConnection(const char *targetHost, const char *portStr) {
  if (targetHost == ((void *)0) || portStr == ((void *)0))
    return ERROR_SOCKFD_VALUE;
  const short port = (short)atoi(portStr);
  if (port < MIN_PORT_VALUE || port > MAX_PORT_VALUE)
    return ERROR_SOCKFD_VALUE;
  int sockfd = ERROR_SOCKFD_VALUE;
  char hostAddrString[46];
  struct addrinfo hints, *servinfo, *p;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_DGRAM;
  int addrResolveResult = getaddrinfo(targetHost, portStr, &hints, &servinfo);
  if (addrResolveResult != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(addrResolveResult));
    return ERROR_SOCKFD_VALUE;
  }
  for(p = servinfo; p != ((void *)0); p = p->ai_next) {
    sockfd = socket(p->ai_family, p->ai_socktype,p->ai_protocol);
    if (sockfd == ERROR_SOCKFD_VALUE) {
      perror("Client socket binding");
      continue;
    }
    if (connect(sockfd, p->ai_addr, p->ai_addrlen) == ERROR_SOCKFD_VALUE) {
      close(sockfd);
      perror("Client socket connecting");
      continue;
    }
    break;
  }
  if (p == ((void *)0)) {
    fprintf(stderr, "client: failed to connect\n");
    return ERROR_SOCKFD_VALUE;
  }
  inet_ntop(
    p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
    hostAddrString, sizeof(hostAddrString)
  );
  freeaddrinfo(servinfo);
  printf("Client: connected to %s\n", hostAddrString);
  return sockfd;
}

canonical_original_code:
int socketConnection(char *targetHost, char *portStr) {
  if (targetHost == ((void *)0) || portStr == ((void *)0))
    return ERROR_SOCKFD_VALUE;
  short port = (short)atoi(portStr);
  if (port < MIN_PORT_VALUE || port > MAX_PORT_VALUE)
    return ERROR_SOCKFD_VALUE;
  int sockfd = ERROR_SOCKFD_VALUE;
  char hostAddrString[46];
  struct addrinfo hints; struct addrinfo *servinfo; struct addrinfo *p;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_DGRAM;
  int addrResolveResult = getaddrinfo(targetHost, portStr, &hints, &servinfo);
  if (addrResolveResult != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(addrResolveResult));
    return ERROR_SOCKFD_VALUE;
  }
  for(p = servinfo; p != ((void *)0); p = p->ai_next) {
    sockfd = socket(p->ai_family, p->ai_socktype,p->ai_protocol);
    if (sockfd == ERROR_SOCKFD_VALUE) {
      perror("Client socket binding");
      continue;
    }
    if (connect(sockfd, p->ai_addr, p->ai_addrlen) == ERROR_SOCKFD_VALUE) {
      close(sockfd);
      perror("Client socket connecting");
      continue;
    }
    break;
  }
  if (p == ((void *)0)) {
    fprintf(stderr, "client: failed to connect\n");
    return ERROR_SOCKFD_VALUE;
  }
  inet_ntop(
    p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
    hostAddrString, sizeof(hostAddrString)
  );
  freeaddrinfo(servinfo);
  printf("Client: connected to %s\n", hostAddrString);
  return sockfd;
}

variable_types:
targetHost
char *

variable_types:
portStr
char *

variable_types: port short

variable_types:
hostAddrString
char [46]

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

variable_types: addrResolveResult int

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


ihello

repo: uberblah/emu

decompiled_code:
int ihello()
{
return puts("Hello!");
}

canonical_decompiled_code:
int func20()
{
return puts("Hello!");
}

original_code:
void ihello(emu_processor* proc)
{
  printf("Hello!\n");
}

canonical_original_code:
void ihello(struct emu_processor *proc)
{
  printf("Hello!\n");
}

variable_types: struct emu_processor { void (*iset[256])(struct emu_processor *); unsigned char regs[128]; unsigned int ip; struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; } *device; } *

user_defined_types: struct emu_processor { void (*iset[256])(struct emu_processor *); unsigned char regs[128]; unsigned int ip; struct emu_device *device; }


decompiled_code:
void proc_instruction_test()
{
char *v0; // rax
_QWORD *v1; // rbp
__int64 i; // rax
_BYTE v3[2048]; // [rsp+0h] [rbp-808h] BYREF
char v4; // [rsp+800h] [rbp-8h] BYREF

puts("You should see \"Hello!\" three times now...");
v0 = v3;
do
{
*(_QWORD *)v0 = ihello;
v0 += 8;
}
while ( v0 != &v4 );
v1 = emup_create(v3, 0x400u);
if ( !v1 )
{
puts("OH DARN!! WE FAILED TO ALLOCATE A PROCESSOR!!");
exit(1);
}
for ( i = 0LL; i != 1024; ++i )
*(_BYTE *)(*(_QWORD *)(v1[273] + 16LL) + i) = 0;
emup_step((__int64)v1);
emup_step((__int64)v1);
emup_step((__int64)v1);
emup_free(v1);
}

canonical_decompiled_code:
void func22()
{
char *v0; // rax
_QWORD *v1; // rbp
__int64 i; // rax
_BYTE v3[2048]; // [rsp+0h] [rbp-808h] BYREF
char v4; // [rsp+800h] [rbp-8h] BYREF

puts("You should see \"Hello!\" three times now...");
v0 = v3;
do
{
*(_QWORD *)v0 = ihello;
v0 += 8;
}
while ( v0 != &v4 );
v1 = emup_create(v3, 0x400u);
if ( !v1 )
{
puts("OH DARN!! WE FAILED TO ALLOCATE A PROCESSOR!!");
exit(1);
}
for ( i = 0LL; i != 1024; ++i )
*(_BYTE *)(*(_QWORD *)(v1[273] + 16LL) + i) = 0;
func15((__int64)v1);
func15((__int64)v1);
func15((__int64)v1);
func14(v1);
}

original_code:
void proc_instruction_test()
{
  printf("You should see \"Hello!\" three times now...\n");
  emu_instruction iset[256];
  int i = 0;
  for(; i < 256; i++) iset[i] = ihello;
  emu_processor* proc = emup_create(iset, 1024);
  if(!proc)
  {
    printf("OH DARN!! WE FAILED TO ALLOCATE A PROCESSOR!!\n");
    exit(1);
  }
  for(i = 0; i < 1024; i++) ((uint8_t*)proc->device->mem)[i] = 0;
  for(i = 0; i < 3; i++) emup_step(proc);
  emup_free(proc);
}

canonical_original_code:
void proc_instruction_test()
{
  printf("You should see \"Hello!\" three times now...\n");
  void (*iset[256])(struct emu_processor *);
  int i = 0;
  for(; i < 256; i++) iset[i] = ihello;
  struct emu_processor *proc = emup_create(iset, 1024);
  if(!proc)
  {
    printf("OH DARN!! WE FAILED TO ALLOCATE A PROCESSOR!!\n");
    exit(1);
  }
  for(i = 0; i < 1024; i++) ((unsigned char *)proc->device->mem)[i] = 0;
  for(i = 0; i < 3; i++) emup_step(proc);
  emup_free(proc);
}

variable_types: void (*[256])(struct emu_processor { void (*iset[256])(struct emu_processor *); unsigned char regs[128]; unsigned int ip; struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; } *device; } *)

variable_types: i int


eflip

decompiled_code:
__int64 __fastcall eflip(int a1)
{
unsigned int v2; // [rsp+0h] [rbp-4h]

BYTE2(v2) = BYTE1(a1);
HIBYTE(v2) = a1;
BYTE1(v2) = BYTE2(a1);
LOBYTE(v2) = HIBYTE(a1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func23(int a1)
{
unsigned int v2; // [rsp+0h] [rbp-4h]

BYTE2(v2) = BYTE1(a1);
HIBYTE(v2) = a1;
BYTE1(v2) = BYTE2(a1);
LOBYTE(v2) = HIBYTE(a1);
return v2;
}

original_code:
uint32_t eflip(uint32_t num)
{
  uint32_t buf = num;
  uint8_t* src = (uint8_t*)(&buf);
  uint8_t* dst = (uint8_t*)(&num);
  dst += 3;
  *dst = *src;
  src++;
  dst--;
  *dst = *src;
  src++;
  dst--;
  *dst = *src;
  src++;
  dst--;
  *dst = *src;
  return num;
}

canonical_original_code:
unsigned int eflip(unsigned int num)
{
  unsigned int buf = num;
  unsigned char *src = (uint8_t*)(&buf);
  unsigned char *dst = (uint8_t*)(&num);
  dst += 3;
  *dst = *src;
  src++;
  dst--;
  *dst = *src;
  src++;
  dst--;
  *dst = *src;
  src++;
  dst--;
  *dst = *src;
  return num;
}

variable_types:
num
unsigned int

variable_types:
buf
unsigned int

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *


decompiled_code:
void proc_register_test()
{
char *v0; // rax
_QWORD *v1; // rbp
__int64 v2; // rbx
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
int v9; // [rsp+Ch] [rbp-81Ch] BYREF
char v10[2048]; // [rsp+10h] [rbp-818h] BYREF
char v11; // [rsp+810h] [rbp-18h] BYREF

v0 = v10;
do
{
*(_QWORD *)v0 = imov;
v0 += 8;
}
while ( v0 != &v11 );
v1 = emup_create(v10, 0x400u);
v2 = *(_QWORD *)(v1[273] + 16LL);
v9 = eflip(-559038737);
emup_regset((__int64)v1, 0, &v9);
v3 = eflip(*((_DWORD *)v1 + 512));
printf("should be deadbeef: %x\n", v3);
v9 = 0;
emup_regget((__int64)v1, 0, &v9);
v4 = eflip(v9);
printf("should be deadbeef: %x\n", v4);
v5 = eflip(*((_DWORD *)v1 + 513));
printf("should not be deadbeef: %x\n", v5);
*(_BYTE *)(v2 + 2) = 8;
*(_WORD *)v2 = 0;
emup_step((__int64)v1);
v9 = 0;
emup_regget((__int64)v1, 8u, &v9);
v6 = eflip(v9);
printf("should be deadbeef: %x\n", v6);
v7 = eflip(*((_DWORD *)v1 + 513));
printf("should be same as above: %x\n", v7);
*(_DWORD *)(v2 + 3) = 328704;
*(_WORD *)(v2 + 7) = 1806;
emup_step((__int64)v1);
emup_step((__int64)v1);
v9 = 0;
emup_regget((__int64)v1, 0, &v9);
v8 = eflip(v9);
printf("should be dedebebe: %x\n", v8);
emup_free(v1);
}

canonical_decompiled_code:
void func24()
{
char *v0; // rax
_QWORD *v1; // rbp
__int64 v2; // rbx
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
int v9; // [rsp+Ch] [rbp-81Ch] BYREF
char v10[2048]; // [rsp+10h] [rbp-818h] BYREF
char v11; // [rsp+810h] [rbp-18h] BYREF

v0 = v10;
do
{
*(_QWORD *)v0 = imov;
v0 += 8;
}
while ( v0 != &v11 );
v1 = emup_create(v10, 0x400u);
v2 = *(_QWORD *)(v1[273] + 16LL);
v9 = func23(-559038737);
func18((__int64)v1, 0, &v9);
v3 = func23(*((_DWORD *)v1 + 512));
printf("should be deadbeef: %x\n", v3);
v9 = 0;
func19((__int64)v1, 0, &v9);
v4 = func23(v9);
printf("should be deadbeef: %x\n", v4);
v5 = func23(*((_DWORD *)v1 + 513));
printf("should not be deadbeef: %x\n", v5);
*(_BYTE *)(v2 + 2) = 8;
*(_WORD *)v2 = 0;
func15((__int64)v1);
v9 = 0;
func19((__int64)v1, 8u, &v9);
v6 = func23(v9);
printf("should be deadbeef: %x\n", v6);
v7 = func23(*((_DWORD *)v1 + 513));
printf("should be same as above: %x\n", v7);
*(_DWORD *)(v2 + 3) = 328704;
*(_WORD *)(v2 + 7) = 1806;
func15((__int64)v1);
func15((__int64)v1);
v9 = 0;
func19((__int64)v1, 0, &v9);
v8 = func23(v9);
printf("should be dedebebe: %x\n", v8);
func14(v1);
}

original_code:
void proc_register_test()
{
  emu_instruction iset[256];
  int i = 0;
  for(; i < 256; i++) iset[i] = imov;
  emu_processor* proc = emup_create(iset, 1024);
  uint8_t* mem = proc->device->mem;
  uint32_t iobuf = eflip(0xdeadbeef);
  emup_regset(proc, 0x00 | 0x00, &iobuf);
  printf("should be deadbeef: %x\n", eflip(((uint32_t*)proc->regs)[0]));
  iobuf = 0;
  emup_regget(proc, 0x00 | 0x00, &iobuf);
  printf("should be deadbeef: %x\n", eflip(iobuf));
  printf("should not be deadbeef: %x\n", eflip(((uint32_t*)proc->regs)[1]));
  mem[0] = 0x00;
  mem[1] = 0x00 | 0x00;
  mem[2] = 0x08 | 0x00;
  emup_step(proc);
  iobuf = 0;
  emup_regget(proc, 0x08 | 0x00, &iobuf);
  printf("should be deadbeef: %x\n", eflip(iobuf));
  printf("should be same as above: %x\n", eflip(((uint32_t*)proc->regs)[1]));
  mem[3] = 0x00;
  mem[4] = 0x00 | 0x04;
  mem[5] = 0x00 | 0x05;
  mem[6] = 0x00;
  mem[7] = 0x08 | 0x06;
  mem[8] = 0x00 | 0x07;
  emup_step(proc);
  emup_step(proc);
  iobuf = 0;
  emup_regget(proc, 0x00 | 0x00, &iobuf);
  printf("should be dedebebe: %x\n", eflip(iobuf));
  emup_free(proc);
}

canonical_original_code:
void proc_register_test()
{
  void (*iset[256])(struct emu_processor *);
  int i = 0;
  for(; i < 256; i++) iset[i] = imov;
  struct emu_processor *proc = emup_create(iset, 1024);
  unsigned char *mem = proc->device->mem;
  unsigned int iobuf = eflip(0xdeadbeef);
  emup_regset(proc, 0x00 | 0x00, &iobuf);
  printf("should be deadbeef: %x\n", eflip(((unsigned int *)proc->regs)[0]));
  iobuf = 0;
  emup_regget(proc, 0x00 | 0x00, &iobuf);
  printf("should be deadbeef: %x\n", eflip(iobuf));
  printf("should not be deadbeef: %x\n", eflip(((unsigned int *)proc->regs)[1]));
  mem[0] = 0x00;
  mem[1] = 0x00 | 0x00;
  mem[2] = 0x08 | 0x00;
  emup_step(proc);
  iobuf = 0;
  emup_regget(proc, 0x08 | 0x00, &iobuf);
  printf("should be deadbeef: %x\n", eflip(iobuf));
  printf("should be same as above: %x\n", eflip(((unsigned int *)proc->regs)[1]));
  mem[3] = 0x00;
  mem[4] = 0x00 | 0x04;
  mem[5] = 0x00 | 0x05;
  mem[6] = 0x00;
  mem[7] = 0x08 | 0x06;
  mem[8] = 0x00 | 0x07;
  emup_step(proc);
  emup_step(proc);
  iobuf = 0;
  emup_regget(proc, 0x00 | 0x00, &iobuf);
  printf("should be dedebebe: %x\n", eflip(iobuf));
  emup_free(proc);
}

variable_types:
mem
unsigned char *

variable_types:
iobuf
unsigned int

user_defined_types: struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
proc_instruction_test(argc, argv, envp);
proc_register_test();
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func22(argc, argv, envp);
func24();
exit(0);
}

original_code:
int main(int argc, char** argv)
{
  proc_instruction_test();
  proc_register_test();
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  proc_instruction_test();
  proc_register_test();
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **


imov

decompiled_code:
void *__fastcall imov(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rax
__int64 v3; // rax
unsigned __int8 v4; // bp
void *result; // rax
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(_QWORD *)(a1 + 2184);
v2 = *(unsigned int *)(a1 + 2176);
v6[0] = 0;
v3 = *(_QWORD *)(v1 + 16) + v2;
v4 = *(_BYTE *)(v3 + 2);
emup_regget(a1, *(_BYTE *)(v3 + 1), v6);
result = emup_regset(a1, v4, v6);
*(_DWORD *)(a1 + 2176) += 3;
return result;
}

original_code:
void imov(emu_processor* proc)
{
  uint32_t iobuf = 0;
  uint8_t* ip = ((uint8_t*)proc->device->mem) + proc->ip;
  uint8_t src = ip[1];
  uint8_t dst = ip[2];
  emup_regget(proc, src, &iobuf);
  emup_regset(proc, dst, &iobuf);
  proc->ip += 3;
}

canonical_original_code:
void imov(struct emu_processor *proc)
{
  unsigned int iobuf = 0;
  unsigned char *ip = ((uint8_t*)proc->device->mem) + proc->ip;
  unsigned char src = ip[1];
  unsigned char dst = ip[2];
  emup_regget(proc, src, &iobuf);
  emup_regset(proc, dst, &iobuf);
  proc->ip += 3;
}

variable_types:
ip
unsigned char *

variable_types:
src
unsigned char

variable_types:
dst
unsigned char


decompiled_code:
int __fastcall pinger_irq_cb(__int64 a1, unsigned int a2)
{
return printf("PING: slot=%d, msg=%d\n", *(unsigned __int8 *)(a1 + 56), a2);
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, unsigned int a2)
{
return printf("PING: slot=%d, msg=%d\n", *(unsigned __int8 *)(a1 + 56), a2);
}

original_code:
void pinger_irq_cb(emu_device* pinger, uint32_t code)
{
  printf("PING: slot=%d, msg=%d\n", pinger->id, code);
}

canonical_original_code:
void pinger_irq_cb(struct emu_device *pinger, unsigned int code)
{
  printf("PING: slot=%d, msg=%d\n", pinger->id, code);
}

variable_types: struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; } *

variable_types:
code
unsigned int


decompiled_code:
int __fastcall pinger_cc_cb(__int64 a1)
{
return printf("CONNECT: slot=%d\n", *(unsigned __int8 *)(a1 + 56));
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1)
{
return printf("CONNECT: slot=%d\n", *(unsigned __int8 *)(a1 + 56));
}

original_code:
void pinger_cc_cb(emu_device* pinger)
{
  printf("CONNECT: slot=%d\n", pinger->id);
}

canonical_original_code:
void pinger_cc_cb(struct emu_device *pinger)
{
  printf("CONNECT: slot=%d\n", pinger->id);
}


decompiled_code:
void __fastcall free_pinger(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func16(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void free_pinger(emu_device* pinger)
{
  free(pinger->mem);
  free(pinger);
}

canonical_original_code:
void free_pinger(struct emu_device *pinger)
{
  free(pinger->mem);
  free(pinger);
}


decompiled_code:
void __fastcall pinger_dc_cb(void *ptr)
{
printf("DISCONNECT: slot=%d\n", *((unsigned __int8 *)ptr + 56));
free_pinger(ptr);
}

canonical_decompiled_code:
void __fastcall func17(void *ptr)
{
printf("DISCONNECT: slot=%d\n", *((unsigned __int8 *)ptr + 56));
func16(ptr);
}

original_code:
void pinger_dc_cb(emu_device* pinger)
{
  printf("DISCONNECT: slot=%d\n", pinger->id);
  free_pinger(pinger);
}

canonical_original_code:
void pinger_dc_cb(struct emu_device *pinger)
{
  printf("DISCONNECT: slot=%d\n", pinger->id);
  free_pinger(pinger);
}


decompiled_code:
// attributes: thunk
void __fastcall ram_dc_cb(void *ptr)
{
free_pinger(ptr);
}

canonical_decompiled_code:
void __fastcall func18(void *ptr)
{
func16(ptr);
}

original_code:
static void ram_dc_cb(emu_device* ram)
{
  freeram(ram);
}

canonical_original_code:
static void ram_dc_cb(struct emu_device *ram)
{
  freeram(ram);
}


decompiled_code:
_QWORD *create_pinger()
{
_QWORD *v0; // r12
void *v1; // rax
void *v3; // rdi

v0 = malloc(0x40uLL);
v1 = malloc(0x80uLL);
v0[2] = v1;
if ( v1 )
{
*((_DWORD *)v0 + 2) = 128;
v0[3] = pinger_irq_cb;
v0[4] = pinger_cc_cb;
v0[5] = pinger_dc_cb;
v0[6] = 0LL;
}
else
{
v3 = v0;
v0 = 0LL;
free(v3);
}
return v0;
}

canonical_decompiled_code:
_QWORD *func19()
{
_QWORD *v0; // r12
void *v1; // rax
void *v3; // rdi

v0 = malloc(0x40uLL);
v1 = malloc(0x80uLL);
v0[2] = v1;
if ( v1 )
{
*((_DWORD *)v0 + 2) = 128;
v0[3] = pinger_irq_cb;
v0[4] = pinger_cc_cb;
v0[5] = pinger_dc_cb;
v0[6] = 0LL;
}
else
{
v3 = v0;
v0 = 0LL;
free(v3);
}
return v0;
}

original_code:
emu_device* create_pinger()
{
  emu_device* pinger = (emu_device*)malloc(sizeof(emu_device));
  pinger->mem = malloc(128);
  if(!pinger->mem)
  {
    free(pinger);
    return ((void *)0);
  }
  pinger->memsize = 128;
  pinger->irq_cb = pinger_irq_cb;
  pinger->cc_cb = pinger_cc_cb;
  pinger->dc_cb = pinger_dc_cb;
  pinger->data = ((void *)0);
  return pinger;
}

canonical_original_code:
struct emu_device *create_pinger()
{
  struct emu_device *pinger = (emu_device*)malloc(sizeof(emu_device));
  pinger->mem = malloc(128);
  if(!pinger->mem)
  {
    free(pinger);
    return ((void *)0);
  }
  pinger->memsize = 128;
  pinger->irq_cb = pinger_irq_cb;
  pinger->cc_cb = pinger_cc_cb;
  pinger->dc_cb = pinger_dc_cb;
  pinger->data = ((void *)0);
  return pinger;
}

return_type: struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; } *


decompiled_code:
void __fastcall my_disconnect(__int64 a1, unsigned __int8 a2)
{
emub_disconnect(a1, a2);
}

canonical_decompiled_code:
void __fastcall func20(__int64 a1, unsigned __int8 a2)
{
func8(a1, a2);
}

original_code:
void my_disconnect(emu_board* board, uint8_t id)
{
  emub_disconnect(board, id);
}

canonical_original_code:
void my_disconnect(struct emu_device *(*board)[256], unsigned char id)
{
  emub_disconnect(board, id);
}

variable_types: struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; } *(*)[256]

variable_types:
id
unsigned char


decompiled_code:
// attributes: thunk
void __fastcall my_broadcast(__int64 a1, unsigned int a2)
{
emub_broadcast(a1, a2);
}

canonical_decompiled_code:
void __fastcall func21(__int64 a1, unsigned int a2)
{
func11(a1, a2);
}

original_code:
void my_broadcast(emu_board* board, uint32_t msg)
{
  emub_broadcast(board, msg);
}

canonical_original_code:
void my_broadcast(struct emu_device *(*board)[256], unsigned int msg)
{
  emub_broadcast(board, msg);
}

variable_types:
msg
unsigned int