decompiled_code:
__int64 jlib_qt_total()
{
return (unsigned int)num_of_qt;
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned int)num_of_qt;
}

original_code:
int jlib_qt_total(void)
{
 return num_of_qt;
}

canonical_original_code:
int jlib_qt_total()
{
 return num_of_qt;
}


repo: smirkant/JPEGdfs

decompiled_code:
__int64 __fastcall jlib_get_ht(__int64 a1, unsigned int a2)
{
return jh_get_table(a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
return jh_get_table(a2);
}

original_code:
struct jh_table *jlib_get_ht(enum component_id c_id, int type)
{
 int no = 0;
 if (c_id == COMPONENT_Y)
  no = 0;
 else
  no = 1;
 return jh_get_table(type, no);
}

variable_types: enum component_id { COMPONENT_Y=1, COMPONENT_Cb=2, COMPONENT_Cr=3, COMPONENT_I=4, COMPONENT_Q=5 }

variable_types: type int

variable_types: no int

return_type: struct jh_table { int no; int type; int num_of_symbol; struct jh_symbol { unsigned int length; unsigned char bits[2]; unsigned char code; } symbol[256]; } *

user_defined_types: struct jh_table { int no; int type; int num_of_symbol; struct jh_symbol symbol[256]; }


decompiled_code:
int *__fastcall jlib_get_qt_from_index(int a1)
{
int *result; // rax

if ( a1 < 0 )
return 0LL;
result = 0LL;
if ( num_of_qt > a1 )
result = &q_table[130 * a1];
return result;
}

canonical_decompiled_code:
int *__fastcall func8(int a1)
{
int *result; // rax

if ( a1 < 0 )
return 0LL;
result = 0LL;
if ( num_of_qt > a1 )
result = &q_table[130 * a1];
return result;
}

original_code:
struct quantization_table *jlib_get_qt_from_index(int index)
{
 if ((index >= 0) && (index < num_of_qt))
  return &q_table[index];
 else
  return ((void *)0);
}

variable_types: index int

return_type: struct quantization_table { int no; int precision; int table[128]; } *


decompiled_code:
int *__fastcall jlib_get_qt(int a1)
{
int *v1; // rdx
int v2; // eax

if ( num_of_qt <= 0 )
return 0LL;
v1 = q_table;
v2 = 0;
while ( *v1 != a1 )
{
++v2;
v1 += 130;
if ( v2 == num_of_qt )
return 0LL;
}
return &q_table[130 * v2];
}

canonical_decompiled_code:
int *__fastcall func9(int a1)
{
int *v1; // rdx
int v2; // eax

if ( num_of_qt <= 0 )
return 0LL;
v1 = q_table;
v2 = 0;
while ( *v1 != a1 )
{
++v2;
v1 += 130;
if ( v2 == num_of_qt )
return 0LL;
}
return &q_table[130 * v2];
}

original_code:
struct quantization_table *jlib_get_qt(int no)
{
 int i;
 for (i = 0; i < num_of_qt; i++) {
  if (q_table[i].no == no)
   return &q_table[i];
 }
 return ((void *)0);
}

variable_types: i int

user_defined_types: struct quantization_table { int no; int precision; int table[128]; }


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

*a1 = _mm_load_si128((const __m128i *)&sos_info);
a1[1] = _mm_load_si128((const __m128i *)&xmmword_ED0);
a1[2] = _mm_load_si128((const __m128i *)&xmmword_EE0);
result = (unsigned int)dword_EF0;
a1[3].m128i_i32[0] = dword_EF0;
return result;
}

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

*a1 = _mm_load_si128((const __m128i *)&sos_info);
a1[1] = _mm_load_si128((const __m128i *)&xmmword_ED0);
a1[2] = _mm_load_si128((const __m128i *)&xmmword_EE0);
result = (unsigned int)dword_EF0;
a1[3].m128i_i32[0] = dword_EF0;
return result;
}

original_code:
void jlib_get_sos_info(struct jscan *info)
{
 memcpy(info, &sos_info, sizeof(struct jscan));
}

variable_types: struct jscan { int num_of_component; struct { enum component_id { COMPONENT_Y=1, COMPONENT_Cb=2, COMPONENT_Cr=3, COMPONENT_I=4, COMPONENT_Q=5 } id; int AC_ht_no; int DC_ht_no; } component[4]; } *

return_type: void

user_defined_types: struct jscan { int num_of_component; struct { enum component_id id; int AC_ht_no; int DC_ht_no; } component[4]; }


decompiled_code:
__int64 jlib_frame0_height()
{
return DWORD1(frame_sof0);
}

canonical_decompiled_code:
__int64 func11()
{
return DWORD1(frame_sof0);
}

original_code:
int jlib_frame0_height(void)
{
 return frame_sof0.height;
}

canonical_original_code:
int jlib_frame0_height()
{
 return frame_sof0.height;
}

return_type: int


decompiled_code:
__int64 jlib_frame0_width()
{
return DWORD2(frame_sof0);
}

canonical_decompiled_code:
__int64 func12()
{
return DWORD2(frame_sof0);
}

original_code:
int jlib_frame0_width(void)
{
 return frame_sof0.width;
}

canonical_original_code:
int jlib_frame0_width()
{
 return frame_sof0.width;
}


decompiled_code:
__int64 jlib_frame0_component_total()
{
return HIDWORD(frame_sof0);
}

canonical_decompiled_code:
__int64 func13()
{
return HIDWORD(frame_sof0);
}

original_code:
int jlib_frame0_component_total(void)
{
 return frame_sof0.num_of_component;
}

canonical_original_code:
int jlib_frame0_component_total()
{
 return frame_sof0.num_of_component;
}


decompiled_code:
void __fastcall jlib_get_frame0_info(__m128i *a1)
{
*a1 = _mm_load_si128((const __m128i *)&frame_sof0);
a1[1] = _mm_load_si128((const __m128i *)xmmword_F10);
a1[2] = _mm_load_si128((const __m128i *)&xmmword_F20);
a1[3] = _mm_load_si128((const __m128i *)&xmmword_F30);
a1[4] = _mm_load_si128((const __m128i *)&xmmword_F40);
}

original_code:
void jlib_get_frame0_info(struct jframe *frame0)
{
 memcpy(frame0, &frame_sof0, sizeof(struct jframe));
}

variable_types: struct jframe { int bpp; int height; int width; int num_of_component; struct { enum component_id { COMPONENT_Y=1, COMPONENT_Cb=2, COMPONENT_Cr=3, COMPONENT_I=4, COMPONENT_Q=5 } id; int v_factor; int h_factor; int qt_no; } component[4]; } *

user_defined_types: struct jframe { int bpp; int height; int width; int num_of_component; struct { enum component_id id; int v_factor; int h_factor; int qt_no; } component[4]; }


original_code:
void jlib_init(void)
{
 int pos, i, j, k, num;
 int index;
 struct jf_SOF0 sof0;
 struct jf_SOS sos;
 struct jf_DQT dqt;
 pos = jf_marker_pos(0xc0, 0);
 jf_get_sof0(&sof0, pos);
 frame_sof0.bpp = sof0.bpp;
 frame_sof0.height = sof0.image_h;
 frame_sof0.width = sof0.image_w;
 frame_sof0.num_of_component = sof0.num_of_component;
 for (i = 0; i < frame_sof0.num_of_component; i++) {
  frame_sof0.component[i].id = sof0.component[i].id;
  frame_sof0.component[i].v_factor = sof0.component[i].v_factor;
  frame_sof0.component[i].h_factor = sof0.component[i].h_factor;
  frame_sof0.component[i].qt_no = sof0.component[i].qt_no;
 }
 pos = jf_marker_pos(0xda, 0);
 jf_get_sos(&sos, pos);
 sos_info.num_of_component = sos.num_of_color_component;
 for (i = 0; i < sos_info.num_of_component; i++) {
  sos_info.component[i].id = sos.component[i].id;
  sos_info.component[i].AC_ht_no = sos.component[i].ac_table;
  sos_info.component[i].DC_ht_no = sos.component[i].dc_table;
 }
 num_of_qt = 0;
 index = 0;
 num = jf_marker_count(0xdb);
 for (i = 0; i < num; i++) {
  pos = jf_marker_pos(0xdb, i);
  jf_get_dqt(&dqt, pos);
  num_of_qt = num_of_qt + dqt.num_of_qt;
  for (j = 0; j < dqt.num_of_qt; j++) {
   q_table[index].no = dqt.qt[j].no;
   q_table[index].precision = dqt.qt[j].precision;
   for (k = 0; k < 64; k++) {
    q_table[index].table[k] = (int)dqt.qt[j].table[zigzag_table[k]];
   }
   index = index + 1;
  }
 }
 if (index != num_of_qt) {
  printf("Extract quantization table failed!\n");
  exit(1);
 }
 init_component_info();
}

canonical_original_code:
void jlib_init()
{
 int pos; int i; int j; int k; int num;
 int index;
 struct jf_SOF0 sof0;
 struct jf_SOS sos;
 struct jf_DQT dqt;
 pos = jf_marker_pos(0xc0, 0);
 jf_get_sof0(&sof0, pos);
 frame_sof0.bpp = sof0.bpp;
 frame_sof0.height = sof0.image_h;
 frame_sof0.width = sof0.image_w;
 frame_sof0.num_of_component = sof0.num_of_component;
 for (i = 0; i < frame_sof0.num_of_component; i++) {
  frame_sof0.component[i].id = sof0.component[i].id;
  frame_sof0.component[i].v_factor = sof0.component[i].v_factor;
  frame_sof0.component[i].h_factor = sof0.component[i].h_factor;
  frame_sof0.component[i].qt_no = sof0.component[i].qt_no;
 }
 pos = jf_marker_pos(0xda, 0);
 jf_get_sos(&sos, pos);
 sos_info.num_of_component = sos.num_of_color_component;
 for (i = 0; i < sos_info.num_of_component; i++) {
  sos_info.component[i].id = sos.component[i].id;
  sos_info.component[i].AC_ht_no = sos.component[i].ac_table;
  sos_info.component[i].DC_ht_no = sos.component[i].dc_table;
 }
 num_of_qt = 0;
 index = 0;
 num = jf_marker_count(0xdb);
 for (i = 0; i < num; i++) {
  pos = jf_marker_pos(0xdb, i);
  jf_get_dqt(&dqt, pos);
  num_of_qt = num_of_qt + dqt.num_of_qt;
  for (j = 0; j < dqt.num_of_qt; j++) {
   q_table[index].no = dqt.qt[j].no;
   q_table[index].precision = dqt.qt[j].precision;
   for (k = 0; k < 64; k++) {
    q_table[index].table[k] = (int)dqt.qt[j].table[zigzag_table[k]];
   }
   index = index + 1;
  }
 }
 if (index != num_of_qt) {
  printf("Extract quantization table failed!\n");
  exit(1);
 }
 init_component_info();
}

variable_types: pos int

variable_types: j int

variable_types: k int

variable_types: num int

variable_types: struct jf_SOF0 { unsigned char id; unsigned int length; unsigned int bpp; unsigned int image_h; unsigned int image_w; unsigned int num_of_component; struct { unsigned int id; unsigned int v_factor; unsigned int h_factor; unsigned int qt_no; } component[4]; }

variable_types: struct jf_SOS { unsigned char id; unsigned int length; unsigned int num_of_color_component; struct { unsigned int id; unsigned int ac_table; unsigned int dc_table; } component[4]; }

variable_types: struct jf_DQT { unsigned char id; unsigned int length; unsigned int num_of_qt; struct { unsigned int no; unsigned int precision; unsigned char table[128]; } qt[4]; }


decompiled_code:
__int64 __fastcall dct_round(double a1)
{
double v1; // xmm0_8

if ( a1 < 0.0 )
v1 = a1 - 0.5;
else
v1 = a1 + 0.5;
return (unsigned int)(int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(double a1)
{
double v1; // xmm0_8

if ( a1 < 0.0 )
v1 = a1 - 0.5;
else
v1 = a1 + 0.5;
return (unsigned int)(int)v1;
}

original_code:
static int dct_round(double value)
{
 if (value >= 0.0)
  return (int)(value + 0.5);
 else
  return (int)(value - 0.5);
}

variable_types: value double


fzigzag

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

for ( result = 0LL; result != 64; ++result )
*(_DWORD *)(a2 + 4LL * zigzag_table[result]) = *(_DWORD *)(a1 + result * 4);
return result * 4;
}

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

for ( result = 0LL; result != 64; ++result )
*(_DWORD *)(a2 + 4LL * zigzag_table[result]) = *(_DWORD *)(a1 + result * 4);
return result * 4;
}

original_code:
extern void fzigzag(int *src, int *dest)
{
 int i;
 int *psrc = src, *pdest = dest;
 for (i = 0; i < 64; i++) {
  *(pdest + zigzag_table[i]) = *psrc++;
 }
}

canonical_original_code:
extern void fzigzag(int *src, int *dest)
{
 int i;
 int *psrc = src; int *pdest = dest;
 for (i = 0; i < 64; i++) {
  *(pdest + zigzag_table[i]) = *psrc++;
 }
}

variable_types:
src
int *

variable_types:
dest
int *

variable_types:
psrc
int *

variable_types:
pdest
int *


fdct

original_code:
extern void fdct(int *src, int *dest)
{
 int u, v, x, y, i, j;
 double alpha_u, alpha_v;
 double tmp, tmp1, tmp2;
 int *psrc, *pdest;
 pdest = dest;
 for (i = 0; i < 64; i++) {
  u = i % 8;
  v = i / 8;
  if (u == 0)
   alpha_u = sqrt(1.0 / 8.0);
  else
   alpha_u = sqrt(2.0 / 8.0);
  if (v == 0)
   alpha_v = sqrt(1.0 / 8.0);
  else
   alpha_v = sqrt(2.0 / 8.0);
  tmp = 0.0;
  psrc = src;
  for (j = 0; j < 64; j++) {
   x = j % 8;
   y = j / 8;
   tmp1 = ((2.0 * x + 1.0) * u * 3.1415926) / 16.0;
   tmp2 = ((2.0 * y + 1.0) * v * 3.1415926) / 16.0;
   tmp = tmp + (*psrc++) * cos(tmp1) * cos(tmp2);
  }
  *pdest++ = dct_round(alpha_u * alpha_v * tmp);
 }
}

canonical_original_code:
extern void fdct(int *src, int *dest)
{
 int u; int v; int x; int y; int i; int j;
 double alpha_u; double alpha_v;
 double tmp; double tmp1; double tmp2;
 int *psrc; int *pdest;
 pdest = dest;
 for (i = 0; i < 64; i++) {
  u = i % 8;
  v = i / 8;
  if (u == 0)
   alpha_u = sqrt(1.0 / 8.0);
  else
   alpha_u = sqrt(2.0 / 8.0);
  if (v == 0)
   alpha_v = sqrt(1.0 / 8.0);
  else
   alpha_v = sqrt(2.0 / 8.0);
  tmp = 0.0;
  psrc = src;
  for (j = 0; j < 64; j++) {
   x = j % 8;
   y = j / 8;
   tmp1 = ((2.0 * x + 1.0) * u * 3.1415926) / 16.0;
   tmp2 = ((2.0 * y + 1.0) * v * 3.1415926) / 16.0;
   tmp = tmp + (*psrc++) * cos(tmp1) * cos(tmp2);
  }
  *pdest++ = dct_round(alpha_u * alpha_v * tmp);
 }
}

variable_types: u int

variable_types: v int

variable_types: x int

variable_types: y int

variable_types: tmp double


idct

original_code:
extern void idct(int *src, int *dest)
{
 int u, v, x, y, i, j;
 double alpha_u, alpha_v;
 double tmp, tmp1, tmp2;
 int *psrc, *pdest;
 pdest = dest;
 for (i = 0; i < 64; i++) {
  x = i % 8;
  y = i / 8;
  tmp = 0.0;
  psrc = src;
  for (j = 0; j < 64; j++) {
   u = j % 8;
   v = j / 8;
   if (u == 0)
    alpha_u = sqrt(1.0 /8.0);
   else
    alpha_u = sqrt(2.0 / 8.0);
   if (v == 0)
    alpha_v = sqrt(1.0 / 8.0);
   else
    alpha_v = sqrt(2.0 / 8.0);
   tmp1 = ((2.0 * x + 1.0) * u * 3.1415926) / 16.0;
   tmp2 = ((2.0 * y + 1.0) * v * 3.1415926) / 16.0;
   tmp = tmp + alpha_u * alpha_v * (*psrc++) * cos(tmp1) * cos(tmp2);
  }
  *pdest++ = dct_round(tmp);
 }
}

