loadWord

decompiled_code:
__int64 __fastcall loadWord(char *src, int a2)
{
int v2; // er12
const char *v3; // rbp
int v4; // ebx
__int64 result; // rax
__int64 v6; // rcx

v2 = curWord;
if ( curWord > 2 )
{
v3 = s1;
v4 = 2;
while ( strcmp(v3, src) )
{
++v4;
v3 += 40;
if ( v4 == v2 )
goto LABEL_5;
}
if ( v2 != v4 )
goto LABEL_8;
v2 = v4;
LABEL_5:
if ( v2 == 1000 )
{
puts("\nToo may words, increase MAX_WORDS\n");
exit(-1);
}
goto LABEL_6;
}
if ( curWord == 2 )
{
LABEL_6:
curWord = v2 + 1;
strcpy(&wordVector[40 * v2], src);
v4 = v2;
goto LABEL_8;
}
v4 = 2;
LABEL_8:
if ( a2 )
{
if ( a2 == 2 )
{
result = v4;
++dword_405084[1000 * v4];
++dword_406020[v4];
++dword_4040E4;
}
else
{
v6 = lastIndex_0;
result = 1000LL * lastIndex_0 + v4;
++bigramArray[result];
++sumVector[v6];
}
}
else
{
result = v4;
++bigramArray[v4];
++sumVector[0];
}
lastIndex_0 = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *src, int a2)
{
int v2; // er12
const char *v3; // rbp
int v4; // ebx
__int64 result; // rax
__int64 v6; // rcx

v2 = curWord;
if ( curWord > 2 )
{
v3 = s1;
v4 = 2;
while ( strcmp(v3, src) )
{
++v4;
v3 += 40;
if ( v4 == v2 )
goto LABEL_5;
}
if ( v2 != v4 )
goto LABEL_8;
v2 = v4;
LABEL_5:
if ( v2 == 1000 )
{
puts("\nToo may words, increase MAX_WORDS\n");
exit(-1);
}
goto LABEL_6;
}
if ( curWord == 2 )
{
LABEL_6:
curWord = v2 + 1;
strcpy(&wordVector[40 * v2], src);
v4 = v2;
goto LABEL_8;
}
v4 = 2;
LABEL_8:
if ( a2 )
{
if ( a2 == 2 )
{
result = v4;
++dword_405084[1000 * v4];
++dword_406020[v4];
++dword_4040E4;
}
else
{
v6 = lastIndex_0;
result = 1000LL * lastIndex_0 + v4;
++bigramArray[result];
++sumVector[v6];
}
}
else
{
result = v4;
++bigramArray[v4];
++sumVector[0];
}
lastIndex_0 = v4;
return result;
}

original_code:
void loadWord( char *word, int order )
{
  int wordIndex;
  static int lastIndex = 0;
  for (wordIndex = 2 ; wordIndex < curWord ; wordIndex++) {
    if (!strcmp(wordVector[wordIndex], word)) {
      break;
    }
  }
  if (wordIndex == curWord) {
    if (curWord == 1000) {
      printf("\nToo may words, increase MAX_WORDS\n\n");
      exit(-1);
    }
    strcpy(wordVector[curWord++], word);
  }
  if (order == 0) {
    bigramArray[0][wordIndex]++;
    sumVector[0]++;
  } else if (order == 2) {
    bigramArray[wordIndex][1]++;
    bigramArray[1][wordIndex]++;
    sumVector[1]++;
  } else {
    bigramArray[lastIndex][wordIndex]++;
    sumVector[lastIndex]++;
  }
  lastIndex = wordIndex;
  return;
}

canonical_original_code:
void loadWord(char *word, int order)
{
  int wordIndex;
  static int lastIndex = 0;
  for (wordIndex = 2 ; wordIndex < curWord ; wordIndex++) {
    if (!strcmp(wordVector[wordIndex], word)) {
      break;
    }
  }
  if (wordIndex == curWord) {
    if (curWord == 1000) {
      printf("\nToo may words, increase MAX_WORDS\n\n");
      exit(-1);
    }
    strcpy(wordVector[curWord++], word);
  }
  if (order == 0) {
    bigramArray[0][wordIndex]++;
    sumVector[0]++;
  } else if (order == 2) {
    bigramArray[wordIndex][1]++;
    bigramArray[1][wordIndex]++;
    sumVector[1]++;
  } else {
    bigramArray[lastIndex][wordIndex]++;
    sumVector[lastIndex]++;
  }
  lastIndex = wordIndex;
  return;
}

variable_types:
word
char *

variable_types: order int

variable_types: wordIndex int

variable_types: lastIndex int


nextWord

