decompiled_code:
__int64 __fastcall timeline_ocalc(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r14
__int64 v5; // rax
int *v6; // rdx
int v7; // ebx
struct tm *v8; // rax
__int64 v9; // rax
__int64 v10; // r12
time_t v11; // rax
char *v12; // r12
struct tm *v13; // rax
unsigned int v14; // esi
_DWORD *v15; // rax
_DWORD *v16; // r13
__int64 v17; // rax
time_t v18; // rsi
time_t v19; // rax
__int64 v20; // rsi
time_t v21; // rax
time_t v22; // rsi
struct tm *v23; // rax
_DWORD *v24; // rax
_DWORD *v25; // r12
__int64 v26; // rax
__int64 v28; // rax
time_t v29; // rsi
time_t timer; // [rsp+28h] [rbp-A0h] BYREF
char s[32]; // [rsp+30h] [rbp-98h] BYREF
struct tm tp; // [rsp+50h] [rbp-78h] BYREF

if ( a1 + 3 >= a2 || a3 <= 2 )
return 0LL;
v4 = itree_really_create("iiab/timeline.c", 334LL, "timeline_ocalc");
v5 = timeline_tickpoints;
if ( timeline_tickpoints )
{
v6 = (int *)((char *)&timeline_tickpoints + 24);
v7 = 0;
do
{
if ( v5 >= a3 )
break;
v5 = *v6;
v6 += 6;
++v7;
}
while ( (_DWORD)v5 );
}
else
{
v7 = 0;
}
timer = timeline_offset + a1;
v8 = localtime(&timer);
strftime(s, 0x14uLL, "%d%b%y", v8);
v9 = nm_nmalloc(32LL, "iiab/timeline.c", 347LL, "timeline_ocalc");
*(_DWORD *)v9 = 2;
v10 = v9;
*(_QWORD *)(v9 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 349LL, "timeline_ocalc");
*(_QWORD *)(v10 + 16) = a1;
itree_add(v4, (unsigned int)a1, v10);
v11 = a1 + timeline_offset;
v12 = (char *)&timeline_tickpoints + 24 * v7;
while ( 1 )
{
timer = *((int *)v12 + 2) + v11;
v13 = localtime(&timer);
v14 = *((_DWORD *)v12 + 1);
*(__m128i *)&tp.tm_sec = _mm_loadu_si128((const __m128i *)v13);
*(__m128i *)&tp.tm_mon = _mm_loadu_si128((const __m128i *)&v13->tm_mon);
*(__m128i *)&tp.tm_isdst = _mm_loadu_si128((const __m128i *)&v13->tm_isdst);
tp.tm_zone = v13->tm_zone;
timeline_rounddown(&tp, v14);
timer = mktime(&tp);
if ( timer >= timeline_offset + a2 )
break;
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;
}
v15 = (_DWORD *)nm_nmalloc(32LL, "iiab/timeline.c", 401LL, "timeline_ocalc");
*v15 = 0;
v16 = v15;
v17 = nm_xnstrdup(s, "iiab/timeline.c", 403LL, "timeline_ocalc");
v18 = timer;
*((_QWORD *)v16 + 1) = v17;
v19 = v18 - timeline_offset;
v20 = (unsigned int)(v18 - timeline_offset);
*((_QWORD *)v16 + 2) = v19;
itree_add(v4, v20, v16);
v11 = timer;
}
v21 = timeline_offset + a2;
v22 = a1 + timeline_offset;
while ( 1 )
{
timer = *((int *)&timeline_tickpoints + 6 * v7 + 3) + v22;
if ( timer >= v21 )
break;
if ( itree_find(v4) == -1 )
{
v28 = nm_nmalloc(32LL, "iiab/timeline.c", 429LL, "timeline_ocalc");
v29 = timer;
*(_DWORD *)v28 = 1;
*(_QWORD *)(v28 + 8) = 0LL;
*(_QWORD *)(v28 + 16) = v29 - timeline_offset;
itree_add(v4, (unsigned int)(v29 - timeline_offset), v28);
}
v22 = timer;
v21 = a2 + timeline_offset;
}
timer = v21;
v23 = localtime(&timer);
strftime(s, 0x14uLL, "%d%b%y", v23);
v24 = (_DWORD *)nm_nmalloc(32LL, "iiab/timeline.c", 442LL, "timeline_ocalc");
*v24 = 2;
v25 = v24;
v26 = nm_xnstrdup(s, "iiab/timeline.c", 444LL, "timeline_ocalc");
*((_QWORD *)v25 + 2) = a2;
*((_QWORD *)v25 + 1) = v26;
itree_add(v4, (unsigned int)a2, v25);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r14
__int64 v5; // rax
int *v6; // rdx
int v7; // ebx
struct tm *v8; // rax
__int64 v9; // rax
__int64 v10; // r12
time_t v11; // rax
char *v12; // r12
struct tm *v13; // rax
unsigned int v14; // esi
_DWORD *v15; // rax
_DWORD *v16; // r13
__int64 v17; // rax
time_t v18; // rsi
time_t v19; // rax
__int64 v20; // rsi
time_t v21; // rax
time_t v22; // rsi
struct tm *v23; // rax
_DWORD *v24; // rax
_DWORD *v25; // r12
__int64 v26; // rax
__int64 v28; // rax
time_t v29; // rsi
time_t timer; // [rsp+28h] [rbp-A0h] BYREF
char s[32]; // [rsp+30h] [rbp-98h] BYREF
struct tm tp; // [rsp+50h] [rbp-78h] BYREF

if ( a1 + 3 >= a2 || a3 <= 2 )
return 0LL;
v4 = itree_really_create("iiab/timeline.c", 334LL, "timeline_ocalc");
v5 = timeline_tickpoints;
if ( timeline_tickpoints )
{
v6 = (int *)((char *)&timeline_tickpoints + 24);
v7 = 0;
do
{
if ( v5 >= a3 )
break;
v5 = *v6;
v6 += 6;
++v7;
}
while ( (_DWORD)v5 );
}
else
{
v7 = 0;
}
timer = timeline_offset + a1;
v8 = localtime(&timer);
strftime(s, 0x14uLL, "%d%b%y", v8);
v9 = nm_nmalloc(32LL, "iiab/timeline.c", 347LL, "timeline_ocalc");
*(_DWORD *)v9 = 2;
v10 = v9;
*(_QWORD *)(v9 + 8) = nm_xnstrdup(s, "iiab/timeline.c", 349LL, "timeline_ocalc");
*(_QWORD *)(v10 + 16) = a1;
itree_add(v4, (unsigned int)a1, v10);
v11 = a1 + timeline_offset;
v12 = (char *)&timeline_tickpoints + 24 * v7;
while ( 1 )
{
timer = *((int *)v12 + 2) + v11;
v13 = localtime(&timer);
v14 = *((_DWORD *)v12 + 1);
*(__m128i *)&tp.tm_sec = _mm_loadu_si128((const __m128i *)v13);
*(__m128i *)&tp.tm_mon = _mm_loadu_si128((const __m128i *)&v13->tm_mon);
*(__m128i *)&tp.tm_isdst = _mm_loadu_si128((const __m128i *)&v13->tm_isdst);
tp.tm_zone = v13->tm_zone;
func3(&tp, v14);
timer = mktime(&tp);
if ( timer >= timeline_offset + a2 )
break;
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;
}
v15 = (_DWORD *)nm_nmalloc(32LL, "iiab/timeline.c", 401LL, "timeline_ocalc");
*v15 = 0;
v16 = v15;
v17 = nm_xnstrdup(s, "iiab/timeline.c", 403LL, "timeline_ocalc");
v18 = timer;
*((_QWORD *)v16 + 1) = v17;
v19 = v18 - timeline_offset;
v20 = (unsigned int)(v18 - timeline_offset);
*((_QWORD *)v16 + 2) = v19;
itree_add(v4, v20, v16);
v11 = timer;
}
v21 = timeline_offset + a2;
v22 = a1 + timeline_offset;
while ( 1 )
{
timer = *((int *)&timeline_tickpoints + 6 * v7 + 3) + v22;
if ( timer >= v21 )
break;
if ( itree_find(v4) == -1 )
{
v28 = nm_nmalloc(32LL, "iiab/timeline.c", 429LL, "timeline_ocalc");
v29 = timer;
*(_DWORD *)v28 = 1;
*(_QWORD *)(v28 + 8) = 0LL;
*(_QWORD *)(v28 + 16) = v29 - timeline_offset;
itree_add(v4, (unsigned int)(v29 - timeline_offset), v28);
}
v22 = timer;
v21 = a2 + timeline_offset;
}
timer = v21;
v23 = localtime(&timer);
strftime(s, 0x14uLL, "%d%b%y", v23);
v24 = (_DWORD *)nm_nmalloc(32LL, "iiab/timeline.c", 442LL, "timeline_ocalc");
*v24 = 2;
v25 = v24;
v26 = nm_xnstrdup(s, "iiab/timeline.c", 444LL, "timeline_ocalc");
*((_QWORD *)v25 + 2) = a2;
*((_QWORD *)v25 + 1) = v26;
itree_add(v4, (unsigned int)a2, v25);
return v4;
}

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


repo: SystemGarden/habitat

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

if ( a2 <= 6 )
{
if ( a2 <= 3 )
{
if ( a2 - 2 > 1 )
return result;
goto LABEL_4;
}
LABEL_8:
*(_DWORD *)(a1 + 4) = 0;
LABEL_4:
*(_DWORD *)a1 = 0;
return result;
}
if ( a2 - 7 <= 1 )
{
*(_DWORD *)(a1 + 28) -= *(_DWORD *)(a1 + 12) - 1;
result = 0x100000000LL;
*(_QWORD *)(a1 + 8) = 0x100000000LL;
goto LABEL_8;
}
return result;
}

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

if ( a2 <= 6 )
{
if ( a2 <= 3 )
{
if ( a2 - 2 > 1 )
return result;
goto LABEL_4;
}
LABEL_8:
*(_DWORD *)(a1 + 4) = 0;
LABEL_4:
*(_DWORD *)a1 = 0;
return result;
}
if ( a2 - 7 <= 1 )
{
*(_DWORD *)(a1 + 28) -= *(_DWORD *)(a1 + 12) - 1;
result = 0x100000000LL;
*(_QWORD *)(a1 + 8) = 0x100000000LL;
goto LABEL_8;
}
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;
     }
}

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 }

return_type: void


decompiled_code:
_QWORD *strbuf_init()
{
_QWORD *v0; // r12
_BYTE *v1; // rax

v0 = (_QWORD *)nm_xnmalloc(16LL, "iiab/strbuf.c", 18LL, "strbuf_init");
v1 = (_BYTE *)nm_xnmalloc(128LL, "iiab/strbuf.c", 19LL, "strbuf_init");
*v0 = v1;
*v1 = 0;
v0[1] = 0x8000000000LL;
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12
_BYTE *v1; // rax

v0 = (_QWORD *)nm_xnmalloc(16LL, "iiab/strbuf.c", 18LL, "strbuf_init");
v1 = (_BYTE *)nm_xnmalloc(128LL, "iiab/strbuf.c", 19LL, "strbuf_init");
*v0 = v1;
*v1 = 0;
v0[1] = 0x8000000000LL;
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; } *


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

return_type: char *


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

return_type: int


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


decompiled_code:
int __fastcall sig_setchild(void (*a1)(int))
{
__m128i v1; // xmm1
__m128i v2; // xmm2
__m128i v3; // xmm3
__m128i v4; // xmm4
__m128i v5; // xmm5
__m128i v6; // xmm6
__m128i v7; // xmm7
int result; // eax
struct sigaction v9; // [rsp+0h] [rbp-A8h] BYREF

elog_fprintf(1LL, "iiab/sig.c", 65LL, "sig_setchild", "set SIGCHILD handler=%p", a1);
v9.sa_handler = a1;
v9.sa_flags = 0x10000000;
v1 = _mm_loadu_si128((const __m128i *)&blockwork.__val[2]);
v2 = _mm_loadu_si128((const __m128i *)&blockwork.__val[4]);
v3 = _mm_loadu_si128((const __m128i *)&blockwork.__val[6]);
v4 = _mm_loadu_si128((const __m128i *)&blockwork.__val[8]);
v5 = _mm_loadu_si128((const __m128i *)&blockwork.__val[10]);
*(__m128i *)v9.sa_mask.__val = _mm_loadu_si128((const __m128i *)&blockwork);
v6 = _mm_loadu_si128((const __m128i *)&blockwork.__val[12]);
v7 = _mm_loadu_si128((const __m128i *)&blockwork.__val[14]);
*(__m128i *)&v9.sa_mask.__val[2] = v1;
*(__m128i *)&v9.sa_mask.__val[4] = v2;
*(__m128i *)&v9.sa_mask.__val[6] = v3;
*(__m128i *)&v9.sa_mask.__val[8] = v4;
*(__m128i *)&v9.sa_mask.__val[10] = v5;
*(__m128i *)&v9.sa_mask.__val[12] = v6;
*(__m128i *)&v9.sa_mask.__val[14] = v7;
result = sigaction(17, &v9, 0LL);
if ( result == -1 )
result = elog_fdie(6LL, "iiab/sig.c", 73LL, "sig_setchild", "unable to install SIGCHILD signal handler");
return result;
}

