main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int v4; // er14
_QWORD *v5; // r13
size_t v6; // r12
_QWORD *v7; // rbx
int v8; // er15
_QWORD *v9; // rbx
size_t v10; // rbp
double *v11; // r12
_DWORD *v12; // rbp
double v13; // xmm0_8
_QWORD *v14; // rbx
double v15; // xmm0_8
__int64 v16; // rcx
double *v17; // rax
double *v18; // rdx
__int64 v19; // r15
double v20; // xmm0_8
double v21; // xmm1_8
__int64 k; // rbx
void *v23; // rdi
__int64 l; // rbx
void *v25; // rdi
int v27; // [rsp+8h] [rbp-A0h]
void (__fastcall *j)(_QWORD, _QWORD, _QWORD); // [rsp+8h] [rbp-A0h]
int i; // [rsp+14h] [rbp-94h]
_QWORD *ptr; // [rsp+18h] [rbp-90h]
double v31; // [rsp+20h] [rbp-88h]
__int64 v32; // [rsp+28h] [rbp-80h]
struct timeval tv; // [rsp+30h] [rbp-78h] BYREF
struct timeval v34; // [rsp+40h] [rbp-68h] BYREF
__int64 v35[11]; // [rsp+50h] [rbp-58h] BYREF

puts("**** bbtree **** ");
v3 = processArgs(argc, (__int64)argv);
v4 = n;
v5 = calloc(n, 8uLL);
v27 = m;
ptr = calloc(m, 8uLL);
if ( v4 <= 0 )
{
v8 = d;
}
else
{
v6 = d;
v7 = v5;
v8 = d;
do
*v7++ = calloc(v6, 8uLL);
while ( &v5[v4] != v7 );
}
if ( v27 > 0 )
{
v9 = ptr;
do
*v9++ = calloc(v8, 8uLL);
while ( &ptr[v27] != v9 );
}
v10 = ::k;
v11 = (double *)calloc(::k, 8uLL);
v12 = calloc(v10, 4uLL);
readData(v5, (unsigned int)v4, (unsigned int)v8, datafile, v3);
readData(ptr, (unsigned int)m, (unsigned int)d, queryfile, v3);
if ( divChoice == 2 )
{
dkl(v35);
puts("divergence = conjugate to KL");
puts("WARNING: this has not been tested thoroughly");
}
else if ( divChoice > 2 )
{
if ( divChoice == 3 )
{
is(v35);
puts("divergence = Itakura-Saito");
puts("WARNING: this has not been tested thoroughly");
}
}
else if ( divChoice )
{
if ( divChoice == 1 )
{
kl(v35);
puts("divergence = KL");
}
}
else
{
l2squared(v35);
puts("divergence = l_2^2");
}
puts("building.....");
gettimeofday(&tv, 0LL);
v32 = buildTree(v5, (unsigned int)n, (unsigned int)d, (unsigned int)bucketSize);
gettimeofday(&v34, 0LL);
v13 = timediff(tv.tv_sec, tv.tv_usec, v34.tv_sec, v34.tv_usec);
printf("done... build time: %6.2f \n", v13);
gettimeofday(&tv, 0LL);
v14 = ptr;
multisearch(
v32,
ptr,
v5,
(unsigned int)n,
(unsigned int)d,
(unsigned int)m,
*(double *)&eps,
v35[0],
v35[1],
v35[2],
v35[3],
(unsigned int)::k,
0x7FFFFFFFLL);
gettimeofday(&v34, 0LL);
v15 = timediff(tv.tv_sec, tv.tv_usec, v34.tv_sec, v34.tv_usec);
v31 = v15;
printf("BBTREE time elapsed = %6.3f \n", v15);
gettimeofday(&tv, 0LL);
for ( i = 0; m > i; ++v14 )
{
if ( ::k > 0 )
{
v16 = (unsigned int)::k;
v17 = v11;
v18 = &v11[::k];
do
*((_QWORD *)++v17 - 1) = LC17;
while ( v17 != v18 );
memset(v12, 255, 4 * v16);
}
v19 = 0LL;
for ( j = (void (__fastcall *)(_QWORD, _QWORD, _QWORD))v35[0]; n > (int)v19; ++v19 )
{
j(v5[v19], *v14, (unsigned int)d);
if ( *v12 == -1 || *v11 > v15 )
insert(v12, v11, (unsigned int)v19, (unsigned int)::k);
}
++i;
}
gettimeofday(&v34, 0LL);
v20 = timediff(tv.tv_sec, tv.tv_usec, v34.tv_sec, v34.tv_usec);
printf("BRUTE time elapsed = %6.3f \n", v20);
v21 = v20;
if ( isOutfile )
{
v20 = v31;
writeDoubs(2LL, outfile, v31, v21);
}
for ( k = 0LL; n > (int)k; ++k )
{
v23 = (void *)v5[k];
free(v23);
}
for ( l = 0LL; m > (int)l; ++l )
{
v25 = (void *)ptr[l];
free(v25);
}
free(v5);
free(ptr);
free(v12);
free(v11);
deleteTree(v32, v20, v21);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int v4; // er14
_QWORD *v5; // r13
size_t v6; // r12
_QWORD *v7; // rbx
int v8; // er15
_QWORD *v9; // rbx
size_t v10; // rbp
double *v11; // r12
_DWORD *v12; // rbp
double v13; // xmm0_8
_QWORD *v14; // rbx
double v15; // xmm0_8
__int64 v16; // rcx
double *v17; // rax
double *v18; // rdx
__int64 v19; // r15
double v20; // xmm0_8
double v21; // xmm1_8
__int64 k; // rbx
void *v23; // rdi
__int64 l; // rbx
void *v25; // rdi
int v27; // [rsp+8h] [rbp-A0h]
void (__fastcall *j)(_QWORD, _QWORD, _QWORD); // [rsp+8h] [rbp-A0h]
int i; // [rsp+14h] [rbp-94h]
_QWORD *ptr; // [rsp+18h] [rbp-90h]
double v31; // [rsp+20h] [rbp-88h]
__int64 v32; // [rsp+28h] [rbp-80h]
struct timeval tv; // [rsp+30h] [rbp-78h] BYREF
struct timeval v34; // [rsp+40h] [rbp-68h] BYREF
__int64 v35[11]; // [rsp+50h] [rbp-58h] BYREF

puts("**** bbtree **** ");
v3 = func0(argc, (__int64)argv);
v4 = n;
v5 = calloc(n, 8uLL);
v27 = m;
ptr = calloc(m, 8uLL);
if ( v4 <= 0 )
{
v8 = d;
}
else
{
v6 = d;
v7 = v5;
v8 = d;
do
*v7++ = calloc(v6, 8uLL);
while ( &v5[v4] != v7 );
}
if ( v27 > 0 )
{
v9 = ptr;
do
*v9++ = calloc(v8, 8uLL);
while ( &ptr[v27] != v9 );
}
v10 = ::k;
v11 = (double *)calloc(::k, 8uLL);
v12 = calloc(v10, 4uLL);
readData(v5, (unsigned int)v4, (unsigned int)v8, datafile, v3);
readData(ptr, (unsigned int)m, (unsigned int)d, queryfile, v3);
if ( divChoice == 2 )
{
dkl(v35);
puts("divergence = conjugate to KL");
puts("WARNING: this has not been tested thoroughly");
}
else if ( divChoice > 2 )
{
if ( divChoice == 3 )
{
is(v35);
puts("divergence = Itakura-Saito");
puts("WARNING: this has not been tested thoroughly");
}
}
else if ( divChoice )
{
if ( divChoice == 1 )
{
kl(v35);
puts("divergence = KL");
}
}
else
{
l2squared(v35);
puts("divergence = l_2^2");
}
puts("building.....");
gettimeofday(&tv, 0LL);
v32 = buildTree(v5, (unsigned int)n, (unsigned int)d, (unsigned int)bucketSize);
gettimeofday(&v34, 0LL);
v13 = func1(tv.tv_sec, tv.tv_usec, v34.tv_sec, v34.tv_usec);
printf("done... build time: %6.2f \n", v13);
gettimeofday(&tv, 0LL);
v14 = ptr;
multisearch(
v32,
ptr,
v5,
(unsigned int)n,
(unsigned int)d,
(unsigned int)m,
*(double *)&eps,
v35[0],
v35[1],
v35[2],
v35[3],
(unsigned int)::k,
0x7FFFFFFFLL);
gettimeofday(&v34, 0LL);
v15 = func1(tv.tv_sec, tv.tv_usec, v34.tv_sec, v34.tv_usec);
v31 = v15;
printf("BBTREE time elapsed = %6.3f \n", v15);
gettimeofday(&tv, 0LL);
for ( i = 0; m > i; ++v14 )
{
if ( ::k > 0 )
{
v16 = (unsigned int)::k;
v17 = v11;
v18 = &v11[::k];
do
*((_QWORD *)++v17 - 1) = LC17;
while ( v17 != v18 );
memset(v12, 255, 4 * v16);
}
v19 = 0LL;
for ( j = (void (__fastcall *)(_QWORD, _QWORD, _QWORD))v35[0]; n > (int)v19; ++v19 )
{
j(v5[v19], *v14, (unsigned int)d);
if ( *v12 == -1 || *v11 > v15 )
insert(v12, v11, (unsigned int)v19, (unsigned int)::k);
}
++i;
}
gettimeofday(&v34, 0LL);
v20 = func1(tv.tv_sec, tv.tv_usec, v34.tv_sec, v34.tv_usec);
printf("BRUTE time elapsed = %6.3f \n", v20);
v21 = v20;
if ( isOutfile )
{
v20 = v31;
writeDoubs(2LL, outfile, v31, v21);
}
for ( k = 0LL; n > (int)k; ++k )
{
v23 = (void *)v5[k];
free(v23);
}
for ( l = 0LL; m > (int)l; ++l )
{
v25 = (void *)ptr[l];
free(v25);
}
free(v5);
free(ptr);
free(v12);
free(v11);
deleteTree(v32, v20, v21);
return 0;
}

original_code:
int main(int argc, char** argv){
  int i,j, *NNs;
  double **x,**q, bbtime, brutetime,*dToNNs,divTemp;
  treenode *root;
  struct timeval tvB,tvE;
  printf("**** bbtree **** \n");
  processArgs(argc,argv);
  x = calloc(n,sizeof(double*));
  q = calloc(m,sizeof(double*));
  for(i=0;i<n;i++)
    x[i]=calloc(d,sizeof(double));
  for(i=0;i<m;i++)
    q[i]=calloc(d,sizeof(double));
  dToNNs = calloc(k,sizeof(double));
  NNs = calloc(k,sizeof(int));
  readData(x,n,d,datafile);
  readData(q,m,d,queryfile);
  bregdiv div;
  switch(divChoice){
  case 0:
    div = l2squared();
    printf("divergence = l_2^2\n");
    break;
  case 1:
    div = kl();
    printf("divergence = KL\n");
    break;
  case 2:
    div = dkl();
    printf("divergence = conjugate to KL\n");
    printf("WARNING: this has not been tested thoroughly\n");
    break;
  case 3:
    div = is();
    printf("divergence = Itakura-Saito\n");
    printf("WARNING: this has not been tested thoroughly\n");
    break;
  }
  printf("building.....\n");
  gettimeofday(&tvB,((void *)0));
  root = buildTree(x,n,d,div,bucketSize);
  gettimeofday(&tvE,((void *)0));
  printf("done... build time: %6.2f \n",timediff(tvB,tvE));
  gettimeofday(&tvB,((void *)0));
  multisearch(root,q,x,div,n,d,m,eps,k,0x7fffffff);
  gettimeofday(&tvE,((void *)0));
  bbtime = timediff(tvB,tvE);
  printf("BBTREE time elapsed = %6.3f \n",bbtime);
  double curmin;
  int curBest;
  gettimeofday(&tvB,((void *)0));
  for(i=0;i<m;i++){
    for(j=0;j<k;j++){
      dToNNs[j]=(__builtin_huge_val ());
      NNs[j]=-1;
    }
    curmin=(__builtin_huge_val ());
    curBest=-1;
    for(j=0;j<n;j++){
      divTemp = div.div(x[j],q[i],d);
      if(NNs[0]==-1 || divTemp < dToNNs[0]){
 insert(NNs,dToNNs,j,divTemp,k);
      }
    }
  }
  gettimeofday(&tvE,((void *)0));
  brutetime = timediff(tvB,tvE);
  printf("BRUTE time elapsed = %6.3f \n",brutetime);
  if(isOutfile){
    writeDoubs(2,outfile,bbtime,brutetime);
  }
  for(i=0;i<n;i++)
    free(x[i]);
  for(i=0;i<m;i++)
    free(q[i]);
  free(x);
  free(q);
  free(NNs);
  free(dToNNs);
  deleteTree(root);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
  int i; int j; int *NNs;
  double **x; double **q; double bbtime; double brutetime; double *dToNNs; double divTemp;
  struct treenode *root;
  struct timeval tvB; struct timeval tvE;
  printf("**** bbtree **** \n");
  processArgs(argc,argv);
  x = calloc(n,sizeof(double *));
  q = calloc(m,sizeof(double *));
  for(i=0;i<n;i++)
    x[i]=calloc(d,sizeof(double));
  for(i=0;i<m;i++)
    q[i]=calloc(d,sizeof(double));
  dToNNs = calloc(k,sizeof(double));
  NNs = calloc(k,sizeof(int));
  readData(x,n,d,datafile);
  readData(q,m,d,queryfile);
  struct bregdiv div;
  switch(divChoice){
  case 0:
    div = l2squared();
    printf("divergence = l_2^2\n");
    break;
  case 1:
    div = kl();
    printf("divergence = KL\n");
    break;
  case 2:
    div = dkl();
    printf("divergence = conjugate to KL\n");
    printf("WARNING: this has not been tested thoroughly\n");
    break;
  case 3:
    div = is();
    printf("divergence = Itakura-Saito\n");
    printf("WARNING: this has not been tested thoroughly\n");
    break;
  }
  printf("building.....\n");
  gettimeofday(&tvB,((void *)0));
  root = buildTree(x,n,d,div,bucketSize);
  gettimeofday(&tvE,((void *)0));
  printf("done... build time: %6.2f \n",timediff(tvB,tvE));
  gettimeofday(&tvB,((void *)0));
  multisearch(root,q,x,div,n,d,m,eps,k,0x7fffffff);
  gettimeofday(&tvE,((void *)0));
  bbtime = timediff(tvB,tvE);
  printf("BBTREE time elapsed = %6.3f \n",bbtime);
  double curmin;
  int curBest;
  gettimeofday(&tvB,((void *)0));
  for(i=0;i<m;i++){
    for(j=0;j<k;j++){
      dToNNs[j]=(__builtin_huge_val ());
      NNs[j]=-1;
    }
    curmin=(__builtin_huge_val ());
    curBest=-1;
    for(j=0;j<n;j++){
      divTemp = div.div(x[j],q[i],d);
      if(NNs[0]==-1 || divTemp < dToNNs[0]){
 insert(NNs,dToNNs,j,divTemp,k);
      }
    }
  }
  gettimeofday(&tvE,((void *)0));
  brutetime = timediff(tvB,tvE);
  printf("BRUTE time elapsed = %6.3f \n",brutetime);
  if(isOutfile){
    writeDoubs(2,outfile,bbtime,brutetime);
  }
  for(i=0;i<n;i++)
    free(x[i]);
  for(i=0;i<m;i++)
    free(q[i]);
  free(x);
  free(q);
  free(NNs);
  free(dToNNs);
  deleteTree(root);
  return 0;
}

variable_types:
NNs
int *

variable_types:
x
double **

variable_types:
q
double **

variable_types: bbtime double

variable_types: brutetime double

variable_types:
dToNNs
double *

variable_types: divTemp double

variable_types: struct treenode { double *mu; double *mup; double divToMu; double R; int *inds; int n; int isLeaf; struct treenode *l; struct treenode *r; } *

variable_types: struct bregdiv { double (*div)(); void (*divmat)(); void (*gradf)(); void (*gradfstar)(); }

variable_types: curmin double

variable_types: curBest int

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


repo: lcayton/bbtree

original_code:
void calcl2gradf(double* gf, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gf[i]=x[i];
}

canonical_original_code:
void calcl2gradf(double *gf, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gf[i]=x[i];
}

