readContention

decompiled_code:
void readContention()
{
__int64 v0; // r13
char *v1; // rax
const char *v2; // r12
int v3; // eax
int v4; // ebx
unsigned int i; // er14
int v6; // eax
int v7; // er14
unsigned int v8; // er12
__int64 v9; // r13
int v10; // eax
__pid_t v11; // eax
__pid_t v12; // eax
__pid_t v13; // eax
__pid_t v14; // eax
__pid_t v15; // eax
__pid_t v16; // eax
__pid_t v17; // eax
int v18; // ebx
__pid_t v19; // eax
__pid_t v20; // eax
__pid_t v21; // eax
__pid_t v22; // eax
__pid_t v23; // eax
__pid_t v24; // eax
__pid_t v25; // eax
__int64 v26; // rbx
int v27; // edx
char *v28; // r13
__int64 v29; // r12
__int64 v30; // r14
__int64 v31; // r12
unsigned __int64 v32; // r14
int v33; // ebx
unsigned int v34; // er12
int v35; // eax
double v36; // xmm1_8
__int64 v37; // r8
double v38; // xmm0_8
__pid_t v39; // eax
int fd[32]; // [rsp+0h] [rbp-201A0h]
char *name[32]; // [rsp+80h] [rbp-20120h]
char s[131104]; // [rsp+180h] [rbp-20020h] BYREF

v0 = 0LL;
memset(s, 42, 0x20000uLL);
do
{
v1 = strdup("./tmpReadContentionBenchXXXXXX");
name[v0] = v1;
v2 = v1;
v3 = mkstemp(v1);
fd[v0] = v3;
v4 = v3;
if ( v3 == -1 )
{
perror("File creation failed");
exit(1);
}
for ( i = 0; i <= 0x7FFFFFF; i += v6 )
{
v6 = write(v4, s, 0x20000uLL);
if ( v6 == -1 )
{
perror("Write error");
exit(1);
}
}
++v0;
printf("Temporary file %s created.\n", v2);
}
while ( v0 != 32 );
v7 = 6;
v8 = 1;
while ( 1 )
{
v9 = 0LL;
printf("Starting %d processes...\n", v8);
v10 = v8 & 7;
if ( (v8 & 7) == 0 )
break;
if ( v10 != 1 )
{
if ( v10 != 2 )
{
if ( v10 != 3 )
{
if ( v10 != 4 )
{
if ( v10 != 5 )
{
if ( v10 != 6 )
{
v39 = fork();
if ( !v39 )
goto LABEL_96;
if ( v39 == -1 )
perror("fork");
v9 = 1LL;
}
v11 = fork();
if ( !v11 )
goto LABEL_96;
if ( v11 == -1 )
perror("fork");
v9 = (unsigned int)(v9 + 1);
}
v12 = fork();
if ( !v12 )
goto LABEL_96;
if ( v12 == -1 )
perror("fork");
v9 = (unsigned int)(v9 + 1);
}
v13 = fork();
if ( !v13 )
goto LABEL_96;
if ( v13 == -1 )
perror("fork");
v9 = (unsigned int)(v9 + 1);
}
v14 = fork();
if ( !v14 )
goto LABEL_96;
if ( v14 == -1 )
perror("fork");
v9 = (unsigned int)(v9 + 1);
}
v15 = fork();
if ( !v15 )
goto LABEL_96;
if ( v15 == -1 )
perror("fork");
v9 = (unsigned int)(v9 + 1);
}
v16 = fork();
if ( !v16 )
goto LABEL_96;
if ( v16 == -1 )
perror("fork");
v9 = (unsigned int)(v9 + 1);
if ( (_DWORD)v9 != v8 )
break;
LABEL_64:
LODWORD(v26) = 0;
v27 = v8 & 7;
if ( (v8 & 7) == 0 )
goto LABEL_119;
if ( v27 != 1 )
{
if ( v27 != 2 )
{
if ( v27 != 3 )
{
if ( v27 != 4 )
{
if ( v27 != 5 )
{
if ( v27 != 6 )
{
waitid(P_ALL, 0, 0LL, 4);
LODWORD(v26) = 1;
}
waitid(P_ALL, 0, 0LL, 4);
LODWORD(v26) = v26 + 1;
}
waitid(P_ALL, 0, 0LL, 4);
LODWORD(v26) = v26 + 1;
}
waitid(P_ALL, 0, 0LL, 4);
LODWORD(v26) = v26 + 1;
}
waitid(P_ALL, 0, 0LL, 4);
LODWORD(v26) = v26 + 1;
}
waitid(P_ALL, 0, 0LL, 4);
LODWORD(v26) = v26 + 1;
}
waitid(P_ALL, 0, 0LL, 4);
v26 = (unsigned int)(v26 + 1);
if ( (_DWORD)v26 != v8 )
{
LABEL_119:
do
{
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
v26 = (unsigned int)(v26 + 8);
}
while ( (_DWORD)v26 != v8 );
}
v8 = 2 * v26;
if ( !--v7 )
{
v28 = name[v26];
close(fd[0]);
if ( unlink(name[0]) == -1 )
perror("File remove failed");
free(v28);
close(fd[1]);
if ( unlink(name[1]) == -1 )
perror("File remove failed");
v29 = 2LL;
free(v28);
do
{
close(fd[v29]);
if ( unlink(name[v29]) == -1 )
perror("File remove failed");
v30 = v29 + 1;
free(v28);
close(fd[v29 + 1]);
if ( unlink(name[v29 + 1]) == -1 )
perror("File remove failed");
free(v28);
close(fd[v29 + 2]);
if ( unlink(name[v29 + 2]) == -1 )
perror("File remove failed");
v31 = v29 + 3;
free(v28);
close(fd[v31]);
if ( unlink(name[v31]) == -1 )
perror("File remove failed");
free(v28);
close(fd[v30 + 3]);
if ( unlink(name[v30 + 3]) == -1 )
perror("File remove failed");
v29 = v30 + 4;
free(v28);
}
while ( v30 != 28 );
return;
}
}
while ( 1 )
{
v17 = fork();
if ( !v17 )
break;
if ( v17 == -1 )
perror("fork");
v18 = v9 + 1;
v9 = (unsigned int)(v9 + 1);
v19 = fork();
if ( !v19 )
break;
if ( v19 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 1);
v20 = fork();
if ( !v20 )
break;
if ( v20 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 2);
v21 = fork();
if ( !v21 )
break;
if ( v21 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 3);
v22 = fork();
if ( !v22 )
break;
if ( v22 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 4);
v23 = fork();
if ( !v23 )
break;
if ( v23 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 5);
v24 = fork();
if ( !v24 )
break;
if ( v24 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 6);
v25 = fork();
if ( !v25 )
break;
if ( v25 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 7);
if ( (_DWORD)v9 == v8 )
goto LABEL_64;
}
LABEL_96:
v32 = __rdtsc();
if ( gl_loopcycle )
{
v33 = fd[v9];
v34 = 0;
do
{
if ( lseek(v33, 0LL, 0) == -1 )
{
perror("Lseek error");
exit(1);
}
do
{
v35 = read(v33, s, 0x20000uLL);
if ( v35 == -1 )
{
perror("Read error");
exit(1);
}
}
while ( v35 );
++v34;
}
while ( gl_loopcycle > v34 );
v36 = (double)gl_loopcycle;
}
else
{
v36 = 0.0;
}
v37 = __rdtsc() - v32;
if ( v37 < 0 )
v38 = (double)(int)(((unsigned __int64)v37 >> 1) | v37 & 1) + (double)(int)(((unsigned __int64)v37 >> 1) | v37 & 1);
else
v38 = (double)(int)v37;
gl_lastavgres = v38 / v36;
printf("Sequential read of %dMB file = %f cycles\n", 128LL, v38 / v36);
free(name[v9]);
}

canonical_decompiled_code:
void func2()
{
__int64 v0; // r13
char *v1; // rax
const char *v2; // r12
int v3; // eax
int v4; // ebx
unsigned int i; // er14
int v6; // eax
int v7; // er14
unsigned int v8; // er12
__int64 v9; // r13
int v10; // eax
__pid_t v11; // eax
__pid_t v12; // eax
__pid_t v13; // eax
__pid_t v14; // eax
__pid_t v15; // eax
__pid_t v16; // eax
__pid_t v17; // eax
int v18; // ebx
__pid_t v19; // eax
__pid_t v20; // eax
__pid_t v21; // eax
__pid_t v22; // eax
__pid_t v23; // eax
__pid_t v24; // eax
__pid_t v25; // eax
__int64 v26; // rbx
int v27; // edx
char *v28; // r13
__int64 v29; // r12
__int64 v30; // r14
__int64 v31; // r12
unsigned __int64 v32; // r14
int v33; // ebx
unsigned int v34; // er12
int v35; // eax
double v36; // xmm1_8
__int64 v37; // r8
double v38; // xmm0_8
__pid_t v39; // eax
int fd[32]; // [rsp+0h] [rbp-201A0h]
char *name[32]; // [rsp+80h] [rbp-20120h]
char s[131104]; // [rsp+180h] [rbp-20020h] BYREF

v0 = 0LL;
memset(s, 42, 0x20000uLL);
do
{
v1 = strdup("./tmpReadContentionBenchXXXXXX");
name[v0] = v1;
v2 = v1;
v3 = mkstemp(v1);
fd[v0] = v3;
v4 = v3;
if ( v3 == -1 )
{
perror("File creation failed");
exit(1);
}
for ( i = 0; i <= 0x7FFFFFF; i += v6 )
{
v6 = write(v4, s, 0x20000uLL);
if ( v6 == -1 )
{
perror("Write error");
exit(1);
}
}
++v0;
printf("Temporary file %s created.\n", v2);
}
while ( v0 != 32 );
v7 = 6;
v8 = 1;
while ( 1 )
{
v9 = 0LL;
printf("Starting %d processes...\n", v8);
v10 = v8 & 7;
if ( (v8 & 7) == 0 )
break;
if ( v10 != 1 )
{
if ( v10 != 2 )
{
if ( v10 != 3 )
{
if ( v10 != 4 )
{
if ( v10 != 5 )
{
if ( v10 != 6 )
{
v39 = fork();
if ( !v39 )
goto LABEL_96;
if ( v39 == -1 )
perror("fork");
v9 = 1LL;
}
v11 = fork();
if ( !v11 )
goto LABEL_96;
if ( v11 == -1 )
perror("fork");
v9 = (unsigned int)(v9 + 1);
}
v12 = fork();
if ( !v12 )
goto LABEL_96;
if ( v12 == -1 )
perror("fork");
v9 = (unsigned int)(v9 + 1);
}
v13 = fork();
if ( !v13 )
goto LABEL_96;
if ( v13 == -1 )
perror("fork");
v9 = (unsigned int)(v9 + 1);
}
v14 = fork();
if ( !v14 )
goto LABEL_96;
if ( v14 == -1 )
perror("fork");
v9 = (unsigned int)(v9 + 1);
}
v15 = fork();
if ( !v15 )
goto LABEL_96;
if ( v15 == -1 )
perror("fork");
v9 = (unsigned int)(v9 + 1);
}
v16 = fork();
if ( !v16 )
goto LABEL_96;
if ( v16 == -1 )
perror("fork");
v9 = (unsigned int)(v9 + 1);
if ( (_DWORD)v9 != v8 )
break;
LABEL_64:
LODWORD(v26) = 0;
v27 = v8 & 7;
if ( (v8 & 7) == 0 )
goto LABEL_119;
if ( v27 != 1 )
{
if ( v27 != 2 )
{
if ( v27 != 3 )
{
if ( v27 != 4 )
{
if ( v27 != 5 )
{
if ( v27 != 6 )
{
waitid(P_ALL, 0, 0LL, 4);
LODWORD(v26) = 1;
}
waitid(P_ALL, 0, 0LL, 4);
LODWORD(v26) = v26 + 1;
}
waitid(P_ALL, 0, 0LL, 4);
LODWORD(v26) = v26 + 1;
}
waitid(P_ALL, 0, 0LL, 4);
LODWORD(v26) = v26 + 1;
}
waitid(P_ALL, 0, 0LL, 4);
LODWORD(v26) = v26 + 1;
}
waitid(P_ALL, 0, 0LL, 4);
LODWORD(v26) = v26 + 1;
}
waitid(P_ALL, 0, 0LL, 4);
v26 = (unsigned int)(v26 + 1);
if ( (_DWORD)v26 != v8 )
{
LABEL_119:
do
{
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
v26 = (unsigned int)(v26 + 8);
}
while ( (_DWORD)v26 != v8 );
}
v8 = 2 * v26;
if ( !--v7 )
{
v28 = name[v26];
close(fd[0]);
if ( unlink(name[0]) == -1 )
perror("File remove failed");
free(v28);
close(fd[1]);
if ( unlink(name[1]) == -1 )
perror("File remove failed");
v29 = 2LL;
free(v28);
do
{
close(fd[v29]);
if ( unlink(name[v29]) == -1 )
perror("File remove failed");
v30 = v29 + 1;
free(v28);
close(fd[v29 + 1]);
if ( unlink(name[v29 + 1]) == -1 )
perror("File remove failed");
free(v28);
close(fd[v29 + 2]);
if ( unlink(name[v29 + 2]) == -1 )
perror("File remove failed");
v31 = v29 + 3;
free(v28);
close(fd[v31]);
if ( unlink(name[v31]) == -1 )
perror("File remove failed");
free(v28);
close(fd[v30 + 3]);
if ( unlink(name[v30 + 3]) == -1 )
perror("File remove failed");
v29 = v30 + 4;
free(v28);
}
while ( v30 != 28 );
return;
}
}
while ( 1 )
{
v17 = fork();
if ( !v17 )
break;
if ( v17 == -1 )
perror("fork");
v18 = v9 + 1;
v9 = (unsigned int)(v9 + 1);
v19 = fork();
if ( !v19 )
break;
if ( v19 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 1);
v20 = fork();
if ( !v20 )
break;
if ( v20 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 2);
v21 = fork();
if ( !v21 )
break;
if ( v21 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 3);
v22 = fork();
if ( !v22 )
break;
if ( v22 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 4);
v23 = fork();
if ( !v23 )
break;
if ( v23 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 5);
v24 = fork();
if ( !v24 )
break;
if ( v24 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 6);
v25 = fork();
if ( !v25 )
break;
if ( v25 == -1 )
perror("fork");
v9 = (unsigned int)(v18 + 7);
if ( (_DWORD)v9 == v8 )
goto LABEL_64;
}
LABEL_96:
v32 = __rdtsc();
if ( gl_loopcycle )
{
v33 = fd[v9];
v34 = 0;
do
{
if ( lseek(v33, 0LL, 0) == -1 )
{
perror("Lseek error");
exit(1);
}
do
{
v35 = read(v33, s, 0x20000uLL);
if ( v35 == -1 )
{
perror("Read error");
exit(1);
}
}
while ( v35 );
++v34;
}
while ( gl_loopcycle > v34 );
v36 = (double)gl_loopcycle;
}
else
{
v36 = 0.0;
}
v37 = __rdtsc() - v32;
if ( v37 < 0 )
v38 = (double)(int)(((unsigned __int64)v37 >> 1) | v37 & 1) + (double)(int)(((unsigned __int64)v37 >> 1) | v37 & 1);
else
v38 = (double)(int)v37;
gl_lastavgres = v38 / v36;
printf("Sequential read of %dMB file = %f cycles\n", 128LL, v38 / v36);
free(name[v9]);
}

