decompiled_code:
const char **__fastcall rt_std_from_lld(const char **a1)
{
int v1; // eax
const char *v3; // r15
const char *v4; // r14
const char *v5; // r13
const char *v6; // r12
const char *v7; // rbp
const char *v8; // rax

if ( !a1 )
elog_fdie(6LL, "iiab/rt_std.c", 269LL, "rt_std_from_lld", "passed NULL low level descriptor");
v1 = *(_DWORD *)a1;
if ( v1 != 7822399 && v1 != 4299644 && v1 != 1053976 )
{
if ( !v1 )
elog_fprintf(
6LL,
"iiab/rt_std.c",
275LL,
"rt_std_from_lld",
"magic type of 0 encountered, possibly previously deleted\n");
v3 = rt_stderr_description();
v4 = rt_stderr_prefix();
v5 = rt_stdout_description();
v6 = rt_stdout_prefix();
v7 = rt_stdin_description();
v8 = rt_stdin_prefix();
elog_fdie(
6LL,
"iiab/rt_std.c",
277LL,
"rt_std_from_lld",
"magic type mismatch: we were given %s (%s [magic %d]) but can only handle either %s (%s) or %s (%s) or %s (%s)",
a1[1],
a1[2],
*(unsigned int *)a1,
v8,
v7,
v6,
v5,
v4,
v3);
}
return a1;
}

canonical_decompiled_code:
const char **__fastcall func19(const char **a1)
{
int v1; // eax
const char *v3; // r15
const char *v4; // r14
const char *v5; // r13
const char *v6; // r12
const char *v7; // rbp
const char *v8; // rax

if ( !a1 )
elog_fdie(6LL, "iiab/rt_std.c", 269LL, "rt_std_from_lld", "passed NULL low level descriptor");
v1 = *(_DWORD *)a1;
if ( v1 != 7822399 && v1 != 4299644 && v1 != 1053976 )
{
if ( !v1 )
elog_fprintf(
6LL,
"iiab/rt_std.c",
275LL,
"rt_std_from_lld",
"magic type of 0 encountered, possibly previously deleted\n");
v3 = func8();
v4 = func7();
v5 = func5();
v6 = func4();
v7 = func2();
v8 = func1();
elog_fdie(
6LL,
"iiab/rt_std.c",
277LL,
"rt_std_from_lld",
"magic type mismatch: we were given %s (%s [magic %d]) but can only handle either %s (%s) or %s (%s) or %s (%s)",
a1[1],
a1[2],
*(unsigned int *)a1,
v8,
v7,
v6,
v5,
v4,
v3);
}
return a1;
}

original_code:
RT_STDD rt_std_from_lld(RT_LLD lld )
{
     if (!lld)
   elog_fdie(FATAL,"iiab/rt_std.c",269,__PRETTY_FUNCTION__,"passed NULL low level descriptor");
     if ( (((RT_STDD)lld)->magic != 4299644) &&
   (((RT_STDD)lld)->magic != 7822399) &&
   (((RT_STDD)lld)->magic != 1053976) ) {
          if (((RT_STDD)lld)->magic == 0)
        elog_fprintf(FATAL,"iiab/rt_std.c",275,__PRETTY_FUNCTION__,"magic type of 0 encountered, possibly " "previously deleted\n");
   elog_fdie(FATAL,"iiab/rt_std.c",277,__PRETTY_FUNCTION__,"magic type mismatch: we were given " "%s (%s [magic %d]) but can only handle either %s (%s) " "or %s (%s) or %s (%s)", ((RT_STDD)lld)->prefix, ((RT_STDD)lld)->description, ((RT_STDD)lld)->magic, rt_stdin_prefix(), rt_stdin_description(), rt_stdout_prefix(), rt_stdout_description(), rt_stderr_prefix(), rt_stderr_description());
     }
     return (RT_STDD) lld;
}

canonical_original_code:
struct rt_std_desc *rt_std_from_lld(void *lld)
{
     if (!lld)
   elog_fdie(FATAL,"iiab/rt_std.c",269,__PRETTY_FUNCTION__,"passed NULL low level descriptor");
     if ( (((struct rt_std_desc *)lld)->magic != 4299644) &&
   (((struct rt_std_desc *)lld)->magic != 7822399) &&
   (((struct rt_std_desc *)lld)->magic != 1053976) ) {
          if (((struct rt_std_desc *)lld)->magic == 0)
        elog_fprintf(FATAL,"iiab/rt_std.c",275,__PRETTY_FUNCTION__,"magic type of 0 encountered, possibly " "previously deleted\n");
   elog_fdie(FATAL,"iiab/rt_std.c",277,__PRETTY_FUNCTION__,"magic type mismatch: we were given " "%s (%s [magic %d]) but can only handle either %s (%s) " "or %s (%s) or %s (%s)", ((struct rt_std_desc *)lld)->prefix, ((struct rt_std_desc *)lld)->description, ((struct rt_std_desc *)lld)->magic, rt_stdin_prefix(), rt_stdin_description(), rt_stdout_prefix(), rt_stdout_description(), rt_stderr_prefix(), rt_stderr_description());
     }
     return (struct rt_std_desc *) lld;
}

return_type: struct rt_std_desc { int magic; char *prefix; char *description; int fd; } *


repo: SystemGarden/habitat

decompiled_code:
__int64 __fastcall rt_std_close(const char **a1)
{
const char **v1; // rax

v1 = rt_std_from_lld(a1);
*(_DWORD *)v1 = 0;
return nm_nfree(v1, "iiab/rt_std.c", 123LL, "rt_std_close");
}

canonical_decompiled_code:
__int64 __fastcall func20(const char **a1)
{
const char **v1; // rax

v1 = func19(a1);
*(_DWORD *)v1 = 0;
return nm_nfree(v1, "iiab/rt_std.c", 123LL, "rt_std_close");
}

original_code:
void rt_std_close (RT_LLD lld)
{
     RT_STDD rt;
     rt = rt_std_from_lld(lld);
     rt->magic = 0;
     nm_nfree(rt,"iiab/rt_std.c",123,__PRETTY_FUNCTION__);
}

canonical_original_code:
void rt_std_close(void *lld)
{
     struct rt_std_desc *rt;
     rt = rt_std_from_lld(lld);
     rt->magic = 0;
     nm_nfree(rt,"iiab/rt_std.c",123,__PRETTY_FUNCTION__);
}

variable_types:
lld
void *

variable_types: struct rt_std_desc { int magic; char *prefix; char *description; int fd; } *

return_type: void


decompiled_code:
__int64 __fastcall rt_std_write(const char **a1, const void *a2, int a3)
{
unsigned int v4; // ebx
int *v6; // rax
char *v7; // rax

if ( *(_DWORD *)rt_std_from_lld(a1) == 1053976 )
v4 = write(2, a2, a3);
else
v4 = write(1, a2, a3);
if ( v4 == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "write() system call returns -1: %s", v7);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func21(const char **a1, const void *a2, int a3)
{
unsigned int v4; // ebx
int *v6; // rax
char *v7; // rax

if ( *(_DWORD *)func19(a1) == 1053976 )
v4 = write(2, a2, a3);
else
v4 = write(1, a2, a3);
if ( v4 == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "write() system call returns -1: %s", v7);
}
return v4;
}

original_code:
int rt_std_write (RT_LLD lld, const void *buf, int buflen)
{
     int n;
     RT_STDD rt;
     rt = rt_std_from_lld(lld);
     if (rt->magic == 1053976)
   n = write(2, buf, buflen);
     else
   n = write(1, buf, buflen);
     if (n == -1)
   fprintf(stderr, "write() system call returns -1: %s",
    strerror((*__errno_location ())));
     return n;
}

canonical_original_code:
int rt_std_write(void *lld, void *buf, int buflen)
{
     int n;
     struct rt_std_desc *rt;
     rt = rt_std_from_lld(lld);
     if (rt->magic == 1053976)
   n = write(2, buf, buflen);
     else
   n = write(1, buf, buflen);
     if (n == -1)
   fprintf(stderr, "write() system call returns -1: %s",
    strerror((*__errno_location ())));
     return n;
}

variable_types:
buf
void *

variable_types: buflen int

variable_types: n int

return_type: int

user_defined_types: struct rt_std_desc { int magic; char *prefix; char *description; int fd; }


