decompiled_code:
int __fastcall sphere_dump(__int64 a1)
{
sceneobj_dump();
fprintf(
stderr,
"Center coordinates: %lf, %lf, %lf\n",
**(double **)(a1 + 24),
*(double *)(*(_QWORD *)(a1 + 24) + 8LL),
*(double *)(*(_QWORD *)(a1 + 24) + 16LL));
return fprintf(stderr, "Radius: %lf\n\n", *(double *)(*(_QWORD *)(a1 + 24) + 24LL));
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
sceneobj_dump();
fprintf(
stderr,
"Center coordinates: %lf, %lf, %lf\n",
**(double **)(a1 + 24),
*(double *)(*(_QWORD *)(a1 + 24) + 8LL),
*(double *)(*(_QWORD *)(a1 + 24) + 16LL));
return fprintf(stderr, "Radius: %lf\n\n", *(double *)(*(_QWORD *)(a1 + 24) + 24LL));
}

original_code:
void sphere_dump(obj_t *obj){
   sceneobj_dump((obj_t *) obj);
   fprintf(stderr, "Center coordinates:  %lf, %lf, %lf\n", ((sphere_t *) obj->typeData)->center.x, ((sphere_t *) obj->typeData)->center.y, ((sphere_t *) obj->typeData)->center.z);
   fprintf(stderr, "Radius:  %lf\n\n", ((sphere_t *) obj->typeData)->radius);
   return;
}

canonical_original_code:
void sphere_dump(struct obj_type *obj){
   sceneobj_dump((struct obj_type *) obj);
   fprintf(stderr, "Center coordinates:  %lf, %lf, %lf\n", ((struct sphere_type *) obj->typeData)->center.x, ((struct sphere_type *) obj->typeData)->center.y, ((struct sphere_type *) obj->typeData)->center.z);
   fprintf(stderr, "Radius:  %lf\n\n", ((struct sphere_type *) obj->typeData)->radius);
   return;
}

user_defined_types: struct sphere_type { struct triple center; double radius; void *priv; }


repo: Kuwagata/Raytracer

original_code:
obj_t *find_closest_obj(list_t *scene, triple_t *base, triple_t *unitDir, obj_t *lasthit){
   obj_t *obj;
   obj_t *clstobj;
   double dist;
   l_reset(scene);
   clstobj = ((void *)0);
   obj = ((void *)0);
   dist = 0;
   while ((obj = ((obj_t *)l_get(scene))) != ((void *)0))
   {
      if(obj != lasthit) {
         dist = obj->sceneData->hits(base, unitDir, obj);
         if(dist > 0) {
            if(clstobj == ((void *)0)) {
               clstobj = obj;
            }
            else {
               if(dist < clstobj->sceneData->distance){
                  clstobj = obj;
               }
            }
         }
      }
   }
   return clstobj;
}

canonical_original_code:
struct obj_type *find_closest_obj(struct list *scene, struct triple *base, struct triple *unitDir, struct obj_type *lasthit){
   struct obj_type *obj;
   struct obj_type *clstobj;
   double dist;
   l_reset(scene);
   clstobj = ((void *)0);
   obj = ((void *)0);
   dist = 0;
   while ((obj = ((struct obj_type *)l_get(scene))) != ((void *)0))
   {
      if(obj != lasthit) {
         dist = obj->sceneData->hits(base, unitDir, obj);
         if(dist > 0) {
            if(clstobj == ((void *)0)) {
               clstobj = obj;
            }
            else {
               if(dist < clstobj->sceneData->distance){
                  clstobj = obj;
               }
            }
         }
      }
   }
   return clstobj;
}

variable_types: struct list { struct node { struct node *next; void *object; } *head; struct node *tail; struct node *position; } *

variable_types:
base
struct triple *

variable_types:
unitDir
struct triple *

variable_types:
lasthit
struct obj_type *

variable_types: struct obj_type { struct obj_type *next; int objid; int objcat; char *objclass; void *typeData; union { struct sceneobj { struct triple { double x; double y; double z; } color; double diffuse; double specular; double (*hits)(struct triple *base, struct triple *dir, struct obj_type *obj); struct triple (*getcolor)(struct obj_type *obj); double (*getdiffuse)(struct obj_type *obj); double (*getspecular)(struct obj_type *obj); struct triple hitloc; struct triple normal; double distance; } *sceneData; struct lightobj { struct triple emissivity; struct triple center; } *lightData; }; } *

variable_types: dist double

user_defined_types: struct list { struct node *head; struct node *tail; struct node *position; }

user_defined_types: struct obj_type { struct obj_type *next; int objid; int objcat; char *objclass; void *typeData; union { struct sceneobj *sceneData; struct lightobj *lightData; }; }

user_defined_types: struct sceneobj { struct triple color; double diffuse; double specular; double (*hits)(struct triple *base, struct triple *dir, struct obj_type *obj); struct triple (*getcolor)(struct obj_type *obj); double (*getdiffuse)(struct obj_type *obj); double (*getspecular)(struct obj_type *obj); struct triple hitloc; struct triple normal; double distance; }


original_code:
void ray_trace(model_t *model, triple_t *base, triple_t *unitDir, triple_t *intensity, double total_dist, obj_t *last_hit){
   obj_t *closest;
   triple_t dist;
   triple_t diff_ill;
   triple_t reflected_intensity;
   triple_t v;
   triple_t u;
   triple_t n;
   triple_t temp;
   double specular;
   diff_ill = tl_scale3(&diff_ill, 0);
   dist = tl_scale3(&dist, 0);
   closest = find_closest_obj(model->scene, base, unitDir, last_hit);
   if(closest == ((void *)0))
      return;
   specular = closest->sceneData->getspecular(closest);
   dist = tl_diff3(&closest->sceneData->hitloc, base);
   total_dist += tl_length3(&dist);
   *intensity = closest->sceneData->getcolor(closest);
   diff_ill = diffuse_illumination(model, closest);
   *intensity = tl_sum3(intensity, &diff_ill);
   *intensity = tl_scale3(intensity, (1/(total_dist)));
   if(specular != 0) {
      reflected_intensity = tl_scale3(&reflected_intensity, 0);
      u = tl_scale3(unitDir, -1);
      u = tl_unitvec3(&u);
      n = tl_unitvec3(&closest->sceneData->normal);
      temp = tl_scale3(&n, 2 * tl_dot3(&u, &n));
      v = tl_diff3(&temp, &u);
      v = tl_unitvec3(&v);
      ray_trace(model, &closest->sceneData->hitloc, &v, &reflected_intensity, total_dist, closest);
      reflected_intensity = tl_scale3(&reflected_intensity, specular);
      *intensity = tl_sum3(intensity, &reflected_intensity);
   }
}

canonical_original_code:
void ray_trace(struct model_type *model, struct triple *base, struct triple *unitDir, struct triple *intensity, double total_dist, struct obj_type *last_hit){
   struct obj_type *closest;
   struct triple dist;
   struct triple diff_ill;
   struct triple reflected_intensity;
   struct triple v;
   struct triple u;
   struct triple n;
   struct triple temp;
   double specular;
   diff_ill = tl_scale3(&diff_ill, 0);
   dist = tl_scale3(&dist, 0);
   closest = find_closest_obj(model->scene, base, unitDir, last_hit);
   if(closest == ((void *)0))
      return;
   specular = closest->sceneData->getspecular(closest);
   dist = tl_diff3(&closest->sceneData->hitloc, base);
   total_dist += tl_length3(&dist);
   *intensity = closest->sceneData->getcolor(closest);
   diff_ill = diffuse_illumination(model, closest);
   *intensity = tl_sum3(intensity, &diff_ill);
   *intensity = tl_scale3(intensity, (1/(total_dist)));
   if(specular != 0) {
      reflected_intensity = tl_scale3(&reflected_intensity, 0);
      u = tl_scale3(unitDir, -1);
      u = tl_unitvec3(&u);
      n = tl_unitvec3(&closest->sceneData->normal);
      temp = tl_scale3(&n, 2 * tl_dot3(&u, &n));
      v = tl_diff3(&temp, &u);
      v = tl_unitvec3(&v);
      ray_trace(model, &closest->sceneData->hitloc, &v, &reflected_intensity, total_dist, closest);
      reflected_intensity = tl_scale3(&reflected_intensity, specular);
      *intensity = tl_sum3(intensity, &reflected_intensity);
   }
}

variable_types: struct model_type { struct environment { int samples; int winPWidth; int winPHeight; double winWWidth; double winWHeight; struct triple { double x; double y; double z; } view_point; } *env; struct list { struct node { struct node *next; void *object; } *head; struct node *tail; struct node *position; } *lights; struct list *scene; } *

variable_types:
intensity
struct triple *

variable_types: struct obj_type { struct obj_type *next; int objid; int objcat; char *objclass; void *typeData; union { struct sceneobj { struct triple color; double diffuse; double specular; double (*hits)(struct triple *base, struct triple *dir, struct obj_type *obj); struct triple (*getcolor)(struct obj_type *obj); double (*getdiffuse)(struct obj_type *obj); double (*getspecular)(struct obj_type *obj); struct triple hitloc; struct triple normal; double distance; } *sceneData; struct lightobj { struct triple emissivity; struct triple center; } *lightData; }; } *

variable_types: specular double

return_type: void

user_defined_types: struct model_type { struct environment *env; struct list *lights; struct list *scene; }

user_defined_types: struct environment { int samples; int winPWidth; int winPHeight; double winWWidth; double winWHeight; struct triple view_point; }


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

result = malloc(0x18uLL);
if ( !result )
_assert_fail("(newlist = malloc(sizeof(list_t))) != NULL", "list.c", 8u, "l_new");
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

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

result = malloc(0x18uLL);
if ( !result )
_assert_fail("(newlist = malloc(sizeof(list_t))) != NULL", "list.c", 8u, "l_new");
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
list_t *l_new() {
   list_t *newlist;
   ((void) sizeof (((newlist = malloc(sizeof(list_t))) != ((void *)0)) ? 1 : 0), __extension__ ({ if ((newlist = malloc(sizeof(list_t))) != ((void *)0)) ; else __assert_fail ("(newlist = malloc(sizeof(list_t))) != NULL", "list.c", 8, __extension__ __PRETTY_FUNCTION__); }));
   newlist->head = ((void *)0);
   newlist->tail = ((void *)0);
   newlist->position = ((void *)0);
   return(newlist);
}

canonical_original_code:
struct list *l_new() {
   struct list *newlist;
   ((void) sizeof (((newlist = malloc(sizeof(list_t))) != ((void *)0)) ? 1 : 0), __extension__ ({ if ((newlist = malloc(sizeof(list_t))) != ((void *)0)) ; else __assert_fail ("(newlist = malloc(sizeof(list_t))) != NULL", "list.c", 8, __extension__ __PRETTY_FUNCTION__); }));
   newlist->head = ((void *)0);
   newlist->tail = ((void *)0);
   newlist->position = ((void *)0);
   return(newlist);
}

return_type: struct list { struct node { struct node *next; void *object; } *head; struct node *tail; struct node *position; } *


original_code:
double cylinder_hits(triple_t *base, triple_t *dir, obj_t *obj) {
   cyl_t *cylinder = (cyl_t *) obj->typeData;
   double t = 0;
   double a = 0;
   double b = 0;
   double c = 0;
   double discriminant = 0;
   triple_t B = tl_diff3(base, &cylinder->center);
   triple_t D = *dir;
   triple_t H;
   triple_t N;
   triple_t temp;
   B = tl_xform3(cylinder->rotate, &B);
   D = tl_xform3(cylinder->rotate, &D);
   a = (D.x * D.x) + (D.z * D.z);
   b = 2 * ((B.x * D.x) + (B.z * D.z));
   c = ((B.x * B.x) + (B.z * B.z)) - (cylinder->radius * cylinder->radius);
   if((discriminant = ((b * b) - 4 * a * c)) < 0)
      return -1;
   t = ((-b) - sqrt(discriminant)) / (2 * a);
   temp = tl_scale3(&D, t);
   H = tl_sum3(&B, &temp);
   if((H.y < 0)||(H.y > cylinder->height)) {
      t = ((-b) + sqrt(discriminant)) / (2 * a);
      temp = tl_scale3(&D, t);
      H = tl_sum3(&B, &temp);
      if((H.y < 0)||(H.y > cylinder->height))
         return -1;
   }
   N.x = H.x;
   N.y = 0;
   N.z = H.z;
   N = tl_unitvec3(&H);
   H = tl_xform3(cylinder->irotate, &H);
   N = tl_xform3(cylinder->irotate, &N);
   H = tl_sum3(&H, &cylinder->center);
   if(H.z > 0)
      return -1;
   obj->sceneData->hitloc = H;
   obj->sceneData->normal = N;
   return t;
}

canonical_original_code:
double cylinder_hits(struct triple *base, struct triple *dir, struct obj_type *obj) {
   struct cylinder_type *cylinder = (cyl_t *) obj->typeData;
   double t = 0;
   double a = 0;
   double b = 0;
   double c = 0;
   double discriminant = 0;
   struct triple B = tl_diff3(base, &cylinder->center);
   struct triple D = *dir;
   struct triple H;
   struct triple N;
   struct triple temp;
   B = tl_xform3(cylinder->rotate, &B);
   D = tl_xform3(cylinder->rotate, &D);
   a = (D.x * D.x) + (D.z * D.z);
   b = 2 * ((B.x * D.x) + (B.z * D.z));
   c = ((B.x * B.x) + (B.z * B.z)) - (cylinder->radius * cylinder->radius);
   if((discriminant = ((b * b) - 4 * a * c)) < 0)
      return -1;
   t = ((-b) - sqrt(discriminant)) / (2 * a);
   temp = tl_scale3(&D, t);
   H = tl_sum3(&B, &temp);
   if((H.y < 0)||(H.y > cylinder->height)) {
      t = ((-b) + sqrt(discriminant)) / (2 * a);
      temp = tl_scale3(&D, t);
      H = tl_sum3(&B, &temp);
      if((H.y < 0)||(H.y > cylinder->height))
         return -1;
   }
   N.x = H.x;
   N.y = 0;
   N.z = H.z;
   N = tl_unitvec3(&H);
   H = tl_xform3(cylinder->irotate, &H);
   N = tl_xform3(cylinder->irotate, &N);
   H = tl_sum3(&H, &cylinder->center);
   if(H.z > 0)
      return -1;
   obj->sceneData->hitloc = H;
   obj->sceneData->normal = N;
   return t;
}

variable_types: struct triple { double x; double y; double z; } *

variable_types:
dir
struct triple *

variable_types: struct cylinder_type { struct triple { double x; double y; double z; } center; struct triple centerline; double radius; double height; struct triple rotate[3]; struct triple irotate[3]; } *

variable_types: t double

variable_types: a double

variable_types: b double

variable_types: c double

variable_types: discriminant double

return_type: double

user_defined_types: struct cylinder_type { struct triple center; struct triple centerline; double radius; double height; struct triple rotate[3]; struct triple irotate[3]; }

user_defined_types: struct lightobj { struct triple emissivity; struct triple center; }


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