original_code:
void readContention(char **arg)
{
 char *filenametpl = "./tmpReadContentionBenchXXXXXX";
 char *filename[(1 << 5)];
 char buf[(128 * 1024)];
 int fd[(1 << 5)];
 int res;
 unsigned int i;
 unsigned int j;
 unsigned int size;
 memset(buf, 42, (128 * 1024));
 for (i = 0; i < (1 << 5); i++)
 {
  filename[i] = strdup(filenametpl);
  if ((fd[i] = mkstemp(filename[i])) == -1)
  {
   perror("File creation failed");
   exit(1);
  }
  for (size = 0; size < (1 << 27); size += res)
   if ((res = write(fd[i], buf, (128 * 1024))) == -1)
   {
    perror("Write error");
    exit(1);
   }
  printf("Temporary file %s created.\n", filename[i]);
 }
 for (i = 1; i <= (1 << 5); i = i << 1)
 {
  printf("Starting %d processes...\n", i);
  for (j = 0; j < i; j++)
  {
   if (!(res = fork()))
   {
    { unsigned long long b; unsigned long long c; unsigned int measureloopcnt; b = rdtsc(); for (measureloopcnt = 0; measureloopcnt < gl_loopcycle; ++measureloopcnt){ if (lseek(fd[j], 0, 0) == -1) { perror("Lseek error"); exit(1); } do { if ((res = read(fd[j], buf, (128 * 1024))) == -1) { perror("Read error"); exit(1); } } while (res); } c = rdtsc(); if (0) printf("Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n", c - b, (double)(c - b) / (double)gl_loopcycle, gl_loopcycle); gl_lastavgres = (double)(c - b) / (double)gl_loopcycle; }
    printf("Sequential read of %dMB file = %f cycles\n", (1 << 27) / (1024 * 1024),
     gl_lastavgres);
    free(filename[j]);
    return;
   }
   else if (res == -1)
    perror("fork");
  }
  for (j = 0; j < i; j++)
   waitid(P_ALL, 0, ((void *)0), 4);
 }
 for (i = 0; i < (1 << 5); i++)
 {
  close(fd[i]);
  if (unlink(filename[i]) == -1)
   perror("File remove failed");
  free(filename[j]);
 }
}

canonical_original_code:
void readContention(char **arg)
{
 char *filenametpl = "./tmpReadContentionBenchXXXXXX";
 char *filename[-1];
 char buf[-1];
 int fd[-1];
 int res;
 unsigned int i;
 unsigned int j;
 unsigned int size;
 memset(buf, 42, (128 * 1024));
 for (i = 0; i < (1 << 5); i++)
 {
  filename[i] = strdup(filenametpl);
  if ((fd[i] = mkstemp(filename[i])) == -1)
  {
   perror("File creation failed");
   exit(1);
  }
  for (size = 0; size < (1 << 27); size += res)
   if ((res = write(fd[i], buf, (128 * 1024))) == -1)
   {
    perror("Write error");
    exit(1);
   }
  printf("Temporary file %s created.\n", filename[i]);
 }
 for (i = 1; i <= (1 << 5); i = i << 1)
 {
  printf("Starting %d processes...\n", i);
  for (j = 0; j < i; j++)
  {
   if (!(res = fork()))
   {
    { unsigned long long b; unsigned long long c; unsigned int measureloopcnt; b = rdtsc(); for (measureloopcnt = 0; measureloopcnt < gl_loopcycle; ++measureloopcnt){ if (lseek(fd[j], 0, 0) == -1) { perror("Lseek error"); exit(1); } do { if ((res = read(fd[j], buf, (128 * 1024))) == -1) { perror("Read error"); exit(1); } } while (res); } c = rdtsc(); if (0) printf("Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n", c - b, (double)(c - b) / (double)gl_loopcycle, gl_loopcycle); gl_lastavgres = (double)(c - b) / (double)gl_loopcycle; }
    printf("Sequential read of %dMB file = %f cycles\n", (1 << 27) / (1024 * 1024),
     gl_lastavgres);
    free(filename[j]);
    return;
   }
   else if (res == -1)
    perror("fork");
  }
  for (j = 0; j < i; j++)
   waitid(P_ALL, 0, ((void *)0), 4);
 }
 for (i = 0; i < (1 << 5); i++)
 {
  close(fd[i]);
  if (unlink(filename[i]) == -1)
   perror("File remove failed");
  free(filename[j]);
 }
}

variable_types:
arg
char **

variable_types:
filenametpl
char *

variable_types:
filename
char *[-1]

variable_types:
fd
int [-1]

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
size
unsigned int


decompiled_code:
int print_help()
{
puts("Le programme \"tartiflette\" permet le stockage de different fichier ou dossier dans une seule et unique archive.");
puts(aUsageTartiflet);
putchar(10);
puts("Options possible:");
puts(aHAfficherLaPr);
puts(" -v Activer le mode verbose.");
puts(aCCr);
puts(" -t Lister le contenu d'une archive existante.");
puts(aRRajouterDesFi);
puts(aUAjouterLesFic);
puts(" -x Extraitre une archive existante.");
puts(aFSp);
puts(" -z Filtrer l'archive au travers de gzip.");
puts(" -d Supprimer une archive existante.");
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
puts("Le programme \"tartiflette\" permet le stockage de different fichier ou dossier dans une seule et unique archive.");
puts(aUsageTartiflet);
putchar(10);
puts("Options possible:");
puts(aHAfficherLaPr);
puts(" -v Activer le mode verbose.");
puts(aCCr);
puts(" -t Lister le contenu d'une archive existante.");
puts(aRRajouterDesFi);
puts(aUAjouterLesFic);
puts(" -x Extraitre une archive existante.");
puts(aFSp);
puts(" -z Filtrer l'archive au travers de gzip.");
puts(" -d Supprimer une archive existante.");
return putchar(10);
}

original_code:
void print_help(){
 printf("Le programme \"tartiflette\" permet le stockage de different fichier ou dossier dans une seule et unique archive.\n");
 printf("Usage : ./tartiflette [-options] [Nom du fichier à créé si option f] [nom des fichiers à inclure dans l'archive]\n");
 printf("\n");
 printf("Options possible:\n");
 printf(" -h Afficher la présente page d'aide.\n");
 printf(" -v Activer le mode verbose.\n");
 printf(" -c Créer une nouvelle archive\n");
 printf(" -t Lister le contenu d'une archive existante.\n");
 printf(" -r Rajouter des fichiers ou dossier à une archive existante.\n");
 printf(" -u Ajouter les fichiers plus récents que leurs copie déjà présente dans une archive existante.\n");
 printf(" -x Extraitre une archive existante.\n");
 printf(" -f Spécifier le nom de l'archive à utiliser, doit être la dernière option appelée.\n");
 printf(" -z Filtrer l'archive au travers de gzip.\n");
 printf(" -d Supprimer une archive existante.\n");
 printf("\n");
}

return_type: void


analyseOption

