ERROR

decompiled_code:
void __fastcall __noreturn ERROR(const char *a1)
{
fputs(a1, stderr);
fputc(10, stderr);
exit(2);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
fputs(a1, stderr);
fputc(10, stderr);
exit(2);
}

original_code:
void ERROR (char *msg) {
    fputs(msg, stderr) ;
    fputc('\n', stderr) ;
    exit(2) ;
}

canonical_original_code:
void ERROR(char *msg) {
    fputs(msg, stderr) ;
    fputc('\n', stderr) ;
    exit(2) ;
}

variable_types:
msg
char *


usage

repo: dandavison/shellfish

decompiled_code:
void __noreturn usage()
{
ERROR("lines -f linenumfile < inputfile ");
}

canonical_decompiled_code:
void __noreturn func8()
{
func7("lines -f linenumfile < inputfile ");
}

original_code:
void usage() {
    ERROR("lines -f linenumfile < inputfile ") ;
}

return_type: void


fseekerrormsg

decompiled_code:
void __noreturn fseekerrormsg()
{
ERROR(
"fseek error (Did you use a pipe and ask for non-monotonically increasing lines? You can't use a pipe in that case.) :");
}

canonical_decompiled_code:
void __noreturn func9()
{
func7(
"fseek error (Did you use a pipe and ask for non-monotonically increasing lines? You can't use a pipe in that case.) :");
}

original_code:
void fseekerrormsg() {
    ERROR("fseek error (Did you use a pipe and ask for non-monotonically increasing lines? You can't use a pipe in that case.) :") ;
}


eigen

decompiled_code:
void __fastcall eigen(__int64 a1, int a2, int a3, int a4, __int64 a5, __int64 a6, double a7)
{
void *v10; // r12
void *v11; // rbp
void *v12; // rbx
int v13[3]; // [rsp+Ch] [rbp-8Ch] BYREF
double v14; // [rsp+18h] [rbp-80h] BYREF
double v15; // [rsp+20h] [rbp-78h] BYREF
__int64 v16; // [rsp+28h] [rbp-70h] BYREF
__int64 v17; // [rsp+30h] [rbp-68h] BYREF
int v18; // [rsp+38h] [rbp-60h] BYREF
unsigned int v19; // [rsp+3Ch] [rbp-5Ch] BYREF
int v20; // [rsp+40h] [rbp-58h] BYREF
int v21; // [rsp+44h] [rbp-54h] BYREF
int v22; // [rsp+48h] [rbp-50h] BYREF
char v23[4]; // [rsp+4Ch] [rbp-4Ch] BYREF
int v24; // [rsp+50h] [rbp-48h] BYREF
int v25; // [rsp+54h] [rbp-44h] BYREF
int v26; // [rsp+58h] [rbp-40h] BYREF
char v27; // [rsp+5Dh] [rbp-3Bh] BYREF
char v28; // [rsp+5Eh] [rbp-3Ah] BYREF
char v29[57]; // [rsp+5Fh] [rbp-39h] BYREF

v13[0] = a2;
v29[0] = a4 == 0 ? 86 : 78;
v27 = 76;
v26 = a2;
v22 = a2;
dlamch(83);
v15 = a7;
if ( a3 <= 0 || a2 <= a3 )
{
v28 = 65;
v24 = -1;
v25 = -1;
a3 = a2;
}
else
{
v28 = 73;
v25 = a2 - a3 + 1;
v24 = a2;
}
v16 = LC0;
v17 = LC0;
v20 = -1;
v21 = -1;
dsyevr_(
v29,
&v28,
&v27,
v13,
a1,
&v26,
&v17,
&v16,
&v25,
&v24,
&v15,
v23,
a5,
a6,
&v22,
0LL,
&v14,
&v21,
&v18,
&v20,
&v19);
if ( v19 )
{
print_stdout("INFO = %d", v19);
eprintf("eigen: dsyevr returned with error code when computing optimal size of work arrays.\n");
}
v21 = (int)v14;
v20 = v18;
v10 = (void *)malloc_dan(8LL * (int)v14);
v11 = (void *)malloc_dan(4LL * v20);
v12 = (void *)malloc_dan(8LL * a3);
dsyevr_(
v29,
&v28,
&v27,
v13,
a1,
&v26,
&v17,
&v16,
&v25,
&v24,
&v15,
v23,
a5,
a6,
&v22,
v12,
v10,
&v21,
v11,
&v20,
&v19);
if ( v19 )
{
print_stdout("INFO = %d", v19);
eprintf("eigen: dsyevr returned with error code.\n");
}
free(v10);
free(v11);
free(v12);
}

original_code:
void eigen(double *A, int dim, int nvecs, bool values_only, double *evals, double *evecs) {
    extern void dsyevr_(char *JOBZp, char *RANGEp, char *UPLOp, int *Np,
   double *A, int *LDAp, double *VLp, double *VUp,
   int *ILp, int *IUp, double *ABSTOLp, int *Mp,
   double *W, double *Z, int *LDZp, int *ISUPPZ,
   double *WORK, int *LWORKp, int *IWORK, int *LIWORKp,
   int *INFOp);
    char
 JOBZ = values_only ? 'N' : 'V',
 RANGE,
 UPLO = 'L' ;
    int
 LDA = dim,
 IL, IU,
 M,
 LDZ = dim,
 *ISUPPZ,
 LWORK,
 *IWORK,
 LIWORK,
 INFO,
 tmp_int ;
    double
 VL, VU,
 ABSTOL=dlamch('S'),
 *WORK,
 tmp_double ;
    if (nvecs > 0 && nvecs < dim) {
 RANGE = 'I' ;
 IL = dim - nvecs + 1;
 IU = dim ;
    }
    else {
 RANGE = 'A' ;
 nvecs = dim ;
 IL = IU = -1.0 ;
    }
    VL = VU = -1.0 ;
    LWORK = LIWORK = -1 ;
       dsyevr_(&JOBZ, &RANGE, &UPLO, &dim, A, &LDA, &VL, &VU,
     &IL, &IU, &ABSTOL, &M, evals, evecs, &LDZ, ISUPPZ,
     &tmp_double, &LWORK, &tmp_int, &LIWORK, &INFO);
    if(INFO != 0) {
 print_stdout("INFO = %d", INFO) ;
 eprintf("eigen: dsyevr returned with error code when computing optimal size of work arrays.\n") ;
    }
    LWORK = (int) tmp_double ;
    LIWORK = tmp_int ;
    WORK = (double *) malloc_dan((LWORK) * sizeof(double)) ;
    IWORK = (int *) malloc_dan((LIWORK) * sizeof(int)) ;
    ISUPPZ = (int *) malloc_dan((2 * nvecs) * sizeof(int)) ;
    dsyevr_(&JOBZ, &RANGE, &UPLO, &dim, A, &LDA, &VL, &VU,
     &IL, &IU, &ABSTOL, &M, evals, evecs, &LDZ, ISUPPZ,
     WORK, &LWORK, IWORK, &LIWORK, &INFO);
    if(INFO != 0) {
 print_stdout("INFO = %d", INFO) ;
 eprintf("eigen: dsyevr returned with error code.\n") ;
    }
    free(WORK) ;
    free(IWORK) ;
    free(ISUPPZ) ;
}

canonical_original_code:
void eigen(double *A, int dim, int nvecs, int values_only, double *evals, double *evecs) {
    extern void dsyevr_(char *JOBZp, char *RANGEp, char *UPLOp, int *Np, double *A, int *LDAp, double *VLp, double *VUp, int *ILp, int *IUp, double *ABSTOLp, int *Mp, double *W, double *Z, int *LDZp, int *ISUPPZ, double *WORK, int *LWORKp, int *IWORK, int *LIWORKp, int *INFOp);
    char JOBZ = values_only ? 'N' : 'V'; char RANGE; char UPLO = 'L';
    int LDA = dim; int IL; int IU; int M; int LDZ = dim; int *ISUPPZ; int LWORK; int *IWORK; int LIWORK; int INFO; int tmp_int;
    double VL; double VU; double ABSTOL = dlamch('S'); double *WORK; double tmp_double;
    if (nvecs > 0 && nvecs < dim) {
 RANGE = 'I' ;
 IL = dim - nvecs + 1;
 IU = dim ;
    }
    else {
 RANGE = 'A' ;
 nvecs = dim ;
 IL = IU = -1.0 ;
    }
    VL = VU = -1.0 ;
    LWORK = LIWORK = -1 ;
       dsyevr_(&JOBZ, &RANGE, &UPLO, &dim, A, &LDA, &VL, &VU,
     &IL, &IU, &ABSTOL, &M, evals, evecs, &LDZ, ISUPPZ,
     &tmp_double, &LWORK, &tmp_int, &LIWORK, &INFO);
    if(INFO != 0) {
 print_stdout("INFO = %d", INFO) ;
 eprintf("eigen: dsyevr returned with error code when computing optimal size of work arrays.\n") ;
    }
    LWORK = (int) tmp_double ;
    LIWORK = tmp_int ;
    WORK = (double *) malloc_dan((LWORK) * sizeof(double)) ;
    IWORK = (int *) malloc_dan((LIWORK) * sizeof(int)) ;
    ISUPPZ = (int *) malloc_dan((2 * nvecs) * sizeof(int)) ;
    dsyevr_(&JOBZ, &RANGE, &UPLO, &dim, A, &LDA, &VL, &VU,
     &IL, &IU, &ABSTOL, &M, evals, evecs, &LDZ, ISUPPZ,
     WORK, &LWORK, IWORK, &LIWORK, &INFO);
    if(INFO != 0) {
 print_stdout("INFO = %d", INFO) ;
 eprintf("eigen: dsyevr returned with error code.\n") ;
    }
    free(WORK) ;
    free(IWORK) ;
    free(ISUPPZ) ;
}

variable_types:
A
double *

variable_types: dim int

variable_types: nvecs int

variable_types:
evals
double *

variable_types:
evecs
double *

variable_types: void (char *JOBZp, char *RANGEp, char *UPLOp, int *Np, double *A, int *LDAp, double *VLp, double *VUp, int *ILp, int *IUp, double *ABSTOLp, int *Mp, double *W, double *Z, int *LDZp, int *ISUPPZ, double *WORK, int *LWORKp, int *IWORK, int *LIWORKp, int *INFOp)

variable_types: JOBZ char

variable_types: RANGE char

variable_types: UPLO char

variable_types: LDA int

variable_types: IL int

variable_types: IU int

variable_types: M int

variable_types: LDZ int

variable_types:
ISUPPZ
int *

variable_types: LWORK int

variable_types:
IWORK
int *

variable_types: LIWORK int

variable_types: INFO int

variable_types: VL double

variable_types: VU double

variable_types: ABSTOL double

variable_types:
WORK
double *


XTX

