main

original_code:
int main(void)
{
  int kingaku, zeikomi;
  Money mon[] = {
    {"一万円", 10000, 0},
    {"五千円", 5000, 0},
    {"  千円", 1000, 0},
    {"五百円", 500, 0},
    {"  百円", 100, 0},
    {"五十円", 50, 0},
    {"  十円", 10, 0},
    {"  五円", 5, 0},
    {"  一円", 1, 0}
  };
  printf("金額 = "); scanf("%d", &kingaku);
  zeikomi = func1(kingaku, mon);
  printf("税込み金額は%d円です．\n", zeikomi);
  prtMoney(mon);
  return 0;
}

canonical_original_code:
int main()
{
  int kingaku; int zeikomi;
  struct Money mon[] = {
    {"一万円", 10000, 0},
    {"五千円", 5000, 0},
    {"  千円", 1000, 0},
    {"五百円", 500, 0},
    {"  百円", 100, 0},
    {"五十円", 50, 0},
    {"  十円", 10, 0},
    {"  五円", 5, 0},
    {"  一円", 1, 0}
  };
  printf("金額 = "); scanf("%d", &kingaku);
  zeikomi = func1(kingaku, mon);
  printf("税込み金額は%d円です．\n", zeikomi);
  prtMoney(mon);
  return 0;
}

variable_types: zeikomi int


calcSeiseki

repo: koturn/example

original_code:
void calcSeiseki(int n, int m, Person p[])
{
  int i;
  double p_ave = 0.0;
  double s = 0.0;
  for (i = 0; i < n; i++) {
    int j;
    int sum = 0.0;
    for (j = 0; j < m; j++) {
      sum += p[i].points[j];
    }
    p[i].ave = sum / m;
    p_ave += p[i].ave;
    if (p[i].ave < 60) {
      p[i].judge = 'F';
    }
  }
  p_ave /= n;
  for (i = 0; i < n; i++) {
    double tmp = p[i].ave - p_ave;
    s += tmp * tmp;
  }
  s = sqrt(s / n);
  for (i = 0; i < n; i++) {
    p[i].s = 10 * (p[i].ave - p_ave) / s + 50;
  }
}

canonical_original_code:
void calcSeiseki(int n, int m, struct Person p[])
{
  int i;
  double p_ave = 0.0;
  double s = 0.0;
  for (i = 0; i < n; i++) {
    int j;
    int sum = 0.0;
    for (j = 0; j < m; j++) {
      sum += p[i].points[j];
    }
    p[i].ave = sum / m;
    p_ave += p[i].ave;
    if (p[i].ave < 60) {
      p[i].judge = 'F';
    }
  }
  p_ave /= n;
  for (i = 0; i < n; i++) {
    double tmp = p[i].ave - p_ave;
    s += tmp * tmp;
  }
  s = sqrt(s / n);
  for (i = 0; i < n; i++) {
    p[i].s = 10 * (p[i].ave - p_ave) / s + 50;
  }
}

variable_types: n int

variable_types: m int

variable_types: struct Person { char judge; char *name; int points[4]; int ave; double s; } []

variable_types: i int

variable_types: s double

variable_types: j int

variable_types: sum int

variable_types: tmp double

return_type: void


prtSeiseki

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

result = puts(s);
if ( a1 > 0 )
{
v3 = a2;
do
{
result = printf(
"%c %-10s %4d %6.1f\n",
(unsigned int)*(char *)v3,
v3[1],
*((unsigned int *)v3 + 8),
*((double *)v3 + 5));
v3 += 6;
}
while ( v3 != &a2[6 * (unsigned int)(a1 - 1) + 6] );
}
return result;
}

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

result = puts(s);
if ( a1 > 0 )
{
v3 = a2;
do
{
result = printf(
"%c %-10s %4d %6.1f\n",
(unsigned int)*(char *)v3,
v3[1],
*((unsigned int *)v3 + 8),
*((double *)v3 + 5));
v3 += 6;
}
while ( v3 != &a2[6 * (unsigned int)(a1 - 1) + 6] );
}
return result;
}

original_code:
void prtSeiseki(int n, Person p[])
{
  int i;
  printf("  名前        成績 偏差値\n");
  for (i = 0; i < n; i++) {
    printf("%c %-10s %4d %6.1f\n", p[i].judge, p[i].name, p[i].ave, p[i].s);
  }
}

canonical_original_code:
void prtSeiseki(int n, struct Person p[])
{
  int i;
  printf("  名前        成績 偏差値\n");
  for (i = 0; i < n; i++) {
    printf("%c %-10s %4d %6.1f\n", p[i].judge, p[i].name, p[i].ave, p[i].s);
  }
}

user_defined_types: struct Person { char judge; char *name; int points[4]; int ave; double s; }


sort

original_code:
void sort(int n, Person p[])
{
  int i;
  for (i = 0; i < n - 1; i++) {
    int j;
    for (j = i + 1; j < n; j++) {
      if (p[i].ave < p[j].ave) {
        Person tmp = p[i];
        p[i] = p[j];
        p[j] = tmp;
      }
    }
  }
}

canonical_original_code:
void sort(int n, struct Person p[])
{
  int i;
  for (i = 0; i < n - 1; i++) {
    int j;
    for (j = i + 1; j < n; j++) {
      if (p[i].ave < p[j].ave) {
        struct Person tmp = p[i];
        p[i] = p[j];
        p[j] = tmp;
      }
    }
  }
}

variable_types: struct Person { char judge; char *name; int points[4]; int ave; double s; }


main

canonical_name: main

return_type: int


prtMat

decompiled_code:
int __fastcall prtMat(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // r13
double *v5; // rbx
int result; // eax

if ( a2 > 0 )
{
v2 = (unsigned int)(a2 - 1);
v3 = a1 + 8 * v2 + 8;
v4 = a1 + 88 * v2 + 88;
do
{
v5 = (double *)(-8LL * (unsigned int)a2 + v3);
do
printf(" %3.1f", *v5++);
while ( v5 != (double *)v3 );
result = putchar(10);
v3 += 80LL;
}
while ( v3 != v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // r13
double *v5; // rbx
int result; // eax

if ( a2 > 0 )
{
v2 = (unsigned int)(a2 - 1);
v3 = a1 + 8 * v2 + 8;
v4 = a1 + 88 * v2 + 88;
do
{
v5 = (double *)(-8LL * (unsigned int)a2 + v3);
do
printf(" %3.1f", *v5++);
while ( v5 != (double *)v3 );
result = putchar(10);
v3 += 80LL;
}
while ( v3 != v4 );
}
return result;
}

original_code:
void prtMat(double a[10][10], int n)
{
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      printf(" %3.1f", a[i][j]);
    }
    printf("\n");
  }
}

canonical_original_code:
void prtMat(double a[10][10], int n)
{
  int i; int j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      printf(" %3.1f", a[i][j]);
    }
    printf("\n");
  }
}


copyMat

canonical_original_code:
void copyMat(double a[10][10], double b[10][10], int n)
{
  int i; int j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      b[i][j] = a[i][j];
    }
  }
}


aPow

decompiled_code:
void __fastcall aPow(int a1, double *a2, double *a3, int a4)
{
int v4; // ebx
double v7[105]; // [rsp+0h] [rbp-348h] BYREF

if ( a1 < 0 )
{
puts("aPow: Error!");
}
else
{
v4 = a1;
if ( a1 )
{
copyMat((__int64)a2, (__int64)a3, a4);
if ( a1 > 1 )
{
do
{
prod(a2, a3, v7, a4);
copyMat((__int64)v7, (__int64)a3, a4);
--v4;
}
while ( v4 != 1 );
}
}
else
{
unitMat((__int64)a3, a4);
}
}
}

original_code:
void aPow(int p, double a[10][10], double x[10][10], int n)
{
  double b[10][10];
  if (p < 0) {
    printf("aPow: Error!\n");
  } else if (p == 0) {
    unitMat(x, n);
  } else {
    copyMat(a, x, n);
    while (p > 1) {
      prod(a, x, b, n);
      copyMat(b, x, n);
      p--;
    }
  }
}

variable_types: p int


getCircle

variable_types: struct Circle { double r; double x0; double y0; double area; } []


prtCircle

decompiled_code:
int __fastcall prtCircle(int a1, double *a2)
{
int result; // eax
int v4; // ebp

result = puts(s);
if ( a1 > 0 )
{
v4 = 0;
do
{
result = printf("%3d:%5.1f (%5.1f, %5.1f) %6.1f\n", (unsigned int)++v4, *a2, a2[1], a2[2], a2[3]);
a2 += 4;
}
while ( v4 != a1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1, double *a2)
{
int result; // eax
int v4; // ebp

result = puts(s);
if ( a1 > 0 )
{
v4 = 0;
do
{
result = printf("%3d:%5.1f (%5.1f, %5.1f) %6.1f\n", (unsigned int)++v4, *a2, a2[1], a2[2], a2[3]);
a2 += 4;
}
while ( v4 != a1 );
}
return result;
}

canonical_original_code:
void prtCircle(int n, struct Circle c[])
{
  int i;
  printf(" no:    r (   x0,    y0)   面積\n");
  for (i = 0; i < n; i++) {
    printf("%3d:%5.1f (%5.1f, %5.1f) %6.1f\n", i + 1, c[i].r, c[i].x0, c[i].y0, c[i].area);
  }
}

user_defined_types: struct Circle { double r; double x0; double y0; double area; }


sort

original_code:
void sort(int n, Circle c[])
{
  int i, j;
  Circle tmp;
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (c[i].area < c[j].area) {
        tmp = c[j];
        c[j] = c[i];
        c[i] = tmp;
      }
    }
  }
}

canonical_original_code:
void sort(int n, struct Circle c[])
{
  int i; int j;
  struct Circle tmp;
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (c[i].area < c[j].area) {
        tmp = c[j];
        c[j] = c[i];
        c[i] = tmp;
      }
    }
  }
}

