GetExt

decompiled_code:
int __fastcall GetExt(__int64 a1, const char *a2, int a3)
{
const char *v3; // rbp
int v5; // ecx
_BYTE *i; // rax
int v7; // ebx
__int64 v8; // rax
__int64 v9; // rdx
__int64 v10; // rcx

v3 = a2;
puts("Getting file extension");
v5 = a3 - 1;
if ( a3 - 1 <= 0 )
{
if ( a3 == 1 )
return puts("Getting file extension failed");
}
else
{
for ( i = (_BYTE *)(a1 + v5); *i != 46; --i )
{
if ( !--v5 )
return puts("Getting file extension failed");
}
}
v7 = a3 - v5;
if ( v7 >= -1 )
{
v8 = 0LL;
v9 = a1 + v5;
do
{
a2[v8] = *(_BYTE *)(v9 + v8);
v10 = v8++;
}
while ( v7 + 1 != v10 );
a2 += v7 + 2;
}
*a2 = 0;
return printf("Getting file extension succeded: %s\n", v3);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, const char *a2, int a3)
{
const char *v3; // rbp
int v5; // ecx
_BYTE *i; // rax
int v7; // ebx
__int64 v8; // rax
__int64 v9; // rdx
__int64 v10; // rcx

v3 = a2;
puts("Getting file extension");
v5 = a3 - 1;
if ( a3 - 1 <= 0 )
{
if ( a3 == 1 )
return puts("Getting file extension failed");
}
else
{
for ( i = (_BYTE *)(a1 + v5); *i != 46; --i )
{
if ( !--v5 )
return puts("Getting file extension failed");
}
}
v7 = a3 - v5;
if ( v7 >= -1 )
{
v8 = 0LL;
v9 = a1 + v5;
do
{
a2[v8] = *(_BYTE *)(v9 + v8);
v10 = v8++;
}
while ( v7 + 1 != v10 );
a2 += v7 + 2;
}
*a2 = 0;
return printf("Getting file extension succeded: %s\n", v3);
}

original_code:
void GetExt (char * file, char * ext, int l)
{
 int i, j;
 printf("Getting file extension\n");
 for(i = l-1; i > 0 && file[i] != '.'; i--) ;
 if(i == 0)
 {
  printf("Getting file extension failed\n");
  return;
 }
 for(j = 0; j <= l - i + 1; j++)
 {
  ext[j] = file[i+j];
 }
 ext[j] = '\0';
 printf("Getting file extension succeded: %s\n", ext);
}

canonical_original_code:
void GetExt(char *file, char *ext, int l)
{
 int i; int j;
 printf("Getting file extension\n");
 for(i = l-1; i > 0 && file[i] != '.'; i--) ;
 if(i == 0)
 {
  printf("Getting file extension failed\n");
  return;
 }
 for(j = 0; j <= l - i + 1; j++)
 {
  ext[j] = file[i+j];
 }
 ext[j] = '\0';
 printf("Getting file extension succeded: %s\n", ext);
}

variable_types:
file
char *

variable_types:
ext
char *

variable_types: j int


GetReturnStatusString