decompiled_code:
__int64 __fastcall XTX(__int64 a1, unsigned int a2, unsigned int a3, double a4)
{
__int64 v4; // rbx
__int64 v5; // rbp

v4 = a3;
v5 = calloc_dan((int)(a3 * a3), 8LL);
if ( !v5 )
eprintf("XTX alloc error\n");
cblas_dsyrk(102LL, 122LL, 112LL, (unsigned int)v4, a2, a1, a4, 0.0, a2, v5, v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, unsigned int a3, double a4)
{
__int64 v4; // rbx
__int64 v5; // rbp

v4 = a3;
v5 = calloc_dan((int)(a3 * a3), 8LL);
if ( !v5 )
eprintf("XTX alloc error\n");
cblas_dsyrk(102LL, 122LL, 112LL, (unsigned int)v4, a2, a1, a4, 0.0, a2, v5, v4);
return v5;
}

original_code:
double *XTX(double *X, int nrow, int ncol, double alpha) {
    double *ans = (double *) calloc_dan((ncol * ncol), sizeof(double)) ; if(ans == ((void *)0)) eprintf("XTX alloc error\n") ;
    cblas_dsyrk(CblasColMajor,
  CblasLower,
  CblasTrans,
  ncol,
  nrow,
  alpha,
  X,
  nrow,
  0.0,
  ans,
  ncol) ;
    return ans ;
}

canonical_original_code:
double *XTX(double *X, int nrow, int ncol, double alpha) {
    double *ans = (double *) calloc_dan((ncol * ncol), sizeof(double)); if(ans == ((void *)0)) eprintf("XTX alloc error\n") ;
    cblas_dsyrk(CblasColMajor,
  CblasLower,
  CblasTrans,
  ncol,
  nrow,
  alpha,
  X,
  nrow,
  0.0,
  ans,
  ncol) ;
    return ans ;
}

variable_types:
X
double *

variable_types: nrow int

variable_types: ncol int

variable_types: alpha double

variable_types:
ans
double *

return_type: double *


decompiled_code:
__int64 __fastcall matprod_general(__int64 a1, __int64 a2, int a3, int a4, unsigned int a5, unsigned int a6, unsigned int a7, unsigned int a8, __int64 a9)
{
__int64 v11; // rcx
__int64 v12; // r8
unsigned int v13; // er9
unsigned int v14; // er10

v11 = a6;
v12 = a8;
v13 = a5;
if ( !a3 )
{
v13 = v11;
v11 = a5;
}
if ( a4 )
{
if ( v13 == a8 )
{
v12 = a7;
v14 = 112;
goto LABEL_6;
}
LABEL_8:
print_stdout("matprod non-conformable error!\nncolL = %d\tnrowR = %d\n", v13, (unsigned int)v12);
exit(1);
}
if ( v13 != a7 )
{
LODWORD(v12) = a7;
goto LABEL_8;
}
v14 = 111;
LABEL_6:
cblas_dgemm(102LL, 111 - ((unsigned int)(a3 == 0) - 1), v14, v11, v12);
return a9;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3, int a4, unsigned int a5, unsigned int a6, unsigned int a7, unsigned int a8, __int64 a9)
{
__int64 v11; // rcx
__int64 v12; // r8
unsigned int v13; // er9
unsigned int v14; // er10

v11 = a6;
v12 = a8;
v13 = a5;
if ( !a3 )
{
v13 = v11;
v11 = a5;
}
if ( a4 )
{
if ( v13 == a8 )
{
v12 = a7;
v14 = 112;
goto LABEL_6;
}
LABEL_8:
print_stdout("matprod non-conformable error!\nncolL = %d\tnrowR = %d\n", v13, (unsigned int)v12);
exit(1);
}
if ( v13 != a7 )
{
LODWORD(v12) = a7;
goto LABEL_8;
}
v14 = 111;
LABEL_6:
cblas_dgemm(102LL, 111 - ((unsigned int)(a3 == 0) - 1), v14, v11, v12);
return a9;
}

original_code:
double *matprod_general(double *A, double *B, bool Atranspose, bool Btranspose,
   int nrowA, int ncolA, int nrowB, int ncolB, double alpha, double beta, double *C) {
    int nrowL, ncolL,
 nrowR, ncolR ;
    int K ;
    if(Atranspose) {
 nrowL = ncolA ;
 ncolL = nrowA ;
    }
    else {
 nrowL = nrowA ;
 ncolL = ncolA ;
    }
    if(Btranspose) {
 nrowR = ncolB ;
 ncolR = nrowB ;
    }
    else {
 nrowR = nrowB ;
 ncolR = ncolB ;
    }
    if(ncolL != nrowR) {
 print_stdout("matprod non-conformable error!\nncolL = %d\tnrowR = %d\n", ncolL, nrowR) ;
 exit(1) ;
    }
    K = ncolL ;
    cblas_dgemm(CblasColMajor,
  Atranspose ? CblasTrans : CblasNoTrans,
  Btranspose ? CblasTrans : CblasNoTrans,
  nrowL,
  ncolR,
  K,
  alpha,
  A,
  nrowA,
  B,
  nrowB,
  beta,
  C,
  nrowL
  ) ;
    return C ;
}

canonical_original_code:
double *matprod_general(double *A, double *B, int Atranspose, int Btranspose, int nrowA, int ncolA, int nrowB, int ncolB, double alpha, double beta, double *C) {
    int nrowL; int ncolL; int nrowR; int ncolR;
    int K;
    if(Atranspose) {
 nrowL = ncolA ;
 ncolL = nrowA ;
    }
    else {
 nrowL = nrowA ;
 ncolL = ncolA ;
    }
    if(Btranspose) {
 nrowR = ncolB ;
 ncolR = nrowB ;
    }
    else {
 nrowR = nrowB ;
 ncolR = ncolB ;
    }
    if(ncolL != nrowR) {
 print_stdout("matprod non-conformable error!\nncolL = %d\tnrowR = %d\n", ncolL, nrowR) ;
 exit(1) ;
    }
    K = ncolL ;
    cblas_dgemm(CblasColMajor,
  Atranspose ? CblasTrans : CblasNoTrans,
  Btranspose ? CblasTrans : CblasNoTrans,
  nrowL,
  ncolR,
  K,
  alpha,
  A,
  nrowA,
  B,
  nrowB,
  beta,
  C,
  nrowL
  ) ;
    return C ;
}

variable_types:
A
double *

variable_types:
B
double *

variable_types: Atranspose int

variable_types: Btranspose int

variable_types: nrowA int

variable_types: ncolA int

variable_types: nrowB int

variable_types: ncolB int

variable_types: beta double

variable_types:
C
double *

variable_types: nrowL int

variable_types: ncolL int

variable_types: nrowR int

variable_types: ncolR int

variable_types: K int


matprod

decompiled_code:
__int64 __fastcall matprod(__int64 a1, __int64 a2, int a3, int a4, unsigned int a5, unsigned int a6, unsigned int a7, unsigned int a8)
{
unsigned int v12; // er12
__int64 v14; // rsi
unsigned int v15; // edi
unsigned int v16; // eax
__int64 v17; // rdx
__int64 v18; // rax

v12 = a5;
if ( a3 )
{
v14 = a5;
v15 = a6;
}
else
{
v14 = a6;
v15 = a5;
}
if ( a4 )
{
v16 = a7;
v17 = a8;
}
else
{
v16 = a8;
v17 = a7;
}
if ( (_DWORD)v14 != (_DWORD)v17 )
{
print_stdout("matprod non-conformable error!\nncolL = %d\tnrowR = %d\n", v14, v17);
exit(1);
}
v18 = calloc_dan((int)(v16 * v15), 8LL);
return matprod_general(a1, a2, a3, a4, v12, a6, a7, a8, v18);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, int a3, int a4, unsigned int a5, unsigned int a6, unsigned int a7, unsigned int a8)
{
unsigned int v12; // er12
__int64 v14; // rsi
unsigned int v15; // edi
unsigned int v16; // eax
__int64 v17; // rdx
__int64 v18; // rax

v12 = a5;
if ( a3 )
{
v14 = a5;
v15 = a6;
}
else
{
v14 = a6;
v15 = a5;
}
if ( a4 )
{
v16 = a7;
v17 = a8;
}
else
{
v16 = a8;
v17 = a7;
}
if ( (_DWORD)v14 != (_DWORD)v17 )
{
print_stdout("matprod non-conformable error!\nncolL = %d\tnrowR = %d\n", v14, v17);
exit(1);
}
v18 = calloc_dan((int)(v16 * v15), 8LL);
return func3(a1, a2, a3, a4, v12, a6, a7, a8, v18);
}

original_code:
double *matprod(double *A, double *B, bool Atranspose, bool Btranspose,
  int nrowA, int ncolA, int nrowB, int ncolB, double alpha) {
    int nrowL, ncolL,
 nrowR, ncolR ;
    int K ;
    double *ans, beta ;
    if(Atranspose) {
 nrowL = ncolA ;
 ncolL = nrowA ;
    }
    else {
 nrowL = nrowA ;
 ncolL = ncolA ;
    }
    if(Btranspose) {
 nrowR = ncolB ;
 ncolR = nrowB ;
    }
    else {
 nrowR = nrowB ;
 ncolR = ncolB ;
    }
    if(ncolL != nrowR) {
 print_stdout("matprod non-conformable error!\nncolL = %d\tnrowR = %d\n", ncolL, nrowR) ;
 exit(1) ;
    }
    K = ncolL ;
    ans = (double *) calloc_dan((nrowL * ncolR), sizeof(double)) ;
    beta = 0.0 ;
    return matprod_general(A, B, Atranspose, Btranspose, nrowA, ncolA, nrowB, ncolB, alpha, beta, ans) ;
    eprintf("matprod now redefined as call to matprod general") ;
    return ans ;
}

canonical_original_code:
double *matprod(double *A, double *B, int Atranspose, int Btranspose, int nrowA, int ncolA, int nrowB, int ncolB, double alpha) {
    int nrowL; int ncolL; int nrowR; int ncolR;
    int K;
    double *ans; double beta;
    if(Atranspose) {
 nrowL = ncolA ;
 ncolL = nrowA ;
    }
    else {
 nrowL = nrowA ;
 ncolL = ncolA ;
    }
    if(Btranspose) {
 nrowR = ncolB ;
 ncolR = nrowB ;
    }
    else {
 nrowR = nrowB ;
 ncolR = ncolB ;
    }
    if(ncolL != nrowR) {
 print_stdout("matprod non-conformable error!\nncolL = %d\tnrowR = %d\n", ncolL, nrowR) ;
 exit(1) ;
    }
    K = ncolL ;
    ans = (double *) calloc_dan((nrowL * ncolR), sizeof(double)) ;
    beta = 0.0 ;
    return matprod_general(A, B, Atranspose, Btranspose, nrowA, ncolA, nrowB, ncolB, alpha, beta, ans) ;
    eprintf("matprod now redefined as call to matprod general") ;
    return ans ;
}

variable_types: alpha double


variable_types:
A
double []

variable_types:
B
double []

variable_types:
ans
double *

return_type: int


original_code:
int main1() {
    double *ans, *evecs, *evals ;
    double X[] = {
 3, 1, 3,
 1, 5, 9,
 2, 6, 5,
 1.3, 2.9, 0.01
    };
    double Y[] = {
 0.5, .998, 12.1,
 11.2, 7.3, 8.995
    } ;
    double Z[] = {
 1, 2, 3,
 4, 5, 6,
 7, 8, 9
    } ;
    printf("X\n") ;
    write_matrix_double(X, stdout, 3, 4, "%.3lf ") ;
    putchar('\n') ;
    ans = XTX(X, 3, 4, 1.0) ;
    printf("XTX\n") ;
    write_matrix_double(ans, stdout, 4, 4, "%.5lf ") ;
    free(ans) ;
    putchar('\n') ;
    printf("t(X) %%*%% X\n") ;
    ans = matprod(X, X, 1, 0, 3, 4, 3, 4, 1.0) ;
    write_matrix_double(ans, stdout, 4, 4, "%.5lf ") ;
    free(ans) ;
    printf("Y\n") ;
    write_matrix_double(Y, stdout, 3, 2, "%.3lf ") ;
    putchar('\n') ;
    printf("t(X) %%*%% Y\n") ;
    ans = matprod(X, Y, 1, 0, 3, 4, 3, 2, 1.0) ;
    write_matrix_double(ans, stdout, 4, 2, "%.5lf ") ;
    printf("Z\n") ;
    write_matrix_double(Z, stdout, 3, 3, "%.3lf ") ;
    evals = (double *) malloc_dan((3) * sizeof(double)) ;
    evecs = (double *) malloc_dan((3*3) * sizeof(double)) ;
    eigen(Z, 3, 3, 0, evals, evecs) ;
    print_stdout("eigenvalues of Z\n\n") ;
    print_stdout("eigenvectors of Z\n\n") ;
    return 0 ;
}

canonical_original_code:
int main1() {
    double *ans; double *evecs; double *evals;
    double X[] = {
 3, 1, 3,
 1, 5, 9,
 2, 6, 5,
 1.3, 2.9, 0.01
    };
    double Y[] = {
 0.5, .998, 12.1,
 11.2, 7.3, 8.995
    };
    double Z[] = {
 1, 2, 3,
 4, 5, 6,
 7, 8, 9
    };
    printf("X\n") ;
    write_matrix_double(X, stdout, 3, 4, "%.3lf ") ;
    putchar('\n') ;
    ans = XTX(X, 3, 4, 1.0) ;
    printf("XTX\n") ;
    write_matrix_double(ans, stdout, 4, 4, "%.5lf ") ;
    free(ans) ;
    putchar('\n') ;
    printf("t(X) %%*%% X\n") ;
    ans = matprod(X, X, 1, 0, 3, 4, 3, 4, 1.0) ;
    write_matrix_double(ans, stdout, 4, 4, "%.5lf ") ;
    free(ans) ;
    printf("Y\n") ;
    write_matrix_double(Y, stdout, 3, 2, "%.3lf ") ;
    putchar('\n') ;
    printf("t(X) %%*%% Y\n") ;
    ans = matprod(X, Y, 1, 0, 3, 4, 3, 2, 1.0) ;
    write_matrix_double(ans, stdout, 4, 2, "%.5lf ") ;
    printf("Z\n") ;
    write_matrix_double(Z, stdout, 3, 3, "%.3lf ") ;
    evals = (double *) malloc_dan((3) * sizeof(double)) ;
    evecs = (double *) malloc_dan((3*3) * sizeof(double)) ;
    eigen(Z, 3, 3, 0, evals, evecs) ;
    print_stdout("eigenvalues of Z\n\n") ;
    print_stdout("eigenvectors of Z\n\n") ;
    return 0 ;
}

variable_types:
evecs
double *

variable_types:
evals
double *

variable_types:
X
double []

variable_types:
Y
double []

variable_types:
Z
double []


repo: danidomi/fteqcc

decompiled_code:
void __fastcall Hash_InitTable(__int64 a1, int a2, __int64 a3)
{
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
}

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

original_code:
void Hash_InitTable(hashtable_t *table, unsigned int numbucks, void *mem)
{
 table->numbuckets = numbucks;
 table->bucket = (bucket_t **)mem;
}

canonical_original_code:
void Hash_InitTable(struct hashtable_s *table, unsigned int numbucks, void *mem)
{
 table->numbuckets = numbucks;
 table->bucket = (struct bucket_s **)mem;
}

variable_types: struct hashtable_s { unsigned int numbuckets; struct bucket_s { void *data; union { char *string; unsigned int value; } key; struct bucket_s *next; } **bucket; } *

variable_types:
numbucks
unsigned int

variable_types:
mem
void *

user_defined_types: struct hashtable_s { unsigned int numbuckets; struct bucket_s **bucket; }


decompiled_code:
__int64 __fastcall Hash_Key(char *a1, unsigned int a2)
{
char v2; // dl
unsigned int v3; // eax

v2 = *a1;
if ( *a1 )
{
v3 = 0;
do
{
v3 += (v3 >> 28) + v2 + 8 * v3;
v2 = *++a1;
}
while ( *a1 );
}
else
{
v3 = 0;
}
return v3 % a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, unsigned int a2)
{
char v2; // dl
unsigned int v3; // eax

v2 = *a1;
if ( *a1 )
{
v3 = 0;
do
{
v3 += (v3 >> 28) + v2 + 8 * v3;
v2 = *++a1;
}
while ( *a1 );
}
else
{
v3 = 0;
}
return v3 % a2;
}

original_code:
unsigned int Hash_Key(const char *name, unsigned int modulus)
{
 unsigned int key;
 for (key=0;*name; name++)
  key += ((key<<3) + (key>>28) + *name);
 return (key%modulus);
}

canonical_original_code:
unsigned int Hash_Key(char *name, unsigned int modulus)
{
 unsigned int key;
 for (key=0;*name; name++)
  key += ((key<<3) + (key>>28) + *name);
 return (key%modulus);
}

variable_types:
name
char *

variable_types:
modulus
unsigned int

variable_types:
key
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall Hash_KeyInsensative(char *a1, unsigned int a2)
{
char v2; // dl
unsigned int v3; // eax
int v4; // eax

v2 = *a1;
if ( *a1 )
{
v3 = 0;
do
{
if ( (unsigned __int8)(v2 - 65) > 0x19u )
v4 = (v3 >> 28) + 8 * v3 + v3;
else
v4 = 9 * v3 + 32 + (v3 >> 28);
v3 = v2 + v4;
v2 = *++a1;
}
while ( *a1 );
}
else
{
v3 = 0;
}
return v3 % a2;
}

original_code:
unsigned int Hash_KeyInsensative(const char *name, unsigned int modulus)
{
 unsigned int key;
 for (key=0;*name; name++)
 {
  if (*name >= 'A' && *name <= 'Z')
   key += ((key<<3) + (key>>28) + (*name-'A'+'a'));
  else
   key += ((key<<3) + (key>>28) + *name);
 }
 return (key%modulus);
}

canonical_original_code:
unsigned int Hash_KeyInsensative(char *name, unsigned int modulus)
{
 unsigned int key;
 for (key=0;*name; name++)
 {
  if (*name >= 'A' && *name <= 'Z')
   key += ((key<<3) + (key>>28) + (*name-'A'+'a'));
  else
   key += ((key<<3) + (key>>28) + *name);
 }
 return (key%modulus);
}


original_code:
void *Hash_AddKey(hashtable_t *table, unsigned int key, void *data, bucket_t *buck)
{
 unsigned int bucknum = key%table->numbuckets;
 buck->data = data;
 buck->key.value = key;
 buck->next = table->bucket[bucknum];
 table->bucket[bucknum] = buck;
 return buck;
}

canonical_original_code:
void *Hash_AddKey(struct hashtable_s *table, unsigned int key, void *data, struct bucket_s *buck)
{
 unsigned int bucknum = key%table->numbuckets;
 buck->data = data;
 buck->key.value = key;
 buck->next = table->bucket[bucknum];
 table->bucket[bucknum] = buck;
 return buck;
}

variable_types:
data
void *

variable_types:
buck
struct bucket_s *

variable_types:
bucknum
unsigned int

return_type: void *

user_defined_types: struct bucket_s { void *data; union { char *string; unsigned int value; } key; struct bucket_s *next; }


original_code:
void Hash_Remove(hashtable_t *table, const char *name)
{
 unsigned int bucknum = Hash_Key(name, table->numbuckets);
 bucket_t *buck;
 buck = table->bucket[bucknum];
 if (!(((*name)!=(*buck->key.string)) || strcmp(name+1,buck->key.string+1)))
 {
  table->bucket[bucknum] = buck->next;
  return;
 }
 while(buck->next)
 {
  if (!(((*name)!=(*buck->next->key.string)) || strcmp(name+1,buck->next->key.string+1)))
  {
   buck->next = buck->next->next;
   return;
  }
  buck = buck->next;
 }
 return;
}

canonical_original_code:
void Hash_Remove(struct hashtable_s *table, char *name)
{
 unsigned int bucknum = Hash_Key(name, table->numbuckets);
 struct bucket_s *buck;
 buck = table->bucket[bucknum];
 if (!(((*name)!=(*buck->key.string)) || strcmp(name+1,buck->key.string+1)))
 {
  table->bucket[bucknum] = buck->next;
  return;
 }
 while(buck->next)
 {
  if (!(((*name)!=(*buck->next->key.string)) || strcmp(name+1,buck->next->key.string+1)))
  {
   buck->next = buck->next->next;
   return;
  }
  buck = buck->next;
 }
 return;
}

variable_types: struct bucket_s { void *data; union { char *string; unsigned int value; } key; struct bucket_s *next; } *


original_code:
void Hash_RemoveData(hashtable_t *table, const char *name, void *data)
{
 unsigned int bucknum = Hash_Key(name, table->numbuckets);
 bucket_t *buck;
 buck = table->bucket[bucknum];
 if (buck->data == data)
  if (!(((*name)!=(*buck->key.string)) || strcmp(name+1,buck->key.string+1)))
  {
   table->bucket[bucknum] = buck->next;
   return;
  }
 while(buck->next)
 {
  if (buck->next->data == data)
   if (!(((*name)!=(*buck->next->key.string)) || strcmp(name+1,buck->next->key.string+1)))
   {
    buck->next = buck->next->next;
    return;
   }
  buck = buck->next;
 }
 return;
}

canonical_original_code:
void Hash_RemoveData(struct hashtable_s *table, char *name, void *data)
{
 unsigned int bucknum = Hash_Key(name, table->numbuckets);
 struct bucket_s *buck;
 buck = table->bucket[bucknum];
 if (buck->data == data)
  if (!(((*name)!=(*buck->key.string)) || strcmp(name+1,buck->key.string+1)))
  {
   table->bucket[bucknum] = buck->next;
   return;
  }
 while(buck->next)
 {
  if (buck->next->data == data)
   if (!(((*name)!=(*buck->next->key.string)) || strcmp(name+1,buck->next->key.string+1)))
   {
    buck->next = buck->next->next;
    return;
   }
  buck = buck->next;
 }
 return;
}


qccHunkAlloc

decompiled_code:
char *__fastcall qccHunkAlloc(__int64 a1)
{
unsigned __int64 v1; // rbx

v1 = (a1 + 7) & 0xFFFFFFFFFFFFFFF8LL;
qccalloced += (a1 + 7) & 0xFFFFFFF8;
if ( qccalloced > qcchunksize )
QCC_Error(56LL, "Compile hunk was filled");
memset((char *)qcchunk + qccalloced - v1, 0, v1);
return (char *)qcchunk + qccalloced - v1;
}

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

v1 = (a1 + 7) & 0xFFFFFFFFFFFFFFF8LL;
qccalloced += (a1 + 7) & 0xFFFFFFF8;
if ( qccalloced > qcchunksize )
QCC_Error(56LL, "Compile hunk was filled");
memset((char *)qcchunk + qccalloced - v1, 0, v1);
return (char *)qcchunk + qccalloced - v1;
}