decompiled_code:
__int64 __fastcall analyseOption(int argc, char **argv)
{
char v2; // r15
char v3; // r14
char v4; // r13
char *v5; // r12
char **v7; // rsi
int v8; // eax
_QWORD *v10; // r8
unsigned __int64 v11; // rcx
int v12; // eax
__int64 v13; // rdx
char v14; // [rsp+Eh] [rbp-4Ah]
unsigned __int8 v15; // [rsp+Fh] [rbp-49h]
char v16; // [rsp+10h] [rbp-48h]
_QWORD *v17; // [rsp+10h] [rbp-48h]
_QWORD *v18; // [rsp+18h] [rbp-40h]
_QWORD *v19; // [rsp+18h] [rbp-40h]
_QWORD *v20; // [rsp+18h] [rbp-40h]

v2 = 0;
v3 = 0;
v4 = 0;
v5 = 0LL;
VERBOSE = 0;
v14 = 0;
v15 = 0;
v16 = 0;
while ( 2 )
{
v7 = argv;
v8 = getopt(argc, argv, "hvctruxf:zd");
if ( v8 == -1 )
{
v10 = malloc(8LL * (argc - optind));
v11 = 8LL * optind;
v12 = optind;
*v10 = argv[v11 / 8];
v13 = (unsigned int)(v12 + 1);
if ( argc > (int)v13 )
{
v7 = &argv[v11 / 8 + 1];
v18 = v10;
memcpy(v10 + 1, v7, 8LL * (unsigned int)(argc - v12 - 2) + 8);
v10 = v18;
}
if ( v2 )
{
v20 = v10;
extract(v5, v7, v13, v11);
v10 = v20;
}
if ( v3 )
{
v19 = v10;
list(v5, v7, v13, v11);
v10 = v19;
}
if ( v16 )
{
v17 = v10;
create(v5, v10, v13, v11);
v10 = v17;
}
if ( v4 )
add(v5, v10, v15, v11);
if ( v14 )
execlp("gzip", "gzip", v5, 0LL, v10);
}
else
{
switch ( v8 )
{
case 'c':
v16 = 1;
continue;
case 'f':
v5 = optarg;
continue;
case 'h':
print_help();
break;
case 'r':
v4 = 1;
continue;
case 't':
v3 = 1;
continue;
case 'u':
v15 = 1;
continue;
case 'v':
VERBOSE = 1;
continue;
case 'x':
v2 = 1;
continue;
case 'z':
v14 = 1;
continue;
default:
continue;
}
}
break;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int argc, char **argv)
{
char v2; // r15
char v3; // r14
char v4; // r13
char *v5; // r12
char **v7; // rsi
int v8; // eax
_QWORD *v10; // r8
unsigned __int64 v11; // rcx
int v12; // eax
__int64 v13; // rdx
char v14; // [rsp+Eh] [rbp-4Ah]
unsigned __int8 v15; // [rsp+Fh] [rbp-49h]
char v16; // [rsp+10h] [rbp-48h]
_QWORD *v17; // [rsp+10h] [rbp-48h]
_QWORD *v18; // [rsp+18h] [rbp-40h]
_QWORD *v19; // [rsp+18h] [rbp-40h]
_QWORD *v20; // [rsp+18h] [rbp-40h]

v2 = 0;
v3 = 0;
v4 = 0;
v5 = 0LL;
VERBOSE = 0;
v14 = 0;
v15 = 0;
v16 = 0;
while ( 2 )
{
v7 = argv;
v8 = getopt(argc, argv, "hvctruxf:zd");
if ( v8 == -1 )
{
v10 = malloc(8LL * (argc - optind));
v11 = 8LL * optind;
v12 = optind;
*v10 = argv[v11 / 8];
v13 = (unsigned int)(v12 + 1);
if ( argc > (int)v13 )
{
v7 = &argv[v11 / 8 + 1];
v18 = v10;
memcpy(v10 + 1, v7, 8LL * (unsigned int)(argc - v12 - 2) + 8);
v10 = v18;
}
if ( v2 )
{
v20 = v10;
extract(v5, v7, v13, v11);
v10 = v20;
}
if ( v3 )
{
v19 = v10;
list(v5, v7, v13, v11);
v10 = v19;
}
if ( v16 )
{
v17 = v10;
create(v5, v10, v13, v11);
v10 = v17;
}
if ( v4 )
add(v5, v10, v15, v11);
if ( v14 )
execlp("gzip", "gzip", v5, 0LL, v10);
}
else
{
switch ( v8 )
{
case 'c':
v16 = 1;
continue;
case 'f':
v5 = optarg;
continue;
case 'h':
func0();
break;
case 'r':
v4 = 1;
continue;
case 't':
v3 = 1;
continue;
case 'u':
v15 = 1;
continue;
case 'v':
VERBOSE = 1;
continue;
case 'x':
v2 = 1;
continue;
case 'z':
v14 = 1;
continue;
default:
continue;
}
}
break;
}
return 1LL;
}

original_code:
int analyseOption(int argc, char* argv[]){
 char * archive = ((void *)0);
 _Bool o_create = 0 , o_add = 0, o_maj = 0, o_extract = 0, o_list = 0, o_zip = 0;
 int compt;
 char** filename = ((void *)0);
 VERBOSE = 0;
 while(1){
  compt = getopt(argc, argv, "hvctruxf:zd");
  if (compt==-1){
   break;
  }
  switch(compt)
  {
  case 'h':
   print_help();
   return 1;
   break;
  case 'v':
   VERBOSE = 1;
   break;
  case 'c':
   o_create = 1;
   break;
  case 't':
   o_list = 1;
   break;
  case 'r':
   o_add = 1;
   break;
  case 'u':
   o_maj = 1;
   break;
  case 'x':
   o_extract = 1;
   break;
  case 'f':
   archive = optarg;
   break;
  case 'z':
   o_zip = 1;
   break;
  case 'd':
   break;
  }
 }
 filename = malloc(sizeof(char*)*(argc-optind));
 filename[0] = argv[optind];
 for(int i=optind+1; i<argc; i++)
  filename[i-optind]= argv[i];
 if(o_extract)
  extract(archive);
 if(o_list)
  list(archive);
 if(o_create)
  create(archive,filename);
 if(o_add)
  add(archive, filename, o_maj);
 if(o_zip == 1)
  execlp("gzip", "gzip", archive, ((void *)0));
 return 1;
}

canonical_original_code:
int analyseOption(int argc, char *argv[]){
 char *archive = ((void *)0);
 _Bool o_create = 0; _Bool o_add = 0; _Bool o_maj = 0; _Bool o_extract = 0; _Bool o_list = 0; _Bool o_zip = 0;
 int compt;
 char **filename = ((void *)0);
 VERBOSE = 0;
 while(1){
  compt = getopt(argc, argv, "hvctruxf:zd");
  if (compt==-1){
   break;
  }
  switch(compt)
  {
  case 'h':
   print_help();
   return 1;
   break;
  case 'v':
   VERBOSE = 1;
   break;
  case 'c':
   o_create = 1;
   break;
  case 't':
   o_list = 1;
   break;
  case 'r':
   o_add = 1;
   break;
  case 'u':
   o_maj = 1;
   break;
  case 'x':
   o_extract = 1;
   break;
  case 'f':
   archive = optarg;
   break;
  case 'z':
   o_zip = 1;
   break;
  case 'd':
   break;
  }
 }
 filename = malloc(sizeof(char *)*(argc-optind));
 filename[0] = argv[optind];
 for(int i = optind+1; i<argc; i++)
  filename[i-optind]= argv[i];
 if(o_extract)
  extract(archive);
 if(o_list)
  list(archive);
 if(o_create)
  create(archive,filename);
 if(o_add)
  add(archive, filename, o_maj);
 if(o_zip == 1)
  execlp("gzip", "gzip", archive, ((void *)0));
 return 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
archive
char *

variable_types: compt int

variable_types:
filename
char **

variable_types: i int

return_type: int


main

canonical_name: main

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

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

original_code:
int main(int argc, char* argv[]){
 analyseOption(argc, argv);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 analyseOption(argc, argv);
 return 0;
}


decompiled_code:
char *init_header()
{
char *result; // rax

result = (char *)malloc(0x101uLL);
if ( !result )
_assert_fail("header", "src/header.c", 0x28u, "init_header");
memset(result, 0, 0x60uLL);
*((_DWORD *)result + 24) = 0;
strcpy(result + 100, "000000000000000000000000000000000000000000000000");
result[156] = 0;
*(_QWORD *)(result + 157) = 0LL;
*(_QWORD *)(result + 249) = 0LL;
memset(
(void *)((unsigned __int64)(result + 165) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)result - (((_DWORD)result + 165) & 0xFFFFFFF8) + 257) >> 3));
return result;
}

canonical_decompiled_code:
char *func0()
{
char *result; // rax

result = (char *)malloc(0x101uLL);
if ( !result )
_assert_fail("header", "src/header.c", 0x28u, "init_header");
memset(result, 0, 0x60uLL);
*((_DWORD *)result + 24) = 0;
strcpy(result + 100, "000000000000000000000000000000000000000000000000");
result[156] = 0;
*(_QWORD *)(result + 157) = 0LL;
*(_QWORD *)(result + 249) = 0LL;
memset(
(void *)((unsigned __int64)(result + 165) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)result - (((_DWORD)result + 165) & 0xFFFFFFF8) + 257) >> 3));
return result;
}

original_code:
Header init_header(void) {
    Header header = (Header) malloc(sizeof(struct Header));
    ((header) ? (void) (0) : __assert_fail ("header", "src/header.c", 40, __extension__ __PRETTY_FUNCTION__));
    memset(header->file_name, '\0', 100);
    memset(header->file_mode, '0', 8);
    memset(header->owner_id, '0', 8);
    memset(header->owner_group_id, '0', 8);
    memset(header->file_size, '0', 12);
    memset(header->last_modification, '0', 12);
    memset(header->checksum, '\0', 8);
    memset(header->type_flag, '\0', 1);
    memset(header->linked_file_name, '\0', 100);
    return header;
}

canonical_original_code:
struct Header *init_header() {
    struct Header *header = (Header) malloc(sizeof(struct Header));
    ((header) ? (void) (0) : __assert_fail ("header", "src/header.c", 40, __extension__ __PRETTY_FUNCTION__));
    memset(header->file_name, '\0', 100);
    memset(header->file_mode, '0', 8);
    memset(header->owner_id, '0', 8);
    memset(header->owner_group_id, '0', 8);
    memset(header->file_size, '0', 12);
    memset(header->last_modification, '0', 12);
    memset(header->checksum, '\0', 8);
    memset(header->type_flag, '\0', 1);
    memset(header->linked_file_name, '\0', 100);
    return header;
}

variable_types: struct Header { char file_name[100]; char file_mode[8]; char owner_id[8]; char owner_group_id[8]; char file_size[12]; char last_modification[12]; char checksum[8]; char type_flag[1]; char linked_file_name[100]; } *


decompiled_code:
char *__fastcall create_header(const char *a1, unsigned int a2, __int64 a3, __int64 a4, char a5, const char *a6)
{
char *v10; // rax
char *v11; // r12

v10 = init_header();
v11 = v10;
if ( a1 )
strcpy(v10, a1);
if ( !a2 )
{
if ( !a3 )
goto LABEL_5;
LABEL_12:
sprintf(v11 + 124, "%lo", a3);
if ( !a4 )
goto LABEL_6;
goto LABEL_13;
}
sprintf(v11 + 100, "%o", a2);
if ( a3 )
goto LABEL_12;
LABEL_5:
if ( !a4 )
goto LABEL_6;
LABEL_13:
sprintf(v11 + 136, "%lo", a4);
LABEL_6:
if ( a5 )
v11[156] = a5;
if ( a6 )
strcpy(v11 + 157, a6);
return v11;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1, unsigned int a2, __int64 a3, __int64 a4, char a5, const char *a6)
{
char *v10; // rax
char *v11; // r12

v10 = func0();
v11 = v10;
if ( a1 )
strcpy(v10, a1);
if ( !a2 )
{
if ( !a3 )
goto LABEL_5;
LABEL_12:
sprintf(v11 + 124, "%lo", a3);
if ( !a4 )
goto LABEL_6;
goto LABEL_13;
}
sprintf(v11 + 100, "%o", a2);
if ( a3 )
goto LABEL_12;
LABEL_5:
if ( !a4 )
goto LABEL_6;
LABEL_13:
sprintf(v11 + 136, "%lo", a4);
LABEL_6:
if ( a5 )
v11[156] = a5;
if ( a6 )
strcpy(v11 + 157, a6);
return v11;
}

original_code:
Header create_header(char * file_name,
                     mode_t file_mode,
                     off_t file_size,
                     time_t last_modification,
                     char type_flag,
                     char * linked_file_name) {
    Header header = init_header();
    if (file_name) strcpy(header->file_name, file_name);
    if (file_mode) sprintf(header->file_mode, "%o", file_mode);
    if (file_size) sprintf(header->file_size, "%lo", file_size);
    if (last_modification) sprintf(header->last_modification, "%lo", last_modification);
    if (type_flag) *header->type_flag = type_flag;
    if (linked_file_name) strcpy(header->linked_file_name, linked_file_name);
    return header;
}

canonical_original_code:
struct Header *create_header(char *file_name, unsigned int file_mode, long file_size, long last_modification, char type_flag, char *linked_file_name) {
    struct Header *header = init_header();
    if (file_name) strcpy(header->file_name, file_name);
    if (file_mode) sprintf(header->file_mode, "%o", file_mode);
    if (file_size) sprintf(header->file_size, "%lo", file_size);
    if (last_modification) sprintf(header->last_modification, "%lo", last_modification);
    if (type_flag) *header->type_flag = type_flag;
    if (linked_file_name) strcpy(header->linked_file_name, linked_file_name);
    return header;
}

return_type: struct Header { char file_name[100]; char file_mode[8]; char owner_id[8]; char owner_group_id[8]; char file_size[12]; char last_modification[12]; char checksum[8]; char type_flag[1]; char linked_file_name[100]; } *


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

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

original_code:
void destruct_header(Header header) {
    free(header);
}

canonical_original_code:
void destruct_header(struct Header *header) {
    free(header);
}

user_defined_types: struct Header { char file_name[100]; char file_mode[8]; char owner_id[8]; char owner_group_id[8]; char file_size[12]; char last_modification[12]; char checksum[8]; char type_flag[1]; char linked_file_name[100]; }


decompiled_code:
__int64 __fastcall header_file_name(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return a1;
}

original_code:
char * header_file_name(Header header) {
    return header->file_name;
}

canonical_original_code:
char *header_file_name(struct Header *header) {
    return header->file_name;
}

return_type: char *


decompiled_code:
__int64 __fastcall header_file_mode(__int64 a1)
{
unsigned int v2; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1 + 100, "%o", &v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v2; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1 + 100, "%o", &v2);
return v2;
}

original_code:
mode_t header_file_mode(Header header) {
    mode_t file_mode;
    sscanf(header->file_mode, "%o", &file_mode);
    return file_mode;
}

