decompiled_code:
__int64 __fastcall rle_decode(const char *a1, const char *a2)
{
FILE *v2; // rbp
FILE *i; // r12
int v4; // er8
int v6; // [rsp+4h] [rbp-24h] BYREF
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6 = 0;
v7 = 0;
v8[0] = 7;
v2 = Fopen(a1, "rb");
for ( i = Fopen(a2, "wb"); ; write_count(&v6, v8, i, &v7, (v4 >> 7) & 1) )
{
v4 = fgetc(v2);
if ( v4 == -1 )
break;
v6 = v4 & 0x7F;
}
Fclose(i);
Fclose(v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, const char *a2)
{
FILE *v2; // rbp
FILE *i; // r12
int v4; // er8
int v6; // [rsp+4h] [rbp-24h] BYREF
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6 = 0;
v7 = 0;
v8[0] = 7;
v2 = Fopen(a1, "rb");
for ( i = Fopen(a2, "wb"); ; func3(&v6, v8, i, &v7, (v4 >> 7) & 1) )
{
v4 = fgetc(v2);
if ( v4 == -1 )
break;
v6 = v4 & 0x7F;
}
func4(i);
func4(v2);
return 1LL;
}

original_code:
uint8_t* rle_decode(uint8_t *encoded_data, size_t in_len, size_t *out_len) {
  bit_wcontext wcon = bit_wcontext_init(1024);
  for (size_t i = 0; i < in_len; i++) {
    uint8_t run = encoded_data[i];
    int type = run_decode_type(run);
    int len = run_decode_len(run);
    for (int j = 0; j < len; j++) {
      bit_wcontext_write(&wcon, type);
    }
  }
  if (wcon.bit_idx != 0) {
    free(wcon.buffer);
    return ((void *)0);
  } else {
    *out_len = wcon.byte_idx;
    return wcon.buffer;
  }
}

canonical_original_code:
unsigned char *rle_decode(unsigned char *encoded_data, unsigned long in_len, unsigned long *out_len) {
  struct bit_wcontext wcon = bit_wcontext_init(1024);
  for (unsigned long i = 0; i < in_len; i++) {
    unsigned char run = encoded_data[i];
    int type = run_decode_type(run);
    int len = run_decode_len(run);
    for (int j = 0; j < len; j++) {
      bit_wcontext_write(&wcon, type);
    }
  }
  if (wcon.bit_idx != 0) {
    free(wcon.buffer);
    return ((void *)0);
  } else {
    *out_len = wcon.byte_idx;
    return wcon.buffer;
  }
}

variable_types: struct bit_wcontext { unsigned char *buffer; unsigned long len; unsigned long byte_idx; unsigned long bit_idx; }

variable_types:
i
unsigned long

variable_types:
run
unsigned char

variable_types: type int

variable_types: len int


Calloc

decompiled_code:
void *__fastcall Calloc(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
unix_error("Calloc error");
return result;
}

canonical_decompiled_code:
void *__fastcall func7(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
func1("Calloc error");
return result;
}

original_code:
void *Calloc(size_t nmemb, size_t size)
{
    void *p;
    if ((p = calloc(nmemb, size)) == ((void *)0))
 unix_error("Calloc error");
    return p;
}

canonical_original_code:
void *Calloc(unsigned long nmemb, unsigned long size)
{
    void *p;
    if ((p = calloc(nmemb, size)) == ((void *)0))
 unix_error("Calloc error");
    return p;
}

variable_types:
nmemb
unsigned long

variable_types:
size
unsigned long

variable_types:
p
void *

return_type: void *


decompiled_code:
__int64 __fastcall rle_encode(const char *a1, const char *a2)
{
FILE *v2; // rbp
FILE *v3; // r12
int v4; // eax
int v6; // [rsp+8h] [rbp-30h] BYREF
int v7; // [rsp+Ch] [rbp-2Ch] BYREF
int v8; // [rsp+10h] [rbp-28h] BYREF
int v9; // [rsp+14h] [rbp-24h] BYREF
int v10; // [rsp+18h] [rbp-20h] BYREF
int v11[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v2 = Fopen(a1, "rb");
v8 = -1;
v9 = 1;
v3 = Fopen(a2, "wb");
v10 = -1;
v11[0] = 0;
while ( 1 )
{
v4 = get_bit(&v6, v2, &v10);
v7 = v4;
if ( v4 == -1 )
break;
v11[0] = 1;
if ( v8 == v4 )
{
v11[0] = 2;
count_run_constprop_0(v11, &v8, (unsigned int *)&v7, &v9, &v10, v2, v3, &v6);
if ( v6 == -1 )
{
run_end_isra_0(v11[0], &v8, (unsigned int *)&v7, v3);
goto LABEL_12;
}
}
else if ( v9 )
{
v8 = v4;
v9 = 0;
}
else
{
run_end_isra_0(1, &v8, (unsigned int *)&v7, v3);
}
--v10;
}
if ( v6 == -1 )
{
v11[0] = 1;
run_end_isra_0(1, &v8, (unsigned int *)&v7, v3);
}
LABEL_12:
Fclose(v3);
Fclose(v2);
return 1LL;
}

original_code:
uint8_t *rle_encode(uint8_t *original_data, size_t in_len, size_t *out_len) {
  rcontext rcon = rcontext_init(original_data, in_len);
  econtext econ = econtext_init();
  byte_wcontext wcon = byte_wcontext_init(1024);
  int bit = rcontext_read_bit(&rcon);
  uint8_t encoded;
  while (bit >= 0) {
    if (econtext_add_bit(&econ, bit, &encoded))
      byte_wcontext_write(&wcon, encoded);
    bit = rcontext_read_bit(&rcon);
  }
  if (econtext_end_bits(&econ, &encoded))
    byte_wcontext_write(&wcon, encoded);
  *out_len = wcon.byte_idx;
  return wcon.buffer;
}

canonical_original_code:
unsigned char *rle_encode(unsigned char *original_data, unsigned long in_len, unsigned long *out_len) {
  struct rcontext rcon = rcontext_init(original_data, in_len);
  struct econtext econ = econtext_init();
  struct byte_wcontext wcon = byte_wcontext_init(1024);
  int bit = rcontext_read_bit(&rcon);
  unsigned char encoded;
  while (bit >= 0) {
    if (econtext_add_bit(&econ, bit, &encoded))
      byte_wcontext_write(&wcon, encoded);
    bit = rcontext_read_bit(&rcon);
  }
  if (econtext_end_bits(&econ, &encoded))
    byte_wcontext_write(&wcon, encoded);
  *out_len = wcon.byte_idx;
  return wcon.buffer;
}

variable_types: struct rcontext { unsigned char *data; unsigned long len; unsigned long byte_idx; int bit_idx; }

variable_types: struct econtext { int run_type; int run_len; }

variable_types: struct byte_wcontext { unsigned char *buffer; unsigned long len; unsigned long byte_idx; }

variable_types: bit int

variable_types:
encoded
unsigned char

return_type: unsigned char *


compare

decompiled_code:
_BOOL8 __fastcall compare(const void *a1, const void *a2)
{
return *((_QWORD *)a1 + 2) < *((_QWORD *)a2 + 2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(const void *a1, const void *a2)
{
return *((_QWORD *)a1 + 2) < *((_QWORD *)a2 + 2);
}

original_code:
int compare (const void * a, const void * b)
{
   return ((pt*)a)->sqd_d < ((pt*)b)->sqd_d;
}

canonical_original_code:
int compare(void *a, void *b)
{
   return ((struct pt *)a)->sqd_d < ((struct pt *)b)->sqd_d;
}

variable_types:
a
void *

variable_types:
b
void *

return_type: int

user_defined_types: struct pt { long long x; long long y; long long sqd_d; }


original_code:
long long dot_product_pt(const pt pts[3])
{
   return ((pts[2].x - pts[0].x) * (pts[1].x - pts[0].x)) + ((pts[2].y - pts[0].y) * (pts[1].y - pts[0].y));
}

canonical_original_code:
long long dot_product_pt(struct pt pts[3])
{
   return ((pts[2].x - pts[0].x) * (pts[1].x - pts[0].x)) + ((pts[2].y - pts[0].y) * (pts[1].y - pts[0].y));
}

variable_types: struct pt { long long x; long long y; long long sqd_d; } [3]

return_type: long long


original_code:
long long sqd_dst(const pt *pt_a, const pt *pt_b)
{
   long long x = pt_b->x - pt_a->x;
   long long y = pt_b->y - pt_a->y;
   return x*x + y*y;
}

canonical_original_code:
long long sqd_dst(struct pt *pt_a, struct pt *pt_b)
{
   long long x = pt_b->x - pt_a->x;
   long long y = pt_b->y - pt_a->y;
   return x*x + y*y;
}

variable_types: struct pt { long long x; long long y; long long sqd_d; } *

variable_types:
x
long long

variable_types:
y
long long


decompiled_code:
int __fastcall angle_type(_QWORD *a1)
{
__int64 v1; // rax

qsort(a1, 3uLL, 0x18uLL, (__compar_fn_t)compare);
v1 = dot_product_pt(a1);
if ( !v1 )
return puts("right");
if ( v1 <= 0 )
return puts("obtuse");
return puts("acute");
}

canonical_decompiled_code:
int __fastcall func10(_QWORD *a1)
{
__int64 v1; // rax

qsort(a1, 3uLL, 0x18uLL, (__compar_fn_t)compare);
v1 = func8(a1);
if ( !v1 )
return puts("right");
if ( v1 <= 0 )
return puts("obtuse");
return puts("acute");
}

original_code:
void angle_type(pt pts[3])
{
   qsort(pts, 3, sizeof(pt), compare);
   long long type = dot_product_pt(pts);
   if (type == 0)
      printf("right\n");
   else if (type > 0)
      printf("acute\n");
   else
      printf("obtuse\n");
}

canonical_original_code:
void angle_type(struct pt pts[3])
{
   qsort(pts, 3, sizeof(pt), compare);
   long long type = dot_product_pt(pts);
   if (type == 0)
      printf("right\n");
   else if (type > 0)
      printf("acute\n");
   else
      printf("obtuse\n");
}

variable_types:
type
long long

return_type: void


original_code:
void edge_type(pt pts[3])
{
   if ((pts[0].x * (pts[1].y - pts[2].y) +
 pts[1].x * (pts[2].y - pts[0].y) +
 pts[2].x * (pts[0].y - pts[1].y)) == 0)
   {
      printf("not a triangle\n");
      exit(0);
   }
   pts[0].sqd_d = sqd_dst(&pts[1], &pts[2]);
   pts[1].sqd_d = sqd_dst(&pts[0], &pts[2]);
   pts[2].sqd_d = sqd_dst(&pts[0], &pts[1]);
   (((pts[0].sqd_d == pts[1].sqd_d == pts[2].sqd_d) == 0) ? (void) (0) : __assert_fail ("(pts[0].sqd_d == pts[1].sqd_d == pts[2].sqd_d) == 0", "triangle.c", 76, __extension__ __PRETTY_FUNCTION__));
   if ((pts[0].sqd_d == pts[1].sqd_d) || (pts[0].sqd_d == pts[2].sqd_d) || (pts[1].sqd_d == pts[2].sqd_d))
      printf("isosceles ");
   else
      printf("scalene ");
}

canonical_original_code:
void edge_type(struct pt pts[3])
{
   if ((pts[0].x * (pts[1].y - pts[2].y) +
 pts[1].x * (pts[2].y - pts[0].y) +
 pts[2].x * (pts[0].y - pts[1].y)) == 0)
   {
      printf("not a triangle\n");
      exit(0);
   }
   pts[0].sqd_d = sqd_dst(&pts[1], &pts[2]);
   pts[1].sqd_d = sqd_dst(&pts[0], &pts[2]);
   pts[2].sqd_d = sqd_dst(&pts[0], &pts[1]);
   (((pts[0].sqd_d == pts[1].sqd_d == pts[2].sqd_d) == 0) ? (void) (0) : __assert_fail ("(pts[0].sqd_d == pts[1].sqd_d == pts[2].sqd_d) == 0", "triangle.c", 76, __extension__ __PRETTY_FUNCTION__));
   if ((pts[0].sqd_d == pts[1].sqd_d) || (pts[0].sqd_d == pts[2].sqd_d) || (pts[1].sqd_d == pts[2].sqd_d))
      printf("isosceles ");
   else
      printf("scalene ");
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5[17]; // [rsp+0h] [rbp-88h] BYREF

if ( argc > 1 )
{
v3 = 1LL;
do
{
__isoc99_sscanf();
argv = (const char **)"%lld";
__isoc99_sscanf();
v4 = v5[3 * ((int)v3 >> 1)];
if ( v4 < 0 || (unsigned __int64)v5[3 * ((int)v3 >> 1) + 1] >= 0x80000000 || v4 >= 0x80000000LL )
__assert_fail(
"pts[i/2].x >= 0 && pts[i/2].y >= 0 && pts[i/2].x <= INT_MAX && pts[i/2].y <= INT_MAX",
"triangle.c",
0x5Fu,
"main");
v3 += 2LL;
}
while ( 2LL * ((unsigned int)(argc - 2) >> 1) + 3 != v3 );
}
edge_type(v5, argv);
angle_type(v5);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5[17]; // [rsp+0h] [rbp-88h] BYREF

if ( argc > 1 )
{
v3 = 1LL;
do
{
__isoc99_sscanf();
argv = (const char **)"%lld";
__isoc99_sscanf();
v4 = v5[3 * ((int)v3 >> 1)];
if ( v4 < 0 || (unsigned __int64)v5[3 * ((int)v3 >> 1) + 1] >= 0x80000000 || v4 >= 0x80000000LL )
__assert_fail(
"pts[i/2].x >= 0 && pts[i/2].y >= 0 && pts[i/2].x <= INT_MAX && pts[i/2].y <= INT_MAX",
"triangle.c",
0x5Fu,
"main");
v3 += 2LL;
}
while ( 2LL * ((unsigned int)(argc - 2) >> 1) + 3 != v3 );
}
func11(v5, argv);
func10(v5);
exit(0);
}

original_code:
int main(int argc, char *argv[])
{
   pt pts[3];
   for (int i = 1; i < argc; i += 2)
   {
      sscanf(argv[i], "%lld", &pts[i/2].x);
      sscanf(argv[i + 1], "%lld", &pts[i/2].y);
      ((pts[i/2].x >= 0 && pts[i/2].y >= 0 && pts[i/2].x <= 0x7fffffff && pts[i/2].y <= 0x7fffffff) ? (void) (0) : __assert_fail ("pts[i/2].x >= 0 && pts[i/2].y >= 0 && pts[i/2].x <= INT_MAX && pts[i/2].y <= INT_MAX", "triangle.c", 95, __extension__ __PRETTY_FUNCTION__));
   }
   edge_type(pts);
   angle_type(pts);
   exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   struct pt pts[3];
   for (int i = 1; i < argc; i += 2)
   {
      sscanf(argv[i], "%lld", &pts[i/2].x);
      sscanf(argv[i + 1], "%lld", &pts[i/2].y);
      ((pts[i/2].x >= 0 && pts[i/2].y >= 0 && pts[i/2].x <= 0x7fffffff && pts[i/2].y <= 0x7fffffff) ? (void) (0) : __assert_fail ("pts[i/2].x >= 0 && pts[i/2].y >= 0 && pts[i/2].x <= INT_MAX && pts[i/2].y <= INT_MAX", "triangle.c", 95, __extension__ __PRETTY_FUNCTION__));
   }
   edge_type(pts);
   angle_type(pts);
   exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int


checkCollinearity

decompiled_code:
double __fastcall checkCollinearity(_DWORD *a1, _DWORD *a2, _DWORD *a3)
{
return ((double)(*a1 * (a2[1] - a3[1])) + (double)(*a2 * (a3[1] - a1[1])) + (double)(*a3 * (a1[1] - a2[1]))) * 0.5;
}

original_code:
double checkCollinearity(int* P1, int* P2, int* P3)
{
  double firstResult = P1[0]*(P2[1]-P3[1]);
  double secondResult = P2[0]*(P3[1]-P1[1]);
  double thirdResult = P3[0]*(P1[1]-P2[1]);
  double result = (firstResult+secondResult+thirdResult)/2;
  return result;
}

canonical_original_code:
double checkCollinearity(int *P1, int *P2, int *P3)
{
  double firstResult = P1[0]*(P2[1]-P3[1]);
  double secondResult = P2[0]*(P3[1]-P1[1]);
  double thirdResult = P3[0]*(P1[1]-P2[1]);
  double result = (firstResult+secondResult+thirdResult)/2;
  return result;
}

variable_types: firstResult double

variable_types: secondResult double

variable_types: thirdResult double

variable_types: result double

return_type: double


computeSide

decompiled_code:
void __fastcall computeSide(_DWORD *a1, _DWORD *a2)
{
int v2; // eax
double v3; // xmm0_8

v2 = a2[1] - a1[1];
v3 = (double)(*a2 - *a1) * (double)(*a2 - *a1) + (double)v2 * (double)v2;
if ( v3 < 0.0 )
sqrt(v3);
}

canonical_decompiled_code:
void __fastcall func8(_DWORD *a1, _DWORD *a2)
{
int v2; // eax
double v3; // xmm0_8

v2 = a2[1] - a1[1];
v3 = (double)(*a2 - *a1) * (double)(*a2 - *a1) + (double)v2 * (double)v2;
if ( v3 < 0.0 )
sqrt(v3);
}

original_code:
double computeSide(int* P1, int* P2)
{
  return sqrt(pow(P2[0] - P1[0], 2) + pow (P2[1] - P1[1], 2));
}

canonical_original_code:
double computeSide(int *P1, int *P2)
{
  return sqrt(pow(P2[0] - P1[0], 2) + pow (P2[1] - P1[1], 2));
}


closeEnough

decompiled_code:
bool __fastcall closeEnough(double a1, double a2)
{
return (int)(a1 * 1000000.0) == (int)(a2 * 1000000.0);
}

canonical_decompiled_code:
bool __fastcall func9(double a1, double a2)
{
return (int)(a1 * 1000000.0) == (int)(a2 * 1000000.0);
}

original_code:
_Bool closeEnough(double firstValue, double secondValue)
{
  int firstRounded = firstValue*1000000;
  int secondRounded = secondValue*1000000;
  if(firstRounded == secondRounded)
    {
      return 1;
    }
  else
    {
      return 0;
    }
}

variable_types: firstValue double

variable_types: secondValue double

variable_types: firstRounded int

variable_types: secondRounded int


checkAngles

decompiled_code:
char __fastcall checkAngles(const char *a1, double a2, double a3, double a4)
{
double v4; // xmm3_8
double v5; // xmm4_8
double v6; // xmm4_8
char result; // al
double v8; // xmm4_8
double v9; // [rsp+8h] [rbp-38h]
double v10; // [rsp+18h] [rbp-28h]
double v11; // [rsp+20h] [rbp-20h]
double v13; // [rsp+30h] [rbp-10h]

v9 = a2 * a2;
v10 = acos((a3 * a3 - a2 * a2 + a4 * a4) / ((a3 + a3) * a4));
v11 = a2 + a2;
v13 = acos((a4 * a4 + v9 - a3 * a3) / (a4 * (a2 + a2)));
v4 = acos((a3 * a3 + v9 - a4 * a4) / (v11 * a3));
if ( closeEnough(v10, 1.570796326794897) )
return printf("%s right\n", a1);
if ( closeEnough(v13, v5) )
return printf("%s right\n", a1);
result = closeEnough(v4, v6);
if ( result )
return printf("%s right\n", a1);
if ( v10 > v8 || v13 > v8 || v4 > v8 )
return printf("%s obtuse\n", a1);
if ( v8 > v10 && v8 > v13 && v8 > v4 )
result = printf("%s acute\n", a1);
return result;
}

canonical_decompiled_code:
char __fastcall func10(const char *a1, double a2, double a3, double a4)
{
double v4; // xmm3_8
double v5; // xmm4_8
double v6; // xmm4_8
char result; // al
double v8; // xmm4_8
double v9; // [rsp+8h] [rbp-38h]
double v10; // [rsp+18h] [rbp-28h]
double v11; // [rsp+20h] [rbp-20h]
double v13; // [rsp+30h] [rbp-10h]

v9 = a2 * a2;
v10 = acos((a3 * a3 - a2 * a2 + a4 * a4) / ((a3 + a3) * a4));
v11 = a2 + a2;
v13 = acos((a4 * a4 + v9 - a3 * a3) / (a4 * (a2 + a2)));
v4 = acos((a3 * a3 + v9 - a4 * a4) / (v11 * a3));
if ( func9(v10, 1.570796326794897) )
return printf("%s right\n", a1);
if ( func9(v13, v5) )
return printf("%s right\n", a1);
result = func9(v4, v6);
if ( result )
return printf("%s right\n", a1);
if ( v10 > v8 || v13 > v8 || v4 > v8 )
return printf("%s obtuse\n", a1);
if ( v8 > v10 && v8 > v13 && v8 > v4 )
result = printf("%s acute\n", a1);
return result;
}

original_code:
void checkAngles(double a, double b, double c, char* result)
{
  double ninteyDegrees = 3.14159265358979323846/2;
  double A = acos((-pow(a, 2) + pow(b, 2) + pow(c, 2))/(2*b*c));
  double B = acos((pow(a, 2) - pow(b, 2) + pow(c, 2))/(2*a*c));
  double C = acos((pow(a, 2) + pow(b, 2) - pow(c, 2))/(2*a*b));
  if(closeEnough(A, ninteyDegrees) || closeEnough(B, ninteyDegrees) || closeEnough(C, ninteyDegrees))
    {
      printf("%s right\n", result);
    }
  else if (A > ninteyDegrees || B > ninteyDegrees || C > ninteyDegrees)
    {
      printf("%s obtuse\n", result);
    }
  else if (A < ninteyDegrees && B < ninteyDegrees && C < ninteyDegrees)
    {
      printf("%s acute\n", result);
    }
}

canonical_original_code:
void checkAngles(double a, double b, double c, char *result)
{
  double ninteyDegrees = 3.14159265358979323846/2;
  double A = acos((-pow(a, 2) + pow(b, 2) + pow(c, 2))/(2*b*c));
  double B = acos((pow(a, 2) - pow(b, 2) + pow(c, 2))/(2*a*c));
  double C = acos((pow(a, 2) + pow(b, 2) - pow(c, 2))/(2*a*b));
  if(closeEnough(A, ninteyDegrees) || closeEnough(B, ninteyDegrees) || closeEnough(C, ninteyDegrees))
    {
      printf("%s right\n", result);
    }
  else if (A > ninteyDegrees || B > ninteyDegrees || C > ninteyDegrees)
    {
      printf("%s obtuse\n", result);
    }
  else if (A < ninteyDegrees && B < ninteyDegrees && C < ninteyDegrees)
    {
      printf("%s acute\n", result);
    }
}

variable_types: a double

variable_types: b double

variable_types: c double

variable_types:
result
char *

variable_types: ninteyDegrees double

variable_types: A double

variable_types: B double

variable_types: C double


checkTriangle

decompiled_code:
char __fastcall checkTriangle(_DWORD *a1, _DWORD *a2, _DWORD *a3, double a4)
{
computeSide(a1, a2);
computeSide(a2, a3);
computeSide(a1, a3);
return checkAngles("equilateral", a4, a4, a4);
}

canonical_decompiled_code:
char __fastcall func11(_DWORD *a1, _DWORD *a2, _DWORD *a3, double a4)
{
func8(a1, a2);
func8(a2, a3);
func8(a1, a3);
return func10("equilateral", a4, a4, a4);
}

original_code:
void checkTriangle(int* P1, int* P2, int* P3)
{
  char* result = "";
  double S1 = computeSide(P1, P2);
  double S2 = computeSide(P2, P3);
  double S3 = computeSide(P1, P3);
  if(S1 == S2 && S1 == S3 && S2 == S3)
    {
      result = "equilateral";
    }
  else if(S1 == S2 || S1 == S3 || S2 == S3)
    {
      result = "isosceles";
    }
  else
    {
      result = "scalene";
    }
  checkAngles(S1, S2, S3, result);
}

canonical_original_code:
void checkTriangle(int *P1, int *P2, int *P3)
{
  char *result = "";
  double S1 = computeSide(P1, P2);
  double S2 = computeSide(P2, P3);
  double S3 = computeSide(P1, P3);
  if(S1 == S2 && S1 == S3 && S2 == S3)
    {
      result = "equilateral";
    }
  else if(S1 == S2 || S1 == S3 || S2 == S3)
    {
      result = "isosceles";
    }
  else
    {
      result = "scalene";
    }
  checkAngles(S1, S2, S3, result);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // r13
_DWORD *v4; // r12
_DWORD *v5; // rbp
int v6; // eax
const char *v7; // rdi
int v8; // eax
const char *v9; // rdi
int v10; // eax
const char *v11; // rdi
int v12; // eax
const char *v13; // rdi
int v14; // eax
const char *v15; // rdi

v3 = malloc(8uLL);
v4 = malloc(8uLL);
v5 = malloc(8uLL);
v6 = atoi(argv[1]);
v7 = argv[2];
*v3 = v6;
v8 = atoi(v7);
v9 = argv[3];
v3[1] = v8;
v10 = atoi(v9);
v11 = argv[4];
*v4 = v10;
v12 = atoi(v11);
v13 = argv[5];
v4[1] = v12;
v14 = atoi(v13);
v15 = argv[6];
*v5 = v14;
v5[1] = atoi(v15);
if ( checkCollinearity(v3, v4, v5) == 0.0 )
{
puts("not a triangle");
exit(0);
}
checkTriangle(v3, v4, v5);
free(v3);
free(v4);
free(v5);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // r13
_DWORD *v4; // r12
_DWORD *v5; // rbp
int v6; // eax
const char *v7; // rdi
int v8; // eax
const char *v9; // rdi
int v10; // eax
const char *v11; // rdi
int v12; // eax
const char *v13; // rdi
int v14; // eax
const char *v15; // rdi

v3 = malloc(8uLL);
v4 = malloc(8uLL);
v5 = malloc(8uLL);
v6 = atoi(argv[1]);
v7 = argv[2];
*v3 = v6;
v8 = atoi(v7);
v9 = argv[3];
v3[1] = v8;
v10 = atoi(v9);
v11 = argv[4];
*v4 = v10;
v12 = atoi(v11);
v13 = argv[5];
v4[1] = v12;
v14 = atoi(v13);
v15 = argv[6];
*v5 = v14;
v5[1] = atoi(v15);
if ( func7(v3, v4, v5) == 0.0 )
{
puts("not a triangle");
exit(0);
}
func11(v3, v4, v5);
free(v3);
free(v4);
free(v5);
exit(0);
}

original_code:
int main(int argc, char* argv[])
{
  int *P1 = malloc(2*sizeof(int));
  int *P2 = malloc(2*sizeof(int));
  int *P3 = malloc(2*sizeof(int));
  P1[0] = atoi(argv[1]);
  P1[1] = atoi(argv[2]);
  P2[0] = atoi(argv[3]);
  P2[1] = atoi(argv[4]);
  P3[0] = atoi(argv[5]);
  P3[1] = atoi(argv[6]);
  double area = checkCollinearity(P1, P2, P3);
  if (checkCollinearity(P1, P2, P3) == 0.0)
    {
      printf("not a triangle\n");
      exit(0);
    }
  checkTriangle(P1, P2, P3);
  free(P1);
  free(P2);
  free(P3);
  exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int *P1 = malloc(2*sizeof(int));
  int *P2 = malloc(2*sizeof(int));
  int *P3 = malloc(2*sizeof(int));
  P1[0] = atoi(argv[1]);
  P1[1] = atoi(argv[2]);
  P2[0] = atoi(argv[3]);
  P2[1] = atoi(argv[4]);
  P3[0] = atoi(argv[5]);
  P3[1] = atoi(argv[6]);
  double area = checkCollinearity(P1, P2, P3);
  if (checkCollinearity(P1, P2, P3) == 0.0)
    {
      printf("not a triangle\n");
      exit(0);
    }
  checkTriangle(P1, P2, P3);
  free(P1);
  free(P2);
  free(P3);
  exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: area double


decompiled_code:
__int64 __fastcall compare_huff_trees(const void *a1, const void *a2)
{
__int64 v2; // rdx
__int64 v3; // rax
int v4; // ecx
__int64 result; // rax

v2 = *(_QWORD *)a1;
if ( !*(_QWORD *)a1 )
return 0xFFFFFFFFLL;
v3 = *(_QWORD *)a2;
if ( !*(_QWORD *)a2 )
return 1LL;
v4 = *(_DWORD *)(v3 + 16);
if ( *(_DWORD *)(v2 + 16) == v4 )
result = (unsigned int)(*(_DWORD *)(v3 + 24) - *(_DWORD *)(v2 + 24));
else
result = 2 * (unsigned int)(*(_DWORD *)(v2 + 16) < v4) - 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
__int64 v2; // rdx
__int64 v3; // rax
int v4; // ecx
__int64 result; // rax

v2 = *(_QWORD *)a1;
if ( !*(_QWORD *)a1 )
return 0xFFFFFFFFLL;
v3 = *(_QWORD *)a2;
if ( !*(_QWORD *)a2 )
return 1LL;
v4 = *(_DWORD *)(v3 + 16);
if ( *(_DWORD *)(v2 + 16) == v4 )
result = (unsigned int)(*(_DWORD *)(v3 + 24) - *(_DWORD *)(v2 + 24));
else
result = 2 * (unsigned int)(*(_DWORD *)(v2 + 16) < v4) - 1;
return result;
}

original_code:
int compare_huff_trees (const void *a, const void *b)
{
 const huff_tree **t1 = (const huff_tree **) a;
 const huff_tree **t2 = (const huff_tree **) b;
    if (((void *)0) == *t1) return -1;
    if (((void *)0) == *t2) return 1;
 if((*t1)->frequency == (*t2)->frequency) {
        return ((*t2)->lowest - (*t1)->lowest);
 } else {
  return ((*t1)->frequency < (*t2)->frequency) ? 1 : -1;
 }
}

canonical_original_code:
int compare_huff_trees(void *a, void *b)
{
 struct huff_tree **t1 = (const huff_tree **) a;
 struct huff_tree **t2 = (const huff_tree **) b;
    if (((void *)0) == *t1) return -1;
    if (((void *)0) == *t2) return 1;
 if((*t1)->frequency == (*t2)->frequency) {
        return ((*t2)->lowest - (*t1)->lowest);
 } else {
  return ((*t1)->frequency < (*t2)->frequency) ? 1 : -1;
 }
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct huff_tree { struct huff_tree *zero_tree; struct huff_tree *one_tree; int frequency; int character; int lowest; } **


decompiled_code:
__int64 __fastcall check_tree_df(__int64 a1)
{
unsigned int v1; // er12
int v3; // eax

if ( *(_QWORD *)a1 )
{
v1 = check_tree_df();
if ( !*(_QWORD *)(a1 + 8) )
goto LABEL_3;
goto LABEL_6;
}
v1 = 0;
if ( *(_QWORD *)(a1 + 8) )
{
LABEL_6:
v1 += check_tree_df();
LABEL_3:
if ( *(_DWORD *)(a1 + 16) != v1 )
_assert_fail("left_freq + right_freq == node->frequency", "huff_table.c", 0x17u, "check_tree_df");
return v1;
}
v3 = *(_DWORD *)(a1 + 20);
if ( v3 > 256 )
_assert_fail("node->character < 257", "huff_table.c", 0xEu, "check_tree_df");
if ( v3 < 0 )
_assert_fail("node->character >= 0", "huff_table.c", 0xFu, "check_tree_df");
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // er12
int v3; // eax

if ( *(_QWORD *)a1 )
{
v1 = func1();
if ( !*(_QWORD *)(a1 + 8) )
goto LABEL_3;
goto LABEL_6;
}
v1 = 0;
if ( *(_QWORD *)(a1 + 8) )
{
LABEL_6:
v1 += func1();
LABEL_3:
if ( *(_DWORD *)(a1 + 16) != v1 )
_assert_fail("left_freq + right_freq == node->frequency", "huff_table.c", 0x17u, "check_tree_df");
return v1;
}
v3 = *(_DWORD *)(a1 + 20);
if ( v3 > 256 )
_assert_fail("node->character < 257", "huff_table.c", 0xEu, "check_tree_df");
if ( v3 < 0 )
_assert_fail("node->character >= 0", "huff_table.c", 0xFu, "check_tree_df");
return *(unsigned int *)(a1 + 16);
}

original_code:
int check_tree_df (huff_tree *node)
{
    int left_freq = 0, right_freq = 0;
    if (!node->zero_tree && ! node->one_tree) {
     ((void) sizeof ((node->character < 257) ? 1 : 0), __extension__ ({ if (node->character < 257) ; else __assert_fail ("node->character < 257", "huff_table.c", 14, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((node->character >= 0) ? 1 : 0), __extension__ ({ if (node->character >= 0) ; else __assert_fail ("node->character >= 0", "huff_table.c", 15, __extension__ __PRETTY_FUNCTION__); }));
     return node->frequency;
    }
    if (node->zero_tree) left_freq = check_tree_df(node->zero_tree);
    if (node->one_tree) right_freq = check_tree_df(node->one_tree);
    ((void) sizeof ((left_freq + right_freq == node->frequency) ? 1 : 0), __extension__ ({ if (left_freq + right_freq == node->frequency) ; else __assert_fail ("left_freq + right_freq == node->frequency", "huff_table.c", 23, __extension__ __PRETTY_FUNCTION__); }));
    return node->frequency;
}

canonical_original_code:
int check_tree_df(struct huff_tree *node)
{
    int left_freq = 0; int right_freq = 0;
    if (!node->zero_tree && ! node->one_tree) {
     ((void) sizeof ((node->character < 257) ? 1 : 0), __extension__ ({ if (node->character < 257) ; else __assert_fail ("node->character < 257", "huff_table.c", 14, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((node->character >= 0) ? 1 : 0), __extension__ ({ if (node->character >= 0) ; else __assert_fail ("node->character >= 0", "huff_table.c", 15, __extension__ __PRETTY_FUNCTION__); }));
     return node->frequency;
    }
    if (node->zero_tree) left_freq = check_tree_df(node->zero_tree);
    if (node->one_tree) right_freq = check_tree_df(node->one_tree);
    ((void) sizeof ((left_freq + right_freq == node->frequency) ? 1 : 0), __extension__ ({ if (left_freq + right_freq == node->frequency) ; else __assert_fail ("left_freq + right_freq == node->frequency", "huff_table.c", 23, __extension__ __PRETTY_FUNCTION__); }));
    return node->frequency;
}

variable_types: struct huff_tree { struct huff_tree *zero_tree; struct huff_tree *one_tree; int frequency; int character; int lowest; } *


decompiled_code:
__int64 __fastcall count_leaf_nodes(_QWORD *a1)
{
int v1; // ebp
int v3; // eax

v1 = 0;
while ( !*a1 )
{
LABEL_5:
a1 = (_QWORD *)a1[1];
if ( !a1 )
{
v3 = 1;
return (unsigned int)(v1 + v3);
}
}
while ( 1 )
{
v3 = count_leaf_nodes();
a1 = (_QWORD *)a1[1];
if ( !a1 )
return (unsigned int)(v1 + v3);
v1 += v3;
if ( !*a1 )
goto LABEL_5;
}
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
int v1; // ebp
int v3; // eax

v1 = 0;
while ( !*a1 )
{
LABEL_5:
a1 = (_QWORD *)a1[1];
if ( !a1 )
{
v3 = 1;
return (unsigned int)(v1 + v3);
}
}
while ( 1 )
{
v3 = func2();
a1 = (_QWORD *)a1[1];
if ( !a1 )
return (unsigned int)(v1 + v3);
v1 += v3;
if ( !*a1 )
goto LABEL_5;
}
}

original_code:
int count_leaf_nodes (huff_tree *node)
{
    int l_count = 0, r_count = 0;
    if (!node->zero_tree && !node->one_tree) return 1;
    if (node->zero_tree) l_count = count_leaf_nodes(node->zero_tree);
    if (node->one_tree) r_count = count_leaf_nodes(node->one_tree);
    return l_count + r_count;
}

canonical_original_code:
int count_leaf_nodes(struct huff_tree *node)
{
    int l_count = 0; int r_count = 0;
    if (!node->zero_tree && !node->one_tree) return 1;
    if (node->zero_tree) l_count = count_leaf_nodes(node->zero_tree);
    if (node->one_tree) r_count = count_leaf_nodes(node->one_tree);
    return l_count + r_count;
}

user_defined_types: struct huff_tree { struct huff_tree *zero_tree; struct huff_tree *one_tree; int frequency; int character; int lowest; }


decompiled_code:
size_t __fastcall check_rep_tree(_QWORD *a1)
{
if ( !a1 )
_assert_fail("tree", "huff_table.c", 0x2Eu, "check_rep_tree");
check_tree_df((__int64)a1);
if ( (int)count_leaf_nodes(a1) > 265 )
_assert_fail("num_leaf_nodes <= 265", "huff_table.c", 0x35u, "check_rep_tree");
return fwrite("OK\n", 1uLL, 3uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func3(_QWORD *a1)
{
if ( !a1 )
_assert_fail("tree", "huff_table.c", 0x2Eu, "check_rep_tree");
func1((__int64)a1);
if ( (int)func2(a1) > 265 )
_assert_fail("num_leaf_nodes <= 265", "huff_table.c", 0x35u, "check_rep_tree");
return fwrite("OK\n", 1uLL, 3uLL, stderr);
}

original_code:
void check_rep_tree (huff_tree *tree)
{
    ((void) sizeof ((tree) ? 1 : 0), __extension__ ({ if (tree) ; else __assert_fail ("tree", "huff_table.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    check_tree_df(tree);
    int num_leaf_nodes = count_leaf_nodes(tree);
    ((void) sizeof ((num_leaf_nodes <= 265) ? 1 : 0), __extension__ ({ if (num_leaf_nodes <= 265) ; else __assert_fail ("num_leaf_nodes <= 265", "huff_table.c", 53, __extension__ __PRETTY_FUNCTION__); }));
    fprintf(stderr, "OK\n");
}

canonical_original_code:
void check_rep_tree(struct huff_tree *tree)
{
    ((void) sizeof ((tree) ? 1 : 0), __extension__ ({ if (tree) ; else __assert_fail ("tree", "huff_table.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    check_tree_df(tree);
    int num_leaf_nodes = count_leaf_nodes(tree);
    ((void) sizeof ((num_leaf_nodes <= 265) ? 1 : 0), __extension__ ({ if (num_leaf_nodes <= 265) ; else __assert_fail ("num_leaf_nodes <= 265", "huff_table.c", 53, __extension__ __PRETTY_FUNCTION__); }));
    fprintf(stderr, "OK\n");
}


decompiled_code:
void __fastcall free_huff_table(void **a1)
{
void **v1; // rbx

v1 = a1;
do
{
if ( *v1 )
free(*v1);
++v1;
}
while ( v1 != a1 + 256 );
}

canonical_decompiled_code:
void __fastcall func5(void **a1)
{
void **v1; // rbx

v1 = a1;
do
{
if ( *v1 )
free(*v1);
++v1;
}
while ( v1 != a1 + 256 );
}

original_code:
void free_huff_table (char *huff_table[])
{
 int i;
 for(i=0; i < 256; i++) {
  if(huff_table[i]) {
   free(huff_table[i]);
  }
 }
}

canonical_original_code:
void free_huff_table(char *huff_table[])
{
 int i;
 for(i=0; i < 256; i++) {
  if(huff_table[i]) {
   free(huff_table[i]);
  }
 }
}

variable_types: i int


decompiled_code:
char *__fastcall concat_characters(const char *a1, char a2)
{
size_t v2; // rax
char *v3; // r13

if ( !a1 )
_assert_fail("prefix != NULL", "huff_table.c", 0x55u, "concat_characters");
v2 = strlen(a1);
v3 = (char *)malloc(v2 + 2);
if ( sprintf(v3, "%s%c", a1, (unsigned int)a2) < 0 )
{
puts("Failed to sprintf the new prefix.");
exit(255);
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func6(const char *a1, char a2)
{
size_t v2; // rax
char *v3; // r13

if ( !a1 )
_assert_fail("prefix != NULL", "huff_table.c", 0x55u, "concat_characters");
v2 = strlen(a1);
v3 = (char *)malloc(v2 + 2);
if ( sprintf(v3, "%s%c", a1, (unsigned int)a2) < 0 )
{
puts("Failed to sprintf the new prefix.");
exit(255);
}
return v3;
}

original_code:
char *concat_characters (char *prefix, char new_char)
{
    ((void) sizeof ((prefix != ((void *)0)) ? 1 : 0), __extension__ ({ if (prefix != ((void *)0)) ; else __assert_fail ("prefix != NULL", "huff_table.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    char *new_prefix = (char *)malloc(strlen(prefix) + 2);
    if (sprintf(new_prefix, "%s%c", prefix, new_char) < 0) {
        printf("Failed to sprintf the new prefix.\n");
        exit(255);
    }
    return new_prefix;
}

canonical_original_code:
char *concat_characters(char *prefix, char new_char)
{
    ((void) sizeof ((prefix != ((void *)0)) ? 1 : 0), __extension__ ({ if (prefix != ((void *)0)) ; else __assert_fail ("prefix != NULL", "huff_table.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    char *new_prefix = (char *)malloc(strlen(prefix) + 2);
    if (sprintf(new_prefix, "%s%c", prefix, new_char) < 0) {
        printf("Failed to sprintf the new prefix.\n");
        exit(255);
    }
    return new_prefix;
}

variable_types:
prefix
char *

return_type: char *


decompiled_code:
void __fastcall traverse_huff_tree(__int64 a1, __int64 a2, char *a3)
{
size_t v4; // r12
void *v5; // r15
void *v6; // r14
char *v7; // rax
char *v8; // rax

if ( *(_QWORD *)a1 || *(_QWORD *)(a1 + 8) )
{
v4 = strlen(a3) + 1;
v5 = malloc(v4);
v6 = malloc(v4);
memcpy(v5, a3, v4);
memcpy(v6, a3, v4);
free(a3);
if ( *(_QWORD *)a1 )
{
v7 = concat_characters((const char *)v6, 48);
traverse_huff_tree(*(_QWORD *)a1, a2, v7);
}
if ( *(_QWORD *)(a1 + 8) )
{
v8 = concat_characters((const char *)v5, 49);
traverse_huff_tree(*(_QWORD *)(a1 + 8), a2, v8);
}
free(v5);
free(v6);
}
else
{
*(_QWORD *)(a2 + 8LL * *(int *)(a1 + 20)) = a3;
}
}

original_code:
void traverse_huff_tree (huff_tree *tree, char **table, char *prefix)
{
    if(!tree->zero_tree && !tree->one_tree) {
     table[tree->character] = prefix;
    } else {
        char *one_prefix = (char *)malloc(strlen(prefix) + 1);
        char *zero_prefix = (char *)malloc(strlen(prefix) + 1);
        strcpy(one_prefix, prefix);
        strcpy(zero_prefix, prefix);
        free(prefix);
        if(tree->zero_tree) {
         traverse_huff_tree(tree->zero_tree, table, concat_characters(zero_prefix, '0'));
        }
        if(tree->one_tree) {
         traverse_huff_tree(tree->one_tree, table, concat_characters(one_prefix, '1'));
        }
        free(one_prefix);
        free(zero_prefix);
    }
}

canonical_original_code:
void traverse_huff_tree(struct huff_tree *tree, char **table, char *prefix)
{
    if(!tree->zero_tree && !tree->one_tree) {
     table[tree->character] = prefix;
    } else {
        char *one_prefix = (char *)malloc(strlen(prefix) + 1);
        char *zero_prefix = (char *)malloc(strlen(prefix) + 1);
        strcpy(one_prefix, prefix);
        strcpy(zero_prefix, prefix);
        free(prefix);
        if(tree->zero_tree) {
         traverse_huff_tree(tree->zero_tree, table, concat_characters(zero_prefix, '0'));
        }
        if(tree->one_tree) {
         traverse_huff_tree(tree->one_tree, table, concat_characters(one_prefix, '1'));
        }
        free(one_prefix);
        free(zero_prefix);
    }
}

variable_types:
table
char **


decompiled_code:
void *__fastcall build_huff_table(__int64 a1)
{
char *v1; // r12
_QWORD *v2; // rbp

v1 = (char *)calloc(1uLL, 8uLL);
v2 = build_huff_tree(a1);
traverse_huff_tree((__int64)v2, (__int64)&huff_table_0, v1);
if ( CHECK_REP )
check_rep_tree(v2);
free_huff_tree(v2);
return &huff_table_0;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1)
{
char *v1; // r12
_QWORD *v2; // rbp

v1 = (char *)calloc(1uLL, 8uLL);
v2 = build_huff_tree(a1);
func7((__int64)v2, (__int64)&huff_table_0, v1);
if ( CHECK_REP )
func3(v2);
func4(v2);
return &huff_table_0;
}

original_code:
char **build_huff_table (int frequencies[])
{
    static char *huff_table[256];
    char *prefix = (char *)calloc(1, sizeof(char *));
    *prefix = '\0';
    huff_tree *tree = build_huff_tree(frequencies);
    traverse_huff_tree(tree, huff_table, prefix);
    if (CHECK_REP) check_rep_tree(tree);
    free_huff_tree(tree);
    return huff_table;
}

canonical_original_code:
char **build_huff_table(int frequencies[])
{
    static char *huff_table[256];
    char *prefix = (char *)calloc(1, sizeof(char *));
    *prefix = '\0';
    struct huff_tree *tree = build_huff_tree(frequencies);
    traverse_huff_tree(tree, huff_table, prefix);
    if (CHECK_REP) check_rep_tree(tree);
    free_huff_tree(tree);
    return huff_table;
}

variable_types:
frequencies
int []

return_type: char **


decompiled_code:
void __fastcall free_huff_tree(void *ptr)
{
if ( ptr )
{
free_huff_tree(*(void **)ptr);
free_huff_tree(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
if ( ptr )
{
func4(*(void **)ptr);
func4(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void free_huff_tree (huff_tree *tree)
{
 if(tree) {
  free_huff_tree(tree->zero_tree);
  free_huff_tree(tree->one_tree);
  free(tree);
 }
}

canonical_original_code:
void free_huff_tree(struct huff_tree *tree)
{
 if(tree) {
  free_huff_tree(tree->zero_tree);
  free_huff_tree(tree->one_tree);
  free(tree);
 }
}


decompiled_code:
bool __fastcall is_leaf(__int64 a1)
{
bool result; // al

result = 0;
if ( !*(_QWORD *)(a1 + 264) )
result = *(_QWORD *)(a1 + 272) == 0LL;
return result;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
bool result; // al

result = 0;
if ( !*(_QWORD *)(a1 + 264) )
result = *(_QWORD *)(a1 + 272) == 0LL;
return result;
}

original_code:
_Bool is_leaf(node *n)
{
    if (n->left != ((void *)0) || n->right != ((void *)0))
        return 0;
    return 1;
}

canonical_original_code:
_Bool is_leaf(struct node *n)
{
    if (n->left != ((void *)0) || n->right != ((void *)0))
        return 0;
    return 1;
}

variable_types: struct node { char code[257]; struct node *left; struct node *right; unsigned long freq; _Bool visited; unsigned char c; unsigned char lowest; } *


decompiled_code:
void *malloc_n()
{
void *result; // rax

result = malloc(0x128uLL);
if ( !result )
{
fwrite("Failed to allocate memory.", 1uLL, 0x1AuLL, stderr);
exit(255);
}
return result;
}

canonical_decompiled_code:
void *func2()
{
void *result; // rax

result = malloc(0x128uLL);
if ( !result )
{
fwrite("Failed to allocate memory.", 1uLL, 0x1AuLL, stderr);
exit(255);
}
return result;
}

original_code:
node * malloc_n(node *n)
{
    n = (node*)malloc(sizeof(node));
    if (n == ((void *)0))
    {
        fprintf(stderr, "Failed to allocate memory.");
        exit(255);
    }
    return n;
}

canonical_original_code:
struct node *malloc_n(struct node *n)
{
    n = (struct node *)malloc(sizeof(node));
    if (n == ((void *)0))
    {
        fprintf(stderr, "Failed to allocate memory.");
        exit(255);
    }
    return n;
}

variable_types:
n
struct node *

return_type: struct node { char code[257]; struct node *left; struct node *right; unsigned long freq; _Bool visited; unsigned char c; unsigned char lowest; } *


decompiled_code:
__int64 __fastcall init_node(_QWORD *a1, char a2)
{
char *v2; // rdx
__int64 result; // rax

v2 = (char *)malloc_n();
*a1 = v2;
*(_QWORD *)v2 = 0LL;
*(_QWORD *)(v2 + 249) = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(v2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v2 - (((_DWORD)v2 + 8) & 0xFFFFFFF8) + 257) >> 3));
v2[288] = 0;
*((_QWORD *)v2 + 33) = 0LL;
*((_QWORD *)v2 + 34) = 0LL;
*((_QWORD *)v2 + 35) = 0LL;
v2[289] = a2;
v2[290] = a2;
return result;
}

canonical_original_code:
void init_node(struct node **n, char c)
{
    (*n) = malloc_n(*n);
    for (int i = 0; i < 257; i++)
        (*n)->code[i] = 0;
    (*n)->left = ((void *)0);
    (*n)->right = ((void *)0);
    (*n)->freq = 0;
    (*n)->visited = 0;
    (*n)->c = c;
    (*n)->lowest = c;
}

variable_types: struct node { char code[257]; struct node *left; struct node *right; unsigned long freq; _Bool visited; unsigned char c; unsigned char lowest; } **

variable_types: c char


decompiled_code:
void free_huff_tree()
{
void **v0; // rbx
void *v1; // rdi

v0 = (void **)&all_nodes;
do
{
v1 = *v0++;
free(v1);
}
while ( v0 != (void **)((char *)&all_nodes + 4088) );
}

canonical_decompiled_code:
void func0()
{
void **v0; // rbx
void *v1; // rdi

v0 = (void **)&all_nodes;
do
{
v1 = *v0++;
free(v1);
}
while ( v0 != (void **)((char *)&all_nodes + 4088) );
}

original_code:
void free_huff_tree()
{
    for (int i = 0; i < 511; i++)
        free(all_nodes[i]);
}


printHuffResultArray

decompiled_code:
int __fastcall printHuffResultArray(const char **a1)
{
const char **v1; // rbp
const char **v2; // rbx
const char *v3; // rdi
int result; // eax

v1 = a1 + 512;
v2 = a1;
do
{
v3 = *v2;
v2 += 2;
result = puts(v3);
}
while ( v2 != v1 );
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char **a1)
{
const char **v1; // rbp
const char **v2; // rbx
const char *v3; // rdi
int result; // eax

v1 = a1 + 512;
v2 = a1;
do
{
v3 = *v2;
v2 += 2;
result = puts(v3);
}
while ( v2 != v1 );
return result;
}

original_code:
void printHuffResultArray(huffResult *resultArray)
{
        for(int i = 0; i < 256; i++)
        {
            huffResult * currentResult = &resultArray[i];
            printf("%s\n", currentResult->string);
        }
}

canonical_original_code:
void printHuffResultArray(struct huffResult *resultArray)
{
        for(int i = 0; i < 256; i++)
        {
            struct huffResult *currentResult = &resultArray[i];
            printf("%s\n", currentResult->string);
        }
}

variable_types: struct huffResult { char *string; int value; } *


minNode

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

if ( a2 > 0x1FF )
_assert_fail("count >= 0 && count < 512", "encoder.c", 0xA8u, "minNode");
if ( a2 )
{
v2 = a1 + 40LL * (a2 - 1) + 40;
result = 0LL;
while ( 1 )
{
while ( *(_DWORD *)(a1 + 12) )
{
LABEL_7:
a1 += 40LL;
if ( a1 == v2 )
return result;
}
if ( result && *(_QWORD *)a1 >= *(_QWORD *)result )
{
if ( *(_QWORD *)a1 == *(_QWORD *)result && *(_DWORD *)(a1 + 8) < *(_DWORD *)(result + 8) )
result = a1;
goto LABEL_7;
}
result = a1;
a1 += 40LL;
if ( a1 == v2 )
return result;
}
}
return 0LL;
}

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

if ( a2 > 0x1FF )
_assert_fail("count >= 0 && count < 512", "encoder.c", 0xA8u, "minNode");
if ( a2 )
{
v2 = a1 + 40LL * (a2 - 1) + 40;
result = 0LL;
while ( 1 )
{
while ( *(_DWORD *)(a1 + 12) )
{
LABEL_7:
a1 += 40LL;
if ( a1 == v2 )
return result;
}
if ( result && *(_QWORD *)a1 >= *(_QWORD *)result )
{
if ( *(_QWORD *)a1 == *(_QWORD *)result && *(_DWORD *)(a1 + 8) < *(_DWORD *)(result + 8) )
result = a1;
goto LABEL_7;
}
result = a1;
a1 += 40LL;
if ( a1 == v2 )
return result;
}
}
return 0LL;
}

original_code:
huffNode* minNode(huffNode nodes[512], int count)
{
    ((count >= 0 && count < 512) ? (void) (0) : __assert_fail ("count >= 0 && count < 512", "encoder.c", 168, __extension__ __PRETTY_FUNCTION__));
    huffNode *lowestNode = ((void *)0);
    for (int i = 0; i < count; i++)
    {
        huffNode *currentNode = &nodes[i];
        if (currentNode->used) continue;
        if (lowestNode == ((void *)0) ||
            currentNode->sum < lowestNode->sum ||
            (currentNode->sum == lowestNode->sum &&
                currentNode->byte < lowestNode->byte))
        {
            lowestNode = currentNode;
        }
    }
    return lowestNode;
}

canonical_original_code:
struct huffNode *minNode(struct huffNode nodes[512], int count)
{
    ((count >= 0 && count < 512) ? (void) (0) : __assert_fail ("count >= 0 && count < 512", "encoder.c", 168, __extension__ __PRETTY_FUNCTION__));
    struct huffNode *lowestNode = ((void *)0);
    for (int i = 0; i < count; i++)
    {
        struct huffNode *currentNode = &nodes[i];
        if (currentNode->used) continue;
        if (lowestNode == ((void *)0) ||
            currentNode->sum < lowestNode->sum ||
            (currentNode->sum == lowestNode->sum &&
                currentNode->byte < lowestNode->byte))
        {
            lowestNode = currentNode;
        }
    }
    return lowestNode;
}

variable_types:
nodes
struct huffNode [512]

variable_types: count int

variable_types: struct huffNode { long long sum; int byte; int used; struct huffNode *parent; struct huffNode *leftLeaf; struct huffNode *rightLeaf; } *


calculateTree

original_code:
huffNode* calculateTree(huffNode nodes[512], int count)
{
    ((count >= 0 && count < 512) ? (void) (0) : __assert_fail ("count >= 0 && count < 512", "encoder.c", 109, __extension__ __PRETTY_FUNCTION__));
    huffNode *lowestNode = minNode(nodes, count);
    ((lowestNode) ? (void) (0) : __assert_fail ("lowestNode", "encoder.c", 112, __extension__ __PRETTY_FUNCTION__));
    lowestNode->used = 1;
    huffNode *secondLowestNode = minNode(nodes, count);
    if (!secondLowestNode) return lowestNode;
    secondLowestNode->used = 1;
    ((count < 511) ? (void) (0) : __assert_fail ("count < 511", "encoder.c", 120, __extension__ __PRETTY_FUNCTION__));
    struct huffNode *newNode = &nodes[count];
    lowestNode->parent = newNode;
    secondLowestNode->parent = newNode;
    *newNode = (struct huffNode) {
        .sum = lowestNode->sum + secondLowestNode->sum,
        .byte = lowestNode->byte < secondLowestNode->byte ?
            lowestNode->byte : secondLowestNode->byte,
        .used = 0,
        .leftLeaf = lowestNode,
        .rightLeaf = secondLowestNode,
    };
    return calculateTree(nodes, count + 1);
}

canonical_original_code:
struct huffNode *calculateTree(struct huffNode nodes[512], int count)
{
    ((count >= 0 && count < 512) ? (void) (0) : __assert_fail ("count >= 0 && count < 512", "encoder.c", 109, __extension__ __PRETTY_FUNCTION__));
    struct huffNode *lowestNode = minNode(nodes, count);
    ((lowestNode) ? (void) (0) : __assert_fail ("lowestNode", "encoder.c", 112, __extension__ __PRETTY_FUNCTION__));
    lowestNode->used = 1;
    struct huffNode *secondLowestNode = minNode(nodes, count);
    if (!secondLowestNode) return lowestNode;
    secondLowestNode->used = 1;
    ((count < 511) ? (void) (0) : __assert_fail ("count < 511", "encoder.c", 120, __extension__ __PRETTY_FUNCTION__));
    struct huffNode *newNode = &nodes[count];
    lowestNode->parent = newNode;
    secondLowestNode->parent = newNode;
    *newNode = (struct huffNode) {
        .sum = lowestNode->sum + secondLowestNode->sum,
        .byte = lowestNode->byte < secondLowestNode->byte ?
            lowestNode->byte : secondLowestNode->byte,
        .used = 0,
        .leftLeaf = lowestNode,
        .rightLeaf = secondLowestNode,
    };
    return calculateTree(nodes, count + 1);
}

return_type: struct huffNode { long long sum; int byte; int used; struct huffNode *parent; struct huffNode *leftLeaf; struct huffNode *rightLeaf; } *


freeResultArray

decompiled_code:
void __fastcall freeResultArray(void *ptr)
{
void *v1; // r12
void **v2; // rbp
void **v3; // rbx
void *v4; // rdi

v1 = ptr;
v2 = (void **)((char *)ptr + 4096);
v3 = (void **)ptr;
do
{
v4 = *v3;
v3 += 2;
free(v4);
}
while ( v3 != v2 );
free(v1);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
void *v1; // r12
void **v2; // rbp
void **v3; // rbx
void *v4; // rdi

v1 = ptr;
v2 = (void **)((char *)ptr + 4096);
v3 = (void **)ptr;
do
{
v4 = *v3;
v3 += 2;
free(v4);
}
while ( v3 != v2 );
free(v1);
}

original_code:
void freeResultArray(huffResult *resultArray)
{
    for(int i = 0; i < 256; i++)
    {
        huffResult * currentResult = &resultArray[i];
        free(currentResult->string);
    }
    free(resultArray);
}

canonical_original_code:
void freeResultArray(struct huffResult *resultArray)
{
    for(int i = 0; i < 256; i++)
    {
        struct huffResult *currentResult = &resultArray[i];
        free(currentResult->string);
    }
    free(resultArray);
}

user_defined_types: struct huffResult { char *string; int value; }


countLeaves

decompiled_code:
__int64 __fastcall countLeaves(__int64 a1)
{
__int64 result; // rax
int v2; // ebx

if ( !a1 )
return 0LL;
v2 = countLeaves(*(_QWORD *)(a1 + 24));
result = v2 + (unsigned int)countLeaves(*(_QWORD *)(a1 + 32));
if ( !(_DWORD)result )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
int v2; // ebx

if ( !a1 )
return 0LL;
v2 = func8(*(_QWORD *)(a1 + 24));
result = v2 + (unsigned int)func8(*(_QWORD *)(a1 + 32));
if ( !(_DWORD)result )
result = 1LL;
return result;
}

original_code:
int countLeaves(huffNode *rootNode){
  if (rootNode) {
      int count = countLeaves(rootNode->leftLeaf)+
           countLeaves(rootNode->rightLeaf);
      return (count == 0) ? 1: count;
   }
   return 0;
}

canonical_original_code:
int countLeaves(struct huffNode *rootNode){
  if (rootNode) {
      int count = countLeaves(rootNode->leftLeaf)+
           countLeaves(rootNode->rightLeaf);
      return (count == 0) ? 1: count;
   }
   return 0;
}

user_defined_types: struct huffNode { long long sum; int byte; int used; struct huffNode *parent; struct huffNode *leftLeaf; struct huffNode *rightLeaf; }


checkTree

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

if ( !a1 )
_assert_fail("rootNode", "encoder.c", 0xCDu, "checkTree");
result = countLeaves(a1);
if ( (int)result > 256 )
_assert_fail("leafCount <= 256", "encoder.c", 0xCFu, "checkTree");
return result;
}

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

if ( !a1 )
_assert_fail("rootNode", "encoder.c", 0xCDu, "checkTree");
result = func8(a1);
if ( (int)result > 256 )
_assert_fail("leafCount <= 256", "encoder.c", 0xCFu, "checkTree");
return result;
}

original_code:
void checkTree(huffNode *rootNode){
  ((rootNode) ? (void) (0) : __assert_fail ("rootNode", "encoder.c", 205, __extension__ __PRETTY_FUNCTION__));
  int leafCount = countLeaves(rootNode);
  ((leafCount <= 256) ? (void) (0) : __assert_fail ("leafCount <= 256", "encoder.c", 207, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void checkTree(struct huffNode *rootNode){
  ((rootNode) ? (void) (0) : __assert_fail ("rootNode", "encoder.c", 205, __extension__ __PRETTY_FUNCTION__));
  int leafCount = countLeaves(rootNode);
  ((leafCount <= 256) ? (void) (0) : __assert_fail ("leafCount <= 256", "encoder.c", 207, __extension__ __PRETTY_FUNCTION__));
}

variable_types: leafCount int


checkValidCode

decompiled_code:
__int64 __fastcall checkValidCode(unsigned __int8 *a1)
{
__int64 result; // rax
unsigned __int8 *v2; // rdx

result = *a1;
if ( (_BYTE)result )
{
v2 = a1 + 1;
do
{
if ( (unsigned __int8)(result - 48) > 1u )
_assert_fail("c == '1' || c == '0'", "encoder.c", 0xF6u, "checkValidCode");
result = *v2++;
}
while ( (_BYTE)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1)
{
__int64 result; // rax
unsigned __int8 *v2; // rdx

result = *a1;
if ( (_BYTE)result )
{
v2 = a1 + 1;
do
{
if ( (unsigned __int8)(result - 48) > 1u )
_assert_fail("c == '1' || c == '0'", "encoder.c", 0xF6u, "checkValidCode");
result = *v2++;
}
while ( (_BYTE)result );
}
return result;
}

original_code:
void checkValidCode (char *s){
  int i = 0;
  while (s[i] != '\0') {
    char c = s[i];
    ((c == '1' || c == '0') ? (void) (0) : __assert_fail ("c == '1' || c == '0'", "encoder.c", 246, __extension__ __PRETTY_FUNCTION__));
    i++;
  }
}

canonical_original_code:
void checkValidCode(char *s){
  int i = 0;
  while (s[i] != '\0') {
    char c = s[i];
    ((c == '1' || c == '0') ? (void) (0) : __assert_fail ("c == '1' || c == '0'", "encoder.c", 246, __extension__ __PRETTY_FUNCTION__));
    i++;
  }
}

variable_types:
s
char *


checkTable

decompiled_code:
__int64 __fastcall checkTable(unsigned __int8 **a1)
{
unsigned __int8 **v1; // rbp
unsigned __int8 **v2; // rbx
unsigned __int8 *v3; // rdi
__int64 result; // rax

v1 = a1 + 512;
v2 = a1;
do
{
v3 = *v2;
v2 += 2;
result = checkValidCode(v3);
}
while ( v1 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 **a1)
{
unsigned __int8 **v1; // rbp
unsigned __int8 **v2; // rbx
unsigned __int8 *v3; // rdi
__int64 result; // rax

v1 = a1 + 512;
v2 = a1;
do
{
v3 = *v2;
v2 += 2;
result = func10(v3);
}
while ( v1 != v2 );
return result;
}

original_code:
void checkTable(huffResult *resultArray){
  int i;
  for (i = 0; i < 256; i++) {
    char *s = resultArray->string;
    checkValidCode(s);
    resultArray++;
  }
}

canonical_original_code:
void checkTable(struct huffResult *resultArray){
  int i;
  for (i = 0; i < 256; i++) {
    char *s = resultArray->string;
    checkValidCode(s);
    resultArray++;
  }
}


decompiled_code:
__int64 __fastcall create_freq_table(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
unsigned __int8 *v3; // rdx
__int64 result; // rax

if ( a3 )
{
v3 = &a2[a3];
do
{
result = *a2++;
++*(_QWORD *)(a1 + 8 * result);
}
while ( v3 != a2 );
}
return result;
}

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

if ( a3 )
{
v3 = &a2[a3];
do
{
result = *a2++;
++*(_QWORD *)(a1 + 8 * result);
}
while ( v3 != a2 );
}
return result;
}

original_code:
void create_freq_table(unsigned long long table[], uint8_t *rle, unsigned long long size) {
  int c;
  for(unsigned long long i = 0; i < size; i++) {
    c = rle[i];
    table[c]++;
  }
}

canonical_original_code:
void create_freq_table(unsigned long long table[], unsigned char *rle, unsigned long long size) {
  int c;
  for(unsigned long long i = 0; i < size; i++) {
    c = rle[i];
    table[c]++;
  }
}

variable_types:
table
unsigned long long []

variable_types:
rle
unsigned char *

variable_types:
size
unsigned long long

variable_types: c int

variable_types:
i
unsigned long long


decompiled_code:
bool __fastcall is_huff_type(const char *a1)
{
char *v1; // rax
bool result; // al

v1 = strrchr(a1, 46);
if ( v1 )
result = strcmp(v1, ".hurl") == 0;
else
result = 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func3(const char *a1)
{
char *v1; // rax
bool result; // al

v1 = strrchr(a1, 46);
if ( v1 )
result = strcmp(v1, ".hurl") == 0;
else
result = 0;
return result;
}

original_code:
_Bool is_huff_type(char *filename) {
  char *file_type = strrchr(filename, '.');
  if(file_type == ((void *)0))
    return 0;
  return (strcmp(file_type, ".hurl") == 0);
}

variable_types:
filename
char *


decompiled_code:
__int64 __fastcall determine_flag(_BYTE *a1)
{
if ( *a1 != 45 )
return 3LL;
if ( a1[1] == 99 && !a1[2] )
return 0LL;
if ( a1[1] == 100 && !a1[2] )
return 1LL;
if ( a1[1] != 116 || a1[2] )
return 3LL;
return 2LL;
}

original_code:
enum Flags determine_flag(char *user_flag) {
  if(strcmp(user_flag, "-c") == 0)
    return COMPRESS;
  else if(strcmp(user_flag, "-d") == 0)
    return DECOMPRESS;
  else if(strcmp(user_flag, "-t") == 0)
    return DUMP;
  else
    return INVALID;
}

return_type: enum Flags { COMPRESS=0, DECOMPRESS=1, DUMP=2, INVALID=3 }


findSide

decompiled_code:
long double __fastcall findSide(int a1, long double a2, long double a3, long double a4, long double a5)
{
long double v10; // fst7
long double v11; // fst6
long double v12; // fst7
long double v13; // fst6
double v14; // xmm0_8
double v16; // [rsp+20h] [rbp-38h]
long double v17; // [rsp+20h] [rbp-38h]

v10 = (long double)(int)abs32((int)(a2 - a4));
v11 = (long double)(int)abs32((int)(a3 - a5));
if ( a1 )
{
printf("difs: %Lf , %Lf\n", v10, v11);
v17 = v10 * v10;
printf("mults: %Lf , %Lf\n", v17, v11 * v11);
v13 = v11 * v11;
v12 = v17;
}
else
{
v12 = v10 * v10;
v13 = v11 * v11;
}
v14 = v12 + v13;
if ( v14 < 0.0 )
v16 = sqrt(v14);
else
v16 = sqrt(v14);
return v16;
}

canonical_decompiled_code:
long double __fastcall func7(int a1, long double a2, long double a3, long double a4, long double a5)
{
long double v10; // fst7
long double v11; // fst6
long double v12; // fst7
long double v13; // fst6
double v14; // xmm0_8
double v16; // [rsp+20h] [rbp-38h]
long double v17; // [rsp+20h] [rbp-38h]

v10 = (long double)(int)abs32((int)(a2 - a4));
v11 = (long double)(int)abs32((int)(a3 - a5));
if ( a1 )
{
printf("difs: %Lf , %Lf\n", v10, v11);
v17 = v10 * v10;
printf("mults: %Lf , %Lf\n", v17, v11 * v11);
v13 = v11 * v11;
v12 = v17;
}
else
{
v12 = v10 * v10;
v13 = v11 * v11;
}
v14 = v12 + v13;
if ( v14 < 0.0 )
v16 = sqrt(v14);
else
v16 = sqrt(v14);
return v16;
}

original_code:
long double findSide(long double x1, long double y1, long double x2, long double y2, int debug)
{
 long double difx = abs(x1 - x2);
 long double dify = abs(y1 - y2);
 if(debug)
 {
  printf("difs: %Lf , %Lf\n", difx , dify);
 }
 long double multx = difx * difx;
 long double multy = dify * dify;
 if(debug)
 {
  printf("mults: %Lf , %Lf\n", multx , multy);
 }
 return sqrt(multx + multy);
}

variable_types: debug int

variable_types:
difx
long double

variable_types:
dify
long double

variable_types:
multx
long double

variable_types:
multy
long double

return_type: long double


readIn

decompiled_code:
long double __fastcall readIn(int a1, __int64 a2)
{
return (long double)atoi(*(const char **)(a2 + 8LL * a1));
}

canonical_decompiled_code:
long double __fastcall func8(int a1, __int64 a2)
{
return (long double)atoi(*(const char **)(a2 + 8LL * a1));
}

original_code:
long double readIn(int index , char **argv )
{
 char *temp = argv[index];
 int tempInt = atoi(temp);
 long double toReturn = (long double)tempInt;
 return toReturn;
}

canonical_original_code:
long double readIn(int index, char **argv)
{
 char *temp = argv[index];
 int tempInt = atoi(temp);
 long double toReturn = (long double)tempInt;
 return toReturn;
}

variable_types: index int

variable_types:
argv
char **

variable_types:
temp
char *

variable_types: tempInt int

variable_types:
toReturn
long double


eq

decompiled_code:
bool __fastcall eq(long double a1, long double a2, long double a3)
{
long double v9; // fst7

if ( a2 <= a1 )
v9 = a1 - a2;
else
v9 = a2 - a1;
return a3 > v9;
}

canonical_decompiled_code:
bool __fastcall func9(long double a1, long double a2, long double a3)
{
long double v9; // fst7

if ( a2 <= a1 )
v9 = a1 - a2;
else
v9 = a2 - a1;
return a3 > v9;
}

original_code:
_Bool eq(long double left , long double right , long double error)
{
 if(left < right)
 {
  return ((right - left) < error);
 }
 else
 {
  return ((left - right) < error);
 }
}

canonical_original_code:
_Bool eq(long double left, long double right, long double error)
{
 if(left < right)
 {
  return ((right - left) < error);
 }
 else
 {
  return ((left - right) < error);
 }
}

variable_types:
left
long double

variable_types:
right
long double

variable_types:
error
long double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
long double v8; // fst7
double v9; // xmm0_8
const char *v10; // rdx
__int64 v11; // rdi
long double v13; // [rsp+0h] [rbp-B8h]
long double v14; // [rsp+0h] [rbp-B8h]
long double v15; // [rsp+0h] [rbp-B8h]
_TBYTE v16; // [rsp+0h] [rbp-B8h]
long double v17; // [rsp+10h] [rbp-A8h]
long double v18; // [rsp+10h] [rbp-A8h]
long double v19; // [rsp+10h] [rbp-A8h]
long double v20; // [rsp+10h] [rbp-A8h]
long double v21; // [rsp+10h] [rbp-A8h]
_TBYTE v22; // [rsp+20h] [rbp-98h]
long double v23; // [rsp+20h] [rbp-98h]
long double v24; // [rsp+30h] [rbp-88h]
long double v25; // [rsp+30h] [rbp-88h]
long double v26; // [rsp+30h] [rbp-88h]
long double v27; // [rsp+40h] [rbp-78h]
long double v28; // [rsp+50h] [rbp-68h]
long double v29; // [rsp+50h] [rbp-68h]
long double v30; // [rsp+50h] [rbp-68h]
long double v31; // [rsp+60h] [rbp-58h]
long double v32; // [rsp+60h] [rbp-58h]
long double v33; // [rsp+60h] [rbp-58h]
long double v34; // [rsp+60h] [rbp-58h]
double v35; // [rsp+60h] [rbp-58h]
long double v36; // [rsp+70h] [rbp-48h]
long double v37; // [rsp+70h] [rbp-48h]
long double v38; // [rsp+80h] [rbp-38h]
long double v39; // [rsp+90h] [rbp-28h]
long double v40; // [rsp+90h] [rbp-28h]
double v41; // [rsp+A8h] [rbp-10h]

if ( argc != 7 )
goto LABEL_17;
v27 = readIn(1LL, argv, envp);
v28 = readIn(2LL, argv, v3);
v31 = readIn(3LL, argv, v4);
v36 = readIn(4LL, argv, v5);
v38 = readIn(5LL, argv, v6);
v8 = readIn(6LL, argv, v7);
v39 = v8;
findSide(*(_TBYTE *)&v27, *(_TBYTE *)&v28, *(_TBYTE *)&v31, *(_TBYTE *)&v36);
findSide(*(_TBYTE *)&v31, *(_TBYTE *)&v36, *(_TBYTE *)&v38, *(_TBYTE *)&v39);
v32 = v8;
findSide(*(_TBYTE *)&v38, *(_TBYTE *)&v39, *(_TBYTE *)&v27, *(_TBYTE *)&v28);
v40 = v32 * v32;
v37 = v8 * v8;
v41 = acos((v40 + v37 - v37) / ((v32 + v32) * v8));
v9 = acos((v37 + v37 - v40) / ((v8 + v8) * v8));
if ( v8 == 0.0 )
goto LABEL_17;
v24 = 9.999999999999999e-12;
v22 = *(_TBYTE *)&v24;
v17 = v8;
v25 = v8;
v13 = v8 + v8;
if ( (unsigned __int8)eq(*(_TBYTE *)&v13, *(_TBYTE *)&v17, v22)
|| (v33 = 9.999999999999999e-12,
v18 = v8,
v14 = v8 + v8,
(unsigned __int8)eq(*(_TBYTE *)&v14, *(_TBYTE *)&v18, *(_TBYTE *)&v33))
|| (v29 = 9.999999999999999e-12,
v15 = v8 + v8,
(unsigned __int8)eq(*(_TBYTE *)&v15, *(_TBYTE *)&v25, *(_TBYTE *)&v29)) )
{
LABEL_17:
puts("not a triangle");
}
else
{
v26 = 9.999999999999999e-12;
v23 = 9.999999999999999e-12;
v19 = v41;
v30 = 1.570796326794897;
if ( !(unsigned __int8)eq(*(_TBYTE *)&v30, *(_TBYTE *)&v19, *(_TBYTE *)&v23) )
{
v20 = v9;
v34 = 1.570796326794897;
v11 = *(_QWORD *)&v34;
if ( !(unsigned __int8)eq(*(_TBYTE *)&v34, *(_TBYTE *)&v20, *(_TBYTE *)&v26) )
{
*(double *)&v34 = 3.141592653589793 - v41 - v9;
v21 = *(double *)&v34;
HIWORD(v16) = WORD4(v34);
*(_QWORD *)&v16 = v11;
if ( !(unsigned __int8)eq(v16, *(_TBYTE *)&v21, COERCE__TBYTE(COERCE_UNSIGNED_INT128(9.999999999999999e-12))) )
{
if ( v41 >= 1.570896326794896558 || v9 >= 1.570896326794896558 || (v10 = "acute", v35 >= 1.570896326794896558) )
{
v10 = "obtuse";
if ( v41 <= 1.570796326794897 && v9 <= 1.570796326794897 && v35 <= 1.570796326794897 )
v10 = "";
}
}
}
}
printf("%s %s\n", "equilateral", v10);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
long double v8; // fst7
double v9; // xmm0_8
const char *v10; // rdx
__int64 v11; // rdi
long double v13; // [rsp+0h] [rbp-B8h]
long double v14; // [rsp+0h] [rbp-B8h]
long double v15; // [rsp+0h] [rbp-B8h]
_TBYTE v16; // [rsp+0h] [rbp-B8h]
long double v17; // [rsp+10h] [rbp-A8h]
long double v18; // [rsp+10h] [rbp-A8h]
long double v19; // [rsp+10h] [rbp-A8h]
long double v20; // [rsp+10h] [rbp-A8h]
long double v21; // [rsp+10h] [rbp-A8h]
_TBYTE v22; // [rsp+20h] [rbp-98h]
long double v23; // [rsp+20h] [rbp-98h]
long double v24; // [rsp+30h] [rbp-88h]
long double v25; // [rsp+30h] [rbp-88h]
long double v26; // [rsp+30h] [rbp-88h]
long double v27; // [rsp+40h] [rbp-78h]
long double v28; // [rsp+50h] [rbp-68h]
long double v29; // [rsp+50h] [rbp-68h]
long double v30; // [rsp+50h] [rbp-68h]
long double v31; // [rsp+60h] [rbp-58h]
long double v32; // [rsp+60h] [rbp-58h]
long double v33; // [rsp+60h] [rbp-58h]
long double v34; // [rsp+60h] [rbp-58h]
double v35; // [rsp+60h] [rbp-58h]
long double v36; // [rsp+70h] [rbp-48h]
long double v37; // [rsp+70h] [rbp-48h]
long double v38; // [rsp+80h] [rbp-38h]
long double v39; // [rsp+90h] [rbp-28h]
long double v40; // [rsp+90h] [rbp-28h]
double v41; // [rsp+A8h] [rbp-10h]

if ( argc != 7 )
goto LABEL_17;
v27 = func8(1LL, argv, envp);
v28 = func8(2LL, argv, v3);
v31 = func8(3LL, argv, v4);
v36 = func8(4LL, argv, v5);
v38 = func8(5LL, argv, v6);
v8 = func8(6LL, argv, v7);
v39 = v8;
func7(*(_TBYTE *)&v27, *(_TBYTE *)&v28, *(_TBYTE *)&v31, *(_TBYTE *)&v36);
func7(*(_TBYTE *)&v31, *(_TBYTE *)&v36, *(_TBYTE *)&v38, *(_TBYTE *)&v39);
v32 = v8;
func7(*(_TBYTE *)&v38, *(_TBYTE *)&v39, *(_TBYTE *)&v27, *(_TBYTE *)&v28);
v40 = v32 * v32;
v37 = v8 * v8;
v41 = acos((v40 + v37 - v37) / ((v32 + v32) * v8));
v9 = acos((v37 + v37 - v40) / ((v8 + v8) * v8));
if ( v8 == 0.0 )
goto LABEL_17;
v24 = 9.999999999999999e-12;
v22 = *(_TBYTE *)&v24;
v17 = v8;
v25 = v8;
v13 = v8 + v8;
if ( (unsigned __int8)func9(*(_TBYTE *)&v13, *(_TBYTE *)&v17, v22)
|| (v33 = 9.999999999999999e-12,
v18 = v8,
v14 = v8 + v8,
(unsigned __int8)func9(*(_TBYTE *)&v14, *(_TBYTE *)&v18, *(_TBYTE *)&v33))
|| (v29 = 9.999999999999999e-12,
v15 = v8 + v8,
(unsigned __int8)func9(*(_TBYTE *)&v15, *(_TBYTE *)&v25, *(_TBYTE *)&v29)) )
{
LABEL_17:
puts("not a triangle");
}
else
{
v26 = 9.999999999999999e-12;
v23 = 9.999999999999999e-12;
v19 = v41;
v30 = 1.570796326794897;
if ( !(unsigned __int8)func9(*(_TBYTE *)&v30, *(_TBYTE *)&v19, *(_TBYTE *)&v23) )
{
v20 = v9;
v34 = 1.570796326794897;
v11 = *(_QWORD *)&v34;
if ( !(unsigned __int8)func9(*(_TBYTE *)&v34, *(_TBYTE *)&v20, *(_TBYTE *)&v26) )
{
*(double *)&v34 = 3.141592653589793 - v41 - v9;
v21 = *(double *)&v34;
HIWORD(v16) = WORD4(v34);
*(_QWORD *)&v16 = v11;
if ( !(unsigned __int8)func9(v16, *(_TBYTE *)&v21, COERCE__TBYTE(COERCE_UNSIGNED_INT128(9.999999999999999e-12))) )
{
if ( v41 >= 1.570896326794896558 || v9 >= 1.570896326794896558 || (v10 = "acute", v35 >= 1.570896326794896558) )
{
v10 = "obtuse";
if ( v41 <= 1.570796326794897 && v9 <= 1.570796326794897 && v35 <= 1.570796326794897 )
v10 = "";
}
}
}
}
printf("%s %s\n", "equilateral", v10);
}
return 0;
}

original_code:
int main(int argc , char *argv[])
{
 long double error = .00000000001;
 long double error1 = 1.0;
 long double error2 = 0.0001;
 int debug = 0;
 char *NOT = "not a triangle\n";
 if(argc != 7)
 {
  printf(NOT);
  return 0;
 }
 long double x1 = readIn(1 , argv);
 long double y1 = readIn(2 , argv);
 long double x2 = readIn(3 , argv);
 long double y2 = readIn(4 , argv);
 long double x3 = readIn(5 , argv);
 long double y3 = readIn(6 , argv);
 long double s1 = findSide(x1 , y1 , x2 , y2 , debug);
 long double s2 = findSide(x2 , y2 , x3 , y3 , debug);
 long double s3 = findSide(x3 , y3 , x1 , y1 , debug);
 double angleS1 = acos(((s2 * s2) + (s3 * s3) - (s1 * s1))/(2 * s2 * s3));
     double angleS2 = acos(((s3 * s3) + (s1 * s1) - (s2 * s2))/(2 * s3 * s1));
     double angleS3 = 3.14159265358979323846 - angleS1 - angleS2;
 if(debug)
 {
  printf("angles = %f , %f , %f, %f\n" , angleS1 , angleS2 , angleS3 , (3.14159265358979323846/2));
 }
 char *toPrint1 = "";
 char *toPrint2 = "";
 if(debug)
        {
                printf("side lengths: %Lf, %Lf , %Lf\n", s1 , s2 , s3);
        }
 if(s1 == 0 || s2 == 0 || s3 == 0)
 {
  printf(NOT);
  return 0;
 }
 else if(eq(s1 + s2 , s3, error) || eq(s1 + s3 , s2 , error) || eq(s2 + s3 , s1 , error))
 {
  printf(NOT);
  return 0;
 }
 else if(s1 == s2 && s2 == s3)
 {
  toPrint1 = "equilateral";
 }
 else if(eq(s1 , s2 , error) || eq(s2 , s3 , error)|| eq(s3 , s1 , error))
 {
  toPrint1 = "isosceles";
 }
 else
 {
  toPrint1 = "scalene";
 }
 if(eq((3.14159265358979323846 / 2) , angleS1 , error) || eq((3.14159265358979323846 / 2) , angleS2 , error) || eq((3.14159265358979323846 / 2) , angleS3 , error))
 {
  toPrint2 = "right";
 }
 else if((angleS1 < ((3.14159265358979323846 / 2) + error2)) && (angleS2 < ((3.14159265358979323846 / 2) + error2)) && (angleS3 < ((3.14159265358979323846 / 2) + error2)))
 {
  toPrint2 = "acute";
 }
 else if((angleS1 > (3.14159265358979323846 / 2)) || (angleS2 > (3.14159265358979323846 / 2)) || (angleS3 > (3.14159265358979323846 / 2)))
 {
  toPrint2 = "obtuse";
 }
 printf("%s %s\n" , toPrint1 , toPrint2);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 long double error = .00000000001;
 long double error1 = 1.0;
 long double error2 = 0.0001;
 int debug = 0;
 char *NOT = "not a triangle\n";
 if(argc != 7)
 {
  printf(NOT);
  return 0;
 }
 long double x1 = readIn(1 , argv);
 long double y1 = readIn(2 , argv);
 long double x2 = readIn(3 , argv);
 long double y2 = readIn(4 , argv);
 long double x3 = readIn(5 , argv);
 long double y3 = readIn(6 , argv);
 long double s1 = findSide(x1 , y1 , x2 , y2 , debug);
 long double s2 = findSide(x2 , y2 , x3 , y3 , debug);
 long double s3 = findSide(x3 , y3 , x1 , y1 , debug);
 double angleS1 = acos(((s2 * s2) + (s3 * s3) - (s1 * s1))/(2 * s2 * s3));
     double angleS2 = acos(((s3 * s3) + (s1 * s1) - (s2 * s2))/(2 * s3 * s1));
     double angleS3 = 3.14159265358979323846 - angleS1 - angleS2;
 if(debug)
 {
  printf("angles = %f , %f , %f, %f\n" , angleS1 , angleS2 , angleS3 , (3.14159265358979323846/2));
 }
 char *toPrint1 = "";
 char *toPrint2 = "";
 if(debug)
        {
                printf("side lengths: %Lf, %Lf , %Lf\n", s1 , s2 , s3);
        }
 if(s1 == 0 || s2 == 0 || s3 == 0)
 {
  printf(NOT);
  return 0;
 }
 else if(eq(s1 + s2 , s3, error) || eq(s1 + s3 , s2 , error) || eq(s2 + s3 , s1 , error))
 {
  printf(NOT);
  return 0;
 }
 else if(s1 == s2 && s2 == s3)
 {
  toPrint1 = "equilateral";
 }
 else if(eq(s1 , s2 , error) || eq(s2 , s3 , error)|| eq(s3 , s1 , error))
 {
  toPrint1 = "isosceles";
 }
 else
 {
  toPrint1 = "scalene";
 }
 if(eq((3.14159265358979323846 / 2) , angleS1 , error) || eq((3.14159265358979323846 / 2) , angleS2 , error) || eq((3.14159265358979323846 / 2) , angleS3 , error))
 {
  toPrint2 = "right";
 }
 else if((angleS1 < ((3.14159265358979323846 / 2) + error2)) && (angleS2 < ((3.14159265358979323846 / 2) + error2)) && (angleS3 < ((3.14159265358979323846 / 2) + error2)))
 {
  toPrint2 = "acute";
 }
 else if((angleS1 > (3.14159265358979323846 / 2)) || (angleS2 > (3.14159265358979323846 / 2)) || (angleS3 > (3.14159265358979323846 / 2)))
 {
  toPrint2 = "obtuse";
 }
 printf("%s %s\n" , toPrint1 , toPrint2);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
NOT
char *


decompiled_code:
void __fastcall print_table(__int64 a1, __int64 a2)
{
char *v2; // rbp
_BYTE v3[2072]; // [rsp+0h] [rbp-818h] BYREF

if ( (unsigned int)check_format() )
{
v2 = (char *)get_mapping_from_file(a1, a2, v3);
puts(v2);
}
else
{
memset(v3, 0, 0x800uLL);
find_frequencies(v3, a1, a2);
v2 = (char *)get_huffman_table(v3);
printf("%s", v2);
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
char *v2; // rbp
_BYTE v3[2072]; // [rsp+0h] [rbp-818h] BYREF

if ( (unsigned int)check_format() )
{
v2 = (char *)get_mapping_from_file(a1, a2, v3);
puts(v2);
}
else
{
memset(v3, 0, 0x800uLL);
find_frequencies(v3, a1, a2);
v2 = (char *)get_huffman_table(v3);
printf("%s", v2);
}
free(v2);
}

original_code:
void print_table(unsigned char* file_pointer, unsigned long long file_length, char* filename)
{
  if(check_format(file_pointer, file_length, filename))
  {
    unsigned long long start_of_compressed;
    char* mapping = get_mapping_from_file(file_pointer, file_length, &start_of_compressed);
    printf("%s\n", mapping);
    free(mapping);
  }
  else
  {
    unsigned long long frequencies[256] = {0};
    find_frequencies(frequencies, file_pointer, file_length);
    char* mapping = get_huffman_table(frequencies);
    printf("%s", mapping);
    free(mapping);
  }
}

canonical_original_code:
void print_table(unsigned char *file_pointer, unsigned long long file_length, char *filename)
{
  if(check_format(file_pointer, file_length, filename))
  {
    unsigned long long start_of_compressed;
    char *mapping = get_mapping_from_file(file_pointer, file_length, &start_of_compressed);
    printf("%s\n", mapping);
    free(mapping);
  }
  else
  {
    unsigned long long frequencies[256] = {0};
    find_frequencies(frequencies, file_pointer, file_length);
    char *mapping = get_huffman_table(frequencies);
    printf("%s", mapping);
    free(mapping);
  }
}

variable_types:
filename
char *

variable_types:
mapping
char *

variable_types:
frequencies
unsigned long long [256]


compress

decompiled_code:
void __fastcall compress(__int64 a1, __int64 a2, __int64 a3)
{
void *v4; // rbp
_BYTE v5[2088]; // [rsp+0h] [rbp-828h] BYREF

memset(v5, 0, 0x800uLL);
find_frequencies(v5, a1, a2);
v4 = (void *)get_huffman_table(v5);
write_compressed_file(a1, a2, a3, v4);
free(v4);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
void *v4; // rbp
_BYTE v5[2088]; // [rsp+0h] [rbp-828h] BYREF

memset(v5, 0, 0x800uLL);
find_frequencies(v5, a1, a2);
v4 = (void *)get_huffman_table(v5);
write_compressed_file(a1, a2, a3, v4);
free(v4);
}

original_code:
void compress(unsigned char* file_pointer, unsigned long long file_length, char* filename)
{
  unsigned long long frequencies[256] = {0};
  find_frequencies(frequencies, file_pointer, file_length);
  char* mapping = get_huffman_table(frequencies);
  write_compressed_file(file_pointer, file_length, filename, mapping);
  free(mapping);
}

canonical_original_code:
void compress(unsigned char *file_pointer, unsigned long long file_length, char *filename)
{
  unsigned long long frequencies[256] = {0};
  find_frequencies(frequencies, file_pointer, file_length);
  char *mapping = get_huffman_table(frequencies);
  write_compressed_file(file_pointer, file_length, filename, mapping);
  free(mapping);
}


decompress

decompiled_code:
void __fastcall decompress(__int64 a1, __int64 a2, __int64 a3)
{
void *v4; // r14
__int64 v5[6]; // [rsp+8h] [rbp-30h] BYREF

if ( !(unsigned int)check_format() )
{
puts("Can't decompress a non-huff file.");
exit(-1);
}
v4 = (void *)get_mapping_from_file(a1, a2, v5);
write_decompressed_file(a1, a2, a3, v4, v5[0]);
free(v4);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
void *v4; // r14
__int64 v5[6]; // [rsp+8h] [rbp-30h] BYREF

if ( !(unsigned int)check_format() )
{
puts("Can't decompress a non-huff file.");
exit(-1);
}
v4 = (void *)get_mapping_from_file(a1, a2, v5);
write_decompressed_file(a1, a2, a3, v4, v5[0]);
free(v4);
}

original_code:
void decompress(unsigned char* file_pointer, unsigned long long file_length, char* filename)
{
  if(!check_format(file_pointer, file_length, filename))
  {
    printf("Can't decompress a non-huff file.\n");
    exit(-1);
  }
  unsigned long long start_of_compressed;
  char* mapping = get_mapping_from_file(file_pointer, file_length, &start_of_compressed);
  write_decompressed_file(file_pointer, file_length, filename, mapping, start_of_compressed);
  free(mapping);
}

canonical_original_code:
void decompress(unsigned char *file_pointer, unsigned long long file_length, char *filename)
{
  if(!check_format(file_pointer, file_length, filename))
  {
    printf("Can't decompress a non-huff file.\n");
    exit(-1);
  }
  unsigned long long start_of_compressed;
  char *mapping = get_mapping_from_file(file_pointer, file_length, &start_of_compressed);
  write_decompressed_file(file_pointer, file_length, filename, mapping, start_of_compressed);
  free(mapping);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // er12
const char *v5; // r14
size_t v6; // r13
char *v7; // rbp
void *v8; // r13
char *v10; // rdi
void *v11; // r14
const char *v12; // r15
size_t v13; // rbx
char *v14; // rbp
size_t v15; // rbx
char *v16; // r13
char *v17; // rdi
void *v18; // rbp
__off_t v19[8]; // [rsp+8h] [rbp-40h] BYREF

if ( argc != 3 )
goto LABEL_10;
v3 = argv[1];
if ( *(_WORD *)v3 != 25389 || (v4 = *((unsigned __int8 *)v3 + 2), v3[2]) )
{
v4 = strcmp(v3, "-d");
if ( !v4 )
{
v10 = (char *)argv[2];
v19[0] = 0LL;
v11 = openFile(v10, v19);
decompress((__int64)v11, v19[0], (__int64)argv[2]);
v12 = argv[2];
v13 = strlen(v12);
v14 = (char *)calloc(v13, 1uLL);
strncpy(v14, v12, v13 - 5);
strcat(v14, ".temp");
v15 = strlen(v12);
v16 = (char *)calloc(1uLL, v15);
strncpy(v16, v12, v15);
v16[strlen(v16) - 5] = 0;
rle_decode(v14, v16);
free(v11);
remove(v14);
return v4;
}
v4 = strcmp(v3, "-t");
if ( !v4 )
{
v17 = (char *)argv[2];
v19[0] = 0LL;
v18 = openFile(v17, v19);
print_table((__int64)v18, v19[0]);
free(v18);
return v4;
}
LABEL_10:
v4 = -1;
puts("usage: huff [-c | -d | -t] file");
return v4;
}
v5 = argv[2];
v6 = strlen(v5);
v7 = (char *)malloc(v6 + 6);
strncpy(v7, v5, v6);
strcat(v7, ".temp");
rle_encode(v5, v7);
v19[0] = 0LL;
v8 = openFile(v7, v19);
compress((__int64)v8, v19[0], (__int64)argv[2]);
free(v8);
remove(v7);
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // er12
const char *v5; // r14
size_t v6; // r13
char *v7; // rbp
void *v8; // r13
char *v10; // rdi
void *v11; // r14
const char *v12; // r15
size_t v13; // rbx
char *v14; // rbp
size_t v15; // rbx
char *v16; // r13
char *v17; // rdi
void *v18; // rbp
__off_t v19[8]; // [rsp+8h] [rbp-40h] BYREF

if ( argc != 3 )
goto LABEL_10;
v3 = argv[1];
if ( *(_WORD *)v3 != 25389 || (v4 = *((unsigned __int8 *)v3 + 2), v3[2]) )
{
v4 = strcmp(v3, "-d");
if ( !v4 )
{
v10 = (char *)argv[2];
v19[0] = 0LL;
v11 = func3(v10, v19);
func1((__int64)v11, v19[0], (__int64)argv[2]);
v12 = argv[2];
v13 = strlen(v12);
v14 = (char *)calloc(v13, 1uLL);
strncpy(v14, v12, v13 - 5);
strcat(v14, ".temp");
v15 = strlen(v12);
v16 = (char *)calloc(1uLL, v15);
strncpy(v16, v12, v15);
v16[strlen(v16) - 5] = 0;
rle_decode(v14, v16);
free(v11);
remove(v14);
return v4;
}
v4 = strcmp(v3, "-t");
if ( !v4 )
{
v17 = (char *)argv[2];
v19[0] = 0LL;
v18 = func3(v17, v19);
func2((__int64)v18, v19[0]);
free(v18);
return v4;
}
LABEL_10:
v4 = -1;
puts("usage: huff [-c | -d | -t] file");
return v4;
}
v5 = argv[2];
v6 = strlen(v5);
v7 = (char *)malloc(v6 + 6);
strncpy(v7, v5, v6);
strcat(v7, ".temp");
rle_encode(v5, v7);
v19[0] = 0LL;
v8 = func3(v7, v19);
func0((__int64)v8, v19[0], (__int64)argv[2]);
free(v8);
remove(v7);
return v4;
}

original_code:
int main(int argc, char* argv[])
{
  if(argc != 3 || (strcmp(argv[1], "-c") != 0 && strcmp(argv[1], "-d") != 0 && strcmp(argv[1], "-t") != 0))
  {
    printf("usage: huff [-c | -d | -t] file\n");
    return -1;
  }
  if(strcmp(argv[1], "-c") == 0)
  {
    const char * extension = ".temp";
    char *tempFile = malloc(strlen(argv[2])+strlen(extension) + 1);
    strncpy(tempFile, argv[2], strlen(argv[2]));
    strcat(tempFile, extension);
    rle_encode(argv[2], tempFile);
      unsigned long long fileLength = 0;
      unsigned char *file_pointer = openFile(tempFile, &fileLength);
      compress(file_pointer, fileLength, argv[2]);
      free(file_pointer);
      remove(tempFile);
  }
  else if(strcmp(argv[1], "-d") == 0)
  {
      unsigned long long fileLength = 0;
      unsigned char *file_pointer = openFile(argv[2], &fileLength);
      decompress(file_pointer, fileLength, argv[2]);
      char *tempFileName = calloc(strlen(argv[2]), sizeof(char));
      strncpy(tempFileName, argv[2], strlen(argv[2]) - strlen(".hurl"));
      strncat(tempFileName, ".temp", sizeof(".temp"));
      char *outputFileName = calloc(sizeof(char), strlen(argv[2]));
      strncpy(outputFileName, argv[2], strlen(argv[2]));
      outputFileName[strlen(outputFileName) -5] = '\0';
      rle_decode(tempFileName, outputFileName);
      free(file_pointer);
      remove(tempFileName);
  }
  else if(strcmp(argv[1], "-t") == 0)
  {
      unsigned long long fileLength = 0;
      unsigned char *file_pointer = openFile(argv[2], &fileLength);
      print_table(file_pointer, fileLength, argv[2]);
      free(file_pointer);
  }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  if(argc != 3 || (strcmp(argv[1], "-c") != 0 && strcmp(argv[1], "-d") != 0 && strcmp(argv[1], "-t") != 0))
  {
    printf("usage: huff [-c | -d | -t] file\n");
    return -1;
  }
  if(strcmp(argv[1], "-c") == 0)
  {
    char *extension = ".temp";
    char *tempFile = malloc(strlen(argv[2])+strlen(extension) + 1);
    strncpy(tempFile, argv[2], strlen(argv[2]));
    strcat(tempFile, extension);
    rle_encode(argv[2], tempFile);
      unsigned long long fileLength = 0;
      unsigned char *file_pointer = openFile(tempFile, &fileLength);
      compress(file_pointer, fileLength, argv[2]);
      free(file_pointer);
      remove(tempFile);
  }
  else if(strcmp(argv[1], "-d") == 0)
  {
      unsigned long long fileLength = 0;
      unsigned char *file_pointer = openFile(argv[2], &fileLength);
      decompress(file_pointer, fileLength, argv[2]);
      char *tempFileName = calloc(strlen(argv[2]), sizeof(char));
      strncpy(tempFileName, argv[2], strlen(argv[2]) - strlen(".hurl"));
      strncat(tempFileName, ".temp", sizeof(".temp"));
      char *outputFileName = calloc(sizeof(char), strlen(argv[2]));
      strncpy(outputFileName, argv[2], strlen(argv[2]));
      outputFileName[strlen(outputFileName) -5] = '\0';
      rle_decode(tempFileName, outputFileName);
      free(file_pointer);
      remove(tempFileName);
  }
  else if(strcmp(argv[1], "-t") == 0)
  {
      unsigned long long fileLength = 0;
      unsigned char *file_pointer = openFile(argv[2], &fileLength);
      print_table(file_pointer, fileLength, argv[2]);
      free(file_pointer);
  }
    return 0;
}

variable_types:
extension
char *

variable_types:
tempFile
char *

variable_types:
fileLength
unsigned long long

variable_types:
tempFileName
char *

variable_types:
outputFileName
char *


decompiled_code:
__int64 __fastcall compare_trees(const void *a1, const void *a2)
{
unsigned __int64 v2; // rax
unsigned __int64 v3; // rdx
__int64 result; // rax

v2 = **(_QWORD **)a1;
v3 = **(_QWORD **)a2;
if ( v2 == v3 )
result = *(_BYTE *)(*(_QWORD *)a1 + 32LL) < *(_BYTE *)(*(_QWORD *)a2 + 32LL) ? 1 : -1;
else
result = v3 < v2 ? -1 : 1;
return result;
}

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

v2 = **(_QWORD **)a1;
v3 = **(_QWORD **)a2;
if ( v2 == v3 )
result = *(_BYTE *)(*(_QWORD *)a1 + 32LL) < *(_BYTE *)(*(_QWORD *)a2 + 32LL) ? 1 : -1;
else
result = v3 < v2 ? -1 : 1;
return result;
}

original_code:
static int compare_trees(const void *a, const void *b) {
  tree t1, t2;
  int r;
  t1 = *(tree *)a;
  t2 = *(tree *)b;
  if (t1->freq == t2->freq) {
    r = (unsigned char)t1->ascii >= (unsigned char)t2->ascii ? -1 : 1;
  }
  else {
    r = t1->freq > t2->freq ? -1 : 1;
  }
  return r;
}

canonical_original_code:
static int compare_trees(void *a, void *b) {
  struct node *t1; struct node *t2;
  int r;
  t1 = *(struct node **)a;
  t2 = *(struct node **)b;
  if (t1->freq == t2->freq) {
    r = (unsigned char)t1->ascii >= (unsigned char)t2->ascii ? -1 : 1;
  }
  else {
    r = t1->freq > t2->freq ? -1 : 1;
  }
  return r;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct node { unsigned long long freq; struct node *parent; struct node *zero; struct node *one; char ascii; } *

variable_types: r int


decompiled_code:
char *__fastcall tree2table(__int64 a1)
{
char *v1; // rax
char *v2; // r12
int v3; // ebx
int v4; // ebp
int v5; // er14
char *result; // rax
int v7; // [rsp+0h] [rbp-13Ch] BYREF
char src[16]; // [rsp+4h] [rbp-138h] BYREF
char v9[296]; // [rsp+14h] [rbp-128h] BYREF

*(_OWORD *)src = 0LL;
memset(v9, 0, 0xF0uLL);
v9[240] = 0;
v1 = (char *)calloc(0x8181uLL, 1uLL);
if ( !v1 )
{
fwrite("tree2table: calloc error\n", 1uLL, 0x19uLL, stderr);
exit(-1);
}
v7 = 0;
v2 = v1;
v3 = 0;
v4 = 0;
do
{
find_char_encoding(a1, (__int64)src, &v7, v3++);
v5 = v7;
strncpy(&v2[v4], src, v7);
v4 += v5;
}
while ( v3 != 256 );
result = v2;
v2[v4] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1)
{
char *v1; // rax
char *v2; // r12
int v3; // ebx
int v4; // ebp
int v5; // er14
char *result; // rax
int v7; // [rsp+0h] [rbp-13Ch] BYREF
char src[16]; // [rsp+4h] [rbp-138h] BYREF
char v9[296]; // [rsp+14h] [rbp-128h] BYREF

*(_OWORD *)src = 0LL;
memset(v9, 0, 0xF0uLL);
v9[240] = 0;
v1 = (char *)calloc(0x8181uLL, 1uLL);
if ( !v1 )
{
fwrite("tree2table: calloc error\n", 1uLL, 0x19uLL, stderr);
exit(-1);
}
v7 = 0;
v2 = v1;
v3 = 0;
v4 = 0;
do
{
func1(a1, (__int64)src, &v7, v3++);
v5 = v7;
strncpy(&v2[v4], src, v7);
v4 += v5;
}
while ( v3 != 256 );
result = v2;
v2[v4] = 0;
return result;
}

original_code:
static char *tree2table(tree t) {
  char temp[257] = {'\0'};
  int i, n, c;
  char *table;
  if ((table = (char *)calloc(33153, sizeof(char))) == ((void *)0)) {
    fprintf(stderr, "tree2table: calloc error\n");
    exit(-1);
  }
  i = n = 0;
  for (c = 0; c < 256; c++) {
    find_char_encoding(t, temp, &i, c);
    strncpy(&table[n], temp, i);
    n = n + i;
  }
  table[n] = '\0';
  return table;
}

canonical_original_code:
static char *tree2table(struct node *t) {
  char temp[257] = {'\0'};
  int i; int n; int c;
  char *table;
  if ((table = (char *)calloc(33153, sizeof(char))) == ((void *)0)) {
    fprintf(stderr, "tree2table: calloc error\n");
    exit(-1);
  }
  i = n = 0;
  for (c = 0; c < 256; c++) {
    find_char_encoding(t, temp, &i, c);
    strncpy(&table[n], temp, i);
    n = n + i;
  }
  table[n] = '\0';
  return table;
}

variable_types:
temp
char [257]

variable_types: i int

variable_types: n int

variable_types: c int

variable_types:
table
char *

user_defined_types: struct node { unsigned long long freq; struct node *parent; struct node *zero; struct node *one; char ascii; }


decompiled_code:
void __fastcall free_tree(_QWORD *a1)
{
if ( a1[2] )
free_tree();
if ( a1[3] )
free_tree();
free(a1);
}

canonical_decompiled_code:
void __fastcall func6(_QWORD *a1)
{
if ( a1[2] )
func6();
if ( a1[3] )
func6();
free(a1);
}

original_code:
void free_tree(tree t) {
  if (t->zero != ((void *)0))
    free_tree(t->zero);
  if (t->one != ((void *)0))
    free_tree(t->one);
  free(t);
}

canonical_original_code:
void free_tree(struct node *t) {
  if (t->zero != ((void *)0))
    free_tree(t->zero);
  if (t->one != ((void *)0))
    free_tree(t->one);
  free(t);
}


decompiled_code:
char *__fastcall get_huffman_table(__int64 a1)
{
size_t i; // rbx
__int64 *v2; // rax
_QWORD *v3; // rbp
char *v4; // r12
__int64 v6[2]; // [rsp+0h] [rbp-828h]
__int64 v7[259]; // [rsp+10h] [rbp-818h] BYREF

for ( i = 0LL; i != 256; ++i )
v7[i] = (__int64)make_node_from_ascii_freq(i, *(_QWORD *)(a1 + 8 * i));
do
{
qsort(v7, i, 8uLL, (__compar_fn_t)compare_trees);
v2 = make_node_from_trees(v6[i + 1], v6[i]);
v6[i--] = (__int64)v2;
check_rep_encode(v2);
}
while ( i != 1 );
v3 = (_QWORD *)v7[0];
v4 = tree2table(v7[0]);
free_tree(v3);
return v4;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 a1)
{
size_t i; // rbx
__int64 *v2; // rax
_QWORD *v3; // rbp
char *v4; // r12
__int64 v6[2]; // [rsp+0h] [rbp-828h]
__int64 v7[259]; // [rsp+10h] [rbp-818h] BYREF

for ( i = 0LL; i != 256; ++i )
v7[i] = (__int64)make_node_from_ascii_freq(i, *(_QWORD *)(a1 + 8 * i));
do
{
qsort(v7, i, 8uLL, (__compar_fn_t)compare_trees);
v2 = make_node_from_trees(v6[i + 1], v6[i]);
v6[i--] = (__int64)v2;
func2(v2);
}
while ( i != 1 );
v3 = (_QWORD *)v7[0];
v4 = func4(v7[0]);
func6(v3);
return v4;
}

original_code:
char *get_huffman_table(unsigned long long ascii_counts[256]) {
  int i, count, tlt;
  char *table;
  tree zero, one, t;
  tree tree_array[256];
  tlt = 255;
  for (i = 0; i < 256; i++) {
    tree_array[i] = make_node_from_ascii_freq((char)i, ascii_counts[i]);
  }
  for (count = 256; count > 1; count--){
    qsort(tree_array, count, sizeof(tree), compare_trees);
    zero = tree_array[tlt--];
    one = tree_array[tlt];
    t = make_node_from_trees(zero, one);
    tree_array[tlt] = t;
    check_rep_encode(t);
  }
  t = tree_array[0];
  table = tree2table(t);
  free_tree(t);
  return table;
}

canonical_original_code:
char *get_huffman_table(unsigned long long ascii_counts[256]) {
  int i; int count; int tlt;
  char *table;
  struct node *zero; struct node *one; struct node *t;
  struct node *tree_array[256];
  tlt = 255;
  for (i = 0; i < 256; i++) {
    tree_array[i] = make_node_from_ascii_freq((char)i, ascii_counts[i]);
  }
  for (count = 256; count > 1; count--){
    qsort(tree_array, count, sizeof(tree), compare_trees);
    zero = tree_array[tlt--];
    one = tree_array[tlt];
    t = make_node_from_trees(zero, one);
    tree_array[tlt] = t;
    check_rep_encode(t);
  }
  t = tree_array[0];
  table = tree2table(t);
  free_tree(t);
  return table;
}

variable_types: count int

variable_types: tlt int

variable_types: struct node { unsigned long long freq; struct node *parent; struct node *zero; struct node *one; char ascii; } *[256]


decompiled_code:
size_t __fastcall sn_write(__int64 a1, const void *a2, size_t a3)
{
__int64 v5; // rbx
void *v6; // rdi
size_t v7; // rbx

v5 = *(_QWORD *)(a1 + 32);
v6 = *(void **)(a1 + 40);
++_gcov0_sn_write;
v7 = v5 - (_QWORD)v6;
if ( v7 > a3 )
v7 = a3;
memcpy(v6, a2, v7);
*(_QWORD *)(a1 + 40) += v7;
return a3;
}

canonical_decompiled_code:
size_t __fastcall func0(__int64 a1, const void *a2, size_t a3)
{
__int64 v5; // rbx
void *v6; // rdi
size_t v7; // rbx

v5 = *(_QWORD *)(a1 + 32);
v6 = *(void **)(a1 + 40);
++_gcov0_sn_write;
v7 = v5 - (_QWORD)v6;
if ( v7 > a3 )
v7 = a3;
memcpy(v6, a2, v7);
*(_QWORD *)(a1 + 40) += v7;
return a3;
}

original_code:
static size_t sn_write(MUSL_FILE *f, const unsigned char *s, size_t l)
{
 size_t k = f->wend - f->wpos;
 if (k > l) k = l;
 memcpy(f->wpos, s, k);
 f->wpos += k;
 return l;
}

canonical_original_code:
static unsigned long sn_write(struct __MUSL_FILE *f, unsigned char *s, unsigned long l)
{
 unsigned long k = f->wend - f->wpos;
 if (k > l) k = l;
 memcpy(f->wpos, s, k);
 f->wpos += k;
 return l;
}

variable_types: struct __MUSL_FILE { unsigned int flags; unsigned char *rpos; int (*close)(struct __MUSL_FILE *); unsigned char *wend; unsigned char *mustbezero_1; unsigned char *wbase; unsigned long (*read)(struct __MUSL_FILE *, unsigned char *, unsigned long); unsigned long (*write)(struct __MUSL_FILE *, unsigned char *, unsigned long); long (*seek)(struct __MUSL_FILE *, long, int); unsigned char *buf; unsigned long buf_size; struct __MUSL_FILE *prev; int fd; int pipe_pid; long lockcount; short dummy3; char mode; char lbf; int lock; int waiters; void *cookie; long off; char *getln_buf; void *mustbezero_2; unsigned char *shend; long shlim; } *

variable_types:
s
unsigned char *

variable_types:
l
unsigned long

variable_types:
k
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall musl_vsnprintf(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v5; // rbx
__int64 result; // rax
char v7; // [rsp+Fh] [rbp-D9h] BYREF
__int64 v8[27]; // [rsp+10h] [rbp-D8h] BYREF

memset(v8, 0, 0xD0uLL);
BYTE3(v8[17]) = -1;
v8[9] = (__int64)sn_write;
HIDWORD(v8[17]) = -1;
if ( a2 - 1 <= 0x7FFFFFFE )
{
++qword_2A8;
}
else
{
++_gcov0_musl_vsnprintf;
if ( a2 )
{
++qword_2B0;
*_errno_location() = 75;
return 0xFFFFFFFFLL;
}
a2 = 1LL;
a1 = (__int64)&v7;
}
v8[5] = a1;
v8[11] = a1;
v5 = -a1 - 2;
if ( v5 > a2 )
v5 = a2;
v8[12] = v5;
v8[4] = v5 + a1;
v8[7] = v5 + a1;
result = musl_vfprintf(v8, a3, a4, 0LL, v5 + a1, v8);
++qword_2B8;
if ( v5 )
{
++qword_2C0;
*(_BYTE *)(v8[5] - (v8[4] == v8[5])) = 0;
}
return result;
}

original_code:
int musl_vsnprintf(char * s, size_t n, const char * fmt, va_list ap)
{
 int r;
 char b;
 MUSL_FILE f = { .lbf = (-1), .write = sn_write, .lock = -1 };
 if (n-1 > 0x7fffffff -1) {
  if (n) {
   (*__errno_location ()) = 75;
   return -1;
  }
  s = &b;
  n = 1;
 }
 if (n > (char *)0+(18446744073709551615UL)-s-1) n = (char *)0+(18446744073709551615UL)-s-1;
 f.buf_size = n;
 f.buf = f.wpos = (void *)s;
 f.wbase = f.wend = (void *)(s+n);
 r = musl_vfprintf(&f, fmt, ap);
 if (n) f.wpos[-(f.wpos == f.wend)] = 0;
 return r;
}

canonical_original_code:
int musl_vsnprintf(char *s, unsigned long n, char *fmt, __builtin_va_list ap)
{
 int r;
 char b;
 struct __MUSL_FILE f = { .lbf = (-1), .write = sn_write, .lock = -1 };
 if (n-1 > 0x7fffffff -1) {
  if (n) {
   (*__errno_location ()) = 75;
   return -1;
  }
  s = &b;
  n = 1;
 }
 if (n > (char *)0+(18446744073709551615UL)-s-1) n = (char *)0+(18446744073709551615UL)-s-1;
 f.buf_size = n;
 f.buf = f.wpos = (void *)s;
 f.wbase = f.wend = (void *)(s+n);
 r = musl_vfprintf(&f, fmt, ap);
 if (n) f.wpos[-(f.wpos == f.wend)] = 0;
 return r;
}

variable_types:
s
char *

variable_types:
n
unsigned long

variable_types:
fmt
char *

variable_types: b char

variable_types: struct __MUSL_FILE { unsigned int flags; unsigned char *rpos; int (*close)(struct __MUSL_FILE *); unsigned char *wend; unsigned char *mustbezero_1; unsigned char *wbase; unsigned long (*read)(struct __MUSL_FILE *, unsigned char *, unsigned long); unsigned long (*write)(struct __MUSL_FILE *, unsigned char *, unsigned long); long (*seek)(struct __MUSL_FILE *, long, int); unsigned char *buf; unsigned long buf_size; struct __MUSL_FILE *prev; int fd; int pipe_pid; long lockcount; short dummy3; char mode; char lbf; int lock; int waiters; void *cookie; long off; char *getln_buf; void *mustbezero_2; unsigned char *shend; long shlim; }


byteFromString

decompiled_code:
__int64 __fastcall byteFromString(_BYTE *a1)
{
_BYTE *v1; // rdx
unsigned int v2; // er8
char v3; // al

v1 = a1 + 8;
v2 = 0;
v3 = (_BYTE)a1 + 7;
do
{
if ( *a1 == 49 )
v2 |= 1 << (v3 - (_BYTE)a1);
++a1;
}
while ( a1 != v1 );
return v2;
}

original_code:
static char byteFromString(char *string)
{
    ((string) ? (void) (0) : __assert_fail ("string", "encodedOutputFileWriter.c", 29, __extension__ __PRETTY_FUNCTION__));
    unsigned char result = 0;
    for(int i = 7; i >= 0; i--)
    {
        char currentBit = string[7-i];
        if(currentBit == '1')
        {
            unsigned char temp = 1<<i;
            result = result | temp;
        }
    }
    return (char)result;
}

variable_types:
string
char *

variable_types:
result
unsigned char

variable_types: currentBit char

variable_types:
temp
unsigned char

return_type: char


decompiled_code:
char __fastcall rle_bit(unsigned __int8 a1)
{
return a1 >> 7;
}

canonical_decompiled_code:
char __fastcall func0(unsigned __int8 a1)
{
return a1 >> 7;
}

original_code:
static char rle_bit(char byte)
{
    return (byte >> 7) & 0x1;
}

variable_types: byte char


decompiled_code:
__int64 __fastcall rle_length(char a1)
{
return a1 & 0x7F;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
return a1 & 0x7F;
}

original_code:
static char rle_length(char byte)
{
    return byte & 0x7f;
}


decompiled_code:
__int64 __fastcall rle_encode(__int64 a1, __int64 a2)
{
int v3; // er15
unsigned __int8 v4; // r14
__int64 result; // rax
int v6; // ebp
unsigned __int8 v7; // di
char v9[57]; // [rsp+Fh] [rbp-39h] BYREF

if ( !a1 )
_assert_fail("input", "rle.c", 0x1Eu, "rle_encode");
if ( !a2 )
_assert_fail("output", "rle.c", 0x1Fu, "rle_encode");
v9[0] = 0;
v3 = 0;
v4 = -1;
LABEL_4:
result = xfread(v9, 1LL, 1LL, a1);
if ( result == 1 )
{
v6 = 7;
while ( v4 != 0xFF )
{
if ( ((v9[0] >> v6) & 1) == v4 )
goto LABEL_11;
v7 = v4;
v4 = (v9[0] >> v6) & 1;
rle_encode_write(v7, v3, a2);
v3 = 1;
LABEL_8:
if ( v6-- == 0 )
goto LABEL_4;
}
v4 = (v9[0] >> v6) & 1;
LABEL_11:
if ( ++v3 == 127 )
{
v3 = 0;
rle_encode_write(v4, 127, a2);
v4 = -1;
}
goto LABEL_8;
}
if ( v3 )
result = rle_encode_write(v4, v3, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
int v3; // er15
unsigned __int8 v4; // r14
__int64 result; // rax
int v6; // ebp
unsigned __int8 v7; // di
char v9[57]; // [rsp+Fh] [rbp-39h] BYREF

if ( !a1 )
_assert_fail("input", "rle.c", 0x1Eu, "rle_encode");
if ( !a2 )
_assert_fail("output", "rle.c", 0x1Fu, "rle_encode");
v9[0] = 0;
v3 = 0;
v4 = -1;
LABEL_4:
result = xfread(v9, 1LL, 1LL, a1);
if ( result == 1 )
{
v6 = 7;
while ( v4 != 0xFF )
{
if ( ((v9[0] >> v6) & 1) == v4 )
goto LABEL_11;
v7 = v4;
v4 = (v9[0] >> v6) & 1;
func2(v7, v3, a2);
v3 = 1;
LABEL_8:
if ( v6-- == 0 )
goto LABEL_4;
}
v4 = (v9[0] >> v6) & 1;
LABEL_11:
if ( ++v3 == 127 )
{
v3 = 0;
func2(v4, 127, a2);
v4 = -1;
}
goto LABEL_8;
}
if ( v3 )
result = func2(v4, v3, a2);
return result;
}

original_code:
uint8_t *rle_encode(uint8_t *original_data, size_t in_len, size_t *out_len) {
  rcontext rcon = rcontext_init(original_data, in_len);
  econtext econ = econtext_init();
  byte_wcontext wcon = byte_wcontext_init(1024);
  int bit = rcontext_read_bit(&rcon);
  uint8_t encoded;
  while (bit >= 0) {
    if (econtext_add_bit(&econ, bit, &encoded))
      byte_wcontext_write(&wcon, encoded);
    bit = rcontext_read_bit(&rcon);
  }
  if (econtext_end_bits(&econ, &encoded))
    byte_wcontext_write(&wcon, encoded);
  *out_len = wcon.byte_idx;
  return wcon.buffer;
}

canonical_original_code:
unsigned char *rle_encode(unsigned char *original_data, unsigned long in_len, unsigned long *out_len) {
  struct rcontext rcon = rcontext_init(original_data, in_len);
  struct econtext econ = econtext_init();
  struct byte_wcontext wcon = byte_wcontext_init(1024);
  int bit = rcontext_read_bit(&rcon);
  unsigned char encoded;
  while (bit >= 0) {
    if (econtext_add_bit(&econ, bit, &encoded))
      byte_wcontext_write(&wcon, encoded);
    bit = rcontext_read_bit(&rcon);
  }
  if (econtext_end_bits(&econ, &encoded))
    byte_wcontext_write(&wcon, encoded);
  *out_len = wcon.byte_idx;
  return wcon.buffer;
}

variable_types: struct rcontext { unsigned char *data; unsigned long len; unsigned long byte_idx; int bit_idx; }

variable_types: struct econtext { int run_type; int run_len; }

variable_types: struct byte_wcontext { unsigned char *buffer; unsigned long len; unsigned long byte_idx; }

variable_types: bit int

variable_types:
encoded
unsigned char