Fractalize

decompiled_code:
__int64 __fastcall Fractalize(__int64 a1)
{
double v1; // xmm2_8
double v2; // xmm0_8
double v3; // xmm1_8
int v4; // er9
char v5; // al
__int64 v6; // xmm5_8
__int64 v7; // xmm4_8
char v8; // r8
__int64 v9; // xmm3_8
char v10; // al
char v11; // al
char v12; // al
int v13; // eax
signed int v14; // edx
signed int v15; // ecx
Drawable v16; // rsi
__int64 result; // rax

v1 = *(double *)(a1 + 32);
v2 = *(double *)(a1 + 40);
v3 = *(double *)(a1 + 48);
v4 = *(_DWORD *)(a1 + 8);
InColor = myback;
White = myback;
v5 = *(_BYTE *)(a1 + 1);
v6 = *(_QWORD *)(a1 + 56);
v7 = *(_QWORD *)(a1 + 64);
Black = myfore;
v8 = *(_BYTE *)a1;
v9 = *(_QWORD *)(a1 + 72);
stalks = v5;
v10 = *(_BYTE *)(a1 + 2);
julia = v8;
spikes = v10;
v11 = *(_BYTE *)(a1 + 3);
maxiter = v4;
splat = v11;
v12 = *(_BYTE *)(a1 + 4);
CenterX = *(_QWORD *)&v1;
colscale = v12;
v13 = *(_DWORD *)(a1 + 12);
CenterY = *(_QWORD *)&v2;
width = *(_QWORD *)&v3;
ncolors = v13;
bitmap = v13 == 2;
cr = v6;
ci = v7;
stalkconst = v9;
v14 = *(_DWORD *)(a1 + 16);
v15 = *(_DWORD *)(a1 + 20);
v16 = *(_QWORD *)(a1 + 80);
PixWidth = v14;
PixHeight = v15;
drawer = v16;
*(double *)&right = v1 + 0.5 * v3;
*(double *)&left = v1 - 0.5 * v3;
*(double *)&top = v2 + 0.5 * v3;
*(double *)&bottom = v2 - 0.5 * v3;
*(double *)&height = *(double *)&top - *(double *)⊥
*(double *)&tx = v3 / (double)v14;
*(double *)&ty = (*(double *)&top - *(double *)&bottom) / (double)v15;
*(double *)&edist = (double)v13 / (double)v4;
if ( v8 )
{
Zconst = v6;
*(&Zconst + 1) = v7;
}
if ( !drawn )
{
theImage = XCreatePixmap(disp, v16, v14, v15, disp->screens[(__int64)disp->default_screen].root_depth);
XSetForeground(disp, mygc, myback);
XFillRectangle(disp, theImage, mygc, 0, 0, PixWidth, PixHeight);
}
result = Loops();
drawn = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
double v1; // xmm2_8
double v2; // xmm0_8
double v3; // xmm1_8
int v4; // er9
char v5; // al
__int64 v6; // xmm5_8
__int64 v7; // xmm4_8
char v8; // r8
__int64 v9; // xmm3_8
char v10; // al
char v11; // al
char v12; // al
int v13; // eax
signed int v14; // edx
signed int v15; // ecx
Drawable v16; // rsi
__int64 result; // rax

v1 = *(double *)(a1 + 32);
v2 = *(double *)(a1 + 40);
v3 = *(double *)(a1 + 48);
v4 = *(_DWORD *)(a1 + 8);
InColor = myback;
White = myback;
v5 = *(_BYTE *)(a1 + 1);
v6 = *(_QWORD *)(a1 + 56);
v7 = *(_QWORD *)(a1 + 64);
Black = myfore;
v8 = *(_BYTE *)a1;
v9 = *(_QWORD *)(a1 + 72);
stalks = v5;
v10 = *(_BYTE *)(a1 + 2);
julia = v8;
spikes = v10;
v11 = *(_BYTE *)(a1 + 3);
maxiter = v4;
splat = v11;
v12 = *(_BYTE *)(a1 + 4);
CenterX = *(_QWORD *)&v1;
colscale = v12;
v13 = *(_DWORD *)(a1 + 12);
CenterY = *(_QWORD *)&v2;
width = *(_QWORD *)&v3;
ncolors = v13;
bitmap = v13 == 2;
cr = v6;
ci = v7;
stalkconst = v9;
v14 = *(_DWORD *)(a1 + 16);
v15 = *(_DWORD *)(a1 + 20);
v16 = *(_QWORD *)(a1 + 80);
PixWidth = v14;
PixHeight = v15;
drawer = v16;
*(double *)&right = v1 + 0.5 * v3;
*(double *)&left = v1 - 0.5 * v3;
*(double *)&top = v2 + 0.5 * v3;
*(double *)&bottom = v2 - 0.5 * v3;
*(double *)&height = *(double *)&top - *(double *)⊥
*(double *)&tx = v3 / (double)v14;
*(double *)&ty = (*(double *)&top - *(double *)&bottom) / (double)v15;
*(double *)&edist = (double)v13 / (double)v4;
if ( v8 )
{
Zconst = v6;
*(&Zconst + 1) = v7;
}
if ( !drawn )
{
theImage = XCreatePixmap(disp, v16, v14, v15, disp->screens[(__int64)disp->default_screen].root_depth);
XSetForeground(disp, mygc, myback);
XFillRectangle(disp, theImage, mygc, 0, 0, PixWidth, PixHeight);
}
result = func3();
drawn = 1;
return result;
}

original_code:
void Fractalize (Fract *T)
{
int res;
 InColor = myback;
 Black = myfore;
 White = myback;
 julia = T->Set;
 stalks = T->stalks;
 spikes = T->spikes;
 splat = T->splat;
 colscale = T->colortype;
 maxiter = T->Iterations;
 ncolors = T->NColors;
 bitmap = (ncolors == 2);
 cr = T->ConstR;
 ci = T->ConstI;
 CenterX = T->CenterX;
 CenterY = T->CenterY;
 width = T->Width;
 stalkconst = T->BeneathStalks;
 PixWidth = T->PixWidth;
 PixHeight = T->PixHeight;
 drawer = T->D;
 left = CenterX - (width/2); right=CenterX + (width/2);
 bottom = CenterY - width/2;
 top = CenterY + width/2;
 height = top-bottom;
 tx = width/PixWidth; ty = height/PixHeight;
 edist = ( ( (double) ncolors)/maxiter);
 if (julia) {
  Zconst.r = cr;
  Zconst.i = ci;
  }
 if (!drawn) {
  theImage = XCreatePixmap(disp, drawer, PixWidth, PixHeight,
   ((&((_XPrivDisplay)(disp))->screens[(((_XPrivDisplay)(disp))->default_screen)])->root_depth));
  XSetForeground(disp, mygc, myback);
  XFillRectangle(disp, theImage, mygc,
   0, 0, PixWidth, PixHeight);
  }
 res = Loops();
 drawn = 1;
}

canonical_original_code:
void Fractalize(struct Fract *T)
{
int res;
 InColor = myback;
 Black = myfore;
 White = myback;
 julia = T->Set;
 stalks = T->stalks;
 spikes = T->spikes;
 splat = T->splat;
 colscale = T->colortype;
 maxiter = T->Iterations;
 ncolors = T->NColors;
 bitmap = (ncolors == 2);
 cr = T->ConstR;
 ci = T->ConstI;
 CenterX = T->CenterX;
 CenterY = T->CenterY;
 width = T->Width;
 stalkconst = T->BeneathStalks;
 PixWidth = T->PixWidth;
 PixHeight = T->PixHeight;
 drawer = T->D;
 left = CenterX - (width/2); right=CenterX + (width/2);
 bottom = CenterY - width/2;
 top = CenterY + width/2;
 height = top-bottom;
 tx = width/PixWidth; ty = height/PixHeight;
 edist = ( ( (double) ncolors)/maxiter);
 if (julia) {
  Zconst.r = cr;
  Zconst.i = ci;
  }
 if (!drawn) {
  theImage = XCreatePixmap(disp, drawer, PixWidth, PixHeight,
   ((&((_XPrivDisplay)(disp))->screens[(((_XPrivDisplay)(disp))->default_screen)])->root_depth));
  XSetForeground(disp, mygc, myback);
  XFillRectangle(disp, theImage, mygc,
   0, 0, PixWidth, PixHeight);
  }
 res = Loops();
 drawn = 1;
}

variable_types: struct Fract { char Set; int Iterations; double CenterX; unsigned long D; } *

variable_types: res int


CheckEvents

repo: russellholt/old

decompiled_code:
void CheckEvents()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void CheckEvents()
{
}

canonical_original_code:
void CheckEvents()
{
}

return_type: void


Usage

decompiled_code:
void __noreturn Usage()
{
puts("Usage: mx datafile [line1] [line2]");
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("Usage: mx datafile [line1] [line2]");
exit(1);
}

original_code:
void Usage()
{
 printf("Usage: mx datafile [line1] [line2]\n");
 exit(1);
}


repo: rutles/libregister

original_code:
uint32_t *fnc_pwm(){
  uint32_t *regs;
  regs = regs_map(0x20200000);
  if(regs == ((void *) -1))
    return ((void *) -1);
  fnc_wr(regs, 18, 2);
  munmap((void *)regs, getpagesize());
  regs = regs_map(0x2020C000);
  if(regs == ((void *) -1))
    return ((void *) -1);
  regs[0] |= 0x80;
  return regs;
}

canonical_original_code:
unsigned int *fnc_pwm(){
  unsigned int *regs;
  regs = regs_map(0x20200000);
  if(regs == ((void *) -1))
    return ((void *) -1);
  fnc_wr(regs, 18, 2);
  munmap((void *)regs, getpagesize());
  regs = regs_map(0x2020C000);
  if(regs == ((void *) -1))
    return ((void *) -1);
  regs[0] |= 0x80;
  return regs;
}

variable_types:
regs
unsigned int *

return_type: unsigned int *


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

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

original_code:
void pwm_spc(uint32_t *regs, uint32_t val){
  regs[4] = val;
  usleep(10);
}

canonical_original_code:
void pwm_spc(unsigned int *regs, unsigned int val){
  regs[4] = val;
  usleep(10);
}

variable_types:
val
unsigned int


decompiled_code:
int __fastcall prt_drv(int a1)
{
_DWORD *v1; // rbp
int v2; // eax

v1 = (_DWORD *)regs_map(537919488LL);
v1[11] = a1 | v1[11] & 0xFFFFFFF8 | 0x5A000000;
v2 = getpagesize();
return munmap(v1, v2);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
_DWORD *v1; // rbp
int v2; // eax

v1 = (_DWORD *)regs_map(537919488LL);
v1[11] = a1 | v1[11] & 0xFFFFFFF8 | 0x5A000000;
v2 = getpagesize();
return munmap(v1, v2);
}

original_code:
void prt_drv(int val){
  uint32_t state;
  uint32_t *regs;
  regs = regs_map(0x20100000);
  state = (regs[11] & ~7) | val;
  regs[11] = 0x5A000000 | state;
  munmap((void *)regs, getpagesize());
}

canonical_original_code:
void prt_drv(int val){
  unsigned int state;
  unsigned int *regs;
  regs = regs_map(0x20100000);
  state = (regs[11] & ~7) | val;
  regs[11] = 0x5A000000 | state;
  munmap((void *)regs, getpagesize());
}

variable_types: val int

variable_types:
state
unsigned int


original_code:
void prt_edg(uint32_t *regs, int port, int val){
  if(val & 1)
    regs[19] |= (1 << port);
  else
    regs[19] &= ~(1 << port);
  if(val & 2)
    regs[22] |= (1 << port);
  else
    regs[22] &= ~(1 << port);
}

canonical_original_code:
void prt_edg(unsigned int *regs, int port, int val){
  if(val & 1)
    regs[19] |= (1 << port);
  else
    regs[19] &= ~(1 << port);
  if(val & 2)
    regs[22] |= (1 << port);
  else
    regs[22] &= ~(1 << port);
}

variable_types: port int


decompiled_code:
__int64 __fastcall prt_rd(__int64 a1, char a2)
{
return (*(_DWORD *)(a1 + 52) >> a2) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2)
{
return (*(_DWORD *)(a1 + 52) >> a2) & 1;
}

original_code:
int prt_rd(uint32_t *regs, int port){
  return (regs[13] >> port) & 1;
}

canonical_original_code:
int prt_rd(unsigned int *regs, int port){
  return (regs[13] >> port) & 1;
}

return_type: int


original_code:
int prt_event(uint32_t *regs, int port){
  int ret;
  ret = regs[16] &= ~(1 << port);
  if(ret)
    regs[16] |= (1 << port);
  return ret;
}

canonical_original_code:
int prt_event(unsigned int *regs, int port){
  int ret;
  ret = regs[16] &= ~(1 << port);
  if(ret)
    regs[16] |= (1 << port);
  return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall pwm_sw(_DWORD *a1, int a2)
{
__int64 result; // rax

result = *a1 & 0xFFFFFFFE;
if ( a2 )
result = *a1 | 1u;
*a1 = result;
return result;
}

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

result = *a1 & 0xFFFFFFFE;
if ( a2 )
result = *a1 | 1u;
*a1 = result;
return result;
}

original_code:
void pwm_sw(uint32_t *regs, uint32_t val){
  if(val)
    regs[0] |= 1;
  else
    regs[0] &= ~1;
}

canonical_original_code:
void pwm_sw(unsigned int *regs, unsigned int val){
  if(val)
    regs[0] |= 1;
  else
    regs[0] &= ~1;
}


canonical_original_code:
void clk_frq(unsigned int *regs, unsigned int val){
  unsigned int save;
  int di; int dr; int df;
  di = 19200000 / val;
  dr = 19200000 % val;
  df = (int)((double)dr * 4096.0 / 19200000.0);
  save = regs[28];
  clk_sw(regs, 0);
  regs[29] = 0x5A000000 | (di << 12) | df;
  regs[28] = save;
}

variable_types:
save
unsigned int

variable_types: di int

variable_types: dr int

variable_types: df int


original_code:
int fnc_rd(uint32_t *regs, int port){
  return (regs[port / 10] >> (port % 10) * 3) & 7;
}

canonical_original_code:
int fnc_rd(unsigned int *regs, int port){
  return (regs[port / 10] >> (port % 10) * 3) & 7;
}


decompiled_code:
__int64 fnc_clk()
{
__int64 v0; // rax
void *v1; // rbp
size_t v2; // rsi

v0 = regs_map(538968064LL);
if ( v0 == -1 )
return -1LL;
v1 = (void *)v0;
fnc_wr(v0, 4LL, 4LL);
v2 = getpagesize();
munmap(v1, v2);
return regs_map(537923584LL);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
void *v1; // rbp
size_t v2; // rsi

v0 = regs_map(538968064LL);
if ( v0 == -1 )
return -1LL;
v1 = (void *)v0;
fnc_wr(v0, 4LL, 4LL);
v2 = getpagesize();
munmap(v1, v2);
return regs_map(537923584LL);
}

original_code:
uint32_t *fnc_clk(){
  uint32_t *regs;
  regs = regs_map(0x20200000);
  if(regs == ((void *) -1))
    return ((void *) -1);
  fnc_wr(regs, 4, 4);
  munmap((void *)regs, getpagesize());
  regs = regs_map(0x20101000);
  if(regs == ((void *) -1))
    return ((void *) -1);
  return regs;
}

