main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
const char **v4; // rbp
char *v6; // r13
char *v7; // r14
__int64 v8; // rdx
char *v9; // r12
const char *v10; // rdi
char v11; // al
int v12; // er12
const char *v14; // rdi
__int64 v15; // rdx
unsigned int *v16; // rax
char *v17; // rsi
__int64 v18; // rdx
__int64 v19; // rsi
__int64 v20; // rdx
__int64 v21; // rsi
__int64 v22; // rdx
unsigned int *v23; // rax
char *v24; // rax
const char *v25; // r8
const char *v26; // rdi
const char **v27; // r12
__int64 v28; // rbp
const char *v29; // rdi
int v30; // eax
const char *v31; // rdx
const char *v32; // [rsp+8h] [rbp-50h]
unsigned int v33; // [rsp+14h] [rbp-44h] BYREF
char *v34[8]; // [rsp+18h] [rbp-40h] BYREF

v3 = 1;
v4 = argv;
v6 = getenv("NEATROFF_F");
v7 = getenv("NEATROFF_M");
v9 = getenv("NEATROFF_T");
if ( !v9 )
v9 = "utf";
if ( !v6 )
v6 = "/neatroff/font";
if ( !v7 )
v7 = "/neatroff/tmac";
if ( argc > 1 )
{
while ( 2 )
{
v10 = v4[v3];
v8 = v3;
if ( *v10 == 45 )
{
v11 = v10[1];
if ( v11 )
{
switch ( v11 )
{
case 'C':
*(_DWORD *)nreg(67LL, argv, v8 * 8) = 1;
goto LABEL_16;
case 'F':
v6 = (char *)(v10 + 2);
if ( !v10[2] )
{
v6 = (char *)v4[v8 + 1];
++v3;
}
goto LABEL_16;
case 'M':
v7 = (char *)(v10 + 2);
if ( !v10[2] )
{
v7 = (char *)v4[v8 + 1];
++v3;
}
goto LABEL_16;
case 'T':
v9 = (char *)(v10 + 2);
if ( !v10[2] )
{
v9 = (char *)v4[v8 + 1];
++v3;
}
goto LABEL_16;
case 'd':
if ( v10[2] )
{
v26 = v10 + 2;
}
else
{
v26 = v4[v8 + 1];
++v3;
}
cmddef(v26, &v33, v34);
argv = (const char **)v34[0];
str_set(v33, v34[0]);
goto LABEL_16;
case 'm':
argv = (const char **)(algn_25 + 10);
v32 = v10 + 2;
v24 = strchr(v10 + 2, 47);
v25 = v10 + 2;
if ( v24
|| (argv = (const char **)(v10 + 2), (unsigned int)cmdmac(v7, v32))
&& (argv = (const char **)(v10 + 2), v30 = cmdmac(".", v32), v25 = v10 + 2, v30) )
{
in_queue(v25);
}
goto LABEL_16;
case 'r':
if ( v10[2] )
{
v14 = v10 + 2;
}
else
{
v14 = v4[v8 + 1];
++v3;
}
cmddef(v14, &v33, v34);
v16 = (unsigned int *)nreg(v33, &v33, v15);
argv = (const char **)(unsigned int)eval_re(v34[0], *v16, 117LL);
num_set(v33, argv);
LABEL_16:
if ( argc <= ++v3 )
goto LABEL_17;
continue;
default:
v12 = 1;
fwrite(
"Usage: neatroff [options] input\n"
"\n"
"Options:\n"
" -mx \tinclude macro x\n"
" -rx=y \tset number register x to y\n"
" -dx=y \tdefine string register x as y\n"
" -C \tenable compatibility mode\n"
" -Tdev \tset output device\n"
" -Fdir \tset font directory (/neatroff/font)\n"
" -Mdir \tset macro directory (/neatroff/tmac)\n",
1uLL,
0x127uLL,
stderr);
return v12;
}
}
}
break;
}
v17 = v9;
if ( !(unsigned int)dev_open(v6, v9, v8 * 8) )
{
hyph_init();
env_init();
tr_init();
LABEL_37:
if ( v3 < argc )
{
v27 = &v4[v3];
v28 = (__int64)&(&v4[argc - 1 - v3])[(__int64)v3 + 1];
do
{
v29 = *v27;
if ( **v27 == 45 && !v29[1] )
v29 = 0LL;
in_queue(v29);
++v27;
}
while ( v27 != (const char **)v28 );
}
goto LABEL_20;
}
LABEL_47:
v31 = v9;
v12 = 1;
fprintf(stderr, "neatroff: cannot open device %s\n", v31);
return v12;
}
LABEL_17:
v17 = v9;
if ( (unsigned int)dev_open(v6, v9, v8 * 8) )
goto LABEL_47;
hyph_init();
env_init();
tr_init();
if ( argc != v3 )
goto LABEL_37;
in_queue(0LL);
LABEL_20:
v19 = *(unsigned int *)nreg(115LL, v17, v18);
out("s%d\n", v19);
v21 = *(unsigned int *)nreg(102LL, v19, v20);
out("f%d\n", v21);
v12 = render();
v23 = (unsigned int *)nreg(112LL, v21, v22);
out("V%d\n", *v23);
hyph_done();
tr_done();
env_done();
dev_close();
map_done();
dir_done();
return v12;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
const char **v4; // rbp
char *v6; // r13
char *v7; // r14
__int64 v8; // rdx
char *v9; // r12
const char *v10; // rdi
char v11; // al
int v12; // er12
const char *v14; // rdi
__int64 v15; // rdx
unsigned int *v16; // rax
char *v17; // rsi
__int64 v18; // rdx
__int64 v19; // rsi
__int64 v20; // rdx
__int64 v21; // rsi
__int64 v22; // rdx
unsigned int *v23; // rax
char *v24; // rax
const char *v25; // r8
const char *v26; // rdi
const char **v27; // r12
__int64 v28; // rbp
const char *v29; // rdi
int v30; // eax
const char *v31; // rdx
const char *v32; // [rsp+8h] [rbp-50h]
unsigned int v33; // [rsp+14h] [rbp-44h] BYREF
char *v34[8]; // [rsp+18h] [rbp-40h] BYREF

v3 = 1;
v4 = argv;
v6 = getenv("NEATROFF_F");
v7 = getenv("NEATROFF_M");
v9 = getenv("NEATROFF_T");
if ( !v9 )
v9 = "utf";
if ( !v6 )
v6 = "/neatroff/font";
if ( !v7 )
v7 = "/neatroff/tmac";
if ( argc > 1 )
{
while ( 2 )
{
v10 = v4[v3];
v8 = v3;
if ( *v10 == 45 )
{
v11 = v10[1];
if ( v11 )
{
switch ( v11 )
{
case 'C':
*(_DWORD *)nreg(67LL, argv, v8 * 8) = 1;
goto LABEL_16;
case 'F':
v6 = (char *)(v10 + 2);
if ( !v10[2] )
{
v6 = (char *)v4[v8 + 1];
++v3;
}
goto LABEL_16;
case 'M':
v7 = (char *)(v10 + 2);
if ( !v10[2] )
{
v7 = (char *)v4[v8 + 1];
++v3;
}
goto LABEL_16;
case 'T':
v9 = (char *)(v10 + 2);
if ( !v10[2] )
{
v9 = (char *)v4[v8 + 1];
++v3;
}
goto LABEL_16;
case 'd':
if ( v10[2] )
{
v26 = v10 + 2;
}
else
{
v26 = v4[v8 + 1];
++v3;
}
func2(v26, &v33, v34);
argv = (const char **)v34[0];
str_set(v33, v34[0]);
goto LABEL_16;
case 'm':
argv = (const char **)(algn_25 + 10);
v32 = v10 + 2;
v24 = strchr(v10 + 2, 47);
v25 = v10 + 2;
if ( v24
|| (argv = (const char **)(v10 + 2), (unsigned int)func1(v7, v32))
&& (argv = (const char **)(v10 + 2), v30 = func1(".", v32), v25 = v10 + 2, v30) )
{
in_queue(v25);
}
goto LABEL_16;
case 'r':
if ( v10[2] )
{
v14 = v10 + 2;
}
else
{
v14 = v4[v8 + 1];
++v3;
}
func2(v14, &v33, v34);
v16 = (unsigned int *)nreg(v33, &v33, v15);
argv = (const char **)(unsigned int)eval_re(v34[0], *v16, 117LL);
num_set(v33, argv);
LABEL_16:
if ( argc <= ++v3 )
goto LABEL_17;
continue;
default:
v12 = 1;
fwrite(
"Usage: neatroff [options] input\n"
"\n"
"Options:\n"
" -mx \tinclude macro x\n"
" -rx=y \tset number register x to y\n"
" -dx=y \tdefine string register x as y\n"
" -C \tenable compatibility mode\n"
" -Tdev \tset output device\n"
" -Fdir \tset font directory (/neatroff/font)\n"
" -Mdir \tset macro directory (/neatroff/tmac)\n",
1uLL,
0x127uLL,
stderr);
return v12;
}
}
}
break;
}
v17 = v9;
if ( !(unsigned int)dev_open(v6, v9, v8 * 8) )
{
hyph_init();
env_init();
tr_init();
LABEL_37:
if ( v3 < argc )
{
v27 = &v4[v3];
v28 = (__int64)&(&v4[argc - 1 - v3])[(__int64)v3 + 1];
do
{
v29 = *v27;
if ( **v27 == 45 && !v29[1] )
v29 = 0LL;
in_queue(v29);
++v27;
}
while ( v27 != (const char **)v28 );
}
goto LABEL_20;
}
LABEL_47:
v31 = v9;
v12 = 1;
fprintf(stderr, "neatroff: cannot open device %s\n", v31);
return v12;
}
LABEL_17:
v17 = v9;
if ( (unsigned int)dev_open(v6, v9, v8 * 8) )
goto LABEL_47;
hyph_init();
env_init();
tr_init();
if ( argc != v3 )
goto LABEL_37;
in_queue(0LL);
LABEL_20:
v19 = *(unsigned int *)nreg(115LL, v17, v18);
out("s%d\n", v19);
v21 = *(unsigned int *)nreg(102LL, v19, v20);
out("f%d\n", v21);
v12 = render();
v23 = (unsigned int *)nreg(112LL, v21, v22);
out("V%d\n", *v23);
hyph_done();
tr_done();
env_done();
dev_close();
map_done();
dir_done();
return v12;
}

original_code:
int main(int argc, char **argv)
{
 char *fdir = getenv("NEATROFF_F");
 char *mdir = getenv("NEATROFF_M");
 char *dev = getenv("NEATROFF_T");
 char *mac, *def;
 int reg, ret;
 int i;
 if (dev == ((void *)0))
  dev = "utf";
 if (fdir == ((void *)0))
  fdir = "/neatroff/font";
 if (mdir == ((void *)0))
  mdir = "/neatroff/tmac";
 for (i = 1; i < argc; i++) {
  if (argv[i][0] != '-' || !argv[i][1])
   break;
  switch (argv[i][1]) {
  case 'C':
   (*nreg(('C'))) = 1;
   break;
  case 'm':
   mac = argv[i] + 2;
   if (strchr(mac, '/') || (cmdmac(mdir, mac) && cmdmac(".", mac)))
    in_queue(mac);
   break;
  case 'r':
   cmddef(argv[i][2] ? argv[i] + 2 : argv[++i], &reg, &def);
   num_set(reg, eval_re(def, (*nreg(reg)), 'u'));
   break;
  case 'd':
   cmddef(argv[i][2] ? argv[i] + 2 : argv[++i], &reg, &def);
   str_set(reg, def);
   break;
  case 'F':
   fdir = argv[i][2] ? argv[i] + 2 : argv[++i];
   break;
  case 'M':
   mdir = argv[i][2] ? argv[i] + 2 : argv[++i];
   break;
  case 'T':
   dev = argv[i][2] ? argv[i] + 2 : argv[++i];
   break;
  default:
   fprintf(stderr, "%s", usage);
   return 1;
  }
 }
 if (dev_open(fdir, dev)) {
  fprintf(stderr, "neatroff: cannot open device %s\n", dev);
  return 1;
 }
 hyph_init();
 env_init();
 tr_init();
 if (i == argc)
  in_queue(((void *)0));
 for (; i < argc; i++)
  in_queue(!strcmp("-", argv[i]) ? ((void *)0) : argv[i]);
 out("s%d\n", (*nreg(('s'))));
 out("f%d\n", (*nreg(('f'))));
 ret = render();
 out("V%d\n", (*nreg(('p'))));
 hyph_done();
 tr_done();
 env_done();
 dev_close();
 map_done();
 dir_done();
 return ret;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *fdir = getenv("NEATROFF_F");
 char *mdir = getenv("NEATROFF_M");
 char *dev = getenv("NEATROFF_T");
 char *mac; char *def;
 int reg; int ret;
 int i;
 if (dev == ((void *)0))
  dev = "utf";
 if (fdir == ((void *)0))
  fdir = "/neatroff/font";
 if (mdir == ((void *)0))
  mdir = "/neatroff/tmac";
 for (i = 1; i < argc; i++) {
  if (argv[i][0] != '-' || !argv[i][1])
   break;
  switch (argv[i][1]) {
  case 'C':
   (*nreg(('C'))) = 1;
   break;
  case 'm':
   mac = argv[i] + 2;
   if (strchr(mac, '/') || (cmdmac(mdir, mac) && cmdmac(".", mac)))
    in_queue(mac);
   break;
  case 'r':
   cmddef(argv[i][2] ? argv[i] + 2 : argv[++i], &reg, &def);
   num_set(reg, eval_re(def, (*nreg(reg)), 'u'));
   break;
  case 'd':
   cmddef(argv[i][2] ? argv[i] + 2 : argv[++i], &reg, &def);
   str_set(reg, def);
   break;
  case 'F':
   fdir = argv[i][2] ? argv[i] + 2 : argv[++i];
   break;
  case 'M':
   mdir = argv[i][2] ? argv[i] + 2 : argv[++i];
   break;
  case 'T':
   dev = argv[i][2] ? argv[i] + 2 : argv[++i];
   break;
  default:
   fprintf(stderr, "%s", usage);
   return 1;
  }
 }
 if (dev_open(fdir, dev)) {
  fprintf(stderr, "neatroff: cannot open device %s\n", dev);
  return 1;
 }
 hyph_init();
 env_init();
 tr_init();
 if (i == argc)
  in_queue(((void *)0));
 for (; i < argc; i++)
  in_queue(!strcmp("-", argv[i]) ? ((void *)0) : argv[i]);
 out("s%d\n", (*nreg(('s'))));
 out("f%d\n", (*nreg(('f'))));
 ret = render();
 out("V%d\n", (*nreg(('p'))));
 hyph_done();
 tr_done();
 env_done();
 dev_close();
 map_done();
 dir_done();
 return ret;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
fdir
char *

variable_types:
mdir
char *

variable_types:
dev
char *

variable_types:
mac
char *

variable_types:
def
char *

variable_types: reg int

variable_types: ret int

variable_types: i int


map

repo: litcave/neatroff

decompiled_code:
__int64 __fastcall map(_BYTE *a1)
{
__int64 result; // rax
__int64 v3; // rdi
int v4; // eax
int v5; // [rsp+0h] [rbp-Ch]

result = 0LL;
if ( *a1 )
{
if ( *a1 != 46 || (result = (unsigned __int8)a1[1], !(_BYTE)result) || a1[2] )
{
v3 = mapdict;
if ( !mapdict )
{
mapdict = dict_make(0xFFFFFFFFLL, 1LL, 2LL);
v3 = mapdict;
}
v4 = dict_idx(v3, a1);
if ( v4 < 0 )
{
dict_put(mapdict, a1, 0LL);
v4 = dict_idx(mapdict, a1);
if ( v4 > 7935 )
{
v5 = v4;
errdie("neatroff: increase NREGS\n");
v4 = v5;
}
}
result = (unsigned int)(v4 + 256);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int64 result; // rax
__int64 v3; // rdi
int v4; // eax
int v5; // [rsp+0h] [rbp-Ch]

result = 0LL;
if ( *a1 )
{
if ( *a1 != 46 || (result = (unsigned __int8)a1[1], !(_BYTE)result) || a1[2] )
{
v3 = mapdict;
if ( !mapdict )
{
mapdict = dict_make(0xFFFFFFFFLL, 1LL, 2LL);
v3 = mapdict;
}
v4 = dict_idx(v3, a1);
if ( v4 < 0 )
{
dict_put(mapdict, a1, 0LL);
v4 = dict_idx(mapdict, a1);
if ( v4 > 7935 )
{
v5 = v4;
errdie("neatroff: increase NREGS\n");
v4 = v5;
}
}
result = (unsigned int)(v4 + 256);
}
}
return result;
}

original_code:
int map(char *s)
{
 int i;
 if (!s[0])
  return 0;
 if (s[0] == '.' && s[1] && !s[2])
  return (unsigned char) s[1];
 if (!mapdict)
  mapdict = dict_make(-1, 1, 2);
 i = dict_idx(mapdict, s);
 if (i < 0) {
  dict_put(mapdict, s, 0);
  i = dict_idx(mapdict, s);
  if (256 + i >= 8192)
   errdie("neatroff: increase NREGS\n");
 }
 return 256 + i;
}

variable_types:
s
char *

return_type: int


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

if ( a1 > 255 )
return (char *)dict_key(mapdict, (unsigned int)(a1 - 256));
map_buf_0 = 46;
result = &map_buf_0;
byte_121 = a1;
byte_122 = 0;
return result;
}

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

if ( a1 > 255 )
return (char *)dict_key(mapdict, (unsigned int)(a1 - 256));
map_buf_0 = 46;
result = &map_buf_0;
byte_121 = a1;
byte_122 = 0;
return result;
}

original_code:
char *map_name(int id)
{
 static char map_buf[128];
 if (id >= 256)
  return dict_key(mapdict, id - 256);
 map_buf[0] = '.';
 map_buf[1] = id;
 map_buf[2] = '\0';
 return map_buf;
}

variable_types: id int

return_type: char *


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

if ( mapdict )
result = dict_free();
return result;
}

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