canonical_original_code:
unsigned int header_file_mode(struct Header *header) {
    unsigned int file_mode;
    sscanf(header->file_mode, "%o", &file_mode);
    return file_mode;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall header_file_size(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

_isoc99_sscanf(a1 + 124, "%lo", &v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

_isoc99_sscanf(a1 + 124, "%lo", &v2);
return v2;
}

original_code:
off_t header_file_size(Header header) {
    off_t file_size;
    sscanf(header->file_size, "%lo", &file_size);
    return file_size;
}

canonical_original_code:
long header_file_size(struct Header *header) {
    long file_size;
    sscanf(header->file_size, "%lo", &file_size);
    return file_size;
}

return_type: long


decompiled_code:
__int64 __fastcall header_last_modification(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

_isoc99_sscanf(a1 + 136, "%lo", &v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

_isoc99_sscanf(a1 + 136, "%lo", &v2);
return v2;
}

original_code:
time_t header_last_modification(Header header) {
    time_t last_modification;
    sscanf(header->last_modification, "%lo", &last_modification);
    return last_modification;
}

canonical_original_code:
long header_last_modification(struct Header *header) {
    long last_modification;
    sscanf(header->last_modification, "%lo", &last_modification);
    return last_modification;
}


decompiled_code:
__int64 __fastcall header_type_flag(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 156);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 156);
}

original_code:
char header_type_flag(Header header) {
    return *header->type_flag;
}

canonical_original_code:
char header_type_flag(struct Header *header) {
    return *header->type_flag;
}

return_type: char


decompiled_code:
__int64 __fastcall header_linked_file_name(__int64 a1)
{
return a1 + 157;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return a1 + 157;
}

original_code:
char * header_linked_file_name(Header header) {
    return header->linked_file_name;
}

canonical_original_code:
char *header_linked_file_name(struct Header *header) {
    return header->linked_file_name;
}


repo: NosicLin/Codger

decompiled_code:
__int64 __fastcall is_in_str(char a1, char *a2)
{
char v2; // al

do
{
v2 = *a2;
if ( !*a2 )
return 0LL;
++a2;
}
while ( v2 != a1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1, char *a2)
{
char v2; // al

do
{
v2 = *a2;
if ( !*a2 )
return 0LL;
++a2;
}
while ( v2 != a1 );
return 1LL;
}

original_code:
static inline int is_in_str(char c,const char* str)
{
 while(*str)
  if(c==*(str++)) return 1 ;
 return 0;
}

canonical_original_code:
static inline int is_in_str(char c, char *str)
{
 while(*str)
  if(c==*(str++)) return 1 ;
 return 0;
}

variable_types: c char

variable_types:
str
char *


decompiled_code:
__int64 __fastcall cal_args_num(char *a1, char *a2)
{
char v2; // di
unsigned int v4; // er8
int v5; // eax
char *v6; // rdx
int v7; // eax
char *v8; // rdx

v2 = *a1;
v4 = 0;
if ( !v2 )
return v4;
do
{
v5 = is_in_str(v2, a2);
v2 = *v6;
if ( !v5 )
{
++v4;
if ( !v2 )
return v4;
while ( 1 )
{
v7 = is_in_str(v2, a2);
v2 = *v8;
if ( v7 )
break;
if ( !v2 )
return v4;
}
}
}
while ( v2 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, char *a2)
{
char v2; // di
unsigned int v4; // er8
int v5; // eax
char *v6; // rdx
int v7; // eax
char *v8; // rdx

v2 = *a1;
v4 = 0;
if ( !v2 )
return v4;
do
{
v5 = func7(v2, a2);
v2 = *v6;
if ( !v5 )
{
++v4;
if ( !v2 )
return v4;
while ( 1 )
{
v7 = func7(v2, a2);
v2 = *v8;
if ( v7 )
break;
if ( !v2 )
return v4;
}
}
}
while ( v2 );
return v4;
}

original_code:
int cal_args_num(const char* buffer,const char* divide)
{
 int args_num=0;
 int now_word=0;
 while(*buffer)
 {
  if(now_word)
  {
   if(is_in_str(*buffer,divide))
   {
    now_word=0;
   }
  }
  else
  {
   if(!is_in_str(*buffer,divide))
   {
    now_word=1;
    args_num++;
   }
  }
  buffer++;
 }
 return args_num;
}

canonical_original_code:
int cal_args_num(char *buffer, char *divide)
{
 int args_num = 0;
 int now_word = 0;
 while(*buffer)
 {
  if(now_word)
  {
   if(is_in_str(*buffer,divide))
   {
    now_word=0;
   }
  }
  else
  {
   if(!is_in_str(*buffer,divide))
   {
    now_word=1;
    args_num++;
   }
  }
  buffer++;
 }
 return args_num;
}

variable_types:
buffer
char *

variable_types:
divide
char *


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

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

original_code:
void free_args(struct args* arg)
{
 free(arg);
}

canonical_original_code:
void free_args(struct args *arg)
{
 free(arg);
}

variable_types:
arg
struct args { int num; char **parg; } *


decompiled_code:
__int64 EgBuildin_GcUpdate()
{
s_buildin = GrGc_Update(s_buildin);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
s_buildin = GrGc_Update(s_buildin);
return 0LL;
}

original_code:
int EgBuildin_GcUpdate()
{
 s_buildin=GrGc_Update(s_buildin);
 return 0;
}


decompiled_code:
__int64 GrModule_BuildinInit()
{
__int64 v0; // rax
__int64 result; // rax

v0 = GrHash_GcNewFlag(4LL);
s_buildin = v0;
if ( v0 )
result = GrUtil_FillWithGrString(v0, &s_buildin_func, 4LL);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rax
__int64 result; // rax

v0 = GrHash_GcNewFlag(4LL);
s_buildin = v0;
if ( v0 )
result = GrUtil_FillWithGrString(v0, &s_buildin_func, 4LL);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int GrModule_BuildinInit()
{
 s_buildin=GrHash_GcNewFlag((1ul<<2));
 if(s_buildin==((void *)0))
 {
  return -1;
 }
 return GrUtil_FillWithGrString(s_buildin,s_buildin_func,
   (1ul<<2));
}


decompiled_code:
__int64 GrModule_BuildinExit()
{
s_buildin = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
s_buildin = 0LL;
return 0LL;
}

original_code:
int GrModule_BuildinExit()
{
 s_buildin=0;
 return 0;
}


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

result = 32LL;
if ( a1 > 0x20 )
{
do
result = (unsigned int)(2 * result);
while ( a1 > (unsigned int)result );
}
return result;
}

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

result = 32LL;
if ( a1 > 0x20 )
{
do
result = (unsigned int)(2 * result);
while ( a1 > (unsigned int)result );
}
return result;
}

original_code:
unsigned int round_log(unsigned size)
{
 unsigned int i=32;
 while(i<size)
 {
  i<<=1;
 }
 return i;
}

canonical_original_code:
unsigned int round_log(unsigned int size)
{
 unsigned int i = 32;
 while(i<size)
 {
  i<<=1;
 }
 return i;
}


decompiled_code:
void __fastcall splstr_realloc(__int64 a1, unsigned int a2)
{
unsigned int v2; // er13
unsigned int v3; // eax
void *v4; // r14
unsigned int v5; // ebp
void *v6; // r12

v2 = *(_DWORD *)(a1 + 8);
v3 = round_log(a2);
if ( v2 > v3 )
{
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_realloc", 35LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Realloc Lose Data,Refuse", 1uLL, 0x18uLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
}
else
{
v4 = *(void **)a1;
v5 = v3;
v6 = malloc(v3);
memcpy(v6, v4, v2 + 1);
free(v4);
*(_DWORD *)(a1 + 12) = v5;
*(_QWORD *)a1 = v6;
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned int a2)
{
unsigned int v2; // er13
unsigned int v3; // eax
void *v4; // r14
unsigned int v5; // ebp
void *v6; // r12

v2 = *(_DWORD *)(a1 + 8);
v3 = func0(a2);
if ( v2 > v3 )
{
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_realloc", 35LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Realloc Lose Data,Refuse", 1uLL, 0x18uLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
}
else
{
v4 = *(void **)a1;
v5 = v3;
v6 = malloc(v3);
memcpy(v6, v4, v2 + 1);
free(v4);
*(_DWORD *)(a1 + 12) = v5;
*(_QWORD *)a1 = v6;
}
}

original_code:
void splstr_realloc(splstr* s_str,unsigned int size)
{
 char* new_str;
 char* old_str=s_str->str;
 unsigned int length=s_str->length;
 size=round_log(size);
 if(size<s_str->length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,35); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Realloc Lose Data,Refuse"); fprintf(stderr,")\n"); }while(0);
  return;
 }
 new_str=(char*)malloc(size);
 memcpy(new_str,old_str,length+1);
 free(old_str);
 s_str->max_cap=size;
 s_str->str=new_str;
}

canonical_original_code:
void splstr_realloc(struct tag_splstr *s_str, unsigned int size)
{
 char *new_str;
 char *old_str = s_str->str;
 unsigned int length = s_str->length;
 size=round_log(size);
 if(size<s_str->length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,35); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Realloc Lose Data,Refuse"); fprintf(stderr,")\n"); }while(0);
  return;
 }
 new_str=(char *)malloc(size);
 memcpy(new_str,old_str,length+1);
 free(old_str);
 s_str->max_cap=size;
 s_str->str=new_str;
}

variable_types: struct tag_splstr { char *str; unsigned int length; unsigned int max_cap; } *

variable_types:
length
unsigned int


decompiled_code:
__int64 __fastcall splstr_insert_char(__int64 a1, unsigned int a2, char a3)
{
unsigned int v4; // ebx
unsigned int v5; // er15
unsigned int v6; // ebp
unsigned int v7; // er14
__int64 v8; // rdx
__int64 result; // rax
char v10; // si
__int64 v11; // rcx

v4 = *(_DWORD *)(a1 + 8);
if ( v4 < a2 )
{
v5 = *(_DWORD *)(a1 + 8);
v6 = v4 + 1;
v7 = 0;
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_insert_char", 65LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Pos Out Of Range", 1uLL, 0x10uLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
if ( v4 + 1 != *(_DWORD *)(a1 + 12) )
goto LABEL_3;
LABEL_7:
splstr_realloc(a1, v4 + 2);
goto LABEL_3;
}
v5 = a2;
v6 = v4 + 1;
v7 = v4 - a2;
if ( v4 + 1 == *(_DWORD *)(a1 + 12) )
goto LABEL_7;
LABEL_3:
v8 = *(_QWORD *)a1;
LODWORD(result) = 0;
do
{
v10 = *(_BYTE *)(v8 + v4 - (unsigned int)result);
v11 = v6 - (unsigned int)result;
result = (unsigned int)(result + 1);
*(_BYTE *)(v8 + v11) = v10;
}
while ( (unsigned int)result <= v7 );
*(_BYTE *)(v8 + v5) = a3;
++*(_DWORD *)(a1 + 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, char a3)
{
unsigned int v4; // ebx
unsigned int v5; // er15
unsigned int v6; // ebp
unsigned int v7; // er14
__int64 v8; // rdx
__int64 result; // rax
char v10; // si
__int64 v11; // rcx

v4 = *(_DWORD *)(a1 + 8);
if ( v4 < a2 )
{
v5 = *(_DWORD *)(a1 + 8);
v6 = v4 + 1;
v7 = 0;
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_insert_char", 65LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Pos Out Of Range", 1uLL, 0x10uLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
if ( v4 + 1 != *(_DWORD *)(a1 + 12) )
goto LABEL_3;
LABEL_7:
func1(a1, v4 + 2);
goto LABEL_3;
}
v5 = a2;
v6 = v4 + 1;
v7 = v4 - a2;
if ( v4 + 1 == *(_DWORD *)(a1 + 12) )
goto LABEL_7;
LABEL_3:
v8 = *(_QWORD *)a1;
LODWORD(result) = 0;
do
{
v10 = *(_BYTE *)(v8 + v4 - (unsigned int)result);
v11 = v6 - (unsigned int)result;
result = (unsigned int)(result + 1);
*(_BYTE *)(v8 + v11) = v10;
}
while ( (unsigned int)result <= v7 );
*(_BYTE *)(v8 + v5) = a3;
++*(_DWORD *)(a1 + 8);
return result;
}

original_code:
void splstr_insert_char(splstr* s_str,unsigned int pos,char c)
{
 char* str;
 unsigned int i;
 unsigned int length=s_str->length;
 int size;
 if(pos>length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,65); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Pos Out Of Range"); fprintf(stderr,")\n"); }while(0);
  pos=length;
 }
 if(length+1==s_str->max_cap)
 {
  splstr_realloc(s_str,s_str->max_cap+1);
 }
 str=s_str->str;
 size=length-pos;
 for(i=0;i<=size;i++)
 {
  str[pos+size-i+1]=str[pos+size-i];
 }
 str[pos]=c;
 s_str->length++;
}

canonical_original_code:
void splstr_insert_char(struct tag_splstr *s_str, unsigned int pos, char c)
{
 char *str;
 unsigned int i;
 unsigned int length = s_str->length;
 int size;
 if(pos>length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,65); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Pos Out Of Range"); fprintf(stderr,")\n"); }while(0);
  pos=length;
 }
 if(length+1==s_str->max_cap)
 {
  splstr_realloc(s_str,s_str->max_cap+1);
 }
 str=s_str->str;
 size=length-pos;
 for(i=0;i<=size;i++)
 {
  str[pos+size-i+1]=str[pos+size-i];
 }
 str[pos]=c;
 s_str->length++;
}

variable_types:
pos
unsigned int

variable_types:
i
unsigned int

variable_types: size int

user_defined_types: struct tag_splstr { char *str; unsigned int length; unsigned int max_cap; }