canonical_original_code:
unsigned int *fnc_clk(){
  unsigned int *regs;
  regs = regs_map(0x20200000);
  if(regs == ((void *) -1))
    return ((void *) -1);
  fnc_wr(regs, 4, 4);
  munmap((void *)regs, getpagesize());
  regs = regs_map(0x20101000);
  if(regs == ((void *) -1))
    return ((void *) -1);
  return regs;
}


decompiled_code:
__int64 __fastcall regs_map(__off_t offset)
{
__int64 v1; // r12
int v2; // eax
int v3; // ebp
int v4; // eax

v1 = -1LL;
v2 = open("/dev/mem", 1052674);
if ( v2 >= 0 )
{
v3 = v2;
v4 = getpagesize();
v1 = (__int64)mmap(0LL, v4, 3, 1, v3, offset);
close(v3);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__off_t offset)
{
__int64 v1; // r12
int v2; // eax
int v3; // ebp
int v4; // eax

v1 = -1LL;
v2 = open("/dev/mem", 1052674);
if ( v2 >= 0 )
{
v3 = v2;
v4 = getpagesize();
v1 = (__int64)mmap(0LL, v4, 3, 1, v3, offset);
close(v3);
}
return v1;
}

original_code:
uint32_t *regs_map(off_t offset){
  int fd;
  void *map;
  fd = open("/dev/mem", 02 | 04010000);
  if(fd < 0)
    return ((void *) -1);
  map = mmap(((void *)0),
    getpagesize(),
    0x1 | 0x2,
    0x01,
    fd,
    offset);
  close(fd);
  return map;
}

canonical_original_code:
unsigned int *regs_map(long offset){
  int fd;
  void *map;
  fd = open("/dev/mem", 02 | 04010000);
  if(fd < 0)
    return ((void *) -1);
  map = mmap(((void *)0),
    getpagesize(),
    0x1 | 0x2,
    0x01,
    fd,
    offset);
  close(fd);
  return map;
}

variable_types: offset long

variable_types: fd int

variable_types:
map
void *


decompiled_code:
__int64 __fastcall prt_pud(__int64 a1, unsigned int a2, int a3)
{
unsigned int v4; // er12
unsigned int v6; // eax

if ( (unsigned int)((__int64 (*)(void))fnc_rd)() )
{
v4 = -1;
v6 = fnc_rd(a1, a2);
printf("GPIO%d FSEL: %d\n", a2, v6);
fwrite("pull up/down set valid only input port.\n", 1uLL, 0x28uLL, stderr);
}
else
{
*(_DWORD *)(a1 + 148) = a3;
v4 = 0;
usleep(1u);
*(_DWORD *)(a1 + 152) = 1 << a2;
usleep(1u);
*(_QWORD *)(a1 + 148) = 0LL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, int a3)
{
unsigned int v4; // er12
unsigned int v6; // eax

if ( (unsigned int)((__int64 (*)(void))fnc_rd)() )
{
v4 = -1;
v6 = fnc_rd(a1, a2);
printf("GPIO%d FSEL: %d\n", a2, v6);
fwrite("pull up/down set valid only input port.\n", 1uLL, 0x28uLL, stderr);
}
else
{
*(_DWORD *)(a1 + 148) = a3;
v4 = 0;
usleep(1u);
*(_DWORD *)(a1 + 152) = 1 << a2;
usleep(1u);
*(_QWORD *)(a1 + 148) = 0LL;
}
return v4;
}

original_code:
int prt_pud(uint32_t *regs, int port, int val){
  if(fnc_rd(regs, port)){
    printf("GPIO%d FSEL: %d\n", port, fnc_rd(regs, port));
    fprintf(stderr, "pull up/down set valid only input port.\n");
    return -1;
  }
  regs[37] = val;
  usleep(1);
  regs[38] = (1 << port);
  usleep(1);
  regs[37] = 0;
  regs[38] = 0;
  return 0;
}

canonical_original_code:
int prt_pud(unsigned int *regs, int port, int val){
  if(fnc_rd(regs, port)){
    printf("GPIO%d FSEL: %d\n", port, fnc_rd(regs, port));
    fprintf(stderr, "pull up/down set valid only input port.\n");
    return -1;
  }
  regs[37] = val;
  usleep(1);
  regs[38] = (1 << port);
  usleep(1);
  regs[37] = 0;
  regs[38] = 0;
  return 0;
}


canonical_original_code:
void clk_sw(unsigned int *regs, int val){
  if(val){
    regs[28] = 0x5A000000 | 0x11;
  } else {
    regs[28] = 0x5A000000 | 0x01;
    while(regs[28] & 0x80);
  }
}


decompiled_code:
__int64 __fastcall prt_wr(__int64 a1, char a2, int a3)
{
__int64 result; // rax

result = (unsigned int)(1 << a2);
if ( a3 )
*(_DWORD *)(a1 + 28) = result;
else
*(_DWORD *)(a1 + 40) = result;
return result;
}

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

result = (unsigned int)(1 << a2);
if ( a3 )
*(_DWORD *)(a1 + 28) = result;
else
*(_DWORD *)(a1 + 40) = result;
return result;
}

original_code:
void prt_wr(uint32_t *regs, int port, int val){
  if(val)
    regs[7] = (1 << port);
  else
    regs[10] = (1 << port);
}

canonical_original_code:
void prt_wr(unsigned int *regs, int port, int val){
  if(val)
    regs[7] = (1 << port);
  else
    regs[10] = (1 << port);
}


decompiled_code:
void __fastcall pwm_mrk(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 20) = a2;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 20) = a2;
}

original_code:
void pwm_mrk(uint32_t *regs, uint32_t value){
  regs[5] = value;
}

canonical_original_code:
void pwm_mrk(unsigned int *regs, unsigned int value){
  regs[5] = value;
}

variable_types:
value
unsigned int


repo: rutles/remocon