original_code:
void *qccHunkAlloc(size_t mem)
{
 mem = (mem + 7)&~7;
 qccalloced+=mem;
 if (qccalloced > qcchunksize)
  QCC_Error(ERR_INTERNAL, "Compile hunk was filled");
 memset(qcchunk+qccalloced-mem, 0, mem);
 return qcchunk+qccalloced-mem;
}

canonical_original_code:
void *qccHunkAlloc(unsigned long mem)
{
 mem = (mem + 7)&~7;
 qccalloced+=mem;
 if (qccalloced > qcchunksize)
  QCC_Error(ERR_INTERNAL, "Compile hunk was filled");
 memset(qcchunk+qccalloced-mem, 0, mem);
 return qcchunk+qccalloced-mem;
}

variable_types:
mem
unsigned long


qccClearHunk

decompiled_code:
void qccClearHunk()
{
if ( qcchunk )
{
free(qcchunk);
qcchunk = 0LL;
}
}

canonical_decompiled_code:
void func1()
{
if ( qcchunk )
{
free(qcchunk);
qcchunk = 0LL;
}
}

original_code:
void qccClearHunk(void)
{
 if (qcchunk)
 {
  free(qcchunk);
  qcchunk=((void *)0);
 }
}

canonical_original_code:
void qccClearHunk()
{
 if (qcchunk)
 {
  free(qcchunk);
  qcchunk=((void *)0);
 }
}


PostCompile

decompiled_code:
void PostCompile()
{
if ( !qccpersisthunk )
qccClearHunk();
if ( asmfile )
{
fclose(asmfile);
asmfile = 0LL;
}
}

canonical_decompiled_code:
void func2()
{
if ( !qccpersisthunk )
func1();
if ( asmfile )
{
fclose(asmfile);
asmfile = 0LL;
}
}

original_code:
void PostCompile(void)
{
 if (!qccpersisthunk)
  qccClearHunk();
 if (asmfile)
 {
  fclose(asmfile);
  asmfile = ((void *)0);
 }
}

canonical_original_code:
void PostCompile()
{
 if (!qccpersisthunk)
  qccClearHunk();
 if (asmfile)
 {
  fclose(asmfile);
  asmfile = ((void *)0);
 }
}


PreCompile

decompiled_code:
_BOOL8 PreCompile()
{
void *v0; // rax
int v1; // ebp
int v2; // ebx

QCC_PR_ResetErrorScope();
qccClearHunk();
qcc_gamedir = 0;
qcchunksize = 0x8000000;
v0 = malloc(0x8000000uLL);
qcchunk = v0;
if ( !v0 )
{
v1 = 0x8000000;
do
{
v2 = v1;
v1 /= 2;
qcchunksize = v1;
v0 = malloc(v1);
qcchunk = v0;
}
while ( !v0 && v2 > 16777217 );
}
qccalloced = 0;
return v0 != 0LL;
}

canonical_decompiled_code:
_BOOL8 func3()
{
void *v0; // rax
int v1; // ebp
int v2; // ebx

QCC_PR_ResetErrorScope();
func1();
qcc_gamedir = 0;
qcchunksize = 0x8000000;
v0 = malloc(0x8000000uLL);
qcchunk = v0;
if ( !v0 )
{
v1 = 0x8000000;
do
{
v2 = v1;
v1 /= 2;
qcchunksize = v1;
v0 = malloc(v1);
qcchunk = v0;
}
while ( !v0 && v2 > 16777217 );
}
qccalloced = 0;
return v0 != 0LL;
}

original_code:
pbool PreCompile(void)
{
 QCC_PR_ResetErrorScope();
 qccClearHunk();
 strcpy(qcc_gamedir, "");
 qcchunk = malloc(qcchunksize=128*1024*1024);
 while(!qcchunk && qcchunksize > 8*1024*1024)
 {
  qcchunksize /= 2;
  qcchunk = malloc(qcchunksize);
 }
 qccalloced=0;
 return !!qcchunk;
}

canonical_original_code:
int PreCompile()
{
 QCC_PR_ResetErrorScope();
 qccClearHunk();
 strcpy(qcc_gamedir, "");
 qcchunk = malloc(qcchunksize=128*1024*1024);
 while(!qcchunk && qcchunksize > 8*1024*1024)
 {
  qcchunksize /= 2;
  qcchunk = malloc(qcchunksize);
 }
 qccalloced=0;
 return !!qcchunk;
}


decompiled_code:
__int64 __fastcall QC_strncasecmp(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v5; // r8
__int64 i; // rcx
unsigned int v7; // esi
int v9; // eax
unsigned int v10; // edi
char v11; // dl

v5 = a3;
for ( i = 0LL; ; ++i )
{
v10 = *(char *)(a1 + i);
v11 = *(_BYTE *)(a2 + i);
v7 = v11;
if ( i == v5 )
return 0;
if ( v10 == v11 )
goto LABEL_8;
if ( v10 - 97 > 0x19 )
break;
v10 -= 32;
if ( (unsigned int)(v11 - 97) <= 0x19 )
goto LABEL_6;
v9 = v11;
v7 = v10;
LABEL_7:
if ( v9 != v7 )
return (unsigned int)-1;
LABEL_8:
if ( !v7 )
return v7;
}
if ( (unsigned int)(v11 - 97) <= 0x19 )
{
LABEL_6:
v9 = v11 - 32;
v7 = v10;
goto LABEL_7;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v5; // r8
__int64 i; // rcx
unsigned int v7; // esi
int v9; // eax
unsigned int v10; // edi
char v11; // dl

v5 = a3;
for ( i = 0LL; ; ++i )
{
v10 = *(char *)(a1 + i);
v11 = *(_BYTE *)(a2 + i);
v7 = v11;
if ( i == v5 )
return 0;
if ( v10 == v11 )
goto LABEL_8;
if ( v10 - 97 > 0x19 )
break;
v10 -= 32;
if ( (unsigned int)(v11 - 97) <= 0x19 )
goto LABEL_6;
v9 = v11;
v7 = v10;
LABEL_7:
if ( v9 != v7 )
return (unsigned int)-1;
LABEL_8:
if ( !v7 )
return v7;
}
if ( (unsigned int)(v11 - 97) <= 0x19 )
{
LABEL_6:
v9 = v11 - 32;
v7 = v10;
goto LABEL_7;
}
return (unsigned int)-1;
}

variable_types: n int


editbadfile

decompiled_code:
char *__fastcall editbadfile(char *src, int a2)
{
char *result; // rax

result = strcpy(&errorfile, src);
errorline = a2;
return result;
}

canonical_decompiled_code:
char *__fastcall func9(char *src, int a2)
{
char *result; // rax

result = strcpy(&errorfile, src);
errorline = a2;
return result;
}

original_code:
void editbadfile(char *fname, int line)
{
 strcpy(errorfile, fname);
 errorline = line;
}

variable_types:
fname
char *

variable_types: line int


decompiled_code:
_BOOL8 __fastcall QC_decodeMethodSupported(unsigned int a1)
{
return a1 <= 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned int a1)
{
return a1 <= 1;
}

original_code:
pbool QC_decodeMethodSupported(int method)
{
 if (method == 0)
  return true;
 if (method == 1)
  return true;
 if (method == 2)
 {
 }
 return false;
}

canonical_original_code:
int QC_decodeMethodSupported(int method)
{
 if (method == 0)
  return true;
 if (method == 1)
  return true;
 if (method == 2)
 {
 }
 return false;
}

variable_types: method int


decompiled_code:
__int64 Sys_Error(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(msg_1, 0x7FFuLL, format, arg);
return QCC_Error(56LL, "%s", msg_1);
}

canonical_decompiled_code:
__int64 func3(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(msg_1, 0x7FFuLL, format, arg);
return QCC_Error(56LL, "%s", msg_1);
}

original_code:
void Sys_Error(const char *text, ...)
{
 va_list argptr;
 static char msg[2048];
 __builtin_va_start(argptr,text);
 vsnprintf (msg,sizeof(msg)-1, text,argptr);
 __builtin_va_end(argptr);
 QCC_Error(ERR_INTERNAL, "%s", msg);
}

canonical_original_code:
void Sys_Error(char *text, ...)
{
 __builtin_va_list argptr;
 static char msg[2048];
 __builtin_va_start(argptr,text);
 vsnprintf (msg,sizeof(msg)-1, text,argptr);
 __builtin_va_end(argptr);
 QCC_Error(ERR_INTERNAL, "%s", msg);
}

variable_types:
text
char *

variable_types:
msg
char [2048]


logprintf

decompiled_code:
__int64 logprintf(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(string_0, 0x400uLL, format, arg);
printf("%s", string_0);
if ( logfile )
fputs(string_0, logfile);
return 0LL;
}

canonical_decompiled_code:
__int64 func4(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(string_0, 0x400uLL, format, arg);
printf("%s", string_0);
if ( logfile )
fputs(string_0, logfile);
return 0LL;
}

original_code:
int logprintf(const char *format, ...)
{
 va_list argptr;
 static char string[1024];
 __builtin_va_start(argptr,format);
 vsnprintf (string,sizeof(string), format,argptr);
 __builtin_va_end(argptr);
 printf("%s", string);
 if (logfile)
  fputs(string, logfile);
 return 0;
}

canonical_original_code:
int logprintf(char *format, ...)
{
 __builtin_va_list argptr;
 static char string[1024];
 __builtin_va_start(argptr,format);
 vsnprintf (string,sizeof(string), format,argptr);
 __builtin_va_end(argptr);
 printf("%s", string);
 if (logfile)
  fputs(string, logfile);
 return 0;
}

variable_types:
format
char *

variable_types:
string
char [1024]


decompiled_code:
__int64 __fastcall char2pset(char a1)
{
__int64 v1; // rax

v1 = 0LL;
while ( color_table[v1] != a1 )
{
if ( ++v1 == 64 )
return 0LL;
}
return 1LL << v1;
}

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

v1 = 0LL;
while ( color_table[v1] != a1 )
{
if ( ++v1 == 64 )
return 0LL;
}
return 1LL << v1;
}

original_code:
pset_t
char2pset (char c)
{
  for (int i = 0; i < 64; i++)
    {
      if (color_table[i] == c)
 return (((pset_t) 1) << i);
    }
  return (0);
}

canonical_original_code:
unsigned long char2pset(char c)
{
  for (int i = 0; i < 64; i++)
    {
      if (color_table[i] == c)
 return (((unsigned long) 1) << i);
    }
  return (0);
}

variable_types: c char

variable_types: i int

return_type: unsigned long


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