decompiled_code:
_BOOL8 __fastcall rt_std_twrite(const char **a1, __int64 a2)
{
const char *v2; // rbx
_BOOL8 result; // rax
int v4; // eax
int v5; // ebp

rt_std_from_lld(a1);
v2 = (const char *)table_outtable(a2);
result = 1LL;
if ( v2 )
{
v4 = strlen(v2);
v5 = rt_std_write(a1, v2, v4);
nm_nfree(v2, "iiab/rt_std.c", 157LL, "rt_std_twrite");
result = v5 != -1;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func22(const char **a1, __int64 a2)
{
const char *v2; // rbx
_BOOL8 result; // rax
int v4; // eax
int v5; // ebp

func19(a1);
v2 = (const char *)table_outtable(a2);
result = 1LL;
if ( v2 )
{
v4 = strlen(v2);
v5 = func21(a1, v2, v4);
nm_nfree(v2, "iiab/rt_std.c", 157LL, "rt_std_twrite");
result = v5 != -1;
}
return result;
}

original_code:
int rt_std_twrite (RT_LLD lld, TABLE tab)
{
     int n;
     RT_STDD rt;
     char *buf;
     rt = rt_std_from_lld(lld);
     buf = table_outtable(tab);
     if ( ! buf)
       return 1;
     n = rt_std_write(lld, buf, strlen(buf));
     nm_nfree(buf,"iiab/rt_std.c",157,__PRETTY_FUNCTION__);
     if (n == -1)
   return 0;
     else
   return 1;
}

canonical_original_code:
int rt_std_twrite(void *lld, struct table_info *tab)
{
     int n;
     struct rt_std_desc *rt;
     char *buf;
     rt = rt_std_from_lld(lld);
     buf = table_outtable(tab);
     if ( ! buf)
       return 1;
     n = rt_std_write(lld, buf, strlen(buf));
     nm_nfree(buf,"iiab/rt_std.c",157,__PRETTY_FUNCTION__);
     if (n == -1)
   return 0;
     else
   return 1;
}

variable_types: struct table_info { int ncols; int nrows; int minrowkey; int maxrowkey; struct tree_head { struct rb_node { union { struct { struct rb_node *flink; struct rb_node *blink; } list; struct { struct rb_node *left; struct rb_node *right; } child; } c; union { struct rb_node *parent; struct rb_node *root; } p; struct status { unsigned int red; unsigned int internal; unsigned int left; unsigned int root; unsigned int head; } s; union { unsigned int ikey; char *key; struct rb_node *lext; } k; union { char *val; struct rb_node *rext; } v; } *root; struct rb_node *node; } *data; struct itree_head { struct rb_node *root; struct rb_node *node; } *colorder; struct tree_head *info; struct tree_head *infolookup; struct itree_head *tobegarbage; int refcount; struct itree_head *roworder; char separator; } *

variable_types:
buf
char *

user_defined_types: struct table_info { int ncols; int nrows; int minrowkey; int maxrowkey; struct tree_head *data; struct itree_head *colorder; struct tree_head *info; struct tree_head *infolookup; struct itree_head *tobegarbage; int refcount; struct itree_head *roworder; char separator; }

user_defined_types: struct tree_head { struct rb_node *root; struct rb_node *node; }

user_defined_types: struct rb_node { union { struct { struct rb_node *flink; struct rb_node *blink; } list; struct { struct rb_node *left; struct rb_node *right; } child; } c; union { struct rb_node *parent; struct rb_node *root; } p; struct status s; union { unsigned int ikey; char *key; struct rb_node *lext; } k; union { char *val; struct rb_node *rext; } v; }


decompiled_code:
_BOOL8 __fastcall rt_std_checkpoint(const char **a1)
{
const char **v1; // rax

v1 = rt_std_from_lld(a1);
return fsync(*((_DWORD *)v1 + 6)) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func23(const char **a1)
{
const char **v1; // rax

v1 = func19(a1);
return fsync(*((_DWORD *)v1 + 6)) == 0;
}

original_code:
int rt_std_checkpoint (RT_LLD lld)
{
     RT_STDD rt;
     int r;
     rt = rt_std_from_lld(lld);
     r = fsync(rt->fd);
     if (r)
          return 0;
     else
   return 1;
}

canonical_original_code:
int rt_std_checkpoint(void *lld)
{
     struct rt_std_desc *rt;
     int r;
     rt = rt_std_from_lld(lld);
     r = fsync(rt->fd);
     if (r)
          return 0;
     else
   return 1;
}

variable_types: r int


variable_types:
k
char *

variable_types:
length
unsigned int

variable_types:
initval
unsigned int

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
c
unsigned int

variable_types:
len
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall hash_str(char *a1)
{
unsigned int v1; // eax

v1 = strlen(a1);
return hash_block(a1, v1, 685570);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
unsigned int v1; // eax

v1 = strlen(a1);
return func0(a1, v1, 685570);
}

original_code:
unsigned int hash_str(char *str) {
     return hash_block(str, strlen(str), 685570);
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall cascade_init(unsigned int a1, const char *a2)
{
int v2; // ebp
__int64 v3; // rbx
__int64 v5; // [rsp+0h] [rbp-38h] BYREF
char v6[4]; // [rsp+8h] [rbp-30h] BYREF
int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = route_stat(a2, 0LL, v7, v6, &v5);
v3 = nm_nmalloc(24LL, "iiab/cascade.c", 102LL, "cascade_init");
*(_DWORD *)v3 = a1;
*(_QWORD *)(v3 + 8) = nm_xnstrdup(a2, "iiab/cascade.c", 104LL, "cascade_init");
if ( v2 )
v2 = v7[0] + 1;
*(_DWORD *)(v3 + 16) = v2;
elog_fprintf(
1LL,
"iiab/cascade.c",
107LL,
"cascade_init",
"cascade type %d init on %s from seq %d",
a1,
a2,
(unsigned int)(v7[0] + 1));
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, const char *a2)
{
int v2; // ebp
__int64 v3; // rbx
__int64 v5; // [rsp+0h] [rbp-38h] BYREF
char v6[4]; // [rsp+8h] [rbp-30h] BYREF
int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = route_stat(a2, 0LL, v7, v6, &v5);
v3 = nm_nmalloc(24LL, "iiab/cascade.c", 102LL, "cascade_init");
*(_DWORD *)v3 = a1;
*(_QWORD *)(v3 + 8) = nm_xnstrdup(a2, "iiab/cascade.c", 104LL, "cascade_init");
if ( v2 )
v2 = v7[0] + 1;
*(_DWORD *)(v3 + 16) = v2;
elog_fprintf(
1LL,
"iiab/cascade.c",
107LL,
"cascade_init",
"cascade type %d init on %s from seq %d",
a1,
a2,
(unsigned int)(v7[0] + 1));
return v3;
}

original_code:
CASCADE *cascade_init(enum cascade_fn func,
        char *monroute )
{
     struct cascade_info *session;
     int seq, size, r;
     time_t modt;
     r = route_stat(monroute, ((void *)0), &seq, &size, &modt);
     session = nm_nmalloc(sizeof(struct cascade_info),"iiab/cascade.c",102,__PRETTY_FUNCTION__);
     session->fn = func;
     session->purl = nm_xnstrdup(monroute,"iiab/cascade.c",104,__PRETTY_FUNCTION__);
     session->seq = r ? seq+1 : 0;
     elog_fprintf(DEBUG,"iiab/cascade.c",107,__PRETTY_FUNCTION__,"cascade type %d init on %s from seq %d", func, monroute, seq+1);
     return session;
}

canonical_original_code:
struct cascade_info *cascade_init(enum cascade_fn func, char *monroute)
{
     struct cascade_info *session;
     int seq; int size; int r;
     long modt;
     r = route_stat(monroute, ((void *)0), &seq, &size, &modt);
     session = nm_nmalloc(sizeof(struct cascade_info),"iiab/cascade.c",102,__PRETTY_FUNCTION__);
     session->fn = func;
     session->purl = nm_xnstrdup(monroute,"iiab/cascade.c",104,__PRETTY_FUNCTION__);
     session->seq = r ? seq+1 : 0;
     elog_fprintf(DEBUG,"iiab/cascade.c",107,__PRETTY_FUNCTION__,"cascade type %d init on %s from seq %d", func, monroute, seq+1);
     return session;
}

variable_types:
monroute
char *

variable_types: struct cascade_info { enum cascade_fn { CASCADE_AVG=0, CASCADE_MIN=1, CASCADE_MAX=2, CASCADE_SUM=3, CASCADE_LAST=4, CASCADE_FIRST=5, CASCADE_DIFF=6, CASCADE_RATE=7 } fn; char *purl; int seq; } *

variable_types: seq int

variable_types: size int

variable_types: modt long

user_defined_types: struct cascade_info { enum cascade_fn fn; char *purl; int seq; }


decompiled_code:
__int64 __fastcall cascade_fini(__int64 a1)
{
nm_nfree(*(_QWORD *)(a1 + 8), "iiab/cascade.c", 120LL, "cascade_fini");
return nm_nfree(a1, "iiab/cascade.c", 121LL, "cascade_fini");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
nm_nfree(*(_QWORD *)(a1 + 8), "iiab/cascade.c", 120LL, "cascade_fini");
return nm_nfree(a1, "iiab/cascade.c", 121LL, "cascade_fini");
}

original_code:
void cascade_fini(CASCADE *session)
{
     nm_nfree(session->purl,"iiab/cascade.c",120,__PRETTY_FUNCTION__);
     nm_nfree(session,"iiab/cascade.c",121,__PRETTY_FUNCTION__);
}

canonical_original_code:
void cascade_fini(struct cascade_info *session)
{
     nm_nfree(session->purl,"iiab/cascade.c",120,__PRETTY_FUNCTION__);
     nm_nfree(session,"iiab/cascade.c",121,__PRETTY_FUNCTION__);
}

user_defined_types: enum cascade_fn { CASCADE_AVG=0, CASCADE_MIN=1, CASCADE_MAX=2, CASCADE_SUM=3, CASCADE_LAST=4, CASCADE_FIRST=5, CASCADE_DIFF=6, CASCADE_RATE=7 }


decompiled_code:
__int64 __fastcall cascade_aggregate(int a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r13
__int64 v4; // rax
__int64 v5; // r14
__int64 v6; // rbx
__int64 v7; // r15
__int64 v8; // r12
_QWORD *v9; // rdx
_QWORD *v10; // rax
__int64 v11; // rax
__int64 v12; // rbp
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // r13
const char *v16; // rbx
const char *v17; // rax
__int64 v18; // rbx
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rax
const char *v22; // rbp
__int64 v23; // rbx
const char *v24; // rsi
bool v25; // al
bool v26; // cf
bool v27; // zf
__int64 v28; // rcx
const char *v29; // rsi
const char *v30; // rdi
__int64 v31; // rax
_QWORD *v32; // rdx
_QWORD *v33; // rax
const char *v34; // rax
__int64 v35; // rax
float v36; // xmm0_4
__int64 v37; // rax
_QWORD *v38; // rdx
_QWORD *v39; // rax
__int64 v40; // rax
_QWORD *v41; // rdx
_QWORD *v42; // rax
__int64 v43; // rax
_QWORD *v44; // rdx
_QWORD *v45; // rax
__int64 v46; // rax
const char *v47; // rax
const char *v48; // rax
__int64 v49; // rax
__int64 *v50; // rdx
__int64 v51; // r14
__int64 v52; // r12
_QWORD *v53; // rdx
_QWORD *v54; // rax
time_t v55; // rax
__int64 v56; // rax
int v57; // ebx
const char *v58; // rax
__int64 v59; // rbp
const char *v60; // rax
__int64 **v61; // rax
__int64 v62; // rax
__int64 v63; // rax
__int64 v64; // rax
double v66; // [rsp+0h] [rbp-58h]
double v67; // [rsp+0h] [rbp-58h]
double v68; // [rsp+0h] [rbp-58h]
double v69; // [rsp+0h] [rbp-58h]
__int64 v71; // [rsp+10h] [rbp-48h]
int v73; // [rsp+1Ch] [rbp-3Ch]

if ( !a2 )
{
elog_fprintf(2LL, "iiab/cascade.c", 217LL, "cascade_aggregate", "no dataset given to aggregate");
return 0LL;
}
if ( !(unsigned int)table_nrows(a2) )
elog_fprintf(2LL, "iiab/cascade.c", 221LL, "cascade_aggregate", "no rows to aggregate in dataset");
if ( !(unsigned int)table_hascol(a2, "_time") )
{
v16 = (const char *)table_outheader(a2);
elog_fprintf(
5LL,
"iiab/cascade.c",
225LL,
"cascade_aggregate",
"attempting to aggregate a table without _time column (columns: %s)",
v16);
nm_nfree(v16, "iiab/cascade.c", 227LL, "cascade_aggregate");
return 0LL;
}
v2 = table_getinforow(a2, "key");
v3 = v2;
if ( v2 )
{
v4 = tree_search(v2, "1", 2LL);
v5 = v4;
if ( v4 )
{
v6 = table_uniqcolvals(a2, v4, 0LL);
if ( v6 )
{
v7 = tree_really_create("iiab/cascade.c", 241LL, "cascade_aggregate");
v8 = tableset_create(a2);
v9 = *(_QWORD **)v6;
v10 = **(_QWORD ***)v6;
*(_QWORD *)(v6 + 8) = v10;
if ( v9 != v10 )
{
do
{
tableset_reset(v8);
v11 = tree_getkey(v6);
tableset_where(v8, v5, 0LL, v11);
v12 = tableset_into(v8);
v13 = tree_getkey(v6);
tree_add(v7, v13, v12);
v14 = **(_QWORD **)(v6 + 8);
*(_QWORD *)(v6 + 8) = v14;
}
while ( v14 != *(_QWORD *)v6 );
}
tableset_destroy(v8);
tree_really_destroy(v6, "iiab/cascade.c", 253LL, "cascade_aggregate");
tree_really_destroy(v3, "iiab/cascade.c", 255LL, "cascade_aggregate");
v73 = 1;
goto LABEL_65;
}
tree_really_destroy(0LL, "iiab/cascade.c", 253LL, "cascade_aggregate");
tree_really_destroy(v3, "iiab/cascade.c", 255LL, "cascade_aggregate");
}
else
{
tree_really_destroy(v3, "iiab/cascade.c", 255LL, "cascade_aggregate");
}
}
v7 = tree_really_create("iiab/cascade.c", 260LL, "cascade_aggregate");
tree_add(v7, "nokey", a2);
v73 = 0;
LABEL_65:
table_first(a2);
v57 = table_hascol(a2, "_dur");
if ( v57 )
{
v17 = (const char *)table_getcurrentcell(a2, "_dur");
v57 = strtol(v17, 0LL, 10);
}
v58 = (const char *)table_getcurrentcell(a2, "_time");
v59 = strtol(v58, 0LL, 10);
table_last(a2);
v60 = (const char *)table_getcurrentcell(a2, "_time");
v71 = v57 + strtol(v60, 0LL, 10) - v59;
v15 = table_create_fromdonor(a2);
table_addcol(v15, "_seq", 0LL);
table_addcol(v15, "_time", 0LL);
table_addcol(v15, "_dur", 0LL);
v61 = *(__int64 ***)v7;
v50 = **(__int64 ***)v7;
*(_QWORD *)(v7 + 8) = v50;
if ( v61 != (__int64 **)v50 )
{
do
{
table_addemptyrow(v15);
v51 = tree_get(v7);
v52 = table_getheader(v51);
v53 = *(_QWORD **)v52;
v54 = **(_QWORD ***)v52;
*(_QWORD *)(v52 + 8) = v54;
if ( v53 != v54 )
{
do
{
v22 = (const char *)tree_getkey(v52);
if ( !(unsigned int)table_hascol(v15, v22) )
{
v18 = nm_xnstrdup(v22, "iiab/cascade.c", 288LL, "cascade_aggregate");
table_addcol(v15, v18, 0LL);
table_freeondestroy(v15, v18);
}
v23 = table_getcol(v51, v22);
v24 = (const char *)table_getinfocell(v51, "type", v22);
if ( v24 && !strcmp(v24, "str") )
{
itree_last(v23);
v19 = itree_get(v23);
table_replacecurrentcell(v15, v22, v19);
}
else if ( !strcmp(v22, "_dur") )
{
itree_last(v23);
v20 = itree_get(v23);
table_replacecurrentcell(v15, "_dur", v20);
}
else
{
v25 = strcmp(v22, "_seq") != 0;
v26 = 0;
v27 = !v25;
if ( v25 )
{
v28 = 6LL;
v29 = v22;
v30 = "_time";
do
{
if ( !v28 )
break;
v26 = *v29 < (unsigned int)*v30;
v27 = *v29++ == *v30++;
--v28;
}
while ( v27 );
if ( (!v26 && !v27) == v26 )
{
itree_last(v23);
v31 = itree_get(v23);
table_replacecurrentcell(v15, "_time", v31);
}
else
{
switch ( a1 )
{
case 0:
v32 = *(_QWORD **)v23;
v33 = **(_QWORD ***)v23;
*(_QWORD *)(v23 + 8) = v33;
if ( v32 == v33 )
{
v67 = 0.0;
}
else
{
v67 = 0.0;
do
{
v34 = (const char *)itree_get(v23);
v67 = atof(v34) + v67;
v35 = **(_QWORD **)(v23 + 8);
*(_QWORD *)(v23 + 8) = v35;
}
while ( v35 != *(_QWORD *)v23 );
}
v30 = (const char *)v23;
v66 = v67 / (double)(int)itree_n(v23, v29);
break;
case 1:
v38 = *(_QWORD **)v23;
v39 = **(_QWORD ***)v23;
*(_QWORD *)(v23 + 8) = v39;
if ( v38 == v39 )
{
v66 = *(double *)&LC3;
}
else
{
v66 = *(double *)&LC3;
do
{
v30 = (const char *)itree_get(v23);
v66 = fmin(atof(v30), v66);
v40 = **(_QWORD **)(v23 + 8);
*(_QWORD *)(v23 + 8) = v40;
}
while ( v40 != *(_QWORD *)v23 );
}
break;
case 2:
v41 = *(_QWORD **)v23;
v42 = **(_QWORD ***)v23;
*(_QWORD *)(v23 + 8) = v42;
if ( v41 == v42 )
{
v66 = *(double *)&LC4;
}
else
{
v66 = *(double *)&LC4;
do
{
v30 = (const char *)itree_get(v23);
v66 = fmax(atof(v30), v66);
v43 = **(_QWORD **)(v23 + 8);
*(_QWORD *)(v23 + 8) = v43;
}
while ( v43 != *(_QWORD *)v23 );
}
break;
case 3:
v44 = *(_QWORD **)v23;
v45 = **(_QWORD ***)v23;
*(_QWORD *)(v23 + 8) = v45;
if ( v44 == v45 )
{
v66 = 0.0;
}
else
{
v66 = 0.0;
do
{
v30 = (const char *)itree_get(v23);
v66 = atof(v30) + v66;
v46 = **(_QWORD **)(v23 + 8);
*(_QWORD *)(v23 + 8) = v46;
}
while ( v46 != *(_QWORD *)v23 );
}
break;
case 4:
itree_last(v23);
v30 = (const char *)itree_get(v23);
v66 = atof(v30);
break;
case 5:
itree_first(v23, v29);
v30 = (const char *)itree_get(v23);
v66 = atof(v30);
break;
case 6:
itree_first(v23, v29);
v47 = (const char *)itree_get(v23);
v68 = atof(v47);
itree_last(v23);
v30 = (const char *)itree_get(v23);
v66 = atof(v30) - v68;
break;
case 7:
itree_first(v23, v29);
v48 = (const char *)itree_get(v23);
v69 = atof(v48);
itree_last(v23);
v30 = (const char *)itree_get(v23);
v66 = (atof(v30) - v69) / (double)(int)v71;
break;
default:
break;
}
v36 = v66;
v37 = util_ftoa(v30, v29, v36);
table_replacecurrentcell_alloc(v15, v22, v37);
}
}
else
{
table_replacecurrentcell(v15, "_seq", "0");
}
}
itree_really_destroy(v23, "iiab/cascade.c", 376LL, "cascade_aggregate");
v21 = **(_QWORD **)(v52 + 8);
*(_QWORD *)(v52 + 8) = v21;
}
while ( v21 != *(_QWORD *)v52 );
}
if ( !(unsigned int)table_hascol(a2, "_time") )
{
v55 = time(0LL);
v56 = util_decdatetime(v55);
table_replacecurrentcell(v15, "_time", v56);
}
if ( !(unsigned int)table_hascol(a2, "_seq") )
table_replacecurrentcell(v15, "_seq", "0");
if ( !(unsigned int)table_hascol(a2, "_dur") )
table_replacecurrentcell(v15, "_dur", "0");
v49 = **(_QWORD **)(v7 + 8);
*(_QWORD *)(v7 + 8) = v49;
v50 = *(__int64 **)v7;
}
while ( v49 != *(_QWORD *)v7 );
}
if ( v73 )
{
v62 = *v50;
*(_QWORD *)(v7 + 8) = *v50;
if ( v62 != *(_QWORD *)v7 )
{
do
{
v63 = tree_get(v7);
table_destroy(v63);
v64 = **(_QWORD **)(v7 + 8);
*(_QWORD *)(v7 + 8) = v64;
}
while ( v64 != *(_QWORD *)v7 );
}
}
tree_really_destroy(v7, "iiab/cascade.c", 395LL, "cascade_aggregate");
return v15;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r13
__int64 v4; // rax
__int64 v5; // r14
__int64 v6; // rbx
__int64 v7; // r15
__int64 v8; // r12
_QWORD *v9; // rdx
_QWORD *v10; // rax
__int64 v11; // rax
__int64 v12; // rbp
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // r13
const char *v16; // rbx
const char *v17; // rax
__int64 v18; // rbx
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rax
const char *v22; // rbp
__int64 v23; // rbx
const char *v24; // rsi
bool v25; // al
bool v26; // cf
bool v27; // zf
__int64 v28; // rcx
const char *v29; // rsi
const char *v30; // rdi
__int64 v31; // rax
_QWORD *v32; // rdx
_QWORD *v33; // rax
const char *v34; // rax
__int64 v35; // rax
float v36; // xmm0_4
__int64 v37; // rax
_QWORD *v38; // rdx
_QWORD *v39; // rax
__int64 v40; // rax
_QWORD *v41; // rdx
_QWORD *v42; // rax
__int64 v43; // rax
_QWORD *v44; // rdx
_QWORD *v45; // rax
__int64 v46; // rax
const char *v47; // rax
const char *v48; // rax
__int64 v49; // rax
__int64 *v50; // rdx
__int64 v51; // r14
__int64 v52; // r12
_QWORD *v53; // rdx
_QWORD *v54; // rax
time_t v55; // rax
__int64 v56; // rax
int v57; // ebx
const char *v58; // rax
__int64 v59; // rbp
const char *v60; // rax
__int64 **v61; // rax
__int64 v62; // rax
__int64 v63; // rax
__int64 v64; // rax
double v66; // [rsp+0h] [rbp-58h]
double v67; // [rsp+0h] [rbp-58h]
double v68; // [rsp+0h] [rbp-58h]
double v69; // [rsp+0h] [rbp-58h]
__int64 v71; // [rsp+10h] [rbp-48h]
int v73; // [rsp+1Ch] [rbp-3Ch]

if ( !a2 )
{
elog_fprintf(2LL, "iiab/cascade.c", 217LL, "cascade_aggregate", "no dataset given to aggregate");
return 0LL;
}
if ( !(unsigned int)table_nrows(a2) )
elog_fprintf(2LL, "iiab/cascade.c", 221LL, "cascade_aggregate", "no rows to aggregate in dataset");
if ( !(unsigned int)table_hascol(a2, "_time") )
{
v16 = (const char *)table_outheader(a2);
elog_fprintf(
5LL,
"iiab/cascade.c",
225LL,
"cascade_aggregate",
"attempting to aggregate a table without _time column (columns: %s)",
v16);
nm_nfree(v16, "iiab/cascade.c", 227LL, "cascade_aggregate");
return 0LL;
}
v2 = table_getinforow(a2, "key");
v3 = v2;
if ( v2 )
{
v4 = tree_search(v2, "1", 2LL);
v5 = v4;
if ( v4 )
{
v6 = table_uniqcolvals(a2, v4, 0LL);
if ( v6 )
{
v7 = tree_really_create("iiab/cascade.c", 241LL, "cascade_aggregate");
v8 = tableset_create(a2);
v9 = *(_QWORD **)v6;
v10 = **(_QWORD ***)v6;
*(_QWORD *)(v6 + 8) = v10;
if ( v9 != v10 )
{
do
{
tableset_reset(v8);
v11 = tree_getkey(v6);
tableset_where(v8, v5, 0LL, v11);
v12 = tableset_into(v8);
v13 = tree_getkey(v6);
tree_add(v7, v13, v12);
v14 = **(_QWORD **)(v6 + 8);
*(_QWORD *)(v6 + 8) = v14;
}
while ( v14 != *(_QWORD *)v6 );
}
tableset_destroy(v8);
tree_really_destroy(v6, "iiab/cascade.c", 253LL, "cascade_aggregate");
tree_really_destroy(v3, "iiab/cascade.c", 255LL, "cascade_aggregate");
v73 = 1;
goto LABEL_65;
}
tree_really_destroy(0LL, "iiab/cascade.c", 253LL, "cascade_aggregate");
tree_really_destroy(v3, "iiab/cascade.c", 255LL, "cascade_aggregate");
}
else
{
tree_really_destroy(v3, "iiab/cascade.c", 255LL, "cascade_aggregate");
}
}
v7 = tree_really_create("iiab/cascade.c", 260LL, "cascade_aggregate");
tree_add(v7, "nokey", a2);
v73 = 0;
LABEL_65:
table_first(a2);
v57 = table_hascol(a2, "_dur");
if ( v57 )
{
v17 = (const char *)table_getcurrentcell(a2, "_dur");
v57 = strtol(v17, 0LL, 10);
}
v58 = (const char *)table_getcurrentcell(a2, "_time");
v59 = strtol(v58, 0LL, 10);
table_last(a2);
v60 = (const char *)table_getcurrentcell(a2, "_time");
v71 = v57 + strtol(v60, 0LL, 10) - v59;
v15 = table_create_fromdonor(a2);
table_addcol(v15, "_seq", 0LL);
table_addcol(v15, "_time", 0LL);
table_addcol(v15, "_dur", 0LL);
v61 = *(__int64 ***)v7;
v50 = **(__int64 ***)v7;
*(_QWORD *)(v7 + 8) = v50;
if ( v61 != (__int64 **)v50 )
{
do
{
table_addemptyrow(v15);
v51 = tree_get(v7);
v52 = table_getheader(v51);
v53 = *(_QWORD **)v52;
v54 = **(_QWORD ***)v52;
*(_QWORD *)(v52 + 8) = v54;
if ( v53 != v54 )
{
do
{
v22 = (const char *)tree_getkey(v52);
if ( !(unsigned int)table_hascol(v15, v22) )
{
v18 = nm_xnstrdup(v22, "iiab/cascade.c", 288LL, "cascade_aggregate");
table_addcol(v15, v18, 0LL);
table_freeondestroy(v15, v18);
}
v23 = table_getcol(v51, v22);
v24 = (const char *)table_getinfocell(v51, "type", v22);
if ( v24 && !strcmp(v24, "str") )
{
itree_last(v23);
v19 = itree_get(v23);
table_replacecurrentcell(v15, v22, v19);
}
else if ( !strcmp(v22, "_dur") )
{
itree_last(v23);
v20 = itree_get(v23);
table_replacecurrentcell(v15, "_dur", v20);
}
else
{
v25 = strcmp(v22, "_seq") != 0;
v26 = 0;
v27 = !v25;
if ( v25 )
{
v28 = 6LL;
v29 = v22;
v30 = "_time";
do
{
if ( !v28 )
break;
v26 = *v29 < (unsigned int)*v30;
v27 = *v29++ == *v30++;
--v28;
}
while ( v27 );
if ( (!v26 && !v27) == v26 )
{
itree_last(v23);
v31 = itree_get(v23);
table_replacecurrentcell(v15, "_time", v31);
}
else
{
switch ( a1 )
{
case 0:
v32 = *(_QWORD **)v23;
v33 = **(_QWORD ***)v23;
*(_QWORD *)(v23 + 8) = v33;
if ( v32 == v33 )
{
v67 = 0.0;
}
else
{
v67 = 0.0;
do
{
v34 = (const char *)itree_get(v23);
v67 = atof(v34) + v67;
v35 = **(_QWORD **)(v23 + 8);
*(_QWORD *)(v23 + 8) = v35;
}
while ( v35 != *(_QWORD *)v23 );
}
v30 = (const char *)v23;
v66 = v67 / (double)(int)itree_n(v23, v29);
break;
case 1:
v38 = *(_QWORD **)v23;
v39 = **(_QWORD ***)v23;
*(_QWORD *)(v23 + 8) = v39;
if ( v38 == v39 )
{
v66 = *(double *)&LC3;
}
else
{
v66 = *(double *)&LC3;
do
{
v30 = (const char *)itree_get(v23);
v66 = fmin(atof(v30), v66);
v40 = **(_QWORD **)(v23 + 8);
*(_QWORD *)(v23 + 8) = v40;
}
while ( v40 != *(_QWORD *)v23 );
}
break;
case 2:
v41 = *(_QWORD **)v23;
v42 = **(_QWORD ***)v23;
*(_QWORD *)(v23 + 8) = v42;
if ( v41 == v42 )
{
v66 = *(double *)&LC4;
}
else
{
v66 = *(double *)&LC4;
do
{
v30 = (const char *)itree_get(v23);
v66 = fmax(atof(v30), v66);
v43 = **(_QWORD **)(v23 + 8);
*(_QWORD *)(v23 + 8) = v43;
}
while ( v43 != *(_QWORD *)v23 );
}
break;
case 3:
v44 = *(_QWORD **)v23;
v45 = **(_QWORD ***)v23;
*(_QWORD *)(v23 + 8) = v45;
if ( v44 == v45 )
{
v66 = 0.0;
}
else
{
v66 = 0.0;
do
{
v30 = (const char *)itree_get(v23);
v66 = atof(v30) + v66;
v46 = **(_QWORD **)(v23 + 8);
*(_QWORD *)(v23 + 8) = v46;
}
while ( v46 != *(_QWORD *)v23 );
}
break;
case 4:
itree_last(v23);
v30 = (const char *)itree_get(v23);
v66 = atof(v30);
break;
case 5:
itree_first(v23, v29);
v30 = (const char *)itree_get(v23);
v66 = atof(v30);
break;
case 6:
itree_first(v23, v29);
v47 = (const char *)itree_get(v23);
v68 = atof(v47);
itree_last(v23);
v30 = (const char *)itree_get(v23);
v66 = atof(v30) - v68;
break;
case 7:
itree_first(v23, v29);
v48 = (const char *)itree_get(v23);
v69 = atof(v48);
itree_last(v23);
v30 = (const char *)itree_get(v23);
v66 = (atof(v30) - v69) / (double)(int)v71;
break;
default:
break;
}
v36 = v66;
v37 = util_ftoa(v30, v29, v36);
table_replacecurrentcell_alloc(v15, v22, v37);
}
}
else
{
table_replacecurrentcell(v15, "_seq", "0");
}
}
itree_really_destroy(v23, "iiab/cascade.c", 376LL, "cascade_aggregate");
v21 = **(_QWORD **)(v52 + 8);
*(_QWORD *)(v52 + 8) = v21;
}
while ( v21 != *(_QWORD *)v52 );
}
if ( !(unsigned int)table_hascol(a2, "_time") )
{
v55 = time(0LL);
v56 = util_decdatetime(v55);
table_replacecurrentcell(v15, "_time", v56);
}
if ( !(unsigned int)table_hascol(a2, "_seq") )
table_replacecurrentcell(v15, "_seq", "0");
if ( !(unsigned int)table_hascol(a2, "_dur") )
table_replacecurrentcell(v15, "_dur", "0");
v49 = **(_QWORD **)(v7 + 8);
*(_QWORD *)(v7 + 8) = v49;
v50 = *(__int64 **)v7;
}
while ( v49 != *(_QWORD *)v7 );
}
if ( v73 )
{
v62 = *v50;
*(_QWORD *)(v7 + 8) = *v50;
if ( v62 != *(_QWORD *)v7 )
{
do
{
v63 = tree_get(v7);
table_destroy(v63);
v64 = **(_QWORD **)(v7 + 8);
*(_QWORD *)(v7 + 8) = v64;
}
while ( v64 != *(_QWORD *)v7 );
}
}
tree_really_destroy(v7, "iiab/cascade.c", 395LL, "cascade_aggregate");
return v15;
}

original_code:
TABLE cascade_aggregate(enum cascade_fn func,
   TABLE dataset )
{
     TREE *inforow, *keyvals, *databykey, *colnames;
     char *keycol, *colname, *tmpstr, *type;
     int duration, haskey=0;
     TABLE itab, result;
     TABSET tset;
     ITREE *col;
     double val, tmpval1, tmpval2;
     time_t t1, t2, tdiff;
     if ( ! dataset ) {
          elog_fprintf(DIAG,"iiab/cascade.c",217,__PRETTY_FUNCTION__,"no dataset given to aggregate");
          return ((void *)0);
     }
     if (table_nrows(dataset) == 0) {
          elog_fprintf(DIAG,"iiab/cascade.c",221,__PRETTY_FUNCTION__,"no rows to aggregate in dataset");
     }
     if ( ! table_hascol(dataset, "_time")) {
          tmpstr = table_outheader(dataset);
          elog_fprintf(ERROR,"iiab/cascade.c",225,__PRETTY_FUNCTION__,"attempting to aggregate a table without _time " "column (columns: %s)", tmpstr);
   nm_nfree(tmpstr,"iiab/cascade.c",227,__PRETTY_FUNCTION__);
          return ((void *)0);
     }
     inforow = table_getinforow(dataset, "key");
     if (inforow) {
          keycol = tree_search(inforow, "1", 2);
   if (keycol) {
        keyvals = table_uniqcolvals(dataset, keycol, ((void *)0));
        if (keyvals) {
      haskey++;
      databykey = tree_really_create("iiab/cascade.c",241,__PRETTY_FUNCTION__);
      tset = tableset_create(dataset);
      for((keyvals)->node = ((keyvals)->root->c.list.flink); (keyvals)->node != ((keyvals)->root); (keyvals)->node = ((keyvals)->node->c.list.flink)) {
           tableset_reset(tset);
    tableset_where(tset, keycol, eq,
     tree_getkey(keyvals));
    itab = tableset_into(tset);
           tree_add(databykey, tree_getkey(keyvals), itab);
      }
      tableset_destroy(tset);
        }
        tree_really_destroy(keyvals,"iiab/cascade.c",253,__PRETTY_FUNCTION__);
   }
   tree_really_destroy(inforow,"iiab/cascade.c",255,__PRETTY_FUNCTION__);
     }
     if ( ! haskey ) {
          databykey = tree_really_create("iiab/cascade.c",260,__PRETTY_FUNCTION__);
   tree_add(databykey, "nokey", dataset);
     }
     table_first(dataset);
     if (table_hascol(dataset, "_dur"))
          duration = strtol(table_getcurrentcell(dataset, "_dur"), ((void *)0), 10);
     else
          duration = 0;
     t1 = strtol(table_getcurrentcell(dataset, "_time"), ((void *)0), 10);
     table_last(dataset);
     t2 = strtol(table_getcurrentcell(dataset, "_time"), ((void *)0), 10);
     tdiff = t2-t1+duration;
     result = table_create_fromdonor(dataset);
     table_addcol(result, "_seq", ((void *)0));
     table_addcol(result, "_time", ((void *)0));
     table_addcol(result, "_dur", ((void *)0));
     for((databykey)->node = ((databykey)->root->c.list.flink); (databykey)->node != ((databykey)->root); (databykey)->node = ((databykey)->node->c.list.flink)) {
          table_addemptyrow(result);
          itab = tree_get(databykey);
   colnames = table_getheader(itab);
   for((colnames)->node = ((colnames)->root->c.list.flink); (colnames)->node != ((colnames)->root); (colnames)->node = ((colnames)->node->c.list.flink)) {
        colname = tree_getkey(colnames);
        if ( ! table_hascol(result, colname)) {
       tmpstr = nm_xnstrdup(colname,"iiab/cascade.c",288,__PRETTY_FUNCTION__);
       table_addcol(result, tmpstr, ((void *)0));
       table_freeondestroy(result, tmpstr);
        }
        col = table_getcol(itab, colname);
        type = table_getinfocell(itab, "type", colname);
        if (type && strcmp(type, "str") == 0) {
      itree_last(col);
      table_replacecurrentcell(result, colname, itree_get(col));
        } else if (strcmp(colname, "_dur") == 0) {
      itree_last(col);
      table_replacecurrentcell(result, "_dur", itree_get(col));
        } else if (strcmp(colname, "_seq") == 0) {
      table_replacecurrentcell(result, "_seq", "0");
        } else if (strcmp(colname, "_time") == 0) {
      itree_last(col);
      table_replacecurrentcell(result, "_time", itree_get(col));
        } else {
      switch (func) {
      case CASCADE_AVG:
           val = 0.0;
    for((col)->node = ((col)->root->c.list.flink); (col)->node != ((col)->root); (col)->node = ((col)->node->c.list.flink))
         val += atof( itree_get(col) );
    val = val / itree_n(col);
    break;
      case CASCADE_MIN:
           val = ((double)1.79769313486231570814527423731704357e+308L);
    for((col)->node = ((col)->root->c.list.flink); (col)->node != ((col)->root); (col)->node = ((col)->node->c.list.flink)) {
         tmpval1 = atof( itree_get(col) );
         if (tmpval1 < val)
       val = tmpval1;
    }
    break;
      case CASCADE_MAX:
           val = ((double)2.22507385850720138309023271733240406e-308L);
    for((col)->node = ((col)->root->c.list.flink); (col)->node != ((col)->root); (col)->node = ((col)->node->c.list.flink)) {
         tmpval1 = atof( itree_get(col) );
         if (tmpval1 > val)
       val = tmpval1;
    }
    break;
      case CASCADE_SUM:
           val = 0.0;
    for((col)->node = ((col)->root->c.list.flink); (col)->node != ((col)->root); (col)->node = ((col)->node->c.list.flink))
         val += atof( itree_get(col) );
    break;
      case CASCADE_LAST:
           itree_last(col);
    val = atof( itree_get(col) );
    break;
      case CASCADE_FIRST:
           itree_first(col);
    val = atof( itree_get(col) );
    break;
      case CASCADE_DIFF:
           itree_first(col);
    tmpval1 = atof( itree_get(col) );
    itree_last(col);
    tmpval2 = atof( itree_get(col) );
    val = tmpval2 - tmpval1;
    break;
      case CASCADE_RATE:
           itree_first(col);
    tmpval1 = atof( itree_get(col) );
    itree_last(col);
    tmpval2 = atof( itree_get(col) );
    val = tmpval2 - tmpval1;
    val = val / tdiff;
    break;
      }
      table_replacecurrentcell_alloc(result, colname,
         util_ftoa(val));
        }
        itree_really_destroy(col,"iiab/cascade.c",376,__PRETTY_FUNCTION__);
   }
   if ( ! table_hascol(dataset, "_time"))
        table_replacecurrentcell(result, "_time",
     util_decdatetime(time(((void *)0))));
   if ( ! table_hascol(dataset, "_seq"))
        table_replacecurrentcell(result, "_seq", "0");
   if ( ! table_hascol(dataset, "_dur"))
        table_replacecurrentcell(result, "_dur", "0");
     }
     if (haskey) {
          for((databykey)->node = ((databykey)->root->c.list.flink); (databykey)->node != ((databykey)->root); (databykey)->node = ((databykey)->node->c.list.flink)) {
        itab = tree_get(databykey);
        table_destroy(itab);
   }
     }
     tree_really_destroy(databykey,"iiab/cascade.c",395,__PRETTY_FUNCTION__);
     return result;
}

canonical_original_code:
struct table_info *cascade_aggregate(enum cascade_fn func, struct table_info *dataset)
{
     struct tree_head *inforow; struct tree_head *keyvals; struct tree_head *databykey; struct tree_head *colnames;
     char *keycol; char *colname; char *tmpstr; char *type;
     int duration; int haskey = 0;
     struct table_info *itab; struct table_info *result;
     struct tableset *tset;
     struct itree_head *col;
     double val; double tmpval1; double tmpval2;
     long t1; long t2; long tdiff;
     if ( ! dataset ) {
          elog_fprintf(DIAG,"iiab/cascade.c",217,__PRETTY_FUNCTION__,"no dataset given to aggregate");
          return ((void *)0);
     }
     if (table_nrows(dataset) == 0) {
          elog_fprintf(DIAG,"iiab/cascade.c",221,__PRETTY_FUNCTION__,"no rows to aggregate in dataset");
     }
     if ( ! table_hascol(dataset, "_time")) {
          tmpstr = table_outheader(dataset);
          elog_fprintf(ERROR,"iiab/cascade.c",225,__PRETTY_FUNCTION__,"attempting to aggregate a table without _time " "column (columns: %s)", tmpstr);
   nm_nfree(tmpstr,"iiab/cascade.c",227,__PRETTY_FUNCTION__);
          return ((void *)0);
     }
     inforow = table_getinforow(dataset, "key");
     if (inforow) {
          keycol = tree_search(inforow, "1", 2);
   if (keycol) {
        keyvals = table_uniqcolvals(dataset, keycol, ((void *)0));
        if (keyvals) {
      haskey++;
      databykey = tree_really_create("iiab/cascade.c",241,__PRETTY_FUNCTION__);
      tset = tableset_create(dataset);
      for((keyvals)->node = ((keyvals)->root->c.list.flink); (keyvals)->node != ((keyvals)->root); (keyvals)->node = ((keyvals)->node->c.list.flink)) {
           tableset_reset(tset);
    tableset_where(tset, keycol, eq,
     tree_getkey(keyvals));
    itab = tableset_into(tset);
           tree_add(databykey, tree_getkey(keyvals), itab);
      }
      tableset_destroy(tset);
        }
        tree_really_destroy(keyvals,"iiab/cascade.c",253,__PRETTY_FUNCTION__);
   }
   tree_really_destroy(inforow,"iiab/cascade.c",255,__PRETTY_FUNCTION__);
     }
     if ( ! haskey ) {
          databykey = tree_really_create("iiab/cascade.c",260,__PRETTY_FUNCTION__);
   tree_add(databykey, "nokey", dataset);
     }
     table_first(dataset);
     if (table_hascol(dataset, "_dur"))
          duration = strtol(table_getcurrentcell(dataset, "_dur"), ((void *)0), 10);
     else
          duration = 0;
     t1 = strtol(table_getcurrentcell(dataset, "_time"), ((void *)0), 10);
     table_last(dataset);
     t2 = strtol(table_getcurrentcell(dataset, "_time"), ((void *)0), 10);
     tdiff = t2-t1+duration;
     result = table_create_fromdonor(dataset);
     table_addcol(result, "_seq", ((void *)0));
     table_addcol(result, "_time", ((void *)0));
     table_addcol(result, "_dur", ((void *)0));
     for((databykey)->node = ((databykey)->root->c.list.flink); (databykey)->node != ((databykey)->root); (databykey)->node = ((databykey)->node->c.list.flink)) {
          table_addemptyrow(result);
          itab = tree_get(databykey);
   colnames = table_getheader(itab);
   for((colnames)->node = ((colnames)->root->c.list.flink); (colnames)->node != ((colnames)->root); (colnames)->node = ((colnames)->node->c.list.flink)) {
        colname = tree_getkey(colnames);
        if ( ! table_hascol(result, colname)) {
       tmpstr = nm_xnstrdup(colname,"iiab/cascade.c",288,__PRETTY_FUNCTION__);
       table_addcol(result, tmpstr, ((void *)0));
       table_freeondestroy(result, tmpstr);
        }
        col = table_getcol(itab, colname);
        type = table_getinfocell(itab, "type", colname);
        if (type && strcmp(type, "str") == 0) {
      itree_last(col);
      table_replacecurrentcell(result, colname, itree_get(col));
        } else if (strcmp(colname, "_dur") == 0) {
      itree_last(col);
      table_replacecurrentcell(result, "_dur", itree_get(col));
        } else if (strcmp(colname, "_seq") == 0) {
      table_replacecurrentcell(result, "_seq", "0");
        } else if (strcmp(colname, "_time") == 0) {
      itree_last(col);
      table_replacecurrentcell(result, "_time", itree_get(col));
        } else {
      switch (func) {
      case CASCADE_AVG:
           val = 0.0;
    for((col)->node = ((col)->root->c.list.flink); (col)->node != ((col)->root); (col)->node = ((col)->node->c.list.flink))
         val += atof( itree_get(col) );
    val = val / itree_n(col);
    break;
      case CASCADE_MIN:
           val = ((double)1.79769313486231570814527423731704357e+308L);
    for((col)->node = ((col)->root->c.list.flink); (col)->node != ((col)->root); (col)->node = ((col)->node->c.list.flink)) {
         tmpval1 = atof( itree_get(col) );
         if (tmpval1 < val)
       val = tmpval1;
    }
    break;
      case CASCADE_MAX:
           val = ((double)2.22507385850720138309023271733240406e-308L);
    for((col)->node = ((col)->root->c.list.flink); (col)->node != ((col)->root); (col)->node = ((col)->node->c.list.flink)) {
         tmpval1 = atof( itree_get(col) );
         if (tmpval1 > val)
       val = tmpval1;
    }
    break;
      case CASCADE_SUM:
           val = 0.0;
    for((col)->node = ((col)->root->c.list.flink); (col)->node != ((col)->root); (col)->node = ((col)->node->c.list.flink))
         val += atof( itree_get(col) );
    break;
      case CASCADE_LAST:
           itree_last(col);
    val = atof( itree_get(col) );
    break;
      case CASCADE_FIRST:
           itree_first(col);
    val = atof( itree_get(col) );
    break;
      case CASCADE_DIFF:
           itree_first(col);
    tmpval1 = atof( itree_get(col) );
    itree_last(col);
    tmpval2 = atof( itree_get(col) );
    val = tmpval2 - tmpval1;
    break;
      case CASCADE_RATE:
           itree_first(col);
    tmpval1 = atof( itree_get(col) );
    itree_last(col);
    tmpval2 = atof( itree_get(col) );
    val = tmpval2 - tmpval1;
    val = val / tdiff;
    break;
      }
      table_replacecurrentcell_alloc(result, colname,
         util_ftoa(val));
        }
        itree_really_destroy(col,"iiab/cascade.c",376,__PRETTY_FUNCTION__);
   }
   if ( ! table_hascol(dataset, "_time"))
        table_replacecurrentcell(result, "_time",
     util_decdatetime(time(((void *)0))));
   if ( ! table_hascol(dataset, "_seq"))
        table_replacecurrentcell(result, "_seq", "0");
   if ( ! table_hascol(dataset, "_dur"))
        table_replacecurrentcell(result, "_dur", "0");
     }
     if (haskey) {
          for((databykey)->node = ((databykey)->root->c.list.flink); (databykey)->node != ((databykey)->root); (databykey)->node = ((databykey)->node->c.list.flink)) {
        itab = tree_get(databykey);
        table_destroy(itab);
   }
     }
     tree_really_destroy(databykey,"iiab/cascade.c",395,__PRETTY_FUNCTION__);
     return result;
}

variable_types: enum cascade_fn { CASCADE_AVG=0, CASCADE_MIN=1, CASCADE_MAX=2, CASCADE_SUM=3, CASCADE_LAST=4, CASCADE_FIRST=5, CASCADE_DIFF=6, CASCADE_RATE=7 }

variable_types:
dataset
struct table_info *

variable_types:
keycol
char *

variable_types:
colname
char *

variable_types:
tmpstr
char *

variable_types:
type
char *

variable_types: duration int

variable_types: haskey int

variable_types: struct tableset { struct table_info { int ncols; int nrows; int minrowkey; int maxrowkey; struct tree_head { struct rb_node { union { struct { struct rb_node *flink; struct rb_node *blink; } list; struct { struct rb_node *left; struct rb_node *right; } child; } c; union { struct rb_node *parent; struct rb_node *root; } p; struct status { unsigned int red; unsigned int internal; unsigned int left; unsigned int root; unsigned int head; } s; union { unsigned int ikey; char *key; struct rb_node *lext; } k; union { char *val; struct rb_node *rext; } v; } *root; struct rb_node *node; } *data; struct itree_head { struct rb_node *root; struct rb_node *node; } *colorder; struct tree_head *info; struct tree_head *infolookup; struct itree_head *tobegarbage; int refcount; struct itree_head *roworder; char separator; } *tab; struct itree_head *cols; struct itree_head *where; int nwhere; int nunless; char *sortby; int sorthow; struct itree_head *rownums; struct tree_head *groupby; struct itree_head *tobegarbage; } *

variable_types: struct itree_head { struct rb_node { union { struct { struct rb_node *flink; struct rb_node *blink; } list; struct { struct rb_node *left; struct rb_node *right; } child; } c; union { struct rb_node *parent; struct rb_node *root; } p; struct status { unsigned int red; unsigned int internal; unsigned int left; unsigned int root; unsigned int head; } s; union { unsigned int ikey; char *key; struct rb_node *lext; } k; union { char *val; struct rb_node *rext; } v; } *root; struct rb_node *node; } *

variable_types: val double

variable_types: tdiff long

user_defined_types: struct tableset { struct table_info *tab; struct itree_head *cols; struct itree_head *where; int nwhere; int nunless; char *sortby; int sorthow; struct itree_head *rownums; struct tree_head *groupby; struct itree_head *tobegarbage; }


decompiled_code:
__int64 __fastcall cascade_sample(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // r12
unsigned int v5; // ebx
__int64 v6; // rax
__int64 v7; // rbp
__int64 v9; // [rsp+0h] [rbp-38h] BYREF
char v10[4]; // [rsp+8h] [rbp-30h] BYREF
int v11[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = route_open(*(_QWORD *)(a1 + 8), 0LL, 0LL, 0LL);
if ( v2 )
{
v3 = v2;
v4 = route_seektread(v2, *(unsigned int *)(a1 + 16), 0xFFFFFFFFLL);
route_tell(v3, v11, v10, &v9);
route_close(v3);
if ( v4 )
{
v5 = table_nrows(v4);
if ( v5 )
{
*(_DWORD *)(a1 + 16) = v11[0] + 1;
v6 = cascade_aggregate(*(_DWORD *)a1, v4);
v7 = v6;
if ( v6 )
{
v5 = 0;
if ( !(unsigned int)route_twrite(a2, v6) )
{
elog_fprintf(5LL, "iiab/cascade.c", 173LL, "cascade_sample", "unable to write result");
v5 = -1;
}
table_destroy(v7);
}
else
{
elog_fprintf(5LL, "iiab/cascade.c", 178LL, "cascade_sample", "no results produced from cascade");
v5 = -1;
}
table_destroy(v4);
}
else
{
elog_fprintf(
2LL,
"iiab/cascade.c",
159LL,
"cascade_sample",
"no rows to cascade sample in %s",
*(const char **)(a1 + 8));
table_destroy(v4);
}
}
else
{
elog_fprintf(
2LL,
"iiab/cascade.c",
154LL,
"cascade_sample",
"no data to cascade sample in %s",
*(const char **)(a1 + 8));
v5 = 0;
}
}
else
{
elog_fprintf(5LL, "iiab/cascade.c", 143LL, "cascade_sample", "route does not exist %s", *(const char **)(a1 + 8));
v5 = -1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // r12
unsigned int v5; // ebx
__int64 v6; // rax
__int64 v7; // rbp
__int64 v9; // [rsp+0h] [rbp-38h] BYREF
char v10[4]; // [rsp+8h] [rbp-30h] BYREF
int v11[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = route_open(*(_QWORD *)(a1 + 8), 0LL, 0LL, 0LL);
if ( v2 )
{
v3 = v2;
v4 = route_seektread(v2, *(unsigned int *)(a1 + 16), 0xFFFFFFFFLL);
route_tell(v3, v11, v10, &v9);
route_close(v3);
if ( v4 )
{
v5 = table_nrows(v4);
if ( v5 )
{
*(_DWORD *)(a1 + 16) = v11[0] + 1;
v6 = func2(*(_DWORD *)a1, v4);
v7 = v6;
if ( v6 )
{
v5 = 0;
if ( !(unsigned int)route_twrite(a2, v6) )
{
elog_fprintf(5LL, "iiab/cascade.c", 173LL, "cascade_sample", "unable to write result");
v5 = -1;
}
table_destroy(v7);
}
else
{
elog_fprintf(5LL, "iiab/cascade.c", 178LL, "cascade_sample", "no results produced from cascade");
v5 = -1;
}
table_destroy(v4);
}
else
{
elog_fprintf(
2LL,
"iiab/cascade.c",
159LL,
"cascade_sample",
"no rows to cascade sample in %s",
*(const char **)(a1 + 8));
table_destroy(v4);
}
}
else
{
elog_fprintf(
2LL,
"iiab/cascade.c",
154LL,
"cascade_sample",
"no data to cascade sample in %s",
*(const char **)(a1 + 8));
v5 = 0;
}
}
else
{
elog_fprintf(5LL, "iiab/cascade.c", 143LL, "cascade_sample", "route does not exist %s", *(const char **)(a1 + 8));
v5 = -1;
}
return v5;
}

original_code:
int cascade_sample(CASCADE *session,
     ROUTE output,
     ROUTE error )
{
     ROUTE rt;
     int r, seq, size, ret=0;
     time_t modt;
     TABLE dataset, result;
     rt = route_open(session->purl, ((void *)0), ((void *)0), 0);
     if ( ! rt ) {
          elog_fprintf(ERROR,"iiab/cascade.c",143,__PRETTY_FUNCTION__,"route does not exist %s", session->purl);
          return -1;
     }
     dataset = route_seektread(rt, session->seq, -1);
     r = route_tell(rt, &seq, &size, &modt);
     route_close(rt);
     if ( ! dataset ) {
          elog_fprintf(DIAG,"iiab/cascade.c",154,__PRETTY_FUNCTION__,"no data to cascade sample in %s", session->purl);
          return 0;
     }
     if ( table_nrows(dataset) == 0 ) {
          elog_fprintf(DIAG,"iiab/cascade.c",159,__PRETTY_FUNCTION__,"no rows to cascade sample in %s", session->purl);
   table_destroy(dataset);
          return 0;
     }
     session->seq = seq+1;
     result = cascade_aggregate(session->fn, dataset);
     if ( result ) {
          if ( ! route_twrite(output, result) ) {
        elog_fprintf(ERROR,"iiab/cascade.c",173,__PRETTY_FUNCTION__,"unable to write result");
        ret = -1;
   }
   table_destroy(result);
     } else {
   elog_fprintf(ERROR,"iiab/cascade.c",178,__PRETTY_FUNCTION__,"no results produced from cascade");
   ret = -1;
     }
     if (dataset)
          table_destroy(dataset);
     return ret;
}

canonical_original_code:
int cascade_sample(struct cascade_info *session, struct route_handle *output, struct route_handle *error)
{
     struct route_handle *rt;
     int r; int seq; int size; int ret = 0;
     long modt;
     struct table_info *dataset; struct table_info *result;
     rt = route_open(session->purl, ((void *)0), ((void *)0), 0);
     if ( ! rt ) {
          elog_fprintf(ERROR,"iiab/cascade.c",143,__PRETTY_FUNCTION__,"route does not exist %s", session->purl);
          return -1;
     }
     dataset = route_seektread(rt, session->seq, -1);
     r = route_tell(rt, &seq, &size, &modt);
     route_close(rt);
     if ( ! dataset ) {
          elog_fprintf(DIAG,"iiab/cascade.c",154,__PRETTY_FUNCTION__,"no data to cascade sample in %s", session->purl);
          return 0;
     }
     if ( table_nrows(dataset) == 0 ) {
          elog_fprintf(DIAG,"iiab/cascade.c",159,__PRETTY_FUNCTION__,"no rows to cascade sample in %s", session->purl);
   table_destroy(dataset);
          return 0;
     }
     session->seq = seq+1;
     result = cascade_aggregate(session->fn, dataset);
     if ( result ) {
          if ( ! route_twrite(output, result) ) {
        elog_fprintf(ERROR,"iiab/cascade.c",173,__PRETTY_FUNCTION__,"unable to write result");
        ret = -1;
   }
   table_destroy(result);
     } else {
   elog_fprintf(ERROR,"iiab/cascade.c",178,__PRETTY_FUNCTION__,"no results produced from cascade");
   ret = -1;
     }
     if (dataset)
          table_destroy(dataset);
     return ret;
}

variable_types: struct route_handle { char *p_url; struct route_lowlevel { int (*ll_magic)(); char *(*ll_prefix)(); char *(*ll_description)(); void (*ll_init)(struct tree_head { struct rb_node { union { struct { struct rb_node *flink; struct rb_node *blink; } list; struct { struct rb_node *left; struct rb_node *right; } child; } c; union { struct rb_node *parent; struct rb_node *root; } p; struct status { unsigned int red; unsigned int internal; unsigned int left; unsigned int root; unsigned int head; } s; union { unsigned int ikey; char *key; struct rb_node *lext; } k; union { char *val; struct rb_node *rext; } v; } *root; struct rb_node *node; } *cf, int debug); void (*ll_fini)(); int (*ll_access)(char *p_url, char *password, char *basename, int flag); void *(*ll_open)(char *p_url, char *comment, char *password, int keep, char *basename); void (*ll_close)(void *lld); int (*ll_write)(void *lld, void *buf, int buflen); int (*ll_twrite)(void *lld, struct table_info { int ncols; int nrows; int minrowkey; int maxrowkey; struct tree_head *data; struct itree_head { struct rb_node *root; struct rb_node *node; } *colorder; struct tree_head *info; struct tree_head *infolookup; struct itree_head *tobegarbage; int refcount; struct itree_head *roworder; char separator; } *tab); int (*ll_tell)(void *lld, int *seq, int *size, long *modt); struct itree_head *(*ll_read)(void *lld, int seq, int offset); struct table_info *(*ll_tread)(void *lld, int seq, int offset); void (*ll_status)(void *lld, char **status, char **info); int (*ll_checkpoint)(void *lld); } *method; void *handle; struct route_buffer { int buflen; char *buffer; } unsent; } *

variable_types:
error
struct route_handle *

variable_types: r int

variable_types: ret int

variable_types: struct table_info { int ncols; int nrows; int minrowkey; int maxrowkey; struct tree_head { struct rb_node { union { struct { struct rb_node *flink; struct rb_node *blink; } list; struct { struct rb_node *left; struct rb_node *right; } child; } c; union { struct rb_node *parent; struct rb_node *root; } p; struct status { unsigned int red; unsigned int internal; unsigned int left; unsigned int root; unsigned int head; } s; union { unsigned int ikey; char *key; struct rb_node *lext; } k; union { char *val; struct rb_node *rext; } v; } *root; struct rb_node *node; } *data; struct itree_head { struct rb_node *root; struct rb_node *node; } *colorder; struct tree_head *info; struct tree_head *infolookup; struct itree_head *tobegarbage; int refcount; struct itree_head *roworder; char separator; } *

user_defined_types: struct route_handle { char *p_url; struct route_lowlevel *method; void *handle; struct route_buffer unsent; }

user_defined_types: struct route_lowlevel { int (*ll_magic)(); char *(*ll_prefix)(); char *(*ll_description)(); void (*ll_init)(struct tree_head *cf, int debug); void (*ll_fini)(); int (*ll_access)(char *p_url, char *password, char *basename, int flag); void *(*ll_open)(char *p_url, char *comment, char *password, int keep, char *basename); void (*ll_close)(void *lld); int (*ll_write)(void *lld, void *buf, int buflen); int (*ll_twrite)(void *lld, struct table_info *tab); int (*ll_tell)(void *lld, int *seq, int *size, long *modt); struct itree_head *(*ll_read)(void *lld, int seq, int offset); struct table_info *(*ll_tread)(void *lld, int seq, int offset); void (*ll_status)(void *lld, char **status, char **info); int (*ll_checkpoint)(void *lld); }


decompiled_code:
__int64 __fastcall timeline_actual(__int64 a1)
{
return timeline_offset + a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return timeline_offset + a1;
}

original_code:
time_t timeline_actual(time_t point)
{
     return point + timeline_offset;
}

canonical_original_code:
long timeline_actual(long point)
{
     return point + timeline_offset;
}

variable_types: point long

return_type: long


original_code:
char * timeline_label(time_t point, time_t scope, char *label, int length)
{
     time_t t;
     struct tm t_tm;
     t = timeline_actual(point);
     localtime_r(&t, &t_tm);
     if ( ! label)
       return ((void *)0);
     if (scope < 600)
       strftime(label, length, "%H:%M:%S", &t_tm);
     else if (scope < 25200)
       strftime(label, length, "%H:%M", &t_tm);
     else if (scope < 129600)
       strftime(label, length, "%H:00", &t_tm);
     else if (scope < 604800)
       strftime(label, length, "%a", &t_tm);
     else if (scope < 1209600)
       strftime(label, length, "%d%b", &t_tm);
     else if (scope < 5356800)
       strftime(label, length, "%d%b", &t_tm);
     else if (scope < 21427200)
       strftime(label, length, "%d%b%y", &t_tm);
     else if (scope < 36892800)
       strftime(label, length, "%b%y", &t_tm);
     else
       strftime(label, length, "%Y", &t_tm);
     return label;
}

canonical_original_code:
char *timeline_label(long point, long scope, char *label, int length)
{
     long t;
     struct tm t_tm;
     t = timeline_actual(point);
     localtime_r(&t, &t_tm);
     if ( ! label)
       return ((void *)0);
     if (scope < 600)
       strftime(label, length, "%H:%M:%S", &t_tm);
     else if (scope < 25200)
       strftime(label, length, "%H:%M", &t_tm);
     else if (scope < 129600)
       strftime(label, length, "%H:00", &t_tm);
     else if (scope < 604800)
       strftime(label, length, "%a", &t_tm);
     else if (scope < 1209600)
       strftime(label, length, "%d%b", &t_tm);
     else if (scope < 5356800)
       strftime(label, length, "%d%b", &t_tm);
     else if (scope < 21427200)
       strftime(label, length, "%d%b%y", &t_tm);
     else if (scope < 36892800)
       strftime(label, length, "%b%y", &t_tm);
     else
       strftime(label, length, "%Y", &t_tm);
     return label;
}

variable_types: scope long

variable_types:
label
char *

variable_types: length int

variable_types: t 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; }

return_type: char *


decompiled_code:
__int64 __fastcall timeline_free(_QWORD *a1)
{
__int64 v2; // rbx
__int64 v3; // rdi

while ( *a1 != *(_QWORD *)*a1 )
{
itree_first(a1);
v2 = itree_get(a1);
v3 = *(_QWORD *)(v2 + 8);
if ( v3 )
nm_nfree(v3, "iiab/timeline.c", 461LL, "timeline_free");
nm_nfree(v2, "iiab/timeline.c", 462LL, "timeline_free");
itree_rm(a1);
}
return itree_really_destroy(a1, "iiab/timeline.c", 466LL, "timeline_free");
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 v2; // rbx
__int64 v3; // rdi

while ( *a1 != *(_QWORD *)*a1 )
{
itree_first(a1);
v2 = itree_get(a1);
v3 = *(_QWORD *)(v2 + 8);
if ( v3 )
nm_nfree(v3, "iiab/timeline.c", 461LL, "timeline_free");
nm_nfree(v2, "iiab/timeline.c", 462LL, "timeline_free");
itree_rm(a1);
}
return itree_really_destroy(a1, "iiab/timeline.c", 466LL, "timeline_free");
}

original_code:
void timeline_free(ITREE *l)
{
     struct timeline_tick *tick;
     while ( ! ((l)->root->c.list.flink == (l)->root) ) {
   itree_first(l);
   tick = itree_get(l);
   if (tick->label)
        nm_nfree(tick->label,"iiab/timeline.c",461,__PRETTY_FUNCTION__);
   nm_nfree(tick,"iiab/timeline.c",462,__PRETTY_FUNCTION__);
   itree_rm(l);
     }
     itree_really_destroy(l,"iiab/timeline.c",466,__PRETTY_FUNCTION__);
}

canonical_original_code:
void timeline_free(struct itree_head *l)
{
     struct timeline_tick *tick;
     while ( ! ((l)->root->c.list.flink == (l)->root) ) {
   itree_first(l);
   tick = itree_get(l);
   if (tick->label)
        nm_nfree(tick->label,"iiab/timeline.c",461,__PRETTY_FUNCTION__);
   nm_nfree(tick,"iiab/timeline.c",462,__PRETTY_FUNCTION__);
   itree_rm(l);
     }
     itree_really_destroy(l,"iiab/timeline.c",466,__PRETTY_FUNCTION__);
}

variable_types: struct timeline_tick { enum timeline_ticktype { TIMELINE_MAJOR=0, TIMELINE_MINOR=1, TIMELINE_NONE=2 } type; char *label; long point; long ptime; } *

user_defined_types: struct itree_head { struct rb_node *root; struct rb_node *node; }

user_defined_types: struct timeline_tick { enum timeline_ticktype type; char *label; long point; long ptime; }

user_defined_types: struct status { unsigned int red; unsigned int internal; unsigned int left; unsigned int root; unsigned int head; }


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

if ( a2 > 6 )
{
if ( a2 - 7 > 1 )
return result;
result = (unsigned int)(a1[3] - 1);
a1[7] -= result;
a1[3] = 1;
LABEL_11:
a1[2] = 0;
goto LABEL_5;
}
if ( a2 > 3 )
goto LABEL_11;
if ( a2 == 2 )
{
LABEL_6:
*a1 = 0;
return result;
}
if ( a2 == 3 )
{
LABEL_5:
a1[1] = 0;
goto LABEL_6;
}
return result;
}

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

if ( a2 > 6 )
{
if ( a2 - 7 > 1 )
return result;
result = (unsigned int)(a1[3] - 1);
a1[7] -= result;
a1[3] = 1;
LABEL_11:
a1[2] = 0;
goto LABEL_5;
}
if ( a2 > 3 )
goto LABEL_11;
if ( a2 == 2 )
{
LABEL_6:
*a1 = 0;
return result;
}
if ( a2 == 3 )
{
LABEL_5:
a1[1] = 0;
goto LABEL_6;
}
return result;
}

original_code:
void timeline_rounddown(struct tm *t_tmp, enum timeline_units unit)
{
     switch (unit) {
     case NOUNIT:
   break;
     case YEARS:
     case MONTHS:
   t_tmp->tm_yday -= t_tmp->tm_mday-1;
   t_tmp->tm_mday = 1;
   t_tmp->tm_hour = 0;
     case MDAYS:
     case DAYS:
     case WEEKDAYS:
   t_tmp->tm_hour = 0;
     case HOURS:
   t_tmp->tm_min = 0;
     case MINS:
   t_tmp->tm_sec = 0;
     case SECS:
   break;
     }
}

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: enum timeline_units { NOUNIT=0, SECS=1, MINS=2, HOURS=3, WEEKDAYS=4, DAYS=5, MDAYS=6, MONTHS=7, YEARS=8 }


decompiled_code:
__int64 __fastcall timeline_calc(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // r12
int v6; // eax
char *v7; // rdx
int v8; // ebx
__int64 v9; // r14
time_t v10; // rdx
time_t v11; // rax
char *v12; // r13
__int64 v13; // rbx
time_t v14; // rax
time_t v15; // rsi
__int64 v16; // rbx
char s[32]; // [rsp+10h] [rbp-98h] BYREF
struct tm tp; // [rsp+30h] [rbp-78h] BYREF
time_t timer; // [rsp+68h] [rbp-40h] BYREF

if ( (int)a2 - (int)a1 <= 2 || a1 + 3 >= a2 )
return 0LL;
v5 = itree_really_create("iiab/timeline.c", 156LL, "timeline_calc");
v6 = timeline_tickpoints;
if ( timeline_tickpoints )
{
v7 = (char *)&timeline_tickpoints + 24;
v8 = 0;
do
{
if ( v6 >= a3 )
break;
++v8;
v7 += 24;
v6 = *((_DWORD *)v7 - 6);
}
while ( v6 );
}
else
{
v8 = timeline_tickpoints;
}
timer = timeline_offset + a1;
localtime_r(&timer, &tp);
strftime(s, 0x14uLL, "%d%b%y", &tp);
v9 = nm_nmalloc(32LL, "iiab/timeline.c", 176LL, "timeline_calc");
*(_DWORD *)v9 = 2;
*(_QWORD *)(v9 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 178LL, "timeline_calc");
*(_QWORD *)(v9 + 16) = a1;
*(_QWORD *)(v9 + 24) = timer;
itree_add(v5, (unsigned int)a1, v9);
timer -= *((int *)&timeline_tickpoints + 6 * v8 + 2);
timeline_rounddown(&tp, *((_DWORD *)&timeline_tickpoints + 6 * v8 + 1));
v10 = mktime(&tp);
timer = v10;
v11 = timeline_offset + a2;
if ( v10 < timeline_offset + a2 )
{
v12 = (char *)&timeline_tickpoints + 24 * v8;
do
{
timer = v10 + *((int *)v12 + 2);
localtime_r(&timer, &tp);
switch ( *((_DWORD *)v12 + 1) )
{
case 0:
strftime(s, 0x14uLL, "??", &tp);
break;
case 1:
strftime(s, 0x14uLL, "%H:%M:%S", &tp);
break;
case 2:
strftime(s, 0x14uLL, "%H:%M", &tp);
break;
case 3:
strftime(s, 0x14uLL, "%H:00", &tp);
break;
case 4:
strftime(s, 0x14uLL, "%a", &tp);
break;
case 5:
strftime(s, 0x14uLL, "%d%b", &tp);
break;
case 6:
strftime(s, 0x14uLL, "%d", &tp);
break;
case 7:
strftime(s, 0x14uLL, "%b", &tp);
break;
case 8:
strftime(s, 0x14uLL, "%Y", &tp);
break;
default:
break;
}
v13 = nm_nmalloc(32LL, "iiab/timeline.c", 235LL, "timeline_calc");
*(_DWORD *)v13 = 0;
*(_QWORD *)(v13 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 237LL, "timeline_calc");
v14 = timer;
v15 = timer - timeline_offset;
*(_QWORD *)(v13 + 16) = timer - timeline_offset;
*(_QWORD *)(v13 + 24) = v14;
itree_add(v5, v15, v13);
v11 = timeline_offset + a2;
v10 = timer;
}
while ( timeline_offset + a2 > timer );
}
timer = v11;
localtime_r(&timer, &tp);
strftime(s, 0x14uLL, "%d%b%y", &tp);
v16 = nm_nmalloc(32LL, "iiab/timeline.c", 290LL, "timeline_calc");
*(_DWORD *)v16 = 2;
*(_QWORD *)(v16 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 292LL, "timeline_calc");
*(_QWORD *)(v16 + 16) = a2;
*(_QWORD *)(v16 + 24) = timer;
itree_add(v5, (unsigned int)a2, v16);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // r12
int v6; // eax
char *v7; // rdx
int v8; // ebx
__int64 v9; // r14
time_t v10; // rdx
time_t v11; // rax
char *v12; // r13
__int64 v13; // rbx
time_t v14; // rax
time_t v15; // rsi
__int64 v16; // rbx
char s[32]; // [rsp+10h] [rbp-98h] BYREF
struct tm tp; // [rsp+30h] [rbp-78h] BYREF
time_t timer; // [rsp+68h] [rbp-40h] BYREF

if ( (int)a2 - (int)a1 <= 2 || a1 + 3 >= a2 )
return 0LL;
v5 = itree_really_create("iiab/timeline.c", 156LL, "timeline_calc");
v6 = timeline_tickpoints;
if ( timeline_tickpoints )
{
v7 = (char *)&timeline_tickpoints + 24;
v8 = 0;
do
{
if ( v6 >= a3 )
break;
++v8;
v7 += 24;
v6 = *((_DWORD *)v7 - 6);
}
while ( v6 );
}
else
{
v8 = timeline_tickpoints;
}
timer = timeline_offset + a1;
localtime_r(&timer, &tp);
strftime(s, 0x14uLL, "%d%b%y", &tp);
v9 = nm_nmalloc(32LL, "iiab/timeline.c", 176LL, "timeline_calc");
*(_DWORD *)v9 = 2;
*(_QWORD *)(v9 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 178LL, "timeline_calc");
*(_QWORD *)(v9 + 16) = a1;
*(_QWORD *)(v9 + 24) = timer;
itree_add(v5, (unsigned int)a1, v9);
timer -= *((int *)&timeline_tickpoints + 6 * v8 + 2);
func3(&tp, *((_DWORD *)&timeline_tickpoints + 6 * v8 + 1));
v10 = mktime(&tp);
timer = v10;
v11 = timeline_offset + a2;
if ( v10 < timeline_offset + a2 )
{
v12 = (char *)&timeline_tickpoints + 24 * v8;
do
{
timer = v10 + *((int *)v12 + 2);
localtime_r(&timer, &tp);
switch ( *((_DWORD *)v12 + 1) )
{
case 0:
strftime(s, 0x14uLL, "??", &tp);
break;
case 1:
strftime(s, 0x14uLL, "%H:%M:%S", &tp);
break;
case 2:
strftime(s, 0x14uLL, "%H:%M", &tp);
break;
case 3:
strftime(s, 0x14uLL, "%H:00", &tp);
break;
case 4:
strftime(s, 0x14uLL, "%a", &tp);
break;
case 5:
strftime(s, 0x14uLL, "%d%b", &tp);
break;
case 6:
strftime(s, 0x14uLL, "%d", &tp);
break;
case 7:
strftime(s, 0x14uLL, "%b", &tp);
break;
case 8:
strftime(s, 0x14uLL, "%Y", &tp);
break;
default:
break;
}
v13 = nm_nmalloc(32LL, "iiab/timeline.c", 235LL, "timeline_calc");
*(_DWORD *)v13 = 0;
*(_QWORD *)(v13 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 237LL, "timeline_calc");
v14 = timer;
v15 = timer - timeline_offset;
*(_QWORD *)(v13 + 16) = timer - timeline_offset;
*(_QWORD *)(v13 + 24) = v14;
itree_add(v5, v15, v13);
v11 = timeline_offset + a2;
v10 = timer;
}
while ( timeline_offset + a2 > timer );
}
timer = v11;
localtime_r(&timer, &tp);
strftime(s, 0x14uLL, "%d%b%y", &tp);
v16 = nm_nmalloc(32LL, "iiab/timeline.c", 290LL, "timeline_calc");
*(_DWORD *)v16 = 2;
*(_QWORD *)(v16 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 292LL, "timeline_calc");
*(_QWORD *)(v16 + 16) = a2;
*(_QWORD *)(v16 + 24) = timer;
itree_add(v5, (unsigned int)a2, v16);
return v5;
}

original_code:
ITREE *timeline_calc(time_t min,
       time_t max,
       time_t dispdiff,
       int maxchars )
{
     int diff;
     int maxlabels;
     int tickindex;
     ITREE *results;
     time_t t;
     struct tm t_tm;
     struct timeline_tick *tick;
     char label[20];
     diff = max - min;
     if (min +3 >= max || diff < 3)
   return ((void *)0);
     maxlabels = maxchars / (1+8+1);
     results = itree_really_create("iiab/timeline.c",156,__PRETTY_FUNCTION__);
     for (tickindex = 0; timeline_tickpoints[ tickindex ].threshold;
   tickindex++)
   if (dispdiff <= timeline_tickpoints[ tickindex ].threshold)
        break;
     t = min + timeline_offset;
     localtime_r(&t, &t_tm);
     strftime(label, 20, "%d%b%y", &t_tm);
     tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",176,__PRETTY_FUNCTION__);
     tick->type = TIMELINE_NONE;
     tick->label = nm_xnstrdup(label,"iiab/timeline.c",178,__PRETTY_FUNCTION__);
     tick->point = min;
     tick->ptime = t;
     itree_add(results, tick->point, tick);
     t -= timeline_tickpoints[ tickindex ].major;
     timeline_rounddown(&t_tm, timeline_tickpoints[ tickindex ].base);
     t = mktime(&t_tm);
     while (t < max + timeline_offset) {
   t += timeline_tickpoints[ tickindex ].major;
   localtime_r(&t, &t_tm);
   switch (timeline_tickpoints[ tickindex ].base) {
   case NOUNIT:
        strftime(label, 20, "??", &t_tm);
        break;
   case SECS:
        strftime(label, 20, "%H:%M:%S", &t_tm);
        break;
   case MINS:
        strftime(label, 20, "%H:%M", &t_tm);
        break;
   case HOURS:
        strftime(label, 20, "%H:00", &t_tm);
        break;
   case WEEKDAYS:
        strftime(label, 20, "%a", &t_tm);
        break;
   case DAYS:
        strftime(label, 20, "%d%b", &t_tm);
        break;
   case MDAYS:
        strftime(label, 20, "%d", &t_tm);
        break;
   case MONTHS:
        strftime(label, 20, "%b", &t_tm);
        break;
   case YEARS:
        strftime(label, 20, "%Y", &t_tm);
        break;
   }
   tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",235,__PRETTY_FUNCTION__);
   tick->type = TIMELINE_MAJOR;
   tick->label = nm_xnstrdup(label,"iiab/timeline.c",237,__PRETTY_FUNCTION__);
   tick->point = t - timeline_offset;
   tick->ptime = t;
   itree_add(results, tick->point, tick);
     }
     t = max + timeline_offset;
     localtime_r(&t, &t_tm);
     strftime(label, 20, "%d%b%y", &t_tm);
     tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",290,__PRETTY_FUNCTION__);
     tick->type = TIMELINE_NONE;
     tick->label = nm_xnstrdup(label,"iiab/timeline.c",292,__PRETTY_FUNCTION__);
     tick->point = max;
     tick->ptime = t;
     itree_add(results, max, tick);
     return results;
}

canonical_original_code:
struct itree_head *timeline_calc(long min, long max, long dispdiff, int maxchars)
{
     int diff;
     int maxlabels;
     int tickindex;
     struct itree_head *results;
     long t;
     struct tm t_tm;
     struct timeline_tick *tick;
     char label[20];
     diff = max - min;
     if (min +3 >= max || diff < 3)
   return ((void *)0);
     maxlabels = maxchars / (1+8+1);
     results = itree_really_create("iiab/timeline.c",156,__PRETTY_FUNCTION__);
     for (tickindex = 0; timeline_tickpoints[ tickindex ].threshold;
   tickindex++)
   if (dispdiff <= timeline_tickpoints[ tickindex ].threshold)
        break;
     t = min + timeline_offset;
     localtime_r(&t, &t_tm);
     strftime(label, 20, "%d%b%y", &t_tm);
     tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",176,__PRETTY_FUNCTION__);
     tick->type = TIMELINE_NONE;
     tick->label = nm_xnstrdup(label,"iiab/timeline.c",178,__PRETTY_FUNCTION__);
     tick->point = min;
     tick->ptime = t;
     itree_add(results, tick->point, tick);
     t -= timeline_tickpoints[ tickindex ].major;
     timeline_rounddown(&t_tm, timeline_tickpoints[ tickindex ].base);
     t = mktime(&t_tm);
     while (t < max + timeline_offset) {
   t += timeline_tickpoints[ tickindex ].major;
   localtime_r(&t, &t_tm);
   switch (timeline_tickpoints[ tickindex ].base) {
   case NOUNIT:
        strftime(label, 20, "??", &t_tm);
        break;
   case SECS:
        strftime(label, 20, "%H:%M:%S", &t_tm);
        break;
   case MINS:
        strftime(label, 20, "%H:%M", &t_tm);
        break;
   case HOURS:
        strftime(label, 20, "%H:00", &t_tm);
        break;
   case WEEKDAYS:
        strftime(label, 20, "%a", &t_tm);
        break;
   case DAYS:
        strftime(label, 20, "%d%b", &t_tm);
        break;
   case MDAYS:
        strftime(label, 20, "%d", &t_tm);
        break;
   case MONTHS:
        strftime(label, 20, "%b", &t_tm);
        break;
   case YEARS:
        strftime(label, 20, "%Y", &t_tm);
        break;
   }
   tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",235,__PRETTY_FUNCTION__);
   tick->type = TIMELINE_MAJOR;
   tick->label = nm_xnstrdup(label,"iiab/timeline.c",237,__PRETTY_FUNCTION__);
   tick->point = t - timeline_offset;
   tick->ptime = t;
   itree_add(results, tick->point, tick);
     }
     t = max + timeline_offset;
     localtime_r(&t, &t_tm);
     strftime(label, 20, "%d%b%y", &t_tm);
     tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",290,__PRETTY_FUNCTION__);
     tick->type = TIMELINE_NONE;
     tick->label = nm_xnstrdup(label,"iiab/timeline.c",292,__PRETTY_FUNCTION__);
     tick->point = max;
     tick->ptime = t;
     itree_add(results, max, tick);
     return results;
}

variable_types: min long

variable_types: max long

variable_types: dispdiff long

variable_types: maxchars int

variable_types: diff int

variable_types: maxlabels int

variable_types: tickindex int

variable_types: struct itree_head { struct rb_node { union { struct { struct rb_node *flink; struct rb_node *blink; } list; struct { struct rb_node *left; struct rb_node *right; } child; } c; union { struct rb_node *parent; struct rb_node *root; } p; struct status { unsigned int red; unsigned int internal; unsigned int left; unsigned int root; unsigned int head; } s; union { unsigned int ikey; char *key; struct rb_node *lext; } k; union { char *val; struct rb_node *rext; } v; } *root; struct rb_node *node; } *

variable_types:
label
char [20]

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; }

user_defined_types: enum timeline_ticktype { TIMELINE_MAJOR=0, TIMELINE_MINOR=1, TIMELINE_NONE=2 }


decompiled_code:
__int64 __fastcall timeline_ocalc(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // r12
int v6; // eax
char *v7; // rdx
int v8; // er13
struct tm *v9; // rax
__int64 v10; // rbx
char *v11; // r14
__int64 v12; // rbx
int v13; // esi
int v14; // eax
struct tm *v15; // rax
__int64 v16; // rdx
int v17; // esi
int v18; // eax
struct tm *v19; // rax
__int64 v20; // rbx
char s[32]; // [rsp+10h] [rbp-98h] BYREF
struct tm tp; // [rsp+30h] [rbp-78h] BYREF
time_t timer; // [rsp+68h] [rbp-40h] BYREF

if ( a1 + 3 >= a2 || a3 <= 2 )
return 0LL;
v5 = itree_really_create("iiab/timeline.c", 334LL, "timeline_ocalc");
v6 = timeline_tickpoints;
if ( timeline_tickpoints )
{
v7 = (char *)&timeline_tickpoints + 24;
v8 = 0;
do
{
if ( v6 >= a3 )
break;
++v8;
v7 += 24;
v6 = *((_DWORD *)v7 - 6);
}
while ( v6 );
}
else
{
v8 = timeline_tickpoints;
}
timer = timeline_offset + a1;
v9 = localtime(&timer);
strftime(s, 0x14uLL, "%d%b%y", v9);
v10 = nm_nmalloc(32LL, "iiab/timeline.c", 347LL, "timeline_ocalc");
*(_DWORD *)v10 = 2;
*(_QWORD *)(v10 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 349LL, "timeline_ocalc");
*(_QWORD *)(v10 + 16) = a1;
itree_add(v5, (unsigned int)a1, v10);
timer = timeline_offset + a1;
v11 = (char *)&timeline_tickpoints + 24 * v8;
while ( 1 )
{
timer += *((int *)v11 + 2);
v15 = localtime(&timer);
*(__m128i *)&tp.tm_sec = _mm_loadu_si128((const __m128i *)v15);
*(__m128i *)&tp.tm_mon = _mm_loadu_si128((const __m128i *)&v15->tm_mon);
*(__m128i *)&tp.tm_isdst = _mm_loadu_si128((const __m128i *)&v15->tm_isdst);
tp.tm_zone = v15->tm_zone;
timeline_rounddown(&tp, *((_DWORD *)v11 + 1));
timer = mktime(&tp);
if ( timer >= timeline_offset + a2 )
break;
switch ( *((_DWORD *)&timeline_tickpoints + 6 * v8 + 1) )
{
case 0:
strftime(s, 0x14uLL, "??", &tp);
break;
case 1:
strftime(s, 0x14uLL, "%H:%M:%S", &tp);
break;
case 2:
strftime(s, 0x14uLL, "%H:%M", &tp);
break;
case 3:
strftime(s, 0x14uLL, "%H:00", &tp);
break;
case 4:
strftime(s, 0x14uLL, "%a", &tp);
break;
case 5:
strftime(s, 0x14uLL, "%d%b", &tp);
break;
case 6:
strftime(s, 0x14uLL, "%d", &tp);
break;
case 7:
strftime(s, 0x14uLL, "%b", &tp);
break;
case 8:
strftime(s, 0x14uLL, "%Y", &tp);
break;
default:
break;
}
v12 = nm_nmalloc(32LL, "iiab/timeline.c", 401LL, "timeline_ocalc");
*(_DWORD *)v12 = 0;
*(_QWORD *)(v12 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 403LL, "timeline_ocalc");
v13 = timer;
v14 = timeline_offset;
*(_QWORD *)(v12 + 16) = timer - timeline_offset;
itree_add(v5, (unsigned int)(v13 - v14), v12);
}
timer = a1 + timeline_offset;
while ( 1 )
{
timer += *((int *)&timeline_tickpoints + 6 * v8 + 3);
if ( timer >= timeline_offset + a2 )
break;
if ( itree_find(v5) == -1 )
{
v16 = nm_nmalloc(32LL, "iiab/timeline.c", 429LL, "timeline_ocalc");
*(_DWORD *)v16 = 1;
*(_QWORD *)(v16 + 8) = 0LL;
v17 = timer;
v18 = timeline_offset;
*(_QWORD *)(v16 + 16) = timer - timeline_offset;
itree_add(v5, (unsigned int)(v17 - v18), v16);
}
}
timer = timeline_offset + a2;
v19 = localtime(&timer);
strftime(s, 0x14uLL, "%d%b%y", v19);
v20 = nm_nmalloc(32LL, "iiab/timeline.c", 442LL, "timeline_ocalc");
*(_DWORD *)v20 = 2;
*(_QWORD *)(v20 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 444LL, "timeline_ocalc");
*(_QWORD *)(v20 + 16) = a2;
itree_add(v5, (unsigned int)a2, v20);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // r12
int v6; // eax
char *v7; // rdx
int v8; // er13
struct tm *v9; // rax
__int64 v10; // rbx
char *v11; // r14
__int64 v12; // rbx
int v13; // esi
int v14; // eax
struct tm *v15; // rax
__int64 v16; // rdx
int v17; // esi
int v18; // eax
struct tm *v19; // rax
__int64 v20; // rbx
char s[32]; // [rsp+10h] [rbp-98h] BYREF
struct tm tp; // [rsp+30h] [rbp-78h] BYREF
time_t timer; // [rsp+68h] [rbp-40h] BYREF

if ( a1 + 3 >= a2 || a3 <= 2 )
return 0LL;
v5 = itree_really_create("iiab/timeline.c", 334LL, "timeline_ocalc");
v6 = timeline_tickpoints;
if ( timeline_tickpoints )
{
v7 = (char *)&timeline_tickpoints + 24;
v8 = 0;
do
{
if ( v6 >= a3 )
break;
++v8;
v7 += 24;
v6 = *((_DWORD *)v7 - 6);
}
while ( v6 );
}
else
{
v8 = timeline_tickpoints;
}
timer = timeline_offset + a1;
v9 = localtime(&timer);
strftime(s, 0x14uLL, "%d%b%y", v9);
v10 = nm_nmalloc(32LL, "iiab/timeline.c", 347LL, "timeline_ocalc");
*(_DWORD *)v10 = 2;
*(_QWORD *)(v10 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 349LL, "timeline_ocalc");
*(_QWORD *)(v10 + 16) = a1;
itree_add(v5, (unsigned int)a1, v10);
timer = timeline_offset + a1;
v11 = (char *)&timeline_tickpoints + 24 * v8;
while ( 1 )
{
timer += *((int *)v11 + 2);
v15 = localtime(&timer);
*(__m128i *)&tp.tm_sec = _mm_loadu_si128((const __m128i *)v15);
*(__m128i *)&tp.tm_mon = _mm_loadu_si128((const __m128i *)&v15->tm_mon);
*(__m128i *)&tp.tm_isdst = _mm_loadu_si128((const __m128i *)&v15->tm_isdst);
tp.tm_zone = v15->tm_zone;
func3(&tp, *((_DWORD *)v11 + 1));
timer = mktime(&tp);
if ( timer >= timeline_offset + a2 )
break;
switch ( *((_DWORD *)&timeline_tickpoints + 6 * v8 + 1) )
{
case 0:
strftime(s, 0x14uLL, "??", &tp);
break;
case 1:
strftime(s, 0x14uLL, "%H:%M:%S", &tp);
break;
case 2:
strftime(s, 0x14uLL, "%H:%M", &tp);
break;
case 3:
strftime(s, 0x14uLL, "%H:00", &tp);
break;
case 4:
strftime(s, 0x14uLL, "%a", &tp);
break;
case 5:
strftime(s, 0x14uLL, "%d%b", &tp);
break;
case 6:
strftime(s, 0x14uLL, "%d", &tp);
break;
case 7:
strftime(s, 0x14uLL, "%b", &tp);
break;
case 8:
strftime(s, 0x14uLL, "%Y", &tp);
break;
default:
break;
}
v12 = nm_nmalloc(32LL, "iiab/timeline.c", 401LL, "timeline_ocalc");
*(_DWORD *)v12 = 0;
*(_QWORD *)(v12 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 403LL, "timeline_ocalc");
v13 = timer;
v14 = timeline_offset;
*(_QWORD *)(v12 + 16) = timer - timeline_offset;
itree_add(v5, (unsigned int)(v13 - v14), v12);
}
timer = a1 + timeline_offset;
while ( 1 )
{
timer += *((int *)&timeline_tickpoints + 6 * v8 + 3);
if ( timer >= timeline_offset + a2 )
break;
if ( itree_find(v5) == -1 )
{
v16 = nm_nmalloc(32LL, "iiab/timeline.c", 429LL, "timeline_ocalc");
*(_DWORD *)v16 = 1;
*(_QWORD *)(v16 + 8) = 0LL;
v17 = timer;
v18 = timeline_offset;
*(_QWORD *)(v16 + 16) = timer - timeline_offset;
itree_add(v5, (unsigned int)(v17 - v18), v16);
}
}
timer = timeline_offset + a2;
v19 = localtime(&timer);
strftime(s, 0x14uLL, "%d%b%y", v19);
v20 = nm_nmalloc(32LL, "iiab/timeline.c", 442LL, "timeline_ocalc");
*(_DWORD *)v20 = 2;
*(_QWORD *)(v20 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 444LL, "timeline_ocalc");
*(_QWORD *)(v20 + 16) = a2;
itree_add(v5, (unsigned int)a2, v20);
return v5;
}

original_code:
ITREE *timeline_ocalc(time_t min,
       time_t max,
       time_t dispdiff )
{
     int tickindex;
     ITREE *results;
     time_t t;
     struct tm t_tm;
     struct tm *t_tmp;
     struct timeline_tick *tick;
     char label[20];
     if (min +3 >= max || dispdiff < 3)
   return ((void *)0);
     results = itree_really_create("iiab/timeline.c",334,__PRETTY_FUNCTION__);
     for (tickindex = 0; timeline_tickpoints[ tickindex ].threshold;
   tickindex++)
   if (dispdiff <= timeline_tickpoints[ tickindex ].threshold)
        break;
     t = min + timeline_offset;
     t_tmp = localtime(&t);
     strftime(label, 20, "%d%b%y", t_tmp);
     tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",347,__PRETTY_FUNCTION__);
     tick->type = TIMELINE_NONE;
     tick->label = nm_xnstrdup(label,"iiab/timeline.c",349,__PRETTY_FUNCTION__);
     tick->point = min;
     itree_add(results, min, tick);
     t = min + timeline_offset;
     while (1) {
   t += timeline_tickpoints[ tickindex ].major;
   t_tmp = localtime(&t);
   memcpy(&t_tm, t_tmp, sizeof(struct tm));
   timeline_rounddown(&t_tm, timeline_tickpoints[ tickindex ].base);
   t = mktime(&t_tm);
   if (t >= max + timeline_offset)
        break;
   switch (timeline_tickpoints[ tickindex ].base) {
   case NOUNIT:
        strftime(label, 20, "??", &t_tm);
        break;
   case SECS:
        strftime(label, 20, "%H:%M:%S", &t_tm);
        break;
   case MINS:
        strftime(label, 20, "%H:%M", &t_tm);
        break;
   case HOURS:
        strftime(label, 20, "%H:00", &t_tm);
        break;
   case WEEKDAYS:
        strftime(label, 20, "%a", &t_tm);
        break;
   case DAYS:
        strftime(label, 20, "%d%b", &t_tm);
        break;
   case MDAYS:
        strftime(label, 20, "%d", &t_tm);
        break;
   case MONTHS:
        strftime(label, 20, "%b", &t_tm);
        break;
   case YEARS:
        strftime(label, 20, "%Y", &t_tm);
        break;
   }
   tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",401,__PRETTY_FUNCTION__);
   tick->type = TIMELINE_MAJOR;
   tick->label = nm_xnstrdup(label,"iiab/timeline.c",403,__PRETTY_FUNCTION__);
   tick->point = t - timeline_offset;
   itree_add(results, t - timeline_offset, tick);
     }
     t = min + timeline_offset;
     while (1) {
   t += timeline_tickpoints[ tickindex ].minor;
   if (t >= max + timeline_offset)
        break;
   if (itree_find(results, t) == (void *) -1) {
        tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",429,__PRETTY_FUNCTION__);
        tick->type = TIMELINE_MINOR;
        tick->label = ((void *)0);
        tick->point = t - timeline_offset;
        itree_add(results, t - timeline_offset, tick);
   }
     }
     t = max + timeline_offset;
     t_tmp = localtime(&t);
     strftime(label, 20, "%d%b%y", t_tmp);
     tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",442,__PRETTY_FUNCTION__);
     tick->type = TIMELINE_NONE;
     tick->label = nm_xnstrdup(label,"iiab/timeline.c",444,__PRETTY_FUNCTION__);
     tick->point = max;
     itree_add(results, max, tick);
     return results;
}

canonical_original_code:
struct itree_head *timeline_ocalc(long min, long max, long dispdiff)
{
     int tickindex;
     struct itree_head *results;
     long t;
     struct tm t_tm;
     struct tm *t_tmp;
     struct timeline_tick *tick;
     char label[20];
     if (min +3 >= max || dispdiff < 3)
   return ((void *)0);
     results = itree_really_create("iiab/timeline.c",334,__PRETTY_FUNCTION__);
     for (tickindex = 0; timeline_tickpoints[ tickindex ].threshold;
   tickindex++)
   if (dispdiff <= timeline_tickpoints[ tickindex ].threshold)
        break;
     t = min + timeline_offset;
     t_tmp = localtime(&t);
     strftime(label, 20, "%d%b%y", t_tmp);
     tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",347,__PRETTY_FUNCTION__);
     tick->type = TIMELINE_NONE;
     tick->label = nm_xnstrdup(label,"iiab/timeline.c",349,__PRETTY_FUNCTION__);
     tick->point = min;
     itree_add(results, min, tick);
     t = min + timeline_offset;
     while (1) {
   t += timeline_tickpoints[ tickindex ].major;
   t_tmp = localtime(&t);
   memcpy(&t_tm, t_tmp, sizeof(struct tm));
   timeline_rounddown(&t_tm, timeline_tickpoints[ tickindex ].base);
   t = mktime(&t_tm);
   if (t >= max + timeline_offset)
        break;
   switch (timeline_tickpoints[ tickindex ].base) {
   case NOUNIT:
        strftime(label, 20, "??", &t_tm);
        break;
   case SECS:
        strftime(label, 20, "%H:%M:%S", &t_tm);
        break;
   case MINS:
        strftime(label, 20, "%H:%M", &t_tm);
        break;
   case HOURS:
        strftime(label, 20, "%H:00", &t_tm);
        break;
   case WEEKDAYS:
        strftime(label, 20, "%a", &t_tm);
        break;
   case DAYS:
        strftime(label, 20, "%d%b", &t_tm);
        break;
   case MDAYS:
        strftime(label, 20, "%d", &t_tm);
        break;
   case MONTHS:
        strftime(label, 20, "%b", &t_tm);
        break;
   case YEARS:
        strftime(label, 20, "%Y", &t_tm);
        break;
   }
   tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",401,__PRETTY_FUNCTION__);
   tick->type = TIMELINE_MAJOR;
   tick->label = nm_xnstrdup(label,"iiab/timeline.c",403,__PRETTY_FUNCTION__);
   tick->point = t - timeline_offset;
   itree_add(results, t - timeline_offset, tick);
     }
     t = min + timeline_offset;
     while (1) {
   t += timeline_tickpoints[ tickindex ].minor;
   if (t >= max + timeline_offset)
        break;
   if (itree_find(results, t) == (void *) -1) {
        tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",429,__PRETTY_FUNCTION__);
        tick->type = TIMELINE_MINOR;
        tick->label = ((void *)0);
        tick->point = t - timeline_offset;
        itree_add(results, t - timeline_offset, tick);
   }
     }
     t = max + timeline_offset;
     t_tmp = localtime(&t);
     strftime(label, 20, "%d%b%y", t_tmp);
     tick = nm_nmalloc(sizeof(struct timeline_tick),"iiab/timeline.c",442,__PRETTY_FUNCTION__);
     tick->type = TIMELINE_NONE;
     tick->label = nm_xnstrdup(label,"iiab/timeline.c",444,__PRETTY_FUNCTION__);
     tick->point = max;
     itree_add(results, max, tick);
     return results;
}

return_type: struct itree_head { struct rb_node { union { struct { struct rb_node *flink; struct rb_node *blink; } list; struct { struct rb_node *left; struct rb_node *right; } child; } c; union { struct rb_node *parent; struct rb_node *root; } p; struct status { unsigned int red; unsigned int internal; unsigned int left; unsigned int root; unsigned int head; } s; union { unsigned int ikey; char *key; struct rb_node *lext; } k; union { char *val; struct rb_node *rext; } v; } *root; struct rb_node *node; } *


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

if ( a2 > 6 )
{
if ( a2 - 7 > 1 )
return result;
result = (unsigned int)(a1[3] - 1);
a1[7] -= result;
a1[3] = 1;
a1[2] = 0;
LABEL_9:
a1[1] = 0;
goto LABEL_4;
}
if ( a2 > 3 )
goto LABEL_9;
if ( a2 - 2 <= 1 )
LABEL_4:
*a1 = 0;
return result;
}

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

if ( a2 > 6 )
{
if ( a2 - 7 > 1 )
return result;
result = (unsigned int)(a1[3] - 1);
a1[7] -= result;
a1[3] = 1;
a1[2] = 0;
LABEL_9:
a1[1] = 0;
goto LABEL_4;
}
if ( a2 > 3 )
goto LABEL_9;
if ( a2 - 2 <= 1 )
LABEL_4:
*a1 = 0;
return result;
}

original_code:
void timeline_orounddown(struct tm *t_tmp, enum timeline_units unit)
{
     switch (unit) {
     case NOUNIT:
   break;
     case YEARS:
     case MONTHS:
   t_tmp->tm_yday -= t_tmp->tm_mday-1;
   t_tmp->tm_mday = 1;
   t_tmp->tm_hour = 0;
     case MDAYS:
     case DAYS:
     case WEEKDAYS:
   t_tmp->tm_min = 0;
     case HOURS:
     case MINS:
   t_tmp->tm_sec = 0;
     case SECS:
   break;
     }
}

user_defined_types: enum timeline_units { NOUNIT=0, SECS=1, MINS=2, HOURS=3, WEEKDAYS=4, DAYS=5, MDAYS=6, MONTHS=7, YEARS=8 }


decompiled_code:
__int64 strbuf_init()
{
__int64 v0; // rbx
_BYTE *v1; // rax

v0 = nm_xnmalloc(16LL, "iiab/strbuf.c", 18LL, "strbuf_init");
v1 = (_BYTE *)nm_xnmalloc(128LL, "iiab/strbuf.c", 19LL, "strbuf_init");
*(_QWORD *)v0 = v1;
*v1 = 0;
*(_DWORD *)(v0 + 8) = 0;
*(_DWORD *)(v0 + 12) = 128;
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
_BYTE *v1; // rax

v0 = nm_xnmalloc(16LL, "iiab/strbuf.c", 18LL, "strbuf_init");
v1 = (_BYTE *)nm_xnmalloc(128LL, "iiab/strbuf.c", 19LL, "strbuf_init");
*(_QWORD *)v0 = v1;
*v1 = 0;
*(_DWORD *)(v0 + 8) = 0;
*(_DWORD *)(v0 + 12) = 128;
return v0;
}

original_code:
STRBUF strbuf_init()
{
     STRBUF s;
     s = nm_xnmalloc(sizeof(struct strbuf_inst),"iiab/strbuf.c",18,__PRETTY_FUNCTION__);
     s->buffer = nm_xnmalloc(128,"iiab/strbuf.c",19,__PRETTY_FUNCTION__);
     s->buffer[0] = '\0';
     s->strlen = 0;
     s->blocklen = 128;
     return s;
}

canonical_original_code:
struct strbuf_inst *strbuf_init()
{
     struct strbuf_inst *s;
     s = nm_xnmalloc(sizeof(struct strbuf_inst),"iiab/strbuf.c",18,__PRETTY_FUNCTION__);
     s->buffer = nm_xnmalloc(128,"iiab/strbuf.c",19,__PRETTY_FUNCTION__);
     s->buffer[0] = '\0';
     s->strlen = 0;
     s->blocklen = 128;
     return s;
}

variable_types: struct strbuf_inst { char *buffer; int strlen; int blocklen; } *


decompiled_code:
void __fastcall strbuf_append(__int64 a1, const char *a2)
{
int v3; // er12
int v4; // eax
int v5; // esi

if ( a2 && *a2 )
{
v3 = strlen(a2);
v4 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) + v3 >= v4 )
{
v5 = v4 + v3 + 1024;
*(_DWORD *)(a1 + 12) = v5;
*(_QWORD *)a1 = nm_xnrealloc(*(_QWORD *)a1, v5, "iiab/strbuf.c", 42LL, "strbuf_append");
}
strcpy((char *)(*(_QWORD *)a1 + *(int *)(a1 + 8)), a2);
*(_DWORD *)(a1 + 8) += v3;
}
}

