cdis

decompiled_code:
double __fastcall cdis(int a1, int a2)
{
double result; // xmm0_8
double *v3; // rdx
double v4; // xmm0_8

result = 0.0;
if ( (a1 + 1) % N != a2 && (a2 + 1) % N != a1 )
{
v3 = (double *)((char *)vlist + 24 * a1);
v4 = (v3[1] - *((double *)vlist + 3 * a2 + 1)) * (v3[1] - *((double *)vlist + 3 * a2 + 1))
+ (*v3 - *((double *)vlist + 3 * a2)) * (*v3 - *((double *)vlist + 3 * a2));
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
}
return result;
}

canonical_decompiled_code:
double __fastcall func10(int a1, int a2)
{
double result; // xmm0_8
double *v3; // rdx
double v4; // xmm0_8

result = 0.0;
if ( (a1 + 1) % N != a2 && (a2 + 1) % N != a1 )
{
v3 = (double *)((char *)vlist + 24 * a1);
v4 = (v3[1] - *((double *)vlist + 3 * a2 + 1)) * (v3[1] - *((double *)vlist + 3 * a2 + 1))
+ (*v3 - *((double *)vlist + 3 * a2)) * (*v3 - *((double *)vlist + 3 * a2));
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
}
return result;
}

original_code:
double cdis(int a, int b){
 if((a+1)%N==b)return 0;
 if((b+1)%N==a)return 0;
 return sqrt((vlist[a].x-vlist[b].x)*(vlist[a].x-vlist[b].x)+(vlist[a].y-vlist[b].y)*(vlist[a].y-vlist[b].y));
}

return_type: double


dps

repo: intijk/triangulation

decompiled_code:
double __fastcall dps(int a1, int a2)
{
return *(double *)(dpstatus + 8LL * (a2 + a1 * (N + 1)));
}

canonical_decompiled_code:
double __fastcall func11(int a1, int a2)
{
return *(double *)(dpstatus + 8LL * (a2 + a1 * (N + 1)));
}

original_code:
double dps(int s, int n){
 return dpstatus[s*(N+1)+n];
}

variable_types: s int

variable_types: n int


setdps

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

if ( dps(a1, a2) >= 0.1 )
{
puts("Status rewrite! Should not be here");
exit(-1);
}
result = dpstatus;
*(double *)(dpstatus + 8LL * (a2 + a1 * (N + 1))) = a3;
return result;
}

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

if ( func11(a1, a2) >= 0.1 )
{
puts("Status rewrite! Should not be here");
exit(-1);
}
result = dpstatus;
*(double *)(dpstatus + 8LL * (a2 + a1 * (N + 1))) = a3;
return result;
}

original_code:
void setdps(int s,int n,double mindis){
 if(dps(s,n)<0.1){
  dpstatus[s*(N+1)+n]=mindis;
 }else{
  printf("Status rewrite! Should not be here\n");
  exit(-1);
 }
}

canonical_original_code:
void setdps(int s, int n, double mindis){
 if(dps(s,n)<0.1){
  dpstatus[s*(N+1)+n]=mindis;
 }else{
  printf("Status rewrite! Should not be here\n");
  exit(-1);
 }
}

variable_types: mindis double

return_type: void


setdpind

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

result = a2 + a1 * (N + 1);
*(_DWORD *)(dpind + 4 * result) = a3;
return result;
}

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

result = a2 + a1 * (N + 1);
*(_DWORD *)(dpind + 4 * result) = a3;
return result;
}

original_code:
void setdpind(int s, int n, int mini){
 dpind[s*(N+1)+n]=mini;
}

variable_types: mini int


getdpind

decompiled_code:
__int64 __fastcall getdpind(int a1, int a2)
{
return *(unsigned int *)(dpind + 4LL * (a2 + a1 * (N + 1)));
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, int a2)
{
return *(unsigned int *)(dpind + 4LL * (a2 + a1 * (N + 1)));
}

original_code:
int getdpind(int s, int n){
 return dpind[s*(N+1)+n];
}

return_type: int


dp

original_code:
double dp(int s, int n){
 if(n<=3)return 0;
 double mindis=((double)1.79769313486231570814527423731704357e+308L);
 int mini=-1;
 if(dps(s,n)>0.0000001){
  return dps(s,n);
 }
 int k;
 for(k=1;k<=n-2;k++){
  double currentdis=cdis(s,(s+k)%N)+cdis((s+k)%N,(s+n-1)%N)+dp(s,k+1)+dp((s+k)%N,n-k);
  if(mindis>currentdis){
   mini=k;
   mindis=currentdis;
  }
 }
 setdpind(s,n,mini);
 setdps(s,n,mindis);
 return mindis;
}

canonical_original_code:
double dp(int s, int n){
 if(n<=3)return 0;
 double mindis = ((double)1.79769313486231570814527423731704357e+308L);
 int mini = -1;
 if(dps(s,n)>0.0000001){
  return dps(s,n);
 }
 int k;
 for(k=1;k<=n-2;k++){
  double currentdis = cdis(s,(s+k)%N)+cdis((s+k)%N,(s+n-1)%N)+dp(s,k+1)+dp((s+k)%N,n-k);
  if(mindis>currentdis){
   mini=k;
   mindis=currentdis;
  }
 }
 setdpind(s,n,mini);
 setdps(s,n,mindis);
 return mindis;
}

variable_types: k int

variable_types: currentdis double


recurRecordEdge