canonical_decompiled_code:
int __fastcall func1(void (*a1)(int))
{
__m128i v1; // xmm1
__m128i v2; // xmm2
__m128i v3; // xmm3
__m128i v4; // xmm4
__m128i v5; // xmm5
__m128i v6; // xmm6
__m128i v7; // xmm7
int result; // eax
struct sigaction v9; // [rsp+0h] [rbp-A8h] BYREF

elog_fprintf(1LL, "iiab/sig.c", 65LL, "sig_setchild", "set SIGCHILD handler=%p", a1);
v9.sa_handler = a1;
v9.sa_flags = 0x10000000;
v1 = _mm_loadu_si128((const __m128i *)&blockwork.__val[2]);
v2 = _mm_loadu_si128((const __m128i *)&blockwork.__val[4]);
v3 = _mm_loadu_si128((const __m128i *)&blockwork.__val[6]);
v4 = _mm_loadu_si128((const __m128i *)&blockwork.__val[8]);
v5 = _mm_loadu_si128((const __m128i *)&blockwork.__val[10]);
*(__m128i *)v9.sa_mask.__val = _mm_loadu_si128((const __m128i *)&blockwork);
v6 = _mm_loadu_si128((const __m128i *)&blockwork.__val[12]);
v7 = _mm_loadu_si128((const __m128i *)&blockwork.__val[14]);
*(__m128i *)&v9.sa_mask.__val[2] = v1;
*(__m128i *)&v9.sa_mask.__val[4] = v2;
*(__m128i *)&v9.sa_mask.__val[6] = v3;
*(__m128i *)&v9.sa_mask.__val[8] = v4;
*(__m128i *)&v9.sa_mask.__val[10] = v5;
*(__m128i *)&v9.sa_mask.__val[12] = v6;
*(__m128i *)&v9.sa_mask.__val[14] = v7;
result = sigaction(17, &v9, 0LL);
if ( result == -1 )
result = elog_fdie(6LL, "iiab/sig.c", 73LL, "sig_setchild", "unable to install SIGCHILD signal handler");
return result;
}

original_code:
void sig_setchild(void (*handler)(int))
{
     struct sigaction s;
     int r;
     elog_fprintf(DEBUG,"iiab/sig.c",65,__PRETTY_FUNCTION__,"set SIGCHILD handler=%p", handler);
     s.__sigaction_handler.sa_handler = handler;
     s.sa_mask = blockwork;
     s.sa_flags = 0x10000000;
     r = sigaction(17, &s, ((void *)0));
     if (r == -1)
   elog_fdie(FATAL,"iiab/sig.c",73,__PRETTY_FUNCTION__,"unable to install SIGCHILD signal handler");
}

variable_types:
handler
void (*)(int)

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: r int

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
int __fastcall sig_setalarm(void (*a1)(int))
{
__m128i v1; // xmm1
__m128i v2; // xmm2
__m128i v3; // xmm3
__m128i v4; // xmm4
__m128i v5; // xmm5
__m128i v6; // xmm6
__m128i v7; // xmm7
int result; // eax
struct sigaction v9; // [rsp+0h] [rbp-A8h] BYREF

elog_fprintf(1LL, "iiab/sig.c", 83LL, "sig_setalarm", "set SIGALRM handler=%p", a1);
v9.sa_handler = a1;
v9.sa_flags = 0x10000000;
v1 = _mm_loadu_si128((const __m128i *)&blockwork.__val[2]);
v2 = _mm_loadu_si128((const __m128i *)&blockwork.__val[4]);
v3 = _mm_loadu_si128((const __m128i *)&blockwork.__val[6]);
v4 = _mm_loadu_si128((const __m128i *)&blockwork.__val[8]);
v5 = _mm_loadu_si128((const __m128i *)&blockwork.__val[10]);
*(__m128i *)v9.sa_mask.__val = _mm_loadu_si128((const __m128i *)&blockwork);
v6 = _mm_loadu_si128((const __m128i *)&blockwork.__val[12]);
v7 = _mm_loadu_si128((const __m128i *)&blockwork.__val[14]);
*(__m128i *)&v9.sa_mask.__val[2] = v1;
*(__m128i *)&v9.sa_mask.__val[4] = v2;
*(__m128i *)&v9.sa_mask.__val[6] = v3;
*(__m128i *)&v9.sa_mask.__val[8] = v4;
*(__m128i *)&v9.sa_mask.__val[10] = v5;
*(__m128i *)&v9.sa_mask.__val[12] = v6;
*(__m128i *)&v9.sa_mask.__val[14] = v7;
result = sigaction(14, &v9, 0LL);
if ( result == -1 )
result = elog_fdie(6LL, "iiab/sig.c", 91LL, "sig_setalarm", "unable to install SIGALRM signal handler");
return result;
}

canonical_decompiled_code:
int __fastcall func2(void (*a1)(int))
{
__m128i v1; // xmm1
__m128i v2; // xmm2
__m128i v3; // xmm3
__m128i v4; // xmm4
__m128i v5; // xmm5
__m128i v6; // xmm6
__m128i v7; // xmm7
int result; // eax
struct sigaction v9; // [rsp+0h] [rbp-A8h] BYREF

elog_fprintf(1LL, "iiab/sig.c", 83LL, "sig_setalarm", "set SIGALRM handler=%p", a1);
v9.sa_handler = a1;
v9.sa_flags = 0x10000000;
v1 = _mm_loadu_si128((const __m128i *)&blockwork.__val[2]);
v2 = _mm_loadu_si128((const __m128i *)&blockwork.__val[4]);
v3 = _mm_loadu_si128((const __m128i *)&blockwork.__val[6]);
v4 = _mm_loadu_si128((const __m128i *)&blockwork.__val[8]);
v5 = _mm_loadu_si128((const __m128i *)&blockwork.__val[10]);
*(__m128i *)v9.sa_mask.__val = _mm_loadu_si128((const __m128i *)&blockwork);
v6 = _mm_loadu_si128((const __m128i *)&blockwork.__val[12]);
v7 = _mm_loadu_si128((const __m128i *)&blockwork.__val[14]);
*(__m128i *)&v9.sa_mask.__val[2] = v1;
*(__m128i *)&v9.sa_mask.__val[4] = v2;
*(__m128i *)&v9.sa_mask.__val[6] = v3;
*(__m128i *)&v9.sa_mask.__val[8] = v4;
*(__m128i *)&v9.sa_mask.__val[10] = v5;
*(__m128i *)&v9.sa_mask.__val[12] = v6;
*(__m128i *)&v9.sa_mask.__val[14] = v7;
result = sigaction(14, &v9, 0LL);
if ( result == -1 )
result = elog_fdie(6LL, "iiab/sig.c", 91LL, "sig_setalarm", "unable to install SIGALRM signal handler");
return result;
}

original_code:
void sig_setalarm(void (*handler)(int))
{
     struct sigaction s;
     int r;
     elog_fprintf(DEBUG,"iiab/sig.c",83,__PRETTY_FUNCTION__,"set SIGALRM handler=%p", handler);
     s.__sigaction_handler.sa_handler = handler;
     s.sa_mask = blockwork;
     s.sa_flags = 0x10000000;
     r = sigaction(14, &s, ((void *)0));
     if (r == -1)
   elog_fdie(FATAL,"iiab/sig.c",91,__PRETTY_FUNCTION__,"unable to install SIGALRM signal handler");
}

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


decompiled_code:
int __fastcall sig_setexit(void (*a1)(int))
{
__m128i v1; // xmm1
__m128i v2; // xmm2
__m128i v3; // xmm3
__m128i v4; // xmm4
__m128i v5; // xmm5
__m128i v6; // xmm6
__m128i v7; // xmm7
int result; // eax
struct sigaction v9; // [rsp+0h] [rbp-A8h] BYREF

elog_fprintf(1LL, "iiab/sig.c", 102LL, "sig_setexit", "set exit handler=%p for SIGHUP, SIGINT, SIGQUIT & SIGTERM", a1);
v9.sa_handler = a1;
v9.sa_flags = 0x10000000;
v1 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[2]);
v2 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[4]);
v3 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[6]);
v4 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[8]);
v5 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[10]);
*(__m128i *)v9.sa_mask.__val = _mm_loadu_si128((const __m128i *)&blockalarm);
v6 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[12]);
v7 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[14]);
*(__m128i *)&v9.sa_mask.__val[2] = v1;
*(__m128i *)&v9.sa_mask.__val[4] = v2;
*(__m128i *)&v9.sa_mask.__val[6] = v3;
*(__m128i *)&v9.sa_mask.__val[8] = v4;
*(__m128i *)&v9.sa_mask.__val[10] = v5;
*(__m128i *)&v9.sa_mask.__val[12] = v6;
*(__m128i *)&v9.sa_mask.__val[14] = v7;
if ( sigaction(1, &v9, 0LL) == -1 )
elog_fdie(6LL, "iiab/sig.c", 113LL, "sig_setexit", "SIGHUP failed to install");
if ( sigaction(2, &v9, 0LL) == -1 )
elog_fdie(6LL, "iiab/sig.c", 116LL, "sig_setexit", "SIGINT failed to install");
if ( sigaction(3, &v9, 0LL) == -1 )
elog_fdie(6LL, "iiab/sig.c", 119LL, "sig_setexit", "SIGQUIT failed to install");
result = sigaction(15, &v9, 0LL);
if ( result == -1 )
result = elog_fdie(6LL, "iiab/sig.c", 122LL, "sig_setexit", "SIGTERM failed to install");
return result;
}

canonical_decompiled_code:
int __fastcall func3(void (*a1)(int))
{
__m128i v1; // xmm1
__m128i v2; // xmm2
__m128i v3; // xmm3
__m128i v4; // xmm4
__m128i v5; // xmm5
__m128i v6; // xmm6
__m128i v7; // xmm7
int result; // eax
struct sigaction v9; // [rsp+0h] [rbp-A8h] BYREF

elog_fprintf(1LL, "iiab/sig.c", 102LL, "sig_setexit", "set exit handler=%p for SIGHUP, SIGINT, SIGQUIT & SIGTERM", a1);
v9.sa_handler = a1;
v9.sa_flags = 0x10000000;
v1 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[2]);
v2 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[4]);
v3 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[6]);
v4 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[8]);
v5 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[10]);
*(__m128i *)v9.sa_mask.__val = _mm_loadu_si128((const __m128i *)&blockalarm);
v6 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[12]);
v7 = _mm_loadu_si128((const __m128i *)&blockalarm.__val[14]);
*(__m128i *)&v9.sa_mask.__val[2] = v1;
*(__m128i *)&v9.sa_mask.__val[4] = v2;
*(__m128i *)&v9.sa_mask.__val[6] = v3;
*(__m128i *)&v9.sa_mask.__val[8] = v4;
*(__m128i *)&v9.sa_mask.__val[10] = v5;
*(__m128i *)&v9.sa_mask.__val[12] = v6;
*(__m128i *)&v9.sa_mask.__val[14] = v7;
if ( sigaction(1, &v9, 0LL) == -1 )
elog_fdie(6LL, "iiab/sig.c", 113LL, "sig_setexit", "SIGHUP failed to install");
if ( sigaction(2, &v9, 0LL) == -1 )
elog_fdie(6LL, "iiab/sig.c", 116LL, "sig_setexit", "SIGINT failed to install");
if ( sigaction(3, &v9, 0LL) == -1 )
elog_fdie(6LL, "iiab/sig.c", 119LL, "sig_setexit", "SIGQUIT failed to install");
result = sigaction(15, &v9, 0LL);
if ( result == -1 )
result = elog_fdie(6LL, "iiab/sig.c", 122LL, "sig_setexit", "SIGTERM failed to install");
return result;
}

original_code:
void sig_setexit(void (*handler)(int))
{
     struct sigaction s;
     int r;
     elog_fprintf(DEBUG,"iiab/sig.c",102,__PRETTY_FUNCTION__,"set exit handler=%p for SIGHUP, SIGINT, SIGQUIT & " "SIGTERM", handler);
     s.__sigaction_handler.sa_handler = handler;
     s.sa_mask = blockalarm;
     s.sa_flags = 0x10000000;
     r = sigaction(1, &s, ((void *)0));
     if (r == -1)
   elog_fdie(FATAL,"iiab/sig.c",113,__PRETTY_FUNCTION__,"SIGHUP failed to install");
     r = sigaction(2, &s, ((void *)0));
     if (r == -1)
   elog_fdie(FATAL,"iiab/sig.c",116,__PRETTY_FUNCTION__,"SIGINT failed to install");
     r = sigaction(3, &s, ((void *)0));
     if (r == -1)
   elog_fdie(FATAL,"iiab/sig.c",119,__PRETTY_FUNCTION__,"SIGQUIT failed to install");
     r = sigaction(15, &s, ((void *)0));
     if (r == -1)
   elog_fdie(FATAL,"iiab/sig.c",122,__PRETTY_FUNCTION__,"SIGTERM failed to install");
}


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