variable_types: struct Circle { double r; double x0; double y0; double area; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v4[401]; // [rsp+0h] [rbp-C98h] BYREF
int v5; // [rsp+C88h] [rbp-10h] BYREF
unsigned int seed[3]; // [rsp+C8Ch] [rbp-Ch] BYREF

printf(&byte_290, argv, envp);
_isoc99_scanf(&unk_29E, seed);
srand(seed[0]);
printf(&byte_2A1);
_isoc99_scanf(&unk_29E, &v5);
getCircle(v5, v4);
sort(v5, (__int64)v4);
prtCircle(v5, v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v4[401]; // [rsp+0h] [rbp-C98h] BYREF
int v5; // [rsp+C88h] [rbp-10h] BYREF
unsigned int seed[3]; // [rsp+C8Ch] [rbp-Ch] BYREF

printf(&byte_290, argv, envp);
_isoc99_scanf(&unk_29E, seed);
srand(seed[0]);
printf(&byte_2A1);
_isoc99_scanf(&unk_29E, &v5);
func0(v5, v4);
func2(v5, (__int64)v4);
func1(v5, v4);
return 0;
}

original_code:
int main(void)
{
  int seed, n;
  Circle c[100];
  printf("乱数seed : ");
  scanf("%d", &seed);
  srand(seed);
  printf("円の個数 : ");
  scanf("%d", &n);
  getCircle(n, c);
  sort(n, c);
  prtCircle(n, c);
  return 0;
}

canonical_original_code:
int main()
{
  int seed; int n;
  struct Circle c[100];
  printf("乱数seed : ");
  scanf("%d", &seed);
  srand(seed);
  printf("円の個数 : ");
  scanf("%d", &n);
  getCircle(n, c);
  sort(n, c);
  prtCircle(n, c);
  return 0;
}

variable_types: seed int

variable_types: struct Circle { double r; double x0; double y0; double area; } [100]


decompiled_code:
__int64 __fastcall f1(int a1, int a2)
{
int v2; // esi
int v3; // edx

if ( a2 > 1 )
{
v2 = a2 - 1;
v3 = 0;
do
{
a1 /= 10;
++v3;
}
while ( v3 != v2 );
}
return (unsigned int)(a1 % 10);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
int v2; // esi
int v3; // edx

if ( a2 > 1 )
{
v2 = a2 - 1;
v3 = 0;
do
{
a1 /= 10;
++v3;
}
while ( v3 != v2 );
}
return (unsigned int)(a1 % 10);
}

original_code:
int f1(int n, int m)
{
  int i;
  for (i = 0; i < m - 1; i++) {
    n /= 10;
  }
  return n % 10;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // er12
unsigned int j; // ebx
unsigned int v5; // ebp
unsigned int v6; // er13

for ( i = 10; i != 100; ++i )
{
for ( j = 10; j != 100; ++j )
{
v5 = 10 * i * f1(j, 2);
if ( (unsigned int)f1(v5, 3) == 4 )
{
v6 = i * f1(j, 1);
if ( (unsigned int)f1(v6 + v5, 3) == 3 )
{
printf(" %d\n", i);
printf(" x%d\n", j);
puts(" ---");
printf(" %d\n", v6);
printf("%d\n", v5);
puts("----");
printf("%d\n", v6 + v5);
}
}
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // er12
unsigned int j; // ebx
unsigned int v5; // ebp
unsigned int v6; // er13

for ( i = 10; i != 100; ++i )
{
for ( j = 10; j != 100; ++j )
{
v5 = 10 * i * func0(j, 2);
if ( (unsigned int)func0(v5, 3) == 4 )
{
v6 = i * func0(j, 1);
if ( (unsigned int)func0(v6 + v5, 3) == 3 )
{
printf(" %d\n", i);
printf(" x%d\n", j);
puts(" ---");
printf(" %d\n", v6);
printf("%d\n", v5);
puts("----");
printf("%d\n", v6 + v5);
}
}
}
}
return 0;
}

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: d int

variable_types: e int


distance

decompiled_code:
double __fastcall distance(double *a1, double *a2)
{
double v2; // xmm0_8
double result; // xmm0_8

v2 = (a1[1] - a2[1]) * (a1[1] - a2[1]) + (*a1 - *a2) * (*a1 - *a2);
if ( v2 < 0.0 )
result = sqrt(v2);
else
result = sqrt(v2);
return result;
}

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

v2 = (a1[1] - a2[1]) * (a1[1] - a2[1]) + (*a1 - *a2) * (*a1 - *a2);
if ( v2 < 0.0 )
result = sqrt(v2);
else
result = sqrt(v2);
return result;
}

return_type: double


inputlength

original_code:
Triangle inputlength(Triangle t) {
  Triangle ret_t;
  ret_t.line1 = distance(t.p1, t.p2);
  ret_t.line2 = distance(t.p2, t.p3);
  ret_t.line3 = distance(t.p3, t.p1);
  return ret_t;
}

canonical_original_code:
struct Triangle inputlength(struct Triangle t) {
  struct Triangle ret_t;
  ret_t.line1 = distance(t.p1, t.p2);
  ret_t.line2 = distance(t.p2, t.p3);
  ret_t.line3 = distance(t.p3, t.p1);
  return ret_t;
}

variable_types:
t
struct Triangle

variable_types: struct Triangle { double p1[2]; double line1; }


main

original_code:
int main(void)
{
  Triangle tri;
  printf("3点を入力してください\n");
  printf("点1(x, y) "); scanf("%lf,%lf", &tri.p1[0], &tri.p1[1]);
  printf("点2(x, y) "); scanf("%lf,%lf", &tri.p2[0], &tri.p2[1]);
  printf("点3(x, y) "); scanf("%lf,%lf", &tri.p3[0], &tri.p3[1]);
  tri = inputlength(tri);
  printf("辺の長さは%.2f, %.2f, %.2f です\n", tri.line1, tri.line2, tri.line3);
  return 0;
}

canonical_original_code:
int main()
{
  struct Triangle tri;
  printf("3点を入力してください\n");
  printf("点1(x, y) "); scanf("%lf,%lf", &tri.p1[0], &tri.p1[1]);
  printf("点2(x, y) "); scanf("%lf,%lf", &tri.p2[0], &tri.p2[1]);
  printf("点3(x, y) "); scanf("%lf,%lf", &tri.p3[0], &tri.p3[1]);
  tri = inputlength(tri);
  printf("辺の長さは%.2f, %.2f, %.2f です\n", tri.line1, tri.line2, tri.line3);
  return 0;
}

user_defined_types: struct Triangle { double p1[2]; double line1; }


sindata

decompiled_code:
void __fastcall sindata(int a1, __int64 a2, float a3, float a4, float a5)
{
__int64 i; // rbx
float v6; // xmm0_4
double v7; // [rsp+0h] [rbp-30h]

if ( a1 > 0 )
{
v7 = a3 * 6.2831853;
for ( i = 0LL; i != a1; *(float *)(a2 + 4 * i++) = v6 )
v6 = sin((double)(int)i * v7 * a4) * a5;
}
}

canonical_decompiled_code:
void __fastcall func0(int a1, __int64 a2, float a3, float a4, float a5)
{
__int64 i; // rbx
float v6; // xmm0_4
double v7; // [rsp+0h] [rbp-30h]

if ( a1 > 0 )
{
v7 = a3 * 6.2831853;
for ( i = 0LL; i != a1; *(float *)(a2 + 4 * i++) = v6 )
v6 = sin((double)(int)i * v7 * a4) * a5;
}
}

original_code:
void sindata(int len, float freq, float tdel, float amp, float *x)
{
  int i;
  for (i = 0; i < len; i++) {
    x[i] = amp * sin(2 * 3.14159265 * freq * i * tdel);
  }
}

variable_types: len int

variable_types: freq float

variable_types: tdel float

variable_types: amp float

variable_types:
x
float *

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rbx
float v5[5002]; // [rsp+0h] [rbp-4E28h] BYREF

sindata(1000, (__int64)v5, 100.0, 0.000049999999, 5.0);
for ( i = 0LL; i != 1000; ++i )
printf("x[%4d] = %f\n", (unsigned int)i, v5[i]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rbx
float v5[5002]; // [rsp+0h] [rbp-4E28h] BYREF

func0(1000, (__int64)v5, 100.0, 0.000049999999, 5.0);
for ( i = 0LL; i != 1000; ++i )
printf("x[%4d] = %f\n", (unsigned int)i, v5[i]);
return 0;
}

original_code:
int main(void)
{
  float x[5000], tdel = 5e-5, freq = 100, amp = 5;
  int len = 1000;
  int i;
  sindata(len, freq, tdel, amp, x);
  for (i = 0; i < len; i++) {
    printf("x[%4d] = %f\n", i, x[i]);
  }
  return 0;
}

canonical_original_code:
int main()
{
  float x[5000]; float tdel = 5e-5; float freq = 100; float amp = 5;
  int len = 1000;
  int i;
  sindata(len, freq, tdel, amp, x);
  for (i = 0; i < len; i++) {
    printf("x[%4d] = %f\n", i, x[i]);
  }
  return 0;
}

variable_types:
x
float [5000]


change

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

if ( a2 <= 0 )
return 0xFFFFFFFFLL;
result = (unsigned int)(a2 + 1988);
if ( a1 != 72 )
{
if ( a1 == 83 )
{
if ( a2 > 64 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(a2 + 1925);
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

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

if ( a2 <= 0 )
return 0xFFFFFFFFLL;
result = (unsigned int)(a2 + 1988);
if ( a1 != 72 )
{
if ( a1 == 83 )
{
if ( a2 > 64 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(a2 + 1925);
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int change(char g, int y)
{
  int year = -1;
  if (y >= 1) {
    switch (g) {
      case 'H':
        year = 1989 + y - 1;
        break;
      case 'S':
        if (y <= 64) {
          year = 1926 + y - 1;
        }
        break;
    }
  }
  return year;
}

variable_types: g char

variable_types: y int

variable_types: year int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // eax
unsigned int v7; // [rsp+8h] [rbp-20h] BYREF
char v8[25]; // [rsp+Fh] [rbp-19h] BYREF

printf("Input the era name (H/S) and year: ");
_isoc99_scanf("%c%d", v8, &v7);
v3 = v7;
v4 = v8[0];
v5 = change(v8[0], v7);
if ( v5 == -1 )
puts("Out of Range");
else
printf("%c %d = %d\n", v4, v3, v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // eax
unsigned int v7; // [rsp+8h] [rbp-20h] BYREF
char v8[25]; // [rsp+Fh] [rbp-19h] BYREF

printf("Input the era name (H/S) and year: ");
_isoc99_scanf("%c%d", v8, &v7);
v3 = v7;
v4 = v8[0];
v5 = func0(v8[0], v7);
if ( v5 == -1 )
puts("Out of Range");
else
printf("%c %d = %d\n", v4, v3, v5);
return 0;
}

original_code:
int main(void)
{
  char g;
  int y1, y2;
  printf("Input the era name (H/S) and year: ");
  scanf("%c%d", &g, &y1);
  y2 = change(g, y1);
  if (y2 != -1) {
    printf("%c %d = %d\n", g, y1, y2);
  } else {
    printf("Out of Range\n");
  }
  return 0;
}

canonical_original_code:
int main()
{
  char g;
  int y1; int y2;
  printf("Input the era name (H/S) and year: ");
  scanf("%c%d", &g, &y1);
  y2 = change(g, y1);
  if (y2 != -1) {
    printf("%c %d = %d\n", g, y1, y2);
  } else {
    printf("Out of Range\n");
  }
  return 0;
}


calc

original_code:
void calc(int m, int n, int p, unsigned char Im[5][10], FEATURE *f)
{
  int i, x, y, a;
  double cx, cy;
  for (i = 1; i <= p; i++) {
    cx = 0, cy = 0, a = 0;
    for (y = 0; y < n; y++) {
      for (x = 0; x < m; x++) {
        if (i == Im[x][y]) {
          a++;
          cx += x;
          cy += y;
        }
      }
    }
    f[i].area = a;
    if (a != 0) {
      f[i].cx = cx / a;
      f[i].cy = cy / a;
    }
  }
}

canonical_original_code:
void calc(int m, int n, int p, unsigned char Im[5][10], struct FEATURE *f)
{
  int i; int x; int y; int a;
  double cx; double cy;
  for (i = 1; i <= p; i++) {
    cx = 0, cy = 0, a = 0;
    for (y = 0; y < n; y++) {
      for (x = 0; x < m; x++) {
        if (i == Im[x][y]) {
          a++;
          cx += x;
          cy += y;
        }
      }
    }
    f[i].area = a;
    if (a != 0) {
      f[i].cx = cx / a;
      f[i].cy = cy / a;
    }
  }
}

variable_types: m int

variable_types: n int

variable_types: p int

variable_types:
Im
unsigned char [5][10]

variable_types: struct FEATURE { int area; double cx; } *

variable_types: x int

variable_types: a int

variable_types: cx double

variable_types: cy double


prtFeature

decompiled_code:
int __fastcall prtFeature(int a1, __int64 a2)
{
double *v2; // rbx
int i; // ebp
__int64 v4; // rdx
int result; // eax

if ( a1 > 0 )
{
v2 = (double *)(a2 + 24);
for ( i = 1; i <= a1; ++i )
{
v4 = *(unsigned int *)v2;
if ( (_DWORD)v4 )
result = printf("%2d: %2d : (%.1f, %.1f)\n", (unsigned int)i, v4, v2[2], v2[1]);
v2 += 3;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1, __int64 a2)
{
double *v2; // rbx
int i; // ebp
__int64 v4; // rdx
int result; // eax

if ( a1 > 0 )
{
v2 = (double *)(a2 + 24);
for ( i = 1; i <= a1; ++i )
{
v4 = *(unsigned int *)v2;
if ( (_DWORD)v4 )
result = printf("%2d: %2d : (%.1f, %.1f)\n", (unsigned int)i, v4, v2[2], v2[1]);
v2 += 3;
}
}
return result;
}

original_code:
void prtFeature(int n, FEATURE *f)
{
  int i;
  for (i = 1; i <= n; i++) {
    if (f[i].area != 0) {
      printf("%2d:  %2d : (%.1f, %.1f)\n", i, f[i].area, f[i].cy, f[i].cx);
    }
  }
}

canonical_original_code:
void prtFeature(int n, struct FEATURE *f)
{
  int i;
  for (i = 1; i <= n; i++) {
    if (f[i].area != 0) {
      printf("%2d:  %2d : (%.1f, %.1f)\n", i, f[i].area, f[i].cy, f[i].cx);
    }
  }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[248]; // [rsp+0h] [rbp-F8h] BYREF

calc(5, 10, 4, (__int64)&Im, (__int64)v4);
prtFeature(4, (__int64)v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[248]; // [rsp+0h] [rbp-F8h] BYREF

func0(5, 10, 4, (__int64)&Im, (__int64)v4);
func1(4, (__int64)v4);
return 0;
}

original_code:
int main(void)
{
  FEATURE fea[10];
  calc(5, 10, 4, Im, fea);
  prtFeature(4, fea);
  return 0;
}

canonical_original_code:
int main()
{
  struct FEATURE fea[10];
  calc(5, 10, 4, Im, fea);
  prtFeature(4, fea);
  return 0;
}

variable_types: struct FEATURE { int area; double cx; } [10]


original_code:
int median_value(int d[], int num)
{
  int i, j, tmp;
  for (i = 0; i < num - 1; i++) {
    for (j = i + 1; j < num; j++) {
      if (d[i] > d[j]) {
        tmp = d[i];
        d[i] = d[j];
        d[j] = tmp;
      }
    }
  }
  return d[num / 2];
}

canonical_original_code:
int median_value(int d[], int num)
{
  int i; int j; int tmp;
  for (i = 0; i < num - 1; i++) {
    for (j = i + 1; j < num; j++) {
      if (d[i] > d[j]) {
        tmp = d[i];
        d[i] = d[j];
        d[j] = tmp;
      }
    }
  }
  return d[num / 2];
}

variable_types:
d
int []

variable_types: num int

variable_types: j int

variable_types: tmp int


median

variable_types: i int


prtData

decompiled_code:
int __fastcall prtData(__int64 a1)
{
unsigned int *v1; // rbp
unsigned int *v2; // rbx
int result; // eax

v1 = (unsigned int *)(a1 + 48);
do
{
v2 = v1 - 12;
do
printf(" %2d", *v2++);
while ( v2 != v1 );
result = puts(&s);
v1 += 12;
}
while ( v1 != (unsigned int *)(a1 + 336) );
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
unsigned int *v1; // rbp
unsigned int *v2; // rbx
int result; // eax

v1 = (unsigned int *)(a1 + 48);
do
{
v2 = v1 - 12;
do
printf(" %2d", *v2++);
while ( v2 != v1 );
result = puts(&s);
v1 += 12;
}
while ( v1 != (unsigned int *)(a1 + 336) );
return result;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char *v4; // rcx
int v5; // ebp
int *v6; // rdx
double v8; // [rsp+8h] [rbp-260h]
char v9[288]; // [rsp+10h] [rbp-258h] BYREF
int v10[12]; // [rsp+130h] [rbp-138h] BYREF
char v11; // [rsp+160h] [rbp-108h] BYREF
char v12; // [rsp+280h] [rbp+18h] BYREF

makeData((__int64)v10);
puts(&byte_3DA);
prtData((__int64)v10);
v3 = v10[0];
v4 = &v11;
v5 = v10[0];
v8 = 0.0;
do
{
v6 = (int *)(v4 - 48);
do
{
v8 = (double)*v6 + v8;
if ( v3 > *v6 )
v3 = *v6;
if ( v5 < *v6 )
v5 = *v6;
++v6;
}
while ( v6 != (int *)v4 );
v4 += 48;
}
while ( v4 != &v12 );
puts(asc_3EA);
printf("%4d|%4d|%4.1f\n", (unsigned int)v3, (unsigned int)v5, v8 / 72.0);
median((__int64)v10, (__int64)v9, 5);
printf(aDxD, 5LL, 5LL);
prtData((__int64)v9);
return 0;
}

original_code:
int main(void)
{
  int in[6][12], out[6][12];
  int m = 5, min, max, i, j;
  double ave;
  makeData(in);
  printf("入力データ\n");
  prtData(in);
  min = max = in[0][0];
  ave = 0;
  for (i = 0; i < 6; i++) {
    for (j = 0; j < 12; j++) {
      ave += in[i][j];
      if (min > in[i][j]) min = in[i][j];
      if (max < in[i][j]) max = in[i][j];
    }
  }
  printf("\n最小|最大|平均\n");
  printf("%4d|%4d|%4.1f\n", min, max, ave / (6 * 12));
  median(in, out, m);
  printf("\n%dx%dメディアンフィルタ\n", m, m);
  prtData(out);
  return 0;
}

canonical_original_code:
int main()
{
  int in[6][12]; int out[6][12];
  int m = 5; int min; int max; int i; int j;
  double ave;
  makeData(in);
  printf("入力データ\n");
  prtData(in);
  min = max = in[0][0];
  ave = 0;
  for (i = 0; i < 6; i++) {
    for (j = 0; j < 12; j++) {
      ave += in[i][j];
      if (min > in[i][j]) min = in[i][j];
      if (max < in[i][j]) max = in[i][j];
    }
  }
  printf("\n最小|最大|平均\n");
  printf("%4d|%4d|%4.1f\n", min, max, ave / (6 * 12));
  median(in, out, m);
  printf("\n%dx%dメディアンフィルタ\n", m, m);
  prtData(out);
  return 0;
}

variable_types: min int

variable_types: max int

variable_types: ave double


inputData

decompiled_code:
__int64 __fastcall inputData(__int64 a1)
{
__int64 result; // rax
unsigned int v3; // ebx
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

printf(&format);
_isoc99_scanf(&unk_23F, v4);
result = v4[0];
if ( (int)v4[0] > 0 )
{
v3 = 0;
do
{
printf(&byte_242, v3);
_isoc99_scanf(&unk_253, a1);
++v3;
result = v4[0];
a1 += 8LL;
}
while ( (int)v4[0] > (int)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
unsigned int v3; // ebx
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

printf(&format);
_isoc99_scanf(&unk_23F, v4);
result = v4[0];
if ( (int)v4[0] > 0 )
{
v3 = 0;
do
{
printf(&byte_242, v3);
_isoc99_scanf(&unk_253, a1);
++v3;
result = v4[0];
a1 += 8LL;
}
while ( (int)v4[0] > (int)v3 );
}
return result;
}

original_code:
int inputData(double x[])
{
  int i, n;
  printf("データ数: ");
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    printf("データ数%d: ", i);
    scanf("%lf", &x[i]);
  }
  return n;
}

canonical_original_code:
int inputData(double x[])
{
  int i; int n;
  printf("データ数: ");
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    printf("データ数%d: ", i);
    scanf("%lf", &x[i]);
  }
  return n;
}

variable_types:
x
double []

variable_types: n int


dft

variable_types: struct Complex { double rl; double im; } []

variable_types: k int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
__int64 i; // rbx
__int64 v6[200]; // [rsp+0h] [rbp-978h] BYREF
char v7[824]; // [rsp+640h] [rbp-338h] BYREF

v3 = inputData((__int64)v7);
dft(v3, (__int64)v7, (double *)v6);
puts("| k| f.rl| f.im|");
if ( v3 > 0 )
{
for ( i = 0LL; i != v3; ++i )
printf("|%2d|%5.1f|%5.1f|\n", (unsigned int)i, *(double *)&v6[2 * i], *(double *)&v6[2 * i + 1]);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
__int64 i; // rbx
__int64 v6[200]; // [rsp+0h] [rbp-978h] BYREF
char v7[824]; // [rsp+640h] [rbp-338h] BYREF

v3 = func0((__int64)v7);
func1(v3, (__int64)v7, (double *)v6);
puts("| k| f.rl| f.im|");
if ( v3 > 0 )
{
for ( i = 0LL; i != v3; ++i )
printf("|%2d|%5.1f|%5.1f|\n", (unsigned int)i, *(double *)&v6[2 * i], *(double *)&v6[2 * i + 1]);
}
return 0;
}

original_code:
int main(void)
{
  int k, n;
  double x[100];
  Complex f[100];
  n = inputData(x);
  dft(n, x, f);
  printf("| k| f.rl| f.im|\n");
  for (k = 0; k < n; k++) {
    printf("|%2d|%5.1f|%5.1f|\n", k, f[k].rl, f[k].im);
  }
  return 0;
}

canonical_original_code:
int main()
{
  int k; int n;
  double x[100];
  struct Complex f[100];
  n = inputData(x);
  dft(n, x, f);
  printf("| k| f.rl| f.im|\n");
  for (k = 0; k < n; k++) {
    printf("|%2d|%5.1f|%5.1f|\n", k, f[k].rl, f[k].im);
  }
  return 0;
}

variable_types:
x
double [100]

variable_types: struct Complex { double rl; double im; } [100]


capital

decompiled_code:
int __fastcall capital(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
int v3; // er12
int v4; // edi

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = 1;
do
{
if ( v1 == 32 )
{
v4 = 32;
v3 = 1;
}
else
{
v4 = v1;
if ( v3 )
{
v4 = (*_ctype_toupper_loc())[v1];
v3 = 0;
}
}
putchar(v4);
v1 = *++v2;
}
while ( *v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
int v3; // er12
int v4; // edi

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = 1;
do
{
if ( v1 == 32 )
{
v4 = 32;
v3 = 1;
}
else
{
v4 = v1;
if ( v3 )
{
v4 = (*_ctype_toupper_loc())[v1];
v3 = 0;
}
}
putchar(v4);
v1 = *++v2;
}
while ( *v2 );
}
return putchar(10);
}

original_code:
void capital(char *st)
{
  int is_top = 1;
  int ch;
  for (; *st != '\0'; st++) {
    if (*st == ' ') {
      ch = ' ';
      is_top = 1;
    } else if (is_top) {
      ch = toupper(*st);
      is_top = 0;
    } else {
      ch = *st;
      is_top = 0;
    }
    putchar(ch);
  }
  putchar('\n');
}

variable_types:
st
char *

variable_types: ch int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[24]; // [rsp+0h] [rbp-48h] BYREF
int v5; // [rsp+18h] [rbp-30h]
__int16 v6; // [rsp+1Ch] [rbp-2Ch]
_WORD v7[21]; // [rsp+1Eh] [rbp-2Ah] BYREF

strcpy(v4, "doshisha university");
v5 = 0;
v6 = 0;
strcpy((char *)v7, "kyotanabe, 610-0321 japan");
v7[14] = 0;
capital(v4);
capital(v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[24]; // [rsp+0h] [rbp-48h] BYREF
int v5; // [rsp+18h] [rbp-30h]
__int16 v6; // [rsp+1Ch] [rbp-2Ch]
_WORD v7[21]; // [rsp+1Eh] [rbp-2Ah] BYREF

strcpy(v4, "doshisha university");
v5 = 0;
v6 = 0;
strcpy((char *)v7, "kyotanabe, 610-0321 japan");
v7[14] = 0;
func0(v4);
func0(v7);
return 0;
}

original_code:
int main(void) {
    char str[2][30] = {
      "doshisha university",
      "kyotanabe, 610-0321 japan"
    };
    int i;
    for (i = 0; i < 2; i++) {
      capital(str[i]);
    }
    return 0;
}

canonical_original_code:
int main() {
    char str[2][30] = {
      "doshisha university",
      "kyotanabe, 610-0321 japan"
    };
    int i;
    for (i = 0; i < 2; i++) {
      capital(str[i]);
    }
    return 0;
}

variable_types:
str
char [2][30]


inputData

decompiled_code:
__int64 __fastcall inputData(__int64 a1)
{
FILE *v1; // rax
FILE *v2; // rbp
__int64 i; // rbx
unsigned int v4; // er13
int v6; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = fopen("input.txt", "r");
if ( !v1 )
return (unsigned int)-1;
v2 = v1;
for ( i = 0LL; ; ++i )
{
v4 = i;
if ( (unsigned int)_isoc99_fscanf(v2, "%d", &v6) == -1 )
break;
*(_DWORD *)(a1 + 4 * i) = v6;
}
fclose(v2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
FILE *v1; // rax
FILE *v2; // rbp
__int64 i; // rbx
unsigned int v4; // er13
int v6; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = fopen("input.txt", "r");
if ( !v1 )
return (unsigned int)-1;
v2 = v1;
for ( i = 0LL; ; ++i )
{
v4 = i;
if ( (unsigned int)_isoc99_fscanf(v2, "%d", &v6) == -1 )
break;
*(_DWORD *)(a1 + 4 * i) = v6;
}
fclose(v2);
return v4;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx

v3 = (unsigned int)inputData((__int64)data);
printf(&byte_1160, v3);
sort(v3, (__int64)data);
outputData(v3, data);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx

v3 = (unsigned int)func0((__int64)data);
printf(&byte_1160, v3);
func1(v3, (__int64)data);
func2(v3, data);
return 0;
}

user_defined_types: struct Complex { double rl; double im; }


decompiled_code:
int *__fastcall func1(int a1, __int64 a2, _DWORD *a3, _DWORD *a4, double *a5)
{
int *result; // rax
double v9; // xmm0_8

sort(a1, a2);
*a3 = *(_DWORD *)(a2 + 36);
result = (int *)*(unsigned int *)(a2 + 40LL * a1 - 4);
*a4 = (_DWORD)result;
v9 = (double)*(int *)(a2 + 36);
if ( a1 > 1 )
{
result = (int *)(a2 + 76);
do
{
v9 = v9 + (double)*result;
result += 10;
}
while ( result != (int *)(a2 + 40LL * (unsigned int)(a1 - 2) + 116) );
}
*a5 = v9 / (double)a1;
return result;
}

canonical_decompiled_code:
int *__fastcall func0(int a1, __int64 a2, _DWORD *a3, _DWORD *a4, double *a5)
{
int *result; // rax
double v9; // xmm0_8

sort(a1, a2);
*a3 = *(_DWORD *)(a2 + 36);
result = (int *)*(unsigned int *)(a2 + 40LL * a1 - 4);
*a4 = (_DWORD)result;
v9 = (double)*(int *)(a2 + 36);
if ( a1 > 1 )
{
result = (int *)(a2 + 76);
do
{
v9 = v9 + (double)*result;
result += 10;
}
while ( result != (int *)(a2 + 40LL * (unsigned int)(a1 - 2) + 116) );
}
*a5 = v9 / (double)a1;
return result;
}

original_code:
void func1(int n, Seiseki a[], int *max, int *min, double *ave)
{
  int i;
  double t;
  sort(n, a);
  *max = a[0].ten;
  *min = a[n - 1].ten;
  t = a[0].ten;
  for (i = 1; i < n; i++) {
    t += a[i].ten;
  }
  *ave = t / n;
}

canonical_original_code:
void func1(int n, struct Seiseki a[], int *max, int *min, double *ave)
{
  int i;
  double t;
  sort(n, a);
  *max = a[0].ten;
  *min = a[n - 1].ten;
  t = a[0].ten;
  for (i = 1; i < n; i++) {
    t += a[i].ten;
  }
  *ave = t / n;
}

variable_types: struct Seiseki { int no; char name[30]; int ten; } []

variable_types:
max
int *

variable_types:
min
int *

variable_types:
ave
double *

variable_types: t double


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v4; // [rsp+0h] [rbp-18h] BYREF
unsigned int v5; // [rsp+8h] [rbp-10h] BYREF
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

func1(4, (__int64)&s_0, v6, &v5, &v4);
printf(&format, v6[0], (unsigned int)s_0, &unk_1C4);
printf(&byte_280, v5, v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v4; // [rsp+0h] [rbp-18h] BYREF
unsigned int v5; // [rsp+8h] [rbp-10h] BYREF
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

func0(4, (__int64)&s_0, v6, &v5, &v4);
printf(&format, v6[0], (unsigned int)s_0, &unk_1C4);
printf(&byte_280, v5, v4);
return 0;
}

original_code:
int main(void)
{
  static Seiseki s[] = {
    {1, "あいうえお", 77},
    {2, "かきくけこ", 57},
    {3, "さしすせそ", 100},
    {4, "たちつてと", 85},
  };
  int n = 4, max, min;
  double ave;
  func1(n, s, &max, &min, &ave);
  printf("最高点 = %d (%d番 : %s)\n", max, s[0].no, s[0].name);
  printf("最低点 = %d  平均点 = %5.1f\n", min, ave);
  return 0;
}

canonical_original_code:
int main()
{
  static struct Seiseki s[] = {
    {1, "あいうえお", 77},
    {2, "かきくけこ", 57},
    {3, "さしすせそ", 100},
    {4, "たちつてと", 85},
  };
  int n = 4; int max; int min;
  double ave;
  func1(n, s, &max, &min, &ave);
  printf("最高点 = %d (%d番 : %s)\n", max, s[0].no, s[0].name);
  printf("最低点 = %d  平均点 = %5.1f\n", min, ave);
  return 0;
}

variable_types: min int

user_defined_types: struct Seiseki { int no; char name[30]; int ten; }


exit

decompiled_code:
void __fastcall __noreturn exit(int status)
{
__asm { int 80h; LINUX - sys_exit }
}

canonical_decompiled_code:
void __fastcall __noreturn func2(int status)
{
__asm { int 80h; LINUX - sys_exit }
}

original_code:
void exit(int status)
{
 asm ( "movl %0, %%ebx	\n\t"
   "movq $1, %%rax		\n\t"
   "int $0x80			\n\t"
   :
   :"r"(status)
   :);
}

variable_types: status int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
signed __int64 v3; // rax
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

v3 = read(0, v5, 0x100uLL);
write(1u, v5, v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
signed __int64 v3; // rax
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

v3 = func1(0, v5, 0x100uLL);
func0(1u, v5, v3);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 long len;
 char buf[256];
 len = read(0, buf, 256);
 write(1, buf, len);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 long len;
 char buf[256];
 len = read(0, buf, 256);
 write(1, buf, len);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: len long

variable_types:
buf
char [256]


repo: koukaipan/xen-examples

decompiled_code:
void __fastcall __noreturn start_kernel(__int64 a1)
{
HYPERVISOR_update_va_mapping(4096LL, *(_QWORD *)(a1 + 40) | 7LL, 2LL);
edata = 4096LL;
init_events();
console_init(a1);
console_write("Hello world!\r\n");
while ( 1 )
HYPERVISOR_sched_op(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(__int64 a1)
{
func1(4096LL, *(_QWORD *)(a1 + 40) | 7LL, 2LL);
edata = 4096LL;
func16();
func5(a1);
func6("Hello world!\r\n");
while ( 1 )
func0(1);
}

original_code:
void start_kernel(start_info_t * start_info)
{
 HYPERVISOR_update_va_mapping((unsigned long) &shared_info,
   ((pte_t) { (start_info->shared_info | 7) } ),
   (2UL<<0));
 HYPERVISOR_shared_info = &shared_info;
 init_events();
 console_init(start_info);
 console_write("Hello world!\r\n");
 while(1)
 {
  HYPERVISOR_sched_op(1,0);
 }
}

canonical_original_code:
void start_kernel(struct start_info *start_info)
{
 HYPERVISOR_update_va_mapping((unsigned long) &shared_info,
   ((struct pte_t) { (start_info->shared_info | 7) } ),
   (2UL<<0));
 HYPERVISOR_shared_info = &shared_info;
 init_events();
 console_init(start_info);
 console_write("Hello world!\r\n");
 while(1)
 {
  HYPERVISOR_sched_op(1,0);
 }
}

variable_types: struct start_info { char magic[32]; unsigned long nr_pages; unsigned long shared_info; unsigned int flags; unsigned long store_mfn; unsigned int store_evtchn; union { struct { unsigned long mfn; unsigned int evtchn; } domU; struct { unsigned int info_off; unsigned int info_size; } dom0; } console; unsigned long pt_base; unsigned long nr_pt_frames; unsigned long mfn_list; unsigned long mod_start; unsigned long mod_len; char cmd_line[1024]; unsigned long first_p2m_pfn; unsigned long nr_p2m_frames; } *


decompiled_code:
__int64 __fastcall console_write(_BYTE *a1)
{
_BYTE *v1; // rbp
unsigned int v2; // ebx
unsigned int v3; // ebx

if ( *a1 )
{
v1 = a1;
do
{
do
{
v2 = *(_DWORD *)(console + 3084) - *(_DWORD *)(console + 3080);
HYPERVISOR_event_channel_op(4);
_mm_mfence();
}
while ( v2 > 0x7FF );
*(_BYTE *)(console + ((*(_DWORD *)(console + 3084))++ & 0x7FF) + 1024) = *v1;
v3 = 1 - (_DWORD)a1 + (_DWORD)v1++;
}
while ( *v1 );
}
else
{
v3 = 0;
}
HYPERVISOR_event_channel_op(4);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1)
{
_BYTE *v1; // rbp
unsigned int v2; // ebx
unsigned int v3; // ebx

if ( *a1 )
{
v1 = a1;
do
{
do
{
v2 = *(_DWORD *)(console + 3084) - *(_DWORD *)(console + 3080);
func4(4);
_mm_mfence();
}
while ( v2 > 0x7FF );
*(_BYTE *)(console + ((*(_DWORD *)(console + 3084))++ & 0x7FF) + 1024) = *v1;
v3 = 1 - (_DWORD)a1 + (_DWORD)v1++;
}
while ( *v1 );
}
else
{
v3 = 0;
}
func4(4);
return v3;
}

original_code:
int console_write(char * message)
{
 struct evtchn_send event;
 event.port = console_evt;
 int length = 0;
 while(*message != '\0')
 {
  XENCONS_RING_IDX data;
  do
  {
   data = console->out_prod - console->out_cons;
   HYPERVISOR_event_channel_op(4, &event);
   __asm__ __volatile__ ( "mfence" : : : "memory");
  } while (data >= sizeof(console->out));
  int ring_index = ((console->out_prod) & (sizeof(console->out)-1));
  console->out[ring_index] = *message;
  __asm__ __volatile__ ( "" : : : "memory");
  console->out_prod++;
  length++;
  message++;
 }
 HYPERVISOR_event_channel_op(4, &event);
 return length;
}

canonical_original_code:
int console_write(char *message)
{
 struct evtchn_send event;
 event.port = console_evt;
 int length = 0;
 while(*message != '\0')
 {
  unsigned int data;
  do
  {
   data = console->out_prod - console->out_cons;
   HYPERVISOR_event_channel_op(4, &event);
   __asm__ __volatile__ ( "mfence" : : : "memory");
  } while (data >= sizeof(console->out));
  int ring_index = ((console->out_prod) & (sizeof(console->out)-1));
  console->out[ring_index] = *message;
  __asm__ __volatile__ ( "" : : : "memory");
  console->out_prod++;
  length++;
  message++;
 }
 HYPERVISOR_event_channel_op(4, &event);
 return length;
}

variable_types:
message
char *

variable_types: struct evtchn_send { unsigned int port; }

variable_types: length int

variable_types:
data
unsigned int


decompiled_code:
__int64 handle_input()
{
__int64 result; // rax
char v1[10]; // [rsp+0h] [rbp-Ah] BYREF

result = console;
if ( *(_DWORD *)(console + 3076) - *(_DWORD *)(console + 3072) > 0 )
{
console_read(v1, *(_DWORD *)(console + 3076) - *(_DWORD *)(console + 3072) + 1);
result = console_write(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
char v1[10]; // [rsp+0h] [rbp-Ah] BYREF

result = console;
if ( *(_DWORD *)(console + 3076) - *(_DWORD *)(console + 3072) > 0 )
{
func7(v1, *(_DWORD *)(console + 3076) - *(_DWORD *)(console + 3072) + 1);
result = func6(v1);
}
return result;
}

original_code:
void handle_input(evtchn_port_t port, struct pt_regs * regs)
{
 XENCONS_RING_IDX cons = console->in_cons;
 XENCONS_RING_IDX prod = console->in_prod;
 int length = prod - cons;
 if(length > 0)
 {
  char buffer[10];
  console_read(buffer, ++length);
  console_write(buffer);
 }
}

canonical_original_code:
void handle_input(unsigned int port, struct pt_regs *regs)
{
 unsigned int cons = console->in_cons;
 unsigned int prod = console->in_prod;
 int length = prod - cons;
 if(length > 0)
 {
  char buffer[10];
  console_read(buffer, ++length);
  console_write(buffer);
 }
}

variable_types:
port
unsigned int

variable_types: struct pt_regs { long ebx; long ecx; long edx; long esi; long edi; long ebp; long eax; int xds; int xes; long orig_eax; long eip; int xcs; long eflags; long esp; int xss; } *

variable_types:
cons
unsigned int

variable_types:
prod
unsigned int

variable_types:
buffer
char [10]


atoc

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

switch ( a1 )
{
case 0:
result = 48LL;
break;
case 1:
result = 49LL;
break;
case 2:
result = 50LL;
break;
case 3:
result = 51LL;
break;
case 4:
result = 52LL;
break;
case 5:
result = 53LL;
break;
case 6:
result = 54LL;
break;
case 7:
result = 55LL;
break;
case 8:
result = 56LL;
break;
case 9:
result = 57LL;
break;
default:
result = 120LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 0:
result = 48LL;
break;
case 1:
result = 49LL;
break;
case 2:
result = 50LL;
break;
case 3:
result = 51LL;
break;
case 4:
result = 52LL;
break;
case 5:
result = 53LL;
break;
case 6:
result = 54LL;
break;
case 7:
result = 55LL;
break;
case 8:
result = 56LL;
break;
case 9:
result = 57LL;
break;
default:
result = 120LL;
break;
}
return result;
}

original_code:
char atoc(int n)
{
 switch(n)
 {
  case 0: return '0';
  case 1: return '1';
  case 2: return '2';
  case 3: return '3';
  case 4: return '4';
  case 5: return '5';
  case 6: return '6';
  case 7: return '7';
  case 8: return '8';
  case 9: return '9';
  default: return 'x';
 }
}

variable_types: n int

return_type: char


decompiled_code:
void EVT_IGN()
{
;
}

canonical_decompiled_code:
void func13()
{
;
}

original_code: void EVT_IGN(evtchn_port_t port, struct pt_regs * regs) {}

canonical_original_code: void EVT_IGN(unsigned int port, struct pt_regs *regs) {}

user_defined_types: struct pt_regs { long ebx; long ecx; long edx; long esi; long edi; long ebp; long eax; int xds; int xes; long orig_eax; long eip; int xcs; long eflags; long esp; int xss; }


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

_BitScanForward64((unsigned __int64 *)&result, a1);
return result;
}

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

_BitScanForward64((unsigned __int64 *)&result, a1);
return result;
}

original_code:
static inline unsigned long int first_bit(unsigned long int word)
{
 __asm__("bsfq %1,%0"
  :"=r" (word)
  :"rm" (word));
 return word;
}

canonical_original_code:
static inline unsigned long first_bit(unsigned long word)
{
 __asm__("bsfq %1,%0"
  :"=r" (word)
  :"rm" (word));
 return word;
}

variable_types:
word
unsigned long

return_type: unsigned long


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 init_events()
{
__int64 result; // rax

HYPERVISOR_set_callbacks(12396LL, 12796LL, 0LL);
for ( result = 0LL; result != 1024; ++result )
{
handlers[result] = 14074LL;
_interlockedbittestandset(&dword_1A00, result);
}
BYTE1(shared_info) = 0;
return result;
}

canonical_decompiled_code:
__int64 func16()
{
__int64 result; // rax

func12(12396LL, 12796LL, 0LL);
for ( result = 0LL; result != 1024; ++result )
{
handlers[result] = 14074LL;
_interlockedbittestandset(&dword_1A00, result);
}
BYTE1(shared_info) = 0;
return result;
}

original_code:
void init_events(void)
{
 HYPERVISOR_set_callbacks(
  (unsigned long)hypervisor_callback,
  (unsigned long)failsafe_callback, 0);
 for(unsigned int i=0 ; i<(1024) ; i++)
 {
  handlers[i] = EVT_IGN;
  __asm__ __volatile__ ("lock btsl %1,%0":"=m"(shared_info.evtchn_mask[0]):"Ir"(i):"memory" );;
 }
 shared_info.vcpu_info[0].evtchn_upcall_mask = 0;
}

canonical_original_code:
void init_events()
{
 HYPERVISOR_set_callbacks(
  (unsigned long)hypervisor_callback,
  (unsigned long)failsafe_callback, 0);
 for(unsigned int i = 0; i<(1024) ; i++)
 {
  handlers[i] = EVT_IGN;
  __asm__ __volatile__ ("lock btsl %1,%0":"=m"(shared_info.evtchn_mask[0]):"Ir"(i):"memory" );;
 }
 shared_info.vcpu_info[0].evtchn_upcall_mask = 0;
}

variable_types:
i
unsigned int


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

result = a1;
handlers[a1] = a2;
_interlockedbittestandreset(&dword_1A00, a1);
return result;
}

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

result = a1;
handlers[a1] = a2;
_interlockedbittestandreset(&dword_1A00, a1);
return result;
}

original_code:
void register_event(evtchn_port_t port, evtchn_handler_t handler)
{
 handlers[port] = handler;
 __asm__ __volatile__ ("lock btrl %1,%0":"=m" ((shared_info.evtchn_mask)):"Ir"((port)):"memory");
}

canonical_original_code:
void register_event(unsigned int port, void (*handler)(unsigned int, struct pt_regs *))
{
 handlers[port] = handler;
 __asm__ __volatile__ ("lock btrl %1,%0":"=m" ((shared_info.evtchn_mask)):"Ir"((port)):"memory");
}

variable_types: void (*)(unsigned int, struct pt_regs { long ebx; long ecx; long edx; long esi; long edi; long ebp; long eax; int xds; int xes; long orig_eax; long eip; int xcs; long eflags; long esp; int xss; } *)


decompiled_code:
void do_divide_error()
{
;
}

canonical_decompiled_code:
void func20()
{
;
}

original_code: void do_divide_error(void) {}

canonical_original_code: void do_divide_error() {}


decompiled_code:
void do_debug()
{
;
}

canonical_decompiled_code:
void func21()
{
;
}

original_code: void do_debug(void) {}

canonical_original_code: void do_debug() {}


decompiled_code:
void do_int3()
{
;
}

canonical_decompiled_code:
void func22()
{
;
}

original_code: void do_int3(void) {}

canonical_original_code: void do_int3() {}


decompiled_code:
void do_overflow()
{
;
}

canonical_decompiled_code:
void func23()
{
;
}

original_code: void do_overflow(void) {}

canonical_original_code: void do_overflow() {}


decompiled_code:
void do_bounds()
{
;
}

canonical_decompiled_code:
void func24()
{
;
}

original_code: void do_bounds(void) {}

canonical_original_code: void do_bounds() {}


decompiled_code:
void do_invalid_op()
{
;
}

canonical_decompiled_code:
void func25()
{
;
}

original_code: void do_invalid_op(void) {}

canonical_original_code: void do_invalid_op() {}


decompiled_code:
void do_device_not_available()
{
;
}

canonical_decompiled_code:
void func26()
{
;
}

original_code: void do_device_not_available(void) {}

canonical_original_code: void do_device_not_available() {}


decompiled_code:
void do_coprocessor_segment_overrun()
{
;
}

canonical_decompiled_code:
void func27()
{
;
}


decompiled_code:
void do_invalid_TSS()
{
;
}

canonical_decompiled_code:
void func28()
{
;
}

original_code: void do_invalid_TSS(void) {}

canonical_original_code: void do_invalid_TSS() {}


decompiled_code:
void do_segment_not_present()
{
;
}

canonical_decompiled_code:
void func29()
{
;
}

original_code: void do_segment_not_present(void) {}

canonical_original_code: void do_segment_not_present() {}


decompiled_code:
void do_stack_segment()
{
;
}

canonical_decompiled_code:
void func30()
{
;
}

original_code: void do_stack_segment(void) {}

canonical_original_code: void do_stack_segment() {}


decompiled_code:
void do_general_protection()
{
;
}

canonical_decompiled_code:
void func31()
{
;
}

original_code: void do_general_protection(void) {}

canonical_original_code: void do_general_protection() {}


decompiled_code:
void do_page_fault()
{
;
}

canonical_decompiled_code:
void func32()
{
;
}

original_code: void do_page_fault(void) {}

canonical_original_code: void do_page_fault() {}


decompiled_code:
void do_coprocessor_error()
{
;
}

canonical_decompiled_code:
void func33()
{
;
}

original_code: void do_coprocessor_error(void) {}

canonical_original_code: void do_coprocessor_error() {}


decompiled_code:
void do_simd_coprocessor_error()
{
;
}

canonical_decompiled_code:
void func34()
{
;
}

original_code: void do_simd_coprocessor_error(void) {}

canonical_original_code: void do_simd_coprocessor_error() {}


decompiled_code:
void do_alignment_check()
{
;
}

canonical_decompiled_code:
void func35()
{
;
}

original_code: void do_alignment_check(void) {}

canonical_original_code: void do_alignment_check() {}


decompiled_code:
void do_spurious_interrupt_bug()
{
;
}

canonical_decompiled_code:
void func36()
{
;
}

original_code: void do_spurious_interrupt_bug(void) {}

canonical_original_code: void do_spurious_interrupt_bug() {}


decompiled_code:
void do_machine_check()
{
;
}

canonical_decompiled_code:
void func37()
{
;
}

original_code: void do_machine_check(void) {}

canonical_original_code: void do_machine_check() {}


decompiled_code:
__int64 trap_init()
{
return HYPERVISOR_set_trap_table(16416LL);
}

original_code:
void trap_init(void)
{
    HYPERVISOR_set_trap_table(trap_table);
}

canonical_original_code:
void trap_init()
{
    HYPERVISOR_set_trap_table(trap_table);
}


decompiled_code:
__int64 __fastcall pcap__connect(__int64 a1)
{
if ( !a1 )
_assert_fail("d", "analysis/pcap.c", 0x2Eu, "pcap__connect");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( !a1 )
_assert_fail("d", "analysis/pcap.c", 0x2Eu, "pcap__connect");
return 0LL;
}

canonical_original_code:
enum err_t pcap__connect(void *d)
{
    ((void) sizeof ((d) ? 1 : 0), __extension__ ({ if (d) ; else __assert_fail ("d", "analysis/pcap.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    return ERR_NONE;
}

variable_types:
d
void *

return_type: enum err_t { ERR_NONE=0, ERR_SEND_FAILED=1, ERR_RECV_FAILED=2, ERR_CONNECTION_FAILED=3, ERR_CONNECTION_CLOSED=4, ERR_TIMEOUT=5, ERR_READ_FAILURE=6, ERR_WRITE_FAILURE=7, ERR_NO_SUCH_VALUE=8, ERR_NOT_SUPPORTED=9, ERR_UNKNOWN=10 }


decompiled_code:
void __fastcall pcap__disconnect(__int64 a1)
{
if ( !a1 )
_assert_fail("d", "analysis/pcap.c", 0x34u, "pcap__disconnect");
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
if ( !a1 )
_assert_fail("d", "analysis/pcap.c", 0x34u, "pcap__disconnect");
}

original_code:
void pcap__disconnect(void *d)
{
    ((void) sizeof ((d) ? 1 : 0), __extension__ ({ if (d) ; else __assert_fail ("d", "analysis/pcap.c", 52, __extension__ __PRETTY_FUNCTION__); }));
}


decompiled_code:
__int64 __fastcall ppkt_prefix_header(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx

if ( !a2 )
_assert_fail("p", "lib/ppkt.c", 0x3Cu, "ppkt_prefix_header");
if ( !a1 )
_assert_fail("hdr", "lib/ppkt.c", 0x3Du, "ppkt_prefix_header");
if ( a2 == a1 )
_assert_fail("p != hdr", "lib/ppkt.c", 0x3Eu, "ppkt_prefix_header");
v2 = a1;
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
*(_QWORD *)(v3 + 24) = a2;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx

if ( !a2 )
_assert_fail("p", "lib/ppkt.c", 0x3Cu, "ppkt_prefix_header");
if ( !a1 )
_assert_fail("hdr", "lib/ppkt.c", 0x3Du, "ppkt_prefix_header");
if ( a2 == a1 )
_assert_fail("p != hdr", "lib/ppkt.c", 0x3Eu, "ppkt_prefix_header");
v2 = a1;
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
*(_QWORD *)(v3 + 24) = a2;
return a1;
}

original_code:
struct ppkt_t *ppkt_prefix_header(struct ppkt_t *hdr, struct ppkt_t *p)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 60, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((hdr) ? 1 : 0), __extension__ ({ if (hdr) ; else __assert_fail ("hdr", "lib/ppkt.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((p != hdr) ? 1 : 0), __extension__ ({ if (p != hdr) ; else __assert_fail ("p != hdr", "lib/ppkt.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    struct ppkt_t *it = hdr;
    while (it->next) it = it->next;
    it->next = p;
    return hdr;
}

variable_types:
hdr
struct ppkt_t *

variable_types:
p
struct ppkt_t *

variable_types: struct ppkt_t { unsigned char *payload; unsigned long size; unsigned long offset; struct ppkt_t *next; unsigned char flags; } *


decompiled_code:
__int64 __fastcall ppkt_append_footer(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx

if ( !a1 )
_assert_fail("footer", "lib/ppkt.c", 0x49u, "ppkt_append_footer");
if ( !a2 )
return a1;
v2 = a2;
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
if ( v3 == a1 )
_assert_fail("it != footer", "lib/ppkt.c", 0x51u, "ppkt_append_footer");
*(_QWORD *)(v3 + 24) = a1;
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx

if ( !a1 )
_assert_fail("footer", "lib/ppkt.c", 0x49u, "ppkt_append_footer");
if ( !a2 )
return a1;
v2 = a2;
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
if ( v3 == a1 )
_assert_fail("it != footer", "lib/ppkt.c", 0x51u, "ppkt_append_footer");
*(_QWORD *)(v3 + 24) = a1;
return a2;
}

original_code:
struct ppkt_t *ppkt_append_footer(struct ppkt_t *footer, struct ppkt_t *p)
{
    ((void) sizeof ((footer) ? 1 : 0), __extension__ ({ if (footer) ; else __assert_fail ("footer", "lib/ppkt.c", 73, __extension__ __PRETTY_FUNCTION__); }));
    if (! p)
        return footer;
    struct ppkt_t *it = p;
    while (it->next) it = it->next;
    ((void) sizeof ((it != footer) ? 1 : 0), __extension__ ({ if (it != footer) ; else __assert_fail ("it != footer", "lib/ppkt.c", 81, __extension__ __PRETTY_FUNCTION__); }));
    it->next = footer;
    return p;
}

variable_types:
footer
struct ppkt_t *

return_type: struct ppkt_t { unsigned char *payload; unsigned long size; unsigned long offset; struct ppkt_t *next; unsigned char flags; } *


decompiled_code:
__int64 __fastcall ppkt_payload(_QWORD *a1)
{
if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xAFu, "ppkt_payload");
return *a1 + a1[2];
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xAFu, "ppkt_payload");
return *a1 + a1[2];
}

original_code:
uint8_t* ppkt_payload(struct ppkt_t *p)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 175, __extension__ __PRETTY_FUNCTION__); }));
    return p->payload + p->offset;
}

canonical_original_code:
unsigned char *ppkt_payload(struct ppkt_t *p)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 175, __extension__ __PRETTY_FUNCTION__); }));
    return p->payload + p->offset;
}

return_type: unsigned char *

user_defined_types: struct ppkt_t { unsigned char *payload; unsigned long size; unsigned long offset; struct ppkt_t *next; unsigned char flags; }


decompiled_code:
__int64 __fastcall ppkt_size(__int64 a1)
{
if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xBCu, "ppkt_size");
return *(_QWORD *)(a1 + 8) - *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xBCu, "ppkt_size");
return *(_QWORD *)(a1 + 8) - *(_QWORD *)(a1 + 16);
}

original_code:
size_t ppkt_size(struct ppkt_t *p)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 188, __extension__ __PRETTY_FUNCTION__); }));
    return p->size - p->offset;
}