decompiled_code:
int __fastcall recurRecordEdge(unsigned int a1, int a2)
{
int result; // eax
int v3; // er13

result = printf("s=%d n=%d\n", a1, (unsigned int)a2);
if ( a2 > 3 )
{
v3 = getdpind(a1, a2);
recordEdge(a1, (int)(a1 + v3) % N);
recordEdge((int)(a1 + v3) % N, (int)(a1 + a2 - 1) % N);
recurRecordEdge(a1, (unsigned int)(v3 + 1));
result = recurRecordEdge((unsigned int)((int)(a1 + v3) % N), (unsigned int)(a2 - v3));
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(unsigned int a1, int a2)
{
int result; // eax
int v3; // er13

result = printf("s=%d n=%d\n", a1, (unsigned int)a2);
if ( a2 > 3 )
{
v3 = func14(a1, a2);
func9(a1, (int)(a1 + v3) % N);
func9((int)(a1 + v3) % N, (int)(a1 + a2 - 1) % N);
func16(a1, (unsigned int)(v3 + 1));
result = func16((unsigned int)((int)(a1 + v3) % N), (unsigned int)(a2 - v3));
}
return result;
}

original_code:
void recurRecordEdge(int s,int n){
 printf("s=%d n=%d\n", s, n);
 if(n<=3)return ;
 int mini=getdpind(s,n);
 recordEdge(s, (s+mini)%N);
 recordEdge((s+mini)%N, (s+n-1)%N);
 recurRecordEdge(s,mini+1);
 recurRecordEdge((s+mini)%N, n-mini);
}

canonical_original_code:
void recurRecordEdge(int s, int n){
 printf("s=%d n=%d\n", s, n);
 if(n<=3)return ;
 int mini = getdpind(s,n);
 recordEdge(s, (s+mini)%N);
 recordEdge((s+mini)%N, (s+n-1)%N);
 recurRecordEdge(s,mini+1);
 recurRecordEdge((s+mini)%N, n-mini);
}


outputEdge

decompiled_code:
int outputEdge()
{
int v0; // ebx
_DWORD *v1; // rax
_DWORD *v2; // r12
__int64 v3; // r14
__int64 i; // r13
__int64 v5; // rbx
const char *v6; // rdx
__int64 v7; // rax
_DWORD *v8; // rdx
int v9; // ebx
int v10; // ebp

printf("%d\n", (unsigned int)N);
v0 = N;
v1 = malloc(4LL * N);
if ( v0 > 0 )
{
v2 = v1;
v3 = 0LL;
for ( i = 0LL; N > (int)i; ++i )
{
v7 = *(_QWORD *)(adjList + 8 * i);
if ( v7 )
{
v8 = v2;
v9 = 0;
do
{
v10 = v9++;
*v8 = *(_DWORD *)v7;
v7 = *(_QWORD *)(v7 + 8);
++v8;
}
while ( v7 );
qsort(v2, v9, 4uLL, (__compar_fn_t)compf);
printf("%f %f ", *(double *)((char *)vlist + v3), *(double *)((char *)vlist + v3 + 8));
if ( v9 )
{
LODWORD(v1) = printf("%d%s", (unsigned int)v9, " ");
if ( v9 > 0 )
{
v5 = 0LL;
do
{
v6 = " ";
if ( v10 == (_DWORD)v5 )
v6 = "s=%d n=%d\n" + 9;
printf("%d%s", (unsigned int)v2[v5++], v6);
LODWORD(v1) = v5 - 1;
}
while ( (int)v5 - 1 < v10 );
}
goto LABEL_8;
}
}
else
{
qsort(v2, 0LL, 4uLL, (__compar_fn_t)compf);
printf("%f %f ", *(double *)((char *)vlist + v3), *(double *)((char *)vlist + v3 + 8));
v9 = 0;
}
LODWORD(v1) = printf("%d%s", (unsigned int)v9, "\n");
LABEL_8:
v3 += 24LL;
}
}
return (int)v1;
}

canonical_decompiled_code:
int func17()
{
int v0; // ebx
_DWORD *v1; // rax
_DWORD *v2; // r12
__int64 v3; // r14
__int64 i; // r13
__int64 v5; // rbx
const char *v6; // rdx
__int64 v7; // rax
_DWORD *v8; // rdx
int v9; // ebx
int v10; // ebp

printf("%d\n", (unsigned int)N);
v0 = N;
v1 = malloc(4LL * N);
if ( v0 > 0 )
{
v2 = v1;
v3 = 0LL;
for ( i = 0LL; N > (int)i; ++i )
{
v7 = *(_QWORD *)(adjList + 8 * i);
if ( v7 )
{
v8 = v2;
v9 = 0;
do
{
v10 = v9++;
*v8 = *(_DWORD *)v7;
v7 = *(_QWORD *)(v7 + 8);
++v8;
}
while ( v7 );
qsort(v2, v9, 4uLL, (__compar_fn_t)compf);
printf("%f %f ", *(double *)((char *)vlist + v3), *(double *)((char *)vlist + v3 + 8));
if ( v9 )
{
LODWORD(v1) = printf("%d%s", (unsigned int)v9, " ");
if ( v9 > 0 )
{
v5 = 0LL;
do
{
v6 = " ";
if ( v10 == (_DWORD)v5 )
v6 = "s=%d n=%d\n" + 9;
printf("%d%s", (unsigned int)v2[v5++], v6);
LODWORD(v1) = v5 - 1;
}
while ( (int)v5 - 1 < v10 );
}
goto LABEL_8;
}
}
else
{
qsort(v2, 0LL, 4uLL, (__compar_fn_t)compf);
printf("%f %f ", *(double *)((char *)vlist + v3), *(double *)((char *)vlist + v3 + 8));
v9 = 0;
}
LODWORD(v1) = printf("%d%s", (unsigned int)v9, "\n");
LABEL_8:
v3 += 24LL;
}
}
return (int)v1;
}

original_code:
void outputEdge()
{
 printf("%d\n", N);
 int *sortSpace=(int*)malloc(sizeof(int)*N);
 adjNode *npt;
 int i,j,c;
 for(i=0;i<N;i++){
  c=0;
  npt=adjList[i];
  while(npt!=((void *)0)){
   sortSpace[c++]=npt->n;
   npt=npt->next;
  }
  qsort(sortSpace,c,sizeof(int),compf);
  printf("%f %f ", vlist[i].x,vlist[i].y);
  printf("%d%s",c,c==0?"\n":" ");
  for(j=0;j<c;j++){
   printf("%d%s",sortSpace[j], j==c-1?"\n":" ");
  }
 }
}

canonical_original_code:
void outputEdge()
{
 printf("%d\n", N);
 int *sortSpace = (int*)malloc(sizeof(int)*N);
 struct adjNode *npt;
 int i; int j; int c;
 for(i=0;i<N;i++){
  c=0;
  npt=adjList[i];
  while(npt!=((void *)0)){
   sortSpace[c++]=npt->n;
   npt=npt->next;
  }
  qsort(sortSpace,c,sizeof(int),compf);
  printf("%f %f ", vlist[i].x,vlist[i].y);
  printf("%d%s",c,c==0?"\n":" ");
  for(j=0;j<c;j++){
   printf("%d%s",sortSpace[j], j==c-1?"\n":" ");
  }
 }
}

variable_types:
sortSpace
int *

variable_types: struct adjNode { int n; struct adjNode *next; } *

variable_types: i int

variable_types: j int

variable_types: c int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx
char *v4; // rax
_QWORD *v5; // rbx
size_t v6; // rbp
__int64 v7; // rbp
void *v8; // rdi
int v9; // ebp
int v10; // ebx
int v11; // edi
size_t v12; // rbx
size_t v13; // r14
void *v14; // r13
void *v15; // r12
double v16; // xmm0_8
unsigned __int64 v18; // [rsp+0h] [rbp-38h]
__int64 v19; // [rsp+8h] [rbp-30h]

__isoc99_scanf();
v3 = malloc(0x18uLL);
vlist = v3;
*v3 = v19;
*(_OWORD *)(v3 + 1) = v18;
N = 1;
while ( (unsigned int)__isoc99_scanf() == 2 )
{
v4 = (char *)malloc(0x18uLL);
*(_QWORD *)v4 = v19;
*(_OWORD *)(v4 + 8) = v18;
v3[2] = v4;
++N;
v3 = v4;
}
v5 = vlist;
v6 = 24LL * N;
vlist = malloc(v6);
memset(vlist, 0, v6);
if ( v5 )
{
v7 = 0LL;
do
{
*(_QWORD *)((char *)vlist + v7) = *v5;
*(_QWORD *)((char *)vlist + v7 + 8) = v5[1];
v8 = v5;
v5 = (_QWORD *)v5[2];
free(v8);
v7 += 24LL;
}
while ( v5 );
}
v9 = N;
if ( N > 0 )
{
v10 = 0;
do
{
v11 = v10++;
recordEdge(v11, v10 % v9);
v9 = N;
}
while ( v10 < N );
}
v12 = v9 * (__int64)(v9 + 1);
v13 = 8 * v12;
v14 = malloc(8 * v12);
dpstatus = (__int64)v14;
v12 *= 4LL;
v15 = malloc(v12);
dpind = (__int64)v15;
memset(v14, 0, v13);
memset(v15, 0, v12);
v16 = dp(0, v9);
printf("%f\n", v16);
recurRecordEdge(0, N);
outputEdge();
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
 double x,y;
 vertex *last;
 scanf("%lf%lf", &x,&y);
 last=vlist=(vertex*)malloc(sizeof(vertex));
 vlist->x=x;
 vlist->y=y;
 vlist->next=((void *)0);
 N=1;
 while(scanf("%lf%lf", &x,&y)==2){
  vertex *v=(vertex*)malloc(sizeof(vertex));
  v->x=x,v->y=y;
  v->next=((void *)0);
  last->next=v;
  last=v;
  N++;
 }
 last=vlist;
 vlist=(vertex*)malloc(sizeof(vertex)*N);
 memset(vlist,0,sizeof(vertex)*N);
 vertex *llast;
 int i=0;
 while(last){
  llast=last;
  vlist[i].x=last->x;
  vlist[i].y=last->y;
  last=last->next;
  free(llast);
  i++;
 }
 for(i=0;i<N;i++){
  recordEdge(i,(i+1)%N);
 }
 dpstatus=(double*)malloc(sizeof(double)*(N+1)*N);
 dpind=(int*)malloc(sizeof(int)*(N+1)*N);
 memset(dpstatus,0,sizeof(double)*(N+1)*N);
 memset(dpind,0,sizeof(int)*(N+1)*N);
 printf("%f\n",dp(0, N));
 recurRecordEdge(0,N);
 outputEdge();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 double x; double y;
 struct vertex *last;
 scanf("%lf%lf", &x,&y);
 last=vlist=(struct vertex *)malloc(sizeof(vertex));
 vlist->x=x;
 vlist->y=y;
 vlist->next=((void *)0);
 N=1;
 while(scanf("%lf%lf", &x,&y)==2){
  struct vertex *v = (vertex*)malloc(sizeof(vertex));
  v->x=x,v->y=y;
  v->next=((void *)0);
  last->next=v;
  last=v;
  N++;
 }
 last=vlist;
 vlist=(struct vertex *)malloc(sizeof(vertex)*N);
 memset(vlist,0,sizeof(vertex)*N);
 struct vertex *llast;
 int i = 0;
 while(last){
  llast=last;
  vlist[i].x=last->x;
  vlist[i].y=last->y;
  last=last->next;
  free(llast);
  i++;
 }
 for(i=0;i<N;i++){
  recordEdge(i,(i+1)%N);
 }
 dpstatus=(double *)malloc(sizeof(double)*(N+1)*N);
 dpind=(int *)malloc(sizeof(int)*(N+1)*N);
 memset(dpstatus,0,sizeof(double)*(N+1)*N);
 memset(dpind,0,sizeof(int)*(N+1)*N);
 printf("%f\n",dp(0, N));
 recurRecordEdge(0,N);
 outputEdge();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: x double

variable_types: y double

variable_types: struct vertex { double x; struct vertex *next; } *


comp

decompiled_code:
__int64 __fastcall comp(const void *a1, const void *a2)
{
double v2; // xmm0_8
__int64 result; // rax

v2 = (*(double *)a1 - *(double *)vlist) * (*((double *)a2 + 1) - *((double *)vlist + 1))
- (*(double *)a2 - *(double *)vlist) * (*((double *)a1 + 1) - *((double *)vlist + 1));
result = 0xFFFFFFFFLL;
if ( v2 <= 0.0 )
result = v2 != 0.0;
return result;
}

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

v2 = (*(double *)a1 - *(double *)vlist) * (*((double *)a2 + 1) - *((double *)vlist + 1))
- (*(double *)a2 - *(double *)vlist) * (*((double *)a1 + 1) - *((double *)vlist + 1));
result = 0xFFFFFFFFLL;
if ( v2 <= 0.0 )
result = v2 != 0.0;
return result;
}

original_code:
int comp(const void *a, const void *b)
{
 vertex p1,p2;
 p1.x=((vertex*)a)->x-vlist[0].x;
 p1.y=((vertex*)a)->y-vlist[0].y;
 p2.x=((vertex*)b)->x-vlist[0].x;
 p2.y=((vertex*)b)->y-vlist[0].y;
 if(p1.x*p2.y-p1.y*p2.x>0)return -1;
 if(p1.x*p2.y-p1.y*p2.x==0)return 0;
 if(p1.x*p2.y-p1.y*p2.x<0)return 1;
}

canonical_original_code:
int comp(void *a, void *b)
{
 struct vertex p1; struct vertex p2;
 p1.x=((struct vertex *)a)->x-vlist[0].x;
 p1.y=((struct vertex *)a)->y-vlist[0].y;
 p2.x=((struct vertex *)b)->x-vlist[0].x;
 p2.y=((struct vertex *)b)->y-vlist[0].y;
 if(p1.x*p2.y-p1.y*p2.x>0)return -1;
 if(p1.x*p2.y-p1.y*p2.x==0)return 0;
 if(p1.x*p2.y-p1.y*p2.x<0)return 1;
}

variable_types:
a
void *

variable_types:
b
void *


main

original_code:
int main(int argc, const char *argv[])
{
 double x, y, miny=((double)1.79769313486231570814527423731704357e+308L), minp_x=((double)1.79769313486231570814527423731704357e+308L);
 vlist=(vertex*)malloc(sizeof(vertex));
 int i;
 while(scanf("%lf%lf",&x,&y)==2){
  N++;
  vlist=(vertex*)realloc(vlist, sizeof(vertex)*N);
  vlist[N-1].x=x,vlist[N-1].y=y;
  if(y<miny || y==miny && x<minp_x)
  {
   p0=N-1;
   miny=y;
   minp_x=x;
  }
 }
 vertex tmp=vlist[0];
 vlist[0]=vlist[p0];
 vlist[p0]=tmp;
 qsort(vlist+1, N-1, sizeof(vertex), comp);
 hlist=(vertex*)malloc(sizeof(vertex)*3);
 hlist[0]=vlist[0];
 hlist[1]=vlist[1];
 hlist[2]=vlist[2];
 int hi=2;
 for(i=3;i<N;i++){
  if(turnNonLeft(hlist[hi-1],hlist[hi],vlist[i])){
   hlist[hi]=vlist[i];
   while(turnNonLeft(hlist[hi-2],hlist[hi-1],hlist[hi])){
    hi--;
    hlist[hi]=hlist[hi+1];
   }
  }else{
   hi++;
   hlist=realloc(hlist,sizeof(vertex)*(hi+1));
   hlist[hi]=vlist[i];
  }
 }
 for(i=0;i<=hi;i++){
  printf("%f %f\n", hlist[i]);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 double x; double y; double miny = ((double)1.79769313486231570814527423731704357e+308L); double minp_x = ((double)1.79769313486231570814527423731704357e+308L);
 vlist=(struct vertex *)malloc(sizeof(vertex));
 int i;
 while(scanf("%lf%lf",&x,&y)==2){
  N++;
  vlist=(struct vertex *)realloc(vlist, sizeof(vertex)*N);
  vlist[N-1].x=x,vlist[N-1].y=y;
  if(y<miny || y==miny && x<minp_x)
  {
   p0=N-1;
   miny=y;
   minp_x=x;
  }
 }
 struct vertex tmp = vlist[0];
 vlist[0]=vlist[p0];
 vlist[p0]=tmp;
 qsort(vlist+1, N-1, sizeof(vertex), comp);
 hlist=(struct vertex *)malloc(sizeof(vertex)*3);
 hlist[0]=vlist[0];
 hlist[1]=vlist[1];
 hlist[2]=vlist[2];
 int hi = 2;
 for(i=3;i<N;i++){
  if(turnNonLeft(hlist[hi-1],hlist[hi],vlist[i])){
   hlist[hi]=vlist[i];
   while(turnNonLeft(hlist[hi-2],hlist[hi-1],hlist[hi])){
    hi--;
    hlist[hi]=hlist[hi+1];
   }
  }else{
   hi++;
   hlist=realloc(hlist,sizeof(vertex)*(hi+1));
   hlist[hi]=vlist[i];
  }
 }
 for(i=0;i<=hi;i++){
  printf("%f %f\n", hlist[i]);
 }
 return 0;
}

variable_types: miny double

variable_types:
tmp
struct vertex { double x; }

variable_types: hi int


finishDraw

decompiled_code:
__int64 finishDraw()
{
cairo_show_page();
cairo_destroy();
cairo_surface_flush();
return cairo_surface_destroy();
}

canonical_decompiled_code:
__int64 func8()
{
cairo_show_page();
cairo_destroy();
cairo_surface_flush();
return cairo_surface_destroy();
}

original_code:
void finishDraw(){
 cairo_show_page(cr);
 cairo_destroy(cr);
 cairo_surface_flush(cs);
 cairo_surface_destroy(cs);
}


drawLine

decompiled_code:
__int64 drawLine()
{
cairo_set_source_rgb();
cairo_move_to();
cairo_line_to();
return cairo_stroke();
}

canonical_decompiled_code:
__int64 func9()
{
cairo_set_source_rgb();
cairo_move_to();
cairo_line_to();
return cairo_stroke();
}

original_code:
void drawLine(int a, int b){
 cairo_set_source_rgb (cr, 0, 0, 0);
 cairo_move_to(cr,vlist[a].x,vlist[a].y);
 cairo_line_to(cr,vlist[b].x,vlist[b].y);
 cairo_stroke(cr);
}

variable_types: a int

variable_types: b int


drawTri

decompiled_code:
__int64 __fastcall drawTri(unsigned int a1, unsigned int a2, unsigned int a3)
{
printf(
"draw triangulor on: %d %d %d (%f,%f)(%f,%f)(%f,%f)\n",
a1,
a2,
a3,
*((double *)vlist + 2 * (int)a1),
*((double *)vlist + 2 * (int)a1 + 1),
*((double *)vlist + 2 * (int)a2),
*((double *)vlist + 2 * (int)a2 + 1),
*((double *)vlist + 2 * (int)a3),
*((double *)vlist + 2 * (int)a3 + 1));
cairo_set_source_rgb();
currentColor_0 = (currentColor_0 + 1) % palletSize;
cairo_move_to();
cairo_line_to();
cairo_line_to();
cairo_close_path();
cairo_fill();
cairo_set_source_rgb();
cairo_move_to();
cairo_line_to();
cairo_line_to();
cairo_close_path();
return cairo_stroke();
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, unsigned int a2, unsigned int a3)
{
printf(
"draw triangulor on: %d %d %d (%f,%f)(%f,%f)(%f,%f)\n",
a1,
a2,
a3,
*((double *)vlist + 2 * (int)a1),
*((double *)vlist + 2 * (int)a1 + 1),
*((double *)vlist + 2 * (int)a2),
*((double *)vlist + 2 * (int)a2 + 1),
*((double *)vlist + 2 * (int)a3),
*((double *)vlist + 2 * (int)a3 + 1));
cairo_set_source_rgb();
currentColor_0 = (currentColor_0 + 1) % palletSize;
cairo_move_to();
cairo_line_to();
cairo_line_to();
cairo_close_path();
cairo_fill();
cairo_set_source_rgb();
cairo_move_to();
cairo_line_to();
cairo_line_to();
cairo_close_path();
return cairo_stroke();
}

original_code:
void drawTri(int a,int b,int c){
 printf("draw triangulor on: %d %d %d (%f,%f)(%f,%f)(%f,%f)\n",
   a,b,c,vlist[a].x,vlist[a].y,vlist[b].x,vlist[b].y,vlist[c].x,vlist[c].y);
 static int currentColor=0;
 cairo_set_source_rgb (cr, pallet[currentColor][0]/255.0, pallet[currentColor][1]/255.0, pallet[currentColor][2]/255.0);
 currentColor=(currentColor+1)%palletSize;
 cairo_move_to(cr,vlist[a].x,vlist[a].y);
 cairo_line_to(cr,vlist[b].x,vlist[b].y);
 cairo_line_to(cr,vlist[c].x,vlist[c].y);
 cairo_close_path(cr);
 cairo_fill(cr);
 cairo_set_source_rgb (cr, 0, 0, 0);
 cairo_move_to(cr,vlist[a].x,vlist[a].y);
 cairo_line_to(cr,vlist[b].x,vlist[b].y);
 cairo_line_to(cr,vlist[c].x,vlist[c].y);
 cairo_close_path(cr);
 cairo_stroke(cr);
}

canonical_original_code:
void drawTri(int a, int b, int c){
 printf("draw triangulor on: %d %d %d (%f,%f)(%f,%f)(%f,%f)\n",
   a,b,c,vlist[a].x,vlist[a].y,vlist[b].x,vlist[b].y,vlist[c].x,vlist[c].y);
 static int currentColor = 0;
 cairo_set_source_rgb (cr, pallet[currentColor][0]/255.0, pallet[currentColor][1]/255.0, pallet[currentColor][2]/255.0);
 currentColor=(currentColor+1)%palletSize;
 cairo_move_to(cr,vlist[a].x,vlist[a].y);
 cairo_line_to(cr,vlist[b].x,vlist[b].y);
 cairo_line_to(cr,vlist[c].x,vlist[c].y);
 cairo_close_path(cr);
 cairo_fill(cr);
 cairo_set_source_rgb (cr, 0, 0, 0);
 cairo_move_to(cr,vlist[a].x,vlist[a].y);
 cairo_line_to(cr,vlist[b].x,vlist[b].y);
 cairo_line_to(cr,vlist[c].x,vlist[c].y);
 cairo_close_path(cr);
 cairo_stroke(cr);
}

variable_types: currentColor int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ecx
int v4; // ebx
__int64 v5; // rdi
double v7; // [rsp+0h] [rbp-18h]
double v8[2]; // [rsp+8h] [rbp-10h] BYREF

vlist = malloc(0x10uLL);
maxx = 0x10000000000000LL;
maxy = 0x10000000000000LL;
minx = 0x7FEFFFFFFFFFFFFFLL;
miny = 0x7FEFFFFFFFFFFFFFLL;
while ( (unsigned int)__isoc99_scanf() == 2 )
{
printf("x=%f y=%f\n", v8[0], v7);
maxx = fmax(v8[0], *(double *)&maxx);
minx = fmin(v8[0], *(double *)&minx);
maxy = fmax(v7, *(double *)&maxy);
miny = fmin(v7, *(double *)&miny);
vlist = realloc(vlist, 16LL * ++N);
*((double *)vlist + 2 * N - 2) = v8[0];
*((double *)vlist + 2 * N - 1) = v7;
}
printf("minx=%f miny=%f maxx=%f maxy=%f\n", *(double *)&minx, *(double *)&miny, *(double *)&maxx, *(double *)&maxy);
initDraw("minx=%f miny=%f maxx=%f maxy=%f\n", v8);
v3 = N;
if ( N > 0 )
{
v4 = 0;
do
{
v5 = (unsigned int)v4++;
drawLine(v5, (unsigned int)(v4 % v3));
v3 = N;
}
while ( v4 < N );
}
finishDraw();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ecx
int v4; // ebx
__int64 v5; // rdi
double v7; // [rsp+0h] [rbp-18h]
double v8[2]; // [rsp+8h] [rbp-10h] BYREF

vlist = malloc(0x10uLL);
maxx = 0x10000000000000LL;
maxy = 0x10000000000000LL;
minx = 0x7FEFFFFFFFFFFFFFLL;
miny = 0x7FEFFFFFFFFFFFFFLL;
while ( (unsigned int)__isoc99_scanf() == 2 )
{
printf("x=%f y=%f\n", v8[0], v7);
maxx = fmax(v8[0], *(double *)&maxx);
minx = fmin(v8[0], *(double *)&minx);
maxy = fmax(v7, *(double *)&maxy);
miny = fmin(v7, *(double *)&miny);
vlist = realloc(vlist, 16LL * ++N);
*((double *)vlist + 2 * N - 2) = v8[0];
*((double *)vlist + 2 * N - 1) = v7;
}
printf("minx=%f miny=%f maxx=%f maxy=%f\n", *(double *)&minx, *(double *)&miny, *(double *)&maxx, *(double *)&maxy);
func7("minx=%f miny=%f maxx=%f maxy=%f\n", v8);
v3 = N;
if ( N > 0 )
{
v4 = 0;
do
{
v5 = (unsigned int)v4++;
func9(v5, (unsigned int)(v4 % v3));
v3 = N;
}
while ( v4 < N );
}
func8();
return 0;
}

variable_types: n int

variable_types: p int


mystrlen

decompiled_code:
__int64 __fastcall mystrlen(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int mystrlen(char *str)
{
    int len = 0;
    while(str[len] != '\0')
    {
       len++;
    }
    return len;
}

variable_types:
str
char *

variable_types: len int


mystrcmp

decompiled_code:
__int64 __fastcall mystrcmp(char *a1, char *a2)
{
char v2; // dl
char v3; // cl
__int64 v4; // rax

v2 = *a1;
v3 = *a2;
if ( *a1 && v2 == v3 )
{
v4 = 1LL;
do
{
v2 = a1[v4];
v3 = a2[v4++];
}
while ( v2 && v2 == v3 );
}
return (unsigned int)(v2 - v3);
}

original_code:
int mystrcmp(char *str1, char *str2)
{
    while(*str1 == *str2 && *str1 != '\0')
    {
        str1++;
        str2++;
    }
    return (*str1 - *str2);
}


mystrstr

decompiled_code:
_BOOL8 __fastcall mystrstr(char *a1, _BYTE *a2)
{
char v2; // dl
__int64 v3; // rax

v2 = *a1;
if ( *a1 == *a2 )
{
v3 = 1LL;
do
v2 = a1[v3++];
while ( v2 == a2[v3 - 1] );
}
return v2 == 0;
}

original_code:
int mystrstr(char *str1, char *str2)
{
    while(*str1 == *str2)
    {
        str1++;
        str2++;
    }
    if(*str1 == '\0')
    {
        return 1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall custom_printstring(char *a1)
{
char *v1; // rbx
char v2; // di

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
++v1;
custom_iowrite((unsigned int)v2);
v2 = *v1;
}
while ( *v1 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
char *v1; // rbx
char v2; // di

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
++v1;
custom_iowrite((unsigned int)v2);
v2 = *v1;
}
while ( *v1 );
}
return 0LL;
}

original_code:
int custom_printstring(char *str)
{
    while(*str != '\0')
    {
      custom_iowrite(*str++);
    }
    return 0;
}


clearscreen

decompiled_code:
__int64 clearscreen()
{
char v1[16]; // [rsp+8h] [rbp-10h] BYREF

strcpy(v1, "\x1B[H\x1B[2J");
custom_printstring(&v1[3]);
return custom_printstring(v1);
}

canonical_decompiled_code:
__int64 func4()
{
char v1[16]; // [rsp+8h] [rbp-10h] BYREF

strcpy(v1, "\x1B[H\x1B[2J");
func3(&v1[3]);
return func3(v1);
}

original_code:
void clearscreen(void)
{
    char clearScreenSeq[] = {0x1B, '[', '2', 'J', 0x00};
    char cursorHomeSeq[] = {0x1B, '[', 'H'};
    custom_printstring(clearScreenSeq);
    custom_printstring(cursorHomeSeq);
    return;
}

canonical_original_code:
void clearscreen()
{
    char clearScreenSeq[] = {0x1B, '[', '2', 'J', 0x00};
    char cursorHomeSeq[] = {0x1B, '[', 'H'};
    custom_printstring(clearScreenSeq);
    custom_printstring(cursorHomeSeq);
    return;
}

variable_types:
clearScreenSeq
char []

variable_types:
cursorHomeSeq
char []


myprintinteger

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

if ( a1 )
{
myprintinteger((unsigned int)(a1 / 10), 0LL);
result = custom_iowrite((unsigned int)(char)(a1 % 10 + 48));
}
else if ( a2 )
{
result = custom_iowrite(48LL);
}
return result;
}

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

if ( a1 )
{
func5((unsigned int)(a1 / 10), 0LL);
result = custom_iowrite((unsigned int)(char)(a1 % 10 + 48));
}
else if ( a2 )
{
result = custom_iowrite(48LL);
}
return result;
}