original_code:
void strbuf_append(STRBUF buf, char *text)
{
     int len;
     if ( !text || !*text)
          return;
     len = strlen(text);
     if (buf->strlen+len >= buf->blocklen) {
          buf->blocklen = buf->blocklen + len + 1024;
          buf->buffer = nm_xnrealloc(buf->buffer,buf->blocklen,"iiab/strbuf.c",42,__PRETTY_FUNCTION__);
     }
     strcpy(buf->buffer + buf->strlen, text);
     buf->strlen += len;
}

canonical_original_code:
void strbuf_append(struct strbuf_inst *buf, char *text)
{
     int len;
     if ( !text || !*text)
          return;
     len = strlen(text);
     if (buf->strlen+len >= buf->blocklen) {
          buf->blocklen = buf->blocklen + len + 1024;
          buf->buffer = nm_xnrealloc(buf->buffer,buf->blocklen,"iiab/strbuf.c",42,__PRETTY_FUNCTION__);
     }
     strcpy(buf->buffer + buf->strlen, text);
     buf->strlen += len;
}

variable_types:
text
char *

variable_types: len int

user_defined_types: struct strbuf_inst { char *buffer; int strlen; int blocklen; }


decompiled_code:
__int64 __fastcall strbuf_string(__int64 a1)
{
return *(_QWORD *)a1;
}

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

