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 func8()
{
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)
{
__int64 v3; // rbx

v3 = 1LL;
printf("const uint32_t %s[%d] = {\n", a3, (unsigned int)a2);
while ( 1 )
{
printf("0x%08x", *(unsigned int *)(a1 + 4 * v3 - 4));
if ( a2 == v3 )
break;
if ( __ROR8__(0xAAAAAAAAAAAAAAABLL * v3, 1) <= 0x2AAAAAAAAAAAAAAAuLL )
puts(",");
else
printf(", ");
++v3;
}
return puts("\n};");
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, __int64 a2, const char *a3)
{
__int64 v3; // rbx

v3 = 1LL;
printf("const uint32_t %s[%d] = {\n", a3, (unsigned int)a2);
while ( 1 )
{
printf("0x%08x", *(unsigned int *)(a1 + 4 * v3 - 4));
if ( a2 == v3 )
break;
if ( __ROR8__(0xAAAAAAAAAAAAAAABLL * v3, 1) <= 0x2AAAAAAAAAAAAAAAuLL )
puts(",");
else
printf(", ");
++v3;
}
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

return_type: void


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

return_type: 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 v7; // rcx
unsigned __int64 v8; // rdx
unsigned __int64 v9; // r9
__int64 result; // rax

v7 = *a2;
if ( (unsigned __int64)*a2 > 7 )
{
v8 = (v7 - 2) / 6uLL;
v9 = v8;
*a2 = v7 - 6 * v8;
*a4 += 8 * v8;
do
{
if ( v9 > 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);
}
else if ( v9 > 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);
}
else
{
if ( v9 == 1 )
return enc_loop_generic_64_inner(a1, a3);
enc_loop_generic_64_inner(a1, a3);
result = enc_loop_generic_64_inner(a1, a3);
}
}
while ( v9 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 **a1, __int64 *a2, __int64 a3, _QWORD *a4)
{
__int64 v7; // rcx
unsigned __int64 v8; // rdx
unsigned __int64 v9; // r9
__int64 result; // rax

v7 = *a2;
if ( (unsigned __int64)*a2 > 7 )
{
v8 = (v7 - 2) / 6uLL;
v9 = v8;
*a2 = v7 - 6 * v8;
*a4 += 8 * v8;
do
{
if ( v9 > 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);
}
else if ( v9 > 3 )
{
func2(a1, a3);
func2(a1, a3);
func2(a1, a3);
result = func2(a1, a3);
}
else
{
if ( v9 == 1 )
return func2(a1, a3);
func2(a1, a3);
result = func2(a1, a3);
}
}
while ( v9 );
}
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 func2(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; } *


main

canonical_name: main

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