v1 = *(_QWORD *)(a1 + 24);
object_dump();
fwrite("Cylinder data:\n", 1uLL, 0xFuLL, stderr);
tl_print3("Center: ", v1);
tl_print3("Centerline: ", v1 + 24);
fprintf(stderr, "Cylinder radius: %lf\n", *(double *)(v1 + 48));
fprintf(stderr, "Cylinder height: %lf\n", *(double *)(v1 + 56));
fwrite("Rotation Matrix: \n", 1uLL, 0x12uLL, stderr);
tl_print3(&unk_7E8, v1 + 64);
tl_print3(&unk_7E8, v1 + 88);
tl_print3(&unk_7E8, v1 + 112);
fwrite("Inverse Matrix: \n", 1uLL, 0x11uLL, stderr);
tl_print3(&unk_7E8, v1 + 136);
tl_print3(&unk_7E8, v1 + 160);
tl_print3(&unk_7E8, v1 + 184);
return fputc(10, stderr);
}

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

v1 = *(_QWORD *)(a1 + 24);
object_dump();
fwrite("Cylinder data:\n", 1uLL, 0xFuLL, stderr);
tl_print3("Center: ", v1);
tl_print3("Centerline: ", v1 + 24);
fprintf(stderr, "Cylinder radius: %lf\n", *(double *)(v1 + 48));
fprintf(stderr, "Cylinder height: %lf\n", *(double *)(v1 + 56));
fwrite("Rotation Matrix: \n", 1uLL, 0x12uLL, stderr);
tl_print3(&unk_7E8, v1 + 64);
tl_print3(&unk_7E8, v1 + 88);
tl_print3(&unk_7E8, v1 + 112);
fwrite("Inverse Matrix: \n", 1uLL, 0x11uLL, stderr);
tl_print3(&unk_7E8, v1 + 136);
tl_print3(&unk_7E8, v1 + 160);
tl_print3(&unk_7E8, v1 + 184);
return fputc(10, stderr);
}

original_code:
void cylinder_dump(obj_t *obj) {
      cyl_t *cylinder = (cyl_t *) obj->typeData;
   object_dump(obj);
   fprintf(stderr, "Cylinder data:\n");
   tl_print3("Center: ", &cylinder->center);
   tl_print3("Centerline: ", &cylinder->centerline);
   fprintf(stderr, "Cylinder radius:     %lf\n", cylinder->radius);
   fprintf(stderr, "Cylinder height:     %lf\n", cylinder->height);
   fprintf(stderr, "Rotation Matrix: \n");
   tl_print3("", &cylinder->rotate[0]);
   tl_print3("", &cylinder->rotate[1]);
   tl_print3("", &cylinder->rotate[2]);
   fprintf(stderr, "Inverse Matrix: \n");
   tl_print3("", &cylinder->irotate[0]);
   tl_print3("", &cylinder->irotate[1]);
   tl_print3("", &cylinder->irotate[2]);
   fprintf(stderr, "\n");
}

canonical_original_code:
void cylinder_dump(struct obj_type *obj) {
      struct cylinder_type *cylinder = (cyl_t *) obj->typeData;
   object_dump(obj);
   fprintf(stderr, "Cylinder data:\n");
   tl_print3("Center: ", &cylinder->center);
   tl_print3("Centerline: ", &cylinder->centerline);
   fprintf(stderr, "Cylinder radius:     %lf\n", cylinder->radius);
   fprintf(stderr, "Cylinder height:     %lf\n", cylinder->height);
   fprintf(stderr, "Rotation Matrix: \n");
   tl_print3("", &cylinder->rotate[0]);
   tl_print3("", &cylinder->rotate[1]);
   tl_print3("", &cylinder->rotate[2]);
   fprintf(stderr, "Inverse Matrix: \n");
   tl_print3("", &cylinder->irotate[0]);
   tl_print3("", &cylinder->irotate[1]);
   tl_print3("", &cylinder->irotate[2]);
   fprintf(stderr, "\n");
}

user_defined_types: struct triple { double x; double y; double z; }


original_code:
triple_t pp_getcolor(obj_t *obj) {
   plane_t *plane = (plane_t *) obj->typeData;
   polygon_t *polygon = (polygon_t *) plane->priv;
   pplane_t *pplane = (pplane_t *) polygon->priv;
   double relx;
   double rely;
   triple_t newhit;
   triple_t color;
   newhit = tl_diff3(&obj->sceneData->hitloc, &plane->point);
   newhit = tl_xform3(pplane->rotate, &newhit);
   relx = newhit.x / pplane->tilewidth;
   relx = relx - (int)relx;
   rely = newhit.y / pplane->tileheight;
   rely = rely - (int)rely;
   relx *= pplane->imagewidth;
   rely = 1 - rely;
   rely *= pplane->imageheight;
   relx = (int) relx;
   rely = (int) rely;
   color.x = pplane->imageData[(int)((rely * pplane->imagewidth) + relx)].r;
   color.y = pplane->imageData[(int)((rely * pplane->imagewidth) + relx)].g;
   color.z = pplane->imageData[(int)((rely * pplane->imagewidth) + relx)].b;
   color.x = (double) color.x / 30;
   color.y = (double) color.y / 30;
   color.z = (double) color.z / 30;
   return color;
}

canonical_original_code:
struct triple pp_getcolor(struct obj_type *obj) {
   struct plane_type *plane = (plane_t *) obj->typeData;
   struct polygon_type *polygon = (polygon_t *) plane->priv;
   struct pplane_type *pplane = (pplane_t *) polygon->priv;
   double relx;
   double rely;
   struct triple newhit;
   struct triple color;
   newhit = tl_diff3(&obj->sceneData->hitloc, &plane->point);
   newhit = tl_xform3(pplane->rotate, &newhit);
   relx = newhit.x / pplane->tilewidth;
   relx = relx - (int)relx;
   rely = newhit.y / pplane->tileheight;
   rely = rely - (int)rely;
   relx *= pplane->imagewidth;
   rely = 1 - rely;
   rely *= pplane->imageheight;
   relx = (int) relx;
   rely = (int) rely;
   color.x = pplane->imageData[(int)((rely * pplane->imagewidth) + relx)].r;
   color.y = pplane->imageData[(int)((rely * pplane->imagewidth) + relx)].g;
   color.z = pplane->imageData[(int)((rely * pplane->imagewidth) + relx)].b;
   color.x = (double) color.x / 30;
   color.y = (double) color.y / 30;
   color.z = (double) color.z / 30;
   return color;
}

variable_types: struct plane_type { struct triple { double x; double y; double z; } point; struct triple normal; void *priv; } *

variable_types: struct polygon_type { int numEdges; struct edge_type { struct triple { double x; double y; double z; } point; struct triple edgeDir; } *edges; void *priv; } *

variable_types: struct pplane_type { struct triple { double x; double y; double z; } rotate[3]; char *filename; double tilewidth; double tileheight; int imagewidth; int imageheight; struct pixel { unsigned char r; unsigned char g; unsigned char b; } *imageData; } *

variable_types: relx double

variable_types: rely double

user_defined_types: struct plane_type { struct triple point; struct triple normal; void *priv; }

user_defined_types: struct polygon_type { int numEdges; struct edge_type *edges; void *priv; }

user_defined_types: struct pplane_type { struct triple rotate[3]; char *filename; double tilewidth; double tileheight; int imagewidth; int imageheight; struct pixel *imageData; }

user_defined_types: struct edge_type { struct triple point; struct triple edgeDir; }


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

v1 = *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + 48LL) + 16LL);
polygon_dump();
fprintf(stderr, "Filename: %s\n", *(const char **)(v1 + 72));
fprintf(stderr, "Tiling Width: %lf, Tiling Height: %lf\n", *(double *)(v1 + 80), *(double *)(v1 + 88));
fprintf(stderr, "Image Width: %d, Image Height: %d\n", *(unsigned int *)(v1 + 96), *(unsigned int *)(v1 + 100));
fwrite("Rotation Matrix:\n", 1uLL, 0x11uLL, stderr);
tl_print3(&unk_467, v1);
tl_print3(&unk_467, v1 + 24);
tl_print3(&unk_467, v1 + 48);
return fputc(10, stderr);
}

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

v1 = *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + 48LL) + 16LL);
polygon_dump();
fprintf(stderr, "Filename: %s\n", *(const char **)(v1 + 72));
fprintf(stderr, "Tiling Width: %lf, Tiling Height: %lf\n", *(double *)(v1 + 80), *(double *)(v1 + 88));
fprintf(stderr, "Image Width: %d, Image Height: %d\n", *(unsigned int *)(v1 + 96), *(unsigned int *)(v1 + 100));
fwrite("Rotation Matrix:\n", 1uLL, 0x11uLL, stderr);
tl_print3(&unk_467, v1);
tl_print3(&unk_467, v1 + 24);
tl_print3(&unk_467, v1 + 48);
return fputc(10, stderr);
}

original_code:
void pplane_dump(obj_t *obj) {
   plane_t *plane = (plane_t *) obj->typeData;
   polygon_t *polygon = (polygon_t *) plane->priv;
   pplane_t *pplane = (pplane_t *) polygon->priv;
   polygon_dump(obj);
   fprintf(stderr, "Filename: %s\n", pplane->filename);
   fprintf(stderr, "Tiling Width: %lf, Tiling Height: %lf\n", pplane->tilewidth, pplane->tileheight);
   fprintf(stderr, "Image Width: %d, Image Height: %d\n", pplane->imagewidth, pplane->imageheight);
   fprintf(stderr, "Rotation Matrix:\n");
   tl_print3("", &pplane->rotate[0]);
   tl_print3("", &pplane->rotate[1]);
   tl_print3("", &pplane->rotate[2]);
   fprintf(stderr, "\n");
}

canonical_original_code:
void pplane_dump(struct obj_type *obj) {
   struct plane_type *plane = (plane_t *) obj->typeData;
   struct polygon_type *polygon = (polygon_t *) plane->priv;
   struct pplane_type *pplane = (pplane_t *) polygon->priv;
   polygon_dump(obj);
   fprintf(stderr, "Filename: %s\n", pplane->filename);
   fprintf(stderr, "Tiling Width: %lf, Tiling Height: %lf\n", pplane->tilewidth, pplane->tileheight);
   fprintf(stderr, "Image Width: %d, Image Height: %d\n", pplane->imagewidth, pplane->imageheight);
   fprintf(stderr, "Rotation Matrix:\n");
   tl_print3("", &pplane->rotate[0]);
   tl_print3("", &pplane->rotate[1]);
   tl_print3("", &pplane->rotate[2]);
   fprintf(stderr, "\n");
}

variable_types: struct obj_type { struct obj_type *next; int objid; int objcat; char *objclass; void *typeData; union { struct sceneobj { struct triple { double x; double y; double z; } color; double diffuse; double specular; double (*hits)(struct triple *base, struct triple *dir, struct obj_type *obj); struct triple (*getcolor)(struct obj_type *obj); double (*getdiffuse)(struct obj_type *obj); double (*getspecular)(struct obj_type *obj); struct triple hitloc; struct triple normal; double distance; } *sceneData; struct lightobj { struct triple emissivity; struct triple center; } *lightData; }; } *

user_defined_types: struct pixel { unsigned char r; unsigned char g; unsigned char b; }


