decompiled_code:
__int64 __fastcall parse_edgemap(_DWORD *a1, const char *a2, int *a3)
{
int v4; // edx
__int64 result; // rax
int v6; // edx

v4 = match_word(a2, "prio,cpy,val,pal,clp,ign", a3);
result = 0LL;
if ( v4 >= 0 )
{
if ( v4 <= 0 )
{
result = parse_uint(a2, (__int64)a1, a3);
if ( !(_BYTE)result )
return result;
}
else
{
*a1 = -1;
*a3 -= 3;
}
if ( *a1 == -1
|| (result = parse_edgemap_mapopt(a1 + 1, a2, a3), (_BYTE)result)
&& (v6 = match_word(a2, "or", a3), result = 0LL, v6 >= 0) )
{
result = parse_edgemap_mapopt(a1 + 6, a2, a3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, const char *a2, int *a3)
{
int v4; // edx
__int64 result; // rax
int v6; // edx

v4 = func1(a2, "prio,cpy,val,pal,clp,ign", a3);
result = 0LL;
if ( v4 >= 0 )
{
if ( v4 <= 0 )
{
result = func3(a2, (__int64)a1, a3);
if ( !(_BYTE)result )
return result;
}
else
{
*a1 = -1;
*a3 -= 3;
}
if ( *a1 == -1
|| (result = func6(a1 + 1, a2, a3), (_BYTE)result)
&& (v6 = func1(a2, "or", a3), result = 0LL, v6 >= 0) )
{
result = func6(a1 + 6, a2, a3);
}
}
return result;
}

original_code:
_Bool parse_edgemap(edgemap_t *target, char *text, unsigned int *accum) {
 int wi = match_word(text, "prio,cpy,val,pal,clp,ign", accum);
 if (wi < 0) {
  return 0;
 }
 else if (wi > 0) {
  target->priority = (0x7fffffff * 2U + 1U);
  *accum -= 3;
 }
 else {
  if (!parse_uint(text, &target->priority, accum)) {
   return 0;
  }
 }
 if (target->priority == (0x7fffffff * 2U + 1U)) {
  if (!parse_edgemap_mapopt(&target->unmatched, text, accum)) {
   return 0;
  }
 }
 else {
  if (!parse_edgemap_mapopt(&target->matched, text, accum)) {
   return 0;
  }
  if (match_word(text, "or", accum) < 0) {
   return 0;
  }
  if (!parse_edgemap_mapopt(&target->unmatched, text, accum)) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
_Bool parse_edgemap(struct edgemap_t *target, char *text, unsigned int *accum) {
 int wi = match_word(text, "prio,cpy,val,pal,clp,ign", accum);
 if (wi < 0) {
  return 0;
 }
 else if (wi > 0) {
  target->priority = (0x7fffffff * 2U + 1U);
  *accum -= 3;
 }
 else {
  if (!parse_uint(text, &target->priority, accum)) {
   return 0;
  }
 }
 if (target->priority == (0x7fffffff * 2U + 1U)) {
  if (!parse_edgemap_mapopt(&target->unmatched, text, accum)) {
   return 0;
  }
 }
 else {
  if (!parse_edgemap_mapopt(&target->matched, text, accum)) {
   return 0;
  }
  if (match_word(text, "or", accum) < 0) {
   return 0;
  }
  if (!parse_edgemap_mapopt(&target->unmatched, text, accum)) {
   return 0;
  }
 }
 return 1;
}

variable_types: struct edgemap_t { unsigned int priority; struct edgemap_mapopt_t { unsigned int type; struct ranged_val_t { _Bool is_ranged; int value; int start; int stop; } value; } matched; struct edgemap_mapopt_t unmatched; } *

variable_types:
accum
unsigned int *

variable_types: wi int

user_defined_types: struct edgemap_t { unsigned int priority; struct edgemap_mapopt_t matched; struct edgemap_mapopt_t unmatched; }


repo: tlvb/blitemoth

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

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

original_code:
action_t *free_action(action_t *prisoner) {
 if (prisoner != ((void *)0)) {
  free(prisoner);
 }
 return ((void *)0);
}

canonical_original_code:
struct action_t *free_action(struct action_t *prisoner) {
 if (prisoner != ((void *)0)) {
  free(prisoner);
 }
 return ((void *)0);
}

variable_types:
prisoner
struct action_t *

return_type: struct action_t { struct ranged_val_t { _Bool is_ranged; int value; int start; int stop; } lbound; struct ranged_val_t ubound; struct palette_t { unsigned int n; unsigned int c[16]; } palette; struct order_t { unsigned char o[16]; } priority; _Bool splitab; struct edgemap_t { unsigned int priority; struct edgemap_mapopt_t { unsigned int type; struct ranged_val_t value; } matched; struct edgemap_mapopt_t unmatched; } below; struct edgemap_t above; } *

user_defined_types: struct action_t { struct ranged_val_t lbound; struct ranged_val_t ubound; struct palette_t palette; struct order_t priority; _Bool splitab; struct edgemap_t below; struct edgemap_t above; }


decompiled_code:
char *__fastcall interpret_argv(int argc, char **argv, _DWORD *a3)
{
char *v5; // rbx
int v6; // eax
const char *v7; // rdx
const char *v8; // rdx
char *v9; // r14
size_t v10; // rax
char *v11; // rdi
size_t v12; // rax
int v13; // eax
void *v14; // rax
void *v15; // r14
int v16; // eax
_QWORD *v17; // rax
int v19[11]; // [rsp+Ch] [rbp-2Ch] BYREF

*a3 = 0;
v5 = (char *)calloc(1uLL, 0x38uLL);
if ( v5 )
{
opterr = 0;
v6 = getopt(argc, argv, "Vvi:o:m:c:");
v19[0] = 0;
if ( v6 >= 0 )
{
while ( 1 )
{
switch ( v6 )
{
case '?':
fprintf(
stderr,
"parser error :: Missing argument to parameter \"-%c\" or parameter \"%c\" not recognized.\n",
(unsigned int)optopt,
(unsigned int)optopt);
*a3 = 3;
return v5;
case 'V':
fwrite("Blitemoth, not much info right now...\n", 1uLL, 0x26uLL, stderr);
goto LABEL_12;
case 'c':
v14 = parse_action(optarg, v19);
v15 = v14;
if ( !v19[0] )
goto LABEL_29;
free_action(v14);
if ( v19[0] == 1 )
{
fwrite(
"parser error :: failed to allocate small amounts of memory, probably bad\n",
1uLL,
0x49uLL,
stderr);
*a3 = 1;
return v5;
}
if ( v19[0] == 2 )
{
fwrite("parser error :: argument to parameter \"-c\" has bad syntax\n", 1uLL, 0x3AuLL, stderr);
*a3 = 2;
return v5;
}
LABEL_29:
v16 = *((_DWORD *)v5 + 10);
*((_DWORD *)v5 + 10) = v16 + 1;
v17 = realloc(*((void **)v5 + 6), 8LL * (unsigned int)(v16 + 1));
if ( !v17 )
{
fwrite("parser error :: memory allocation failure\n", 1uLL, 0x2AuLL, stderr);
free_action(v15);
--*((_DWORD *)v5 + 10);
*a3 = 1;
return v5;
}
*((_QWORD *)v5 + 6) = v17;
v17[*((_DWORD *)v5 + 10) - 1] = v15;
goto LABEL_12;
case 'i':
v9 = optarg;
v10 = strlen(optarg);
v11 = (char *)calloc(v10 + 1, 1uLL);
*((_QWORD *)v5 + 1) = v11;
if ( v11 )
goto LABEL_16;
goto LABEL_19;
case 'm':
v5[24] = 1;
v13 = _isoc99_sscanf(optarg, "%u %u", v5 + 28, v5 + 32);
if ( v13 )
{
if ( v13 == 1 )
{
*((_DWORD *)v5 + 8) = *((_DWORD *)v5 + 7);
*((_DWORD *)v5 + 7) = 0;
}
}
else
{
fwrite("parser error :: argument \"-m\" needs one or two positive numbers\n", 1uLL, 0x40uLL, stderr);
}
goto LABEL_12;
case 'o':
v9 = optarg;
v12 = strlen(optarg);
v11 = (char *)calloc(v12 + 1, 1uLL);
*((_QWORD *)v5 + 2) = v11;
if ( !v11 )
{
LABEL_19:
fwrite("parser error :: memory allocation failure\n", 1uLL, 0x2AuLL, stderr);
*a3 = 1;
return v5;
}
LABEL_16:
strcpy(v11, v9);
LABEL_12:
v6 = getopt(argc, argv, "Vvi:o:m:c:");
if ( v6 < 0 )
goto LABEL_3;
break;
case 'v':
*v5 = 1;
goto LABEL_12;
default:
goto LABEL_12;
}
}
}
LABEL_3:
if ( *v5 )
{
v7 = (const char *)*((_QWORD *)v5 + 1);
if ( v7 )
{
if ( v5[24] )
{
fwrite("Input: files '", 1uLL, 0xEuLL, stderr);
fprintf(stderr, *((const char **)v5 + 1), *((unsigned int *)v5 + 7));
fwrite("' to '", 1uLL, 6uLL, stderr);
fprintf(stderr, *((const char **)v5 + 1), *((unsigned int *)v5 + 8));
fwrite("' inclusive.\n", 1uLL, 0xDuLL, stderr);
}
else
{
fprintf(stderr, "Input: '%s'\n", v7);
}
}
v8 = (const char *)*((_QWORD *)v5 + 2);
if ( v8 )
{
if ( v5[24] )
{
fwrite("Output: files '", 1uLL, 0xFuLL, stderr);
fprintf(stderr, *((const char **)v5 + 2), *((unsigned int *)v5 + 7));
fwrite("' to '", 1uLL, 6uLL, stderr);
fprintf(stderr, *((const char **)v5 + 2), *((unsigned int *)v5 + 8));
fwrite("' inclusive.\n", 1uLL, 0xDuLL, stderr);
}
else
{
fprintf(stderr, "Output: '%s'\n", v8);
}
}
}
}
else
{
fwrite("parser error :: memory allocation failure\n", 1uLL, 0x2AuLL, stderr);
*a3 = 1;
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func10(int argc, char **argv, _DWORD *a3)
{
char *v5; // rbx
int v6; // eax
const char *v7; // rdx
const char *v8; // rdx
char *v9; // r14
size_t v10; // rax
char *v11; // rdi
size_t v12; // rax
int v13; // eax
void *v14; // rax
void *v15; // r14
int v16; // eax
_QWORD *v17; // rax
int v19[11]; // [rsp+Ch] [rbp-2Ch] BYREF

*a3 = 0;
v5 = (char *)calloc(1uLL, 0x38uLL);
if ( v5 )
{
opterr = 0;
v6 = getopt(argc, argv, "Vvi:o:m:c:");
v19[0] = 0;
if ( v6 >= 0 )
{
while ( 1 )
{
switch ( v6 )
{
case '?':
fprintf(
stderr,
"parser error :: Missing argument to parameter \"-%c\" or parameter \"%c\" not recognized.\n",
(unsigned int)optopt,
(unsigned int)optopt);
*a3 = 3;
return v5;
case 'V':
fwrite("Blitemoth, not much info right now...\n", 1uLL, 0x26uLL, stderr);
goto LABEL_12;
case 'c':
v14 = func8(optarg, v19);
v15 = v14;
if ( !v19[0] )
goto LABEL_29;
func9(v14);
if ( v19[0] == 1 )
{
fwrite(
"parser error :: failed to allocate small amounts of memory, probably bad\n",
1uLL,
0x49uLL,
stderr);
*a3 = 1;
return v5;
}
if ( v19[0] == 2 )
{
fwrite("parser error :: argument to parameter \"-c\" has bad syntax\n", 1uLL, 0x3AuLL, stderr);
*a3 = 2;
return v5;
}
LABEL_29:
v16 = *((_DWORD *)v5 + 10);
*((_DWORD *)v5 + 10) = v16 + 1;
v17 = realloc(*((void **)v5 + 6), 8LL * (unsigned int)(v16 + 1));
if ( !v17 )
{
fwrite("parser error :: memory allocation failure\n", 1uLL, 0x2AuLL, stderr);
func9(v15);
--*((_DWORD *)v5 + 10);
*a3 = 1;
return v5;
}
*((_QWORD *)v5 + 6) = v17;
v17[*((_DWORD *)v5 + 10) - 1] = v15;
goto LABEL_12;
case 'i':
v9 = optarg;
v10 = strlen(optarg);
v11 = (char *)calloc(v10 + 1, 1uLL);
*((_QWORD *)v5 + 1) = v11;
if ( v11 )
goto LABEL_16;
goto LABEL_19;
case 'm':
v5[24] = 1;
v13 = _isoc99_sscanf(optarg, "%u %u", v5 + 28, v5 + 32);
if ( v13 )
{
if ( v13 == 1 )
{
*((_DWORD *)v5 + 8) = *((_DWORD *)v5 + 7);
*((_DWORD *)v5 + 7) = 0;
}
}
else
{
fwrite("parser error :: argument \"-m\" needs one or two positive numbers\n", 1uLL, 0x40uLL, stderr);
}
goto LABEL_12;
case 'o':
v9 = optarg;
v12 = strlen(optarg);
v11 = (char *)calloc(v12 + 1, 1uLL);
*((_QWORD *)v5 + 2) = v11;
if ( !v11 )
{
LABEL_19:
fwrite("parser error :: memory allocation failure\n", 1uLL, 0x2AuLL, stderr);
*a3 = 1;
return v5;
}
LABEL_16:
strcpy(v11, v9);
LABEL_12:
v6 = getopt(argc, argv, "Vvi:o:m:c:");
if ( v6 < 0 )
goto LABEL_3;
break;
case 'v':
*v5 = 1;
goto LABEL_12;
default:
goto LABEL_12;
}
}
}
LABEL_3:
if ( *v5 )
{
v7 = (const char *)*((_QWORD *)v5 + 1);
if ( v7 )
{
if ( v5[24] )
{
fwrite("Input: files '", 1uLL, 0xEuLL, stderr);
fprintf(stderr, *((const char **)v5 + 1), *((unsigned int *)v5 + 7));
fwrite("' to '", 1uLL, 6uLL, stderr);
fprintf(stderr, *((const char **)v5 + 1), *((unsigned int *)v5 + 8));
fwrite("' inclusive.\n", 1uLL, 0xDuLL, stderr);
}
else
{
fprintf(stderr, "Input: '%s'\n", v7);
}
}
v8 = (const char *)*((_QWORD *)v5 + 2);
if ( v8 )
{
if ( v5[24] )
{
fwrite("Output: files '", 1uLL, 0xFuLL, stderr);
fprintf(stderr, *((const char **)v5 + 2), *((unsigned int *)v5 + 7));
fwrite("' to '", 1uLL, 6uLL, stderr);
fprintf(stderr, *((const char **)v5 + 2), *((unsigned int *)v5 + 8));
fwrite("' inclusive.\n", 1uLL, 0xDuLL, stderr);
}
else
{
fprintf(stderr, "Output: '%s'\n", v8);
}
}
}
}
else
{
fwrite("parser error :: memory allocation failure\n", 1uLL, 0x2AuLL, stderr);
*a3 = 1;
}
return v5;
}

original_code:
setup_t *interpret_argv(int argc, char * const argv[], int *status) {
 *status = 0;
 setup_t *setup = calloc(1, sizeof(setup_t));
 if (setup == ((void *)0)) {
  fprintf(stderr, "parser error :: " "memory allocation failure\n");
  *status = 1;
  return setup;
 }
 const char *optstr = "Vvi:o:m:c:";
 opterr = 0;
 int opt = getopt(argc, argv, optstr);
 int actionstatus = 0;
 while (opt > -1) {
  action_t *action = ((void *)0);
  action_t **tmp = ((void *)0);
  switch (opt) {
   case 'V':
    fprintf(stderr, "Blitemoth, not much info right now...\n");
    break;
   case 'v':
    setup->verbose = 1;
    break;
   case 'i':
    setup->file.input = calloc(strlen(optarg)+1, sizeof(char));
    if (setup->file.input == ((void *)0)) {
     fprintf(stderr, "parser error :: " "memory allocation failure\n");
     *status = 1;
     return setup;
    }
    strcpy(setup->file.input, optarg);
    break;
   case 'o':
    setup->file.output = calloc(strlen(optarg)+1, sizeof(char));
    if (setup->file.output == ((void *)0)) {
     fprintf(stderr, "parser error :: " "memory allocation failure\n");
     *status = 1;
     return setup;
    }
    strcpy(setup->file.output, optarg);
    break;
   case 'm':
    setup->file.range = 1;
    int n = sscanf(optarg, "%u %u",
      &(setup->file.begin),
      &(setup->file.end));
    switch (n) {
     case 0:
      fprintf(stderr, "parser error :: " "argument \"-m\" needs one or two positive numbers\n");
      break;
     case 1:
      setup->file.end = setup->file.begin;
      setup->file.begin = 0;
      break;
    }
    break;
   case 'c':
    action = parse_action(optarg, &actionstatus);
    if (actionstatus != 0) {
     free_action(action);
     switch (actionstatus) {
      case 2:
       fprintf(stderr, "parser error :: " "argument to parameter \"-c\" has bad syntax\n");
       *status = 2;
       return setup;
       break;
      case 1:
       fprintf(stderr, "parser error :: " "failed to allocate small amounts of memory, probably bad\n");
       *status = 1;
       return setup;
       break;
     }
    }
    setup->work.count += 1;
    tmp = realloc(setup->work.action, setup->work.count*sizeof(action_t*));
    if (tmp == ((void *)0)) {
     fprintf(stderr, "parser error :: " "memory allocation failure\n");
     free_action(action);
     setup->work.count -= 1;
     *status = 1;
     return setup;
    }
    setup->work.action = tmp;
    setup->work.action[setup->work.count-1] = action;
    break;
   case '?':
    fprintf(stderr, "parser error :: " "Missing argument to parameter \"-%c\" or parameter \"%c\" not recognized.\n", optopt, optopt);
    *status = 3;
    return setup;
    break;
  }
  opt = getopt(argc, argv, optstr);
 }
 if (setup->verbose) {
  if (setup->file.input != ((void *)0)) {
   if (setup->file.range) {
    fprintf(stderr, "Input: files '");
    fprintf(stderr, setup->file.input, setup->file.begin);
    fprintf(stderr, "' to '");
    fprintf(stderr, setup->file.input, setup->file.end);
    fprintf(stderr, "' inclusive.\n");
   }
   else {
    fprintf(stderr, "Input: '%s'\n", setup->file.input);
   }
  }
  if (setup->file.output != ((void *)0)) {
   if (setup->file.range) {
    fprintf(stderr, "Output: files '");
    fprintf(stderr, setup->file.output, setup->file.begin);
    fprintf(stderr, "' to '");
    fprintf(stderr, setup->file.output, setup->file.end);
    fprintf(stderr, "' inclusive.\n");
   }
   else {
    fprintf(stderr, "Output: '%s'\n", setup->file.output);
   }
  }
 }
 return setup;
}

canonical_original_code:
struct setup_t *interpret_argv(int argc, char *argv[], int *status) {
 *status = 0;
 struct setup_t *setup = calloc(1, sizeof(setup_t));
 if (setup == ((void *)0)) {
  fprintf(stderr, "parser error :: " "memory allocation failure\n");
  *status = 1;
  return setup;
 }
 char *optstr = "Vvi:o:m:c:";
 opterr = 0;
 int opt = getopt(argc, argv, optstr);
 int actionstatus = 0;
 while (opt > -1) {
  struct action_t *action = ((void *)0);
  struct action_t **tmp = ((void *)0);
  switch (opt) {
   case 'V':
    fprintf(stderr, "Blitemoth, not much info right now...\n");
    break;
   case 'v':
    setup->verbose = 1;
    break;
   case 'i':
    setup->file.input = calloc(strlen(optarg)+1, sizeof(char));
    if (setup->file.input == ((void *)0)) {
     fprintf(stderr, "parser error :: " "memory allocation failure\n");
     *status = 1;
     return setup;
    }
    strcpy(setup->file.input, optarg);
    break;
   case 'o':
    setup->file.output = calloc(strlen(optarg)+1, sizeof(char));
    if (setup->file.output == ((void *)0)) {
     fprintf(stderr, "parser error :: " "memory allocation failure\n");
     *status = 1;
     return setup;
    }
    strcpy(setup->file.output, optarg);
    break;
   case 'm':
    setup->file.range = 1;
    int n = sscanf(optarg, "%u %u",
      &(setup->file.begin),
      &(setup->file.end));
    switch (n) {
     case 0:
      fprintf(stderr, "parser error :: " "argument \"-m\" needs one or two positive numbers\n");
      break;
     case 1:
      setup->file.end = setup->file.begin;
      setup->file.begin = 0;
      break;
    }
    break;
   case 'c':
    action = parse_action(optarg, &actionstatus);
    if (actionstatus != 0) {
     free_action(action);
     switch (actionstatus) {
      case 2:
       fprintf(stderr, "parser error :: " "argument to parameter \"-c\" has bad syntax\n");
       *status = 2;
       return setup;
       break;
      case 1:
       fprintf(stderr, "parser error :: " "failed to allocate small amounts of memory, probably bad\n");
       *status = 1;
       return setup;
       break;
     }
    }
    setup->work.count += 1;
    tmp = realloc(setup->work.action, setup->work.count*sizeof(struct action_t *));
    if (tmp == ((void *)0)) {
     fprintf(stderr, "parser error :: " "memory allocation failure\n");
     free_action(action);
     setup->work.count -= 1;
     *status = 1;
     return setup;
    }
    setup->work.action = tmp;
    setup->work.action[setup->work.count-1] = action;
    break;
   case '?':
    fprintf(stderr, "parser error :: " "Missing argument to parameter \"-%c\" or parameter \"%c\" not recognized.\n", optopt, optopt);
    *status = 3;
    return setup;
    break;
  }
  opt = getopt(argc, argv, optstr);
 }
 if (setup->verbose) {
  if (setup->file.input != ((void *)0)) {
   if (setup->file.range) {
    fprintf(stderr, "Input: files '");
    fprintf(stderr, setup->file.input, setup->file.begin);
    fprintf(stderr, "' to '");
    fprintf(stderr, setup->file.input, setup->file.end);
    fprintf(stderr, "' inclusive.\n");
   }
   else {
    fprintf(stderr, "Input: '%s'\n", setup->file.input);
   }
  }
  if (setup->file.output != ((void *)0)) {
   if (setup->file.range) {
    fprintf(stderr, "Output: files '");
    fprintf(stderr, setup->file.output, setup->file.begin);
    fprintf(stderr, "' to '");
    fprintf(stderr, setup->file.output, setup->file.end);
    fprintf(stderr, "' inclusive.\n");
   }
   else {
    fprintf(stderr, "Output: '%s'\n", setup->file.output);
   }
  }
 }
 return setup;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
status
int *

variable_types: struct setup_t { _Bool verbose; struct { char *input; char *output; _Bool range; unsigned int begin; unsigned int end; } file; struct { unsigned int count; struct action_t { struct ranged_val_t { _Bool is_ranged; int value; int start; int stop; } lbound; struct ranged_val_t ubound; struct palette_t { unsigned int n; unsigned int c[16]; } palette; struct order_t { unsigned char o[16]; } priority; _Bool splitab; struct edgemap_t { unsigned int priority; struct edgemap_mapopt_t { unsigned int type; struct ranged_val_t value; } matched; struct edgemap_mapopt_t unmatched; } below; struct edgemap_t above; } **action; } work; } *

variable_types:
optstr
char *

variable_types: opt int

variable_types: actionstatus int

variable_types: n int

user_defined_types: struct setup_t { _Bool verbose; struct { char *input; char *output; _Bool range; unsigned int begin; unsigned int end; } file; struct { unsigned int count; struct action_t **action; } work; }


decompiled_code:
void __fastcall free_setup(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
unsigned int v4; // ebx

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
if ( *((_QWORD *)ptr + 6) )
{
if ( *((_DWORD *)ptr + 10) )
{
v4 = 0;
do
free_action(*(void **)(*((_QWORD *)ptr + 6) + 8LL * v4++));
while ( *((_DWORD *)ptr + 10) > v4 );
}
free(*((void **)ptr + 6));
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
unsigned int v4; // ebx

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
if ( *((_QWORD *)ptr + 6) )
{
if ( *((_DWORD *)ptr + 10) )
{
v4 = 0;
do
func9(*(void **)(*((_QWORD *)ptr + 6) + 8LL * v4++));
while ( *((_DWORD *)ptr + 10) > v4 );
}
free(*((void **)ptr + 6));
}
free(ptr);
}
}

original_code:
setup_t *free_setup(setup_t *prisoner) {
 if (prisoner != ((void *)0)) {
  if (prisoner->file.input != ((void *)0))
   free(prisoner->file.input);
  if (prisoner->file.output != ((void *)0))
   free(prisoner->file.output);
  if (prisoner->work.action != ((void *)0)) {
   for (unsigned int i=0; i<prisoner->work.count; ++i) {
    free_action(prisoner->work.action[i]);
   }
   free(prisoner->work.action);
  }
  free(prisoner);
 }
}

canonical_original_code:
struct setup_t *free_setup(struct setup_t *prisoner) {
 if (prisoner != ((void *)0)) {
  if (prisoner->file.input != ((void *)0))
   free(prisoner->file.input);
  if (prisoner->file.output != ((void *)0))
   free(prisoner->file.output);
  if (prisoner->work.action != ((void *)0)) {
   for (unsigned int i = 0; i<prisoner->work.count; ++i) {
    free_action(prisoner->work.action[i]);
   }
   free(prisoner->work.action);
  }
  free(prisoner);
 }
}

variable_types:
prisoner
struct setup_t *

variable_types:
i
unsigned int

return_type: struct setup_t { _Bool verbose; struct { char *input; char *output; _Bool range; unsigned int begin; unsigned int end; } file; struct { unsigned int count; struct action_t { struct ranged_val_t { _Bool is_ranged; int value; int start; int stop; } lbound; struct ranged_val_t ubound; struct palette_t { unsigned int n; unsigned int c[16]; } palette; struct order_t { unsigned char o[16]; } priority; _Bool splitab; struct edgemap_t { unsigned int priority; struct edgemap_mapopt_t { unsigned int type; struct ranged_val_t value; } matched; struct edgemap_mapopt_t unmatched; } below; struct edgemap_t above; } **action; } work; } *


decompiled_code:
__int64 __fastcall ppm_free(void *ptr)
{
void *v2; // rdi

if ( !ptr )
return 0LL;
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
void *v2; // rdi

if ( !ptr )
return 0LL;
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
return 0LL;
}

original_code:
ppm_t *ppm_free(ppm_t *prisoner) {
 if (prisoner != ((void *)0)) {
  if (prisoner->data != ((void *)0)) {
   free(prisoner->data);
  }
  free(prisoner);
 }
 return ((void *)0);
}

canonical_original_code:
struct ppm_t *ppm_free(struct ppm_t *prisoner) {
 if (prisoner != ((void *)0)) {
  if (prisoner->data != ((void *)0)) {
   free(prisoner->data);
  }
  free(prisoner);
 }
 return ((void *)0);
}

variable_types:
prisoner
struct ppm_t *

return_type: struct ppm_t { unsigned int width; unsigned int height; union rgb888_t { struct { unsigned char r; } n; unsigned char c[3]; } *data; } *

user_defined_types: struct ppm_t { unsigned int width; unsigned int height; union rgb888_t *data; }


repo: tlvb/vitium

decompiled_code:
void __fastcall font_destroy(__int64 a1)
{
free(*(void **)(a1 + 40));
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
free(*(void **)(a1 + 40));
}

original_code:
void font_destroy(pcf2_font_t *font) {
 free(font->bitmap);
}

canonical_original_code:
void font_destroy(struct pcf2_font_t *font) {
 free(font->bitmap);
}

variable_types: struct pcf2_font_t { struct pcf2_header_t { unsigned char magic[4]; unsigned int version; unsigned int headersize; unsigned int flags; unsigned int length; unsigned int charsize; unsigned int height; unsigned int width; } header; unsigned int bpr; unsigned char *bitmap; } *

return_type: void

user_defined_types: struct pcf2_font_t { struct pcf2_header_t header; unsigned int bpr; unsigned char *bitmap; }


original_code:
void draw_glyph(bitmap_t *canvas, int x, int y, unsigned int c, const pcf2_font_t *f, const u83_t *fg) {
 for (int dy=0; dy<f->header.height; ++dy) {
  for (int dbx=0; dbx<f->bpr; ++dbx) {
   uint8_t fb = f->bitmap[c*f->header.charsize + dy*f->bpr + dbx];
   for (int dx=0; dx<8 && dx+dbx*8<f->header.width; ++dx) {
    int canvasx = x + dbx*8 + dx;
    int canvasy = y + dy;
    if (canvasx>=0 && canvasy>=0 && canvasx<canvas->width && canvasy<canvas->height) {
     unsigned int canvasi = canvasy*canvas->width + canvasx;
     if ((fb & (1<<(7-dx))) != 0) {
      memcpy(canvas->data+canvasi, fg, sizeof(u83_t));
     }
    }
   }
  }
 }
}

canonical_original_code:
void draw_glyph(struct bitmap_t *canvas, int x, int y, unsigned int c, struct pcf2_font_t *f, struct u83_t *fg) {
 for (int dy = 0; dy<f->header.height; ++dy) {
  for (int dbx = 0; dbx<f->bpr; ++dbx) {
   unsigned char fb = f->bitmap[c*f->header.charsize + dy*f->bpr + dbx];
   for (int dx = 0; dx<8 && dx+dbx*8<f->header.width; ++dx) {
    int canvasx = x + dbx*8 + dx;
    int canvasy = y + dy;
    if (canvasx>=0 && canvasy>=0 && canvasx<canvas->width && canvasy<canvas->height) {
     unsigned int canvasi = canvasy*canvas->width + canvasx;
     if ((fb & (1<<(7-dx))) != 0) {
      memcpy(canvas->data+canvasi, fg, sizeof(u83_t));
     }
    }
   }
  }
 }
}

variable_types: struct bitmap_t { unsigned int width; unsigned int height; struct u83_t { unsigned char x[3]; } *data; } *

variable_types: x int

variable_types: y int

variable_types:
c
unsigned int

variable_types:
fg
struct u83_t *

variable_types: dy int

variable_types: dbx int

variable_types:
fb
unsigned char

variable_types: dx int

variable_types: canvasx int

variable_types: canvasy int

variable_types:
canvasi
unsigned int

user_defined_types: struct bitmap_t { unsigned int width; unsigned int height; struct u83_t *data; }

user_defined_types: struct pcf2_header_t { unsigned char magic[4]; unsigned int version; unsigned int headersize; unsigned int flags; unsigned int length; unsigned int charsize; unsigned int height; unsigned int width; }


decompiled_code:
size_t __fastcall draw_string(__int64 a1, int a2, int a3, const char *a4, __int64 a5, __int64 a6)
{
unsigned int i; // ebx
size_t result; // rax

for ( i = 0; ; ++i )
{
result = strlen(a4);
if ( i >= result )
break;
draw_glyph(a1, a2 + *(_DWORD *)(a5 + 28) * i, a3, (unsigned __int8)a4[i], a5, a6);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func5(__int64 a1, int a2, int a3, const char *a4, __int64 a5, __int64 a6)
{
unsigned int i; // ebx
size_t result; // rax

for ( i = 0; ; ++i )
{
result = strlen(a4);
if ( i >= result )
break;
func4(a1, a2 + *(_DWORD *)(a5 + 28) * i, a3, (unsigned __int8)a4[i], a5, a6);
}
return result;
}

original_code:
void draw_string(bitmap_t *canvas, int x, int y, const char *s, const pcf2_font_t *f, const u83_t *fg){
 for (unsigned int i=0; i<strlen(s); ++i) {
  draw_glyph(canvas, x+i*f->header.width, y, (uint8_t)s[i], f, fg);
 }
}

canonical_original_code:
void draw_string(struct bitmap_t *canvas, int x, int y, char *s, struct pcf2_font_t *f, struct u83_t *fg){
 for (unsigned int i = 0; i<strlen(s); ++i) {
  draw_glyph(canvas, x+i*f->header.width, y, (unsigned char)s[i], f, fg);
 }
}

variable_types:
s
char *


original_code:
void draw_glyph_sc(bitmap_t *canvas, int x, int y, unsigned int c, const pcf2_font_t *f, const u83_t *fg, unsigned int sc) {
 for (int dy=0; dy<f->header.height; ++dy) {
  for (int dbx=0; dbx<f->bpr; ++dbx) {
   uint8_t fb = f->bitmap[c*f->header.charsize + dy*f->bpr + dbx];
   for (int dx=0; dx<8 && dx+dbx*8<f->header.width; ++dx) {
    for (int sy=0; sy<1<<sc; ++sy) {
     for (int sx=0; sx<1<<sc; ++sx) {
      int canvasx = sx+x + ((dbx*8 + dx)<<sc);
      int canvasy = sy+y + (dy<<sc);
      if (canvasx>=0 && canvasy>=0 && canvasx<canvas->width && canvasy<canvas->height) {
       unsigned int canvasi = canvasy*canvas->width + canvasx;
       if ((fb & (1<<(7-dx))) != 0) {
        memcpy(canvas->data+canvasi, fg, sizeof(u83_t));
       }
      }
     }
    }
   }
  }
 }
}

canonical_original_code:
void draw_glyph_sc(struct bitmap_t *canvas, int x, int y, unsigned int c, struct pcf2_font_t *f, struct u83_t *fg, unsigned int sc) {
 for (int dy = 0; dy<f->header.height; ++dy) {
  for (int dbx = 0; dbx<f->bpr; ++dbx) {
   unsigned char fb = f->bitmap[c*f->header.charsize + dy*f->bpr + dbx];
   for (int dx = 0; dx<8 && dx+dbx*8<f->header.width; ++dx) {
    for (int sy = 0; sy<1<<sc; ++sy) {
     for (int sx = 0; sx<1<<sc; ++sx) {
      int canvasx = sx+x + ((dbx*8 + dx)<<sc);
      int canvasy = sy+y + (dy<<sc);
      if (canvasx>=0 && canvasy>=0 && canvasx<canvas->width && canvasy<canvas->height) {
       unsigned int canvasi = canvasy*canvas->width + canvasx;
       if ((fb & (1<<(7-dx))) != 0) {
        memcpy(canvas->data+canvasi, fg, sizeof(u83_t));
       }
      }
     }
    }
   }
  }
 }
}

variable_types:
sc
unsigned int

variable_types: sy int

variable_types: sx int


decompiled_code:
size_t __fastcall draw_string_sc(__int64 a1, int a2, int a3, const char *a4, __int64 a5, __int64 a6, char a7)
{
unsigned int i; // ebx
size_t result; // rax

for ( i = 0; ; ++i )
{
result = strlen(a4);
if ( i >= result )
break;
draw_glyph_sc(a1, a2 + ((*(_DWORD *)(a5 + 28) * i) << a7), a3, (unsigned __int8)a4[i], a5, a6, a7);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(__int64 a1, int a2, int a3, const char *a4, __int64 a5, __int64 a6, char a7)
{
unsigned int i; // ebx
size_t result; // rax

for ( i = 0; ; ++i )
{
result = strlen(a4);
if ( i >= result )
break;
func6(a1, a2 + ((*(_DWORD *)(a5 + 28) * i) << a7), a3, (unsigned __int8)a4[i], a5, a6, a7);
}
return result;
}

original_code:
void draw_string_sc(bitmap_t *canvas, int x, int y, const char *s, const pcf2_font_t *f, const u83_t *fg, unsigned int sc) {
 for (unsigned int i=0; i<strlen(s); ++i) {
  draw_glyph_sc(canvas, x+i*f->header.width*(1<<sc), y, (uint8_t)s[i], f, fg, sc);
 }
}

canonical_original_code:
void draw_string_sc(struct bitmap_t *canvas, int x, int y, char *s, struct pcf2_font_t *f, struct u83_t *fg, unsigned int sc) {
 for (unsigned int i = 0; i<strlen(s); ++i) {
  draw_glyph_sc(canvas, x+i*f->header.width*(1<<sc), y, (unsigned char)s[i], f, fg, sc);
 }
}

variable_types: struct pcf2_font_t { struct pcf2_header_t { unsigned char magic[4]; unsigned int version; unsigned int headersize; unsigned int flags; unsigned int length; unsigned int charsize; unsigned int height; unsigned int width; } header; unsigned int bpr; unsigned char *bitmap; } *

variable_types:
i
unsigned int


original_code:
void draw_glyph_asc(bitmap_t *canvas, int x, int y, unsigned int c, const pcf2_font_t *f, const u83_t *fg, float a, unsigned int sc) {
 for (int dy=0; dy<f->header.height; ++dy) {
  for (int dbx=0; dbx<f->bpr; ++dbx) {
   uint8_t fb = f->bitmap[c*f->header.charsize + dy*f->bpr + dbx];
   for (int dx=0; dx<8 && dx+dbx*8<f->header.width; ++dx) {
    for (int sy=0; sy<1<<sc; ++sy) {
     for (int sx=0; sx<1<<sc; ++sx) {
      int canvasx = sx+x + ((dbx*8 + dx)<<sc);
      int canvasy = sy+y + (dy<<sc);
      if (canvasx>=0 && canvasy>=0 && canvasx<canvas->width && canvasy<canvas->height) {
       unsigned int canvasi = canvasy*canvas->width + canvasx;
       if ((fb & (1<<(7-dx))) != 0) {
        for (int i=0; i<3; ++i) {
         canvas->data[canvasi].x[i] = (fg->x[i]*a) + (canvas->data[canvasi].x[i]*(1.0f-a));
        }
       }
      }
     }
    }
   }
  }
 }
}

canonical_original_code:
void draw_glyph_asc(struct bitmap_t *canvas, int x, int y, unsigned int c, struct pcf2_font_t *f, struct u83_t *fg, float a, unsigned int sc) {
 for (int dy = 0; dy<f->header.height; ++dy) {
  for (int dbx = 0; dbx<f->bpr; ++dbx) {
   unsigned char fb = f->bitmap[c*f->header.charsize + dy*f->bpr + dbx];
   for (int dx = 0; dx<8 && dx+dbx*8<f->header.width; ++dx) {
    for (int sy = 0; sy<1<<sc; ++sy) {
     for (int sx = 0; sx<1<<sc; ++sx) {
      int canvasx = sx+x + ((dbx*8 + dx)<<sc);
      int canvasy = sy+y + (dy<<sc);
      if (canvasx>=0 && canvasy>=0 && canvasx<canvas->width && canvasy<canvas->height) {
       unsigned int canvasi = canvasy*canvas->width + canvasx;
       if ((fb & (1<<(7-dx))) != 0) {
        for (int i = 0; i<3; ++i) {
         canvas->data[canvasi].x[i] = (fg->x[i]*a) + (canvas->data[canvasi].x[i]*(1.0f-a));
        }
       }
      }
     }
    }
   }
  }
 }
}

variable_types: struct bitmap_t { unsigned int width; unsigned int height; struct u83_t { unsigned char x[3]; } *data; } *

variable_types: x int

variable_types: a float

variable_types: i int


decompiled_code:
size_t __fastcall draw_string_asc(__int64 a1, int a2, int a3, const char *a4, __int64 a5, __int64 a6, float a7, char a8)
{
unsigned int i; // ebx
size_t result; // rax

for ( i = 0; ; ++i )
{
result = strlen(a4);
if ( i >= result )
break;
draw_glyph_asc(a1, a2 + ((*(_DWORD *)(a5 + 28) * i) << a8), a3, (unsigned __int8)a4[i], a5, a6, a7, a8);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func9(__int64 a1, int a2, int a3, const char *a4, __int64 a5, __int64 a6, float a7, char a8)
{
unsigned int i; // ebx
size_t result; // rax

for ( i = 0; ; ++i )
{
result = strlen(a4);
if ( i >= result )
break;
func8(a1, a2 + ((*(_DWORD *)(a5 + 28) * i) << a8), a3, (unsigned __int8)a4[i], a5, a6, a7, a8);
}
return result;
}

original_code:
void draw_string_asc(bitmap_t *canvas, int x, int y, const char *s, const pcf2_font_t *f, const u83_t *fg, float a, unsigned int sc) {
 for (unsigned int i=0; i<strlen(s); ++i) {
  draw_glyph_asc(canvas, x+i*f->header.width*(1<<sc), y, (uint8_t)s[i], f, fg, a, sc);
 }
}

canonical_original_code:
void draw_string_asc(struct bitmap_t *canvas, int x, int y, char *s, struct pcf2_font_t *f, struct u83_t *fg, float a, unsigned int sc) {
 for (unsigned int i = 0; i<strlen(s); ++i) {
  draw_glyph_asc(canvas, x+i*f->header.width*(1<<sc), y, (unsigned char)s[i], f, fg, a, sc);
 }
}

variable_types: y int

variable_types:
fg
struct u83_t *


decompiled_code:
__int64 __fastcall bitmap_free(void *ptr)
{
void *v2; // rdi

if ( !ptr )
return 0LL;
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
void *v2; // rdi

if ( !ptr )
return 0LL;
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
return 0LL;
}

original_code:
bitmap_t *bitmap_free(bitmap_t *prisoner) {
 if (prisoner != ((void *)0)) {
  if (prisoner->data != ((void *)0)) {
   free(prisoner->data);
  }
  free(prisoner);
 }
 return ((void *)0);
}

canonical_original_code:
struct bitmap_t *bitmap_free(struct bitmap_t *prisoner) {
 if (prisoner != ((void *)0)) {
  if (prisoner->data != ((void *)0)) {
   free(prisoner->data);
  }
  free(prisoner);
 }
 return ((void *)0);
}

variable_types:
prisoner
struct bitmap_t *

return_type: struct bitmap_t { unsigned int width; unsigned int height; struct u83_t { unsigned char x[3]; } *data; } *


variable_types:
ido
struct u83_t { unsigned char x[3]; } *

variable_types:
idi
struct u83_t *

variable_types:
n
unsigned long

variable_types:
i
unsigned long

variable_types: r double

variable_types: g double

variable_types: b double

variable_types: y double

variable_types: cb double

variable_types: cr double


canonical_original_code:
void to_rgb(struct u83_t *ido, struct u83_t *idi, unsigned long n) {
 for (unsigned long i = 0; i<n; ++i) {
  double y = (double) idi[i].x[0];
  double cb = (double) idi[i].x[1];
  double cr = (double) idi[i].x[2];
  double r = y + 1.40200*(cr-128);
  double g = y - 0.34414*(cb-128) - 0.71414*(cr-128);
  double b = y + 1.77200*(cb-128);
  r = ((r<0)?0:((r>255)?255:r));
  g = ((g<0)?0:((g>255)?255:g));
  b = ((b<0)?0:((b>255)?255:b));
  ido[i].x[0] = (unsigned char) round(r);
  ido[i].x[1] = (unsigned char) round(g);
  ido[i].x[2] = (unsigned char) round(b);
 }
}


decompiled_code:
int __fastcall counter_init(pthread_mutex_t **a1, pthread_mutex_t *a2, pthread_mutex_t *a3)
{
pthread_mutex_t *v4; // rax
int result; // eax

v4 = (pthread_mutex_t *)malloc(0x28uLL);
*a1 = v4;
if ( !v4 )
_assert_fail("c->m != NULL", "src/counter.c", 7u, "counter_init");
result = pthread_mutex_init(v4, 0LL);
a1[1] = a2;
a1[2] = a3;
a1[3] = a2;
return result;
}

canonical_decompiled_code:
int __fastcall func0(pthread_mutex_t **a1, pthread_mutex_t *a2, pthread_mutex_t *a3)
{
pthread_mutex_t *v4; // rax
int result; // eax

v4 = (pthread_mutex_t *)malloc(0x28uLL);
*a1 = v4;
if ( !v4 )
_assert_fail("c->m != NULL", "src/counter.c", 7u, "counter_init");
result = pthread_mutex_init(v4, 0LL);
a1[1] = a2;
a1[2] = a3;
a1[3] = a2;
return result;
}

original_code:
void counter_init(counter_t *c, const size_t start, const size_t end) {
 c->m = malloc(sizeof(pthread_mutex_t));
 ((void) sizeof ((c->m != ((void *)0)) ? 1 : 0), __extension__ ({ if (c->m != ((void *)0)) ; else __assert_fail ("c->m != NULL", "src/counter.c", 7, __extension__ __PRETTY_FUNCTION__); }));
 pthread_mutex_init(c->m, ((void *)0));
 c->start = start;
 c->end = end;
 c->next = start;
}

canonical_original_code:
void counter_init(struct counter_t *c, unsigned long start, unsigned long end) {
 c->m = malloc(sizeof(pthread_mutex_t));
 ((void) sizeof ((c->m != ((void *)0)) ? 1 : 0), __extension__ ({ if (c->m != ((void *)0)) ; else __assert_fail ("c->m != NULL", "src/counter.c", 7, __extension__ __PRETTY_FUNCTION__); }));
 pthread_mutex_init(c->m, ((void *)0));
 c->start = start;
 c->end = end;
 c->next = start;
}

variable_types: struct counter_t { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *m; unsigned long start; unsigned long end; unsigned long next; } *

variable_types:
start
unsigned long

variable_types:
end
unsigned long

user_defined_types: struct counter_t { union pthread_mutex_t *m; unsigned long start; unsigned long end; unsigned long next; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


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

pthread_mutex_lock(*(pthread_mutex_t **)a1);
v1 = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 24) = v1 + 1;
pthread_mutex_unlock(*(pthread_mutex_t **)a1);
return v1;
}

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

pthread_mutex_lock(*(pthread_mutex_t **)a1);
v1 = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 24) = v1 + 1;
pthread_mutex_unlock(*(pthread_mutex_t **)a1);
return v1;
}

original_code:
size_t counter_get(counter_t *c) {
 size_t current;
 pthread_mutex_lock(c->m);
 current = c->next++;
 pthread_mutex_unlock(c->m);
 return current;
}

canonical_original_code:
unsigned long counter_get(struct counter_t *c) {
 unsigned long current;
 pthread_mutex_lock(c->m);
 current = c->next++;
 pthread_mutex_unlock(c->m);
 return current;
}

variable_types:
current
unsigned long

return_type: unsigned long

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


original_code:
int buffer_destroy(buffer_t *b, void *state) {
 for (size_t i=0; i<b->pop; ++i) {
  (*b->relinquisher)(b->storage[i].data, b->storage[i].index, state, 1);
 }
 free(b->storage);
 b->bsize = 0;
 pthread_mutex_destroy(b->m);
 free(b->m);
}

canonical_original_code:
int buffer_destroy(struct buffer_t *b, void *state) {
 for (unsigned long i = 0; i<b->pop; ++i) {
  (*b->relinquisher)(b->storage[i].data, b->storage[i].index, state, 1);
 }
 free(b->storage);
 b->bsize = 0;
 pthread_mutex_destroy(b->m);
 free(b->m);
}

variable_types: struct buffer_t { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *m; struct buffer_point_t { unsigned int index; unsigned int readercount; void *data; } *storage; unsigned long bsize; unsigned long pop; void *(*reader)(unsigned int index, void *old, void *state, int *status); void (*relinquisher)(void *data, unsigned int index, void *state, _Bool kill); } *

variable_types:
state
void *

return_type: int

user_defined_types: struct buffer_t { union pthread_mutex_t *m; struct buffer_point_t *storage; unsigned long bsize; unsigned long pop; void *(*reader)(unsigned int index, void *old, void *state, int *status); void (*relinquisher)(void *data, unsigned int index, void *state, _Bool kill); }


decompiled_code:
int __fastcall buffer_relinquish(__int64 a1, unsigned int a2, __int64 a3, pthread_cond_t *a4)
{
__int64 v7; // rcx
__int64 v8; // rax
__int64 v9; // rdx
int v10; // edi

pthread_mutex_lock(*(pthread_mutex_t **)a1);
v7 = *(_QWORD *)(a1 + 24);
if ( v7 )
{
v8 = *(_QWORD *)(a1 + 8);
v9 = 0LL;
while ( 1 )
{
if ( *(_DWORD *)v8 == a2 )
{
v10 = *(_DWORD *)(v8 + 4);
if ( v10 )
break;
}
++v9;
v8 += 16LL;
if ( v9 == v7 )
return pthread_mutex_unlock(*(pthread_mutex_t **)a1);
}
*(_DWORD *)(v8 + 4) = v10 - 1;
(*(void (__fastcall **)(_QWORD, _QWORD, __int64, _QWORD))(a1 + 40))(*(_QWORD *)(v8 + 8), a2, a3, 0LL);
if ( a4 )
pthread_cond_signal(a4);
}
return pthread_mutex_unlock(*(pthread_mutex_t **)a1);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, unsigned int a2, __int64 a3, pthread_cond_t *a4)
{
__int64 v7; // rcx
__int64 v8; // rax
__int64 v9; // rdx
int v10; // edi

pthread_mutex_lock(*(pthread_mutex_t **)a1);
v7 = *(_QWORD *)(a1 + 24);
if ( v7 )
{
v8 = *(_QWORD *)(a1 + 8);
v9 = 0LL;
while ( 1 )
{
if ( *(_DWORD *)v8 == a2 )
{
v10 = *(_DWORD *)(v8 + 4);
if ( v10 )
break;
}
++v9;
v8 += 16LL;
if ( v9 == v7 )
return pthread_mutex_unlock(*(pthread_mutex_t **)a1);
}
*(_DWORD *)(v8 + 4) = v10 - 1;
(*(void (__fastcall **)(_QWORD, _QWORD, __int64, _QWORD))(a1 + 40))(*(_QWORD *)(v8 + 8), a2, a3, 0LL);
if ( a4 )
pthread_cond_signal(a4);
}
return pthread_mutex_unlock(*(pthread_mutex_t **)a1);
}

original_code:
void buffer_relinquish(buffer_t *b, unsigned int index, void *state, pthread_cond_t *wait_var) {
 pthread_mutex_lock(b->m);
 for (size_t i=0; i<b->pop; ++i) {
  buffer_point_t *bp = &b->storage[i];
  if (bp->index == index && bp->readercount > 0) {
   --bp->readercount;
   (*b->relinquisher)(bp->data, index, state, 0);
   if (wait_var != ((void *)0)) {
    pthread_cond_signal(wait_var);
   }
   break;
  }
 }
 pthread_mutex_unlock(b->m);
}

canonical_original_code:
void buffer_relinquish(struct buffer_t *b, unsigned int index, void *state, union pthread_cond_t *wait_var) {
 pthread_mutex_lock(b->m);
 for (unsigned long i = 0; i<b->pop; ++i) {
  struct buffer_point_t *bp = &b->storage[i];
  if (bp->index == index && bp->readercount > 0) {
   --bp->readercount;
   (*b->relinquisher)(bp->data, index, state, 0);
   if (wait_var != ((void *)0)) {
    pthread_cond_signal(wait_var);
   }
   break;
  }
 }
 pthread_mutex_unlock(b->m);
}

variable_types:
index
unsigned int

variable_types: union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } *

variable_types: struct buffer_point_t { unsigned int index; unsigned int readercount; void *data; } *

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }


original_code:
void scalepow2(bitmap_t *out, bitmap_t *in, unsigned int spow) {
 unsigned int limit = 1<<spow;
 for (size_t ty=0; ty<out->height; ++ty) {
  for (size_t tx=0; tx<out->width; ++tx) {
   size_t tp = tx + ty*out->width;
   unsigned int ys = 0;
   unsigned int cbs = 0;
   unsigned int crs = 0;
   size_t ctr = 0;
   for (size_t y=0; y<limit; ++y) {
    size_t sy = ty*limit + y;
    if (sy >= in->height) { break; }
    for (size_t x=0; x<limit; ++x) {
     size_t sx = tx*limit + x;
     if (sx >= in->width) { break; }
     size_t sp = sx + sy*in->width;
     ys += in->data[sp].x[0];
     cbs += in->data[sp].x[1];
     crs += in->data[sp].x[2];
     ++ctr;
    }
   }
   ctr = ctr==0?1:ctr;
   out->data[tp].x[0] = ys/ctr;
   out->data[tp].x[1] = cbs/ctr;
   out->data[tp].x[2] = crs/ctr;
  }
 }
}

canonical_original_code:
void scalepow2(struct bitmap_t *out, struct bitmap_t *in, unsigned int spow) {
 unsigned int limit = 1<<spow;
 for (unsigned long ty = 0; ty<out->height; ++ty) {
  for (unsigned long tx = 0; tx<out->width; ++tx) {
   unsigned long tp = tx + ty*out->width;
   unsigned int ys = 0;
   unsigned int cbs = 0;
   unsigned int crs = 0;
   unsigned long ctr = 0;
   for (unsigned long y = 0; y<limit; ++y) {
    unsigned long sy = ty*limit + y;
    if (sy >= in->height) { break; }
    for (unsigned long x = 0; x<limit; ++x) {
     unsigned long sx = tx*limit + x;
     if (sx >= in->width) { break; }
     unsigned long sp = sx + sy*in->width;
     ys += in->data[sp].x[0];
     cbs += in->data[sp].x[1];
     crs += in->data[sp].x[2];
     ++ctr;
    }
   }
   ctr = ctr==0?1:ctr;
   out->data[tp].x[0] = ys/ctr;
   out->data[tp].x[1] = cbs/ctr;
   out->data[tp].x[2] = crs/ctr;
  }
 }
}

variable_types: struct bitmap_t { unsigned int width; unsigned int height; struct u83_t { unsigned char x[3]; } *data; } *

variable_types:
in
struct bitmap_t *

variable_types:
spow
unsigned int

variable_types:
limit
unsigned int

variable_types:
ty
unsigned long

variable_types:
tx
unsigned long

variable_types:
tp
unsigned long

variable_types:
ys
unsigned int

variable_types:
cbs
unsigned int

variable_types:
crs
unsigned int

variable_types:
ctr
unsigned long

variable_types:
y
unsigned long

variable_types:
sy
unsigned long

variable_types:
x
unsigned long

variable_types:
sx
unsigned long

variable_types:
sp
unsigned long


repo: acceso/jOS

decompiled_code:
// attributes: thunk
void __noreturn kernel_idle()
{
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func0()
{
while ( 1 )
;
}

original_code:
void kernel_idle(void)
{
 while (1)
  ;
}

canonical_original_code:
void kernel_idle()
{
 while (1)
  ;
}


decompiled_code:
void __noreturn sys_exit()
{
_enable();
kernel_idle();
}

canonical_decompiled_code:
void __noreturn func1()
{
_enable();
func0();
}

original_code:
void sys_exit(u64 code)
{
 asm volatile("sti\n\t");
 kernel_idle();
}

canonical_original_code:
void sys_exit(unsigned long code)
{
 asm volatile("sti\n\t");
 kernel_idle();
}

variable_types:
code
unsigned long


decompiled_code:
__int64 init_task()
{
_BYTE *v0; // rax
_QWORD *v1; // rdx

syscall_register(60LL, sys_exit);
v0 = (_BYTE *)xkmallocf(272LL, "init_task");
init = (__int64)v0;
*v0 = 0;
v1 = v0 + 8;
do
*v1++ = 0LL;
while ( v1 != (_QWORD *)(v0 + 264) );
load_init_page_tables(v0);
return init;
}

canonical_decompiled_code:
__int64 func2()
{
_BYTE *v0; // rax
_QWORD *v1; // rdx

syscall_register(60LL, sys_exit);
v0 = (_BYTE *)xkmallocf(272LL, "init_task");
init = (__int64)v0;
*v0 = 0;
v1 = v0 + 8;
do
*v1++ = 0LL;
while ( v1 != (_QWORD *)(v0 + 264) );
load_init_page_tables(v0);
return init;
}

original_code:
struct task *init_task(void)
{
 u8 i;
 syscall_register(60, sys_exit);
 init = xkmallocf(sizeof(struct task), __func__);
 init->state = 0;
 for (i = 0; i < 32; i++)
  init->fds[i] = ((void *)0);
 load_init_page_tables(init);
 return init;
}

canonical_original_code:
struct task *init_task()
{
 unsigned char i;
 syscall_register(60, sys_exit);
 init = xkmallocf(sizeof(struct task), __func__);
 init->state = 0;
 for (i = 0; i < 32; i++)
  init->fds[i] = ((void *)0);
 load_init_page_tables(init);
 return init;
}

variable_types:
i
unsigned char

return_type: struct task { unsigned char state; struct file { struct inode { struct super { struct dev_t { unsigned int major; unsigned int minor; } dev; unsigned long blocksize; unsigned long blocksizephys; struct list_head { struct list_head *prev; } bcache; struct list_head icache; struct super_ops { struct super *(*super_read)(struct dev_t *dev); struct inode *(*inode_read)(struct super *sb, unsigned long inum); } *ops; unsigned long magic; unsigned long time; struct inode *mounted; unsigned int flags; void *priv; } *sb; unsigned long num; unsigned short mode; unsigned char nlinks; unsigned int uid; unsigned int gid; unsigned long filesize; unsigned long nblocks; unsigned long atime; unsigned long mtime; unsigned long ctime; unsigned int flags; unsigned int count; struct list_head l; struct super *covered; struct inode_ops { struct inode *(*lookup)(struct inode *, char *, unsigned char); unsigned long (*bmap)(struct inode *, long); struct bhead { struct list_head l; unsigned long bnum; void *data; unsigned char count; } *(*block_read)(struct inode *, long); } *ops; void *priv; } *inode; unsigned short count; unsigned short mode; unsigned short flags; long pos; } *fds[32]; struct mm { struct list_head l; unsigned long *pgd; unsigned char count; void *code_start; void *code_end; void *data_start; void *data_end; void *heap_start; void *heap_end; void *stack_start; unsigned short used_pages; } *mm; } *

user_defined_types: struct task { unsigned char state; struct file *fds[32]; struct mm *mm; }

user_defined_types: struct file { struct inode *inode; unsigned short count; unsigned short mode; unsigned short flags; long pos; }

user_defined_types: struct inode { struct super *sb; unsigned long num; unsigned short mode; unsigned char nlinks; unsigned int uid; unsigned int gid; unsigned long filesize; unsigned long nblocks; unsigned long atime; unsigned long mtime; unsigned long ctime; unsigned int flags; unsigned int count; struct list_head l; struct super *covered; struct inode_ops *ops; void *priv; }

user_defined_types: struct super { struct dev_t dev; unsigned long blocksize; unsigned long blocksizephys; struct list_head bcache; struct list_head icache; struct super_ops *ops; unsigned long magic; unsigned long time; struct inode *mounted; unsigned int flags; void *priv; }

user_defined_types: struct inode_ops { struct inode *(*lookup)(struct inode *, char *, unsigned char); unsigned long (*bmap)(struct inode *, long); struct bhead *(*block_read)(struct inode *, long); }


decompiled_code:
__int64 ext2_bread()
{
return bread();
}

canonical_decompiled_code:
__int64 func0()
{
return bread();
}

original_code:
struct bhead *ext2_bread(struct super *sb, size_t bnum)
{
 return bread(sb, bnum);
}

canonical_original_code:
struct bhead *ext2_bread(struct super *sb, unsigned long bnum)
{
 return bread(sb, bnum);
}

variable_types: struct super { struct dev_t { unsigned int major; unsigned int minor; } dev; unsigned long blocksize; unsigned long blocksizephys; struct list_head bcache; struct list_head icache; struct super_ops { struct super *(*super_read)(struct dev_t *dev); struct inode { struct super *sb; unsigned long num; unsigned short mode; unsigned char nlinks; unsigned int uid; unsigned int gid; unsigned long filesize; unsigned long nblocks; unsigned long atime; unsigned long mtime; unsigned long ctime; unsigned int flags; unsigned int count; struct list_head l; struct super *covered; struct inode_ops { struct inode *(*lookup)(struct inode *, char *, unsigned char); unsigned long (*bmap)(struct inode *, long); struct bhead *(*block_read)(struct inode *, long); } *ops; void *priv; } *(*inode_read)(struct super *sb, unsigned long inum); } *ops; unsigned long magic; unsigned long time; struct inode *mounted; unsigned int flags; void *priv; } *

variable_types:
bnum
unsigned long

return_type: struct bhead { struct list_head { struct list_head *prev; } l; unsigned long bnum; void *data; unsigned char count; } *

user_defined_types: struct bhead { struct list_head l; unsigned long bnum; void *data; unsigned char count; }

user_defined_types: struct super_ops { struct super *(*super_read)(struct dev_t *dev); struct inode *(*inode_read)(struct super *sb, unsigned long inum); }


bopen

decompiled_code:
__int64 __fastcall bopen(_DWORD *a1)
{
__int64 (*v1)(void); // rax
__int64 result; // rax

if ( *a1 <= 1u && (v1 = (__int64 (*)(void))**((_QWORD **)&bdevsw + (unsigned int)*a1)) != 0LL )
result = v1();
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
__int64 (*v1)(void); // rax
__int64 result; // rax

if ( *a1 <= 1u && (v1 = (__int64 (*)(void))**((_QWORD **)&bdevsw + (unsigned int)*a1)) != 0LL )
result = v1();
else
result = 0LL;
return result;
}

original_code:
size_t bopen(dev_t *dev)
{
 if (dev->major >= 2)
  return 0;
 if (bdevsw[dev->major]->open == ((void *)0))
  return 0;
 return bdevsw[dev->major]->open(dev);
}

canonical_original_code:
unsigned long bopen(struct dev_t *dev)
{
 if (dev->major >= 2)
  return 0;
 if (bdevsw[dev->major]->open == ((void *)0))
  return 0;
 return bdevsw[dev->major]->open(dev);
}

variable_types: struct dev_t { unsigned int major; unsigned int minor; } *


breadu

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

if ( *a1 <= 1u && (v3 = *(__int64 (__fastcall **)(_DWORD *, __int64, __int64))(bdevsw[*a1] + 16LL)) != 0LL )
result = v3(a1, a2, a3);
else
result = 0LL;
return result;
}

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

if ( *a1 <= 1u && (v3 = *(__int64 (__fastcall **)(_DWORD *, __int64, __int64))(bdevsw[*a1] + 16LL)) != 0LL )
result = v3(a1, a2, a3);
else
result = 0LL;
return result;
}

original_code:
size_t breadu(dev_t *dev, size_t pos, void *addr, size_t count)
{
 if (dev->major >= 2)
  return 0;
 if (bdevsw[dev->major]->read == ((void *)0))
  return 0;
 return bdevsw[dev->major]->read(dev, pos, addr, count);
}

canonical_original_code:
unsigned long breadu(struct dev_t *dev, unsigned long pos, void *addr, unsigned long count)
{
 if (dev->major >= 2)
  return 0;
 if (bdevsw[dev->major]->read == ((void *)0))
  return 0;
 return bdevsw[dev->major]->read(dev, pos, addr, count);
}

variable_types:
pos
unsigned long

variable_types:
addr
void *

variable_types:
count
unsigned long

user_defined_types: struct dev_t { unsigned int major; unsigned int minor; }


bwrite

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

if ( *a1 <= 1u && (v3 = *(__int64 (__fastcall **)(_DWORD *, __int64, __int64))(bdevsw[*a1] + 24LL)) != 0LL )
result = v3(a1, a2, a3);
else
result = 0LL;
return result;
}

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

if ( *a1 <= 1u && (v3 = *(__int64 (__fastcall **)(_DWORD *, __int64, __int64))(bdevsw[*a1] + 24LL)) != 0LL )
result = v3(a1, a2, a3);
else
result = 0LL;
return result;
}

original_code:
size_t bwrite(dev_t *dev, size_t pos, void *addr, size_t count)
{
 if (dev->major >= 2)
  return 0;
 if (bdevsw[dev->major]->write == ((void *)0))
  return 0;
 return bdevsw[dev->major]->write(dev, pos, addr, count);
}

canonical_original_code:
unsigned long bwrite(struct dev_t *dev, unsigned long pos, void *addr, unsigned long count)
{
 if (dev->major >= 2)
  return 0;
 if (bdevsw[dev->major]->write == ((void *)0))
  return 0;
 return bdevsw[dev->major]->write(dev, pos, addr, count);
}


decompiled_code:
void init_bdev()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void init_bdev(void)
{
}

canonical_original_code:
void init_bdev()
{
}


xkmallocf

decompiled_code:
__int64 __fastcall xkmallocf(unsigned __int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = kmalloc(a1);
if ( !v2 )
oom(a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = func0(a1);
if ( !v2 )
oom(a2);
return v2;
}

original_code:
void *xkmallocf(size_t size, const char *msg)
{
 void *ptr;
 ptr = kmalloc(size);
 if (ptr == ((void *)0))
  oom(msg);
 return ptr;
}

canonical_original_code:
void *xkmallocf(unsigned long size, char *msg)
{
 void *ptr;
 ptr = kmalloc(size);
 if (ptr == ((void *)0))
  oom(msg);
 return ptr;
}

variable_types:
size
unsigned long

variable_types:
msg
char *

variable_types:
ptr
void *

return_type: void *


decompiled_code:
void *__fastcall xkmallocf0(size_t n, __int64 a2)
{
void *v2; // rbx

v2 = (void *)xkmallocf(n, a2);
memset(v2, 0, n);
return v2;
}

canonical_decompiled_code:
void *__fastcall func2(size_t n, __int64 a2)
{
void *v2; // rbx

v2 = (void *)func1(n, a2);
memset(v2, 0, n);
return v2;
}

original_code:
void *xkmallocf0(size_t size, const char *msg)
{
 void *p;
 p = xkmallocf(size, msg);
 memset(p, '\0', size);
 return p;
}

canonical_original_code:
void *xkmallocf0(unsigned long size, char *msg)
{
 void *p;
 p = xkmallocf(size, msg);
 memset(p, '\0', size);
 return p;
}

variable_types:
p
void *


kfree

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

result = kcache_free(kmalloc16, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc32, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc64, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc128, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc256, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc512, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc1024, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc2048, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc4096, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc8192, a1);
if ( (_BYTE)result != 1 )
result = kma_free(a1);
}
}
}
}
}
}
}
}
}
return result;
}

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