result = -1LL;
if ( a1 <= 0x40 )
result = 0xFFFFFFFFFFFFFFFFLL >> (64 - (unsigned __int8)a1);
return result;
}

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

result = -1LL;
if ( a1 <= 0x40 )
result = 0xFFFFFFFFFFFFFFFFLL >> (64 - (unsigned __int8)a1);
return result;
}

canonical_original_code:
unsigned long pset_full(unsigned long color_range)
{
  return (color_range > 64 ? (18446744073709551615UL)
   : (18446744073709551615UL) >> (64 - color_range));
}


decompiled_code:
__int64 pset_empty()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 0LL;
}

original_code:
pset_t
pset_empty (void)
{
  return (0);
}

canonical_original_code:
unsigned long pset_empty()
{
  return (0);
}


decompiled_code:
__int64 __fastcall pset_set(__int64 a1, char a2)
{
return a1 | char2pset(a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char a2)
{
return a1 | func0(a2);
}

original_code:
pset_t
pset_set (pset_t pset, char c)
{
  return (pset | char2pset (c));
}

canonical_original_code:
unsigned long pset_set(unsigned long pset, char c)
{
  return (pset | char2pset (c));
}

variable_types:
pset
unsigned long


decompiled_code:
__int64 __fastcall pset_discard(__int64 a1, char a2)
{
return a1 & ~char2pset(a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char a2)
{
return a1 & ~func0(a2);
}

original_code:
pset_t
pset_discard (pset_t pset, char c)
{
  return (pset & (~ char2pset (c)));
}

canonical_original_code:
unsigned long pset_discard(unsigned long pset, char c)
{
  return (pset & (~ char2pset (c)));
}


decompiled_code:
__int64 __fastcall pset_negate(__int64 a1)
{
return ~a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return ~a1;
}

original_code:
pset_t
pset_negate (pset_t pset)
{
  return (~pset);
}

canonical_original_code:
unsigned long pset_negate(unsigned long pset)
{
  return (~pset);
}


decompiled_code:
__int64 __fastcall pset_and(__int64 a1, __int64 a2)
{
return a2 & a1;
}

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

original_code:
pset_t
pset_and (pset_t pset1, pset_t pset2)
{
  return (pset1 & pset2);
}

canonical_original_code:
unsigned long pset_and(unsigned long pset1, unsigned long pset2)
{
  return (pset1 & pset2);
}


decompiled_code:
__int64 __fastcall pset_or(__int64 a1, __int64 a2)
{
return a2 | a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
return a2 | a1;
}

original_code:
pset_t
pset_or (pset_t pset1, pset_t pset2)
{
  return (pset1 | pset2);
}

canonical_original_code:
unsigned long pset_or(unsigned long pset1, unsigned long pset2)
{
  return (pset1 | pset2);
}


decompiled_code:
__int64 __fastcall pset_xor(__int64 a1, __int64 a2)
{
return a2 ^ a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
return a2 ^ a1;
}

original_code:
pset_t
pset_xor (pset_t pset1, pset_t pset2)
{
  return (pset1 ^ pset2);
}

canonical_original_code:
unsigned long pset_xor(unsigned long pset1, unsigned long pset2)
{
  return (pset1 ^ pset2);
}


decompiled_code:
bool __fastcall pset_is_included(__int64 a1, __int64 a2)
{
return (a2 | a1) == a2;
}

canonical_decompiled_code:
bool __fastcall func10(__int64 a1, __int64 a2)
{
return (a2 | a1) == a2;
}

original_code:
_Bool
pset_is_included (pset_t pset1, pset_t pset2)
{
  return ((pset1 | pset2) == pset2);
}

canonical_original_code:
_Bool pset_is_included(unsigned long pset1, unsigned long pset2)
{
  return ((pset1 | pset2) == pset2);
}


decompiled_code:
_BOOL8 __fastcall pset_is_singleton(__int64 a1)
{
bool v1; // al

v1 = 0;
if ( a1 )
v1 = (a1 & -a1) == a1;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1)
{
bool v1; // al

v1 = 0;
if ( a1 )
v1 = (a1 & -a1) == a1;
return v1;
}

original_code:
_Bool
pset_is_singleton (pset_t pset)
{
  return (pset == 0 ? 0 : (pset & (- pset)) == pset);
}

canonical_original_code:
_Bool pset_is_singleton(unsigned long pset)
{
  return (pset == 0 ? 0 : (pset & (- pset)) == pset);
}


original_code:
size_t
pset_cardinality (pset_t pset)
{
  static const uint64_t m1 = 0x5555555555555555;
  static const uint64_t m2 = 0x3333333333333333;
  static const uint64_t m4 = 0x0f0f0f0f0f0f0f0f;
  static const uint64_t h01 = 0x0101010101010101;
  pset -= (pset >> 1) & m1;
  pset = (pset & m2) + ((pset >> 2) & m2);
  pset = (pset + (pset >> 4)) & m4;
  return (pset * h01)>>56;
}

canonical_original_code:
unsigned long pset_cardinality(unsigned long pset)
{
  static unsigned long m1 = 0x5555555555555555;
  static unsigned long m2 = 0x3333333333333333;
  static unsigned long m4 = 0x0f0f0f0f0f0f0f0f;
  static unsigned long h01 = 0x0101010101010101;
  pset -= (pset >> 1) & m1;
  pset = (pset & m2) + ((pset >> 2) & m2);
  pset = (pset + (pset >> 4)) & m4;
  return (pset * h01)>>56;
}


decompiled_code:
__int64 __fastcall pset_leftmost(__int64 a1)
{
__int64 v1; // rax

v1 = pset_negate(a1 - 1);
return pset_and(a1, v1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 v1; // rax

v1 = func6(a1 - 1);
return func7(a1, v1);
}

original_code:
pset_t
pset_leftmost (pset_t pset)
{
  return (pset_and (pset, pset_negate (pset - 1)));
}

canonical_original_code:
unsigned long pset_leftmost(unsigned long pset)
{
  return (pset_and (pset, pset_negate (pset - 1)));
}


decompiled_code:
__int64 out_of_memory()
{
fprintf(stderr, "%s: error: out of memory!\n", (const char *)exec_name);
return usage(1LL);
}

canonical_decompiled_code:
__int64 func0()
{
fprintf(stderr, "%s: error: out of memory!\n", (const char *)exec_name);
return usage(1LL);
}

original_code:
static void
out_of_memory ()
{
  fprintf (stderr, "%s: error: out of memory!\n", exec_name);
  usage (1);
}

canonical_original_code:
static void out_of_memory()
{
  fprintf (stderr, "%s: error: out of memory!\n", exec_name);
  usage (1);
}


shuffle

original_code:
static void
shuffle (int* const arr, int size)
{
  srand (time (((void *)0)));
  for (int i = 0; i < size - 1; i++)
    {
      int r = i + (rand () % (size - i));
      int t = arr[i];
      arr[i] = arr[r];
      arr[r] = t;
    }
}

canonical_original_code:
static void shuffle(int *arr, int size)
{
  srand (time (((void *)0)));
  for (int i = 0; i < size - 1; i++)
    {
      int r = i + (rand () % (size - i));
      int t = arr[i];
      arr[i] = arr[r];
      arr[r] = t;
    }
}

variable_types:
arr
int *

variable_types: size int

variable_types: r int

variable_types: t int


decompiled_code:
void __fastcall grid_free(void *ptr)
{
unsigned int v1; // ebx
__int64 v2; // rax

if ( ptr )
{
if ( grid_size )
{
v1 = 0;
v2 = 0LL;
do
{
free(*((void **)ptr + v2));
v2 = ++v1;
}
while ( v1 < grid_size );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
unsigned int v1; // ebx
__int64 v2; // rax

if ( ptr )
{
if ( grid_size )
{
v1 = 0;
v2 = 0LL;
do
{
free(*((void **)ptr + v2));
v2 = ++v1;
}
while ( v1 < grid_size );
}
free(ptr);
}
}

original_code:
void
grid_free (pset_t** grid)
{
  if (grid == ((void *)0))
    return;
  for (unsigned int i = 0; i < grid_size; i++)
    free (grid[i]);
  free (grid);
}

canonical_original_code:
void grid_free(unsigned long **grid)
{
  if (grid == ((void *)0))
    return;
  for (unsigned int i = 0; i < grid_size; i++)
    free (grid[i]);
  free (grid);
}

variable_types:
grid
unsigned long **

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall stack_free(__int64 a1)
{
__int64 v1; // rbp
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 32);
grid_free(*(void **)a1);
free((void *)a1);
result = stack_free(v1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbp
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 32);
func2(*(void **)a1);
free((void *)a1);
result = func3(v1);
}
return result;
}

original_code:
static void
stack_free (choice_t* stack)
{
  if (stack == ((void *)0))
    return;
  choice_t* prev = stack->previous;
  grid_free (stack->grid);
  free (stack);
  return (stack_free (prev));
}

canonical_original_code:
static void stack_free(struct choice *stack)
{
  if (stack == ((void *)0))
    return;
  struct choice *prev = stack->previous;
  grid_free (stack->grid);
  free (stack);
  return (stack_free (prev));
}

variable_types: struct choice { unsigned long **grid; unsigned long x; unsigned long y; unsigned long choice; struct choice *previous; } *


decompiled_code:
__int64 __fastcall stack_pop(void *ptr, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rax
_QWORD *v4; // r13
unsigned int v5; // er8
__int64 v6; // rcx
unsigned int v7; // edx
__int64 i; // rax

if ( !ptr )
return 0LL;
v2 = *((_QWORD *)ptr + 4);
v3 = pset_negate(*((_QWORD *)ptr + 3));
v4 = (_QWORD *)(*(_QWORD *)(*(_QWORD *)ptr + 8LL * *((_QWORD *)ptr + 1)) + 8LL * *((_QWORD *)ptr + 2));
*v4 = pset_and(*v4, v3);
if ( grid_size )
{
v5 = 0;
v6 = 0LL;
v7 = 0;
for ( i = 0LL; ; i = 0LL )
{
do
{
*(_QWORD *)(*(_QWORD *)(a2 + 8 * v6) + 8 * i) = *(_QWORD *)(*(_QWORD *)(*(_QWORD *)ptr + 8 * v6) + 8 * i);
i = ++v7;
}
while ( v7 < grid_size );
v6 = ++v5;
if ( grid_size <= v5 )
break;
v7 = 0;
}
}
grid_free(*(void **)ptr);
free(ptr);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rax
_QWORD *v4; // r13
unsigned int v5; // er8
__int64 v6; // rcx
unsigned int v7; // edx
__int64 i; // rax

if ( !ptr )
return 0LL;
v2 = *((_QWORD *)ptr + 4);
v3 = pset_negate(*((_QWORD *)ptr + 3));
v4 = (_QWORD *)(*(_QWORD *)(*(_QWORD *)ptr + 8LL * *((_QWORD *)ptr + 1)) + 8LL * *((_QWORD *)ptr + 2));
*v4 = pset_and(*v4, v3);
if ( grid_size )
{
v5 = 0;
v6 = 0LL;
v7 = 0;
for ( i = 0LL; ; i = 0LL )
{
do
{
*(_QWORD *)(*(_QWORD *)(a2 + 8 * v6) + 8 * i) = *(_QWORD *)(*(_QWORD *)(*(_QWORD *)ptr + 8 * v6) + 8 * i);
i = ++v7;
}
while ( v7 < grid_size );
v6 = ++v5;
if ( grid_size <= v5 )
break;
v7 = 0;
}
}
func2(*(void **)ptr);
free(ptr);
return v2;
}

original_code:
static choice_t*
stack_pop (choice_t* stack, pset_t** grid)
{
  if (stack == ((void *)0))
    return (((void *)0));
  choice_t* prev = stack->previous;
  stack->grid[stack->x][stack->y] = pset_and (stack->grid[stack->x][stack->y],
           pset_negate (stack->choice));
  for (unsigned int i = 0; i < grid_size; i++)
    for (unsigned int j = 0; j < grid_size; j++)
      grid[i][j] = stack->grid[i][j];
  grid_free (stack->grid);
  free (stack);
  return (prev);
}

canonical_original_code:
static struct choice *stack_pop(struct choice *stack, unsigned long **grid)
{
  if (stack == ((void *)0))
    return (((void *)0));
  struct choice *prev = stack->previous;
  stack->grid[stack->x][stack->y] = pset_and (stack->grid[stack->x][stack->y],
           pset_negate (stack->choice));
  for (unsigned int i = 0; i < grid_size; i++)
    for (unsigned int j = 0; j < grid_size; j++)
      grid[i][j] = stack->grid[i][j];
  grid_free (stack->grid);
  free (stack);
  return (prev);
}

variable_types:
stack
struct choice *

variable_types:
j
unsigned int

return_type: struct choice { unsigned long **grid; unsigned long x; unsigned long y; unsigned long choice; struct choice *previous; } *


decompiled_code:
_QWORD *grid_alloc()
{
_QWORD *v0; // r12
size_t v1; // rdi
unsigned int v2; // ebp
__int64 v3; // rbx
void *v4; // rax

v0 = calloc(grid_size, 8uLL);
if ( !v0 )
out_of_memory();
v1 = grid_size;
if ( grid_size )
{
v2 = 0;
v3 = 0LL;
do
{
v4 = calloc(v1, 8uLL);
v0[v3] = v4;
if ( !v4 )
out_of_memory();
v3 = ++v2;
v1 = grid_size;
}
while ( v2 < grid_size );
}
return v0;
}

canonical_decompiled_code:
_QWORD *func5()
{
_QWORD *v0; // r12
size_t v1; // rdi
unsigned int v2; // ebp
__int64 v3; // rbx
void *v4; // rax

v0 = calloc(grid_size, 8uLL);
if ( !v0 )
func0();
v1 = grid_size;
if ( grid_size )
{
v2 = 0;
v3 = 0LL;
do
{
v4 = calloc(v1, 8uLL);
v0[v3] = v4;
if ( !v4 )
func0();
v3 = ++v2;
v1 = grid_size;
}
while ( v2 < grid_size );
}
return v0;
}

original_code:
pset_t**
grid_alloc (void)
{
  pset_t** ret;
  ret = calloc (grid_size, sizeof (pset_t*));
  if (ret == ((void *)0))
    out_of_memory ();
  for (unsigned int i = 0; i < grid_size; i++)
    {
      ret[i] = calloc (grid_size, sizeof (pset_t));
      if (ret[i] == ((void *)0))
 out_of_memory ();
    }
  return (ret);
}

canonical_original_code:
unsigned long **grid_alloc()
{
  unsigned long **ret;
  ret = calloc (grid_size, sizeof (unsigned long *));
  if (ret == ((void *)0))
    out_of_memory ();
  for (unsigned int i = 0; i < grid_size; i++)
    {
      ret[i] = calloc (grid_size, sizeof (pset_t));
      if (ret[i] == ((void *)0))
 out_of_memory ();
    }
  return (ret);
}

variable_types:
ret
unsigned long **

return_type: unsigned long **


decompiled_code:
int __fastcall grid_print(_QWORD **a1)
{
__int64 v2; // rax
unsigned __int64 v3; // r13
__int64 v4; // rdx
unsigned int v5; // ebp
__int64 v6; // rbx
__int64 v7; // r14
__int64 v8; // rbx
_QWORD *v9; // r12
unsigned __int64 v10; // rbx
unsigned int v11; // er12
__int64 v12; // rbp
size_t v13; // rdi
__int64 v14; // rbx
_QWORD *v15; // r14
unsigned int v17; // [rsp+Ch] [rbp-8Ch]
unsigned int v18; // [rsp+Ch] [rbp-8Ch]
__int64 v19[8]; // [rsp+10h] [rbp-88h] BYREF
char v20; // [rsp+50h] [rbp-48h]

v19[0] = 0LL;
v19[1] = 0LL;
v19[2] = 0LL;
v19[3] = 0LL;
v19[4] = 0LL;
v19[5] = 0LL;
v19[6] = 0LL;
v19[7] = 0LL;
v20 = 0;
LODWORD(v2) = grid_size;
if ( grid_size == 1 )
{
if ( random_choice )
{
v17 = 0;
v3 = 0LL;
v4 = 0LL;
LABEL_13:
while ( grid_size )
{
v9 = &a1[v4];
v5 = 0;
v6 = 0LL;
do
{
v7 = 8 * v6;
if ( pset_cardinality(*(_QWORD *)(*v9 + 8 * v6)) > v3 )
{
v8 = *(_QWORD *)(*v9 + 8 * v6);
if ( v8 != pset_full(grid_size) )
v3 = pset_cardinality(*(_QWORD *)(*v9 + v7));
}
v6 = ++v5;
LODWORD(v2) = grid_size;
}
while ( v5 < grid_size );
v4 = ++v17;
if ( grid_size <= v17 )
{
if ( grid_size )
{
v18 = 0;
v2 = 0LL;
do
{
v13 = grid_size;
if ( grid_size )
{
v15 = &a1[v2];
v11 = 0;
v12 = 0LL;
do
{
v14 = *(_QWORD *)(*v15 + 8 * v12);
if ( v14 == pset_full(v13) )
{
fputc(95, output_stream);
v10 = v3;
}
else
{
v10 = v3 - pset_cardinality(*(_QWORD *)(*v15 + 8 * v12));
pset2str(v19, *(_QWORD *)(*v15 + 8 * v12));
fprintf(output_stream, "%s ", (const char *)v19);
}
for ( ; v10; --v10 )
fputc(32, output_stream);
v12 = ++v11;
v13 = grid_size;
}
while ( v11 < grid_size );
}
fputc(10, output_stream);
v2 = ++v18;
}
while ( v18 < grid_size );
}
return v2;
}
}
}
else
{
pset2str(v19, **a1);
LODWORD(v2) = fprintf(output_stream, "%s\n", (const char *)v19);
}
}
else if ( grid_size )
{
v17 = 0;
v3 = 0LL;
v4 = 0LL;
goto LABEL_13;
}
return v2;
}

canonical_decompiled_code:
int __fastcall func6(_QWORD **a1)
{
__int64 v2; // rax
unsigned __int64 v3; // r13
__int64 v4; // rdx
unsigned int v5; // ebp
__int64 v6; // rbx
__int64 v7; // r14
__int64 v8; // rbx
_QWORD *v9; // r12
unsigned __int64 v10; // rbx
unsigned int v11; // er12
__int64 v12; // rbp
size_t v13; // rdi
__int64 v14; // rbx
_QWORD *v15; // r14
unsigned int v17; // [rsp+Ch] [rbp-8Ch]
unsigned int v18; // [rsp+Ch] [rbp-8Ch]
__int64 v19[8]; // [rsp+10h] [rbp-88h] BYREF
char v20; // [rsp+50h] [rbp-48h]

v19[0] = 0LL;
v19[1] = 0LL;
v19[2] = 0LL;
v19[3] = 0LL;
v19[4] = 0LL;
v19[5] = 0LL;
v19[6] = 0LL;
v19[7] = 0LL;
v20 = 0;
LODWORD(v2) = grid_size;
if ( grid_size == 1 )
{
if ( random_choice )
{
v17 = 0;
v3 = 0LL;
v4 = 0LL;
LABEL_13:
while ( grid_size )
{
v9 = &a1[v4];
v5 = 0;
v6 = 0LL;
do
{
v7 = 8 * v6;
if ( pset_cardinality(*(_QWORD *)(*v9 + 8 * v6)) > v3 )
{
v8 = *(_QWORD *)(*v9 + 8 * v6);
if ( v8 != pset_full(grid_size) )
v3 = pset_cardinality(*(_QWORD *)(*v9 + v7));
}
v6 = ++v5;
LODWORD(v2) = grid_size;
}
while ( v5 < grid_size );
v4 = ++v17;
if ( grid_size <= v17 )
{
if ( grid_size )
{
v18 = 0;
v2 = 0LL;
do
{
v13 = grid_size;
if ( grid_size )
{
v15 = &a1[v2];
v11 = 0;
v12 = 0LL;
do
{
v14 = *(_QWORD *)(*v15 + 8 * v12);
if ( v14 == pset_full(v13) )
{
fputc(95, output_stream);
v10 = v3;
}
else
{
v10 = v3 - pset_cardinality(*(_QWORD *)(*v15 + 8 * v12));
pset2str(v19, *(_QWORD *)(*v15 + 8 * v12));
fprintf(output_stream, "%s ", (const char *)v19);
}
for ( ; v10; --v10 )
fputc(32, output_stream);
v12 = ++v11;
v13 = grid_size;
}
while ( v11 < grid_size );
}
fputc(10, output_stream);
v2 = ++v18;
}
while ( v18 < grid_size );
}
return v2;
}
}
}
else
{
pset2str(v19, **a1);
LODWORD(v2) = fprintf(output_stream, "%s\n", (const char *)v19);
}
}
else if ( grid_size )
{
v17 = 0;
v3 = 0LL;
v4 = 0LL;
goto LABEL_13;
}
return v2;
}

original_code:
void
grid_print (const pset_t** grid)
{
  char str[64 +1] = {0};
  size_t max_cardinality = 0;
  if (grid_size == 1 && !random_choice)
    {
      pset2str (str,grid[0][0]);
      fprintf (output_stream, "%s\n", str);
      return;
    }
  for (unsigned int i = 0; i < grid_size; i++)
    for (unsigned int j = 0; j < grid_size; j++)
      {
 if (pset_cardinality (grid[i][j]) > max_cardinality
     && grid[i][j] != pset_full (grid_size))
   max_cardinality = pset_cardinality(grid[i][j]);
      }
  for (unsigned int i = 0; i < grid_size; i++)
    {
      for (unsigned int j = 0; j < grid_size; j++)
 {
   size_t spaces_length;
   if (grid[i][j] == pset_full (grid_size))
     {
       spaces_length = max_cardinality;
       fprintf (output_stream, "_");
     }
   else
     {
       spaces_length = max_cardinality - pset_cardinality(grid[i][j]);
       pset2str (str, grid[i][j]);
       fprintf (output_stream, "%s ", str);
     }
   for (;spaces_length > 0; spaces_length--)
     fputc (' ', output_stream);
 }
      fprintf (output_stream, "\n");
    }
}

canonical_original_code:
void grid_print(unsigned long **grid)
{
  char str[-1] = {0};
  unsigned long max_cardinality = 0;
  if (grid_size == 1 && !random_choice)
    {
      pset2str (str,grid[0][0]);
      fprintf (output_stream, "%s\n", str);
      return;
    }
  for (unsigned int i = 0; i < grid_size; i++)
    for (unsigned int j = 0; j < grid_size; j++)
      {
 if (pset_cardinality (grid[i][j]) > max_cardinality
     && grid[i][j] != pset_full (grid_size))
   max_cardinality = pset_cardinality(grid[i][j]);
      }
  for (unsigned int i = 0; i < grid_size; i++)
    {
      for (unsigned int j = 0; j < grid_size; j++)
 {
   unsigned long spaces_length;
   if (grid[i][j] == pset_full (grid_size))
     {
       spaces_length = max_cardinality;
       fprintf (output_stream, "_");
     }
   else
     {
       spaces_length = max_cardinality - pset_cardinality(grid[i][j]);
       pset2str (str, grid[i][j]);
       fprintf (output_stream, "%s ", str);
     }
   for (;spaces_length > 0; spaces_length--)
     fputc (' ', output_stream);
 }
      fprintf (output_stream, "\n");
    }
}

variable_types:
str
char [-1]


decompiled_code:
int __fastcall stack_print(__int64 a1)
{
int result; // eax
char v2[80]; // [rsp-50h] [rbp-A8h] BYREF
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

if ( a1 )
{
pset2str(v3, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *(_QWORD *)(a1 + 8)) + 8LL * *(_QWORD *)(a1 + 16)));
pset2str(v2, *(_QWORD *)(a1 + 24));
if ( verbose )
grid_print(*(_QWORD ***)a1);
result = fprintf(
output_stream,
"Next choice at: grid[%d][%d] = '%s', and choice is = '%s'\n",
*(_QWORD *)(a1 + 8),
*(_QWORD *)(a1 + 16),
v3,
v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
int result; // eax
char v2[80]; // [rsp-50h] [rbp-A8h] BYREF
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

if ( a1 )
{
pset2str(v3, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *(_QWORD *)(a1 + 8)) + 8LL * *(_QWORD *)(a1 + 16)));
pset2str(v2, *(_QWORD *)(a1 + 24));
if ( verbose )
func6(*(_QWORD ***)a1);
result = fprintf(
output_stream,
"Next choice at: grid[%d][%d] = '%s', and choice is = '%s'\n",
*(_QWORD *)(a1 + 8),
*(_QWORD *)(a1 + 16),
v3,
v2);
}
return result;
}

original_code:
static void
stack_print (const choice_t* stack)
{
  if (stack == ((void *)0))
    return;
   char str1[64 + 1];
   char str2[64 + 1];
   pset2str (str1, stack->grid[stack->x][stack->y]);
   pset2str (str2, stack->choice);
   if (verbose)
     grid_print ((const pset_t**) stack->grid);
   fprintf (output_stream,
     "Next choice at: grid[%d][%d] = '%s', and choice is = '%s'\n",
    (int) stack->x, (int) stack->y, str1, str2);
}

canonical_original_code:
static void stack_print(struct choice *stack)
{
  if (stack == ((void *)0))
    return;
   char str1[-1];
   char str2[-1];
   pset2str (str1, stack->grid[stack->x][stack->y]);
   pset2str (str2, stack->choice);
   if (verbose)
     grid_print ((unsigned long **) stack->grid);
   fprintf (output_stream,
     "Next choice at: grid[%d][%d] = '%s', and choice is = '%s'\n",
    (int) stack->x, (int) stack->y, str1, str2);
}

user_defined_types: struct choice { unsigned long **grid; unsigned long x; unsigned long y; unsigned long choice; struct choice *previous; }


decompiled_code:
__int64 __fastcall number_of_solutions(__int64 a1)
{
unsigned int v1; // er12
_QWORD *v2; // rbx
int v4; // eax

v1 = 0;
v2 = 0LL;
do
{
while ( 1 )
{
while ( 1 )
{
v4 = grid_heuristics(a1);
if ( v4 != 1 )
break;
v2 = stack_push(v2, a1);
}
if ( v4 != 2 )
break;
if ( !v2 )
return v1;
LABEL_9:
v2 = (_QWORD *)stack_pop(v2, a1);
}
}
while ( v4 );
++v1;
if ( v2 )
goto LABEL_9;
stack_free(0LL);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
unsigned int v1; // er12
_QWORD *v2; // rbx
int v4; // eax

v1 = 0;
v2 = 0LL;
do
{
while ( 1 )
{
while ( 1 )
{
v4 = grid_heuristics(a1);
if ( v4 != 1 )
break;
v2 = stack_push(v2, a1);
}
if ( v4 != 2 )
break;
if ( !v2 )
return v1;
LABEL_9:
v2 = (_QWORD *)func4(v2, a1);
}
}
while ( v4 );
++v1;
if ( v2 )
goto LABEL_9;
func3(0LL);
return v1;
}

original_code:
static int
number_of_solutions (pset_t** grid)
{
  choice_t* stack = ((void *)0);
  int sols = 0;
  for (;;)
    {
      switch (grid_heuristics (grid))
 {
 case 0:
   sols++;
   if (stack == ((void *)0))
     {
       stack_free (stack);
       return (sols);
     }
   else
     {
       stack = stack_pop (stack, grid);
       break;
     }
 case 1:
   stack = stack_push (stack, grid);
   break;
 case 2:
   if (stack == ((void *)0))
     {
       return (sols);
     }
   stack = stack_pop (stack, grid);
   break;
 }
    }
}

canonical_original_code:
static int number_of_solutions(unsigned long **grid)
{
  struct choice *stack = ((void *)0);
  int sols = 0;
  for (;;)
    {
      switch (grid_heuristics (grid))
 {
 case 0:
   sols++;
   if (stack == ((void *)0))
     {
       stack_free (stack);
       return (sols);
     }
   else
     {
       stack = stack_pop (stack, grid);
       break;
     }
 case 1:
   stack = stack_push (stack, grid);
   break;
 case 2:
   if (stack == ((void *)0))
     {
       return (sols);
     }
   stack = stack_pop (stack, grid);
   break;
 }
    }
}

variable_types: sols int


decompiled_code:
__int64 __fastcall grid_solver(_QWORD **a1)
{
_QWORD *v1; // rbx
int v2; // eax
unsigned int v3; // ebx

v1 = 0LL;
do
{
while ( 1 )
{
while ( 1 )
{
v2 = grid_heuristics(a1);
if ( v2 != 1 )
break;
v1 = stack_push(v1, (__int64)a1);
}
if ( v2 != 2 )
break;
if ( !v1 )
{
v3 = (unsigned __int8)random_choice;
if ( random_choice )
return 0;
fwrite("Grid could not be solved\n", 1uLL, 0x19uLL, output_stream);
return v3;
}
v1 = (_QWORD *)stack_pop(v1, (__int64)a1);
}
}
while ( v2 );
if ( !random_choice )
{
fwrite("Grid has been solved\n", 1uLL, 0x15uLL, output_stream);
grid_print(a1);
}
stack_free((__int64)v1);
return 1;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD **a1)
{
_QWORD *v1; // rbx
int v2; // eax
unsigned int v3; // ebx

v1 = 0LL;
do
{
while ( 1 )
{
while ( 1 )
{
v2 = grid_heuristics(a1);
if ( v2 != 1 )
break;
v1 = stack_push(v1, (__int64)a1);
}
if ( v2 != 2 )
break;
if ( !v1 )
{
v3 = (unsigned __int8)random_choice;
if ( random_choice )
return 0;
fwrite("Grid could not be solved\n", 1uLL, 0x19uLL, output_stream);
return v3;
}
v1 = (_QWORD *)func4(v1, (__int64)a1);
}
}
while ( v2 );
if ( !random_choice )
{
fwrite("Grid has been solved\n", 1uLL, 0x15uLL, output_stream);
func6(a1);
}
func3((__int64)v1);
return 1;
}

original_code:
_Bool
grid_solver (pset_t** grid)
{
  choice_t* stack = ((void *)0);
  for (;;)
    {
      switch (grid_heuristics (grid))
 {
 case 0:
   if (!random_choice)
     {
       fprintf (output_stream, "Grid has been solved\n");
       grid_print ((const pset_t**) grid);
     }
   stack_free (stack);
   return (1);
 case 1:
   stack = stack_push (stack, grid);
   break;
 case 2:
   if (stack == ((void *)0))
     {
       if (!random_choice)
  fprintf (output_stream, "Grid could not be solved\n");
       return (0);
     }
   stack = stack_pop (stack, grid);
   break;
 }
    }
}

canonical_original_code:
_Bool grid_solver(unsigned long **grid)
{
  struct choice *stack = ((void *)0);
  for (;;)
    {
      switch (grid_heuristics (grid))
 {
 case 0:
   if (!random_choice)
     {
       fprintf (output_stream, "Grid has been solved\n");
       grid_print ((unsigned long **) grid);
     }
   stack_free (stack);
   return (1);
 case 1:
   stack = stack_push (stack, grid);
   break;
 case 2:
   if (stack == ((void *)0))
     {
       if (!random_choice)
  fprintf (output_stream, "Grid could not be solved\n");
       return (0);
     }
   stack = stack_pop (stack, grid);
   break;
 }
    }
}


decompiled_code:
__int64 __fastcall check_input_char(char a1)
{
__int64 result; // rax
char *v2; // rax
char v3[80]; // [rsp+0h] [rbp-50h] BYREF

strcpy(v3, "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@&*");
result = 1LL;
if ( a1 != 95 )
{
if ( grid_size )
{
v2 = v3;
while ( *v2 != a1 )
{
if ( ++v2 == &v3[grid_size] )
return 0LL;
}
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
__int64 result; // rax
char *v2; // rax
char v3[80]; // [rsp+0h] [rbp-50h] BYREF

strcpy(v3, "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@&*");
result = 1LL;
if ( a1 != 95 )
{
if ( grid_size )
{
v2 = v3;
while ( *v2 != a1 )
{
if ( ++v2 == &v3[grid_size] )
return 0LL;
}
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
static _Bool
check_input_char (char c)
{
  const char tbl[] = "123456789"
                     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                     "abcdefghijklmnopqrstuvwxyz"
                     "@&*";
  if (c == '_')
    return (1);
  for (unsigned int i = 0; i < grid_size; i++)
    if (c == tbl[i])
      return (1);
  return (0);
}

canonical_original_code:
static _Bool check_input_char(char c)
{
  char tbl[] = "123456789"
                     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                     "abcdefghijklmnopqrstuvwxyz"
                     "@&*";
  if (c == '_')
    return (1);
  for (unsigned int i = 0; i < grid_size; i++)
    if (c == tbl[i])
      return (1);
  return (0);
}

variable_types:
tbl
char []


version

decompiled_code:
void __noreturn version()
{
printf("%s %d.%d.%d\nThis software is a sudoku solver\n", "sudoku", 1LL, 0LL, 0LL);
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
printf("%s %d.%d.%d\nThis software is a sudoku solver\n", "sudoku", 1LL, 0LL, 0LL);
exit(0);
}

original_code:
static void
version (void)
{
  printf ("%s %d.%d.%d\n"
   "This software is a sudoku solver\n",
   "sudoku", 1, 0, 0);
  exit (0);
}

canonical_original_code:
static void version()
{
  printf ("%s %d.%d.%d\n"
   "This software is a sudoku solver\n",
   "sudoku", 1, 0, 0);
  exit (0);
}


usage

decompiled_code:
void __fastcall __noreturn usage(int status)
{
char *v1; // rax

v1 = _xpg_basename(exec_name);
if ( status )
fprintf(stderr, "Try `%s --help` for more information\n", v1);
else
printf(
"Usage: %s [OPTION] FILE\n"
"Solve Sudoku puzzles of variable sizes (1-64)\n"
"\n"
" -o, --output=FILE write result to FILE\n"
" -s, --strict generate a unique-solution grid -g, --generate=SIZE generates a grid of size SIZE (by defau"
"lt 9)\n"
" -v, --verbose verbose output\n"
" -V, --version display version and exit\n"
" -h, --help display this help\n",
v1);
grid_free(grid);
fclose(output_stream);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int status)
{
char *v1; // rax

v1 = _xpg_basename(exec_name);
if ( status )
fprintf(stderr, "Try `%s --help` for more information\n", v1);
else
printf(
"Usage: %s [OPTION] FILE\n"
"Solve Sudoku puzzles of variable sizes (1-64)\n"
"\n"
" -o, --output=FILE write result to FILE\n"
" -s, --strict generate a unique-solution grid -g, --generate=SIZE generates a grid of size SIZE (by defau"
"lt 9)\n"
" -v, --verbose verbose output\n"
" -V, --version display version and exit\n"
" -h, --help display this help\n",
v1);
grid_free(grid);
fclose(output_stream);
exit(status);
}

original_code:
void
usage (int status)
{
  if (status == 0)
    {
      printf (
 "Usage: %s [OPTION] FILE\n"
        "Solve Sudoku puzzles of variable sizes (1-64)\n"
 "\n"
 "  -o, --output=FILE   write result to FILE\n"
 "  -s, --strict        generate a unique-solution grid"
 "  -g, --generate=SIZE generates a grid of size SIZE (by default 9)\n"
        "  -v, --verbose       verbose output\n"
 "  -V, --version       display version and exit\n"
 "  -h, --help          display this help\n",
        __xpg_basename(exec_name));
    }
  else
    {
      fprintf (stderr, "Try `%s --help` for more information\n",
        __xpg_basename(exec_name));
    }
  grid_free (grid);
  fclose (output_stream);
  exit (status);
}

canonical_original_code:
void usage(int status)
{
  if (status == 0)
    {
      printf (
 "Usage: %s [OPTION] FILE\n"
        "Solve Sudoku puzzles of variable sizes (1-64)\n"
 "\n"
 "  -o, --output=FILE   write result to FILE\n"
 "  -s, --strict        generate a unique-solution grid"
 "  -g, --generate=SIZE generates a grid of size SIZE (by default 9)\n"
        "  -v, --verbose       verbose output\n"
 "  -V, --version       display version and exit\n"
 "  -h, --help          display this help\n",
        __xpg_basename(exec_name));
    }
  else
    {
      fprintf (stderr, "Try `%s --help` for more information\n",
        __xpg_basename(exec_name));
    }
  grid_free (grid);
  fclose (output_stream);
  exit (status);
}

variable_types: status int


main

canonical_name: main

repo: danielgjackson/xed

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char *v4; // r13
int i; // er12
const char *v6; // rbx
int v7; // ebx

fwrite("XED File Format Parser\n", 1uLL, 0x17uLL, stderr);
fwrite("2013, Dan Jackson\n", 1uLL, 0x12uLL, stderr);
fputc(10, stderr);
if ( argc <= 1 )
{
LABEL_12:
fwrite("ERROR: Input file not specified.\n", 1uLL, 0x21uLL, stderr);
}
else
{
v3 = argv + 1;
v4 = 0LL;
for ( i = 0; ; i = 1 )
{
v6 = *v3;
if ( !strcasecmp(*v3, "--help") )
break;
if ( *v6 == 45 )
{
fprintf(stderr, "ERROR: Unknown option: %s\n", v6);
break;
}
if ( i )
{
fprintf(stderr, "ERROR: Unknown positional parameter: %s\n", v6);
break;
}
if ( ++v3 == &argv[(unsigned int)(argc - 2) + 2] )
{
fprintf(stderr, "NOTE: Processing: %s\n", v6);
v7 = xed_decode(v6);
fwrite("NOTE: End processing\n", 1uLL, 0x15uLL, stderr);
return v7;
}
v4 = v6;
}
if ( !v4 )
goto LABEL_12;
}
fputc(10, stderr);
fwrite("Usage: xed_decode <input.xed>\n", 1uLL, 0x1EuLL, stderr);
fputc(10, stderr);
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char *v4; // r13
int i; // er12
const char *v6; // rbx
int v7; // ebx

fwrite("XED File Format Parser\n", 1uLL, 0x17uLL, stderr);
fwrite("2013, Dan Jackson\n", 1uLL, 0x12uLL, stderr);
fputc(10, stderr);
if ( argc <= 1 )
{
LABEL_12:
fwrite("ERROR: Input file not specified.\n", 1uLL, 0x21uLL, stderr);
}
else
{
v3 = argv + 1;
v4 = 0LL;
for ( i = 0; ; i = 1 )
{
v6 = *v3;
if ( !strcasecmp(*v3, "--help") )
break;
if ( *v6 == 45 )
{
fprintf(stderr, "ERROR: Unknown option: %s\n", v6);
break;
}
if ( i )
{
fprintf(stderr, "ERROR: Unknown positional parameter: %s\n", v6);
break;
}
if ( ++v3 == &argv[(unsigned int)(argc - 2) + 2] )
{
fprintf(stderr, "NOTE: Processing: %s\n", v6);
v7 = func0(v6);
fwrite("NOTE: End processing\n", 1uLL, 0x15uLL, stderr);
return v7;
}
v4 = v6;
}
if ( !v4 )
goto LABEL_12;
}
fputc(10, stderr);
fwrite("Usage: xed_decode <input.xed>\n", 1uLL, 0x1EuLL, stderr);
fputc(10, stderr);
return -1;
}

original_code:
int main(int argc, char *argv[])
{
    int ret = 0;
    char help = 0;
    int positional;
    int i;
    const char *infile = ((void *)0);
    fprintf(stderr, "XED File Format Parser\n");
    fprintf(stderr, "2013, Dan Jackson\n");
    fprintf(stderr, "\n");
    positional = 0;
    for (i = 1; i < argc; i++)
    {
        if (!strcasecmp(argv[i], "--help")) { help = 1; break; }
        else if (argv[i][0] == '-')
        {
            fprintf(stderr, "ERROR: Unknown option: %s\n", argv[i]);
            help = 1;
            break;
        }
        else
        {
            positional++;
            if (positional == 1)
            {
                infile = argv[i];
            }
            else
            {
                fprintf(stderr, "ERROR: Unknown positional parameter: %s\n", argv[i]);
                help = 1;
                break;
            }
        }
    }
    if (infile == ((void *)0)) { fprintf(stderr, "ERROR: Input file not specified.\n"); help = 1; }
    if (help)
    {
        fprintf(stderr, "\n");
        fprintf(stderr, "Usage: xed_decode <input.xed>\n");
        fprintf(stderr, "\n");
        ret = -1;
    }
    else
    {
        fprintf(stderr, "NOTE: Processing: %s\n", infile);
        ret = xed_decode(infile);
        fprintf(stderr, "NOTE: End processing\n");
    }
    return ret;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int ret = 0;
    char help = 0;
    int positional;
    int i;
    char *infile = ((void *)0);
    fprintf(stderr, "XED File Format Parser\n");
    fprintf(stderr, "2013, Dan Jackson\n");
    fprintf(stderr, "\n");
    positional = 0;
    for (i = 1; i < argc; i++)
    {
        if (!strcasecmp(argv[i], "--help")) { help = 1; break; }
        else if (argv[i][0] == '-')
        {
            fprintf(stderr, "ERROR: Unknown option: %s\n", argv[i]);
            help = 1;
            break;
        }
        else
        {
            positional++;
            if (positional == 1)
            {
                infile = argv[i];
            }
            else
            {
                fprintf(stderr, "ERROR: Unknown positional parameter: %s\n", argv[i]);
                help = 1;
                break;
            }
        }
    }
    if (infile == ((void *)0)) { fprintf(stderr, "ERROR: Input file not specified.\n"); help = 1; }
    if (help)
    {
        fprintf(stderr, "\n");
        fprintf(stderr, "Usage: xed_decode <input.xed>\n");
        fprintf(stderr, "\n");
        ret = -1;
    }
    else
    {
        fprintf(stderr, "NOTE: Processing: %s\n", infile);
        ret = xed_decode(infile);
        fprintf(stderr, "NOTE: End processing\n");
    }
    return ret;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ret int

variable_types: help char

variable_types: positional int

variable_types:
infile
char *


repo: danielgtaylor/jpeg-archive

original_code:
float KBND_SYMMETRIC(const float *img, int w, int h, int x, int y, float bnd_const)
{
    if (x<0) x=-1-x;
    else if (x>=w) x=(w-(x-w))-1;
    if (y<0) y=-1-y;
    else if (y>=h) y=(h-(y-h))-1;
    return img[y*w + x];
}

canonical_original_code:
float KBND_SYMMETRIC(float *img, int w, int h, int x, int y, float bnd_const)
{
    if (x<0) x=-1-x;
    else if (x>=w) x=(w-(x-w))-1;
    if (y<0) y=-1-y;
    else if (y>=h) y=(h-(y-h))-1;
    return img[y*w + x];
}

variable_types:
img
float *

variable_types: w int

variable_types: h int

variable_types: x int

variable_types: y int

return_type: float


decompiled_code:
float __fastcall KBND_REPLICATE(__int64 a1, int a2, int a3, int a4, int a5)
{
int v6; // esi

if ( a4 < 0 )
a4 = 0;
if ( a2 <= a4 )
a4 = a2 - 1;
v6 = 0;
if ( a5 >= 0 )
v6 = a5;
if ( v6 >= a3 )
v6 = a3 - 1;
return *(float *)(a1 + 4LL * (a4 + a2 * v6));
}

original_code:
float KBND_REPLICATE(const float *img, int w, int h, int x, int y, float bnd_const)
{
    if (x<0) x=0;
    if (x>=w) x=w-1;
    if (y<0) y=0;
    if (y>=h) y=h-1;
    return img[y*w + x];
}

canonical_original_code:
float KBND_REPLICATE(float *img, int w, int h, int x, int y, float bnd_const)
{
    if (x<0) x=0;
    if (x>=w) x=w-1;
    if (y<0) y=0;
    if (y>=h) y=h-1;
    return img[y*w + x];
}


decompiled_code:
float __fastcall KBND_CONSTANT(__int64 a1, int a2, int a3, int a4, int a5)
{
float result; // xmm0_4

if ( a4 < 0 )
a4 = 0;
if ( a5 < 0 )
a5 = 0;
if ( a4 < a2 && a5 < a3 )
result = *(float *)(a1 + 4LL * (a4 + a2 * a5));
return result;
}

canonical_decompiled_code:
float __fastcall func3(__int64 a1, int a2, int a3, int a4, int a5)
{
float result; // xmm0_4

if ( a4 < 0 )
a4 = 0;
if ( a5 < 0 )
a5 = 0;
if ( a4 < a2 && a5 < a3 )
result = *(float *)(a1 + 4LL * (a4 + a2 * a5));
return result;
}

original_code:
float KBND_CONSTANT(const float *img, int w, int h, int x, int y, float bnd_const)
{
    if (x<0) x=0;
    if (y<0) y=0;
    if (x>=w || y>=h)
        return bnd_const;
    return img[y*w + x];
}

canonical_original_code:
float KBND_CONSTANT(float *img, int w, int h, int x, int y, float bnd_const)
{
    if (x<0) x=0;
    if (y<0) y=0;
    if (x>=w || y>=h)
        return bnd_const;
    return img[y*w + x];
}


clamp

original_code:
float clamp(float low, float value, float high) {
    return (value < low) ? low : ((value > high) ? high : value);
}

variable_types: low float

variable_types: value float

variable_types: high float


interpolate

original_code:
int interpolate(const unsigned char *image, int width, int components, float x, float y, int offset) {
    int stride = width * components;
    float px = x - floor(x);
    float py = y - floor(y);
    int x1 = floor(x);
    int x2 = ceil(x);
    int y1 = floor(y);
    int y2 = ceil(y);
    float top = (float) image[y1 * stride + x1 * components + offset] * (1.0 - px) +
                (float) image[y1 * stride + x2 * components + offset] * px;
    float bot = (float) image[y2 * stride + x1 * components + offset] * (1.0 - px) +
                (float) image[y2 * stride + x2 * components + offset] * px;
    return (top * (1.0 - py)) + (bot * py);
}

canonical_original_code:
int interpolate(unsigned char *image, int width, int components, float x, float y, int offset) {
    int stride = width * components;
    float px = x - floor(x);
    float py = y - floor(y);
    int x1 = floor(x);
    int x2 = ceil(x);
    int y1 = floor(y);
    int y2 = ceil(y);
    float top = (float) image[y1 * stride + x1 * components + offset] * (1.0 - px) +
                (float) image[y1 * stride + x2 * components + offset] * px;
    float bot = (float) image[y2 * stride + x1 * components + offset] * (1.0 - px) +
                (float) image[y2 * stride + x2 * components + offset] * px;
    return (top * (1.0 - py)) + (bot * py);
}

variable_types:
image
unsigned char *

variable_types: width int

variable_types: components int

variable_types: x float

variable_types: y float

variable_types: offset int

variable_types: stride int

variable_types: px float

variable_types: py float

variable_types: top float

variable_types: bot float


meanPixelError

original_code:
float meanPixelError(const unsigned char *original, const unsigned char *compressed, int width, int height, int components) {
    float pme = 0.0;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            for (int z = 0; z < components; z++) {
                int offset = y * width * components + x * components + z;
                pme += abs(original[offset] - compressed[offset]);
            }
        }
    }
    return pme / (width * height * components);
}

canonical_original_code:
float meanPixelError(unsigned char *original, unsigned char *compressed, int width, int height, int components) {
    float pme = 0.0;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            for (int z = 0; z < components; z++) {
                int offset = y * width * components + x * components + z;
                pme += abs(original[offset] - compressed[offset]);
            }
        }
    }
    return pme / (width * height * components);
}

variable_types:
original
unsigned char *

variable_types:
compressed
unsigned char *

variable_types: height int

variable_types: pme float

variable_types: z int


defish

original_code:
void defish(const unsigned char *input, unsigned char *output, int width, int height, int components, float strength, float zoom) {
    const int cx = width / 2;
    const int cy = height / 2;
    const float len = sqrt(width * width + height * height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            float dx = (cx - x) * zoom;
            float dy = (cy - y) * zoom;
            float r = sqrt(dx * dx + dy * dy) / len * strength;
            float theta = 1.0;
            if (r != 0.0) {
                theta = atan(r) / r;
            }
            dx = clamp(0.0, (float) width / 2.0 - theta * dx, width);
            dy = clamp(0.0, (float) height / 2.0 - theta * dy, height);
            for (int z = 0; z < components; z++) {
                output[y * width * components + x * components + z] = interpolate(input, width, components, dx, dy, z);
            }
        }
    }
}

canonical_original_code:
void defish(unsigned char *input, unsigned char *output, int width, int height, int components, float strength, float zoom) {
    int cx = width / 2;
    int cy = height / 2;
    float len = sqrt(width * width + height * height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            float dx = (cx - x) * zoom;
            float dy = (cy - y) * zoom;
            float r = sqrt(dx * dx + dy * dy) / len * strength;
            float theta = 1.0;
            if (r != 0.0) {
                theta = atan(r) / r;
            }
            dx = clamp(0.0, (float) width / 2.0 - theta * dx, width);
            dy = clamp(0.0, (float) height / 2.0 - theta * dy, height);
            for (int z = 0; z < components; z++) {
                output[y * width * components + x * components + z] = interpolate(input, width, components, dx, dy, z);
            }
        }
    }
}