canonical_original_code:
unsigned long ppkt_size(struct ppkt_t *p)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 188, __extension__ __PRETTY_FUNCTION__); }));
    return p->size - p->offset;
}


decompiled_code:
__int64 __fastcall ppkt_payload_sized(_QWORD *a1, unsigned __int64 a2)
{
if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xB5u, "ppkt_payload_sized");
if ( ppkt_size((__int64)a1) < a2 )
_assert_fail("ppkt_size(p) >= size", "lib/ppkt.c", 0xB6u, "ppkt_payload_sized");
return ppkt_payload(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, unsigned __int64 a2)
{
if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xB5u, "ppkt_payload_sized");
if ( func4((__int64)a1) < a2 )
_assert_fail("ppkt_size(p) >= size", "lib/ppkt.c", 0xB6u, "ppkt_payload_sized");
return func3(a1);
}

original_code:
uint8_t* ppkt_payload_sized(struct ppkt_t *p, size_t size)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 181, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((ppkt_size(p) >= size) ? 1 : 0), __extension__ ({ if (ppkt_size(p) >= size) ; else __assert_fail ("ppkt_size(p) >= size", "lib/ppkt.c", 182, __extension__ __PRETTY_FUNCTION__); }));
    return ppkt_payload(p);
}

canonical_original_code:
unsigned char *ppkt_payload_sized(struct ppkt_t *p, unsigned long size)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 181, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((ppkt_size(p) >= size) ? 1 : 0), __extension__ ({ if (ppkt_size(p) >= size) ; else __assert_fail ("ppkt_size(p) >= size", "lib/ppkt.c", 182, __extension__ __PRETTY_FUNCTION__); }));
    return ppkt_payload(p);
}

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall ppkt_chain_size(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp

if ( !a1 )
return 0LL;
v1 = a1;
v2 = 0LL;
do
{
v2 += ppkt_size(v1);
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp

if ( !a1 )
return 0LL;
v1 = a1;
v2 = 0LL;
do
{
v2 += func4(v1);
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
return v2;
}

original_code:
size_t ppkt_chain_size(struct ppkt_t *p)
{
    size_t length = 0;
    while (p)
    {
        length += ppkt_size(p);
        p = p->next;
    }
    return length;
}

canonical_original_code:
unsigned long ppkt_chain_size(struct ppkt_t *p)
{
    unsigned long length = 0;
    while (p)
    {
        length += ppkt_size(p);
        p = p->next;
    }
    return length;
}

variable_types:
length
unsigned long


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

if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xCFu, "ppkt_chain_count");
result = 0LL;
do
{
++result;
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return result;
}

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

if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xCFu, "ppkt_chain_count");
result = 0LL;
do
{
++result;
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return result;
}