result = kcache_free(kmalloc16, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc32, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc64, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc128, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc256, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc512, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc1024, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc2048, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc4096, a1);
if ( (_BYTE)result != 1 )
{
result = kcache_free(kmalloc8192, a1);
if ( (_BYTE)result != 1 )
result = kma_free(a1);
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
void kfree(void *ptr)
{
 if (kcache_free(kmalloc16, ptr) == 1)
  return;
 if (kcache_free(kmalloc32, ptr) == 1)
  return;
 if (kcache_free(kmalloc64, ptr) == 1)
  return;
 if (kcache_free(kmalloc128, ptr) == 1)
  return;
 if (kcache_free(kmalloc256, ptr) == 1)
  return;
 if (kcache_free(kmalloc512, ptr) == 1)
  return;
 if (kcache_free(kmalloc1024, ptr) == 1)
  return;
 if (kcache_free(kmalloc2048, ptr) == 1)
  return;
 if (kcache_free(kmalloc4096, ptr) == 1)
  return;
 if (kcache_free(kmalloc8192, ptr) == 1)
  return;
 kma_free(ptr);
 return;
}


decompiled_code:
void init_kmalloc()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void init_kmalloc(void)
{
 return;
 kmalloc16 = kcache_create("kmalloc-16", 16);
 kmalloc32 = kcache_create("kmalloc-32", 32);
 kmalloc64 = kcache_create("kmalloc-64", 64);
 kmalloc128 = kcache_create("kmalloc-128", 128);
 kmalloc256 = kcache_create("kmalloc-256", 256);
 kmalloc512 = kcache_create("kmalloc-512", 512);
 kmalloc1024 = kcache_create("kmalloc-1024", 1024);
 kmalloc2048 = kcache_create("kmalloc-2048", 2048);
 kmalloc4096 = kcache_create("kmalloc-4096", 4096);
 kmalloc8192 = kcache_create("kmalloc-8192", 8192);
 return;
}

canonical_original_code:
void init_kmalloc()
{
 return;
 kmalloc16 = kcache_create("kmalloc-16", 16);
 kmalloc32 = kcache_create("kmalloc-32", 32);
 kmalloc64 = kcache_create("kmalloc-64", 64);
 kmalloc128 = kcache_create("kmalloc-128", 128);
 kmalloc256 = kcache_create("kmalloc-256", 256);
 kmalloc512 = kcache_create("kmalloc-512", 512);
 kmalloc1024 = kcache_create("kmalloc-1024", 1024);
 kmalloc2048 = kcache_create("kmalloc-2048", 2048);
 kmalloc4096 = kcache_create("kmalloc-4096", 4096);
 kmalloc8192 = kcache_create("kmalloc-8192", 8192);
 return;
}


isdigit

decompiled_code:
bool __fastcall isdigit(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

canonical_decompiled_code:
bool __fastcall func0(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

original_code:
static inline u8 isdigit(char c)
{
 return c >= '0' && c <= '9';
}

canonical_original_code:
static inline unsigned char isdigit(char c)
{
 return c >= '0' && c <= '9';
}

variable_types: c char

return_type: unsigned char


itoau

decompiled_code:
unsigned __int64 __fastcall itoau(unsigned __int64 a1, unsigned __int8 *a2, unsigned __int8 a3)
{
unsigned __int8 *v3; // r8
unsigned __int8 *i; // rcx
unsigned __int8 v5; // al
unsigned __int64 result; // rax

v3 = a2;
for ( i = a2; ; ++i )
{
v5 = a1 % a3 + 87;
if ( (int)(a1 % a3) <= 9 )
v5 = a1 % a3 + 48;
*i = v5;
result = a1 / a3;
if ( a3 > a1 )
break;
a1 /= a3;
}
i[1] = 0;
if ( i > a2 )
{
do
{
result = *v3++;
*(v3 - 1) = *i--;
i[1] = result;
}
while ( v3 < i );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 a1, unsigned __int8 *a2, unsigned __int8 a3)
{
unsigned __int8 *v3; // r8
unsigned __int8 *i; // rcx
unsigned __int8 v5; // al
unsigned __int64 result; // rax

v3 = a2;
for ( i = a2; ; ++i )
{
v5 = a1 % a3 + 87;
if ( (int)(a1 % a3) <= 9 )
v5 = a1 % a3 + 48;
*i = v5;
result = a1 / a3;
if ( a3 > a1 )
break;
a1 /= a3;
}
i[1] = 0;
if ( i > a2 )
{
do
{
result = *v3++;
*(v3 - 1) = *i--;
i[1] = result;
}
while ( v3 < i );
}
return result;
}

original_code:
static void itoau(u64 n, char *s, u8 base)
{
 char *p;
 u64 pn = n;
 p = s;
 do {
  int rem = pn % base;
  *p++ = (rem < 10) ? rem + '0' : rem + 'a' - 10;
 } while (pn /= base);
 *p-- = '\0';
 while (p > s) {
  char tmp = *s;
  *s++ = *p;
  *p-- = tmp;
 }
}

canonical_original_code:
static void itoau(unsigned long n, char *s, unsigned char base)
{
 char *p;
 unsigned long pn = n;
 p = s;
 do {
  int rem = pn % base;
  *p++ = (rem < 10) ? rem + '0' : rem + 'a' - 10;
 } while (pn /= base);
 *p-- = '\0';
 while (p > s) {
  char tmp = *s;
  *s++ = *p;
  *p-- = tmp;
 }
}

variable_types:
n
unsigned long

variable_types:
s
char *

variable_types:
base
unsigned char

variable_types:
p
char *

variable_types:
pn
unsigned long

variable_types: rem int

variable_types: tmp char


kputs

decompiled_code:
__int64 __fastcall kputs(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
unsigned __int8 v2; // di
__int64 result; // rax

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
++v1;
result = vga_writechar(v2);
v2 = *v1;
}
while ( *v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
unsigned __int8 v2; // di
__int64 result; // rax

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
++v1;
result = vga_writechar(v2);
v2 = *v1;
}
while ( *v1 );
}
return result;
}

original_code:
void kputs(const char *s)
{
 while (*s)
  vga_writechar(*s++);
}

canonical_original_code:
void kputs(char *s)
{
 while (*s)
  vga_writechar(*s++);
}


namei

decompiled_code:
__int64 __fastcall namei(_BYTE *a1)
{
__int64 v1; // r12
const char *v2; // rbx
char i; // al
__int16 v4; // bp

if ( !a1 )
return 0LL;
v1 = 0LL;
if ( *a1 == 47 )
{
v1 = root;
v2 = a1 + 1;
while ( 1 )
{
for ( i = *v2; *v2 == 47; i = *v2 )
++v2;
if ( !i )
break;
v4 = strlen2sep(v2, 47LL);
if ( v4 == -1 )
v4 = strlen(v2);
if ( !v4 )
break;
if ( root == v1 && !(unsigned __int8)strncmp(v2, "..", v4) )
{
v2 += v4;
}
else
{
v1 = (**(__int64 (__fastcall ***)(__int64, const char *, _QWORD))(v1 + 104))(v1, v2, (unsigned __int8)v4);
if ( !v1 )
return v1;
v2 += v4;
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int64 v1; // r12
const char *v2; // rbx
char i; // al
__int16 v4; // bp

if ( !a1 )
return 0LL;
v1 = 0LL;
if ( *a1 == 47 )
{
v1 = root;
v2 = a1 + 1;
while ( 1 )
{
for ( i = *v2; *v2 == 47; i = *v2 )
++v2;
if ( !i )
break;
v4 = strlen2sep(v2, 47LL);
if ( v4 == -1 )
v4 = strlen(v2);
if ( !v4 )
break;
if ( root == v1 && !(unsigned __int8)strncmp(v2, "..", v4) )
{
v2 += v4;
}
else
{
v1 = (**(__int64 (__fastcall ***)(__int64, const char *, _QWORD))(v1 + 104))(v1, v2, (unsigned __int8)v4);
if ( !v1 )
return v1;
v2 += v4;
}
}
}
return v1;
}

original_code:
struct inode *namei(const char *path)
{
 s16 len;
 struct inode *inode;
 if (path == ((void *)0) || *path != '/')
  return ((void *)0);
 inode = root;
 path++;
 while (path) {
  while (*path == '/')
   path++;
  if (*path == '\0')
   return inode;
  len = strlen2sep(path, '/');
  if (len == -1)
   len = strlen(path);
  if (len == 0)
   return inode;
  if (inode == root && strncmp(path, "..", len) == 0) {
   path += len;
   continue;
  }
  inode = inode->ops->lookup(inode, path, len);
  if (inode == ((void *)0))
   return ((void *)0);
  path += len;
 }
 return inode;
}

canonical_original_code:
struct inode *namei(char *path)
{
 short len;
 struct inode *inode;
 if (path == ((void *)0) || *path != '/')
  return ((void *)0);
 inode = root;
 path++;
 while (path) {
  while (*path == '/')
   path++;
  if (*path == '\0')
   return inode;
  len = strlen2sep(path, '/');
  if (len == -1)
   len = strlen(path);
  if (len == 0)
   return inode;
  if (inode == root && strncmp(path, "..", len) == 0) {
   path += len;
   continue;
  }
  inode = inode->ops->lookup(inode, path, len);
  if (inode == ((void *)0))
   return ((void *)0);
  path += len;
 }
 return inode;
}

variable_types:
path
char *

variable_types: len short

variable_types: struct inode { struct super { struct dev_t { unsigned int major; unsigned int minor; } dev; unsigned long blocksize; unsigned long blocksizephys; struct list_head { struct list_head *prev; } bcache; struct list_head icache; struct super_ops { struct super *(*super_read)(struct dev_t *dev); struct inode *(*inode_read)(struct super *sb, unsigned long inum); } *ops; unsigned long magic; unsigned long time; struct inode *mounted; unsigned int flags; void *priv; } *sb; unsigned long num; unsigned short mode; unsigned char nlinks; unsigned int uid; unsigned int gid; unsigned long filesize; unsigned long nblocks; unsigned long atime; unsigned long mtime; unsigned long ctime; unsigned int flags; unsigned int count; struct list_head l; struct super *covered; struct inode_ops { struct inode *(*lookup)(struct inode *, char *, unsigned char); unsigned long (*bmap)(struct inode *, long); struct bhead { struct list_head l; unsigned long bnum; void *data; unsigned char count; } *(*block_read)(struct inode *, long); } *ops; void *priv; } *


mktime

variable_types: struct tm { short tm_sec; short tm_min; short tm_hour; short tm_mday; short tm_mon; short tm_year; short tm_wday; short tm_yday; short tm_isdst; } *


decompiled_code:
__int64 __fastcall msr_write(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a2;
__writemsr(a1, a2);
return result;
}

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

result = a2;
__writemsr(a1, a2);
return result;
}

original_code:
static inline void msr_write(u32 msr, u64 data)
{
 asm volatile(
  "wrmsr"
  :
  : "c" (msr), "a"(data & 0xffffffff), "d" (data >> 32)
  : "memory");
}

canonical_original_code:
static inline void msr_write(unsigned int msr, unsigned long data)
{
 asm volatile(
  "wrmsr"
  :
  : "c" (msr), "a"(data & 0xffffffff), "d" (data >> 32)
  : "memory");
}

variable_types:
msr
unsigned int

variable_types:
data
unsigned long


exec

decompiled_code:
__int64 exec()
{
if ( elf_map() != -1 )
{
msr_write(0xC0000081, 0);
msr_write(0xC0000082, syscall_dispatch);
__asm { sysret }
JUMPOUT(0x61LL);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
if ( elf_map() != -1 )
{
func0(0xC0000081, 0);
func0(0xC0000082, syscall_dispatch);
__asm { sysret }
JUMPOUT(0x61LL);
}
return 0xFFFFFFFFLL;
}

original_code:
s32 exec(const char *path)
{
 s64 entry;
 entry = elf_map(path);
 if (entry == -1)
  return -1;
 do { msr_write(0xc0000081, ((u64)0x30)<<48 | ((u64)0x20)<<32 ); msr_write(0xc0000082, (u64)syscall_dispatch); asm volatile("mov %0, %%rcx\n\t" "sysretq\n\t" : : "m"(entry)); } while (0);
 return 0;
}

canonical_original_code:
int exec(char *path)
{
 long entry;
 entry = elf_map(path);
 if (entry == -1)
  return -1;
 do { msr_write(0xc0000081, ((unsigned long)0x30)<<48 | ((unsigned long)0x20)<<32 ); msr_write(0xc0000082, (unsigned long)syscall_dispatch); asm volatile("mov %0, %%rcx\n\t" "sysretq\n\t" : : "m"(entry)); } while (0);
 return 0;
}

variable_types: entry long


printQueue

decompiled_code:
int __fastcall printQueue(unsigned int **a1)
{
unsigned int *i; // rbx
int result; // eax

for ( i = *a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
result = printf("%d %p\n", *i, *((const void **)i + 1));
return result;
}

canonical_decompiled_code:
int __fastcall func0(unsigned int **a1)
{
unsigned int *i; // rbx
int result; // eax

for ( i = *a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
result = printf("%d %p\n", *i, *((const void **)i + 1));
return result;
}

original_code:
void printQueue(que * q)
{
node * print = q->front;
while (print != ((void *)0))
    {
    printf ("%d %p\n", print->member, print->next);
    print = print -> next;
    }
}

canonical_original_code:
void printQueue(struct queue *q)
{
struct nod *print = q->front;
while (print != ((void *)0))
    {
    printf ("%d %p\n", print->member, print->next);
    print = print -> next;
    }
}

variable_types: struct queue { struct nod { int member; struct nod *next; } *front; struct nod *rear; } *

user_defined_types: struct queue { struct nod *front; struct nod *rear; }


peek

decompiled_code:
int __fastcall peek(unsigned int **a1)
{
int result; // eax

if ( a1 )
result = printf("peek %d \n", **a1);
else
result = puts("empty Q");
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int **a1)
{
int result; // eax

if ( a1 )
result = printf("peek %d \n", **a1);
else
result = puts("empty Q");
return result;
}

original_code:
void peek(que * q)
{
if (q == ((void *)0))
    {
    printf ("empty Q\n");
    return;
    }
printf ("peek %d \n", q->front->member);
}

canonical_original_code:
void peek(struct queue *q)
{
if (q == ((void *)0))
    {
    printf ("empty Q\n");
    return;
    }
printf ("peek %d \n", q->front->member);
}

user_defined_types: struct nod { int member; struct nod *next; }


delQueue

decompiled_code:
void __fastcall delQueue(_QWORD ***a1)
{
_QWORD *v2; // rax
_QWORD *i; // rdi
_QWORD *v4; // rbp

v2 = *a1;
for ( i = **a1; i; i = **a1 )
{
v4 = (_QWORD *)i[1];
free(i);
**a1 = v4;
v2 = *a1;
}
free(v2);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func2(_QWORD ***a1)
{
_QWORD *v2; // rax
_QWORD *i; // rdi
_QWORD *v4; // rbp

v2 = *a1;
for ( i = **a1; i; i = **a1 )
{
v4 = (_QWORD *)i[1];
free(i);
**a1 = v4;
v2 = *a1;
}
free(v2);
*a1 = 0LL;
}

original_code:
void delQueue(que ** q)
{
node * temp;
while ((*q)->front != ((void *)0))
    {
    temp = (*q)->front->next;
    free((*q)->front);
    (*q)->front = temp;
    }
free (*q);
*q=((void *)0);
}

canonical_original_code:
void delQueue(struct queue **q)
{
struct nod *temp;
while ((*q)->front != ((void *)0))
    {
    temp = (*q)->front->next;
    free((*q)->front);
    (*q)->front = temp;
    }
free (*q);
*q=((void *)0);
}

variable_types: struct queue { struct nod { int member; struct nod *next; } *front; struct nod *rear; } **


deQueue

decompiled_code:
__int64 __fastcall deQueue(void ***a1)
{
void **v1; // rax
_QWORD *v2; // rbp
unsigned int v3; // er12

v1 = *a1;
if ( *a1 )
{
v2 = (_QWORD *)*((_QWORD *)*v1 + 1);
v3 = *(_DWORD *)*v1;
if ( v2 )
{
free(*v1);
**a1 = v2;
}
else
{
delQueue((_QWORD ***)a1);
}
}
else
{
puts("empty q");
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(void ***a1)
{
void **v1; // rax
_QWORD *v2; // rbp
unsigned int v3; // er12

v1 = *a1;
if ( *a1 )
{
v2 = (_QWORD *)*((_QWORD *)*v1 + 1);
v3 = *(_DWORD *)*v1;
if ( v2 )
{
free(*v1);
**a1 = v2;
}
else
{
func2((_QWORD ***)a1);
}
}
else
{
puts("empty q");
v3 = -1;
}
return v3;
}

original_code:
int deQueue(que ** q)
{
node * temp;
int result;
if (*q == ((void *)0))
    {
    printf("empty q\n");
    return -1;
    }
temp = (*q)->front->next;
result = (*q)->front->member;
if(temp == ((void *)0))
    delQueue(q);
else
    {
    free((*q)->front);
    (*q)->front = temp;
    }
return result;
}

canonical_original_code:
int deQueue(struct queue **q)
{
struct nod *temp;
int result;
if (*q == ((void *)0))
    {
    printf("empty q\n");
    return -1;
    }
temp = (*q)->front->next;
result = (*q)->front->member;
if(temp == ((void *)0))
    delQueue(q);
else
    {
    free((*q)->front);
    (*q)->front = temp;
    }
return result;
}

variable_types: struct nod { int member; struct nod *next; } *

variable_types: result int


repo: acelster/scatter-pt-viz

decompiled_code:
__int64 __fastcall set_color(__int64 a1, float *a2, float a3)
{
float v3; // xmm1_4
float v4; // xmm0_4
__int64 result; // rax

v3 = 1.0 / ((double)COLOR_BANDS - 1.0);
LODWORD(result) = (int)(float)(a3 / v3);
v4 = (float)(a3 - (float)((float)(int)result * v3)) / v3;
result = (int)result;
*a2 = (float)((float)(*(float *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 72LL) + 4LL * (int)result + 4)
- *(float *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 72LL) + 4LL * (int)result))
* v4)
+ *(float *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 72LL) + 4LL * (int)result);
a2[3] = (float)((float)(*(float *)(**(_QWORD **)(a1 + 16) + 4LL * (int)result + 4)
- *(float *)(**(_QWORD **)(a1 + 16) + 4LL * (int)result))
* v4)
+ *(float *)(**(_QWORD **)(a1 + 16) + 4LL * (int)result);
a2[2] = (float)((float)(*(float *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 24LL) + 4LL * (int)result + 4)
- *(float *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 24LL) + 4LL * (int)result))
* v4)
+ *(float *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 24LL) + 4LL * (int)result);
a2[1] = (float)(v4
* (float)(*(float *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 48LL) + 4LL * (int)result + 4)
- *(float *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 48LL) + 4LL * (int)result)))
+ *(float *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 48LL) + 4LL * (int)result);
return result;
}

original_code:
void set_color(Transfer_Overlay* t, float iso, Color* c){
  float step_size = 1.0/(COLOR_BANDS - 1.0);
  int low_index = (int)(iso/step_size);
  int high_index = low_index + 1;
  float p = (iso - low_index*step_size)/step_size;
  float low_val = (t->transfers[3].values[low_index]);
  float high_val = (t->transfers[3].values[high_index]);
  c->a = low_val + p*(high_val - low_val);
  low_val = (t->transfers[0].values[low_index]);
  high_val = (t->transfers[0].values[high_index]);
  c->r = low_val + p*(high_val - low_val);
  low_val = (t->transfers[1].values[low_index]);
  high_val = (t->transfers[1].values[high_index]);
  c->g = low_val + p*(high_val - low_val);
  low_val = (t->transfers[2].values[low_index]);
  high_val = (t->transfers[2].values[high_index]);
  c->b = low_val + p*(high_val - low_val);
}

canonical_original_code:
void set_color(struct Transfer_Overlay *t, float iso, struct Color *c){
  float step_size = 1.0/(COLOR_BANDS - 1.0);
  int low_index = (int)(iso/step_size);
  int high_index = low_index + 1;
  float p = (iso - low_index*step_size)/step_size;
  float low_val = (t->transfers[3].values[low_index]);
  float high_val = (t->transfers[3].values[high_index]);
  c->a = low_val + p*(high_val - low_val);
  low_val = (t->transfers[0].values[low_index]);
  high_val = (t->transfers[0].values[high_index]);
  c->r = low_val + p*(high_val - low_val);
  low_val = (t->transfers[1].values[low_index]);
  high_val = (t->transfers[1].values[high_index]);
  c->g = low_val + p*(high_val - low_val);
  low_val = (t->transfers[2].values[low_index]);
  high_val = (t->transfers[2].values[high_index]);
  c->b = low_val + p*(high_val - low_val);
}

variable_types: struct Transfer_Overlay { struct Color { float a; float b; float g; float r; } *color_table; int color_table_size; struct Transfer { float *values; struct Quad { float x; float y; float w; float h; struct Color c; } *quads; int drag_started; int index_of_draged; } *transfers; struct Quad *quads; int color_selected; int visible; float max_intensity; } *

variable_types: iso float

variable_types:
c
struct Color *

variable_types: p float

user_defined_types: struct Transfer_Overlay { struct Color *color_table; int color_table_size; struct Transfer *transfers; struct Quad *quads; int color_selected; int visible; float max_intensity; }

user_defined_types: struct Transfer { float *values; struct Quad *quads; int drag_started; int index_of_draged; }


decompiled_code:
const __m128i *__fastcall set_color_from_table(__int64 a1, __m128i *a2, float a3)
{
const __m128i *result; // rax

if ( a3 > 1.0 )
puts("Too big values...");
result = (const __m128i *)(*(_QWORD *)a1 + 16LL * (int)(float)((float)*(int *)(a1 + 8) * a3));
*a2 = _mm_loadu_si128(result);
return result;
}

canonical_decompiled_code:
const __m128i *__fastcall func1(__int64 a1, __m128i *a2, float a3)
{
const __m128i *result; // rax

if ( a3 > 1.0 )
puts("Too big values...");
result = (const __m128i *)(*(_QWORD *)a1 + 16LL * (int)(float)((float)*(int *)(a1 + 8) * a3));
*a2 = _mm_loadu_si128(result);
return result;
}

original_code:
void set_color_from_table(Transfer_Overlay* t, float iso, Color* c){
  if(iso > 1.0){
    printf("Too big values...\n");
  }
  int index = (int)(iso * t->color_table_size);
  *c = t->color_table[index];
}

canonical_original_code:
void set_color_from_table(struct Transfer_Overlay *t, float iso, struct Color *c){
  if(iso > 1.0){
    printf("Too big values...\n");
  }
  int index = (int)(iso * t->color_table_size);
  *c = t->color_table[index];
}

variable_types: index int

user_defined_types: struct Color { float a; float b; float g; float r; }

user_defined_types: struct Quad { float x; float y; float w; float h; struct Color c; }


decompiled_code:
__int64 __fastcall update_color_table(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
unsigned int v3; // er12
__m128i v4; // xmm2
float v5; // [rsp+4h] [rbp-1Ch]

result = *(unsigned int *)(a1 + 8);
v5 = 1.0 / (float)(int)result;
if ( (int)result > 0 )
{
v2 = 0LL;
v3 = LC3;
do
{
result = set_color(a1, (float *)(*(_QWORD *)a1 + 16 * v2), *(float *)&v3);
v4 = _mm_cvtsi32_si128(v3);
*(float *)v4.m128i_i32 = *(float *)v4.m128i_i32 + v5;
v3 = _mm_cvtsi128_si32(v4);
++v2;
}
while ( *(_DWORD *)(a1 + 8) > (int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
unsigned int v3; // er12
__m128i v4; // xmm2
float v5; // [rsp+4h] [rbp-1Ch]

result = *(unsigned int *)(a1 + 8);
v5 = 1.0 / (float)(int)result;
if ( (int)result > 0 )
{
v2 = 0LL;
v3 = LC3;
do
{
result = func0(a1, (float *)(*(_QWORD *)a1 + 16 * v2), *(float *)&v3);
v4 = _mm_cvtsi32_si128(v3);
*(float *)v4.m128i_i32 = *(float *)v4.m128i_i32 + v5;
v3 = _mm_cvtsi128_si32(v4);
++v2;
}
while ( *(_DWORD *)(a1 + 8) > (int)v2 );
}
return result;
}

original_code:
void update_color_table(Transfer_Overlay* t){
  float step = 1.0/(float)t->color_table_size;
  float iso = 0;
  for(int c = 0; c < t->color_table_size; c++){
    set_color(t, iso, &t->color_table[c]);
    iso += step;
  }
}

canonical_original_code:
void update_color_table(struct Transfer_Overlay *t){
  float step = 1.0/(float)t->color_table_size;
  float iso = 0;
  for(int c = 0; c < t->color_table_size; c++){
    set_color(t, iso, &t->color_table[c]);
    iso += step;
  }
}

variable_types: step float

variable_types: c int


decompiled_code:
double __fastcall get_default_color_value(int a1, int a2)
{
double result; // xmm0_8
double v3; // xmm1_8
double v4; // xmm1_8
double v5; // xmm1_8

HIDWORD(result) = 0;
*(float *)&result = (float)a2 / (float)COLOR_BANDS;
if ( a1 == 2 )
{
v4 = *(float *)&result;
*(_QWORD *)&result = (unsigned int)LC1;
if ( v4 >= 0.3 )
{
result = 0.0;
if ( v4 <= 0.6 )
{
result = 1.0 - (v4 - 0.3) / 0.3;
*(float *)&result = result;
}
}
}
else if ( a1 > 2 )
{
if ( a1 == 3 )
{
if ( *(float *)&result < 0.3 )
{
result = 0.0;
}
else if ( *(float *)&result <= 1.0 )
{
v5 = (*(float *)&result - 0.3) * 0.5;
if ( v5 > 1.0 )
v5 = *(double *)&LC0;
HIDWORD(result) = 0;
*(float *)&result = v5;
}
else
{
*(_QWORD *)&result = (unsigned int)LC1;
}
}
}
else if ( a1 )
{
if ( a1 == 1 )
{
v3 = *(float *)&result;
result = 0.0;
if ( v3 >= 0.3 )
{
*(_QWORD *)&result = (unsigned int)LC1;
if ( v3 <= 0.6 )
{
HIDWORD(result) = 0;
*(float *)&result = (v3 - 0.3) / 0.3;
}
}
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func5(int a1, int a2)
{
double result; // xmm0_8
double v3; // xmm1_8
double v4; // xmm1_8
double v5; // xmm1_8

HIDWORD(result) = 0;
*(float *)&result = (float)a2 / (float)COLOR_BANDS;
if ( a1 == 2 )
{
v4 = *(float *)&result;
*(_QWORD *)&result = (unsigned int)LC1;
if ( v4 >= 0.3 )
{
result = 0.0;
if ( v4 <= 0.6 )
{
result = 1.0 - (v4 - 0.3) / 0.3;
*(float *)&result = result;
}
}
}
else if ( a1 > 2 )
{
if ( a1 == 3 )
{
if ( *(float *)&result < 0.3 )
{
result = 0.0;
}
else if ( *(float *)&result <= 1.0 )
{
v5 = (*(float *)&result - 0.3) * 0.5;
if ( v5 > 1.0 )
v5 = *(double *)&LC0;
HIDWORD(result) = 0;
*(float *)&result = v5;
}
else
{
*(_QWORD *)&result = (unsigned int)LC1;
}
}
}
else if ( a1 )
{
if ( a1 == 1 )
{
v3 = *(float *)&result;
result = 0.0;
if ( v3 >= 0.3 )
{
*(_QWORD *)&result = (unsigned int)LC1;
if ( v3 <= 0.6 )
{
HIDWORD(result) = 0;
*(float *)&result = (v3 - 0.3) / 0.3;
}
}
}
}
return result;
}

original_code:
float get_default_color_value(int channel, int c){
  float p = (float)c/COLOR_BANDS;
  switch(channel){
    case 0:
      return p;
    case 1:
      if(p < 0.3)
        return 0;
      else if(p > 0.6)
        return 1;
      else
        return (p - 0.3)/0.3;
    case 2:
      if(p < 0.3)
        return 1;
      else if(p > 0.6)
        return 0;
      else
        return 1 - (p - 0.3)/0.3;
    case 3:
      if(p < 0.3)
        return 0;
      else if(p > 1)
        return 1;
      else{
        double d = (p - 0.3)/2.0;
        if(d > 1)
          d = 1;
        return d;
      }
  }
}

variable_types: channel int

variable_types: d double

return_type: float


decompiled_code:
void __fastcall init_transfer(__int64 a1, int a2)
{
__int64 v2; // rbx
_DWORD *v3; // rbp
double v4; // xmm0_8

*(_QWORD *)a1 = malloc(4LL * COLOR_BANDS);
*(_QWORD *)(a1 + 8) = malloc(32LL * COLOR_BANDS);
if ( COLOR_BANDS > 0 )
{
v2 = 0LL;
do
{
v3 = (_DWORD *)(*(_QWORD *)a1 + 4 * v2);
v4 = get_default_color_value(a2, v2);
*v3 = LODWORD(v4);
++v2;
}
while ( COLOR_BANDS > (int)v2 );
}
*(_DWORD *)(a1 + 16) = 0;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2)
{
__int64 v2; // rbx
_DWORD *v3; // rbp
double v4; // xmm0_8

*(_QWORD *)a1 = malloc(4LL * COLOR_BANDS);
*(_QWORD *)(a1 + 8) = malloc(32LL * COLOR_BANDS);
if ( COLOR_BANDS > 0 )
{
v2 = 0LL;
do
{
v3 = (_DWORD *)(*(_QWORD *)a1 + 4 * v2);
v4 = func5(a2, v2);
*v3 = LODWORD(v4);
++v2;
}
while ( COLOR_BANDS > (int)v2 );
}
*(_DWORD *)(a1 + 16) = 0;
}

original_code:
void init_transfer(Transfer* t, int channel){
  t->values = (float*)malloc(sizeof(float) * COLOR_BANDS);
  t->quads = (Quad*)malloc(sizeof(Quad) * COLOR_BANDS);
  for(int c = 0; c < COLOR_BANDS; c++){
    t->values[c] = get_default_color_value(channel, c);
  }
  t->drag_started = 0;
}

canonical_original_code:
void init_transfer(struct Transfer *t, int channel){
  t->values = (float *)malloc(sizeof(float) * COLOR_BANDS);
  t->quads = (struct Quad *)malloc(sizeof(Quad) * COLOR_BANDS);
  for(int c = 0; c < COLOR_BANDS; c++){
    t->values[c] = get_default_color_value(channel, c);
  }
  t->drag_started = 0;
}

variable_types: struct Transfer { float *values; struct Quad { float x; float y; float w; float h; struct Color { float a; float b; float g; float r; } c; } *quads; int drag_started; int index_of_draged; } *


original_code:
Transfer_Overlay* init_transfer_overlay(Ranges* r){
  Transfer_Overlay* t = (Transfer_Overlay*)malloc(sizeof(Transfer_Overlay));
  t->color_selected = 0;
  t->visible = 0;
  t->max_intensity = log(r->imax);
  MAX_INTENSITY = t->max_intensity;
  printf("Max intensity: %f\n", t->max_intensity);
  t->transfers = (Transfer*)malloc(sizeof(Transfer)*4);
  init_transfer(&t->transfers[0], 0);
  init_transfer(&t->transfers[1], 1);
  init_transfer(&t->transfers[2], 2);
  init_transfer(&t->transfers[3], 3);
  t->quads = (Quad*)malloc(sizeof(Quad)*6);
  Quad* quads = t->quads;
  Color c = {1.0,1.0,1.0,1.0};
  quads[0].x = 0; quads[0].y = 0; quads[0].w = 1; quads[0].h = 0.4;
  c.a = 0.5;
  quads[0].c = c;
  quads[1].x = 0.05; quads[1].y = 0.01; quads[1].w = 0.08; quads[1].h = 0.08;
  c.a = 1.0; c.g = 0; c.b = 0;
  quads[1].c = c;
  quads[2].x = 0.05; quads[2].y = 0.11; quads[2].w = 0.08; quads[2].h = 0.08;
  c.g = 1.0; c.r = 0;
  quads[2].c = c;
  quads[3].x = 0.05; quads[3].y = 0.21; quads[3].w = 0.08; quads[3].h = 0.08;
  c.g = 0; c.b = 1.0;
  quads[3].c = c;
  quads[4].x = 0.05; quads[4].y = 0.31; quads[4].w = 0.08; quads[4].h = 0.08;
  c.r = 0.6; c.g = 0.6; c.b = 0.6;
  quads[4].c = c;
  quads[5].x = 0.2; quads[5].y = 0.05; quads[5].w = 0.77; quads[5].h = 0.32;
  c.r = 1.0; c.g = 1.0; c.b = 1.0;
  quads[5].c = c;
  read_colors(t);
  t->color_table_size = 10000;
  t->color_table = (Color*)malloc(sizeof(Color)* t->color_table_size);
  update_color_table(t);
  return t;
}

canonical_original_code:
struct Transfer_Overlay *init_transfer_overlay(struct Ranges *r){
  struct Transfer_Overlay *t = (Transfer_Overlay*)malloc(sizeof(Transfer_Overlay));
  t->color_selected = 0;
  t->visible = 0;
  t->max_intensity = log(r->imax);
  MAX_INTENSITY = t->max_intensity;
  printf("Max intensity: %f\n", t->max_intensity);
  t->transfers = (struct Transfer *)malloc(sizeof(Transfer)*4);
  init_transfer(&t->transfers[0], 0);
  init_transfer(&t->transfers[1], 1);
  init_transfer(&t->transfers[2], 2);
  init_transfer(&t->transfers[3], 3);
  t->quads = (struct Quad *)malloc(sizeof(Quad)*6);
  struct Quad *quads = t->quads;
  struct Color c = {1.0,1.0,1.0,1.0};
  quads[0].x = 0; quads[0].y = 0; quads[0].w = 1; quads[0].h = 0.4;
  c.a = 0.5;
  quads[0].c = c;
  quads[1].x = 0.05; quads[1].y = 0.01; quads[1].w = 0.08; quads[1].h = 0.08;
  c.a = 1.0; c.g = 0; c.b = 0;
  quads[1].c = c;
  quads[2].x = 0.05; quads[2].y = 0.11; quads[2].w = 0.08; quads[2].h = 0.08;
  c.g = 1.0; c.r = 0;
  quads[2].c = c;
  quads[3].x = 0.05; quads[3].y = 0.21; quads[3].w = 0.08; quads[3].h = 0.08;
  c.g = 0; c.b = 1.0;
  quads[3].c = c;
  quads[4].x = 0.05; quads[4].y = 0.31; quads[4].w = 0.08; quads[4].h = 0.08;
  c.r = 0.6; c.g = 0.6; c.b = 0.6;
  quads[4].c = c;
  quads[5].x = 0.2; quads[5].y = 0.05; quads[5].w = 0.77; quads[5].h = 0.32;
  c.r = 1.0; c.g = 1.0; c.b = 1.0;
  quads[5].c = c;
  read_colors(t);
  t->color_table_size = 10000;
  t->color_table = (struct Color *)malloc(sizeof(Color)* t->color_table_size);
  update_color_table(t);
  return t;
}

variable_types: struct Ranges { float xmin; float xmax; float ymin; float ymax; float zmin; float zmax; float imin; float imax; } *

variable_types: struct Quad { float x; float y; float w; float h; struct Color { float a; float b; float g; float r; } c; } *

return_type: struct Transfer_Overlay { struct Color { float a; float b; float g; float r; } *color_table; int color_table_size; struct Transfer { float *values; struct Quad { float x; float y; float w; float h; struct Color c; } *quads; int drag_started; int index_of_draged; } *transfers; struct Quad *quads; int color_selected; int visible; float max_intensity; } *


original_code:
void render_transfer(Transfer* t, int color_index, float x, float y, float w, float h){
  Color color = {1.0,0.0,0.0,0.0};
  if(color_index == 0){
    color.r = 1.0;
  }
  if(color_index == 1){
    color.g = 1.0;
  }
  if(color_index == 2){
    color.b = 1.0;
  }
  if(color_index == 3){
    color.r = 0.5; color.g = 0.5; color.b = 0.5;
  }
  for(int c = 0; c < COLOR_BANDS; c++){
    glLineWidth(2);
    glEnable(0x0B20);
    if(c < COLOR_BANDS -1){
      float x1 = x + ((float)c/(COLOR_BANDS-1.0))*w + 0.01;
      float y1 = y + t->values[c]*h + 0.01;
      float x2 = x + ((float)(c+1)/(COLOR_BANDS-1.0))*w + 0.01;
      float y2 = y + t->values[(c+1)]*h + 0.01;
      glColor4f(color.r,color.g,color.b,color.a);
      glBegin(0x0001);
      glVertex3f(x1, y1, 0);
      glVertex3f(x2,y2, 0);
      glEnd();
    }
    glLineWidth(1);
    glDisable(0x0B20);
    t->quads[c].y = y + t->values[c]*h;
    t->quads[c].x = x + ((float)c/(COLOR_BANDS-1.0))*w;
    t->quads[c].w = 0.02;
    t->quads[c].h = 0.02;
    t->quads[c].c = color;
    render(&t->quads[c]);
  }
}

canonical_original_code:
void render_transfer(struct Transfer *t, int color_index, float x, float y, float w, float h){
  struct Color color = {1.0,0.0,0.0,0.0};
  if(color_index == 0){
    color.r = 1.0;
  }
  if(color_index == 1){
    color.g = 1.0;
  }
  if(color_index == 2){
    color.b = 1.0;
  }
  if(color_index == 3){
    color.r = 0.5; color.g = 0.5; color.b = 0.5;
  }
  for(int c = 0; c < COLOR_BANDS; c++){
    glLineWidth(2);
    glEnable(0x0B20);
    if(c < COLOR_BANDS -1){
      float x1 = x + ((float)c/(COLOR_BANDS-1.0))*w + 0.01;
      float y1 = y + t->values[c]*h + 0.01;
      float x2 = x + ((float)(c+1)/(COLOR_BANDS-1.0))*w + 0.01;
      float y2 = y + t->values[(c+1)]*h + 0.01;
      glColor4f(color.r,color.g,color.b,color.a);
      glBegin(0x0001);
      glVertex3f(x1, y1, 0);
      glVertex3f(x2,y2, 0);
      glEnd();
    }
    glLineWidth(1);
    glDisable(0x0B20);
    t->quads[c].y = y + t->values[c]*h;
    t->quads[c].x = x + ((float)c/(COLOR_BANDS-1.0))*w;
    t->quads[c].w = 0.02;
    t->quads[c].h = 0.02;
    t->quads[c].c = color;
    render(&t->quads[c]);
  }
}

variable_types: x float

variable_types: y float

variable_types: w float

variable_types: h float

variable_types: struct Color { float a; float b; float g; float r; }


original_code:
void render_transfer_overlay(Transfer_Overlay* transfer_overlay){
  if(!transfer_overlay->visible){
    return;
  }
  for(int c = 0; c < 6; c++){
    render(&transfer_overlay->quads[c]);
  }
  int cs = transfer_overlay->color_selected;
  render_transfer(&transfer_overlay->transfers[cs], cs, 0.2, 0.05, 0.75, 0.3);
}

canonical_original_code:
void render_transfer_overlay(struct Transfer_Overlay *transfer_overlay){
  if(!transfer_overlay->visible){
    return;
  }
  for(int c = 0; c < 6; c++){
    render(&transfer_overlay->quads[c]);
  }
  int cs = transfer_overlay->color_selected;
  render_transfer(&transfer_overlay->transfers[cs], cs, 0.2, 0.05, 0.75, 0.3);
}

variable_types: struct Transfer_Overlay { struct Color { float a; float b; float g; float r; } *color_table; int color_table_size; struct Transfer { float *values; struct Quad { float x; float y; float w; float h; struct Color c; } *quads; int drag_started; int index_of_draged; } *transfers; struct Quad *quads; int color_selected; int visible; float max_intensity; } *

variable_types: cs int


decompiled_code:
void __fastcall start_drag(__int64 a1, float a2, float a3)
{
__int64 v3; // rbx

if ( COLOR_BANDS > 0 )
{
v3 = 0LL;
do
{
if ( (unsigned int)inside_quad(*(_QWORD *)(a1 + 8) + 32 * v3, a2, a3) )
{
*(_DWORD *)(a1 + 16) = 1;
*(_DWORD *)(a1 + 20) = v3;
}
++v3;
}
while ( COLOR_BANDS > (int)v3 );
}
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, float a2, float a3)
{
__int64 v3; // rbx

if ( COLOR_BANDS > 0 )
{
v3 = 0LL;
do
{
if ( (unsigned int)inside_quad(*(_QWORD *)(a1 + 8) + 32 * v3, a2, a3) )
{
*(_DWORD *)(a1 + 16) = 1;
*(_DWORD *)(a1 + 20) = v3;
}
++v3;
}
while ( COLOR_BANDS > (int)v3 );
}
}

original_code:
void start_drag(Transfer* transfer, float x, float y){
  for(int c = 0; c < COLOR_BANDS; c++){
    if(inside_quad(&transfer->quads[c], x, y)){
      transfer->drag_started = 1;
      transfer->index_of_draged = c;
    }
  }
}

canonical_original_code:
void start_drag(struct Transfer *transfer, float x, float y){
  for(int c = 0; c < COLOR_BANDS; c++){
    if(inside_quad(&transfer->quads[c], x, y)){
      transfer->drag_started = 1;
      transfer->index_of_draged = c;
    }
  }
}


decompiled_code:
__int64 __fastcall stop_drag(__int64 *a1, double a2, float a3)
{
__int64 result; // rax
float v4; // xmm1_4

if ( *((_DWORD *)a1 + 4) )
{
result = *a1;
v4 = (a3 - 0.05) / 0.3;
*(float *)(*a1 + 4LL * *((int *)a1 + 5)) = v4;
}
*((_DWORD *)a1 + 4) = 0;
return result;
}

original_code:
void stop_drag(Transfer* transfer, float x, float y){
  if(transfer->drag_started){
    transfer->values[transfer->index_of_draged] = (y-0.05)/0.3;
  }
  transfer->drag_started = 0;
}

canonical_original_code:
void stop_drag(struct Transfer *transfer, float x, float y){
  if(transfer->drag_started){
    transfer->values[transfer->index_of_draged] = (y-0.05)/0.3;
  }
  transfer->drag_started = 0;
}


decompiled_code:
void __fastcall handle_mouse(__int64 a1, int a2, float a3, float a4)
{
__int64 v4; // rbp

if ( *(_DWORD *)(a1 + 36) )
{
if ( a2 )
{
stop_drag(
(__int64 *)(*(_QWORD *)(a1 + 16) + 24LL * *(int *)(a1 + 32)),
COERCE_DOUBLE((unsigned __int64)LODWORD(a3)),
a4);
update_color_table(a1);
}
else
{
v4 = 0LL;
while ( !(unsigned int)inside_quad(*(_QWORD *)(a1 + 24) + 32 * (v4 + 1), a3, a4) )
{
if ( ++v4 == 4 )
{
start_drag(*(_QWORD *)(a1 + 16) + 24LL * *(int *)(a1 + 32), a3, a4);
return;
}
}
*(_DWORD *)(a1 + 32) = v4;
}
}
}

original_code:
void handle_mouse(Transfer_Overlay* t, float x, float y, int state){
  if(!t->visible){
    return;
  }
  if(state == 0x0000){
    for(int c = 1; c < 5; c++){
      if(inside_quad(&t->quads[c], x, y)){
        t->color_selected = c -1;
        return;
      }
    }
  }
  if(state == 0x0000){
    start_drag(&t->transfers[t->color_selected],x,y);
  }
  else{
    stop_drag(&t->transfers[t->color_selected],x,y);
    update_color_table(t);
  }
}

canonical_original_code:
void handle_mouse(struct Transfer_Overlay *t, float x, float y, int state){
  if(!t->visible){
    return;
  }
  if(state == 0x0000){
    for(int c = 1; c < 5; c++){
      if(inside_quad(&t->quads[c], x, y)){
        t->color_selected = c -1;
        return;
      }
    }
  }
  if(state == 0x0000){
    start_drag(&t->transfers[t->color_selected],x,y);
  }
  else{
    stop_drag(&t->transfers[t->color_selected],x,y);
    update_color_table(t);
  }
}

variable_types: state int


original_code:
void normalize_Coord(Coord* c){
  float length = sqrt(c->x*c->x + c->y*c->y + c->z*c->z);
  c->x /= length;
  c->y /= length;
  c->z /= length;
}

canonical_original_code:
void normalize_Coord(struct Coord *c){
  float length = sqrt(c->x*c->x + c->y*c->y + c->z*c->z);
  c->x /= length;
  c->y /= length;
  c->z /= length;
}

variable_types: struct Coord { float x; float y; float z; } *

variable_types: length float


decompiled_code:
__m128i __fastcall sub_Coord(double a1, double a2, double a3)
{
__m128i v4; // [rsp+24h] [rbp-14h] BYREF

*(float *)v4.m128i_i32 = *(float *)&a1 - *(float *)&a3;
*(float *)&v4.m128i_i32[1] = *((float *)&a1 + 1) - *((float *)&a3 + 1);
return _mm_loadl_epi64(&v4);
}

original_code:
Coord sub_Coord(Coord a, Coord b){
  Coord c;
  c.x = a.x - b.x;
  c.y = a.y - b.y;
  c.z = a.z - b.z;
  return c;
}

canonical_original_code:
struct Coord sub_Coord(struct Coord a, struct Coord b){
  struct Coord c;
  c.x = a.x - b.x;
  c.y = a.y - b.y;
  c.z = a.z - b.z;
  return c;
}

variable_types:
a
struct Coord

variable_types:
b
struct Coord

variable_types: struct Coord { float x; float y; float z; }


decompiled_code:
__m128i __fastcall div_Coord(double a1, double a2, double a3, double a4, float a5)
{
float v5; // xmm5_4
float v6; // xmm2_4
__m128i v8; // [rsp+24h] [rbp-14h] BYREF

if ( *(float *)&a3 == 0.0 )
v5 = a5 / *(float *)&a3;
else
v5 = *(float *)&a1 / *(float *)&a3;
if ( *((float *)&a3 + 1) == 0.0 )
v6 = a5 / *((float *)&a3 + 1);
else
v6 = *((float *)&a1 + 1) / *((float *)&a3 + 1);
v8.m128i_i64[0] = __PAIR64__(LODWORD(v6), LODWORD(v5));
return _mm_loadl_epi64(&v8);
}

canonical_decompiled_code:
__m128i __fastcall func2(double a1, double a2, double a3, double a4, float a5)
{
float v5; // xmm5_4
float v6; // xmm2_4
__m128i v8; // [rsp+24h] [rbp-14h] BYREF

if ( *(float *)&a3 == 0.0 )
v5 = a5 / *(float *)&a3;
else
v5 = *(float *)&a1 / *(float *)&a3;
if ( *((float *)&a3 + 1) == 0.0 )
v6 = a5 / *((float *)&a3 + 1);
else
v6 = *((float *)&a1 + 1) / *((float *)&a3 + 1);
v8.m128i_i64[0] = __PAIR64__(LODWORD(v6), LODWORD(v5));
return _mm_loadl_epi64(&v8);
}

original_code:
Coord div_Coord(Coord a, Coord b, float safe){
  Coord c;
  c.x = (b.x == 0) ? safe/b.x :a.x/b.x;
  c.y = (b.y == 0) ? safe/b.y :a.y/b.y;
  c.z = (b.z == 0) ? safe/b.z :a.z/b.z;
  return c;
}

canonical_original_code:
struct Coord div_Coord(struct Coord a, struct Coord b, float safe){
  struct Coord c;
  c.x = (b.x == 0) ? safe/b.x :a.x/b.x;
  c.y = (b.y == 0) ? safe/b.y :a.y/b.y;
  c.z = (b.z == 0) ? safe/b.z :a.z/b.z;
  return c;
}

variable_types: safe float

return_type: struct Coord { float x; float y; float z; }


original_code:
Coord min_Coord(Coord a, Coord b){
  Coord c;
  c.x = fmin(a.x, b.x);
  c.y = fmin(a.y, b.y);
  c.z = fmin(a.z, b.z);
  return c;
}

canonical_original_code:
struct Coord min_Coord(struct Coord a, struct Coord b){
  struct Coord c;
  c.x = fmin(a.x, b.x);
  c.y = fmin(a.y, b.y);
  c.z = fmin(a.z, b.z);
  return c;
}

user_defined_types: struct Coord { float x; float y; float z; }


original_code:
Coord max_Coord(Coord a, Coord b){
  Coord c;
  c.x = fmax(a.x, b.x);
  c.y = fmax(a.y, b.y);
  c.z = fmax(a.z, b.z);
  return c;
}

canonical_original_code:
struct Coord max_Coord(struct Coord a, struct Coord b){
  struct Coord c;
  c.x = fmax(a.x, b.x);
  c.y = fmax(a.y, b.y);
  c.z = fmax(a.z, b.z);
  return c;
}


decompiled_code:
__m128i __fastcall add_scaled_Coord(double a1, double a2, double a3, double a4, float a5)
{
__m128i v6; // [rsp+24h] [rbp-14h] BYREF

*(float *)v6.m128i_i32 = (float)(a5 * *(float *)&a3) + *(float *)&a1;
*(float *)&v6.m128i_i32[1] = (float)(a5 * *((float *)&a3 + 1)) + *((float *)&a1 + 1);
return _mm_loadl_epi64(&v6);
}

canonical_decompiled_code:
__m128i __fastcall func5(double a1, double a2, double a3, double a4, float a5)
{
__m128i v6; // [rsp+24h] [rbp-14h] BYREF

*(float *)v6.m128i_i32 = (float)(a5 * *(float *)&a3) + *(float *)&a1;
*(float *)&v6.m128i_i32[1] = (float)(a5 * *((float *)&a3 + 1)) + *((float *)&a1 + 1);
return _mm_loadl_epi64(&v6);
}

original_code:
Coord add_scaled_Coord(Coord a, Coord b, float c){
  Coord d;
  d.x = a.x + b.x*c;
  d.y = a.y + b.y*c;
  d.z = a.z + b.z*c;
  return d;
}

canonical_original_code:
struct Coord add_scaled_Coord(struct Coord a, struct Coord b, float c){
  struct Coord d;
  d.x = a.x + b.x*c;
  d.y = a.y + b.y*c;
  d.z = a.z + b.z*c;
  return d;
}

variable_types: c float