original_code:
void md5model_end(struct md5model *model) {
 int i;
 for(i=0; i<model->num.joints; i++) {
 }
 for(i=0; i<model->num.meshes; i++) {
  struct md5mesh *mesh = &model->meshes[i];
  free(mesh->verts);
  free(mesh->tris);
  free(mesh->weights);
 }
 free(model->meshes);
 free(model->base);
 free(model->jinfo);
}

variable_types: struct md5model { struct { int joints; } num; struct md5joint { struct v3_t { float x; } pos; struct quat_t { float x; } ori; } *base; struct md5jinfo { char *name; int parent; } *jinfo; struct md5mesh { struct { int verts; } num; struct md5vertex { struct v3_t pos; struct v2_t { float x; } st; int start; int count; } *verts; struct md5tri { int idx[3]; } *tris; struct md5weight { struct v3_t pos; int joint; float bias; } *weights; char *shader; } *meshes; } *

variable_types: i int

variable_types: struct md5mesh { struct { int verts; } num; struct md5vertex { struct v3_t { float x; } pos; struct v2_t { float x; } st; int start; int count; } *verts; struct md5tri { int idx[3]; } *tris; struct md5weight { struct v3_t pos; int joint; float bias; } *weights; char *shader; } *

user_defined_types: struct md5model { struct { int joints; } num; struct md5joint *base; struct md5jinfo *jinfo; struct md5mesh *meshes; }

user_defined_types: struct md5mesh { struct { int verts; } num; struct md5vertex *verts; struct md5tri *tris; struct md5weight *weights; char *shader; }

user_defined_types: struct md5joint { struct v3_t pos; struct quat_t ori; }

user_defined_types: struct md5vertex { struct v3_t pos; struct v2_t st; int start; int count; }


original_code:
void md5model_mkmesh(struct md5mesh *mesh, struct md5joint *skel)
{
 int j, k;
 for (j=0; j<mesh->num.verts; j++) {
  v3_make(&mesh->verts[j].pos, 0, 0, 0);
  const struct md5vertex *vertex = &mesh->verts[j];
  for (k=vertex->start; k<vertex->start + vertex->count; k++) {
   v3_t wv;
   const struct md5weight *weight = &mesh->weights[k];
   const struct md5joint *joint = &skel[weight->joint];
   quat_rotatep(&wv, &joint->ori, &weight->pos);
   mesh->verts[j].pos.x += (joint->pos.x + wv.x) * weight->bias;
   mesh->verts[j].pos.y += (joint->pos.y + wv.y) * weight->bias;
   mesh->verts[j].pos.z += (joint->pos.z + wv.z) * weight->bias;
  }
 }
}

canonical_original_code:
void md5model_mkmesh(struct md5mesh *mesh, struct md5joint *skel)
{
 int j; int k;
 for (j=0; j<mesh->num.verts; j++) {
  v3_make(&mesh->verts[j].pos, 0, 0, 0);
  struct md5vertex *vertex = &mesh->verts[j];
  for (k=vertex->start; k<vertex->start + vertex->count; k++) {
   struct v3_t wv;
   struct md5weight *weight = &mesh->weights[k];
   struct md5joint *joint = &skel[weight->joint];
   quat_rotatep(&wv, &joint->ori, &weight->pos);
   mesh->verts[j].pos.x += (joint->pos.x + wv.x) * weight->bias;
   mesh->verts[j].pos.y += (joint->pos.y + wv.y) * weight->bias;
   mesh->verts[j].pos.z += (joint->pos.z + wv.z) * weight->bias;
  }
 }
}

variable_types: struct md5joint { struct v3_t pos; struct quat_t { float x; } ori; } *

variable_types: j int

variable_types: k int

variable_types: struct md5vertex { struct v3_t { float x; } pos; struct v2_t { float x; } st; int start; int count; } *

variable_types:
wv
struct v3_t { float x; }

variable_types: struct md5weight { struct v3_t { float x; } pos; int joint; float bias; } *

variable_types: struct md5joint { struct v3_t { float x; } pos; struct quat_t { float x; } ori; } *

return_type: void

user_defined_types: struct md5weight { struct v3_t pos; int joint; float bias; }


decompiled_code:
float *__fastcall v3_fill(float *a1, float a2, float a3, float a4)
{
float *result; // rax

result = a1;
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
return result;
}

canonical_decompiled_code:
float *__fastcall func0(float *a1, float a2, float a3, float a4)
{
float *result; // rax

result = a1;
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
return result;
}

original_code:
static v3_t *v3_fill(v3_t *u, fp_t x, fp_t y, fp_t z) {
 u->x = x;
 u->y = y;
 u->z = z;
 return u;
}

canonical_original_code:
static struct v3_t *v3_fill(struct v3_t *u, float x, float y, float z) {
 u->x = x;
 u->y = y;
 u->z = z;
 return u;
}

variable_types:
u
struct v3_t *

variable_types: x float

variable_types: y float

variable_types: z float

return_type: struct v3_t { float x; } *


decompiled_code:
// attributes: thunk
float *__fastcall v3_make(float *a1, float a2, float a3, float a4)
{
return v3_fill(a1, a2, a3, a4);
}

canonical_decompiled_code:
float *__fastcall func1(float *a1, float a2, float a3, float a4)
{
return func0(a1, a2, a3, a4);
}

original_code:
v3_t *v3_make(v3_t *u, fp_t x, fp_t y, fp_t z) {
 return v3_fill(u, x, y, z);
}

canonical_original_code:
struct v3_t *v3_make(struct v3_t *u, float x, float y, float z) {
 return v3_fill(u, x, y, z);
}


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

result = a1;
*a1 = *a2 ^ LC0;
a1[1] = a2[1] ^ LC0;
a1[2] = a2[2] ^ LC0;
return result;
}

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

result = a1;
*a1 = *a2 ^ LC0;
a1[1] = a2[1] ^ LC0;
a1[2] = a2[2] ^ LC0;
return result;
}

original_code:
v3_t *v3_minus(v3_t *r, const v3_t *u) {
 r->x = - u->x;
 r->y = - u->y;
 r->z = - u->z;
 return r;
}

canonical_original_code:
struct v3_t *v3_minus(struct v3_t *r, struct v3_t *u) {
 r->x = - u->x;
 r->y = - u->y;
 r->z = - u->z;
 return r;
}

variable_types:
r
struct v3_t *


decompiled_code:
float *__fastcall v3_scale(float *a1, float *a2, float a3)
{
float *result; // rax

result = a1;
*a1 = *a2 / a3;
a1[1] = a2[1] / a3;
a1[2] = a2[2] / a3;
return result;
}

canonical_decompiled_code:
float *__fastcall func3(float *a1, float *a2, float a3)
{
float *result; // rax

result = a1;
*a1 = *a2 / a3;
a1[1] = a2[1] / a3;
a1[2] = a2[2] / a3;
return result;
}

original_code:
v3_t *v3_scale(v3_t *r, const v3_t *u, fp_t k) {
 r->x = u->x / k;
 r->y = u->y / k;
 r->z = u->z / k;
 return r;
}

canonical_original_code:
struct v3_t *v3_scale(struct v3_t *r, struct v3_t *u, float k) {
 r->x = u->x / k;
 r->y = u->y / k;
 r->z = u->z / k;
 return r;
}

variable_types: k float


decompiled_code:
float *__fastcall v3_add(float *a1, float *a2, float *a3)
{
float *result; // rax

result = a1;
*a1 = *a2 + *a3;
a1[1] = a2[1] + a3[1];
a1[2] = a2[2] + a3[2];
return result;
}

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

result = a1;
*a1 = *a2 + *a3;
a1[1] = a2[1] + a3[1];
a1[2] = a2[2] + a3[2];
return result;
}

original_code:
v3_t *v3_add(v3_t *r, const v3_t *u, const v3_t *v) {
 r->x = u->x + v->x;
 r->y = u->y + v->y;
 r->z = u->z + v->z;
 return r;
}

canonical_original_code:
struct v3_t *v3_add(struct v3_t *r, struct v3_t *u, struct v3_t *v) {
 r->x = u->x + v->x;
 r->y = u->y + v->y;
 r->z = u->z + v->z;
 return r;
}

variable_types:
v
struct v3_t *


decompiled_code:
float *__fastcall v3_sub(float *a1, float *a2, float *a3)
{
float *result; // rax

result = a1;
*a1 = *a2 - *a3;
a1[1] = a2[1] - a3[1];
a1[2] = a2[2] - a3[2];
return result;
}

canonical_decompiled_code:
float *__fastcall func5(float *a1, float *a2, float *a3)
{
float *result; // rax

result = a1;
*a1 = *a2 - *a3;
a1[1] = a2[1] - a3[1];
a1[2] = a2[2] - a3[2];
return result;
}

original_code:
v3_t *v3_sub(v3_t *r, const v3_t *u, const v3_t *v) {
 r->x = u->x - v->x;
 r->y = u->y - v->y;
 r->z = u->z - v->z;
 return r;
}

canonical_original_code:
struct v3_t *v3_sub(struct v3_t *r, struct v3_t *u, struct v3_t *v) {
 r->x = u->x - v->x;
 r->y = u->y - v->y;
 r->z = u->z - v->z;
 return r;
}


decompiled_code:
float *__fastcall v3_cross(float *a1, float *a2, float *a3)
{
float *result; // rax
float v4; // xmm2_4
float v5; // xmm1_4
float v6; // xmm3_4
float v7; // xmm0_4
float v8; // xmm6_4
float v9; // xmm5_4

result = a1;
v4 = a2[1];
v5 = a3[2];
v6 = a2[2];
v7 = a3[1];
v8 = *a2;
v9 = *a3;
*a1 = (float)(v4 * v5) - (float)(v6 * v7);
a1[1] = (float)(v5 * v8) - (float)(v6 * v9);
a1[2] = (float)(v7 * v8) - (float)(v4 * v9);
return result;
}

canonical_decompiled_code:
float *__fastcall func6(float *a1, float *a2, float *a3)
{
float *result; // rax
float v4; // xmm2_4
float v5; // xmm1_4
float v6; // xmm3_4
float v7; // xmm0_4
float v8; // xmm6_4
float v9; // xmm5_4

result = a1;
v4 = a2[1];
v5 = a3[2];
v6 = a2[2];
v7 = a3[1];
v8 = *a2;
v9 = *a3;
*a1 = (float)(v4 * v5) - (float)(v6 * v7);
a1[1] = (float)(v5 * v8) - (float)(v6 * v9);
a1[2] = (float)(v7 * v8) - (float)(v4 * v9);
return result;
}

original_code:
v3_t *v3_cross(v3_t *r, const v3_t *u, const v3_t *v) {
 v3_t tmp;
 tmp.x = u->y*v->z - u->z*v->y;
 tmp.y = u->x*v->z - u->z*v->x;
 tmp.z = u->x*v->y - u->y*v->x;
 *r = tmp;
 return r;
}

canonical_original_code:
struct v3_t *v3_cross(struct v3_t *r, struct v3_t *u, struct v3_t *v) {
 struct v3_t tmp;
 tmp.x = u->y*v->z - u->z*v->y;
 tmp.y = u->x*v->z - u->z*v->x;
 tmp.z = u->x*v->y - u->y*v->x;
 *r = tmp;
 return r;
}

variable_types:
tmp
struct v3_t { float x; }


decompiled_code:
float __fastcall v3_dot(float *a1, float *a2)
{
return (float)((float)(*a1 * *a2) + (float)(a1[1] * a2[1])) + (float)(a1[2] * a2[2]);
}

canonical_decompiled_code:
float __fastcall func7(float *a1, float *a2)
{
return (float)((float)(*a1 * *a2) + (float)(a1[1] * a2[1])) + (float)(a1[2] * a2[2]);
}

original_code:
fp_t v3_dot(const v3_t *u, const v3_t *v) {
 return u->x * v->x + u->y * v->y + u->z * v->z;
}

canonical_original_code:
float v3_dot(struct v3_t *u, struct v3_t *v) {
 return u->x * v->x + u->y * v->y + u->z * v->z;
}

variable_types:
u
struct v3_t { float x; } *

return_type: float


decompiled_code:
float *__fastcall v3_project(float *a1, float *a2, float *a3)
{
float v4; // xmm1_4
float v6; // [rsp+4h] [rbp-14h]

v6 = v3_dot(a2, a3);
v4 = v3_dot(a3, a3);
return v3_scale(a1, a3, v6 / v4);
}

canonical_decompiled_code:
float *__fastcall func8(float *a1, float *a2, float *a3)
{
float v4; // xmm1_4
float v6; // [rsp+4h] [rbp-14h]

v6 = func7(a2, a3);
v4 = func7(a3, a3);
return func3(a1, a3, v6 / v4);
}

original_code:
v3_t *v3_project(v3_t *r, const v3_t *u, const v3_t *v) {
 return v3_scale(r, v, v3_dot(u, v) / v3_dot(v, v));
}

canonical_original_code:
struct v3_t *v3_project(struct v3_t *r, struct v3_t *u, struct v3_t *v) {
 return v3_scale(r, v, v3_dot(u, v) / v3_dot(v, v));
}


decompiled_code:
float __fastcall v3_norm(float *a1)
{
float v1; // xmm0_4
float result; // xmm0_4

v1 = v3_dot(a1, a1);
if ( v1 < 0.0 )
result = sqrtf(v1);
else
result = fsqrt(v1);
return result;
}

canonical_decompiled_code:
float __fastcall func9(float *a1)
{
float v1; // xmm0_4
float result; // xmm0_4

v1 = func7(a1, a1);
if ( v1 < 0.0 )
result = sqrtf(v1);
else
result = fsqrt(v1);
return result;
}

original_code:
fp_t v3_norm(const v3_t *u) {
 return sqrt(v3_dot(u, u));
}

canonical_original_code:
float v3_norm(struct v3_t *u) {
 return sqrt(v3_dot(u, u));
}


decompiled_code:
float *__fastcall v3_normalize(float *a1, float *a2)
{
float v2; // xmm0_4

v2 = v3_norm(a2);
*a1 = *a2 / v2;
a1[1] = a2[1] / v2;
a1[2] = a2[2] / v2;
return a1;
}

original_code:
v3_t *v3_normalize(v3_t *r, const v3_t *q) {
 fp_t normal = v3_norm(q);
 r->x = q->x / normal;
 r->y = q->y / normal;
 r->z = q->z / normal;
 return r;
}

canonical_original_code:
struct v3_t *v3_normalize(struct v3_t *r, struct v3_t *q) {
 float normal = v3_norm(q);
 r->x = q->x / normal;
 r->y = q->y / normal;
 r->z = q->z / normal;
 return r;
}

variable_types:
q
struct v3_t *

variable_types: normal float


decompiled_code:
__int64 __fastcall cels_convert_to_fahr(int a1)
{
return (unsigned int)(int)((double)a1 * 1.8 + 32.0);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned int)(int)((double)a1 * 1.8 + 32.0);
}

original_code:
int cels_convert_to_fahr( int celsius )
{
    int fahr = 0;
    fahr = ( 9.0 / 5.0 ) * celsius + 32.0;
    return fahr;
}

canonical_original_code:
int cels_convert_to_fahr(int celsius)
{
    int fahr = 0;
    fahr = ( 9.0 / 5.0 ) * celsius + 32.0;
    return fahr;
}

variable_types: celsius int

variable_types: fahr int

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
float v6; // [rsp+Ch] [rbp-Ch]

printf("%3s\t%7s\n", "celsius", "fahr");
v3 = 16;
v6 = 0.0;
do
{
v4 = cels_convert_to_fahr((int)v6);
printf("%3.0f\t%6.1f\n", v6, (float)v4);
v6 = v6 + 20.0;
--v3;
}
while ( v3 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
float v6; // [rsp+Ch] [rbp-Ch]

printf("%3s\t%7s\n", "celsius", "fahr");
v3 = 16;
v6 = 0.0;
do
{
v4 = func0((int)v6);
printf("%3.0f\t%6.1f\n", v6, (float)v4);
v6 = v6 + 20.0;
--v3;
}
while ( v3 );
return 0;
}

original_code:
int main( void )
{
    float celsius = 0;
    float fahr = 0;
    int upper = 300;
    int lower = 0;
    int step = 20;
    printf("%3s\t%7s\n", "celsius", "fahr" );
    for ( celsius = lower ; celsius <= upper ; celsius += step )
    {
        fahr = cels_convert_to_fahr(celsius);
        printf( "%3.0f\t%6.1f\n", celsius, fahr );
    }
    return 0;
}