original_code: char * strbuf_string(STRBUF buf) { return buf->buffer; }

canonical_original_code: char *strbuf_string(struct strbuf_inst *buf) { return buf->buffer; }


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

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

original_code: int strbuf_strlen(STRBUF buf) { return buf->strlen; }

canonical_original_code: int strbuf_strlen(struct strbuf_inst *buf) { return buf->strlen; }


decompiled_code:
__int64 __fastcall strbuf_fini(__int64 a1)
{
return nm_nfree(a1, "iiab/strbuf.c", 68LL, "strbuf_fini");
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return nm_nfree(a1, "iiab/strbuf.c", 68LL, "strbuf_fini");
}

original_code:
void strbuf_fini(STRBUF buf)
{
     nm_nfree(buf,"iiab/strbuf.c",68,__PRETTY_FUNCTION__);
}

canonical_original_code:
void strbuf_fini(struct strbuf_inst *buf)
{
     nm_nfree(buf,"iiab/strbuf.c",68,__PRETTY_FUNCTION__);
}


decompiled_code:
int sig_init()
{
int result; // eax

if ( sigemptyset(&blocknothing) )
elog_fdie(6LL, "iiab/sig.c", 28LL, "sig_init", "unable to prepare blocknothing");
if ( sigemptyset(&blockchild) && sigaddset(&blockchild, 17) )
elog_fdie(6LL, "iiab/sig.c", 32LL, "sig_init", "unable to prepare blockchild");
if ( sigemptyset(&blockalarm) && sigaddset(&blockalarm, 14) )
elog_fdie(6LL, "iiab/sig.c", 36LL, "sig_init", "unable to prepare blockalarm");
if ( sigemptyset(&blocktty) && sigaddset(&blocktty, 20) && sigaddset(&blockwork, 22) && sigaddset(&blockwork, 21) )
elog_fdie(6LL, "iiab/sig.c", 41LL, "sig_init", "unable to prepare blocktty");
if ( sigemptyset(&blockwork) && sigaddset(&blockwork, 17) && sigaddset(&blockwork, 14) )
elog_fdie(6LL, "iiab/sig.c", 46LL, "sig_init", "unable to prepare blockwork");
if ( sigfillset(&blockall) )
elog_fdie(6LL, "iiab/sig.c", 50LL, "sig_init", "unable to prepare blockall");
++sig_didinit;
elog_fsend(1LL, "iiab/sig.c", 54LL, "sig_init", "enable signals");
result = sigprocmask(2, &blocknothing, 0LL);
if ( result == -1 )
result = elog_fdie(6LL, "iiab/sig.c", 56LL, "sig_init", "unable to BLOCK");
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

if ( sigemptyset(&blocknothing) )
elog_fdie(6LL, "iiab/sig.c", 28LL, "sig_init", "unable to prepare blocknothing");
if ( sigemptyset(&blockchild) && sigaddset(&blockchild, 17) )
elog_fdie(6LL, "iiab/sig.c", 32LL, "sig_init", "unable to prepare blockchild");
if ( sigemptyset(&blockalarm) && sigaddset(&blockalarm, 14) )
elog_fdie(6LL, "iiab/sig.c", 36LL, "sig_init", "unable to prepare blockalarm");
if ( sigemptyset(&blocktty) && sigaddset(&blocktty, 20) && sigaddset(&blockwork, 22) && sigaddset(&blockwork, 21) )
elog_fdie(6LL, "iiab/sig.c", 41LL, "sig_init", "unable to prepare blocktty");
if ( sigemptyset(&blockwork) && sigaddset(&blockwork, 17) && sigaddset(&blockwork, 14) )
elog_fdie(6LL, "iiab/sig.c", 46LL, "sig_init", "unable to prepare blockwork");
if ( sigfillset(&blockall) )
elog_fdie(6LL, "iiab/sig.c", 50LL, "sig_init", "unable to prepare blockall");
++sig_didinit;
elog_fsend(1LL, "iiab/sig.c", 54LL, "sig_init", "enable signals");
result = sigprocmask(2, &blocknothing, 0LL);
if ( result == -1 )
result = elog_fdie(6LL, "iiab/sig.c", 56LL, "sig_init", "unable to BLOCK");
return result;
}

