decompiled_code:
__int64 __fastcall rcontext_read_bit(__int64 a1)
{
unsigned __int64 v1; // rax
unsigned __int64 v2; // rdx
unsigned int v3; // esi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(a1 + 16);
if ( v1 < v2 )
_assert_fail("con->len >= con->byte_idx", "rle.c", 0x2Au, "rcontext_read_bit");
v3 = *(_DWORD *)(a1 + 24);
if ( v3 > 7 )
_assert_fail("con->bit_idx >= 0 && con->bit_idx <= 7", "rle.c", 0x2Bu, "rcontext_read_bit");
if ( v1 == v2 )
return 0xFFFFFFFFLL;
result = ((int)*(unsigned __int8 *)(*(_QWORD *)a1 + v2) >> (7 - v3)) & 1;
if ( v3 == 7 )
{
*(_DWORD *)(a1 + 24) = 0;
*(_QWORD *)(a1 + 16) = v2 + 1;
}
else
{
*(_DWORD *)(a1 + 24) = v3 + 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned __int64 v1; // rax
unsigned __int64 v2; // rdx
unsigned int v3; // esi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(a1 + 16);
if ( v1 < v2 )
_assert_fail("con->len >= con->byte_idx", "rle.c", 0x2Au, "rcontext_read_bit");
v3 = *(_DWORD *)(a1 + 24);
if ( v3 > 7 )
_assert_fail("con->bit_idx >= 0 && con->bit_idx <= 7", "rle.c", 0x2Bu, "rcontext_read_bit");
if ( v1 == v2 )
return 0xFFFFFFFFLL;
result = ((int)*(unsigned __int8 *)(*(_QWORD *)a1 + v2) >> (7 - v3)) & 1;
if ( v3 == 7 )
{
*(_DWORD *)(a1 + 24) = 0;
*(_QWORD *)(a1 + 16) = v2 + 1;
}
else
{
*(_DWORD *)(a1 + 24) = v3 + 1;
}
return result;
}

original_code:
static int rcontext_read_bit(rcontext *con) {
  ((con->len >= con->byte_idx) ? (void) (0) : __assert_fail ("con->len >= con->byte_idx", "rle.c", 42, __extension__ __PRETTY_FUNCTION__));
  ((con->bit_idx >= 0 && con->bit_idx <= 7) ? (void) (0) : __assert_fail ("con->bit_idx >= 0 && con->bit_idx <= 7", "rle.c", 43, __extension__ __PRETTY_FUNCTION__));
  if (con->len == con->byte_idx) {
    return -1;
  } else {
    uint8_t to_extract = con->data[con->byte_idx];
    int bit = (to_extract >> (7 - con->bit_idx)) & 0x1;
    con->bit_idx++;
    if (con->bit_idx == 8) {
      con->bit_idx = 0;
      con->byte_idx++;
    }
    return bit;
  }
}

canonical_original_code:
static int rcontext_read_bit(struct rcontext *con) {
  ((con->len >= con->byte_idx) ? (void) (0) : __assert_fail ("con->len >= con->byte_idx", "rle.c", 42, __extension__ __PRETTY_FUNCTION__));
  ((con->bit_idx >= 0 && con->bit_idx <= 7) ? (void) (0) : __assert_fail ("con->bit_idx >= 0 && con->bit_idx <= 7", "rle.c", 43, __extension__ __PRETTY_FUNCTION__));
  if (con->len == con->byte_idx) {
    return -1;
  } else {
    unsigned char to_extract = con->data[con->byte_idx];
    int bit = (to_extract >> (7 - con->bit_idx)) & 0x1;
    con->bit_idx++;
    if (con->bit_idx == 8) {
      con->bit_idx = 0;
      con->byte_idx++;
    }
    return bit;
  }
}

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


decompiled_code:
unsigned __int64 __fastcall byte_wcontext_write(__int64 *a1, char a2)
{
unsigned __int64 v3; // rsi
bool v4; // zf
__int64 v6; // rdi
unsigned __int64 result; // rax
__int64 v8; // rax

v3 = a1[2];
v4 = a1[1] == v3;
if ( a1[1] < v3 )
_assert_fail("con->len >= con->byte_idx", "rle.c", 0x4Bu, "byte_wcontext_write");
v6 = *a1;
if ( v4 )
{
v8 = xrealloc(v6, 2 * v3);
v3 = a1[2];
a1[1] *= 2LL;
*a1 = v8;
v6 = v8;
}
result = v3 + 1;
a1[2] = v3 + 1;
*(_BYTE *)(v6 + v3) = a2;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(__int64 *a1, char a2)
{
unsigned __int64 v3; // rsi
bool v4; // zf
__int64 v6; // rdi
unsigned __int64 result; // rax
__int64 v8; // rax

v3 = a1[2];
v4 = a1[1] == v3;
if ( a1[1] < v3 )
_assert_fail("con->len >= con->byte_idx", "rle.c", 0x4Bu, "byte_wcontext_write");
v6 = *a1;
if ( v4 )
{
v8 = xrealloc(v6, 2 * v3);
v3 = a1[2];
a1[1] *= 2LL;
*a1 = v8;
v6 = v8;
}
result = v3 + 1;
a1[2] = v3 + 1;
*(_BYTE *)(v6 + v3) = a2;
return result;
}

original_code:
static void byte_wcontext_write(byte_wcontext *con, uint8_t byte) {
  ((con->len >= con->byte_idx) ? (void) (0) : __assert_fail ("con->len >= con->byte_idx", "rle.c", 75, __extension__ __PRETTY_FUNCTION__));
  if (con->len == con->byte_idx) {
    con->buffer = xrealloc(con->buffer, con->len*2);
    con->len *= 2;
  }
  con->buffer[con->byte_idx++] = byte;
}

canonical_original_code:
static void byte_wcontext_write(struct byte_wcontext *con, unsigned char byte) {
  ((con->len >= con->byte_idx) ? (void) (0) : __assert_fail ("con->len >= con->byte_idx", "rle.c", 75, __extension__ __PRETTY_FUNCTION__));
  if (con->len == con->byte_idx) {
    con->buffer = xrealloc(con->buffer, con->len*2);
    con->len *= 2;
  }
  con->buffer[con->byte_idx++] = byte;
}

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

variable_types:
byte
unsigned char

return_type: void


decompiled_code:
__int64 __fastcall rle_encode(__int64 a1, __int64 a2, _QWORD *a3)
{
int v4; // eax
signed int i; // esi
char v7; // [rsp+7h] [rbp-61h] BYREF
__int64 v8; // [rsp+8h] [rbp-60h] BYREF
__int64 v9[4]; // [rsp+10h] [rbp-58h] BYREF
char v10[56]; // [rsp+30h] [rbp-38h] BYREF

rcontext_init((__int64)v10, a1, a2);
v8 = econtext_init(v9);
byte_wcontext_init_constprop_0(v9);
v4 = rcontext_read_bit((__int64)v10);
if ( v4 >= 0 )
{
for ( i = v4; i >= 0; i = rcontext_read_bit((__int64)v10) )
{
while ( !(unsigned int)econtext_add_bit((unsigned int *)&v8, i, &v7) )
{
i = rcontext_read_bit((__int64)v10);
if ( i < 0 )
goto LABEL_6;
}
byte_wcontext_write(v9, v7);
}
}
LABEL_6:
if ( (unsigned int)econtext_end_bits_isra_0(v8, SHIDWORD(v8), &v7) )
byte_wcontext_write(v9, v7);
*a3 = v9[2];
return v9[0];
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, _QWORD *a3)
{
int v4; // eax
signed int i; // esi
char v7; // [rsp+7h] [rbp-61h] BYREF
__int64 v8; // [rsp+8h] [rbp-60h] BYREF
__int64 v9[4]; // [rsp+10h] [rbp-58h] BYREF
char v10[56]; // [rsp+30h] [rbp-38h] BYREF

func2((__int64)v10, a1, a2);
v8 = func3(v9);
byte_wcontext_init_constprop_0(v9);
v4 = func6((__int64)v10);
if ( v4 >= 0 )
{
for ( i = v4; i >= 0; i = func6((__int64)v10) )
{
while ( !(unsigned int)func5((unsigned int *)&v8, i, &v7) )
{
i = func6((__int64)v10);
if ( i < 0 )
goto LABEL_6;
}
func7(v9, v7);
}
}
LABEL_6:
if ( (unsigned int)func9(v8, SHIDWORD(v8), &v7) )
func7(v9, v7);
*a3 = v9[2];
return v9[0];
}

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 *


decompiled_code:
void *__fastcall rle_decode(unsigned __int8 *a1, __int64 a2, void **a3)
{
unsigned __int8 *v4; // r13
int v5; // ebx
unsigned __int8 v6; // r12
char v7; // r8
int v8; // ebp
void *result; // rax
void *ptr[11]; // [rsp+0h] [rbp-58h] BYREF

v4 = a1;
bit_wcontext_init_constprop_0((__int64 *)ptr);
if ( a2 )
{
do
{
v5 = 0;
v6 = run_decode_type(*v4);
v8 = run_decode_len(v7);
if ( v8 > 0 )
{
do
{
++v5;
bit_wcontext_write((__int64 *)ptr, v6);
}
while ( v8 != v5 );
}
++v4;
}
while ( &a1[a2] != v4 );
}
result = ptr[0];
if ( ptr[3] )
{
free(ptr[0]);
result = 0LL;
}
else
{
*a3 = ptr[2];
}
return result;
}

canonical_decompiled_code:
void *__fastcall func11(unsigned __int8 *a1, __int64 a2, void **a3)
{
unsigned __int8 *v4; // r13
int v5; // ebx
unsigned __int8 v6; // r12
char v7; // r8
int v8; // ebp
void *result; // rax
void *ptr[11]; // [rsp+0h] [rbp-58h] BYREF

v4 = a1;
bit_wcontext_init_constprop_0((__int64 *)ptr);
if ( a2 )
{
do
{
v5 = 0;
v6 = func0(*v4);
v8 = func1(v7);
if ( v8 > 0 )
{
do
{
++v5;
func8((__int64 *)ptr, v6);
}
while ( v8 != v5 );
}
++v4;
}
while ( &a1[a2] != v4 );
}
result = ptr[0];
if ( ptr[3] )
{
free(ptr[0]);
result = 0LL;
}
else
{
*a3 = ptr[2];
}
return result;
}

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

variable_types: j int


cmpfunc

decompiled_code:
__int64 __fastcall cmpfunc(const void *a1, const void *a2)
{
return (unsigned int)*(_QWORD *)a1 - *(_DWORD *)a2;
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, const void *a2)
{
return (unsigned int)*(_QWORD *)a1 - *(_DWORD *)a2;
}

original_code:
int cmpfunc (const void * a, const void * b)
{
   return ( *(long long*)a - *(long long*)b );
}

canonical_original_code:
int cmpfunc(void *a, void *b)
{
   return ( *(long long *)a - *(long long *)b );
}

variable_types:
a
void *

variable_types:
b
void *

return_type: int


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

v2 = atoi(a1);
atoi(a2);
return v2;
}

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

v2 = atoi(a1);
atoi(a2);
return v2;
}

original_code:
Point create_point(char* x, char* y)
{
    Point point;
    point.x = atoi(x);
    point.y = atoi(y);
    return point;
}

canonical_original_code:
struct point create_point(char *x, char *y)
{
    struct point point;
    point.x = atoi(x);
    point.y = atoi(y);
    return point;
}

variable_types:
x
char *

variable_types:
y
char *

variable_types: struct point { long long x; long long y; }


decompiled_code:
__int64 __fastcall calculate_squared_distance(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return (a3 - a1) * (a3 - a1) + (a4 - a2) * (a4 - a2);
}

original_code:
long long calculate_squared_distance(Point point1, Point point2)
{
    long long side = 0;
    long long x_side = point2.x - point1.x;
    x_side = x_side * x_side;
    long long y_side = point2.y - point1.y;
    y_side = y_side * y_side;
    long long total = x_side + y_side;
    side = total;
    return side;
}

canonical_original_code:
long long calculate_squared_distance(struct point point1, struct point point2)
{
    long long side = 0;
    long long x_side = point2.x - point1.x;
    x_side = x_side * x_side;
    long long y_side = point2.y - point1.y;
    y_side = y_side * y_side;
    long long total = x_side + y_side;
    side = total;
    return side;
}

variable_types:
side
long long

variable_types:
total
long long

return_type: long long

user_defined_types: struct point { long long x; long long y; }


gcd

decompiled_code:
__int64 __fastcall gcd(__int64 a1, __int64 a2)
{
if ( a2 <= 1 || a1 <= 1 )
return 1LL;
if ( a1 != a2 )
{
while ( 1 )
{
if ( a2 < a1 )
{
a1 -= a2;
if ( a1 <= 1 )
return 1LL;
}
else
{
a2 -= a1;
}
if ( a2 <= 1 )
break;
if ( a2 == a1 )
return (unsigned int)a1;
}
return 1LL;
}
return (unsigned int)a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
if ( a2 <= 1 || a1 <= 1 )
return 1LL;
if ( a1 != a2 )
{
while ( 1 )
{
if ( a2 < a1 )
{
a1 -= a2;
if ( a1 <= 1 )
return 1LL;
}
else
{
a2 -= a1;
}
if ( a2 <= 1 )
break;
if ( a2 == a1 )
return (unsigned int)a1;
}
return 1LL;
}
return (unsigned int)a1;
}

original_code:
int gcd(long long a, long long b){
    if(a <= 1 || b <= 1){
        return 1;
    }
    if(a == b){
        return a;
    }
    if(a > b){
        return gcd(a-b, b);
    } else{
        return gcd(a, b-a);
    }
}

variable_types:
a
long long

variable_types:
b
long long


