showerr

repo: tlvb/blitemoth

decompiled_code:
int __fastcall showerr(const char *a1, int a2)
{
int v2; // ebx

fprintf(stderr, "parser error :: \"%s\"\n", a1);
fwrite("parser error :: ", 1uLL, 0x11uLL, stderr);
if ( a2 > 0 )
{
v2 = a2 - 1;
do
fputc(46, stderr);
while ( v2-- != 0 );
}
return fprintf(stderr, "\x1B[1;31m^\x1B[0mHERE (character %d)\n", (unsigned int)a2);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, int a2)
{
int v2; // ebx

fprintf(stderr, "parser error :: \"%s\"\n", a1);
fwrite("parser error :: ", 1uLL, 0x11uLL, stderr);
if ( a2 > 0 )
{
v2 = a2 - 1;
do
fputc(46, stderr);
while ( v2-- != 0 );
}
return fprintf(stderr, "\x1B[1;31m^\x1B[0mHERE (character %d)\n", (unsigned int)a2);
}

original_code:
void showerr(char *text, unsigned int accum) {
 fprintf(stderr, "parser error :: " "\"%s\"\n", text);
 fprintf(stderr, "parser error :: " " ");
 int a = accum;
 while (a-- > 0)
  fputc('.', stderr);
 fprintf(stderr,"\x1b[1;31m^\x1b[0mHERE (character %d)\n", accum);
}

variable_types:
text
char *

variable_types:
accum
unsigned int

variable_types: a int


decompiled_code:
__int64 __fastcall match_word(const char *a1, const char *a2, int *a3)
{
const char *v3; // r12
int *v4; // rbx
size_t v5; // rax
size_t v6; // rbx
int i; // ebp
unsigned int v8; // er15
char *v9; // r14
int v10; // ebp
size_t v11; // rdx
size_t v13; // rax
size_t v14; // rdx
int v16; // [rsp+1Ch] [rbp-5Ch] BYREF
char s[88]; // [rsp+20h] [rbp-58h] BYREF

v3 = a2;
v4 = a3;
v5 = strlen(a1);
v6 = (unsigned int)*v4;
if ( v5 > v6 )
{
v16 = 0;
for ( i = 1; ; ++i )
{
v8 = i - 1;
v9 = strchr(v3, 44);
if ( !v9 )
break;
if ( (unsigned int)_isoc99_sscanf(&a1[v6], "%31s%n", s, &v16) )
{
v13 = strlen(s);
v14 = (unsigned int)((_DWORD)v9 - (_DWORD)v3);
if ( v14 == v13 && !strncmp(s, v3, v14) )
goto LABEL_9;
}
v3 = v9 + 1;
v6 = (unsigned int)*a3;
}
v10 = strlen(v3);
if ( (unsigned int)_isoc99_sscanf(&a1[v6], "%31s%n", s, &v16) )
{
v11 = strlen(s);
if ( v11 == v10 && !strncmp(s, v3, v11) )
{
LABEL_9:
*a3 += v16;
return v8;
}
}
}
v8 = -1;
fprintf(stderr, "parser error :: Expected word from list [%s]\n", a2);
showerr(a1, *a3);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2, int *a3)
{
const char *v3; // r12
int *v4; // rbx
size_t v5; // rax
size_t v6; // rbx
int i; // ebp
unsigned int v8; // er15
char *v9; // r14
int v10; // ebp
size_t v11; // rdx
size_t v13; // rax
size_t v14; // rdx
int v16; // [rsp+1Ch] [rbp-5Ch] BYREF
char s[88]; // [rsp+20h] [rbp-58h] BYREF

v3 = a2;
v4 = a3;
v5 = strlen(a1);
v6 = (unsigned int)*v4;
if ( v5 > v6 )
{
v16 = 0;
for ( i = 1; ; ++i )
{
v8 = i - 1;
v9 = strchr(v3, 44);
if ( !v9 )
break;
if ( (unsigned int)_isoc99_sscanf(&a1[v6], "%31s%n", s, &v16) )
{
v13 = strlen(s);
v14 = (unsigned int)((_DWORD)v9 - (_DWORD)v3);
if ( v14 == v13 && !strncmp(s, v3, v14) )
goto LABEL_9;
}
v3 = v9 + 1;
v6 = (unsigned int)*a3;
}
v10 = strlen(v3);
if ( (unsigned int)_isoc99_sscanf(&a1[v6], "%31s%n", s, &v16) )
{
v11 = strlen(s);
if ( v11 == v10 && !strncmp(s, v3, v11) )
{
LABEL_9:
*a3 += v16;
return v8;
}
}
}
v8 = -1;
fprintf(stderr, "parser error :: Expected word from list [%s]\n", a2);
func0(a1, *a3);
return v8;
}