original_code:
void myprintinteger(int number, unsigned char iStart)
{
    unsigned char digit;
    if(number == 0)
    {
        if(iStart)
        {
            custom_iowrite('0');
        }
        return;
    }
    digit = (number % 10) + 0x30;
    myprintinteger(number/10, 0);
    custom_iowrite(digit);
    return;
}

variable_types: number int

variable_types:
iStart
unsigned char

variable_types:
digit
unsigned char


mypower

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

result = 1LL;
if ( a2 )
result = (unsigned int)a1 * (unsigned int)mypower(a1, (unsigned int)(a2 - 1));
return result;
}

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

result = 1LL;
if ( a2 )
result = (unsigned int)a1 * (unsigned int)func6(a1, (unsigned int)(a2 - 1));
return result;
}

original_code:
int mypower(int x, int y)
{
    if(y == 0)
    {
        return 1;
    }
    return (x*mypower(x, y-1));
}

variable_types: x int

variable_types: y int


myatoi

variable_types: base int

variable_types:
result
int *

variable_types: iVal int

return_type: enum RET_CODE { SUCCESS=0, CMD_FAIL=1, CMD_FAILQUIET=2, NULL_ERR=3, BASE_ERR=4, PARSE_ERR=5, PARAM_ERR=6, PARAM1_ERR=7, PARAM2_ERR=8, PARAM3_ERR=9, PARAM4_ERR=10, EXIT_CODE=11 }


disableEchoCanonMode

decompiled_code:
int __fastcall disableEchoCanonMode(struct termios *termios_p)
{
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, termios_p);
*(__m128i *)&v2.c_iflag = _mm_loadu_si128((const __m128i *)termios_p);
*(__m128i *)&v2.c_line = _mm_loadu_si128((const __m128i *)&termios_p->c_line);
*(__m128i *)&v2.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p->c_cc[15]);
*(_QWORD *)&v2.c_cc[31] = *(_QWORD *)&termios_p->c_cc[31];
v2.c_ospeed = termios_p->c_ospeed;
v2.c_lflag &= 0xFFFFFFF5;
return tcsetattr(0, 0, &v2);
}

canonical_decompiled_code:
int __fastcall func8(struct termios *termios_p)
{
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, termios_p);
*(__m128i *)&v2.c_iflag = _mm_loadu_si128((const __m128i *)termios_p);
*(__m128i *)&v2.c_line = _mm_loadu_si128((const __m128i *)&termios_p->c_line);
*(__m128i *)&v2.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p->c_cc[15]);
*(_QWORD *)&v2.c_cc[31] = *(_QWORD *)&termios_p->c_cc[31];
v2.c_ospeed = termios_p->c_ospeed;
v2.c_lflag &= 0xFFFFFFF5;
return tcsetattr(0, 0, &v2);
}

original_code:
void disableEchoCanonMode(struct termios *oldSettings)
{
    struct termios newSettings;
    tcgetattr(0, oldSettings);
    newSettings = *oldSettings;
    newSettings.c_lflag &= ~(0000002 | 0000010);
    tcsetattr(0, 0, &newSettings);
    return;
}

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


restoreTerminalMode

decompiled_code:
int __fastcall restoreTerminalMode(struct termios *termios_p)
{
return tcsetattr(0, 0, termios_p);
}

canonical_decompiled_code:
int __fastcall func9(struct termios *termios_p)
{
return tcsetattr(0, 0, termios_p);
}

original_code:
void restoreTerminalMode(struct termios *oldSettings)
{
    tcsetattr(0, 0, oldSettings);
    return;
}

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


original_code:
STACK_RET_CODE stack_initialize(HIST_STACK *histStack)
{
    if(histStack == ((void *)0))
    {
        return STACK_NULL_ERR;
    }
    histStack->stackSize = 0;
    memset(histStack->stackBuffer, 0, 40);
    return STACK_SUCCESS;
}

canonical_original_code:
enum STACK_RET_CODE stack_initialize(struct HIST_STACK *histStack)
{
    if(histStack == ((void *)0))
    {
        return STACK_NULL_ERR;
    }
    histStack->stackSize = 0;
    memset(histStack->stackBuffer, 0, 40);
    return STACK_SUCCESS;
}

variable_types: struct HIST_STACK { char stackBuffer[5][40]; int stackSize; int accessIndex; enum STACK_POP_STATE { STACK_IDLE=0, STACK_UP=1, STACK_DOWN=2 } stack_pop_state; } *

return_type: enum STACK_RET_CODE { STACK_SUCCESS=0, STACK_FAILURE=1, STACK_UNDERFLOW=2, STACK_OVERFLOW=3, STACK_ERROR=4, STACK_NULL_ERR=5 }

user_defined_types: struct HIST_STACK { char stackBuffer[5][40]; int stackSize; int accessIndex; enum STACK_POP_STATE stack_pop_state; }