result = sigprocmask(0, &blocktty, 0LL);
if ( result == -1 )
result = elog_fdie(6LL, "iiab/sig.c", 131LL, "sig_blocktty", "unable to block tty signals");
return result;
}

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

result = sigprocmask(0, &blocktty, 0LL);
if ( result == -1 )
result = elog_fdie(6LL, "iiab/sig.c", 131LL, "sig_blocktty", "unable to block tty signals");
return result;
}

original_code:
void sig_blocktty()
{
     if (sigprocmask(0, &blocktty, ((void *)0)) == -1)
   elog_fdie(FATAL,"iiab/sig.c",131,__PRETTY_FUNCTION__,"unable to block tty signals");
}


decompiled_code:
__int64 sig_off()
{
if ( sigprocmask(0, &blockall, &blockprev) == -1 )
elog_fdie(6LL, "iiab/sig.c", 140LL, "sig_off", "unable to BLOCK signals when attempting to disable");
return elog_fsend(1LL, "iiab/sig.c", 142LL, "sig_off", "disabled signals");
}

canonical_decompiled_code:
__int64 func5()
{
if ( sigprocmask(0, &blockall, &blockprev) == -1 )
elog_fdie(6LL, "iiab/sig.c", 140LL, "sig_off", "unable to BLOCK signals when attempting to disable");
return elog_fsend(1LL, "iiab/sig.c", 142LL, "sig_off", "disabled signals");
}

original_code:
void sig_off()
{
     if (sigprocmask(0, &blockall, &blockprev) == -1)
   elog_fdie(FATAL,"iiab/sig.c",140,__PRETTY_FUNCTION__,"unable to BLOCK signals when attempting to disable");
     elog_fsend(DEBUG,"iiab/sig.c",142,__PRETTY_FUNCTION__,"disabled signals");
}


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

if ( !sig_didinit )
return elog_fsend(5LL, "iiab/sig.c", 151LL, "sig_on", "ask to restore signals but sig not init; do nothing");
elog_fsend(1LL, "iiab/sig.c", 149LL, "sig_on", "restore signals");
result = sigprocmask(2, &blockprev, 0LL);
if ( result == -1 )
result = elog_fdie(6LL, "iiab/sig.c", 157LL, "sig_on", "unable to UNBLOCK signal to restore them");
return result;
}

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

if ( !sig_didinit )
return elog_fsend(5LL, "iiab/sig.c", 151LL, "sig_on", "ask to restore signals but sig not init; do nothing");
elog_fsend(1LL, "iiab/sig.c", 149LL, "sig_on", "restore signals");
result = sigprocmask(2, &blockprev, 0LL);
if ( result == -1 )
result = elog_fdie(6LL, "iiab/sig.c", 157LL, "sig_on", "unable to UNBLOCK signal to restore them");
return result;
}

original_code:
void sig_on()
{
     if (sig_didinit) {
          elog_fsend(DEBUG,"iiab/sig.c",149,__PRETTY_FUNCTION__,"restore signals");
     } else {
          elog_fsend(ERROR,"iiab/sig.c",151,__PRETTY_FUNCTION__,"ask to restore signals but sig not init; " "do nothing");
   return;
     }
     if (sigprocmask(2, &blockprev, ((void *)0)) == -1)
   elog_fdie(FATAL,"iiab/sig.c",157,__PRETTY_FUNCTION__,"unable to UNBLOCK signal to restore them");
}


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

result = &rcache_mru;
do
{
*result = 0LL;
result += 7;
*(result - 6) = 0LL;
*(result - 5) = 0LL;
*(result - 4) = 0LL;
*(result - 3) = 0LL;
*(result - 2) = 0LL;
*((_DWORD *)result - 2) = 0;
}
while ( result != (_QWORD *)((char *)&rcache_mru + 560) );
return result;
}

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

result = &rcache_mru;
do
{
*result = 0LL;
result += 7;
*(result - 6) = 0LL;
*(result - 5) = 0LL;
*(result - 4) = 0LL;
*(result - 3) = 0LL;
*(result - 2) = 0LL;
*((_DWORD *)result - 2) = 0;
}
while ( result != (_QWORD *)((char *)&rcache_mru + 560) );
return result;
}

original_code:
void rcache_init()
{
     int i;
     for (i=0; i<10; i++) {
          rcache_mru[i].basepurl = ((void *)0);
          rcache_mru[i].last_call = 0;
          rcache_mru[i].last_time = 0;
          rcache_mru[i].tab = ((void *)0);
          rcache_mru[i].oldest = 0;
          rcache_mru[i].youngest = 0;
   rcache_mru[i].status = RCACHE_LOAD_EMPTY;
     }
}

variable_types: i int


decompiled_code:
__int64 rcache_fini()
{
_QWORD *v0; // rbx
__int64 result; // rax

v0 = &rcache_mru;
do
{
if ( *v0 )
result = nm_nfree(*v0, "myhabitat/rcache.c", 53LL, "rcache_fini");
if ( v0[3] )
result = table_destroy();
*v0 = 0LL;
v0 += 7;
*(v0 - 6) = 0LL;
*(v0 - 5) = 0LL;
*(v0 - 4) = 0LL;
*(v0 - 3) = 0LL;
*(v0 - 2) = 0LL;
*((_DWORD *)v0 - 2) = 0;
}
while ( v0 != (_QWORD *)((char *)&rcache_mru + 560) );
return result;
}

canonical_decompiled_code:
__int64 func1()
{
_QWORD *v0; // rbx
__int64 result; // rax

v0 = &rcache_mru;
do
{
if ( *v0 )
result = nm_nfree(*v0, "myhabitat/rcache.c", 53LL, "rcache_fini");
if ( v0[3] )
result = table_destroy();
*v0 = 0LL;
v0 += 7;
*(v0 - 6) = 0LL;
*(v0 - 5) = 0LL;
*(v0 - 4) = 0LL;
*(v0 - 3) = 0LL;
*(v0 - 2) = 0LL;
*((_DWORD *)v0 - 2) = 0;
}
while ( v0 != (_QWORD *)((char *)&rcache_mru + 560) );
return result;
}

original_code:
void rcache_fini()
{
     int i;
     for (i=0; i<10; i++) {
          if (rcache_mru[i].basepurl)
        nm_nfree(rcache_mru[i].basepurl,"myhabitat/rcache.c",53,__PRETTY_FUNCTION__);
          if (rcache_mru[i].tab)
        table_destroy(rcache_mru[i].tab);
          rcache_mru[i].basepurl = ((void *)0);
          rcache_mru[i].last_call = 0;
          rcache_mru[i].last_time = 0;
          rcache_mru[i].tab = ((void *)0);
          rcache_mru[i].oldest = 0;
          rcache_mru[i].youngest = 0;
   rcache_mru[i].status = RCACHE_LOAD_EMPTY;
     }
}


decompiled_code:
time_t __fastcall rcache_priv_create_entry(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, int a6)
{
char *v10; // rbx
__int64 v11; // rax
time_t result; // rax

v10 = (char *)&rcache_mru + 56 * a1;
*(_QWORD *)v10 = nm_xnstrdup(a2, "myhabitat/rcache.c", 234LL, "rcache_priv_create_entry");
v11 = rcache_ncalls;
*((_QWORD *)v10 + 3) = a3;
*((_QWORD *)v10 + 1) = ++v11;
rcache_ncalls = v11;
result = time(0LL);
*((_QWORD *)v10 + 4) = a4;
*((_QWORD *)v10 + 2) = result;
*((_QWORD *)v10 + 5) = a5;
*((_DWORD *)v10 + 12) = a6;
return result;
}

canonical_decompiled_code:
time_t __fastcall func2(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, int a6)
{
char *v10; // rbx
__int64 v11; // rax
time_t result; // rax

v10 = (char *)&rcache_mru + 56 * a1;
*(_QWORD *)v10 = nm_xnstrdup(a2, "myhabitat/rcache.c", 234LL, "rcache_priv_create_entry");
v11 = rcache_ncalls;
*((_QWORD *)v10 + 3) = a3;
*((_QWORD *)v10 + 1) = ++v11;
rcache_ncalls = v11;
result = time(0LL);
*((_QWORD *)v10 + 4) = a4;
*((_QWORD *)v10 + 2) = result;
*((_QWORD *)v10 + 5) = a5;
*((_DWORD *)v10 + 12) = a6;
return result;
}

original_code:
void rcache_priv_create_entry(int slot, char *basepurl, TABLE tab,
         time_t oldest, time_t youngest,
         enum rcache_load_status status)
{
     rcache_mru[slot].basepurl = nm_xnstrdup(basepurl,"myhabitat/rcache.c",234,__PRETTY_FUNCTION__);
     rcache_mru[slot].tab = tab;
     rcache_mru[slot].last_call = ++rcache_ncalls;
     rcache_mru[slot].last_time = time(((void *)0));
     rcache_mru[slot].oldest = oldest;
     rcache_mru[slot].youngest = youngest;
     rcache_mru[slot].status = status;
}

canonical_original_code:
void rcache_priv_create_entry(int slot, char *basepurl, struct table_info *tab, long oldest, long youngest, enum rcache_load_status status)
{
     rcache_mru[slot].basepurl = nm_xnstrdup(basepurl,"myhabitat/rcache.c",234,__PRETTY_FUNCTION__);
     rcache_mru[slot].tab = tab;
     rcache_mru[slot].last_call = ++rcache_ncalls;
     rcache_mru[slot].last_time = time(((void *)0));
     rcache_mru[slot].oldest = oldest;
     rcache_mru[slot].youngest = youngest;
     rcache_mru[slot].status = status;
}

variable_types: slot int

variable_types:
basepurl
char *

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: oldest long

variable_types: youngest long

variable_types: enum rcache_load_status { RCACHE_LOAD_EMPTY=0, RCACHE_LOAD_FAIL=1, RCACHE_LOAD_HOLE=2, RCACHE_LOAD_TIMETABLE=3, RCACHE_LOAD_TABLE=4, RCACHE_LOAD_TEXT=5, RCACHE_LOAD_RING=6 }

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:
__int64 rcache_priv_oldest_entry()
{
_QWORD *v0; // rdx
__int64 result; // rax

v0 = rcache_mru;
result = 0LL;
do
{
if ( !*v0 )
break;
result = (unsigned int)(result + 1);
v0 += 7;
}
while ( (_DWORD)result != 10 );
return result;
}

canonical_decompiled_code:
__int64 func4()
{
_QWORD *v0; // rdx
__int64 result; // rax

v0 = rcache_mru;
result = 0LL;
do
{
if ( !*v0 )
break;
result = (unsigned int)(result + 1);
v0 += 7;
}
while ( (_DWORD)result != 10 );
return result;
}

original_code:
int rcache_priv_oldest_entry()
{
     int i, min, oldest_idx = -1;
     min = rcache_ncalls;
     for (i=0; i<10; i++) {
          if (rcache_mru[i].basepurl) {
        if ( rcache_mru[i].last_call &&
      rcache_mru[i].last_call < min) {
          min = rcache_mru[i].last_call;
   oldest_idx = i;
        }
   } else {
        return i;
   }
     }
     return i;
}

canonical_original_code:
int rcache_priv_oldest_entry()
{
     int i; int min; int oldest_idx = -1;
     min = rcache_ncalls;
     for (i=0; i<10; i++) {
          if (rcache_mru[i].basepurl) {
        if ( rcache_mru[i].last_call &&
      rcache_mru[i].last_call < min) {
          min = rcache_mru[i].last_call;
   oldest_idx = i;
        }
   } else {
        return i;
   }
     }
     return i;
}

variable_types: min int