decompiled_code:
const char *__fastcall GetReturnStatusString(int a1)
{
const char *result; // rax

result = " 200 OK";
if ( a1 != 200 )
{
result = " 404 Not Found";
if ( a1 != 404 )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(int a1)
{
const char *result; // rax

result = " 200 OK";
if ( a1 != 200 )
{
result = " 404 Not Found";
if ( a1 != 404 )
result = 0LL;
}
return result;
}

original_code:
char * GetReturnStatusString(int status)
{
 switch (status){
  case 200: return " 200 OK";
     break;
  case 404: return " 404 Not Found";
     break;
 };
 return ((void *)0);
}

canonical_original_code:
char *GetReturnStatusString(int status)
{
 switch (status){
  case 200: return " 200 OK";
     break;
  case 404: return " 404 Not Found";
     break;
 };
 return ((void *)0);
}

variable_types: status int

return_type: char *


GetContentTypeLine

decompiled_code:
const char *__fastcall GetContentTypeLine(const char *a1)
{
const char *v1; // r8

v1 = "Content-Type: text/html\n";
if ( strcmp(a1, ".html") )
{
if ( strcmp(a1, ".htm") )
{
v1 = "Content-Type: text/plain\n";
if ( !strcmp(a1, ".png") )
v1 = "Content-Type: image/png\n";
}
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func4(const char *a1)
{
const char *v1; // r8

v1 = "Content-Type: text/html\n";
if ( strcmp(a1, ".html") )
{
if ( strcmp(a1, ".htm") )
{
v1 = "Content-Type: text/plain\n";
if ( !strcmp(a1, ".png") )
v1 = "Content-Type: image/png\n";
}
}
return v1;
}

original_code:
char * GetContentTypeLine (char * ext)
{
 if(strcmp(ext, ".html") == 0 || strcmp(ext, ".htm") == 0)
 {
  return "Content-Type: text/html\n";
 }
 if(strcmp(ext, ".png") == 0)
 {
  return "Content-Type: image/png\n";
 }
 return "Content-Type: text/plain\n";
}

canonical_original_code:
char *GetContentTypeLine(char *ext)
{
 if(strcmp(ext, ".html") == 0 || strcmp(ext, ".htm") == 0)
 {
  return "Content-Type: text/html\n";
 }
 if(strcmp(ext, ".png") == 0)
 {
  return "Content-Type: image/png\n";
 }
 return "Content-Type: text/plain\n";
}


GetHTTPVer

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

result = a3 + a1 + 1;
*(_BYTE *)(a3 + a1 + 9) = 0;
return result;
}

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

result = a3 + a1 + 1;
*(_BYTE *)(a3 + a1 + 9) = 0;
return result;
}

original_code:
char * GetHTTPVer (char * buffer, int n, int i)
{
 buffer = &buffer[i+1];
 buffer[8] = '\0';
 return buffer;
}

canonical_original_code:
char *GetHTTPVer(char *buffer, int n, int i)
{
 buffer = &buffer[i+1];
 buffer[8] = '\0';
 return buffer;
}

variable_types:
buffer
char *

variable_types: n int

variable_types: i int


OPTIONS

decompiled_code:
ssize_t __fastcall OPTIONS(int fd)
{
struct tm *v1; // rax
size_t v2; // rax
size_t v3; // rax
__m128i *v4; // rdx
__m128i v5; // xmm0
char *v6; // rdx
time_t timer; // [rsp+8h] [rbp-850h] BYREF
struct tm tp; // [rsp+10h] [rbp-848h] BYREF
char buf[16]; // [rsp+50h] [rbp-808h] BYREF
char dest[1008]; // [rsp+60h] [rbp-7F8h] BYREF
char s[1032]; // [rsp+450h] [rbp-408h] BYREF

timer = time(0LL);
v1 = gmtime(&timer);
*(__m128i *)&tp.tm_sec = _mm_loadu_si128((const __m128i *)v1);
*(__m128i *)&tp.tm_mon = _mm_loadu_si128((const __m128i *)&v1->tm_mon);
*(__m128i *)&tp.tm_isdst = _mm_loadu_si128((const __m128i *)&v1->tm_isdst);
tp.tm_zone = v1->tm_zone;
strftime(s, 0x400uLL, "Date: %a, %d %b %Y %H:%M:%S %Z\r\n", &tp);
v2 = strlen(buf);
*(__m128i *)&buf[v2] = _mm_load_si128((const __m128i *)&LC29);
strcpy(&dest[v2], s);
v3 = strlen(buf);
v4 = (__m128i *)&buf[v3];
*v4 = _mm_load_si128((const __m128i *)&LC30);
v4[1] = _mm_load_si128((const __m128i *)&LC31);
v5 = _mm_load_si128((const __m128i *)&LC32);
v6 = &dest[v3 + 15];
*((_WORD *)v6 + 8) = 2608;
*(__m128i *)v6 = v5;
strcpy(&dest[v3 + 49], "e\n");
*(__m128i *)&dest[v3 + 33] = _mm_load_si128((const __m128i *)&LC21);
return write(fd, buf, v3 + 67);
}

canonical_decompiled_code:
ssize_t __fastcall func9(int fd)
{
struct tm *v1; // rax
size_t v2; // rax
size_t v3; // rax
__m128i *v4; // rdx
__m128i v5; // xmm0
char *v6; // rdx
time_t timer; // [rsp+8h] [rbp-850h] BYREF
struct tm tp; // [rsp+10h] [rbp-848h] BYREF
char buf[16]; // [rsp+50h] [rbp-808h] BYREF
char dest[1008]; // [rsp+60h] [rbp-7F8h] BYREF
char s[1032]; // [rsp+450h] [rbp-408h] BYREF

timer = time(0LL);
v1 = gmtime(&timer);
*(__m128i *)&tp.tm_sec = _mm_loadu_si128((const __m128i *)v1);
*(__m128i *)&tp.tm_mon = _mm_loadu_si128((const __m128i *)&v1->tm_mon);
*(__m128i *)&tp.tm_isdst = _mm_loadu_si128((const __m128i *)&v1->tm_isdst);
tp.tm_zone = v1->tm_zone;
strftime(s, 0x400uLL, "Date: %a, %d %b %Y %H:%M:%S %Z\r\n", &tp);
v2 = strlen(buf);
*(__m128i *)&buf[v2] = _mm_load_si128((const __m128i *)&LC29);
strcpy(&dest[v2], s);
v3 = strlen(buf);
v4 = (__m128i *)&buf[v3];
*v4 = _mm_load_si128((const __m128i *)&LC30);
v4[1] = _mm_load_si128((const __m128i *)&LC31);
v5 = _mm_load_si128((const __m128i *)&LC32);
v6 = &dest[v3 + 15];
*((_WORD *)v6 + 8) = 2608;
*(__m128i *)v6 = v5;
strcpy(&dest[v3 + 49], "e\n");
*(__m128i *)&dest[v3 + 33] = _mm_load_si128((const __m128i *)&LC21);
return write(fd, buf, v3 + 67);
}

original_code:
void OPTIONS(int con)
{
 char lineBuffer [1024];
 char tmp[1024];
 time_t now;
 struct tm tm;
 now = time(0);
 tm = *gmtime(&now);
 strftime(tmp, 1024, "Date: %a, %d %b %Y %H:%M:%S %Z\r\n", &tm);
 strcat(lineBuffer, "HTTP/1.1 200 OK\n");
 strcat(lineBuffer, tmp);
 strcat(lineBuffer, "Server: Melhor server do mundo\n");
 strcat(lineBuffer, "Content-Length: 0\n");
 strcat(lineBuffer, "Connection: close\n");
 write(con, lineBuffer, strlen(lineBuffer));
}

canonical_original_code:
void OPTIONS(int con)
{
 char lineBuffer[1024];
 char tmp[1024];
 long now;
 struct tm tm;
 now = time(0);
 tm = *gmtime(&now);
 strftime(tmp, 1024, "Date: %a, %d %b %Y %H:%M:%S %Z\r\n", &tm);
 strcat(lineBuffer, "HTTP/1.1 200 OK\n");
 strcat(lineBuffer, tmp);
 strcat(lineBuffer, "Server: Melhor server do mundo\n");
 strcat(lineBuffer, "Content-Length: 0\n");
 strcat(lineBuffer, "Connection: close\n");
 write(con, lineBuffer, strlen(lineBuffer));
}

variable_types: con int

variable_types:
lineBuffer
char [1024]

variable_types:
tmp
char [1024]

variable_types: now 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; }

return_type: void


SliceSimple

repo: renaud/libstb

original_code:
int SliceSimple(double *xp,
  double (*post)(double, void *),
  double *bounds,
  rngp_t rng, int loops, void *pars) {
  double x = *xp, y;
  double range[2];
  int tries;
  if ( x<bounds[0] || x>bounds[1] ) {
    fprintf(stderr,
     "SliceSimple: input value %lf outside bounds [%lg,%lg]\n",
     x, bounds[0], bounds[1]);
    return 1;
  }
  while ( loops-->0 ) {
    y = post(x,pars);
    range[0] = bounds[0];
    range[1] = bounds[1];
    y += log(gsl_ran_flat(rng, 0, 1));
    for (tries=1; tries<200; tries++) {
      x = range[0] + gsl_ran_flat(rng, 0, 1)*(range[1]-range[0]);
      if ( post(x,pars)>y ) {
 *xp = x;
 break;
      }
      if ( x<*xp )
 range[0] = x;
      else
 range[1] = x;
    }
    if (tries>=200 ) {
      fprintf(stderr,
       "SliceSimple: giving up after %d tries, range=[%lg,%lg]\n",
       200, range[0], range[1]);
      return 1;
    }
  }
  return 0;
}

canonical_original_code:
int SliceSimple(double *xp, double (*post)(double, void *), double *bounds, struct gsl_rng *rng, int loops, void *pars) {
  double x = *xp; double y;
  double range[2];
  int tries;
  if ( x<bounds[0] || x>bounds[1] ) {
    fprintf(stderr,
     "SliceSimple: input value %lf outside bounds [%lg,%lg]\n",
     x, bounds[0], bounds[1]);
    return 1;
  }
  while ( loops-->0 ) {
    y = post(x,pars);
    range[0] = bounds[0];
    range[1] = bounds[1];
    y += log(gsl_ran_flat(rng, 0, 1));
    for (tries=1; tries<200; tries++) {
      x = range[0] + gsl_ran_flat(rng, 0, 1)*(range[1]-range[0]);
      if ( post(x,pars)>y ) {
 *xp = x;
 break;
      }
      if ( x<*xp )
 range[0] = x;
      else
 range[1] = x;
    }
    if (tries>=200 ) {
      fprintf(stderr,
       "SliceSimple: giving up after %d tries, range=[%lg,%lg]\n",
       200, range[0], range[1]);
      return 1;
    }
  }
  return 0;
}

variable_types:
xp
double *

variable_types:
post
double (*)(double, void *)

variable_types:
bounds
double *

variable_types: struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *

variable_types: loops int

variable_types:
pars
void *

variable_types: x double

variable_types: y double

variable_types:
range
double [2]

variable_types: tries int

return_type: int

user_defined_types: struct gsl_rng { struct gsl_rng_type *type; void *state; }


sampleb

decompiled_code:
void __fastcall sampleb(int a1, int *a2, int *a3, __int64 a4, unsigned int a5, int a6, double a7, double a8, double a9, double a10)
{
double v12; // xmm1_8
int *v13; // r15
__int64 v14; // r14
double v15; // xmm0_8
__int64 v16; // rdx
int v17; // eax
double v18; // xmm0_8
double v19; // xmm2_8
double v20; // xmm0_8
double v21; // xmm0_8
__int64 v22; // xmm1_8
double v23; // xmm0_8
__int128 x; // [rsp+0h] [rbp-C0h]
double v26; // [rsp+10h] [rbp-B0h]
double v29; // [rsp+30h] [rbp-90h] BYREF
__int64 v30; // [rsp+38h] [rbp-88h] BYREF
__int64 v31; // [rsp+40h] [rbp-80h]
__int64 v32; // [rsp+48h] [rbp-78h]
__int128 v33; // [rsp+58h] [rbp-68h] BYREF
int v34; // [rsp+68h] [rbp-58h]
int *v35; // [rsp+70h] [rbp-50h]
double v36; // [rsp+78h] [rbp-48h]

*(double *)&x = a8;
if ( a9 <= 0.0 )
{
fwrite("Illegal scale in sampleb()\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
v12 = 1.0 / a9;
*((double *)&x + 1) = 1.0 / a9;
if ( a1 > 0 )
{
v13 = a2;
v14 = (unsigned int)(a1 - 1);
do
{
if ( *v13 )
{
v15 = gsl_ran_beta(a4, a7, (double)*v13);
if ( v15 <= 0.0 )
{
fprintf(stderr, "Illegal q in sampleb(b=%lf)\n", a7);
exit(1);
}
*((double *)&x + 1) = *((double *)&x + 1) - log(v15);
}
++v13;
}
while ( &a2[v14 + 1] != v13 );
v12 = 0.0;
if ( a10 == 0.0 )
{
v16 = (__int64)&a3[v14 + 1];
do
{
v17 = *a3++;
*(double *)&x = (double)v17 + *(double *)&x;
}
while ( (int *)v16 != a3 );
goto LABEL_11;
}
LABEL_24:
v34 = a1;
v35 = a3;
v30 = LC7;
v31 = LC1;
v36 = a10;
v32 = LC8;
v33 = x;
bmax((__int64)&v33, a7);
v29 = a7;
if ( a6 > 1 )
{
fprintf(stderr, "Max b (%lg,%lg) -> %lg\n", a7, *((double *)&x + 1), a7);
v31 = LC8;
if ( !(unsigned int)SliceSimple(&v29, bterms, &v30, a4, a5, &v33) )
{
fprintf(stderr, "Sample b ~ G(%lg) = %lf\n", *((double *)&x + 1), v29);
return;
}
}
else
{
v31 = LC8;
if ( !(unsigned int)SliceSimple(&v29, bterms, &v30, a4, a5, &v33) )
return;
}
fwrite("SliceSimple error\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
if ( a10 != 0.0 )
goto LABEL_24;
LABEL_11:
if ( *(double *)&x <= 400.0 )
{
v21 = *(double *)&x;
gsl_ran_gamma(a4, *(double *)&x, 1.0);
}
else
{
do
{
v18 = gsl_ran_gaussian(a4, 1.0, v12);
v19 = v18;
if ( *(double *)&x < 0.0 )
{
v26 = v18;
v20 = sqrt(*(double *)&x);
v19 = v26;
}
else
{
v20 = sqrt(*(double *)&x);
}
v21 = v20 * v19 + *(double *)&x;
v29 = v21;
}
while ( v21 <= 0.0 );
}
v22 = LC7;
v23 = v21 / *((double *)&x + 1);
if ( v23 < 0.01 || (v22 = LC8, v23 > 2000.0) )
{
v29 = *(double *)&v22;
v23 = *(double *)&v22;
}
else
{
v29 = v23;
}
if ( a6 > 1 )
fprintf(stderr, "Sample b ~ gamma(%lg,%lg) = %lf\n", *(double *)&x, *((double *)&x + 1), v23);
}

canonical_decompiled_code:
void __fastcall func1(int a1, int *a2, int *a3, __int64 a4, unsigned int a5, int a6, double a7, double a8, double a9, double a10)
{
double v12; // xmm1_8
int *v13; // r15
__int64 v14; // r14
double v15; // xmm0_8
__int64 v16; // rdx
int v17; // eax
double v18; // xmm0_8
double v19; // xmm2_8
double v20; // xmm0_8
double v21; // xmm0_8
__int64 v22; // xmm1_8
double v23; // xmm0_8
__int128 x; // [rsp+0h] [rbp-C0h]
double v26; // [rsp+10h] [rbp-B0h]
double v29; // [rsp+30h] [rbp-90h] BYREF
__int64 v30; // [rsp+38h] [rbp-88h] BYREF
__int64 v31; // [rsp+40h] [rbp-80h]
__int64 v32; // [rsp+48h] [rbp-78h]
__int128 v33; // [rsp+58h] [rbp-68h] BYREF
int v34; // [rsp+68h] [rbp-58h]
int *v35; // [rsp+70h] [rbp-50h]
double v36; // [rsp+78h] [rbp-48h]

*(double *)&x = a8;
if ( a9 <= 0.0 )
{
fwrite("Illegal scale in sampleb()\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
v12 = 1.0 / a9;
*((double *)&x + 1) = 1.0 / a9;
if ( a1 > 0 )
{
v13 = a2;
v14 = (unsigned int)(a1 - 1);
do
{
if ( *v13 )
{
v15 = gsl_ran_beta(a4, a7, (double)*v13);
if ( v15 <= 0.0 )
{
fprintf(stderr, "Illegal q in sampleb(b=%lf)\n", a7);
exit(1);
}
*((double *)&x + 1) = *((double *)&x + 1) - log(v15);
}
++v13;
}
while ( &a2[v14 + 1] != v13 );
v12 = 0.0;
if ( a10 == 0.0 )
{
v16 = (__int64)&a3[v14 + 1];
do
{
v17 = *a3++;
*(double *)&x = (double)v17 + *(double *)&x;
}
while ( (int *)v16 != a3 );
goto LABEL_11;
}
LABEL_24:
v34 = a1;
v35 = a3;
v30 = LC7;
v31 = LC1;
v36 = a10;
v32 = LC8;
v33 = x;
func0((__int64)&v33, a7);
v29 = a7;
if ( a6 > 1 )
{
fprintf(stderr, "Max b (%lg,%lg) -> %lg\n", a7, *((double *)&x + 1), a7);
v31 = LC8;
if ( !(unsigned int)SliceSimple(&v29, bterms, &v30, a4, a5, &v33) )
{
fprintf(stderr, "Sample b ~ G(%lg) = %lf\n", *((double *)&x + 1), v29);
return;
}
}
else
{
v31 = LC8;
if ( !(unsigned int)SliceSimple(&v29, bterms, &v30, a4, a5, &v33) )
return;
}
fwrite("SliceSimple error\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
if ( a10 != 0.0 )
goto LABEL_24;
LABEL_11:
if ( *(double *)&x <= 400.0 )
{
v21 = *(double *)&x;
gsl_ran_gamma(a4, *(double *)&x, 1.0);
}
else
{
do
{
v18 = gsl_ran_gaussian(a4, 1.0, v12);
v19 = v18;
if ( *(double *)&x < 0.0 )
{
v26 = v18;
v20 = sqrt(*(double *)&x);
v19 = v26;
}
else
{
v20 = sqrt(*(double *)&x);
}
v21 = v20 * v19 + *(double *)&x;
v29 = v21;
}
while ( v21 <= 0.0 );
}
v22 = LC7;
v23 = v21 / *((double *)&x + 1);
if ( v23 < 0.01 || (v22 = LC8, v23 > 2000.0) )
{
v29 = *(double *)&v22;
v23 = *(double *)&v22;
}
else
{
v29 = v23;
}
if ( a6 > 1 )
fprintf(stderr, "Sample b ~ gamma(%lg,%lg) = %lf\n", *(double *)&x, *((double *)&x + 1), v23);
}

original_code:
double sampleb(double b_in, int I, double shape, double scale,
        scnt_int *N, scnt_int *T, double apar,
        rngp_t rng, int loops, int verbose) {
  double Q;
  double q;
  double myb;
  int i;
  if ( scale<=0 ) {
    fprintf(stderr,"Illegal scale in sampleb()\n");
    exit(1);
  }
  Q = 1.0/scale;
  for (i=0; i<I; i++) {
    if ( N[i]<=0 )
      continue;
    q = gsl_ran_beta(rng, b_in, (int)N[i]);
    if ( q<=0 ) {
      fprintf(stderr,"Illegal q in sampleb(b=%lf)\n", b_in);
      exit(1);
    }
    Q -= log(q);
  }
  if ( apar==0 ) {
    double Tsum = shape;
    for (i=0; i<I; i++)
      Tsum += T[i];
    if ( Tsum>400 ) {
      do {
 myb = Tsum + gsl_ran_gaussian(rng, 1) * sqrt(Tsum);
      } while ( myb<=0 );
    } else
      myb = gsl_ran_gamma(rng, Tsum, 1);
    myb /= Q;
    if ( myb<0.01 )
      myb = 0.01;
    if ( myb>2000 )
      myb = 2000;
    if ( verbose>1 )
      fprintf(stderr,"Sample b ~ gamma(%lg,%lg) = %lf\n", Tsum, Q, myb);
  } else {
    double initb[3] = {0.01,1,2000};
    BLData bld;
    bld.Q = Q;
    bld.I = I;
    bld.T = T;
    bld.apar = apar;
    bld.shape = shape;
    myb = bmax(b_in, &bld);
    if ( verbose>1 )
      fprintf(stderr,"Max b (%lg,%lg) -> %lg\n", b_in, Q, myb);
    initb[1] = 2000;
    if ( SliceSimple(&myb, bterms, initb, rng, loops, &bld) ) {
      fprintf(stderr,"SliceSimple error\n");
      exit(1);
    }
    if ( verbose>1 )
      fprintf(stderr,"Sample b ~ G(%lg) = %lf\n", Q, myb);
  }
  return myb;
}

canonical_original_code:
double sampleb(double b_in, int I, double shape, double scale, unsigned int *N, unsigned int *T, double apar, struct gsl_rng *rng, int loops, int verbose) {
  double Q;
  double q;
  double myb;
  int i;
  if ( scale<=0 ) {
    fprintf(stderr,"Illegal scale in sampleb()\n");
    exit(1);
  }
  Q = 1.0/scale;
  for (i=0; i<I; i++) {
    if ( N[i]<=0 )
      continue;
    q = gsl_ran_beta(rng, b_in, (int)N[i]);
    if ( q<=0 ) {
      fprintf(stderr,"Illegal q in sampleb(b=%lf)\n", b_in);
      exit(1);
    }
    Q -= log(q);
  }
  if ( apar==0 ) {
    double Tsum = shape;
    for (i=0; i<I; i++)
      Tsum += T[i];
    if ( Tsum>400 ) {
      do {
 myb = Tsum + gsl_ran_gaussian(rng, 1) * sqrt(Tsum);
      } while ( myb<=0 );
    } else
      myb = gsl_ran_gamma(rng, Tsum, 1);
    myb /= Q;
    if ( myb<0.01 )
      myb = 0.01;
    if ( myb>2000 )
      myb = 2000;
    if ( verbose>1 )
      fprintf(stderr,"Sample b ~ gamma(%lg,%lg) = %lf\n", Tsum, Q, myb);
  } else {
    double initb[3] = {0.01,1,2000};
    struct bldata bld;
    bld.Q = Q;
    bld.I = I;
    bld.T = T;
    bld.apar = apar;
    bld.shape = shape;
    myb = bmax(b_in, &bld);
    if ( verbose>1 )
      fprintf(stderr,"Max b (%lg,%lg) -> %lg\n", b_in, Q, myb);
    initb[1] = 2000;
    if ( SliceSimple(&myb, bterms, initb, rng, loops, &bld) ) {
      fprintf(stderr,"SliceSimple error\n");
      exit(1);
    }
    if ( verbose>1 )
      fprintf(stderr,"Sample b ~ G(%lg) = %lf\n", Q, myb);
  }
  return myb;
}

variable_types: I int

variable_types: shape double

variable_types: scale double

variable_types:
N
unsigned int *

variable_types:
T
unsigned int *

variable_types: apar double

variable_types: verbose int

variable_types: Q double

variable_types: q double

variable_types: myb double

variable_types: Tsum double

variable_types:
initb
double [3]

variable_types: struct bldata { double shape; double Q; int I; unsigned int *T; double apar; }

return_type: double

user_defined_types: struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); }


decompiled_code:
double __fastcall S_approx(int a1, int a2, float a3)
{
double result; // xmm0_8
double v5; // xmm3_8
double v6; // xmm2_8
double v7; // xmm0_8
double v8; // xmm2_8
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // xmm0_8
double v12; // xmm0_8
double v13; // [rsp+0h] [rbp-50h]
double v14; // [rsp+0h] [rbp-50h]
double v15; // [rsp+0h] [rbp-50h]
double v16; // [rsp+0h] [rbp-50h]
double v17; // [rsp+0h] [rbp-50h]
double v18; // [rsp+0h] [rbp-50h]
double v19; // [rsp+0h] [rbp-50h]
double v20; // [rsp+0h] [rbp-50h]
double v21; // [rsp+0h] [rbp-50h]
double v22; // [rsp+0h] [rbp-50h]
double v23; // [rsp+0h] [rbp-50h]
double v24; // [rsp+0h] [rbp-50h]
double v25; // [rsp+0h] [rbp-50h]
double v26; // [rsp+8h] [rbp-48h]
double v27; // [rsp+8h] [rbp-48h]
double v28; // [rsp+8h] [rbp-48h]
double v29; // [rsp+8h] [rbp-48h]
double v30; // [rsp+8h] [rbp-48h]
double v31; // [rsp+8h] [rbp-48h]
double v32; // [rsp+8h] [rbp-48h]
double v33; // [rsp+8h] [rbp-48h]
double v34; // [rsp+8h] [rbp-48h]
double v35; // [rsp+8h] [rbp-48h]
double v36; // [rsp+8h] [rbp-48h]
double v37; // [rsp+8h] [rbp-48h]
double v38; // [rsp+8h] [rbp-48h]
double v39; // [rsp+10h] [rbp-40h]
double v40; // [rsp+10h] [rbp-40h]
double v41; // [rsp+10h] [rbp-40h]
double v42; // [rsp+10h] [rbp-40h]
double v43; // [rsp+10h] [rbp-40h]
double v44; // [rsp+18h] [rbp-38h]
double v45; // [rsp+18h] [rbp-38h]
double v46; // [rsp+18h] [rbp-38h]
double v47; // [rsp+18h] [rbp-38h]
float v48; // [rsp+18h] [rbp-38h]
double v49; // [rsp+18h] [rbp-38h]
double v50; // [rsp+20h] [rbp-30h]
double v51; // [rsp+20h] [rbp-30h]
double v52; // [rsp+20h] [rbp-30h]
float v53; // [rsp+28h] [rbp-28h]
double v54; // [rsp+28h] [rbp-28h]
double v55; // [rsp+28h] [rbp-28h]
double v56; // [rsp+30h] [rbp-20h]
double v57; // [rsp+30h] [rbp-20h]
double x; // [rsp+38h] [rbp-18h]

if ( a1 == a2 )
return 0.0;
result = *(double *)&LC1;
if ( a1 >= a2 )
{
if ( a2 == 1 )
{
v15 = lgamma((float)((float)a1 - a3));
result = v15 - lgamma((float)(1.0 - a3));
}
else if ( a3 >= 0.001 )
{
switch ( a2 )
{
case 2:
v47 = lgamma((float)((float)a1 - a3));
v35 = lgamma((float)(1.0 - a3));
v20 = lgamma((float)((float)a1 - (float)(a3 + a3)));
v21 = v20 - lgamma((float)(1.0 - (float)(a3 + a3)));
v41 = log(a3);
v10 = exp(v47 - v35 - v21);
result = v21 - v41 + log(v10 - 1.0);
break;
case 3:
v56 = lgamma((float)((float)a1 - a3));
v30 = lgamma((float)(1.0 - a3));
v53 = a3;
v51 = lgamma((float)((float)a1 - (float)(v53 + v53)));
v40 = lgamma((float)(1.0 - (float)(v53 + v53)));
v16 = lgamma((float)((float)a1 - (float)(a3 * 3.0)));
v17 = v16 - lgamma((float)(1.0 - (float)(a3 * 3.0)));
v45 = log(a3);
v31 = exp(v56 - v30 - v17);
v7 = exp(v51 - v40 - v17);
result = v17 - (v45 + v45) - 0.6931471805599453 + log(v31 - (v7 + v7) + 1.0);
break;
case 4:
v54 = lgamma((float)((float)a1 - a3));
v37 = lgamma((float)(1.0 - a3));
v48 = a3;
x = lgamma((float)((float)a1 - (float)(v48 + v48)));
v43 = lgamma((float)(1.0 - (float)(v48 + v48)));
v57 = lgamma((float)((float)a1 - (float)(a3 * 3.0)));
v49 = lgamma((float)(1.0 - (float)(a3 * 3.0)));
v24 = lgamma((float)((float)a1 - (float)(a3 * 4.0)));
v25 = v24 - lgamma((float)(1.0 - (float)(a3 * 4.0)));
v52 = log(a3);
v55 = exp(v54 - v37 - v25);
v38 = exp(x - v43 - v25);
v12 = exp(v57 - v49 - v25);
result = v25 - 3.0 * v52 - 1.791759469228055 + log(v55 - v38 * 3.0 + v12 * 3.0 - 1.0);
break;
}
}
else
{
switch ( a2 )
{
case 2:
v22 = lgamma((float)((float)a1 - a3));
v42 = (float)(1.0 - a3);
v23 = v22 - lgamma(v42);
v36 = gsl_sf_psi((float)((float)a1 - a3));
v11 = gsl_sf_psi(v42);
result = log(v36 - v11) + v23;
break;
case 3:
v32 = gsl_sf_psi((float)((float)a1 - a3));
v18 = (float)(1.0 - a3);
v8 = v32 - gsl_sf_psi(v18);
v33 = (float)((float)a1 - a3);
v46 = lgamma(v33);
v19 = lgamma(v18);
v34 = gsl_sf_psi_n(1LL, v33);
v9 = gsl_sf_psi_n(1LL, (float)(1.0 - a3));
result = v46 - v19 - 0.6931471805599453 + log(v34 - v9 + v8 * v8);
break;
case 4:
v26 = gsl_sf_psi((float)((float)a1 - a3));
v13 = (float)(1.0 - a3);
v5 = v26 - gsl_sf_psi(v13);
v27 = (float)((float)a1 - a3);
v50 = lgamma(v27);
v44 = v13;
v14 = lgamma(v13);
v28 = gsl_sf_psi_n(2LL, v27);
v29 = v28 - gsl_sf_psi_n(2LL, v44);
v39 = gsl_sf_psi_n(1LL, (float)((float)a1 - a3));
v6 = v39 - gsl_sf_psi_n(1LL, v44);
result = v50 - v14 - 1.791759469228055 + log(3.0 * v6 * v5 + v29 + v5 * (v5 * v5));
break;
}
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func0(int a1, int a2, float a3)
{
double result; // xmm0_8
double v5; // xmm3_8
double v6; // xmm2_8
double v7; // xmm0_8
double v8; // xmm2_8
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // xmm0_8
double v12; // xmm0_8
double v13; // [rsp+0h] [rbp-50h]
double v14; // [rsp+0h] [rbp-50h]
double v15; // [rsp+0h] [rbp-50h]
double v16; // [rsp+0h] [rbp-50h]
double v17; // [rsp+0h] [rbp-50h]
double v18; // [rsp+0h] [rbp-50h]
double v19; // [rsp+0h] [rbp-50h]
double v20; // [rsp+0h] [rbp-50h]
double v21; // [rsp+0h] [rbp-50h]
double v22; // [rsp+0h] [rbp-50h]
double v23; // [rsp+0h] [rbp-50h]
double v24; // [rsp+0h] [rbp-50h]
double v25; // [rsp+0h] [rbp-50h]
double v26; // [rsp+8h] [rbp-48h]
double v27; // [rsp+8h] [rbp-48h]
double v28; // [rsp+8h] [rbp-48h]
double v29; // [rsp+8h] [rbp-48h]
double v30; // [rsp+8h] [rbp-48h]
double v31; // [rsp+8h] [rbp-48h]
double v32; // [rsp+8h] [rbp-48h]
double v33; // [rsp+8h] [rbp-48h]
double v34; // [rsp+8h] [rbp-48h]
double v35; // [rsp+8h] [rbp-48h]
double v36; // [rsp+8h] [rbp-48h]
double v37; // [rsp+8h] [rbp-48h]
double v38; // [rsp+8h] [rbp-48h]
double v39; // [rsp+10h] [rbp-40h]
double v40; // [rsp+10h] [rbp-40h]
double v41; // [rsp+10h] [rbp-40h]
double v42; // [rsp+10h] [rbp-40h]
double v43; // [rsp+10h] [rbp-40h]
double v44; // [rsp+18h] [rbp-38h]
double v45; // [rsp+18h] [rbp-38h]
double v46; // [rsp+18h] [rbp-38h]
double v47; // [rsp+18h] [rbp-38h]
float v48; // [rsp+18h] [rbp-38h]
double v49; // [rsp+18h] [rbp-38h]
double v50; // [rsp+20h] [rbp-30h]
double v51; // [rsp+20h] [rbp-30h]
double v52; // [rsp+20h] [rbp-30h]
float v53; // [rsp+28h] [rbp-28h]
double v54; // [rsp+28h] [rbp-28h]
double v55; // [rsp+28h] [rbp-28h]
double v56; // [rsp+30h] [rbp-20h]
double v57; // [rsp+30h] [rbp-20h]
double x; // [rsp+38h] [rbp-18h]

if ( a1 == a2 )
return 0.0;
result = *(double *)&LC1;
if ( a1 >= a2 )
{
if ( a2 == 1 )
{
v15 = lgamma((float)((float)a1 - a3));
result = v15 - lgamma((float)(1.0 - a3));
}
else if ( a3 >= 0.001 )
{
switch ( a2 )
{
case 2:
v47 = lgamma((float)((float)a1 - a3));
v35 = lgamma((float)(1.0 - a3));
v20 = lgamma((float)((float)a1 - (float)(a3 + a3)));
v21 = v20 - lgamma((float)(1.0 - (float)(a3 + a3)));
v41 = log(a3);
v10 = exp(v47 - v35 - v21);
result = v21 - v41 + log(v10 - 1.0);
break;
case 3:
v56 = lgamma((float)((float)a1 - a3));
v30 = lgamma((float)(1.0 - a3));
v53 = a3;
v51 = lgamma((float)((float)a1 - (float)(v53 + v53)));
v40 = lgamma((float)(1.0 - (float)(v53 + v53)));
v16 = lgamma((float)((float)a1 - (float)(a3 * 3.0)));
v17 = v16 - lgamma((float)(1.0 - (float)(a3 * 3.0)));
v45 = log(a3);
v31 = exp(v56 - v30 - v17);
v7 = exp(v51 - v40 - v17);
result = v17 - (v45 + v45) - 0.6931471805599453 + log(v31 - (v7 + v7) + 1.0);
break;
case 4:
v54 = lgamma((float)((float)a1 - a3));
v37 = lgamma((float)(1.0 - a3));
v48 = a3;
x = lgamma((float)((float)a1 - (float)(v48 + v48)));
v43 = lgamma((float)(1.0 - (float)(v48 + v48)));
v57 = lgamma((float)((float)a1 - (float)(a3 * 3.0)));
v49 = lgamma((float)(1.0 - (float)(a3 * 3.0)));
v24 = lgamma((float)((float)a1 - (float)(a3 * 4.0)));
v25 = v24 - lgamma((float)(1.0 - (float)(a3 * 4.0)));
v52 = log(a3);
v55 = exp(v54 - v37 - v25);
v38 = exp(x - v43 - v25);
v12 = exp(v57 - v49 - v25);
result = v25 - 3.0 * v52 - 1.791759469228055 + log(v55 - v38 * 3.0 + v12 * 3.0 - 1.0);
break;
}
}
else
{
switch ( a2 )
{
case 2:
v22 = lgamma((float)((float)a1 - a3));
v42 = (float)(1.0 - a3);
v23 = v22 - lgamma(v42);
v36 = gsl_sf_psi((float)((float)a1 - a3));
v11 = gsl_sf_psi(v42);
result = log(v36 - v11) + v23;
break;
case 3:
v32 = gsl_sf_psi((float)((float)a1 - a3));
v18 = (float)(1.0 - a3);
v8 = v32 - gsl_sf_psi(v18);
v33 = (float)((float)a1 - a3);
v46 = lgamma(v33);
v19 = lgamma(v18);
v34 = gsl_sf_psi_n(1LL, v33);
v9 = gsl_sf_psi_n(1LL, (float)(1.0 - a3));
result = v46 - v19 - 0.6931471805599453 + log(v34 - v9 + v8 * v8);
break;
case 4:
v26 = gsl_sf_psi((float)((float)a1 - a3));
v13 = (float)(1.0 - a3);
v5 = v26 - gsl_sf_psi(v13);
v27 = (float)((float)a1 - a3);
v50 = lgamma(v27);
v44 = v13;
v14 = lgamma(v13);
v28 = gsl_sf_psi_n(2LL, v27);
v29 = v28 - gsl_sf_psi_n(2LL, v44);
v39 = gsl_sf_psi_n(1LL, (float)((float)a1 - a3));
v6 = v39 - gsl_sf_psi_n(1LL, v44);
result = v50 - v14 - 1.791759469228055 + log(3.0 * v6 * v5 + v29 + v5 * (v5 * v5));
break;
}
}
}
return result;
}

original_code:
double S_approx(int n, int m, float a) {
  ((void) (0));
  if ( n==m )
    return 0.0;
  if ( n<m )
    return -(__builtin_huge_val ());
  if ( m==1 ) {
    return lgamma(n-a) - lgamma(1-a);
  } else if ( a<0.001 ) {
    if (m==2 ) {
      return lgamma(n-a) - lgamma(1-a) +
 log(gsl_sf_psi(n-a) - gsl_sf_psi(1-a));
    } else if ( m==3 ) {
      double gg = gsl_sf_psi(n-a) - gsl_sf_psi(1-a);
      return lgamma(n-a) - lgamma(1-a) - log(2.0) +
 log(gsl_sf_psi_n(1,n-a) - gsl_sf_psi_n(1,1-a) + gg*gg);
    } else if ( m==4 ) {
      double gg = gsl_sf_psi(n-a) - gsl_sf_psi(1-a);
      return lgamma(n-a) - lgamma(1-a) - log(6.0) +
 log((gsl_sf_psi_n(2,n-a) - gsl_sf_psi_n(2,1-a)) +
     3*(gsl_sf_psi_n(1,n-a) - gsl_sf_psi_n(1,1-a))*gg + gg*gg*gg);
    }
  } else if ( m==2 ) {
    double ga = lgamma(n-a) - lgamma(1-a);
    double g2a = lgamma(n-2*a) - lgamma(1-2*a);
    return g2a - log(a) + log(exp(ga-g2a)-1.0);
  } else if ( m==3 ) {
    double ga = lgamma(n-a) - lgamma(1-a);
    double g2a = lgamma(n-2*a) - lgamma(1-2*a);
    double g3a = lgamma(n-3*a) - lgamma(1-3*a);
    return g3a - 2*log(a) - log(2.0) +
      log(exp(ga-g3a)-2*exp(g2a-g3a)+1.0);
  } else if ( m==4 ) {
    double ga = lgamma(n-a) - lgamma(1-a);
    double g2a = lgamma(n-2*a) - lgamma(1-2*a);
    double g3a = lgamma(n-3*a) - lgamma(1-3*a);
    double g4a = lgamma(n-4*a) - lgamma(1-4*a);
    return g4a - 3*log(a) - log(6.0) +
      log(exp(ga-g4a)-3*exp(g2a-g4a)+3*exp(g3a-g4a)-1.0);
  }
  return -(__builtin_huge_val ());
}

variable_types: n int

variable_types: m int

variable_types: a float

variable_types: gg double

variable_types: ga double


decompiled_code:
double __fastcall S_approx_da(int a1, int a2, float a3)
{
float v3; // xmm1_4
double result; // xmm0_8
double v6; // rbx
double v7; // rbp
double v8; // rbp
double v9; // rbx
double v10; // rbx
double v11; // rbp
__m128i v12; // xmm7
float v13; // ebx
double v14; // rbx
double v15; // rbp
float v16; // [rsp+0h] [rbp-98h]
float v17; // [rsp+0h] [rbp-98h]
double v18; // [rsp+0h] [rbp-98h]
double v19; // [rsp+0h] [rbp-98h]
double v20; // [rsp+0h] [rbp-98h]
double v21; // [rsp+0h] [rbp-98h]
double v22; // [rsp+0h] [rbp-98h]
double v23; // [rsp+0h] [rbp-98h]
double v24; // [rsp+0h] [rbp-98h]
double v25; // [rsp+0h] [rbp-98h]
double v26; // [rsp+8h] [rbp-90h]
double v27; // [rsp+10h] [rbp-88h]
double v28; // [rsp+10h] [rbp-88h]
double v29; // [rsp+10h] [rbp-88h]
double v30; // [rsp+10h] [rbp-88h]
double v31; // [rsp+10h] [rbp-88h]
double v32; // [rsp+10h] [rbp-88h]
double v33; // [rsp+10h] [rbp-88h]
double v34; // [rsp+18h] [rbp-80h]
double v35; // [rsp+18h] [rbp-80h]
double v36; // [rsp+18h] [rbp-80h]
double v37; // [rsp+18h] [rbp-80h]
float v38; // [rsp+18h] [rbp-80h]
double v39; // [rsp+18h] [rbp-80h]
double v40; // [rsp+18h] [rbp-80h]
double v41; // [rsp+20h] [rbp-78h]
double v42; // [rsp+20h] [rbp-78h]
float v43; // [rsp+20h] [rbp-78h]
double v44; // [rsp+20h] [rbp-78h]
double v45; // [rsp+20h] [rbp-78h]
double v46; // [rsp+20h] [rbp-78h]
float v47; // [rsp+28h] [rbp-70h]
double v48; // [rsp+28h] [rbp-70h]
double v49; // [rsp+28h] [rbp-70h]
double v50; // [rsp+28h] [rbp-70h]
double v51; // [rsp+28h] [rbp-70h]
double v52; // [rsp+30h] [rbp-68h]
double v53; // [rsp+30h] [rbp-68h]
double v54; // [rsp+30h] [rbp-68h]
double v55; // [rsp+30h] [rbp-68h]
double v56; // [rsp+38h] [rbp-60h]
double v57; // [rsp+38h] [rbp-60h]
double v58; // [rsp+38h] [rbp-60h]
double v59; // [rsp+40h] [rbp-58h]
double v60; // [rsp+40h] [rbp-58h]
double v61; // [rsp+48h] [rbp-50h]
double v62; // [rsp+48h] [rbp-50h]
double v63; // [rsp+48h] [rbp-50h]
double v64; // [rsp+50h] [rbp-48h]
double v65; // [rsp+50h] [rbp-48h]
double v66; // [rsp+58h] [rbp-40h]
double v67; // [rsp+60h] [rbp-38h]
double v68; // [rsp+68h] [rbp-30h]
double v69; // [rsp+70h] [rbp-28h]

if ( a1 == a2 )
return 0.0;
if ( a1 < a2 )
return *(double *)&LC1;
v3 = a3;
if ( a2 == 1 )
{
v6 = gsl_sf_psi((float)((float)a1 - a3));
*(_QWORD *)&result = COERCE_UNSIGNED_INT64(v6 - gsl_sf_psi((float)(1.0 - v3))) ^ LC10;
}
else
{
v16 = a3;
v26 = S_approx(a1, a2, a3);
if ( a2 == 2 )
{
v27 = lgamma((float)((float)a1 - a3));
v41 = (float)(1.0 - v16);
v47 = v16;
v52 = v27 - lgamma(v41);
v17 = v16 + v16;
v34 = (float)((float)a1 - v17);
v7 = lgamma(v34);
v28 = (float)(1.0 - v17);
v8 = v7 - lgamma(v28);
v9 = gsl_sf_psi((float)((float)a1 - a3));
v18 = gsl_sf_psi(v41);
v42 = gsl_sf_psi(v34);
v29 = gsl_sf_psi(v28);
v35 = exp(v52 - v26);
exp(v8 - v26);
result = (COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v9 - v18) ^ LC10) * v35 - (v42 - v29) * -2.0 * (v8 - v26) - 1.0)
/ v47;
}
else if ( a2 == 3 )
{
v30 = lgamma((float)((float)a1 - a3));
v66 = (float)(1.0 - a3);
v43 = a3;
v64 = v30 - lgamma(v66);
v19 = lgamma((float)((float)a1 - (float)(v43 + v43)));
v61 = (float)(1.0 - (float)(v43 + v43));
v48 = v19 - lgamma(v61);
v20 = lgamma((float)((float)a1 - (float)(a3 * 3.0)));
v36 = (float)(1.0 - (float)(a3 * 3.0));
v56 = v20 - lgamma(v36);
v10 = gsl_sf_psi((float)((float)a1 - a3));
v21 = gsl_sf_psi(v66);
v53 = gsl_sf_psi((float)((float)a1 - (float)(v43 + v43)));
v31 = gsl_sf_psi(v61);
v11 = gsl_sf_psi((float)((float)a1 - (float)(a3 * 3.0)));
v37 = gsl_sf_psi(v36);
v44 = exp(v64 - v26);
v49 = exp(v48 - v26);
result = (COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v10 - v21) ^ LC10) * v44
- (v53 - v31) * -2.0 * (v49 + v49)
+ (v11 - v37) * -3.0 * exp(v56 - v26))
* 0.5
/ a3
/ a3
+ (float)(-2.0 / a3);
}
else
{
result = *(double *)&LC1;
if ( a2 == 4 )
{
v12 = 0LL;
*(float *)v12.m128i_i32 = (float)a1;
v13 = COERCE_FLOAT(_mm_cvtsi128_si32(v12));
v32 = lgamma((float)((float)a1 - a3));
v69 = (float)(1.0 - a3);
v38 = a3;
v68 = v32 - lgamma(v69);
v62 = (float)(v13 - (float)(v38 + v38));
v22 = lgamma(v62);
v59 = (float)(1.0 - (float)(v38 + v38));
v67 = v22 - lgamma(v59);
v57 = (float)(v13 - (float)(a3 * 3.0));
v23 = lgamma(v57);
v39 = (float)(1.0 - (float)(a3 * 3.0));
v54 = v23 - lgamma(v39);
v50 = (float)(v13 - (float)(a3 * 4.0));
v24 = lgamma(v50);
v45 = (float)(1.0 - (float)(a3 * 4.0));
v65 = v24 - lgamma(v45);
v14 = gsl_sf_psi((float)((float)a1 - a3));
v25 = gsl_sf_psi(v69);
v63 = gsl_sf_psi(v62);
v33 = gsl_sf_psi(v59);
v60 = gsl_sf_psi(v57);
v40 = gsl_sf_psi(v39);
v15 = gsl_sf_psi(v50);
v46 = gsl_sf_psi(v45);
v51 = exp(v68 - v26);
v58 = exp(v67 - v26);
v55 = exp(v54 - v26);
result = (COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v14 - v25) ^ LC10) * v51
- v58 * 3.0 * ((v63 - v33) * -2.0)
+ v55 * 3.0 * ((v60 - v40) * -3.0)
- (v15 - v46) * -4.0 * exp(v65 - v26))
/ 3.0
/ a3
/ a3
/ a3
+ (float)(-3.0 / a3);
}
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func1(int a1, int a2, float a3)
{
float v3; // xmm1_4
double result; // xmm0_8
double v6; // rbx
double v7; // rbp
double v8; // rbp
double v9; // rbx
double v10; // rbx
double v11; // rbp
__m128i v12; // xmm7
float v13; // ebx
double v14; // rbx
double v15; // rbp
float v16; // [rsp+0h] [rbp-98h]
float v17; // [rsp+0h] [rbp-98h]
double v18; // [rsp+0h] [rbp-98h]
double v19; // [rsp+0h] [rbp-98h]
double v20; // [rsp+0h] [rbp-98h]
double v21; // [rsp+0h] [rbp-98h]
double v22; // [rsp+0h] [rbp-98h]
double v23; // [rsp+0h] [rbp-98h]
double v24; // [rsp+0h] [rbp-98h]
double v25; // [rsp+0h] [rbp-98h]
double v26; // [rsp+8h] [rbp-90h]
double v27; // [rsp+10h] [rbp-88h]
double v28; // [rsp+10h] [rbp-88h]
double v29; // [rsp+10h] [rbp-88h]
double v30; // [rsp+10h] [rbp-88h]
double v31; // [rsp+10h] [rbp-88h]
double v32; // [rsp+10h] [rbp-88h]
double v33; // [rsp+10h] [rbp-88h]
double v34; // [rsp+18h] [rbp-80h]
double v35; // [rsp+18h] [rbp-80h]
double v36; // [rsp+18h] [rbp-80h]
double v37; // [rsp+18h] [rbp-80h]
float v38; // [rsp+18h] [rbp-80h]
double v39; // [rsp+18h] [rbp-80h]
double v40; // [rsp+18h] [rbp-80h]
double v41; // [rsp+20h] [rbp-78h]
double v42; // [rsp+20h] [rbp-78h]
float v43; // [rsp+20h] [rbp-78h]
double v44; // [rsp+20h] [rbp-78h]
double v45; // [rsp+20h] [rbp-78h]
double v46; // [rsp+20h] [rbp-78h]
float v47; // [rsp+28h] [rbp-70h]
double v48; // [rsp+28h] [rbp-70h]
double v49; // [rsp+28h] [rbp-70h]
double v50; // [rsp+28h] [rbp-70h]
double v51; // [rsp+28h] [rbp-70h]
double v52; // [rsp+30h] [rbp-68h]
double v53; // [rsp+30h] [rbp-68h]
double v54; // [rsp+30h] [rbp-68h]
double v55; // [rsp+30h] [rbp-68h]
double v56; // [rsp+38h] [rbp-60h]
double v57; // [rsp+38h] [rbp-60h]
double v58; // [rsp+38h] [rbp-60h]
double v59; // [rsp+40h] [rbp-58h]
double v60; // [rsp+40h] [rbp-58h]
double v61; // [rsp+48h] [rbp-50h]
double v62; // [rsp+48h] [rbp-50h]
double v63; // [rsp+48h] [rbp-50h]
double v64; // [rsp+50h] [rbp-48h]
double v65; // [rsp+50h] [rbp-48h]
double v66; // [rsp+58h] [rbp-40h]
double v67; // [rsp+60h] [rbp-38h]
double v68; // [rsp+68h] [rbp-30h]
double v69; // [rsp+70h] [rbp-28h]

if ( a1 == a2 )
return 0.0;
if ( a1 < a2 )
return *(double *)&LC1;
v3 = a3;
if ( a2 == 1 )
{
v6 = gsl_sf_psi((float)((float)a1 - a3));
*(_QWORD *)&result = COERCE_UNSIGNED_INT64(v6 - gsl_sf_psi((float)(1.0 - v3))) ^ LC10;
}
else
{
v16 = a3;
v26 = func0(a1, a2, a3);
if ( a2 == 2 )
{
v27 = lgamma((float)((float)a1 - a3));
v41 = (float)(1.0 - v16);
v47 = v16;
v52 = v27 - lgamma(v41);
v17 = v16 + v16;
v34 = (float)((float)a1 - v17);
v7 = lgamma(v34);
v28 = (float)(1.0 - v17);
v8 = v7 - lgamma(v28);
v9 = gsl_sf_psi((float)((float)a1 - a3));
v18 = gsl_sf_psi(v41);
v42 = gsl_sf_psi(v34);
v29 = gsl_sf_psi(v28);
v35 = exp(v52 - v26);
exp(v8 - v26);
result = (COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v9 - v18) ^ LC10) * v35 - (v42 - v29) * -2.0 * (v8 - v26) - 1.0)
/ v47;
}
else if ( a2 == 3 )
{
v30 = lgamma((float)((float)a1 - a3));
v66 = (float)(1.0 - a3);
v43 = a3;
v64 = v30 - lgamma(v66);
v19 = lgamma((float)((float)a1 - (float)(v43 + v43)));
v61 = (float)(1.0 - (float)(v43 + v43));
v48 = v19 - lgamma(v61);
v20 = lgamma((float)((float)a1 - (float)(a3 * 3.0)));
v36 = (float)(1.0 - (float)(a3 * 3.0));
v56 = v20 - lgamma(v36);
v10 = gsl_sf_psi((float)((float)a1 - a3));
v21 = gsl_sf_psi(v66);
v53 = gsl_sf_psi((float)((float)a1 - (float)(v43 + v43)));
v31 = gsl_sf_psi(v61);
v11 = gsl_sf_psi((float)((float)a1 - (float)(a3 * 3.0)));
v37 = gsl_sf_psi(v36);
v44 = exp(v64 - v26);
v49 = exp(v48 - v26);
result = (COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v10 - v21) ^ LC10) * v44
- (v53 - v31) * -2.0 * (v49 + v49)
+ (v11 - v37) * -3.0 * exp(v56 - v26))
* 0.5
/ a3
/ a3
+ (float)(-2.0 / a3);
}
else
{
result = *(double *)&LC1;
if ( a2 == 4 )
{
v12 = 0LL;
*(float *)v12.m128i_i32 = (float)a1;
v13 = COERCE_FLOAT(_mm_cvtsi128_si32(v12));
v32 = lgamma((float)((float)a1 - a3));
v69 = (float)(1.0 - a3);
v38 = a3;
v68 = v32 - lgamma(v69);
v62 = (float)(v13 - (float)(v38 + v38));
v22 = lgamma(v62);
v59 = (float)(1.0 - (float)(v38 + v38));
v67 = v22 - lgamma(v59);
v57 = (float)(v13 - (float)(a3 * 3.0));
v23 = lgamma(v57);
v39 = (float)(1.0 - (float)(a3 * 3.0));
v54 = v23 - lgamma(v39);
v50 = (float)(v13 - (float)(a3 * 4.0));
v24 = lgamma(v50);
v45 = (float)(1.0 - (float)(a3 * 4.0));
v65 = v24 - lgamma(v45);
v14 = gsl_sf_psi((float)((float)a1 - a3));
v25 = gsl_sf_psi(v69);
v63 = gsl_sf_psi(v62);
v33 = gsl_sf_psi(v59);
v60 = gsl_sf_psi(v57);
v40 = gsl_sf_psi(v39);
v15 = gsl_sf_psi(v50);
v46 = gsl_sf_psi(v45);
v51 = exp(v68 - v26);
v58 = exp(v67 - v26);
v55 = exp(v54 - v26);
result = (COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v14 - v25) ^ LC10) * v51
- v58 * 3.0 * ((v63 - v33) * -2.0)
+ v55 * 3.0 * ((v60 - v40) * -3.0)
- (v15 - v46) * -4.0 * exp(v65 - v26))
/ 3.0
/ a3
/ a3
/ a3
+ (float)(-3.0 / a3);
}
}
}
return result;
}

original_code:
double S_approx_da(int n, int m, float a) {
  double snm;
  ((void) (0));
  if ( n==m )
    return 0.0;
  if ( n<m )
    return -(__builtin_huge_val ());
  if ( m==1 ) {
    return -(gsl_sf_psi(n-a) - gsl_sf_psi(1-a));
  }
  snm = S_approx(n, m, a);
  if ( m==2 ) {
    double ga = lgamma(n-a) - lgamma(1-a);
    double g2a = lgamma(n-2*a) - lgamma(1-2*a);
    double dga = -(gsl_sf_psi(n-a) - gsl_sf_psi(1-a));
    double dg2a = -2.0*(gsl_sf_psi(n-2*a) - gsl_sf_psi(1-2*a));
    return (exp(ga-snm)*dga - exp(g2a-snm)*dg2a - 1)/a;
  } else if ( m==3 ) {
    double ga = lgamma(n-a) - lgamma(1-a);
    double g2a = lgamma(n-2*a) - lgamma(1-2*a);
    double g3a = lgamma(n-3*a) - lgamma(1-3*a);
    double dga = -(gsl_sf_psi(n-a) - gsl_sf_psi(1-a));
    double dg2a = -2*(gsl_sf_psi(n-2*a) - gsl_sf_psi(1-2*a));
    double dg3a = -3*(gsl_sf_psi(n-3*a) - gsl_sf_psi(1-3*a));
    return - 2/a + (exp(ga-snm)*dga-2*exp(g2a-snm)*dg2a+exp(g3a-snm)*dg3a)/2/a/a;
  } else if ( m==4 ) {
    double ga = lgamma(n-a) - lgamma(1-a);
    double g2a = lgamma(n-2*a) - lgamma(1-2*a);
    double g3a = lgamma(n-3*a) - lgamma(1-3*a);
    double g4a = lgamma(n-4*a) - lgamma(1-4*a);
    double dga = -(gsl_sf_psi(n-a) - gsl_sf_psi(1-a));
    double dg2a = -2*(gsl_sf_psi(n-2*a) - gsl_sf_psi(1-2*a));
    double dg3a = -3*(gsl_sf_psi(n-3*a) - gsl_sf_psi(1-3*a));
    double dg4a = -4*(gsl_sf_psi(n-4*a) - gsl_sf_psi(1-4*a));
    return - 3/a +
      (exp(ga-snm)*dga-3*exp(g2a-snm)*dg2a+3*exp(g3a-snm)*dg3a-exp(g4a-snm)*dg4a)/3/a/a/a;
  }
  return -(__builtin_huge_val ());
}

variable_types: snm double

variable_types: dga double


diffset

decompiled_code:
void diffset()
{
__int64 i; // rbx

for ( i = 3LL; i != 2000; ++i )
{
fg[i] = lgamma((double)(int)i);
fp0[i] = gsl_sf_psi((double)(int)i);
fp1[i] = gsl_sf_psi_n(1LL, (double)(int)i);
fp2[i] = gsl_sf_psi_n(2LL, (double)(int)i);
fp3[i] = gsl_sf_psi_n(3LL, (double)(int)i);
}
fset = 1;
}

canonical_decompiled_code:
void func0()
{
__int64 i; // rbx

for ( i = 3LL; i != 2000; ++i )
{
fg[i] = lgamma((double)(int)i);
fp0[i] = gsl_sf_psi((double)(int)i);
fp1[i] = gsl_sf_psi_n(1LL, (double)(int)i);
fp2[i] = gsl_sf_psi_n(2LL, (double)(int)i);
fp3[i] = gsl_sf_psi_n(3LL, (double)(int)i);
}
fset = 1;
}

original_code:
static void diffset(void) {
  int i;
  for (i=3; i<2000; i++) {
    fg[i] = lgamma(i);
    fp0[i] = gsl_sf_psi(i);
    fp1[i] = gsl_sf_psi_n(1,i);
    fp2[i] = gsl_sf_psi_n(2,i);
    fp3[i] = gsl_sf_psi_n(3,i);
  }
  fset = 1;
}

canonical_original_code:
static void diffset() {
  int i;
  for (i=3; i<2000; i++) {
    fg[i] = lgamma(i);
    fp0[i] = gsl_sf_psi(i);
    fp1[i] = gsl_sf_psi_n(1,i);
    fp2[i] = gsl_sf_psi_n(2,i);
    fp3[i] = gsl_sf_psi_n(3,i);
  }
  fset = 1;
}

variable_types: i int


decompiled_code:
__int64 __fastcall gcache_init(__int64 a1, double a2)
{
double v2; // xmm0_8
__int64 result; // rax

*(double *)a1 = a2;
v2 = lgamma(a2);
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
*(double *)(a1 + 8) = v2;
*(_QWORD *)(a1 + 808) = 0LL;
memset(
(void *)((a1 + 24) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 24) & 0xFFFFFFF8) + 816) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, double a2)
{
double v2; // xmm0_8
__int64 result; // rax

*(double *)a1 = a2;
v2 = lgamma(a2);
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
*(double *)(a1 + 8) = v2;
*(_QWORD *)(a1 + 808) = 0LL;
memset(
(void *)((a1 + 24) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 24) & 0xFFFFFFF8) + 816) >> 3));
return result;
}