variable_types:
input
unsigned char *

variable_types:
output
unsigned char *

variable_types: strength float

variable_types: zoom float

variable_types: cx int

variable_types: cy int

variable_types: len float

variable_types: y int

variable_types: x int

variable_types: dx float

variable_types: dy float

variable_types: r float

variable_types: theta float


grayscale

original_code:
long grayscale(const unsigned char *input, unsigned char **output, int width, int height) {
    int stride = width * 3;
    *output = malloc(width * height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            (*output)[y * width + x] = input[y * stride + x * 3] * 0.299 +
                                       input[y * stride + x * 3 + 1] * 0.587 +
                                       input[y * stride + x * 3 + 2] * 0.114 + 0.5;
        }
    }
    return width * height;
}

canonical_original_code:
long grayscale(unsigned char *input, unsigned char **output, int width, int height) {
    int stride = width * 3;
    *output = malloc(width * height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            (*output)[y * width + x] = input[y * stride + x * 3] * 0.299 +
                                       input[y * stride + x * 3 + 1] * 0.587 +
                                       input[y * stride + x * 3 + 2] * 0.114 + 0.5;
        }
    }
    return width * height;
}

variable_types:
output
unsigned char **

variable_types: width int

variable_types: stride int

return_type: long


maxluma

decompiled_code:
__int64 __fastcall maxluma(_BYTE *a1, int a2, int a3, int a4)
{
__int64 v5; // r9
__int64 v6; // rsi
int v7; // er8
unsigned int v8; // edx
_BYTE *v9; // rax

if ( a4 <= 0 )
return 0;
v5 = a2;
v6 = (__int64)&a1[a3 - 1 + 1];
v7 = 0;
v8 = 0;
do
{
v9 = a1;
if ( a3 > 0 )
{
do
{
if ( (unsigned __int8)v8 < *v9 )
v8 = (unsigned __int8)*v9;
++v9;
}
while ( v9 != (_BYTE *)v6 );
}
a1 += v5;
++v7;
v6 += v5;
}
while ( a4 != v7 );
return v8;
}