variable_types:
gf
double *

variable_types:
x
double *

variable_types: d int

variable_types: i int

return_type: void


decompiled_code:
// attributes: thunk
void __fastcall calcl2gradfstar(__int64 a1, __int64 a2, int a3)
{
calcl2gradf(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2, int a3)
{
func1(a1, a2, a3);
}

original_code:
void calcl2gradfstar(double* gfs, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gfs[i]=x[i];
}

canonical_original_code:
void calcl2gradfstar(double *gfs, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gfs[i]=x[i];
}

variable_types:
gfs
double *


original_code:
void calcl2divmat(double** dmat, double** x, double** y, int n, int m, int d){
  int i,j,k;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      dmat[i][j]=0;
      for(k=0;k<d;k++){
 dmat[i][j]+=.5*(x[i][k] - y[j][k])*(x[i][k] - y[j][k]);
      }
    }
  }
}

canonical_original_code:
void calcl2divmat(double **dmat, double **x, double **y, int n, int m, int d){
  int i; int j; int k;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      dmat[i][j]=0;
      for(k=0;k<d;k++){
 dmat[i][j]+=.5*(x[i][k] - y[j][k])*(x[i][k] - y[j][k]);
      }
    }
  }
}

variable_types:
dmat
double **

variable_types:
y
double **

variable_types: n int

variable_types: m int

variable_types: j int

variable_types: k int


calcisgradf

original_code:
void calcisgradf(double *gf, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gf[i]=-1/x[i];
}


calcisgradfstar

decompiled_code:
// attributes: thunk
void __fastcall calcisgradfstar(__int64 a1, __int64 a2, int a3)
{
calcisgradf(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2, int a3)
{
func4(a1, a2, a3);
}

original_code:
void calcisgradfstar(double *gfs, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gfs[i]=-1/x[i];
}


calckldiv

decompiled_code:
double __fastcall calckldiv(double *a1, __int64 a2, int a3)
{
double v3; // xmm3_8
__int64 v4; // r12
double *v6; // rbx
double v7; // xmm2_8
double v8; // xmm1_8

if ( a3 <= 0 )
return 0.0;
v3 = 0.0;
v4 = (__int64)&a1[(unsigned int)(a3 - 1) + 1];
v6 = a1;
v7 = *(double *)&LC3;
do
{
while ( 1 )
{
v8 = *v6;
if ( *v6 > v7 )
break;
++v6;
a2 += 8LL;
if ( v6 == (double *)v4 )
return v3;
}
++v6;
a2 += 8LL;
v7 = *(double *)&LC3;
v3 = v3 + v8 * log(v8 / *(double *)(a2 - 8)) + *(double *)(a2 - 8) - *(v6 - 1);
}
while ( v6 != (double *)v4 );
return v3;
}

canonical_decompiled_code:
double __fastcall func6(double *a1, __int64 a2, int a3)
{
double v3; // xmm3_8
__int64 v4; // r12
double *v6; // rbx
double v7; // xmm2_8
double v8; // xmm1_8

if ( a3 <= 0 )
return 0.0;
v3 = 0.0;
v4 = (__int64)&a1[(unsigned int)(a3 - 1) + 1];
v6 = a1;
v7 = *(double *)&LC3;
do
{
while ( 1 )
{
v8 = *v6;
if ( *v6 > v7 )
break;
++v6;
a2 += 8LL;
if ( v6 == (double *)v4 )
return v3;
}
++v6;
a2 += 8LL;
v7 = *(double *)&LC3;
v3 = v3 + v8 * log(v8 / *(double *)(a2 - 8)) + *(double *)(a2 - 8) - *(v6 - 1);
}
while ( v6 != (double *)v4 );
return v3;
}

original_code:
double calckldiv(double *x, double *y, int d){
  int i;
  double ans=0;
  for(i=0;i<d;i++){
    if(x[i] > 1e-12 )
      ans+= x[i]*log(x[i]/y[i])+y[i]-x[i];
  }
  return ans;
}

canonical_original_code:
double calckldiv(double *x, double *y, int d){
  int i;
  double ans = 0;
  for(i=0;i<d;i++){
    if(x[i] > 1e-12 )
      ans+= x[i]*log(x[i]/y[i])+y[i]-x[i];
  }
  return ans;
}

variable_types:
y
double *

variable_types: ans double

return_type: double


calckldivmat

original_code:
void calckldivmat(double **dmat, double **x, double** y, int n, int m, int d){
  int i,j;
  for (i=0;i<n;i++){
    for(j=0;j<m;j++)
      dmat[i][j] = calckldiv(x[i],y[j],d);
  }
}

canonical_original_code:
void calckldivmat(double **dmat, double **x, double **y, int n, int m, int d){
  int i; int j;
  for (i=0;i<n;i++){
    for(j=0;j<m;j++)
      dmat[i][j] = calckldiv(x[i],y[j],d);
  }
}

variable_types:
x
double **


calcklgradf

original_code:
void calcklgradf(double *gf, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gf[i]=log(x[i]) +1.0;
}


calcdklgradfstar

decompiled_code:
// attributes: thunk
void __fastcall calcdklgradfstar(__int64 a1, __int64 a2, int a3)
{
calcklgradf(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, __int64 a2, int a3)
{
func8(a1, a2, a3);
}

original_code:
void calcdklgradfstar(double* gfs, double *x, int d){
  int i;
  for (i=0;i<d;i++)
    gfs[i]=log(x[i]) +1;
}

canonical_original_code:
void calcdklgradfstar(double *gfs, double *x, int d){
  int i;
  for (i=0;i<d;i++)
    gfs[i]=log(x[i]) +1;
}


calcisdiv

original_code:
double calcisdiv(double *x, double *y, int d){
  double ans=0;
  int i;
  for (i=0;i<d;i++)
    ans+=x[i]/y[i] - log(x[i]/y[i]) -1;
  return ans;
}

canonical_original_code:
double calcisdiv(double *x, double *y, int d){
  double ans = 0;
  int i;
  for (i=0;i<d;i++)
    ans+=x[i]/y[i] - log(x[i]/y[i]) -1;
  return ans;
}


calcisdivmat

original_code:
void calcisdivmat(double** dmat, double** x, double **y, int n, int m, int d){
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      dmat[i][j]=calcisdiv(x[i],y[j],d);
    }
  }
}

canonical_original_code:
void calcisdivmat(double **dmat, double **x, double **y, int n, int m, int d){
  int i; int j;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      dmat[i][j]=calcisdiv(x[i],y[j],d);
    }
  }
}


calcklgradfstar

decompiled_code:
void __fastcall calcklgradfstar(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 i; // rbx

if ( a3 > 0 )
{
v3 = a3;
for ( i = 0LL; i != v3; ++i )
*(double *)(a1 + 8 * i) = exp(*(double *)(a2 + 8 * i) - 1.0);
}
}

original_code:
void calcklgradfstar(double *gfs,double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gfs[i] = exp(x[i]-1.0);
}

canonical_original_code:
void calcklgradfstar(double *gfs, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gfs[i] = exp(x[i]-1.0);
}


calcdklgradf

decompiled_code:
// attributes: thunk
void __fastcall calcdklgradf(__int64 a1, __int64 a2, int a3)
{
calcklgradfstar(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, __int64 a2, int a3)
{
func12(a1, a2, a3);
}

original_code:
void calcdklgradf(double *gf, double*x, int d){
  int i;
  for(i=0;i<d;i++)
    gf[i]=exp(x[i]-1);
}

canonical_original_code:
void calcdklgradf(double *gf, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gf[i]=exp(x[i]-1);
}


calcdkldiv

original_code:
double calcdkldiv(double *x, double *y, int d){
  int i;
  double ans=0;
  for(i=0;i<d;i++)
    ans+=exp(x[i]-1) - (1+x[i]-y[i])*exp(y[i]-1);
  return ans;
}

canonical_original_code:
double calcdkldiv(double *x, double *y, int d){
  int i;
  double ans = 0;
  for(i=0;i<d;i++)
    ans+=exp(x[i]-1) - (1+x[i]-y[i])*exp(y[i]-1);
  return ans;
}


calcdkldivmat

original_code:
void calcdkldivmat(double** dmat,double** x, double **y, int n, int m, int d){
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      dmat[i][j]=calcdkldiv(x[i],y[j],d);
    }
  }
}

canonical_original_code:
void calcdkldivmat(double **dmat, double **x, double **y, int n, int m, int d){
  int i; int j;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      dmat[i][j]=calcdkldiv(x[i],y[j],d);
    }
  }
}


recBinSearch

original_code:
int recBinSearch(double l, double r, treenode *node, double *q, double* qp, bregdiv div, int d, double minDistEst,double eps){
  double theta = 0.5*(double)(l+r);
  double divToMu, divToQ, lbnd;
  int i;
  distCount+=2;
  for(i=0;i<d;i++){
    xp[i]=theta*qp[i]+(1-theta)*(node->mup[i]);
  }
  div.gradfstar(x,xp,d);
  divToMu = div.div(x,node->mu,d);
  divToQ = div.div(x,q,d);
  lbnd = divToQ + (1.0/theta -1.0)*(divToMu - node->R);
  if((1.0+eps)*lbnd >= minDistEst)
    return 0;
  if( (fabs(divToMu - node->R)) < node->R*1e-3)
      return 1;
  if(divToMu > node->R)
    return recBinSearch(l,theta,node,q,qp,div,d,minDistEst,eps);
  else{
    if(divToQ*(1.0+eps) < minDistEst){
      return 1;
    }
    return recBinSearch(theta,r,node,q,qp,div,d,minDistEst,eps);
  }
}

canonical_original_code:
int recBinSearch(double l, double r, struct treenode *node, double *q, double *qp, struct bregdiv div, int d, double minDistEst, double eps){
  double theta = 0.5*(double)(l+r);
  double divToMu; double divToQ; double lbnd;
  int i;
  distCount+=2;
  for(i=0;i<d;i++){
    xp[i]=theta*qp[i]+(1-theta)*(node->mup[i]);
  }
  div.gradfstar(x,xp,d);
  divToMu = div.div(x,node->mu,d);
  divToQ = div.div(x,q,d);
  lbnd = divToQ + (1.0/theta -1.0)*(divToMu - node->R);
  if((1.0+eps)*lbnd >= minDistEst)
    return 0;
  if( (fabs(divToMu - node->R)) < node->R*1e-3)
      return 1;
  if(divToMu > node->R)
    return recBinSearch(l,theta,node,q,qp,div,d,minDistEst,eps);
  else{
    if(divToQ*(1.0+eps) < minDistEst){
      return 1;
    }
    return recBinSearch(theta,r,node,q,qp,div,d,minDistEst,eps);
  }
}

variable_types: l double

variable_types: r double

variable_types: struct treenode { double *mu; double *mup; double divToMu; double R; int *inds; int n; int isLeaf; struct treenode *l; struct treenode *r; } *

variable_types:
q
double *

variable_types:
qp
double *

variable_types: struct bregdiv { double (*div)(); void (*divmat)(); void (*gradf)(); void (*gradfstar)(); }

variable_types: minDistEst double

variable_types: eps double

variable_types: theta double

variable_types: divToMu double

variable_types: divToQ double

variable_types: lbnd double

return_type: int


needToSearch

decompiled_code:
__int64 __fastcall needToSearch(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, __int64 a5, __int64 a6, double a7, double a8, double (__fastcall *a9)(__int64, __int64, _QWORD), int a10, int a11, void (__fastcall *a12)(__int64, double *, _QWORD, double, double, double, double, double))
{
double v13; // xmm0_8
__int64 result; // rax

v13 = *(double *)(a1 + 16);
if ( *(double *)(a1 + 24) <= v13 && a7 <= v13 * (a8 + 1.0) )
result = recBinSearch(a1, a2, a3, a4, 0.0, 1.0, a7, a8, a5, a6, a9, a10, a11, a12);
else
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, __int64 a5, __int64 a6, double a7, double a8, double (__fastcall *a9)(__int64, __int64, _QWORD), int a10, int a11, void (__fastcall *a12)(__int64, double *, _QWORD, double, double, double, double, double))
{
double v13; // xmm0_8
__int64 result; // rax

v13 = *(double *)(a1 + 16);
if ( *(double *)(a1 + 24) <= v13 && a7 <= v13 * (a8 + 1.0) )
result = func0(a1, a2, a3, a4, 0.0, 1.0, a7, a8, a5, a6, a9, a10, a11, a12);
else
result = 1LL;
return result;
}

original_code:
int needToSearch(treenode *node,double* q,double* qp,bregdiv div, int d, double minDistEst,double eps){
    if( ((node->divToMu) < (node->R)) || ((node->divToMu)*(1.0+eps) < (minDistEst)))
      return 1;
    return recBinSearch(0.0,1.0,node,q,qp,div,d,minDistEst,eps);
}

canonical_original_code:
int needToSearch(struct treenode *node, double *q, double *qp, struct bregdiv div, int d, double minDistEst, double eps){
    if( ((node->divToMu) < (node->R)) || ((node->divToMu)*(1.0+eps) < (minDistEst)))
      return 1;
    return recBinSearch(0.0,1.0,node,q,qp,div,d,minDistEst,eps);
}

variable_types: d int

user_defined_types: struct bregdiv { double (*div)(); void (*divmat)(); void (*gradf)(); void (*gradfstar)(); }

user_defined_types: struct treenode { double *mu; double *mup; double divToMu; double R; int *inds; int n; int isLeaf; struct treenode *l; struct treenode *r; }


rsearch

original_code:
void rsearch(treenode *node, double *q, double *qp, double**data, bregdiv div, int d, double eps, int k){
  double divTemp;
  int i;
  if(node->isLeaf){
    distCount+=node->n;
    for(i=0;i<(node->n);i++){
      divTemp = div.div(data[node->inds[i]],q,d);
      if (NNs[0]==-1 || divTemp< dtoNNs[0]){
 insert(NNs,dtoNNs,node->inds[i],divTemp,k);
      }
    }
    return;
  }
  distCount+=2;
  node->l->divToMu = div.div(q,node->l->mu,d);
  node->r->divToMu = div.div(q,node->r->mu,d);
  if(node->l->divToMu < node->r->divToMu){
    rsearch(node->l,q,qp,data,div,d,eps,k);
    if(needToSearch(node->r,q,qp,div,d,dtoNNs[0],eps))
      rsearch(node->r,q,qp,data,div,d,eps,k);
  }
  else{
    rsearch(node->r,q,qp,data,div,d,eps,k);
    if(needToSearch(node->l,q,qp,div,d,dtoNNs[0],eps))
      rsearch(node->l,q,qp,data,div,d,eps,k);
  }
}

canonical_original_code:
void rsearch(struct treenode *node, double *q, double *qp, double **data, struct bregdiv div, int d, double eps, int k){
  double divTemp;
  int i;
  if(node->isLeaf){
    distCount+=node->n;
    for(i=0;i<(node->n);i++){
      divTemp = div.div(data[node->inds[i]],q,d);
      if (NNs[0]==-1 || divTemp< dtoNNs[0]){
 insert(NNs,dtoNNs,node->inds[i],divTemp,k);
      }
    }
    return;
  }
  distCount+=2;
  node->l->divToMu = div.div(q,node->l->mu,d);
  node->r->divToMu = div.div(q,node->r->mu,d);
  if(node->l->divToMu < node->r->divToMu){
    rsearch(node->l,q,qp,data,div,d,eps,k);
    if(needToSearch(node->r,q,qp,div,d,dtoNNs[0],eps))
      rsearch(node->r,q,qp,data,div,d,eps,k);
  }
  else{
    rsearch(node->r,q,qp,data,div,d,eps,k);
    if(needToSearch(node->l,q,qp,div,d,dtoNNs[0],eps))
      rsearch(node->l,q,qp,data,div,d,eps,k);
  }
}

variable_types:
data
double **

variable_types: k int

variable_types: divTemp double

variable_types: i int


multisearch