original_code:
void gcache_init(struct gcache_s *lgp, double p) {
  lgp->par = p;
  lgp->lgpar = lgamma(p);
  memset(lgp->cache, 0, 100*sizeof(lgp->cache[0]));
}

variable_types: struct gcache_s { double par; double lgpar; double cache[100]; } *

variable_types: p double


decompiled_code:
void __fastcall gcache_value(double *a1, int a2)
{
__int64 v2; // rbp
double v3; // xmm0_8

if ( a2 > 0 )
{
if ( a2 > 99 )
{
lgamma((double)a2 + *a1);
}
else
{
v2 = a2 + 2LL;
if ( a1[v2] == 0.0 )
{
v3 = *a1;
switch ( a2 )
{
case 1:
a1[3] = log(v3);
break;
case 2:
a1[4] = log(v3 * (v3 + 1.0));
break;
case 3:
a1[5] = log((v3 + 2.0) * ((v3 + 1.0) * v3));
break;
default:
a1[v2] = lgamma(v3 + (double)a2) - a1[1];
break;
}
}
}
}
}

original_code:
double gcache_value(struct gcache_s *lgp, int j) {
  if ( j<=0 )
    return 0;
  if ( j>=100 )
    return lgamma(j+lgp->par) - lgp->lgpar;
  if ( lgp->cache[j]==0 ) {
    if ( j==1 )
      lgp->cache[j] = log(lgp->par);
    else if ( j==2 )
      lgp->cache[j] = log(lgp->par*(lgp->par+1));
    else if ( j==3 )
      lgp->cache[j] = log(lgp->par*(lgp->par+1)*(lgp->par+2));
   else
    lgp->cache[j] = lgamma(j+lgp->par) - lgp->lgpar;
  }
  return lgp->cache[j];
}

