cstringtoi

decompiled_code:
__int64 __fastcall cstringtoi(__int16 *a1)
{
int v1; // er8
unsigned __int8 *v3; // rax
int v4; // ecx
int v5; // edi
int v6; // edx
__int64 result; // rax
unsigned __int8 *v8; // rsi
int v9; // er11
int v10; // esi
char v11; // dl
int v12; // ecx
__int64 v13; // rdx
__int64 v14; // rcx
unsigned __int8 *v15; // r9
int v16; // esi
unsigned __int8 *v17; // rdx
int v18; // ecx
int i; // ecx

v1 = *a1;
if ( v1 <= 0 )
return 0LL;
v3 = (unsigned __int8 *)(a1 + 1);
v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = *v3;
if ( (((_BYTE)v6 - 43) & 0xFD) != 0 )
break;
if ( (_BYTE)v6 == 45 )
v5 ^= 1u;
++v4;
++v3;
if ( v4 == v1 )
goto LABEL_31;
}
if ( v4 >= v1 )
{
LABEL_31:
result = 0LL;
goto LABEL_13;
}
result = 0LL;
v8 = (unsigned __int8 *)a1 + v4 + 3;
while ( (unsigned __int8)(v6 - 48) <= 9u )
{
if ( (int)result > 214748363 )
return 0x7FFFFFFFLL;
++v4;
result = (unsigned int)(v6 + 10 * result - 48);
if ( v4 == v1 )
break;
v6 = *v8++;
}
LABEL_13:
v9 = *(_DWORD *)(systab + 24LL) & 1;
if ( v9 && v4 < v1 - 1 && *((_BYTE *)a1 + v4 + 2) == 69 )
{
v10 = v4 + 1;
v11 = *((_BYTE *)a1 + v4 + 3);
if ( v11 == 45 )
{
v10 = v4 + 2;
v9 = -1;
}
else
{
v12 = v4 + 2;
if ( v11 == 43 )
v10 = v12;
}
if ( v10 < v1 )
{
v13 = (unsigned int)(v1 - 1 - v10);
v14 = (__int64)a1 + v10 + 3;
v15 = (unsigned __int8 *)a1 + v10 + 2;
v16 = 0;
v17 = (unsigned __int8 *)(v14 + v13);
do
{
v18 = *v15;
if ( (unsigned __int8)(v18 - 48) > 9u )
break;
++v15;
v16 = v18 + 10 * v16 - 48;
}
while ( v15 != v17 );
if ( v16 )
{
for ( i = 10; v16 != 1; i *= 10 )
--v16;
if ( v9 == 1 )
result = (unsigned int)(i * result);
else
result = (unsigned int)((int)result / i);
}
}
}
if ( v5 )
result = (unsigned int)-(int)result;
return result;
}

original_code:
int cstringtoi(cstring *str)
{ int ret = 0;
  int i;
  int minus = 0;
  for (i=0; (i < (int)str->len)&&
            ((str->buf[i] == '-') ||
             (str->buf[i] == '+')); i++)
    if (str->buf[i] == '-') minus = !minus;
  for (i = i; i < (int)str->len; i++)
  { if ((str->buf[i] > '9')||(str->buf[i] < '0')) break;
    if (ret > 214748363) return 0x7fffffff;
    ret = (ret * 10) + ((int)str->buf[i] - 48);
  }
  if ((systab->historic & 1)
     && (i < (str->len - 1)) && (str->buf[i] == 'E'))
  { int exp = 0;
    int expsgn = 1;
    int j = 10;
    i++;
    if (str->buf[i] == '-')
    { expsgn = -1;
      i++;
    }
    else if (str->buf[i] == '+')
    { i++;
    }
    for (i = i; i < str->len; i++)
    { if ((str->buf[i] < '0') || (str->buf[i] > '9'))
      { break;
      }
      exp = (exp * 10) + (str->buf[i] - '0');
    }
    if (exp)
    { while (exp > 1)
      { j = j * 10;
        exp--;
      }
      if (expsgn > 0)
      { ret = ret * j;
      }
      else
      { ret = ret / j;
      }
    }
  }
  if (minus) ret = -ret;
  return ret;
}

canonical_original_code:
int cstringtoi(struct CSTRING *str)
{ int ret = 0;
  int i;
  int minus = 0;
  for (i=0; (i < (int)str->len)&&
            ((str->buf[i] == '-') ||
             (str->buf[i] == '+')); i++)
    if (str->buf[i] == '-') minus = !minus;
  for (i = i; i < (int)str->len; i++)
  { if ((str->buf[i] > '9')||(str->buf[i] < '0')) break;
    if (ret > 214748363) return 0x7fffffff;
    ret = (ret * 10) + ((int)str->buf[i] - 48);
  }
  if ((systab->historic & 1)
     && (i < (str->len - 1)) && (str->buf[i] == 'E'))
  { int exp = 0;
    int expsgn = 1;
    int j = 10;
    i++;
    if (str->buf[i] == '-')
    { expsgn = -1;
      i++;
    }
    else if (str->buf[i] == '+')
    { i++;
    }
    for (i = i; i < str->len; i++)
    { if ((str->buf[i] < '0') || (str->buf[i] > '9'))
      { break;
      }
      exp = (exp * 10) + (str->buf[i] - '0');
    }
    if (exp)
    { while (exp > 1)
      { j = j * 10;
        exp--;
      }
      if (expsgn > 0)
      { ret = ret * j;
      }
      else
      { ret = ret / j;
      }
    }
  }
  if (minus) ret = -ret;
  return ret;
}

variable_types: struct CSTRING { short len; unsigned char buf[32768]; } *

variable_types: i int

variable_types: minus int

variable_types: exp int

variable_types: expsgn int

variable_types: j int


cstringtob

repo: jcwynholds/mumps