decompiled_code:
__int64 __fastcall stack_push(void *dest, void *src)
{
int v2; // edx
__int64 result; // rax
char *v4; // rbx
void *v5; // r13
int v6; // eax
int v7; // eax
int v8; // eax

if ( !dest )
return 5LL;
v2 = mystrlen(src);
result = 0LL;
if ( v2 )
{
v4 = (char *)dest + 120;
do
{
v5 = v4;
v6 = mystrlen(v4);
memcpy(v4 + 40, v4, v6 + 1);
v4 -= 40;
}
while ( v5 != dest );
v7 = *((_DWORD *)dest + 50);
if ( v7 <= 4 )
*((_DWORD *)dest + 50) = v7 + 1;
v8 = mystrlen(src);
memcpy(dest, src, v8 + 1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *dest, void *src)
{
int v2; // edx
__int64 result; // rax
char *v4; // rbx
void *v5; // r13
int v6; // eax
int v7; // eax
int v8; // eax

if ( !dest )
return 5LL;
v2 = mystrlen(src);
result = 0LL;
if ( v2 )
{
v4 = (char *)dest + 120;
do
{
v5 = v4;
v6 = mystrlen(v4);
memcpy(v4 + 40, v4, v6 + 1);
v4 -= 40;
}
while ( v5 != dest );
v7 = *((_DWORD *)dest + 50);
if ( v7 <= 4 )
*((_DWORD *)dest + 50) = v7 + 1;
v8 = mystrlen(src);
memcpy(dest, src, v8 + 1);
result = 0LL;
}
return result;
}

original_code:
STACK_RET_CODE stack_push(HIST_STACK *histStack, char *entry)
{
    int index = 0;
    if(histStack == ((void *)0))
    {
        return STACK_NULL_ERR;
    }
    if(mystrlen(entry) == 0)
    {
        return STACK_SUCCESS;
    }
    for(index = 5 - 1; index > 0; index--)
    {
        memcpy(histStack->stackBuffer[index],
             histStack->stackBuffer[index - 1], mystrlen(histStack->stackBuffer[index - 1]) + 1);
    }
    if(histStack->stackSize < 5)
    {
        histStack->stackSize++;
    }
    memcpy(histStack->stackBuffer[0], entry, mystrlen(entry) + 1);
    return STACK_SUCCESS;
}

canonical_original_code:
enum STACK_RET_CODE stack_push(struct HIST_STACK *histStack, char *entry)
{
    int index = 0;
    if(histStack == ((void *)0))
    {
        return STACK_NULL_ERR;
    }
    if(mystrlen(entry) == 0)
    {
        return STACK_SUCCESS;
    }
    for(index = 5 - 1; index > 0; index--)
    {
        memcpy(histStack->stackBuffer[index],
             histStack->stackBuffer[index - 1], mystrlen(histStack->stackBuffer[index - 1]) + 1);
    }
    if(histStack->stackSize < 5)
    {
        histStack->stackSize++;
    }
    memcpy(histStack->stackBuffer[0], entry, mystrlen(entry) + 1);
    return STACK_SUCCESS;
}

variable_types:
entry
char *

variable_types: index int

user_defined_types: enum STACK_RET_CODE { STACK_SUCCESS=0, STACK_FAILURE=1, STACK_UNDERFLOW=2, STACK_OVERFLOW=3, STACK_ERROR=4, STACK_NULL_ERR=5 }

user_defined_types: enum STACK_POP_STATE { STACK_IDLE=0, STACK_UP=1, STACK_DOWN=2 }


decompiled_code:
__int64 __fastcall stack_pop_up(_DWORD *a1, void *a2)
{
int v2; // edx
__int64 result; // rax
int v4; // ecx
int v5; // eax
int v6; // eax

v2 = a1[50];
result = 2LL;
if ( v2 )
{
v4 = a1[51];
if ( a1[52] == 2 )
a1[51] = v4 + 1;
v5 = a1[51];
if ( v2 > v5 )
{
v6 = mystrlen(&a1[10 * v5]);
memcpy(a2, &a1[10 * a1[51]++], v6 + 1);
result = 0LL;
}
else
{
a1[51] = v4;
result = 2LL;
}
}
return result;
}

original_code:
STACK_RET_CODE stack_pop_up(HIST_STACK *histStack, char *entry)
{
    int prevaccessIndex = histStack->accessIndex;
    if(histStack->stackSize == 0)
    {
        return STACK_UNDERFLOW;
    }
    if(histStack->stack_pop_state == STACK_DOWN)
    {
        histStack->accessIndex++;
    }
    if(histStack->accessIndex < histStack->stackSize)
    {
        memcpy(entry, histStack->stackBuffer[histStack->accessIndex]
                        , mystrlen(histStack->stackBuffer[histStack->accessIndex]) + 1);
        histStack->accessIndex++;
        return STACK_SUCCESS;
    }
    histStack->accessIndex = prevaccessIndex;
    return STACK_UNDERFLOW;
}

canonical_original_code:
enum STACK_RET_CODE stack_pop_up(struct HIST_STACK *histStack, char *entry)
{
    int prevaccessIndex = histStack->accessIndex;
    if(histStack->stackSize == 0)
    {
        return STACK_UNDERFLOW;
    }
    if(histStack->stack_pop_state == STACK_DOWN)
    {
        histStack->accessIndex++;
    }
    if(histStack->accessIndex < histStack->stackSize)
    {
        memcpy(entry, histStack->stackBuffer[histStack->accessIndex]
                        , mystrlen(histStack->stackBuffer[histStack->accessIndex]) + 1);
        histStack->accessIndex++;
        return STACK_SUCCESS;
    }
    histStack->accessIndex = prevaccessIndex;
    return STACK_UNDERFLOW;
}

variable_types: prevaccessIndex int


original_code:
STACK_RET_CODE stack_pop_down(HIST_STACK *histStack, char *entry)
{
    int prevaccessIndex = histStack->accessIndex;
    if(histStack->stackSize == 0)
    {
        return STACK_UNDERFLOW;
    }
    if(histStack->stack_pop_state == STACK_UP)
    {
        histStack->accessIndex--;
    }
    if(histStack->accessIndex > 0)
    {
        histStack->accessIndex--;
        memcpy(entry, histStack->stackBuffer[histStack->accessIndex]
                , mystrlen(histStack->stackBuffer[histStack->accessIndex]) + 1);
        return STACK_SUCCESS;
    }
    histStack->accessIndex = prevaccessIndex;
    return STACK_UNDERFLOW;
}

canonical_original_code:
enum STACK_RET_CODE stack_pop_down(struct HIST_STACK *histStack, char *entry)
{
    int prevaccessIndex = histStack->accessIndex;
    if(histStack->stackSize == 0)
    {
        return STACK_UNDERFLOW;
    }
    if(histStack->stack_pop_state == STACK_UP)
    {
        histStack->accessIndex--;
    }
    if(histStack->accessIndex > 0)
    {
        histStack->accessIndex--;
        memcpy(entry, histStack->stackBuffer[histStack->accessIndex]
                , mystrlen(histStack->stackBuffer[histStack->accessIndex]) + 1);
        return STACK_SUCCESS;
    }
    histStack->accessIndex = prevaccessIndex;
    return STACK_UNDERFLOW;
}


checkIfElementExists

decompiled_code:
__int64 __fastcall checkIfElementExists(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // ebp

if ( *(int *)(a1 + 200) <= 0 )
return 1LL;
v2 = a1;
v3 = 0;
while ( (unsigned int)mystrcmp(v2, a2) )
{
++v3;
v2 += 40LL;
if ( *(_DWORD *)(a1 + 200) <= v3 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // ebp

if ( *(int *)(a1 + 200) <= 0 )
return 1LL;
v2 = a1;
v3 = 0;
while ( (unsigned int)mystrcmp(v2, a2) )
{
++v3;
v2 += 40LL;
if ( *(_DWORD *)(a1 + 200) <= v3 )
return 1LL;
}
return 0LL;
}

original_code:
STACK_RET_CODE checkIfElementExists(HIST_STACK *histStack, char *entry)
{
    int iVal;
    for(iVal = 0; iVal < histStack->stackSize; iVal++)
    {
        if(mystrcmp(histStack->stackBuffer[iVal], entry) == 0)
        {
            return STACK_SUCCESS;
        }
    }
    return STACK_FAILURE;
}

canonical_original_code:
enum STACK_RET_CODE checkIfElementExists(struct HIST_STACK *histStack, char *entry)
{
    int iVal;
    for(iVal = 0; iVal < histStack->stackSize; iVal++)
    {
        if(mystrcmp(histStack->stackBuffer[iVal], entry) == 0)
        {
            return STACK_SUCCESS;
        }
    }
    return STACK_FAILURE;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)stack_initialize(&g_histstack, argv, envp) )
return -1;
disableEchoCanonMode(&g_OldSettings);
custom_printstring(" _______________________________________________________ \n\r");
custom_printstring("/ \\\n\r");
custom_printstring("| Welcome to CLI |\n\r");
custom_printstring("\\_________ _______________________________/ \n\r");
custom_printstring(" \\_ __/ ___---------__ \n\r");
custom_printstring(" \\ _/ / \\_ \n\r");
custom_printstring(" \\ / / \\ \n\r");
custom_printstring(" | / | _ _ \\ \\ \n\r");
custom_printstring(" | | / / \\ / \\ | \\ \n\r");
custom_printstring(" | | || || || | \n\r");
custom_printstring(" | | | \\_//\\\\_/ | | \n\r");
custom_printstring(" | | | || | _ / / | \n\r");
custom_printstring(" \\ \\ |_________|| \\/ / / \n\r");
custom_printstring(" \\ \\_ |_|_|_|_|/| _/___/ \n\r");
custom_printstring(" \\__> _ _/_ _ / | \n\r");
custom_printstring(" .|_|_|_|_| | \n\r");
custom_printstring(" | / \n\r");
custom_printstring(" |__________/ \n\r");
custom_printstring("Welcome to CLI");
custom_printstring("\r\n");
custom_printstring("Type \"help\" for list of commands");
custom_printstring("\r\n");
custom_printstring("\r\n");
custom_printstring("Hit <TAB> for autocomplete");
custom_printstring("\r\n");
custom_printstring("Hit <UP>/<DOWN> for command history");
custom_printstring("\r\n");
custom_printstring("Hit <LEFT/RIGHT> for line editing");
while ( (unsigned int)CLILoop() != 11 )
;
restoreTerminalMode(&g_OldSettings);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    if(stack_initialize(&g_histstack) != STACK_SUCCESS)
    {
      return -1;
    }
    disableEchoCanonMode(&g_OldSettings);
    custom_printstring(" _______________________________________________________ \n\r");
    custom_printstring("/                                                       \\\n\r");
    custom_printstring("|               Welcome to CLI                          |\n\r");
    custom_printstring("\\_________              _______________________________/ \n\r");
    custom_printstring("          \\_         __/    ___---------__               \n\r");
    custom_printstring("            \\      _/      /              \\_             \n\r");
    custom_printstring("             \\    /       /                 \\            \n\r");
    custom_printstring("              |  /       | _    _ \\          \\           \n\r");
    custom_printstring("              | |       / / \\  / \\ |          \\          \n\r");
    custom_printstring("              | |       ||   ||   ||           |         \n\r");
    custom_printstring("              | |       | \\_//\\\\_/ |           |         \n\r");
    custom_printstring("              | |         |  ||     | _  / /   |         \n\r");
    custom_printstring("               \\ \\        |_________|| \\/ /   /          \n\r");
    custom_printstring("                \\ \\_       |_|_|_|_|/|  _/___/           \n\r");
    custom_printstring("                 \\__>       _ _/_ _ /  |                 \n\r");
    custom_printstring("                          .|_|_|_|_|   |                 \n\r");
    custom_printstring("                          |           /                  \n\r");
    custom_printstring("                          |__________/                   \n\r");
    custom_printstring("Welcome to CLI");
    custom_printstring("\r\n");
    custom_printstring("Type \"help\" for list of commands");
    custom_printstring("\r\n");
    custom_printstring("\r\n");
    custom_printstring("Hit    <TAB>     for autocomplete");
    custom_printstring("\r\n");
    custom_printstring("Hit <UP>/<DOWN>  for command history");
    custom_printstring("\r\n");
    custom_printstring("Hit <LEFT/RIGHT> for line editing");
    while(1)
    {
       if(CLILoop() == EXIT_CODE)
       {
         restoreTerminalMode(&g_OldSettings);
         break;
       }
    }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


help

original_code:
RET_CODE help(PMSG *pmsg)
{
    int numCmds, iVal;
    numCmds = g_CmdTblSize;
    custom_printstring("----------------------------------------------------------------\n\r");
    custom_printstring("Command Name\n\r");
    custom_printstring("----------------------------------------------------------------\n\r");
    for(iVal = 0; iVal < numCmds; iVal++)
    {
        custom_printstring(cmdTable[iVal].cmdName);
        custom_printstring("\n\r");
    }
    return SUCCESS;
}

canonical_original_code:
enum RET_CODE help(struct PMSG *pmsg)
{
    int numCmds; int iVal;
    numCmds = g_CmdTblSize;
    custom_printstring("----------------------------------------------------------------\n\r");
    custom_printstring("Command Name\n\r");
    custom_printstring("----------------------------------------------------------------\n\r");
    for(iVal = 0; iVal < numCmds; iVal++)
    {
        custom_printstring(cmdTable[iVal].cmdName);
        custom_printstring("\n\r");
    }
    return SUCCESS;
}

variable_types: struct PMSG { char cmdBuff[40]; int argc; char argv[4][10]; enum PARSE_STATE { INSIDE_WORD=0, OUTSIDE_WORD=1 } parse_state; enum LEFT_RIGHT_STATE { LEFT_RIGHT_ACTIVE=0, LEFT_RIGHT_IDLE=1 } left_right_state; } *

variable_types: numCmds int

user_defined_types: enum RET_CODE { SUCCESS=0, CMD_FAIL=1, CMD_FAILQUIET=2, NULL_ERR=3, BASE_ERR=4, PARSE_ERR=5, PARAM_ERR=6, PARAM1_ERR=7, PARAM2_ERR=8, PARAM3_ERR=9, PARAM4_ERR=10, EXIT_CODE=11 }

user_defined_types: struct PMSG { char cmdBuff[40]; int argc; char argv[4][10]; enum PARSE_STATE parse_state; enum LEFT_RIGHT_STATE left_right_state; }


echo

decompiled_code:
__int64 __fastcall echo(__int64 a1)
{
custom_printstring(a1 + 54);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
custom_printstring(a1 + 54);
return 0LL;
}

original_code:
RET_CODE echo(PMSG *pmsg)
{
    custom_printstring(pmsg->argv[1]);
    return SUCCESS;
}

canonical_original_code:
enum RET_CODE echo(struct PMSG *pmsg)
{
    custom_printstring(pmsg->argv[1]);
    return SUCCESS;
}

user_defined_types: enum PARSE_STATE { INSIDE_WORD=0, OUTSIDE_WORD=1 }

user_defined_types: enum LEFT_RIGHT_STATE { LEFT_RIGHT_ACTIVE=0, LEFT_RIGHT_IDLE=1 }


history

decompiled_code:
__int64 history()
{
_DWORD *v0; // rbp
int v1; // ebx

if ( (int)g_histstack[50] <= 0 )
return 0LL;
v0 = g_histstack;
v1 = 0;
do
{
custom_printstring(v0);
custom_printstring(&unk_E80);
++v1;
v0 += 10;
}
while ( g_histstack[50] > v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
_DWORD *v0; // rbp
int v1; // ebx

if ( (int)g_histstack[50] <= 0 )
return 0LL;
v0 = g_histstack;
v1 = 0;
do
{
custom_printstring(v0);
custom_printstring(&unk_E80);
++v1;
v0 += 10;
}
while ( g_histstack[50] > v1 );
return 0LL;
}

original_code:
RET_CODE history(PMSG *pmsg)
{
    int iVal = 0;
    for(iVal = 0; iVal < g_histstack.stackSize; iVal++)
    {
        custom_printstring(g_histstack.stackBuffer[iVal]);
        custom_printstring("\r\n");
    }
    return SUCCESS;
}

canonical_original_code:
enum RET_CODE history(struct PMSG *pmsg)
{
    int iVal = 0;
    for(iVal = 0; iVal < g_histstack.stackSize; iVal++)
    {
        custom_printstring(g_histstack.stackBuffer[iVal]);
        custom_printstring("\r\n");
    }
    return SUCCESS;
}


myexit

decompiled_code:
__int64 myexit()
{
custom_printstring("****** Exiting ******\n\r");
return 11LL;
}

canonical_decompiled_code:
__int64 func3()
{
custom_printstring("****** Exiting ******\n\r");
return 11LL;
}

original_code:
RET_CODE myexit(PMSG *pmsg)
{
    custom_printstring("******"" ""Exiting"" ""******""\n\r");
    return EXIT_CODE;
}

canonical_original_code:
enum RET_CODE myexit(struct PMSG *pmsg)
{
    custom_printstring("******"" ""Exiting"" ""******""\n\r");
    return EXIT_CODE;
}


clear

decompiled_code:
__int64 clear()
{
clearscreen();
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
clearscreen();
return 0LL;
}

original_code:
RET_CODE clear(PMSG *pmsg)
{
    clearscreen();
    return SUCCESS;
}

canonical_original_code:
enum RET_CODE clear(struct PMSG *pmsg)
{
    clearscreen();
    return SUCCESS;
}


CLILoop

decompiled_code:
__int64 CLILoop()
{
SMHandler_1 = (__int64 (__fastcall *)(_QWORD))SMHandler_1(&g_pmsg);
return SMHandler_1 == 0LL ? 0xB : 0;
}

canonical_decompiled_code:
__int64 func5()
{
SMHandler_1 = (__int64 (__fastcall *)(_QWORD))SMHandler_1(&g_pmsg);
return SMHandler_1 == 0LL ? 0xB : 0;
}

original_code:
RET_CODE CLILoop(void)
{
    static pFuncPtr SMHandler = (pFuncPtr)InitState;
    SMHandler = (pFuncPtr)SMHandler((void *)&g_pmsg);
    if(SMHandler == ((void *)0))
    {
        return EXIT_CODE;
    }
    return SUCCESS;
}

canonical_original_code:
enum RET_CODE CLILoop()
{
    static int (*(*SMHandler)(void *))(void *) = (pFuncPtr)InitState;
    SMHandler = (int (*(*)(void *))(void *))SMHandler((void *)&g_pmsg);
    if(SMHandler == ((void *)0))
    {
        return EXIT_CODE;
    }
    return SUCCESS;
}

variable_types:
SMHandler
int (*(*)(void *))(void *)


convertArgumentsIntoInteger

decompiled_code:
__int64 __fastcall convertArgumentsIntoInteger(int a1)
{
unsigned __int64 v1; // rbx
unsigned __int64 v2; // rbp
__int64 result; // rax

if ( a1 <= 1 )
return 0LL;
v1 = (unsigned int)((_DWORD)&g_pmsg + 54);
v2 = (unsigned int)((_DWORD)&g_CmdArgs + 4);
do
{
if ( *(_BYTE *)v1 == 48 && (*(_BYTE *)(v1 + 1) & 0xDF) == 88 )
{
result = myatoi(v1 + 2, 16LL, v2);
if ( (_DWORD)result == 6 )
return result;
}
else
{
result = myatoi(v1, 10LL, v2);
if ( (_DWORD)result == 6 )
return result;
}
v1 += 10LL;
v2 += 4LL;
}
while ( (_UNKNOWN *)v2 != (_UNKNOWN *)((char *)&g_CmdArgs + 4 * (unsigned int)(a1 - 2) + 8) );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
unsigned __int64 v1; // rbx
unsigned __int64 v2; // rbp
__int64 result; // rax

if ( a1 <= 1 )
return 0LL;
v1 = (unsigned int)((_DWORD)&g_pmsg + 54);
v2 = (unsigned int)((_DWORD)&g_CmdArgs + 4);
do
{
if ( *(_BYTE *)v1 == 48 && (*(_BYTE *)(v1 + 1) & 0xDF) == 88 )
{
result = myatoi(v1 + 2, 16LL, v2);
if ( (_DWORD)result == 6 )
return result;
}
else
{
result = myatoi(v1, 10LL, v2);
if ( (_DWORD)result == 6 )
return result;
}
v1 += 10LL;
v2 += 4LL;
}
while ( (_UNKNOWN *)v2 != (_UNKNOWN *)((char *)&g_CmdArgs + 4 * (unsigned int)(a1 - 2) + 8) );
return 0LL;
}

canonical_original_code:
enum RET_CODE convertArgumentsIntoInteger(int nArgs)
{
    int iVal;
    for(iVal = 1; iVal < nArgs; iVal++)
    {
        if(((((g_pmsg.argv[iVal][0]) == '0') && (((g_pmsg.argv[iVal][1]) == 'x') || ((g_pmsg.argv[iVal][1]) == 'X'))) ? 1 : 0))
        {
            if(myatoi(&g_pmsg.argv[iVal][2], 16, (int *)&g_CmdArgs[iVal]) == PARAM_ERR)
            {
                return PARAM_ERR;
            }
        }
        else
        {
            if(myatoi(&g_pmsg.argv[iVal][0], 10, (int *)&g_CmdArgs[iVal]) == PARAM_ERR)
            {
                return PARAM_ERR;
            }
        }
    }
    return SUCCESS;
}

variable_types: nArgs int


add

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

v1 = 6;
if ( !(unsigned int)convertArgumentsIntoInteger(*(_DWORD *)(a1 + 40)) )
{
v1 = 0;
myprintinteger(g_CmdArgs[1], 1LL);
custom_printstring(" + ");
myprintinteger(g_CmdArgs[2], 1LL);
custom_printstring(" = ");
myprintinteger(g_CmdArgs[1] + g_CmdArgs[2], 1LL);
}
return v1;
}

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

v1 = 6;
if ( !(unsigned int)func6(*(_DWORD *)(a1 + 40)) )
{
v1 = 0;
myprintinteger(g_CmdArgs[1], 1LL);
custom_printstring(" + ");
myprintinteger(g_CmdArgs[2], 1LL);
custom_printstring(" = ");
myprintinteger(g_CmdArgs[1] + g_CmdArgs[2], 1LL);
}
return v1;
}

original_code:
RET_CODE add(PMSG *pmsg)
{
    if(convertArgumentsIntoInteger(pmsg->argc) != SUCCESS)
    {
        return PARAM_ERR;
    }
    myprintinteger(g_CmdArgs[1], 1);
    custom_printstring(" + ");
    myprintinteger(g_CmdArgs[2], 1);
    custom_printstring(" = ");
    myprintinteger(g_CmdArgs[1] + g_CmdArgs[2], 1);
    return SUCCESS;
}

canonical_original_code:
enum RET_CODE add(struct PMSG *pmsg)
{
    if(convertArgumentsIntoInteger(pmsg->argc) != SUCCESS)
    {
        return PARAM_ERR;
    }
    myprintinteger(g_CmdArgs[1], 1);
    custom_printstring(" + ");
    myprintinteger(g_CmdArgs[2], 1);
    custom_printstring(" = ");
    myprintinteger(g_CmdArgs[1] + g_CmdArgs[2], 1);
    return SUCCESS;
}


decompiled_code:
int custom_ioread()
{
return getchar();
}

canonical_decompiled_code:
int func0()
{
return getchar();
}

original_code:
char custom_ioread()
{
    char ch;
    ch = getchar();
    return ch;
}

variable_types: ch char

return_type: char


decompiled_code:
int __fastcall custom_iowrite(char a1)
{
return putchar(a1);
}

canonical_decompiled_code:
int __fastcall func1(char a1)
{
return putchar(a1);
}

original_code:
void custom_iowrite(char ch)
{
    putchar(ch);
    return;
}


initializeAutoCompl

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

result = 1LL;
if ( a1 )
{
a1[101] = 0;
a1[100] = 0;
a1[102] = 0;
result = 3LL;
}
return result;
}

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

result = 1LL;
if ( a1 )
{
a1[101] = 0;
a1[100] = 0;
a1[102] = 0;
result = 3LL;
}
return result;
}