decompiled_code:
__int64 __fastcall rcache_request(char *src, __int64 a2, __int64 a3, unsigned int a4)
{
unsigned int *v6; // rax
unsigned int *v7; // r14
__int64 v8; // r12
__int64 v9; // rax
__int64 v10; // r15
__int64 v11; // r12
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rdx
__int64 v15; // r13
int v16; // er9
unsigned int v17; // er9
int v19; // er12
__int64 v20; // [rsp-8h] [rbp-260h]
int v21; // [rsp+0h] [rbp-258h]
const char *v22; // [rsp+8h] [rbp-250h]
int v23; // [rsp+8h] [rbp-250h]
const char *v24; // [rsp+10h] [rbp-248h]
char s[568]; // [rsp+20h] [rbp-238h] BYREF

if ( !src )
return 1;
v6 = (unsigned int *)rcache_priv_find_entry(src);
v7 = v6;
if ( v6 )
{
v8 = *((_QWORD *)v6 + 4);
v9 = *((_QWORD *)v6 + 5);
v10 = v9 + 1;
if ( v8 > a2 )
v10 = a2;
v11 = v8 - 1;
if ( a3 > v9 )
v11 = a3;
if ( v10 > v11 )
return v7[12];
}
else
{
v10 = a2;
v11 = a3;
}
v12 = util_decdatetime(v10);
v22 = (const char *)nm_xnstrdup(v12, "myhabitat/rcache.c", 135LL, "rcache_request");
v13 = util_decdatetime(v11);
v24 = (const char *)nm_xnstrdup(v13, "myhabitat/rcache.c", 136LL, "rcache_request");
if ( v10 )
{
snprintf(s, 0x200uLL, "%s,cons,*,t=%ld-%ld", src, v10, v11);
elog_fprintf(
2LL,
"myhabitat/rcache.c",
139LL,
"rcache_request",
"Reading %s into cache from %s to %s",
src,
v22,
v24);
v14 = v20;
}
else
{
strncpy(s, src, 0x200uLL);
elog_fprintf(2LL, "myhabitat/rcache.c", 145LL, "rcache_request", "Reading %s into cache without time", src);
}
v15 = fileroute_tread(s, a4, v14);
if ( !v15 )
{
elog_fprintf(
2LL,
"myhabitat/rcache.c",
155LL,
"rcache_request",
"No data available between %s and %s from '%s' (%s)\n",
v22,
v24,
src,
s);
nm_nfree(v22, "myhabitat/rcache.c", 160LL, "rcache_request");
nm_nfree(v24, "myhabitat/rcache.c", 161LL, "rcache_request");
if ( v7 )
{
rcache_priv_grow_entry(v7, v10, v11);
return 2;
}
return 1;
}
nm_nfree(v22, "myhabitat/rcache.c", 169LL, "rcache_request");
nm_nfree(v24, "myhabitat/rcache.c", 170LL, "rcache_request");
table_rmcol(v15, "_ringid");
table_rmcol(v15, "_dur");
table_rmcol(v15, "_seq");
if ( (int)table_ncols(v15) <= 2 && (unsigned int)table_hascol(v15, "data") )
v16 = 5;
else
v16 = ((unsigned int)table_hascol(v15, "_time") == 0) + 3;
if ( v7 )
{
v21 = v16;
table_addtable(*((_QWORD *)v7 + 3), v15, 1LL);
table_sortnumeric(*((_QWORD *)v7 + 3), "_time", 0LL);
rcache_priv_grow_entry(v7, v10, v11);
table_destroy(v15);
v17 = v21;
}
else
{
v23 = v16;
v19 = rcache_priv_oldest_entry();
rcache_priv_free_entry(v19);
rcache_priv_create_entry(v19, (__int64)src, v15, a2, a3, v23);
v17 = v23;
}
return v17;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *src, __int64 a2, __int64 a3, unsigned int a4)
{
unsigned int *v6; // rax
unsigned int *v7; // r14
__int64 v8; // r12
__int64 v9; // rax
__int64 v10; // r15
__int64 v11; // r12
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rdx
__int64 v15; // r13
int v16; // er9
unsigned int v17; // er9
int v19; // er12
__int64 v20; // [rsp-8h] [rbp-260h]
int v21; // [rsp+0h] [rbp-258h]
const char *v22; // [rsp+8h] [rbp-250h]
int v23; // [rsp+8h] [rbp-250h]
const char *v24; // [rsp+10h] [rbp-248h]
char s[568]; // [rsp+20h] [rbp-238h] BYREF

if ( !src )
return 1;
v6 = (unsigned int *)rcache_priv_find_entry(src);
v7 = v6;
if ( v6 )
{
v8 = *((_QWORD *)v6 + 4);
v9 = *((_QWORD *)v6 + 5);
v10 = v9 + 1;
if ( v8 > a2 )
v10 = a2;
v11 = v8 - 1;
if ( a3 > v9 )
v11 = a3;
if ( v10 > v11 )
return v7[12];
}
else
{
v10 = a2;
v11 = a3;
}
v12 = util_decdatetime(v10);
v22 = (const char *)nm_xnstrdup(v12, "myhabitat/rcache.c", 135LL, "rcache_request");
v13 = util_decdatetime(v11);
v24 = (const char *)nm_xnstrdup(v13, "myhabitat/rcache.c", 136LL, "rcache_request");
if ( v10 )
{
snprintf(s, 0x200uLL, "%s,cons,*,t=%ld-%ld", src, v10, v11);
elog_fprintf(
2LL,
"myhabitat/rcache.c",
139LL,
"rcache_request",
"Reading %s into cache from %s to %s",
src,
v22,
v24);
v14 = v20;
}
else
{
strncpy(s, src, 0x200uLL);
elog_fprintf(2LL, "myhabitat/rcache.c", 145LL, "rcache_request", "Reading %s into cache without time", src);
}
v15 = fileroute_tread(s, a4, v14);
if ( !v15 )
{
elog_fprintf(
2LL,
"myhabitat/rcache.c",
155LL,
"rcache_request",
"No data available between %s and %s from '%s' (%s)\n",
v22,
v24,
src,
s);
nm_nfree(v22, "myhabitat/rcache.c", 160LL, "rcache_request");
nm_nfree(v24, "myhabitat/rcache.c", 161LL, "rcache_request");
if ( v7 )
{
func5(v7, v10, v11);
return 2;
}
return 1;
}
nm_nfree(v22, "myhabitat/rcache.c", 169LL, "rcache_request");
nm_nfree(v24, "myhabitat/rcache.c", 170LL, "rcache_request");
table_rmcol(v15, "_ringid");
table_rmcol(v15, "_dur");
table_rmcol(v15, "_seq");
if ( (int)table_ncols(v15) <= 2 && (unsigned int)table_hascol(v15, "data") )
v16 = 5;
else
v16 = ((unsigned int)table_hascol(v15, "_time") == 0) + 3;
if ( v7 )
{
v21 = v16;
table_addtable(*((_QWORD *)v7 + 3), v15, 1LL);
table_sortnumeric(*((_QWORD *)v7 + 3), "_time", 0LL);
func5(v7, v10, v11);
table_destroy(v15);
v17 = v21;
}
else
{
v23 = v16;
v19 = func4();
func3(v19);
func2(v19, (__int64)src, v15, a2, a3, v23);
v17 = v23;
}
return v17;
}

original_code:
enum rcache_load_status rcache_request(char *basepurl,
           time_t min_t, time_t max_t,
           FILEROUTE_TYPE hint)
{
     char purl[512];
     time_t from_t, to_t;
     char *from_txt, *to_txt;
     struct rcache_entry *existing;
     TABLE tab;
     int slot;
     enum rcache_load_status status;
     if (!basepurl)
          return RCACHE_LOAD_FAIL;
     existing = rcache_priv_find_entry(basepurl);
     if (existing) {
          if (existing->oldest <= min_t)
        from_t = existing->youngest+1;
   else
        from_t = min_t;
   if (existing->youngest >= max_t)
        to_t = existing->oldest-1;
   else
        to_t = max_t;
   if (from_t > to_t) {
        return existing->status;
   }
     } else {
          from_t = min_t;
   to_t = max_t;
     }
     from_txt = nm_xnstrdup(util_decdatetime(from_t),"myhabitat/rcache.c",135,__PRETTY_FUNCTION__);
     to_txt = nm_xnstrdup(util_decdatetime(to_t),"myhabitat/rcache.c",136,__PRETTY_FUNCTION__);
     if (from_t) {
          snprintf(purl, 512, "%s,cons,*,t=%ld-%ld", basepurl, from_t, to_t);
   elog_fprintf(DIAG,"myhabitat/rcache.c",139,__PRETTY_FUNCTION__,"Reading %s into cache from %s to %s", basepurl, from_txt, to_txt);
     } else {
          strncpy(purl, basepurl, 512);
   elog_fprintf(DIAG,"myhabitat/rcache.c",145,__PRETTY_FUNCTION__,"Reading %s into cache without time", basepurl);
     }
     tab = fileroute_tread(purl, hint);
     if (!tab) {
          elog_fprintf(DIAG,"myhabitat/rcache.c",155,__PRETTY_FUNCTION__,"No data available between %s and %s from '%s' (%s)\n", from_txt, to_txt, basepurl, purl);
   nm_nfree(from_txt,"myhabitat/rcache.c",160,__PRETTY_FUNCTION__);
   nm_nfree(to_txt,"myhabitat/rcache.c",161,__PRETTY_FUNCTION__);
   if (existing) {
        rcache_priv_grow_entry(existing, from_t, to_t);
        return RCACHE_LOAD_HOLE;
   } else {
        return RCACHE_LOAD_FAIL;
   }
     }
     nm_nfree(from_txt,"myhabitat/rcache.c",169,__PRETTY_FUNCTION__);
     nm_nfree(to_txt,"myhabitat/rcache.c",170,__PRETTY_FUNCTION__);
     table_rmcol(tab, "_ringid");
     table_rmcol(tab, "_dur");
     table_rmcol(tab, "_seq");
     if (table_ncols(tab) <= 2 && table_hascol(tab, "data"))
          status = RCACHE_LOAD_TEXT;
     else if (table_hascol(tab, "_time"))
          status = RCACHE_LOAD_TIMETABLE;
     else
          status = RCACHE_LOAD_TABLE;
     if (existing) {
          table_addtable(existing->tab, tab, 1);
   table_sortnumeric(existing->tab, "_time", ((void *)0));
   rcache_priv_grow_entry(existing, from_t, to_t);
   table_destroy(tab);
     } else {
          slot = rcache_priv_oldest_entry();
   rcache_priv_free_entry(slot);
   rcache_priv_create_entry(slot, basepurl, tab, min_t, max_t, status);
     }
     return status;
}

canonical_original_code:
enum rcache_load_status rcache_request(char *basepurl, long min_t, long max_t, enum fileroute_file_type hint)
{
     char purl[512];
     long from_t; long to_t;
     char *from_txt; char *to_txt;
     struct rcache_entry *existing;
     struct table_info *tab;
     int slot;
     enum rcache_load_status status;
     if (!basepurl)
          return RCACHE_LOAD_FAIL;
     existing = rcache_priv_find_entry(basepurl);
     if (existing) {
          if (existing->oldest <= min_t)
        from_t = existing->youngest+1;
   else
        from_t = min_t;
   if (existing->youngest >= max_t)
        to_t = existing->oldest-1;
   else
        to_t = max_t;
   if (from_t > to_t) {
        return existing->status;
   }
     } else {
          from_t = min_t;
   to_t = max_t;
     }
     from_txt = nm_xnstrdup(util_decdatetime(from_t),"myhabitat/rcache.c",135,__PRETTY_FUNCTION__);
     to_txt = nm_xnstrdup(util_decdatetime(to_t),"myhabitat/rcache.c",136,__PRETTY_FUNCTION__);
     if (from_t) {
          snprintf(purl, 512, "%s,cons,*,t=%ld-%ld", basepurl, from_t, to_t);
   elog_fprintf(DIAG,"myhabitat/rcache.c",139,__PRETTY_FUNCTION__,"Reading %s into cache from %s to %s", basepurl, from_txt, to_txt);
     } else {
          strncpy(purl, basepurl, 512);
   elog_fprintf(DIAG,"myhabitat/rcache.c",145,__PRETTY_FUNCTION__,"Reading %s into cache without time", basepurl);
     }
     tab = fileroute_tread(purl, hint);
     if (!tab) {
          elog_fprintf(DIAG,"myhabitat/rcache.c",155,__PRETTY_FUNCTION__,"No data available between %s and %s from '%s' (%s)\n", from_txt, to_txt, basepurl, purl);
   nm_nfree(from_txt,"myhabitat/rcache.c",160,__PRETTY_FUNCTION__);
   nm_nfree(to_txt,"myhabitat/rcache.c",161,__PRETTY_FUNCTION__);
   if (existing) {
        rcache_priv_grow_entry(existing, from_t, to_t);
        return RCACHE_LOAD_HOLE;
   } else {
        return RCACHE_LOAD_FAIL;
   }
     }
     nm_nfree(from_txt,"myhabitat/rcache.c",169,__PRETTY_FUNCTION__);
     nm_nfree(to_txt,"myhabitat/rcache.c",170,__PRETTY_FUNCTION__);
     table_rmcol(tab, "_ringid");
     table_rmcol(tab, "_dur");
     table_rmcol(tab, "_seq");
     if (table_ncols(tab) <= 2 && table_hascol(tab, "data"))
          status = RCACHE_LOAD_TEXT;
     else if (table_hascol(tab, "_time"))
          status = RCACHE_LOAD_TIMETABLE;
     else
          status = RCACHE_LOAD_TABLE;
     if (existing) {
          table_addtable(existing->tab, tab, 1);
   table_sortnumeric(existing->tab, "_time", ((void *)0));
   rcache_priv_grow_entry(existing, from_t, to_t);
   table_destroy(tab);
     } else {
          slot = rcache_priv_oldest_entry();
   rcache_priv_free_entry(slot);
   rcache_priv_create_entry(slot, basepurl, tab, min_t, max_t, status);
     }
     return status;
}