decompiled_code:
__int64 __fastcall cstringtob(__int16 *a1)
{
int v1; // esi
__int64 result; // rax
char v3; // dl
__int64 v4; // rsi
char *v5; // rax
int v6; // ecx

v1 = *a1;
result = 0LL;
if ( v1 > 0 )
{
while ( 1 )
{
v3 = *((_BYTE *)a1 + result + 2);
if ( ((v3 - 43) & 0xFD) != 0 )
break;
if ( v1 <= (int)++result )
goto LABEL_13;
}
if ( (int)result < v1 )
{
v4 = (__int64)a1 + (int)result + (unsigned int)(v1 - 1 - result) + 3;
v5 = (char *)a1 + (int)result + 3;
v6 = 0;
if ( v3 == 48 )
goto LABEL_10;
LABEL_7:
if ( v3 != 46 )
return (unsigned __int8)(v3 - 49) <= 8u;
if ( !v6 )
{
v6 = 1;
LABEL_10:
while ( v5 != (char *)v4 )
{
v3 = *v5++;
if ( v3 != 48 )
goto LABEL_7;
}
}
}
LABEL_13:
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 *a1)
{
int v1; // esi
__int64 result; // rax
char v3; // dl
__int64 v4; // rsi
char *v5; // rax
int v6; // ecx

v1 = *a1;
result = 0LL;
if ( v1 > 0 )
{
while ( 1 )
{
v3 = *((_BYTE *)a1 + result + 2);
if ( ((v3 - 43) & 0xFD) != 0 )
break;
if ( v1 <= (int)++result )
goto LABEL_13;
}
if ( (int)result < v1 )
{
v4 = (__int64)a1 + (int)result + (unsigned int)(v1 - 1 - result) + 3;
v5 = (char *)a1 + (int)result + 3;
v6 = 0;
if ( v3 == 48 )
goto LABEL_10;
LABEL_7:
if ( v3 != 46 )
return (unsigned __int8)(v3 - 49) <= 8u;
if ( !v6 )
{
v6 = 1;
LABEL_10:
while ( v5 != (char *)v4 )
{
v3 = *v5++;
if ( v3 != 48 )
goto LABEL_7;
}
}
}
LABEL_13:
result = 0LL;
}
return result;
}

original_code:
int cstringtob(cstring *str)
{ int ret = 0;
  int i;
  int dp = 0;
  for (i=0; (i < (int)str->len)&&
            ((str->buf[i] == '-') ||
            (str->buf[i] == '+')); i++);
  for (i = i; i < (int)str->len; i++)
  { if (str->buf[i] == '0') continue;
    if (str->buf[i] == '.')
    { if (dp) break;
      dp = 1;
      continue;
    }
    if ((str->buf[i] >= '1') &&
        (str->buf[i] <= '9'))
      ret = 1;
    break;
  }
  return ret;
}

canonical_original_code:
int cstringtob(struct CSTRING *str)
{ int ret = 0;
  int i;
  int dp = 0;
  for (i=0; (i < (int)str->len)&&
            ((str->buf[i] == '-') ||
            (str->buf[i] == '+')); i++);
  for (i = i; i < (int)str->len; i++)
  { if (str->buf[i] == '0') continue;
    if (str->buf[i] == '.')
    { if (dp) break;
      dp = 1;
      continue;
    }
    if ((str->buf[i] >= '1') &&
        (str->buf[i] <= '9'))
      ret = 1;
    break;
  }
  return ret;
}

variable_types: ret int

variable_types: dp int

return_type: int

user_defined_types: struct CSTRING { short len; unsigned char buf[32768]; }


itocstring

canonical_original_code:
short itocstring(unsigned char *buf, int n)
{ int i = 0;
  int p = 0;
  int a[12];
  a[0] = 0;
  if (n < 0)
  { buf[p++] = '-';
    n = -n;
  }
  while (n)
  { a[i++] = n % 10;
    n = n/10;
  }
  while (i) buf[p++] = a[--i] + 48;
  if (!p) buf[p++] = '0';
  buf[p] = '\0';
  return (short) p;
}

variable_types:
buf
unsigned char *

variable_types: n int

variable_types: p int

variable_types:
a
int [12]

return_type: short


uitocstring

decompiled_code:
__int64 __fastcall uitocstring(_BYTE *a1, unsigned int a2)
{
__int64 v3; // rdx
unsigned int v4; // er9
int v5; // er10
unsigned int v6; // edi
unsigned int v7; // eax
int v8; // eax
unsigned int v9; // edi
_BYTE *v10; // rdx
int *v11; // rcx
__int64 result; // rax
int v13; // [rsp+0h] [rbp-34h]
int v14[12]; // [rsp+4h] [rbp-30h] BYREF

v14[0] = 0;
if ( a2 )
{
v3 = 1LL;
do
{
v4 = a2;
v5 = v3;
v6 = 5 * (a2 / 0xA);
v7 = a2;
a2 /= 0xAu;
v8 = v7 - 2 * v6;
v9 = v3;
*(&v13 + v3++) = v8;
}
while ( v4 > 9 );
v10 = a1;
v11 = &v14[v5];
while ( 1 )
{
--v11;
*v10 = v8 + 48;
if ( v10 == &a1[v5 - 1] )
break;
v8 = *(v11 - 1);
++v10;
}
a1[v5] = 0;
result = v9;
}
else
{
*a1 = 48;
result = 1LL;
a1[1] = 0;
}
return result;
}

original_code:
short uitocstring(u_char *buf, u_int n)
{ int i = 0;
  int p = 0;
  int a[12];
  a[0] = 0;
  while (n)
  { a[i++] = n % 10;
    n = n/10;
  }
  while (i) buf[p++] = a[--i] + 48;
  if (!p) buf[p++] = '0';
  buf[p] = '\0';
  return (short) p;
}

canonical_original_code:
short uitocstring(unsigned char *buf, unsigned int n)
{ int i = 0;
  int p = 0;
  int a[12];
  a[0] = 0;
  while (n)
  { a[i++] = n % 10;
    n = n/10;
  }
  while (i) buf[p++] = a[--i] + 48;
  if (!p) buf[p++] = '0';
  buf[p] = '\0';
  return (short) p;
}

variable_types:
n
unsigned int


getvol

decompiled_code:
__int64 __fastcall getvol(__int16 *a1)
{
__int16 v1; // dx
__int64 v2; // rax
__int64 result; // rax

v1 = *a1;
if ( *a1 < 8 )
v1 = *a1 + 1;
v2 = **(_QWORD **)(systab + 228LL);
if ( v2 )
result = memcmp((const void *)(v2 + 16), a1 + 1, v1) == 0 ? 1 : -26;
else
result = 4294967270LL;
return result;
}

original_code:
short getvol(cstring *vol)
{ int i;
  short s;
  s = vol->len;
  if (s < 8) s++;
  for (i = 0; i < 1; i++)
  { if (systab->vol[i]->vollab == ((void *)0)) continue;
    if (bcmp(&systab->vol[i]->vollab->volnam.var_cu[0],
      vol->buf, s) != 0) continue;
    return (short) i + 1;
  }
  return (-26);
}

canonical_original_code:
short getvol(struct CSTRING *vol)
{ int i;
  short s;
  s = vol->len;
  if (s < 8) s++;
  for (i = 0; i < 1; i++)
  { if (systab->vol[i]->vollab == ((void *)0)) continue;
    if (bcmp(&systab->vol[i]->vollab->volnam.var_cu[0],
      vol->buf, s) != 0) continue;
    return (short) i + 1;
  }
  return (-26);
}

variable_types: s short


getuci

original_code:
short getuci(cstring *uci, int vol)
{ int i;
  short s;
  s = uci->len;
  if (s < 8) s++;
  if (vol == 0) vol = partab.jobtab->vol;
  vol--;
  for (i = 0; i < 64; i++)
  { if (bcmp(&systab->vol[vol]->vollab->uci[i].name.var_cu[0],
      uci->buf, s) == 0) return (short) i + 1;
  }
  return (-26);
}

canonical_original_code:
short getuci(struct CSTRING *uci, int vol)
{ int i;
  short s;
  s = uci->len;
  if (s < 8) s++;
  if (vol == 0) vol = partab.jobtab->vol;
  vol--;
  for (i = 0; i < 64; i++)
  { if (bcmp(&systab->vol[vol]->vollab->uci[i].name.var_cu[0],
      uci->buf, s) == 0) return (short) i + 1;
  }
  return (-26);
}

variable_types: vol int


SemOp

decompiled_code:
__int64 __fastcall SemOp(int a1, int a2)
{
int v2; // ebx
unsigned int v3; // eax
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // rax
struct sembuf sops; // [rsp+Ah] [rbp-1Eh] BYREF

*(_DWORD *)&sops.sem_op = 0x10000000;
if ( a2 )
{
sops.sem_num = a1;
v2 = 5;
sops.sem_op = a2;
while ( 1 )
{
v3 = semop(*((_DWORD *)systab + 5), &sops, 1uLL);
v6 = v3;
if ( !(_WORD)v3 )
break;
v7 = partab;
if ( a2 <= 0 && !partab )
{
panic("SemOp() error in write daemon", &sops, v4, v5, v6);
v7 = partab;
}
if ( *(_DWORD *)(v7 + 24) )
{
LODWORD(v6) = -251;
return (unsigned int)v6;
}
if ( !--v2 )
{
if ( *((_DWORD *)systab + 49) == -1 )
exit(0);
if ( a1 != 1 || a2 != 1 )
panic("SemOp() failed", &sops, v4, v5, v6);
goto LABEL_10;
}
}
if ( a1 != 2 )
goto LABEL_10;
curr_lock += a2;
}
else
{
LABEL_10:
LODWORD(v6) = 0;
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
int v2; // ebx
unsigned int v3; // eax
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // rax
struct sembuf sops; // [rsp+Ah] [rbp-1Eh] BYREF

*(_DWORD *)&sops.sem_op = 0x10000000;
if ( a2 )
{
sops.sem_num = a1;
v2 = 5;
sops.sem_op = a2;
while ( 1 )
{
v3 = semop(*((_DWORD *)systab + 5), &sops, 1uLL);
v6 = v3;
if ( !(_WORD)v3 )
break;
v7 = partab;
if ( a2 <= 0 && !partab )
{
panic("SemOp() error in write daemon", &sops, v4, v5, v6);
v7 = partab;
}
if ( *(_DWORD *)(v7 + 24) )
{
LODWORD(v6) = -251;
return (unsigned int)v6;
}
if ( !--v2 )
{
if ( *((_DWORD *)systab + 49) == -1 )
exit(0);
if ( a1 != 1 || a2 != 1 )
panic("SemOp() failed", &sops, v4, v5, v6);
goto LABEL_10;
}
}
if ( a1 != 2 )
goto LABEL_10;
curr_lock += a2;
}
else
{
LABEL_10:
LODWORD(v6) = 0;
}
return (unsigned int)v6;
}

original_code:
short SemOp(int sem_num, int numb)
{ short s;
  int i;
  struct sembuf buf={0, 0, 0x1000};
  if (numb == 0)
  { return 0;
  }
  buf.sem_num = (u_short) sem_num;
  buf.sem_op = (short) numb;
  for (i = 0; i < 5; i++)
  { s = semop(systab->sem_id, &buf, 1);
    if (s == 0)
    { if (sem_num == 2) curr_lock += numb;
      return 0;
    }
    if (numb < 1)
      if (partab.jobtab == ((void *)0))
 panic("SemOp() error in write daemon");
      if (partab.jobtab->trap)
        return -(51 +200);
  }
  if (systab->start_user == -1)
  { exit(0);
  }
  if ((sem_num != 1) || (numb != 1)) panic("SemOp() failed");
  return 0;
}

canonical_original_code:
short SemOp(int sem_num, int numb)
{ short s;
  int i;
  struct sembuf buf = {0, 0, 0x1000};
  if (numb == 0)
  { return 0;
  }
  buf.sem_num = (unsigned short) sem_num;
  buf.sem_op = (short) numb;
  for (i = 0; i < 5; i++)
  { s = semop(systab->sem_id, &buf, 1);
    if (s == 0)
    { if (sem_num == 2) curr_lock += numb;
      return 0;
    }
    if (numb < 1)
      if (partab.jobtab == ((void *)0))
 panic("SemOp() error in write daemon");
      if (partab.jobtab->trap)
        return -(51 +200);
  }
  if (systab->start_user == -1)
  { exit(0);
  }
  if ((sem_num != 1) || (numb != 1)) panic("SemOp() failed");
  return 0;
}

variable_types: numb int

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


attention

original_code:
short attention()
{ short s = 0;
  if (partab.jobtab->trap & (1 << 2))
  { partab.jobtab->trap = partab.jobtab->trap & ~(1 << 2);
    partab.jobtab->async_error = -(51 +200);
  }
  if (partab.jobtab->trap & 1)
  { partab.jobtab->trap = partab.jobtab->trap & ~1;
    partab.jobtab->async_error = -(66 +200);
  }
  if (partab.jobtab->trap & (1 << 30))
  { partab.jobtab->trap = partab.jobtab->trap & ~(1 << 30);
    partab.jobtab->async_error = -(67 +200);
  }
  if (partab.jobtab->trap & (1 << 31))
  { partab.jobtab->trap = partab.jobtab->trap & ~(1 << 31);
    partab.jobtab->async_error = -(68 +200);
  }
  if (partab.jobtab->trap & ((1 << 3) | (1 << 15) | (1 << 17)))
  { partab.jobtab->trap = 0;
    partab.jobtab->async_error = 0;
    partab.jobtab->attention = 0;
    return 1;
  }
  partab.jobtab->trap = 0;
  partab.jobtab->attention = 0;
  s = partab.jobtab->async_error;
  partab.jobtab->async_error = 0;
  if ((s == 0) && (partab.debug > 0))
  { if (partab.debug <= partab.jobtab->commands)
      s = 256;
    else partab.jobtab->attention = 1;
  }
  return s;
}


SchedYield

decompiled_code:
// attributes: thunk
int SchedYield(void)
{
return sched_yield();
}

canonical_decompiled_code:
int func2(void)
{
return sched_yield();
}

original_code:
void SchedYield()
{ int i;
  i = sched_yield();
  return;
}

return_type: void


original_code:
void ST_Restore(ST_newtab *newtab)
{
  ST_newtab *ptr;
  ST_depend *dd;
  ST_depend *ddf;
  int i;
  int t;
  short ret;
  int chk;
  int kill;
  ptr = newtab;
  if (ptr == ((void *)0)) return;
  if (ptr->stindex != ((void *)0))
  { for (t = 0; t < 1023; t++)
    { if (st_hash[t] != -1)
      { chk = st_hash[t];
        while (chk != -1)
        { kill = chk;
   if (symtab[chk].varnam.var_cu[0] == '$')
     kill = -1;
   else
          { for (i = 0; i < ptr->count_enn; i++)
            { if (symtab[chk].varnam.var_qu ==
                  symtab[ptr->stindex[i]].varnam.var_qu)
              { kill = -1;
         break;
       }
            }
   }
          chk = symtab[chk].fwd_link;
          if (kill > -1)
            ret = ST_SymKill(kill);
        }
      }
    }
  }
  for (i = 0; i < ptr->count_new; i++)
  { if (symtab[ptr->locdata[i].stindex].data != ((void *)0))
    { symtab[ptr->locdata[i].stindex].data->attach--;
      if (symtab[ptr->locdata[i].stindex].data->attach < 1)
      { dd = symtab[ptr->locdata[i].stindex].data->deplnk;
        while (dd != ((void *)0))
        { ddf = dd;
          dd = dd->deplnk;
          free(ddf);
        }
        free(symtab[ptr->locdata[i].stindex].data);
 symtab[ptr->locdata[i].stindex].data = ((void *)0);
      }
    }
    symtab[ptr->locdata[i].stindex].data = ptr->locdata[i].data;
    --symtab[ptr->locdata[i].stindex].usage;
    if (symtab[ptr->locdata[i].stindex].data != ((void *)0))
      if ((symtab[ptr->locdata[i].stindex].data->deplnk == ((void *)0)) &&
   (symtab[ptr->locdata[i].stindex].data->attach < 2) &&
   (symtab[ptr->locdata[i].stindex].data->dbc == -1))
      { free(symtab[ptr->locdata[i].stindex].data);
 symtab[ptr->locdata[i].stindex].data = ((void *)0);
      }
    if ((symtab[ptr->locdata[i].stindex].usage < 1) &&
 (symtab[ptr->locdata[i].stindex].data == ((void *)0)))
      ret = ST_SymKill(ptr->locdata[i].stindex);
  }
  if (ptr->fwd_link != ((void *)0))
  { ST_Restore(ptr->fwd_link);
  }
  free(ptr);
  if (ptr == (ST_newtab *) partab.jobtab->dostk[partab.jobtab->cur_do].newtab)
    partab.jobtab->dostk[partab.jobtab->cur_do].newtab = ((void *)0);
}

canonical_original_code:
void ST_Restore(struct ST_NEWTAB *newtab)
{
  struct ST_NEWTAB *ptr;
  struct ST_DEPEND *dd;
  struct ST_DEPEND *ddf;
  int i;
  int t;
  short ret;
  int chk;
  int kill;
  ptr = newtab;
  if (ptr == ((void *)0)) return;
  if (ptr->stindex != ((void *)0))
  { for (t = 0; t < 1023; t++)
    { if (st_hash[t] != -1)
      { chk = st_hash[t];
        while (chk != -1)
        { kill = chk;
   if (symtab[chk].varnam.var_cu[0] == '$')
     kill = -1;
   else
          { for (i = 0; i < ptr->count_enn; i++)
            { if (symtab[chk].varnam.var_qu ==
                  symtab[ptr->stindex[i]].varnam.var_qu)
              { kill = -1;
         break;
       }
            }
   }
          chk = symtab[chk].fwd_link;
          if (kill > -1)
            ret = ST_SymKill(kill);
        }
      }
    }
  }
  for (i = 0; i < ptr->count_new; i++)
  { if (symtab[ptr->locdata[i].stindex].data != ((void *)0))
    { symtab[ptr->locdata[i].stindex].data->attach--;
      if (symtab[ptr->locdata[i].stindex].data->attach < 1)
      { dd = symtab[ptr->locdata[i].stindex].data->deplnk;
        while (dd != ((void *)0))
        { ddf = dd;
          dd = dd->deplnk;
          free(ddf);
        }
        free(symtab[ptr->locdata[i].stindex].data);
 symtab[ptr->locdata[i].stindex].data = ((void *)0);
      }
    }
    symtab[ptr->locdata[i].stindex].data = ptr->locdata[i].data;
    --symtab[ptr->locdata[i].stindex].usage;
    if (symtab[ptr->locdata[i].stindex].data != ((void *)0))
      if ((symtab[ptr->locdata[i].stindex].data->deplnk == ((void *)0)) &&
   (symtab[ptr->locdata[i].stindex].data->attach < 2) &&
   (symtab[ptr->locdata[i].stindex].data->dbc == -1))
      { free(symtab[ptr->locdata[i].stindex].data);
 symtab[ptr->locdata[i].stindex].data = ((void *)0);
      }
    if ((symtab[ptr->locdata[i].stindex].usage < 1) &&
 (symtab[ptr->locdata[i].stindex].data == ((void *)0)))
      ret = ST_SymKill(ptr->locdata[i].stindex);
  }
  if (ptr->fwd_link != ((void *)0))
  { ST_Restore(ptr->fwd_link);
  }
  free(ptr);
  if (ptr == (struct ST_NEWTAB *) partab.jobtab->dostk[partab.jobtab->cur_do].newtab)
    partab.jobtab->dostk[partab.jobtab->cur_do].newtab = ((void *)0);
}

variable_types: struct ST_NEWTAB { struct ST_NEWTAB *fwd_link; short count_enn; short *stindex; short count_new; struct ST_LOCDATA { short stindex; struct ST_DATA { struct ST_DEPEND { struct ST_DEPEND *deplnk; unsigned char keylen; unsigned char bytes[-1]; } *deplnk; short attach; short dbc; unsigned char data[-1]; } *data; } *locdata; } *

variable_types: t int

variable_types: ret short

variable_types: chk int

variable_types: kill int

user_defined_types: struct ST_NEWTAB { struct ST_NEWTAB *fwd_link; short count_enn; short *stindex; short count_new; struct ST_LOCDATA *locdata; }

user_defined_types: struct ST_LOCDATA { short stindex; struct ST_DATA *data; }

user_defined_types: struct ST_DATA { struct ST_DEPEND *deplnk; short attach; short dbc; unsigned char data[-1]; }


main

canonical_name: main

repo: jd-code/groovit

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
_BOOL4 v4; // ebp
int v5; // ebx
_BOOL4 v6; // er13
int v7; // er12
_BOOL8 v8; // r14
unsigned int v10; // ebp
int v11; // [rsp+4h] [rbp-34h] BYREF
int v12; // [rsp+8h] [rbp-30h] BYREF
int v13[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v11 = 16;
v12 = 2;
v13[0] = 44100;
if ( argc != 2 )
{
v3 = -1;
puts("ECHEC=BADUSE");
return v3;
}
v3 = open(argv[1], 1, envp);
if ( v3 != -1 )
{
puts("ECHEC=0");
v11 = 16;
if ( ioctl(v3, 0xC0045005uLL, &v11) != -1 && v11 == 16 )
{
v5 = 1;
v4 = 0;
}
else
{
v11 = 8;
if ( ioctl(v3, 0xC0045005uLL, &v11) == -1 )
{
v5 = 0;
v4 = 0;
}
else
{
v4 = v11 == 16;
v5 = 0;
}
}
v12 = 2;
v6 = 0;
if ( ioctl(v3, 0xC0045006uLL, &v12) != -1 )
v6 = v12 == 2;
v13[0] = 44100;
if ( ioctl(v3, 0xC0045002uLL, v13) == -1 || v13[0] > 4674599 )
{
v13[0] = 22050;
if ( ioctl(v3, 0xC0045002uLL, v13) == -1 )
{
v7 = 0;
LODWORD(v8) = 0;
}
else
{
v8 = v13[0] <= 2342599;
v7 = 0;
}
}
else
{
v7 = 1;
LODWORD(v8) = 0;
}
if ( v5 )
{
puts("HOPEDRESO=16\nHOPEDRESOBIS=HOPEDRESO16");
}
else if ( v4 )
{
puts("HOPEDRESO=8\nHOPEDRESOBIS=HOPEDRESO8");
}
if ( !v6 )
{
puts("STEREO=1");
if ( v7 )
puts("HOPEDSPRATE=44100");
else
puts("HOPEDSPRATE=22050");
printf("ECHEC=NOTENOUGH\nREASON=\"");
printf("no stereo ");
goto LABEL_19;
}
puts("STEREO=2");
if ( v7 )
{
puts("HOPEDSPRATE=44100");
}
else
{
puts("HOPEDSPRATE=22050");
if ( !v8 )
{
LABEL_18:
printf("ECHEC=NOTENOUGH\nREASON=\"");
LABEL_19:
if ( !(v7 | v8) )
printf("handles neither 44KHz nor 22KHz ");
if ( !(v5 | v4) )
printf("handles neither 8bits nor 16bits sounds ");
puts("\"");
return 0;
}
}
if ( v5 | v4 )
return 0;
goto LABEL_18;
}
v10 = *__errno_location();
if ( v10 == 13 )
{
puts("ECHEC=DENIED");
}
else if ( v10 == 16 )
{
puts("ECHEC=BUSY");
}
printf("ECHEC=ERR%d\n", v10);
return v3;
}

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

canonical_original_code: int main(){return 0;}


repo: jdarcy/etcd-api

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
char *v4; // r14
int v5; // eax
__int64 v6; // r12
const char *v7; // r14
int v8; // er13
__int64 v9; // rdx
int v11; // eax
__int128 v12; // [rsp+8h] [rbp-50h]
int v13; // [rsp+8h] [rbp-50h]
__int64 v14; // [rsp+18h] [rbp-40h]

v3 = 0LL;
v12 = 0uLL;
v4 = getenv("ETCD_SERVERS");
while ( 1 )
{
v5 = getopt_long(argc, (char *const *)argv, "i:p:s:t:", &my_opts, 0LL);
if ( v5 == -1 )
break;
if ( v5 == 115 )
{
v4 = optarg;
}
else if ( v5 > 115 )
{
if ( v5 != 116 )
return print_usage(*argv);
*(_QWORD *)&v12 = optarg;
}
else if ( v5 == 105 )
{
v3 = optarg;
}
else
{
if ( v5 != 112 )
return print_usage(*argv);
*((_QWORD *)&v12 + 1) = optarg;
}
}
if ( !v4 || optind == argc )
return print_usage(*argv);
strdup(v4);
v6 = etcd_open_str();
if ( v6 )
{
v7 = argv[optind];
v8 = optind + 1;
v9 = 8LL * optind++;
v14 = v9;
if ( !strcasecmp(v7, "get") )
{
if ( argc - v8 == 1 && !((unsigned __int64)v12 | (unsigned __int64)v3 | *((_QWORD *)&v12 + 1)) )
{
v11 = do_get(v6, *(const char **)((char *)argv + v14 + 8));
goto LABEL_24;
}
goto LABEL_15;
}
if ( !strcasecmp(v7, "set") )
{
if ( argc - v8 == 2 && !v3 )
{
v11 = do_set(
v6,
*(const char **)((char *)argv + v14 + 8),
*(const char **)((char *)argv + v14 + 16),
*((_QWORD *)&v12 + 1),
v12);
goto LABEL_24;
}
}
else if ( !strcasecmp(v7, "delete") )
{
if ( argc - v8 == 1 && !((unsigned __int64)v12 | (unsigned __int64)v3 | *((_QWORD *)&v12 + 1)) )
{
v11 = do_delete(v6, *(const char **)((char *)argv + v14 + 8));
LABEL_24:
v13 = v11;
etcd_close_str();
return v13;
}
}
else if ( !strcasecmp(v7, "watch") )
{
if ( argc - v8 == 1 && v12 == 0 )
{
v11 = do_watch(v6, *(const char **)((char *)argv + v14 + 8), v3);
goto LABEL_24;
}
}
else if ( !strcasecmp(v7, "leader") )
{
if ( v8 == argc && !((unsigned __int64)v12 | (unsigned __int64)v3 | *((_QWORD *)&v12 + 1)) )
{
v11 = do_leader(v6);
goto LABEL_24;
}
}
else if ( !strcasecmp(v7, "lock") )
{
if ( argc - v8 == 1 && !*((_QWORD *)&v12 + 1) && (_QWORD)v12 )
{
v11 = do_lock(v6, *(const char **)((char *)argv + v14 + 8), v12, v3);
goto LABEL_24;
}
}
else if ( !strcasecmp(v7, "unlock") && argc - v8 == 1 && v12 == 0 && v3 )
{
v11 = do_unlock(v6, *(const char **)((char *)argv + v14 + 8), v3);
goto LABEL_24;
}
LABEL_15:
etcd_close_str();
return print_usage(*argv);
}
fwrite("etcd_open failed\n", 1uLL, 0x11uLL, stderr);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
char *v4; // r14
int v5; // eax
__int64 v6; // r12
const char *v7; // r14
int v8; // er13
__int64 v9; // rdx
int v11; // eax
__int128 v12; // [rsp+8h] [rbp-50h]
int v13; // [rsp+8h] [rbp-50h]
__int64 v14; // [rsp+18h] [rbp-40h]

v3 = 0LL;
v12 = 0uLL;
v4 = getenv("ETCD_SERVERS");
while ( 1 )
{
v5 = getopt_long(argc, (char *const *)argv, "i:p:s:t:", &my_opts, 0LL);
if ( v5 == -1 )
break;
if ( v5 == 115 )
{
v4 = optarg;
}
else if ( v5 > 115 )
{
if ( v5 != 116 )
return func14(*argv);
*(_QWORD *)&v12 = optarg;
}
else if ( v5 == 105 )
{
v3 = optarg;
}
else
{
if ( v5 != 112 )
return func14(*argv);
*((_QWORD *)&v12 + 1) = optarg;
}
}
if ( !v4 || optind == argc )
return func14(*argv);
strdup(v4);
v6 = etcd_open_str();
if ( v6 )
{
v7 = argv[optind];
v8 = optind + 1;
v9 = 8LL * optind++;
v14 = v9;
if ( !strcasecmp(v7, "get") )
{
if ( argc - v8 == 1 && !((unsigned __int64)v12 | (unsigned __int64)v3 | *((_QWORD *)&v12 + 1)) )
{
v11 = func7(v6, *(const char **)((char *)argv + v14 + 8));
goto LABEL_24;
}
goto LABEL_15;
}
if ( !strcasecmp(v7, "set") )
{
if ( argc - v8 == 2 && !v3 )
{
v11 = func9(
v6,
*(const char **)((char *)argv + v14 + 8),
*(const char **)((char *)argv + v14 + 16),
*((_QWORD *)&v12 + 1),
v12);
goto LABEL_24;
}
}
else if ( !strcasecmp(v7, "delete") )
{
if ( argc - v8 == 1 && !((unsigned __int64)v12 | (unsigned __int64)v3 | *((_QWORD *)&v12 + 1)) )
{
v11 = func12(v6, *(const char **)((char *)argv + v14 + 8));
LABEL_24:
v13 = v11;
etcd_close_str();
return v13;
}
}
else if ( !strcasecmp(v7, "watch") )
{
if ( argc - v8 == 1 && v12 == 0 )
{
v11 = func8(v6, *(const char **)((char *)argv + v14 + 8), v3);
goto LABEL_24;
}
}
else if ( !strcasecmp(v7, "leader") )
{
if ( v8 == argc && !((unsigned __int64)v12 | (unsigned __int64)v3 | *((_QWORD *)&v12 + 1)) )
{
v11 = func13(v6);
goto LABEL_24;
}
}
else if ( !strcasecmp(v7, "lock") )
{
if ( argc - v8 == 1 && !*((_QWORD *)&v12 + 1) && (_QWORD)v12 )
{
v11 = func10(v6, *(const char **)((char *)argv + v14 + 8), v12, v3);
goto LABEL_24;
}
}
else if ( !strcasecmp(v7, "unlock") && argc - v8 == 1 && v12 == 0 && v3 )
{
v11 = func11(v6, *(const char **)((char *)argv + v14 + 8), v3);
goto LABEL_24;
}
LABEL_15:
etcd_close_str();
return func14(*argv);
}
fwrite("etcd_open failed\n", 1uLL, 0x11uLL, stderr);
return 1;
}

original_code:
int
main (int argc, char **argv)
{
        int opt;
        char *servers = getenv("ETCD_SERVERS");
        char *command;
        char *precond = ((void *)0);
        char *ttl = ((void *)0);
        char *index_str = ((void *)0);
        etcd_session sess;
        int res = !0;
        int parsed = 0;
        for (;;) {
                opt = getopt_long(argc,argv,"i:p:s:t:",my_opts,((void *)0));
                if (opt == (-1)) {
                        break;
                }
                switch (opt) {
                case 'i':
                        index_str = optarg;
                        break;
                case 'p':
                        precond = optarg;
                        break;
                case 's':
                        servers = optarg;
                        break;
                case 't':
                        ttl = optarg;
                        break;
                default:
                        return print_usage(argv[0]);
                }
        }
        if (!servers) {
                return print_usage(argv[0]);
        }
        if (optind == argc) {
                return print_usage(argv[0]);
        }
        sess = etcd_open_str(strdup(servers));
        if (!sess) {
                fprintf(stderr,"etcd_open failed\n");
                return !0;
        }
        command = argv[optind++];
        if (!strcasecmp(command,"get")) {
                if (((argc-optind) == 1) && !precond && !ttl && !index_str) {
                        parsed = 1;
                        res = do_get(sess,argv[optind]);
                }
        }
        else if (!strcasecmp(command,"set")) {
                if (((argc-optind) == 2) && !index_str) {
                        parsed = 1;
                        res = do_set (sess, argv[optind], argv[optind+1],
                                      precond, ttl);
                }
        }
        else if (!strcasecmp(command,"delete")) {
                if (((argc-optind) == 1) && !precond && !ttl && !index_str) {
                        parsed = 1;
                        res = do_delete(sess,argv[optind]);
                }
        }
        else if (!strcasecmp(command,"watch")) {
                if (((argc-optind) == 1) && !precond && !ttl) {
                        parsed = 1;
                        res = do_watch(sess,argv[optind],index_str);
                }
        }
        else if (!strcasecmp(command,"leader")) {
                if (((argc-optind) == 0) && !precond && !ttl && !index_str) {
                        parsed = 1;
                        res = do_leader(sess);
                }
        }
        else if (!strcasecmp(command,"lock")) {
                if (((argc-optind) == 1) && !precond && ttl) {
                        parsed = 1;
                        res = do_lock(sess,argv[optind],ttl,index_str);
                }
        }
        else if (!strcasecmp(command,"unlock")) {
                if (((argc-optind) == 1) && !precond && !ttl && index_str) {
                        parsed = 1;
                        res = do_unlock(sess,argv[optind],index_str);
                }
        }
        etcd_close_str(sess);
        return parsed ? res : print_usage(argv[0]);
}

canonical_original_code:
int main(int argc, char **argv)
{
        int opt;
        char *servers = getenv("ETCD_SERVERS");
        char *command;
        char *precond = ((void *)0);
        char *ttl = ((void *)0);
        char *index_str = ((void *)0);
        void *sess;
        int res = !0;
        int parsed = 0;
        for (;;) {
                opt = getopt_long(argc,argv,"i:p:s:t:",my_opts,((void *)0));
                if (opt == (-1)) {
                        break;
                }
                switch (opt) {
                case 'i':
                        index_str = optarg;
                        break;
                case 'p':
                        precond = optarg;
                        break;
                case 's':
                        servers = optarg;
                        break;
                case 't':
                        ttl = optarg;
                        break;
                default:
                        return print_usage(argv[0]);
                }
        }
        if (!servers) {
                return print_usage(argv[0]);
        }
        if (optind == argc) {
                return print_usage(argv[0]);
        }
        sess = etcd_open_str(strdup(servers));
        if (!sess) {
                fprintf(stderr,"etcd_open failed\n");
                return !0;
        }
        command = argv[optind++];
        if (!strcasecmp(command,"get")) {
                if (((argc-optind) == 1) && !precond && !ttl && !index_str) {
                        parsed = 1;
                        res = do_get(sess,argv[optind]);
                }
        }
        else if (!strcasecmp(command,"set")) {
                if (((argc-optind) == 2) && !index_str) {
                        parsed = 1;
                        res = do_set (sess, argv[optind], argv[optind+1],
                                      precond, ttl);
                }
        }
        else if (!strcasecmp(command,"delete")) {
                if (((argc-optind) == 1) && !precond && !ttl && !index_str) {
                        parsed = 1;
                        res = do_delete(sess,argv[optind]);
                }
        }
        else if (!strcasecmp(command,"watch")) {
                if (((argc-optind) == 1) && !precond && !ttl) {
                        parsed = 1;
                        res = do_watch(sess,argv[optind],index_str);
                }
        }
        else if (!strcasecmp(command,"leader")) {
                if (((argc-optind) == 0) && !precond && !ttl && !index_str) {
                        parsed = 1;
                        res = do_leader(sess);
                }
        }
        else if (!strcasecmp(command,"lock")) {
                if (((argc-optind) == 1) && !precond && ttl) {
                        parsed = 1;
                        res = do_lock(sess,argv[optind],ttl,index_str);
                }
        }
        else if (!strcasecmp(command,"unlock")) {
                if (((argc-optind) == 1) && !precond && !ttl && index_str) {
                        parsed = 1;
                        res = do_unlock(sess,argv[optind],index_str);
                }
        }
        etcd_close_str(sess);
        return parsed ? res : print_usage(argv[0]);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int

variable_types:
servers
char *

variable_types:
command
char *

variable_types:
precond
char *

variable_types:
ttl
char *

variable_types:
sess
void *

variable_types: res int

variable_types: parsed int


decompiled_code:
__int64 __fastcall do_get(__int64 a1, const char *a2)
{
const char *v2; // rax
char *v3; // rbp
__int64 result; // rax

printf("getting %s\n", a2);
v2 = (const char *)etcd_get();
if ( v2 )
{
v3 = (char *)v2;
printf("got value: %s\n", v2);
free(v3);
result = 0LL;
}
else
{
fwrite("etcd_get failed\n", 1uLL, 0x10uLL, stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
const char *v2; // rax
char *v3; // rbp
__int64 result; // rax

printf("getting %s\n", a2);
v2 = (const char *)etcd_get();
if ( v2 )
{
v3 = (char *)v2;
printf("got value: %s\n", v2);
free(v3);
result = 0LL;
}
else
{
fwrite("etcd_get failed\n", 1uLL, 0x10uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int
do_get (etcd_session sess, char *key)
{
        char *value;
        printf("getting %s\n",key);
        value = etcd_get(sess,key);
        if (!value) {
                fprintf(stderr,"etcd_get failed\n");
                return !0;
        }
        printf("got value: %s\n",value);
        free(value);
        return 0;
}

canonical_original_code:
int do_get(void *sess, char *key)
{
        char *value;
        printf("getting %s\n",key);
        value = etcd_get(sess,key);
        if (!value) {
                fprintf(stderr,"etcd_get failed\n");
                return !0;
        }
        printf("got value: %s\n",value);
        free(value);
        return 0;
}

variable_types:
key
char *

variable_types:
value
char *


decompiled_code:
__int64 __fastcall do_watch(__int64 a1, const char *a2, const char *a3)
{
__int64 v3; // rsi
unsigned int v6; // [rsp+1Ch] [rbp-4Ch]
char *v7; // [rsp+20h] [rbp-48h]
char *ptr; // [rsp+28h] [rbp-40h]

printf("getting %s\n", a2);
if ( a3 )
v6 = strtol(a3, 0LL, 10);
while ( !(unsigned int)etcd_watch() )
{
v3 = v6++;
printf("index is %d\n", v3);
if ( v7 )
{
if ( ptr )
{
printf("key %s was set to %s\n", v7, ptr);
free(ptr);
}
else
{
printf("key %s was deleted\n", v7);
}
free(v7);
}
else
{
puts("I don't know what happened");
}
sleep(1u);
}
fwrite("etcd_watch failed\n", 1uLL, 0x12uLL, stderr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2, const char *a3)
{
__int64 v3; // rsi
unsigned int v6; // [rsp+1Ch] [rbp-4Ch]
char *v7; // [rsp+20h] [rbp-48h]
char *ptr; // [rsp+28h] [rbp-40h]

printf("getting %s\n", a2);
if ( a3 )
v6 = strtol(a3, 0LL, 10);
while ( !(unsigned int)etcd_watch() )
{
v3 = v6++;
printf("index is %d\n", v3);
if ( v7 )
{
if ( ptr )
{
printf("key %s was set to %s\n", v7, ptr);
free(ptr);
}
else
{
printf("key %s was deleted\n", v7);
}
free(v7);
}
else
{
puts("I don't know what happened");
}
sleep(1u);
}
fwrite("etcd_watch failed\n", 1uLL, 0x12uLL, stderr);
return 1LL;
}

original_code:
int
do_watch (etcd_session sess, char *pfx, char *index_str)
{
        char *key;
        char *value;
        int index_i;
        int *indexp;
        etcd_result res;
        printf("getting %s\n",pfx);
        if (index_str) {
                index_i = (int)strtol(index_str,((void *)0),10);
                indexp = &index_i;
        }
        else {
                indexp = ((void *)0);
        }
        for (;;) {
                res = etcd_watch(sess,pfx,&key,&value,indexp,&index_i);
                if (res != ETCD_OK) {
                        fprintf(stderr,"etcd_watch failed\n");
                        return !0;
                }
                printf("index is %d\n",index_i++);
                if (key) {
                        if (value) {
                                printf("key %s was set to %s\n",key,value);
                                free(value);
                        }
                        else {
                                printf("key %s was deleted\n",key);
                        }
                        free(key);
                }
                else {
                        printf("I don't know what happened\n");
                }
                indexp = &index_i;
                sleep(1);
        }
        return 0;
}

canonical_original_code:
int do_watch(void *sess, char *pfx, char *index_str)
{
        char *key;
        char *value;
        int index_i;
        int *indexp;
        enum etcd_result res;
        printf("getting %s\n",pfx);
        if (index_str) {
                index_i = (int)strtol(index_str,((void *)0),10);
                indexp = &index_i;
        }
        else {
                indexp = ((void *)0);
        }
        for (;;) {
                res = etcd_watch(sess,pfx,&key,&value,indexp,&index_i);
                if (res != ETCD_OK) {
                        fprintf(stderr,"etcd_watch failed\n");
                        return !0;
                }
                printf("index is %d\n",index_i++);
                if (key) {
                        if (value) {
                                printf("key %s was set to %s\n",key,value);
                                free(value);
                        }
                        else {
                                printf("key %s was deleted\n",key);
                        }
                        free(key);
                }
                else {
                        printf("I don't know what happened\n");
                }
                indexp = &index_i;
                sleep(1);
        }
        return 0;
}

variable_types:
pfx
char *

variable_types:
indexp
int *

variable_types: enum etcd_result { ETCD_OK=0, ETCD_PROTOCOL_ERROR=1, ETCD_WTF=2 }


decompiled_code:
__int64 __fastcall do_set(__int64 a1, const char *a2, const char *a3, const char *a4, const char *a5)
{
unsigned __int64 v7; // rbx
int v8; // er8
__int64 result; // rax

printf("setting %s to %s\n", a2, a3);
if ( a4 )
printf(" precond = %s\n", a4);
if ( a5 )
{
v7 = strtoul(a5, 0LL, 10);
printf(" ttl = %lu\n", v7);
}
v8 = etcd_set();
result = 0LL;
if ( v8 )
{
fwrite("etcd_set failed\n", 1uLL, 0x10uLL, stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const char *a2, const char *a3, const char *a4, const char *a5)
{
unsigned __int64 v7; // rbx
int v8; // er8
__int64 result; // rax

printf("setting %s to %s\n", a2, a3);
if ( a4 )
printf(" precond = %s\n", a4);
if ( a5 )
{
v7 = strtoul(a5, 0LL, 10);
printf(" ttl = %lu\n", v7);
}
v8 = etcd_set();
result = 0LL;
if ( v8 )
{
fwrite("etcd_set failed\n", 1uLL, 0x10uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int
do_set (etcd_session sess, char *key, char *value, char *precond, char *ttl)
{
        unsigned long ttl_num = 0;
        printf("setting %s to %s\n",key,value);
        if (precond) {
                printf("  precond = %s\n",precond);
        }
        if (ttl) {
                ttl_num = strtoul(ttl,((void *)0),10);
                printf("  ttl = %lu\n",ttl_num);
        }
        else {
                ttl_num = 0;
        }
        if (etcd_set(sess,key,value,precond,ttl_num) != ETCD_OK) {
                fprintf(stderr,"etcd_set failed\n");
                return !0;
        }
        return 0;
}

canonical_original_code:
int do_set(void *sess, char *key, char *value, char *precond, char *ttl)
{
        unsigned long ttl_num = 0;
        printf("setting %s to %s\n",key,value);
        if (precond) {
                printf("  precond = %s\n",precond);
        }
        if (ttl) {
                ttl_num = strtoul(ttl,((void *)0),10);
                printf("  ttl = %lu\n",ttl_num);
        }
        else {
                ttl_num = 0;
        }
        if (etcd_set(sess,key,value,precond,ttl_num) != ETCD_OK) {
                fprintf(stderr,"etcd_set failed\n");
                return !0;
        }
        return 0;
}


decompiled_code:
__int64 __fastcall do_lock(__int64 a1, const char *a2, const char *a3, const char *a4)
{
if ( !a3 )
return 1LL;
if ( a4 )
printf("locking %s (%s) for %s\n", a2, a4, a3);
else
printf("locking %s for %s\n", a2, a3);
strtoul(a3, 0LL, 10);
if ( !(unsigned int)etcd_lock() )
return 0LL;
fwrite("etcd_lock failed\n", 1uLL, 0x11uLL, stderr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2, const char *a3, const char *a4)
{
if ( !a3 )
return 1LL;
if ( a4 )
printf("locking %s (%s) for %s\n", a2, a4, a3);
else
printf("locking %s for %s\n", a2, a3);
strtoul(a3, 0LL, 10);
if ( !(unsigned int)etcd_lock() )
return 0LL;
fwrite("etcd_lock failed\n", 1uLL, 0x11uLL, stderr);
return 1LL;
}

original_code:
int
do_lock (etcd_session sess, char *key, char *ttl, char *index_in)
{
        unsigned long ttl_num = 0;
        char *index_out = ((void *)0);
        if (!ttl) {
                return !0;
        }
        if (index_in) {
                printf("locking %s (%s) for %s\n",key,index_in,ttl);
        }
        else {
                printf("locking %s for %s\n",key,ttl);
        }
        ttl_num = strtoul(ttl,((void *)0),10);
        if (etcd_lock(sess,key,ttl_num,index_in,&index_out) != ETCD_OK) {
                fprintf(stderr,"etcd_lock failed\n");
                return !0;
        }
        if (index_out) {
                printf("got back index number %s\n",index_out);
                free(index_out);
        }
        return 0;
}

canonical_original_code:
int do_lock(void *sess, char *key, char *ttl, char *index_in)
{
        unsigned long ttl_num = 0;
        char *index_out = ((void *)0);
        if (!ttl) {
                return !0;
        }
        if (index_in) {
                printf("locking %s (%s) for %s\n",key,index_in,ttl);
        }
        else {
                printf("locking %s for %s\n",key,ttl);
        }
        ttl_num = strtoul(ttl,((void *)0),10);
        if (etcd_lock(sess,key,ttl_num,index_in,&index_out) != ETCD_OK) {
                fprintf(stderr,"etcd_lock failed\n");
                return !0;
        }
        if (index_out) {
                printf("got back index number %s\n",index_out);
                free(index_out);
        }
        return 0;
}


decompiled_code:
__int64 __fastcall do_unlock(__int64 a1, const char *a2, const char *a3)
{
int v3; // er8
__int64 result; // rax

printf("unlocking %s (%s)\n", a2, a3);
v3 = etcd_unlock();
result = 0LL;
if ( v3 )
{
fwrite("etcd_unlock failed\n", 1uLL, 0x13uLL, stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, const char *a2, const char *a3)
{
int v3; // er8
__int64 result; // rax

printf("unlocking %s (%s)\n", a2, a3);
v3 = etcd_unlock();
result = 0LL;
if ( v3 )
{
fwrite("etcd_unlock failed\n", 1uLL, 0x13uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int
do_unlock (etcd_session sess, char *key, char *index_in)
{
        printf("unlocking %s (%s)\n",key,index_in);
        if (etcd_unlock(sess,key,index_in) != ETCD_OK) {
                fprintf(stderr,"etcd_unlock failed\n");
                return !0;
        }
        return 0;
}

canonical_original_code:
int do_unlock(void *sess, char *key, char *index_in)
{
        printf("unlocking %s (%s)\n",key,index_in);
        if (etcd_unlock(sess,key,index_in) != ETCD_OK) {
                fprintf(stderr,"etcd_unlock failed\n");
                return !0;
        }
        return 0;
}


decompiled_code:
__int64 __fastcall do_delete(__int64 a1, const char *a2)
{
int v2; // er8
__int64 result; // rax

printf("deleting %s\n", a2);
v2 = etcd_delete();
result = 0LL;
if ( v2 )
{
fwrite("etcd_delete failed\n", 1uLL, 0x13uLL, stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const char *a2)
{
int v2; // er8
__int64 result; // rax

printf("deleting %s\n", a2);
v2 = etcd_delete();
result = 0LL;
if ( v2 )
{
fwrite("etcd_delete failed\n", 1uLL, 0x13uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int
do_delete (etcd_session sess, char *key)
{
        printf("deleting %s\n",key);
        if (etcd_delete(sess,key) != ETCD_OK) {
                fprintf(stderr,"etcd_delete failed\n");
                return !0;
        }
        return 0;
}

canonical_original_code:
int do_delete(void *sess, char *key)
{
        printf("deleting %s\n",key);
        if (etcd_delete(sess,key) != ETCD_OK) {
                fprintf(stderr,"etcd_delete failed\n");
                return !0;
        }
        return 0;
}


decompiled_code:
__int64 do_leader()
{
const char *v0; // rax
char *v1; // rbp
__int64 result; // rax

puts("finding leader");
v0 = (const char *)etcd_leader();
if ( v0 )
{
v1 = (char *)v0;
printf("leader is %s\n", v0);
free(v1);
result = 0LL;
}
else
{
fwrite("etcd_leader failed\n", 1uLL, 0x13uLL, stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
const char *v0; // rax
char *v1; // rbp
__int64 result; // rax

puts("finding leader");
v0 = (const char *)etcd_leader();
if ( v0 )
{
v1 = (char *)v0;
printf("leader is %s\n", v0);
free(v1);
result = 0LL;
}
else
{
fwrite("etcd_leader failed\n", 1uLL, 0x13uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int
do_leader (etcd_session sess)
{
        char *value;
        printf("finding leader\n");
        value = etcd_leader(sess);
        if (!value) {
                fprintf(stderr,"etcd_leader failed\n");
                return !0;
        }
        printf("leader is %s\n",value);
        free(value);
        return 0;
}

canonical_original_code:
int do_leader(void *sess)
{
        char *value;
        printf("finding leader\n");
        value = etcd_leader(sess);
        if (!value) {
                fprintf(stderr,"etcd_leader failed\n");
                return !0;
        }
        printf("leader is %s\n",value);
        free(value);
        return 0;
}


decompiled_code:
__int64 __fastcall print_usage(const char *a1)
{
fprintf(stderr, "Usage: %s [-s server-list] command ...\n", a1);
fwrite("Valid commands:\n", 1uLL, 0x10uLL, stderr);
fwrite(" get KEY\n", 1uLL, 0x10uLL, stderr);
fwrite(" set [-p precond] [-t ttl] KEY VALUE\n", 1uLL, 0x2CuLL, stderr);
fwrite(" delete KEY\n", 1uLL, 0x10uLL, stderr);
fwrite(" watch [-i index] KEY\n", 1uLL, 0x1BuLL, stderr);
fwrite(" leader\n", 1uLL, 9uLL, stderr);
fwrite(" lock -t ttl [-i index] KEY\n", 1uLL, 0x21uLL, stderr);
fwrite(" unlock -i index KEY\n", 1uLL, 0x19uLL, stderr);
fwrite(
"Server list is host:port pairs separated by comma,\n"
"semicolon, or white space. If not given on the\n"
"command line, ETCD_SERVERS will be used from the\n"
"environment instead.\n",
1uLL,
0xA9uLL,
stderr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1)
{
fprintf(stderr, "Usage: %s [-s server-list] command ...\n", a1);
fwrite("Valid commands:\n", 1uLL, 0x10uLL, stderr);
fwrite(" get KEY\n", 1uLL, 0x10uLL, stderr);
fwrite(" set [-p precond] [-t ttl] KEY VALUE\n", 1uLL, 0x2CuLL, stderr);
fwrite(" delete KEY\n", 1uLL, 0x10uLL, stderr);
fwrite(" watch [-i index] KEY\n", 1uLL, 0x1BuLL, stderr);
fwrite(" leader\n", 1uLL, 9uLL, stderr);
fwrite(" lock -t ttl [-i index] KEY\n", 1uLL, 0x21uLL, stderr);
fwrite(" unlock -i index KEY\n", 1uLL, 0x19uLL, stderr);
fwrite(
"Server list is host:port pairs separated by comma,\n"
"semicolon, or white space. If not given on the\n"
"command line, ETCD_SERVERS will be used from the\n"
"environment instead.\n",
1uLL,
0xA9uLL,
stderr);
return 1LL;
}

original_code:
int
print_usage (char *prog)
{
        fprintf (stderr, "Usage: %s [-s server-list] command ...\n",prog);
        fprintf (stderr, "Valid commands:\n");
        fprintf (stderr, "  get       KEY\n");
        fprintf (stderr, "  set       [-p precond] [-t ttl] KEY VALUE\n");
        fprintf (stderr, "  delete    KEY\n");
        fprintf (stderr, "  watch     [-i index] KEY\n");
        fprintf (stderr, "  leader\n");
        fprintf (stderr, "  lock     -t ttl [-i index] KEY\n");
        fprintf (stderr, "  unlock    -i index KEY\n");
        fprintf (stderr, "Server list is host:port pairs separated by comma,\n"
                         "semicolon, or white space.  If not given on the\n"
                         "command line, ETCD_SERVERS will be used from the\n"
                         "environment instead.\n");
        return !0;
}

canonical_original_code:
int print_usage(char *prog)
{
        fprintf (stderr, "Usage: %s [-s server-list] command ...\n",prog);
        fprintf (stderr, "Valid commands:\n");
        fprintf (stderr, "  get       KEY\n");
        fprintf (stderr, "  set       [-p precond] [-t ttl] KEY VALUE\n");
        fprintf (stderr, "  delete    KEY\n");
        fprintf (stderr, "  watch     [-i index] KEY\n");
        fprintf (stderr, "  leader\n");
        fprintf (stderr, "  lock     -t ttl [-i index] KEY\n");
        fprintf (stderr, "  unlock    -i index KEY\n");
        fprintf (stderr, "Server list is host:port pairs separated by comma,\n"
                         "semicolon, or white space.  If not given on the\n"
                         "command line, ETCD_SERVERS will be used from the\n"
                         "environment instead.\n");
        return !0;
}

variable_types:
prog
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
float v3; // xmm5_4
float v4; // xmm6_4
float v5; // xmm7_4
float v6; // xmm4_4
FILE *v7; // rbp
float v9; // [rsp+0h] [rbp-28h]
float v10; // [rsp+Ch] [rbp-1Ch]

if ( argc <= 4 )
{
puts("We need at least 4 argument beside the name of the executable!\n EXIT!");
exit(1);
}
v3 = atof(argv[1]);
v9 = v3;
v4 = atof(argv[2]);
v5 = atof(argv[3]);
v6 = atof(argv[4]);
v10 = v6;
v7 = fopen("data1.dat", "a");
fprintf(v7, "%d %f %f %e %e\n", 0xFFFFFFFFLL, v9, v4, v5, v10);
fclose(v7);
ini_pos(12LL, 0LL, 10.0, v9, v4, v5, v10);
ini_pos(18LL, 12LL, 20.0, v9, v4, v5, v10);
ini_pos(24LL, 30LL, 30.0, v9, v4, v5, v10);
ini_pos(30LL, 54LL, 40.0, v9, v4, v5, v10);
ini_pos(36LL, 84LL, 50.0, v9, v4, v5, v10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
float v3; // xmm5_4
float v4; // xmm6_4
float v5; // xmm7_4
float v6; // xmm4_4
FILE *v7; // rbp
float v9; // [rsp+0h] [rbp-28h]
float v10; // [rsp+Ch] [rbp-1Ch]

if ( argc <= 4 )
{
puts("We need at least 4 argument beside the name of the executable!\n EXIT!");
exit(1);
}
v3 = atof(argv[1]);
v9 = v3;
v4 = atof(argv[2]);
v5 = atof(argv[3]);
v6 = atof(argv[4]);
v10 = v6;
v7 = fopen("data1.dat", "a");
fprintf(v7, "%d %f %f %e %e\n", 0xFFFFFFFFLL, v9, v4, v5, v10);
fclose(v7);
func7(12LL, 0LL, 10.0, v9, v4, v5, v10);
func7(18LL, 12LL, 20.0, v9, v4, v5, v10);
func7(24LL, 30LL, 30.0, v9, v4, v5, v10);
func7(30LL, 54LL, 40.0, v9, v4, v5, v10);
func7(36LL, 84LL, 50.0, v9, v4, v5, v10);
return 0;
}

original_code:
int main(){
  evolve("data1.dat","data2.dat");
  evolve("data2.dat","data3.dat");
  evolve("data3.dat","data4.dat");
  evolve("data4.dat","data5.dat");
  evolve("data5.dat","data6.dat");
}


repo: jdkoftinoff/microsupport

decompiled_code:
__int64 device_name_read()
{
if ( us_log_level > 3 )
us_log_debug_proc("%s: ", "device_name_read");
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
if ( us_log_level > 3 )
us_log_debug_proc("%s: ", "device_name_read");
return 1LL;
}

original_code:
static _Bool device_name_read( us_test_trie_schema_entry_t *US_UNUSED_self __attribute__( ( unused ) ) )
{
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "%s: ", __FUNCTION__ ); } while ( 0 );
    return 1;
}

canonical_original_code:
static _Bool device_name_read(struct us_test_trie_schema_entry_s *US_UNUSED_self)
{
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "%s: ", __FUNCTION__ ); } while ( 0 );
    return 1;
}

variable_types: struct us_test_trie_schema_entry_s { char *m_address; struct us_test_trie_schema_value_s { char m_type; enum us_schema_rw_t { US_RO=0, US_RW=1 } m_rw; void *m_data; short m_data_len; } *m_params[4]; int m_additional; _Bool (*read_proc)(struct us_test_trie_schema_entry_s *self); _Bool (*write_proc)(struct us_test_trie_schema_entry_s *self); } *

user_defined_types: struct us_test_trie_schema_entry_s { char *m_address; struct us_test_trie_schema_value_s *m_params[4]; int m_additional; _Bool (*read_proc)(struct us_test_trie_schema_entry_s *self); _Bool (*write_proc)(struct us_test_trie_schema_entry_s *self); }

user_defined_types: struct us_test_trie_schema_value_s { char m_type; enum us_schema_rw_t m_rw; void *m_data; short m_data_len; }


decompiled_code:
__int64 device_name_write()
{
int v0; // eax

v0 = us_log_level;
if ( us_log_level > 3 )
{
us_log_debug_proc("%s: ", "device_name_write");
v0 = us_log_level;
}
if ( v0 > 2 )
us_log_info_proc("new system name: %s ", system_name);
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax

v0 = us_log_level;
if ( us_log_level > 3 )
{
us_log_debug_proc("%s: ", "device_name_write");
v0 = us_log_level;
}
if ( v0 > 2 )
us_log_info_proc("new system name: %s ", system_name);
return 1LL;
}

original_code:
static _Bool device_name_write( us_test_trie_schema_entry_t *US_UNUSED_self __attribute__( ( unused ) ) )
{
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "%s: ", __FUNCTION__ ); } while ( 0 );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "new system name: %s ", system_name ); } while ( 0 );
    return 1;
}

canonical_original_code:
static _Bool device_name_write(struct us_test_trie_schema_entry_s *US_UNUSED_self)
{
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "%s: ", __FUNCTION__ ); } while ( 0 );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "new system name: %s ", system_name ); } while ( 0 );
    return 1;
}

user_defined_types: enum us_schema_rw_t { US_RO=0, US_RW=1 }


decompiled_code:
__int64 system_name_read()
{
if ( us_log_level > 3 )
us_log_debug_proc("%s: ", "system_name_read");
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
if ( us_log_level > 3 )
us_log_debug_proc("%s: ", "system_name_read");
return 1LL;
}

original_code:
static _Bool system_name_read( us_test_trie_schema_entry_t *US_UNUSED_self __attribute__( ( unused ) ) )
{
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "%s: ", __FUNCTION__ ); } while ( 0 );
    return 1;
}

canonical_original_code:
static _Bool system_name_read(struct us_test_trie_schema_entry_s *US_UNUSED_self)
{
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "%s: ", __FUNCTION__ ); } while ( 0 );
    return 1;
}


decompiled_code:
__int64 system_name_write()
{
int v0; // eax

v0 = us_log_level;
if ( us_log_level > 3 )
{
us_log_debug_proc("%s: ", "system_name_write");
v0 = us_log_level;
}
if ( v0 > 2 )
us_log_info_proc("new system name: %s ", device_name);
return 1LL;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax

v0 = us_log_level;
if ( us_log_level > 3 )
{
us_log_debug_proc("%s: ", "system_name_write");
v0 = us_log_level;
}
if ( v0 > 2 )
us_log_info_proc("new system name: %s ", device_name);
return 1LL;
}

original_code:
static _Bool system_name_write( us_test_trie_schema_entry_t *US_UNUSED_self __attribute__( ( unused ) ) )
{
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "%s: ", __FUNCTION__ ); } while ( 0 );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "new system name: %s ", device_name ); } while ( 0 );
    return 1;
}

canonical_original_code:
static _Bool system_name_write(struct us_test_trie_schema_entry_s *US_UNUSED_self)
{
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "%s: ", __FUNCTION__ ); } while ( 0 );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "new system name: %s ", device_name ); } while ( 0 );
    return 1;
}


decompiled_code:
__int64 us_test_trie_1()
{
unsigned int v0; // er12
__int64 v1; // rax
__int64 v2; // rbx
char v3; // al
__int64 v4; // rdx
__int64 v6; // [rsp-10h] [rbp-38h]
unsigned __int16 v7; // [rsp+Ah] [rbp-1Eh] BYREF
__int16 v8; // [rsp+Ch] [rbp-1Ch] BYREF
char v9[26]; // [rsp+Eh] [rbp-1Ah] BYREF

if ( us_log_level > 2 )
us_log_info_proc("us_test_trie_1");
v0 = 1;
v1 = us_trie_dyn_create(
us_testutil_sys_allocator,
128LL,
&us_trie_basic_ignorer,
&us_trie_basic_ignorer,
&us_trie_basic_db_skip,
&us_trie_basic_comparator);
v2 = v1;
if ( v1 )
{
us_trie_add(v1, "/input/level/", 13LL, 1LL);
us_trie_add(v2, "/output/level/", 14LL, 2LL);
v0 = us_trie_find(v2, "/output/level/", 14LL, &v7, &v8, v9, 0LL, 0LL);
if ( (_BYTE)v0 )
{
if ( us_log_level > 2 )
us_log_info_proc("found '%s' len %d flags %d", "/output/level/", (unsigned int)v8, v7);
}
else if ( us_log_level > 2 )
{
us_log_info_proc("did not find '%s'", "/output/level/");
}
v3 = us_trie_find(v2, "/input/level/", 13LL, &v7, &v8, v9, 0LL, 0LL);
v4 = v6;
if ( v3 )
{
if ( us_log_level > 2 )
us_log_info_proc("found '%s' len %d flags %d", "/input/level/", (unsigned int)v8, v7);
}
else
{
v0 = 0;
if ( us_log_level > 2 )
{
us_log_info_proc("did not find '%s'", "/input/level/");
(*(void (__fastcall **)(__int64))(v2 + 56))(v2);
return v0;
}
}
(*(void (__fastcall **)(__int64, const char *, __int64))(v2 + 56))(v2, "/input/level/", v4);
}
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // er12
__int64 v1; // rax
__int64 v2; // rbx
char v3; // al
__int64 v4; // rdx
__int64 v6; // [rsp-10h] [rbp-38h]
unsigned __int16 v7; // [rsp+Ah] [rbp-1Eh] BYREF
__int16 v8; // [rsp+Ch] [rbp-1Ch] BYREF
char v9[26]; // [rsp+Eh] [rbp-1Ah] BYREF

if ( us_log_level > 2 )
us_log_info_proc("us_test_trie_1");
v0 = 1;
v1 = us_trie_dyn_create(
us_testutil_sys_allocator,
128LL,
&us_trie_basic_ignorer,
&us_trie_basic_ignorer,
&us_trie_basic_db_skip,
&us_trie_basic_comparator);
v2 = v1;
if ( v1 )
{
us_trie_add(v1, "/input/level/", 13LL, 1LL);
us_trie_add(v2, "/output/level/", 14LL, 2LL);
v0 = us_trie_find(v2, "/output/level/", 14LL, &v7, &v8, v9, 0LL, 0LL);
if ( (_BYTE)v0 )
{
if ( us_log_level > 2 )
us_log_info_proc("found '%s' len %d flags %d", "/output/level/", (unsigned int)v8, v7);
}
else if ( us_log_level > 2 )
{
us_log_info_proc("did not find '%s'", "/output/level/");
}
v3 = us_trie_find(v2, "/input/level/", 13LL, &v7, &v8, v9, 0LL, 0LL);
v4 = v6;
if ( v3 )
{
if ( us_log_level > 2 )
us_log_info_proc("found '%s' len %d flags %d", "/input/level/", (unsigned int)v8, v7);
}
else
{
v0 = 0;
if ( us_log_level > 2 )
{
us_log_info_proc("did not find '%s'", "/input/level/");
(*(void (__fastcall **)(__int64))(v2 + 56))(v2);
return v0;
}
}
(*(void (__fastcall **)(__int64, const char *, __int64))(v2 + 56))(v2, "/input/level/", v4);
}
return v0;
}

original_code:
static _Bool us_test_trie_1( void )
{
    _Bool r = 1;
    us_trie_dyn_t *trie;
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "us_test_trie_1" ); } while ( 0 );
    trie = us_trie_dyn_create( us_testutil_sys_allocator,
                               128,
                               us_trie_basic_ignorer,
                               us_trie_basic_ignorer,
                               us_trie_basic_db_skip,
                               us_trie_basic_comparator );
    if ( trie )
    {
        const char *s;
        s = "/input/level/";
        us_trie_add( &trie->m_base, (us_trie_node_value_t *)s, strlen( s ), (us_trie_node_flags_t)1 );
        s = "/output/level/";
        us_trie_add( &trie->m_base, (us_trie_node_value_t *)s, strlen( s ), (us_trie_node_flags_t)2 );
        {
            us_trie_node_flags_t flags;
            int16_t match_len;
            us_trie_node_id_t match_item;
            s = "/output/level/";
            if ( us_trie_find( &trie->m_base, (us_trie_node_value_t *)s, strlen( s ), &flags, &match_len, &match_item, 0, 0 ) )
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "found '%s' len %d flags %d", s, match_len, flags ); } while ( 0 );
            }
            else
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "did not find '%s'", s ); } while ( 0 );
                r = 0;
            }
            s = "/input/level/";
            if ( us_trie_find( &trie->m_base, (us_trie_node_value_t *)s, strlen( s ), &flags, &match_len, &match_item, 0, 0 ) )
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "found '%s' len %d flags %d", s, match_len, flags ); } while ( 0 );
            }
            else
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "did not find '%s'", s ); } while ( 0 );
                r = 0;
            }
        }
        trie->destroy( trie );
    }
    return r;
}