decompiled_code:
__int64 __fastcall splstr_push_front(__int64 a1, char a2)
{
return splstr_insert_char(a1, 0, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2)
{
return func2(a1, 0, a2);
}

original_code:
void splstr_push_front(splstr* s_str,char c)
{
 splstr_insert_char(s_str,0,c);
}

canonical_original_code:
void splstr_push_front(struct tag_splstr *s_str, char c)
{
 splstr_insert_char(s_str,0,c);
}


decompiled_code:
__int64 __fastcall splstr_push_back(__int64 a1, char a2)
{
return splstr_insert_char(a1, *(_DWORD *)(a1 + 8), a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char a2)
{
return func2(a1, *(_DWORD *)(a1 + 8), a2);
}

original_code:
void splstr_push_back(splstr* s_str,char c)
{
 splstr_insert_char(s_str,s_str->length,c);
}

canonical_original_code:
void splstr_push_back(struct tag_splstr *s_str, char c)
{
 splstr_insert_char(s_str,s_str->length,c);
}


decompiled_code:
void *__fastcall splstr_insert_str(__int64 a1, unsigned int a2, const char *a3)
{
unsigned int v3; // er14
unsigned int v6; // eax
unsigned int v7; // er13
unsigned int v8; // ebp
unsigned int v9; // er9
unsigned int v10; // esi
unsigned int v11; // er15
__int64 v12; // rdi
unsigned int v13; // eax
char v14; // cl
__int64 v15; // rdx
void *result; // rax
unsigned int v17; // [rsp+Ch] [rbp-3Ch]
unsigned int v18; // [rsp+Ch] [rbp-3Ch]

v3 = a2;
v6 = strlen(a3);
v7 = *(_DWORD *)(a1 + 8);
v8 = v6;
v9 = v6;
if ( v7 < a2 )
{
v17 = v6;
v3 = *(_DWORD *)(a1 + 8);
v11 = 0;
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_insert_str", 92LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Pos Out Of Range", 1uLL, 0x10uLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
v9 = v17;
v10 = v7 + v8 + 1;
if ( v10 <= *(_DWORD *)(a1 + 12) )
goto LABEL_3;
LABEL_7:
v18 = v9;
splstr_realloc(a1, v10);
v9 = v18;
goto LABEL_3;
}
v10 = v7 + v6 + 1;
v11 = v7 - v3;
if ( v10 > *(_DWORD *)(a1 + 12) )
goto LABEL_7;
LABEL_3:
v12 = *(_QWORD *)a1;
v13 = 0;
do
{
v14 = *(_BYTE *)(v12 + v7 - v13);
v15 = v9 + v7 - v13++;
*(_BYTE *)(v12 + v15) = v14;
}
while ( v13 <= v11 );
result = memcpy((void *)(v3 + v12), a3, v8);
*(_DWORD *)(a1 + 8) += v8;
return result;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, unsigned int a2, const char *a3)
{
unsigned int v3; // er14
unsigned int v6; // eax
unsigned int v7; // er13
unsigned int v8; // ebp
unsigned int v9; // er9
unsigned int v10; // esi
unsigned int v11; // er15
__int64 v12; // rdi
unsigned int v13; // eax
char v14; // cl
__int64 v15; // rdx
void *result; // rax
unsigned int v17; // [rsp+Ch] [rbp-3Ch]
unsigned int v18; // [rsp+Ch] [rbp-3Ch]

v3 = a2;
v6 = strlen(a3);
v7 = *(_DWORD *)(a1 + 8);
v8 = v6;
v9 = v6;
if ( v7 < a2 )
{
v17 = v6;
v3 = *(_DWORD *)(a1 + 8);
v11 = 0;
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_insert_str", 92LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Pos Out Of Range", 1uLL, 0x10uLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
v9 = v17;
v10 = v7 + v8 + 1;
if ( v10 <= *(_DWORD *)(a1 + 12) )
goto LABEL_3;
LABEL_7:
v18 = v9;
func1(a1, v10);
v9 = v18;
goto LABEL_3;
}
v10 = v7 + v6 + 1;
v11 = v7 - v3;
if ( v10 > *(_DWORD *)(a1 + 12) )
goto LABEL_7;
LABEL_3:
v12 = *(_QWORD *)a1;
v13 = 0;
do
{
v14 = *(_BYTE *)(v12 + v7 - v13);
v15 = v9 + v7 - v13++;
*(_BYTE *)(v12 + v15) = v14;
}
while ( v13 <= v11 );
result = memcpy((void *)(v3 + v12), a3, v8);
*(_DWORD *)(a1 + 8) += v8;
return result;
}

original_code:
void splstr_insert_str(splstr* d_str,unsigned int pos,const char* s_str)
{
 unsigned int s_length=strlen(s_str);
 char* str;
 unsigned int i;
 unsigned int d_length=d_str->length;
 unsigned size;
 if(pos>d_length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,92); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Pos Out Of Range"); fprintf(stderr,")\n"); }while(0);
  pos=d_length;
 }
 if(d_length+s_length+1>d_str->max_cap)
 {
  splstr_realloc(d_str,d_length+s_length+1);
 }
 str=d_str->str;
 size=d_length-pos;
 for(i=0;i<=size;i++)
 {
  str[pos+size-i+s_length]=str[pos+size-i];
 }
 memcpy(str+pos,s_str,s_length);
 d_str->length+=s_length;
}

canonical_original_code:
void splstr_insert_str(struct tag_splstr *d_str, unsigned int pos, char *s_str)
{
 unsigned int s_length = strlen(s_str);
 char *str;
 unsigned int i;
 unsigned int d_length = d_str->length;
 unsigned int size;
 if(pos>d_length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,92); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Pos Out Of Range"); fprintf(stderr,")\n"); }while(0);
  pos=d_length;
 }
 if(d_length+s_length+1>d_str->max_cap)
 {
  splstr_realloc(d_str,d_length+s_length+1);
 }
 str=d_str->str;
 size=d_length-pos;
 for(i=0;i<=size;i++)
 {
  str[pos+size-i+s_length]=str[pos+size-i];
 }
 memcpy(str+pos,s_str,s_length);
 d_str->length+=s_length;
}

variable_types:
size
unsigned int


decompiled_code:
void *__fastcall splstr_insert_splstr(__int64 a1, unsigned int a2, const char **a3)
{
return splstr_insert_str(a1, a2, *a3);
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, unsigned int a2, const char **a3)
{
return func5(a1, a2, *a3);
}

original_code:
void splstr_insert_splstr(splstr* d_str,unsigned pos,splstr* s_str)
{
 splstr_insert_str(d_str,pos,s_str->str);
}

canonical_original_code:
void splstr_insert_splstr(struct tag_splstr *d_str, unsigned int pos, struct tag_splstr *s_str)
{
 splstr_insert_str(d_str,pos,s_str->str);
}


decompiled_code:
size_t __fastcall splstr_remove(__int64 *a1, unsigned int a2, int a3)
{
unsigned int v3; // er8
size_t result; // rax
int v6; // er10
__int64 v7; // rcx
unsigned int v8; // edx
__int64 v9; // rsi
char v10; // di
__int64 v11; // rsi

v3 = *((_DWORD *)a1 + 2);
if ( v3 <= a2 )
{
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_remove", 135LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Pos Out Of Range", 1uLL, 0x10uLL, stderr);
result = fwrite(")\n", 1uLL, 2uLL, stderr);
}
else
{
LODWORD(result) = a2 + a3;
v6 = a3;
if ( a2 + a3 > v3 )
{
LODWORD(result) = *((_DWORD *)a1 + 2);
v6 = v3 - a2;
}
v7 = *a1;
v8 = result - v6;
do
{
v9 = (unsigned int)result;
result = (unsigned int)(result + 1);
v10 = *(_BYTE *)(v7 + v9);
v11 = v8++;
*(_BYTE *)(v7 + v11) = v10;
}
while ( v3 >= (unsigned int)result );
*((_DWORD *)a1 + 2) -= v6;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(__int64 *a1, unsigned int a2, int a3)
{
unsigned int v3; // er8
size_t result; // rax
int v6; // er10
__int64 v7; // rcx
unsigned int v8; // edx
__int64 v9; // rsi
char v10; // di
__int64 v11; // rsi

v3 = *((_DWORD *)a1 + 2);
if ( v3 <= a2 )
{
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_remove", 135LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Pos Out Of Range", 1uLL, 0x10uLL, stderr);
result = fwrite(")\n", 1uLL, 2uLL, stderr);
}
else
{
LODWORD(result) = a2 + a3;
v6 = a3;
if ( a2 + a3 > v3 )
{
LODWORD(result) = *((_DWORD *)a1 + 2);
v6 = v3 - a2;
}
v7 = *a1;
v8 = result - v6;
do
{
v9 = (unsigned int)result;
result = (unsigned int)(result + 1);
v10 = *(_BYTE *)(v7 + v9);
v11 = v8++;
*(_BYTE *)(v7 + v11) = v10;
}
while ( v3 >= (unsigned int)result );
*((_DWORD *)a1 + 2) -= v6;
}
return result;
}

original_code:
void splstr_remove(splstr* s_str,unsigned int pos,unsigned int size)
{
 unsigned int s_length=s_str->length;
 char* str=s_str->str;
 unsigned int i;
 if(pos>=s_length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,135); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Pos Out Of Range"); fprintf(stderr,")\n"); }while(0);
  return ;
 }
 if(pos+size>s_length)
 {
  size=s_length-pos;
 }
 for(i=pos+size;i<=s_length;i++)
 {
  str[i-size]=str[i];
 }
 s_str->length-=size;
}

canonical_original_code:
void splstr_remove(struct tag_splstr *s_str, unsigned int pos, unsigned int size)
{
 unsigned int s_length = s_str->length;
 char *str = s_str->str;
 unsigned int i;
 if(pos>=s_length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,135); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Pos Out Of Range"); fprintf(stderr,")\n"); }while(0);
  return ;
 }
 if(pos+size>s_length)
 {
  size=s_length-pos;
 }
 for(i=pos+size;i<=s_length;i++)
 {
  str[i-size]=str[i];
 }
 s_str->length-=size;
}


decompiled_code:
size_t __fastcall splstr_remove_range(__int64 *a1, unsigned int a2, unsigned int a3)
{
if ( a3 >= a2 )
return splstr_remove(a1, a2, a3 - a2 + 1);
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_remove_range", 123LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Error Range", 1uLL, 0xBuLL, stderr);
return fwrite(")\n", 1uLL, 2uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func8(__int64 *a1, unsigned int a2, unsigned int a3)
{
if ( a3 >= a2 )
return func7(a1, a2, a3 - a2 + 1);
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_remove_range", 123LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Error Range", 1uLL, 0xBuLL, stderr);
return fwrite(")\n", 1uLL, 2uLL, stderr);
}

original_code:
void splstr_remove_range(splstr* s_str,unsigned int begin,unsigned int end)
{
 if(end<begin)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,123); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Error Range"); fprintf(stderr,")\n"); }while(0);
  return ;
 }
 return splstr_remove(s_str,begin,end-begin+1);
}

canonical_original_code:
void splstr_remove_range(struct tag_splstr *s_str, unsigned int begin, unsigned int end)
{
 if(end<begin)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,123); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Error Range"); fprintf(stderr,")\n"); }while(0);
  return ;
 }
 return splstr_remove(s_str,begin,end-begin+1);
}

variable_types:
begin
unsigned int

variable_types:
end
unsigned int


decompiled_code:
void *__fastcall splstr_assign(__int64 a1, const char *a2)
{
int v2; // er12
unsigned int v3; // ebp
void *result; // rax

v2 = strlen(a2);
v3 = v2 + 1;
if ( (unsigned int)(v2 + 1) > *(_DWORD *)(a1 + 12) )
splstr_realloc(a1, v3);
result = memcpy(*(void **)a1, a2, v3);
*(_DWORD *)(a1 + 8) = v2;
return result;
}

canonical_decompiled_code:
void *__fastcall func11(__int64 a1, const char *a2)
{
int v2; // er12
unsigned int v3; // ebp
void *result; // rax

v2 = strlen(a2);
v3 = v2 + 1;
if ( (unsigned int)(v2 + 1) > *(_DWORD *)(a1 + 12) )
func1(a1, v3);
result = memcpy(*(void **)a1, a2, v3);
*(_DWORD *)(a1 + 8) = v2;
return result;
}

original_code:
void splstr_assign(splstr* d_str,const char* s_str)
{
 unsigned int s_length=strlen(s_str);
 char* str;
 if(s_length+1>d_str->max_cap)
 {
  splstr_realloc(d_str,s_length+1);
 }
 str=d_str->str;
 memcpy(str,s_str,s_length+1);
 d_str->length=s_length;
}

canonical_original_code:
void splstr_assign(struct tag_splstr *d_str, char *s_str)
{
 unsigned int s_length = strlen(s_str);
 char *str;
 if(s_length+1>d_str->max_cap)
 {
  splstr_realloc(d_str,s_length+1);
 }
 str=d_str->str;
 memcpy(str,s_str,s_length+1);
 d_str->length=s_length;
}