original_code:
void reduce_slope(Slope * slope){
    if(slope->rise == 0){
        slope->run = 1;
        return;
    }
    if(slope->run == 0){
        slope->rise = 1;
        return;
    }
    int divisor = gcd(slope->rise, slope->run);
    slope->rise = slope->rise/divisor;
    slope->run = slope->run/divisor;
}

canonical_original_code:
void reduce_slope(struct slope *slope){
    if(slope->rise == 0){
        slope->run = 1;
        return;
    }
    if(slope->run == 0){
        slope->rise = 1;
        return;
    }
    int divisor = gcd(slope->rise, slope->run);
    slope->rise = slope->rise/divisor;
    slope->run = slope->run/divisor;
}

variable_types: struct slope { int is_negative; int rise; int run; } *

variable_types: divisor int


decompiled_code:
__int64 __fastcall calculate_slope(int a1, int a2, int a3, int a4)
{
__int64 v5; // [rsp+18h] [rbp-20h] BYREF
int v6; // [rsp+20h] [rbp-18h]

v6 = a1 - a3;
HIDWORD(v5) = a2 - a4;
insure_correct_slope(&v5);
reduce_slope((__int64)&v5);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, int a2, int a3, int a4)
{
__int64 v5; // [rsp+18h] [rbp-20h] BYREF
int v6; // [rsp+20h] [rbp-18h]

v6 = a1 - a3;
HIDWORD(v5) = a2 - a4;
func12(&v5);
func11((__int64)&v5);
return v5;
}

original_code:
Slope calculate_slope(Point pointA, Point pointB){
    Slope slope;
    slope.rise = pointA.y - pointB.y;
    slope.run = pointA.x - pointB.x;
    insure_correct_slope(&slope);
    reduce_slope(&slope);
    return slope;
}

canonical_original_code:
struct slope calculate_slope(struct point pointA, struct point pointB){
    struct slope slope;
    slope.rise = pointA.y - pointB.y;
    slope.run = pointA.x - pointB.x;
    insure_correct_slope(&slope);
    reduce_slope(&slope);
    return slope;
}

variable_types:
pointB
struct point

variable_types: struct slope { int is_negative; int rise; int run; }


decompiled_code:
_BOOL8 __fastcall are_slopes_equal(__int64 a1, int a2, __int64 a3, int a4)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 == a3 )
result = a2 == a4;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(__int64 a1, int a2, __int64 a3, int a4)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 == a3 )
result = a2 == a4;
return result;
}

original_code:
int are_slopes_equal(Slope slopeA, Slope slopeB){
    return (slopeA.is_negative == slopeB.is_negative) && (slopeA.rise == slopeB.rise) && (slopeA.run == slopeB.run);
}

canonical_original_code:
int are_slopes_equal(struct slope slopeA, struct slope slopeB){
    return (slopeA.is_negative == slopeB.is_negative) && (slopeA.rise == slopeB.rise) && (slopeA.run == slopeB.run);
}

variable_types:
slopeB
struct slope

user_defined_types: struct slope { int is_negative; int rise; int run; }


decompiled_code:
__int64 __fastcall are_points_equal(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return (a1 == a3) & (unsigned __int8)(a2 == a4);
}

original_code:
int are_points_equal(Point pointA, Point pointB){
    long long x = pointA.x == pointB.x;
    long long y = pointA.y == pointB.y;
    return y && x;
}

canonical_original_code:
int are_points_equal(struct point pointA, struct point pointB){
    long long x = pointA.x == pointB.x;
    long long y = pointA.y == pointB.y;
    return y && x;
}

variable_types:
x
long long

variable_types:
y
long long


decompiled_code:
_BOOL8 __fastcall has_overlapping_points(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BOOL4 v4; // er12
__int64 v5; // r8
__int64 v6; // r9
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r10
__int64 v10; // r11

v4 = 1;
if ( !(unsigned int)are_points_equal(a1, a2, a3, a4) && !(unsigned int)are_points_equal(a1, a2, v5, v6) )
v4 = are_points_equal(v10, v9, v8, v7) != 0;
return v4;
}

original_code:
int has_overlapping_points(Point pointA, Point pointB, Point pointC){
    if(are_points_equal(pointA, pointB)){
        return 1;
    }
    if(are_points_equal(pointA, pointC)){
        return 1;
    }
    if(are_points_equal(pointB, pointC)){
        return 1;
    }
    return 0;
}

canonical_original_code:
int has_overlapping_points(struct point pointA, struct point pointB, struct point pointC){
    if(are_points_equal(pointA, pointB)){
        return 1;
    }
    if(are_points_equal(pointA, pointC)){
        return 1;
    }
    if(are_points_equal(pointB, pointC)){
        return 1;
    }
    return 0;
}

variable_types:
pointC
struct point


decompiled_code:
_BOOL8 __fastcall is_illegal_triangle(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // er15
int v5; // er14
int v6; // er8
int v8; // er12
__int64 v9; // rax
int v10; // edx
int v11; // er9
__int64 v12; // rax
int v13; // edx
__int64 v14; // [rsp+8h] [rbp-50h]
int v15; // [rsp+10h] [rbp-48h]

v4 = a4;
v5 = a3;
if ( has_overlapping_points(a1, a2, a3, a4) )
return 1LL;
v8 = v6;
v9 = calculate_slope(a1, a2, v5, v4);
v15 = v10;
v14 = v9;
v12 = calculate_slope(a1, a2, v8, v11);
return are_slopes_equal(v14, v15, v12, v13);
}

original_code:
int is_illegal_triangle(Point point1, Point point2, Point point3){
    if(has_overlapping_points(point1, point2, point3)){
        return 1;
    }
    Slope slope_1_2 = calculate_slope(point1, point2);
    Slope slope_1_3 = calculate_slope(point1, point3);
    int result = are_slopes_equal(slope_1_2, slope_1_3);
    return result;
}

canonical_original_code:
int is_illegal_triangle(struct point point1, struct point point2, struct point point3){
    if(has_overlapping_points(point1, point2, point3)){
        return 1;
    }
    struct slope slope_1_2 = calculate_slope(point1, point2);
    struct slope slope_1_3 = calculate_slope(point1, point3);
    int result = are_slopes_equal(slope_1_2, slope_1_3);
    return result;
}

variable_types: result int


decompiled_code:
__int64 __fastcall dot_product(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rdi
__int64 result; // rax
__int64 v8; // rsi

v6 = (a3 - a5) * (a1 - a5);
result = 0xFFFFFFFFLL;
v8 = (a4 - a6) * (a2 - a6);
if ( v8 + v6 >= 0 )
result = v8 + v6 != 0;
return result;
}

original_code:
int dot_product(Point point_A, Point point_B, Point origin){
    long long x = (point_A.x-origin.x)*(point_B.x-origin.x);
    long long y = (point_A.y-origin.y)*(point_B.y-origin.y);
    long long result = x+y;
    if( result < 0){
        return -1;
    }
    if( result > 0){
        return 1;
    }
    return 0;
}

canonical_original_code:
int dot_product(struct point point_A, struct point point_B, struct point origin){
    long long x = (point_A.x-origin.x)*(point_B.x-origin.x);
    long long y = (point_A.y-origin.y)*(point_B.y-origin.y);
    long long result = x+y;
    if( result < 0){
        return -1;
    }
    if( result > 0){
        return 1;
    }
    return 0;
}

variable_types:
origin
struct point

variable_types:
result
long long


decompiled_code:
__int64 __fastcall find_triangle_side_type(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

v1 = a1[1];
v2 = v1 == a1[2];
if ( *a1 == v1 )
++v2;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

v1 = a1[1];
v2 = v1 == a1[2];
if ( *a1 == v1 )
++v2;
return v2;
}

original_code:
triangle_side_type find_triangle_side_type(long long sides[])
{
    triangle_side_type result;
    long long s1 = sides[0];
    long long s2 = sides[1];
    long long s3 = sides[2];
    if(s1 == s2){
        if(s2 == s3){
            result = eq;
        } else{
            result = is;
        }
    }else if(s2 == s3){
        result = is;
    } else{
        result = sc;
    }
    return result;
}

canonical_original_code:
enum triangle_side_type find_triangle_side_type(long long sides[])
{
    enum triangle_side_type result;
    long long s1 = sides[0];
    long long s2 = sides[1];
    long long s3 = sides[2];
    if(s1 == s2){
        if(s2 == s3){
            result = eq;
        } else{
            result = is;
        }
    }else if(s2 == s3){
        result = is;
    } else{
        result = sc;
    }
    return result;
}

variable_types:
sides
long long []

variable_types: enum triangle_side_type { sc=0, is=1, eq=2 }


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

result = *a1 == 0;
if ( *a1 < 0 )
result = 2LL;
return result;
}

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

result = *a1 == 0;
if ( *a1 < 0 )
result = 2LL;
return result;
}

canonical_original_code:
enum triangle_angle_type find_triangle_angle_type(long long angles[])
{
    if(angles[0] < 0){
        return ob;
    }
    if(angles[0] > 0){
        return ac;
    }
    return ri;
}

variable_types:
angles
long long []

return_type: enum triangle_angle_type { ac=0, ri=1, ob=2 }


decompiled_code:
char *__fastcall triangle_classification(_QWORD *a1, __int64 *a2)
{
unsigned int v2; // eax
int v3; // ecx
__int64 v4; // r8

find_triangle_side_type(a1);
v2 = find_triangle_angle_type(a2);
if ( v3 == 1 )
{
if ( v2 <= 2 )
return CSWTCH_21[v2];
return (char *)v4;
}
if ( v3 == 2 || v3 || v2 > 2 )
return (char *)v4;
return CSWTCH_20[v2];
}

canonical_decompiled_code:
char *__fastcall func21(_QWORD *a1, __int64 *a2)
{
unsigned int v2; // eax
int v3; // ecx
__int64 v4; // r8

func19(a1);
v2 = func20(a2);
if ( v3 == 1 )
{
if ( v2 <= 2 )
return CSWTCH_21[v2];
return (char *)v4;
}
if ( v3 == 2 || v3 || v2 > 2 )
return (char *)v4;
return CSWTCH_20[v2];
}

original_code:
char* triangle_classification(long long sides[], long long angles[])
{
    triangle_side_type side_type = find_triangle_side_type(sides);
    triangle_angle_type angle_type = find_triangle_angle_type(angles);
    switch(side_type){
        case sc:
        {
         switch(angle_type){
             case ac:
             {
                 return "scalene acute";
             }
             case ri:
             {
                 return "scalene right";
             }
             case ob:
             {
                 return "scalene obtuse";
             }
         }
        }
        case is:
        {
            switch(angle_type){
             case ac:
             {
                 return "isosceles acute";
             }
             case ri:
             {
                 return "isosceles right";
             }
             case ob:
             {
                 return "isosceles obtuse";
             }
         }
        }
        case eq:
        {
             return "equilateral acute";
        }
    }
}

canonical_original_code:
char *triangle_classification(long long sides[], long long angles[])
{
    enum triangle_side_type side_type = find_triangle_side_type(sides);
    enum triangle_angle_type angle_type = find_triangle_angle_type(angles);
    switch(side_type){
        case sc:
        {
         switch(angle_type){
             case ac:
             {
                 return "scalene acute";
             }
             case ri:
             {
                 return "scalene right";
             }
             case ob:
             {
                 return "scalene obtuse";
             }
         }
        }
        case is:
        {
            switch(angle_type){
             case ac:
             {
                 return "isosceles acute";
             }
             case ri:
             {
                 return "isosceles right";
             }
             case ob:
             {
                 return "isosceles obtuse";
             }
         }
        }
        case eq:
        {
             return "equilateral acute";
        }
    }
}

variable_types: enum triangle_angle_type { ac=0, ri=1, ob=2 }

return_type: char *

user_defined_types: enum triangle_side_type { sc=0, is=1, eq=2 }


original_code:
char* find_triangle_type(Point points[])
{
    if(is_illegal_triangle(points[0], points[1], points[2])){
        return "not a triangle";
    }
    long long sides[3];
    long long dot_product_angles[3];
    sides[0] = calculate_squared_distance(points[0], points[1]);
    sides[1] = calculate_squared_distance(points[0], points[2]);
    sides[2] = calculate_squared_distance(points[1], points[2]);
    dot_product_angles[0] = dot_product(points[0], points[1], points[2]);
    dot_product_angles[1] = dot_product(points[1], points[2], points[0]);
    dot_product_angles[2] = dot_product(points[2], points[0], points[1]);
    qsort(sides, 3, sizeof(long long), cmpfunc);
    qsort(dot_product_angles, 3, sizeof(long long), cmpfunc);
    return triangle_classification(sides, dot_product_angles);
}

canonical_original_code:
char *find_triangle_type(struct point points[])
{
    if(is_illegal_triangle(points[0], points[1], points[2])){
        return "not a triangle";
    }
    long long sides[3];
    long long dot_product_angles[3];
    sides[0] = calculate_squared_distance(points[0], points[1]);
    sides[1] = calculate_squared_distance(points[0], points[2]);
    sides[2] = calculate_squared_distance(points[1], points[2]);
    dot_product_angles[0] = dot_product(points[0], points[1], points[2]);
    dot_product_angles[1] = dot_product(points[1], points[2], points[0]);
    dot_product_angles[2] = dot_product(points[2], points[0], points[1]);
    qsort(sides, 3, sizeof(long long), cmpfunc);
    qsort(dot_product_angles, 3, sizeof(long long), cmpfunc);
    return triangle_classification(sides, dot_product_angles);
}

variable_types: struct point { long long x; long long y; } []

variable_types:
sides
long long [3]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rax
const char *v5; // rsi
const char *v6; // rdi
__int64 v7; // rdx
__int64 v8; // rax
const char *v9; // rsi
const char *v10; // rdi
__int64 v11; // rdx
__int64 v12; // rax
__int64 v13; // rdx
const char *v14; // rax
__int64 v16[7]; // [rsp+0h] [rbp-38h] BYREF