canonical_original_code:
static _Bool us_test_trie_1()
{
    _Bool r = 1;
    struct us_trie_dyn_s *trie;
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "us_test_trie_1" ); } while ( 0 );
    trie = us_trie_dyn_create( us_testutil_sys_allocator,
                               128,
                               us_trie_basic_ignorer,
                               us_trie_basic_ignorer,
                               us_trie_basic_db_skip,
                               us_trie_basic_comparator );
    if ( trie )
    {
        char *s;
        s = "/input/level/";
        us_trie_add( &trie->m_base, (char *)s, strlen( s ), (unsigned short)1 );
        s = "/output/level/";
        us_trie_add( &trie->m_base, (char *)s, strlen( s ), (unsigned short)2 );
        {
            unsigned short flags;
            short match_len;
            short match_item;
            s = "/output/level/";
            if ( us_trie_find( &trie->m_base, (char *)s, strlen( s ), &flags, &match_len, &match_item, 0, 0 ) )
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "found '%s' len %d flags %d", s, match_len, flags ); } while ( 0 );
            }
            else
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "did not find '%s'", s ); } while ( 0 );
                r = 0;
            }
            s = "/input/level/";
            if ( us_trie_find( &trie->m_base, (char *)s, strlen( s ), &flags, &match_len, &match_item, 0, 0 ) )
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "found '%s' len %d flags %d", s, match_len, flags ); } while ( 0 );
            }
            else
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "did not find '%s'", s ); } while ( 0 );
                r = 0;
            }
        }
        trie->destroy( trie );
    }
    return r;
}