original_code:
static uint8_t maxluma(uint8_t *buf, int stride, int width, int height)
{
    uint8_t *in = buf;
    uint8_t max = 0;
    int i, j;
    for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++)
            max = (in[j] > max ? in[j] : max);
        in += stride;
    }
    return max;
}

canonical_original_code:
static unsigned char maxluma(unsigned char *buf, int stride, int width, int height)
{
    unsigned char *in = buf;
    unsigned char max = 0;
    int i; int j;
    for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++)
            max = (in[j] > max ? in[j] : max);
        in += stride;
    }
    return max;
}

variable_types:
buf
unsigned char *

variable_types: height int

variable_types:
in
unsigned char *

variable_types:
max
unsigned char

variable_types: i int

variable_types: j int

return_type: unsigned char


original_code:
static double psnr_factor(uint8_t *orig, uint8_t *cmp, int orig_stride,
                          int cmp_stride, int width, int height, uint8_t max)
{
    uint8_t *old, *new;
    double ret;
    int sum;
    int i, j;
    sum = 0;
    old = orig;
    new = cmp;
    for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++)
            sum += (old[j] - new[j]) * (old[j] - new[j]);
        old += orig_stride;
        new += cmp_stride;
    }
    ret = (double) sum / (double) (width * height);
    ret = 10.0 * log10(65025.0 / ret);
    if (max > 128)
        ret /= 50.0;
    else
        ret /= (0.0016 * (double) (max * max)) - (0.38 * (double) max + 72.5);
    return ((ret < 1.0 ? ret : 1.0) > 0.0 ? (ret < 1.0 ? ret : 1.0) : 0.0);
}