variable_types: j int

user_defined_types: struct gcache_s { double par; double lgpar; double cache[100]; }


decompiled_code:
__int64 __fastcall pcache_init(__int64 a1, double a2)
{
double v2; // xmm0_8
__int64 result; // rax

*(double *)a1 = a2;
v2 = gsl_sf_psi(a2);
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
*(double *)(a1 + 8) = v2;
*(_QWORD *)(a1 + 808) = 0LL;
memset(
(void *)((a1 + 24) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 24) & 0xFFFFFFF8) + 816) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, double a2)
{
double v2; // xmm0_8
__int64 result; // rax

*(double *)a1 = a2;
v2 = gsl_sf_psi(a2);
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
*(double *)(a1 + 8) = v2;
*(_QWORD *)(a1 + 808) = 0LL;
memset(
(void *)((a1 + 24) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 24) & 0xFFFFFFF8) + 816) >> 3));
return result;
}

original_code:
void pcache_init(struct gcache_s *lgp, double p) {
  lgp->par = p;
  lgp->lgpar = gsl_sf_psi(p);
  memset(lgp->cache, 0, 100*sizeof(lgp->cache[0]));
}


original_code:
double pcache_value(struct gcache_s *lgp, int j) {
  if ( j<=0 )
    return 0;
  if ( j>=100 )
    return gsl_sf_psi(j+lgp->par) - lgp->lgpar;
  if ( lgp->cache[j]==0 ) {
    if ( j==1 )
      lgp->cache[j] = 1/lgp->par;
    else if ( j==2 )
      lgp->cache[j] = 1/lgp->par + 1/(1+lgp->par);
    else if ( j==3 )
      lgp->cache[j] = 1/lgp->par + 1/(1+lgp->par) + 1/(2+lgp->par);
    else
      lgp->cache[j] = gsl_sf_psi(j+lgp->par) - lgp->lgpar;
  }
  return lgp->cache[j];
}