original_code:
AUTOCOMPL_RET_CODE initializeAutoCompl(AUTOCOMPL_STRUCT *autoComplStruct)
{
    if(autoComplStruct == ((void *)0))
    {
      return AUTOCOMPL_NULL_ERR;
    }
    autoComplStruct->totalHits = 0;
    autoComplStruct->matchIndex = 0;
    autoComplStruct->autoComplState = AUTO_IDLE;
    return AUTOCOMPL_SUCCESS;
}

canonical_original_code:
enum AUTOCOMPL_RET_CODE initializeAutoCompl(struct AUTOCOMPL_STRUCT *autoComplStruct)
{
    if(autoComplStruct == ((void *)0))
    {
      return AUTOCOMPL_NULL_ERR;
    }
    autoComplStruct->totalHits = 0;
    autoComplStruct->matchIndex = 0;
    autoComplStruct->autoComplState = AUTO_IDLE;
    return AUTOCOMPL_SUCCESS;
}

variable_types: struct AUTOCOMPL_STRUCT { char matchList[20][20]; int matchIndex; int totalHits; enum AUTOCOMPL_STATE { AUTO_IDLE=0, AUTO_ACTIVE=1 } autoComplState; } *

return_type: enum AUTOCOMPL_RET_CODE { AUTOCOMPL_NOHITS=0, AUTOCOMPL_NULL_ERR=1, AUTOCOMPL_ERR=2, AUTOCOMPL_SUCCESS=3 }

user_defined_types: struct AUTOCOMPL_STRUCT { char matchList[20][20]; int matchIndex; int totalHits; enum AUTOCOMPL_STATE autoComplState; }


buildMatchList

original_code:
AUTOCOMPL_RET_CODE buildMatchList(AUTOCOMPL_STRUCT *autoComplStruct, char *searchStr, CMD_TABLE *cmdTable, int cmdTableSize)
{
    int index = 0;
    autoComplStruct->totalHits = 0;
    autoComplStruct->matchIndex = 0;
    for(index = 0; index < cmdTableSize; index++)
    {
        if(mystrstr(searchStr, cmdTable[index].cmdName) == 1)
        {
            memcpy(autoComplStruct->matchList[autoComplStruct->totalHits++]
                , cmdTable[index].cmdName, mystrlen(cmdTable[index].cmdName) +1);
        }
    }
    if(autoComplStruct->totalHits == 0)
    {
        return AUTOCOMPL_NOHITS;
    }
    return AUTOCOMPL_SUCCESS;
}

canonical_original_code:
enum AUTOCOMPL_RET_CODE buildMatchList(struct AUTOCOMPL_STRUCT *autoComplStruct, char *searchStr, struct CMD_TABLE *cmdTable, int cmdTableSize)
{
    int index = 0;
    autoComplStruct->totalHits = 0;
    autoComplStruct->matchIndex = 0;
    for(index = 0; index < cmdTableSize; index++)
    {
        if(mystrstr(searchStr, cmdTable[index].cmdName) == 1)
        {
            memcpy(autoComplStruct->matchList[autoComplStruct->totalHits++]
                , cmdTable[index].cmdName, mystrlen(cmdTable[index].cmdName) +1);
        }
    }
    if(autoComplStruct->totalHits == 0)
    {
        return AUTOCOMPL_NOHITS;
    }
    return AUTOCOMPL_SUCCESS;
}

variable_types:
searchStr
char *

variable_types: struct CMD_TABLE { char cmdName[10]; enum RET_CODE { SUCCESS=0, CMD_FAIL=1, CMD_FAILQUIET=2, NULL_ERR=3, BASE_ERR=4, PARSE_ERR=5, PARAM_ERR=6, PARAM1_ERR=7, PARAM2_ERR=8, PARAM3_ERR=9, PARAM4_ERR=10, EXIT_CODE=11 } (*cmdFuncPtr)(struct PMSG { char cmdBuff[40]; int argc; char argv[4][10]; enum PARSE_STATE { INSIDE_WORD=0, OUTSIDE_WORD=1 } parse_state; enum LEFT_RIGHT_STATE { LEFT_RIGHT_ACTIVE=0, LEFT_RIGHT_IDLE=1 } left_right_state; } *); int argNum; char cmdUsage[30]; } *

variable_types: cmdTableSize int

user_defined_types: enum AUTOCOMPL_RET_CODE { AUTOCOMPL_NOHITS=0, AUTOCOMPL_NULL_ERR=1, AUTOCOMPL_ERR=2, AUTOCOMPL_SUCCESS=3 }

user_defined_types: struct CMD_TABLE { char cmdName[10]; enum RET_CODE (*cmdFuncPtr)(struct PMSG *); int argNum; char cmdUsage[30]; }

user_defined_types: enum AUTOCOMPL_STATE { AUTO_IDLE=0, AUTO_ACTIVE=1 }


findMatch

original_code:
AUTOCOMPL_RET_CODE findMatch(AUTOCOMPL_STRUCT *autoComplStruct, char *searchStr, CMD_TABLE *cmdTable, int cmdTableSize)
{
    AUTOCOMPL_RET_CODE retCode;
    if(autoComplStruct->autoComplState == AUTO_IDLE)
    {
        if((retCode = buildMatchList(autoComplStruct, searchStr, cmdTable, cmdTableSize)) != AUTOCOMPL_SUCCESS)
        {
            return retCode;
        }
        autoComplStruct->autoComplState = AUTO_ACTIVE;
        memcpy(autoComplStruct->matchList[autoComplStruct->totalHits++]
            , searchStr, mystrlen(searchStr) +1);
    }
    memcpy(searchStr, autoComplStruct->matchList[autoComplStruct->matchIndex]
            , mystrlen(autoComplStruct->matchList[autoComplStruct->matchIndex]) + 1);
    autoComplStruct->matchIndex = (++autoComplStruct->matchIndex) % autoComplStruct->totalHits;
    return AUTOCOMPL_SUCCESS;
}