variable_types: struct us_trie_dyn_s { struct us_trie_s { short m_max_nodes; short m_num_nodes; struct us_trie_node_s { short m_parent; short m_sibling; short m_child; char m_value; unsigned short m_flags; } *m_nodes; short m_first_free; _Bool (*m_query_ignorer)(char); _Bool (*m_db_ignorer)(char); int (*m_db_skip)(char); int (*m_comparator)(char, char); } m_base; void (*destroy)(struct us_trie_dyn_s *); struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *m_allocator; struct us_trie_node_s *m_nodes; } *

variable_types:
s
char *

variable_types:
flags
unsigned short

user_defined_types: struct us_trie_dyn_s { struct us_trie_s m_base; void (*destroy)(struct us_trie_dyn_s *); struct us_allocator_s *m_allocator; struct us_trie_node_s *m_nodes; }

user_defined_types: struct us_trie_s { short m_max_nodes; short m_num_nodes; struct us_trie_node_s *m_nodes; short m_first_free; _Bool (*m_query_ignorer)(char); _Bool (*m_db_ignorer)(char); int (*m_db_skip)(char); int (*m_comparator)(char, char); }


decompiled_code:
__int64 us_test_trie_2()
{
unsigned int v0; // er13
__int64 v1; // r12
const char *v2; // rbp
__int64 i; // rbx
__int16 v4; // ax
__int64 v5; // rcx
int v6; // er13
int v7; // er13
int v8; // er13

if ( us_log_level > 2 )
us_log_info_proc("us_test_trie_2");
v0 = 0;
v1 = us_trie_dyn_create(
us_testutil_sys_allocator,
128LL,
&us_trie_basic_ignorer,
&us_trie_basic_ignorer,
&us_trie_basic_db_skip,
&us_trie_basic_comparator);
if ( v1 )
{
v2 = us_test_trie_schema;
for ( i = 0LL; v2; v2 = (&us_test_trie_schema)[8 * i] )
{
v4 = strlen(v2);
v5 = (unsigned __int16)i++;
us_trie_add(v1, v2, (unsigned int)v4, v5);
}
v6 = us_test_trie_schema_dispatch_constprop_0(v1, "/device/name", &unk_9FA, 0LL);
v7 = us_test_trie_schema_dispatch_constprop_0(v1, "/device/system", "s", "new system name") & v6;
v8 = us_test_trie_schema_dispatch_constprop_0(v1, "/device/name", "s", "new device name") & v7;
v0 = us_test_trie_schema_dispatch_constprop_0(v1, "/device/system", &unk_9FA, 0LL) & v8;
(*(void (__fastcall **)(__int64))(v1 + 56))(v1);
}
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // er13
__int64 v1; // r12
const char *v2; // rbp
__int64 i; // rbx
__int16 v4; // ax
__int64 v5; // rcx
int v6; // er13
int v7; // er13
int v8; // er13

if ( us_log_level > 2 )
us_log_info_proc("us_test_trie_2");
v0 = 0;
v1 = us_trie_dyn_create(
us_testutil_sys_allocator,
128LL,
&us_trie_basic_ignorer,
&us_trie_basic_ignorer,
&us_trie_basic_db_skip,
&us_trie_basic_comparator);
if ( v1 )
{
v2 = us_test_trie_schema;
for ( i = 0LL; v2; v2 = (&us_test_trie_schema)[8 * i] )
{
v4 = strlen(v2);
v5 = (unsigned __int16)i++;
us_trie_add(v1, v2, (unsigned int)v4, v5);
}
v6 = func5(v1, "/device/name", &unk_9FA, 0LL);
v7 = func5(v1, "/device/system", "s", "new system name") & v6;
v8 = func5(v1, "/device/name", "s", "new device name") & v7;
v0 = func5(v1, "/device/system", &unk_9FA, 0LL) & v8;
(*(void (__fastcall **)(__int64))(v1 + 56))(v1);
}
return v0;
}