decompiled_code:
__int64 __fastcall qcache_init(__int64 a1, double a2)
{
__int64 result; // rax
double v3; // [rsp+0h] [rbp-18h]

*(double *)a1 = a2;
if ( a2 > 0.0 )
{
v3 = lgamma(1.0 - (a2 + a2));
*(double *)(a1 + 8) = v3 - lgamma(1.0 - a2);
}
else
{
*(_QWORD *)(a1 + 8) = 0LL;
}
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
*(_QWORD *)(a1 + 808) = 0LL;
memset(
(void *)((a1 + 24) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 24) & 0xFFFFFFF8) + 816) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, double a2)
{
__int64 result; // rax
double v3; // [rsp+0h] [rbp-18h]

*(double *)a1 = a2;
if ( a2 > 0.0 )
{
v3 = lgamma(1.0 - (a2 + a2));
*(double *)(a1 + 8) = v3 - lgamma(1.0 - a2);
}
else
{
*(_QWORD *)(a1 + 8) = 0LL;
}
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
*(_QWORD *)(a1 + 808) = 0LL;
memset(
(void *)((a1 + 24) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 24) & 0xFFFFFFF8) + 816) >> 3));
return result;
}

original_code:
void qcache_init(struct gcache_s *lgp, double p) {
  lgp->par = p;
  if ( p>0 )
    lgp->lgpar = lgamma(1-2*p) - lgamma(1-p);
  else
    lgp->lgpar = 0;
  memset(lgp->cache, 0, 100*sizeof(lgp->cache[0]));
}


gammadiff

decompiled_code:
void __fastcall gammadiff(int a1, double a2, double a3)
{
double v3; // xmm2_8
double v4; // xmm0_8

v3 = a2;
if ( !fset )
{
diffset();
v3 = a2;
}
if ( a1 > 3 )
{
if ( v3 > 0.5 )
{
lgamma((double)a1 + v3);
lgamma(v3);
}
else if ( a3 == 0.0 )
{
log((v3 + 1.0) * v3 * (v3 + 2.0));
if ( a1 > 1999 )
lgamma((double)a1 + v3);
}
else if ( a1 > 1999 )
{
lgamma((double)a1 + v3);
}
}
else if ( a1 <= 1 )
{
if ( a1 )
log(v3);
}
else
{
v4 = (v3 + 1.0) * v3;
if ( a1 != 2 )
v4 = v4 * (v3 + 2.0);
log(v4);
}
}

original_code:
double gammadiff(int N, double alpha, double lga) {
  double val;
  if ( fset==0 ) diffset();
  if ( N<=3 ) {
    if ( N<=1 ) {
      if ( N==0 )
 return 0;
      return log(alpha);
    }
    if ( N==2 )
      return log(alpha*(1+alpha));
    return log(alpha*(1+alpha)*(2+alpha));
  } else if ( alpha>0.5 ) {
    return lgamma(N+alpha) - lgamma(alpha);
  } else if ( lga != 0 ) {
    if ( N>= 2000 )
      val = lgamma(N+alpha);
    else
      val = fg[N]
 + alpha*(fp0[N]
   + alpha/2 * (fp1[N] + alpha/3 * fp2[N]));
    return val - lga;
  }
  val = log(alpha*(1+alpha)*(2+alpha));
  if ( N>= 2000 )
    val += lgamma(N+alpha) -
      ( fg[3] + alpha*(fp0[3] +
         alpha/2 * ( fp1[3] + alpha/3 * fp2[3])));
  else
    val += fg[N]-fg[3]
      + alpha*( (fp0[N]-fp0[3])
  + alpha/2 * ((fp1[N]-fp1[3])
        + alpha/3 * (fp2[N]-fp2[3])));
  return val;
}

variable_types: N int

variable_types: alpha double

variable_types: lga double

variable_types: val double


psidiff

original_code:
double psidiff(int N, double alpha, double pa) {
  double val;
  ((void) (0));
  if ( fset==0 ) diffset();
  if ( N<=3 ) {
    if ( N<=1 ) {
      if ( N==0 )
 return 0;
      return 1/alpha;
    }
    if ( N==2 )
      return 1/alpha + 1/(1+alpha);
    return 1/alpha + 1/(1+alpha) + 1/(2+alpha);
  } else if ( alpha>0.5 ) {
    return gsl_sf_psi(N+alpha) - (pa>0)?pa:gsl_sf_psi(alpha);
  } else if ( pa != 0 ) {
    if ( N>= 2000 )
      val = gsl_sf_psi(N+alpha);
    else
      val = fp0[N] + alpha*(fp1[N]
       + alpha/2 * (fp2[N] + alpha/3 * fp3[N]));
    return val - pa;
  }
  val = 1/alpha + 1/(1+alpha) + 1/(2+alpha);
  if ( N>= 2000 )
    val += lgamma(N+alpha) -
      ( fp0[3] + alpha*(fp1[3] +
   alpha/2 * ( fp2[3] + alpha/3 * fp3[3])));
  else
    val += fp0[N]-fp0[3] + alpha*(fp1[N]-fp1[3])
      + alpha*alpha/2 * (fp2[N]-fp2[3])
      + alpha*alpha*alpha/6 * (fp3[N]-fp3[3]);
  return val;
}

variable_types: pa double


original_code:
static uint32_t sympoly_sample_full(int K, int H, double *val, rngp_t rng) {
  int h, k;
  double *esp, espp[10*10];
  uint32_t wr;
  double mult = 1;
  ((void) (0));
  ((void) (0));
  ((void) (0));
  if ( H*K<10*10 )
    esp = &espp[0];
  else
    esp = malloc(sizeof(*esp)*K*H);
  if ( !esp )
    return 0;
  esp[0] = val[0];
  for (k=1; k<K; k++) {
    double vk = val[k];
    if ( vk>1 ) {
      double lastv = mult;
      mult /= vk;
      for (h=0; h<k && h<H; h++) {
 double thisv = esp[k-1+h*K];
 esp[k+h*K] = thisv/vk + lastv;
        lastv = thisv;
      }
      if ( h==k )
 esp[k+h*K] = lastv;
    } else {
      double lastv = mult;
      for (h=0; h<k && h<H; h++) {
 double thisv = esp[k-1+h*K];
 esp[k+h*K] = thisv + vk*lastv;
        lastv = thisv;
      }
      if ( h==k )
 esp[k+h*K] = vk*lastv;
    }
  }
  wr = 0;
  for (k=K-1, h=H; k>=h && h>0; k--) {
    ((void) (0));
    if ( val[k]<=1 ) {
      if ( esp[k+(h-1)*K]* gsl_ran_flat(rng, 0, 1) >= esp[k-1+(h-1)*K] ) {
 wr |= 1U<<(unsigned)k;
 h--;
      }
    } else {
      if ( esp[k+(h-1)*K]* gsl_ran_flat(rng, 0, 1) >= esp[k-1+(h-1)*K]/val[k] ) {
 wr |= 1U<<(unsigned)k;
 h--;
      }
    }
  }
  if ( esp!=&espp[0] )
    free(esp);
  ((void) (0));
  if ( h>0 )
    wr |= (1U<<(unsigned)h) - 1;
  return wr;
}

canonical_original_code:
static unsigned int sympoly_sample_full(int K, int H, double *val, struct gsl_rng *rng) {
  int h; int k;
  double *esp; double espp[-1];
  unsigned int wr;
  double mult = 1;
  ((void) (0));
  ((void) (0));
  ((void) (0));
  if ( H*K<10*10 )
    esp = &espp[0];
  else
    esp = malloc(sizeof(*esp)*K*H);
  if ( !esp )
    return 0;
  esp[0] = val[0];
  for (k=1; k<K; k++) {
    double vk = val[k];
    if ( vk>1 ) {
      double lastv = mult;
      mult /= vk;
      for (h=0; h<k && h<H; h++) {
 double thisv = esp[k-1+h*K];
 esp[k+h*K] = thisv/vk + lastv;
        lastv = thisv;
      }
      if ( h==k )
 esp[k+h*K] = lastv;
    } else {
      double lastv = mult;
      for (h=0; h<k && h<H; h++) {
 double thisv = esp[k-1+h*K];
 esp[k+h*K] = thisv + vk*lastv;
        lastv = thisv;
      }
      if ( h==k )
 esp[k+h*K] = vk*lastv;
    }
  }
  wr = 0;
  for (k=K-1, h=H; k>=h && h>0; k--) {
    ((void) (0));
    if ( val[k]<=1 ) {
      if ( esp[k+(h-1)*K]* gsl_ran_flat(rng, 0, 1) >= esp[k-1+(h-1)*K] ) {
 wr |= 1U<<(unsigned int)k;
 h--;
      }
    } else {
      if ( esp[k+(h-1)*K]* gsl_ran_flat(rng, 0, 1) >= esp[k-1+(h-1)*K]/val[k] ) {
 wr |= 1U<<(unsigned int)k;
 h--;
      }
    }
  }
  if ( esp!=&espp[0] )
    free(esp);
  ((void) (0));
  if ( h>0 )
    wr |= (1U<<(unsigned int)h) - 1;
  return wr;
}

variable_types: K int

variable_types: H int

variable_types:
val
double *

variable_types: struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *

variable_types: h int

variable_types: k int

variable_types:
esp
double *

variable_types:
espp
double [-1]

variable_types:
wr
unsigned int

variable_types: mult double

variable_types: vk double

variable_types: lastv double

variable_types: thisv double

return_type: unsigned int


sympoly

original_code:
int sympoly(int K, double *val, double *res, double *overflow) {
  int h, k;
  double mult = 1;
  *overflow = 0;
  res[0] = 1;
  for (k=1; k<=K; k++)
    res[k] = 0;
  if ( K==0 )
    return 0;
  res[1] = val[0];
  for (k=1; k<K; k++) {
    double vk = val[k];
    if ( vk>1 ) {
      double lastv = mult;
      mult /= vk;
      *overflow += log(vk);
      for (h=1; h<=k; h++) {
 double thisv = res[h];
 res[h] = thisv/vk + lastv;
 lastv = thisv;
      }
      res[h] = lastv;
    } else {
      double lastv = mult;
      for (h=1; h<=k; h++) {
 double thisv = res[h];
 res[h] += vk*lastv;
 lastv = thisv;
      }
      res[h] = vk*lastv;
    }
  }
  if ( *overflow<15 ) {
    double eo = exp(*overflow);
    for (h=1; h<=K; h++)
      res[h] *= eo;
    *overflow = 0;
  }
  return 0;
}

canonical_original_code:
int sympoly(int K, double *val, double *res, double *overflow) {
  int h; int k;
  double mult = 1;
  *overflow = 0;
  res[0] = 1;
  for (k=1; k<=K; k++)
    res[k] = 0;
  if ( K==0 )
    return 0;
  res[1] = val[0];
  for (k=1; k<K; k++) {
    double vk = val[k];
    if ( vk>1 ) {
      double lastv = mult;
      mult /= vk;
      *overflow += log(vk);
      for (h=1; h<=k; h++) {
 double thisv = res[h];
 res[h] = thisv/vk + lastv;
 lastv = thisv;
      }
      res[h] = lastv;
    } else {
      double lastv = mult;
      for (h=1; h<=k; h++) {
 double thisv = res[h];
 res[h] += vk*lastv;
 lastv = thisv;
      }
      res[h] = vk*lastv;
    }
  }
  if ( *overflow<15 ) {
    double eo = exp(*overflow);
    for (h=1; h<=K; h++)
      res[h] *= eo;
    *overflow = 0;
  }
  return 0;
}

variable_types:
res
double *

variable_types:
overflow
double *

variable_types: eo double


decompiled_code:
__int64 __fastcall sympoly_sample(int a1, int a2, double *a3, __int64 a4)
{
double *v4; // rbx
__int64 v5; // rdx
double v6; // xmm2_8
double *v7; // rax
double v8; // xmm0_8
int v9; // ecx
double v10; // xmm0_8

if ( a2 == 0 || a2 > a1 || !a1 )
return 0LL;
if ( a2 == a1 )
return (unsigned int)((1 << a2) - 1);
if ( a2 > 1 )
return sympoly_sample_full(a1, a2, a3, a4);
if ( a1 <= 0 )
{
gsl_ran_flat(a4, 0.0);
return 0LL;
}
v4 = a3;
v5 = (__int64)&a3[(unsigned int)(a1 - 1) + 1];
v6 = 0.0;
v7 = v4;
do
v6 = v6 + *v7++;
while ( (double *)v5 != v7 );
v8 = gsl_ran_flat(a4, 0.0);
v9 = 0;
v10 = v8 * v6;
while ( v10 > 0.0 )
{
v10 = v10 - *v4++;
if ( a1 == v9 + 1 )
return (unsigned int)(1 << v9);
++v9;
}
LOBYTE(v9) = v9 - 1;
return (unsigned int)(1 << v9);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, double *a3, __int64 a4)
{
double *v4; // rbx
__int64 v5; // rdx
double v6; // xmm2_8
double *v7; // rax
double v8; // xmm0_8
int v9; // ecx
double v10; // xmm0_8

if ( a2 == 0 || a2 > a1 || !a1 )
return 0LL;
if ( a2 == a1 )
return (unsigned int)((1 << a2) - 1);
if ( a2 > 1 )
return func0(a1, a2, a3, a4);
if ( a1 <= 0 )
{
gsl_ran_flat(a4, 0.0);
return 0LL;
}
v4 = a3;
v5 = (__int64)&a3[(unsigned int)(a1 - 1) + 1];
v6 = 0.0;
v7 = v4;
do
v6 = v6 + *v7++;
while ( (double *)v5 != v7 );
v8 = gsl_ran_flat(a4, 0.0);
v9 = 0;
v10 = v8 * v6;
while ( v10 > 0.0 )
{
v10 = v10 - *v4++;
if ( a1 == v9 + 1 )
return (unsigned int)(1 << v9);
++v9;
}
LOBYTE(v9) = v9 - 1;
return (unsigned int)(1 << v9);
}

original_code:
uint32_t sympoly_sample(int K, int H, double *val, rngp_t rng) {
  int k ;
  double sum;
  if ( H>K || K==0 || H==0 )
    return 0U;
  if ( H==K ) {
    return (1U<<(unsigned)H) - 1;
  }
  if ( H>1 ) {
    return sympoly_sample_full(K, H, val, rng);
  }
  ((void) (0));
  sum = 0;
  for (k=0; k<K; k++) {
    sum += val[k];
  }
  sum *= gsl_ran_flat(rng, 0, 1);
  for (k=0; k<K && sum>0; k++)
    sum -= val[k];
  ((void) (0));
  return 1U<<(unsigned)(k-1U);
}

canonical_original_code:
unsigned int sympoly_sample(int K, int H, double *val, struct gsl_rng *rng) {
  int k;
  double sum;
  if ( H>K || K==0 || H==0 )
    return 0U;
  if ( H==K ) {
    return (1U<<(unsigned int)H) - 1;
  }
  if ( H>1 ) {
    return sympoly_sample_full(K, H, val, rng);
  }
  ((void) (0));
  sum = 0;
  for (k=0; k<K; k++) {
    sum += val[k];
  }
  sum *= gsl_ran_flat(rng, 0, 1);
  for (k=0; k<K && sum>0; k++)
    sum -= val[k];
  ((void) (0));
  return 1U<<(unsigned int)(k-1U);
}

variable_types: sum double


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

va_start(arg, format);
if ( yaps )
result = yaps(format, arg);
else
result = vfprintf(stderr, format, arg);
return result;
}

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

va_start(arg, format);
if ( yaps )
result = yaps(format, arg);
else
result = vfprintf(stderr, format, arg);
return result;
}

original_code:
void yaps_message(const char *fmt, ...)
{
  va_list ap;
  __builtin_va_start(ap,fmt);
  if ( yaps )
    yaps(fmt, ap);
  else
    vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
}

canonical_original_code:
void yaps_message(char *fmt, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  if ( yaps )
    yaps(fmt, ap);
  else
    vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
}

variable_types:
fmt
char *


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

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

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

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

original_code:
void yaps_quit(const char *fmt, ...)
{
  va_list ap;
  __builtin_va_start(ap,fmt);
  if ( yaps )
    yaps(fmt, ap);
  else
    vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
  exit(1);
}

canonical_original_code:
void yaps_quit(char *fmt, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  if ( yaps )
    yaps(fmt, ap);
  else
    vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
  exit(1);
}