original_code:
size_t ppkt_chain_count(struct ppkt_t *p)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 207, __extension__ __PRETTY_FUNCTION__); }));
    size_t length = 0;
    while (p)
    {
        length++;
        p = p->next;
    }
    return length;
}

canonical_original_code:
unsigned long ppkt_chain_count(struct ppkt_t *p)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 207, __extension__ __PRETTY_FUNCTION__); }));
    unsigned long length = 0;
    while (p)
    {
        length++;
        p = p->next;
    }
    return length;
}


decompiled_code:
__int64 __fastcall ppkt_next(__int64 a1)
{
if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xDDu, "ppkt_next");
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xDDu, "ppkt_next");
return *(_QWORD *)(a1 + 24);
}

original_code:
struct ppkt_t* ppkt_next(struct ppkt_t *p)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 221, __extension__ __PRETTY_FUNCTION__); }));
    return p->next;
}

canonical_original_code:
struct ppkt_t *ppkt_next(struct ppkt_t *p)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 221, __extension__ __PRETTY_FUNCTION__); }));
    return p->next;
}


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

if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xE3u, "ppkt_pull");
result = ppkt_size(a1);
if ( result < a2 )
_assert_fail("size <= ppkt_size(p)", "lib/ppkt.c", 0xE4u, "ppkt_pull");
*(_QWORD *)(a1 + 16) += a2;
return result;
}

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