original_code:
static _Bool us_test_trie_2( void )
{
    _Bool r = 0;
    us_trie_dyn_t *trie;
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "us_test_trie_2" ); } while ( 0 );
    trie = us_trie_dyn_create( us_testutil_sys_allocator,
                               128,
                               us_trie_basic_ignorer,
                               us_trie_basic_ignorer,
                               us_trie_basic_db_skip,
                               us_trie_basic_comparator );
    if ( trie )
    {
        int item = 0;
        us_test_trie_schema_entry_t *cur = &us_test_trie_schema[0];
        while ( cur && cur->m_address != 0 )
        {
            us_trie_add(
                &trie->m_base, (us_trie_node_value_t *)cur->m_address, strlen( cur->m_address ), (us_trie_node_flags_t)item );
            item++;
            cur++;
        }
        r = 1;
        r &= us_test_trie_schema_dispatch( &trie->m_base, "/device/name", "", 0, 0 );
        r &= us_test_trie_schema_dispatch( &trie->m_base, "/device/system", "s", (void *)"new system name", 0 );
        r &= us_test_trie_schema_dispatch( &trie->m_base, "/device/name", "s", (void *)"new device name", 0 );
        r &= us_test_trie_schema_dispatch( &trie->m_base, "/device/system", "", 0, 0 );
        trie->destroy( trie );
    }
    return r;
}

