decompiled_code:
void __fastcall words_find(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 *v7; // rbx
__int64 v8; // rdi
__int64 v9[3]; // [rsp+0h] [rbp-58h] BYREF
_QWORD v10[8]; // [rsp+18h] [rbp-40h] BYREF

if ( !a4 && *(_QWORD *)(a2 + 32) < (unsigned __int64)*(unsigned __int8 *)(a1 + 33) )
return;
v7 = (__int64 *)word_head;
if ( !word_head )
return;
while ( 1 )
{
if ( (unsigned __int64)v7[1] > *(_QWORD *)(a2 + 32) || !(unsigned __int8)histogram_fits(v7[2], a2) )
goto LABEL_13;
v8 = histogram_copy(a2);
v10[0] = v8;
if ( !v8 )
return;
if ( !(unsigned __int8)histogram_subtract(v8, v7[2]) )
{
histogram_destroy(v10);
return;
}
if ( !*(_QWORD *)(v10[0] + 32LL) )
break;
v9[0] = *v7;
v9[1] = v7[1];
v9[2] = a3;
words_find(a1, v10[0], v9);
histogram_destroy(v10);
LABEL_13:
v7 = (__int64 *)v7[3];
if ( !v7 )
return;
}
if ( a4 || v7[1] >= (unsigned __int64)*(unsigned __int8 *)(a1 + 33) )
{
fwrite((const void *)*v7, v7[1], 1uLL, stdout);
for ( ; a3; a3 = *(_QWORD *)(a3 + 16) )
{
fputc(32, stdout);
fwrite(*(const void **)a3, *(_QWORD *)(a3 + 8), 1uLL, stdout);
}
fputc(10, stdout);
}
histogram_destroy(v10);
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 *v7; // rbx
__int64 v8; // rdi
__int64 v9[3]; // [rsp+0h] [rbp-58h] BYREF
_QWORD v10[8]; // [rsp+18h] [rbp-40h] BYREF

if ( !a4 && *(_QWORD *)(a2 + 32) < (unsigned __int64)*(unsigned __int8 *)(a1 + 33) )
return;
v7 = (__int64 *)word_head;
if ( !word_head )
return;
while ( 1 )
{
if ( (unsigned __int64)v7[1] > *(_QWORD *)(a2 + 32) || !(unsigned __int8)histogram_fits(v7[2], a2) )
goto LABEL_13;
v8 = histogram_copy(a2);
v10[0] = v8;
if ( !v8 )
return;
if ( !(unsigned __int8)histogram_subtract(v8, v7[2]) )
{
histogram_destroy(v10);
return;
}
if ( !*(_QWORD *)(v10[0] + 32LL) )
break;
v9[0] = *v7;
v9[1] = v7[1];
v9[2] = a3;
func5(a1, v10[0], v9);
histogram_destroy(v10);
LABEL_13:
v7 = (__int64 *)v7[3];
if ( !v7 )
return;
}
if ( a4 || v7[1] >= (unsigned __int64)*(unsigned __int8 *)(a1 + 33) )
{
fwrite((const void *)*v7, v7[1], 1uLL, stdout);
for ( ; a3; a3 = *(_QWORD *)(a3 + 16) )
{
fputc(32, stdout);
fwrite(*(const void **)a3, *(_QWORD *)(a3 + 8), 1uLL, stdout);
}
fputc(10, stdout);
}
histogram_destroy(v10);
}

original_code:
static void
words_find (const struct config *config, struct histogram *h, struct prev_word *prev, int len_satisfied)
{
 struct word *w;
 struct histogram *copy;
 struct prev_word pw;
 struct prev_word *p;
 if (!len_satisfied && h->ntotal < config->haslength) {
  return;
 }
 for (w = word_head; w; w = w->next)
 {
  if (w->len > h->ntotal) {
   continue;
  }
  if (histogram_fits(w->hist, h) == 0) {
   continue;
  }
  if ((copy = histogram_copy(h)) == ((void *)0)) {
   return;
  }
  if (!histogram_subtract(copy, w->hist)) {
   histogram_destroy(&copy);
   return;
  }
  if (copy->ntotal == 0)
  {
   if (len_satisfied || w->len >= config->haslength) {
    fwrite(w->str, w->len, 1, stdout);
    for (p = prev; p; p = p->prev) {
     fputc(' ', stdout);
     fwrite(p->str, p->len, 1, stdout);
    }
    fputc('\n', stdout);
   }
   histogram_destroy(&copy);
   return;
  }
  pw.str = w->str;
  pw.len = w->len;
  pw.prev = prev;
  words_find(config, copy, &pw, (len_satisfied || w->len >= config->haslength));
  histogram_destroy(&copy);
 }
}

canonical_original_code:
static void words_find(struct config *config, struct histogram *h, struct prev_word *prev, int len_satisfied)
{
 struct word *w;
 struct histogram *copy;
 struct prev_word pw;
 struct prev_word *p;
 if (!len_satisfied && h->ntotal < config->haslength) {
  return;
 }
 for (w = word_head; w; w = w->next)
 {
  if (w->len > h->ntotal) {
   continue;
  }
  if (histogram_fits(w->hist, h) == 0) {
   continue;
  }
  if ((copy = histogram_copy(h)) == ((void *)0)) {
   return;
  }
  if (!histogram_subtract(copy, w->hist)) {
   histogram_destroy(&copy);
   return;
  }
  if (copy->ntotal == 0)
  {
   if (len_satisfied || w->len >= config->haslength) {
    fwrite(w->str, w->len, 1, stdout);
    for (p = prev; p; p = p->prev) {
     fputc(' ', stdout);
     fwrite(p->str, p->len, 1, stdout);
    }
    fputc('\n', stdout);
   }
   histogram_destroy(&copy);
   return;
  }
  pw.str = w->str;
  pw.len = w->len;
  pw.prev = prev;
  words_find(config, copy, &pw, (len_satisfied || w->len >= config->haslength));
  histogram_destroy(&copy);
 }
}

variable_types: struct config { char *name; char *dictfile; struct args { char **av; int ac; } words; unsigned char minlength; unsigned char haslength; _Bool print_help; } *

variable_types: struct prev_word { char *str; unsigned long len; struct prev_word *prev; } *

user_defined_types: struct histogram { char *bins; int *freq; unsigned long len; int maxfreq; unsigned long ntotal; }


main

canonical_name: main

repo: aklomp/anagram

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // dl
int result; // eax
__int64 v5; // rsi
__int64 v6; // [rsp+8h] [rbp-70h] BYREF
size_t v7; // [rsp+10h] [rbp-68h] BYREF
__int64 v8; // [rsp+18h] [rbp-60h] BYREF
void *ptr[2]; // [rsp+20h] [rbp-58h] BYREF
__int128 v10[2]; // [rsp+30h] [rbp-48h] BYREF
__int64 v11; // [rsp+50h] [rbp-28h]
const char **v12; // [rsp+60h] [rbp-18h] BYREF
int v13; // [rsp+68h] [rbp-10h]

v10[0] = (__int128)_mm_loadu_si128((const __m128i *)&config_default);
v10[1] = (__int128)_mm_loadu_si128((const __m128i *)&config_default + 1);
v11 = *((_QWORD *)&config_default + 4);
v7 = 0LL;
v6 = 0LL;
v12 = argv;
v13 = argc;
if ( (unsigned __int8)args_parse(v10, &v12, envp) )
{
if ( BYTE2(v11) )
{
usage((const char **)v10);
result = 0;
}
else
{
v3 = input_get(v10, ptr);
result = 1;
if ( v3 )
{
v5 = histogram_create(ptr[0], ptr[1]);
v8 = v5;
if ( v5 )
{
if ( (unsigned int)parse_dictfile((__int64)v10, v5, &v7, &v6) )
{
if ( BYTE1(v11) <= v7 )
{
if ( v6 )
words_find((__int64)v10, v8, 0LL, 0);
}
words_destroy();
histogram_destroy(&v8);
free(ptr[0]);
result = 0;
}
else
{
fwrite("Could not parse file\n", 1uLL, 0x15uLL, stderr);
histogram_destroy(&v8);
free(ptr[0]);
result = 1;
}
}
else
{
fwrite("Could not create histogram of input\n", 1uLL, 0x24uLL, stderr);
free(ptr[0]);
result = 1;
}
}
}
}
else
{
usage((const char **)v10);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // dl
int result; // eax
__int64 v5; // rsi
__int64 v6; // [rsp+8h] [rbp-70h] BYREF
size_t v7; // [rsp+10h] [rbp-68h] BYREF
__int64 v8; // [rsp+18h] [rbp-60h] BYREF
void *ptr[2]; // [rsp+20h] [rbp-58h] BYREF
__int128 v10[2]; // [rsp+30h] [rbp-48h] BYREF
__int64 v11; // [rsp+50h] [rbp-28h]
const char **v12; // [rsp+60h] [rbp-18h] BYREF
int v13; // [rsp+68h] [rbp-10h]

v10[0] = (__int128)_mm_loadu_si128((const __m128i *)&config_default);
v10[1] = (__int128)_mm_loadu_si128((const __m128i *)&config_default + 1);
v11 = *((_QWORD *)&config_default + 4);
v7 = 0LL;
v6 = 0LL;
v12 = argv;
v13 = argc;
if ( (unsigned __int8)args_parse(v10, &v12, envp) )
{
if ( BYTE2(v11) )
{
func2((const char **)v10);
result = 0;
}
else
{
v3 = input_get(v10, ptr);
result = 1;
if ( v3 )
{
v5 = histogram_create(ptr[0], ptr[1]);
v8 = v5;
if ( v5 )
{
if ( (unsigned int)func4((__int64)v10, v5, &v7, &v6) )
{
if ( BYTE1(v11) <= v7 )
{
if ( v6 )
func5((__int64)v10, v8, 0LL, 0);
}
func1();
histogram_destroy(&v8);
free(ptr[0]);
result = 0;
}
else
{
fwrite("Could not parse file\n", 1uLL, 0x15uLL, stderr);
histogram_destroy(&v8);
free(ptr[0]);
result = 1;
}
}
else
{
fwrite("Could not create histogram of input\n", 1uLL, 0x24uLL, stderr);
free(ptr[0]);
result = 1;
}
}
}
}
else
{
func2((const char **)v10);
result = 1;
}
return result;
}

original_code:
int
main (int argc, char *argv[])
{
 struct config config = config_default;
 struct input input;
 struct histogram *inhist;
 size_t max_found_len = 0;
 size_t nwords = 0;
 if (!args_parse(&config, &(struct args) { .ac = argc, .av = argv })) {
  usage(&config);
  return 1;
 }
 if (config.print_help) {
  usage(&config);
  return 0;
 }
 if (!input_get(&config, &input)) {
  return 1;
 }
 if ((inhist = histogram_create(input.str, input.len)) == ((void *)0)) {
  fprintf(stderr, "Could not create histogram of input\n");
  free(input.str);
  return 1;
 }
 if (parse_dictfile(&config, inhist, &max_found_len, &nwords) == 0) {
  fprintf(stderr, "Could not parse file\n");
  histogram_destroy(&inhist);
  free(input.str);
  return 1;
 }
 if (max_found_len >= config.haslength && nwords > 0) {
  words_find(&config, inhist, ((void *)0), 0);
 }
 words_destroy();
 histogram_destroy(&inhist);
 free(input.str);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct config config = config_default;
 struct input input;
 struct histogram *inhist;
 unsigned long max_found_len = 0;
 unsigned long nwords = 0;
 if (!args_parse(&config, &(struct args) { .ac = argc, .av = argv })) {
  usage(&config);
  return 1;
 }
 if (config.print_help) {
  usage(&config);
  return 0;
 }
 if (!input_get(&config, &input)) {
  return 1;
 }
 if ((inhist = histogram_create(input.str, input.len)) == ((void *)0)) {
  fprintf(stderr, "Could not create histogram of input\n");
  free(input.str);
  return 1;
 }
 if (parse_dictfile(&config, inhist, &max_found_len, &nwords) == 0) {
  fprintf(stderr, "Could not parse file\n");
  histogram_destroy(&inhist);
  free(input.str);
  return 1;
 }
 if (max_found_len >= config.haslength && nwords > 0) {
  words_find(&config, inhist, ((void *)0), 0);
 }
 words_destroy();
 histogram_destroy(&inhist);
 free(input.str);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct config { char *name; char *dictfile; struct args { char **av; int ac; } words; unsigned char minlength; unsigned char haslength; _Bool print_help; }

variable_types: struct input { char *str; unsigned long len; }

variable_types: struct histogram { char *bins; int *freq; unsigned long len; int maxfreq; unsigned long ntotal; } *

variable_types:
nwords
unsigned long

return_type: int

user_defined_types: struct config { char *name; char *dictfile; struct args words; unsigned char minlength; unsigned char haslength; _Bool print_help; }


decompiled_code:
__int64 __fastcall char_compare(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0LL;
if ( *(_BYTE *)a1 != *(_BYTE *)a2 )
result = 2 * (unsigned int)(*(_BYTE *)a1 >= *(_BYTE *)a2) - 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0LL;
if ( *(_BYTE *)a1 != *(_BYTE *)a2 )
result = 2 * (unsigned int)(*(_BYTE *)a1 >= *(_BYTE *)a2) - 1;
return result;
}

original_code:
static int
char_compare (const void *const p1, const void *const p2)
{
 if (*(char *const)p1 == *(char *const)p2) {
  return 0;
 }
 return (*(char *const)p1 < *(char *const)p2) ? -1 : 1;
}

canonical_original_code:
static int char_compare(void *p1, void *p2)
{
 if (*(char *)p1 == *(char *)p2) {
  return 0;
 }
 return (*(char *)p1 < *(char *)p2) ? -1 : 1;
}


decompiled_code:
void __fastcall histogram_destroy(void ***a1)
{
if ( a1 )
{
if ( *a1 )
{
free(**a1);
free((*a1)[1]);
free(*a1);
*a1 = 0LL;
}
}
}

original_code:
void
histogram_destroy (struct histogram **h)
{
 if (h == ((void *)0) || *h == ((void *)0)) {
  return;
 }
 free((*h)->bins);
 free((*h)->freq);
 free(*h);
 *h = ((void *)0);
}

canonical_original_code:
void histogram_destroy(struct histogram **h)
{
 if (h == ((void *)0) || *h == ((void *)0)) {
  return;
 }
 free((*h)->bins);
 free((*h)->freq);
 free(*h);
 *h = ((void *)0);
}

variable_types: struct histogram { char *bins; int *freq; unsigned long len; int maxfreq; unsigned long ntotal; } **

return_type: void


decompiled_code:
__int64 __fastcall histogram_fits(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // r13
__int64 result; // rax
char *v4; // r14
char *v5; // r13
char *v6; // rbx
char *v7; // rax

v2 = *(_QWORD *)(a1 + 16);
result = 0LL;
if ( v2 <= *(_QWORD *)(a2 + 16) && *(_DWORD *)(a1 + 24) <= *(_DWORD *)(a2 + 24) )
{
v4 = *(char **)a1;
v5 = (char *)(*(_QWORD *)a1 + v2);
if ( *(_QWORD *)a1 >= (unsigned __int64)v5 )
{
result = 1LL;
}
else
{
v6 = *(char **)a1;
while ( 1 )
{
v7 = find_character(a2, *v6);
if ( !v7 )
return 0LL;
if ( *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4 * (v6 - v4)) > *(_DWORD *)(*(_QWORD *)(a2 + 8)
+ 4LL * (_QWORD)&v7[-*(_QWORD *)a2]) )
break;
if ( ++v6 == v5 )
return 1LL;
}
result = 0LL;
}
}
return result;
}

