decompiled_code:
__int64 __fastcall bf_init(char *nptr)
{
char *v1; // rax
char *v2; // rbx
const char *v3; // rbp
char *v4; // rax
char *v5; // rbx
unsigned __int8 v6; // al
unsigned __int8 v7; // bp
_BYTE *v8; // rax
__int64 v9; // rsi
char *v10; // r15
int v11; // ebx
int v12; // er12
unsigned int v13; // er14
char v14; // r13
char *v15; // rdi
__int64 v16; // r13
__m128i *v17; // rax
char v18; // al
__int64 result; // rax
__int64 v20; // r13
__m128i *v21; // rax
void *v22; // rcx
__int64 v23; // rdx
__int64 v24; // rdx

v1 = strchr(nptr, 58);
if ( !v1 )
goto LABEL_45;
*v1 = 0;
v2 = v1;
bf_options = atoi(nptr);
if ( bf_options <= 0 )
{
fwrite("Error: minimum length must be between 1 and 127, format: -x min:max:types\n", 1uLL, 0x4AuLL, stderr);
return 1LL;
}
v3 = v2 + 1;
if ( !v2[1] )
{
fwrite("Error: no maximum length specified for -x min:max:types!\n", 1uLL, 0x39uLL, stderr);
return 1LL;
}
v4 = strchr(v2 + 1, 58);
v5 = v4;
if ( !v4 )
{
LABEL_45:
fwrite("Error: Invalid option format for -x\n", 1uLL, 0x24uLL, stderr);
return 1LL;
}
*v4 = 0;
v6 = atoi(v3);
v7 = bf_options;
*(&bf_options + 1) = v6;
if ( v6 < v7 )
{
fwrite("Error: you specified a minimum length higher than the maximum length!\n", 1uLL, 0x46uLL, stderr);
result = 1LL;
}
else
{
if ( !v5[1] )
{
fwrite("Error: charset not specified!\n", 1uLL, 0x1EuLL, stderr);
return 1LL;
}
v8 = malloc(0x100uLL);
*((_QWORD *)&bf_options + 34) = v8;
if ( v8 )
{
v9 = (unsigned int)v5[1];
*v8 = 0;
v10 = v5 + 1;
if ( (_BYTE)v9 )
{
v11 = 0;
v12 = 0;
while ( (_BYTE)v9 != 65 )
{
if ( (_BYTE)v9 == 97 )
{
v12 += 26;
v15 = (char *)*((_QWORD *)&bf_options + 34);
if ( 256 - v12 <= 0 )
goto LABEL_49;
if ( (v11 & 1) != 0 )
{
free(v15);
fwrite("Error: 'a' specified more than once in charset!\n", 1uLL, 0x30uLL, stderr);
return 1LL;
}
v11 |= 1u;
v16 = *((_QWORD *)&bf_options + 34);
v17 = (__m128i *)(v16 + strlen(v15));
++v10;
strcpy(v17[1].m128i_i8, "qrstuvwxyz");
*v17 = _mm_load_si128((const __m128i *)&LC17);
v9 = (unsigned int)*v10;
if ( !*v10 )
{
LABEL_22:
v7 = bf_options;
v18 = v12;
goto LABEL_23;
}
}
else
{
if ( (_BYTE)v9 == 49 )
{
v12 += 10;
v15 = (char *)*((_QWORD *)&bf_options + 34);
if ( 256 - v12 <= 0 )
{
LABEL_49:
free(v15);
fprintf(stderr, "Error: charset specification exceeds %d characters.\n", 256LL);
return 1LL;
}
if ( (v11 & 4) != 0 )
{
free(v15);
fwrite("Error: '1' specified more than once in charset!\n", 1uLL, 0x30uLL, stderr);
return 1LL;
}
v11 |= 4u;
strcat(*((char **)&bf_options + 34), "0123456789");
}
else
{
if ( (unsigned __int8)(v9 - 50) <= 7u || (_BYTE)v9 == 48 )
{
if ( (v11 & 4) != 0 )
{
printf(
"[ERROR] character %c defined in -x although the whole number range was already defined by '1', ignored\n",
v9);
goto LABEL_16;
}
printf("[WARNING] adding character %c for -x, note that '1' will add all numbers from 0-9\n", v9);
}
v13 = *v10;
v14 = *v10;
if ( (unsigned int)(tolower(v13) - 98) > 0x18 )
goto LABEL_14;
if ( (v11 & 2) == 0 )
{
v22 = &unk_8E0;
if ( v14 >= 91 )
v22 = &unk_8E3;
v23 = 65LL;
if ( v14 >= 91 )
v23 = 97LL;
printf(
"[WARNING] adding character %c for -x, note that '%c' will add all %scase letters\n",
v13,
v23,
v22);
LABEL_14:
++v12;
v15 = (char *)*((_QWORD *)&bf_options + 34);
if ( 256 - v12 <= 0 )
goto LABEL_49;
v15[v12 - 1] = *v10;
*(_BYTE *)(*((_QWORD *)&bf_options + 34) + v12) = 0;
goto LABEL_16;
}
v24 = 65LL;
if ( v14 >= 91 )
v24 = 97LL;
printf(
"[ERROR] character %c defined in -x although the whole letter range was already defined by '%c', ignored\n",
v13,
v24);
}
LABEL_16:
v9 = (unsigned int)*++v10;
if ( !(_BYTE)v9 )
goto LABEL_22;
}
}
v12 += 26;
v15 = (char *)*((_QWORD *)&bf_options + 34);
if ( 256 - v12 <= 0 )
goto LABEL_49;
if ( (v11 & 2) != 0 )
{
free(v15);
fwrite("Error: 'A' specified more than once in charset!\n", 1uLL, 0x30uLL, stderr);
return 1LL;
}
v11 |= 2u;
v20 = *((_QWORD *)&bf_options + 34);
v21 = (__m128i *)(v20 + strlen(v15));
strcpy(v21[1].m128i_i8, "QRSTUVWXYZ");
*v21 = _mm_load_si128((const __m128i *)&LC18);
goto LABEL_16;
}
v18 = 0;
LOBYTE(v12) = 0;
LABEL_23:
*(&bf_options + 260) = v18;
*(&bf_options + 2) = v7;
*(_QWORD *)(&bf_options + 3) = 0LL;
*(_QWORD *)(&bf_options + 251) = 0LL;
memset(
(void *)(((_DWORD)&bf_options + 11) & 0xFFFFFFF8),
0,
8LL * (((_DWORD)&bf_options + 3 - (((_DWORD)&bf_options + 11) & 0xFFFFFFF8) + 256) >> 3));
result = debug;
if ( debug )
{
printf(
"[DEBUG] bfg INIT: from %d, to %d, len: %d, set: %s\n",
v7,
(unsigned __int8)*(&bf_options + 1),
(unsigned __int8)v12,
*((const char **)&bf_options + 34));
result = 0LL;
}
}
else
{
fwrite("Error: can't allocate enough memory!\n", 1uLL, 0x25uLL, stderr);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *nptr)
{
char *v1; // rax
char *v2; // rbx
const char *v3; // rbp
char *v4; // rax
char *v5; // rbx
unsigned __int8 v6; // al
unsigned __int8 v7; // bp
_BYTE *v8; // rax
__int64 v9; // rsi
char *v10; // r15
int v11; // ebx
int v12; // er12
unsigned int v13; // er14
char v14; // r13
char *v15; // rdi
__int64 v16; // r13
__m128i *v17; // rax
char v18; // al
__int64 result; // rax
__int64 v20; // r13
__m128i *v21; // rax
void *v22; // rcx
__int64 v23; // rdx
__int64 v24; // rdx

v1 = strchr(nptr, 58);
if ( !v1 )
goto LABEL_45;
*v1 = 0;
v2 = v1;
bf_options = atoi(nptr);
if ( bf_options <= 0 )
{
fwrite("Error: minimum length must be between 1 and 127, format: -x min:max:types\n", 1uLL, 0x4AuLL, stderr);
return 1LL;
}
v3 = v2 + 1;
if ( !v2[1] )
{
fwrite("Error: no maximum length specified for -x min:max:types!\n", 1uLL, 0x39uLL, stderr);
return 1LL;
}
v4 = strchr(v2 + 1, 58);
v5 = v4;
if ( !v4 )
{
LABEL_45:
fwrite("Error: Invalid option format for -x\n", 1uLL, 0x24uLL, stderr);
return 1LL;
}
*v4 = 0;
v6 = atoi(v3);
v7 = bf_options;
*(&bf_options + 1) = v6;
if ( v6 < v7 )
{
fwrite("Error: you specified a minimum length higher than the maximum length!\n", 1uLL, 0x46uLL, stderr);
result = 1LL;
}
else
{
if ( !v5[1] )
{
fwrite("Error: charset not specified!\n", 1uLL, 0x1EuLL, stderr);
return 1LL;
}
v8 = malloc(0x100uLL);
*((_QWORD *)&bf_options + 34) = v8;
if ( v8 )
{
v9 = (unsigned int)v5[1];
*v8 = 0;
v10 = v5 + 1;
if ( (_BYTE)v9 )
{
v11 = 0;
v12 = 0;
while ( (_BYTE)v9 != 65 )
{
if ( (_BYTE)v9 == 97 )
{
v12 += 26;
v15 = (char *)*((_QWORD *)&bf_options + 34);
if ( 256 - v12 <= 0 )
goto LABEL_49;
if ( (v11 & 1) != 0 )
{
free(v15);
fwrite("Error: 'a' specified more than once in charset!\n", 1uLL, 0x30uLL, stderr);
return 1LL;
}
v11 |= 1u;
v16 = *((_QWORD *)&bf_options + 34);
v17 = (__m128i *)(v16 + strlen(v15));
++v10;
strcpy(v17[1].m128i_i8, "qrstuvwxyz");
*v17 = _mm_load_si128((const __m128i *)&LC17);
v9 = (unsigned int)*v10;
if ( !*v10 )
{
LABEL_22:
v7 = bf_options;
v18 = v12;
goto LABEL_23;
}
}
else
{
if ( (_BYTE)v9 == 49 )
{
v12 += 10;
v15 = (char *)*((_QWORD *)&bf_options + 34);
if ( 256 - v12 <= 0 )
{
LABEL_49:
free(v15);
fprintf(stderr, "Error: charset specification exceeds %d characters.\n", 256LL);
return 1LL;
}
if ( (v11 & 4) != 0 )
{
free(v15);
fwrite("Error: '1' specified more than once in charset!\n", 1uLL, 0x30uLL, stderr);
return 1LL;
}
v11 |= 4u;
strcat(*((char **)&bf_options + 34), "0123456789");
}
else
{
if ( (unsigned __int8)(v9 - 50) <= 7u || (_BYTE)v9 == 48 )
{
if ( (v11 & 4) != 0 )
{
printf(
"[ERROR] character %c defined in -x although the whole number range was already defined by '1', ignored\n",
v9);
goto LABEL_16;
}
printf("[WARNING] adding character %c for -x, note that '1' will add all numbers from 0-9\n", v9);
}
v13 = *v10;
v14 = *v10;
if ( (unsigned int)(tolower(v13) - 98) > 0x18 )
goto LABEL_14;
if ( (v11 & 2) == 0 )
{
v22 = &unk_8E0;
if ( v14 >= 91 )
v22 = &unk_8E3;
v23 = 65LL;
if ( v14 >= 91 )
v23 = 97LL;
printf(
"[WARNING] adding character %c for -x, note that '%c' will add all %scase letters\n",
v13,
v23,
v22);
LABEL_14:
++v12;
v15 = (char *)*((_QWORD *)&bf_options + 34);
if ( 256 - v12 <= 0 )
goto LABEL_49;
v15[v12 - 1] = *v10;
*(_BYTE *)(*((_QWORD *)&bf_options + 34) + v12) = 0;
goto LABEL_16;
}
v24 = 65LL;
if ( v14 >= 91 )
v24 = 97LL;
printf(
"[ERROR] character %c defined in -x although the whole letter range was already defined by '%c', ignored\n",
v13,
v24);
}
LABEL_16:
v9 = (unsigned int)*++v10;
if ( !(_BYTE)v9 )
goto LABEL_22;
}
}
v12 += 26;
v15 = (char *)*((_QWORD *)&bf_options + 34);
if ( 256 - v12 <= 0 )
goto LABEL_49;
if ( (v11 & 2) != 0 )
{
free(v15);
fwrite("Error: 'A' specified more than once in charset!\n", 1uLL, 0x30uLL, stderr);
return 1LL;
}
v11 |= 2u;
v20 = *((_QWORD *)&bf_options + 34);
v21 = (__m128i *)(v20 + strlen(v15));
strcpy(v21[1].m128i_i8, "QRSTUVWXYZ");
*v21 = _mm_load_si128((const __m128i *)&LC18);
goto LABEL_16;
}
v18 = 0;
LOBYTE(v12) = 0;
LABEL_23:
*(&bf_options + 260) = v18;
*(&bf_options + 2) = v7;
*(_QWORD *)(&bf_options + 3) = 0LL;
*(_QWORD *)(&bf_options + 251) = 0LL;
memset(
(void *)(((_DWORD)&bf_options + 11) & 0xFFFFFFF8),
0,
8LL * (((_DWORD)&bf_options + 3 - (((_DWORD)&bf_options + 11) & 0xFFFFFFF8) + 256) >> 3));
result = debug;
if ( debug )
{
printf(
"[DEBUG] bfg INIT: from %d, to %d, len: %d, set: %s\n",
v7,
(unsigned __int8)*(&bf_options + 1),
(unsigned __int8)v12,
*((const char **)&bf_options + 34));
result = 0LL;
}
}
else
{
fwrite("Error: can't allocate enough memory!\n", 1uLL, 0x25uLL, stderr);
result = 1LL;
}
}
return result;
}

original_code:
int bf_init(char *arg) {
  int i = 0;
  int crs_len = 0;
  char flags = 0;
  char *tmp = strchr(arg, ':');
  if (!tmp) {
    fprintf(stderr, "Error: Invalid option format for -x\n");
    return 1;
  } else {
    tmp[0] = '\0';
  }
  bf_options.from = atoi(arg);
  if (bf_options.from < 1 || bf_options.from > 127) {
    fprintf(stderr, "Error: minimum length must be between 1 and 127, format: -x min:max:types\n");
    return 1;
  }
  arg = tmp + 1;
  tmp++;
  if (!arg[0]) {
    fprintf(stderr, "Error: no maximum length specified for -x min:max:types!\n");
    return 1;
  }
  tmp = strchr(arg, ':');
  if (!tmp) {
    fprintf(stderr, "Error: Invalid option format for -x\n");
    return 1;
  } else {
    tmp[0] = '\0';
  }
  bf_options.to = atoi(arg);
  tmp++;
  if (bf_options.from > bf_options.to) {
    fprintf(stderr, "Error: you specified a minimum length higher than the maximum length!\n");
    return 1;
  }
  if (tmp[0] == 0) {
    fprintf(stderr, "Error: charset not specified!\n");
    return 1;
  }
  bf_options.crs = malloc(sizeof(char) * 256);
  if (bf_options.crs == ((void *)0)) {
    fprintf(stderr, "Error: can't allocate enough memory!\n");
    return 1;
  }
  bf_options.crs[0] = 0;
  for (; tmp[i]; i++) {
    switch (tmp[i]) {
     case 'a':
      crs_len += 26;
      if (256 - crs_len < 1) {
        free(bf_options.crs);
        fprintf(stderr, "Error: charset specification exceeds %d characters.\n", 256);
        return 1;
      } else if (flags & 1) {
        free(bf_options.crs);
        fprintf(stderr, "Error: 'a' specified more than once in charset!\n");
        return 1;
      } else {
        strcat(bf_options.crs, "abcdefghijklmnopqrstuvwxyz");
        flags |= 1;
      }
      break;
     case 'A':
      crs_len += 26;
      if (256 - crs_len < 1) {
        free(bf_options.crs);
        fprintf(stderr, "Error: charset specification exceeds %d characters.\n", 256);
        return 1;
      } else if (flags & 2) {
        free(bf_options.crs);
        fprintf(stderr, "Error: 'A' specified more than once in charset!\n");
        return 1;
      } else {
        strcat(bf_options.crs, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
        flags |= 2;
      }
      break;
     case '1':
      crs_len += 10;
      if (256 - crs_len < 1) {
        free(bf_options.crs);
        fprintf(stderr, "Error: charset specification exceeds %d characters.\n", 256);
        return 1;
      } else if (flags & 4) {
        free(bf_options.crs);
        fprintf(stderr, "Error: '1' specified more than once in charset!\n");
        return 1;
      } else {
        strcat(bf_options.crs, "0123456789");
        flags |= 4;
      }
      break;
     default:
      if ((tmp[i] >= '2' && tmp[i] <= '9') || tmp[i] == '0') {
        if ((flags & 4) > 0) {
          printf("[ERROR] character %c defined in -x although the whole number range was already defined by '1', ignored\n", tmp[i]);
          continue;
        }
        printf("[WARNING] adding character %c for -x, note that '1' will add all numbers from 0-9\n", tmp[i]);
      }
      if (tolower((int)tmp[i]) >= 'b' && tolower((int)tmp[i]) <= 'z') {
        if ((tmp[i] <= 'Z' && (flags & 2) > 0) || (tmp[i] > 'Z' && (flags & 2) > 0)) {
          printf("[ERROR] character %c defined in -x although the whole letter range was already defined by '%c', ignored\n", tmp[i], tmp[i] <= 'Z' ? 'A' : 'a');
          continue;
        }
        printf("[WARNING] adding character %c for -x, note that '%c' will add all %scase letters\n", tmp[i], tmp[i] <= 'Z' ? 'A' : 'a', tmp[i] <= 'Z' ? "up" : "low");
      }
      crs_len++;
      if (256 - crs_len < 1) {
        free(bf_options.crs);
        fprintf(stderr, "Error: charset specification exceeds %d characters.\n", 256);
        return 1;
      } else {
        bf_options.crs[crs_len - 1] = tmp[i];
        bf_options.crs[crs_len] = '\0';
      }
      break;
    }
  }
  bf_options.crs_len = crs_len;
  bf_options.current = bf_options.from;
  memset((char*)bf_options.state, 0, sizeof(bf_options.state));
  if (debug)
    printf("[DEBUG] bfg INIT: from %d, to %d, len: %d, set: %s\n", bf_options.from, bf_options.to, bf_options.crs_len, bf_options.crs);
  return 0;
}

canonical_original_code:
int bf_init(char *arg) {
  int i = 0;
  int crs_len = 0;
  char flags = 0;
  char *tmp = strchr(arg, ':');
  if (!tmp) {
    fprintf(stderr, "Error: Invalid option format for -x\n");
    return 1;
  } else {
    tmp[0] = '\0';
  }
  bf_options.from = atoi(arg);
  if (bf_options.from < 1 || bf_options.from > 127) {
    fprintf(stderr, "Error: minimum length must be between 1 and 127, format: -x min:max:types\n");
    return 1;
  }
  arg = tmp + 1;
  tmp++;
  if (!arg[0]) {
    fprintf(stderr, "Error: no maximum length specified for -x min:max:types!\n");
    return 1;
  }
  tmp = strchr(arg, ':');
  if (!tmp) {
    fprintf(stderr, "Error: Invalid option format for -x\n");
    return 1;
  } else {
    tmp[0] = '\0';
  }
  bf_options.to = atoi(arg);
  tmp++;
  if (bf_options.from > bf_options.to) {
    fprintf(stderr, "Error: you specified a minimum length higher than the maximum length!\n");
    return 1;
  }
  if (tmp[0] == 0) {
    fprintf(stderr, "Error: charset not specified!\n");
    return 1;
  }
  bf_options.crs = malloc(sizeof(char) * 256);
  if (bf_options.crs == ((void *)0)) {
    fprintf(stderr, "Error: can't allocate enough memory!\n");
    return 1;
  }
  bf_options.crs[0] = 0;
  for (; tmp[i]; i++) {
    switch (tmp[i]) {
     case 'a':
      crs_len += 26;
      if (256 - crs_len < 1) {
        free(bf_options.crs);
        fprintf(stderr, "Error: charset specification exceeds %d characters.\n", 256);
        return 1;
      } else if (flags & 1) {
        free(bf_options.crs);
        fprintf(stderr, "Error: 'a' specified more than once in charset!\n");
        return 1;
      } else {
        strcat(bf_options.crs, "abcdefghijklmnopqrstuvwxyz");
        flags |= 1;
      }
      break;
     case 'A':
      crs_len += 26;
      if (256 - crs_len < 1) {
        free(bf_options.crs);
        fprintf(stderr, "Error: charset specification exceeds %d characters.\n", 256);
        return 1;
      } else if (flags & 2) {
        free(bf_options.crs);
        fprintf(stderr, "Error: 'A' specified more than once in charset!\n");
        return 1;
      } else {
        strcat(bf_options.crs, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
        flags |= 2;
      }
      break;
     case '1':
      crs_len += 10;
      if (256 - crs_len < 1) {
        free(bf_options.crs);
        fprintf(stderr, "Error: charset specification exceeds %d characters.\n", 256);
        return 1;
      } else if (flags & 4) {
        free(bf_options.crs);
        fprintf(stderr, "Error: '1' specified more than once in charset!\n");
        return 1;
      } else {
        strcat(bf_options.crs, "0123456789");
        flags |= 4;
      }
      break;
     default:
      if ((tmp[i] >= '2' && tmp[i] <= '9') || tmp[i] == '0') {
        if ((flags & 4) > 0) {
          printf("[ERROR] character %c defined in -x although the whole number range was already defined by '1', ignored\n", tmp[i]);
          continue;
        }
        printf("[WARNING] adding character %c for -x, note that '1' will add all numbers from 0-9\n", tmp[i]);
      }
      if (tolower((int)tmp[i]) >= 'b' && tolower((int)tmp[i]) <= 'z') {
        if ((tmp[i] <= 'Z' && (flags & 2) > 0) || (tmp[i] > 'Z' && (flags & 2) > 0)) {
          printf("[ERROR] character %c defined in -x although the whole letter range was already defined by '%c', ignored\n", tmp[i], tmp[i] <= 'Z' ? 'A' : 'a');
          continue;
        }
        printf("[WARNING] adding character %c for -x, note that '%c' will add all %scase letters\n", tmp[i], tmp[i] <= 'Z' ? 'A' : 'a', tmp[i] <= 'Z' ? "up" : "low");
      }
      crs_len++;
      if (256 - crs_len < 1) {
        free(bf_options.crs);
        fprintf(stderr, "Error: charset specification exceeds %d characters.\n", 256);
        return 1;
      } else {
        bf_options.crs[crs_len - 1] = tmp[i];
        bf_options.crs[crs_len] = '\0';
      }
      break;
    }
  }
  bf_options.crs_len = crs_len;
  bf_options.current = bf_options.from;
  memset((char *)bf_options.state, 0, sizeof(bf_options.state));
  if (debug)
    printf("[DEBUG] bfg INIT: from %d, to %d, len: %d, set: %s\n", bf_options.from, bf_options.to, bf_options.crs_len, bf_options.crs);
  return 0;
}

variable_types:
arg
char *

variable_types: i int

variable_types: flags char

variable_types:
tmp
char *


repo: ArchAssault-Project/hydra

decompiled_code:
__int64 bf_get_pcount()
{
__int64 v0; // r12
int v1; // ebx
unsigned __int64 v2; // rax
double v3; // xmm0_8

v0 = 0LL;
v1 = (unsigned __int8)bf_options[0];
if ( (unsigned __int8)bf_options[1] >= (unsigned int)bf_options[0] )
{
do
{
v3 = pow((double)(unsigned __int8)bf_options[260], (float)v1);
if ( v3 < 9.223372036854776e18 )
v2 = (unsigned int)(int)v3;
else
v2 = (unsigned int)(int)(v3 - 9.223372036854776e18) ^ 0x8000000000000000LL;
v0 += v2;
++v1;
}
while ( (unsigned __int8)bf_options[1] >= v1 );
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // r12
int v1; // ebx
unsigned __int64 v2; // rax
double v3; // xmm0_8

v0 = 0LL;
v1 = (unsigned __int8)bf_options[0];
if ( (unsigned __int8)bf_options[1] >= (unsigned int)bf_options[0] )
{
do
{
v3 = pow((double)(unsigned __int8)bf_options[260], (float)v1);
if ( v3 < 9.223372036854776e18 )
v2 = (unsigned int)(int)v3;
else
v2 = (unsigned int)(int)(v3 - 9.223372036854776e18) ^ 0x8000000000000000LL;
v0 += v2;
++v1;
}
while ( (unsigned __int8)bf_options[1] >= v1 );
}
return v0;
}

original_code:
unsigned long int bf_get_pcount() {
  int i;
  unsigned long int count = 0;
  for (i = bf_options.from; i <= bf_options.to; i++)
    count += (unsigned long int) (pow((float) bf_options.crs_len, (float) i));
  return count;
}

canonical_original_code:
unsigned long bf_get_pcount() {
  int i;
  unsigned long count = 0;
  for (i = bf_options.from; i <= bf_options.to; i++)
    count += (unsigned long) (pow((float) bf_options.crs_len, (float) i));
  return count;
}

variable_types:
count
unsigned long

return_type: unsigned long


decompiled_code:
_BYTE *bf_next()
{
_BYTE *v0; // r12
__int64 v1; // rbx
_BYTE *v2; // rax
int v3; // ebp
__int64 v4; // rax
__int64 v5; // rax
int v6; // er8
unsigned __int8 v7; // si
unsigned __int8 v8; // dl
__int64 v10; // rbx
__int64 v11; // rsi

v0 = 0LL;
v1 = (unsigned __int8)bf_options[2];
if ( (unsigned __int8)v1 <= (unsigned __int8)bf_options[1] )
{
v2 = malloc(0x100uLL);
*(_QWORD *)&bf_options[280] = v2;
v0 = v2;
if ( v2 )
{
v3 = (unsigned __int8)v1;
v4 = 0LL;
if ( (_BYTE)v1 )
{
do
{
v0[v4] = *(_BYTE *)(*(_QWORD *)&bf_options[272] + (unsigned __int8)bf_options[v4 + 3]);
++v4;
v0 = *(_BYTE **)&bf_options[280];
v1 = (unsigned __int8)bf_options[2];
}
while ( (int)v1 > (int)v4 );
}
v0[v1] = 0;
if ( debug )
{
v10 = 0LL;
printf(
"[DEBUG] bfg IN: len %d, from %d, current %d, to %d, state:",
(unsigned __int8)bf_options[260],
(unsigned __int8)bf_options[0],
(unsigned __int8)bf_options[2],
(unsigned __int8)bf_options[1]);
if ( bf_options[2] )
{
do
{
v11 = (unsigned __int8)bf_options[v10++ + 3];
printf(" %d", v11);
}
while ( (unsigned __int8)bf_options[2] > (int)v10 );
}
printf(", x: %s\n", *(const char **)&bf_options[280]);
}
LODWORD(v5) = v3 - 1;
v6 = (_DWORD)bf_options + 3;
if ( v3 )
{
v7 = bf_options[260];
v5 = (int)v5;
v6 = (_DWORD)bf_options + 3;
while ( 1 )
{
v8 = bf_options[v5 + 3] + 1;
if ( v8 < v7 )
break;
bf_options[v5-- + 3] = 0;
if ( (_DWORD)v5 == -1 )
goto LABEL_16;
}
bf_options[(int)v5 + 3] = v8;
}
else
{
LABEL_16:
++bf_options[2];
*(_QWORD *)&bf_options[3] = 0LL;
*(_QWORD *)&bf_options[251] = 0LL;
memset(
(void *)(((_DWORD)bf_options + 11) & 0xFFFFFFF8),
0,
8LL * ((v6 - (((_DWORD)bf_options + 11) & 0xFFFFFFF8) + 256) >> 3));
}
v0 = *(_BYTE **)&bf_options[280];
}
else
{
fwrite("Error: Can not allocate memory for -x data!\n", 1uLL, 0x2CuLL, stderr);
}
}
return v0;
}

canonical_decompiled_code:
_BYTE *func2()
{
_BYTE *v0; // r12
__int64 v1; // rbx
_BYTE *v2; // rax
int v3; // ebp
__int64 v4; // rax
__int64 v5; // rax
int v6; // er8
unsigned __int8 v7; // si
unsigned __int8 v8; // dl
__int64 v10; // rbx
__int64 v11; // rsi

v0 = 0LL;
v1 = (unsigned __int8)bf_options[2];
if ( (unsigned __int8)v1 <= (unsigned __int8)bf_options[1] )
{
v2 = malloc(0x100uLL);
*(_QWORD *)&bf_options[280] = v2;
v0 = v2;
if ( v2 )
{
v3 = (unsigned __int8)v1;
v4 = 0LL;
if ( (_BYTE)v1 )
{
do
{
v0[v4] = *(_BYTE *)(*(_QWORD *)&bf_options[272] + (unsigned __int8)bf_options[v4 + 3]);
++v4;
v0 = *(_BYTE **)&bf_options[280];
v1 = (unsigned __int8)bf_options[2];
}
while ( (int)v1 > (int)v4 );
}
v0[v1] = 0;
if ( debug )
{
v10 = 0LL;
printf(
"[DEBUG] bfg IN: len %d, from %d, current %d, to %d, state:",
(unsigned __int8)bf_options[260],
(unsigned __int8)bf_options[0],
(unsigned __int8)bf_options[2],
(unsigned __int8)bf_options[1]);
if ( bf_options[2] )
{
do
{
v11 = (unsigned __int8)bf_options[v10++ + 3];
printf(" %d", v11);
}
while ( (unsigned __int8)bf_options[2] > (int)v10 );
}
printf(", x: %s\n", *(const char **)&bf_options[280]);
}
LODWORD(v5) = v3 - 1;
v6 = (_DWORD)bf_options + 3;
if ( v3 )
{
v7 = bf_options[260];
v5 = (int)v5;
v6 = (_DWORD)bf_options + 3;
while ( 1 )
{
v8 = bf_options[v5 + 3] + 1;
if ( v8 < v7 )
break;
bf_options[v5-- + 3] = 0;
if ( (_DWORD)v5 == -1 )
goto LABEL_16;
}
bf_options[(int)v5 + 3] = v8;
}
else
{
LABEL_16:
++bf_options[2];
*(_QWORD *)&bf_options[3] = 0LL;
*(_QWORD *)&bf_options[251] = 0LL;
memset(
(void *)(((_DWORD)bf_options + 11) & 0xFFFFFFF8),
0,
8LL * ((v6 - (((_DWORD)bf_options + 11) & 0xFFFFFFF8) + 256) >> 3));
}
v0 = *(_BYTE **)&bf_options[280];
}
else
{
fwrite("Error: Can not allocate memory for -x data!\n", 1uLL, 0x2CuLL, stderr);
}
}
return v0;
}

original_code:
char *bf_next() {
  int i, pos = bf_options.current - 1;
  if (bf_options.current > bf_options.to)
    return ((void *)0);
  if ((bf_options.ptr = malloc(256)) == ((void *)0)) {
    fprintf(stderr, "Error: Can not allocate memory for -x data!\n");
    return ((void *)0);
  }
  for (i = 0; i < bf_options.current; i++)
    bf_options.ptr[i] = bf_options.crs[bf_options.state[i]];
  bf_options.ptr[bf_options.current] = 0;
  if (debug) {
    printf("[DEBUG] bfg IN: len %d, from %d, current %d, to %d, state:", bf_options.crs_len, bf_options.from, bf_options.current, bf_options.to);
    for (i = 0; i < bf_options.current; i++)
      printf(" %d", bf_options.state[i]);
    printf(", x: %s\n", bf_options.ptr);
  }
  while (pos >= 0 && (++bf_options.state[pos]) >= bf_options.crs_len) {
    bf_options.state[pos] = 0;
    pos--;
  }
  if (pos < 0) {
    bf_options.current++;
    memset((char*)bf_options.state, 0, sizeof(bf_options.state));
  }
  return bf_options.ptr;
}

canonical_original_code:
char *bf_next() {
  int i; int pos = bf_options.current - 1;
  if (bf_options.current > bf_options.to)
    return ((void *)0);
  if ((bf_options.ptr = malloc(256)) == ((void *)0)) {
    fprintf(stderr, "Error: Can not allocate memory for -x data!\n");
    return ((void *)0);
  }
  for (i = 0; i < bf_options.current; i++)
    bf_options.ptr[i] = bf_options.crs[bf_options.state[i]];
  bf_options.ptr[bf_options.current] = 0;
  if (debug) {
    printf("[DEBUG] bfg IN: len %d, from %d, current %d, to %d, state:", bf_options.crs_len, bf_options.from, bf_options.current, bf_options.to);
    for (i = 0; i < bf_options.current; i++)
      printf(" %d", bf_options.state[i]);
    printf(", x: %s\n", bf_options.ptr);
  }
  while (pos >= 0 && (++bf_options.state[pos]) >= bf_options.crs_len) {
    bf_options.state[pos] = 0;
    pos--;
  }
  if (pos < 0) {
    bf_options.current++;
    memset((char *)bf_options.state, 0, sizeof(bf_options.state));
  }
  return bf_options.ptr;
}

variable_types: pos int

return_type: char *


decompiled_code:
char *__fastcall nntp_read_server_capacity(unsigned int a1)
{
const unsigned __int16 **v1; // rbx
char *v2; // rax
char *v3; // rax
char *v4; // rbp

while ( 1 )
{
v4 = (char *)hydra_receive_line(a1);
if ( !v4 )
break;
v1 = _ctype_b_loc();
if ( ((*v1)[*v4] & 0x800) != 0 && v4[3] == 32 )
break;
v2 = &v4[strlen(v4) - 1];
if ( *v2 == 10 )
{
*v2 = 0;
v2 = &v4[strlen(v4) - 1];
}
if ( *v2 == 13 )
*v2 = 0;
v3 = rindex(v4, 10);
if ( v3 )
{
if ( ((*v1)[v3[1]] & 0x800) != 0 && v3[4] == 32 )
break;
}
free(v4);
}
return v4;
}

original_code:
char *nntp_read_server_capacity(int sock) {
  char *ptr = ((void *)0);
  int resp = 0;
  char *buf = ((void *)0);
  do {
    if (buf != ((void *)0))
      free(buf);
    ptr = buf = hydra_receive_line(sock);
    if (buf != ((void *)0)) {
      if (((*__ctype_b_loc ())[(int) (((int) buf[0]))] & (unsigned short int) _ISdigit) && buf[3] == ' ')
        resp = 1;
      else {
        if (buf[strlen(buf) - 1] == '\n')
          buf[strlen(buf) - 1] = 0;
        if (buf[strlen(buf) - 1] == '\r')
          buf[strlen(buf) - 1] = 0;
        if ((ptr = strrchr(buf, '\n')) != ((void *)0)) {
          ptr++;
          if (((*__ctype_b_loc ())[(int) (((int) *ptr))] & (unsigned short int) _ISdigit) && *(ptr + 3) == ' ')
            resp = 1;
        }
      }
    }
  } while (buf != ((void *)0) && resp == 0);
  return buf;
}

canonical_original_code:
char *nntp_read_server_capacity(int sock) {
  char *ptr = ((void *)0);
  int resp = 0;
  char *buf = ((void *)0);
  do {
    if (buf != ((void *)0))
      free(buf);
    ptr = buf = hydra_receive_line(sock);
    if (buf != ((void *)0)) {
      if (((*__ctype_b_loc ())[(int) (((int) buf[0]))] & (unsigned short) _ISdigit) && buf[3] == ' ')
        resp = 1;
      else {
        if (buf[strlen(buf) - 1] == '\n')
          buf[strlen(buf) - 1] = 0;
        if (buf[strlen(buf) - 1] == '\r')
          buf[strlen(buf) - 1] = 0;
        if ((ptr = strrchr(buf, '\n')) != ((void *)0)) {
          ptr++;
          if (((*__ctype_b_loc ())[(int) (((int) *ptr))] & (unsigned short) _ISdigit) && *(ptr + 3) == ' ')
            resp = 1;
        }
      }
    }
  } while (buf != ((void *)0) && resp == 0);
  return buf;
}

variable_types: sock int

variable_types:
ptr
char *

variable_types: resp int

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall send_nick(unsigned int a1, __int64 a2, const char *a3)
{
size_t v3; // rax
size_t v4; // rax
const char *v5; // rbx
unsigned int v6; // er12
unsigned int v7; // eax
size_t v8; // rax

if ( *a3 )
{
sprintf(buffer, "PASS %s\r\n", a3);
v3 = strlen(buffer);
if ( (int)hydra_send(a1, buffer, v3, 0LL) < 0 )
return 0xFFFFFFFFLL;
}
strcpy(buffer, "CAP LS\r\n");
v4 = strlen(buffer);
if ( (int)hydra_send(a1, buffer, v4, 0LL) < 0 )
return 0xFFFFFFFFLL;
v5 = (const char *)hydra_address2string(a2);
v6 = getpid();
v7 = getpid();
sprintf(buffer, "NICK hydra%d\r\nUSER hydra%d hydra %s :hydra\r\n", v7, v6, v5);
v8 = strlen(buffer);
return (unsigned int)((int)hydra_send(a1, buffer, v8, 0LL) >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2, const char *a3)
{
size_t v3; // rax
size_t v4; // rax
const char *v5; // rbx
unsigned int v6; // er12
unsigned int v7; // eax
size_t v8; // rax

if ( *a3 )
{
sprintf(buffer, "PASS %s\r\n", a3);
v3 = strlen(buffer);
if ( (int)hydra_send(a1, buffer, v3, 0LL) < 0 )
return 0xFFFFFFFFLL;
}
strcpy(buffer, "CAP LS\r\n");
v4 = strlen(buffer);
if ( (int)hydra_send(a1, buffer, v4, 0LL) < 0 )
return 0xFFFFFFFFLL;
v5 = (const char *)hydra_address2string(a2);
v6 = getpid();
v7 = getpid();
sprintf(buffer, "NICK hydra%d\r\nUSER hydra%d hydra %s :hydra\r\n", v7, v6, v5);
v8 = strlen(buffer);
return (unsigned int)((int)hydra_send(a1, buffer, v8, 0LL) >> 31);
}

original_code:
int send_nick(int s, char *ip, char *pass) {
  if (strlen(pass) > 0) {
    sprintf(buffer, "PASS %s\r\n", pass);
    if (hydra_send(s, buffer, strlen(buffer), 0) < 0) {
      return -1;
    }
  }
  sprintf(buffer, "CAP LS\r\n");
  if (hydra_send(s, buffer, strlen(buffer), 0) < 0) {
    return -1;
  }
  sprintf(buffer, "NICK hydra%d\r\nUSER hydra%d hydra %s :hydra\r\n", (int) getpid(), (int) getpid(), hydra_address2string(ip));
  if (hydra_send(s, buffer, strlen(buffer), 0) < 0) {
    return -1;
  }
  return 0;
}

variable_types: s int

variable_types:
ip
char *

variable_types:
pass
char *

return_type: int


decompiled_code:
__int64 __fastcall irc_server_connect(__int64 a1, int a2, unsigned int a3, char a4)
{
__int64 result; // rax

if ( a2 >= 0 )
hydra_disconnect((unsigned int)a2);
if ( (a4 & 1) != 0 )
{
if ( a3 )
{
mysslport = a3;
result = hydra_connect_ssl(a1, a3);
}
else
{
result = hydra_connect_ssl(a1, (unsigned int)mysslport);
}
}
else if ( a3 )
{
myport = a3;
result = hydra_connect_tcp(a1, a3);
}
else
{
result = hydra_connect_tcp(a1, (unsigned int)myport);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, unsigned int a3, char a4)
{
__int64 result; // rax

if ( a2 >= 0 )
hydra_disconnect((unsigned int)a2);
if ( (a4 & 1) != 0 )
{
if ( a3 )
{
mysslport = a3;
result = hydra_connect_ssl(a1, a3);
}
else
{
result = hydra_connect_ssl(a1, (unsigned int)mysslport);
}
}
else if ( a3 )
{
myport = a3;
result = hydra_connect_tcp(a1, a3);
}
else
{
result = hydra_connect_tcp(a1, (unsigned int)myport);
}
return result;
}

original_code:
int irc_server_connect(char *ip, int sock, int port, unsigned char options) {
  if (sock >= 0)
    sock = hydra_disconnect(sock);
  if ((options & 1) == 0) {
    if (port != 0)
      myport = port;
    sock = hydra_connect_tcp(ip, myport);
    port = myport;
  } else {
    if (port != 0)
      mysslport = port;
    sock = hydra_connect_ssl(ip, mysslport);
    port = mysslport;
  }
  return sock;
}

variable_types: port int

variable_types:
options
unsigned char


decompiled_code:
int dummy_ncp()
{
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
return putchar(10);
}

original_code:
void dummy_ncp() {
  printf("\n");
}

canonical_original_code:
void dummy_ncp() {
  printf("\n");
}

return_type: void


decompiled_code:
int dummy_afp()
{
return putchar(10);
}

original_code:
void dummy_afp() {
  printf("\n");
}

canonical_original_code:
void dummy_afp() {
  printf("\n");
}


decompiled_code:
char *__fastcall smtp_read_server_capacity(unsigned int a1)
{
const unsigned __int16 **v1; // rbx
char *v2; // rax
char *v3; // rax
char *v4; // rbp

while ( 1 )
{
v4 = (char *)hydra_receive_line(a1);
if ( !v4 )
break;
v1 = _ctype_b_loc();
if ( ((*v1)[*v4] & 0x800) != 0 && v4[3] == 32 )
break;
v2 = &v4[strlen(v4) - 1];
if ( *v2 == 10 )
{
*v2 = 0;
v2 = &v4[strlen(v4) - 1];
}
if ( *v2 == 13 )
*v2 = 0;
v3 = rindex(v4, 10);
if ( v3 )
{
if ( ((*v1)[v3[1]] & 0x800) != 0 && v3[4] == 32 )
break;
}
free(v4);
}
return v4;
}

original_code:
char *smtp_read_server_capacity(int sock) {
  char *ptr = ((void *)0);
  int resp = 0;
  char *buf = ((void *)0);
  do {
    if (buf != ((void *)0))
      free(buf);
    ptr = buf = hydra_receive_line(sock);
    if (buf != ((void *)0)) {
      if (((*__ctype_b_loc ())[(int) (((int) buf[0]))] & (unsigned short int) _ISdigit) && buf[3] == ' ')
        resp = 1;
      else {
        if (buf[strlen(buf) - 1] == '\n')
          buf[strlen(buf) - 1] = 0;
        if (buf[strlen(buf) - 1] == '\r')
          buf[strlen(buf) - 1] = 0;
        if ((ptr = strrchr(buf, '\n')) != ((void *)0)) {
          ptr++;
          if (((*__ctype_b_loc ())[(int) (((int) *ptr))] & (unsigned short int) _ISdigit) && *(ptr + 3) == ' ')
            resp = 1;
        }
      }
    }
  } while (buf != ((void *)0) && resp == 0);
  return buf;
}

canonical_original_code:
char *smtp_read_server_capacity(int sock) {
  char *ptr = ((void *)0);
  int resp = 0;
  char *buf = ((void *)0);
  do {
    if (buf != ((void *)0))
      free(buf);
    ptr = buf = hydra_receive_line(sock);
    if (buf != ((void *)0)) {
      if (((*__ctype_b_loc ())[(int) (((int) buf[0]))] & (unsigned short) _ISdigit) && buf[3] == ' ')
        resp = 1;
      else {
        if (buf[strlen(buf) - 1] == '\n')
          buf[strlen(buf) - 1] = 0;
        if (buf[strlen(buf) - 1] == '\r')
          buf[strlen(buf) - 1] = 0;
        if ((ptr = strrchr(buf, '\n')) != ((void *)0)) {
          ptr++;
          if (((*__ctype_b_loc ())[(int) (((int) *ptr))] & (unsigned short) _ISdigit) && *(ptr + 3) == ' ')
            resp = 1;
        }
      }
    }
  } while (buf != ((void *)0) && resp == 0);
  return buf;
}


decompiled_code:
int dummy_oracle()
{
return putchar(10);
}

original_code:
void dummy_oracle() {
  printf("\n");
}

canonical_original_code:
void dummy_oracle() {
  printf("\n");
}


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

if ( !a2 )
return 0LL;
v2 = -1;
v3 = &a1[a2];
do
{
v4 = *a1++;
v2 = crc32_tab[(unsigned __int8)(v2 ^ v4)] ^ (v2 >> 8);
}
while ( a1 != v3 );
return ~v2;
}

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

if ( !a2 )
return 0LL;
v2 = -1;
v3 = &a1[a2];
do
{
v4 = *a1++;
v2 = crc32_tab[(unsigned __int8)(v2 ^ v4)] ^ (v2 >> 8);
}
while ( a1 != v3 );
return ~v2;
}

original_code:
unsigned int crc32(const void *buf, unsigned int size) {
  const unsigned char *p;
  unsigned int crc;
  p = buf;
  crc = ~0U;
  while (size--)
    crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
  return crc ^ ~0U;
}

canonical_original_code:
unsigned int crc32(void *buf, unsigned int size) {
  unsigned char *p;
  unsigned int crc;
  p = buf;
  crc = ~0U;
  while (size--)
    crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
  return crc ^ ~0U;
}

variable_types:
buf
void *

variable_types:
size
unsigned int

variable_types:
p
unsigned char *

variable_types:
crc
unsigned int

return_type: unsigned int


repo: ArchAssault-Project/secure-delete

decompiled_code:
void __fastcall sdel_init(int a1)
{
__pid_t v1; // er12
__uid_t v2; // ebx
__gid_t v3; // er13
int v4; // eax

setvbuf(stdout, 0LL, 2, 0LL);
setvbuf(stderr, 0LL, 2, 0LL);
v1 = getpid();
v2 = getuid();
v3 = getgid();
v4 = time(0LL);
srand(v4 ^ (v3 + v2 + v1));
devrandom = 0LL;
if ( a1 )
{
devrandom = fopen64("/dev/urandom", "r");
if ( devrandom )
{
if ( verbose )
printf("Using %s for random input.\n", "/dev/urandom");
}
}
_internal_sdel_init = 1;
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
__pid_t v1; // er12
__uid_t v2; // ebx
__gid_t v3; // er13
int v4; // eax

setvbuf(stdout, 0LL, 2, 0LL);
setvbuf(stderr, 0LL, 2, 0LL);
v1 = getpid();
v2 = getuid();
v3 = getgid();
v4 = time(0LL);
srand(v4 ^ (v3 + v2 + v1));
devrandom = 0LL;
if ( a1 )
{
devrandom = fopen64("/dev/urandom", "r");
if ( devrandom )
{
if ( verbose )
printf("Using %s for random input.\n", "/dev/urandom");
}
}
_internal_sdel_init = 1;
}

original_code:
void sdel_init(int secure_random) {
    (void) setvbuf(stdout, ((void *)0), 2, 0);
    (void) setvbuf(stderr, ((void *)0), 2, 0);
    if (32769<16384)
        fprintf(stderr, "Programming Warning: in-compiled blocksize is <16k !\n");
    if (32769 % 3 > 0)
        fprintf(stderr, "Programming Error: in-compiled blocksize is not a multiple of 3!\n");
    srand( (getpid()+getuid()+getgid()) ^ time(0) );
    devrandom = ((void *)0);
    if (secure_random) {
        if ((devrandom = fopen("/dev/urandom", "r")) != ((void *)0))
            if (verbose)
                printf("Using %s for random input.\n", "/dev/urandom");
    }
    __internal_sdel_init = 1;
}


decompiled_code:
size_t sdel_finnish()
{
size_t result; // rax

if ( devrandom )
{
fclose(devrandom);
devrandom = 0LL;
}
result = (unsigned int)_internal_sdel_init;
if ( !_internal_sdel_init )
return fwrite(
"Programming Error: sdel-lib was not initialized before calling sdel_finnish().\n",
1uLL,
0x4FuLL,
stderr);
_internal_sdel_init = 0;
return result;
}

canonical_decompiled_code:
size_t func4()
{
size_t result; // rax

if ( devrandom )
{
fclose(devrandom);
devrandom = 0LL;
}
result = (unsigned int)_internal_sdel_init;
if ( !_internal_sdel_init )
return fwrite(
"Programming Error: sdel-lib was not initialized before calling sdel_finnish().\n",
1uLL,
0x4FuLL,
stderr);
_internal_sdel_init = 0;
return result;
}

original_code:
void sdel_finnish() {
    if (devrandom != ((void *)0)) {
        fclose(devrandom);
        devrandom = ((void *)0);
    }
    if (! __internal_sdel_init) {
        fprintf(stderr, "Programming Error: sdel-lib was not initialized before calling sdel_finnish().\n");
        return;
    }
    __internal_sdel_init = 0;
}


decompiled_code:
__int64 __fastcall sdel_unlink(char *file, int a2, int a3, int a4)
{
void *v7; // rsp
int v8; // ebx
char *v9; // rsi
const char *v10; // rdi
unsigned int v11; // er14
int v13; // edi
struct stat64 buf; // [rsp+0h] [rbp-C0h] BYREF

v7 = alloca(strlen(file) + 1);
if ( !a2 )
{
if ( a3 )
{
v13 = open64(file, a4 | 0x201);
if ( v13 >= 0 )
close(v13);
}
}
v8 = 0;
strcpy((char *)&buf, file);
while ( 1 )
{
_sdel_random_filename((const char *)&buf);
if ( lstat64((const char *)&buf, &buf) < 0 )
break;
if ( ++v8 == 101 )
{
fprintf(stderr, "Warning: Couldn't find a free filename for %s!\n", file);
strcpy((char *)&buf, file);
if ( !a2 )
goto LABEL_13;
LABEL_9:
v9 = file;
v10 = "Warning: Unable to remove directory %s - ";
v11 = rmdir((const char *)&buf);
if ( !v11 )
{
if ( verbose )
{
printf("Removed directory %s ...", file);
return v11;
}
return 0;
}
goto LABEL_20;
}
}
if ( rename(file, (const char *)&buf) )
{
fprintf(stderr, "Warning: Couldn't rename %s - ", file);
perror(&s);
strcpy((char *)&buf, file);
}
if ( a2 )
goto LABEL_9;
LABEL_13:
v11 = unlink((const char *)&buf);
if ( v11 )
{
v9 = file;
v10 = "Warning: Unable to unlink file %s - ";
LABEL_20:
v11 = -1;
printf(v10, v9);
perror(&s);
rename((const char *)&buf, file);
return v11;
}
if ( !verbose )
return 0;
printf(" Removed file %s ...", file);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *file, int a2, int a3, int a4)
{
void *v7; // rsp
int v8; // ebx
char *v9; // rsi
const char *v10; // rdi
unsigned int v11; // er14
int v13; // edi
struct stat64 buf; // [rsp+0h] [rbp-C0h] BYREF

v7 = alloca(strlen(file) + 1);
if ( !a2 )
{
if ( a3 )
{
v13 = open64(file, a4 | 0x201);
if ( v13 >= 0 )
close(v13);
}
}
v8 = 0;
strcpy((char *)&buf, file);
while ( 1 )
{
func2((const char *)&buf);
if ( lstat64((const char *)&buf, &buf) < 0 )
break;
if ( ++v8 == 101 )
{
fprintf(stderr, "Warning: Couldn't find a free filename for %s!\n", file);
strcpy((char *)&buf, file);
if ( !a2 )
goto LABEL_13;
LABEL_9:
v9 = file;
v10 = "Warning: Unable to remove directory %s - ";
v11 = rmdir((const char *)&buf);
if ( !v11 )
{
if ( verbose )
{
printf("Removed directory %s ...", file);
return v11;
}
return 0;
}
goto LABEL_20;
}
}
if ( rename(file, (const char *)&buf) )
{
fprintf(stderr, "Warning: Couldn't rename %s - ", file);
perror(&s);
strcpy((char *)&buf, file);
}
if ( a2 )
goto LABEL_9;
LABEL_13:
v11 = unlink((const char *)&buf);
if ( v11 )
{
v9 = file;
v10 = "Warning: Unable to unlink file %s - ";
LABEL_20:
v11 = -1;
printf(v10, v9);
perror(&s);
rename((const char *)&buf, file);
return v11;
}
if ( !verbose )
return 0;
printf(" Removed file %s ...", file);
return v11;
}

original_code:
int sdel_unlink(char *filename, int directory, int truncate, int slow) {
   int fd;
   int turn = 0;
   int result;
   char newname[strlen(filename) + 1];
   struct stat filestat;
   if (! directory && truncate)
       if ((fd = open(filename, 01 | 01000 | slow)) >= 0)
           close(fd);
    strcpy(newname, filename);
    do {
        __sdel_random_filename(newname);
        if ((result = lstat(newname, &filestat)) >= 0)
            turn++;
    } while ((result >= 0) && (turn <= 100));
    if (turn <= 100) {
       result = rename(filename, newname);
       if (result != 0) {
          fprintf(stderr, "Warning: Couldn't rename %s - ", filename);
          perror("");
          strcpy(newname, filename);
       }
    } else {
       fprintf(stderr,"Warning: Couldn't find a free filename for %s!\n",filename);
       strcpy(newname, filename);
    }
    if (directory) {
        result = rmdir(newname);
        if (result) {
            printf("Warning: Unable to remove directory %s - ", filename);
            perror("");
     (void) rename(newname, filename);
 } else
     if (verbose)
         printf("Removed directory %s ...", filename);
    } else {
        result = unlink(newname);
        if (result) {
            printf("Warning: Unable to unlink file %s - ", filename);
            perror("");
            (void) rename(newname, filename);
        } else
            if (verbose)
                printf(" Removed file %s ...", filename);
    }
    if (result != 0)
        return -1;
    return 0;
}

canonical_original_code:
int sdel_unlink(char *filename, int directory, int truncate, int slow) {
   int fd;
   int turn = 0;
   int result;
   char newname[-1];
   struct stat filestat;
   if (! directory && truncate)
       if ((fd = open(filename, 01 | 01000 | slow)) >= 0)
           close(fd);
    strcpy(newname, filename);
    do {
        __sdel_random_filename(newname);
        if ((result = lstat(newname, &filestat)) >= 0)
            turn++;
    } while ((result >= 0) && (turn <= 100));
    if (turn <= 100) {
       result = rename(filename, newname);
       if (result != 0) {
          fprintf(stderr, "Warning: Couldn't rename %s - ", filename);
          perror("");
          strcpy(newname, filename);
       }
    } else {
       fprintf(stderr,"Warning: Couldn't find a free filename for %s!\n",filename);
       strcpy(newname, filename);
    }
    if (directory) {
        result = rmdir(newname);
        if (result) {
            printf("Warning: Unable to remove directory %s - ", filename);
            perror("");
     (void) rename(newname, filename);
 } else
     if (verbose)
         printf("Removed directory %s ...", filename);
    } else {
        result = unlink(newname);
        if (result) {
            printf("Warning: Unable to unlink file %s - ", filename);
            perror("");
            (void) rename(newname, filename);
        } else
            if (verbose)
                printf(" Removed file %s ...", filename);
    }
    if (result != 0)
        return -1;
    return 0;
}

variable_types:
filename
char *

variable_types: directory int

variable_types: truncate int

variable_types: slow int

variable_types: fd int

variable_types: turn int

variable_types: result int

variable_types:
newname
char [-1]

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
int __fastcall sdel_wipe_inodes(char *src)
{
size_t v1; // rax
char *v2; // rbx
char **v3; // r12
char *v4; // r13
int v5; // er14
int v6; // er13
size_t v7; // rbp
char *v8; // rdi
__int64 v9; // rax
char **v10; // rbx
__int64 v11; // r13
char *v12; // rbp
int result; // eax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 16);
if ( verbose )
printf("Wiping inodes ...");
v3 = (char **)malloc(0x2000000uLL);
v4 = stpcpy(v2, src);
if ( src[strlen(src) - 1] != 47 )
*(_WORD *)v4 = 47;
v5 = 0;
v6 = 0;
strcat(v2, "xxxxxxxx.xxx");
while ( 1 )
{
_sdel_random_filename(v2);
if ( open64(v2, 193, 384LL) >= 0 )
break;
++v5;
LABEL_7:
if ( v5 > 4 )
goto LABEL_10;
}
v7 = strlen(v2);
v8 = (char *)malloc(v7);
v9 = v6++;
v3[v9] = v8;
memcpy(v8, v2, v7 + 1);
if ( v6 <= 0x3FFFFF )
goto LABEL_7;
LABEL_10:
sync();
if ( v5 <= 4 )
fwrite("Warning: could not wipe all inodes!\n", 1uLL, 0x24uLL, stderr);
v3[v6] = 0LL;
if ( v6 )
{
v10 = v3;
v11 = (__int64)&v3[(unsigned int)(v6 - 1) + 1];
do
{
v12 = *v10++;
unlink(v12);
free(v12);
}
while ( (char **)v11 != v10 );
}
free(v3);
sync();
result = verbose;
if ( verbose )
result = printf(" Done ... ");
return result;
}

canonical_decompiled_code:
int __fastcall func7(char *src)
{
size_t v1; // rax
char *v2; // rbx
char **v3; // r12
char *v4; // r13
int v5; // er14
int v6; // er13
size_t v7; // rbp
char *v8; // rdi
__int64 v9; // rax
char **v10; // rbx
__int64 v11; // r13
char *v12; // rbp
int result; // eax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 16);
if ( verbose )
printf("Wiping inodes ...");
v3 = (char **)malloc(0x2000000uLL);
v4 = stpcpy(v2, src);
if ( src[strlen(src) - 1] != 47 )
*(_WORD *)v4 = 47;
v5 = 0;
v6 = 0;
strcat(v2, "xxxxxxxx.xxx");
while ( 1 )
{
func2(v2);
if ( open64(v2, 193, 384LL) >= 0 )
break;
++v5;
LABEL_7:
if ( v5 > 4 )
goto LABEL_10;
}
v7 = strlen(v2);
v8 = (char *)malloc(v7);
v9 = v6++;
v3[v9] = v8;
memcpy(v8, v2, v7 + 1);
if ( v6 <= 0x3FFFFF )
goto LABEL_7;
LABEL_10:
sync();
if ( v5 <= 4 )
fwrite("Warning: could not wipe all inodes!\n", 1uLL, 0x24uLL, stderr);
v3[v6] = 0LL;
if ( v6 )
{
v10 = v3;
v11 = (__int64)&v3[(unsigned int)(v6 - 1) + 1];
do
{
v12 = *v10++;
unlink(v12);
free(v12);
}
while ( (char **)v11 != v10 );
}
free(v3);
sync();
result = verbose;
if ( verbose )
result = printf(" Done ... ");
return result;
}

original_code:
void sdel_wipe_inodes(char *loc, char **array) {
    char *template = malloc(strlen(loc) + 16);
    int i = 0;
    int fail = 0;
    int fd;
    if (verbose)
        printf("Wiping inodes ...");
    array = malloc(4194304 * sizeof(template));
    strcpy(template, loc);
    if (loc[strlen(loc) - 1] != '/')
        strcat(template, "/");
    strcat(template, "xxxxxxxx.xxx");
    while(i < 4194304 && fail < 5) {
        __sdel_random_filename(template);
        if (open(template, 0100 | 0200 | 01, 0600) < 0)
            fail++;
        else {
            array[i] = malloc(strlen(template));
            strcpy(array[i], template);
            i++;
        }
    }
    sync();
    if (fail < 5) {
        fprintf(stderr, "Warning: could not wipe all inodes!\n");
    }
    array[i] = ((void *)0);
    fd = 0;
    while(fd < i) {
        unlink(array[fd]);
        free(array[fd]);
        fd++;
    }
    free(array);
    array = ((void *)0);
    sync();
    if (verbose)
        printf(" Done ... ");
}

variable_types:
loc
char *

variable_types:
array
char **

variable_types:
template
char *

variable_types: i int

variable_types: fail int


crcTable

repo: Archenoth/AIPS

decompiled_code:
__int64 __fastcall crcTable(__int64 a1, int a2)
{
__int64 i; // r8
__int64 result; // rax
int v6; // edx
char v7; // si

for ( i = 0LL; i != 256; ++i )
{
LODWORD(result) = i;
v6 = 8;
do
{
v7 = result;
result = (unsigned int)result >> 1;
if ( (v7 & 1) != 0 )
result = a2 ^ (unsigned int)result;
--v6;
}
while ( v6 );
*(_DWORD *)(a1 + 4 * i) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 i; // r8
__int64 result; // rax
int v6; // edx
char v7; // si

for ( i = 0LL; i != 256; ++i )
{
LODWORD(result) = i;
v6 = 8;
do
{
v7 = result;
result = (unsigned int)result >> 1;
if ( (v7 & 1) != 0 )
result = a2 ^ (unsigned int)result;
--v6;
}
while ( v6 );
*(_DWORD *)(a1 + 4 * i) = result;
}
return result;
}

original_code:
void crcTable(unsigned int *table, unsigned int polynomial){
  unsigned int current;
  int i, ii;
  for(i = 0; i < 256; i++){
    current = i;
    for(ii = 8; ii > 0; ii--)
      if(current & 1)
 current = (current >> 1) ^ polynomial;
      else
 current >>= 1;
    table[i] = current;
  }
}

canonical_original_code:
void crcTable(unsigned int *table, unsigned int polynomial){
  unsigned int current;
  int i; int ii;
  for(i = 0; i < 256; i++){
    current = i;
    for(ii = 8; ii > 0; ii--)
      if(current & 1)
 current = (current >> 1) ^ polynomial;
      else
 current >>= 1;
    table[i] = current;
  }
}

variable_types:
table
unsigned int *

variable_types:
polynomial
unsigned int

variable_types:
current
unsigned int

variable_types: ii int


AIPSError

decompiled_code:
__int64 AIPSError(int a1, const char *a2, ...)
{
int v2; // edx
int v3; // ecx
int v4; // er8
int v5; // er9
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
__int64 v8; // [rsp+30h] [rbp-B8h]
__int64 v9; // [rsp+38h] [rbp-B0h]
__int64 v10; // [rsp+40h] [rbp-A8h]
__int64 v11; // [rsp+48h] [rbp-A0h]

va_start(arg, a2);
v8 = va_arg(arg, _QWORD);
v9 = va_arg(arg, _QWORD);
v10 = va_arg(arg, _QWORD);
v11 = va_arg(arg, _QWORD);
va_end(arg);
if ( a1 > 0 )
{
fwrite("Error: ", 1uLL, 7uLL, stderr);
va_start(arg, a2);
vfprintf(stderr, a2, arg);
fputc(10, stderr);
result = 0LL;
if ( a1 == 1 )
return result;
}
else
{
va_start(arg, a2);
vfprintf(stderr, a2, arg);
fputc(10, stderr);
}
if ( a1 == 2 )
Exit(1);
result = 1LL;
if ( a1 )
result = AIPSError(1, (unsigned int)"Unrecognized error!", v2, v3, v4, v5);
return result;
}

canonical_decompiled_code:
__int64 func0(int a1, const char *a2, ...)
{
int v2; // edx
int v3; // ecx
int v4; // er8
int v5; // er9
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
__int64 v8; // [rsp+30h] [rbp-B8h]
__int64 v9; // [rsp+38h] [rbp-B0h]
__int64 v10; // [rsp+40h] [rbp-A8h]
__int64 v11; // [rsp+48h] [rbp-A0h]

va_start(arg, a2);
v8 = va_arg(arg, _QWORD);
v9 = va_arg(arg, _QWORD);
v10 = va_arg(arg, _QWORD);
v11 = va_arg(arg, _QWORD);
va_end(arg);
if ( a1 > 0 )
{
fwrite("Error: ", 1uLL, 7uLL, stderr);
va_start(arg, a2);
vfprintf(stderr, a2, arg);
fputc(10, stderr);
result = 0LL;
if ( a1 == 1 )
return result;
}
else
{
va_start(arg, a2);
vfprintf(stderr, a2, arg);
fputc(10, stderr);
}
if ( a1 == 2 )
Exit(1);
result = 1LL;
if ( a1 )
result = func0(1, (unsigned int)"Unrecognized error!", v2, v3, v4, v5);
return result;
}

original_code:
int AIPSError(int level, const char *message, ...){
  va_list concat;
  if(level > 0) {
    fprintf(stderr, "Error: ");
  }
  __builtin_va_start(concat,message);
  vfprintf(stderr, message, concat);
  __builtin_va_end(concat);
  fprintf(stderr, "\n");
  switch(level) {
    case 0:
      return 1;
    case 1:
      return 0;
    case 2:
      _Exit(1);
    default:
      return AIPSError(1, "Unrecognized error!");
  }
}

canonical_original_code:
int AIPSError(int level, char *message, ...){
  __builtin_va_list concat;
  if(level > 0) {
    fprintf(stderr, "Error: ");
  }
  __builtin_va_start(concat,message);
  vfprintf(stderr, message, concat);
  __builtin_va_end(concat);
  fprintf(stderr, "\n");
  switch(level) {
    case 0:
      return 1;
    case 1:
      return 0;
    case 2:
      _Exit(1);
    default:
      return AIPSError(1, "Unrecognized error!");
  }
}

variable_types: level int

variable_types:
message
char *


repo: Atalanta/run-length-encoding

decompiled_code:
__int64 can_create_and_free_a_block()
{
__int64 v0; // rax

v0 = create_block();
return free_block(v0);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax

v0 = create_block();
return free_block(v0);
}

original_code:
static void can_create_and_free_a_block () {
    block_t *block = create_block();
    free_block(block);
}

canonical_original_code:
static void can_create_and_free_a_block() {
    struct block_t *block = create_block();
    free_block(block);
}

variable_types: struct block_t { int size; char *buffer; } *


decompiled_code:
__int64 can_establish_length_of_input()
{
int *v0; // rbp
__int64 v1; // rax

v0 = (int *)create_block();
append_character(v0, 97LL);
v1 = create_equal_to_value_constraint(1LL, &unk_249);
assert_that_("encoder_tests.c", 12LL, "block->size", *v0, v1);
return free_block(v0);
}

canonical_decompiled_code:
__int64 func1()
{
int *v0; // rbp
__int64 v1; // rax

v0 = (int *)create_block();
append_character(v0, 97LL);
v1 = create_equal_to_value_constraint(1LL, &unk_249);
assert_that_("encoder_tests.c", 12LL, "block->size", *v0, v1);
return free_block(v0);
}

original_code:
static void can_establish_length_of_input () {
    block_t *block = create_block();
 append_character(block, 'a');
 assert_that_("encoder_tests.c", 12, "block->size", (intptr_t)block->size, create_equal_to_value_constraint((intptr_t)1, "1"));
    free_block(block);
}

canonical_original_code:
static void can_establish_length_of_input() {
    struct block_t *block = create_block();
 append_character(block, 'a');
 assert_that_("encoder_tests.c", 12, "block->size", (long)block->size, create_equal_to_value_constraint((long)1, "1"));
    free_block(block);
}

user_defined_types: struct block_t { int size; char *buffer; }


decompiled_code:
__int64 can_handle_a_big_string()
{
int v0; // ebx
int *v1; // rbp
__int64 v2; // rax

v0 = 260;
v1 = (int *)create_block();
do
{
append_character(v1, 97LL);
--v0;
}
while ( v0 );
v2 = create_equal_to_value_constraint(260LL, "260");
assert_that_("encoder_tests.c", 31LL, "block->size", *v1, v2);
return free_block(v1);
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // ebx
int *v1; // rbp
__int64 v2; // rax

v0 = 260;
v1 = (int *)create_block();
do
{
append_character(v1, 97LL);
--v0;
}
while ( v0 );
v2 = create_equal_to_value_constraint(260LL, "260");
assert_that_("encoder_tests.c", 31LL, "block->size", *v1, v2);
return free_block(v1);
}

original_code:
static void can_handle_a_big_string () {
    block_t *block = create_block();
 int i;
 for (i = 0; i < 260; i++) {
  append_character(block, 'a');
 }
 assert_that_("encoder_tests.c", 31, "block->size", (intptr_t)block->size, create_equal_to_value_constraint((intptr_t)260, "260"));
 free_block(block);
}

canonical_original_code:
static void can_handle_a_big_string() {
    struct block_t *block = create_block();
 int i;
 for (i = 0; i < 260; i++) {
  append_character(block, 'a');
 }
 assert_that_("encoder_tests.c", 31, "block->size", (long)block->size, create_equal_to_value_constraint((long)260, "260"));
 free_block(block);
}


decompiled_code:
__int64 can_generate_string_from_block()
{
__int64 v0; // rbp
__int64 v1; // rax

v0 = create_block();
append_character(v0, 97LL);
append_character(v0, 98LL);
append_character(v0, 99LL);
v1 = create_equal_to_string_constraint("abc", "\"abc\"");
assert_that_("encoder_tests.c", 21LL, "block->buffer", *(_QWORD *)(v0 + 8), v1);
return free_block(v0);
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbp
__int64 v1; // rax

v0 = create_block();
append_character(v0, 97LL);
append_character(v0, 98LL);
append_character(v0, 99LL);
v1 = create_equal_to_string_constraint("abc", "\"abc\"");
assert_that_("encoder_tests.c", 21LL, "block->buffer", *(_QWORD *)(v0 + 8), v1);
return free_block(v0);
}

original_code:
static void can_generate_string_from_block () {
    block_t *block = create_block();
 append_character(block, 'a');
 append_character(block, 'b');
 append_character(block, 'c');
 assert_that_("encoder_tests.c", 21, "block->buffer", (intptr_t)block->buffer, create_equal_to_string_constraint("abc", "\"abc\""));
    free_block(block);
}

canonical_original_code:
static void can_generate_string_from_block() {
    struct block_t *block = create_block();
 append_character(block, 'a');
 append_character(block, 'b');
 append_character(block, 'c');
 assert_that_("encoder_tests.c", 21, "block->buffer", (long)block->buffer, create_equal_to_string_constraint("abc", "\"abc\""));
    free_block(block);
}


main

canonical_name: main

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

v3 = create_named_test_suite_("main", "encoder_tests.c", 36LL);
add_test_(v3, "can_create_and_free_a_block", &CgreenSpec__default__can_create_and_free_a_block__);
add_test_(v3, "can_establish_length_of_input", &CgreenSpec__default__can_establish_length_of_input__);
add_test_(v3, "can_generate_string_from_block", &CgreenSpec__default__can_generate_string_from_block__);
add_test_(v3, "can_handle_a_big_string", &CgreenSpec__default__can_handle_a_big_string__);
v4 = create_text_reporter();
return run_test_suite(v3, v4);
}

original_code:
int main(int argc, char **argv) {
    TestSuite *suite = create_named_test_suite_(__func__, "encoder_tests.c", 36);
    add_test_(suite, "can_create_and_free_a_block", &CgreenSpec__default__can_create_and_free_a_block__);
    add_test_(suite, "can_establish_length_of_input", &CgreenSpec__default__can_establish_length_of_input__);
    add_test_(suite, "can_generate_string_from_block", &CgreenSpec__default__can_generate_string_from_block__);
    add_test_(suite, "can_handle_a_big_string", &CgreenSpec__default__can_handle_a_big_string__);
    return run_test_suite(suite, create_text_reporter());
}

canonical_original_code:
int main(int argc, char **argv) {
    struct TestSuite_ *suite = create_named_test_suite_(__func__, "encoder_tests.c", 36);
    add_test_(suite, "can_create_and_free_a_block", &CgreenSpec__default__can_create_and_free_a_block__);
    add_test_(suite, "can_establish_length_of_input", &CgreenSpec__default__can_establish_length_of_input__);
    add_test_(suite, "can_generate_string_from_block", &CgreenSpec__default__can_generate_string_from_block__);
    add_test_(suite, "can_handle_a_big_string", &CgreenSpec__default__can_handle_a_big_string__);
    return run_test_suite(suite, create_text_reporter());
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct TestSuite_ { char *name; char *filename; int line; struct UnitTest { int type; char *name; union { struct CgreenTest { struct CgreenContext { char *name; char *filename; void (*setup)(); void (*teardown)(); } *context; char *name; void (*run)(); char *filename; int line; } *test; struct TestSuite_ *suite; } Runnable; } *tests; void (*setup)(); void (*teardown)(); int size; } *

user_defined_types: struct TestSuite_ { char *name; char *filename; int line; struct UnitTest *tests; void (*setup)(); void (*teardown)(); int size; }

user_defined_types: struct UnitTest { int type; char *name; union { struct CgreenTest *test; struct TestSuite_ *suite; } Runnable; }

user_defined_types: struct CgreenTest { struct CgreenContext *context; char *name; void (*run)(); char *filename; int line; }


slurp

decompiled_code:
__int64 __fastcall slurp(__int64 (*a1)(void))
{
__int64 i; // rbp
char v2; // al

for ( i = create_block(); ; i = append_character(i, (unsigned int)v2) )
{
v2 = a1();
if ( v2 == -1 )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 (*a1)(void))
{
__int64 i; // rbp
char v2; // al

for ( i = func9(); ; i = func11(i, (unsigned int)v2) )
{
v2 = a1();
if ( v2 == -1 )
break;
}
return i;
}

original_code:
block_t *slurp(int (*in)(void)) {
    block_t *block = create_block();
    char byte;
    while((byte = in()) != (-1)) {
  block = append_character(block, byte);
 }
    return block;
}

canonical_original_code:
struct block_t *slurp(int (*in)()) {
    struct block_t *block = create_block();
    char byte;
    while((byte = in()) != (-1)) {
  block = append_character(block, byte);
 }
    return block;
}

variable_types:
in
int (*)()

variable_types: byte char

return_type: struct block_t { int size; char *buffer; } *


verbatim

decompiled_code:
int __fastcall verbatim(int a1, char *a2)
{
char *v2; // rbx
int result; // eax
__int64 v4; // rbp
int v5; // edi

v2 = a2;
result = printf("%d:", (unsigned int)a1);
if ( a1 > 0 )
{
v4 = (__int64)&a2[a1 - 1 + 1];
do
{
v5 = *v2++;
result = putchar(v5);
}
while ( v2 != (char *)v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1, char *a2)
{
char *v2; // rbx
int result; // eax
__int64 v4; // rbp
int v5; // edi

v2 = a2;
result = printf("%d:", (unsigned int)a1);
if ( a1 > 0 )
{
v4 = (__int64)&a2[a1 - 1 + 1];
do
{
v5 = *v2++;
result = putchar(v5);
}
while ( v2 != (char *)v4 );
}
return result;
}

original_code:
void verbatim(int size, char *buffer) {
    int i;
    printf("%d:", size);
    for(i = 0; i < size; i++) {
      printf("%c", buffer[i]);
    };
}

variable_types: size int

variable_types:
buffer
char *


decompiled_code:
_QWORD *create_block()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
result[1] = 0LL;
*(_DWORD *)result = 0;
return result;
}

canonical_decompiled_code:
_QWORD *func9()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
result[1] = 0LL;
*(_DWORD *)result = 0;
return result;
}

original_code:
block_t *create_block(void) {
    block_t *block = malloc(sizeof(block_t));
    block->buffer = ((void *)0);
    block->size = 0;
    return block;
}

canonical_original_code:
struct block_t *create_block() {
    struct block_t *block = malloc(sizeof(block_t));
    block->buffer = ((void *)0);
    block->size = 0;
    return block;
}


decompiled_code:
// attributes: thunk
void free_block(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func10(void *ptr)
{
free(ptr);
}

original_code:
void free_block(block_t *block) {
    free(block);
}

canonical_original_code:
void free_block(struct block_t *block) {
    free(block);
}


decompiled_code:
void **__fastcall append_character(void **a1, char a2)
{
_BYTE *v2; // rax
__int64 v3; // rdx
void **result; // rax

v2 = realloc(a1[1], *(_DWORD *)a1 + 1);
v3 = *(int *)a1;
a1[1] = v2;
v2[v3] = a2;
result = a1;
++*(_DWORD *)a1;
return result;
}

canonical_decompiled_code:
void **__fastcall func11(void **a1, char a2)
{
_BYTE *v2; // rax
__int64 v3; // rdx
void **result; // rax

v2 = realloc(a1[1], *(_DWORD *)a1 + 1);
v3 = *(int *)a1;
a1[1] = v2;
v2[v3] = a2;
result = a1;
++*(_DWORD *)a1;
return result;
}

original_code:
block_t *append_character(block_t *block, char byte) {
 block->buffer = realloc(block->buffer, (block->size + 1)*sizeof(char));
 block->buffer[block->size] = byte;
 block->size++;
 return block;
}

canonical_original_code:
struct block_t *append_character(struct block_t *block, char byte) {
 block->buffer = realloc(block->buffer, (block->size + 1)*sizeof(char));
 block->buffer[block->size] = byte;
 block->size++;
 return block;
}

variable_types:
block
struct block_t *


main

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

v3 = (_QWORD *)slurp(getchar, argv, envp);
verbatim(*(unsigned int *)v3, v3[1]);
free_block(v3);
return 0;
}

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

v3 = (_QWORD *)func7(getchar, argv, envp);
func8(*(unsigned int *)v3, v3[1]);
func10(v3);
return 0;
}

original_code:
int main(int argc, char **argv) {
    block_t *block = slurp(getchar);
    verbatim(block->size, block->buffer);
    free_block(block);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    struct block_t *block = slurp(getchar);
    verbatim(block->size, block->buffer);
    free_block(block);
    return 0;
}


errorMessage

repo: Autarc/Media-Programming

decompiled_code:
void __fastcall __noreturn errorMessage(__int16 a1, const char *a2)
{
fprintf(
stderr,
"\n"
"ERROR:\t\t(%i) - %s\n"
"\n"
"USAGE:\t\tpgmop.elf <infile> [-o <outfile>] [ -norm | -invert ]\n"
"\n"
"EXAMPLE:\tpgmop.elf logo.bin.pgm -o normalized.bin.pgm -norm\n"
"\t\tpgmop.elf logo.bin.pgm -invert | display\n"
"\n"
"DESCRIPTION:\tpgmop is a small utility tool, which reads PGM images (ascii or binary)\n"
"\t\tand can normalize or invert them. The result can be saved into a file\n"
"\t\tor shown at the commandline.\n"
"\n",
(unsigned int)a1,
a2);
exit(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(__int16 a1, const char *a2)
{
fprintf(
stderr,
"\n"
"ERROR:\t\t(%i) - %s\n"
"\n"
"USAGE:\t\tpgmop.elf <infile> [-o <outfile>] [ -norm | -invert ]\n"
"\n"
"EXAMPLE:\tpgmop.elf logo.bin.pgm -o normalized.bin.pgm -norm\n"
"\t\tpgmop.elf logo.bin.pgm -invert | display\n"
"\n"
"DESCRIPTION:\tpgmop is a small utility tool, which reads PGM images (ascii or binary)\n"
"\t\tand can normalize or invert them. The result can be saved into a file\n"
"\t\tor shown at the commandline.\n"
"\n",
(unsigned int)a1,
a2);
exit(a1);
}

original_code:
void errorMessage ( short exitNumber, char* message ) {
 fprintf( stderr, "\nERROR:\t\t(%i) - %s\n\nUSAGE:\t\tpgmop.elf <infile> [-o <outfile>] [ -norm | -invert ]\n\nEXAMPLE:\tpgmop.elf logo.bin.pgm -o normalized.bin.pgm -norm\n\t\tpgmop.elf logo.bin.pgm -invert | display\n\nDESCRIPTION:\tpgmop is a small utility tool, which reads PGM images (ascii or binary)\n\t\tand can normalize or invert them. The result can be saved into a file\n\t\tor shown at the commandline.\n\n", exitNumber, message );
 exit( exitNumber );
}

canonical_original_code:
void errorMessage(short exitNumber, char *message) {
 fprintf( stderr, "\nERROR:\t\t(%i) - %s\n\nUSAGE:\t\tpgmop.elf <infile> [-o <outfile>] [ -norm | -invert ]\n\nEXAMPLE:\tpgmop.elf logo.bin.pgm -o normalized.bin.pgm -norm\n\t\tpgmop.elf logo.bin.pgm -invert | display\n\nDESCRIPTION:\tpgmop is a small utility tool, which reads PGM images (ascii or binary)\n\t\tand can normalize or invert them. The result can be saved into a file\n\t\tor shown at the commandline.\n\n", exitNumber, message );
 exit( exitNumber );
}

variable_types: exitNumber short


valid

decompiled_code:
_BOOL8 __fastcall valid(char a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( (unsigned __int8)(a1 + 1) <= 0x21u )
result = ((0x200004C01uLL >> (a1 + 1)) & 1) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( (unsigned __int8)(a1 + 1) <= 0x21u )
result = ((0x200004C01uLL >> (a1 + 1)) & 1) == 0;
return result;
}

variable_types: c char


setStats

original_code:
void setStats( Image * in, Image * out ) {
 out->magic[0] = 'P';
 out->magic[1] = '2';
 int width = in->width,
  height = in->height,
  i;
 out->width = width;
 out->height = height;
 out->depth = in->depth;
 out->data = (byte**) malloc( height * sizeof(byte*) );
 for ( i = 0; i < height; i++ ) {
  out->data[i] = (byte*) malloc( width * sizeof(byte) );
 }
 int x, y;
 for ( y = 0; y < height; y++ ) {
  for ( x = 0; x < width; x++ ) {
   out->data[y][x] = in->data[y][x];
  }
 }
}

canonical_original_code:
void setStats(struct image *in, struct image *out) {
 out->magic[0] = 'P';
 out->magic[1] = '2';
 int width = in->width; int height = in->height; int i;
 out->width = width;
 out->height = height;
 out->depth = in->depth;
 out->data = (unsigned char **) malloc( height * sizeof(unsigned char *) );
 for ( i = 0; i < height; i++ ) {
  out->data[i] = (unsigned char *) malloc( width * sizeof(byte) );
 }
 int x; int y;
 for ( y = 0; y < height; y++ ) {
  for ( x = 0; x < width; x++ ) {
   out->data[y][x] = in->data[y][x];
  }
 }
}

variable_types: struct image { char *name; char magic[2]; char **comments; unsigned short width; unsigned short height; unsigned short depth; unsigned char **data; unsigned short min; unsigned short max; } *

variable_types:
out
struct image *

variable_types: width int

variable_types: height int

variable_types: i int

variable_types: x int

variable_types: y int


NormPGM

original_code:
unsigned short NormPGM( Image * in, Image * out ) {
    int height = in->height,
     width = in->width,
     min = in->min,
     max = in->max,
     range = max - min;
    int x, y;
    byte color;
    for ( y = 0; y < height; y++ ) {
     for ( x = 0; x < width; x++ ) {
   color = in->data[y][x];
   out->data[y][x] = ( color - min ) * 255 / range;
     }
    }
 return 1;
}

canonical_original_code:
unsigned short NormPGM(struct image *in, struct image *out) {
    int height = in->height; int width = in->width; int min = in->min; int max = in->max; int range = max - min;
    int x; int y;
    unsigned char color;
    for ( y = 0; y < height; y++ ) {
     for ( x = 0; x < width; x++ ) {
   color = in->data[y][x];
   out->data[y][x] = ( color - min ) * 255 / range;
     }
    }
 return 1;
}

variable_types: min int

variable_types: max int

variable_types: range int

variable_types:
color
unsigned char

return_type: unsigned short

user_defined_types: struct image { char *name; char magic[2]; char **comments; unsigned short width; unsigned short height; unsigned short depth; unsigned char **data; unsigned short min; unsigned short max; }


InvertPGM

original_code:
unsigned short InvertPGM( Image * in, Image * out ) {
    int height = in->height,
     width = in->width,
     x, y, color;
    for ( y = 0; y < height; y++ ) {
     for ( x = 0; x < width; x++ ) {
   color = in->data[y][x];
   out->data[y][x] = 255 - color;
     }
    }
 return 1;
}

canonical_original_code:
unsigned short InvertPGM(struct image *in, struct image *out) {
    int height = in->height; int width = in->width; int x; int y; int color;
    for ( y = 0; y < height; y++ ) {
     for ( x = 0; x < width; x++ ) {
   color = in->data[y][x];
   out->data[y][x] = 255 - color;
     }
    }
 return 1;
}

variable_types: color int


freeImage

original_code:
void freeImage( Image * img ) {
 int height = img->height,
  i;
 for ( i = 0; i < height; i++ ) {
  free( img->data[i] );
 }
 free( img->data );
}

canonical_original_code:
void freeImage(struct image *img) {
 int height = img->height; int i;
 for ( i = 0; i < height; i++ ) {
  free( img->data[i] );
 }
 free( img->data );
}


main

repo: AvdeevPavel/linux

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
run(argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func13(argc, argv, envp);
return 0;
}

original_code:
int main() {
 run();
 return 0;
}

canonical_original_code:
int main() {
 run();
 return 0;
}


printString

decompiled_code:
void __fastcall printString(void *buf, int a2)
{
int v3; // ebx
int v4; // eax

if ( a2 > 0 )
{
v3 = a2;
do
{
v4 = write(1, buf, v3);
if ( v4 < 0 )
exit(1);
v3 -= v4;
buf = (char *)buf + v4;
}
while ( v3 > 0 );
}
}

canonical_decompiled_code:
void __fastcall func7(void *buf, int a2)
{
int v3; // ebx
int v4; // eax

if ( a2 > 0 )
{
v3 = a2;
do
{
v4 = write(1, buf, v3);
if ( v4 < 0 )
exit(1);
v3 -= v4;
buf = (char *)buf + v4;
}
while ( v3 > 0 );
}
}

original_code:
void printString(char *str, int size_) {
 int n_written = 0;
 while(size_ > 0) {
  n_written = write(1, str, size_);
  if (n_written < 0) {
   exit(1);
  }
  str = str + n_written;
  size_ = size_ - n_written;
 }
}

variable_types:
str
char *


reverseString

original_code:
void reverseString(char *str, int size_) {
 int i = 0;
 for (i = 0; i < size_ / 2; ++i) {
  str[i] = str[i] ^ str[size_ - i - 1];
  str[size_ - i - 1] = str[i] ^ str[size_ - i - 1];
  str[i] = str[i] ^ str[size_ - i - 1];
 }
}


getStringInConsole

decompiled_code:
__int64 __fastcall getStringInConsole(__int64 a1, unsigned int *a2, int a3)
{
int v3; // eax
unsigned int v4; // er8

v3 = read(0, (void *)(a1 + a3), 10 - a3);
if ( !v3 )
return 0LL;
if ( v3 < 0 )
exit(1);
v4 = v3 + *a2;
*a2 = v4;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned int *a2, int a3)
{
int v3; // eax
unsigned int v4; // er8

v3 = read(0, (void *)(a1 + a3), 10 - a3);
if ( !v3 )
return 0LL;
if ( v3 < 0 )
exit(1);
v4 = v3 + *a2;
*a2 = v4;
return v4;
}

original_code:
int getStringInConsole(char *buffer, int *indexRead, int sub) {
 int n_read = read(0, buffer + sub, 10 - sub);
 if (n_read == 0) {
  return 0;
 } else if (n_read < 0) {
  exit(1);
 } else {
  *indexRead += n_read;
  return *indexRead;
 }
}

variable_types:
buffer
char *

variable_types:
indexRead
int *

variable_types: sub int


getStringInBuf

decompiled_code:
__int64 __fastcall getStringInBuf(__int64 a1, __int64 a2, int *a3, int *a4)
{
int v4; // eax
int v5; // edx
int *v6; // rcx
__int64 v7; // r9
_DWORD *v8; // r10
int v9; // eax

v4 = findEndString(a1 + *a4, *a3);
if ( v4 < 0 )
return 0LL;
v9 = v4 + 1;
*v8 = v9 - v5;
*v6 = v9;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, int *a3, int *a4)
{
int v4; // eax
int v5; // edx
int *v6; // rcx
__int64 v7; // r9
_DWORD *v8; // r10
int v9; // eax

v4 = func9(a1 + *a4, *a3);
if ( v4 < 0 )
return 0LL;
v9 = v4 + 1;
*v8 = v9 - v5;
*v6 = v9;
return v7;
}

original_code:
char *getStringInBuf(char *buffer, int *len, int *indexRead, int *index_) {
 int indexEnd = findEndString(buffer + *index_, *indexRead);
 char *out = ((void *)0);
 if (indexEnd < 0) {
  return ((void *)0);
 } else {
  out = buffer + *index_;
  *len = (indexEnd + 1) - *index_;
      *index_ = indexEnd + 1;
  return out;
 }
}

variable_types:
len
int *

variable_types: indexEnd int

variable_types:
out
char *


decompiled_code:
__int64 __fastcall getline_(__int64 *a1)
{
__int64 v1; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = 0;
while ( 1 )
{
LABEL_2:
if ( index__2 )
{
indexRead_1 -= index__2;
memmove(&buffer_0, (const void *)(index__2 + 4210768LL), indexRead_1);
index__2 = 0;
}
v1 = getStringInBuf((__int64)&buffer_0, (__int64)v3, &indexRead_1, &index__2);
if ( v1 )
break;
if ( indexRead_1 == 10 )
{
while ( 1 )
{
index__2 = 0;
indexRead_1 = 0;
if ( !(unsigned int)getStringInConsole((__int64)&buffer_0, (unsigned int *)&indexRead_1, 0) )
break;
if ( getStringInBuf((__int64)&buffer_0, (__int64)v3, &indexRead_1, &index__2) )
goto LABEL_2;
}
LABEL_7:
*a1 = 0LL;
return 0LL;
}
if ( !(unsigned int)getStringInConsole((__int64)&buffer_0, (unsigned int *)&indexRead_1, indexRead_1) )
goto LABEL_7;
}
*a1 = v1;
return (unsigned int)v3[0];
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1)
{
__int64 v1; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = 0;
while ( 1 )
{
LABEL_2:
if ( index__2 )
{
indexRead_1 -= index__2;
memmove(&buffer_0, (const void *)(index__2 + 4210768LL), indexRead_1);
index__2 = 0;
}
v1 = func11((__int64)&buffer_0, (__int64)v3, &indexRead_1, &index__2);
if ( v1 )
break;
if ( indexRead_1 == 10 )
{
while ( 1 )
{
index__2 = 0;
indexRead_1 = 0;
if ( !(unsigned int)func10((__int64)&buffer_0, (unsigned int *)&indexRead_1, 0) )
break;
if ( func11((__int64)&buffer_0, (__int64)v3, &indexRead_1, &index__2) )
goto LABEL_2;
}
LABEL_7:
*a1 = 0LL;
return 0LL;
}
if ( !(unsigned int)func10((__int64)&buffer_0, (unsigned int *)&indexRead_1, indexRead_1) )
goto LABEL_7;
}
*a1 = v1;
return (unsigned int)v3[0];
}

original_code:
int getline_(char **str) {
 static int indexRead = 0;
 static int index_ = 0;
 static char buffer[10];
 int n_read = 0;
 int length_ = 0;
 char *tempStr = *str;
 for(;;) {
  if (index_ != 0) {
   indexRead -= index_;
   memmove(buffer, buffer + index_, indexRead);
   index_ = 0;
  }
  tempStr = getStringInBuf(buffer, &length_, &indexRead, &index_);
  if (tempStr != ((void *)0)) {
   *str = tempStr;
   return length_;
  } else {
   if (10 == indexRead) {
    while(tempStr == ((void *)0)) {
     index_ = 0;
     indexRead = 0;
     n_read = getStringInConsole(buffer, &indexRead, 0);
     if (n_read == 0) {
      *str = ((void *)0);
      return 0;
     }
     tempStr = getStringInBuf(buffer, &length_, &indexRead, &index_);
    }
   } else {
    n_read = getStringInConsole(buffer, &indexRead, indexRead);
    if (n_read == 0) {
     *str = ((void *)0);
     return 0;
    }
   }
  }
 }
}

variable_types:
str
char **

variable_types: indexRead int

variable_types:
buffer
char [10]

variable_types:
tempStr
char *


main

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func12(argc, argv, envp);
return 0;
}


printString

canonical_original_code:
void printString(char *str, int size_) {
 int n_written = 0;
 while(size_ > 0) {
  n_written = write(1, str, size_);
  if (n_written < 0) {
   exit(1);
  }
  str = str + n_written;
  size_ = size_ - n_written;
 }
}


reverseString

canonical_original_code:
void reverseString(char *str, int size_) {
 int i = 0;
 for (i = 0; i < size_ / 2; ++i) {
  str[i] = str[i] ^ str[size_ - i - 1];
  str[size_ - i - 1] = str[i] ^ str[size_ - i - 1];
  str[i] = str[i] ^ str[size_ - i - 1];
 }
}

variable_types: i int


delete

decompiled_code:
void __fastcall delete(_QWORD *a1)
{
void *v2; // rdi

if ( a1[2] )
delete();
v2 = (void *)a1[1];
if ( v2 )
free(v2);
free(a1);
}

canonical_decompiled_code:
void __fastcall func10(_QWORD *a1)
{
void *v2; // rdi

if ( a1[2] )
func10();
v2 = (void *)a1[1];
if ( v2 )
free(v2);
free(a1);
}

original_code:
void delete(Node *current) {
 if (current->prev != ((void *)0)) {
  delete(current->prev);
 }
 if (current->str != ((void *)0)) {
  free(current->str);
 }
 free(current);
}

canonical_original_code:
void delete(struct Node *current) {
 if (current->prev != ((void *)0)) {
  delete(current->prev);
 }
 if (current->str != ((void *)0)) {
  free(current->str);
 }
 free(current);
}

variable_types: struct Node { int size; int sizeStr; char *str; struct Node *prev; } *


reverseToPrint

decompiled_code:
void __fastcall reverseToPrint(__int64 a1)
{
int v2; // esi

do
{
v2 = *(_DWORD *)(a1 + 4);
if ( v2 > 0 )
{
reverseString(*(_QWORD *)(a1 + 8), v2);
printString(*(void **)(a1 + 8), *(_DWORD *)(a1 + 4));
}
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
}

original_code:
void reverseToPrint(Node* current) {
 if (current->sizeStr > 0) {
  reverseString(current->str, current->sizeStr);
  printString(current->str, current->sizeStr);
 }
 if (current->prev != ((void *)0))
  reverseToPrint(current->prev);
}

canonical_original_code:
void reverseToPrint(struct Node *current) {
 if (current->sizeStr > 0) {
  reverseString(current->str, current->sizeStr);
  printString(current->str, current->sizeStr);
 }
 if (current->prev != ((void *)0))
  reverseToPrint(current->prev);
}

user_defined_types: struct Node { int size; int sizeStr; char *str; struct Node *prev; }


decompiled_code:
void stroe_in_memory()
{
__int64 v0; // r13
char *i; // r12
int v2; // ebp
int v3; // ebx
char *v4; // r14
char v5; // al

v0 = 0LL;
i = 0LL;
v2 = 10;
if ( __ROR4__(-858993459, 1) > 0x19999999u )
goto LABEL_9;
LABEL_2:
for ( i = (char *)realloc(i, v2); i; i = (char *)malloc(0xAuLL) )
{
v3 = v0;
v4 = &i[v0];
do
{
v5 = getchar();
if ( v5 == 10 )
{
*v4 = 0;
printf("\nthe string we get is %s\n", i);
free(i);
return;
}
++v3;
*v4++ = v5;
}
while ( v2 > v3 );
v2 += 10;
v0 += 10LL;
if ( __ROR4__(-858993459 * v3, 1) <= 0x19999999u )
goto LABEL_2;
LABEL_9:
;
}
puts("\nCan't find free space in memory");
printf("\nthe string we get is %s\n", 0LL);
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // r13
char *i; // r12
int v2; // ebp
int v3; // ebx
char *v4; // r14
char v5; // al

v0 = 0LL;
i = 0LL;
v2 = 10;
if ( __ROR4__(-858993459, 1) > 0x19999999u )
goto LABEL_9;
LABEL_2:
for ( i = (char *)realloc(i, v2); i; i = (char *)malloc(0xAuLL) )
{
v3 = v0;
v4 = &i[v0];
do
{
v5 = getchar();
if ( v5 == 10 )
{
*v4 = 0;
printf("\nthe string we get is %s\n", i);
free(i);
return;
}
++v3;
*v4++ = v5;
}
while ( v2 > v3 );
v2 += 10;
v0 += 10LL;
if ( __ROR4__(-858993459 * v3, 1) <= 0x19999999u )
goto LABEL_2;
LABEL_9:
;
}
puts("\nCan't find free space in memory");
printf("\nthe string we get is %s\n", 0LL);
}

original_code:
void stroe_in_memory() {
 int index = 1, interval = 1;
 char *string = ((void *)0), input;
 while (1 == 1) {
  if (index % 10 == 0) {
   string = (char *) realloc(string,
     10 * interval * sizeof(char));
  } else {
   string = (char *) malloc(10 * sizeof(char));
  }
  if (string != ((void *)0) ) {
   for (index = 10 * (interval - 1);
   index < 10 * interval; ++index) {
    if ((input = getchar()) == '\n') {
     *(string + index) = '\0';
     break;
    }
    *(string + index) = input;
   }
   if (input == '\n') {
    break;
   }
   ++interval;
  } else {
   printf("\nCan't find free space in memory\n");
   break;
  }
 }
 printf("\nthe string we get is %s\n", string);
 if (string != ((void *)0) ) {
  free(string);
 }
}

canonical_original_code:
void stroe_in_memory() {
 int index = 1; int interval = 1;
 char *string = ((void *)0); char input;
 while (1 == 1) {
  if (index % 10 == 0) {
   string = (char *) realloc(string,
     10 * interval * sizeof(char));
  } else {
   string = (char *) malloc(10 * sizeof(char));
  }
  if (string != ((void *)0) ) {
   for (index = 10 * (interval - 1);
   index < 10 * interval; ++index) {
    if ((input = getchar()) == '\n') {
     *(string + index) = '\0';
     break;
    }
    *(string + index) = input;
   }
   if (input == '\n') {
    break;
   }
   ++interval;
  } else {
   printf("\nCan't find free space in memory\n");
   break;
  }
 }
 printf("\nthe string we get is %s\n", string);
 if (string != ((void *)0) ) {
  free(string);
 }
}

variable_types: index int

variable_types: interval int

variable_types:
string
char *

variable_types: input char


main

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

while ( 1 )
{
puts("\nplease chose how to store the input:");
puts("1. connected list");
puts("2. array in memory");
printf("enter your chose:");
v3 = getchar();
getchar();
puts("\nStart to enter your string");
if ( v3 == 49 )
{
connected_list_string("\nStart to enter your string", argv);
return 0;
}
if ( v3 == 50 )
break;
puts("\nSorry but this option dosn't exist in the menu, please try again\n\n");
getchar();
}
stroe_in_memory("\nStart to enter your string", argv);
return 0;
}

original_code:
int main(void) {
 int again = 1;
 char choise = '\0';
 while (again > 0) {
  printf("\nplease chose how to store the input:\n");
  printf("1. connected list\n");
  printf("2. array in memory\n");
  printf("enter your chose:");
  choise = getchar();
  getchar();
  printf("\nStart to enter your string\n");
  switch (choise) {
  case '1':
   connected_list_string();
   again = 0;
   break;
  case '2':
   stroe_in_memory();
   again = 0;
   break;
  default:
   printf(
     "\nSorry but this option dosn't exist in the menu, please try again\n\n\n");
   getchar();
   break;
  }
 }
 return 0;
}

canonical_original_code:
int main() {
 int again = 1;
 char choise = '\0';
 while (again > 0) {
  printf("\nplease chose how to store the input:\n");
  printf("1. connected list\n");
  printf("2. array in memory\n");
  printf("enter your chose:");
  choise = getchar();
  getchar();
  printf("\nStart to enter your string\n");
  switch (choise) {
  case '1':
   connected_list_string();
   again = 0;
   break;
  case '2':
   stroe_in_memory();
   again = 0;
   break;
  default:
   printf(
     "\nSorry but this option dosn't exist in the menu, please try again\n\n\n");
   getchar();
   break;
  }
 }
 return 0;
}

variable_types: again int

variable_types: choise char


decompiled_code:
void connected_list_string()
{
char *v0; // rax
char *v1; // r13
char *v2; // r12
char *v3; // rbx
char v4; // al
char *v5; // rax
_QWORD *v6; // rax
char *v7; // rdi

v0 = (char *)malloc(0x18uLL);
if ( !v0 )
LABEL_11:
connected_list_string_cold();
v1 = v0;
v2 = v0;
LABEL_3:
v3 = v2;
while ( 1 )
{
v4 = getchar();
if ( v4 == 10 )
break;
*v3++ = v4;
if ( v3 == v2 + 10 )
{
v5 = (char *)malloc(0x18uLL);
*((_QWORD *)v2 + 2) = v5;
if ( !v5 )
goto LABEL_11;
v2 = v5;
goto LABEL_3;
}
}
v6 = malloc(0x18uLL);
*((_QWORD *)v2 + 2) = v6;
v6[2] = 0LL;
printf("The string we get is ");
while ( *((_QWORD *)v1 + 2) )
{
printf("%s", v1);
v7 = v1;
v1 = (char *)*((_QWORD *)v1 + 2);
free(v7);
}
putchar(10);
free(v1);
}

canonical_decompiled_code:
void func0()
{
char *v0; // rax
char *v1; // r13
char *v2; // r12
char *v3; // rbx
char v4; // al
char *v5; // rax
_QWORD *v6; // rax
char *v7; // rdi

v0 = (char *)malloc(0x18uLL);
if ( !v0 )
LABEL_11:
func1();
v1 = v0;
v2 = v0;
LABEL_3:
v3 = v2;
while ( 1 )
{
v4 = getchar();
if ( v4 == 10 )
break;
*v3++ = v4;
if ( v3 == v2 + 10 )
{
v5 = (char *)malloc(0x18uLL);
*((_QWORD *)v2 + 2) = v5;
if ( !v5 )
goto LABEL_11;
v2 = v5;
goto LABEL_3;
}
}
v6 = malloc(0x18uLL);
*((_QWORD *)v2 + 2) = v6;
v6[2] = 0LL;
printf("The string we get is ");
while ( *((_QWORD *)v1 + 2) )
{
printf("%s", v1);
v7 = v1;
v1 = (char *)*((_QWORD *)v1 + 2);
free(v7);
}
putchar(10);
free(v1);
}

original_code:
void connected_list_string() {
 cstring *list = ((void *)0), *first = ((void *)0);
 char input;
 int index = 0;
 first = (cstring *) malloc(sizeof(cstring));
 list = first;
 while (list != ((void *)0)) {
  for (index = 0; index < 10; ++index) {
   if ((input = getchar()) != '\n') {
    list->str[index] = input;
   } else {
    break;
   }
  }
  list->next = (cstring *) malloc(sizeof(cstring));
  list = list->next;
  if (input == '\n') {
   break;
  }
 }
 list->next = ((void *)0);
 printf("The string we get is ");
 while (first->next != ((void *)0)) {
  printf("%s", first->str);
  list = first;
  first = first->next;
  free(list);
 }
 printf("\n");
 free(first);
}

canonical_original_code:
void connected_list_string() {
 struct stringStruct *list = ((void *)0); struct stringStruct *first = ((void *)0);
 char input;
 int index = 0;
 first = (struct stringStruct *) malloc(sizeof(cstring));
 list = first;
 while (list != ((void *)0)) {
  for (index = 0; index < 10; ++index) {
   if ((input = getchar()) != '\n') {
    list->str[index] = input;
   } else {
    break;
   }
  }
  list->next = (struct stringStruct *) malloc(sizeof(cstring));
  list = list->next;
  if (input == '\n') {
   break;
  }
 }
 list->next = ((void *)0);
 printf("The string we get is ");
 while (first->next != ((void *)0)) {
  printf("%s", first->str);
  list = first;
  first = first->next;
  free(list);
 }
 printf("\n");
 free(first);
}

variable_types: struct stringStruct { char str[10]; struct stringStruct *next; } *


testWord

decompiled_code:
__int64 __fastcall testWord(const char *a1, const char *a2)
{
int v3; // er13
size_t v4; // r8
__int64 result; // rax
char v6; // dl
char *v7; // rdi
__int64 v8; // rax
int v9; // ecx

v3 = strlen(a1);
v4 = strlen(a2);
result = 0xFFFFFFFFLL;
if ( v3 == v4 )
{
v6 = *a2;
if ( *a2 )
{
v7 = (char *)(a2 + 1);
do
{
v8 = 1LL;
v9 = 0;
if ( v3 > 0 )
{
while ( a1[v8 - 1] != v6 )
{
v9 = v8++;
if ( v8 == (unsigned int)(v3 - 1) + 2LL )
goto LABEL_11;
}
}
else
{
LABEL_11:
if ( v3 == v9 )
return 0xFFFFFFFFLL;
}
v6 = *v7++;
}
while ( v6 );
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
int v3; // er13
size_t v4; // r8
__int64 result; // rax
char v6; // dl
char *v7; // rdi
__int64 v8; // rax
int v9; // ecx

v3 = strlen(a1);
v4 = strlen(a2);
result = 0xFFFFFFFFLL;
if ( v3 == v4 )
{
v6 = *a2;
if ( *a2 )
{
v7 = (char *)(a2 + 1);
do
{
v8 = 1LL;
v9 = 0;
if ( v3 > 0 )
{
while ( a1[v8 - 1] != v6 )
{
v9 = v8++;
if ( v8 == (unsigned int)(v3 - 1) + 2LL )
goto LABEL_11;
}
}
else
{
LABEL_11:
if ( v3 == v9 )
return 0xFFFFFFFFLL;
}
v6 = *v7++;
}
while ( v6 );
}
result = 1LL;
}
return result;
}

original_code:
int testWord(char *word, char *letters){
 int lettersIndex, wordIndex, wordLength;
 if((wordLength = strlen(word)) != strlen(letters)){
  return -1;
 }
 for(lettersIndex = 0; letters[lettersIndex] != 0; lettersIndex++){
  for(wordIndex=0; wordIndex < wordLength; ++wordIndex){
   if (word[wordIndex] == letters[lettersIndex]){
    break;
   }
  }
  if(wordIndex == wordLength){
   return -1;
  }
 }
 return 1;
}

canonical_original_code:
int testWord(char *word, char *letters){
 int lettersIndex; int wordIndex; int wordLength;
 if((wordLength = strlen(word)) != strlen(letters)){
  return -1;
 }
 for(lettersIndex = 0; letters[lettersIndex] != 0; lettersIndex++){
  for(wordIndex=0; wordIndex < wordLength; ++wordIndex){
   if (word[wordIndex] == letters[lettersIndex]){
    break;
   }
  }
  if(wordIndex == wordLength){
   return -1;
  }
 }
 return 1;
}

variable_types:
word
char *

variable_types:
letters
char *

variable_types: lettersIndex int

variable_types: wordIndex int

variable_types: wordLength int


repo: AxFab/axlibc

original_code:
void test_stack ()
{
  void* stack[2048];
  int sp = 0;
  xHeapArea_t heap;
  meminit_r (&heap, malloc (0x80000), 0x80000 - 64);
  stack[sp++] = malloc_r(&heap, 64);
  stack[sp++] = malloc_r(&heap, 64);
  while (sp < 2048 - 4) {
    printf("%-20s   [%s]\n", ("#1"), (0) == (memcorrupt_r (&heap)) ? "\e[32mOk\e[0m" : "\e[31mErr\e[0m" );
    stack[sp++] = malloc_r(&heap, 64);
    stack[sp++] = malloc_r(&heap, 48);
    free_r(&heap, stack[sp-3]);
    printf("%-20s   [%s]\n", ("#2"), (0) == (memcorrupt_r (&heap)) ? "\e[32mOk\e[0m" : "\e[31mErr\e[0m" );
    stack[sp-3] = malloc_r(&heap, 64);
    stack[sp++] = malloc_r(&heap, 48);
    stack[sp++] = malloc_r(&heap, 48);
    printf("%-20s   [%s]\n", ("#3"), (0) == (memcorrupt_r (&heap)) ? "\e[32mOk\e[0m" : "\e[31mErr\e[0m" );
    stack[sp-4] = malloc_r(&heap, 64);
    free_r(&heap, stack[sp--]);
    free_r(&heap, stack[sp--]);
    printf("%-20s   [%s]\n", ("#4"), (0) == (memcorrupt_r (&heap)) ? "\e[32mOk\e[0m" : "\e[31mErr\e[0m" );
  }
}

canonical_original_code:
void test_stack()
{
  void *stack[2048];
  int sp = 0;
  struct xHeapArea heap;
  meminit_r (&heap, malloc (0x80000), 0x80000 - 64);
  stack[sp++] = malloc_r(&heap, 64);
  stack[sp++] = malloc_r(&heap, 64);
  while (sp < 2048 - 4) {
    printf("%-20s   [%s]\n", ("#1"), (0) == (memcorrupt_r (&heap)) ? "\e[32mOk\e[0m" : "\e[31mErr\e[0m" );
    stack[sp++] = malloc_r(&heap, 64);
    stack[sp++] = malloc_r(&heap, 48);
    free_r(&heap, stack[sp-3]);
    printf("%-20s   [%s]\n", ("#2"), (0) == (memcorrupt_r (&heap)) ? "\e[32mOk\e[0m" : "\e[31mErr\e[0m" );
    stack[sp-3] = malloc_r(&heap, 64);
    stack[sp++] = malloc_r(&heap, 48);
    stack[sp++] = malloc_r(&heap, 48);
    printf("%-20s   [%s]\n", ("#3"), (0) == (memcorrupt_r (&heap)) ? "\e[32mOk\e[0m" : "\e[31mErr\e[0m" );
    stack[sp-4] = malloc_r(&heap, 64);
    free_r(&heap, stack[sp--]);
    free_r(&heap, stack[sp--]);
    printf("%-20s   [%s]\n", ("#4"), (0) == (memcorrupt_r (&heap)) ? "\e[32mOk\e[0m" : "\e[31mErr\e[0m" );
  }
}

variable_types:
stack
void *[2048]

variable_types: sp int

variable_types: struct xHeapArea { struct xHeapChunk { unsigned int prev_size; unsigned int reserved; unsigned int chunk_size; unsigned int is_used; union { struct { struct xHeapChunk *prev_chunk; struct xHeapChunk *next_chunk; }; unsigned int data[4]; }; } *start; struct xHeapChunk *free_list; unsigned long max; unsigned long available; char lock; long flags; }

user_defined_types: struct xHeapArea { struct xHeapChunk *start; struct xHeapChunk *free_list; unsigned long max; unsigned long available; char lock; long flags; }


canonical_original_code:
void test_big() {
  struct xHeapArea heap;
  meminit_r (&heap, malloc (0x80000), 0x80000 - 64);
  malloc_r(&heap, 64);
  malloc_r(&heap, 64);
  malloc_r(&heap, 64);
  void *big = malloc_r(&heap, 1024);
  printf("%-20s   [%s]\n", ("#1"), (0) == (memcorrupt_r (&heap)) ? "\e[32mOk\e[0m" : "\e[31mErr\e[0m" );
  malloc_r(&heap, 64);
  malloc_r(&heap, 64);
  free_r (&heap, big);
  printf("%-20s   [%s]\n", ("#2"), (0) == (memcorrupt_r (&heap)) ? "\e[32mOk\e[0m" : "\e[31mErr\e[0m" );
  malloc_r(&heap, 64);
  printf("%-20s   [%s]\n", ("#3"), (0) == (memcorrupt_r (&heap)) ? "\e[32mOk\e[0m" : "\e[31mErr\e[0m" );
}

variable_types:
big
void *

user_defined_types: struct xHeapChunk { unsigned int prev_size; unsigned int reserved; unsigned int chunk_size; unsigned int is_used; union { struct { struct xHeapChunk *prev_chunk; struct xHeapChunk *next_chunk; }; unsigned int data[4]; }; }


kprintf

decompiled_code:
__int64 __fastcall kprintf(const char *a1)
{
++_gcov0_kprintf;
printf("%s", a1);
++qword_768;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
++_gcov0_kprintf;
printf("%s", a1);
++qword_768;
return 0LL;
}

original_code:
int kprintf (const char *msg) {
  printf ("%s",msg);
  return 0;
}

canonical_original_code:
int kprintf(char *msg) {
  printf ("%s",msg);
  return 0;
}

variable_types:
msg
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
int v4; // eax
const char *v5; // rdx
int v6; // eax
const char *v7; // rdx
_BYTE v9[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_main;
v3 = malloc(0x80000uLL);
meminit_r(v9, v3, 524224LL);
++qword_788;
v4 = memcorrupt_r(v9);
++qword_790;
v5 = "\x1B[32mOk\x1B[0m";
if ( v4 )
{
++qword_798;
v5 = "\x1B[31mErr\x1B[0m";
}
printf("%-20s [%s]\n", "#1", v5);
++qword_7A0;
malloc_r(v9, 64LL);
++qword_7A8;
v6 = memcorrupt_r(v9);
++qword_7B0;
v7 = "\x1B[32mOk\x1B[0m";
if ( v6 )
{
++qword_7B8;
v7 = "\x1B[31mErr\x1B[0m";
}
printf("%-20s [%s]\n", "#2", v7);
++qword_7C0;
test_big();
++qword_7C8;
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
int v4; // eax
const char *v5; // rdx
int v6; // eax
const char *v7; // rdx
_BYTE v9[56]; // [rsp+0h] [rbp-38h] BYREF

++_gcov0_main;
v3 = malloc(0x80000uLL);
meminit_r(v9, v3, 524224LL);
++qword_788;
v4 = memcorrupt_r(v9);
++qword_790;
v5 = "\x1B[32mOk\x1B[0m";
if ( v4 )
{
++qword_798;
v5 = "\x1B[31mErr\x1B[0m";
}
printf("%-20s [%s]\n", "#1", v5);
++qword_7A0;
malloc_r(v9, 64LL);
++qword_7A8;
v6 = memcorrupt_r(v9);
++qword_7B0;
v7 = "\x1B[32mOk\x1B[0m";
if ( v6 )
{
++qword_7B8;
v7 = "\x1B[31mErr\x1B[0m";
}
printf("%-20s [%s]\n", "#2", v7);
++qword_7C0;
func1();
++qword_7C8;
return 0;
}


atoi

decompiled_code:
__int64 __fastcall atoi(char *a1)
{
__int64 result; // rax
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

++_gcov0_atoi;
result = strtox(a1, 0LL, 10, v2);
if ( v2[0] == 43 )
{
++qword_CA0;
}
else
{
++qword_C98;
result = (unsigned int)-(int)result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
__int64 result; // rax
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

++_gcov0_atoi;
result = func0(a1, 0LL, 10, v2);
if ( v2[0] == 43 )
{
++qword_CA0;
}
else
{
++qword_C98;
result = (unsigned int)-(int)result;
}
return result;
}

original_code:
int atoi (const char* str)
{
  char sign;
  uintmax_t value = _strtox(str, 0, 10, &sign);
  return (int) (sign == '+') ? value : -value;
}

canonical_original_code:
int atoi(char *str)
{
  char sign;
  unsigned long long value = _strtox(str, 0, 10, &sign);
  return (int) (sign == '+') ? value : -value;
}

variable_types:
str
char *

variable_types: sign char

variable_types:
value
unsigned long long


atol

decompiled_code:
__int64 __fastcall atol(char *a1)
{
__int64 result; // rax
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

++_gcov0_atol;
result = strtox(a1, 0LL, 10, v2);
if ( v2[0] == 43 )
{
++qword_CC0;
}
else
{
++qword_CB8;
result = -result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
__int64 result; // rax
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

++_gcov0_atol;
result = func0(a1, 0LL, 10, v2);
if ( v2[0] == 43 )
{
++qword_CC0;
}
else
{
++qword_CB8;
result = -result;
}
return result;
}

original_code:
long atol (const char* str)
{
  char sign;
  uintmax_t value = _strtox(str, 0, 10, &sign);
  return (long) (sign == '+') ? value : -value;
}

canonical_original_code:
long atol(char *str)
{
  char sign;
  unsigned long long value = _strtox(str, 0, 10, &sign);
  return (long) (sign == '+') ? value : -value;
}

return_type: long


atoll

decompiled_code:
__int64 __fastcall atoll(char *a1)
{
__int64 result; // rax
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

++_gcov0_atoll;
result = strtox(a1, 0LL, 10, v2);
if ( v2[0] == 43 )
{
++qword_CE0;
}
else
{
++qword_CD8;
result = -result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
__int64 result; // rax
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

++_gcov0_atoll;
result = func0(a1, 0LL, 10, v2);
if ( v2[0] == 43 )
{
++qword_CE0;
}
else
{
++qword_CD8;
result = -result;
}
return result;
}

original_code:
long long atoll (const char* str)
{
  char sign;
  uintmax_t value = _strtox(str, 0, 10, &sign);
  return (long long) (sign == '+') ? value : -value;
}

canonical_original_code:
long long atoll(char *str)
{
  char sign;
  unsigned long long value = _strtox(str, 0, 10, &sign);
  return (long long) (sign == '+') ? value : -value;
}

return_type: long long