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 )
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();
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

return_type: double


feedForward

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

for ( i = 0LL; i != 3; *(double *)&qword_4045D8[i] = sigmoid(v5) )
{
v1 = (double *)&inputs;
v2 = &wih[i];
v3 = 0.0;
do
{
v4 = *v1++ * *v2;
v2 += 3;
v3 = v3 + v4;
}
while ( v1 != who );
v5 = v3 + *(double *)&qword_404700[i++];
}
for ( j = 0LL;
j != 4;
*(double *)&qword_404598[j] = sigmoid(
*(double *)&qword_4045F0 * *(double *)&qword_404658[j]
+ v7 * *(double *)&hidden
+ 0.0
+ *(double *)&qword_404638[j] * *(double *)&qword_4045E8
+ *(double *)&qword_404678[j]) )
{
v7 = who[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

return_type: void


backPropagate

decompiled_code:
double *backPropagate()
{
__int64 i; // rax
double v1; // xmm0_8
double v2; // xmm2_8
double v3; // xmm0_8
__int64 v4; // rcx
__int64 v5; // rdx
__int64 v6; // rax
double v7; // xmm2_8
double v8; // xmm0_8
double v9; // xmm0_8
__int64 j; // rcx
double *v11; // rdx
__int64 *v12; // rax
double v13; // xmm1_8
double v14; // xmm0_8
double v15; // xmm1_8
__int64 k; // rcx
double *v17; // rdx
double *result; // rax
double v19; // xmm1_8
double v20; // xmm0_8
double v21; // xmm1_8

for ( i = 0LL; i != 32; *(double *)((char *)&qword_404578 + i) = v2 * v3 )
{
v1 = *(double *)((char *)&actual + i);
v2 = *(double *)((char *)&target + i) - v1;
v3 = sigmoidDerivative(v1);
}
qword_404560 = 0LL;
v4 = 0LL;
v5 = 0LL;
errh = 0LL;
do
{
v6 = 0LL;
v7 = 0.0;
do
{
v8 = *(double *)&erro[v6] * *(double *)((char *)who + v5 + v6 * 8);
++v6;
v7 = v7 + v8;
}
while ( v6 != 4 );
v9 = sigmoidDerivative(*(double *)((char *)&hidden + v4));
*(double *)((char *)&qword_404548 + v4) = v7 * v9;
}
while ( v5 != 96 );
for ( j = 0LL; j != 4; *(double *)&qword_404678[j] = v15 )
{
v11 = &who[j];
v12 = &hidden;
v13 = *(double *)&erro[j] * 0.2;
do
{
v14 = *(double *)v12++;
v11 += 4;
*(v11 - 4) = v14 * v13 + *(v11 - 4);
}
while ( &unk_4045F8 != (_UNKNOWN *)v12 );
v15 = v13 + *(double *)&qword_404680[j++];
}
for ( k = 0LL; k != 3; *(double *)&qword_4046F8[k] = v21 )
{
v17 = &wih[k];
result = (double *)&inputs;
v19 = *(double *)((char *)&errh + k * 8) * 0.2;
do
{
v20 = *result++;
v17 += 3;
*(v17 - 3) = v20 * v19 + *(v17 - 3);
}
while ( who != result );
v21 = v19 + *(double *)&qword_404700[k++];
}
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

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

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

v1 = *a1;
result = 0LL;
if ( a1[1] > *a1 )
{
v1 = a1[1];
result = 1LL;
}
if ( a1[2] > v1 )
{
v1 = a1[2];
result = 2LL;
}
if ( a1[3] > v1 )
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

return_type: int


emitHTTPResponseHeader

decompiled_code:
ssize_t __fastcall emitHTTPResponseHeader(int fd)
{
__m128i v2; // [rsp+0h] [rbp-58h] BYREF
char v3[16]; // [rsp+10h] [rbp-48h] BYREF

v3[0] = 0;
v2 = _mm_load_si128((const __m128i *)&LC0);
write(fd, &v2, 0x10uLL);
strcpy(v3, "\n");
v2 = _mm_load_si128((const __m128i *)&LC1);
write(fd, &v2, 0x11uLL);
strcpy(v3, "e\n");
v2 = _mm_load_si128((const __m128i *)&LC2);
write(fd, &v2, 0x12uLL);
strcpy(v3, "xt/html\n\n");
v2 = _mm_load_si128((const __m128i *)&LC3);
return write(fd, &v2, 0x19uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func2(int fd)
{
__m128i v2; // [rsp+0h] [rbp-58h] BYREF
char v3[16]; // [rsp+10h] [rbp-48h] BYREF

v3[0] = 0;
v2 = _mm_load_si128((const __m128i *)&LC0);
write(fd, &v2, 0x10uLL);
strcpy(v3, "\n");
v2 = _mm_load_si128((const __m128i *)&LC1);
write(fd, &v2, 0x11uLL);
strcpy(v3, "e\n");
v2 = _mm_load_si128((const __m128i *)&LC2);
write(fd, &v2, 0x12uLL);
strcpy(v3, "xt/html\n\n");
v2 = _mm_load_si128((const __m128i *)&LC3);
return write(fd, &v2, 0x19uLL);
}

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:
size_t __fastcall getFilename(char *s, char *a2, int a3)
{
unsigned __int64 v3; // rbx
__int64 v4; // rax
int v5; // edx
char *i; // r12
size_t result; // rax

v3 = a3;
if ( s[a3] == 32 )
{
v4 = a3 + 1;
do
v5 = v4++;
while ( s[v4 - 1] == 32 );
v3 = v5;
}
for ( i = a2; ; ++i )
{
result = strlen(s);
if ( result <= v3 )
break;
result = (unsigned __int8)s[v3++];
if ( (_BYTE)result == 32 )
{
*i = 0;
break;
}
*i = result;
}
if ( *a2 == 47 && !a2[1] )
{
result = 0x682E7865646E692FLL;
strcpy(a2, "/index.html");
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(char *s, char *a2, int a3)
{
unsigned __int64 v3; // rbx
__int64 v4; // rax
int v5; // edx
char *i; // r12
size_t result; // rax

v3 = a3;
if ( s[a3] == 32 )
{
v4 = a3 + 1;
do
v5 = v4++;
while ( s[v4 - 1] == 32 );
v3 = v5;
}
for ( i = a2; ; ++i )
{
result = strlen(s);
if ( result <= v3 )
break;
result = (unsigned __int8)s[v3++];
if ( (_BYTE)result == 32 )
{
*i = 0;
break;
}
*i = result;
}
if ( *a2 == 47 && !a2[1] )
{
result = 0x682E7865646E692FLL;
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)
{
__int64 v1; // rsi
int v2; // ebx
__int64 result; // rax
char *v4; // r12
size_t v5; // rax
__int64 v6; // [rsp+0h] [rbp-1088h] BYREF
int v7; // [rsp+8h] [rbp-1080h]
__m128i buf; // [rsp+60h] [rbp-1028h] BYREF
__int128 v9[2]; // [rsp+70h] [rbp-1018h] BYREF
__int64 v10; // [rsp+90h] [rbp-FF8h]

v1 = 0LL;
v2 = 0;
do
{
result = read(fd, &buf.m128i_i8[v1], 0xFFuLL);
v2 += result;
v1 = v2;
buf.m128i_i8[v2] = 0;
if ( (int)result <= 0 )
return result;
}
while ( buf.m128i_i8[v2 - 4] != 13
|| buf.m128i_i8[v2 - 3] != 10
|| buf.m128i_i8[v2 - 2] != 13
|| buf.m128i_i8[v2 - 1] != 10 );
if ( buf.m128i_i16[0] != 17735 || buf.m128i_i8[2] != 84 )
{
if ( buf.m128i_i32[0] != 1414745936 )
{
strcpy((char *)v9, " Implemented\n\n");
buf = _mm_load_si128((const __m128i *)&LC13);
return write(fd, &buf, 0x1EuLL);
}
getFilename(buf.m128i_i8, (char *)&v6, 5);
if ( (_DWORD)v6 == 1701602095 && WORD2(v6) == 29281 )
{
clearEntries();
emitHTTPResponseHeader(fd);
buf = _mm_load_si128((const __m128i *)&LC10);
v10 = 0xA0A3E503C3E31LL;
v9[0] = (__int128)_mm_load_si128((const __m128i *)&LC11);
v9[1] = (__int128)_mm_load_si128((const __m128i *)&LC12);
return write(fd, &buf, 0x37uLL);
}
goto LABEL_15;
}
getFilename(buf.m128i_i8, (char *)&v6, 4);
if ( v6 == 0x682E7865646E692FLL && (_WORD)v7 == 28020 && BYTE2(v7) == 108 )
return emitNews((unsigned int)fd);
if ( v6 == 0x2E6769666E6F632FLL && v7 == 1819112552 )
return emitConfig((unsigned int)fd);
if ( (_WORD)v6 != 24879 || BYTE2(v6) != 114 )
{
LABEL_15:
v4 = notfound;
v5 = strlen(notfound);
return write(fd, v4, v5);
}
return emitArticle((unsigned int)fd, &v6);
}

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()
{
unsigned int v0; // ebp
socklen_t v1; // edx
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr v4; // [rsp+10h] [rbp-18h] BYREF

optval = 1;
if ( listenfd != -1 )
close(listenfd);
listenfd = socket(2, 1, 0);
v0 = listenfd;
if ( setsockopt(listenfd, 1, 2, &optval, 4u) < 0 )
return 0xFFFFFFFFLL;
*(_QWORD *)&v4.sa_data[6] = 0LL;
v4.sa_family = 2;
*(_QWORD *)&v4.sa_data[2] = (unsigned int)_bswap_32_constprop_0(v0, &v4, 16LL);
*(_WORD *)v4.sa_data = _bswap_16_constprop_0();
if ( bind(v0, &v4, v1) < 0 )
return 0xFFFFFFFFLL;
listen(v0, 1);
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // ebp
socklen_t v1; // edx
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr v4; // [rsp+10h] [rbp-18h] BYREF

optval = 1;
if ( listenfd != -1 )
close(listenfd);
listenfd = socket(2, 1, 0);
v0 = listenfd;
if ( setsockopt(listenfd, 1, 2, &optval, 4u) < 0 )
return 0xFFFFFFFFLL;
*(_QWORD *)&v4.sa_data[6] = 0LL;
v4.sa_family = 2;
*(_QWORD *)&v4.sa_data[2] = (unsigned int)func0(v0, &v4, 16LL);
*(_WORD *)v4.sa_data = func1();
if ( bind(v0, &v4, v1) < 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]; }

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]; }


checkHttpServer

decompiled_code:
int checkHttpServer()
{
int v0; // edi
int result; // eax
int v2; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-BCh] BYREF
struct timeval timeout; // [rsp+10h] [rbp-B8h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
v0 = listenfd;
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
readfds.fds_bits[listenfd / 64] |= 1LL << (listenfd % 64);
result = select(v0 + 1, &readfds, 0LL, 0LL, &timeout);
if ( result <= 0 )
{
if ( !result )
return result;
return initHttpServer();
}
if ( (readfds.fds_bits[listenfd / 64] & (1LL << (listenfd % 64))) == 0 )
return initHttpServer();
addr_len = 16;
result = accept(listenfd, &addr, &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; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-BCh] BYREF
struct timeval timeout; // [rsp+10h] [rbp-B8h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
v0 = listenfd;
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
readfds.fds_bits[listenfd / 64] |= 1LL << (listenfd % 64);
result = select(v0 + 1, &readfds, 0LL, 0LL, &timeout);
if ( result <= 0 )
{
if ( !result )
return result;
return func5();
}
if ( (readfds.fds_bits[listenfd / 64] & (1LL << (listenfd % 64))) == 0 )
return func5();
addr_len = 16;
result = accept(listenfd, &addr, &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)
{
return fmax(0.0, sin((double)a1 / 100.0));
}

canonical_decompiled_code:
double __fastcall func18(int a1)
{
return fmax(0.0, sin((double)a1 / 100.0));
}

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


simulate

decompiled_code:
__int64 simulate()
{
float v0; // xmm0_4
int v1; // eax
int v2; // ebx
int v3; // ebp
double v4; // xmm0_8
float v5; // xmm6_4
float v6; // xmm4_4
double v7; // xmm2_8
double v8; // xmm5_8
double v9; // xmm1_8
float v10; // xmm2_4
double v11; // xmm4_8
float v12; // xmm0_4
double v13; // xmm5_8
double v14; // xmm0_8
double v15; // xmm5_8
float v16; // xmm0_4
__int64 result; // rax
double v18; // xmm0_8
double v19; // xmm0_8
double v20; // xmm0_8
double v21; // xmm3_8
double v22; // xmm5_8
double v23; // xmm0_8
double v24; // xmm0_8
double v25; // xmm0_8
double v26; // xmm0_8
double v27; // xmm0_8
int v28; // [rsp+8h] [rbp-30h]
float v29; // [rsp+8h] [rbp-30h]
double v30; // [rsp+8h] [rbp-30h]
float v31; // [rsp+8h] [rbp-30h]
double v32; // [rsp+8h] [rbp-30h]
double v33; // [rsp+8h] [rbp-30h]
double v34; // [rsp+8h] [rbp-30h]
double v35; // [rsp+8h] [rbp-30h]
float v36; // [rsp+10h] [rbp-28h]
double v37; // [rsp+10h] [rbp-28h]
double v38; // [rsp+10h] [rbp-28h]

v0 = (float)rand() * 4.6566129e-10;
v1 = curLoad;
if ( v0 < 0.02 )
{
v1 = (int)((float)((float)rand() * 5.0) * 4.656612873077393e-10);
curLoad = v1;
}
v2 = t_0;
v3 = chargeMode;
v36 = load[v1];
*(float *)&voltage = *(float *)&voltage - v36;
v28 = voltage;
v4 = charge(t_0);
v5 = *(float *)&v28;
v6 = v36;
v7 = v4;
v8 = *(float *)&timer;
if ( v3 == 1 )
{
if ( v8 < 0.0 )
{
v38 = v4;
v31 = v6;
v26 = sqrt(v8);
v5 = *(float *)&voltage;
v3 = chargeMode;
v7 = v38;
v21 = v26;
v8 = *(float *)&timer;
v6 = v31;
}
else
{
v21 = sqrt(v8);
}
v10 = v5 + v21 * v7;
voltage = LODWORD(v10);
}
else
{
if ( v8 < 0.0 )
{
v37 = v4;
v29 = v6;
v24 = sqrt(v8);
v5 = *(float *)&voltage;
v3 = chargeMode;
v7 = v37;
v9 = v24;
v8 = *(float *)&timer;
v6 = v29;
}
else
{
v9 = sqrt(v8);
}
v10 = v7 * v9 / 10.0 + v5;
voltage = LODWORD(v10);
}
v11 = v6;
if ( v10 < 0.0 )
{
voltage = 0;
if ( v3 == 1 )
goto LABEL_27;
LABEL_10:
v12 = *(float *)&temperature;
if ( *(float *)&temperature <= 20.0 )
{
if ( v8 < 0.0 )
{
v32 = v11;
v27 = sqrt(v8);
v11 = v32;
v22 = v27;
v12 = *(float *)&temperature;
}
else
{
v22 = sqrt(v8);
}
v14 = v12;
v15 = v22 / 100.0;
}
else
{
if ( v8 < 0.0 )
{
v30 = v11;
v25 = sqrt(v8);
v11 = v30;
v13 = v25;
v12 = *(float *)&temperature;
}
else
{
v13 = sqrt(v8);
}
v14 = v12;
v15 = v13 / 20.0;
}
v16 = v14 - 10.0 * (v11 * v15);
temperature = LODWORD(v16);
if ( v16 >= 0.0 )
goto LABEL_15;
LABEL_25:
temperature = 0;
goto LABEL_17;
}
if ( v10 > 35.0 )
{
voltage = 1108082688;
if ( v3 != 1 )
goto LABEL_10;
goto LABEL_36;
}
if ( v3 != 1 )
goto LABEL_10;
if ( v10 > 25.0 )
{
LABEL_36:
if ( v8 < 0.0 )
{
v34 = v11;
v23 = sqrt(v8);
v11 = v34;
}
else
{
v23 = sqrt(v8);
}
v19 = v23 / 25.0;
goto LABEL_24;
}
if ( v10 > 15.0 )
{
if ( v8 < 0.0 )
{
v33 = v11;
v18 = sqrt(v8);
v11 = v33;
}
else
{
v18 = sqrt(v8);
}
v19 = v18 / 20.0;
goto LABEL_24;
}
LABEL_27:
if ( v8 < 0.0 )
{
v35 = v11;
v20 = sqrt(v8);
v11 = v35;
}
else
{
v20 = sqrt(v8);
}
v19 = v20 / 15.0;
LABEL_24:
v16 = v19 * v11 * 10.0 + *(float *)&temperature;
temperature = LODWORD(v16);
if ( v16 < 0.0 )
goto LABEL_25;
LABEL_15:
if ( v16 > 40.0 )
temperature = 1109393408;
LABEL_17:
result = 0LL;
t_0 = v2 + 1;
return result;
}

canonical_decompiled_code:
__int64 func19()
{
float v0; // xmm0_4
int v1; // eax
int v2; // ebx
int v3; // ebp
double v4; // xmm0_8
float v5; // xmm6_4
float v6; // xmm4_4
double v7; // xmm2_8
double v8; // xmm5_8
double v9; // xmm1_8
float v10; // xmm2_4
double v11; // xmm4_8
float v12; // xmm0_4
double v13; // xmm5_8
double v14; // xmm0_8
double v15; // xmm5_8
float v16; // xmm0_4
__int64 result; // rax
double v18; // xmm0_8
double v19; // xmm0_8
double v20; // xmm0_8
double v21; // xmm3_8
double v22; // xmm5_8
double v23; // xmm0_8
double v24; // xmm0_8
double v25; // xmm0_8
double v26; // xmm0_8
double v27; // xmm0_8
int v28; // [rsp+8h] [rbp-30h]
float v29; // [rsp+8h] [rbp-30h]
double v30; // [rsp+8h] [rbp-30h]
float v31; // [rsp+8h] [rbp-30h]
double v32; // [rsp+8h] [rbp-30h]
double v33; // [rsp+8h] [rbp-30h]
double v34; // [rsp+8h] [rbp-30h]
double v35; // [rsp+8h] [rbp-30h]
float v36; // [rsp+10h] [rbp-28h]
double v37; // [rsp+10h] [rbp-28h]
double v38; // [rsp+10h] [rbp-28h]

v0 = (float)rand() * 4.6566129e-10;
v1 = curLoad;
if ( v0 < 0.02 )
{
v1 = (int)((float)((float)rand() * 5.0) * 4.656612873077393e-10);
curLoad = v1;
}
v2 = t_0;
v3 = chargeMode;
v36 = load[v1];
*(float *)&voltage = *(float *)&voltage - v36;
v28 = voltage;
v4 = func18(t_0);
v5 = *(float *)&v28;
v6 = v36;
v7 = v4;
v8 = *(float *)&timer;
if ( v3 == 1 )
{
if ( v8 < 0.0 )
{
v38 = v4;
v31 = v6;
v26 = sqrt(v8);
v5 = *(float *)&voltage;
v3 = chargeMode;
v7 = v38;
v21 = v26;
v8 = *(float *)&timer;
v6 = v31;
}
else
{
v21 = sqrt(v8);
}
v10 = v5 + v21 * v7;
voltage = LODWORD(v10);
}
else
{
if ( v8 < 0.0 )
{
v37 = v4;
v29 = v6;
v24 = sqrt(v8);
v5 = *(float *)&voltage;
v3 = chargeMode;
v7 = v37;
v9 = v24;
v8 = *(float *)&timer;
v6 = v29;
}
else
{
v9 = sqrt(v8);
}
v10 = v7 * v9 / 10.0 + v5;
voltage = LODWORD(v10);
}
v11 = v6;
if ( v10 < 0.0 )
{
voltage = 0;
if ( v3 == 1 )
goto LABEL_27;
LABEL_10:
v12 = *(float *)&temperature;
if ( *(float *)&temperature <= 20.0 )
{
if ( v8 < 0.0 )
{
v32 = v11;
v27 = sqrt(v8);
v11 = v32;
v22 = v27;
v12 = *(float *)&temperature;
}
else
{
v22 = sqrt(v8);
}
v14 = v12;
v15 = v22 / 100.0;
}
else
{
if ( v8 < 0.0 )
{
v30 = v11;
v25 = sqrt(v8);
v11 = v30;
v13 = v25;
v12 = *(float *)&temperature;
}
else
{
v13 = sqrt(v8);
}
v14 = v12;
v15 = v13 / 20.0;
}
v16 = v14 - 10.0 * (v11 * v15);
temperature = LODWORD(v16);
if ( v16 >= 0.0 )
goto LABEL_15;
LABEL_25:
temperature = 0;
goto LABEL_17;
}
if ( v10 > 35.0 )
{
voltage = 1108082688;
if ( v3 != 1 )
goto LABEL_10;
goto LABEL_36;
}
if ( v3 != 1 )
goto LABEL_10;
if ( v10 > 25.0 )
{
LABEL_36:
if ( v8 < 0.0 )
{
v34 = v11;
v23 = sqrt(v8);
v11 = v34;
}
else
{
v23 = sqrt(v8);
}
v19 = v23 / 25.0;
goto LABEL_24;
}
if ( v10 > 15.0 )
{
if ( v8 < 0.0 )
{
v33 = v11;
v18 = sqrt(v8);
v11 = v33;
}
else
{
v18 = sqrt(v8);
}
v19 = v18 / 20.0;
goto LABEL_24;
}
LABEL_27:
if ( v8 < 0.0 )
{
v35 = v11;
v20 = sqrt(v8);
v11 = v35;
}
else
{
v20 = sqrt(v8);
}
v19 = v20 / 15.0;
LABEL_24:
v16 = v19 * v11 * 10.0 + *(float *)&temperature;
temperature = LODWORD(v16);
if ( v16 < 0.0 )
goto LABEL_25;
LABEL_15:
if ( v16 > 40.0 )
temperature = 1109393408;
LABEL_17:
result = 0LL;
t_0 = v2 + 1;
return result;
}

original_code:
int simulate( void )
{
  extern int chargeMode;
  static int t=0;
  if (((float)rand() / (float)2147483647) < 0.02) {
    curLoad = (int)((float)(5)*rand()/(2147483647 +1.0));
  }
  voltage -= load[curLoad];
  if (chargeMode == 1) {
    voltage += (charge(t) * sqrt(timer));
  } else {
    voltage += ((charge(t) * sqrt(timer)) / 10.0 );
  }
  if (voltage < 0.0) voltage = 0.0;
  else if (voltage > 35.0) voltage = 35.0;
  if (chargeMode == 1) {
    if (voltage > 25) {
      temperature += ((load[curLoad] * (sqrt(timer)/25.0)) * 10.0);
    } else if (voltage > 15) {
      temperature += ((load[curLoad] * (sqrt(timer)/20.0)) * 10.0);
    } else {
      temperature += ((load[curLoad] * (sqrt(timer)/15.0)) * 10.0);
    }
  } else {
    if (temperature > 20.0) {
      temperature -= ((load[curLoad] * (sqrt(timer)/20.0)) * 10.0);
    } else {
      temperature -= ((load[curLoad] * (sqrt(timer)/100.0)) * 10.0);
    }
  }
  if (temperature < 0.0) temperature = 0.0;
  else if (temperature > 40.0) temperature = 40.0;
  t++;
  return 0;
}

canonical_original_code:
int simulate()
{
  extern int chargeMode;
  static int t = 0;
  if (((float)rand() / (float)2147483647) < 0.02) {
    curLoad = (int)((float)(5)*rand()/(2147483647 +1.0));
  }
  voltage -= load[curLoad];
  if (chargeMode == 1) {
    voltage += (charge(t) * sqrt(timer));
  } else {
    voltage += ((charge(t) * sqrt(timer)) / 10.0 );
  }
  if (voltage < 0.0) voltage = 0.0;
  else if (voltage > 35.0) voltage = 35.0;
  if (chargeMode == 1) {
    if (voltage > 25) {
      temperature += ((load[curLoad] * (sqrt(timer)/25.0)) * 10.0);
    } else if (voltage > 15) {
      temperature += ((load[curLoad] * (sqrt(timer)/20.0)) * 10.0);
    } else {
      temperature += ((load[curLoad] * (sqrt(timer)/15.0)) * 10.0);
    }
  } else {
    if (temperature > 20.0) {
      temperature -= ((load[curLoad] * (sqrt(timer)/20.0)) * 10.0);
    } else {
      temperature -= ((load[curLoad] * (sqrt(timer)/100.0)) * 10.0);
    }
  }
  if (temperature < 0.0) temperature = 0.0;
  else if (temperature > 40.0) temperature = 40.0;
  t++;
  return 0;
}

variable_types: chargeMode int


emitNews

original_code:
void emitNews( int connfd )
{
  int i;
  char line[300 +1];
  elementType *walker;
  extern monitorEntryType monitors[];
  extern feedEntryType feed;
  extern elementType head;
  emitHTTPResponseHeader( connfd );
  write( connfd, prologue, strlen(prologue));
  strcpy(line,
          "
Web Agent Results

");
  write( connfd, line, strlen(line));
  strcpy(line, "

\n");
  write( connfd, line, strlen(line));
  for (i = 0 ; i < 20 ; i++) {
    if ((monitors[i].active) && (monitors[i].changed)) {
      sprintf(line, "
%s	\n"
                    "%s"
                    "
\n",
               monitors[i].urlName, monitors[i].url, monitors[i].url);
      write( connfd, line, strlen(line));
      monitors[i].shown = 1;
    }
  }
  strcpy(line, "

\n");
  write( connfd, line, strlen(line));
  walker = head.next;
  if (walker) {
    strcpy(line, "

\n");
    write( connfd, line, strlen(line));
    while (walker) {
      sprintf(line, "
%s	\n"
                    "%s	"
                    "%s
",
                    feed.groups[walker->group].groupName,
                    walker->link,
                    walker->subject,
                    walker->msgDate );
      write( connfd, line, strlen(line));
      walker->shown = 1;
      walker = walker->next;
    }
    strcpy(line, "

\n");
    write( connfd, line, strlen(line));
  }
  strcpy(line, "<FORM METHOD=\"POST\" ACTION=/clear\">");
  write( connfd, line, strlen(line));
  strcpy(line, "

<INPUT TYPE=\"submit\" VALUE=\"Mark Read\">
\n");
  write( connfd, line, strlen(line));
  write( connfd, epilogue, strlen(epilogue));
  return;
}

canonical_original_code:
void emitNews(int connfd)
{
  int i;
  char line[-1];
  struct elementStruct *walker;
  extern struct monitorEntryType monitors[];
  extern struct feedEntryType feed;
  extern struct elementStruct head;
  emitHTTPResponseHeader( connfd );
  write( connfd, prologue, strlen(prologue));
  strcpy(line,
          "
Web Agent Results

");
  write( connfd, line, strlen(line));
  strcpy(line, "

\n");
  write( connfd, line, strlen(line));
  for (i = 0 ; i < 20 ; i++) {
    if ((monitors[i].active) && (monitors[i].changed)) {
      sprintf(line, "
%s	\n"
                    "%s"
                    "
\n",
               monitors[i].urlName, monitors[i].url, monitors[i].url);
      write( connfd, line, strlen(line));
      monitors[i].shown = 1;
    }
  }
  strcpy(line, "

\n");
  write( connfd, line, strlen(line));
  walker = head.next;
  if (walker) {
    strcpy(line, "

\n");
    write( connfd, line, strlen(line));
    while (walker) {
      sprintf(line, "
%s	\n"
                    "%s	"
                    "%s
",
                    feed.groups[walker->group].groupName,
                    walker->link,
                    walker->subject,
                    walker->msgDate );
      write( connfd, line, strlen(line));
      walker->shown = 1;
      walker = walker->next;
    }
    strcpy(line, "

\n");
    write( connfd, line, strlen(line));
  }
  strcpy(line, "<FORM METHOD=\"POST\" ACTION=/clear\">");
  write( connfd, line, strlen(line));
  strcpy(line, "

<INPUT TYPE=\"submit\" VALUE=\"Mark Read\">
\n");
  write( connfd, line, strlen(line));
  write( connfd, epilogue, strlen(epilogue));
  return;
}

variable_types: connfd int

variable_types:
line
char [-1]

variable_types: struct elementStruct { int group; int rank; int msgId; char subject[-1]; char msgDate[-1]; char link[-1]; int shown; struct elementStruct *next; } *

variable_types: struct monitorEntryType { int active; char url[80]; char urlName[-1]; int length; int changed; int shown; } []

variable_types: struct feedEntryType { char url[80]; struct groupEntryType { int active; char groupName[-1]; int lastMessageRead; char searchString[10][-1]; int numSearchStrings; } groups[20]; }

user_defined_types: struct feedEntryType { char url[80]; struct groupEntryType groups[20]; }


emitConfig

decompiled_code:
ssize_t __fastcall emitConfig(int fd)
{
unsigned __int64 v1; // rbx
char *v2; // r12
size_t v3; // rax
const char *v4; // rcx
const char *v5; // rdx
size_t v6; // rax
char *v7; // r13
size_t v8; // rax
size_t v9; // rax
int v10; // eax
const char *v11; // rbx
__int64 v12; // r12
size_t v13; // rax
const char *v14; // rsi
char *v15; // rax
size_t v16; // rax
char *v17; // r12
size_t v18; // rax
char dest[16]; // [rsp+0h] [rbp-158h] BYREF
__m128i v21; // [rsp+10h] [rbp-148h]
__int128 v22[19]; // [rsp+20h] [rbp-138h] BYREF

v1 = (unsigned int)((_DWORD)&monitors + 84);
emitHTTPResponseHeader();
v2 = prologue;
v3 = strlen(prologue);
write(fd, v2, v3);
strcpy((char *)v22, "ont>

");
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC18);
v21 = _mm_load_si128((const __m128i *)&LC19);
write(fd, dest, 0x2CuLL);
strcpy((char *)v22, "font>

");
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC20);
v21 = _mm_load_si128((const __m128i *)&LC21);
write(fd, dest, 0x2DuLL);
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC5);
v21 = _mm_load_si128((const __m128i *)&LC6);
v22[0] = (__int128)_mm_load_si128((const __m128i *)&LC7);
write(fd, dest, 0x2FuLL);
do
{
while ( !*(_DWORD *)(v1 - 84) )
{
v1 += 140LL;
if ( (_UNKNOWN *)v1 == (_UNKNOWN *)((char *)&monitors + 2884) )
goto LABEL_5;
}
v4 = (const char *)(v1 - 80);
v5 = (const char *)v1;
v1 += 140LL;
sprintf(dest, "
%s	%s
\n", v5, v4);
v6 = strlen(dest);
write(fd, dest, v6);
}
while ( (_UNKNOWN *)v1 != (_UNKNOWN *)((char *)&monitors + 2884) );
LABEL_5:
v7 = feed;
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC8);
v21 = _mm_load_si128((const __m128i *)&LC9);
write(fd, dest, 0x1FuLL);
sprintf(dest, "
Feed %s

\n", feed);
v8 = strlen(dest);
write(fd, dest, v8);
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC5);
v21 = _mm_load_si128((const __m128i *)&LC6);
v22[0] = (__int128)_mm_load_si128((const __m128i *)&LC7);
write(fd, dest, 0x2FuLL);
do
{
while ( !*((_DWORD *)v7 + 20) )
{
v7 += 508;
if ( v7 == &feed[10160] )
goto LABEL_13;
}
sprintf(dest, "
Group %s	\n", v7 + 84);
v9 = strlen(dest);
write(fd, dest, v9);
v10 = *((_DWORD *)v7 + 146);
v21.m128i_i32[0] = 4075819;
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC22);
if ( v10 <= 0 )
{
*(__int32 *)((char *)v21.m128i_i32 + 3) = 6105691;
}
else
{
v11 = v7 + 172;
v12 = (__int64)&v7[41 * (v10 - 1) + 213];
while ( 1 )
{
v13 = strlen(dest);
v14 = v11;
v11 += 41;
v15 = stpcpy(&dest[v13], v14);
if ( v11 == (const char *)v12 )
break;
strcpy(v15, ", ");
}
}
v7 += 508;
v16 = strlen(dest);
strcpy(&dest[v16 + 16], ">\n");
*(__m128i *)&dest[v16] = _mm_load_si128((const __m128i *)&LC23);
write(fd, dest, v16 + 18);
}
while ( v7 != &feed[10160] );
LABEL_13:
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC8);
v21 = _mm_load_si128((const __m128i *)&LC9);
write(fd, dest, 0x1FuLL);
v17 = epilogue;
v18 = strlen(epilogue);
return write(fd, v17, v18);
}

canonical_decompiled_code:
ssize_t __fastcall func1(int fd)
{
unsigned __int64 v1; // rbx
char *v2; // r12
size_t v3; // rax
const char *v4; // rcx
const char *v5; // rdx
size_t v6; // rax
char *v7; // r13
size_t v8; // rax
size_t v9; // rax
int v10; // eax
const char *v11; // rbx
__int64 v12; // r12
size_t v13; // rax
const char *v14; // rsi
char *v15; // rax
size_t v16; // rax
char *v17; // r12
size_t v18; // rax
char dest[16]; // [rsp+0h] [rbp-158h] BYREF
__m128i v21; // [rsp+10h] [rbp-148h]
__int128 v22[19]; // [rsp+20h] [rbp-138h] BYREF

v1 = (unsigned int)((_DWORD)&monitors + 84);
emitHTTPResponseHeader();
v2 = prologue;
v3 = strlen(prologue);
write(fd, v2, v3);
strcpy((char *)v22, "ont>

");
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC18);
v21 = _mm_load_si128((const __m128i *)&LC19);
write(fd, dest, 0x2CuLL);
strcpy((char *)v22, "font>

");
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC20);
v21 = _mm_load_si128((const __m128i *)&LC21);
write(fd, dest, 0x2DuLL);
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC5);
v21 = _mm_load_si128((const __m128i *)&LC6);
v22[0] = (__int128)_mm_load_si128((const __m128i *)&LC7);
write(fd, dest, 0x2FuLL);
do
{
while ( !*(_DWORD *)(v1 - 84) )
{
v1 += 140LL;
if ( (_UNKNOWN *)v1 == (_UNKNOWN *)((char *)&monitors + 2884) )
goto LABEL_5;
}
v4 = (const char *)(v1 - 80);
v5 = (const char *)v1;
v1 += 140LL;
sprintf(dest, "
%s	%s
\n", v5, v4);
v6 = strlen(dest);
write(fd, dest, v6);
}
while ( (_UNKNOWN *)v1 != (_UNKNOWN *)((char *)&monitors + 2884) );
LABEL_5:
v7 = feed;
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC8);
v21 = _mm_load_si128((const __m128i *)&LC9);
write(fd, dest, 0x1FuLL);
sprintf(dest, "
Feed %s

\n", feed);
v8 = strlen(dest);
write(fd, dest, v8);
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC5);
v21 = _mm_load_si128((const __m128i *)&LC6);
v22[0] = (__int128)_mm_load_si128((const __m128i *)&LC7);
write(fd, dest, 0x2FuLL);
do
{
while ( !*((_DWORD *)v7 + 20) )
{
v7 += 508;
if ( v7 == &feed[10160] )
goto LABEL_13;
}
sprintf(dest, "
Group %s	\n", v7 + 84);
v9 = strlen(dest);
write(fd, dest, v9);
v10 = *((_DWORD *)v7 + 146);
v21.m128i_i32[0] = 4075819;
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC22);
if ( v10 <= 0 )
{
*(__int32 *)((char *)v21.m128i_i32 + 3) = 6105691;
}
else
{
v11 = v7 + 172;
v12 = (__int64)&v7[41 * (v10 - 1) + 213];
while ( 1 )
{
v13 = strlen(dest);
v14 = v11;
v11 += 41;
v15 = stpcpy(&dest[v13], v14);
if ( v11 == (const char *)v12 )
break;
strcpy(v15, ", ");
}
}
v7 += 508;
v16 = strlen(dest);
strcpy(&dest[v16 + 16], ">\n");
*(__m128i *)&dest[v16] = _mm_load_si128((const __m128i *)&LC23);
write(fd, dest, v16 + 18);
}
while ( v7 != &feed[10160] );
LABEL_13:
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC8);
v21 = _mm_load_si128((const __m128i *)&LC9);
write(fd, dest, 0x1FuLL);
v17 = epilogue;
v18 = strlen(epilogue);
return write(fd, v17, v18);
}

original_code:
void emitConfig( int connfd )
{
  char line[300 +1];
  int i, j;
  extern monitorEntryType monitors[];
  extern feedEntryType feed;
  emitHTTPResponseHeader( connfd );
  write( connfd, prologue, strlen(prologue));
  strcpy(line, "
Configuration

");
  write( connfd, line, strlen(line));
  strcpy(line, "Sites to Monitor

");
  write( connfd, line, strlen(line));
  strcpy(line, "

\n");
  write( connfd, line, strlen(line));
  for (i = 0 ; i < 20 ; i++) {
    if (monitors[i].active) {
      sprintf(line, "
%s	"
                    "%s
\n",
               monitors[i].urlName, monitors[i].url);
      write( connfd, line, strlen(line));
    }
  }
  strcpy(line, "

\n");
  write( connfd, line, strlen(line));
  sprintf(line,
    "
Feed %s

\n", feed.url);
  write( connfd, line, strlen(line));
  strcpy(line, "

\n");
  write( connfd, line, strlen(line));
  for (i = 0 ; i < 20 ; i++) {
    if (feed.groups[i].active) {
      sprintf(line, "
Group %s	\n",
               feed.groups[i].groupName);
      write( connfd, line, strlen(line));
      strcpy(line, "\n");
      if (feed.groups[i].numSearchStrings > 0) {
        for (j = 0 ; j < feed.groups[i].numSearchStrings ; j++) {
          if (j > 0) strcat(line, ", ");
          strcat(line, feed.groups[i].searchString[j]);
        }
      } else {
        strcat(line, "[*]");
      }
      strcat(line, "
\n");
      write( connfd, line, strlen(line) );
    }
  }
  strcpy(line, "

\n");
  write( connfd, line, strlen(line));
  write( connfd, epilogue, strlen(epilogue));
  return;
}

canonical_original_code:
void emitConfig(int connfd)
{
  char line[-1];
  int i; int j;
  extern struct monitorEntryType monitors[];
  extern struct feedEntryType feed;
  emitHTTPResponseHeader( connfd );
  write( connfd, prologue, strlen(prologue));
  strcpy(line, "
Configuration

");
  write( connfd, line, strlen(line));
  strcpy(line, "Sites to Monitor

");
  write( connfd, line, strlen(line));
  strcpy(line, "

\n");
  write( connfd, line, strlen(line));
  for (i = 0 ; i < 20 ; i++) {
    if (monitors[i].active) {
      sprintf(line, "
%s	"
                    "%s
\n",
               monitors[i].urlName, monitors[i].url);
      write( connfd, line, strlen(line));
    }
  }
  strcpy(line, "

\n");
  write( connfd, line, strlen(line));
  sprintf(line,
    "
Feed %s

\n", feed.url);
  write( connfd, line, strlen(line));
  strcpy(line, "

\n");
  write( connfd, line, strlen(line));
  for (i = 0 ; i < 20 ; i++) {
    if (feed.groups[i].active) {
      sprintf(line, "
Group %s	\n",
               feed.groups[i].groupName);
      write( connfd, line, strlen(line));
      strcpy(line, "\n");
      if (feed.groups[i].numSearchStrings > 0) {
        for (j = 0 ; j < feed.groups[i].numSearchStrings ; j++) {
          if (j > 0) strcat(line, ", ");
          strcat(line, feed.groups[i].searchString[j]);
        }
      } else {
        strcat(line, "[*]");
      }
      strcat(line, "
\n");
      write( connfd, line, strlen(line) );
    }
  }
  strcpy(line, "

\n");
  write( connfd, line, strlen(line));
  write( connfd, epilogue, strlen(epilogue));
  return;
}

variable_types: i int

variable_types: j int

user_defined_types: struct monitorEntryType { int active; char url[80]; char urlName[-1]; int length; int changed; int shown; }

user_defined_types: struct groupEntryType { int active; char groupName[-1]; int lastMessageRead; char searchString[10][-1]; int numSearchStrings; }


emitArticle

decompiled_code:
__int64 __fastcall emitArticle(int fd, __int64 a2)
{
char *v2; // r13
size_t v3; // rax
void *v4; // rax
char *v5; // r12
size_t v6; // rax
size_t v8; // rax
size_t v9; // rax
size_t v10; // rax
size_t v11; // rax
char *v12; // r12
size_t v13; // rax
size_t v14; // rax
int v15; // [rsp+8h] [rbp-2A0h] BYREF
int v16; // [rsp+Ch] [rbp-29Ch] BYREF
char s[16]; // [rsp+10h] [rbp-298h] BYREF
__m128i v18; // [rsp+20h] [rbp-288h]
char v19[8]; // [rsp+30h] [rbp-278h] BYREF
void *ptr; // [rsp+140h] [rbp-168h] BYREF
int v21; // [rsp+148h] [rbp-160h]
char v22[101]; // [rsp+150h] [rbp-158h] BYREF
char v23[101]; // [rsp+1B5h] [rbp-F3h] BYREF
char v24[102]; // [rsp+21Ah] [rbp-8Eh] BYREF
char *v25; // [rsp+280h] [rbp-28h]

emitHTTPResponseHeader();
v2 = prologue;
v3 = strlen(prologue);
write(fd, v2, v3);
_isoc99_sscanf(a2, "/art%d_%d", &v15, &v16);
v4 = calloc(0x10001uLL, 1uLL);
v21 = 0x10000;
ptr = v4;
prune(feed, s);
if ( !(unsigned int)nntpConnect(s)
&& (int)nntpSetGroup(&feed[508 * v15 + 84], (unsigned int)(v16 - 1)) > 0
&& (int)nntpRetrieve(&ptr, 0x10000LL) > 0 )
{
if ( (unsigned int)nntpParse(&ptr, 0LL) )
{
puts("Parse error");
}
else
{
sprintf(s, "Subject : %s\n

", v22);
v8 = strlen(s);
write(fd, s, v8);
sprintf(s, "Sender : %s\n

", v23);
v9 = strlen(s);
write(fd, s, v9);
sprintf(s, "Group : %s\n

", &feed[508 * v15 + 84]);
v10 = strlen(s);
write(fd, s, v10);
sprintf(s, "Msg Date : %s\n

", v24);
v11 = strlen(s);
write(fd, s, v11);
v12 = v25;
v13 = strlen(v25);
write(fd, v12, v13);
strcpy(v19, ">
");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC30);
v18 = _mm_load_si128((const __m128i *)&LC31);
v14 = strlen(s);
write(fd, s, v14);
}
}
v5 = epilogue;
v6 = strlen(epilogue);
write(fd, v5, v6);
free(ptr);
return nntpDisconnect();
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, __int64 a2)
{
char *v2; // r13
size_t v3; // rax
void *v4; // rax
char *v5; // r12
size_t v6; // rax
size_t v8; // rax
size_t v9; // rax
size_t v10; // rax
size_t v11; // rax
char *v12; // r12
size_t v13; // rax
size_t v14; // rax
int v15; // [rsp+8h] [rbp-2A0h] BYREF
int v16; // [rsp+Ch] [rbp-29Ch] BYREF
char s[16]; // [rsp+10h] [rbp-298h] BYREF
__m128i v18; // [rsp+20h] [rbp-288h]
char v19[8]; // [rsp+30h] [rbp-278h] BYREF
void *ptr; // [rsp+140h] [rbp-168h] BYREF
int v21; // [rsp+148h] [rbp-160h]
char v22[101]; // [rsp+150h] [rbp-158h] BYREF
char v23[101]; // [rsp+1B5h] [rbp-F3h] BYREF
char v24[102]; // [rsp+21Ah] [rbp-8Eh] BYREF
char *v25; // [rsp+280h] [rbp-28h]

emitHTTPResponseHeader();
v2 = prologue;
v3 = strlen(prologue);
write(fd, v2, v3);
_isoc99_sscanf(a2, "/art%d_%d", &v15, &v16);
v4 = calloc(0x10001uLL, 1uLL);
v21 = 0x10000;
ptr = v4;
prune(feed, s);
if ( !(unsigned int)nntpConnect(s)
&& (int)nntpSetGroup(&feed[508 * v15 + 84], (unsigned int)(v16 - 1)) > 0
&& (int)nntpRetrieve(&ptr, 0x10000LL) > 0 )
{
if ( (unsigned int)nntpParse(&ptr, 0LL) )
{
puts("Parse error");
}
else
{
sprintf(s, "Subject : %s\n

", v22);
v8 = strlen(s);
write(fd, s, v8);
sprintf(s, "Sender : %s\n

", v23);
v9 = strlen(s);
write(fd, s, v9);
sprintf(s, "Group : %s\n

", &feed[508 * v15 + 84]);
v10 = strlen(s);
write(fd, s, v10);
sprintf(s, "Msg Date : %s\n

", v24);
v11 = strlen(s);
write(fd, s, v11);
v12 = v25;
v13 = strlen(v25);
write(fd, v12, v13);
strcpy(v19, ">
");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC30);
v18 = _mm_load_si128((const __m128i *)&LC31);
v14 = strlen(s);
write(fd, s, v14);
}
}
v5 = epilogue;
v6 = strlen(epilogue);
write(fd, v5, v6);
free(ptr);
return nntpDisconnect();
}

original_code:
void emitArticle( int connfd, char *filename )
{
  int group, article, count, result;
  news_t news;
  char line[300 +1];
  extern feedEntryType feed;
  emitHTTPResponseHeader( connfd );
  write( connfd, prologue, strlen(prologue));
  sscanf(filename, "/art%d_%d", &group, &article);
  news.msg = (char *)malloc((64*1024)+1);
  bzero( news.msg, (64*1024)+1 );
  news.msgLen = (64*1024);
  prune( feed.url, line );
  count = nntpConnect( line );
  if (count == 0) {
    count = nntpSetGroup( feed.groups[group].groupName, article-1 );
    if (count > 0) {
      result = nntpRetrieve( &news, (64*1024) );
      if (result > 0) {
        result = nntpParse( &news, 0 );
        if (result == 0) {
          sprintf( line, "Subject  : %s\n

",
                    news.subject );
          write( connfd, line, strlen(line) );
          sprintf( line, "Sender   : %s\n

",
                    news.sender );
          write( connfd, line, strlen(line) );
          sprintf( line, "Group    : %s\n

",
                    feed.groups[group].groupName );
          write( connfd, line, strlen(line) );
          sprintf( line, "Msg Date : %s\n"
                         "

",
                    news.msgDate );
          write( connfd, line, strlen(line) );
          write( connfd, news.bodyStart, strlen(news.bodyStart) );
          sprintf(line, "

End of Message\n

");
          write( connfd, line, strlen(line) );
        } else {
          printf("Parse error\n");
        }
      }
    }
  }
  write( connfd, epilogue, strlen(epilogue));
  free( news.msg );
  nntpDisconnect();
  return;
}

canonical_original_code:
void emitArticle(int connfd, char *filename)
{
  int group; int article; int count; int result;
  struct news_t news;
  char line[-1];
  extern struct feedEntryType feed;
  emitHTTPResponseHeader( connfd );
  write( connfd, prologue, strlen(prologue));
  sscanf(filename, "/art%d_%d", &group, &article);
  news.msg = (char *)malloc((64*1024)+1);
  bzero( news.msg, (64*1024)+1 );
  news.msgLen = (64*1024);
  prune( feed.url, line );
  count = nntpConnect( line );
  if (count == 0) {
    count = nntpSetGroup( feed.groups[group].groupName, article-1 );
    if (count > 0) {
      result = nntpRetrieve( &news, (64*1024) );
      if (result > 0) {
        result = nntpParse( &news, 0 );
        if (result == 0) {
          sprintf( line, "Subject  : %s\n

",
                    news.subject );
          write( connfd, line, strlen(line) );
          sprintf( line, "Sender   : %s\n

",
                    news.sender );
          write( connfd, line, strlen(line) );
          sprintf( line, "Group    : %s\n

",
                    feed.groups[group].groupName );
          write( connfd, line, strlen(line) );
          sprintf( line, "Msg Date : %s\n"
                         "

",
                    news.msgDate );
          write( connfd, line, strlen(line) );
          write( connfd, news.bodyStart, strlen(news.bodyStart) );
          sprintf(line, "

End of Message\n

");
          write( connfd, line, strlen(line) );
        } else {
          printf("Parse error\n");
        }
      }
    }
  }
  write( connfd, epilogue, strlen(epilogue));
  free( news.msg );
  nntpDisconnect();
  return;
}

variable_types:
filename
char *

variable_types: group int

variable_types: article int

variable_types: count int

variable_types: result int

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


findEmptyMemSlot

decompiled_code:
__int64 findEmptyMemSlot()
{
char *v0; // rdx
__int64 result; // rax

v0 = &workingMemory;
result = 0LL;
do
{
if ( !*(_DWORD *)v0 )
break;
result = (unsigned int)(result + 1);
v0 += 96;
}
while ( (_DWORD)result != 40 );
return result;
}

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

v0 = &workingMemory;
result = 0LL;
do
{
if ( !*(_DWORD *)v0 )
break;
result = (unsigned int)(result + 1);
v0 += 96;
}
while ( (_DWORD)result != 40 );
return result;
}

original_code:
int findEmptyMemSlot( void )
{
  int i;
  for (i = 0 ; i < 40 ; i++) {
    if (!workingMemory[i].active) break;
  }
  return i;
}

canonical_original_code:
int findEmptyMemSlot()
{
  int i;
  for (i = 0 ; i < 40 ; i++) {
    if (!workingMemory[i].active) break;
  }
  return i;
}


performAddCommand

decompiled_code:
int __fastcall performAddCommand(char *src)
{
const char *v2; // rbx
int result; // eax
int v4; // eax
__int64 v5; // rdi

v2 = (const char *)(unsigned int)((_DWORD)&workingMemory + 4);
while ( 1 )
{
if ( *((_DWORD *)v2 - 1) )
{
result = strcmp(v2, src);
if ( !result )
break;
}
v2 += 96;
if ( v2 == &workingMemory + 3844 )
{
v4 = findEmptyMemSlot();
if ( v4 > 39 )
_assert_fail("0", "rulefire.c", 0x6Cu, "performAddCommand");
v5 = 96LL * v4;
*(_DWORD *)(&workingMemory + v5) = 1;
strcpy(&workingMemory + v5 + 4, src);
return 1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *src)
{
const char *v2; // rbx
int result; // eax
int v4; // eax
__int64 v5; // rdi

v2 = (const char *)(unsigned int)((_DWORD)&workingMemory + 4);
while ( 1 )
{
if ( *((_DWORD *)v2 - 1) )
{
result = strcmp(v2, src);
if ( !result )
break;
}
v2 += 96;
if ( v2 == &workingMemory + 3844 )
{
v4 = func0();
if ( v4 > 39 )
_assert_fail("0", "rulefire.c", 0x6Cu, "performAddCommand");
v5 = 96LL * v4;
*(_DWORD *)(&workingMemory + v5) = 1;
strcpy(&workingMemory + v5 + 4, src);
return 1;
}
}
return result;
}

original_code:
int performAddCommand( char *mem )
{
  int slot;
  for (slot = 0 ; slot < 40 ; slot++) {
    if (workingMemory[slot].active) {
      if (!strcmp( workingMemory[slot].element, mem )) {
        return 0;
      }
    }
  }
  slot = findEmptyMemSlot();
  if (slot < 40) {
    workingMemory[slot].active = 1;
    strcpy( workingMemory[slot].element, mem );
  } else {
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "rulefire.c", 108, __extension__ __PRETTY_FUNCTION__); }));
  }
  return 1;
}

canonical_original_code:
int performAddCommand(char *mem)
{
  int slot;
  for (slot = 0 ; slot < 40 ; slot++) {
    if (workingMemory[slot].active) {
      if (!strcmp( workingMemory[slot].element, mem )) {
        return 0;
      }
    }
  }
  slot = findEmptyMemSlot();
  if (slot < 40) {
    workingMemory[slot].active = 1;
    strcpy( workingMemory[slot].element, mem );
  } else {
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "rulefire.c", 108, __extension__ __PRETTY_FUNCTION__); }));
  }
  return 1;
}

variable_types:
mem
char *

variable_types: slot int


performDeleteCommand

decompiled_code:
__int64 __fastcall performDeleteCommand(__int64 a1)
{
unsigned int v1; // er12
char *v2; // rbx
size_t v3; // rax
size_t v4; // rax
char v6[96]; // [rsp+0h] [rbp-198h] BYREF
char s[96]; // [rsp+60h] [rbp-138h] BYREF
char s2[96]; // [rsp+C0h] [rbp-D8h] BYREF
char v9[120]; // [rsp+120h] [rbp-78h] BYREF

v1 = 0;
v2 = (char *)(unsigned int)((_DWORD)&workingMemory + 4);
_isoc99_sscanf(a1, "(%s %s)", v6, s);
do
{
while ( 1 )
{
if ( *((_DWORD *)v2 - 1) )
{
_isoc99_sscanf(v2, "(%s %s)", s2, v9);
v3 = strlen(v6);
if ( !strncmp(v6, s2, v3) )
{
v4 = strlen(s);
if ( !strncmp(s, v9, v4) )
break;
}
}
v2 += 96;
if ( v2 == &workingMemory + 3844 )
return v1;
}
v2 += 96;
*((_DWORD *)v2 - 25) = 0;
v1 = 1;
*((_OWORD *)v2 - 6) = 0LL;
*((_OWORD *)v2 - 5) = 0LL;
*((_OWORD *)v2 - 4) = 0LL;
*((_OWORD *)v2 - 3) = 0LL;
*((_OWORD *)v2 - 2) = 0LL;
}
while ( v2 != &workingMemory + 3844 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v1; // er12
char *v2; // rbx
size_t v3; // rax
size_t v4; // rax
char v6[96]; // [rsp+0h] [rbp-198h] BYREF
char s[96]; // [rsp+60h] [rbp-138h] BYREF
char s2[96]; // [rsp+C0h] [rbp-D8h] BYREF
char v9[120]; // [rsp+120h] [rbp-78h] BYREF

v1 = 0;
v2 = (char *)(unsigned int)((_DWORD)&workingMemory + 4);
_isoc99_sscanf(a1, "(%s %s)", v6, s);
do
{
while ( 1 )
{
if ( *((_DWORD *)v2 - 1) )
{
_isoc99_sscanf(v2, "(%s %s)", s2, v9);
v3 = strlen(v6);
if ( !strncmp(v6, s2, v3) )
{
v4 = strlen(s);
if ( !strncmp(s, v9, v4) )
break;
}
}
v2 += 96;
if ( v2 == &workingMemory + 3844 )
return v1;
}
v2 += 96;
*((_DWORD *)v2 - 25) = 0;
v1 = 1;
*((_OWORD *)v2 - 6) = 0LL;
*((_OWORD *)v2 - 5) = 0LL;
*((_OWORD *)v2 - 4) = 0LL;
*((_OWORD *)v2 - 3) = 0LL;
*((_OWORD *)v2 - 2) = 0LL;
}
while ( v2 != &workingMemory + 3844 );
return v1;
}

original_code:
int performDeleteCommand( char *mem )
{
  int slot;
  int ret = 0;
  char term1[80 +1];
  char term2[80 +1];
  char wm_term1[80 +1];
  char wm_term2[80 +1];
  sscanf( mem, "(%s %s)", term1, term2 );
  for ( slot = 0 ; slot < 40 ; slot++ ) {
    if ( workingMemory[slot].active ) {
      sscanf( workingMemory[slot].element, "(%s %s)", wm_term1, wm_term2 );
      if (!strncmp(term1, wm_term1, strlen(term1)) &&
          !strncmp(term2, wm_term2, strlen(term2))) {
        workingMemory[slot].active = 0;
        bzero( workingMemory[slot].element, 80 );
        ret = 1;
      }
    }
  }
  return ret;
}

canonical_original_code:
int performDeleteCommand(char *mem)
{
  int slot;
  int ret = 0;
  char term1[-1];
  char term2[-1];
  char wm_term1[-1];
  char wm_term2[-1];
  sscanf( mem, "(%s %s)", term1, term2 );
  for ( slot = 0 ; slot < 40 ; slot++ ) {
    if ( workingMemory[slot].active ) {
      sscanf( workingMemory[slot].element, "(%s %s)", wm_term1, wm_term2 );
      if (!strncmp(term1, wm_term1, strlen(term1)) &&
          !strncmp(term2, wm_term2, strlen(term2))) {
        workingMemory[slot].active = 0;
        bzero( workingMemory[slot].element, 80 );
        ret = 1;
      }
    }
  }
  return ret;
}

variable_types: ret int


performPrintCommand

original_code:
int performPrintCommand( char *element )
{
  char string[40 +1];
  int i=0, j=0;
  while ( element[i] != '"') i++;
  i++;
  while ( element[i] != '"') string[j++] = element[i++];
  string[j] = 0;
  printf("%s\n", string);
  return 1;
}

canonical_original_code:
int performPrintCommand(char *element)
{
  char string[-1];
  int i = 0; int j = 0;
  while ( element[i] != '"') i++;
  i++;
  while ( element[i] != '"') string[j++] = element[i++];
  string[j] = 0;
  printf("%s\n", string);
  return 1;
}

variable_types:
element
char *

variable_types:
string
char [-1]


performEnableCommand

decompiled_code:
__int64 __fastcall performEnableCommand(const char *a1)
{
char *v1; // rax
unsigned int v3; // [rsp+8h] [rbp-10h] BYREF
unsigned int v4; // [rsp+Ch] [rbp-Ch] BYREF

v1 = strstr(a1, "timer");
_isoc99_sscanf(v1, "timer %d %d", &v3, &v4);
startTimer(v3, v4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
char *v1; // rax
unsigned int v3; // [rsp+8h] [rbp-10h] BYREF
unsigned int v4; // [rsp+Ch] [rbp-Ch] BYREF

v1 = strstr(a1, "timer");
_isoc99_sscanf(v1, "timer %d %d", &v3, &v4);
startTimer(v3, v4);
return 1LL;
}

original_code:
int performEnableCommand( char *element )
{
  char *string;
  int timer, expiration;
  void startTimer( int, int );
  string = strstr( element, "timer" );
  sscanf( string, "timer %d %d", &timer, &expiration );
  startTimer( timer, expiration );
  return 1;
}

canonical_original_code:
int performEnableCommand(char *element)
{
  char *string;
  int timer; int expiration;
  void startTimer(int, int);
  string = strstr( element, "timer" );
  sscanf( string, "timer %d %d", &timer, &expiration );
  startTimer( timer, expiration );
  return 1;
}

variable_types:
string
char *

variable_types: timer int

variable_types: expiration int

variable_types:
startTimer
void (int, int)


fireRule

decompiled_code:
__int64 __fastcall fireRule(int a1, unsigned __int8 *a2, __int64 a3, __int64 a4, __int64 a5, unsigned int a6)
{
__int64 v6; // r13
__int64 i; // rbx
int v9; // eax
char v11[88]; // [rsp+0h] [rbp-58h] BYREF

v6 = 13LL * a1;
for ( i = *((_QWORD *)&ruleSet + 13 * a1 + 12); i; i = *(_QWORD *)(i + 88) )
{
while ( !memcmp((const void *)(i + 4), "(add", 4uLL) )
{
constructElement(v11, i + 4, a2);
v9 = performAddCommand(v11);
i = *(_QWORD *)(i + 88);
a6 = v9;
if ( !i )
return a6;
}
if ( !memcmp((const void *)(i + 4), "(delete", 7uLL) )
{
constructElement(v11, i + 4, a2);
a6 = performDeleteCommand((__int64)v11);
}
else if ( !memcmp((const void *)(i + 4), "(disable", 8uLL) )
{
*((_DWORD *)&ruleSet + 2 * v6) = 0;
a6 = 1;
}
else if ( !memcmp((const void *)(i + 4), "(print", 6uLL) )
{
a6 = performPrintCommand((_BYTE *)(i + 4));
}
else if ( !memcmp((const void *)(i + 4), "(enable", 7uLL) )
{
a6 = performEnableCommand((const char *)(i + 4));
}
else if ( !memcmp((const void *)(i + 4), "(quit", 5uLL) )
{
endRun = 1;
}
}
return a6;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, unsigned __int8 *a2, __int64 a3, __int64 a4, __int64 a5, unsigned int a6)
{
__int64 v6; // r13
__int64 i; // rbx
int v9; // eax
char v11[88]; // [rsp+0h] [rbp-58h] BYREF

v6 = 13LL * a1;
for ( i = *((_QWORD *)&ruleSet + 13 * a1 + 12); i; i = *(_QWORD *)(i + 88) )
{
while ( !memcmp((const void *)(i + 4), "(add", 4uLL) )
{
func1(v11, i + 4, a2);
v9 = func2(v11);
i = *(_QWORD *)(i + 88);
a6 = v9;
if ( !i )
return a6;
}
if ( !memcmp((const void *)(i + 4), "(delete", 7uLL) )
{
func1(v11, i + 4, a2);
a6 = func3((__int64)v11);
}
else if ( !memcmp((const void *)(i + 4), "(disable", 8uLL) )
{
*((_DWORD *)&ruleSet + 2 * v6) = 0;
a6 = 1;
}
else if ( !memcmp((const void *)(i + 4), "(print", 6uLL) )
{
a6 = func4((_BYTE *)(i + 4));
}
else if ( !memcmp((const void *)(i + 4), "(enable", 7uLL) )
{
a6 = func5((const char *)(i + 4));
}
else if ( !memcmp((const void *)(i + 4), "(quit", 5uLL) )
{
endRun = 1;
}
}
return a6;
}

original_code:
int fireRule( int rule, const char *arg )
{
  int ret;
  memoryElementType *walker = ruleSet[rule].consequent;
  char newCons[40 +1];
  while (walker) {
    if (!strncmp(walker->element, "(add", 4)) {
      constructElement( newCons, walker->element, arg );
      ret = performAddCommand( newCons );
    } else if (!strncmp(walker->element, "(delete", 7)) {
      constructElement( newCons, walker->element, arg );
      ret = performDeleteCommand( newCons );
    } else if (!strncmp(walker->element, "(disable", 8)) {
      ruleSet[rule].active = 0;
      ret = 1;
    } else if (!strncmp(walker->element, "(print", 6)) {
      ret = performPrintCommand( walker->element );
    } else if (!strncmp(walker->element, "(enable", 7)) {
      ret = performEnableCommand( walker->element );
    } else if (!strncmp(walker->element, "(quit", 5)) {
      extern int endRun;
      endRun = 1;
    }
    walker = walker->next;
  }
  return ret;
}

canonical_original_code:
int fireRule(int rule, char *arg)
{
  int ret;
  struct memoryElementStruct *walker = ruleSet[rule].consequent;
  char newCons[-1];
  while (walker) {
    if (!strncmp(walker->element, "(add", 4)) {
      constructElement( newCons, walker->element, arg );
      ret = performAddCommand( newCons );
    } else if (!strncmp(walker->element, "(delete", 7)) {
      constructElement( newCons, walker->element, arg );
      ret = performDeleteCommand( newCons );
    } else if (!strncmp(walker->element, "(disable", 8)) {
      ruleSet[rule].active = 0;
      ret = 1;
    } else if (!strncmp(walker->element, "(print", 6)) {
      ret = performPrintCommand( walker->element );
    } else if (!strncmp(walker->element, "(enable", 7)) {
      ret = performEnableCommand( walker->element );
    } else if (!strncmp(walker->element, "(quit", 5)) {
      extern int endRun;
      endRun = 1;
    }
    walker = walker->next;
  }
  return ret;
}

variable_types: rule int

variable_types:
arg
char *

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

variable_types:
newCons
char [-1]

variable_types: endRun int


parseEntry

original_code:
int parseEntry( news_t *news, const char *searchString, char *dest )
{
  int i, index, len;
  if ((!news) || (!dest) || (!searchString)) return -1;
  len = strlen(searchString);
  for (i = 0 ; i < news->msgLen ; i++) {
    if (news->msg[i] == searchString[0]) {
      if (!strncmp(&news->msg[i], searchString, len )) {
        i += (len + 1);
        index = 0;
        while (!((news->msg[i] == 0x0d) && (news->msg[i+1] == 0x0a))) {
          dest[index++] = tolower(news->msg[i++]);
        }
        dest[index] = 0;
        break;
      }
    }
  }
  if (i == news->msgLen) {
    return -1;
  }
  return 0;
}

canonical_original_code:
int parseEntry(struct news_t *news, char *searchString, char *dest)
{
  int i; int index; int len;
  if ((!news) || (!dest) || (!searchString)) return -1;
  len = strlen(searchString);
  for (i = 0 ; i < news->msgLen ; i++) {
    if (news->msg[i] == searchString[0]) {
      if (!strncmp(&news->msg[i], searchString, len )) {
        i += (len + 1);
        index = 0;
        while (!((news->msg[i] == 0x0d) && (news->msg[i+1] == 0x0a))) {
          dest[index++] = tolower(news->msg[i++]);
        }
        dest[index] = 0;
        break;
      }
    }
  }
  if (i == news->msgLen) {
    return -1;
  }
  return 0;
}

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

variable_types:
searchString
char *

variable_types:
dest
char *

variable_types: i int

variable_types: index int

variable_types: len int


fixAddress

decompiled_code:
__int64 __fastcall fixAddress(char *dest)
{
int v2; // eax
int v3; // edi
__int64 v4; // rcx
__int64 v5; // rax
__int64 v6; // rcx
int v7; // edx
int v8; // esi
__int64 v9; // rax
__int64 v10; // rdi
char *v11; // rdx
char v12; // cl
__int64 result; // rax
int v14; // ecx
char v15[120]; // [rsp+0h] [rbp-78h] BYREF

if ( !dest )
return 0xFFFFFFFFLL;
v2 = strlen(dest);
v3 = v2;
if ( v2 > 0 )
{
v4 = (unsigned int)(v2 - 1);
v5 = 1LL;
v6 = v4 + 2;
while ( 1 )
{
v7 = v5;
if ( dest[v5 - 1] == 60 )
break;
if ( ++v5 == v6 )
{
v14 = v7++;
goto LABEL_13;
}
}
LABEL_6:
v8 = 0;
if ( v3 > v7 )
{
v9 = 0LL;
v10 = (unsigned int)(v3 - 1 - v7);
v11 = &dest[v7];
while ( 1 )
{
v12 = v11[v9];
v8 = v9;
if ( v12 == 62 )
break;
v15[v9] = v12;
v8 = v9 + 1;
if ( v9 == v10 )
break;
++v9;
}
}
v15[v8] = 0;
strcpy(dest, v15);
return 0LL;
}
v7 = 1;
v14 = 0;
LABEL_13:
result = 0LL;
if ( v3 != v14 )
goto LABEL_6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *dest)
{
int v2; // eax
int v3; // edi
__int64 v4; // rcx
__int64 v5; // rax
__int64 v6; // rcx
int v7; // edx
int v8; // esi
__int64 v9; // rax
__int64 v10; // rdi
char *v11; // rdx
char v12; // cl
__int64 result; // rax
int v14; // ecx
char v15[120]; // [rsp+0h] [rbp-78h] BYREF

if ( !dest )
return 0xFFFFFFFFLL;
v2 = strlen(dest);
v3 = v2;
if ( v2 > 0 )
{
v4 = (unsigned int)(v2 - 1);
v5 = 1LL;
v6 = v4 + 2;
while ( 1 )
{
v7 = v5;
if ( dest[v5 - 1] == 60 )
break;
if ( ++v5 == v6 )
{
v14 = v7++;
goto LABEL_13;
}
}
LABEL_6:
v8 = 0;
if ( v3 > v7 )
{
v9 = 0LL;
v10 = (unsigned int)(v3 - 1 - v7);
v11 = &dest[v7];
while ( 1 )
{
v12 = v11[v9];
v8 = v9;
if ( v12 == 62 )
break;
v15[v9] = v12;
v8 = v9 + 1;
if ( v9 == v10 )
break;
++v9;
}
}
v15[v8] = 0;
strcpy(dest, v15);
return 0LL;
}
v7 = 1;
v14 = 0;
LABEL_13:
result = 0LL;
if ( v3 != v14 )
goto LABEL_6;
return result;
}

original_code:
int fixAddress ( char *address )
{
  int i, j, len;
  char string[100 +1];
  if (!address) return -1;
  len = strlen(address);
  for (i = 0 ; i < len ; i++) {
    if (address[i] == '<') break;
  }
  if (i++ == len) return 0;
  j = 0;
  for ( ; i < len ; i++) {
    if (address[i] == '>') break;
    string[j++] = address[i];
  }
  string[j] = 0;
  strcpy(address, string);
  return 0;
}

canonical_original_code:
int fixAddress(char *address)
{
  int i; int j; int len;
  char string[-1];
  if (!address) return -1;
  len = strlen(address);
  for (i = 0 ; i < len ; i++) {
    if (address[i] == '<') break;
  }
  if (i++ == len) return 0;
  j = 0;
  for ( ; i < len ; i++) {
    if (address[i] == '>') break;
    string[j++] = address[i];
  }
  string[j] = 0;
  strcpy(address, string);
  return 0;
}

variable_types:
address
char *

variable_types: j int


findBody

decompiled_code:
__int64 __fastcall findBody(__int64 *a1)
{
int v1; // er8
__int64 v2; // rdx
__int64 v3; // rax
int v4; // ecx
__int64 result; // rax

v1 = *((_DWORD *)a1 + 2);
if ( v1 <= 0 )
return 0xFFFFFFFFLL;
v2 = *a1;
v3 = 0LL;
while ( *(_BYTE *)(v2 + v3) != 13
|| *(_BYTE *)(v2 + v3 + 1) != 10
|| *(_BYTE *)(v2 + v3 + 2) != 13
|| *(_BYTE *)(v2 + v3 + 3) != 10 )
{
if ( v1 == ++v3 )
return 0xFFFFFFFFLL;
}
v4 = v3 + 4;
if ( v1 <= (int)v3 + 4 )
return 0xFFFFFFFFLL;
result = 0LL;
a1[40] = v4 + v2;
return result;
}

original_code:
int findBody( news_t *news )
{
  int i, result=-1;
  for (i = 0 ; i < news->msgLen ; i++) {
    if ((news->msg[i] == 0x0d) && (news->msg[i+1] == 0x0a) &&
        (news->msg[i+2] == 0x0d) && (news->msg[i+3] == 0x0a)) {
      i+=4;
      break;
    }
  }
  if (i < news->msgLen) {
    news->bodyStart = &news->msg[i];
    result = 0;
  }
  return result;
}

canonical_original_code:
int findBody(struct news_t *news)
{
  int i; int result = -1;
  for (i = 0 ; i < news->msgLen ; i++) {
    if ((news->msg[i] == 0x0d) && (news->msg[i+1] == 0x0a) &&
        (news->msg[i+2] == 0x0d) && (news->msg[i+3] == 0x0a)) {
      i+=4;
      break;
    }
  }
  if (i < news->msgLen) {
    news->bodyStart = &news->msg[i];
    result = 0;
  }
  return result;
}

variable_types: result int

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


skipWhiteSpace

decompiled_code:
unsigned __int8 *__fastcall skipWhiteSpace(unsigned __int8 *a1)
{
__int64 v1; // rcx
unsigned __int8 *result; // rax
unsigned __int64 v3; // rdx

v1 = 0x2800030000000001LL;
result = a1;
while ( 1 )
{
v3 = *result;
if ( (unsigned __int8)v3 <= 0x3Du )
goto LABEL_4;
do
{
do
v3 = *++result;
while ( (unsigned __int8)v3 > 0x3Du );
LABEL_4:
;
}
while ( !_bittest64(&v1, v3) );
if ( (_BYTE)v3 != 59 )
return result;
do
++result;
while ( *(result - 1) != 10 );
}
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func0(unsigned __int8 *a1)
{
__int64 v1; // rcx
unsigned __int8 *result; // rax
unsigned __int64 v3; // rdx

v1 = 0x2800030000000001LL;
result = a1;
while ( 1 )
{
v3 = *result;
if ( (unsigned __int8)v3 <= 0x3Du )
goto LABEL_4;
do
{
do
v3 = *++result;
while ( (unsigned __int8)v3 > 0x3Du );
LABEL_4:
;
}
while ( !_bittest64(&v1, v3) );
if ( (_BYTE)v3 != 59 )
return result;
do
++result;
while ( *(result - 1) != 10 );
}
}

original_code:
char *skipWhiteSpace( char *block )
{
  char ch;
  while (1) {
    ch = *block;
    while ((ch != '(') && (ch != ')') && (ch != '=') &&
           (ch != 0) && (ch != ';')) {
      block++;
      ch = *block;
    }
    if (ch == ';') {
      while (*block++ != 0x0a);
    } else break;
  }
  return block;
}

canonical_original_code:
char *skipWhiteSpace(char *block)
{
  char ch;
  while (1) {
    ch = *block;
    while ((ch != '(') && (ch != ')') && (ch != '=') &&
           (ch != 0) && (ch != ';')) {
      block++;
      ch = *block;
    }
    if (ch == ';') {
      while (*block++ != 0x0a);
    } else break;
  }
  return block;
}

variable_types:
block
char *

variable_types: ch char

return_type: char *


parseAntecedent

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

while ( 1 )
{
result = skipWhiteSpace(a1);
if ( *result != 40 )
break;
a1 = parseElement(result, (__int64 *)(a2 + 88));
}
return result;
}

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

while ( 1 )
{
result = func0(a1);
if ( *result != 40 )
break;
a1 = parseElement(result, (__int64 *)(a2 + 88));
}
return result;
}

original_code:
char *parseAntecedent( char *block, ruleType *rule )
{
  while (1) {
    block = skipWhiteSpace( block );
    if (*block == '(') {
      block = parseElement( block, &rule->antecedent );
    } else break;
  }
  return block;
}

canonical_original_code:
char *parseAntecedent(char *block, struct ruleType *rule)
{
  while (1) {
    block = skipWhiteSpace( block );
    if (*block == '(') {
      block = parseElement( block, &rule->antecedent );
    } else break;
  }
  return block;
}

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

user_defined_types: struct ruleType { int active; char ruleName[-1]; struct memoryElementStruct *antecedent; struct memoryElementStruct *consequent; }


parseConsequent

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

while ( 1 )
{
result = skipWhiteSpace(a1);
if ( *result != 40 )
break;
a1 = parseElement(result, (__int64 *)(a2 + 96));
}
return result;
}

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

while ( 1 )
{
result = func0(a1);
if ( *result != 40 )
break;
a1 = parseElement(result, (__int64 *)(a2 + 96));
}
return result;
}

original_code:
char *parseConsequent( char *block, ruleType *rule )
{
  while (1) {
    block = skipWhiteSpace( block );
    if (*block == '(') {
      block = parseElement(block, &rule->consequent);
    } else break;
  }
  return block;
}

canonical_original_code:
char *parseConsequent(char *block, struct ruleType *rule)
{
  while (1) {
    block = skipWhiteSpace( block );
    if (*block == '(') {
      block = parseElement(block, &rule->consequent);
    } else break;
  }
  return block;
}

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


initializePopulation

original_code:
void initializePopulation( void )
{
  int member, index;
  int x, temp;
  for (member = 0 ; member < 100 ; member++) {
    for (index = 0 ; index < 80 ; index++) {
      population[member].solution[index] = index+1;
    }
    for (index = 0 ; index < 80 ; index++) {
      x = (int)((float)(80)*rand()/(2147483647 +1.0));
      temp = population[member].solution[index];
      population[member].solution[index] = population[member].solution[x];
      population[member].solution[x] = temp;
    }
  }
}

canonical_original_code:
void initializePopulation()
{
  int member; int index;
  int x; int temp;
  for (member = 0 ; member < 100 ; member++) {
    for (index = 0 ; index < 80 ; index++) {
      population[member].solution[index] = index+1;
    }
    for (index = 0 ; index < 80 ; index++) {
      x = (int)((float)(80)*rand()/(2147483647 +1.0));
      temp = population[member].solution[index];
      population[member].solution[index] = population[member].solution[x];
      population[member].solution[x] = temp;
    }
  }
}

variable_types: member int

variable_types: x int

variable_types: temp int


simulateAnnealing

original_code:
int simulateAnnealing( float curTemp )
{
  int member, i;
  memberType tempMember;
  float energy;
  int useNew = 0;
  int solution = -1;
  for (member = 0 ; member < 100 ; member++) {
    for (i = 0 ; i < 80 ; i++) {
      tempMember.solution[i] = population[member].solution[i];
    }
    tweakSolution( &tempMember );
    energy = computeEnergy( &tempMember );
    useNew = 0;
    if (energy < population[member].energy) {
      useNew = 1;
    } else {
      float test = ((float)rand() / (float)2147483647);
      float delta = energy - population[member].energy;
      if (exp(-delta/curTemp) > test) {
        useNew = 1;
      }
    }
    if (useNew) {
      for (i = 0 ; i < 80 ; i++) {
        population[member].solution[i] = tempMember.solution[i];
        population[member].energy = energy;
      }
    }
    if (population[member].energy == 0) solution = member;
  }
  return solution;
}

canonical_original_code:
int simulateAnnealing(float curTemp)
{
  int member; int i;
  struct memberType tempMember;
  float energy;
  int useNew = 0;
  int solution = -1;
  for (member = 0 ; member < 100 ; member++) {
    for (i = 0 ; i < 80 ; i++) {
      tempMember.solution[i] = population[member].solution[i];
    }
    tweakSolution( &tempMember );
    energy = computeEnergy( &tempMember );
    useNew = 0;
    if (energy < population[member].energy) {
      useNew = 1;
    } else {
      float test = ((float)rand() / (float)2147483647);
      float delta = energy - population[member].energy;
      if (exp(-delta/curTemp) > test) {
        useNew = 1;
      }
    }
    if (useNew) {
      for (i = 0 ; i < 80 ; i++) {
        population[member].solution[i] = tempMember.solution[i];
        population[member].energy = energy;
      }
    }
    if (population[member].energy == 0) solution = member;
  }
  return solution;
}

variable_types: curTemp float

variable_types: struct memberType { char solution[80]; float energy; }

variable_types: energy float

variable_types: useNew int

variable_types: solution int

variable_types: test float

variable_types: delta float


computeAllEnergy

decompiled_code:
void computeAllEnergy()
{
float *v0; // rbx
__int64 v1; // rdi

v0 = (float *)&population;
do
{
v1 = (__int64)v0;
v0 += 21;
*(v0 - 1) = computeEnergy(v1);
}
while ( v0 != (float *)&end );
}

canonical_decompiled_code:
void func12()
{
float *v0; // rbx
__int64 v1; // rdi

v0 = (float *)&population;
do
{
v1 = (__int64)v0;
v0 += 21;
*(v0 - 1) = func10(v1);
}
while ( v0 != (float *)&end );
}

original_code:
void computeAllEnergy( void )
{
  int member;
  for (member = 0 ; member < 100 ; member++) {
    population[member].energy = computeEnergy( &population[member] );
  }
}

canonical_original_code:
void computeAllEnergy()
{
  int member;
  for (member = 0 ; member < 100 ; member++) {
    population[member].energy = computeEnergy( &population[member] );
  }
}


tweakSolution

decompiled_code:
__int64 __fastcall tweakSolution(__int64 a1)
{
int v1; // ebx
__int64 result; // rax
char v3; // dl

v1 = (int)((float)((float)rand() * 80.0) * 4.656612873077393e-10);
do
LODWORD(result) = (int)((float)((float)rand() * 80.0) * 4.656612873077393e-10);
while ( v1 == (_DWORD)result );
result = (int)result;
v3 = *(_BYTE *)(a1 + v1);
*(_BYTE *)(a1 + v1) = *(_BYTE *)(a1 + (int)result);
*(_BYTE *)(a1 + (int)result) = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int v1; // ebx
__int64 result; // rax
char v3; // dl

v1 = (int)((float)((float)rand() * 80.0) * 4.656612873077393e-10);
do
LODWORD(result) = (int)((float)((float)rand() * 80.0) * 4.656612873077393e-10);
while ( v1 == (_DWORD)result );
result = (int)result;
v3 = *(_BYTE *)(a1 + v1);
*(_BYTE *)(a1 + v1) = *(_BYTE *)(a1 + (int)result);
*(_BYTE *)(a1 + (int)result) = v3;
return result;
}

original_code:
void tweakSolution( memberType *member )
{
  int temp, x, y;
  x = (int)((float)(80)*rand()/(2147483647 +1.0));
  do {
    y = (int)((float)(80)*rand()/(2147483647 +1.0));
  } while (x == y);
  temp = member->solution[x];
  member->solution[x] = member->solution[y];
  member->solution[y] = temp;
}

canonical_original_code:
void tweakSolution(struct memberType *member)
{
  int temp; int x; int y;
  x = (int)((float)(80)*rand()/(2147483647 +1.0));
  do {
    y = (int)((float)(80)*rand()/(2147483647 +1.0));
  } while (x == y);
  temp = member->solution[x];
  member->solution[x] = member->solution[y];
  member->solution[y] = temp;
}

variable_types: struct memberType { char solution[80]; float energy; } *

variable_types: y int


emitSolution

original_code:
void emitSolution( memberType *member )
{
  char board[80][80];
  int x, y;
  bzero( (void *)board, 80 * 80 );
  for (x = 0 ; x < 80 ; x++) {
    board[x][member->solution[x]-1] = 'Q';
  }
  printf("board:\n");
  for (y = 0 ; y < 80 ; y++) {
    for (x = 0 ; x < 80 ; x++) {
      if (board[x][y] == 'Q') printf("Q ");
      else printf(". ");
    }
    printf("\n");
  }
  printf("\n\n");
}

canonical_original_code:
void emitSolution(struct memberType *member)
{
  char board[80][80];
  int x; int y;
  bzero( (void *)board, 80 * 80 );
  for (x = 0 ; x < 80 ; x++) {
    board[x][member->solution[x]-1] = 'Q';
  }
  printf("board:\n");
  for (y = 0 ; y < 80 ; y++) {
    for (x = 0 ; x < 80 ; x++) {
      if (board[x][y] == 'Q') printf("Q ");
      else printf(". ");
    }
    printf("\n");
  }
  printf("\n\n");
}

variable_types:
board
char [80][80]

user_defined_types: struct memberType { char solution[80]; float energy; }


computeEnergy

original_code:
float computeEnergy( memberType *member )
{
  int i, j, x, y, tempx, tempy;
  char board[80][80];
  int conflicts;
  const int dx[4] = {-1, 1, -1, 1};
  const int dy[4] = {-1, 1, 1, -1};
  bzero( (void *)board, 80 * 80 );
  for (i = 0 ; i < 80 ; i++) {
    board[i][member->solution[i]-1] = 'Q';
  }
  conflicts = 0;
  for (i = 0 ; i < 80 ; i++) {
    x = i; y = member->solution[i]-1;
    for (j = 0 ; j < 4 ; j++) {
      tempx = x ; tempy = y;
      while(1) {
        tempx += dx[j]; tempy += dy[j];
        if ((tempx < 0) || (tempx >= 80) ||
               (tempy < 0) || (tempy >= 80)) break;
        if (board[tempx][tempy] == 'Q') conflicts++;
      }
    }
  }
  return (float)conflicts;
}

canonical_original_code:
float computeEnergy(struct memberType *member)
{
  int i; int j; int x; int y; int tempx; int tempy;
  char board[80][80];
  int conflicts;
  int dx[4] = {-1, 1, -1, 1};
  int dy[4] = {-1, 1, 1, -1};
  bzero( (void *)board, 80 * 80 );
  for (i = 0 ; i < 80 ; i++) {
    board[i][member->solution[i]-1] = 'Q';
  }
  conflicts = 0;
  for (i = 0 ; i < 80 ; i++) {
    x = i; y = member->solution[i]-1;
    for (j = 0 ; j < 4 ; j++) {
      tempx = x ; tempy = y;
      while(1) {
        tempx += dx[j]; tempy += dy[j];
        if ((tempx < 0) || (tempx >= 80) ||
               (tempy < 0) || (tempy >= 80)) break;
        if (board[tempx][tempy] == 'Q') conflicts++;
      }
    }
  }
  return (float)conflicts;
}

variable_types: i int

variable_types: j int

variable_types: tempx int

variable_types: tempy int

variable_types: conflicts int

variable_types:
dx
int [4]

variable_types:
dy
int [4]

return_type: float


interpretSTM

decompiled_code:
__int64 __fastcall interpretSTM(unsigned int *a1, int a2, __int64 a3, int a4)
{
int v5; // ecx
int *v6; // rdx
__int64 v7; // rcx
__int64 v8; // rax
int v9; // esi
__int64 v10; // rcx
__int64 result; // rax
int v12; // eax
int v13; // eax
int v14; // edx
int v15; // esi
__int64 v16; // rax
__int64 v17; // rax

stackPointer = 0;
v5 = a4 - 1;
if ( v5 >= 0 )
{
v6 = (int *)(a3 + 4LL * v5);
v7 = (unsigned int)v5 + 2LL;
v8 = 1LL;
do
{
stackPointer = v8;
v9 = *v6--;
dword_4040FC[v8++] = v9;
}
while ( v8 != v7 );
}
if ( a2 <= 0 )
return 0LL;
v10 = (__int64)&a1[a2 - 1 + 1];
while ( 2 )
{
result = *a1;
switch ( (int)result )
{
case 0:
v17 = stackPointer;
if ( stackPointer == 15 || stackPointer <= 0 )
return 1LL;
++stackPointer;
stack[v17] = stack[(int)v17 - 1];
goto LABEL_9;
case 1:
if ( stackPointer <= 1 )
return result;
v14 = stackPointer - 2;
v15 = stack[stackPointer - 1];
stack[stackPointer - 1] = stack[stackPointer - 2];
stack[v14] = v15;
goto LABEL_9;
case 2:
v13 = stackPointer;
if ( stackPointer <= 1 )
return 1LL;
--stackPointer;
stack[v13 - 2] *= stack[v13 - 1];
goto LABEL_9;
case 3:
v12 = stackPointer;
if ( stackPointer <= 1 )
return 1LL;
--stackPointer;
stack[v12 - 2] += stack[v12 - 1];
goto LABEL_9;
case 4:
v16 = stackPointer;
if ( stackPointer > 1 )
{
++stackPointer;
stack[v16] = stack[(int)v16 - 2];
LABEL_9:
if ( (unsigned int *)v10 == ++a1 )
return 0LL;
continue;
}
return 1LL;
default:
goto LABEL_9;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1, int a2, __int64 a3, int a4)
{
int v5; // ecx
int *v6; // rdx
__int64 v7; // rcx
__int64 v8; // rax
int v9; // esi
__int64 v10; // rcx
__int64 result; // rax
int v12; // eax
int v13; // eax
int v14; // edx
int v15; // esi
__int64 v16; // rax
__int64 v17; // rax

stackPointer = 0;
v5 = a4 - 1;
if ( v5 >= 0 )
{
v6 = (int *)(a3 + 4LL * v5);
v7 = (unsigned int)v5 + 2LL;
v8 = 1LL;
do
{
stackPointer = v8;
v9 = *v6--;
dword_4040FC[v8++] = v9;
}
while ( v8 != v7 );
}
if ( a2 <= 0 )
return 0LL;
v10 = (__int64)&a1[a2 - 1 + 1];
while ( 2 )
{
result = *a1;
switch ( (int)result )
{
case 0:
v17 = stackPointer;
if ( stackPointer == 15 || stackPointer <= 0 )
return 1LL;
++stackPointer;
stack[v17] = stack[(int)v17 - 1];
goto LABEL_9;
case 1:
if ( stackPointer <= 1 )
return result;
v14 = stackPointer - 2;
v15 = stack[stackPointer - 1];
stack[stackPointer - 1] = stack[stackPointer - 2];
stack[v14] = v15;
goto LABEL_9;
case 2:
v13 = stackPointer;
if ( stackPointer <= 1 )
return 1LL;
--stackPointer;
stack[v13 - 2] *= stack[v13 - 1];
goto LABEL_9;
case 3:
v12 = stackPointer;
if ( stackPointer <= 1 )
return 1LL;
--stackPointer;
stack[v12 - 2] += stack[v12 - 1];
goto LABEL_9;
case 4:
v16 = stackPointer;
if ( stackPointer > 1 )
{
++stackPointer;
stack[v16] = stack[(int)v16 - 2];
LABEL_9:
if ( (unsigned int *)v10 == ++a1 )
return 0LL;
continue;
}
return 1LL;
default:
goto LABEL_9;
}
}
}

original_code:
int interpretSTM(const int *program, int progLength,
                   const int *args, int argsLength)
{
  int pc = 0;
  int i, error = 0;
  int a, b;
  stackPointer = 0;
  for (i = argsLength-1 ; i >= 0 ; i--) {
    (stack[stackPointer++] = args[i]);
  }
  while ((error == 0) && (pc < progLength)) {
    switch(program[pc++]) {
      case 0x00:
        if (stackPointer < 1) { error = 1 ; break; };
        if (stackPointer == 15) { error = 1 ; break; };
        (stack[stackPointer++] = (stack[stackPointer-1]));
        break;
      case 0x01:
        if (stackPointer < 2) { error = 1 ; break; };
        a = stack[stackPointer-1];
        stack[stackPointer-1] = stack[stackPointer-2];
        stack[stackPointer-2] = a;
        break;
      case 0x02:
        if (stackPointer < 2) { error = 1 ; break; };
        a = (stack[--stackPointer]); b = (stack[--stackPointer]);
        (stack[stackPointer++] = a * b);
        break;
      case 0x03:
        if (stackPointer < 2) { error = 1 ; break; };
        a = (stack[--stackPointer]); b = (stack[--stackPointer]);
        (stack[stackPointer++] = a + b);
        break;
      case 0x04:
        if (stackPointer < 2) { error = 1 ; break; };
        (stack[stackPointer++] = stack[stackPointer-2]);
        break;
    }
  }
  return(error);
}

canonical_original_code:
int interpretSTM(int *program, int progLength, int *args, int argsLength)
{
  int pc = 0;
  int i; int error = 0;
  int a; int b;
  stackPointer = 0;
  for (i = argsLength-1 ; i >= 0 ; i--) {
    (stack[stackPointer++] = args[i]);
  }
  while ((error == 0) && (pc < progLength)) {
    switch(program[pc++]) {
      case 0x00:
        if (stackPointer < 1) { error = 1 ; break; };
        if (stackPointer == 15) { error = 1 ; break; };
        (stack[stackPointer++] = (stack[stackPointer-1]));
        break;
      case 0x01:
        if (stackPointer < 2) { error = 1 ; break; };
        a = stack[stackPointer-1];
        stack[stackPointer-1] = stack[stackPointer-2];
        stack[stackPointer-2] = a;
        break;
      case 0x02:
        if (stackPointer < 2) { error = 1 ; break; };
        a = (stack[--stackPointer]); b = (stack[--stackPointer]);
        (stack[stackPointer++] = a * b);
        break;
      case 0x03:
        if (stackPointer < 2) { error = 1 ; break; };
        a = (stack[--stackPointer]); b = (stack[--stackPointer]);
        (stack[stackPointer++] = a + b);
        break;
      case 0x04:
        if (stackPointer < 2) { error = 1 ; break; };
        (stack[stackPointer++] = stack[stackPointer-2]);
        break;
    }
  }
  return(error);
}

variable_types:
program
int *

variable_types: progLength int

variable_types:
args
int *

variable_types: argsLength int

variable_types: pc int

variable_types: error int

variable_types: a int

variable_types: b int


selectParent

decompiled_code:
__int64 selectParent()
{
int v0; // eax
float v1; // xmm0_4
unsigned int v2; // er8
float v3; // xmm1_4
unsigned int v4; // eax

v0 = rand();
v1 = 0.0;
v2 = chrom_0;
v3 = (float)((float)((float)v0 * 4.6566129e-10) * *(float *)&totFitness) * 0.25;
while ( 1 )
{
while ( 1 )
{
v1 = v1 + *(float *)&populations[21000 * curPop + 7 * (int)v2];
v4 = v2 + 1;
if ( v1 >= v3 )
break;
if ( v2 == 2999 )
v4 = 0;
v2 = v4;
}
if ( v2 == 2999 )
{
chrom_0 = 0;
return 2999;
}
if ( v2 != -1 )
break;
v2 = 0;
}
chrom_0 = v2 + 1;
return v2;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // eax
float v1; // xmm0_4
unsigned int v2; // er8
float v3; // xmm1_4
unsigned int v4; // eax

v0 = rand();
v1 = 0.0;
v2 = chrom_0;
v3 = (float)((float)((float)v0 * 4.6566129e-10) * *(float *)&totFitness) * 0.25;
while ( 1 )
{
while ( 1 )
{
v1 = v1 + *(float *)&populations[21000 * curPop + 7 * (int)v2];
v4 = v2 + 1;
if ( v1 >= v3 )
break;
if ( v2 == 2999 )
v4 = 0;
v2 = v4;
}
if ( v2 == 2999 )
{
chrom_0 = 0;
return 2999;
}
if ( v2 != -1 )
break;
v2 = 0;
}
chrom_0 = v2 + 1;
return v2;
}

original_code:
int selectParent( void )
{
  static int chrom = 0;
  int ret = -1;
  float retFitness = 0.0;
  float fitMarker = ((((float)rand() / (float)2147483647) * totFitness) * 0.25);
  do {
    retFitness += populations[curPop][chrom].fitness;
    if (retFitness >= fitMarker) {
      ret = chrom;
    }
    if (++chrom == 3000) chrom = 0;
  } while (ret == -1);
  return ret;
}

canonical_original_code:
int selectParent()
{
  static int chrom = 0;
  int ret = -1;
  float retFitness = 0.0;
  float fitMarker = ((((float)rand() / (float)2147483647) * totFitness) * 0.25);
  do {
    retFitness += populations[curPop][chrom].fitness;
    if (retFitness >= fitMarker) {
      ret = chrom;
    }
    if (++chrom == 3000) chrom = 0;
  } while (ret == -1);
  return ret;
}

variable_types: chrom int

variable_types: ret int

variable_types: retFitness float

variable_types: fitMarker float


mutate

decompiled_code:
__int64 __fastcall mutate(unsigned int a1)
{
int v2; // eax

if ( (float)((float)rand() * 4.6566129e-10) <= 0.9299999999999999 )
return a1;
v2 = rand();
++curMutations;
return (unsigned int)(int)((float)((float)v2 * 6.0) * 4.656612873077393e-10);
}

original_code:
int mutate(int gene)
{
  float temp = ((float)rand() / (float)2147483647);
  if (temp > (1.0 - 0.07)) {
      gene = (int)((float)((0x05 +1))*rand()/(2147483647 +1.0));
      curMutations++;
  }
  return gene;
}

variable_types: gene int

variable_types: temp float


performReproduction

original_code:
int performReproduction( int parentA, int parentB, int childA, int childB )
{
  int crossPoint, i;
  int nextPop = (curPop == 0) ? 1 : 0;
  int mutate( int );
  if (((float)rand() / (float)2147483647) > (1.0 - 0.8)) {
    crossPoint = (int)((float)(((populations[curPop][parentA].progSize-2 > populations[curPop][parentB].progSize-2) ? populations[curPop][parentA].progSize-2 : populations[curPop][parentB].progSize-2))*rand()/(2147483647 +1.0))+1;
    curCrossovers++;
  } else {
    crossPoint = 12;
  }
  for (i = 0 ; i < crossPoint ; i++) {
    populations[nextPop][childA].program[i] =
        mutate(populations[curPop][parentA].program[i]);
    populations[nextPop][childB].program[i] =
        mutate(populations[curPop][parentB].program[i]);
  }
  for ( ; i < 12 ; i++) {
    populations[nextPop][childA].program[i] =
        mutate(populations[curPop][parentB].program[i]);
    populations[nextPop][childB].program[i] =
        mutate(populations[curPop][parentA].program[i]);
  }
  populations[nextPop][childA].progSize =
    populations[curPop][parentA].progSize;
  populations[nextPop][childB].progSize =
    populations[curPop][parentB].progSize;
  return 0;
}

canonical_original_code:
int performReproduction(int parentA, int parentB, int childA, int childB)
{
  int crossPoint; int i;
  int nextPop = (curPop == 0) ? 1 : 0;
  int mutate(int);
  if (((float)rand() / (float)2147483647) > (1.0 - 0.8)) {
    crossPoint = (int)((float)(((populations[curPop][parentA].progSize-2 > populations[curPop][parentB].progSize-2) ? populations[curPop][parentA].progSize-2 : populations[curPop][parentB].progSize-2))*rand()/(2147483647 +1.0))+1;
    curCrossovers++;
  } else {
    crossPoint = 12;
  }
  for (i = 0 ; i < crossPoint ; i++) {
    populations[nextPop][childA].program[i] =
        mutate(populations[curPop][parentA].program[i]);
    populations[nextPop][childB].program[i] =
        mutate(populations[curPop][parentB].program[i]);
  }
  for ( ; i < 12 ; i++) {
    populations[nextPop][childA].program[i] =
        mutate(populations[curPop][parentB].program[i]);
    populations[nextPop][childB].program[i] =
        mutate(populations[curPop][parentA].program[i]);
  }
  populations[nextPop][childA].progSize =
    populations[curPop][parentA].progSize;
  populations[nextPop][childB].progSize =
    populations[curPop][parentB].progSize;
  return 0;
}

variable_types: parentA int

variable_types: parentB int

variable_types: childA int

variable_types: childB int

variable_types: crossPoint int

variable_types: i int

variable_types: nextPop int

variable_types:
mutate
int (int)


performSelection

decompiled_code:
__int64 performSelection()
{
int i; // ebx
int v1; // ebp
int v2; // eax
int v3; // ecx
int v4; // edx

for ( i = 0; i != 3000; i += 2 )
{
v1 = selectParent();
v2 = selectParent();
v3 = i + 1;
v4 = i;
performReproduction(v1, v2, v4, v3);
}
return 0LL;
}

original_code:
int performSelection( void )
{
  int par1, par2;
  int child1, child2;
  int chrom;
  for (chrom = 0 ; chrom < 3000 ; chrom+=2) {
    par1 = selectParent();
    par2 = selectParent();
    child1 = chrom;
    child2 = chrom+1;
    performReproduction( par1, par2, child1, child2 );
  }
  return 0;
}

canonical_original_code:
int performSelection()
{
  int par1; int par2;
  int child1; int child2;
  int chrom;
  for (chrom = 0 ; chrom < 3000 ; chrom+=2) {
    par1 = selectParent();
    par2 = selectParent();
    child1 = chrom;
    child2 = chrom+1;
    performReproduction( par1, par2, child1, child2 );
  }
  return 0;
}


printProgram

decompiled_code:
int __fastcall printProgram(int a1, int a2)
{
__int64 v2; // rbp
int result; // eax
__int64 v4; // rbx
__int64 v5; // rax

v2 = 168000LL * a2 + 56LL * a1;
result = *(_DWORD *)((char *)populations + v2 + 4);
if ( result > 0 )
{
v4 = 0LL;
do
{
v5 = *(int *)((char *)&dword_404188[v4++] + v2);
result = puts((&tins)[v5]);
}
while ( *(_DWORD *)((char *)populations + v2 + 4) > (int)v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(int a1, int a2)
{
__int64 v2; // rbp
int result; // eax
__int64 v4; // rbx
__int64 v5; // rax

v2 = 168000LL * a2 + 56LL * a1;
result = *(_DWORD *)((char *)populations + v2 + 4);
if ( result > 0 )
{
v4 = 0LL;
do
{
v5 = *(int *)((char *)&dword_404188[v4++] + v2);
result = puts((&tins)[v5]);
}
while ( *(_DWORD *)((char *)populations + v2 + 4) > (int)v4 );
}
return result;
}

original_code:
void printProgram( int index, int curPop )
{
  int i;
  for (i = 0 ; i < populations[curPop][index].progSize ; i++) {
    printf("%s\n", tins[ populations[curPop][index].program[i] ] );
  }
}

canonical_original_code:
void printProgram(int index, int curPop)
{
  int i;
  for (i = 0 ; i < populations[curPop][index].progSize ; i++) {
    printf("%s\n", tins[ populations[curPop][index].program[i] ] );
  }
}

variable_types: index int

variable_types: curPop int


sigmoid

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

canonical_decompiled_code:
double __fastcall func7(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


initializeNetwork

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

*(double *)&w_hid0inp0 = (double)rand() / 2147483647.0;
*(double *)&w_hid0inp1 = (double)rand() / 2147483647.0;
*(double *)&w_hid1inp0 = (double)rand() / 2147483647.0;
*(double *)&w_hid1inp1 = (double)rand() / 2147483647.0;
*(double *)&w_outh0 = (double)rand() / 2147483647.0;
*(double *)&w_outh1 = (double)rand() / 2147483647.0;
*(double *)&h0_bias = (double)rand() / 2147483647.0;
*(double *)&h1_bias = (double)rand() / 2147483647.0;
result = rand();
*(double *)&out_bias = (double)result / 2147483647.0;
return result;
}


feedforward

decompiled_code:
void feedforward()
{
hid_0 = sigmoid(
*(double *)&inp_0 * *(double *)&w_hid0inp0
+ *(double *)&inp_1 * *(double *)&w_hid0inp1
+ *(double *)&h0_bias);
hid_1 = sigmoid(
*(double *)&inp_0 * *(double *)&w_hid1inp0
+ *(double *)&inp_1 * *(double *)&w_hid1inp1
+ *(double *)&h1_bias);
out = sigmoid(*(double *)&hid_0 * *(double *)&w_outh0 + *(double *)&hid_1 * *(double *)&w_outh1 + *(double *)&out_bias);
}

canonical_decompiled_code:
void func10()
{
hid_0 = func7(
*(double *)&inp_0 * *(double *)&w_hid0inp0
+ *(double *)&inp_1 * *(double *)&w_hid0inp1
+ *(double *)&h0_bias);
hid_1 = func7(
*(double *)&inp_0 * *(double *)&w_hid1inp0
+ *(double *)&inp_1 * *(double *)&w_hid1inp1
+ *(double *)&h1_bias);
out = func7(*(double *)&hid_0 * *(double *)&w_outh0 + *(double *)&hid_1 * *(double *)&w_outh1 + *(double *)&out_bias);
}

original_code:
void feedforward( void )
{
  hid_0 = sigmoid( (inp_0 * w_hid0inp0) + (inp_1 * w_hid0inp1) + h0_bias );
  hid_1 = sigmoid( (inp_0 * w_hid1inp0) + (inp_1 * w_hid1inp1) + h1_bias );
  out = sigmoid(((hid_0 * w_outh0) + (hid_1 * w_outh1) + out_bias));
  return;
}

canonical_original_code:
void feedforward()
{
  hid_0 = sigmoid( (inp_0 * w_hid0inp0) + (inp_1 * w_hid0inp1) + h0_bias );
  hid_1 = sigmoid( (inp_0 * w_hid1inp0) + (inp_1 * w_hid1inp1) + h1_bias );
  out = sigmoid(((hid_0 * w_outh0) + (hid_1 * w_outh1) + out_bias));
  return;
}