v4 = create_point(argv[1], argv[2], envp);
v5 = argv[4];
v6 = argv[3];
v16[0] = v4;
v16[1] = v7;
v8 = create_point(v6, v5, v7);
v9 = argv[6];
v10 = argv[5];
v16[2] = v8;
v16[3] = v11;
v12 = create_point(v10, v9, v11);
v16[5] = v13;
v16[4] = v12;
v14 = (const char *)find_triangle_type(v16);
puts(v14);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rax
const char *v5; // rsi
const char *v6; // rdi
__int64 v7; // rdx
__int64 v8; // rax
const char *v9; // rsi
const char *v10; // rdi
__int64 v11; // rdx
__int64 v12; // rax
__int64 v13; // rdx
const char *v14; // rax
__int64 v16[7]; // [rsp+0h] [rbp-38h] BYREF

v4 = func8(argv[1], argv[2], envp);
v5 = argv[4];
v6 = argv[3];
v16[0] = v4;
v16[1] = v7;
v8 = func8(v6, v5, v7);
v9 = argv[6];
v10 = argv[5];
v16[2] = v8;
v16[3] = v11;
v12 = func8(v10, v9, v11);
v16[5] = v13;
v16[4] = v12;
v14 = (const char *)func22(v16);
puts(v14);
return 0;
}

original_code:
int main(int argc, char** argv) {
    Point points[3];
    points[0] = create_point(argv[1], argv[2]);
    points[1] = create_point(argv[3], argv[4]);
    points[2] = create_point(argv[5], argv[6]);
    char* triangle_type = find_triangle_type(points);
    printf("%s\n", triangle_type);
    return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
    struct point points[3];
    points[0] = create_point(argv[1], argv[2]);
    points[1] = create_point(argv[3], argv[4]);
    points[2] = create_point(argv[5], argv[6]);
    char *triangle_type = find_triangle_type(points);
    printf("%s\n", triangle_type);
    return (0);
}

variable_types: argc int

variable_types:
argv
char **

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


decompiled_code:
void init_buffer()
{
*(__m128i *)buf = _mm_load_si128((const __m128i *)&xmmword_4021A0);
xmmword_404090 = *(_OWORD *)buf;
xmmword_4040A0 = *(_OWORD *)buf;
xmmword_4040B0 = *(_OWORD *)buf;
xmmword_4040C0 = *(_OWORD *)buf;
xmmword_4040D0 = *(_OWORD *)buf;
xmmword_4040E0 = *(_OWORD *)buf;
xmmword_4040F0 = *(_OWORD *)buf;
xmmword_404100 = *(_OWORD *)buf;
xmmword_404110 = *(_OWORD *)buf;
xmmword_404120 = *(_OWORD *)buf;
xmmword_404130 = *(_OWORD *)buf;
xmmword_404140 = *(_OWORD *)buf;
xmmword_404150 = *(_OWORD *)buf;
xmmword_404160 = *(_OWORD *)buf;
xmmword_404170 = *(_OWORD *)buf;
}

canonical_decompiled_code:
void func9()
{
*(__m128i *)buf = _mm_load_si128((const __m128i *)&xmmword_4021A0);
xmmword_404090 = *(_OWORD *)buf;
xmmword_4040A0 = *(_OWORD *)buf;
xmmword_4040B0 = *(_OWORD *)buf;
xmmword_4040C0 = *(_OWORD *)buf;
xmmword_4040D0 = *(_OWORD *)buf;
xmmword_4040E0 = *(_OWORD *)buf;
xmmword_4040F0 = *(_OWORD *)buf;
xmmword_404100 = *(_OWORD *)buf;
xmmword_404110 = *(_OWORD *)buf;
xmmword_404120 = *(_OWORD *)buf;
xmmword_404130 = *(_OWORD *)buf;
xmmword_404140 = *(_OWORD *)buf;
xmmword_404150 = *(_OWORD *)buf;
xmmword_404160 = *(_OWORD *)buf;
xmmword_404170 = *(_OWORD *)buf;
}

original_code:
void init_buffer() {
  for (int i = 0; i < sizeof(buf) / sizeof(buf[0]); i++) {
    buf[i] = '\xCC';
  }
}

variable_types: i int


