original_code:
void sort_results(tcomp_results* results, char* comp) {
    if (results->num_results < 2) {
        return;
    }
    int halfway = results->num_results/2;
    tcomp_results* lower = malloc(sizeof(tcomp_results));
    tcomp_results* upper = malloc(sizeof(tcomp_results));
    lower->num_results = halfway;
    upper->num_results = results->num_results - halfway;
    lower->results = malloc(lower->num_results);
    upper->results = malloc(upper->num_results);
    lower->curr = 0;
    upper->curr = 0;
    int i;
    for (i = 0; i < halfway; ++i) {
        if (similarity(results->results[i], comp) > similarity(results->results[halfway+i], comp)) {
            lower->results[lower->curr] = results->results[halfway+i];
            upper->results[upper->curr] = results->results[i];
        } else {
            lower->results[lower->curr] = results->results[i];
            upper->results[upper->curr] = results->results[halfway+i];
        }
        lower->curr++;
        upper->curr++;
    }
    if (halfway != results->num_results - halfway) {
        upper->results[upper->curr] = results->results[results->num_results - 1];
    }
    for (i = 0; i < lower->num_results; ++i) {
        sort_results(lower, comp);
    }
    for (i = 0; i < upper->num_results; ++i) {
        sort_results(upper, comp);
    }
}

canonical_original_code:
void sort_results(struct tcomp_results *results, char *comp) {
    if (results->num_results < 2) {
        return;
    }
    int halfway = results->num_results/2;
    struct tcomp_results *lower = malloc(sizeof(tcomp_results));
    struct tcomp_results *upper = malloc(sizeof(tcomp_results));
    lower->num_results = halfway;
    upper->num_results = results->num_results - halfway;
    lower->results = malloc(lower->num_results);
    upper->results = malloc(upper->num_results);
    lower->curr = 0;
    upper->curr = 0;
    int i;
    for (i = 0; i < halfway; ++i) {
        if (similarity(results->results[i], comp) > similarity(results->results[halfway+i], comp)) {
            lower->results[lower->curr] = results->results[halfway+i];
            upper->results[upper->curr] = results->results[i];
        } else {
            lower->results[lower->curr] = results->results[i];
            upper->results[upper->curr] = results->results[halfway+i];
        }
        lower->curr++;
        upper->curr++;
    }
    if (halfway != results->num_results - halfway) {
        upper->results[upper->curr] = results->results[results->num_results - 1];
    }
    for (i = 0; i < lower->num_results; ++i) {
        sort_results(lower, comp);
    }
    for (i = 0; i < upper->num_results; ++i) {
        sort_results(upper, comp);
    }
}

variable_types: struct tcomp_results { char **results; int curr; int num_results; } *

variable_types:
comp
char *

variable_types: halfway int


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char *v4; // r12
__int64 v5; // rbp
int v6; // er12
__int64 i; // rbx
const char *v8; // rdi

v3 = argv;
if ( (unsigned int)(argc - 2) > 1 )
{
PrintHeader(argc, argv, envp);
v6 = 1;
fprintf(stderr, "USAGE:\n%s [verbose-level] <inputfile>\n", *argv);
fwrite("optional verbose-level argument can be:\n", 1uLL, 0x28uLL, stderr);
fwrite(" -q - quiet\n", 1uLL, 0x1BuLL, stderr);
fwrite(" -n - normal\n", 1uLL, 0x1CuLL, stderr);
fwrite(" -v - verbose\n", 1uLL, 0x1DuLL, stderr);
fwrite(" -db - debug\n", 1uLL, 0x1BuLL, stderr);
Disclamer();
}
else
{
v4 = argv[1];
v5 = 1LL;
if ( argc == 3 )
{
argv = (const char **)"-q";
*(_QWORD *)&argc = v4;
fixverb = 1;
if ( !strncmp(v4, "-q", 2uLL) )
{
verbose = 0;
v5 = 2LL;
}
else
{
argv = (const char **)"-v";
*(_QWORD *)&argc = v4;
if ( !strncmp(v4, "-v", 2uLL) )
{
verbose = 2;
v5 = 2LL;
}
else
{
argv = (const char **)"-db";
*(_QWORD *)&argc = v4;
if ( !strncmp(v4, "-db", 3uLL) )
{
verbose = 3;
v5 = 2LL;
}
else
{
argv = (const char **)"-n";
*(_QWORD *)&argc = v4;
if ( strncmp(v4, "-n", 2uLL) )
{
PrintHeader(v4, "-n", envp);
v6 = 1;
fprintf(stderr, "USAGE:\n%s [verbose-level] <inputfile>\n", *v3);
fwrite("optional verbose-level argument can be:\n", 1uLL, 0x28uLL, stderr);
fwrite(" -q - quiet\n", 1uLL, 0x17uLL, stderr);
fwrite(" -n - normal\n", 1uLL, 0x18uLL, stderr);
fwrite(" -v - verbose\n", 1uLL, 0x19uLL, stderr);
fwrite(" -db - debug\n", 1uLL, 0x17uLL, stderr);
return v6;
}
verbose = 1;
v5 = 2LL;
}
}
}
}
if ( *v4 != 45 || (v6 = *((unsigned __int8 *)v4 + 1) - 104) != 0 )
{
PrintHeader(*(_QWORD *)&argc, argv, envp);
v6 = 0;
Parse(v3[v5]);
}
else
{
for ( i = 0LL; NumKWT > (int)i; ++i )
{
v8 = (&KWTARR)[i];
puts(v8);
}
}
}
return v6;
}

original_code:
int main(int argc, char **argv)
{
 int f=1;
 if(argc==2||argc==3)
 {
  if (argc==3)
  {
   fixverb=1;
   if (strncmp(argv[1],"-q",2)==0)
    verbose=QUIET;
   else if (strncmp(argv[1],"-v",2)==0)
    verbose=VERBOSE;
   else if (strncmp(argv[1],"-db",3)==0)
    verbose=DEBUG;
   else if (strncmp(argv[1],"-n",2)==0)
    verbose=NORMAL;
   else
   {
    PrintHeader();
    fprintf(stderr,"USAGE:\n%s [verbose-level] <inputfile>\n", argv[0]);
    fprintf(stderr,"optional verbose-level argument can be:\n");
    fprintf(stderr,"       -q    -   quiet\n");
    fprintf(stderr,"       -n    -   normal\n");
    fprintf(stderr,"       -v    -   verbose\n");
    fprintf(stderr,"       -db   -   debug\n");
    return 1;
   }
   f++;
  }
  if (strncmp(argv[1],"-h",2)==0)
  {
   int i;
   for (i=0;i<NumKWT;i++)
    printf("%s\n", KWTARR[i]);
   return 0;
  }
  PrintHeader();
  Parse (argv[f]);
 }
 else
 {
  PrintHeader();
  fprintf(stderr,"USAGE:\n%s [verbose-level] <inputfile>\n", argv[0]);
  fprintf(stderr,"optional verbose-level argument can be:\n");
  fprintf(stderr,"       -q        -   quiet\n");
  fprintf(stderr,"       -n        -   normal\n");
  fprintf(stderr,"       -v        -   verbose\n");
  fprintf(stderr,"       -db       -   debug\n");
  Disclamer();
  return 1;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int f = 1;
 if(argc==2||argc==3)
 {
  if (argc==3)
  {
   fixverb=1;
   if (strncmp(argv[1],"-q",2)==0)
    verbose=QUIET;
   else if (strncmp(argv[1],"-v",2)==0)
    verbose=VERBOSE;
   else if (strncmp(argv[1],"-db",3)==0)
    verbose=DEBUG;
   else if (strncmp(argv[1],"-n",2)==0)
    verbose=NORMAL;
   else
   {
    PrintHeader();
    fprintf(stderr,"USAGE:\n%s [verbose-level] <inputfile>\n", argv[0]);
    fprintf(stderr,"optional verbose-level argument can be:\n");
    fprintf(stderr,"       -q    -   quiet\n");
    fprintf(stderr,"       -n    -   normal\n");
    fprintf(stderr,"       -v    -   verbose\n");
    fprintf(stderr,"       -db   -   debug\n");
    return 1;
   }
   f++;
  }
  if (strncmp(argv[1],"-h",2)==0)
  {
   int i;
   for (i=0;i<NumKWT;i++)
    printf("%s\n", KWTARR[i]);
   return 0;
  }
  PrintHeader();
  Parse (argv[f]);
 }
 else
 {
  PrintHeader();
  fprintf(stderr,"USAGE:\n%s [verbose-level] <inputfile>\n", argv[0]);
  fprintf(stderr,"optional verbose-level argument can be:\n");
  fprintf(stderr,"       -q        -   quiet\n");
  fprintf(stderr,"       -n        -   normal\n");
  fprintf(stderr,"       -v        -   verbose\n");
  fprintf(stderr,"       -db       -   debug\n");
  Disclamer();
  return 1;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: f int

variable_types: i int

return_type: int


Print

decompiled_code:
int Print(unsigned int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = (int)arg[0].reg_save_area;
if ( verbose >= a1 )
result = vprintf(a2, arg);
return result;
}

canonical_decompiled_code:
int func0(unsigned int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = (int)arg[0].reg_save_area;
if ( verbose >= a1 )
result = vprintf(a2, arg);
return result;
}

original_code:
void Print(VERB_LEVEL v_level, const char *format_str, ...)
{
       va_list ap;
       __builtin_va_start(ap,format_str);
 if (v_level<=verbose)
  vprintf(format_str, ap);
}

canonical_original_code:
void Print(enum VERB_LEVEL v_level, char *format_str, ...)
{
       __builtin_va_list ap;
       __builtin_va_start(ap,format_str);
 if (v_level<=verbose)
  vprintf(format_str, ap);
}

variable_types: enum VERB_LEVEL { QUIET=0, NORMAL=1, VERBOSE=2, DEBUG=3 }

return_type: void


Error

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

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

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

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

original_code:
void Error( const char *format_str, ...)
{
       va_list ap;
       __builtin_va_start(ap,format_str);
 vfprintf(stderr,format_str, ap);
 exit(1);
}

canonical_original_code:
void Error(char *format_str, ...)
{
       __builtin_va_list ap;
       __builtin_va_start(ap,format_str);
 vfprintf(stderr,format_str, ap);
 exit(1);
}


Warning

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

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

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

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

original_code:
void Warning( const char *format_str, ...)
{
       va_list ap;
       __builtin_va_start(ap,format_str);
 vfprintf(stderr,format_str, ap);
}

canonical_original_code:
void Warning(char *format_str, ...)
{
       __builtin_va_list ap;
       __builtin_va_start(ap,format_str);
 vfprintf(stderr,format_str, ap);
}


ProgressBar

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

v4 = (int)(a3 * a1) / 100;
v5 = (int)(a2 * a3) / 100;
result = a2;
if ( a3 != v5 )
{
v8 = v5 + 1;
v9 = a1;
v10 = a3 / a4;
if ( v4 >= v8 )
{
do
{
if ( v8 % v10 )
{
printf("\b\b\b\b");
putchar(61);
}
else
{
if ( v8 )
printf("\b\b\b\b");
putchar(124);
}
++v8;
printf("%3i%%", a1);
}
while ( v4 >= v8 );
}
else if ( (int)a1 <= (int)a2 )
{
v9 = a2;
}
else
{
printf("\b\b\b\b");
printf("%3i%%", a1);
}
if ( a3 == v4 )
putchar(10);
fflush(stdout);
result = v9;
}
return result;
}

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

v4 = (int)(a3 * a1) / 100;
v5 = (int)(a2 * a3) / 100;
result = a2;
if ( a3 != v5 )
{
v8 = v5 + 1;
v9 = a1;
v10 = a3 / a4;
if ( v4 >= v8 )
{
do
{
if ( v8 % v10 )
{
printf("\b\b\b\b");
putchar(61);
}
else
{
if ( v8 )
printf("\b\b\b\b");
putchar(124);
}
++v8;
printf("%3i%%", a1);
}
while ( v4 >= v8 );
}
else if ( (int)a1 <= (int)a2 )
{
v9 = a2;
}
else
{
printf("\b\b\b\b");
printf("%3i%%", a1);
}
if ( a3 == v4 )
putchar(10);
fflush(stdout);
result = v9;
}
return result;
}

original_code:
int ProgressBar(int pcn, int pco, int len, int tics)
{
 int pc_n=(pcn*len)/100;
 int pc=pco, tic;
 int i;
 pco=(pco*len)/100;
 if (pco==len)
  return pc;
 tic=len/tics;
 for (i=pco+1;i<=pc_n;i++)
 {
  if(i%tic == 0)
  {
   if (i==0)
    printf("|");
   else
   {
    printf("\b\b\b\b");
    printf("|");
   }
  }
  else
  {
   printf("\b\b\b\b");
   printf("=");
  }
  pc=pcn;
  printf("%3i%%",pc);
 }
 if (pcn>pc)
 {
  printf("\b\b\b\b");
  printf("%3i%%",pcn);
  pc=pcn;
 }
 if (pc_n==len)
  printf("\n");
 fflush(stdout);
 return pc;
}

canonical_original_code:
int ProgressBar(int pcn, int pco, int len, int tics)
{
 int pc_n = (pcn*len)/100;
 int pc = pco; int tic;
 int i;
 pco=(pco*len)/100;
 if (pco==len)
  return pc;
 tic=len/tics;
 for (i=pco+1;i<=pc_n;i++)
 {
  if(i%tic == 0)
  {
   if (i==0)
    printf("|");
   else
   {
    printf("\b\b\b\b");
    printf("|");
   }
  }
  else
  {
   printf("\b\b\b\b");
   printf("=");
  }
  pc=pcn;
  printf("%3i%%",pc);
 }
 if (pcn>pc)
 {
  printf("\b\b\b\b");
  printf("%3i%%",pcn);
  pc=pcn;
 }
 if (pc_n==len)
  printf("\n");
 fflush(stdout);
 return pc;
}

variable_types: pcn int

variable_types: pco int

variable_types: len int

variable_types: tics int

variable_types: pc int

variable_types: tic int


MakeMesh

original_code:
int MakeMesh(double **x, double **y, double x1, double x2, double y1, double y2, int Nx, int Ny)
{
 int i,j;
 double xs, ys;
 if (Nx==0)
  xs=0;
 else
  xs=(x2-x1)/(double)Nx;
 if (Ny==0)
  ys=0;
 else
  ys=(y2-y1)/(double)Ny;
 (*x)=malloc((Nx*Ny+Nx+Ny+1)*sizeof(double));
 (*y)=malloc((Nx*Ny+Nx+Ny+1)*sizeof(double));
 for (i=0;i<=Nx;i++)
  for (j=0;j<=Ny;j++)
  {
   (*x)[i*(Ny+1)+j]=x1+i*xs;
   (*y)[i*(Ny+1)+j]=y1+j*ys;
  }
 return Nx*Ny+Nx+Ny;
}

canonical_original_code:
int MakeMesh(double **x, double **y, double x1, double x2, double y1, double y2, int Nx, int Ny)
{
 int i; int j;
 double xs; double ys;
 if (Nx==0)
  xs=0;
 else
  xs=(x2-x1)/(double)Nx;
 if (Ny==0)
  ys=0;
 else
  ys=(y2-y1)/(double)Ny;
 (*x)=malloc((Nx*Ny+Nx+Ny+1)*sizeof(double));
 (*y)=malloc((Nx*Ny+Nx+Ny+1)*sizeof(double));
 for (i=0;i<=Nx;i++)
  for (j=0;j<=Ny;j++)
  {
   (*x)[i*(Ny+1)+j]=x1+i*xs;
   (*y)[i*(Ny+1)+j]=y1+j*ys;
  }
 return Nx*Ny+Nx+Ny;
}

variable_types:
x
double **

variable_types:
y
double **

variable_types: Nx int

variable_types: Ny int

variable_types: j int

variable_types: xs double

variable_types: ys double


Disclamer

decompiled_code:
int Disclamer()
{
putchar(10);
puts("DISCLAMER:");
puts("No warranties, either express or implied, are hereby ");
puts("given. All software is supplied as is, without ");
puts("guarantee. The user assumes all responsibility for ");
puts("damages resulting from the use of this software, ");
puts("including, but not limited to, attacks from angry ");
puts("little animals (like kittens or bunnies). ");
return putchar(10);
}

canonical_decompiled_code:
int func11()
{
putchar(10);
puts("DISCLAMER:");
puts("No warranties, either express or implied, are hereby ");
puts("given. All software is supplied as is, without ");
puts("guarantee. The user assumes all responsibility for ");
puts("damages resulting from the use of this software, ");
puts("including, but not limited to, attacks from angry ");
puts("little animals (like kittens or bunnies). ");
return putchar(10);
}

original_code:
void Disclamer()
{
 printf("\n");
 printf("DISCLAMER:\n");
 printf("No warranties, either express or implied, are hereby  \n");
 printf("given. All software is supplied as is, without        \n");
 printf("guarantee. The user assumes all responsibility for    \n");
 printf("damages resulting from the use of this software,      \n");
 printf("including, but not limited to, attacks from angry     \n");
 printf("little animals (like kittens or bunnies).             \n");
 printf("\n");
}


decompiled_code:
double __fastcall ell_int(double a1)
{
double v1; // xmm2_8
double v2; // xmm0_8
double v3; // xmm3_8
double v4; // xmm0_8

v1 = *(double *)&LC0;
v2 = sqrt(1.0 - a1 * a1);
v3 = v2 + 1.0;
do
{
v4 = v2 * v1;
v1 = v3 * 0.5;
v2 = sqrt(v4);
v3 = v3 * 0.5 + v2;
}
while ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64((v1 - v2) / v3) & LC2) > 1.0e-15 );
return 3.141592653589793 / v3;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
double v1; // xmm2_8
double v2; // xmm0_8
double v3; // xmm3_8
double v4; // xmm0_8