decompiled_code:
__int64 __fastcall plane_dump(__int64 a1)
{
sceneobj_dump();
tl_print3("Point Data: ", *(_QWORD *)(a1 + 24));
return tl_print3("Normal Data: ", *(_QWORD *)(a1 + 24) + 24LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
sceneobj_dump();
tl_print3("Point Data: ", *(_QWORD *)(a1 + 24));
return tl_print3("Normal Data: ", *(_QWORD *)(a1 + 24) + 24LL);
}

original_code:
void plane_dump(obj_t *obj){
   sceneobj_dump(obj);
   tl_print3("Point Data: ", &((plane_t *) obj->typeData)->point);
   tl_print3("Normal Data: ", &((plane_t *) obj->typeData)->normal);
   return;
}

canonical_original_code:
void plane_dump(struct obj_type *obj){
   sceneobj_dump(obj);
   tl_print3("Point Data: ", &((struct plane_type *) obj->typeData)->point);
   tl_print3("Normal Data: ", &((struct plane_type *) obj->typeData)->normal);
   return;
}


decompiled_code:
int __fastcall object_dump(__int64 a1)
{
return fprintf(
stderr,
"Dumping object %d, category %d, type %s\n",
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
*(const char **)(a1 + 16));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
return fprintf(
stderr,
"Dumping object %d, category %d, type %s\n",
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
*(const char **)(a1 + 16));
}

original_code:
void object_dump(obj_t *obj){
   fprintf(stderr, "Dumping object %d, category %d, type %s\n", obj->objid, obj->objcat, obj->objclass);
   return;
}

canonical_original_code:
void object_dump(struct obj_type *obj){
   fprintf(stderr, "Dumping object %d, category %d, type %s\n", obj->objid, obj->objcat, obj->objclass);
   return;
}


decompiled_code:
int __fastcall environment_dump(double *a1)
{
fwrite("Environment Dump:\n", 1uLL, 0x12uLL, stderr);
tl_print3(" Viewpoint: ", a1 + 4);
fprintf(stderr, " Pixel size: %8d %8d\n", *((unsigned int *)a1 + 1), *((unsigned int *)a1 + 2));
fprintf(stderr, " World size: %8.4lf %8.4lf\n", a1[2], a1[3]);
return fprintf(stderr, " Samples Taken: %d\n", *(unsigned int *)a1);
}

canonical_decompiled_code:
int __fastcall func1(double *a1)
{
fwrite("Environment Dump:\n", 1uLL, 0x12uLL, stderr);
tl_print3(" Viewpoint: ", a1 + 4);
fprintf(stderr, " Pixel size: %8d %8d\n", *((unsigned int *)a1 + 1), *((unsigned int *)a1 + 2));
fprintf(stderr, " World size: %8.4lf %8.4lf\n", a1[2], a1[3]);
return fprintf(stderr, " Samples Taken: %d\n", *(unsigned int *)a1);
}

original_code:
void environment_dump(env_t *environment) {
   fprintf(stderr, "Environment Dump:\n");
   tl_print3( "   Viewpoint: ", &environment->view_point);
   fprintf(stderr, "   Pixel size: %8d %8d\n",
          environment->winPWidth,
          environment->winPHeight);
   fprintf(stderr, "   World size: %8.4lf %8.4lf\n",
          environment->winWWidth,
          environment->winWHeight);
   fprintf(stderr, "   Samples Taken: %d\n", environment->samples);
}

canonical_original_code:
void environment_dump(struct environment *environment) {
   fprintf(stderr, "Environment Dump:\n");
   tl_print3( "   Viewpoint: ", &environment->view_point);
   fprintf(stderr, "   Pixel size: %8d %8d\n",
          environment->winPWidth,
          environment->winPHeight);
   fprintf(stderr, "   World size: %8.4lf %8.4lf\n",
          environment->winWWidth,
          environment->winWHeight);
   fprintf(stderr, "   Samples Taken: %d\n", environment->samples);
}

variable_types: struct environment { int samples; int winPWidth; int winPHeight; double winWWidth; double winWHeight; struct triple { double x; double y; double z; } view_point; } *


original_code:
triple_t map_pix_to_world (env_t *environment, int x, int y) {
   triple_t world;
   world.x = (((double)(x)/(double)(environment->winPWidth-1))*environment->winWWidth);
   world.x -= environment->winWWidth/2.0;
   world.y = (((double)(y)/(double)(environment->winPHeight-1))*environment->winWHeight);
   world.y -= environment->winWHeight/2.0;
   world.z = 0;
   return(world);
}

canonical_original_code:
struct triple map_pix_to_world(struct environment *environment, int x, int y) {
   struct triple world;
   world.x = (((double)(x)/(double)(environment->winPWidth-1))*environment->winWWidth);
   world.x -= environment->winWWidth/2.0;
   world.y = (((double)(y)/(double)(environment->winPHeight-1))*environment->winWHeight);
   world.y -= environment->winWHeight/2.0;
   world.z = 0;
   return(world);
}

variable_types: struct environment { int samples; int winPWidth; int winPHeight; double winWWidth; double winWHeight; struct triple view_point; } *

variable_types: x int

variable_types: y int

variable_types: struct triple { double x; double y; double z; }


raytest

decompiled_code:
int __fastcall raytest(__int64 a1)
{
int result; // eax
int i; // er13
double v3; // rbp
int j; // ebx
__m128i v5; // [rsp+0h] [rbp-A8h] BYREF
__int64 v6; // [rsp+10h] [rbp-98h]
__int64 v7[4]; // [rsp+20h] [rbp-88h] BYREF
__m128i v8; // [rsp+40h] [rbp-68h] BYREF
__int64 v9; // [rsp+50h] [rbp-58h]
__m128i v10; // [rsp+60h] [rbp-48h] BYREF
__int64 v11; // [rsp+70h] [rbp-38h]

result = fwrite(" col row x y length unitv.x unitv.y unitv.z\n", 1uLL, 0x3AuLL, stderr);
for ( i = 0; *(_DWORD *)(a1 + 8) > i; ++i )
{
for ( j = 0; *(_DWORD *)(a1 + 4) > j; ++j )
{
map_pix_to_world((__int64)&v5, a1, j, i);
v10 = _mm_loadu_si128(&v5);
v11 = v6;
tl_diff3(&v5, a1 + 32, &v10);
v8 = _mm_loadu_si128(&v5);
v9 = v6;
v3 = tl_length3(&v8);
tl_unitvec3(v7, &v8);
result = fprintf(
stderr,
"%4d %4d %7.3lf %7.3lf %7.3lf %7.3lf %7.3lf %7.3lf\n",
(unsigned int)j,
(unsigned int)i,
*(double *)v10.m128i_i64,
*(double *)&v10.m128i_i64[1],
v3,
*(double *)v7,
*(double *)&v7[1],
*(double *)&v7[2]);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
int result; // eax
int i; // er13
double v3; // rbp
int j; // ebx
__m128i v5; // [rsp+0h] [rbp-A8h] BYREF
__int64 v6; // [rsp+10h] [rbp-98h]
__int64 v7[4]; // [rsp+20h] [rbp-88h] BYREF
__m128i v8; // [rsp+40h] [rbp-68h] BYREF
__int64 v9; // [rsp+50h] [rbp-58h]
__m128i v10; // [rsp+60h] [rbp-48h] BYREF
__int64 v11; // [rsp+70h] [rbp-38h]

result = fwrite(" col row x y length unitv.x unitv.y unitv.z\n", 1uLL, 0x3AuLL, stderr);
for ( i = 0; *(_DWORD *)(a1 + 8) > i; ++i )
{
for ( j = 0; *(_DWORD *)(a1 + 4) > j; ++j )
{
func2((__int64)&v5, a1, j, i);
v10 = _mm_loadu_si128(&v5);
v11 = v6;
tl_diff3(&v5, a1 + 32, &v10);
v8 = _mm_loadu_si128(&v5);
v9 = v6;
v3 = tl_length3(&v8);
tl_unitvec3(v7, &v8);
result = fprintf(
stderr,
"%4d %4d %7.3lf %7.3lf %7.3lf %7.3lf %7.3lf %7.3lf\n",
(unsigned int)j,
(unsigned int)i,
*(double *)v10.m128i_i64,
*(double *)&v10.m128i_i64[1],
v3,
*(double *)v7,
*(double *)&v7[1],
*(double *)&v7[2]);
}
}
return result;
}

original_code:
void raytest(env_t *environment) {
   int column;
   int row;
   triple_t worldPix;
   triple_t directionV ;
   double len;
   triple_t directionUnitV;
   fprintf(stderr, " col  row       x       y  length unitv.x unitv.y unitv.z\n");
   for (row=0; row<environment->winPHeight; row++) {
      for (column=0; column<environment->winPWidth; column++) {
          worldPix = map_pix_to_world(environment, column, row);
          directionV = tl_diff3(&environment->view_point, &worldPix);
          len = tl_length3(&directionV);
          directionUnitV = tl_unitvec3(&directionV);
          fprintf(stderr, "%4d %4d %7.3lf %7.3lf %7.3lf %7.3lf %7.3lf %7.3lf\n",
                           column, row,
                           worldPix.x, worldPix.y,
                           len,
                           directionUnitV.x,
                           directionUnitV.y,
                           directionUnitV.z);
      }
   }
}

canonical_original_code:
void raytest(struct environment *environment) {
   int column;
   int row;
   struct triple worldPix;
   struct triple directionV;
   double len;
   struct triple directionUnitV;
   fprintf(stderr, " col  row       x       y  length unitv.x unitv.y unitv.z\n");
   for (row=0; row<environment->winPHeight; row++) {
      for (column=0; column<environment->winPWidth; column++) {
          worldPix = map_pix_to_world(environment, column, row);
          directionV = tl_diff3(&environment->view_point, &worldPix);
          len = tl_length3(&directionV);
          directionUnitV = tl_unitvec3(&directionV);
          fprintf(stderr, "%4d %4d %7.3lf %7.3lf %7.3lf %7.3lf %7.3lf %7.3lf\n",
                           column, row,
                           worldPix.x, worldPix.y,
                           len,
                           directionUnitV.x,
                           directionUnitV.y,
                           directionUnitV.z);
      }
   }
}

variable_types: column int

variable_types: row int

variable_types: len double


decompiled_code:
__int64 __fastcall model_dump(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r13
const char *v3; // r12
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // r13
const char *v7; // r12
__int64 v8; // rbx

l_reset(*(_QWORD *)(a1 + 16));
l_reset(*(_QWORD *)(a1 + 8));
while ( 1 )
{
v1 = l_get(*(_QWORD *)(a1 + 16));
v2 = v1;
if ( !v1 )
break;
v3 = *(const char **)(v1 + 16);
v4 = 0LL;
while ( strcmp(v3, (const char *)*(&helper + 3 * v4)) )
{
if ( ++v4 == 9 )
{
fwrite("Bad class\n", 1uLL, 0xAuLL, stderr);
exit(1);
}
}
(*(&helper + 3 * (int)v4 + 2))(v2);
}
while ( 1 )
{
result = l_get(*(_QWORD *)(a1 + 8));
v6 = result;
if ( !result )
break;
v7 = *(const char **)(result + 16);
v8 = 0LL;
while ( strcmp(v7, (const char *)*(&helper + 3 * v8)) )
{
if ( ++v8 == 9 )
{
fwrite("Bad class\n", 1uLL, 0xAuLL, stderr);
exit(1);
}
}
(*(&helper + 3 * (int)v8 + 2))(v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r13
const char *v3; // r12
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // r13
const char *v7; // r12
__int64 v8; // rbx

l_reset(*(_QWORD *)(a1 + 16));
l_reset(*(_QWORD *)(a1 + 8));
while ( 1 )
{
v1 = l_get(*(_QWORD *)(a1 + 16));
v2 = v1;
if ( !v1 )
break;
v3 = *(const char **)(v1 + 16);
v4 = 0LL;
while ( strcmp(v3, (const char *)*(&helper + 3 * v4)) )
{
if ( ++v4 == 9 )
{
fwrite("Bad class\n", 1uLL, 0xAuLL, stderr);
exit(1);
}
}
(*(&helper + 3 * (int)v4 + 2))(v2);
}
while ( 1 )
{
result = l_get(*(_QWORD *)(a1 + 8));
v6 = result;
if ( !result )
break;
v7 = *(const char **)(result + 16);
v8 = 0LL;
while ( strcmp(v7, (const char *)*(&helper + 3 * v8)) )
{
if ( ++v8 == 9 )
{
fwrite("Bad class\n", 1uLL, 0xAuLL, stderr);
exit(1);
}
}
(*(&helper + 3 * (int)v8 + 2))(v6);
}
return result;
}

original_code:
void model_dump(model_t *model) {
   obj_t *obj;
   int ctr;
   int flag;
   l_reset(model->scene);
   l_reset(model->lights);
   while ((obj = l_get(model->scene)) != ((void *)0))
   {
      flag = 0;
      for(ctr = 0; ctr < (sizeof(helper)/sizeof(*helper)); ctr++) {
         if(strcmp(obj->objclass, (helper[ctr]).objecttype) == 0) {
            (helper[ctr]).dump(obj);
            flag = 1;
            break;
         }
      }
      if(flag == 0) {
         fprintf(stderr, "Bad class\n");
         exit(1);
      }
   }
   while ((obj = l_get(model->lights)) != ((void *)0))
   {
      flag = 0;
      for(ctr = 0; ctr < (sizeof(helper)/sizeof(*helper)); ctr++) {
         if(strcmp(obj->objclass, helper[ctr].objecttype) == 0) {
            helper[ctr].dump(obj);
            flag = 1;
            break;
         }
      }
      if(flag == 0) {
         fprintf(stderr, "Bad class\n");
         exit(1);
      }
   }
}

canonical_original_code:
void model_dump(struct model_type *model) {
   struct obj_type *obj;
   int ctr;
   int flag;
   l_reset(model->scene);
   l_reset(model->lights);
   while ((obj = l_get(model->scene)) != ((void *)0))
   {
      flag = 0;
      for(ctr = 0; ctr < (sizeof(helper)/sizeof(*helper)); ctr++) {
         if(strcmp(obj->objclass, (helper[ctr]).objecttype) == 0) {
            (helper[ctr]).dump(obj);
            flag = 1;
            break;
         }
      }
      if(flag == 0) {
         fprintf(stderr, "Bad class\n");
         exit(1);
      }
   }
   while ((obj = l_get(model->lights)) != ((void *)0))
   {
      flag = 0;
      for(ctr = 0; ctr < (sizeof(helper)/sizeof(*helper)); ctr++) {
         if(strcmp(obj->objclass, helper[ctr].objecttype) == 0) {
            helper[ctr].dump(obj);
            flag = 1;
            break;
         }
      }
      if(flag == 0) {
         fprintf(stderr, "Bad class\n");
         exit(1);
      }
   }
}

variable_types: struct model_type { struct environment { int samples; int winPWidth; int winPHeight; double winWWidth; double winWHeight; struct triple { double x; double y; double z; } view_point; } *env; struct list { struct node { struct node *next; void *object; } *head; struct node *tail; struct node *position; } *lights; struct list *scene; } *

variable_types: ctr int

variable_types: flag int


repo: Kveri/IOUsniffer

decompiled_code:
int __fastcall display_help(const char *a1)
{
printf("Usage: %s [-h] [-i <netio_dir>] [-n <NETMAP>] ", a1);
puts("[-s <sniff_dir>] [-f] [-d [-d ...]]");
puts(&byte_5CA);
puts("Arguments:");
puts("\t-h: displays this help");
puts("\t-i <netio_dir>: Look for netio sockets in <netio_dir>");
puts("\t\t\t[default=/tmp/netio0]");
puts("\t-n <NETMAP>: Location of <NETMAP> file [default=./NETMAP]");
printf("\t-s <sniff_dir>: Directory to place sniffs to ");
puts("[default=/tmp/iousn*]");
puts("\t-o: Only sniff on links where DLT is specified");
puts("\t-f: Flush at every write to pcap");
puts("\t-d: Increase debug level (may be specified more than once)");
puts(&byte_5CA);
printf("Version: %s\n", "0.2");
return puts("Author: Martin Cechvala");
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
printf("Usage: %s [-h] [-i <netio_dir>] [-n <NETMAP>] ", a1);
puts("[-s <sniff_dir>] [-f] [-d [-d ...]]");
puts(&byte_5CA);
puts("Arguments:");
puts("\t-h: displays this help");
puts("\t-i <netio_dir>: Look for netio sockets in <netio_dir>");
puts("\t\t\t[default=/tmp/netio0]");
puts("\t-n <NETMAP>: Location of <NETMAP> file [default=./NETMAP]");
printf("\t-s <sniff_dir>: Directory to place sniffs to ");
puts("[default=/tmp/iousn*]");
puts("\t-o: Only sniff on links where DLT is specified");
puts("\t-f: Flush at every write to pcap");
puts("\t-d: Increase debug level (may be specified more than once)");
puts(&byte_5CA);
printf("Version: %s\n", "0.2");
return puts("Author: Martin Cechvala");
}

original_code:
void display_help(char *name)
{
 printf("Usage: %s [-h] [-i <netio_dir>] [-n <NETMAP>] ", name);
 printf("[-s <sniff_dir>] [-f] [-d [-d ...]]\n");
 puts("");
 puts("Arguments:");
 printf("\t-h: displays this help\n");
 printf("\t-i <netio_dir>: Look for netio sockets in <netio_dir>\n");
 printf("\t\t\t[default=/tmp/netio0]\n");
 printf("\t-n <NETMAP>: Location of <NETMAP> file [default=./NETMAP]\n");
 printf("\t-s <sniff_dir>: Directory to place sniffs to ");
 printf("[default=/tmp/iousn*]\n");
 printf("\t-o: Only sniff on links where DLT is specified\n");
 printf("\t-f: Flush at every write to pcap\n");
 printf("\t-d: Increase debug level (may be specified more than once)\n");
 puts("");
 printf("Version: %s\n", "0.2");
 printf("Author: Martin Cechvala\n");
}

variable_types:
name
char *


decompiled_code:
int __fastcall parse_arguments(int argc, char **argv)
{
char v2; // al
char *v3; // r12
size_t v4; // rax
char *v5; // r12
size_t v6; // rax
char *v7; // rax
char *v8; // r12
size_t v9; // rax
char *v10; // rax
int result; // eax
char *v12; // rax
struct stat v13; // [rsp+0h] [rbp-A8h] BYREF

config = 0LL;
*(&config + 1) = 0LL;
*(&config + 2) = 0LL;
*((_DWORD *)&config + 7) = 0;
*((_DWORD *)&config + 6) = 0;
*((_DWORD *)&config + 8) = 0;
while ( 1 )
{
v2 = getopt(argc, argv, "hi:n:s:odf");
if ( v2 == -1 )
break;
switch ( v2 )
{
case 'd':
++*((_DWORD *)&config + 6);
break;
case 'f':
*((_DWORD *)&config + 7) = 1;
break;
case 'h':
display_help(*argv);
exit(0);
case 'i':
v3 = optarg;
v4 = strlen(optarg);
config = (char *)malloc(v4 + 1);
strcpy(config, v3);
break;
case 'n':
v5 = optarg;
v6 = strlen(optarg);
v7 = (char *)malloc(v6 + 1);
*(&config + 1) = v7;
strcpy(v7, v5);
break;
case 'o':
*((_DWORD *)&config + 8) = 1;
break;
case 's':
v8 = optarg;
v9 = strlen(optarg);
v10 = (char *)malloc(v9 + 1);
*(&config + 2) = v10;
strcpy(v10, v8);
break;
default:
continue;
}
}
if ( !config )
{
config = (char *)malloc(0xCuLL);
strcpy(config, "/tmp/netio0");
}
if ( stat(config, &v13) )
{
perror("Netio socket dir access error");
result = -1;
}
else if ( (v13.st_mode & 0xF000) == 0x4000 )
{
if ( !*(&config + 1) )
{
v12 = (char *)malloc(7uLL);
*(&config + 1) = v12;
strcpy(v12, "NETMAP");
}
if ( stat(*(&config + 1), &v13) )
{
perror("NETMAP file access error");
result = -1;
}
else if ( (v13.st_mode & 0xF000) == 0x8000 )
{
if ( !*(&config + 2) )
*(&config + 2) = tempnam("/tmp", "iousniff");
result = mkdir(*(&config + 2), 0x1A4u);
if ( result )
{
stat(*(&config + 2), &v13);
if ( (v13.st_mode & 0xF000) == 0x4000 )
{
result = 0;
}
else
{
perror("Sniff path isn't a directory");
result = -1;
}
}
}
else
{
fwrite("NETMAP file isn't a regular file\n", 1uLL, 0x21uLL, stderr);
result = -1;
}
}
else
{
fwrite("Netio socket path isn't a directory", 1uLL, 0x23uLL, stderr);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int argc, char **argv)
{
char v2; // al
char *v3; // r12
size_t v4; // rax
char *v5; // r12
size_t v6; // rax
char *v7; // rax
char *v8; // r12
size_t v9; // rax
char *v10; // rax
int result; // eax
char *v12; // rax
struct stat v13; // [rsp+0h] [rbp-A8h] BYREF

config = 0LL;
*(&config + 1) = 0LL;
*(&config + 2) = 0LL;
*((_DWORD *)&config + 7) = 0;
*((_DWORD *)&config + 6) = 0;
*((_DWORD *)&config + 8) = 0;
while ( 1 )
{
v2 = getopt(argc, argv, "hi:n:s:odf");
if ( v2 == -1 )
break;
switch ( v2 )
{
case 'd':
++*((_DWORD *)&config + 6);
break;
case 'f':
*((_DWORD *)&config + 7) = 1;
break;
case 'h':
func0(*argv);
exit(0);
case 'i':
v3 = optarg;
v4 = strlen(optarg);
config = (char *)malloc(v4 + 1);
strcpy(config, v3);
break;
case 'n':
v5 = optarg;
v6 = strlen(optarg);
v7 = (char *)malloc(v6 + 1);
*(&config + 1) = v7;
strcpy(v7, v5);
break;
case 'o':
*((_DWORD *)&config + 8) = 1;
break;
case 's':
v8 = optarg;
v9 = strlen(optarg);
v10 = (char *)malloc(v9 + 1);
*(&config + 2) = v10;
strcpy(v10, v8);
break;
default:
continue;
}
}
if ( !config )
{
config = (char *)malloc(0xCuLL);
strcpy(config, "/tmp/netio0");
}
if ( stat(config, &v13) )
{
perror("Netio socket dir access error");
result = -1;
}
else if ( (v13.st_mode & 0xF000) == 0x4000 )
{
if ( !*(&config + 1) )
{
v12 = (char *)malloc(7uLL);
*(&config + 1) = v12;
strcpy(v12, "NETMAP");
}
if ( stat(*(&config + 1), &v13) )
{
perror("NETMAP file access error");
result = -1;
}
else if ( (v13.st_mode & 0xF000) == 0x8000 )
{
if ( !*(&config + 2) )
*(&config + 2) = tempnam("/tmp", "iousniff");
result = mkdir(*(&config + 2), 0x1A4u);
if ( result )
{
stat(*(&config + 2), &v13);
if ( (v13.st_mode & 0xF000) == 0x4000 )
{
result = 0;
}
else
{
perror("Sniff path isn't a directory");
result = -1;
}
}
}
else
{
fwrite("NETMAP file isn't a regular file\n", 1uLL, 0x21uLL, stderr);
result = -1;
}
}
else
{
fwrite("Netio socket path isn't a directory", 1uLL, 0x23uLL, stderr);
result = -1;
}
return result;
}

original_code:
int parse_arguments(int argc, char * argv[], char * envp[])
{
 struct stat st;
 int ret;
 char c;
 config.netio_dir = ((void *)0);
 config.netmap_file = ((void *)0);
 config.sniff_dir = ((void *)0);
 config.flush_at_write = 0;
 config.debug_level = 0;
 config.sniff_dlt_only = 0;
 while ((c = getopt(argc, argv, "hi:n:s:odf")) != -1) {
  switch (c) {
   case 'h':
    display_help(argv[0]);
    exit(0);
   case 'i':
    config.netio_dir = (char *)malloc(strlen(optarg) + 1);
    strcpy(config.netio_dir, optarg);
    break;
   case 'n':
    config.netmap_file = (char *)malloc(strlen(optarg) + 1);
    strcpy(config.netmap_file, optarg);
    break;
   case 's':
    config.sniff_dir = (char *)malloc(strlen(optarg) + 1);
    strcpy(config.sniff_dir, optarg);
    break;
   case 'o':
    config.sniff_dlt_only = 1;
    break;
   case 'f':
    config.flush_at_write = 1;
    break;
   case 'd':
    config.debug_level++;
    break;
  }
 }
 if (!config.netio_dir) {
  config.netio_dir = (char *)malloc(strlen("/tmp/netio0")+1);
  strcpy(config.netio_dir, "/tmp/netio0");
 }
 ret = stat(config.netio_dir, &st);
 if (ret) {
  perror("Netio socket dir access error");
  return -1;
 }
 if (!((((st.st_mode)) & 0170000) == (0040000))) {
  fprintf(stderr, "Netio socket path isn't a directory");
  return -1;
 }
 if (!config.netmap_file) {
  config.netmap_file = (char *)malloc(strlen("NETMAP")+1);
  strcpy(config.netmap_file, "NETMAP");
 }
 ret = stat(config.netmap_file, &st);
 if (ret) {
  perror("NETMAP file access error");
  return -1;
 }
 if (!((((st.st_mode)) & 0170000) == (0100000))) {
  fprintf(stderr, "NETMAP file isn't a regular file\n");
  return -1;
 }
 if (!config.sniff_dir)
  config.sniff_dir = tempnam("/tmp", "iousniff");
 ret = mkdir(config.sniff_dir, 0644);
 if (ret) {
  ret = stat(config.sniff_dir, &st);
  if (!((((st.st_mode)) & 0170000) == (0040000))) {
    perror("Sniff path isn't a directory");
    return -1;
  }
 }
 return 0;
}

canonical_original_code:
int parse_arguments(int argc, char *argv[], char *envp[])
{
 struct stat st;
 int ret;
 char c;
 config.netio_dir = ((void *)0);
 config.netmap_file = ((void *)0);
 config.sniff_dir = ((void *)0);
 config.flush_at_write = 0;
 config.debug_level = 0;
 config.sniff_dlt_only = 0;
 while ((c = getopt(argc, argv, "hi:n:s:odf")) != -1) {
  switch (c) {
   case 'h':
    display_help(argv[0]);
    exit(0);
   case 'i':
    config.netio_dir = (char *)malloc(strlen(optarg) + 1);
    strcpy(config.netio_dir, optarg);
    break;
   case 'n':
    config.netmap_file = (char *)malloc(strlen(optarg) + 1);
    strcpy(config.netmap_file, optarg);
    break;
   case 's':
    config.sniff_dir = (char *)malloc(strlen(optarg) + 1);
    strcpy(config.sniff_dir, optarg);
    break;
   case 'o':
    config.sniff_dlt_only = 1;
    break;
   case 'f':
    config.flush_at_write = 1;
    break;
   case 'd':
    config.debug_level++;
    break;
  }
 }
 if (!config.netio_dir) {
  config.netio_dir = (char *)malloc(strlen("/tmp/netio0")+1);
  strcpy(config.netio_dir, "/tmp/netio0");
 }
 ret = stat(config.netio_dir, &st);
 if (ret) {
  perror("Netio socket dir access error");
  return -1;
 }
 if (!((((st.st_mode)) & 0170000) == (0040000))) {
  fprintf(stderr, "Netio socket path isn't a directory");
  return -1;
 }
 if (!config.netmap_file) {
  config.netmap_file = (char *)malloc(strlen("NETMAP")+1);
  strcpy(config.netmap_file, "NETMAP");
 }
 ret = stat(config.netmap_file, &st);
 if (ret) {
  perror("NETMAP file access error");
  return -1;
 }
 if (!((((st.st_mode)) & 0170000) == (0100000))) {
  fprintf(stderr, "NETMAP file isn't a regular file\n");
  return -1;
 }
 if (!config.sniff_dir)
  config.sniff_dir = tempnam("/tmp", "iousniff");
 ret = mkdir(config.sniff_dir, 0644);
 if (ret) {
  ret = stat(config.sniff_dir, &st);
  if (!((((st.st_mode)) & 0170000) == (0040000))) {
    perror("Sniff path isn't a directory");
    return -1;
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
envp
char *[]

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: ret int

variable_types: c char

return_type: int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


debug

decompiled_code:
int debug(int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( config[6] >= a1 )
{
va_start(arg, a2);
result = vprintf(a2, arg);
}
return result;
}

canonical_decompiled_code:
int func0(int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( config[6] >= a1 )
{
va_start(arg, a2);
result = vprintf(a2, arg);
}
return result;
}

original_code:
void debug(int level, const char *format, ...)
{
    va_list args;
 if (level > config.debug_level)
  return;
    __builtin_va_start(args,format);
    vprintf(format, args);
    __builtin_va_end(args);
}

canonical_original_code:
void debug(int level, char *format, ...)
{
    __builtin_va_list args;
 if (level > config.debug_level)
  return;
    __builtin_va_start(args,format);
    vprintf(format, args);
    __builtin_va_end(args);
}

variable_types: level int

variable_types:
format
char *


decompiled_code:
int __fastcall dump_packet(__int64 a1, int a2)
{
__int64 i; // r13
int v4; // edx
int v5; // eax
int v6; // ebx
int v7; // ebx
__int64 v8; // rbx
int v9; // er14
char v10; // di

if ( a2 > 0 )
{
for ( i = 0LL; i != 16LL * (((unsigned int)(a2 - 1) >> 4) + 1); i += 16LL )
{
printf("%04x\t", (unsigned int)i);
if ( (int)i >= a2 )
{
v4 = 0;
LABEL_21:
v7 = (v4 <= 6) + 3 * (16 - v4) + 2;
goto LABEL_22;
}
v5 = i;
v6 = 1;
while ( 1 )
{
printf("%02x ", *(unsigned __int8 *)(a1 + v5));
if ( v6 != 8 )
break;
putchar(32);
v4 = 8;
LABEL_4:
v5 = i + v4;
++v6;
if ( (int)i + v4 >= a2 )
goto LABEL_21;
}
v4 = v6;
if ( v6 <= 15 )
goto LABEL_4;
v7 = 3 * (16 - v6) + 2;
if ( v7 <= 0 )
{
LABEL_24:
v8 = i;
v9 = 1;
do
{
v10 = *(_BYTE *)(a1 + v8);
if ( (unsigned __int8)(v10 - 32) > 0x5Eu )
putchar(46);
else
putchar(v10);
if ( v9 == 8 )
{
putchar(32);
}
else if ( v9 > 15 )
{
goto LABEL_16;
}
++v8;
++v9;
}
while ( a2 > (int)v8 );
goto LABEL_16;
}
do
{
LABEL_22:
putchar(32);
--v7;
}
while ( v7 > 0 );
if ( (int)i < a2 )
goto LABEL_24;
LABEL_16:
putchar(10);
}
}
return putchar(10);
}

original_code:
void dump_packet(char *buf, int len)
{
 int i, pkt_n = 0;
 while (pkt_n < len) {
  printf("%04x\t", pkt_n);
  for (i = 0; i < 16 && pkt_n+i < len; i++) {
   printf("%02x ", buf[pkt_n+i] & 0xff);
   if (i == 7)
    putchar(' ');
  }
  for (i = 3*(16-i)+2+(i<7); i > 0; i--)
   putchar(' ');
  for (i = 0; i < 16 && pkt_n+i < len; i++) {
   if (buf[pkt_n+i] >= 0x20 && buf[pkt_n+i] <= 0x7E)
    putchar(buf[pkt_n+i]);
   else
    putchar('.');
   if (i == 7)
    putchar(' ');
  }
  putchar('\n');
  pkt_n += 16;
 }
 putchar('\n');
}

canonical_original_code:
void dump_packet(char *buf, int len)
{
 int i; int pkt_n = 0;
 while (pkt_n < len) {
  printf("%04x\t", pkt_n);
  for (i = 0; i < 16 && pkt_n+i < len; i++) {
   printf("%02x ", buf[pkt_n+i] & 0xff);
   if (i == 7)
    putchar(' ');
  }
  for (i = 3*(16-i)+2+(i<7); i > 0; i--)
   putchar(' ');
  for (i = 0; i < 16 && pkt_n+i < len; i++) {
   if (buf[pkt_n+i] >= 0x20 && buf[pkt_n+i] <= 0x7E)
    putchar(buf[pkt_n+i]);
   else
    putchar('.');
   if (i == 7)
    putchar(' ');
  }
  putchar('\n');
  pkt_n += 16;
 }
 putchar('\n');
}

variable_types:
buf
char *

variable_types: len int

variable_types: i int


dirselect

repo: KypaB/OS

decompiled_code:
_BOOL8 __fastcall dirselect(const struct dirent *a1)
{
return a1->d_name[0] != 46;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(const struct dirent *a1)
{
return a1->d_name[0] != 46;
}

original_code:
int dirselect(const struct dirent *dp) {
 if(dp->d_name[0] != '.') {
  return 1;
 } else {
  return 0;
 }
}

canonical_original_code:
int dirselect(struct dirent *dp) {
 if(dp->d_name[0] != '.') {
  return 1;
 } else {
  return 0;
 }
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *


sumsize

decompiled_code:
__int64 __fastcall sumsize(char *src)
{
int v1; // eax
int v2; // ebp
__int64 v3; // r12
unsigned __int64 v4; // rbx
char v6[64]; // [rsp+0h] [rbp-108h] BYREF
struct stat v7; // [rsp+40h] [rbp-C8h] BYREF
struct dirent **namelist; // [rsp+D8h] [rbp-30h] BYREF

v1 = scandir(src, &namelist, (int (*)(const struct dirent *))dirselect, alphasort);
v2 = 0;
if ( v1 > 0 )
{
v3 = 8LL * (unsigned int)v1;
v4 = 0LL;
do
{
strcpy(v6, src);
*(_WORD *)&v6[strlen(v6)] = 47;
strcat(v6, namelist[v4 / 8]->d_name);
stat(v6, &v7);
v2 += LODWORD(v7.st_blocks);
v4 += 8LL;
}
while ( v4 != v3 );
}
return (unsigned int)(v2 / 2);
}

canonical_decompiled_code:
__int64 __fastcall func8(char *src)
{
int v1; // eax
int v2; // ebp
__int64 v3; // r12
unsigned __int64 v4; // rbx
char v6[64]; // [rsp+0h] [rbp-108h] BYREF
struct stat v7; // [rsp+40h] [rbp-C8h] BYREF
struct dirent **namelist; // [rsp+D8h] [rbp-30h] BYREF

v1 = scandir(src, &namelist, (int (*)(const struct dirent *))dirselect, alphasort);
v2 = 0;
if ( v1 > 0 )
{
v3 = 8LL * (unsigned int)v1;
v4 = 0LL;
do
{
strcpy(v6, src);
*(_WORD *)&v6[strlen(v6)] = 47;
strcat(v6, namelist[v4 / 8]->d_name);
func13(v6, &v7);
v2 += LODWORD(v7.st_blocks);
v4 += 8LL;
}
while ( v4 != v3 );
}
return (unsigned int)(v2 / 2);
}

original_code:
int sumsize(char *dirpath) {
 struct dirent **flist;
 struct stat fstat;
 int size = 0;
 int n;
 n = scandir(dirpath, &flist, dirselect, alphasort);
 if(n > 0) {
  int i;
  for(i = 0; i < n; ++i) {
   char path[50];
   strcpy(path, dirpath);
   strcat(path,"/");
   strcat(path,flist[i]->d_name);
   stat(path, &fstat);
   size += fstat.st_blocks;
  }
 }
 return size/2;
}

variable_types:
dirpath
char *

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } **

variable_types: size int

variable_types: n int

variable_types:
path
char [50]

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


printdir

decompiled_code:
void __fastcall printdir(__int64 a1, int a2, char *a3)
{
__int64 v4; // rbx
unsigned int v5; // eax
__int64 v6; // rbp
const char *v7; // rdi
const char *v8; // rdi
const char *v9; // rdi
const char *v10; // rdi
const char *v11; // rdi
const char *v12; // rdi
const char *v13; // rdi
const char *v14; // rdi
const char *v15; // rdi
const char *v16; // rdi
struct passwd *v17; // rax
struct group *v18; // rax
struct tm *v19; // rax
__int64 v20; // [rsp+8h] [rbp-130h]
char s[32]; // [rsp+10h] [rbp-128h] BYREF
char dest[2]; // [rsp+30h] [rbp-108h] BYREF
struct stat v23; // [rsp+70h] [rbp-C8h] BYREF

if ( lflag )
{
if ( multidirflag )
printf("%s:\n", a3);
v5 = sumsize(a3);
printf("total %d\n", v5);
if ( a2 > 0 )
{
v6 = a1;
v20 = a1 + 8LL * (unsigned int)(a2 - 1) + 8;
do
{
strcpy(dest, a3);
*(_WORD *)&dest[strlen(dest)] = 47;
strcat(dest, (const char *)(*(_QWORD *)v6 + 19LL));
stat(dest, &v23);
v7 = "d";
if ( (v23.st_mode & 0xF000) != 0x4000 )
v7 = aRwx;
printf(v7);
v8 = aRwx;
if ( (v23.st_mode & 0x100) != 0 )
v8 = &aRwx[2];
printf(v8);
v9 = aRwx;
if ( SLOBYTE(v23.st_mode) < 0 )
v9 = &aRwx[4];
printf(v9);
v10 = aRwx;
if ( (v23.st_mode & 0x40) != 0 )
v10 = &aRwx[6];
printf(v10);
v11 = aRwx;
if ( (v23.st_mode & 0x20) != 0 )
v11 = &aRwx[2];
printf(v11);
v12 = aRwx;
if ( (v23.st_mode & 0x10) != 0 )
v12 = &aRwx[4];
printf(v12);
v13 = aRwx;
if ( (v23.st_mode & 8) != 0 )
v13 = &aRwx[6];
printf(v13);
v14 = aRwx;
if ( (v23.st_mode & 4) != 0 )
v14 = &aRwx[2];
printf(v14);
v15 = aRwx;
if ( (v23.st_mode & 2) != 0 )
v15 = &aRwx[4];
printf(v15);
v16 = aRwx;
if ( (v23.st_mode & 1) != 0 )
v16 = &aRwx[6];
printf(v16);
printf(" %d", LODWORD(v23.st_nlink));
v17 = getpwuid(v23.st_uid);
printf(" %s", v17->pw_name);
v18 = getgrgid(v23.st_gid);
printf(" %s", v18->gr_name);
printf(" %5d", LODWORD(v23.st_size));
v19 = localtime(&v23.st_mtim.tv_sec);
strftime(s, 0x14uLL, "%b %d %R", v19);
printf(" %s", s);
printf(" %s", (const char *)(*(_QWORD *)v6 + 19LL));
putchar(10);
v6 += 8LL;
}
while ( v6 != v20 );
}
}
else
{
if ( multidirflag )
printf("%s:\n", a3);
if ( a2 > 0 )
{
v4 = a1;
do
{
puts((const char *)(*(_QWORD *)v4 + 19LL));
v4 += 8LL;
}
while ( v4 != a1 + 8LL * (unsigned int)(a2 - 1) + 8 );
}
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2, char *a3)
{
__int64 v4; // rbx
unsigned int v5; // eax
__int64 v6; // rbp
const char *v7; // rdi
const char *v8; // rdi
const char *v9; // rdi
const char *v10; // rdi
const char *v11; // rdi
const char *v12; // rdi
const char *v13; // rdi
const char *v14; // rdi
const char *v15; // rdi
const char *v16; // rdi
struct passwd *v17; // rax
struct group *v18; // rax
struct tm *v19; // rax
__int64 v20; // [rsp+8h] [rbp-130h]
char s[32]; // [rsp+10h] [rbp-128h] BYREF
char dest[2]; // [rsp+30h] [rbp-108h] BYREF
struct stat v23; // [rsp+70h] [rbp-C8h] BYREF

if ( lflag )
{
if ( multidirflag )
printf("%s:\n", a3);
v5 = func8(a3);
printf("total %d\n", v5);
if ( a2 > 0 )
{
v6 = a1;
v20 = a1 + 8LL * (unsigned int)(a2 - 1) + 8;
do
{
strcpy(dest, a3);
*(_WORD *)&dest[strlen(dest)] = 47;
strcat(dest, (const char *)(*(_QWORD *)v6 + 19LL));
func13(dest, &v23);
v7 = "d";
if ( (v23.st_mode & 0xF000) != 0x4000 )
v7 = aRwx;
printf(v7);
v8 = aRwx;
if ( (v23.st_mode & 0x100) != 0 )
v8 = &aRwx[2];
printf(v8);
v9 = aRwx;
if ( SLOBYTE(v23.st_mode) < 0 )
v9 = &aRwx[4];
printf(v9);
v10 = aRwx;
if ( (v23.st_mode & 0x40) != 0 )
v10 = &aRwx[6];
printf(v10);
v11 = aRwx;
if ( (v23.st_mode & 0x20) != 0 )
v11 = &aRwx[2];
printf(v11);
v12 = aRwx;
if ( (v23.st_mode & 0x10) != 0 )
v12 = &aRwx[4];
printf(v12);
v13 = aRwx;
if ( (v23.st_mode & 8) != 0 )
v13 = &aRwx[6];
printf(v13);
v14 = aRwx;
if ( (v23.st_mode & 4) != 0 )
v14 = &aRwx[2];
printf(v14);
v15 = aRwx;
if ( (v23.st_mode & 2) != 0 )
v15 = &aRwx[4];
printf(v15);
v16 = aRwx;
if ( (v23.st_mode & 1) != 0 )
v16 = &aRwx[6];
printf(v16);
printf(" %d", LODWORD(v23.st_nlink));
v17 = getpwuid(v23.st_uid);
printf(" %s", v17->pw_name);
v18 = getgrgid(v23.st_gid);
printf(" %s", v18->gr_name);
printf(" %5d", LODWORD(v23.st_size));
v19 = localtime(&v23.st_mtim.tv_sec);
strftime(s, 0x14uLL, "%b %d %R", v19);
printf(" %s", s);
printf(" %s", (const char *)(*(_QWORD *)v6 + 19LL));
putchar(10);
v6 += 8LL;
}
while ( v6 != v20 );
}
}
else
{
if ( multidirflag )
printf("%s:\n", a3);
if ( a2 > 0 )
{
v4 = a1;
do
{
puts((const char *)(*(_QWORD *)v4 + 19LL));
v4 += 8LL;
}
while ( v4 != a1 + 8LL * (unsigned int)(a2 - 1) + 8 );
}
}
}

original_code:
void printdir(struct dirent **flist, int length, char *dirpath) {
 int i;
 struct stat fstat;
 if(!lflag) {
  if(multidirflag) {
   printf("%s:\n", dirpath);
  }
  for (i = 0; i < length; ++i) {
   printf("%s\n", flist[i]->d_name);
  }
 } else {
  if(multidirflag) {
   printf("%s:\n", dirpath);
  }
  printf("total %d\n", sumsize(dirpath));
  for(i = 0; i < length; ++i) {
   char path[50];
   strcpy(path, dirpath);
   strcat(path,"/");
   strcat(path,flist[i]->d_name);
   stat(path, &fstat);
   printf((((((fstat.st_mode)) & 0170000) == (0040000))) ? "d" : "-");
   printf((fstat.st_mode & 0400) ? "r" : "-");
   printf((fstat.st_mode & 0200) ? "w" : "-");
   printf((fstat.st_mode & 0100) ? "x" : "-");
   printf((fstat.st_mode & (0400 >> 3)) ? "r" : "-");
   printf((fstat.st_mode & (0200 >> 3)) ? "w" : "-");
   printf((fstat.st_mode & (0100 >> 3)) ? "x" : "-");
   printf((fstat.st_mode & ((0400 >> 3) >> 3)) ? "r" : "-");
   printf((fstat.st_mode & ((0200 >> 3) >> 3)) ? "w" : "-");
   printf((fstat.st_mode & ((0100 >> 3) >> 3)) ? "x" : "-");
   printf(" %d", (int) fstat.st_nlink);
   printf(" %s", getpwuid(fstat.st_uid)->pw_name);
   printf(" %s", getgrgid(fstat.st_gid)->gr_name);
   printf(" %5d", (int) fstat.st_size);
   char mtime[20];
   strftime(mtime, 20,"%b  %d %R", localtime(&fstat.st_mtim.tv_sec));
   printf(" %s", mtime);
   printf(" %s", flist[i]->d_name);
   printf("\n");
  }
 }
}

variable_types: length int

variable_types:
mtime
char [20]

user_defined_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; }


getdir

decompiled_code:
void __fastcall getdir(char *filename)
{
int v1; // eax
int *v2; // rbp
char *v3; // rax
char *v4; // rax
struct stat v5; // [rsp+0h] [rbp-B8h] BYREF
struct dirent **namelist; // [rsp+98h] [rbp-20h] BYREF

v1 = scandir(filename, &namelist, (int (*)(const struct dirent *))dirselect, alphasort);
if ( v1 <= 0 )
{
if ( fopen(filename, &aRwx[2]) )
{
stat(filename, &v5);
puts(filename);
}
if ( strcmp(filename, "-l") )
{
v2 = __errno_location();
if ( *v2 == 2 )
{
v4 = strerror(2);
fprintf(stderr, "ls: cannot access %s: %s\n", filename, v4);
}
if ( *v2 == 13 )
{
v3 = strerror(13);
fprintf(stderr, "ls: cannot open directory %s: %s\n", filename, v3);
}
}
}
else
{
printdir((__int64)namelist, v1, filename);
}
}

canonical_decompiled_code:
void __fastcall func10(char *filename)
{
int v1; // eax
int *v2; // rbp
char *v3; // rax
char *v4; // rax
struct stat v5; // [rsp+0h] [rbp-B8h] BYREF
struct dirent **namelist; // [rsp+98h] [rbp-20h] BYREF

v1 = scandir(filename, &namelist, (int (*)(const struct dirent *))dirselect, alphasort);
if ( v1 <= 0 )
{
if ( fopen(filename, &aRwx[2]) )
{
func13(filename, &v5);
puts(filename);
}
if ( strcmp(filename, "-l") )
{
v2 = __errno_location();
if ( *v2 == 2 )
{
v4 = strerror(2);
fprintf(stderr, "ls: cannot access %s: %s\n", filename, v4);
}
if ( *v2 == 13 )
{
v3 = strerror(13);
fprintf(stderr, "ls: cannot open directory %s: %s\n", filename, v3);
}
}
}
else
{
func9((__int64)namelist, v1, filename);
}
}

original_code:
void getdir(char *dirname) {
 struct dirent **flist;
 int n;
 int file;
 n = scandir(dirname, &flist, dirselect, alphasort);
 if(n > 0) {
  printdir(flist, n, dirname);
 } else {
  if(file = fopen(dirname, "r") != ((void *)0)) {
   struct stat fstat;
   stat(dirname, &fstat);
   printf("%s\n", dirname);
  }
  if(strcmp(dirname, "-l") == 0) {
   return;
  }
  if((*__errno_location ()) == 2) {
   fprintf(stderr ,"ls: cannot access %s: %s\n", dirname, strerror((*__errno_location ())));
  }
  if((*__errno_location ()) == 13) {
   fprintf(stderr ,"ls: cannot open directory %s: %s\n", dirname, strerror((*__errno_location ())));
  }
 }
}

variable_types:
dirname
char *

variable_types: file int


main

canonical_name: main

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

if ( argc > 0 )
{
v3 = argv;
do
{
if ( !strcmp(*v3, "-l") )
lflag = 1;
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 1) + 1] );
}
if ( argc - lflag <= 2 )
{
if ( argc - lflag == 1 )
{
getdir(".");
return 0;
}
}
else
{
multidirflag = 1;
}
if ( argc > 1 )
{
v4 = (char **)(argv + 1);
do
getdir(*v4++);
while ( v4 != (char **)&argv[(unsigned int)(argc - 2) + 2] );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rax
char **v4; // rbx

if ( argc > 0 )
{
v3 = argv;
do
{
if ( !strcmp(*v3, "-l") )
lflag = 1;
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 1) + 1] );
}
if ( argc - lflag <= 2 )
{
if ( argc - lflag == 1 )
{
func10(".");
return 0;
}
}
else
{
multidirflag = 1;
}
if ( argc > 1 )
{
v4 = (char **)(argv + 1);
do
func10(*v4++);
while ( v4 != (char **)&argv[(unsigned int)(argc - 2) + 2] );
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int i;
 for(i = 0; i < argc; i++) {
  if(strcmp(argv[i], "-l") == 0) {
   lflag = 1;
  }
 }
 if((argc-lflag) > 2) {
  multidirflag = 1;
 }
 if((argc-lflag) == 1) {
  getdir(".");
 } else {
  int i;
  for(i = 1;i < argc;i++) {
   getdir(argv[i]);
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


print

decompiled_code:
__int64 __fastcall print(const char *a1, char a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
if ( (a2 & 1) != 0 )
printf("% 8d", a5);
if ( (a2 & 2) != 0 )
printf("% 8d", a4);
if ( (a2 & 4) != 0 )
printf("% 8d", a3);
if ( *a1 != 45 )
printf(" %s", a1);
putchar(10);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, char a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
if ( (a2 & 1) != 0 )
printf("% 8d", a5);
if ( (a2 & 2) != 0 )
printf("% 8d", a4);
if ( (a2 & 4) != 0 )
printf("% 8d", a3);
if ( *a1 != 45 )
printf(" %s", a1);
putchar(10);
return 0LL;
}

original_code:
int print(const char *fname, int opt, int chars, int words, int lines)
{
 if(opt&OPT_L) printf("% 8d", lines);
 if(opt&OPT_W) printf("% 8d", words);
 if(opt&OPT_C) printf("% 8d", chars);
 if(fname[0]!='-') printf(" %s", fname);
 putchar('\n');
 return 0;
}

canonical_original_code:
int print(char *fname, int opt, int chars, int words, int lines)
{
 if(opt&OPT_L) printf("% 8d", lines);
 if(opt&OPT_W) printf("% 8d", words);
 if(opt&OPT_C) printf("% 8d", chars);
 if(fname[0]!='-') printf(" %s", fname);
 putchar('\n');
 return 0;
}

variable_types:
fname
char *

variable_types: opt int

variable_types: chars int

variable_types: words int

variable_types: lines int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char *v4; // rax
int v5; // ebx
char v6; // dl
char *i; // rax
const char *v8; // rdi
int v9; // er12
int result; // eax
unsigned int v11; // [rsp+4h] [rbp-24h] BYREF
unsigned int v12; // [rsp+8h] [rbp-20h] BYREF
unsigned int v13[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v13[0] = 0;
v12 = 0;
v11 = 0;
v3 = argv + 1;
v4 = argv[1];
v5 = 0;
if ( v4 )
{
do
{
if ( *v4 != 45 )
break;
v6 = v4[1];
for ( i = (char *)(v4 + 2); v6; v6 = *i++ )
{
switch ( v6 )
{
case 'l':
v5 |= 1u;
break;
case 'w':
v5 |= 2u;
break;
case 'c':
v5 |= 4u;
break;
default:
fprintf(stderr, "Unknown option %c\n", (unsigned int)v6);
fwrite("Usage: wc [-cwl] [<filename>*]\n", 1uLL, 0x1FuLL, stderr);
return -1;
}
}
v4 = *++v3;
}
while ( *v3 );
if ( !v5 )
LOBYTE(v5) = 7;
}
else
{
LOBYTE(v5) = 7;
}
v8 = *v3;
v9 = 0;
if ( *v3 )
{
do
{
++v9;
if ( (unsigned int)wc(v8, v5, v13, &v12, &v11) == -1 )
{
perror(*v3);
return 1;
}
v8 = *++v3;
}
while ( *v3 );
if ( !v9 )
goto LABEL_24;
result = 0;
if ( v9 > 1 )
{
print("total", v5, v13[0], v12, v11);
result = 0;
}
}
else
{
LABEL_24:
wc("-", v5, v13, &v12, &v11);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char *v4; // rax
int v5; // ebx
char v6; // dl
char *i; // rax
const char *v8; // rdi
int v9; // er12
int result; // eax
unsigned int v11; // [rsp+4h] [rbp-24h] BYREF
unsigned int v12; // [rsp+8h] [rbp-20h] BYREF
unsigned int v13[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v13[0] = 0;
v12 = 0;
v11 = 0;
v3 = argv + 1;
v4 = argv[1];
v5 = 0;
if ( v4 )
{
do
{
if ( *v4 != 45 )
break;
v6 = v4[1];
for ( i = (char *)(v4 + 2); v6; v6 = *i++ )
{
switch ( v6 )
{
case 'l':
v5 |= 1u;
break;
case 'w':
v5 |= 2u;
break;
case 'c':
v5 |= 4u;
break;
default:
fprintf(stderr, "Unknown option %c\n", (unsigned int)v6);
fwrite("Usage: wc [-cwl] [<filename>*]\n", 1uLL, 0x1FuLL, stderr);
return -1;
}
}
v4 = *++v3;
}
while ( *v3 );
if ( !v5 )
LOBYTE(v5) = 7;
}
else
{
LOBYTE(v5) = 7;
}
v8 = *v3;
v9 = 0;
if ( *v3 )
{
do
{
++v9;
if ( (unsigned int)func8(v8, v5, v13, &v12, &v11) == -1 )
{
perror(*v3);
return 1;
}
v8 = *++v3;
}
while ( *v3 );
if ( !v9 )
goto LABEL_24;
result = 0;
if ( v9 > 1 )
{
func7("total", v5, v13[0], v12, v11);
result = 0;
}
}
else
{
LABEL_24:
func8("-", v5, v13, &v12, &v11);
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 int chars=0;
 int words=0;
 int lines=0;
 int nfiles=0;
 int opt=0;
 int n;
 while((++argv)[0] && argv[0][0]=='-') {
  n=1;
  while(argv[0][n]) {
   switch(argv[0][n++]) {
   case 'c': opt|=OPT_C; break;
   case 'w': opt|=OPT_W; break;
   case 'l': opt|=OPT_L; break;
   default:
    fprintf(stderr, "Unknown option %c\n", argv[0][n-1]);
    fprintf(stderr, "Usage: wc [-cwl] [<filename>*]\n");
    return -1;
   }
  }
 }
 if(!opt) opt=OPT_L|OPT_W|OPT_C;
 while(argv[0]) {
  ++nfiles;
  if(wc(*argv, opt, &chars, &words, &lines)==-1) {
   perror(*argv);
   return 1;
  }
  ++argv;
 }
 if(nfiles==0) wc("-", opt, &chars, &words, &lines);
 else if(nfiles>1) print("total", opt, chars, words, lines);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int chars = 0;
 int words = 0;
 int lines = 0;
 int nfiles = 0;
 int opt = 0;
 int n;
 while((++argv)[0] && argv[0][0]=='-') {
  n=1;
  while(argv[0][n]) {
   switch(argv[0][n++]) {
   case 'c': opt|=OPT_C; break;
   case 'w': opt|=OPT_W; break;
   case 'l': opt|=OPT_L; break;
   default:
    fprintf(stderr, "Unknown option %c\n", argv[0][n-1]);
    fprintf(stderr, "Usage: wc [-cwl] [<filename>*]\n");
    return -1;
   }
  }
 }
 if(!opt) opt=OPT_L|OPT_W|OPT_C;
 while(argv[0]) {
  ++nfiles;
  if(wc(*argv, opt, &chars, &words, &lines)==-1) {
   perror(*argv);
   return 1;
  }
  ++argv;
 }
 if(nfiles==0) wc("-", opt, &chars, &words, &lines);
 else if(nfiles>1) print("total", opt, chars, words, lines);
 return 0;
}

variable_types: nfiles int


initLayersList

repo: L-Naej/IMAGIMP

decompiled_code:
__int64 initLayersList()
{
__int64 v0; // rax

v0 = parseCmdLine();
if ( !v0 )
{
fwrite("Impossible d'initialiser la liste des calques, le programme va quitter.\n", 1uLL, 0x48uLL, stderr);
exit(-1);
}
return createList(0LL, v0);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax

v0 = parseCmdLine();
if ( !v0 )
{
fwrite("Impossible d'initialiser la liste des calques, le programme va quitter.\n", 1uLL, 0x48uLL, stderr);
exit(-1);
}
return createList(0LL, v0);
}

original_code:
List* initLayersList(int argc, char** argv){
 Layer* firstLay = ((void *)0);
 firstLay = parseCmdLine(argc, argv);
 List* layerList = ((void *)0);
 if(firstLay != ((void *)0)){
  layerList = createList(LAYER, firstLay);
 }
 else{
  fprintf(stderr, "Impossible d'initialiser la liste des calques, le programme va quitter.\n");
  exit(-1);
 }
 return layerList;
}

canonical_original_code:
struct list *initLayersList(int argc, char **argv){
 struct layer *firstLay = ((void *)0);
 firstLay = parseCmdLine(argc, argv);
 struct list *layerList = ((void *)0);
 if(firstLay != ((void *)0)){
  layerList = createList(LAYER, firstLay);
 }
 else{
  fprintf(stderr, "Impossible d'initialiser la liste des calques, le programme va quitter.\n");
  exit(-1);
 }
 return layerList;
}

variable_types:
argv
char **

variable_types: struct layer { int id; struct image { short format; char *comments; char *name; int width; int height; int maxValue; unsigned char *arrayRGB; unsigned char *histoGrey; unsigned char *histoRGB; } *imgSource; struct image *imgFinale; struct image *histoSource; struct image *histoFinal; double opacity; enum layer_operation { SUM=1, MULTIPLICATION=2 } operation; struct list { struct cell { struct cell *next; struct cell *previous; void *userData; } *head; struct cell *cursor; struct cell *bottom; int size; int position; enum list_type { LAYER=0, LUT=1, REVIEW=2, UNKNOWN=3 } type; } *lutList; } *

user_defined_types: struct layer { int id; struct image *imgSource; struct image *imgFinale; struct image *histoSource; struct image *histoFinal; double opacity; enum layer_operation operation; struct list *lutList; }

user_defined_types: struct list { struct cell *head; struct cell *cursor; struct cell *bottom; int size; int position; enum list_type type; }


nextLayer

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( !*(_DWORD *)(a1 + 32) )
result = nextData(a1);
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( !*(_DWORD *)(a1 + 32) )
result = nextData(a1);
return result;
}

original_code:
Layer* nextLayer(List* layerList){
 if(layerList == ((void *)0) || layerList->type != LAYER)
  return ((void *)0);
 return (Layer*) nextData(layerList);
}

canonical_original_code:
struct layer *nextLayer(struct list *layerList){
 if(layerList == ((void *)0) || layerList->type != LAYER)
  return ((void *)0);
 return (struct layer *) nextData(layerList);
}

variable_types:
layerList
struct list *

return_type: struct layer { int id; struct image { short format; char *comments; char *name; int width; int height; int maxValue; unsigned char *arrayRGB; unsigned char *histoGrey; unsigned char *histoRGB; } *imgSource; struct image *imgFinale; struct image *histoSource; struct image *histoFinal; double opacity; enum layer_operation { SUM=1, MULTIPLICATION=2 } operation; struct list { struct cell { struct cell *next; struct cell *previous; void *userData; } *head; struct cell *cursor; struct cell *bottom; int size; int position; enum list_type { LAYER=0, LUT=1, REVIEW=2, UNKNOWN=3 } type; } *lutList; } *


previousLayer

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( !*(_DWORD *)(a1 + 32) )
result = previousData();
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( !*(_DWORD *)(a1 + 32) )
result = previousData();
return result;
}

original_code:
Layer* previousLayer(List* layerList){
 if(layerList == ((void *)0) || layerList->type != LAYER)
  return ((void *)0);
 return (Layer*) previousData(layerList);
}

canonical_original_code:
struct layer *previousLayer(struct list *layerList){
 if(layerList == ((void *)0) || layerList->type != LAYER)
  return ((void *)0);
 return (struct layer *) previousData(layerList);
}

user_defined_types: enum layer_operation { SUM=1, MULTIPLICATION=2 }

user_defined_types: struct image { short format; char *comments; char *name; int width; int height; int maxValue; unsigned char *arrayRGB; unsigned char *histoGrey; unsigned char *histoRGB; }

user_defined_types: enum list_type { LAYER=0, LUT=1, REVIEW=2, UNKNOWN=3 }

user_defined_types: struct cell { struct cell *next; struct cell *previous; void *userData; }


currentLayer

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( !*(_DWORD *)(a1 + 32) )
result = currentData();
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( !*(_DWORD *)(a1 + 32) )
result = currentData();
return result;
}

original_code:
Layer* currentLayer(List* layerList){
 if(layerList == ((void *)0) || layerList->type != LAYER)
  return ((void *)0);
 return (Layer*) currentData(layerList);
}

canonical_original_code:
struct layer *currentLayer(struct list *layerList){
 if(layerList == ((void *)0) || layerList->type != LAYER)
  return ((void *)0);
 return (struct layer *) currentData(layerList);
}


delCurrentLayer

decompiled_code:
__int64 __fastcall delCurrentLayer(__int64 a1)
{
__int64 v1; // rax

if ( !a1 )
return 0LL;
if ( *(_DWORD *)(a1 + 32) )
return 0LL;
if ( *(_DWORD *)(a1 + 24) == 1 )
return 0LL;
v1 = currentCell();
return delCellInList(a1, v1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rax

if ( !a1 )
return 0LL;
if ( *(_DWORD *)(a1 + 32) )
return 0LL;
if ( *(_DWORD *)(a1 + 24) == 1 )
return 0LL;
v1 = currentCell();
return delCellInList(a1, v1);
}

original_code:
Layer* delCurrentLayer(List* layerList){
 if(layerList == ((void *)0) || layerList->type != LAYER)
  return false;
 if(layerList->size == 1) return false;
 Cell* c = currentCell(layerList);
 Layer* curLay = ((void *)0);
 curLay = delCellInList(layerList, c);
 return curLay;
}

canonical_original_code:
struct layer *delCurrentLayer(struct list *layerList){
 if(layerList == ((void *)0) || layerList->type != LAYER)
  return false;
 if(layerList->size == 1) return false;
 struct cell *c = currentCell(layerList);
 struct layer *curLay = ((void *)0);
 curLay = delCellInList(layerList, c);
 return curLay;
}

variable_types: struct cell { struct cell *next; struct cell *previous; void *userData; } *


delLayer

decompiled_code:
__int64 __fastcall delLayer(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // edx
__int64 v4; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
result = 0LL;
if ( !*(_DWORD *)(a1 + 32) )
{
v3 = goToData();
result = 0LL;
if ( v3 != -1 )
{
v4 = currentCell(a1);
result = delCellInList(a1, v4);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // edx
__int64 v4; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
result = 0LL;
if ( !*(_DWORD *)(a1 + 32) )
{
v3 = goToData();
result = 0LL;
if ( v3 != -1 )
{
v4 = currentCell(a1);
result = delCellInList(a1, v4);
}
}
return result;
}

original_code:
Layer* delLayer(List* layerList, Layer* lay){
 if(layerList == ((void *)0) || lay == ((void *)0) || layerList->type != LAYER)
  return false;
 if(goToData(layerList, (void*) lay) != -1 ){
  return delCellInList(layerList, currentCell(layerList));
 }
 else return ((void *)0);
}

canonical_original_code:
struct layer *delLayer(struct list *layerList, struct layer *lay){
 if(layerList == ((void *)0) || lay == ((void *)0) || layerList->type != LAYER)
  return false;
 if(goToData(layerList, (void *) lay) != -1 ){
  return delCellInList(layerList, currentCell(layerList));
 }
 else return ((void *)0);
}

variable_types:
lay
struct layer *


genFinalImageRecur

original_code:
void genFinalImageRecur(List* list, Layer* lay, Image* finalImage){
 Layer* pre = ((void *)0);
 long int i = 0;
 long int nPix = finalImage->width*finalImage->height;
 short tmp;
 if ( (pre = previousData(list)) != ((void *)0) ){
  genFinalImageRecur(list, pre, finalImage);
  if(lay->operation == SUM){
   for(i = 0; i < nPix*3; ++i){
    tmp = finalImage->arrayRGB[i] + (short)(ceil(lay->opacity * lay->imgFinale->arrayRGB[i]));
    if(tmp > finalImage->maxValue) tmp = finalImage->maxValue;
    else if(tmp < 0) tmp = 0;
    finalImage->arrayRGB[i] = tmp;
   }
  }
  else if(lay->operation == MULTIPLICATION){
   for(i = 0; i < nPix*3; ++i){
    tmp = (short)(ceil((1-lay->opacity)*finalImage->arrayRGB[i])) + (short)(ceil(lay->opacity * lay->imgFinale->arrayRGB[i]));
    if(tmp > finalImage->maxValue) tmp = finalImage->maxValue;
    else if(tmp < 0) tmp = 0;
    finalImage->arrayRGB[i] = tmp;
   }
  }
 }
 else{
  for(i = 0; i < nPix*3; ++i){
   finalImage->arrayRGB[i] = lay->imgFinale->arrayRGB[i];
  }
 }
}

canonical_original_code:
void genFinalImageRecur(struct list *list, struct layer *lay, struct image *finalImage){
 struct layer *pre = ((void *)0);
 long i = 0;
 long nPix = finalImage->width*finalImage->height;
 short tmp;
 if ( (pre = previousData(list)) != ((void *)0) ){
  genFinalImageRecur(list, pre, finalImage);
  if(lay->operation == SUM){
   for(i = 0; i < nPix*3; ++i){
    tmp = finalImage->arrayRGB[i] + (short)(ceil(lay->opacity * lay->imgFinale->arrayRGB[i]));
    if(tmp > finalImage->maxValue) tmp = finalImage->maxValue;
    else if(tmp < 0) tmp = 0;
    finalImage->arrayRGB[i] = tmp;
   }
  }
  else if(lay->operation == MULTIPLICATION){
   for(i = 0; i < nPix*3; ++i){
    tmp = (short)(ceil((1-lay->opacity)*finalImage->arrayRGB[i])) + (short)(ceil(lay->opacity * lay->imgFinale->arrayRGB[i]));
    if(tmp > finalImage->maxValue) tmp = finalImage->maxValue;
    else if(tmp < 0) tmp = 0;
    finalImage->arrayRGB[i] = tmp;
   }
  }
 }
 else{
  for(i = 0; i < nPix*3; ++i){
   finalImage->arrayRGB[i] = lay->imgFinale->arrayRGB[i];
  }
 }
}

variable_types: struct list { struct cell { struct cell *next; struct cell *previous; void *userData; } *head; struct cell *cursor; struct cell *bottom; int size; int position; enum list_type { LAYER=0, LUT=1, REVIEW=2, UNKNOWN=3 } type; } *

variable_types: struct layer { int id; struct image { short format; char *comments; char *name; int width; int height; int maxValue; unsigned char *arrayRGB; unsigned char *histoGrey; unsigned char *histoRGB; } *imgSource; struct image *imgFinale; struct image *histoSource; struct image *histoFinal; double opacity; enum layer_operation { SUM=1, MULTIPLICATION=2 } operation; struct list *lutList; } *

variable_types:
finalImage
struct image *

variable_types: i long

variable_types: nPix long

variable_types: tmp short


main

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

initIHM(argc, argv, envp);
layerList = initLayersList((unsigned int)argc, argv);
puts("\n\n\tAppuyez sur ESPACE pour afficher la liste des commandes.");
printState();
v3 = *(_QWORD *)(currentData(layerList) + 16);
v4 = *(unsigned int *)(v3 + 24);
if ( (int)v4 <= 512 && *(int *)(v3 + 28) <= 512 )
{
fixeFonctionClicSouris(&clickMouse);
fixeFonctionDessin(mondessin);
initGLIMAGIMP_IHM(*(unsigned int *)(v3 + 24), *(unsigned int *)(v3 + 28), *(_QWORD *)(v3 + 40), 712LL, 512LL);
}
else
{
initGLIMAGIMP(v4, *(unsigned int *)(v3 + 28), *(_QWORD *)(v3 + 40));
}
return 0;
}

original_code:
int main(int argc, char** argv){
 initIHM();
 layerList = initLayersList(argc, argv);
 printf("\n\n\tAppuyez sur ESPACE pour afficher la liste des commandes.\n");
 printState();
 Image* img = ((Layer*)currentData(layerList))->imgFinale;
 if (img->width<=512 && img->height<=512){
  fixeFonctionClicSouris(clickMouse);
  fixeFonctionDessin(mondessin);
  initGLIMAGIMP_IHM(img->width,img->height,img->arrayRGB,712,512);
 }
 else initGLIMAGIMP(img->width, img->height, img->arrayRGB);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 initIHM();
 layerList = initLayersList(argc, argv);
 printf("\n\n\tAppuyez sur ESPACE pour afficher la liste des commandes.\n");
 printState();
 struct image *img = ((Layer*)currentData(layerList))->imgFinale;
 if (img->width<=512 && img->height<=512){
  fixeFonctionClicSouris(clickMouse);
  fixeFonctionDessin(mondessin);
  initGLIMAGIMP_IHM(img->width,img->height,img->arrayRGB,712,512);
 }
 else initGLIMAGIMP(img->width, img->height, img->arrayRGB);
 return 0;
}

variable_types: argc int

variable_types: struct image { short format; char *comments; char *name; int width; int height; int maxValue; unsigned char *arrayRGB; unsigned char *histoGrey; unsigned char *histoRGB; } *


freeLayer

decompiled_code:
void __fastcall freeLayer(void *ptr)
{
if ( ptr )
{
freeImage(*((_QWORD *)ptr + 1));
freeImage(*((_QWORD *)ptr + 2));
freeImage(*((_QWORD *)ptr + 3));
freeImage(*((_QWORD *)ptr + 4));
freeListComplete(*((_QWORD *)ptr + 7));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
freeImage(*((_QWORD *)ptr + 1));
freeImage(*((_QWORD *)ptr + 2));
freeImage(*((_QWORD *)ptr + 3));
freeImage(*((_QWORD *)ptr + 4));
freeListComplete(*((_QWORD *)ptr + 7));
free(ptr);
}
}

original_code:
void freeLayer(Layer* l){
 if(l== ((void *)0)) return;
 freeImage(l->imgSource);
 freeImage(l->imgFinale);
 freeImage(l->histoSource);
 freeImage(l->histoFinal);
 freeListComplete(l->lutList);
 free(l);
}

canonical_original_code:
void freeLayer(struct layer *l){
 if(l== ((void *)0)) return;
 freeImage(l->imgSource);
 freeImage(l->imgFinale);
 freeImage(l->histoSource);
 freeImage(l->histoFinal);
 freeListComplete(l->lutList);
 free(l);
}


createLayer

decompiled_code:
unsigned int *__fastcall createLayer(__int64 a1, unsigned int a2, double a3)
{
unsigned int *v3; // rbx
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax

if ( !a1 )
return 0LL;
v3 = (unsigned int *)malloc(0x40uLL);
if ( v3 )
{
*v3 = ++cntLayerId;
*((_QWORD *)v3 + 1) = a1;
*((double *)v3 + 5) = a3;
v3[12] = a2;
*((_QWORD *)v3 + 7) = 0LL;
*((_QWORD *)v3 + 2) = 0LL;
v4 = copyImage(a1);
*((_QWORD *)v3 + 2) = v4;
if ( !v4 )
{
fprintf(stderr, format, v3);
freeLayer(v3);
}
if ( (unsigned int)addNeutralLut(v3, *(_DWORD *)(a1 + 32)) )
{
*((_QWORD *)v3 + 3) = 0LL;
*((_QWORD *)v3 + 4) = 0LL;
v5 = createHistogram(*((_QWORD *)v3 + 1));
*((_QWORD *)v3 + 3) = v5;
if ( !v5 )
fprintf(stderr, aImpossibleDAll, *v3);
v6 = copyImage(*((_QWORD *)v3 + 3));
*((_QWORD *)v3 + 4) = v6;
if ( !v6 )
fprintf(stderr, aImpossibleDAll, *v3);
}
else
{
fprintf(stderr, "Une erreur est survenue lors de l'ajout du LUT neutre du layer %p.\n", v3);
freeLayer(v3);
v3 = 0LL;
}
}
return v3;
}

canonical_decompiled_code:
unsigned int *__fastcall func2(__int64 a1, unsigned int a2, double a3)
{
unsigned int *v3; // rbx
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax

if ( !a1 )
return 0LL;
v3 = (unsigned int *)malloc(0x40uLL);
if ( v3 )
{
*v3 = ++cntLayerId;
*((_QWORD *)v3 + 1) = a1;
*((double *)v3 + 5) = a3;
v3[12] = a2;
*((_QWORD *)v3 + 7) = 0LL;
*((_QWORD *)v3 + 2) = 0LL;
v4 = copyImage(a1);
*((_QWORD *)v3 + 2) = v4;
if ( !v4 )
{
fprintf(stderr, format, v3);
func0(v3);
}
if ( (unsigned int)func1(v3, *(_DWORD *)(a1 + 32)) )
{
*((_QWORD *)v3 + 3) = 0LL;
*((_QWORD *)v3 + 4) = 0LL;
v5 = createHistogram(*((_QWORD *)v3 + 1));
*((_QWORD *)v3 + 3) = v5;
if ( !v5 )
fprintf(stderr, aImpossibleDAll, *v3);
v6 = copyImage(*((_QWORD *)v3 + 3));
*((_QWORD *)v3 + 4) = v6;
if ( !v6 )
fprintf(stderr, aImpossibleDAll, *v3);
}
else
{
fprintf(stderr, "Une erreur est survenue lors de l'ajout du LUT neutre du layer %p.\n", v3);
func0(v3);
v3 = 0LL;
}
}
return v3;
}

original_code:
Layer* createLayer(Image* source, double opa, LAYER_OP operation){
 if(source == ((void *)0)) return ((void *)0);
 Layer* l = (Layer*) malloc(sizeof(Layer));
 if(l == ((void *)0)) return ((void *)0);
 l->id = ++cntLayerId;
 l->imgSource = source;
 l->opacity = opa;
 l->operation = operation;
 l->lutList = ((void *)0);
 l->imgFinale = ((void *)0);
 l->imgFinale = copyImage(l->imgSource);
 if(l->imgFinale == ((void *)0)){
  fprintf(stderr, "Une erreur est survenue lors de l'allocation mémoire de l'image finale du layer %p.\n", l);
  freeLayer(l);
 }
 if(! addNeutralLut(l, source->maxValue) ){
  fprintf(stderr, "Une erreur est survenue lors de l'ajout du LUT neutre du layer %p.\n", l);
  freeLayer(l);
  return ((void *)0);
 }
 l->histoSource = ((void *)0);
 l->histoFinal = ((void *)0);
 l->histoSource = createHistogram(l->imgSource);
 if(l->histoSource == ((void *)0)){
  fprintf(stderr, "Impossible d'allouer la mémoire nécessaire pour l'histogramme de l'image du calque d'id %d.\n", l->id);
 }
 l->histoFinal = copyImage(l->histoSource);
 if(l->histoFinal == ((void *)0)){
  fprintf(stderr, "Impossible d'allouer la mémoire nécessaire pour l'histogramme de l'image du calque d'id %d.\n", l->id);
 }
 return l;
}

canonical_original_code:
struct layer *createLayer(struct image *source, double opa, enum layer_operation operation){
 if(source == ((void *)0)) return ((void *)0);
 struct layer *l = (Layer*) malloc(sizeof(Layer));
 if(l == ((void *)0)) return ((void *)0);
 l->id = ++cntLayerId;
 l->imgSource = source;
 l->opacity = opa;
 l->operation = operation;
 l->lutList = ((void *)0);
 l->imgFinale = ((void *)0);
 l->imgFinale = copyImage(l->imgSource);
 if(l->imgFinale == ((void *)0)){
  fprintf(stderr, "Une erreur est survenue lors de l'allocation mémoire de l'image finale du layer %p.\n", l);
  freeLayer(l);
 }
 if(! addNeutralLut(l, source->maxValue) ){
  fprintf(stderr, "Une erreur est survenue lors de l'ajout du LUT neutre du layer %p.\n", l);
  freeLayer(l);
  return ((void *)0);
 }
 l->histoSource = ((void *)0);
 l->histoFinal = ((void *)0);
 l->histoSource = createHistogram(l->imgSource);
 if(l->histoSource == ((void *)0)){
  fprintf(stderr, "Impossible d'allouer la mémoire nécessaire pour l'histogramme de l'image du calque d'id %d.\n", l->id);
 }
 l->histoFinal = copyImage(l->histoSource);
 if(l->histoFinal == ((void *)0)){
  fprintf(stderr, "Impossible d'allouer la mémoire nécessaire pour l'histogramme de l'image du calque d'id %d.\n", l->id);
 }
 return l;
}

variable_types:
source
struct image *

variable_types: opa double

variable_types: enum layer_operation { SUM=1, MULTIPLICATION=2 }


createEmptyLayer

decompiled_code:
unsigned int *__fastcall createEmptyLayer(unsigned int a1, unsigned int a2)
{
unsigned int *v2; // rbx
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rax
__int64 v6; // rax

v2 = (unsigned int *)malloc(0x40uLL);
if ( v2 )
{
*v2 = ++cntLayerId;
*((_QWORD *)v2 + 7) = 0LL;
*((_QWORD *)v2 + 1) = 0LL;
*((_QWORD *)v2 + 2) = 0LL;
*((_QWORD *)v2 + 1) = createEmptyImg(a1, a2, 255LL);
v3 = createEmptyImg(a1, a2, 255LL);
*((_QWORD *)v2 + 2) = v3;
v4 = *((_QWORD *)v2 + 1);
if ( v3 && v4 )
{
*((_QWORD *)v2 + 5) = 0LL;
v2[12] = 2;
if ( (unsigned int)addNeutralLut(v2, *(_DWORD *)(v4 + 32)) )
{
*((_QWORD *)v2 + 3) = 0LL;
*((_QWORD *)v2 + 4) = 0LL;
v5 = createHistogram(*((_QWORD *)v2 + 1));
*((_QWORD *)v2 + 3) = v5;
if ( !v5 )
fprintf(stderr, aImpossibleDAll, *v2);
v6 = copyImage(*((_QWORD *)v2 + 3));
*((_QWORD *)v2 + 4) = v6;
if ( !v6 )
fprintf(stderr, aImpossibleDAll, *v2);
}
else
{
fwrite("Une erreur est survenue lors de l'ajout du LUT neutre.\n", 1uLL, 0x37uLL, stderr);
freeLayer(v2);
v2 = 0LL;
}
}
else
{
freeLayer(v2);
v2 = 0LL;
}
}
return v2;
}

canonical_decompiled_code:
unsigned int *__fastcall func3(unsigned int a1, unsigned int a2)
{
unsigned int *v2; // rbx
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rax
__int64 v6; // rax

v2 = (unsigned int *)malloc(0x40uLL);
if ( v2 )
{
*v2 = ++cntLayerId;
*((_QWORD *)v2 + 7) = 0LL;
*((_QWORD *)v2 + 1) = 0LL;
*((_QWORD *)v2 + 2) = 0LL;
*((_QWORD *)v2 + 1) = createEmptyImg(a1, a2, 255LL);
v3 = createEmptyImg(a1, a2, 255LL);
*((_QWORD *)v2 + 2) = v3;
v4 = *((_QWORD *)v2 + 1);
if ( v3 && v4 )
{
*((_QWORD *)v2 + 5) = 0LL;
v2[12] = 2;
if ( (unsigned int)func1(v2, *(_DWORD *)(v4 + 32)) )
{
*((_QWORD *)v2 + 3) = 0LL;
*((_QWORD *)v2 + 4) = 0LL;
v5 = createHistogram(*((_QWORD *)v2 + 1));
*((_QWORD *)v2 + 3) = v5;
if ( !v5 )
fprintf(stderr, aImpossibleDAll, *v2);
v6 = copyImage(*((_QWORD *)v2 + 3));
*((_QWORD *)v2 + 4) = v6;
if ( !v6 )
fprintf(stderr, aImpossibleDAll, *v2);
}
else
{
fwrite("Une erreur est survenue lors de l'ajout du LUT neutre.\n", 1uLL, 0x37uLL, stderr);
func0(v2);
v2 = 0LL;
}
}
else
{
func0(v2);
v2 = 0LL;
}
}
return v2;
}

original_code:
Layer* createEmptyLayer(int w, int h){
 Layer* l = (Layer*) malloc(sizeof(Layer));
 if(l == ((void *)0)) return ((void *)0);
 l->id = ++cntLayerId;
 l->lutList = ((void *)0);
 l->imgSource = ((void *)0);
 l->imgFinale = ((void *)0);
 l->imgSource = createEmptyImg(w,h, 255);
 l->imgFinale = createEmptyImg(w,h, 255);
 if(l->imgSource == ((void *)0) || l->imgFinale == ((void *)0)){
  freeLayer(l);
  return ((void *)0);
 }
 l->opacity = 0.0;
 l->operation = MULTIPLICATION;
 if(! addNeutralLut(l, l->imgSource->maxValue) ){
  fprintf(stderr, "Une erreur est survenue lors de l'ajout du LUT neutre.\n");
  freeLayer(l);
  return ((void *)0);
 }
 l->histoSource = ((void *)0);
 l->histoFinal = ((void *)0);
 l->histoSource = createHistogram(l->imgSource);
 if(l->histoSource == ((void *)0)){
  fprintf(stderr, "Impossible d'allouer la mémoire nécessaire pour l'histogramme de l'image du calque d'id %d.\n", l->id);
 }
 l->histoFinal = copyImage(l->histoSource);
 if(l->histoFinal == ((void *)0)){
  fprintf(stderr, "Impossible d'allouer la mémoire nécessaire pour l'histogramme de l'image du calque d'id %d.\n", l->id);
 }
 return l;
}

canonical_original_code:
struct layer *createEmptyLayer(int w, int h){
 struct layer *l = (Layer*) malloc(sizeof(Layer));
 if(l == ((void *)0)) return ((void *)0);
 l->id = ++cntLayerId;
 l->lutList = ((void *)0);
 l->imgSource = ((void *)0);
 l->imgFinale = ((void *)0);
 l->imgSource = createEmptyImg(w,h, 255);
 l->imgFinale = createEmptyImg(w,h, 255);
 if(l->imgSource == ((void *)0) || l->imgFinale == ((void *)0)){
  freeLayer(l);
  return ((void *)0);
 }
 l->opacity = 0.0;
 l->operation = MULTIPLICATION;
 if(! addNeutralLut(l, l->imgSource->maxValue) ){
  fprintf(stderr, "Une erreur est survenue lors de l'ajout du LUT neutre.\n");
  freeLayer(l);
  return ((void *)0);
 }
 l->histoSource = ((void *)0);
 l->histoFinal = ((void *)0);
 l->histoSource = createHistogram(l->imgSource);
 if(l->histoSource == ((void *)0)){
  fprintf(stderr, "Impossible d'allouer la mémoire nécessaire pour l'histogramme de l'image du calque d'id %d.\n", l->id);
 }
 l->histoFinal = copyImage(l->histoSource);
 if(l->histoFinal == ((void *)0)){
  fprintf(stderr, "Impossible d'allouer la mémoire nécessaire pour l'histogramme de l'image du calque d'id %d.\n", l->id);
 }
 return l;
}

variable_types: w int

variable_types: h int


dumpLayer

decompiled_code:
void __fastcall dumpLayer(unsigned int *a1)
{
unsigned int v1; // eax

if ( a1 )
{
printf("\n-----------Affichage Layer ID n° %d-----------\n\n", *a1);
printf("Address : %p\n", a1);
printf(aOp);
v1 = a1[12];
if ( v1 == 1 )
{
puts("SUM");
}
else if ( v1 == 2 )
{
puts("MULTIPLICATION");
}
printf("Opacity : %f\n", *((double *)a1 + 5));
printf("Image source : %s\n", *(const char **)(*((_QWORD *)a1 + 1) + 16LL));
dumpImage(*((_QWORD *)a1 + 1));
}
}

canonical_decompiled_code:
void __fastcall func4(unsigned int *a1)
{
unsigned int v1; // eax

if ( a1 )
{
printf("\n-----------Affichage Layer ID n° %d-----------\n\n", *a1);
printf("Address : %p\n", a1);
printf(aOp);
v1 = a1[12];
if ( v1 == 1 )
{
puts("SUM");
}
else if ( v1 == 2 )
{
puts("MULTIPLICATION");
}
printf("Opacity : %f\n", *((double *)a1 + 5));
printf("Image source : %s\n", *(const char **)(*((_QWORD *)a1 + 1) + 16LL));
dumpImage(*((_QWORD *)a1 + 1));
}
}

original_code:
void dumpLayer(Layer* l){
 if(l == ((void *)0)) return;
 printf("\n-----------Affichage Layer ID n° %d-----------\n\n", l->id);
 printf("Address : %p\n", l);
 printf("Opération : ");
 switch(l->operation){
  case SUM : printf("SUM\n");
  break;
  case MULTIPLICATION : printf("MULTIPLICATION\n");
  break;
 }
 printf("Opacity : %f\n", l->opacity);
 printf("Image source : %s\n", l->imgSource->name);
 dumpImage(l->imgSource);
}

canonical_original_code:
void dumpLayer(struct layer *l){
 if(l == ((void *)0)) return;
 printf("\n-----------Affichage Layer ID n° %d-----------\n\n", l->id);
 printf("Address : %p\n", l);
 printf("Opération : ");
 switch(l->operation){
  case SUM : printf("SUM\n");
  break;
  case MULTIPLICATION : printf("MULTIPLICATION\n");
  break;
 }
 printf("Opacity : %f\n", l->opacity);
 printf("Image source : %s\n", l->imgSource->name);
 dumpImage(l->imgSource);
}

variable_types: struct layer { int id; struct image { short format; char *comments; char *name; int width; int height; int maxValue; unsigned char *arrayRGB; unsigned char *histoGrey; unsigned char *histoRGB; } *imgSource; struct image *imgFinale; struct image *histoSource; struct image *histoFinal; double opacity; enum layer_operation { SUM=1, MULTIPLICATION=2 } operation; struct list { struct cell { struct cell *next; struct cell *previous; void *userData; } *head; struct cell *cursor; struct cell *bottom; int size; int position; enum list_type { LAYER=0, LUT=1, REVIEW=2, UNKNOWN=3 } type; } *lutList; } *


setLayerOpacity

decompiled_code:
void __fastcall setLayerOpacity(__int64 a1, double a2)
{
if ( a1 )
{
if ( a2 <= 1.0 )
{
if ( a2 < 0.0 )
a2 = 0.0;
}
else
{
a2 = *(double *)&LC13;
}
*(double *)(a1 + 40) = a2;
}
}

original_code:
void setLayerOpacity(Layer* lay, double newOpa){
 if(lay == ((void *)0)) return;
 if(newOpa > 1.0) newOpa = 1.0;
 else if(newOpa < 0.0) newOpa = 0.0;
 lay->opacity = newOpa;
}

canonical_original_code:
void setLayerOpacity(struct layer *lay, double newOpa){
 if(lay == ((void *)0)) return;
 if(newOpa > 1.0) newOpa = 1.0;
 else if(newOpa < 0.0) newOpa = 0.0;
 lay->opacity = newOpa;
}

variable_types: newOpa double


setLayerOperation

decompiled_code:
void __fastcall setLayerOperation(__int64 a1, int a2)
{
if ( a1 )
*(_DWORD *)(a1 + 48) = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2)
{
if ( a1 )
*(_DWORD *)(a1 + 48) = a2;
}

original_code:
void setLayerOperation(Layer* lay, LAYER_OP newOp){
 if(lay == ((void *)0)) return;
 lay->operation = newOp;
}

canonical_original_code:
void setLayerOperation(struct layer *lay, enum layer_operation newOp){
 if(lay == ((void *)0)) return;
 lay->operation = newOp;
}


delLastLut

decompiled_code:
__int64 __fastcall delLastLut(__int64 a1)
{
__int64 v1; // rbp

if ( !a1 )
return 0LL;
v1 = *(_QWORD *)(goToBottomCell(*(_QWORD *)(a1 + 56)) + 16);
if ( !*(_DWORD *)(v1 + 20) )
return 0LL;
delBottomCell(*(_QWORD *)(a1 + 56));
applyLuts(a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // rbp

if ( !a1 )
return 0LL;
v1 = *(_QWORD *)(goToBottomCell(*(_QWORD *)(a1 + 56)) + 16);
if ( !*(_DWORD *)(v1 + 20) )
return 0LL;
delBottomCell(*(_QWORD *)(a1 + 56));
func8(a1);
return v1;
}

original_code:
Lut* delLastLut(Layer* lay){
 if(lay == ((void *)0)) return ((void *)0);
 Lut* lutToDelete = ((void *)0);
 Cell* last = goToBottomCell(lay->lutList);
 lutToDelete = (Lut*)last->userData;
 if( lutToDelete->function == NEUTRAL ) return ((void *)0);
 delBottomCell(lay->lutList);
 applyLuts(lay);
 return lutToDelete;
}

canonical_original_code:
struct lut *delLastLut(struct layer *lay){
 if(lay == ((void *)0)) return ((void *)0);
 struct lut *lutToDelete = ((void *)0);
 struct cell *last = goToBottomCell(lay->lutList);
 lutToDelete = (struct lut *)last->userData;
 if( lutToDelete->function == NEUTRAL ) return ((void *)0);
 delBottomCell(lay->lutList);
 applyLuts(lay);
 return lutToDelete;
}

variable_types: struct lut { struct Channels { unsigned char *chan1; unsigned char *chan2; unsigned char *chan3; int size; } *channels; long size; int maxValue; enum lut_function { INVERT=1, ADDLUM=2, DIMLUM=3, ADDCON=4, DIMCON=5, SEPIA=6, GRAY=7, NEUTRAL=0 } function; int valueEffect; } *

variable_types: struct cell { struct cell *next; struct cell *previous; void *userData; } *

user_defined_types: struct lut { struct Channels *channels; long size; int maxValue; enum lut_function function; int valueEffect; }


neutral

original_code:
void neutral(Lut* lt, Channels* input){
 int i;
 if(lt == ((void *)0)) return;
 for(i=0; i < lt->size; i++){
  lt->channels->chan1[i] = input->chan1[i];
  lt->channels->chan2[i] = input->chan2[i];
  lt->channels->chan3[i] = input->chan3[i];
 }
}

canonical_original_code:
void neutral(struct lut *lt, struct Channels *input){
 int i;
 if(lt == ((void *)0)) return;
 for(i=0; i < lt->size; i++){
  lt->channels->chan1[i] = input->chan1[i];
  lt->channels->chan2[i] = input->chan2[i];
  lt->channels->chan3[i] = input->chan3[i];
 }
}

variable_types:
input
struct Channels *

variable_types: i int

user_defined_types: enum lut_function { INVERT=1, ADDLUM=2, DIMLUM=3, ADDCON=4, DIMCON=5, SEPIA=6, GRAY=7, NEUTRAL=0 }

user_defined_types: struct Channels { unsigned char *chan1; unsigned char *chan2; unsigned char *chan3; int size; }


invertLut

original_code:
void invertLut(Lut* lt, Channels* input){
 int i;
 if(lt == ((void *)0)) return;
 for(i=0; i < lt->size; i++){
  lt->channels->chan1[i] = lt->maxValue - input->chan1[i];
  lt->channels->chan2[i] = lt->maxValue - input->chan2[i];
  lt->channels->chan3[i] = lt->maxValue - input->chan3[i];
 }
}

canonical_original_code:
void invertLut(struct lut *lt, struct Channels *input){
 int i;
 if(lt == ((void *)0)) return;
 for(i=0; i < lt->size; i++){
  lt->channels->chan1[i] = lt->maxValue - input->chan1[i];
  lt->channels->chan2[i] = lt->maxValue - input->chan2[i];
  lt->channels->chan3[i] = lt->maxValue - input->chan3[i];
 }
}


addLum

original_code:
void addLum(Lut* lt, Channels* input){
 int i;
 int tmp;
 if(lt == ((void *)0)) return;
 for (i=0; i < lt->size; i++){
  tmp = input->chan1[i]+lt->valueEffect;
  if(tmp > lt->maxValue) tmp = lt->maxValue;
  else if (tmp < 0) tmp = 0;
  lt->channels->chan1[i] = (unsigned char) tmp;
  tmp = input->chan2[i]+lt->valueEffect;
  if(tmp > lt->maxValue) tmp = lt->maxValue;
  else if (tmp < 0) tmp = 0;
  lt->channels->chan2[i] = (unsigned char) tmp;
  tmp = input->chan3[i]+lt->valueEffect;
  if(tmp > lt->maxValue) tmp = lt->maxValue;
  else if (tmp < 0) tmp = 0;
  lt->channels->chan3[i] = (unsigned char) tmp;
 }
}

canonical_original_code:
void addLum(struct lut *lt, struct Channels *input){
 int i;
 int tmp;
 if(lt == ((void *)0)) return;
 for (i=0; i < lt->size; i++){
  tmp = input->chan1[i]+lt->valueEffect;
  if(tmp > lt->maxValue) tmp = lt->maxValue;
  else if (tmp < 0) tmp = 0;
  lt->channels->chan1[i] = (unsigned char) tmp;
  tmp = input->chan2[i]+lt->valueEffect;
  if(tmp > lt->maxValue) tmp = lt->maxValue;
  else if (tmp < 0) tmp = 0;
  lt->channels->chan2[i] = (unsigned char) tmp;
  tmp = input->chan3[i]+lt->valueEffect;
  if(tmp > lt->maxValue) tmp = lt->maxValue;
  else if (tmp < 0) tmp = 0;
  lt->channels->chan3[i] = (unsigned char) tmp;
 }
}

variable_types: tmp int