if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xE3u, "ppkt_pull");
result = func4(a1);
if ( result < a2 )
_assert_fail("size <= ppkt_size(p)", "lib/ppkt.c", 0xE4u, "ppkt_pull");
*(_QWORD *)(a1 + 16) += a2;
return result;
}

original_code:
void ppkt_pull(struct ppkt_t *p, size_t size)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 227, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((size <= ppkt_size(p)) ? 1 : 0), __extension__ ({ if (size <= ppkt_size(p)) ; else __assert_fail ("size <= ppkt_size(p)", "lib/ppkt.c", 228, __extension__ __PRETTY_FUNCTION__); }));
    p->offset += size;
}

canonical_original_code:
void ppkt_pull(struct ppkt_t *p, unsigned long size)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 227, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((size <= ppkt_size(p)) ? 1 : 0), __extension__ ({ if (size <= ppkt_size(p)) ; else __assert_fail ("size <= ppkt_size(p)", "lib/ppkt.c", 228, __extension__ __PRETTY_FUNCTION__); }));
    p->offset += size;
}


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

if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xEBu, "ppkt_cut");
result = ppkt_size(a1);
if ( result < a2 )
_assert_fail("size <= ppkt_size(p)", "lib/ppkt.c", 0xECu, "ppkt_cut");
*(_QWORD *)(a1 + 8) -= a2;
return result;
}

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