canonical_original_code:
static _Bool us_test_trie_2()
{
    _Bool r = 0;
    struct us_trie_dyn_s *trie;
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "us_test_trie_2" ); } while ( 0 );
    trie = us_trie_dyn_create( us_testutil_sys_allocator,
                               128,
                               us_trie_basic_ignorer,
                               us_trie_basic_ignorer,
                               us_trie_basic_db_skip,
                               us_trie_basic_comparator );
    if ( trie )
    {
        int item = 0;
        struct us_test_trie_schema_entry_s *cur = &us_test_trie_schema[0];
        while ( cur && cur->m_address != 0 )
        {
            us_trie_add(
                &trie->m_base, (char *)cur->m_address, strlen( cur->m_address ), (unsigned short)item );
            item++;
            cur++;
        }
        r = 1;
        r &= us_test_trie_schema_dispatch( &trie->m_base, "/device/name", "", 0, 0 );
        r &= us_test_trie_schema_dispatch( &trie->m_base, "/device/system", "s", (void *)"new system name", 0 );
        r &= us_test_trie_schema_dispatch( &trie->m_base, "/device/name", "s", (void *)"new device name", 0 );
        r &= us_test_trie_schema_dispatch( &trie->m_base, "/device/system", "", 0, 0 );
        trie->destroy( trie );
    }
    return r;
}

variable_types: item int

user_defined_types: struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); }

user_defined_types: struct us_trie_node_s { short m_parent; short m_sibling; short m_child; char m_value; unsigned short m_flags; }


decompiled_code:
__int64 __fastcall us_test_trie_main(unsigned int a1, const char **a2)
{
unsigned int v3; // er12
int v4; // eax

if ( !(unsigned __int8)us_testutil_start(0x2000LL, 0x2000LL, a1, a2) )
return 1LL;
us_logger_printer_start(us_testutil_printer_stdout, us_testutil_printer_stderr);
us_log_level = 4;
us_log_info_proc("Hello world from %s compiled on %s", "../../../src/us_test_trie_main.c", "May 23 2025");
if ( (unsigned __int8)us_test_trie_1() && (unsigned __int8)us_test_trie_2() )
{
v4 = us_log_level;
v3 = 0;
LABEL_6:
if ( v4 > 2 )
us_log_info_proc("Finishing %s", *a2);
goto LABEL_8;
}
v3 = 1;
if ( us_log_level > 0 )
{
us_log_error_proc("Failed");
v4 = us_log_level;
goto LABEL_6;
}
LABEL_8:
us_logger_finish();
us_testutil_finish();
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, const char **a2)
{
unsigned int v3; // er12
int v4; // eax

if ( !(unsigned __int8)us_testutil_start(0x2000LL, 0x2000LL, a1, a2) )
return 1LL;
us_logger_printer_start(us_testutil_printer_stdout, us_testutil_printer_stderr);
us_log_level = 4;
us_log_info_proc("Hello world from %s compiled on %s", "../../../src/us_test_trie_main.c", "May 23 2025");
if ( (unsigned __int8)func4() && (unsigned __int8)func6() )
{
v4 = us_log_level;
v3 = 0;
LABEL_6:
if ( v4 > 2 )
us_log_info_proc("Finishing %s", *a2);
goto LABEL_8;
}
v3 = 1;
if ( us_log_level > 0 )
{
us_log_error_proc("Failed");
v4 = us_log_level;
goto LABEL_6;
}
LABEL_8:
us_logger_finish();
us_testutil_finish();
return v3;
}