canonical_original_code:
static double psnr_factor(unsigned char *orig, unsigned char *cmp, int orig_stride, int cmp_stride, int width, int height, unsigned char max)
{
    unsigned char *old; unsigned char *new;
    double ret;
    int sum;
    int i; int j;
    sum = 0;
    old = orig;
    new = cmp;
    for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++)
            sum += (old[j] - new[j]) * (old[j] - new[j]);
        old += orig_stride;
        new += cmp_stride;
    }
    ret = (double) sum / (double) (width * height);
    ret = 10.0 * log10(65025.0 / ret);
    if (max > 128)
        ret /= 50.0;
    else
        ret /= (0.0016 * (double) (max * max)) - (0.38 * (double) max + 72.5);
    return ((ret < 1.0 ? ret : 1.0) > 0.0 ? (ret < 1.0 ? ret : 1.0) : 0.0);
}

variable_types:
orig
unsigned char *

variable_types:
cmp
unsigned char *

variable_types:
old
unsigned char *

variable_types:
new
unsigned char *

variable_types: ret double

variable_types: sum int

return_type: double


decompiled_code:
double __fastcall smallfry_metric(_BYTE *a1, __int64 a2, int a3, int a4)
{
unsigned __int8 v6; // r15
double v7; // rbp

v6 = maxluma(a1, a3, a3, a4);
v7 = psnr_factor((__int64)a1, a2, a3, a3, a3, a4, v6);
return v7 * 37.1891885161239 + COERCE_DOUBLE(aae_factor((__int64)a1, a2, a3, a3, a3, a4, v6)) * 78.5328607296973;
}

original_code:
double smallfry_metric(uint8_t *inbuf, uint8_t *outbuf, int width, int height)
{
    double p, a, b;
    uint8_t max;
    max = maxluma(inbuf, width, width, height);
    p = psnr_factor(inbuf, outbuf, width, width, width, height, max);
    a = aae_factor(inbuf, outbuf, width, width, width, height, max);
    b = p * 37.1891885161239 + a * 78.5328607296973;
    return b;
}

canonical_original_code:
double smallfry_metric(unsigned char *inbuf, unsigned char *outbuf, int width, int height)
{
    double p; double a; double b;
    unsigned char max;
    max = maxluma(inbuf, width, width, height);
    p = psnr_factor(inbuf, outbuf, width, width, width, height, max);
    a = aae_factor(inbuf, outbuf, width, width, width, height, max);
    b = p * 37.1891885161239 + a * 78.5328607296973;
    return b;
}

variable_types:
inbuf
unsigned char *

variable_types:
outbuf
unsigned char *

variable_types: p double

variable_types: a double

variable_types: b double


scale