if ( !a1 )
_assert_fail("p", "lib/ppkt.c", 0xEBu, "ppkt_cut");
result = func4(a1);
if ( result < a2 )
_assert_fail("size <= ppkt_size(p)", "lib/ppkt.c", 0xECu, "ppkt_cut");
*(_QWORD *)(a1 + 8) -= a2;
return result;
}

original_code:
void ppkt_cut(struct ppkt_t *p, size_t size)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 235, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((size <= ppkt_size(p)) ? 1 : 0), __extension__ ({ if (size <= ppkt_size(p)) ; else __assert_fail ("size <= ppkt_size(p)", "lib/ppkt.c", 236, __extension__ __PRETTY_FUNCTION__); }));
    p->size -= size;
}

canonical_original_code:
void ppkt_cut(struct ppkt_t *p, unsigned long size)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "lib/ppkt.c", 235, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((size <= ppkt_size(p)) ? 1 : 0), __extension__ ({ if (size <= ppkt_size(p)) ; else __assert_fail ("size <= ppkt_size(p)", "lib/ppkt.c", 236, __extension__ __PRETTY_FUNCTION__); }));
    p->size -= size;
}


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

switch ( a1 )
{
case 0:
result = "Raw memory S5";
break;
case 3:
result = "SysInfo";
break;
case 5:
result = "SysFlags";
break;
case 6:
result = "Analog in";
break;
case 7:
result = "Analog out";
break;
case 28:
result = "Counter";
break;
case 29:
result = "Timer";
break;
case 30:
result = "Counter (200 family)";
break;
case 31:
result = "Timer (200 family)";
break;
case 128:
result = "Direct peripheral access";
break;
case 129:
result = "Inputs";
break;
case 130:
result = "Outputs";
break;
case 131:
result = "Flags";
break;
case 132:
result = "Data blocks";
break;
case 133:
result = "Instance data blocks";
break;
case 134:
result = "System data S5";
break;
case 135:
result = "V";
break;
default:
result = "unknown";
break;
}
return result;
}

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

switch ( a1 )
{
case 0:
result = "Raw memory S5";
break;
case 3:
result = "SysInfo";
break;
case 5:
result = "SysFlags";
break;
case 6:
result = "Analog in";
break;
case 7:
result = "Analog out";
break;
case 28:
result = "Counter";
break;
case 29:
result = "Timer";
break;
case 30:
result = "Counter (200 family)";
break;
case 31:
result = "Timer (200 family)";
break;
case 128:
result = "Direct peripheral access";
break;
case 129:
result = "Inputs";
break;
case 130:
result = "Outputs";
break;
case 131:
result = "Flags";
break;
case 132:
result = "Data blocks";
break;
case 133:
result = "Instance data blocks";
break;
case 134:
result = "System data S5";
break;
case 135:
result = "V";
break;
default:
result = "unknown";
break;
}
return result;
}

original_code:
const char* s7comm_area_to_string(const enum s7comm_area_t area)
{
    switch (area)
    {
        case s7comm_area_SysInfo:
            return "SysInfo";
        case s7comm_area_SysFlags:
            return "SysFlags";
        case s7comm_area_AnaIn:
            return "Analog in";
        case s7comm_area_AnaOut:
            return "Analog out";
        case s7comm_area_P:
            return "Direct peripheral access";
        case s7comm_area_Inputs:
            return "Inputs";
        case s7comm_area_Outputs:
            return "Outputs";
        case s7comm_area_Flags:
            return "Flags";
        case s7comm_area_DB:
            return "Data blocks";
        case s7comm_area_DI:
            return "Instance data blocks";
        case s7comm_area_SysDataS5:
            return "System data S5";
        case s7comm_area_V:
            return "V";
        case s7comm_area_Counter:
            return "Counter";
        case s7comm_area_Timer:
            return "Timer";
        case s7comm_area_Counter200:
            return "Counter (200 family)";
        case s7comm_area_Timer200:
            return "Timer (200 family)";
        case s7comm_area_RawMemoryS5:
            return "Raw memory S5";
    }
    return "unknown";
}

canonical_original_code:
char *s7comm_area_to_string(enum s7comm_area_t area)
{
    switch (area)
    {
        case s7comm_area_SysInfo:
            return "SysInfo";
        case s7comm_area_SysFlags:
            return "SysFlags";
        case s7comm_area_AnaIn:
            return "Analog in";
        case s7comm_area_AnaOut:
            return "Analog out";
        case s7comm_area_P:
            return "Direct peripheral access";
        case s7comm_area_Inputs:
            return "Inputs";
        case s7comm_area_Outputs:
            return "Outputs";
        case s7comm_area_Flags:
            return "Flags";
        case s7comm_area_DB:
            return "Data blocks";
        case s7comm_area_DI:
            return "Instance data blocks";
        case s7comm_area_SysDataS5:
            return "System data S5";
        case s7comm_area_V:
            return "V";
        case s7comm_area_Counter:
            return "Counter";
        case s7comm_area_Timer:
            return "Timer";
        case s7comm_area_Counter200:
            return "Counter (200 family)";
        case s7comm_area_Timer200:
            return "Timer (200 family)";
        case s7comm_area_RawMemoryS5:
            return "Raw memory S5";
    }
    return "unknown";
}

variable_types: enum s7comm_area_t { s7comm_area_SysInfo=3, s7comm_area_SysFlags=5, s7comm_area_AnaIn=6, s7comm_area_AnaOut=7, s7comm_area_P=128, s7comm_area_Inputs=129, s7comm_area_Outputs=130, s7comm_area_Flags=131, s7comm_area_DB=132, s7comm_area_DI=133, s7comm_area_SysDataS5=134, s7comm_area_V=135, s7comm_area_Counter=28, s7comm_area_Timer=29, s7comm_area_Counter200=30, s7comm_area_Timer200=31, s7comm_area_RawMemoryS5=0 }

return_type: char *


decompiled_code:
int __fastcall dump_bytes(unsigned __int8 *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax

if ( !a2 )
goto LABEL_9;
printf("%02x ", *a1);
v2 = 0LL;
while ( 1 )
{
v3 = v2 & 0xF;
if ( v3 == 15 )
LODWORD(v3) = putchar(10);
if ( a2 == ++v2 )
break;
printf("%02x ", a1[v2]);
if ( (v2 & 7) == 7 )
printf(" ");
}
if ( (v2 & 0xF) != 15 )
LABEL_9:
LODWORD(v3) = putchar(10);
return v3;
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int8 *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax

if ( !a2 )
goto LABEL_9;
printf("%02x ", *a1);
v2 = 0LL;
while ( 1 )
{
v3 = v2 & 0xF;
if ( v3 == 15 )
LODWORD(v3) = putchar(10);
if ( a2 == ++v2 )
break;
printf("%02x ", a1[v2]);
if ( (v2 & 7) == 7 )
printf(" ");
}
if ( (v2 & 0xF) != 15 )
LABEL_9:
LODWORD(v3) = putchar(10);
return v3;
}

original_code:
void dump_bytes(const uint8_t *bytes, size_t size)
{
    size_t i;
    for (i = 0; i < size; i++)
    {
        printf("%02x ", bytes[i]);
        if (i % 8 == 7)
            printf("  ");
        if (i % 16 == 15)
            printf("\n");
    }
    if (i % 16 != 15)
        printf("\n");
}

canonical_original_code:
void dump_bytes(unsigned char *bytes, unsigned long size)
{
    unsigned long i;
    for (i = 0; i < size; i++)
    {
        printf("%02x ", bytes[i]);
        if (i % 8 == 7)
            printf("  ");
        if (i % 16 == 15)
            printf("\n");
    }
    if (i % 16 != 15)
        printf("\n");
}

variable_types:
bytes
unsigned char *

variable_types:
i
unsigned long


help

decompiled_code:
void __fastcall __noreturn help(const char *a1)
{
printf("Usage: %s [-l] -a <ip> -t [mda] -d <db> -n <number>\n", a1);
puts(" -l: Target is a Logo device.");
puts(" -t:");
puts(" m: Merker (bit)");
puts(" d: Data word");
puts(" a: Output");
puts(" i: Input");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
printf("Usage: %s [-l] -a <ip> -t [mda] -d <db> -n <number>\n", a1);
puts(" -l: Target is a Logo device.");
puts(" -t:");
puts(" m: Merker (bit)");
puts(" d: Data word");
puts(" a: Output");
puts(" i: Input");
exit(1);
}

original_code:
static void help(const char *name)
{
    printf("Usage: %s [-l] -a <ip> -t [mda] -d <db> -n <number>\n", name);
    printf(" -l: Target is a Logo device.\n");
    printf(" -t:\n");
    printf("       m: Merker (bit)\n");
    printf("       d: Data word\n");
    printf("       a: Output\n");
    printf("       i: Input\n");
    exit(1);
}

canonical_original_code:
static void help(char *name)
{
    printf("Usage: %s [-l] -a <ip> -t [mda] -d <db> -n <number>\n", name);
    printf(" -l: Target is a Logo device.\n");
    printf(" -t:\n");
    printf("       m: Merker (bit)\n");
    printf("       d: Data word\n");
    printf("       a: Output\n");
    printf("       i: Input\n");
    exit(1);
}

variable_types:
name
char *


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