decompiled_code:
int __fastcall rc_pfree(unsigned int a1)
{
int v1; // ebp
size_t v2; // rax
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = open("/sys/class/gpio/unexport", 1);
sprintf(v4, "%d", a1);
v2 = strlen(v4);
write(v1, v4, v2);
return close(v1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
int v1; // ebp
size_t v2; // rax
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = open("/sys/class/gpio/unexport", 1);
sprintf(v4, "%d", a1);
v2 = strlen(v4);
write(v1, v4, v2);
return close(v1);
}

original_code:
void rc_pfree(int port){
  int fd;
  char buf[40];
  fd = open("/sys/class/gpio/unexport", 01);
  sprintf(buf, "%d", port);
  write(fd, buf, strlen(buf));
  close(fd);
}

variable_types:
buf
char [40]


original_code:
int rc_next(struct irspec *ir){
  char c;
  int ret;
  long temp;
  struct timespec now;
  struct pollfd pfd;
  pfd.fd = ir->fd;
  pfd.events = 0x002;
  lseek(ir->fd, 0, 0);
  ret = poll(&pfd, 1, 100);
  clock_gettime(4, &now);
  read(ir->fd, &c, 1);
  if(ret <= 0)
    return ret;
  ir->gap = ((now.tv_sec - ir->origin.tv_sec) * 1000000 + (now.tv_nsec - ir->origin.tv_nsec) / 1000);
  ir->interval = ir->gap - ir->last;
  lseek(ir->fd, 0, 0);
  ret = poll(&pfd, 1, 2000);
  clock_gettime(4, &now);
  ir->last = ((now.tv_sec - ir->origin.tv_sec) * 1000000 + (now.tv_nsec - ir->origin.tv_nsec) / 1000);
  read(ir->fd, &c, 1);
  if(ret <= 0)
    return ret;
  lseek(ir->fd, 0, 0);
  ret = poll(&pfd, 1, 10);
  clock_gettime(4, &now);
  read(ir->fd, &c, 1);
  temp = ((now.tv_sec - ir->origin.tv_sec) * 1000000 + (now.tv_nsec - ir->origin.tv_nsec) / 1000);
  ir->repeat = temp - ir->last;
  ir->last = temp;
  return ret;
}

variable_types: struct irspec { struct timespec { long tv_sec; long tv_nsec; } origin; int fd; long lon; long repeat; int length; long *son; int count; unsigned char *code; long last; long interval; long gap; } *

variable_types: c char

variable_types: temp long

variable_types: struct pollfd { int fd; short events; short revents; }

user_defined_types: struct irspec { struct timespec origin; int fd; long lon; long repeat; int length; long *son; int count; unsigned char *code; long last; long interval; long gap; }


decompiled_code:
__int64 __fastcall rc_analyze(unsigned int a1, __int64 a2)
{
int v3; // ebp
void *v4; // rax
char *v5; // r13
__int64 v6; // rax
__int64 v7; // rsi
__int64 v8; // rcx
char *v9; // r15
char *v10; // rax
__int64 v11; // r8
__int64 v12; // rax
__int64 v13; // rsi
__int64 v14; // rdx
__int64 v15; // rcx
__int64 v16; // rdx
__int64 v17; // rax
bool v18; // cl
int v19; // eax
_QWORD *ptr; // [rsp+8h] [rbp-20B0h]
void *ptra; // [rsp+8h] [rbp-20B0h]
char v23[16]; // [rsp+10h] [rbp-20A8h] BYREF
int fd; // [rsp+20h] [rbp-2098h]
__int64 v25; // [rsp+28h] [rbp-2090h]
__int64 v26; // [rsp+30h] [rbp-2088h]
__int64 v27; // [rsp+38h] [rbp-2080h]
int v28; // [rsp+40h] [rbp-2078h]
char *v29; // [rsp+48h] [rbp-2070h]
char *v30; // [rsp+50h] [rbp-2068h]
int v31; // [rsp+58h] [rbp-2060h]
__int64 v32; // [rsp+60h] [rbp-2058h]
__int64 v33; // [rsp+70h] [rbp-2048h]
__int64 v34; // [rsp+78h] [rbp-2040h]
char src[4096]; // [rsp+80h] [rbp-2038h] BYREF
char v36[4152]; // [rsp+1080h] [rbp-1038h] BYREF

fd = rc_passign();
if ( fd <= 0 )
{
fwrite("Port invalid.\n", 1uLL, 0xEuLL, stderr);
return 0xFFFFFFFFLL;
}
v29 = src;
v30 = v36;
if ( (int)rc_start(v23) <= 0 )
{
fwrite("Illegal signal format.\n", 1uLL, 0x17uLL, stderr);
close(fd);
rc_pfree(a1);
return 0xFFFFFFFFLL;
}
rc_record(v23);
v3 = v28;
if ( (int)rc_next(v23) > 0 )
{
if ( v27 >= 8 * v26 / 10 && v27 <= 12 * v26 / 10 )
{
v32 = *(_QWORD *)(a2 + 88);
rc_decode(v23);
*(_DWORD *)(a2 + 48) = 1;
goto LABEL_8;
}
fprintf(stderr, "Repeat code was found. 2nd signal was reduced.\nLeader off: %dusec, standard: %dusec.\n", v27, v26);
}
*(_DWORD *)(a2 + 48) = 0;
LABEL_8:
close(fd);
rc_pfree(a1);
*(_QWORD *)a2 = v25;
*(_QWORD *)(a2 + 8) = v26;
v4 = calloc(v3, 8uLL);
if ( v3 <= 0 )
{
ptra = v4;
*(_QWORD *)(a2 + 24) = rc_center(v4, (unsigned int)v3);
*(_QWORD *)(a2 + 32) = rc_center(ptra, 0LL);
*(_QWORD *)(a2 + 40) = rc_center(ptra, 0LL);
free(ptra);
}
else
{
v5 = v36;
ptr = memcpy(v4, src, 8LL * (unsigned int)v3);
v6 = rc_center(ptr, (unsigned int)v3);
v7 = 0LL;
*(_QWORD *)(a2 + 24) = v6;
v8 = 2 * v6;
v9 = &v36[8 * (v3 - 1) + 8];
v10 = v36;
do
{
if ( v8 < *(_QWORD *)v10 )
{
v11 = (int)v7;
v7 = (unsigned int)(v7 + 1);
ptr[v11] = *(_QWORD *)v10;
}
v10 += 8;
}
while ( v9 != v10 );
v12 = rc_center(ptr, v7);
v13 = 0LL;
*(_QWORD *)(a2 + 32) = v12;
v14 = 2LL * *(_QWORD *)(a2 + 24);
do
{
if ( v14 >= *(_QWORD *)v5 )
{
v15 = (int)v13;
v13 = (unsigned int)(v13 + 1);
ptr[v15] = *(_QWORD *)v5;
}
v5 += 8;
}
while ( v5 != v9 );
*(_QWORD *)(a2 + 40) = rc_center(ptr, v13);
free(ptr);
v16 = 0LL;
do
{
v17 = (int)v16 >> 3;
*(_BYTE *)(v17 + *(_QWORD *)(a2 + 80)) *= 2;
v18 = 2LL * *(_QWORD *)(a2 + 24) < *(_QWORD *)&v36[8 * v16++];
*(_BYTE *)(*(_QWORD *)(a2 + 80) + v17) |= v18;
}
while ( v3 != v16 );
}
v19 = v3 + 14;
if ( v3 + 7 >= 0 )
v19 = v3 + 7;
*(_DWORD *)(a2 + 72) = v19 >> 3;
if ( (v3 & 7) != 0 )
fwrite("1st shot is not filled with bit\n", 1uLL, 0x20uLL, stderr);
if ( *(_DWORD *)(a2 + 48) )
{
*(_QWORD *)(a2 + 64) = v33;
*(_QWORD *)(a2 + 56) = v34;
*(_DWORD *)(a2 + 76) = v31;
if ( (v28 & 7) != 0 )
fwrite("2nd shot is not filled with bit\n", 1uLL, 0x20uLL, stderr);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
int v3; // ebp
void *v4; // rax
char *v5; // r13
__int64 v6; // rax
__int64 v7; // rsi
__int64 v8; // rcx
char *v9; // r15
char *v10; // rax
__int64 v11; // r8
__int64 v12; // rax
__int64 v13; // rsi
__int64 v14; // rdx
__int64 v15; // rcx
__int64 v16; // rdx
__int64 v17; // rax
bool v18; // cl
int v19; // eax
_QWORD *ptr; // [rsp+8h] [rbp-20B0h]
void *ptra; // [rsp+8h] [rbp-20B0h]
char v23[16]; // [rsp+10h] [rbp-20A8h] BYREF
int fd; // [rsp+20h] [rbp-2098h]
__int64 v25; // [rsp+28h] [rbp-2090h]
__int64 v26; // [rsp+30h] [rbp-2088h]
__int64 v27; // [rsp+38h] [rbp-2080h]
int v28; // [rsp+40h] [rbp-2078h]
char *v29; // [rsp+48h] [rbp-2070h]
char *v30; // [rsp+50h] [rbp-2068h]
int v31; // [rsp+58h] [rbp-2060h]
__int64 v32; // [rsp+60h] [rbp-2058h]
__int64 v33; // [rsp+70h] [rbp-2048h]
__int64 v34; // [rsp+78h] [rbp-2040h]
char src[4096]; // [rsp+80h] [rbp-2038h] BYREF
char v36[4152]; // [rsp+1080h] [rbp-1038h] BYREF

fd = rc_passign();
if ( fd <= 0 )
{
fwrite("Port invalid.\n", 1uLL, 0xEuLL, stderr);
return 0xFFFFFFFFLL;
}
v29 = src;
v30 = v36;
if ( (int)rc_start(v23) <= 0 )
{
fwrite("Illegal signal format.\n", 1uLL, 0x17uLL, stderr);
close(fd);
rc_pfree(a1);
return 0xFFFFFFFFLL;
}
rc_record(v23);
v3 = v28;
if ( (int)rc_next(v23) > 0 )
{
if ( v27 >= 8 * v26 / 10 && v27 <= 12 * v26 / 10 )
{
v32 = *(_QWORD *)(a2 + 88);
rc_decode(v23);
*(_DWORD *)(a2 + 48) = 1;
goto LABEL_8;
}
fprintf(stderr, "Repeat code was found. 2nd signal was reduced.\nLeader off: %dusec, standard: %dusec.\n", v27, v26);
}
*(_DWORD *)(a2 + 48) = 0;
LABEL_8:
close(fd);
rc_pfree(a1);
*(_QWORD *)a2 = v25;
*(_QWORD *)(a2 + 8) = v26;
v4 = calloc(v3, 8uLL);
if ( v3 <= 0 )
{
ptra = v4;
*(_QWORD *)(a2 + 24) = rc_center(v4, (unsigned int)v3);
*(_QWORD *)(a2 + 32) = rc_center(ptra, 0LL);
*(_QWORD *)(a2 + 40) = rc_center(ptra, 0LL);
free(ptra);
}
else
{
v5 = v36;
ptr = memcpy(v4, src, 8LL * (unsigned int)v3);
v6 = rc_center(ptr, (unsigned int)v3);
v7 = 0LL;
*(_QWORD *)(a2 + 24) = v6;
v8 = 2 * v6;
v9 = &v36[8 * (v3 - 1) + 8];
v10 = v36;
do
{
if ( v8 < *(_QWORD *)v10 )
{
v11 = (int)v7;
v7 = (unsigned int)(v7 + 1);
ptr[v11] = *(_QWORD *)v10;
}
v10 += 8;
}
while ( v9 != v10 );
v12 = rc_center(ptr, v7);
v13 = 0LL;
*(_QWORD *)(a2 + 32) = v12;
v14 = 2LL * *(_QWORD *)(a2 + 24);
do
{
if ( v14 >= *(_QWORD *)v5 )
{
v15 = (int)v13;
v13 = (unsigned int)(v13 + 1);
ptr[v15] = *(_QWORD *)v5;
}
v5 += 8;
}
while ( v5 != v9 );
*(_QWORD *)(a2 + 40) = rc_center(ptr, v13);
free(ptr);
v16 = 0LL;
do
{
v17 = (int)v16 >> 3;
*(_BYTE *)(v17 + *(_QWORD *)(a2 + 80)) *= 2;
v18 = 2LL * *(_QWORD *)(a2 + 24) < *(_QWORD *)&v36[8 * v16++];
*(_BYTE *)(*(_QWORD *)(a2 + 80) + v17) |= v18;
}
while ( v3 != v16 );
}
v19 = v3 + 14;
if ( v3 + 7 >= 0 )
v19 = v3 + 7;
*(_DWORD *)(a2 + 72) = v19 >> 3;
if ( (v3 & 7) != 0 )
fwrite("1st shot is not filled with bit\n", 1uLL, 0x20uLL, stderr);
if ( *(_DWORD *)(a2 + 48) )
{
*(_QWORD *)(a2 + 64) = v33;
*(_QWORD *)(a2 + 56) = v34;
*(_DWORD *)(a2 + 76) = v31;
if ( (v28 & 7) != 0 )
fwrite("2nd shot is not filled with bit\n", 1uLL, 0x20uLL, stderr);
}
return 0LL;
}

original_code:
int rc_analyze(int port, struct rcspec *rc){
  struct irspec ir;
  int i;
  int ret;
  int length;
  int index;
  long son[512], soff[512];
  long *work;
  ir.fd = rc_passign(port);
  if(ir.fd <= 0){
    fprintf(stderr, "Port invalid.\n");
    return -1;
  }
  ir.son = son;
  ir.soff = soff;
  ret = rc_start(&ir);
  if(ret <= 0){
    fprintf(stderr, "Illegal signal format.\n");
    close(ir.fd);
    rc_pfree(port);
    return -1;
  }
  rc_record(&ir);
  length = ir.length;
  ret = rc_next(&ir);
  if(ret <= 0){
    rc->multi = 0;
  }
  else
  if((ir.repeat < ir.loff * 8 / 10) ||
  (ir.repeat > ir.loff * 12 / 10)){
    fprintf(stderr, "Repeat code was found. 2nd signal was reduced.\n"
    "Leader off: %dusec, standard: %dusec.\n", ir.repeat, ir.loff);
    rc->multi = 0;
  } else {
    ir.code = rc->code2;
    rc_decode(&ir);
    rc->multi = 1;
  }
  close(ir.fd);
  rc_pfree(port);
  rc->lon = ir.lon;
  rc->loff = ir.loff;
  work = (long *)calloc(length, sizeof(long));
  for(i = 0; i < length; i++)
    work[i] = son[i];
  rc->t = rc_center(work, length);
  index = 0;
  for(i = 0; i < length; i++){
    if(rc->t * 2 < soff[i]){
      work[index++] = soff[i];
    }
  }
  rc->h = rc_center(work, index);
  index = 0;
  for(i = 0; i < length; i++){
    if(rc->t * 2 >= soff[i]){
      work[index++] = soff[i];
    }
  }
  rc->l = rc_center(work, index);
  free(work);
  for(i = 0; i < length; i++){
    rc->code1[i / 8] <<= 1;
    rc->code1[i / 8] |= (rc->t * 2 < soff[i]);
  }
  rc->count1 = (length + 7) / 8;
  if(length % 8)
    fprintf(stderr, "1st shot is not filled with bit\n");
  if(rc->multi){
    rc->interval = ir.interval;
    rc->gap = ir.gap;
    rc->count2 = ir.count;
    if(ir.length % 8)
      fprintf(stderr, "2nd shot is not filled with bit\n");
  }
  return 0;
}

canonical_original_code:
int rc_analyze(int port, struct rcspec *rc){
  struct irspec ir;
  int i;
  int ret;
  int length;
  int index;
  long son[512]; long soff[512];
  long *work;
  ir.fd = rc_passign(port);
  if(ir.fd <= 0){
    fprintf(stderr, "Port invalid.\n");
    return -1;
  }
  ir.son = son;
  ir.soff = soff;
  ret = rc_start(&ir);
  if(ret <= 0){
    fprintf(stderr, "Illegal signal format.\n");
    close(ir.fd);
    rc_pfree(port);
    return -1;
  }
  rc_record(&ir);
  length = ir.length;
  ret = rc_next(&ir);
  if(ret <= 0){
    rc->multi = 0;
  }
  else
  if((ir.repeat < ir.loff * 8 / 10) ||
  (ir.repeat > ir.loff * 12 / 10)){
    fprintf(stderr, "Repeat code was found. 2nd signal was reduced.\n"
    "Leader off: %dusec, standard: %dusec.\n", ir.repeat, ir.loff);
    rc->multi = 0;
  } else {
    ir.code = rc->code2;
    rc_decode(&ir);
    rc->multi = 1;
  }
  close(ir.fd);
  rc_pfree(port);
  rc->lon = ir.lon;
  rc->loff = ir.loff;
  work = (long *)calloc(length, sizeof(long));
  for(i = 0; i < length; i++)
    work[i] = son[i];
  rc->t = rc_center(work, length);
  index = 0;
  for(i = 0; i < length; i++){
    if(rc->t * 2 < soff[i]){
      work[index++] = soff[i];
    }
  }
  rc->h = rc_center(work, index);
  index = 0;
  for(i = 0; i < length; i++){
    if(rc->t * 2 >= soff[i]){
      work[index++] = soff[i];
    }
  }
  rc->l = rc_center(work, index);
  free(work);
  for(i = 0; i < length; i++){
    rc->code1[i / 8] <<= 1;
    rc->code1[i / 8] |= (rc->t * 2 < soff[i]);
  }
  rc->count1 = (length + 7) / 8;
  if(length % 8)
    fprintf(stderr, "1st shot is not filled with bit\n");
  if(rc->multi){
    rc->interval = ir.interval;
    rc->gap = ir.gap;
    rc->count2 = ir.count;
    if(ir.length % 8)
      fprintf(stderr, "2nd shot is not filled with bit\n");
  }
  return 0;
}

variable_types: struct rcspec { long lon; long repeat; long t; long h; long l; int multi; long gap; long interval; int count1; unsigned char *code1; } *

variable_types: struct irspec { struct timespec { long tv_sec; long tv_nsec; } origin; int fd; long lon; long repeat; int length; long *son; int count; unsigned char *code; long last; long interval; long gap; }

variable_types: i int

variable_types: length int

variable_types: index int

variable_types:
son
long [512]

variable_types:
soff
long [512]

variable_types:
work
long *


decompiled_code:
__int64 __fastcall rc_start(struct timespec *tp)
{
int v2; // edi
__syscall_slong_t v3; // rax
unsigned int v4; // er12
__syscall_slong_t v5; // rax
__int64 v6; // rsi
__int64 v7; // rdx
__int64 result; // rax
__syscall_slong_t v9; // rdx
char buf; // [rsp+7h] [rbp-31h] BYREF
struct pollfd fds; // [rsp+8h] [rbp-30h] BYREF
struct timespec tpa; // [rsp+10h] [rbp-28h] BYREF

v2 = tp[1].tv_sec;
fds.events = 2;
fds.fd = v2;
while ( 1 )
{
lseek(v2, 0LL, 0);
poll(&fds, 1uLL, -1);
clock_gettime(4, tp);
read(tp[1].tv_sec, &buf, 1uLL);
if ( buf != 49 )
{
lseek(tp[1].tv_sec, 0LL, 0);
poll(&fds, 1uLL, -1);
clock_gettime(4, &tpa);
read(tp[1].tv_sec, &buf, 1uLL);
v3 = 1000000 * (tpa.tv_sec - tp->tv_sec) + (tpa.tv_nsec - tp->tv_nsec) / 1000;
tp[1].tv_nsec = v3;
if ( v3 > 1999 )
break;
}
v2 = tp[1].tv_sec;
}
lseek(tp[1].tv_sec, 0LL, 0);
v4 = poll(&fds, 1uLL, 10);
clock_gettime(4, &tpa);
read(tp[1].tv_sec, &buf, 1uLL);
v5 = tpa.tv_nsec - tp->tv_nsec;
v6 = v5 >> 63;
v7 = (unsigned __int128)(0x20C49BA5E353F7CFLL * (__int128)v5) >> 64;
result = v4;
v9 = 1000000 * (tpa.tv_sec - tp->tv_sec) + (v7 >> 7) - v6;
tp[5].tv_nsec = v9;
tp[2].tv_sec = v9 - tp[1].tv_nsec;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(struct timespec *tp)
{
int v2; // edi
__syscall_slong_t v3; // rax
unsigned int v4; // er12
__syscall_slong_t v5; // rax
__int64 v6; // rsi
__int64 v7; // rdx
__int64 result; // rax
__syscall_slong_t v9; // rdx
char buf; // [rsp+7h] [rbp-31h] BYREF
struct pollfd fds; // [rsp+8h] [rbp-30h] BYREF
struct timespec tpa; // [rsp+10h] [rbp-28h] BYREF

v2 = tp[1].tv_sec;
fds.events = 2;
fds.fd = v2;
while ( 1 )
{
lseek(v2, 0LL, 0);
poll(&fds, 1uLL, -1);
clock_gettime(4, tp);
read(tp[1].tv_sec, &buf, 1uLL);
if ( buf != 49 )
{
lseek(tp[1].tv_sec, 0LL, 0);
poll(&fds, 1uLL, -1);
clock_gettime(4, &tpa);
read(tp[1].tv_sec, &buf, 1uLL);
v3 = 1000000 * (tpa.tv_sec - tp->tv_sec) + (tpa.tv_nsec - tp->tv_nsec) / 1000;
tp[1].tv_nsec = v3;
if ( v3 > 1999 )
break;
}
v2 = tp[1].tv_sec;
}
lseek(tp[1].tv_sec, 0LL, 0);
v4 = poll(&fds, 1uLL, 10);
clock_gettime(4, &tpa);
read(tp[1].tv_sec, &buf, 1uLL);
v5 = tpa.tv_nsec - tp->tv_nsec;
v6 = v5 >> 63;
v7 = (unsigned __int128)(0x20C49BA5E353F7CFLL * (__int128)v5) >> 64;
result = v4;
v9 = 1000000 * (tpa.tv_sec - tp->tv_sec) + (v7 >> 7) - v6;
tp[5].tv_nsec = v9;
tp[2].tv_sec = v9 - tp[1].tv_nsec;
return result;
}

original_code:
int rc_start(struct irspec *ir){
  char c;
  int ret;
  struct timespec now;
  struct pollfd pfd;
  pfd.fd = ir->fd;
  pfd.events = 0x002;
  do{
    do{
      lseek(ir->fd, 0, 0);
      poll(&pfd, 1, -1);
      clock_gettime(4, &ir->origin);
      read(ir->fd, &c, 1);
    } while (c == '1');
    lseek(ir->fd, 0, 0);
    poll(&pfd, 1, -1);
    clock_gettime(4, &now);
    read(ir->fd, &c, 1);
    ir->lon = ((now.tv_sec - ir->origin.tv_sec) * 1000000 + (now.tv_nsec - ir->origin.tv_nsec) / 1000);
  } while(ir->lon < 2000);
  lseek(ir->fd, 0, 0);
  ret = poll(&pfd, 1, 10);
  clock_gettime(4, &now);
  read(ir->fd, &c, 1);
  ir->last = ((now.tv_sec - ir->origin.tv_sec) * 1000000 + (now.tv_nsec - ir->origin.tv_nsec) / 1000);
  ir->loff = ir->last - ir->lon;
  return ret;
}

variable_types: ret int

variable_types: struct timespec { long tv_sec; long tv_nsec; }

user_defined_types: struct pollfd { int fd; short events; short revents; }


original_code:
uint32_t *regs_map(off_t offset){
  int fd;
  void *map;
  fd = open("/dev/mem", 02 | 04010000);
  if(fd < 0)
    return (uint32_t *)((void *) -1);
  map = mmap(((void *)0),
    getpagesize(),
    0x1 | 0x2,
    0x01,
    fd,
    offset);
  close(fd);
  return (uint32_t *)map;
}

canonical_original_code:
unsigned int *regs_map(long offset){
  int fd;
  void *map;
  fd = open("/dev/mem", 02 | 04010000);
  if(fd < 0)
    return (unsigned int *)((void *) -1);
  map = mmap(((void *)0),
    getpagesize(),
    0x1 | 0x2,
    0x01,
    fd,
    offset);
  close(fd);
  return (unsigned int *)map;
}

variable_types: offset long

variable_types: fd int

variable_types:
map
void *


variable_types:
regs
unsigned int *

variable_types: val int


decompiled_code:
__int64 __fastcall clk_frq(__int64 a1)
{
int v1; // edx
unsigned int v2; // er8
unsigned __int64 v3; // rtt
int v4; // ecx
__int64 result; // rax

clk_sw(a1, 0);
LODWORD(v3) = 19200000;
HIDWORD(v3) = v1;
*(_DWORD *)(a1 + 112) = v4;
result = (int)((double)(int)(v3 % v2) * 4096.0 / 19200000.0) | ((unsigned int)(v3 / v2) << 12) | 0x5A000000;
*(_DWORD *)(a1 + 116) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // edx
unsigned int v2; // er8
unsigned __int64 v3; // rtt
int v4; // ecx
__int64 result; // rax

func2(a1, 0);
LODWORD(v3) = 19200000;
HIDWORD(v3) = v1;
*(_DWORD *)(a1 + 112) = v4;
result = (int)((double)(int)(v3 % v2) * 4096.0 / 19200000.0) | ((unsigned int)(v3 / v2) << 12) | 0x5A000000;
*(_DWORD *)(a1 + 116) = result;
return result;
}

variable_types:
val
unsigned int

variable_types:
save
unsigned int

variable_types: di int

variable_types: dr int

variable_types: df int


decompiled_code:
__int64 fnc_clk()
{
__int64 v0; // rax
void *v1; // rbp
int v2; // eax

v0 = regs_map(538968064LL);
if ( v0 == -1 )
return -1LL;
v1 = (void *)v0;
fnc_wr(v0, 4, 4);
v2 = getpagesize();
munmap(v1, v2);
return regs_map(537923584LL);
}

original_code:
uint32_t *fnc_clk(){
  uint32_t *regs;
  regs = regs_map(0x20200000);
  if(regs == ((void *) -1))
    return (uint32_t *)((void *) -1);
  fnc_wr(regs, 4, 4);
  munmap((void *)regs, getpagesize());
  regs = regs_map(0x20101000);
  if(regs == ((void *) -1))
    return (uint32_t *)((void *) -1);
  return regs;
}

canonical_original_code:
unsigned int *fnc_clk(){
  unsigned int *regs;
  regs = regs_map(0x20200000);
  if(regs == ((void *) -1))
    return (unsigned int *)((void *) -1);
  fnc_wr(regs, 4, 4);
  munmap((void *)regs, getpagesize());
  regs = regs_map(0x20101000);
  if(regs == ((void *) -1))
    return (unsigned int *)((void *) -1);
  return regs;
}


original_code:
int rc_shot(struct rcspec *rc){
  int i, j;
  int ret;
  uint32_t *regs;
  uint8_t code;
  struct timespec org;
  regs = fnc_clk();
  if(regs == ((void *) -1)){
    fprintf(stderr, "fail to get registers map. %s\n", strerror((*__errno_location ())));
    return -1;
  }
  clk_frq(regs, 38000);
  clk_sw(regs, 0);
  clock_gettime(1, &org);
  clk_sw(regs, 1);
  org.tv_nsec += (rc->lon * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  clk_sw(regs, 0);
  org.tv_nsec += (rc->loff * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  for(i = 0; i < rc->count1; i++){
    code = rc->code1[i];
    for(j = 0; j < 8; j++){
      clk_sw(regs, 1);
      org.tv_nsec += (rc->t * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
      clk_sw(regs, 0);
      if(code & 0x80){
        org.tv_nsec += (rc->h * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
      } else {
        org.tv_nsec += (rc->l * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
      }
      code <<= 1;
    }
  }
  clk_sw(regs, 1);
  org.tv_nsec += (rc->t * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  clk_sw(regs, 0);
  if(!rc->multi){
    ret = munmap((void *)regs, getpagesize());
    return ret;
  }
  org.tv_nsec += (rc->interval * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  clk_sw(regs, 1);
  org.tv_nsec += (rc->lon * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  clk_sw(regs, 0);
  org.tv_nsec += (rc->loff * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  for(i = 0; i < rc->count2; i++){
    code = rc->code2[i];
    for(j = 0; j < 8; j++){
      clk_sw(regs, 1);
      org.tv_nsec += (rc->t * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
      clk_sw(regs, 0);
      if(code & 0x80){
        org.tv_nsec += (rc->h * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
      } else {
        org.tv_nsec += (rc->l * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
      }
      code <<= 1;
    }
  }
  clk_sw(regs, 1);
  org.tv_nsec += (rc->t * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  clk_sw(regs, 0);
  ret = munmap((void *)regs, getpagesize());
  return ret;
}

canonical_original_code:
int rc_shot(struct rcspec *rc){
  int i; int j;
  int ret;
  unsigned int *regs;
  unsigned char code;
  struct timespec org;
  regs = fnc_clk();
  if(regs == ((void *) -1)){
    fprintf(stderr, "fail to get registers map. %s\n", strerror((*__errno_location ())));
    return -1;
  }
  clk_frq(regs, 38000);
  clk_sw(regs, 0);
  clock_gettime(1, &org);
  clk_sw(regs, 1);
  org.tv_nsec += (rc->lon * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  clk_sw(regs, 0);
  org.tv_nsec += (rc->loff * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  for(i = 0; i < rc->count1; i++){
    code = rc->code1[i];
    for(j = 0; j < 8; j++){
      clk_sw(regs, 1);
      org.tv_nsec += (rc->t * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
      clk_sw(regs, 0);
      if(code & 0x80){
        org.tv_nsec += (rc->h * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
      } else {
        org.tv_nsec += (rc->l * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
      }
      code <<= 1;
    }
  }
  clk_sw(regs, 1);
  org.tv_nsec += (rc->t * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  clk_sw(regs, 0);
  if(!rc->multi){
    ret = munmap((void *)regs, getpagesize());
    return ret;
  }
  org.tv_nsec += (rc->interval * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  clk_sw(regs, 1);
  org.tv_nsec += (rc->lon * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  clk_sw(regs, 0);
  org.tv_nsec += (rc->loff * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  for(i = 0; i < rc->count2; i++){
    code = rc->code2[i];
    for(j = 0; j < 8; j++){
      clk_sw(regs, 1);
      org.tv_nsec += (rc->t * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
      clk_sw(regs, 0);
      if(code & 0x80){
        org.tv_nsec += (rc->h * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
      } else {
        org.tv_nsec += (rc->l * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
      }
      code <<= 1;
    }
  }
  clk_sw(regs, 1);
  org.tv_nsec += (rc->t * 1000); if(org.tv_nsec >= 1000000000){ org.tv_nsec -= 1000000000; org.tv_sec += 1; } clock_nanosleep(1, 1, &org, ((void *)0));;
  clk_sw(regs, 0);
  ret = munmap((void *)regs, getpagesize());
  return ret;
}

variable_types: struct rcspec { long lon; long repeat; long t; long h; long l; int multi; long gap; long interval; int count1; unsigned char *code1; } *

variable_types: i int

variable_types: j int

variable_types:
code
unsigned char

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


original_code:
int rc_receive(int fd, struct rcspec *rc){
  struct irspec ir;
  int ret;
  ir.fd = fd;
  ir.code = rc->code1;
  ret = rc_start(&ir);
  if(ret <= 0){
    return -1;
  }
  rc_decode(&ir);
  rc->count1 = ir.count;
  ret = rc_next(&ir);
  if(ret <= 0){
    rc->multi = 0;
  }
  else
  if((ir.repeat < ir.loff * 8 / 10) ||
  (ir.repeat > ir.loff * 12 / 10)){
    rc->multi = 0;
  } else {
    ir.code = rc->code2;
    rc_decode(&ir);
    rc->multi = 1;
    rc->count2 = ir.count;
  }
  return 0;
}

variable_types: struct irspec { struct timespec { long tv_sec; long tv_nsec; } origin; int fd; long lon; long repeat; int length; long *son; int count; unsigned char *code; long last; long interval; long gap; }

user_defined_types: struct rcspec { long lon; long repeat; long t; long h; long l; int multi; long gap; long interval; int count1; unsigned char *code1; }


decompiled_code:
__int64 __fastcall rc_getopt(int argc, char **argv, __int64 a3)
{
char *v3; // r14
unsigned int v4; // er13
signed int v6; // eax
int v7; // eax
int v8; // eax
__int64 result; // rax

v3 = 0LL;
v4 = 0;
*(_QWORD *)(a3 + 8) = "noname";
v6 = (unsigned int)get_current_dir_name();
*(_DWORD *)(a3 + 24) = 0;
*(_QWORD *)(a3 + 16) = v6;
while ( 1 )
{
v7 = getopt_long(argc, argv, "g:n:d:l", &long_options_0, 0LL);
if ( v7 == -1 )
break;
if ( v7 == 108 )
{
*(_DWORD *)(a3 + 24) = 1;
}
else if ( v7 > 108 )
{
if ( v7 == 110 )
*(_QWORD *)(a3 + 8) = optarg;
else
LABEL_10:
v4 = 1;
}
else if ( v7 == 100 )
{
free(*(void **)(a3 + 16));
*(_QWORD *)(a3 + 16) = optarg;
}
else
{
if ( v7 != 103 )
goto LABEL_10;
v3 = optarg;
}
}
if ( v4 )
{
v4 = -1;
fwrite("unknown option found.\n", 1uLL, 0x16uLL, stderr);
LABEL_17:
result = v4;
}
else if ( v3 )
{
v8 = atoi(v3);
if ( v8 )
{
*(_DWORD *)a3 = v8;
goto LABEL_17;
}
*(_DWORD *)a3 = 25;
fprintf(stderr, "GPIO number %s is invalid.\n", v3);
fwrite("port was set GPIO25.\n", 1uLL, 0x15uLL, stderr);
result = 0LL;
}
else
{
result = 0LL;
*(_DWORD *)a3 = 25;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv, __int64 a3)
{
char *v3; // r14
unsigned int v4; // er13
signed int v6; // eax
int v7; // eax
int v8; // eax
__int64 result; // rax

v3 = 0LL;
v4 = 0;
*(_QWORD *)(a3 + 8) = "noname";
v6 = (unsigned int)get_current_dir_name();
*(_DWORD *)(a3 + 24) = 0;
*(_QWORD *)(a3 + 16) = v6;
while ( 1 )
{
v7 = getopt_long(argc, argv, "g:n:d:l", &long_options_0, 0LL);
if ( v7 == -1 )
break;
if ( v7 == 108 )
{
*(_DWORD *)(a3 + 24) = 1;
}
else if ( v7 > 108 )
{
if ( v7 == 110 )
*(_QWORD *)(a3 + 8) = optarg;
else
LABEL_10:
v4 = 1;
}
else if ( v7 == 100 )
{
free(*(void **)(a3 + 16));
*(_QWORD *)(a3 + 16) = optarg;
}
else
{
if ( v7 != 103 )
goto LABEL_10;
v3 = optarg;
}
}
if ( v4 )
{
v4 = -1;
fwrite("unknown option found.\n", 1uLL, 0x16uLL, stderr);
LABEL_17:
result = v4;
}
else if ( v3 )
{
v8 = atoi(v3);
if ( v8 )
{
*(_DWORD *)a3 = v8;
goto LABEL_17;
}
*(_DWORD *)a3 = 25;
fprintf(stderr, "GPIO number %s is invalid.\n", v3);
fwrite("port was set GPIO25.\n", 1uLL, 0x15uLL, stderr);
result = 0LL;
}
else
{
result = 0LL;
*(_DWORD *)a3 = 25;
}
return result;
}

original_code:
int rc_getopt(int argc, char *argv[], struct opspec *op){
  int opt;
  char *gpio;
  int error;
  static struct option long_options[] = {
    {"gpio", 1, ((void *)0), 'g'},
    {"name", 1, ((void *)0), 'n'},
    {"directory", 1, ((void *)0), 'd'},
    {"lirc", 0, ((void *)0), 'l'},
    {0, 0, 0, 0}
  };
  error = 0;
  gpio = ((void *)0);
  op->name = "noname";
  op->dir = (char *)get_current_dir_name();
  op->lirc = 0;
  while((opt = getopt_long(argc, argv, "g:n:d:l", long_options, ((void *)0))) != -1){
    switch(opt){
      case 'g':
        gpio = optarg;
        break;
      case 'n':
        op->name = optarg;
        break;
      case 'd':
        free(op->dir);
        op->dir = optarg;
        break;
      case 'l':
        op->lirc = 1;
        break;
      default:
        error = 1;
        break;
    }
  }
  if(error){
    fprintf(stderr, "unknown option found.\n");
    return -1;
  }
  if(gpio == ((void *)0)){
    op->port = 25;
  } else {
    op->port = atoi(gpio);
    if(op->port == 0){
      op->port = 25;
      fprintf(stderr, "GPIO number %s is invalid.\n", gpio);
      fprintf(stderr, "port was set GPIO25.\n");
    }
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct opspec { int port; char *name; char *dir; int lirc; } *

variable_types: opt int

variable_types:
gpio
char *

variable_types: error int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


decompiled_code:
__int64 rc_getch()
{
__m128i v0; // xmm0
__m128i v1; // xmm2
unsigned int v2; // er12
struct termios v4; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

tcgetattr(0, &v4);
v0 = _mm_loadu_si128((const __m128i *)&v4);
v1 = _mm_loadu_si128((const __m128i *)&v4.c_cc[15]);
*(__m128i *)&termios_p.c_line = _mm_loadu_si128((const __m128i *)&v4.c_line);
*(_QWORD *)&termios_p.c_cc[31] = *(_QWORD *)&v4.c_cc[31];
*(__m128i *)&termios_p.c_iflag = v0;
*(__m128i *)&termios_p.c_cc[15] = v1;
termios_p.c_lflag = v0.m128i_i32[3] & 0xFFFFFFF5;
termios_p.c_ospeed = v4.c_ospeed;
tcsetattr(0, 0, &termios_p);
v2 = getchar();
tcsetattr(0, 0, &v4);
return v2;
}

canonical_decompiled_code:
__int64 func0()
{
__m128i v0; // xmm0
__m128i v1; // xmm2
unsigned int v2; // er12
struct termios v4; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

tcgetattr(0, &v4);
v0 = _mm_loadu_si128((const __m128i *)&v4);
v1 = _mm_loadu_si128((const __m128i *)&v4.c_cc[15]);
*(__m128i *)&termios_p.c_line = _mm_loadu_si128((const __m128i *)&v4.c_line);
*(_QWORD *)&termios_p.c_cc[31] = *(_QWORD *)&v4.c_cc[31];
*(__m128i *)&termios_p.c_iflag = v0;
*(__m128i *)&termios_p.c_cc[15] = v1;
termios_p.c_lflag = v0.m128i_i32[3] & 0xFFFFFFF5;
termios_p.c_ospeed = v4.c_ospeed;
tcsetattr(0, 0, &termios_p);
v2 = getchar();
tcsetattr(0, 0, &v4);
return v2;
}

original_code:
int rc_getch(){
  struct termios old;
  struct termios now;
  int ch;
  tcgetattr( 0, &old);
  now = old;
  now.c_lflag &= ~(0000002 | 0000010);
  tcsetattr( 0, 0, &now);
  ch = getchar();
  tcsetattr( 0, 0, &old);
  return ch;
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types: ch int


decompiled_code:
__int64 __fastcall rc_passign(unsigned int a1)
{
unsigned int v1; // er12
size_t v2; // rax
int v3; // ebx
int v4; // er12
int v5; // er12
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
char v11[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = open("/sys/class/gpio/export", 1);
if ( v1 == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "fail to open GPIO%d. %s\n", a1, v10);
}
else
{
sprintf(v11, "%d", a1);
v2 = strlen(v11);
v3 = write(v1, v11, v2);
close(v1);
if ( v3 <= 0 )
{
v7 = _errno_location();
v1 = -1;
v8 = strerror(*v7);
fprintf(stderr, "fail to open GPIO%d. %s\n", a1, v8);
}
else
{
sprintf(v11, "/sys/class/gpio/gpio%d/direction", a1);
v4 = open(v11, 1);
write(v4, "in", 2uLL);
close(v4);
sprintf(v11, "/sys/class/gpio/gpio%d/edge", a1);
v5 = open(v11, 1);
write(v5, "both", 4uLL);
close(v5);
sprintf(v11, "/sys/class/gpio/gpio%d/value", a1);
v1 = open(v11, 0);
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
unsigned int v1; // er12
size_t v2; // rax
int v3; // ebx
int v4; // er12
int v5; // er12
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
char v11[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = open("/sys/class/gpio/export", 1);
if ( v1 == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "fail to open GPIO%d. %s\n", a1, v10);
}
else
{
sprintf(v11, "%d", a1);
v2 = strlen(v11);
v3 = write(v1, v11, v2);
close(v1);
if ( v3 <= 0 )
{
v7 = _errno_location();
v1 = -1;
v8 = strerror(*v7);
fprintf(stderr, "fail to open GPIO%d. %s\n", a1, v8);
}
else
{
sprintf(v11, "/sys/class/gpio/gpio%d/direction", a1);
v4 = open(v11, 1);
write(v4, "in", 2uLL);
close(v4);
sprintf(v11, "/sys/class/gpio/gpio%d/edge", a1);
v5 = open(v11, 1);
write(v5, "both", 4uLL);
close(v5);
sprintf(v11, "/sys/class/gpio/gpio%d/value", a1);
v1 = open(v11, 0);
}
}
return v1;
}

original_code:
int rc_passign(int port){
  int ret;
  int fd;
  char buf[40];
  fd = open("/sys/class/gpio/export", 01);
  if(fd == -1){
    fprintf(stderr, "fail to open GPIO%d. %s\n", port, strerror((*__errno_location ())));
    return -1;
  }
  sprintf(buf, "%d", port);
  ret = write(fd, buf, strlen(buf));
  close(fd);
  if(ret <= 0){
    fprintf(stderr, "fail to open GPIO%d. %s\n", port, strerror((*__errno_location ())));
    return -1;
  }
  sprintf(buf, "/sys/class/gpio/gpio%d/direction", port);
  fd = open(buf, 01);
  write(fd, "in", 2);
  close(fd);
  sprintf(buf, "/sys/class/gpio/gpio%d/edge", port);
  fd = open(buf, 01);
  write(fd, "both", 4);
  close(fd);
  sprintf(buf, "/sys/class/gpio/gpio%d/value", port);
  fd = open(buf, 00);
  return fd;
}

variable_types: port int

variable_types: ret int

variable_types: fd int

variable_types:
buf
char [40]


original_code:
int rc_decode(struct irspec *ir){
  int i, j;
  int ret = 1;
  char c;
  long temp;
  long son, soff;
  struct timespec now;
  struct pollfd pfd;
  pfd.fd = ir->fd;
  pfd.events = 0x002;
  for(i = 0; i < ((512 + 7) / 8); i++)
    for(j = 0; j < 8; j++){
      lseek(ir->fd, 0, 0);
      poll(&pfd, 1, -1);
      clock_gettime(4, &now);
      read(ir->fd, &c, 1);
      temp = ((now.tv_sec - ir->origin.tv_sec) * 1000000 + (now.tv_nsec - ir->origin.tv_nsec) / 1000);
      son = temp - ir->last;
      ir->last = temp;
      lseek(ir->fd, 0, 0);
      ret = poll(&pfd, 1, 10);
      clock_gettime(4, &now);
      read(ir->fd, &c, 1);
      temp = ((now.tv_sec - ir->origin.tv_sec) * 1000000 + (now.tv_nsec - ir->origin.tv_nsec) / 1000);
      soff = temp - ir->last;
      ir->last = temp;
      ir->code[i] <<= 1;
      ir->code[i] |= (son * 2 < soff);
      if(ret <= 0){
        ir->length = i * 8 + j;
        ir->count = i;
        return 0;
      }
  }
  return -1;
}

canonical_original_code:
int rc_decode(struct irspec *ir){
  int i; int j;
  int ret = 1;
  char c;
  long temp;
  long son; long soff;
  struct timespec now;
  struct pollfd pfd;
  pfd.fd = ir->fd;
  pfd.events = 0x002;
  for(i = 0; i < ((512 + 7) / 8); i++)
    for(j = 0; j < 8; j++){
      lseek(ir->fd, 0, 0);
      poll(&pfd, 1, -1);
      clock_gettime(4, &now);
      read(ir->fd, &c, 1);
      temp = ((now.tv_sec - ir->origin.tv_sec) * 1000000 + (now.tv_nsec - ir->origin.tv_nsec) / 1000);
      son = temp - ir->last;
      ir->last = temp;
      lseek(ir->fd, 0, 0);
      ret = poll(&pfd, 1, 10);
      clock_gettime(4, &now);
      read(ir->fd, &c, 1);
      temp = ((now.tv_sec - ir->origin.tv_sec) * 1000000 + (now.tv_nsec - ir->origin.tv_nsec) / 1000);
      soff = temp - ir->last;
      ir->last = temp;
      ir->code[i] <<= 1;
      ir->code[i] |= (son * 2 < soff);
      if(ret <= 0){
        ir->length = i * 8 + j;
        ir->count = i;
        return 0;
      }
  }
  return -1;
}

variable_types: struct irspec { struct timespec { long tv_sec; long tv_nsec; } origin; int fd; long lon; long repeat; int length; long *son; int count; unsigned char *code; long last; long interval; long gap; } *

variable_types: i int

variable_types: c char

variable_types: temp long

variable_types: son long

variable_types: soff long

variable_types: struct pollfd { int fd; short events; short revents; }


original_code:
int rc_record(struct irspec *ir){
  int i;
  int ret;
  char c;
  long temp;
  struct timespec now;
  struct pollfd pfd;
  pfd.fd = ir->fd;
  pfd.events = 0x002;
  for(i = 0; i < 512; i++){
    lseek(ir->fd, 0, 0);
    poll(&pfd, 1, -1);
    clock_gettime(4, &now);
    read(ir->fd, &c, 1);
    temp = ((now.tv_sec - ir->origin.tv_sec) * 1000000 + (now.tv_nsec - ir->origin.tv_nsec) / 1000);
    ir->son[i] = temp - ir->last;
    ir->last = temp;
    lseek(ir->fd, 0, 0);
    ret = poll(&pfd, 1, 10);
    clock_gettime(4, &now);
    read(ir->fd, &c, 1);
    temp = ((now.tv_sec - ir->origin.tv_sec) * 1000000 + (now.tv_nsec - ir->origin.tv_nsec) / 1000);
    ir->soff[i] = temp - ir->last;
    ir->last = temp;
    if(ret <= 0){
      ir->length = i;
      return 0;
    }
  }
  return -1;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }


original_code:
long rc_center(long *array, int length){
  long temp;
  int i, j;
  for(i = 0; i < length - 1; i++)
    for(j = length - 1; j > i; j--)
      if(array[j - 1] > array[j]){
        temp = array[j];
        array[j] = array[j - 1];
        array[j - 1] = temp;
      }
  return array[length / 2];
}

canonical_original_code:
long rc_center(long *array, int length){
  long temp;
  int i; int j;
  for(i = 0; i < length - 1; i++)
    for(j = length - 1; j > i; j--)
      if(array[j - 1] > array[j]){
        temp = array[j];
        array[j] = array[j - 1];
        array[j - 1] = temp;
      }
  return array[length / 2];
}

variable_types:
array
long *

variable_types: length int

variable_types: j int

return_type: long


decompiled_code:
__int64 __fastcall rc_speccmp(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rax
int v4; // edx
__int64 result; // rax
__int64 v6; // rax
int v7; // edx

v2 = *(int *)(a1 + 72);
if ( (_DWORD)v2 != *(_DWORD *)(a2 + 72) )
return 0xFFFFFFFFLL;
if ( (int)v2 > 0 )
{
v3 = 0LL;
v4 = 0;
do
{
if ( *(_BYTE *)(*(_QWORD *)(a1 + 80) + v3) != *(_BYTE *)(*(_QWORD *)(a2 + 80) + v3) )
v4 = 1;
++v3;
}
while ( (int)v2 != v3 );
if ( v4 )
return 0xFFFFFFFFLL;
}
result = *(unsigned int *)(a1 + 48);
if ( (_DWORD)result != *(_DWORD *)(a2 + 48) )
return 0xFFFFFFFFLL;
if ( !(_DWORD)result )
return result;
if ( *(_DWORD *)(a1 + 76) != *(_DWORD *)(a2 + 76) )
return 0xFFFFFFFFLL;
if ( (int)v2 <= 0 )
return 0LL;
v6 = 0LL;
v7 = 0;
do
{
if ( *(_BYTE *)(*(_QWORD *)(a1 + 80) + v6) != *(_BYTE *)(*(_QWORD *)(a2 + 80) + v6) )
v7 = 1;
++v6;
}
while ( v6 != v2 );
return (unsigned int)-v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rax
int v4; // edx
__int64 result; // rax
__int64 v6; // rax
int v7; // edx

v2 = *(int *)(a1 + 72);
if ( (_DWORD)v2 != *(_DWORD *)(a2 + 72) )
return 0xFFFFFFFFLL;
if ( (int)v2 > 0 )
{
v3 = 0LL;
v4 = 0;
do
{
if ( *(_BYTE *)(*(_QWORD *)(a1 + 80) + v3) != *(_BYTE *)(*(_QWORD *)(a2 + 80) + v3) )
v4 = 1;
++v3;
}
while ( (int)v2 != v3 );
if ( v4 )
return 0xFFFFFFFFLL;
}
result = *(unsigned int *)(a1 + 48);
if ( (_DWORD)result != *(_DWORD *)(a2 + 48) )
return 0xFFFFFFFFLL;
if ( !(_DWORD)result )
return result;
if ( *(_DWORD *)(a1 + 76) != *(_DWORD *)(a2 + 76) )
return 0xFFFFFFFFLL;
if ( (int)v2 <= 0 )
return 0LL;
v6 = 0LL;
v7 = 0;
do
{
if ( *(_BYTE *)(*(_QWORD *)(a1 + 80) + v6) != *(_BYTE *)(*(_QWORD *)(a2 + 80) + v6) )
v7 = 1;
++v6;
}
while ( v6 != v2 );
return (unsigned int)-v7;
}

original_code:
int rc_speccmp(struct rcspec *rc1, struct rcspec *rc2){
  int i;
  int neq;
  if(rc1->count1 != rc2->count1)
    return -1;
  neq = 0;
  for(i = 0; i < rc1->count1; i++)
    if(rc1->code1[i] != rc2->code1[i])
      neq = 1;
  if(neq)
    return -1;
  if(rc1->multi != rc2->multi)
    return -1;
  if(rc1->multi){
    if(rc1->count2 != rc2->count2)
      return -1;
    neq = 0;
    for(i = 0; i < rc1->count1; i++)
      if(rc1->code1[i] != rc2->code1[i])
        neq = 1;
    if(neq)
      return -1;
  }
  return 0;
}

variable_types: struct rcspec { long lon; long repeat; long t; long h; long l; int multi; long gap; long interval; int count1; unsigned char *code1; } *

variable_types: neq int


repo: rvbelapure/fast-tcp-over-tcp

decompiled_code:
int __fastcall gt_listen(int *a1, int a2)
{
return listen(*a1, a2);
}

canonical_decompiled_code:
int __fastcall func1(int *a1, int a2)
{
return listen(*a1, a2);
}

original_code:
int gt_listen(sock_descriptor_t *sockfd, int backlog) {
 return listen(sockfd->sockfd, backlog);
}

canonical_original_code:
int gt_listen(struct _sock_descriptor *sockfd, int backlog) {
 return listen(sockfd->sockfd, backlog);
}

variable_types: struct _sock_descriptor { int sockfd; char *data; long offset; long length; unsigned int CCnumber; int half_synchronized_flag; } *

variable_types: backlog int


original_code:
int gt_close(sock_descriptor_t *sockfd)
{
 if((sockfd->length - sockfd->offset > 0) && (sockfd->data))
 {
  free(sockfd->data);
  sockfd->length = 0;
  sockfd->offset = 0;
 }
 return close(sockfd->sockfd);
}

canonical_original_code:
int gt_close(struct _sock_descriptor *sockfd)
{
 if((sockfd->length - sockfd->offset > 0) && (sockfd->data))
 {
  free(sockfd->data);
  sockfd->length = 0;
  sockfd->offset = 0;
 }
 return close(sockfd->sockfd);
}

user_defined_types: struct _sock_descriptor { int sockfd; char *data; long offset; long length; unsigned int CCnumber; int half_synchronized_flag; }


decompiled_code:
__int64 cc_gen()
{
unsigned int v0; // er12

pthread_mutex_lock(&ccgen_mutex);
v0 = CCgen + 1;
if ( CCgen == 0x80000000 )
v0 = 1;
CCgen = v0;
pthread_mutex_unlock(&ccgen_mutex);
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // er12

pthread_mutex_lock(&ccgen_mutex);
v0 = CCgen + 1;
if ( CCgen == 0x80000000 )
v0 = 1;
CCgen = v0;
pthread_mutex_unlock(&ccgen_mutex);
return v0;
}

original_code:
uint32_t cc_gen(){
 uint32_t CCgen_local;
 pthread_mutex_lock(&ccgen_mutex);
 if(CCgen == (1 << 31)){
  CCgen = 1;
  CCgen_local = CCgen;
 }
 else{
  CCgen++;
  CCgen_local = CCgen;
 }
 pthread_mutex_unlock(&ccgen_mutex);
 return CCgen_local;
}

canonical_original_code:
unsigned int cc_gen(){
 unsigned int CCgen_local;
 pthread_mutex_lock(&ccgen_mutex);
 if(CCgen == (1 << 31)){
  CCgen = 1;
  CCgen_local = CCgen;
 }
 else{
  CCgen++;
  CCgen_local = CCgen;
 }
 pthread_mutex_unlock(&ccgen_mutex);
 return CCgen_local;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall get_client_id(__int64 a1)
{
unsigned int v1; // ebx
int *v2; // rax
__int64 v3; // rcx

v1 = 0;
pthread_mutex_lock(&addr_list_mutex);
v2 = (int *)addr_list;
do
{
v3 = *v2;
if ( v3 == a1 )
goto LABEL_5;
if ( !(_DWORD)v3 )
{
*v2 = a1;
LABEL_5:
pthread_mutex_unlock(&addr_list_mutex);
return v1;
}
++v1;
++v2;
}
while ( v1 != 100 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
unsigned int v1; // ebx
int *v2; // rax
__int64 v3; // rcx

v1 = 0;
pthread_mutex_lock(&addr_list_mutex);
v2 = (int *)addr_list;
do
{
v3 = *v2;
if ( v3 == a1 )
goto LABEL_5;
if ( !(_DWORD)v3 )
{
*v2 = a1;
LABEL_5:
pthread_mutex_unlock(&addr_list_mutex);
return v1;
}
++v1;
++v2;
}
while ( v1 != 100 );
return 0xFFFFFFFFLL;
}

original_code:
uint32_t get_client_id(unsigned long addr){
 int addr_found = 0;
 int i;
 pthread_mutex_lock(&addr_list_mutex);
 for(i=0; i<100; i++){
  if(addr_list[i] == addr){
   addr_found = 1;
   break;
  }
  if(addr_list[i] == 0){
   break;
  }
 }
 if((i == 100) && (addr_found == 0))
  return -1;
 if(addr_found == 0)
  addr_list[i] = addr;
 pthread_mutex_unlock(&addr_list_mutex);
 return i;
}

canonical_original_code:
unsigned int get_client_id(unsigned long addr){
 int addr_found = 0;
 int i;
 pthread_mutex_lock(&addr_list_mutex);
 for(i=0; i<100; i++){
  if(addr_list[i] == addr){
   addr_found = 1;
   break;
  }
  if(addr_list[i] == 0){
   break;
  }
 }
 if((i == 100) && (addr_found == 0))
  return -1;
 if(addr_found == 0)
  addr_list[i] = addr;
 pthread_mutex_unlock(&addr_list_mutex);
 return i;
}

variable_types:
addr
unsigned long


decompiled_code:
void __fastcall __noreturn key_updater(void *a1)
{
__int64 v1; // rax

while ( 1 )
{
sleep(0x12Cu);
pthread_rwlock_wrlock(&server_key_rwlock);
do
{
do
{
v1 = random();
key = v1;
}
while ( !v1 );
}
while ( v1 == 0x7FFFFFFFFFFFFFFFLL );
pthread_rwlock_unlock(&server_key_rwlock);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
__int64 v1; // rax

while ( 1 )
{
sleep(0x12Cu);
pthread_rwlock_wrlock(&server_key_rwlock);
do
{
do
{
v1 = random();
key = v1;
}
while ( !v1 );
}
while ( v1 == 0x7FFFFFFFFFFFFFFFLL );
pthread_rwlock_unlock(&server_key_rwlock);
}
}

original_code:
void * key_updater(void *t)
{
 while(1)
 {
  sleep(300);
  pthread_rwlock_wrlock(&server_key_rwlock);
  key = (unsigned long) random();
  while((key == 0) || (key == 0x7fffffffffffffffL)) key = (unsigned long) random();
  pthread_rwlock_unlock(&server_key_rwlock);
 }
}

canonical_original_code:
void *key_updater(void *t)
{
 while(1)
 {
  sleep(300);
  pthread_rwlock_wrlock(&server_key_rwlock);
  key = (unsigned long) random();
  while((key == 0) || (key == 0x7fffffffffffffffL)) key = (unsigned long) random();
  pthread_rwlock_unlock(&server_key_rwlock);
 }
}

variable_types:
t
void *

return_type: void *


canonical_decompiled_code:
int __fastcall func2(int *a1, int a2)
{
return listen(*a1, a2);
}


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

pthread_rwlock_rdlock(&server_key_rwlock);
if ( (key ^ a2) == a1 )
{
pthread_mutex_lock(&server_tfo_threshold_mutex);
if ( (unsigned __int64)active_tfo_connections > 0x32 )
{
pthread_mutex_unlock(&server_tfo_threshold_mutex);
pthread_rwlock_unlock(&server_key_rwlock);
result = 0LL;
}
else
{
++active_tfo_connections;
pthread_mutex_unlock(&server_tfo_threshold_mutex);
pthread_rwlock_unlock(&server_key_rwlock);
result = 1LL;
}
}
else
{
pthread_rwlock_unlock(&server_key_rwlock);
result = 0xFFFFFFFFLL;
}
return result;
}

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

pthread_rwlock_rdlock(&server_key_rwlock);
if ( (key ^ a2) == a1 )
{
pthread_mutex_lock(&server_tfo_threshold_mutex);
if ( (unsigned __int64)active_tfo_connections > 0x32 )
{
pthread_mutex_unlock(&server_tfo_threshold_mutex);
pthread_rwlock_unlock(&server_key_rwlock);
result = 0LL;
}
else
{
++active_tfo_connections;
pthread_mutex_unlock(&server_tfo_threshold_mutex);
pthread_rwlock_unlock(&server_key_rwlock);
result = 1LL;
}
}
else
{
pthread_rwlock_unlock(&server_key_rwlock);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int cookie_verify(unsigned long cookie, unsigned long addr)
{
 pthread_rwlock_rdlock(&server_key_rwlock);
 if(cookie != (key ^ addr))
 {
  pthread_rwlock_unlock(&server_key_rwlock);
  return -1;
 }
 pthread_mutex_lock(&server_tfo_threshold_mutex);
 if(active_tfo_connections > 50)
 {
  pthread_mutex_unlock(&server_tfo_threshold_mutex);
  pthread_rwlock_unlock(&server_key_rwlock);
  return 0;
 }
 active_tfo_connections++;
 pthread_mutex_unlock(&server_tfo_threshold_mutex);
 pthread_rwlock_unlock(&server_key_rwlock);
 return 1;
}

variable_types:
cookie
unsigned long


decompiled_code:
__int64 __fastcall cookie_gen(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // r12

pthread_rwlock_rdlock(&server_key_rwlock);
v1 = key;
v2 = a1 ^ key;
pthread_rwlock_unlock(&server_key_rwlock);
if ( v1 == a1 )
_assert_fail("cookie != 0", "libtcp.c", 0x1B9u, "cookie_gen");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // r12

pthread_rwlock_rdlock(&server_key_rwlock);
v1 = key;
v2 = a1 ^ key;
pthread_rwlock_unlock(&server_key_rwlock);
if ( v1 == a1 )
_assert_fail("cookie != 0", "libtcp.c", 0x1B9u, "cookie_gen");
return v2;
}

original_code:
unsigned long cookie_gen(unsigned long addr)
{
 unsigned long cookie = 0;
 pthread_rwlock_rdlock(&server_key_rwlock);
 cookie = key ^ addr;
 pthread_rwlock_unlock(&server_key_rwlock);
 ((void) sizeof ((cookie != 0) ? 1 : 0), __extension__ ({ if (cookie != 0) ; else __assert_fail ("cookie != 0", "libtcp.c", 441, __extension__ __PRETTY_FUNCTION__); }));
 return cookie;
}

return_type: unsigned long


initializeBitArray

repo: rvimieiro/disclosed

original_code:
void initializeBitArray(BitArray * container, unsigned short size)
{
 if(! container) {
  return;
 }
 container->size = size;
 container->length = (unsigned short) ceil(((float)size)/(sizeof(uint64_t)<<3));
 container->data = (uint64_t *) calloc(container->length,sizeof(uint64_t));
 memset(container->data,0,container->length*sizeof(uint64_t));
 container->nelements = 0;
}

canonical_original_code:
void initializeBitArray(struct __bitarray *container, unsigned short size)
{
 if(! container) {
  return;
 }
 container->size = size;
 container->length = (unsigned short) ceil(((float)size)/(sizeof(unsigned long)<<3));
 container->data = (unsigned long *) calloc(container->length,sizeof(unsigned long));
 memset(container->data,0,container->length*sizeof(unsigned long));
 container->nelements = 0;
}

variable_types: struct __bitarray { unsigned short size; unsigned short length; unsigned short nelements; unsigned long *data; } *

variable_types:
size
unsigned short


destroyBitArray

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

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

original_code:
void destroyBitArray(BitArray* set){
 if(set){
  free(set->data);
  free(set);
 }
}

canonical_original_code:
void destroyBitArray(struct __bitarray *set){
 if(set){
  free(set->data);
  free(set);
 }
}

user_defined_types: struct __bitarray { unsigned short size; unsigned short length; unsigned short nelements; unsigned long *data; }


bitArrayToArray

original_code:
void bitArrayToArray(const BitArray * ba, int ** dest){
 int i, j;
 int count;
 int index;
 int nbits = sizeof(uint64_t)<<3;
 if(!ba) { *dest = ((void *)0); return; }
 if(!*dest) *dest = (int*)malloc(sizeof(int)*ba->nelements);
 for (i = 0, count = 0, index= 0; i < ba->length; i++){
  if(ba->data[i]) {
   const uint64_t one = 1;
   for(j = 0; j < nbits; j++,count++){
    if( (one<<j) & ba->data[i] )
     (*dest)[index++] = count;
   }
  }
  else{
   count+= nbits;
  }
 }
}

canonical_original_code:
void bitArrayToArray(struct __bitarray *ba, int **dest){
 int i; int j;
 int count;
 int index;
 int nbits = sizeof(uint64_t)<<3;
 if(!ba) { *dest = ((void *)0); return; }
 if(!*dest) *dest = (int *)malloc(sizeof(int)*ba->nelements);
 for (i = 0, count = 0, index= 0; i < ba->length; i++){
  if(ba->data[i]) {
   unsigned long one = 1;
   for(j = 0; j < nbits; j++,count++){
    if( (one<<j) & ba->data[i] )
     (*dest)[index++] = count;
   }
  }
  else{
   count+= nbits;
  }
 }
}

variable_types:
dest
int **

variable_types: i int

variable_types: count int

variable_types: index int

variable_types: nbits int

variable_types:
one
unsigned long


decompiled_code:
void __fastcall __noreturn SIG_HANDLER(unsigned int a1)
{
gettimeofday(&stop, 0LL);
*(double *)&timespent = (double)(LODWORD(stop.tv_usec) - LODWORD(start.tv_usec)) / 1000000.0
+ (double)(LODWORD(stop.tv_sec) - LODWORD(start.tv_sec));
fprintf(stderr, "Execution interrupted by signal %d\n", a1);
fwrite("Aborting...\n", 1uLL, 0xCuLL, stderr);
fprintf(
stderr,
"Found %ld closed sets out of %ld candidates so far in %4.2f sec\n",
totalClosed,
numberCandidates,
*(double *)&timespent);
fclose(output);
exit(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(unsigned int a1)
{
gettimeofday(&stop, 0LL);
*(double *)&timespent = (double)(LODWORD(stop.tv_usec) - LODWORD(start.tv_usec)) / 1000000.0
+ (double)(LODWORD(stop.tv_sec) - LODWORD(start.tv_sec));
fprintf(stderr, "Execution interrupted by signal %d\n", a1);
fwrite("Aborting...\n", 1uLL, 0xCuLL, stderr);
fprintf(
stderr,
"Found %ld closed sets out of %ld candidates so far in %4.2f sec\n",
totalClosed,
numberCandidates,
*(double *)&timespent);
fclose(output);
exit(a1);
}

original_code:
void SIG_HANDLER(int sig){
 gettimeofday(&stop,((void *)0));
 timespent = (stop.tv_sec-start.tv_sec);
 timespent += (stop.tv_usec-start.tv_usec)/1000000.0;
 fprintf(stderr, "Execution interrupted by signal %d\n", sig);
 fprintf(stderr, "Aborting...\n");
 fprintf(stderr, "Found %ld closed sets out of %ld candidates so far in %4.2f sec\n",totalClosed,numberCandidates,timespent);
 fclose(output);
 exit(sig);
}

variable_types: sig int


showIntro

decompiled_code:
int showIntro()
{
return fprintf(stderr, "%s\t(GPL)\tversion %s %s\t%s\n", "Disclosed", "0.9", "2014-02-18", "Renato Vimieiro");
}

canonical_decompiled_code:
int func1()
{
return fprintf(stderr, "%s\t(GPL)\tversion %s %s\t%s\n", "Disclosed", "0.9", "2014-02-18", "Renato Vimieiro");
}

original_code:
void showIntro(){
 fprintf(stderr,"%s\t(GPL)\tversion %s  %s\t%s\n","Disclosed","0.9","2014-02-18","Renato Vimieiro");
}


showUsage

decompiled_code:
void __fastcall __noreturn showUsage(const char *a1)
{
fprintf(stderr, "\nProgram usage:\n%s <input> <minsup> <maxsup> <print transactions> [<output>]\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
fprintf(stderr, "\nProgram usage:\n%s <input> <minsup> <maxsup> <print transactions> [<output>]\n", a1);
exit(1);
}

original_code:
void showUsage(char * com){
 fprintf(stderr,"\nProgram usage:\n%s <input> <minsup> <maxsup> <print transactions> [<output>]\n",com);
 exit(1);
}

canonical_original_code:
void showUsage(char *com){
 fprintf(stderr,"\nProgram usage:\n%s <input> <minsup> <maxsup> <print transactions> [<output>]\n",com);
 exit(1);
}

variable_types:
com
char *


initializeRepository

decompiled_code:
void __fastcall initializeRepository(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void initializeRepository(Database* rep){
 rep->size = 0;
 rep->objsize = 0;
}

canonical_original_code:
void initializeRepository(struct __database *rep){
 rep->size = 0;
 rep->objsize = 0;
}

variable_types: struct __database { struct __bitarray { unsigned short size; unsigned short length; unsigned short nelements; unsigned long *data; } **data; int size; int objsize; } *

user_defined_types: struct __database { struct __bitarray **data; int size; int objsize; }


conditionalTable

original_code:
int* conditionalTable (const int* src, int* sizeSrc, const BitArray* set){
 int* dst;
 int i;
 register uint64_t *a, *b, *end;
 end = (set->data) + (set->length);
 int count = 0;
 int size = *sizeSrc;
 register int elem;
 ((void) sizeof ((src && set) ? 1 : 0), __extension__ ({ if (src && set) ; else __assert_fail ("src && set", "../condtable.c", 41, __extension__ __PRETTY_FUNCTION__); }));
 dst = (int*)malloc(sizeof(int)*size);
 for(i = 0; i < size; i++){
  elem = src[i];
  for(a=rep.data[elem]->data,b=set->data; b < end && !(*a & ~(*b)); a++, b++);
  if(b == end) dst[count++] = elem;
 }
 *sizeSrc = count;
 dst = (int*)realloc(dst,count*sizeof(int));
 return dst;
}

canonical_original_code:
int *conditionalTable(int *src, int *sizeSrc, struct __bitarray *set){
 int *dst;
 int i;
 register unsigned long *a; register unsigned long *b; register unsigned long *end;
 end = (set->data) + (set->length);
 int count = 0;
 int size = *sizeSrc;
 register int elem;
 ((void) sizeof ((src && set) ? 1 : 0), __extension__ ({ if (src && set) ; else __assert_fail ("src && set", "../condtable.c", 41, __extension__ __PRETTY_FUNCTION__); }));
 dst = (int *)malloc(sizeof(int)*size);
 for(i = 0; i < size; i++){
  elem = src[i];
  for(a=rep.data[elem]->data,b=set->data; b < end && !(*a & ~(*b)); a++, b++);
  if(b == end) dst[count++] = elem;
 }
 *sizeSrc = count;
 dst = (int *)realloc(dst,count*sizeof(int));
 return dst;
}

variable_types:
src
int *

variable_types:
sizeSrc
int *

variable_types:
dst
int *

variable_types:
a
unsigned long *

variable_types:
b
unsigned long *

variable_types:
end
unsigned long *

variable_types: size int

variable_types: elem int

return_type: int *


repo: rvion/school-mega-repo

variable_types:
idum
long *

variable_types: j int

variable_types: k long

variable_types: iy long

variable_types:
iv
long [32]

variable_types: temp float

return_type: float


variable_types: inext int

variable_types: inextp int

variable_types:
ma
long [56]

variable_types: iff int

variable_types: mj long

variable_types: mk long

variable_types: i int

variable_types: ii int

variable_types: k int


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

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

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

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

original_code:
uint8 ui8min2(uint8 x0, uint8 x1)
{
    if(x0<x1)
        return x0;
    else
        return x1;
}

canonical_original_code:
unsigned char ui8min2(unsigned char x0, unsigned char x1)
{
    if(x0<x1)
        return x0;
    else
        return x1;
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall ui8min3(unsigned __int8 a1, unsigned __int8 a2)
{
unsigned __int8 v2; // al
unsigned __int8 v3; // dl

v2 = ui8min2(a1, a2);
return ui8min2(v2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, unsigned __int8 a2)
{
unsigned __int8 v2; // al
unsigned __int8 v3; // dl

v2 = func0(a1, a2);
return func0(v2, v3);
}

original_code:
uint8 ui8min3(uint8 x0, uint8 x1, uint8 x2)
{
    return ui8min2(ui8min2(x0,x1),x2);
}

canonical_original_code:
unsigned char ui8min3(unsigned char x0, unsigned char x1, unsigned char x2)
{
    return ui8min2(ui8min2(x0,x1),x2);
}


decompiled_code:
__int64 __fastcall ui8min4(__int64 a1, __int64 a2, unsigned __int8 a3, unsigned __int8 a4)
{
unsigned __int8 v4; // r9
unsigned __int8 v5; // r8
unsigned __int8 v6; // al
unsigned __int8 v7; // dl

ui8min2(a3, a4);
v6 = ui8min2(v5, v4);
return ui8min2(v6, v7);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned __int8 a3, unsigned __int8 a4)
{
unsigned __int8 v4; // r9
unsigned __int8 v5; // r8
unsigned __int8 v6; // al
unsigned __int8 v7; // dl

func0(a3, a4);
v6 = func0(v5, v4);
return func0(v6, v7);
}

original_code:
uint8 ui8min4(uint8 x0, uint8 x1, uint8 x2, uint8 x3)
{
    return ui8min2(ui8min2(x0,x1),ui8min2(x2,x3));
}

canonical_original_code:
unsigned char ui8min4(unsigned char x0, unsigned char x1, unsigned char x2, unsigned char x3)
{
    return ui8min2(ui8min2(x0,x1),ui8min2(x2,x3));
}


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

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

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

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

original_code:
uint8 ui8max2(uint8 x0, uint8 x1)
{
    if(x0>x1)
        return x0;
    else
        return x1;
}

canonical_original_code:
unsigned char ui8max2(unsigned char x0, unsigned char x1)
{
    if(x0>x1)
        return x0;
    else
        return x1;
}


decompiled_code:
__int64 __fastcall ui8max3(unsigned __int8 a1, unsigned __int8 a2)
{
unsigned __int8 v2; // al
unsigned __int8 v3; // dl

v2 = ui8max2(a1, a2);
return ui8max2(v2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1, unsigned __int8 a2)
{
unsigned __int8 v2; // al
unsigned __int8 v3; // dl

v2 = func3(a1, a2);
return func3(v2, v3);
}

original_code:
uint8 ui8max3(uint8 x0, uint8 x1, uint8 x2)
{
    return ui8max2(ui8max2(x0,x1),x2);
}

canonical_original_code:
unsigned char ui8max3(unsigned char x0, unsigned char x1, unsigned char x2)
{
    return ui8max2(ui8max2(x0,x1),x2);
}


decompiled_code:
__int64 __fastcall ui8max4(__int64 a1, __int64 a2, unsigned __int8 a3, unsigned __int8 a4)
{
unsigned __int8 v4; // r9
unsigned __int8 v5; // r8
unsigned __int8 v6; // al
unsigned __int8 v7; // dl

ui8max2(a3, a4);
v6 = ui8max2(v5, v4);
return ui8max2(v6, v7);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned __int8 a3, unsigned __int8 a4)
{
unsigned __int8 v4; // r9
unsigned __int8 v5; // r8
unsigned __int8 v6; // al
unsigned __int8 v7; // dl

func3(a3, a4);
v6 = func3(v5, v4);
return func3(v6, v7);
}

original_code:
uint8 ui8max4(uint8 x0, uint8 x1, uint8 x2, uint8 x3)
{
    return ui8max2(ui8max2(x0,x1),ui8max2(x2,x3));
}

canonical_original_code:
unsigned char ui8max4(unsigned char x0, unsigned char x1, unsigned char x2, unsigned char x3)
{
    return ui8max2(ui8max2(x0,x1),ui8max2(x2,x3));
}


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

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

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

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

original_code:
uint16 ui16min2(uint16 x0, uint16 x1)
{
    if(x0<x1)
        return x0;
    else
        return x1;
}

canonical_original_code:
unsigned short ui16min2(unsigned short x0, unsigned short x1)
{
    if(x0<x1)
        return x0;
    else
        return x1;
}

return_type: unsigned short


decompiled_code:
__int64 __fastcall ui16min3(unsigned __int16 a1, unsigned __int16 a2)
{
unsigned __int16 v2; // ax
unsigned __int16 v3; // dx

v2 = ui16min2(a1, a2);
return ui16min2(v2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int16 a1, unsigned __int16 a2)
{
unsigned __int16 v2; // ax
unsigned __int16 v3; // dx

v2 = func6(a1, a2);
return func6(v2, v3);
}

original_code:
uint16 ui16min3(uint16 x0, uint16 x1, uint16 x2)
{
    return ui16min2(ui16min2(x0,x1),x2);
}

canonical_original_code:
unsigned short ui16min3(unsigned short x0, unsigned short x1, unsigned short x2)
{
    return ui16min2(ui16min2(x0,x1),x2);
}


decompiled_code:
__int64 __fastcall ui16min4(__int64 a1, __int64 a2, unsigned __int16 a3, unsigned __int16 a4)
{
unsigned __int16 v4; // r9
unsigned __int16 v5; // r8
unsigned __int16 v6; // ax
unsigned __int16 v7; // dx

ui16min2(a3, a4);
v6 = ui16min2(v5, v4);
return ui16min2(v6, v7);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, unsigned __int16 a3, unsigned __int16 a4)
{
unsigned __int16 v4; // r9
unsigned __int16 v5; // r8
unsigned __int16 v6; // ax
unsigned __int16 v7; // dx

func6(a3, a4);
v6 = func6(v5, v4);
return func6(v6, v7);
}

original_code:
uint16 ui16min4(uint16 x0, uint16 x1, uint16 x2, uint16 x3)
{
    return ui16min2(ui16min2(x0,x1),ui16min2(x2,x3));
}

canonical_original_code:
unsigned short ui16min4(unsigned short x0, unsigned short x1, unsigned short x2, unsigned short x3)
{
    return ui16min2(ui16min2(x0,x1),ui16min2(x2,x3));
}


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

result = a2;
if ( (unsigned __int16)a1 >= (unsigned __int16)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (unsigned __int16)a1 >= (unsigned __int16)a2 )
result = a1;
return result;
}

original_code:
uint16 ui16max2(uint16 x0, uint16 x1)
{
    if(x0>x1)
        return x0;
    else
        return x1;
}

canonical_original_code:
unsigned short ui16max2(unsigned short x0, unsigned short x1)
{
    if(x0>x1)
        return x0;
    else
        return x1;
}


decompiled_code:
__int64 __fastcall ui16max3(unsigned __int16 a1, unsigned __int16 a2)
{
unsigned __int16 v2; // ax
unsigned __int16 v3; // dx

v2 = ui16max2(a1, a2);
return ui16max2(v2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int16 a1, unsigned __int16 a2)
{
unsigned __int16 v2; // ax
unsigned __int16 v3; // dx

v2 = func9(a1, a2);
return func9(v2, v3);
}

original_code:
uint16 ui16max3(uint16 x0, uint16 x1, uint16 x2)
{
    return ui16max2(ui16max2(x0,x1),x2);
}

canonical_original_code:
unsigned short ui16max3(unsigned short x0, unsigned short x1, unsigned short x2)
{
    return ui16max2(ui16max2(x0,x1),x2);
}


decompiled_code:
__int64 __fastcall ui16max4(__int64 a1, __int64 a2, unsigned __int16 a3, unsigned __int16 a4)
{
unsigned __int16 v4; // r9
unsigned __int16 v5; // r8
unsigned __int16 v6; // ax
unsigned __int16 v7; // dx

ui16max2(a3, a4);
v6 = ui16max2(v5, v4);
return ui16max2(v6, v7);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, unsigned __int16 a3, unsigned __int16 a4)
{
unsigned __int16 v4; // r9
unsigned __int16 v5; // r8
unsigned __int16 v6; // ax
unsigned __int16 v7; // dx

func9(a3, a4);
v6 = func9(v5, v4);
return func9(v6, v7);
}

original_code:
uint16 ui16max4(uint16 x0, uint16 x1, uint16 x2, uint16 x3)
{
    return ui16max2(ui16max2(x0,x1),ui16max2(x2,x3));
}

canonical_original_code:
unsigned short ui16max4(unsigned short x0, unsigned short x1, unsigned short x2, unsigned short x3)
{
    return ui16max2(ui16max2(x0,x1),ui16max2(x2,x3));
}


original_code:
uint8 ui8rand(void)
{
    static uint32 x=0;
    x = (11 * x + 13) % 17;
    return (uint8) x;
}

canonical_original_code:
unsigned char ui8rand()
{
    static unsigned int x = 0;
    x = (11 * x + 13) % 17;
    return (unsigned char) x;
}

variable_types:
x
unsigned int


original_code:
uint32 ui32rand(void)
{
    static uint32 x=0;
    x = (11 * x + 13) % 17;
    return (uint32) x;
}

canonical_original_code:
unsigned int ui32rand()
{
    static unsigned int x = 0;
    x = (11 * x + 13) % 17;
    return (unsigned int) x;
}


decompiled_code:
__int64 f32rand()
{
int v0; // xmm0_4
__int64 result; // rax

*(float *)&v0 = fmod((float)((float)(11.0 * *(float *)&x_0) + 13.0), 17.0);
result = (unsigned int)(int)*(float *)&v0;
x_0 = v0;
return result;
}

canonical_decompiled_code:
__int64 func14()
{
int v0; // xmm0_4
__int64 result; // rax

*(float *)&v0 = fmod((float)((float)(11.0 * *(float *)&x_0) + 13.0), 17.0);
result = (unsigned int)(int)*(float *)&v0;
x_0 = v0;
return result;
}

original_code:
uint32 f32rand(void)
{
    static float32 x=0;
    x = (float32) fmod(11 * x + 13, 17);
    return (float32) x ;
}

canonical_original_code:
unsigned int f32rand()
{
    static float x = 0;
    x = (float) fmod(11 * x + 13, 17);
    return (float) x ;
}

variable_types: x float


decompiled_code:
void __fastcall rand_ui8vector(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rdi
char v6; // al

v5 = (unsigned int)a3;
if ( (int)a2 <= (int)a3 )
{
a2 = (int)a2;
do
{
v6 = ui8rand(v5, a2, a3, a4, a1);
*(_BYTE *)(a1 + a2++) = v6;
}
while ( (int)v5 >= (int)a2 );
}
}

original_code:
void rand_ui8vector(uint8 *X, int i0, int i1)
{
    int i;
    for(i=i0; i<=i1; i++) {
        X[i] = ui8rand();
    }
}

canonical_original_code:
void rand_ui8vector(unsigned char *X, int i0, int i1)
{
    int i;
    for(i=i0; i<=i1; i++) {
        X[i] = ui8rand();
    }
}

variable_types:
X
unsigned char *


decompiled_code:
void __fastcall rand_ui32vector(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rdi
int v6; // eax

v5 = (unsigned int)a3;
if ( (int)a2 <= (int)a3 )
{
a2 = (int)a2;
do
{
v6 = ui32rand(v5, a2, a3, a4, a1);
*(_DWORD *)(a1 + 4 * a2++) = v6;
}
while ( (int)v5 >= (int)a2 );
}
}

original_code:
void rand_ui32vector(uint32 *X, int i0, int i1)
{
    int i;
    for(i=i0; i<=i1; i++) {
        X[i] = ui32rand();
    }
}

canonical_original_code:
void rand_ui32vector(unsigned int *X, int i0, int i1)
{
    int i;
    for(i=i0; i<=i1; i++) {
        X[i] = ui32rand();
    }
}

variable_types:
X
unsigned int *


decompiled_code:
void __fastcall rand_f32vector(__int64 a1, int a2, int a3)
{
__int64 v4; // rbx

if ( a2 <= a3 )
{
v4 = a2;
do
*(float *)(a1 + 4 * v4++) = (float)(int)f32rand();
while ( a3 >= (int)v4 );
}
}

canonical_decompiled_code:
void __fastcall func17(__int64 a1, int a2, int a3)
{
__int64 v4; // rbx

if ( a2 <= a3 )
{
v4 = a2;
do
*(float *)(a1 + 4 * v4++) = (float)(int)func14();
while ( a3 >= (int)v4 );
}
}

original_code:
void rand_f32vector(float32 *X, int i0, int i1)
{
    int i;
    for(i=i0; i<=i1; i++) {
        X[i] = f32rand();
    }
}

canonical_original_code:
void rand_f32vector(float *X, int i0, int i1)
{
    int i;
    for(i=i0; i<=i1; i++) {
        X[i] = f32rand();
    }
}

variable_types:
X
float *


getIter

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

result = 1024LL;
if ( a1 > 31 )
{
result = 64LL;
if ( a1 > 63 )
{
result = 8LL;
if ( a1 > 127 )
result = (unsigned int)((unsigned int)(a1 - 1024) > 0x3FF) + 1;
}
}
return result;
}

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

result = 1024LL;
if ( a1 > 31 )
{
result = 64LL;
if ( a1 > 63 )
{
result = 8LL;
if ( a1 > 127 )
result = (unsigned int)((unsigned int)(a1 - 1024) > 0x3FF) + 1;
}
}
return result;
}

original_code:
int getIter(int size)
{
    if(size < 32) return 1024;
    if(size < 64) return 64 ;
    if(size < 128) return 8;
    if(size < 256) return 2;
    if(size < 512) return 2;
    if(size < 1024) return 2;
    if(size < 2048) return 1;
    return 2;
}

variable_types: size int


getIterAV

decompiled_code:
__int64 __fastcall getIterAV(int a1)
{
return 3 * (unsigned int)getIter(a1);
}

canonical_decompiled_code:
__int64 __fastcall func19(int a1)
{
return 3 * (unsigned int)func18(a1);
}

original_code:
int getIterAV(int size)
{
    return 3*getIter(size);
}


gauss

decompiled_code:
float __fastcall gauss(float a1, float a2)
{
return 1.0
/ (a1
* 2.506628309507644)
* exp((float)(COERCE_FLOAT(COERCE_UNSIGNED_INT(a2 * a2) ^ LC3) / (float)((float)(a1 + a1) * a1)));
}

canonical_decompiled_code:
float __fastcall func20(float a1, float a2)
{
return 1.0
/ (a1
* 2.506628309507644)
* exp((float)(COERCE_FLOAT(COERCE_UNSIGNED_INT(a2 * a2) ^ LC3) / (float)((float)(a1 + a1) * a1)));
}

original_code:
float32 gauss(float32 sigma, float32 x)
{
    float32 pi = 3.1415927;
    float32 y;
    y = 1.0f / (sqrt(2*pi)*sigma) * exp(-(x*x)/(2*sigma*sigma));
    return y;
}

canonical_original_code:
float gauss(float sigma, float x)
{
    float pi = 3.1415927;
    float y;
    y = 1.0f / (sqrt(2*pi)*sigma) * exp(-(x*x)/(2*sigma*sigma));
    return y;
}

variable_types: sigma float

variable_types: pi float

variable_types: y float


decompiled_code:
float __fastcall gauss2(float a1, float a2, float a3)
{
return 1.0
/ (a1
* 2.506628309507644)
* exp((float)(COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(a2 * a2) + (float)(a3 * a3)) ^ LC3)
/ (float)((float)(a1 + a1) * a1)));
}

canonical_decompiled_code:
float __fastcall func21(float a1, float a2, float a3)
{
return 1.0
/ (a1
* 2.506628309507644)
* exp((float)(COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(a2 * a2) + (float)(a3 * a3)) ^ LC3)
/ (float)((float)(a1 + a1) * a1)));
}

original_code:
float32 gauss2(float32 sigma, float32 x, float32 y)
{
    float32 pi = 3.1415927;
    float32 g;
    g = 1.0f / (sqrt(2*pi)*sigma) * exp(-(x*x +y*y)/(2*sigma*sigma));
    return g;
}

canonical_original_code:
float gauss2(float sigma, float x, float y)
{
    float pi = 3.1415927;
    float g;
    g = 1.0f / (sqrt(2*pi)*sigma) * exp(-(x*x +y*y)/(2*sigma*sigma));
    return g;
}

variable_types: g float


cpp

decompiled_code:
double __fastcall cpp(int a1, double a2)
{
return a2 * 2300000000.0 / (double)a1;
}

canonical_decompiled_code:
double __fastcall func22(int a1, double a2)
{
return a2 * 2300000000.0 / (double)a1;
}

original_code:
double cpp(double t, int n)
{
    double c = n;
    double cpp = t * 2.3e9 / c;
    return cpp;
}

variable_types: t double

variable_types: n int

variable_types: c double

variable_types: cpp double

return_type: double


decompiled_code:
__int64 alloc_ui8lut()
{
return ui8vector(0LL, 255LL);
}

canonical_decompiled_code:
__int64 func0()
{
return ui8vector(0LL, 255LL);
}

original_code:
uint8* alloc_ui8lut(void)
{
    return ui8vector(0, 255);
}

canonical_original_code:
unsigned char *alloc_ui8lut()
{
    return ui8vector(0, 255);
}

return_type: unsigned char *


decompiled_code:
__int64 __fastcall free_ui8lut(__int64 a1)
{
return free_ui8vector(a1, 0LL, 255LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return free_ui8vector(a1, 0LL, 255LL);
}

original_code:
void free_ui8lut(uint8 *L)
{
    free_ui8vector(L, 0, 255);
}

canonical_original_code:
void free_ui8lut(unsigned char *L)
{
    free_ui8vector(L, 0, 255);
}

variable_types:
L
unsigned char *


decompiled_code:
__int64 __fastcall zero_ui8lut(__int64 a1)
{
return zero_ui8vector(a1, 0LL, 255LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return zero_ui8vector(a1, 0LL, 255LL);
}

original_code:
void zero_ui8lut(uint8 *L)
{
    zero_ui8vector(L, 0, 255);
}

canonical_original_code:
void zero_ui8lut(unsigned char *L)
{
    zero_ui8vector(L, 0, 255);
}


decompiled_code:
__int64 __fastcall display_ui8lut(__int64 a1, __int64 a2, __int64 a3)
{
return display_ui8vector(a1, 0LL, 255LL, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
return display_ui8vector(a1, 0LL, 255LL, a2, a3);
}

original_code:
void display_ui8lut(uint8 *L, char *format, char *name)
{
    display_ui8vector(L, 0, 255, format, name);
}

canonical_original_code:
void display_ui8lut(unsigned char *L, char *format, char *name)
{
    display_ui8vector(L, 0, 255, format, name);
}

variable_types:
format
char *

variable_types:
name
char *


decompiled_code:
unsigned __int64 __fastcall init_ui8lut(_QWORD *a1, __int64 a2, unsigned __int8 a3)
{
unsigned __int64 *v5; // rcx
unsigned int v6; // edx
unsigned __int64 result; // rax
unsigned __int64 v8; // rdi

a2 = (unsigned __int8)a2;
if ( (_BYTE)a2 )
{
if ( (unsigned int)a2 >= 8 )
{
*a1 = 0LL;
v8 = (unsigned __int64)(a1 + 1);
*(_QWORD *)(v8 + a2 - 16) = 0LL;
memset(
(void *)(v8 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * (((unsigned int)a2 + (unsigned int)a1 - (v8 & 0xFFFFFFF8)) >> 3));
}
else if ( (a2 & 4) != 0 )
{
*(_DWORD *)a1 = 0;
*(_DWORD *)((char *)a1 + a2 - 4) = 0;
}
else
{
*(_BYTE *)a1 = 0;
if ( (a2 & 2) != 0 )
*(_WORD *)((char *)a1 + a2 - 2) = 0;
}
}
v5 = (_QWORD *)((char *)a1 + a2);
v6 = 256 - (unsigned __int8)a2;
result = 0x101010101010101LL * a3;
if ( v6 >= 8 )
{
*v5 = result;
*(unsigned __int64 *)((char *)v5 + v6 - 8) = result;
memset64(
(void *)((unsigned __int64)(v5 + 1) & 0xFFFFFFFFFFFFFFF8LL),
result,
(v6 + (_DWORD)v5 - (((_DWORD)v5 + 8) & 0xFFFFFFF8)) >> 3);
}
else if ( (v6 & 4) != 0 )
{
*(_DWORD *)v5 = result;
*(_DWORD *)((char *)v5 + v6 - 4) = result;
}
else if ( v6 )
{
*(_BYTE *)v5 = a3;
if ( (v6 & 2) != 0 )
*(_WORD *)((char *)v5 + v6 - 2) = result;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(_QWORD *a1, __int64 a2, unsigned __int8 a3)
{
unsigned __int64 *v5; // rcx
unsigned int v6; // edx
unsigned __int64 result; // rax
unsigned __int64 v8; // rdi

a2 = (unsigned __int8)a2;
if ( (_BYTE)a2 )
{
if ( (unsigned int)a2 >= 8 )
{
*a1 = 0LL;
v8 = (unsigned __int64)(a1 + 1);
*(_QWORD *)(v8 + a2 - 16) = 0LL;
memset(
(void *)(v8 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * (((unsigned int)a2 + (unsigned int)a1 - (v8 & 0xFFFFFFF8)) >> 3));
}
else if ( (a2 & 4) != 0 )
{
*(_DWORD *)a1 = 0;
*(_DWORD *)((char *)a1 + a2 - 4) = 0;
}
else
{
*(_BYTE *)a1 = 0;
if ( (a2 & 2) != 0 )
*(_WORD *)((char *)a1 + a2 - 2) = 0;
}
}
v5 = (_QWORD *)((char *)a1 + a2);
v6 = 256 - (unsigned __int8)a2;
result = 0x101010101010101LL * a3;
if ( v6 >= 8 )
{
*v5 = result;
*(unsigned __int64 *)((char *)v5 + v6 - 8) = result;
memset64(
(void *)((unsigned __int64)(v5 + 1) & 0xFFFFFFFFFFFFFFF8LL),
result,
(v6 + (_DWORD)v5 - (((_DWORD)v5 + 8) & 0xFFFFFFF8)) >> 3);
}
else if ( (v6 & 4) != 0 )
{
*(_DWORD *)v5 = result;
*(_DWORD *)((char *)v5 + v6 - 4) = result;
}
else if ( v6 )
{
*(_BYTE *)v5 = a3;
if ( (v6 & 2) != 0 )
*(_WORD *)((char *)v5 + v6 - 2) = result;
}
return result;
}

original_code:
void init_ui8lut(uint8 *L, uint8 threshold, uint8 value)
{
    int i;
    for(i=0; i<threshold; i++) {
        L[i] = 0;
    }
    for(i=threshold; i<=255; i++) {
        L[i] = value;
    }
}

canonical_original_code:
void init_ui8lut(unsigned char *L, unsigned char threshold, unsigned char value)
{
    int i;
    for(i=0; i<threshold; i++) {
        L[i] = 0;
    }
    for(i=threshold; i<=255; i++) {
        L[i] = value;
    }
}

variable_types:
threshold
unsigned char

variable_types:
value
unsigned char

variable_types: i int


original_code:
void apply_ui8lut(uint8 **X, int i0, int i1, int j0, int j1, uint8 *L, uint8 **Y)
{
    uint8 x, y;
    int i, j;
    for(i=i0; i<=i1; i++) {
        for(j=j0; j<=j1; j++) {
            x = X[i][j];
            y = L[x];
            Y[i][j] = y;
        }
    }
}

canonical_original_code:
void apply_ui8lut(unsigned char **X, int i0, int i1, int j0, int j1, unsigned char *L, unsigned char **Y)
{
    unsigned char x; unsigned char y;
    int i; int j;
    for(i=i0; i<=i1; i++) {
        for(j=j0; j<=j1; j++) {
            x = X[i][j];
            y = L[x];
            Y[i][j] = y;
        }
    }
}

variable_types:
X
unsigned char **

variable_types:
Y
unsigned char **

variable_types:
x
unsigned char

variable_types:
y
unsigned char

variable_types: j int


decompiled_code:
__int64 __fastcall binary_threshold_ui8matrix(__int64 a1, int a2, int a3, int a4, int a5, unsigned __int8 a6, __int64 a7)
{
_QWORD *v9; // rbp

v9 = (_QWORD *)alloc_ui8lut();
init_ui8lut(v9, a6, 1u);
apply_ui8lut(a1, a2, a3, a4, a5, (__int64)v9, a7);
return free_ui8lut((__int64)v9);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, int a3, int a4, int a5, unsigned __int8 a6, __int64 a7)
{
_QWORD *v9; // rbp

v9 = (_QWORD *)func0();
func4(v9, a6, 1u);
func5(a1, a2, a3, a4, a5, (__int64)v9, a7);
return func1((__int64)v9);
}

original_code:
void binary_threshold_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 threshold, uint8 **Y)
{
    uint8 *L;
    L = alloc_ui8lut();
    init_ui8lut(L, threshold, 1);
    apply_ui8lut(X, i0, i1, j0, j1, L, Y);
    free_ui8lut(L);
}

canonical_original_code:
void binary_threshold_ui8matrix(unsigned char **X, int i0, int i1, int j0, int j1, unsigned char threshold, unsigned char **Y)
{
    unsigned char *L;
    L = alloc_ui8lut();
    init_ui8lut(L, threshold, 1);
    apply_ui8lut(X, i0, i1, j0, j1, L, Y);
    free_ui8lut(L);
}


decompiled_code:
__int64 __fastcall threshold_ui8matrix(__int64 a1, int a2, int a3, int a4, int a5, unsigned __int8 a6, unsigned __int8 a7, __int64 a8)
{
_QWORD *v9; // rbp

v9 = (_QWORD *)alloc_ui8lut();
init_ui8lut(v9, a6, a7);
apply_ui8lut(a1, a2, a3, a4, a5, (__int64)v9, a8);
return free_ui8lut((__int64)v9);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, int a3, int a4, int a5, unsigned __int8 a6, unsigned __int8 a7, __int64 a8)
{
_QWORD *v9; // rbp

v9 = (_QWORD *)func0();
func4(v9, a6, a7);
func5(a1, a2, a3, a4, a5, (__int64)v9, a8);
return func1((__int64)v9);
}

original_code:
void threshold_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 threshold, uint8 value, uint8 **Y)
{
    uint8 *L;
    L = alloc_ui8lut();
    init_ui8lut(L, threshold, value);
    apply_ui8lut(X, i0, i1, j0, j1, L, Y);
    free_ui8lut(L);
}

canonical_original_code:
void threshold_ui8matrix(unsigned char **X, int i0, int i1, int j0, int j1, unsigned char threshold, unsigned char value, unsigned char **Y)
{
    unsigned char *L;
    L = alloc_ui8lut();
    init_ui8lut(L, threshold, value);
    apply_ui8lut(X, i0, i1, j0, j1, L, Y);
    free_ui8lut(L);
}


original_code:
void double_intensity_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 **Y)
{
    int j;
    uint8 *L;
    L = alloc_ui8lut();
    for(j=0; j<=127; j++) { L[j] = 2*j; }
    for(j=128; j<=255; j++) { L[j] = 255; }
    apply_ui8lut(X, i0, i1, j0, j1, L, Y);
    free_ui8lut(L);
}

canonical_original_code:
void double_intensity_ui8matrix(unsigned char **X, int i0, int i1, int j0, int j1, unsigned char **Y)
{
    int j;
    unsigned char *L;
    L = alloc_ui8lut();
    for(j=0; j<=127; j++) { L[j] = 2*j; }
    for(j=128; j<=255; j++) { L[j] = 255; }
    apply_ui8lut(X, i0, i1, j0, j1, L, Y);
    free_ui8lut(L);
}


decompiled_code:
__int64 __fastcall gray2bin_ui8matrix(__int64 a1, int a2, int a3, int a4, int a5, __int64 a6)
{
_QWORD *v9; // rbp

v9 = (_QWORD *)alloc_ui8lut();
init_ui8lut(v9, 1LL, 1u);
apply_ui8lut(a1, a2, a3, a4, a5, (__int64)v9, a6);
return free_ui8lut((__int64)v9);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3, int a4, int a5, __int64 a6)
{
_QWORD *v9; // rbp

v9 = (_QWORD *)func0();
func4(v9, 1LL, 1u);
func5(a1, a2, a3, a4, a5, (__int64)v9, a6);
return func1((__int64)v9);
}

original_code:
void gray2bin_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 **Y)
{
    uint8 *L;
    L = alloc_ui8lut();
    init_ui8lut(L, 1, 1);
    apply_ui8lut(X, i0, i1, j0, j1, L, Y);
    free_ui8lut(L);
}

canonical_original_code:
void gray2bin_ui8matrix(unsigned char **X, int i0, int i1, int j0, int j1, unsigned char **Y)
{
    unsigned char *L;
    L = alloc_ui8lut();
    init_ui8lut(L, 1, 1);
    apply_ui8lut(X, i0, i1, j0, j1, L, Y);
    free_ui8lut(L);
}