main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
char *v4; // rbp
int v5; // eax
char *v6; // rbp
size_t j; // rbx
const unsigned __int16 **v8; // rax
__int64 v9; // r12
char *v11; // rbx
const __int32_t **v12; // r13
int v13; // eax
int v14; // er12
const __int32_t **v15; // r13
int v16; // eax
int i; // [rsp+4h] [rbp-5A4h]
char v18[688]; // [rsp+10h] [rbp-598h] BYREF
char v19[26]; // [rsp+2C0h] [rbp-2E8h] BYREF
char v20[676]; // [rsp+2DAh] [rbp-2CEh] BYREF
char v21; // [rsp+57Eh] [rbp-2Ah] BYREF

gen_table((__int64)v19, (__int64)v18);
v4 = 0LL;
for ( i = 0; ; i = 1 )
{
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "dp:th");
if ( v5 == -1 )
{
if ( !v4 )
usage();
printf("pass: %s\n", v4);
while ( 1 )
{
v14 = getchar();
if ( v14 == -1 )
return 0;
if ( !i )
break;
if ( ((*__ctype_b_loc())[v14] & 0x400) == 0 )
goto LABEL_22;
v12 = __ctype_tolower_loc();
v13 = tolower(v14);
putchar(v20[26 * (*v12)[v4[v3++]] - 3333 + v13]);
LABEL_23:
if ( v3 > strlen(v4) - 1 )
v3 = 0;
}
if ( ((*__ctype_b_loc())[v14] & 0x400) != 0 )
{
v15 = __ctype_tolower_loc();
v16 = tolower(v14);
putchar(v20[26 * (*v15)[v4[v3++]] - 2645 + v16]);
goto LABEL_23;
}
LABEL_22:
putchar(v14);
goto LABEL_23;
}
if ( v5 != 112 )
break;
v4 = strdup(_bss_start);
for ( j = 0LL; strlen(v4) > j; ++j )
{
v8 = __ctype_b_loc();
v9 = v4[j];
if ( ((*v8)[v9] & 0x400) == 0 )
{
fwrite("wrong charater in password!\n", 1uLL, 0x1CuLL, stderr);
return 1;
}
v4[j] = (*__ctype_tolower_loc())[v9];
}
}
if ( v5 == 116 )
break;
if ( v5 != 100 )
usage();
}
v6 = v20;
do
{
v11 = v6 - 26;
do
printf("%c ", (unsigned int)*v11++);
while ( v6 != v11 );
putchar(10);
v6 += 26;
}
while ( v6 != &v21 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
char *v4; // rbp
int v5; // eax
char *v6; // rbp
size_t j; // rbx
const unsigned __int16 **v8; // rax
__int64 v9; // r12
char *v11; // rbx
const __int32_t **v12; // r13
int v13; // eax
int v14; // er12
const __int32_t **v15; // r13
int v16; // eax
int i; // [rsp+4h] [rbp-5A4h]
char v18[688]; // [rsp+10h] [rbp-598h] BYREF
char v19[26]; // [rsp+2C0h] [rbp-2E8h] BYREF
char v20[676]; // [rsp+2DAh] [rbp-2CEh] BYREF
char v21; // [rsp+57Eh] [rbp-2Ah] BYREF

func7((__int64)v19, (__int64)v18);
v4 = 0LL;
for ( i = 0; ; i = 1 )
{
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "dp:th");
if ( v5 == -1 )
{
if ( !v4 )
func8();
printf("pass: %s\n", v4);
while ( 1 )
{
v14 = getchar();
if ( v14 == -1 )
return 0;
if ( !i )
break;
if ( ((*__ctype_b_loc())[v14] & 0x400) == 0 )
goto LABEL_22;
v12 = __ctype_tolower_loc();
v13 = tolower(v14);
putchar(v20[26 * (*v12)[v4[v3++]] - 3333 + v13]);
LABEL_23:
if ( v3 > strlen(v4) - 1 )
v3 = 0;
}
if ( ((*__ctype_b_loc())[v14] & 0x400) != 0 )
{
v15 = __ctype_tolower_loc();
v16 = tolower(v14);
putchar(v20[26 * (*v15)[v4[v3++]] - 2645 + v16]);
goto LABEL_23;
}
LABEL_22:
putchar(v14);
goto LABEL_23;
}
if ( v5 != 112 )
break;
v4 = strdup(_bss_start);
for ( j = 0LL; strlen(v4) > j; ++j )
{
v8 = __ctype_b_loc();
v9 = v4[j];
if ( ((*v8)[v9] & 0x400) == 0 )
{
fwrite("wrong charater in password!\n", 1uLL, 0x1CuLL, stderr);
return 1;
}
v4[j] = (*__ctype_tolower_loc())[v9];
}
}
if ( v5 == 116 )
break;
if ( v5 != 100 )
func8();
}
v6 = v20;
do
{
v11 = v6 - 26;
do
printf("%c ", (unsigned int)*v11++);
while ( v6 != v11 );
putchar(10);
v6 += 26;
}
while ( v6 != &v21 );
return 0;
}