canonical_original_code:
extern void idct(int *src, int *dest)
{
 int u; int v; int x; int y; int i; int j;
 double alpha_u; double alpha_v;
 double tmp; double tmp1; double tmp2;
 int *psrc; int *pdest;
 pdest = dest;
 for (i = 0; i < 64; i++) {
  x = i % 8;
  y = i / 8;
  tmp = 0.0;
  psrc = src;
  for (j = 0; j < 64; j++) {
   u = j % 8;
   v = j / 8;
   if (u == 0)
    alpha_u = sqrt(1.0 /8.0);
   else
    alpha_u = sqrt(2.0 / 8.0);
   if (v == 0)
    alpha_v = sqrt(1.0 / 8.0);
   else
    alpha_v = sqrt(2.0 / 8.0);
   tmp1 = ((2.0 * x + 1.0) * u * 3.1415926) / 16.0;
   tmp2 = ((2.0 * y + 1.0) * v * 3.1415926) / 16.0;
   tmp = tmp + alpha_u * alpha_v * (*psrc++) * cos(tmp1) * cos(tmp2);
  }
  *pdest++ = dct_round(tmp);
 }
}

variable_types: i int


original_code:
static int get_symbol(struct jh_symbol *symbol,
  unsigned char *table,
  unsigned char *symtable)
{
 int i = 0, j = 0, index = 0;
 int tmp[16];
 struct ht_node *p = ((void *)0);
 ht_chars_to_ints((char *)table, tmp, 16);
 ht_build_tree(tmp);
 for (i = 0; i < 17; i++) {
  p = ht_get_tree_row(i);
  while (p != ((void *)0)) {
   if (p->type == HT_BRANCH) {
    p = p->next;
    continue;
   }
   symbol[index].length = p->depth;
   symbol[index].code = symtable[index];
   for (j = 0; j < p->depth; j++) {
    if (p->bits[j] == GBIT_1)
     gb_set_1(symbol[index].bits, j);
    else
     gb_set_0(symbol[index].bits, j);
   }
   index = index + 1;
   p = p->next;
  }
 }
 ht_destroy_tree();
 return index;
}

canonical_original_code:
static int get_symbol(struct jh_symbol *symbol, unsigned char *table, unsigned char *symtable)
{
 int i = 0; int j = 0; int index = 0;
 int tmp[16];
 struct ht_node *p = ((void *)0);
 ht_chars_to_ints((char *)table, tmp, 16);
 ht_build_tree(tmp);
 for (i = 0; i < 17; i++) {
  p = ht_get_tree_row(i);
  while (p != ((void *)0)) {
   if (p->type == HT_BRANCH) {
    p = p->next;
    continue;
   }
   symbol[index].length = p->depth;
   symbol[index].code = symtable[index];
   for (j = 0; j < p->depth; j++) {
    if (p->bits[j] == GBIT_1)
     gb_set_1(symbol[index].bits, j);
    else
     gb_set_0(symbol[index].bits, j);
   }
   index = index + 1;
   p = p->next;
  }
 }
 ht_destroy_tree();
 return index;
}

variable_types: struct jh_symbol { unsigned int length; unsigned char bits[2]; unsigned char code; } *

variable_types:
table
unsigned char *

variable_types:
symtable
unsigned char *

variable_types: j int

variable_types: index int

variable_types:
tmp
int [16]

variable_types: struct ht_node { int depth; int code; enum gbit { GBIT_0=0, GBIT_1=1 } bits[16]; enum ht_type { HT_LEAF=0, HT_BRANCH=1 } type; struct ht_node *next; } *

user_defined_types: struct ht_node { int depth; int code; enum gbit bits[16]; enum ht_type type; struct ht_node *next; }