variable_types: enum fileroute_file_type { FILEROUTE_TYPE_UNKNOWN=0, FILEROUTE_TYPE_GRS=1, FILEROUTE_TYPE_RS=2, FILEROUTE_TYPE_CSV=3, FILEROUTE_TYPE_TSV=4, FILEROUTE_TYPE_SSV=5, FILEROUTE_TYPE_PSV=6, FILEROUTE_TYPE_FHA=7, FILEROUTE_TYPE_TEXT=8 }

variable_types:
purl
char [512]

variable_types: struct rcache_entry { char *basepurl; long last_call; long last_time; 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; long oldest; long youngest; enum rcache_load_status { RCACHE_LOAD_EMPTY=0, RCACHE_LOAD_FAIL=1, RCACHE_LOAD_HOLE=2, RCACHE_LOAD_TIMETABLE=3, RCACHE_LOAD_TABLE=4, RCACHE_LOAD_TEXT=5, RCACHE_LOAD_RING=6 } status; } *

user_defined_types: struct rcache_entry { char *basepurl; long last_call; long last_time; struct table_info *tab; long oldest; long youngest; enum rcache_load_status status; }


decompiled_code:
__int64 uicollect_stopclockwork()
{
const char *v0; // rbp

v0 = (const char *)util_strjoin(iiab_dir_bin, "/killclock >/dev/null", 0LL);
elog_fprintf(
3LL,
"myhabitat/uicollect.c",
117LL,
"uicollect_stopclockwork",
"Stopping local data collection with %s",
v0);
if ( system(v0) != -1 )
return nm_nfree(v0, "myhabitat/uicollect.c", 125LL, "uicollect_stopclockwork");
elog_fprintf(
5LL,
"myhabitat/uicollect.c",
120LL,
"uicollect_stopclockwork",
"Unable to stop local data collection (attempted %s)",
v0);
return nm_nfree(v0, "myhabitat/uicollect.c", 122LL, "uicollect_stopclockwork");
}

canonical_decompiled_code:
__int64 func0()
{
const char *v0; // rbp

v0 = (const char *)util_strjoin(iiab_dir_bin, "/killclock >/dev/null", 0LL);
elog_fprintf(
3LL,
"myhabitat/uicollect.c",
117LL,
"uicollect_stopclockwork",
"Stopping local data collection with %s",
v0);
if ( system(v0) != -1 )
return nm_nfree(v0, "myhabitat/uicollect.c", 125LL, "uicollect_stopclockwork");
elog_fprintf(
5LL,
"myhabitat/uicollect.c",
120LL,
"uicollect_stopclockwork",
"Unable to stop local data collection (attempted %s)",
v0);
return nm_nfree(v0, "myhabitat/uicollect.c", 122LL, "uicollect_stopclockwork");
}

original_code:
void uicollect_stopclockwork()
{
     int r;
     char *cmd;
     cmd = util_strjoin(iiab_dir_bin, "/killclock >/dev/null", ((void *)0));
     elog_fprintf(INFO,"myhabitat/uicollect.c",117,__PRETTY_FUNCTION__,"Stopping local data collection with %s", cmd);
     r = system(cmd);
     if (r == -1) {
          elog_fprintf(ERROR,"myhabitat/uicollect.c",120,__PRETTY_FUNCTION__,"Unable to stop local data collection " "(attempted %s)", cmd);
   nm_nfree(cmd,"myhabitat/uicollect.c",122,__PRETTY_FUNCTION__);
   return;
     }
     nm_nfree(cmd,"myhabitat/uicollect.c",125,__PRETTY_FUNCTION__);
     return;
}

variable_types:
cmd
char *


decompiled_code:
_BOOL8 uicollect_is_clockwork_runable()
{
const char *v0; // rbp
int v1; // ebx

v0 = (const char *)util_strjoin(iiab_dir_bin, "/clockwork", 0LL);
elog_fprintf(
3LL,
"myhabitat/uicollect.c",
220LL,
"uicollect_is_clockwork_runable",
"Looking for %s to collect local data",
v0);
v1 = access(v0, 5);
nm_nfree(v0, "myhabitat/uicollect.c", 222LL, "uicollect_is_clockwork_runable");
return v1 == 0;
}

canonical_decompiled_code:
_BOOL8 func1()
{
const char *v0; // rbp
int v1; // ebx

v0 = (const char *)util_strjoin(iiab_dir_bin, "/clockwork", 0LL);
elog_fprintf(
3LL,
"myhabitat/uicollect.c",
220LL,
"uicollect_is_clockwork_runable",
"Looking for %s to collect local data",
v0);
v1 = access(v0, 5);
nm_nfree(v0, "myhabitat/uicollect.c", 222LL, "uicollect_is_clockwork_runable");
return v1 == 0;
}

original_code:
int uicollect_is_clockwork_runable()
{
     int noclockwork;
     char *path;
     path = util_strjoin(iiab_dir_bin, "/clockwork", ((void *)0));
     elog_fprintf(INFO,"myhabitat/uicollect.c",220,__PRETTY_FUNCTION__,"Looking for %s to collect local data", path);
     noclockwork = access(path, 4 | 1);
     nm_nfree(path,"myhabitat/uicollect.c",222,__PRETTY_FUNCTION__);
     if (noclockwork)
   return 0;
     else
   return 1;
}

variable_types: noclockwork int

variable_types:
path
char *


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

if ( !uicollect_is_clockwork_runable() )
return elog_fprintf(
6LL,
"myhabitat/uicollect.c",
102LL,
"uicollect_startclockwork",
"Can't find collector - please check installation is correct");
v0 = (const char *)util_strjoin(iiab_dir_bin, "/clockwork", 0LL);
elog_fprintf(3LL, "myhabitat/uicollect.c", 88LL, "uicollect_startclockwork", "Starting %s to collect local data", v0);
if ( system(v0) == -1 )
{
elog_fprintf(
6LL,
"myhabitat/uicollect.c",
91LL,
"uicollect_startclockwork",
"Problem starting the collector - please check installation is correct. (We tried %s.) ",
v0);
result = nm_nfree(v0, "myhabitat/uicollect.c", 94LL, "uicollect_startclockwork");
}
else
{
nm_nfree(v0, "myhabitat/uicollect.c", 97LL, "uicollect_startclockwork");
result = elog_fprintf(3LL, "myhabitat/uicollect.c", 99LL, "uicollect_startclockwork", "Now collecting local data");
}
return result;
}

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

if ( !func1() )
return elog_fprintf(
6LL,
"myhabitat/uicollect.c",
102LL,
"uicollect_startclockwork",
"Can't find collector - please check installation is correct");
v0 = (const char *)util_strjoin(iiab_dir_bin, "/clockwork", 0LL);
elog_fprintf(3LL, "myhabitat/uicollect.c", 88LL, "uicollect_startclockwork", "Starting %s to collect local data", v0);
if ( system(v0) == -1 )
{
elog_fprintf(
6LL,
"myhabitat/uicollect.c",
91LL,
"uicollect_startclockwork",
"Problem starting the collector - please check installation is correct. (We tried %s.) ",
v0);
result = nm_nfree(v0, "myhabitat/uicollect.c", 94LL, "uicollect_startclockwork");
}
else
{
nm_nfree(v0, "myhabitat/uicollect.c", 97LL, "uicollect_startclockwork");
result = elog_fprintf(3LL, "myhabitat/uicollect.c", 99LL, "uicollect_startclockwork", "Now collecting local data");
}
return result;
}

original_code:
void uicollect_startclockwork()
{
     int r;
     char *cmd;
     if (uicollect_is_clockwork_runable()) {
          cmd = util_strjoin(iiab_dir_bin, "/clockwork", ((void *)0));
   elog_fprintf(INFO,"myhabitat/uicollect.c",88,__PRETTY_FUNCTION__,"Starting %s to collect local data", cmd);
   r = system(cmd);
   if (r == -1) {
        elog_fprintf(FATAL,"myhabitat/uicollect.c",91,__PRETTY_FUNCTION__,"Problem starting the collector - please " "check installation is correct. (We tried %s.) ", cmd);
        nm_nfree(cmd,"myhabitat/uicollect.c",94,__PRETTY_FUNCTION__);
        return;
   }
   nm_nfree(cmd,"myhabitat/uicollect.c",97,__PRETTY_FUNCTION__);
   elog_fprintf(INFO,"myhabitat/uicollect.c",99,__PRETTY_FUNCTION__,"Now collecting local data");
   return;
     } else {
          elog_fprintf(FATAL,"myhabitat/uicollect.c",102,__PRETTY_FUNCTION__,"Can't find collector - please check " "installation is correct");
     }
     return;
}


decompiled_code:
__int64 __fastcall uicollect_is_clockwork_running(_QWORD *a1, const char **a2, __int64 a3, const char **a4, int a5)
{
unsigned int v7; // eax
__int64 v8; // r12
const char *v10; // rdx
const char *v11; // rax

if ( a1 )
*a1 = "clockwork";
v7 = iiab_getlockpid("clockwork", a2, a3, a4);
v8 = v7;
if ( !v7 )
goto LABEL_4;
if ( !(unsigned int)iiab_ispidrunning(v7) )
{
if ( a5 )
{
v10 = "(unknown)";
if ( a4 )
v10 = *a4;
v11 = "(unknown)";
if ( a2 )
v11 = *a2;
elog_fprintf(
5LL,
"myhabitat/uicollect.c",
187LL,
"uicollect_is_clockwork_running",
"The collector has crashed and the debris will be cleaned up by re-runnng it (was %s on pid %d started by %s at %s.",
"clockwork",
v8,
v11,
v10);
uilog_modal_alert(
"<big><b>Local Collector has Crashed</b></big>",
"The local data collector had crashed sometime in the past and will need to be restarted");
}
LABEL_4:
uicollect_set_status_not_collecting();
return 0LL;
}
uicollect_set_status_collecting();
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, const char **a2, __int64 a3, const char **a4, int a5)
{
unsigned int v7; // eax
__int64 v8; // r12
const char *v10; // rdx
const char *v11; // rax

if ( a1 )
*a1 = "clockwork";
v7 = iiab_getlockpid("clockwork", a2, a3, a4);
v8 = v7;
if ( !v7 )
goto LABEL_4;
if ( !(unsigned int)iiab_ispidrunning(v7) )
{
if ( a5 )
{
v10 = "(unknown)";
if ( a4 )
v10 = *a4;
v11 = "(unknown)";
if ( a2 )
v11 = *a2;
elog_fprintf(
5LL,
"myhabitat/uicollect.c",
187LL,
"uicollect_is_clockwork_running",
"The collector has crashed and the debris will be cleaned up by re-runnng it (was %s on pid %d started by %s at %s.",
"clockwork",
v8,
v11,
v10);
uilog_modal_alert(
"<big><b>Local Collector has Crashed</b></big>",
"The local data collector had crashed sometime in the past and will need to be restarted");
}
LABEL_4:
func3();
return 0LL;
}
func4();
return (unsigned int)v8;
}

original_code:
int uicollect_is_clockwork_running(char **key, char **user, char **tty,
       char **datestr, int giveerror)
{
     int pid;
     if (key)
          *key = "clockwork";
     pid = iiab_getlockpid("clockwork", user, tty, datestr);
     if (pid) {
          if ( ! iiab_ispidrunning(pid) ) {
        if (giveerror) {
      elog_fprintf(ERROR,"myhabitat/uicollect.c",187,__PRETTY_FUNCTION__,"The collector has crashed and the " "debris will be cleaned up by re-runnng it " "(was %s on pid %d started by %s at %s.", "clockwork", pid, user?*user:"(unknown)", datestr?*datestr:"(unknown)");
      uilog_modal_alert("<big><b>Local Collector has "
          "Crashed</b></big>",
          "The local data collector had crashed "
          "sometime in the past and will need to "
          "be restarted");
        }
        pid = 0;
   }
     }
     if (pid)
          uicollect_set_status_collecting();
     else
          uicollect_set_status_not_collecting();
     return pid;
}

variable_types:
key
char **

variable_types:
user
char **

variable_types:
tty
char **

variable_types:
datestr
char **

variable_types: giveerror int

variable_types: pid int


decompiled_code:
__int64 cmdln_do_exit()
{
cmdln_done = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
cmdln_done = 1;
return 0LL;
}

original_code:
int cmdln_do_exit() {
     cmdln_done = 1;
     return 0;
}


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

if ( a2 )
result = 0LL;
else
result = rl_completion_matches(a1, cmdln_cmdgenerator);
return result;
}

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

if ( a2 )
result = 0LL;
else
result = rl_completion_matches(a1, cmdln_cmdgenerator);
return result;
}

original_code:
char **cmdln_completion (char *text, int start, int end)
{
     char **matches;
     matches = (char **)((void *)0);
     if (start == 0)
          matches = rl_completion_matches (text, cmdln_cmdgenerator);
     return (matches);
}

canonical_original_code:
char **cmdln_completion(char *text, int start, int end)
{
     char **matches;
     matches = (char **)((void *)0);
     if (start == 0)
          matches = rl_completion_matches (text, cmdln_cmdgenerator);
     return (matches);
}

variable_types:
text
char *

variable_types: start int

variable_types: end int

variable_types:
matches
char **

return_type: char **