canonical_original_code:
enum AUTOCOMPL_RET_CODE findMatch(struct AUTOCOMPL_STRUCT *autoComplStruct, char *searchStr, struct CMD_TABLE *cmdTable, int cmdTableSize)
{
    enum AUTOCOMPL_RET_CODE retCode;
    if(autoComplStruct->autoComplState == AUTO_IDLE)
    {
        if((retCode = buildMatchList(autoComplStruct, searchStr, cmdTable, cmdTableSize)) != AUTOCOMPL_SUCCESS)
        {
            return retCode;
        }
        autoComplStruct->autoComplState = AUTO_ACTIVE;
        memcpy(autoComplStruct->matchList[autoComplStruct->totalHits++]
            , searchStr, mystrlen(searchStr) +1);
    }
    memcpy(searchStr, autoComplStruct->matchList[autoComplStruct->matchIndex]
            , mystrlen(autoComplStruct->matchList[autoComplStruct->matchIndex]) + 1);
    autoComplStruct->matchIndex = (++autoComplStruct->matchIndex) % autoComplStruct->totalHits;
    return AUTOCOMPL_SUCCESS;
}

variable_types: enum AUTOCOMPL_RET_CODE { AUTOCOMPL_NOHITS=0, AUTOCOMPL_NULL_ERR=1, AUTOCOMPL_ERR=2, AUTOCOMPL_SUCCESS=3 }


A

decompiled_code:
_BOOL8 __fastcall A(int a1)
{
return a1 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(int a1)
{
return a1 != 0;
}

original_code:
int A(int x) {
    return x != 0;
}

canonical_original_code:
int A(int x) {
    return x != 0;
}

variable_types: x int


B

decompiled_code:
_BOOL8 __fastcall B(int a1)
{
return a1 != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(int a1)
{
return a1 != -1;
}

original_code:
int B(int x) {
    return x != ~0;
}

canonical_original_code:
int B(int x) {
    return x != ~0;
}


decompiled_code:
int __fastcall print_good(const char *a1)
{
return printf("%s %s %s", "\x1B[1m\x1B[32m", a1, "\x1B[0m");
}

canonical_decompiled_code:
int __fastcall func11(const char *a1)
{
return printf("%s %s %s", "\x1B[1m\x1B[32m", a1, "\x1B[0m");
}

original_code:
void print_good(char * string) {
    printf("%s %s %s", "\033[1m\033[32m", string, "\033[0m");
}

canonical_original_code:
void print_good(char *string) {
    printf("%s %s %s", "\033[1m\033[32m", string, "\033[0m");
}

variable_types:
string
char *


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

if ( a2 <= 0 || a1 <= 0 )
{
if ( a2 < 0 && a1 < 0 && (int)(0x80000000 - a2) > a1 )
return 0x80000000LL;
return (unsigned int)(a2 + a1);
}
result = 0x7FFFFFFFLL;
if ( 0x7FFFFFFF - a2 >= a1 )
return (unsigned int)(a2 + a1);
return result;
}

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

if ( a2 <= 0 || a1 <= 0 )
{
if ( a2 < 0 && a1 < 0 && (int)(0x80000000 - a2) > a1 )
return 0x80000000LL;
return (unsigned int)(a2 + a1);
}
result = 0x7FFFFFFFLL;
if ( 0x7FFFFFFF - a2 >= a1 )
return (unsigned int)(a2 + a1);
return result;
}

original_code:
int saturating_add(int x, int y) {
    int TMin = (-0x7fffffff - 1);
    int TMax = ~TMin;
    if (y>0 && x>0 && (TMax - y < x)) {
            return TMax;
    } else if (y<0 && x<0 && (TMin - y > x)) {
            return TMin;
    } else {
        return x + y;
    }
}

variable_types: y int

variable_types: TMin int

variable_types: TMax int


canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
return printf("%s %s %s", "\x1B[1m\x1B[32m", a1, "\x1B[0m");
}


decompiled_code:
__int64 __fastcall rotate_left(int a1, char a2)
{
return (unsigned int)__ROL4__(a1, a2);
}

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

original_code:
unsigned rotate_left(unsigned x, int n) {
    unsigned a = x;
    a = a << n;
    x = x >> (((sizeof(int) << 3) - n) & (~(sizeof(int) << 3)));
    return a | x;
}

canonical_original_code:
unsigned int rotate_left(unsigned int x, int n) {
    unsigned int a = x;
    a = a << n;
    x = x >> (((sizeof(int) << 3) - n) & (~(sizeof(int) << 3)));
    return a | x;
}

variable_types:
x
unsigned int

variable_types: n int

variable_types:
a
unsigned int

return_type: unsigned int


decompiled_code:
_BOOL8 __fastcall any_odd_one(int a1)
{
return (a1 & 0xAAAAAAAA) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(int a1)
{
return (a1 & 0xAAAAAAAA) != 0;
}

original_code:
int any_odd_one(unsigned x) {
        unsigned mask = 0xAAAAAAAA;
        return (x & mask) != 0;
    }

canonical_original_code:
int any_odd_one(unsigned int x) {
        unsigned int mask = 0xAAAAAAAA;
        return (x & mask) != 0;
    }

variable_types:
mask
unsigned int


decompiled_code:
_BOOL8 __fastcall iposix_gid_compare(int a1, int a2)
{
return a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1, int a2)
{
return a1 == a2;
}

original_code:
static int
iposix_gid_compare (group_id_t a, group_id_t b)
{
  return a.value == b.value;
}

canonical_original_code:
static int iposix_gid_compare(struct group_id_t a, struct group_id_t b)
{
  return a.value == b.value;
}

variable_types:
a
struct group_id_t { int value; }

variable_types:
b
struct group_id_t


decompiled_code:
_BOOL8 __fastcall iposix_gid_valid(int a1)
{
return a1 != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int a1)
{
return a1 != -1;
}

original_code:
static int
iposix_gid_valid (group_id_t gid)
{
  return gid.value != -1;
}

canonical_original_code:
static int iposix_gid_valid(struct group_id_t gid)
{
  return gid.value != -1;
}

variable_types:
gid
struct group_id_t { int value; }


decompiled_code:
_BOOL8 __fastcall iposix_uid_compare(int a1, int a2)
{
return a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1, int a2)
{
return a1 == a2;
}

original_code:
static int
iposix_uid_compare (user_id_t a, user_id_t b)
{
  return a.value == b.value;
}

canonical_original_code:
static int iposix_uid_compare(struct user_id_t a, struct user_id_t b)
{
  return a.value == b.value;
}

variable_types:
a
struct user_id_t { int value; }

variable_types:
b
struct user_id_t


decompiled_code:
_BOOL8 __fastcall iposix_uid_valid(int a1)
{
return a1 != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1)
{
return a1 != -1;
}

original_code:
static int
iposix_uid_valid (user_id_t uid)
{
  return uid.value != -1;
}

canonical_original_code:
static int iposix_uid_valid(struct user_id_t uid)
{
  return uid.value != -1;
}

variable_types:
uid
struct user_id_t { int value; }


decompiled_code:
__int64 iposix_supports_symlinks()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 1LL;
}

original_code:
static int
iposix_supports_symlinks (void)
{
  return 1;
}

canonical_original_code:
static int iposix_supports_symlinks()
{
  return 1;
}


decompiled_code:
__int64 iposix_supports_posix_modes()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func6()
{
return 1LL;
}

original_code:
static int
iposix_supports_posix_modes (void)
{
  return 1;
}

canonical_original_code:
static int iposix_supports_posix_modes()
{
  return 1;
}


decompiled_code:
char *iposix_user_name_current()
{
return getlogin();
}

canonical_decompiled_code:
char *func7()
{
return getlogin();
}

original_code:
const char *
iposix_user_name_current (void)
{
  return getlogin ();
}

canonical_original_code:
char *iposix_user_name_current()
{
  return getlogin ();
}

return_type: char *


decompiled_code:
__mode_t __fastcall iposix_umask(__mode_t a1)
{
return umask(a1);
}

canonical_decompiled_code:
__mode_t __fastcall func8(__mode_t a1)
{
return umask(a1);
}

original_code:
static unsigned int
iposix_umask (unsigned int m)
{
  return umask (m);
}

canonical_original_code:
static unsigned int iposix_umask(unsigned int m)
{
  return umask (m);
}

variable_types:
m
unsigned int


decompiled_code:
_BOOL8 __fastcall iposix_can_set_ownership(int a1)
{
if ( a1 == -1 )
_assert_fail("uid.value != -1", "install-posix.c", 0x126u, "iposix_can_set_ownership");
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(int a1)
{
if ( a1 == -1 )
_assert_fail("uid.value != -1", "install-posix.c", 0x126u, "iposix_can_set_ownership");
return a1 == 0;
}

original_code:
static int
iposix_can_set_ownership (user_id_t uid)
{
  ((void) sizeof ((uid.value != -1) ? 1 : 0), __extension__ ({ if (uid.value != -1) ; else __assert_fail ("uid.value != -1", "install-posix.c", 294, __extension__ __PRETTY_FUNCTION__); }));
  return uid.value == 0;
}

canonical_original_code:
static int iposix_can_set_ownership(struct user_id_t uid)
{
  ((void) sizeof ((uid.value != -1) ? 1 : 0), __extension__ ({ if (uid.value != -1) ; else __assert_fail ("uid.value != -1", "install-posix.c", 294, __extension__ __PRETTY_FUNCTION__); }));
  return uid.value == 0;
}


decompiled_code:
void __fastcall iposix_uid_free(__int64 a1)
{
if ( !a1 )
_assert_fail("uid != NULL", "install-posix.c", 0xB7u, "iposix_uid_free");
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
if ( !a1 )
_assert_fail("uid != NULL", "install-posix.c", 0xB7u, "iposix_uid_free");
}

original_code:
static void
iposix_uid_free (user_id_t *uid)
{
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 183, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void iposix_uid_free(struct user_id_t *uid)
{
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 183, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types:
uid
struct user_id_t { int value; } *


decompiled_code:
void __fastcall iposix_gid_free(__int64 a1)
{
if ( !a1 )
_assert_fail("gid != NULL", "install-posix.c", 0x76u, "iposix_gid_free");
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
if ( !a1 )
_assert_fail("gid != NULL", "install-posix.c", 0x76u, "iposix_gid_free");
}

original_code:
static void
iposix_gid_free (group_id_t *gid)
{
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 118, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void iposix_gid_free(struct group_id_t *gid)
{
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 118, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types:
gid
struct group_id_t { int value; } *


decompiled_code:
_BOOL8 __fastcall iposix_file_link(const char *a1, const char *a2)
{
if ( !a1 )
_assert_fail("src != NULL", "install-posix.c", 0x112u, "iposix_file_link");
if ( !a2 )
_assert_fail("dst != NULL", "install-posix.c", 0x113u, "iposix_file_link");
return symlink(a1, a2) != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(const char *a1, const char *a2)
{
if ( !a1 )
_assert_fail("src != NULL", "install-posix.c", 0x112u, "iposix_file_link");
if ( !a2 )
_assert_fail("dst != NULL", "install-posix.c", 0x113u, "iposix_file_link");
return symlink(a1, a2) != -1;
}

original_code:
static int
iposix_file_link (const char *src, const char *dst)
{
  ((void) sizeof ((src != ((void *)0)) ? 1 : 0), __extension__ ({ if (src != ((void *)0)) ; else __assert_fail ("src != NULL", "install-posix.c", 274, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((dst != ((void *)0)) ? 1 : 0), __extension__ ({ if (dst != ((void *)0)) ; else __assert_fail ("dst != NULL", "install-posix.c", 275, __extension__ __PRETTY_FUNCTION__); }));
  if (symlink (src, dst) == -1) return 0;
  return 1;
}

canonical_original_code:
static int iposix_file_link(char *src, char *dst)
{
  ((void) sizeof ((src != ((void *)0)) ? 1 : 0), __extension__ ({ if (src != ((void *)0)) ; else __assert_fail ("src != NULL", "install-posix.c", 274, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((dst != ((void *)0)) ? 1 : 0), __extension__ ({ if (dst != ((void *)0)) ; else __assert_fail ("dst != NULL", "install-posix.c", 275, __extension__ __PRETTY_FUNCTION__); }));
  if (symlink (src, dst) == -1) return 0;
  return 1;
}

variable_types:
src
char *

variable_types:
dst
char *


decompiled_code:
__int64 __fastcall iposix_file_size(const char *a1, __off_t *a2)
{
int v2; // edx
__int64 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0x106u, "iposix_file_size");
if ( !a2 )
_assert_fail("size != NULL", "install-posix.c", 0x107u, "iposix_file_size");
v2 = stat(a1, &v4);
result = 0LL;
if ( v2 != -1 )
{
*a2 = v4.st_size;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(const char *a1, __off_t *a2)
{
int v2; // edx
__int64 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0x106u, "iposix_file_size");
if ( !a2 )
_assert_fail("size != NULL", "install-posix.c", 0x107u, "iposix_file_size");
v2 = stat(a1, &v4);
result = 0LL;
if ( v2 != -1 )
{
*a2 = v4.st_size;
result = 1LL;
}
return result;
}

original_code:
static int
iposix_file_size (const char *file, size_t *size)
{
  struct stat sb;
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 262, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((size != ((void *)0)) ? 1 : 0), __extension__ ({ if (size != ((void *)0)) ; else __assert_fail ("size != NULL", "install-posix.c", 263, __extension__ __PRETTY_FUNCTION__); }));
  if (stat (file, &sb) == -1) return 0;
  *size = sb.st_size;
  return 1;
}

canonical_original_code:
static int iposix_file_size(char *file, unsigned long *size)
{
  struct stat sb;
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 262, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((size != ((void *)0)) ? 1 : 0), __extension__ ({ if (size != ((void *)0)) ; else __assert_fail ("size != NULL", "install-posix.c", 263, __extension__ __PRETTY_FUNCTION__); }));
  if (stat (file, &sb) == -1) return 0;
  *size = sb.st_size;
  return 1;
}

variable_types:
file
char *

variable_types:
size
unsigned long *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall iposix_file_ownership_get(const char *a1, __uid_t *a2, __gid_t *a3)
{
int v4; // edx
__int64 result; // rax
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xF6u, "iposix_file_ownership_get");
if ( !a2 )
_assert_fail("uid != NULL", "install-posix.c", 0xF7u, "iposix_file_ownership_get");
if ( !a3 )
_assert_fail("gid != NULL", "install-posix.c", 0xF8u, "iposix_file_ownership_get");
v4 = stat(a1, &v6);
result = 0LL;
if ( v4 != -1 )
{
*a2 = v6.st_uid;
*a3 = v6.st_gid;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1, __uid_t *a2, __gid_t *a3)
{
int v4; // edx
__int64 result; // rax
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xF6u, "iposix_file_ownership_get");
if ( !a2 )
_assert_fail("uid != NULL", "install-posix.c", 0xF7u, "iposix_file_ownership_get");
if ( !a3 )
_assert_fail("gid != NULL", "install-posix.c", 0xF8u, "iposix_file_ownership_get");
v4 = stat(a1, &v6);
result = 0LL;
if ( v4 != -1 )
{
*a2 = v6.st_uid;
*a3 = v6.st_gid;
result = 1LL;
}
return result;
}

original_code:
static int
iposix_file_ownership_get (const char *file, user_id_t *uid, group_id_t *gid)
{
  struct stat sb;
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 246, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 247, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 248, __extension__ __PRETTY_FUNCTION__); }));
  if (stat (file, &sb) == -1) return 0;
  uid->value = sb.st_uid;
  gid->value = sb.st_gid;
  return 1;
}

canonical_original_code:
static int iposix_file_ownership_get(char *file, struct user_id_t *uid, struct group_id_t *gid)
{
  struct stat sb;
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 246, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 247, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 248, __extension__ __PRETTY_FUNCTION__); }));
  if (stat (file, &sb) == -1) return 0;
  uid->value = sb.st_uid;
  gid->value = sb.st_gid;
  return 1;
}

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


decompiled_code:
__int64 __fastcall iposix_file_mode_get(const char *a1, int *a2)
{
int v2; // edx
__int64 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xE0u, "iposix_file_mode_get");
if ( !a2 )
_assert_fail("mode != NULL", "install-posix.c", 0xE1u, "iposix_file_mode_get");
v2 = stat(a1, &v4);
result = 0LL;
if ( v2 != -1 )
{
*a2 = v4.st_mode & 0x1ED;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(const char *a1, int *a2)
{
int v2; // edx
__int64 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xE0u, "iposix_file_mode_get");
if ( !a2 )
_assert_fail("mode != NULL", "install-posix.c", 0xE1u, "iposix_file_mode_get");
v2 = stat(a1, &v4);
result = 0LL;
if ( v2 != -1 )
{
*a2 = v4.st_mode & 0x1ED;
result = 1LL;
}
return result;
}

original_code:
static int
iposix_file_mode_get (const char *file, permissions_t *mode)
{
  struct stat sb;
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 224, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((mode != ((void *)0)) ? 1 : 0), __extension__ ({ if (mode != ((void *)0)) ; else __assert_fail ("mode != NULL", "install-posix.c", 225, __extension__ __PRETTY_FUNCTION__); }));
  if (stat (file, &sb) == -1) return 0;
  mode->value = sb.st_mode & 0755;
  return 1;
}