original_code:
_Bool
histogram_fits (const struct histogram *h, const struct histogram *base)
{
 if (h->len > base->len) {
  return 0;
 }
 if (h->maxfreq > base->maxfreq) {
  return 0;
 }
 for (const char *b, *t = h->bins; t < h->bins + h->len; t++) {
  if ((b = find_character(base, *t)) == ((void *)0)) {
   return 0;
  }
  if (h->freq[t - h->bins] > base->freq[b - base->bins]) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
_Bool histogram_fits(struct histogram *h, struct histogram *base)
{
 if (h->len > base->len) {
  return 0;
 }
 if (h->maxfreq > base->maxfreq) {
  return 0;
 }
 for (char *b; char *t = h->bins; t < h->bins + h->len; t++) {
  if ((b = find_character(base, *t)) == ((void *)0)) {
   return 0;
  }
  if (h->freq[t - h->bins] > base->freq[b - base->bins]) {
   return 0;
  }
 }
 return 1;
}

variable_types:
base
struct histogram *

variable_types:
b
char *

variable_types:
t
char *


original_code:
_Bool
histogram_subtract (struct histogram *target, struct histogram *from)
{
 char *t;
 char *f;
 int *freq_t;
 int *freq_f;
 target->maxfreq = 0;
 for (f = from->bins, t = target->bins; f < from->bins + from->len; f++) {
  freq_t = target->freq + (t - target->bins);
  while (*t < *f) {
   if (*freq_t > target->maxfreq) {
    target->maxfreq = *freq_t;
   }
   if (++t == target->bins + target->len) {
    return 0;
   }
   freq_t = target->freq + (t - target->bins);
  }
  if (*t != *f) {
   return 0;
  }
  freq_f = from->freq + (f - from->bins);
  if (*freq_f > *freq_t) {
   return 0;
  }
  *freq_t -= *freq_f;
  target->ntotal -= *freq_f;
  if (*freq_t > target->maxfreq) {
   target->maxfreq = *freq_t;
  }
 }
 return 1;
}

canonical_original_code:
_Bool histogram_subtract(struct histogram *target, struct histogram *from)
{
 char *t;
 char *f;
 int *freq_t;
 int *freq_f;
 target->maxfreq = 0;
 for (f = from->bins, t = target->bins; f < from->bins + from->len; f++) {
  freq_t = target->freq + (t - target->bins);
  while (*t < *f) {
   if (*freq_t > target->maxfreq) {
    target->maxfreq = *freq_t;
   }
   if (++t == target->bins + target->len) {
    return 0;
   }
   freq_t = target->freq + (t - target->bins);
  }
  if (*t != *f) {
   return 0;
  }
  freq_f = from->freq + (f - from->bins);
  if (*freq_f > *freq_t) {
   return 0;
  }
  *freq_t -= *freq_f;
  target->ntotal -= *freq_f;
  if (*freq_t > target->maxfreq) {
   target->maxfreq = *freq_t;
  }
 }
 return 1;
}

variable_types:
from
struct histogram *

variable_types:
f
char *


decompiled_code:
__int64 __fastcall char_compare(const void *a1, const void *a2)
{
return 2 * (unsigned int)(*(_BYTE *)a1 >= *(_BYTE *)a2) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return 2 * (unsigned int)(*(_BYTE *)a1 >= *(_BYTE *)a2) - 1;
}

original_code:
static int
char_compare (const void *const p1, const void *const p2)
{
 return (*(char *const)p1 < *(char *const)p2) ? -1 : 1;
}

canonical_original_code:
static int char_compare(void *p1, void *p2)
{
 return (*(char *)p1 < *(char *)p2) ? -1 : 1;
}


decompiled_code:
__int64 __fastcall codec_choose_forced(_QWORD *a1, __int16 a2)
{
__int64 result; // rax

result = 0LL;
if ( a2 )
{
if ( (a2 & 1) != 0 )
{
*a1 = &base64_stream_encode_avx2;
a1[1] = &base64_stream_decode_avx2;
result = 1LL;
}
else if ( (a2 & 2) != 0 )
{
*a1 = &base64_stream_encode_neon32;
a1[1] = &base64_stream_decode_neon32;
result = 1LL;
}
else if ( (a2 & 4) != 0 )
{
*a1 = &base64_stream_encode_neon64;
a1[1] = &base64_stream_decode_neon64;
result = 1LL;
}
else if ( (a2 & 8) != 0 )
{
*a1 = &base64_stream_encode_plain;
a1[1] = &base64_stream_decode_plain;
result = 1LL;
}
else if ( (a2 & 0x10) != 0 )
{
*a1 = &base64_stream_encode_ssse3;
a1[1] = &base64_stream_decode_ssse3;
result = 1LL;
}
else if ( (a2 & 0x20) != 0 )
{
*a1 = &base64_stream_encode_sse41;
a1[1] = &base64_stream_decode_sse41;
result = 1LL;
}
else if ( (a2 & 0x40) != 0 )
{
*a1 = &base64_stream_encode_sse42;
a1[1] = &base64_stream_decode_sse42;
result = 1LL;
}
else if ( (a2 & 0x80u) != 0 )
{
*a1 = &base64_stream_encode_avx;
a1[1] = &base64_stream_decode_avx;
result = 1LL;
}
else
{
result = 0LL;
if ( (a2 & 0x100) != 0 )
{
*a1 = &base64_stream_encode_avx512;
a1[1] = &base64_stream_decode_avx512;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int16 a2)
{
__int64 result; // rax

result = 0LL;
if ( a2 )
{
if ( (a2 & 1) != 0 )
{
*a1 = &base64_stream_encode_avx2;
a1[1] = &base64_stream_decode_avx2;
result = 1LL;
}
else if ( (a2 & 2) != 0 )
{
*a1 = &base64_stream_encode_neon32;
a1[1] = &base64_stream_decode_neon32;
result = 1LL;
}
else if ( (a2 & 4) != 0 )
{
*a1 = &base64_stream_encode_neon64;
a1[1] = &base64_stream_decode_neon64;
result = 1LL;
}
else if ( (a2 & 8) != 0 )
{
*a1 = &base64_stream_encode_plain;
a1[1] = &base64_stream_decode_plain;
result = 1LL;
}
else if ( (a2 & 0x10) != 0 )
{
*a1 = &base64_stream_encode_ssse3;
a1[1] = &base64_stream_decode_ssse3;
result = 1LL;
}
else if ( (a2 & 0x20) != 0 )
{
*a1 = &base64_stream_encode_sse41;
a1[1] = &base64_stream_decode_sse41;
result = 1LL;
}
else if ( (a2 & 0x40) != 0 )
{
*a1 = &base64_stream_encode_sse42;
a1[1] = &base64_stream_decode_sse42;
result = 1LL;
}
else if ( (a2 & 0x80u) != 0 )
{
*a1 = &base64_stream_encode_avx;
a1[1] = &base64_stream_decode_avx;
result = 1LL;
}
else
{
result = 0LL;
if ( (a2 & 0x100) != 0 )
{
*a1 = &base64_stream_encode_avx512;
a1[1] = &base64_stream_decode_avx512;
result = 1LL;
}
}
}
return result;
}

original_code:
static _Bool
codec_choose_forced (struct codec *codec, int flags)
{
 if (!(flags & 0xFFFF)) {
  return 0;
 }
 if (flags & (1 << 0)) {
  codec->enc = base64_stream_encode_avx2;
  codec->dec = base64_stream_decode_avx2;
  return 1;
 }
 if (flags & (1 << 1)) {
  codec->enc = base64_stream_encode_neon32;
  codec->dec = base64_stream_decode_neon32;
  return 1;
 }
 if (flags & (1 << 2)) {
  codec->enc = base64_stream_encode_neon64;
  codec->dec = base64_stream_decode_neon64;
  return 1;
 }
 if (flags & (1 << 3)) {
  codec->enc = base64_stream_encode_plain;
  codec->dec = base64_stream_decode_plain;
  return 1;
 }
 if (flags & (1 << 4)) {
  codec->enc = base64_stream_encode_ssse3;
  codec->dec = base64_stream_decode_ssse3;
  return 1;
 }
 if (flags & (1 << 5)) {
  codec->enc = base64_stream_encode_sse41;
  codec->dec = base64_stream_decode_sse41;
  return 1;
 }
 if (flags & (1 << 6)) {
  codec->enc = base64_stream_encode_sse42;
  codec->dec = base64_stream_decode_sse42;
  return 1;
 }
 if (flags & (1 << 7)) {
  codec->enc = base64_stream_encode_avx;
  codec->dec = base64_stream_decode_avx;
  return 1;
 }
 if (flags & (1 << 8)) {
  codec->enc = base64_stream_encode_avx512;
  codec->dec = base64_stream_decode_avx512;
  return 1;
 }
 return 0;
}

canonical_original_code:
static _Bool codec_choose_forced(struct codec *codec, int flags)
{
 if (!(flags & 0xFFFF)) {
  return 0;
 }
 if (flags & (1 << 0)) {
  codec->enc = base64_stream_encode_avx2;
  codec->dec = base64_stream_decode_avx2;
  return 1;
 }
 if (flags & (1 << 1)) {
  codec->enc = base64_stream_encode_neon32;
  codec->dec = base64_stream_decode_neon32;
  return 1;
 }
 if (flags & (1 << 2)) {
  codec->enc = base64_stream_encode_neon64;
  codec->dec = base64_stream_decode_neon64;
  return 1;
 }
 if (flags & (1 << 3)) {
  codec->enc = base64_stream_encode_plain;
  codec->dec = base64_stream_decode_plain;
  return 1;
 }
 if (flags & (1 << 4)) {
  codec->enc = base64_stream_encode_ssse3;
  codec->dec = base64_stream_decode_ssse3;
  return 1;
 }
 if (flags & (1 << 5)) {
  codec->enc = base64_stream_encode_sse41;
  codec->dec = base64_stream_decode_sse41;
  return 1;
 }
 if (flags & (1 << 6)) {
  codec->enc = base64_stream_encode_sse42;
  codec->dec = base64_stream_decode_sse42;
  return 1;
 }
 if (flags & (1 << 7)) {
  codec->enc = base64_stream_encode_avx;
  codec->dec = base64_stream_decode_avx;
  return 1;
 }
 if (flags & (1 << 8)) {
  codec->enc = base64_stream_encode_avx512;
  codec->dec = base64_stream_decode_avx512;
  return 1;
 }
 return 0;
}

variable_types: struct codec { void (*enc)(struct base64_state { int eof; int bytes; int flags; unsigned char carry; } *state, char *src, unsigned long srclen, char *out, unsigned long *outlen); int (*dec)(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen); } *

variable_types: flags int

user_defined_types: struct codec { void (*enc)(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen); int (*dec)(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen); }


decompiled_code:
__int64 __fastcall codec_choose(_QWORD *a1, __int16 a2)
{
__int64 result; // rax

result = codec_choose_forced(a1, a2);
if ( !(_BYTE)result )
{
result = codec_choose_arm(a1);
if ( !(_BYTE)result )
{
result = codec_choose_x86(a1);
if ( !(_BYTE)result )
{
*a1 = &base64_stream_encode_plain;
a1[1] = &base64_stream_decode_plain;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int16 a2)
{
__int64 result; // rax

result = func0(a1, a2);
if ( !(_BYTE)result )
{
result = func1(a1);
if ( !(_BYTE)result )
{
result = func2(a1);
if ( !(_BYTE)result )
{
*a1 = &base64_stream_encode_plain;
a1[1] = &base64_stream_decode_plain;
}
}
}
return result;
}

original_code:
void
codec_choose (struct codec *codec, int flags)
{
 if (codec_choose_forced(codec, flags)) {
  return;
 }
 if (codec_choose_arm(codec)) {
  return;
 }
 if (codec_choose_x86(codec)) {
  return;
 }
 codec->enc = base64_stream_encode_plain;
 codec->dec = base64_stream_decode_plain;
}

canonical_original_code:
void codec_choose(struct codec *codec, int flags)
{
 if (codec_choose_forced(codec, flags)) {
  return;
 }
 if (codec_choose_arm(codec)) {
  return;
 }
 if (codec_choose_x86(codec)) {
  return;
 }
 codec->enc = base64_stream_encode_plain;
 codec->dec = base64_stream_decode_plain;
}

user_defined_types: struct base64_state { int eof; int bytes; int flags; unsigned char carry; }


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

if ( !codec || (_BYTE)a2 )
result = codec_choose(&codec, a2);
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
*(_BYTE *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 8) = a2;
return result;
}

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

if ( !codec || (_BYTE)a2 )
result = codec_choose(&codec, a2);
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
*(_BYTE *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 8) = a2;
return result;
}

original_code:
void
base64_stream_encode_init (struct base64_state *state, int flags)
{
 if (codec.enc == ((void *)0) || flags & 0xFF) {
  codec_choose(&codec, flags);
 }
 state->eof = 0;
 state->bytes = 0;
 state->carry = 0;
 state->flags = flags;
}

canonical_original_code:
void base64_stream_encode_init(struct base64_state *state, int flags)
{
 if (codec.enc == ((void *)0) || flags & 0xFF) {
  codec_choose(&codec, flags);
 }
 state->eof = 0;
 state->bytes = 0;
 state->carry = 0;
 state->flags = flags;
}

variable_types: struct base64_state { int eof; int bytes; int flags; unsigned char carry; } *


decompiled_code:
__int64 base64_stream_encode()
{
return codec();
}

canonical_decompiled_code:
__int64 func1()
{
return codec();
}

original_code:
void
base64_stream_encode
 ( struct base64_state *state
 , const char *src
 , size_t srclen
 , char *out
 , size_t *outlen
 )
{
 codec.enc(state, src, srclen, out, outlen);
}

canonical_original_code:
void base64_stream_encode(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 codec.enc(state, src, srclen, out, outlen);
}

variable_types:
src
char *

variable_types:
srclen
unsigned long

variable_types:
out
char *

variable_types:
outlen
unsigned long *


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

if ( !qword_1B8 || (_WORD)a2 )
result = codec_choose(&codec, a2);
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
*(_BYTE *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 8) = a2;
return result;
}

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

if ( !qword_1B8 || (_WORD)a2 )
result = codec_choose(&codec, a2);
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
*(_BYTE *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 8) = a2;
return result;
}

original_code:
void
base64_stream_decode_init (struct base64_state *state, int flags)
{
 if (codec.dec == ((void *)0) || flags & 0xFFFF) {
  codec_choose(&codec, flags);
 }
 state->eof = 0;
 state->bytes = 0;
 state->carry = 0;
 state->flags = flags;
}

canonical_original_code:
void base64_stream_decode_init(struct base64_state *state, int flags)
{
 if (codec.dec == ((void *)0) || flags & 0xFFFF) {
  codec_choose(&codec, flags);
 }
 state->eof = 0;
 state->bytes = 0;
 state->carry = 0;
 state->flags = flags;
}


decompiled_code:
__int64 base64_stream_decode()
{
return qword_1B8();
}

canonical_decompiled_code:
__int64 func4()
{
return qword_1B8();
}

original_code:
int
base64_stream_decode
 ( struct base64_state *state
 , const char *src
 , size_t srclen
 , char *out
 , size_t *outlen
 )
{
 return codec.dec(state, src, srclen, out, outlen);
}

canonical_original_code:
int base64_stream_decode(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 return codec.dec(state, src, srclen, out, outlen);
}


decompiled_code:
__int64 __fastcall base64_decode(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax
_DWORD v8[14]; // [rsp+0h] [rbp-38h] BYREF

base64_stream_decode_init((__int64)v8, a5);
result = base64_stream_decode(v8, a1, a2, a3, a4);
if ( (_DWORD)result )
{
if ( v8[1] )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax
_DWORD v8[14]; // [rsp+0h] [rbp-38h] BYREF

func3((__int64)v8, a5);
result = func4(v8, a1, a2, a3, a4);
if ( (_DWORD)result )
{
if ( v8[1] )
result = 0LL;
}
return result;
}

original_code:
int
base64_decode
 ( const char *src
 , size_t srclen
 , char *out
 , size_t *outlen
 , int flags
 )
{
 int ret;
 struct base64_state state;
 base64_stream_decode_init(&state, flags);
 ret = base64_stream_decode(&state, src, srclen, out, outlen);
 if (ret && (state.bytes == 0)) {
  return ret;
 }
 return 0;
}

canonical_original_code:
int base64_decode(char *src, unsigned long srclen, char *out, unsigned long *outlen, int flags)
{
 int ret;
 struct base64_state state;
 base64_stream_decode_init(&state, flags);
 ret = base64_stream_decode(&state, src, srclen, out, outlen);
 if (ret && (state.bytes == 0)) {
  return ret;
 }
 return 0;
}

variable_types: ret int

variable_types: struct base64_state { int eof; int bytes; int flags; unsigned char carry; }


decompiled_code:
__int64 base64_stream_decode_avx()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_avx ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_avx(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
__int64 base64_stream_decode_ssse3()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_ssse3 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_ssse3(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
_BOOL8 __fastcall codec_supported(unsigned int a1)
{
char v2[14]; // [rsp+8h] [rbp-20h] BYREF
char v3[18]; // [rsp+16h] [rbp-12h] BYREF

return (unsigned int)base64_decode("aGVsbG8=", 8LL, v3, v2, a1) != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned int a1)
{
char v2[14]; // [rsp+8h] [rbp-20h] BYREF
char v3[18]; // [rsp+16h] [rbp-12h] BYREF

return (unsigned int)base64_decode("aGVsbG8=", 8LL, v3, v2, a1) != -1;
}

original_code:
int
codec_supported (int flags)
{
 char *a = "aGVsbG8=";
 char b[10];
 size_t outlen;
 return (base64_decode(a, strlen(a), b, &outlen, flags) != -1);
}

canonical_original_code:
int codec_supported(int flags)
{
 char *a = "aGVsbG8=";
 char b[10];
 unsigned long outlen;
 return (base64_decode(a, strlen(a), b, &outlen, flags) != -1);
}

variable_types:
a
char *

variable_types:
b
char [10]

variable_types:
outlen
unsigned long


decompiled_code:
__int64 base64_stream_decode_neon32()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_neon32 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_neon32(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
__int64 base64_stream_decode_avx2()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_avx2 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_avx2(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
__int64 base64_stream_decode_avx512()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_avx512 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_avx512(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
__int64 base64_stream_decode_sse41()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_sse41 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_sse41(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
__int64 base64_stream_decode_sse42()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_sse42 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_sse42(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
__int64 base64_stream_decode_neon64()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_neon64 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_neon64(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


printStart

decompiled_code:
int printStart()
{
puts("#include <stdint.h>");
printf("#define CHAR62 '%c'\n", (unsigned __int8)byte_4040DE);
printf("#define CHAR63 '%c'\n", (unsigned __int8)byte_4040DF);
return printf("#define CHARPAD '%c'\n", (unsigned __int8)padchar);
}

canonical_decompiled_code:
int func7()
{
puts("#include <stdint.h>");
printf("#define CHAR62 '%c'\n", (unsigned __int8)byte_4040DE);
printf("#define CHAR63 '%c'\n", (unsigned __int8)byte_4040DF);
return printf("#define CHARPAD '%c'\n", (unsigned __int8)padchar);
}

original_code:
static void printStart(void)
{
 printf("#include <stdint.h>\n");
 printf("#define CHAR62 '%c'\n", b64chars[62]);
 printf("#define CHAR63 '%c'\n", b64chars[63]);
 printf("#define CHARPAD '%c'\n", padchar);
}

canonical_original_code:
static void printStart()
{
 printf("#include <stdint.h>\n");
 printf("#define CHAR62 '%c'\n", b64chars[62]);
 printf("#define CHAR63 '%c'\n", b64chars[63]);
 printf("#define CHARPAD '%c'\n", padchar);
}


decompiled_code:
int __fastcall uint32_array_to_c_hex(__int64 a1, __int64 a2, const char *a3)
{
unsigned __int64 i; // rbx

printf("const uint32_t %s[%d] = {\n", a3, (unsigned int)a2);
for ( i = 1LL; ; ++i )
{
printf("0x%08x", *(unsigned int *)(a1 + 4 * i - 4));
if ( i == a2 )
break;
if ( i == 6 * (i / 6) )
puts(",");
else
printf(", ");
}
return puts("\n};");
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, __int64 a2, const char *a3)
{
unsigned __int64 i; // rbx

printf("const uint32_t %s[%d] = {\n", a3, (unsigned int)a2);
for ( i = 1LL; ; ++i )
{
printf("0x%08x", *(unsigned int *)(a1 + 4 * i - 4));
if ( i == a2 )
break;
if ( i == 6 * (i / 6) )
puts(",");
else
printf(", ");
}
return puts("\n};");
}

original_code:
void uint32_array_to_c_hex(const uint32_t* ary, size_t sz, const char* name)
{
 size_t i = 0;
 printf("const uint32_t %s[%d] = {\n", name, (int)sz);
 for (;;) {
  printf("0x%08" "x", ary[i]);
  ++i;
  if (i == sz)
   break;
  if (i % 6 == 0) {
   printf(",\n");
  } else {
   printf(", ");
  }
 }
 printf("\n};\n");
}

canonical_original_code:
void uint32_array_to_c_hex(unsigned int *ary, unsigned long sz, char *name)
{
 unsigned long i = 0;
 printf("const uint32_t %s[%d] = {\n", name, (int)sz);
 for (;;) {
  printf("0x%08" "x", ary[i]);
  ++i;
  if (i == sz)
   break;
  if (i % 6 == 0) {
   printf(",\n");
  } else {
   printf(", ");
  }
 }
 printf("\n};\n");
}

variable_types:
ary
unsigned int *

variable_types:
sz
unsigned long

variable_types:
name
char *

variable_types:
i
unsigned long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
__int64 i; // rax
__int64 j; // rax
__int64 k; // rax
__int64 l; // rax
__int64 m; // rax
__int64 n; // rax
__int64 ii; // rax
__int64 jj; // rax
int v13[258]; // [rsp+0h] [rbp-408h] BYREF

if ( argc == 2 )
{
v3 = argv[1];
if ( strlen(v3) != 3 )
{
fwrite("input must be a string of 3 characters '-', '.' or '_'\n", 1uLL, 0x37uLL, _bss_start);
exit(1);
}
fprintf(_bss_start, "fusing '%s' as replacements in base64 encoding\n", v3);
byte_4040DE = *v3;
byte_4040DF = v3[1];
padchar = v3[2];
}
printStart();
puts("\n\n#if BASE64_LITTLE_ENDIAN");
puts("\n\n/* SPECIAL DECODE TABLES FOR LITTLE ENDIAN (INTEL) CPUS */\n");
clearDecodeTable(v13);
for ( i = 0LL; i != 64; ++i )
v13[(unsigned __int8)b64chars[i]] = 4 * i;
uint32_array_to_c_hex((__int64)v13, 256LL, "base64_table_dec_32bit_d0");
puts("\n");
clearDecodeTable(v13);
for ( j = 0LL; j != 64; ++j )
v13[(unsigned __int8)b64chars[j]] = (unsigned __int16)((_WORD)j << 12) | ((unsigned int)j >> 4) & 3;
uint32_array_to_c_hex((__int64)v13, 256LL, "base64_table_dec_32bit_d1");
puts("\n");
clearDecodeTable(v13);
for ( k = 0LL; k != 64; ++k )
v13[(unsigned __int8)b64chars[k]] = ((_WORD)k << 6) & 0xF00 | ((_DWORD)k << 22) & 0xC00000;
uint32_array_to_c_hex((__int64)v13, 256LL, "base64_table_dec_32bit_d2");
puts("\n");
clearDecodeTable(v13);
for ( l = 0LL; l != 64; ++l )
v13[(unsigned __int8)b64chars[l]] = (_DWORD)l << 16;
uint32_array_to_c_hex((__int64)v13, 256LL, "base64_table_dec_32bit_d3");
puts("\n");
puts("#else");
puts("\n\n/* SPECIAL DECODE TABLES FOR BIG ENDIAN (IBM/MOTOROLA/SUN) CPUS */\n");
clearDecodeTable(v13);
for ( m = 0LL; m != 64; ++m )
v13[(unsigned __int8)b64chars[m]] = (_DWORD)m << 26;
uint32_array_to_c_hex((__int64)v13, 256LL, "base64_table_dec_32bit_d0");
puts("\n");
clearDecodeTable(v13);
for ( n = 0LL; n != 64; ++n )
v13[(unsigned __int8)b64chars[n]] = (_DWORD)n << 20;
uint32_array_to_c_hex((__int64)v13, 256LL, "base64_table_dec_32bit_d1");
puts("\n");
clearDecodeTable(v13);
for ( ii = 0LL; ii != 64; ++ii )
v13[(unsigned __int8)b64chars[ii]] = (_DWORD)ii << 14;
uint32_array_to_c_hex((__int64)v13, 256LL, "base64_table_dec_32bit_d2");
puts("\n");
clearDecodeTable(v13);
for ( jj = 0LL; jj != 64; ++jj )
v13[(unsigned __int8)b64chars[jj]] = (_DWORD)jj << 8;
uint32_array_to_c_hex((__int64)v13, 256LL, "base64_table_dec_32bit_d3");
puts("\n");
puts("#endif");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
__int64 i; // rax
__int64 j; // rax
__int64 k; // rax
__int64 l; // rax
__int64 m; // rax
__int64 n; // rax
__int64 ii; // rax
__int64 jj; // rax
int v13[258]; // [rsp+0h] [rbp-408h] BYREF

if ( argc == 2 )
{
v3 = argv[1];
if ( strlen(v3) != 3 )
{
fwrite("input must be a string of 3 characters '-', '.' or '_'\n", 1uLL, 0x37uLL, _bss_start);
exit(1);
}
fprintf(_bss_start, "fusing '%s' as replacements in base64 encoding\n", v3);
byte_4040DE = *v3;
byte_4040DF = v3[1];
padchar = v3[2];
}
func7();
puts("\n\n#if BASE64_LITTLE_ENDIAN");
puts("\n\n/* SPECIAL DECODE TABLES FOR LITTLE ENDIAN (INTEL) CPUS */\n");
clearDecodeTable(v13);
for ( i = 0LL; i != 64; ++i )
v13[(unsigned __int8)b64chars[i]] = 4 * i;
func8((__int64)v13, 256LL, "base64_table_dec_32bit_d0");
puts("\n");
clearDecodeTable(v13);
for ( j = 0LL; j != 64; ++j )
v13[(unsigned __int8)b64chars[j]] = (unsigned __int16)((_WORD)j << 12) | ((unsigned int)j >> 4) & 3;
func8((__int64)v13, 256LL, "base64_table_dec_32bit_d1");
puts("\n");
clearDecodeTable(v13);
for ( k = 0LL; k != 64; ++k )
v13[(unsigned __int8)b64chars[k]] = ((_WORD)k << 6) & 0xF00 | ((_DWORD)k << 22) & 0xC00000;
func8((__int64)v13, 256LL, "base64_table_dec_32bit_d2");
puts("\n");
clearDecodeTable(v13);
for ( l = 0LL; l != 64; ++l )
v13[(unsigned __int8)b64chars[l]] = (_DWORD)l << 16;
func8((__int64)v13, 256LL, "base64_table_dec_32bit_d3");
puts("\n");
puts("#else");
puts("\n\n/* SPECIAL DECODE TABLES FOR BIG ENDIAN (IBM/MOTOROLA/SUN) CPUS */\n");
clearDecodeTable(v13);
for ( m = 0LL; m != 64; ++m )
v13[(unsigned __int8)b64chars[m]] = (_DWORD)m << 26;
func8((__int64)v13, 256LL, "base64_table_dec_32bit_d0");
puts("\n");
clearDecodeTable(v13);
for ( n = 0LL; n != 64; ++n )
v13[(unsigned __int8)b64chars[n]] = (_DWORD)n << 20;
func8((__int64)v13, 256LL, "base64_table_dec_32bit_d1");
puts("\n");
clearDecodeTable(v13);
for ( ii = 0LL; ii != 64; ++ii )
v13[(unsigned __int8)b64chars[ii]] = (_DWORD)ii << 14;
func8((__int64)v13, 256LL, "base64_table_dec_32bit_d2");
puts("\n");
clearDecodeTable(v13);
for ( jj = 0LL; jj != 64; ++jj )
v13[(unsigned __int8)b64chars[jj]] = (_DWORD)jj << 8;
func8((__int64)v13, 256LL, "base64_table_dec_32bit_d3");
puts("\n");
puts("#endif");
return 0;
}

original_code:
int main(int argc, char** argv)
{
 uint32_t x;
 uint32_t i = 0;
 uint32_t ary[256];
 if (argc == 2) {
  uint8_t* replacements = (uint8_t*)argv[1];
  if (strlen((char*)replacements) != 3) {
   fprintf(stderr, "input must be a string of 3 characters '-', '.' or '_'\n");
   exit(1);
  }
  fprintf(stderr, "fusing '%s' as replacements in base64 encoding\n", replacements);
  b64chars[62] = replacements[0];
  b64chars[63] = replacements[1];
  padchar = replacements[2];
 }
 printStart();
 printf("\n\n#if BASE64_LITTLE_ENDIAN\n");
 printf("\n\n/* SPECIAL DECODE TABLES FOR LITTLE ENDIAN (INTEL) CPUS */\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 2;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d0");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = ((i & 0x30) >> 4) | ((i & 0x0F) << 12);
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d1");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = ((i & 0x03) << 22) | ((i & 0x3c) << 6);
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d2");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 16;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d3");
 printf("\n\n");
 printf("#else\n");
 printf("\n\n/* SPECIAL DECODE TABLES FOR BIG ENDIAN (IBM/MOTOROLA/SUN) CPUS */\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 26;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d0");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 20;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d1");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 14;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d2");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 8;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d3");
 printf("\n\n");
 printf("#endif\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned int x;
 unsigned int i = 0;
 unsigned int ary[256];
 if (argc == 2) {
  unsigned char *replacements = (uint8_t*)argv[1];
  if (strlen((char *)replacements) != 3) {
   fprintf(stderr, "input must be a string of 3 characters '-', '.' or '_'\n");
   exit(1);
  }
  fprintf(stderr, "fusing '%s' as replacements in base64 encoding\n", replacements);
  b64chars[62] = replacements[0];
  b64chars[63] = replacements[1];
  padchar = replacements[2];
 }
 printStart();
 printf("\n\n#if BASE64_LITTLE_ENDIAN\n");
 printf("\n\n/* SPECIAL DECODE TABLES FOR LITTLE ENDIAN (INTEL) CPUS */\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 2;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d0");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = ((i & 0x30) >> 4) | ((i & 0x0F) << 12);
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d1");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = ((i & 0x03) << 22) | ((i & 0x3c) << 6);
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d2");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 16;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d3");
 printf("\n\n");
 printf("#else\n");
 printf("\n\n/* SPECIAL DECODE TABLES FOR BIG ENDIAN (IBM/MOTOROLA/SUN) CPUS */\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 26;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d0");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 20;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d1");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 14;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d2");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 8;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d3");
 printf("\n\n");
 printf("#endif\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
x
unsigned int

variable_types:
i
unsigned int

variable_types:
ary
unsigned int [256]

variable_types:
replacements
unsigned char *


original_code:
static inline int
dec_loop_generic_32_inner (const uint8_t **s, uint8_t **o, size_t *rounds)
{
 const uint32_t str
  = base64_table_dec_32bit_d0[(*s)[0]]
  | base64_table_dec_32bit_d1[(*s)[1]]
  | base64_table_dec_32bit_d2[(*s)[2]]
  | base64_table_dec_32bit_d3[(*s)[3]];
 if (str & 0x80000000U) {
  return 0;
 }
 memcpy(*o, &str, sizeof (str));
 *s += 4;
 *o += 3;
 *rounds -= 1;
 return 1;
}

canonical_original_code:
static inline int dec_loop_generic_32_inner(unsigned char **s, unsigned char **o, unsigned long *rounds)
{
 unsigned int str = base64_table_dec_32bit_d0[(*s)[0]]
  | base64_table_dec_32bit_d1[(*s)[1]]
  | base64_table_dec_32bit_d2[(*s)[2]]
  | base64_table_dec_32bit_d3[(*s)[3]];
 if (str & 0x80000000U) {
  return 0;
 }
 memcpy(*o, &str, sizeof (str));
 *s += 4;
 *o += 3;
 *rounds -= 1;
 return 1;
}

variable_types:
s
unsigned char **

variable_types:
o
unsigned char **

variable_types:
rounds
unsigned long *

variable_types:
str
unsigned int


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

v2 = _byteswap_uint64(**a1);
**(_WORD **)a2 = base64_table_enc_12bit[v2 >> 52];
*(_WORD *)(*(_QWORD *)a2 + 2LL) = base64_table_enc_12bit[(v2 >> 40) & 0xFFF];
*(_WORD *)(*(_QWORD *)a2 + 4LL) = base64_table_enc_12bit[(v2 >> 28) & 0xFFF];
result = base64_table_enc_12bit[(v2 >> 16) & 0xFFF];
*(_WORD *)(*(_QWORD *)a2 + 6LL) = result;
*a1 = (unsigned __int64 *)((char *)*a1 + 6);
*(_QWORD *)a2 += 8LL;
return result;
}

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

v2 = _byteswap_uint64(**a1);
**(_WORD **)a2 = base64_table_enc_12bit[v2 >> 52];
*(_WORD *)(*(_QWORD *)a2 + 2LL) = base64_table_enc_12bit[(v2 >> 40) & 0xFFF];
*(_WORD *)(*(_QWORD *)a2 + 4LL) = base64_table_enc_12bit[(v2 >> 28) & 0xFFF];
result = base64_table_enc_12bit[(v2 >> 16) & 0xFFF];
*(_WORD *)(*(_QWORD *)a2 + 6LL) = result;
*a1 = (unsigned __int64 *)((char *)*a1 + 6);
*(_QWORD *)a2 += 8LL;
return result;
}

original_code:
static inline void
enc_loop_generic_64_inner (const uint8_t **s, uint8_t **o)
{
 uint64_t src;
 memcpy(&src, *s, sizeof (src));
 src = __builtin_bswap64(src);
 const size_t index0 = (src >> 52) & 0xFFFU;
 const size_t index1 = (src >> 40) & 0xFFFU;
 const size_t index2 = (src >> 28) & 0xFFFU;
 const size_t index3 = (src >> 16) & 0xFFFU;
 memcpy(*o + 0, base64_table_enc_12bit + index0, 2);
 memcpy(*o + 2, base64_table_enc_12bit + index1, 2);
 memcpy(*o + 4, base64_table_enc_12bit + index2, 2);
 memcpy(*o + 6, base64_table_enc_12bit + index3, 2);
 *s += 6;
 *o += 8;
}

canonical_original_code:
static inline void enc_loop_generic_64_inner(unsigned char **s, unsigned char **o)
{
 unsigned long src;
 memcpy(&src, *s, sizeof (src));
 src = __builtin_bswap64(src);
 unsigned long index0 = (src >> 52) & 0xFFFU;
 unsigned long index1 = (src >> 40) & 0xFFFU;
 unsigned long index2 = (src >> 28) & 0xFFFU;
 unsigned long index3 = (src >> 16) & 0xFFFU;
 memcpy(*o + 0, base64_table_enc_12bit + index0, 2);
 memcpy(*o + 2, base64_table_enc_12bit + index1, 2);
 memcpy(*o + 4, base64_table_enc_12bit + index2, 2);
 memcpy(*o + 6, base64_table_enc_12bit + index3, 2);
 *s += 6;
 *o += 8;
}

variable_types:
src
unsigned long


decompiled_code:
__int64 __fastcall enc_loop_generic_64(unsigned __int64 **a1, __int64 *a2, __int64 a3, _QWORD *a4)
{
__int64 v6; // rcx
unsigned __int64 v8; // rbx
__int64 result; // rax

v6 = *a2;
if ( (unsigned __int64)*a2 > 7 )
{
v8 = (v6 - 2) / 6uLL;
*a2 = v6 - 6 * v8;
*a4 += 8 * v8;
do
{
if ( v8 > 7 )
{
enc_loop_generic_64_inner(a1, a3);
enc_loop_generic_64_inner(a1, a3);
enc_loop_generic_64_inner(a1, a3);
enc_loop_generic_64_inner(a1, a3);
enc_loop_generic_64_inner(a1, a3);
enc_loop_generic_64_inner(a1, a3);
enc_loop_generic_64_inner(a1, a3);
result = enc_loop_generic_64_inner(a1, a3);
v8 -= 8LL;
}
else if ( v8 > 3 )
{
enc_loop_generic_64_inner(a1, a3);
enc_loop_generic_64_inner(a1, a3);
enc_loop_generic_64_inner(a1, a3);
result = enc_loop_generic_64_inner(a1, a3);
v8 -= 4LL;
}
else
{
if ( v8 <= 1 )
return enc_loop_generic_64_inner(a1, a3);
enc_loop_generic_64_inner(a1, a3);
result = enc_loop_generic_64_inner(a1, a3);
v8 -= 2LL;
}
}
while ( v8 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 **a1, __int64 *a2, __int64 a3, _QWORD *a4)
{
__int64 v6; // rcx
unsigned __int64 v8; // rbx
__int64 result; // rax

v6 = *a2;
if ( (unsigned __int64)*a2 > 7 )
{
v8 = (v6 - 2) / 6uLL;
*a2 = v6 - 6 * v8;
*a4 += 8 * v8;
do
{
if ( v8 > 7 )
{
func2(a1, a3);
func2(a1, a3);
func2(a1, a3);
func2(a1, a3);
func2(a1, a3);
func2(a1, a3);
func2(a1, a3);
result = func2(a1, a3);
v8 -= 8LL;
}
else if ( v8 > 3 )
{
func2(a1, a3);
func2(a1, a3);
func2(a1, a3);
result = func2(a1, a3);
v8 -= 4LL;
}
else
{
if ( v8 <= 1 )
return func2(a1, a3);
func2(a1, a3);
result = func2(a1, a3);
v8 -= 2LL;
}
}
while ( v8 );
}
return result;
}

original_code:
static inline void
enc_loop_generic_64 (const uint8_t **s, size_t *slen, uint8_t **o, size_t *olen)
{
 if (*slen < 8) {
  return;
 }
 size_t rounds = (*slen - 2) / 6;
 *slen -= rounds * 6;
 *olen += rounds * 8;
 do {
  if (rounds >= 8) {
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   rounds -= 8;
   continue;
  }
  if (rounds >= 4) {
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   rounds -= 4;
   continue;
  }
  if (rounds >= 2) {
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   rounds -= 2;
   continue;
  }
  enc_loop_generic_64_inner(s, o);
  break;
 } while (rounds > 0);
}

canonical_original_code:
static inline void enc_loop_generic_64(unsigned char **s, unsigned long *slen, unsigned char **o, unsigned long *olen)
{
 if (*slen < 8) {
  return;
 }
 unsigned long rounds = (*slen - 2) / 6;
 *slen -= rounds * 6;
 *olen += rounds * 8;
 do {
  if (rounds >= 8) {
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   rounds -= 8;
   continue;
  }
  if (rounds >= 4) {
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   rounds -= 4;
   continue;
  }
  if (rounds >= 2) {
   enc_loop_generic_64_inner(s, o);
   enc_loop_generic_64_inner(s, o);
   rounds -= 2;
   continue;
  }
  enc_loop_generic_64_inner(s, o);
  break;
 } while (rounds > 0);
}

variable_types:
slen
unsigned long *

variable_types:
olen
unsigned long *

variable_types:
rounds
unsigned long


decompiled_code:
void __fastcall buffer_free(void **a1)
{
free(*a1);
free(a1[1]);
}

canonical_decompiled_code:
void __fastcall func4(void **a1)
{
free(*a1);
free(a1[1]);
}

original_code:
static void
buffer_free (struct buffer *buf)
{
 free(buf->raw);
 free(buf->enc);
}

canonical_original_code:
static void buffer_free(struct buffer *buf)
{
 free(buf->raw);
 free(buf->enc);
}

variable_types: struct buffer { char *raw; char *enc; } *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // bl
int result; // eax
void *v5[2]; // [rsp+0h] [rbp-48h] BYREF
const char *v6[2]; // [rsp+10h] [rbp-38h] BYREF
FILE *stream; // [rsp+20h] [rbp-28h]
__int64 v8; // [rsp+28h] [rbp-20h]
__int64 v9; // [rsp+30h] [rbp-18h]

v6[0] = 0LL;
v9 = 0LL;
v6[1] = "stdin";
stream = stdin;
v8 = 76LL;
if ( (unsigned __int8)parse_opts(argc, (char **)argv, v6) )
{
if ( BYTE1(v9) )
{
usage(stdout, v6);
result = 0;
}
else if ( (unsigned __int8)buffer_alloc(v6, v5) )
{
if ( (_BYTE)v9 )
v3 = (unsigned int)decode(v6, (char **)v5) != 0;
else
v3 = encode((__int64)v6, v5);
buffer_free(v5);
fclose(stream);
fclose(stdout);
result = v3 ^ 1;
}
else
{
result = 1;
}
}
else
{
usage(stderr, v6);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // bl
int result; // eax
void *v5[2]; // [rsp+0h] [rbp-48h] BYREF
const char *v6[2]; // [rsp+10h] [rbp-38h] BYREF
FILE *stream; // [rsp+20h] [rbp-28h]
__int64 v8; // [rsp+28h] [rbp-20h]
__int64 v9; // [rsp+30h] [rbp-18h]

v6[0] = 0LL;
v9 = 0LL;
v6[1] = "stdin";
stream = stdin;
v8 = 76LL;
if ( (unsigned __int8)func2(argc, (char **)argv, v6) )
{
if ( BYTE1(v9) )
{
func0(stdout, v6);
result = 0;
}
else if ( (unsigned __int8)func3(v6, v5) )
{
if ( (_BYTE)v9 )
v3 = (unsigned int)func6(v6, (char **)v5) != 0;
else
v3 = func10((__int64)v6, v5);
func4(v5);
fclose(stream);
fclose(stdout);
result = v3 ^ 1;
}
else
{
result = 1;
}
}
else
{
func0(stderr, v6);
result = 1;
}
return result;
}


repo: aklomp/thumbstrip

decompiled_code:
size_t print_usage()
{
return fwrite(
"Creates a strip of thumbnail images, and an optional mapfile.\n"
" -o <outfile> image file to create, default 'pnm:-'\n"
" -m <mapfile> map file to create, optional\n"
" -h <height> height of a row in pixels, default 28\n"
" -s <space> space between thumbnails in pixels, default 4\n"
" -w <width> width of a row in pixels, default 732\n"
" -v be verbose\n"
" -? print this help screen\n",
1uLL,
0x194uLL,
stderr);
}

canonical_decompiled_code:
size_t func7()
{
return fwrite(
"Creates a strip of thumbnail images, and an optional mapfile.\n"
" -o <outfile> image file to create, default 'pnm:-'\n"
" -m <mapfile> map file to create, optional\n"
" -h <height> height of a row in pixels, default 28\n"
" -s <space> space between thumbnails in pixels, default 4\n"
" -w <width> width of a row in pixels, default 732\n"
" -v be verbose\n"
" -? print this help screen\n",
1uLL,
0x194uLL,
stderr);
}

original_code:
static void
print_usage (void)
{
 fputs(
 "Creates a strip of thumbnail images, and an optional mapfile.\n"
 "  -o <outfile>   image file to create, default '" "pnm:-" "'\n"
 "  -m <mapfile>   map file to create, optional\n"
 "  -h <height>    height of a row in pixels, default " "28" "\n"
 "  -s <space>     space between thumbnails in pixels, default " "4" "\n"
 "  -w <width>     width of a row in pixels, default " "732" "\n"
 "  -v             be verbose\n"
 "  -?             print this help screen\n"
 , stderr);
}

canonical_original_code:
static void print_usage()
{
 fputs(
 "Creates a strip of thumbnail images, and an optional mapfile.\n"
 "  -o <outfile>   image file to create, default '" "pnm:-" "'\n"
 "  -m <mapfile>   map file to create, optional\n"
 "  -h <height>    height of a row in pixels, default " "28" "\n"
 "  -s <space>     space between thumbnails in pixels, default " "4" "\n"
 "  -w <width>     width of a row in pixels, default " "732" "\n"
 "  -v             be verbose\n"
 "  -?             print this help screen\n"
 , stderr);
}


repo: aknj/lu

decompiled_code:
int __fastcall print_matrix(unsigned __int64 *a1, double a2)
{
unsigned __int64 i; // r12
unsigned __int64 j; // rbx
int result; // eax

for ( i = 0LL; *a1 > i; ++i )
{
for ( j = 0LL; a1[1] > j; ++j )
{
gsl_matrix_get();
printf("\t[ %g ] ", a2);
}
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(unsigned __int64 *a1, double a2)
{
unsigned __int64 i; // r12
unsigned __int64 j; // rbx
int result; // eax

for ( i = 0LL; *a1 > i; ++i )
{
for ( j = 0LL; a1[1] > j; ++j )
{
gsl_matrix_get();
printf("\t[ %g ] ", a2);
}
result = putchar(10);
}
return result;
}

original_code:
void print_matrix(gsl_matrix *m) {
    int i;
    int j;
    for(i = 0; i < m->size1; i++) {
        for(j = 0; j < m->size2; j++) {
            printf("\t[ %g ] ", gsl_matrix_get(m, i, j));
        }
        printf("\n");
    }
}

canonical_original_code:
void print_matrix(struct gsl_matrix *m) {
    int i;
    int j;
    for(i = 0; i < m->size1; i++) {
        for(j = 0; j < m->size2; j++) {
            printf("\t[ %g ] ", gsl_matrix_get(m, i, j));
        }
        printf("\n");
    }
}

variable_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: i int

variable_types: j int

user_defined_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; }


sigchld

repo: akrennmair/tuitest

decompiled_code:
void sigchld()
{
getout = 1;
}

canonical_decompiled_code:
void func0()
{
getout = 1;
}

original_code:
static void sigchld(int signo) {
 getout = 1;
}

variable_types: signo int


decompiled_code:
__int64 tt_init()
{
__int16 v0; // r13
int i; // er12
int j; // ebx
__int16 v3; // bp
__int64 result; // rax

signal(17, (__sighandler_t)sigchld);
initscr();
noecho();
start_color();
raw();
nodelay(stdscr, 1);
keypad(stdscr, 1);
v0 = 7;
for ( i = 0; i != 8; ++i )
{
v3 = v0;
for ( j = 1; ; ++j )
{
if ( i != 7 || j != 1 )
{
init_pair(v3, i, j - 1);
if ( j > 7 )
break;
}
v3 += 8;
}
--v0;
}
wrefresh(stdscr);
term_win = newwin(27, 82, 1, 1);
wattrset(term_win, 16128);
wborder(term_win, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
mvwprintw(term_win, 0, 27, "[ Application Under Test ]");
wrefresh(term_win);
result = rote_vt_create(25LL, 80LL);
rt = result;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int16 v0; // r13
int i; // er12
int j; // ebx
__int16 v3; // bp
__int64 result; // rax

signal(17, (__sighandler_t)sigchld);
initscr();
noecho();
start_color();
raw();
nodelay(stdscr, 1);
keypad(stdscr, 1);
v0 = 7;
for ( i = 0; i != 8; ++i )
{
v3 = v0;
for ( j = 1; ; ++j )
{
if ( i != 7 || j != 1 )
{
init_pair(v3, i, j - 1);
if ( j > 7 )
break;
}
v3 += 8;
}
--v0;
}
wrefresh(stdscr);
term_win = newwin(27, 82, 1, 1);
wattrset(term_win, 16128);
wborder(term_win, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
mvwprintw(term_win, 0, 27, "[ Application Under Test ]");
wrefresh(term_win);
result = rote_vt_create(25LL, 80LL);
rt = result;
return result;
}

original_code:
void tt_init() {
 int i, j;
 signal(17, sigchld);
 initscr();
 noecho();
 start_color();
 raw();
 nodelay(stdscr, 1);
 keypad(stdscr, 1);
 for (i = 0; i < 8; i++) {
  for (j = 0; j < 8; j++) {
   if (i != 7 || j != 0)
    init_pair(j*8+7-i, i, j);
  }
 }
 wrefresh(stdscr);
 term_win = newwin(25 +2,80 +2,1,1);
 wattrset(term_win, (((chtype)(((7*8+7-0))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
 wborder(term_win, 0, 0, 0, 0, 0, 0, 0, 0);
 mvwprintw(term_win, 0, 27, "[ Application Under Test ]");
 wrefresh(term_win);
 rt = rote_vt_create(25,80);
}

canonical_original_code:
void tt_init() {
 int i; int j;
 signal(17, sigchld);
 initscr();
 noecho();
 start_color();
 raw();
 nodelay(stdscr, 1);
 keypad(stdscr, 1);
 for (i = 0; i < 8; i++) {
  for (j = 0; j < 8; j++) {
   if (i != 7 || j != 0)
    init_pair(j*8+7-i, i, j);
  }
 }
 wrefresh(stdscr);
 term_win = newwin(25 +2,80 +2,1,1);
 wattrset(term_win, (((chtype)(((7*8+7-0))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
 wborder(term_win, 0, 0, 0, 0, 0, 0, 0, 0);
 mvwprintw(term_win, 0, 27, "[ Application Under Test ]");
 wrefresh(term_win);
 rt = rote_vt_create(25,80);
}


decompiled_code:
int tt_close()
{
waitpid(pid, 0LL, 1);
rote_vt_destroy(rt);
rt = 0LL;
return endwin();
}

canonical_decompiled_code:
int func2()
{
waitpid(pid, 0LL, 1);
rote_vt_destroy(rt);
rt = 0LL;
return endwin();
}

original_code:
void tt_close() {
 waitpid(pid, ((void *)0), 1);
 rote_vt_destroy(rt);
 rt = ((void *)0);
 endwin();
}


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

result = rote_vt_forkpty(rt, a1);
pid = result;
return result;
}

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

result = rote_vt_forkpty(rt, a1);
pid = result;
return result;
}

original_code:
void tt_run(const char * cmdline) {
 pid = rote_vt_forkpty(rt, cmdline);
}

canonical_original_code:
void tt_run(char *cmdline) {
 pid = rote_vt_forkpty(rt, cmdline);
}

variable_types:
cmdline
char *


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
return fprintf(stderr, "%s: usage: %s [-f] [-x] <script> <command>\n\n", a1, a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "%s: usage: %s [-f] [-x] <script> <command>\n\n", a1, a1);
}

original_code:
void usage(char * argv0) {
 fprintf(stderr, "%s: usage: %s [-f] [-x] <script> <command>\n\n", argv0, argv0);
}

canonical_original_code:
void usage(char *argv0) {
 fprintf(stderr, "%s: usage: %s [-f] [-x] <script> <command>\n\n", argv0, argv0);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int result; // eax
const char *v5; // rbp
const char *v6; // rbx
int *v7; // rax
char *v8; // rax

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "fx");
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'f':
tt_set_fastmode(1LL);
break;
case 'x':
tt_set_xmloutput(1LL);
break;
case '?':
fprintf(stderr, "Error: unknown option -%c\n", (unsigned int)optopt);
usage(*argv);
return 1;
}
}
if ( argc - optind <= 1 )
{
usage(*argv);
result = 1;
}
else
{
v5 = argv[optind];
v6 = argv[optind + 1];
tt_init();
if ( (unsigned int)tt_open_script(v5) )
{
tt_record_run(v6);
tt_run(v6);
tt_record();
tt_close_script();
tt_close();
result = 0;
}
else
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "Error: couldn't open `%s': %s\n", v5, v8);
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int result; // eax
const char *v5; // rbp
const char *v6; // rbx
int *v7; // rax
char *v8; // rax

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "fx");
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'f':
tt_set_fastmode(1LL);
break;
case 'x':
tt_set_xmloutput(1LL);
break;
case '?':
fprintf(stderr, "Error: unknown option -%c\n", (unsigned int)optopt);
func0(*argv);
return 1;
}
}
if ( argc - optind <= 1 )
{
func0(*argv);
result = 1;
}
else
{
v5 = argv[optind];
v6 = argv[optind + 1];
tt_init();
if ( (unsigned int)tt_open_script(v5) )
{
tt_record_run(v6);
tt_run(v6);
tt_record();
tt_close_script();
tt_close();
result = 0;
}
else
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "Error: couldn't open `%s': %s\n", v5, v8);
result = 1;
}
}
return result;
}

original_code:
int main(int argc, char * argv[]) {
 const char * script;
 const char * cmd;
 int c;
 while ((c = getopt(argc, argv, "fx")) != -1) {
  switch (c) {
   case 'f':
    tt_set_fastmode(1);
    break;
   case 'x':
    tt_set_xmloutput(1);
    break;
   case '?':
    fprintf(stderr, "Error: unknown option -%c\n", optopt);
    usage(argv[0]);
    return 1;
  }
 }
 if ((argc - optind) < 2) {
  usage(argv[0]);
  return 1;
 }
 script = argv[optind];
 cmd = argv[optind+1];
 tt_init();
 if (!tt_open_script(script)) {
  fprintf(stderr, "Error: couldn't open `%s': %s\n", script, strerror((*__errno_location ())));
  return 1;
 }
 tt_record_run(cmd);
 tt_run(cmd);
 tt_record();
 tt_close_script();
 tt_close();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 char *script;
 char *cmd;
 int c;
 while ((c = getopt(argc, argv, "fx")) != -1) {
  switch (c) {
   case 'f':
    tt_set_fastmode(1);
    break;
   case 'x':
    tt_set_xmloutput(1);
    break;
   case '?':
    fprintf(stderr, "Error: unknown option -%c\n", optopt);
    usage(argv[0]);
    return 1;
  }
 }
 if ((argc - optind) < 2) {
  usage(argv[0]);
  return 1;
 }
 script = argv[optind];
 cmd = argv[optind+1];
 tt_init();
 if (!tt_open_script(script)) {
  fprintf(stderr, "Error: couldn't open `%s': %s\n", script, strerror((*__errno_location ())));
  return 1;
 }
 tt_record_run(cmd);
 tt_run(cmd);
 tt_record();
 tt_close_script();
 tt_close();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
script
char *

variable_types:
cmd
char *

variable_types: c int


decompiled_code:
__int64 __fastcall ensure_printable(unsigned int a1)
{
__int64 result; // rax

result = 32LL;
if ( (unsigned __int8)a1 >= 0x20u )
result = a1;
return result;
}

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

result = 32LL;
if ( (unsigned __int8)a1 >= 0x20u )
result = a1;
return result;
}

original_code:
static inline unsigned char ensure_printable(unsigned char ch)
                                        { return ch >= 32 ? ch : 32; }

variable_types:
ch
unsigned char

return_type: unsigned char


decompiled_code:
void __fastcall rote_vt_destroy(void *ptr)
{
__int64 v1; // rbx

if ( ptr )
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 6));
if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 1) + 8 * v1++));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v1; // rbx

if ( ptr )
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 6));
if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 1) + 8 * v1++));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void rote_vt_destroy(RoteTerm *rt) {
   int i;
   if (!rt) return;
   free(rt->pd);
   free(rt->line_dirty);
   for (i = 0; i < rt->rows; i++) free(rt->cells[i]);
   free(rt->cells);
   free(rt);
}

canonical_original_code:
void rote_vt_destroy(struct RoteTerm_ *rt) {
   int i;
   if (!rt) return;
   free(rt->pd);
   free(rt->line_dirty);
   for (i = 0; i < rt->rows; i++) free(rt->cells[i]);
   free(rt->cells);
   free(rt);
}

variable_types: struct RoteTerm_ { int rows; struct RoteCell_ { unsigned char ch; unsigned char attr; } **cells; int crow; unsigned char curattr; int childpid; struct RoteTermPrivate_ { _Bool escaped; _Bool graphmode; int scrolltop; int saved_x; char esbuf[128]; int esbuf_len; int pty; int (*handler)(struct RoteTerm_ *rt, char *es); } *pd; _Bool curpos_dirty; _Bool *line_dirty; } *

user_defined_types: struct RoteTerm_ { int rows; struct RoteCell_ **cells; int crow; unsigned char curattr; int childpid; struct RoteTermPrivate_ *pd; _Bool curpos_dirty; _Bool *line_dirty; }


decompiled_code:
int __fastcall rote_vt_forkpty(__int64 a1, const char *a2)
{
int result; // eax
struct winsize winp; // [rsp+8h] [rbp-20h] BYREF

winp.ws_row = *(_DWORD *)a1;
winp.ws_col = *(_DWORD *)(a1 + 4);
winp.ws_ypixel = 0;
winp.ws_xpixel = 0;
result = forkpty((int *)(*(_QWORD *)(a1 + 32) + 152LL), 0LL, 0LL, &winp);
if ( result < 0 )
return -1;
if ( !result )
{
setenv("TERM", "linux", 1);
execl("/bin/sh", "/bin/sh", "-c", a2, 0LL);
fprintf(stderr, "\nexecl() failed.\nCommand: '%s'\n", a2);
exit(127);
}
*(_DWORD *)(a1 + 28) = result;
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, const char *a2)
{
int result; // eax
struct winsize winp; // [rsp+8h] [rbp-20h] BYREF

winp.ws_row = *(_DWORD *)a1;
winp.ws_col = *(_DWORD *)(a1 + 4);
winp.ws_ypixel = 0;
winp.ws_xpixel = 0;
result = forkpty((int *)(*(_QWORD *)(a1 + 32) + 152LL), 0LL, 0LL, &winp);
if ( result < 0 )
return -1;
if ( !result )
{
setenv("TERM", "linux", 1);
execl("/bin/sh", "/bin/sh", "-c", a2, 0LL);
fprintf(stderr, "\nexecl() failed.\nCommand: '%s'\n", a2);
exit(127);
}
*(_DWORD *)(a1 + 28) = result;
return result;
}

original_code:
pid_t rote_vt_forkpty(RoteTerm *rt, const char *command) {
   struct winsize ws;
   pid_t childpid;
   ws.ws_row = rt->rows;
   ws.ws_col = rt->cols;
   ws.ws_xpixel = ws.ws_ypixel = 0;
   childpid = forkpty(&rt->pd->pty, ((void *)0), ((void *)0), &ws);
   if (childpid < 0) return -1;
   if (childpid == 0) {
      setenv("TERM", "linux", 1);
      execl("/bin/sh", "/bin/sh", "-c", command, ((void *)0));
      fprintf(stderr, "\nexecl() failed.\nCommand: '%s'\n", command);
      exit(127);
   }
   rt->childpid = childpid;
   return childpid;
}

canonical_original_code:
int rote_vt_forkpty(struct RoteTerm_ *rt, char *command) {
   struct winsize ws;
   int childpid;
   ws.ws_row = rt->rows;
   ws.ws_col = rt->cols;
   ws.ws_xpixel = ws.ws_ypixel = 0;
   childpid = forkpty(&rt->pd->pty, ((void *)0), ((void *)0), &ws);
   if (childpid < 0) return -1;
   if (childpid == 0) {
      setenv("TERM", "linux", 1);
      execl("/bin/sh", "/bin/sh", "-c", command, ((void *)0));
      fprintf(stderr, "\nexecl() failed.\nCommand: '%s'\n", command);
      exit(127);
   }
   rt->childpid = childpid;
   return childpid;
}

variable_types:
command
char *

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }

variable_types: childpid int

user_defined_types: struct RoteTermPrivate_ { _Bool escaped; _Bool graphmode; int scrolltop; int saved_x; char esbuf[128]; int esbuf_len; int pty; int (*handler)(struct RoteTerm_ *rt, char *es); }

user_defined_types: struct RoteCell_ { unsigned char ch; unsigned char attr; }


decompiled_code:
__int64 __fastcall rote_vt_forsake_child(__int64 a1)
{
int v2; // edi
__int64 result; // rax

v2 = *(_DWORD *)(*(_QWORD *)(a1 + 32) + 152LL);
if ( v2 >= 0 )
close(v2);
result = *(_QWORD *)(a1 + 32);
*(_DWORD *)(result + 152) = -1;
*(_DWORD *)(a1 + 28) = 0;
return result;
}

original_code:
void rote_vt_forsake_child(RoteTerm *rt) {
   if (rt->pd->pty >= 0) close(rt->pd->pty);
   rt->pd->pty = -1;
   rt->childpid = 0;
}

canonical_original_code:
void rote_vt_forsake_child(struct RoteTerm_ *rt) {
   if (rt->pd->pty >= 0) close(rt->pd->pty);
   rt->pd->pty = -1;
   rt->childpid = 0;
}


decompiled_code:
int __fastcall rote_vt_update(__int64 a1)
{
__int64 v1; // rax
int v3; // ebp
int v4; // edi
_BYTE v6[512]; // [rsp-200h] [rbp-2A8h] BYREF
struct timeval timeout; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

v1 = *(_QWORD *)(a1 + 32);
if ( *(int *)(v1 + 152) >= 0 )
{
v3 = 5;
do
{
memset(&readfds, 0, sizeof(readfds));
v4 = *(_DWORD *)(*(_QWORD *)(a1 + 32) + 152LL);
readfds.fds_bits[v4 / 64] |= 1LL << (v4 % 64);
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
LODWORD(v1) = select(v4 + 1, &readfds, 0LL, 0LL, &timeout);
if ( (int)v1 <= 0 )
break;
LODWORD(v1) = read(*(_DWORD *)(*(_QWORD *)(a1 + 32) + 152LL), v6, 0x200uLL);
if ( (int)v1 <= 0 )
break;
LODWORD(v1) = rote_vt_inject(a1, v6, (unsigned int)v1);
--v3;
}
while ( v3 );
}
return v1;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
__int64 v1; // rax
int v3; // ebp
int v4; // edi
_BYTE v6[512]; // [rsp-200h] [rbp-2A8h] BYREF
struct timeval timeout; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

v1 = *(_QWORD *)(a1 + 32);
if ( *(int *)(v1 + 152) >= 0 )
{
v3 = 5;
do
{
memset(&readfds, 0, sizeof(readfds));
v4 = *(_DWORD *)(*(_QWORD *)(a1 + 32) + 152LL);
readfds.fds_bits[v4 / 64] |= 1LL << (v4 % 64);
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
LODWORD(v1) = select(v4 + 1, &readfds, 0LL, 0LL, &timeout);
if ( (int)v1 <= 0 )
break;
LODWORD(v1) = read(*(_DWORD *)(*(_QWORD *)(a1 + 32) + 152LL), v6, 0x200uLL);
if ( (int)v1 <= 0 )
break;
LODWORD(v1) = rote_vt_inject(a1, v6, (unsigned int)v1);
--v3;
}
while ( v3 );
}
return v1;
}

original_code:
void rote_vt_update(RoteTerm *rt) {
   fd_set ifs;
   struct timeval tvzero;
   char buf[512];
   int bytesread;
   int n = 5;
   if (rt->pd->pty < 0) return;
   while (n--) {
      do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&ifs)->__fds_bits)[0]) : "memory"); } while (0); ((void) (((&ifs)->__fds_bits)[((rt->pd->pty) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((rt->pd->pty) % (8 * (int) sizeof (__fd_mask)))))));
      tvzero.tv_sec = 0; tvzero.tv_usec = 0;
      if (select(rt->pd->pty + 1, &ifs, ((void *)0), ((void *)0), &tvzero) <= 0)
         return;
      bytesread = read(rt->pd->pty, buf, 512);
      if (bytesread <= 0) return;
      rote_vt_inject(rt, buf, bytesread);
   }
}