decompiled_code:
char *__fastcall cmdln_cmdgenerator(char *s2, int a2)
{
_QWORD *v2; // rbp
int v3; // eax
_QWORD *v4; // rdx
_QWORD *v5; // rax
__int64 v7; // rax
const char **v8; // rax
const char *v9; // rbp
const char **v10; // rax

v2 = cmdln_commands;
if ( !a2 )
{
v3 = strlen(s2);
v4 = (_QWORD *)*v2;
len_0 = v3;
v5 = (_QWORD *)*v4;
v2[1] = *v4;
if ( v4 == v5 )
return 0LL;
while ( 1 )
{
v8 = (const char **)tree_get(v2);
v9 = *v8;
if ( !strncmp(*v8, s2, len_0) )
break;
v2 = cmdln_commands;
v7 = *(_QWORD *)cmdln_commands[1];
cmdln_commands[1] = v7;
if ( v7 == *v2 )
return 0LL;
}
return strdup(v9);
}
if ( *cmdln_commands == *(_QWORD *)cmdln_commands[1] )
return 0LL;
tree_next(cmdln_commands);
v10 = (const char **)tree_get(cmdln_commands);
v9 = *v10;
if ( !strncmp(*v10, s2, len_0) )
return strdup(v9);
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func2(char *s2, int a2)
{
_QWORD *v2; // rbp
int v3; // eax
_QWORD *v4; // rdx
_QWORD *v5; // rax
__int64 v7; // rax
const char **v8; // rax
const char *v9; // rbp
const char **v10; // rax

v2 = cmdln_commands;
if ( !a2 )
{
v3 = strlen(s2);
v4 = (_QWORD *)*v2;
len_0 = v3;
v5 = (_QWORD *)*v4;
v2[1] = *v4;
if ( v4 == v5 )
return 0LL;
while ( 1 )
{
v8 = (const char **)tree_get(v2);
v9 = *v8;
if ( !strncmp(*v8, s2, len_0) )
break;
v2 = cmdln_commands;
v7 = *(_QWORD *)cmdln_commands[1];
cmdln_commands[1] = v7;
if ( v7 == *v2 )
return 0LL;
}
return strdup(v9);
}
if ( *cmdln_commands == *(_QWORD *)cmdln_commands[1] )
return 0LL;
tree_next(cmdln_commands);
v10 = (const char **)tree_get(cmdln_commands);
v9 = *v10;
if ( !strncmp(*v10, s2, len_0) )
return strdup(v9);
return 0LL;
}

original_code:
char *cmdln_cmdgenerator (const char *text, int state)
{
     static int len;
     struct cmdln_def *cmd;
     if (!state) {
   len = strlen(text);
   for((cmdln_commands)->node = ((cmdln_commands)->root->c.list.flink); (cmdln_commands)->node != ((cmdln_commands)->root); (cmdln_commands)->node = ((cmdln_commands)->node->c.list.flink)) {
        cmd = tree_get(cmdln_commands);
        if (strncmp(cmd->name, text, len) == 0)
      return (strdup(cmd->name));
   }
     } else {
   if (!((cmdln_commands)->root==(cmdln_commands)->node->c.list.flink)) {
        tree_next(cmdln_commands);
        cmd = tree_get(cmdln_commands);
        if (strncmp(cmd->name, text, len) == 0)
      return (strdup(cmd->name));
   }
     }
     return ((char *)((void *)0));
}

canonical_original_code:
char *cmdln_cmdgenerator(char *text, int state)
{
     static int len;
     struct cmdln_def *cmd;
     if (!state) {
   len = strlen(text);
   for((cmdln_commands)->node = ((cmdln_commands)->root->c.list.flink); (cmdln_commands)->node != ((cmdln_commands)->root); (cmdln_commands)->node = ((cmdln_commands)->node->c.list.flink)) {
        cmd = tree_get(cmdln_commands);
        if (strncmp(cmd->name, text, len) == 0)
      return (strdup(cmd->name));
   }
     } else {
   if (!((cmdln_commands)->root==(cmdln_commands)->node->c.list.flink)) {
        tree_next(cmdln_commands);
        cmd = tree_get(cmdln_commands);
        if (strncmp(cmd->name, text, len) == 0)
      return (strdup(cmd->name));
   }
     }
     return ((char *)((void *)0));
}

variable_types: state int

variable_types: len int

variable_types: struct cmdln_def { char *name; int (*func)(int, char **); char *help; } *


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

tree_really_destroy(cmdln_commands, "trm/cmdln.c", 70LL, "cmdln_fini");
result = &cmdln_prompt;
if ( cmdln_prompt )
result = (_QWORD *)nm_nfree(cmdln_prompt, "trm/cmdln.c", 72LL, "cmdln_fini");
return result;
}

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

tree_really_destroy(cmdln_commands, "trm/cmdln.c", 70LL, "cmdln_fini");
result = &cmdln_prompt;
if ( cmdln_prompt )
result = (_QWORD *)nm_nfree(cmdln_prompt, "trm/cmdln.c", 72LL, "cmdln_fini");
return result;
}

original_code:
void cmdln_fini() {
     tree_really_destroy(cmdln_commands,"trm/cmdln.c",70,__PRETTY_FUNCTION__);
     if (cmdln_prompt)
   nm_nfree(cmdln_prompt,"trm/cmdln.c",72,__PRETTY_FUNCTION__);
}


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

if ( cmdln_prompt )
nm_nfree(cmdln_prompt, "trm/cmdln.c", 79LL, "cmdln_setprompt");
result = nm_xnstrdup(a1, "trm/cmdln.c", 80LL, "cmdln_setprompt");
cmdln_prompt = result;
return result;
}

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

if ( cmdln_prompt )
nm_nfree(cmdln_prompt, "trm/cmdln.c", 79LL, "cmdln_setprompt");
result = nm_xnstrdup(a1, "trm/cmdln.c", 80LL, "cmdln_setprompt");
cmdln_prompt = result;
return result;
}

original_code:
void cmdln_setprompt(char *newprompt)
{
     if (cmdln_prompt)
   nm_nfree(cmdln_prompt,"trm/cmdln.c",79,__PRETTY_FUNCTION__);
     cmdln_prompt = nm_xnstrdup(newprompt,"trm/cmdln.c",80,__PRETTY_FUNCTION__);
}

variable_types:
newprompt
char *