decompiled_code:
void *__fastcall splstr_copy(__int64 a1, const char **a2)
{
return splstr_assign(a1, *a2);
}

canonical_decompiled_code:
void *__fastcall func12(__int64 a1, const char **a2)
{
return func11(a1, *a2);
}

original_code:
void splstr_copy(splstr* d_str,splstr* s_str)
{
 splstr_assign(d_str,s_str->str);
}

canonical_original_code:
void splstr_copy(struct tag_splstr *d_str, struct tag_splstr *s_str)
{
 splstr_assign(d_str,s_str->str);
}


decompiled_code:
__int64 __fastcall splstr_length(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

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

original_code:
int splstr_length(splstr* s_str)
{
 return s_str->length;
}

canonical_original_code:
int splstr_length(struct tag_splstr *s_str)
{
 return s_str->length;
}


decompiled_code:
void *splstr_alloc()
{
return malloc(0x10uLL);
}

canonical_decompiled_code:
void *func14()
{
return malloc(0x10uLL);
}

original_code:
splstr* splstr_alloc()
{
 return (splstr*) malloc(sizeof(splstr));
}

canonical_original_code:
struct tag_splstr *splstr_alloc()
{
 return (struct tag_splstr *) malloc(sizeof(splstr));
}

return_type: struct tag_splstr { char *str; unsigned int length; unsigned int max_cap; } *


decompiled_code:
void *__fastcall splstr_init_str(__int64 a1, const char *a2)
{
unsigned int v2; // ebx
unsigned int v3; // eax
void *v4; // rax

v2 = strlen(a2);
v3 = round_log(v2);
*(_DWORD *)(a1 + 8) = v2;
*(_DWORD *)(a1 + 12) = v3;
v4 = malloc(v3);
*(_QWORD *)a1 = v4;
return memcpy(v4, a2, v2 + 1);
}

canonical_decompiled_code:
void *__fastcall func15(__int64 a1, const char *a2)
{
unsigned int v2; // ebx
unsigned int v3; // eax
void *v4; // rax

v2 = strlen(a2);
v3 = func0(v2);
*(_DWORD *)(a1 + 8) = v2;
*(_DWORD *)(a1 + 12) = v3;
v4 = malloc(v3);
*(_QWORD *)a1 = v4;
return memcpy(v4, a2, v2 + 1);
}

original_code:
void splstr_init_str(splstr* s_str,const char* str)
{
 unsigned length=strlen(str);
 unsigned max_cap=round_log(length);
 s_str->max_cap=max_cap;
 s_str->length=length;
 s_str->str=(char*)malloc(max_cap);
 memcpy(s_str->str,str,length+1);
}

canonical_original_code:
void splstr_init_str(struct tag_splstr *s_str, char *str)
{
 unsigned int length = strlen(str);
 unsigned int max_cap = round_log(length);
 s_str->max_cap=max_cap;
 s_str->length=length;
 s_str->str=(char *)malloc(max_cap);
 memcpy(s_str->str,str,length+1);
}


decompiled_code:
void __fastcall splstr_destory(__int64 a1)
{
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1)
{
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void splstr_destory(splstr* s_str)
{
 free(s_str->str);
 s_str->length=0;
 s_str->max_cap=0;
 s_str->str=((void *)0);
}

canonical_original_code:
void splstr_destory(struct tag_splstr *s_str)
{
 free(s_str->str);
 s_str->length=0;
 s_str->max_cap=0;
 s_str->str=((void *)0);
}


decompiled_code:
void __fastcall splstr_free(void *ptr)
{
splstr_destory((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func17(void *ptr)
{
func16((__int64)ptr);
free(ptr);
}

original_code:
void splstr_free(splstr* s_str)
{
 splstr_destory(s_str);
 free(s_str);
}

canonical_original_code:
void splstr_free(struct tag_splstr *s_str)
{
 splstr_destory(s_str);
 free(s_str);
}


decompiled_code:
void __fastcall list_add(_QWORD *a1, __int64 a2)
{
_list_add(a1, a2, *(_QWORD **)(a2 + 8));
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1, __int64 a2)
{
func1(a1, a2, *(_QWORD **)(a2 + 8));
}

original_code:
static inline void list_add(struct list_head *new_list, struct list_head *head)
{
 __list_add(new_list, head, head->next);
}

variable_types: struct list_head { struct list_head *prev; struct list_head *next; } *

variable_types:
head
struct list_head *


decompiled_code:
void __fastcall list_add_tail(_QWORD *a1, __int64 *a2)
{
_list_add(a1, *a2, a2);
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1, __int64 *a2)
{
func1(a1, *a2, a2);
}

original_code:
static inline void list_add_tail(struct list_head *new_list, struct list_head *head)
{
 __list_add(new_list, head->prev, head);
}

user_defined_types: struct list_head { struct list_head *prev; struct list_head *next; }


decompiled_code:
_BOOL8 __fastcall list_empty(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == a1;
}

original_code:
static inline int list_empty(const struct list_head *head)
{
 return head->next == head;
}

canonical_original_code:
static inline int list_empty(struct list_head *head)
{
 return head->next == head;
}


decompiled_code:
void *__fastcall Gr_Alloc(size_t a1)
{
if ( !a1 )
a1 = 1LL;
return malloc(a1);
}

canonical_decompiled_code:
void *__fastcall func7(size_t a1)
{
if ( !a1 )
a1 = 1LL;
return malloc(a1);
}

original_code:
static inline void* Gr_Alloc(size_t size)
{
 size= size==0?1:size;
 return malloc(size);
}

canonical_original_code:
static inline void *Gr_Alloc(unsigned long size)
{
 size= size==0?1:size;
 return malloc(size);
}

variable_types:
size
unsigned long

return_type: void *


decompiled_code:
void *__fastcall pages_idx_free(int a1)
{
__int64 v1; // rcx
void *result; // rax

if ( pages_idx_free_pos <= a1 )
_assert_fail("pos<pages_idx_free_pos", "memory.c", 0x6Bu, "pages_idx_free");
v1 = pages_idx_next;
result = pages_idx_array;
pages_idx_next = a1;
*((_QWORD *)pages_idx_array + a1) = v1;
return result;
}

canonical_decompiled_code:
void *__fastcall func8(int a1)
{
__int64 v1; // rcx
void *result; // rax

if ( pages_idx_free_pos <= a1 )
_assert_fail("pos<pages_idx_free_pos", "memory.c", 0x6Bu, "pages_idx_free");
v1 = pages_idx_next;
result = pages_idx_array;
pages_idx_next = a1;
*((_QWORD *)pages_idx_array + a1) = v1;
return result;
}

original_code:
static inline void pages_idx_free(int pos)
{
 ((void) sizeof ((pos<pages_idx_free_pos) ? 1 : 0), __extension__ ({ if (pos<pages_idx_free_pos) ; else __assert_fail ("pos<pages_idx_free_pos", "memory.c", 107, __extension__ __PRETTY_FUNCTION__); }));
 pages_idx_array[pos]=(void*)pages_idx_next;
 pages_idx_next=pos;
}

canonical_original_code:
static inline void pages_idx_free(int pos)
{
 ((void) sizeof ((pos<pages_idx_free_pos) ? 1 : 0), __extension__ ({ if (pos<pages_idx_free_pos) ; else __assert_fail ("pos<pages_idx_free_pos", "memory.c", 107, __extension__ __PRETTY_FUNCTION__); }));
 pages_idx_array[pos]=(void *)pages_idx_next;
 pages_idx_next=pos;
}

variable_types: pos int


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

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

original_code:
static inline void Gr_Free(void* ptr)
{
 free(ptr);
}

canonical_original_code:
static inline void Gr_Free(void *ptr)
{
 free(ptr);
}

variable_types:
ptr
void *


decompiled_code:
__int64 page_idx_enlarge()
{
int v0; // ebx
int v1; // er12
void *v2; // rax
void *v3; // rbp
void *v4; // r13
__int64 result; // rax

v0 = pages_idx_cap;
v1 = 2 * pages_idx_cap;
if ( (pages_idx_cap & 0x40000000) != 0 )
return 0xFFFFFFFFLL;
v2 = Gr_Alloc(8LL * v1);
v3 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
v4 = pages_idx_array;
memcpy(v2, pages_idx_array, 8LL * v0);
Gr_Free(v4);
pages_idx_array = v3;
result = 0LL;
pages_idx_cap = v1;
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // ebx
int v1; // er12
void *v2; // rax
void *v3; // rbp
void *v4; // r13
__int64 result; // rax

v0 = pages_idx_cap;
v1 = 2 * pages_idx_cap;
if ( (pages_idx_cap & 0x40000000) != 0 )
return 0xFFFFFFFFLL;
v2 = func7(8LL * v1);
v3 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
v4 = pages_idx_array;
memcpy(v2, pages_idx_array, 8LL * v0);
func9(v4);
pages_idx_array = v3;
result = 0LL;
pages_idx_cap = v1;
return result;
}

original_code:
static inline int page_idx_enlarge()
{
 int enlarge_size=pages_idx_cap<<1;
 if(enlarge_size<0)
 {
  return -1;
 }
 void** new_idx=(void**)Gr_Alloc(enlarge_size*sizeof(void*));
 if(new_idx==((void *)0))
 {
  return -1;
 }
 memcpy(new_idx,pages_idx_array,sizeof(void*) * pages_idx_cap);
 Gr_Free(pages_idx_array);
 pages_idx_array=new_idx;
 pages_idx_cap=enlarge_size;
 return 0;
}

canonical_original_code:
static inline int page_idx_enlarge()
{
 int enlarge_size = pages_idx_cap<<1;
 if(enlarge_size<0)
 {
  return -1;
 }
 void **new_idx = (void**)Gr_Alloc(enlarge_size*sizeof(void*));
 if(new_idx==((void *)0))
 {
  return -1;
 }
 memcpy(new_idx,pages_idx_array,sizeof(void *) * pages_idx_cap);
 Gr_Free(pages_idx_array);
 pages_idx_array=new_idx;
 pages_idx_cap=enlarge_size;
 return 0;
}


decompiled_code:
__int64 __fastcall pages_idx_alloc(__int64 a1)
{
unsigned int v1; // er12
__int64 *v2; // rax
__int64 v3; // rdx
int v5; // ebx

v1 = pages_idx_next;
if ( pages_idx_next != -1 )
{
v2 = (__int64 *)((char *)pages_idx_array + 8 * pages_idx_next);
v3 = *v2;
*v2 = a1;
pages_idx_next = v3;
return v1;
}
v5 = pages_idx_free_pos;
if ( pages_idx_free_pos == pages_idx_cap && (int)page_idx_enlarge() < 0 )
return v1;
pages_idx_free_pos = v5 + 1;
*((_QWORD *)pages_idx_array + v5) = a1;
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
unsigned int v1; // er12
__int64 *v2; // rax
__int64 v3; // rdx
int v5; // ebx

v1 = pages_idx_next;
if ( pages_idx_next != -1 )
{
v2 = (__int64 *)((char *)pages_idx_array + 8 * pages_idx_next);
v3 = *v2;
*v2 = a1;
pages_idx_next = v3;
return v1;
}
v5 = pages_idx_free_pos;
if ( pages_idx_free_pos == pages_idx_cap && (int)func10() < 0 )
return v1;
pages_idx_free_pos = v5 + 1;
*((_QWORD *)pages_idx_array + v5) = a1;
return (unsigned int)v5;
}

original_code:
static inline int pages_idx_alloc(void* ptr)
{
 int ret;
 if(pages_idx_next!=-1)
 {
  ret=pages_idx_next;
  pages_idx_next=(int) pages_idx_array[ret];
  pages_idx_array[ret]=ptr;
  return ret;
 }
 if(pages_idx_free_pos==pages_idx_cap)
 {
  if(page_idx_enlarge()<0)
  {
   return -1;
  }
 }
 ret=pages_idx_free_pos++;
 pages_idx_array[ret]=ptr;
 return ret;
}

canonical_original_code:
static inline int pages_idx_alloc(void *ptr)
{
 int ret;
 if(pages_idx_next!=-1)
 {
  ret=pages_idx_next;
  pages_idx_next=(int) pages_idx_array[ret];
  pages_idx_array[ret]=ptr;
  return ret;
 }
 if(pages_idx_free_pos==pages_idx_cap)
 {
  if(page_idx_enlarge()<0)
  {
   return -1;
  }
 }
 ret=pages_idx_free_pos++;
 pages_idx_array[ret]=ptr;
 return ret;
}

variable_types: ret int


decompiled_code:
void __fastcall Gr_MemFree(void *ptr)
{
_QWORD *v1; // r12
int v2; // er13
__int16 v3; // dx
__int64 v4; // rcx
__int16 v5; // ax
__int64 *v6; // rsi
__int64 v7; // rdx
__int16 v8; // ax
__int64 v9; // rcx

v1 = (_QWORD *)((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL);
v2 = *(_DWORD *)((char *)&loc_17 + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL) + 1);
if ( pages_idx_free_pos > v2 && v2 >= 0 && *((_QWORD **)pages_idx_array + v2) == v1 )
{
if ( ((unsigned __int8)ptr & 7) != 0 )
_assert_fail("!((unsigned long)ptr&GR_MEM_ALIGN_LOW_MASK)", "memory.c", 0xF8u, "Gr_MemFree");
v3 = *(_WORD *)((char *)&loc_1A + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL) + 2);
if ( v3 > 31 )
{
fprintf(stderr, "%s::%s(Line %d):", "memory.c", "Gr_MemFree", 250LL);
fprintf(stderr, "%s(%s,", "BUG_ON", "h->p_slot_idx>=(256>>3)");
fprintf(
stderr,
"h->p_slot_idx=%d,Max=%d",
(unsigned int)*(__int16 *)((char *)&loc_1A + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL) + 2),
32LL);
fwrite(")\n", 1uLL, 2uLL, stderr);
v3 = *(_WORD *)((char *)&loc_1A + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL) + 2);
}
v4 = v3;
v5 = *(_WORD *)((char *)&locret_1E + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL));
v6 = (__int64 *)(48LL * v3);
if ( v5 == *(__int16 *)((char *)&word_72C + (_QWORD)v6) )
{
list_del((__int64)v1);
v6 = (__int64 *)((char *)&slots + 48 * v9);
list_add_tail(v1, v6);
v5 = *(_WORD *)((char *)&locret_1E + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL));
}
v7 = *(_QWORD *)((char *)_list_add + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL));
v8 = v5 - 1;
*(_WORD *)((char *)&locret_1E + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL)) = v8;
*(_QWORD *)ptr = v7;
*(_QWORD *)((char *)_list_add + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL)) = ptr;
if ( !v8 )
{
if ( (_QWORD *)qword_720[6 * v4] == v1 )
qword_720[6 * v4] = 0LL;
else
list_del((__int64)v1);
Gr_FreePage(v1, v6, v7);
pages_idx_free(v2);
}
}
else
{
Gr_Free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func14(void *ptr)
{
_QWORD *v1; // r12
int v2; // er13
__int16 v3; // dx
__int64 v4; // rcx
__int16 v5; // ax
__int64 *v6; // rsi
__int64 v7; // rdx
__int16 v8; // ax
__int64 v9; // rcx

v1 = (_QWORD *)((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL);
v2 = *(_DWORD *)((char *)&loc_17 + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL) + 1);
if ( pages_idx_free_pos > v2 && v2 >= 0 && *((_QWORD **)pages_idx_array + v2) == v1 )
{
if ( ((unsigned __int8)ptr & 7) != 0 )
_assert_fail("!((unsigned long)ptr&GR_MEM_ALIGN_LOW_MASK)", "memory.c", 0xF8u, "Gr_MemFree");
v3 = *(_WORD *)((char *)&loc_1A + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL) + 2);
if ( v3 > 31 )
{
fprintf(stderr, "%s::%s(Line %d):", "memory.c", "Gr_MemFree", 250LL);
fprintf(stderr, "%s(%s,", "BUG_ON", "h->p_slot_idx>=(256>>3)");
fprintf(
stderr,
"h->p_slot_idx=%d,Max=%d",
(unsigned int)*(__int16 *)((char *)&loc_1A + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL) + 2),
32LL);
fwrite(")\n", 1uLL, 2uLL, stderr);
v3 = *(_WORD *)((char *)&loc_1A + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL) + 2);
}
v4 = v3;
v5 = *(_WORD *)((char *)&locret_1E + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL));
v6 = (__int64 *)(48LL * v3);
if ( v5 == *(__int16 *)((char *)&word_72C + (_QWORD)v6) )
{
func5((__int64)v1);
v6 = (__int64 *)((char *)&slots + 48 * v9);
func3(v1, v6);
v5 = *(_WORD *)((char *)&locret_1E + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL));
}
v7 = *(_QWORD *)((char *)_list_add + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL));
v8 = v5 - 1;
*(_WORD *)((char *)&locret_1E + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL)) = v8;
*(_QWORD *)ptr = v7;
*(_QWORD *)((char *)_list_add + ((unsigned __int64)ptr & 0xFFFFFFFFFFFFF000LL)) = ptr;
if ( !v8 )
{
if ( (_QWORD *)qword_720[6 * v4] == v1 )
qword_720[6 * v4] = 0LL;
else
func5((__int64)v1);
Gr_FreePage(v1, v6, v7);
func8(v2);
}
}
else
{
func9(ptr);
}
}