decompiled_code:
char *__fastcall reverse_inplace(char *a1, unsigned __int64 a2)
{
char *result; // rax
unsigned __int64 v3; // rsi
char *v4; // rsi
char v5; // cl
char v6; // dl

result = (char *)a2;
v3 = a2 >> 1;
if ( v3 )
{
result = &result[(_QWORD)a1 - 1];
v4 = &a1[v3];
do
{
v5 = *result;
v6 = *a1++;
--result;
*(a1 - 1) = v5;
result[1] = v6;
}
while ( a1 != v4 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func10(char *a1, unsigned __int64 a2)
{
char *result; // rax
unsigned __int64 v3; // rsi
char *v4; // rsi
char v5; // cl
char v6; // dl

result = (char *)a2;
v3 = a2 >> 1;
if ( v3 )
{
result = &result[(_QWORD)a1 - 1];
v4 = &a1[v3];
do
{
v5 = *result;
v6 = *a1++;
--result;
*(a1 - 1) = v5;
result[1] = v6;
}
while ( a1 != v4 );
}
return result;
}

original_code:
void reverse_inplace(char *buf, size_t len) {
  size_t half = len / 2;
  for (int i = 0; i < half; i++) {
    char tmp = buf[i];
    buf[i] = buf[len-i-1];
    buf[len-i-1] = tmp;
  }
}

canonical_original_code:
void reverse_inplace(char *buf, unsigned long len) {
  unsigned long half = len / 2;
  for (int i = 0; i < half; i++) {
    char tmp = buf[i];
    buf[i] = buf[len-i-1];
    buf[len-i-1] = tmp;
  }
}

variable_types:
buf
char *

variable_types:
len
unsigned long

variable_types:
half
unsigned long

variable_types: tmp char


itostr

decompiled_code:
char *__fastcall itostr(__int64 a1, int a2, unsigned __int64 *a3)
{
int v5; // er8
char *v6; // rsi
int v7; // eax
int v8; // edx
int v9; // ecx
unsigned __int64 v10; // rsi
int v11; // er8
char *result; // rax
size_t v13; // rax

if ( (unsigned int)(a2 - 2) > 0xE )
__assert_fail(
"base >= 2 && base <= 16 && \"Only accepted bases are binary up to hex\"",
"xprintf.c",
0x67u,
"itostr");
init_buffer();
v6 = buf;
v7 = v5;
if ( v5 )
{
do
{
v8 = v7 % a2;
v7 /= a2;
v9 = -v8;
if ( v5 >= 0 )
v9 = v8;
*v6++ = dig_lookup[v9];
}
while ( v7 );
*v6 = 0;
v10 = v6 - buf;
reverse_inplace(buf, v10);
if ( v11 < 0 )
{
v13 = strlen(buf);
memmove(&buf[1], buf, v13);
result = buf;
buf[0] = 45;
*a3 = v10 + 1;
}
else
{
*a3 = v10;
result = buf;
}
}
else
{
strcpy(buf, "0");
result = buf;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func11(__int64 a1, int a2, unsigned __int64 *a3)
{
int v5; // er8
char *v6; // rsi
int v7; // eax
int v8; // edx
int v9; // ecx
unsigned __int64 v10; // rsi
int v11; // er8
char *result; // rax
size_t v13; // rax

if ( (unsigned int)(a2 - 2) > 0xE )
__assert_fail(
"base >= 2 && base <= 16 && \"Only accepted bases are binary up to hex\"",
"xprintf.c",
0x67u,
"itostr");
func9();
v6 = buf;
v7 = v5;
if ( v5 )
{
do
{
v8 = v7 % a2;
v7 /= a2;
v9 = -v8;
if ( v5 >= 0 )
v9 = v8;
*v6++ = dig_lookup[v9];
}
while ( v7 );
*v6 = 0;
v10 = v6 - buf;
func10(buf, v10);
if ( v11 < 0 )
{
v13 = strlen(buf);
memmove(&buf[1], buf, v13);
result = buf;
buf[0] = 45;
*a3 = v10 + 1;
}
else
{
*a3 = v10;
result = buf;
}
}
else
{
strcpy(buf, "0");
result = buf;
}
return result;
}

original_code:
const char* itostr(int val, int base, size_t *len) {
  ((base >= 2 && base <= 16 && "Only accepted bases are binary up to hex") ? (void) (0) : __assert_fail ("base >= 2 && base <= 16 && \"Only accepted bases are binary up to hex\"", "xprintf.c", 103, __extension__ __PRETTY_FUNCTION__));
  init_buffer();
  if (val == 0) {
    buf[0] = '0';
    buf[1] = '\0';
    return &buf[0];
  }
  _Bool neg = (val < 0);
  char *cur = &buf[0];
  while (val != 0) {
    int new_dig = val % base;
    if (neg) new_dig *= -1;
    *cur++ = dig_lookup[new_dig];
    val = val / base;
  }
  *cur = '\0';
  reverse_inplace(buf, cur - buf);
  if (neg) {
    memmove(buf+1, buf, strlen(buf));
    buf[0] = '-';
    *len = (cur - buf) + 1;
  } else {
    *len = cur - buf;
  }
  return buf;
}

canonical_original_code:
char *itostr(int val, int base, unsigned long *len) {
  ((base >= 2 && base <= 16 && "Only accepted bases are binary up to hex") ? (void) (0) : __assert_fail ("base >= 2 && base <= 16 && \"Only accepted bases are binary up to hex\"", "xprintf.c", 103, __extension__ __PRETTY_FUNCTION__));
  init_buffer();
  if (val == 0) {
    buf[0] = '0';
    buf[1] = '\0';
    return &buf[0];
  }
  _Bool neg = (val < 0);
  char *cur = &buf[0];
  while (val != 0) {
    int new_dig = val % base;
    if (neg) new_dig *= -1;
    *cur++ = dig_lookup[new_dig];
    val = val / base;
  }
  *cur = '\0';
  reverse_inplace(buf, cur - buf);
  if (neg) {
    memmove(buf+1, buf, strlen(buf));
    buf[0] = '-';
    *len = (cur - buf) + 1;
  } else {
    *len = cur - buf;
  }
  return buf;
}

variable_types: val int

variable_types: base int

variable_types:
len
unsigned long *

variable_types:
cur
char *


utostr

decompiled_code:
char *__fastcall utostr(unsigned int a1, unsigned int a2)
{
_BYTE *v2; // rcx
unsigned int v3; // edx
__int64 v4; // r8
_QWORD *v5; // r9
char *result; // rax

if ( a2 - 2 > 0xE )
__assert_fail(
"base >= 2 && base <= 16 && \"Only accepted bases are binary up to hex\"",
"xprintf.c",
0x8Bu,
"utostr");
init_buffer();
if ( a1 )
{
do
{
*v2++ = dig_lookup[a1 % a2];
v3 = a1;
a1 /= a2;
}
while ( a2 <= v3 );
*v2 = 0;
reverse_inplace(buf, v2 - buf);
*v5 = v4;
result = buf;
}
else
{
strcpy(buf, "0");
result = buf;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func12(unsigned int a1, unsigned int a2)
{
_BYTE *v2; // rcx
unsigned int v3; // edx
__int64 v4; // r8
_QWORD *v5; // r9
char *result; // rax

if ( a2 - 2 > 0xE )
__assert_fail(
"base >= 2 && base <= 16 && \"Only accepted bases are binary up to hex\"",
"xprintf.c",
0x8Bu,
"utostr");
func9();
if ( a1 )
{
do
{
*v2++ = dig_lookup[a1 % a2];
v3 = a1;
a1 /= a2;
}
while ( a2 <= v3 );
*v2 = 0;
func10(buf, v2 - buf);
*v5 = v4;
result = buf;
}
else
{
strcpy(buf, "0");
result = buf;
}
return result;
}

original_code:
const char* utostr(unsigned val, int base, size_t *len) {
  ((base >= 2 && base <= 16 && "Only accepted bases are binary up to hex") ? (void) (0) : __assert_fail ("base >= 2 && base <= 16 && \"Only accepted bases are binary up to hex\"", "xprintf.c", 139, __extension__ __PRETTY_FUNCTION__));
  init_buffer();
  if (val == 0) {
    buf[0] = '0';
    buf[1] = '\0';
    return &buf[0];
  }
  char *cur = &buf[0];
  while (val != 0) {
    int new_dig = val % base;
    *cur++ = dig_lookup[new_dig];
    val = val / base;
  }
  *cur = '\0';
  reverse_inplace(buf, cur - buf);
  *len = cur - buf;
  return buf;
}

canonical_original_code:
char *utostr(unsigned int val, int base, unsigned long *len) {
  ((base >= 2 && base <= 16 && "Only accepted bases are binary up to hex") ? (void) (0) : __assert_fail ("base >= 2 && base <= 16 && \"Only accepted bases are binary up to hex\"", "xprintf.c", 139, __extension__ __PRETTY_FUNCTION__));
  init_buffer();
  if (val == 0) {
    buf[0] = '0';
    buf[1] = '\0';
    return &buf[0];
  }
  char *cur = &buf[0];
  while (val != 0) {
    int new_dig = val % base;
    *cur++ = dig_lookup[new_dig];
    val = val / base;
  }
  *cur = '\0';
  reverse_inplace(buf, cur - buf);
  *len = cur - buf;
  return buf;
}

variable_types:
val
unsigned int


xvprintf

decompiled_code:
__int64 __fastcall xvprintf(char *a1, int *a2)
{
return xvfprintf(_bss_start, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(char *a1, int *a2)
{
return func13(_bss_start, a1, a2);
}

original_code:
int xvprintf(const char *fmt, va_list ap) {
  return xvfprintf(stdout, fmt, ap);
}

canonical_original_code:
int xvprintf(char *fmt, __builtin_va_list ap) {
  return xvfprintf(stdout, fmt, ap);
}

variable_types:
fmt
char *


xprintf

decompiled_code:
__int64 xprintf(char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return xvprintf(a1, (int *)va);
}

canonical_decompiled_code:
__int64 func16(char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func15(a1, (int *)va);
}

original_code:
int xprintf(const char *fmt, ...) {
  va_list ap;
  int res;
  __builtin_va_start(ap,fmt);
  res = xvprintf(fmt, ap);
  __builtin_va_end(ap);
  return res;
}

canonical_original_code:
int xprintf(char *fmt, ...) {
  __builtin_va_list ap;
  int res;
  __builtin_va_start(ap,fmt);
  res = xvprintf(fmt, ap);
  __builtin_va_end(ap);
  return res;
}

variable_types: res int


squaredDistance

decompiled_code:
__int64 __fastcall squaredDistance(int a1, int a2, int a3, int a4)
{
return (unsigned int)(int)((double)(a3 - a1) * (double)(a3 - a1) + (double)(a4 - a2) * (double)(a4 - a2));
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2, int a3, int a4)
{
return (unsigned int)(int)((double)(a3 - a1) * (double)(a3 - a1) + (double)(a4 - a2) * (double)(a4 - a2));
}

original_code:
long long squaredDistance(long long ax, long long ay, long long bx, long long by) {
 return pow(bx - ax, 2) + pow(by - ay, 2);
}

variable_types:
ax
long long

variable_types:
ay
long long

variable_types:
bx
long long

variable_types:
by
long long


getSides

original_code:
void getSides(struct triangle *triangle, struct pts pts){
 (*triangle).A = squaredDistance(pts.ax, pts.ay, pts.bx, pts.by);
 (*triangle).B = squaredDistance(pts.bx, pts.by, pts.cx, pts.cy);
 (*triangle).C = squaredDistance(pts.cx, pts.cy, pts.ax, pts.ay);
}

variable_types: struct triangle { long long A; long long B; long long C; } *

variable_types: struct pts { long long ax; long long ay; long long bx; long long by; long long cx; long long cy; }


getLongSide

decompiled_code:
__int64 __fastcall getLongSide(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v9; // rdx
__int64 result; // rax

v9 = a7;
result = 65LL;
if ( a7 <= a8 )
{
v9 = a8;
result = 66LL;
}
if ( a9 >= v9 )
result = 67LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v9; // rdx
__int64 result; // rax

v9 = a7;
result = 65LL;
if ( a7 <= a8 )
{
v9 = a8;
result = 66LL;
}
if ( a9 >= v9 )
result = 67LL;
return result;
}

original_code:
char getLongSide(struct triangle triangle) {
 char longSide = 'A';
 long long max = 0;
 if(triangle.A > triangle.B) {
  max = triangle.A;
 } else {
  longSide = 'B';
  max = triangle.B;
 }
 return max > triangle.C ? longSide : 'C';
}

variable_types: struct triangle { long long A; long long B; long long C; }

variable_types: longSide char

variable_types:
max
long long

return_type: char


findTriangle

original_code:
char * findTriangle(struct pts pts, struct triangle triangle) {
 char longSide = getLongSide(triangle);
 long angle = 0;
 if(longSide == 'A') {
  angle = findAngle((pts.bx - pts.cx),
  (pts.by - pts.cy), (pts.ax - pts.cx), (pts.ay - pts.cy));
 } else if(longSide == 'B') {
  angle = findAngle((pts.bx - pts.ax),
  (pts.by - pts.ay), (pts.cx - pts.ax), (pts.cy - pts.ay));
 } else {
  angle = findAngle((pts.ax - pts.bx),
  (pts.ay - pts.by), (pts.cx - pts.bx), (pts.cy - pts.by));
 }
 if(angle == 0) {
  return "right";
 } else if(angle > 0) {
  return "acute";
 } else {
  return "obtuse";
 }
}

canonical_original_code:
char *findTriangle(struct pts pts, struct triangle triangle) {
 char longSide = getLongSide(triangle);
 long angle = 0;
 if(longSide == 'A') {
  angle = findAngle((pts.bx - pts.cx),
  (pts.by - pts.cy), (pts.ax - pts.cx), (pts.ay - pts.cy));
 } else if(longSide == 'B') {
  angle = findAngle((pts.bx - pts.ax),
  (pts.by - pts.ay), (pts.cx - pts.ax), (pts.cy - pts.ay));
 } else {
  angle = findAngle((pts.ax - pts.bx),
  (pts.ay - pts.by), (pts.cx - pts.bx), (pts.cy - pts.by));
 }
 if(angle == 0) {
  return "right";
 } else if(angle > 0) {
  return "acute";
 } else {
  return "obtuse";
 }
}

variable_types: angle long

user_defined_types: struct pts { long long ax; long long ay; long long bx; long long by; long long cx; long long cy; }

user_defined_types: struct triangle { long long A; long long B; long long C; }


findType

decompiled_code:
const char *__fastcall findType(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
const char *result; // rax

if ( a8 == a9 || a7 == a8 || a7 == a9 )
result = "isosceles";
else
result = "scalene";
return result;
}

canonical_decompiled_code:
const char *__fastcall func12(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
const char *result; // rax

if ( a8 == a9 || a7 == a8 || a7 == a9 )
result = "isosceles";
else
result = "scalene";
return result;
}

original_code:
char * findType(struct triangle triangle) {
 int bool = triangle.A == triangle.B
    || triangle.B == triangle.C
    || triangle.C == triangle.A;
 return bool ? "isosceles" : "scalene";
}

canonical_original_code:
char *findType(struct triangle triangle) {
 int bool = triangle.A == triangle.B
    || triangle.B == triangle.C
    || triangle.C == triangle.A;
 return bool ? "isosceles" : "scalene";
}

variable_types: bool int


collinearCheck

original_code:
int collinearCheck(struct pts pts) {
 int bool = ((pts.ax * (pts.by - pts.cy)) +
    (pts.bx * (pts.cy - pts.ay)) +
    (pts.cx * (pts.ay - pts.by))) == 0;
 return bool;
}


main

original_code:
int main(int argc, char *argv[]) {
 struct triangle triangle = {0};
 struct pts pts = {0};
 if(argc == 7) {
  setup(&pts, argv);
 } else {
  printf("not a triangle\n");
  return 0;
 }
    getSides(&triangle, pts);
    if(collinearCheck(pts)) {
     printf("not a triangle\n");
     return 0;
    }
    printf("%s %s\n",findType(triangle),findTriangle(pts, triangle));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


findAngle

decompiled_code:
__int64 __fastcall findAngle(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return a3 * a1 + a4 * a2;
}

original_code:
long findAngle(long ax, long ay, long bx, long by) {
 return (ax * bx) + (ay * by);
}

variable_types: ax long

variable_types: ay long

variable_types: bx long

variable_types: by long

return_type: long


decompiled_code:
__int64 __fastcall length_squared(__int64 a1, __int64 a2)
{
return a1 * a1 + a2 * a2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
return a1 * a1 + a2 * a2;
}

original_code:
long long length_squared(long long x, long long y) {
  return x * x + y * y;
}

variable_types:
x
long long

variable_types:
y
long long


decompiled_code:
const char *__fastcall side_type_squares(__int64 a1, __int64 a2, __int64 a3)
{
const char *result; // rax

if ( a1 == a3 || a1 == a2 || a2 == a3 )
result = "isosceles";
else
result = "scalene";
return result;
}

canonical_decompiled_code:
const char *__fastcall func8(__int64 a1, __int64 a2, __int64 a3)
{
const char *result; // rax

if ( a1 == a3 || a1 == a2 || a2 == a3 )
result = "isosceles";
else
result = "scalene";
return result;
}

original_code:
const char *side_type_squares(long long asq, long long bsq, long long csq) {
         if (asq == bsq || asq == csq || bsq == csq) {
    return "isosceles";
  }
  else {
    return "scalene";
  }
}

variable_types:
asq
long long

variable_types:
bsq
long long

variable_types:
csq
long long


decompiled_code:
const char *__fastcall angle_from_squares(__int64 a1, __int64 a2, __int64 a3)
{
const char *result; // rax
__int64 v4; // rdx

result = "obtuse";
v4 = a3 - a1 - a2;
if ( v4 <= 0 )
{
result = "right";
if ( v4 )
result = "acute";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func9(__int64 a1, __int64 a2, __int64 a3)
{
const char *result; // rax
__int64 v4; // rdx

result = "obtuse";
v4 = a3 - a1 - a2;
if ( v4 <= 0 )
{
result = "right";
if ( v4 )
result = "acute";
}
return result;
}

original_code:
const char *angle_from_squares(long long asq, long long bsq, long long csq) {
  long long diff = csq - asq - bsq;
  if (diff > 0) {
    return "obtuse";
  }
  else if (diff == 0) {
    return "right";
  }
  else {
    return "acute";
  }
}

variable_types:
diff
long long


main

original_code:
int main (int argc, char **argv) {
  long long pts[6];
  long long l1sq, l2sq, l3sq;
  int i;
  if (argc < 7) {
    printf("Please enter three integral points in first quadrant of the xy-plane.\n");
    return 0;
  }
  for (i = 0; i < 6; i++) {
    if (sscanf(argv[i+1], "%lld", &pts[i]) != 1) {
      printf("input error\n");
      return 0;
    }
  }
  for (i = 0; i < 6; i++) {
    ((void) sizeof ((pts[i] < 2147483648ll) ? 1 : 0), __extension__ ({ if (pts[i] < 2147483648ll) ; else __assert_fail ("pts[i] < 2147483648ll", "triangle.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((-1ll < pts[i]) ? 1 : 0), __extension__ ({ if (-1ll < pts[i]) ; else __assert_fail ("-1ll < pts[i]", "triangle.c", 40, __extension__ __PRETTY_FUNCTION__); }));
  }
  pts[4] = pts[4] - pts[0];
  pts[5] = pts[5] - pts[1];
  pts[2] = pts[2] - pts[0];
  pts[3] = pts[3] - pts[1];
  pts[0] = pts[4] - pts[2];
  pts[1] = pts[5] - pts[3];
  if (pts[2] * pts[5] == pts[4] * pts[3]) {
    printf("not a triangle\n");
    return 0;
  }
  l1sq = length_squared(pts[0], pts[1]);
  l2sq = length_squared(pts[2], pts[3]);
  l3sq = length_squared(pts[4], pts[5]);
  printf("%s ", side_type_squares(l1sq, l2sq, l3sq));
  if (l1sq >= l2sq && l1sq >= l3sq) {
    printf("%s\n", angle_from_squares(l2sq, l3sq, l1sq));
  }
  else if (l2sq >= l1sq && l2sq >= l3sq) {
    printf("%s\n", angle_from_squares(l1sq, l3sq, l2sq));
  }
  else {
    printf("%s\n", angle_from_squares(l1sq, l2sq, l3sq));
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  long long pts[6];
  long long l1sq; long long l2sq; long long l3sq;
  int i;
  if (argc < 7) {
    printf("Please enter three integral points in first quadrant of the xy-plane.\n");
    return 0;
  }
  for (i = 0; i < 6; i++) {
    if (sscanf(argv[i+1], "%lld", &pts[i]) != 1) {
      printf("input error\n");
      return 0;
    }
  }
  for (i = 0; i < 6; i++) {
    ((void) sizeof ((pts[i] < 2147483648ll) ? 1 : 0), __extension__ ({ if (pts[i] < 2147483648ll) ; else __assert_fail ("pts[i] < 2147483648ll", "triangle.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((-1ll < pts[i]) ? 1 : 0), __extension__ ({ if (-1ll < pts[i]) ; else __assert_fail ("-1ll < pts[i]", "triangle.c", 40, __extension__ __PRETTY_FUNCTION__); }));
  }
  pts[4] = pts[4] - pts[0];
  pts[5] = pts[5] - pts[1];
  pts[2] = pts[2] - pts[0];
  pts[3] = pts[3] - pts[1];
  pts[0] = pts[4] - pts[2];
  pts[1] = pts[5] - pts[3];
  if (pts[2] * pts[5] == pts[4] * pts[3]) {
    printf("not a triangle\n");
    return 0;
  }
  l1sq = length_squared(pts[0], pts[1]);
  l2sq = length_squared(pts[2], pts[3]);
  l3sq = length_squared(pts[4], pts[5]);
  printf("%s ", side_type_squares(l1sq, l2sq, l3sq));
  if (l1sq >= l2sq && l1sq >= l3sq) {
    printf("%s\n", angle_from_squares(l2sq, l3sq, l1sq));
  }
  else if (l2sq >= l1sq && l2sq >= l3sq) {
    printf("%s\n", angle_from_squares(l1sq, l3sq, l2sq));
  }
  else {
    printf("%s\n", angle_from_squares(l1sq, l2sq, l3sq));
  }
  return 0;
}

variable_types:
argv
char **

variable_types:
pts
long long [6]

variable_types: i int


decompiled_code:
unsigned __int64 __fastcall get_sq_len(int a1, int a2, int a3, int a4)
{
return (unsigned int)(int)((double)(a4 - a2) * (double)(a4 - a2))
+ (unsigned __int64)(unsigned int)(int)((double)(a3 - a1) * (double)(a3 - a1));
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(int a1, int a2, int a3, int a4)
{
return (unsigned int)(int)((double)(a4 - a2) * (double)(a4 - a2))
+ (unsigned __int64)(unsigned int)(int)((double)(a3 - a1) * (double)(a3 - a1));
}

original_code:
long long get_sq_len (struct point p1, struct point p2)
{
 long long part1, part2, sum;
 part1 = pow((p2.x - p1.x), 2ll);
 part2 = pow((p2.y - p1.y), 2ll);
 sum = part1 + part2;
 return sum;
}

canonical_original_code:
long long get_sq_len(struct point p1, struct point p2)
{
 long long part1; long long part2; long long sum;
 part1 = pow((p2.x - p1.x), 2ll);
 part2 = pow((p2.y - p1.y), 2ll);
 sum = part1 + part2;
 return sum;
}

variable_types: struct point { long long x; long long y; }

variable_types:
sum
long long


decompiled_code:
__int64 __fastcall get_length(int a1, int a2, int a3, int a4)
{
double v4; // xmm0_8
double v5; // xmm0_8

v4 = (double)(int)get_sq_len(a1, a2, a3, a4);
if ( v4 < 0.0 )
v5 = sqrt(v4);
else
v5 = sqrt(v4);
return (unsigned int)(int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, int a3, int a4)
{
double v4; // xmm0_8
double v5; // xmm0_8

v4 = (double)(int)func7(a1, a2, a3, a4);
if ( v4 < 0.0 )
v5 = sqrt(v4);
else
v5 = sqrt(v4);
return (unsigned int)(int)v5;
}

original_code:
long long get_length (struct point p1, struct point p2)
{
 return sqrt(get_sq_len(p1, p2));
}

canonical_original_code:
long long get_length(struct point p1, struct point p2)
{
 return sqrt(get_sq_len(p1, p2));
}


original_code:
int is_iso (long long len1, long long len2, long long len3)
{
 return (len1 == len2 || len1 == len3 || len2 == len3);
}

canonical_original_code:
int is_iso(long long len1, long long len2, long long len3)
{
 return (len1 == len2 || len1 == len3 || len2 == len3);
}


decompiled_code:
__int64 __fastcall new_point(const char *a1, const char *a2)
{
double v3; // [rsp+8h] [rbp-10h]

v3 = atof(a1);
atof(a2);
return (unsigned int)(int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1, const char *a2)
{
double v3; // [rsp+8h] [rbp-10h]

v3 = atof(a1);
atof(a2);
return (unsigned int)(int)v3;
}

original_code:
struct point new_point (char * num1, char * num2)
{
 struct point current;
 current.x = atof(num1);
 current.y = atof(num2);
 return current;
}

canonical_original_code:
struct point new_point(char *num1, char *num2)
{
 struct point current;
 current.x = atof(num1);
 current.y = atof(num2);
 return current;
}

return_type: struct point { long long x; long long y; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rbp
__int64 v5; // rdx
__int64 v6; // r15
__int64 v7; // rdx
__int64 v8; // r14
__int64 v9; // r12
__int64 v10; // rdx
__int64 v11; // r13
__int64 v12; // rbx
__int64 v14; // [rsp+8h] [rbp-80h]
__int64 v15; // [rsp+10h] [rbp-78h]
double v16; // [rsp+18h] [rbp-70h]
double v17; // [rsp+30h] [rbp-58h]
__int64 v18; // [rsp+38h] [rbp-50h]
double v19; // [rsp+48h] [rbp-40h]

v4 = new_point(argv[1], argv[2], envp);
v15 = v5;
v6 = new_point(argv[3], argv[4], v5);
v8 = v7;
v9 = new_point(argv[5], argv[6], v7);
v11 = v10;
v14 = get_length(v4, v15, v6, v8);
v12 = get_length(v6, v8, v9, v11);
v18 = get_length(v4, v15, v9, v11);
v19 = get_angle((double)(int)v18, (double)(int)v12, (double)(int)v14);
v17 = get_angle((double)(int)v14, (double)(int)v18, (double)(int)v12);
v16 = get_angle((double)(int)v14, (double)(int)v12, (double)(int)v18);
if ( (unsigned int)is_nat(v4, v15, v6, v8, v9, v11) )
{
puts("not a triangle");
}
else
{
if ( (unsigned int)is_iso(v14, v12, v18) )
printf("isosceles ");
else
printf("scalene ");
if ( (unsigned int)is_right(v4, v15, v6, v8, v9, v11) )
{
puts("right");
}
else if ( (unsigned int)is_acute(v19, v16, v17) )
{
puts("acute");
}
else
{
puts("obtuse");
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rbp
__int64 v5; // rdx
__int64 v6; // r15
__int64 v7; // rdx
__int64 v8; // r14
__int64 v9; // r12
__int64 v10; // rdx
__int64 v11; // r13
__int64 v12; // rbx
__int64 v14; // [rsp+8h] [rbp-80h]
__int64 v15; // [rsp+10h] [rbp-78h]
double v16; // [rsp+18h] [rbp-70h]
double v17; // [rsp+30h] [rbp-58h]
__int64 v18; // [rsp+38h] [rbp-50h]
double v19; // [rsp+48h] [rbp-40h]

v4 = func14(argv[1], argv[2], envp);
v15 = v5;
v6 = func14(argv[3], argv[4], v5);
v8 = v7;
v9 = func14(argv[5], argv[6], v7);
v11 = v10;
v14 = func8(v4, v15, v6, v8);
v12 = func8(v6, v8, v9, v11);
v18 = func8(v4, v15, v9, v11);
v19 = func9((double)(int)v18, (double)(int)v12, (double)(int)v14);
v17 = func9((double)(int)v14, (double)(int)v18, (double)(int)v12);
v16 = func9((double)(int)v14, (double)(int)v12, (double)(int)v18);
if ( (unsigned int)func10(v4, v15, v6, v8, v9, v11) )
{
puts("not a triangle");
}
else
{
if ( (unsigned int)func13(v14, v12, v18) )
printf("isosceles ");
else
printf("scalene ");
if ( (unsigned int)func11(v4, v15, v6, v8, v9, v11) )
{
puts("right");
}
else if ( (unsigned int)func12(v19, v16, v17) )
{
puts("acute");
}
else
{
puts("obtuse");
}
}
return 0;
}

original_code:
int main (int argc, char * argv[])
{
 long long len_p1_p2, len_p2_p3, len_p1_p3;
 double ang_p1_p2, ang_p2_p3, ang_p1_p3;
 struct point p1, p2, p3;
 p1 = new_point(argv[1], argv[2]);
 p2 = new_point(argv[3], argv[4]);
 p3 = new_point(argv[5], argv[6]);
 len_p1_p2 = get_length(p1, p2);
 len_p2_p3 = get_length(p2, p3);
 len_p1_p3 = get_length(p1, p3);
 ang_p1_p2 = get_angle(len_p1_p3, len_p2_p3, len_p1_p2);
 ang_p2_p3 = get_angle(len_p1_p2, len_p1_p3, len_p2_p3);
 ang_p1_p3 = get_angle(len_p1_p2, len_p2_p3, len_p1_p3);
 if (is_nat(p1, p2, p3)) {
  printf("not a triangle\n");
  return 0;
 }
 if (is_iso(len_p1_p2, len_p2_p3, len_p1_p3)) {
  printf("isosceles ");
 } else {
  printf("scalene ");
 }
 if (is_right(p1, p2, p3)) {
  printf("right\n");
 } else if (is_acute(ang_p1_p2, ang_p1_p3, ang_p2_p3)) {
  printf("acute\n");
 } else {
  printf("obtuse\n");
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 long long len_p1_p2; long long len_p2_p3; long long len_p1_p3;
 double ang_p1_p2; double ang_p2_p3; double ang_p1_p3;
 struct point p1; struct point p2; struct point p3;
 p1 = new_point(argv[1], argv[2]);
 p2 = new_point(argv[3], argv[4]);
 p3 = new_point(argv[5], argv[6]);
 len_p1_p2 = get_length(p1, p2);
 len_p2_p3 = get_length(p2, p3);
 len_p1_p3 = get_length(p1, p3);
 ang_p1_p2 = get_angle(len_p1_p3, len_p2_p3, len_p1_p2);
 ang_p2_p3 = get_angle(len_p1_p2, len_p1_p3, len_p2_p3);
 ang_p1_p3 = get_angle(len_p1_p2, len_p2_p3, len_p1_p3);
 if (is_nat(p1, p2, p3)) {
  printf("not a triangle\n");
  return 0;
 }
 if (is_iso(len_p1_p2, len_p2_p3, len_p1_p3)) {
  printf("isosceles ");
 } else {
  printf("scalene ");
 }
 if (is_right(p1, p2, p3)) {
  printf("right\n");
 } else if (is_acute(ang_p1_p2, ang_p1_p3, ang_p2_p3)) {
  printf("acute\n");
 } else {
  printf("obtuse\n");
 }
 return 0;
}

variable_types: argc int


decompiled_code:
void __fastcall get_angle(double a1, double a2, double a3)
{
acos((a1 * a1 + a2 * a2 - a3 * a3) / ((a1 + a1) * a2));
}

canonical_decompiled_code:
void __fastcall func9(double a1, double a2, double a3)
{
acos((a1 * a1 + a2 * a2 - a3 * a3) / ((a1 + a1) * a2));
}

original_code:
double get_angle (double len_a, double len_b, double len_c)
{
 double asq, bsq, csq, num, den, product;
 asq = pow(len_a, 2.0);
 bsq = pow(len_b, 2.0);
 csq = pow(len_c, 2.0);
 num = asq + bsq - csq;
 den = 2.0 * len_a * len_b;
 product = num / den;
 return acos(product);
}

canonical_original_code:
double get_angle(double len_a, double len_b, double len_c)
{
 double asq; double bsq; double csq; double num; double den; double product;
 asq = pow(len_a, 2.0);
 bsq = pow(len_b, 2.0);
 csq = pow(len_c, 2.0);
 num = asq + bsq - csq;
 den = 2.0 * len_a * len_b;
 product = num / den;
 return acos(product);
}

variable_types: asq double

variable_types: bsq double

variable_types: csq double

variable_types: num double

variable_types: den double

variable_types: product double

return_type: double


original_code:
int is_nat (struct point p1, struct point p2, struct point p3)
{
 long long result1, result2, result3;
 result1 = (p1.x * (p2.y - p3.y));
 result2 = (p2.x * (p3.y - p1.y));
 result3 = (p3.x * (p1.y - p2.y));
 return ((result1 + result2 + result3) == 0);
}

canonical_original_code:
int is_nat(struct point p1, struct point p2, struct point p3)
{
 long long result1; long long result2; long long result3;
 result1 = (p1.x * (p2.y - p3.y));
 result2 = (p2.x * (p3.y - p1.y));
 result3 = (p3.x * (p1.y - p2.y));
 return ((result1 + result2 + result3) == 0);
}


original_code:
int is_right (struct point p1, struct point p2, struct point p3)
{
 int result1, result2, result3;
 result1 = (get_sq_len(p1, p2) + get_sq_len(p2, p3) == get_sq_len(p1, p3));
 result2 = (get_sq_len(p2, p3) + get_sq_len(p1, p3) == get_sq_len(p1, p2));
 result3 = (get_sq_len(p1, p2) + get_sq_len(p1, p3) == get_sq_len(p2, p3));
 return (result1 || result2 || result3);
}

canonical_original_code:
int is_right(struct point p1, struct point p2, struct point p3)
{
 int result1; int result2; int result3;
 result1 = (get_sq_len(p1, p2) + get_sq_len(p2, p3) == get_sq_len(p1, p3));
 result2 = (get_sq_len(p2, p3) + get_sq_len(p1, p3) == get_sq_len(p1, p2));
 result3 = (get_sq_len(p1, p2) + get_sq_len(p1, p3) == get_sq_len(p2, p3));
 return (result1 || result2 || result3);
}


decompiled_code:
_BOOL8 __fastcall is_acute(double a1, double a2, double a3)
{
_BOOL8 result; // rax

if ( a1 >= 1.57079633 || a2 >= 1.57079633 )
result = 0LL;
else
result = a3 < 1.57079633;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(double a1, double a2, double a3)
{
_BOOL8 result; // rax

if ( a1 >= 1.57079633 || a2 >= 1.57079633 )
result = 0LL;
else
result = a3 < 1.57079633;
return result;
}


decompiled_code:
bool __fastcall IS_BYTE(__int16 a1)
{
return (unsigned __int16)(a1 + 256) <= 0xFFu;
}

canonical_decompiled_code:
bool __fastcall func0(__int16 a1)
{
return (unsigned __int16)(a1 + 256) <= 0xFFu;
}

original_code:
static _Bool IS_BYTE(short path) {
    return path >= -256 && path <= -1;
}

variable_types: path short


decompiled_code:
__int64 __fastcall BYTE_INDEX(int a1)
{
return (unsigned int)~a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned int)~a1;
}

original_code:
static short BYTE_INDEX(short path) {
    return -(path + 1);
}

return_type: short


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

result = a1;
if ( (unsigned __int8)a2 <= (unsigned __int8)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (unsigned __int8)a2 <= (unsigned __int8)a1 )
result = a2;
return result;
}

original_code:
static uint8_t MIN_UINT8(uint8_t a, uint8_t b) {
    return a < b ? a : b;
}

canonical_original_code:
static unsigned char MIN_UINT8(unsigned char a, unsigned char b) {
    return a < b ? a : b;
}

variable_types:
a
unsigned char

variable_types:
b
unsigned char

return_type: unsigned char


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

result = 1LL;
if ( *(_QWORD *)a1 <= *(_QWORD *)a2 )
{
if ( *(_QWORD *)a1 < *(_QWORD *)a2 )
result = 0xFFFFFFFFLL;
else
result = *((unsigned __int8 *)a1 + 10) - (unsigned int)*((unsigned __int8 *)a2 + 10);
}
return result;
}

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

result = 1LL;
if ( *(_QWORD *)a1 <= *(_QWORD *)a2 )
{
if ( *(_QWORD *)a1 < *(_QWORD *)a2 )
result = 0xFFFFFFFFLL;
else
result = *((unsigned __int8 *)a1 + 10) - (unsigned int)*((unsigned __int8 *)a2 + 10);
}
return result;
}

original_code:
static int compare_prioritized_nodes(const void *a, const void *b) {
    struct prioritized_node *node_a = (struct prioritized_node *) a;
    struct prioritized_node *node_b = (struct prioritized_node *) b;
    if (node_a->priority > node_b->priority)
        return 1;
    else if (node_a->priority < node_b->priority)
        return -1;
    else
        return (int)node_a->smallest_byte - (int)node_b->smallest_byte;
}

canonical_original_code:
static int compare_prioritized_nodes(void *a, void *b) {
    struct prioritized_node *node_a = (struct prioritized_node *) a;
    struct prioritized_node *node_b = (struct prioritized_node *) b;
    if (node_a->priority > node_b->priority)
        return 1;
    else if (node_a->priority < node_b->priority)
        return -1;
    else
        return (int)node_a->smallest_byte - (int)node_b->smallest_byte;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct prioritized_node { unsigned long priority; short node; unsigned char smallest_byte; } *


decompiled_code:
char *__fastcall fill_table(void *src, __int16 a2, __int64 a3, __int64 a4)
{
size_t v5; // rbx
void *v6; // rsp
size_t v7; // rbx
void *v8; // rsp
char *result; // rax
__int64 v10; // rdx
char **v11; // rbx
char *v12; // rax
char v13[8]; // [rsp+0h] [rbp-40h] BYREF
char *v14; // [rsp+8h] [rbp-38h]

if ( IS_BYTE(a2) )
{
strlen((const char *)src);
v11 = (char **)(a4 + 8LL * (__int16)BYTE_INDEX(a2));
v12 = (char *)xmalloc(v10 + 1);
*v11 = v12;
result = strcpy(v12, (const char *)src);
}
else
{
v14 = v13;
v5 = strlen((const char *)src);
v6 = alloca(v5 + 2);
memcpy(v13, src, v5 + 1);
v13[v5] = 48;
v13[v5 + 1] = 0;
fill_table(v13);
v7 = strlen((const char *)src);
v8 = alloca(v7 + 2);
memcpy(v13, src, v7 + 1);
v13[v7] = 49;
v13[v7 + 1] = 0;
result = (char *)fill_table(v13);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(void *src, __int16 a2, __int64 a3, __int64 a4)
{
size_t v5; // rbx
void *v6; // rsp
size_t v7; // rbx
void *v8; // rsp
char *result; // rax
__int64 v10; // rdx
char **v11; // rbx
char *v12; // rax
char v13[8]; // [rsp+0h] [rbp-40h] BYREF
char *v14; // [rsp+8h] [rbp-38h]

if ( func0(a2) )
{
strlen((const char *)src);
v11 = (char **)(a4 + 8LL * (__int16)func1(a2));
v12 = (char *)xmalloc(v10 + 1);
*v11 = v12;
result = strcpy(v12, (const char *)src);
}
else
{
v14 = v13;
v5 = strlen((const char *)src);
v6 = alloca(v5 + 2);
memcpy(v13, src, v5 + 1);
v13[v5] = 48;
v13[v5 + 1] = 0;
func4(v13);
v7 = strlen((const char *)src);
v8 = alloca(v7 + 2);
memcpy(v13, src, v7 + 1);
v13[v7] = 49;
v13[v7 + 1] = 0;
result = (char *)func4(v13);
}
return result;
}

original_code:
static void fill_table(const char *code, short node, const struct tree *tree,
        char *out_table[256]) {
    ((void) (0));
    ((void) (0));
    if (IS_BYTE(node)) {
        out_table[BYTE_INDEX(node)] = xmalloc((strlen(code) + 1));
        strcpy(out_table[BYTE_INDEX(node)], code);
        return;
    }
    for (short i = 0; i < 2; i++) {
        size_t code_length = strlen(code);
        char new_code[code_length + 2];
        strcpy(new_code, code);
        new_code[code_length] = (char)i + '0';
        new_code[code_length + 1] = 0;
        short path = tree->nodes[node].paths[i];
        ((void) (0));
        ((void) (0));
        fill_table(new_code, path, tree, out_table);
    }
}

canonical_original_code:
static void fill_table(char *code, short node, struct tree *tree, char *out_table[256]) {
    ((void) (0));
    ((void) (0));
    if (IS_BYTE(node)) {
        out_table[BYTE_INDEX(node)] = xmalloc((strlen(code) + 1));
        strcpy(out_table[BYTE_INDEX(node)], code);
        return;
    }
    for (short i = 0; i < 2; i++) {
        unsigned long code_length = strlen(code);
        char new_code[-1];
        strcpy(new_code, code);
        new_code[code_length] = (char)i + '0';
        new_code[code_length + 1] = 0;
        short path = tree->nodes[node].paths[i];
        ((void) (0));
        ((void) (0));
        fill_table(new_code, path, tree, out_table);
    }
}

variable_types:
code
char *

variable_types: node short

variable_types: struct tree { struct node { short paths[2]; } nodes[255]; } *

variable_types: i short

user_defined_types:
struct tree { struct node nodes[255]; }
struct node { short paths[2]; }


original_code:
void huff_make_table(const uint64_t freq[256], char *out_table[256]) {
    struct prioritized_node node_list[256];
    for (short i = 0; i < 256; i++) {
        node_list[i] = (struct prioritized_node) {
            .priority = freq[i],
            .node = BYTE_INDEX(i),
            .smallest_byte = (uint8_t)i };
    }
    struct tree tree;
    for (short i = 0; i < 255; i++) {
        qsort(node_list + (unsigned short)i, 256 - (unsigned short)i,
                sizeof(struct prioritized_node), compare_prioritized_nodes);
        short huff_index = 254 - i;
        tree.nodes[huff_index] = (struct node) {
            .paths = {
                node_list[i].node,
                node_list[i + 1].node } };
        node_list[i + 1] = (struct prioritized_node) {
            .priority = node_list[i].priority + node_list[i + 1].priority,
            .node = huff_index,
            .smallest_byte = MIN_UINT8(node_list[i].smallest_byte,
                    node_list[i + 1].smallest_byte) };
    }
    ((void) (0));
    fill_table("", 0, &tree, out_table);
    ((void) (0));
}

canonical_original_code:
void huff_make_table(unsigned long freq[256], char *out_table[256]) {
    struct prioritized_node node_list[256];
    for (short i = 0; i < 256; i++) {
        node_list[i] = (struct prioritized_node) {
            .priority = freq[i],
            .node = BYTE_INDEX(i),
            .smallest_byte = (unsigned char)i };
    }
    struct tree tree;
    for (short i = 0; i < 255; i++) {
        qsort(node_list + (unsigned short)i, 256 - (unsigned short)i,
                sizeof(struct prioritized_node), compare_prioritized_nodes);
        short huff_index = 254 - i;
        tree.nodes[huff_index] = (struct node) {
            .paths = {
                node_list[i].node,
                node_list[i + 1].node } };
        node_list[i + 1] = (struct prioritized_node) {
            .priority = node_list[i].priority + node_list[i + 1].priority,
            .node = huff_index,
            .smallest_byte = MIN_UINT8(node_list[i].smallest_byte,
                    node_list[i + 1].smallest_byte) };
    }
    ((void) (0));
    fill_table("", 0, &tree, out_table);
    ((void) (0));
}

variable_types:
freq
unsigned long [256]

variable_types: struct prioritized_node { unsigned long priority; short node; unsigned char smallest_byte; } [256]

variable_types: struct tree { struct node { short paths[2]; } nodes[255]; }


original_code:
void huff_make_decoder(struct huff_decoder *decoder,
                       const char * const table[256]) {
    ((void) (0));
    memset(decoder, 0, sizeof(struct huff_decoder));
    short next_empty = 1;
    for (short i = 0; i < 256; i++) {
        short current_node = 0;
        for (short j = 0; ; j++) {
            ((void) (0));
            short direction = table[i][j] - '0';
            short *path = &decoder->tree.nodes[current_node].paths[direction];
            if (table[i][j + 1] == 0) {
                ((void) (0));
                *path = BYTE_INDEX(i);
                break;
            }
            if (*path == 0) {
                ((void) (0));
                *path = next_empty;
                next_empty++;
            }
            current_node = *path;
        }
    }
    ((void) (0));
}

canonical_original_code:
void huff_make_decoder(struct huff_decoder *decoder, char *table[256]) {
    ((void) (0));
    memset(decoder, 0, sizeof(struct huff_decoder));
    short next_empty = 1;
    for (short i = 0; i < 256; i++) {
        short current_node = 0;
        for (short j = 0; ; j++) {
            ((void) (0));
            short direction = table[i][j] - '0';
            short *path = &decoder->tree.nodes[current_node].paths[direction];
            if (table[i][j + 1] == 0) {
                ((void) (0));
                *path = BYTE_INDEX(i);
                break;
            }
            if (*path == 0) {
                ((void) (0));
                *path = next_empty;
                next_empty++;
            }
            current_node = *path;
        }
    }
    ((void) (0));
}

variable_types: struct huff_decoder { struct tree { struct node { short paths[2]; } nodes[255]; } tree; short current_node; } *

variable_types:
table
char *[256]

variable_types: j short

variable_types: direction short

variable_types:
path
short *

user_defined_types: struct huff_decoder { struct tree tree; short current_node; }


decompiled_code:
int __fastcall huff_decode(int a1, __int64 a2)
{
int v2; // er8
__int16 v3; // dx
int result; // eax

if ( IS_BYTE(*(_WORD *)(a2 + 2 * (a1 + 2LL * *(__int16 *)(a2 + 1020)))) )
{
LOWORD(result) = BYTE_INDEX(v2);
*(_WORD *)(a2 + 1020) = v3;
result = (__int16)result;
}
else
{
*(_WORD *)(a2 + 1020) = v2;
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1, __int64 a2)
{
int v2; // er8
__int16 v3; // dx
int result; // eax

if ( func0(*(_WORD *)(a2 + 2 * (a1 + 2LL * *(__int16 *)(a2 + 1020)))) )
{
LOWORD(result) = func1(v2);
*(_WORD *)(a2 + 1020) = v3;
result = (__int16)result;
}
else
{
*(_WORD *)(a2 + 1020) = v2;
result = -1;
}
return result;
}

original_code:
int huff_decode(int bit, struct huff_decoder *decoder) {
    ((void) (0));
    ((void) (0));
    decoder->current_node =
        decoder->tree.nodes[decoder->current_node].paths[bit];
    if (IS_BYTE(decoder->current_node)) {
        int result = BYTE_INDEX(decoder->current_node);
        decoder->current_node = 0;
        return result;
    }
    return -1;
}

variable_types: bit int

variable_types: result int


decompiled_code:
__int64 __fastcall compare_nodes(const void *a1, const void *a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
unsigned __int64 v4; // rax
__int64 result; // rax
unsigned __int8 v6; // cl

v2 = *(_QWORD *)a1;
if ( !*(_QWORD *)a1 )
return 1LL;
v3 = *(_QWORD *)a2;
if ( !*(_QWORD *)a2 )
return 0xFFFFFFFFLL;
v4 = *(_QWORD *)(v3 + 280);
if ( *(_QWORD *)(v2 + 280) != v4 )
return *(_QWORD *)(v2 + 280) < v4 ? -1 : 1;
v6 = *(_BYTE *)(v3 + 290);
result = 0xFFFFFFFFLL;
if ( *(_BYTE *)(v2 + 290) >= v6 )
result = *(_BYTE *)(v2 + 290) != v6;
return result;
}

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

v2 = *(_QWORD *)a1;
if ( !*(_QWORD *)a1 )
return 1LL;
v3 = *(_QWORD *)a2;
if ( !*(_QWORD *)a2 )
return 0xFFFFFFFFLL;
v4 = *(_QWORD *)(v3 + 280);
if ( *(_QWORD *)(v2 + 280) != v4 )
return *(_QWORD *)(v2 + 280) < v4 ? -1 : 1;
v6 = *(_BYTE *)(v3 + 290);
result = 0xFFFFFFFFLL;
if ( *(_BYTE *)(v2 + 290) >= v6 )
result = *(_BYTE *)(v2 + 290) != v6;
return result;
}

original_code:
int compare_nodes(const void* node1, const void* node2)
{
    node **n1 = (node**)node1;
    node **n2 = (node**)node2;
    if (*n1 == ((void *)0))
        return 1;
    if (*n2 == ((void *)0))
        return -1;
    if ((*n1)->freq == (*n2)->freq)
        return (*n1)->lowest < (*n2)->lowest ? -1 : (*n1)->lowest == (*n2)->lowest ? 0 : 1;
    return (*n1)->freq < (*n2)->freq ? -1 : (*n1)->freq == (*n2)->freq ? 0 : 1;
}

canonical_original_code:
int compare_nodes(void *node1, void *node2)
{
    struct node **n1 = (node**)node1;
    struct node **n2 = (node**)node2;
    if (*n1 == ((void *)0))
        return 1;
    if (*n2 == ((void *)0))
        return -1;
    if ((*n1)->freq == (*n2)->freq)
        return (*n1)->lowest < (*n2)->lowest ? -1 : (*n1)->lowest == (*n2)->lowest ? 0 : 1;
    return (*n1)->freq < (*n2)->freq ? -1 : (*n1)->freq == (*n2)->freq ? 0 : 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:
__int64 __fastcall get_code(unsigned __int8 a1)
{
return table[a1];
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
return table[a1];
}

original_code:
char * get_code(char c)
{
    return table[(uint8_t)c];
}

canonical_original_code:
char *get_code(char c)
{
    return table[(unsigned char)c];
}

variable_types: c char


decompiled_code:
__int64 init_nodes()
{
__int64 *v0; // rbp
int v1; // ebx
__int64 v2; // rsi
__int64 *v3; // rdi
__int64 result; // rax

v0 = &nodes;
v1 = 0;
do
{
v2 = (unsigned int)(char)v1;
v3 = v0;
++v1;
++v0;
init_node(v3, v2);
result = all_node_curr++;
all_nodes[result] = *(v0 - 1);
}
while ( v1 != 256 );
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 *v0; // rbp
int v1; // ebx
__int64 v2; // rsi
__int64 *v3; // rdi
__int64 result; // rax

v0 = &nodes;
v1 = 0;
do
{
v2 = (unsigned int)(char)v1;
v3 = v0;
++v1;
++v0;
init_node(v3, v2);
result = all_node_curr++;
all_nodes[result] = *(v0 - 1);
}
while ( v1 != 256 );
return result;
}

original_code:
void init_nodes()
{
    for (int i = 0; i < 256; i++)
    {
        init_node(&nodes[i], i);
        all_nodes[all_node_curr++] = nodes[i];
    }
}

variable_types: i int


decompiled_code:
__int64 __fastcall byte_freq(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx

for ( result = 0LL; result != 256; ++result )
{
v2 = *(_QWORD *)(a1 + result * 8);
v3 = nodes[result];
*(_QWORD *)(v3 + 280) = v2;
}
return result * 8;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx

for ( result = 0LL; result != 256; ++result )
{
v2 = *(_QWORD *)(a1 + result * 8);
v3 = nodes[result];
*(_QWORD *)(v3 + 280) = v2;
}
return result * 8;
}

original_code:
void byte_freq(uint64_t freq[256])
{
    for (int i = 0; i < 256; i++)
        nodes[i]->freq = freq[i];
}

canonical_original_code:
void byte_freq(unsigned long freq[256])
{
    for (int i = 0; i < 256; i++)
        nodes[i]->freq = freq[i];
}


decompiled_code:
void sort_nodes()
{
qsort(nodes, 0x100uLL, 8uLL, (__compar_fn_t)compare_nodes);
}

canonical_decompiled_code:
void func4()
{
qsort(nodes, 0x100uLL, 8uLL, (__compar_fn_t)compare_nodes);
}

original_code:
void sort_nodes()
{
    qsort(nodes, 256, sizeof(node*), compare_nodes);
}

canonical_original_code:
void sort_nodes()
{
    qsort(nodes, 256, sizeof(struct node *), compare_nodes);
}

user_defined_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:
__int64 __fastcall check_build(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 || !a2 )
_assert_fail("node0 != NULL && node1 != NULL", "compress.c", 0x47u, "check_build");
if ( *(_QWORD *)(a1 + 280) > *(_QWORD *)(a2 + 280) )
_assert_fail("node0->freq <= node1->freq", "compress.c", 0x48u, "check_build");
result = ((__int64 (*)(void))is_leaf)();
if ( (_BYTE)result )
{
result = is_leaf(a2);
if ( (_BYTE)result )
{
result = *(unsigned __int8 *)(a2 + 289);
if ( *(_BYTE *)(a1 + 289) == (_BYTE)result )
_assert_fail("node0->c != node1->c", "compress.c", 0x4Au, "check_build");
}
}
return result;
}

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

if ( !a1 || !a2 )
_assert_fail("node0 != NULL && node1 != NULL", "compress.c", 0x47u, "check_build");
if ( *(_QWORD *)(a1 + 280) > *(_QWORD *)(a2 + 280) )
_assert_fail("node0->freq <= node1->freq", "compress.c", 0x48u, "check_build");
result = ((__int64 (*)(void))is_leaf)();
if ( (_BYTE)result )
{
result = is_leaf(a2);
if ( (_BYTE)result )
{
result = *(unsigned __int8 *)(a2 + 289);
if ( *(_BYTE *)(a1 + 289) == (_BYTE)result )
_assert_fail("node0->c != node1->c", "compress.c", 0x4Au, "check_build");
}
}
return result;
}

original_code:
void check_build(node *node0, node *node1)
{
    ((node0 != ((void *)0) && node1 != ((void *)0)) ? (void) (0) : __assert_fail ("node0 != NULL && node1 != NULL", "compress.c", 71, __extension__ __PRETTY_FUNCTION__));
    ((node0->freq <= node1->freq) ? (void) (0) : __assert_fail ("node0->freq <= node1->freq", "compress.c", 72, __extension__ __PRETTY_FUNCTION__));
    if (is_leaf(node0) && is_leaf(node1))
        ((node0->c != node1->c) ? (void) (0) : __assert_fail ("node0->c != node1->c", "compress.c", 74, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void check_build(struct node *node0, struct node *node1)
{
    ((node0 != ((void *)0) && node1 != ((void *)0)) ? (void) (0) : __assert_fail ("node0 != NULL && node1 != NULL", "compress.c", 71, __extension__ __PRETTY_FUNCTION__));
    ((node0->freq <= node1->freq) ? (void) (0) : __assert_fail ("node0->freq <= node1->freq", "compress.c", 72, __extension__ __PRETTY_FUNCTION__));
    if (is_leaf(node0) && is_leaf(node1))
        ((node0->c != node1->c) ? (void) (0) : __assert_fail ("node0->c != node1->c", "compress.c", 74, __extension__ __PRETTY_FUNCTION__));
}

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 build_tree_frq()
{
int v0; // er12
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rax
unsigned __int8 v4; // cl
unsigned __int8 v5; // dl
int v6; // edx
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = 255;
do
{
v1 = nodes[0];
v2 = qword_1CE8;
check_build(nodes[0], qword_1CE8);
nodes[0] = 0LL;
qword_1CE8 = 0LL;
v7[0] = 0LL;
init_node(v7, 0LL);
v3 = v7[0];
*(_QWORD *)(v7[0] + 280) = *(_QWORD *)(v1 + 280) + *(_QWORD *)(v2 + 280);
v4 = *(_BYTE *)(v1 + 290);
v5 = *(_BYTE *)(v2 + 290);
*(_QWORD *)(v3 + 264) = v1;
*(_QWORD *)(v3 + 272) = v2;
nodes[0] = v3;
if ( v5 > v4 )
v5 = v4;
*(_BYTE *)(v3 + 290) = v5;
v6 = all_node_curr;
all_nodes[all_node_curr] = v3;
all_node_curr = v6 + 1;
sort_nodes();
--v0;
}
while ( v0 );
if ( !nodes[0] )
_assert_fail("nodes[0] != NULL", "compress.c", 0x6Au, "build_tree_frq");
}

original_code:
void build_tree_frq()
{
    for (int i = 0; i < 255; i++)
    {
        node* node0 = nodes[0];
        node* node1 = nodes[1];
        check_build(node0, node1);
        nodes[0] = ((void *)0);
        nodes[1] = ((void *)0);
        node* new_node = ((void *)0);
        init_node(&new_node, 0);
        new_node->freq = node0->freq + node1->freq;
        new_node->lowest = node0->lowest < node1->lowest ? node0->lowest : node0->lowest == node1->lowest ? node1->lowest : node1->lowest;
        new_node->left = node0;
        new_node->right = node1;
        nodes[0] = new_node;
        all_nodes[all_node_curr++] = new_node;
        sort_nodes();
    }
    ((nodes[0] != ((void *)0)) ? (void) (0) : __assert_fail ("nodes[0] != NULL", "compress.c", 106, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void build_tree_frq()
{
    for (int i = 0; i < 255; i++)
    {
        struct node *node0 = nodes[0];
        struct node *node1 = nodes[1];
        check_build(node0, node1);
        nodes[0] = ((void *)0);
        nodes[1] = ((void *)0);
        struct node *new_node = ((void *)0);
        init_node(&new_node, 0);
        new_node->freq = node0->freq + node1->freq;
        new_node->lowest = node0->lowest < node1->lowest ? node0->lowest : node0->lowest == node1->lowest ? node1->lowest : node1->lowest;
        new_node->left = node0;
        new_node->right = node1;
        nodes[0] = new_node;
        all_nodes[all_node_curr++] = new_node;
        sort_nodes();
    }
    ((nodes[0] != ((void *)0)) ? (void) (0) : __assert_fail ("nodes[0] != NULL", "compress.c", 106, __extension__ __PRETTY_FUNCTION__));
}


decompiled_code:
__int64 *clear_visited()
{
__int64 *result; // rax

result = all_nodes;
do
{
if ( *result )
*(_BYTE *)(*result + 288) = 0;
++result;
}
while ( result != &all_nodes[511] );
return result;
}

canonical_decompiled_code:
__int64 *func7()
{
__int64 *result; // rax

result = all_nodes;
do
{
if ( *result )
*(_BYTE *)(*result + 288) = 0;
++result;
}
while ( result != &all_nodes[511] );
return result;
}

original_code:
void clear_visited()
{
    for (int i = 0; i < 511; i++)
        if (all_nodes[i] != ((void *)0))
            all_nodes[i]->visited = 0;
}


dfs

decompiled_code:
__int64 __fastcall dfs(__int64 a1)
{
char *v2; // rdi
char *v3; // rdi
__int64 result; // rax
char *v5; // rbp
char *v6; // rbp

if ( !a1 )
_assert_fail("root", "compress.c", 0x77u, "dfs");
*(_BYTE *)(a1 + 288) = 1;
v2 = *(char **)(a1 + 264);
if ( v2 && !v2[288] )
{
v5 = strcat(v2, (const char *)a1);
*(_WORD *)&v5[strlen(v5)] = 48;
if ( *(_QWORD *)(a1 + 280) < *(_QWORD *)(*(_QWORD *)(a1 + 264) + 280LL) )
_assert_fail("root->freq >= root->left->freq", "compress.c", 0x7Eu, "dfs");
dfs();
}
v3 = *(char **)(a1 + 272);
if ( v3 && !v3[288] )
{
v6 = strcat(v3, (const char *)a1);
*(_WORD *)&v6[strlen(v6)] = 49;
if ( *(_QWORD *)(a1 + 280) < *(_QWORD *)(*(_QWORD *)(a1 + 272) + 280LL) )
_assert_fail("root->freq >= root->right->freq", "compress.c", 0x87u, "dfs");
dfs();
}
result = is_leaf(a1);
if ( (_BYTE)result )
{
result = *(unsigned __int8 *)(a1 + 289);
table[result] = a1;
}
else if ( *(_BYTE *)(a1 + 289) )
{
_assert_fail("root->c == 0", "compress.c", 0x8Eu, "dfs");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
char *v2; // rdi
char *v3; // rdi
__int64 result; // rax
char *v5; // rbp
char *v6; // rbp

if ( !a1 )
_assert_fail("root", "compress.c", 0x77u, "dfs");
*(_BYTE *)(a1 + 288) = 1;
v2 = *(char **)(a1 + 264);
if ( v2 && !v2[288] )
{
v5 = strcat(v2, (const char *)a1);
*(_WORD *)&v5[strlen(v5)] = 48;
if ( *(_QWORD *)(a1 + 280) < *(_QWORD *)(*(_QWORD *)(a1 + 264) + 280LL) )
_assert_fail("root->freq >= root->left->freq", "compress.c", 0x7Eu, "dfs");
func8();
}
v3 = *(char **)(a1 + 272);
if ( v3 && !v3[288] )
{
v6 = strcat(v3, (const char *)a1);
*(_WORD *)&v6[strlen(v6)] = 49;
if ( *(_QWORD *)(a1 + 280) < *(_QWORD *)(*(_QWORD *)(a1 + 272) + 280LL) )
_assert_fail("root->freq >= root->right->freq", "compress.c", 0x87u, "dfs");
func8();
}
result = is_leaf(a1);
if ( (_BYTE)result )
{
result = *(unsigned __int8 *)(a1 + 289);
table[result] = a1;
}
else if ( *(_BYTE *)(a1 + 289) )
{
_assert_fail("root->c == 0", "compress.c", 0x8Eu, "dfs");
}
return result;
}

original_code:
void dfs(node *root)
{
    ((root) ? (void) (0) : __assert_fail ("root", "compress.c", 119, __extension__ __PRETTY_FUNCTION__));
    root->visited = 1;
    if (root->left != ((void *)0))
    {
        if (root->left->visited == 0)
        {
            strcat(strcat(root->left->code, root->code), "0");
            ((root->freq >= root->left->freq) ? (void) (0) : __assert_fail ("root->freq >= root->left->freq", "compress.c", 126, __extension__ __PRETTY_FUNCTION__));
            dfs(root->left);
        }
    }
    if (root->right != ((void *)0))
    {
        if (root->right->visited == 0)
        {
            strcat(strcat(root->right->code, root->code), "1");
            ((root->freq >= root->right->freq) ? (void) (0) : __assert_fail ("root->freq >= root->right->freq", "compress.c", 135, __extension__ __PRETTY_FUNCTION__));
            dfs(root->right);
        }
    }
    if(is_leaf(root))
        table[root->c] = root->code;
    else
        ((root->c == 0) ? (void) (0) : __assert_fail ("root->c == 0", "compress.c", 142, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void dfs(struct node *root)
{
    ((root) ? (void) (0) : __assert_fail ("root", "compress.c", 119, __extension__ __PRETTY_FUNCTION__));
    root->visited = 1;
    if (root->left != ((void *)0))
    {
        if (root->left->visited == 0)
        {
            strcat(strcat(root->left->code, root->code), "0");
            ((root->freq >= root->left->freq) ? (void) (0) : __assert_fail ("root->freq >= root->left->freq", "compress.c", 126, __extension__ __PRETTY_FUNCTION__));
            dfs(root->left);
        }
    }
    if (root->right != ((void *)0))
    {
        if (root->right->visited == 0)
        {
            strcat(strcat(root->right->code, root->code), "1");
            ((root->freq >= root->right->freq) ? (void) (0) : __assert_fail ("root->freq >= root->right->freq", "compress.c", 135, __extension__ __PRETTY_FUNCTION__));
            dfs(root->right);
        }
    }
    if(is_leaf(root))
        table[root->c] = root->code;
    else
        ((root->c == 0) ? (void) (0) : __assert_fail ("root->c == 0", "compress.c", 142, __extension__ __PRETTY_FUNCTION__));
}


decompiled_code:
__int64 create_table()
{
clear_visited();
return dfs(nodes[0]);
}

canonical_decompiled_code:
__int64 func9()
{
func7();
return func8(nodes[0]);
}

original_code:
void create_table()
{
    clear_visited();
    dfs(*nodes);
}


decompiled_code:
__int64 __fastcall gen_tree_frq(__int64 a1)
{
init_nodes();
byte_freq(a1);
sort_nodes();
build_tree_frq();
return create_table();
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
func2();
func3(a1);
func4();
func6();
return func9();
}

original_code:
void gen_tree_frq(uint64_t freq[256])
{
    init_nodes();
    byte_freq(freq);
    sort_nodes();
    build_tree_frq();
    create_table();
}

canonical_original_code:
void gen_tree_frq(unsigned long freq[256])
{
    init_nodes();
    byte_freq(freq);
    sort_nodes();
    build_tree_frq();
    create_table();
}


createDecodeTreeFromResultArray

decompiled_code:
size_t __fastcall createDecodeTreeFromResultArray(const char **a1, char *a2)
{
int v2; // er13
int v3; // er12
char *v4; // rbp
size_t v5; // rbx
const char *v6; // r15
char *v7; // rax
size_t result; // rax
__int64 v9; // rax
__int64 v10; // rax
bool v11; // zf

v2 = 0;
v3 = 1;
memset(a2, 0, 0x4FD8uLL);
do
{
v4 = a2;
v5 = 0LL;
v6 = *a1;
while ( 1 )
{
result = strlen(v6);
if ( v5 >= result )
break;
if ( v6[v5] == 48 )
{
v7 = (char *)*((_QWORD *)v4 + 3);
if ( !v7 )
{
v9 = v3++;
v7 = &a2[40 * v9];
*((_QWORD *)v4 + 3) = v7;
}
}
else
{
v7 = (char *)*((_QWORD *)v4 + 4);
if ( !v7 )
{
v10 = v3++;
v7 = &a2[40 * v10];
*((_QWORD *)v4 + 4) = v7;
}
}
*((_QWORD *)v7 + 2) = v4;
++v5;
v4 = v7;
}
v11 = *((_QWORD *)v4 + 3) == 0LL;
*((_DWORD *)v4 + 2) = v2;
if ( !v11 || *((_QWORD *)v4 + 4) )
_assert_fail(
"currentNode->leftLeaf == NULL && currentNode->rightLeaf == NULL",
"decoder.c",
0x40u,
"createDecodeTreeFromResultArray");
++v2;
a1 += 2;
}
while ( v2 != 256 );
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(const char **a1, char *a2)
{
int v2; // er13
int v3; // er12
char *v4; // rbp
size_t v5; // rbx
const char *v6; // r15
char *v7; // rax
size_t result; // rax
__int64 v9; // rax
__int64 v10; // rax
bool v11; // zf

v2 = 0;
v3 = 1;
memset(a2, 0, 0x4FD8uLL);
do
{
v4 = a2;
v5 = 0LL;
v6 = *a1;
while ( 1 )
{
result = strlen(v6);
if ( v5 >= result )
break;
if ( v6[v5] == 48 )
{
v7 = (char *)*((_QWORD *)v4 + 3);
if ( !v7 )
{
v9 = v3++;
v7 = &a2[40 * v9];
*((_QWORD *)v4 + 3) = v7;
}
}
else
{
v7 = (char *)*((_QWORD *)v4 + 4);
if ( !v7 )
{
v10 = v3++;
v7 = &a2[40 * v10];
*((_QWORD *)v4 + 4) = v7;
}
}
*((_QWORD *)v7 + 2) = v4;
++v5;
v4 = v7;
}
v11 = *((_QWORD *)v4 + 3) == 0LL;
*((_DWORD *)v4 + 2) = v2;
if ( !v11 || *((_QWORD *)v4 + 4) )
_assert_fail(
"currentNode->leftLeaf == NULL && currentNode->rightLeaf == NULL",
"decoder.c",
0x40u,
"createDecodeTreeFromResultArray");
++v2;
a1 += 2;
}
while ( v2 != 256 );
return result;
}

original_code:
void createDecodeTreeFromResultArray(huffResult *resultArray, huffNode out[511])
{
    memset(out, 0, sizeof(huffNode) * 511);
    huffNode *rootNode = out;
    int nextFreeNode = 1;
    for(int i = 0; i < 256; i++)
    {
        huffResult *currentResult = &resultArray[i];
        char * valueString = currentResult->string;
        huffNode *currentNode = rootNode;
        for(int j = 0; (unsigned)j < strlen(valueString); j++)
        {
            if (valueString[j] == '0')
            {
                if(currentNode->leftLeaf == ((void *)0))
                {
                    currentNode->leftLeaf = &out[nextFreeNode];
                    nextFreeNode++;
                }
                huffNode *parentNode = currentNode;
                currentNode = currentNode->leftLeaf;
                currentNode->parent = parentNode;
            }
            else
            {
                if(currentNode->rightLeaf == ((void *)0))
                {
                    currentNode->rightLeaf = &out[nextFreeNode];
                    nextFreeNode++;
                }
                huffNode *parentNode = currentNode;
                currentNode = currentNode->rightLeaf;
                currentNode->parent = parentNode;
            }
        }
        currentNode->byte = i;
        ((currentNode->leftLeaf == ((void *)0) && currentNode->rightLeaf == ((void *)0)) ? (void) (0) : __assert_fail ("currentNode->leftLeaf == NULL && currentNode->rightLeaf == NULL", "decoder.c", 64, __extension__ __PRETTY_FUNCTION__));
    }
}

canonical_original_code:
void createDecodeTreeFromResultArray(struct huffResult *resultArray, struct huffNode out[511])
{
    memset(out, 0, sizeof(huffNode) * 511);
    struct huffNode *rootNode = out;
    int nextFreeNode = 1;
    for(int i = 0; i < 256; i++)
    {
        struct huffResult *currentResult = &resultArray[i];
        char *valueString = currentResult->string;
        struct huffNode *currentNode = rootNode;
        for(int j = 0; (unsigned int)j < strlen(valueString); j++)
        {
            if (valueString[j] == '0')
            {
                if(currentNode->leftLeaf == ((void *)0))
                {
                    currentNode->leftLeaf = &out[nextFreeNode];
                    nextFreeNode++;
                }
                struct huffNode *parentNode = currentNode;
                currentNode = currentNode->leftLeaf;
                currentNode->parent = parentNode;
            }
            else
            {
                if(currentNode->rightLeaf == ((void *)0))
                {
                    currentNode->rightLeaf = &out[nextFreeNode];
                    nextFreeNode++;
                }
                struct huffNode *parentNode = currentNode;
                currentNode = currentNode->rightLeaf;
                currentNode->parent = parentNode;
            }
        }
        currentNode->byte = i;
        ((currentNode->leftLeaf == ((void *)0) && currentNode->rightLeaf == ((void *)0)) ? (void) (0) : __assert_fail ("currentNode->leftLeaf == NULL && currentNode->rightLeaf == NULL", "decoder.c", 64, __extension__ __PRETTY_FUNCTION__));
    }
}

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

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

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

variable_types: nextFreeNode int

variable_types:
valueString
char *

variable_types: j int


createHuffResultArrayFromFileEncodings

decompiled_code:
int __fastcall createHuffResultArrayFromFileEncodings(__int64 a1, void **a2)
{
int v2; // er14
void **v3; // r13
void **v4; // r12
int v5; // esi
__int64 i; // rax
__int64 v7; // rdx
int v8; // ebp
void **v9; // rax
int v10; // eax
void *v11; // rax
size_t n; // [rsp+8h] [rbp-40h]

v2 = 0;
v3 = a2;
v4 = a2;
v5 = 0;
do
{
*((_DWORD *)v3 + 2) = v2;
*v3 = &unk_387;
for ( i = v5; ; ++i )
{
v7 = (unsigned int)*(char *)(a1 + i);
v8 = i;
if ( *(_BYTE *)(a1 + i) == 10 )
break;
if ( (unsigned __int8)(v7 - 48) > 1u )
{
LODWORD(v9) = fprintf(stderr, "Invalid character found in encoding: %c\n", v7);
return (int)v9;
}
}
if ( (int)i > v5 )
{
v10 = i - v5;
n = v10;
v11 = calloc(v10 + 1, v10);
if ( !v11 )
_assert_fail("value", "decoder.c", 0x9Bu, "createHuffResultArrayFromFileEncodings");
*v3 = memcpy(v11, (const void *)(a1 + v5), n);
}
++v2;
v5 = v8 + 1;
v3 += 2;
}
while ( v2 != 256 );
v9 = v4 + 512;
do
{
if ( !*v4 )
_assert_fail("currentResult->string", "decoder.c", 0xA8u, "createHuffResultArrayFromFileEncodings");
v4 += 2;
}
while ( v9 != v4 );
return (int)v9;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, void **a2)
{
int v2; // er14
void **v3; // r13
void **v4; // r12
int v5; // esi
__int64 i; // rax
__int64 v7; // rdx
int v8; // ebp
void **v9; // rax
int v10; // eax
void *v11; // rax
size_t n; // [rsp+8h] [rbp-40h]

v2 = 0;
v3 = a2;
v4 = a2;
v5 = 0;
do
{
*((_DWORD *)v3 + 2) = v2;
*v3 = &unk_387;
for ( i = v5; ; ++i )
{
v7 = (unsigned int)*(char *)(a1 + i);
v8 = i;
if ( *(_BYTE *)(a1 + i) == 10 )
break;
if ( (unsigned __int8)(v7 - 48) > 1u )
{
LODWORD(v9) = fprintf(stderr, "Invalid character found in encoding: %c\n", v7);
return (int)v9;
}
}
if ( (int)i > v5 )
{
v10 = i - v5;
n = v10;
v11 = calloc(v10 + 1, v10);
if ( !v11 )
_assert_fail("value", "decoder.c", 0x9Bu, "createHuffResultArrayFromFileEncodings");
*v3 = memcpy(v11, (const void *)(a1 + v5), n);
}
++v2;
v5 = v8 + 1;
v3 += 2;
}
while ( v2 != 256 );
v9 = v4 + 512;
do
{
if ( !*v4 )
_assert_fail("currentResult->string", "decoder.c", 0xA8u, "createHuffResultArrayFromFileEncodings");
v4 += 2;
}
while ( v9 != v4 );
return (int)v9;
}

original_code:
void createHuffResultArrayFromFileEncodings(
    char encodings[32768], huffResult resultArray[256])
{
    int stringIndex = 0;
    for(int i = 0; i < 256; i++)
    {
        huffResult * currentResult = &resultArray[i];
        currentResult->value = i;
        currentResult->string = "";
        int currentStartIndex = stringIndex;
        while (encodings[stringIndex] != '\n')
        {
            char testChar = encodings[stringIndex++];
            if(!(testChar == '0' || testChar == '1'))
            {
                fprintf(stderr, "Invalid character found in encoding: %c\n",
                    testChar);
                return;
            }
        }
        if(currentStartIndex< stringIndex)
        {
            int length = stringIndex - currentStartIndex;
            char * value = calloc(length+1,sizeof(char) * length);
            ((value) ? (void) (0) : __assert_fail ("value", "decoder.c", 155, __extension__ __PRETTY_FUNCTION__));
            memcpy(value, &encodings[currentStartIndex], length);
            currentResult->string = value;
        }
        stringIndex++;
    }
    for(int i = 0; i < 256; i++)
    {
        huffResult * currentResult = &resultArray[i];
        ((currentResult->string) ? (void) (0) : __assert_fail ("currentResult->string", "decoder.c", 168, __extension__ __PRETTY_FUNCTION__));
    }
}

canonical_original_code:
void createHuffResultArrayFromFileEncodings(char encodings[32768], struct huffResult resultArray[256])
{
    int stringIndex = 0;
    for(int i = 0; i < 256; i++)
    {
        struct huffResult *currentResult = &resultArray[i];
        currentResult->value = i;
        currentResult->string = "";
        int currentStartIndex = stringIndex;
        while (encodings[stringIndex] != '\n')
        {
            char testChar = encodings[stringIndex++];
            if(!(testChar == '0' || testChar == '1'))
            {
                fprintf(stderr, "Invalid character found in encoding: %c\n",
                    testChar);
                return;
            }
        }
        if(currentStartIndex< stringIndex)
        {
            int length = stringIndex - currentStartIndex;
            char *value = calloc(length+1,sizeof(char) * length);
            ((value) ? (void) (0) : __assert_fail ("value", "decoder.c", 155, __extension__ __PRETTY_FUNCTION__));
            memcpy(value, &encodings[currentStartIndex], length);
            currentResult->string = value;
        }
        stringIndex++;
    }
    for(int i = 0; i < 256; i++)
    {
        struct huffResult *currentResult = &resultArray[i];
        ((currentResult->string) ? (void) (0) : __assert_fail ("currentResult->string", "decoder.c", 168, __extension__ __PRETTY_FUNCTION__));
    }
}

variable_types:
encodings
char [32768]

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

variable_types: stringIndex int

variable_types: currentStartIndex int

variable_types: testChar char

variable_types: length int

variable_types:
value
char *


decompiled_code:
__int64 __fastcall to_array(int *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 result; // rax

v2 = 7LL;
do
{
result = (*a1 >> v2) & 1;
*(_DWORD *)(a2 + 4 * v2) = result;
}
while ( v2-- != 0 );
return result;
}

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

v2 = 7LL;
do
{
result = (*a1 >> v2) & 1;
*(_DWORD *)(a2 + 4 * v2) = result;
}
while ( v2-- != 0 );
return result;
}

original_code:
static void to_array(int *curr_char, int *bit_array)
{
  int i;
  for (i = 7; i >= 0; i--)
    {
      bit_array[i] = ((*curr_char) >> i) & 0x1;
    }
}


decompiled_code:
void __fastcall __noreturn unix_error(const char *a1)
{
puts(a1);
exit(255);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
puts(a1);
exit(255);
}

original_code:
static void unix_error(char *msg)
{
    printf("%s\n", msg);
    exit(255);
}

variable_types:
msg
char *