repo: medigeek/isdst

decompiled_code:
_BOOL8 __fastcall compare_live(time_t a1, time_t a2)
{
int v2; // ebx
time_t v4; // [rsp+0h] [rbp-18h] BYREF
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v4 = a2;
v2 = localtime(&timer)->tm_isdst;
return localtime(&v4)->tm_isdst != v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(time_t a1, time_t a2)
{
int v2; // ebx
time_t v4; // [rsp+0h] [rbp-18h] BYREF
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v4 = a2;
v2 = localtime(&timer)->tm_isdst;
return localtime(&v4)->tm_isdst != v2;
}

original_code:
int compare_live(time_t now, time_t now2) {
    struct tm *tnow2;
    int isdst2;
    int isdst;
    struct tm *tm_now;
    tm_now = localtime(&now);
    isdst = tm_now->tm_isdst;
    tnow2 = localtime(&now2);
    isdst2 = tnow2->tm_isdst;
    if (isdst2 == isdst) { return 0; }
    else { return 1; }
}

canonical_original_code:
int compare_live(long now, long now2) {
    struct tm *tnow2;
    int isdst2;
    int isdst;
    struct tm *tm_now;
    tm_now = localtime(&now);
    isdst = tm_now->tm_isdst;
    tnow2 = localtime(&now2);
    isdst2 = tnow2->tm_isdst;
    if (isdst2 == isdst) { return 0; }
    else { return 1; }
}

variable_types: now long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: isdst int


dstnotify

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

timer = a1;
if ( localtime(&timer)->tm_isdst == 1 )
{
puts("dstnotify(): Daylight savings time is in effect.");
libnotify_notify("DST in effect!", "Daylight savings time is in effect.");
}
else
{
puts("dstnotify(): Daylight savings time is not in effect anymore.");
libnotify_notify("DST not in effect!", "Daylight savings time is not in effect anymore.");
}
return 0LL;
}

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

timer = a1;
if ( localtime(&timer)->tm_isdst == 1 )
{
puts("dstnotify(): Daylight savings time is in effect.");
func8("DST in effect!", "Daylight savings time is in effect.");
}
else
{
puts("dstnotify(): Daylight savings time is not in effect anymore.");
func8("DST not in effect!", "Daylight savings time is not in effect anymore.");
}
return 0LL;
}

original_code:
int dstnotify(time_t now) {
    struct tm *tm_now;
    int isdst;
    tm_now = localtime(&now);
    isdst = tm_now->tm_isdst;
    if (isdst == 1) {
        printf("dstnotify(): Daylight savings time is in effect.\n");
        libnotify_notify("DST in effect!", "Daylight savings time is in effect.");
    } else {
        printf("dstnotify(): Daylight savings time is not in effect anymore.\n");
        libnotify_notify("DST not in effect!", "Daylight savings time is not in effect anymore.");
    }
    return 0;
}

canonical_original_code:
int dstnotify(long now) {
    struct tm *tm_now;
    int isdst;
    tm_now = localtime(&now);
    isdst = tm_now->tm_isdst;
    if (isdst == 1) {
        printf("dstnotify(): Daylight savings time is in effect.\n");
        libnotify_notify("DST in effect!", "Daylight savings time is in effect.");
    } else {
        printf("dstnotify(): Daylight savings time is not in effect anymore.\n");
        libnotify_notify("DST not in effect!", "Daylight savings time is not in effect anymore.");
    }
    return 0;
}

return_type: int

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


main

canonical_name: main

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

signal(2, (__sighandler_t)terminate);
signal(15, (__sighandler_t)terminate);
v3 = time(0LL);
if ( compare_fromfile(v3) )
{
dstnotify(v3);
puts("ALARM! DST changed since last check!");
}
while ( 1 )
{
v4 = time(0LL);
if ( compare_live(v3, v4) )
{
dstnotify(v3);
puts("LIVE ALARM! DST changed since last live check!");
}
else
{
dstnotify(v3);
puts("No changes detected in DST. Sleeping...");
}
sleep(0xAu);
v3 = v4;
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
time_t v3; // rbp
time_t v4; // rbx

signal(2, (__sighandler_t)terminate);
signal(15, (__sighandler_t)terminate);
v3 = time(0LL);
if ( func10(v3) )
{
func12(v3);
puts("ALARM! DST changed since last check!");
}
while ( 1 )
{
v4 = time(0LL);
if ( func11(v3, v4) )
{
func12(v3);
puts("LIVE ALARM! DST changed since last live check!");
}
else
{
func12(v3);
puts("No changes detected in DST. Sleeping...");
}
sleep(0xAu);
v3 = v4;
}
}

original_code:
int main(void) {
    signal(2, terminate);
    signal(15, terminate);
    time_t now;
    time_t now2;
    int cmpfile;
    int cmplive;
    now = time(((void *)0));
    cmpfile = compare_fromfile(now);
    if (cmpfile == 1) {
        dstnotify(now);
        printf("ALARM! DST changed since last check!\n");
    }
    while (1)
    {
        now2 = time(((void *)0));
        cmplive = compare_live(now, now2);
        if (cmplive == 1)
        {
            dstnotify(now);
            printf("LIVE ALARM! DST changed since last live check!\n");
        }
        else
        {
            dstnotify(now);
            printf("No changes detected in DST. Sleeping...\n");
        }
        now = now2;
        sleep(10);
    }
    return 0;
}

canonical_original_code:
int main() {
    signal(2, terminate);
    signal(15, terminate);
    long now;
    long now2;
    int cmpfile;
    int cmplive;
    now = time(((void *)0));
    cmpfile = compare_fromfile(now);
    if (cmpfile == 1) {
        dstnotify(now);
        printf("ALARM! DST changed since last check!\n");
    }
    while (1)
    {
        now2 = time(((void *)0));
        cmplive = compare_live(now, now2);
        if (cmplive == 1)
        {
            dstnotify(now);
            printf("LIVE ALARM! DST changed since last live check!\n");
        }
        else
        {
            dstnotify(now);
            printf("No changes detected in DST. Sleeping...\n");
        }
        now = now2;
        sleep(10);
    }
    return 0;
}

variable_types: cmpfile int

variable_types: cmplive int


fatal

repo: medmunds/puzzles