switch ( a1 )
{
case 0:
result = "No error";
break;
case 1:
result = "Send failed";
break;
case 2:
result = "Receive failed";
break;
case 3:
result = "Connection failed";
break;
case 4:
result = "Connection closed";
break;
case 5:
result = "Timeout";
break;
case 6:
result = "Read failure";
break;
case 7:
result = "Write failure";
break;
case 8:
result = "Variable does not exist";
break;
case 9:
result = "Not supported";
break;
case 10:
result = "Unknown";
break;
default:
_assert_fail("0", "lib/err.c", 0x20u, "err_to_string");
}
return result;
}

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

switch ( a1 )
{
case 0:
result = "No error";
break;
case 1:
result = "Send failed";
break;
case 2:
result = "Receive failed";
break;
case 3:
result = "Connection failed";
break;
case 4:
result = "Connection closed";
break;
case 5:
result = "Timeout";
break;
case 6:
result = "Read failure";
break;
case 7:
result = "Write failure";
break;
case 8:
result = "Variable does not exist";
break;
case 9:
result = "Not supported";
break;
case 10:
result = "Unknown";
break;
default:
_assert_fail("0", "lib/err.c", 0x20u, "err_to_string");
}
return result;
}

original_code:
const char* err_to_string(const err_t err)
{
    switch (err)
    {
        case ERR_NONE:
            return "No error";
        case ERR_SEND_FAILED:
            return "Send failed";
        case ERR_RECV_FAILED:
            return "Receive failed";
        case ERR_CONNECTION_FAILED:
            return "Connection failed";
        case ERR_CONNECTION_CLOSED:
            return "Connection closed";
        case ERR_TIMEOUT:
            return "Timeout";
        case ERR_READ_FAILURE:
            return "Read failure";
        case ERR_WRITE_FAILURE:
            return "Write failure";
        case ERR_NO_SUCH_VALUE:
            return "Variable does not exist";
        case ERR_NOT_SUPPORTED:
            return "Not supported";
        case ERR_UNKNOWN:
            return "Unknown";
    }
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "lib/err.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    return ((void *)0);
}

canonical_original_code:
char *err_to_string(enum err_t err)
{
    switch (err)
    {
        case ERR_NONE:
            return "No error";
        case ERR_SEND_FAILED:
            return "Send failed";
        case ERR_RECV_FAILED:
            return "Receive failed";
        case ERR_CONNECTION_FAILED:
            return "Connection failed";
        case ERR_CONNECTION_CLOSED:
            return "Connection closed";
        case ERR_TIMEOUT:
            return "Timeout";
        case ERR_READ_FAILURE:
            return "Read failure";
        case ERR_WRITE_FAILURE:
            return "Write failure";
        case ERR_NO_SUCH_VALUE:
            return "Variable does not exist";
        case ERR_NOT_SUPPORTED:
            return "Not supported";
        case ERR_UNKNOWN:
            return "Unknown";
    }
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "lib/err.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    return ((void *)0);
}

variable_types: enum err_t { ERR_NONE=0, ERR_SEND_FAILED=1, ERR_RECV_FAILED=2, ERR_CONNECTION_FAILED=3, ERR_CONNECTION_CLOSED=4, ERR_TIMEOUT=5, ERR_READ_FAILURE=6, ERR_WRITE_FAILURE=7, ERR_NO_SUCH_VALUE=8, ERR_NOT_SUPPORTED=9, ERR_UNKNOWN=10 }


repo: kralljr/gibbs-truncnormal-mdl

decompiled_code:
double __fastcall checked_strtod(const char **a1, char a2, const char *a3)
{
double result; // xmm0_8
char *endptr; // [rsp+8h] [rbp-20h] BYREF

endptr = 0LL;
result = strtod(a3, &endptr);
if ( endptr == a3 )
exit_invalid_argument(a1, a2, a3);
return result;
}

canonical_decompiled_code:
double __fastcall func8(const char **a1, char a2, const char *a3)
{
double result; // xmm0_8
char *endptr; // [rsp+8h] [rbp-20h] BYREF

endptr = 0LL;
result = strtod(a3, &endptr);
if ( endptr == a3 )
func7(a1, a2, a3);
return result;
}

original_code:
static double
checked_strtod(char *argv[], char flag, char *s)
{
    double y;
    char *endptr = ((void *)0);
    y = strtod(s, &endptr);
    if (s == endptr) {
        exit_invalid_argument(argv, flag, s);
    }
    return y;
}

variable_types:
argv
char *[]

variable_types: flag char

variable_types:
s
char *

variable_types: y double

variable_types:
endptr
char *


decompiled_code:
void __fastcall __noreturn exit_eio(const char **a1, const char *a2)
{
int *v2; // rax
char *v3; // rax

v2 = __errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s: can't open %s: %s\n", *a1, a2, v3);
exit(2);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(const char **a1, const char *a2)
{
int *v2; // rax
char *v3; // rax

v2 = __errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s: can't open %s: %s\n", *a1, a2, v3);
exit(2);
}

original_code:
static void
exit_eio(char *argv[], char *filename)
{
    fprintf(stderr, "%s: can't open %s: %s\n", argv[0], filename, strerror((*__errno_location ())));
    exit(2);
}

variable_types:
filename
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
const char *v4; // r15
__int64 v5; // r12
int v6; // er13
int v7; // eax
FILE *v8; // rbp
__int64 v9; // rbx
const char *v10; // rsi
int i; // er14
double v13; // [rsp+8h] [rbp-60h]
__int64 v14; // [rsp+10h] [rbp-58h]
double v15; // [rsp+18h] [rbp-50h]
char *endptr[8]; // [rsp+28h] [rbp-40h] BYREF

opterr = 0;
v3 = 0LL;
v4 = 0LL;
v5 = 0x3FF0000000000000LL;
v15 = -1.0;
v14 = 0x3FF0000000000000LL;
v13 = 0.0;
v6 = 1;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "n:m:s:a:b:o:r:h");
if ( v7 == -1 )
break;
endptr[0] = 0LL;
switch ( v7 )
{
case '?':
exit_invalid_flag(argv, optopt);
case 'a':
v15 = checked_strtod(argv, 97, optarg);
break;
case 'b':
v5 = checked_strtod(argv, 98, optarg);
break;
case 'h':
exit_usage(argv);
case 'm':
v13 = checked_strtod(argv, 109, optarg);
break;
case 'n':
v6 = strtol(optarg, endptr, 10);
break;
case 'o':
v4 = optarg;
break;
case 'r':
v3 = strtol(optarg, endptr, 0);
break;
case 's':
v14 = checked_strtod(argv, 115, optarg);
break;
default:
continue;
}
}
if ( v4 )
{
v8 = fopen(v4, "wt");
if ( !v8 )
exit_eio(argv, v4);
v9 = gsl_rng_alloc();
v10 = (const char *)v3;
gsl_rng_set();
if ( v6 <= 0 )
goto LABEL_19;
}
else
{
v8 = (FILE *)stdout;
v9 = gsl_rng_alloc();
v10 = (const char *)v3;
gsl_rng_set();
if ( v6 <= 0 )
goto LABEL_20;
}
for ( i = 0; i < v6; ++i )
{
ran_truncnormal(v9, v10, v15, *(double *)&v5, v13, *(double *)&v14);
v10 = "%0.16f\n";
fprintf(v8, "%0.16f\n", v15);
}
if ( v4 )
LABEL_19:
fclose(v8);
LABEL_20:
gsl_rng_free();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
const char *v4; // r15
__int64 v5; // r12
int v6; // er13
int v7; // eax
FILE *v8; // rbp
__int64 v9; // rbx
const char *v10; // rsi
int i; // er14
double v13; // [rsp+8h] [rbp-60h]
__int64 v14; // [rsp+10h] [rbp-58h]
double v15; // [rsp+18h] [rbp-50h]
char *endptr[8]; // [rsp+28h] [rbp-40h] BYREF

opterr = 0;
v3 = 0LL;
v4 = 0LL;
v5 = 0x3FF0000000000000LL;
v15 = -1.0;
v14 = 0x3FF0000000000000LL;
v13 = 0.0;
v6 = 1;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "n:m:s:a:b:o:r:h");
if ( v7 == -1 )
break;
endptr[0] = 0LL;
switch ( v7 )
{
case '?':
func10(argv, optopt);
case 'a':
v15 = func8(argv, 97, optarg);
break;
case 'b':
v5 = func8(argv, 98, optarg);
break;
case 'h':
func9(argv);
case 'm':
v13 = func8(argv, 109, optarg);
break;
case 'n':
v6 = strtol(optarg, endptr, 10);
break;
case 'o':
v4 = optarg;
break;
case 'r':
v3 = strtol(optarg, endptr, 0);
break;
case 's':
v14 = func8(argv, 115, optarg);
break;
default:
continue;
}
}
if ( v4 )
{
v8 = fopen(v4, "wt");
if ( !v8 )
func11(argv, v4);
v9 = gsl_rng_alloc();
v10 = (const char *)v3;
gsl_rng_set();
if ( v6 <= 0 )
goto LABEL_19;
}
else
{
v8 = (FILE *)stdout;
v9 = gsl_rng_alloc();
v10 = (const char *)v3;
gsl_rng_set();
if ( v6 <= 0 )
goto LABEL_20;
}
for ( i = 0; i < v6; ++i )
{
func19(v9, v10, v15, *(double *)&v5, v13, *(double *)&v14);
v10 = "%0.16f\n";
fprintf(v8, "%0.16f\n", v15);
}
if ( v4 )
LABEL_19:
fclose(v8);
LABEL_20:
gsl_rng_free();
return 0;
}

original_code:
int
main(int argc, char * const argv[])
{
    const char *data_filename;
    const char *mdls_filename;
    const char *output_filename;
    struct gibbs_problem p = {
        ((void *)0),
        ((void *)0),
        1000,
        0,
        1,
        0,
        ((void *)0), ((void *)0), ((void *)0), ((void *)0)};
    gsl_matrix *data = ((void *)0);
    gsl_matrix *mdls = ((void *)0);
    int optflag;
    int exit_val = 0;
    opterr = 0;
    while ((optflag = getopt(argc, argv, "n:b:d:r:h")) != -1) {
        char *endptr = ((void *)0);
        switch (optflag) {
            case 'n':
                p.iterations = strtol(optarg, &endptr, 10);
                break;
            case 'b':
                p.burn = strtol(optarg, &endptr, 10);
                break;
            case 'd':
                p.draws = strtol(optarg, &endptr, 10);
                break;
            case 'r':
                p.seed = strtol(optarg, &endptr, 0);
                break;
            case 'h':
                print_usage(argv[0]);
                return 0;
            case '?':
                fprintf(stderr, "%s: invalid option or missing argument: -'%c'\n",
                        argv[0], optopt);
                print_usage(argv[0]);
                return 1;
        }
    }
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument DATA\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    data_filename = argv[optind++];
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument MDLS\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    mdls_filename = argv[optind++];
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument OUT\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    output_filename = argv[optind++];
    if (optind < argc) {
        fprintf(stderr, "%s: unexpected argument: %s\n", argv[0], argv[optind]);
        print_usage(argv[0]);
        return 1;
    }
    data = csv_load_file(data_filename);
    if (data == ((void *)0)) {
        fprintf(stderr, "%s: cannot read '%s': %s\n",
                argv[0], data_filename, strerror((*__errno_location ())));
        exit_val = (*__errno_location ());
        goto exit;
    }
    mdls = csv_load_file(mdls_filename);
    if (mdls == ((void *)0)) {
        fprintf(stderr, "%s: cannot read '%s': %s\n",
                argv[0], mdls_filename, strerror((*__errno_location ())));
        exit_val = (*__errno_location ());
        goto exit;
    }
    if (data->size1 != mdls->size1 || data->size2 != mdls->size2) {
        fprintf(stderr, "Non-matching `data' and `mdls' dimensions\n");
        exit_val = GSL_EBADLEN;
        goto exit;
    }
    p.data = data;
    p.mdls = mdls;
    gibbs_problem_exec(&p);
    ncdf_write_file(output_filename, &p);
    gibbs_problem_free(&p);
exit:
    if (data != ((void *)0)) {
        gsl_matrix_free(data);
    }
    if (mdls != ((void *)0)) {
        gsl_matrix_free(mdls);
    }
    return exit_val;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char *data_filename;
    char *mdls_filename;
    char *output_filename;
    struct gibbs_problem p = {
        ((void *)0),
        ((void *)0),
        1000,
        0,
        1,
        0,
        ((void *)0), ((void *)0), ((void *)0), ((void *)0)};
    struct gsl_matrix *data = ((void *)0);
    struct gsl_matrix *mdls = ((void *)0);
    int optflag;
    int exit_val = 0;
    opterr = 0;
    while ((optflag = getopt(argc, argv, "n:b:d:r:h")) != -1) {
        char *endptr = ((void *)0);
        switch (optflag) {
            case 'n':
                p.iterations = strtol(optarg, &endptr, 10);
                break;
            case 'b':
                p.burn = strtol(optarg, &endptr, 10);
                break;
            case 'd':
                p.draws = strtol(optarg, &endptr, 10);
                break;
            case 'r':
                p.seed = strtol(optarg, &endptr, 0);
                break;
            case 'h':
                print_usage(argv[0]);
                return 0;
            case '?':
                fprintf(stderr, "%s: invalid option or missing argument: -'%c'\n",
                        argv[0], optopt);
                print_usage(argv[0]);
                return 1;
        }
    }
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument DATA\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    data_filename = argv[optind++];
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument MDLS\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    mdls_filename = argv[optind++];
    if (optind == argc) {
        fprintf(stderr, "%s: missing argument OUT\n", argv[0]);
        print_usage(argv[0]);
        return 1;
    }
    output_filename = argv[optind++];
    if (optind < argc) {
        fprintf(stderr, "%s: unexpected argument: %s\n", argv[0], argv[optind]);
        print_usage(argv[0]);
        return 1;
    }
    data = csv_load_file(data_filename);
    if (data == ((void *)0)) {
        fprintf(stderr, "%s: cannot read '%s': %s\n",
                argv[0], data_filename, strerror((*__errno_location ())));
        exit_val = (*__errno_location ());
        goto exit;
    }
    mdls = csv_load_file(mdls_filename);
    if (mdls == ((void *)0)) {
        fprintf(stderr, "%s: cannot read '%s': %s\n",
                argv[0], mdls_filename, strerror((*__errno_location ())));
        exit_val = (*__errno_location ());
        goto exit;
    }
    if (data->size1 != mdls->size1 || data->size2 != mdls->size2) {
        fprintf(stderr, "Non-matching `data' and `mdls' dimensions\n");
        exit_val = GSL_EBADLEN;
        goto exit;
    }
    p.data = data;
    p.mdls = mdls;
    gibbs_problem_exec(&p);
    ncdf_write_file(output_filename, &p);
    gibbs_problem_free(&p);
exit:
    if (data != ((void *)0)) {
        gsl_matrix_free(data);
    }
    if (mdls != ((void *)0)) {
        gsl_matrix_free(mdls);
    }
    return exit_val;
}