decompiled_code:
void *__fastcall scale(__int64 a1, int a2, int a3, void **a4, int a5, int a6)
{
void *result; // rax
int v12; // er8
int v13; // edi
__int64 v14; // rcx
int v15; // edx

result = malloc(a6 * (__int64)a5);
*a4 = result;
if ( a6 > 0 )
{
v12 = 0;
v13 = 0;
do
{
if ( a5 > 0 )
{
v14 = v12;
v15 = 0;
do
{
result = *a4;
*((_BYTE *)*a4 + v14++) = *(_BYTE *)(a1
+ a2 * (int)((float)((float)((float)v13 / (float)a6) * (float)a3) + 0.5)
+ (int)((float)((float)((float)v15++ / (float)a5) * (float)a2) + 0.5));
}
while ( a5 != v15 );
}
++v13;
v12 += a5;
}
while ( a6 != v13 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1, int a2, int a3, void **a4, int a5, int a6)
{
void *result; // rax
int v12; // er8
int v13; // edi
__int64 v14; // rcx
int v15; // edx

result = malloc(a6 * (__int64)a5);
*a4 = result;
if ( a6 > 0 )
{
v12 = 0;
v13 = 0;
do
{
if ( a5 > 0 )
{
v14 = v12;
v15 = 0;
do
{
result = *a4;
*((_BYTE *)*a4 + v14++) = *(_BYTE *)(a1
+ a2 * (int)((float)((float)((float)v13 / (float)a6) * (float)a3) + 0.5)
+ (int)((float)((float)((float)v15++ / (float)a5) * (float)a2) + 0.5));
}
while ( a5 != v15 );
}
++v13;
v12 += a5;
}
while ( a6 != v13 );
}
return result;
}

original_code:
void scale(unsigned char *image, int width, int height, unsigned char **newImage, int newWidth, int newHeight) {
    *newImage = malloc((unsigned long) newWidth * newHeight);
    for (int y = 0; y < newHeight; y++) {
        for (int x = 0; x < newWidth; x++) {
            int oldY = (float) y / newHeight * height + 0.5;
            int oldX = (float) x / newWidth * width + 0.5;
            (*newImage)[y * newWidth + x] = image[oldY * width + oldX];
        }
    }
}

variable_types:
image
unsigned char *

variable_types: width int

variable_types:
newImage
unsigned char **

variable_types: newWidth int

variable_types: newHeight int

variable_types: y int

variable_types: x int

variable_types: oldY int

variable_types: oldX int


genHash

decompiled_code:
void *__fastcall genHash(__int64 a1, int a2, int a3, _QWORD *a4)
{
void *result; // rax
int v9; // edi
int v10; // esi

result = malloc(a3 * (__int64)a2);
*a4 = result;
if ( a3 > 0 )
{
v9 = 0;
v10 = 0;
do
{
result = (void *)v9;
if ( a2 > 0 )
{
do
{
*((_BYTE *)result + *a4) = *((_BYTE *)result + a1) < *((_BYTE *)result + a1 + 1);
result = (char *)result + 1;
}
while ( result != (void *)((unsigned int)a2 + (__int64)v9) );
}
++v10;
v9 += a2;
}
while ( a3 != v10 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, int a2, int a3, _QWORD *a4)
{
void *result; // rax
int v9; // edi
int v10; // esi

result = malloc(a3 * (__int64)a2);
*a4 = result;
if ( a3 > 0 )
{
v9 = 0;
v10 = 0;
do
{
result = (void *)v9;
if ( a2 > 0 )
{
do
{
*((_BYTE *)result + *a4) = *((_BYTE *)result + a1) < *((_BYTE *)result + a1 + 1);
result = (char *)result + 1;
}
while ( result != (void *)((unsigned int)a2 + (__int64)v9) );
}
++v10;
v9 += a2;
}
while ( a3 != v10 );
}
return result;
}

original_code:
void genHash(unsigned char *image, int width, int height, unsigned char **hash) {
    *hash = malloc((unsigned long) width * height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int pos = y * width + x;
            (*hash)[pos] = image[pos] < image[pos + 1];
        }
    }
}

variable_types: height int

variable_types:
hash
unsigned char **

variable_types: pos int


jpegHash

decompiled_code:
__int64 __fastcall jpegHash(__int64 a1, _QWORD *a2, int a3)
{
__int64 v4; // rdx
__int64 result; // rax
int v6; // [rsp+8h] [rbp-30h] BYREF
int v7; // [rsp+Ch] [rbp-2Ch] BYREF
void *v8; // [rsp+10h] [rbp-28h] BYREF
void *ptr; // [rsp+18h] [rbp-20h] BYREF

v4 = decodeFile(a1, &ptr, 2LL, &v7, &v6, 1LL);
result = 1LL;
if ( v4 )
{
scale((__int64)ptr, v7, v6, &v8, a3, a3);
free(ptr);
genHash((__int64)v8, a3, a3, a2);
free(v8);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2, int a3)
{
__int64 v4; // rdx
__int64 result; // rax
int v6; // [rsp+8h] [rbp-30h] BYREF
int v7; // [rsp+Ch] [rbp-2Ch] BYREF
void *v8; // [rsp+10h] [rbp-28h] BYREF
void *ptr; // [rsp+18h] [rbp-20h] BYREF

v4 = decodeFile(a1, &ptr, 2LL, &v7, &v6, 1LL);
result = 1LL;
if ( v4 )
{
func0((__int64)ptr, v7, v6, &v8, a3, a3);
free(ptr);
func1((__int64)v8, a3, a3, a2);
free(v8);
result = 0LL;
}
return result;
}

original_code:
int jpegHash(const char *filename, unsigned char **hash, int size) {
    unsigned char *image;
    unsigned long imageSize = 0;
    unsigned char *scaled;
    int width, height;
    imageSize = decodeFile(filename, &image, FILETYPE_JPEG, &width, &height, JCS_GRAYSCALE);
    if (!imageSize)
        return 1;
    scale(image, width, height, &scaled, size, size);
    free(image);
    genHash(scaled, size, size, hash);
    free(scaled);
    return 0;
}

canonical_original_code:
int jpegHash(char *filename, unsigned char **hash, int size) {
    unsigned char *image;
    unsigned long imageSize = 0;
    unsigned char *scaled;
    int width; int height;
    imageSize = decodeFile(filename, &image, FILETYPE_JPEG, &width, &height, JCS_GRAYSCALE);
    if (!imageSize)
        return 1;
    scale(image, width, height, &scaled, size, size);
    free(image);
    genHash(scaled, size, size, hash);
    free(scaled);
    return 0;
}

variable_types:
filename
char *

variable_types: size int

variable_types:
imageSize
unsigned long

variable_types:
scaled
unsigned char *


jpegHashFromBuffer

decompiled_code:
__int64 __fastcall jpegHashFromBuffer(__int64 a1, __int64 a2, _QWORD *a3, int a4)
{
__int64 v6; // rdx
__int64 result; // rax
int v8; // [rsp+10h] [rbp-30h] BYREF
int v9; // [rsp+14h] [rbp-2Ch] BYREF
void *v10; // [rsp+18h] [rbp-28h] BYREF
void *ptr; // [rsp+20h] [rbp-20h] BYREF

v6 = decodeFileFromBuffer(a1, a2, &ptr, 2LL, &v9, &v8, 1LL);
result = 1LL;
if ( v6 )
{
scale((__int64)ptr, v9, v8, &v10, a4, a4);
free(ptr);
genHash((__int64)v10, a4, a4, a3);
free(v10);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, _QWORD *a3, int a4)
{
__int64 v6; // rdx
__int64 result; // rax
int v8; // [rsp+10h] [rbp-30h] BYREF
int v9; // [rsp+14h] [rbp-2Ch] BYREF
void *v10; // [rsp+18h] [rbp-28h] BYREF
void *ptr; // [rsp+20h] [rbp-20h] BYREF

v6 = decodeFileFromBuffer(a1, a2, &ptr, 2LL, &v9, &v8, 1LL);
result = 1LL;
if ( v6 )
{
func0((__int64)ptr, v9, v8, &v10, a4, a4);
free(ptr);
func1((__int64)v10, a4, a4, a3);
free(v10);
result = 0LL;
}
return result;
}

original_code:
int jpegHashFromBuffer(unsigned char *imageBuf, long bufSize, unsigned char **hash, int size) {
    unsigned char *image;
    unsigned long imageSize = 0;
    unsigned char *scaled;
    int width, height;
    imageSize = decodeFileFromBuffer(imageBuf, bufSize, &image, FILETYPE_JPEG, &width, &height, JCS_GRAYSCALE);
    if (!imageSize)
        return 1;
    scale(image, width, height, &scaled, size, size);
    free(image);
    genHash(scaled, size, size, hash);
    free(scaled);
    return 0;
}

canonical_original_code:
int jpegHashFromBuffer(unsigned char *imageBuf, long bufSize, unsigned char **hash, int size) {
    unsigned char *image;
    unsigned long imageSize = 0;
    unsigned char *scaled;
    int width; int height;
    imageSize = decodeFileFromBuffer(imageBuf, bufSize, &image, FILETYPE_JPEG, &width, &height, JCS_GRAYSCALE);
    if (!imageSize)
        return 1;
    scale(image, width, height, &scaled, size, size);
    free(image);
    genHash(scaled, size, size, hash);
    free(scaled);
    return 0;
}

variable_types:
imageBuf
unsigned char *

variable_types: bufSize long


hammingDist

original_code:
unsigned int hammingDist(const unsigned char *hash1, const unsigned char *hash2, int hashLength) {
    unsigned int dist = 0;
    for (unsigned int x = 0; x < hashLength; x++) {
        if (hash1[x] != hash2[x]) {
            dist++;
        }
    }
    return dist;
}

canonical_original_code:
unsigned int hammingDist(unsigned char *hash1, unsigned char *hash2, int hashLength) {
    unsigned int dist = 0;
    for (unsigned int x = 0; x < hashLength; x++) {
        if (hash1[x] != hash2[x]) {
            dist++;
        }
    }
    return dist;
}

variable_types: hashLength int

variable_types:
dist
unsigned int

variable_types:
x
unsigned int


original_code:
float iqa_mse(const unsigned char *ref, const unsigned char *cmp, int w, int h, int stride)
{
    int error, offset;
    unsigned long long sum=0;
    int ww,hh;
    for (hh=0; hh<h; ++hh) {
        offset = hh*stride;
        for (ww=0; ww<w; ++ww, ++offset) {
            error = ref[offset] - cmp[offset];
            sum += error * error;
        }
    }
    return (float)( (double)sum / (double)(w*h) );
}

canonical_original_code:
float iqa_mse(unsigned char *ref, unsigned char *cmp, int w, int h, int stride)
{
    int error; int offset;
    unsigned long long sum = 0;
    int ww; int hh;
    for (hh=0; hh<h; ++hh) {
        offset = hh*stride;
        for (ww=0; ww<w; ++ww, ++offset) {
            error = ref[offset] - cmp[offset];
            sum += error * error;
        }
    }
    return (float)( (double)sum / (double)(w*h) );
}

variable_types:
ref
unsigned char *

variable_types:
cmp
unsigned char *

variable_types: w int

variable_types: h int

variable_types: stride int

variable_types: error int

variable_types: offset int

variable_types:
sum
unsigned long long

variable_types: ww int

variable_types: hh int


decompiled_code:
float iqa_psnr()
{
double v0; // xmm0_8

v0 = iqa_mse();
return log10((float)(65025.0 / *(float *)&v0)) * 10.0;
}

canonical_decompiled_code:
float func0()
{
double v0; // xmm0_8

v0 = iqa_mse();
return log10((float)(65025.0 / *(float *)&v0)) * 10.0;
}

original_code:
float iqa_psnr(const unsigned char *ref, const unsigned char *cmp, int w, int h, int stride)
{
    const int L_sqd = 255 * 255;
    return (float)( 10.0 * log10( L_sqd / iqa_mse(ref,cmp,w,h,stride) ) );
}

canonical_original_code:
float iqa_psnr(unsigned char *ref, unsigned char *cmp, int w, int h, int stride)
{
    int L_sqd = 255 * 255;
    return (float)( 10.0 * log10( L_sqd / iqa_mse(ref,cmp,w,h,stride) ) );
}


repo: danielmartin/localthresh

decompiled_code:
void __noreturn print_usage()
{
fwrite("Usage: localthresh Mean input_image output_image [-w window_size] [-c constant]\n", 1uLL, 0x50uLL, stderr);
fwrite(
" localthresh Niblack input_image output_image [-w window_size] [-c constant] [-k std_constant]\n",
1uLL,
0x65uLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("Usage: localthresh Mean input_image output_image [-w window_size] [-c constant]\n", 1uLL, 0x50uLL, stderr);
fwrite(
" localthresh Niblack input_image output_image [-w window_size] [-c constant] [-k std_constant]\n",
1uLL,
0x65uLL,
stderr);
exit(1);
}

original_code:
static void
print_usage()
{
    fprintf(stderr, "Usage: localthresh Mean input_image output_image [-w window_size] [-c constant]\n");
    fprintf(stderr, "       localthresh Niblack input_image output_image [-w window_size] [-c constant] [-k std_constant]\n");
    exit(1);
}


repo: danielverkamp/mathparse

original_code:
static tok get_number_oct(const char **s)
{
 const char *end;
 tok ret;
 ret.type = T_NONE;
 ret.val = 0.0;
 if ((*s)[0] != '0' || (*s)[1] != 'o')
  return ret;
 for (end = *s + 2; *end >= '0' && *end <= '7'; end++)
  ret.val = ret.val * 8.0 + (*end - '0');
 if (end != *s + 2) {
  ret.type = T_NUM;
  *s = end;
 }
 return ret;
}

canonical_original_code:
static struct tok get_number_oct(char **s)
{
 char *end;
 struct tok ret;
 ret.type = T_NONE;
 ret.val = 0.0;
 if ((*s)[0] != '0' || (*s)[1] != 'o')
  return ret;
 for (end = *s + 2; *end >= '0' && *end <= '7'; end++)
  ret.val = ret.val * 8.0 + (*end - '0');
 if (end != *s + 2) {
  ret.type = T_NUM;
  *s = end;
 }
 return ret;
}

variable_types:
s
char **

variable_types:
end
char *

variable_types: struct tok { int type; double val; char *str; }


original_code:
static tok get_number_hex(const char **s)
{
 const char *end;
 tok ret;
 ret.type = T_NONE;
 ret.val = 0.0;
 if ((*s)[0] != '0' || (*s)[1] != 'x')
  return ret;
 for (end = *s + 2; ; end++) {
  if (*end >= '0' && *end <= '9')
   ret.val = ret.val * 16.0 + (*end - '0');
  else if (*end >= 'A' && *end <= 'F')
   ret.val = ret.val * 16.0 + (*end - 'A') + 10.0;
  else if (*end >= 'a' && *end <= 'f')
   ret.val = ret.val * 16.0 + (*end - 'a') + 10.0;
  else
   break;
 }
 if (end != *s + 2) {
  ret.type = T_NUM;
  *s = end;
 }
 return ret;
}

canonical_original_code:
static struct tok get_number_hex(char **s)
{
 char *end;
 struct tok ret;
 ret.type = T_NONE;
 ret.val = 0.0;
 if ((*s)[0] != '0' || (*s)[1] != 'x')
  return ret;
 for (end = *s + 2; ; end++) {
  if (*end >= '0' && *end <= '9')
   ret.val = ret.val * 16.0 + (*end - '0');
  else if (*end >= 'A' && *end <= 'F')
   ret.val = ret.val * 16.0 + (*end - 'A') + 10.0;
  else if (*end >= 'a' && *end <= 'f')
   ret.val = ret.val * 16.0 + (*end - 'a') + 10.0;
  else
   break;
 }
 if (end != *s + 2) {
  ret.type = T_NUM;
  *s = end;
 }
 return ret;
}

return_type: struct tok { int type; double val; char *str; }


original_code:
static tok get_number_bin(const char **s)
{
 const char *end;
 tok ret;
 ret.type = T_NONE;
 ret.val = 0.0;
 if ((*s)[0] != '0' || (*s)[1] != 'b')
  return ret;
 for (end = *s + 2; *end == '0' || *end == '1'; end++)
  ret.val = ret.val * 2.0 + (*end - '0');
 if (end != *s + 2) {
  ret.type = T_NUM;
  *s = end;
 }
 return ret;
}

canonical_original_code:
static struct tok get_number_bin(char **s)
{
 char *end;
 struct tok ret;
 ret.type = T_NONE;
 ret.val = 0.0;
 if ((*s)[0] != '0' || (*s)[1] != 'b')
  return ret;
 for (end = *s + 2; *end == '0' || *end == '1'; end++)
  ret.val = ret.val * 2.0 + (*end - '0');
 if (end != *s + 2) {
  ret.type = T_NUM;
  *s = end;
 }
 return ret;
}

user_defined_types: struct tok { int type; double val; char *str; }


factorial

decompiled_code:
double __fastcall factorial(double a1)
{
double result; // xmm0_8

if ( a1 > 170.0 )
return 1.0 / 0.0;
result = *(double *)&LC4;
if ( a1 > 0.0 )
result = factorial(a1 - 1.0) * a1;
return result;
}

canonical_decompiled_code:
double __fastcall func3(double a1)
{
double result; // xmm0_8

if ( a1 > 170.0 )
return 1.0 / 0.0;
result = *(double *)&LC4;
if ( a1 > 0.0 )
result = func3(a1 - 1.0) * a1;
return result;
}

original_code:
static double factorial(double x)
{
 if (__builtin_isnan (x)) return x;
 if (x > 170.0) return 1.0/0.0;
 if (x <= 0.0) return 1.0;
 return x * factorial(x - 1.0);
}

variable_types: x double