decompiled_code:
void __fastcall multisearch(__int64 a1, __int64 *a2, __int64 a3, double a4, __int64 a5, signed int a6, int a7, double (__fastcall *a8)(__int64, __int64, _QWORD), __int64 a9, void (__fastcall *a10)(void *, __int64, _QWORD, _QWORD, void *, double, double), void (__fastcall *a11)(__int64, double *, _QWORD, double, double, double, double, double), signed int a12, int a13)
{
__int64 *v13; // r15
size_t v15; // rbp
void *v17; // rbp
void *v18; // rax
void *v19; // r8
double v20; // xmm1_8
double *v21; // rcx
_DWORD *v22; // rdx
__int64 v23; // rax
__int64 v24; // rsi
double v25; // [rsp+10h] [rbp-58h]
void *ptra; // [rsp+20h] [rbp-48h]
__int64 *ptr; // [rsp+20h] [rbp-48h]

v13 = a2;
v15 = a6;
v25 = a4;
x = (__int64)calloc(a6, 8uLL);
ptra = (void *)x;
xp = calloc(v15, 8uLL);
v17 = calloc(v15, 8uLL);
dtoNNs = calloc(a12, 8uLL);
v18 = calloc(a12, 4uLL);
v19 = ptra;
distCount = 0LL;
NNs = v18;
if ( a7 > 0 )
{
v20 = *(double *)&LC5;
ptr = &a2[(unsigned int)(a7 - 1) + 1];
do
{
v21 = (double *)dtoNNs;
v22 = NNs;
leafBound = a13;
v23 = 0LL;
if ( a12 > 0 )
{
do
{
v21[v23] = v20;
v22[v23++] = -1;
}
while ( a12 != v23 );
}
v24 = *v13++;
a10(v17, v24, (unsigned int)a6, a10, v19, a4, v20);
a4 = v25;
rsearch(a1, *(v13 - 1), (__int64)v17, a3, a6, a12, v25, a8, a9, (__int64)a10, a11);
v20 = *(double *)&LC5;
}
while ( ptr != v13 );
v19 = (void *)x;
}
free(v19);
free(xp);
free(v17);
free(NNs);
free(dtoNNs);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 *a2, __int64 a3, double a4, __int64 a5, signed int a6, int a7, double (__fastcall *a8)(__int64, __int64, _QWORD), __int64 a9, void (__fastcall *a10)(void *, __int64, _QWORD, _QWORD, void *, double, double), void (__fastcall *a11)(__int64, double *, _QWORD, double, double, double, double, double), signed int a12, int a13)
{
__int64 *v13; // r15
size_t v15; // rbp
void *v17; // rbp
void *v18; // rax
void *v19; // r8
double v20; // xmm1_8
double *v21; // rcx
_DWORD *v22; // rdx
__int64 v23; // rax
__int64 v24; // rsi
double v25; // [rsp+10h] [rbp-58h]
void *ptra; // [rsp+20h] [rbp-48h]
__int64 *ptr; // [rsp+20h] [rbp-48h]

v13 = a2;
v15 = a6;
v25 = a4;
x = (__int64)calloc(a6, 8uLL);
ptra = (void *)x;
xp = calloc(v15, 8uLL);
v17 = calloc(v15, 8uLL);
dtoNNs = calloc(a12, 8uLL);
v18 = calloc(a12, 4uLL);
v19 = ptra;
distCount = 0LL;
NNs = v18;
if ( a7 > 0 )
{
v20 = *(double *)&LC5;
ptr = &a2[(unsigned int)(a7 - 1) + 1];
do
{
v21 = (double *)dtoNNs;
v22 = NNs;
leafBound = a13;
v23 = 0LL;
if ( a12 > 0 )
{
do
{
v21[v23] = v20;
v22[v23++] = -1;
}
while ( a12 != v23 );
}
v24 = *v13++;
a10(v17, v24, (unsigned int)a6, a10, v19, a4, v20);
a4 = v25;
func2(a1, *(v13 - 1), (__int64)v17, a3, a6, a12, v25, a8, a9, (__int64)a10, a11);
v20 = *(double *)&LC5;
}
while ( ptr != v13 );
v19 = (void *)x;
}
free(v19);
free(xp);
free(v17);
free(NNs);
free(dtoNNs);
}

original_code:
void multisearch(treenode* root, double **Q, double**data, bregdiv div, int n, int d, int m, double eps, int k, int maxLeaves){
  int i,j;
  double* qp;
  x = calloc(d,sizeof(double));
  xp = calloc(d,sizeof(double));
  qp = calloc(d,sizeof(double));
  dtoNNs = calloc(k,sizeof(double));
  NNs = calloc(k,sizeof(int));
  distCount=0;
  for(i=0;i<m;i++){
    leafBound = maxLeaves;
    for(j=0;j<k;j++){
      dtoNNs[j]=(__builtin_huge_val ());
      NNs[j]=-1;
    }
    div.gradf(qp,Q[i],d);
    rsearch(root,Q[i],qp,data,div,d,eps,k);
  }
  free(x);
  free(xp);
  free(qp);
  free(NNs);
  free(dtoNNs);
}

canonical_original_code:
void multisearch(struct treenode *root, double **Q, double **data, struct bregdiv div, int n, int d, int m, double eps, int k, int maxLeaves){
  int i; int j;
  double *qp;
  x = calloc(d,sizeof(double));
  xp = calloc(d,sizeof(double));
  qp = calloc(d,sizeof(double));
  dtoNNs = calloc(k,sizeof(double));
  NNs = calloc(k,sizeof(int));
  distCount=0;
  for(i=0;i<m;i++){
    leafBound = maxLeaves;
    for(j=0;j<k;j++){
      dtoNNs[j]=(__builtin_huge_val ());
      NNs[j]=-1;
    }
    div.gradf(qp,Q[i],d);
    rsearch(root,Q[i],qp,data,div,d,eps,k);
  }
  free(x);
  free(xp);
  free(qp);
  free(NNs);
  free(dtoNNs);
}

variable_types:
Q
double **

variable_types: n int

variable_types: m int

variable_types: maxLeaves int

variable_types: j int


compInds

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

v2 = *(double *)a1 - *(double *)a2;
result = 0xFFFFFFFFLL;
if ( v2 >= 0.0 )
result = v2 != 0.0;
return result;
}

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

v2 = *(double *)a1 - *(double *)a2;
result = 0xFFFFFFFFLL;
if ( v2 >= 0.0 )
result = v2 != 0.0;
return result;
}

original_code:
int compInds(const void *a, const void *b){
  double diff = (double)( (*((sortitem*)a)).val - (*((sortitem*)b)).val );
  if(diff<0)
    return -1;
  else if(diff==0)
    return 0;
  else
    return 1;
}

canonical_original_code:
int compInds(void *a, void *b){
  double diff = (double)( (*((sortitem*)a)).val - (*((sortitem*)b)).val );
  if(diff<0)
    return -1;
  else if(diff==0)
    return 0;
  else
    return 1;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: diff double


mean

original_code:
void mean(double* mu,double** data,int* inds, int n, int d){
  int i,j;
  for(i=0;i<d;i++){
    for(j=0;j<n;j++){
      mu[i]+=data[inds[j]][i];
    }
    mu[i]/=((double)n);
  }
}

canonical_original_code:
void mean(double *mu, double **data, int *inds, int n, int d){
  int i; int j;
  for(i=0;i<d;i++){
    for(j=0;j<n;j++){
      mu[i]+=data[inds[j]][i];
    }
    mu[i]/=((double)n);
  }
}

variable_types:
mu
double *

variable_types:
inds
int *


genRand

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

do
result = (unsigned int)(rand() / (int)(0x80000000 / a1));
while ( a1 <= (int)result );
return result;
}

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

do
result = (unsigned int)(rand() / (int)(0x80000000 / a1));
while ( a1 <= (int)result );
return result;
}

original_code:
int genRand(int n){
  int val;
  while(n<= (val= rand()/(int)(((unsigned)2147483647 + 1) / n)));
  return val;
}

canonical_original_code:
int genRand(int n){
  int val;
  while(n<= (val= rand()/(int)(((unsigned int)2147483647 + 1) / n)));
  return val;
}

variable_types: val int


sortWithInds

original_code:
void sortWithInds(double* a, int* inds, int length){
  int i;
  sortitem *s;
  s = calloc(length,sizeof(sortitem));
  for(i=0;i<length;i++){
    s[i].val = a[i];
    s[i].ind = inds[i];
  }
  qsort(s,length,sizeof(sortitem),compInds);
  for(i=0;i<length;i++){
    inds[i]=s[i].ind;
    a[i]=s[i].val;
  }
  free(s);
}

canonical_original_code:
void sortWithInds(double *a, int *inds, int length){
  int i;
  struct sortitem *s;
  s = calloc(length,sizeof(sortitem));
  for(i=0;i<length;i++){
    s[i].val = a[i];
    s[i].ind = inds[i];
  }
  qsort(s,length,sizeof(sortitem),compInds);
  for(i=0;i<length;i++){
    inds[i]=s[i].ind;
    a[i]=s[i].val;
  }
  free(s);
}

variable_types:
a
double *

variable_types: length int

variable_types: struct sortitem { double val; int ind; } *


insert

decompiled_code:
double *__fastcall insert(_DWORD *a1, double *a2, int a3, int a4, double a5)
{
double *result; // rax
_DWORD *v8; // rcx
double *v9; // rdx
__int64 v10; // r8
int v11; // esi
double v12; // xmm0_8

result = (double *)(unsigned int)a4;
if ( a4 > 1 )
{
v8 = a1;
v9 = a2;
v10 = (__int64)&a1[(_DWORD)result - 2 + 1];
while ( 1 )
{
result = v9++;
a1 = v8;
v12 = result[1];
a2 = result;
if ( v12 <= a5 )
break;
v11 = v8[1];
++v8;
*a1 = v11;
*result = v12;
if ( a1 + 1 == (_DWORD *)v10 )
{
*v8 = a3;
*v9 = a5;
return result;
}
}
}
*a1 = a3;
*a2 = a5;
return result;
}

canonical_decompiled_code:
double *__fastcall func10(_DWORD *a1, double *a2, int a3, int a4, double a5)
{
double *result; // rax
_DWORD *v8; // rcx
double *v9; // rdx
__int64 v10; // r8
int v11; // esi
double v12; // xmm0_8

result = (double *)(unsigned int)a4;
if ( a4 > 1 )
{
v8 = a1;
v9 = a2;
v10 = (__int64)&a1[(_DWORD)result - 2 + 1];
while ( 1 )
{
result = v9++;
a1 = v8;
v12 = result[1];
a2 = result;
if ( v12 <= a5 )
break;
v11 = v8[1];
++v8;
*a1 = v11;
*result = v12;
if ( a1 + 1 == (_DWORD *)v10 )
{
*v8 = a3;
*v9 = a5;
return result;
}
}
}
*a1 = a3;
*a2 = a5;
return result;
}

original_code:
void insert(int* NNs, double* dtoNNs, int newNN, double dNNnew, int k){
  int i=0;
  while (i < (k-1) && dtoNNs[i+1]>dNNnew){
    NNs[i]=NNs[i+1];
    dtoNNs[i]=dtoNNs[i+1];
    i++;
  }
  NNs[i]=newNN;
  dtoNNs[i]=dNNnew;
}

canonical_original_code:
void insert(int *NNs, double *dtoNNs, int newNN, double dNNnew, int k){
  int i = 0;
  while (i < (k-1) && dtoNNs[i+1]>dNNnew){
    NNs[i]=NNs[i+1];
    dtoNNs[i]=dtoNNs[i+1];
    i++;
  }
  NNs[i]=newNN;
  dtoNNs[i]=dNNnew;
}

variable_types:
NNs
int *

variable_types:
dtoNNs
double *

variable_types: newNN int

variable_types: dNNnew double

variable_types: k int


contarCruzD

repo: lccrubik/doc

variable_types: struct cubo { int F[9]; int B[9]; int U[9]; int D[9]; int R[9]; int L[9]; } *

variable_types: i int


decompiled_code:
_BOOL8 __fastcall cruz2D(_DWORD *a1)
{
return (int)contarCruzD(a1) > 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_DWORD *a1)
{
return (int)func0(a1) > 1;
}

original_code: int cruz2D(cubo *C) { return contarCruzD(C) >= 2; }

canonical_original_code: int cruz2D(struct cubo *C) { return contarCruzD(C) >= 2; }

user_defined_types: struct cubo { int F[9]; int B[9]; int U[9]; int D[9]; int R[9]; int L[9]; }


decompiled_code:
_BOOL8 __fastcall cruz3D(_DWORD *a1)
{
return (int)contarCruzD(a1) > 2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_DWORD *a1)
{
return (int)func0(a1) > 2;
}

original_code: int cruz3D(cubo *C) { return contarCruzD(C) >= 3; }

canonical_original_code: int cruz3D(struct cubo *C) { return contarCruzD(C) >= 3; }


decompiled_code:
_BOOL8 __fastcall cruz4D(_DWORD *a1)
{
return (int)contarCruzD(a1) > 3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_DWORD *a1)
{
return (int)func0(a1) > 3;
}

original_code: int cruz4D(cubo *C) { return contarCruzD(C) >= 4; }

canonical_original_code: int cruz4D(struct cubo *C) { return contarCruzD(C) >= 4; }


decompiled_code:
_BOOL8 __fastcall esqD1(_DWORD *a1)
{
return (int)contarEsqD(a1) > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_DWORD *a1)
{
return (int)func4(a1) > 0;
}

original_code: int esqD1(cubo *C) { return contarEsqD(C) >= 1; }

canonical_original_code: int esqD1(struct cubo *C) { return contarEsqD(C) >= 1; }