canonical_original_code:
void rote_vt_update(struct RoteTerm_ *rt) {
   struct fd_set ifs;
   struct timeval tvzero;
   char buf[512];
   int bytesread;
   int n = 5;
   if (rt->pd->pty < 0) return;
   while (n--) {
      do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&ifs)->__fds_bits)[0]) : "memory"); } while (0); ((void) (((&ifs)->__fds_bits)[((rt->pd->pty) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((rt->pd->pty) % (8 * (int) sizeof (__fd_mask)))))));
      tvzero.tv_sec = 0; tvzero.tv_usec = 0;
      if (select(rt->pd->pty + 1, &ifs, ((void *)0), ((void *)0), &tvzero) <= 0)
         return;
      bytesread = read(rt->pd->pty, buf, 512);
      if (bytesread <= 0) return;
      rote_vt_inject(rt, buf, bytesread);
   }
}

variable_types:
ifs
struct fd_set { long __fds_bits[-1]; }

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

variable_types:
buf
char [512]

variable_types: bytesread int

variable_types: n int


decompiled_code:
ssize_t __fastcall rote_vt_write(__int64 a1, char *a2, __int64 a3)
{
char *v3; // rbp
int v4; // ebx
ssize_t result; // rax
size_t v6; // rax

v3 = a2;
v4 = a3;
result = *(_QWORD *)(a1 + 32);
if ( *(int *)(result + 152) < 0 )
return rote_vt_inject(a1, a2, a3);
if ( (int)a3 > 0 )
{
while ( 1 )
{
result = write(*(_DWORD *)(*(_QWORD *)(a1 + 32) + 152LL), v3, v4);
if ( (int)result < 0 )
break;
v3 += (int)result;
v4 -= result;
if ( v4 <= 0 )
return result;
}
v6 = strlen(errormsg_0);
result = rote_vt_inject(a1, errormsg_0, v6);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func7(__int64 a1, char *a2, __int64 a3)
{
char *v3; // rbp
int v4; // ebx
ssize_t result; // rax
size_t v6; // rax

v3 = a2;
v4 = a3;
result = *(_QWORD *)(a1 + 32);
if ( *(int *)(result + 152) < 0 )
return rote_vt_inject(a1, a2, a3);
if ( (int)a3 > 0 )
{
while ( 1 )
{
result = write(*(_DWORD *)(*(_QWORD *)(a1 + 32) + 152LL), v3, v4);
if ( (int)result < 0 )
break;
v3 += (int)result;
v4 -= result;
if ( v4 <= 0 )
return result;
}
v6 = strlen(errormsg_0);
result = rote_vt_inject(a1, errormsg_0, v6);
}
return result;
}

original_code:
void rote_vt_write(RoteTerm *rt, const char *data, int len) {
   if (rt->pd->pty < 0) {
      rote_vt_inject(rt, data, len);
      return;
   }
   while (len > 0) {
      int byteswritten = write(rt->pd->pty, data, len);
      if (byteswritten < 0) {
         static char errormsg[] = "\n(ROTE: pty write() error)\n";
         rote_vt_inject(rt, errormsg, strlen(errormsg));
         return;
      }
      data += byteswritten;
      len -= byteswritten;
   }
}

canonical_original_code:
void rote_vt_write(struct RoteTerm_ *rt, char *data, int len) {
   if (rt->pd->pty < 0) {
      rote_vt_inject(rt, data, len);
      return;
   }
   while (len > 0) {
      int byteswritten = write(rt->pd->pty, data, len);
      if (byteswritten < 0) {
         static char errormsg[] = "\n(ROTE: pty write() error)\n";
         rote_vt_inject(rt, errormsg, strlen(errormsg));
         return;
      }
      data += byteswritten;
      len -= byteswritten;
   }
}

variable_types:
data
char *

variable_types: len int

variable_types: byteswritten int

variable_types:
errormsg
char []


decompiled_code:
__int64 __fastcall rote_vt_install_handler(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 32);
*(_QWORD *)(result + 160) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 32);
*(_QWORD *)(result + 160) = a2;
return result;
}