original_code:
int match_word(char *text, char *words, unsigned int *accum) {
 if (strlen(text) > *accum) {;
  char tmp[32];
  int delta = 0;
  int i = 0;
  char *wordsp = words;
  char *wordsq;
  do {
   wordsq = strchr(wordsp, ',');
   unsigned int len;
   if (wordsq == ((void *)0))
    len = strlen(wordsp);
   else
    len = wordsq-wordsp;
   if (sscanf(text+*accum, "%31s%n", tmp, &delta) != 0) {
    if ((strlen(tmp) == len) && (strncmp(tmp, wordsp, len) == 0)) {
     *accum += delta;
     return i;
    }
   }
   wordsp = wordsq + 1;
   ++i;
  } while (wordsq != ((void *)0));
 }
 fprintf(stderr, "parser error :: " "Expected word from list [%s]\n", words);
 showerr(text, *accum);
 return -1;
}

variable_types:
words
char *

variable_types:
accum
unsigned int *

variable_types:
tmp
char [32]

variable_types: delta int

variable_types: i int

variable_types:
wordsp
char *

variable_types:
wordsq
char *

variable_types:
len
unsigned int

return_type: int


decompiled_code:
__int64 __fastcall parse_int(const char *a1, __int64 a2, int *a3)
{
size_t v5; // rax
size_t v6; // rdi
__int64 result; // rax
int v8; // [rsp+Ch] [rbp-1Ch] BYREF

v5 = strlen(a1);
v6 = (unsigned int)*a3;
if ( v5 > v6 && (v8 = 0, (unsigned int)_isoc99_sscanf(&a1[v6], "%d%n", a2, &v8)) && v8 > 0 )
{
*a3 += v8;
result = 1LL;
}
else
{
fwrite("parser error :: Expected an integer\n", 1uLL, 0x24uLL, stderr);
showerr(a1, *a3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int64 a2, int *a3)
{
size_t v5; // rax
size_t v6; // rdi
__int64 result; // rax
int v8; // [rsp+Ch] [rbp-1Ch] BYREF

v5 = strlen(a1);
v6 = (unsigned int)*a3;
if ( v5 > v6 && (v8 = 0, (unsigned int)_isoc99_sscanf(&a1[v6], "%d%n", a2, &v8)) && v8 > 0 )
{
*a3 += v8;
result = 1LL;
}
else
{
fwrite("parser error :: Expected an integer\n", 1uLL, 0x24uLL, stderr);
func0(a1, *a3);
result = 0LL;
}
return result;
}

original_code:
_Bool parse_int(char *text, int *target, unsigned int *accum) {
 if (strlen(text) > *accum) {
  int delta = 0;
  if (sscanf(text+*accum, "%d%n", target, &delta) != 0) {
   if (delta > 0) {
    *accum += delta;
    return 1;
   }
  }
 }
 fprintf(stderr, "parser error :: " "Expected an integer\n");
 showerr(text, *accum);
 return 0;
}

variable_types:
target
int *


decompiled_code:
__int64 __fastcall parse_uint(const char *a1, __int64 a2, int *a3)
{
size_t v5; // rax
size_t v6; // rdi
__int64 result; // rax
int v8; // [rsp+Ch] [rbp-1Ch] BYREF

v5 = strlen(a1);
v6 = (unsigned int)*a3;
if ( v5 > v6 && (v8 = 0, (unsigned int)_isoc99_sscanf(&a1[v6], "%u%n", a2, &v8)) && v8 > 0 )
{
*a3 += v8;
result = 1LL;
}
else
{
fwrite("parser error :: Expected a positive integer\n", 1uLL, 0x2CuLL, stderr);
showerr(a1, *a3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2, int *a3)
{
size_t v5; // rax
size_t v6; // rdi
__int64 result; // rax
int v8; // [rsp+Ch] [rbp-1Ch] BYREF

v5 = strlen(a1);
v6 = (unsigned int)*a3;
if ( v5 > v6 && (v8 = 0, (unsigned int)_isoc99_sscanf(&a1[v6], "%u%n", a2, &v8)) && v8 > 0 )
{
*a3 += v8;
result = 1LL;
}
else
{
fwrite("parser error :: Expected a positive integer\n", 1uLL, 0x2CuLL, stderr);
func0(a1, *a3);
result = 0LL;
}
return result;
}

original_code:
_Bool parse_uint(char *text, unsigned int *target, unsigned int *accum) {
 if (strlen(text) > *accum) {
  int delta = 0;
  if (sscanf(text+*accum, "%u%n", target, &delta) != 0) {
   if (delta > 0) {
    *accum += delta;
    return 1;
   }
  }
 }
 fprintf(stderr, "parser error :: " "Expected a positive integer\n");
 showerr(text, *accum);
 return 0;
}

variable_types:
target
unsigned int *


decompiled_code:
__int64 __fastcall parse_ranged_val(__int64 a1, const char *a2, int *a3)
{
unsigned int v4; // er12
size_t v5; // rax
size_t v6; // rdx
int v8; // eax

v4 = parse_int(a2, a1 + 4, a3);
if ( !(_BYTE)v4 )
return v4;
v5 = strlen(a2);
v6 = (unsigned int)*a3;
if ( v5 <= v6 || a2[v6] != 58 )
{
*(_BYTE *)a1 = 0;
return v4;
}
*a3 = v6 + 1;
if ( strlen(a2) <= (unsigned int)(v6 + 1) )
{
v4 = 0;
fwrite("parser error :: colon indicates range, but we are running out of string\n", 1uLL, 0x48uLL, stderr);
showerr(a2, *a3);
return v4;
}
v8 = *(_DWORD *)(a1 + 4);
*(_BYTE *)a1 = 1;
*(_DWORD *)(a1 + 8) = v8;
return parse_int(a2, a1 + 12, a3);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, int *a3)
{
unsigned int v4; // er12
size_t v5; // rax
size_t v6; // rdx
int v8; // eax

v4 = func2(a2, a1 + 4, a3);
if ( !(_BYTE)v4 )
return v4;
v5 = strlen(a2);
v6 = (unsigned int)*a3;
if ( v5 <= v6 || a2[v6] != 58 )
{
*(_BYTE *)a1 = 0;
return v4;
}
*a3 = v6 + 1;
if ( strlen(a2) <= (unsigned int)(v6 + 1) )
{
v4 = 0;
fwrite("parser error :: colon indicates range, but we are running out of string\n", 1uLL, 0x48uLL, stderr);
func0(a2, *a3);
return v4;
}
v8 = *(_DWORD *)(a1 + 4);
*(_BYTE *)a1 = 1;
*(_DWORD *)(a1 + 8) = v8;
return func2(a2, a1 + 12, a3);
}

original_code:
_Bool parse_ranged_val(ranged_val_t *target, char *text, unsigned int *accum) {
 int n = 0;
 if (!parse_int(text, &target->value, accum)) {
  return 0;
 }
 if ((strlen(text) > *accum) && (text[*accum] == ':')) {
  *accum += 1;
  if (!(strlen(text) > *accum)) {
   fprintf(stderr, "parser error :: " "colon indicates range, but we are running out of string\n");
   showerr(text, *accum);
   return 0;
  }
  target->start = target->value;
  target->is_ranged = 1;
  if (!parse_int(text, &target->stop, accum)) {
   return 0;
  }
 }
 else {
  target->is_ranged = 0;
 }
 return 1;
}

canonical_original_code:
_Bool parse_ranged_val(struct ranged_val_t *target, char *text, unsigned int *accum) {
 int n = 0;
 if (!parse_int(text, &target->value, accum)) {
  return 0;
 }
 if ((strlen(text) > *accum) && (text[*accum] == ':')) {
  *accum += 1;
  if (!(strlen(text) > *accum)) {
   fprintf(stderr, "parser error :: " "colon indicates range, but we are running out of string\n");
   showerr(text, *accum);
   return 0;
  }
  target->start = target->value;
  target->is_ranged = 1;
  if (!parse_int(text, &target->stop, accum)) {
   return 0;
  }
 }
 else {
  target->is_ranged = 0;
 }
 return 1;
}

variable_types: struct ranged_val_t { _Bool is_ranged; int value; int start; int stop; } *

variable_types: n int


original_code:
_Bool parse_order(order_t *target, char *text, unsigned int *accum, int n) {
 ranged_val_t tmp;
 int counter = 0;
 while (counter < n) {
  if (!parse_ranged_val(&tmp, text, accum)) {
   return 0;
  }
  if (tmp.is_ranged) {
   if (tmp.stop > tmp.start) {
    while (counter < n && tmp.value <= tmp.stop) {
     target->o[counter++] = tmp.value++;
    }
   }
   else {
    while (counter < n && tmp.value >= tmp.stop) {
     target->o[counter++] = tmp.value--;
    }
   }
  }
  else {
   target->o[counter++] = tmp.value;
  }
 }
 return 1;
}

canonical_original_code:
_Bool parse_order(struct order_t *target, char *text, unsigned int *accum, int n) {
 struct ranged_val_t tmp;
 int counter = 0;
 while (counter < n) {
  if (!parse_ranged_val(&tmp, text, accum)) {
   return 0;
  }
  if (tmp.is_ranged) {
   if (tmp.stop > tmp.start) {
    while (counter < n && tmp.value <= tmp.stop) {
     target->o[counter++] = tmp.value++;
    }
   }
   else {
    while (counter < n && tmp.value >= tmp.stop) {
     target->o[counter++] = tmp.value--;
    }
   }
  }
  else {
   target->o[counter++] = tmp.value;
  }
 }
 return 1;
}

variable_types: struct order_t { unsigned char o[16]; } *

variable_types: struct ranged_val_t { _Bool is_ranged; int value; int start; int stop; }

variable_types: counter int


decompiled_code:
__int64 __fastcall parse_edgemap_mapopt(_DWORD *a1, const char *a2, int *a3)
{
int v4; // eax
int v5; // eax
__int64 result; // rax
__int64 v7[2]; // [rsp+0h] [rbp-38h]
int v8; // [rsp+10h] [rbp-28h]

v7[0] = 0x100000000LL;
v7[1] = 0x300000002LL;
v8 = 4;
v4 = match_word(a2, "cpy,val,pal,clp,ign", a3);
if ( v4 < 0 )
return 0LL;
v5 = *((_DWORD *)v7 + v4);
*a1 = v5;
if ( (unsigned int)(v5 - 1) <= 1 )
result = parse_ranged_val((__int64)(a1 + 1), a2, a3);
else
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1, const char *a2, int *a3)
{
int v4; // eax
int v5; // eax
__int64 result; // rax
__int64 v7[2]; // [rsp+0h] [rbp-38h]
int v8; // [rsp+10h] [rbp-28h]

v7[0] = 0x100000000LL;
v7[1] = 0x300000002LL;
v8 = 4;
v4 = func1(a2, "cpy,val,pal,clp,ign", a3);
if ( v4 < 0 )
return 0LL;
v5 = *((_DWORD *)v7 + v4);
*a1 = v5;
if ( (unsigned int)(v5 - 1) <= 1 )
result = func4((__int64)(a1 + 1), a2, a3);
else
result = 1LL;
return result;
}

original_code:
_Bool parse_edgemap_mapopt(edgemap_mapopt_t *target, char *text, unsigned int *accum) {
 char tmp[8];
 unsigned int modevs[5] = {0, 1, 2, 3, 4};
 int typei = match_word(text, "cpy,val,pal,clp,ign", accum);
 if (typei < 0) {
  return 0;
 }
 target->type = modevs[typei];
 if (target->type == 1 || target->type == 2) {
  if (!parse_ranged_val(&target->value, text, accum)) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
_Bool parse_edgemap_mapopt(struct edgemap_mapopt_t *target, char *text, unsigned int *accum) {
 char tmp[8];
 unsigned int modevs[5] = {0, 1, 2, 3, 4};
 int typei = match_word(text, "cpy,val,pal,clp,ign", accum);
 if (typei < 0) {
  return 0;
 }
 target->type = modevs[typei];
 if (target->type == 1 || target->type == 2) {
  if (!parse_ranged_val(&target->value, text, accum)) {
   return 0;
  }
 }
 return 1;
}

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

variable_types:
text
char *

variable_types:
tmp
char [8]

variable_types:
modevs
unsigned int [5]

variable_types: typei int

user_defined_types: struct edgemap_mapopt_t { unsigned int type; struct ranged_val_t value; }


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

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

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

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

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


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:
unsigned int *__fastcall interpret_argv(int argc, char **argv, _DWORD *a3)
{
unsigned int *v6; // r12
int v7; // eax
char *v8; // r14
size_t v9; // rax
char *v10; // rax
char *v11; // rdi
const char *v12; // rdx
const char *v13; // rdx
char *v14; // rdi
int v15; // eax
unsigned int v16; // eax
size_t v17; // rax
char *v18; // rax
void *v19; // r14
void *v20; // rdi
__int64 v21; // rsi
_QWORD *v22; // rax
unsigned int v23; // edx
int v25[11]; // [rsp+Ch] [rbp-2Ch] BYREF

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

canonical_decompiled_code:
unsigned int *__fastcall func10(int argc, char **argv, _DWORD *a3)
{
unsigned int *v6; // r12
int v7; // eax
char *v8; // r14
size_t v9; // rax
char *v10; // rax
char *v11; // rdi
const char *v12; // rdx
const char *v13; // rdx
char *v14; // rdi
int v15; // eax
unsigned int v16; // eax
size_t v17; // rax
char *v18; // rax
void *v19; // r14
void *v20; // rdi
__int64 v21; // rsi
_QWORD *v22; // rax
unsigned int v23; // edx
int v25[11]; // [rsp+Ch] [rbp-2Ch] BYREF

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

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

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
void **v4; // rdi
unsigned int v5; // ebx
__int64 v6; // rax

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

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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
v4 = (void **)*((_QWORD *)ptr + 6);
if ( v4 )
{
if ( *((_DWORD *)ptr + 10) )
{
v5 = 0;
do
{
v6 = v5++;
func9(v4[v6]);
v4 = (void **)*((_QWORD *)ptr + 6);
}
while ( *((_DWORD *)ptr + 10) > v5 );
}
free(v4);
}
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 func3(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
int v10; // ecx
int v11; // esi
size_t result; // rax

for ( i = 0; ; ++i )
{
result = strlen(a4);
if ( i >= result )
break;
v10 = (unsigned __int8)a4[i];
v11 = a2 + i * *(_DWORD *)(a5 + 28);
draw_glyph(a1, v11, a3, v10, 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
int v10; // ecx
int v11; // esi
size_t result; // rax

for ( i = 0; ; ++i )
{
result = strlen(a4);
if ( i >= result )
break;
v10 = (unsigned __int8)a4[i];
v11 = a2 + i * *(_DWORD *)(a5 + 28);
func4(a1, v11, a3, v10, 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
int v11; // er10
int v12; // esi
size_t result; // rax

for ( i = 0; ; ++i )
{
result = strlen(a4);
if ( i >= result )
break;
v11 = (unsigned __int8)a4[i];
v12 = i * *(_DWORD *)(a5 + 28);
draw_glyph_sc(a1, a2 + (v12 << a7), a3, v11, 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
int v11; // er10
int v12; // esi
size_t result; // rax

for ( i = 0; ; ++i )
{
result = strlen(a4);
if ( i >= result )
break;
v11 = (unsigned __int8)a4[i];
v12 = i * *(_DWORD *)(a5 + 28);
func6(a1, a2 + (v12 << a7), a3, v11, 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
int v12; // er10
int v13; // esi
size_t result; // rax

for ( i = 0; ; ++i )
{
result = strlen(a4);
if ( i >= result )
break;
v12 = (unsigned __int8)a4[i];
v13 = i * *(_DWORD *)(a5 + 28);
draw_glyph_asc(a1, a2 + (v13 << a8), a3, v12, 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
int v12; // er10
int v13; // esi
size_t result; // rax

for ( i = 0; ; ++i )
{
result = strlen(a4);
if ( i >= result )
break;
v12 = (unsigned __int8)a4[i];
v13 = i * *(_DWORD *)(a5 + 28);
func8(a1, a2 + (v13 << a8), a3, v12, 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 v2; // r12
pthread_mutex_t *v3; // rdi

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v2; // r12
pthread_mutex_t *v3; // rdi

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

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 *

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 v8; // rcx
__int64 v9; // rax
__int64 v10; // rdx
int v11; // esi
__int64 v12; // rdi

pthread_mutex_lock(*(pthread_mutex_t **)a1);
v8 = *(_QWORD *)(a1 + 24);
if ( v8 )
{
v9 = *(_QWORD *)(a1 + 8);
v10 = 0LL;
while ( 1 )
{
if ( *(_DWORD *)v9 == a2 )
{
v11 = *(_DWORD *)(v9 + 4);
if ( v11 )
break;
}
++v10;
v9 += 16LL;
if ( v8 == v10 )
return pthread_mutex_unlock(*(pthread_mutex_t **)a1);
}
v12 = *(_QWORD *)(v9 + 8);
*(_DWORD *)(v9 + 4) = v11 - 1;
(*(void (__fastcall **)(__int64, _QWORD, __int64, _QWORD))(a1 + 40))(v12, 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 v8; // rcx
__int64 v9; // rax
__int64 v10; // rdx
int v11; // esi
__int64 v12; // rdi

pthread_mutex_lock(*(pthread_mutex_t **)a1);
v8 = *(_QWORD *)(a1 + 24);
if ( v8 )
{
v9 = *(_QWORD *)(a1 + 8);
v10 = 0LL;
while ( 1 )
{
if ( *(_DWORD *)v9 == a2 )
{
v11 = *(_DWORD *)(v9 + 4);
if ( v11 )
break;
}
++v10;
v9 += 16LL;
if ( v8 == v10 )
return pthread_mutex_unlock(*(pthread_mutex_t **)a1);
}
v12 = *(_QWORD *)(v9 + 8);
*(_DWORD *)(v9 + 4) = v11 - 1;
(*(void (__fastcall **)(__int64, _QWORD, __int64, _QWORD))(a1 + 40))(v12, 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; // rdi
_QWORD *v1; // rax

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

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

syscall_register(60LL, sys_exit);
v0 = (_BYTE *)xkmallocf(272LL, "init_task");
init = v0;
v1 = v0 + 8;
*v0 = 0;
do
*v1++ = 0LL;
while ( v1 != (_QWORD *)(v0 + 264) );
load_init_page_tables();
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(unsigned int *a1)
{
__int64 v1; // rax
__int64 (*v2)(void); // rax
__int64 result; // rax

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

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

v1 = *a1;
if ( (unsigned int)v1 <= 1 && (v2 = (__int64 (*)(void))**((_QWORD **)&bdevsw + v1)) != 0LL )
result = v2();
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(unsigned int *a1)
{
__int64 v1; // rax
__int64 (*v2)(void); // rax
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
__int64 v1; // rax
__int64 (*v2)(void); // rax
__int64 result; // rax

v1 = *a1;
if ( (unsigned int)v1 <= 1 && (v2 = *(__int64 (**)(void))(bdevsw[v1] + 16LL)) != 0LL )
result = v2();
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(unsigned int *a1)
{
__int64 v1; // rax
__int64 (*v2)(void); // rax
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1)
{
__int64 v1; // rax
__int64 (*v2)(void); // rax
__int64 result; // rax

v1 = *a1;
if ( (unsigned int)v1 <= 1 && (v2 = *(__int64 (**)(void))(bdevsw[v1] + 24LL)) != 0LL )
result = v2();
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 result; // rax

result = kmalloc(a1);
if ( !result )
{
oom(a2);
result = 0LL;
}
return result;
}

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

result = func0(a1);
if ( !result )
{
oom(a2);
result = 0LL;
}
return result;
}

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; // r12

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

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

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 __int64 v4; // r9
unsigned __int8 *v5; // rdi
unsigned __int8 *i; // rcx
unsigned __int64 result; // rax
unsigned __int8 v8; // dl

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

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 a1, unsigned __int8 *a2, unsigned __int8 a3)
{
unsigned __int64 v4; // r9
unsigned __int8 *v5; // rdi
unsigned __int8 *i; // rcx
unsigned __int64 result; // rax
unsigned __int8 v8; // dl

v4 = a3;
v5 = a2;
for ( i = a2; ; ++i )
{
result = a1 / v4;
v8 = a1 % v4 + 48;
if ( a1 % v4 > 9 )
v8 = a1 % v4 + 87;
*i = v8;
if ( v4 > a1 )
break;
a1 /= v4;
}
i[1] = 0;
if ( i > a2 )
{
while ( 1 )
{
result = *v5;
--i;
*v5++ = v8;
i[1] = result;
if ( v5 >= i )
break;
v8 = *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

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()
{
void (__fastcall *v0)(unsigned int, unsigned int); // r8

if ( elf_map() != -1 )
{
msr_write(0xC0000081, 0);
v0(0xC0000082, syscall_dispatch);
__asm { sysret }
JUMPOUT(0x64LL);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
void (__fastcall *v0)(unsigned int, unsigned int); // r8

if ( elf_map() != -1 )
{
func0(0xC0000081, 0);
v0(0xC0000082, syscall_dispatch);
__asm { sysret }
JUMPOUT(0x64LL);
}
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; // rdi
_QWORD *v3; // rbx
void *v4; // rdi

v2 = *a1;
v3 = (_QWORD *)*v2;
if ( *v2 )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[1];
free(v4);
v2 = *a1;
**a1 = v3;
}
while ( v3 );
}
free(v2);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func2(_QWORD **a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbx
void *v4; // rdi

v2 = *a1;
v3 = (_QWORD *)*v2;
if ( *v2 )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[1];
free(v4);
v2 = *a1;
**a1 = v3;
}
while ( v3 );
}
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
void *v2; // rbx
unsigned int v3; // er12

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

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

v1 = *a1;
if ( !*a1 )
{
v3 = -1;
puts("empty q");
return v3;
}
v2 = (void *)*((_QWORD *)*v1 + 1);
v3 = *(_DWORD *)*v1;
if ( v2 )
{
free(*v1);
**a1 = v2;
return v3;
}
func2(a1);
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)
{
__int64 *v3; // rcx
__int64 v4; // rdi
float v5; // xmm1_4
__int64 result; // rax
float v7; // xmm2_4
float v8; // xmm0_4
float v9; // xmm1_4
__int64 v10; // rdi
float v11; // xmm2_4
float v12; // xmm1_4
__int64 v13; // rdi
__int64 v14; // rcx

v3 = *(__int64 **)(a1 + 16);
v4 = v3[9];
v5 = 1.0 / ((double)COLOR_BANDS - 1.0);
result = (int)(float)(a3 / v5);
v7 = *(float *)(v4 + 4LL * (int)result);
v8 = (float)(a3 - (float)((float)(int)result * v5)) / v5;
v9 = *(float *)(v4 + 4LL * (int)result + 4);
v10 = *v3;
*a2 = (float)((float)(v9 - v7) * v8) + v7;
v11 = *(float *)(v10 + 4LL * (int)result);
v12 = *(float *)(v10 + 4LL * (int)result + 4);
v13 = v3[3];
v14 = v3[6];
a2[3] = (float)((float)(v12 - v11) * v8) + v11;
a2[2] = (float)((float)(*(float *)(v13 + 4LL * (int)result + 4) - *(float *)(v13 + 4LL * (int)result)) * v8)
+ *(float *)(v13 + 4LL * (int)result);
a2[1] = (float)(v8 * (float)(*(float *)(v14 + 4LL * (int)result + 4) - *(float *)(v14 + 4LL * (int)result)))
+ *(float *)(v14 + 4LL * (int)result);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, float *a2, float a3)
{
__int64 *v3; // rcx
__int64 v4; // rdi
float v5; // xmm1_4
__int64 result; // rax
float v7; // xmm2_4
float v8; // xmm0_4
float v9; // xmm1_4
__int64 v10; // rdi
float v11; // xmm2_4
float v12; // xmm1_4
__int64 v13; // rdi
__int64 v14; // rcx

v3 = *(__int64 **)(a1 + 16);
v4 = v3[9];
v5 = 1.0 / ((double)COLOR_BANDS - 1.0);
result = (int)(float)(a3 / v5);
v7 = *(float *)(v4 + 4LL * (int)result);
v8 = (float)(a3 - (float)((float)(int)result * v5)) / v5;
v9 = *(float *)(v4 + 4LL * (int)result + 4);
v10 = *v3;
*a2 = (float)((float)(v9 - v7) * v8) + v7;
v11 = *(float *)(v10 + 4LL * (int)result);
v12 = *(float *)(v10 + 4LL * (int)result + 4);
v13 = v3[3];
v14 = v3[6];
a2[3] = (float)((float)(v12 - v11) * v8) + v11;
a2[2] = (float)((float)(*(float *)(v13 + 4LL * (int)result + 4) - *(float *)(v13 + 4LL * (int)result)) * v8)
+ *(float *)(v13 + 4LL * (int)result);
a2[1] = (float)(v8 * (float)(*(float *)(v14 + 4LL * (int)result + 4) - *(float *)(v14 + 4LL * (int)result)))
+ *(float *)(v14 + 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)(a3 * (float)*(int *)(a1 + 8)));
*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)(a3 * (float)*(int *)(a1 + 8)));
*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 v3; // r8
float v4; // xmm3_4
float v5; // xmm4_4

result = *(unsigned int *)(a1 + 8);
if ( (int)result > 0 )
{
v3 = 0LL;
v4 = 0.0;
do
{
result = set_color(a1, (float *)(*(_QWORD *)a1 + 16 * v3), v4);
v4 = v4 + v5;
}
while ( *(_DWORD *)(a1 + 8) > (int)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
__int64 v3; // r8
float v4; // xmm3_4
float v5; // xmm4_4

result = *(unsigned int *)(a1 + 8);
if ( (int)result > 0 )
{
v3 = 0LL;
v4 = 0.0;
do
{
result = func0(a1, (float *)(*(_QWORD *)a1 + 16 * v3), v4);
v4 = v4 + v5;
}
while ( *(_DWORD *)(a1 + 8) > (int)v3 );
}
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:
float __fastcall get_default_color_value(int a1, int a2)
{
float result; // xmm0_4
double v3; // xmm1_8
double v4; // xmm1_8
double v5; // xmm1_8

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

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

result = (float)a2 / (float)COLOR_BANDS;
if ( a1 == 2 )
{
v4 = result;
result = *(float *)&LC1;
if ( v4 >= 0.3 )
{
result = 0.0;
if ( v4 <= 0.6 )
result = 1.0 - (v4 - 0.3) / 0.3;
}
}
else if ( a1 > 2 )
{
if ( a1 == 3 )
{
if ( result < 0.3 )
{
result = 0.0;
}
else if ( result <= 1.0 )
{
v5 = (result - 0.3) * 0.5;
result = *(float *)&LC1;
if ( v5 <= 1.0 )
result = v5;
}
else
{
result = *(float *)&LC1;
}
}
}
else if ( a1 )
{
if ( a1 == 1 )
{
v3 = result;
result = 0.0;
if ( v3 >= 0.3 )
{
result = *(float *)&LC1;
if ( v3 <= 0.6 )
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)
{
float *v3; // rax
__int64 v4; // rdi
float *v5; // rbx
void *result; // rax
int v7; // edx
float v8; // xmm0_4
__int64 v9; // rax
void *v10; // rdx

v3 = (float *)malloc(4LL * COLOR_BANDS);
v4 = COLOR_BANDS;
*(_QWORD *)a1 = v3;
v5 = v3;
result = malloc(32 * v4);
v7 = COLOR_BANDS;
*(_QWORD *)(a1 + 8) = result;
if ( v7 > 0 )
{
LODWORD(result) = 0;
do
{
v8 = get_default_color_value(a2, (int)result);
v5[v9] = v8;
result = (void *)(v9 + 1);
}
while ( result != v10 );
}
*(_DWORD *)(a1 + 16) = 0;
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, int a2)
{
float *v3; // rax
__int64 v4; // rdi
float *v5; // rbx
void *result; // rax
int v7; // edx
float v8; // xmm0_4
__int64 v9; // rax
void *v10; // rdx

v3 = (float *)malloc(4LL * COLOR_BANDS);
v4 = COLOR_BANDS;
*(_QWORD *)a1 = v3;
v5 = v3;
result = malloc(32 * v4);
v7 = COLOR_BANDS;
*(_QWORD *)(a1 + 8) = result;
if ( v7 > 0 )
{
LODWORD(result) = 0;
do
{
v8 = func5(a2, (int)result);
v5[v9] = v8;
result = (void *)(v9 + 1);
}
while ( result != v10 );
}
*(_DWORD *)(a1 + 16) = 0;
return result;
}

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