*(_QWORD *)&v6 = 0LL;
v9 = 0LL;
*((_QWORD *)&v6 + 1) = "stdin";
stream = stdin;
v8 = 76LL;
if ( (unsigned __int8)parse_opts_constprop_0(argc, (char **)argv, (const char **)&v6) )
{
if ( BYTE1(v9) )
{
usage_isra_0(stdout, (const char *)v6);
result = 0;
}
else if ( (unsigned __int8)buffer_alloc((const char **)&v6, v5) )
{
if ( (_BYTE)v9 )
v3 = (unsigned int)decode((const char **)&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_isra_0(stderr, (const char *)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-10h] [rbp-48h] BYREF
__int128 v6; // [rsp+0h] [rbp-38h] BYREF
FILE *stream; // [rsp+10h] [rbp-28h]
__int64 v8; // [rsp+18h] [rbp-20h]
__int64 v9; // [rsp+20h] [rbp-18h]

*(_QWORD *)&v6 = 0LL;
v9 = 0LL;
*((_QWORD *)&v6 + 1) = "stdin";
stream = stdin;
v8 = 76LL;
if ( (unsigned __int8)func5(argc, (char **)argv, (const char **)&v6) )
{
if ( BYTE1(v9) )
{
func10(stdout, (const char *)v6);
result = 0;
}
else if ( (unsigned __int8)func1((const char **)&v6, v5) )
{
if ( (_BYTE)v9 )
v3 = (unsigned int)func4((const char **)&v6, (char **)v5) != 0;
else
v3 = func9((__int64)&v6, v5);
func2(v5);
fclose(stream);
fclose(stdout);
result = v3 ^ 1;
}
else
{
result = 1;
}
}
else
{
func10(stderr, (const char *)v6);
result = 1;
}
return result;
}

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 *


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 v2; // r12
unsigned __int64 i; // rbx
int result; // eax

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

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

if ( *a1 )
{
v2 = 0LL;
do
{
for ( i = 0LL; a1[1] > i; ++i )
{
gsl_matrix_get();
printf("\t[ %g ] ", a2);
}
++v2;
result = putchar(10);
}
while ( *a1 > v2 );
}
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()
{
int v0; // er14
int v1; // ebx
__int16 i; // bp
__int64 result; // rax

v0 = 0;
signal(17, (__sighandler_t)sigchld);
initscr();
noecho();
start_color();
raw();
nodelay(stdscr, 1);
keypad(stdscr, 1);
do
{
v1 = 1;
for ( i = 7 - v0; ; i += 8 )
{
if ( v1 != 1 || v0 != 7 )
{
init_pair(i, v0, v1 - 1);
if ( v1 == 8 )
break;
}
++v1;
}
++v0;
}
while ( v0 != 8 );
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()
{
int v0; // er14
int v1; // ebx
__int16 i; // bp
__int64 result; // rax

v0 = 0;
signal(17, (__sighandler_t)sigchld);
initscr();
noecho();
start_color();
raw();
nodelay(stdscr, 1);
keypad(stdscr, 1);
do
{
v1 = 1;
for ( i = 7 - v0; ; i += 8 )
{
if ( v1 != 1 || v0 != 7 )
{
init_pair(i, v0, v1 - 1);
if ( v1 == 8 )
break;
}
++v1;
}
++v0;
}
while ( v0 != 8 );
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; // r12
const char *v6; // rbp
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; // r12
const char *v6; // rbp
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:
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 v2; // rbx
void *v3; // rdi

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

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( ptr )
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 6));
if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
free(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
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(int *a1, const char *a2)
{
int v2; // eax
int result; // eax
struct winsize winp; // [rsp+8h] [rbp-20h] BYREF

v2 = *a1;
*(_DWORD *)&winp.ws_xpixel = 0;
winp.ws_row = v2;
*(_DWORD *)&winp.ws_col = (unsigned __int16)a1[1];
result = forkpty((int *)(*((_QWORD *)a1 + 4) + 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);
}
a1[7] = result;
return result;
}

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

v2 = *a1;
*(_DWORD *)&winp.ws_xpixel = 0;
winp.ws_row = v2;
*(_DWORD *)&winp.ws_col = (unsigned __int16)a1[1];
result = forkpty((int *)(*((_QWORD *)a1 + 4) + 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);
}
a1[7] = 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)
{
__int64 result; // rax
int v3; // edi

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

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

result = *(_QWORD *)(a1 + 32);
v3 = *(_DWORD *)(result + 152);
if ( v3 >= 0 )
{
close(v3);
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)
{
int result; // eax
int v3; // ebx
__int64 v4; // rax
int v5; // edi
struct timeval v6; // [rsp+0h] [rbp-2C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-2B8h] BYREF
char buf[568]; // [rsp+90h] [rbp-238h] BYREF

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

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
int result; // eax
int v3; // ebx
__int64 v4; // rax
int v5; // edi
struct timeval v6; // [rsp+0h] [rbp-2C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-2B8h] BYREF
char buf[568]; // [rsp+90h] [rbp-238h] BYREF

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

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, size_t a3)
{
int v4; // er12
ssize_t result; // rax
char *v6; // rbp
int v7; // edi

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

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

v4 = a3;
result = *(_QWORD *)(a1 + 32);
v6 = a2;
v7 = *(_DWORD *)(result + 152);
if ( v7 < 0 )
return rote_vt_inject(a1, a2, a3);
if ( (int)a3 > 0 )
{
while ( 1 )
{
result = write(v7, v6, v4);
if ( (int)result < 0 )
break;
v4 -= result;
v6 += (int)result;
if ( v4 <= 0 )
return result;
v7 = *(_DWORD *)(*(_QWORD *)(a1 + 32) + 152LL);
}
a2 = errormsg_0;
a3 = strlen(errormsg_0);
return rote_vt_inject(a1, a2, a3);
}
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:
char *__fastcall rote_vt_take_snapshot(__int64 a1)
{
int v1; // er13
int v2; // ebp
char *v3; // r12
const void **v4; // rax
char *v5; // rcx
const void **v6; // rbx
__int64 v7; // r13
char *v8; // rcx

v1 = *(_DWORD *)a1;
v2 = 2 * *(_DWORD *)(a1 + 4);
v3 = (char *)malloc(v2 * *(_DWORD *)a1);
if ( v1 > 0 )
{
v4 = *(const void ***)(a1 + 8);
v5 = v3;
v6 = v4 + 1;
v7 = (__int64)&v4[(unsigned int)(v1 - 1) + 1];
while ( 1 )
{
v8 = (char *)memcpy(v5, *v4, v2);
v4 = v6;
v5 = &v8[v2];
if ( (const void **)v7 == v6 )
break;
++v6;
}
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1)
{
int v1; // er13
int v2; // ebp
char *v3; // r12
const void **v4; // rax
char *v5; // rcx
const void **v6; // rbx
__int64 v7; // r13
char *v8; // rcx

v1 = *(_DWORD *)a1;
v2 = 2 * *(_DWORD *)(a1 + 4);
v3 = (char *)malloc(v2 * *(_DWORD *)a1);
if ( v1 > 0 )
{
v4 = *(const void ***)(a1 + 8);
v5 = v3;
v6 = v4 + 1;
v7 = (__int64)&v4[(unsigned int)(v1 - 1) + 1];
while ( 1 )
{
v8 = (char *)memcpy(v5, *v4, v2);
v4 = v6;
v5 = &v8[v2];
if ( (const void **)v7 == v6 )
break;
++v6;
}
}
return v3;
}

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
size_t v3; // r13
__int64 v6; // rbx
const void *v7; // rsi
void *v8; // rdi

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

canonical_decompiled_code:
void *__fastcall func10(__int64 a1, char *a2)
{
void *result; // rax
size_t v3; // r13
__int64 v6; // rbx
const void *v7; // rsi
void *v8; // rdi

result = (void *)*(unsigned int *)(a1 + 4);
if ( *(int *)a1 > 0 )
{
v3 = 2 * (int)result;
v6 = 0LL;
do
{
v7 = a2;
a2 += v3;
*(_BYTE *)(*(_QWORD *)(a1 + 48) + v6) = 1;
v8 = *(void **)(*(_QWORD *)(a1 + 8) + 8 * v6++);
result = memcpy(v8, v7, v3);
}
while ( *(_DWORD *)a1 > (int)v6 );
}
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_verification(unsigned int a1, __int64 a2, __int64 a3)
{
char *v3; // rbp
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

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

v4[0] = 0;
v3 = tt_getlinediff_constprop_0(a2, a3, (int *)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);
}

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_wait_until_expected_text(unsigned int a1, __int64 a2, __int64 a3)
{
char *v3; // rbp
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
v3 = tt_getlinediff_constprop_0(a2, a3, (int *)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 func4(unsigned int a1, __int64 a2, __int64 a3)
{
char *v3; // rbp
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
v3 = tt_getlinediff_constprop_0(a2, a3, (int *)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);
}


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

v3 = a3;
if ( fastmode && (a3 & 1) == 0 )
tt_record_wait_until_idle();
v6 = 0;
fprintf(f, "\n# begin auto-generated verification #%u \n", autogen);
do
{
if ( memcmp(s1, s2, 0x50uLL) )
{
if ( v3 )
tt_generate_wait_until_expected_text(v6, (__int64)s1, (__int64)s2);
v3 = 0;
tt_generate_verification(v6, (__int64)s1, (__int64)s2);
}
++v6;
s1 = (char *)s1 + 80;
s2 = (char *)s2 + 80;
}
while ( v6 != 25 );
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 v3; // er12
unsigned int v6; // er15
int result; // eax

v3 = a3;
if ( fastmode && (a3 & 1) == 0 )
func2();
v6 = 0;
fprintf(f, "\n# begin auto-generated verification #%u \n", autogen);
do
{
if ( memcmp(s1, s2, 0x50uLL) )
{
if ( v3 )
func4(v6, (__int64)s1, (__int64)s2);
v3 = 0;
func3(v6, (__int64)s1, (__int64)s2);
}
++v6;
s1 = (char *)s1 + 80;
s2 = (char *)s2 + 80;
}
while ( v6 != 25 );
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[1024]; // [rsp+0h] [rbp-1828h] BYREF
char s[1024]; // [rsp+400h] [rbp-1428h] BYREF
char v5[2048]; // [rsp+800h] [rbp-1028h] BYREF
char v6[2088]; // [rsp+1000h] [rbp-828h] BYREF

snprintf(v3, 0x400uLL, "%s.log", filename);
snprintf(s, 0x400uLL, "RESULT-%s.xml", filename);
escape_quotes(v5, v3);
escape_quotes(v6, s);
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", v5, v6);
result = 1LL;
}
else
{
fprintf(f, "verifier = Tuitest::Verifier.new(\"%s\")\n\n", v5);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *filename)
{
FILE *v1; // rcx
__int64 result; // rax
char v3[1024]; // [rsp+0h] [rbp-1828h] BYREF
char s[1024]; // [rsp+400h] [rbp-1428h] BYREF
char v5[2048]; // [rsp+800h] [rbp-1028h] BYREF
char v6[2088]; // [rsp+1000h] [rbp-828h] BYREF

snprintf(v3, 0x400uLL, "%s.log", filename);
snprintf(s, 0x400uLL, "RESULT-%s.xml", filename);
func0(v5, v3);
func0(v6, s);
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", v5, v6);
result = 1LL;
}
else
{
fprintf(f, "verifier = Tuitest::Verifier.new(\"%s\")\n\n", v5);
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:
int tt_record()
{
int result; // eax
int v1; // eax
unsigned int v2; // er13
void *v3; // r9
struct timeval v4; // [rsp+0h] [rbp-FF8h] BYREF
struct timeval tv; // [rsp+10h] [rbp-FE8h] BYREF
char s1[2000]; // [rsp+20h] [rbp-FD8h] BYREF
char v7[2056]; // [rsp+7F0h] [rbp-808h] BYREF

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

canonical_decompiled_code:
int func10()
{
int result; // eax
int v1; // eax
unsigned int v2; // er13
void *v3; // r9
struct timeval v4; // [rsp+0h] [rbp-FF8h] BYREF
struct timeval tv; // [rsp+10h] [rbp-FE8h] BYREF
char s1[2000]; // [rsp+20h] [rbp-FD8h] BYREF
char v7[2056]; // [rsp+7F0h] [rbp-808h] BYREF

func1((__int64)s1);
for ( result = gettimeofday(&v4, 0LL); !getout; result = getout )
{
while ( 1 )
{
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
wrefresh(term_win);
v1 = wgetch(stdscr);
v2 = v1;
if ( v1 != 269 )
break;
LABEL_14:
func1((__int64)s1);
result = getout;
if ( getout )
return result;
}
if ( (unsigned int)(v1 - 270) <= 1 )
{
gettimeofday(&tv, 0LL);
if ( !fastmode && v2 != 271 )
func8(SLODWORD(tv.tv_usec) / 1000 + 1000 * LODWORD(tv.tv_sec) - 1000 * LODWORD(v4.tv_sec) - v4.tv_usec / 1000);
gettimeofday(&v4, 0LL);
func1((__int64)v7);
func5(s1, v3, v2 == 271);
goto LABEL_14;
}
if ( v1 != -1 )
{
gettimeofday(&tv, 0LL);
if ( !fastmode )
func8(SLODWORD(tv.tv_usec) / 1000 + 1000 * LODWORD(tv.tv_sec) - 1000 * LODWORD(v4.tv_sec) - v4.tv_usec / 1000);
func9(v2);
rote_vt_keypress(rt, v2);
gettimeofday(&v4, 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; // rbp

v1 = strlen(a1);
v2 = malloc(2 * v1 + 1);
escape_quotes(v2, 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; // rbp

v1 = strlen(a1);
v2 = malloc(2 * v1 + 1);
func0(v2, 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);
}


decompiled_code:
int __fastcall tt_wait(unsigned int a1)
{
unsigned int v1; // ebx

v1 = a1;
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
if ( a1 > 0x3E8 )
{
do
{
v1 -= 1000;
usleep(0xF4240u);
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
wrefresh(term_win);
}
while ( v1 > 0x3E8 );
}
usleep(1000 * v1);
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
return wrefresh(term_win);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
unsigned int v1; // ebx

v1 = a1;
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
if ( a1 > 0x3E8 )
{
do
{
v1 -= 1000;
usleep(0xF4240u);
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
wrefresh(term_win);
}
while ( v1 > 0x3E8 );
}
usleep(1000 * v1);
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
return wrefresh(term_win);
}

original_code:
void tt_wait(unsigned int msec) {
 rote_vt_draw(rt, term_win, 1, 1, ((void *)0));
 while (msec > 1000) {
  usleep(1000000);
  msec -= 1000;
  rote_vt_draw(rt, term_win, 1, 1, ((void *)0));
  wrefresh(term_win);
 }
 usleep(msec * 1000);
 rote_vt_draw(rt, term_win, 1, 1, ((void *)0));
 wrefresh(term_win);
}


decompiled_code:
char *__fastcall tt_getrow(unsigned int a1)
{
__int64 v1; // rcx
__int64 i; // rax
char v4[104]; // [rsp-50h] [rbp-68h] BYREF

if ( a1 > 0x18 )
return 0LL;
v1 = *(_QWORD *)(*(_QWORD *)(rt + 8LL) + 8LL * a1);
for ( i = 0LL; i != 80; ++i )
v4[i] = *(_BYTE *)(v1 + 2 * i);
v4[80] = 0;
return strdup(v4);
}

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1)
{
__int64 v1; // rcx
__int64 i; // rax
char v4[104]; // [rsp-50h] [rbp-68h] BYREF

if ( a1 > 0x18 )
return 0LL;
v1 = *(_QWORD *)(*(_QWORD *)(rt + 8LL) + 8LL * a1);
for ( i = 0LL; i != 80; ++i )
v4[i] = *(_BYTE *)(v1 + 2 * i);
v4[80] = 0;
return strdup(v4);
}

original_code:
char * tt_getrow(unsigned int row) {
 if (row < 25) {
  char buf[81];
  unsigned int i;
  RoteCell* p = rt->cells[row];
  for (i=0;i<80;i++) {
   buf[i] = p[i].ch;
  }
  buf[80] = '\0';
  return strdup(buf);
 }
 return ((void *)0);
}

canonical_original_code:
char *tt_getrow(unsigned int row) {
 if (row < 25) {
  char buf[81];
  unsigned int i;
  struct RoteCell_ *p = rt->cells[row];
  for (i=0;i<80;i++) {
   buf[i] = p[i].ch;
  }
  buf[80] = '\0';
  return strdup(buf);
 }
 return ((void *)0);
}

variable_types:
row
unsigned int

variable_types:
buf
char [81]

variable_types:
i
unsigned int

variable_types: struct RoteCell_ { unsigned char ch; unsigned char attr; } *

return_type: char *


decompiled_code:
bool __fastcall is_valid_csi_ender(char a1)
{
return (unsigned __int8)((a1 & 0xDF) - 64) <= 0x1Au;
}

canonical_decompiled_code:
bool __fastcall func0(char a1)
{
return (unsigned __int8)((a1 & 0xDF) - 64) <= 0x1Au;
}

original_code:
static inline _Bool is_valid_csi_ender(char c) {
   return (c >= 'a' && c <= 'z') ||
          (c >= 'A' && c <= 'Z') ||
          c == '@' || c == '`';
}

variable_types: c char


original_code:
static inline void put_normal_char(RoteTerm *rt, char c) {
   if (rt->ccol >= rt->cols) {
      rt->ccol = 0;
      cursor_line_down(rt);
   }
   rt->cells[rt->crow][rt->ccol].ch = c;
   rt->cells[rt->crow][rt->ccol].attr = rt->curattr;
   rt->ccol++;
   rt->line_dirty[rt->crow] = 1;
   rt->curpos_dirty = 1;
}

canonical_original_code:
static inline void put_normal_char(struct RoteTerm_ *rt, char c) {
   if (rt->ccol >= rt->cols) {
      rt->ccol = 0;
      cursor_line_down(rt);
   }
   rt->cells[rt->crow][rt->ccol].ch = c;
   rt->cells[rt->crow][rt->ccol].attr = rt->curattr;
   rt->ccol++;
   rt->line_dirty[rt->crow] = 1;
   rt->curpos_dirty = 1;
}

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


decompiled_code:
__int64 __fastcall put_graphmode_char(__int64 a1, char a2)
{
bool v2; // zf
char v3; // si

if ( a2 <= 119 )
{
if ( a2 > 115 )
v3 = 43;
else
v3 = (unsigned __int8)(a2 - 106) < 5u ? 43 : 37;
}
else
{
v2 = a2 == 120;
v3 = 37;
if ( v2 )
v3 = 124;
}
return put_normal_char(a1, v3);
}

original_code:
static inline void put_graphmode_char(RoteTerm *rt, char c) {
   char nc;
   switch (c) {
      case 'j': case 'k': case 'l': case 'm': case 'n': case 't':
                                    case 'u': case 'v': case 'w':
         nc = '+'; break;
      case 'x':
         nc = '|'; break;
      default:
         nc = '%';
   }
   put_normal_char(rt, nc);
}

canonical_original_code:
static inline void put_graphmode_char(struct RoteTerm_ *rt, char c) {
   char nc;
   switch (c) {
      case 'j': case 'k': case 'l': case 'm': case 'n': case 't':
                                    case 'u': case 'v': case 'w':
         nc = '+'; break;
      case 'x':
         nc = '|'; break;
      default:
         nc = '%';
   }
   put_normal_char(rt, nc);
}

variable_types: nc char


decompiled_code:
void __fastcall try_interpret_escape_seq(__int64 a1)
{
__int64 v1; // rsi
char v2; // bp
char v3; // r12
__int64 (__fastcall *v4)(__int64, __int64); // rax
int v5; // eax
__int64 v6; // rdi

v1 = *(_QWORD *)(a1 + 32);
v2 = *(_BYTE *)(v1 + 20);
if ( !v2 )
return;
v3 = *(_BYTE *)(v1 + *(_DWORD *)(v1 + 148) - 1 + 20);
v4 = *(__int64 (__fastcall **)(__int64, __int64))(v1 + 160);
if ( v4 )
{
v5 = v4(a1, v1 + 20);
if ( !v5 )
goto LABEL_14;
if ( v5 == 1 )
return;
}
if ( v2 == 77 )
{
cursor_line_up(a1);
goto LABEL_14;
}
if ( ((v2 - 91) & 0xFD) != 0 )
{
LABEL_14:
v6 = *(_QWORD *)(a1 + 32);
LABEL_15:
cancel_escape_sequence_isra_0(v6);
return;
}
if ( v2 == 91 )
{
if ( is_valid_csi_ender(v3) )
{
rote_es_interpret_csi(a1);
cancel_escape_sequence_isra_0(*(_QWORD *)(a1 + 32));
}
}
else if ( v2 == 93 && v3 == 7 )
{
cancel_escape_sequence_isra_0(*(_QWORD *)(a1 + 32));
}
v6 = *(_QWORD *)(a1 + 32);
if ( *(int *)(v6 + 148) > 126 )
goto LABEL_15;
}

original_code:
static void try_interpret_escape_seq(RoteTerm *rt) {
   char firstchar = rt->pd->esbuf[0];
   char lastchar = rt->pd->esbuf[rt->pd->esbuf_len-1];
   if (!firstchar) return;
   if (rt->pd->handler) {
      int answer = (*(rt->pd->handler))(rt, rt->pd->esbuf);
      if (answer == 0) {
         cancel_escape_sequence(rt);
         return;
      }
      else if (answer == 1) {
         return;
      }
   }
   if (firstchar == 'M') {
      cursor_line_up(rt);
      cancel_escape_sequence(rt);
      return;
   }
   if (firstchar != '[' && firstchar != ']') {
      cancel_escape_sequence(rt);
      return;
   }
   if (firstchar == '[' && is_valid_csi_ender(lastchar)) {
      rote_es_interpret_csi(rt);
      cancel_escape_sequence(rt);
   }
   else if (firstchar == ']' && lastchar == '\a') {
      cancel_escape_sequence(rt);
   }
   if (rt->pd->esbuf_len + 1 >= 128) cancel_escape_sequence(rt);
}

canonical_original_code:
static void try_interpret_escape_seq(struct RoteTerm_ *rt) {
   char firstchar = rt->pd->esbuf[0];
   char lastchar = rt->pd->esbuf[rt->pd->esbuf_len-1];
   if (!firstchar) return;
   if (rt->pd->handler) {
      int answer = (*(rt->pd->handler))(rt, rt->pd->esbuf);
      if (answer == 0) {
         cancel_escape_sequence(rt);
         return;
      }
      else if (answer == 1) {
         return;
      }
   }
   if (firstchar == 'M') {
      cursor_line_up(rt);
      cancel_escape_sequence(rt);
      return;
   }
   if (firstchar != '[' && firstchar != ']') {
      cancel_escape_sequence(rt);
      return;
   }
   if (firstchar == '[' && is_valid_csi_ender(lastchar)) {
      rote_es_interpret_csi(rt);
      cancel_escape_sequence(rt);
   }
   else if (firstchar == ']' && lastchar == '\a') {
      cancel_escape_sequence(rt);
   }
   if (rt->pd->esbuf_len + 1 >= 128) cancel_escape_sequence(rt);
}

variable_types: firstchar char

variable_types: lastchar char

variable_types: answer int


decompiled_code:
void __fastcall handle_control_char(__int64 a1, char a2)
{
int v2; // eax

switch ( a2 )
{
case 8:
v2 = *(_DWORD *)(a1 + 20);
if ( v2 > 0 )
*(_DWORD *)(a1 + 20) = v2 - 1;
*(_BYTE *)(a1 + 40) = 1;
break;
case 9:
while ( (*(_BYTE *)(a1 + 20) & 7) != 0 )
put_normal_char(a1, 32);
break;
case 10:
*(_DWORD *)(a1 + 20) = 0;
cursor_line_down(a1);
*(_BYTE *)(a1 + 40) = 1;
break;
case 13:
*(_DWORD *)(a1 + 20) = 0;
break;
case 14:
*(_BYTE *)(*(_QWORD *)(a1 + 32) + 1LL) = 1;
break;
case 15:
*(_BYTE *)(*(_QWORD *)(a1 + 32) + 1LL) = 0;
break;
case 24:
case 26:
cancel_escape_sequence_isra_0(*(_QWORD *)(a1 + 32));
break;
case 27:
new_escape_sequence_isra_0(*(_QWORD *)(a1 + 32));
break;
default:
return;
}
}

original_code:
static void handle_control_char(RoteTerm *rt, char c) {
   switch (c) {
      case '\r': rt->ccol = 0; break;
      case '\n':
         rt->ccol = 0; cursor_line_down(rt);
         rt->curpos_dirty = 1;
         break;
      case '\b':
         if (rt->ccol > 0) rt->ccol--;
         rt->curpos_dirty = 1;
         break;
      case '\t':
         while (rt->ccol % 8) put_normal_char(rt, ' ');
         break;
      case '\x1B':
         new_escape_sequence(rt);
         break;
      case '\x0E':
         rt->pd->graphmode = 1;
         break;
      case '\x0F':
         rt->pd->graphmode = 0;
         break;
      case '\x9B':
         new_escape_sequence(rt);
         rt->pd->esbuf[rt->pd->esbuf_len++] = '[';
         break;
      case '\x18': case '\x1A':
         cancel_escape_sequence(rt);
         break;
      case '\a':
         break;
   }
}

canonical_original_code:
static void handle_control_char(struct RoteTerm_ *rt, char c) {
   switch (c) {
      case '\r': rt->ccol = 0; break;
      case '\n':
         rt->ccol = 0; cursor_line_down(rt);
         rt->curpos_dirty = 1;
         break;
      case '\b':
         if (rt->ccol > 0) rt->ccol--;
         rt->curpos_dirty = 1;
         break;
      case '\t':
         while (rt->ccol % 8) put_normal_char(rt, ' ');
         break;
      case '\x1B':
         new_escape_sequence(rt);
         break;
      case '\x0E':
         rt->pd->graphmode = 1;
         break;
      case '\x0F':
         rt->pd->graphmode = 0;
         break;
      case '\x9B':
         new_escape_sequence(rt);
         rt->pd->esbuf[rt->pd->esbuf_len++] = '[';
         break;
      case '\x18': case '\x1A':
         cancel_escape_sequence(rt);
         break;
      case '\a':
         break;
   }
}


decompiled_code:
void __fastcall rote_vt_inject(__int64 a1, char *a2, int a3)
{
char *v3; // rbp
char *v4; // rbx
char v5; // si
__int64 v6; // rax
int v7; // edx
__int64 v8; // rcx
int v9; // edx

v3 = &a2[a3];
if ( a3 > 0 )
{
v4 = a2;
while ( 1 )
{
v5 = *v4;
if ( !*v4 )
goto LABEL_4;
if ( (unsigned __int8)(v5 - 1) <= 0x1Eu )
{
handle_control_char(a1, v5);
goto LABEL_4;
}
v6 = *(_QWORD *)(a1 + 32);
if ( *(_BYTE *)v6 )
{
v7 = *(_DWORD *)(v6 + 148);
if ( v7 <= 127 )
{
v8 = v7;
v9 = v7 + 1;
*(_BYTE *)(v6 + v8 + 20) = *v4;
*(_DWORD *)(v6 + 148) = v9;
*(_BYTE *)(v6 + v9 + 20) = 0;
try_interpret_escape_seq(a1);
goto LABEL_4;
}
}
if ( *(_BYTE *)(v6 + 1) )
{
put_graphmode_char(a1, v5);
LABEL_4:
if ( ++v4 == v3 )
return;
}
else
{
put_normal_char(a1, v5);
if ( ++v4 == v3 )
return;
}
}
}
}

original_code:
void rote_vt_inject(RoteTerm *rt, const char *data, int len) {
   int i;
   for (i = 0; i < len; i++, data++) {
      if (*data == 0) continue;
      if (*data >= 1 && *data <= 31) {
         handle_control_char(rt, *data);
         continue;
      }
      if (rt->pd->escaped && rt->pd->esbuf_len < 128) {
         rt->pd->esbuf[rt->pd->esbuf_len] = *data;
         rt->pd->esbuf[++rt->pd->esbuf_len] = 0;
         try_interpret_escape_seq(rt);
      }
      else if (rt->pd->graphmode)
         put_graphmode_char(rt, *data);
      else
         put_normal_char(rt, *data);
   }
}

canonical_original_code:
void rote_vt_inject(struct RoteTerm_ *rt, char *data, int len) {
   int i;
   for (i = 0; i < len; i++, data++) {
      if (*data == 0) continue;
      if (*data >= 1 && *data <= 31) {
         handle_control_char(rt, *data);
         continue;
      }
      if (rt->pd->escaped && rt->pd->esbuf_len < 128) {
         rt->pd->esbuf[rt->pd->esbuf_len] = *data;
         rt->pd->esbuf[++rt->pd->esbuf_len] = 0;
         try_interpret_escape_seq(rt);
      }
      else if (rt->pd->graphmode)
         put_graphmode_char(rt, *data);
      else
         put_normal_char(rt, *data);
   }
}

variable_types:
data
char *

variable_types: len int

variable_types: i int


getElapsedTime

repo: akshatarao/AOS

decompiled_code:
double __fastcall getElapsedTime(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
double result; // xmm0_8

v2 = a2[1] + 1000000LL * *a2 - (a1[1] + 1000000LL * *a1);
if ( v2 < 0 )
result = (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1)) + (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1));
else
result = (double)(int)v2;
return result;
}

canonical_decompiled_code:
double __fastcall func7(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
double result; // xmm0_8

v2 = a2[1] + 1000000LL * *a2 - (a1[1] + 1000000LL * *a1);
if ( v2 < 0 )
result = (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1)) + (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1));
else
result = (double)(int)v2;
return result;
}

original_code:
double getElapsedTime(struct timeval *start_t, struct timeval *finish_t){
        unsigned long start,finish,final_usec,final_sec;
        start=(start_t->tv_sec*1000000 + start_t->tv_usec);
        finish=(finish_t->tv_sec*1000000 + finish_t->tv_usec);
        final_sec =(finish-start)/1000000;
        final_usec = (finish-start)%1000000;
        return (finish-start);
        }

canonical_original_code:
double getElapsedTime(struct timeval *start_t, struct timeval *finish_t){
        unsigned long start; unsigned long finish; unsigned long final_usec; unsigned long final_sec;
        start=(start_t->tv_sec*1000000 + start_t->tv_usec);
        finish=(finish_t->tv_sec*1000000 + finish_t->tv_usec);
        final_sec =(finish-start)/1000000;
        final_usec = (finish-start)%1000000;
        return (finish-start);
        }

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

variable_types:
start
unsigned long

variable_types:
finish
unsigned long

return_type: double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v4; // rdi
int v5; // er12
int v6; // eax
void *v7; // rsp
int v8; // er15
__int64 v9; // r14
_QWORD *v10; // rbx
_DWORD *v11; // rax
__int64 v13[8]; // [rsp+0h] [rbp-40h] BYREF

if ( argc <= 2 )
{
printf("\nSyntax: %s numberOfThreads numberOfBarriers", *argv);
fflush(_bss_start);
exit(1);
}
v3 = atoi(argv[1]);
v4 = argv[2];
numberOfThreads = v3;
v5 = v3;
v6 = atoi(v4);
numberOfBarriers = v6;
if ( v5 <= 0 || v6 <= 0 )
{
printf("\nERROR: Number of threads/barriers cannot be negative!");
exit(1);
}
v7 = alloca(4LL * v6);
omp_set_num_threads();
v8 = numberOfThreads;
if ( (double)numberOfThreads <= 0.0 )
{
log((double)numberOfThreads);
v8 = numberOfThreads;
}
v9 = 0LL;
v10 = malloc(8LL * v8);
if ( v8 > 0 )
{
do
{
v11 = malloc(0xCuLL);
v11[2] = v9;
v10[v9++] = v11;
*(_QWORD *)v11 = 0LL;
}
while ( v9 != v8 );
}
if ( numberOfBarriers > 0 )
memset(v13, 0, 4LL * numberOfBarriers);
v13[1] = (__int64)v13;
v13[0] = (__int64)v10;
GOMP_parallel();
return 0;
}

original_code:
int main(int argc, char** argv)
{
   if(argc < 3)
   {
 printf("\nSyntax: %s numberOfThreads numberOfBarriers", argv[0]);
 fflush(stdout);
 exit(1);
   }
    numberOfThreads = atoi(argv[1]);
    numberOfBarriers = atoi(argv[2]);
    if(numberOfThreads <=0 || numberOfBarriers <= 0) {
      printf("\nERROR: Number of threads/barriers cannot be negative!");
      exit(1);
    }
    int k,l;
    int barrierArray[numberOfBarriers];
    omp_set_num_threads(numberOfThreads);
    int rounds = ceil(log(numberOfThreads)/log(2));
    Thread** threadList = malloc(numberOfThreads*sizeof(Thread*));
    for(k = 0; k < numberOfThreads; k++){
        Thread* thread;
        thread = (Thread*) malloc(sizeof(Thread));
        thread->receivingCount = 0;
        thread->sentCount = 0;
        thread->threadID = k;
        *(threadList + k) = thread;
    }
    for(l = 0;l < numberOfBarriers; l++)
        barrierArray[l] = 0;

#pragma omp parallel shared(numberOfThreads,rounds)
    {
        int i = 0,j;
        struct timeval startTime,endTime;
        double totalTime = 0.00;
        numberOfThreads = omp_get_num_threads();
        int threadId = omp_get_thread_num();
        Thread* thread = *(threadList + threadId);
        for(i = 0; i <numberOfBarriers; i++) {
            j = 0;
            while(j < 9999){
                j++;
            }
            printf("Entered thread %d of %d threads at barrier %d\n", thread->threadID, numberOfThreads-1, i);
           gettimeofday(&startTime, ((void *)0));
           disseminationBarrier(thread,threadList,threadId);
           printf("Completed thread %d of %d threads at barrier %d\n", thread->threadID, numberOfThreads-1, i);

#pragma omp critical
           {
                barrierArray[i] = barrierArray[i] + 1;
           }
           while(barrierArray[i]!= numberOfThreads);
           gettimeofday(&endTime, ((void *)0));
           totalTime = totalTime + getElapsedTime(&startTime,&endTime);
           }
           printf("Time spent in barrier by thread %d is %f\n",thread->threadID,(totalTime/numberOfBarriers));
    }
return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
   if(argc < 3)
   {
 printf("\nSyntax: %s numberOfThreads numberOfBarriers", argv[0]);
 fflush(stdout);
 exit(1);
   }
    numberOfThreads = atoi(argv[1]);
    numberOfBarriers = atoi(argv[2]);
    if(numberOfThreads <=0 || numberOfBarriers <= 0) {
      printf("\nERROR: Number of threads/barriers cannot be negative!");
      exit(1);
    }
    int k; int l;
    int barrierArray[-1];
    omp_set_num_threads(numberOfThreads);
    int rounds = ceil(log(numberOfThreads)/log(2));
    struct thread_struct **threadList = malloc(numberOfThreads*sizeof(Thread*));
    for(k = 0; k < numberOfThreads; k++){
        struct thread_struct *thread;
        thread = (struct thread_struct *) malloc(sizeof(Thread));
        thread->receivingCount = 0;
        thread->sentCount = 0;
        thread->threadID = k;
        *(threadList + k) = thread;
    }
    for(l = 0;l < numberOfBarriers; l++)
        barrierArray[l] = 0;

#pragma omp parallel shared(numberOfThreads,rounds)
    {
        int i = 0; int j;
        struct timeval startTime; struct timeval endTime;
        double totalTime = 0.00;
        numberOfThreads = omp_get_num_threads();
        int threadId = omp_get_thread_num();
        struct thread_struct *thread = *(threadList + threadId);
        for(i = 0; i <numberOfBarriers; i++) {
            j = 0;
            while(j < 9999){
                j++;
            }
            printf("Entered thread %d of %d threads at barrier %d\n", thread->threadID, numberOfThreads-1, i);
           gettimeofday(&startTime, ((void *)0));
           disseminationBarrier(thread,threadList,threadId);
           printf("Completed thread %d of %d threads at barrier %d\n", thread->threadID, numberOfThreads-1, i);

#pragma omp critical
           {
                barrierArray[i] = barrierArray[i] + 1;
           }
           while(barrierArray[i]!= numberOfThreads);
           gettimeofday(&endTime, ((void *)0));
           totalTime = totalTime + getElapsedTime(&startTime,&endTime);
           }
           printf("Time spent in barrier by thread %d is %f\n",thread->threadID,(totalTime/numberOfBarriers));
    }
return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: k int

variable_types: l int

variable_types:
barrierArray
int [-1]

variable_types: rounds int

variable_types: struct thread_struct { int receivingCount; int sentCount; int threadID; } **

variable_types: j int

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

variable_types: totalTime double

variable_types: threadId int


centralizedThreadBarrierLogic

decompiled_code:
__int64 __fastcall centralizedThreadBarrierLogic(__int64 a1, _DWORD *a2, _DWORD *a3)
{
*(_DWORD *)(*(_QWORD *)a1 + 4LL) = *(_DWORD *)(*(_QWORD *)a1 + 4LL) == 0;
GOMP_critical_start();
if ( (*a2)-- == 1 )
{
printf("\nSwitching Global Sense to %d", *(unsigned int *)(*(_QWORD *)a1 + 4LL));
*a2 = numberOfThreads;
*a3 = *(_DWORD *)(*(_QWORD *)a1 + 4LL);
}
return GOMP_critical_end();
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _DWORD *a2, _DWORD *a3)
{
*(_DWORD *)(*(_QWORD *)a1 + 4LL) = *(_DWORD *)(*(_QWORD *)a1 + 4LL) == 0;
GOMP_critical_start();
if ( (*a2)-- == 1 )
{
printf("\nSwitching Global Sense to %d", *(unsigned int *)(*(_QWORD *)a1 + 4LL));
*a2 = numberOfThreads;
*a3 = *(_DWORD *)(*(_QWORD *)a1 + 4LL);
}
return GOMP_critical_end();
}

original_code:
void centralizedThreadBarrierLogic(Thread **thread, int* countOfThreads, int* globalSense)
{
  int i = 0;
  while(i < 9999)
      i++;
  (*thread)->sense = !(*thread)->sense;

#pragma omp critical
  {
      *countOfThreads = *countOfThreads - 1;
    if(*countOfThreads == 0)
    {
       printf("\nSwitching Global Sense to %d", (*thread)->sense);
        *countOfThreads = numberOfThreads;
        *globalSense = (*thread)->sense;
    }
  }
  i = 0;
  while((*thread)->sense != *globalSense)
  {
 i++;
  }
}

canonical_original_code:
void centralizedThreadBarrierLogic(struct thread_struct **thread, int *countOfThreads, int *globalSense)
{
  int i = 0;
  while(i < 9999)
      i++;
  (*thread)->sense = !(*thread)->sense;

#pragma omp critical
  {
      *countOfThreads = *countOfThreads - 1;
    if(*countOfThreads == 0)
    {
       printf("\nSwitching Global Sense to %d", (*thread)->sense);
        *countOfThreads = numberOfThreads;
        *globalSense = (*thread)->sense;
    }
  }
  i = 0;
  while((*thread)->sense != *globalSense)
  {
 i++;
  }
}

variable_types: struct thread_struct { int count; int sense; int localBarrierCounter; } **

variable_types:
countOfThreads
int *

variable_types:
globalSense
int *


centralizedOMP

decompiled_code:
int __fastcall centralizedOMP(int a1, int a2)
{
int v2; // ebp
__int64 v3; // rax
float v4; // xmm0_4

if ( a1 <= 0 || a2 <= 0 )
{
printf("\nERROR: Number of threads/barriers cannot be negative!");
exit(1);
}
v2 = 0;
memset(barrierTimeCounter, 0, 4LL * a2);
omp_set_num_threads();
globalThreadSense = 1;
do
{
++v2;
threadCounter = a1;
GOMP_parallel();
}
while ( a2 > v2 );
v3 = 0LL;
v4 = 0.0;
do
v4 = v4 + barrierTimeCounter[v3++];
while ( a2 > (int)v3 );
return printf("\nAverage time taken at Barriers is %f\n", (float)(v4 / (float)a2));
}

canonical_decompiled_code:
int __fastcall func9(int a1, int a2)
{
int v2; // ebp
__int64 v3; // rax
float v4; // xmm0_4

if ( a1 <= 0 || a2 <= 0 )
{
printf("\nERROR: Number of threads/barriers cannot be negative!");
exit(1);
}
v2 = 0;
memset(barrierTimeCounter, 0, 4LL * a2);
omp_set_num_threads();
globalThreadSense = 1;
do
{
++v2;
threadCounter = a1;
GOMP_parallel();
}
while ( a2 > v2 );
v3 = 0LL;
v4 = 0.0;
do
v4 = v4 + barrierTimeCounter[v3++];
while ( a2 > (int)v3 );
return printf("\nAverage time taken at Barriers is %f\n", (float)(v4 / (float)a2));
}

original_code:
void centralizedOMP(int numberOfThreads, int numberOfBarriers)
{
  if(numberOfThreads <=0 || numberOfBarriers <= 0)
  {
      printf("\nERROR: Number of threads/barriers cannot be negative!");
      exit(1);
  }
  int i = 0;
  for(i = 0; i < numberOfBarriers; i++)
  {
       barrierTimeCounter[i] = 0.0;
  }
  omp_set_num_threads(numberOfThreads);
  globalThreadSense = 1;
  for(i = 0; i < numberOfBarriers; i++)
  {
    threadCounter = numberOfThreads;

#pragma omp parallel shared(globalThreadSense, numberOfThreads)
       {
      struct timeval startTime, endTime;
     double totalTime;
      numberOfThreads = omp_get_num_threads();
      Thread* thread;
      thread = (Thread*)malloc(sizeof(Thread));
      thread->sense = 1;
      int i = 0, j =0, threadID;
      threadID = omp_get_thread_num();
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nEntered thread %d  of %d threads at barrier %d", threadID, numberOfThreads, i);
   gettimeofday(&startTime, ((void *)0));
          centralizedThreadBarrierLogic(&thread, &threadCounter, &globalThreadSense);
   gettimeofday(&endTime, ((void *)0));
   totalTime = (endTime.tv_sec * 1000000 + endTime.tv_usec)- (startTime.tv_sec * 1000000 + startTime.tv_usec);
   printf("\nTotal time at barrier %d by thread %d is %f", i, threadID, totalTime);

#pragma omp critical
   {
  barrierTimeCounter[i] += (float)totalTime;
   }
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nCompleted thread %d of %d threads at barrier %d %d", threadID, numberOfThreads, i, thread->sense, globalThreadSense);
   }
  }
  float totalBarrierTime = 0.0;
  for(i = 0; i < numberOfBarriers; i++)
  {
        totalBarrierTime += barrierTimeCounter[i];
  }
  printf("\nAverage time taken at Barriers is %f\n", (float)totalBarrierTime/numberOfBarriers);
}

canonical_original_code:
void centralizedOMP(int numberOfThreads, int numberOfBarriers)
{
  if(numberOfThreads <=0 || numberOfBarriers <= 0)
  {
      printf("\nERROR: Number of threads/barriers cannot be negative!");
      exit(1);
  }
  int i = 0;
  for(i = 0; i < numberOfBarriers; i++)
  {
       barrierTimeCounter[i] = 0.0;
  }
  omp_set_num_threads(numberOfThreads);
  globalThreadSense = 1;
  for(i = 0; i < numberOfBarriers; i++)
  {
    threadCounter = numberOfThreads;

#pragma omp parallel shared(globalThreadSense, numberOfThreads)
       {
      struct timeval startTime; struct timeval endTime;
     double totalTime;
      numberOfThreads = omp_get_num_threads();
      struct thread_struct *thread;
      thread = (struct thread_struct *)malloc(sizeof(Thread));
      thread->sense = 1;
      int i = 0; int j = 0; int threadID;
      threadID = omp_get_thread_num();
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nEntered thread %d  of %d threads at barrier %d", threadID, numberOfThreads, i);
   gettimeofday(&startTime, ((void *)0));
          centralizedThreadBarrierLogic(&thread, &threadCounter, &globalThreadSense);
   gettimeofday(&endTime, ((void *)0));
   totalTime = (endTime.tv_sec * 1000000 + endTime.tv_usec)- (startTime.tv_sec * 1000000 + startTime.tv_usec);
   printf("\nTotal time at barrier %d by thread %d is %f", i, threadID, totalTime);

#pragma omp critical
   {
  barrierTimeCounter[i] += (float)totalTime;
   }
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nCompleted thread %d of %d threads at barrier %d %d", threadID, numberOfThreads, i, thread->sense, globalThreadSense);
   }
  }
  float totalBarrierTime = 0.0;
  for(i = 0; i < numberOfBarriers; i++)
  {
        totalBarrierTime += barrierTimeCounter[i];
  }
  printf("\nAverage time taken at Barriers is %f\n", (float)totalBarrierTime/numberOfBarriers);
}

variable_types: numberOfThreads int

variable_types: numberOfBarriers int

variable_types: i int

variable_types: struct thread_struct { int count; int sense; int localBarrierCounter; } *

variable_types: threadID int

variable_types: totalBarrierTime float

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


main

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

if ( argc <= 2 )
{
printf("\nSyntax: <executable> numberOfThreads numberOfBarriers");
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
if ( v3 <= 0 || v4 <= 0 )
{
printf("\nInvalid Inputs!");
exit(1);
}
centralizedOMP((unsigned int)v3, (unsigned int)v4);
return 0;
}

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

if ( argc <= 2 )
{
printf("\nSyntax: <executable> numberOfThreads numberOfBarriers");
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
if ( v3 <= 0 || v4 <= 0 )
{
printf("\nInvalid Inputs!");
exit(1);
}
func9((unsigned int)v3, (unsigned int)v4);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
    if(argc < 3)
    {
        printf("\nSyntax: <executable> numberOfThreads numberOfBarriers");
        exit(1);
    }
    int numberOfThreads = atoi(argv[1]);
    int numberOfBarriers = atoi(argv[2]);
    if(numberOfThreads <= 0 || numberOfBarriers <= 0)
    {
        printf("\nInvalid Inputs!");
        exit(1);
    }
    centralizedOMP(numberOfThreads,numberOfBarriers);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    if(argc < 3)
    {
        printf("\nSyntax: <executable> numberOfThreads numberOfBarriers");
        exit(1);
    }
    int numberOfThreads = atoi(argv[1]);
    int numberOfBarriers = atoi(argv[2]);
    if(numberOfThreads <= 0 || numberOfBarriers <= 0)
    {
        printf("\nInvalid Inputs!");
        exit(1);
    }
    centralizedOMP(numberOfThreads,numberOfBarriers);
}

variable_types: argc int

variable_types:
argv
char *[]


baselineOMP

decompiled_code:
int __fastcall baselineOMP(int a1, int a2)
{
__int64 v2; // rbx
float v3; // xmm1_4

if ( a1 <= 0 || a2 <= 0 )
{
printf("\nERROR: Number of threads/barriers cannot be negative!");
exit(1);
}
memset(barrierTimeCounter, 0, sizeof(barrierTimeCounter));
omp_set_num_threads();
v2 = 0LL;
GOMP_parallel();
v3 = 0.0;
do
{
printf("\nTime taken at Barrier %d is %f", (unsigned int)v2, barrierTimeCounter[v2]);
v3 = v3 + barrierTimeCounter[v2++];
}
while ( a2 > (int)v2 );
return printf("\nAverage time taken at Barriers is %f\n", (float)(v3 / (float)a2));
}

canonical_decompiled_code:
int __fastcall func8(int a1, int a2)
{
__int64 v2; // rbx
float v3; // xmm1_4

if ( a1 <= 0 || a2 <= 0 )
{
printf("\nERROR: Number of threads/barriers cannot be negative!");
exit(1);
}
memset(barrierTimeCounter, 0, sizeof(barrierTimeCounter));
omp_set_num_threads();
v2 = 0LL;
GOMP_parallel();
v3 = 0.0;
do
{
printf("\nTime taken at Barrier %d is %f", (unsigned int)v2, barrierTimeCounter[v2]);
v3 = v3 + barrierTimeCounter[v2++];
}
while ( a2 > (int)v2 );
return printf("\nAverage time taken at Barriers is %f\n", (float)(v3 / (float)a2));
}

original_code:
void baselineOMP(int numberOfThreads, int numberOfBarriers)
{
  if(numberOfThreads <=0 || numberOfBarriers <= 0)
  {
      printf("\nERROR: Number of threads/barriers cannot be negative!");
      exit(1);
  }
  int i = 0;
  for(i = 0; i < 100000; i++)
  {
       barrierTimeCounter[i] = 0.0;
  }
  omp_set_num_threads(numberOfThreads);

#pragma omp parallel shared(numberOfThreads)
  {
     struct timeval startTime, endTime;
     double totalTime;
       numberOfThreads = omp_get_num_threads();
      int i = 0, j =0, threadID;
      threadID = omp_get_thread_num();
      for(i = 0; i <numberOfBarriers; i++)
      {
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nEntered thread %d  of %d threads at barrier %d", threadID, numberOfThreads, i);
          gettimeofday(&startTime, ((void *)0));

#pragma omp barrier
   {
          }
          gettimeofday(&endTime, ((void *)0));
          totalTime = (endTime.tv_sec * 1000000 + endTime.tv_usec)- (startTime.tv_sec * 1000000 + startTime.tv_usec);
          printf("\nTotal time at barrier %d by thread %d is %f", i, threadID, totalTime);

#pragma omp critical
          {
                barrierTimeCounter[i] += (float)totalTime;
          }
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nCompleted thread %d of %d threads at barrier %d", threadID, numberOfThreads, i);
      }
  }
  float totalBarrierTime = 0.0;
  for(i = 0; i < numberOfBarriers; i++)
  {
        printf("\nTime taken at Barrier %d is %f", i, barrierTimeCounter[i]);
        totalBarrierTime += barrierTimeCounter[i];
  }
  printf("\nAverage time taken at Barriers is %f\n", (float)totalBarrierTime/numberOfBarriers);
}

canonical_original_code:
void baselineOMP(int numberOfThreads, int numberOfBarriers)
{
  if(numberOfThreads <=0 || numberOfBarriers <= 0)
  {
      printf("\nERROR: Number of threads/barriers cannot be negative!");
      exit(1);
  }
  int i = 0;
  for(i = 0; i < 100000; i++)
  {
       barrierTimeCounter[i] = 0.0;
  }
  omp_set_num_threads(numberOfThreads);

#pragma omp parallel shared(numberOfThreads)
  {
     struct timeval startTime; struct timeval endTime;
     double totalTime;
       numberOfThreads = omp_get_num_threads();
      int i = 0; int j = 0; int threadID;
      threadID = omp_get_thread_num();
      for(i = 0; i <numberOfBarriers; i++)
      {
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nEntered thread %d  of %d threads at barrier %d", threadID, numberOfThreads, i);
          gettimeofday(&startTime, ((void *)0));

#pragma omp barrier
   {
          }
          gettimeofday(&endTime, ((void *)0));
          totalTime = (endTime.tv_sec * 1000000 + endTime.tv_usec)- (startTime.tv_sec * 1000000 + startTime.tv_usec);
          printf("\nTotal time at barrier %d by thread %d is %f", i, threadID, totalTime);

#pragma omp critical
          {
                barrierTimeCounter[i] += (float)totalTime;
          }
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nCompleted thread %d of %d threads at barrier %d", threadID, numberOfThreads, i);
      }
  }
  float totalBarrierTime = 0.0;
  for(i = 0; i < numberOfBarriers; i++)
  {
        printf("\nTime taken at Barrier %d is %f", i, barrierTimeCounter[i]);
        totalBarrierTime += barrierTimeCounter[i];
  }
  printf("\nAverage time taken at Barriers is %f\n", (float)totalBarrierTime/numberOfBarriers);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
int v4; // eax

if ( argc <= 2 )
{
printf("\nSyntax: %s numberOfThreads numberOfBarriers\n", *argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
if ( v4 > 100000 )
{
printf("\nNumber of Barriers exceeded");
exit(1);
}
baselineOMP(v3, (unsigned int)v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
int v4; // eax

if ( argc <= 2 )
{
printf("\nSyntax: %s numberOfThreads numberOfBarriers\n", *argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
if ( v4 > 100000 )
{
printf("\nNumber of Barriers exceeded");
exit(1);
}
func8(v3, (unsigned int)v4);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  int numberOfThreads, numberOfBarriers;
  if(argc < 3)
  {
 printf("\nSyntax: %s numberOfThreads numberOfBarriers\n", argv[0]);
 exit(1);
  }
  numberOfThreads = atoi(argv[1]);
  numberOfBarriers = atoi(argv[2]);
  if(numberOfBarriers > 100000)
  {
 printf("\nNumber of Barriers exceeded");
 exit(1);
  }
  baselineOMP(numberOfThreads, numberOfBarriers);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int numberOfThreads; int numberOfBarriers;
  if(argc < 3)
  {
 printf("\nSyntax: %s numberOfThreads numberOfBarriers\n", argv[0]);
 exit(1);
  }
  numberOfThreads = atoi(argv[1]);
  numberOfBarriers = atoi(argv[2]);
  if(numberOfBarriers > 100000)
  {
 printf("\nNumber of Barriers exceeded");
 exit(1);
  }
  baselineOMP(numberOfThreads, numberOfBarriers);
  return 0;
}

variable_types:
argv
char **


signalHandler

repo: aktau/hhpc

decompiled_code:
void signalHandler()
{
working = 0;
}

canonical_decompiled_code:
void func0()
{
working = 0;
}

original_code:
static void signalHandler(int signo) {
    working = 0;
}

variable_types: signo int