decompiled_code:
__int64 __fastcall cmdln_addcommand(_QWORD *a1)
{
_QWORD *v1; // rbx
_BYTE *i; // rsi
_QWORD *v3; // rdx
__int64 result; // rax

if ( a1 )
{
v1 = a1;
for ( i = (_BYTE *)*a1; *(_BYTE *)*v1; i = (_BYTE *)*v1 )
{
v3 = v1;
v1 += 3;
result = tree_add(cmdln_commands, i, v3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
_QWORD *v1; // rbx
_BYTE *i; // rsi
_QWORD *v3; // rdx
__int64 result; // rax

if ( a1 )
{
v1 = a1;
for ( i = (_BYTE *)*a1; *(_BYTE *)*v1; i = (_BYTE *)*v1 )
{
v3 = v1;
v1 += 3;
result = tree_add(cmdln_commands, i, v3);
}
}
return result;
}

original_code:
void cmdln_addcommand(struct cmdln_def *command )
{
     struct cmdln_def *c;
     if (!command)
   return;
     c = command;
     while (*c->name != '\0') {
   tree_add(cmdln_commands, c->name, c);
   c++;
     }
}

canonical_original_code:
void cmdln_addcommand(struct cmdln_def *command)
{
     struct cmdln_def *c;
     if (!command)
   return;
     c = command;
     while (*c->name != '\0') {
   tree_add(cmdln_commands, c->name, c);
   c++;
     }
}

user_defined_types: struct cmdln_def { char *name; int (*func)(int, char **); char *help; }


decompiled_code:
__int64 __fastcall cmdln_rmcommand(__int64 a1)
{
__int64 v1; // r8
__int64 result; // rax

v1 = tree_find(cmdln_commands, a1);
result = 0LL;
if ( v1 != -1 )
{
tree_rm(cmdln_commands);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // r8
__int64 result; // rax

v1 = tree_find(cmdln_commands, a1);
result = 0LL;
if ( v1 != -1 )
{
tree_rm(cmdln_commands);
result = 1LL;
}
return result;
}

original_code:
int cmdln_rmcommand(char *command )
{
     struct cmdln_def *cmd;
     cmd = tree_find(cmdln_commands, command);
     if (cmd == (void *) -1)
   return 0;
     tree_rm(cmdln_commands);
     return 1;
}

canonical_original_code:
int cmdln_rmcommand(char *command)
{
     struct cmdln_def *cmd;
     cmd = tree_find(cmdln_commands, command);
     if (cmd == (void *) -1)
   return 0;
     tree_rm(cmdln_commands);
     return 1;
}

variable_types:
command
char *


decompiled_code:
__int64 __fastcall cmdln_findcommand(__int64 a1)
{
return tree_find(cmdln_commands, a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return tree_find(cmdln_commands, a1);
}

original_code:
struct cmdln_def *cmdln_findcommand(char *name )
{
     return tree_find(cmdln_commands, name);
}

canonical_original_code:
struct cmdln_def *cmdln_findcommand(char *name)
{
     return tree_find(cmdln_commands, name);
}

variable_types:
name
char *

return_type: struct cmdln_def { char *name; int (*func)(int, char **); char *help; } *


decompiled_code:
__int64 __fastcall cmdln_tabulate(const char *a1)
{
int v1; // eax
__int64 v2; // rax

if ( !cmdln_tablist )
return elog_fprintf(5LL, "trm/cmdln.c", 157LL, "cmdln_tabulate", "cmdln_tabulate()", 0LL, "list not set\n");
v1 = strlen(a1);
if ( cmdln_tabwidest < v1 )
cmdln_tabwidest = v1;
v2 = nm_xnstrdup(a1, "trm/cmdln.c", 164LL, "cmdln_tabulate");
return itree_append(cmdln_tablist, v2);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
int v1; // eax
__int64 v2; // rax

if ( !cmdln_tablist )
return elog_fprintf(5LL, "trm/cmdln.c", 157LL, "cmdln_tabulate", "cmdln_tabulate()", 0LL, "list not set\n");
v1 = strlen(a1);
if ( cmdln_tabwidest < v1 )
cmdln_tabwidest = v1;
v2 = nm_xnstrdup(a1, "trm/cmdln.c", 164LL, "cmdln_tabulate");
return itree_append(cmdln_tablist, v2);
}

original_code:
void cmdln_tabulate(char *token)
{
     int l;
     if ( ! cmdln_tablist) {
          elog_fprintf(ERROR,"trm/cmdln.c",157,__PRETTY_FUNCTION__,"cmdln_tabulate()", 0, "list not set\n");
   return;
     }
     l = strlen(token);
     if (l > cmdln_tabwidest)
   cmdln_tabwidest = l;
     itree_append(cmdln_tablist, nm_xnstrdup(token,"trm/cmdln.c",164,__PRETTY_FUNCTION__));
     return;
}

variable_types:
token
char *

variable_types: l int


decompiled_code:
__int64 cmdln_freetablist()
{
_QWORD *v0; // rdi
__int64 v1; // rdx
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 result; // rax

v0 = cmdln_tablist;
v1 = *cmdln_tablist;
v2 = *(_QWORD *)*cmdln_tablist;
cmdln_tablist[1] = v2;
if ( v1 != v2 )
{
do
{
v3 = itree_get();
nm_nfree(v3, "trm/cmdln.c", 204LL, "cmdln_freetablist");
v0 = cmdln_tablist;
v4 = *(_QWORD *)cmdln_tablist[1];
cmdln_tablist[1] = v4;
}
while ( v4 != *v0 );
}
result = itree_really_destroy(v0, "trm/cmdln.c", 205LL, "cmdln_freetablist");
cmdln_tablist = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func9()
{
_QWORD *v0; // rdi
__int64 v1; // rdx
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 result; // rax

v0 = cmdln_tablist;
v1 = *cmdln_tablist;
v2 = *(_QWORD *)*cmdln_tablist;
cmdln_tablist[1] = v2;
if ( v1 != v2 )
{
do
{
v3 = itree_get();
nm_nfree(v3, "trm/cmdln.c", 204LL, "cmdln_freetablist");
v0 = cmdln_tablist;
v4 = *(_QWORD *)cmdln_tablist[1];
cmdln_tablist[1] = v4;
}
while ( v4 != *v0 );
}
result = itree_really_destroy(v0, "trm/cmdln.c", 205LL, "cmdln_freetablist");
cmdln_tablist = 0LL;
return result;
}

original_code:
void cmdln_freetablist()
{
     for((cmdln_tablist)->node = ((cmdln_tablist)->root->c.list.flink); (cmdln_tablist)->node != ((cmdln_tablist)->root); (cmdln_tablist)->node = ((cmdln_tablist)->node->c.list.flink))
   nm_nfree(itree_get(cmdln_tablist),"trm/cmdln.c",204,__PRETTY_FUNCTION__);
     itree_really_destroy(cmdln_tablist,"trm/cmdln.c",205,__PRETTY_FUNCTION__);
     cmdln_tablist = ((void *)0);
}


decompiled_code:
_DWORD *cmdln_begintabulate()
{
_DWORD *result; // rax

if ( cmdln_tablist )
{
elog_fprintf(
5LL,
"trm/cmdln.c",
142LL,
"cmdln_begintabulate",
"cmdln_begintabulate()",
0LL,
"list shouldn't exist!\n");
cmdln_freetablist();
}
cmdln_tablist = (_QWORD *)itree_really_create("trm/cmdln.c", 147LL, "cmdln_begintabulate");
result = cmdln_tabwidest;
cmdln_tabwidest[0] = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func10()
{
_DWORD *result; // rax

if ( cmdln_tablist )
{
elog_fprintf(
5LL,
"trm/cmdln.c",
142LL,
"cmdln_begintabulate",
"cmdln_begintabulate()",
0LL,
"list shouldn't exist!\n");
func9();
}
cmdln_tablist = (_QWORD *)itree_really_create("trm/cmdln.c", 147LL, "cmdln_begintabulate");
result = cmdln_tabwidest;
cmdln_tabwidest[0] = 0;
return result;
}

original_code:
void cmdln_begintabulate()
{
     if (cmdln_tablist) {
          elog_fprintf(ERROR,"trm/cmdln.c",142,__PRETTY_FUNCTION__,"cmdln_begintabulate()", 0, "list shouldn't exist!\n");
   cmdln_freetablist();
     }
     cmdln_tablist = itree_really_create("trm/cmdln.c",147,__PRETTY_FUNCTION__);
     cmdln_tabwidest = 0;
}


decompiled_code:
__int64 cmdln_endtabulate()
{
int v0; // ebx
__int64 v1; // rdx
__int64 v2; // rax
int v3; // er13
_QWORD *v4; // rdi
__int64 v5; // rax
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp-10h] [rbp-48h]
char s[50]; // [rsp+6h] [rbp-32h] BYREF

if ( cmdln_tablist )
{
v0 = 80 / (cmdln_tabwidest[0] + 2);
sprintf(s, "%%-%ds", (unsigned int)(cmdln_tabwidest[0] + 2));
v1 = *cmdln_tablist;
v2 = *(_QWORD *)*cmdln_tablist;
cmdln_tablist[1] = v2;
if ( v1 != v2 )
{
v3 = 0;
do
{
v6 = itree_get();
++v3;
printf(s, v6);
if ( v0 <= v3 )
{
v3 = 0;
putchar(10);
}
v4 = cmdln_tablist;
v5 = *(_QWORD *)cmdln_tablist[1];
cmdln_tablist[1] = v5;
}
while ( v5 != *v4 );
if ( v3 )
putchar(10);
}
result = cmdln_freetablist();
}
else
{
elog_fprintf(5LL, "trm/cmdln.c", 176LL, "cmdln_endtabulate", "cmdln_endtabulate()", 0LL, "list not set\n");
result = v8;
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // ebx
__int64 v1; // rdx
__int64 v2; // rax
int v3; // er13
_QWORD *v4; // rdi
__int64 v5; // rax
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp-10h] [rbp-48h]
char s[50]; // [rsp+6h] [rbp-32h] BYREF

if ( cmdln_tablist )
{
v0 = 80 / (cmdln_tabwidest[0] + 2);
sprintf(s, "%%-%ds", (unsigned int)(cmdln_tabwidest[0] + 2));
v1 = *cmdln_tablist;
v2 = *(_QWORD *)*cmdln_tablist;
cmdln_tablist[1] = v2;
if ( v1 != v2 )
{
v3 = 0;
do
{
v6 = itree_get();
++v3;
printf(s, v6);
if ( v0 <= v3 )
{
v3 = 0;
putchar(10);
}
v4 = cmdln_tablist;
v5 = *(_QWORD *)cmdln_tablist[1];
cmdln_tablist[1] = v5;
}
while ( v5 != *v4 );
if ( v3 )
putchar(10);
}
result = func9();
}
else
{
elog_fprintf(5LL, "trm/cmdln.c", 176LL, "cmdln_endtabulate", "cmdln_endtabulate()", 0LL, "list not set\n");
result = v8;
}
return result;
}

original_code:
void cmdln_endtabulate()
{
     int i, ncols;
     char format[10];
     if ( ! cmdln_tablist) {
          elog_fprintf(ERROR,"trm/cmdln.c",176,__PRETTY_FUNCTION__,"cmdln_endtabulate()", 0, "list not set\n");
   return;
     }
     ncols = 80 / (cmdln_tabwidest+2);
     sprintf(format, "%%-%ds", cmdln_tabwidest+2);
     i = 0;
     for((cmdln_tablist)->node = ((cmdln_tablist)->root->c.list.flink); (cmdln_tablist)->node != ((cmdln_tablist)->root); (cmdln_tablist)->node = ((cmdln_tablist)->node->c.list.flink)) {
   printf(format, itree_get(cmdln_tablist));
   if (++i >= ncols) {
        printf("\n");
        i = 0;
   }
     }
     if (i)
   printf("\n");
     cmdln_freetablist();
     return;
}

canonical_original_code:
void cmdln_endtabulate()
{
     int i; int ncols;
     char format[10];
     if ( ! cmdln_tablist) {
          elog_fprintf(ERROR,"trm/cmdln.c",176,__PRETTY_FUNCTION__,"cmdln_endtabulate()", 0, "list not set\n");
   return;
     }
     ncols = 80 / (cmdln_tabwidest+2);
     sprintf(format, "%%-%ds", cmdln_tabwidest+2);
     i = 0;
     for((cmdln_tablist)->node = ((cmdln_tablist)->root->c.list.flink); (cmdln_tablist)->node != ((cmdln_tablist)->root); (cmdln_tablist)->node = ((cmdln_tablist)->node->c.list.flink)) {
   printf(format, itree_get(cmdln_tablist));
   if (++i >= ncols) {
        printf("\n");
        i = 0;
   }
     }
     if (i)
   printf("\n");
     cmdln_freetablist();
     return;
}

variable_types: i int

variable_types: ncols int

variable_types:
format
char [10]


decompiled_code:
__int64 __fastcall cmdln_do_help(int a1, __int64 a2)
{
const char **v2; // rbx
__int64 v3; // r12
const char **v4; // rax
const char *v5; // rsi
__int64 result; // rax
__int64 v7; // rdx
__int64 v8; // rax
const char *v9; // rax
_QWORD *v10; // rdi
__int64 v11; // rax

if ( a1 <= 1 )
{
cmdln_begintabulate();
v7 = *cmdln_commands;
v8 = *(_QWORD *)*cmdln_commands;
cmdln_commands[1] = v8;
if ( v7 != v8 )
{
do
{
v9 = (const char *)tree_getkey();
cmdln_tabulate(v9);
v10 = cmdln_commands;
v11 = *(_QWORD *)cmdln_commands[1];
cmdln_commands[1] = v11;
}
while ( v11 != *v10 );
}
cmdln_endtabulate();
puts("^P/^N-previous/next line ^F/^B-forward/backward char <tab>-complete command");
result = 0LL;
}
else
{
v2 = (const char **)(a2 + 8);
v3 = a2 + 8LL * (unsigned int)(a1 - 2) + 16;
do
{
while ( 1 )
{
v4 = (const char **)tree_find(cmdln_commands, *v2);
if ( v4 == (const char **)-1LL )
break;
++v2;
printf("%s\t\t%s\n", *v4, v4[2]);
if ( v2 == (const char **)v3 )
goto LABEL_6;
}
v5 = *v2++;
printf("Can't help; command does not exist: %s\n", v5);
}
while ( v2 != (const char **)v3 );
LABEL_6:
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, __int64 a2)
{
const char **v2; // rbx
__int64 v3; // r12
const char **v4; // rax
const char *v5; // rsi
__int64 result; // rax
__int64 v7; // rdx
__int64 v8; // rax
const char *v9; // rax
_QWORD *v10; // rdi
__int64 v11; // rax

if ( a1 <= 1 )
{
func10();
v7 = *cmdln_commands;
v8 = *(_QWORD *)*cmdln_commands;
cmdln_commands[1] = v8;
if ( v7 != v8 )
{
do
{
v9 = (const char *)tree_getkey();
func8(v9);
v10 = cmdln_commands;
v11 = *(_QWORD *)cmdln_commands[1];
cmdln_commands[1] = v11;
}
while ( v11 != *v10 );
}
func11();
puts("^P/^N-previous/next line ^F/^B-forward/backward char <tab>-complete command");
result = 0LL;
}
else
{
v2 = (const char **)(a2 + 8);
v3 = a2 + 8LL * (unsigned int)(a1 - 2) + 16;
do
{
while ( 1 )
{
v4 = (const char **)tree_find(cmdln_commands, *v2);
if ( v4 == (const char **)-1LL )
break;
++v2;
printf("%s\t\t%s\n", *v4, v4[2]);
if ( v2 == (const char **)v3 )
goto LABEL_6;
}
v5 = *v2++;
printf("Can't help; command does not exist: %s\n", v5);
}
while ( v2 != (const char **)v3 );
LABEL_6:
result = 0LL;
}
return result;
}

original_code:
int cmdln_do_help(int argc, char **argv) {
     int i;
     struct cmdln_def *cmd;
     if (argc < 2) {
   cmdln_begintabulate();
   for((cmdln_commands)->node = ((cmdln_commands)->root->c.list.flink); (cmdln_commands)->node != ((cmdln_commands)->root); (cmdln_commands)->node = ((cmdln_commands)->node->c.list.flink))
        cmdln_tabulate(tree_getkey(cmdln_commands));
   cmdln_endtabulate();
   printf("^P/^N-previous/next line   ^F/^B-forward/backward char   <tab>-complete command\n");
     } else {
   for (i=1; i<argc; i++) {
        if ((cmd = tree_find(cmdln_commands, argv[i])) == (void *) -1)
      printf("Can't help; command does not exist: %s\n",argv[i]);
        else {
      printf("%s\t\t%s\n", cmd->name, cmd->help);
        }
   }
     }
     return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall cmdln_joinargs(char *s, int a2, __int64 a3, const char *a4, int a5)
{
unsigned __int64 v7; // r13
__int64 v8; // rbx
size_t v9; // rax
char *v10; // rax

*s = 0;
if ( a5 >= a2 )
return 0LL;
v7 = a3 + 8 * (a5 + (unsigned __int64)(unsigned int)(a2 - 1 - a5)) + 8;
v8 = a3 + 8LL * a5;
do
{
v8 += 8LL;
v9 = strlen(s);
v10 = stpcpy(&s[v9], *(const char **)(v8 - 8));
strcpy(v10, a4);
}
while ( v8 != v7 );
return (unsigned int)(a2 - a5);
}

canonical_decompiled_code:
__int64 __fastcall func13(char *s, int a2, __int64 a3, const char *a4, int a5)
{
unsigned __int64 v7; // r13
__int64 v8; // rbx
size_t v9; // rax
char *v10; // rax

*s = 0;
if ( a5 >= a2 )
return 0LL;
v7 = a3 + 8 * (a5 + (unsigned __int64)(unsigned int)(a2 - 1 - a5)) + 8;
v8 = a3 + 8LL * a5;
do
{
v8 += 8LL;
v9 = strlen(s);
v10 = stpcpy(&s[v9], *(const char **)(v8 - 8));
strcpy(v10, a4);
}
while ( v8 != v7 );
return (unsigned int)(a2 - a5);
}

original_code:
int cmdln_joinargs(char *buf,
     int fargc,
     char *fargv[],
     char *conj,
     int from )
{
     int i;
     *buf = '\0';
     for (i=from; i<fargc; i++) {
   strcat(buf, fargv[i]);
   strcat(buf, conj);
     }
     return (i-from < 0 ? 0 : i-from);
}

canonical_original_code:
int cmdln_joinargs(char *buf, int fargc, char *fargv[], char *conj, int from)
{
     int i;
     *buf = '\0';
     for (i=from; i<fargc; i++) {
   strcat(buf, fargv[i]);
   strcat(buf, conj);
     }
     return (i-from < 0 ? 0 : i-from);
}

variable_types:
buf
char *

variable_types: fargc int

variable_types:
fargv
char *[]

variable_types:
conj
char *

variable_types: from int


decompiled_code:
__int64 __fastcall cmdln_do_shell(int a1, __int64 a2)
{
unsigned int v2; // eax
__int64 result; // rax
unsigned int v4; // eax
_BYTE savedregs[264]; // [rsp+0h] [rbp+0h] BYREF

if ( (int)cmdln_joinargs(savedregs, a1, a2, " ", 1) <= 0 )
{
v4 = system("/bin/sh");
if ( !v4 )
return 0LL;
printf("Command returned error: %d\n", v4);
result = 0LL;
}
else
{
v2 = system(savedregs);
if ( !v2 )
return 0LL;
printf("Command status: %d\n", v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, __int64 a2)
{
unsigned int v2; // eax
__int64 result; // rax
unsigned int v4; // eax
_BYTE savedregs[264]; // [rsp+0h] [rbp+0h] BYREF

if ( (int)func13(savedregs, a1, a2, " ", 1) <= 0 )
{
v4 = system("/bin/sh");
if ( !v4 )
return 0LL;
printf("Command returned error: %d\n", v4);
result = 0LL;
}
else
{
v2 = system(savedregs);
if ( !v2 )
return 0LL;
printf("Command status: %d\n", v2);
result = 0LL;
}
return result;
}

original_code:
int cmdln_do_shell(int argc, char **argv) {
     char buf[250];
     int r;
     r = cmdln_joinargs(buf, argc, argv, " ", 1);
     if (r > 0) {
   r = system(buf);
   if (r)
        printf("Command status: %d\n", r);
     } else {
   r = system("/bin/sh");
   if (r)
        printf("Command returned error: %d\n", r);
     }
     return 0;
}

variable_types:
buf
char [250]

variable_types: r int


decompiled_code:
__int64 __fastcall cmdln_parse(const char *a1)
{
unsigned int v1; // er12
int v2; // er15
const unsigned __int16 **v3; // rax
__int64 v4; // rdx
char v5; // r14
const char *v6; // rbp
int v7; // er13
int v9; // [rsp+14h] [rbp-54h]
char v10[58]; // [rsp+2Eh] [rbp-3Ah] BYREF

v1 = 0;
cmdln_argc[0] = 0;
if ( *a1 )
{
v10[1] = 0;
v9 = strlen(a1);
if ( v9 > 0 )
{
v2 = 0;
while ( 1 )
{
v6 = &a1[v2];
v10[0] = 0;
v7 = strcspn(v6, " \"'\t\n");
if ( v7 )
break;
v3 = _ctype_b_loc();
v4 = *v6;
++v2;
v5 = *v6;
if ( ((*v3)[v4] & 0x2000) == 0 )
{
v6 = &a1[v2];
v10[0] = v4;
v7 = strcspn(v6, v10);
LABEL_6:
*((_QWORD *)&cmdln_argv + (int)v1) = nm_xnmalloc(v7 + 1, "trm/cmdln.c", 302LL, "cmdln_parse");
strncpy(*((char **)&cmdln_argv + cmdln_argc[0]), v6, v7);
v2 = v7 + v2 - ((v5 == 0) - 1);
*(_BYTE *)(*((_QWORD *)&cmdln_argv + cmdln_argc[0]) + v7) = 0;
v1 = ++cmdln_argc[0];
}
if ( v2 >= v9 )
return v1;
}
v5 = 0;
goto LABEL_6;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func15(const char *a1)
{
unsigned int v1; // er12
int v2; // er15
const unsigned __int16 **v3; // rax
__int64 v4; // rdx
char v5; // r14
const char *v6; // rbp
int v7; // er13
int v9; // [rsp+14h] [rbp-54h]
char v10[58]; // [rsp+2Eh] [rbp-3Ah] BYREF

v1 = 0;
cmdln_argc[0] = 0;
if ( *a1 )
{
v10[1] = 0;
v9 = strlen(a1);
if ( v9 > 0 )
{
v2 = 0;
while ( 1 )
{
v6 = &a1[v2];
v10[0] = 0;
v7 = strcspn(v6, " \"'\t\n");
if ( v7 )
break;
v3 = _ctype_b_loc();
v4 = *v6;
++v2;
v5 = *v6;
if ( ((*v3)[v4] & 0x2000) == 0 )
{
v6 = &a1[v2];
v10[0] = v4;
v7 = strcspn(v6, v10);
LABEL_6:
*((_QWORD *)&cmdln_argv + (int)v1) = nm_xnmalloc(v7 + 1, "trm/cmdln.c", 302LL, "cmdln_parse");
strncpy(*((char **)&cmdln_argv + cmdln_argc[0]), v6, v7);
v2 = v7 + v2 - ((v5 == 0) - 1);
*(_BYTE *)(*((_QWORD *)&cmdln_argv + cmdln_argc[0]) + v7) = 0;
v1 = ++cmdln_argc[0];
}
if ( v2 >= v9 )
return v1;
}
v5 = 0;
goto LABEL_6;
}
}
return v1;
}

original_code:
int cmdln_parse(char *cmdline )
{
     char quote[2];
     int span, i=0, nchars=0;
     cmdln_argc = 0;
     if (*cmdline == '\0')
   return cmdln_argc;
     quote[1] = '\0';
     nchars = strlen(cmdline);
     while (i < nchars) {
   quote[0] = 0;
   span = strcspn(cmdline+i, " \"\'\t\n");
   if (span == 0) {
        if (((*__ctype_b_loc ())[(int) ((cmdline[i]))] & (unsigned short int) _ISspace)) {
      i++;
      continue;
        }
        quote[0] = cmdline[i++];
        span = strcspn(cmdline+i, quote);
   }
   cmdln_argv[cmdln_argc] = nm_xnmalloc(span+1,"trm/cmdln.c",302,__PRETTY_FUNCTION__);
   strncpy(cmdln_argv[cmdln_argc], cmdline+i, span);
   *(cmdln_argv[cmdln_argc]+span) = '\0';
   cmdln_argc++;
   i += span;
   if (quote[0])
        i++;
     }
     return cmdln_argc;
}

canonical_original_code:
int cmdln_parse(char *cmdline)
{
     char quote[2];
     int span; int i = 0; int nchars = 0;
     cmdln_argc = 0;
     if (*cmdline == '\0')
   return cmdln_argc;
     quote[1] = '\0';
     nchars = strlen(cmdline);
     while (i < nchars) {
   quote[0] = 0;
   span = strcspn(cmdline+i, " \"\'\t\n");
   if (span == 0) {
        if (((*__ctype_b_loc ())[(int) ((cmdline[i]))] & (unsigned short) _ISspace)) {
      i++;
      continue;
        }
        quote[0] = cmdline[i++];
        span = strcspn(cmdline+i, quote);
   }
   cmdln_argv[cmdln_argc] = nm_xnmalloc(span+1,"trm/cmdln.c",302,__PRETTY_FUNCTION__);
   strncpy(cmdln_argv[cmdln_argc], cmdline+i, span);
   *(cmdln_argv[cmdln_argc]+span) = '\0';
   cmdln_argc++;
   i += span;
   if (quote[0])
        i++;
     }
     return cmdln_argc;
}

variable_types:
cmdline
char *

variable_types:
quote
char [2]

variable_types: span int

variable_types: nchars int


decompiled_code:
void __fastcall cmdln_run(int a1, const char **a2)
{
__int64 v2; // rax
const char **v3; // rbx
__int64 v4; // r12
const char *v5; // rsi

if ( a1 )
{
v2 = tree_find(cmdln_commands, *a2);
if ( v2 == -1 )
{
if ( !cmdln_lastresort
|| (unsigned int)((__int64 (__fastcall *)(_QWORD, const char **))cmdln_lastresort)((unsigned int)a1, a2) )
{
printf("Unknown command:");
if ( a1 > 0 )
{
v3 = a2;
v4 = (__int64)&a2[(unsigned int)(a1 - 1) + 1];
do
{
v5 = *v3++;
printf(" %s", v5);
}
while ( v3 != (const char **)v4 );
}
putchar(10);
}
}
else
{
(*(void (__fastcall **)(_QWORD, const char **))(v2 + 8))((unsigned int)a1, a2);
}
}
}

canonical_decompiled_code:
void __fastcall func16(int a1, const char **a2)
{
__int64 v2; // rax
const char **v3; // rbx
__int64 v4; // r12
const char *v5; // rsi

if ( a1 )
{
v2 = tree_find(cmdln_commands, *a2);
if ( v2 == -1 )
{
if ( !cmdln_lastresort
|| (unsigned int)((__int64 (__fastcall *)(_QWORD, const char **))cmdln_lastresort)((unsigned int)a1, a2) )
{
printf("Unknown command:");
if ( a1 > 0 )
{
v3 = a2;
v4 = (__int64)&a2[(unsigned int)(a1 - 1) + 1];
do
{
v5 = *v3++;
printf(" %s", v5);
}
while ( v3 != (const char **)v4 );
}
putchar(10);
}
}
else
{
(*(void (__fastcall **)(_QWORD, const char **))(v2 + 8))((unsigned int)a1, a2);
}
}
}

original_code:
void cmdln_run(int argc, char **argv) {
     struct cmdln_def *dothis;
     int i, r;
     if (argc == 0)
   return;
     r = -1;
     if ((dothis = tree_find(cmdln_commands, argv[0])) != (void *) -1)
   r = dothis->func(argc, argv);
     else {
   if (cmdln_lastresort)
        r = cmdln_lastresort(argc, argv);
   if (r) {
        printf("Unknown command:");
        for (i=0; i<argc; i++)
      printf(" %s", argv[i]);
        printf("\n");
   }
     }
}

canonical_original_code:
void cmdln_run(int argc, char **argv) {
     struct cmdln_def *dothis;
     int i; int r;
     if (argc == 0)
   return;
     r = -1;
     if ((dothis = tree_find(cmdln_commands, argv[0])) != (void *) -1)
   r = dothis->func(argc, argv);
     else {
   if (cmdln_lastresort)
        r = cmdln_lastresort(argc, argv);
   if (r) {
        printf("Unknown command:");
        for (i=0; i<argc; i++)
      printf(" %s", argv[i]);
        printf("\n");
   }
     }
}

variable_types: struct cmdln_def { char *name; int (*func)(int, char **); char *help; } *


decompiled_code:
__int64 cmdln_readloop()
{
const char *v0; // r13
__int64 result; // rax
__int64 v2; // rbx

cmdln_done = 0;
do
{
v0 = (const char *)readline(cmdln_prompt);
result = nm_adopt(v0, "trm/cmdln.c", 223LL, "cmdln_readloop");
if ( !v0 )
break;
util_strtrim(v0);
if ( *v0 )
{
add_history(v0);
cmdln_parse(v0);
cmdln_run(cmdln_argc[0], (const char **)&cmdln_argv);
}
if ( cmdln_argc[0] > 0 )
{
v2 = 0LL;
do
{
nm_nfree(*((_QWORD *)&cmdln_argv + v2), "trm/cmdln.c", 237LL, "cmdln_readloop");
*((_QWORD *)&cmdln_argv + v2++) = 0LL;
}
while ( cmdln_argc[0] > (int)v2 );
}
nm_nfree(v0, "trm/cmdln.c", 241LL, "cmdln_readloop");
result = cmdln_done;
}
while ( !cmdln_done );
return result;
}

canonical_decompiled_code:
__int64 func17()
{
const char *v0; // r13
__int64 result; // rax
__int64 v2; // rbx

cmdln_done = 0;
do
{
v0 = (const char *)readline(cmdln_prompt);
result = nm_adopt(v0, "trm/cmdln.c", 223LL, "cmdln_readloop");
if ( !v0 )
break;
util_strtrim(v0);
if ( *v0 )
{
add_history(v0);
func15(v0);
func16(cmdln_argc[0], (const char **)&cmdln_argv);
}
if ( cmdln_argc[0] > 0 )
{
v2 = 0LL;
do
{
nm_nfree(*((_QWORD *)&cmdln_argv + v2), "trm/cmdln.c", 237LL, "cmdln_readloop");
*((_QWORD *)&cmdln_argv + v2++) = 0LL;
}
while ( cmdln_argc[0] > (int)v2 );
}
nm_nfree(v0, "trm/cmdln.c", 241LL, "cmdln_readloop");
result = cmdln_done;
}
while ( !cmdln_done );
return result;
}

original_code:
void cmdln_readloop()
{
     char *line;
     int i;
     cmdln_done = 0;
     while (!cmdln_done) {
   line = readline(cmdln_prompt);
   nm_adopt(line,"trm/cmdln.c",223,__PRETTY_FUNCTION__);
   if (!line)
        break;
   util_strtrim(line);
   if (*line) {
        add_history(line);
        cmdln_parse(line);
        cmdln_run(cmdln_argc, cmdln_argv);
   }
   for (i=0; i<cmdln_argc; i++) {
        nm_nfree(cmdln_argv[i],"trm/cmdln.c",237,__PRETTY_FUNCTION__);
        cmdln_argv[i] = 0;
   }
   nm_nfree(line,"trm/cmdln.c",241,__PRETTY_FUNCTION__);
     }
}

variable_types:
line
char *

variable_types: i int


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

rl_readline_name = cmdln_binname;
result = &rl_attempted_completion_function;
rl_attempted_completion_function = cmdln_completion;
return result;
}

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

rl_readline_name = cmdln_binname;
result = &rl_attempted_completion_function;
rl_attempted_completion_function = cmdln_completion;
return result;
}

original_code:
void cmdln_initialize_readline ()
{
     rl_readline_name = cmdln_binname;
     rl_attempted_completion_function = (CPPFunction *) cmdln_completion;
}

canonical_original_code:
void cmdln_initialize_readline()
{
     rl_readline_name = cmdln_binname;
     rl_attempted_completion_function = (char **(*)()) cmdln_completion;
}