canonical_original_code:
static int iposix_file_mode_get(char *file, struct permissions_t *mode)
{
  struct stat sb;
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 224, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((mode != ((void *)0)) ? 1 : 0), __extension__ ({ if (mode != ((void *)0)) ; else __assert_fail ("mode != NULL", "install-posix.c", 225, __extension__ __PRETTY_FUNCTION__); }));
  if (stat (file, &sb) == -1) return 0;
  mode->value = sb.st_mode & 0755;
  return 1;
}

variable_types: struct permissions_t { unsigned int value; } *


decompiled_code:
_BOOL8 __fastcall iposix_file_ownership_set(const char *a1, __uid_t a2, __gid_t a3)
{
if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xEBu, "iposix_file_ownership_set");
return chown(a1, a2, a3) != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(const char *a1, __uid_t a2, __gid_t a3)
{
if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xEBu, "iposix_file_ownership_set");
return chown(a1, a2, a3) != -1;
}

original_code:
static int
iposix_file_ownership_set (const char *file, user_id_t uid, group_id_t gid)
{
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 235, __extension__ __PRETTY_FUNCTION__); }));
  if (chown (file, uid.value, gid.value) == -1) return 0;
  return 1;
}

canonical_original_code:
static int iposix_file_ownership_set(char *file, struct user_id_t uid, struct group_id_t gid)
{
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 235, __extension__ __PRETTY_FUNCTION__); }));
  if (chown (file, uid.value, gid.value) == -1) return 0;
  return 1;
}

user_defined_types:
struct user_id_t { int value; }
struct group_id_t { int value; }


decompiled_code:
_BOOL8 __fastcall iposix_file_mode_set(const char *a1, __mode_t a2)
{
if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xD6u, "iposix_file_mode_set");
return chmod(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func17(const char *a1, __mode_t a2)
{
if ( !a1 )
_assert_fail("file != NULL", "install-posix.c", 0xD6u, "iposix_file_mode_set");
return chmod(a1, a2) == 0;
}

original_code:
static int
iposix_file_mode_set (const char *file, permissions_t mode)
{
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 214, __extension__ __PRETTY_FUNCTION__); }));
  return chmod (file, mode.value) == 0;
}

canonical_original_code:
static int iposix_file_mode_set(char *file, struct permissions_t mode)
{
  ((void) sizeof ((file != ((void *)0)) ? 1 : 0), __extension__ ({ if (file != ((void *)0)) ; else __assert_fail ("file != NULL", "install-posix.c", 214, __extension__ __PRETTY_FUNCTION__); }));
  return chmod (file, mode.value) == 0;
}

variable_types: struct permissions_t { unsigned int value; }


decompiled_code:
_BOOL8 __fastcall iposix_mkdir(const char *a1, __mode_t a2)
{
if ( !a1 )
_assert_fail("dir != NULL", "install-posix.c", 0xCBu, "iposix_mkdir");
return mkdir(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func18(const char *a1, __mode_t a2)
{
if ( !a1 )
_assert_fail("dir != NULL", "install-posix.c", 0xCBu, "iposix_mkdir");
return mkdir(a1, a2) == 0;
}

original_code:
static int
iposix_mkdir (const char *dir, permissions_t mode)
{
  ((void) sizeof ((dir != ((void *)0)) ? 1 : 0), __extension__ ({ if (dir != ((void *)0)) ; else __assert_fail ("dir != NULL", "install-posix.c", 203, __extension__ __PRETTY_FUNCTION__); }));
  return mkdir (dir, mode.value) == 0;
}

canonical_original_code:
static int iposix_mkdir(char *dir, struct permissions_t mode)
{
  ((void) sizeof ((dir != ((void *)0)) ? 1 : 0), __extension__ ({ if (dir != ((void *)0)) ; else __assert_fail ("dir != NULL", "install-posix.c", 203, __extension__ __PRETTY_FUNCTION__); }));
  return mkdir (dir, mode.value) == 0;
}

variable_types:
dir
char *

user_defined_types: struct permissions_t { unsigned int value; }


decompiled_code:
__int64 __fastcall iposix_uid_lookup(const char *a1, __uid_t *a2)
{
struct passwd *v2; // rax

if ( !a1 )
_assert_fail("user != NULL", "install-posix.c", 0xA4u, "iposix_uid_lookup");
if ( !a2 )
_assert_fail("uid != NULL", "install-posix.c", 0xA5u, "iposix_uid_lookup");
v2 = getpwnam(a1);
if ( !v2 )
return 0LL;
*a2 = v2->pw_uid;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(const char *a1, __uid_t *a2)
{
struct passwd *v2; // rax

if ( !a1 )
_assert_fail("user != NULL", "install-posix.c", 0xA4u, "iposix_uid_lookup");
if ( !a2 )
_assert_fail("uid != NULL", "install-posix.c", 0xA5u, "iposix_uid_lookup");
v2 = getpwnam(a1);
if ( !v2 )
return 0LL;
*a2 = v2->pw_uid;
return 1LL;
}

original_code:
static int
iposix_uid_lookup (const char *user, user_id_t *uid)
{
  struct passwd *pwd;
  ((void) sizeof ((user != ((void *)0)) ? 1 : 0), __extension__ ({ if (user != ((void *)0)) ; else __assert_fail ("user != NULL", "install-posix.c", 164, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 165, __extension__ __PRETTY_FUNCTION__); }));
  pwd = getpwnam (user);
  if (!pwd) return 0;
  uid->value = pwd->pw_uid;
  return 1;
}

canonical_original_code:
static int iposix_uid_lookup(char *user, struct user_id_t *uid)
{
  struct passwd *pwd;
  ((void) sizeof ((user != ((void *)0)) ? 1 : 0), __extension__ ({ if (user != ((void *)0)) ; else __assert_fail ("user != NULL", "install-posix.c", 164, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 165, __extension__ __PRETTY_FUNCTION__); }));
  pwd = getpwnam (user);
  if (!pwd) return 0;
  uid->value = pwd->pw_uid;
  return 1;
}

variable_types:
user
char *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
__int64 __fastcall iposix_uid_current(__uid_t *a1)
{
if ( !a1 )
_assert_fail("uid != NULL", "install-posix.c", 0x99u, "iposix_uid_current");
*a1 = getuid();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func20(__uid_t *a1)
{
if ( !a1 )
_assert_fail("uid != NULL", "install-posix.c", 0x99u, "iposix_uid_current");
*a1 = getuid();
return 1LL;
}

original_code:
static int
iposix_uid_current (user_id_t *uid)
{
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 153, __extension__ __PRETTY_FUNCTION__); }));
  uid->value = getuid ();
  return 1;
}

canonical_original_code:
static int iposix_uid_current(struct user_id_t *uid)
{
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 153, __extension__ __PRETTY_FUNCTION__); }));
  uid->value = getuid ();
  return 1;
}


decompiled_code:
__int64 __fastcall iposix_uid_scan(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x8Fu, "iposix_uid_scan");
if ( !a2 )
_assert_fail("uid != NULL", "install-posix.c", 0x90u, "iposix_uid_scan");
return _isoc99_sscanf(a1, "%d", a2);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x8Fu, "iposix_uid_scan");
if ( !a2 )
_assert_fail("uid != NULL", "install-posix.c", 0x90u, "iposix_uid_scan");
return _isoc99_sscanf(a1, "%d", a2);
}

original_code:
static unsigned int
iposix_uid_scan (const char *buffer, user_id_t *uid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 143, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 144, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = sscanf (buffer, "%d", &uid->value);
  return size;
}

canonical_original_code:
static unsigned int iposix_uid_scan(char *buffer, struct user_id_t *uid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 143, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((uid != ((void *)0)) ? 1 : 0), __extension__ ({ if (uid != ((void *)0)) ; else __assert_fail ("uid != NULL", "install-posix.c", 144, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = sscanf (buffer, "%d", &uid->value);
  return size;
}

variable_types:
buffer
char *

variable_types:
size
unsigned int


decompiled_code:
__int64 __fastcall iposix_gid_scan(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x4Eu, "iposix_gid_scan");
if ( !a2 )
_assert_fail("gid != NULL", "install-posix.c", 0x4Fu, "iposix_gid_scan");
return _isoc99_sscanf(a1, "%d", a2);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x4Eu, "iposix_gid_scan");
if ( !a2 )
_assert_fail("gid != NULL", "install-posix.c", 0x4Fu, "iposix_gid_scan");
return _isoc99_sscanf(a1, "%d", a2);
}

original_code:
static unsigned int
iposix_gid_scan (const char *buffer, group_id_t *gid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 78, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 79, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = sscanf (buffer, "%d", &gid->value);
  return size;
}

canonical_original_code:
static unsigned int iposix_gid_scan(char *buffer, struct group_id_t *gid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 78, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 79, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = sscanf (buffer, "%d", &gid->value);
  return size;
}


decompiled_code:
int __fastcall iposix_uid_format(char *a1, unsigned int a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x86u, "iposix_uid_format");
return snprintf(a1, 0x20uLL, "%d", a2);
}

canonical_decompiled_code:
int __fastcall func23(char *a1, unsigned int a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x86u, "iposix_uid_format");
return snprintf(a1, 0x20uLL, "%d", a2);
}

original_code:
static unsigned int
iposix_uid_format (char *buffer, user_id_t uid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 134, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = snprintf (buffer, (sizeof (int) << 3), "%d", uid.value);
  return size;
}

canonical_original_code:
static unsigned int iposix_uid_format(char *buffer, struct user_id_t uid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 134, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = snprintf (buffer, (sizeof (int) << 3), "%d", uid.value);
  return size;
}


decompiled_code:
int __fastcall iposix_gid_format(char *a1, unsigned int a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x45u, "iposix_gid_format");
return snprintf(a1, 0x20uLL, "%d", a2);
}

canonical_decompiled_code:
int __fastcall func24(char *a1, unsigned int a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "install-posix.c", 0x45u, "iposix_gid_format");
return snprintf(a1, 0x20uLL, "%d", a2);
}

original_code:
static unsigned int
iposix_gid_format (char *buffer, group_id_t gid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 69, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = snprintf (buffer, (sizeof (int) << 3), "%d", gid.value);
  return size;
}

canonical_original_code:
static unsigned int iposix_gid_format(char *buffer, struct group_id_t gid)
{
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "install-posix.c", 69, __extension__ __PRETTY_FUNCTION__); }));
  unsigned int size = snprintf (buffer, (sizeof (int) << 3), "%d", gid.value);
  return size;
}

variable_types:
gid
struct group_id_t { int value; }