v1 = *(double *)&LC0;
v2 = sqrt(1.0 - a1 * a1);
v3 = v2 + 1.0;
do
{
v4 = v2 * v1;
v1 = v3 * 0.5;
v2 = sqrt(v4);
v3 = v3 * 0.5 + v2;
}
while ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64((v1 - v2) / v3) & LC2) > 1.0e-15 );
return 3.141592653589793 / v3;
}

variable_types: k double

variable_types: K double

variable_types: c double

return_type: double


variable_types: Kratio double

variable_types: q double

variable_types: nom double

variable_types: denom double

variable_types: m int


canonical_original_code:
int scd2(double u, double mc, double *s, double *c, double *d)
{
 double B10 = 1.0/24.0; double B11 = 1.0/6.0; double B20 = 1.0/720.0;
 double B21 = 11.0/180.0; double B22 = 1.0/45.0;
 double m; double uA; double uT; double u0; double v; double a; double b; double y; double z; double my; double mc2; double m2; double x; double xz; double w;
 int n; int i; int j;
 m=1.0-mc;
 uA=1.76269+mc*1.16357;
 uT=5.217e-3-m*2.143e-3;
 u0=u;
 for (n=0;n<=20;n++)
 {
  if (u0<uT)
   break;
  u0/=2.0;
 }
 if (n==20)
 {
  fprintf(stderr,"error: argument u too large in scd2: u=%e",u);
  return 1;
 }
 v=u0*u0;
 a=1.0;
 b=v*(0.5-v*(B10+m*B11-v*(B20+m*(B21+m*B22))));
 if (u<uA)
 {
  for (j=0;j<n;j++)
  {
   y=b*(a*2.0-b);
   z=a*a;
   my=m*y;
   b=y*2.0*(z-my);
   a=z*z-my*y;
  }
 }
 else
 {
  for (j=0;j<n;j++)
  {
   y=b*(a*2.0-b);
   z=a*a;
   my=m*y;
   if (z<my*2.0)
   {
    *c=a-b;
    mc2=mc*2.0;
    m2=m*2.0;
    for (i=j;i<=n;i++)
    {
     x=(*c)*(*c);
     z=a*a;
     w=m*x*x-mc*z*z;
     xz=x*z;
     *c=mc2*xz+w;
     a=m2*xz-w;
    }
    *c/=a;
    x=(*c)*(*c);
    *s=sqrt(1.0-x);
    *d=sqrt(mc+m*x);
    return 0;
   }
   b=y*2.0*(z-my);
   a=z*z-my*y;
  }
 }
 b/=a;
 y=b*(2.0-b);
 *c=1.0-b;
 *s=sqrt(y);
 *d=sqrt(1.0-m*y);
 return 0;
}

variable_types: u double

variable_types: mc double

variable_types:
s
double *

variable_types:
c
double *

variable_types:
d
double *

variable_types: m double

variable_types: uA double

variable_types: uT double

variable_types: v double

variable_types: a double

variable_types: b double

variable_types: y double

variable_types: z double

variable_types: my double

variable_types: x double

variable_types: xz double

variable_types: w double

variable_types: n int

variable_types: i int


scd

variable_types: u double

variable_types: K double

variable_types: k double

variable_types:
s
double *

variable_types: NEG int

variable_types: ss double

variable_types: cc double

variable_types: dd double

variable_types: nom double


original_code:
int sn_i(double u, double v, double K, double k, double *sn_re, double *sn_im, double *dsn_redu, double *dsn_redv,double *dsn_imdu,double *dsn_imdv)
{
 double s,c,d,s1,c1,d1;
 double kk, KK, nom;
 if(scd(u, K, k, &s, &c, &d))
  return 1;
 kk=sqrt(1-k*k);
 KK=ell_int(kk);
 if (scd(v, KK, kk, &s1, &c1, &d1))
  return 1;
 nom=1-d*d*s1*s1;
 (*sn_re)=s*d1/nom;
 (*sn_im)=c*d*s1*c1/nom;
 if (dsn_redu!=((void *)0))
  (*dsn_redu)=c*d*d1/nom-2*(k*k)*c*d*(s*s)*d1*(s1*s1)/(nom*nom);
 if (dsn_imdu!=((void *)0))
  (*dsn_imdu)=-(d*d)*s*c1*s1/nom-(k*k)*(c*c)*s*c1*s1/nom-2*(k*k)*(c*c)*(d*d)*s*c1*(s1*s1*s1)/(nom*nom);
 if (dsn_redv!=((void *)0))
  (*dsn_redv)=2*(d*d)*s*c1*(d1*d1)*s1/(nom*nom)-(kk*kk)*s*c1*s1/nom;
 if (dsn_imdv!=((void *)0))
  (*dsn_imdv)=-c*d*d1*(s1*s1)/nom+c*d*(c1*c1)*d1/nom+2*c*(d*d*d)*(c1*c1)*d1*(s1*s1)/(nom*nom);
 return 0;
}

canonical_original_code:
int sn_i(double u, double v, double K, double k, double *sn_re, double *sn_im, double *dsn_redu, double *dsn_redv, double *dsn_imdu, double *dsn_imdv)
{
 double s; double c; double d; double s1; double c1; double d1;
 double kk; double KK; double nom;
 if(scd(u, K, k, &s, &c, &d))
  return 1;
 kk=sqrt(1-k*k);
 KK=ell_int(kk);
 if (scd(v, KK, kk, &s1, &c1, &d1))
  return 1;
 nom=1-d*d*s1*s1;
 (*sn_re)=s*d1/nom;
 (*sn_im)=c*d*s1*c1/nom;
 if (dsn_redu!=((void *)0))
  (*dsn_redu)=c*d*d1/nom-2*(k*k)*c*d*(s*s)*d1*(s1*s1)/(nom*nom);
 if (dsn_imdu!=((void *)0))
  (*dsn_imdu)=-(d*d)*s*c1*s1/nom-(k*k)*(c*c)*s*c1*s1/nom-2*(k*k)*(c*c)*(d*d)*s*c1*(s1*s1*s1)/(nom*nom);
 if (dsn_redv!=((void *)0))
  (*dsn_redv)=2*(d*d)*s*c1*(d1*d1)*s1/(nom*nom)-(kk*kk)*s*c1*s1/nom;
 if (dsn_imdv!=((void *)0))
  (*dsn_imdv)=-c*d*d1*(s1*s1)/nom+c*d*(c1*c1)*d1/nom+2*c*(d*d*d)*(c1*c1)*d1*(s1*s1)/(nom*nom);
 return 0;
}

variable_types: v double

variable_types: s double

variable_types: c double

variable_types: d double

variable_types: kk double

variable_types: KK double


variable_types: x double

variable_types: ax double

variable_types: ans double

variable_types:
P
double [7]

variable_types:
Q
double [9]

variable_types: y double


variable_types:
Q
double [7]


repo: INQNET/klimalogger

decompiled_code:
int __fastcall print_log(int a1, const char *a2)
{
int result; // eax

if ( a1 < 0 )
result = fprintf(stderr, "%s\n", a2);
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, const char *a2)
{
int result; // eax

if ( a1 < 0 )
result = fprintf(stderr, "%s\n", a2);
return result;
}

original_code:
void print_log(int log_level, char* str) {
  if (log_level < 0)
    fprintf(stderr,"%s\n",str);
}