if ( mapdict )
result = dict_free();
return result;
}

original_code:
void map_done(void)
{
 if (mapdict)
  dict_free(mapdict);
}

canonical_original_code:
void map_done()
{
 if (mapdict)
  dict_free(mapdict);
}

return_type: void


original_code:
static int tok_num(char **s, int scale)
{
 while (**s == ' ' || **s == '\t')
  (*s)++;
 return eval_up(s, scale);
}

variable_types:
s
char **

variable_types: scale int


original_code:
static int tok_numpt(char **s, int scale, int *i)
{
 char *o;
 while (**s == ' ' || **s == '\t')
  (*s)++;
 o = *s;
 *i = eval_up(s, scale);
 return o == *s ? 1 : 0;
}

variable_types:
i
int *

variable_types:
o
char *


repo: literalsands/graphics-project-sdl

original_code:
int Line2D_Iteration(int* int_args, float* float_args) {
 if(int_args[0] == int_args[2] && int_args[1] == int_args[3])
  return 0;
 int_args[9] = (int_args[8] << 1);
 if (int_args[9] > int_args[5]) {
  int_args[8] += int_args[5];
  int_args[0] += int_args[6];
 }
 if (int_args[9] < int_args[4]) {
  int_args[8] += int_args[4];
  int_args[1] += int_args[7];
 }
 return 1;
}

canonical_original_code:
int Line2D_Iteration(int *int_args, float *float_args) {
 if(int_args[0] == int_args[2] && int_args[1] == int_args[3])
  return 0;
 int_args[9] = (int_args[8] << 1);
 if (int_args[9] > int_args[5]) {
  int_args[8] += int_args[5];
  int_args[0] += int_args[6];
 }
 if (int_args[9] < int_args[4]) {
  int_args[8] += int_args[4];
  int_args[1] += int_args[7];
 }
 return 1;
}


Iterate

decompiled_code:
__int64 __fastcall Iterate(__int64 a1)
{
return (*(__int64 (__fastcall **)(_QWORD, _QWORD))(a1 + 16))(*(_QWORD *)a1, *(_QWORD *)(a1 + 8));
}

original_code:
int Iterate(Iterator* iterator) {
 return iterator->iteration_function(iterator->int_args, iterator->float_args);
}

canonical_original_code:
int Iterate(struct _Iterator *iterator) {
 return iterator->iteration_function(iterator->int_args, iterator->float_args);
}

variable_types: struct _Iterator { int *int_args; float *float_args; int (*iteration_function)(int *, float *); } *