decompiled_code:
__int64 __fastcall jh_bits_to_value(__int64 a1, unsigned int a2, int a3)
{
unsigned int v4; // ebp
int v5; // ebx
__int64 result; // rax
unsigned int v7; // ebp
unsigned int v8; // er14
unsigned int v9; // ebx

if ( (unsigned int)((__int64 (*)(void))gb_get)() == 1 )
{
if ( a3 <= 0 )
{
v9 = 0;
}
else
{
v7 = a2;
v8 = a2 + a3;
v9 = 0;
do
v9 = gb_get(a1, v7++) | (2 * v9);
while ( v8 != v7 );
}
result = v9;
}
else
{
v4 = a2;
v5 = 0;
if ( a3 > 0 )
{
do
v5 = ((unsigned int)gb_get(a1, v4++) == 0) | (2 * v5);
while ( v4 != a3 + a2 );
}
result = (unsigned int)-v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, int a3)
{
unsigned int v4; // ebp
int v5; // ebx
__int64 result; // rax
unsigned int v7; // ebp
unsigned int v8; // er14
unsigned int v9; // ebx

if ( (unsigned int)((__int64 (*)(void))gb_get)() == 1 )
{
if ( a3 <= 0 )
{
v9 = 0;
}
else
{
v7 = a2;
v8 = a2 + a3;
v9 = 0;
do
v9 = gb_get(a1, v7++) | (2 * v9);
while ( v8 != v7 );
}
result = v9;
}
else
{
v4 = a2;
v5 = 0;
if ( a3 > 0 )
{
do
v5 = ((unsigned int)gb_get(a1, v4++) == 0) | (2 * v5);
while ( v4 != a3 + a2 );
}
result = (unsigned int)-v5;
}
return result;
}

original_code:
int jh_bits_to_value(unsigned char *bytes, int index, int n)
{
 unsigned int value = 0;
 int ret = 0;
 int i;
 enum gbit ggbit;
 if (gb_get(bytes, index) == GBIT_1) {
  for (i = 0; i < n; i++) {
   ggbit = gb_get(bytes, index + i);
   value = value << 1;
   value = value | ggbit;
  }
  ret = (int)value;
 } else {
  for (i = 0; i < n; i++) {
   ggbit = gb_get(bytes, index + i);
   value = value << 1;
   value = value | (! ggbit);
  }
  ret = 0 - (int)value;
 }
 return ret;
}

variable_types:
bytes
unsigned char *

variable_types: n int

variable_types:
value
unsigned int

variable_types: ret int

variable_types:
ggbit
enum gbit { GBIT_0=0, GBIT_1=1 }


decompiled_code:
char *__fastcall jh_get_table_from_index(int a1)
{
char *result; // rax

if ( a1 < 0 )
return 0LL;
result = 0LL;
if ( num_of_table > a1 )
result = (char *)&table + 2060 * a1;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(int a1)
{
char *result; // rax

if ( a1 < 0 )
return 0LL;
result = 0LL;
if ( num_of_table > a1 )
result = (char *)&table + 2060 * a1;
return result;
}

original_code:
struct jh_table *jh_get_table_from_index(int index)
{
 if ((index >= 0) && (index < num_of_table))
  return &table[index];
 else
  return ((void *)0);
}

user_defined_types: struct jh_symbol { unsigned int length; unsigned char bits[2]; unsigned char code; }


decompiled_code:
char *__fastcall jh_get_table(int a1, int a2)
{
_DWORD *v2; // rax
int v3; // edx

if ( num_of_table <= 0 )
return 0LL;
v2 = &table;
v3 = 0;
do
{
if ( v2[1] == a1 && *v2 == a2 )
return (char *)&table + 2060 * v3;
++v3;
v2 += 515;
}
while ( v3 != num_of_table );
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func3(int a1, int a2)
{
_DWORD *v2; // rax
int v3; // edx

if ( num_of_table <= 0 )
return 0LL;
v2 = &table;
v3 = 0;
do
{
if ( v2[1] == a1 && *v2 == a2 )
return (char *)&table + 2060 * v3;
++v3;
v2 += 515;
}
while ( v3 != num_of_table );
return 0LL;
}

original_code:
struct jh_table *jh_get_table(int type, int no)
{
 int i;
 for (i = 0; i < num_of_table; i++) {
  if ((table[i].type == type) && (table[i].no == no))
   return &table[i];
 }
 return ((void *)0);
}

variable_types: type int

variable_types: no int


decompiled_code:
__int64 jh_init()
{
__int64 result; // rax
int v1; // ebp
unsigned int i; // ebx
unsigned int v3; // eax
int v4; // er10
__int64 v5; // rcx
char *v6; // rdx
char *v7; // r9
_DWORD *v8; // rbp
char *v9; // rbx
int v10; // er13
char *v11; // rax
int v12; // edx
__int64 v13; // [rsp+0h] [rbp-D58h] BYREF
int v14; // [rsp+8h] [rbp-D50h]
char v15[1148]; // [rsp+Ch] [rbp-D4Ch] BYREF
char v16[2256]; // [rsp+488h] [rbp-8D0h] BYREF

result = jf_marker_count(196LL);
num_of_table = 0;
if ( (int)result > 0 )
{
v1 = result;
for ( i = 0; i != v1; ++i )
{
v3 = jf_marker_pos(196LL, i);
jf_get_dht(&v13, v3);
result = (unsigned int)num_of_table;
v4 = num_of_table + v14;
num_of_table += v14;
if ( v14 > 0 )
{
v5 = (int)result;
result = (__int64)&v15[280 * (int)result + 1124];
v6 = v15;
v7 = &v16[280 * (unsigned int)(v14 - 1) + 256 + 280 * v5];
do
{
*(_QWORD *)result = *(_QWORD *)v6;
*(_QWORD *)(result + 272) = *((_QWORD *)v6 + 34);
qmemcpy(
(void *)((result + 8) & 0xFFFFFFFFFFFFFFF8LL),
&v6[-(result - ((result + 8) & 0xFFFFFFFFFFFFFFF8LL))],
8LL * (((unsigned int)result - (((_DWORD)result + 8) & 0xFFFFFFF8) + 280) >> 3));
result += 280LL;
v6 += 280;
}
while ( (char *)result != v7 );
}
}
if ( v4 > 0 )
{
v8 = &unk_3AC;
v9 = v16;
v10 = 0;
do
{
*(v8 - 3) = *((_DWORD *)v9 - 6);
*(v8 - 2) = *((_DWORD *)v9 - 5);
v11 = v9 - 16;
v12 = 0;
do
v12 += (unsigned __int8)*v11++;
while ( v11 != v9 );
*(v8 - 1) = v12;
result = get_symbol((__int64)v8, (__int64)(v9 - 16), (__int64)v9);
if ( *(v8 - 1) != (_DWORD)result )
{
puts("Build binary tree FAILED!");
exit(1);
}
++v10;
v8 += 515;
v9 += 280;
}
while ( num_of_table > v10 );
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
int v1; // ebp
unsigned int i; // ebx
unsigned int v3; // eax
int v4; // er10
__int64 v5; // rcx
char *v6; // rdx
char *v7; // r9
_DWORD *v8; // rbp
char *v9; // rbx
int v10; // er13
char *v11; // rax
int v12; // edx
__int64 v13; // [rsp+0h] [rbp-D58h] BYREF
int v14; // [rsp+8h] [rbp-D50h]
char v15[1148]; // [rsp+Ch] [rbp-D4Ch] BYREF
char v16[2256]; // [rsp+488h] [rbp-8D0h] BYREF

result = jf_marker_count(196LL);
num_of_table = 0;
if ( (int)result > 0 )
{
v1 = result;
for ( i = 0; i != v1; ++i )
{
v3 = jf_marker_pos(196LL, i);
jf_get_dht(&v13, v3);
result = (unsigned int)num_of_table;
v4 = num_of_table + v14;
num_of_table += v14;
if ( v14 > 0 )
{
v5 = (int)result;
result = (__int64)&v15[280 * (int)result + 1124];
v6 = v15;
v7 = &v16[280 * (unsigned int)(v14 - 1) + 256 + 280 * v5];
do
{
*(_QWORD *)result = *(_QWORD *)v6;
*(_QWORD *)(result + 272) = *((_QWORD *)v6 + 34);
qmemcpy(
(void *)((result + 8) & 0xFFFFFFFFFFFFFFF8LL),
&v6[-(result - ((result + 8) & 0xFFFFFFFFFFFFFFF8LL))],
8LL * (((unsigned int)result - (((_DWORD)result + 8) & 0xFFFFFFF8) + 280) >> 3));
result += 280LL;
v6 += 280;
}
while ( (char *)result != v7 );
}
}
if ( v4 > 0 )
{
v8 = &unk_3AC;
v9 = v16;
v10 = 0;
do
{
*(v8 - 3) = *((_DWORD *)v9 - 6);
*(v8 - 2) = *((_DWORD *)v9 - 5);
v11 = v9 - 16;
v12 = 0;
do
v12 += (unsigned __int8)*v11++;
while ( v11 != v9 );
*(v8 - 1) = v12;
result = func0((__int64)v8, (__int64)(v9 - 16), (__int64)v9);
if ( *(v8 - 1) != (_DWORD)result )
{
puts("Build binary tree FAILED!");
exit(1);
}
++v10;
v8 += 515;
v9 += 280;
}
while ( num_of_table > v10 );
}
}
return result;
}

original_code:
void jh_init(void)
{
 struct {
  unsigned int no;
  unsigned int type;
  unsigned char table[16];
  unsigned char symbol[256];
 } ht[8];
 struct jf_DHT dht;
 int num_of_dht;
 int i = 0, num = 0, j;
 unsigned int pos = 0;
 int symbol_count;
 num_of_dht = jf_marker_count(0xc4);
 num_of_table = 0;
 for (i = 0; i < num_of_dht; i++) {
  pos = jf_marker_pos(0xc4, i);
  jf_get_dht(&dht, pos);
  num = dht.num_of_ht;
  num_of_table = num_of_table + num;
  for (j = 0; j < num; j++)
   memcpy(&ht[num_of_table - num + j], &dht.ht[j], sizeof(ht[0]));
 }
 for (i = 0; i < num_of_table; i++) {
  table[i].no = ht[i].no;
  table[i].type = ht[i].type;
  table[i].num_of_symbol = 0;
  for (j = 0; j < 16; j++)
   table[i].num_of_symbol += ht[i].table[j];
  symbol_count = get_symbol(table[i].symbol, ht[i].table, ht[i].symbol);
  if (table[i].num_of_symbol != symbol_count) {
   printf("Build binary tree FAILED!\n");
   exit(1);
  }
 }
}

canonical_original_code:
void jh_init()
{
 struct { unsigned int no; unsigned int type; unsigned char table[16]; unsigned char symbol[256]; } ht[8];
 struct jf_DHT dht;
 int num_of_dht;
 int i = 0; int num = 0; int j;
 unsigned int pos = 0;
 int symbol_count;
 num_of_dht = jf_marker_count(0xc4);
 num_of_table = 0;
 for (i = 0; i < num_of_dht; i++) {
  pos = jf_marker_pos(0xc4, i);
  jf_get_dht(&dht, pos);
  num = dht.num_of_ht;
  num_of_table = num_of_table + num;
  for (j = 0; j < num; j++)
   memcpy(&ht[num_of_table - num + j], &dht.ht[j], sizeof(ht[0]));
 }
 for (i = 0; i < num_of_table; i++) {
  table[i].no = ht[i].no;
  table[i].type = ht[i].type;
  table[i].num_of_symbol = 0;
  for (j = 0; j < 16; j++)
   table[i].num_of_symbol += ht[i].table[j];
  symbol_count = get_symbol(table[i].symbol, ht[i].table, ht[i].symbol);
  if (table[i].num_of_symbol != symbol_count) {
   printf("Build binary tree FAILED!\n");
   exit(1);
  }
 }
}

variable_types: struct { unsigned int no; unsigned int type; unsigned char table[16]; unsigned char symbol[256]; } [8]

variable_types: struct jf_DHT { unsigned char id; unsigned int length; unsigned int num_of_ht; struct { unsigned int no; unsigned int type; unsigned char table[16]; unsigned char symbol[256]; } ht[4]; }

variable_types: num int

variable_types:
pos
unsigned int


decompiled_code:
__int64 jh_table_count()
{
return (unsigned int)num_of_table;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)num_of_table;
}

original_code:
int jh_table_count(void)
{
 return num_of_table;
}

canonical_original_code:
int jh_table_count()
{
 return num_of_table;
}


original_code:
enum gbit gb_get(unsigned char *bytes, int index)
{
 int i = 0, j = 0;
 char ch = 0;
 i = index / 8;
 j = 7 - (index % 8);
 ch = *(bytes + i);
 ch = (ch >> j) & 0x1;
 if (ch)
  return GBIT_1;
 else
  return GBIT_0;
}

canonical_original_code:
enum gbit gb_get(unsigned char *bytes, int index)
{
 int i = 0; int j = 0;
 char ch = 0;
 i = index / 8;
 j = 7 - (index % 8);
 ch = *(bytes + i);
 ch = (ch >> j) & 0x1;
 if (ch)
  return GBIT_1;
 else
  return GBIT_0;
}

variable_types: i int

variable_types: ch char

return_type: enum gbit { GBIT_0=0, GBIT_1=1 }


decompiled_code:
__int64 __fastcall gb_get_int(__int64 a1, int a2, int a3)
{
int v3; // ebx
int v4; // er12
unsigned int v5; // ebp

if ( a3 <= 0 )
return 0;
v3 = a2;
v4 = a3 + a2;
v5 = 0;
do
v5 = gb_get(a1, v3++) + 2 * v5;
while ( v3 != v4 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int a3)
{
int v3; // ebx
int v4; // er12
unsigned int v5; // ebp

if ( a3 <= 0 )
return 0;
v3 = a2;
v4 = a3 + a2;
v5 = 0;
do
v5 = func0(a1, v3++) + 2 * v5;
while ( v3 != v4 );
return v5;
}

original_code:
int gb_get_int(unsigned char *bytes, int index, int n)
{
 int i = 0;
 unsigned int value = 0;
 enum gbit ggbit;
 for (i = 0; i < n; i++) {
  ggbit = gb_get(bytes, index + i);
  value = (value << 1) + ggbit;
 }
 return (int)value;
}


original_code:
int gb_set_1(unsigned char *bytes, int index)
{
 int i = 0, j = 0;
 char ch = 0;
 i = index / 8;
 j = 7 - (index % 8);
 ch = *(bytes + i);
 ch = ch | (1 << j);
 *(bytes + i) = ch;
 return 0;
}

canonical_original_code:
int gb_set_1(unsigned char *bytes, int index)
{
 int i = 0; int j = 0;
 char ch = 0;
 i = index / 8;
 j = 7 - (index % 8);
 ch = *(bytes + i);
 ch = ch | (1 << j);
 *(bytes + i) = ch;
 return 0;
}

variable_types: j int


original_code:
int gb_set_0(unsigned char *bytes, int index)
{
 int i = 0, j = 0;
 char ch = 0;
 i = index / 8;
 j = 7 - (index % 8);
 ch = *(bytes + i);
 ch = ch & (~(1 << j));
 *(bytes + i) = ch;
 return 0;
}

canonical_original_code:
int gb_set_0(unsigned char *bytes, int index)
{
 int i = 0; int j = 0;
 char ch = 0;
 i = index / 8;
 j = 7 - (index % 8);
 ch = *(bytes + i);
 ch = ch & (~(1 << j));
 *(bytes + i) = ch;
 return 0;
}

variable_types: index int


decompiled_code:
__int64 __fastcall gb_cmp(__int64 a1, int a2, __int64 a3, int a4, int a5)
{
int i; // ebx
int v9; // ebp

if ( a5 <= 0 )
{
i = 0;
}
else
{
for ( i = 0; i != a5; ++i )
{
v9 = gb_get(a1, a2 + i);
if ( v9 != (unsigned int)gb_get(a3, a4 + i) )
break;
}
}
return (unsigned int)-(a5 != i);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, __int64 a3, int a4, int a5)
{
int i; // ebx
int v9; // ebp

if ( a5 <= 0 )
{
i = 0;
}
else
{
for ( i = 0; i != a5; ++i )
{
v9 = func0(a1, a2 + i);
if ( v9 != (unsigned int)func0(a3, a4 + i) )
break;
}
}
return (unsigned int)-(a5 != i);
}

original_code:
int gb_cmp(unsigned char *bytes0, int index0,
  unsigned char *bytes1, int index1,
  int n)
{
 int i = 0;
 enum gbit bit0, bit1;
 for (i = 0; i < n; i++) {
  bit0 = gb_get(bytes0, index0 + i);
  bit1 = gb_get(bytes1, index1 + i);
  if (bit0 != bit1)
   break;
 }
 if (i == n)
  return 0;
 else
  return -1;
}

canonical_original_code:
int gb_cmp(unsigned char *bytes0, int index0, unsigned char *bytes1, int index1, int n)
{
 int i = 0;
 enum gbit bit0; enum gbit bit1;
 for (i = 0; i < n; i++) {
  bit0 = gb_get(bytes0, index0 + i);
  bit1 = gb_get(bytes1, index1 + i);
  if (bit0 != bit1)
   break;
 }
 if (i == n)
  return 0;
 else
  return -1;
}


decompiled_code:
int print_hts()
{
int result; // eax
int v1; // er15
unsigned int i; // er14
__int64 v3; // rsi
__int64 v4; // rbx
unsigned int j; // er12
int v6; // edx
unsigned int *v7; // rax
unsigned int *v8; // rbp

result = jh_table_count();
if ( result > 0 )
{
v1 = result;
for ( i = 0; i != v1; ++i )
{
v8 = (unsigned int *)jh_get_table_from_index(i);
printf("no = %d ", *v8);
if ( !*v8 )
printf("(Y) , ");
if ( *v8 == 1 )
printf("(CbCr), ");
printf("type = %d ", v8[1]);
if ( !v8[1] )
printf("(DC), ");
if ( v8[1] == 1 )
printf("(AC), ");
printf("Total number of codes: %d\n", v8[2]);
for ( j = 1; j != 17; ++j )
{
printf("%2d bits: ", j);
v6 = v8[2];
if ( v6 <= 0 )
{
v3 = 0LL;
}
else
{
v7 = v8 + 3;
LODWORD(v3) = 0;
do
{
v3 = (*v7 == j) + (unsigned int)v3;
v7 += 2;
}
while ( v7 != &v8[2 * (v6 - 1) + 5] );
}
printf("(%3d ): ", v3);
if ( (int)v8[2] > 0 )
{
v4 = 0LL;
do
{
if ( v8[2 * v4 + 3] == j )
printf("%2x ", BYTE2(v8[2 * v4 + 4]));
++v4;
}
while ( (int)v8[2] > (int)v4 );
}
putchar(10);
}
result = putchar(10);
}
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax
int v1; // er15
unsigned int i; // er14
__int64 v3; // rsi
__int64 v4; // rbx
unsigned int j; // er12
int v6; // edx
unsigned int *v7; // rax
unsigned int *v8; // rbp

result = jh_table_count();
if ( result > 0 )
{
v1 = result;
for ( i = 0; i != v1; ++i )
{
v8 = (unsigned int *)jh_get_table_from_index(i);
printf("no = %d ", *v8);
if ( !*v8 )
printf("(Y) , ");
if ( *v8 == 1 )
printf("(CbCr), ");
printf("type = %d ", v8[1]);
if ( !v8[1] )
printf("(DC), ");
if ( v8[1] == 1 )
printf("(AC), ");
printf("Total number of codes: %d\n", v8[2]);
for ( j = 1; j != 17; ++j )
{
printf("%2d bits: ", j);
v6 = v8[2];
if ( v6 <= 0 )
{
v3 = 0LL;
}
else
{
v7 = v8 + 3;
LODWORD(v3) = 0;
do
{
v3 = (*v7 == j) + (unsigned int)v3;
v7 += 2;
}
while ( v7 != &v8[2 * (v6 - 1) + 5] );
}
printf("(%3d ): ", v3);
if ( (int)v8[2] > 0 )
{
v4 = 0LL;
do
{
if ( v8[2 * v4 + 3] == j )
printf("%2x ", BYTE2(v8[2 * v4 + 4]));
++v4;
}
while ( (int)v8[2] > (int)v4 );
}
putchar(10);
}
result = putchar(10);
}
}
return result;
}

original_code:
void print_hts(void)
{
 int n, i, j, k, count;
 struct jh_table *ht;
 n = jh_table_count();
 for (i = 0; i < n; i++) {
  ht = jh_get_table_from_index(i);
  printf("no = %d ", ht->no);
  if (ht->no == 0)
   printf("(Y)   ,  ");
  if (ht->no == 1)
   printf("(CbCr),  ");
  printf("type = %d ", ht->type);
  if (ht->type == 0)
   printf("(DC),  ");
  if (ht->type == 1)
   printf("(AC),  ");
  printf("Total number of codes: %d\n", ht->num_of_symbol);
  for (j = 1; j <= 16; j++) {
   printf("%2d bits: ", j);
   count = 0;
   for (k = 0; k < ht->num_of_symbol; k++) {
    if (ht->symbol[k].length == j)
     count++;
   }
   printf("(%3d ): ", count);
   for (k = 0; k < ht->num_of_symbol; k++) {
    if (ht->symbol[k].length == j)
     printf("%2x ", ht->symbol[k].code);
   }
   printf("\n");
  }
  printf("\n");
 }
}

canonical_original_code:
void print_hts()
{
 int n; int i; int j; int k; int count;
 struct jh_table *ht;
 n = jh_table_count();
 for (i = 0; i < n; i++) {
  ht = jh_get_table_from_index(i);
  printf("no = %d ", ht->no);
  if (ht->no == 0)
   printf("(Y)   ,  ");
  if (ht->no == 1)
   printf("(CbCr),  ");
  printf("type = %d ", ht->type);
  if (ht->type == 0)
   printf("(DC),  ");
  if (ht->type == 1)
   printf("(AC),  ");
  printf("Total number of codes: %d\n", ht->num_of_symbol);
  for (j = 1; j <= 16; j++) {
   printf("%2d bits: ", j);
   count = 0;
   for (k = 0; k < ht->num_of_symbol; k++) {
    if (ht->symbol[k].length == j)
     count++;
   }
   printf("(%3d ): ", count);
   for (k = 0; k < ht->num_of_symbol; k++) {
    if (ht->symbol[k].length == j)
     printf("%2x ", ht->symbol[k].code);
   }
   printf("\n");
  }
  printf("\n");
 }
}

variable_types: k int

variable_types: count int

variable_types: struct jh_table { int no; int type; int num_of_symbol; struct jh_symbol { unsigned int length; unsigned char bits[2]; unsigned char code; } symbol[256]; } *


decompiled_code:
__int64 print_all_marker_addr()
{
unsigned int v0; // eax
__int64 result; // rax
char v2[4]; // [rsp+8h] [rbp-10h] BYREF
unsigned int v3; // [rsp+Ch] [rbp-Ch]

v0 = jf_marker_total();
printf("There are %d markers.\n", v0);
for ( result = jf_marker_first(v2); !(_DWORD)result; result = jf_marker_next(v2) )
{
switch ( v2[0] )
{
case 0xC0:
printf("SOF0, %2x, %8x\n", 192LL, v3);
break;
case 0xC4:
printf("DHT, %2x, %8x\n", 196LL, v3);
break;
case 0xD8:
printf("SOI, %2x, %8x\n", 216LL, v3);
break;
case 0xD9:
printf("EOI, %2x, %8x\n", 217LL, v3);
break;
case 0xDA:
printf("SOS, %2x, %8x\n", 218LL, v3);
break;
case 0xDB:
printf("DQT, %2x, %8x\n", 219LL, v3);
break;
case 0xE0:
printf("APP0, %2x, %8x\n", 224LL, v3);
break;
default:
printf("%2x, %8x\n", (unsigned __int8)v2[0], v3);
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // eax
__int64 result; // rax
char v2[4]; // [rsp+8h] [rbp-10h] BYREF
unsigned int v3; // [rsp+Ch] [rbp-Ch]

v0 = jf_marker_total();
printf("There are %d markers.\n", v0);
for ( result = jf_marker_first(v2); !(_DWORD)result; result = jf_marker_next(v2) )
{
switch ( v2[0] )
{
case 0xC0:
printf("SOF0, %2x, %8x\n", 192LL, v3);
break;
case 0xC4:
printf("DHT, %2x, %8x\n", 196LL, v3);
break;
case 0xD8:
printf("SOI, %2x, %8x\n", 216LL, v3);
break;
case 0xD9:
printf("EOI, %2x, %8x\n", 217LL, v3);
break;
case 0xDA:
printf("SOS, %2x, %8x\n", 218LL, v3);
break;
case 0xDB:
printf("DQT, %2x, %8x\n", 219LL, v3);
break;
case 0xE0:
printf("APP0, %2x, %8x\n", 224LL, v3);
break;
default:
printf("%2x, %8x\n", (unsigned __int8)v2[0], v3);
break;
}
}
return result;
}

original_code:
void print_all_marker_addr(void)
{
 struct jf_marker marker;
 int flag = 0;
 printf("There are %d markers.\n", jf_marker_total());
 flag = jf_marker_first(&marker);
 while (flag == 0) {
  switch (marker.id) {
  case 0xd8:
   printf("SOI, %2x, %8x\n", marker.id, marker.pos);
   break;
  case 0xe0:
   printf("APP0, %2x, %8x\n", marker.id, marker.pos);
   break;
  case 0xdb:
   printf("DQT, %2x, %8x\n", marker.id, marker.pos);
   break;
  case 0xc0:
   printf("SOF0, %2x, %8x\n", marker.id, marker.pos);
   break;
  case 0xc4:
   printf("DHT, %2x, %8x\n", marker.id, marker.pos);
   break;
  case 0xda:
   printf("SOS, %2x, %8x\n", marker.id, marker.pos);
   break;
  case 0xd9:
   printf("EOI, %2x, %8x\n", marker.id, marker.pos);
   break;
  default:
   printf("%2x, %8x\n", marker.id, marker.pos);
  }
  flag = jf_marker_next(&marker);
 }
}

canonical_original_code:
void print_all_marker_addr()
{
 struct jf_marker marker;
 int flag = 0;
 printf("There are %d markers.\n", jf_marker_total());
 flag = jf_marker_first(&marker);
 while (flag == 0) {
  switch (marker.id) {
  case 0xd8:
   printf("SOI, %2x, %8x\n", marker.id, marker.pos);
   break;
  case 0xe0:
   printf("APP0, %2x, %8x\n", marker.id, marker.pos);
   break;
  case 0xdb:
   printf("DQT, %2x, %8x\n", marker.id, marker.pos);
   break;
  case 0xc0:
   printf("SOF0, %2x, %8x\n", marker.id, marker.pos);
   break;
  case 0xc4:
   printf("DHT, %2x, %8x\n", marker.id, marker.pos);
   break;
  case 0xda:
   printf("SOS, %2x, %8x\n", marker.id, marker.pos);
   break;
  case 0xd9:
   printf("EOI, %2x, %8x\n", marker.id, marker.pos);
   break;
  default:
   printf("%2x, %8x\n", marker.id, marker.pos);
  }
  flag = jf_marker_next(&marker);
 }
}

variable_types: struct jf_marker { unsigned char id; unsigned int pos; }

variable_types: flag int


decompiled_code:
int __fastcall print_8x8(__int64 a1)
{
unsigned int *v1; // rbp
unsigned int *v2; // rbx

v1 = (unsigned int *)(a1 + 32);
do
{
v2 = v1 - 8;
do
printf("%d, ", *v2++);
while ( v2 != v1 );
putchar(10);
v1 += 8;
}
while ( v1 != (unsigned int *)(a1 + 288) );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
unsigned int *v1; // rbp
unsigned int *v2; // rbx

v1 = (unsigned int *)(a1 + 32);
do
{
v2 = v1 - 8;
do
printf("%d, ", *v2++);
while ( v2 != v1 );
putchar(10);
v1 += 8;
}
while ( v1 != (unsigned int *)(a1 + 288) );
return putchar(10);
}

original_code:
void print_8x8(int *block)
{
 int i, j;
 for (i = 0; i < 8; i++) {
  for (j = 0; j < 8; j++) {
   printf("%d, ", block[i * 8 + j]);
  }
  printf("\n");
 }
 printf("\n");
}

canonical_original_code:
void print_8x8(int *block)
{
 int i; int j;
 for (i = 0; i < 8; i++) {
  for (j = 0; j < 8; j++) {
   printf("%d, ", block[i * 8 + j]);
  }
  printf("\n");
 }
 printf("\n");
}

variable_types:
block
int *


decompiled_code:
int print_qts()
{
int result; // eax
int v1; // er12
unsigned int i; // ebp
unsigned int *v3; // rbx

result = jlib_qt_total();
if ( result > 0 )
{
v1 = result;
for ( i = 0; i != v1; ++i )
{
v3 = (unsigned int *)jlib_get_qt_from_index(i);
printf("no = %d ", *v3);
if ( *v3 )
puts("(Chrominance)");
else
puts("(Luminance)");
printf("precision = %d bits\n", 8 * v3[1] + 8);
result = print_8x8((__int64)(v3 + 2));
}
}
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax
int v1; // er12
unsigned int i; // ebp
unsigned int *v3; // rbx

result = jlib_qt_total();
if ( result > 0 )
{
v1 = result;
for ( i = 0; i != v1; ++i )
{
v3 = (unsigned int *)jlib_get_qt_from_index(i);
printf("no = %d ", *v3);
if ( *v3 )
puts("(Chrominance)");
else
puts("(Luminance)");
printf("precision = %d bits\n", 8 * v3[1] + 8);
result = func2((__int64)(v3 + 2));
}
}
return result;
}

original_code:
void print_qts(void)
{
 int i, j, k, n;
 struct quantization_table *qt;
 n = jlib_qt_total();
 for (i = 0; i < n; i++) {
  qt = jlib_get_qt_from_index(i);
  printf("no = %d ", qt->no);
  if (qt->no == 0)
   printf("(Luminance)\n");
  else
   printf("(Chrominance)\n");
  printf("precision = %d bits\n", (qt->precision + 1) * 8);
  print_8x8(qt->table);
 }
}

canonical_original_code:
void print_qts()
{
 int i; int j; int k; int n;
 struct quantization_table *qt;
 n = jlib_qt_total();
 for (i = 0; i < n; i++) {
  qt = jlib_get_qt_from_index(i);
  printf("no = %d ", qt->no);
  if (qt->no == 0)
   printf("(Luminance)\n");
  else
   printf("(Chrominance)\n");
  printf("precision = %d bits\n", (qt->precision + 1) * 8);
  print_8x8(qt->table);
 }
}

variable_types: n int

variable_types: struct quantization_table { int no; int precision; int table[128]; } *


irlc

original_code:
void irlc(int *rlc, int *block, int n)
{
 int i = 0, j, index = 0;
 int zeroes;
 while (1) {
  if (index >= n)
   break;
  if ((rlc[i * 2 + 0] == 0) && (rlc[i * 2 + 1] == 0)) {
   for ( ; index < n; )
    block[index++] = 0;
  } else {
   zeroes = rlc[i * 2 + 0];
   for (j = 0; j < zeroes; j++)
    block[index++] = 0;
   block[index++] = rlc[i * 2 + 1];
  }
  i = i + 1;
 }
}

canonical_original_code:
void irlc(int *rlc, int *block, int n)
{
 int i = 0; int j; int index = 0;
 int zeroes;
 while (1) {
  if (index >= n)
   break;
  if ((rlc[i * 2 + 0] == 0) && (rlc[i * 2 + 1] == 0)) {
   for ( ; index < n; )
    block[index++] = 0;
  } else {
   zeroes = rlc[i * 2 + 0];
   for (j = 0; j < zeroes; j++)
    block[index++] = 0;
   block[index++] = rlc[i * 2 + 1];
  }
  i = i + 1;
 }
}

variable_types:
rlc
int *

variable_types: zeroes int


decompiled_code:
__int64 __fastcall jc_get_R(int a1, __int64 a2, int a3)
{
return (unsigned int)(int)((double)a3 * 1.402 + (double)a1 + 128.0);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, int a3)
{
return (unsigned int)(int)((double)a3 * 1.402 + (double)a1 + 128.0);
}

original_code:
int jc_get_R(int Y, int Cb, int Cr)
{
 double R = 0.0;
 R = Y + 1.402 * (Cr) + 128;
 return (int)R;
}

variable_types: Y int

variable_types: Cb int

variable_types: Cr int

variable_types: R double


decompiled_code:
__int64 __fastcall jc_get_B(int a1, int a2)
{
return (unsigned int)(int)((double)a2 * 1.772 + (double)a1 + 128.0);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return (unsigned int)(int)((double)a2 * 1.772 + (double)a1 + 128.0);
}

original_code:
int jc_get_B(int Y, int Cb, int Cr)
{
 double B = 0.0;
 B = Y + 1.772 * (Cb) + 128;
 return (int)B;
}

variable_types: B double


repo: smranta/graps

decompiled_code:
int graps_readConfig()
{
char *v0; // rax
struct timeval *v1; // rbp
int result; // eax
int v3; // eax
char *v4; // rdx
char *v5; // rbx
struct timeval *v6; // rbx
char v7[1024]; // [rsp+0h] [rbp-428h] BYREF
size_t n; // [rsp+400h] [rbp-28h] BYREF
char *haystack; // [rsp+408h] [rbp-20h] BYREF

haystack = 0LL;
v0 = getenv("HOME");
sprintf(v7, "%s/.grapsrc", v0);
v1 = grap;
v1[4].tv_usec = (__suseconds_t)fopen(v7, "r");
if ( grap[4].tv_usec )
{
while ( 1 )
{
v3 = getline(&haystack, &n, (FILE *)grap[4].tv_usec);
if ( v3 == -1 )
break;
v4 = &haystack[v3 - 1];
if ( *v4 == 10 )
*v4 = 0;
v5 = haystack;
if ( *haystack != 35 && v3 != 1 )
{
if ( strstr(haystack, "capture_enabled") )
{
LODWORD(grap[5].tv_usec) = atoi(v5 + 16);
}
else if ( strstr(v5, "capture_everyframe") )
{
HIDWORD(grap[5].tv_sec) = atoi(v5 + 19);
}
else if ( strstr(v5, "capture_delay") )
{
LODWORD(grap[5].tv_sec) = atoi(v5 + 14);
}
else if ( strstr(v5, "capture_path") )
{
strcpy((char *)&grap[5].tv_usec + 4, v5 + 13);
}
else if ( strstr(v5, "showfps_enabled") )
{
HIDWORD(grap[69].tv_usec) = atoi(v5 + 16);
}
else if ( strstr(v5, "showfps_delay") )
{
LODWORD(grap[70].tv_sec) = atoi(v5 + 14);
}
else if ( strstr(v5, "flip_frame") )
{
HIDWORD(grap[70].tv_sec) = atoi(v5 + 11);
}
else if ( strstr(v5, "quiet") )
{
LODWORD(grap[71].tv_sec) = atoi(v5 + 6);
}
else if ( strstr(v5, "rawvideo_stream") )
{
HIDWORD(grap[71].tv_sec) = atoi(v5 + 16);
}
else if ( strstr(v5, "resize_enable") )
{
LODWORD(grap[71].tv_usec) = atoi(v5 + 14);
}
else if ( strstr(v5, "grapsctl") )
{
LODWORD(grap[71].tv_usec) = atoi(v5 + 8);
}
else
{
printf("grapsrc : \"%s\" not recognised. ignored.\n", v5);
}
}
}
result = fclose((FILE *)grap[4].tv_usec);
}
else
{
result = puts("graps config file not found. using default values.");
}
v6 = grap;
if ( HIDWORD(grap[5].tv_sec) )
LODWORD(grap[72].tv_sec) = 0;
if ( HIDWORD(v6[71].tv_sec) )
{
LODWORD(v6[71].tv_usec) = 0;
if ( !LODWORD(v6[72].tv_sec) )
{
v6[4].tv_usec = (__suseconds_t)fopen("/tmp/grapsvideopipe", "w");
result = (int)grap;
if ( !grap[4].tv_usec )
{
printf("Error : opening videopipe");
exit(0);
}
}
}
return result;
}

canonical_decompiled_code:
int func6()
{
char *v0; // rax
struct timeval *v1; // rbp
int result; // eax
int v3; // eax
char *v4; // rdx
char *v5; // rbx
struct timeval *v6; // rbx
char v7[1024]; // [rsp+0h] [rbp-428h] BYREF
size_t n; // [rsp+400h] [rbp-28h] BYREF
char *haystack; // [rsp+408h] [rbp-20h] BYREF

haystack = 0LL;
v0 = getenv("HOME");
sprintf(v7, "%s/.grapsrc", v0);
v1 = grap;
v1[4].tv_usec = (__suseconds_t)fopen(v7, "r");
if ( grap[4].tv_usec )
{
while ( 1 )
{
v3 = getline(&haystack, &n, (FILE *)grap[4].tv_usec);
if ( v3 == -1 )
break;
v4 = &haystack[v3 - 1];
if ( *v4 == 10 )
*v4 = 0;
v5 = haystack;
if ( *haystack != 35 && v3 != 1 )
{
if ( strstr(haystack, "capture_enabled") )
{
LODWORD(grap[5].tv_usec) = atoi(v5 + 16);
}
else if ( strstr(v5, "capture_everyframe") )
{
HIDWORD(grap[5].tv_sec) = atoi(v5 + 19);
}
else if ( strstr(v5, "capture_delay") )
{
LODWORD(grap[5].tv_sec) = atoi(v5 + 14);
}
else if ( strstr(v5, "capture_path") )
{
strcpy((char *)&grap[5].tv_usec + 4, v5 + 13);
}
else if ( strstr(v5, "showfps_enabled") )
{
HIDWORD(grap[69].tv_usec) = atoi(v5 + 16);
}
else if ( strstr(v5, "showfps_delay") )
{
LODWORD(grap[70].tv_sec) = atoi(v5 + 14);
}
else if ( strstr(v5, "flip_frame") )
{
HIDWORD(grap[70].tv_sec) = atoi(v5 + 11);
}
else if ( strstr(v5, "quiet") )
{
LODWORD(grap[71].tv_sec) = atoi(v5 + 6);
}
else if ( strstr(v5, "rawvideo_stream") )
{
HIDWORD(grap[71].tv_sec) = atoi(v5 + 16);
}
else if ( strstr(v5, "resize_enable") )
{
LODWORD(grap[71].tv_usec) = atoi(v5 + 14);
}
else if ( strstr(v5, "grapsctl") )
{
LODWORD(grap[71].tv_usec) = atoi(v5 + 8);
}
else
{
printf("grapsrc : \"%s\" not recognised. ignored.\n", v5);
}
}
}
result = fclose((FILE *)grap[4].tv_usec);
}
else
{
result = puts("graps config file not found. using default values.");
}
v6 = grap;
if ( HIDWORD(grap[5].tv_sec) )
LODWORD(grap[72].tv_sec) = 0;
if ( HIDWORD(v6[71].tv_sec) )
{
LODWORD(v6[71].tv_usec) = 0;
if ( !LODWORD(v6[72].tv_sec) )
{
v6[4].tv_usec = (__suseconds_t)fopen("/tmp/grapsvideopipe", "w");
result = (int)grap;
if ( !grap[4].tv_usec )
{
printf("Error : opening videopipe");
exit(0);
}
}
}
return result;
}

original_code:
void graps_readConfig(){
 char *line = ((void *)0);
 int read;
 size_t len;
 char grapsrc[1024];
 sprintf( grapsrc, "%s/.grapsrc", getenv("HOME") );
 grap->fp = fopen( grapsrc, "r" );
 if( grap->fp != ((void *)0) ){
  while( (read = getline(&line, &len, grap->fp)) != -1 ){
   if( line[read-1] == '\n' ) line[read-1] = '\0';
   if( line[0] == '#' || read == 1 )
    continue;
   if( strstr( line, "capture_enabled" ) != ((void *)0) ){
    grap->capture = atoi( &line[16] );
   }
   else if( strstr( line, "capture_everyframe" ) != ((void *)0) ){
    grap->capture_everyframe = atoi( &line[19] );
   }
   else if( strstr( line, "capture_delay" ) != ((void *)0) ){
    grap->capture_delay = atoi( &line[14] );
   }
   else if( strstr( line, "capture_path" ) != ((void *)0) ){
    strcpy( grap->capture_path, &line[13] );
   }
   else if( strstr( line, "showfps_enabled" ) != ((void *)0) ){
    grap->showfps = atoi( &line[16] );
   }
   else if( strstr( line, "showfps_delay" ) != ((void *)0) ){
    grap->showfps_delay = atoi( &line[14] );
   }
   else if( strstr( line, "flip_frame" ) != ((void *)0) ){
    grap->flip_frame = atoi( &line[11] );
   }
   else if( strstr( line, "quiet" ) != ((void *)0) ){
    grap->quiet = atoi( &line[6] );
   }
   else if( strstr( line, "rawvideo_stream" ) != ((void *)0) ){
    grap->rawvideo_stream = atoi( &line[16] );
   }
   else if( strstr( line, "resize_enable" ) != ((void *)0) ){
    grap->resize_enable = atoi( &line[14] );
   }
   else if( strstr( line, "grapsctl" ) != ((void *)0) ){
    grap->resize_enable = atoi( &line[8] );
   }
   else {
    printf("grapsrc : \"%s\" not recognised. ignored.\n", line );
   }
  }
  fclose( grap->fp );
 }else{
  printf("graps config file not found. using default values.\n");
 }
 if( grap->capture_everyframe ){
  grap->grapsctl = 0;
 }
 if( grap->rawvideo_stream ){
  grap->resize_enable = 0;
  if( !grap->grapsctl ){
   grap->fp = fopen( "/tmp/grapsvideopipe", "w" );
   if( !grap->fp ){
    printf("Error : opening videopipe");
    exit( 0 );
    return;
   }
  }
 }
}

canonical_original_code:
void graps_readConfig(){
 char *line = ((void *)0);
 int read;
 unsigned long len;
 char grapsrc[1024];
 sprintf( grapsrc, "%s/.grapsrc", getenv("HOME") );
 grap->fp = fopen( grapsrc, "r" );
 if( grap->fp != ((void *)0) ){
  while( (read = getline(&line, &len, grap->fp)) != -1 ){
   if( line[read-1] == '\n' ) line[read-1] = '\0';
   if( line[0] == '#' || read == 1 )
    continue;
   if( strstr( line, "capture_enabled" ) != ((void *)0) ){
    grap->capture = atoi( &line[16] );
   }
   else if( strstr( line, "capture_everyframe" ) != ((void *)0) ){
    grap->capture_everyframe = atoi( &line[19] );
   }
   else if( strstr( line, "capture_delay" ) != ((void *)0) ){
    grap->capture_delay = atoi( &line[14] );
   }
   else if( strstr( line, "capture_path" ) != ((void *)0) ){
    strcpy( grap->capture_path, &line[13] );
   }
   else if( strstr( line, "showfps_enabled" ) != ((void *)0) ){
    grap->showfps = atoi( &line[16] );
   }
   else if( strstr( line, "showfps_delay" ) != ((void *)0) ){
    grap->showfps_delay = atoi( &line[14] );
   }
   else if( strstr( line, "flip_frame" ) != ((void *)0) ){
    grap->flip_frame = atoi( &line[11] );
   }
   else if( strstr( line, "quiet" ) != ((void *)0) ){
    grap->quiet = atoi( &line[6] );
   }
   else if( strstr( line, "rawvideo_stream" ) != ((void *)0) ){
    grap->rawvideo_stream = atoi( &line[16] );
   }
   else if( strstr( line, "resize_enable" ) != ((void *)0) ){
    grap->resize_enable = atoi( &line[14] );
   }
   else if( strstr( line, "grapsctl" ) != ((void *)0) ){
    grap->resize_enable = atoi( &line[8] );
   }
   else {
    printf("grapsrc : \"%s\" not recognised. ignored.\n", line );
   }
  }
  fclose( grap->fp );
 }else{
  printf("graps config file not found. using default values.\n");
 }
 if( grap->capture_everyframe ){
  grap->grapsctl = 0;
 }
 if( grap->rawvideo_stream ){
  grap->resize_enable = 0;
  if( !grap->grapsctl ){
   grap->fp = fopen( "/tmp/grapsvideopipe", "w" );
   if( !grap->fp ){
    printf("Error : opening videopipe");
    exit( 0 );
    return;
   }
  }
 }
}

variable_types:
line
char *

variable_types: read int

variable_types:
len
unsigned long

variable_types:
grapsrc
char [1024]


decompiled_code:
int graps_mesg()
{
int result; // eax

result = (int)grap;
if ( !LODWORD(grap[71].tv_sec) )
result = printf(
"graps v0.1\t\t\t\t\t\t\t\t\n"
"Copyright 2006, smr <smr at smr.co.in>\t\n"
"\t\t\t\t\t\t\t\t\t\t\n"
"using :\t\t\t\t\t\t\t\t\t\n"
" capture_enabled : %d\t\t\t\n"
" capture_delay : %d\t\t\t\n"
" capture_everyframe : %d\t\t\t\n"
" capture_path : %s\t\t\t\n"
" showfps_enabled : %d\t\t\t\n"
" showfps_delay : %d\t\t\t\n"
" flip_frame : %d\t\t\t\n"
" rawvideo_stream : %d\t\t\t\n"
" resize_enable : %d\t\t\t\n"
" grapsctl : %d\t\t\t\n"
"\n",
LODWORD(grap[5].tv_usec),
LODWORD(grap[5].tv_sec),
HIDWORD(grap[5].tv_sec),
(const char *)&grap[5].tv_usec + 4,
HIDWORD(grap[69].tv_usec),
LODWORD(grap[70].tv_sec),
HIDWORD(grap[70].tv_sec),
HIDWORD(grap[71].tv_sec),
LODWORD(grap[71].tv_usec),
LODWORD(grap[72].tv_sec));
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax

result = (int)grap;
if ( !LODWORD(grap[71].tv_sec) )
result = printf(
"graps v0.1\t\t\t\t\t\t\t\t\n"
"Copyright 2006, smr <smr at smr.co.in>\t\n"
"\t\t\t\t\t\t\t\t\t\t\n"
"using :\t\t\t\t\t\t\t\t\t\n"
" capture_enabled : %d\t\t\t\n"
" capture_delay : %d\t\t\t\n"
" capture_everyframe : %d\t\t\t\n"
" capture_path : %s\t\t\t\n"
" showfps_enabled : %d\t\t\t\n"
" showfps_delay : %d\t\t\t\n"
" flip_frame : %d\t\t\t\n"
" rawvideo_stream : %d\t\t\t\n"
" resize_enable : %d\t\t\t\n"
" grapsctl : %d\t\t\t\n"
"\n",
LODWORD(grap[5].tv_usec),
LODWORD(grap[5].tv_sec),
HIDWORD(grap[5].tv_sec),
(const char *)&grap[5].tv_usec + 4,
HIDWORD(grap[69].tv_usec),
LODWORD(grap[70].tv_sec),
HIDWORD(grap[70].tv_sec),
HIDWORD(grap[71].tv_sec),
LODWORD(grap[71].tv_usec),
LODWORD(grap[72].tv_sec));
return result;
}

original_code:
void graps_mesg( void ){
 if( !grap->quiet ) printf("graps v0.1								\nCopyright 2006, smr <smr at smr.co.in>	\n										\nusing :									\n    capture_enabled     : %d			\n    capture_delay       : %d			\n    capture_everyframe  : %d			\n    capture_path        : %s			\n    showfps_enabled     : %d			\n    showfps_delay       : %d			\n    flip_frame          : %d			\n    rawvideo_stream     : %d			\n    resize_enable       : %d			\n    grapsctl            : %d			\n\n", grap->capture, grap->capture_delay, grap->capture_everyframe,
 grap->capture_path, grap->showfps, grap->showfps_delay,
 grap->flip_frame, grap->rawvideo_stream, grap->resize_enable, grap->grapsctl );
}

canonical_original_code:
void graps_mesg(){
 if( !grap->quiet ) printf("graps v0.1								\nCopyright 2006, smr <smr at smr.co.in>	\n										\nusing :									\n    capture_enabled     : %d			\n    capture_delay       : %d			\n    capture_everyframe  : %d			\n    capture_path        : %s			\n    showfps_enabled     : %d			\n    showfps_delay       : %d			\n    flip_frame          : %d			\n    rawvideo_stream     : %d			\n    resize_enable       : %d			\n    grapsctl            : %d			\n\n", grap->capture, grap->capture_delay, grap->capture_everyframe,
 grap->capture_path, grap->showfps, grap->showfps_delay,
 grap->flip_frame, grap->rawvideo_stream, grap->resize_enable, grap->grapsctl );
}


decompiled_code:
__int64 __fastcall graps_flipFrame(__int64 a1)
{
struct timeval *v2; // r9
int i; // edi
int v4; // er10
int v5; // esi
__int64 result; // rax
int v7; // esi
int j; // ecx
char *v9; // rax
char v10; // r11

v2 = grap;
for ( i = 0; SLODWORD(v2[70].tv_usec) > i; ++i )
{
v5 = HIDWORD(v2[70].tv_usec);
v4 = 0;
if ( v5 > 1 )
{
do
{
v7 = v5 - v4;
for ( j = 0; j != 3; ++j )
{
v9 = (char *)(a1 + j + 3 * (i + v4 * LODWORD(v2[70].tv_usec)));
v10 = *v9;
*v9 = *(_BYTE *)(a1 + j + 3 * (i + v7 * LODWORD(v2[70].tv_usec)));
*(_BYTE *)(a1 + j + 3 * (i + LODWORD(v2[70].tv_usec) * v7)) = v10;
}
++v4;
v5 = HIDWORD(v2[70].tv_usec);
result = (unsigned int)(v5 / 2);
}
while ( (int)result > v4 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
struct timeval *v2; // r9
int i; // edi
int v4; // er10
int v5; // esi
__int64 result; // rax
int v7; // esi
int j; // ecx
char *v9; // rax
char v10; // r11

v2 = grap;
for ( i = 0; SLODWORD(v2[70].tv_usec) > i; ++i )
{
v5 = HIDWORD(v2[70].tv_usec);
v4 = 0;
if ( v5 > 1 )
{
do
{
v7 = v5 - v4;
for ( j = 0; j != 3; ++j )
{
v9 = (char *)(a1 + j + 3 * (i + v4 * LODWORD(v2[70].tv_usec)));
v10 = *v9;
*v9 = *(_BYTE *)(a1 + j + 3 * (i + v7 * LODWORD(v2[70].tv_usec)));
*(_BYTE *)(a1 + j + 3 * (i + LODWORD(v2[70].tv_usec) * v7)) = v10;
}
++v4;
v5 = HIDWORD(v2[70].tv_usec);
result = (unsigned int)(v5 / 2);
}
while ( (int)result > v4 );
}
}
return result;
}

original_code:
void graps_flipFrame( unsigned char *data ){
 int i, j, j2, k;
 unsigned char t;
 for( i=0; i<grap->width; ++i ){
  for( j=0; j<grap->height/2; ++j ){
   j2 = grap->height - j;
   for( k=0; k<3; ++k ){
    t = data[ j * grap->width * 3 + i * 3 + k ];
    data[ j * grap->width * 3 + i * 3 + k ] = data[ j2 * grap->width *3 + i * 3 + k ];
    data[ j2 * grap->width * 3 + i * 3 + k ] = t;
   }
  }
 }
}

canonical_original_code:
void graps_flipFrame(unsigned char *data){
 int i; int j; int j2; int k;
 unsigned char t;
 for( i=0; i<grap->width; ++i ){
  for( j=0; j<grap->height/2; ++j ){
   j2 = grap->height - j;
   for( k=0; k<3; ++k ){
    t = data[ j * grap->width * 3 + i * 3 + k ];
    data[ j * grap->width * 3 + i * 3 + k ] = data[ j2 * grap->width *3 + i * 3 + k ];
    data[ j2 * grap->width * 3 + i * 3 + k ] = t;
   }
  }
 }
}

variable_types:
data
unsigned char *

variable_types: i int

variable_types: j int

variable_types: k int

variable_types:
t
unsigned char


decompiled_code:
int __fastcall graps_write(void *ptr)
{
struct timeval *v3; // r12
FILE *v4; // rdi
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( HIDWORD(grap[70].tv_sec) )
graps_flipFrame();
if ( HIDWORD(grap[71].tv_sec) )
return fwrite(ptr, 1uLL, 3 * HIDWORD(grap[70].tv_usec) * LODWORD(grap[70].tv_usec), (FILE *)grap[4].tv_usec);
sprintf(v5, "%s/frame%04d.ppm", (const char *)&grap[5].tv_usec + 4, LODWORD(grap[4].tv_sec));
v3 = grap;
v3[4].tv_usec = (__suseconds_t)fopen(v5, "w");
v4 = (FILE *)grap[4].tv_usec;
if ( !v4 )
{
printf("Error writing file %s. Make sure path is valid and quota is not full.\n", v5);
exit(0);
}
fprintf(v4, "P6\n%d %d\n255\n", LODWORD(grap[70].tv_usec), HIDWORD(grap[70].tv_usec));
fwrite(ptr, 1uLL, 3 * HIDWORD(grap[70].tv_usec) * LODWORD(grap[70].tv_usec), (FILE *)grap[4].tv_usec);
return fclose((FILE *)grap[4].tv_usec);
}

canonical_decompiled_code:
int __fastcall func9(void *ptr)
{
struct timeval *v3; // r12
FILE *v4; // rdi
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( HIDWORD(grap[70].tv_sec) )
func8();
if ( HIDWORD(grap[71].tv_sec) )
return fwrite(ptr, 1uLL, 3 * HIDWORD(grap[70].tv_usec) * LODWORD(grap[70].tv_usec), (FILE *)grap[4].tv_usec);
sprintf(v5, "%s/frame%04d.ppm", (const char *)&grap[5].tv_usec + 4, LODWORD(grap[4].tv_sec));
v3 = grap;
v3[4].tv_usec = (__suseconds_t)fopen(v5, "w");
v4 = (FILE *)grap[4].tv_usec;
if ( !v4 )
{
printf("Error writing file %s. Make sure path is valid and quota is not full.\n", v5);
exit(0);
}
fprintf(v4, "P6\n%d %d\n255\n", LODWORD(grap[70].tv_usec), HIDWORD(grap[70].tv_usec));
fwrite(ptr, 1uLL, 3 * HIDWORD(grap[70].tv_usec) * LODWORD(grap[70].tv_usec), (FILE *)grap[4].tv_usec);
return fclose((FILE *)grap[4].tv_usec);
}

original_code:
void graps_write( unsigned char *data ){
 char frameName[1024];
 if( grap->flip_frame )
  graps_flipFrame( data );
 if( grap->rawvideo_stream ){
  fwrite( data, sizeof( unsigned char), grap->width*grap->height*3, grap->fp );
 }else{
  sprintf( frameName, "%s/frame%04d.ppm", grap->capture_path, grap->frame_count );
  grap->fp = fopen( frameName, "w");
  if( grap->fp == ((void *)0) ){
   printf("Error writing file %s. Make sure path is valid and quota is not full.\n", frameName );
   exit( 0 );
  }
  fprintf( grap->fp, "P6\n%d %d\n255\n", grap->width, grap->height );
  fwrite( data, sizeof( unsigned char), grap->width*grap->height*3, grap->fp );
  fclose( grap->fp );
 }
}

canonical_original_code:
void graps_write(unsigned char *data){
 char frameName[1024];
 if( grap->flip_frame )
  graps_flipFrame( data );
 if( grap->rawvideo_stream ){
  fwrite( data, sizeof( unsigned char), grap->width*grap->height*3, grap->fp );
 }else{
  sprintf( frameName, "%s/frame%04d.ppm", grap->capture_path, grap->frame_count );
  grap->fp = fopen( frameName, "w");
  if( grap->fp == ((void *)0) ){
   printf("Error writing file %s. Make sure path is valid and quota is not full.\n", frameName );
   exit( 0 );
  }
  fprintf( grap->fp, "P6\n%d %d\n255\n", grap->width, grap->height );
  fwrite( data, sizeof( unsigned char), grap->width*grap->height*3, grap->fp );
  fclose( grap->fp );
 }
}

variable_types:
frameName
char [1024]


graps

decompiled_code:
const __m128i *graps()
{
struct timeval *v0; // rbx
struct timeval *v1; // roff
const __m128i *result; // rax
int v3; // edx
__int64 v4; // rcx
__suseconds_t v5; // [rsp+8h] [rbp-10h]

v0 = grap;
gettimeofday(grap, 0LL);
if ( LODWORD(v0[5].tv_usec)
&& v0[3].tv_sec
&& (HIDWORD(v0[5].tv_sec)
|| SLODWORD(v0[5].tv_sec) < (__int64)(unsigned int)(int)((double)(LODWORD(v0->tv_usec) - LODWORD(v0[1].tv_usec))
/ 1000.0
+ (double)(1000
* (LODWORD(v0->tv_sec) - LODWORD(v0[1].tv_sec))))) )
{
if ( LODWORD(v0[71].tv_usec) )
{
glGetIntegerv();
if ( v5 != grap[70].tv_usec )
{
printf(
"resizing %d,%d -- %d,%d\n",
LODWORD(grap[70].tv_usec),
HIDWORD(grap[70].tv_usec),
(unsigned int)v5,
HIDWORD(v5));
grap[70].tv_usec = v5;
}
}
glReadPixels();
if ( LODWORD(grap[72].tv_sec) )
HIDWORD(grap[71].tv_usec) = 1;
else
graps_write((void *)grap[3].tv_sec);
v1 = grap;
grap[1] = (struct timeval)_mm_loadu_si128((const __m128i *)grap);
++LODWORD(v1[4].tv_sec);
}
result = (const __m128i *)grap;
v3 = HIDWORD(grap[4].tv_sec) + 1;
HIDWORD(grap[4].tv_sec) = v3;
if ( result[69].m128i_i32[3] )
{
v4 = (unsigned int)(int)((double)(result->m128i_i32[2] - result[2].m128i_i32[2]) / 1000.0
+ (double)(1000 * (result->m128i_i32[0] - result[2].m128i_i32[0])));
result = (const __m128i *)result[70].m128i_i32[0];
if ( (__int64)result < v4 )
{
printf("\rfps : %.2f ", (double)v3 * 1000.0 / (double)(int)v4);
fflush(stdout);
result = (const __m128i *)grap;
HIDWORD(grap[4].tv_sec) = 0;
result[2] = _mm_loadu_si128(result);
}
}
return result;
}

canonical_decompiled_code:
const __m128i *func11()
{
struct timeval *v0; // rbx
struct timeval *v1; // roff
const __m128i *result; // rax
int v3; // edx
__int64 v4; // rcx
__suseconds_t v5; // [rsp+8h] [rbp-10h]

v0 = grap;
gettimeofday(grap, 0LL);
if ( LODWORD(v0[5].tv_usec)
&& v0[3].tv_sec
&& (HIDWORD(v0[5].tv_sec)
|| SLODWORD(v0[5].tv_sec) < (__int64)(unsigned int)(int)((double)(LODWORD(v0->tv_usec) - LODWORD(v0[1].tv_usec))
/ 1000.0
+ (double)(1000
* (LODWORD(v0->tv_sec) - LODWORD(v0[1].tv_sec))))) )
{
if ( LODWORD(v0[71].tv_usec) )
{
glGetIntegerv();
if ( v5 != grap[70].tv_usec )
{
printf(
"resizing %d,%d -- %d,%d\n",
LODWORD(grap[70].tv_usec),
HIDWORD(grap[70].tv_usec),
(unsigned int)v5,
HIDWORD(v5));
grap[70].tv_usec = v5;
}
}
glReadPixels();
if ( LODWORD(grap[72].tv_sec) )
HIDWORD(grap[71].tv_usec) = 1;
else
func9((void *)grap[3].tv_sec);
v1 = grap;
grap[1] = (struct timeval)_mm_loadu_si128((const __m128i *)grap);
++LODWORD(v1[4].tv_sec);
}
result = (const __m128i *)grap;
v3 = HIDWORD(grap[4].tv_sec) + 1;
HIDWORD(grap[4].tv_sec) = v3;
if ( result[69].m128i_i32[3] )
{
v4 = (unsigned int)(int)((double)(result->m128i_i32[2] - result[2].m128i_i32[2]) / 1000.0
+ (double)(1000 * (result->m128i_i32[0] - result[2].m128i_i32[0])));
result = (const __m128i *)result[70].m128i_i32[0];
if ( (__int64)result < v4 )
{
printf("\rfps : %.2f ", (double)v3 * 1000.0 / (double)(int)v4);
fflush(stdout);
result = (const __m128i *)grap;
HIDWORD(grap[4].tv_sec) = 0;
result[2] = _mm_loadu_si128(result);
}
}
return result;
}

original_code:
void graps(){
 int viewport[4];
 long int timediff;
 gettimeofday( &grap->curtime, ((void *)0) );
 timediff = ( grap->curtime.tv_sec - grap->oldtime.tv_sec ) *1000 + ( grap->curtime.tv_usec - grap->oldtime.tv_usec )/1000.0;
 if( grap->capture && grap->data != ((void *)0) && ( grap->capture_everyframe || timediff > grap->capture_delay ) ){
  if( grap->resize_enable ){
   glGetIntegerv(0x0BA2, viewport);
   if( viewport[2] != grap->width || viewport[3] != grap->height ){
    printf("resizing %d,%d -- %d,%d\n", grap->width, grap->height, viewport[2], viewport[3] );
    grap->width = viewport[2];
    grap->height = viewport[3];
   }
  }
  glReadPixels( 0, 0, grap->width, grap->height, 0x1907, 0x1401, grap->data );
  if( grap->grapsctl ){
   grap->frame_ready = 1;
  }else{
   graps_write( grap->data );
  }
  grap->oldtime = grap->curtime;
  ++grap->frame_count;
 }
 ++grap->fps_frame_count;
 timediff = ( grap->curtime.tv_sec - grap->oldtime2.tv_sec ) *1000 + ( grap->curtime.tv_usec - grap->oldtime2.tv_usec )/1000.0;
 if( grap->showfps && timediff > grap->showfps_delay ){
  printf("\rfps : %.2f   ", grap->fps_frame_count * 1000.0 / timediff);
  fflush( stdout );
  grap->fps_frame_count = 0;
  grap->oldtime2 = grap->curtime;
 }
}

canonical_original_code:
void graps(){
 int viewport[4];
 long timediff;
 gettimeofday( &grap->curtime, ((void *)0) );
 timediff = ( grap->curtime.tv_sec - grap->oldtime.tv_sec ) *1000 + ( grap->curtime.tv_usec - grap->oldtime.tv_usec )/1000.0;
 if( grap->capture && grap->data != ((void *)0) && ( grap->capture_everyframe || timediff > grap->capture_delay ) ){
  if( grap->resize_enable ){
   glGetIntegerv(0x0BA2, viewport);
   if( viewport[2] != grap->width || viewport[3] != grap->height ){
    printf("resizing %d,%d -- %d,%d\n", grap->width, grap->height, viewport[2], viewport[3] );
    grap->width = viewport[2];
    grap->height = viewport[3];
   }
  }
  glReadPixels( 0, 0, grap->width, grap->height, 0x1907, 0x1401, grap->data );
  if( grap->grapsctl ){
   grap->frame_ready = 1;
  }else{
   graps_write( grap->data );
  }
  grap->oldtime = grap->curtime;
  ++grap->frame_count;
 }
 ++grap->fps_frame_count;
 timediff = ( grap->curtime.tv_sec - grap->oldtime2.tv_sec ) *1000 + ( grap->curtime.tv_usec - grap->oldtime2.tv_usec )/1000.0;
 if( grap->showfps && timediff > grap->showfps_delay ){
  printf("\rfps : %.2f   ", grap->fps_frame_count * 1000.0 / timediff);
  fflush( stdout );
  grap->fps_frame_count = 0;
  grap->oldtime2 = grap->curtime;
 }
}

variable_types:
viewport
int [4]

variable_types: timediff long


decompiled_code:
int graps_readConfig()
{
char *v0; // rax
__int64 v1; // rbx
int result; // eax
int v3; // eax
char *v4; // rdx
char *v5; // rbx
__int64 v6; // rbx
char v7[1024]; // [rsp+0h] [rbp-418h] BYREF
size_t n; // [rsp+400h] [rbp-18h] BYREF
char *haystack; // [rsp+408h] [rbp-10h] BYREF

haystack = 0LL;
v0 = getenv("HOME");
sprintf(v7, "%s/.grapsrc", v0);
v1 = grap;
*(_QWORD *)(v1 + 72) = fopen(v7, "r");
if ( *(_QWORD *)(grap + 72) )
{
while ( 1 )
{
v3 = getline(&haystack, &n, *(FILE **)(grap + 72));
if ( v3 == -1 )
break;
v4 = &haystack[v3 - 1];
if ( *v4 == 10 )
*v4 = 0;
v5 = haystack;
if ( *haystack != 35 && v3 != 1 )
{
if ( strstr(haystack, "capture_enabled") )
{
*(_DWORD *)(grap + 88) = atoi(v5 + 16);
}
else if ( strstr(v5, "capture_everyframe") )
{
*(_DWORD *)(grap + 84) = atoi(v5 + 19);
}
else if ( strstr(v5, "capture_delay") )
{
*(_DWORD *)(grap + 80) = atoi(v5 + 14);
}
else if ( strstr(v5, "capture_path") )
{
strcpy((char *)(grap + 92), v5 + 13);
}
else if ( strstr(v5, "showfps_enabled") )
{
*(_DWORD *)(grap + 1116) = atoi(v5 + 16);
}
else if ( strstr(v5, "showfps_delay") )
{
*(_DWORD *)(grap + 1120) = atoi(v5 + 14);
}
else if ( strstr(v5, "flip_frame") )
{
*(_DWORD *)(grap + 1124) = atoi(v5 + 11);
}
else if ( strstr(v5, "quiet") )
{
*(_DWORD *)(grap + 1136) = atoi(v5 + 6);
}
else if ( strstr(v5, "rawvideo_stream") )
{
*(_DWORD *)(grap + 1140) = atoi(v5 + 16);
}
else if ( strstr(v5, "resize_enable") )
{
*(_DWORD *)(grap + 1144) = atoi(v5 + 14);
}
else if ( strstr(v5, "grapsctl") )
{
*(_DWORD *)(grap + 1144) = atoi(v5 + 8);
}
else
{
printf("grapsrc : \"%s\" not recognised. ignored.\n", v5);
}
}
}
result = fclose(*(FILE **)(grap + 72));
}
else
{
result = puts("graps config file not found. using default values.");
}
v6 = grap;
if ( *(_DWORD *)(grap + 84) )
*(_DWORD *)(grap + 1152) = 0;
if ( *(_DWORD *)(v6 + 1140) )
{
*(_DWORD *)(v6 + 1144) = 0;
if ( !*(_DWORD *)(v6 + 1152) )
{
*(_QWORD *)(v6 + 72) = fopen("/tmp/grapsvideopipe", "w");
result = grap;
if ( !*(_QWORD *)(grap + 72) )
{
printf("Error : opening videopipe");
exit(0);
}
}
}
return result;
}

canonical_decompiled_code:
int func7()
{
char *v0; // rax
__int64 v1; // rbx
int result; // eax
int v3; // eax
char *v4; // rdx
char *v5; // rbx
__int64 v6; // rbx
char v7[1024]; // [rsp+0h] [rbp-418h] BYREF
size_t n; // [rsp+400h] [rbp-18h] BYREF
char *haystack; // [rsp+408h] [rbp-10h] BYREF

haystack = 0LL;
v0 = getenv("HOME");
sprintf(v7, "%s/.grapsrc", v0);
v1 = grap;
*(_QWORD *)(v1 + 72) = fopen(v7, "r");
if ( *(_QWORD *)(grap + 72) )
{
while ( 1 )
{
v3 = getline(&haystack, &n, *(FILE **)(grap + 72));
if ( v3 == -1 )
break;
v4 = &haystack[v3 - 1];
if ( *v4 == 10 )
*v4 = 0;
v5 = haystack;
if ( *haystack != 35 && v3 != 1 )
{
if ( strstr(haystack, "capture_enabled") )
{
*(_DWORD *)(grap + 88) = atoi(v5 + 16);
}
else if ( strstr(v5, "capture_everyframe") )
{
*(_DWORD *)(grap + 84) = atoi(v5 + 19);
}
else if ( strstr(v5, "capture_delay") )
{
*(_DWORD *)(grap + 80) = atoi(v5 + 14);
}
else if ( strstr(v5, "capture_path") )
{
strcpy((char *)(grap + 92), v5 + 13);
}
else if ( strstr(v5, "showfps_enabled") )
{
*(_DWORD *)(grap + 1116) = atoi(v5 + 16);
}
else if ( strstr(v5, "showfps_delay") )
{
*(_DWORD *)(grap + 1120) = atoi(v5 + 14);
}
else if ( strstr(v5, "flip_frame") )
{
*(_DWORD *)(grap + 1124) = atoi(v5 + 11);
}
else if ( strstr(v5, "quiet") )
{
*(_DWORD *)(grap + 1136) = atoi(v5 + 6);
}
else if ( strstr(v5, "rawvideo_stream") )
{
*(_DWORD *)(grap + 1140) = atoi(v5 + 16);
}
else if ( strstr(v5, "resize_enable") )
{
*(_DWORD *)(grap + 1144) = atoi(v5 + 14);
}
else if ( strstr(v5, "grapsctl") )
{
*(_DWORD *)(grap + 1144) = atoi(v5 + 8);
}
else
{
printf("grapsrc : \"%s\" not recognised. ignored.\n", v5);
}
}
}
result = fclose(*(FILE **)(grap + 72));
}
else
{
result = puts("graps config file not found. using default values.");
}
v6 = grap;
if ( *(_DWORD *)(grap + 84) )
*(_DWORD *)(grap + 1152) = 0;
if ( *(_DWORD *)(v6 + 1140) )
{
*(_DWORD *)(v6 + 1144) = 0;
if ( !*(_DWORD *)(v6 + 1152) )
{
*(_QWORD *)(v6 + 72) = fopen("/tmp/grapsvideopipe", "w");
result = grap;
if ( !*(_QWORD *)(grap + 72) )
{
printf("Error : opening videopipe");
exit(0);
}
}
}
return result;
}


decompiled_code:
int graps_mesg()
{
int result; // eax

result = grap;
if ( !*(_DWORD *)(grap + 1136) )
result = printf(
"graps v0.1\t\t\t\t\t\t\t\t\n"
"Copyright 2006, smr <smr at smr.co.in>\t\n"
"\t\t\t\t\t\t\t\t\t\t\n"
"using :\t\t\t\t\t\t\t\t\t\n"
" capture_enabled : %d\t\t\t\n"
" capture_delay : %d\t\t\t\n"
" capture_everyframe : %d\t\t\t\n"
" capture_path : %s\t\t\t\n"
" showfps_enabled : %d\t\t\t\n"
" showfps_delay : %d\t\t\t\n"
" flip_frame : %d\t\t\t\n"
" rawvideo_stream : %d\t\t\t\n"
" resize_enable : %d\t\t\t\n"
" grapsctl : %d\t\t\t\n"
"\n",
*(unsigned int *)(grap + 88),
*(unsigned int *)(grap + 80),
*(unsigned int *)(grap + 84),
(const char *)(grap + 92),
*(unsigned int *)(grap + 1116),
*(unsigned int *)(grap + 1120),
*(unsigned int *)(grap + 1124),
*(unsigned int *)(grap + 1140),
*(unsigned int *)(grap + 1144),
*(unsigned int *)(grap + 1152));
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax

result = grap;
if ( !*(_DWORD *)(grap + 1136) )
result = printf(
"graps v0.1\t\t\t\t\t\t\t\t\n"
"Copyright 2006, smr <smr at smr.co.in>\t\n"
"\t\t\t\t\t\t\t\t\t\t\n"
"using :\t\t\t\t\t\t\t\t\t\n"
" capture_enabled : %d\t\t\t\n"
" capture_delay : %d\t\t\t\n"
" capture_everyframe : %d\t\t\t\n"
" capture_path : %s\t\t\t\n"
" showfps_enabled : %d\t\t\t\n"
" showfps_delay : %d\t\t\t\n"
" flip_frame : %d\t\t\t\n"
" rawvideo_stream : %d\t\t\t\n"
" resize_enable : %d\t\t\t\n"
" grapsctl : %d\t\t\t\n"
"\n",
*(unsigned int *)(grap + 88),
*(unsigned int *)(grap + 80),
*(unsigned int *)(grap + 84),
(const char *)(grap + 92),
*(unsigned int *)(grap + 1116),
*(unsigned int *)(grap + 1120),
*(unsigned int *)(grap + 1124),
*(unsigned int *)(grap + 1140),
*(unsigned int *)(grap + 1144),
*(unsigned int *)(grap + 1152));
return result;
}


decompiled_code:
int __fastcall graps_write(void *ptr)
{
__int64 v2; // rbx
__int64 v4; // rbx
FILE *v5; // rdi
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

v2 = grap;
if ( *(_DWORD *)(grap + 1124) )
graps_flipFrame((__int64)ptr);
if ( *(_DWORD *)(v2 + 1140) )
return fwrite(ptr, 1uLL, 3 * *(_DWORD *)(v2 + 1132) * *(_DWORD *)(v2 + 1128), *(FILE **)(v2 + 72));
sprintf(v6, "%s/frame%04d.ppm", (const char *)(v2 + 92), *(unsigned int *)(v2 + 64));
v4 = grap;
*(_QWORD *)(v4 + 72) = fopen(v6, "w");
v5 = *(FILE **)(grap + 72);
if ( !v5 )
{
printf("Error writing file %s. Make sure path is valid and quota is not full.\n", v6);
exit(0);
}
fprintf(v5, "P6\n%d %d\n255\n", *(unsigned int *)(grap + 1128), *(unsigned int *)(grap + 1132));
fwrite(ptr, 1uLL, 3 * *(_DWORD *)(grap + 1132) * *(_DWORD *)(grap + 1128), *(FILE **)(grap + 72));
return fclose(*(FILE **)(grap + 72));
}

canonical_decompiled_code:
int __fastcall func10(void *ptr)
{
__int64 v2; // rbx
__int64 v4; // rbx
FILE *v5; // rdi
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

v2 = grap;
if ( *(_DWORD *)(grap + 1124) )
func9((__int64)ptr);
if ( *(_DWORD *)(v2 + 1140) )
return fwrite(ptr, 1uLL, 3 * *(_DWORD *)(v2 + 1132) * *(_DWORD *)(v2 + 1128), *(FILE **)(v2 + 72));
sprintf(v6, "%s/frame%04d.ppm", (const char *)(v2 + 92), *(unsigned int *)(v2 + 64));
v4 = grap;
*(_QWORD *)(v4 + 72) = fopen(v6, "w");
v5 = *(FILE **)(grap + 72);
if ( !v5 )
{
printf("Error writing file %s. Make sure path is valid and quota is not full.\n", v6);
exit(0);
}
fprintf(v5, "P6\n%d %d\n255\n", *(unsigned int *)(grap + 1128), *(unsigned int *)(grap + 1132));
fwrite(ptr, 1uLL, 3 * *(_DWORD *)(grap + 1132) * *(_DWORD *)(grap + 1128), *(FILE **)(grap + 72));
return fclose(*(FILE **)(grap + 72));
}


repo: smunaut/osmo-pocsag

decompiled_code:
__int64 __fastcall hamming_weight(unsigned int a1)
{
unsigned int v1; // edx
int v2; // eax

if ( !a1 )
return 0;
v1 = 0;
v2 = 0;
do
{
v1 += a1 & 1;
a1 >>= 1;
++v2;
}
while ( v2 <= 31 && a1 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
unsigned int v1; // edx
int v2; // eax

if ( !a1 )
return 0;
v1 = 0;
v2 = 0;
do
{
v1 += a1 & 1;
a1 >>= 1;
++v2;
}
while ( v2 <= 31 && a1 );
return v1;
}

original_code:
static int
hamming_weight(uint32_t data)
{
 int i, c=0;
 for (i=0; i<32 && data; i++) {
  c += data & 1;
  data >>= 1;
 }
 return c;
}

canonical_original_code:
static int hamming_weight(unsigned int data)
{
 int i; int c = 0;
 for (i=0; i<32 && data; i++) {
  c += data & 1;
  data >>= 1;
 }
 return c;
}

variable_types:
data
unsigned int

variable_types: c int


decompiled_code:
__int64 __fastcall even_parity(unsigned int a1)
{
unsigned int v1; // edi

v1 = ((a1 ^ HIWORD(a1)) >> 8) ^ a1 ^ HIWORD(a1);
return (27030 >> ((v1 ^ (v1 >> 4)) & 0xF)) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
unsigned int v1; // edi

v1 = ((a1 ^ HIWORD(a1)) >> 8) ^ a1 ^ HIWORD(a1);
return (27030 >> ((v1 ^ (v1 >> 4)) & 0xF)) & 1;
}

original_code:
static inline uint8_t
even_parity(uint32_t x)
{
 x ^= x >> 16;
 x ^= x >> 8;
 x ^= x >> 4;
 x &= 0xf;
 return (0x6996 >> x) & 1;
}

canonical_original_code:
static inline unsigned char even_parity(unsigned int x)
{
 x ^= x >> 16;
 x ^= x >> 8;
 x ^= x >> 4;
 x &= 0xf;
 return (0x6996 >> x) & 1;
}

variable_types:
x
unsigned int

return_type: unsigned char


decompiled_code:
__int64 __fastcall bch_syndrome(unsigned int a1)
{
unsigned int v1; // ebx
int v2; // ecx
unsigned int v3; // edx
unsigned int v4; // eax
char v5; // dl
unsigned int v6; // eax

v1 = a1 >> 1;
v2 = 21;
v3 = 1989148672;
v4 = 0x40000000;
do
{
if ( (v4 & v1) != 0 )
v1 ^= v3;
v4 >>= 1;
v3 >>= 1;
--v2;
}
while ( v2 );
v5 = even_parity(a1);
v6 = v1;
if ( v5 )
{
BYTE1(v6) = BYTE1(v1) | 4;
v1 = v6;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
unsigned int v1; // ebx
int v2; // ecx
unsigned int v3; // edx
unsigned int v4; // eax
char v5; // dl
unsigned int v6; // eax

v1 = a1 >> 1;
v2 = 21;
v3 = 1989148672;
v4 = 0x40000000;
do
{
if ( (v4 & v1) != 0 )
v1 ^= v3;
v4 >>= 1;
v3 >>= 1;
--v2;
}
while ( v2 );
v5 = func8(a1);
v6 = v1;
if ( v5 )
{
BYTE1(v6) = BYTE1(v1) | 4;
v1 = v6;
}
return v1;
}

original_code:
static uint32_t
bch_syndrome(uint32_t data)
{
 uint32_t shreg = data >> 1;
 uint32_t mask = 1L << (31 -1), coeff = 0x769 << (21 -1);
 int n = 21;
 for(; n > 0; mask >>= 1, coeff >>= 1, n--)
  if (shreg & mask)
   shreg ^= coeff;
 if (even_parity(data))
  shreg |= (1 << (31 - 21));
 return shreg;
}

canonical_original_code:
static unsigned int bch_syndrome(unsigned int data)
{
 unsigned int shreg = data >> 1;
 unsigned int mask = 1L << (31 -1); unsigned int coeff = 0x769 << (21 -1);
 int n = 21;
 for(; n > 0; mask >>= 1, coeff >>= 1, n--)
  if (shreg & mask)
   shreg ^= coeff;
 if (even_parity(data))
  shreg |= (1 << (31 - 21));
 return shreg;
}

variable_types:
shreg
unsigned int

variable_types:
mask
unsigned int

variable_types:
coeff
unsigned int

variable_types: n int

return_type: unsigned int


decompiled_code:
__int64 __fastcall bch_fix(unsigned int a1)
{
int v1; // ebp
unsigned int v2; // ebx
int v3; // ebp
int v4; // er14
int v5; // er13

v1 = 0;
while ( 1 )
{
v2 = a1 ^ (1 << v1);
if ( !(unsigned int)bch_syndrome(v2) )
return v2;
if ( ++v1 == 32 )
{
v3 = 1;
LABEL_5:
v4 = v3;
v5 = 1 << (v3 - 1);
while ( 1 )
{
v2 = a1 ^ (v5 | (1 << v3));
if ( !(unsigned int)bch_syndrome(v2) )
return v2;
if ( ++v3 > 31 )
{
v3 = v4 + 1;
if ( v4 != 31 )
goto LABEL_5;
return a1;
}
}
}
}
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
int v1; // ebp
unsigned int v2; // ebx
int v3; // ebp
int v4; // er14
int v5; // er13

v1 = 0;
while ( 1 )
{
v2 = a1 ^ (1 << v1);
if ( !(unsigned int)func9(v2) )
return v2;
if ( ++v1 == 32 )
{
v3 = 1;
LABEL_5:
v4 = v3;
v5 = 1 << (v3 - 1);
while ( 1 )
{
v2 = a1 ^ (v5 | (1 << v3));
if ( !(unsigned int)func9(v2) )
return v2;
if ( ++v3 > 31 )
{
v3 = v4 + 1;
if ( v4 != 31 )
goto LABEL_5;
return a1;
}
}
}
}
}

original_code:
static uint32_t
bch_fix(uint32_t data)
{
 uint32_t t;
 int i, j;
 for (i=0; i<32; i++) {
  t = data ^ (1<<i);
  if (!bch_syndrome(t))
   return t;
 }
 for (i=0; i<32; i++) {
  for (j=i+1; j<32; j++) {
   t = data ^ ((1<<i) | (1<<j));
   if (!bch_syndrome(t))
    return t;
  }
 }
 return data;
}

canonical_original_code:
static unsigned int bch_fix(unsigned int data)
{
 unsigned int t;
 int i; int j;
 for (i=0; i<32; i++) {
  t = data ^ (1<<i);
  if (!bch_syndrome(t))
   return t;
 }
 for (i=0; i<32; i++) {
  for (j=i+1; j<32; j++) {
   t = data ^ ((1<<i) | (1<<j));
   if (!bch_syndrome(t))
    return t;
  }
 }
 return data;
}

variable_types:
t
unsigned int


variable_types: struct pocsag_txt { unsigned int bits; int nb; int nc; char buf[256]; } *

variable_types:
d
unsigned int

variable_types: c char


decompiled_code:
__int64 __fastcall pocsag_txt_init(__int64 a1)
{
int v1; // eax
void *v2; // rdi
unsigned int v3; // ecx
__int64 result; // rax

v1 = a1;
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = 0;
*(_QWORD *)(a1 + 12) = 0LL;
*(_QWORD *)(a1 + 260) = 0LL;
v2 = (void *)((a1 + 20) & 0xFFFFFFFFFFFFFFF8LL);
v3 = (unsigned int)(v1 - (_DWORD)v2 + 268) >> 3;
result = 0LL;
memset(v2, 0, 8LL * v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
int v1; // eax
void *v2; // rdi
unsigned int v3; // ecx
__int64 result; // rax

v1 = a1;
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = 0;
*(_QWORD *)(a1 + 12) = 0LL;
*(_QWORD *)(a1 + 260) = 0LL;
v2 = (void *)((a1 + 20) & 0xFFFFFFFFFFFFFFF8LL);
v3 = (unsigned int)(v1 - (_DWORD)v2 + 268) >> 3;
result = 0LL;
memset(v2, 0, 8LL * v3);
return result;
}

original_code:
static void
pocsag_txt_init(struct pocsag_txt *pt)
{
 pt->bits = 0;
 pt->nb = 0;
 pt->nc = 0;
 memset(pt->buf, 0x00, 256);
}

user_defined_types: struct pocsag_txt { unsigned int bits; int nb; int nc; char buf[256]; }


decompiled_code:
__int64 __fastcall pocsag_init(_QWORD *a1)
{
*a1 = 0LL;
*(_QWORD *)((char *)a1 + 284) = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 292) >> 3));
return pocsag_txt_init((__int64)(a1 + 3));
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1)
{
*a1 = 0LL;
*(_QWORD *)((char *)a1 + 284) = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 292) >> 3));
return func12((__int64)(a1 + 3));
}

original_code:
static void
pocsag_init(struct pocsag *ps)
{
 memset(ps, 0x00, sizeof(struct pocsag));
 pocsag_txt_init(&ps->txt);
}

variable_types: struct pocsag { int b; int sync; unsigned int cw; int cw_bits; int cw_num; int txt_active; struct pocsag_txt { unsigned int bits; int nb; int nc; char buf[256]; } txt; } *

user_defined_types: struct pocsag { int b; int sync; unsigned int cw; int cw_bits; int cw_num; int txt_active; struct pocsag_txt txt; }


original_code:
static void
pocsag_rx_bit(struct pocsag *ps, uint8_t bit)
{
 uint32_t cw;
 uint32_t syndrome;
 ps->cw = (ps->cw << 1) | bit;
 ps->b++;
 if (!ps->sync) {
  if (ps->cw != 0x7cd215d8)
   return;
  printf("SYNC @%d\n", ps->b-1);
  ps->sync = 4;
  ps->cw = 0;
  ps->cw_bits = 0;
  ps->cw_num = 0;
  return;
 }
 if (++ps->cw_bits != 32)
  return;
 ps->cw_bits = 0;
 cw = ps->cw;
 syndrome = bch_syndrome(cw);
 if (syndrome) {
  cw = bch_fix(ps->cw);
  syndrome = bch_syndrome(cw);
 }
 if (syndrome) {
  ps->sync -= 1;
  if (ps->sync <= 0) {
   ps->sync = 0;
   printf(" <lost sync>\n");
   return;
  }
 } else {
  ps->sync += 2;
  if (ps->sync > 4)
   ps->sync = 4;
 }
 printf("%2d %08x (%08x) %d %2s",
  ps->cw_num, cw, ps->cw, hamming_weight(cw ^ ps->cw),
  syndrome == 0 ? "OK" : " "
 );
 if (ps->cw_num == -1) {
  if (cw == 0x7cd215d8)
   printf(" => SYNC\n");
  ps->cw_num++;
  return;
 }
 if (cw == 0x7a89c197) {
  printf(" => IDLE");
  if (!syndrome) {
   ps->txt_active = 0;
  }
 } else if (cw == 0x7cd215d8)
  printf(" => SYNC");
 else if (cw & (1<<31))
 {
  static uint32_t ld;
  char *tbl = "0123456789*U -)(";
  uint32_t d = (cw >> 11) & 0xfffff;
  int i;
  printf(" __ ");
  for (i=0; i<5; i++) {
   printf("%c", tbl[(d >> ((4-i)*4)) & 0xf]);
  }
  if (ps->txt_active) {
   pocsag_txt_feed(&ps->txt, d);
   printf(" - %d %d TXT: |%s|", ps->txt.nb, ps->txt.nc, ps->txt.buf);
  }
 }
 else
 {
  printf(" => Addr: %d", (cw >> 11) & 3);
  if (!syndrome) {
   pocsag_txt_init(&ps->txt);
   ps->txt_active = 1;
  } else if (ps->txt_active) {
   uint32_t d = (cw >> 11) & 0xfffff;
   pocsag_txt_feed(&ps->txt, d);
  }
 }
 printf("\n");
 ps->cw_num ++;
 if (ps->cw_num == 16)
  ps->cw_num = -1;
}

canonical_original_code:
static void pocsag_rx_bit(struct pocsag *ps, unsigned char bit)
{
 unsigned int cw;
 unsigned int syndrome;
 ps->cw = (ps->cw << 1) | bit;
 ps->b++;
 if (!ps->sync) {
  if (ps->cw != 0x7cd215d8)
   return;
  printf("SYNC @%d\n", ps->b-1);
  ps->sync = 4;
  ps->cw = 0;
  ps->cw_bits = 0;
  ps->cw_num = 0;
  return;
 }
 if (++ps->cw_bits != 32)
  return;
 ps->cw_bits = 0;
 cw = ps->cw;
 syndrome = bch_syndrome(cw);
 if (syndrome) {
  cw = bch_fix(ps->cw);
  syndrome = bch_syndrome(cw);
 }
 if (syndrome) {
  ps->sync -= 1;
  if (ps->sync <= 0) {
   ps->sync = 0;
   printf(" <lost sync>\n");
   return;
  }
 } else {
  ps->sync += 2;
  if (ps->sync > 4)
   ps->sync = 4;
 }
 printf("%2d %08x (%08x) %d %2s",
  ps->cw_num, cw, ps->cw, hamming_weight(cw ^ ps->cw),
  syndrome == 0 ? "OK" : " "
 );
 if (ps->cw_num == -1) {
  if (cw == 0x7cd215d8)
   printf(" => SYNC\n");
  ps->cw_num++;
  return;
 }
 if (cw == 0x7a89c197) {
  printf(" => IDLE");
  if (!syndrome) {
   ps->txt_active = 0;
  }
 } else if (cw == 0x7cd215d8)
  printf(" => SYNC");
 else if (cw & (1<<31))
 {
  static unsigned int ld;
  char *tbl = "0123456789*U -)(";
  unsigned int d = (cw >> 11) & 0xfffff;
  int i;
  printf(" __ ");
  for (i=0; i<5; i++) {
   printf("%c", tbl[(d >> ((4-i)*4)) & 0xf]);
  }
  if (ps->txt_active) {
   pocsag_txt_feed(&ps->txt, d);
   printf(" - %d %d TXT: |%s|", ps->txt.nb, ps->txt.nc, ps->txt.buf);
  }
 }
 else
 {
  printf(" => Addr: %d", (cw >> 11) & 3);
  if (!syndrome) {
   pocsag_txt_init(&ps->txt);
   ps->txt_active = 1;
  } else if (ps->txt_active) {
   unsigned int d = (cw >> 11) & 0xfffff;
   pocsag_txt_feed(&ps->txt, d);
  }
 }
 printf("\n");
 ps->cw_num ++;
 if (ps->cw_num == 16)
  ps->cw_num = -1;
}

variable_types:
bit
unsigned char

variable_types:
cw
unsigned int

variable_types:
syndrome
unsigned int

variable_types:
ld
unsigned int

variable_types:
tbl
char *

variable_types: i int


extend

decompiled_code:
void extend()
{
int v0; // ebx
_DWORD *v1; // rbp
_DWORD *v2; // rsi
__int64 i; // rax

v0 = len;
v1 = malloc(8LL * len);
if ( v0 > 0 )
{
v2 = primes;
for ( i = 0LL; i != v0; ++i )
v1[i] = v2[i];
}
free(primes);
primes = v1;
len *= 2;
}

canonical_decompiled_code:
void func7()
{
int v0; // ebx
_DWORD *v1; // rbp
_DWORD *v2; // rsi
__int64 i; // rax

v0 = len;
v1 = malloc(8LL * len);
if ( v0 > 0 )
{
v2 = primes;
for ( i = 0LL; i != v0; ++i )
v1[i] = v2[i];
}
free(primes);
primes = v1;
len *= 2;
}

original_code:
void extend(){
    int * new_primes = (int *)malloc(sizeof(int) * len * 2);
    for (int i = 0; i < len; i++){
        new_primes[i] = primes[i];
    }
    free(primes);
    primes = new_primes;
    len = len * 2;
}

canonical_original_code:
void extend(){
    int *new_primes = (int *)malloc(sizeof(int) * len * 2);
    for (int i = 0; i < len; i++){
        new_primes[i] = primes[i];
    }
    free(primes);
    primes = new_primes;
    len = len * 2;
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // ebp
_DWORD *v5; // rcx

primes = malloc(0x9C40uLL);
v3 = 2;
v4 = 0;
while ( 1 )
{
if ( v4 <= 0 )
{
LABEL_8:
*((_DWORD *)primes + v4++) = v3;
printf("%d ", (unsigned int)v3);
if ( len <= v4 )
extend();
}
else
{
v5 = primes;
while ( v3 % *v5 )
{
if ( ++v5 == (_DWORD *)((char *)primes + 4 * (unsigned int)(v4 - 1) + 4) )
goto LABEL_8;
}
}
++v3;
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // ebp
_DWORD *v5; // rcx

primes = malloc(0x9C40uLL);
v3 = 2;
v4 = 0;
while ( 1 )
{
if ( v4 <= 0 )
{
LABEL_8:
*((_DWORD *)primes + v4++) = v3;
printf("%d ", (unsigned int)v3);
if ( len <= v4 )
func7();
}
else
{
v5 = primes;
while ( v3 % *v5 )
{
if ( ++v5 == (_DWORD *)((char *)primes + 4 * (unsigned int)(v4 - 1) + 4) )
goto LABEL_8;
}
}
++v3;
}
}

original_code:
int main(){
    primes = (int *)malloc(sizeof(int) * 10000);
    int num_of_primes = 0;
    int num = 2;
    while(1){
        char is_prime = 1;
        for (int i = 0; i < num_of_primes; i++){
            if(num % primes[i] == 0){
                is_prime = 0;
                break;
            }
        }
        if (is_prime){
            primes[num_of_primes] = num;
            num_of_primes++;
            printf("%d ", num);
            if(num_of_primes >= len) extend();
        }
        num++;
    }
    return 0;
}

variable_types: num int


repo: snatchev/Luadbi

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

result = a1;
if ( a1 != 2 )
{
result = 0LL;
if ( a1 != 5 )
{
result = 3LL;
if ( a1 == 1 )
result = 1LL;
}
}
return result;
}

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

result = a1;
if ( a1 != 2 )
{
result = 0LL;
if ( a1 != 5 )
{
result = 3LL;
if ( a1 == 1 )
result = 1LL;
}
}
return result;
}

original_code:
static lua_push_type_t sqlite_to_lua_push(unsigned int sqlite_type) {
    lua_push_type_t lua_type;
    switch(sqlite_type) {
    case 5:
        lua_type = LUA_PUSH_NIL;
        break;
    case 1:
        lua_type = LUA_PUSH_INTEGER;
        break;
    case 2:
        lua_type = LUA_PUSH_NUMBER;
        break;
    default:
        lua_type = LUA_PUSH_STRING;
    }
    return lua_type;
}

canonical_original_code:
static enum lua_push_type sqlite_to_lua_push(unsigned int sqlite_type) {
    enum lua_push_type lua_type;
    switch(sqlite_type) {
    case 5:
        lua_type = LUA_PUSH_NIL;
        break;
    case 1:
        lua_type = LUA_PUSH_INTEGER;
        break;
    case 2:
        lua_type = LUA_PUSH_NUMBER;
        break;
    default:
        lua_type = LUA_PUSH_STRING;
    }
    return lua_type;
}

variable_types: enum lua_push_type { LUA_PUSH_NIL=0, LUA_PUSH_INTEGER=1, LUA_PUSH_NUMBER=2, LUA_PUSH_STRING=3, LUA_PUSH_BOOLEAN=4, LUA_PUSH_MAX=5 }


decompiled_code:
void signal_handler()
{
++counter;
puts(" Caught Ctrl+C");
}

canonical_decompiled_code:
void func7()
{
++counter;
puts(" Caught Ctrl+C");
}

original_code:
void signal_handler(int arg)
{
 counter++;
 printf("  Caught Ctrl+C\n");
}

variable_types: arg int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
signal(2, (__sighandler_t)signal_handler);
while ( counter <= 2 )
;
return 0;
}

original_code:
int main(int argc, char const *argv[])
{
 signal(2, signal_handler);
 while(counter < 3);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 signal(2, signal_handler);
 while(counter < 3);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
unsigned __int64 gethrcycle_x86()
{
return __rdtsc();
}

canonical_decompiled_code:
unsigned __int64 func7()
{
return __rdtsc();
}

original_code:
hrtime_t gethrcycle_x86(void)
{
    unsigned int tmp[2];
    __asm__ ("rdtsc"
      : "=a" (tmp[1]), "=d" (tmp[0])
      : "c" (0x10) );
    return ( ((hrtime_t)tmp[0] << 32 | tmp[1]) );
}

canonical_original_code:
long long gethrcycle_x86()
{
    unsigned int tmp[2];
    __asm__ ("rdtsc"
      : "=a" (tmp[1]), "=d" (tmp[0])
      : "c" (0x10) );
    return ( ((long long)tmp[0] << 32 | tmp[1]) );
}

variable_types:
tmp
unsigned int [2]

return_type: long long


decompiled_code:
double gethrtime_x86()
{
if ( *(double *)&CPU_MHZ_0 == 0.0 )
CPU_MHZ_0 = getMHZ_x86();
return (double)(int)gethrcycle_x86() * 0.000001 / *(double *)&CPU_MHZ_0;
}

canonical_decompiled_code:
double func9()
{
if ( *(double *)&CPU_MHZ_0 == 0.0 )
CPU_MHZ_0 = func8();
return (double)(int)func7() * 0.000001 / *(double *)&CPU_MHZ_0;
}

original_code:
double gethrtime_x86(void)
{
    static double CPU_MHZ=0;
    if (CPU_MHZ==0) CPU_MHZ=getMHZ_x86();
    return (gethrcycle_x86()*0.000001)/CPU_MHZ;
}

canonical_original_code:
double gethrtime_x86()
{
    static double CPU_MHZ = 0;
    if (CPU_MHZ==0) CPU_MHZ=getMHZ_x86();
    return (gethrcycle_x86()*0.000001)/CPU_MHZ;
}

return_type: double


empty

decompiled_code:
void empty()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code: void empty(void){}

canonical_original_code: void empty(){}


threadMain

decompiled_code:
void *__fastcall threadMain(void *a1)
{
int v1; // ebx

v1 = 10000;
do
{
pthread_spin_lock(&lock);
++shared_counter;
pthread_spin_unlock(&lock);
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // ebx

v1 = 10000;
do
{
pthread_spin_lock(&lock);
++shared_counter;
pthread_spin_unlock(&lock);
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
void *threadMain(void *args)
{
 int i;
 for (i = 0; i < 10000; ++i)
 {
  pthread_spin_lock(&lock);
  shared_counter++;
  pthread_spin_unlock(&lock);
 }
 return ((void *)0);
}

variable_types:
args
void *

return_type: void *


canonical_decompiled_code:
unsigned __int64 func8()
{
return __rdtsc();
}


canonical_decompiled_code:
double func10()
{
if ( *(double *)&CPU_MHZ_0 == 0.0 )
CPU_MHZ_0 = func9();
return (double)(int)func8() * 0.000001 / *(double *)&CPU_MHZ_0;
}


NewRecEle

decompiled_code:
_QWORD *NewRecEle()
{
_QWORD *v0; // rbx

v0 = malloc(0x20uLL);
OutString(8, "Malloc ELE\n");
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
v0[3] = 0LL;
}
return v0;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *v0; // rbx

v0 = malloc(0x20uLL);
func0(8, "Malloc ELE\n");
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
v0[3] = 0LL;
}
return v0;
}

original_code:
REC_INFO* NewRecEle()
{
    REC_INFO* pRec = ((void *)0);
    pRec = (REC_INFO*)malloc(sizeof(REC_INFO));
    OutString((1<<3),"Malloc ELE\n");
    if(pRec == ((void *)0))
    {
        return ((void *)0);
    }
    memset(pRec,0,sizeof(REC_INFO));
    return pRec;
}

canonical_original_code:
struct REC_INFO_STRU *NewRecEle()
{
    struct REC_INFO_STRU *pRec = ((void *)0);
    pRec = (struct REC_INFO_STRU *)malloc(sizeof(REC_INFO));
    OutString((1<<3),"Malloc ELE\n");
    if(pRec == ((void *)0))
    {
        return ((void *)0);
    }
    memset(pRec,0,sizeof(REC_INFO));
    return pRec;
}

variable_types: struct REC_INFO_STRU { enum ELE_TYPE { ELE_SEPERATOR=0, ELE_TEXT=1, ELE_END=2 } type; char *pContent; enum ELE_SEPERATOR_TYPE { SEP_COMMA=0, SEP_COLON=1, SEP_EQUAL=2, SEP_SPACE=3, SEP_RETURN=4, SEP_NEXTLINE=5, SEP_END=6 } sep; struct REC_INFO_STRU *pNext; } *

user_defined_types: struct REC_INFO_STRU { enum ELE_TYPE type; char *pContent; enum ELE_SEPERATOR_TYPE sep; struct REC_INFO_STRU *pNext; }


SaveTextInfo

decompiled_code:
__int64 __fastcall SaveTextInfo(__int64 a1, const void *a2, size_t a3)
{
__int64 result; // rax
_BYTE *v5; // rax
_BYTE *v6; // r13

result = 0LL;
if ( a3 )
{
v5 = malloc(a3 + 1);
v6 = v5;
*(_QWORD *)(a1 + 8) = v5;
if ( v5 )
{
memcpy(v5, a2, a3);
v6[a3] = 0;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const void *a2, size_t a3)
{
__int64 result; // rax
_BYTE *v5; // rax
_BYTE *v6; // r13

result = 0LL;
if ( a3 )
{
v5 = malloc(a3 + 1);
v6 = v5;
*(_QWORD *)(a1 + 8) = v5;
if ( v5 )
{
memcpy(v5, a2, a3);
v6[a3] = 0;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int SaveTextInfo(REC_INFO* pEle, char* pStr, size_t strLen)
{
    if(strLen > 0)
    {
        pEle->pContent = (char*)malloc(strLen + 1);
        if(pEle->pContent == ((void *)0))
        {
            return -1;
        }
        memcpy(pEle->pContent, pStr, strLen);
        pEle->pContent[strLen] = '\0';
    }
    return 0;
}

canonical_original_code:
int SaveTextInfo(struct REC_INFO_STRU *pEle, char *pStr, unsigned long strLen)
{
    if(strLen > 0)
    {
        pEle->pContent = (char *)malloc(strLen + 1);
        if(pEle->pContent == ((void *)0))
        {
            return -1;
        }
        memcpy(pEle->pContent, pStr, strLen);
        pEle->pContent[strLen] = '\0';
    }
    return 0;
}

variable_types:
pStr
char *

variable_types:
strLen
unsigned long

user_defined_types: enum ELE_TYPE { ELE_SEPERATOR=0, ELE_TEXT=1, ELE_END=2 }

user_defined_types: enum ELE_SEPERATOR_TYPE { SEP_COMMA=0, SEP_COLON=1, SEP_EQUAL=2, SEP_SPACE=3, SEP_RETURN=4, SEP_NEXTLINE=5, SEP_END=6 }


SaveSepInfo

decompiled_code:
__int64 __fastcall SaveSepInfo(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
return 0LL;
}

original_code:
int SaveSepInfo(REC_INFO* pEle, enum ELE_SEPERATOR_TYPE sepType)
{
    pEle->sep = sepType;
    return 0;
}

canonical_original_code:
int SaveSepInfo(struct REC_INFO_STRU *pEle, enum ELE_SEPERATOR_TYPE sepType)
{
    pEle->sep = sepType;
    return 0;
}

variable_types: enum ELE_SEPERATOR_TYPE { SEP_COMMA=0, SEP_COLON=1, SEP_EQUAL=2, SEP_SPACE=3, SEP_RETURN=4, SEP_NEXTLINE=5, SEP_END=6 }


DelAllEle

decompiled_code:
int __fastcall DelAllEle(void *ptr)
{
_QWORD *v1; // rbx
int result; // eax
_QWORD *v3; // rbp
void *v4; // rdi

v1 = ptr;
if ( ptr )
{
do
{
v3 = v1;
v1 = (_QWORD *)v1[3];
v4 = (void *)v3[1];
if ( v4 )
free(v4);
free(v3);
result = OutString(8, "FREE ELE\n");
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(void *ptr)
{
_QWORD *v1; // rbx
int result; // eax
_QWORD *v3; // rbp
void *v4; // rdi

v1 = ptr;
if ( ptr )
{
do
{
v3 = v1;
v1 = (_QWORD *)v1[3];
v4 = (void *)v3[1];
if ( v4 )
free(v4);
free(v3);
result = func0(8, "FREE ELE\n");
}
while ( v1 );
}
return result;
}

original_code:
void DelAllEle(REC_INFO* pEle)
{
    REC_INFO* pEleDel;
    REC_INFO* pEleNext;
    pEleDel = pEle;
    while(pEleDel)
    {
        pEleNext = pEleDel->pNext;
        if(pEleDel->pContent)
        {
            free(pEleDel->pContent);
        }
        free(pEleDel);
        OutString((1<<3), "FREE ELE\n");
        pEleDel = pEleNext;
    }
    return;
}

canonical_original_code:
void DelAllEle(struct REC_INFO_STRU *pEle)
{
    struct REC_INFO_STRU *pEleDel;
    struct REC_INFO_STRU *pEleNext;
    pEleDel = pEle;
    while(pEleDel)
    {
        pEleNext = pEleDel->pNext;
        if(pEleDel->pContent)
        {
            free(pEleDel->pContent);
        }
        free(pEleDel);
        OutString((1<<3), "FREE ELE\n");
        pEleDel = pEleNext;
    }
    return;
}


OutputRecInfo

decompiled_code:
void __fastcall OutputRecInfo(__int64 a1)
{
__int64 i; // rbx

for ( i = a1; i; i = *(_QWORD *)(i + 24) )
{
if ( *(_DWORD *)i )
{
if ( *(_DWORD *)i != 1 )
return;
printf("ELE_TEXT[%s]\n", *(const char **)(i + 8));
}
else
{
printf("ELE_SEPERATOR[%c]\n", (unsigned int)seperator[*(unsigned int *)(i + 16)]);
}
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
__int64 i; // rbx

for ( i = a1; i; i = *(_QWORD *)(i + 24) )
{
if ( *(_DWORD *)i )
{
if ( *(_DWORD *)i != 1 )
return;
printf("ELE_TEXT[%s]\n", *(const char **)(i + 8));
}
else
{
printf("ELE_SEPERATOR[%c]\n", (unsigned int)seperator[*(unsigned int *)(i + 16)]);
}
}
}

original_code:
void OutputRecInfo(REC_INFO* pEle)
{
    while(pEle)
    {
        switch(pEle->type)
        {
            case ELE_TEXT:
                printf("ELE_TEXT[%s]\n", pEle->pContent);
                break;
            case ELE_SEPERATOR:
                printf("ELE_SEPERATOR[%c]\n", seperator[pEle->sep]);
                break;
            default:
                return;
        }
        pEle = pEle->pNext;
    }
    return;
}

canonical_original_code:
void OutputRecInfo(struct REC_INFO_STRU *pEle)
{
    while(pEle)
    {
        switch(pEle->type)
        {
            case ELE_TEXT:
                printf("ELE_TEXT[%s]\n", pEle->pContent);
                break;
            case ELE_SEPERATOR:
                printf("ELE_SEPERATOR[%c]\n", seperator[pEle->sep]);
                break;
            default:
                return;
        }
        pEle = pEle->pNext;
    }
    return;
}


fillBuffer

decompiled_code:
int *__fastcall fillBuffer(float a1)
{
int *result; // rax
int *v2; // rdx

result = (int *)&unk_404144;
do
{
v2 = result;
result[1] = *result;
--result;
}
while ( v2 != &sampleBuffer );
sampleBuffer = LODWORD(a1);
return result;
}

canonical_decompiled_code:
int *__fastcall func7(float a1)
{
int *result; // rax
int *v2; // rdx

result = (int *)&unk_404144;
do
{
v2 = result;
result[1] = *result;
--result;
}
while ( v2 != &sampleBuffer );
sampleBuffer = LODWORD(a1);
return result;
}

original_code:
void fillBuffer(float v){
 for(int i = 51 -1; i>0; i--){
  sampleBuffer[i] = sampleBuffer[i-1];
 }
 sampleBuffer[0] = v;
}

variable_types: v float


rms

decompiled_code:
float __fastcall rms(float *a1, float a2)
{
float v2; // xmm2_4
float v3; // xmm0_4
float *v4; // rax
float *v5; // rdx
float v6; // xmm0_4
float result; // xmm0_4

v2 = a2 * a2;
v3 = (float)((float)(a2 * a2) + a1[179]) - a1[127];
a1[179] = v3;
v4 = a1 + 126;
do
{
v5 = v4;
v4[1] = *v4;
--v4;
}
while ( v5 != a1 );
*a1 = v2;
v6 = v3 * 0.0078125;
if ( v6 < 0.0 )
result = sqrtf(v6);
else
result = fsqrt(v6);
return result;
}

canonical_decompiled_code:
float __fastcall func8(float *a1, float a2)
{
float v2; // xmm2_4
float v3; // xmm0_4
float *v4; // rax
float *v5; // rdx
float v6; // xmm0_4
float result; // xmm0_4

v2 = a2 * a2;
v3 = (float)((float)(a2 * a2) + a1[179]) - a1[127];
a1[179] = v3;
v4 = a1 + 126;
do
{
v5 = v4;
v4[1] = *v4;
--v4;
}
while ( v5 != a1 );
*a1 = v2;
v6 = v3 * 0.0078125;
if ( v6 < 0.0 )
result = sqrtf(v6);
else
result = fsqrt(v6);
return result;
}

original_code:
float rms(float v, struct Filter* filter){
 filter->sum = filter->sum + v*v - filter->squareBuffer[128 -1];
 for(int i = 128 -1; i>0; i--){
  filter->squareBuffer[i] = filter->squareBuffer[i-1];
 }
 filter->squareBuffer[0] = v*v;
 return sqrt(filter->sum/128);
}

canonical_original_code:
float rms(float v, struct Filter *filter){
 filter->sum = filter->sum + v*v - filter->squareBuffer[128 -1];
 for(int i = 128 -1; i>0; i--){
  filter->squareBuffer[i] = filter->squareBuffer[i-1];
 }
 filter->squareBuffer[0] = v*v;
 return sqrt(filter->sum/128);
}

variable_types: struct Filter { float squareBuffer[128]; float coeffBuffer[51]; float sum; } *

return_type: float


generateSample

decompiled_code:
float __fastcall generateSample(float a1)
{
float i; // xmm0_4

for ( i = a1 * 3.1415; i > 0.0; i = i - 6.283 )
;
return cos(i);
}

canonical_decompiled_code:
float __fastcall func10(float a1)
{
float i; // xmm0_4

for ( i = a1 * 3.1415; i > 0.0; i = i - 6.283 )
;
return cos(i);
}

original_code:
float generateSample(float x){
 float y = (3.1415*x);
 while(y>0){
  y-=2*3.1415;
 }
 return cos(y);
}

variable_types: x float

variable_types: y float