original_code:
int us_test_trie_main( int argc, const char **argv )
{
    int r = 1;
    if ( us_testutil_start( 8192, 8192, argc, argv ) )
    {
        us_logger_printer_start( us_testutil_printer_stdout, us_testutil_printer_stderr );
        do { us_log_level = ( ( 4 ) ); } while ( 0 );
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Hello world from %s compiled on %s", "../../../src/us_test_trie_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_trie_1() && us_test_trie_2() )
            r = 0;
        if ( r != 0 )
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Failed" ); } while ( 0 );
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing %s", argv[0] ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}

canonical_original_code:
int us_test_trie_main(int argc, char **argv)
{
    int r = 1;
    if ( us_testutil_start( 8192, 8192, argc, argv ) )
    {
        us_logger_printer_start( us_testutil_printer_stdout, us_testutil_printer_stderr );
        do { us_log_level = ( ( 4 ) ); } while ( 0 );
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Hello world from %s compiled on %s", "../../../src/us_test_trie_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_trie_1() && us_test_trie_2() )
            r = 0;
        if ( r != 0 )
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Failed" ); } while ( 0 );
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing %s", argv[0] ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: r int


original_code:
us_trie_t *us_trie_init( us_trie_t *self,
                         uint16_t max_nodes,
                         uint16_t num_nodes,
                         us_trie_node_t *nodes,
                         us_trie_ignorer_proc query_ignorer,
                         us_trie_ignorer_proc db_ignorer,
                         us_trie_db_skip_proc db_skip,
                         us_trie_comparator_proc comparator )
{
    self->m_max_nodes = max_nodes;
    self->m_num_nodes = num_nodes;
    self->m_nodes = nodes;
    self->m_query_ignorer = query_ignorer;
    self->m_db_ignorer = db_ignorer;
    self->m_db_skip = db_skip;
    self->m_comparator = comparator;
    self->m_first_free = 0;
    return self;
}

canonical_original_code:
struct us_trie_s *us_trie_init(struct us_trie_s *self, unsigned short max_nodes, unsigned short num_nodes, struct us_trie_node_s *nodes, _Bool (*query_ignorer)(char), _Bool (*db_ignorer)(char), int (*db_skip)(char), int (*comparator)(char, char))
{
    self->m_max_nodes = max_nodes;
    self->m_num_nodes = num_nodes;
    self->m_nodes = nodes;
    self->m_query_ignorer = query_ignorer;
    self->m_db_ignorer = db_ignorer;
    self->m_db_skip = db_skip;
    self->m_comparator = comparator;
    self->m_first_free = 0;
    return self;
}

variable_types:
self
struct us_trie_s *

variable_types:
nodes
struct us_trie_node_s *

variable_types:
comparator
int (*)(char, char)

return_type: struct us_trie_s { short m_max_nodes; short m_num_nodes; struct us_trie_node_s { short m_parent; short m_sibling; short m_child; char m_value; unsigned short m_flags; } *m_nodes; short m_first_free; _Bool (*m_query_ignorer)(char); _Bool (*m_db_ignorer)(char); int (*m_db_skip)(char); int (*m_comparator)(char, char); } *


decompiled_code:
__int64 us_trie_basic_ignorer()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 0LL;
}

original_code:
_Bool us_trie_basic_ignorer( us_trie_node_value_t US_UNUSED_v __attribute__( ( unused ) ) )
{
    return 0;
}

canonical_original_code:
_Bool us_trie_basic_ignorer(char US_UNUSED_v)
{
    return 0;
}


decompiled_code:
__int64 us_trie_basic_db_skip()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 1LL;
}

original_code:
int us_trie_basic_db_skip( us_trie_node_value_t US_UNUSED_v __attribute__( ( unused ) ) )
{
    return 1;
}

canonical_original_code:
int us_trie_basic_db_skip(char US_UNUSED_v)
{
    return 1;
}