decompiled_code:
void __fastcall Delete_Iterator(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void Delete_Iterator(Iterator* del) {
 free(del->int_args);
 free(del->float_args);
 free(del);
}

canonical_original_code:
void Delete_Iterator(struct _Iterator *del) {
 free(del->int_args);
 free(del->float_args);
 free(del);
}

user_defined_types: struct _Iterator { int *int_args; float *float_args; int (*iteration_function)(int *, float *); }


variable_types: sx float

variable_types: sy float


decompiled_code:
void __fastcall RotateTransformMatrix2D(float *a1, float a2)
{
float v2; // xmm0_4
float v3; // xmm1_4
float v4; // xmm6_4
float v5; // xmm4_4
float v6; // xmm2_4
float v7; // xmm5_4
float v8; // xmm8_4
float v9; // xmm7_4
float v10; // xmm9_4
float v11; // xmm3_4
float v12; // xmm6_4
float v13; // xmm5_4
float cosx; // [rsp+8h] [rbp-10h] BYREF
float sinx[3]; // [rsp+Ch] [rbp-Ch] BYREF

sincosf(a2, sinx, &cosx);
v2 = sinx[0];
v3 = cosx;
v4 = a1[1];
LODWORD(v5) = LODWORD(sinx[0]) ^ LC0;
v6 = a1[3];
v7 = a1[4];
v8 = a1[6];
v9 = a1[7];
v10 = (float)(cosx * *a1) + (float)(COERCE_FLOAT(LODWORD(sinx[0]) ^ LC0) * v4);
v11 = (float)(*a1 * sinx[0]) + (float)(v4 * cosx);
v12 = COERCE_FLOAT(LODWORD(sinx[0]) ^ LC0) * v7;
v13 = v7 * cosx;
*a1 = v10;
a1[1] = v11;
a1[3] = (float)(v3 * v6) + v12;
a1[4] = (float)(v6 * v2) + v13;
a1[6] = (float)(v5 * v9) + (float)(v3 * v8);
a1[7] = (float)(v2 * v8) + (float)(v3 * v9);
}

canonical_decompiled_code:
void __fastcall func2(float *a1, float a2)
{
float v2; // xmm0_4
float v3; // xmm1_4
float v4; // xmm6_4
float v5; // xmm4_4
float v6; // xmm2_4
float v7; // xmm5_4
float v8; // xmm8_4
float v9; // xmm7_4
float v10; // xmm9_4
float v11; // xmm3_4
float v12; // xmm6_4
float v13; // xmm5_4
float cosx; // [rsp+8h] [rbp-10h] BYREF
float sinx[3]; // [rsp+Ch] [rbp-Ch] BYREF

sincosf(a2, sinx, &cosx);
v2 = sinx[0];
v3 = cosx;
v4 = a1[1];
LODWORD(v5) = LODWORD(sinx[0]) ^ LC0;
v6 = a1[3];
v7 = a1[4];
v8 = a1[6];
v9 = a1[7];
v10 = (float)(cosx * *a1) + (float)(COERCE_FLOAT(LODWORD(sinx[0]) ^ LC0) * v4);
v11 = (float)(*a1 * sinx[0]) + (float)(v4 * cosx);
v12 = COERCE_FLOAT(LODWORD(sinx[0]) ^ LC0) * v7;
v13 = v7 * cosx;
*a1 = v10;
a1[1] = v11;
a1[3] = (float)(v3 * v6) + v12;
a1[4] = (float)(v6 * v2) + v13;
a1[6] = (float)(v5 * v9) + (float)(v3 * v8);
a1[7] = (float)(v2 * v8) + (float)(v3 * v9);
}

variable_types: t float

variable_types: ct float

variable_types: st float

variable_types: zz float

variable_types: zw float

variable_types: wz float

variable_types: ww float

variable_types: tz float

variable_types: tw float


decompiled_code:
void __fastcall Point2DTransformation(float *a1, float *a2)
{
float v2; // [rsp+0h] [rbp-20h]
float v3; // [rsp+4h] [rbp-1Ch]

v3 = (float)(int)*a1;
v2 = (float)(int)a1[1];
*a1 = roundf((float)((float)(v3 * *a2) + (float)(v2 * a2[3])) + a2[6]);
a1[1] = roundf((float)((float)(v3 * a2[1]) + (float)(v2 * a2[4])) + a2[7]);
}

canonical_decompiled_code:
void __fastcall func3(float *a1, float *a2)
{
float v2; // [rsp+0h] [rbp-20h]
float v3; // [rsp+4h] [rbp-1Ch]

v3 = (float)(int)*a1;
v2 = (float)(int)a1[1];
*a1 = roundf((float)((float)(v3 * *a2) + (float)(v2 * a2[3])) + a2[6]);
a1[1] = roundf((float)((float)(v3 * a2[1]) + (float)(v2 * a2[4])) + a2[7]);
}

variable_types:
line
float (*)[2]

variable_types: z int

variable_types: w int


whereFree

repo: liuch/tags

decompiled_code:
void __fastcall whereFree(void *ptr)
{
__int64 *v2; // rbp
__int64 v3; // rax
__int64 *v4; // rbx
__int64 v5; // rdi

v2 = (__int64 *)*((_QWORD *)ptr + 1);
if ( v2 )
{
v3 = *((unsigned int *)ptr + 1);
if ( (_DWORD)v3 )
{
v4 = &v2[v3];
do
{
v5 = *v2++;
propFree(v5);
}
while ( v2 != v4 );
v2 = (__int64 *)*((_QWORD *)ptr + 1);
}
free(v2);
}
free(ptr);
}

original_code:
void whereFree(struct WhereStruct *whr)
{
 struct PropertyStruct **pCond = whr->conditions;
 if (pCond != ((void *)0))
 {
  unsigned int cnt = whr->condCount;
  for ( ; cnt != 0; --cnt)
   propFree(*pCond++);
  free(whr->conditions);
 }
 free(whr);
}

variable_types: struct WhereStruct { unsigned int condMax; unsigned int condCount; struct PropertyStruct { unsigned int maxSize; unsigned int curSize; unsigned int blkCount; unsigned int valuesOffset; unsigned int valCount; struct SubvalHandle { unsigned int subvalSize; enum SubvalStatus { NotUsed=0, Used=1 } subvalStatus; unsigned int userData; } **arrayDirect; struct SubvalHandle **arrayByValue; struct SubvalHandle **arrayByUser; unsigned int userData; } **conditions; } *

variable_types:
cnt
unsigned int

user_defined_types: struct WhereStruct { unsigned int condMax; unsigned int condCount; struct PropertyStruct **conditions; }

user_defined_types: struct PropertyStruct { unsigned int maxSize; unsigned int curSize; unsigned int blkCount; unsigned int valuesOffset; unsigned int valCount; struct SubvalHandle **arrayDirect; struct SubvalHandle **arrayByValue; struct SubvalHandle **arrayByUser; unsigned int userData; }

user_defined_types: struct SubvalHandle { unsigned int subvalSize; enum SubvalStatus subvalStatus; unsigned int userData; }


whereIsFiltered

decompiled_code:
__int64 __fastcall whereIsFiltered(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v4; // rbx
__int64 v5; // r15
__int64 v6; // rax
__int64 *v7; // rax
__int64 v8; // rbp
__int64 *v10; // r12
__int64 v11; // rax
__int64 *v12; // r15
__int64 v13; // rdi
__int64 v14; // rax
__int64 v15; // [rsp+8h] [rbp-40h]

v2 = *(unsigned int *)(a1 + 4);
if ( (_DWORD)v2 )
{
v4 = 0LL;
v15 = 8 * v2;
do
{
while ( 1 )
{
v5 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + v4);
v6 = propGetName(v5);
v7 = (__int64 *)itemGetPropertyPosByName(a2, v6);
if ( v7 )
break;
if ( !(unsigned int)propIsEmpty(v5) || *(_DWORD *)(v5 + 48) )
return 1LL;
LABEL_10:
v4 += 8LL;
if ( v4 == v15 )
return 0LL;
}
v8 = *v7;
if ( (unsigned int)propIsEmpty(v5) )
{
if ( !(unsigned int)propIsEmpty(v8) && !*(_DWORD *)(v5 + 48) )
return 1LL;
goto LABEL_10;
}
v10 = (__int64 *)propGetValueIndex(v5, 0LL);
v11 = *(unsigned int *)(v5 + 16);
if ( !(_DWORD)v11 )
return 1LL;
v12 = &v10[v11];
while ( 1 )
{
v13 = *v10++;
v14 = subvalString(v13);
if ( propIsSubval(v8, v14) )
break;
if ( v12 == v10 )
return 1LL;
}
v4 += 8LL;
}
while ( v4 != v15 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v4; // rbx
__int64 v5; // r15
__int64 v6; // rax
__int64 *v7; // rax
__int64 v8; // rbp
__int64 *v10; // r12
__int64 v11; // rax
__int64 *v12; // r15
__int64 v13; // rdi
__int64 v14; // rax
__int64 v15; // [rsp+8h] [rbp-40h]

v2 = *(unsigned int *)(a1 + 4);
if ( (_DWORD)v2 )
{
v4 = 0LL;
v15 = 8 * v2;
do
{
while ( 1 )
{
v5 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + v4);
v6 = propGetName(v5);
v7 = (__int64 *)itemGetPropertyPosByName(a2, v6);
if ( v7 )
break;
if ( !(unsigned int)propIsEmpty(v5) || *(_DWORD *)(v5 + 48) )
return 1LL;
LABEL_10:
v4 += 8LL;
if ( v4 == v15 )
return 0LL;
}
v8 = *v7;
if ( (unsigned int)propIsEmpty(v5) )
{
if ( !(unsigned int)propIsEmpty(v8) && !*(_DWORD *)(v5 + 48) )
return 1LL;
goto LABEL_10;
}
v10 = (__int64 *)propGetValueIndex(v5, 0LL);
v11 = *(unsigned int *)(v5 + 16);
if ( !(_DWORD)v11 )
return 1LL;
v12 = &v10[v11];
while ( 1 )
{
v13 = *v10++;
v14 = subvalString(v13);
if ( propIsSubval(v8, v14) )
break;
if ( v12 == v10 )
return 1LL;
}
v4 += 8LL;
}
while ( v4 != v15 );
}
return 0LL;
}

original_code:
int whereIsFiltered(const struct WhereStruct *whr, struct ItemStruct *item)
{
 unsigned int whrIdx = 0;
 unsigned int whrCnt = whr->condCount;
 for ( ; whrIdx < whrCnt; ++whrIdx)
 {
  struct PropertyStruct *cond = whr->conditions[whrIdx];
  struct PropertyStruct **pItemProp = itemGetPropertyPosByName(item, propGetName(cond));
  if (pItemProp == ((void *)0))
  {
   if (!propIsEmpty(cond) || cond->userData)
    return 1;
  }
  else
  {
   struct PropertyStruct *itemProp = *pItemProp;
   if (propIsEmpty(cond))
   {
    if (propIsEmpty(itemProp) || cond->userData)
     continue;
    return 1;
   }
   struct SubvalHandle **condArray = propGetValueIndex(cond, None);
   unsigned int cnt = cond->valCount;
   unsigned int i;
   for (i = 0; ; ++i)
   {
    if (i == cnt)
     return 1;
    struct SubvalHandle *sub = *condArray++;
    if (propIsSubval(itemProp, subvalString(sub)))
     break;
   }
  }
 }
 return 0;
}

canonical_original_code:
int whereIsFiltered(struct WhereStruct *whr, struct ItemStruct *item)
{
 unsigned int whrIdx = 0;
 unsigned int whrCnt = whr->condCount;
 for ( ; whrIdx < whrCnt; ++whrIdx)
 {
  struct PropertyStruct *cond = whr->conditions[whrIdx];
  struct PropertyStruct **pItemProp = itemGetPropertyPosByName(item, propGetName(cond));
  if (pItemProp == ((void *)0))
  {
   if (!propIsEmpty(cond) || cond->userData)
    return 1;
  }
  else
  {
   struct PropertyStruct *itemProp = *pItemProp;
   if (propIsEmpty(cond))
   {
    if (propIsEmpty(itemProp) || cond->userData)
     continue;
    return 1;
   }
   struct SubvalHandle **condArray = propGetValueIndex(cond, None);
   unsigned int cnt = cond->valCount;
   unsigned int i;
   for (i = 0; ; ++i)
   {
    if (i == cnt)
     return 1;
    struct SubvalHandle *sub = *condArray++;
    if (propIsSubval(itemProp, subvalString(sub)))
     break;
   }
  }
 }
 return 0;
}

variable_types: struct ItemStruct { unsigned long fileSize; int hash[-1]; unsigned int fileNameMax; unsigned int fileNameCount; int **fileNames; unsigned int propsMax; unsigned int propsCount; struct PropertyStruct **props; } *

variable_types:
whrIdx
unsigned int

variable_types:
whrCnt
unsigned int

variable_types: struct PropertyStruct { unsigned int maxSize; unsigned int curSize; unsigned int blkCount; unsigned int valuesOffset; unsigned int valCount; struct SubvalHandle { unsigned int subvalSize; enum SubvalStatus { NotUsed=0, Used=1 } subvalStatus; unsigned int userData; } **arrayDirect; struct SubvalHandle **arrayByValue; struct SubvalHandle **arrayByUser; unsigned int userData; } **

variable_types:
i
unsigned int


whereInsertConditions

decompiled_code:
__int64 __fastcall whereInsertConditions(void **a1, __int64 a2)
{
__int64 v2; // rbp
unsigned int v3; // eax
__int64 result; // rax
char *v5; // rax
char *v6; // rcx

v2 = *(unsigned int *)a1;
v3 = *((_DWORD *)a1 + 1);
if ( (_DWORD)v2 == v3 )
{
if ( (_DWORD)v2 )
v5 = (char *)realloc(a1[1], 8LL * (unsigned int)(v2 + 10));
else
v5 = (char *)malloc(0x50uLL);
if ( v5 )
{
v6 = &v5[8 * v2];
*((_QWORD *)v6 + 9) = 0LL;
*(_QWORD *)v6 = a2;
*(_OWORD *)(v6 + 8) = 0LL;
*(_OWORD *)(v6 + 24) = 0LL;
*(_OWORD *)(v6 + 40) = 0LL;
*(_OWORD *)(v6 + 56) = 0LL;
a1[1] = v5;
result = 0LL;
*(_DWORD *)a1 += 10;
++*((_DWORD *)a1 + 1);
}
else
{
result = 1LL;
}
}
else
{
*((_QWORD *)a1[1] + v3) = a2;
*((_DWORD *)a1 + 1) = v3 + 1;
result = 0LL;
}
return result;
}

original_code:
int whereInsertConditions(struct WhereStruct *whr, struct PropertyStruct *prop)
{
 unsigned int max = whr->condMax;
 unsigned int cnt = whr->condCount;
 if (cnt == max)
 {
  struct PropertyStruct **newPtr;
  if (max == 0)
   newPtr = malloc(sizeof(struct PropertyStruct *) * 10);
  else
   newPtr = realloc(whr->conditions, sizeof(struct PropertyStruct *) * (max + 10));
  if (newPtr == ((void *)0))
   return 1;
  bzero(&newPtr[max], sizeof(struct PropertyStruct *) * 10);
  newPtr[max] = prop;
  whr->conditions = newPtr;
  whr->condMax += 10;
  ++whr->condCount;
  return 0;
 }
 whr->conditions[cnt] = prop;
 ++whr->condCount;
 return 0;
}

variable_types:
prop
struct PropertyStruct *

variable_types:
max
unsigned int


whereSetConditions

decompiled_code:
__int64 __fastcall whereSetConditions(void **a1, __int64 a2, __int64 a3, int a4)
{
__int64 v5; // rbp
__int64 result; // rax

v5 = propInit(a2, a3);
result = 1LL;
if ( v5 )
{
*(_DWORD *)(v5 + 48) = a4;
result = whereInsertConditions(a1, v5);
if ( (_DWORD)result )
{
propFree(v5);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void **a1, __int64 a2, __int64 a3, int a4)
{
__int64 v5; // rbp
__int64 result; // rax

v5 = propInit(a2, a3);
result = 1LL;
if ( v5 )
{
*(_DWORD *)(v5 + 48) = a4;
result = func2(a1, v5);
if ( (_DWORD)result )
{
propFree(v5);
result = 1LL;
}
}
return result;
}

original_code:
int whereSetConditions(struct WhereStruct *whr, const wchar_t *name, const wchar_t *value, unsigned int data)
{
 struct PropertyStruct *prop = propInit(name, value);
 if (prop == ((void *)0))
  return 1;
 prop->userData = data;
 if (whereInsertConditions(whr, prop) == 0)
  return 0;
 propFree(prop);
 return 1;
}

canonical_original_code:
int whereSetConditions(struct WhereStruct *whr, int *name, int *value, unsigned int data)
{
 struct PropertyStruct *prop = propInit(name, value);
 if (prop == ((void *)0))
  return 1;
 prop->userData = data;
 if (whereInsertConditions(whr, prop) == 0)
  return 0;
 propFree(prop);
 return 1;
}

variable_types:
name
int *

variable_types:
value
int *

variable_types:
data
unsigned int

variable_types: struct PropertyStruct { unsigned int maxSize; unsigned int curSize; unsigned int blkCount; unsigned int valuesOffset; unsigned int valCount; struct SubvalHandle { unsigned int subvalSize; enum SubvalStatus { NotUsed=0, Used=1 } subvalStatus; unsigned int userData; } **arrayDirect; struct SubvalHandle **arrayByValue; struct SubvalHandle **arrayByUser; unsigned int userData; } *


whereSetConditionsRaw

decompiled_code:
__int64 __fastcall whereSetConditionsRaw(void **a1, const wchar_t *a2)
{
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rdx
__int64 v6; // rbx
int v7; // ecx
wchar_t *v8; // rdx
wchar_t *v9; // r12
wchar_t *v10; // rax
wchar_t *v11; // r13
__int64 result; // rax
__int64 v13; // rdx
__int64 v14; // rbx
wchar_t v15[2048]; // [rsp+0h] [rbp-4028h] BYREF
wchar_t dest[2058]; // [rsp+2000h] [rbp-2028h] BYREF

while ( 1 )
{
v9 = wcschr(a2, 61);
v10 = wcschr(a2, 64);
v11 = v10;
if ( !v10 )
break;
if ( v9 && v9 < v10 )
{
v3 = v9 - a2;
if ( (unsigned int)(v3 - 1) > 0x7FE )
return 1LL;
}
else
{
v3 = v10 - a2;
if ( (unsigned int)(v3 - 1) > 0x7FE )
return 1LL;
}
v4 = (unsigned int)v3;
wcsncpy(v15, a2, (unsigned int)v3);
v15[v4] = 0;
if ( v9 && v9 <= v11 )
{
v5 = v11 - (v9 + 1);
if ( (unsigned int)v5 > 0x7FF )
return 1LL;
v6 = (unsigned int)v5;
if ( (_DWORD)v5 )
wcsncpy(dest, v9 + 1, (unsigned int)v5);
dest[v6] = 0;
v7 = 0;
v8 = dest;
}
else
{
v7 = 1;
v8 = 0LL;
}
if ( !(unsigned int)whereSetConditions(a1, (__int64)v15, (__int64)v8, v7) )
{
a2 = v11 + 1;
if ( v11[1] )
continue;
}
return 1LL;
}
if ( !v9 )
return whereSetConditions(a1, (__int64)a2, 0LL, 1);
result = 1LL;
v13 = v9 - a2;
if ( (unsigned int)(v13 - 1) <= 0x7FE )
{
v14 = (unsigned int)v13;
wcsncpy(dest, a2, (unsigned int)v13);
dest[v14] = 0;
result = whereSetConditions(a1, (__int64)dest, (__int64)(v9 + 1), 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(void **a1, const wchar_t *a2)
{
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rdx
__int64 v6; // rbx
int v7; // ecx
wchar_t *v8; // rdx
wchar_t *v9; // r12
wchar_t *v10; // rax
wchar_t *v11; // r13
__int64 result; // rax
__int64 v13; // rdx
__int64 v14; // rbx
wchar_t v15[2048]; // [rsp+0h] [rbp-4028h] BYREF
wchar_t dest[2058]; // [rsp+2000h] [rbp-2028h] BYREF

while ( 1 )
{
v9 = wcschr(a2, 61);
v10 = wcschr(a2, 64);
v11 = v10;
if ( !v10 )
break;
if ( v9 && v9 < v10 )
{
v3 = v9 - a2;
if ( (unsigned int)(v3 - 1) > 0x7FE )
return 1LL;
}
else
{
v3 = v10 - a2;
if ( (unsigned int)(v3 - 1) > 0x7FE )
return 1LL;
}
v4 = (unsigned int)v3;
wcsncpy(v15, a2, (unsigned int)v3);
v15[v4] = 0;
if ( v9 && v9 <= v11 )
{
v5 = v11 - (v9 + 1);
if ( (unsigned int)v5 > 0x7FF )
return 1LL;
v6 = (unsigned int)v5;
if ( (_DWORD)v5 )
wcsncpy(dest, v9 + 1, (unsigned int)v5);
dest[v6] = 0;
v7 = 0;
v8 = dest;
}
else
{
v7 = 1;
v8 = 0LL;
}
if ( !(unsigned int)func3(a1, (__int64)v15, (__int64)v8, v7) )
{
a2 = v11 + 1;
if ( v11[1] )
continue;
}
return 1LL;
}
if ( !v9 )
return func3(a1, (__int64)a2, 0LL, 1);
result = 1LL;
v13 = v9 - a2;
if ( (unsigned int)(v13 - 1) <= 0x7FE )
{
v14 = (unsigned int)v13;
wcsncpy(dest, a2, (unsigned int)v13);
dest[v14] = 0;
result = func3(a1, (__int64)dest, (__int64)(v9 + 1), 0);
}
return result;
}

original_code:
int whereSetConditionsRaw(struct WhereStruct *whr, const wchar_t *whereStr)
{
 const wchar_t *curStrPos = whereStr;
 do
 {
  const wchar_t *startVal = wcschr(curStrPos, L'=');
  const wchar_t *endVal = wcschr(curStrPos, L'@');
  if (endVal == ((void *)0))
  {
   if (startVal != ((void *)0))
   {
    unsigned int nameLen = startVal - curStrPos;
    wchar_t name[2048];
    if (nameLen == 0 || nameLen >= sizeof(name) / sizeof(wchar_t))
     return 1;
    ++startVal;
    wcsncpy(name, curStrPos, nameLen);
    name[nameLen] = L'\0';
    return whereSetConditions(whr, name, startVal, 0);
   }
   return whereSetConditions(whr, curStrPos, ((void *)0), 1);
  }
  unsigned int nameLen;
  if (startVal != ((void *)0) && startVal < endVal)
   nameLen = startVal - curStrPos;
  else
   nameLen = endVal - curStrPos;
  wchar_t name[2048];
  if (nameLen == 0 || nameLen >= sizeof(name) / sizeof(wchar_t))
   return 1;
  wcsncpy(name, curStrPos, nameLen);
  name[nameLen] = L'\0';
  if (startVal == ((void *)0) || startVal > endVal)
  {
   if (whereSetConditions(whr, name, ((void *)0), 1) != 0)
    return 1;
  }
  else
  {
   ++startVal;
   wchar_t val[2048];
   unsigned int valLen = endVal - startVal;
   if (valLen >= sizeof(val) / sizeof(wchar_t))
    return 1;
   if (valLen != 0)
    wcsncpy(val, startVal, valLen);
   val[valLen] = L'\0';
   if (whereSetConditions(whr, name, val, 0) != 0)
    return 1;
  }
  if (endVal == ((void *)0))
   return (whr->condCount == 0) ? 1 : 0;
  curStrPos = endVal + 1;
 } while (*curStrPos != L'\0');
 return 1;
}

canonical_original_code:
int whereSetConditionsRaw(struct WhereStruct *whr, int *whereStr)
{
 int *curStrPos = whereStr;
 do
 {
  int *startVal = wcschr(curStrPos, L'=');
  int *endVal = wcschr(curStrPos, L'@');
  if (endVal == ((void *)0))
  {
   if (startVal != ((void *)0))
   {
    unsigned int nameLen = startVal - curStrPos;
    int name[2048];
    if (nameLen == 0 || nameLen >= sizeof(name) / sizeof(wchar_t))
     return 1;
    ++startVal;
    wcsncpy(name, curStrPos, nameLen);
    name[nameLen] = L'\0';
    return whereSetConditions(whr, name, startVal, 0);
   }
   return whereSetConditions(whr, curStrPos, ((void *)0), 1);
  }
  unsigned int nameLen;
  if (startVal != ((void *)0) && startVal < endVal)
   nameLen = startVal - curStrPos;
  else
   nameLen = endVal - curStrPos;
  int name[2048];
  if (nameLen == 0 || nameLen >= sizeof(name) / sizeof(wchar_t))
   return 1;
  wcsncpy(name, curStrPos, nameLen);
  name[nameLen] = L'\0';
  if (startVal == ((void *)0) || startVal > endVal)
  {
   if (whereSetConditions(whr, name, ((void *)0), 1) != 0)
    return 1;
  }
  else
  {
   ++startVal;
   int val[2048];
   unsigned int valLen = endVal - startVal;
   if (valLen >= sizeof(val) / sizeof(wchar_t))
    return 1;
   if (valLen != 0)
    wcsncpy(val, startVal, valLen);
   val[valLen] = L'\0';
   if (whereSetConditions(whr, name, val, 0) != 0)
    return 1;
  }
  if (endVal == ((void *)0))
   return (whr->condCount == 0) ? 1 : 0;
  curStrPos = endVal + 1;
 } while (*curStrPos != L'\0');
 return 1;
}

variable_types:
whereStr
int *

variable_types:
curStrPos
int *

variable_types:
startVal
int *

variable_types:
endVal
int *

variable_types:
nameLen
unsigned int

variable_types:
name
int [2048]

variable_types:
val
int [2048]

variable_types:
valLen
unsigned int


showHelp

decompiled_code:
size_t showHelp()
{
return fwrite(
"Usage: tags <keys> [<files>]\n"
"Sets and displays the properties of a file, that stored in a special index file in the same folder.\n"
"The program does not modify any files except its index file!\n"
"\n"
"Keys:\n"
" -a, --append-value APPEND_LIST\n"
" adds the value of the parameters for the specified files\n"
" -c, --create-index\n"
" creates empty index file in the current directory and exit.\n"
" The index file is created only if it is not present\n"
" -d, --remove-value DELETE_LIST\n"
" removes information about the specified files, their parameters or\n"
" the individual values of parameters from the index\n"
" -f, --fields-list FIELDS_LIST\n"
" fields list for -l key\n"
" -h, --help\n"
" show this help\n"
" -i, --file-info\n"
" output short information about the specified files\n"
" -l, --file-list\n"
" displays fields separated by tabs, one line for each file in the index.\n"
" List of fields you specify in the -f key.\n"
" If the -f key is not specified, displayed a list of files\n"
" -p, --value-list\n"
" output summary information about a properties\n"
" -r, --recursive\n"
" the recursive flag. Can be used with -l and -p keys\n"
" -s, --set-value SET_LIST\n"
" sets the parameters and their values for the specified files\n"
" -v, --version\n"
" output version information and exit\n"
" -w, --where WHERE_LIST\n"
" list of a conditions. Use with -a, -s, -d and -l keys\n"
" --move-file OLD_FILE_NAME NEW_FILE_NAME\n"
" change a file name within an index or transfer data to another index.\n"
" OLD_FILE_NAME and NEW_FILE_NAME can contain the path to the index file\n"
" Note: when using the -a, -d, -i and -s keys, you must specify one or more files\n"
" Note: keys -a, -d, and -s can be used simultaneously\n"
"\n"
"APPEND_LIST, DELETE_LIST, SET_LIST specification:\n"
" param_name=[subval,subval,...][@param_name=...]\n"
" <param_name> can contain letters, numbers, and other characters. But it can not contain a '='.\n"
" The characters after the '=' is a list of values separated by commas.\n"
"\n"
"FIELDS_LIST specification:\n"
" field[,field...]\n"
" <field> this is the name of the property or one of the special properties.\n"
" If instead of a list of fields specify '-', will display the internal structure of the index\n"
"\n"
"WHERE_LIST specification:\n"
" see SET_LIST specification\n"
" 'param_name=value1,value2' equivalently 'param_name' contains 'value1' OR 'value2' or both.\n"
" 'param_name=value1@param_name=value2' equivalently 'param_name' contains 'value1' AND 'value2'.\n"
" 'param_name=' means that the parameter is missing or empty\n"
" 'param_name' means that the parameter is defined, including the empty\n"
"\n"
"Special properties:\n"
" '@FileSize' - file size\n"
" '@FileName' - file name\n"
" Note: this is parameters is read only\n"
"\n"
"Examples:\n"
" tags -c\n"
" Creates empty index file in the current directory\n"
" tags -s type=photo@format=jpg *.jpg\n"
" Assigns a parameter of 'type' value 'photo' and a parameter of 'format' value 'jpg' for\n"
" all files with the extension jpg. If the file is not in the index, it is added.\n"
" tags -a tag=pets -w tag=dog,cat@type=photo *\n"
" Adds to the property 'tag' value 'pet', for files that have this property is the value of 'dog' or 'cat'."
"\n"
" tags -d - temp.jpg\n"
" Deletes all data about the file temp.jpg from the index. The file is not deleted.\n"
" tags -l -f @FileName,@FileSize,tag -w tag=pets\n"
" Displays file name, file size and property 'tag' for files that have property to 'tag' is the value of 'pets'.\n",
1uLL,
0xD8CuLL,
stdout);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite(
"Usage: tags <keys> [<files>]\n"
"Sets and displays the properties of a file, that stored in a special index file in the same folder.\n"
"The program does not modify any files except its index file!\n"
"\n"
"Keys:\n"
" -a, --append-value APPEND_LIST\n"
" adds the value of the parameters for the specified files\n"
" -c, --create-index\n"
" creates empty index file in the current directory and exit.\n"
" The index file is created only if it is not present\n"
" -d, --remove-value DELETE_LIST\n"
" removes information about the specified files, their parameters or\n"
" the individual values of parameters from the index\n"
" -f, --fields-list FIELDS_LIST\n"
" fields list for -l key\n"
" -h, --help\n"
" show this help\n"
" -i, --file-info\n"
" output short information about the specified files\n"
" -l, --file-list\n"
" displays fields separated by tabs, one line for each file in the index.\n"
" List of fields you specify in the -f key.\n"
" If the -f key is not specified, displayed a list of files\n"
" -p, --value-list\n"
" output summary information about a properties\n"
" -r, --recursive\n"
" the recursive flag. Can be used with -l and -p keys\n"
" -s, --set-value SET_LIST\n"
" sets the parameters and their values for the specified files\n"
" -v, --version\n"
" output version information and exit\n"
" -w, --where WHERE_LIST\n"
" list of a conditions. Use with -a, -s, -d and -l keys\n"
" --move-file OLD_FILE_NAME NEW_FILE_NAME\n"
" change a file name within an index or transfer data to another index.\n"
" OLD_FILE_NAME and NEW_FILE_NAME can contain the path to the index file\n"
" Note: when using the -a, -d, -i and -s keys, you must specify one or more files\n"
" Note: keys -a, -d, and -s can be used simultaneously\n"
"\n"
"APPEND_LIST, DELETE_LIST, SET_LIST specification:\n"
" param_name=[subval,subval,...][@param_name=...]\n"
" <param_name> can contain letters, numbers, and other characters. But it can not contain a '='.\n"
" The characters after the '=' is a list of values separated by commas.\n"
"\n"
"FIELDS_LIST specification:\n"
" field[,field...]\n"
" <field> this is the name of the property or one of the special properties.\n"
" If instead of a list of fields specify '-', will display the internal structure of the index\n"
"\n"
"WHERE_LIST specification:\n"
" see SET_LIST specification\n"
" 'param_name=value1,value2' equivalently 'param_name' contains 'value1' OR 'value2' or both.\n"
" 'param_name=value1@param_name=value2' equivalently 'param_name' contains 'value1' AND 'value2'.\n"
" 'param_name=' means that the parameter is missing or empty\n"
" 'param_name' means that the parameter is defined, including the empty\n"
"\n"
"Special properties:\n"
" '@FileSize' - file size\n"
" '@FileName' - file name\n"
" Note: this is parameters is read only\n"
"\n"
"Examples:\n"
" tags -c\n"
" Creates empty index file in the current directory\n"
" tags -s type=photo@format=jpg *.jpg\n"
" Assigns a parameter of 'type' value 'photo' and a parameter of 'format' value 'jpg' for\n"
" all files with the extension jpg. If the file is not in the index, it is added.\n"
" tags -a tag=pets -w tag=dog,cat@type=photo *\n"
" Adds to the property 'tag' value 'pet', for files that have this property is the value of 'dog' or 'cat'."
"\n"
" tags -d - temp.jpg\n"
" Deletes all data about the file temp.jpg from the index. The file is not deleted.\n"
" tags -l -f @FileName,@FileSize,tag -w tag=pets\n"
" Displays file name, file size and property 'tag' for files that have property to 'tag' is the value of 'pets'.\n",
1uLL,
0xD8CuLL,
stdout);
}

original_code:
void showHelp()
{
 fputs("Usage: tags <keys> [<files>]\n"
  "Sets and displays the properties of a file, that stored in a special index file in the same folder.\n"
  "The program does not modify any files except its index file!\n"
  "\nKeys:\n"
  "  -a, --append-value APPEND_LIST\n"
  "          adds the value of the parameters for the specified files\n"
  "  -c, --create-index\n"
  "          creates empty index file in the current directory and exit.\n"
  "          The index file is created only if it is not present\n"
  "  -d, --remove-value DELETE_LIST\n"
  "          removes information about the specified files, their parameters or\n"
  "          the individual values of parameters from the index\n"
  "  -f, --fields-list FIELDS_LIST\n"
  "          fields list for -l key\n"
  "  -h, --help\n"
  "          show this help\n"
  "  -i, --file-info\n"
  "          output short information about the specified files\n"
  "  -l, --file-list\n"
  "          displays fields separated by tabs, one line for each file in the index.\n"
  "          List of fields you specify in the -f key.\n"
  "          If the -f key is not specified, displayed a list of files\n"
  "  -p, --value-list\n"
  "          output summary information about a properties\n"
  "  -r, --recursive\n"
  "          the recursive flag. Can be used with -l and -p keys\n"
  "  -s, --set-value SET_LIST\n"
  "          sets the parameters and their values for the specified files\n"
  "  -v, --version\n"
  "          output version information and exit\n"
  "  -w, --where WHERE_LIST\n"
  "          list of a conditions. Use with -a, -s, -d and -l keys\n"
  "  --move-file OLD_FILE_NAME NEW_FILE_NAME\n"
  "          change a file name within an index or transfer data to another index.\n"
  "          OLD_FILE_NAME and NEW_FILE_NAME can contain the path to the index file\n"
  "  Note: when using the -a, -d, -i and -s keys, you must specify one or more files\n"
  "  Note: keys -a, -d, and -s can be used simultaneously\n"
  "\nAPPEND_LIST, DELETE_LIST, SET_LIST specification:\n"
  "  param_name=[subval,subval,...][@param_name=...]\n"
  "  <param_name> can contain letters, numbers, and other characters. But it can not contain a '='.\n"
  "  The characters after the '=' is a list of values separated by commas.\n"
  "\nFIELDS_LIST specification:\n"
  "  field[,field...]\n"
  "  <field> this is the name of the property or one of the special properties.\n"
  "  If instead of a list of fields specify '-', will display the internal structure of the index\n"
  "\nWHERE_LIST specification:\n"
  "  see SET_LIST specification\n"
  "  'param_name=value1,value2' equivalently 'param_name' contains 'value1' OR 'value2' or both.\n"
  "  'param_name=value1@param_name=value2' equivalently 'param_name' contains 'value1' AND 'value2'.\n"
  "  'param_name=' means that the parameter is missing or empty\n"
  "  'param_name'  means that the parameter is defined, including the empty\n"
  "\nSpecial properties:\n"
  "  '@FileSize' - file size\n"
  "  '@FileName' - file name\n"
  "  Note: this is parameters is read only\n"
  "\nExamples:\n"
  "  tags -c\n"
  "    Creates empty index file in the current directory\n"
  "  tags -s type=photo@format=jpg *.jpg\n"
  "    Assigns a parameter of 'type' value 'photo' and a parameter of 'format' value 'jpg' for\n"
  "    all files with the extension jpg. If the file is not in the index, it is added.\n"
  "  tags -a tag=pets -w tag=dog,cat@type=photo *\n"
  "    Adds to the property 'tag' value 'pet', for files that have this property is the value of 'dog' or 'cat'.\n"
  "  tags -d - temp.jpg\n"
  "    Deletes all data about the file temp.jpg from the index. The file is not deleted.\n"
  "  tags -l -f @FileName,@FileSize,tag -w tag=pets\n"
  "    Displays file name, file size and property 'tag' for files that have property to 'tag' is the value of 'pets'.\n"
  , stdout);
}


showVersion

decompiled_code:
size_t showVersion()
{
return fwrite("Tags 0.0.1\n", 1uLL, 0xBuLL, stdout);
}

canonical_decompiled_code:
size_t func1()
{
return fwrite("Tags 0.0.1\n", 1uLL, 0xBuLL, stdout);
}

original_code:
void showVersion()
{
 fputs("Tags " "0.0.1" "\n", stdout);
}


showWarning

decompiled_code:
size_t __fastcall showWarning(int a1)
{
if ( a1 == 1 )
{
fwrite("Invalid combination of options\n", 1uLL, 0x1FuLL, stderr);
}
else if ( a1 == 2 )
{
fwrite("List of files is not specified\n", 1uLL, 0x1FuLL, stderr);
}
return fwrite("Run `tags -h` for get help.\n", 1uLL, 0x1CuLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func2(int a1)
{
if ( a1 == 1 )
{
fwrite("Invalid combination of options\n", 1uLL, 0x1FuLL, stderr);
}
else if ( a1 == 2 )
{
fwrite("List of files is not specified\n", 1uLL, 0x1FuLL, stderr);
}
return fwrite("Run `tags -h` for get help.\n", 1uLL, 0x1CuLL, stderr);
}

original_code:
void showWarning(enum WarnMode mode)
{
 switch (mode)
 {
  case WarnOptions:
   fputs("Invalid combination of options\n", stderr);
   break;
  case WarnFiles:
   fputs("List of files is not specified\n", stderr);
   break;
  default:
   ;
 }
 fputs("Run `tags -h` for get help.\n", stderr);
}

variable_types: enum WarnMode { WarnNone=0, WarnOptions=1, WarnFiles=2, WarnOther=3 }


freeResources

decompiled_code:
void freeResources()
{
if ( addOptArg )
free(addOptArg);
if ( delOptArg )
free(delOptArg);
if ( setOptArg )
free(setOptArg);
if ( whrOptArg )
free(whrOptArg);
if ( fieldsList )
free(fieldsList);
}

canonical_decompiled_code:
void func3()
{
if ( addOptArg )
free(addOptArg);
if ( delOptArg )
free(delOptArg);
if ( setOptArg )
free(setOptArg);
if ( whrOptArg )
free(whrOptArg);
if ( fieldsList )
free(fieldsList);
}

original_code:
void freeResources(void)
{
 if (addOptArg != ((void *)0))
  free(addOptArg);
 if (delOptArg != ((void *)0))
  free(delOptArg);
 if (setOptArg != ((void *)0))
  free(setOptArg);
 if (whrOptArg != ((void *)0))
  free(whrOptArg);
 if (fieldsList != ((void *)0))
  free(fieldsList);
}

canonical_original_code:
void freeResources()
{
 if (addOptArg != ((void *)0))
  free(addOptArg);
 if (delOptArg != ((void *)0))
  free(delOptArg);
 if (setOptArg != ((void *)0))
  free(setOptArg);
 if (whrOptArg != ((void *)0))
  free(whrOptArg);
 if (fieldsList != ((void *)0))
  free(fieldsList);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
int v6; // er13
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = argc;
setlocale(6, &locale);
if ( argc == 1 )
{
showWarning(1);
return v3;
}
longind[0] = -1;
flags = 0;
while ( 2 )
{
v4 = getopt_long(argc, (char *const *)argv, "a:cd:f:hilprs:vw:", &long_options, longind);
if ( v4 == -1 )
{
if ( addOptArg || delOptArg || setOptArg )
{
if ( flags )
{
v6 = 1;
}
else
{
v6 = 2;
if ( argc - optind > 0 )
{
v3 = tagsUpdateFileInfo(
&argv[optind],
(unsigned int)(argc - optind),
addOptArg,
delOptArg,
setOptArg,
whrOptArg);
LABEL_24:
freeResources();
return v3;
}
}
}
else
{
v3 = argc - optind;
if ( flags == 2 )
{
v6 = 1;
if ( !v3 && !whrOptArg && !fieldsList )
{
v3 = tagsCreateIndex();
goto LABEL_24;
}
}
else if ( flags == 4 )
{
if ( v3 <= 0 )
{
v6 = 2;
}
else
{
v6 = 1;
if ( !whrOptArg && !fieldsList )
{
v3 = tagsStatus(&argv[optind], (unsigned int)v3);
goto LABEL_24;
}
}
}
else if ( (flags & 8) != 0 )
{
v6 = 1;
if ( !(v3 | flags & 0xFFFFFFD7) )
{
v3 = tagsList(fieldsList, whrOptArg);
goto LABEL_24;
}
}
else if ( (flags & 0x10) != 0 )
{
v6 = 1;
if ( !(v3 | flags & 0xFFFFFFCF) && !whrOptArg && !fieldsList )
{
v3 = tagsShowProps();
goto LABEL_24;
}
}
else
{
v6 = 1;
if ( flags == 64 )
{
if ( !v3 && !whrOptArg && !fieldsList )
{
showVersion();
goto LABEL_24;
}
}
else if ( flags == 128 && v3 == 2 && !whrOptArg && !fieldsList )
{
v3 = moveFile(&argv[optind]);
goto LABEL_24;
}
}
}
freeResources();
v3 = 1;
showWarning(v6);
return v3;
}
switch ( v4 )
{
case 97:
addOptArg = (void *)makeWideCharString(optarg, 0LL);
continue;
case 99:
flags |= 2u;
continue;
case 100:
delOptArg = (void *)makeWideCharString(optarg, 0LL);
continue;
case 102:
fieldsList = (void *)makeWideCharString(optarg, 0LL);
continue;
case 104:
v3 = 0;
showHelp();
break;
case 105:
flags |= 4u;
continue;
case 108:
flags |= 8u;
continue;
case 112:
flags |= 0x10u;
continue;
case 114:
flags |= 0x20u;
continue;
case 115:
setOptArg = (void *)makeWideCharString(optarg, 0LL);
continue;
case 118:
flags |= 0x40u;
continue;
case 119:
whrOptArg = (void *)makeWideCharString(optarg, 0LL);
continue;
case 128:
flags |= 0x80u;
continue;
default:
v3 = 1;
showWarning(3);
break;
}
return v3;
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
int v6; // er13
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = argc;
setlocale(6, &locale);
if ( argc == 1 )
{
func2(1);
return v3;
}
longind[0] = -1;
flags = 0;
while ( 2 )
{
v4 = getopt_long(argc, (char *const *)argv, "a:cd:f:hilprs:vw:", &long_options, longind);
if ( v4 == -1 )
{
if ( addOptArg || delOptArg || setOptArg )
{
if ( flags )
{
v6 = 1;
}
else
{
v6 = 2;
if ( argc - optind > 0 )
{
v3 = tagsUpdateFileInfo(
&argv[optind],
(unsigned int)(argc - optind),
addOptArg,
delOptArg,
setOptArg,
whrOptArg);
LABEL_24:
func3();
return v3;
}
}
}
else
{
v3 = argc - optind;
if ( flags == 2 )
{
v6 = 1;
if ( !v3 && !whrOptArg && !fieldsList )
{
v3 = tagsCreateIndex();
goto LABEL_24;
}
}
else if ( flags == 4 )
{
if ( v3 <= 0 )
{
v6 = 2;
}
else
{
v6 = 1;
if ( !whrOptArg && !fieldsList )
{
v3 = tagsStatus(&argv[optind], (unsigned int)v3);
goto LABEL_24;
}
}
}
else if ( (flags & 8) != 0 )
{
v6 = 1;
if ( !(v3 | flags & 0xFFFFFFD7) )
{
v3 = tagsList(fieldsList, whrOptArg);
goto LABEL_24;
}
}
else if ( (flags & 0x10) != 0 )
{
v6 = 1;
if ( !(v3 | flags & 0xFFFFFFCF) && !whrOptArg && !fieldsList )
{
v3 = tagsShowProps();
goto LABEL_24;
}
}
else
{
v6 = 1;
if ( flags == 64 )
{
if ( !v3 && !whrOptArg && !fieldsList )
{
func1();
goto LABEL_24;
}
}
else if ( flags == 128 && v3 == 2 && !whrOptArg && !fieldsList )
{
v3 = moveFile(&argv[optind]);
goto LABEL_24;
}
}
}
func3();
v3 = 1;
func2(v6);
return v3;
}
switch ( v4 )
{
case 97:
addOptArg = (void *)makeWideCharString(optarg, 0LL);
continue;
case 99:
flags |= 2u;
continue;
case 100:
delOptArg = (void *)makeWideCharString(optarg, 0LL);
continue;
case 102:
fieldsList = (void *)makeWideCharString(optarg, 0LL);
continue;
case 104:
v3 = 0;
func0();
break;
case 105:
flags |= 4u;
continue;
case 108:
flags |= 8u;
continue;
case 112:
flags |= 0x10u;
continue;
case 114:
flags |= 0x20u;
continue;
case 115:
setOptArg = (void *)makeWideCharString(optarg, 0LL);
continue;
case 118:
flags |= 0x40u;
continue;
case 119:
whrOptArg = (void *)makeWideCharString(optarg, 0LL);
continue;
case 128:
flags |= 0x80u;
continue;
default:
v3 = 1;
func2(3);
break;
}
return v3;
}
}

original_code:
int main(int argc, char *argv[])
{
 setlocale(6, "");
 if (argc == 1)
 {
  showWarning(WarnOptions);
  return 1;
 }
 int res = 0;
 int opt, oi = -1;
 flags = NoneFlag;
 while (res == 0 && (opt = getopt_long(argc, argv, "a:cd:f:hilprs:vw:", long_options, &oi)) != -1)
 {
  switch (opt)
  {
   case 'a':
    addOptArg = makeWideCharString(optarg, 0);
    break;
   case 'c':
    flags |= InitFlag;
    break;
   case 'd':
    delOptArg = makeWideCharString(optarg, 0);
    break;
   case 'f':
    fieldsList = makeWideCharString(optarg, 0);
    break;
   case 'h':
    showHelp();
    return 0;
   case 'i':
    flags |= InfoFlag;
    break;
   case 'l':
    flags |= ListFlag;
    break;
   case 'p':
    flags |= PropFlag;
    break;
   case 'r':
    flags |= RecurFlag;
    break;
   case 's':
    setOptArg = makeWideCharString(optarg, 0);
    break;
   case 'v':
    flags |= VersionFlag;
    break;
   case 'w':
    whrOptArg = makeWideCharString(optarg, 0);
    break;
   case MoveFileOption:
    flags |= MoveFileFlag;
    break;
   default:
    showWarning(WarnOther);
    res = 1;
    break;
  }
 }
 if (res != 0)
  return res;
 res = 1;
 enum WarnMode warn = WarnOptions;
 if (addOptArg == ((void *)0) && delOptArg == ((void *)0) && setOptArg == ((void *)0))
 {
  int filesCnt = argc - optind;
  if (flags == InitFlag)
  {
   if (filesCnt == 0 && whrOptArg == ((void *)0) && fieldsList == ((void *)0))
   {
    res = tagsCreateIndex();
    warn = WarnNone;
   }
  }
  else if (flags == InfoFlag)
  {
   if (filesCnt > 0)
   {
    if (whrOptArg == ((void *)0) && fieldsList == ((void *)0))
    {
     res = tagsStatus(&argv[optind], filesCnt);
     warn = WarnNone;
    }
   }
   else
    warn = WarnFiles;
  }
  else if ((flags & ListFlag) != 0)
  {
   if ((flags & ~(ListFlag | RecurFlag)) == 0 && filesCnt == 0)
   {
    res = tagsList(fieldsList, whrOptArg);
    warn = WarnNone;
   }
  }
  else if ((flags & PropFlag) != 0)
  {
   if ((flags & ~(PropFlag | RecurFlag)) == 0 && filesCnt == 0 && whrOptArg == ((void *)0) && fieldsList == ((void *)0))
   {
    res = tagsShowProps();
    warn = WarnNone;
   }
  }
  else if (flags == VersionFlag)
  {
   if (filesCnt == 0 && whrOptArg == ((void *)0) && fieldsList == ((void *)0))
   {
    showVersion();
    res = 0;
    warn = WarnNone;
   }
  }
  else if (flags == MoveFileFlag)
  {
   if (filesCnt == 2 && whrOptArg == ((void *)0) && fieldsList == ((void *)0))
   {
    res = moveFile(&argv[optind]);
    warn = WarnNone;
   }
  }
 }
 else
 {
  if (flags == NoneFlag)
  {
   warn = WarnFiles;
   int filesCnt = argc - optind;
   if (filesCnt > 0)
   {
    res = tagsUpdateFileInfo(&argv[optind], filesCnt, addOptArg, delOptArg, setOptArg, whrOptArg);
    warn = WarnNone;
   }
  }
 }
 freeResources();
 if (warn != WarnNone)
  showWarning(warn);
 return res;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 setlocale(6, "");
 if (argc == 1)
 {
  showWarning(WarnOptions);
  return 1;
 }
 int res = 0;
 int opt; int oi = -1;
 flags = NoneFlag;
 while (res == 0 && (opt = getopt_long(argc, argv, "a:cd:f:hilprs:vw:", long_options, &oi)) != -1)
 {
  switch (opt)
  {
   case 'a':
    addOptArg = makeWideCharString(optarg, 0);
    break;
   case 'c':
    flags |= InitFlag;
    break;
   case 'd':
    delOptArg = makeWideCharString(optarg, 0);
    break;
   case 'f':
    fieldsList = makeWideCharString(optarg, 0);
    break;
   case 'h':
    showHelp();
    return 0;
   case 'i':
    flags |= InfoFlag;
    break;
   case 'l':
    flags |= ListFlag;
    break;
   case 'p':
    flags |= PropFlag;
    break;
   case 'r':
    flags |= RecurFlag;
    break;
   case 's':
    setOptArg = makeWideCharString(optarg, 0);
    break;
   case 'v':
    flags |= VersionFlag;
    break;
   case 'w':
    whrOptArg = makeWideCharString(optarg, 0);
    break;
   case MoveFileOption:
    flags |= MoveFileFlag;
    break;
   default:
    showWarning(WarnOther);
    res = 1;
    break;
  }
 }
 if (res != 0)
  return res;
 res = 1;
 enum WarnMode warn = WarnOptions;
 if (addOptArg == ((void *)0) && delOptArg == ((void *)0) && setOptArg == ((void *)0))
 {
  int filesCnt = argc - optind;
  if (flags == InitFlag)
  {
   if (filesCnt == 0 && whrOptArg == ((void *)0) && fieldsList == ((void *)0))
   {
    res = tagsCreateIndex();
    warn = WarnNone;
   }
  }
  else if (flags == InfoFlag)
  {
   if (filesCnt > 0)
   {
    if (whrOptArg == ((void *)0) && fieldsList == ((void *)0))
    {
     res = tagsStatus(&argv[optind], filesCnt);
     warn = WarnNone;
    }
   }
   else
    warn = WarnFiles;
  }
  else if ((flags & ListFlag) != 0)
  {
   if ((flags & ~(ListFlag | RecurFlag)) == 0 && filesCnt == 0)
   {
    res = tagsList(fieldsList, whrOptArg);
    warn = WarnNone;
   }
  }
  else if ((flags & PropFlag) != 0)
  {
   if ((flags & ~(PropFlag | RecurFlag)) == 0 && filesCnt == 0 && whrOptArg == ((void *)0) && fieldsList == ((void *)0))
   {
    res = tagsShowProps();
    warn = WarnNone;
   }
  }
  else if (flags == VersionFlag)
  {
   if (filesCnt == 0 && whrOptArg == ((void *)0) && fieldsList == ((void *)0))
   {
    showVersion();
    res = 0;
    warn = WarnNone;
   }
  }
  else if (flags == MoveFileFlag)
  {
   if (filesCnt == 2 && whrOptArg == ((void *)0) && fieldsList == ((void *)0))
   {
    res = moveFile(&argv[optind]);
    warn = WarnNone;
   }
  }
 }
 else
 {
  if (flags == NoneFlag)
  {
   warn = WarnFiles;
   int filesCnt = argc - optind;
   if (filesCnt > 0)
   {
    res = tagsUpdateFileInfo(&argv[optind], filesCnt, addOptArg, delOptArg, setOptArg, whrOptArg);
    warn = WarnNone;
   }
  }
 }
 freeResources();
 if (warn != WarnNone)
  showWarning(warn);
 return res;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: res int

variable_types: opt int

variable_types: oi int

variable_types: filesCnt int

user_defined_types: enum WarnMode { WarnNone=0, WarnOptions=1, WarnFiles=2, WarnOther=3 }


fieldsFree

decompiled_code:
void __fastcall fieldsFree(void *ptr)
{
void **v2; // rdi
int v3; // eax
void **v4; // rbx
__int64 v5; // r12
void *v6; // rdi
void *v7; // rdi

v2 = (void **)*((_QWORD *)ptr + 2);
if ( v2 )
{
v3 = *((_DWORD *)ptr + 1);
if ( v3 )
{
v4 = v2;
v5 = (__int64)&v2[(unsigned int)(v3 - 1) + 1];
do
{
v6 = *v4++;
free(v6);
}
while ( v4 != (void **)v5 );
v2 = (void **)*((_QWORD *)ptr + 2);
}
free(v2);
}
v7 = (void *)*((_QWORD *)ptr + 3);
if ( v7 )
free(v7);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void **v2; // rdi
int v3; // eax
void **v4; // rbx
__int64 v5; // r12
void *v6; // rdi
void *v7; // rdi

v2 = (void **)*((_QWORD *)ptr + 2);
if ( v2 )
{
v3 = *((_DWORD *)ptr + 1);
if ( v3 )
{
v4 = v2;
v5 = (__int64)&v2[(unsigned int)(v3 - 1) + 1];
do
{
v6 = *v4++;
free(v6);
}
while ( v4 != (void **)v5 );
v2 = (void **)*((_QWORD *)ptr + 2);
}
free(v2);
}
v7 = (void *)*((_QWORD *)ptr + 3);
if ( v7 )
free(v7);
free(ptr);
}

original_code:
void fieldsFree(struct FieldListStruct* fields)
{
 unsigned int cnt = fields->fieldsCount;
 unsigned int i;
 if (fields->fieldsList != ((void *)0))
 {
  struct FieldStruct **pFld = fields->fieldsList;
  for (i = 0; i < cnt; ++i)
   free(pFld[i]);
  free(fields->fieldsList);
 }
 if (fields->columns != ((void *)0))
  free(fields->columns);
 free(fields);
}

canonical_original_code:
void fieldsFree(struct FieldListStruct *fields)
{
 unsigned int cnt = fields->fieldsCount;
 unsigned int i;
 if (fields->fieldsList != ((void *)0))
 {
  struct FieldStruct **pFld = fields->fieldsList;
  for (i = 0; i < cnt; ++i)
   free(pFld[i]);
  free(fields->fieldsList);
 }
 if (fields->columns != ((void *)0))
  free(fields->columns);
 free(fields);
}

variable_types: struct FieldListStruct { unsigned int fieldsMax; unsigned int fieldsCount; unsigned int colMax; unsigned int colCount; struct FieldStruct { enum FieldType { Error=0, Property=1, FileName=2, FileSize=3 } type; struct FieldCache { short empty; unsigned int offset; unsigned int size; } cache; int name[]; } **fieldsList; struct FieldStruct **columns; } *

variable_types:
cnt
unsigned int

variable_types:
i
unsigned int

user_defined_types: struct FieldListStruct { unsigned int fieldsMax; unsigned int fieldsCount; unsigned int colMax; unsigned int colCount; struct FieldStruct **fieldsList; struct FieldStruct **columns; }

user_defined_types: struct FieldStruct { enum FieldType type; struct FieldCache cache; int name[]; }


fldFree

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

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

original_code:
void fldFree(struct FieldStruct *fld)
{
 free(fld);
}

variable_types: struct FieldStruct { enum FieldType { Error=0, Property=1, FileName=2, FileSize=3 } type; struct FieldCache { short empty; unsigned int offset; unsigned int size; } cache; int name[]; } *


fldGetType

decompiled_code:
__int64 __fastcall fldGetType(const wchar_t *a1, int a2)
{
__int64 result; // rax
int v3; // er8

result = 1LL;
if ( *a1 == 64 )
{
result = 0LL;
if ( a2 == 9 )
{
v3 = wcsncmp(a1, U"@FileName", 9uLL);
result = 2LL;
if ( v3 )
result = wcsncmp(a1, U"@FileSize", 9uLL) == 0 ? 3 : 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const wchar_t *a1, int a2)
{
__int64 result; // rax
int v3; // er8

result = 1LL;
if ( *a1 == 64 )
{
result = 0LL;
if ( a2 == 9 )
{
v3 = wcsncmp(a1, U"@FileName", 9uLL);
result = 2LL;
if ( v3 )
result = wcsncmp(a1, U"@FileSize", 9uLL) == 0 ? 3 : 0;
}
}
return result;
}

original_code:
enum FieldType fldGetType(const wchar_t *name, unsigned int len)
{
 if (name[0] == L'@')
 {
  if (len == 9)
  {
   if (wcsncmp(name, L"@FileName", len) == 0)
    return FileName;
   if (wcsncmp(name, L"@FileSize", len) == 0)
    return FileSize;
  }
  return Error;
 }
 return Property;
}

canonical_original_code:
enum FieldType fldGetType(int *name, unsigned int len)
{
 if (name[0] == L'@')
 {
  if (len == 9)
  {
   if (wcsncmp(name, L"@FileName", len) == 0)
    return FileName;
   if (wcsncmp(name, L"@FileSize", len) == 0)
    return FileSize;
  }
  return Error;
 }
 return Property;
}

variable_types:
name
int *

variable_types:
len
unsigned int

return_type: enum FieldType { Error=0, Property=1, FileName=2, FileSize=3 }


fieldsInit

original_code:
struct FieldListStruct *fieldsInit(const wchar_t *fieldsList)
{
 struct FieldListStruct *fields = malloc(sizeof(struct FieldListStruct));
 if (fields == ((void *)0))
  return ((void *)0);
 bzero(fields, sizeof(struct FieldListStruct));
 fields->fieldsList = malloc(sizeof(struct FieldStruct *) * 10);
 if (fields->fieldsList == ((void *)0))
 {
  fieldsFree(fields);
  return ((void *)0);
 }
 fields->fieldsMax = 10;
 fields->columns = malloc(sizeof(struct FieldStruct *) * 10);
 if (fields->columns == ((void *)0))
 {
  fieldsFree(fields);
  return ((void *)0);
 }
 fields->colMax = 10;
 const wchar_t *pStart = fieldsList;
 while (pStart != L'\0')
 {
  if (fields->colCount == fields->colMax)
  {
   struct FieldStruct **pC = realloc(fields->columns, sizeof(struct FieldStruct *) * (fields->colMax + 10));
   if (pC == ((void *)0))
   {
    fieldsFree(fields);
    return ((void *)0);
   }
   fields->columns = pC;
   fields->colMax += 10;
  }
  unsigned int len;
  const wchar_t *pEnd = wcschr(pStart, L',');
  if (pEnd == ((void *)0))
   len = wcslen(pStart);
  else
   len = pEnd - pStart;
  struct FieldStruct *fld = ((void *)0);
  if (len != 0)
  {
   fld = fieldsFind(fields, pStart, len);
   if (fld == ((void *)0))
   {
    if (fields->fieldsCount == fields->fieldsMax)
    {
     struct FieldStruct **pF = realloc(fields->fieldsList, sizeof(struct FieldStruct *) * (fields->fieldsMax + 10));
     if (pF == ((void *)0))
     {
      fieldsFree(fields);
      return ((void *)0);
     }
     fields->fieldsList = pF;
     fields->fieldsMax += 10;
    }
    fld = fldInit(pStart, len);
    if (fld == ((void *)0))
    {
     fieldsFree(fields);
     return ((void *)0);
    }
    fields->fieldsList[fields->fieldsCount++] = fld;
   }
  }
  fields->columns[fields->colCount++] = fld;
  if (pEnd == ((void *)0))
   break;
  pStart = pEnd + 1;
 }
 return fields;
}

canonical_original_code:
struct FieldListStruct *fieldsInit(int *fieldsList)
{
 struct FieldListStruct *fields = malloc(sizeof(struct FieldListStruct));
 if (fields == ((void *)0))
  return ((void *)0);
 bzero(fields, sizeof(struct FieldListStruct));
 fields->fieldsList = malloc(sizeof(struct FieldStruct *) * 10);
 if (fields->fieldsList == ((void *)0))
 {
  fieldsFree(fields);
  return ((void *)0);
 }
 fields->fieldsMax = 10;
 fields->columns = malloc(sizeof(struct FieldStruct *) * 10);
 if (fields->columns == ((void *)0))
 {
  fieldsFree(fields);
  return ((void *)0);
 }
 fields->colMax = 10;
 int *pStart = fieldsList;
 while (pStart != L'\0')
 {
  if (fields->colCount == fields->colMax)
  {
   struct FieldStruct **pC = realloc(fields->columns, sizeof(struct FieldStruct *) * (fields->colMax + 10));
   if (pC == ((void *)0))
   {
    fieldsFree(fields);
    return ((void *)0);
   }
   fields->columns = pC;
   fields->colMax += 10;
  }
  unsigned int len;
  int *pEnd = wcschr(pStart, L',');
  if (pEnd == ((void *)0))
   len = wcslen(pStart);
  else
   len = pEnd - pStart;
  struct FieldStruct *fld = ((void *)0);
  if (len != 0)
  {
   fld = fieldsFind(fields, pStart, len);
   if (fld == ((void *)0))
   {
    if (fields->fieldsCount == fields->fieldsMax)
    {
     struct FieldStruct **pF = realloc(fields->fieldsList, sizeof(struct FieldStruct *) * (fields->fieldsMax + 10));
     if (pF == ((void *)0))
     {
      fieldsFree(fields);
      return ((void *)0);
     }
     fields->fieldsList = pF;
     fields->fieldsMax += 10;
    }
    fld = fldInit(pStart, len);
    if (fld == ((void *)0))
    {
     fieldsFree(fields);
     return ((void *)0);
    }
    fields->fieldsList[fields->fieldsCount++] = fld;
   }
  }
  fields->columns[fields->colCount++] = fld;
  if (pEnd == ((void *)0))
   break;
  pStart = pEnd + 1;
 }
 return fields;
}

variable_types:
fieldsList
int *

variable_types:
pStart
int *

variable_types:
pEnd
int *

return_type: struct FieldListStruct { unsigned int fieldsMax; unsigned int fieldsCount; unsigned int colMax; unsigned int colCount; struct FieldStruct { enum FieldType { Error=0, Property=1, FileName=2, FileSize=3 } type; struct FieldCache { short empty; unsigned int offset; unsigned int size; } cache; int name[]; } **fieldsList; struct FieldStruct **columns; } *


reversew

decompiled_code:
__int64 __fastcall reversew(const wchar_t *a1)
{
__int64 result; // rax
__int64 v2; // rdx
wchar_t v3; // ecx

result = (unsigned int)wcslen(a1) - 1;
if ( (int)result > 0 )
{
result = (int)result;
v2 = 0LL;
do
{
v3 = a1[v2];
a1[v2++] = a1[result];
a1[result--] = v3;
}
while ( (int)result > (int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const wchar_t *a1)
{
__int64 result; // rax
__int64 v2; // rdx
wchar_t v3; // ecx

result = (unsigned int)wcslen(a1) - 1;
if ( (int)result > 0 )
{
result = (int)result;
v2 = 0LL;
do
{
v3 = a1[v2];
a1[v2++] = a1[result];
a1[result--] = v3;
}
while ( (int)result > (int)v2 );
}
return result;
}

original_code:
void reversew(wchar_t *s)
{
 int i, j;
 wchar_t c;
 for (i = 0, j = wcslen(s) - 1; i < j; i++, j--)
 {
  c = s[i];
  s[i] = s[j];
  s[j] = c;
 }
}

canonical_original_code:
void reversew(int *s)
{
 int i; int j;
 int c;
 for (i = 0, j = wcslen(s) - 1; i < j; i++, j--)
 {
  c = s[i];
  s[i] = s[j];
  s[j] = c;
 }
}

variable_types:
s
int *

variable_types: i int

variable_types: j int

variable_types: c int


uitow

decompiled_code:
__int64 __fastcall uitow(unsigned __int64 a1, const wchar_t *a2)
{
__int64 v3; // rsi
unsigned __int64 v4; // rax

v3 = 0LL;
do
{
a2[v3++] = a1 % 0xA + 48;
v4 = a1;
a1 /= 0xAuLL;
}
while ( v4 > 9 );
a2[v3] = 0;
return reversew(a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1, const wchar_t *a2)
{
__int64 v3; // rsi
unsigned __int64 v4; // rax

v3 = 0LL;
do
{
a2[v3++] = a1 % 0xA + 48;
v4 = a1;
a1 /= 0xAuLL;
}
while ( v4 > 9 );
a2[v3] = 0;
return func0(a2);
}

original_code:
void uitow(unsigned long int n, wchar_t *s)
{
 unsigned long int i = 0;
 do
 {
  s[i++] = n % 10 + L'0';
 } while ((n /= 10) > 0);
 s[i] = L'\0';
 reversew(s);
}

canonical_original_code:
void uitow(unsigned long n, int *s)
{
 unsigned long i = 0;
 do
 {
  s[i++] = n % 10 + L'0';
 } while ((n /= 10) > 0);
 s[i] = L'\0';
 reversew(s);
}

variable_types:
n
unsigned long

variable_types:
i
unsigned long


freeConfigOne

repo: liuhengloveyou/confl

decompiled_code:
void __fastcall freeConfigOne(__int64 *a1)
{
__int64 v1; // rbp
void *v3; // rdi

v1 = *a1;
if ( *a1 )
{
if ( *(_QWORD *)v1 )
free(*(void **)v1);
v3 = *(void **)(v1 + 8);
if ( v3 )
free(v3);
*a1 = *(_QWORD *)(v1 + 16);
free((void *)v1);
}
}

original_code:
static void freeConfigOne(struct config **one)
{
 struct config *tmp = *one;
 if (!tmp) {
  return;
 }
 if (tmp->name) {
  free(tmp->name);
  tmp->name = ((void *)0);
 }
 if (tmp->value) {
  free(tmp->value);
  tmp->value = ((void *)0);
 }
 *one = tmp->next;
 free(tmp);
 return;
}

variable_types: struct config { char *name; char *value; struct config *next; } **


findNode

decompiled_code:
__int64 __fastcall findNode(__int64 a1, const char *a2)
{
__int64 v2; // r12
__int64 v3; // rbp

if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
if ( !v2 || !a2 )
return 0LL;
if ( !strcmp(*(const char **)v2, a2) )
return a1 + 8;
while ( 1 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
break;
if ( !strcmp(*(const char **)v2, a2) )
return v3 + 16;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
__int64 v2; // r12
__int64 v3; // rbp

if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
if ( !v2 || !a2 )
return 0LL;
if ( !strcmp(*(const char **)v2, a2) )
return a1 + 8;
while ( 1 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
break;
if ( !strcmp(*(const char **)v2, a2) )
return v3 + 16;
}
return v2;
}

original_code:
static struct config **findNode(const config_t *one, const char *key)
{
 if (!one) {
  return ((void *)0);
 }
 if (!one->confs) {
  return ((void *)0);
 }
 if (!key) {
  return ((void *)0);
 }
 if (!strcmp(one->confs->name, key)) {
  return (struct config **)&one->confs;
 }
 for (struct config *tmp = one->confs; tmp; tmp = tmp->next) {
  if (tmp->next && !strcmp(tmp->next->name, key)) {
   return (struct config **)&tmp->next;
  }
 }
 return ((void *)0);
}

canonical_original_code:
static struct config **findNode(struct configl *one, char *key)
{
 if (!one) {
  return ((void *)0);
 }
 if (!one->confs) {
  return ((void *)0);
 }
 if (!key) {
  return ((void *)0);
 }
 if (!strcmp(one->confs->name, key)) {
  return (struct config **)&one->confs;
 }
 for (struct config *tmp = one->confs; tmp; tmp = tmp->next) {
  if (tmp->next && !strcmp(tmp->next->name, key)) {
   return (struct config **)&tmp->next;
  }
 }
 return ((void *)0);
}

variable_types: struct configl { char *fn; struct config *confs; } *

variable_types:
key
char *

return_type: struct config { char *name; char *value; struct config *next; } **


confDestory

decompiled_code:
void __fastcall confDestory(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
free(v2);
*(_QWORD *)ptr = 0LL;
}
while ( *((_QWORD *)ptr + 1) )
freeConfigOne((__int64 *)ptr + 1);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
free(v2);
*(_QWORD *)ptr = 0LL;
}
while ( *((_QWORD *)ptr + 1) )
func0((__int64 *)ptr + 1);
free(ptr);
}
}

original_code:
void confDestory(config_t *one)
{
 if (!one) {
  return;
 }
 if (one->fn) {
  free(one->fn);
  one->fn = ((void *)0);
 }
 while (one->confs) {
  freeConfigOne(&one->confs);
 }
 free(one);
 one = ((void *)0);
}

canonical_original_code:
void confDestory(struct configl *one)
{
 if (!one) {
  return;
 }
 if (one->fn) {
  free(one->fn);
  one->fn = ((void *)0);
 }
 while (one->confs) {
  freeConfigOne(&one->confs);
 }
 free(one);
 one = ((void *)0);
}

variable_types: struct configl { char *fn; struct config { char *name; char *value; struct config *next; } *confs; } *

user_defined_types: struct configl { char *fn; struct config *confs; }


confSet

decompiled_code:
__int64 __fastcall confSet(__int64 a1, char *a2, char *a3)
{
__int64 result; // rax
__int64 v5; // rax
__int64 v6; // r13
char *v7; // r12
size_t v8; // rbx
size_t v9; // rdi
char *v10; // rax
char *v11; // rbx
char *v12; // rdi
_QWORD *v13; // rax
__int64 v14; // rdx

result = 0LL;
if ( a1 )
{
v5 = findNode(a1, a2);
v6 = v5;
if ( v5 )
{
v7 = *(char **)(*(_QWORD *)v5 + 8LL);
v8 = strlen(v7);
v9 = strlen(a3);
if ( v8 >= v9 )
{
LABEL_6:
strcpy(v7, a3);
return 0LL;
}
v10 = (char *)malloc(v9);
v11 = v10;
if ( v10 )
{
v12 = v7;
v7 = v10;
free(v12);
*(_QWORD *)(*(_QWORD *)v6 + 8LL) = v11;
goto LABEL_6;
}
result = 4294967294LL;
}
else
{
v13 = newConfig(a2, a3);
if ( v13 )
{
v14 = *(_QWORD *)(a1 + 8);
if ( v14 )
v13[2] = v14;
*(_QWORD *)(a1 + 8) = v13;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char *a2, char *a3)
{
__int64 result; // rax
__int64 v5; // rax
__int64 v6; // r13
char *v7; // r12
size_t v8; // rbx
size_t v9; // rdi
char *v10; // rax
char *v11; // rbx
char *v12; // rdi
_QWORD *v13; // rax
__int64 v14; // rdx

result = 0LL;
if ( a1 )
{
v5 = func1(a1, a2);
v6 = v5;
if ( v5 )
{
v7 = *(char **)(*(_QWORD *)v5 + 8LL);
v8 = strlen(v7);
v9 = strlen(a3);
if ( v8 >= v9 )
{
LABEL_6:
strcpy(v7, a3);
return 0LL;
}
v10 = (char *)malloc(v9);
v11 = v10;
if ( v10 )
{
v12 = v7;
v7 = v10;
free(v12);
*(_QWORD *)(*(_QWORD *)v6 + 8LL) = v11;
goto LABEL_6;
}
result = 4294967294LL;
}
else
{
v13 = newConfig(a2, a3);
if ( v13 )
{
v14 = *(_QWORD *)(a1 + 8);
if ( v14 )
v13[2] = v14;
*(_QWORD *)(a1 + 8) = v13;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int confSet(config_t *one, const char *key, const char *val)
{
 if (!one) {
  return 0;
 }
 struct config **tmp = findNode(one, key);
 if (tmp) {
  size_t ol = strlen((*tmp)->value);
  size_t nl = strlen(val);
  if (nl > ol) {
   char *tp = (char *)malloc(nl);
   if (!tp) {
    return -2;
   }
   free((*tmp)->value);
   (*tmp)->value = tp;
  }
  strcpy((*tmp)->value, val);
  return 0;
 }
 struct config *node = newConfig(key, val);
 if (!node) {
  return -1;
 }
 if (one->confs) {
  node->next = one->confs;
 }
 one->confs = node;
 return 0;
}

canonical_original_code:
int confSet(struct configl *one, char *key, char *val)
{
 if (!one) {
  return 0;
 }
 struct config **tmp = findNode(one, key);
 if (tmp) {
  unsigned long ol = strlen((*tmp)->value);
  unsigned long nl = strlen(val);
  if (nl > ol) {
   char *tp = (char *)malloc(nl);
   if (!tp) {
    return -2;
   }
   free((*tmp)->value);
   (*tmp)->value = tp;
  }
  strcpy((*tmp)->value, val);
  return 0;
 }
 struct config *node = newConfig(key, val);
 if (!node) {
  return -1;
 }
 if (one->confs) {
  node->next = one->confs;
 }
 one->confs = node;
 return 0;
}

variable_types:
val
char *

variable_types:
ol
unsigned long

variable_types:
nl
unsigned long

variable_types:
tp
char *

variable_types: struct config { char *name; char *value; struct config *next; } *


confGet

decompiled_code:
__int64 __fastcall confGet(__int64 a1, const char *a2)
{
__int64 result; // rax

result = findNode(a1, a2);
if ( result )
result = *(_QWORD *)(*(_QWORD *)result + 8LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
__int64 result; // rax

result = func1(a1, a2);
if ( result )
result = *(_QWORD *)(*(_QWORD *)result + 8LL);
return result;
}

original_code:
const char *confGet(const config_t *one, const char *key)
{
 struct config **tmp = findNode(one, key);
 if (!tmp) {
  return ((void *)0);
 }
 return (const char *)(*tmp)->value;
}

canonical_original_code:
char *confGet(struct configl *one, char *key)
{
 struct config **tmp = findNode(one, key);
 if (!tmp) {
  return ((void *)0);
 }
 return (char *)(*tmp)->value;
}

user_defined_types: struct config { char *name; char *value; struct config *next; }


confDel

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

v2 = (__int64 *)findNode(a1, a2);
if ( v2 )
freeConfigOne(v2);
}

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

v2 = (__int64 *)func1(a1, a2);
if ( v2 )
func0(v2);
}

original_code:
void confDel(config_t *one, const char *key)
{
 struct config **tmp = findNode(one, key);
 if (tmp) {
  freeConfigOne(tmp);
 }
 return;
}

canonical_original_code:
void confDel(struct configl *one, char *key)
{
 struct config **tmp = findNode(one, key);
 if (tmp) {
  freeConfigOne(tmp);
 }
 return;
}


main

repo: liulei/cuco

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

original_code:
int main(int argc, char ** argv){
 begrun();
 run();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 begrun();
 run();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 init_drift_table()
{
__int64 v0; // rbx
__int64 v1; // rbp
double v2; // xmm0_8
double v3; // xmm3_8
double v4; // xmm0_8
double v6; // [rsp+0h] [rbp-58h]
double v7; // [rsp+0h] [rbp-58h]
double x; // [rsp+8h] [rbp-50h]
double v9; // [rsp+10h] [rbp-48h]
double v10; // [rsp+10h] [rbp-48h]
double v11; // [rsp+20h] [rbp-38h] BYREF
char v12[8]; // [rsp+28h] [rbp-30h] BYREF
__int64 v13[5]; // [rsp+30h] [rbp-28h] BYREF

v0 = 1LL;
logTimeBegin = log(All[22]);
logTimeMax = log(All[24]);
v1 = gsl_integration_workspace_alloc(100000LL);
do
{
v9 = All[16];
x = *(double *)&logTimeBegin;
v13[0] = (__int64)drift_integ;
v6 = exp((*(double *)&logTimeMax - *(double *)&logTimeBegin) / 1000.0 * (double)(int)v0 + *(double *)&logTimeBegin);
v2 = exp(x);
gsl_integration_qag(v13, 100000LL, 4LL, v1, &v11, v12, v2, v6, v9, 0.00000001);
v3 = *(double *)&logTimeBegin;
*(float *)&v2 = v11;
*((_DWORD *)&DriftTable + v0 - 1) = LODWORD(v2);
v10 = All[16];
v13[0] = (__int64)gravkick_integ;
v7 = exp((*(double *)&logTimeMax - v3) / 1000.0 * (double)(int)v0 + v3);
v4 = exp(v3);
gsl_integration_qag(v13, 100000LL, 4LL, v1, &v11, v12, v4, v7, v10, 0.00000001);
*(float *)&v4 = v11;
*((_DWORD *)&GravKickTable + v0++ - 1) = LODWORD(v4);
}
while ( v0 != 1001 );
return gsl_integration_workspace_free(v1);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx
__int64 v1; // rbp
double v2; // xmm0_8
double v3; // xmm3_8
double v4; // xmm0_8
double v6; // [rsp+0h] [rbp-58h]
double v7; // [rsp+0h] [rbp-58h]
double x; // [rsp+8h] [rbp-50h]
double v9; // [rsp+10h] [rbp-48h]
double v10; // [rsp+10h] [rbp-48h]
double v11; // [rsp+20h] [rbp-38h] BYREF
char v12[8]; // [rsp+28h] [rbp-30h] BYREF
__int64 v13[5]; // [rsp+30h] [rbp-28h] BYREF

v0 = 1LL;
logTimeBegin = log(All[22]);
logTimeMax = log(All[24]);
v1 = gsl_integration_workspace_alloc(100000LL);
do
{
v9 = All[16];
x = *(double *)&logTimeBegin;
v13[0] = (__int64)drift_integ;
v6 = exp((*(double *)&logTimeMax - *(double *)&logTimeBegin) / 1000.0 * (double)(int)v0 + *(double *)&logTimeBegin);
v2 = exp(x);
gsl_integration_qag(v13, 100000LL, 4LL, v1, &v11, v12, v2, v6, v9, 0.00000001);
v3 = *(double *)&logTimeBegin;
*(float *)&v2 = v11;
*((_DWORD *)&DriftTable + v0 - 1) = LODWORD(v2);
v10 = All[16];
v13[0] = (__int64)gravkick_integ;
v7 = exp((*(double *)&logTimeMax - v3) / 1000.0 * (double)(int)v0 + v3);
v4 = exp(v3);
gsl_integration_qag(v13, 100000LL, 4LL, v1, &v11, v12, v4, v7, v10, 0.00000001);
*(float *)&v4 = v11;
*((_DWORD *)&GravKickTable + v0++ - 1) = LODWORD(v4);
}
while ( v0 != 1001 );
return gsl_integration_workspace_free(v1);
}

original_code:
void init_drift_table(void){
 int i;
 double result, abserr;
 gsl_function F;
 gsl_integration_workspace * workspace;
 logTimeBegin = log(All.TimeBegin);
 logTimeMax = log(All.TimeMax);
 workspace = gsl_integration_workspace_alloc(100000);
 for(i = 0; i < 1000; ++i){
  F.function = &drift_integ;
  gsl_integration_qag(&F, exp(logTimeBegin), exp(logTimeBegin + ((logTimeMax - logTimeBegin) / 1000) * (i + 1)), All.Hubble,
   1.0e-8, 100000, GSL_INTEG_GAUSS41, workspace, &result, &abserr);
  DriftTable[i] = result;
  F.function = &gravkick_integ;
  gsl_integration_qag(&F, exp(logTimeBegin), exp(logTimeBegin + ((logTimeMax - logTimeBegin) / 1000) * (i + 1)), All.Hubble,
   1.0e-8, 100000, GSL_INTEG_GAUSS41, workspace, &result, &abserr);
  GravKickTable[i] = result;
 }
 gsl_integration_workspace_free(workspace);
}

canonical_original_code:
void init_drift_table(){
 int i;
 double result; double abserr;
 struct gsl_function_struct F;
 struct gsl_integration_workspace *workspace;
 logTimeBegin = log(All.TimeBegin);
 logTimeMax = log(All.TimeMax);
 workspace = gsl_integration_workspace_alloc(100000);
 for(i = 0; i < 1000; ++i){
  F.function = &drift_integ;
  gsl_integration_qag(&F, exp(logTimeBegin), exp(logTimeBegin + ((logTimeMax - logTimeBegin) / 1000) * (i + 1)), All.Hubble,
   1.0e-8, 100000, GSL_INTEG_GAUSS41, workspace, &result, &abserr);
  DriftTable[i] = result;
  F.function = &gravkick_integ;
  gsl_integration_qag(&F, exp(logTimeBegin), exp(logTimeBegin + ((logTimeMax - logTimeBegin) / 1000) * (i + 1)), All.Hubble,
   1.0e-8, 100000, GSL_INTEG_GAUSS41, workspace, &result, &abserr);
  GravKickTable[i] = result;
 }
 gsl_integration_workspace_free(workspace);
}

variable_types: result double

variable_types: abserr double

variable_types: struct gsl_function_struct { double (*function)(double x, void *params); void *params; }

variable_types: struct gsl_integration_workspace { unsigned long limit; unsigned long size; unsigned long nrmax; unsigned long i; unsigned long maximum_level; double *alist; double *blist; double *rlist; double *elist; unsigned long *order; unsigned long *level; } *


decompiled_code:
double __fastcall get_drift_factor(int a1, int a2)
{
double v2; // xmm2_8
double v3; // xmm1_8
int v4; // eax
int v5; // edx
double v6; // xmm7_8
double v7; // xmm1_8
double v8; // xmm0_8
int v9; // eax
int v10; // edx
double v11; // xmm4_8

v2 = *(double *)&All[26];
v3 = ((double)a1 * v2 + *(double *)&logTimeBegin - *(double *)&logTimeBegin)
/ (*(double *)&logTimeMax - *(double *)&logTimeBegin)
* 1000.0;
v4 = (int)v3;
if ( (int)v3 > 999 )
{
v6 = *(double *)&LC5;
v5 = 998;
v4 = 999;
goto LABEL_5;
}
if ( v4 > 0 )
{
v5 = v4 - 1;
v6 = (double)v4;
LABEL_5:
v7 = (v3 - v6) * (float)(*((float *)&DriftTable + v4) - *((float *)&DriftTable + v5)) + *((float *)&DriftTable + v5);
goto LABEL_6;
}
v7 = v3 * DriftTable;
LABEL_6:
v8 = ((double)a2 * v2 + *(double *)&logTimeBegin - *(double *)&logTimeBegin)
/ (*(double *)&logTimeMax - *(double *)&logTimeBegin)
* 1000.0;
v9 = (int)v8;
if ( (int)v8 > 999 )
{
v11 = *(double *)&LC5;
v10 = 998;
v9 = 999;
return (v8 - v11) * (float)(*((float *)&DriftTable + v9) - *((float *)&DriftTable + v10))
+ *((float *)&DriftTable + v10)
- v7;
}
if ( v9 > 0 )
{
v10 = v9 - 1;
v11 = (double)v9;
return (v8 - v11) * (float)(*((float *)&DriftTable + v9) - *((float *)&DriftTable + v10))
+ *((float *)&DriftTable + v10)
- v7;
}
return v8 * DriftTable - v7;
}

canonical_decompiled_code:
double __fastcall func2(int a1, int a2)
{
double v2; // xmm2_8
double v3; // xmm1_8
int v4; // eax
int v5; // edx
double v6; // xmm7_8
double v7; // xmm1_8
double v8; // xmm0_8
int v9; // eax
int v10; // edx
double v11; // xmm4_8

v2 = *(double *)&All[26];
v3 = ((double)a1 * v2 + *(double *)&logTimeBegin - *(double *)&logTimeBegin)
/ (*(double *)&logTimeMax - *(double *)&logTimeBegin)
* 1000.0;
v4 = (int)v3;
if ( (int)v3 > 999 )
{
v6 = *(double *)&LC5;
v5 = 998;
v4 = 999;
goto LABEL_5;
}
if ( v4 > 0 )
{
v5 = v4 - 1;
v6 = (double)v4;
LABEL_5:
v7 = (v3 - v6) * (float)(*((float *)&DriftTable + v4) - *((float *)&DriftTable + v5)) + *((float *)&DriftTable + v5);
goto LABEL_6;
}
v7 = v3 * DriftTable;
LABEL_6:
v8 = ((double)a2 * v2 + *(double *)&logTimeBegin - *(double *)&logTimeBegin)
/ (*(double *)&logTimeMax - *(double *)&logTimeBegin)
* 1000.0;
v9 = (int)v8;
if ( (int)v8 > 999 )
{
v11 = *(double *)&LC5;
v10 = 998;
v9 = 999;
return (v8 - v11) * (float)(*((float *)&DriftTable + v9) - *((float *)&DriftTable + v10))
+ *((float *)&DriftTable + v10)
- v7;
}
if ( v9 > 0 )
{
v10 = v9 - 1;
v11 = (double)v9;
return (v8 - v11) * (float)(*((float *)&DriftTable + v9) - *((float *)&DriftTable + v10))
+ *((float *)&DriftTable + v10)
- v7;
}
return v8 * DriftTable - v7;
}

original_code:
double get_drift_factor(int time0, int time1){
 double a1, a2, df1, df2, u1, u2;
 int i1, i2;
 a1 = logTimeBegin + time0 * All.Timebase_interval;
 a2 = logTimeBegin + time1 * All.Timebase_interval;
 u1 = (a1 - logTimeBegin) / (logTimeMax - logTimeBegin) * 1000;
 i1 = (int) u1;
 if(i1 >= 1000)
  i1 = 1000 - 1;
 if(i1 < 1)
  df1 = u1 * DriftTable[0];
 else
  df1 = DriftTable[i1 - 1] + (DriftTable[i1] - DriftTable[i1 - 1]) * (u1 - i1);
 u2 = (a2 - logTimeBegin) / (logTimeMax - logTimeBegin) * 1000;
 i2 = (int) u2;
 if(i2 >= 1000)
  i2 = 1000 - 1;
 if(i2 < 1)
  df2 = u2 * DriftTable[0];
 else
  df2 = DriftTable[i2 - 1] + (DriftTable[i2] - DriftTable[i2 - 1]) * (u2 - i2);
 return df2 - df1;
}

canonical_original_code:
double get_drift_factor(int time0, int time1){
 double a1; double a2; double df1; double df2; double u1; double u2;
 int i1; int i2;
 a1 = logTimeBegin + time0 * All.Timebase_interval;
 a2 = logTimeBegin + time1 * All.Timebase_interval;
 u1 = (a1 - logTimeBegin) / (logTimeMax - logTimeBegin) * 1000;
 i1 = (int) u1;
 if(i1 >= 1000)
  i1 = 1000 - 1;
 if(i1 < 1)
  df1 = u1 * DriftTable[0];
 else
  df1 = DriftTable[i1 - 1] + (DriftTable[i1] - DriftTable[i1 - 1]) * (u1 - i1);
 u2 = (a2 - logTimeBegin) / (logTimeMax - logTimeBegin) * 1000;
 i2 = (int) u2;
 if(i2 >= 1000)
  i2 = 1000 - 1;
 if(i2 < 1)
  df2 = u2 * DriftTable[0];
 else
  df2 = DriftTable[i2 - 1] + (DriftTable[i2] - DriftTable[i2 - 1]) * (u2 - i2);
 return df2 - df1;
}

return_type: double


decompiled_code:
double __fastcall get_gravkick_factor(int a1, int a2)
{
double v2; // xmm2_8
double v3; // xmm1_8
int v4; // eax
int v5; // edx
double v6; // xmm7_8
double v7; // xmm1_8
double v8; // xmm0_8
int v9; // eax
int v10; // edx
double v11; // xmm4_8

v2 = *(double *)&All[26];
v3 = ((double)a1 * v2 + *(double *)&logTimeBegin - *(double *)&logTimeBegin)
/ (*(double *)&logTimeMax - *(double *)&logTimeBegin)
* 1000.0;
v4 = (int)v3;
if ( (int)v3 > 999 )
{
v6 = *(double *)&LC5;
v5 = 998;
v4 = 999;
goto LABEL_5;
}
if ( v4 > 0 )
{
v5 = v4 - 1;
v6 = (double)v4;
LABEL_5:
v7 = (v3 - v6) * (float)(*((float *)&GravKickTable + v4) - *((float *)&GravKickTable + v5))
+ *((float *)&GravKickTable + v5);
goto LABEL_6;
}
v7 = v3 * GravKickTable;
LABEL_6:
v8 = ((double)a2 * v2 + *(double *)&logTimeBegin - *(double *)&logTimeBegin)
/ (*(double *)&logTimeMax - *(double *)&logTimeBegin)
* 1000.0;
v9 = (int)v8;
if ( (int)v8 > 999 )
{
v11 = *(double *)&LC5;
v10 = 998;
v9 = 999;
return (v8 - v11) * (float)(*((float *)&GravKickTable + v9) - *((float *)&GravKickTable + v10))
+ *((float *)&GravKickTable + v10)
- v7;
}
if ( v9 > 0 )
{
v10 = v9 - 1;
v11 = (double)v9;
return (v8 - v11) * (float)(*((float *)&GravKickTable + v9) - *((float *)&GravKickTable + v10))
+ *((float *)&GravKickTable + v10)
- v7;
}
return v8 * GravKickTable - v7;
}

canonical_decompiled_code:
double __fastcall func3(int a1, int a2)
{
double v2; // xmm2_8
double v3; // xmm1_8
int v4; // eax
int v5; // edx
double v6; // xmm7_8
double v7; // xmm1_8
double v8; // xmm0_8
int v9; // eax
int v10; // edx
double v11; // xmm4_8

v2 = *(double *)&All[26];
v3 = ((double)a1 * v2 + *(double *)&logTimeBegin - *(double *)&logTimeBegin)
/ (*(double *)&logTimeMax - *(double *)&logTimeBegin)
* 1000.0;
v4 = (int)v3;
if ( (int)v3 > 999 )
{
v6 = *(double *)&LC5;
v5 = 998;
v4 = 999;
goto LABEL_5;
}
if ( v4 > 0 )
{
v5 = v4 - 1;
v6 = (double)v4;
LABEL_5:
v7 = (v3 - v6) * (float)(*((float *)&GravKickTable + v4) - *((float *)&GravKickTable + v5))
+ *((float *)&GravKickTable + v5);
goto LABEL_6;
}
v7 = v3 * GravKickTable;
LABEL_6:
v8 = ((double)a2 * v2 + *(double *)&logTimeBegin - *(double *)&logTimeBegin)
/ (*(double *)&logTimeMax - *(double *)&logTimeBegin)
* 1000.0;
v9 = (int)v8;
if ( (int)v8 > 999 )
{
v11 = *(double *)&LC5;
v10 = 998;
v9 = 999;
return (v8 - v11) * (float)(*((float *)&GravKickTable + v9) - *((float *)&GravKickTable + v10))
+ *((float *)&GravKickTable + v10)
- v7;
}
if ( v9 > 0 )
{
v10 = v9 - 1;
v11 = (double)v9;
return (v8 - v11) * (float)(*((float *)&GravKickTable + v9) - *((float *)&GravKickTable + v10))
+ *((float *)&GravKickTable + v10)
- v7;
}
return v8 * GravKickTable - v7;
}

original_code:
double get_gravkick_factor(int time0, int time1){
 double a1, a2, df1, df2, u1, u2;
 int i1, i2;
 a1 = logTimeBegin + time0 * All.Timebase_interval;
 a2 = logTimeBegin + time1 * All.Timebase_interval;
 u1 = (a1 - logTimeBegin) / (logTimeMax - logTimeBegin) * 1000;
 i1 = (int) u1;
 if(i1 >= 1000)
  i1 = 1000 - 1;
 if(i1 < 1)
  df1 = u1 * GravKickTable[0];
 else
  df1 = GravKickTable[i1 - 1] + (GravKickTable[i1] - GravKickTable[i1 - 1]) * (u1 - i1);
 u2 = (a2 - logTimeBegin) / (logTimeMax - logTimeBegin) * 1000;
 i2 = (int) u2;
 if(i2 >= 1000)
  i2 = 1000 - 1;
 if(i2 < 1)
  df2 = u2 * GravKickTable[0];
 else
  df2 = GravKickTable[i2 - 1] + (GravKickTable[i2] - GravKickTable[i2 - 1]) * (u2 - i2);
 return df2 - df1;
}

canonical_original_code:
double get_gravkick_factor(int time0, int time1){
 double a1; double a2; double df1; double df2; double u1; double u2;
 int i1; int i2;
 a1 = logTimeBegin + time0 * All.Timebase_interval;
 a2 = logTimeBegin + time1 * All.Timebase_interval;
 u1 = (a1 - logTimeBegin) / (logTimeMax - logTimeBegin) * 1000;
 i1 = (int) u1;
 if(i1 >= 1000)
  i1 = 1000 - 1;
 if(i1 < 1)
  df1 = u1 * GravKickTable[0];
 else
  df1 = GravKickTable[i1 - 1] + (GravKickTable[i1] - GravKickTable[i1 - 1]) * (u1 - i1);
 u2 = (a2 - logTimeBegin) / (logTimeMax - logTimeBegin) * 1000;
 i2 = (int) u2;
 if(i2 >= 1000)
  i2 = 1000 - 1;
 if(i2 < 1)
  df2 = u2 * GravKickTable[0];
 else
  df2 = GravKickTable[i2 - 1] + (GravKickTable[i2] - GravKickTable[i2 - 1]) * (u2 - i2);
 return df2 - df1;
}


decompiled_code:
__int64 __fastcall find_next_outputtime(int a1)
{
__int64 v1; // rbx
int v2; // er12
float v3; // xmm0_4
float v4; // xmm1_4
int v5; // eax

if ( *((int *)&All + 543) <= 0 )
return 0x20000000LL;
v1 = 0LL;
v2 = -1;
do
{
while ( 1 )
{
v3 = *((float *)&All + v1 + 43);
v4 = *((float *)&All + 22);
if ( v3 < v4 )
goto LABEL_3;
if ( *((float *)&All + 24) < v3 )
goto LABEL_3;
v5 = (int)(log(v3 / v4) / *((double *)&All + 13));
if ( v5 <= a1 )
goto LABEL_3;
if ( v2 != -1 )
break;
v2 = v5;
LABEL_3:
if ( *((_DWORD *)&All + 543) <= (int)++v1 )
goto LABEL_11;
}
if ( v2 > v5 )
v2 = v5;
++v1;
}
while ( *((_DWORD *)&All + 543) > (int)v1 );
LABEL_11:
if ( v2 != -1 )
return (unsigned int)v2;
return 0x20000000LL;
}

original_code:
int find_next_outputtime(int ti_curr){
 int i, ti, ti_next;
 double time;
 ti_next = -1;
 for(i = 0; i < All.OutputListLength; ++i){
  time = All.OutputListTimes[i];
  if(time >= All.TimeBegin && time <= All.TimeMax){
   ti = log(time / All.TimeBegin) / All.Timebase_interval;
   if(ti > ti_curr){
    if(ti_next == -1)
     ti_next = ti;
    if(ti_next > ti)
     ti_next = ti;
   }
  }
 }
 if(ti_next == -1){
  ti_next = 2 * (1<<28);
 }
 return(ti_next);
}

canonical_original_code:
int find_next_outputtime(int ti_curr){
 int i; int ti; int ti_next;
 double time;
 ti_next = -1;
 for(i = 0; i < All.OutputListLength; ++i){
  time = All.OutputListTimes[i];
  if(time >= All.TimeBegin && time <= All.TimeMax){
   ti = log(time / All.TimeBegin) / All.Timebase_interval;
   if(ti > ti_curr){
    if(ti_next == -1)
     ti_next = ti;
    if(ti_next > ti)
     ti_next = ti;
   }
  }
 }
 if(ti_next == -1){
  ti_next = 2 * (1<<28);
 }
 return(ti_next);
}

variable_types: i int

variable_types: ti int

variable_types: time double


decompiled_code:
void find_next_sync_point_and_drift()
{
double v0; // xmm0_8
__int64 v1; // rax
int v2; // ebx
double v3; // r14
int v4; // esi
int v5; // eax
double v6; // xmm0_8
double v7; // xmm0_8
int v8; // eax
float v9; // xmm0_4
double v10; // [rsp+0h] [rbp-30h]
double v11; // [rsp+0h] [rbp-30h]
double v12; // [rsp+8h] [rbp-28h]
float v13; // [rsp+14h] [rbp-1Ch]

v13 = *((float *)&All + 21);
v0 = (double)*(int *)(P + 52LL);
if ( NumPart > 1u )
{
v1 = P + 112LL;
do
{
v1 += 60LL;
v0 = fmin((double)*(int *)(v1 - 60), v0);
}
while ( v1 != P + 60LL * (unsigned int)(NumPart - 2) + 172 );
}
v2 = *((_DWORD *)&All + 30);
v12 = (double)v2;
v3 = (double)v2;
if ( v0 < (double)v2 )
{
v2 = (int)v0;
v3 = v0;
v12 = (double)(int)v0;
}
v4 = *((_DWORD *)&All + 29);
if ( v3 >= (double)v4 )
{
do
{
if ( v4 < 0 )
break;
move_particles(*((unsigned int *)&All + 28));
v5 = *((_DWORD *)&All + 29);
v10 = *((float *)&All + 22);
v6 = (double)v5 * *((double *)&All + 13);
*((_DWORD *)&All + 28) = v5;
v7 = exp(v6);
++*((_DWORD *)&All + 42);
*(float *)&v7 = v7 * v10;
*((_DWORD *)&All + 21) = LODWORD(v7);
savepositions();
v8 = find_next_outputtime(*((_DWORD *)&All + 29) + 1);
*((_DWORD *)&All + 29) = v8;
v4 = v8;
}
while ( v3 >= (double)v8 );
}
move_particles(*((unsigned int *)&All + 28));
*((_DWORD *)&All + 28) = v2;
v11 = *((float *)&All + 22);
v9 = exp(v12 * *((double *)&All + 13)) * v11;
*((float *)&All + 21) = v9;
*((float *)&All + 23) = v9 - v13;
}

original_code:
void find_next_sync_point_and_drift(void){
 int i;
 double timeold;
 double min, min_glob;
 timeold = All.Time;
 min = P[0].Ti_endstep;
 for(i = 1; i < NumPart; ++i){
  if(min > P[i].Ti_endstep){
   min = P[i].Ti_endstep;
  }
 }
 min_glob = min;
 if(min_glob >= All.PM_Ti_endstep){
  min_glob = All.PM_Ti_endstep;
 }
 while(min_glob >= All.Ti_nextoutput && All.Ti_nextoutput >= 0){
  move_particles(All.Ti_Current, All.Ti_nextoutput);
  All.Ti_Current = All.Ti_nextoutput;
  All.Time = All.TimeBegin * exp(All.Ti_Current * All.Timebase_interval);
  savepositions(All.SnapshotFileCount++);
  All.Ti_nextoutput = find_next_outputtime(All.Ti_nextoutput + 1);
 }
 move_particles(All.Ti_Current, min_glob);
 All.Ti_Current = min_glob;
 All.Time = All.TimeBegin * exp(All.Ti_Current * All.Timebase_interval);
 All.TimeStep = All.Time - timeold;
}

canonical_original_code:
void find_next_sync_point_and_drift(){
 int i;
 double timeold;
 double min; double min_glob;
 timeold = All.Time;
 min = P[0].Ti_endstep;
 for(i = 1; i < NumPart; ++i){
  if(min > P[i].Ti_endstep){
   min = P[i].Ti_endstep;
  }
 }
 min_glob = min;
 if(min_glob >= All.PM_Ti_endstep){
  min_glob = All.PM_Ti_endstep;
 }
 while(min_glob >= All.Ti_nextoutput && All.Ti_nextoutput >= 0){
  move_particles(All.Ti_Current, All.Ti_nextoutput);
  All.Ti_Current = All.Ti_nextoutput;
  All.Time = All.TimeBegin * exp(All.Ti_Current * All.Timebase_interval);
  savepositions(All.SnapshotFileCount++);
  All.Ti_nextoutput = find_next_outputtime(All.Ti_nextoutput + 1);
 }
 move_particles(All.Ti_Current, min_glob);
 All.Ti_Current = min_glob;
 All.Time = All.TimeBegin * exp(All.Ti_Current * All.Timebase_interval);
 All.TimeStep = All.Time - timeold;
}

variable_types: timeold double

variable_types: min double


decompiled_code:
int every_timestep_stuff()
{
double v0; // xmm3_8
double v2; // [rsp+0h] [rbp-18h]
double v3; // [rsp+8h] [rbp-10h]

v3 = All[21];
v2 = log(v3);
v0 = v2 - log((float)(All[21] - All[23]));
return printf(
"\nBegin Step %d, Time: %g, Redshift: %g, Systemstep: %g, Dloga: %g\n",
LODWORD(All[41]),
All[21],
1.0 / v3 - 1.0,
All[23],
v0);
}

canonical_decompiled_code:
int func2()
{
double v0; // xmm3_8
double v2; // [rsp+0h] [rbp-18h]
double v3; // [rsp+8h] [rbp-10h]

v3 = All[21];
v2 = log(v3);
v0 = v2 - log((float)(All[21] - All[23]));
return printf(
"\nBegin Step %d, Time: %g, Redshift: %g, Systemstep: %g, Dloga: %g\n",
LODWORD(All[41]),
All[21],
1.0 / v3 - 1.0,
All[23],
v0);
}

original_code:
void every_timestep_stuff(void){
 double z;
 z = 1.0 / (All.Time) - 1;
 printf("\nBegin Step %d, Time: %g, Redshift: %g, Systemstep: %g, Dloga: %g\n", All.NumCurrentTiStep, All.Time, z, All.TimeStep, log(All.Time)- log(All.Time - All.TimeStep));
}

canonical_original_code:
void every_timestep_stuff(){
 double z;
 z = 1.0 / (All.Time) - 1;
 printf("\nBegin Step %d, Time: %g, Redshift: %g, Systemstep: %g, Dloga: %g\n", All.NumCurrentTiStep, All.Time, z, All.TimeStep, log(All.Time)- log(All.Time - All.TimeStep));
}

variable_types: z double


run

decompiled_code:
__int64 run()
{
do
{
find_next_sync_point_and_drift();
every_timestep_stuff();
compute_accelerations();
advance_and_find_timesteps();
++LODWORD(All[41]);
}
while ( SLODWORD(All[28]) <= 0xFFFFFFF && All[24] >= All[21] );
++LODWORD(All[42]);
return savepositions();
}

canonical_decompiled_code:
__int64 func3()
{
do
{
func1();
func2();
compute_accelerations();
advance_and_find_timesteps();
++LODWORD(All[41]);
}
while ( SLODWORD(All[28]) <= 0xFFFFFFF && All[24] >= All[21] );
++LODWORD(All[42]);
return savepositions();
}

original_code:
void run(void){
 do{
  find_next_sync_point_and_drift();
  every_timestep_stuff();
  compute_accelerations();
  advance_and_find_timesteps();
  All.NumCurrentTiStep++;
 }while(All.Ti_Current < (1<<28) && All.Time <= All.TimeMax);
 savepositions(All.SnapshotFileCount++);
}

canonical_original_code:
void run(){
 do{
  find_next_sync_point_and_drift();
  every_timestep_stuff();
  compute_accelerations();
  advance_and_find_timesteps();
  All.NumCurrentTiStep++;
 }while(All.Ti_Current < (1<<28) && All.Time <= All.TimeMax);
 savepositions(All.SnapshotFileCount++);
}