original_code:
void rote_vt_install_handler(RoteTerm *rt, rote_es_handler_t handler) {
   rt->pd->handler = handler;
}

canonical_original_code:
void rote_vt_install_handler(struct RoteTerm_ *rt, int (*handler)(struct RoteTerm_ *rt, char *es)) {
   rt->pd->handler = handler;
}

variable_types:
handler
int (*)(struct RoteTerm_ *rt, char *es)


decompiled_code:
void *__fastcall rote_vt_take_snapshot(__int64 a1)
{
int v1; // er12
int v2; // er13
char *v3; // rax
void *v4; // r15
__int64 v5; // r13
char *v6; // rbp
__int64 v7; // rbx

v1 = 2 * *(_DWORD *)(a1 + 4);
v2 = *(_DWORD *)a1;
v3 = (char *)malloc(v1 * *(_DWORD *)a1);
v4 = v3;
if ( v2 > 0 )
{
v5 = 8LL * (unsigned int)v2;
v6 = v3;
v7 = 0LL;
do
{
memcpy(v6, *(const void **)(*(_QWORD *)(a1 + 8) + v7), v1);
v6 += v1;
v7 += 8LL;
}
while ( v7 != v5 );
}
return v4;
}

original_code:
void *rote_vt_take_snapshot(RoteTerm *rt) {
   int i;
   int bytes_per_row = sizeof(RoteCell) * rt->cols;
   void *buf = malloc(bytes_per_row * rt->rows);
   void *ptr = buf;
   for (i = 0; i < rt->rows; i++, ptr += bytes_per_row)
      memcpy(ptr, rt->cells[i], bytes_per_row);
   return buf;
}