decompiled_code:
_BOOL8 __fastcall esqD2(_DWORD *a1)
{
return (int)contarEsqD(a1) > 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(_DWORD *a1)
{
return (int)func4(a1) > 1;
}

original_code: int esqD2(cubo *C) { return contarEsqD(C) >= 2; }

canonical_original_code: int esqD2(struct cubo *C) { return contarEsqD(C) >= 2; }


decompiled_code:
_BOOL8 __fastcall esqD3(_DWORD *a1)
{
return (int)contarEsqD(a1) > 2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_DWORD *a1)
{
return (int)func4(a1) > 2;
}

original_code: int esqD3(cubo *C) { return contarEsqD(C) >= 3; }

canonical_original_code: int esqD3(struct cubo *C) { return contarEsqD(C) >= 3; }


decompiled_code:
_BOOL8 __fastcall esqD4(_DWORD *a1)
{
return (int)contarEsqD(a1) > 3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(_DWORD *a1)
{
return (int)func4(a1) > 3;
}

original_code: int esqD4(cubo *C) { return contarEsqD(C) >= 4; }

canonical_original_code: int esqD4(struct cubo *C) { return contarEsqD(C) >= 4; }


contarBordes

decompiled_code:
__int64 __fastcall contarBordes(_DWORD *a1)
{
__int64 result; // rax
int v2; // edx
int v3; // ecx
int v4; // esi
int v5; // ecx

result = esqD4(a1);
if ( !(_DWORD)result )
return result;
v2 = a1[4];
v3 = a1[40];
result = 0LL;
if ( a1[5] != v2 )
{
v4 = a1[13];
if ( a1[41] != v3 )
goto LABEL_4;
LABEL_10:
result = (a1[12] == v4) + (unsigned int)result;
v5 = a1[49];
if ( a1[14] != v4 )
{
LABEL_5:
if ( a1[50] != v5 )
return result;
return (v2 == a1[3]) + (unsigned int)result;
}
goto LABEL_8;
}
v4 = a1[13];
result = a1[39] == v3;
if ( a1[41] == v3 )
goto LABEL_10;
LABEL_4:
v5 = a1[49];
if ( a1[14] != v4 )
goto LABEL_5;
LABEL_8:
result = (a1[48] == v5) + (unsigned int)result;
if ( a1[50] == v5 )
return (v2 == a1[3]) + (unsigned int)result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1)
{
__int64 result; // rax
int v2; // edx
int v3; // ecx
int v4; // esi
int v5; // ecx

result = func8(a1);
if ( !(_DWORD)result )
return result;
v2 = a1[4];
v3 = a1[40];
result = 0LL;
if ( a1[5] != v2 )
{
v4 = a1[13];
if ( a1[41] != v3 )
goto LABEL_4;
LABEL_10:
result = (a1[12] == v4) + (unsigned int)result;
v5 = a1[49];
if ( a1[14] != v4 )
{
LABEL_5:
if ( a1[50] != v5 )
return result;
return (v2 == a1[3]) + (unsigned int)result;
}
goto LABEL_8;
}
v4 = a1[13];
result = a1[39] == v3;
if ( a1[41] == v3 )
goto LABEL_10;
LABEL_4:
v5 = a1[49];
if ( a1[14] != v4 )
goto LABEL_5;
LABEL_8:
result = (a1[48] == v5) + (unsigned int)result;
if ( a1[50] == v5 )
return (v2 == a1[3]) + (unsigned int)result;
return result;
}


decompiled_code:
_BOOL8 __fastcall bordesUD1(_DWORD *a1)
{
return (int)contarBordes(a1) > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(_DWORD *a1)
{
return (int)func9(a1) > 0;
}

original_code: int bordesUD1(cubo *C) { return contarBordes(C) >= 1; }

canonical_original_code: int bordesUD1(struct cubo *C) { return contarBordes(C) >= 1; }


decompiled_code:
_BOOL8 __fastcall bordesUD2(_DWORD *a1)
{
return (int)contarBordes(a1) > 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(_DWORD *a1)
{
return (int)func9(a1) > 1;
}

original_code: int bordesUD2(cubo *C) { return contarBordes(C) >= 2; }

canonical_original_code: int bordesUD2(struct cubo *C) { return contarBordes(C) >= 2; }


decompiled_code:
_BOOL8 __fastcall bordesUD3(_DWORD *a1)
{
return (int)contarBordes(a1) > 2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(_DWORD *a1)
{
return (int)func9(a1) > 2;
}

original_code: int bordesUD3(cubo *C) { return contarBordes(C) >= 3; }

canonical_original_code: int bordesUD3(struct cubo *C) { return contarBordes(C) >= 3; }


decompiled_code:
_BOOL8 __fastcall bordesUD4(_DWORD *a1)
{
return (int)contarBordes(a1) > 3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(_DWORD *a1)
{
return (int)func9(a1) > 3;
}

original_code: int bordesUD4(cubo *C) { return contarBordes(C) >= 4; }

canonical_original_code: int bordesUD4(struct cubo *C) { return contarBordes(C) >= 4; }


reemplazar

original_code:
static int reemplazar(char* orig, char* a, char* b)
{
 int j,k;
 int R = 0;
 char* dest = orig;
 while(*orig != 0)
 {
  j = 0;
  while(orig[j] != 0 && a[j] != 0 && orig[j] == a[j]) j++;
  if(a[j] == 0)
  {
   R = 1;
   for(k=0;b[k]!=0;++k)
    dest[k] = b[k];
   dest+=k;
   orig+=j;
  } else
   *dest++ = *orig++;
 }
 *dest = 0;
 return R; }

canonical_original_code:
static int reemplazar(char *orig, char *a, char *b)
{
 int j; int k;
 int R = 0;
 char *dest = orig;
 while(*orig != 0)
 {
  j = 0;
  while(orig[j] != 0 && a[j] != 0 && orig[j] == a[j]) j++;
  if(a[j] == 0)
  {
   R = 1;
   for(k=0;b[k]!=0;++k)
    dest[k] = b[k];
   dest+=k;
   orig+=j;
  } else
   *dest++ = *orig++;
 }
 *dest = 0;
 return R; }

variable_types:
orig
char *

variable_types:
a
char *

variable_types:
b
char *

variable_types: j int

variable_types: R int

variable_types:
dest
char *


simplificar

decompiled_code:
__int64 __fastcall simplificar(_BYTE *a1)
{
void **v1; // rbx
void *v2; // rsi
char *v3; // rdx
int v4; // ebp
__int64 result; // rax

do
{
v1 = &off_1F0;
v2 = &unk_101;
v3 = (char *)&unk_104;
v4 = 0;
while ( 1 )
{
result = reemplazar(a1, (__int64)v2, v3);
v4 += result;
if ( v1 == (void **)&unk_480 )
break;
v3 = (char *)v1[1];
v2 = *v1;
v1 += 2;
}
}
while ( v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
void **v1; // rbx
void *v2; // rsi
char *v3; // rdx
int v4; // ebp
__int64 result; // rax

do
{
v1 = &off_1F0;
v2 = &unk_101;
v3 = (char *)&unk_104;
v4 = 0;
while ( 1 )
{
result = func0(a1, (__int64)v2, v3);
v4 += result;
if ( v1 == (void **)&unk_480 )
break;
v3 = (char *)v1[1];
v2 = *v1;
v1 += 2;
}
}
while ( v4 );
return result;
}

original_code:
void simplificar(char* str)
{
 unsigned int i;
 int R = 1;
 while(R != 0)
 {
  R = 0;
  for(i=0;i<sizeof(tabla)/sizeof(char*);i+=2)
   R += reemplazar(str,tabla[i],tabla[i+1]);
 }
}

canonical_original_code:
void simplificar(char *str)
{
 unsigned int i;
 int R = 1;
 while(R != 0)
 {
  R = 0;
  for(i=0;i<sizeof(tabla)/sizeof(char *);i+=2)
   R += reemplazar(str,tabla[i],tabla[i+1]);
 }
}

variable_types:
str
char *

variable_types:
i
unsigned int


reload

repo: lcrocker/ojcardlib

decompiled_code:
__int64 reload()
{
char *v0; // r10
__int64 v1; // r9
__int64 result; // rax
unsigned int v3; // edi
unsigned int v4; // ebx
unsigned int v5; // ecx
unsigned int v6; // er11
unsigned int v7; // esi
unsigned __int64 v8; // rax
unsigned __int64 v9; // r12
__int64 v10; // rdx

if ( !seeded )
_assert_fail("_seeded", "/usr/src/repo/source/library/prng.c", 0x6Fu, "reload");
v0 = (char *)˚
v1 = x;
result = y;
v3 = z1;
v4 = c1;
v5 = z2;
v6 = c2;
do
{
v0 += 8;
v7 = -382903 * v3 + v4;
v8 = result ^ (result << 21) ^ ((result ^ (unsigned __int64)(result << 21)) >> 17);
v1 = 0x14ADA13ED78492ADLL * v1 + 123456789;
v9 = (4294584393LL * v3 + (unsigned __int64)v4) >> 32;
v3 = v7;
v4 = v9;
result = (v8 << 30) ^ v8;
v10 = 4246477509LL * v5 + v6;
v5 = -48489787 * v5 + v6;
v6 = HIDWORD(v10);
*((_QWORD *)v0 - 1) = result + v1 + v7 + (v10 << 32);
}
while ( (char *)&ring + 2048 != v0 );
c1 = v9;
c2 = HIDWORD(v10);
rptr = (__int64)&ring + 2048;
x = v1;
y = result;
z1 = v7;
z2 = v10;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
char *v0; // r10
__int64 v1; // r9
__int64 result; // rax
unsigned int v3; // edi
unsigned int v4; // ebx
unsigned int v5; // ecx
unsigned int v6; // er11
unsigned int v7; // esi
unsigned __int64 v8; // rax
unsigned __int64 v9; // r12
__int64 v10; // rdx

if ( !seeded )
_assert_fail("_seeded", "/usr/src/repo/source/library/prng.c", 0x6Fu, "reload");
v0 = (char *)˚
v1 = x;
result = y;
v3 = z1;
v4 = c1;
v5 = z2;
v6 = c2;
do
{
v0 += 8;
v7 = -382903 * v3 + v4;
v8 = result ^ (result << 21) ^ ((result ^ (unsigned __int64)(result << 21)) >> 17);
v1 = 0x14ADA13ED78492ADLL * v1 + 123456789;
v9 = (4294584393LL * v3 + (unsigned __int64)v4) >> 32;
v3 = v7;
v4 = v9;
result = (v8 << 30) ^ v8;
v10 = 4246477509LL * v5 + v6;
v5 = -48489787 * v5 + v6;
v6 = HIDWORD(v10);
*((_QWORD *)v0 - 1) = result + v1 + v7 + (v10 << 32);
}
while ( (char *)&ring + 2048 != v0 );
c1 = v9;
c2 = HIDWORD(v10);
rptr = (__int64)&ring + 2048;
x = v1;
y = result;
z1 = v7;
z2 = v10;
return result;
}

variable_types:
t
unsigned long


decompiled_code:
__int64 __fastcall ojr_seed(int a1)
{
__int64 result; // rax
int v2; // eax
int v3; // ebp
__int64 v4; // rax
time_t timer; // [rsp+0h] [rbp-30h] BYREF
__int64 buf; // [rsp+8h] [rbp-28h] BYREF
__int64 v7; // [rsp+10h] [rbp-20h]
int v8; // [rsp+18h] [rbp-18h]
int v9; // [rsp+1Ch] [rbp-14h]
int v10; // [rsp+20h] [rbp-10h]
int v11; // [rsp+24h] [rbp-Ch]

z1 = 43219876;
rptr = (__int64)˚
x = 0x1CBE991A83LL;
y = 0xE5F4C8F743LL;
c1 = 6543217;
z2 = 21987643;
c2 = 1732654;
seeded = 0;
if ( a1 )
{
seeded = 1;
result = 0LL;
y = a1 & 0xA5A5A5A5 ^ 0xE5F4C8F743LL;
x = a1 & 0x5A5A5A5A ^ 0x1CBE991A83LL;
}
else
{
v2 = open("/dev/urandom", 0);
v3 = v2;
if ( v2 != -1 )
{
if ( read(v2, &buf, 0x20uLL) == 32 )
seeded = 1;
close(v3);
}
if ( seeded )
{
x = buf;
v4 = v7;
if ( !v7 )
v4 = 0xE5F4C8F743LL;
y = v4;
z1 = v8;
c1 = v9 | 0x10000000;
z2 = v10;
c2 = v11 | 0x20000000;
result = 0LL;
}
else
{
time(&timer);
seeded = 1;
y ^= timer & 0x5A5A5A5A;
result = 0LL;
x = (unsigned int)timer & 0xA5A5A5A5 ^ (unsigned __int64)x;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 result; // rax
int v2; // eax
int v3; // ebp
__int64 v4; // rax
time_t timer; // [rsp+0h] [rbp-30h] BYREF
__int64 buf; // [rsp+8h] [rbp-28h] BYREF
__int64 v7; // [rsp+10h] [rbp-20h]
int v8; // [rsp+18h] [rbp-18h]
int v9; // [rsp+1Ch] [rbp-14h]
int v10; // [rsp+20h] [rbp-10h]
int v11; // [rsp+24h] [rbp-Ch]

z1 = 43219876;
rptr = (__int64)˚
x = 0x1CBE991A83LL;
y = 0xE5F4C8F743LL;
c1 = 6543217;
z2 = 21987643;
c2 = 1732654;
seeded = 0;
if ( a1 )
{
seeded = 1;
result = 0LL;
y = a1 & 0xA5A5A5A5 ^ 0xE5F4C8F743LL;
x = a1 & 0x5A5A5A5A ^ 0x1CBE991A83LL;
}
else
{
v2 = open("/dev/urandom", 0);
v3 = v2;
if ( v2 != -1 )
{
if ( read(v2, &buf, 0x20uLL) == 32 )
seeded = 1;
close(v3);
}
if ( seeded )
{
x = buf;
v4 = v7;
if ( !v7 )
v4 = 0xE5F4C8F743LL;
y = v4;
z1 = v8;
c1 = v9 | 0x10000000;
z2 = v10;
c2 = v11 | 0x20000000;
result = 0LL;
}
else
{
time(&timer);
seeded = 1;
y ^= timer & 0x5A5A5A5A;
result = 0LL;
x = (unsigned int)timer & 0xA5A5A5A5 ^ (unsigned __int64)x;
}
}
return result;
}

variable_types: seed int

variable_types:
s
unsigned int [8]

variable_types: t long

variable_types: fn int


decompiled_code:
__int64 ojr_next16()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 result; // rax

if ( !seeded )
_assert_fail("_seeded", "/usr/src/repo/source/library/prng.c", 0x86u, "ojr_next16");
v0 = rptr;
if ( (_UNKNOWN *)rptr == &ring )
{
reload();
v0 = rptr;
}
v1 = v0 - 2;
result = *(unsigned __int16 *)(v0 - 2);
rptr = v1;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 result; // rax

if ( !seeded )
_assert_fail("_seeded", "/usr/src/repo/source/library/prng.c", 0x86u, "ojr_next16");
v0 = rptr;
if ( (_UNKNOWN *)rptr == &ring )
{
func0();
v0 = rptr;
}
v1 = v0 - 2;
result = *(unsigned __int16 *)(v0 - 2);
rptr = v1;
return result;
}

original_code:
uint16_t ojr_next16(void) {
    ((_seeded) ? (void) (0) : __assert_fail ("_seeded", "/usr/src/repo/source/library/prng.c", 134, __extension__ __PRETTY_FUNCTION__));
    if (rptr == ring) reload();
    return *--rptr;
}

canonical_original_code:
unsigned short ojr_next16() {
    ((_seeded) ? (void) (0) : __assert_fail ("_seeded", "/usr/src/repo/source/library/prng.c", 134, __extension__ __PRETTY_FUNCTION__));
    if (rptr == ring) reload();
    return *--rptr;
}

return_type: unsigned short


decompiled_code:
__int64 ojr_next32()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 result; // rax

if ( !seeded )
_assert_fail("_seeded", "/usr/src/repo/source/library/prng.c", 0x8Cu, "ojr_next32");
v0 = rptr;
if ( rptr < (unsigned __int64)&unk_564 )
{
reload();
v0 = rptr;
}
v1 = v0 - 4;
result = *(unsigned int *)(v0 - 4);
rptr = v1;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 result; // rax

if ( !seeded )
_assert_fail("_seeded", "/usr/src/repo/source/library/prng.c", 0x8Cu, "ojr_next32");
v0 = rptr;
if ( rptr < (unsigned __int64)&unk_564 )
{
func0();
v0 = rptr;
}
v1 = v0 - 4;
result = *(unsigned int *)(v0 - 4);
rptr = v1;
return result;
}

original_code:
uint32_t ojr_next32(void) {
    ((_seeded) ? (void) (0) : __assert_fail ("_seeded", "/usr/src/repo/source/library/prng.c", 140, __extension__ __PRETTY_FUNCTION__));
    if (rptr < (ring + 2)) reload();
    rptr -= 2;
    return *((uint32_t *)rptr);
}

canonical_original_code:
unsigned int ojr_next32() {
    ((_seeded) ? (void) (0) : __assert_fail ("_seeded", "/usr/src/repo/source/library/prng.c", 140, __extension__ __PRETTY_FUNCTION__));
    if (rptr < (ring + 2)) reload();
    rptr -= 2;
    return *((unsigned int *)rptr);
}

return_type: unsigned int


decompiled_code:
__int64 ojr_next64()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 result; // rax

if ( !seeded )
_assert_fail("_seeded", "/usr/src/repo/source/library/prng.c", 0x93u, "ojr_next64");
v0 = rptr;
if ( rptr < (unsigned __int64)&unk_568 )
{
reload();
v0 = rptr;
}
v1 = v0 - 8;
result = *(_QWORD *)(v0 - 8);
rptr = v1;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 result; // rax

if ( !seeded )
_assert_fail("_seeded", "/usr/src/repo/source/library/prng.c", 0x93u, "ojr_next64");
v0 = rptr;
if ( rptr < (unsigned __int64)&unk_568 )
{
func0();
v0 = rptr;
}
v1 = v0 - 8;
result = *(_QWORD *)(v0 - 8);
rptr = v1;
return result;
}

original_code:
uint64_t ojr_next64(void) {
    ((_seeded) ? (void) (0) : __assert_fail ("_seeded", "/usr/src/repo/source/library/prng.c", 147, __extension__ __PRETTY_FUNCTION__));
    if (rptr < (ring + 4)) reload();
    rptr -= 4;
    return *((uint64_t *)rptr);
}

canonical_original_code:
unsigned long ojr_next64() {
    ((_seeded) ? (void) (0) : __assert_fail ("_seeded", "/usr/src/repo/source/library/prng.c", 147, __extension__ __PRETTY_FUNCTION__));
    if (rptr < (ring + 4)) reload();
    rptr -= 4;
    return *((unsigned long *)rptr);
}

return_type: unsigned long


decompiled_code:
double ojr_next_double()
{
return COERCE_DOUBLE(((unsigned __int64)ojr_next64() >> 12) | 0x3FF0000000000000LL) - 1.0;
}

canonical_decompiled_code:
double func5()
{
return COERCE_DOUBLE(((unsigned __int64)ojr_next64() >> 12) | 0x3FF0000000000000LL) - 1.0;
}

original_code:
double ojr_next_double(void) {
    uint64_t r = ojr_next64();
    ieee.i = (r >> 12) | 0x3FF0000000000000;
    return ieee.d - 1.0;
}

canonical_original_code:
double ojr_next_double() {
    unsigned long r = ojr_next64();
    ieee.i = (r >> 12) | 0x3FF0000000000000;
    return ieee.d - 1.0;
}

variable_types:
r
unsigned long


original_code:
int ojr_rand(int limit) {
    int v, m = limit - 1;
    ((_seeded) ? (void) (0) : __assert_fail ("_seeded", "/usr/src/repo/source/library/prng.c", 169, __extension__ __PRETTY_FUNCTION__));
    ((limit > 0) ? (void) (0) : __assert_fail ("limit > 0", "/usr/src/repo/source/library/prng.c", 170, __extension__ __PRETTY_FUNCTION__));
    ((limit < 65536) ? (void) (0) : __assert_fail ("limit < 65536", "/usr/src/repo/source/library/prng.c", 171, __extension__ __PRETTY_FUNCTION__));
    m |= m >> 1;
    m |= m >> 2;
    m |= m >> 4;
    m |= m >> 8;
    do {
        if (rptr == ring) reload();
        v = m & *--rptr;
    } while (v >= limit);
    return v;
}

canonical_original_code:
int ojr_rand(int limit) {
    int v; int m = limit - 1;
    ((_seeded) ? (void) (0) : __assert_fail ("_seeded", "/usr/src/repo/source/library/prng.c", 169, __extension__ __PRETTY_FUNCTION__));
    ((limit > 0) ? (void) (0) : __assert_fail ("limit > 0", "/usr/src/repo/source/library/prng.c", 170, __extension__ __PRETTY_FUNCTION__));
    ((limit < 65536) ? (void) (0) : __assert_fail ("limit < 65536", "/usr/src/repo/source/library/prng.c", 171, __extension__ __PRETTY_FUNCTION__));
    m |= m >> 1;
    m |= m >> 2;
    m |= m >> 4;
    m |= m >> 8;
    do {
        if (rptr == ring) reload();
        v = m & *--rptr;
    } while (v >= limit);
    return v;
}

variable_types: limit int

variable_types: v int

variable_types: m int


decompiled_code:
__int64 ojd_ntypes()
{
return 7LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 7LL;
}

original_code: int ojd_ntypes(void) { return 7; }

canonical_original_code: int ojd_ntypes() { return 7; }


decompiled_code:
__int64 __fastcall ojd_size(unsigned int a1)
{
return *((_QWORD *)&oj_common_decks + 11 * a1 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return *((_QWORD *)&oj_common_decks + 11 * a1 + 2);
}

original_code: int ojd_size(oj_decktype t) { return _oj_common_decks[t].length; }

canonical_original_code: int ojd_size(enum _oj_decktype t) { return _oj_common_decks[t].length; }

variable_types: enum _oj_decktype { OJD_STANDARD=0, OJD_ONEJOKER=1, OJD_TWOJOKERS=2, OJD_SKAT=3, OJD_PAN=4, OJD_PANJ=5, OJD_PINOCHLE=6 }


decompiled_code:
char *__fastcall ojd_deck(unsigned int a1)
{
return (char *)&oj_common_decks + 88 * a1;
}

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1)
{
return (char *)&oj_common_decks + 88 * a1;
}

original_code: oj_cardlist *ojd_deck(oj_decktype t) { return &_oj_common_decks[t]; }

canonical_original_code: struct _oj_cardlist *ojd_deck(enum _oj_decktype t) { return &_oj_common_decks[t]; }

return_type: struct _oj_cardlist { int _johnnymoss; long allocation; long pflags; unsigned long mask; char *cards; void *filler[4]; } *

user_defined_types: enum _oj_decktype { OJD_STANDARD=0, OJD_ONEJOKER=1, OJD_TWOJOKERS=2, OJD_SKAT=3, OJD_PAN=4, OJD_PANJ=5, OJD_PINOCHLE=6 }


decompiled_code:
__int64 __fastcall ojc_binomial(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rcx
__int64 v5; // rdi
__int64 v6; // rdx

if ( a1 < 0 || a2 < 0 )
_assert_fail("n >= 0 && k >= 0", "/usr/src/repo/source/library/combiner.c", 0x15u, "ojc_binomial");
if ( !a2 || a1 == a2 )
return 1LL;
result = 0LL;
if ( a1 < a2 )
return result;
if ( a1 - a2 <= a2 )
a2 = a1 - a2;
if ( a2 == 1 )
return a1;
if ( a1 <= 54 && a2 <= 54 )
return bctable[(((a1 - 3) * (a1 - 3)) >> 2) + a2];
if ( !a2 )
return 1LL;
v3 = a1 - (a2 - 1);
if ( a1 - (a2 - 1) < 0 )
return -1LL;
v4 = 1LL;
v5 = a1 + 1LL - a2;
while ( 1 )
{
result = v3 / v4;
if ( a2 < (int)v4 + 1 )
break;
v6 = v5 + v4++;
v3 = v6 * result;
if ( v3 < 0 )
return -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rcx
__int64 v5; // rdi
__int64 v6; // rdx

if ( a1 < 0 || a2 < 0 )
_assert_fail("n >= 0 && k >= 0", "/usr/src/repo/source/library/combiner.c", 0x15u, "ojc_binomial");
if ( !a2 || a1 == a2 )
return 1LL;
result = 0LL;
if ( a1 < a2 )
return result;
if ( a1 - a2 <= a2 )
a2 = a1 - a2;
if ( a2 == 1 )
return a1;
if ( a1 <= 54 && a2 <= 54 )
return bctable[(((a1 - 3) * (a1 - 3)) >> 2) + a2];
if ( !a2 )
return 1LL;
v3 = a1 - (a2 - 1);
if ( a1 - (a2 - 1) < 0 )
return -1LL;
v4 = 1LL;
v5 = a1 + 1LL - a2;
while ( 1 )
{
result = v3 / v4;
if ( a2 < (int)v4 + 1 )
break;
v6 = v5 + v4++;
v3 = v6 * result;
if ( v3 < 0 )
return -1LL;
}
return result;
}

original_code:
int64_t ojc_binomial(int n, int k) {
    ((n >= 0 && k >= 0) ? (void) (0) : __assert_fail ("n >= 0 && k >= 0", "/usr/src/repo/source/library/combiner.c", 21, __extension__ __PRETTY_FUNCTION__));
    if (0 == k || n == k) return 1LL;
    if (k > n) return 0LL;
    if (k > (n - k)) k = n - k;
    if (1 == k) return (long long)n;
    if (n <= 54 && k <= 54) {
        return bctable[(((n - 3) * (n - 3)) >> 2) + k];
    }
    int64_t b = 1LL;
    for (int i = 1; i <= k; ++i) {
        b *= (n - (k - i));
        if (b < 0) return -1LL;
        b /= i;
    }
    return b;
}

canonical_original_code:
long ojc_binomial(int n, int k) {
    ((n >= 0 && k >= 0) ? (void) (0) : __assert_fail ("n >= 0 && k >= 0", "/usr/src/repo/source/library/combiner.c", 21, __extension__ __PRETTY_FUNCTION__));
    if (0 == k || n == k) return 1LL;
    if (k > n) return 0LL;
    if (k > (n - k)) k = n - k;
    if (1 == k) return (long long)n;
    if (n <= 54 && k <= 54) {
        return bctable[(((n - 3) * (n - 3)) >> 2) + k];
    }
    long b = 1LL;
    for (int i = 1; i <= k; ++i) {
        b *= (n - (k - i));
        if (b < 0) return -1LL;
        b /= i;
    }
    return b;
}

variable_types: n int

variable_types: k int

variable_types: b long

variable_types: i int

return_type: long


original_code:
int ojc_new(
    oj_combiner *cp,
    oj_cardlist *deck,
    oj_cardlist *hand,
    int k,
    int64_t count)
{
    int i;
    ((0 != cp && 0 != deck && 0 != hand) ? (void) (0) : __assert_fail ("0 != cp && 0 != deck && 0 != hand", "/usr/src/repo/source/library/combiner.c", 52, __extension__ __PRETTY_FUNCTION__));
    ((hand->allocation >= k) ? (void) (0) : __assert_fail ("hand->allocation >= k", "/usr/src/repo/source/library/combiner.c", 53, __extension__ __PRETTY_FUNCTION__));
    ((deck->length >= k && deck->length <= 54) ? (void) (0) : __assert_fail ("deck->length >= k && deck->length <= 54", "/usr/src/repo/source/library/combiner.c", 54, __extension__ __PRETTY_FUNCTION__));
    ((k >= 0 && k <= 54) ? (void) (0) : __assert_fail ("k >= 0 && k <= 54", "/usr/src/repo/source/library/combiner.c", 55, __extension__ __PRETTY_FUNCTION__));
    if (hand->pflags & 1) return (-2);
    if (hand->pflags & 2) return (-4);
    cp->_johnnymoss = 0x10ACE0FF;
    cp->deck = deck;
    cp->hand = hand;
    cp->k = k;
    cp->total = ojc_binomial(deck->length, k);
    if (0 == count) cp->remaining = cp->total;
    else cp->remaining = count;
    hand->length = k;
    for (i = 0; i < k; ++i) hand->cards[i] = deck->cards[i];
    for (i = 0; i < deck->length; ++i) {
        cp->map[i] = cp->invert[deck->cards[i]] = i;
    }
    hand->eflags = 0;
    return 0;
}

canonical_original_code:
int ojc_new(struct _oj_combiner *cp, struct _oj_cardlist *deck, struct _oj_cardlist *hand, int k, long count)
{
    int i;
    ((0 != cp && 0 != deck && 0 != hand) ? (void) (0) : __assert_fail ("0 != cp && 0 != deck && 0 != hand", "/usr/src/repo/source/library/combiner.c", 52, __extension__ __PRETTY_FUNCTION__));
    ((hand->allocation >= k) ? (void) (0) : __assert_fail ("hand->allocation >= k", "/usr/src/repo/source/library/combiner.c", 53, __extension__ __PRETTY_FUNCTION__));
    ((deck->length >= k && deck->length <= 54) ? (void) (0) : __assert_fail ("deck->length >= k && deck->length <= 54", "/usr/src/repo/source/library/combiner.c", 54, __extension__ __PRETTY_FUNCTION__));
    ((k >= 0 && k <= 54) ? (void) (0) : __assert_fail ("k >= 0 && k <= 54", "/usr/src/repo/source/library/combiner.c", 55, __extension__ __PRETTY_FUNCTION__));
    if (hand->pflags & 1) return (-2);
    if (hand->pflags & 2) return (-4);
    cp->_johnnymoss = 0x10ACE0FF;
    cp->deck = deck;
    cp->hand = hand;
    cp->k = k;
    cp->total = ojc_binomial(deck->length, k);
    if (0 == count) cp->remaining = cp->total;
    else cp->remaining = count;
    hand->length = k;
    for (i = 0; i < k; ++i) hand->cards[i] = deck->cards[i];
    for (i = 0; i < deck->length; ++i) {
        cp->map[i] = cp->invert[deck->cards[i]] = i;
    }
    hand->eflags = 0;
    return 0;
}

variable_types: struct _oj_combiner { int _johnnymoss; long k; struct _oj_cardlist { int _johnnymoss; long allocation; long pflags; unsigned long mask; char *cards; void *filler[4]; } *deck; char map[56]; long total; void *filler[4]; } *

variable_types:
deck
struct _oj_cardlist *

variable_types:
hand
struct _oj_cardlist *

variable_types: count long

user_defined_types: struct _oj_combiner { int _johnnymoss; long k; struct _oj_cardlist *deck; char map[56]; long total; void *filler[4]; }


original_code:
int ojc_next(oj_combiner *cp) {
    int i, j, k = cp->k, n = cp->deck->length;
    oj_card *a = cp->map;
    ((0 != cp && 0x10ACE0FF == cp->_johnnymoss) ? (void) (0) : __assert_fail ("0 != cp && 0x10ACE0FF == cp->_johnnymoss", "/usr/src/repo/source/library/combiner.c", 83, __extension__ __PRETTY_FUNCTION__));
    if (0 == cp->remaining) return 0;
    if (cp->remaining != cp->total) {
        for (i = 0; i < k-1; ++i) {
            if (a[i] < a[i+1] - 1) break;
        }
        ((! ((i == k-1) && (a[i] == n-1))) ? (void) (0) : __assert_fail ("! ((i == k-1) && (a[i] == n-1))", "/usr/src/repo/source/library/combiner.c", 91, __extension__ __PRETTY_FUNCTION__));
        ++a[i];
        for (j = 0; j < i; ++j) a[j] = j;
    }
    for (int c = 0; c < k; ++c) {
        cp->hand->cards[c] = cp->deck->cards[a[c]];
    }
    --cp->remaining;
    cp->hand->eflags = 0;
    return 1;
}

canonical_original_code:
int ojc_next(struct _oj_combiner *cp) {
    int i; int j; int k = cp->k; int n = cp->deck->length;
    char *a = cp->map;
    ((0 != cp && 0x10ACE0FF == cp->_johnnymoss) ? (void) (0) : __assert_fail ("0 != cp && 0x10ACE0FF == cp->_johnnymoss", "/usr/src/repo/source/library/combiner.c", 83, __extension__ __PRETTY_FUNCTION__));
    if (0 == cp->remaining) return 0;
    if (cp->remaining != cp->total) {
        for (i = 0; i < k-1; ++i) {
            if (a[i] < a[i+1] - 1) break;
        }
        ((! ((i == k-1) && (a[i] == n-1))) ? (void) (0) : __assert_fail ("! ((i == k-1) && (a[i] == n-1))", "/usr/src/repo/source/library/combiner.c", 91, __extension__ __PRETTY_FUNCTION__));
        ++a[i];
        for (j = 0; j < i; ++j) a[j] = j;
    }
    for (int c = 0; c < k; ++c) {
        cp->hand->cards[c] = cp->deck->cards[a[c]];
    }
    --cp->remaining;
    cp->hand->eflags = 0;
    return 1;
}

variable_types: j int

variable_types:
a
char *

variable_types: c int

user_defined_types: struct _oj_cardlist { int _johnnymoss; long allocation; long pflags; unsigned long mask; char *cards; void *filler[4]; }


original_code:
int ojc_next_random(oj_combiner *cp) {
    int k = cp->k, n = cp->deck->length;
    oj_card *mp = cp->map;
    ((0 != cp && 0x10ACE0FF == cp->_johnnymoss) ? (void) (0) : __assert_fail ("0 != cp && 0x10ACE0FF == cp->_johnnymoss", "/usr/src/repo/source/library/combiner.c", 107, __extension__ __PRETTY_FUNCTION__));
    if (0 == cp->remaining) return 0;
    int_fast64_t set = 0ll, m;
    for (int j = n - k; j < n; ++j) {
        int r = ojr_rand(j+1);
        m = 1ll << r;
        if (set & m) {
            *mp++ = j;
            set |= (1ll << j);
        } else {
            *mp++ = r;
            set |= m;
        }
    }
    for (int i = 0; i < k; ++i) {
        cp->hand->cards[i] = cp->deck->cards[cp->map[i]];
    }
    --cp->remaining;
    cp->hand->eflags = 0;
    return 1;
}

canonical_original_code:
int ojc_next_random(struct _oj_combiner *cp) {
    int k = cp->k; int n = cp->deck->length;
    char *mp = cp->map;
    ((0 != cp && 0x10ACE0FF == cp->_johnnymoss) ? (void) (0) : __assert_fail ("0 != cp && 0x10ACE0FF == cp->_johnnymoss", "/usr/src/repo/source/library/combiner.c", 107, __extension__ __PRETTY_FUNCTION__));
    if (0 == cp->remaining) return 0;
    long set = 0ll; long m;
    for (int j = n - k; j < n; ++j) {
        int r = ojr_rand(j+1);
        m = 1ll << r;
        if (set & m) {
            *mp++ = j;
            set |= (1ll << j);
        } else {
            *mp++ = r;
            set |= m;
        }
    }
    for (int i = 0; i < k; ++i) {
        cp->hand->cards[i] = cp->deck->cards[cp->map[i]];
    }
    --cp->remaining;
    cp->hand->eflags = 0;
    return 1;
}

variable_types:
mp
char *

variable_types: set long

variable_types: m long

variable_types: r int


decompiled_code:
__int64 __fastcall ojc_colex_rank(__int64 a1, __int64 a2)
{
__int64 v3; // rdx
__int64 v5; // rsi
__int64 v6; // rcx
__int64 i; // rax
__int64 v8; // rbx
__int64 v9; // r12
int v10; // edi
_BYTE v12[104]; // [rsp+0h] [rbp-68h] BYREF

if ( !a2 || !a1 )
_assert_fail("0 != hand && 0 != cp", "/usr/src/repo/source/library/combiner.c", 0x8Bu, "ojc_colex_rank");
v3 = *(_QWORD *)(a2 + 16);
if ( v3 > 63 )
_assert_fail("hand->length < 64", "/usr/src/repo/source/library/combiner.c", 0x8Cu, "ojc_colex_rank");
v5 = *(_QWORD *)(a1 + 8);
if ( v3 != v5 )
return -1LL;
if ( v5 > 0 )
{
v6 = *(_QWORD *)(a2 + 48);
for ( i = 0LL; i != v5; ++i )
v12[i] = *(_BYTE *)(a1 + *(char *)(v6 + i) + 96);
}
ojl_sort_cards(v12);
if ( *(__int64 *)(a1 + 8) > 0 )
{
v8 = 0LL;
v9 = 0LL;
do
{
v10 = (char)v12[v8++];
v9 += ojc_binomial(v10, v8);
}
while ( *(_QWORD *)(a1 + 8) > v8 );
return v9;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v3; // rdx
__int64 v5; // rsi
__int64 v6; // rcx
__int64 i; // rax
__int64 v8; // rbx
__int64 v9; // r12
int v10; // edi
_BYTE v12[104]; // [rsp+0h] [rbp-68h] BYREF

if ( !a2 || !a1 )
_assert_fail("0 != hand && 0 != cp", "/usr/src/repo/source/library/combiner.c", 0x8Bu, "ojc_colex_rank");
v3 = *(_QWORD *)(a2 + 16);
if ( v3 > 63 )
_assert_fail("hand->length < 64", "/usr/src/repo/source/library/combiner.c", 0x8Cu, "ojc_colex_rank");
v5 = *(_QWORD *)(a1 + 8);
if ( v3 != v5 )
return -1LL;
if ( v5 > 0 )
{
v6 = *(_QWORD *)(a2 + 48);
for ( i = 0LL; i != v5; ++i )
v12[i] = *(_BYTE *)(a1 + *(char *)(v6 + i) + 96);
}
ojl_sort_cards(v12);
if ( *(__int64 *)(a1 + 8) > 0 )
{
v8 = 0LL;
v9 = 0LL;
do
{
v10 = (char)v12[v8++];
v9 += func0(v10, v8);
}
while ( *(_QWORD *)(a1 + 8) > v8 );
return v9;
}
return 0LL;
}

original_code:
int64_t ojc_colex_rank(oj_combiner *cp, oj_cardlist *hand) {
    oj_card buf[56];
    int64_t r = 0LL;
    ((0 != hand && 0 != cp) ? (void) (0) : __assert_fail ("0 != hand && 0 != cp", "/usr/src/repo/source/library/combiner.c", 139, __extension__ __PRETTY_FUNCTION__));
    ((hand->length < 64) ? (void) (0) : __assert_fail ("hand->length < 64", "/usr/src/repo/source/library/combiner.c", 140, __extension__ __PRETTY_FUNCTION__));
    if (hand->length != cp->k) return -1LL;
    for (int i = 0; i < cp->k; ++i) buf[i] = cp->invert[hand->cards[i]];
    _ojl_sort_cards(buf, cp->k);
    for (int i = 0; i < cp->k; ++i) r += ojc_binomial(buf[i], i + 1);
    return r;
}

canonical_original_code:
long ojc_colex_rank(struct _oj_combiner *cp, struct _oj_cardlist *hand) {
    char buf[56];
    long r = 0LL;
    ((0 != hand && 0 != cp) ? (void) (0) : __assert_fail ("0 != hand && 0 != cp", "/usr/src/repo/source/library/combiner.c", 139, __extension__ __PRETTY_FUNCTION__));
    ((hand->length < 64) ? (void) (0) : __assert_fail ("hand->length < 64", "/usr/src/repo/source/library/combiner.c", 140, __extension__ __PRETTY_FUNCTION__));
    if (hand->length != cp->k) return -1LL;
    for (int i = 0; i < cp->k; ++i) buf[i] = cp->invert[hand->cards[i]];
    _ojl_sort_cards(buf, cp->k);
    for (int i = 0; i < cp->k; ++i) r += ojc_binomial(buf[i], i + 1);
    return r;
}

variable_types:
buf
char [56]

variable_types: r long


original_code:
int ojc_colex_hand_at(oj_combiner *cp, int64_t rank, oj_cardlist *hand) {
    int i, n = cp->deck->length;
    oj_card buf[64];
    int64_t b;
    ((0 != hand && 0 != cp) ? (void) (0) : __assert_fail ("0 != hand && 0 != cp", "/usr/src/repo/source/library/combiner.c", 155, __extension__ __PRETTY_FUNCTION__));
    if (hand->pflags & 1) return (-2);
    if (hand->allocation < cp->k) return (-3);
    if (rank >= cp->total) return (-5);
    for (i = cp->k; i >= 1; --i) {
        while ((b = ojc_binomial(n, i)) > rank) --n;
        buf[i-1] = n;
        rank -= b;
    }
    hand->length = cp->k;
    for (i = 0; i < cp->k; ++i) hand->cards[i] = cp->deck->cards[buf[i]];
    hand->eflags = 0;
    return 0;
}

canonical_original_code:
int ojc_colex_hand_at(struct _oj_combiner *cp, long rank, struct _oj_cardlist *hand) {
    int i; int n = cp->deck->length;
    char buf[64];
    long b;
    ((0 != hand && 0 != cp) ? (void) (0) : __assert_fail ("0 != hand && 0 != cp", "/usr/src/repo/source/library/combiner.c", 155, __extension__ __PRETTY_FUNCTION__));
    if (hand->pflags & 1) return (-2);
    if (hand->allocation < cp->k) return (-3);
    if (rank >= cp->total) return (-5);
    for (i = cp->k; i >= 1; --i) {
        while ((b = ojc_binomial(n, i)) > rank) --n;
        buf[i-1] = n;
        rank -= b;
    }
    hand->length = cp->k;
    for (i = 0; i < cp->k; ++i) hand->cards[i] = cp->deck->cards[buf[i]];
    hand->eflags = 0;
    return 0;
}

variable_types: rank long

variable_types: n int

variable_types:
buf
char [64]


decompiled_code:
__int64 __fastcall ojp_eval5(__int64 a1)
{
char *v1; // rcx

if ( !a1 || *(_DWORD *)a1 != 279765247 )
_assert_fail("0 != p && 0x10ACE0FF == p->_johnnymoss", "/usr/src/repo/source/library/poker.c", 0x14u, "ojp_eval5");
if ( *(_QWORD *)(a1 + 16) != 5LL )
_assert_fail("5 == p->length", "/usr/src/repo/source/library/poker.c", 0x15u, "ojp_eval5");
v1 = *(char **)(a1 + 48);
return (unsigned int)ldc4[ldc3[ldc2[v1[2] + ldc1[52 * *v1 - 52 + v1[1]]] + v1[3]] + v1[4]];
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *v1; // rcx

if ( !a1 || *(_DWORD *)a1 != 279765247 )
_assert_fail("0 != p && 0x10ACE0FF == p->_johnnymoss", "/usr/src/repo/source/library/poker.c", 0x14u, "ojp_eval5");
if ( *(_QWORD *)(a1 + 16) != 5LL )
_assert_fail("5 == p->length", "/usr/src/repo/source/library/poker.c", 0x15u, "ojp_eval5");
v1 = *(char **)(a1 + 48);
return (unsigned int)ldc4[ldc3[ldc2[v1[2] + ldc1[52 * *v1 - 52 + v1[1]]] + v1[3]] + v1[4]];
}

original_code:
int ojp_eval5(oj_cardlist *p) {
    ((0 != p && 0x10ACE0FF == p->_johnnymoss) ? (void) (0) : __assert_fail ("0 != p && 0x10ACE0FF == p->_johnnymoss", "/usr/src/repo/source/library/poker.c", 20, __extension__ __PRETTY_FUNCTION__));
    ((5 == p->length) ? (void) (0) : __assert_fail ("5 == p->length", "/usr/src/repo/source/library/poker.c", 21, __extension__ __PRETTY_FUNCTION__));
    return ldc4[ ldc3[ ldc2[ ldc1[
        52 * (p->cards[0] - 1) + p->cards[1] ]
           + p->cards[2] ] + p->cards[3] ] + p->cards[4] ];
}

canonical_original_code:
int ojp_eval5(struct _oj_cardlist *p) {
    ((0 != p && 0x10ACE0FF == p->_johnnymoss) ? (void) (0) : __assert_fail ("0 != p && 0x10ACE0FF == p->_johnnymoss", "/usr/src/repo/source/library/poker.c", 20, __extension__ __PRETTY_FUNCTION__));
    ((5 == p->length) ? (void) (0) : __assert_fail ("5 == p->length", "/usr/src/repo/source/library/poker.c", 21, __extension__ __PRETTY_FUNCTION__));
    return ldc4[ ldc3[ ldc2[ ldc1[
        52 * (p->cards[0] - 1) + p->cards[1] ]
           + p->cards[2] ] + p->cards[3] ] + p->cards[4] ];
}

variable_types: struct _oj_cardlist { int _johnnymoss; long allocation; long pflags; unsigned long mask; char *cards; void *filler[4]; } *


variable_types:
h
char *

variable_types: best int


decompiled_code:
__int64 __fastcall ojp_best5(__int64 a1, __int64 a2)
{
__int64 v2; // rax
int v3; // er12
int v4; // eax
__int64 result; // rax

if ( !a1 || (v2 = *(_QWORD *)(a1 + 16), v2 <= 4) )
_assert_fail("0 != p && p->length >= 5", "/usr/src/repo/source/library/poker.c", 0x8Du, "ojp_best5");
if ( !a2 || *(__int64 *)(a2 + 8) <= 4 || (*(_BYTE *)(a2 + 24) & 1) != 0 )
_assert_fail(
"0 != bh && bh->allocation >= 5 && (!(bh->pflags & OJF_RDONLY))",
"/usr/src/repo/source/library/poker.c",
0x8Eu,
"ojp_best5");
if ( v2 == 5 )
{
ojl_copy(a2, a1);
result = ojp_eval5(a1);
}
else
{
v3 = 9999;
ojl_new(&hand, &hbuf, 5LL);
ojc_new(&cmb, a1, &hand, 5LL, 0LL);
while ( (unsigned int)ojc_next(&cmb) )
{
v4 = ojp_eval5((__int64)&hand);
if ( v3 > v4 )
{
v3 = v4;
ojl_copy(a2, &hand);
}
}
result = (unsigned int)v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rax
int v3; // er12
int v4; // eax
__int64 result; // rax

if ( !a1 || (v2 = *(_QWORD *)(a1 + 16), v2 <= 4) )
_assert_fail("0 != p && p->length >= 5", "/usr/src/repo/source/library/poker.c", 0x8Du, "ojp_best5");
if ( !a2 || *(__int64 *)(a2 + 8) <= 4 || (*(_BYTE *)(a2 + 24) & 1) != 0 )
_assert_fail(
"0 != bh && bh->allocation >= 5 && (!(bh->pflags & OJF_RDONLY))",
"/usr/src/repo/source/library/poker.c",
0x8Eu,
"ojp_best5");
if ( v2 == 5 )
{
ojl_copy(a2, a1);
result = func0(a1);
}
else
{
v3 = 9999;
ojl_new(&hand, &hbuf, 5LL);
ojc_new(&cmb, a1, &hand, 5LL, 0LL);
while ( (unsigned int)ojc_next(&cmb) )
{
v4 = func0((__int64)&hand);
if ( v3 > v4 )
{
v3 = v4;
ojl_copy(a2, &hand);
}
}
result = (unsigned int)v3;
}
return result;
}

original_code:
int ojp_best5(oj_cardlist *p, oj_cardlist *bh) {
    ((0 != p && p->length >= 5) ? (void) (0) : __assert_fail ("0 != p && p->length >= 5", "/usr/src/repo/source/library/poker.c", 141, __extension__ __PRETTY_FUNCTION__));
    ((0 != bh && bh->allocation >= 5 && (!(bh->pflags & 1))) ? (void) (0) : __assert_fail ("0 != bh && bh->allocation >= 5 && (!(bh->pflags & OJF_RDONLY))", "/usr/src/repo/source/library/poker.c", 142, __extension__ __PRETTY_FUNCTION__));
    if (5 == p->length) {
        ojl_copy(bh, p);
        return ojp_eval5(p);
    }
    ojl_new(&_hand, _hbuf, 5);
    ojc_new(&_cmb, p, &_hand, 5, 0LL);
    int best = 9999;
    while (ojc_next(&_cmb)) {
        int v = ojp_eval5(&_hand);
        if (v < best) {
            best = v;
            ojl_copy(bh, &_hand);
        }
    }
    return best;
}

canonical_original_code:
int ojp_best5(struct _oj_cardlist *p, struct _oj_cardlist *bh) {
    ((0 != p && p->length >= 5) ? (void) (0) : __assert_fail ("0 != p && p->length >= 5", "/usr/src/repo/source/library/poker.c", 141, __extension__ __PRETTY_FUNCTION__));
    ((0 != bh && bh->allocation >= 5 && (!(bh->pflags & 1))) ? (void) (0) : __assert_fail ("0 != bh && bh->allocation >= 5 && (!(bh->pflags & OJF_RDONLY))", "/usr/src/repo/source/library/poker.c", 142, __extension__ __PRETTY_FUNCTION__));
    if (5 == p->length) {
        ojl_copy(bh, p);
        return ojp_eval5(p);
    }
    ojl_new(&_hand, _hbuf, 5);
    ojc_new(&_cmb, p, &_hand, 5, 0LL);
    int best = 9999;
    while (ojc_next(&_cmb)) {
        int v = ojp_eval5(&_hand);
        if (v < best) {
            best = v;
            ojl_copy(bh, &_hand);
        }
    }
    return best;
}

variable_types:
bh
struct _oj_cardlist *

variable_types: v int


original_code:
int ojp_hand_info(oj_poker_hand_info *pi, oj_cardlist *p, int val) {
    oj_card t[5], *h = p->cards;
    ((0 != pi && 0 != p) ? (void) (0) : __assert_fail ("0 != pi && 0 != p", "/usr/src/repo/source/library/poker.c", 167, __extension__ __PRETTY_FUNCTION__));
    ((5 == p->length) ? (void) (0) : __assert_fail ("5 == p->length", "/usr/src/repo/source/library/poker.c", 168, __extension__ __PRETTY_FUNCTION__));
    if (-1 == val) val = ojp_eval5(p);
    pi->val = val;
    ojl_sort(p);
    ojl_reverse(p);
    if (val < 11) {
        pi->group = 1;
        pi->nranks = 1;
        pi->ranks[0] = ((oj_rank)(((h[0]) - 1) >> 2));
        if (OJR_ACE == pi->ranks[0] && OJR_FIVE == ((oj_rank)(((h[1]) - 1) >> 2))) {
            pi->ranks[0] = OJR_FIVE;
            t[0] = h[0];
            memmove(h, h + 1, 4 * sizeof(oj_card));
            h[4] = t[0];
        }
    } else if (val < 167) {
        pi->group = 2;
        pi->nranks = 2;
        if (((oj_rank)(((h[0]) - 1) >> 2)) != ((oj_rank)(((h[1]) - 1) >> 2))) {
            t[0] = h[0];
            memmove(h, h + 1, 4 * sizeof(oj_card));
            h[4] = t[0];
        }
        pi->ranks[0] = ((oj_rank)(((h[0]) - 1) >> 2));
        pi->ranks[1] = ((oj_rank)(((h[4]) - 1) >> 2));
    } else if (val < 323) {
        pi->group = 3;
        pi->nranks = 2;
        if (((oj_rank)(((h[0]) - 1) >> 2)) != ((oj_rank)(((h[2]) - 1) >> 2))) {
            memmove(t, h, 2 * sizeof(oj_card));
            memmove(h, h + 2, 3 * sizeof(oj_card));
            memmove(h + 3, t, 2 * sizeof(oj_card));
        }
        pi->ranks[0] = ((oj_rank)(((h[0]) - 1) >> 2));
        pi->ranks[1] = ((oj_rank)(((h[3]) - 1) >> 2));
    } else if (val < 1600) {
        pi->group = 4;
        pi->nranks = 5;
        for (int i = 0; i < 5; ++i) pi->ranks[i] = ((oj_rank)(((h[i]) - 1) >> 2));
    } else if (val < 1610) {
        pi->group = 5;
        pi->nranks = 1;
        pi->ranks[0] = ((oj_rank)(((h[0]) - 1) >> 2));
        if (OJR_ACE == pi->ranks[0] && OJR_FIVE == ((oj_rank)(((h[1]) - 1) >> 2))) {
            pi->ranks[0] = OJR_FIVE;
            t[0] = h[0];
            memmove(h, h + 1, 4 * sizeof(oj_card));
            h[4] = t[0];
        }
    } else if (val < 2468) {
        pi->group = 6;
        pi->nranks = 3;
        for (int i = 0; i < 3; ++i) t[i] = ((oj_rank)(((h[i]) - 1) >> 2));
        if (t[0] != t[1]) {
            if (t[1] != t[2]) {
                memmove(t, h, 2 * sizeof(oj_card));
                memmove(h, h + 2, 3 * sizeof(oj_card));
                memmove(h + 3, t, 2 * sizeof(oj_card));
            } else {
                t[0] = h[0];
                memmove(h, h + 1, 3 * sizeof(oj_card));
                h[3] = t[0];
            }
        }
        for (int i = 0; i < 3; ++i) pi->ranks[i] = ((oj_rank)(((h[i+2]) - 1) >> 2));
    } else if (val < 3326) {
        pi->group = 7;
        pi->nranks = 3;
        for (int i = 0; i < 5; ++i) t[i] = ((oj_rank)(((h[i]) - 1) >> 2));
        if (t[3] == t[4]) {
            if (t[0] == t[1]) {
                t[0] = h[2];
                memmove(h + 2, h + 3, 2 * sizeof(oj_card));
                h[4] = t[0];
            } else {
                t[0] = h[0];
                memmove(h, h + 1, 4 * sizeof(oj_card));
                h[4] = t[0];
            }
        }
        for (int i = 0; i < 3; ++i) pi->ranks[i] = ((oj_rank)(((h[i << 1]) - 1) >> 2));
    } else if (val < 6186) {
        pi->group = 8;
        pi->nranks = 4;
        for (int i = 0; i < 5; ++i) t[i] = ((oj_rank)(((h[i]) - 1) >> 2));
        if (t[1] == t[2]) {
            t[0] = h[0];
            memmove(h, h + 1, 2 * sizeof(oj_card));
            h[2] = t[0];
        } else if (t[2] == t[3]) {
            memmove(t, h, 2 * sizeof(oj_card));
            memmove(h, h + 2, 2 * sizeof(oj_card));
            memmove(h + 2, t, 2 * sizeof(oj_card));
        } else if (t[3] == t[4]) {
            memmove(t, h, 3 * sizeof(oj_card));
            memmove(h, h + 3, 2 * sizeof(oj_card));
            memmove(h + 2, t, 3 * sizeof(oj_card));
        }
        for (int i = 0; i < 4; ++i) pi->ranks[i] = ((oj_rank)(((h[i+1]) - 1) >> 2));
    } else {
        pi->group = 9;
        pi->nranks = 5;
        for (int i = 0; i < 5; ++i) pi->ranks[i] = ((oj_rank)(((h[i]) - 1) >> 2));
    }
    pi->_johnnymoss = 0x10ACE0FF;
    return pi->group;
}

canonical_original_code:
int ojp_hand_info(struct _oj_poker_hand_info *pi, struct _oj_cardlist *p, int val) {
    char t[5]; char *h = p->cards;
    ((0 != pi && 0 != p) ? (void) (0) : __assert_fail ("0 != pi && 0 != p", "/usr/src/repo/source/library/poker.c", 167, __extension__ __PRETTY_FUNCTION__));
    ((5 == p->length) ? (void) (0) : __assert_fail ("5 == p->length", "/usr/src/repo/source/library/poker.c", 168, __extension__ __PRETTY_FUNCTION__));
    if (-1 == val) val = ojp_eval5(p);
    pi->val = val;
    ojl_sort(p);
    ojl_reverse(p);
    if (val < 11) {
        pi->group = 1;
        pi->nranks = 1;
        pi->ranks[0] = ((oj_rank)(((h[0]) - 1) >> 2));
        if (OJR_ACE == pi->ranks[0] && OJR_FIVE == ((oj_rank)(((h[1]) - 1) >> 2))) {
            pi->ranks[0] = OJR_FIVE;
            t[0] = h[0];
            memmove(h, h + 1, 4 * sizeof(oj_card));
            h[4] = t[0];
        }
    } else if (val < 167) {
        pi->group = 2;
        pi->nranks = 2;
        if (((oj_rank)(((h[0]) - 1) >> 2)) != ((oj_rank)(((h[1]) - 1) >> 2))) {
            t[0] = h[0];
            memmove(h, h + 1, 4 * sizeof(oj_card));
            h[4] = t[0];
        }
        pi->ranks[0] = ((oj_rank)(((h[0]) - 1) >> 2));
        pi->ranks[1] = ((oj_rank)(((h[4]) - 1) >> 2));
    } else if (val < 323) {
        pi->group = 3;
        pi->nranks = 2;
        if (((oj_rank)(((h[0]) - 1) >> 2)) != ((oj_rank)(((h[2]) - 1) >> 2))) {
            memmove(t, h, 2 * sizeof(oj_card));
            memmove(h, h + 2, 3 * sizeof(oj_card));
            memmove(h + 3, t, 2 * sizeof(oj_card));
        }
        pi->ranks[0] = ((oj_rank)(((h[0]) - 1) >> 2));
        pi->ranks[1] = ((oj_rank)(((h[3]) - 1) >> 2));
    } else if (val < 1600) {
        pi->group = 4;
        pi->nranks = 5;
        for (int i = 0; i < 5; ++i) pi->ranks[i] = ((oj_rank)(((h[i]) - 1) >> 2));
    } else if (val < 1610) {
        pi->group = 5;
        pi->nranks = 1;
        pi->ranks[0] = ((oj_rank)(((h[0]) - 1) >> 2));
        if (OJR_ACE == pi->ranks[0] && OJR_FIVE == ((oj_rank)(((h[1]) - 1) >> 2))) {
            pi->ranks[0] = OJR_FIVE;
            t[0] = h[0];
            memmove(h, h + 1, 4 * sizeof(oj_card));
            h[4] = t[0];
        }
    } else if (val < 2468) {
        pi->group = 6;
        pi->nranks = 3;
        for (int i = 0; i < 3; ++i) t[i] = ((oj_rank)(((h[i]) - 1) >> 2));
        if (t[0] != t[1]) {
            if (t[1] != t[2]) {
                memmove(t, h, 2 * sizeof(oj_card));
                memmove(h, h + 2, 3 * sizeof(oj_card));
                memmove(h + 3, t, 2 * sizeof(oj_card));
            } else {
                t[0] = h[0];
                memmove(h, h + 1, 3 * sizeof(oj_card));
                h[3] = t[0];
            }
        }
        for (int i = 0; i < 3; ++i) pi->ranks[i] = ((oj_rank)(((h[i+2]) - 1) >> 2));
    } else if (val < 3326) {
        pi->group = 7;
        pi->nranks = 3;
        for (int i = 0; i < 5; ++i) t[i] = ((oj_rank)(((h[i]) - 1) >> 2));
        if (t[3] == t[4]) {
            if (t[0] == t[1]) {
                t[0] = h[2];
                memmove(h + 2, h + 3, 2 * sizeof(oj_card));
                h[4] = t[0];
            } else {
                t[0] = h[0];
                memmove(h, h + 1, 4 * sizeof(oj_card));
                h[4] = t[0];
            }
        }
        for (int i = 0; i < 3; ++i) pi->ranks[i] = ((oj_rank)(((h[i << 1]) - 1) >> 2));
    } else if (val < 6186) {
        pi->group = 8;
        pi->nranks = 4;
        for (int i = 0; i < 5; ++i) t[i] = ((oj_rank)(((h[i]) - 1) >> 2));
        if (t[1] == t[2]) {
            t[0] = h[0];
            memmove(h, h + 1, 2 * sizeof(oj_card));
            h[2] = t[0];
        } else if (t[2] == t[3]) {
            memmove(t, h, 2 * sizeof(oj_card));
            memmove(h, h + 2, 2 * sizeof(oj_card));
            memmove(h + 2, t, 2 * sizeof(oj_card));
        } else if (t[3] == t[4]) {
            memmove(t, h, 3 * sizeof(oj_card));
            memmove(h, h + 3, 2 * sizeof(oj_card));
            memmove(h + 2, t, 3 * sizeof(oj_card));
        }
        for (int i = 0; i < 4; ++i) pi->ranks[i] = ((oj_rank)(((h[i+1]) - 1) >> 2));
    } else {
        pi->group = 9;
        pi->nranks = 5;
        for (int i = 0; i < 5; ++i) pi->ranks[i] = ((oj_rank)(((h[i]) - 1) >> 2));
    }
    pi->_johnnymoss = 0x10ACE0FF;
    return pi->group;
}

variable_types: struct _oj_poker_hand_info { int _johnnymoss; int val; int ranks[5]; void *filler[4]; } *

variable_types: val int

variable_types:
t
char [5]

variable_types: i int


decompiled_code:
__int64 __fastcall ojp_hand_group_name(int a1)
{
if ( (unsigned int)(a1 - 1) > 8 )
_assert_fail("g >= 1 && g <= 9", "/usr/src/repo/source/library/poker.c", 0x11Du, "ojp_hand_group_name");
return ojp_hand_group_names[a1];
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
if ( (unsigned int)(a1 - 1) > 8 )
_assert_fail("g >= 1 && g <= 9", "/usr/src/repo/source/library/poker.c", 0x11Du, "ojp_hand_group_name");
return ojp_hand_group_names[a1];
}

original_code:
char *ojp_hand_group_name(int g) {
    ((g >= 1 && g <= 9) ? (void) (0) : __assert_fail ("g >= 1 && g <= 9", "/usr/src/repo/source/library/poker.c", 285, __extension__ __PRETTY_FUNCTION__));
    return _ojp_hand_group_names[g];
}

variable_types: g int

return_type: char *


decompiled_code:
char *__fastcall ojp_hand_description(_DWORD *a1, char *a2, int a3)
{
size_t v4; // rbp
__int64 v5; // rax
__int64 v6; // rdi
const char *v7; // rbx
const char *v8; // r13
const char *v9; // rax
const char *v11; // r15
const char *v12; // r14
const char *v13; // r13
const char *v14; // rax
__int64 v15; // rdi
const char *v16; // rax
__int64 v17; // rdi
const char *v18; // r13
const char *v19; // rdx
__int64 v20; // rax
__int64 v21; // rdi
const char *v22; // r14
const char *v23; // rax
const char *v24; // r15
const char *v25; // r14
const char *v26; // r13
const char *v27; // rax
const char *v28; // rax
const char *v29; // r14
__int64 v30; // rax
__int64 v31; // rdi
const char *v32; // rbx
const char *v33; // r13
const char *v34; // rax
const char *v35; // r13
__int64 v36; // rax
__int64 v37; // rdi
const char *v38; // rdx
const char *v39; // r15
__int64 v40; // rax
__int64 v41; // rdi
const char *v42; // r14
const char *v43; // rax
const char *v44; // r15
const char *v45; // r14
__int64 v46; // rax
__int64 v47; // rdi
const char *v48; // rbx
const char *v49; // r13
const char *v50; // rax
const char *v51; // [rsp+8h] [rbp-40h]
const char *v52; // [rsp+8h] [rbp-40h]
const char *v53; // [rsp+8h] [rbp-40h]
const char *v54; // [rsp+8h] [rbp-40h]

if ( *a1 != 279765247 )
_assert_fail(
"0x10ACE0FF == pi->_johnnymoss",
"/usr/src/repo/source/library/poker.c",
0x125u,
"ojp_hand_description");
v4 = a3;
switch ( a1[2] )
{
case 1:
v15 = (unsigned int)a1[4];
if ( (_DWORD)v15 == 12 )
{
snprintf(a2, a3, "Royal Flush");
}
else
{
v16 = (const char *)ojt_rank(v15);
snprintf(a2, v4, "%s-high Straight Flush", v16);
}
break;
case 2:
v5 = ojt_rank((unsigned int)a1[5]);
v6 = (unsigned int)a1[4];
v7 = "es";
v8 = (const char *)v5;
if ( (_DWORD)v6 != 4 )
v7 = "s";
v9 = (const char *)ojt_rank(v6);
snprintf(a2, (int)v4, "Four %s%s, %s", v9, v7, v8);
break;
case 3:
v17 = (unsigned int)a1[5];
v18 = "es";
v19 = "s";
if ( (_DWORD)v17 == 4 )
v19 = "es";
v52 = v19;
v20 = ojt_rank(v17);
v21 = (unsigned int)a1[4];
v22 = (const char *)v20;
if ( (_DWORD)v21 != 4 )
v18 = "s";
v23 = (const char *)ojt_rank(v21);
snprintf(a2, (int)v4, "%s%s Full of %s%s", v23, v18, v22, v52);
break;
case 4:
v53 = (const char *)ojt_rank((unsigned int)a1[8]);
v24 = (const char *)ojt_rank((unsigned int)a1[7]);
v25 = (const char *)ojt_rank((unsigned int)a1[6]);
v26 = (const char *)ojt_rank((unsigned int)a1[5]);
v27 = (const char *)ojt_rank((unsigned int)a1[4]);
snprintf(a2, (int)v4, "Flush, %s, %s, %s, %s, %s", v27, v26, v25, v24, v53);
break;
case 5:
v28 = (const char *)ojt_rank((unsigned int)a1[4]);
snprintf(a2, (int)v4, "%s-high Straight", v28);
break;
case 6:
v29 = (const char *)ojt_rank((unsigned int)a1[6]);
v30 = ojt_rank((unsigned int)a1[5]);
v31 = (unsigned int)a1[4];
v32 = "es";
v33 = (const char *)v30;
if ( (_DWORD)v31 != 4 )
v32 = "s";
v34 = (const char *)ojt_rank(v31);
snprintf(a2, (int)v4, "Three %s%s, %s, %s", v34, v32, v33, v29);
break;
case 7:
v35 = "es";
v36 = ojt_rank((unsigned int)a1[6]);
v37 = (unsigned int)a1[5];
v38 = "s";
v39 = (const char *)v36;
if ( (_DWORD)v37 == 4 )
v38 = "es";
v54 = v38;
v40 = ojt_rank(v37);
v41 = (unsigned int)a1[4];
v42 = (const char *)v40;
if ( (_DWORD)v41 != 4 )
v35 = "s";
v43 = (const char *)ojt_rank(v41);
snprintf(a2, (int)v4, "Two Pair, %s%s and %s%s, %s", v43, v35, v42, v54, v39);
break;
case 8:
v44 = (const char *)ojt_rank((unsigned int)a1[7]);
v45 = (const char *)ojt_rank((unsigned int)a1[6]);
v46 = ojt_rank((unsigned int)a1[5]);
v47 = (unsigned int)a1[4];
v48 = "es";
v49 = (const char *)v46;
if ( (_DWORD)v47 != 4 )
v48 = "s";
v50 = (const char *)ojt_rank(v47);
snprintf(a2, (int)v4, "Pair of %s%s, %s, %s, %s", v50, v48, v49, v45, v44);
break;
case 9:
v51 = (const char *)ojt_rank((unsigned int)a1[8]);
v11 = (const char *)ojt_rank((unsigned int)a1[7]);
v12 = (const char *)ojt_rank((unsigned int)a1[6]);
v13 = (const char *)ojt_rank((unsigned int)a1[5]);
v14 = (const char *)ojt_rank((unsigned int)a1[4]);
snprintf(a2, (int)v4, "No Pair, %s, %s, %s, %s, %s", v14, v13, v12, v11, v51);
break;
default:
return a2;
}
return a2;
}

canonical_decompiled_code:
char *__fastcall func5(_DWORD *a1, char *a2, int a3)
{
size_t v4; // rbp
__int64 v5; // rax
__int64 v6; // rdi
const char *v7; // rbx
const char *v8; // r13
const char *v9; // rax
const char *v11; // r15
const char *v12; // r14
const char *v13; // r13
const char *v14; // rax
__int64 v15; // rdi
const char *v16; // rax
__int64 v17; // rdi
const char *v18; // r13
const char *v19; // rdx
__int64 v20; // rax
__int64 v21; // rdi
const char *v22; // r14
const char *v23; // rax
const char *v24; // r15
const char *v25; // r14
const char *v26; // r13
const char *v27; // rax
const char *v28; // rax
const char *v29; // r14
__int64 v30; // rax
__int64 v31; // rdi
const char *v32; // rbx
const char *v33; // r13
const char *v34; // rax
const char *v35; // r13
__int64 v36; // rax
__int64 v37; // rdi
const char *v38; // rdx
const char *v39; // r15
__int64 v40; // rax
__int64 v41; // rdi
const char *v42; // r14
const char *v43; // rax
const char *v44; // r15
const char *v45; // r14
__int64 v46; // rax
__int64 v47; // rdi
const char *v48; // rbx
const char *v49; // r13
const char *v50; // rax
const char *v51; // [rsp+8h] [rbp-40h]
const char *v52; // [rsp+8h] [rbp-40h]
const char *v53; // [rsp+8h] [rbp-40h]
const char *v54; // [rsp+8h] [rbp-40h]

if ( *a1 != 279765247 )
_assert_fail(
"0x10ACE0FF == pi->_johnnymoss",
"/usr/src/repo/source/library/poker.c",
0x125u,
"ojp_hand_description");
v4 = a3;
switch ( a1[2] )
{
case 1:
v15 = (unsigned int)a1[4];
if ( (_DWORD)v15 == 12 )
{
snprintf(a2, a3, "Royal Flush");
}
else
{
v16 = (const char *)ojt_rank(v15);
snprintf(a2, v4, "%s-high Straight Flush", v16);
}
break;
case 2:
v5 = ojt_rank((unsigned int)a1[5]);
v6 = (unsigned int)a1[4];
v7 = "es";
v8 = (const char *)v5;
if ( (_DWORD)v6 != 4 )
v7 = "s";
v9 = (const char *)ojt_rank(v6);
snprintf(a2, (int)v4, "Four %s%s, %s", v9, v7, v8);
break;
case 3:
v17 = (unsigned int)a1[5];
v18 = "es";
v19 = "s";
if ( (_DWORD)v17 == 4 )
v19 = "es";
v52 = v19;
v20 = ojt_rank(v17);
v21 = (unsigned int)a1[4];
v22 = (const char *)v20;
if ( (_DWORD)v21 != 4 )
v18 = "s";
v23 = (const char *)ojt_rank(v21);
snprintf(a2, (int)v4, "%s%s Full of %s%s", v23, v18, v22, v52);
break;
case 4:
v53 = (const char *)ojt_rank((unsigned int)a1[8]);
v24 = (const char *)ojt_rank((unsigned int)a1[7]);
v25 = (const char *)ojt_rank((unsigned int)a1[6]);
v26 = (const char *)ojt_rank((unsigned int)a1[5]);
v27 = (const char *)ojt_rank((unsigned int)a1[4]);
snprintf(a2, (int)v4, "Flush, %s, %s, %s, %s, %s", v27, v26, v25, v24, v53);
break;
case 5:
v28 = (const char *)ojt_rank((unsigned int)a1[4]);
snprintf(a2, (int)v4, "%s-high Straight", v28);
break;
case 6:
v29 = (const char *)ojt_rank((unsigned int)a1[6]);
v30 = ojt_rank((unsigned int)a1[5]);
v31 = (unsigned int)a1[4];
v32 = "es";
v33 = (const char *)v30;
if ( (_DWORD)v31 != 4 )
v32 = "s";
v34 = (const char *)ojt_rank(v31);
snprintf(a2, (int)v4, "Three %s%s, %s, %s", v34, v32, v33, v29);
break;
case 7:
v35 = "es";
v36 = ojt_rank((unsigned int)a1[6]);
v37 = (unsigned int)a1[5];
v38 = "s";
v39 = (const char *)v36;
if ( (_DWORD)v37 == 4 )
v38 = "es";
v54 = v38;
v40 = ojt_rank(v37);
v41 = (unsigned int)a1[4];
v42 = (const char *)v40;
if ( (_DWORD)v41 != 4 )
v35 = "s";
v43 = (const char *)ojt_rank(v41);
snprintf(a2, (int)v4, "Two Pair, %s%s and %s%s, %s", v43, v35, v42, v54, v39);
break;
case 8:
v44 = (const char *)ojt_rank((unsigned int)a1[7]);
v45 = (const char *)ojt_rank((unsigned int)a1[6]);
v46 = ojt_rank((unsigned int)a1[5]);
v47 = (unsigned int)a1[4];
v48 = "es";
v49 = (const char *)v46;
if ( (_DWORD)v47 != 4 )
v48 = "s";
v50 = (const char *)ojt_rank(v47);
snprintf(a2, (int)v4, "Pair of %s%s, %s, %s, %s", v50, v48, v49, v45, v44);
break;
case 9:
v51 = (const char *)ojt_rank((unsigned int)a1[8]);
v11 = (const char *)ojt_rank((unsigned int)a1[7]);
v12 = (const char *)ojt_rank((unsigned int)a1[6]);
v13 = (const char *)ojt_rank((unsigned int)a1[5]);
v14 = (const char *)ojt_rank((unsigned int)a1[4]);
snprintf(a2, (int)v4, "No Pair, %s, %s, %s, %s, %s", v14, v13, v12, v11, v51);
break;
default:
return a2;
}
return a2;
}

original_code:
char *ojp_hand_description(oj_poker_hand_info *pi, char *buf, int size) {
    ((0x10ACE0FF == pi->_johnnymoss) ? (void) (0) : __assert_fail ("0x10ACE0FF == pi->_johnnymoss", "/usr/src/repo/source/library/poker.c", 293, __extension__ __PRETTY_FUNCTION__));
    switch (pi->group) {
    case 1:
        if (12 == pi->ranks[0]) {
            snprintf(buf, size, "Royal Flush");
        } else {
            snprintf(buf, size, "%s-high Straight Flush", (ojt_rank(pi->ranks[0])));
        }
        break;
    case 2:
        snprintf(buf, size, "Four %s%s, %s", (ojt_rank(pi->ranks[0])), ((OJR_SIX==pi->ranks[0])?"es":"s"), (ojt_rank(pi->ranks[1])));
        break;
    case 3:
        snprintf(buf, size, "%s%s Full of %s%s", (ojt_rank(pi->ranks[0])), ((OJR_SIX==pi->ranks[0])?"es":"s"),
            (ojt_rank(pi->ranks[1])), ((OJR_SIX==pi->ranks[1])?"es":"s"));
        break;
    case 4:
        snprintf(buf, size, "Flush, %s, %s, %s, %s, %s", (ojt_rank(pi->ranks[0])), (ojt_rank(pi->ranks[1])),
            (ojt_rank(pi->ranks[2])), (ojt_rank(pi->ranks[3])), (ojt_rank(pi->ranks[4])));
        break;
    case 5:
        snprintf(buf, size, "%s-high Straight", (ojt_rank(pi->ranks[0])));
        break;
    case 6:
        snprintf(buf, size, "Three %s%s, %s, %s", (ojt_rank(pi->ranks[0])), ((OJR_SIX==pi->ranks[0])?"es":"s"),
            (ojt_rank(pi->ranks[1])), (ojt_rank(pi->ranks[2])));
        break;
    case 7:
        snprintf(buf, size, "Two Pair, %s%s and %s%s, %s", (ojt_rank(pi->ranks[0])), ((OJR_SIX==pi->ranks[0])?"es":"s"),
            (ojt_rank(pi->ranks[1])), ((OJR_SIX==pi->ranks[1])?"es":"s"), (ojt_rank(pi->ranks[2])));
        break;
    case 8:
        snprintf(buf, size, "Pair of %s%s, %s, %s, %s", (ojt_rank(pi->ranks[0])), ((OJR_SIX==pi->ranks[0])?"es":"s"),
            (ojt_rank(pi->ranks[1])), (ojt_rank(pi->ranks[2])), (ojt_rank(pi->ranks[3])));
        break;
    case 9:
        snprintf(buf, size, "No Pair, %s, %s, %s, %s, %s", (ojt_rank(pi->ranks[0])), (ojt_rank(pi->ranks[1])),
            (ojt_rank(pi->ranks[2])), (ojt_rank(pi->ranks[3])), (ojt_rank(pi->ranks[4])));
        break;
    }
    return buf;
}

canonical_original_code:
char *ojp_hand_description(struct _oj_poker_hand_info *pi, char *buf, int size) {
    ((0x10ACE0FF == pi->_johnnymoss) ? (void) (0) : __assert_fail ("0x10ACE0FF == pi->_johnnymoss", "/usr/src/repo/source/library/poker.c", 293, __extension__ __PRETTY_FUNCTION__));
    switch (pi->group) {
    case 1:
        if (12 == pi->ranks[0]) {
            snprintf(buf, size, "Royal Flush");
        } else {
            snprintf(buf, size, "%s-high Straight Flush", (ojt_rank(pi->ranks[0])));
        }
        break;
    case 2:
        snprintf(buf, size, "Four %s%s, %s", (ojt_rank(pi->ranks[0])), ((OJR_SIX==pi->ranks[0])?"es":"s"), (ojt_rank(pi->ranks[1])));
        break;
    case 3:
        snprintf(buf, size, "%s%s Full of %s%s", (ojt_rank(pi->ranks[0])), ((OJR_SIX==pi->ranks[0])?"es":"s"),
            (ojt_rank(pi->ranks[1])), ((OJR_SIX==pi->ranks[1])?"es":"s"));
        break;
    case 4:
        snprintf(buf, size, "Flush, %s, %s, %s, %s, %s", (ojt_rank(pi->ranks[0])), (ojt_rank(pi->ranks[1])),
            (ojt_rank(pi->ranks[2])), (ojt_rank(pi->ranks[3])), (ojt_rank(pi->ranks[4])));
        break;
    case 5:
        snprintf(buf, size, "%s-high Straight", (ojt_rank(pi->ranks[0])));
        break;
    case 6:
        snprintf(buf, size, "Three %s%s, %s, %s", (ojt_rank(pi->ranks[0])), ((OJR_SIX==pi->ranks[0])?"es":"s"),
            (ojt_rank(pi->ranks[1])), (ojt_rank(pi->ranks[2])));
        break;
    case 7:
        snprintf(buf, size, "Two Pair, %s%s and %s%s, %s", (ojt_rank(pi->ranks[0])), ((OJR_SIX==pi->ranks[0])?"es":"s"),
            (ojt_rank(pi->ranks[1])), ((OJR_SIX==pi->ranks[1])?"es":"s"), (ojt_rank(pi->ranks[2])));
        break;
    case 8:
        snprintf(buf, size, "Pair of %s%s, %s, %s, %s", (ojt_rank(pi->ranks[0])), ((OJR_SIX==pi->ranks[0])?"es":"s"),
            (ojt_rank(pi->ranks[1])), (ojt_rank(pi->ranks[2])), (ojt_rank(pi->ranks[3])));
        break;
    case 9:
        snprintf(buf, size, "No Pair, %s, %s, %s, %s, %s", (ojt_rank(pi->ranks[0])), (ojt_rank(pi->ranks[1])),
            (ojt_rank(pi->ranks[2])), (ojt_rank(pi->ranks[3])), (ojt_rank(pi->ranks[4])));
        break;
    }
    return buf;
}

variable_types:
buf
char *

variable_types: size int

user_defined_types: struct _oj_poker_hand_info { int _johnnymoss; int val; int ranks[5]; void *filler[4]; }


decompiled_code:
char *__fastcall ojt_card(char a1)
{
unsigned __int8 v1; // di

v1 = a1 - 1;
if ( v1 > 0x35u )
_assert_fail("c > 0 && c < 55", "/usr/src/repo/source/library/text.c", 0x1Cu, "ojt_card");
return cardnames[(char)v1];
}

canonical_decompiled_code:
char *__fastcall func1(char a1)
{
unsigned __int8 v1; // di

v1 = a1 - 1;
if ( v1 > 0x35u )
_assert_fail("c > 0 && c < 55", "/usr/src/repo/source/library/text.c", 0x1Cu, "ojt_card");
return cardnames[(char)v1];
}

original_code:
char *ojt_card(oj_card c) {
    ((c > 0 && c < 55) ? (void) (0) : __assert_fail ("c > 0 && c < 55", "/usr/src/repo/source/library/text.c", 28, __extension__ __PRETTY_FUNCTION__));
    return _cardnames[c - 1];
}

canonical_original_code:
char *ojt_card(char c) {
    ((c > 0 && c < 55) ? (void) (0) : __assert_fail ("c > 0 && c < 55", "/usr/src/repo/source/library/text.c", 28, __extension__ __PRETTY_FUNCTION__));
    return _cardnames[c - 1];
}

variable_types: c char


decompiled_code:
char *__fastcall ojt_rank(unsigned int a1)
{
if ( a1 > 0xD )
_assert_fail("r <= 13", "/usr/src/repo/source/library/text.c", 0x27u, "ojt_rank");
return ranknames[a1];
}

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1)
{
if ( a1 > 0xD )
_assert_fail("r <= 13", "/usr/src/repo/source/library/text.c", 0x27u, "ojt_rank");
return ranknames[a1];
}

original_code:
char *ojt_rank(oj_rank r) {
    ((r <= 13) ? (void) (0) : __assert_fail ("r <= 13", "/usr/src/repo/source/library/text.c", 39, __extension__ __PRETTY_FUNCTION__));
    return _ranknames[r];
}

canonical_original_code:
char *ojt_rank(enum _oj_rank r) {
    ((r <= 13) ? (void) (0) : __assert_fail ("r <= 13", "/usr/src/repo/source/library/text.c", 39, __extension__ __PRETTY_FUNCTION__));
    return _ranknames[r];
}

variable_types: enum _oj_rank { OJR_DEUCE=0, OJR_TWO=0, OJR_TREY=1, OJR_THREE=1, OJR_FOUR=2, OJR_FIVE=3, OJR_SIX=4, OJR_SEVEN=5, OJR_EIGHT=6, OJR_NINE=7, OJR_TEN=8, OJR_JACK=9, OJR_KNAVE=9, OJR_QUEEN=10, OJR_KING=11, OJR_ACE=12, OJR_JOKER=13 }


decompiled_code:
char *__fastcall ojt_suit(unsigned int a1)
{
if ( a1 > 3 )
_assert_fail("s <= 3", "/usr/src/repo/source/library/text.c", 0x31u, "ojt_suit");
return suitnames[a1];
}

canonical_decompiled_code:
char *__fastcall func3(unsigned int a1)
{
if ( a1 > 3 )
_assert_fail("s <= 3", "/usr/src/repo/source/library/text.c", 0x31u, "ojt_suit");
return suitnames[a1];
}

original_code:
char *ojt_suit(oj_suit s) {
    ((s <= 3) ? (void) (0) : __assert_fail ("s <= 3", "/usr/src/repo/source/library/text.c", 49, __extension__ __PRETTY_FUNCTION__));
    return _suitnames[s];
}

canonical_original_code:
char *ojt_suit(enum _oj_suit s) {
    ((s <= 3) ? (void) (0) : __assert_fail ("s <= 3", "/usr/src/repo/source/library/text.c", 49, __extension__ __PRETTY_FUNCTION__));
    return _suitnames[s];
}

variable_types: enum _oj_suit { OJS_CLUB=0, OJS_DIAMOND=1, OJS_HEART=2, OJS_SPADE=3 }