canonical_original_code:
int main()
{
    float celsius = 0;
    float fahr = 0;
    int upper = 300;
    int lower = 0;
    int step = 20;
    printf("%3s\t%7s\n", "celsius", "fahr" );
    for ( celsius = lower ; celsius <= upper ; celsius += step )
    {
        fahr = cels_convert_to_fahr(celsius);
        printf( "%3.0f\t%6.1f\n", celsius, fahr );
    }
    return 0;
}

variable_types: celsius float

variable_types: fahr float

variable_types: upper int

variable_types: lower int

variable_types: step int


decompiled_code:
__int64 __fastcall horizontal_bars(int *a1, int a2)
{
int v3; // er13
int v4; // ebx

puts("\n=== horizontal_bars!!===");
if ( a2 > 0 )
{
v3 = 0;
do
{
printf("|%2d| ", (unsigned int)++v3);
if ( *a1 > 0 )
{
v4 = 0;
do
{
putchar(42);
++v4;
}
while ( *a1 > v4 );
}
putchar(10);
++a1;
}
while ( v3 != a2 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int a2)
{
int v3; // er13
int v4; // ebx

puts("\n=== horizontal_bars!!===");
if ( a2 > 0 )
{
v3 = 0;
do
{
printf("|%2d| ", (unsigned int)++v3);
if ( *a1 > 0 )
{
v4 = 0;
do
{
putchar(42);
++v4;
}
while ( *a1 > v4 );
}
putchar(10);
++a1;
}
while ( v3 != a2 );
}
return 0LL;
}

original_code:
int horizontal_bars ( int buffer[] ,int word_id )
{
    int i = 0;
    int j = 0;
    printf("\n=== horizontal_bars!!===\n");
    for ( i=0 ; i<word_id ; i++ ) {
        printf("|%2d| ",i+1);
        for ( j=0 ; j<buffer[i]; j++ ) {
            putchar('*');
        }
        putchar('\n');
    }
    return 0;
}

canonical_original_code:
int horizontal_bars(int buffer[], int word_id)
{
    int i = 0;
    int j = 0;
    printf("\n=== horizontal_bars!!===\n");
    for ( i=0 ; i<word_id ; i++ ) {
        printf("|%2d| ",i+1);
        for ( j=0 ; j<buffer[i]; j++ ) {
            putchar('*');
        }
        putchar('\n');
    }
    return 0;
}

variable_types:
buffer
int []

variable_types: i int

variable_types: j int


original_code:
int vertical_bars( int buffer[] ,int word_id )
{
    printf("\n===vertical_bars!!===\n");
    int i = 0;
    int j = 0;
    int max = 0;
    printf("|%2c|", ' ');
    for ( i=0 ; i<word_id ; i++ ) {
        printf("%2d|", i+1);
        max = (buffer[i]>max) ? buffer[i]:max;
    }
    putchar('\n');
    printf("|%2c|", ' ');
    for ( i=0 ; i<word_id ; i++ ) {
        printf("%2c|", '_');
    }
    putchar('\n');
    for ( i=max-1 ; i>=0; i-- ) {
        printf("|%2d|", i+1);
        for ( j=0 ; j<word_id ; j++ ) {
            printf("%2c|", i < buffer[j] ? '*' : ' ');
        }
        putchar('\n');
    }
    return 0;
}

canonical_original_code:
int vertical_bars(int buffer[], int word_id)
{
    printf("\n===vertical_bars!!===\n");
    int i = 0;
    int j = 0;
    int max = 0;
    printf("|%2c|", ' ');
    for ( i=0 ; i<word_id ; i++ ) {
        printf("%2d|", i+1);
        max = (buffer[i]>max) ? buffer[i]:max;
    }
    putchar('\n');
    printf("|%2c|", ' ');
    for ( i=0 ; i<word_id ; i++ ) {
        printf("%2c|", '_');
    }
    putchar('\n');
    for ( i=max-1 ; i>=0; i-- ) {
        printf("|%2d|", i+1);
        for ( j=0 ; j<word_id ; j++ ) {
            printf("%2c|", i < buffer[j] ? '*' : ' ');
        }
        putchar('\n');
    }
    return 0;
}

variable_types: max int


decompiled_code:
int __fastcall num_to_repeat_char(int a1, char a2)
{
int i; // ebx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = putchar(a2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, char a2)
{
int i; // ebx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = putchar(a2);
}
return result;
}

original_code:
void num_to_repeat_char ( int num, char symbol )
{
    int i = 0;
    for( i=0 ; i<num ; i++ ) {
        printf("%c",symbol);
    }
}

canonical_original_code:
void num_to_repeat_char(int num, char symbol)
{
    int i = 0;
    for( i=0 ; i<num ; i++ ) {
        printf("%c",symbol);
    }
}

variable_types: num int

variable_types: symbol char


rateN

original_code:
void rateN(int g, int n, double R[n][g], double R_i[], double W[g][g], double gamma[], double tau[], double dt)
{
 int t,i,j,l;
 double s;
 for (i=0; i<g; i++){
  R[0][i] = R_i[i];
 }
 for (t=1; t<=n; t++){
  l = t-1;
  for (i=0; i<g; i++){
   s = 0;
   for (j=0; j<g; j++){
    s += W[j][i]*R[l][j];
   }
   R[t][i]=R[l][i]+dt/tau[i]*(-R[l][i]+(0 > s+gamma[i] ? 0 : s+gamma[i]));
  }
 }
}

canonical_original_code:
void rateN(int g, int n, double R[-1][-1], double R_i[], double W[-1][-1], double gamma[], double tau[], double dt)
{
 int t; int i; int j; int l;
 double s;
 for (i=0; i<g; i++){
  R[0][i] = R_i[i];
 }
 for (t=1; t<=n; t++){
  l = t-1;
  for (i=0; i<g; i++){
   s = 0;
   for (j=0; j<g; j++){
    s += W[j][i]*R[l][j];
   }
   R[t][i]=R[l][i]+dt/tau[i]*(-R[l][i]+(0 > s+gamma[i] ? 0 : s+gamma[i]));
  }
 }
}

variable_types: g int

variable_types: n int

variable_types:
gamma
double []

variable_types:
tau
double []

variable_types: dt double

variable_types: t int

variable_types: l int

variable_types: s double


assignPingW

original_code:
void
assignPingW(int no, double W[2*no][2*no],
            double wee, double wei, double wie, double wii,
            double xee, double xei, double xie, double xii)
{
    int i,j,g=2*no;
    double wW[2][2];
        wW[0][0]=wee; wW[0][1]=wei;
        wW[1][0]=wie; wW[1][1]=wii;
    double xW[2][2];
        xW[0][0]=xee; xW[0][1]=xei;
        xW[1][0]=xie; xW[1][1]=xii;
    for (i=0; i<g; i++){
        for (j=0; j<g; j++){
            if ( i/2 == j/2 ){
                W[i][j] = wW[i%2][j%2];
            } else {
                W[i][j] = xW[i%2][j%2];
            }
        }
    }
}

canonical_original_code:
void assignPingW(int no, double W[-1][-1], double wee, double wei, double wie, double wii, double xee, double xei, double xie, double xii)
{
    int i; int j; int g = 2*no;
    double wW[2][2];
        wW[0][0]=wee; wW[0][1]=wei;
        wW[1][0]=wie; wW[1][1]=wii;
    double xW[2][2];
        xW[0][0]=xee; xW[0][1]=xei;
        xW[1][0]=xie; xW[1][1]=xii;
    for (i=0; i<g; i++){
        for (j=0; j<g; j++){
            if ( i/2 == j/2 ){
                W[i][j] = wW[i%2][j%2];
            } else {
                W[i][j] = xW[i%2][j%2];
            }
        }
    }
}

variable_types: no int

variable_types: wee double

variable_types: wei double

variable_types: wie double

variable_types: wii double

variable_types: xee double

variable_types: xei double

variable_types: xie double

variable_types: xii double

variable_types:
wW
double [2][2]

variable_types:
xW
double [2][2]


rateSTDP

original_code:
void
rateSTDP(int n, int g, double dt, double R[n][g],
            double W[][g][g], double W_0[g][g], int W_c[g][g])
{
    int t,i,l;
    int tau, ga, gb;
    double sum;
    int wid = 100e-3/dt;
    int step = 10;
    double tau_w = 10;
    double A_n = -.51;
    double A_p = 1.03;
    double tau_n = 0.036;
    double tau_p = 0.014;
    double tau_d = 2e-3;
    double tau_pot = 1e-3;
    int ne_start = wid-tau_d/dt;
    int ne_end = wid + tau_pot/dt;
    int ne_diff = ne_end-ne_start;
    double kernel[2*wid+1];
    for (tau=0; tau<=wid; tau++){
        kernel[tau] = A_n*exp((-0.1+tau*dt)/tau_n);
    }
    for (tau=wid; tau<=2*wid; tau++){
        kernel[tau] = A_p*exp(-dt*(tau-wid)/tau_p);
    }
    for (tau=ne_start; tau<ne_end; tau++){
        kernel[tau] = kernel[ne_start]+(kernel[ne_end]-kernel[ne_start])*(tau-ne_start)/ne_diff;
    }
    for (ga=0; ga<g; ga++){
        for (gb=0; gb<g; gb++){
            W[0][ga][gb] = W_0[ga][gb];
        }
    }
    for (t=step; t<n; t+=step){
      i = t/step;
      l = i-1;
      for (ga=0; ga<g; ga++){ for (gb=0; gb<g; gb++){
        if ( t-wid < 0 || t+wid >= n ){
          W[i][ga][gb] = W[l][ga][gb];
        } else {
          if ( W_c[ga][gb] ){
            sum = 0;
            for (tau=0; tau<=wid; tau++){
                sum += kernel[tau]*R[t][ga]*R[t+tau-wid][gb]*dt;
            }
            for (tau=0; tau<=wid; tau++){
                sum += kernel[tau+wid]*R[t][gb]*R[t-tau][ga]*dt;
            }
            W[i][ga][gb] = W[l][ga][gb] + sum*dt/tau_w;
          } else {
            W[i][ga][gb] = W[l][ga][gb];
          }
        }
      }}
    }
}

canonical_original_code:
void rateSTDP(int n, int g, double dt, double R[-1][-1], double W[][-1][-1], double W_0[-1][-1], int W_c[-1][-1])
{
    int t; int i; int l;
    int tau; int ga; int gb;
    double sum;
    int wid = 100e-3/dt;
    int step = 10;
    double tau_w = 10;
    double A_n = -.51;
    double A_p = 1.03;
    double tau_n = 0.036;
    double tau_p = 0.014;
    double tau_d = 2e-3;
    double tau_pot = 1e-3;
    int ne_start = wid-tau_d/dt;
    int ne_end = wid + tau_pot/dt;
    int ne_diff = ne_end-ne_start;
    double kernel[-1];
    for (tau=0; tau<=wid; tau++){
        kernel[tau] = A_n*exp((-0.1+tau*dt)/tau_n);
    }
    for (tau=wid; tau<=2*wid; tau++){
        kernel[tau] = A_p*exp(-dt*(tau-wid)/tau_p);
    }
    for (tau=ne_start; tau<ne_end; tau++){
        kernel[tau] = kernel[ne_start]+(kernel[ne_end]-kernel[ne_start])*(tau-ne_start)/ne_diff;
    }
    for (ga=0; ga<g; ga++){
        for (gb=0; gb<g; gb++){
            W[0][ga][gb] = W_0[ga][gb];
        }
    }
    for (t=step; t<n; t+=step){
      i = t/step;
      l = i-1;
      for (ga=0; ga<g; ga++){ for (gb=0; gb<g; gb++){
        if ( t-wid < 0 || t+wid >= n ){
          W[i][ga][gb] = W[l][ga][gb];
        } else {
          if ( W_c[ga][gb] ){
            sum = 0;
            for (tau=0; tau<=wid; tau++){
                sum += kernel[tau]*R[t][ga]*R[t+tau-wid][gb]*dt;
            }
            for (tau=0; tau<=wid; tau++){
                sum += kernel[tau+wid]*R[t][gb]*R[t-tau][ga]*dt;
            }
            W[i][ga][gb] = W[l][ga][gb] + sum*dt/tau_w;
          } else {
            W[i][ga][gb] = W[l][ga][gb];
          }
        }
      }}
    }
}

variable_types: n int

variable_types: g int

variable_types: i int

variable_types: tau int

variable_types: ga int

variable_types: gb int

variable_types: sum double

variable_types: wid int

variable_types: step int

variable_types:
kernel
double [-1]


original_code:
void
*Learned_Synchrony_worker(void *arg)
{
    THREAD_DAT_1D * in = arg;
    printf("Starting thread %d...\n", in->id);
    int n=9999, no=2;
    double dt=0.0001;
    int i,j;
    int res = in->res;
    double wW[2][2];
        wW[0][0]=2; wW[0][1]=2.873;
        wW[1][0]=-2.873; wW[1][1]=-2;
    double ei=0.3, ie=-0.5, ii=0;
    double ee=in->DATA_IN[0];
    int p=1000;
    double lp_rates[p][2];
    get_last_period(&p, lp_rates, wW);
    double Re[n][no];
    double R_i[no][2];
    double pds[no][no];
    int numtrials = 300;
    double thesum;
    for (i=in->a; i<in->b; i++){
        R_i[0][0] = lp_rates[0][0];
        R_i[0][1] = lp_rates[0][1];
        R_i[1][0] = lp_rates[i*p/res][0];
        R_i[1][1] = lp_rates[i*p/res][1];
        thesum = 0;
        for (j=0; j<numtrials; j++){
            pingRateN(n,no,Re,R_i,ee,ei,ie,ii,wW,dt);
            phdiff2(n, no, Re, pds);
            thesum += pds[0][1];
        }
        in->DATA[i] = thesum/numtrials;
    }
}

canonical_original_code:
void *Learned_Synchrony_worker(void *arg)
{
    struct THREAD_DAT_1D *in = arg;
    printf("Starting thread %d...\n", in->id);
    int n = 9999; int no = 2;
    double dt = 0.0001;
    int i; int j;
    int res = in->res;
    double wW[2][2];
        wW[0][0]=2; wW[0][1]=2.873;
        wW[1][0]=-2.873; wW[1][1]=-2;
    double ei = 0.3; double ie = -0.5; double ii = 0;
    double ee = in->DATA_IN[0];
    int p = 1000;
    double lp_rates[-1][2];
    get_last_period(&p, lp_rates, wW);
    double Re[-1][-1];
    double R_i[-1][2];
    double pds[-1][-1];
    int numtrials = 300;
    double thesum;
    for (i=in->a; i<in->b; i++){
        R_i[0][0] = lp_rates[0][0];
        R_i[0][1] = lp_rates[0][1];
        R_i[1][0] = lp_rates[i*p/res][0];
        R_i[1][1] = lp_rates[i*p/res][1];
        thesum = 0;
        for (j=0; j<numtrials; j++){
            pingRateN(n,no,Re,R_i,ee,ei,ie,ii,wW,dt);
            phdiff2(n, no, Re, pds);
            thesum += pds[0][1];
        }
        in->DATA[i] = thesum/numtrials;
    }
}

variable_types:
arg
void *

variable_types: struct THREAD_DAT_1D { int id; int a; int b; int res; double *DATA; double *DATA_IN; } *

variable_types: no int

variable_types: dt double

variable_types: j int

variable_types: res int

variable_types: ei double

variable_types: ie double

variable_types: ii double

variable_types: ee double

variable_types: p int

variable_types:
Re
double [-1][-1]

variable_types:
pds
double [-1][-1]

variable_types: numtrials int

variable_types: thesum double

return_type: void *


decompiled_code:
unsigned __int64 __fastcall plasticPingRateN_recW(int a1, int a2, __int64 a3, __int64 a4, int a5, int a6, double a7, double a8, double a9, double a10, double a11, int a12, int a13, _QWORD *a14, __int64 a15)
{
int v15; // er13
int v16; // er15
void *v17; // rsp
_BYTE *v18; // rbx
void *v19; // rsp
__int64 v20; // r12
int v21; // eax
double v22; // xmm0_8
double v23; // xmm1_8
_BYTE *v24; // rbx
int v25; // eax
double v26; // xmm0_8
int v27; // eax
double v28; // xmm0_8
double v29; // rbx
int v30; // eax
double v31; // xmm0_8
int v32; // er13
__int64 v33; // rbx
_BYTE *v34; // rax
__int64 v35; // rcx
_BYTE *v36; // rax
__int64 v37; // rdx
_BYTE *v38; // rcx
int v39; // edi
__int64 v40; // rsi
_QWORD *v41; // rax
void *v42; // rsp
void *v43; // rsp
_BYTE *v44; // rdx
int v45; // ecx
_QWORD *v46; // rax
__int64 v47; // r8
void *v48; // rsp
_BYTE *v49; // rdx
int v50; // ecx
_DWORD *v51; // rax
__int64 v52; // r9
__int64 v53; // xmm3_8
__int64 v54; // xmm4_8
__int64 v55; // xmm5_8
__int64 v56; // xmm6_8
int v57; // er13
int v58; // er12
__int64 *v59; // rsi
__int64 v60; // r8
int v61; // ecx
_DWORD *v62; // rax
signed __int64 v63; // rdx
unsigned __int64 result; // rax
unsigned __int64 v65; // r9
__int64 v66; // rdx
int v67; // er10
__int64 v68; // r8
int v69; // er11
int v70; // ecx
_QWORD *v71; // rsi
signed __int64 v72; // rax
void *v73; // rsp
void *v74; // rsp
signed __int64 v75; // rax
void *v76; // rsp
void *v77; // rsp
void *v78; // rsp
void *v79; // rsp
_BYTE v80[4]; // [rsp+0h] [rbp-100h] BYREF
int v81; // [rsp+4h] [rbp-FCh]
_BYTE *v82; // [rsp+8h] [rbp-F8h] BYREF
__int64 v83; // [rsp+10h] [rbp-F0h]
__int64 v84; // [rsp+18h] [rbp-E8h]
_BYTE *v85; // [rsp+20h] [rbp-E0h]
double v86; // [rsp+28h] [rbp-D8h]
int v87; // [rsp+30h] [rbp-D0h]
unsigned int v88; // [rsp+34h] [rbp-CCh]
_BYTE *v89; // [rsp+38h] [rbp-C8h]
_BYTE *v90; // [rsp+40h] [rbp-C0h]
_BYTE *v91; // [rsp+48h] [rbp-B8h]
_BYTE **v92; // [rsp+50h] [rbp-B0h]
__int64 v93; // [rsp+58h] [rbp-A8h]
unsigned __int64 v94; // [rsp+60h] [rbp-A0h]
unsigned __int64 v95; // [rsp+68h] [rbp-98h]
unsigned __int64 v96; // [rsp+70h] [rbp-90h]
__int64 v97; // [rsp+78h] [rbp-88h]
__int64 v98; // [rsp+80h] [rbp-80h]
__int64 v99; // [rsp+88h] [rbp-78h]
__int64 v100; // [rsp+90h] [rbp-70h]
__int64 v101; // [rsp+98h] [rbp-68h]
unsigned __int64 v102; // [rsp+A0h] [rbp-60h]
signed __int64 v103; // [rsp+A8h] [rbp-58h]
_BYTE *v104; // [rsp+B0h] [rbp-50h]
unsigned __int64 v105; // [rsp+B8h] [rbp-48h]
double v106; // [rsp+C0h] [rbp-40h]
double v107; // [rsp+C8h] [rbp-38h]

v15 = a1;
v88 = a2;
v83 = a3;
v104 = (_BYTE *)a4;
v100 = *(_QWORD *)&a7;
v99 = *(_QWORD *)&a8;
v98 = *(_QWORD *)&a9;
v97 = *(_QWORD *)&a10;
LODWORD(v82) = a5;
v87 = a6;
v86 = a11;
v84 = a2;
v16 = 2 * a2;
v101 = v16;
v105 = 16LL * a2;
v102 = v16 * (__int64)v16;
v103 = 8 * v102;
v17 = alloca(16 * ((8 * 2 * a2 * (__int64)a1 + 15) / 0x10uLL));
v18 = v80;
v19 = alloca(16 * ((v105 + 15) / 0x10));
v85 = v80;
if ( 2 * a2 <= 0 )
{
v72 = 16 * ((v105 + 15) / 0x10);
v73 = alloca(v72);
v89 = v80;
v74 = alloca(v72);
v90 = v80;
v75 = 16 * ((v103 + 15) / 0x10uLL);
v76 = alloca(v75);
v77 = alloca(v75);
v78 = alloca(v75);
v79 = alloca(16 * ((4 * v102 + 15) / 0x10));
v91 = v80;
}
else
{
LODWORD(v96) = v16 - 1;
v20 = 0LL;
LODWORD(v95) = 2 * a2;
LODWORD(v94) = a1;
v93 = (__int64)v80;
do
{
v24 = &v104[16 * ((int)v20 / 2)];
v107 = *(double *)&v24[8 * ((int)v20 % 2)];
v25 = rand();
v26 = log((double)v25 * 4.656612873077393e-10) * -2.0;
if ( v26 < 0.0 )
v106 = sqrt(v26);
else
v106 = sqrt(v26);
v27 = rand();
v28 = sin((double)v27 * 4.656612873077393e-10 * 6.283185307179586);
v23 = *(double *)&LC0;
if ( v28 * v106 + v107 >= 0.01 )
{
v29 = *(double *)&v24[8 * ((int)v20 % 2)];
v30 = rand();
v31 = log((double)v30 * 4.656612873077393e-10) * -2.0;
if ( v31 < 0.0 )
v107 = sqrt(v31);
else
v107 = sqrt(v31);
v21 = rand();
v22 = sin((double)v21 * 4.656612873077393e-10 * 6.283185307179586);
v23 = v107 * v22 + v29;
}
*(double *)&v80[8 * v20++] = v23;
}
while ( v20 != v16 );
v16 = v95;
v32 = v94;
v33 = v93;
v89 = v80;
v34 = v80;
v35 = 16LL * (((unsigned int)v96 >> 1) + 1);
do
{
*(_QWORD *)v34 = LC5;
*((_QWORD *)v34 + 1) = LC6;
v34 += 16;
}
while ( v34 != &v80[v35] );
v90 = v80;
v36 = v80;
do
{
*(_QWORD *)v36 = LC7;
*((_QWORD *)v36 + 1) = LC0;
v36 += 16;
}
while ( v36 != &v80[v35] );
v96 = v105 >> 3;
v37 = 8LL * (unsigned int)v16;
v38 = &v80[v37];
v39 = 0;
v40 = -8LL * (unsigned int)v16;
do
{
v41 = &v38[v40];
do
*v41++ = 0LL;
while ( v41 != (_QWORD *)v38 );
++v39;
v38 += v105;
}
while ( v16 != v39 );
v42 = alloca(v103);
v43 = alloca(v103);
v44 = &v80[v37];
v45 = 0;
do
{
v46 = &v44[v40];
do
*v46++ = 0LL;
while ( v46 != (_QWORD *)v44 );
++v45;
v44 += v105;
}
while ( v16 != v45 );
v47 = 4 * v101;
v48 = alloca(4 * v102);
v91 = v80;
v95 = (unsigned __int64)(4 * v101) >> 2;
v104 = v80;
v49 = &v80[4 * v16];
v50 = 0;
do
{
v51 = &v49[-4 * v16];
do
*v51++ = 0;
while ( v51 != (_DWORD *)v49 );
++v50;
v49 += v47;
}
while ( v16 != v50 );
v94 = 8 * v95;
v93 = 16 * v96;
v103 = 0LL;
*(_QWORD *)&v106 = 1LL;
v52 = 0LL;
v92 = &(&v82)[v105 / 8];
v102 = v96 + 1;
v81 = v32;
v53 = v100;
v54 = v99;
v55 = v98;
v56 = v97;
v57 = (int)v82;
v58 = v87;
v82 = (_BYTE *)v33;
do
{
v59 = (__int64 *)((char *)v92 + v103);
v60 = v95 * (*(_QWORD *)&v106 - v52);
v100 = v103;
v101 = (__int64)v104;
v61 = 0;
v97 = (int)v52 * v102;
v98 = SLODWORD(v106) + v96 * (int)v52;
v99 = v96 * SLODWORD(v106) + (int)v52;
*(_QWORD *)&v107 = v102 * SLODWORD(v106);
v62 = v104;
v63 = v103;
do
{
if ( v61 == (_DWORD)v52 )
{
*(_QWORD *)&v80[8 * v97] = *a14;
*(_QWORD *)&v80[8 * v98] = a14[1];
*(_QWORD *)&v80[8 * v99] = a14[2];
*(_QWORD *)&v80[8 * *(_QWORD *)&v107] = a14[3];
}
else
{
*(_QWORD *)&v80[v63] = LC8;
*(_QWORD *)&v80[v63] = LC9;
*v62 = v57;
v62[1] = v58;
v62[v60] = a12;
v62[v60 + 1] = a13;
*(_QWORD *)&v80[v63] = v53;
*(_BYTE **)((char *)&v82 + v63) = (_BYTE *)v54;
*(v59 - 1) = v55;
*v59 = v56;
}
v61 += 2;
v62 += 2;
v59 += 2;
v63 += 16LL;
}
while ( v16 > v61 );
v52 += 2LL;
*(_QWORD *)&v106 += 2LL;
v104 += v94;
v103 += v93;
}
while ( v16 > (int)v52 );
v15 = v81;
v18 = v82;
}
plasticRateN_recW(
(unsigned int)v16,
(unsigned int)v15,
v18,
v85,
a15,
v91,
5000.0,
500.0,
v86,
v80,
v80,
v80,
v89,
v90);
result = v88;
if ( (int)v88 > 0 )
{
v65 = v105 >> 3;
v66 = v83;
result = 2 * v88;
v67 = 2 * v88;
v68 = 8 * v84;
v69 = 0;
do
{
v71 = (_QWORD *)v66;
v70 = 0;
if ( v15 > 0 )
{
do
{
result = v69 + v65 * v70;
*v71 = *(_QWORD *)&v18[8 * result];
++v70;
v71 = (_QWORD *)((char *)v71 + v68);
}
while ( v15 != v70 );
}
v66 += 8LL;
v69 += 2;
}
while ( v67 != v69 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(int a1, int a2, __int64 a3, __int64 a4, int a5, int a6, double a7, double a8, double a9, double a10, double a11, int a12, int a13, _QWORD *a14, __int64 a15)
{
int v15; // er13
int v16; // er15
void *v17; // rsp
_BYTE *v18; // rbx
void *v19; // rsp
__int64 v20; // r12
int v21; // eax
double v22; // xmm0_8
double v23; // xmm1_8
_BYTE *v24; // rbx
int v25; // eax
double v26; // xmm0_8
int v27; // eax
double v28; // xmm0_8
double v29; // rbx
int v30; // eax
double v31; // xmm0_8
int v32; // er13
__int64 v33; // rbx
_BYTE *v34; // rax
__int64 v35; // rcx
_BYTE *v36; // rax
__int64 v37; // rdx
_BYTE *v38; // rcx
int v39; // edi
__int64 v40; // rsi
_QWORD *v41; // rax
void *v42; // rsp
void *v43; // rsp
_BYTE *v44; // rdx
int v45; // ecx
_QWORD *v46; // rax
__int64 v47; // r8
void *v48; // rsp
_BYTE *v49; // rdx
int v50; // ecx
_DWORD *v51; // rax
__int64 v52; // r9
__int64 v53; // xmm3_8
__int64 v54; // xmm4_8
__int64 v55; // xmm5_8
__int64 v56; // xmm6_8
int v57; // er13
int v58; // er12
__int64 *v59; // rsi
__int64 v60; // r8
int v61; // ecx
_DWORD *v62; // rax
signed __int64 v63; // rdx
unsigned __int64 result; // rax
unsigned __int64 v65; // r9
__int64 v66; // rdx
int v67; // er10
__int64 v68; // r8
int v69; // er11
int v70; // ecx
_QWORD *v71; // rsi
signed __int64 v72; // rax
void *v73; // rsp
void *v74; // rsp
signed __int64 v75; // rax
void *v76; // rsp
void *v77; // rsp
void *v78; // rsp
void *v79; // rsp
_BYTE v80[4]; // [rsp+0h] [rbp-100h] BYREF
int v81; // [rsp+4h] [rbp-FCh]
_BYTE *v82; // [rsp+8h] [rbp-F8h] BYREF
__int64 v83; // [rsp+10h] [rbp-F0h]
__int64 v84; // [rsp+18h] [rbp-E8h]
_BYTE *v85; // [rsp+20h] [rbp-E0h]
double v86; // [rsp+28h] [rbp-D8h]
int v87; // [rsp+30h] [rbp-D0h]
unsigned int v88; // [rsp+34h] [rbp-CCh]
_BYTE *v89; // [rsp+38h] [rbp-C8h]
_BYTE *v90; // [rsp+40h] [rbp-C0h]
_BYTE *v91; // [rsp+48h] [rbp-B8h]
_BYTE **v92; // [rsp+50h] [rbp-B0h]
__int64 v93; // [rsp+58h] [rbp-A8h]
unsigned __int64 v94; // [rsp+60h] [rbp-A0h]
unsigned __int64 v95; // [rsp+68h] [rbp-98h]
unsigned __int64 v96; // [rsp+70h] [rbp-90h]
__int64 v97; // [rsp+78h] [rbp-88h]
__int64 v98; // [rsp+80h] [rbp-80h]
__int64 v99; // [rsp+88h] [rbp-78h]
__int64 v100; // [rsp+90h] [rbp-70h]
__int64 v101; // [rsp+98h] [rbp-68h]
unsigned __int64 v102; // [rsp+A0h] [rbp-60h]
signed __int64 v103; // [rsp+A8h] [rbp-58h]
_BYTE *v104; // [rsp+B0h] [rbp-50h]
unsigned __int64 v105; // [rsp+B8h] [rbp-48h]
double v106; // [rsp+C0h] [rbp-40h]
double v107; // [rsp+C8h] [rbp-38h]

v15 = a1;
v88 = a2;
v83 = a3;
v104 = (_BYTE *)a4;
v100 = *(_QWORD *)&a7;
v99 = *(_QWORD *)&a8;
v98 = *(_QWORD *)&a9;
v97 = *(_QWORD *)&a10;
LODWORD(v82) = a5;
v87 = a6;
v86 = a11;
v84 = a2;
v16 = 2 * a2;
v101 = v16;
v105 = 16LL * a2;
v102 = v16 * (__int64)v16;
v103 = 8 * v102;
v17 = alloca(16 * ((8 * 2 * a2 * (__int64)a1 + 15) / 0x10uLL));
v18 = v80;
v19 = alloca(16 * ((v105 + 15) / 0x10));
v85 = v80;
if ( 2 * a2 <= 0 )
{
v72 = 16 * ((v105 + 15) / 0x10);
v73 = alloca(v72);
v89 = v80;
v74 = alloca(v72);
v90 = v80;
v75 = 16 * ((v103 + 15) / 0x10uLL);
v76 = alloca(v75);
v77 = alloca(v75);
v78 = alloca(v75);
v79 = alloca(16 * ((4 * v102 + 15) / 0x10));
v91 = v80;
}
else
{
LODWORD(v96) = v16 - 1;
v20 = 0LL;
LODWORD(v95) = 2 * a2;
LODWORD(v94) = a1;
v93 = (__int64)v80;
do
{
v24 = &v104[16 * ((int)v20 / 2)];
v107 = *(double *)&v24[8 * ((int)v20 % 2)];
v25 = rand();
v26 = log((double)v25 * 4.656612873077393e-10) * -2.0;
if ( v26 < 0.0 )
v106 = sqrt(v26);
else
v106 = sqrt(v26);
v27 = rand();
v28 = sin((double)v27 * 4.656612873077393e-10 * 6.283185307179586);
v23 = *(double *)&LC0;
if ( v28 * v106 + v107 >= 0.01 )
{
v29 = *(double *)&v24[8 * ((int)v20 % 2)];
v30 = rand();
v31 = log((double)v30 * 4.656612873077393e-10) * -2.0;
if ( v31 < 0.0 )
v107 = sqrt(v31);
else
v107 = sqrt(v31);
v21 = rand();
v22 = sin((double)v21 * 4.656612873077393e-10 * 6.283185307179586);
v23 = v107 * v22 + v29;
}
*(double *)&v80[8 * v20++] = v23;
}
while ( v20 != v16 );
v16 = v95;
v32 = v94;
v33 = v93;
v89 = v80;
v34 = v80;
v35 = 16LL * (((unsigned int)v96 >> 1) + 1);
do
{
*(_QWORD *)v34 = LC5;
*((_QWORD *)v34 + 1) = LC6;
v34 += 16;
}
while ( v34 != &v80[v35] );
v90 = v80;
v36 = v80;
do
{
*(_QWORD *)v36 = LC7;
*((_QWORD *)v36 + 1) = LC0;
v36 += 16;
}
while ( v36 != &v80[v35] );
v96 = v105 >> 3;
v37 = 8LL * (unsigned int)v16;
v38 = &v80[v37];
v39 = 0;
v40 = -8LL * (unsigned int)v16;
do
{
v41 = &v38[v40];
do
*v41++ = 0LL;
while ( v41 != (_QWORD *)v38 );
++v39;
v38 += v105;
}
while ( v16 != v39 );
v42 = alloca(v103);
v43 = alloca(v103);
v44 = &v80[v37];
v45 = 0;
do
{
v46 = &v44[v40];
do
*v46++ = 0LL;
while ( v46 != (_QWORD *)v44 );
++v45;
v44 += v105;
}
while ( v16 != v45 );
v47 = 4 * v101;
v48 = alloca(4 * v102);
v91 = v80;
v95 = (unsigned __int64)(4 * v101) >> 2;
v104 = v80;
v49 = &v80[4 * v16];
v50 = 0;
do
{
v51 = &v49[-4 * v16];
do
*v51++ = 0;
while ( v51 != (_DWORD *)v49 );
++v50;
v49 += v47;
}
while ( v16 != v50 );
v94 = 8 * v95;
v93 = 16 * v96;
v103 = 0LL;
*(_QWORD *)&v106 = 1LL;
v52 = 0LL;
v92 = &(&v82)[v105 / 8];
v102 = v96 + 1;
v81 = v32;
v53 = v100;
v54 = v99;
v55 = v98;
v56 = v97;
v57 = (int)v82;
v58 = v87;
v82 = (_BYTE *)v33;
do
{
v59 = (__int64 *)((char *)v92 + v103);
v60 = v95 * (*(_QWORD *)&v106 - v52);
v100 = v103;
v101 = (__int64)v104;
v61 = 0;
v97 = (int)v52 * v102;
v98 = SLODWORD(v106) + v96 * (int)v52;
v99 = v96 * SLODWORD(v106) + (int)v52;
*(_QWORD *)&v107 = v102 * SLODWORD(v106);
v62 = v104;
v63 = v103;
do
{
if ( v61 == (_DWORD)v52 )
{
*(_QWORD *)&v80[8 * v97] = *a14;
*(_QWORD *)&v80[8 * v98] = a14[1];
*(_QWORD *)&v80[8 * v99] = a14[2];
*(_QWORD *)&v80[8 * *(_QWORD *)&v107] = a14[3];
}
else
{
*(_QWORD *)&v80[v63] = LC8;
*(_QWORD *)&v80[v63] = LC9;
*v62 = v57;
v62[1] = v58;
v62[v60] = a12;
v62[v60 + 1] = a13;
*(_QWORD *)&v80[v63] = v53;
*(_BYTE **)((char *)&v82 + v63) = (_BYTE *)v54;
*(v59 - 1) = v55;
*v59 = v56;
}
v61 += 2;
v62 += 2;
v59 += 2;
v63 += 16LL;
}
while ( v16 > v61 );
v52 += 2LL;
*(_QWORD *)&v106 += 2LL;
v104 += v94;
v103 += v93;
}
while ( v16 > (int)v52 );
v15 = v81;
v18 = v82;
}
plasticRateN_recW(
(unsigned int)v16,
(unsigned int)v15,
v18,
v85,
a15,
v91,
5000.0,
500.0,
v86,
v80,
v80,
v80,
v89,
v90);
result = v88;
if ( (int)v88 > 0 )
{
v65 = v105 >> 3;
v66 = v83;
result = 2 * v88;
v67 = 2 * v88;
v68 = 8 * v84;
v69 = 0;
do
{
v71 = (_QWORD *)v66;
v70 = 0;
if ( v15 > 0 )
{
do
{
result = v69 + v65 * v70;
*v71 = *(_QWORD *)&v18[8 * result];
++v70;
v71 = (_QWORD *)((char *)v71 + v68);
}
while ( v15 != v70 );
}
v66 += 8LL;
v69 += 2;
}
while ( v67 != v69 );
}
return result;
}

variable_types: n int

variable_types: xEE double

variable_types: xEI double

variable_types: xIE double

variable_types: xII double

variable_types:
wW
double [2][2]

variable_types: g int

variable_types: i int

variable_types: k int

variable_types: l int

variable_types:
gamma
double [-1]

variable_types:
tau
double [-1]

variable_types:
th
double [-1][-1]


plasticPingRateN

decompiled_code:
unsigned __int64 __fastcall plasticPingRateN(int a1, int a2, __int64 a3, _QWORD *a4, int a5, int a6, double a7, double a8, double a9, double a10, double a11, int a12, int a13, _QWORD *a14, _QWORD *a15)
{
int v15; // er13
unsigned int v16; // er15
void *v17; // rsp
double v18; // r12
void *v19; // rsp
__int64 v20; // r12
int v21; // eax
double v22; // xmm0_8
double v23; // xmm1_8
_QWORD *v24; // rbx
int v25; // eax
double v26; // xmm0_8
int v27; // eax
double v28; // xmm0_8
double v29; // rbx
int v30; // eax
double v31; // xmm0_8
int v32; // er13
__int64 v33; // r12
_BYTE *v34; // rax
__int64 v35; // rcx
_BYTE *v36; // rax
__int64 v37; // rdi
signed __int64 v38; // r10
void *v39; // rsp
unsigned __int64 v40; // rbx
double v41; // r9
__int64 v42; // r8
_BYTE *v43; // rdx
int v44; // ecx
__int64 v45; // rsi
_QWORD *v46; // rax
void *v47; // rsp
_BYTE *v48; // r10
_BYTE *v49; // r8
int v50; // edx
_QWORD *v51; // rax
unsigned __int64 v52; // rcx
void *v53; // rsp
_BYTE *v54; // rsi
_BYTE *v55; // rdx
int v56; // er8
_DWORD *v57; // rax
_BYTE *v58; // rcx
_QWORD *v59; // rdx
signed int v60; // er8
double v61; // xmm3_8
double v62; // xmm4_8
double v63; // xmm5_8
double v64; // xmm6_8
int v65; // er11
int v66; // ebx
_QWORD *v68; // rdi
_QWORD *v69; // rdx
__int64 v70; // rax
unsigned __int64 result; // rax
unsigned __int64 v72; // r9
__int64 v73; // rdx
int v74; // er10
__int64 v75; // r8
int v76; // er11
_QWORD *v77; // r14
__int64 v78; // xmm2_8
int v79; // ecx
_QWORD *v80; // rsi
signed __int64 v81; // rax
void *v82; // rsp
void *v83; // rsp
signed __int64 v84; // rax
void *v85; // rsp
void *v86; // rsp
void *v87; // rsp
_BYTE v88[8]; // [rsp+0h] [rbp-F0h] BYREF
int v89; // [rsp+8h] [rbp-E8h]
int v90; // [rsp+Ch] [rbp-E4h]
double v91; // [rsp+10h] [rbp-E0h]
double v92; // [rsp+18h] [rbp-D8h]
double v93; // [rsp+20h] [rbp-D0h]
double v94; // [rsp+28h] [rbp-C8h]
__int64 v95; // [rsp+30h] [rbp-C0h]
__int64 v96; // [rsp+38h] [rbp-B8h]
_BYTE *v97; // [rsp+40h] [rbp-B0h]
double v98; // [rsp+48h] [rbp-A8h]
int v99; // [rsp+50h] [rbp-A0h]
unsigned int v100; // [rsp+54h] [rbp-9Ch]
_BYTE *v101; // [rsp+58h] [rbp-98h]
_BYTE *v102; // [rsp+60h] [rbp-90h]
_BYTE *v103; // [rsp+68h] [rbp-88h]
_BYTE *v104; // [rsp+70h] [rbp-80h]
_BYTE *v105; // [rsp+78h] [rbp-78h]
__int64 v106; // [rsp+80h] [rbp-70h]
unsigned __int64 v107; // [rsp+88h] [rbp-68h]
unsigned __int64 v108; // [rsp+90h] [rbp-60h]
double v109; // [rsp+98h] [rbp-58h]
_QWORD *v110; // [rsp+A0h] [rbp-50h]
double v111; // [rsp+A8h] [rbp-48h]
unsigned __int64 v112; // [rsp+B0h] [rbp-40h]
double v113; // [rsp+B8h] [rbp-38h]
_QWORD *v114; // [rsp+110h] [rbp+20h]

v15 = a1;
v100 = a2;
v95 = a3;
v110 = a4;
v94 = a7;
v93 = a8;
v92 = a9;
v91 = a10;
v99 = a5;
v90 = a6;
v98 = a11;
v96 = a2;
v16 = 2 * a2;
*(_QWORD *)&v109 = 2 * a2;
v112 = 8LL * *(_QWORD *)&v109;
v17 = alloca(16 * ((8 * *(_QWORD *)&v109 * a1 + 15LL) / 0x10uLL));
v18 = COERCE_DOUBLE(v88);
v19 = alloca(16 * ((8LL * *(_QWORD *)&v109 + 15) / 0x10uLL));
v97 = v88;
if ( 2 * a2 <= 0 )
{
v81 = 16 * ((v112 + 15) / 0x10);
v82 = alloca(v81);
v101 = v88;
v83 = alloca(v81);
v102 = v88;
v84 = 16 * ((8LL * *(_QWORD *)&v109 * *(_QWORD *)&v109 + 15) / 0x10uLL);
v85 = alloca(v84);
v104 = v88;
v86 = alloca(v84);
v105 = v88;
v87 = alloca(16 * ((4LL * *(_QWORD *)&v109 * *(_QWORD *)&v109 + 15) / 0x10uLL));
v103 = v88;
}
else
{
LODWORD(v108) = v16 - 1;
LODWORD(v107) = 2 * a2;
LODWORD(v106) = a1;
v105 = v88;
v20 = 0LL;
do
{
v24 = &v110[2 * ((int)v20 / 2)];
v113 = *(double *)&v24[(int)v20 % 2];
v25 = rand();
v26 = log((double)v25 * 4.656612873077393e-10) * -2.0;
if ( v26 < 0.0 )
v111 = sqrt(v26);
else
v111 = sqrt(v26);
v27 = rand();
v28 = sin((double)v27 * 4.656612873077393e-10 * 6.283185307179586);
v23 = 0.0;
if ( v28 * v111 + v113 >= 0.0 )
{
v29 = *(double *)&v24[(int)v20 % 2];
v30 = rand();
v31 = log((double)v30 * 4.656612873077393e-10) * -2.0;
if ( v31 < 0.0 )
v113 = sqrt(v31);
else
v113 = sqrt(v31);
v21 = rand();
v22 = sin((double)v21 * 4.656612873077393e-10 * 6.283185307179586);
v23 = v113 * v22 + v29;
}
*(double *)&v88[8 * v20++] = v23;
}
while ( v20 != v16 );
v16 = v107;
v32 = v106;
v33 = (__int64)v105;
v101 = v88;
v34 = v88;
v35 = 16LL * (((unsigned int)v108 >> 1) + 1);
do
{
*(_QWORD *)v34 = LC4;
*((_QWORD *)v34 + 1) = LC5;
v34 += 16;
}
while ( v34 != &v88[v35] );
v102 = v88;
v36 = v88;
do
{
*(_QWORD *)v36 = LC6;
*((_QWORD *)v36 + 1) = LC7;
v36 += 16;
}
while ( v36 != &v88[v35] );
v37 = *(_QWORD *)&v109 * *(_QWORD *)&v109;
v38 = 8LL * *(_QWORD *)&v109 * *(_QWORD *)&v109;
v39 = alloca(v38);
v104 = v88;
v40 = v112 >> 3;
v41 = COERCE_DOUBLE(v88);
v42 = 8LL * v16;
v43 = &v88[v42];
v44 = 0;
v45 = -8LL * v16;
do
{
v46 = &v43[v45];
do
*v46++ = 0LL;
while ( v46 != (_QWORD *)v43 );
++v44;
v43 += v112;
}
while ( v16 != v44 );
v47 = alloca(v38);
v105 = v88;
v48 = v88;
v49 = &v88[v42];
v50 = 0;
do
{
v51 = &v49[v45];
do
*v51++ = 0LL;
while ( v51 != (_QWORD *)v49 );
++v50;
v49 += v112;
}
while ( v16 != v50 );
v52 = 4LL * *(_QWORD *)&v109;
v53 = alloca(4 * v37);
v103 = v88;
v54 = v88;
v55 = &v88[4 * v16];
v56 = 0;
do
{
v57 = &v55[-4 * v16];
do
*v57++ = 0;
while ( v57 != (_DWORD *)v55 );
++v56;
v55 += v52;
}
while ( v16 != v56 );
v108 = 8 * (v52 >> 2);
v58 = &v88[v52];
v59 = a15;
v60 = 0;
v107 = 16 * v40;
v110 = a15;
v106 = 16 * (*(_QWORD *)&v109 + 1LL);
v89 = v32;
v61 = v94;
v62 = v93;
v63 = v92;
v64 = v91;
v65 = v99;
v66 = v90;
v94 = *(double *)&v33;
do
{
v68 = v59;
v69 = &v59[v112 / 8];
v70 = 0LL;
v113 = v41;
v114 = a14;
do
{
if ( v60 == (_DWORD)v70 )
{
v77 = v110;
*v110 = *v114;
v77[1] = v114[1];
v78 = v114[2];
v111 = v109;
v77[*(_QWORD *)&v109] = v78;
v77[*(_QWORD *)&v111 + 1] = v114[3];
}
else
{
*(_QWORD *)&v48[8 * v70] = LC8;
*(_QWORD *)(*(_QWORD *)&v113 + 8 * v70) = LC9;
*(_DWORD *)&v54[4 * v70] = v65;
*(_DWORD *)&v54[4 * v70 + 4] = v66;
*(_DWORD *)&v58[4 * v70] = a12;
*(_DWORD *)&v58[4 * v70 + 4] = a13;
*(double *)&v68[v70] = v61;
*(double *)&v68[v70 + 1] = v62;
*(double *)&v69[v70] = v63;
*(double *)&v69[v70 + 1] = v64;
}
v70 += 2LL;
}
while ( (int)v16 > (int)v70 );
a14 = v114;
v60 += 2;
v48 += v107;
*(_QWORD *)&v41 = v107 + *(_QWORD *)&v113;
v54 += v108;
v58 += v108;
v59 = &v69[v112 / 8];
v110 = (_QWORD *)((char *)v110 + v106);
}
while ( (int)v16 > v60 );
v15 = v89;
v18 = v94;
}
plasticRateN(v16, (unsigned int)v15, *(_QWORD *)&v18, v97, v103, a15, 100000.0, 1000.0, v98, v105, v104, v101, v102);
result = v100;
if ( (int)v100 > 0 )
{
v72 = v112 >> 3;
v73 = v95;
result = 2 * v100;
v74 = 2 * v100;
v75 = 8 * v96;
v76 = 0;
do
{
v80 = (_QWORD *)v73;
v79 = 0;
if ( v15 > 0 )
{
do
{
result = v76 + v72 * v79;
*v80 = *(_QWORD *)(*(_QWORD *)&v18 + 8 * result);
++v79;
v80 = (_QWORD *)((char *)v80 + v75);
}
while ( v15 != v79 );
}
v73 += 8LL;
v76 += 2;
}
while ( v76 != v74 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(int a1, int a2, __int64 a3, _QWORD *a4, int a5, int a6, double a7, double a8, double a9, double a10, double a11, int a12, int a13, _QWORD *a14, _QWORD *a15)
{
int v15; // er13
unsigned int v16; // er15
void *v17; // rsp
double v18; // r12
void *v19; // rsp
__int64 v20; // r12
int v21; // eax
double v22; // xmm0_8
double v23; // xmm1_8
_QWORD *v24; // rbx
int v25; // eax
double v26; // xmm0_8
int v27; // eax
double v28; // xmm0_8
double v29; // rbx
int v30; // eax
double v31; // xmm0_8
int v32; // er13
__int64 v33; // r12
_BYTE *v34; // rax
__int64 v35; // rcx
_BYTE *v36; // rax
__int64 v37; // rdi
signed __int64 v38; // r10
void *v39; // rsp
unsigned __int64 v40; // rbx
double v41; // r9
__int64 v42; // r8
_BYTE *v43; // rdx
int v44; // ecx
__int64 v45; // rsi
_QWORD *v46; // rax
void *v47; // rsp
_BYTE *v48; // r10
_BYTE *v49; // r8
int v50; // edx
_QWORD *v51; // rax
unsigned __int64 v52; // rcx
void *v53; // rsp
_BYTE *v54; // rsi
_BYTE *v55; // rdx
int v56; // er8
_DWORD *v57; // rax
_BYTE *v58; // rcx
_QWORD *v59; // rdx
signed int v60; // er8
double v61; // xmm3_8
double v62; // xmm4_8
double v63; // xmm5_8
double v64; // xmm6_8
int v65; // er11
int v66; // ebx
_QWORD *v68; // rdi
_QWORD *v69; // rdx
__int64 v70; // rax
unsigned __int64 result; // rax
unsigned __int64 v72; // r9
__int64 v73; // rdx
int v74; // er10
__int64 v75; // r8
int v76; // er11
_QWORD *v77; // r14
__int64 v78; // xmm2_8
int v79; // ecx
_QWORD *v80; // rsi
signed __int64 v81; // rax
void *v82; // rsp
void *v83; // rsp
signed __int64 v84; // rax
void *v85; // rsp
void *v86; // rsp
void *v87; // rsp
_BYTE v88[8]; // [rsp+0h] [rbp-F0h] BYREF
int v89; // [rsp+8h] [rbp-E8h]
int v90; // [rsp+Ch] [rbp-E4h]
double v91; // [rsp+10h] [rbp-E0h]
double v92; // [rsp+18h] [rbp-D8h]
double v93; // [rsp+20h] [rbp-D0h]
double v94; // [rsp+28h] [rbp-C8h]
__int64 v95; // [rsp+30h] [rbp-C0h]
__int64 v96; // [rsp+38h] [rbp-B8h]
_BYTE *v97; // [rsp+40h] [rbp-B0h]
double v98; // [rsp+48h] [rbp-A8h]
int v99; // [rsp+50h] [rbp-A0h]
unsigned int v100; // [rsp+54h] [rbp-9Ch]
_BYTE *v101; // [rsp+58h] [rbp-98h]
_BYTE *v102; // [rsp+60h] [rbp-90h]
_BYTE *v103; // [rsp+68h] [rbp-88h]
_BYTE *v104; // [rsp+70h] [rbp-80h]
_BYTE *v105; // [rsp+78h] [rbp-78h]
__int64 v106; // [rsp+80h] [rbp-70h]
unsigned __int64 v107; // [rsp+88h] [rbp-68h]
unsigned __int64 v108; // [rsp+90h] [rbp-60h]
double v109; // [rsp+98h] [rbp-58h]
_QWORD *v110; // [rsp+A0h] [rbp-50h]
double v111; // [rsp+A8h] [rbp-48h]
unsigned __int64 v112; // [rsp+B0h] [rbp-40h]
double v113; // [rsp+B8h] [rbp-38h]
_QWORD *v114; // [rsp+110h] [rbp+20h]

v15 = a1;
v100 = a2;
v95 = a3;
v110 = a4;
v94 = a7;
v93 = a8;
v92 = a9;
v91 = a10;
v99 = a5;
v90 = a6;
v98 = a11;
v96 = a2;
v16 = 2 * a2;
*(_QWORD *)&v109 = 2 * a2;
v112 = 8LL * *(_QWORD *)&v109;
v17 = alloca(16 * ((8 * *(_QWORD *)&v109 * a1 + 15LL) / 0x10uLL));
v18 = COERCE_DOUBLE(v88);
v19 = alloca(16 * ((8LL * *(_QWORD *)&v109 + 15) / 0x10uLL));
v97 = v88;
if ( 2 * a2 <= 0 )
{
v81 = 16 * ((v112 + 15) / 0x10);
v82 = alloca(v81);
v101 = v88;
v83 = alloca(v81);
v102 = v88;
v84 = 16 * ((8LL * *(_QWORD *)&v109 * *(_QWORD *)&v109 + 15) / 0x10uLL);
v85 = alloca(v84);
v104 = v88;
v86 = alloca(v84);
v105 = v88;
v87 = alloca(16 * ((4LL * *(_QWORD *)&v109 * *(_QWORD *)&v109 + 15) / 0x10uLL));
v103 = v88;
}
else
{
LODWORD(v108) = v16 - 1;
LODWORD(v107) = 2 * a2;
LODWORD(v106) = a1;
v105 = v88;
v20 = 0LL;
do
{
v24 = &v110[2 * ((int)v20 / 2)];
v113 = *(double *)&v24[(int)v20 % 2];
v25 = rand();
v26 = log((double)v25 * 4.656612873077393e-10) * -2.0;
if ( v26 < 0.0 )
v111 = sqrt(v26);
else
v111 = sqrt(v26);
v27 = rand();
v28 = sin((double)v27 * 4.656612873077393e-10 * 6.283185307179586);
v23 = 0.0;
if ( v28 * v111 + v113 >= 0.0 )
{
v29 = *(double *)&v24[(int)v20 % 2];
v30 = rand();
v31 = log((double)v30 * 4.656612873077393e-10) * -2.0;
if ( v31 < 0.0 )
v113 = sqrt(v31);
else
v113 = sqrt(v31);
v21 = rand();
v22 = sin((double)v21 * 4.656612873077393e-10 * 6.283185307179586);
v23 = v113 * v22 + v29;
}
*(double *)&v88[8 * v20++] = v23;
}
while ( v20 != v16 );
v16 = v107;
v32 = v106;
v33 = (__int64)v105;
v101 = v88;
v34 = v88;
v35 = 16LL * (((unsigned int)v108 >> 1) + 1);
do
{
*(_QWORD *)v34 = LC4;
*((_QWORD *)v34 + 1) = LC5;
v34 += 16;
}
while ( v34 != &v88[v35] );
v102 = v88;
v36 = v88;
do
{
*(_QWORD *)v36 = LC6;
*((_QWORD *)v36 + 1) = LC7;
v36 += 16;
}
while ( v36 != &v88[v35] );
v37 = *(_QWORD *)&v109 * *(_QWORD *)&v109;
v38 = 8LL * *(_QWORD *)&v109 * *(_QWORD *)&v109;
v39 = alloca(v38);
v104 = v88;
v40 = v112 >> 3;
v41 = COERCE_DOUBLE(v88);
v42 = 8LL * v16;
v43 = &v88[v42];
v44 = 0;
v45 = -8LL * v16;
do
{
v46 = &v43[v45];
do
*v46++ = 0LL;
while ( v46 != (_QWORD *)v43 );
++v44;
v43 += v112;
}
while ( v16 != v44 );
v47 = alloca(v38);
v105 = v88;
v48 = v88;
v49 = &v88[v42];
v50 = 0;
do
{
v51 = &v49[v45];
do
*v51++ = 0LL;
while ( v51 != (_QWORD *)v49 );
++v50;
v49 += v112;
}
while ( v16 != v50 );
v52 = 4LL * *(_QWORD *)&v109;
v53 = alloca(4 * v37);
v103 = v88;
v54 = v88;
v55 = &v88[4 * v16];
v56 = 0;
do
{
v57 = &v55[-4 * v16];
do
*v57++ = 0;
while ( v57 != (_DWORD *)v55 );
++v56;
v55 += v52;
}
while ( v16 != v56 );
v108 = 8 * (v52 >> 2);
v58 = &v88[v52];
v59 = a15;
v60 = 0;
v107 = 16 * v40;
v110 = a15;
v106 = 16 * (*(_QWORD *)&v109 + 1LL);
v89 = v32;
v61 = v94;
v62 = v93;
v63 = v92;
v64 = v91;
v65 = v99;
v66 = v90;
v94 = *(double *)&v33;
do
{
v68 = v59;
v69 = &v59[v112 / 8];
v70 = 0LL;
v113 = v41;
v114 = a14;
do
{
if ( v60 == (_DWORD)v70 )
{
v77 = v110;
*v110 = *v114;
v77[1] = v114[1];
v78 = v114[2];
v111 = v109;
v77[*(_QWORD *)&v109] = v78;
v77[*(_QWORD *)&v111 + 1] = v114[3];
}
else
{
*(_QWORD *)&v48[8 * v70] = LC8;
*(_QWORD *)(*(_QWORD *)&v113 + 8 * v70) = LC9;
*(_DWORD *)&v54[4 * v70] = v65;
*(_DWORD *)&v54[4 * v70 + 4] = v66;
*(_DWORD *)&v58[4 * v70] = a12;
*(_DWORD *)&v58[4 * v70 + 4] = a13;
*(double *)&v68[v70] = v61;
*(double *)&v68[v70 + 1] = v62;
*(double *)&v69[v70] = v63;
*(double *)&v69[v70 + 1] = v64;
}
v70 += 2LL;
}
while ( (int)v16 > (int)v70 );
a14 = v114;
v60 += 2;
v48 += v107;
*(_QWORD *)&v41 = v107 + *(_QWORD *)&v113;
v54 += v108;
v58 += v108;
v59 = &v69[v112 / 8];
v110 = (_QWORD *)((char *)v110 + v106);
}
while ( (int)v16 > v60 );
v15 = v89;
v18 = v94;
}
plasticRateN(v16, (unsigned int)v15, *(_QWORD *)&v18, v97, v103, a15, 100000.0, 1000.0, v98, v105, v104, v101, v102);
result = v100;
if ( (int)v100 > 0 )
{
v72 = v112 >> 3;
v73 = v95;
result = 2 * v100;
v74 = 2 * v100;
v75 = 8 * v96;
v76 = 0;
do
{
v80 = (_QWORD *)v73;
v79 = 0;
if ( v15 > 0 )
{
do
{
result = v76 + v72 * v79;
*v80 = *(_QWORD *)(*(_QWORD *)&v18 + 8 * result);
++v79;
v80 = (_QWORD *)((char *)v80 + v75);
}
while ( v15 != v79 );
}
v73 += 8LL;
v76 += 2;
}
while ( v76 != v74 );
}
return result;
}

variable_types: no int

variable_types:
Re
double [-1][-1]

variable_types: dt double

variable_types: j int


pingRateN

variable_types: n int


original_code:
void *EE_Attractor_worker(void *arg)
{
 printf("Inside string...");
 THREAD_DAT_1D * in = arg;
 printf("%d to %d\n", in->a, in->b);
 int n=9999, no=2;
 double dt=0.0001;
 int i, j, k;
 double ei=0.3;
 double ie=-0.5;
 double ii=0;
 double ee_a=0.1;
 double ee_b=0.3;
 int ee_res=in->res;
 double ee_vec[ee_res];
 linspace(ee_a, ee_b, ee_res, ee_vec);
 int ipd_res = 200;
 int trials = 100;
 double wW[2][2];
  wW[0][0]=2; wW[0][1]=2.873;
  wW[1][0]=-2.873; wW[1][1]=-2;
 int p=1000;
 double lp_rates[p][2];
 get_last_period(&p, lp_rates, wW);
 double Re[n][no];
 double R_i[no][no];
 double pds[no][no];
 double phdiffs[ee_res][ipd_res];
 for (i=in->a; i<in->b; i++){
  printf("T%d: %f percent done\n", in->id, 100*((double) i-in->a)/((double) ee_res-in->a));
  for (j=0; j<ipd_res; j++){
   R_i[0][0]=lp_rates[0][0];
   R_i[0][1]=lp_rates[0][1];
   R_i[1][0]=lp_rates[j*p/ipd_res][0];
   R_i[1][1]=lp_rates[j*p/ipd_res][1];
   in->DATA[i*ee_res+j]=0;
   for (k=0; k<trials; k++){
    pingRateN(n,no,Re,R_i,ee_vec[i],ei,ie,ii,wW,dt);
    phdiff2(n, no, Re, pds);
    in->DATA[i*ee_res+j]=in->DATA[i*ee_res+j]+pds[0][1];
   }
   in->DATA[i*ee_res+j]=in->DATA[i*ee_res+j]/trials;
  }
 }
 pthread_exit(((void *)0));
}

canonical_original_code:
void *EE_Attractor_worker(void *arg)
{
 printf("Inside string...");
 struct THREAD_DAT_1D *in = arg;
 printf("%d to %d\n", in->a, in->b);
 int n = 9999; int no = 2;
 double dt = 0.0001;
 int i; int j; int k;
 double ei = 0.3;
 double ie = -0.5;
 double ii = 0;
 double ee_a = 0.1;
 double ee_b = 0.3;
 int ee_res = in->res;
 double ee_vec[-1];
 linspace(ee_a, ee_b, ee_res, ee_vec);
 int ipd_res = 200;
 int trials = 100;
 double wW[2][2];
  wW[0][0]=2; wW[0][1]=2.873;
  wW[1][0]=-2.873; wW[1][1]=-2;
 int p = 1000;
 double lp_rates[-1][2];
 get_last_period(&p, lp_rates, wW);
 double Re[-1][-1];
 double R_i[-1][-1];
 double pds[-1][-1];
 double phdiffs[-1][-1];
 for (i=in->a; i<in->b; i++){
  printf("T%d: %f percent done\n", in->id, 100*((double) i-in->a)/((double) ee_res-in->a));
  for (j=0; j<ipd_res; j++){
   R_i[0][0]=lp_rates[0][0];
   R_i[0][1]=lp_rates[0][1];
   R_i[1][0]=lp_rates[j*p/ipd_res][0];
   R_i[1][1]=lp_rates[j*p/ipd_res][1];
   in->DATA[i*ee_res+j]=0;
   for (k=0; k<trials; k++){
    pingRateN(n,no,Re,R_i,ee_vec[i],ei,ie,ii,wW,dt);
    phdiff2(n, no, Re, pds);
    in->DATA[i*ee_res+j]=in->DATA[i*ee_res+j]+pds[0][1];
   }
   in->DATA[i*ee_res+j]=in->DATA[i*ee_res+j]/trials;
  }
 }
 pthread_exit(((void *)0));
}

variable_types:
arg
void *

variable_types: struct THREAD_DAT_1D { int id; int a; int b; int res; double *DATA; double *DATA_IN; } *

variable_types: ei double

variable_types: ie double

variable_types: ii double

variable_types: trials int

variable_types: p int

variable_types:
pds
double [-1][-1]

variable_types:
phdiffs
double [-1][-1]


bodyDiff

repo: wisdompilot/parallelComputing

decompiled_code:
double __fastcall bodyDiff(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax
double v4; // xmm0_8
double v5; // xmm1_8
double result; // xmm0_8

v3 = a1 + 56LL * a3;
if ( a1 == v3 )
return 0.0;
v4 = *(double *)(a1 + 32) - *(double *)(a2 + 32);
v5 = (*(double *)(a1 + 24) - *(double *)(a2 + 24)) * (*(double *)(a1 + 24) - *(double *)(a2 + 24)) + v4 * v4;
result = 0.0;
do
{
result = result + v5;
a1 += 56LL;
}
while ( a1 != v3 );
return result;
}

canonical_decompiled_code:
double __fastcall func7(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax
double v4; // xmm0_8
double v5; // xmm1_8
double result; // xmm0_8

v3 = a1 + 56LL * a3;
if ( a1 == v3 )
return 0.0;
v4 = *(double *)(a1 + 32) - *(double *)(a2 + 32);
v5 = (*(double *)(a1 + 24) - *(double *)(a2 + 24)) * (*(double *)(a1 + 24) - *(double *)(a2 + 24)) + v4 * v4;
result = 0.0;
do
{
result = result + v5;
a1 += 56LL;
}
while ( a1 != v3 );
return result;
}

original_code:
double bodyDiff(Body *a, Body *b, int size){
 Body *i = a, *j = b;
 double squareDiff = 0;
 double dvx, dvy;
 for (i = a; i != a + size; i++){
  dvx = a->velocity.x - b->velocity.x;
  dvy = a->velocity.y - b->velocity.y;
  squareDiff += dvx * dvx + dvy * dvy;
 }
 return squareDiff;
}

canonical_original_code:
double bodyDiff(struct Body *a, struct Body *b, int size){
 struct Body *i = a; struct Body *j = b;
 double squareDiff = 0;
 double dvx; double dvy;
 for (i = a; i != a + size; i++){
  dvx = a->velocity.x - b->velocity.x;
  dvy = a->velocity.y - b->velocity.y;
  squareDiff += dvx * dvx + dvy * dvy;
 }
 return squareDiff;
}

variable_types: struct Body { double mass; struct Vec2 { double x; } position; struct Vec2 velocity; struct Vec2 acceleration; } *

variable_types:
b
struct Body *

variable_types: size int

variable_types: squareDiff double

variable_types: dvx double

variable_types: dvy double

return_type: double

user_defined_types: struct Body { double mass; struct Vec2 position; struct Vec2 velocity; struct Vec2 acceleration; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbx
void *v4; // rbp
double v5; // xmm0_8
__m128i v7; // [rsp+0h] [rbp-78h] BYREF
__int64 v8; // [rsp+10h] [rbp-68h]
__m128i v9; // [rsp+20h] [rbp-58h] BYREF
__int64 v10; // [rsp+30h] [rbp-48h]
__m128i v11; // [rsp+40h] [rbp-38h] BYREF
__int64 v12; // [rsp+50h] [rbp-28h]

v3 = malloc(0x445C0uLL);
v4 = malloc(0x445C0uLL);
randInit(v3, 0LL, 5000LL);
bodyCopy(v4, v3, 0LL, 5000LL);
getState(&v7, v3, 5000LL);
v11 = _mm_loadu_si128(&v7);
v12 = v8;
nextPhase(v3, 4LL, &forceTable, 0.001);
nextPhaseHalf(v4, 4LL, &forceTable, 0.001);
v5 = bodyDiff((__int64)v3, (__int64)v4, 5000);
printf("diff=%f\n", v5);
getState(&v7, v3, 5000LL);
v9 = _mm_loadu_si128(&v7);
v10 = v8;
statePrint(&v11);
statePrint(&v9);
free(v3);
return 0;
}

original_code:
int main(int argc, char *argv[]){
 double t0, t1, te;
 Body *bodies = (Body *) malloc (sizeof(Body ) * 5000);
 Body *bodies2 = (Body *) malloc (sizeof(Body ) * 5000);
 Body *bodies3 = (Body *) malloc (sizeof(Body ) * 5000);
 randInit (bodies, 0, 5000);
 bodyCopy(bodies2, bodies, 0, 5000);
 struct BodyState bs0, bsK;
 bs0 = getState(bodies, 5000);
 nextPhase(bodies, 0.001, 4, forceTable);
 nextPhaseHalf(bodies2, 0.001, 4, forceTable);
 double diff = bodyDiff(bodies, bodies2, 5000);
 printf("diff=%f\n", diff);
 bsK = getState(bodies, 5000);
 statePrint(&bs0);
 statePrint(&bsK);
 free(bodies);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 double t0; double t1; double te;
 struct Body *bodies = (Body *) malloc (sizeof(Body ) * 5000);
 struct Body *bodies2 = (Body *) malloc (sizeof(Body ) * 5000);
 struct Body *bodies3 = (Body *) malloc (sizeof(Body ) * 5000);
 randInit (bodies, 0, 5000);
 bodyCopy(bodies2, bodies, 0, 5000);
 struct BodyState bs0; struct BodyState bsK;
 bs0 = getState(bodies, 5000);
 nextPhase(bodies, 0.001, 4, forceTable);
 nextPhaseHalf(bodies2, 0.001, 4, forceTable);
 double diff = bodyDiff(bodies, bodies2, 5000);
 printf("diff=%f\n", diff);
 bsK = getState(bodies, 5000);
 statePrint(&bs0);
 statePrint(&bsK);
 free(bodies);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: te double

variable_types: struct BodyState { double mvx; double energy; }

variable_types: diff double


fastInvSqrtCube

decompiled_code:
double __fastcall fastInvSqrtCube(double a1)
{
return (1.5
- a1
* 0.5
* COERCE_DOUBLE(0x5FE6EB50C7B537A9LL - (*(_QWORD *)&a1 >> 1))
* COERCE_DOUBLE(0x5FE6EB50C7B537A9LL - (*(_QWORD *)&a1 >> 1)))
* COERCE_DOUBLE(0x5FE6EB50C7B537A9LL - (*(_QWORD *)&a1 >> 1))
/ a1;
}

canonical_decompiled_code:
double __fastcall func7(double a1)
{
return (1.5
- a1
* 0.5
* COERCE_DOUBLE(0x5FE6EB50C7B537A9LL - (*(_QWORD *)&a1 >> 1))
* COERCE_DOUBLE(0x5FE6EB50C7B537A9LL - (*(_QWORD *)&a1 >> 1)))
* COERCE_DOUBLE(0x5FE6EB50C7B537A9LL - (*(_QWORD *)&a1 >> 1))
/ a1;
}

original_code:
double fastInvSqrtCube(double number) {
 uint64_t i;
 double x2, y;
 x2 = number * 0.5;
 y = number;
 i = *(uint64_t *) &y;
 i = 0x5fe6eb50c7b537a9 - (i >> 1);
 y = *(double *) &i;
 y = y * (1.5 - (x2 * y * y));
 return y / number;
}

canonical_original_code:
double fastInvSqrtCube(double number) {
 unsigned long i;
 double x2; double y;
 x2 = number * 0.5;
 y = number;
 i = *(unsigned long *) &y;
 i = 0x5fe6eb50c7b537a9 - (i >> 1);
 y = *(double *) &i;
 y = y * (1.5 - (x2 * y * y));
 return y / number;
}

variable_types: number double

variable_types:
i
unsigned long

variable_types: y double


randTest

original_code:
void randTest(Body bodies[], int start, int end){
 int i;
 srand (time(((void *)0)));
 for (i = start; i < end; i++){
  bodies[i].mass = 1;
  bodies[i].position.x = 0.1 * i;
  bodies[i].position.y = 0.1 * i;
  bodies[i].velocity.x = 1;
  bodies[i].velocity.y = 1;
 }
}

canonical_original_code:
void randTest(struct Body bodies[], int start, int end){
 int i;
 srand (time(((void *)0)));
 for (i = start; i < end; i++){
  bodies[i].mass = 1;
  bodies[i].position.x = 0.1 * i;
  bodies[i].position.y = 0.1 * i;
  bodies[i].velocity.x = 1;
  bodies[i].velocity.y = 1;
 }
}

variable_types: struct Body { double mass; struct Vec2 { double x; } position; struct Vec2 velocity; struct Vec2 acceleration; } []

variable_types: start int

variable_types: end int

variable_types: i int


bodiesPrint

decompiled_code:
int __fastcall bodiesPrint(__int64 a1, int a2, int a3)
{
int v3; // ebx
double *v5; // rbp

v3 = a2;
putchar(123);
if ( a2 < a3 )
{
v5 = (double *)(a1 + 40LL * a2 + 8);
do
{
printf("{%f, %f}", *v5, v5[1]);
if ( v3 == a3 - 1 )
break;
printf(", ");
++v3;
v5 += 5;
}
while ( a3 != v3 );
}
return puts("}, ");
}

original_code:
void bodiesPrint(Body bodies[], int start, int end){
 int i;
 printf("{");
 for (i = start; i < end; i++){
  printf("{%f, %f}", bodies[i].position.x, bodies[i].position.y);
  if (i == end - 1)
   break;
  else
   printf(", ");
 }
 printf("}, \n");
}

canonical_original_code:
void bodiesPrint(struct Body bodies[], int start, int end){
 int i;
 printf("{");
 for (i = start; i < end; i++){
  printf("{%f, %f}", bodies[i].position.x, bodies[i].position.y);
  if (i == end - 1)
   break;
  else
   printf(", ");
 }
 printf("}, \n");
}

variable_types: struct Body { double mass; struct Vec2 { double x; } position; struct Vec2 velocity; } []

user_defined_types: struct Body { double mass; struct Vec2 position; struct Vec2 velocity; }


wctime

decompiled_code:
int __fastcall wctime(double *a1)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

result = gettimeofday(&v2, 0LL);
*a1 = (double)SLODWORD(v2.tv_usec) * 0.000001 + (double)SLODWORD(v2.tv_sec);
return result;
}

canonical_decompiled_code:
int __fastcall func14(double *a1)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

result = gettimeofday(&v2, 0LL);
*a1 = (double)SLODWORD(v2.tv_usec) * 0.000001 + (double)SLODWORD(v2.tv_sec);
return result;
}

original_code:
void wctime(double *t) {
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 *t = tv.tv_sec + (1E-6) * tv.tv_usec;
}

variable_types:
t
double *

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


repo: witchnaga/filedlg

decompiled_code:
__int64 __fastcall file_dialog_get_action(__int64 a1)
{
unsigned int v1; // edx
__int16 v2; // ax
int v4; // eax

v1 = 0;
if ( a1 )
{
v2 = *(_WORD *)(a1 + 24);
if ( v2 )
{
switch ( v2 )
{
case 1:
v4 = 1;
break;
case 2:
v4 = 2;
break;
case 3:
v4 = 3;
break;
default:
return v1;
}
}
else
{
v4 = 0;
}
v1 = dword_402124[2 * v4];
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
unsigned int v1; // edx
__int16 v2; // ax
int v4; // eax

v1 = 0;
if ( a1 )
{
v2 = *(_WORD *)(a1 + 24);
if ( v2 )
{
switch ( v2 )
{
case 1:
v4 = 1;
break;
case 2:
v4 = 2;
break;
case 3:
v4 = 3;
break;
default:
return v1;
}
}
else
{
v4 = 0;
}
v1 = dword_402124[2 * v4];
}
return v1;
}

original_code:
static GtkFileChooserAction file_dialog_get_action(Command* cmd_ptr)
{
 GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
 if (cmd_ptr != ((void *)0)) {
  int i;
  for (i = 0; i < (sizeof(actions)/sizeof((actions)[0])); ++i) {
   if (cmd_ptr->action == actions[i].action) {
    action = actions[i].gtk_action;
    break;
   }
  }
 }
 return action;
}

canonical_original_code:
static enum GtkFileChooserAction file_dialog_get_action(struct Command *cmd_ptr)
{
 enum GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
 if (cmd_ptr != ((void *)0)) {
  int i;
  for (i = 0; i < (sizeof(actions)/sizeof((actions)[0])); ++i) {
   if (cmd_ptr->action == actions[i].action) {
    action = actions[i].gtk_action;
    break;
   }
  }
 }
 return action;
}

variable_types: struct Command { int argc; char **argv; unsigned short mode; unsigned int filter; unsigned short action; char *title; } *

variable_types: enum GtkFileChooserAction { GTK_FILE_CHOOSER_ACTION_OPEN=0, GTK_FILE_CHOOSER_ACTION_SAVE=1, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER=2, GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER=3 }


original_code:
static void command_init(int argc, char** argv, Command* data_ptr)
{
 if (data_ptr != ((void *)0)) {
  data_ptr->argc = argc;
  data_ptr->argv = argv;
  data_ptr->mode = COMMAND_MODE_EXEC;
  data_ptr->filter = COMMAND_FILTER_DEFAULT;
  data_ptr->action = COMMAND_ACTION_DEFAULT;
  data_ptr->title = ((void *)0);
 }
}

canonical_original_code:
static void command_init(int argc, char **argv, struct Command *data_ptr)
{
 if (data_ptr != ((void *)0)) {
  data_ptr->argc = argc;
  data_ptr->argv = argv;
  data_ptr->mode = COMMAND_MODE_EXEC;
  data_ptr->filter = COMMAND_FILTER_DEFAULT;
  data_ptr->action = COMMAND_ACTION_DEFAULT;
  data_ptr->title = ((void *)0);
 }
}

variable_types: argc int

variable_types:
argv
char **

user_defined_types: struct Command { int argc; char **argv; unsigned short mode; unsigned int filter; unsigned short action; char *title; }


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

result = 0LL;
if ( a4 < a1 )
{
*(_QWORD *)(a3 + 32) = *(_QWORD *)(a2 + 8LL * a4 + 8);
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a4 < a1 )
{
*(_QWORD *)(a3 + 32) = *(_QWORD *)(a2 + 8LL * a4 + 8);
result = 1LL;
}
return result;
}

original_code:
static int command_parse_title(int argc, char** argv, Command* data_ptr, int pos)
{
 int result = 0;
 if (pos < argc) {
  result = 1;
  data_ptr->title = argv[pos + 1];
 }
 return result;
}

canonical_original_code:
static int command_parse_title(int argc, char **argv, struct Command *data_ptr, int pos)
{
 int result = 0;
 if (pos < argc) {
  result = 1;
  data_ptr->title = argv[pos + 1];
 }
 return result;
}

variable_types: pos int

variable_types: result int


decompiled_code:
__int64 __fastcall command_parse_action(int a1, __int64 a2, __int64 a3, int a4)
{
__int64 result; // rax
const char *v6; // r12
__int64 v7; // rbx

result = 0LL;
if ( a4 < a1 )
{
v6 = *(const char **)(a2 + 8LL * a4 + 8);
if ( *v6 == 45 )
{
puts("command_parse_action : action parameter is invalid.");
result = 0LL;
}
else
{
v7 = 0LL;
while ( strcmp(v6, (const char *)action_parameter[2 * v7]) )
{
if ( ++v7 == 4 )
return 1LL;
}
*(_WORD *)(a3 + 24) = word_402448[8 * (int)v7];
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, __int64 a2, __int64 a3, int a4)
{
__int64 result; // rax
const char *v6; // r12
__int64 v7; // rbx

result = 0LL;
if ( a4 < a1 )
{
v6 = *(const char **)(a2 + 8LL * a4 + 8);
if ( *v6 == 45 )
{
puts("command_parse_action : action parameter is invalid.");
result = 0LL;
}
else
{
v7 = 0LL;
while ( strcmp(v6, (const char *)action_parameter[2 * v7]) )
{
if ( ++v7 == 4 )
return 1LL;
}
*(_WORD *)(a3 + 24) = word_402448[8 * (int)v7];
result = 1LL;
}
}
return result;
}

original_code:
static int command_parse_action(int argc, char** argv, Command* data_ptr, int pos)
{
 int result = 0;
 if (pos < argc) {
  if (*argv[pos + 1] != '-') {
   int i;
   result = 1;
   for (i = 0; i < (sizeof(action_parameter)/sizeof((action_parameter)[0])); ++i) {
    if (strcmp(argv[pos + 1], action_parameter[i].command) == 0) {
     data_ptr->action = action_parameter[i].value;
     break;
    }
   }
  } else {
   printf("command_parse_action : action parameter is invalid.\n");
  }
 }
 return result;
}

canonical_original_code:
static int command_parse_action(int argc, char **argv, struct Command *data_ptr, int pos)
{
 int result = 0;
 if (pos < argc) {
  if (*argv[pos + 1] != '-') {
   int i;
   result = 1;
   for (i = 0; i < (sizeof(action_parameter)/sizeof((action_parameter)[0])); ++i) {
    if (strcmp(argv[pos + 1], action_parameter[i].command) == 0) {
     data_ptr->action = action_parameter[i].value;
     break;
    }
   }
  } else {
   printf("command_parse_action : action parameter is invalid.\n");
  }
 }
 return result;
}


decompiled_code:
__int64 __fastcall command_parse_filter(int a1, __int64 a2, __int64 a3, int a4)
{
__int64 result; // rax
const char *v5; // r12
int v6; // eax
int v7; // er15
__int64 v8; // r13
const char *v9; // rsi
__int64 v10; // rbx
int v11; // eax
int v12; // edx
__int64 *v13; // rbp
int v15; // [rsp+Ch] [rbp-4Ch]
char dest[8]; // [rsp+10h] [rbp-48h] BYREF
__int64 v17; // [rsp+18h] [rbp-40h]

result = 0LL;
if ( a4 >= a1 )
return result;
v5 = *(const char **)(a2 + 8LL * a4 + 8);
if ( *v5 == 45 )
{
puts("command_parse_filter : filter parameter is nothing.");
return 0LL;
}
v6 = strlen(*(const char **)(a2 + 8LL * a4 + 8));
v7 = v6;
if ( v6 <= 0 )
return 1LL;
v8 = (unsigned int)(v6 - 1) + 2LL;
v9 = v5;
v10 = 1LL;
v15 = 0;
while ( 1 )
{
v12 = (_DWORD)v5 - 1 + v10;
if ( v5[v10 - 1] != 43 )
break;
v11 = v12 - (_DWORD)v9;
if ( v12 - (int)v9 > 0 )
goto LABEL_6;
LABEL_7:
if ( ++v10 == v8 )
goto LABEL_11;
}
if ( v7 != (_DWORD)v10 )
goto LABEL_7;
v11 = (_DWORD)v5 + v10 - (_DWORD)v9;
if ( v11 > 0 )
{
LABEL_6:
if ( (unsigned int)v11 <= 0xF )
{
*(_QWORD *)dest = 0LL;
v17 = 0LL;
strncpy(dest, v9, v11);
v13 = (__int64 *)&filter_parameter;
while ( strcmp(dest, (const char *)*v13) )
{
v13 += 2;
if ( v13 == action_parameter )
goto LABEL_20;
}
v15 |= dword_4022D8[4 * v10];
LABEL_20:
v9 = &v5[v10];
}
goto LABEL_7;
}
LABEL_11:
if ( v15 )
*(_DWORD *)(a3 + 20) = v15;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1, __int64 a2, __int64 a3, int a4)
{
__int64 result; // rax
const char *v5; // r12
int v6; // eax
int v7; // er15
__int64 v8; // r13
const char *v9; // rsi
__int64 v10; // rbx
int v11; // eax
int v12; // edx
__int64 *v13; // rbp
int v15; // [rsp+Ch] [rbp-4Ch]
char dest[8]; // [rsp+10h] [rbp-48h] BYREF
__int64 v17; // [rsp+18h] [rbp-40h]

result = 0LL;
if ( a4 >= a1 )
return result;
v5 = *(const char **)(a2 + 8LL * a4 + 8);
if ( *v5 == 45 )
{
puts("command_parse_filter : filter parameter is nothing.");
return 0LL;
}
v6 = strlen(*(const char **)(a2 + 8LL * a4 + 8));
v7 = v6;
if ( v6 <= 0 )
return 1LL;
v8 = (unsigned int)(v6 - 1) + 2LL;
v9 = v5;
v10 = 1LL;
v15 = 0;
while ( 1 )
{
v12 = (_DWORD)v5 - 1 + v10;
if ( v5[v10 - 1] != 43 )
break;
v11 = v12 - (_DWORD)v9;
if ( v12 - (int)v9 > 0 )
goto LABEL_6;
LABEL_7:
if ( ++v10 == v8 )
goto LABEL_11;
}
if ( v7 != (_DWORD)v10 )
goto LABEL_7;
v11 = (_DWORD)v5 + v10 - (_DWORD)v9;
if ( v11 > 0 )
{
LABEL_6:
if ( (unsigned int)v11 <= 0xF )
{
*(_QWORD *)dest = 0LL;
v17 = 0LL;
strncpy(dest, v9, v11);
v13 = (__int64 *)&filter_parameter;
while ( strcmp(dest, (const char *)*v13) )
{
v13 += 2;
if ( v13 == action_parameter )
goto LABEL_20;
}
v15 |= dword_4022D8[4 * v10];
LABEL_20:
v9 = &v5[v10];
}
goto LABEL_7;
}
LABEL_11:
if ( v15 )
*(_DWORD *)(a3 + 20) = v15;
return 1LL;
}

original_code:
static int command_parse_filter(int argc, char** argv, Command* data_ptr, int pos)
{
 int result = 0;
 if (pos < argc) {
  if (*argv[pos + 1] != '-') {
   int i, j;
   char buffer[16];
   unsigned int filter = 0;
   char* p_start = argv[pos + 1];
   int cch = strlen(argv[pos + 1]);
   result = 1;
   for (i = 0; i < cch; ++i) {
    char* p_temp = argv[pos + 1];
    char* p = &p_temp[i];
    int len = 0;
    if (*p == '+') {
     len = (p - p_start);
    } else if (cch == (i + 1)) {
     len = (p - p_start) + 1;
    }
    if (len > 0) {
     if ((sizeof(buffer) / sizeof(char)) > len) {
      memset(buffer, 0, sizeof(buffer));
      strncpy(buffer, p_start, len);
      for (j = 0; j < (sizeof(filter_parameter)/sizeof((filter_parameter)[0])); ++j) {
       if (strcmp(buffer, filter_parameter[j].command) == 0) {
        filter |= filter_parameter[i].value;
        break;
       }
      }
      p_start = &p_temp[i + 1];
     }
    }
   }
   if (filter != 0) {
    data_ptr->filter = filter;
   }
  } else {
   printf("command_parse_filter : filter parameter is nothing.\n");
  }
 }
 return result;
}

canonical_original_code:
static int command_parse_filter(int argc, char **argv, struct Command *data_ptr, int pos)
{
 int result = 0;
 if (pos < argc) {
  if (*argv[pos + 1] != '-') {
   int i; int j;
   char buffer[16];
   unsigned int filter = 0;
   char *p_start = argv[pos + 1];
   int cch = strlen(argv[pos + 1]);
   result = 1;
   for (i = 0; i < cch; ++i) {
    char *p_temp = argv[pos + 1];
    char *p = &p_temp[i];
    int len = 0;
    if (*p == '+') {
     len = (p - p_start);
    } else if (cch == (i + 1)) {
     len = (p - p_start) + 1;
    }
    if (len > 0) {
     if ((sizeof(buffer) / sizeof(char)) > len) {
      memset(buffer, 0, sizeof(buffer));
      strncpy(buffer, p_start, len);
      for (j = 0; j < (sizeof(filter_parameter)/sizeof((filter_parameter)[0])); ++j) {
       if (strcmp(buffer, filter_parameter[j].command) == 0) {
        filter |= filter_parameter[i].value;
        break;
       }
      }
      p_start = &p_temp[i + 1];
     }
    }
   }
   if (filter != 0) {
    data_ptr->filter = filter;
   }
  } else {
   printf("command_parse_filter : filter parameter is nothing.\n");
  }
 }
 return result;
}

variable_types: j int

variable_types:
buffer
char [16]

variable_types:
filter
unsigned int

variable_types: cch int

variable_types:
p
char *

variable_types: len int


decompiled_code:
__int64 __fastcall command_parse(int a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
int i; // ebx

result = 0LL;
if ( a3 )
{
command_init(a1, a2, a3);
if ( a1 <= 0 )
{
result = 1LL;
}
else
{
for ( i = 0; i < a1; ++i )
{
if ( *(_QWORD *)(a2 + 8LL * i) )
{
if ( !strcmp(*(const char **)(a2 + 8LL * i), "--help") )
{
i += command_parse_help((unsigned int)a1, a2, a3);
}
else if ( !strcmp(*(const char **)(a2 + 8LL * i), "--title") || !strcmp(*(const char **)(a2 + 8LL * i), "-t") )
{
i += command_parse_title(a1, a2, a3, i);
}
else if ( !strcmp(*(const char **)(a2 + 8LL * i), "--action") || !strcmp(*(const char **)(a2 + 8LL * i), "-a") )
{
i += command_parse_action(a1, a2, a3, i);
}
else if ( !strcmp(*(const char **)(a2 + 8LL * i), "--filter") || !strcmp(*(const char **)(a2 + 8LL * i), "-f") )
{
i += command_parse_filter(a1, a2, a3, i);
}
}
}
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
int i; // ebx

result = 0LL;
if ( a3 )
{
func11(a1, a2, a3);
if ( a1 <= 0 )
{
result = 1LL;
}
else
{
for ( i = 0; i < a1; ++i )
{
if ( *(_QWORD *)(a2 + 8LL * i) )
{
if ( !strcmp(*(const char **)(a2 + 8LL * i), "--help") )
{
i += func12((unsigned int)a1, a2, a3);
}
else if ( !strcmp(*(const char **)(a2 + 8LL * i), "--title") || !strcmp(*(const char **)(a2 + 8LL * i), "-t") )
{
i += func13(a1, a2, a3, i);
}
else if ( !strcmp(*(const char **)(a2 + 8LL * i), "--action") || !strcmp(*(const char **)(a2 + 8LL * i), "-a") )
{
i += func14(a1, a2, a3, i);
}
else if ( !strcmp(*(const char **)(a2 + 8LL * i), "--filter") || !strcmp(*(const char **)(a2 + 8LL * i), "-f") )
{
i += func15(a1, a2, a3, i);
}
}
}
result = 1LL;
}
}
return result;
}

original_code:
int command_parse(int argc, char** argv, Command* data_ptr)
{
 int result = 0;
 if (data_ptr != ((void *)0)) {
  int i;
  command_init(argc, argv, data_ptr);
  result = 1;
  for (i = 0; i < argc; ++i) {
   char* p = argv[i];
   if (p != ((void *)0)) {
    if (strcmp(p, "--help") == 0) {
     i += command_parse_help(argc, argv, data_ptr, i);
    } else if (strcmp(p, "--title") == 0 || strcmp(p, "-t") == 0) {
     i += command_parse_title(argc, argv, data_ptr, i);
    } else if (strcmp(p, "--action") == 0 || strcmp(p, "-a") == 0) {
     i += command_parse_action(argc, argv, data_ptr, i);
    } else if (strcmp(p, "--filter") == 0 || strcmp(p, "-f") == 0) {
     i += command_parse_filter(argc, argv, data_ptr, i);
    }
   }
  }
 }
 return result;
}

canonical_original_code:
int command_parse(int argc, char **argv, struct Command *data_ptr)
{
 int result = 0;
 if (data_ptr != ((void *)0)) {
  int i;
  command_init(argc, argv, data_ptr);
  result = 1;
  for (i = 0; i < argc; ++i) {
   char *p = argv[i];
   if (p != ((void *)0)) {
    if (strcmp(p, "--help") == 0) {
     i += command_parse_help(argc, argv, data_ptr, i);
    } else if (strcmp(p, "--title") == 0 || strcmp(p, "-t") == 0) {
     i += command_parse_title(argc, argv, data_ptr, i);
    } else if (strcmp(p, "--action") == 0 || strcmp(p, "-a") == 0) {
     i += command_parse_action(argc, argv, data_ptr, i);
    } else if (strcmp(p, "--filter") == 0 || strcmp(p, "-f") == 0) {
     i += command_parse_filter(argc, argv, data_ptr, i);
    }
   }
  }
 }
 return result;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v5; // [rsp+10h] [rbp-28h]
__int64 v6; // [rsp+18h] [rbp-20h]
__int64 v7; // [rsp+20h] [rbp-18h]

v4[0] = 0LL;
v4[1] = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
if ( (unsigned int)command_parse(argc, (__int64)argv, (__int64)v4) )
{
if ( (_WORD)v5 )
{
if ( (_WORD)v5 == 1 )
help(v4);
else
puts("main : cmd.mode is unexpected.");
}
else
{
exec((__int64)v4);
}
}
else
{
puts("main : parse_command is failed.");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v5; // [rsp+10h] [rbp-28h]
__int64 v6; // [rsp+18h] [rbp-20h]
__int64 v7; // [rsp+20h] [rbp-18h]

v4[0] = 0LL;
v4[1] = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
if ( (unsigned int)func16(argc, (__int64)argv, (__int64)v4) )
{
if ( (_WORD)v5 )
{
if ( (_WORD)v5 == 1 )
func18(v4);
else
puts("main : cmd.mode is unexpected.");
}
else
{
func17((__int64)v4);
}
}
else
{
puts("main : parse_command is failed.");
}
return 0;
}

original_code:
int main(int argc, char** argv)
{
 Command cmd;
 memset(&cmd, 0, sizeof(cmd));
 if (command_parse(argc, argv, &cmd) != 0) {
  switch (cmd.mode) {
   case COMMAND_MODE_EXEC: exec(&cmd); break;
   case COMMAND_MODE_HELP: help(&cmd); break;
   default:
    printf("main : cmd.mode is unexpected.\n"); break;
  }
 } else {
  printf("main : parse_command is failed.\n");
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct Command cmd;
 memset(&cmd, 0, sizeof(cmd));
 if (command_parse(argc, argv, &cmd) != 0) {
  switch (cmd.mode) {
   case COMMAND_MODE_EXEC: exec(&cmd); break;
   case COMMAND_MODE_HELP: help(&cmd); break;
   default:
    printf("main : cmd.mode is unexpected.\n"); break;
  }
 } else {
  printf("main : parse_command is failed.\n");
 }
 return 0;
}

variable_types: struct Command { int argc; char **argv; unsigned short mode; unsigned int filter; unsigned short action; char *title; }


decompiled_code:
__int64 macs_map_free_index()
{
__int64 v0; // rdx
__int64 result; // rax
__int64 v2; // rcx

v0 = (unsigned int)((_DWORD)map + 24);
result = 0LL;
v2 = 0LL;
while ( !*(_DWORD *)(v0 + 8) )
{
if ( *(_QWORD *)v0 < map[5 * v2 + 3] )
v2 = result;
++result;
v0 += 40LL;
if ( result == 4096 )
return v2;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rdx
__int64 result; // rax
__int64 v2; // rcx

v0 = (unsigned int)((_DWORD)map + 24);
result = 0LL;
v2 = 0LL;
while ( !*(_DWORD *)(v0 + 8) )
{
if ( *(_QWORD *)v0 < map[5 * v2 + 3] )
v2 = result;
++result;
v0 += 40LL;
if ( result == 4096 )
return v2;
}
return result;
}

original_code:
static size_t macs_map_free_index() {
 size_t min_index = 0;
 size_t i;
 for (i = 0; i < 4096; i++) {
  if (map[i].removed)
   return i;
  if (map[i].insert_time < map[min_index].insert_time) {
   min_index = i;
  }
 }
 return min_index;
}

canonical_original_code:
static unsigned long macs_map_free_index() {
 unsigned long min_index = 0;
 unsigned long i;
 for (i = 0; i < 4096; i++) {
  if (map[i].removed)
   return i;
  if (map[i].insert_time < map[min_index].insert_time) {
   min_index = i;
  }
 }
 return min_index;
}

variable_types:
i
unsigned long

return_type: unsigned long


decompiled_code:
_BOOL8 __fastcall macs_equal(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
__int64 s1; // [rsp+8h] [rbp-10h] BYREF

s1 = a1;
v3 = a2;
return memcmp(&s1, &v3, 6uLL) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
__int64 s1; // [rsp+8h] [rbp-10h] BYREF

s1 = a1;
v3 = a2;
return memcmp(&s1, &v3, 6uLL) == 0;
}

original_code:
static int macs_equal(mac_t m1, mac_t m2) {
 return memcmp(&m1, &m2, sizeof (mac_t)) == 0;
}

canonical_original_code:
static int macs_equal(struct mac_addr_t m1, struct mac_addr_t m2) {
 return memcmp(&m1, &m2, sizeof (mac_t)) == 0;
}

variable_types: struct mac_addr_t { unsigned char a[6]; }


decompiled_code:
__int64 __fastcall macs_map_get_index(__int64 a1, int a2)
{
unsigned __int64 v2; // rbp
__int64 v3; // rbx

v2 = (unsigned int)((_DWORD)map + 8);
v3 = 0LL;
while ( *(_DWORD *)(v2 + 24)
|| !macs_equal(
((unsigned __int64)BYTE4(a1) << 32) | ((unsigned __int64)BYTE2(a1) << 16) | (unsigned __int16)a1 | ((unsigned __int64)BYTE3(a1) << 24) | ((unsigned __int64)BYTE5(a1) << 40),
map[5 * v3])
|| *(_DWORD *)v2 != a2 )
{
++v3;
v2 += 40LL;
if ( v3 == 4096 )
return -1LL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
unsigned __int64 v2; // rbp
__int64 v3; // rbx

v2 = (unsigned int)((_DWORD)map + 8);
v3 = 0LL;
while ( *(_DWORD *)(v2 + 24)
|| !func1(
((unsigned __int64)BYTE4(a1) << 32) | ((unsigned __int64)BYTE2(a1) << 16) | (unsigned __int16)a1 | ((unsigned __int64)BYTE3(a1) << 24) | ((unsigned __int64)BYTE5(a1) << 40),
map[5 * v3])
|| *(_DWORD *)v2 != a2 )
{
++v3;
v2 += 40LL;
if ( v3 == 4096 )
return -1LL;
}
return v3;
}

original_code:
static size_t macs_map_get_index(mac_t mac, int vlan) {
 size_t i;
 for (i = 0; i < 4096; i++)
  if (!map[i].removed && macs_equal(mac, map[i].mac) && vlan == map[i].vlan)
   return i;
 return -1;
}

canonical_original_code:
static unsigned long macs_map_get_index(struct mac_addr_t mac, int vlan) {
 unsigned long i;
 for (i = 0; i < 4096; i++)
  if (!map[i].removed && macs_equal(mac, map[i].mac) && vlan == map[i].vlan)
   return i;
 return -1;
}

variable_types: vlan int

user_defined_types: struct mac_addr_t { unsigned char a[6]; }


decompiled_code:
_BOOL8 __fastcall macs_map_exists(__int64 a1, int a2)
{
return macs_map_get_index(
a1 & 0xFF00000000LL | ((unsigned __int64)BYTE3(a1) << 24) | (unsigned __int8)a1 | (unsigned __int64)((unsigned __int16)a1 & 0xFF00) | ((unsigned __int64)BYTE2(a1) << 16) | a1 & 0xFF0000000000LL,
a2) != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, int a2)
{
return func2(
a1 & 0xFF00000000LL | ((unsigned __int64)BYTE3(a1) << 24) | (unsigned __int8)a1 | (unsigned __int64)((unsigned __int16)a1 & 0xFF00) | ((unsigned __int64)BYTE2(a1) << 16) | a1 & 0xFF0000000000LL,
a2) != -1;
}

original_code:
int macs_map_exists(mac_t mac, int vlan) {
 return macs_map_get_index(mac, vlan) != -1;
}

canonical_original_code:
int macs_map_exists(struct mac_addr_t mac, int vlan) {
 return macs_map_get_index(mac, vlan) != -1;
}


decompiled_code:
__int64 __fastcall mac_is_multicast(char a1)
{
return a1 & 1;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
return a1 & 1;
}

original_code:
int mac_is_multicast(mac_t mac) {
 return mac.a[0] & 1;
}

canonical_original_code:
int mac_is_multicast(struct mac_addr_t mac) {
 return mac.a[0] & 1;
}


decompiled_code:
ssize_t slicz_read_callback()
{
int v0; // eax
ssize_t result; // rax

puts("receiving");
v0 = recv(slicz_fd, &buf, 0x5EEuLL, 0);
if ( v0 < 0 )
syserr("Slicz socket read", (char)&buf);
result = write(tap_fd, &buf, v0);
if ( (int)result < 0 )
syserr("Tap socket write", (char)&buf);
return result;
}

canonical_decompiled_code:
ssize_t func7()
{
int v0; // eax
ssize_t result; // rax

puts("receiving");
v0 = recv(slicz_fd, &buf, 0x5EEuLL, 0);
if ( v0 < 0 )
func9("Slicz socket read", (char)&buf);
result = write(tap_fd, &buf, v0);
if ( (int)result < 0 )
func9("Tap socket write", (char)&buf);
return result;
}

original_code:
void slicz_read_callback(int sock, short ev, void* arg) {
 printf("receiving\n");
 int r = recv(slicz_fd, buf, sizeof (buf), 0);
 if (r < 0) syserr("Slicz socket read");
 int w = write(tap_fd, buf, r);
 if (w < 0) syserr("Tap socket write");
}

canonical_original_code:
void slicz_read_callback(int sock, short ev, void *arg) {
 printf("receiving\n");
 int r = recv(slicz_fd, buf, sizeof (buf), 0);
 if (r < 0) syserr("Slicz socket read");
 int w = write(tap_fd, buf, r);
 if (w < 0) syserr("Tap socket write");
}

variable_types: sock int

variable_types: ev short

variable_types:
arg
void *

variable_types: r int

variable_types: w int


decompiled_code:
ssize_t tap_read_callback()
{
int v0; // eax
ssize_t result; // rax

puts("sending");
v0 = read(tap_fd, &buf, 0x5EEuLL);
if ( v0 < 0 )
syserr("Tap socket read", (char)&buf);
result = send(slicz_fd, &buf, v0, 0);
if ( (int)result < 0 )
syserr("Slicz socket write", (char)&buf);
return result;
}

canonical_decompiled_code:
ssize_t func8()
{
int v0; // eax
ssize_t result; // rax

puts("sending");
v0 = read(tap_fd, &buf, 0x5EEuLL);
if ( v0 < 0 )
func9("Tap socket read", (char)&buf);
result = send(slicz_fd, &buf, v0, 0);
if ( (int)result < 0 )
func9("Slicz socket write", (char)&buf);
return result;
}

original_code:
void tap_read_callback(int sock, short ev, void* arg) {
 printf("sending\n");
 int r = read(tap_fd, buf, sizeof (buf));
 if (r < 0) syserr("Tap socket read");
 int w = send(slicz_fd, buf, r, 0);
 if (w < 0) syserr("Slicz socket write");
}

canonical_original_code:
void tap_read_callback(int sock, short ev, void *arg) {
 printf("sending\n");
 int r = read(tap_fd, buf, sizeof (buf));
 if (r < 0) syserr("Tap socket read");
 int w = send(slicz_fd, buf, r, 0);
 if (w < 0) syserr("Slicz socket write");
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // al
int v4; // ebx
__int64 v5; // rcx
struct addrinfo *v6; // rdi
char v7; // si
sockaddr *v8; // rsi
int result; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-80h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-78h] BYREF
char dest[16]; // [rsp+40h] [rbp-48h] BYREF
__int64 v13; // [rsp+50h] [rbp-38h]
__int64 v14; // [rsp+58h] [rbp-30h]
__int64 v15; // [rsp+60h] [rbp-28h]

strcpy(tap_name, "siktap");
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "d:");
if ( v3 == -1 )
break;
if ( v3 != 100 )
fatal("Unknown option", (char)argv);
if ( strlen(optarg) > 0x31 )
fatal("Too long interface name", (char)argv);
strcpy(tap_name, optarg);
}
if ( optind >= argc )
fatal("Wrong configuration", (char)argv);
slicz_addr = strtok((char *)argv[optind], ":");
if ( !slicz_addr )
fatal("No address", (char)":");
slicz_port = strtok(0LL, ":");
if ( !slicz_port )
fatal("No port", (char)":");
v4 = open("/dev/net/tun", 2);
tap_fd = v4;
if ( v4 < 0 )
{
perror("open(/dev/net/tun)");
result = 1;
}
else
{
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
strncpy(dest, tap_name, 0x10uLL);
LOWORD(v13) = 4098;
if ( ioctl(v4, 0x400454CAuLL, dest) < 0 )
{
perror("ioctl(TUNSETIFF)");
result = 1;
}
else
{
slicz_fd = socket(2, 2, 0);
if ( slicz_fd < 0 )
syserr("socket", 2);
v5 = 12LL;
v6 = &req;
while ( v5 )
{
v6->ai_flags = 0;
v6 = (struct addrinfo *)((char *)v6 + 4);
--v5;
}
req.ai_family = 2;
req.ai_socktype = 2;
v7 = (char)slicz_port;
if ( getaddrinfo(slicz_addr, slicz_port, &req, &pai) )
syserr("getaddrinfo", v7);
v8 = pai->ai_addr;
if ( connect(slicz_fd, v8, pai->ai_addrlen) < 0 )
syserr("connect", (char)v8);
freeaddrinfo(pai);
if ( !event_base_new() )
syserr("Error creating base", (char)v8);
event_new();
event_add();
event_new();
event_add();
event_base_dispatch();
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // al
int v4; // ebx
__int64 v5; // rcx
struct addrinfo *v6; // rdi
char v7; // si
sockaddr *v8; // rsi
int result; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-80h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-78h] BYREF
char dest[16]; // [rsp+40h] [rbp-48h] BYREF
__int64 v13; // [rsp+50h] [rbp-38h]
__int64 v14; // [rsp+58h] [rbp-30h]
__int64 v15; // [rsp+60h] [rbp-28h]

strcpy(tap_name, "siktap");
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "d:");
if ( v3 == -1 )
break;
if ( v3 != 100 )
func10("Unknown option", (char)argv);
if ( strlen(optarg) > 0x31 )
func10("Too long interface name", (char)argv);
strcpy(tap_name, optarg);
}
if ( optind >= argc )
func10("Wrong configuration", (char)argv);
slicz_addr = strtok((char *)argv[optind], ":");
if ( !slicz_addr )
func10("No address", (char)":");
slicz_port = strtok(0LL, ":");
if ( !slicz_port )
func10("No port", (char)":");
v4 = open("/dev/net/tun", 2);
tap_fd = v4;
if ( v4 < 0 )
{
perror("open(/dev/net/tun)");
result = 1;
}
else
{
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
strncpy(dest, tap_name, 0x10uLL);
LOWORD(v13) = 4098;
if ( ioctl(v4, 0x400454CAuLL, dest) < 0 )
{
perror("ioctl(TUNSETIFF)");
result = 1;
}
else
{
slicz_fd = socket(2, 2, 0);
if ( slicz_fd < 0 )
func9("socket", 2);
v5 = 12LL;
v6 = &req;
while ( v5 )
{
v6->ai_flags = 0;
v6 = (struct addrinfo *)((char *)v6 + 4);
--v5;
}
req.ai_family = 2;
req.ai_socktype = 2;
v7 = (char)slicz_port;
if ( getaddrinfo(slicz_addr, slicz_port, &req, &pai) )
func9("getaddrinfo", v7);
v8 = pai->ai_addr;
if ( connect(slicz_fd, v8, pai->ai_addrlen) < 0 )
func9("connect", (char)v8);
freeaddrinfo(pai);
if ( !event_base_new() )
func9("Error creating base", (char)v8);
event_new();
event_add();
event_new();
event_add();
event_base_dispatch();
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char** argv) {
 char opt;
 control_port = 42420;
 int was_c = 0;
 while ((opt = getopt(argc, argv, "c:p:")) != -1) {
  if (opt == 'c') {
   if (!was_c) {
    control_port = atoi(optarg);
    was_c = 1;
   } else {
    fatal("There should be one -c flag");
   }
  } else if (opt != 'p') {
   fatal("Wrong parameter");
  }
 }
 slicz_start();
 optind = 1;
 while ((opt = getopt(argc, argv, "c:p:")) != -1) {
  if (opt == 'p') {
   if (setconfig(optarg) != 0)
    fatal("Invalid configuration: %s", optarg);
  }
 }
 event_base_dispatch(base);
}

canonical_original_code:
int main(int argc, char **argv) {
 char opt;
 control_port = 42420;
 int was_c = 0;
 while ((opt = getopt(argc, argv, "c:p:")) != -1) {
  if (opt == 'c') {
   if (!was_c) {
    control_port = atoi(optarg);
    was_c = 1;
   } else {
    fatal("There should be one -c flag");
   }
  } else if (opt != 'p') {
   fatal("Wrong parameter");
  }
 }
 slicz_start();
 optind = 1;
 while ((opt = getopt(argc, argv, "c:p:")) != -1) {
  if (opt == 'p') {
   if (setconfig(optarg) != 0)
    fatal("Invalid configuration: %s", optarg);
  }
 }
 event_base_dispatch(base);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt char


syserr

decompiled_code:
void __noreturn syserr(char *format, ...)
{
int *v1; // rbx
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
v1 = __errno_location();
v2 = strerror(*v1);
fprintf(stderr, " (%d; %s)\n", (unsigned int)*v1, v2);
exit(1);
}

canonical_decompiled_code:
void __noreturn func9(char *format, ...)
{
int *v1; // rbx
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
v1 = __errno_location();
v2 = strerror(*v1);
fprintf(stderr, " (%d; %s)\n", (unsigned int)*v1, v2);
exit(1);
}

original_code:
void syserr(const char *fmt, ...) {
 va_list fmt_args;
 fprintf(stderr, "ERROR: ");
 __builtin_va_start(fmt_args,fmt);
 vfprintf(stderr, fmt, fmt_args);
 __builtin_va_end(fmt_args);
 fprintf(stderr, " (%d; %s)\n", (*__errno_location ()), strerror((*__errno_location ())));
 exit(1);
}

canonical_original_code:
void syserr(char *fmt, ...) {
 __builtin_va_list fmt_args;
 fprintf(stderr, "ERROR: ");
 __builtin_va_start(fmt_args,fmt);
 vfprintf(stderr, fmt, fmt_args);
 __builtin_va_end(fmt_args);
 fprintf(stderr, " (%d; %s)\n", (*__errno_location ()), strerror((*__errno_location ())));
 exit(1);
}

variable_types:
fmt
char *


fatal

decompiled_code:
void __noreturn fatal(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func10(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

original_code:
void fatal(const char *fmt, ...) {
 va_list fmt_args;
 fprintf(stderr, "ERROR: ");
 __builtin_va_start(fmt_args,fmt);
 vfprintf(stderr, fmt, fmt_args);
 __builtin_va_end(fmt_args);
 fprintf(stderr, "\n");
 exit(1);
}

canonical_original_code:
void fatal(char *fmt, ...) {
 __builtin_va_list fmt_args;
 fprintf(stderr, "ERROR: ");
 __builtin_va_start(fmt_args,fmt);
 vfprintf(stderr, fmt, fmt_args);
 __builtin_va_end(fmt_args);
 fprintf(stderr, "\n");
 exit(1);
}


decompiled_code:
_BOOL8 __fastcall frame_is_tagged(__int64 a1)
{
return *(_WORD *)(a1 + 12) == (unsigned __int16)_bswap_16(33024);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return *(_WORD *)(a1 + 12) == (unsigned __int16)func0(33024);
}

original_code:
int frame_is_tagged(frame_t* f) {
 return f->tpid == ntohs(0x8100);
}

canonical_original_code:
int frame_is_tagged(struct frame *f) {
 return f->tpid == ntohs(0x8100);
}

variable_types: struct frame { struct mac_addr_t { unsigned char a[6]; } dst_mac; struct mac_addr_t src_mac; unsigned short tpid; unsigned short tci; char content[1502]; unsigned long content_len; } *

user_defined_types: struct frame { struct mac_addr_t dst_mac; struct mac_addr_t src_mac; unsigned short tpid; unsigned short tci; char content[1502]; unsigned long content_len; }


decompiled_code:
__int64 __fastcall frame_vlan(__int64 a1)
{
return _bswap_16(*(_WORD *)(a1 + 14)) & 0xFFF;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return func0(*(_WORD *)(a1 + 14)) & 0xFFF;
}

original_code:
int frame_vlan(frame_t* f) {
 return ntohs(f->tci) & 4095U;
}

canonical_original_code:
int frame_vlan(struct frame *f) {
 return ntohs(f->tci) & 4095U;
}


decompiled_code:
char *__fastcall frame_from_str(void *src, size_t n)
{
char *v2; // rbx

v2 = (char *)malloc(0x5F6uLL);
memcpy(v2, src, n);
*(_QWORD *)(v2 + 1518) = n - 16;
if ( !frame_is_tagged((__int64)v2) )
{
*(_QWORD *)(v2 + 1518) = n - 12;
memmove(v2 + 24416, v2 + 18312, n - 12);
}
return v2;
}

original_code:
frame_t* frame_from_str(char* buf, size_t len) {
 frame_t* f = malloc(sizeof (frame_t));
 memcpy(f, buf, len);
 f->content_len = len - 16;
 if (!frame_is_tagged(f)) {
  f->content_len = len - 12;
  memmove(f + 16, f + 12, f->content_len);
 }
 return f;
}

canonical_original_code:
struct frame *frame_from_str(char *buf, unsigned long len) {
 struct frame *f = malloc(sizeof (frame_t));
 memcpy(f, buf, len);
 f->content_len = len - 16;
 if (!frame_is_tagged(f)) {
  f->content_len = len - 12;
  memmove(f + 16, f + 12, f->content_len);
 }
 return f;
}

variable_types:
buf
char *

variable_types:
len
unsigned long

return_type: struct frame { struct mac_addr_t { unsigned char a[6]; } dst_mac; struct mac_addr_t src_mac; unsigned short tpid; unsigned short tci; char content[1502]; unsigned long content_len; } *


original_code:
size_t frame_to_str(frame_t* f, char* buf) {
 buf = (char*) f;
 size_t len = 16;
 if (!frame_is_tagged(f)) {
  memmove(buf + 12, buf + 16, f->content_len);
  len = 12;
 }
 len += f->content_len;
 return len;
}

canonical_original_code:
unsigned long frame_to_str(struct frame *f, char *buf) {
 buf = (char *) f;
 unsigned long len = 16;
 if (!frame_is_tagged(f)) {
  memmove(buf + 12, buf + 16, f->content_len);
  len = 12;
 }
 len += f->content_len;
 return len;
}


decompiled_code:
__int16 __fastcall frame_set_vlan(__int64 a1, __int16 a2)
{
__int16 result; // ax

if ( !frame_is_tagged(a1) )
*(_WORD *)(a1 + 12) = _bswap_16(33024);
result = _bswap_16(a2 & 0xFFF);
*(_WORD *)(a1 + 14) = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func5(__int64 a1, __int16 a2)
{
__int16 result; // ax

if ( !func1(a1) )
*(_WORD *)(a1 + 12) = func0(33024);
result = func0(a2 & 0xFFF);
*(_WORD *)(a1 + 14) = result;
return result;
}

original_code:
void frame_set_vlan(frame_t* f, int vlan) {
 if (!frame_is_tagged(f)) {
  f->tpid = htons(0x8100);
 }
 f->tci = htons(vlan & 4095U);
}

canonical_original_code:
void frame_set_vlan(struct frame *f, int vlan) {
 if (!frame_is_tagged(f)) {
  f->tpid = htons(0x8100);
 }
 f->tci = htons(vlan & 4095U);
}


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

result = frame_is_tagged(a1);
if ( result )
*(_WORD *)(a1 + 12) = 0;
return result;
}

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

result = func1(a1);
if ( result )
*(_WORD *)(a1 + 12) = 0;
return result;
}

original_code:
void frame_untag(frame_t* f) {
 if (frame_is_tagged(f))
  f->tpid = 0;
}

canonical_original_code:
void frame_untag(struct frame *f) {
 if (frame_is_tagged(f))
  f->tpid = 0;
}