variable_types: argc int

variable_types: struct gibbs_problem { struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *data; struct gsl_matrix *mdls; unsigned long iterations; unsigned long burn; unsigned long draws; long seed; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; } *mthet; struct gsl_matrix *msig; struct gsl_matrix **ddata; unsigned long *dindexes; }

variable_types: optflag int

user_defined_types: struct gibbs_problem { struct gsl_matrix *data; struct gsl_matrix *mdls; unsigned long iterations; unsigned long burn; unsigned long draws; long seed; struct gsl_vector *mthet; struct gsl_matrix *msig; struct gsl_matrix **ddata; unsigned long *dindexes; }

user_defined_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; }


decompiled_code:
__int64 ran_left_utruncnormal_neg()
{
return gsl_ran_ugaussian();
}

canonical_decompiled_code:
__int64 func12()
{
return gsl_ran_ugaussian();
}

original_code:
static double
ran_left_utruncnormal_neg(const gsl_rng *r, double a)
{
    double y;
    do {
        y = gsl_ran_ugaussian(r);
    } while (y < a);
    return y;
}

canonical_original_code:
static double ran_left_utruncnormal_neg(struct gsl_rng *r, double a)
{
    double y;
    do {
        y = gsl_ran_ugaussian(r);
    } while (y < a);
    return y;
}

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: a double

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


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

do
result = gsl_ran_ugaussian();
while ( a1 > a2 );
return result;
}

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

do
result = gsl_ran_ugaussian();
while ( a1 > a2 );
return result;
}

original_code:
static double
ran_two_utruncnormal_repeat(const gsl_rng *r, double a, double b)
{
    double y;
    do {
        y = gsl_ran_ugaussian(r);
    } while (y < a || y > b);
    return y;
}

canonical_original_code:
static double ran_two_utruncnormal_repeat(struct gsl_rng *r, double a, double b)
{
    double y;
    do {
        y = gsl_ran_ugaussian(r);
    } while (y < a || y > b);
    return y;
}

variable_types: b 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 ran_left_utruncnormal_pos(double a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
double v3; // r15
double v4; // r14
double v7; // [rsp+8h] [rbp-30h]

v1 = a1 * a1 + 4.0;
if ( v1 < 0.0 )
v2 = sqrt(v1);
else
v2 = sqrt(v1);
v7 = (v2 + a1) * 0.5;
v3 = 1.0 / v7;
do
{
gsl_ran_exponential();
v4 = exp(-((v3 + a1 - v7) * (v3 + a1 - v7)) * 0.5);
gsl_ran_flat();
}
while ( v4 < 0.0 );
return v3 + a1;
}

canonical_decompiled_code:
double __fastcall func14(double a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
double v3; // r15
double v4; // r14
double v7; // [rsp+8h] [rbp-30h]

v1 = a1 * a1 + 4.0;
if ( v1 < 0.0 )
v2 = sqrt(v1);
else
v2 = sqrt(v1);
v7 = (v2 + a1) * 0.5;
v3 = 1.0 / v7;
do
{
gsl_ran_exponential();
v4 = exp(-((v3 + a1 - v7) * (v3 + a1 - v7)) * 0.5);
gsl_ran_flat();
}
while ( v4 < 0.0 );
return v3 + a1;
}

original_code:
static double
ran_left_utruncnormal_pos(const gsl_rng *r, double a)
{
    double astar;
    double z;
    double u;
    double rho;
    astar = (a + sqrt((a * a) + 4.0)) / 2.0;
    do {
        z = gsl_ran_exponential(r, 1.0 / astar) + a;
        rho = exp(-pow(z - astar, 2) / 2.0);
        u = gsl_ran_flat(r, 0.0, 1.0);
    } while (u > rho);
    return z;
}

canonical_original_code:
static double ran_left_utruncnormal_pos(struct gsl_rng *r, double a)
{
    double astar;
    double z;
    double u;
    double rho;
    astar = (a + sqrt((a * a) + 4.0)) / 2.0;
    do {
        z = gsl_ran_exponential(r, 1.0 / astar) + a;
        rho = exp(-pow(z - astar, 2) / 2.0);
        u = gsl_ran_flat(r, 0.0, 1.0);
    } while (u > rho);
    return z;
}

variable_types: astar double

variable_types: z double

variable_types: u double

variable_types: rho double


decompiled_code:
void __fastcall ran_left_utruncnormal(double a1)
{
if ( a1 <= 0.0 )
ran_left_utruncnormal_neg();
else
ran_left_utruncnormal_pos(a1);
}

canonical_decompiled_code:
void __fastcall func15(double a1)
{
if ( a1 <= 0.0 )
func12();
else
func14(a1);
}

original_code:
static double
ran_left_utruncnormal(const gsl_rng *r, double a)
{
    return (a > 0) ? ran_left_utruncnormal_pos(r, a) :
                     ran_left_utruncnormal_neg(r, a);
}

canonical_original_code:
static double ran_left_utruncnormal(struct gsl_rng *r, double a)
{
    return (a > 0) ? ran_left_utruncnormal_pos(r, a) :
                     ran_left_utruncnormal_neg(r, a);
}


decompiled_code:
double __fastcall ran_two_utruncnormal_robert(double a1, double a2)
{
double v3; // [rsp+10h] [rbp-18h]

do
{
gsl_ran_flat();
if ( a2 < 0.0 )
{
v3 = exp((a2 * a2 - a1 * a1) * 0.5);
}
else if ( a1 <= 0.0 )
{
v3 = exp(-(a1 * a1) * 0.5);
}
else
{
v3 = exp((a1 * a1 - a1 * a1) * 0.5);
}
gsl_ran_flat();
}
while ( v3 < 0.0 );
return a1;
}

original_code:
static double
ran_two_utruncnormal_robert(const gsl_rng *r, double a, double b)
{
    double z;
    double u;
    double rho;
    do {
        z = gsl_ran_flat(r, a, b);
        if (b < 0) {
            rho = exp((b * b - z * z) / 2.0);
        } else if (a > 0) {
            rho = exp((a * a - z * z) / 2.0);
        } else {
            rho = exp(-(z * z) / 2.0);
        }
        u = gsl_ran_flat(r, 0.0, 1.0);
    } while (u > rho);
    return z;
}

canonical_original_code:
static double ran_two_utruncnormal_robert(struct gsl_rng *r, double a, double b)
{
    double z;
    double u;
    double rho;
    do {
        z = gsl_ran_flat(r, a, b);
        if (b < 0) {
            rho = exp((b * b - z * z) / 2.0);
        } else if (a > 0) {
            rho = exp((a * a - z * z) / 2.0);
        } else {
            rho = exp(-(z * z) / 2.0);
        }
        u = gsl_ran_flat(r, 0.0, 1.0);
    } while (u > rho);
    return z;
}


decompiled_code:
void __fastcall ran_two_utruncnormal(double a1, double a2)
{
if ( a1 <= 0.0 )
{
if ( a2 < 0.0 )
{
while ( a1 > -ran_left_utruncnormal_pos(-a2) )
;
}
else if ( a2 - a1 >= 2.506628274631 )
{
ran_two_utruncnormal_repeat(a1, a2);
}
else
{
ran_two_utruncnormal_robert(a1, a2);
}
}
else
{
while ( ran_left_utruncnormal_pos(a1) > a2 )
;
}
}

original_code:
static double
ran_two_utruncnormal(const gsl_rng *r, double a, double b)
{
    double y;
    if (a > 0.0) {
        do {
            y = ran_left_utruncnormal_pos(r, a);
        } while (y > b);
    } else if (b < 0.0) {
        do {
            y = -ran_left_utruncnormal_pos(r, -b);
        } while (y < a);
    } else if (b - a < SQRT_TWO_PI) {
        y = ran_two_utruncnormal_robert(r, a, b);
    } else {
        y = ran_two_utruncnormal_repeat(r, a, b);
    }
    return y;
}

canonical_original_code:
static double ran_two_utruncnormal(struct gsl_rng *r, double a, double b)
{
    double y;
    if (a > 0.0) {
        do {
            y = ran_left_utruncnormal_pos(r, a);
        } while (y > b);
    } else if (b < 0.0) {
        do {
            y = -ran_left_utruncnormal_pos(r, -b);
        } while (y < a);
    } else if (b - a < SQRT_TWO_PI) {
        y = ran_two_utruncnormal_robert(r, a, b);
    } else {
        y = ran_two_utruncnormal_repeat(r, a, b);
    }
    return y;
}


decompiled_code:
void __fastcall ran_utruncnormal(double a1, double a2)
{
if ( (unsigned int)gsl_isinf() && (unsigned int)gsl_isinf() )
{
gsl_ran_ugaussian();
}
else if ( (unsigned int)gsl_isinf() )
{
ran_left_utruncnormal(-a2);
}
else if ( (unsigned int)gsl_isinf() )
{
ran_left_utruncnormal(a1);
}
else
{
ran_two_utruncnormal(a1, a2);
}
}

canonical_decompiled_code:
void __fastcall func18(double a1, double a2)
{
if ( (unsigned int)gsl_isinf() && (unsigned int)gsl_isinf() )
{
gsl_ran_ugaussian();
}
else if ( (unsigned int)gsl_isinf() )
{
func15(-a2);
}
else if ( (unsigned int)gsl_isinf() )
{
func15(a1);
}
else
{
func17(a1, a2);
}
}

original_code:
double
ran_utruncnormal(const gsl_rng *r, double a, double b)
{
    double y;
    if (gsl_isinf(a) && gsl_isinf(b)) {
        y = gsl_ran_ugaussian(r);
    } else if (gsl_isinf(a)) {
        y = -ran_left_utruncnormal(r, -b);
    } else if (gsl_isinf(b)) {
        y = ran_left_utruncnormal(r, a);
    } else {
        y = ran_two_utruncnormal(r, a, b);
    }
    return y;
}

canonical_original_code:
double ran_utruncnormal(struct gsl_rng *r, double a, double b)
{
    double y;
    if (gsl_isinf(a) && gsl_isinf(b)) {
        y = gsl_ran_ugaussian(r);
    } else if (gsl_isinf(a)) {
        y = -ran_left_utruncnormal(r, -b);
    } else if (gsl_isinf(b)) {
        y = ran_left_utruncnormal(r, a);
    } else {
        y = ran_two_utruncnormal(r, a, b);
    }
    return y;
}


decompiled_code:
double __fastcall ran_truncnormal(double a1, double a2, double a3, double a4)
{
double v4; // xmm0_8

v4 = (a1 - a3) / a4;
ran_utruncnormal(v4, (a2 - a3) / a4);
return v4 * a4 + a3;
}

canonical_decompiled_code:
double __fastcall func19(double a1, double a2, double a3, double a4)
{
double v4; // xmm0_8

v4 = (a1 - a3) / a4;
func18(v4, (a2 - a3) / a4);
return v4 * a4 + a3;
}

original_code:
double
ran_truncnormal(const gsl_rng *r, double a, double b, double m, double s)
{
    double y;
    double am = (a - m) / s;
    double bm = (b - m) / s;
    y = ran_utruncnormal(r, am, bm);
    return s * y + m;
}

canonical_original_code:
double ran_truncnormal(struct gsl_rng *r, double a, double b, double m, double s)
{
    double y;
    double am = (a - m) / s;
    double bm = (b - m) / s;
    y = ran_utruncnormal(r, am, bm);
    return s * y + m;
}

variable_types: m double

variable_types: s double

variable_types: am double

variable_types: bm double