original_code:
int
main(int argc, char**argv)
{
 int c, p, decode_flag = 0, ch;
 char *password = ((void *)0);
 char table[26][26], rtable[26][26];
 gen_table(table, rtable);
 while ((ch = getopt(argc, argv, "dp:th")) != -1) {
  switch (ch) {
  case 'd':
   decode_flag = 1;
   break;
  case 'p':
   password = strdup(optarg);
   for (int i = 0; i < strlen(password); i++) {
    if (((*__ctype_b_loc ())[(int) ((password[i]))] & (unsigned short int) _ISalpha)) {
     password[i] = tolower(password[i]);
    } else {
     fprintf(stderr,
         "wrong charater in password!\n");
     return 1;
    }
   }
   break;
  case 't':
   for (int y = 0; y < 26; y++) {
    for (int x = 0; x < 26; x++)
     printf("%c ", table[y][x]);
    printf("\n");
   }
   return 0;
  case 'h':
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (password == ((void *)0))
  usage();
 printf("pass: %s\n", password);
 while ((c = getchar()) != (-1)) {
  if (!decode_flag && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha)) {
   c = table[tolower(password[p]) - 'a'][tolower(c) - 'a'];
   printf("%c", c);
   p++;
  } else if (decode_flag && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha)) {
   c = rtable[tolower(password[p]) - 'a'][tolower(c) -'a'];
   printf("%c", c);
   p++;
  } else {
   putchar(c);
  }
  if (p > strlen(password) - 1)
   p = 0;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int c; int p; int decode_flag = 0; int ch;
 char *password = ((void *)0);
 char table[26][26]; char rtable[26][26];
 gen_table(table, rtable);
 while ((ch = getopt(argc, argv, "dp:th")) != -1) {
  switch (ch) {
  case 'd':
   decode_flag = 1;
   break;
  case 'p':
   password = strdup(optarg);
   for (int i = 0; i < strlen(password); i++) {
    if (((*__ctype_b_loc ())[(int) ((password[i]))] & (unsigned short) _ISalpha)) {
     password[i] = tolower(password[i]);
    } else {
     fprintf(stderr,
         "wrong charater in password!\n");
     return 1;
    }
   }
   break;
  case 't':
   for (int y = 0; y < 26; y++) {
    for (int x = 0; x < 26; x++)
     printf("%c ", table[y][x]);
    printf("\n");
   }
   return 0;
  case 'h':
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (password == ((void *)0))
  usage();
 printf("pass: %s\n", password);
 while ((c = getchar()) != (-1)) {
  if (!decode_flag && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha)) {
   c = table[tolower(password[p]) - 'a'][tolower(c) - 'a'];
   printf("%c", c);
   p++;
  } else if (decode_flag && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha)) {
   c = rtable[tolower(password[p]) - 'a'][tolower(c) -'a'];
   printf("%c", c);
   p++;
  } else {
   putchar(c);
  }
  if (p > strlen(password) - 1)
   p = 0;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: p int

variable_types: ch int

variable_types:
password
char *


usage

repo: younix/pie

decompiled_code:
void __noreturn usage()
{
fwrite(
"pie [OPTIONS] NUM ...\n"
"\n"
"OPTIONS:\n"
"\t-t TITLE\tTitle of the chart.\n"
"\t-d DESCRIPTION\tDescription of the chart.\n"
"\t-o FILE\t\tOutput file for SVG data.\n",
1uLL,
0x8CuLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
fwrite(
"pie [OPTIONS] NUM ...\n"
"\n"
"OPTIONS:\n"
"\t-t TITLE\tTitle of the chart.\n"
"\t-d DESCRIPTION\tDescription of the chart.\n"
"\t-o FILE\t\tOutput file for SVG data.\n",
1uLL,
0x8CuLL,
stderr);
exit(1);
}

original_code:
void
usage(void)
{
 fprintf(stderr, "pie [OPTIONS] NUM ...\n"
   "\n"
   "OPTIONS:\n"
   "	-t TITLE	Title of the chart.\n"
   "	-d DESCRIPTION	Description of the chart.\n"
   "	-o FILE		Output file for SVG data.\n");
 exit(1);
}

canonical_original_code:
void usage()
{
 fprintf(stderr, "pie [OPTIONS] NUM ...\n"
   "\n"
   "OPTIONS:\n"
   "	-t TITLE	Title of the chart.\n"
   "	-d DESCRIPTION	Description of the chart.\n"
   "	-o FILE		Output file for SVG data.\n");
 exit(1);
}

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebx
int v5; // eax
int v6; // er14
int v7; // eax
__int64 v8; // r14
void *v9; // rsp
double v10; // xmm0_8
const char **v11; // rbx
int *v12; // r12
const char **v13; // r14
int v14; // er13
int v15; // eax
__int64 v16; // r14
double v17; // r12
__int64 v18; // rbx
double v19; // r13
double v20; // xmm6_8
double v21; // xmm2_8
double v22; // xmm3_8
int result; // eax
_BYTE v24[4]; // [rsp+0h] [rbp-100h] BYREF
int v25; // [rsp+4h] [rbp-FCh]
double v26; // [rsp+8h] [rbp-F8h]
double v27; // [rsp+10h] [rbp-F0h]
double v28; // [rsp+18h] [rbp-E8h]
double v29; // [rsp+20h] [rbp-E0h]
double v30; // [rsp+28h] [rbp-D8h]
double v31; // [rsp+30h] [rbp-D0h]
double v32; // [rsp+38h] [rbp-C8h]
double cosx; // [rsp+40h] [rbp-C0h] BYREF
double sinx; // [rsp+48h] [rbp-B8h] BYREF
__int64 v35[22]; // [rsp+50h] [rbp-B0h]

v35[0] = (__int64)"#8ae234";
v35[1] = (__int64)"#ef2929";
v35[2] = (__int64)"#729fcf";
v35[3] = (__int64)"#ad7fa8";
v35[4] = (__int64)"#fcaf3e";
v35[5] = (__int64)"#4e9a06";
v35[6] = (__int64)"#a40000";
v35[7] = (__int64)"#204a87";
v35[8] = (__int64)"#5c3566";
v35[9] = (__int64)"#ce5c00";
v35[10] = (__int64)"#73d216";
v35[11] = (__int64)"#cc0000";
v35[12] = (__int64)"#3465a4";
v35[13] = (__int64)"#75507b";
v35[14] = (__int64)"#f57900";
v31 = COERCE_DOUBLE("Picture of a pie chart");
v32 = COERCE_DOUBLE("Pie chart");
v3 = 400;
v4 = 400;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "o:t:d:w:h:");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'd':
v31 = COERCE_DOUBLE(strdup(optarg));
break;
case 'h':
v3 = strtol(optarg, 0LL, 10);
break;
case 'o':
v5 = open(optarg, 65, 438LL);
v6 = v5;
if ( v5 == -1 )
{
perror(optarg);
exit(1);
}
dup2(v5, 1);
close(v6);
break;
case 't':
v32 = COERCE_DOUBLE(strdup(optarg));
break;
case 'w':
v4 = strtol(optarg, 0LL, 10);
break;
default:
usage();
return result;
}
}
v25 = argc - optind;
v8 = optind;
if ( argc - optind > 15 )
{
fprintf(stderr, "Too mutch data. Maximum of %d numbers are posibile.\n", 15LL);
exit(1);
}
if ( v25 <= 0 )
{
fwrite("no numbers found.\n", 1uLL, 0x12uLL, stderr);
usage();
}
v9 = alloca(4LL * v25);
v10 = (double)(v4 / 2);
v29 = v10;
v28 = (double)(v3 / 2);
if ( v4 / 2 >= v3 / 2 )
v10 = (double)(v3 / 2);
v30 = v10 - 10.0;
if ( v10 - 10.0 < 5.0 )
{
fwrite("Your chart is too small to draw.\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
printf(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
"<svg xmlns:svg=\"http://www.w3.org/2000/svg\"\n"
" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.0\"\n"
" width=\"%d\" height=\"%d\" id=\"svg2\">\n"
"\t<title>%s</title>\n"
"\t<desc>%s</desc>\n",
(unsigned int)v4,
(unsigned int)v3,
*(const char **)&v32,
*(const char **)&v31);
v11 = &argv[v8];
v12 = (int *)v24;
v13 = &(&argv[v25 - 1])[v8 + 1];
v14 = 0;
do
{
v15 = strtol(*v11, 0LL, 10);
*v12 = v15;
if ( v15 < 0 )
{
fwrite("negative input number\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
v14 += v15;
++v11;
++v12;
}
while ( v11 != v13 );
v27 = (double)v14 / 360.0;
v26 = (double)v14 * 0.5;
v16 = (unsigned int)v25;
v17 = v30;
v18 = 0LL;
v32 = 0.0;
v19 = 0.0;
do
{
v20 = (double)*(int *)&v24[4 * v18];
v31 = v20;
v32 = v20 / v27 + v32;
sincos(v32 * 0.0174532925199433, &sinx, &cosx);
v21 = v17;
v17 = v30 * cosx;
v22 = v19;
v19 = v30 * sinx;
printf(
"\t<path d=\"M%f,%f L%f,%f A%f,%f 0 %d,1 %f,%f z\" fill=\"%s\" stroke=\"#FFFFFF\" stroke-width=\"3\" fill-opacity=\""
"1.0\" stroke-linejoin=\"round\" />\n",
v29,
v28,
v21 + v29,
v22 + v28,
v30,
v30,
v31 > v26,
v30 * cosx + v29,
v30 * sinx + v28,
(const char *)v35[v18++]);
}
while ( v16 != v18 );
puts("</svg>");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebx
int v5; // eax
int v6; // er14
int v7; // eax
__int64 v8; // r14
void *v9; // rsp
double v10; // xmm0_8
const char **v11; // rbx
int *v12; // r12
const char **v13; // r14
int v14; // er13
int v15; // eax
__int64 v16; // r14
double v17; // r12
__int64 v18; // rbx
double v19; // r13
double v20; // xmm6_8
double v21; // xmm2_8
double v22; // xmm3_8
int result; // eax
_BYTE v24[4]; // [rsp+0h] [rbp-100h] BYREF
int v25; // [rsp+4h] [rbp-FCh]
double v26; // [rsp+8h] [rbp-F8h]
double v27; // [rsp+10h] [rbp-F0h]
double v28; // [rsp+18h] [rbp-E8h]
double v29; // [rsp+20h] [rbp-E0h]
double v30; // [rsp+28h] [rbp-D8h]
double v31; // [rsp+30h] [rbp-D0h]
double v32; // [rsp+38h] [rbp-C8h]
double cosx; // [rsp+40h] [rbp-C0h] BYREF
double sinx; // [rsp+48h] [rbp-B8h] BYREF
__int64 v35[22]; // [rsp+50h] [rbp-B0h]

v35[0] = (__int64)"#8ae234";
v35[1] = (__int64)"#ef2929";
v35[2] = (__int64)"#729fcf";
v35[3] = (__int64)"#ad7fa8";
v35[4] = (__int64)"#fcaf3e";
v35[5] = (__int64)"#4e9a06";
v35[6] = (__int64)"#a40000";
v35[7] = (__int64)"#204a87";
v35[8] = (__int64)"#5c3566";
v35[9] = (__int64)"#ce5c00";
v35[10] = (__int64)"#73d216";
v35[11] = (__int64)"#cc0000";
v35[12] = (__int64)"#3465a4";
v35[13] = (__int64)"#75507b";
v35[14] = (__int64)"#f57900";
v31 = COERCE_DOUBLE("Picture of a pie chart");
v32 = COERCE_DOUBLE("Pie chart");
v3 = 400;
v4 = 400;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "o:t:d:w:h:");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'd':
v31 = COERCE_DOUBLE(strdup(optarg));
break;
case 'h':
v3 = strtol(optarg, 0LL, 10);
break;
case 'o':
v5 = open(optarg, 65, 438LL);
v6 = v5;
if ( v5 == -1 )
{
perror(optarg);
exit(1);
}
dup2(v5, 1);
close(v6);
break;
case 't':
v32 = COERCE_DOUBLE(strdup(optarg));
break;
case 'w':
v4 = strtol(optarg, 0LL, 10);
break;
default:
func7();
return result;
}
}
v25 = argc - optind;
v8 = optind;
if ( argc - optind > 15 )
{
fprintf(stderr, "Too mutch data. Maximum of %d numbers are posibile.\n", 15LL);
exit(1);
}
if ( v25 <= 0 )
{
fwrite("no numbers found.\n", 1uLL, 0x12uLL, stderr);
func7();
}
v9 = alloca(4LL * v25);
v10 = (double)(v4 / 2);
v29 = v10;
v28 = (double)(v3 / 2);
if ( v4 / 2 >= v3 / 2 )
v10 = (double)(v3 / 2);
v30 = v10 - 10.0;
if ( v10 - 10.0 < 5.0 )
{
fwrite("Your chart is too small to draw.\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
printf(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
"<svg xmlns:svg=\"http://www.w3.org/2000/svg\"\n"
" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.0\"\n"
" width=\"%d\" height=\"%d\" id=\"svg2\">\n"
"\t<title>%s</title>\n"
"\t<desc>%s</desc>\n",
(unsigned int)v4,
(unsigned int)v3,
*(const char **)&v32,
*(const char **)&v31);
v11 = &argv[v8];
v12 = (int *)v24;
v13 = &(&argv[v25 - 1])[v8 + 1];
v14 = 0;
do
{
v15 = strtol(*v11, 0LL, 10);
*v12 = v15;
if ( v15 < 0 )
{
fwrite("negative input number\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
v14 += v15;
++v11;
++v12;
}
while ( v11 != v13 );
v27 = (double)v14 / 360.0;
v26 = (double)v14 * 0.5;
v16 = (unsigned int)v25;
v17 = v30;
v18 = 0LL;
v32 = 0.0;
v19 = 0.0;
do
{
v20 = (double)*(int *)&v24[4 * v18];
v31 = v20;
v32 = v20 / v27 + v32;
sincos(v32 * 0.0174532925199433, &sinx, &cosx);
v21 = v17;
v17 = v30 * cosx;
v22 = v19;
v19 = v30 * sinx;
printf(
"\t<path d=\"M%f,%f L%f,%f A%f,%f 0 %d,1 %f,%f z\" fill=\"%s\" stroke=\"#FFFFFF\" stroke-width=\"3\" fill-opacity=\""
"1.0\" stroke-linejoin=\"round\" />\n",
v29,
v28,
v21 + v29,
v22 + v28,
v30,
v30,
v31 > v26,
v30 * cosx + v29,
v30 * sinx + v28,
(const char *)v35[v18++]);
}
while ( v16 != v18 );
puts("</svg>");
return 0;
}

original_code:
int
main(int argc, char **argv)
{
 char *color[] = {"#8ae234", "#ef2929", "#729fcf", "#ad7fa8", "#fcaf3e",
    "#4e9a06", "#a40000", "#204a87", "#5c3566", "#ce5c00",
    "#73d216", "#cc0000", "#3465a4", "#75507b", "#f57900"};
 int max_colors = sizeof(color) / sizeof(color[0]);
 int width = 400;
 int height = 400;
 char *title = "Pie chart";
 char *desc = "Picture of a pie chart";
 int ch, fd;
 while ((ch = getopt(argc, argv, "o:t:d:w:h:")) != -1) {
  switch (ch) {
  case 'o':
   if ((fd = open(optarg, 01|0100, 0400|0200
    |(0400 >> 3)|(0200 >> 3)|((0400 >> 3) >> 3)|((0200 >> 3) >> 3))) == -1) {
    perror(optarg);
    exit(1);
   }
   dup2(fd, 1);
   close(fd);
   break;
  case 't':
   title = strdup(optarg);
   break;
  case 'd':
   desc = strdup(optarg);
   break;
  case 'w':
   width = strtol(optarg, ((void *)0), 10);
   break;
  case 'h':
   height = strtol(optarg, ((void *)0), 10);
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc > max_colors) {
  fprintf(stderr, "Too mutch data. "
   "Maximum of %d numbers are posibile.\n", max_colors);
  exit(1);
 } else if (argc < 1) {
  fprintf(stderr, "no numbers found.\n");
  usage();
 }
 int data[argc];
 double centerx = width / 2;
 double centery = height / 2;
 int laf = 0;
 double radius = ((centerx) < (centery) ? (centerx) : (centery)) - 10;
 if (radius < 5.0) {
  fprintf(stderr, "Your chart is too small to draw.\n");
  exit(1);
 }
 printf( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
  "<svg xmlns:svg=\"http://www.w3.org/2000/svg\"\n"
  "    xmlns=\"http://www.w3.org/2000/svg\" version=\"1.0\"\n"
  "    width=\"%d\" height=\"%d\" id=\"svg2\">\n"
  "\t<title>%s</title>\n"
  "\t<desc>%s</desc>\n",
  width, height, title, desc);
 int max = argc;
 int sum = 0;
 for (int i = 0; i < max; i++) {
  data[i] = strtol(argv[i], ((void *)0), 10);
  if (data[i] < 0) {
   fprintf(stderr, "negative input number\n");
   exit(1);
  }
  sum += data[i];
 }
 double deg = sum / 360.0;
 double jung = sum / 2.0;
 double dx = radius;
 double dy = 0.0;
 double oldangle = 0.0;
 for (int i = 0; i < max; i++) {
  double angle = oldangle + data[i] / deg;
  double x = cos(((3.14159265358979323846 / 180.0) * (angle))) * radius;
  double y = sin(((3.14159265358979323846 / 180.0) * (angle))) * radius;
  if (data[i] > jung)
   laf = 1;
  else
   laf = 0;
  double ax = centerx + x;
  double ay = centery + y;
  double adx = centerx + dx;
  double ady = centery + dy;
  printf( "\t<path d=\"M%f,%f"
   " L%f,%f"
   " A%f,%f 0 %d,1 %f,%f"
   " z\""
   " fill=\"%s\" stroke=\"#FFFFFF\" stroke-width=\"3\""
   " fill-opacity=\"1.0\" stroke-linejoin=\"round\" />\n",
   centerx, centery, adx, ady, radius, radius, laf, ax, ay,
   color[i]);
  dx = x; dy = y; oldangle = angle;
 }
 printf("</svg>\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *color[] = {"#8ae234", "#ef2929", "#729fcf", "#ad7fa8", "#fcaf3e",
    "#4e9a06", "#a40000", "#204a87", "#5c3566", "#ce5c00",
    "#73d216", "#cc0000", "#3465a4", "#75507b", "#f57900"};
 int max_colors = sizeof(color) / sizeof(color[0]);
 int width = 400;
 int height = 400;
 char *title = "Pie chart";
 char *desc = "Picture of a pie chart";
 int ch; int fd;
 while ((ch = getopt(argc, argv, "o:t:d:w:h:")) != -1) {
  switch (ch) {
  case 'o':
   if ((fd = open(optarg, 01|0100, 0400|0200
    |(0400 >> 3)|(0200 >> 3)|((0400 >> 3) >> 3)|((0200 >> 3) >> 3))) == -1) {
    perror(optarg);
    exit(1);
   }
   dup2(fd, 1);
   close(fd);
   break;
  case 't':
   title = strdup(optarg);
   break;
  case 'd':
   desc = strdup(optarg);
   break;
  case 'w':
   width = strtol(optarg, ((void *)0), 10);
   break;
  case 'h':
   height = strtol(optarg, ((void *)0), 10);
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc > max_colors) {
  fprintf(stderr, "Too mutch data. "
   "Maximum of %d numbers are posibile.\n", max_colors);
  exit(1);
 } else if (argc < 1) {
  fprintf(stderr, "no numbers found.\n");
  usage();
 }
 int data[-1];
 double centerx = width / 2;
 double centery = height / 2;
 int laf = 0;
 double radius = ((centerx) < (centery) ? (centerx) : (centery)) - 10;
 if (radius < 5.0) {
  fprintf(stderr, "Your chart is too small to draw.\n");
  exit(1);
 }
 printf( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
  "<svg xmlns:svg=\"http://www.w3.org/2000/svg\"\n"
  "    xmlns=\"http://www.w3.org/2000/svg\" version=\"1.0\"\n"
  "    width=\"%d\" height=\"%d\" id=\"svg2\">\n"
  "\t<title>%s</title>\n"
  "\t<desc>%s</desc>\n",
  width, height, title, desc);
 int max = argc;
 int sum = 0;
 for (int i = 0; i < max; i++) {
  data[i] = strtol(argv[i], ((void *)0), 10);
  if (data[i] < 0) {
   fprintf(stderr, "negative input number\n");
   exit(1);
  }
  sum += data[i];
 }
 double deg = sum / 360.0;
 double jung = sum / 2.0;
 double dx = radius;
 double dy = 0.0;
 double oldangle = 0.0;
 for (int i = 0; i < max; i++) {
  double angle = oldangle + data[i] / deg;
  double x = cos(((3.14159265358979323846 / 180.0) * (angle))) * radius;
  double y = sin(((3.14159265358979323846 / 180.0) * (angle))) * radius;
  if (data[i] > jung)
   laf = 1;
  else
   laf = 0;
  double ax = centerx + x;
  double ay = centery + y;
  double adx = centerx + dx;
  double ady = centery + dy;
  printf( "\t<path d=\"M%f,%f"
   " L%f,%f"
   " A%f,%f 0 %d,1 %f,%f"
   " z\""
   " fill=\"%s\" stroke=\"#FFFFFF\" stroke-width=\"3\""
   " fill-opacity=\"1.0\" stroke-linejoin=\"round\" />\n",
   centerx, centery, adx, ady, radius, radius, laf, ax, ay,
   color[i]);
  dx = x; dy = y; oldangle = angle;
 }
 printf("</svg>\n");
 return 0;
}

variable_types:
color
char *[]

variable_types: width int

variable_types: height int

variable_types:
title
char *

variable_types:
desc
char *

variable_types: fd int

variable_types:
data
int [-1]

variable_types: centerx double

variable_types: centery double

variable_types: laf int

variable_types: radius double

variable_types: max int

variable_types: sum int

variable_types: i int

variable_types: deg double

variable_types: jung double

variable_types: dx double

variable_types: dy double

variable_types: oldangle double

variable_types: angle double

variable_types: x double

variable_types: y double

variable_types: ax double

variable_types: ay double

variable_types: adx double

variable_types: ady double

return_type: int


isshow

repo: younix/sj

decompiled_code:
__int64 __fastcall isshow(const char *a1)
{
__int64 v2; // rcx
bool v3; // dl
bool v4; // cf
bool v5; // zf
const char *v6; // rdi
const char *v7; // rsi

LODWORD(v2) = 1;
if ( strcmp(a1, "away") )
{
LODWORD(v2) = 1;
if ( strcmp(a1, "chat") )
{
v3 = strcmp(a1, "dnd") != 0;
LODWORD(v2) = 1;
v4 = 0;
v5 = !v3;
if ( v3 )
{
v6 = "xa";
v2 = 3LL;
v7 = a1;
do
{
if ( !v2 )
break;
v4 = *v7 < (unsigned int)*v6;
v5 = *v7++ == *v6++;
--v2;
}
while ( v5 );
LOBYTE(v2) = (!v4 && !v5) == v4;
}
}
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
__int64 v2; // rcx
bool v3; // dl
bool v4; // cf
bool v5; // zf
const char *v6; // rdi
const char *v7; // rsi

LODWORD(v2) = 1;
if ( strcmp(a1, "away") )
{
LODWORD(v2) = 1;
if ( strcmp(a1, "chat") )
{
v3 = strcmp(a1, "dnd") != 0;
LODWORD(v2) = 1;
v4 = 0;
v5 = !v3;
if ( v3 )
{
v6 = "xa";
v2 = 3LL;
v7 = a1;
do
{
if ( !v2 )
break;
v4 = *v7 < (unsigned int)*v6;
v5 = *v7++ == *v6++;
--v2;
}
while ( v5 );
LOBYTE(v2) = (!v4 && !v5) == v4;
}
}
}
return (unsigned int)v2;
}

original_code:
_Bool
isshow(const char *show)
{
 if (strcmp(show, "away") == 0) return 1;
 if (strcmp(show, "chat") == 0) return 1;
 if (strcmp(show, "dnd") == 0) return 1;
 if (strcmp(show, "xa") == 0) return 1;
 return 0;
}

canonical_original_code:
_Bool isshow(char *show)
{
 if (strcmp(show, "away") == 0) return 1;
 if (strcmp(show, "chat") == 0) return 1;
 if (strcmp(show, "dnd") == 0) return 1;
 if (strcmp(show, "xa") == 0) return 1;
 return 0;
}

variable_types:
show
char *


istype

decompiled_code:
__int64 __fastcall istype(const char *a1)
{
__int64 v2; // rcx
bool v3; // dl
bool v4; // cf
bool v5; // zf
const char *v6; // rdi
const char *v7; // rsi

LODWORD(v2) = 1;
if ( strcmp(a1, "subscribe") )
{
LODWORD(v2) = 1;
if ( strcmp(a1, "subscribed") )
{
LODWORD(v2) = 1;
if ( strcmp(a1, "unavailable") )
{
v3 = strcmp(a1, "unsubscribe") != 0;
LODWORD(v2) = 1;
v4 = 0;
v5 = !v3;
if ( v3 )
{
v6 = (const char *)&unk_40202D;
v2 = 13LL;
v7 = a1;
do
{
if ( !v2 )
break;
v4 = *v7 < (unsigned int)*v6;
v5 = *v7++ == *v6++;
--v2;
}
while ( v5 );
LOBYTE(v2) = (!v4 && !v5) == v4;
}
}
}
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
__int64 v2; // rcx
bool v3; // dl
bool v4; // cf
bool v5; // zf
const char *v6; // rdi
const char *v7; // rsi

LODWORD(v2) = 1;
if ( strcmp(a1, "subscribe") )
{
LODWORD(v2) = 1;
if ( strcmp(a1, "subscribed") )
{
LODWORD(v2) = 1;
if ( strcmp(a1, "unavailable") )
{
v3 = strcmp(a1, "unsubscribe") != 0;
LODWORD(v2) = 1;
v4 = 0;
v5 = !v3;
if ( v3 )
{
v6 = (const char *)&unk_40202D;
v2 = 13LL;
v7 = a1;
do
{
if ( !v2 )
break;
v4 = *v7 < (unsigned int)*v6;
v5 = *v7++ == *v6++;
--v2;
}
while ( v5 );
LOBYTE(v2) = (!v4 && !v5) == v4;
}
}
}
}
return (unsigned int)v2;
}

original_code:
_Bool
istype(const char *type)
{
 if (strcmp(type, "subscribe") == 0) return 1;
 if (strcmp(type, "subscribed") == 0) return 1;
 if (strcmp(type, "unavailable") == 0) return 1;
 if (strcmp(type, "unsubscribe") == 0) return 1;
 if (strcmp(type, "unsubscribed") == 0) return 1;
 return 0;
}

canonical_original_code:
_Bool istype(char *type)
{
 if (strcmp(type, "subscribe") == 0) return 1;
 if (strcmp(type, "subscribed") == 0) return 1;
 if (strcmp(type, "unavailable") == 0) return 1;
 if (strcmp(type, "unsubscribe") == 0) return 1;
 if (strcmp(type, "unsubscribed") == 0) return 1;
 return 0;
}

variable_types:
type
char *


usage

decompiled_code:
void __noreturn usage()
{
fwrite(
"presence [-d <dir>] [-t <to>] [-s <show>] [-p <prio>] [type]\n"
" prio: -128..127\n"
" show: away|chat|dnd|xa\n"
" type: subscribe|subscribed|unavailable|unsubscribe|unsubscribed\n",
1uLL,
0xAAuLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func9()
{
fwrite(
"presence [-d <dir>] [-t <to>] [-s <show>] [-p <prio>] [type]\n"
" prio: -128..127\n"
" show: away|chat|dnd|xa\n"
" type: subscribe|subscribed|unavailable|unsubscribe|unsubscribed\n",
1uLL,
0xAAuLL,
stderr);
exit(1);
}

original_code:
void
usage(void)
{
 fprintf(stderr,
  "presence [-d <dir>] [-t <to>] [-s <show>] [-p <prio>] [type]\n"
  "  prio: -128..127\n"
  "  show: away|chat|dnd|xa\n"
  "  type: subscribe|subscribed|unavailable|unsubscribe|"
      "unsubscribed\n");
 exit(1);
}

canonical_original_code:
void usage()
{
 fprintf(stderr,
  "presence [-d <dir>] [-t <to>] [-s <show>] [-p <prio>] [type]\n"
  "  prio: -128..127\n"
  "  show: away|chat|dnd|xa\n"
  "  type: subscribe|subscribed|unavailable|unsubscribe|"
      "unsubscribed\n");
 exit(1);
}


repo: younix/xii

decompiled_code:
void __noreturn usage()
{
fwrite("xii [-t <title>] [-e <window>] [-d <dir>] [-o <out>] [-i <in>]\n", 1uLL, 0x3FuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func11()
{
fwrite("xii [-t <title>] [-e <window>] [-d <dir>] [-o <out>] [-i <in>]\n", 1uLL, 0x3FuLL, stderr);
exit(1);
}

original_code:
void
usage(void)
{
 fprintf(stderr,
     "xii [-t <title>] [-e <window>] [-d <dir>] [-o <out>] [-i <in>]\n");
 exit(1);
}

canonical_original_code:
void usage()
{
 fprintf(stderr,
     "xii [-t <title>] [-e <window>] [-d <dir>] [-o <out>] [-i <in>]\n");
 exit(1);
}


readInstruction

decompiled_code:
__int64 __fastcall readInstruction(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, unsigned __int16 a8)
{
__int64 v8; // rax
unsigned int v9; // esi

v8 = 0LL;
v9 = 0;
do
{
v9 |= *(unsigned __int8 *)(a7 + a8 + v8) << (8 * v8);
++v8;
}
while ( v8 != 4 );
return v9;
}

original_code:
uint32_t readInstruction(state_t st) {
 uint32_t res = 0;
 for (int i = 0; i < 4; i++) {
  res |= st.mem[st.pc + i] << (8 * i);
 }
 return res;
}

canonical_original_code:
unsigned int readInstruction(struct state st) {
 unsigned int res = 0;
 for (int i = 0; i < 4; i++) {
  res |= st.mem[st.pc + i] << (8 * i);
 }
 return res;
}

variable_types: struct state { unsigned char *mem; unsigned short pc; int reg[32]; int halt; }

variable_types:
res
unsigned int

return_type: unsigned int


getOpcode

decompiled_code:
__int64 __fastcall getOpcode(unsigned int a1)
{
return a1 >> 26;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
return a1 >> 26;
}

original_code:
uint8_t getOpcode(uint32_t inst) {
 uint32_t mask = 0xFC000000;
 uint32_t res = inst & mask;
 return res >> 26;
}

canonical_original_code:
unsigned char getOpcode(unsigned int inst) {
 unsigned int mask = 0xFC000000;
 unsigned int res = inst & mask;
 return res >> 26;
}

variable_types:
inst
unsigned int

variable_types:
mask
unsigned int

return_type: unsigned char


getAddr

decompiled_code:
__int64 __fastcall getAddr(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
return a1;
}

original_code:
uint16_t getAddr(uint32_t inst) {
 uint32_t mask = 0x03FFFFFF;
 return mask & inst;
}

canonical_original_code:
unsigned short getAddr(unsigned int inst) {
 unsigned int mask = 0x03FFFFFF;
 return mask & inst;
}

return_type: unsigned short


decompiled_code:
__int64 __fastcall getR1(unsigned int a1)
{
return (a1 >> 21) & 0x1F;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
return (a1 >> 21) & 0x1F;
}

original_code:
uint8_t getR1(uint32_t inst) {
 uint32_t mask = 0x03E00000;
 return (inst & mask) >> 21;
}

canonical_original_code:
unsigned char getR1(unsigned int inst) {
 unsigned int mask = 0x03E00000;
 return (inst & mask) >> 21;
}


decompiled_code:
__int64 __fastcall getR2(unsigned int a1)
{
return HIWORD(a1) & 0x1F;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
return HIWORD(a1) & 0x1F;
}

original_code:
uint8_t getR2(uint32_t inst) {
 uint32_t mask = 0x001F0000;
 return (inst & mask) >> 16;
}

canonical_original_code:
unsigned char getR2(unsigned int inst) {
 unsigned int mask = 0x001F0000;
 return (inst & mask) >> 16;
}


decompiled_code:
__int64 __fastcall getR3(unsigned __int16 a1)
{
return a1 >> 11;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int16 a1)
{
return a1 >> 11;
}

original_code:
uint8_t getR3(uint32_t inst) {
 uint32_t mask = 0x0000F800;
 return (inst & mask) >> 11;
}

canonical_original_code:
unsigned char getR3(unsigned int inst) {
 unsigned int mask = 0x0000F800;
 return (inst & mask) >> 11;
}


getImm

decompiled_code:
__int64 __fastcall getImm(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1)
{
return a1;
}

original_code:
uint16_t getImm(uint32_t inst) {
 uint32_t mask = 0x0000FFFF;
 return (inst & mask);
}

canonical_original_code:
unsigned short getImm(unsigned int inst) {
 unsigned int mask = 0x0000FFFF;
 return (inst & mask);
}


signExtension

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

result = a1;
if ( (a1 & 0x8000u) != 0 )
result = a1 | 0xFFFF0000;
return result;
}

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

result = a1;
if ( (a1 & 0x8000u) != 0 )
result = a1 | 0xFFFF0000;
return result;
}

original_code:
int32_t signExtension(uint16_t val) {
 if (0x00008000 & val) {
  return 0xFFFF0000 | val;
 } else {
  return val;
 }
}

canonical_original_code:
int signExtension(unsigned short val) {
 if (0x00008000 & val) {
  return 0xFFFF0000 | val;
 } else {
  return val;
 }
}

variable_types:
val
unsigned short


printReg

decompiled_code:
int __fastcall printReg(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, __int64 a8)
{
__int64 i; // rbx
int result; // eax

fprintf(stderr, "PC: %i\n\n", (unsigned __int16)a8);
for ( i = 0LL; i != 32; ++i )
result = fprintf(stderr, "R[%i]: %i\n", (unsigned int)i, *((unsigned int *)&a8 + i + 1));
return result;
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, __int64 a8)
{
__int64 i; // rbx
int result; // eax

fprintf(stderr, "PC: %i\n\n", (unsigned __int16)a8);
for ( i = 0LL; i != 32; ++i )
result = fprintf(stderr, "R[%i]: %i\n", (unsigned int)i, *((unsigned int *)&a8 + i + 1));
return result;
}

original_code:
void printReg(state_t st) {
 fprintf(stderr, "PC: %i\n\n", st.pc);
 for (int i = 0; i < 32; i++) {
  fprintf(stderr, "R[%i]: %i\n", i, st.reg[i]);
 }
}

canonical_original_code:
void printReg(struct state st) {
 fprintf(stderr, "PC: %i\n\n", st.pc);
 for (int i = 0; i < 32; i++) {
  fprintf(stderr, "R[%i]: %i\n", i, st.reg[i]);
 }
}

variable_types: i int

user_defined_types: struct state { unsigned char *mem; unsigned short pc; int reg[32]; int halt; }


repo: yshui/cgrouper

decompiled_code:
__int64 __fastcall cgroup_is_mounted(char *s1)
{
__int64 i; // rbx

for ( i = cgroup_head; i; i = *(_QWORD *)(i + 16) )
{
if ( !strcmp(s1, *(const char **)i) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
__int64 i; // rbx

for ( i = cgroup_head; i; i = *(_QWORD *)(i + 16) )
{
if ( !strcmp(s1, *(const char **)i) )
break;
}
return i;
}

original_code:
static struct cgroup_entry *cgroup_is_mounted(const char *type){
 struct cgroup_entry *entry;
 for ((entry) = ((&cgroup_head)->lh_first); (entry); (entry) = ((entry)->next.le_next))
  if(strcmp(type, entry->type) == 0)
   return entry;
 return ((void *)0);
}

canonical_original_code:
static struct cgroup_entry *cgroup_is_mounted(char *type){
 struct cgroup_entry *entry;
 for ((entry) = ((&cgroup_head)->lh_first); (entry); (entry) = ((entry)->next.le_next))
  if(strcmp(type, entry->type) == 0)
   return entry;
 return ((void *)0);
}

variable_types: struct cgroup_entry { char *type; char *mp; struct { struct cgroup_entry *le_next; struct cgroup_entry **le_prev; } next; } *


decompiled_code:
void __fastcall add_mount(char *s1, char *src)
{
__int64 v2; // rbx
size_t v3; // rax
char *v4; // rax
size_t v5; // rax

v2 = cgroup_head;
if ( cgroup_head )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return;
}
if ( !*(_QWORD *)(v2 + 8) )
{
v3 = strlen(src);
v4 = (char *)malloc(v3 + 1);
*(_QWORD *)(v2 + 8) = v4;
strcpy(v4, src);
v5 = strlen(src);
if ( src[v5 - 1] == 47 )
*(_BYTE *)(*(_QWORD *)(v2 + 8) + v5 - 1) = 0;
}
}
}

canonical_decompiled_code:
void __fastcall func1(char *s1, char *src)
{
__int64 v2; // rbx
size_t v3; // rax
char *v4; // rax
size_t v5; // rax

v2 = cgroup_head;
if ( cgroup_head )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return;
}
if ( !*(_QWORD *)(v2 + 8) )
{
v3 = strlen(src);
v4 = (char *)malloc(v3 + 1);
*(_QWORD *)(v2 + 8) = v4;
strcpy(v4, src);
v5 = strlen(src);
if ( src[v5 - 1] == 47 )
*(_BYTE *)(*(_QWORD *)(v2 + 8) + v5 - 1) = 0;
}
}
}

original_code:
static void add_mount(const char *type, const char *mp){
 struct cgroup_entry *cent;
 for ((cent) = ((&cgroup_head)->lh_first); (cent); (cent) = ((cent)->next.le_next))
  if(strcmp(type, cent->type) == 0){
   if(!cent->mp){
    cent->mp = malloc(strlen(mp)+1);
    strcpy(cent->mp, mp);
    if(mp[strlen(mp)-1] == '/')
     cent->mp[strlen(mp)-1] = 0;
   }
   return;
  }
}

canonical_original_code:
static void add_mount(char *type, char *mp){
 struct cgroup_entry *cent;
 for ((cent) = ((&cgroup_head)->lh_first); (cent); (cent) = ((cent)->next.le_next))
  if(strcmp(type, cent->type) == 0){
   if(!cent->mp){
    cent->mp = malloc(strlen(mp)+1);
    strcpy(cent->mp, mp);
    if(mp[strlen(mp)-1] == '/')
     cent->mp[strlen(mp)-1] = 0;
   }
   return;
  }
}

variable_types:
mp
char *

user_defined_types: struct cgroup_entry { char *type; char *mp; struct { struct cgroup_entry *le_next; struct cgroup_entry **le_prev; } next; }


decompiled_code:
__int64 __fastcall option_contain_cgroup_type(char *src)
{
size_t v2; // rax
char *v3; // rbp
__int64 v4; // rbx
char *v5; // rdi

v2 = strlen(src);
v3 = (char *)malloc(v2 + 1);
v4 = cgroup_head;
if ( cgroup_head )
{
while ( 1 )
{
strcpy(v3, src);
v5 = strtok(v3, ",");
if ( v5 )
break;
LABEL_5:
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
goto LABEL_6;
}
while ( strcmp(v5, *(const char **)v4) )
{
v5 = strtok(0LL, ",");
if ( !v5 )
goto LABEL_5;
}
free(v3);
}
else
{
LABEL_6:
free(v3);
v4 = 0LL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src)
{
size_t v2; // rax
char *v3; // rbp
__int64 v4; // rbx
char *v5; // rdi

v2 = strlen(src);
v3 = (char *)malloc(v2 + 1);
v4 = cgroup_head;
if ( cgroup_head )
{
while ( 1 )
{
strcpy(v3, src);
v5 = strtok(v3, ",");
if ( v5 )
break;
LABEL_5:
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
goto LABEL_6;
}
while ( strcmp(v5, *(const char **)v4) )
{
v5 = strtok(0LL, ",");
if ( !v5 )
goto LABEL_5;
}
free(v3);
}
else
{
LABEL_6:
free(v3);
v4 = 0LL;
}
return v4;
}

original_code:
static struct cgroup_entry *option_contain_cgroup_type(const char *opts){
 struct cgroup_entry *cent;
 char *tmp_opts = malloc(strlen(opts)+1);
 for ((cent) = ((&cgroup_head)->lh_first); (cent); (cent) = ((cent)->next.le_next)){
  strcpy(tmp_opts, opts);
  char *opt = strtok(tmp_opts, ",");
  while(opt){
   if(strcmp(opt, cent->type) == 0){
    free(tmp_opts);
    return cent;
   }
   opt = strtok(((void *)0), ",");
  }
 }
 free(tmp_opts);
 return ((void *)0);
}

canonical_original_code:
static struct cgroup_entry *option_contain_cgroup_type(char *opts){
 struct cgroup_entry *cent;
 char *tmp_opts = malloc(strlen(opts)+1);
 for ((cent) = ((&cgroup_head)->lh_first); (cent); (cent) = ((cent)->next.le_next)){
  strcpy(tmp_opts, opts);
  char *opt = strtok(tmp_opts, ",");
  while(opt){
   if(strcmp(opt, cent->type) == 0){
    free(tmp_opts);
    return cent;
   }
   opt = strtok(((void *)0), ",");
  }
 }
 free(tmp_opts);
 return ((void *)0);
}

variable_types:
opts
char *

variable_types:
opt
char *

return_type: struct cgroup_entry { char *type; char *mp; struct { struct cgroup_entry *le_next; struct cgroup_entry **le_prev; } next; } *


decompiled_code:
void *__fastcall cgroup_mount(char *s1)
{
__int64 v1; // rax
void *v2; // r12

v1 = cgroup_is_mounted(s1);
if ( v1 )
return *(void **)(v1 + 8);
v2 = malloc(0x1000uLL);
if ( snprintf((char *)v2, 0x1000uLL, "/sys/fs/cgroup/%s", s1) > 4095 )
{
puts("cgroup name too long");
v2 = 0LL;
}
else if ( mount("cgroup", (const char *)v2, "cgroup", 0x20000EuLL, s1) == -1 )
{
free(v2);
v2 = 0LL;
}
else
{
add_mount(s1, (char *)v2);
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func4(char *s1)
{
__int64 v1; // rax
void *v2; // r12

v1 = func0(s1);
if ( v1 )
return *(void **)(v1 + 8);
v2 = malloc(0x1000uLL);
if ( snprintf((char *)v2, 0x1000uLL, "/sys/fs/cgroup/%s", s1) > 4095 )
{
puts("cgroup name too long");
v2 = 0LL;
}
else if ( mount("cgroup", (const char *)v2, "cgroup", 0x20000EuLL, s1) == -1 )
{
free(v2);
v2 = 0LL;
}
else
{
func1(s1, (char *)v2);
}
return v2;
}

original_code:
const char *cgroup_mount(const char *type){
 struct cgroup_entry *entry;
 if((entry = cgroup_is_mounted(type)))
  return entry->mp;
 char *target = malloc(4096);
 int len = snprintf(target, 4096, "/sys/fs/cgroup/%s", type);
 if(len >= 4096){
  printf("cgroup name too long\n");
  return ((void *)0);
 }
 int ret = mount("cgroup", target, "cgroup", MS_NODEV|MS_NOEXEC|MS_NOSUID|MS_RELATIME, type);
 if(ret == -1){
  free(target);
  return ((void *)0);
 }
 add_mount(type, target);
 return target;
}

canonical_original_code:
char *cgroup_mount(char *type){
 struct cgroup_entry *entry;
 if((entry = cgroup_is_mounted(type)))
  return entry->mp;
 char *target = malloc(4096);
 int len = snprintf(target, 4096, "/sys/fs/cgroup/%s", type);
 if(len >= 4096){
  printf("cgroup name too long\n");
  return ((void *)0);
 }
 int ret = mount("cgroup", target, "cgroup", MS_NODEV|MS_NOEXEC|MS_NOSUID|MS_RELATIME, type);
 if(ret == -1){
  free(target);
  return ((void *)0);
 }
 add_mount(type, target);
 return target;
}

variable_types:
target
char *

variable_types: len int

variable_types: ret int

return_type: char *


decompiled_code:
void __fastcall cgroup_put(void **a1)
{
free(*a1);
}

canonical_decompiled_code:
void __fastcall func5(void **a1)
{
free(*a1);
}

original_code:
void cgroup_put(struct cgroup *cgr){
 free(cgr->full_path);
}

variable_types:
cgr
struct cgroup { char *full_path; } *


decompiled_code:
__int64 cgroup_init()
{
return cgroup_get_mount();
}

canonical_decompiled_code:
__int64 func7()
{
return func3();
}

original_code:
int cgroup_init(){
 return cgroup_get_mount();
}


decompiled_code:
__int64 nl_connect()
{
unsigned int v0; // ebx
struct sockaddr addr; // [rsp+4h] [rbp-24h] BYREF

v0 = socket(16, 2050, 11);
if ( v0 == -1 )
{
perror("socket");
}
else
{
addr.sa_family = 16;
*(_DWORD *)&addr.sa_data[6] = 1;
*(_DWORD *)&addr.sa_data[2] = getpid();
if ( bind(v0, &addr, 0xCu) == -1 )
{
perror("bind");
close(v0);
v0 = -1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebx
struct sockaddr addr; // [rsp+4h] [rbp-24h] BYREF

v0 = socket(16, 2050, 11);
if ( v0 == -1 )
{
perror("socket");
}
else
{
addr.sa_family = 16;
*(_DWORD *)&addr.sa_data[6] = 1;
*(_DWORD *)&addr.sa_data[2] = getpid();
if ( bind(v0, &addr, 0xCu) == -1 )
{
perror("bind");
close(v0);
v0 = -1;
}
}
return v0;
}

original_code:
static int nl_connect()
{
 int rc;
 int nl_sock;
 struct sockaddr_nl sa_nl;
 nl_sock = socket(16, SOCK_DGRAM|SOCK_NONBLOCK, 11);
 if (nl_sock == -1) {
  perror("socket");
  return -1;
 }
 sa_nl.nl_family = 16;
 sa_nl.nl_groups = 0x1;
 sa_nl.nl_pid = getpid();
 rc = bind(nl_sock, (struct sockaddr *)&sa_nl, sizeof(sa_nl));
 if (rc == -1) {
  perror("bind");
  close(nl_sock);
  return -1;
 }
 return nl_sock;
}

variable_types: rc int

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


zmalloc

decompiled_code:
void *__fastcall zmalloc(size_t n)
{
void *v1; // rax

v1 = malloc(n);
return memset(v1, 0, n);
}

canonical_decompiled_code:
void *__fastcall func0(size_t n)
{
void *v1; // rax

v1 = malloc(n);
return memset(v1, 0, n);
}

original_code:
void *zmalloc(size_t size){
 void *tmp = malloc(size);
 memset(tmp, 0, size);
 return tmp;
}

canonical_original_code:
void *zmalloc(unsigned long size){
 void *tmp = malloc(size);
 memset(tmp, 0, size);
 return tmp;
}

variable_types:
size
unsigned long

variable_types:
tmp
void *

return_type: void *


repo: ystk/fs-test

decompiled_code:
void __fastcall __noreturn net_thread(void *a1)
{
int v1; // ebx
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

fprintf(stderr, "Starting NET thread: %d\n", 94LL);
*(_DWORD *)&v2.sa_data[10] = 0;
*(_WORD *)v2.sa_data = _bswap_16(13579);
v2.sa_family = 2;
*(_QWORD *)&v2.sa_data[2] = (unsigned int)_bswap_32(0);
v1 = socket(2, 2, 0);
bind(v1, &v2, 0x10u);
net_recv_write(v1);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(void *a1)
{
int v1; // ebx
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

fprintf(stderr, "Starting NET thread: %d\n", 94LL);
*(_DWORD *)&v2.sa_data[10] = 0;
*(_WORD *)v2.sa_data = func7(13579);
v2.sa_family = 2;
*(_QWORD *)&v2.sa_data[2] = (unsigned int)func8(0);
v1 = socket(2, 2, 0);
bind(v1, &v2, 0x10u);
func9(v1);
}

original_code:
void *net_thread(void *net_args)
{
        int recv_soc;
        int recv_port = 13579;
        int stat;
        struct sockaddr_in recv_socaddr;
        fprintf(stderr,"Starting NET thread: %d\n", 94);
        memset(&recv_socaddr, 0, sizeof(struct sockaddr_in));
        recv_socaddr.sin_port = htons(recv_port);
        recv_socaddr.sin_family = 2;
        recv_socaddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
        recv_soc = socket(2, SOCK_DGRAM, 0);
        stat = bind(recv_soc, (struct sockaddr_in *) &recv_socaddr,
                        sizeof(struct sockaddr_in));
        net_recv_write(recv_soc, &recv_socaddr);
        return 0;
}

canonical_original_code:
void *net_thread(void *net_args)
{
        int recv_soc;
        int recv_port = 13579;
        int stat;
        struct sockaddr_in recv_socaddr;
        fprintf(stderr,"Starting NET thread: %d\n", 94);
        memset(&recv_socaddr, 0, sizeof(struct sockaddr_in));
        recv_socaddr.sin_port = htons(recv_port);
        recv_socaddr.sin_family = 2;
        recv_socaddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
        recv_soc = socket(2, SOCK_DGRAM, 0);
        stat = bind(recv_soc, (struct sockaddr_in *) &recv_socaddr,
                        sizeof(struct sockaddr_in));
        net_recv_write(recv_soc, &recv_socaddr);
        return 0;
}

variable_types: stat int

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

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


decompiled_code:
int __fastcall net_recv(int fd)
{
char *v1; // rbp
__int64 i; // r14
char *v3; // rbx
int result; // eax

v1 = (char *)&unk_604140;
for ( i = 0LL; i != 3; ++i )
{
if ( w_progress == (_DWORD)i )
fprintf(stderr, "Buffer overflow: %d\n", 121LL);
pthread_mutex_lock((pthread_mutex_t *)(log_mutex + 40 * i));
net_ready = 1;
v3 = v1 - 0x200000;
do
{
if ( recvfrom(fd, v3, 0x400uLL, 0, 0LL, 0LL) == -1 )
{
perror("recv");
close(fd);
exit(1);
}
fprintf(stderr, "RECV: %s", v3);
v3 += 1024;
}
while ( v3 != v1 );
result = pthread_mutex_unlock((pthread_mutex_t *)(log_mutex + 40 * i));
v1 += 0x200000;
}
if ( w_progress == -1 )
{
fwrite("File I/O too slow\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(int fd)
{
char *v1; // rbp
__int64 i; // r14
char *v3; // rbx
int result; // eax

v1 = (char *)&unk_604140;
for ( i = 0LL; i != 3; ++i )
{
if ( w_progress == (_DWORD)i )
fprintf(stderr, "Buffer overflow: %d\n", 121LL);
pthread_mutex_lock((pthread_mutex_t *)(log_mutex + 40 * i));
net_ready = 1;
v3 = v1 - 0x200000;
do
{
if ( recvfrom(fd, v3, 0x400uLL, 0, 0LL, 0LL) == -1 )
{
perror("recv");
close(fd);
exit(1);
}
fprintf(stderr, "RECV: %s", v3);
v3 += 1024;
}
while ( v3 != v1 );
result = pthread_mutex_unlock((pthread_mutex_t *)(log_mutex + 40 * i));
v1 += 0x200000;
}
if ( w_progress == -1 )
{
fwrite("File I/O too slow\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
return result;
}

original_code:
void net_recv(int soc, struct sockaddr_in *sockaddr, struct net_arg_struct *na)
{
        int i, j;
        ssize_t num_recv;
        char *rbufp;
        for (i = 0; i< 3; i++){
                if (w_progress == i){
                        fprintf(stderr,"Buffer overflow: %d\n", 121);
                }
                pthread_mutex_lock(&log_mutex[i]);
                net_ready = 1;
                for(j = 0; j<2048; j++){
                        rbufp = rbuf[i][j];
                        num_recv = recvfrom(soc, rbufp, 1024, 0, ((void *)0), ((void *)0));
                        if(num_recv == -1) {
                                perror("recv");
                                close(soc);
                                exit(1);
                        }
                        fprintf(stderr,"RECV: %s", rbufp);
                }
                pthread_mutex_unlock(&log_mutex[i]);
        }
        if (w_progress == -1){
                fprintf(stderr,"File I/O too slow\n");
                exit(1);
        }
}

canonical_original_code:
void net_recv(int soc, struct sockaddr_in *sockaddr, struct net_arg_struct *na)
{
        int i; int j;
        long num_recv;
        char *rbufp;
        for (i = 0; i< 3; i++){
                if (w_progress == i){
                        fprintf(stderr,"Buffer overflow: %d\n", 121);
                }
                pthread_mutex_lock(&log_mutex[i]);
                net_ready = 1;
                for(j = 0; j<2048; j++){
                        rbufp = rbuf[i][j];
                        num_recv = recvfrom(soc, rbufp, 1024, 0, ((void *)0), ((void *)0));
                        if(num_recv == -1) {
                                perror("recv");
                                close(soc);
                                exit(1);
                        }
                        fprintf(stderr,"RECV: %s", rbufp);
                }
                pthread_mutex_unlock(&log_mutex[i]);
        }
        if (w_progress == -1){
                fprintf(stderr,"File I/O too slow\n");
                exit(1);
        }
}

variable_types: soc int

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

variable_types: j int

variable_types:
rbufp
char *


decompiled_code:
void __noreturn fio_thread()
{
FILE *v0; // rax
FILE *v1; // r12
const char *v2; // rbp
__int64 i; // r14
const char *v4; // rbx

fprintf(stderr, "Starting LOG thread: %d\n", 153LL);
v0 = fopen("./log/log.txt", "w");
if ( net_ready != 1 )
{
while ( 1 )
sched_yield();
}
v1 = v0;
fprintf(stderr, "Starting logging: %d\n", 164LL);
while ( 1 )
{
v2 = (const char *)&unk_604140;
for ( i = 0LL; i != 3; ++i )
{
pthread_mutex_lock((pthread_mutex_t *)(log_mutex + 40 * i));
w_progress = i;
v4 = v2 - 0x200000;
do
{
fputs(v4, v1);
v4 += 1024;
}
while ( v4 != v2 );
pthread_mutex_unlock((pthread_mutex_t *)(log_mutex + 40 * i));
v2 += 0x200000;
}
}
}

canonical_decompiled_code:
void __noreturn func12()
{
FILE *v0; // rax
FILE *v1; // r12
const char *v2; // rbp
__int64 i; // r14
const char *v4; // rbx

fprintf(stderr, "Starting LOG thread: %d\n", 153LL);
v0 = fopen("./log/log.txt", "w");
if ( net_ready != 1 )
{
while ( 1 )
sched_yield();
}
v1 = v0;
fprintf(stderr, "Starting logging: %d\n", 164LL);
while ( 1 )
{
v2 = (const char *)&unk_604140;
for ( i = 0LL; i != 3; ++i )
{
pthread_mutex_lock((pthread_mutex_t *)(log_mutex + 40 * i));
w_progress = i;
v4 = v2 - 0x200000;
do
{
fputs(v4, v1);
v4 += 1024;
}
while ( v4 != v2 );
pthread_mutex_unlock((pthread_mutex_t *)(log_mutex + 40 * i));
v2 += 0x200000;
}
}
}

original_code:
void *fio_thread(void *fio_args)
{
        struct f_thr_args *fa = (struct f_thr_args *)fio_args;
        fio_main(fa);
        return ((void *)0);
}

variable_types: struct f_thr_args { int id; int id_max; int type; int count; long fsize; long wsize; int gran; long fnum; char *path; char *serv_ip; int port; int socket; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *serv_addr; } *

user_defined_types: struct f_thr_args { int id; int id_max; int type; int count; long fsize; long wsize; int gran; long fnum; char *path; char *serv_ip; int port; int socket; struct sockaddr_in *serv_addr; }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_mutex_t *v3; // rbx
pthread_t v4; // [rsp+0h] [rbp-18h] BYREF
char v5[9]; // [rsp+Fh] [rbp-9h] BYREF

v3 = (pthread_mutex_t *)malloc(0x78uLL);
log_mutex = (__int64)v3;
pthread_mutex_init(v3, 0LL);
pthread_mutex_init(v3 + 1, 0LL);
pthread_mutex_init(v3 + 2, 0LL);
if ( pthread_create(&v4, 0LL, (void *(*)(void *))net_thread, &net_args) )
exit(1);
while ( 1 )
{
printf("COMMAND(q): ");
scanf("%c", v5);
if ( v5[0] == 113 )
break;
fflush(0LL);
}
fflush(0LL);
exit(0);
}

original_code:
int main()
{
        int i;
        char com;
        pthread_t netthr;
        log_mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t) * 3);
        for(i=0; i<3; i++){
                pthread_mutex_init(&log_mutex[i], ((void *)0));
        }
        if(pthread_create(&netthr, ((void *)0), net_thread, &net_args)){
                exit(1);
        }
        while(1){
                printf("COMMAND(q): ");
                scanf("%c", &com);
                if (com == 'q'){
                        fflush(((void *)0));
                        exit(0);
                }else{
                        fflush(((void *)0));
                }
        }
        pthread_join(netthr, ((void *)0));
}

canonical_original_code:
int main()
{
        int i;
        char com;
        unsigned long netthr;
        log_mutex = (union pthread_mutex_t *)malloc(sizeof(pthread_mutex_t) * 3);
        for(i=0; i<3; i++){
                pthread_mutex_init(&log_mutex[i], ((void *)0));
        }
        if(pthread_create(&netthr, ((void *)0), net_thread, &net_args)){
                exit(1);
        }
        while(1){
                printf("COMMAND(q): ");
                scanf("%c", &com);
                if (com == 'q'){
                        fflush(((void *)0));
                        exit(0);
                }else{
                        fflush(((void *)0));
                }
        }
        pthread_join(netthr, ((void *)0));
}

variable_types: i int

variable_types: com char

variable_types:
netthr
unsigned long

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
int __fastcall bar_init(unsigned int count)
{
fprintf(stderr, "BAR_INIT(%d) ", count);
return pthread_barrier_init(&barrier, 0LL, count);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int count)
{
fprintf(stderr, "BAR_INIT(%d) ", count);
return pthread_barrier_init(&barrier, 0LL, count);
}

original_code:
void bar_init(int num)
{
  fprintf(stderr, "BAR_INIT(%d) ", num);
  pthread_barrier_init(&barrier, ((void *)0), num);
}

variable_types: num int


decompiled_code:
int bar_wait()
{
return pthread_barrier_wait(&barrier);
}

canonical_decompiled_code:
int func1()
{
return pthread_barrier_wait(&barrier);
}

original_code:
void bar_wait(int id)
{
  pthread_barrier_wait(&barrier);
}

variable_types: id int


nrerror

decompiled_code:
void __fastcall __noreturn nrerror(char *s)
{
puts("Numerical Recipes run-time error...");
puts(s);
puts("...now exiting to system...");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(char *s)
{
puts("Numerical Recipes run-time error...");
puts(s);
puts("...now exiting to system...");
exit(1);
}

original_code:
void nrerror(char error_text[])
{
 printf("Numerical Recipes run-time error...\n");
 printf("%s\n",error_text);
 printf("...now exiting to system...\n");
 exit(1);
}


vector

decompiled_code:
char *__fastcall vector(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(4 * (a2 - a1) + 8);
if ( !v2 )
nrerror("allocation failure in vector()");
return &v2[4 * (1 - a1)];
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(4 * (a2 - a1) + 8);
if ( !v2 )
func0("allocation failure in vector()");
return &v2[4 * (1 - a1)];
}

original_code:
float *vector(long nl, long nh)
{
 float *v;
 v=(float *)malloc((size_t) ((nh-nl+1+1)*sizeof(float)));
 if (!v) nrerror("allocation failure in vector()");
 return v-nl+1;
}

canonical_original_code:
float *vector(long nl, long nh)
{
 float *v;
 v=(float *)malloc((unsigned long) ((nh-nl+1+1)*sizeof(float)));
 if (!v) nrerror("allocation failure in vector()");
 return v-nl+1;
}

variable_types: nl long

variable_types: nh long

variable_types:
v
float *

return_type: float *


matrix

original_code:
float **matrix(long nrl, long nrh, long ncl, long nch)
{
 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
 float **m;
 m=(float **) malloc((size_t)((nrow+1)*sizeof(float*)));
 if (!m) nrerror("allocation failure 1 in matrix()");
 m += 1;
 m -= nrl;
 m[nrl]=(float *) malloc((size_t)((nrow*ncol+1)*sizeof(float)));
 if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
 m[nrl] += 1;
 m[nrl] -= ncl;
 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
 return m;
}

canonical_original_code:
float **matrix(long nrl, long nrh, long ncl, long nch)
{
 long i; long nrow = nrh-nrl+1; long ncol = nch-ncl+1;
 float **m;
 m=(float **) malloc((unsigned long)((nrow+1)*sizeof(float *)));
 if (!m) nrerror("allocation failure 1 in matrix()");
 m += 1;
 m -= nrl;
 m[nrl]=(float *) malloc((unsigned long)((nrow*ncol+1)*sizeof(float)));
 if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
 m[nrl] += 1;
 m[nrl] -= ncl;
 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
 return m;
}

variable_types: nrl long

variable_types: nrh long

variable_types: ncl long

variable_types: nch long

variable_types: i long

variable_types: nrow long

variable_types: ncol long

variable_types:
m
float **

return_type: float **


decompiled_code:
void __fastcall free_vector(__int64 a1, __int64 a2)
{
free((void *)(a1 + 4 * a2 - 4));
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2)
{
free((void *)(a1 + 4 * a2 - 4));
}

original_code:
void free_vector(float *v, long nl, long nh)
{
 free((void *) (v+nl-1));
}


original_code:
void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
{
 free((void *)(m[nrl]+ncl-1));
 free((void *) (m+nrl-1));
}


loganREF

original_code:
float loganREF(float *REF, float *ROI, float k2, float *t, float *frd, int nframes, int stframe, int endframe, float *intercept, float *slope, float *Rsq)
{
float BP, r, *x, *y, *intgREF, *intgROI, *tmpx, *tmpy, mx, Sxx, Sx, k, Syy, Sy, my, xt, yt, Sxy,delta, sxx, syy, sxy;
int i;
intgREF=vector(0, nframes-1);
intgROI=vector(0, nframes-1);
tmpx=vector(0, nframes-1);
tmpy=vector(0, nframes-1);
x=vector(0, nframes-1);
y=vector(0, nframes-1);
tmpx[0]=REF[0]*t[0]/2./60.;
tmpy[0]=ROI[0]*t[0]/2./60.;
intgREF[0]=tmpx[0];
intgROI[0]=tmpy[0];
x[0]=(intgREF[0]+REF[0]/k2)/(ROI[0]+1.0e-2);
y[0]=intgROI[0]/(ROI[0]+1.0e-2);
for (i=1; i<nframes; i++)
 {
 intgREF[i]=intgREF[i-1]+(REF[i-1]+REF[i])*(t[i]-t[i-1])/2./60.;
 intgROI[i]=intgROI[i-1]+(ROI[i-1]+ROI[i])*(t[i]-t[i-1])/2./60.;
 x[i]=(intgREF[i]+REF[i]/k2)/(ROI[i]+1.0e-2);
 y[i]=intgROI[i]/(ROI[i]+1.0e-2);
 }
k=(float)(endframe-stframe+1);
mx=0.;
Sxx=0.;
my=0.;
Syy=0.;
Sxy=0.;
for (i=stframe-1; i<endframe; i++)
 {
 mx += x[i];
 Sxx += x[i]*x[i];
 my += y[i];
 Syy += y[i]*y[i];
 Sxy += x[i]*y[i];
 }
Sx = mx;
mx /= k;
sxx = Sxx - k*mx*mx;
delta = k*Sxx -Sx*Sx;
Sy = my;
my /= k;
syy = Syy - k*my*my;
sxy=0;
for (i=stframe-1; i<endframe; i++)
 {
 xt = x[i] - mx;
 yt = y[i] - my;
 sxy += xt*yt;
 }
if (sxx*syy>0) {
 r=sxy/sqrtf(sxx*syy);
 } else {
 r=0;
 }
*intercept=(Sxx*Sy-Sx*Sxy)/delta;
*slope=(k*Sxy-Sx*Sy)/delta;
*Rsq=r*r;
BP=*slope-1.;
return(BP);
}

canonical_original_code:
float loganREF(float *REF, float *ROI, float k2, float *t, float *frd, int nframes, int stframe, int endframe, float *intercept, float *slope, float *Rsq)
{
float BP; float r; float *x; float *y; float *intgREF; float *intgROI; float *tmpx; float *tmpy; float mx; float Sxx; float Sx; float k; float Syy; float Sy; float my; float xt; float yt; float Sxy; float delta; float sxx; float syy; float sxy;
int i;
intgREF=vector(0, nframes-1);
intgROI=vector(0, nframes-1);
tmpx=vector(0, nframes-1);
tmpy=vector(0, nframes-1);
x=vector(0, nframes-1);
y=vector(0, nframes-1);
tmpx[0]=REF[0]*t[0]/2./60.;
tmpy[0]=ROI[0]*t[0]/2./60.;
intgREF[0]=tmpx[0];
intgROI[0]=tmpy[0];
x[0]=(intgREF[0]+REF[0]/k2)/(ROI[0]+1.0e-2);
y[0]=intgROI[0]/(ROI[0]+1.0e-2);
for (i=1; i<nframes; i++)
 {
 intgREF[i]=intgREF[i-1]+(REF[i-1]+REF[i])*(t[i]-t[i-1])/2./60.;
 intgROI[i]=intgROI[i-1]+(ROI[i-1]+ROI[i])*(t[i]-t[i-1])/2./60.;
 x[i]=(intgREF[i]+REF[i]/k2)/(ROI[i]+1.0e-2);
 y[i]=intgROI[i]/(ROI[i]+1.0e-2);
 }
k=(float)(endframe-stframe+1);
mx=0.;
Sxx=0.;
my=0.;
Syy=0.;
Sxy=0.;
for (i=stframe-1; i<endframe; i++)
 {
 mx += x[i];
 Sxx += x[i]*x[i];
 my += y[i];
 Syy += y[i]*y[i];
 Sxy += x[i]*y[i];
 }
Sx = mx;
mx /= k;
sxx = Sxx - k*mx*mx;
delta = k*Sxx -Sx*Sx;
Sy = my;
my /= k;
syy = Syy - k*my*my;
sxy=0;
for (i=stframe-1; i<endframe; i++)
 {
 xt = x[i] - mx;
 yt = y[i] - my;
 sxy += xt*yt;
 }
if (sxx*syy>0) {
 r=sxy/sqrtf(sxx*syy);
 } else {
 r=0;
 }
*intercept=(Sxx*Sy-Sx*Sxy)/delta;
*slope=(k*Sxy-Sx*Sy)/delta;
*Rsq=r*r;
BP=*slope-1.;
return(BP);
}

variable_types:
REF
float *

variable_types:
ROI
float *

variable_types:
t
float *

variable_types:
frd
float *

variable_types: nframes int

variable_types: stframe int

variable_types: endframe int

variable_types:
intercept
float *

variable_types:
slope
float *

variable_types:
Rsq
float *

variable_types: BP float

variable_types: r float

variable_types:
x
float *

variable_types:
y
float *

variable_types:
intgREF
float *

variable_types:
intgROI
float *

variable_types:
tmpx
float *

variable_types:
tmpy
float *

variable_types: mx float

variable_types: Sxx float

variable_types: Sx float

variable_types: k float

variable_types: Syy float

variable_types: Sy float

variable_types: my float

variable_types: xt float

variable_types: yt float

variable_types: Sxy float

variable_types: delta float

variable_types: sxx float

variable_types: syy float

variable_types: sxy float

return_type: float


decompiled_code:
int Getifh_rcs()
{
return puts(rcsid);
}

canonical_decompiled_code:
int func0()
{
return puts(rcsid);
}

original_code: void Getifh_rcs (void) {printf ("%s\n", rcsid);}

canonical_original_code: void Getifh_rcs() {printf ("%s\n", rcsid);}


decompiled_code:
void __fastcall gauss3d(__int64 a1, int *a2, int *a3, int *a4, float *a5, float *a6)
{
int v6; // edx
int v7; // eax
float *v9; // rbp
float *v10; // rbx
int v11; // er13
int v12; // er14
__int64 v13; // rdx
__int64 v14; // rcx
float *v15; // rsi
float *v16; // rcx
unsigned __int64 v17; // rax
__int64 v18; // rbx
float *v19; // r12
float *v20; // rbx
int i; // ebp
int v22; // edx
int v23; // eax
int v24; // ecx
int v25; // er13
int v26; // er15
int v27; // esi
int v28; // ecx
double v29; // xmm0_8
__int64 v30; // r12
int j; // er13
int v32; // eax
double v33; // xmm2_8
float v34; // xmm1_4
float v35; // xmm0_4
int v36; // edx
int v37; // esi
__int64 v38; // rbx
float *v39; // rbp
float *v40; // rbx
__int64 v41; // rdx
unsigned __int64 v42; // rax
int k; // er12
float *v44; // [rsp+0h] [rbp-98h]
float *v45; // [rsp+0h] [rbp-98h]
double v46; // [rsp+0h] [rbp-98h]
float *v47; // [rsp+8h] [rbp-90h]
float *v48; // [rsp+8h] [rbp-90h]
int v49; // [rsp+10h] [rbp-88h]
double v50; // [rsp+10h] [rbp-88h]
int v51; // [rsp+10h] [rbp-88h]
int v53; // [rsp+20h] [rbp-78h]
float *v54; // [rsp+30h] [rbp-68h]
double v55; // [rsp+30h] [rbp-68h]
int v56; // [rsp+38h] [rbp-60h]
int v57; // [rsp+3Ch] [rbp-5Ch]
int v58; // [rsp+44h] [rbp-54h] BYREF
int v59; // [rsp+48h] [rbp-50h] BYREF
int v60; // [rsp+4Ch] [rbp-4Ch] BYREF
int v61; // [rsp+50h] [rbp-48h] BYREF
int v62; // [rsp+54h] [rbp-44h] BYREF
int v63; // [rsp+58h] [rbp-40h] BYREF
int v64[15]; // [rsp+5Ch] [rbp-3Ch] BYREF

v59 = 1;
v58 = -1;
v56 = *a2;
v6 = *a3;
v61 = v6;
v7 = *a4;
v60 = *a4;
if ( (v56 & 1) != 0 )
{
fwrite("gauss3d: nx not a multiple of 2\n", 1uLL, 0x20uLL, stderr);
exit(-1);
}
v64[0] = v56 / 2;
v63 = v56 / 2 + 1;
v62 = v6 * v63;
v9 = (float *)malloc(4LL * v7 * v6 * v63);
if ( !v9 )
errm("gauss3d");
v10 = (float *)malloc(4LL * v60 * v61 * v63);
if ( !v10 )
errm("gauss3d");
if ( v60 > 0 )
{
v49 = 0;
v11 = 0;
v44 = v9;
v47 = v10;
v54 = a5;
v12 = 0;
do
{
for ( i = 0; v61 > i; ++i )
{
if ( v56 > 0 )
{
v13 = a1 + 4LL * v12;
v14 = v11;
v15 = &v44[v14];
v16 = &v47[v14];
v17 = 0LL;
do
{
v15[v17 / 4] = *(float *)(v13 + 2 * v17);
v16[v17 / 4] = *(float *)(v13 + 2 * v17 + 4);
v17 += 4LL;
}
while ( v17 != 4LL * (((unsigned int)(v56 - 1) >> 1) + 1) );
v12 += ((v56 - 1) & 0xFFFFFFFE) + 2;
}
v18 = v11;
v19 = &v47[v18];
v20 = &v44[v18];
fft_(v20, v19, &v59, v64, &v59, &v58);
realt_(v20, v19, &v59, v64, &v59, &v58);
v11 += v63;
}
++v49;
}
while ( v60 > v49 );
v9 = v44;
v10 = v47;
a5 = v54;
}
fft_(v9, v10, &v60, &v61, &v63, &v58);
fft_(v9, v10, &v59, &v60, &v62, &v58);
v50 = -0.6931471805599453 / (float)(*a6 * *a6);
v22 = v60;
v57 = 0;
v23 = 0;
v24 = 0;
if ( v60 > 0 )
{
while ( 1 )
{
v55 = (float)((float)v24 / (float)((float)v22 * a5[2]));
v36 = v61;
v53 = 0;
v28 = 0;
if ( v61 > 0 )
{
while ( 1 )
{
if ( v63 > 0 )
{
v29 = (float)((float)v28 / (float)((float)v36 * a5[1]));
v46 = v29 * v29;
v30 = v23 + 1;
for ( j = 0; j < v63; ++j )
{
v32 = v56 - j;
if ( v56 / 2 >= j )
v32 = j;
v33 = exp(
((float)((float)v32 / (float)((float)v56 * *a5)) * (float)((float)v32 / (float)((float)v56 * *a5))
+ v46
+ v55 * v55)
* v50);
v34 = v9[v30 - 1] * v33;
v9[v30 - 1] = v34;
v35 = v10[v30 - 1] * v33;
v10[v30 - 1] = v35;
v23 = v30++;
}
}
++v53;
v36 = v61;
if ( v61 <= v53 )
break;
v27 = v61 - v53;
if ( v61 / 2 >= v53 )
v27 = v53;
v28 = v27;
}
}
++v57;
v22 = v60;
if ( v60 <= v57 )
break;
v37 = v60 - v57;
if ( v60 / 2 >= v57 )
v37 = v57;
v24 = v37;
}
}
fft_(v9, v10, &v59, &v60, &v62, &v59);
fft_(v9, v10, &v60, &v61, &v63, &v59);
if ( v60 > 0 )
{
v51 = 0;
v25 = 0;
v26 = 0;
v45 = v9;
v48 = v10;
do
{
for ( k = 0; v61 > k; ++k )
{
v38 = v26;
v39 = &v48[v38];
v40 = &v45[v38];
realt_(v40, v39, &v59, v64, &v59, &v59);
fft_(v40, v39, &v59, v64, &v59, &v59);
if ( v56 > 0 )
{
v41 = a1 + 4LL * v25;
v42 = 0LL;
do
{
*(float *)(v41 + 2 * v42) = v40[v42 / 4];
*(float *)(v41 + 2 * v42 + 4) = v39[v42 / 4];
v42 += 4LL;
}
while ( v42 != 4LL * (((unsigned int)(v56 - 1) >> 1) + 1) );
v25 += ((v56 - 1) & 0xFFFFFFFE) + 2;
}
v26 += v63;
}
++v51;
}
while ( v60 > v51 );
v9 = v45;
v10 = v48;
}
free(v9);
free(v10);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int *a2, int *a3, int *a4, float *a5, float *a6)
{
int v6; // edx
int v7; // eax
float *v9; // rbp
float *v10; // rbx
int v11; // er13
int v12; // er14
__int64 v13; // rdx
__int64 v14; // rcx
float *v15; // rsi
float *v16; // rcx
unsigned __int64 v17; // rax
__int64 v18; // rbx
float *v19; // r12
float *v20; // rbx
int i; // ebp
int v22; // edx
int v23; // eax
int v24; // ecx
int v25; // er13
int v26; // er15
int v27; // esi
int v28; // ecx
double v29; // xmm0_8
__int64 v30; // r12
int j; // er13
int v32; // eax
double v33; // xmm2_8
float v34; // xmm1_4
float v35; // xmm0_4
int v36; // edx
int v37; // esi
__int64 v38; // rbx
float *v39; // rbp
float *v40; // rbx
__int64 v41; // rdx
unsigned __int64 v42; // rax
int k; // er12
float *v44; // [rsp+0h] [rbp-98h]
float *v45; // [rsp+0h] [rbp-98h]
double v46; // [rsp+0h] [rbp-98h]
float *v47; // [rsp+8h] [rbp-90h]
float *v48; // [rsp+8h] [rbp-90h]
int v49; // [rsp+10h] [rbp-88h]
double v50; // [rsp+10h] [rbp-88h]
int v51; // [rsp+10h] [rbp-88h]
int v53; // [rsp+20h] [rbp-78h]
float *v54; // [rsp+30h] [rbp-68h]
double v55; // [rsp+30h] [rbp-68h]
int v56; // [rsp+38h] [rbp-60h]
int v57; // [rsp+3Ch] [rbp-5Ch]
int v58; // [rsp+44h] [rbp-54h] BYREF
int v59; // [rsp+48h] [rbp-50h] BYREF
int v60; // [rsp+4Ch] [rbp-4Ch] BYREF
int v61; // [rsp+50h] [rbp-48h] BYREF
int v62; // [rsp+54h] [rbp-44h] BYREF
int v63; // [rsp+58h] [rbp-40h] BYREF
int v64[15]; // [rsp+5Ch] [rbp-3Ch] BYREF

v59 = 1;
v58 = -1;
v56 = *a2;
v6 = *a3;
v61 = v6;
v7 = *a4;
v60 = *a4;
if ( (v56 & 1) != 0 )
{
fwrite("gauss3d: nx not a multiple of 2\n", 1uLL, 0x20uLL, stderr);
exit(-1);
}
v64[0] = v56 / 2;
v63 = v56 / 2 + 1;
v62 = v6 * v63;
v9 = (float *)malloc(4LL * v7 * v6 * v63);
if ( !v9 )
errm("gauss3d");
v10 = (float *)malloc(4LL * v60 * v61 * v63);
if ( !v10 )
errm("gauss3d");
if ( v60 > 0 )
{
v49 = 0;
v11 = 0;
v44 = v9;
v47 = v10;
v54 = a5;
v12 = 0;
do
{
for ( i = 0; v61 > i; ++i )
{
if ( v56 > 0 )
{
v13 = a1 + 4LL * v12;
v14 = v11;
v15 = &v44[v14];
v16 = &v47[v14];
v17 = 0LL;
do
{
v15[v17 / 4] = *(float *)(v13 + 2 * v17);
v16[v17 / 4] = *(float *)(v13 + 2 * v17 + 4);
v17 += 4LL;
}
while ( v17 != 4LL * (((unsigned int)(v56 - 1) >> 1) + 1) );
v12 += ((v56 - 1) & 0xFFFFFFFE) + 2;
}
v18 = v11;
v19 = &v47[v18];
v20 = &v44[v18];
fft_(v20, v19, &v59, v64, &v59, &v58);
realt_(v20, v19, &v59, v64, &v59, &v58);
v11 += v63;
}
++v49;
}
while ( v60 > v49 );
v9 = v44;
v10 = v47;
a5 = v54;
}
fft_(v9, v10, &v60, &v61, &v63, &v58);
fft_(v9, v10, &v59, &v60, &v62, &v58);
v50 = -0.6931471805599453 / (float)(*a6 * *a6);
v22 = v60;
v57 = 0;
v23 = 0;
v24 = 0;
if ( v60 > 0 )
{
while ( 1 )
{
v55 = (float)((float)v24 / (float)((float)v22 * a5[2]));
v36 = v61;
v53 = 0;
v28 = 0;
if ( v61 > 0 )
{
while ( 1 )
{
if ( v63 > 0 )
{
v29 = (float)((float)v28 / (float)((float)v36 * a5[1]));
v46 = v29 * v29;
v30 = v23 + 1;
for ( j = 0; j < v63; ++j )
{
v32 = v56 - j;
if ( v56 / 2 >= j )
v32 = j;
v33 = exp(
((float)((float)v32 / (float)((float)v56 * *a5)) * (float)((float)v32 / (float)((float)v56 * *a5))
+ v46
+ v55 * v55)
* v50);
v34 = v9[v30 - 1] * v33;
v9[v30 - 1] = v34;
v35 = v10[v30 - 1] * v33;
v10[v30 - 1] = v35;
v23 = v30++;
}
}
++v53;
v36 = v61;
if ( v61 <= v53 )
break;
v27 = v61 - v53;
if ( v61 / 2 >= v53 )
v27 = v53;
v28 = v27;
}
}
++v57;
v22 = v60;
if ( v60 <= v57 )
break;
v37 = v60 - v57;
if ( v60 / 2 >= v57 )
v37 = v57;
v24 = v37;
}
}
fft_(v9, v10, &v59, &v60, &v62, &v59);
fft_(v9, v10, &v60, &v61, &v63, &v59);
if ( v60 > 0 )
{
v51 = 0;
v25 = 0;
v26 = 0;
v45 = v9;
v48 = v10;
do
{
for ( k = 0; v61 > k; ++k )
{
v38 = v26;
v39 = &v48[v38];
v40 = &v45[v38];
realt_(v40, v39, &v59, v64, &v59, &v59);
fft_(v40, v39, &v59, v64, &v59, &v59);
if ( v56 > 0 )
{
v41 = a1 + 4LL * v25;
v42 = 0LL;
do
{
*(float *)(v41 + 2 * v42) = v40[v42 / 4];
*(float *)(v41 + 2 * v42 + 4) = v39[v42 / 4];
v42 += 4LL;
}
while ( v42 != 4LL * (((unsigned int)(v56 - 1) >> 1) + 1) );
v25 += ((v56 - 1) & 0xFFFFFFFE) + 2;
}
v26 += v63;
}
++v51;
}
while ( v60 > v51 );
v9 = v45;
v10 = v48;
}
free(v9);
free(v10);
}

original_code:
void gauss3d (float *image, int *pnx, int *pny, int *pnz, float *cmppix, float *fhalf) {
 float *a, *b;
 double q, factor, f2, fx, fy, fz;
 int i, k, n1, n2, n2ny, jndex;
 int ix, iy, iz, nx, ny, nz, kx, ky, kz;
  int one = 1, negone = -1;
 nx = *pnx; ny = *pny; nz = *pnz;
 if (nx % 2) {
  fprintf (stderr, "gauss3d: nx not a multiple of 2\n");
  exit (-1);
 }
 n1 = nx/2;
 n2 = n1 + 1;
 n2ny = n2*ny;
 if (!(a = (float *) malloc (n2*ny*nz * sizeof (float)))) errm ("gauss3d");
 if (!(b = (float *) malloc (n2*ny*nz * sizeof (float)))) errm ("gauss3d");
 k = jndex = 0;
 for (iz = 0; iz < nz; iz++) {
 for (iy = 0; iy < ny; iy++) {
  for (i = ix = 0; ix < nx; ix += 2, i++) {
   (a + k)[i] = image[jndex++];
   (b + k)[i] = image[jndex++];
  }
  fft_ (a + k, b + k, &one, &n1, &one, &negone);
  realt_ (a + k, b + k, &one, &n1, &one, &negone);
  k += n2;
 }}
 fft_ (a, b, &nz, &ny, &n2, &negone);
 fft_ (a, b, &one, &nz, &n2ny, &negone);
 q = -log(2.)/((*fhalf)*(*fhalf));
 i = 0;
 for (iz = 0; iz < nz; iz++) {
  kz = (iz <= nz/2) ? iz : nz - iz;
  fz = kz/(nz*cmppix[2]);
 for (iy = 0; iy < ny; iy++) {
  ky = (iy <= ny/2) ? iy : ny - iy;
  fy = ky/(ny*cmppix[1]);
 for (ix = 0; ix < n2; ix++) {
  kx = (ix <= nx/2) ? ix : nx - ix;
  fx = kx/(nx*cmppix[0]);
  f2 = fx*fx + fy*fy + fz*fz;
  factor = exp (q*f2);
  a[i] *= factor;
   b[i] *= factor;
  i++;
 }}}
 fft_ (a, b, &one, &nz, &n2ny, &one);
 fft_ (a, b, &nz, &ny, &n2, &one);
 k = jndex = 0;
 for (iz = 0; iz < nz; iz++) {
 for (iy = 0; iy < ny; iy++) {
  realt_ (a + k, b + k, &one, &n1, &one, &one);
  fft_ (a + k, b + k, &one, &n1, &one, &one);
  for (i = ix = 0; ix < nx; ix += 2, i++) {
   image[jndex++] = (a + k)[i];
   image[jndex++] = (b + k)[i];
  }
  k += n2;
 }}
 free (a);
 free (b);
}

canonical_original_code:
void gauss3d(float *image, int *pnx, int *pny, int *pnz, float *cmppix, float *fhalf) {
 float *a; float *b;
 double q; double factor; double f2; double fx; double fy; double fz;
 int i; int k; int n1; int n2; int n2ny; int jndex;
 int ix; int iy; int iz; int nx; int ny; int nz; int kx; int ky; int kz;
  int one = 1; int negone = -1;
 nx = *pnx; ny = *pny; nz = *pnz;
 if (nx % 2) {
  fprintf (stderr, "gauss3d: nx not a multiple of 2\n");
  exit (-1);
 }
 n1 = nx/2;
 n2 = n1 + 1;
 n2ny = n2*ny;
 if (!(a = (float *) malloc (n2*ny*nz * sizeof (float)))) errm ("gauss3d");
 if (!(b = (float *) malloc (n2*ny*nz * sizeof (float)))) errm ("gauss3d");
 k = jndex = 0;
 for (iz = 0; iz < nz; iz++) {
 for (iy = 0; iy < ny; iy++) {
  for (i = ix = 0; ix < nx; ix += 2, i++) {
   (a + k)[i] = image[jndex++];
   (b + k)[i] = image[jndex++];
  }
  fft_ (a + k, b + k, &one, &n1, &one, &negone);
  realt_ (a + k, b + k, &one, &n1, &one, &negone);
  k += n2;
 }}
 fft_ (a, b, &nz, &ny, &n2, &negone);
 fft_ (a, b, &one, &nz, &n2ny, &negone);
 q = -log(2.)/((*fhalf)*(*fhalf));
 i = 0;
 for (iz = 0; iz < nz; iz++) {
  kz = (iz <= nz/2) ? iz : nz - iz;
  fz = kz/(nz*cmppix[2]);
 for (iy = 0; iy < ny; iy++) {
  ky = (iy <= ny/2) ? iy : ny - iy;
  fy = ky/(ny*cmppix[1]);
 for (ix = 0; ix < n2; ix++) {
  kx = (ix <= nx/2) ? ix : nx - ix;
  fx = kx/(nx*cmppix[0]);
  f2 = fx*fx + fy*fy + fz*fz;
  factor = exp (q*f2);
  a[i] *= factor;
   b[i] *= factor;
  i++;
 }}}
 fft_ (a, b, &one, &nz, &n2ny, &one);
 fft_ (a, b, &nz, &ny, &n2, &one);
 k = jndex = 0;
 for (iz = 0; iz < nz; iz++) {
 for (iy = 0; iy < ny; iy++) {
  realt_ (a + k, b + k, &one, &n1, &one, &one);
  fft_ (a + k, b + k, &one, &n1, &one, &one);
  for (i = ix = 0; ix < nx; ix += 2, i++) {
   image[jndex++] = (a + k)[i];
   image[jndex++] = (b + k)[i];
  }
  k += n2;
 }}
 free (a);
 free (b);
}

variable_types:
image
float *

variable_types:
pnx
int *

variable_types:
pny
int *

variable_types:
pnz
int *

variable_types:
cmppix
float *

variable_types:
fhalf
float *

variable_types:
a
float *

variable_types:
b
float *

variable_types: q double

variable_types: factor double

variable_types: fx double

variable_types: fy double

variable_types: fz double

variable_types: i int

variable_types: k int

variable_types: jndex int

variable_types: ix int

variable_types: iy int

variable_types: iz int

variable_types: nx int

variable_types: ny int

variable_types: nz int

variable_types: kx int

variable_types: ky int

variable_types: kz int

variable_types: one int

variable_types: negone int


repo: ytHu/symtable

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

if ( !a1 )
_assert_fail("pcKey != NULL", "hash.c", 0xAu, "SymTable_hash");
v2 = *a1;
v3 = a1 + 1;
for ( i = 0; v2; v2 = *(v3 - 1) )
{
i = v2 + 65599 * i;
++v3;
}
return i % a2;
}

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

if ( !a1 )
_assert_fail("pcKey != NULL", "hash.c", 0xAu, "SymTable_hash");
v2 = *a1;
v3 = a1 + 1;
for ( i = 0; v2; v2 = *(v3 - 1) )
{
i = v2 + 65599 * i;
++v3;
}
return i % a2;
}

original_code:
int SymTable_hash(const char *pcKey, int iBucketCount)
{
    enum { HASH_MULTIPLIER = 65599 };
    int i;
    unsigned int uiHash = 0U;
    ((pcKey != ((void *)0)) ? (void) (0) : __assert_fail ("pcKey != NULL", "hash.c", 10, __extension__ __PRETTY_FUNCTION__));
    for(i = 0; pcKey[i] != '\0'; i++)
        uiHash = uiHash * (unsigned int)HASH_MULTIPLIER + (unsigned int)pcKey[i];
    return (int)(uiHash%(unsigned int)iBucketCount);
}

canonical_original_code:
int SymTable_hash(char *pcKey, int iBucketCount)
{
    enum { HASH_MULTIPLIER = 65599 };
    int i;
    unsigned int uiHash = 0U;
    ((pcKey != ((void *)0)) ? (void) (0) : __assert_fail ("pcKey != NULL", "hash.c", 10, __extension__ __PRETTY_FUNCTION__));
    for(i = 0; pcKey[i] != '\0'; i++)
        uiHash = uiHash * (unsigned int)HASH_MULTIPLIER + (unsigned int)pcKey[i];
    return (int)(uiHash%(unsigned int)iBucketCount);
}

variable_types:
pcKey
char *

variable_types: iBucketCount int

variable_types:
uiHash
unsigned int


original_code:
static void SymTable_rehash(SymTable_t oSymTable)
{
    int i, hashCode;
    struct Bind *oldBind = oSymTable->bind;
    struct Bind *tmpBind, *newBind, *bind;
    int oldBucketCounts = oSymTable->bucketCounts[0];
    ++(oSymTable->bucketCounts);
    oSymTable->bind = (struct Bind *)malloc(oSymTable->bucketCounts[0]*sizeof(struct Bind));
    if(!(oSymTable->bind))
    {
        oSymTable->bind = oldBind;
        --(oSymTable->bucketCounts);
        return ;
    }
    for(i = 0; i < oSymTable->bucketCounts[0]; ++i)
    {
        oSymTable->bind[i].next = ((void *)0);
        oSymTable->bind[i].key = ((void *)0);
    }
    for(i = 0; i < oldBucketCounts; ++i)
    {
        bind = oldBind[i].next;
        while(bind)
        {
            tmpBind=bind->next;
            hashCode = SymTable_hash(bind->key, oSymTable->bucketCounts[0]);
            newBind = &(oSymTable->bind[hashCode]);
            while(newBind->next)
                newBind = newBind->next;
            newBind->next = bind;
            bind->next = ((void *)0);
            bind = tmpBind;
        }
    }
    free(oldBind);
}

canonical_original_code:
static void SymTable_rehash(struct SymTable *oSymTable)
{
    int i; int hashCode;
    struct Bind *oldBind = oSymTable->bind;
    struct Bind *tmpBind; struct Bind *newBind; struct Bind *bind;
    int oldBucketCounts = oSymTable->bucketCounts[0];
    ++(oSymTable->bucketCounts);
    oSymTable->bind = (struct Bind *)malloc(oSymTable->bucketCounts[0]*sizeof(struct Bind));
    if(!(oSymTable->bind))
    {
        oSymTable->bind = oldBind;
        --(oSymTable->bucketCounts);
        return ;
    }
    for(i = 0; i < oSymTable->bucketCounts[0]; ++i)
    {
        oSymTable->bind[i].next = ((void *)0);
        oSymTable->bind[i].key = ((void *)0);
    }
    for(i = 0; i < oldBucketCounts; ++i)
    {
        bind = oldBind[i].next;
        while(bind)
        {
            tmpBind=bind->next;
            hashCode = SymTable_hash(bind->key, oSymTable->bucketCounts[0]);
            newBind = &(oSymTable->bind[hashCode]);
            while(newBind->next)
                newBind = newBind->next;
            newBind->next = bind;
            bind->next = ((void *)0);
            bind = tmpBind;
        }
    }
    free(oldBind);
}

variable_types: struct SymTable { struct Bind { char *key; void *val; struct Bind *next; } *bind; int numBinds; int *bucketCounts; } *

variable_types: i int

variable_types: hashCode int

variable_types: oldBucketCounts int

user_defined_types: struct SymTable { struct Bind *bind; int numBinds; int *bucketCounts; }


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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int SymTable_getLength(SymTable_t oSymTable)
{
    if(!oSymTable)
        return -1;
    return oSymTable->numBinds;
}

canonical_original_code:
int SymTable_getLength(struct SymTable *oSymTable)
{
    if(!oSymTable)
        return -1;
    return oSymTable->numBinds;
}

variable_types: struct SymTable { struct Bind { char *key; void *val; struct Bind *next; } *bind; int numBinds; } *

user_defined_types: struct SymTable { struct Bind *bind; int numBinds; }


decompiled_code:
__int64 log_print(int a1, const char *a2, ...)
{
unsigned int v2; // ebx
int v3; // ebx
struct tm *v4; // rax
unsigned int v5; // ebx
int *v6; // rbp
FILE *v7; // rdi
int v9; // edx
int v10; // ecx
int v11; // er8
int v12; // er9
char *v13; // rax
time_t v14; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v2 = 0;
if ( log_prio <= a1 )
{
if ( buffer || (buffer = (char *)malloc(0x2000uLL)) != 0LL )
{
v3 = 0;
if ( log_fd )
{
time(&v14);
v4 = localtime(&v14);
v3 = strftime(buffer, 0x2000uLL, "%b %d %H:%M:%S :", v4);
}
va_start(arg, a2);
v5 = vsnprintf(&buffer[v3], 0x2000 - v3, a2, arg) + v3;
if ( v5 > 0x1FFF )
{
*_errno_location() = 0;
v2 = log_print(1, (unsigned int)"log_print: arguments too long", v9, v10, v11, v12, v14);
}
else
{
v6 = _errno_location();
if ( *v6 )
{
v13 = strerror(*v6);
snprintf(&buffer[v5], (int)(0x2000 - v5), ": %s", v13);
*v6 = 0;
}
v7 = log_fd;
if ( !log_fd )
v7 = stderr;
v2 = fprintf(v7, "%s\n", buffer);
fflush(log_fd);
}
}
else
{
fwrite("log_print(): out of memory\n", 1uLL, 0x1BuLL, stderr);
v2 = -1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 func0(int a1, const char *a2, ...)
{
unsigned int v2; // ebx
int v3; // ebx
struct tm *v4; // rax
unsigned int v5; // ebx
int *v6; // rbp
FILE *v7; // rdi
int v9; // edx
int v10; // ecx
int v11; // er8
int v12; // er9
char *v13; // rax
time_t v14; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v2 = 0;
if ( log_prio <= a1 )
{
if ( buffer || (buffer = (char *)malloc(0x2000uLL)) != 0LL )
{
v3 = 0;
if ( log_fd )
{
time(&v14);
v4 = localtime(&v14);
v3 = strftime(buffer, 0x2000uLL, "%b %d %H:%M:%S :", v4);
}
va_start(arg, a2);
v5 = vsnprintf(&buffer[v3], 0x2000 - v3, a2, arg) + v3;
if ( v5 > 0x1FFF )
{
*_errno_location() = 0;
v2 = func0(1, (unsigned int)"log_print: arguments too long", v9, v10, v11, v12, v14);
}
else
{
v6 = _errno_location();
if ( *v6 )
{
v13 = strerror(*v6);
snprintf(&buffer[v5], (int)(0x2000 - v5), ": %s", v13);
*v6 = 0;
}
v7 = log_fd;
if ( !log_fd )
v7 = stderr;
v2 = fprintf(v7, "%s\n", buffer);
fflush(log_fd);
}
}
else
{
fwrite("log_print(): out of memory\n", 1uLL, 0x1BuLL, stderr);
v2 = -1;
}
}
return v2;
}

original_code:
int log_print(int prio, const char *fmt, ...)
{
 va_list az;
 int len = 0, retval;
 if (prio < log_prio)
  return 0;
 if (buffer == ((void *)0)) {
  buffer = malloc(8192);
  if (buffer == ((void *)0)) {
   fprintf(stderr, "log_print(): out of memory\n");
   return -1;
  }
 }
 if (log_fd != ((void *)0)) {
  time_t tzgr;
  time(&tzgr);
  len += strftime(buffer, 8192, "%b %d %H:%M:%S :", localtime(&tzgr));
 }
 __builtin_va_start(az,fmt);
 len += vsnprintf(buffer + len, 8192 - len, fmt, az);
 __builtin_va_end(az);
 if (len < 0 || len >= 8192) {
  (*__errno_location ()) = 0;
  return log_print(1, "log_print: arguments too long");
 }
 if ((*__errno_location ())) {
  len += snprintf(buffer + len, 8192 - len, ": %s", strerror((*__errno_location ())));
  (*__errno_location ()) = 0;
 }
 retval = fprintf((log_fd ? log_fd : stderr), "%s\n", buffer);
 fflush(log_fd);
 return retval;
}

canonical_original_code:
int log_print(int prio, char *fmt, ...)
{
 __builtin_va_list az;
 int len = 0; int retval;
 if (prio < log_prio)
  return 0;
 if (buffer == ((void *)0)) {
  buffer = malloc(8192);
  if (buffer == ((void *)0)) {
   fprintf(stderr, "log_print(): out of memory\n");
   return -1;
  }
 }
 if (log_fd != ((void *)0)) {
  long tzgr;
  time(&tzgr);
  len += strftime(buffer, 8192, "%b %d %H:%M:%S :", localtime(&tzgr));
 }
 __builtin_va_start(az,fmt);
 len += vsnprintf(buffer + len, 8192 - len, fmt, az);
 __builtin_va_end(az);
 if (len < 0 || len >= 8192) {
  (*__errno_location ()) = 0;
  return log_print(1, "log_print: arguments too long");
 }
 if ((*__errno_location ())) {
  len += snprintf(buffer + len, 8192 - len, ": %s", strerror((*__errno_location ())));
  (*__errno_location ()) = 0;
 }
 retval = fprintf((log_fd ? log_fd : stderr), "%s\n", buffer);
 fflush(log_fd);
 return retval;
}

variable_types: prio int

variable_types:
fmt
char *

variable_types: len int

variable_types: retval int

variable_types: tzgr long


decompiled_code:
void log_close()
{
if ( buffer )
free(buffer);
if ( log_fd )
fclose(log_fd);
}

canonical_decompiled_code:
void func1()
{
if ( buffer )
free(buffer);
if ( log_fd )
fclose(log_fd);
}

original_code:
void log_close(void)
{
 if (buffer)
  free(buffer);
 if (log_fd)
  fclose(log_fd);
}

canonical_original_code:
void log_close()
{
 if (buffer)
  free(buffer);
 if (log_fd)
  fclose(log_fd);
}


decompiled_code:
__int64 __fastcall log_init(char *filename)
{
if ( log_fd )
log_close();
log_fd = fopen(filename, "a");
if ( log_fd )
return 0LL;
fwrite("log_init(): can not open logfile", 1uLL, 0x20uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *filename)
{
if ( log_fd )
func1();
log_fd = fopen(filename, "a");
if ( log_fd )
return 0LL;
fwrite("log_init(): can not open logfile", 1uLL, 0x20uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int log_init(const char *logfile)
{
 if (log_fd != ((void *)0))
  log_close();
 log_fd = fopen(logfile, "a");
 if (log_fd == ((void *)0)) {
  fprintf(stderr, "log_init(): can not open logfile");
  return -1;
 }
 return 0;
}

canonical_original_code:
int log_init(char *logfile)
{
 if (log_fd != ((void *)0))
  log_close();
 log_fd = fopen(logfile, "a");
 if (log_fd == ((void *)0)) {
  fprintf(stderr, "log_init(): can not open logfile");
  return -1;
 }
 return 0;
}

variable_types:
logfile
char *


decompiled_code:
void __fastcall log_setprio(int a1)
{
log_prio = a1;
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
log_prio = a1;
}

original_code:
void log_setprio(int prio)
{
 log_prio = prio;
}


original_code:
int linebuffer_read(struct linebuffer *lbuf, int fd)
{
 char buf[32];
 int len = read(fd, buf, sizeof(buf));
 if (len <= 0)
  return -1;
 int i;
 for (i = 0; i < len; i++) {
  if (buf[i] == 0x08 && lbuf->pos > 0) {
   lbuf->pos--;
  } else if (buf[i] >= ' ' || buf[i] == '\r') {
   lbuf->data[lbuf->pos++] = buf[i];
  }
  if (lbuf->pos > lbuf->size)
   return -1;
 }
 return 0;
}

variable_types: struct linebuffer { int size; int pos; char data[]; } *

variable_types: fd int

variable_types:
buf
char [32]


decompiled_code:
char *__fastcall linebuffer_get(__int64 a1)
{
char *v1; // r12
_BYTE *v2; // rax
_BYTE *v3; // rbp
int v4; // ebx
char *v5; // r13
int v6; // ebx

v1 = (char *)(a1 + 8);
v2 = memchr((const void *)(a1 + 8), 13, *(int *)(a1 + 4));
v3 = v2;
if ( !v2 )
return 0LL;
*v2 = 0;
v4 = (_DWORD)v2 - (_DWORD)v1;
v5 = 0LL;
if ( (int)v2 - (int)v1 > 0 )
v5 = strdup(v1);
v6 = *(_DWORD *)(a1 + 4) + ~v4;
*(_DWORD *)(a1 + 4) = v6;
memmove(v1, v3 + 1, v6);
return v5;
}

original_code:
char * linebuffer_get(struct linebuffer *lbuf)
{
 char *newline = memchr(lbuf->data, '\r', lbuf->pos);
 if (newline == ((void *)0))
  return ((void *)0);
 char *retval = ((void *)0);
 *newline = '\0';
 int len = newline - lbuf->data;
 if (len > 0)
  retval = strdup(lbuf->data);
 lbuf->pos -= len +1;
 memmove(lbuf->data, newline +1, lbuf->pos);
 return retval;
}

canonical_original_code:
char *linebuffer_get(struct linebuffer *lbuf)
{
 char *newline = memchr(lbuf->data, '\r', lbuf->pos);
 if (newline == ((void *)0))
  return ((void *)0);
 char *retval = ((void *)0);
 *newline = '\0';
 int len = newline - lbuf->data;
 if (len > 0)
  retval = strdup(lbuf->data);
 lbuf->pos -= len +1;
 memmove(lbuf->data, newline +1, lbuf->pos);
 return retval;
}

variable_types:
newline
char *

variable_types:
retval
char *

user_defined_types: struct linebuffer { int size; int pos; char data[]; }


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

result = *(unsigned int *)(a1 + 4);
*(_DWORD *)(a1 + 4) = 0;
return result;
}

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

result = *(unsigned int *)(a1 + 4);
*(_DWORD *)(a1 + 4) = 0;
return result;
}

original_code:
int linebuffer_clear(struct linebuffer *lbuf)
{
 int oldpos = lbuf->pos;
 lbuf->pos = 0;
 return oldpos;
}

variable_types: oldpos int


decompiled_code:
__int64 patch_dot1qvlan()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func7()
{
return 0xFFFFFFFFLL;
}

original_code:
static int patch_dot1qvlan(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 return -1;
 int id = code - patch->code;
 if (id < 1 || id > 32)
  return -1;
 char *tmp, *buf = strdup(parameter);
 int vlanid = atoi(strtok_r(buf, ":", &tmp));
 char *name = strtok_r(((void *)0), ":", &tmp);
 strncpy(config + 0x63e8 + (id -1) * 0xd0, name, 12);
 *((uint16_t *)(config + 0x64b4 + (id -1) * 0xd0)) = htons(vlanid);
 *((uint8_t *)(config + 0x64b6 + (id -1) * 0xd0)) = 0x03;
 *((uint32_t *)(config + 0x63f4 + (id -1) * 0xd0)) = 0x03FFFFFF;
 *((uint32_t *)(config + 0x6434 + (id -1) * 0xd0)) = 0x03FFFFFF;
 *((uint32_t *)(config + 0x6474 + (id -1) * 0xd0)) = 0;
 free(buf);
 return 0;
}

canonical_original_code:
static int patch_dot1qvlan(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 return -1;
 int id = code - patch->code;
 if (id < 1 || id > 32)
  return -1;
 char *tmp; char *buf = strdup(parameter);
 int vlanid = atoi(strtok_r(buf, ":", &tmp));
 char *name = strtok_r(((void *)0), ":", &tmp);
 strncpy(config + 0x63e8 + (id -1) * 0xd0, name, 12);
 *((unsigned short *)(config + 0x64b4 + (id -1) * 0xd0)) = htons(vlanid);
 *((unsigned char *)(config + 0x64b6 + (id -1) * 0xd0)) = 0x03;
 *((unsigned int *)(config + 0x63f4 + (id -1) * 0xd0)) = 0x03FFFFFF;
 *((unsigned int *)(config + 0x6434 + (id -1) * 0xd0)) = 0x03FFFFFF;
 *((unsigned int *)(config + 0x6474 + (id -1) * 0xd0)) = 0;
 free(buf);
 return 0;
}

variable_types:
config
void *

variable_types: struct cfg_patch { int code; int mask; int (*patch)(void *config, struct cfg_patch *patch, int code, char *parameter); int offset; int size; int min; int max; } *

variable_types: code int

variable_types:
parameter
char *

variable_types: id int

variable_types:
tmp
char *

variable_types:
buf
char *

variable_types: vlanid int

variable_types:
name
char *


decompiled_code:
__int64 patch_dot1qport()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func8()
{
return 0xFFFFFFFFLL;
}

original_code:
static int patch_dot1qport(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 return -1;
 int id = code - patch->code;
 if (id < 1 || id > 32)
  return -1;
 char *tmp, *buf = strdup(parameter);
 int port = atoi(strtok_r(buf, ":", &tmp));
 char *control = strtok_r(((void *)0), ":", &tmp);
 char *tagging = strtok_r(((void *)0), ":", &tmp);
 if (port < 1 || port > 26) {
  free(buf);
  return -1;
 }
 uint32_t *a = (uint32_t *)(config + 0x63f4 + (id -1) * 0xd0);
 uint32_t *b = (uint32_t *)(config + 0x6434 + (id -1) * 0xd0);
 uint32_t *c = (uint32_t *)(config + 0x6474 + (id -1) * 0xd0);
 uint32_t value = (1 << (port -1));
 if (strcmp(control, "normal") == 0) {
  *a &= ~value;
  *b &= ~value;
 } else if (strcmp(control, "fixed") == 0) {
  *a &= ~value;
  *b |= value;
 } else if (strcmp(control, "forbidden") == 0) {
  *a |= value;
  *b |= value;
 } else {
  free(buf);
  return -1;
 }
 if (strcmp(tagging, "tagging") == 0)
  *c |= value;
 else
  *c &= ~value;
 free(buf);
 return 0;
}

canonical_original_code:
static int patch_dot1qport(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 return -1;
 int id = code - patch->code;
 if (id < 1 || id > 32)
  return -1;
 char *tmp; char *buf = strdup(parameter);
 int port = atoi(strtok_r(buf, ":", &tmp));
 char *control = strtok_r(((void *)0), ":", &tmp);
 char *tagging = strtok_r(((void *)0), ":", &tmp);
 if (port < 1 || port > 26) {
  free(buf);
  return -1;
 }
 unsigned int *a = (uint32_t *)(config + 0x63f4 + (id -1) * 0xd0);
 unsigned int *b = (uint32_t *)(config + 0x6434 + (id -1) * 0xd0);
 unsigned int *c = (uint32_t *)(config + 0x6474 + (id -1) * 0xd0);
 unsigned int value = (1 << (port -1));
 if (strcmp(control, "normal") == 0) {
  *a &= ~value;
  *b &= ~value;
 } else if (strcmp(control, "fixed") == 0) {
  *a &= ~value;
  *b |= value;
 } else if (strcmp(control, "forbidden") == 0) {
  *a |= value;
  *b |= value;
 } else {
  free(buf);
  return -1;
 }
 if (strcmp(tagging, "tagging") == 0)
  *c |= value;
 else
  *c &= ~value;
 free(buf);
 return 0;
}

variable_types: port int

variable_types:
control
char *

variable_types:
tagging
char *

variable_types:
a
unsigned int *

variable_types:
b
unsigned int *

variable_types:
c
unsigned int *

variable_types:
value
unsigned int

user_defined_types: struct cfg_patch { int code; int mask; int (*patch)(void *config, struct cfg_patch *patch, int code, char *parameter); int offset; int size; int min; int max; }


decompiled_code:
__int64 __fastcall patch_8bit(__int64 a1, int *a2, __int64 a3, const char *a4)
{
int v4; // eax

v4 = atoi(a4);
if ( a2[6] > v4 )
return 0xFFFFFFFFLL;
if ( a2[7] < v4 )
return 0xFFFFFFFFLL;
*(_BYTE *)(a1 + a2[4]) = v4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int *a2, __int64 a3, const char *a4)
{
int v4; // eax

v4 = atoi(a4);
if ( a2[6] > v4 )
return 0xFFFFFFFFLL;
if ( a2[7] < v4 )
return 0xFFFFFFFFLL;
*(_BYTE *)(a1 + a2[4]) = v4;
return 0LL;
}

original_code:
static int patch_8bit(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 int value = atoi(parameter);
 if (value < patch->min || value > patch->max)
  return -1;
 *((uint8_t *)(config + patch->offset)) = value;
 return 0;
}

canonical_original_code:
static int patch_8bit(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 int value = atoi(parameter);
 if (value < patch->min || value > patch->max)
  return -1;
 *((unsigned char *)(config + patch->offset)) = value;
 return 0;
}

variable_types: value int


decompiled_code:
__int64 __fastcall patch_portenable(__int64 a1, _DWORD *a2, int a3, const char *a4)
{
int v4; // edx

v4 = a3 - *a2;
if ( (unsigned int)(v4 - 1) > 0x19 )
return 0xFFFFFFFFLL;
*(_BYTE *)(a1 + 112 * (v4 - 1) + 13163) = strcmp(a4, "on") == 0 ? 3 : 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, _DWORD *a2, int a3, const char *a4)
{
int v4; // edx

v4 = a3 - *a2;
if ( (unsigned int)(v4 - 1) > 0x19 )
return 0xFFFFFFFFLL;
*(_BYTE *)(a1 + 112 * (v4 - 1) + 13163) = strcmp(a4, "on") == 0 ? 3 : 1;
return 0LL;
}

original_code:
static int patch_portenable(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 int port = code - patch->code;
 if (port < 1 || port > 26)
  return -1;
 int status = (strcmp(parameter, "on") == 0);
 *((uint8_t *)(config + 0x336b + (port -1) * 0x70)) = (status ? 0x03 : 0x01);
 return 0;
}

canonical_original_code:
static int patch_portenable(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 int port = code - patch->code;
 if (port < 1 || port > 26)
  return -1;
 int status = (strcmp(parameter, "on") == 0);
 *((unsigned char *)(config + 0x336b + (port -1) * 0x70)) = (status ? 0x03 : 0x01);
 return 0;
}

variable_types:
config
void *

variable_types: status int


decompiled_code:
__int64 __fastcall patch_portvlan(__int64 a1, _DWORD *a2, int a3, const char *a4)
{
int v4; // edx
int v5; // er14
char *v6; // r15
char *v7; // rax
unsigned int v8; // er13
bool v9; // bp
_BOOL4 v10; // er12
int v11; // eax
char *save_ptr[8]; // [rsp+0h] [rbp-40h] BYREF

v4 = a3 - *a2;
if ( (unsigned int)(v4 - 1) > 0x19 )
return 0xFFFFFFFFLL;
v5 = v4;
v6 = strdup(a4);
v7 = strtok_r(v6, ":", save_ptr);
v8 = atoi(v7);
v9 = strcmp(strtok_r(0LL, ":", save_ptr), "check") == 0;
v10 = strcmp(strtok_r(0LL, ":", save_ptr), "all") != 0;
free(v6);
if ( v8 > 0xFF )
return 0xFFFFFFFFLL;
v11 = 16 * (3 * v5 - 3);
*(_BYTE *)(a1 + v11 + 24319) = v8;
*(_BYTE *)(a1 + v11 + 24320) = v10;
*(_BYTE *)(a1 + v11 + 24321) = v9;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, _DWORD *a2, int a3, const char *a4)
{
int v4; // edx
int v5; // er14
char *v6; // r15
char *v7; // rax
unsigned int v8; // er13
bool v9; // bp
_BOOL4 v10; // er12
int v11; // eax
char *save_ptr[8]; // [rsp+0h] [rbp-40h] BYREF

v4 = a3 - *a2;
if ( (unsigned int)(v4 - 1) > 0x19 )
return 0xFFFFFFFFLL;
v5 = v4;
v6 = strdup(a4);
v7 = strtok_r(v6, ":", save_ptr);
v8 = atoi(v7);
v9 = strcmp(strtok_r(0LL, ":", save_ptr), "check") == 0;
v10 = strcmp(strtok_r(0LL, ":", save_ptr), "all") != 0;
free(v6);
if ( v8 > 0xFF )
return 0xFFFFFFFFLL;
v11 = 16 * (3 * v5 - 3);
*(_BYTE *)(a1 + v11 + 24319) = v8;
*(_BYTE *)(a1 + v11 + 24320) = v10;
*(_BYTE *)(a1 + v11 + 24321) = v9;
return 0LL;
}

original_code:
static int patch_portvlan(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 int port = code - patch->code;
 if (port < 1 || port > 26)
  return -1;
 char *tmp, *buf = strdup(parameter);
 int vlanid = atoi(strtok_r(buf, ":", &tmp));
 int check_ingress = (strcmp(strtok_r(((void *)0), ":", &tmp), "check") == 0);
 int accept_all = (strcmp(strtok_r(((void *)0), ":", &tmp), "all") == 0);
 free(buf);
 if (vlanid < 0 || vlanid > 255)
  return -1;
 *((uint8_t *)(config + 0x5eff + (port -1) * 0x30)) = vlanid;
 *((uint8_t *)(config + 0x5f00 + (port -1) * 0x30)) = accept_all ? 0x00 : 0x01;
 *((uint8_t *)(config + 0x5f01 + (port -1) * 0x30)) = check_ingress ? 0x01 : 0x00;
 return 0;
}

canonical_original_code:
static int patch_portvlan(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 int port = code - patch->code;
 if (port < 1 || port > 26)
  return -1;
 char *tmp; char *buf = strdup(parameter);
 int vlanid = atoi(strtok_r(buf, ":", &tmp));
 int check_ingress = (strcmp(strtok_r(((void *)0), ":", &tmp), "check") == 0);
 int accept_all = (strcmp(strtok_r(((void *)0), ":", &tmp), "all") == 0);
 free(buf);
 if (vlanid < 0 || vlanid > 255)
  return -1;
 *((unsigned char *)(config + 0x5eff + (port -1) * 0x30)) = vlanid;
 *((unsigned char *)(config + 0x5f00 + (port -1) * 0x30)) = accept_all ? 0x00 : 0x01;
 *((unsigned char *)(config + 0x5f01 + (port -1) * 0x30)) = check_ingress ? 0x01 : 0x00;
 return 0;
}

variable_types: struct cfg_patch { int code; int mask; int (*patch)(void *config, struct cfg_patch *patch, int code, char *parameter); int offset; int size; int min; int max; } *

variable_types: code int


decompiled_code:
__int64 __fastcall patch_portname(__int64 a1, _DWORD *a2, int a3, const char *a4)
{
int v4; // edx

v4 = a3 - *a2;
if ( (unsigned int)(v4 - 1) > 0x19 )
return 0xFFFFFFFFLL;
strncpy((char *)(a1 + 112 * (v4 - 1) + 13164), a4, (int)a2[5]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, _DWORD *a2, int a3, const char *a4)
{
int v4; // edx

v4 = a3 - *a2;
if ( (unsigned int)(v4 - 1) > 0x19 )
return 0xFFFFFFFFLL;
strncpy((char *)(a1 + 112 * (v4 - 1) + 13164), a4, (int)a2[5]);
return 0LL;
}

original_code:
static int patch_portname(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 int port = code - patch->code;
 if (port < 1 || port > 26)
  return -1;
 strncpy(config + 0x336c + (port -1) * 0x70, parameter, patch->size);
 return 0;
}

canonical_original_code:
static int patch_portname(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 int port = code - patch->code;
 if (port < 1 || port > 26)
  return -1;
 strncpy(config + 0x336c + (port -1) * 0x70, parameter, patch->size);
 return 0;
}

variable_types:
parameter
char *


original_code:
static int patch_snmp_community(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 strncpy(config + 0x00A0 + patch->offset, parameter, patch->size);
 *((uint8_t *)(config + 0x0101)) = 0x01;
 strncpy(config + 0x9914 + patch->offset, parameter, patch->size);
 *((uint8_t *)(config + 0x9975)) = 0x01;
 strncpy(config + 0x9984 + patch->offset, parameter, patch->size);
 *((uint8_t *)(config + 0x99e5)) = 0x01;
 strncpy(config + 0x99f4 + patch->offset, parameter, patch->size);
 *((uint8_t *)(config + 0x9a55)) = 0x01;
 return 0;
}

canonical_original_code:
static int patch_snmp_community(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 strncpy(config + 0x00A0 + patch->offset, parameter, patch->size);
 *((unsigned char *)(config + 0x0101)) = 0x01;
 strncpy(config + 0x9914 + patch->offset, parameter, patch->size);
 *((unsigned char *)(config + 0x9975)) = 0x01;
 strncpy(config + 0x9984 + patch->offset, parameter, patch->size);
 *((unsigned char *)(config + 0x99e5)) = 0x01;
 strncpy(config + 0x99f4 + patch->offset, parameter, patch->size);
 *((unsigned char *)(config + 0x9a55)) = 0x01;
 return 0;
}


decompiled_code:
__int64 __fastcall patch_string(__int64 a1, __int64 a2, __int64 a3, const char *a4)
{
strncpy((char *)(*(int *)(a2 + 16) + a1), a4, *(int *)(a2 + 20));
return 0LL;
}

original_code:
static int patch_string(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 strncpy(config + patch->offset, parameter, patch->size);
 return 0;
}

canonical_original_code:
static int patch_string(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 strncpy(config + patch->offset, parameter, patch->size);
 return 0;
}