decompiled_code:
__int64 __fastcall us_trie_basic_comparator(char a1, char a2)
{
return (unsigned int)(a1 - a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1, char a2)
{
return (unsigned int)(a1 - a2);
}

original_code:
int us_trie_basic_comparator( us_trie_node_value_t a, us_trie_node_value_t b )
{
    return (int)( a - b );
}

canonical_original_code:
int us_trie_basic_comparator(char a, char b)
{
    return (int)( a - b );
}

variable_types: a char

variable_types: b char


original_code:
int us_trie_count( const us_trie_t *self )
{
    us_trie_node_id_t cnt = self->m_max_nodes;
    us_trie_node_id_t last = 0;
    us_trie_node_t *buf = self->m_nodes;
    us_trie_node_id_t i;
    for ( i = 0; i < cnt; ++i )
    {
        if ( !us_trie_node_is_free( &buf[i] ) )
            last = i;
    }
    return last + 1;
}

canonical_original_code:
int us_trie_count(struct us_trie_s *self)
{
    short cnt = self->m_max_nodes;
    short last = 0;
    struct us_trie_node_s *buf = self->m_nodes;
    short i;
    for ( i = 0; i < cnt; ++i )
    {
        if ( !us_trie_node_is_free( &buf[i] ) )
            last = i;
    }
    return last + 1;
}

variable_types: struct us_trie_s { short m_max_nodes; short m_num_nodes; struct us_trie_node_s { short m_parent; short m_sibling; short m_child; char m_value; unsigned short m_flags; } *m_nodes; short m_first_free; _Bool (*m_query_ignorer)(char); _Bool (*m_db_ignorer)(char); int (*m_db_skip)(char); int (*m_comparator)(char, char); } *

variable_types: cnt short

variable_types: last short

variable_types: i short


decompiled_code:
__int64 __fastcall us_trie_find_sibling(__int64 a1, __int16 a2, char a3, _WORD *a4)
{
unsigned int v4; // er14
__int64 v6; // rbp
__int64 v7; // r15
unsigned int v8; // eax
unsigned int v9; // er12

v4 = a3;
v6 = *(_QWORD *)(a1 + 8);
while ( 1 )
{
v7 = v6 + 10LL * a2;
LOBYTE(v8) = us_trie_node_is_free_isra_0(*(_WORD *)v7);
v9 = v8;
if ( (_BYTE)v8 )
return 0;
if ( !(unsigned __int8)us_trie_node_is_end_isra_0(*(_WORD *)(v7 + 8))
&& !(*(unsigned int (__fastcall **)(_QWORD, _QWORD))(a1 + 48))((unsigned int)*(char *)(v7 + 6), v4) )
{
break;
}
if ( !*(_WORD *)(v7 + 2) )
{
*a4 = a2;
return v9;
}
a2 = *(_WORD *)(v7 + 2);
}
v9 = 1;
*a4 = a2;
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int16 a2, char a3, _WORD *a4)
{
unsigned int v4; // er14
__int64 v6; // rbp
__int64 v7; // r15
unsigned int v8; // eax
unsigned int v9; // er12

v4 = a3;
v6 = *(_QWORD *)(a1 + 8);
while ( 1 )
{
v7 = v6 + 10LL * a2;
LOBYTE(v8) = func2(*(_WORD *)v7);
v9 = v8;
if ( (_BYTE)v8 )
return 0;
if ( !(unsigned __int8)func1(*(_WORD *)(v7 + 8))
&& !(*(unsigned int (__fastcall **)(_QWORD, _QWORD))(a1 + 48))((unsigned int)*(char *)(v7 + 6), v4) )
{
break;
}
if ( !*(_WORD *)(v7 + 2) )
{
*a4 = a2;
return v9;
}
a2 = *(_WORD *)(v7 + 2);
}
v9 = 1;
*a4 = a2;
return v9;
}

original_code:
_Bool
    us_trie_find_sibling( const us_trie_t *self, us_trie_node_id_t first_item, us_trie_node_value_t v, us_trie_node_id_t *item )
{
    const us_trie_node_t *buf = self->m_nodes;
    while ( !us_trie_node_is_free( &buf[first_item] ) )
    {
        if ( !us_trie_node_is_end( &buf[first_item] ) && self->m_comparator( buf[first_item].m_value, v ) == 0 )
        {
            *item = first_item;
            return 1;
        }
        else
        {
            if ( buf[first_item].m_sibling == 0 )
            {
                *item = first_item;
                return 0;
            }
            else
            {
                first_item = buf[first_item].m_sibling;
            }
        }
    }
    return 0;
}

canonical_original_code:
_Bool us_trie_find_sibling(struct us_trie_s *self, short first_item, char v, short *item)
{
    struct us_trie_node_s *buf = self->m_nodes;
    while ( !us_trie_node_is_free( &buf[first_item] ) )
    {
        if ( !us_trie_node_is_end( &buf[first_item] ) && self->m_comparator( buf[first_item].m_value, v ) == 0 )
        {
            *item = first_item;
            return 1;
        }
        else
        {
            if ( buf[first_item].m_sibling == 0 )
            {
                *item = first_item;
                return 0;
            }
            else
            {
                first_item = buf[first_item].m_sibling;
            }
        }
    }
    return 0;
}

variable_types: v char

variable_types:
item
short *

variable_types: struct us_trie_node_s { short m_parent; short m_sibling; short m_child; char m_value; unsigned short m_flags; } *


original_code:
_Bool us_trie_find( const us_trie_t *self,
                   const us_trie_node_value_t *list,
                   int16_t list_len,
                   us_trie_node_flags_t *flags,
                   int16_t *match_len,
                   us_trie_node_id_t *match_item,
                   us_trie_node_id_t initial_leaf_pos,
                   us_trie_node_id_t initial_list_pos )
{
    us_trie_node_t *buf = self->m_nodes;
    us_trie_node_id_t i = initial_leaf_pos;
    us_trie_node_id_t list_pos = initial_list_pos;
    while ( list_pos < list_len && self->m_query_ignorer( list[list_pos] ) )
        ++list_pos;
    while ( list_pos < list_len && !us_trie_node_is_free( &buf[i] ) )
    {
        if ( !us_trie_find_sibling( self, i, list[list_pos], &i ) )
        {
            return 0;
        }
        if ( buf[i].m_child )
        {
            us_trie_node_id_t j;
            if ( self->m_db_skip( buf[i].m_value ) == -1 )
                return 1;
            i = buf[i].m_child;
            for ( j = i; j != 0; j = buf[j].m_sibling )
            {
                if ( us_trie_node_is_end( &buf[j] ) )
                {
                    us_trie_node_id_t k;
                    for ( k = i; k != 0; k = buf[k].m_sibling )
                    {
                        if ( us_trie_find( self, list, list_len, flags, match_len, match_item, k, list_pos + 1 ) )
                        {
                            return 1;
                        }
                    }
                    if ( flags )
                        *flags = us_trie_node_get_flags( &buf[j] );
                    if ( match_len )
                        *match_len = list_pos + 1;
                    if ( match_item )
                        *match_item = j;
                    return 1;
                }
            }
        }
        else
        {
            if ( flags )
                *flags = us_trie_node_get_flags( &buf[i] );
            if ( match_len )
                *match_len = list_pos + 1;
            if ( match_item )
                *match_item = i;
            return 1;
        }
        while ( list_pos < list_len && self->m_query_ignorer( list[++list_pos] ) )
            ;
    }
    return 0;
}

canonical_original_code:
_Bool us_trie_find(struct us_trie_s *self, char *list, short list_len, unsigned short *flags, short *match_len, short *match_item, short initial_leaf_pos, short initial_list_pos)
{
    struct us_trie_node_s *buf = self->m_nodes;
    short i = initial_leaf_pos;
    short list_pos = initial_list_pos;
    while ( list_pos < list_len && self->m_query_ignorer( list[list_pos] ) )
        ++list_pos;
    while ( list_pos < list_len && !us_trie_node_is_free( &buf[i] ) )
    {
        if ( !us_trie_find_sibling( self, i, list[list_pos], &i ) )
        {
            return 0;
        }
        if ( buf[i].m_child )
        {
            short j;
            if ( self->m_db_skip( buf[i].m_value ) == -1 )
                return 1;
            i = buf[i].m_child;
            for ( j = i; j != 0; j = buf[j].m_sibling )
            {
                if ( us_trie_node_is_end( &buf[j] ) )
                {
                    short k;
                    for ( k = i; k != 0; k = buf[k].m_sibling )
                    {
                        if ( us_trie_find( self, list, list_len, flags, match_len, match_item, k, list_pos + 1 ) )
                        {
                            return 1;
                        }
                    }
                    if ( flags )
                        *flags = us_trie_node_get_flags( &buf[j] );
                    if ( match_len )
                        *match_len = list_pos + 1;
                    if ( match_item )
                        *match_item = j;
                    return 1;
                }
            }
        }
        else
        {
            if ( flags )
                *flags = us_trie_node_get_flags( &buf[i] );
            if ( match_len )
                *match_len = list_pos + 1;
            if ( match_item )
                *match_item = i;
            return 1;
        }
        while ( list_pos < list_len && self->m_query_ignorer( list[++list_pos] ) )
            ;
    }
    return 0;
}

variable_types:
list
char *

variable_types:
flags
unsigned short *

variable_types: j short

variable_types: k short


original_code:
int16_t us_trie_extract( const us_trie_t *self, us_trie_node_value_t *list, int16_t max_len, us_trie_node_id_t end_leaf_index )
{
    us_trie_node_t *buf = self->m_nodes;
    int16_t len = 0;
    us_trie_node_id_t cur_item = end_leaf_index;
    us_trie_node_value_t *p = list;
    if ( end_leaf_index < 0 )
    {
        return 0;
    }
    if ( us_trie_node_is_end( &buf[cur_item] ) )
    {
        cur_item = buf[cur_item].m_parent;
    }
    if ( cur_item < 0 )
    {
        return 0;
    }
    while ( len < max_len )
    {
        *p++ = buf[cur_item].m_value;
        len++;
        if ( buf[cur_item].m_parent == ( int16_t )( -2 ) )
        {
            if ( len > 1 )
            {
                uint16_t i;
                for ( i = 0; i < len / 2; ++i )
                {
                    us_trie_node_value_t tmp = list[i];
                    list[i] = list[len - i - 1];
                    list[len - i - 1] = tmp;
                }
            }
            return len;
        }
        cur_item = buf[cur_item].m_parent;
    }
    return 0;
}

canonical_original_code:
short us_trie_extract(struct us_trie_s *self, char *list, short max_len, short end_leaf_index)
{
    struct us_trie_node_s *buf = self->m_nodes;
    short len = 0;
    short cur_item = end_leaf_index;
    char *p = list;
    if ( end_leaf_index < 0 )
    {
        return 0;
    }
    if ( us_trie_node_is_end( &buf[cur_item] ) )
    {
        cur_item = buf[cur_item].m_parent;
    }
    if ( cur_item < 0 )
    {
        return 0;
    }
    while ( len < max_len )
    {
        *p++ = buf[cur_item].m_value;
        len++;
        if ( buf[cur_item].m_parent == ( short )( -2 ) )
        {
            if ( len > 1 )
            {
                unsigned short i;
                for ( i = 0; i < len / 2; ++i )
                {
                    char tmp = list[i];
                    list[i] = list[len - i - 1];
                    list[len - i - 1] = tmp;
                }
            }
            return len;
        }
        cur_item = buf[cur_item].m_parent;
    }
    return 0;
}

variable_types: len short

variable_types:
p
char *

variable_types:
i
unsigned short

variable_types: tmp char


decompiled_code:
void __fastcall us_osc_dispatch_index_init(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

original_code:
static inline void us_osc_dispatch_index_init( us_osc_dispatch_index_t *self )
{
    int i;
    for ( i = 0; i < ( 4 ); ++i )
        self->axis[i] = 0;
}

canonical_original_code:
static inline void us_osc_dispatch_index_init(struct us_osc_dispatch_index_s *self)
{
    int i;
    for ( i = 0; i < ( 4 ); ++i )
        self->axis[i] = 0;
}

variable_types: struct us_osc_dispatch_index_s { int axis[-1]; } *

variable_types: i int


decompiled_code:
__int64 __fastcall us_test_osc_dispatch_media_level(__int64 a1, __int64 a2, unsigned int *a3)
{
(*(void (**)(_QWORD, const char *, ...))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"%s received:",
"us_test_osc_dispatch_media_level");
(*(void (__fastcall **)(__int64, _QWORD))(a2 + 16))(a2, us_testutil_printer_stdout);
(*(void (**)(_QWORD, const char *, ...))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"\nindex values: %d,%d,%d,%d\n",
*a3,
a3[1],
a3[2],
a3[3]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int *a3)
{
(*(void (**)(_QWORD, const char *, ...))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"%s received:",
"us_test_osc_dispatch_media_level");
(*(void (__fastcall **)(__int64, _QWORD))(a2 + 16))(a2, us_testutil_printer_stdout);
(*(void (**)(_QWORD, const char *, ...))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"\nindex values: %d,%d,%d,%d\n",
*a3,
a3[1],
a3[2],
a3[3]);
return 1LL;
}

original_code:
static _Bool us_test_osc_dispatch_media_level( struct us_osc_dispatch_s *US_UNUSED_self __attribute__( ( unused ) ),
                                              const us_osc_msg_t *msg,
                                              const us_osc_dispatch_index_t *index,
                                              us_osc_sender_t *US_UNUSED_sender __attribute__( ( unused ) ),
                                              void *US_UNUSED_extra __attribute__( ( unused ) ) )
{
    us_testutil_printer_stdout->printf( us_testutil_printer_stdout, "%s received:", __FUNCTION__ );
    msg->print( msg, us_testutil_printer_stdout );
    us_testutil_printer_stdout->printf( us_testutil_printer_stdout,
                                        "\nindex values: %d,%d,%d,%d\n",
                                        index->axis[0],
                                        index->axis[1],
                                        index->axis[2],
                                        index->axis[3] );
    return 1;
}

canonical_original_code:
static _Bool us_test_osc_dispatch_media_level(struct us_osc_dispatch_s *US_UNUSED_self, struct us_osc_msg_s *msg, struct us_osc_dispatch_index_s *index, struct us_osc_sender_s *US_UNUSED_sender, void *US_UNUSED_extra)
{
    us_testutil_printer_stdout->printf( us_testutil_printer_stdout, "%s received:", __FUNCTION__ );
    msg->print( msg, us_testutil_printer_stdout );
    us_testutil_printer_stdout->printf( us_testutil_printer_stdout,
                                        "\nindex values: %d,%d,%d,%d\n",
                                        index->axis[0],
                                        index->axis[1],
                                        index->axis[2],
                                        index->axis[3] );
    return 1;
}

variable_types: struct us_osc_dispatch_s { void (*destroy)(struct us_osc_dispatch_s *self); _Bool (*receive_msg)(struct us_osc_dispatch_s *self, struct us_osc_msg_s { void (*destroy)(struct us_osc_msg_s *self); struct us_osc_msg_element_s { void (*destroy)(struct us_osc_msg_element_s *self, struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *allocator); _Bool (*print)(struct us_osc_msg_element_s *self, struct us_print_s { void (*destroy)(struct us_print_s *self); _Bool (*printf)(struct us_print_s *self, char *fmt, ...); _Bool (*vprintf)(struct us_print_s *self, char *fmt, __builtin_va_list ap); } *printer); _Bool (*flatten)(struct us_osc_msg_element_s *self, struct us_buffer_s { void (*destroy)(struct us_buffer_s *self); struct us_allocator_s *m_allocator; unsigned char *m_buffer; unsigned long m_next_in; unsigned long m_next_out; unsigned long m_max_length; } *buf, int *length); struct us_osc_msg_element_s *m_next; char m_code; } *(*append)(struct us_osc_msg_s *self, struct us_osc_msg_element_s *element); _Bool (*print)(struct us_osc_msg_s *self, struct us_print_s *printer); _Bool (*flatten)(struct us_osc_msg_s *self, struct us_buffer_s *buf, int *length); struct us_allocator_s *m_allocator; char *m_address; unsigned int m_address_code; struct us_osc_msg_element_s *m_first_element; struct us_osc_msg_element_s *m_last_element; struct us_osc_msg_s *m_next; } *msg, struct us_osc_sender_s { void (*destroy)(struct us_osc_sender_s *self); _Bool (*can_send)(struct us_osc_sender_s *self); _Bool (*send_msg)(struct us_osc_sender_s *self, struct us_osc_msg_s *msg); _Bool (*form_and_send_msg)(struct us_osc_sender_s *self, char *address, char *typetags, ...); } *sender, void *extra); struct us_allocator_s *allocator; struct us_trie_dyn_s { struct us_trie_s { short m_max_nodes; short m_num_nodes; struct us_trie_node_s { short m_parent; short m_sibling; short m_child; char m_value; unsigned short m_flags; } *m_nodes; short m_first_free; _Bool (*m_query_ignorer)(char); _Bool (*m_db_ignorer)(char); int (*m_db_skip)(char); int (*m_comparator)(char, char); } m_base; void (*destroy)(struct us_trie_dyn_s *); struct us_allocator_s *m_allocator; struct us_trie_node_s *m_nodes; } *trie; _Bool (*notify)(struct us_osc_dispatch_s *self, char *address, struct us_osc_dispatch_table_s { char *address; _Bool (*receive_msg_proc)(struct us_osc_dispatch_s *self, struct us_osc_msg_s *msg, struct us_osc_dispatch_index_s { int axis[-1]; } *index, struct us_osc_sender_s *sender, void *extra); struct us_osc_dispatch_index_s index; } *table_item, struct us_osc_dispatch_index_s *index); struct us_osc_dispatch_map_s { struct us_osc_dispatch_map_entry_s { struct us_osc_dispatch_table_s *table_entry; struct us_osc_dispatch_index_s final_index; } *entries; int max_entries; int num_entries; } map; } *

variable_types:
msg
struct us_osc_msg_s *

variable_types:
index
struct us_osc_dispatch_index_s *

user_defined_types: struct us_osc_dispatch_s { void (*destroy)(struct us_osc_dispatch_s *self); _Bool (*receive_msg)(struct us_osc_dispatch_s *self, struct us_osc_msg_s *msg, struct us_osc_sender_s *sender, void *extra); struct us_allocator_s *allocator; struct us_trie_dyn_s *trie; _Bool (*notify)(struct us_osc_dispatch_s *self, char *address, struct us_osc_dispatch_table_s *table_item, struct us_osc_dispatch_index_s *index); struct us_osc_dispatch_map_s map; }

user_defined_types: struct us_osc_dispatch_map_s { struct us_osc_dispatch_map_entry_s *entries; int max_entries; int num_entries; }

user_defined_types: struct us_osc_msg_s { void (*destroy)(struct us_osc_msg_s *self); struct us_osc_msg_element_s *(*append)(struct us_osc_msg_s *self, struct us_osc_msg_element_s *element); _Bool (*print)(struct us_osc_msg_s *self, struct us_print_s *printer); _Bool (*flatten)(struct us_osc_msg_s *self, struct us_buffer_s *buf, int *length); struct us_allocator_s *m_allocator; char *m_address; unsigned int m_address_code; struct us_osc_msg_element_s *m_first_element; struct us_osc_msg_element_s *m_last_element; struct us_osc_msg_s *m_next; }

user_defined_types: struct us_osc_dispatch_table_s { char *address; _Bool (*receive_msg_proc)(struct us_osc_dispatch_s *self, struct us_osc_msg_s *msg, struct us_osc_dispatch_index_s *index, struct us_osc_sender_s *sender, void *extra); struct us_osc_dispatch_index_s index; }

user_defined_types: struct us_osc_msg_element_s { void (*destroy)(struct us_osc_msg_element_s *self, struct us_allocator_s *allocator); _Bool (*print)(struct us_osc_msg_element_s *self, struct us_print_s *printer); _Bool (*flatten)(struct us_osc_msg_element_s *self, struct us_buffer_s *buf, int *length); struct us_osc_msg_element_s *m_next; char m_code; }


decompiled_code:
__int64 __fastcall us_test_osc_dispatch_media_pan(__int64 a1, __int64 a2, unsigned int *a3)
{
(*(void (**)(_QWORD, const char *, ...))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"%s received:",
"us_test_osc_dispatch_media_pan");
(*(void (__fastcall **)(__int64, _QWORD))(a2 + 16))(a2, us_testutil_printer_stdout);
(*(void (**)(_QWORD, const char *, ...))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"\nindex values: %d,%d,%d,%d\n",
*a3,
a3[1],
a3[2],
a3[3]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int *a3)
{
(*(void (**)(_QWORD, const char *, ...))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"%s received:",
"us_test_osc_dispatch_media_pan");
(*(void (__fastcall **)(__int64, _QWORD))(a2 + 16))(a2, us_testutil_printer_stdout);
(*(void (**)(_QWORD, const char *, ...))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"\nindex values: %d,%d,%d,%d\n",
*a3,
a3[1],
a3[2],
a3[3]);
return 1LL;
}

original_code:
static _Bool us_test_osc_dispatch_media_pan( struct us_osc_dispatch_s *US_UNUSED_self __attribute__( ( unused ) ),
                                            const us_osc_msg_t *msg,
                                            const us_osc_dispatch_index_t *index,
                                            us_osc_sender_t *US_UNUSED_sender __attribute__( ( unused ) ),
                                            void *US_UNUSED_extra __attribute__( ( unused ) ) )
{
    us_testutil_printer_stdout->printf( us_testutil_printer_stdout, "%s received:", __FUNCTION__ );
    msg->print( msg, us_testutil_printer_stdout );
    us_testutil_printer_stdout->printf( us_testutil_printer_stdout,
                                        "\nindex values: %d,%d,%d,%d\n",
                                        index->axis[0],
                                        index->axis[1],
                                        index->axis[2],
                                        index->axis[3] );
    return 1;
}

canonical_original_code:
static _Bool us_test_osc_dispatch_media_pan(struct us_osc_dispatch_s *US_UNUSED_self, struct us_osc_msg_s *msg, struct us_osc_dispatch_index_s *index, struct us_osc_sender_s *US_UNUSED_sender, void *US_UNUSED_extra)
{
    us_testutil_printer_stdout->printf( us_testutil_printer_stdout, "%s received:", __FUNCTION__ );
    msg->print( msg, us_testutil_printer_stdout );
    us_testutil_printer_stdout->printf( us_testutil_printer_stdout,
                                        "\nindex values: %d,%d,%d,%d\n",
                                        index->axis[0],
                                        index->axis[1],
                                        index->axis[2],
                                        index->axis[3] );
    return 1;
}

user_defined_types: struct us_osc_dispatch_map_entry_s { struct us_osc_dispatch_table_s *table_entry; struct us_osc_dispatch_index_s final_index; }

user_defined_types: struct us_osc_sender_s { void (*destroy)(struct us_osc_sender_s *self); _Bool (*can_send)(struct us_osc_sender_s *self); _Bool (*send_msg)(struct us_osc_sender_s *self, struct us_osc_msg_s *msg); _Bool (*form_and_send_msg)(struct us_osc_sender_s *self, char *address, char *typetags, ...); }

user_defined_types: struct us_osc_dispatch_index_s { int axis[-1]; }

user_defined_types: struct us_print_s { void (*destroy)(struct us_print_s *self); _Bool (*printf)(struct us_print_s *self, char *fmt, ...); _Bool (*vprintf)(struct us_print_s *self, char *fmt, __builtin_va_list ap); }

user_defined_types: struct us_buffer_s { void (*destroy)(struct us_buffer_s *self); struct us_allocator_s *m_allocator; unsigned char *m_buffer; unsigned long m_next_in; unsigned long m_next_out; unsigned long m_max_length; }