decompiled_code:
void __noreturn yaps_sysquit(char *format, ...)
{
int v2; // edi
char *v3; // rax
char *v4; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

v2 = *_errno_location();
if ( yaps )
{
v3 = strerror(v2);
call_yaps_constprop_0((__int64)"%s: ", v3);
}
else
{
v4 = strerror(v2);
fprintf(stderr, "%s: ", v4);
}
va_start(arg, format);
if ( yaps )
yaps(format, arg);
else
vfprintf(stderr, format, arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func4(char *format, ...)
{
int v2; // edi
char *v3; // rax
char *v4; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

v2 = *_errno_location();
if ( yaps )
{
v3 = strerror(v2);
func3((__int64)"%s: ", v3);
}
else
{
v4 = strerror(v2);
fprintf(stderr, "%s: ", v4);
}
va_start(arg, format);
if ( yaps )
yaps(format, arg);
else
vfprintf(stderr, format, arg);
exit(1);
}

original_code:
void yaps_sysquit(const char *fmt, ...)
{
  va_list ap;
  if ( yaps )
    call_yaps("%s: ", strerror((*__errno_location ())));
  else
    fprintf(stderr, "%s: ", strerror((*__errno_location ())));
  __builtin_va_start(ap,fmt);
  if ( yaps )
    yaps(fmt, ap);
  else
    vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
  exit(1);
}

canonical_original_code:
void yaps_sysquit(char *fmt, ...)
{
  __builtin_va_list ap;
  if ( yaps )
    call_yaps("%s: ", strerror((*__errno_location ())));
  else
    fprintf(stderr, "%s: ", strerror((*__errno_location ())));
  __builtin_va_start(ap,fmt);
  if ( yaps )
    yaps(fmt, ap);
  else
    vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
  exit(1);
}


samplea

original_code:
double samplea(double mya,
        int I, int *K, scnt_int *T,
        scnt_int **n, stcnt_int **t,
        void (*getval)(scnt_int *n, stcnt_int *t, unsigned i, unsigned k),
        double *bpar,
        rngp_t rng, int loops, int verbose) {
  double inita[3] = {0.01,1,0.98};
  int i, k;
  ALData ald;
  inita[1] = mya;
  if ( fabs(inita[1]-0.98)/0.98<0.00001 ) {
    inita[1] = 0.98*0.999 + 0.01*0.001;
  }
  if ( fabs(inita[1]-0.01)/0.01<0.00001 ) {
    inita[1] = 0.01*0.999 + 0.98*0.001;
  }
  if ( inita[1]-0.2>0.01 ) inita[0] = inita[1]-0.2;
  if ( inita[1]+0.2<0.98 ) inita[2] = inita[1]+0.2;
  ald.T = T;
  ald.n = n;
  ald.t = t;
  ald.I = I;
  ald.K = K;
  ald.val = getval;
  ald.bpar = bpar;
  ald.verbose = verbose;
  ald.maxt = 1;
  ald.maxn = 1;
  ald.S = ((void *)0);
  if ( getval ) {
    for (i=0; i<I; i++)
      for (k=0; k<K[i]; k++) {
 scnt_int myn;
 stcnt_int myt;
 getval(&myn, &myt, i, k);
 if ( myt>=ald.maxt )
   ald.maxt = myt+1;
 if ( myn>=ald.maxn )
   ald.maxn = myn+1;
      }
  } else {
    for (i=0; i<I; i++)
      for (k=0; k<K[i]; k++) {
 if ( t[i][k]>=ald.maxt )
   ald.maxt = t[i][k]+1;
 if ( n[i][k]>=ald.maxn )
   ald.maxn = n[i][k]+1;
      }
  }
  inita[1] = 0.98;
  if ( SliceSimple(&mya, aterms, inita, rng, loops, &ald) ) {
    fprintf(stderr,"SliceSimple error\n");
    exit(1);
  }
  if ( ald.S ) S_free(ald.S);
  return mya;
}

canonical_original_code:
double samplea(double mya, int I, int *K, unsigned int *T, unsigned int **n, unsigned short **t, void (*getval)(unsigned int *n, unsigned short *t, unsigned int i, unsigned int k), double *bpar, struct gsl_rng *rng, int loops, int verbose) {
  double inita[3] = {0.01,1,0.98};
  int i; int k;
  struct aldata ald;
  inita[1] = mya;
  if ( fabs(inita[1]-0.98)/0.98<0.00001 ) {
    inita[1] = 0.98*0.999 + 0.01*0.001;
  }
  if ( fabs(inita[1]-0.01)/0.01<0.00001 ) {
    inita[1] = 0.01*0.999 + 0.98*0.001;
  }
  if ( inita[1]-0.2>0.01 ) inita[0] = inita[1]-0.2;
  if ( inita[1]+0.2<0.98 ) inita[2] = inita[1]+0.2;
  ald.T = T;
  ald.n = n;
  ald.t = t;
  ald.I = I;
  ald.K = K;
  ald.val = getval;
  ald.bpar = bpar;
  ald.verbose = verbose;
  ald.maxt = 1;
  ald.maxn = 1;
  ald.S = ((void *)0);
  if ( getval ) {
    for (i=0; i<I; i++)
      for (k=0; k<K[i]; k++) {
 unsigned int myn;
 unsigned short myt;
 getval(&myn, &myt, i, k);
 if ( myt>=ald.maxt )
   ald.maxt = myt+1;
 if ( myn>=ald.maxn )
   ald.maxn = myn+1;
      }
  } else {
    for (i=0; i<I; i++)
      for (k=0; k<K[i]; k++) {
 if ( t[i][k]>=ald.maxt )
   ald.maxt = t[i][k]+1;
 if ( n[i][k]>=ald.maxn )
   ald.maxn = n[i][k]+1;
      }
  }
  inita[1] = 0.98;
  if ( SliceSimple(&mya, aterms, inita, rng, loops, &ald) ) {
    fprintf(stderr,"SliceSimple error\n");
    exit(1);
  }
  if ( ald.S ) S_free(ald.S);
  return mya;
}

variable_types: mya double

variable_types: I int

variable_types:
K
int *

variable_types:
T
unsigned int *

variable_types:
n
unsigned int **

variable_types:
t
unsigned short **

variable_types: void (*)(unsigned int *n, unsigned short *t, unsigned int i, unsigned int k)

variable_types:
bpar
double *

variable_types: loops int

variable_types: verbose int

variable_types:
inita
double [3]

variable_types: i int

variable_types: struct aldata { int I; int *K; unsigned int **n; unsigned short **t; void (*val)(unsigned int *n, unsigned short *t, unsigned int i, unsigned int k); int maxt; int maxn; unsigned int *T; double *bpar; struct stable_s { unsigned int maxM; unsigned int usedM; unsigned int startM; double **S; float **Sf; double *SfrontN; double *SfrontM; double **V; float **Vf; double *VfrontN; double *VfrontM; unsigned int usedN1; double *S1; double lga; double a; unsigned int flags; unsigned int memalloced; char *tag; } *S; int verbose; }

variable_types:
myn
unsigned int

variable_types:
myt
unsigned short

user_defined_types: struct aldata { int I; int *K; unsigned int **n; unsigned short **t; void (*val)(unsigned int *n, unsigned short *t, unsigned int i, unsigned int k); int maxt; int maxn; unsigned int *T; double *bpar; struct stable_s *S; int verbose; }


repo: reschly/certgeneration

decompiled_code:
__int64 __fastcall commonname_type(const char *a1)
{
return 1 - ((unsigned int)(strchr(a1, 64) == 0LL) - 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
return 1 - ((unsigned int)(strchr(a1, 64) == 0LL) - 1);
}

original_code:
int commonname_type(char *cn)
{
 char* pos;
 pos = strchr(cn, '@');
 if (pos)
  return 2;
 else
  return 1;
}

canonical_original_code:
int commonname_type(char *cn)
{
 char *pos;
 pos = strchr(cn, '@');
 if (pos)
  return 2;
 else
  return 1;
}

variable_types:
cn
char *

variable_types:
pos
char *


gmalloc

decompiled_code:
void *__fastcall gmalloc(size_t a1)
{
void *result; // rax

if ( !a1 )
{
puts("gmalloc: zero size");
exit(-1);
}
result = malloc(a1);
if ( !result )
{
printf("gmalloc: out of memory (allocating %lu bytes)\n", a1);
exit(-1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

if ( !a1 )
{
puts("gmalloc: zero size");
exit(-1);
}
result = malloc(a1);
if ( !result )
{
printf("gmalloc: out of memory (allocating %lu bytes)\n", a1);
exit(-1);
}
return result;
}

original_code:
void* gmalloc(size_t size)
{
  void *ptr;
  if(size == 0) {
    printf("gmalloc: zero size\n");
    exit(-1);
  }
  ptr = malloc(size);
  if(ptr == ((void *)0)) {
    printf("gmalloc: out of memory (allocating %lu bytes)\n", (u_long) size);
    exit(-1);
  }
  return ptr;
}

canonical_original_code:
void *gmalloc(unsigned long size)
{
  void *ptr;
  if(size == 0) {
    printf("gmalloc: zero size\n");
    exit(-1);
  }
  ptr = malloc(size);
  if(ptr == ((void *)0)) {
    printf("gmalloc: out of memory (allocating %lu bytes)\n", (unsigned long) size);
    exit(-1);
  }
  return ptr;
}

variable_types:
size
unsigned long

variable_types:
ptr
void *

return_type: void *


gcalloc

decompiled_code:
void *__fastcall gcalloc(size_t a1, size_t a2)
{
void *result; // rax

if ( !a1 || !a2 )
{
puts("gcalloc: zero size");
exit(-1);
}
result = calloc(a1, a2);
if ( !result )
{
printf("gcalloc: out of memory (allocating %lu bytes)\n", a2 * a1);
exit(-1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1, size_t a2)
{
void *result; // rax

if ( !a1 || !a2 )
{
puts("gcalloc: zero size");
exit(-1);
}
result = calloc(a1, a2);
if ( !result )
{
printf("gcalloc: out of memory (allocating %lu bytes)\n", a2 * a1);
exit(-1);
}
return result;
}

original_code:
void* gcalloc(size_t nmemb, size_t size)
{
  void* *ptr;
  if(nmemb == 0 || size == 0) {
    printf("gcalloc: zero size\n");
    exit(-1);
  }
  ptr = calloc(nmemb, size);
  if(ptr == ((void *)0)) {
    printf("gcalloc: out of memory (allocating %lu bytes)\n",
           (u_long)nmemb*size);
    exit(-1);
  }
  return ptr;
}

canonical_original_code:
void *gcalloc(unsigned long nmemb, unsigned long size)
{
  void **ptr;
  if(nmemb == 0 || size == 0) {
    printf("gcalloc: zero size\n");
    exit(-1);
  }
  ptr = calloc(nmemb, size);
  if(ptr == ((void *)0)) {
    printf("gcalloc: out of memory (allocating %lu bytes)\n",
           (unsigned long)nmemb*size);
    exit(-1);
  }
  return ptr;
}

variable_types:
nmemb
unsigned long

variable_types:
ptr
void **


grealloc

decompiled_code:
void *__fastcall grealloc(void *a1, size_t a2)
{
void *result; // rax

if ( !a2 )
{
puts("grealloc: zero size");
exit(-1);
}
if ( a1 )
result = realloc(a1, a2);
else
result = malloc(a2);
if ( !result )
{
printf("grealloc: out of memory (new size %lu bytes)\n", a2);
exit(-1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
void *result; // rax

if ( !a2 )
{
puts("grealloc: zero size");
exit(-1);
}
if ( a1 )
result = realloc(a1, a2);
else
result = malloc(a2);
if ( !result )
{
printf("grealloc: out of memory (new size %lu bytes)\n", a2);
exit(-1);
}
return result;
}

original_code:
void *grealloc(void *ptr, size_t size)
{
  void *new_ptr;
  if(size == 0) {
    printf("grealloc: zero size\n");
    exit(-1);
  }
  if(ptr == ((void *)0)) {
    new_ptr = malloc(size);
  } else {
    new_ptr = realloc(ptr, size);
  }
  if(new_ptr == ((void *)0)) {
    printf("grealloc: out of memory (new size %lu bytes)\n", (u_long)size);
    exit(-1);
  }
  return new_ptr;
}

canonical_original_code:
void *grealloc(void *ptr, unsigned long size)
{
  void *new_ptr;
  if(size == 0) {
    printf("grealloc: zero size\n");
    exit(-1);
  }
  if(ptr == ((void *)0)) {
    new_ptr = malloc(size);
  } else {
    new_ptr = realloc(ptr, size);
  }
  if(new_ptr == ((void *)0)) {
    printf("grealloc: out of memory (new size %lu bytes)\n", (unsigned long)size);
    exit(-1);
  }
  return new_ptr;
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er13
unsigned int v4; // er12
const char *v5; // rbp
int v6; // eax
const char **v7; // rbp
const char **v8; // rbx
const char *v9; // rsi

v3 = 0;
v4 = 0;
v5 = 0LL;
opterr = 0;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "abc:");
if ( v6 == -1 )
{
fprintf(stdout, "a = %d\nb = %d\ncstr = %s\n", v4, v3, v5);
if ( argc > optind )
{
v7 = &argv[optind];
v8 = &(&argv[optind])[(unsigned __int64)(unsigned int)(argc + ~optind) + 1];
do
{
v9 = *v7++;
printf("Additional argument %s\n", v9);
}
while ( v7 != v8 );
}
exit(0);
}
if ( v6 != 98 )
break;
v3 = 1;
}
if ( v6 <= 98 )
break;
if ( v6 != 99 )
goto LABEL_10;
v5 = (const char *)optarg;
}
if ( v6 == 63 )
{
if ( optopt == 99 )
fwrite("-c requires an argument.\n", 1uLL, 0x19uLL, stderr);
else
fprintf(stderr, "Unknown flag '%c'.\n", (unsigned int)optopt);
LABEL_10:
exit(1);
}
if ( v6 != 97 )
goto LABEL_10;
v4 = 1;
}
}

original_code:
int main (int argc, char **argv){
    int a = 0, b = 0;
    char *cstr = ((void *)0);
    int arg;
    opterr = 0;
    while ((arg = getopt (argc, argv, "abc:")) != -1){
        switch (arg){
            case 'a':
                a = 1;
                break;
            case 'b':
                b = 1;
                break;
            case 'c':
                cstr = optarg;
                break;
            case '?':
                if (optopt == 'c'){
                    fprintf(stderr, "-c requires an argument.\n");
                }else{
                    fprintf(stderr, "Unknown flag '%c'.\n", optopt);
                }
            default:
                exit(1);
        }
    }
    fprintf(stdout, "a = %d\nb = %d\ncstr = %s\n", a, b, cstr);
    for (int i = optind; i < argc; i++){
        printf("Additional argument %s\n", argv[i]);
    }
    exit(0);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv){
    int a = 0; int b = 0;
    char *cstr = ((void *)0);
    int arg;
    opterr = 0;
    while ((arg = getopt (argc, argv, "abc:")) != -1){
        switch (arg){
            case 'a':
                a = 1;
                break;
            case 'b':
                b = 1;
                break;
            case 'c':
                cstr = optarg;
                break;
            case '?':
                if (optopt == 'c'){
                    fprintf(stderr, "-c requires an argument.\n");
                }else{
                    fprintf(stderr, "Unknown flag '%c'.\n", optopt);
                }
            default:
                exit(1);
        }
    }
    fprintf(stdout, "a = %d\nb = %d\ncstr = %s\n", a, b, cstr);
    for (int i = optind; i < argc; i++){
        printf("Additional argument %s\n", argv[i]);
    }
    exit(0);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: a int

variable_types: b int

variable_types:
cstr
char *

variable_types: arg int


repo: reuteran/arp-spoofer

decompiled_code:
void __fastcall sig_handler(int a1)
{
if ( a1 == 2 )
g_running = 0;
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
if ( a1 == 2 )
g_running = 0;
}

original_code:
void sig_handler(int signum)
{
  if (signum == 2)
    g_running = 0;
}

variable_types: signum int


setupArpHdr

original_code:
struct arp_hdr *setupArpHdr(uint8_t *src_mac, uint8_t *src_ip, uint8_t *dest_mac, uint8_t *dest_ip)
{
  int status;
  struct arp_hdr *hdr = malloc(sizeof(struct arp_hdr));
  hdr->htype = htons(0x0001);
  hdr->ptype = htons(0x0800);
  hdr->hlen = 6;
  hdr->plen = 4;
  hdr->opcode = htons(2);
  memcpy(hdr->src_ip,src_ip,4);
  memcpy(hdr->dest_ip, dest_ip, 4);
  memcpy(hdr->src_mac, src_mac, 6);
  memcpy(hdr->dest_mac, dest_mac, 6);
  return hdr;
}

canonical_original_code:
struct arp_hdr *setupArpHdr(unsigned char *src_mac, unsigned char *src_ip, unsigned char *dest_mac, unsigned char *dest_ip)
{
  int status;
  struct arp_hdr *hdr = malloc(sizeof(struct arp_hdr));
  hdr->htype = htons(0x0001);
  hdr->ptype = htons(0x0800);
  hdr->hlen = 6;
  hdr->plen = 4;
  hdr->opcode = htons(2);
  memcpy(hdr->src_ip,src_ip,4);
  memcpy(hdr->dest_ip, dest_ip, 4);
  memcpy(hdr->src_mac, src_mac, 6);
  memcpy(hdr->dest_mac, dest_mac, 6);
  return hdr;
}

variable_types: status int

variable_types: struct arp_hdr { unsigned short htype; unsigned short ptype; unsigned char hlen; unsigned char plen; unsigned short opcode; unsigned char src_mac[6]; unsigned char src_ip[4]; unsigned char dest_mac[6]; unsigned char dest_ip[4]; } *


populateIfreq

decompiled_code:
char *__fastcall populateIfreq(const char *a1)
{
char *v1; // r12
int v2; // eax
int v3; // ebp

v1 = (char *)malloc(0x28uLL);
v2 = socket(2, 3, 255);
if ( v2 < 0 )
{
perror("socket() failed to get socket descriptor for using ioctl() ");
exit(1);
}
v3 = v2;
*(_QWORD *)v1 = 0LL;
snprintf(v1, 0x10uLL, "%s", a1);
if ( ioctl(v3, 0x8927uLL, v1) < 0 )
{
perror("ioctl() failed to get source MAC address ");
exit(1);
}
close(v3);
return v1;
}

canonical_decompiled_code:
char *__fastcall func11(const char *a1)
{
char *v1; // r12
int v2; // eax
int v3; // ebp

v1 = (char *)malloc(0x28uLL);
v2 = socket(2, 3, 255);
if ( v2 < 0 )
{
perror("socket() failed to get socket descriptor for using ioctl() ");
exit(1);
}
v3 = v2;
*(_QWORD *)v1 = 0LL;
snprintf(v1, 0x10uLL, "%s", a1);
if ( ioctl(v3, 0x8927uLL, v1) < 0 )
{
perror("ioctl() failed to get source MAC address ");
exit(1);
}
close(v3);
return v1;
}

original_code:
struct ifreq * populateIfreq(char *interface)
{
  int sd;
  struct ifreq *ifr = malloc(sizeof(struct ifreq));
  if ((sd = socket (2, SOCK_RAW, IPPROTO_RAW)) < 0) {
    perror ("socket() failed to get socket descriptor for using ioctl() ");
    exit (1);
  }
  memset (ifr, 0, sizeof (ifr));
  snprintf (ifr->ifr_ifrn.ifrn_name, sizeof (ifr->ifr_ifrn.ifrn_name), "%s", interface);
  if (ioctl (sd, 0x8927, ifr) < 0) {
    perror ("ioctl() failed to get source MAC address ");
    exit (1);
  }
  close (sd);
  return ifr;
}

canonical_original_code:
struct ifreq *populateIfreq(char *interface)
{
  int sd;
  struct ifreq *ifr = malloc(sizeof(struct ifreq));
  if ((sd = socket (2, SOCK_RAW, IPPROTO_RAW)) < 0) {
    perror ("socket() failed to get socket descriptor for using ioctl() ");
    exit (1);
  }
  memset (ifr, 0, sizeof (ifr));
  snprintf (ifr->ifr_ifrn.ifrn_name, sizeof (ifr->ifr_ifrn.ifrn_name), "%s", interface);
  if (ioctl (sd, 0x8927, ifr) < 0) {
    perror ("ioctl() failed to get source MAC address ");
    exit (1);
  }
  close (sd);
  return ifr;
}

variable_types:
interface
char *

variable_types: sd int

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

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


copykey

decompiled_code:
__int64 __fastcall copykey(_QWORD *a1, _QWORD *a2)
{
__int64 result; // rax

*a1 = *a2;
a1[1] = a2[1];
a1[2] = a2[2];
result = a2[3];
a1[3] = result;
return result;
}

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

*a1 = *a2;
a1[1] = a2[1];
a1[2] = a2[2];
result = a2[3];
a1[3] = result;
return result;
}

original_code:
static void
copykey(curve25519key_t *n, curve25519key_t *x) {
  int c;
  for (c = 0; c < (256/64); c++) {
    n[0][c] = x[0][c];
  }
}

canonical_original_code:
static void copykey(unsigned long (*n)[-1], unsigned long (*x)[-1]) {
  int c;
  for (c = 0; c < (256/64); c++) {
    n[0][c] = x[0][c];
  }
}

variable_types:
n
unsigned long (*)[-1]

variable_types:
x
unsigned long (*)[-1]

variable_types: c int


zeromodp

decompiled_code:
_BOOL8 __fastcall zeromodp(__int64 a1)
{
return (unsigned int)_gmpn_cmp(a1, &zerocmp, 4LL) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return (unsigned int)_gmpn_cmp(a1, &zerocmp, 4LL) == 0;
}

original_code:
static
int zeromodp(curve25519key_t *x) {
  return (__gmpn_cmp((mp_limb_t*)x, (mp_limb_t*)&zerocmp, (256/64)) == 0);
}

canonical_original_code:
static int zeromodp(unsigned long (*x)[-1]) {
  return (__gmpn_cmp((unsigned long *)x, (unsigned long *)&zerocmp, (256/64)) == 0);
}


addmodp

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

_gmpn_add_n(a1, a1, a2, 4LL);
result = _gmpn_cmp(a1, &p25519, 4LL);
if ( (int)result >= 0 )
result = _gmpn_sub_n(a1, a1, &p25519, 4LL);
return result;
}

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

_gmpn_add_n(a1, a1, a2, 4LL);
result = _gmpn_cmp(a1, &p25519, 4LL);
if ( (int)result >= 0 )
result = _gmpn_sub_n(a1, a1, &p25519, 4LL);
return result;
}

canonical_original_code:
static void addmodp(unsigned long (*a)[-1], unsigned long (*b)[-1]) {
  __gmpn_add_n((unsigned long *)a, (unsigned long *)a, (unsigned long *)b, (256/64));
  if (__gmpn_cmp((unsigned long *)a, (unsigned long *)&p25519, (256/64)) >= 0) {
    __gmpn_sub_n((unsigned long *)a, (unsigned long *)a, (unsigned long *)&p25519, (256/64));
  }
}

variable_types:
a
unsigned long (*)[-1]

variable_types:
b
unsigned long (*)[-1]


submodp

decompiled_code:
__int64 __fastcall submodp(__int64 a1, __int64 a2)
{
if ( (int)_gmpn_cmp(a2, a1, 4LL) > 0 )
_gmpn_add_n(a1, &p25519, a1, 4LL);
return _gmpn_sub_n(a1, a1, a2, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
if ( (int)_gmpn_cmp(a2, a1, 4LL) > 0 )
_gmpn_add_n(a1, &p25519, a1, 4LL);
return _gmpn_sub_n(a1, a1, a2, 4LL);
}

original_code:
static
void submodp(curve25519key_t *a, curve25519key_t *b) {
  if (__gmpn_cmp((mp_limb_t*)b, (mp_limb_t*)a, (256/64)) > 0) {
    __gmpn_add_n((mp_limb_t*)a, (mp_limb_t*)&p25519, (mp_limb_t*)a, (256/64));
  }
  __gmpn_sub_n((mp_limb_t*)a, (mp_limb_t*)a, (mp_limb_t*)b, (256/64));
}

canonical_original_code:
static void submodp(unsigned long (*a)[-1], unsigned long (*b)[-1]) {
  if (__gmpn_cmp((unsigned long *)b, (unsigned long *)a, (256/64)) > 0) {
    __gmpn_add_n((unsigned long *)a, (unsigned long *)&p25519, (unsigned long *)a, (256/64));
  }
  __gmpn_sub_n((unsigned long *)a, (unsigned long *)a, (unsigned long *)b, (256/64));
}


sqrmodp

decompiled_code:
__int64 __fastcall sqrmodp(__int64 a1)
{
return mulmodp(a1, a1);
}

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

original_code:
static void
sqrmodp(curve25519key_t *a) {
  mulmodp(a, a);
}

canonical_original_code:
static void sqrmodp(unsigned long (*a)[-1]) {
  mulmodp(a, a);
}


sum

decompiled_code:
__int64 __fastcall sum(_QWORD *a1, _QWORD *a2, _QWORD *a3, __int64 a4, _QWORD *a5, __int64 a6, __int64 a7)
{
__int64 v11; // rcx
_QWORD v13[4]; // [rsp+0h] [rbp-B8h] BYREF
_QWORD v14[4]; // [rsp+20h] [rbp-98h] BYREF
_QWORD v15[4]; // [rsp+40h] [rbp-78h] BYREF
_QWORD v16[11]; // [rsp+60h] [rbp-58h] BYREF

copykey(v15, a3);
submodp((__int64)v15, v11);
copykey(v13, a5);
addmodp((__int64)v13, a6);
mulmodp((__int64)v15, (__int64)v13);
copykey(v16, a3);
addmodp((__int64)v16, a4);
copykey(v14, a5);
submodp((__int64)v14, a6);
mulmodp((__int64)v16, (__int64)v14);
copykey(a1, v15);
addmodp((__int64)a1, (__int64)v16);
sqrmodp((__int64)a1);
copykey(a2, v15);
submodp((__int64)a2, (__int64)v16);
sqrmodp((__int64)a2);
return mulmodp((__int64)a2, a7);
}

original_code:
static
void sum(curve25519key_t *x_3, curve25519key_t *z_3, curve25519key_t *x, curve25519key_t *z, curve25519key_t *x_p, curve25519key_t *z_p, curve25519key_t *x_1) {
  curve25519key_t k, l, p, q;
  copykey(&p, x); submodp(&p, z); copykey(&k, x_p); addmodp(&k, z_p); mulmodp(&p, &k);
  copykey(&q, x); addmodp(&q, z); copykey(&l, x_p); submodp(&l, z_p); mulmodp(&q, &l);
  copykey(x_3, &p); addmodp(x_3, &q); sqrmodp(x_3);
  copykey(z_3, &p); submodp(z_3, &q); sqrmodp(z_3); mulmodp(z_3, x_1);
}

canonical_original_code:
static void sum(unsigned long (*x_3)[-1], unsigned long (*z_3)[-1], unsigned long (*x)[-1], unsigned long (*z)[-1], unsigned long (*x_p)[-1], unsigned long (*z_p)[-1], unsigned long (*x_1)[-1]) {
  unsigned long k[-1]; unsigned long l[-1]; unsigned long p[-1]; unsigned long q[-1];
  copykey(&p, x); submodp(&p, z); copykey(&k, x_p); addmodp(&k, z_p); mulmodp(&p, &k);
  copykey(&q, x); addmodp(&q, z); copykey(&l, x_p); submodp(&l, z_p); mulmodp(&q, &l);
  copykey(x_3, &p); addmodp(x_3, &q); sqrmodp(x_3);
  copykey(z_3, &p); submodp(z_3, &q); sqrmodp(z_3); mulmodp(z_3, x_1);
}

variable_types:
z
unsigned long (*)[-1]

variable_types:
k
unsigned long [-1]

variable_types:
l
unsigned long [-1]

variable_types:
p
unsigned long [-1]

variable_types:
q
unsigned long [-1]


dbl

decompiled_code:
__int64 __fastcall dbl(_QWORD *a1, _QWORD *a2, _QWORD *a3, __int64 a4)
{
__int64 v6; // rcx
_QWORD v8[4]; // [rsp+0h] [rbp-88h] BYREF
_QWORD v9[4]; // [rsp+20h] [rbp-68h] BYREF
_QWORD v10[9]; // [rsp+40h] [rbp-48h] BYREF

copykey(v8, a3);
addmodp((__int64)v8, v6);
sqrmodp((__int64)v8);
copykey(v9, a3);
submodp((__int64)v9, a4);
sqrmodp((__int64)v9);
copykey(v10, v8);
submodp((__int64)v10, (__int64)v9);
copykey(a1, v9);
mulmodp((__int64)a1, (__int64)v8);
copykey(a2, v10);
mulasmall((__int64)a2);
addmodp((__int64)a2, (__int64)v8);
return mulmodp((__int64)a2, (__int64)v10);
}

original_code:
static
void dbl(curve25519key_t *x_2, curve25519key_t *z_2, curve25519key_t *x, curve25519key_t *z) {
  curve25519key_t m, n, o;
  copykey(&m, x); addmodp(&m, z); sqrmodp(&m);
  copykey(&n, x); submodp(&n, z); sqrmodp(&n);
  copykey(&o, &m); submodp(&o, &n);
  copykey(x_2, &n); mulmodp(x_2, &m);
  copykey(z_2, &o); mulasmall(z_2); addmodp(z_2, &m); mulmodp(z_2, &o);
}

canonical_original_code:
static void dbl(unsigned long (*x_2)[-1], unsigned long (*z_2)[-1], unsigned long (*x)[-1], unsigned long (*z)[-1]) {
  unsigned long m[-1]; unsigned long n[-1]; unsigned long o[-1];
  copykey(&m, x); addmodp(&m, z); sqrmodp(&m);
  copykey(&n, x); submodp(&n, z); sqrmodp(&n);
  copykey(&o, &m); submodp(&o, &n);
  copykey(x_2, &n); mulmodp(x_2, &m);
  copykey(z_2, &o); mulasmall(z_2); addmodp(z_2, &m); mulmodp(z_2, &o);
}

variable_types:
m
unsigned long [-1]

variable_types:
n
unsigned long [-1]

variable_types:
o
unsigned long [-1]


invmodp

decompiled_code:
__int64 __fastcall invmodp(_QWORD *a1)
{
int v1; // ebx
_QWORD v3[7]; // [rsp+0h] [rbp-38h] BYREF

v1 = 249;
copykey(v3, a1);
do
{
sqrmodp((__int64)a1);
mulmodp((__int64)a1, (__int64)v3);
--v1;
}
while ( v1 );
sqrmodp((__int64)a1);
sqrmodp((__int64)a1);
mulmodp((__int64)a1, (__int64)v3);
sqrmodp((__int64)a1);
sqrmodp((__int64)a1);
mulmodp((__int64)a1, (__int64)v3);
sqrmodp((__int64)a1);
return mulmodp((__int64)a1, (__int64)v3);
}

original_code:
static void
invmodp(curve25519key_t *a) {
  curve25519key_t c; copykey(&c, a);
  int i = 250;
  while (--i) {
    sqrmodp(a);
    mulmodp(a, &c);
  }
  sqrmodp(a);
  sqrmodp(a); mulmodp(a, &c);
  sqrmodp(a);
  sqrmodp(a); mulmodp(a, &c);
  sqrmodp(a); mulmodp(a, &c);
}

canonical_original_code:
static void invmodp(unsigned long (*a)[-1]) {
  unsigned long c[-1]; copykey(&c, a);
  int i = 250;
  while (--i) {
    sqrmodp(a);
    mulmodp(a, &c);
  }
  sqrmodp(a);
  sqrmodp(a); mulmodp(a, &c);
  sqrmodp(a);
  sqrmodp(a); mulmodp(a, &c);
  sqrmodp(a); mulmodp(a, &c);
}

variable_types:
c
unsigned long [-1]

variable_types: i int


decompiled_code:
__int64 __fastcall curve25519key_getbit(__int64 a1, unsigned int a2)
{
return (*(_QWORD *)(a1 + 8LL * (a2 >> 6)) >> a2) & 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned int a2)
{
return (*(_QWORD *)(a1 + 8LL * (a2 >> 6)) >> a2) & 1LL;
}

original_code:
extern int
curve25519key_getbit(curve25519key_t *x, unsigned int n) {
  unsigned int d = 64;
  return (x[0][n / d] >> (n % d)) & 1;
}

canonical_original_code:
extern int curve25519key_getbit(unsigned long (*x)[-1], unsigned int n) {
  unsigned int d = 64;
  return (x[0][n / d] >> (n % d)) & 1;
}

variable_types:
n
unsigned int

variable_types:
d
unsigned int


decompiled_code:
__int64 __fastcall curve25519key_setbit(__int64 a1, unsigned int a2, int a3)
{
__int64 v4; // rdx
__int64 result; // rax

v4 = a2 >> 6;
result = *(_QWORD *)(a1 + 8 * v4) & ~(1LL << a2);
if ( a3 )
result = (1LL << a2) | *(_QWORD *)(a1 + 8 * v4);
*(_QWORD *)(a1 + 8 * v4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2, int a3)
{
__int64 v4; // rdx
__int64 result; // rax

v4 = a2 >> 6;
result = *(_QWORD *)(a1 + 8 * v4) & ~(1LL << a2);
if ( a3 )
result = (1LL << a2) | *(_QWORD *)(a1 + 8 * v4);
*(_QWORD *)(a1 + 8 * v4) = result;
return result;
}

original_code:
extern void
curve25519key_setbit(curve25519key_t *x, unsigned int n, int v) {
  unsigned int d = 64;
  unsigned int i = n / d;
  mp_limb_t l = x[0][i];
  if (v) {
    l |= ((mp_limb_t)1)<<(n % d);
  } else {
    l &= ~(((mp_limb_t)(1))<<(n % d));
  }
  x[0][i] = l;
}

canonical_original_code:
extern void curve25519key_setbit(unsigned long (*x)[-1], unsigned int n, int v) {
  unsigned int d = 64;
  unsigned int i = n / d;
  unsigned long l = x[0][i];
  if (v) {
    l |= ((unsigned long)1)<<(n % d);
  } else {
    l &= ~(((mp_limb_t)(1))<<(n % d));
  }
  x[0][i] = l;
}

variable_types: v int

variable_types:
i
unsigned int

variable_types:
l
unsigned long


decompiled_code:
__int64 __fastcall curve25519key_getbyte(__int64 a1, int a2)
{
return (unsigned __int8)(*(_QWORD *)(a1 + 8LL * ((unsigned int)(8 * a2) >> 6)) >> ((8 * a2) & 0x3F));
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
return (unsigned __int8)(*(_QWORD *)(a1 + 8LL * ((unsigned int)(8 * a2) >> 6)) >> ((8 * a2) & 0x3F));
}

original_code:
extern unsigned int
curve25519key_getbyte(curve25519key_t *x, unsigned int n) {
  unsigned int d = 64;
  n *= 8;
  return (x[0][n / d] >> (n % d)) & 0xff;
}

canonical_original_code:
extern unsigned int curve25519key_getbyte(unsigned long (*x)[-1], unsigned int n) {
  unsigned int d = 64;
  n *= 8;
  return (x[0][n / d] >> (n % d)) & 0xff;
}

variable_types:
x
unsigned long (*)[-1]


decompiled_code:
__int64 __fastcall curve25519key_setbyte(__int64 a1, int a2, int a3)
{
unsigned int v3; // esi
char v4; // cl
int v5; // eax
__int64 v6; // rsi
__int64 result; // rax

v3 = 8 * a2;
v4 = v3 & 0x3F;
v5 = 255 << (v3 & 0x3F);
v6 = v3 >> 6;
result = (unsigned int)(a3 << v4) | *(_QWORD *)(a1 + 8 * v6) & ~(__int64)v5;
*(_QWORD *)(a1 + 8 * v6) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2, int a3)
{
unsigned int v3; // esi
char v4; // cl
int v5; // eax
__int64 v6; // rsi
__int64 result; // rax

v3 = 8 * a2;
v4 = v3 & 0x3F;
v5 = 255 << (v3 & 0x3F);
v6 = v3 >> 6;
result = (unsigned int)(a3 << v4) | *(_QWORD *)(a1 + 8 * v6) & ~(__int64)v5;
*(_QWORD *)(a1 + 8 * v6) = result;
return result;
}

original_code:
extern void
curve25519key_setbyte(curve25519key_t *x, unsigned int n, unsigned int v) {
  n *= 8;
  {
    unsigned int d = 64;
    unsigned int i = n / d;
    mp_limb_t l = x[0][i];
    l = ~l;
    l |= 0xff << (n % d);
    l = ~l;
    l |= v << (n % d);
    x[0][i] = l;
  }
}

canonical_original_code:
extern void curve25519key_setbyte(unsigned long (*x)[-1], unsigned int n, unsigned int v) {
  n *= 8;
  {
    unsigned int d = 64;
    unsigned int i = n / d;
    unsigned long l = x[0][i];
    l = ~l;
    l |= 0xff << (n % d);
    l = ~l;
    l |= v << (n % d);
    x[0][i] = l;
  }
}

variable_types:
v
unsigned int


decompiled_code:
__int64 __fastcall curve25519key_getuint32(__int64 a1, unsigned int a2)
{
return *(_QWORD *)(a1 + 8LL * (a2 >> 1)) >> (32 * (a2 & 1));
}

original_code:
extern unsigned int
curve25519key_getuint32(curve25519key_t *x, unsigned int n) {
  return (x[0][n>>1] >> ((n&1)*32))&0xffffffff;
}

canonical_original_code:
extern unsigned int curve25519key_getuint32(unsigned long (*x)[-1], unsigned int n) {
  return (x[0][n>>1] >> ((n&1)*32))&0xffffffff;
}


decompiled_code:
unsigned __int64 __fastcall curve25519key_setuint32(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v3; // rcx
__int64 v4; // rax
unsigned __int64 result; // rax

v3 = a2 >> 1;
v4 = *(_QWORD *)(a1 + 8 * v3);
if ( (a2 & 1) != 0 )
result = ((unsigned __int64)a3 << 32) | (unsigned int)v4;
else
result = a3 | v4 & 0xFFFFFFFF00000000LL;
*(_QWORD *)(a1 + 8 * v3) = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func15(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v3; // rcx
__int64 v4; // rax
unsigned __int64 result; // rax

v3 = a2 >> 1;
v4 = *(_QWORD *)(a1 + 8 * v3);
if ( (a2 & 1) != 0 )
result = ((unsigned __int64)a3 << 32) | (unsigned int)v4;
else
result = a3 | v4 & 0xFFFFFFFF00000000LL;
*(_QWORD *)(a1 + 8 * v3) = result;
return result;
}

original_code:
extern void
curve25519key_setuint32(curve25519key_t *x, unsigned int n, unsigned int v) {
  x[0][n>>1] = (n&1)
  ? (x[0][n>>1] & 0xffffffff) | (((mp_limb_t)v)<<32)
  : (x[0][n>>1] & 0xffffffff00000000) | v;
}

canonical_original_code:
extern void curve25519key_setuint32(unsigned long (*x)[-1], unsigned int n, unsigned int v) {
  x[0][n>>1] = (n&1)
  ? (x[0][n>>1] & 0xffffffff) | (((unsigned long)v)<<32)
  : (x[0][n>>1] & 0xffffffff00000000) | v;
}


decompiled_code:
__int64 __fastcall curve25519key_validate(__int64 a1)
{
__int64 result; // rax
void *v2; // rsi
int v3; // eax
bool v4; // zf
int v5; // eax
int v6; // eax

result = _gmpn_cmp(a1, &unk_960, 4LL);
if ( (int)result <= 0 )
{
if ( !(_DWORD)result )
return result;
result = _gmpn_cmp(a1, &unk_900, 4LL);
if ( (int)result <= 0 )
{
if ( (_DWORD)result )
{
v6 = _gmpn_cmp(a1, &unk_8E0, 4LL);
v2 = &unsafe;
if ( v6 >= 0 )
return v6 != 0;
return (unsigned int)_gmpn_cmp(a1, v2, 4LL) != 0;
}
return result;
}
v5 = _gmpn_cmp(a1, &unk_920, 4LL);
v4 = v5 == 0;
if ( v5 > 0 )
{
v2 = &unk_940;
return (unsigned int)_gmpn_cmp(a1, v2, 4LL) != 0;
}
return !v4;
}
result = _gmpn_cmp(a1, &unk_9C0, 4LL);
if ( (int)result <= 0 )
{
if ( !(_DWORD)result )
return result;
v3 = _gmpn_cmp(a1, &unk_980, 4LL);
v4 = v3 == 0;
if ( v3 > 0 )
{
v2 = &unk_9A0;
return (unsigned int)_gmpn_cmp(a1, v2, 4LL) != 0;
}
return !v4;
}
result = _gmpn_cmp(a1, &unk_A00, 4LL);
if ( (int)result > 0 )
{
v2 = &unk_A20;
return (unsigned int)_gmpn_cmp(a1, v2, 4LL) != 0;
}
if ( (_DWORD)result )
{
v2 = &unk_9E0;
return (unsigned int)_gmpn_cmp(a1, v2, 4LL) != 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
__int64 result; // rax
void *v2; // rsi
int v3; // eax
bool v4; // zf
int v5; // eax
int v6; // eax

result = _gmpn_cmp(a1, &unk_960, 4LL);
if ( (int)result <= 0 )
{
if ( !(_DWORD)result )
return result;
result = _gmpn_cmp(a1, &unk_900, 4LL);
if ( (int)result <= 0 )
{
if ( (_DWORD)result )
{
v6 = _gmpn_cmp(a1, &unk_8E0, 4LL);
v2 = &unsafe;
if ( v6 >= 0 )
return v6 != 0;
return (unsigned int)_gmpn_cmp(a1, v2, 4LL) != 0;
}
return result;
}
v5 = _gmpn_cmp(a1, &unk_920, 4LL);
v4 = v5 == 0;
if ( v5 > 0 )
{
v2 = &unk_940;
return (unsigned int)_gmpn_cmp(a1, v2, 4LL) != 0;
}
return !v4;
}
result = _gmpn_cmp(a1, &unk_9C0, 4LL);
if ( (int)result <= 0 )
{
if ( !(_DWORD)result )
return result;
v3 = _gmpn_cmp(a1, &unk_980, 4LL);
v4 = v3 == 0;
if ( v3 > 0 )
{
v2 = &unk_9A0;
return (unsigned int)_gmpn_cmp(a1, v2, 4LL) != 0;
}
return !v4;
}
result = _gmpn_cmp(a1, &unk_A00, 4LL);
if ( (int)result > 0 )
{
v2 = &unk_A20;
return (unsigned int)_gmpn_cmp(a1, v2, 4LL) != 0;
}
if ( (_DWORD)result )
{
v2 = &unk_9E0;
return (unsigned int)_gmpn_cmp(a1, v2, 4LL) != 0;
}
return result;
}

canonical_original_code:
extern int curve25519key_validate(unsigned long (*x)[-1]) {
  int r;
  if ((r = __gmpn_cmp((unsigned long *)(x), (unsigned long *)(unsafe + 5), (256/64))) > 0) {
    if ((r = __gmpn_cmp((unsigned long *)(x), (unsigned long *)(unsafe + 8), (256/64))) > 0) {
      if ((r = __gmpn_cmp((unsigned long *)(x), (unsigned long *)(unsafe + 10), (256/64))) > 0) {
 if (__gmpn_cmp((unsigned long *)(x), (unsigned long *)(unsafe + 11), (256/64)) == 0) {
   return 0;
 }
      } else if (r < 0) {
 if (__gmpn_cmp((unsigned long *)(x), (unsigned long *)(unsafe + 9), (256/64)) == 0) {
   return 0;
 }
      } else {
 return 0;
      }
    } else if (r < 0) {
      if ((r = __gmpn_cmp((unsigned long *)(x), (unsigned long *)(unsafe + 6), (256/64))) > 0) {
 if (__gmpn_cmp((unsigned long *)(x), (unsigned long *)(unsafe + 7), (256/64)) == 0) {
   return 0;
 }
      } else if (r == 0) {
 return 0;
      }
    } else {
      return 0;
    }
  } else if (r < 0) {
    if ((r = __gmpn_cmp((unsigned long *)(x), (unsigned long *)(unsafe + 2), (256/64))) > 0) {
      if ((r = __gmpn_cmp((unsigned long *)(x), (unsigned long *)(unsafe + 3), (256/64))) > 0) {
 if (__gmpn_cmp((unsigned long *)(x), (unsigned long *)(unsafe + 4), (256/64)) == 0) {
   return 0;
 }
      } else if (r == 0) {
 return 0;
      }
    } else if (r < 0) {
      if ((r = __gmpn_cmp((unsigned long *)(x), (unsigned long *)(unsafe + 1), (256/64))) < 0) {
 if (__gmpn_cmp((unsigned long *)(x), (unsigned long *)(unsafe), (256/64)) == 0) {
   return 0;
 }
      } else if (r == 0) {
 return 0;
      }
    } else {
      return 0;
    }
  } else {
    return 0;
  }
  return 1;
}

variable_types: r int


decompiled_code:
__int64 __fastcall curve25519(_QWORD *a1, __int64 a2, _QWORD *a3)
{
signed int v5; // ebx
_QWORD *v6; // rdx
__int64 v7; // rcx
unsigned int v8; // esi
_QWORD v11[4]; // [rsp+0h] [rbp-148h] BYREF
_QWORD v12[4]; // [rsp+20h] [rbp-128h] BYREF
_QWORD v13[4]; // [rsp+40h] [rbp-108h] BYREF
_QWORD v14[4]; // [rsp+60h] [rbp-E8h] BYREF
_QWORD v15[4]; // [rsp+80h] [rbp-C8h] BYREF
_QWORD v16[4]; // [rsp+A0h] [rbp-A8h] BYREF
_QWORD v17[4]; // [rsp+C0h] [rbp-88h] BYREF
_QWORD v18[4]; // [rsp+E0h] [rbp-68h] BYREF
_QWORD v19[9]; // [rsp+100h] [rbp-48h] BYREF

if ( zeromodp(a2) )
return copykey(a1, zerocmp);
v5 = 255;
copykey(v11, a3);
dbl(v12, v13, v6, v7);
copykey(v14, v11);
copykey(v15, onecmp);
do
v8 = v5--;
while ( !(unsigned int)curve25519key_getbit(a2, v8) );
if ( v5 >= 0 )
{
do
{
if ( (unsigned int)curve25519key_getbit(a2, v5) )
{
sum(v16, v17, v12, (__int64)v13, v14, (__int64)v15, (__int64)v11);
dbl(v18, v19, v12, (__int64)v13);
}
else
{
dbl(v16, v17, v14, (__int64)v15);
sum(v18, v19, v12, (__int64)v13, v14, (__int64)v15, (__int64)v11);
}
copykey(v14, v16);
copykey(v15, v17);
copykey(v12, v18);
copykey(v13, v19);
}
while ( v5-- != 0 );
}
invmodp(v15);
mulmodp((__int64)v14, (__int64)v15);
return copykey(a1, v14);
}

original_code:
extern void
curve25519(curve25519key_t *r, curve25519key_t *f, curve25519key_t *c) {
  curve25519key_t x_1, x_a, z_a, x, z;
  if (zeromodp(f)) {
    copykey(r, &zerocmp);
    return;
  }
  copykey(&x_1, c);
  dbl(&x_a, &z_a, &x_1, &onecmp);
  copykey(&x, &x_1);
  copykey(&z, &onecmp);
  int n = 256 -1;
  while (curve25519key_getbit(f, n) == 0) {
    n--;
  }
  n--;
  while (n >= 0) {
    curve25519key_t nx, nz, nx_a, nz_a;
    int b = curve25519key_getbit(f, n);
    if (b == 0) {
      dbl(&nx, &nz, &x, &z);
      sum(&nx_a, &nz_a, &x_a, &z_a, &x, &z, &x_1);
    } else {
      sum(&nx, &nz, &x_a, &z_a, &x, &z, &x_1);
      dbl(&nx_a, &nz_a, &x_a, &z_a);
    }
    copykey(&x, &nx); copykey(&z, &nz); copykey(&x_a, &nx_a); copykey(&z_a, &nz_a);
    n--;
  }
  invmodp(&z);
  mulmodp(&x, &z);
  copykey(r, &x);
}

canonical_original_code:
extern void curve25519(unsigned long (*r)[-1], unsigned long (*f)[-1], unsigned long (*c)[-1]) {
  unsigned long x_1[-1]; unsigned long x_a[-1]; unsigned long z_a[-1]; unsigned long x[-1]; unsigned long z[-1];
  if (zeromodp(f)) {
    copykey(r, &zerocmp);
    return;
  }
  copykey(&x_1, c);
  dbl(&x_a, &z_a, &x_1, &onecmp);
  copykey(&x, &x_1);
  copykey(&z, &onecmp);
  int n = 256 -1;
  while (curve25519key_getbit(f, n) == 0) {
    n--;
  }
  n--;
  while (n >= 0) {
    unsigned long nx[-1]; unsigned long nz[-1]; unsigned long nx_a[-1]; unsigned long nz_a[-1];
    int b = curve25519key_getbit(f, n);
    if (b == 0) {
      dbl(&nx, &nz, &x, &z);
      sum(&nx_a, &nz_a, &x_a, &z_a, &x, &z, &x_1);
    } else {
      sum(&nx, &nz, &x_a, &z_a, &x, &z, &x_1);
      dbl(&nx_a, &nz_a, &x_a, &z_a);
    }
    copykey(&x, &nx); copykey(&z, &nz); copykey(&x_a, &nx_a); copykey(&z_a, &nz_a);
    n--;
  }
  invmodp(&z);
  mulmodp(&x, &z);
  copykey(r, &x);
}

variable_types:
r
unsigned long (*)[-1]

variable_types:
f
unsigned long (*)[-1]

variable_types:
c
unsigned long (*)[-1]

variable_types:
x
unsigned long [-1]

variable_types:
z
unsigned long [-1]

variable_types: n int

variable_types:
nx
unsigned long [-1]

variable_types:
nz
unsigned long [-1]

variable_types: b int