decompiled_code:
__int64 __fastcall iposix_gid_lookup(const char *a1, __gid_t *a2)
{
struct group *v2; // rax

if ( !a1 )
_assert_fail("group != NULL", "install-posix.c", 0x63u, "iposix_gid_lookup");
if ( !a2 )
_assert_fail("gid != NULL", "install-posix.c", 0x64u, "iposix_gid_lookup");
v2 = getgrnam(a1);
if ( !v2 )
return 0LL;
*a2 = v2->gr_gid;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func25(const char *a1, __gid_t *a2)
{
struct group *v2; // rax

if ( !a1 )
_assert_fail("group != NULL", "install-posix.c", 0x63u, "iposix_gid_lookup");
if ( !a2 )
_assert_fail("gid != NULL", "install-posix.c", 0x64u, "iposix_gid_lookup");
v2 = getgrnam(a1);
if ( !v2 )
return 0LL;
*a2 = v2->gr_gid;
return 1LL;
}

original_code:
static int
iposix_gid_lookup (const char *group, group_id_t *gid)
{
  struct group *grp;
  ((void) sizeof ((group != ((void *)0)) ? 1 : 0), __extension__ ({ if (group != ((void *)0)) ; else __assert_fail ("group != NULL", "install-posix.c", 99, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 100, __extension__ __PRETTY_FUNCTION__); }));
  grp = getgrnam (group);
  if (!grp) return 0;
  gid->value = grp->gr_gid;
  return 1;
}

canonical_original_code:
static int iposix_gid_lookup(char *group, struct group_id_t *gid)
{
  struct group *grp;
  ((void) sizeof ((group != ((void *)0)) ? 1 : 0), __extension__ ({ if (group != ((void *)0)) ; else __assert_fail ("group != NULL", "install-posix.c", 99, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 100, __extension__ __PRETTY_FUNCTION__); }));
  grp = getgrnam (group);
  if (!grp) return 0;
  gid->value = grp->gr_gid;
  return 1;
}

variable_types:
group
char *

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *


decompiled_code:
__int64 __fastcall iposix_gid_current(__gid_t *a1)
{
if ( !a1 )
_assert_fail("gid != NULL", "install-posix.c", 0x58u, "iposix_gid_current");
*a1 = getgid();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func26(__gid_t *a1)
{
if ( !a1 )
_assert_fail("gid != NULL", "install-posix.c", 0x58u, "iposix_gid_current");
*a1 = getgid();
return 1LL;
}

original_code:
static int
iposix_gid_current (group_id_t *gid)
{
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 88, __extension__ __PRETTY_FUNCTION__); }));
  gid->value = getgid ();
  return 1;
}

canonical_original_code:
static int iposix_gid_current(struct group_id_t *gid)
{
  ((void) sizeof ((gid != ((void *)0)) ? 1 : 0), __extension__ ({ if (gid != ((void *)0)) ; else __assert_fail ("gid != NULL", "install-posix.c", 88, __extension__ __PRETTY_FUNCTION__); }));
  gid->value = getgid ();
  return 1;
}


decompiled_code:
int *iposix_error_reset()
{
int *result; // rax

result = _errno_location();
*result = 0;
return result;
}

canonical_decompiled_code:
int *func27()
{
int *result; // rax

result = _errno_location();
*result = 0;
return result;
}

original_code:
static void
iposix_error_reset (void)
{
  (*__errno_location ()) = 0;
}

canonical_original_code:
static void iposix_error_reset()
{
  (*__errno_location ()) = 0;
}


decompiled_code:
__int64 iposix_error_current()
{
return *_errno_location();
}

canonical_decompiled_code:
__int64 func28()
{
return *_errno_location();
}

original_code:
static install_error_t
iposix_error_current (void)
{
  install_error_t e;
  e.value = (unsigned long) (*__errno_location ());
  return e;
}

canonical_original_code:
static struct install_error_t iposix_error_current()
{
  struct install_error_t e;
  e.value = (unsigned long) (*__errno_location ());
  return e;
}

variable_types: struct install_error_t { unsigned long value; }


decompiled_code:
char *__fastcall iposix_error_message(int a1)
{
return strerror(a1);
}

canonical_decompiled_code:
char *__fastcall func29(int a1)
{
return strerror(a1);
}

original_code:
static const char *
iposix_error_message (install_error_t error)
{
  return strerror (error.value);
}

canonical_original_code:
static char *iposix_error_message(struct install_error_t error)
{
  return strerror (error.value);
}

user_defined_types: struct install_error_t { unsigned long value; }


decompiled_code:
char *iposix_error_message_current()
{
int v0; // eax

v0 = iposix_error_current();
return iposix_error_message(v0);
}

canonical_decompiled_code:
char *func30()
{
int v0; // eax

v0 = func28();
return func29(v0);
}

original_code:
static const char *
iposix_error_message_current (void)
{
  return iposix_error_message (iposix_error_current ());
}

canonical_original_code:
static char *iposix_error_message_current()
{
  return iposix_error_message (iposix_error_current ());
}


decompiled_code:
int __fastcall cb_info(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

original_code:
static void
cb_info (const char *str, void *data)
{
  (void) fprintf (stderr, "%s\n", str);
}

canonical_original_code:
static void cb_info(char *str, void *data)
{
  (void) fprintf (stderr, "%s\n", str);
}

variable_types:
str
char *

variable_types:
data
void *


decompiled_code:
int __fastcall cb_warn(const char *a1)
{
return fprintf(stderr, "%s: warning: %s\n", "instchk", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return fprintf(stderr, "%s: warning: %s\n", "instchk", a1);
}

original_code:
static void
cb_warn (const char *str, void *data)
{
  (void) fprintf (stderr, "%s: warning: %s\n", progname, str);
}

canonical_original_code:
static void cb_warn(char *str, void *data)
{
  (void) fprintf (stderr, "%s: warning: %s\n", progname, str);
}


repo: ioerror/libmsr

decompiled_code:
__int64 __fastcall msr_dumpbits(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbp
unsigned int i; // ebx
int v4; // eax

if ( a2 > 0 )
{
v2 = a1;
do
{
for ( i = 7; i != -1; --i )
{
v4 = *v2;
if ( _bittest(&v4, i) )
putchar(49);
else
putchar(48);
}
++v2;
}
while ( v2 != &a1[a2 - 1 + 1] );
}
putchar(10);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbp
unsigned int i; // ebx
int v4; // eax

if ( a2 > 0 )
{
v2 = a1;
do
{
for ( i = 7; i != -1; --i )
{
v4 = *v2;
if ( _bittest(&v4, i) )
putchar(49);
else
putchar(48);
}
++v2;
}
while ( v2 != &a1[a2 - 1 + 1] );
}
putchar(10);
return 0LL;
}

original_code:
int
msr_dumpbits (uint8_t * buf, int len)
{
 int bytes, i;
 for (bytes = 0; bytes < len; bytes++) {
  for (i = 7; i > -1; i--) {
   if (buf[bytes] & (1 << i))
    printf("1");
   else
    printf("0");
  }
 }
 printf ("\n");
 return (0);
}

canonical_original_code:
int msr_dumpbits(unsigned char *buf, int len)
{
 int bytes; int i;
 for (bytes = 0; bytes < len; bytes++) {
  for (i = 7; i > -1; i--) {
   if (buf[bytes] & (1 << i))
    printf("1");
   else
    printf("0");
  }
 }
 printf ("\n");
 return (0);
}

variable_types:
buf
unsigned char *

variable_types: len int

variable_types: bytes int

variable_types: i int


decompiled_code:
__int64 __fastcall msr_getbit(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 v4; // rsi
__int64 v5; // rdx

v4 = a3;
v5 = 8 * (unsigned int)a2;
if ( (int)v5 >= (int)v4 )
return ((int)*(unsigned __int8 *)(a1 + (int)v4 / 8) >> (((unsigned int)((int)v4 >> 31) >> 29)
- ((((unsigned int)((int)v4 >> 31) >> 29) + v4) & 7)
+ 7)) & 1;
printf("%d > %d\n", v4, v5);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 v4; // rsi
__int64 v5; // rdx

v4 = a3;
v5 = 8 * (unsigned int)a2;
if ( (int)v5 >= (int)v4 )
return ((int)*(unsigned __int8 *)(a1 + (int)v4 / 8) >> (((unsigned int)((int)v4 >> 31) >> 29)
- ((((unsigned int)((int)v4 >> 31) >> 29) + v4) & 7)
+ 7)) & 1;
printf("%d > %d\n", v4, v5);
return 0xFFFFFFFFLL;
}

original_code:
int
msr_getbit (uint8_t * buf, uint8_t len, int bit)
{
 int byte;
 int b;
 if (bit > (len * 8)) {
  printf ("%d > %d\n", bit, len * 8);
  return (-1);
 }
 byte = bit / 8;
 b = 7 - (bit % 8);
 if (buf[byte] & (1 << b))
  return (1);
 return (0);
}

canonical_original_code:
int msr_getbit(unsigned char *buf, unsigned char len, int bit)
{
 int byte;
 int b;
 if (bit > (len * 8)) {
  printf ("%d > %d\n", bit, len * 8);
  return (-1);
 }
 byte = bit / 8;
 b = 7 - (bit % 8);
 if (buf[byte] & (1 << b))
  return (1);
 return (0);
}

variable_types:
len
unsigned char

variable_types: bit int

variable_types: byte int

variable_types: b int


decompiled_code:
__int64 __fastcall msr_setbit(__int64 a1, unsigned __int8 a2, unsigned int a3, int a4)
{
__int64 v5; // rsi
__int64 v6; // rdx
int v8; // eax
unsigned int v9; // ecx
__int64 result; // rax

v5 = a3;
v6 = 8 * (unsigned int)a2;
if ( (int)v6 < (int)v5 )
{
printf("%d > %d\n", v5, v6);
result = 0xFFFFFFFFLL;
}
else
{
v8 = (int)v5 / 8;
v9 = ((unsigned int)((int)v5 >> 31) >> 29) - ((((unsigned int)((int)v5 >> 31) >> 29) + (_BYTE)v5) & 7) + 7;
if ( a4 )
*(_BYTE *)(a1 + v8) |= 1 << v9;
else
*(_BYTE *)(a1 + v8) &= __ROL4__(-2, v9);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int8 a2, unsigned int a3, int a4)
{
__int64 v5; // rsi
__int64 v6; // rdx
int v8; // eax
unsigned int v9; // ecx
__int64 result; // rax

v5 = a3;
v6 = 8 * (unsigned int)a2;
if ( (int)v6 < (int)v5 )
{
printf("%d > %d\n", v5, v6);
result = 0xFFFFFFFFLL;
}
else
{
v8 = (int)v5 / 8;
v9 = ((unsigned int)((int)v5 >> 31) >> 29) - ((((unsigned int)((int)v5 >> 31) >> 29) + (_BYTE)v5) & 7) + 7;
if ( a4 )
*(_BYTE *)(a1 + v8) |= 1 << v9;
else
*(_BYTE *)(a1 + v8) &= __ROL4__(-2, v9);
result = 0LL;
}
return result;
}

original_code:
int
msr_setbit (uint8_t * buf, uint8_t len, int bit, int val)
{
 int byte;
 int b;
 if (bit > (len * 8)) {
  printf ("%d > %d\n", bit, len * 8);
  return (-1);
 }
 byte = bit / 8;
 b = 7 - (bit % 8);
 if (val)
  buf[byte] |= 1 << b;
 else
  buf[byte] &= ~(1 << b);
 return (0);
}

canonical_original_code:
int msr_setbit(unsigned char *buf, unsigned char len, int bit, int val)
{
 int byte;
 int b;
 if (bit > (len * 8)) {
  printf ("%d > %d\n", bit, len * 8);
  return (-1);
 }
 byte = bit / 8;
 b = 7 - (bit % 8);
 if (val)
  buf[byte] |= 1 << b;
 else
  buf[byte] &= ~(1 << b);
 return (0);
}

variable_types: val int


original_code:
int
msr_decode(uint8_t * inbuf, uint8_t inlen,
    uint8_t * outbuf, uint8_t * outlen, int bpc)
{
 uint8_t * b;
 uint8_t len;
 int ch = 0;
 char byte = 0;
 int i, x;
 len = inlen;
 b = inbuf;
 x = 0;
 for (i = 0; i < len * 8; i++) {
  byte |= msr_getbit (b, len, i) << ch;
  if (ch == (bpc - 1)) {
   byte &= ~(1 << ch);
   if (bpc < 7)
    byte |= 0x30;
   else {
    if (byte < 0x20)
     byte |= 0x20;
    else {
     byte |= 0x40;
     byte -= 0x20;
    }
   }
   outbuf[x] = byte;
   x++;
   if (x == *outlen)
    break;
   ch = 0;
   byte = 0;
  } else
   ch++;
 }
 if (x == *outlen)
  return (-1);
 *outlen = x;
 return (0);
}

canonical_original_code:
int msr_decode(unsigned char *inbuf, unsigned char inlen, unsigned char *outbuf, unsigned char *outlen, int bpc)
{
 unsigned char *b;
 unsigned char len;
 int ch = 0;
 char byte = 0;
 int i; int x;
 len = inlen;
 b = inbuf;
 x = 0;
 for (i = 0; i < len * 8; i++) {
  byte |= msr_getbit (b, len, i) << ch;
  if (ch == (bpc - 1)) {
   byte &= ~(1 << ch);
   if (bpc < 7)
    byte |= 0x30;
   else {
    if (byte < 0x20)
     byte |= 0x20;
    else {
     byte |= 0x40;
     byte -= 0x20;
    }
   }
   outbuf[x] = byte;
   x++;
   if (x == *outlen)
    break;
   ch = 0;
   byte = 0;
  } else
   ch++;
 }
 if (x == *outlen)
  return (-1);
 *outlen = x;
 return (0);
}

variable_types:
inbuf
unsigned char *

variable_types:
inlen
unsigned char

variable_types:
outbuf
unsigned char *

variable_types:
outlen
unsigned char *

variable_types: bpc int

variable_types:
b
unsigned char *

variable_types: ch int

variable_types: byte char

variable_types: x int