decompiled_code:
void __noreturn fatal(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("fatal error: ", 1uLL, 0xDuLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func27(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("fatal error: ", 1uLL, 0xDuLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

original_code:
void fatal(char *fmt, ...)
{
    va_list ap;
    fprintf(stderr, "fatal error: ");
    __builtin_va_start(ap,fmt);
    vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
    fprintf(stderr, "\n");
    exit(1);
}

canonical_original_code:
void fatal(char *fmt, ...)
{
    __builtin_va_list ap;
    fprintf(stderr, "fatal error: ");
    __builtin_va_start(ap,fmt);
    vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
    fprintf(stderr, "\n");
    exit(1);
}

variable_types:
fmt
char *

return_type: void


original_code:
tdq *tdq_new(int n)
{
    int i;
    tdq *tdq = ( (struct tdq *) smalloc (sizeof (struct tdq)) );
    tdq->queue = ( (int *) smalloc ((n) * sizeof (int)) );
    tdq->flags = ( (char *) smalloc ((n) * sizeof (char)) );
    for (i = 0; i < n; i++) {
        tdq->queue[i] = 0;
        tdq->flags[i] = 0;
    }
    tdq->n = n;
    tdq->ip = tdq->op = 0;
    return tdq;
}

canonical_original_code:
struct tdq *tdq_new(int n)
{
    int i;
    struct tdq *tdq = ( (struct tdq *) smalloc (sizeof (struct tdq)) );
    tdq->queue = ( (int *) smalloc ((n) * sizeof (int)) );
    tdq->flags = ( (char *) smalloc ((n) * sizeof (char)) );
    for (i = 0; i < n; i++) {
        tdq->queue[i] = 0;
        tdq->flags[i] = 0;
    }
    tdq->n = n;
    tdq->ip = tdq->op = 0;
    return tdq;
}

variable_types: n int

variable_types: i int

variable_types: struct tdq { int n; int *queue; int ip; char *flags; } *


decompiled_code:
__int64 __fastcall tdq_free(__int64 a1)
{
sfree(*(_QWORD *)(a1 + 8));
sfree(*(_QWORD *)(a1 + 24));
return sfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
sfree(*(_QWORD *)(a1 + 8));
sfree(*(_QWORD *)(a1 + 24));
return sfree(a1);
}

original_code:
void tdq_free(tdq *tdq)
{
    sfree(tdq->queue);
    sfree(tdq->flags);
    sfree(tdq);
}

canonical_original_code:
void tdq_free(struct tdq *tdq)
{
    sfree(tdq->queue);
    sfree(tdq->flags);
    sfree(tdq);
}

user_defined_types: struct tdq { int n; int *queue; int ip; char *flags; }


decompiled_code:
__int64 __fastcall tdq_add(__int64 a1, unsigned int a2)
{
__int64 result; // rax

if ( *(_DWORD *)a1 <= a2 )
_assert_fail("(unsigned)k < (unsigned)tdq->n", "tdq.c", 0x3Cu, "tdq_add");
result = (int)a2;
if ( !*(_BYTE *)(*(_QWORD *)(a1 + 24) + (int)a2) )
{
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * *(int *)(a1 + 16)) = a2;
*(_BYTE *)(*(_QWORD *)(a1 + 24) + (int)a2) = 1;
result = (unsigned int)(*(_DWORD *)(a1 + 16) + 1);
*(_DWORD *)(a1 + 16) = result;
if ( (_DWORD)result == *(_DWORD *)a1 )
*(_DWORD *)(a1 + 16) = 0;
}
return result;
}

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

if ( *(_DWORD *)a1 <= a2 )
_assert_fail("(unsigned)k < (unsigned)tdq->n", "tdq.c", 0x3Cu, "tdq_add");
result = (int)a2;
if ( !*(_BYTE *)(*(_QWORD *)(a1 + 24) + (int)a2) )
{
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * *(int *)(a1 + 16)) = a2;
*(_BYTE *)(*(_QWORD *)(a1 + 24) + (int)a2) = 1;
result = (unsigned int)(*(_DWORD *)(a1 + 16) + 1);
*(_DWORD *)(a1 + 16) = result;
if ( (_DWORD)result == *(_DWORD *)a1 )
*(_DWORD *)(a1 + 16) = 0;
}
return result;
}

original_code:
void tdq_add(tdq *tdq, int k)
{
    (((unsigned)k < (unsigned)tdq->n) ? (void) (0) : __assert_fail ("(unsigned)k < (unsigned)tdq->n", "tdq.c", 60, __extension__ __PRETTY_FUNCTION__));
    if (!tdq->flags[k]) {
        tdq->queue[tdq->ip] = k;
        tdq->flags[k] = 1;
        if (++tdq->ip == tdq->n)
            tdq->ip = 0;
    }
}

canonical_original_code:
void tdq_add(struct tdq *tdq, int k)
{
    (((unsigned int)k < (unsigned int)tdq->n) ? (void) (0) : __assert_fail ("(unsigned)k < (unsigned)tdq->n", "tdq.c", 60, __extension__ __PRETTY_FUNCTION__));
    if (!tdq->flags[k]) {
        tdq->queue[tdq->ip] = k;
        tdq->flags[k] = 1;
        if (++tdq->ip == tdq->n)
            tdq->ip = 0;
    }
}

variable_types: k int


original_code:
int tdq_remove(tdq *tdq)
{
    int ret = tdq->queue[tdq->op];
    if (!tdq->flags[ret])
        return -1;
    tdq->flags[ret] = 0;
    if (++tdq->op == tdq->n)
        tdq->op = 0;
    return ret;
}

canonical_original_code:
int tdq_remove(struct tdq *tdq)
{
    int ret = tdq->queue[tdq->op];
    if (!tdq->flags[ret])
        return -1;
    tdq->flags[ret] = 0;
    if (++tdq->op == tdq->n)
        tdq->op = 0;
    return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall tdq_fill(signed int *a1)
{
signed int v1; // ebx
__int64 result; // rax

if ( *a1 > 0 )
{
v1 = 0;
do
result = tdq_add((__int64)a1, v1++);
while ( *a1 > v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(signed int *a1)
{
signed int v1; // ebx
__int64 result; // rax

if ( *a1 > 0 )
{
v1 = 0;
do
result = func2((__int64)a1, v1++);
while ( *a1 > v1 );
}
return result;
}

original_code:
void tdq_fill(tdq *tdq)
{
    int i;
    for (i = 0; i < tdq->n; i++)
        tdq_add(tdq, i);
}

canonical_original_code:
void tdq_fill(struct tdq *tdq)
{
    int i;
    for (i = 0; i < tdq->n; i++)
        tdq_add(tdq, i);
}


original_code:
int maxflow_with_scratch(void *scratch, int nv, int source, int sink,
    int ne, const int *edges, const int *backedges,
    const int *capacity, int *flow, int *cut)
{
    int *todo = (int *)scratch;
    int *prev = todo + nv;
    int *firstedge = todo + 2*nv;
    int *firstbackedge = todo + 3*nv;
    int i, j, head, tail, from, to;
    int totalflow;
    j = 0;
    for (i = 0; i < ne; i++)
 while (j <= edges[2*i])
     firstedge[j++] = i;
    while (j < nv)
 firstedge[j++] = ne;
    ((j == nv) ? (void) (0) : __assert_fail ("j == nv", "maxflow.c", 42, __extension__ __PRETTY_FUNCTION__));
    j = 0;
    for (i = 0; i < ne; i++)
 while (j <= edges[2*backedges[i]+1])
     firstbackedge[j++] = i;
    while (j < nv)
 firstbackedge[j++] = ne;
    ((j == nv) ? (void) (0) : __assert_fail ("j == nv", "maxflow.c", 54, __extension__ __PRETTY_FUNCTION__));
    for (i = 0; i < ne; i++)
 flow[i] = 0;
    totalflow = 0;
    while (1) {
 for (i = 0; i < nv; i++)
     prev[i] = -1;
 head = tail = 0;
 todo[tail++] = source;
 while (head < tail && prev[sink] <= 0) {
     from = todo[head++];
     for (i = firstedge[from]; i < ne && edges[2*i] == from; i++) {
  to = edges[2*i+1];
  if (to == source || prev[to] >= 0)
      continue;
  if (capacity[i] >= 0 && flow[i] >= capacity[i])
      continue;
  prev[to] = 2*i;
  todo[tail++] = to;
     }
     for (i = firstbackedge[from];
   j = backedges[i], i < ne && edges[2*j+1]==from; i++) {
  to = edges[2*j];
  if (to == source || prev[to] >= 0)
      continue;
  if (flow[j] <= 0)
      continue;
  prev[to] = 2*j+1;
  todo[tail++] = to;
     }
 }
 if (prev[sink] >= 0) {
     int max;
     to = sink;
     max = -1;
     while (to != source) {
  int spare;
  i = prev[to];
  from = edges[i];
  ((from != to) ? (void) (0) : __assert_fail ("from != to", "maxflow.c", 145, __extension__ __PRETTY_FUNCTION__));
  if (i & 1)
      spare = flow[i / 2];
  else if (capacity[i / 2] >= 0)
      spare = capacity[i / 2] - flow[i / 2];
  else
      spare = -1;
  ((spare != 0) ? (void) (0) : __assert_fail ("spare != 0", "maxflow.c", 157, __extension__ __PRETTY_FUNCTION__));
  if (max < 0 || (spare >= 0 && spare < max))
      max = spare;
  to = from;
     }
     ((max > 0) ? (void) (0) : __assert_fail ("max > 0", "maxflow.c", 170, __extension__ __PRETTY_FUNCTION__));
     to = sink;
     while (to != source) {
  i = prev[to];
  from = edges[i];
  ((from != to) ? (void) (0) : __assert_fail ("from != to", "maxflow.c", 183, __extension__ __PRETTY_FUNCTION__));
  if (i & 1)
      flow[i / 2] -= max;
  else
      flow[i / 2] += max;
  to = from;
     }
     totalflow += max;
     continue;
 }
 if (cut) {
     for (i = 0; i < nv; i++) {
  if (i == source || prev[i] >= 0)
      cut[i] = 0;
  else
      cut[i] = 1;
     }
 }
 return totalflow;
    }
}

canonical_original_code:
int maxflow_with_scratch(void *scratch, int nv, int source, int sink, int ne, int *edges, int *backedges, int *capacity, int *flow, int *cut)
{
    int *todo = (int *)scratch;
    int *prev = todo + nv;
    int *firstedge = todo + 2*nv;
    int *firstbackedge = todo + 3*nv;
    int i; int j; int head; int tail; int from; int to;
    int totalflow;
    j = 0;
    for (i = 0; i < ne; i++)
 while (j <= edges[2*i])
     firstedge[j++] = i;
    while (j < nv)
 firstedge[j++] = ne;
    ((j == nv) ? (void) (0) : __assert_fail ("j == nv", "maxflow.c", 42, __extension__ __PRETTY_FUNCTION__));
    j = 0;
    for (i = 0; i < ne; i++)
 while (j <= edges[2*backedges[i]+1])
     firstbackedge[j++] = i;
    while (j < nv)
 firstbackedge[j++] = ne;
    ((j == nv) ? (void) (0) : __assert_fail ("j == nv", "maxflow.c", 54, __extension__ __PRETTY_FUNCTION__));
    for (i = 0; i < ne; i++)
 flow[i] = 0;
    totalflow = 0;
    while (1) {
 for (i = 0; i < nv; i++)
     prev[i] = -1;
 head = tail = 0;
 todo[tail++] = source;
 while (head < tail && prev[sink] <= 0) {
     from = todo[head++];
     for (i = firstedge[from]; i < ne && edges[2*i] == from; i++) {
  to = edges[2*i+1];
  if (to == source || prev[to] >= 0)
      continue;
  if (capacity[i] >= 0 && flow[i] >= capacity[i])
      continue;
  prev[to] = 2*i;
  todo[tail++] = to;
     }
     for (i = firstbackedge[from];
   j = backedges[i], i < ne && edges[2*j+1]==from; i++) {
  to = edges[2*j];
  if (to == source || prev[to] >= 0)
      continue;
  if (flow[j] <= 0)
      continue;
  prev[to] = 2*j+1;
  todo[tail++] = to;
     }
 }
 if (prev[sink] >= 0) {
     int max;
     to = sink;
     max = -1;
     while (to != source) {
  int spare;
  i = prev[to];
  from = edges[i];
  ((from != to) ? (void) (0) : __assert_fail ("from != to", "maxflow.c", 145, __extension__ __PRETTY_FUNCTION__));
  if (i & 1)
      spare = flow[i / 2];
  else if (capacity[i / 2] >= 0)
      spare = capacity[i / 2] - flow[i / 2];
  else
      spare = -1;
  ((spare != 0) ? (void) (0) : __assert_fail ("spare != 0", "maxflow.c", 157, __extension__ __PRETTY_FUNCTION__));
  if (max < 0 || (spare >= 0 && spare < max))
      max = spare;
  to = from;
     }
     ((max > 0) ? (void) (0) : __assert_fail ("max > 0", "maxflow.c", 170, __extension__ __PRETTY_FUNCTION__));
     to = sink;
     while (to != source) {
  i = prev[to];
  from = edges[i];
  ((from != to) ? (void) (0) : __assert_fail ("from != to", "maxflow.c", 183, __extension__ __PRETTY_FUNCTION__));
  if (i & 1)
      flow[i / 2] -= max;
  else
      flow[i / 2] += max;
  to = from;
     }
     totalflow += max;
     continue;
 }
 if (cut) {
     for (i = 0; i < nv; i++) {
  if (i == source || prev[i] >= 0)
      cut[i] = 0;
  else
      cut[i] = 1;
     }
 }
 return totalflow;
    }
}

variable_types:
scratch
void *

variable_types: nv int

variable_types: source int

variable_types: sink int

variable_types: ne int

variable_types:
edges
int *

variable_types:
backedges
int *

variable_types:
capacity
int *

variable_types:
flow
int *

variable_types:
cut
int *

variable_types:
todo
int *

variable_types:
prev
int *

variable_types:
firstedge
int *

variable_types:
firstbackedge
int *

variable_types: j int

variable_types: head int

variable_types: tail int

variable_types: from int

variable_types: to int

variable_types: totalflow int

variable_types: max int

variable_types: spare int


decompiled_code:
__int64 __fastcall maxflow_scratch_size(int a1)
{
return (unsigned int)(16 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned int)(16 * a1);
}

original_code:
int maxflow_scratch_size(int nv)
{
    return (nv * 4) * sizeof(int);
}

variable_types: nv int


original_code:
void maxflow_setup_backedges(int ne, const int *edges, int *backedges)
{
    int i, n;
    for (i = 0; i < ne; i++)
 backedges[i] = i;
    n = 0;
    while (n < ne) {
 n++;
 i = n-1;
 while (i > 0) {
     int p = ( ((i)-1)/2 );
     if (( (edges[2*(backedges[p])+1] < edges[2*(backedges[i])+1]) || (edges[2*(backedges[p])+1] == edges[2*(backedges[i])+1] && edges[2*(backedges[p])] < edges[2*(backedges[i])]) )) {
  do { int swaptmp = (backedges[p]); (backedges[p]) = (backedges[i]); (backedges[i]) = swaptmp; } while (0);
  i = p;
     } else
  break;
 }
    }
    while (n > 0) {
 n--;
 do { int swaptmp = (backedges[0]); (backedges[0]) = (backedges[n]); (backedges[n]) = swaptmp; } while (0);
 i = 0;
 while (1) {
     int lc, rc;
     lc = ( 2*(i)+1 );
     rc = ( 2*(i)+2 );
     if (lc >= n)
  break;
     if (rc >= n) {
  if (( (edges[2*(backedges[i])+1] < edges[2*(backedges[lc])+1]) || (edges[2*(backedges[i])+1] == edges[2*(backedges[lc])+1] && edges[2*(backedges[i])] < edges[2*(backedges[lc])]) ))
      do { int swaptmp = (backedges[i]); (backedges[i]) = (backedges[lc]); (backedges[lc]) = swaptmp; } while (0);
  break;
     } else {
  if (( (edges[2*(backedges[i])+1] < edges[2*(backedges[lc])+1]) || (edges[2*(backedges[i])+1] == edges[2*(backedges[lc])+1] && edges[2*(backedges[i])] < edges[2*(backedges[lc])]) ) ||
      ( (edges[2*(backedges[i])+1] < edges[2*(backedges[rc])+1]) || (edges[2*(backedges[i])+1] == edges[2*(backedges[rc])+1] && edges[2*(backedges[i])] < edges[2*(backedges[rc])]) )) {
      if (( (edges[2*(backedges[lc])+1] < edges[2*(backedges[rc])+1]) || (edges[2*(backedges[lc])+1] == edges[2*(backedges[rc])+1] && edges[2*(backedges[lc])] < edges[2*(backedges[rc])]) )) {
   do { int swaptmp = (backedges[i]); (backedges[i]) = (backedges[rc]); (backedges[rc]) = swaptmp; } while (0);
   i = rc;
      } else {
   do { int swaptmp = (backedges[i]); (backedges[i]) = (backedges[lc]); (backedges[lc]) = swaptmp; } while (0);
   i = lc;
      }
  } else {
      break;
  }
     }
 }
    }
}

canonical_original_code:
void maxflow_setup_backedges(int ne, int *edges, int *backedges)
{
    int i; int n;
    for (i = 0; i < ne; i++)
 backedges[i] = i;
    n = 0;
    while (n < ne) {
 n++;
 i = n-1;
 while (i > 0) {
     int p = ( ((i)-1)/2 );
     if (( (edges[2*(backedges[p])+1] < edges[2*(backedges[i])+1]) || (edges[2*(backedges[p])+1] == edges[2*(backedges[i])+1] && edges[2*(backedges[p])] < edges[2*(backedges[i])]) )) {
  do { int swaptmp = (backedges[p]); (backedges[p]) = (backedges[i]); (backedges[i]) = swaptmp; } while (0);
  i = p;
     } else
  break;
 }
    }
    while (n > 0) {
 n--;
 do { int swaptmp = (backedges[0]); (backedges[0]) = (backedges[n]); (backedges[n]) = swaptmp; } while (0);
 i = 0;
 while (1) {
     int lc; int rc;
     lc = ( 2*(i)+1 );
     rc = ( 2*(i)+2 );
     if (lc >= n)
  break;
     if (rc >= n) {
  if (( (edges[2*(backedges[i])+1] < edges[2*(backedges[lc])+1]) || (edges[2*(backedges[i])+1] == edges[2*(backedges[lc])+1] && edges[2*(backedges[i])] < edges[2*(backedges[lc])]) ))
      do { int swaptmp = (backedges[i]); (backedges[i]) = (backedges[lc]); (backedges[lc]) = swaptmp; } while (0);
  break;
     } else {
  if (( (edges[2*(backedges[i])+1] < edges[2*(backedges[lc])+1]) || (edges[2*(backedges[i])+1] == edges[2*(backedges[lc])+1] && edges[2*(backedges[i])] < edges[2*(backedges[lc])]) ) ||
      ( (edges[2*(backedges[i])+1] < edges[2*(backedges[rc])+1]) || (edges[2*(backedges[i])+1] == edges[2*(backedges[rc])+1] && edges[2*(backedges[i])] < edges[2*(backedges[rc])]) )) {
      if (( (edges[2*(backedges[lc])+1] < edges[2*(backedges[rc])+1]) || (edges[2*(backedges[lc])+1] == edges[2*(backedges[rc])+1] && edges[2*(backedges[lc])] < edges[2*(backedges[rc])]) )) {
   do { int swaptmp = (backedges[i]); (backedges[i]) = (backedges[rc]); (backedges[rc]) = swaptmp; } while (0);
   i = rc;
      } else {
   do { int swaptmp = (backedges[i]); (backedges[i]) = (backedges[lc]); (backedges[lc]) = swaptmp; } while (0);
   i = lc;
      }
  } else {
      break;
  }
     }
 }
    }
}

variable_types: ne int

variable_types:
edges
int *

variable_types:
backedges
int *

variable_types: i int

variable_types: n int

variable_types: p int

variable_types: swaptmp int

variable_types: lc int

variable_types: rc int


maxflow

decompiled_code:
__int64 __fastcall maxflow(int a1, int a2, int a3, int a4, int *a5, __int64 a6, _DWORD *a7, __int64 a8)
{
__int64 v11; // r15
int v12; // eax
int *v13; // rax
int *v14; // rbx
int *v15; // r15
unsigned int v16; // ebp

v11 = a4;
v12 = maxflow_scratch_size(a1);
v13 = (int *)smalloc(v12 + 4 * a4);
if ( !v13 )
return (unsigned int)-1;
v14 = v13;
v15 = &v13[v11];
maxflow_setup_backedges(a4, (__int64)a5, v13);
v16 = maxflow_with_scratch(v15, a1, a2, a3, a4, a5, v14, a6, a7, a8);
sfree(v14);
return v16;
}

original_code:
int maxflow(int nv, int source, int sink,
     int ne, const int *edges, const int *capacity,
     int *flow, int *cut)
{
    void *scratch;
    int *backedges;
    int size;
    int ret;
    size = ne * sizeof(int) + maxflow_scratch_size(nv);
    backedges = smalloc(size);
    if (!backedges)
 return -1;
    scratch = backedges + ne;
    maxflow_setup_backedges(ne, edges, backedges);
    ret = maxflow_with_scratch(scratch, nv, source, sink, ne, edges,
          backedges, capacity, flow, cut);
    sfree(backedges);
    return ret;
}

canonical_original_code:
int maxflow(int nv, int source, int sink, int ne, int *edges, int *capacity, int *flow, int *cut)
{
    void *scratch;
    int *backedges;
    int size;
    int ret;
    size = ne * sizeof(int) + maxflow_scratch_size(nv);
    backedges = smalloc(size);
    if (!backedges)
 return -1;
    scratch = backedges + ne;
    maxflow_setup_backedges(ne, edges, backedges);
    ret = maxflow_with_scratch(scratch, nv, source, sink, ne, edges,
          backedges, capacity, flow, cut);
    sfree(backedges);
    return ret;
}

variable_types: source int

variable_types: sink int

variable_types:
capacity
int *

variable_types:
flow
int *

variable_types:
cut
int *

variable_types:
scratch
void *

variable_types: size int

variable_types: ret int


factx

decompiled_code:
__int64 __fastcall factx(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
__int64 result; // rax

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

original_code:
static long factx(long x, long y)
{
    long acc = 1, i;
    for (i = y; i <= x; i++)
        acc *= i;
    return acc;
}

canonical_original_code:
static long factx(long x, long y)
{
    long acc = 1; long i;
    for (i = y; i <= x; i++)
        acc *= i;
    return acc;
}

variable_types: x long

variable_types: y long

variable_types: acc long

variable_types: i long

return_type: long


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

result = *(unsigned int *)(a1 + 12);
*(_DWORD *)(a1 + 8) = result;
if ( *(int *)a1 > 0 )
{
result = 0LL;
do
{
*(_DWORD *)(*(_QWORD *)(a1 + 16) + 4 * result) = result;
++result;
}
while ( *(_DWORD *)a1 > (int)result );
}
return result;
}

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

result = *(unsigned int *)(a1 + 12);
*(_DWORD *)(a1 + 8) = result;
if ( *(int *)a1 > 0 )
{
result = 0LL;
do
{
*(_DWORD *)(*(_QWORD *)(a1 + 16) + 4 * result) = result;
++result;
}
while ( *(_DWORD *)a1 > (int)result );
}
return result;
}

original_code:
void reset_combi(combi_ctx *combi)
{
    int i;
    combi->nleft = combi->total;
    for (i = 0; i < combi->r; i++)
        combi->a[i] = i;
}

canonical_original_code:
void reset_combi(struct _combi_ctx *combi)
{
    int i;
    combi->nleft = combi->total;
    for (i = 0; i < combi->r; i++)
        combi->a[i] = i;
}

variable_types:
combi
struct _combi_ctx { int r; int *a; } *

variable_types: i int


decompiled_code:
__int64 __fastcall new_combi(int a1, int a2)
{
__int64 v2; // rbp
void *v3; // rax
__int64 v4; // r13

if ( a1 > a2 )
_assert_fail("r <= n", "combi.c", 0x1Du, "new_combi");
if ( a2 <= 0 )
_assert_fail("n >= 1", "combi.c", 0x1Eu, "new_combi");
v2 = smalloc(24LL);
*(_QWORD *)(v2 + 8) = 0LL;
*(_QWORD *)(v2 + 16) = 0LL;
*(_DWORD *)v2 = a1;
*(_DWORD *)(v2 + 4) = a2;
v3 = (void *)smalloc(4LL * a1);
*(_QWORD *)(v2 + 16) = v3;
memset(v3, 0, 4LL * a1);
v4 = factx(a2, a1 + 1);
*(_DWORD *)(v2 + 12) = v4 / factx(a2 - a1, 1LL);
reset_combi(v2);
return v2;
}

original_code:
combi_ctx *new_combi(int r, int n)
{
    long nfr, nrf;
    combi_ctx *combi;
    ((r <= n) ? (void) (0) : __assert_fail ("r <= n", "combi.c", 29, __extension__ __PRETTY_FUNCTION__));
    ((n >= 1) ? (void) (0) : __assert_fail ("n >= 1", "combi.c", 30, __extension__ __PRETTY_FUNCTION__));
    combi = ( (combi_ctx *) smalloc (sizeof (combi_ctx)) );
    memset(combi, 0, sizeof(combi_ctx));
    combi->r = r;
    combi->n = n;
    combi->a = ( (int *) smalloc ((r) * sizeof (int)) );
    memset(combi->a, 0, r * sizeof(int));
    nfr = factx(n, r+1);
    nrf = factx(n-r, 1);
    combi->total = (int)(nfr / nrf);
    reset_combi(combi);
    return combi;
}

canonical_original_code:
struct _combi_ctx *new_combi(int r, int n)
{
    long nfr; long nrf;
    struct _combi_ctx *combi;
    ((r <= n) ? (void) (0) : __assert_fail ("r <= n", "combi.c", 29, __extension__ __PRETTY_FUNCTION__));
    ((n >= 1) ? (void) (0) : __assert_fail ("n >= 1", "combi.c", 30, __extension__ __PRETTY_FUNCTION__));
    combi = ( (struct _combi_ctx *) smalloc (sizeof (combi_ctx)) );
    memset(combi, 0, sizeof(combi_ctx));
    combi->r = r;
    combi->n = n;
    combi->a = ( (int *) smalloc ((r) * sizeof (int)) );
    memset(combi->a, 0, r * sizeof(int));
    nfr = factx(n, r+1);
    nrf = factx(n-r, 1);
    combi->total = (int)(nfr / nrf);
    reset_combi(combi);
    return combi;
}

variable_types: r int

variable_types: n int

variable_types: nfr long

variable_types: nrf long

return_type: struct _combi_ctx { int r; int *a; } *


original_code:
combi_ctx *next_combi(combi_ctx *combi)
{
    int i = combi->r - 1, j;
    if (combi->nleft == combi->total)
        goto done;
    else if (combi->nleft <= 0)
        return ((void *)0);
    while (combi->a[i] == combi->n - combi->r + i)
        i--;
    combi->a[i] += 1;
    for (j = i+1; j < combi->r; j++)
        combi->a[j] = combi->a[i] + j - i;
    done:
    combi->nleft--;
    return combi;
}

canonical_original_code:
struct _combi_ctx *next_combi(struct _combi_ctx *combi)
{
    int i = combi->r - 1; int j;
    if (combi->nleft == combi->total)
        goto done;
    else if (combi->nleft <= 0)
        return ((void *)0);
    while (combi->a[i] == combi->n - combi->r + i)
        i--;
    combi->a[i] += 1;
    for (j = i+1; j < combi->r; j++)
        combi->a[j] = combi->a[i] + j - i;
    done:
    combi->nleft--;
    return combi;
}

variable_types:
combi
struct _combi_ctx *

variable_types: j int


decompiled_code:
__int64 __fastcall free_combi(__int64 a1)
{
sfree(*(_QWORD *)(a1 + 16));
return sfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
sfree(*(_QWORD *)(a1 + 16));
return sfree(a1);
}

original_code:
void free_combi(combi_ctx *combi)
{
    sfree(combi->a);
    sfree(combi);
}

canonical_original_code:
void free_combi(struct _combi_ctx *combi)
{
    sfree(combi->a);
    sfree(combi);
}


decompiled_code:
void __fastcall dsf_init(_DWORD *a1, int a2)
{
_DWORD *v2; // rax

if ( a2 > 0 )
{
v2 = a1;
do
*v2++ = 6;
while ( v2 != &a1[a2 - 1 + 1] );
}
}

canonical_decompiled_code:
void __fastcall func0(_DWORD *a1, int a2)
{
_DWORD *v2; // rax

if ( a2 > 0 )
{
v2 = a1;
do
*v2++ = 6;
while ( v2 != &a1[a2 - 1 + 1] );
}
}

original_code:
void dsf_init(int *dsf, int size)
{
    int i;
    for (i = 0; i < size; i++) dsf[i] = 6;
}

variable_types:
dsf
int *


decompiled_code:
__int64 __fastcall edsf_canonify(__int64 a1, int a2, int *a3)
{
__int64 result; // rax
int v6; // ecx
int v7; // edx
int v8; // edi
int *v9; // r8
int v10; // esi

if ( a2 < 0 )
_assert_fail("index >= 0", "dsf.c", 0x6Eu, "edsf_canonify");
result = (unsigned int)a2;
v6 = *(_DWORD *)(a1 + 4LL * a2);
v7 = v6 & 2;
if ( (v6 & 2) != 0 )
{
v8 = a2;
v7 = 0;
if ( !a3 )
return result;
goto LABEL_5;
}
do
{
v7 ^= v6 & 1;
v8 = v6 >> 2;
v6 = *(_DWORD *)(a1 + 4LL * (v6 >> 2));
}
while ( (v6 & 2) == 0 );
if ( a3 )
LABEL_5:
*a3 = v7;
if ( v8 != a2 )
{
do
{
v9 = (int *)(a1 + 4LL * (int)result);
result = (unsigned int)(*v9 >> 2);
v10 = v7;
v7 ^= *v9 & 1;
*v9 = (4 * v8) | v10;
}
while ( v8 != (_DWORD)result );
}
if ( v7 )
_assert_fail("inverse == 0", "dsf.c", 0x89u, "edsf_canonify");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int *a3)
{
__int64 result; // rax
int v6; // ecx
int v7; // edx
int v8; // edi
int *v9; // r8
int v10; // esi

if ( a2 < 0 )
_assert_fail("index >= 0", "dsf.c", 0x6Eu, "edsf_canonify");
result = (unsigned int)a2;
v6 = *(_DWORD *)(a1 + 4LL * a2);
v7 = v6 & 2;
if ( (v6 & 2) != 0 )
{
v8 = a2;
v7 = 0;
if ( !a3 )
return result;
goto LABEL_5;
}
do
{
v7 ^= v6 & 1;
v8 = v6 >> 2;
v6 = *(_DWORD *)(a1 + 4LL * (v6 >> 2));
}
while ( (v6 & 2) == 0 );
if ( a3 )
LABEL_5:
*a3 = v7;
if ( v8 != a2 )
{
do
{
v9 = (int *)(a1 + 4LL * (int)result);
result = (unsigned int)(*v9 >> 2);
v10 = v7;
v7 ^= *v9 & 1;
*v9 = (4 * v8) | v10;
}
while ( v8 != (_DWORD)result );
}
if ( v7 )
_assert_fail("inverse == 0", "dsf.c", 0x89u, "edsf_canonify");
return result;
}

original_code:
int edsf_canonify(int *dsf, int index, int *inverse_return)
{
    int start_index = index, canonical_index;
    int inverse = 0;
    ((index >= 0) ? (void) (0) : __assert_fail ("index >= 0", "dsf.c", 110, __extension__ __PRETTY_FUNCTION__));
    while ((dsf[index] & 2) == 0) {
        inverse ^= (dsf[index] & 1);
 index = dsf[index] >> 2;
    }
    canonical_index = index;
    if (inverse_return)
        *inverse_return = inverse;
    index = start_index;
    while (index != canonical_index) {
 int nextindex = dsf[index] >> 2;
        int nextinverse = inverse ^ (dsf[index] & 1);
 dsf[index] = (canonical_index << 2) | inverse;
        inverse = nextinverse;
 index = nextindex;
    }
    ((inverse == 0) ? (void) (0) : __assert_fail ("inverse == 0", "dsf.c", 137, __extension__ __PRETTY_FUNCTION__));
    return index;
}

canonical_original_code:
int edsf_canonify(int *dsf, int index, int *inverse_return)
{
    int start_index = index; int canonical_index;
    int inverse = 0;
    ((index >= 0) ? (void) (0) : __assert_fail ("index >= 0", "dsf.c", 110, __extension__ __PRETTY_FUNCTION__));
    while ((dsf[index] & 2) == 0) {
        inverse ^= (dsf[index] & 1);
 index = dsf[index] >> 2;
    }
    canonical_index = index;
    if (inverse_return)
        *inverse_return = inverse;
    index = start_index;
    while (index != canonical_index) {
 int nextindex = dsf[index] >> 2;
        int nextinverse = inverse ^ (dsf[index] & 1);
 dsf[index] = (canonical_index << 2) | inverse;
        inverse = nextinverse;
 index = nextindex;
    }
    ((inverse == 0) ? (void) (0) : __assert_fail ("inverse == 0", "dsf.c", 137, __extension__ __PRETTY_FUNCTION__));
    return index;
}

variable_types: index int

variable_types: inverse int

variable_types: nextindex int

variable_types: nextinverse int


decompiled_code:
__int64 __fastcall dsf_canonify(__int64 a1, int a2)
{
return edsf_canonify(a1, a2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
return func1(a1, a2, 0LL);
}

original_code:
int dsf_canonify(int *dsf, int index)
{
    return edsf_canonify(dsf, index, ((void *)0));
}


decompiled_code:
__int64 __fastcall dsf_size(__int64 a1, int a2)
{
return (unsigned int)(*(int *)(a1 + 4LL * (int)dsf_canonify(a1, a2)) >> 2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
return (unsigned int)(*(int *)(a1 + 4LL * (int)func2(a1, a2)) >> 2);
}

original_code:
int dsf_size(int *dsf, int index) {
    return dsf[dsf_canonify(dsf, index)] >> 2;
}


decompiled_code:
__int64 __fastcall edsf_merge(__int64 a1, int a2, int a3, int a4)
{
int v7; // ebp
int v8; // er12
int v9; // esi
int v10; // edx
unsigned int v11; // er13
int v12; // eax
int *v13; // rdi
__int64 result; // rax
int v15; // [rsp+8h] [rbp-30h] BYREF
int v16[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v7 = edsf_canonify(a1, a2, v16);
if ( (*(_BYTE *)(a1 + 4LL * v7) & 2) == 0 )
_assert_fail("dsf[v1] & 2", "dsf.c", 0x98u, "edsf_merge");
v8 = v16[0] ^ a4;
v9 = edsf_canonify(a1, a3, &v15);
if ( (*(_BYTE *)(a1 + 4LL * v9) & 2) == 0 )
_assert_fail("dsf[v2] & 2", "dsf.c", 0x9Bu, "edsf_merge");
v10 = v15;
v11 = v8 ^ v15;
if ( v7 == v9 )
{
if ( v15 != v8 )
_assert_fail("!inverse", "dsf.c", 0xA1u, "edsf_merge");
}
else
{
if ( v11 > 1 )
_assert_fail("inverse == 0 || inverse == 1", "dsf.c", 0xA3u, "edsf_merge");
if ( v7 > v9 )
{
v12 = v7;
v7 = v9;
v9 = v12;
}
v13 = (int *)(a1 + 4LL * v9);
*(_DWORD *)(a1 + 4LL * v7) += *v13 & 0xFFFFFFFC;
*v13 = (v10 != v8) | (4 * v7);
}
result = edsf_canonify(a1, v9, &v15);
if ( v7 != (_DWORD)result )
_assert_fail("v2 == v1", "dsf.c", 0xBCu, "edsf_merge");
if ( v15 != v11 )
_assert_fail("i2 == inverse", "dsf.c", 0xBDu, "edsf_merge");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, int a3, int a4)
{
int v7; // ebp
int v8; // er12
int v9; // esi
int v10; // edx
unsigned int v11; // er13
int v12; // eax
int *v13; // rdi
__int64 result; // rax
int v15; // [rsp+8h] [rbp-30h] BYREF
int v16[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v7 = func1(a1, a2, v16);
if ( (*(_BYTE *)(a1 + 4LL * v7) & 2) == 0 )
_assert_fail("dsf[v1] & 2", "dsf.c", 0x98u, "edsf_merge");
v8 = v16[0] ^ a4;
v9 = func1(a1, a3, &v15);
if ( (*(_BYTE *)(a1 + 4LL * v9) & 2) == 0 )
_assert_fail("dsf[v2] & 2", "dsf.c", 0x9Bu, "edsf_merge");
v10 = v15;
v11 = v8 ^ v15;
if ( v7 == v9 )
{
if ( v15 != v8 )
_assert_fail("!inverse", "dsf.c", 0xA1u, "edsf_merge");
}
else
{
if ( v11 > 1 )
_assert_fail("inverse == 0 || inverse == 1", "dsf.c", 0xA3u, "edsf_merge");
if ( v7 > v9 )
{
v12 = v7;
v7 = v9;
v9 = v12;
}
v13 = (int *)(a1 + 4LL * v9);
*(_DWORD *)(a1 + 4LL * v7) += *v13 & 0xFFFFFFFC;
*v13 = (v10 != v8) | (4 * v7);
}
result = func1(a1, v9, &v15);
if ( v7 != (_DWORD)result )
_assert_fail("v2 == v1", "dsf.c", 0xBCu, "edsf_merge");
if ( v15 != v11 )
_assert_fail("i2 == inverse", "dsf.c", 0xBDu, "edsf_merge");
return result;
}

original_code:
void edsf_merge(int *dsf, int v1, int v2, int inverse)
{
    int i1, i2;
    v1 = edsf_canonify(dsf, v1, &i1);
    ((dsf[v1] & 2) ? (void) (0) : __assert_fail ("dsf[v1] & 2", "dsf.c", 152, __extension__ __PRETTY_FUNCTION__));
    inverse ^= i1;
    v2 = edsf_canonify(dsf, v2, &i2);
    ((dsf[v2] & 2) ? (void) (0) : __assert_fail ("dsf[v2] & 2", "dsf.c", 155, __extension__ __PRETTY_FUNCTION__));
    inverse ^= i2;
    if (v1 == v2)
        ((!inverse) ? (void) (0) : __assert_fail ("!inverse", "dsf.c", 161, __extension__ __PRETTY_FUNCTION__));
    else {
 ((inverse == 0 || inverse == 1) ? (void) (0) : __assert_fail ("inverse == 0 || inverse == 1", "dsf.c", 163, __extension__ __PRETTY_FUNCTION__));
 if (v1 > v2) {
     int v3 = v1;
     v1 = v2;
     v2 = v3;
 }
 dsf[v1] += (dsf[v2] >> 2) << 2;
 dsf[v2] = (v1 << 2) | !!inverse;
    }
    v2 = edsf_canonify(dsf, v2, &i2);
    ((v2 == v1) ? (void) (0) : __assert_fail ("v2 == v1", "dsf.c", 188, __extension__ __PRETTY_FUNCTION__));
    ((i2 == inverse) ? (void) (0) : __assert_fail ("i2 == inverse", "dsf.c", 189, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void edsf_merge(int *dsf, int v1, int v2, int inverse)
{
    int i1; int i2;
    v1 = edsf_canonify(dsf, v1, &i1);
    ((dsf[v1] & 2) ? (void) (0) : __assert_fail ("dsf[v1] & 2", "dsf.c", 152, __extension__ __PRETTY_FUNCTION__));
    inverse ^= i1;
    v2 = edsf_canonify(dsf, v2, &i2);
    ((dsf[v2] & 2) ? (void) (0) : __assert_fail ("dsf[v2] & 2", "dsf.c", 155, __extension__ __PRETTY_FUNCTION__));
    inverse ^= i2;
    if (v1 == v2)
        ((!inverse) ? (void) (0) : __assert_fail ("!inverse", "dsf.c", 161, __extension__ __PRETTY_FUNCTION__));
    else {
 ((inverse == 0 || inverse == 1) ? (void) (0) : __assert_fail ("inverse == 0 || inverse == 1", "dsf.c", 163, __extension__ __PRETTY_FUNCTION__));
 if (v1 > v2) {
     int v3 = v1;
     v1 = v2;
     v2 = v3;
 }
 dsf[v1] += (dsf[v2] >> 2) << 2;
 dsf[v2] = (v1 << 2) | !!inverse;
    }
    v2 = edsf_canonify(dsf, v2, &i2);
    ((v2 == v1) ? (void) (0) : __assert_fail ("v2 == v1", "dsf.c", 188, __extension__ __PRETTY_FUNCTION__));
    ((i2 == inverse) ? (void) (0) : __assert_fail ("i2 == inverse", "dsf.c", 189, __extension__ __PRETTY_FUNCTION__));
}


decompiled_code:
__int64 __fastcall dsf_merge(__int64 a1, int a2, int a3)
{
return edsf_merge(a1, a2, a3, 0);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, int a3)
{
return func4(a1, a2, a3, 0);
}

original_code:
void dsf_merge(int *dsf, int v1, int v2)
{
    edsf_merge(dsf, v1, v2, 0);
}


smalloc

decompiled_code:
void *__fastcall smalloc(size_t a1)
{
void *v1; // rbx

v1 = malloc(a1);
if ( !v1 )
fatal("out of memory");
return v1;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *v1; // rbx

v1 = malloc(a1);
if ( !v1 )
fatal("out of memory");
return v1;
}

original_code:
void *smalloc(size_t size) {
    void *p;
    p = malloc(size);
    if (!p)
 fatal("out of memory");
    return p;
}

canonical_original_code:
void *smalloc(unsigned long size) {
    void *p;
    p = malloc(size);
    if (!p)
 fatal("out of memory");
    return p;
}

variable_types:
size
unsigned long

variable_types:
p
void *

return_type: void *


sfree

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

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

original_code:
void sfree(void *p) {
    if (p) {
 free(p);
    }
}


srealloc

decompiled_code:
void *__fastcall srealloc(void *a1, size_t a2)
{
void *v2; // rbx

if ( a1 )
v2 = realloc(a1, a2);
else
v2 = malloc(a2);
if ( !v2 )
fatal("out of memory");
return v2;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
void *v2; // rbx

if ( a1 )
v2 = realloc(a1, a2);
else
v2 = malloc(a2);
if ( !v2 )
fatal("out of memory");
return v2;
}

original_code:
void *srealloc(void *p, size_t size) {
    void *q;
    if (p) {
 q = realloc(p, size);
    } else {
 q = malloc(size);
    }
    if (!q)
 fatal("out of memory");
    return q;
}

canonical_original_code:
void *srealloc(void *p, unsigned long size) {
    void *q;
    if (p) {
 q = realloc(p, size);
    } else {
 q = malloc(size);
    }
    if (!q)
 fatal("out of memory");
    return q;
}

variable_types:
q
void *


dupstr

decompiled_code:
char *__fastcall dupstr(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)smalloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func3(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)func0(v1 + 1);
return strcpy(v2, src);
}

original_code:
char *dupstr(const char *s) {
    char *r = smalloc(1+strlen(s));
    strcpy(r,s);
    return r;
}

canonical_original_code:
char *dupstr(char *s) {
    char *r = smalloc(1+strlen(s));
    strcpy(r,s);
    return r;
}

variable_types:
s
char *

variable_types:
r
char *

return_type: char *


loop

repo: medrimonia/projetSysteme

decompiled_code:
void *__fastcall loop(void *a1)
{
int v1; // eax

v1 = 200000000;
do
--v1;
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // eax

v1 = 200000000;
do
--v1;
while ( v1 );
return 0LL;
}

original_code:
static void * loop(void * thread_no)
{
    int k;
    int i=0;
    for (k = 0; k < 1000 * 1000 * 200 / 1; k++){
        i++;
    }
    return ((void *)0);
}

canonical_original_code:
static void *loop(void *thread_no)
{
    int k;
    int i = 0;
    for (k = 0; k < 1000 * 1000 * 200 / 1; k++){
        i++;
    }
    return ((void *)0);
}

variable_types: k int

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char arg[4]; // [rsp+4h] [rbp-14h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( pthread_create(newthread, 0LL, loop, arg) )
__assert_fail("!err", "parallel-speed-compare.c", 0x22u, "main");
if ( pthread_join(newthread[0], 0LL) )
__assert_fail("!err", "parallel-speed-compare.c", 0x27u, "main");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    pthread_t th[1];
    int id[1];
    int err;
    int i;
    for (i = 0; i < 1; i++){
        err = pthread_create(&th[i], ((void *)0), loop, &id[i]);
        ((void) sizeof ((!err) ? 1 : 0), __extension__ ({ if (!err) ; else __assert_fail ("!err", "parallel-speed-compare.c", 34, __extension__ __PRETTY_FUNCTION__); }));
    }
    for (i = 0; i < 1; i++){
        err = pthread_join(th[i], ((void *)0));
        ((void) sizeof ((!err) ? 1 : 0), __extension__ ({ if (!err) ; else __assert_fail ("!err", "parallel-speed-compare.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned long th[1];
    int id[1];
    int err;
    int i;
    for (i = 0; i < 1; i++){
        err = pthread_create(&th[i], ((void *)0), loop, &id[i]);
        ((void) sizeof ((!err) ? 1 : 0), __extension__ ({ if (!err) ; else __assert_fail ("!err", "parallel-speed-compare.c", 34, __extension__ __PRETTY_FUNCTION__); }));
    }
    for (i = 0; i < 1; i++){
        err = pthread_join(th[i], ((void *)0));
        ((void) sizeof ((!err) ? 1 : 0), __extension__ ({ if (!err) ; else __assert_fail ("!err", "parallel-speed-compare.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
th
unsigned long [1]

variable_types:
id
int [1]

variable_types: err int


repo: meetrp/device-one

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int *v5; // rbp
char *v6; // rax
int *v8; // rbx
char *v9; // rax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v3 = open("/dev/ones", 0, envp);
if ( v3 == -1 )
{
v8 = __errno_location();
printf("error %d\n", (unsigned int)*v8);
v9 = strerror(*v8);
printf("error %s\n", v9);
exit(2);
}
v4 = v3;
buf[0] = 0;
if ( (unsigned int)read(v3, buf, 1uLL) )
{
printf("0x%x\n", (unsigned __int8)buf[0]);
}
else
{
v5 = __errno_location();
printf("error %d\n", (unsigned int)*v5);
v6 = strerror(*v5);
printf("error %s\n", v6);
}
close(v4);
return 0;
}

original_code:
int
main()
{
    int res = 0;
    char buf[1];
    int fp = open("/dev/ones", 00);
    if (fp == -1) {
        printf("error %d\n", (*__errno_location ()));
        printf("error %s\n", strerror((*__errno_location ())));
        exit(2);
    }
    memset(&buf, 0, (size_t)1);
    res = read(fp, &buf, 1);
    if (! res) {
        printf("error %d\n", (*__errno_location ()));
        printf("error %s\n", strerror((*__errno_location ())));
    } else
        printf("0x%x\n", (unsigned char)(buf[0]));
    close(fp);
}

canonical_original_code:
int main()
{
    int res = 0;
    char buf[1];
    int fp = open("/dev/ones", 00);
    if (fp == -1) {
        printf("error %d\n", (*__errno_location ()));
        printf("error %s\n", strerror((*__errno_location ())));
        exit(2);
    }
    memset(&buf, 0, (unsigned long)1);
    res = read(fp, &buf, 1);
    if (! res) {
        printf("error %d\n", (*__errno_location ()));
        printf("error %s\n", strerror((*__errno_location ())));
    } else
        printf("0x%x\n", (unsigned char)(buf[0]));
    close(fp);
}

variable_types: res int

variable_types:
buf
char [1]

variable_types: fp int


repo: meetrp/memory-wrapper

decompiled_code:
void __fastcall fmc_back_trace(const char *a1, const char *a2, unsigned int a3)
{
int v4; // eax
__int64 v5; // r15
char **v6; // rbp
__int64 v7; // r9
__int64 i; // rbx
void *v9[263]; // [rsp+0h] [rbp-838h] BYREF

v4 = backtrace(v9, 255);
v5 = v4;
v6 = backtrace_symbols(v9, v4);
if ( v5 )
{
for ( i = 0LL; i != v5; ++i )
fmc_log("FTL", a1, a2, a3, "%s", (__int64)v6[i]);
}
fmc_log("FTL", a1, a2, a3, "", v7);
free(v6);
}

canonical_decompiled_code:
void __fastcall func8(const char *a1, const char *a2, unsigned int a3)
{
int v4; // eax
__int64 v5; // r15
char **v6; // rbp
__int64 v7; // r9
__int64 i; // rbx
void *v9[263]; // [rsp+0h] [rbp-838h] BYREF

v4 = backtrace(v9, 255);
v5 = v4;
v6 = backtrace_symbols(v9, v4);
if ( v5 )
{
for ( i = 0LL; i != v5; ++i )
func7("FTL", a1, a2, a3, "%s", (__int64)v6[i]);
}
func7("FTL", a1, a2, a3, "", v7);
free(v6);
}

original_code:
void
fmc_back_trace(const char *fname, const char *func, int32_t line_no)
{
 void *buf[255];
 size_t size;
 char **strings;
 size_t i;
 size = backtrace(buf, sizeof(buf)/sizeof(void*));
 strings = backtrace_symbols(buf, size);
 for (i = 0; i < size; i++)
  fmc_log("FTL", fname, func, line_no, "%s", strings[i]);
 fmc_log("FTL", fname, func, line_no, "");
 free(strings);
}

canonical_original_code:
void fmc_back_trace(char *fname, char *func, int line_no)
{
 void *buf[255];
 unsigned long size;
 char **strings;
 unsigned long i;
 size = backtrace(buf, sizeof(buf)/sizeof(void *));
 strings = backtrace_symbols(buf, size);
 for (i = 0; i < size; i++)
  fmc_log("FTL", fname, func, line_no, "%s", strings[i]);
 fmc_log("FTL", fname, func, line_no, "");
 free(strings);
}

variable_types:
fname
char *

variable_types:
func
char *

variable_types:
buf
void *[255]

variable_types:
strings
char **

variable_types:
i
unsigned long


decompiled_code:
void __fastcall fmc_del_elem(__int64 a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rdi
__int64 v3; // rax
__int64 v4; // rax

v1 = fmc_find_elem(a1);
v2 = v1;
if ( (_QWORD *)fmc_allocation_table_head == v1 )
fmc_allocation_table_head = 0LL;
v3 = v1[1];
if ( v3 )
*(_QWORD *)(v3 + 16) = v2[2];
v4 = v2[2];
if ( v4 )
*(_QWORD *)(v4 + 8) = v2[1];
free(v2);
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rdi
__int64 v3; // rax
__int64 v4; // rax

v1 = fmc_find_elem(a1);
v2 = v1;
if ( (_QWORD *)fmc_allocation_table_head == v1 )
fmc_allocation_table_head = 0LL;
v3 = v1[1];
if ( v3 )
*(_QWORD *)(v3 + 16) = v2[2];
v4 = v2[2];
if ( v4 )
*(_QWORD *)(v4 + 8) = v2[1];
free(v2);
}

original_code:
static void
fmc_del_elem(void *ptr)
{
 fmc_mem_table_t *elem = fmc_find_elem(ptr);
 if (elem == fmc_allocation_table_head) fmc_allocation_table_head = ((void *)0);
 if (((void *)0) != elem->prev) elem->prev->next = elem->next;
 if (((void *)0) != elem->next) elem->next->prev = elem->prev;
 free(elem);
}

canonical_original_code:
static void fmc_del_elem(void *ptr)
{
 struct __fmc_mem_table *elem = fmc_find_elem(ptr);
 if (elem == fmc_allocation_table_head) fmc_allocation_table_head = ((void *)0);
 if (((void *)0) != elem->prev) elem->prev->next = elem->next;
 if (((void *)0) != elem->next) elem->next->prev = elem->prev;
 free(elem);
}

variable_types:
ptr
void *

variable_types: struct __fmc_mem_table { long allocated_addr; struct __fmc_mem_table *prev; struct __fmc_mem_table *next; } *


decompiled_code:
int __fastcall fmc_init(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
fmc_allocation_table_head = 0LL;
return fmc_log("DBG", "fmc.c", "fmc_init", 0x1Fu, "allocation table has been initialized", a6);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
fmc_allocation_table_head = 0LL;
return func7("DBG", "fmc.c", "fmc_init", 0x1Fu, "allocation table has been initialized", a6);
}

original_code:
void
fmc_init()
{
 fmc_allocation_table_head = ((void *)0);
 fmc_log("DBG", "fmc.c", __FUNCTION__, 31, "allocation table has been initialized");
}


decompiled_code:
int __fastcall fmc_deinit(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // r9
__int64 v7; // r9
__int64 v8; // r9
__int64 *v9; // rbx
int result; // eax

if ( fmc_allocation_table_head )
{
fmc_log("ERR", "fmc.c", "fmc_deinit", 0x36u, "===================== ERROR =====================", a6);
fmc_log("ERR", "fmc.c", "fmc_deinit", 0x37u, "allocation table is not empty!!", v6);
fmc_log("ERR", "fmc.c", "fmc_deinit", 0x38u, "Leaked memory addresses are:", v7);
v9 = (__int64 *)fmc_allocation_table_head;
if ( fmc_allocation_table_head )
{
do
{
fmc_log(
"ERR",
"fmc.c",
"fmc_deinit",
0x4Bu,
"%p --> HDR[%s:%ld] - FTR[%s:%d]",
*v9,
*v9 + 12,
*(unsigned int *)(*v9 + 8),
*v9 + (int)(*(_QWORD *)*v9 + 50),
*(unsigned int *)(*v9 + (int)(*(_QWORD *)*v9 + 66)));
v9 = (__int64 *)v9[2];
}
while ( v9 );
}
result = fmc_log("ERR", "fmc.c", "fmc_deinit", 0x4Fu, "", v8);
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // r9
__int64 v7; // r9
__int64 v8; // r9
__int64 *v9; // rbx
int result; // eax

if ( fmc_allocation_table_head )
{
func7("ERR", "fmc.c", "fmc_deinit", 0x36u, "===================== ERROR =====================", a6);
func7("ERR", "fmc.c", "fmc_deinit", 0x37u, "allocation table is not empty!!", v6);
func7("ERR", "fmc.c", "fmc_deinit", 0x38u, "Leaked memory addresses are:", v7);
v9 = (__int64 *)fmc_allocation_table_head;
if ( fmc_allocation_table_head )
{
do
{
func7(
"ERR",
"fmc.c",
"fmc_deinit",
0x4Bu,
"%p --> HDR[%s:%ld] - FTR[%s:%d]",
*v9,
*v9 + 12,
*(unsigned int *)(*v9 + 8),
*v9 + (int)(*(_QWORD *)*v9 + 50),
*(unsigned int *)(*v9 + (int)(*(_QWORD *)*v9 + 66)));
v9 = (__int64 *)v9[2];
}
while ( v9 );
}
result = func7("ERR", "fmc.c", "fmc_deinit", 0x4Fu, "", v8);
}
return result;
}

original_code:
void
fmc_deinit()
{
 fmc_mem_table_t *iterator = ((void *)0);
 char *hdr_func, *ftr_func;
 int32_t hdr_lineno, ftr_lineno;
 int32_t posn = 0;
 size_t orig_size;
 void *ptr;
 if (((void *)0) == fmc_allocation_table_head)
  return;
 fmc_log("ERR", "fmc.c", __FUNCTION__, 54, "===================== ERROR =====================");
 fmc_log("ERR", "fmc.c", __FUNCTION__, 55, "allocation table is not empty!!");
 fmc_log("ERR", "fmc.c", __FUNCTION__, 56, "Leaked memory addresses are:");
 iterator = fmc_allocation_table_head;
 while (iterator) {
  ptr = (void *)iterator->allocated_addr;
  posn = 0;
  orig_size = *(size_t *)(ptr + posn); posn += sizeof(size_t);
  hdr_lineno = *(int32_t *)(ptr + posn); posn += sizeof(int32_t);
  hdr_func = (char *)(ptr + posn); posn += 16;
  posn += sizeof("0xC00BFACE");
  posn += orig_size;
  posn += sizeof("0xC00BFACE");
  ftr_func = (char *)(ptr + posn); posn += 16;
  ftr_lineno = *(int32_t *)(ptr + posn); posn += sizeof(int32_t);
  fmc_log("ERR", "fmc.c", __FUNCTION__, 75, "%p --> HDR[%s:%ld] - FTR[%s:%d]", ptr, hdr_func, hdr_lineno, ftr_func, ftr_lineno);
  iterator = iterator->next;
 }
 fmc_log("ERR", "fmc.c", __FUNCTION__, 79, "");
}

canonical_original_code:
void fmc_deinit()
{
 struct __fmc_mem_table *iterator = ((void *)0);
 char *hdr_func; char *ftr_func;
 int hdr_lineno; int ftr_lineno;
 int posn = 0;
 unsigned long orig_size;
 void *ptr;
 if (((void *)0) == fmc_allocation_table_head)
  return;
 fmc_log("ERR", "fmc.c", __FUNCTION__, 54, "===================== ERROR =====================");
 fmc_log("ERR", "fmc.c", __FUNCTION__, 55, "allocation table is not empty!!");
 fmc_log("ERR", "fmc.c", __FUNCTION__, 56, "Leaked memory addresses are:");
 iterator = fmc_allocation_table_head;
 while (iterator) {
  ptr = (void *)iterator->allocated_addr;
  posn = 0;
  orig_size = *(unsigned long *)(ptr + posn); posn += sizeof(unsigned long);
  hdr_lineno = *(int *)(ptr + posn); posn += sizeof(int);
  hdr_func = (char *)(ptr + posn); posn += 16;
  posn += sizeof("0xC00BFACE");
  posn += orig_size;
  posn += sizeof("0xC00BFACE");
  ftr_func = (char *)(ptr + posn); posn += 16;
  ftr_lineno = *(int *)(ptr + posn); posn += sizeof(int);
  fmc_log("ERR", "fmc.c", __FUNCTION__, 75, "%p --> HDR[%s:%ld] - FTR[%s:%d]", ptr, hdr_func, hdr_lineno, ftr_func, ftr_lineno);
  iterator = iterator->next;
 }
 fmc_log("ERR", "fmc.c", __FUNCTION__, 79, "");
}

variable_types: posn int

user_defined_types: struct __fmc_mem_table { long allocated_addr; struct __fmc_mem_table *prev; struct __fmc_mem_table *next; }


decompiled_code:
char *__fastcall fmc_alloc(__int64 a1, const char *a2, unsigned int a3, __int64 a4)
{
__int64 v4; // r13
char *v6; // rbx

v4 = a3;
v6 = (char *)calloc(a4 + 70, 1uLL);
*(_QWORD *)v6 = a4;
*((_DWORD *)v6 + 2) = v4;
snprintf(v6 + 12, 0x10uLL, "%s", a2);
strcpy(v6 + 28, "0xC00BFACE");
strcpy(&v6[(int)a4 + 39], "0xC00BFACE");
snprintf(&v6[(int)a4 + 50], 0x10uLL, "%s", a2);
*(_DWORD *)&v6[(int)a4 + 66] = v4;
fmc_add_new_elem((__int64)v6);
fmc_log("DBG", "fmc.c", "fmc_alloc", 0xBCu, "allocated memory[%p] for a call from [%s:%d]", (__int64)v6, a2, v4);
return v6 + 39;
}

canonical_decompiled_code:
char *__fastcall func13(__int64 a1, const char *a2, unsigned int a3, __int64 a4)
{
__int64 v4; // r13
char *v6; // rbx

v4 = a3;
v6 = (char *)calloc(a4 + 70, 1uLL);
*(_QWORD *)v6 = a4;
*((_DWORD *)v6 + 2) = v4;
snprintf(v6 + 12, 0x10uLL, "%s", a2);
strcpy(v6 + 28, "0xC00BFACE");
strcpy(&v6[(int)a4 + 39], "0xC00BFACE");
snprintf(&v6[(int)a4 + 50], 0x10uLL, "%s", a2);
*(_DWORD *)&v6[(int)a4 + 66] = v4;
fmc_add_new_elem((__int64)v6);
func7("DBG", "fmc.c", "fmc_alloc", 0xBCu, "allocated memory[%p] for a call from [%s:%d]", (__int64)v6, a2, v4);
return v6 + 39;
}

original_code:
void*
fmc_alloc(const char *fname, const char *func, int32_t line_no, size_t original_size)
{
 size_t new_size = sizeof(size_t) + (sizeof("0xC00BFACE") + 16 + sizeof(int32_t)) + original_size + (sizeof("0xC00BFACE") + 16 + sizeof(int32_t));
 char *buf = calloc(new_size, sizeof(char));
 int32_t posn = 0;
 *((size_t *)(buf + posn)) = original_size; posn += sizeof(size_t);
 *((int32_t *)(buf + posn)) = line_no; posn += sizeof(int32_t);
 snprintf((char*)buf + posn, (size_t)16, "%s", func); posn += 16;
 snprintf((char*)buf + posn, (size_t)sizeof("0xC00BFACE"), "%s", "0xC00BFACE"); posn += sizeof("0xC00BFACE");
 posn += original_size;
 snprintf((char*)buf + posn, (size_t)sizeof("0xC00BFACE"), "%s", "0xC00BFACE"); posn += sizeof("0xC00BFACE");
 snprintf((char*)buf + posn, (size_t)16, "%s", func); posn += 16;
 *((int32_t *)(buf + posn)) = line_no;
 fmc_add_new_elem(buf);
 fmc_log("DBG", "fmc.c", __FUNCTION__, 188, "allocated memory[%p] for a call from [%s:%d]", buf, func, line_no);
 return (buf + sizeof(size_t) + (sizeof("0xC00BFACE") + 16 + sizeof(int32_t)));
}

canonical_original_code:
void *fmc_alloc(char *fname, char *func, int line_no, unsigned long original_size)
{
 unsigned long new_size = sizeof(size_t) + (sizeof("0xC00BFACE") + 16 + sizeof(int32_t)) + original_size + (sizeof("0xC00BFACE") + 16 + sizeof(int32_t));
 char *buf = calloc(new_size, sizeof(char));
 int posn = 0;
 *((unsigned long *)(buf + posn)) = original_size; posn += sizeof(unsigned long);
 *((int *)(buf + posn)) = line_no; posn += sizeof(int);
 snprintf((char *)buf + posn, (unsigned long)16, "%s", func); posn += 16;
 snprintf((char *)buf + posn, (unsigned long)sizeof("0xC00BFACE"), "%s", "0xC00BFACE"); posn += sizeof("0xC00BFACE");
 posn += original_size;
 snprintf((char *)buf + posn, (unsigned long)sizeof("0xC00BFACE"), "%s", "0xC00BFACE"); posn += sizeof("0xC00BFACE");
 snprintf((char *)buf + posn, (unsigned long)16, "%s", func); posn += 16;
 *((int *)(buf + posn)) = line_no;
 fmc_add_new_elem(buf);
 fmc_log("DBG", "fmc.c", __FUNCTION__, 188, "allocated memory[%p] for a call from [%s:%d]", buf, func, line_no);
 return (buf + sizeof(unsigned long) + (sizeof("0xC00BFACE") + 16 + sizeof(int)));
}

variable_types:
buf
char *


decompiled_code:
int __fastcall fmc_free(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // r12
__int64 v7; // rbx

v6 = a3;
v7 = a4 - 39;
fmc_check_memory(a4 - 39, a1, a2, a3, a5, a6);
fmc_del_elem(v7);
return fmc_log("DBG", "fmc.c", "fmc_free", 0x116u, "freeing up memory[%p] for a call from [%s:%d]", v7, a2, v6);
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // r12
__int64 v7; // rbx

v6 = a3;
v7 = a4 - 39;
func9(a4 - 39, a1, a2, a3, a5, a6);
func10(v7);
return func7("DBG", "fmc.c", "fmc_free", 0x116u, "freeing up memory[%p] for a call from [%s:%d]", v7, a2, v6);
}

original_code:
void
fmc_free(const char *fname, const char *func, int32_t line_no, void *ptr)
{
 char *our_ptr = (char *)ptr - ((sizeof("0xC00BFACE") + 16 + sizeof(int32_t)) + sizeof(size_t));
 fmc_check_memory(our_ptr, fname, func, line_no);
 fmc_del_elem(our_ptr);
 fmc_log("DBG", "fmc.c", __FUNCTION__, 278, "freeing up memory[%p] for a call from [%s:%d]", our_ptr, func, line_no);
}

canonical_original_code:
void fmc_free(char *fname, char *func, int line_no, void *ptr)
{
 char *our_ptr = (char *)ptr - ((sizeof("0xC00BFACE") + 16 + sizeof(int32_t)) + sizeof(size_t));
 fmc_check_memory(our_ptr, fname, func, line_no);
 fmc_del_elem(our_ptr);
 fmc_log("DBG", "fmc.c", __FUNCTION__, 278, "freeing up memory[%p] for a call from [%s:%d]", our_ptr, func, line_no);
}


decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
char *v6; // rax
__int64 v7; // r8
__int64 v8; // r9
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9

fmc_init(*(__int64 *)&argc, (__int64)argv, (__int64)envp, v3, v4, v5);
v6 = fmc_alloc((__int64)"test.c", "main", 0x13u, 10LL);
*(v6 - 31) = 97;
fmc_free((__int64)"test.c", (__int64)"main", 0x1Eu, (__int64)v6, v7, v8);
fmc_deinit((__int64)"test.c", (__int64)"main", v9, v10, v11, v12);
return 0;
}

original_code:
int
main(void)
{
 char *a = ((void *)0);
 fmc_init();
 a = (char *)fmc_alloc("test.c", __FUNCTION__, 19, 10 * sizeof(char));
 *(a-31) = 'a';
 fmc_free("test.c", __FUNCTION__, 30, a);
 fmc_deinit();
 return 0;
}

canonical_original_code:
int main()
{
 char *a = ((void *)0);
 fmc_init();
 a = (char *)fmc_alloc("test.c", __FUNCTION__, 19, 10 * sizeof(char));
 *(a-31) = 'a';
 fmc_free("test.c", __FUNCTION__, 30, a);
 fmc_deinit();
 return 0;
}

variable_types:
a
char *


repo: meiao/cte

decompiled_code:
void __fastcall free_node(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)(a1 + 8);
if ( v2 )
free(v2);
if ( *(_QWORD *)a1 )
free(*(void **)a1);
if ( *(_QWORD *)(a1 + 24) )
free_node();
if ( *(_QWORD *)(a1 + 32) )
free_node();
free((void *)a1);
}

original_code:
void free_node(Tree_node* node) {
  if (node->bic_data != ((void *)0)) {
    free(node->bic_data);
  }
  if (node->prob_data != ((void *)0)) {
    free(node->prob_data);
  }
  if (node->child != ((void *)0)) {
    free_node(node->child);
  }
  if (node->sibling != ((void *)0)) {
    free_node(node->sibling);
  }
  free(node);
}

canonical_original_code:
void free_node(struct tree_node *node) {
  if (node->bic_data != ((void *)0)) {
    free(node->bic_data);
  }
  if (node->prob_data != ((void *)0)) {
    free(node->prob_data);
  }
  if (node->child != ((void *)0)) {
    free_node(node->child);
  }
  if (node->sibling != ((void *)0)) {
    free_node(node->sibling);
  }
  free(node);
}

variable_types: struct tree_node { struct prob_data { int occurrences; double probability; int degrees_freedom; double Lw; } *prob_data; struct bic_data { double Vw; int Sw; } *bic_data; char symbol; struct tree_node *child; struct tree_node *sibling; struct tree_node *parent; } *

user_defined_types: struct tree_node { struct prob_data *prob_data; struct bic_data *bic_data; char symbol; struct tree_node *child; struct tree_node *sibling; struct tree_node *parent; }


decompiled_code:
__int64 __fastcall get_child_node(__int64 a1, char a2)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
for ( result = *(_QWORD *)(a1 + 24); result; result = *(_QWORD *)(result + 32) )
{
if ( *(_BYTE *)(result + 16) == a2 )
break;
}
return result;
}

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

if ( !a1 )
return 0LL;
for ( result = *(_QWORD *)(a1 + 24); result; result = *(_QWORD *)(result + 32) )
{
if ( *(_BYTE *)(result + 16) == a2 )
break;
}
return result;
}

original_code:
Tree_node* get_child_node(Tree_node* parent, char symbol) {
  if (parent == ((void *)0)) {
    return ((void *)0);
  }
  Tree_node* current_node = parent->child;
  while(current_node != ((void *)0) && current_node->symbol != symbol) {
    current_node = current_node->sibling;
  }
  return current_node;
}

canonical_original_code:
struct tree_node *get_child_node(struct tree_node *parent, char symbol) {
  if (parent == ((void *)0)) {
    return ((void *)0);
  }
  struct tree_node *current_node = parent->child;
  while(current_node != ((void *)0) && current_node->symbol != symbol) {
    current_node = current_node->sibling;
  }
  return current_node;
}

variable_types:
parent
struct tree_node *

variable_types: symbol char

return_type: struct tree_node { struct prob_data { int occurrences; double probability; int degrees_freedom; double Lw; } *prob_data; struct bic_data { double Vw; int Sw; } *bic_data; char symbol; struct tree_node *child; struct tree_node *sibling; struct tree_node *parent; } *


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

result = malloc(0x30uLL);
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x30uLL);
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
Tree_node* new_Tree_node() {
  Tree_node* node = (Tree_node*) malloc(sizeof(Tree_node));
  node->child = ((void *)0);
  node->sibling = ((void *)0);
  node->parent = ((void *)0);
  node->prob_data = ((void *)0);
  node->bic_data = ((void *)0);
  return node;
}

canonical_original_code:
struct tree_node *new_Tree_node() {
  struct tree_node *node = (Tree_node*) malloc(sizeof(Tree_node));
  node->child = ((void *)0);
  node->sibling = ((void *)0);
  node->parent = ((void *)0);
  node->prob_data = ((void *)0);
  node->bic_data = ((void *)0);
  return node;
}

user_defined_types: struct prob_data { int occurrences; double probability; int degrees_freedom; double Lw; }


decompiled_code:
double __fastcall Vw2(__int64 a1)
{
__int64 v1; // rax
double result; // xmm0_8

v1 = *(_QWORD *)(a1 + 24);
if ( !v1 )
return *(double *)&LC1;
result = *(double *)&LC1;
do
{
result = result * **(double **)(v1 + 8);
v1 = *(_QWORD *)(v1 + 32);
}
while ( v1 );
return result;
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1)
{
__int64 v1; // rax
double result; // xmm0_8

v1 = *(_QWORD *)(a1 + 24);
if ( !v1 )
return *(double *)&LC1;
result = *(double *)&LC1;
do
{
result = result * **(double **)(v1 + 8);
v1 = *(_QWORD *)(v1 + 32);
}
while ( v1 );
return result;
}

original_code:
double Vw2(Tree_node* node, double c) {
  double vw2 = 1.0;
  Tree_node* current_child = node->child;
  while (current_child != ((void *)0)) {
    vw2 *= current_child->bic_data->Vw;
    current_child = current_child->sibling;
  }
  return vw2;
}

canonical_original_code:
double Vw2(struct tree_node *node, double c) {
  double vw2 = 1.0;
  struct tree_node *current_child = node->child;
  while (current_child != ((void *)0)) {
    vw2 *= current_child->bic_data->Vw;
    current_child = current_child->sibling;
  }
  return vw2;
}

variable_types: c double

return_type: double


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

if ( !a1 )
return 0xFFFFFFFFLL;
LODWORD(result) = -1;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 40);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
LODWORD(result) = -1;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 40);
}
while ( a1 );
return result;
}

original_code:
int node_depth(Tree_node* node) {
  int depth = -1;
  Tree_node* current_node = node;
  while (current_node != ((void *)0)) {
    depth++;
    current_node = current_node->parent;
  }
  return depth;
}

canonical_original_code:
int node_depth(struct tree_node *node) {
  int depth = -1;
  struct tree_node *current_node = node;
  while (current_node != ((void *)0)) {
    depth++;
    current_node = current_node->parent;
  }
  return depth;
}

variable_types: depth int


decompiled_code:
__int64 __fastcall get_prob_node(__int64 a1)
{
__int64 i; // rdi

for ( i = prob_root; bic_root != a1; a1 = *(_QWORD *)(a1 + 40) )
i = get_child_node(i, (unsigned int)*(char *)(a1 + 16));
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 i; // rdi

for ( i = prob_root; bic_root != a1; a1 = *(_QWORD *)(a1 + 40) )
i = get_child_node(i, (unsigned int)*(char *)(a1 + 16));
return i;
}

original_code:
Tree_node* get_prob_node(Tree_node* bic_node) {
  Tree_node* prob_node = prob_root;
  Tree_node* parent_node = bic_node;
  while (parent_node != bic_root) {
    prob_node = get_child_node(prob_node, parent_node->symbol);
    parent_node = parent_node->parent;
  }
  return prob_node;
}

canonical_original_code:
struct tree_node *get_prob_node(struct tree_node *bic_node) {
  struct tree_node *prob_node = prob_root;
  struct tree_node *parent_node = bic_node;
  while (parent_node != bic_root) {
    prob_node = get_child_node(prob_node, parent_node->symbol);
    parent_node = parent_node->parent;
  }
  return prob_node;
}


VwSw

original_code:
void VwSw(Tree_node* bic_node, double c) {
  if (bic_node == ((void *)0) || bic_node->bic_data == ((void *)0)) {
    return;
  }
  Tree_node* prob_node = get_prob_node(bic_node);
  if (node_depth(bic_node) == max_word_size || bic_node->child == ((void *)0)) {
    bic_node->bic_data->Sw = 0;
    bic_node->bic_data->Vw = Vw1(bic_node, prob_node, c);
    VwSw(bic_node->sibling, c);
    return;
  }
  VwSw(bic_node->child, c);
  double vw1 = Vw1(bic_node, prob_node, c);
  double vw2 = Vw2(bic_node, c);
  if (vw1 >= vw2) {
    bic_node->bic_data->Sw = 0;
    bic_node->bic_data->Vw = vw1;
  } else {
    bic_node->bic_data->Sw = 1;
    bic_node->bic_data->Vw = vw2;
  }
  VwSw(bic_node->sibling, c);
}

canonical_original_code:
void VwSw(struct tree_node *bic_node, double c) {
  if (bic_node == ((void *)0) || bic_node->bic_data == ((void *)0)) {
    return;
  }
  struct tree_node *prob_node = get_prob_node(bic_node);
  if (node_depth(bic_node) == max_word_size || bic_node->child == ((void *)0)) {
    bic_node->bic_data->Sw = 0;
    bic_node->bic_data->Vw = Vw1(bic_node, prob_node, c);
    VwSw(bic_node->sibling, c);
    return;
  }
  VwSw(bic_node->child, c);
  double vw1 = Vw1(bic_node, prob_node, c);
  double vw2 = Vw2(bic_node, c);
  if (vw1 >= vw2) {
    bic_node->bic_data->Sw = 0;
    bic_node->bic_data->Vw = vw1;
  } else {
    bic_node->bic_data->Sw = 1;
    bic_node->bic_data->Vw = vw2;
  }
  VwSw(bic_node->sibling, c);
}


decompiled_code:
double __fastcall recover_prob(char *a1)
{
__int64 v2; // rdi
char v3; // si
char *v4; // rbx

v2 = prob_root;
v3 = *a1;
if ( *a1 )
{
v4 = a1 + 1;
do
{
v2 = get_child_node(v2, (unsigned int)v3);
v3 = *v4++;
}
while ( v3 );
}
return *(double *)(*(_QWORD *)v2 + 8LL);
}

canonical_decompiled_code:
double __fastcall func4(char *a1)
{
__int64 v2; // rdi
char v3; // si
char *v4; // rbx

v2 = prob_root;
v3 = *a1;
if ( *a1 )
{
v4 = a1 + 1;
do
{
v2 = get_child_node(v2, (unsigned int)v3);
v3 = *v4++;
}
while ( v3 );
}
return *(double *)(*(_QWORD *)v2 + 8LL);
}

original_code:
double recover_prob(char* sufix) {
  Tree_node* current_node = prob_root;
  for (int i = 0; sufix[i] != '\0'; i++) {
    current_node = get_child_node(current_node, sufix[i]);
  }
  return current_node->prob_data->probability;
}

canonical_original_code:
double recover_prob(char *sufix) {
  struct tree_node *current_node = prob_root;
  for (int i = 0; sufix[i] != '\0'; i++) {
    current_node = get_child_node(current_node, sufix[i]);
  }
  return current_node->prob_data->probability;
}

variable_types:
sufix
char *

variable_types: i int


decompiled_code:
void __fastcall add_selected_words_to_tau(_QWORD *a1, __int64 a2)
{
char *v2; // r12
double v3; // xmm0_8

if ( a1 )
{
if ( *(_DWORD *)(a1[1] + 8LL) == 1 )
{
add_selected_words_to_tau(a1[3]);
}
else
{
v2 = recover_sufix((__int64)a1);
v3 = recover_prob(v2);
insert_tau_item(a2, v2, v3);
}
add_selected_words_to_tau(a1[4]);
}
}

canonical_decompiled_code:
void __fastcall func5(_QWORD *a1, __int64 a2)
{
char *v2; // r12
double v3; // xmm0_8

if ( a1 )
{
if ( *(_DWORD *)(a1[1] + 8LL) == 1 )
{
func5(a1[3]);
}
else
{
v2 = recover_sufix((__int64)a1);
v3 = func4(v2);
insert_tau_item(a2, v2, v3);
}
func5(a1[4]);
}
}

original_code:
void add_selected_words_to_tau(Tree_node* node, Tau* tau) {
  if(node == ((void *)0)) {
    return;
  }
  if (node->bic_data->Sw == 1) {
    add_selected_words_to_tau(node->child, tau);
  } else {
    char* sufix = recover_sufix(node);
    double prob = recover_prob(sufix);
    insert_tau_item(tau, sufix, prob);
  }
  add_selected_words_to_tau(node->sibling, tau);
}

canonical_original_code:
void add_selected_words_to_tau(struct tree_node *node, struct tau *tau) {
  if(node == ((void *)0)) {
    return;
  }
  if (node->bic_data->Sw == 1) {
    add_selected_words_to_tau(node->child, tau);
  } else {
    char *sufix = recover_sufix(node);
    double prob = recover_prob(sufix);
    insert_tau_item(tau, sufix, prob);
  }
  add_selected_words_to_tau(node->sibling, tau);
}

variable_types: struct tau { struct tau_item { char *string; double probability; struct tau_item *next; } *item; double c; } *

variable_types: prob double

user_defined_types: struct tau { struct tau_item *item; double c; }


decompiled_code:
__int64 __fastcall calculate_BIC(double a1)
{
__int64 v1; // rbx

VwSw(*(_QWORD **)(bic_root + 24LL), a1);
v1 = new_Tau();
*(double *)(v1 + 8) = a1;
add_selected_words_to_tau(*(_QWORD **)(bic_root + 24LL), v1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(double a1)
{
__int64 v1; // rbx

func3(*(_QWORD **)(bic_root + 24LL), a1);
v1 = new_Tau();
*(double *)(v1 + 8) = a1;
func5(*(_QWORD **)(bic_root + 24LL), v1);
return v1;
}

original_code:
Tau* calculate_BIC(double c) {
  VwSw(bic_root->child, c);
  Tau* tau = new_Tau();
  tau->c = c;
  add_selected_words_to_tau(bic_root->child, tau);
  return tau;
}

canonical_original_code:
struct tau *calculate_BIC(double c) {
  VwSw(bic_root->child, c);
  struct tau *tau = new_Tau();
  tau->c = c;
  add_selected_words_to_tau(bic_root->child, tau);
  return tau;
}

return_type: struct tau { struct tau_item { char *string; double probability; struct tau_item *next; } *item; double c; } *


decompiled_code:
char *most_frequent_word()
{
char *v0; // rbx
_DWORD **v1; // rax
int v2; // ecx
_DWORD **v3; // rdx
char *v4; // rax

v0 = (char *)malloc(max_word_size + 1);
v1 = most_frequent_child(prob_root);
v2 = max_word_size;
if ( max_word_size > 0 )
{
v3 = v1;
v4 = &v0[max_word_size - 1];
do
{
*v4 = *((_BYTE *)v3 + 16);
v3 = (_DWORD **)v3[5];
--v4;
}
while ( v4 != &v0[v2 - 2LL - (unsigned int)(v2 - 1)] );
}
return v0;
}

canonical_decompiled_code:
char *func7()
{
char *v0; // rbx
_DWORD **v1; // rax
int v2; // ecx
_DWORD **v3; // rdx
char *v4; // rax

v0 = (char *)malloc(max_word_size + 1);
v1 = most_frequent_child(prob_root);
v2 = max_word_size;
if ( max_word_size > 0 )
{
v3 = v1;
v4 = &v0[max_word_size - 1];
do
{
*v4 = *((_BYTE *)v3 + 16);
v3 = (_DWORD **)v3[5];
--v4;
}
while ( v4 != &v0[v2 - 2LL - (unsigned int)(v2 - 1)] );
}
return v0;
}

original_code:
char* most_frequent_word() {
  char* word = (char*) malloc((max_word_size+1)*sizeof(char));
  Tree_node* max_node = most_frequent_child(prob_root);
  Tree_node* node = max_node;
  for (int i = 1; i <= max_word_size; i++) {
    word[max_word_size-i] = node->symbol;
    node = node->parent;
  }
  return word;
}

canonical_original_code:
char *most_frequent_word() {
  char *word = (char*) malloc((max_word_size+1)*sizeof(char));
  struct tree_node *max_node = most_frequent_child(prob_root);
  struct tree_node *node = max_node;
  for (int i = 1; i <= max_word_size; i++) {
    word[max_word_size-i] = node->symbol;
    node = node->parent;
  }
  return word;
}

variable_types:
word
char *


decompiled_code:
double __fastcall L_tau(__int64 *a1)
{
__int64 v1; // r12
double v2; // r13
const char *v3; // rbp
int v4; // eax
__int64 v5; // rdi
const char *v6; // rbx
__int64 v7; // rbp

v1 = *a1;
if ( !*a1 )
return *(double *)&LC1;
v2 = *(double *)&LC1;
do
{
v3 = *(const char **)v1;
v4 = strlen(*(const char **)v1);
v5 = prob_root;
if ( v4 > 0 )
{
v6 = v3;
v7 = (__int64)&v3[v4 - 1 + 1];
do
v5 = get_child_node(v5, (unsigned int)*v6++);
while ( v6 != (const char *)v7 );
}
if ( v5 )
v2 = v2 * *(double *)(*(_QWORD *)v5 + 24LL);
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
double __fastcall func8(__int64 *a1)
{
__int64 v1; // r12
double v2; // r13
const char *v3; // rbp
int v4; // eax
__int64 v5; // rdi
const char *v6; // rbx
__int64 v7; // rbp

v1 = *a1;
if ( !*a1 )
return *(double *)&LC1;
v2 = *(double *)&LC1;
do
{
v3 = *(const char **)v1;
v4 = strlen(*(const char **)v1);
v5 = prob_root;
if ( v4 > 0 )
{
v6 = v3;
v7 = (__int64)&v3[v4 - 1 + 1];
do
v5 = get_child_node(v5, (unsigned int)*v6++);
while ( v6 != (const char *)v7 );
}
if ( v5 )
v2 = v2 * *(double *)(*(_QWORD *)v5 + 24LL);
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
return v2;
}

original_code:
double L_tau(Tau* tau) {
  double value = 1.0;
  Tau_item* item = tau->item;
  while (item != ((void *)0)) {
    char* word = item->string;
    int word_length = strlen(word);
    Tree_node* node = prob_root;
    for (int i = 0; i < word_length; i++) {
      node = get_child_node(node, word[i]);
    }
    if (node != ((void *)0)) {
      value *= node->prob_data->Lw;
    }
    item = item->next;
  }
  return value;
}

canonical_original_code:
double L_tau(struct tau *tau) {
  double value = 1.0;
  struct tau_item *item = tau->item;
  while (item != ((void *)0)) {
    char *word = item->string;
    int word_length = strlen(word);
    struct tree_node *node = prob_root;
    for (int i = 0; i < word_length; i++) {
      node = get_child_node(node, word[i]);
    }
    if (node != ((void *)0)) {
      value *= node->prob_data->Lw;
    }
    item = item->next;
  }
  return value;
}

variable_types: value double

variable_types: struct tau_item { char *string; double probability; struct tau_item *next; } *


kmp

decompiled_code:
__int64 __fastcall kmp(const char *a1, int a2, const char *a3)
{
unsigned int v4; // ebx
int v6; // er14
int v7; // er15
_DWORD *v8; // rdi
unsigned int v9; // ebp
int v10; // edx
int v11; // er15

v4 = a2;
v6 = strlen(a1);
v7 = strlen(a3);
v8 = kmp_table(a3);
if ( v6 <= a2 )
{
LABEL_10:
free(v8);
return (unsigned int)-1;
}
v9 = a2;
v10 = 0;
v11 = v7 - 1;
while ( 1 )
{
if ( a3[v10] != a1[v4] )
{
v10 = v8[v10];
v9 = v4 - v10;
if ( v10 < 0 )
v10 = 0;
goto LABEL_6;
}
if ( v11 == v10 )
break;
++v10;
LABEL_6:
v4 = v9 + v10;
if ( (int)(v9 + v10) >= v6 )
goto LABEL_10;
}
free(v8);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, int a2, const char *a3)
{
unsigned int v4; // ebx
int v6; // er14
int v7; // er15
_DWORD *v8; // rdi
unsigned int v9; // ebp
int v10; // edx
int v11; // er15

v4 = a2;
v6 = strlen(a1);
v7 = strlen(a3);
v8 = kmp_table(a3);
if ( v6 <= a2 )
{
LABEL_10:
free(v8);
return (unsigned int)-1;
}
v9 = a2;
v10 = 0;
v11 = v7 - 1;
while ( 1 )
{
if ( a3[v10] != a1[v4] )
{
v10 = v8[v10];
v9 = v4 - v10;
if ( v10 < 0 )
v10 = 0;
goto LABEL_6;
}
if ( v11 == v10 )
break;
++v10;
LABEL_6:
v4 = v9 + v10;
if ( (int)(v9 + v10) >= v6 )
goto LABEL_10;
}
free(v8);
return v9;
}

original_code:
int kmp(char* source, int init, char* match) {
  int source_length = strlen(source);
  int match_length = strlen(match);
  int m = init;
  int i = 0;
  int* t = kmp_table(match);
  while (m + i < source_length) {
    if (match[i] == source[m + i]) {
      if (i == match_length - 1) {
        free(t);
        return m;
      }
      i++;
    } else {
      m = m + i - t[i];
      if (t[i] > -1) {
        i = t[i];
      } else {
        i = 0;
      }
    }
  }
  free(t);
  return -1;
}

canonical_original_code:
int kmp(char *source, int init, char *match) {
  int source_length = strlen(source);
  int match_length = strlen(match);
  int m = init;
  int i = 0;
  int *t = kmp_table(match);
  while (m + i < source_length) {
    if (match[i] == source[m + i]) {
      if (i == match_length - 1) {
        free(t);
        return m;
      }
      i++;
    } else {
      m = m + i - t[i];
      if (t[i] > -1) {
        i = t[i];
      } else {
        i = 0;
      }
    }
  }
  free(t);
  return -1;
}

variable_types:
source
char *

variable_types: init int

variable_types:
match
char *

variable_types: m int

variable_types:
t
int *


decompiled_code:
size_t __fastcall insert_sample(const char *a1)
{
const char *v1; // r13
size_t result; // rax
int v3; // er12
int v4; // er15
__int64 v5; // r14
_DWORD **v6; // rdi
const char *v7; // rbp
int v8; // ebx
__int64 v9; // r14
__int64 v10; // rdi
const char *v11; // rbx

v1 = a1;
result = strlen(a1);
if ( *a1 )
{
v3 = result;
v4 = result;
v5 = 0LL;
do
{
v6 = (_DWORD **)prob_root;
if ( max_word_size >= 0 && v4 > (int)v5 )
{
v7 = &v1[v5];
v8 = 0;
do
{
v6 = (_DWORD **)get_create_node_child(v6, (unsigned int)*v7, 0LL);
++**v6;
if ( max_word_size < ++v8 )
break;
++v7;
}
while ( v8 != v3 );
}
result = (unsigned __int8)v1[++v5];
--v3;
}
while ( (_BYTE)result );
if ( *v1 )
{
v9 = 0LL;
do
{
v10 = bic_root;
if ( max_word_size > 0 && (int)v9 >= 0 )
{
v11 = v1;
do
{
v10 = get_create_node_child(v10, (unsigned int)*v11, 1LL);
if ( max_word_size <= (int)v1 + 1 - (int)v11 )
break;
--v11;
}
while ( v11 != &v1[-v9 - 1] );
}
result = *((unsigned __int8 *)v1 + 1);
++v9;
++v1;
}
while ( (_BYTE)result );
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
const char *v1; // r13
size_t result; // rax
int v3; // er12
int v4; // er15
__int64 v5; // r14
_DWORD **v6; // rdi
const char *v7; // rbp
int v8; // ebx
__int64 v9; // r14
__int64 v10; // rdi
const char *v11; // rbx

v1 = a1;
result = strlen(a1);
if ( *a1 )
{
v3 = result;
v4 = result;
v5 = 0LL;
do
{
v6 = (_DWORD **)prob_root;
if ( max_word_size >= 0 && v4 > (int)v5 )
{
v7 = &v1[v5];
v8 = 0;
do
{
v6 = (_DWORD **)get_create_node_child(v6, (unsigned int)*v7, 0LL);
++**v6;
if ( max_word_size < ++v8 )
break;
++v7;
}
while ( v8 != v3 );
}
result = (unsigned __int8)v1[++v5];
--v3;
}
while ( (_BYTE)result );
if ( *v1 )
{
v9 = 0LL;
do
{
v10 = bic_root;
if ( max_word_size > 0 && (int)v9 >= 0 )
{
v11 = v1;
do
{
v10 = get_create_node_child(v10, (unsigned int)*v11, 1LL);
if ( max_word_size <= (int)v1 + 1 - (int)v11 )
break;
--v11;
}
while ( v11 != &v1[-v9 - 1] );
}
result = *((unsigned __int8 *)v1 + 1);
++v9;
++v1;
}
while ( (_BYTE)result );
}
}
return result;
}

original_code:
void insert_sample(char* sample) {
  int sample_length = strlen(sample);
  for (int i = 0; sample[i] != '\0'; i++) {
    Tree_node* current_node = prob_root;
    for (int d = 0; d < max_word_size + 1 && d + i < sample_length; d++) {
      current_node = get_create_node_child(current_node, sample[i+d], PROB);
      current_node->prob_data->occurrences++;
    }
  }
  for (int i = 0; sample[i] != '\0'; i++) {
    Tree_node* current_node = bic_root;
    for (int d = 0; d < max_word_size && i - d >= 0; d++) {
      current_node = get_create_node_child(current_node, sample[i-d], BIC);
    }
  }
}

canonical_original_code:
void insert_sample(char *sample) {
  int sample_length = strlen(sample);
  for (int i = 0; sample[i] != '\0'; i++) {
    struct tree_node *current_node = prob_root;
    for (int d = 0; d < max_word_size + 1 && d + i < sample_length; d++) {
      current_node = get_create_node_child(current_node, sample[i+d], PROB);
      current_node->prob_data->occurrences++;
    }
  }
  for (int i = 0; sample[i] != '\0'; i++) {
    struct tree_node *current_node = bic_root;
    for (int d = 0; d < max_word_size && i - d >= 0; d++) {
      current_node = get_create_node_child(current_node, sample[i-d], BIC);
    }
  }
}

variable_types:
sample
char *

variable_types: struct tree_node { struct prob_data { int occurrences; double probability; int degrees_freedom; double Lw; } *prob_data; struct bic_data { double Vw; int Sw; } *bic_data; char symbol; struct tree_node *child; struct tree_node *sibling; struct tree_node *parent; } *

variable_types: d int


decompiled_code:
__int64 size_of_sample()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = *(_QWORD *)(prob_root + 24);
if ( !v0 )
return 0;
v1 = 0;
do
{
v1 += **(_DWORD **)v0;
v0 = *(_QWORD *)(v0 + 32);
}
while ( v0 );
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = *(_QWORD *)(prob_root + 24);
if ( !v0 )
return 0;
v1 = 0;
do
{
v1 += **(_DWORD **)v0;
v0 = *(_QWORD *)(v0 + 32);
}
while ( v0 );
return v1;
}

original_code:
int size_of_sample() {
  int n = 0;
  Tree_node* current_node = prob_root->child;
  while (current_node != ((void *)0)) {
    n += current_node->prob_data->occurrences;
    current_node = current_node->sibling;
  }
  return n;
}

canonical_original_code:
int size_of_sample() {
  int n = 0;
  struct tree_node *current_node = prob_root->child;
  while (current_node != ((void *)0)) {
    n += current_node->prob_data->occurrences;
    current_node = current_node->sibling;
  }
  return n;
}

variable_types: n int


original_code:
void set_degrees_freedom(Tree_node* node) {
  if (node == ((void *)0) || node->prob_data == ((void *)0)) {
    return;
  }
  Tree_node* current_node = node->child;
  int df = 0;
  while (current_node != ((void *)0)) {
    df++;
    current_node = current_node->sibling;
  }
  node->prob_data->degrees_freedom = df;
}

canonical_original_code:
void set_degrees_freedom(struct tree_node *node) {
  if (node == ((void *)0) || node->prob_data == ((void *)0)) {
    return;
  }
  struct tree_node *current_node = node->child;
  int df = 0;
  while (current_node != ((void *)0)) {
    df++;
    current_node = current_node->sibling;
  }
  node->prob_data->degrees_freedom = df;
}

variable_types: df int


decompiled_code:
__int64 __fastcall set_probability(_QWORD *a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax

v1 = *(_QWORD *)(a1[5] + 24LL);
if ( v1 )
{
v2 = 0;
do
{
v2 += **(_DWORD **)v1;
v1 = *(_QWORD *)(v1 + 32);
}
while ( v1 );
}
else
{
v2 = 0;
}
result = *a1;
*(double *)(*a1 + 8LL) = (double)*(int *)*a1 / (double)v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax

v1 = *(_QWORD *)(a1[5] + 24LL);
if ( v1 )
{
v2 = 0;
do
{
v2 += **(_DWORD **)v1;
v1 = *(_QWORD *)(v1 + 32);
}
while ( v1 );
}
else
{
v2 = 0;
}
result = *a1;
*(double *)(*a1 + 8LL) = (double)*(int *)*a1 / (double)v2;
return result;
}

original_code:
void set_probability(Tree_node* node) {
  int sum_occurrences = 0;
  Tree_node* current_node = node->parent->child;
  while (current_node != ((void *)0)) {
    sum_occurrences += current_node->prob_data->occurrences;
    current_node = current_node->sibling;
  }
  node->prob_data->probability = node->prob_data->occurrences / (double) sum_occurrences;
}

canonical_original_code:
void set_probability(struct tree_node *node) {
  int sum_occurrences = 0;
  struct tree_node *current_node = node->parent->child;
  while (current_node != ((void *)0)) {
    sum_occurrences += current_node->prob_data->occurrences;
    current_node = current_node->sibling;
  }
  node->prob_data->probability = node->prob_data->occurrences / (double) sum_occurrences;
}


decompiled_code:
__int64 __fastcall calculate_probabilities(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
if ( *a1 )
{
set_degrees_freedom(a1);
set_probability(a1);
calculate_probabilities(a1[3]);
result = calculate_probabilities(a1[4]);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
if ( *a1 )
{
func2(a1);
func3(a1);
func4(a1[3]);
result = func4(a1[4]);
}
}
return result;
}

original_code:
void calculate_probabilities(Tree_node* node) {
  if (node == ((void *)0) || node->prob_data == ((void *)0)) {
    return;
  }
  set_degrees_freedom(node);
  set_probability(node);
  calculate_probabilities(node->child);
  calculate_probabilities(node->sibling);
}

canonical_original_code:
void calculate_probabilities(struct tree_node *node) {
  if (node == ((void *)0) || node->prob_data == ((void *)0)) {
    return;
  }
  set_degrees_freedom(node);
  set_probability(node);
  calculate_probabilities(node->child);
  calculate_probabilities(node->sibling);
}


decompiled_code:
__int64 __fastcall calculate_Lw(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 result; // rax
double v3; // [rsp+0h] [rbp-20h]

if ( a1 && *a1 )
{
v1 = (_QWORD *)a1[3];
if ( v1 )
{
v3 = *(double *)&LC0;
do
{
v3 = pow(*(double *)(*v1 + 8LL), (double)*(int *)*v1) * v3;
v1 = (_QWORD *)v1[4];
}
while ( v1 );
}
else
{
v3 = *(double *)&LC0;
}
*(double *)(*a1 + 24LL) = v3;
calculate_Lw(a1[3]);
result = calculate_Lw(a1[4]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 result; // rax
double v3; // [rsp+0h] [rbp-20h]

if ( a1 && *a1 )
{
v1 = (_QWORD *)a1[3];
if ( v1 )
{
v3 = *(double *)&LC0;
do
{
v3 = pow(*(double *)(*v1 + 8LL), (double)*(int *)*v1) * v3;
v1 = (_QWORD *)v1[4];
}
while ( v1 );
}
else
{
v3 = *(double *)&LC0;
}
*(double *)(*a1 + 24LL) = v3;
func5(a1[3]);
result = func5(a1[4]);
}
return result;
}

original_code:
void calculate_Lw(Tree_node* node) {
  if (node == ((void *)0) || node->prob_data == ((void *)0)) {
    return;
  }
  double value = 1.0f;
  Tree_node* child = node->child;
  while (child != ((void *)0)) {
    value *= pow(child->prob_data->probability, child->prob_data->occurrences);
    child = child->sibling;
  }
  node->prob_data->Lw = value;
  calculate_Lw(node->child);
  calculate_Lw(node->sibling);
}

canonical_original_code:
void calculate_Lw(struct tree_node *node) {
  if (node == ((void *)0) || node->prob_data == ((void *)0)) {
    return;
  }
  double value = 1.0f;
  struct tree_node *child = node->child;
  while (child != ((void *)0)) {
    value *= pow(child->prob_data->probability, child->prob_data->occurrences);
    child = child->sibling;
  }
  node->prob_data->Lw = value;
  calculate_Lw(node->child);
  calculate_Lw(node->sibling);
}


decompiled_code:
__int64 __fastcall setup_BIC(const char **a1, int a2)
{
const char *v3; // rdi
const char **v4; // rbx

if ( bic_root )
free_node();
if ( prob_root )
free_node();
bic_root = new_Tree_node();
prob_root = new_Tree_node();
max_word_size = a2;
v3 = *a1;
if ( *a1 )
{
v4 = a1 + 1;
do
{
insert_sample(v3);
v3 = *v4++;
}
while ( v3 );
}
sample_size = size_of_sample();
calculate_probabilities(*(_QWORD **)(prob_root + 24));
return calculate_Lw(*(_QWORD **)(prob_root + 24));
}

canonical_decompiled_code:
__int64 __fastcall func6(const char **a1, int a2)
{
const char *v3; // rdi
const char **v4; // rbx

if ( bic_root )
free_node();
if ( prob_root )
free_node();
bic_root = new_Tree_node();
prob_root = new_Tree_node();
max_word_size = a2;
v3 = *a1;
if ( *a1 )
{
v4 = a1 + 1;
do
{
func0(v3);
v3 = *v4++;
}
while ( v3 );
}
sample_size = func1();
func4(*(_QWORD **)(prob_root + 24));
return func5(*(_QWORD **)(prob_root + 24));
}

original_code:
void setup_BIC(char** samples, int depth) {
  if (bic_root != ((void *)0)) {
    free_node(bic_root);
  }
  if (prob_root != ((void *)0)) {
    free_node(prob_root);
  }
  bic_root = new_Tree_node();
  prob_root = new_Tree_node();
  max_word_size = depth;
  for (int i = 0; samples[i] != ((void *)0); i++) {
    insert_sample(samples[i]);
  }
  sample_size = size_of_sample();
  calculate_probabilities(prob_root->child);
  calculate_Lw(prob_root->child);
}

canonical_original_code:
void setup_BIC(char **samples, int depth) {
  if (bic_root != ((void *)0)) {
    free_node(bic_root);
  }
  if (prob_root != ((void *)0)) {
    free_node(prob_root);
  }
  bic_root = new_Tree_node();
  prob_root = new_Tree_node();
  max_word_size = depth;
  for (int i = 0; samples[i] != ((void *)0); i++) {
    insert_sample(samples[i]);
  }
  sample_size = size_of_sample();
  calculate_probabilities(prob_root->child);
  calculate_Lw(prob_root->child);
}

variable_types:
samples
char **

variable_types: depth int


decompiled_code:
double *__fastcall new_tau_item(__int64 a1, double a2)
{
double *result; // rax

result = (double *)malloc(0x18uLL);
*(_QWORD *)result = a1;
result[1] = a2;
result[2] = 0.0;
return result;
}

canonical_decompiled_code:
double *__fastcall func0(__int64 a1, double a2)
{
double *result; // rax

result = (double *)malloc(0x18uLL);
*(_QWORD *)result = a1;
result[1] = a2;
result[2] = 0.0;
return result;
}

original_code:
Tau_item* new_tau_item(char* string, double prob) {
  Tau_item* tau_item = (Tau_item*) malloc(sizeof(Tau_item));
  tau_item->string = string;
  tau_item->probability = prob;
  tau_item->next = ((void *)0);
  return tau_item;
}

canonical_original_code:
struct tau_item *new_tau_item(char *string, double prob) {
  struct tau_item *tau_item = (Tau_item*) malloc(sizeof(Tau_item));
  tau_item->string = string;
  tau_item->probability = prob;
  tau_item->next = ((void *)0);
  return tau_item;
}

variable_types:
string
char *

return_type: struct tau_item { char *string; double probability; struct tau_item *next; } *


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

result = malloc(0x10uLL);
*result = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
return result;
}

original_code:
Tau* new_Tau() {
  Tau* tau = (Tau*) malloc(sizeof(Tau));
  tau->item = ((void *)0);
  return tau;
}

canonical_original_code:
struct tau *new_Tau() {
  struct tau *tau = (Tau*) malloc(sizeof(Tau));
  tau->item = ((void *)0);
  return tau;
}

variable_types: struct tau { struct tau_item { char *string; double probability; struct tau_item *next; } *item; double c; } *


decompiled_code:
void __fastcall free_Tau(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void free_Tau(Tau* t) {
  Tau_item* item = t->item;
  while (item != ((void *)0)) {
    Tau_item* next_item = item->next;
    free(item);
    item = next_item;
  }
  free(t);
  t = ((void *)0);
}

canonical_original_code:
void free_Tau(struct tau *t) {
  struct tau_item *item = t->item;
  while (item != ((void *)0)) {
    struct tau_item *next_item = item->next;
    free(item);
    item = next_item;
  }
  free(t);
  t = ((void *)0);
}

user_defined_types: struct tau_item { char *string; double probability; struct tau_item *next; }


decompiled_code:
__int64 __fastcall items_in_Tau(__int64 *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
return v2;
}

original_code:
int items_in_Tau(Tau* t) {
  int items = 0;
  Tau_item* item = t->item;
  while (item != ((void *)0)) {
    items++;
    item = item->next;
  }
  return items;
}

canonical_original_code:
int items_in_Tau(struct tau *t) {
  int items = 0;
  struct tau_item *item = t->item;
  while (item != ((void *)0)) {
    items++;
    item = item->next;
  }
  return items;
}

variable_types: items int


decompiled_code:
__int64 __fastcall equals_Tau(__int64 *a1, __int64 *a2)
{
int v2; // er12
int v3; // edx
__int64 result; // rax
__int64 v5; // r12
__int64 v6; // r13
const char *v7; // rbp
__int64 v8; // rbx

v2 = items_in_Tau(a1);
v3 = items_in_Tau(a2);
result = 0LL;
if ( v2 == v3 )
{
v5 = *a1;
if ( *a1 )
{
v6 = *a2;
while ( v6 )
{
v7 = *(const char **)v5;
v8 = v6;
while ( strcmp(v7, *(const char **)v8) )
{
v8 = *(_QWORD *)(v8 + 16);
if ( !v8 )
return 0LL;
}
v5 = *(_QWORD *)(v5 + 16);
if ( !v5 )
return 1LL;
}
result = 0LL;
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, __int64 *a2)
{
int v2; // er12
int v3; // edx
__int64 result; // rax
__int64 v5; // r12
__int64 v6; // r13
const char *v7; // rbp
__int64 v8; // rbx

v2 = func4(a1);
v3 = func4(a2);
result = 0LL;
if ( v2 == v3 )
{
v5 = *a1;
if ( *a1 )
{
v6 = *a2;
while ( v6 )
{
v7 = *(const char **)v5;
v8 = v6;
while ( strcmp(v7, *(const char **)v8) )
{
v8 = *(_QWORD *)(v8 + 16);
if ( !v8 )
return 0LL;
}
v5 = *(_QWORD *)(v5 + 16);
if ( !v5 )
return 1LL;
}
result = 0LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
int equals_Tau(Tau* t1, Tau* t2) {
  if (items_in_Tau(t1) != items_in_Tau(t2)) {
    return 0;
  }
  Tau_item* item_t1 = t1->item;
  while (item_t1 != ((void *)0)) {
    Tau_item* item_t2 = t2->item;
    while(1) {
      if (item_t2 == ((void *)0)) {
        return 0;
      }
      if (strcmp(item_t1->string, item_t2->string) == 0) {
        break;
      }
      item_t2 = item_t2->next;
    }
    item_t1 = item_t1->next;
  }
  return 1;
}

canonical_original_code:
int equals_Tau(struct tau *t1, struct tau *t2) {
  if (items_in_Tau(t1) != items_in_Tau(t2)) {
    return 0;
  }
  struct tau_item *item_t1 = t1->item;
  while (item_t1 != ((void *)0)) {
    struct tau_item *item_t2 = t2->item;
    while(1) {
      if (item_t2 == ((void *)0)) {
        return 0;
      }
      if (strcmp(item_t1->string, item_t2->string) == 0) {
        break;
      }
      item_t2 = item_t2->next;
    }
    item_t1 = item_t1->next;
  }
  return 1;
}


decompiled_code:
int __fastcall print_Tau(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
result = printf("%s ", *(const char **)i);
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
result = printf("%s ", *(const char **)i);
return result;
}

original_code:
void print_Tau(Tau* tau) {
  Tau_item* item = tau->item;
  while (item != ((void *)0)) {
    printf("%s ", item->string);
    item = item->next;
  }
}

canonical_original_code:
void print_Tau(struct tau *tau) {
  struct tau_item *item = tau->item;
  while (item != ((void *)0)) {
    printf("%s ", item->string);
    item = item->next;
  }
}