canonical_original_code:
void *rote_vt_take_snapshot(struct RoteTerm_ *rt) {
   int i;
   int bytes_per_row = sizeof(RoteCell) * rt->cols;
   void *buf = malloc(bytes_per_row * rt->rows);
   void *ptr = buf;
   for (i = 0; i < rt->rows; i++, ptr += bytes_per_row)
      memcpy(ptr, rt->cells[i], bytes_per_row);
   return buf;
}

variable_types: i int

variable_types:
buf
void *

variable_types:
ptr
void *

return_type: void *


decompiled_code:
void *__fastcall rote_vt_restore_snapshot(__int64 a1, char *a2)
{
void *result; // rax
__int64 v4; // rbx
size_t v5; // r13

result = (void *)*(unsigned int *)(a1 + 4);
if ( *(int *)a1 > 0 )
{
v4 = 0LL;
v5 = 2 * (int)result;
do
{
*(_BYTE *)(*(_QWORD *)(a1 + 48) + v4) = 1;
result = memcpy(*(void **)(*(_QWORD *)(a1 + 8) + 8 * v4), a2, v5);
a2 += v5;
++v4;
}
while ( *(_DWORD *)a1 > (int)v4 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1, char *a2)
{
void *result; // rax
__int64 v4; // rbx
size_t v5; // r13

result = (void *)*(unsigned int *)(a1 + 4);
if ( *(int *)a1 > 0 )
{
v4 = 0LL;
v5 = 2 * (int)result;
do
{
*(_BYTE *)(*(_QWORD *)(a1 + 48) + v4) = 1;
result = memcpy(*(void **)(*(_QWORD *)(a1 + 8) + 8 * v4), a2, v5);
a2 += v5;
++v4;
}
while ( *(_DWORD *)a1 > (int)v4 );
}
return result;
}

original_code:
void rote_vt_restore_snapshot(RoteTerm *rt, void *snapbuf) {
   int i;
   int bytes_per_row = sizeof(RoteCell) * rt->cols;
   for (i = 0; i < rt->rows; i++, snapbuf += bytes_per_row) {
      rt->line_dirty[i] = 1;
      memcpy(rt->cells[i], snapbuf, bytes_per_row);
   }
}

canonical_original_code:
void rote_vt_restore_snapshot(struct RoteTerm_ *rt, void *snapbuf) {
   int i;
   int bytes_per_row = sizeof(RoteCell) * rt->cols;
   for (i = 0; i < rt->rows; i++, snapbuf += bytes_per_row) {
      rt->line_dirty[i] = 1;
      memcpy(rt->cells[i], snapbuf, bytes_per_row);
   }
}

variable_types: struct RoteTerm_ { int rows; struct RoteCell_ { unsigned char ch; unsigned char attr; } **cells; int crow; unsigned char curattr; int childpid; struct RoteTermPrivate_ { _Bool escaped; _Bool graphmode; int scrolltop; int saved_x; char esbuf[128]; int esbuf_len; int pty; int (*handler)(struct RoteTerm_ *rt, char *es); } *pd; _Bool curpos_dirty; _Bool *line_dirty; } *

variable_types:
snapbuf
void *


decompiled_code:
__int64 __fastcall rote_vt_get_pty_fd(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 32) + 152LL);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 32) + 152LL);
}