original_code:
void Gr_MemFree(void* ptr)
{
 register struct block_header* b=(struct block_header*)ptr;
 register struct page_header* h=(struct page_header*)((unsigned long)(ptr) & (~((1ul<<12)-1)));
 ((void) sizeof (((!((unsigned long)(h) &((1ul<<12)-1)))) ? 1 : 0), __extension__ ({ if ((!((unsigned long)(h) &((1ul<<12)-1)))) ; else __assert_fail ("GR_PAGE_ALIGNED(h)", "memory.c", 222, __extension__ __PRETTY_FUNCTION__); }));
 register struct slot_header* s;
 register int page_idx=h->p_page_idx;
 if(page_idx>=pages_idx_free_pos||page_idx<0)
 {
  Gr_Free(ptr);
  return ;
 }
 if(pages_idx_array[page_idx]!=(void*)h)
 {
  Gr_Free(ptr);
  return;
 }
 ((void) sizeof ((!((unsigned long)ptr&((1ul<<3)-1))) ? 1 : 0), __extension__ ({ if (!((unsigned long)ptr&((1ul<<3)-1))) ; else __assert_fail ("!((unsigned long)ptr&GR_MEM_ALIGN_LOW_MASK)", "memory.c", 248, __extension__ __PRETTY_FUNCTION__); }));
 do{ if(h->p_slot_idx>=(256>>3)) { fprintf(stderr,"%s::%s(Line %d):","memory.c",__func__,250); fprintf(stderr,"%s(%s,","BUG_ON","h->p_slot_idx>=(256>>3)"); fprintf(stderr,"h->p_slot_idx=%d,Max=%d", h->p_slot_idx,(256>>3)); fprintf(stderr,")\n"); } }while(0);
 s=&slots[h->p_slot_idx];
 if(h->p_block_used==s->s_block_nu)
 {
  list_del(&h->p_link);
  list_add_tail(&h->p_link,&s->s_free_page);
 }
 h->p_block_used--;
 b->b_next=h->p_free_block;
 h->p_free_block=b;
 if((h->p_block_used==0))
 {
  if(s->s_cur==h)
  {
   s->s_cur=((void *)0);
  }
  else
  {
   list_del(&h->p_link);
  }
  Gr_FreePage(h);
  pages_idx_free(page_idx);
 }
}

canonical_original_code:
void Gr_MemFree(void *ptr)
{
 register struct block_header *b = (struct block_header*)ptr;
 register struct page_header *h = (struct page_header*)((unsigned long)(ptr) & (~((1ul<<12)-1)));
 ((void) sizeof (((!((unsigned long)(h) &((1ul<<12)-1)))) ? 1 : 0), __extension__ ({ if ((!((unsigned long)(h) &((1ul<<12)-1)))) ; else __assert_fail ("GR_PAGE_ALIGNED(h)", "memory.c", 222, __extension__ __PRETTY_FUNCTION__); }));
 register struct slot_header *s;
 register int page_idx = h->p_page_idx;
 if(page_idx>=pages_idx_free_pos||page_idx<0)
 {
  Gr_Free(ptr);
  return ;
 }
 if(pages_idx_array[page_idx]!=(void *)h)
 {
  Gr_Free(ptr);
  return;
 }
 ((void) sizeof ((!((unsigned long)ptr&((1ul<<3)-1))) ? 1 : 0), __extension__ ({ if (!((unsigned long)ptr&((1ul<<3)-1))) ; else __assert_fail ("!((unsigned long)ptr&GR_MEM_ALIGN_LOW_MASK)", "memory.c", 248, __extension__ __PRETTY_FUNCTION__); }));
 do{ if(h->p_slot_idx>=(256>>3)) { fprintf(stderr,"%s::%s(Line %d):","memory.c",__func__,250); fprintf(stderr,"%s(%s,","BUG_ON","h->p_slot_idx>=(256>>3)"); fprintf(stderr,"h->p_slot_idx=%d,Max=%d", h->p_slot_idx,(256>>3)); fprintf(stderr,")\n"); } }while(0);
 s=&slots[h->p_slot_idx];
 if(h->p_block_used==s->s_block_nu)
 {
  list_del(&h->p_link);
  list_add_tail(&h->p_link,&s->s_free_page);
 }
 h->p_block_used--;
 b->b_next=h->p_free_block;
 h->p_free_block=b;
 if((h->p_block_used==0))
 {
  if(s->s_cur==h)
  {
   s->s_cur=((void *)0);
  }
  else
  {
   list_del(&h->p_link);
  }
  Gr_FreePage(h);
  pages_idx_free(page_idx);
 }
}

variable_types: struct page_header { struct list_head { struct list_head *prev; struct list_head *next; } p_link; struct block_header { struct block_header *b_next; } *p_free_block; int p_page_idx; short p_slot_idx; short p_block_used; unsigned long p_free_pos; } *

variable_types: struct slot_header { struct list_head { struct list_head *prev; struct list_head *next; } s_free_page; struct list_head s_full_page; struct page_header { struct list_head p_link; struct block_header { struct block_header *b_next; } *p_free_block; int p_page_idx; short p_slot_idx; short p_block_used; unsigned long p_free_pos; } *s_cur; short s_block_size; short s_alloc_offset; short s_block_nu; } *

user_defined_types: struct page_header { struct list_head p_link; struct block_header *p_free_block; int p_page_idx; short p_slot_idx; short p_block_used; unsigned long p_free_pos; }

user_defined_types: struct slot_header { struct list_head s_free_page; struct list_head s_full_page; struct page_header *s_cur; short s_block_size; short s_alloc_offset; short s_block_nu; }


decompiled_code:
__int64 GrModule_MemInit()
{
char *v0; // rcx
__int64 v1; // rsi
__int64 v2; // rcx
__int16 v3; // ax
__int64 v4; // rdx
__int64 v5; // r8
unsigned __int64 v6; // rax
unsigned __int128 v7; // rtt

pages_idx_array = Gr_Alloc(0x2000uLL);
if ( !pages_idx_array )
return 0xFFFFFFFFLL;
v0 = (char *)&slots;
v1 = 8LL;
do
{
INIT_LIST_HEAD(v0);
INIT_LIST_HEAD((_QWORD *)(v2 + 16));
*((_WORD *)v0 - 3) = v3;
*(_QWORD *)&v7 = v5;
*((_QWORD *)&v7 + 1) = v4;
v6 = v7 / (unsigned __int64)v1;
*((_WORD *)v0 - 4) = v1;
*((_QWORD *)v0 - 2) = 0LL;
v1 += 8LL;
*((_WORD *)v0 - 2) = v6;
}
while ( v0 != "memory.c" );
return 0LL;
}

canonical_decompiled_code:
__int64 func15()
{
char *v0; // rcx
__int64 v1; // rsi
__int64 v2; // rcx
__int16 v3; // ax
__int64 v4; // rdx
__int64 v5; // r8
unsigned __int64 v6; // rax
unsigned __int128 v7; // rtt

pages_idx_array = func7(0x2000uLL);
if ( !pages_idx_array )
return 0xFFFFFFFFLL;
v0 = (char *)&slots;
v1 = 8LL;
do
{
func0(v0);
func0((_QWORD *)(v2 + 16));
*((_WORD *)v0 - 3) = v3;
*(_QWORD *)&v7 = v5;
*((_QWORD *)&v7 + 1) = v4;
v6 = v7 / (unsigned __int64)v1;
*((_WORD *)v0 - 4) = v1;
*((_QWORD *)v0 - 2) = 0LL;
v1 += 8LL;
*((_WORD *)v0 - 2) = v6;
}
while ( v0 != "memory.c" );
return 0LL;
}

original_code:
int GrModule_MemInit()
{
 pages_idx_array=(void**)Gr_Alloc(1024*sizeof(void*));
 if(pages_idx_array==((void *)0))
 {
  return -1;
 }
 int i=0;
 struct slot_header* s;
 for(i=0;i<(256>>3);i++)
 {
  s=&slots[i];
  INIT_LIST_HEAD(&s->s_free_page);
  INIT_LIST_HEAD(&s->s_full_page);
  s->s_cur=((void *)0);
  s->s_block_size=(i+1)<<3;
  s->s_alloc_offset=((~((1ul<<3)-1))&((sizeof(struct page_header))+((1ul<<3)-1)));
  s->s_block_nu=((1ul<<12)-s->s_alloc_offset)/s->s_block_size;
 }
 return 0;
}