canonical_original_code:
void print_log(int log_level, char *str) {
  if (log_level < 0)
    fprintf(stderr,"%s\n",str);
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall read_last_byte_seq(unsigned int a1)
{
print_log(3, "read_last_byte_seq");
set_RTS(a1, 1LL);
nanodelay();
set_DTR(a1, 0LL);
nanodelay();
set_RTS(a1, 0LL);
nanodelay();
set_RTS(a1, 1LL);
nanodelay();
set_DTR(a1, 1LL);
nanodelay();
set_RTS(a1, 0LL);
return nanodelay();
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
func0(3, "read_last_byte_seq");
set_RTS(a1, 1LL);
nanodelay();
set_DTR(a1, 0LL);
nanodelay();
set_RTS(a1, 0LL);
nanodelay();
set_RTS(a1, 1LL);
nanodelay();
set_DTR(a1, 1LL);
nanodelay();
set_RTS(a1, 0LL);
return nanodelay();
}

original_code:
void read_last_byte_seq(WEATHERSTATION ws) {
  print_log(3,"read_last_byte_seq");
  set_RTS(ws,1);
  nanodelay();
  set_DTR(ws,0);
  nanodelay();
  set_RTS(ws,0);
  nanodelay();
  set_RTS(ws,1);
  nanodelay();
  set_DTR(ws,1);
  nanodelay();
  set_RTS(ws,0);
  nanodelay();
}

canonical_original_code:
void read_last_byte_seq(int ws) {
  print_log(3,"read_last_byte_seq");
  set_RTS(ws,1);
  nanodelay();
  set_DTR(ws,0);
  nanodelay();
  set_RTS(ws,0);
  nanodelay();
  set_RTS(ws,1);
  nanodelay();
  set_DTR(ws,1);
  nanodelay();
  set_RTS(ws,0);
  nanodelay();
}

variable_types: ws int


decompiled_code:
_BOOL8 __fastcall read_bit(__int64 a1)
{
int v1; // ebx
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

set_DTR(a1, 0LL);
nanodelay();
v1 = get_CTS((unsigned int)a1);
nanodelay();
set_DTR((unsigned int)a1, 1LL);
nanodelay();
sprintf(v3, "Read bit %i", v1 == 0);
print_log(4, v3);
return v1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
int v1; // ebx
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

set_DTR(a1, 0LL);
nanodelay();
v1 = get_CTS((unsigned int)a1);
nanodelay();
set_DTR((unsigned int)a1, 1LL);
nanodelay();
sprintf(v3, "Read bit %i", v1 == 0);
func0(4, v3);
return v1 == 0;
}

original_code:
int read_bit(WEATHERSTATION ws) {
  int bit_value;
  char str[20];
  set_DTR(ws,0);
  nanodelay();
  bit_value = get_CTS(ws);
  nanodelay();
  set_DTR(ws,1);
  nanodelay();
  sprintf(str,"Read bit %i",!bit_value);
  print_log(4,str);
  return !bit_value;
}

canonical_original_code:
int read_bit(int ws) {
  int bit_value;
  char str[20];
  set_DTR(ws,0);
  nanodelay();
  bit_value = get_CTS(ws);
  nanodelay();
  set_DTR(ws,1);
  nanodelay();
  sprintf(str,"Read bit %i",!bit_value);
  print_log(4,str);
  return !bit_value;
}

variable_types:
str
char [20]


decompiled_code:
int __fastcall write_bit(__int64 a1, unsigned int a2)
{
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

set_RTS(a1, a2 == 0);
nanodelay();
set_DTR((unsigned int)a1, 0LL);
nanodelay();
set_DTR((unsigned int)a1, 1LL);
sprintf(v3, "Write bit %i", a2);
return print_log(4, v3);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, unsigned int a2)
{
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

set_RTS(a1, a2 == 0);
nanodelay();
set_DTR((unsigned int)a1, 0LL);
nanodelay();
set_DTR((unsigned int)a1, 1LL);
sprintf(v3, "Write bit %i", a2);
return func0(4, v3);
}

original_code:
void write_bit(WEATHERSTATION ws,int bit) {
  char str[20];
  set_RTS(ws,!bit);
  nanodelay();
  set_DTR(ws,0);
  nanodelay();
  set_DTR(ws,1);
  sprintf(str,"Write bit %i",bit);
  print_log(4,str);
}

canonical_original_code:
void write_bit(int ws, int bit) {
  char str[20];
  set_RTS(ws,!bit);
  nanodelay();
  set_DTR(ws,0);
  nanodelay();
  set_DTR(ws,1);
  sprintf(str,"Write bit %i",bit);
  print_log(4,str);
}

variable_types: bit int


decompiled_code:
__int64 __fastcall read_next_byte_seq(unsigned int a1)
{
print_log(3, "read_next_byte_seq");
write_bit(a1, 0);
set_RTS(a1, 0LL);
return nanodelay();
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
func0(3, "read_next_byte_seq");
func3(a1, 0);
set_RTS(a1, 0LL);
return nanodelay();
}

original_code:
void read_next_byte_seq(WEATHERSTATION ws) {
  print_log(3,"read_next_byte_seq");
  write_bit(ws,0);
  set_RTS(ws,0);
  nanodelay();
}

canonical_original_code:
void read_next_byte_seq(int ws) {
  print_log(3,"read_next_byte_seq");
  write_bit(ws,0);
  set_RTS(ws,0);
  nanodelay();
}


decompiled_code:
_BOOL8 __fastcall read_byte(unsigned int a1)
{
_BOOL4 v1; // er12
int v2; // ebx
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = 0;
v2 = 8;
do
{
v1 = read_bit(a1) + 2 * v1;
--v2;
}
while ( v2 );
sprintf(v4, "Read byte %i", v1);
print_log(3, v4);
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(unsigned int a1)
{
_BOOL4 v1; // er12
int v2; // ebx
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = 0;
v2 = 8;
do
{
v1 = func2(a1) + 2 * v1;
--v2;
}
while ( v2 );
sprintf(v4, "Read byte %i", v1);
func0(3, v4);
return v1;
}

original_code:
int read_byte(WEATHERSTATION ws) {
  int byte = 0;
  int i;
  char str[20];
  for (i = 0; i < 8; i++)
  {
    byte *= 2;
    byte += read_bit(ws);
  }
  sprintf(str,"Read byte %i",byte);
  print_log(3,str);
  return byte;
}

canonical_original_code:
int read_byte(int ws) {
  int byte = 0;
  int i;
  char str[20];
  for (i = 0; i < 8; i++)
  {
    byte *= 2;
    byte += read_bit(ws);
  }
  sprintf(str,"Read byte %i",byte);
  print_log(3,str);
  return byte;
}

variable_types: byte int

variable_types: i int


decompiled_code:
_BOOL8 __fastcall write_byte(unsigned int a1, unsigned int a2)
{
int v2; // ebp
char v3; // bl
int v4; // esi
int v5; // ebx
char v7[56]; // [rsp+0h] [rbp-38h] BYREF

v2 = 8;
v3 = a2;
sprintf(v7, "Writing byte %i", a2);
print_log(3, v7);
do
{
v4 = v3 & 0x80;
v3 *= 2;
write_bit(a1, v4);
--v2;
}
while ( v2 );
set_RTS(a1, 0LL);
nanodelay();
v5 = get_CTS(a1);
nanodelay();
set_DTR(a1, 0LL);
nanodelay();
set_DTR(a1, 1LL);
nanodelay();
return v5 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(unsigned int a1, unsigned int a2)
{
int v2; // ebp
char v3; // bl
int v4; // esi
int v5; // ebx
char v7[56]; // [rsp+0h] [rbp-38h] BYREF

v2 = 8;
v3 = a2;
sprintf(v7, "Writing byte %i", a2);
func0(3, v7);
do
{
v4 = v3 & 0x80;
v3 *= 2;
func3(a1, v4);
--v2;
}
while ( v2 );
set_RTS(a1, 0LL);
nanodelay();
v5 = get_CTS(a1);
nanodelay();
set_DTR(a1, 0LL);
nanodelay();
set_DTR(a1, 1LL);
nanodelay();
return v5 != 0;
}

original_code:
int write_byte(WEATHERSTATION ws, int byte) {
  int status;
  int i;
  char str[20];
  sprintf(str,"Writing byte %i",byte);
  print_log(3,str);
  for (i = 0; i < 8; i++)
  {
    write_bit(ws, byte & 0x80);
    byte <<= 1;
    byte &= 0xff;
  }
  set_RTS(ws,0);
  nanodelay();
  status = get_CTS(ws);
  nanodelay();
  set_DTR(ws,0);
  nanodelay();
  set_DTR(ws,1);
  nanodelay();
  if (status)
    return 1;
  else
    return 0;
}

canonical_original_code:
int write_byte(int ws, int byte) {
  int status;
  int i;
  char str[20];
  sprintf(str,"Writing byte %i",byte);
  print_log(3,str);
  for (i = 0; i < 8; i++)
  {
    write_bit(ws, byte & 0x80);
    byte <<= 1;
    byte &= 0xff;
  }
  set_RTS(ws,0);
  nanodelay();
  status = get_CTS(ws);
  nanodelay();
  set_DTR(ws,0);
  nanodelay();
  set_DTR(ws,1);
  nanodelay();
  if (status)
    return 1;
  else
    return 0;
}

variable_types: status int


decompiled_code:
__int64 __fastcall eeprom_read(unsigned int a1, _BYTE *a2, __int64 a3)
{
_BYTE *v4; // rbx

v4 = a2;
if ( write_byte(a1, 0xA1u) )
{
if ( a3 )
{
while ( 1 )
{
*v4++ = read_byte(a1);
if ( &a2[a3] == v4 )
break;
read_next_byte_seq(a1);
}
}
else
{
LODWORD(a3) = 0;
}
read_last_byte_seq(a1);
}
else
{
LODWORD(a3) = -1;
}
return (unsigned int)a3;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, _BYTE *a2, __int64 a3)
{
_BYTE *v4; // rbx

v4 = a2;
if ( func6(a1, 0xA1u) )
{
if ( a3 )
{
while ( 1 )
{
*v4++ = func5(a1);
if ( &a2[a3] == v4 )
break;
func4(a1);
}
}
else
{
LODWORD(a3) = 0;
}
func1(a1);
}
else
{
LODWORD(a3) = -1;
}
return (unsigned int)a3;
}

original_code:
int eeprom_read(WEATHERSTATION ws, unsigned char *buf, size_t count) {
  unsigned char command = 0xa1;
  int i;
  if (!write_byte(ws,command))
    return -1;
  for (i = 0; i < count; i++) {
    buf[i] = read_byte(ws);
    if (i + 1 < count)
      read_next_byte_seq(ws);
  }
  read_last_byte_seq(ws);
  return i;
}

canonical_original_code:
int eeprom_read(int ws, unsigned char *buf, unsigned long count) {
  unsigned char command = 0xa1;
  int i;
  if (!write_byte(ws,command))
    return -1;
  for (i = 0; i < count; i++) {
    buf[i] = read_byte(ws);
    if (i + 1 < count)
      read_next_byte_seq(ws);
  }
  read_last_byte_seq(ws);
  return i;
}

variable_types:
buf
unsigned char *

variable_types:
count
unsigned long

variable_types:
command
unsigned char


decompiled_code:
__int64 __fastcall write_data(unsigned int a1, int a2, int a3, unsigned __int8 *a4)
{
int v7; // esi
__int64 v8; // r13
unsigned int v9; // esi

write_byte(a1, 0xA0u);
v7 = a2 + 255;
if ( a2 >= 0 )
v7 = a2;
write_byte(a1, v7 >> 8);
write_byte(a1, (unsigned __int8)(a2 + ((unsigned int)(a2 >> 31) >> 24)) - ((unsigned int)(a2 >> 31) >> 24));
if ( a4 )
{
if ( a3 <= 0 )
{
a3 = 0;
}
else
{
v8 = (__int64)&a4[a3 - 1 + 1];
do
{
v9 = *a4++;
write_byte(a1, v9);
}
while ( a4 != (unsigned __int8 *)v8 );
}
}
else
{
a3 = -1;
}
set_DTR(a1, 0LL);
nanodelay();
set_RTS(a1, 0LL);
nanodelay();
set_RTS(a1, 1LL);
nanodelay();
set_DTR(a1, 1LL);
nanodelay();
set_RTS(a1, 0LL);
nanodelay();
return (unsigned int)a3;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, int a2, int a3, unsigned __int8 *a4)
{
int v7; // esi
__int64 v8; // r13
unsigned int v9; // esi

func6(a1, 0xA0u);
v7 = a2 + 255;
if ( a2 >= 0 )
v7 = a2;
func6(a1, v7 >> 8);
func6(a1, (unsigned __int8)(a2 + ((unsigned int)(a2 >> 31) >> 24)) - ((unsigned int)(a2 >> 31) >> 24));
if ( a4 )
{
if ( a3 <= 0 )
{
a3 = 0;
}
else
{
v8 = (__int64)&a4[a3 - 1 + 1];
do
{
v9 = *a4++;
func6(a1, v9);
}
while ( a4 != (unsigned __int8 *)v8 );
}
}
else
{
a3 = -1;
}
set_DTR(a1, 0LL);
nanodelay();
set_RTS(a1, 0LL);
nanodelay();
set_RTS(a1, 1LL);
nanodelay();
set_DTR(a1, 1LL);
nanodelay();
set_RTS(a1, 0LL);
nanodelay();
return (unsigned int)a3;
}

original_code:
int write_data(WEATHERSTATION ws, int address, int number, unsigned char *writedata) {
  unsigned char command = 0xa0;
  int i = -1;
  write_byte(ws,command);
  write_byte(ws,address/256);
  write_byte(ws,address%256);
  if (writedata!=((void *)0)) {
    for (i = 0; i < number; i++)
    {
      write_byte(ws,writedata[i]);
    }
  }
  set_DTR(ws,0);
  nanodelay();
  set_RTS(ws,0);
  nanodelay();
  set_RTS(ws,1);
  nanodelay();
  set_DTR(ws,1);
  nanodelay();
  set_RTS(ws,0);
  nanodelay();
  return i;
}

canonical_original_code:
int write_data(int ws, int address, int number, unsigned char *writedata) {
  unsigned char command = 0xa0;
  int i = -1;
  write_byte(ws,command);
  write_byte(ws,address/256);
  write_byte(ws,address%256);
  if (writedata!=((void *)0)) {
    for (i = 0; i < number; i++)
    {
      write_byte(ws,writedata[i]);
    }
  }
  set_DTR(ws,0);
  nanodelay();
  set_RTS(ws,0);
  nanodelay();
  set_RTS(ws,1);
  nanodelay();
  set_DTR(ws,1);
  nanodelay();
  set_RTS(ws,0);
  nanodelay();
  return i;
}

variable_types: address int

variable_types: number int

variable_types:
writedata
unsigned char *


decompiled_code:
__int64 __fastcall eeprom_seek(unsigned int a1, int a2)
{
return write_data(a1, a2, 0, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, int a2)
{
return func8(a1, a2, 0, 0LL);
}

original_code:
int eeprom_seek(WEATHERSTATION ws, off_t pos) {
  return write_data(ws, pos, 0, ((void *)0));
}

canonical_original_code:
int eeprom_seek(int ws, long pos) {
  return write_data(ws, pos, 0, ((void *)0));
}

variable_types: pos long


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

ioperm(0x80uLL, 1uLL, 1);
LOBYTE(result) = inb_constprop_0();
m_f = a1;
result = (unsigned __int8)result;
old_port_value = (unsigned __int8)result;
return result;
}

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

ioperm(0x80uLL, 1uLL, 1);
LOBYTE(result) = func1();
m_f = a1;
result = (unsigned __int8)result;
old_port_value = (unsigned __int8)result;
return result;
}

original_code:
void microdelay_init(unsigned int multiply_factor) {
    ioperm(0x80,1,1);
    old_port_value=inb(0x80);
    m_f = multiply_factor;
}


microdelay

decompiled_code:
__int64 __fastcall microdelay(int a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( m_f * a1 )
{
do
result = outb_constprop_0((unsigned __int8)old_port_value);
while ( v2 != 1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( m_f * a1 )
{
do
result = func0((unsigned __int8)old_port_value);
while ( v2 != 1 );
}
return result;
}

original_code:
void microdelay(unsigned int microsec) {
  unsigned long int i;
  i = m_f * microsec;
  while (i)
    {
      outb(old_port_value,0x80);
      i--;
    }
}

canonical_original_code:
void microdelay(unsigned int microsec) {
  unsigned long i;
  i = m_f * microsec;
  while (i)
    {
      outb(old_port_value,0x80);
      i--;
    }
}

variable_types:
microsec
unsigned int

variable_types:
i
unsigned long


decompiled_code:
int __fastcall close_weatherstation(int fd)
{
tcflush(fd, 2);
return close(fd);
}

canonical_decompiled_code:
int __fastcall func4(int fd)
{
tcflush(fd, 2);
return close(fd);
}

original_code:
void close_weatherstation(WEATHERSTATION ws)
{
  tcflush(ws,2);
  close(ws);
  return;
}

canonical_original_code:
void close_weatherstation(int ws)
{
  tcflush(ws,2);
  close(ws);
  return;
}


decompiled_code:
int __fastcall set_DTR(int fd, int a2)
{
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

ioctl(fd, 0x5415uLL, v3);
if ( a2 )
{
print_log(5LL, "Set DTR");
v3[0] |= 2u;
}
else
{
print_log(5LL, "Clear DTR");
v3[0] &= 0xFFFFFFFD;
}
return ioctl(fd, 0x5418uLL, v3);
}

canonical_decompiled_code:
int __fastcall func5(int fd, int a2)
{
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

ioctl(fd, 0x5415uLL, v3);
if ( a2 )
{
print_log(5LL, "Set DTR");
v3[0] |= 2u;
}
else
{
print_log(5LL, "Clear DTR");
v3[0] &= 0xFFFFFFFD;
}
return ioctl(fd, 0x5418uLL, v3);
}

original_code:
void set_DTR(WEATHERSTATION ws, int val)
{
  int portstatus;
  ioctl(ws, 0x5415, &portstatus);
  if (val)
  {
    print_log(5,"Set DTR");
    portstatus |= 0x002;
  }
  else
  {
    print_log(5,"Clear DTR");
    portstatus &= ~0x002;
  }
  ioctl(ws, 0x5418, &portstatus);
}

canonical_original_code:
void set_DTR(int ws, int val)
{
  int portstatus;
  ioctl(ws, 0x5415, &portstatus);
  if (val)
  {
    print_log(5,"Set DTR");
    portstatus |= 0x002;
  }
  else
  {
    print_log(5,"Clear DTR");
    portstatus &= ~0x002;
  }
  ioctl(ws, 0x5418, &portstatus);
}

variable_types: val int

variable_types: portstatus int


decompiled_code:
int __fastcall set_RTS(int fd, int a2)
{
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

ioctl(fd, 0x5415uLL, v3);
if ( a2 )
{
print_log(5LL, "Set RTS");
v3[0] |= 4u;
}
else
{
print_log(5LL, "Clear RTS");
v3[0] &= 0xFFFFFFFB;
}
return ioctl(fd, 0x5418uLL, v3);
}

canonical_decompiled_code:
int __fastcall func6(int fd, int a2)
{
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

ioctl(fd, 0x5415uLL, v3);
if ( a2 )
{
print_log(5LL, "Set RTS");
v3[0] |= 4u;
}
else
{
print_log(5LL, "Clear RTS");
v3[0] &= 0xFFFFFFFB;
}
return ioctl(fd, 0x5418uLL, v3);
}

original_code:
void set_RTS(WEATHERSTATION ws, int val)
{
  int portstatus;
  ioctl(ws, 0x5415, &portstatus);
  if (val)
  {
    print_log(5,"Set RTS");
    portstatus |= 0x004;
  }
  else
  {
    print_log(5,"Clear RTS");
    portstatus &= ~0x004;
  }
  ioctl(ws, 0x5418, &portstatus);
}

canonical_original_code:
void set_RTS(int ws, int val)
{
  int portstatus;
  ioctl(ws, 0x5415, &portstatus);
  if (val)
  {
    print_log(5,"Set RTS");
    portstatus |= 0x004;
  }
  else
  {
    print_log(5,"Clear RTS");
    portstatus &= ~0x004;
  }
  ioctl(ws, 0x5418, &portstatus);
}

variable_types: ws int


decompiled_code:
__int64 __fastcall get_DSR(int a1)
{
unsigned int v1; // er12
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

ioctl(a1, 0x5415uLL, v3);
v1 = v3[0] & 0x100;
if ( (v3[0] & 0x100) != 0 )
{
print_log(5LL, "Got DSR = 1");
result = 1LL;
}
else
{
print_log(5LL, "Got DSR = 0");
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
unsigned int v1; // er12
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

ioctl(a1, 0x5415uLL, v3);
v1 = v3[0] & 0x100;
if ( (v3[0] & 0x100) != 0 )
{
print_log(5LL, "Got DSR = 1");
result = 1LL;
}
else
{
print_log(5LL, "Got DSR = 0");
result = v1;
}
return result;
}

original_code:
int get_DSR(WEATHERSTATION ws)
{
  int portstatus;
  ioctl(ws, 0x5415, &portstatus);
  if (portstatus & 0x100)
  {
    print_log(5,"Got DSR = 1");
    return 1;
  }
  else
  {
    print_log(5,"Got DSR = 0");
    return 0;
  }
}

canonical_original_code:
int get_DSR(int ws)
{
  int portstatus;
  ioctl(ws, 0x5415, &portstatus);
  if (portstatus & 0x100)
  {
    print_log(5,"Got DSR = 1");
    return 1;
  }
  else
  {
    print_log(5,"Got DSR = 0");
    return 0;
  }
}


decompiled_code:
__int64 __fastcall get_CTS(int a1)
{
unsigned int v1; // er12
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

ioctl(a1, 0x5415uLL, v3);
v1 = v3[0] & 0x20;
if ( (v3[0] & 0x20) != 0 )
{
print_log(5LL, "Got CTS = 1");
result = 1LL;
}
else
{
print_log(5LL, "Got CTS = 0");
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
unsigned int v1; // er12
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

ioctl(a1, 0x5415uLL, v3);
v1 = v3[0] & 0x20;
if ( (v3[0] & 0x20) != 0 )
{
print_log(5LL, "Got CTS = 1");
result = 1LL;
}
else
{
print_log(5LL, "Got CTS = 0");
result = v1;
}
return result;
}

original_code:
int get_CTS(WEATHERSTATION ws)
{
  int portstatus;
  ioctl(ws, 0x5415, &portstatus);
  if (portstatus & 0x020)
  {
    print_log(5,"Got CTS = 1");
    return 1;
  }
  else
  {
    print_log(5,"Got CTS = 0");
    return 0;
  }
}

canonical_original_code:
int get_CTS(int ws)
{
  int portstatus;
  ioctl(ws, 0x5415, &portstatus);
  if (portstatus & 0x020)
  {
    print_log(5,"Got CTS = 1");
    return 1;
  }
  else
  {
    print_log(5,"Got CTS = 0");
    return 0;
  }
}


decompiled_code:
int __fastcall sleep_short(int a1)
{
return usleep(1000 * a1);
}

canonical_decompiled_code:
int __fastcall func9(int a1)
{
return usleep(1000 * a1);
}

original_code:
void sleep_short(int milliseconds)
{
 usleep(milliseconds * 1000);
}

variable_types: milliseconds int


decompiled_code:
__int64 __fastcall open_weatherstation(char *file)
{
int v1; // eax
unsigned int v2; // er12
__int64 v3; // rbx
__int64 v4; // rbx
const char *v6; // rsi
struct termios v7; // [rsp+0h] [rbp-4058h] BYREF
char buf[16408]; // [rsp+40h] [rbp-4018h] BYREF

print_log(1LL, "open_weatherstation");
microdelay_init(1);
v1 = open(file, 258);
if ( v1 < 0 )
{
printf("\nUnable to open serial device %s\n", file);
exit(1);
}
v2 = v1;
if ( flock(v1, 2) < 0 )
{
perror("\nSerial device is locked by other program\n");
exit(1);
}
*(_QWORD *)&v7.c_cc[31] = 0LL;
*(_OWORD *)&v7.c_iflag = 0LL;
*(_OWORD *)&v7.c_line = 0LL;
*(_OWORD *)&v7.c_cc[15] = 0LL;
v7.c_ospeed = 0;
v7.c_cflag = 2224;
cfsetispeed(&v7, 7u);
cfsetospeed(&v7, 7u);
v7.c_oflag &= 0xFFFFFFFE;
v7.c_lflag = 0;
v7.c_iflag = 5;
*(_WORD *)&v7.c_cc[5] = 10;
if ( tcsetattr(v2, 0, &v7) < 0 )
{
printf("Unable to initialize serial device");
exit(0);
}
v3 = 499LL;
tcflush(v2, 2);
memset(buf, 0x55u, 0x1C0uLL);
write(v2, buf, 0x1C0uLL);
set_DTR(v2, 0);
set_RTS(v2, 0);
sleep_short(10);
while ( !(unsigned int)get_DSR(v2) )
{
sleep_short(10);
if ( !--v3 )
{
v6 = "Connection timeout 1";
LABEL_13:
print_log(2LL, v6);
puts("Connection timeout");
close_weatherstation(v2);
exit(0);
}
}
v4 = 499LL;
sleep_short(10);
while ( (unsigned int)get_DSR(v2) )
{
sleep_short(10);
if ( !--v4 )
{
v6 = "Connection timeout 2";
goto LABEL_13;
}
}
set_RTS(v2, 1);
set_DTR(v2, 1);
write(v2, buf, 0x1C0uLL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *file)
{
int v1; // eax
unsigned int v2; // er12
__int64 v3; // rbx
__int64 v4; // rbx
const char *v6; // rsi
struct termios v7; // [rsp+0h] [rbp-4058h] BYREF
char buf[16408]; // [rsp+40h] [rbp-4018h] BYREF

print_log(1LL, "open_weatherstation");
func2(1);
v1 = open(file, 258);
if ( v1 < 0 )
{
printf("\nUnable to open serial device %s\n", file);
exit(1);
}
v2 = v1;
if ( flock(v1, 2) < 0 )
{
perror("\nSerial device is locked by other program\n");
exit(1);
}
*(_QWORD *)&v7.c_cc[31] = 0LL;
*(_OWORD *)&v7.c_iflag = 0LL;
*(_OWORD *)&v7.c_line = 0LL;
*(_OWORD *)&v7.c_cc[15] = 0LL;
v7.c_ospeed = 0;
v7.c_cflag = 2224;
cfsetispeed(&v7, 7u);
cfsetospeed(&v7, 7u);
v7.c_oflag &= 0xFFFFFFFE;
v7.c_lflag = 0;
v7.c_iflag = 5;
*(_WORD *)&v7.c_cc[5] = 10;
if ( tcsetattr(v2, 0, &v7) < 0 )
{
printf("Unable to initialize serial device");
exit(0);
}
v3 = 499LL;
tcflush(v2, 2);
memset(buf, 0x55u, 0x1C0uLL);
write(v2, buf, 0x1C0uLL);
func5(v2, 0);
func6(v2, 0);
func9(10);
while ( !(unsigned int)func7(v2) )
{
func9(10);
if ( !--v3 )
{
v6 = "Connection timeout 1";
LABEL_13:
print_log(2LL, v6);
puts("Connection timeout");
func4(v2);
exit(0);
}
}
v4 = 499LL;
func9(10);
while ( (unsigned int)func7(v2) )
{
func9(10);
if ( !--v4 )
{
v6 = "Connection timeout 2";
goto LABEL_13;
}
}
func6(v2, 1);
func5(v2, 1);
write(v2, buf, 0x1C0uLL);
return v2;
}

original_code:
WEATHERSTATION open_weatherstation (char *device) {
  WEATHERSTATION ws;
  struct termios adtio;
  unsigned char buffer[16384];
  long i;
  print_log(1,"open_weatherstation");
  microdelay_init(1);
  if ((ws = open(device, 02 | 0400)) < 0)
  {
    printf("\nUnable to open serial device %s\n", device);
    exit(1);
  }
  if ( flock(ws, 2) < 0 ) {
    perror("\nSerial device is locked by other program\n");
    exit(1);
  }
  memset(&adtio, 0, sizeof(adtio));
  adtio.c_cflag &= ~0000400;
  adtio.c_cflag &= ~0000100;
  adtio.c_cflag &= ~0000060;
  adtio.c_cflag |= 0000060;
  adtio.c_cflag |= 0000200;
  adtio.c_cflag &= ~0002000;
  adtio.c_cflag &= ~020000000000;
  adtio.c_cflag |= 0004000;
  cfsetispeed(&adtio, 0000007);
  cfsetospeed(&adtio, 0000007);
  adtio.c_lflag = 0;
  adtio.c_iflag = 0000001|0000004;
  adtio.c_oflag &= ~0000001;
  adtio.c_cc[5] = 10;
  adtio.c_cc[6] = 0;
  if (tcsetattr(ws, 0, &adtio) < 0)
  {
   printf("Unable to initialize serial device");
   exit(0);
  }
  tcflush(ws, 2);
  for (i = 0; i < 448; i++) {
    buffer[i] = 'U';
  }
  write(ws, buffer, 448);
  set_DTR(ws,0);
  set_RTS(ws,0);
  i = 0;
  do {
    sleep_short(10);
    i++;
  } while (i < 500 && !get_DSR(ws));
  if (i == 500)
  {
    print_log(2,"Connection timeout 1");
    printf ("Connection timeout\n");
    close_weatherstation(ws);
    exit(0);
  }
  i = 0;
  do {
    sleep_short(10);
    i++;
  } while (i < 500 && get_DSR(ws));
  if (i != 500) {
    set_RTS(ws,1);
    set_DTR(ws,1);
  } else {
    print_log(2,"Connection timeout 2");
    printf ("Connection timeout\n");
    close_weatherstation(ws);
    exit(0);
  }
  write(ws, buffer, 448);
  return ws;
}

canonical_original_code:
int open_weatherstation(char *device) {
  int ws;
  struct termios adtio;
  unsigned char buffer[16384];
  long i;
  print_log(1,"open_weatherstation");
  microdelay_init(1);
  if ((ws = open(device, 02 | 0400)) < 0)
  {
    printf("\nUnable to open serial device %s\n", device);
    exit(1);
  }
  if ( flock(ws, 2) < 0 ) {
    perror("\nSerial device is locked by other program\n");
    exit(1);
  }
  memset(&adtio, 0, sizeof(adtio));
  adtio.c_cflag &= ~0000400;
  adtio.c_cflag &= ~0000100;
  adtio.c_cflag &= ~0000060;
  adtio.c_cflag |= 0000060;
  adtio.c_cflag |= 0000200;
  adtio.c_cflag &= ~0002000;
  adtio.c_cflag &= ~020000000000;
  adtio.c_cflag |= 0004000;
  cfsetispeed(&adtio, 0000007);
  cfsetospeed(&adtio, 0000007);
  adtio.c_lflag = 0;
  adtio.c_iflag = 0000001|0000004;
  adtio.c_oflag &= ~0000001;
  adtio.c_cc[5] = 10;
  adtio.c_cc[6] = 0;
  if (tcsetattr(ws, 0, &adtio) < 0)
  {
   printf("Unable to initialize serial device");
   exit(0);
  }
  tcflush(ws, 2);
  for (i = 0; i < 448; i++) {
    buffer[i] = 'U';
  }
  write(ws, buffer, 448);
  set_DTR(ws,0);
  set_RTS(ws,0);
  i = 0;
  do {
    sleep_short(10);
    i++;
  } while (i < 500 && !get_DSR(ws));
  if (i == 500)
  {
    print_log(2,"Connection timeout 1");
    printf ("Connection timeout\n");
    close_weatherstation(ws);
    exit(0);
  }
  i = 0;
  do {
    sleep_short(10);
    i++;
  } while (i < 500 && get_DSR(ws));
  if (i != 500) {
    set_RTS(ws,1);
    set_DTR(ws,1);
  } else {
    print_log(2,"Connection timeout 2");
    printf ("Connection timeout\n");
    close_weatherstation(ws);
    exit(0);
  }
  write(ws, buffer, 448);
  return ws;
}

variable_types:
device
char *

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

variable_types:
buffer
unsigned char [16384]

variable_types: i long


nanodelay

decompiled_code:
__int64 nanodelay()
{
return microdelay(10);
}

canonical_decompiled_code:
__int64 func11()
{
return func3(10);
}

original_code:
void nanodelay() {
 microdelay(10);
}

canonical_original_code:
void nanodelay() {
 microdelay(10);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char *v4; // r13
unsigned int v5; // er12
int v6; // er13
__int64 v7; // rbp
int v8; // ebx
__int64 v9; // r14
unsigned int v10; // er15
char *v11; // rsi
unsigned int v12; // eax
int v14; // ecx
struct tm *v15; // r12
size_t v16; // rax
int v17; // [rsp+4h] [rbp-8044h]
FILE *stream; // [rsp+8h] [rbp-8040h]
time_t s[4103]; // [rsp+10h] [rbp-8038h] BYREF

if ( (unsigned int)(argc - 2) > 1 )
{
fwrite("E: no serial device specified.\n", 1uLL, 0x1FuLL, stderr);
print_usage();
}
v3 = argv[1];
if ( argc == 3 )
{
v4 = (char *)argv[2];
}
else
{
s[0] = time(0LL);
v15 = localtime(s);
if ( !v15 )
{
perror("localtime");
exit(1);
}
v4 = (char *)malloc(0x32uLL);
strcpy(v4, "tfa.dump.");
v16 = strlen(v4);
strftime(&v4[v16], 8 - v16, "%Y%m%d.%H%M", v15);
}
if ( geteuid() )
{
fwrite("E: this program needs root privileges to do direct port I/O.\n", 1uLL, 0x3DuLL, stderr);
exit(1);
}
v5 = open_weatherstation(v3);
stream = fopen(v4, "w");
if ( !stream )
{
printf("Cannot open file %s\n", v4);
exit(1);
}
printf("Dumping %d bytes to %s.\n", 0x7FFFLL, v4);
v6 = 0;
memset(s, 170, 0x8000uLL);
v17 = 0;
LABEL_7:
v7 = v6;
v8 = v6;
while ( 1 )
{
v6 = v8;
if ( v8 > 32766 )
break;
v9 = 1000LL;
v10 = 1000;
if ( v8 > 31767 )
{
v9 = (unsigned int)(0x7FFF - v8);
v10 = 0x7FFF - v8;
}
printf(" ... reading %d bytes beginning from %d\n", v10, (unsigned int)v8);
v8 += 1000;
nanodelay();
eeprom_seek(v5, v7);
v11 = (char *)s + v7;
v7 += 1000LL;
v12 = eeprom_read(v5, v11, v9);
if ( v10 != v12 )
{
if ( v12 != -1 || (v14 = v17, v17 > 9) )
{
printf(" >>> got %d bytes\n", v12);
fwrite("E: got less than requested bytes, dump is probably unusable.\n", 1uLL, 0x3DuLL, stderr);
break;
}
++v17;
fprintf(stderr, "W: eeprom ack failed, retrying read (retries left: %d).\n", (unsigned int)(10 - (v14 + 1)));
close_weatherstation(v5);
v5 = open_weatherstation("/dev/ttyS0");
goto LABEL_7;
}
v17 = 0;
}
fwrite(s, 0x7FFFuLL, 1uLL, stream);
close_weatherstation(v5);
fclose(stream);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char *v4; // r13
unsigned int v5; // er12
int v6; // er13
__int64 v7; // rbp
int v8; // ebx
__int64 v9; // r14
unsigned int v10; // er15
char *v11; // rsi
unsigned int v12; // eax
int v14; // ecx
struct tm *v15; // r12
size_t v16; // rax
int v17; // [rsp+4h] [rbp-8044h]
FILE *stream; // [rsp+8h] [rbp-8040h]
time_t s[4103]; // [rsp+10h] [rbp-8038h] BYREF

if ( (unsigned int)(argc - 2) > 1 )
{
fwrite("E: no serial device specified.\n", 1uLL, 0x1FuLL, stderr);
func0();
}
v3 = argv[1];
if ( argc == 3 )
{
v4 = (char *)argv[2];
}
else
{
s[0] = time(0LL);
v15 = localtime(s);
if ( !v15 )
{
perror("localtime");
exit(1);
}
v4 = (char *)malloc(0x32uLL);
strcpy(v4, "tfa.dump.");
v16 = strlen(v4);
strftime(&v4[v16], 8 - v16, "%Y%m%d.%H%M", v15);
}
if ( geteuid() )
{
fwrite("E: this program needs root privileges to do direct port I/O.\n", 1uLL, 0x3DuLL, stderr);
exit(1);
}
v5 = open_weatherstation(v3);
stream = fopen(v4, "w");
if ( !stream )
{
printf("Cannot open file %s\n", v4);
exit(1);
}
printf("Dumping %d bytes to %s.\n", 0x7FFFLL, v4);
v6 = 0;
memset(s, 170, 0x8000uLL);
v17 = 0;
LABEL_7:
v7 = v6;
v8 = v6;
while ( 1 )
{
v6 = v8;
if ( v8 > 32766 )
break;
v9 = 1000LL;
v10 = 1000;
if ( v8 > 31767 )
{
v9 = (unsigned int)(0x7FFF - v8);
v10 = 0x7FFF - v8;
}
printf(" ... reading %d bytes beginning from %d\n", v10, (unsigned int)v8);
v8 += 1000;
nanodelay();
eeprom_seek(v5, v7);
v11 = (char *)s + v7;
v7 += 1000LL;
v12 = eeprom_read(v5, v11, v9);
if ( v10 != v12 )
{
if ( v12 != -1 || (v14 = v17, v17 > 9) )
{
printf(" >>> got %d bytes\n", v12);
fwrite("E: got less than requested bytes, dump is probably unusable.\n", 1uLL, 0x3DuLL, stderr);
break;
}
++v17;
fprintf(stderr, "W: eeprom ack failed, retrying read (retries left: %d).\n", (unsigned int)(10 - (v14 + 1)));
close_weatherstation(v5);
v5 = open_weatherstation("/dev/ttyS0");
goto LABEL_7;
}
v17 = 0;
}
fwrite(s, 0x7FFFuLL, 1uLL, stream);
close_weatherstation(v5);
fclose(stream);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 WEATHERSTATION ws;
 unsigned char data[32768];
 char* serial_device;
 int sensors;
 int block_size = 0;
 int data_offset = 0x64;
 int start_adr;
 int record_interval;
 int skip, skip_offset;
 int sequential = 0;
 Record r;
 Record rnext;
 time_t t;
 struct tm *tm;
 memset(data, 0xAA, 32768);
 if (argc != 2) {
  fprintf(stderr, "E: no serial device specified.\n");
  print_usage();
 }
 serial_device = argv[1];
 if (geteuid() != 0) {
  fprintf(stderr, "E: this program needs root privileges to do direct port I/O.\n");
  exit(1);
 }
 t = time(((void *)0));
 tm = localtime(&t);
 if (tm == ((void *)0)) {
  perror("localtime");
  exit(1);
 }
 ws = open_weatherstation(serial_device);
 nanodelay();
 eeprom_seek(ws, 0);
 eeprom_read(ws, data, data_offset);
 sensors = data[0x0C];
 sensors++;
 if (sensors == 4 || sensors == 5) block_size = 15;
 if (sensors == 6) block_size = 20;
 printf("Using sensors=%d\n", sensors);
 if (block_size == 0) {
  fprintf(stderr,"E: dont understand this format, found sensors=%d\n", sensors);
  exit(1);
 }
 printf("Saved time: %02X:%02X \n", data[1], data[0]);
 skip = ((data[0xA] & 0x0F) * 100) + ((data[0x09]>>4) * 10) + (data[0x09] & 0x0F);
 printf("RecordCount: %d    (other interesting shid: %02X %02X )\n", skip, data[0x0B], data[0x0A] & 0xF0);
 printf("Scanning for two connected records\n");
 start_adr = data_offset;
 while(start_adr < (data_offset + block_size*50)) {
  int read_len = (2*block_size);
  eeprom_seek(ws, start_adr);
  eeprom_read(ws, data + start_adr, read_len);
  record_parse(data+data_offset, &r, sensors);
  record_parse(data+data_offset+block_size, &rnext, sensors);
  record_interval = rnext.time_m - r.time_m;
  if (record_interval > 0 && record_interval < 30) {
   break;
  }
  record_interval = -1;
  start_adr += read_len;
 }
 if (record_interval == -1) {
  fprintf(stderr,"E: can't discover recording interval\n");
  exit(1);
 }
 printf("%02d.%02d.20%02d %02d:%02d \n", r.date_d, r.date_m, r.date_y, r.time_h, r.time_m);
 printf("%02d.%02d.20%02d %02d:%02d \n", rnext.date_d, rnext.date_m, rnext.date_y, rnext.time_h, rnext.time_m);
 printf("Recording interval: %d\n", record_interval);
 skip = 0;
 if (tm->tm_year-(2000+r.date_y) > 1 || tm->tm_mon-r.date_m > 1) {
  sequential = 1;
 }
 if (tm->tm_hour-r.time_h > 1) {
  skip += (tm->tm_hour-r.time_h)*60/record_interval;
  printf("hours off: %d\n", (tm->tm_hour-r.time_h));
  skip += (tm->tm_min-r.time_m)/record_interval;
 }
 if (tm->tm_hour-r.time_h == 0 && tm->tm_min-r.time_m > (2*record_interval)) {
  printf("only correcting minutes\n");
  skip += (tm->tm_min-r.time_m)/record_interval;
 }
 skip -= 5;
 printf("skip=%d, seq=%d\n", skip, sequential);
 if (skip > 1100 || skip < 0) {
  sequential = 1;
 }
 if (sequential == 1) {
  printf("Falling back to sequential read.\n");
  printf("not implemented ;)\n");
 } else {
  printf("Jumping to record %d\n", skip);
  skip_offset = data_offset + skip*block_size;
  eeprom_seek(ws, skip_offset);
  eeprom_read(ws, data+skip_offset, block_size*2);
  record_parse(data+skip_offset, &r, sensors);
  printf("%02d.%02d.20%02d %02d:%02d ",
   r.date_d, r.date_m, r.date_y, r.time_h, r.time_m);
  printf("\n");
 }
 close_weatherstation(ws);
 return(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int ws;
 unsigned char data[32768];
 char *serial_device;
 int sensors;
 int block_size = 0;
 int data_offset = 0x64;
 int start_adr;
 int record_interval;
 int skip; int skip_offset;
 int sequential = 0;
 struct _Record r;
 struct _Record rnext;
 long t;
 struct tm *tm;
 memset(data, 0xAA, 32768);
 if (argc != 2) {
  fprintf(stderr, "E: no serial device specified.\n");
  print_usage();
 }
 serial_device = argv[1];
 if (geteuid() != 0) {
  fprintf(stderr, "E: this program needs root privileges to do direct port I/O.\n");
  exit(1);
 }
 t = time(((void *)0));
 tm = localtime(&t);
 if (tm == ((void *)0)) {
  perror("localtime");
  exit(1);
 }
 ws = open_weatherstation(serial_device);
 nanodelay();
 eeprom_seek(ws, 0);
 eeprom_read(ws, data, data_offset);
 sensors = data[0x0C];
 sensors++;
 if (sensors == 4 || sensors == 5) block_size = 15;
 if (sensors == 6) block_size = 20;
 printf("Using sensors=%d\n", sensors);
 if (block_size == 0) {
  fprintf(stderr,"E: dont understand this format, found sensors=%d\n", sensors);
  exit(1);
 }
 printf("Saved time: %02X:%02X \n", data[1], data[0]);
 skip = ((data[0xA] & 0x0F) * 100) + ((data[0x09]>>4) * 10) + (data[0x09] & 0x0F);
 printf("RecordCount: %d    (other interesting shid: %02X %02X )\n", skip, data[0x0B], data[0x0A] & 0xF0);
 printf("Scanning for two connected records\n");
 start_adr = data_offset;
 while(start_adr < (data_offset + block_size*50)) {
  int read_len = (2*block_size);
  eeprom_seek(ws, start_adr);
  eeprom_read(ws, data + start_adr, read_len);
  record_parse(data+data_offset, &r, sensors);
  record_parse(data+data_offset+block_size, &rnext, sensors);
  record_interval = rnext.time_m - r.time_m;
  if (record_interval > 0 && record_interval < 30) {
   break;
  }
  record_interval = -1;
  start_adr += read_len;
 }
 if (record_interval == -1) {
  fprintf(stderr,"E: can't discover recording interval\n");
  exit(1);
 }
 printf("%02d.%02d.20%02d %02d:%02d \n", r.date_d, r.date_m, r.date_y, r.time_h, r.time_m);
 printf("%02d.%02d.20%02d %02d:%02d \n", rnext.date_d, rnext.date_m, rnext.date_y, rnext.time_h, rnext.time_m);
 printf("Recording interval: %d\n", record_interval);
 skip = 0;
 if (tm->tm_year-(2000+r.date_y) > 1 || tm->tm_mon-r.date_m > 1) {
  sequential = 1;
 }
 if (tm->tm_hour-r.time_h > 1) {
  skip += (tm->tm_hour-r.time_h)*60/record_interval;
  printf("hours off: %d\n", (tm->tm_hour-r.time_h));
  skip += (tm->tm_min-r.time_m)/record_interval;
 }
 if (tm->tm_hour-r.time_h == 0 && tm->tm_min-r.time_m > (2*record_interval)) {
  printf("only correcting minutes\n");
  skip += (tm->tm_min-r.time_m)/record_interval;
 }
 skip -= 5;
 printf("skip=%d, seq=%d\n", skip, sequential);
 if (skip > 1100 || skip < 0) {
  sequential = 1;
 }
 if (sequential == 1) {
  printf("Falling back to sequential read.\n");
  printf("not implemented ;)\n");
 } else {
  printf("Jumping to record %d\n", skip);
  skip_offset = data_offset + skip*block_size;
  eeprom_seek(ws, skip_offset);
  eeprom_read(ws, data+skip_offset, block_size*2);
  record_parse(data+skip_offset, &r, sensors);
  printf("%02d.%02d.20%02d %02d:%02d ",
   r.date_d, r.date_m, r.date_y, r.time_h, r.time_m);
  printf("\n");
 }
 close_weatherstation(ws);
 return(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
data
unsigned char [32768]

variable_types: sensors int

variable_types: skip int

variable_types: sequential int

variable_types: struct _Record { int date_d; int time_h; int h_in; float t_in; }

variable_types: t long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
void __noreturn print_usage()
{
fwrite("Usage: dump_tfa /dev/ttyS0 <dumpfile>\n", 1uLL, 0x26uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("Usage: dump_tfa /dev/ttyS0 <dumpfile>\n", 1uLL, 0x26uLL, stderr);
exit(1);
}

original_code:
void print_usage() {
 fprintf(stderr, "Usage: realtime /dev/ttyS0\n");
 exit(1);
}


printTemp

decompiled_code:
int __fastcall printTemp(const char *a1, float a2)
{
int result; // eax

if ( a2 != 255.0 )
result = printf("T%s: %02.1f ", a1, a2);
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, float a2)
{
int result; // eax

if ( a2 != 255.0 )
result = printf("T%s: %02.1f ", a1, a2);
return result;
}

original_code:
void printTemp(const char* name, float value) {
 if (value == 0xFF) return;
 printf("T%s: %02.1f ", name, value);
}

canonical_original_code:
void printTemp(char *name, float value) {
 if (value == 0xFF) return;
 printf("T%s: %02.1f ", name, value);
}

variable_types:
name
char *

variable_types: value float


printHumidity

decompiled_code:
int __fastcall printHumidity(const char *a1, float a2)
{
int result; // eax

if ( a2 != 255.0 )
result = printf("H%s: %02.1f ", a1, a2);
return result;
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, float a2)
{
int result; // eax

if ( a2 != 255.0 )
result = printf("H%s: %02.1f ", a1, a2);
return result;
}

original_code:
void printHumidity(const char* name, float value) {
 if (value == 0xFF) return;
 printf("H%s: %02.1f ", name, value);
}

canonical_original_code:
void printHumidity(char *name, float value) {
 if (value == 0xFF) return;
 printf("H%s: %02.1f ", name, value);
}


variable_types:
data
void *

variable_types: struct _Record { int date_d; int time_h; int h_in; float t_in; } *

variable_types:
ptr
unsigned char *


decompiled_code:
int __fastcall sha256(char *src, const char *a2, const char *a3)
{
const char *v3; // r15
char *v5; // rbp
char *v6; // rbx
size_t v7; // rax
__int64 v8; // rdx
char *v9; // rdi
_BYTE v11[32]; // [rsp+0h] [rbp-138h] BYREF
char dest[112]; // [rsp+20h] [rbp-118h] BYREF
char v13[168]; // [rsp+90h] [rbp-A8h] BYREF

v3 = a3;
v5 = (char *)a3;
v6 = v11;
strcpy(dest, a2);
strncat(dest, src, 3uLL);
SHA256_Init(v13);
v7 = strlen(dest);
SHA256_Update(v13, dest, v7);
SHA256_Final(v11, v13);
do
{
v8 = (unsigned __int8)*v6;
v9 = v5;
++v6;
v5 += 2;
sprintf(v9, "%02x", v8);
}
while ( v6 != dest );
return printf("\n* FONCTION SHA256\n* SEL :%s\n* MOT :%s\n* HASH :%s\n\n", src, a2, v3);
}

canonical_decompiled_code:
int __fastcall func1(char *src, const char *a2, const char *a3)
{
const char *v3; // r15
char *v5; // rbp
char *v6; // rbx
size_t v7; // rax
__int64 v8; // rdx
char *v9; // rdi
_BYTE v11[32]; // [rsp+0h] [rbp-138h] BYREF
char dest[112]; // [rsp+20h] [rbp-118h] BYREF
char v13[168]; // [rsp+90h] [rbp-A8h] BYREF

v3 = a3;
v5 = (char *)a3;
v6 = v11;
strcpy(dest, a2);
strncat(dest, src, 3uLL);
SHA256_Init(v13);
v7 = strlen(dest);
SHA256_Update(v13, dest, v7);
SHA256_Final(v11, v13);
do
{
v8 = (unsigned __int8)*v6;
v9 = v5;
++v6;
v5 += 2;
sprintf(v9, "%02x", v8);
}
while ( v6 != dest );
return printf("\n* FONCTION SHA256\n* SEL :%s\n* MOT :%s\n* HASH :%s\n\n", src, a2, v3);
}

original_code:
void sha256(char* sel, char* mot, char tampon[100])
{
 char toHash[100];
 strcpy(toHash,mot);
 strncat(toHash,sel,3);
 unsigned char hash[32];
 SHA256_CTX sha256;
 SHA256_Init(&sha256);
 SHA256_Update(&sha256, toHash, strlen(toHash));
 SHA256_Final(hash, &sha256);
 int i=0;
 for(i=0;i<32;i++)
 {
  sprintf(tampon+(2*i), "%02x", hash[i]);
 }
 printf("\n* FONCTION SHA256\n* SEL  :%s\n* MOT  :%s\n* HASH :%s\n\n",sel,mot,tampon);
}

canonical_original_code:
void sha256(char *sel, char *mot, char tampon[100])
{
 char toHash[100];
 strcpy(toHash,mot);
 strncat(toHash,sel,3);
 unsigned char hash[32];
 struct SHA256state_st sha256;
 SHA256_Init(&sha256);
 SHA256_Update(&sha256, toHash, strlen(toHash));
 SHA256_Final(hash, &sha256);
 int i = 0;
 for(i=0;i<32;i++)
 {
  sprintf(tampon+(2*i), "%02x", hash[i]);
 }
 printf("\n* FONCTION SHA256\n* SEL  :%s\n* MOT  :%s\n* HASH :%s\n\n",sel,mot,tampon);
}

variable_types:
sel
char *

variable_types:
mot
char *

variable_types:
tampon
char [100]

variable_types:
toHash
char [100]

variable_types:
hash
unsigned char [32]

variable_types: struct SHA256state_st { unsigned int h[8]; unsigned int Nl; unsigned int data[16]; unsigned int num; }

variable_types: i int


print

decompiled_code:
int __fastcall print(const char *a1)
{
printf("%s", a1);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
printf("%s", a1);
return fflush(stdout);
}

original_code:
void print(char *s){
 printf("%s", s);
 fflush(stdout);
}

variable_types:
s
char *


flush

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

do
result = getchar();
while ( result != -1 && result != 10 );
return result;
}

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

do
result = getchar();
while ( result != -1 && result != 10 );
return result;
}

original_code:
void flush(){
 int c;
 while ((c = getchar ()) != '\n' && c != (-1));
}

variable_types: c int


decompiled_code:
int __fastcall aff_info(__int64 a1)
{
struct in_addr *v1; // rdx
unsigned __int16 v2; // bx
char *v3; // rax

v2 = _bswap_16(*(_WORD *)(a1 + 2));
v3 = inet_ntoa(v1[1]);
printf("[%s:%d]", v3, v2);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
struct in_addr *v1; // rdx
unsigned __int16 v2; // bx
char *v3; // rax

v2 = func0(*(_WORD *)(a1 + 2));
v3 = inet_ntoa(v1[1]);
printf("[%s:%d]", v3, v2);
return fflush(stdout);
}

original_code:
void aff_info(struct sockaddr_in* cible){
 printf("[%s:%d]",
  inet_ntoa((struct in_addr) cible->sin_addr),
  ntohs(cible->sin_port)
  );
 fflush(stdout);
}

canonical_original_code:
void aff_info(struct sockaddr_in *cible){
 printf("[%s:%d]",
  inet_ntoa((struct in_addr) cible->sin_addr),
  ntohs(cible->sin_port)
  );
 fflush(stdout);
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
int v5; // er13
int *v6; // rax
int *v7; // r14
unsigned __int16 v8; // ax
int v9; // ebp
__int16 v10; // bx
char *v11; // rdx
char *v12; // rdx
char *v13; // rdx
char *v14; // rax
__int16 v15[2]; // [rsp+8h] [rbp-50h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr v18; // [rsp+20h] [rbp-38h] BYREF

if ( argc <= 2 )
{
print("AUTHSERV 1.0\n");
v3 = connexionDb("AUTHSERV 1.0\n", argv);
v4 = v3;
if ( argc == 2 )
dropDb(v3);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
addr_len = 16;
print(aPortD);
_isoc99_scanf("%6ud", v15);
flush();
*(_WORD *)addr.sa_data = _bswap_16(v15[0]);
printf(aCr);
v5 = socket(2, 1, 0);
v6 = _errno_location();
v7 = v6;
if ( v5 == -1 )
{
v11 = strerror(*v6);
fprintf(stderr, "\n :-( FAIL SOCKET : %s\n", v11);
}
else
{
printf(aR);
if ( bind(v5, &addr, 0x10u) < 0 )
{
v12 = strerror(*v7);
fprintf(stderr, "\n :-( FAIL BIND : %s\n", v12);
}
else
{
puts(aR_0);
if ( listen(v5, 1) )
{
v14 = strerror(*v7);
fprintf(stderr, "\nFAIL LISTEN : %s\n", v14);
exit(-1);
}
while ( 1 )
{
v8 = _bswap_16(*(__int16 *)addr.sa_data);
printf("--- En attente de la connexion de COMSERV sur le port %d ---\n", v8);
v9 = accept(v5, &v18, &addr_len);
if ( v9 < 0 )
break;
print(aComservConnect);
aff_info((__int64)&v18);
print("\n\n");
do
{
v10 = reading(v4, v9);
sleep(0);
}
while ( v10 );
print("\nX X X Deconnexion de COMSERV. X X X\n");
close(v9);
}
v13 = strerror(*v7);
fprintf(stderr, "\n:-( FAIL ACCEPT : %s\n", v13);
}
}
}
else
{
fprintf(stderr, "usage: %s\n", *argv);
}
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
int v5; // er13
int *v6; // rax
int *v7; // r14
unsigned __int16 v8; // ax
int v9; // ebp
__int16 v10; // bx
char *v11; // rdx
char *v12; // rdx
char *v13; // rdx
char *v14; // rax
__int16 v15[2]; // [rsp+8h] [rbp-50h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr v18; // [rsp+20h] [rbp-38h] BYREF

if ( argc <= 2 )
{
func7("AUTHSERV 1.0\n");
v3 = func3("AUTHSERV 1.0\n", argv);
v4 = v3;
if ( argc == 2 )
func4(v3);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
addr_len = 16;
func7(aPortD);
_isoc99_scanf("%6ud", v15);
func8();
*(_WORD *)addr.sa_data = func0(v15[0]);
printf(aCr);
v5 = socket(2, 1, 0);
v6 = _errno_location();
v7 = v6;
if ( v5 == -1 )
{
v11 = strerror(*v6);
fprintf(stderr, "\n :-( FAIL SOCKET : %s\n", v11);
}
else
{
printf(aR);
if ( bind(v5, &addr, 0x10u) < 0 )
{
v12 = strerror(*v7);
fprintf(stderr, "\n :-( FAIL BIND : %s\n", v12);
}
else
{
puts(aR_0);
if ( listen(v5, 1) )
{
v14 = strerror(*v7);
fprintf(stderr, "\nFAIL LISTEN : %s\n", v14);
exit(-1);
}
while ( 1 )
{
v8 = func0(*(__int16 *)addr.sa_data);
printf("--- En attente de la connexion de COMSERV sur le port %d ---\n", v8);
v9 = accept(v5, &v18, &addr_len);
if ( v9 < 0 )
break;
func7(aComservConnect);
func9((__int64)&v18);
func7("\n\n");
do
{
v10 = func10(v4, v9);
sleep(0);
}
while ( v10 );
func7("\nX X X Deconnexion de COMSERV. X X X\n");
close(v9);
}
v13 = strerror(*v7);
fprintf(stderr, "\n:-( FAIL ACCEPT : %s\n", v13);
}
}
}
else
{
fprintf(stderr, "usage: %s\n", *argv);
}
exit(1);
}

original_code:
int main(int argc, char** argv)
{
  int nb_joueurs_recu;
  char* pseudos[9] = {((void *)0),((void *)0),((void *)0),((void *)0),((void *)0),((void *)0),((void *)0),((void *)0),((void *)0)};
  int nb_case_col_map_recu;
  int nb_case_lig_map_recu;
  int nb_case_tot_map;
  int i;
  char* desc_map;
  int x, y;
  nb_joueurs_recu = 9;
  pseudos[0] = "Bidouille";
  pseudos[1] = "Tamaman";
  pseudos[2] = "Natsouille";
  pseudos[3] = "Seip'";
  pseudos[4] = "Unidouille";
  pseudos[5] = "Nocta";
  pseudos[6] = "";
  pseudos[7] = "éééééé";
  pseudos[8] = "YOPYOPYOP";
  nb_case_col_map_recu = 20;
  nb_case_lig_map_recu = 15;
  nb_case_tot_map = nb_case_col_map_recu * nb_case_lig_map_recu;
  desc_map = malloc ((nb_case_tot_map + 1) * sizeof(char));
  for (i=0; i < nb_case_tot_map; i++) desc_map[i] = 'O';
  desc_map[nb_case_tot_map] = '\0';
  desc_map[10] = '1';
  desc_map[13] = '2';
  desc_map[23] = '3';
  desc_map[45] = '4';
  desc_map[52] = '5';
  desc_map[53] = '6';
  desc_map[63] = '7';
  desc_map[68] = '8';
  desc_map[70] = '9';
  desc_map[72] = 'X';
  desc_map[83] = 'D';
  initialisation_sdl(nb_joueurs_recu, pseudos, nb_case_col_map_recu, nb_case_lig_map_recu);
  attendre_clic_croix();
  update_sdl(2, 1, "15", desc_map);
  update_sdl(0, 8, "5", desc_map);
  a_toi_de_jouer(&x, &y, desc_map);
  desc_map[((y * nb_case_col_map_recu) + x)] = 'D';
  update_sdl(3, 3, "15", desc_map);
  a_toi_de_jouer(&x, &y, desc_map);
  desc_map[((y * nb_case_col_map_recu) + x)] = 'X';
  update_sdl(3, 4, "6", desc_map);
  attendre_clic_croix();
  a_toi_de_jouer(&x, &y, desc_map);
  desc_map[((y * nb_case_col_map_recu) + x)] = 'D';
  update_sdl(9, 5, "79", desc_map);
  attendre_clic_croix();
  victoire(3);
  attendre_fermeture_sdl();
  free(desc_map);
  arret_sdl();
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int nb_joueurs_recu;
  char *pseudos[9] = {((void *)0),((void *)0),((void *)0),((void *)0),((void *)0),((void *)0),((void *)0),((void *)0),((void *)0)};
  int nb_case_col_map_recu;
  int nb_case_lig_map_recu;
  int nb_case_tot_map;
  int i;
  char *desc_map;
  int x; int y;
  nb_joueurs_recu = 9;
  pseudos[0] = "Bidouille";
  pseudos[1] = "Tamaman";
  pseudos[2] = "Natsouille";
  pseudos[3] = "Seip'";
  pseudos[4] = "Unidouille";
  pseudos[5] = "Nocta";
  pseudos[6] = "";
  pseudos[7] = "éééééé";
  pseudos[8] = "YOPYOPYOP";
  nb_case_col_map_recu = 20;
  nb_case_lig_map_recu = 15;
  nb_case_tot_map = nb_case_col_map_recu * nb_case_lig_map_recu;
  desc_map = malloc ((nb_case_tot_map + 1) * sizeof(char));
  for (i=0; i < nb_case_tot_map; i++) desc_map[i] = 'O';
  desc_map[nb_case_tot_map] = '\0';
  desc_map[10] = '1';
  desc_map[13] = '2';
  desc_map[23] = '3';
  desc_map[45] = '4';
  desc_map[52] = '5';
  desc_map[53] = '6';
  desc_map[63] = '7';
  desc_map[68] = '8';
  desc_map[70] = '9';
  desc_map[72] = 'X';
  desc_map[83] = 'D';
  initialisation_sdl(nb_joueurs_recu, pseudos, nb_case_col_map_recu, nb_case_lig_map_recu);
  attendre_clic_croix();
  update_sdl(2, 1, "15", desc_map);
  update_sdl(0, 8, "5", desc_map);
  a_toi_de_jouer(&x, &y, desc_map);
  desc_map[((y * nb_case_col_map_recu) + x)] = 'D';
  update_sdl(3, 3, "15", desc_map);
  a_toi_de_jouer(&x, &y, desc_map);
  desc_map[((y * nb_case_col_map_recu) + x)] = 'X';
  update_sdl(3, 4, "6", desc_map);
  attendre_clic_croix();
  a_toi_de_jouer(&x, &y, desc_map);
  desc_map[((y * nb_case_col_map_recu) + x)] = 'D';
  update_sdl(9, 5, "79", desc_map);
  attendre_clic_croix();
  victoire(3);
  attendre_fermeture_sdl();
  free(desc_map);
  arret_sdl();
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
pseudos
char *[9]

variable_types: x int

variable_types: y int


decompiled_code:
void __fastcall __noreturn attente_fermeture(__int64 a1)
{
attendre_fermeture_sdl_ou_changement_etat(a1, &g_thread_exit);
puts(s);
arret_sdl();
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(__int64 a1)
{
attendre_fermeture_sdl_ou_changement_etat(a1, &g_thread_exit);
puts(s);
arret_sdl();
exit(-1);
}

original_code:
void* attente_fermeture (void* arg)
{
  attendre_fermeture_sdl_ou_changement_etat((bool*) arg, g_thread_exit);
  printf("Clic croix SDL détecté.\n");
  arret_sdl();
  exit(-1);
  return arg;
}

canonical_original_code:
void *attente_fermeture(void *arg)
{
  attendre_fermeture_sdl_ou_changement_etat((short *) arg, g_thread_exit);
  printf("Clic croix SDL détecté.\n");
  arret_sdl();
  exit(-1);
  return arg;
}

variable_types:
arg
void *

return_type: void *


print

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
printf("%s", a1);
return fflush(stdout);
}

canonical_original_code:
void print(char *s){
 printf("%s", s);
 fflush(stdout);
}


flush

decompiled_code:
_BOOL8 flush(void)
{
_BOOL8 result; // rax
int v1; // [rsp+Ch] [rbp-4h]

do
{
v1 = getchar();
result = v1 != 10 && v1 != -1;
}
while ( result );
return result;
}

canonical_decompiled_code:
_BOOL8 func1(void)
{
_BOOL8 result; // rax
int v1; // [rsp+Ch] [rbp-4h]

do
{
v1 = getchar();
result = v1 != 10 && v1 != -1;
}
while ( result );
return result;
}

canonical_original_code:
void flush(){
 int c;
 while ((c = getchar ()) != '\n' && c != (-1));
}


decompiled_code:
int __fastcall aff_info(sockaddr_in *a1)
{
unsigned int v1; // ebx
char *v2; // rax

v1 = ntohs(a1->sin_port);
v2 = inet_ntoa(a1->sin_addr);
printf("[%s::%d]", v2, v1);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func2(sockaddr_in *a1)
{
unsigned int v1; // ebx
char *v2; // rax

v1 = ntohs(a1->sin_port);
v2 = inet_ntoa(a1->sin_addr);
printf("[%s::%d]", v2, v1);
return fflush(stdout);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE *v3; // r14
_BYTE *v4; // rbp
_BYTE *v5; // r13
_BYTE *v6; // rax
void *v7; // r12
char *v8; // rdi
const char **v10; // [rsp+0h] [rbp-218h] BYREF
int v11; // [rsp+Ch] [rbp-20Ch] BYREF
char v12[8]; // [rsp+10h] [rbp-208h] BYREF
char *v13; // [rsp+18h] [rbp-200h]
_BYTE *v14; // [rsp+140h] [rbp-D8h]
_BYTE *v15; // [rsp+158h] [rbp-C0h]
_BYTE *v16; // [rsp+1C0h] [rbp-58h]
_BYTE *v17; // [rsp+1C8h] [rbp-50h]
int v18; // [rsp+1DCh] [rbp-3Ch]

v11 = argc;
v10 = argv;
v3 = malloc(1uLL);
v4 = malloc(1uLL);
v5 = malloc(1uLL);
v6 = malloc(1uLL);
*v3 = 0;
*v6 = 0;
v7 = v6;
v17 = v6;
*v4 = 0;
*v5 = 0;
v14 = v3;
v15 = v4;
v16 = v5;
v18 = 0x10000;
if ( !XInitThreads() )
{
fwrite(&unk_478, 1uLL, 0x24uLL, stderr);
exit(1);
}
gdk_threads_enter(1LL);
gdk_threads_init(1LL);
gtk_init(&v11, &v10);
creer_fenetres(v12);
v8 = v13;
gtk_widget_show_all(v13);
gdk_threads_leave(v8);
while ( HIWORD(v18) )
{
HIWORD(v18) = 0;
gdk_threads_enter(v8);
gtk_main(v8);
gdk_threads_leave(v8);
if ( (_WORD)v18 )
{
detruire_fenetres(v12, 0LL);
puts("Lancement du jeu.");
v8 = v12;
traitement_jeu(v12);
}
}
puts("Fin de la fonction main. Fermeture...");
free(v3);
free(v5);
free(v7);
free(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl func2(int argc, const char **argv, const char **envp)
{
_BYTE *v3; // r14
_BYTE *v4; // rbp
_BYTE *v5; // r13
_BYTE *v6; // rax
void *v7; // r12
char *v8; // rdi
const char **v10; // [rsp+0h] [rbp-218h] BYREF
int v11; // [rsp+Ch] [rbp-20Ch] BYREF
char v12[8]; // [rsp+10h] [rbp-208h] BYREF
char *v13; // [rsp+18h] [rbp-200h]
_BYTE *v14; // [rsp+140h] [rbp-D8h]
_BYTE *v15; // [rsp+158h] [rbp-C0h]
_BYTE *v16; // [rsp+1C0h] [rbp-58h]
_BYTE *v17; // [rsp+1C8h] [rbp-50h]
int v18; // [rsp+1DCh] [rbp-3Ch]

v11 = argc;
v10 = argv;
v3 = malloc(1uLL);
v4 = malloc(1uLL);
v5 = malloc(1uLL);
v6 = malloc(1uLL);
*v3 = 0;
*v6 = 0;
v7 = v6;
v17 = v6;
*v4 = 0;
*v5 = 0;
v14 = v3;
v15 = v4;
v16 = v5;
v18 = 0x10000;
if ( !XInitThreads() )
{
fwrite(&unk_478, 1uLL, 0x24uLL, stderr);
exit(1);
}
gdk_threads_enter(1LL);
gdk_threads_init(1LL);
gtk_init(&v11, &v10);
creer_fenetres(v12);
v8 = v13;
gtk_widget_show_all(v13);
gdk_threads_leave(v8);
while ( HIWORD(v18) )
{
HIWORD(v18) = 0;
gdk_threads_enter(v8);
gtk_main(v8);
gdk_threads_leave(v8);
if ( (_WORD)v18 )
{
detruire_fenetres(v12, 0LL);
puts("Lancement du jeu.");
v8 = v12;
traitement_jeu(v12);
}
}
puts("Fin de la fonction main. Fermeture...");
free(v3);
free(v5);
free(v7);
free(v4);
return 0;
}


repo: ISOBlue/isoblue-software

decompiled_code:
__int64 __fastcall init_socket(char *src)
{
int v1; // eax
unsigned int v2; // er12
struct sockaddr v4; // [rsp+0h] [rbp-58h] BYREF
char dest[16]; // [rsp+10h] [rbp-48h] BYREF
int v6; // [rsp+20h] [rbp-38h]

v4 = 0LL;
v1 = socket(29, 2050, 7);
if ( v1 < 0 )
{
perror("socket");
exit(1);
}
v2 = v1;
strcpy(dest, src);
ioctl(v2, 0x8933uLL, dest);
v4.sa_family = 29;
v4.sa_data[6] = -1;
*(_DWORD *)&v4.sa_data[2] = v6;
if ( bind(v2, &v4, 0x10u) < 0 )
{
perror("bind");
exit(1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *src)
{
int v1; // eax
unsigned int v2; // er12
struct sockaddr v4; // [rsp+0h] [rbp-58h] BYREF
char dest[16]; // [rsp+10h] [rbp-48h] BYREF
int v6; // [rsp+20h] [rbp-38h]

v4 = 0LL;
v1 = socket(29, 2050, 7);
if ( v1 < 0 )
{
perror("socket");
exit(1);
}
v2 = v1;
strcpy(dest, src);
ioctl(v2, 0x8933uLL, dest);
v4.sa_family = 29;
v4.sa_data[6] = -1;
*(_DWORD *)&v4.sa_data[2] = v6;
if ( bind(v2, &v4, 0x10u) < 0 )
{
perror("bind");
exit(1);
}
return v2;
}

original_code:
static int init_socket(char *ifname)
{
 struct sockaddr_can addr = { 0 };
 struct ifreq ifr;
 int sock;
 if((sock = socket(29, SOCK_DGRAM | SOCK_NONBLOCK, 7))
   < 0) {
  perror("socket");
  exit(1);
 }
 strcpy(ifr.ifr_ifrn.ifrn_name, ifname);
 ioctl(sock, 0x8933, &ifr);
 addr.can_family = 29;
 addr.can_ifindex = ifr.ifr_ifru.ifru_ivalue;
 addr.can_addr.isobus.addr = 255U;
 if(bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
  perror("bind");
  exit(1);
 }
 return sock;
}

variable_types:
ifname
char *

variable_types: struct sockaddr_can { unsigned short can_family; int can_ifindex; union { struct { unsigned int rx_id; } tp; struct { unsigned char addr; } isobus; } can_addr; }

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

variable_types: sock int

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


repo: ITikhonov/captcha

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // edi
unsigned int v5; // ebp
__int64 v6; // rbx
__int64 v7; // rdx
unsigned int v8; // ebx
__int64 v9; // rsi

v3 = width;
v4 = 0;
v5 = 0;
v6 = 1LL;
if ( width > 0 )
{
while ( v3 > (int)v6 )
{
if ( byte_402008[v6] == 97 )
{
v7 = v5++;
copy((unsigned int)(v4 + 1), (unsigned int)(v6 - 1), v7);
v3 = width;
v4 = v6;
}
++v6;
}
v8 = 0;
printf("static int8_t *lt[]={");
if ( v5 )
{
do
{
v9 = 0LL;
if ( (v8 & 0xFFFFFFFD) != 4 )
v9 = v8;
++v8;
printf("lt%d,", v9);
}
while ( v5 != v8 );
}
}
else
{
printf("static int8_t *lt[]={");
}
puts("};\n");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // edi
unsigned int v5; // ebp
__int64 v6; // rbx
__int64 v7; // rdx
unsigned int v8; // ebx
__int64 v9; // rsi

v3 = width;
v4 = 0;
v5 = 0;
v6 = 1LL;
if ( width > 0 )
{
while ( v3 > (int)v6 )
{
if ( byte_402008[v6] == 97 )
{
v7 = v5++;
func7((unsigned int)(v4 + 1), (unsigned int)(v6 - 1), v7);
v3 = width;
v4 = v6;
}
++v6;
}
v8 = 0;
printf("static int8_t *lt[]={");
if ( v5 )
{
do
{
v9 = 0LL;
if ( (v8 & 0xFFFFFFFD) != 4 )
v9 = v8;
++v8;
printf("lt%d,", v9);
}
while ( v5 != v8 );
}
}
else
{
printf("static int8_t *lt[]={");
}
puts("};\n");
return 0;
}

canonical_original_code:
int main() {
 int i; int st = 0; int idx = 0;
 for(i=0;i<width;i++) {
  if(im[0][i]=='a') {
   copy(st+1,i-1,idx);
   idx++;
   st=i;
  }
 }
 printf("static int8_t *lt[]={");
 for(i=0;i<idx;i++) {
  printf("lt%d,",(i==6||i==4)?0:i);
 }
 printf("};\n\n");
 return 0;
}

variable_types: st int

variable_types: idx int


copy

original_code:
void copy(int s, int e, int idx) {
 int r,i;
 for(i=s;i<e;i++) {
  for(r=0;r<50;r++) {
   if(im[r][i]!=' ') goto findend;
  }
 }
 findend: s=i;
 for(i=e;i>s;i--) {
  for(r=0;r<50;r++) {
   if(im[r][i]!=' ') goto go;
  }
 }
 go: e=i+1;
 printf("static int8_t lt%u[]={",idx);
 for(r=0;r<50;r++) {
  int l=0;
  for(i=s;i<e;i++) {
   char c=im[r][i];
   if(c==' ') { l++; }
   else {
    if(l) { printf("-%u,",l); l=0; }
    printf("%u,",colors[c-'a']);
   }
  }
  printf("-100,");
 }
 printf("-101};\n");
}

canonical_original_code:
void copy(int s, int e, int idx) {
 int r; int i;
 for(i=s;i<e;i++) {
  for(r=0;r<50;r++) {
   if(im[r][i]!=' ') goto findend;
  }
 }
 findend: s=i;
 for(i=e;i>s;i--) {
  for(r=0;r<50;r++) {
   if(im[r][i]!=' ') goto go;
  }
 }
 go: e=i+1;
 printf("static int8_t lt%u[]={",idx);
 for(r=0;r<50;r++) {
  int l = 0;
  for(i=s;i<e;i++) {
   char c = im[r][i];
   if(c==' ') { l++; }
   else {
    if(l) { printf("-%u,",l); l=0; }
    printf("%u,",colors[c-'a']);
   }
  }
  printf("-100,");
 }
 printf("-101};\n");
}

variable_types: s int

variable_types: e int

variable_types: r int

variable_types: l int

variable_types: c char


repo: IanHarvey/minicrypt

decompiled_code:
__int64 __fastcall mpisub_mini(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rsi
unsigned int v6; // edx
unsigned int v7; // ecx
unsigned int v8; // er10
int v9; // edx
int v10; // eax
int v11; // ecx

v5 = 0LL;
v6 = 0;
do
{
v7 = *(_DWORD *)(a2 + v5);
v8 = *(_DWORD *)(a3 + v5);
v9 = v6 + (unsigned __int16)v7 - (unsigned __int16)v8;
v10 = (unsigned __int16)v9;
v11 = HIWORD(v7) - HIWORD(v8) + (v9 >> 16);
v6 = v11 >> 16;
*(_DWORD *)(a1 + v5) = (v11 << 16) | v10;
v5 += 4LL;
}
while ( v5 != 32 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rsi
unsigned int v6; // edx
unsigned int v7; // ecx
unsigned int v8; // er10
int v9; // edx
int v10; // eax
int v11; // ecx

v5 = 0LL;
v6 = 0;
do
{
v7 = *(_DWORD *)(a2 + v5);
v8 = *(_DWORD *)(a3 + v5);
v9 = v6 + (unsigned __int16)v7 - (unsigned __int16)v8;
v10 = (unsigned __int16)v9;
v11 = HIWORD(v7) - HIWORD(v8) + (v9 >> 16);
v6 = v11 >> 16;
*(_DWORD *)(a1 + v5) = (v11 << 16) | v10;
v5 += 4LL;
}
while ( v5 != 32 );
return v6;
}

original_code:
uint32_t mpisub_mini( UInt_Mini *res, const UInt_Mini *a, const UInt_Mini *b )
{
    int i;
    uint32_t carry = 0;
    for (i=0; i<8; i++)
    {
      int32_t ai = a->digits[i];
      int32_t bi = b->digits[i];
      int32_t rL = (ai & 0xFFFF) - (bi & 0xFFFF) + carry;
      int32_t rH = ((ai >> 16) & 0xFFFF) - ((bi >> 16) & 0xFFFF) + (rL >> 16);
      res->digits[i] = (rL & 0xFFFF) | (rH << 16);
      carry = rH >> 16;
    }
    return (uint32_t)carry;
}

canonical_original_code:
unsigned int mpisub_mini(struct UInt_Mini *res, struct UInt_Mini *a, struct UInt_Mini *b)
{
    int i;
    unsigned int carry = 0;
    for (i=0; i<8; i++)
    {
      int ai = a->digits[i];
      int bi = b->digits[i];
      int rL = (ai & 0xFFFF) - (bi & 0xFFFF) + carry;
      int rH = ((ai >> 16) & 0xFFFF) - ((bi >> 16) & 0xFFFF) + (rL >> 16);
      res->digits[i] = (rL & 0xFFFF) | (rH << 16);
      carry = rH >> 16;
    }
    return (unsigned int)carry;
}

variable_types: struct UInt_Mini { unsigned int digits[8]; } *

variable_types:
a
struct UInt_Mini *

variable_types:
b
struct UInt_Mini *

variable_types: i int

variable_types:
carry
unsigned int

variable_types: ai int

variable_types: bi int

variable_types: rL int

variable_types: rH int

return_type: unsigned int


decompiled_code:
__int64 __fastcall u64_shift_bits(_DWORD *a1)
{
unsigned int v1; // edx
unsigned int v2; // eax
__int64 result; // rax

v1 = a1[1];
v2 = *a1 >> 29;
a1[1] = v1 >> 29;
result = (2 * v1) & 0x3FFFFFFF | v2;
*a1 = result;
return result;
}

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

v1 = a1[1];
v2 = *a1 >> 29;
a1[1] = v1 >> 29;
result = (2 * v1) & 0x3FFFFFFF | v2;
*a1 = result;
return result;
}

canonical_original_code:
static void u64_shift_bits(struct U64 *u)
{
  u->lo30 = (u->lo30 >> 29) | ((u->hi << 1) & 0x3FFFFFFF);
  u->hi >>= 29;
}

variable_types: struct U64 { unsigned int lo30; unsigned int hi; } *


decompiled_code:
__int64 __fastcall u64_add(_DWORD *a1, int a2)
{
unsigned int v2; // eax
__int64 result; // rax

v2 = *a1 + a2;
a1[1] += v2 >> 30;
result = v2 & 0x3FFFFFFF;
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, int a2)
{
unsigned int v2; // eax
__int64 result; // rax

v2 = *a1 + a2;
a1[1] += v2 >> 30;
result = v2 & 0x3FFFFFFF;
*a1 = result;
return result;
}

canonical_original_code:
static void u64_add(struct U64 *u, int i)
{
  unsigned int lo30 = u->lo30;
  lo30 += i;
  u->lo30 = (lo30 & 0x3FFFFFFF);
  u->hi += (lo30 >> 30);
}

user_defined_types: struct U64 { unsigned int lo30; unsigned int hi; }


decompiled_code:
__int64 __fastcall u64_mul_add(unsigned int *a1, int a2, int a3)
{
__int16 v3; // cx
int v4; // esi
int v5; // er8
int v6; // edx
unsigned int v7; // eax
int v8; // edx
unsigned int v9; // er8
__int64 result; // rax

v3 = a2;
v4 = a2 >> 15;
v5 = a3 & 0x7FFF;
v6 = a3 >> 15;
v7 = v4 * v5 + v6 * (v3 & 0x7FFF);
v8 = (v7 >> 15) + a1[1] + v4 * v6;
v9 = *a1 + v5 * (v3 & 0x7FFF) + ((v7 << 15) & 0x3FFF8000);
result = v9 >> 30;
*a1 = v9 & 0x3FFFFFFF;
a1[1] = result + v8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, int a2, int a3)
{
__int16 v3; // cx
int v4; // esi
int v5; // er8
int v6; // edx
unsigned int v7; // eax
int v8; // edx
unsigned int v9; // er8
__int64 result; // rax

v3 = a2;
v4 = a2 >> 15;
v5 = a3 & 0x7FFF;
v6 = a3 >> 15;
v7 = v4 * v5 + v6 * (v3 & 0x7FFF);
v8 = (v7 >> 15) + a1[1] + v4 * v6;
v9 = *a1 + v5 * (v3 & 0x7FFF) + ((v7 << 15) & 0x3FFF8000);
result = v9 >> 30;
*a1 = v9 & 0x3FFFFFFF;
a1[1] = result + v8;
return result;
}

variable_types:
mr
unsigned int

variable_types:
hi
unsigned int


variable_types:
dst
int *

variable_types:
src
int *

variable_types: j int

variable_types: struct U64 { unsigned int lo30; unsigned int hi; }


canonical_original_code:
void F25519_mul3_mini(struct F25519_Mini *res, struct F25519_Mini *s1, struct F25519_Mini *s2)
{
  struct MulResult w;
  int r;
  struct U64 r64;
  ((r64).lo30 = (r64).hi = 0);
  for ( r=0; r < 9*2 - 1; r++ )
  {
     if ( r < 9 )
     {
       u64_sum_row(&r64,
                   &s1->digits[0],
                   &s2->digits[r],
                   r+1);
     }
     else
     {
       u64_sum_row(&r64,
                   &s1->digits[r-9 +1],
                   &s2->digits[9 -1],
                   2*9 -1-r);
     }
     w.digits[r] = ((int)((r64).lo30 & 0x1fffffff));
     u64_shift_bits(&(r64));
  }
  w.digits[r] = ((int)((r64).lo30 & 0x1fffffff));
  mul_reduce_approx(res->digits, w.digits);
  F25519_reduce_mini_(res);
}

variable_types:
res
struct F25519_Mini { int digits[9]; } *

variable_types:
w
struct MulResult { int digits[-1]; }

variable_types: r int


decompiled_code:
__int64 __fastcall F25519_sqr_mini(__int64 a1, int *a2)
{
return F25519_mul3_mini(a1, a2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int *a2)
{
return func5(a1, a2, a2);
}

original_code:
void F25519_sqr_mini(F25519_Mini *res, const F25519_Mini *s)
{
  F25519_mul3_mini(res, s, s);
}

canonical_original_code:
void F25519_sqr_mini(struct F25519_Mini *res, struct F25519_Mini *s)
{
  F25519_mul3_mini(res, s, s);
}

variable_types:
s
struct F25519_Mini *


decompiled_code:
__int64 __fastcall F25519_mulK_mini(__int64 a1, int *a2, unsigned int a3)
{
int v4[18]; // [rsp+0h] [rbp-48h] BYREF

F25519_setK_mini(v4, a3);
return F25519_mul3_mini(a1, a2, v4);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int *a2, unsigned int a3)
{
int v4[18]; // [rsp+0h] [rbp-48h] BYREF

F25519_setK_mini(v4, a3);
return func5(a1, a2, v4);
}

original_code:
void F25519_mulK_mini(F25519_Mini *res, const F25519_Mini *s1, uint32_t s2)
{
  F25519_Mini s2l;
  F25519_setK_mini(&s2l, s2);
  F25519_mul3_mini(res, s1, &s2l);
}

canonical_original_code:
void F25519_mulK_mini(struct F25519_Mini *res, struct F25519_Mini *s1, unsigned int s2)
{
  struct F25519_Mini s2l;
  F25519_setK_mini(&s2l, s2);
  F25519_mul3_mini(res, s1, &s2l);
}


ROR

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

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

original_code:
static uint32_t ROR(uint32_t v, unsigned n)
{
  return (v >> n) | (v << (32-n));
}

canonical_original_code:
static unsigned int ROR(unsigned int v, unsigned int n)
{
  return (v >> n) | (v << (32-n));
}

variable_types:
v
unsigned int

variable_types:
n
unsigned int


canonical_original_code:
static void SHA256Mini_compress(unsigned int *H, unsigned char *msg)
{
  unsigned int W[16];
  unsigned int i;
  get_BE32(msg, W, 16);
  unsigned int a; unsigned int b; unsigned int c; unsigned int d; unsigned int e; unsigned int f; unsigned int g; unsigned int h;
  a=H[0]; b=H[1]; c=H[2]; d=H[3];
  e=H[4]; f=H[5]; g=H[6]; h=H[7];
  for (i=0; i<64; i++)
  {
    unsigned int temp1; unsigned int temp2; unsigned int W_i;
    if ( i < 16 )
      W_i = W[i];
    else
    {
      temp1 = W[(i-15) & 15];
      temp1 = ROR(temp1, 7) ^ ROR(temp1, 18) ^ (temp1 >> 3);
      temp2 = W[(i-2) & 15];
      temp2 = ROR(temp2, 17) ^ ROR(temp2, 19) ^ (temp2 >> 10);
      W_i = W[i & 15] + W[(i-7) & 15] + temp1 + temp2;
      W[i & 15] = W_i;
    }
    temp1 = h + K[i] + W_i;
    temp1 += ROR(e,6) ^ ROR(e,11) ^ ROR(e,25);
    temp1 += (e & f) ^ (~e & g);
    temp2 = ROR(a,2) ^ ROR(a,13) ^ ROR(a,22);
    temp2 += (a & b) ^ (a & c) ^ (b & c);
    h=g; g=f; f=e; e = d + temp1;
    d=c; c=b; b=a; a = temp1 + temp2;
  }
  H[0] += a;
  H[1] += b;
  H[2] += c;
  H[3] += d;
  H[4] += e;
  H[5] += f;
  H[6] += g;
  H[7] += h;
}

variable_types:
H
unsigned int *

variable_types:
msg
unsigned char *

variable_types:
W
unsigned int [16]

variable_types:
i
unsigned int

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
c
unsigned int

variable_types:
d
unsigned int

variable_types:
e
unsigned int

variable_types:
f
unsigned int

variable_types:
g
unsigned int

variable_types:
h
unsigned int


original_code:
void SHA256Mini_Update(SHA256Mini_ctx *ctx, const void *pvmsg, size_t remain)
{
  const uint8_t *msg = (const uint8_t *)pvmsg;
  while ( remain > 0 )
  {
    uint32_t got = (ctx->count & 63);
    uint32_t space = 64-got;
    uint32_t taken;
    if ( remain >= space )
    {
      if ( got==0 )
        SHA256Mini_compress(ctx->H, msg);
      else
      {
        memcpy( ctx->msgbuf + got, msg, space );
        SHA256Mini_compress(ctx->H, ctx->msgbuf);
      }
      taken = space;
    }
    else
    {
      memcpy( ctx->msgbuf + got, msg, remain );
      taken = remain;
    }
    ctx->count += taken;
    msg += taken;
    remain -= taken;
  }
}

canonical_original_code:
void SHA256Mini_Update(struct SHA256Mini_ctx *ctx, void *pvmsg, unsigned long remain)
{
  unsigned char *msg = (const uint8_t *)pvmsg;
  while ( remain > 0 )
  {
    unsigned int got = (ctx->count & 63);
    unsigned int space = 64-got;
    unsigned int taken;
    if ( remain >= space )
    {
      if ( got==0 )
        SHA256Mini_compress(ctx->H, msg);
      else
      {
        memcpy( ctx->msgbuf + got, msg, space );
        SHA256Mini_compress(ctx->H, ctx->msgbuf);
      }
      taken = space;
    }
    else
    {
      memcpy( ctx->msgbuf + got, msg, remain );
      taken = remain;
    }
    ctx->count += taken;
    msg += taken;
    remain -= taken;
  }
}

variable_types: struct SHA256Mini_ctx { unsigned long count; unsigned char msgbuf[64]; unsigned int H[8]; } *

variable_types:
pvmsg
void *

variable_types:
remain
unsigned long

variable_types:
got
unsigned int

variable_types:
space
unsigned int

variable_types:
taken
unsigned int


original_code:
void SHA256Mini_Final(SHA256Mini_ctx *ctx, uint8_t *out)
{
  uint32_t got = (ctx->count & 63);
  ctx->msgbuf[got++] = 0x80;
  if ( got > 56 )
  {
    memset(ctx->msgbuf + got, 0, 64-got);
    SHA256Mini_compress(ctx->H, ctx->msgbuf);
    got = 0;
  }
  memset( ctx->msgbuf + got, 0, 64-got );
  size_t nbits = ctx->count << 3;
  ((void) sizeof (((nbits >> 3) == ctx->count) ? 1 : 0), __extension__ ({ if ((nbits >> 3) == ctx->count) ; else __assert_fail ("(nbits >> 3) == ctx->count", "../src/sha2_mini.c", 180, __extension__ __PRETTY_FUNCTION__); }));
  uint8_t *p = ctx->msgbuf + 63;
  while ( nbits > 0 )
  {
    *p-- = (uint8_t)(nbits & 0xFF);
    nbits >>= 8;
  }
  SHA256Mini_compress(ctx->H, ctx->msgbuf);
  put_BE32(ctx->H, out, 8);
}

canonical_original_code:
void SHA256Mini_Final(struct SHA256Mini_ctx *ctx, unsigned char *out)
{
  unsigned int got = (ctx->count & 63);
  ctx->msgbuf[got++] = 0x80;
  if ( got > 56 )
  {
    memset(ctx->msgbuf + got, 0, 64-got);
    SHA256Mini_compress(ctx->H, ctx->msgbuf);
    got = 0;
  }
  memset( ctx->msgbuf + got, 0, 64-got );
  unsigned long nbits = ctx->count << 3;
  ((void) sizeof (((nbits >> 3) == ctx->count) ? 1 : 0), __extension__ ({ if ((nbits >> 3) == ctx->count) ; else __assert_fail ("(nbits >> 3) == ctx->count", "../src/sha2_mini.c", 180, __extension__ __PRETTY_FUNCTION__); }));
  unsigned char *p = ctx->msgbuf + 63;
  while ( nbits > 0 )
  {
    *p-- = (unsigned char)(nbits & 0xFF);
    nbits >>= 8;
  }
  SHA256Mini_compress(ctx->H, ctx->msgbuf);
  put_BE32(ctx->H, out, 8);
}

variable_types:
out
unsigned char *

variable_types:
nbits
unsigned long

variable_types:
p
unsigned char *

user_defined_types: struct SHA256Mini_ctx { unsigned long count; unsigned char msgbuf[64]; unsigned int H[8]; }


decompiled_code:
__int64 __fastcall SHA256Mini(_QWORD *a1, __int64 a2, __int64 a3)
{
size_t v4; // rdx
unsigned __int64 v6[15]; // [rsp+0h] [rbp-78h] BYREF

SHA256Mini_Init(v6);
SHA256Mini_Update(v6, a1, v4);
return SHA256Mini_Final(v6, a3);
}

canonical_decompiled_code:
__int64 __fastcall func14(_QWORD *a1, __int64 a2, __int64 a3)
{
size_t v4; // rdx
unsigned __int64 v6[15]; // [rsp+0h] [rbp-78h] BYREF

func11(v6);
func12(v6, a1, v4);
return func13(v6, a3);
}

original_code:
void SHA256Mini(const void *msg, size_t msglen, uint8_t *out32)
{
  SHA256Mini_ctx c;
  SHA256Mini_Init(&c);
  SHA256Mini_Update(&c, msg, msglen);
  SHA256Mini_Final(&c, out32);
}

canonical_original_code:
void SHA256Mini(void *msg, unsigned long msglen, unsigned char *out32)
{
  struct SHA256Mini_ctx c;
  SHA256Mini_Init(&c);
  SHA256Mini_Update(&c, msg, msglen);
  SHA256Mini_Final(&c, out32);
}

variable_types:
msg
void *

variable_types:
msglen
unsigned long

variable_types: struct SHA256Mini_ctx { unsigned long count; unsigned char msgbuf[64]; unsigned int H[8]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
size_t v4; // rbp
_OWORD *v5; // rbx
const char *v6; // rdi
__int128 v9[3]; // [rsp+0h] [rbp-38h] BYREF

v3 = 0;
v4 = 0LL;
v5 = &unk_402088;
while ( 1 )
{
printf("Length %5ld: ", v4);
SHA256Mini(*((_QWORD *)v5 - 1), v4, v9);
if ( *v5 != v9[0] || v5[1] != v9[1] )
break;
v5 = (_OWORD *)((char *)v5 + 40);
puts("OK");
v6 = (const char *)*((_QWORD *)v5 - 1);
if ( !v6 )
return v3 != 0;
LABEL_4:
v4 = strlen(v6);
}
v5 = (_OWORD *)((char *)v5 + 40);
++v3;
puts("FAIL");
v6 = (const char *)*((_QWORD *)v5 - 1);
if ( v6 )
goto LABEL_4;
return v3 != 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
size_t v4; // rbp
_OWORD *v5; // rbx
const char *v6; // rdi
__int128 v9[3]; // [rsp+0h] [rbp-38h] BYREF

v3 = 0;
v4 = 0LL;
v5 = &unk_402088;
while ( 1 )
{
printf("Length %5ld: ", v4);
func14(*((_QWORD *)v5 - 1), v4, v9);
if ( *v5 != v9[0] || v5[1] != v9[1] )
break;
v5 = (_OWORD *)((char *)v5 + 40);
puts("OK");
v6 = (const char *)*((_QWORD *)v5 - 1);
if ( !v6 )
return v3 != 0;
LABEL_4:
v4 = strlen(v6);
}
v5 = (_OWORD *)((char *)v5 + 40);
++v3;
puts("FAIL");
v6 = (const char *)*((_QWORD *)v5 - 1);
if ( v6 )
goto LABEL_4;
return v3 != 0;
}

original_code:
int main()
{
  const TestVector *tv;
  int fails=0;
  for (tv=&tvs[0]; tv->in != ((void *)0); tv++)
  {
    uint8_t buf[32];
    size_t l = strlen(tv->in);
    printf("Length %5ld: ", (unsigned long)l);
    SHA256Mini(tv->in, l, buf);
    if ( memcmp(buf, tv->out, 32) != 0 )
    {
      fails++;
      printf("FAIL\n");
    }
    else
      printf("OK\n");
  }
  return fails ? 1 : 0;
}

canonical_original_code:
int main()
{
  struct TestVector *tv;
  int fails = 0;
  for (tv=&tvs[0]; tv->in != ((void *)0); tv++)
  {
    unsigned char buf[32];
    unsigned long l = strlen(tv->in);
    printf("Length %5ld: ", (unsigned long)l);
    SHA256Mini(tv->in, l, buf);
    if ( memcmp(buf, tv->out, 32) != 0 )
    {
      fails++;
      printf("FAIL\n");
    }
    else
      printf("OK\n");
  }
  return fails ? 1 : 0;
}

variable_types: struct TestVector { char *in; unsigned char out[32]; } *

variable_types: fails int

variable_types:
buf
unsigned char [32]

variable_types:
l
unsigned long


decompiled_code:
__int64 __fastcall getU32(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

canonical_original_code:
static unsigned int getU32(unsigned char *pt)
{
  return (pt[0] << 24) | (pt[1] << 16) | (pt[2] << 8) | pt[3];
}

variable_types:
pt
unsigned char *


decompiled_code:
__int64 __fastcall Te0(unsigned __int8 a1)
{
int v1; // edx

v1 = (unsigned __int16)Sx0201[a1];
return ((unsigned __int8)v1 << 8) ^ (v1 << 16) ^ (unsigned __int8)v1 ^ (unsigned int)BYTE1(v1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1)
{
int v1; // edx

v1 = (unsigned __int16)Sx0201[a1];
return ((unsigned __int8)v1 << 8) ^ (v1 << 16) ^ (unsigned __int8)v1 ^ (unsigned int)BYTE1(v1);
}

canonical_original_code:
static unsigned int Te0(unsigned char idx)
{
  unsigned int s0201 = Sx0201[idx];
  unsigned int s01 = s0201 & 0xFF;
  unsigned int s03 = s01 ^ (s0201 >> 8);
  return (s0201 << 16) ^ (s01 << 8) ^ s03;
}

variable_types:
idx
unsigned char


decompiled_code:
__int64 __fastcall Te0123(int a1, int a2)
{
unsigned __int8 v2; // dh
unsigned __int8 v3; // bh
int v4; // esi
unsigned __int8 v5; // r10
int v6; // eax
int v7; // er8
int v8; // er9

v3 = v2;
Te0(HIBYTE(a1));
v4 = Te0(BYTE2(a2));
Te0(v3);
v6 = Te0(v5);
return __ROL4__(v6, 8) ^ v8 ^ (unsigned int)(__ROL4__(v7, 16) ^ __ROR4__(v4, 8));
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
unsigned __int8 v2; // dh
unsigned __int8 v3; // bh
int v4; // esi
unsigned __int8 v5; // r10
int v6; // eax
int v7; // er8
int v8; // er9

v3 = v2;
func2(HIBYTE(a1));
v4 = func2(BYTE2(a2));
func2(v3);
v6 = func2(v5);
return __ROL4__(v6, 8) ^ v8 ^ (unsigned int)(__ROL4__(v7, 16) ^ __ROR4__(v4, 8));
}


decompiled_code:
__int64 __fastcall Sx01(unsigned __int8 a1)
{
return LOBYTE(Sx0201[a1]);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1)
{
return LOBYTE(Sx0201[a1]);
}

original_code:
static uint32_t Sx01(uint32_t idx)
{
  return Sx0201[idx & 0xFF] & 0xFF;
}

canonical_original_code:
static unsigned int Sx01(unsigned int idx)
{
  return Sx0201[idx & 0xFF] & 0xFF;
}

variable_types:
idx
unsigned int


SxBytes

decompiled_code:
__int64 __fastcall SxBytes(int a1)
{
unsigned __int8 v1; // er8^2
unsigned __int8 v2; // r8^1
unsigned __int8 v3; // r8
int v4; // eax
int v5; // ecx
int v6; // edx

Sx01(HIBYTE(a1));
Sx01(v1);
Sx01(v2);
v4 = Sx01(v3);
return v4 | v6 | (unsigned int)(v5 << 8);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
unsigned __int8 v1; // er8^2
unsigned __int8 v2; // r8^1
unsigned __int8 v3; // r8
int v4; // eax
int v5; // ecx
int v6; // edx

func4(HIBYTE(a1));
func4(v1);
func4(v2);
v4 = func4(v3);
return v4 | v6 | (unsigned int)(v5 << 8);
}