original_code:
int rote_vt_get_pty_fd(RoteTerm *rt) {
   return rt->pd->pty;
}

canonical_original_code:
int rote_vt_get_pty_fd(struct RoteTerm_ *rt) {
   return rt->pd->pty;
}


decompiled_code:
__int64 __fastcall tt_take_snapshot(__int64 a1)
{
__int64 i; // rcx
__int64 result; // rax

for ( i = 0LL; i != 200; i += 8LL )
{
for ( result = 0LL; result != 80; ++result )
*(_BYTE *)(a1 + result) = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)(rt + 8LL) + i) + 2 * result);
a1 += 80LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 i; // rcx
__int64 result; // rax

for ( i = 0LL; i != 200; i += 8LL )
{
for ( result = 0LL; result != 80; ++result )
*(_BYTE *)(a1 + result) = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)(rt + 8LL) + i) + 2 * result);
a1 += 80LL;
}
return result;
}

original_code:
static void tt_take_snapshot(char screen[25][80]) {
 unsigned int i, j;
 for (i=0;i<25;i++) {
  for (j=0;j<80;j++) {
   screen[i][j] = rt->cells[i][j].ch;
  }
 }
}

canonical_original_code:
static void tt_take_snapshot(char screen[25][80]) {
 unsigned int i; unsigned int j;
 for (i=0;i<25;i++) {
  for (j=0;j<80;j++) {
   screen[i][j] = rt->cells[i][j].ch;
  }
 }
}