canonical_original_code:
int GrModule_MemInit()
{
 pages_idx_array=(void **)Gr_Alloc(1024*sizeof(void *));
 if(pages_idx_array==((void *)0))
 {
  return -1;
 }
 int i = 0;
 struct slot_header *s;
 for(i=0;i<(256>>3);i++)
 {
  s=&slots[i];
  INIT_LIST_HEAD(&s->s_free_page);
  INIT_LIST_HEAD(&s->s_full_page);
  s->s_cur=((void *)0);
  s->s_block_size=(i+1)<<3;
  s->s_alloc_offset=((~((1ul<<3)-1))&((sizeof(struct page_header))+((1ul<<3)-1)));
  s->s_block_nu=((1ul<<12)-s->s_alloc_offset)/s->s_block_size;
 }
 return 0;
}

variable_types: i int

user_defined_types: struct block_header { struct block_header *b_next; }


decompiled_code:
__int64 GrModule_MemExit()
{
__int64 result; // rax

if ( !pages_idx_array )
return 0LL;
Gr_Free(pages_idx_array);
result = 0LL;
pages_idx_array = 0LL;
return result;
}

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

if ( !pages_idx_array )
return 0LL;
func9(pages_idx_array);
result = 0LL;
pages_idx_array = 0LL;
return result;
}

original_code:
int GrModule_MemExit()
{
 if(pages_idx_array)
 {
  Gr_Free(pages_idx_array);
  pages_idx_array=((void *)0);
 }
 return 0;
}


canonical_original_code:
static inline void list_add(struct list_head *new_list, struct list_head *head)
{
 __list_add(new_list, head, head->next);
}


decompiled_code:
void alloc_area()
{
_QWORD *v0; // rax
__int64 v1; // rcx
_QWORD *v2; // rax
__int64 v3; // rdx

v0 = malloc(0x100030uLL);
if ( v0 )
{
INIT_LIST_HEAD(v0);
v1 &= 0xFFFFFFFFFFFFF000LL;
v2[2] = v3;
++s_area_nu;
v2[3] = v1;
v2[4] = 0LL;
v2[5] = (unsigned int)(((unsigned __int64)v2 - v1 + 1048624) >> 12);
}
}

original_code:
static struct area_header* alloc_area()
{
 struct area_header* h=(struct area_header*)malloc(sizeof(*h)+1024*1024);
 if(h==((void *)0)) return ((void *)0);
 INIT_LIST_HEAD(&h->a_link);
 h->a_block=(unsigned long)h+sizeof(*h);
 h->a_alloc_start=(((unsigned long)(h->a_block)+((1ul<<12)-1))&(~((1ul<<12)-1)));
 h->a_free_pages=((void *)0);
 h->a_page_nu=(1024*1024 -(h->a_alloc_start-h->a_block))>>12;
 h->a_free_pos=0;
 h->a_page_used=0;
 s_area_nu++;
 return h;
}

canonical_original_code:
static struct area_header *alloc_area()
{
 struct area_header *h = (struct area_header*)malloc(sizeof(*h)+1024*1024);
 if(h==((void *)0)) return ((void *)0);
 INIT_LIST_HEAD(&h->a_link);
 h->a_block=(unsigned long)h+sizeof(*h);
 h->a_alloc_start=(((unsigned long)(h->a_block)+((1ul<<12)-1))&(~((1ul<<12)-1)));
 h->a_free_pages=((void *)0);
 h->a_page_nu=(1024*1024 -(h->a_alloc_start-h->a_block))>>12;
 h->a_free_pos=0;
 h->a_page_used=0;
 s_area_nu++;
 return h;
}

variable_types: struct area_header { struct list_head { struct list_head *prev; struct list_head *next; } a_link; unsigned long a_block; unsigned long a_alloc_start; struct page_header { struct page_header *p_next; } *a_free_pages; int a_page_nu; short a_free_pos; short a_page_used; } *

user_defined_types: struct area_header { struct list_head a_link; unsigned long a_block; unsigned long a_alloc_start; struct page_header *a_free_pages; int a_page_nu; short a_free_pos; short a_page_used; }


decompiled_code:
void __fastcall free_area(_WORD *a1)
{
if ( a1[23] )
_assert_fail("h->a_page_used==0", "mem_base.c", 0x5Fu, "free_area");
if ( s_area_nu <= 0 )
_assert_fail("s_area_nu>0", "mem_base.c", 0x60u, "free_area");
--s_area_nu;
free(a1);
}

canonical_decompiled_code:
void __fastcall func6(_WORD *a1)
{
if ( a1[23] )
_assert_fail("h->a_page_used==0", "mem_base.c", 0x5Fu, "free_area");
if ( s_area_nu <= 0 )
_assert_fail("s_area_nu>0", "mem_base.c", 0x60u, "free_area");
--s_area_nu;
free(a1);
}

original_code:
static void free_area(struct area_header* h)
{
 ((void) sizeof ((h->a_page_used==0) ? 1 : 0), __extension__ ({ if (h->a_page_used==0) ; else __assert_fail ("h->a_page_used==0", "mem_base.c", 95, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((s_area_nu>0) ? 1 : 0), __extension__ ({ if (s_area_nu>0) ; else __assert_fail ("s_area_nu>0", "mem_base.c", 96, __extension__ __PRETTY_FUNCTION__); }));
 s_area_nu--;
 free(h);
}

canonical_original_code:
static void free_area(struct area_header *h)
{
 ((void) sizeof ((h->a_page_used==0) ? 1 : 0), __extension__ ({ if (h->a_page_used==0) ; else __assert_fail ("h->a_page_used==0", "mem_base.c", 95, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((s_area_nu>0) ? 1 : 0), __extension__ ({ if (s_area_nu>0) ; else __assert_fail ("s_area_nu>0", "mem_base.c", 96, __extension__ __PRETTY_FUNCTION__); }));
 s_area_nu--;
 free(h);
}

user_defined_types: struct page_header { struct page_header *p_next; }


decompiled_code:
int Gr_PrintAreaNum()
{
return printf("AreaNum=%d\n", (unsigned int)s_area_nu);
}

canonical_decompiled_code:
int func11()
{
return printf("AreaNum=%d\n", (unsigned int)s_area_nu);
}

original_code:
void Gr_PrintAreaNum()
{
 printf("AreaNum=%d\n",s_area_nu);
}


decompiled_code:
__int64 yl_cur_string()
{
if ( !yl_scanner )
{
fprintf(stderr, "%s::%s(Line %d):", "yylex.c", "yl_cur_string", 19LL);
fprintf(stderr, "%s(%s,", "BUG_ON", "yl_scanner==0");
fwrite("NULL Scanner", 1uLL, 0xCuLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
}
return sc_token_string_isra_0(*(_QWORD *)(yl_scanner + 16));
}

canonical_decompiled_code:
__int64 func3()
{
if ( !yl_scanner )
{
fprintf(stderr, "%s::%s(Line %d):", "yylex.c", "yl_cur_string", 19LL);
fprintf(stderr, "%s(%s,", "BUG_ON", "yl_scanner==0");
fwrite("NULL Scanner", 1uLL, 0xCuLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
}
return func0(*(_QWORD *)(yl_scanner + 16));
}

original_code:
char* yl_cur_string()
{
 do{ if(yl_scanner==0) { fprintf(stderr,"%s::%s(Line %d):","yylex.c",__func__,19); fprintf(stderr,"%s(%s,","BUG_ON","yl_scanner==0"); fprintf(stderr,"NULL Scanner"); fprintf(stderr,")\n"); } }while(0);
 return sc_token_string(yl_scanner);
}

canonical_original_code:
char *yl_cur_string()
{
 do{ if(yl_scanner==0) { fprintf(stderr,"%s::%s(Line %d):","yylex.c",__func__,19); fprintf(stderr,"%s(%s,","BUG_ON","yl_scanner==0"); fprintf(stderr,"NULL Scanner"); fprintf(stderr,")\n"); } }while(0);
 return sc_token_string(yl_scanner);
}


decompiled_code:
void yl_ignore_newline()
{
++ignore_newline;
}

canonical_decompiled_code:
void func6()
{
++ignore_newline;
}

original_code:
void yl_ignore_newline()
{
 ignore_newline+=1;
}


decompiled_code:
void yl_restore_newline()
{
--ignore_newline;
}

canonical_decompiled_code:
void func7()
{
--ignore_newline;
}

original_code:
void yl_restore_newline()
{
 ignore_newline-=1;
}


yyerror

decompiled_code:
int yyerror()
{
return fprintf(stderr, "SyntaxError At Line %d\n", *(unsigned int *)(yl_scanner + 12));
}

canonical_decompiled_code:
int func4()
{
return fprintf(stderr, "SyntaxError At Line %d\n", *(unsigned int *)(yl_scanner + 12));
}

original_code:
void yyerror(char* error)
{
 fprintf(stderr,"SyntaxError At Line %d\n",yl_scanner->s_line);
}

canonical_original_code:
void yyerror(char *error)
{
 fprintf(stderr,"SyntaxError At Line %d\n",yl_scanner->s_line);
}

variable_types:
error
char *


yylex

decompiled_code:
__int64 yylex()
{
__int64 result; // rax
__int64 v1; // rax

if ( !yl_scanner )
{
fprintf(stderr, "%s::%s(Line %d):", "yylex.c", "yylex", 29LL);
fprintf(stderr, "%s(%s,", "BUG_ON", "yl_scanner==0");
fwrite("NULL Scanner", 1uLL, 0xCuLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
}
do
{
while ( 1 )
{
result = sc_next_token();
if ( (_DWORD)result != 80 )
{
if ( (_DWORD)result == 6 )
{
v1 = sc_token_string_isra_0(*(_QWORD *)(yl_scanner + 16));
result = symbol_type(v1);
}
if ( (_DWORD)result != 43 )
break;
}
if ( !ignore_newline )
return 301LL;
}
}
while ( (_DWORD)result == 81 );
if ( (_DWORD)result != -1 )
result = (unsigned int)(result + 258);
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
__int64 v1; // rax

if ( !yl_scanner )
{
fprintf(stderr, "%s::%s(Line %d):", "yylex.c", "yylex", 29LL);
fprintf(stderr, "%s(%s,", "BUG_ON", "yl_scanner==0");
fwrite("NULL Scanner", 1uLL, 0xCuLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
}
do
{
while ( 1 )
{
result = sc_next_token();
if ( (_DWORD)result != 80 )
{
if ( (_DWORD)result == 6 )
{
v1 = func0(*(_QWORD *)(yl_scanner + 16));
result = symbol_type(v1);
}
if ( (_DWORD)result != 43 )
break;
}
if ( !ignore_newline )
return 301LL;
}
}
while ( (_DWORD)result == 81 );
if ( (_DWORD)result != -1 )
result = (unsigned int)(result + 258);
return result;
}

original_code:
int yylex()
{
 do{ if(yl_scanner==0) { fprintf(stderr,"%s::%s(Line %d):","yylex.c",__func__,29); fprintf(stderr,"%s(%s,","BUG_ON","yl_scanner==0"); fprintf(stderr,"NULL Scanner"); fprintf(stderr,")\n"); } }while(0);
 int token=TOKEN_WS;
 while(1)
 {
  token=sc_next_token(yl_scanner);
  if(token==TOKEN_ANNO)
  {
   token=TOKEN_NEWLINE;
  }
  if(token==TOKEN_ID)
  {
   token=symbol_type(sc_token_string(yl_scanner));
  }
  if(token==TOKEN_NEWLINE)
  {
   if(ignore_newline)
   {
    continue;
   }
  }
  if(token==TOKEN_WS)
  {
   continue;
  }
  break;
 }
 if(token!=(-1))
 {
  token+=258;
 }
 return token;
}

canonical_original_code:
int yylex()
{
 do{ if(yl_scanner==0) { fprintf(stderr,"%s::%s(Line %d):","yylex.c",__func__,29); fprintf(stderr,"%s(%s,","BUG_ON","yl_scanner==0"); fprintf(stderr,"NULL Scanner"); fprintf(stderr,")\n"); } }while(0);
 int token = TOKEN_WS;
 while(1)
 {
  token=sc_next_token(yl_scanner);
  if(token==TOKEN_ANNO)
  {
   token=TOKEN_NEWLINE;
  }
  if(token==TOKEN_ID)
  {
   token=symbol_type(sc_token_string(yl_scanner));
  }
  if(token==TOKEN_NEWLINE)
  {
   if(ignore_newline)
   {
    continue;
   }
  }
  if(token==TOKEN_WS)
  {
   continue;
  }
  break;
 }
 if(token!=(-1))
 {
  token+=258;
 }
 return token;
}

variable_types: token int