original_code:
void sig_init()
{
     if (sigemptyset(&blocknothing))
   elog_fdie(FATAL,"iiab/sig.c",28,__PRETTY_FUNCTION__,"unable to prepare blocknothing");
     if (sigemptyset(&blockchild) && sigaddset(&blockchild, 17))
   elog_fdie(FATAL,"iiab/sig.c",32,__PRETTY_FUNCTION__,"unable to prepare blockchild");
     if (sigemptyset(&blockalarm) && sigaddset(&blockalarm, 14))
   elog_fdie(FATAL,"iiab/sig.c",36,__PRETTY_FUNCTION__,"unable to prepare blockalarm");
     if (sigemptyset(&blocktty) && sigaddset(&blocktty, 20)
   && sigaddset(&blockwork, 22) && sigaddset(&blockwork, 21))
   elog_fdie(FATAL,"iiab/sig.c",41,__PRETTY_FUNCTION__,"unable to prepare blocktty");
     if (sigemptyset(&blockwork) && sigaddset(&blockwork, 17)
  && sigaddset(&blockwork, 14))
   elog_fdie(FATAL,"iiab/sig.c",46,__PRETTY_FUNCTION__,"unable to prepare blockwork");
     if (sigfillset(&blockall))
   elog_fdie(FATAL,"iiab/sig.c",50,__PRETTY_FUNCTION__,"unable to prepare blockall");
     sig_didinit++;
     elog_fsend(DEBUG,"iiab/sig.c",54,__PRETTY_FUNCTION__,"enable signals");
     if (sigprocmask(2, &blocknothing, ((void *)0)) == -1)
          elog_fdie(FATAL,"iiab/sig.c",56,__PRETTY_FUNCTION__,"unable to BLOCK");
}