variable_types:
screen
char [25][80]

variable_types:
i
unsigned int

variable_types:
j
unsigned int


decompiled_code:
size_t tt_record_wait_until_idle()
{
return fwrite("\nTuitest.wait_until_idle\n", 1uLL, 0x19uLL, f);
}

canonical_decompiled_code:
size_t func2()
{
return fwrite("\nTuitest.wait_until_idle\n", 1uLL, 0x19uLL, f);
}

original_code:
static void tt_record_wait_until_idle() {
 fprintf(f, "\nTuitest.wait_until_idle\n");
}


decompiled_code:
void __fastcall tt_generate_wait_until_expected_text(unsigned int a1, __int64 a2, __int64 a3)
{
char *v3; // rbx
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
v3 = tt_getlinediff(a2, a3, v4);
fprintf(
f,
"if not Tuitest.wait_until_expected_text(%u, %u, \"%s\", 0) then # TODO: set timeout to required limit (milliseconds)\n",
a1,
v4[0],
v3);
fprintf(f, "\tverifier.log_fail(\"Waiting for `%s' on position (%u, %u) timed out.\", :warn)\n", v3, a1, v4[0]);
fwrite("end\n", 1uLL, 4uLL, f);
free(v3);
}

canonical_decompiled_code:
void __fastcall func3(unsigned int a1, __int64 a2, __int64 a3)
{
char *v3; // rbx
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
v3 = tt_getlinediff(a2, a3, v4);
fprintf(
f,
"if not Tuitest.wait_until_expected_text(%u, %u, \"%s\", 0) then # TODO: set timeout to required limit (milliseconds)\n",
a1,
v4[0],
v3);
fprintf(f, "\tverifier.log_fail(\"Waiting for `%s' on position (%u, %u) timed out.\", :warn)\n", v3, a1, v4[0]);
fwrite("end\n", 1uLL, 4uLL, f);
free(v3);
}

original_code:
static void tt_generate_wait_until_expected_text(unsigned int row, char oldrow[80], char newrow[80]) {
 unsigned int col = 0;
 char * buf = tt_getlinediff(oldrow, newrow, &col);
 fprintf(f, "if not Tuitest.wait_until_expected_text(%u, %u, \"%s\", 0) then # TODO: set timeout to required limit (milliseconds)\n", row, col, buf);
 fprintf(f, "\tverifier.log_fail(\"Waiting for `%s' on position (%u, %u) timed out.\", :warn)\n", buf, row, col);
 fprintf(f, "end\n");
 free(buf);
}

canonical_original_code:
static void tt_generate_wait_until_expected_text(unsigned int row, char oldrow[80], char newrow[80]) {
 unsigned int col = 0;
 char *buf = tt_getlinediff(oldrow, newrow, &col);
 fprintf(f, "if not Tuitest.wait_until_expected_text(%u, %u, \"%s\", 0) then # TODO: set timeout to required limit (milliseconds)\n", row, col, buf);
 fprintf(f, "\tverifier.log_fail(\"Waiting for `%s' on position (%u, %u) timed out.\", :warn)\n", buf, row, col);
 fprintf(f, "end\n");
 free(buf);
}

variable_types:
row
unsigned int

variable_types:
oldrow
char [80]

variable_types:
newrow
char [80]

variable_types:
col
unsigned int

variable_types:
buf
char *


decompiled_code:
void __fastcall tt_generate_verification(unsigned int a1, __int64 a2, __int64 a3)
{
char *v3; // rbx
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
v3 = tt_getlinediff(a2, a3, v4);
fprintf(f, "verifier.expect(%u, %u, \"%s\")\n", a1, v4[0], v3);
free(v3);
}

canonical_decompiled_code:
void __fastcall func4(unsigned int a1, __int64 a2, __int64 a3)
{
char *v3; // rbx
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
v3 = tt_getlinediff(a2, a3, v4);
fprintf(f, "verifier.expect(%u, %u, \"%s\")\n", a1, v4[0], v3);
free(v3);
}

original_code:
static void tt_generate_verification(unsigned int row, char oldrow[80], char newrow[80]) {
 unsigned int col = 0;
 char * buf = tt_getlinediff(oldrow, newrow, &col);
 fprintf(f, "verifier.expect(%u, %u, \"%s\")\n", row, col, buf);
 free(buf);
}

canonical_original_code:
static void tt_generate_verification(unsigned int row, char oldrow[80], char newrow[80]) {
 unsigned int col = 0;
 char *buf = tt_getlinediff(oldrow, newrow, &col);
 fprintf(f, "verifier.expect(%u, %u, \"%s\")\n", row, col, buf);
 free(buf);
}


decompiled_code:
int __fastcall tt_generate_verifications(void *s1, void *s2, int a3)
{
int v5; // er15
unsigned int i; // er12
int result; // eax

v5 = a3;
if ( fastmode && !a3 )
tt_record_wait_until_idle();
fprintf(f, "\n# begin auto-generated verification #%u \n", autogen);
for ( i = 0; i != 25; ++i )
{
if ( memcmp(s1, s2, 0x50uLL) )
{
if ( v5 )
tt_generate_wait_until_expected_text(i, (__int64)s1, (__int64)s2);
tt_generate_verification(i, (__int64)s1, (__int64)s2);
v5 = 0;
}
s1 = (char *)s1 + 80;
s2 = (char *)s2 + 80;
}
result = fprintf(f, "# end auto-generated verification #%u \n\n", autogen);
++autogen;
return result;
}

canonical_decompiled_code:
int __fastcall func5(void *s1, void *s2, int a3)
{
int v5; // er15
unsigned int i; // er12
int result; // eax

v5 = a3;
if ( fastmode && !a3 )
func2();
fprintf(f, "\n# begin auto-generated verification #%u \n", autogen);
for ( i = 0; i != 25; ++i )
{
if ( memcmp(s1, s2, 0x50uLL) )
{
if ( v5 )
func3(i, (__int64)s1, (__int64)s2);
func4(i, (__int64)s1, (__int64)s2);
v5 = 0;
}
s1 = (char *)s1 + 80;
s2 = (char *)s2 + 80;
}
result = fprintf(f, "# end auto-generated verification #%u \n\n", autogen);
++autogen;
return result;
}

original_code:
static void tt_generate_verifications(char oldscreen[25][80], char newscreen[25][80], int first_verification_is_wait) {
 unsigned int i;
 if (fastmode && !first_verification_is_wait) {
  tt_record_wait_until_idle();
 }
 fprintf(f, "\n# begin auto-generated verification #%u \n", autogen);
 for (i=0;i<25;i++) {
  if (memcmp(oldscreen[i],newscreen[i], 80)!=0) {
   if (first_verification_is_wait) {
    first_verification_is_wait = 0;
    tt_generate_wait_until_expected_text(i, oldscreen[i], newscreen[i]);
   }
   tt_generate_verification(i, oldscreen[i], newscreen[i]);
  }
 }
 fprintf(f, "# end auto-generated verification #%u \n\n", autogen);
 autogen++;
}

variable_types:
oldscreen
char [25][80]

variable_types:
newscreen
char [25][80]