decompiled_code:
__int64 __fastcall nextWord(int a1)
{
int v1; // er8
__int64 result; // rax
int i; // ecx
float v4; // [rsp+Ch] [rbp-1Ch]

v4 = (float)sumVector[a1];
v1 = (int)((float)((float)rand() * v4) * 4.656612873077393e-10);
result = (unsigned int)((a1 + 1) % curWord);
for ( i = bigramArray[1000 * a1 + (int)result]; v1 >= i; i += bigramArray[1000 * a1 + (int)result] )
{
result = (unsigned int)(result + 1);
if ( a1 == (_DWORD)result )
break;
result = (unsigned int)((int)result % curWord);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int v1; // er8
__int64 result; // rax
int i; // ecx
float v4; // [rsp+Ch] [rbp-1Ch]

v4 = (float)sumVector[a1];
v1 = (int)((float)((float)rand() * v4) * 4.656612873077393e-10);
result = (unsigned int)((a1 + 1) % curWord);
for ( i = bigramArray[1000 * a1 + (int)result]; v1 >= i; i += bigramArray[1000 * a1 + (int)result] )
{
result = (unsigned int)(result + 1);
if ( a1 == (_DWORD)result )
break;
result = (unsigned int)((int)result % curWord);
}
return result;
}

original_code:
int nextWord( int word )
{
  int nextWord = (word + 1);
  int max = sumVector[word];
  int lim, sum = 0;
  lim = (int)((float)(max)*rand()/(2147483647 +1.0))+1;
  while (nextWord != word) {
    nextWord = nextWord % curWord;
    sum += bigramArray[word][nextWord];
    if (sum >= lim) {
      return nextWord;
    }
    nextWord++;
  }
  return nextWord;
}

canonical_original_code:
int nextWord(int word)
{
  int nextWord = (word + 1);
  int max = sumVector[word];
  int lim; int sum = 0;
  lim = (int)((float)(max)*rand()/(2147483647 +1.0))+1;
  while (nextWord != word) {
    nextWord = nextWord % curWord;
    sum += bigramArray[word][nextWord];
    if (sum >= lim) {
      return nextWord;
    }
    nextWord++;
  }
  return nextWord;
}

variable_types: word int

variable_types: nextWord int

variable_types: max int

variable_types: lim int

variable_types: sum int

return_type: int


buildSentence

decompiled_code:
__int64 buildSentence()
{
int v0; // ebx
int i; // ebp

putchar(10);
v0 = nextWord(0);
for ( i = 0; i <= 99; i += (int)((float)((float)rand() * 12.0) * 4.656612873077393e-10) + 1 )
{
if ( v0 == 1 )
break;
printf("%s ", &wordVector[40 * v0]);
v0 = nextWord(v0);
}
printf("%c.\n\n", 8LL);
return 0LL;
}

original_code:
int buildSentence( void )
{
  int word = 0;
  int max = 0;
  printf("\n");
  word = nextWord(word);
  while (word != 1) {
    printf("%s ", wordVector[word]);
    word = nextWord(word);
    max += (int)((float)(12)*rand()/(2147483647 +1.0)) + 1;
    if (max >= 100) break;
  }
  printf("%c.\n\n", 8);
  return 0;
}

canonical_original_code:
int buildSentence()
{
  int word = 0;
  int max = 0;
  printf("\n");
  word = nextWord(word);
  while (word != 1) {
    printf("%s ", wordVector[word]);
    word = nextWord(word);
    max += (int)((float)(12)*rand()/(2147483647 +1.0)) + 1;
    if (max >= 100) break;
  }
  printf("%c.\n\n", 8);
  return 0;
}


parseOptions

decompiled_code:
int __fastcall parseOptions(char **argv, int argc, _DWORD *a3, char *a4)
{
int v6; // er12
int result; // eax

*a3 = 0;
v6 = 1;
if ( argc <= 1 )
goto LABEL_10;
while ( 1 )
{
result = getopt(argc, argv, "vf:");
if ( result == -1 )
break;
if ( result == 102 )
{
strcpy(a4, optarg);
v6 = 0;
}
else if ( result == 118 )
{
*a3 = 1;
}
else
{
v6 = 1;
}
}
if ( v6 )
{
LABEL_10:
puts("\nUsage is : \n");
printf("\t%s -f <filename> -v\n\n", *argv);
puts("\t\t -f corpus filename\n\t\t -v verbose mode\n");
exit(0);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(char **argv, int argc, _DWORD *a3, char *a4)
{
int v6; // er12
int result; // eax

*a3 = 0;
v6 = 1;
if ( argc <= 1 )
goto LABEL_10;
while ( 1 )
{
result = getopt(argc, argv, "vf:");
if ( result == -1 )
break;
if ( result == 102 )
{
strcpy(a4, optarg);
v6 = 0;
}
else if ( result == 118 )
{
*a3 = 1;
}
else
{
v6 = 1;
}
}
if ( v6 )
{
LABEL_10:
puts("\nUsage is : \n");
printf("\t%s -f <filename> -v\n\n", *argv);
puts("\t\t -f corpus filename\n\t\t -v verbose mode\n");
exit(0);
}
return result;
}

original_code:
void parseOptions( char *argv[], int argc, int *dbg, char *fname )
{
  int opt, error = 1;
  *dbg = 0;
  if (argc > 1) {
    while ((opt = getopt(argc, argv, "vf:")) != -1) {
      switch(opt) {
        case 'v':
          *dbg = 1;
          break;
        case 'f':
          strcpy(fname, optarg);
          error = 0;
          break;
        default:
          error = 1;
      }
    }
  }
  if (error) {
    printf("\nUsage is : \n\n");
    printf("\t%s -f <filename> -v\n\n", argv[0]);
    printf("\t\t -f corpus filename\n\t\t -v verbose mode\n\n");
    exit(0);
  }
  return;
}

canonical_original_code:
void parseOptions(char *argv[], int argc, int *dbg, char *fname)
{
  int opt; int error = 1;
  *dbg = 0;
  if (argc > 1) {
    while ((opt = getopt(argc, argv, "vf:")) != -1) {
      switch(opt) {
        case 'v':
          *dbg = 1;
          break;
        case 'f':
          strcpy(fname, optarg);
          error = 0;
          break;
        default:
          error = 1;
      }
    }
  }
  if (error) {
    printf("\nUsage is : \n\n");
    printf("\t%s -f <filename> -v\n\n", argv[0]);
    printf("\t\t -f corpus filename\n\t\t -v verbose mode\n\n");
    exit(0);
  }
  return;
}

variable_types:
argv
char *[]

variable_types: argc int

variable_types:
dbg
int *

variable_types:
fname
char *

variable_types: opt int

variable_types: error int

return_type: void


emitMatrix

decompiled_code:
int emitMatrix()
{
int result; // eax
__int64 v1; // rbp
__int64 v2; // r12
__int64 v3; // rbx

result = putchar(10);
if ( curWord > 0 )
{
v1 = 0LL;
v2 = 0LL;
do
{
printf("%20s : ", &wordVector[40 * v2]);
if ( curWord > 0 )
{
v3 = 0LL;
do
printf("%d ", (unsigned int)bigramArray[v3++ + v1]);
while ( curWord > (int)v3 );
}
result = printf(" : %d\n", (unsigned int)sumVector[v2++]);
v1 += 1000LL;
}
while ( curWord > (int)v2 );
}
return result;
}

canonical_decompiled_code:
int func12()
{
int result; // eax
__int64 v1; // rbp
__int64 v2; // r12
__int64 v3; // rbx

result = putchar(10);
if ( curWord > 0 )
{
v1 = 0LL;
v2 = 0LL;
do
{
printf("%20s : ", &wordVector[40 * v2]);
if ( curWord > 0 )
{
v3 = 0LL;
do
printf("%d ", (unsigned int)bigramArray[v3++ + v1]);
while ( curWord > (int)v3 );
}
result = printf(" : %d\n", (unsigned int)sumVector[v2++]);
v1 += 1000LL;
}
while ( curWord > (int)v2 );
}
return result;
}

original_code:
void emitMatrix( void )
{
  int x, y;
  printf("\n");
  for (x = 0 ; x < curWord ; x++) {
    printf("%20s : ", wordVector[x]);
    for ( y = 0 ; y < curWord ; y++) {
      printf("%d ", bigramArray[x][y]);
    }
    printf(" : %d\n", sumVector[x]);
  }
}

canonical_original_code:
void emitMatrix()
{
  int x; int y;
  printf("\n");
  for (x = 0 ; x < curWord ; x++) {
    printf("%20s : ", wordVector[x]);
    for ( y = 0 ; y < curWord ; y++) {
      printf("%d ", bigramArray[x][y]);
    }
    printf(" : %d\n", sumVector[x]);
  }
}

variable_types: x int

variable_types: y int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v5; // [rsp+Ch] [rbp-3Ch] BYREF
char v6[56]; // [rsp+10h] [rbp-38h] BYREF

v5 = 0;
parseOptions((char **)argv, argc, &v5, v6);
v3 = time(0LL);
srand(v3);
memset(bigramArray, 0, 0x3D0900uLL);
strcpy(wordVector, "<START>");
strcpy((char *)&dword_7D59A8, "<END>");
parseFile(v6);
if ( v5 )
emitMatrix();
printf("unique = %d\n", (unsigned int)curWord);
buildSentence();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v5; // [rsp+Ch] [rbp-3Ch] BYREF
char v6[56]; // [rsp+10h] [rbp-38h] BYREF

v5 = 0;
func10((char **)argv, argc, &v5, v6);
v3 = time(0LL);
srand(v3);
memset(bigramArray, 0, 0x3D0900uLL);
strcpy(wordVector, "<START>");
strcpy((char *)&dword_7D59A8, "<END>");
func11(v6);
if ( v5 )
func12();
printf("unique = %d\n", (unsigned int)curWord);
func9();
return 0;
}

original_code:
int main( int argc, char *argv[] )
{
  char filename[40];
  int debug = 0;
  parseOptions( argv, argc, &debug, filename );
  srand(time(((void *)0)));
  bzero(bigramArray, sizeof(bigramArray));
  strcpy(wordVector[0], "<START>");
  strcpy(wordVector[1], "<END>");
  parseFile( filename );
  if (debug) emitMatrix();
  printf("unique = %d\n", curWord);
  buildSentence();
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char filename[40];
  int debug = 0;
  parseOptions( argv, argc, &debug, filename );
  srand(time(((void *)0)));
  bzero(bigramArray, sizeof(bigramArray));
  strcpy(wordVector[0], "<START>");
  strcpy(wordVector[1], "<END>");
  parseFile( filename );
  if (debug) emitMatrix();
  printf("unique = %d\n", curWord);
  buildSentence();
  return 0;
}

variable_types:
filename
char [40]

variable_types: debug int


listPrint

decompiled_code:
int __fastcall listPrint(__int64 a1)
{
__int64 v1; // rbx

v1 = a1 + 8;
do
{
if ( *(_QWORD *)v1 )
printf("(%d,%d) ", *(unsigned int *)(*(_QWORD *)v1 + 32LL), *(unsigned int *)(*(_QWORD *)v1 + 36LL));
v1 += 8LL;
}
while ( v1 != a1 + 4008 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
__int64 v1; // rbx

v1 = a1 + 8;
do
{
if ( *(_QWORD *)v1 )
printf("(%d,%d) ", *(unsigned int *)(*(_QWORD *)v1 + 32LL), *(unsigned int *)(*(_QWORD *)v1 + 36LL));
v1 += 8LL;
}
while ( v1 != a1 + 4008 );
return putchar(10);
}

original_code:
void listPrint( list_t *list_p )
{
  int i;
  for (i = 0 ; i < 500 ; i++) {
    if (list_p->elem[i] != 0) {
      printf("(%d,%d) ", list_p->elem[i]->x, list_p->elem[i]->y);
    }
  }
  printf("\n");
}

canonical_original_code:
void listPrint(struct list_t *list_p)
{
  int i;
  for (i = 0 ; i < 500 ; i++) {
    if (list_p->elem[i] != 0) {
      printf("(%d,%d) ", list_p->elem[i]->x, list_p->elem[i]->y);
    }
  }
  printf("\n");
}

variable_types: struct list_t { int numElems; struct node_s { struct node_s *parent; double g; double h; double f; int x; int y; } *elem[500]; } *

variable_types: i int

user_defined_types: struct list_t { int numElems; struct node_s *elem[500]; }


listEmpty

decompiled_code:
_BOOL8 __fastcall listEmpty(_DWORD *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(_DWORD *a1)
{
return *a1 == 0;
}

original_code:
int listEmpty( list_t *list_p )
{
  if (list_p->numElems == 0) return 1;
  else return 0;
}

canonical_original_code:
int listEmpty(struct list_t *list_p)
{
  if (list_p->numElems == 0) return 1;
  else return 0;
}

user_defined_types: struct node_s { struct node_s *parent; double g; double h; double f; int x; int y; }


listFindBest

original_code:
node_t *listFindBest( list_t *list_p )
{
  int i;
  int best = -1;
  for (i = 0 ; i < 500 ; i++) {
    if (list_p->elem[i] != 0) {
      best = i++;
      break;
    }
  }
  for ( ; i < 500 ; i++) {
    if (list_p->elem[i] != 0) {
      if (list_p->elem[i]->f < list_p->elem[best]->f) {
        best = i;
      }
    }
  }
  return list_p->elem[best];
}

canonical_original_code:
struct node_s *listFindBest(struct list_t *list_p)
{
  int i;
  int best = -1;
  for (i = 0 ; i < 500 ; i++) {
    if (list_p->elem[i] != 0) {
      best = i++;
      break;
    }
  }
  for ( ; i < 500 ; i++) {
    if (list_p->elem[i] != 0) {
      if (list_p->elem[i]->f < list_p->elem[best]->f) {
        best = i;
      }
    }
  }
  return list_p->elem[best];
}

variable_types: struct list_t { int numElems; struct node_s *elem[500]; } *

variable_types: best int

return_type: struct node_s { struct node_s *parent; double g; double h; double f; int x; int y; } *


listPresent

original_code:
int listPresent( list_t *list_p, int x, int y )
{
  int i;
  for (i = 0 ; i < 500 ; i++) {
    if (list_p->elem[i]) {
      if ((list_p->elem[i]->x == x) && (list_p->elem[i]->y == y)) return 1;
    }
  }
  return 0;
}

canonical_original_code:
int listPresent(struct list_t *list_p, int x, int y)
{
  int i;
  for (i = 0 ; i < 500 ; i++) {
    if (list_p->elem[i]) {
      if ((list_p->elem[i]->x == x) && (list_p->elem[i]->y == y)) return 1;
    }
  }
  return 0;
}


listGet

original_code:
node_t *listGet( list_t *list_p, int x, int y, int remove )
{
  int i;
  node_t *node = (node_t *)((void *)0);
  for (i = 0 ; i < 500 ; i++) {
    if (list_p->elem[i]) {
      if ((list_p->elem[i]->x == x) && (list_p->elem[i]->y == y)) {
        node = list_p->elem[i];
        if (remove) {
          list_p->elem[i] = (node_t *)((void *)0);
          list_p->numElems--;
        }
        break;
      }
    }
  }
  return node;
}

canonical_original_code:
struct node_s *listGet(struct list_t *list_p, int x, int y, int remove)
{
  int i;
  struct node_s *node = (node_t *)((void *)0);
  for (i = 0 ; i < 500 ; i++) {
    if (list_p->elem[i]) {
      if ((list_p->elem[i]->x == x) && (list_p->elem[i]->y == y)) {
        node = list_p->elem[i];
        if (remove) {
          list_p->elem[i] = (struct node_s *)((void *)0);
          list_p->numElems--;
        }
        break;
      }
    }
  }
  return node;
}

variable_types: remove int

variable_types: struct node_s { struct node_s *parent; double g; double h; double f; int x; int y; } *


decompiled_code:
double __fastcall calc_h(__int64 a1)
{
double v1; // xmm0_8
double v2; // xmm1_8

if ( !a1 )
__assert_fail("node_p", "misc.c", 0x3Bu, "calc_h");
v1 = (double)*(int *)(a1 + 32) - (double)goal_x;
if ( v1 < 0.0 )
v1 = -v1;
v2 = (double)*(int *)(a1 + 36) - (double)goal_y;
if ( v2 < 0.0 )
v2 = -v2;
return v1 + v2;
}

canonical_decompiled_code:
double __fastcall func13(__int64 a1)
{
double v1; // xmm0_8
double v2; // xmm1_8

if ( !a1 )
__assert_fail("node_p", "misc.c", 0x3Bu, "calc_h");
v1 = (double)*(int *)(a1 + 32) - (double)goal_x;
if ( v1 < 0.0 )
v1 = -v1;
v2 = (double)*(int *)(a1 + 36) - (double)goal_y;
if ( v2 < 0.0 )
v2 = -v2;
return v1 + v2;
}

original_code:
double calc_h( node_t *node_p )
{
  double h;
  extern const int goal_x, goal_y;
  ((void) sizeof ((node_p) ? 1 : 0), __extension__ ({ if (node_p) ; else __assert_fail ("node_p", "misc.c", 59, __extension__ __PRETTY_FUNCTION__); }));
  h = (double)( (double)1.0 *
                (((((double)node_p->x-(double)goal_x) >= 0.0) ? ((double)node_p->x-(double)goal_x) : -((double)node_p->x-(double)goal_x)) +
                 ((((double)node_p->y-(double)goal_y) >= 0.0) ? ((double)node_p->y-(double)goal_y) : -((double)node_p->y-(double)goal_y))) );
  return h;
}

canonical_original_code:
double calc_h(struct node_s *node_p)
{
  double h;
  extern int goal_x; extern int goal_y;
  ((void) sizeof ((node_p) ? 1 : 0), __extension__ ({ if (node_p) ; else __assert_fail ("node_p", "misc.c", 59, __extension__ __PRETTY_FUNCTION__); }));
  h = (double)( (double)1.0 *
                (((((double)node_p->x-(double)goal_x) >= 0.0) ? ((double)node_p->x-(double)goal_x) : -((double)node_p->x-(double)goal_x)) +
                 ((((double)node_p->y-(double)goal_y) >= 0.0) ? ((double)node_p->y-(double)goal_y) : -((double)node_p->y-(double)goal_y))) );
  return h;
}

variable_types: h double

return_type: double


decompiled_code:
double __fastcall calc_g(__int64 a1)
{
if ( !a1 )
__assert_fail("node_p", "misc.c", 0x49u, "calc_g");
return (*(double *)(a1 + 8) - 1.0) * 0.5 + 1.0;
}

canonical_decompiled_code:
double __fastcall func14(__int64 a1)
{
if ( !a1 )
__assert_fail("node_p", "misc.c", 0x49u, "calc_g");
return (*(double *)(a1 + 8) - 1.0) * 0.5 + 1.0;
}

original_code:
double calc_g( node_t *node_p )
{
  double g;
  ((void) sizeof ((node_p) ? 1 : 0), __extension__ ({ if (node_p) ; else __assert_fail ("node_p", "misc.c", 73, __extension__ __PRETTY_FUNCTION__); }));
  g = 1.0 + (double)0.5 * (node_p->g - 1.0);
  return g;
}

canonical_original_code:
double calc_g(struct node_s *node_p)
{
  double g;
  ((void) sizeof ((node_p) ? 1 : 0), __extension__ ({ if (node_p) ; else __assert_fail ("node_p", "misc.c", 73, __extension__ __PRETTY_FUNCTION__); }));
  g = 1.0 + (double)0.5 * (node_p->g - 1.0);
  return g;
}

variable_types: g double


showBestPath

decompiled_code:
int __fastcall showBestPath(__int64 ***a1)
{
__int64 **i; // rdx
__int64 *v2; // rbp
unsigned int *v3; // rbx

grid[15 * goal_y + goal_x] = 71;
for ( i = *a1; *i; i = (__int64 **)*i )
grid[15 * *((int *)i + 9) + *((int *)i + 8)] = 46;
grid[15 * *(int *)(start_node_p + 36) + *(int *)(start_node_p + 32)] = 83;
putchar(10);
v2 = (__int64 *)&unk_4040BC;
do
{
v3 = (unsigned int *)v2 - 15;
do
printf("%c ", *v3++);
while ( v3 != (unsigned int *)v2 );
putchar(10);
v2 = (__int64 *)((char *)v2 + 60);
}
while ( v2 != &closedList_p );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func15(__int64 ***a1)
{
__int64 **i; // rdx
__int64 *v2; // rbp
unsigned int *v3; // rbx

grid[15 * goal_y + goal_x] = 71;
for ( i = *a1; *i; i = (__int64 **)*i )
grid[15 * *((int *)i + 9) + *((int *)i + 8)] = 46;
grid[15 * *(int *)(start_node_p + 36) + *(int *)(start_node_p + 32)] = 83;
putchar(10);
v2 = (__int64 *)&unk_4040BC;
do
{
v3 = (unsigned int *)v2 - 15;
do
printf("%c ", *v3++);
while ( v3 != (unsigned int *)v2 );
putchar(10);
v2 = (__int64 *)((char *)v2 + 60);
}
while ( v2 != &closedList_p );
return putchar(10);
}

original_code:
void showBestPath( node_t *walker )
{
  int x, y;
  extern int grid[15][15];
  extern const int goal_x, goal_y;
  grid[goal_y][goal_x] = 'G';
  walker = (node_t *)walker->parent;
  while (walker->parent != (node_t *)((void *)0)) {
    grid[walker->y][walker->x] = '.';
    walker = (node_t *)walker->parent;
  }
  grid[start_node_p->y][start_node_p->x] = 'S';
  printf("\n");
  for (y = 0 ; y < 15 ; y++) {
    for (x = 0 ; x < 15 ; x++) {
      printf("%c ", grid[y][x]);
    }
    printf("\n");
  }
  printf("\n");
  return;
}

canonical_original_code:
void showBestPath(struct node_s *walker)
{
  int x; int y;
  extern int grid[15][15];
  extern int goal_x; extern int goal_y;
  grid[goal_y][goal_x] = 'G';
  walker = (struct node_s *)walker->parent;
  while (walker->parent != (struct node_s *)((void *)0)) {
    grid[walker->y][walker->x] = '.';
    walker = (struct node_s *)walker->parent;
  }
  grid[start_node_p->y][start_node_p->x] = 'S';
  printf("\n");
  for (y = 0 ; y < 15 ; y++) {
    for (x = 0 ; x < 15 ; x++) {
      printf("%c ", grid[y][x]);
    }
    printf("\n");
  }
  printf("\n");
  return;
}


cleanup

decompiled_code:
void cleanup()
{
__int64 i; // rbx
void *v1; // rdi
void *v2; // rdi

for ( i = 1LL; i != 501; ++i )
{
v1 = (void *)openList_p[i];
if ( v1 )
free(v1);
v2 = (void *)closedList_p[i];
if ( v2 )
free(v2);
}
}

canonical_decompiled_code:
void func16()
{
__int64 i; // rbx
void *v1; // rdi
void *v2; // rdi

for ( i = 1LL; i != 501; ++i )
{
v1 = (void *)openList_p[i];
if ( v1 )
free(v1);
v2 = (void *)closedList_p[i];
if ( v2 )
free(v2);
}
}

original_code:
void cleanup( void )
{
  int i;
  extern list_t openList_p;
  extern list_t closedList_p;
  for (i = 0 ; i < 500 ; i++) {
    if (openList_p.elem[i]) free(openList_p.elem[i]);
    if (closedList_p.elem[i]) free(closedList_p.elem[i]);
  }
  return;
}

canonical_original_code:
void cleanup()
{
  int i;
  extern struct list_t openList_p;
  extern struct list_t closedList_p;
  for (i = 0 ; i < 500 ; i++) {
    if (openList_p.elem[i]) free(openList_p.elem[i]);
    if (closedList_p.elem[i]) free(closedList_p.elem[i]);
  }
  return;
}

variable_types: struct list_t { int numElems; struct node_s { struct node_s *parent; double g; double h; double f; int x; int y; } *elem[500]; }


printStructure

decompiled_code:
int printStructure()
{
int result; // eax
_QWORD *v1; // rbp
unsigned int i; // er12
__int64 j; // rbx
__int64 k; // rbx

result = printf("Parsed %d rules\n", (unsigned int)ruleIndex);
v1 = &ruleSet;
for ( i = 0; i != 40; ++i )
{
if ( *(_DWORD *)v1 )
{
printf("Rule %d :\n", i);
puts("Antecedents : ");
for ( j = v1[11]; j; j = *(_QWORD *)(j + 88) )
printf(" %s\n", (const char *)(j + 4));
puts("Consequents : ");
for ( k = v1[12]; k; k = *(_QWORD *)(k + 88) )
printf(" %s\n", (const char *)(k + 4));
result = putchar(10);
}
v1 += 13;
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax
_QWORD *v1; // rbp
unsigned int i; // er12
__int64 j; // rbx
__int64 k; // rbx

result = printf("Parsed %d rules\n", (unsigned int)ruleIndex);
v1 = &ruleSet;
for ( i = 0; i != 40; ++i )
{
if ( *(_DWORD *)v1 )
{
printf("Rule %d :\n", i);
puts("Antecedents : ");
for ( j = v1[11]; j; j = *(_QWORD *)(j + 88) )
printf(" %s\n", (const char *)(j + 4));
puts("Consequents : ");
for ( k = v1[12]; k; k = *(_QWORD *)(k + 88) )
printf(" %s\n", (const char *)(k + 4));
result = putchar(10);
}
v1 += 13;
}
return result;
}

original_code:
void printStructure( void )
{
  memoryElementType *ptr;
  int i;
  printf("Parsed %d rules\n", ruleIndex);
  for (i = 0 ; i < 40 ; i++) {
    if (ruleSet[i].active) {
      printf("Rule %d :\n", i);
      printf("Antecedents : \n");
      ptr = ruleSet[i].antecedent;
      while (ptr) {
        printf("  %s\n", ptr->element);
        ptr = ptr->next;
      }
      printf("Consequents : \n");
      ptr = ruleSet[i].consequent;
      while (ptr) {
        printf("  %s\n", ptr->element);
        ptr = ptr->next;
      }
      printf("\n");
    }
  }
}

canonical_original_code:
void printStructure()
{
  struct memoryElementStruct *ptr;
  int i;
  printf("Parsed %d rules\n", ruleIndex);
  for (i = 0 ; i < 40 ; i++) {
    if (ruleSet[i].active) {
      printf("Rule %d :\n", i);
      printf("Antecedents : \n");
      ptr = ruleSet[i].antecedent;
      while (ptr) {
        printf("  %s\n", ptr->element);
        ptr = ptr->next;
      }
      printf("Consequents : \n");
      ptr = ruleSet[i].consequent;
      while (ptr) {
        printf("  %s\n", ptr->element);
        ptr = ptr->next;
      }
      printf("\n");
    }
  }
}

variable_types: struct memoryElementStruct { int active; char element[-1]; struct memoryElementStruct *next; } *


printWorkingMemory

decompiled_code:
int printWorkingMemory()
{
const char *v0; // rbx

puts("\tWorking Memory:");
v0 = (const char *)(unsigned int)((_DWORD)&workingMemory + 4);
do
{
if ( *((_DWORD *)v0 - 1) )
printf("\t\t%s\n", v0);
v0 += 96;
}
while ( v0 != (const char *)(unsigned int)((_DWORD)&workingMemory + 3844) );
return putchar(10);
}

canonical_decompiled_code:
int func1()
{
const char *v0; // rbx

puts("\tWorking Memory:");
v0 = (const char *)(unsigned int)((_DWORD)&workingMemory + 4);
do
{
if ( *((_DWORD *)v0 - 1) )
printf("\t\t%s\n", v0);
v0 += 96;
}
while ( v0 != (const char *)(unsigned int)((_DWORD)&workingMemory + 3844) );
return putchar(10);
}

original_code:
void printWorkingMemory( void )
{
  int slot;
  printf("\tWorking Memory:\n");
  for (slot = 0 ; slot < 40 ; slot++) {
    if (workingMemory[slot].active) {
      printf("\t\t%s\n", workingMemory[slot].element);
    }
  }
  printf("\n");
}

canonical_original_code:
void printWorkingMemory()
{
  int slot;
  printf("\tWorking Memory:\n");
  for (slot = 0 ; slot < 40 ; slot++) {
    if (workingMemory[slot].active) {
      printf("\t\t%s\n", workingMemory[slot].element);
    }
  }
  printf("\n");
}

variable_types: slot int


emitHelp

decompiled_code:
void __noreturn emitHelp()
{
puts("\n\trbs -r <rule file> [-hd]\n");
puts("\t\t -r specify the rules file");
puts("\t\t -d debug mode");
puts("\t\t -h this help\n");
exit(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
puts("\n\trbs -r <rule file> [-hd]\n");
puts("\t\t -r specify the rules file");
puts("\t\t -d debug mode");
puts("\t\t -h this help\n");
exit(0);
}

original_code:
void emitHelp( void )
{
  printf("\n\trbs -r <rule file> [-hd]\n\n");
  printf("\t\t -r  specify the rules file\n");
  printf("\t\t -d  debug mode\n");
  printf("\t\t -h  this help\n\n");
  exit(0);
}

canonical_original_code:
void emitHelp()
{
  printf("\n\trbs -r <rule file> [-hd]\n\n");
  printf("\t\t -r  specify the rules file\n");
  printf("\t\t -d  debug mode\n");
  printf("\t\t -h  this help\n\n");
  exit(0);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v5[13]; // [rsp+0h] [rbp-68h] BYREF

v5[0] = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
v5[4] = 0LL;
v5[5] = 0LL;
v5[6] = 0LL;
v5[7] = 0LL;
v5[8] = 0LL;
v5[9] = 0LL;
debug = 0;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "hdr:");
if ( v3 == -1 )
break;
if ( v3 == 104 )
emitHelp();
if ( v3 == 114 )
{
strcpy((char *)v5, optarg);
}
else if ( v3 == 100 )
{
debug = 1;
puts("Debugging enabled");
}
}
if ( !LOBYTE(v5[0]) )
emitHelp();
memset(&workingMemory, 0, 0xF00uLL);
memset(&ruleSet, 0, 0x1040uLL);
timers[0] = 0LL;
timers[1] = 0LL;
timers[2] = 0LL;
timers[3] = 0LL;
timers[4] = 0LL;
timers[5] = 0LL;
timers[6] = 0LL;
timers[7] = 0LL;
timers[8] = 0LL;
timers[9] = 0LL;
if ( (int)parseFile(v5, argv, &ruleSet) < 0 )
{
puts("\nCould not open file, or parse error\n");
exit(0);
}
while ( 1 )
{
interpret();
if ( debug )
printWorkingMemory();
processTimers();
if ( endRun )
break;
sleep(1u);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v5[13]; // [rsp+0h] [rbp-68h] BYREF

v5[0] = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
v5[4] = 0LL;
v5[5] = 0LL;
v5[6] = 0LL;
v5[7] = 0LL;
v5[8] = 0LL;
v5[9] = 0LL;
debug = 0;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "hdr:");
if ( v3 == -1 )
break;
if ( v3 == 104 )
func2();
if ( v3 == 114 )
{
strcpy((char *)v5, optarg);
}
else if ( v3 == 100 )
{
debug = 1;
puts("Debugging enabled");
}
}
if ( !LOBYTE(v5[0]) )
func2();
memset(&workingMemory, 0, 0xF00uLL);
memset(&ruleSet, 0, 0x1040uLL);
timers[0] = 0LL;
timers[1] = 0LL;
timers[2] = 0LL;
timers[3] = 0LL;
timers[4] = 0LL;
timers[5] = 0LL;
timers[6] = 0LL;
timers[7] = 0LL;
timers[8] = 0LL;
timers[9] = 0LL;
if ( (int)parseFile(v5, argv, &ruleSet) < 0 )
{
puts("\nCould not open file, or parse error\n");
exit(0);
}
while ( 1 )
{
interpret();
if ( debug )
func1();
processTimers();
if ( endRun )
break;
sleep(1u);
}
return 0;
}

original_code:
int main( int argc, char *argv[] )
{
  int opt, ret;
  char inpfile[80]={0};
  extern void processTimers( void );
  extern int parseFile( char * );
  extern void interpret( void );
  debug = 0;
  while ((opt = getopt(argc, argv, "hdr:")) != -1) {
    switch( opt ) {
      case 'r':
        strcpy(inpfile, optarg);
        break;
      case 'd':
        debug = 1;
        printf("Debugging enabled\n");
        break;
      case 'h':
        emitHelp();
        break;
    }
  }
  if (inpfile[0] == 0) emitHelp();
  bzero( (void *)workingMemory, sizeof(workingMemory) );
  bzero( (void *)ruleSet, sizeof(ruleSet) );
  bzero( (void *)timers, sizeof(timers) );
  ret = parseFile( inpfile );
  if (ret < 0) {
    printf("\nCould not open file, or parse error\n\n");
    exit(0);
  }
  while (1) {
    interpret();
    if (debug) {
      printWorkingMemory();
    }
    processTimers();
    if (endRun) break;
    sleep(1);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int opt; int ret;
  char inpfile[80] = {0};
  extern void processTimers();
  extern int parseFile(char *);
  extern void interpret();
  debug = 0;
  while ((opt = getopt(argc, argv, "hdr:")) != -1) {
    switch( opt ) {
      case 'r':
        strcpy(inpfile, optarg);
        break;
      case 'd':
        debug = 1;
        printf("Debugging enabled\n");
        break;
      case 'h':
        emitHelp();
        break;
    }
  }
  if (inpfile[0] == 0) emitHelp();
  bzero( (void *)workingMemory, sizeof(workingMemory) );
  bzero( (void *)ruleSet, sizeof(ruleSet) );
  bzero( (void *)timers, sizeof(timers) );
  ret = parseFile( inpfile );
  if (ret < 0) {
    printf("\nCould not open file, or parse error\n\n");
    exit(0);
  }
  while (1) {
    interpret();
    if (debug) {
      printWorkingMemory();
    }
    processTimers();
    if (endRun) break;
    sleep(1);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: ret int

variable_types:
inpfile
char [80]

variable_types:
processTimers
void ()

variable_types:
parseFile
int (char *)

variable_types:
interpret
void ()


getRandomCharacter

original_code:
unsigned char getRandomCharacter( void )
{
  const unsigned char alphabet[3] = {'0', '1', '#'};
  return( alphabet[(int)((double)(3)*rand()/(2147483647 +1.0))] );
}

canonical_original_code:
unsigned char getRandomCharacter()
{
  unsigned char alphabet[3] = {'0', '1', '#'};
  return( alphabet[(int)((double)(3)*rand()/(2147483647 +1.0))] );
}

variable_types:
alphabet
unsigned char [3]

return_type: unsigned char


readDetectors

decompiled_code:
__int64 __fastcall readDetectors(__int64 a1)
{
__int64 i; // rdx
int v2; // eax
__int64 result; // rax

for ( i = 0LL; i != 4; ++i )
{
v2 = 5 * (dir[2 * i] + agent_y);
LOBYTE(v2) = world[20 * dir[2 * i] + 20 * agent_y + dword_402064[2 * i] + agent_x] == 42;
result = (unsigned int)(v2 + 48);
*(_BYTE *)(a1 + i) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 i; // rdx
int v2; // eax
__int64 result; // rax

for ( i = 0LL; i != 4; ++i )
{
v2 = 5 * (dir[2 * i] + agent_y);
LOBYTE(v2) = world[20 * dir[2 * i] + 20 * agent_y + dword_402064[2 * i] + agent_x] == 42;
result = (unsigned int)(v2 + 48);
*(_BYTE *)(a1 + i) = result;
}
return result;
}

original_code:
void readDetectors( unsigned char *condition )
{
  int i;
  for (i = 0 ; i < 4 ; i++) {
    int y = agent_y + dir[i].loc_y;
    int x = agent_x + dir[i].loc_x;
    condition[i] = (world[y][x] == '*') ? '1' : '0';
  }
  return;
}

canonical_original_code:
void readDetectors(unsigned char *condition)
{
  int i;
  for (i = 0 ; i < 4 ; i++) {
    int y = agent_y + dir[i].loc_y;
    int x = agent_x + dir[i].loc_x;
    condition[i] = (world[y][x] == '*') ? '1' : '0';
  }
  return;
}

variable_types:
condition
unsigned char *

variable_types: i int

variable_types: y int

variable_types: x int


match

decompiled_code:
__int64 __fastcall match(char a1, char a2)
{
return (a1 == 35) | (unsigned __int8)(a1 == a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1, char a2)
{
return (a1 == 35) | (unsigned __int8)(a1 == a2);
}

original_code:
int match( unsigned char cl, unsigned char cn )
{
  if (cl == '#') return 1;
  else if (cl == cn) return 1;
  return 0;
}

canonical_original_code:
int match(unsigned char cl, unsigned char cn)
{
  if (cl == '#') return 1;
  else if (cl == cn) return 1;
  return 0;
}

variable_types:
cl
unsigned char

variable_types:
cn
unsigned char


calculateSpecificity

original_code:
void calculateSpecificity( int classifier )
{
  int i;
  list[classifier].specificity = 0.0;
  for (i = 0 ; i < 4 ; i++) {
    if (list[classifier].condition[i] != '#') {
      list[classifier].specificity++;
    }
  }
  list[classifier].specificity /= (double)4;
  return;
}

canonical_original_code:
void calculateSpecificity(int classifier)
{
  int i;
  list[classifier].specificity = 0.0;
  for (i = 0 ; i < 4 ; i++) {
    if (list[classifier].condition[i] != '#') {
      list[classifier].specificity++;
    }
  }
  list[classifier].specificity /= (double)4;
  return;
}

variable_types: classifier int


createCoveringClassifier

original_code:
int createCoveringClassifier( int classifier, unsigned char *condition )
{
  int c, act;
  double minStrength = 99.0;
  if (classifier == -1) {
    for (c = 0 ; c < 32 ; c++) {
      if (list[c].strength < minStrength) {
        classifier = c;
        minStrength = list[c].strength;
      }
    }
  }
  for (c = 0 ; c < 4 ; c++) {
    if (((float)rand() / (float)2147483647) > 0.75) {
      list[classifier].condition[c] = condition[c];
    } else {
      list[classifier].condition[c] = '#';
    }
  }
  for (act = 0 ; act < 2 ; act++) {
    list[classifier].action[act] = 0x30 + (int)((double)(2)*rand()/(2147483647 +1.0));
  }
  list[classifier].strength = 1.0;
  list[classifier].episode = 0;
  calculateSpecificity( classifier );
  return classifier;
}

canonical_original_code:
int createCoveringClassifier(int classifier, unsigned char *condition)
{
  int c; int act;
  double minStrength = 99.0;
  if (classifier == -1) {
    for (c = 0 ; c < 32 ; c++) {
      if (list[c].strength < minStrength) {
        classifier = c;
        minStrength = list[c].strength;
      }
    }
  }
  for (c = 0 ; c < 4 ; c++) {
    if (((float)rand() / (float)2147483647) > 0.75) {
      list[classifier].condition[c] = condition[c];
    } else {
      list[classifier].condition[c] = '#';
    }
  }
  for (act = 0 ; act < 2 ; act++) {
    list[classifier].action[act] = 0x30 + (int)((double)(2)*rand()/(2147483647 +1.0));
  }
  list[classifier].strength = 1.0;
  list[classifier].episode = 0;
  calculateSpecificity( classifier );
  return classifier;
}

variable_types: c int

variable_types: act int

variable_types: minStrength double


matchClassifiers

original_code:
int matchClassifiers( unsigned char *condition )
{
  int c;
  int i;
  double bidSum = 0.0;
  int matchFound = 0;
  for (c = 0 ; c < 32 ; c++) {
    list[c].match = 0;
    for (i = 0 ; i < 4 ; i++) {
      if (!match(list[c].condition[i], condition[i])) break;
    }
    if (i == 4) {
      list[c].match = 1;
      list[c].bid = ((double)0.5) * list[c].strength * list[c].specificity;
      bidSum += list[c].bid;
      matchFound = 1;
    }
  }
  if (matchFound) {
    int tries = 32;
    c = (int)((double)(32)*rand()/(2147483647 +1.0));
    while (1) {
      if (list[c].match) {
        if ( (list[c].bid / bidSum) > ((float)rand() / (float)2147483647)) break;
        if ( --tries == 0) break;
      }
      if (++c >= 32) c = 0;
    }
  } else {
    if (c == 32) {
      c = createCoveringClassifier( -1, condition );
    }
  }
  return c;
}

canonical_original_code:
int matchClassifiers(unsigned char *condition)
{
  int c;
  int i;
  double bidSum = 0.0;
  int matchFound = 0;
  for (c = 0 ; c < 32 ; c++) {
    list[c].match = 0;
    for (i = 0 ; i < 4 ; i++) {
      if (!match(list[c].condition[i], condition[i])) break;
    }
    if (i == 4) {
      list[c].match = 1;
      list[c].bid = ((double)0.5) * list[c].strength * list[c].specificity;
      bidSum += list[c].bid;
      matchFound = 1;
    }
  }
  if (matchFound) {
    int tries = 32;
    c = (int)((double)(32)*rand()/(2147483647 +1.0));
    while (1) {
      if (list[c].match) {
        if ( (list[c].bid / bidSum) > ((float)rand() / (float)2147483647)) break;
        if ( --tries == 0) break;
      }
      if (++c >= 32) c = 0;
    }
  } else {
    if (c == 32) {
      c = createCoveringClassifier( -1, condition );
    }
  }
  return c;
}

variable_types: bidSum double

variable_types: matchFound int

variable_types: tries int


initClassifier

original_code:
void initClassifier( int classifier )
{
  int cond, act;
  for (cond = 0 ; cond < 4 ; cond++) {
    list[classifier].condition[cond] = getRandomCharacter();
  }
  for (act = 0 ; act < 2 ; act++) {
    list[classifier].action[act] = 0x30 + (int)((double)(2)*rand()/(2147483647 +1.0));
  }
  list[classifier].strength = 1.0;
  list[classifier].episode = 0;
  calculateSpecificity( classifier );
  return;
}

canonical_original_code:
void initClassifier(int classifier)
{
  int cond; int act;
  for (cond = 0 ; cond < 4 ; cond++) {
    list[classifier].condition[cond] = getRandomCharacter();
  }
  for (act = 0 ; act < 2 ; act++) {
    list[classifier].action[act] = 0x30 + (int)((double)(2)*rand()/(2147483647 +1.0));
  }
  list[classifier].strength = 1.0;
  list[classifier].episode = 0;
  calculateSpecificity( classifier );
  return;
}

variable_types: cond int


printAgent

decompiled_code:
int printAgent()
{
unsigned __int64 v0; // rbp
unsigned int i; // er12
int result; // eax
__int64 j; // rbx

puts("\nClassifier List:");
v0 = 0LL;
for ( i = 0; i != 32; ++i )
{
printf("C%02d ", i);
for ( j = 0LL; j != 4; ++j )
putchar((unsigned __int8)list[v0 + j]);
printf(" : ");
putchar((unsigned __int8)byte_404244[v0]);
putchar((unsigned __int8)byte_404245[v0]);
result = printf(" Strength %g\n", *(double *)&qword_404248[v0 / 8]);
v0 += 40LL;
}
return result;
}

canonical_decompiled_code:
int func17()
{
unsigned __int64 v0; // rbp
unsigned int i; // er12
int result; // eax
__int64 j; // rbx

puts("\nClassifier List:");
v0 = 0LL;
for ( i = 0; i != 32; ++i )
{
printf("C%02d ", i);
for ( j = 0LL; j != 4; ++j )
putchar((unsigned __int8)list[v0 + j]);
printf(" : ");
putchar((unsigned __int8)byte_404244[v0]);
putchar((unsigned __int8)byte_404245[v0]);
result = printf(" Strength %g\n", *(double *)&qword_404248[v0 / 8]);
v0 += 40LL;
}
return result;
}

original_code:
void printAgent( void )
{
  int c, cond, act;
  printf("\nClassifier List:\n");
  for (c = 0 ; c < 32 ; c++) {
    printf( "C%02d ", c );
    for (cond = 0 ; cond < 4 ; cond++) {
      printf("%c", list[c].condition[cond]);
    }
    printf(" : ");
    for (act = 0 ; act < 2 ; act++) {
      printf("%c", list[c].action[act]);
    }
    printf("  Strength %g\n", list[c].strength);
  }
  return;
}

canonical_original_code:
void printAgent()
{
  int c; int cond; int act;
  printf("\nClassifier List:\n");
  for (c = 0 ; c < 32 ; c++) {
    printf( "C%02d ", c );
    for (cond = 0 ; cond < 4 ; cond++) {
      printf("%c", list[c].condition[cond]);
    }
    printf(" : ");
    for (act = 0 ; act < 2 ; act++) {
      printf("%c", list[c].action[act]);
    }
    printf("  Strength %g\n", list[c].strength);
  }
  return;
}


printWorld

decompiled_code:
int printWorld()
{
char *v0; // rbp
unsigned __int8 *v1; // rbx
int result; // eax

puts("World:");
v0 = (char *)&unk_4040B4;
do
{
putchar(9);
v1 = (unsigned __int8 *)(v0 - 20);
do
printf("%c ", *v1++);
while ( v1 != (unsigned __int8 *)v0 );
result = putchar(10);
v0 += 20;
}
while ( v0 != byte_404244 );
return result;
}

canonical_decompiled_code:
int func18()
{
char *v0; // rbp
unsigned __int8 *v1; // rbx
int result; // eax

puts("World:");
v0 = (char *)&unk_4040B4;
do
{
putchar(9);
v1 = (unsigned __int8 *)(v0 - 20);
do
printf("%c ", *v1++);
while ( v1 != (unsigned __int8 *)v0 );
result = putchar(10);
v0 += 20;
}
while ( v0 != byte_404244 );
return result;
}

original_code:
void printWorld( void )
{
  int y, x;
  printf("World:\n");
  for (y = 0 ; y < 20 ; y++) {
    printf("\t");
    for (x = 0 ; x < 20 ; x++) {
      printf("%c ", world[y][x]);
    }
    printf("\n");
  }
  return;
}

canonical_original_code:
void printWorld()
{
  int y; int x;
  printf("World:\n");
  for (y = 0 ; y < 20 ; y++) {
    printf("\t");
    for (x = 0 ; x < 20 ; x++) {
      printf("%c ", world[y][x]);
    }
    printf("\n");
  }
  return;
}


initAgent

original_code:
void initAgent( void )
{
  int c, i;
  for (c = 0 ; c < 32 ; c++) {
    initClassifier( c );
  }
  while (1) {
    agent_y = 1+(int)((double)(20 -2)*rand()/(2147483647 +1.0));
    agent_x = 1+(int)((double)(20 -2)*rand()/(2147483647 +1.0));
    if (world[agent_y][agent_x] == '*') continue;
    for (i = 0 ; i < 4 ; i++) {
      int y = agent_y + dir[i].loc_y;
      int x = agent_x + dir[i].loc_x;
      if (world[y][x] == '*') break;
    }
    if (i == 4) break;
  }
  world[agent_y][agent_x] = '@';
  return;
}

canonical_original_code:
void initAgent()
{
  int c; int i;
  for (c = 0 ; c < 32 ; c++) {
    initClassifier( c );
  }
  while (1) {
    agent_y = 1+(int)((double)(20 -2)*rand()/(2147483647 +1.0));
    agent_x = 1+(int)((double)(20 -2)*rand()/(2147483647 +1.0));
    if (world[agent_y][agent_x] == '*') continue;
    for (i = 0 ; i < 4 ; i++) {
      int y = agent_y + dir[i].loc_y;
      int x = agent_x + dir[i].loc_x;
      if (world[y][x] == '*') break;
    }
    if (i == 4) break;
  }
  world[agent_y][agent_x] = '@';
  return;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
time_t v3; // rdi
int i; // ebp
int v5; // eax
__int64 *v6; // rdx
int v7; // ebx
double v8; // xmm1_8
double v9; // xmm0_8
char v11[28]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = time(0LL);
srand(v3);
initWorld(v3, argv);
initAgent();
for ( i = 0; i != 1000; ++i )
{
readDetectors((__int64)v11);
v7 = matchClassifiers((__int64)v11);
sendEffectors(v7);
system("clear");
printWorld();
v5 = i % 10;
if ( !(i % 10) )
{
v8 = *(double *)&qword_404258[5 * v7];
v9 = *(double *)&qword_404248[5 * v7] - v8;
if ( v9 < 0.0 )
qword_404248[5 * v7] = 0LL;
else
*(double *)&qword_404248[5 * v7] = v9;
v6 = qword_404248;
do
{
if ( *((_DWORD *)v6 + 7) && v7 != v5 )
{
*(double *)v6 = v8 / 10.0 + *(double *)v6;
*((_DWORD *)v6 + 7) = 0;
}
++v5;
v6 += 5;
}
while ( v5 != 32 );
}
}
printAgent();
return 0;
}

original_code:
int main()
{
  int t, i, c;
  unsigned char detectors[4];
  srand( time(((void *)0)) );
  initWorld();
  initAgent();
  for (t = 0 ; t < 1000 ; t++) {
    readDetectors( detectors );
    c = matchClassifiers( detectors );
    sendEffectors( c );
    system("clear");
    printWorld();
    if ( (t % 10) == 0 ) {
      list[c].strength -= list[c].bid;
      if (list[c].strength < 0.0) list[c].strength = 0.0;
      for (i = 0 ; i < 32 ; i++) {
        if ((list[i].episode) && (i != c)) {
          list[i].strength += ( list[c].bid / (double)10 );
          list[i].episode = 0;
        }
      }
    }
  }
  printAgent();
  return 0;
}

canonical_original_code:
int main()
{
  int t; int i; int c;
  unsigned char detectors[4];
  srand( time(((void *)0)) );
  initWorld();
  initAgent();
  for (t = 0 ; t < 1000 ; t++) {
    readDetectors( detectors );
    c = matchClassifiers( detectors );
    sendEffectors( c );
    system("clear");
    printWorld();
    if ( (t % 10) == 0 ) {
      list[c].strength -= list[c].bid;
      if (list[c].strength < 0.0) list[c].strength = 0.0;
      for (i = 0 ; i < 32 ; i++) {
        if ((list[i].episode) && (i != c)) {
          list[i].strength += ( list[c].bid / (double)10 );
          list[i].episode = 0;
        }
      }
    }
  }
  printAgent();
  return 0;
}

variable_types: t int

variable_types:
detectors
unsigned char [4]


fireTimer

decompiled_code:
__int64 __fastcall fireTimer(unsigned int a1)
{
__int64 result; // rax
char v2[104]; // [rsp+0h] [rbp-68h] BYREF

sprintf(v2, "(timer-triggered %d)", a1);
result = performAddCommand(v2);
timers[2 * a1] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
__int64 result; // rax
char v2[104]; // [rsp+0h] [rbp-68h] BYREF

sprintf(v2, "(timer-triggered %d)", a1);
result = performAddCommand(v2);
timers[2 * a1] = 0;
return result;
}

original_code:
int fireTimer( int timerIndex )
{
  int ret;
  char element[80 +1];
  extern int performAddCommand( char *mem );
  sprintf( element, "(timer-triggered %d)", timerIndex );
  ret = performAddCommand( element );
  timers[timerIndex].active = 0;
  return ret;
}

canonical_original_code:
int fireTimer(int timerIndex)
{
  int ret;
  char element[-1];
  extern int performAddCommand(char *mem);
  sprintf( element, "(timer-triggered %d)", timerIndex );
  ret = performAddCommand( element );
  timers[timerIndex].active = 0;
  return ret;
}

variable_types: timerIndex int

variable_types: ret int

variable_types:
element
char [-1]

variable_types:
performAddCommand
int (char *mem)


startTimer

decompiled_code:
void __fastcall startTimer(int a1, int a2)
{
timers[2 * a1 + 1] = a2;
timers[2 * a1] = 1;
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2)
{
timers[2 * a1 + 1] = a2;
timers[2 * a1] = 1;
}

original_code:
void startTimer( int index, int expiration )
{
  timers[index].expiration = expiration;
  timers[index].active = 1;
  return;
}

canonical_original_code:
void startTimer(int index, int expiration)
{
  timers[index].expiration = expiration;
  timers[index].active = 1;
  return;
}

variable_types: index int

variable_types: expiration int


processTimers

decompiled_code:
__int64 processTimers()
{
__int64 i; // rbx
__int64 result; // rax

for ( i = 0LL; i != 10; ++i )
{
if ( timers[2 * i] )
{
result = (unsigned int)(timers[2 * i + 1] - 1);
timers[2 * i + 1] = result;
if ( !(_DWORD)result )
result = fireTimer(i);
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 i; // rbx
__int64 result; // rax

for ( i = 0LL; i != 10; ++i )
{
if ( timers[2 * i] )
{
result = (unsigned int)(timers[2 * i + 1] - 1);
timers[2 * i + 1] = result;
if ( !(_DWORD)result )
result = func0(i);
}
}
return result;
}

original_code:
void processTimers( void )
{
  int i;
  for (i = 0 ; i < 10 ; i++) {
    if (timers[i].active) {
      if (--timers[i].expiration == 0) {
        fireTimer( i );
      }
    }
  }
  return;
}

canonical_original_code:
void processTimers()
{
  int i;
  for (i = 0 ; i < 10 ; i++) {
    if (timers[i].active) {
      if (--timers[i].expiration == 0) {
        fireTimer( i );
      }
    }
  }
  return;
}

variable_types: i int


dialog

decompiled_code:
__int64 __fastcall dialog(int fd, void *buf, char *s2, int a4)
{
__int64 result; // rax
int v7; // eax
size_t v8; // r14

if ( fd == -1 )
return 0xFFFFFFFFLL;
if ( !buf )
return 0xFFFFFFFFLL;
if ( *(_BYTE *)buf )
{
v8 = (int)strlen((const char *)buf);
if ( write(fd, buf, v8) != v8 )
return 0xFFFFFFFFLL;
}
result = 0LL;
if ( s2 )
{
v7 = read(fd, buf, 0xC8uLL);
if ( v7 < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
*((_BYTE *)buf + v7) = 0;
result = (unsigned int)-(strncmp((const char *)buf, s2, a4) != 0);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, void *buf, char *s2, int a4)
{
__int64 result; // rax
int v7; // eax
size_t v8; // r14

if ( fd == -1 )
return 0xFFFFFFFFLL;
if ( !buf )
return 0xFFFFFFFFLL;
if ( *(_BYTE *)buf )
{
v8 = (int)strlen((const char *)buf);
if ( write(fd, buf, v8) != v8 )
return 0xFFFFFFFFLL;
}
result = 0LL;
if ( s2 )
{
v7 = read(fd, buf, 0xC8uLL);
if ( v7 < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
*((_BYTE *)buf + v7) = 0;
result = (unsigned int)-(strncmp((const char *)buf, s2, a4) != 0);
}
}
return result;
}

original_code:
int dialog( int sd, char *buffer, char *resp, int rlen )
{
  int ret, len;
  if ((sd == -1) || (!buffer)) return -1;
  if (strlen(buffer) > 0) {
    len = strlen( buffer );
    if ( write( sd, buffer, len ) != len ) return -1;
  }
  if (resp != ((void *)0)) {
    ret = read( sd, buffer, 200 );
    if (ret >= 0) {
      buffer[ret] = 0;
      if (strncmp( buffer, resp, rlen )) return -1;
    } else {
      return -1;
    }
  }
  return 0;
}

canonical_original_code:
int dialog(int sd, char *buffer, char *resp, int rlen)
{
  int ret; int len;
  if ((sd == -1) || (!buffer)) return -1;
  if (strlen(buffer) > 0) {
    len = strlen( buffer );
    if ( write( sd, buffer, len ) != len ) return -1;
  }
  if (resp != ((void *)0)) {
    ret = read( sd, buffer, 200 );
    if (ret >= 0) {
      buffer[ret] = 0;
      if (strncmp( buffer, resp, rlen )) return -1;
    } else {
      return -1;
    }
  }
  return 0;
}

variable_types: sd int

variable_types:
buffer
char *

variable_types:
resp
char *

variable_types: rlen int

variable_types: len int


nntpSetGroup

decompiled_code:
__int64 __fastcall nntpSetGroup(const char *a1, int a2)
{
__int64 result; // rax
unsigned int v3; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = -1;
if ( !a1 )
return 0xFFFFFFFFLL;
result = (unsigned int)sock;
if ( sock != -1 )
{
snprintf(&buffer, 0x50uLL, "group %s\n", a1);
if ( !(unsigned int)dialog(sock, &buffer, "211", 3) )
{
_isoc99_sscanf(&buffer, "211 %d %d %d ", &v3, &firstMessage, &lastMessage);
if ( a2 == -1 )
{
curMessage = firstMessage;
}
else
{
curMessage = a2 + 1;
v3 = lastMessage - a2;
}
printf("Set news group to %s\n", a1);
}
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, int a2)
{
__int64 result; // rax
unsigned int v3; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = -1;
if ( !a1 )
return 0xFFFFFFFFLL;
result = (unsigned int)sock;
if ( sock != -1 )
{
snprintf(&buffer, 0x50uLL, "group %s\n", a1);
if ( !(unsigned int)func1(sock, &buffer, "211", 3) )
{
_isoc99_sscanf(&buffer, "211 %d %d %d ", &v3, &firstMessage, &lastMessage);
if ( a2 == -1 )
{
curMessage = firstMessage;
}
else
{
curMessage = a2 + 1;
v3 = lastMessage - a2;
}
printf("Set news group to %s\n", a1);
}
result = v3;
}
return result;
}

original_code:
int nntpSetGroup( char *group, int lastRead )
{
  int result = -1;
  int numMessages = -1;
  if ((!group) || (sock == -1)) return -1;
  snprintf( buffer, 80, "group %s\n", group );
  result = dialog( sock, buffer, "211", 3 );
  if (result == 0) {
    sscanf( buffer, "211 %d %d %d ",
             &numMessages, &firstMessage, &lastMessage );
    if (lastRead == -1) {
      curMessage = firstMessage;
    } else {
      curMessage = lastRead+1;
      numMessages = lastMessage - lastRead;
    }
    printf("Set news group to %s\n", group);
  }
  return( numMessages );
}

canonical_original_code:
int nntpSetGroup(char *group, int lastRead)
{
  int result = -1;
  int numMessages = -1;
  if ((!group) || (sock == -1)) return -1;
  snprintf( buffer, 80, "group %s\n", group );
  result = dialog( sock, buffer, "211", 3 );
  if (result == 0) {
    sscanf( buffer, "211 %d %d %d ",
             &numMessages, &firstMessage, &lastMessage );
    if (lastRead == -1) {
      curMessage = firstMessage;
    } else {
      curMessage = lastRead+1;
      numMessages = lastMessage - lastRead;
    }
    printf("Set news group to %s\n", group);
  }
  return( numMessages );
}

variable_types:
group
char *

variable_types: lastRead int

variable_types: result int

variable_types: numMessages int


nntpPeek

decompiled_code:
__int64 __fastcall nntpPeek(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v4; // rcx
int v5; // eax
int v6; // esi
int v7; // ebx
__int64 v8; // rcx
__int64 i; // rax
int v10; // er13
int v11; // ebx
__int64 v12; // rbp
char v13; // dl
int v14; // ecx
int v15; // eax
__int64 v16; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
result = (unsigned int)sock;
if ( sock != -1 )
{
v4 = (unsigned int)curMessage;
if ( curMessage == -1 )
{
result = 4294967294LL;
}
else if ( curMessage > lastMessage )
{
result = 4294967294LL;
}
else
{
*(_DWORD *)(a1 + 12) = curMessage;
snprintf(buffer, 0x50uLL, "head %d\n", v4);
if ( (int)dialog(sock, buffer, "221", 3) < 0 )
{
result = 4294967293LL;
}
else
{
v5 = strlen(buffer);
v6 = v5;
v7 = v5;
if ( v5 <= 1 )
{
v10 = 0;
}
else
{
v8 = (unsigned int)(v5 - 2);
for ( i = 0LL; ; ++i )
{
if ( buffer[i] == 13 && buffer[i + 1] == 10 )
{
v7 = v6 - (i - 2);
memmove(*(void **)a1, &buffer[(int)i + 2], v7);
v10 = v7;
goto LABEL_15;
}
if ( v8 == i )
break;
}
v10 = 0;
}
LABEL_15:
if ( a2 - 79 > v10 + v7 )
{
v11 = 0;
do
{
v12 = v10;
v14 = read(sock, (void *)(*(_QWORD *)a1 + v10), a2 - v10);
v15 = v10;
v10 += v14;
if ( v10 > v15 )
{
v16 = v12 + (unsigned int)(v10 + ~v15) + 1;
do
{
if ( v11 )
{
switch ( v11 )
{
case 1:
v11 = 2 * (*(_BYTE *)(*(_QWORD *)a1 + v12) == 10);
break;
case 2:
v13 = *(_BYTE *)(*(_QWORD *)a1 + v12);
v11 = 1;
if ( v13 != 13 )
v11 = 3 * (v13 == 46);
break;
case 3:
v11 = 4 * (*(_BYTE *)(*(_QWORD *)a1 + v12) == 13);
break;
case 4:
if ( *(_BYTE *)(*(_QWORD *)a1 + v12) == 10 )
goto LABEL_34;
v11 = 0;
break;
default:
v11 = 0;
break;
}
}
else
{
v11 = *(_BYTE *)(*(_QWORD *)a1 + v12) == 13;
}
++v12;
}
while ( v16 != v12 );
}
}
while ( v10 + v14 < a2 - 79 );
}
LABEL_34:
result = (unsigned int)(v10 - 3);
*(_BYTE *)(*(_QWORD *)a1 + (int)result) = 0;
*(_DWORD *)(a1 + 8) = result;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v4; // rcx
int v5; // eax
int v6; // esi
int v7; // ebx
__int64 v8; // rcx
__int64 i; // rax
int v10; // er13
int v11; // ebx
__int64 v12; // rbp
char v13; // dl
int v14; // ecx
int v15; // eax
__int64 v16; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
result = (unsigned int)sock;
if ( sock != -1 )
{
v4 = (unsigned int)curMessage;
if ( curMessage == -1 )
{
result = 4294967294LL;
}
else if ( curMessage > lastMessage )
{
result = 4294967294LL;
}
else
{
*(_DWORD *)(a1 + 12) = curMessage;
snprintf(buffer, 0x50uLL, "head %d\n", v4);
if ( (int)func1(sock, buffer, "221", 3) < 0 )
{
result = 4294967293LL;
}
else
{
v5 = strlen(buffer);
v6 = v5;
v7 = v5;
if ( v5 <= 1 )
{
v10 = 0;
}
else
{
v8 = (unsigned int)(v5 - 2);
for ( i = 0LL; ; ++i )
{
if ( buffer[i] == 13 && buffer[i + 1] == 10 )
{
v7 = v6 - (i - 2);
memmove(*(void **)a1, &buffer[(int)i + 2], v7);
v10 = v7;
goto LABEL_15;
}
if ( v8 == i )
break;
}
v10 = 0;
}
LABEL_15:
if ( a2 - 79 > v10 + v7 )
{
v11 = 0;
do
{
v12 = v10;
v14 = read(sock, (void *)(*(_QWORD *)a1 + v10), a2 - v10);
v15 = v10;
v10 += v14;
if ( v10 > v15 )
{
v16 = v12 + (unsigned int)(v10 + ~v15) + 1;
do
{
if ( v11 )
{
switch ( v11 )
{
case 1:
v11 = 2 * (*(_BYTE *)(*(_QWORD *)a1 + v12) == 10);
break;
case 2:
v13 = *(_BYTE *)(*(_QWORD *)a1 + v12);
v11 = 1;
if ( v13 != 13 )
v11 = 3 * (v13 == 46);
break;
case 3:
v11 = 4 * (*(_BYTE *)(*(_QWORD *)a1 + v12) == 13);
break;
case 4:
if ( *(_BYTE *)(*(_QWORD *)a1 + v12) == 10 )
goto LABEL_34;
v11 = 0;
break;
default:
v11 = 0;
break;
}
}
else
{
v11 = *(_BYTE *)(*(_QWORD *)a1 + v12) == 13;
}
++v12;
}
while ( v16 != v12 );
}
}
while ( v10 + v14 < a2 - 79 );
}
LABEL_34:
result = (unsigned int)(v10 - 3);
*(_BYTE *)(*(_QWORD *)a1 + (int)result) = 0;
*(_DWORD *)(a1 + 8) = result;
}
}
}
return result;
}

original_code:
int nntpPeek ( news_t *news, int totalLen )
{
  int result = -1, i, len=0, stop, state, bufIdx=0;
  if ((!news) || (sock == -1)) return -1;
  if ((curMessage == -1) || (curMessage > lastMessage)) return -2;
  news->msgId = curMessage;
  snprintf( buffer, 80, "head %d\n", curMessage );
  result = dialog( sock, buffer, "221", 3 );
  if (result < 0) return -3;
  len = strlen( buffer );
  for ( i = 0 ; i < len-1 ; i++ ) {
    if ( (buffer[i] == 0x0d) && (buffer[i+1] == 0x0a) ) {
      len -= i-2;
      memmove( news->msg, &buffer[i+2], len );
      bufIdx = len;
      break;
    }
  }
  state = stop = 0;
  while (!stop) {
    if (bufIdx+len > totalLen - 80) break;
    len = read( sock, &news->msg[bufIdx], (totalLen-bufIdx) );
    for ( i = bufIdx ; i < bufIdx+len ; i++ ) {
      if ( (state == 0) && (news->msg[i] == 0x0d) ) state = 1;
      else if ( (state == 1) && (news->msg[i] == 0x0a) ) state = 2;
      else if ( (state == 2) && (news->msg[i] == 0x0d) ) state = 1;
      else if ( (state == 2) && (news->msg[i] == '.') ) state = 3;
      else if ( (state == 3) && (news->msg[i] == 0x0d) ) state = 4;
      else if ( (state == 4) && (news->msg[i] == 0x0a) ) { stop = 1; break; }
      else state = 0;
    }
    bufIdx += len;
  }
  bufIdx -= 3;
  news->msg[bufIdx] = 0;
  news->msgLen = bufIdx;
  return bufIdx;
}

canonical_original_code:
int nntpPeek(struct news_t *news, int totalLen)
{
  int result = -1; int i; int len = 0; int stop; int state; int bufIdx = 0;
  if ((!news) || (sock == -1)) return -1;
  if ((curMessage == -1) || (curMessage > lastMessage)) return -2;
  news->msgId = curMessage;
  snprintf( buffer, 80, "head %d\n", curMessage );
  result = dialog( sock, buffer, "221", 3 );
  if (result < 0) return -3;
  len = strlen( buffer );
  for ( i = 0 ; i < len-1 ; i++ ) {
    if ( (buffer[i] == 0x0d) && (buffer[i+1] == 0x0a) ) {
      len -= i-2;
      memmove( news->msg, &buffer[i+2], len );
      bufIdx = len;
      break;
    }
  }
  state = stop = 0;
  while (!stop) {
    if (bufIdx+len > totalLen - 80) break;
    len = read( sock, &news->msg[bufIdx], (totalLen-bufIdx) );
    for ( i = bufIdx ; i < bufIdx+len ; i++ ) {
      if ( (state == 0) && (news->msg[i] == 0x0d) ) state = 1;
      else if ( (state == 1) && (news->msg[i] == 0x0a) ) state = 2;
      else if ( (state == 2) && (news->msg[i] == 0x0d) ) state = 1;
      else if ( (state == 2) && (news->msg[i] == '.') ) state = 3;
      else if ( (state == 3) && (news->msg[i] == 0x0d) ) state = 4;
      else if ( (state == 4) && (news->msg[i] == 0x0a) ) { stop = 1; break; }
      else state = 0;
    }
    bufIdx += len;
  }
  bufIdx -= 3;
  news->msg[bufIdx] = 0;
  news->msgLen = bufIdx;
  return bufIdx;
}

variable_types: struct news_t { char *msg; int msgLen; int msgId; char subject[-1]; char sender[-1]; char msgDate[-1]; char *bodyStart; } *

variable_types: totalLen int

variable_types: stop int

variable_types: state int

variable_types: bufIdx int


nntpSkip

decompiled_code:
void nntpSkip()
{
++curMessage;
}

canonical_decompiled_code:
void func4()
{
++curMessage;
}

original_code:
void nntpSkip( void )
{
  curMessage++;
}

canonical_original_code:
void nntpSkip()
{
  curMessage++;
}


nntpRetrieve

decompiled_code:
__int64 __fastcall nntpRetrieve(__int64 a1, int a2)
{
__int64 result; // rax
int v4; // eax
int v5; // esi
int v6; // er13
__int64 v7; // rcx
__int64 i; // rax
int v9; // ebp
int v10; // ebx
__int64 v11; // rax
char v12; // dl
int v13; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
result = (unsigned int)sock;
if ( sock != -1 )
{
result = (unsigned int)curMessage;
if ( curMessage != -1 )
{
if ( curMessage > lastMessage )
{
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)(a1 + 12) = curMessage;
curMessage = result + 1;
snprintf(buffer, 0x50uLL, "article %d\n", (unsigned int)result);
if ( (int)dialog(sock, buffer, "220", 3) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v4 = strlen(buffer);
v5 = v4;
v6 = v4;
if ( v4 > 1 )
{
v7 = (unsigned int)(v4 - 2);
for ( i = 0LL; buffer[i] != 13 || buffer[i + 1] != 10; ++i )
{
if ( v7 == i )
goto LABEL_13;
}
v6 = v5 - (i - 2);
memmove(*(void **)a1, &buffer[(int)i + 2], v6);
}
LABEL_13:
if ( v6 >= a2 - 79 )
{
v9 = 0;
}
else
{
v9 = 0;
v10 = 0;
do
{
if ( v6 > v9 )
{
v11 = v9;
do
{
if ( v10 )
{
switch ( v10 )
{
case 1:
v10 = 2 * (*(_BYTE *)(*(_QWORD *)a1 + v11) == 10);
break;
case 2:
v12 = *(_BYTE *)(*(_QWORD *)a1 + v11);
v10 = 1;
if ( v12 != 13 )
v10 = 3 * (v12 == 46);
break;
case 3:
v10 = 4 * (*(_BYTE *)(*(_QWORD *)a1 + v11) == 13);
break;
case 4:
if ( *(_BYTE *)(*(_QWORD *)a1 + v11) == 10 )
goto LABEL_36;
v10 = 0;
break;
default:
v10 = 0;
break;
}
}
else
{
v10 = *(_BYTE *)(*(_QWORD *)a1 + v11) == 13;
}
++v9;
++v11;
}
while ( v9 != v6 );
v9 = v6;
}
v13 = read(sock, (void *)(*(_QWORD *)a1 + v9), a2 - v9);
if ( v13 <= 0 )
break;
v6 = v9 + v13;
if ( v9 + v13 > a2 )
break;
}
while ( v6 < a2 - 79 );
}
LABEL_36:
result = (unsigned int)(v9 - 3);
*(_BYTE *)(*(_QWORD *)a1 + (int)result) = 0;
*(_DWORD *)(a1 + 8) = result;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
__int64 result; // rax
int v4; // eax
int v5; // esi
int v6; // er13
__int64 v7; // rcx
__int64 i; // rax
int v9; // ebp
int v10; // ebx
__int64 v11; // rax
char v12; // dl
int v13; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
result = (unsigned int)sock;
if ( sock != -1 )
{
result = (unsigned int)curMessage;
if ( curMessage != -1 )
{
if ( curMessage > lastMessage )
{
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)(a1 + 12) = curMessage;
curMessage = result + 1;
snprintf(buffer, 0x50uLL, "article %d\n", (unsigned int)result);
if ( (int)func1(sock, buffer, "220", 3) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v4 = strlen(buffer);
v5 = v4;
v6 = v4;
if ( v4 > 1 )
{
v7 = (unsigned int)(v4 - 2);
for ( i = 0LL; buffer[i] != 13 || buffer[i + 1] != 10; ++i )
{
if ( v7 == i )
goto LABEL_13;
}
v6 = v5 - (i - 2);
memmove(*(void **)a1, &buffer[(int)i + 2], v6);
}
LABEL_13:
if ( v6 >= a2 - 79 )
{
v9 = 0;
}
else
{
v9 = 0;
v10 = 0;
do
{
if ( v6 > v9 )
{
v11 = v9;
do
{
if ( v10 )
{
switch ( v10 )
{
case 1:
v10 = 2 * (*(_BYTE *)(*(_QWORD *)a1 + v11) == 10);
break;
case 2:
v12 = *(_BYTE *)(*(_QWORD *)a1 + v11);
v10 = 1;
if ( v12 != 13 )
v10 = 3 * (v12 == 46);
break;
case 3:
v10 = 4 * (*(_BYTE *)(*(_QWORD *)a1 + v11) == 13);
break;
case 4:
if ( *(_BYTE *)(*(_QWORD *)a1 + v11) == 10 )
goto LABEL_36;
v10 = 0;
break;
default:
v10 = 0;
break;
}
}
else
{
v10 = *(_BYTE *)(*(_QWORD *)a1 + v11) == 13;
}
++v9;
++v11;
}
while ( v9 != v6 );
v9 = v6;
}
v13 = read(sock, (void *)(*(_QWORD *)a1 + v9), a2 - v9);
if ( v13 <= 0 )
break;
v6 = v9 + v13;
if ( v9 + v13 > a2 )
break;
}
while ( v6 < a2 - 79 );
}
LABEL_36:
result = (unsigned int)(v9 - 3);
*(_BYTE *)(*(_QWORD *)a1 + (int)result) = 0;
*(_DWORD *)(a1 + 8) = result;
}
}
}
}
return result;
}

original_code:
int nntpRetrieve ( news_t *news, int totalLen )
{
  int result = -1, i, len=0, stop, state, bufIdx=0;
  if ((!news) || (sock == -1)) return -1;
  if ((curMessage == -1) || (curMessage > lastMessage)) return -1;
  news->msgId = curMessage;
  snprintf( buffer, 80, "article %d\n", curMessage++ );
  result = dialog( sock, buffer, "220", 3 );
  if (result < 0) return -1;
  len = strlen(buffer);
  for ( i = 0 ; i < len-1 ; i++ ) {
    if ( (buffer[i] == 0x0d) && (buffer[i+1] == 0x0a) ) {
      len -= i-2;
      memmove( news->msg, &buffer[i+2], len );
      break;
    }
  }
  state = stop = 0;
  while (!stop) {
    if (bufIdx+len > totalLen - 80) break;
    for ( i = bufIdx ; i < bufIdx+len ; i++ ) {
      if ( (state == 0) && (news->msg[i] == 0x0d) ) state = 1;
      else if ( (state == 1) && (news->msg[i] == 0x0a) ) state = 2;
      else if ( (state == 2) && (news->msg[i] == 0x0d) ) state = 1;
      else if ( (state == 2) && (news->msg[i] == '.') ) state = 3;
      else if ( (state == 3) && (news->msg[i] == 0x0d) ) state = 4;
      else if ( (state == 4) && (news->msg[i] == 0x0a) ) { stop = 1; break; }
      else state = 0;
    }
    bufIdx += (i-bufIdx);
    if (!stop) {
      len = read( sock, &news->msg[bufIdx], (totalLen-bufIdx) );
      if ( (len <= 0) || (bufIdx+len > totalLen) ) {
        break;
      }
    }
  }
  bufIdx -= 3;
  news->msg[bufIdx] = 0;
  news->msgLen = bufIdx;
  return bufIdx;
}

canonical_original_code:
int nntpRetrieve(struct news_t *news, int totalLen)
{
  int result = -1; int i; int len = 0; int stop; int state; int bufIdx = 0;
  if ((!news) || (sock == -1)) return -1;
  if ((curMessage == -1) || (curMessage > lastMessage)) return -1;
  news->msgId = curMessage;
  snprintf( buffer, 80, "article %d\n", curMessage++ );
  result = dialog( sock, buffer, "220", 3 );
  if (result < 0) return -1;
  len = strlen(buffer);
  for ( i = 0 ; i < len-1 ; i++ ) {
    if ( (buffer[i] == 0x0d) && (buffer[i+1] == 0x0a) ) {
      len -= i-2;
      memmove( news->msg, &buffer[i+2], len );
      break;
    }
  }
  state = stop = 0;
  while (!stop) {
    if (bufIdx+len > totalLen - 80) break;
    for ( i = bufIdx ; i < bufIdx+len ; i++ ) {
      if ( (state == 0) && (news->msg[i] == 0x0d) ) state = 1;
      else if ( (state == 1) && (news->msg[i] == 0x0a) ) state = 2;
      else if ( (state == 2) && (news->msg[i] == 0x0d) ) state = 1;
      else if ( (state == 2) && (news->msg[i] == '.') ) state = 3;
      else if ( (state == 3) && (news->msg[i] == 0x0d) ) state = 4;
      else if ( (state == 4) && (news->msg[i] == 0x0a) ) { stop = 1; break; }
      else state = 0;
    }
    bufIdx += (i-bufIdx);
    if (!stop) {
      len = read( sock, &news->msg[bufIdx], (totalLen-bufIdx) );
      if ( (len <= 0) || (bufIdx+len > totalLen) ) {
        break;
      }
    }
  }
  bufIdx -= 3;
  news->msg[bufIdx] = 0;
  news->msgLen = bufIdx;
  return bufIdx;
}

user_defined_types: struct news_t { char *msg; int msgLen; int msgId; char subject[-1]; char sender[-1]; char msgDate[-1]; char *bodyStart; }


nntpParse

decompiled_code:
__int64 __fastcall nntpParse(__int64 a1, int a2)
{
int v2; // ebp

if ( a1 )
{
if ( (int)parseEntry(a1, "Subject:", a1 + 16) < 0 )
{
v2 = -1;
}
else if ( (int)parseEntry(a1, "Date:", a1 + 218) < 0 )
{
v2 = -2;
}
else
{
v2 = parseEntry(a1, "From:", a1 + 117);
if ( v2 < 0 )
{
v2 = -3;
}
else
{
fixAddress(a1 + 117);
if ( !a2 )
v2 = findBody(a1);
}
}
}
else
{
v2 = -1;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
int v2; // ebp

if ( a1 )
{
if ( (int)parseEntry(a1, "Subject:", a1 + 16) < 0 )
{
v2 = -1;
}
else if ( (int)parseEntry(a1, "Date:", a1 + 218) < 0 )
{
v2 = -2;
}
else
{
v2 = parseEntry(a1, "From:", a1 + 117);
if ( v2 < 0 )
{
v2 = -3;
}
else
{
fixAddress(a1 + 117);
if ( !a2 )
v2 = findBody(a1);
}
}
}
else
{
v2 = -1;
}
return (unsigned int)v2;
}

original_code:
int nntpParse( news_t *news, unsigned int flags )
{
  int result;
  if (!news) return -1;
  result = parseEntry( news, "Subject:", news->subject );
  if (result < 0) return -1;
  result = parseEntry( news, "Date:", news->msgDate );
  if (result < 0) return -2;
  result = parseEntry( news, "From:", news->sender );
  if (result < 0) return -3;
  fixAddress( news->sender );
  if (flags == 0) {
    result = findBody( news );
  }
  return result;
}

canonical_original_code:
int nntpParse(struct news_t *news, unsigned int flags)
{
  int result;
  if (!news) return -1;
  result = parseEntry( news, "Subject:", news->subject );
  if (result < 0) return -1;
  result = parseEntry( news, "Date:", news->msgDate );
  if (result < 0) return -2;
  result = parseEntry( news, "From:", news->sender );
  if (result < 0) return -3;
  fixAddress( news->sender );
  if (flags == 0) {
    result = findBody( news );
  }
  return result;
}

variable_types:
flags
unsigned int


nntpDisconnect

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

result = (unsigned int)sock;
if ( sock != -1 )
{
close(sock);
lastMessage = -1;
firstMessage = -1;
curMessage = -1;
sock = -1;
result = 0LL;
}
return result;
}

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

result = (unsigned int)sock;
if ( sock != -1 )
{
close(sock);
lastMessage = -1;
firstMessage = -1;
curMessage = -1;
sock = -1;
result = 0LL;
}
return result;
}

original_code:
int nntpDisconnect ( void )
{
  if (sock == -1) return -1;
  close(sock);
  sock = curMessage = firstMessage = lastMessage = -1;
  return 0;
}

canonical_original_code:
int nntpDisconnect()
{
  if (sock == -1) return -1;
  close(sock);
  sock = curMessage = firstMessage = lastMessage = -1;
  return 0;
}


nntpConnect

decompiled_code:
__int64 __fastcall nntpConnect(char *name)
{
int v1; // ebx
struct hostent *v3; // rax
__int64 v4; // rdi
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

if ( name )
{
sock = socket(2, 1, 0);
v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[6] = 0LL;
*(_WORD *)v5.sa_data = _bswap_16(119);
*(_DWORD *)&v5.sa_data[2] = inet_addr(name);
if ( *(_DWORD *)&v5.sa_data[2] == -1 )
{
v3 = gethostbyname(name);
if ( !v3 )
return (unsigned int)-1;
*(_DWORD *)&v5.sa_data[2] = **(_DWORD **)v3->h_addr_list;
}
printf("Connecting to %s\n", name);
v1 = connect(sock, &v5, 0x10u);
if ( v1 >= 0 )
{
buffer[0] = 0;
v4 = (unsigned int)sock;
v1 = dialog(sock, buffer, "20", 2);
if ( v1 < 0 )
nntpDisconnect(v4, buffer);
}
}
else
{
v1 = -1;
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *name)
{
int v1; // ebx
struct hostent *v3; // rax
__int64 v4; // rdi
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

if ( name )
{
sock = socket(2, 1, 0);
v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[6] = 0LL;
*(_WORD *)v5.sa_data = func0(119);
*(_DWORD *)&v5.sa_data[2] = inet_addr(name);
if ( *(_DWORD *)&v5.sa_data[2] == -1 )
{
v3 = gethostbyname(name);
if ( !v3 )
return (unsigned int)-1;
*(_DWORD *)&v5.sa_data[2] = **(_DWORD **)v3->h_addr_list;
}
printf("Connecting to %s\n", name);
v1 = connect(sock, &v5, 0x10u);
if ( v1 >= 0 )
{
buffer[0] = 0;
v4 = (unsigned int)sock;
v1 = func1(sock, buffer, "20", 2);
if ( v1 < 0 )
func7(v4, buffer);
}
}
else
{
v1 = -1;
}
return (unsigned int)v1;
}

original_code:
int nntpConnect ( char *nntpServer )
{
  int result = -1;
  struct sockaddr_in servaddr;
  if (!nntpServer) return -1;
  sock = socket( 2, SOCK_STREAM, 0 );
  bzero( &servaddr, sizeof(servaddr) );
  servaddr.sin_family = 2;
  servaddr.sin_port = htons( 119 );
  servaddr.sin_addr.s_addr = inet_addr( nntpServer );
  if ( servaddr.sin_addr.s_addr == 0xffffffff ) {
    struct hostent *hptr = (struct hostent *)gethostbyname( nntpServer );
    if ( hptr == ((void *)0) ) {
      return -1;
    } else {
      struct in_addr **addrs;
      addrs = (struct in_addr **)hptr->h_addr_list;
      memcpy( &servaddr.sin_addr, *addrs, sizeof(struct in_addr) );
    }
  }
  printf( "Connecting to %s\n", nntpServer );
  result = connect( sock, (struct sockaddr *)&servaddr, sizeof(servaddr) );
  if ( result >= 0 ) {
    buffer[0] = 0;
    result = dialog( sock, buffer, "20", 2 );
    if (result < 0) nntpDisconnect();
  }
  return ( result );
}

canonical_original_code:
int nntpConnect(char *nntpServer)
{
  int result = -1;
  struct sockaddr_in servaddr;
  if (!nntpServer) return -1;
  sock = socket( 2, SOCK_STREAM, 0 );
  bzero( &servaddr, sizeof(servaddr) );
  servaddr.sin_family = 2;
  servaddr.sin_port = htons( 119 );
  servaddr.sin_addr.s_addr = inet_addr( nntpServer );
  if ( servaddr.sin_addr.s_addr == 0xffffffff ) {
    struct hostent *hptr = (struct hostent *)gethostbyname( nntpServer );
    if ( hptr == ((void *)0) ) {
      return -1;
    } else {
      struct in_addr **addrs;
      addrs = (struct in_addr **)hptr->h_addr_list;
      memcpy( &servaddr.sin_addr, *addrs, sizeof(struct in_addr) );
    }
  }
  printf( "Connecting to %s\n", nntpServer );
  result = connect( sock, (struct sockaddr *)&servaddr, sizeof(servaddr) );
  if ( result >= 0 ) {
    buffer[0] = 0;
    result = dialog( sock, buffer, "20", 2 );
    if (result < 0) nntpDisconnect();
  }
  return ( result );
}

variable_types:
nntpServer
char *

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

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: struct in_addr { unsigned int s_addr; } **

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

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


assignRandomWeights

decompiled_code:
int assignRandomWeights()
{
__int64 i; // rbp
__int64 j; // rbx
__int64 k; // rbp
__int64 l; // rbx
int result; // eax

for ( i = 0LL; i != 15; i += 3LL )
{
for ( j = 0LL; j != 3; ++j )
*(double *)&wih[j + i] = (float)((float)rand() * 4.6566129e-10) - 0.5;
}
for ( k = 0LL; k != 16; k += 4LL )
{
for ( l = 0LL; l != 4; ++l )
{
result = rand();
*(double *)&who[l + k] = (float)((float)result * 4.6566129e-10) - 0.5;
}
}
return result;
}

original_code:
void assignRandomWeights( void )
{
  int hid, inp, out;
  for (inp = 0 ; inp < 4 +1 ; inp++) {
    for (hid = 0 ; hid < 3 ; hid++) {
      wih[inp][hid] = ( ((float)rand() / (float)2147483647) - 0.5);
    }
  }
  for (hid = 0 ; hid < 3 +1 ; hid++) {
    for (out = 0 ; out < 4 ; out++) {
      who[hid][out] = ( ((float)rand() / (float)2147483647) - 0.5);
    }
  }
}

canonical_original_code:
void assignRandomWeights()
{
  int hid; int inp; int out;
  for (inp = 0 ; inp < 4 +1 ; inp++) {
    for (hid = 0 ; hid < 3 ; hid++) {
      wih[inp][hid] = ( ((float)rand() / (float)2147483647) - 0.5);
    }
  }
  for (hid = 0 ; hid < 3 +1 ; hid++) {
    for (out = 0 ; out < 4 ; out++) {
      who[hid][out] = ( ((float)rand() / (float)2147483647) - 0.5);
    }
  }
}

variable_types: hid int

variable_types: inp int

variable_types: out int


sigmoid

decompiled_code:
double __fastcall sigmoid(double a1)
{
return 1.0 / (exp(-a1) + 1.0);
}

canonical_decompiled_code:
double __fastcall func8(double a1)
{
return 1.0 / (exp(-a1) + 1.0);
}

original_code:
double sigmoid( double val )
{
  return (1.0 / (1.0 + exp(-val)));
}

canonical_original_code:
double sigmoid(double val)
{
  return (1.0 / (1.0 + exp(-val)));
}

variable_types: val double


feedForward

decompiled_code:
void feedForward()
{
__int64 i; // rbx
__int64 *v1; // rax
double *v2; // rdx
double v3; // xmm1_8
__int64 j; // rbx

for ( i = 0LL; i != 3; ++i )
{
v1 = &inputs;
v2 = (double *)&wih[i];
v3 = 0.0;
do
{
v3 = v3 + *(double *)v1++ * *v2;
v2 += 3;
}
while ( v1 != who );
*(double *)&hidden[i] = sigmoid(v3 + *(double *)&qword_404700[i]);
}
for ( j = 0LL; j != 4; ++j )
*(double *)&actual[j] = sigmoid(
*(double *)&qword_4045F0 * *(double *)&qword_404660[j]
+ *(double *)hidden * *(double *)&who[j]
+ 0.0
+ *(double *)&qword_4045E8 * *(double *)&qword_404640[j]
+ *(double *)&qword_404680[j]);
}

original_code:
void feedForward( )
{
  int inp, hid, out;
  double sum;
  for (hid = 0 ; hid < 3 ; hid++) {
    sum = 0.0;
    for (inp = 0 ; inp < 4 ; inp++) {
      sum += inputs[inp] * wih[inp][hid];
    }
    sum += wih[4][hid];
    hidden[hid] = sigmoid( sum );
  }
  for (out = 0 ; out < 4 ; out++) {
    sum = 0.0;
    for (hid = 0 ; hid < 3 ; hid++) {
      sum += hidden[hid] * who[hid][out];
    }
    sum += who[3][out];
    actual[out] = sigmoid( sum );
  }
}

canonical_original_code:
void feedForward()
{
  int inp; int hid; int out;
  double sum;
  for (hid = 0 ; hid < 3 ; hid++) {
    sum = 0.0;
    for (inp = 0 ; inp < 4 ; inp++) {
      sum += inputs[inp] * wih[inp][hid];
    }
    sum += wih[4][hid];
    hidden[hid] = sigmoid( sum );
  }
  for (out = 0 ; out < 4 ; out++) {
    sum = 0.0;
    for (hid = 0 ; hid < 3 ; hid++) {
      sum += hidden[hid] * who[hid][out];
    }
    sum += who[3][out];
    actual[out] = sigmoid( sum );
  }
}

variable_types: sum double


backPropagate

decompiled_code:
__int64 *backPropagate()
{
__int64 i; // rbx
double v1; // xmm0_8
__int64 v2; // rbp
__int64 j; // rbx
__int64 v4; // rax
__int64 k; // rcx
double v6; // xmm1_8
double *v7; // rdx
__int64 *v8; // rax
__int64 l; // rcx
double v10; // xmm1_8
double *v11; // rdx
__int64 *result; // rax
double v13; // [rsp+0h] [rbp-18h]
double v14; // [rsp+0h] [rbp-18h]

for ( i = 0LL; i != 4; ++i )
{
v1 = *(double *)&actual[i];
v13 = *(double *)&target[i] - v1;
*(double *)&erro[i] = sigmoidDerivative(v1) * v13;
}
v2 = 0LL;
for ( j = 0LL; j != 12; j += 4LL )
{
v4 = 0LL;
v14 = 0.0;
do
{
v14 = *(double *)&erro[v4] * *(double *)&who[j + v4] + v14;
++v4;
}
while ( v4 != 4 );
*(double *)&errh[v2] = sigmoidDerivative(*(double *)&hidden[v2]) * v14;
++v2;
}
for ( k = 0LL; k != 4; ++k )
{
v6 = 0.2 * *(double *)&erro[k];
v7 = (double *)&who[k];
v8 = hidden;
do
{
*v7 = v6 * *(double *)v8 + *v7;
v7 += 4;
++v8;
}
while ( v8 != (__int64 *)&unk_4045F8 );
*(double *)&qword_404680[k] = v6 + *(double *)&qword_404680[k];
}
for ( l = 0LL; l != 3; ++l )
{
v10 = 0.2 * *(double *)&errh[l];
v11 = (double *)&wih[l];
result = &inputs;
do
{
*v11 = v10 * *(double *)result + *v11;
v11 += 3;
++result;
}
while ( result != who );
*(double *)&qword_404700[l] = v10 + *(double *)&qword_404700[l];
}
return result;
}

original_code:
void backPropagate( void )
{
  int inp, hid, out;
  for (out = 0 ; out < 4 ; out++) {
    erro[out] = (target[out] - actual[out]) * sigmoidDerivative( actual[out] );
  }
  for (hid = 0 ; hid < 3 ; hid++) {
    errh[hid] = 0.0;
    for (out = 0 ; out < 4 ; out++) {
      errh[hid] += erro[out] * who[hid][out];
    }
    errh[hid] *= sigmoidDerivative( hidden[hid] );
  }
  for (out = 0 ; out < 4 ; out++) {
    for (hid = 0 ; hid < 3 ; hid++) {
      who[hid][out] += (0.2 * erro[out] * hidden[hid]);
    }
    who[3][out] += (0.2 * erro[out]);
  }
  for (hid = 0 ; hid < 3 ; hid++) {
    for (inp = 0 ; inp < 4 ; inp++) {
      wih[inp][hid] += (0.2 * errh[hid] * inputs[inp]);
    }
    wih[4][hid] += (0.2 * errh[hid]);
  }
}

canonical_original_code:
void backPropagate()
{
  int inp; int hid; int out;
  for (out = 0 ; out < 4 ; out++) {
    erro[out] = (target[out] - actual[out]) * sigmoidDerivative( actual[out] );
  }
  for (hid = 0 ; hid < 3 ; hid++) {
    errh[hid] = 0.0;
    for (out = 0 ; out < 4 ; out++) {
      errh[hid] += erro[out] * who[hid][out];
    }
    errh[hid] *= sigmoidDerivative( hidden[hid] );
  }
  for (out = 0 ; out < 4 ; out++) {
    for (hid = 0 ; hid < 3 ; hid++) {
      who[hid][out] += (0.2 * erro[out] * hidden[hid]);
    }
    who[3][out] += (0.2 * erro[out]);
  }
  for (hid = 0 ; hid < 3 ; hid++) {
    for (inp = 0 ; inp < 4 ; inp++) {
      wih[inp][hid] += (0.2 * errh[hid] * inputs[inp]);
    }
    wih[4][hid] += (0.2 * errh[hid]);
  }
}


action

decompiled_code:
__int64 __fastcall action(double *a1)
{
double v1; // xmm0_8
__int64 result; // rax
double v3; // xmm1_8

v1 = a1[1];
result = 1LL;
if ( v1 <= *a1 )
{
v1 = *a1;
result = 0LL;
}
v3 = a1[2];
if ( v3 > v1 )
result = 2LL;
else
v3 = v1;
if ( a1[3] > v3 )
result = 3LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(double *a1)
{
double v1; // xmm0_8
__int64 result; // rax
double v3; // xmm1_8

v1 = a1[1];
result = 1LL;
if ( v1 <= *a1 )
{
v1 = *a1;
result = 0LL;
}
v3 = a1[2];
if ( v3 > v1 )
result = 2LL;
else
v3 = v1;
if ( a1[3] > v3 )
result = 3LL;
return result;
}

original_code:
int action( double *vector )
{
  int index, sel;
  double max;
  sel = 0;
  max = vector[sel];
  for (index = 1 ; index < 4 ; index++) {
    if (vector[index] > max) {
      max = vector[index]; sel = index;
    }
  }
  return( sel );
}

canonical_original_code:
int action(double *vector)
{
  int index; int sel;
  double max;
  sel = 0;
  max = vector[sel];
  for (index = 1 ; index < 4 ; index++) {
    if (vector[index] > max) {
      max = vector[index]; sel = index;
    }
  }
  return( sel );
}

variable_types:
vector
double *

variable_types: index int

variable_types: sel int

variable_types: max double


emitHTTPResponseHeader

decompiled_code:
ssize_t __fastcall emitHTTPResponseHeader(int fd)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // rax
size_t v4; // rax
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

strcpy(v6, "HTTP/1.1 200 OK\n");
v1 = strlen(v6);
write(fd, v6, v1);
strcpy(v6, "Server: tinyHttp\n");
v2 = strlen(v6);
write(fd, v6, v2);
strcpy(v6, "Connection: close\n");
v3 = strlen(v6);
write(fd, v6, v3);
strcpy(v6, "Content-Type: text/html\n\n");
v4 = strlen(v6);
return write(fd, v6, v4);
}

canonical_decompiled_code:
ssize_t __fastcall func2(int fd)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // rax
size_t v4; // rax
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

strcpy(v6, "HTTP/1.1 200 OK\n");
v1 = strlen(v6);
write(fd, v6, v1);
strcpy(v6, "Server: tinyHttp\n");
v2 = strlen(v6);
write(fd, v6, v2);
strcpy(v6, "Connection: close\n");
v3 = strlen(v6);
write(fd, v6, v3);
strcpy(v6, "Content-Type: text/html\n\n");
v4 = strlen(v6);
return write(fd, v6, v4);
}

original_code:
void emitHTTPResponseHeader( int connfd )
{
  char line[80];
  strcpy( line, "HTTP/1.1 200 OK\n" );
  write( connfd, line, strlen(line) );
  strcpy( line, "Server: tinyHttp\n" );
  write( connfd, line, strlen(line) );
  strcpy( line, "Connection: close\n" );
  write( connfd, line, strlen(line) );
  strcpy( line, "Content-Type: text/html\n\n" );
  write( connfd, line, strlen(line) );
  return;
}

canonical_original_code:
void emitHTTPResponseHeader(int connfd)
{
  char line[80];
  strcpy( line, "HTTP/1.1 200 OK\n" );
  write( connfd, line, strlen(line) );
  strcpy( line, "Server: tinyHttp\n" );
  write( connfd, line, strlen(line) );
  strcpy( line, "Connection: close\n" );
  write( connfd, line, strlen(line) );
  strcpy( line, "Content-Type: text/html\n\n" );
  write( connfd, line, strlen(line) );
  return;
}

variable_types: connfd int

variable_types:
line
char [80]


getFilename

decompiled_code:
char __fastcall getFilename(char *s, char *a2, int a3)
{
__int64 v3; // rax
size_t v4; // rbx
__int64 v5; // rbp
char v6; // al
bool v7; // zf
char result; // al

if ( s[a3] == 32 )
{
v3 = a3 + 1;
do
a3 = v3++;
while ( s[v3 - 1] == 32 );
}
v4 = a3;
v5 = 0LL;
while ( strlen(s) > v4 )
{
v6 = s[v4++];
if ( v6 == 32 )
{
a2[(int)v5] = 0;
break;
}
a2[v5++] = v6;
}
v7 = strcmp(a2, "/") == 0;
result = !v7;
if ( v7 )
{
result = 47;
strcpy(a2, "/index.html");
}
return result;
}

canonical_decompiled_code:
char __fastcall func3(char *s, char *a2, int a3)
{
__int64 v3; // rax
size_t v4; // rbx
__int64 v5; // rbp
char v6; // al
bool v7; // zf
char result; // al

if ( s[a3] == 32 )
{
v3 = a3 + 1;
do
a3 = v3++;
while ( s[v3 - 1] == 32 );
}
v4 = a3;
v5 = 0LL;
while ( strlen(s) > v4 )
{
v6 = s[v4++];
if ( v6 == 32 )
{
a2[(int)v5] = 0;
break;
}
a2[v5++] = v6;
}
v7 = strcmp(a2, "/") == 0;
result = !v7;
if ( v7 )
{
result = 47;
strcpy(a2, "/index.html");
}
return result;
}

original_code:
void getFilename(char *inbuf, char *out, int start)
{
  int i=start, j=0;
  while (inbuf[i] == ' ') i++;
  for ( ; i < strlen(inbuf) ; i++) {
    if (inbuf[i] == ' ') {
      out[j] = 0;
      break;
    }
    out[j++] = inbuf[i];
  }
  if (!strcmp(out, "/")) strcpy(out, "/index.html");
  return;
}

canonical_original_code:
void getFilename(char *inbuf, char *out, int start)
{
  int i = start; int j = 0;
  while (inbuf[i] == ' ') i++;
  for ( ; i < strlen(inbuf) ; i++) {
    if (inbuf[i] == ' ') {
      out[j] = 0;
      break;
    }
    out[j++] = inbuf[i];
  }
  if (!strcmp(out, "/")) strcpy(out, "/index.html");
  return;
}

variable_types:
inbuf
char *

variable_types:
out
char *

variable_types: start int

variable_types: i int

variable_types: j int


handleConnection

decompiled_code:
__int64 __fastcall handleConnection(int fd)
{
int v2; // ebx
__int64 result; // rax
bool v4; // cf
bool v5; // zf
const char *v6; // rdi
__int64 v7; // rcx
char *v8; // rsi
size_t v9; // rax
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
char *v14; // rsi
char v15; // al
bool v16; // cf
bool v17; // zf
char *v18; // rsi
const char *v19; // rdi
__int64 v20; // rcx
char *v21; // rbx
size_t v22; // rax
size_t v23; // rax
char v24[96]; // [rsp+0h] [rbp-1088h] BYREF
char s[4136]; // [rsp+60h] [rbp-1028h] BYREF

v2 = 0;
do
{
result = read(fd, &s[v2], 0xFFuLL);
v2 += result;
s[v2] = 0;
if ( (int)result <= 0 )
return result;
}
while ( s[v2 - 4] != 13 || s[v2 - 3] != 10 || s[v2 - 2] != 13 || s[v2 - 1] != 10 );
if ( !memcmp(s, &unk_60F, 3uLL) )
{
getFilename(s, v24, 4);
v12 = "/index.html";
v13 = 11LL;
v14 = v24;
do
{
if ( !v13 )
break;
v10 = (unsigned __int8)*v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
v15 = (!v10 && !v11) - v10;
v16 = 0;
v17 = v15 == 0;
if ( !v15 )
return emitNews((unsigned int)fd, v14);
v18 = v24;
v19 = "/config.html";
v20 = 12LL;
do
{
if ( !v20 )
break;
v16 = (unsigned __int8)*v18 < (unsigned int)*v19;
v17 = *v18++ == *v19++;
--v20;
}
while ( v17 );
if ( (!v16 && !v17) == v16 )
return emitConfig((unsigned int)fd, v18);
if ( !memcmp(v24, "/art", 3uLL) )
return emitArticle((unsigned int)fd, v24);
goto LABEL_26;
}
if ( !memcmp(s, "POST", 4uLL) )
{
getFilename(s, v24, 5);
v6 = "/clear";
v7 = 6LL;
v8 = v24;
do
{
if ( !v7 )
break;
v4 = (unsigned __int8)*v8 < (unsigned int)*v6;
v5 = *v8++ == *v6++;
--v7;
}
while ( v5 );
if ( (!v4 && !v5) == v4 )
{
clearEntries(v6, v8);
emitHTTPResponseHeader(fd);
strcpy(s, "

Click Back and Reload to refresh page.

\n\n");
v9 = strlen(s);
return write(fd, s, v9);
}
LABEL_26:
v21 = notfound;
v22 = strlen(notfound);
return write(fd, v21, v22);
}
strcpy(s, "HTTP/1.1 501 Not Implemented\n\n");
v23 = strlen(s);
return write(fd, s, v23);
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd)
{
int v2; // ebx
__int64 result; // rax
bool v4; // cf
bool v5; // zf
const char *v6; // rdi
__int64 v7; // rcx
char *v8; // rsi
size_t v9; // rax
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
char *v14; // rsi
char v15; // al
bool v16; // cf
bool v17; // zf
char *v18; // rsi
const char *v19; // rdi
__int64 v20; // rcx
char *v21; // rbx
size_t v22; // rax
size_t v23; // rax
char v24[96]; // [rsp+0h] [rbp-1088h] BYREF
char s[4136]; // [rsp+60h] [rbp-1028h] BYREF

v2 = 0;
do
{
result = read(fd, &s[v2], 0xFFuLL);
v2 += result;
s[v2] = 0;
if ( (int)result <= 0 )
return result;
}
while ( s[v2 - 4] != 13 || s[v2 - 3] != 10 || s[v2 - 2] != 13 || s[v2 - 1] != 10 );
if ( !memcmp(s, &unk_60F, 3uLL) )
{
func3(s, v24, 4);
v12 = "/index.html";
v13 = 11LL;
v14 = v24;
do
{
if ( !v13 )
break;
v10 = (unsigned __int8)*v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
v15 = (!v10 && !v11) - v10;
v16 = 0;
v17 = v15 == 0;
if ( !v15 )
return emitNews((unsigned int)fd, v14);
v18 = v24;
v19 = "/config.html";
v20 = 12LL;
do
{
if ( !v20 )
break;
v16 = (unsigned __int8)*v18 < (unsigned int)*v19;
v17 = *v18++ == *v19++;
--v20;
}
while ( v17 );
if ( (!v16 && !v17) == v16 )
return emitConfig((unsigned int)fd, v18);
if ( !memcmp(v24, "/art", 3uLL) )
return emitArticle((unsigned int)fd, v24);
goto LABEL_26;
}
if ( !memcmp(s, "POST", 4uLL) )
{
func3(s, v24, 5);
v6 = "/clear";
v7 = 6LL;
v8 = v24;
do
{
if ( !v7 )
break;
v4 = (unsigned __int8)*v8 < (unsigned int)*v6;
v5 = *v8++ == *v6++;
--v7;
}
while ( v5 );
if ( (!v4 && !v5) == v4 )
{
clearEntries(v6, v8);
func2(fd);
strcpy(s, "

Click Back and Reload to refresh page.

\n\n");
v9 = strlen(s);
return write(fd, s, v9);
}
LABEL_26:
v21 = notfound;
v22 = strlen(notfound);
return write(fd, v21, v22);
}
strcpy(s, "HTTP/1.1 501 Not Implemented\n\n");
v23 = strlen(s);
return write(fd, s, v23);
}

original_code:
void handleConnection( int connfd )
{
  int len, max, loop;
  char buffer[4096 +1];
  char filename[80+1];
  max = 0; loop = 1;
  while (loop) {
    len = read(connfd, &buffer[max], 255); buffer[max+len] = 0;
    if (len <= 0) return;
    max += len;
    if ((buffer[max-4] == 0x0d) && (buffer[max-3] == 0x0a) &&
        (buffer[max-2] == 0x0d) && (buffer[max-1] == 0x0a)) loop = 0;
  }
  if (!strncmp(buffer, "GET", 3)) {
    getFilename(buffer, filename, 4);
    if (!strncmp(filename, "/index.html", 11)) emitNews( connfd );
    else if (!strncmp(filename, "/config.html", 12)) emitConfig( connfd );
    else if (!strncmp(filename, "/art", 3)) emitArticle( connfd, filename );
    else write(connfd, notfound, strlen(notfound));
  } else if (!strncmp(buffer, "POST", 4)) {
    getFilename(buffer, filename, 5);
    if (!strncmp(filename, "/clear", 6)) {
      clearEntries();
      emitHTTPResponseHeader( connfd );
      strcpy(buffer, "

Click Back and Reload to "
                     "refresh page.

\n\n");
      write(connfd, buffer, strlen(buffer));
    } else {
      write(connfd, notfound, strlen(notfound));
    }
  } else {
    strcpy(buffer, "HTTP/1.1 501 Not Implemented\n\n");
    write(connfd, buffer, strlen(buffer));
  }
  return;
}

canonical_original_code:
void handleConnection(int connfd)
{
  int len; int max; int loop;
  char buffer[-1];
  char filename[-1];
  max = 0; loop = 1;
  while (loop) {
    len = read(connfd, &buffer[max], 255); buffer[max+len] = 0;
    if (len <= 0) return;
    max += len;
    if ((buffer[max-4] == 0x0d) && (buffer[max-3] == 0x0a) &&
        (buffer[max-2] == 0x0d) && (buffer[max-1] == 0x0a)) loop = 0;
  }
  if (!strncmp(buffer, "GET", 3)) {
    getFilename(buffer, filename, 4);
    if (!strncmp(filename, "/index.html", 11)) emitNews( connfd );
    else if (!strncmp(filename, "/config.html", 12)) emitConfig( connfd );
    else if (!strncmp(filename, "/art", 3)) emitArticle( connfd, filename );
    else write(connfd, notfound, strlen(notfound));
  } else if (!strncmp(buffer, "POST", 4)) {
    getFilename(buffer, filename, 5);
    if (!strncmp(filename, "/clear", 6)) {
      clearEntries();
      emitHTTPResponseHeader( connfd );
      strcpy(buffer, "

Click Back and Reload to "
                     "refresh page.

\n\n");
      write(connfd, buffer, strlen(buffer));
    } else {
      write(connfd, notfound, strlen(notfound));
    }
  } else {
    strcpy(buffer, "HTTP/1.1 501 Not Implemented\n\n");
    write(connfd, buffer, strlen(buffer));
  }
  return;
}

variable_types: len int

variable_types: max int

variable_types: loop int

variable_types:
buffer
char [-1]

variable_types:
filename
char [-1]


initHttpServer

decompiled_code:
__int64 initHttpServer()
{
int v0; // ebx
struct sockaddr v2; // [rsp+0h] [rbp-28h] BYREF
int optval[3]; // [rsp+1Ch] [rbp-Ch] BYREF

optval[0] = 1;
if ( listenfd != -1 )
close(listenfd);
v0 = socket(2, 1, 0);
listenfd = v0;
if ( setsockopt(v0, 1, 2, optval, 4u) < 0 )
return 0xFFFFFFFFLL;
*(_DWORD *)&v2.sa_data[10] = 0;
v2.sa_family = 2;
*(_QWORD *)&v2.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)v2.sa_data = _bswap_16(8080);
if ( bind(v0, &v2, 0x10u) < 0 )
return 0xFFFFFFFFLL;
listen(v0, 1);
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // ebx
struct sockaddr v2; // [rsp+0h] [rbp-28h] BYREF
int optval[3]; // [rsp+1Ch] [rbp-Ch] BYREF

optval[0] = 1;
if ( listenfd != -1 )
close(listenfd);
v0 = socket(2, 1, 0);
listenfd = v0;
if ( setsockopt(v0, 1, 2, optval, 4u) < 0 )
return 0xFFFFFFFFLL;
*(_DWORD *)&v2.sa_data[10] = 0;
v2.sa_family = 2;
*(_QWORD *)&v2.sa_data[2] = (unsigned int)func0(0);
*(_WORD *)v2.sa_data = func1(8080);
if ( bind(v0, &v2, 0x10u) < 0 )
return 0xFFFFFFFFLL;
listen(v0, 1);
return 0LL;
}

original_code:
int initHttpServer( void )
{
  int on=1, ret;
  struct sockaddr_in servaddr;
  if (listenfd != -1) close( listenfd );
  listenfd = socket( 2, SOCK_STREAM, 0 );
  ret = setsockopt( listenfd, 1, 2, &on, sizeof(on) );
  if (ret < 0) return -1;
  bzero( (void *)&servaddr, sizeof(servaddr) );
  servaddr.sin_family = 2;
  servaddr.sin_addr.s_addr = htonl( ((in_addr_t) 0x00000000) );
  servaddr.sin_port = htons( 8080 );
  ret = bind( listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr) );
  if (ret < 0) return -1;
  listen(listenfd, 1);
  return 0;
}

canonical_original_code:
int initHttpServer()
{
  int on = 1; int ret;
  struct sockaddr_in servaddr;
  if (listenfd != -1) close( listenfd );
  listenfd = socket( 2, SOCK_STREAM, 0 );
  ret = setsockopt( listenfd, 1, 2, &on, sizeof(on) );
  if (ret < 0) return -1;
  bzero( (void *)&servaddr, sizeof(servaddr) );
  servaddr.sin_family = 2;
  servaddr.sin_addr.s_addr = htonl( ((unsigned int) 0x00000000) );
  servaddr.sin_port = htons( 8080 );
  ret = bind( listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr) );
  if (ret < 0) return -1;
  listen(listenfd, 1);
  return 0;
}

variable_types: on int

variable_types: ret int

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


checkHttpServer

decompiled_code:
int checkHttpServer()
{
int v0; // edi
int result; // eax
int v2; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-B8h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-9Ch] BYREF
struct timeval timeout; // [rsp+20h] [rbp-98h] BYREF
fd_set readfds; // [rsp+30h] [rbp-88h] BYREF

memset(&readfds, 0, sizeof(readfds));
v0 = listenfd;
readfds.fds_bits[listenfd / 64] |= 1LL << (listenfd % 64);
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
result = select(v0 + 1, &readfds, 0LL, 0LL, &timeout);
if ( result <= 0 )
{
if ( result >= 0 )
return result;
return initHttpServer();
}
if ( (readfds.fds_bits[listenfd / 64] & (1LL << (listenfd % 64))) == 0 )
return initHttpServer();
addr_len = 16;
result = accept(listenfd, &v3, &addr_len);
v2 = result;
if ( result > 0 )
{
handleConnection(result);
result = close(v2);
}
return result;
}

canonical_decompiled_code:
int func6()
{
int v0; // edi
int result; // eax
int v2; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-B8h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-9Ch] BYREF
struct timeval timeout; // [rsp+20h] [rbp-98h] BYREF
fd_set readfds; // [rsp+30h] [rbp-88h] BYREF

memset(&readfds, 0, sizeof(readfds));
v0 = listenfd;
readfds.fds_bits[listenfd / 64] |= 1LL << (listenfd % 64);
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
result = select(v0 + 1, &readfds, 0LL, 0LL, &timeout);
if ( result <= 0 )
{
if ( result >= 0 )
return result;
return func5();
}
if ( (readfds.fds_bits[listenfd / 64] & (1LL << (listenfd % 64))) == 0 )
return func5();
addr_len = 16;
result = accept(listenfd, &v3, &addr_len);
v2 = result;
if ( result > 0 )
{
func4(result);
result = close(v2);
}
return result;
}

original_code:
void checkHttpServer( void )
{
  fd_set rfds;
  struct timeval tv;
  int ret = -1;
  int connfd;
  socklen_t clilen;
  struct sockaddr_in cliaddr;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rfds)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))));
  tv.tv_sec = 1;
  tv.tv_usec = 0;
  ret = select( listenfd+1, &rfds, ((void *)0), ((void *)0), &tv );
  if (ret > 0) {
    if (((((&rfds)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
      clilen = sizeof(cliaddr);
      connfd = accept( listenfd, (struct sockaddr *)&cliaddr, &clilen );
      if (connfd > 0) {
        handleConnection( connfd );
        close( connfd );
      }
    } else {
      initHttpServer();
    }
  } else if (ret < 0) {
      initHttpServer();
  } else {
  }
  return;
}

canonical_original_code:
void checkHttpServer()
{
  struct fd_set rfds;
  struct timeval tv;
  int ret = -1;
  int connfd;
  unsigned int clilen;
  struct sockaddr_in cliaddr;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rfds)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))));
  tv.tv_sec = 1;
  tv.tv_usec = 0;
  ret = select( listenfd+1, &rfds, ((void *)0), ((void *)0), &tv );
  if (ret > 0) {
    if (((((&rfds)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
      clilen = sizeof(cliaddr);
      connfd = accept( listenfd, (struct sockaddr *)&cliaddr, &clilen );
      if (connfd > 0) {
        handleConnection( connfd );
        close( connfd );
      }
    } else {
      initHttpServer();
    }
  } else if (ret < 0) {
      initHttpServer();
  } else {
  }
  return;
}

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

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

variable_types:
clilen
unsigned int


charge

decompiled_code:
double __fastcall charge(int a1)
{
double result; // xmm0_8

result = sin((double)a1 / 100.0);
if ( result < 0.0 )
result = 0.0;
return result;
}

canonical_decompiled_code:
double __fastcall func12(int a1)
{
double result; // xmm0_8

result = sin((double)a1 / 100.0);
if ( result < 0.0 )
result = 0.0;
return result;
}

original_code:
double charge( int t )
{
  double result;
  result = sin( (double)t/100.0 );
  if (result < 0.0) result = 0.0;
  return result;
}

canonical_original_code:
double charge(int t)
{
  double result;
  result = sin( (double)t/100.0 );
  if (result < 0.0) result = 0.0;
  return result;
}

variable_types: t int

variable_types: result double