decompiled_code:
__int64 __fastcall tt_open_script(char *filename)
{
FILE *v1; // rcx
__int64 result; // rax
char v3[2048]; // [rsp+0h] [rbp-1818h] BYREF
char v4[2048]; // [rsp+800h] [rbp-1018h] BYREF
char v5[1024]; // [rsp+1000h] [rbp-818h] BYREF
char s[1048]; // [rsp+1400h] [rbp-418h] BYREF

snprintf(s, 0x400uLL, "%s.log", filename);
snprintf(v5, 0x400uLL, "RESULT-%s.xml", filename);
escape_quotes(v4, (unsigned __int8 *)s);
escape_quotes(v3, (unsigned __int8 *)v5);
v1 = fopen(filename, "w+");
f = v1;
result = 0LL;
if ( v1 )
{
fwrite("#!/usr/bin/env ruby\n", 1uLL, 0x14uLL, v1);
fwrite("# auto-generated tuitest script\n", 1uLL, 0x20uLL, f);
fwrite("require 'tuitest'\n\n", 1uLL, 0x13uLL, f);
fwrite("Tuitest.init\n", 1uLL, 0xDuLL, f);
if ( xmloutput )
{
fprintf(f, "verifier = Tuitest::Verifier.new(\"%s\", \"%s\")\n\n", v4, v3);
result = 1LL;
}
else
{
fprintf(f, "verifier = Tuitest::Verifier.new(\"%s\")\n\n", v4);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *filename)
{
FILE *v1; // rcx
__int64 result; // rax
char v3[2048]; // [rsp+0h] [rbp-1818h] BYREF
char v4[2048]; // [rsp+800h] [rbp-1018h] BYREF
char v5[1024]; // [rsp+1000h] [rbp-818h] BYREF
char s[1048]; // [rsp+1400h] [rbp-418h] BYREF

snprintf(s, 0x400uLL, "%s.log", filename);
snprintf(v5, 0x400uLL, "RESULT-%s.xml", filename);
func0(v4, (unsigned __int8 *)s);
func0(v3, (unsigned __int8 *)v5);
v1 = fopen(filename, "w+");
f = v1;
result = 0LL;
if ( v1 )
{
fwrite("#!/usr/bin/env ruby\n", 1uLL, 0x14uLL, v1);
fwrite("# auto-generated tuitest script\n", 1uLL, 0x20uLL, f);
fwrite("require 'tuitest'\n\n", 1uLL, 0x13uLL, f);
fwrite("Tuitest.init\n", 1uLL, 0xDuLL, f);
if ( xmloutput )
{
fprintf(f, "verifier = Tuitest::Verifier.new(\"%s\", \"%s\")\n\n", v4, v3);
result = 1LL;
}
else
{
fprintf(f, "verifier = Tuitest::Verifier.new(\"%s\")\n\n", v4);
result = 1LL;
}
}
return result;
}

original_code:
int tt_open_script(const char * file) {
 char logfilename[1024];
 char xmlfilename[1024];
 char escaped_logfile[2048];
 char escaped_xmlfile[2048];
 snprintf(logfilename, sizeof(logfilename), "%s.log", file);
 snprintf(xmlfilename, sizeof(xmlfilename), "RESULT-%s.xml", file);
 escape_quotes(escaped_logfile, logfilename);
 escape_quotes(escaped_xmlfile, xmlfilename);
 f = fopen(file, "w+");
 if (!f) {
  return 0;
 }
 fprintf(f, "#!/usr/bin/env ruby\n");
 fprintf(f, "# auto-generated tuitest script\n");
 fprintf(f, "require 'tuitest'\n\n");
 fprintf(f, "Tuitest.init\n");
 if (xmloutput) {
  fprintf(f, "verifier = Tuitest::Verifier.new(\"%s\", \"%s\")\n\n", escaped_logfile, escaped_xmlfile);
 } else {
  fprintf(f, "verifier = Tuitest::Verifier.new(\"%s\")\n\n", escaped_logfile);
 }
 return 1;
}

canonical_original_code:
int tt_open_script(char *file) {
 char logfilename[1024];
 char xmlfilename[1024];
 char escaped_logfile[2048];
 char escaped_xmlfile[2048];
 snprintf(logfilename, sizeof(logfilename), "%s.log", file);
 snprintf(xmlfilename, sizeof(xmlfilename), "RESULT-%s.xml", file);
 escape_quotes(escaped_logfile, logfilename);
 escape_quotes(escaped_xmlfile, xmlfilename);
 f = fopen(file, "w+");
 if (!f) {
  return 0;
 }
 fprintf(f, "#!/usr/bin/env ruby\n");
 fprintf(f, "# auto-generated tuitest script\n");
 fprintf(f, "require 'tuitest'\n\n");
 fprintf(f, "Tuitest.init\n");
 if (xmloutput) {
  fprintf(f, "verifier = Tuitest::Verifier.new(\"%s\", \"%s\")\n\n", escaped_logfile, escaped_xmlfile);
 } else {
  fprintf(f, "verifier = Tuitest::Verifier.new(\"%s\")\n\n", escaped_logfile);
 }
 return 1;
}

variable_types:
file
char *

variable_types:
logfilename
char [1024]

variable_types:
xmlfilename
char [1024]


decompiled_code:
int tt_close_script()
{
if ( fastmode )
tt_record_wait_until_idle();
fwrite("\nTuitest.close\n", 1uLL, 0xFuLL, f);
fwrite("verifier.finish\n\n", 1uLL, 0x11uLL, f);
fwrite("# EOF\n", 1uLL, 6uLL, f);
return fclose(f);
}

canonical_decompiled_code:
int func7()
{
if ( fastmode )
func2();
fwrite("\nTuitest.close\n", 1uLL, 0xFuLL, f);
fwrite("verifier.finish\n\n", 1uLL, 0x11uLL, f);
fwrite("# EOF\n", 1uLL, 6uLL, f);
return fclose(f);
}

original_code:
void tt_close_script() {
 if (fastmode)
  tt_record_wait_until_idle();
 fprintf(f, "\nTuitest.close\n");
 fprintf(f, "verifier.finish\n\n");
 fprintf(f, "# EOF\n");
 fclose(f);
}


decompiled_code:
int __fastcall tt_record_wait(unsigned int a1)
{
return fprintf(f, "Tuitest.wait(%u)\n\n", a1);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1)
{
return fprintf(f, "Tuitest.wait(%u)\n\n", a1);
}

original_code:
void tt_record_wait(unsigned int msec) {
 fprintf(f, "Tuitest.wait(%u)\n\n", msec);
}

variable_types:
msec
unsigned int


decompiled_code:
int __fastcall tt_record_keypress(unsigned int a1)
{
const char *v1; // rdx

if ( a1 - 32 > 0x5E )
return fprintf(f, "Tuitest.keypress(%d)\n", a1);
v1 = "\\";
if ( a1 != 34 )
v1 = (const char *)&LC21;
return fprintf(f, "Tuitest.keypress(\"%s%c\"[0])\n", v1, a1);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1)
{
const char *v1; // rdx

if ( a1 - 32 > 0x5E )
return fprintf(f, "Tuitest.keypress(%d)\n", a1);
v1 = "\\";
if ( a1 != 34 )
v1 = (const char *)&LC21;
return fprintf(f, "Tuitest.keypress(\"%s%c\"[0])\n", v1, a1);
}

original_code:
void tt_record_keypress(int key) {
 if (key >= 0x20 && key <= 0x7E) {
  fprintf(f, "Tuitest.keypress(\"%s%c\"[0])\n", key == '"' ? "\\" : "", key);
 } else {
  fprintf(f, "Tuitest.keypress(%d)\n", key);
 }
}

variable_types: key int


decompiled_code:
_DWORD *tt_record()
{
_DWORD *result; // rax
int v1; // eax
unsigned int v2; // ebx
_BYTE v3[2000]; // [rsp+0h] [rbp-FD8h] BYREF
char s1[2000]; // [rsp+7D0h] [rbp-808h] BYREF
struct timeval v5; // [rsp+FA0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+FB0h] [rbp-28h] BYREF

tt_take_snapshot((__int64)s1);
gettimeofday(&tv, 0LL);
for ( result = &getout; !getout; result = &getout )
{
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
wrefresh(term_win);
v1 = wgetch(stdscr);
v2 = v1;
if ( v1 == 269 )
{
tt_take_snapshot((__int64)s1);
}
else if ( (unsigned int)(v1 - 270) <= 1 )
{
gettimeofday(&v5, 0LL);
if ( !fastmode && v2 != 271 )
tt_record_wait(1000 * LODWORD(v5.tv_sec) + SLODWORD(v5.tv_usec) / 1000 - 1000 * LODWORD(tv.tv_sec) - tv.tv_usec / 1000);
gettimeofday(&tv, 0LL);
tt_take_snapshot((__int64)v3);
tt_generate_verifications(s1, v3, v2 == 271);
tt_take_snapshot((__int64)s1);
}
else if ( v1 != -1 )
{
gettimeofday(&v5, 0LL);
if ( !fastmode )
tt_record_wait(1000 * LODWORD(v5.tv_sec) + SLODWORD(v5.tv_usec) / 1000 - 1000 * LODWORD(tv.tv_sec) - tv.tv_usec / 1000);
tt_record_keypress(v2);
rote_vt_keypress(rt, v2);
gettimeofday(&tv, 0LL);
}
}
return result;
}

canonical_decompiled_code:
_DWORD *func10()
{
_DWORD *result; // rax
int v1; // eax
unsigned int v2; // ebx
_BYTE v3[2000]; // [rsp+0h] [rbp-FD8h] BYREF
char s1[2000]; // [rsp+7D0h] [rbp-808h] BYREF
struct timeval v5; // [rsp+FA0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+FB0h] [rbp-28h] BYREF

func1((__int64)s1);
gettimeofday(&tv, 0LL);
for ( result = &getout; !getout; result = &getout )
{
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
wrefresh(term_win);
v1 = wgetch(stdscr);
v2 = v1;
if ( v1 == 269 )
{
func1((__int64)s1);
}
else if ( (unsigned int)(v1 - 270) <= 1 )
{
gettimeofday(&v5, 0LL);
if ( !fastmode && v2 != 271 )
func8(1000 * LODWORD(v5.tv_sec) + SLODWORD(v5.tv_usec) / 1000 - 1000 * LODWORD(tv.tv_sec) - tv.tv_usec / 1000);
gettimeofday(&tv, 0LL);
func1((__int64)v3);
func5(s1, v3, v2 == 271);
func1((__int64)s1);
}
else if ( v1 != -1 )
{
gettimeofday(&v5, 0LL);
if ( !fastmode )
func8(1000 * LODWORD(v5.tv_sec) + SLODWORD(v5.tv_usec) / 1000 - 1000 * LODWORD(tv.tv_sec) - tv.tv_usec / 1000);
func9(v2);
rote_vt_keypress(rt, v2);
gettimeofday(&tv, 0LL);
}
}
return result;
}

original_code:
void tt_record() {
 int ch;
 struct timeval t1, t2;
 char screen[25][80];
 tt_take_snapshot(screen);
 gettimeofday(&t1, ((void *)0));
 while (!getout) {
  rote_vt_draw(rt, term_win, 1, 1, ((void *)0));
  wrefresh(term_win);
  ch = wgetch(stdscr);
  if (ch == (0410 +(5))) {
   tt_take_snapshot(screen);
  } else if (ch == (0410 +(6)) || ch == (0410 +(7))) {
   char curscreen[25][80];
   gettimeofday(&t2, ((void *)0));
   if (!fastmode && ch != (0410 +(7)))
    tt_record_wait((t2.tv_sec*1000 + t2.tv_usec/1000) - (t1.tv_sec*1000 + t1.tv_usec/1000));
   gettimeofday(&t1, ((void *)0));
   tt_take_snapshot(curscreen);
   tt_generate_verifications(screen, curscreen, ch == (0410 +(7)));
   tt_take_snapshot(screen);
  } else if (ch != (-1)) {
   gettimeofday(&t2, ((void *)0));
   if (!fastmode)
    tt_record_wait((t2.tv_sec*1000 + t2.tv_usec/1000) - (t1.tv_sec*1000 + t1.tv_usec/1000));
   tt_record_keypress(ch);
   rote_vt_keypress(rt, ch);
   gettimeofday(&t1, ((void *)0));
  }
 }
}

canonical_original_code:
void tt_record() {
 int ch;
 struct timeval t1; struct timeval t2;
 char screen[25][80];
 tt_take_snapshot(screen);
 gettimeofday(&t1, ((void *)0));
 while (!getout) {
  rote_vt_draw(rt, term_win, 1, 1, ((void *)0));
  wrefresh(term_win);
  ch = wgetch(stdscr);
  if (ch == (0410 +(5))) {
   tt_take_snapshot(screen);
  } else if (ch == (0410 +(6)) || ch == (0410 +(7))) {
   char curscreen[25][80];
   gettimeofday(&t2, ((void *)0));
   if (!fastmode && ch != (0410 +(7)))
    tt_record_wait((t2.tv_sec*1000 + t2.tv_usec/1000) - (t1.tv_sec*1000 + t1.tv_usec/1000));
   gettimeofday(&t1, ((void *)0));
   tt_take_snapshot(curscreen);
   tt_generate_verifications(screen, curscreen, ch == (0410 +(7)));
   tt_take_snapshot(screen);
  } else if (ch != (-1)) {
   gettimeofday(&t2, ((void *)0));
   if (!fastmode)
    tt_record_wait((t2.tv_sec*1000 + t2.tv_usec/1000) - (t1.tv_sec*1000 + t1.tv_usec/1000));
   tt_record_keypress(ch);
   rote_vt_keypress(rt, ch);
   gettimeofday(&t1, ((void *)0));
  }
 }
}

variable_types: ch int

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

variable_types:
curscreen
char [25][80]


decompiled_code:
void __fastcall tt_record_run(char *a1)
{
size_t v1; // rax
_BYTE *v2; // rbx

v1 = strlen(a1);
v2 = malloc(2 * v1 + 1);
escape_quotes(v2, (unsigned __int8 *)a1);
fprintf(f, "\nTuitest.run(\"%s\")\n\n", v2);
if ( fastmode )
tt_record_wait_until_idle();
free(v2);
}

canonical_decompiled_code:
void __fastcall func11(char *a1)
{
size_t v1; // rax
_BYTE *v2; // rbx

v1 = strlen(a1);
v2 = malloc(2 * v1 + 1);
func0(v2, (unsigned __int8 *)a1);
fprintf(f, "\nTuitest.run(\"%s\")\n\n", v2);
if ( fastmode )
func2();
free(v2);
}

original_code:
void tt_record_run(const char * cmd) {
 char * esccmd = malloc(strlen(cmd)*2 + 1);
 escape_quotes(esccmd, cmd);
 fprintf(f, "\nTuitest.run(\"%s\")\n\n", esccmd);
 if (fastmode)
  tt_record_wait_until_idle();
 free(esccmd);
}

canonical_original_code:
void tt_record_run(char *cmd) {
 char *esccmd = malloc(strlen(cmd)*2 + 1);
 escape_quotes(esccmd, cmd);
 fprintf(f, "\nTuitest.run(\"%s\")\n\n", esccmd);
 if (fastmode)
  tt_record_wait_until_idle();
 free(esccmd);
}

variable_types:
cmd
char *

variable_types:
esccmd
char *


decompiled_code:
__int64 __fastcall tt_keypress(unsigned int a1)
{
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
wrefresh(term_win);
return rote_vt_keypress(rt, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
wrefresh(term_win);
return rote_vt_keypress(rt, a1);
}

original_code:
void tt_keypress(int key) {
 rote_vt_draw(rt, term_win, 1, 1, ((void *)0));
 wrefresh(term_win);
 rote_vt_keypress(rt, key);
}