decompiled_code:
void *list_new()
{
return calloc(1uLL, 0x20uLL);
}

canonical_decompiled_code:
void *func2()
{
return calloc(1uLL, 0x20uLL);
}

original_code:
struct list *list_new()
{
 struct list *new;
 new = calloc(1, sizeof(*new));
 if (!new) return ((void *)0);
 return new;
}

variable_types: struct list { struct listnode { struct listnode *next; struct listnode *prev; void *data; } *head; struct listnode *tail; long count; void (*del)(void *val); } *

user_defined_types: struct list { struct listnode *head; struct listnode *tail; long count; void (*del)(void *val); }


repo: massar/ecmh

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

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

original_code:
void list_free(struct list *l)
{
 if (l) free(l);
}

return_type: void

user_defined_types: struct listnode { struct listnode *next; struct listnode *prev; void *data; }


decompiled_code:
void __fastcall list_delete_all_node(__int64 a1)
{
_QWORD *v1; // rbx
void (__fastcall *v2)(_QWORD); // rax
_QWORD *v3; // rbp

v1 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
do
{
v2 = *(void (__fastcall **)(_QWORD))(a1 + 24);
v3 = v1;
v1 = (_QWORD *)*v1;
if ( v2 )
v2(v3[2]);
listnode_free(v3);
}
while ( v1 );
}
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code:
void list_delete_all_node(struct list *list)
{
 struct listnode *node;
 struct listnode *next;
 for (node = list->head; node; node = next)
 {
  next = node->next;
  if (list->del) (*list->del)(node->data);
  listnode_free(node);
 }
 list->head = list->tail = ((void *)0);
 list->count = 0;
}

variable_types: struct listnode { struct listnode *next; struct listnode *prev; void *data; } *


decompiled_code:
void __fastcall list_delete(_QWORD *a1)
{
_QWORD *v1; // rbx
void (__fastcall *v2)(_QWORD); // rax
_QWORD *v3; // rbp

v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v2 = (void (__fastcall *)(_QWORD))a1[3];
v3 = v1;
v1 = (_QWORD *)*v1;
if ( v2 )
v2(v3[2]);
listnode_free(v3);
}
while ( v1 );
}
list_free(a1);
}

canonical_decompiled_code:
void __fastcall func5(_QWORD *a1)
{
_QWORD *v1; // rbx
void (__fastcall *v2)(_QWORD); // rax
_QWORD *v3; // rbp

v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v2 = (void (__fastcall *)(_QWORD))a1[3];
v3 = v1;
v1 = (_QWORD *)*v1;
if ( v2 )
v2(v3[2]);
func1(v3);
}
while ( v1 );
}
func3(a1);
}

original_code:
void list_delete(struct list *list)
{
 struct listnode *node;
 struct listnode *next;
 for (node = list->head; node; node = next)
 {
  next = node->next;
  if (list->del) (*list->del)(node->data);
  listnode_free(node);
 }
 list_free (list);
}


decompiled_code:
void __fastcall list_delete_node(_QWORD *a1, __int64 *a2)
{
_QWORD *v2; // rdx
__int64 v3; // rcx

v2 = (_QWORD *)a2[1];
v3 = *a2;
if ( v2 )
{
*v2 = v3;
if ( v3 )
{
LABEL_3:
*(_QWORD *)(v3 + 8) = v2;
--a1[2];
listnode_free(a2);
return;
}
}
else
{
*a1 = v3;
if ( v3 )
goto LABEL_3;
}
--a1[2];
a1[1] = v2;
listnode_free(a2);
}

original_code:
void list_delete_node(struct list *list, struct listnode *node)
{
 if (node->prev) node->prev->next = node->next;
 else list->head = node->next;
 if (node->next) node->next->prev = node->prev;
 else list->tail = node->prev;
 list->count--;
 listnode_free(node);
}

variable_types:
node
struct listnode *


decompiled_code:
void __fastcall group_destroy(void *ptr)
{
if ( ptr )
{
list_delete_all_node(*((_QWORD *)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
list_delete_all_node(*((_QWORD *)ptr + 2));
free(ptr);
}
}

original_code:
void group_destroy(struct groupnode *groupn)
{
 if (!groupn) return;
{}
 list_delete_all_node(groupn->interfaces);
 free(groupn);
}

variable_types: struct groupnode { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } mca; struct list { struct listnode { struct listnode *next; struct listnode *prev; void *data; } *head; struct listnode *tail; long count; void (*del)(void *val); } *interfaces; long lastforward; unsigned long bytes; unsigned long packets; } *

user_defined_types: struct groupnode { struct in6_addr mca; struct list *interfaces; long lastforward; unsigned long bytes; unsigned long packets; }


dolog

decompiled_code:
void dolog(int a1, const char *a2, ...)
{
const char *v3; // rsi
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( !g_conf || *(_QWORD *)(g_conf + 56LL) || a1 != 7 )
{
va_start(arg, a2);
if ( g_conf )
{
if ( *(_QWORD *)(g_conf + 48LL) )
{
LOBYTE(a1) = a1 | 0xB8;
vsyslog(a1, a2, arg);
return;
}
if ( *(_QWORD *)(g_conf + 56LL) )
{
v3 = "debug";
if ( a1 != 7 )
{
v3 = "error";
if ( a1 != 3 )
{
v3 = "warn";
if ( a1 != 4 )
{
v3 = "info";
if ( a1 != 6 )
v3 = (const char *)&unk_25F;
}
}
}
printf("[%6s] ", v3);
}
}
vprintf(a2, arg);
}
}

canonical_decompiled_code:
void func0(int a1, const char *a2, ...)
{
const char *v3; // rsi
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( !g_conf || *(_QWORD *)(g_conf + 56LL) || a1 != 7 )
{
va_start(arg, a2);
if ( g_conf )
{
if ( *(_QWORD *)(g_conf + 48LL) )
{
LOBYTE(a1) = a1 | 0xB8;
vsyslog(a1, a2, arg);
return;
}
if ( *(_QWORD *)(g_conf + 56LL) )
{
v3 = "debug";
if ( a1 != 7 )
{
v3 = "error";
if ( a1 != 3 )
{
v3 = "warn";
if ( a1 != 4 )
{
v3 = "info";
if ( a1 != 6 )
v3 = (const char *)&unk_25F;
}
}
}
printf("[%6s] ", v3);
}
}
vprintf(a2, arg);
}
}

original_code:
void dolog(int level, const char *fmt, ...)
{
 va_list ap;
 if (g_conf && !g_conf->verbose && level == 7) return;
 __builtin_va_start(ap,fmt);
 if (g_conf && g_conf->daemonize)
 {
  vsyslog((23<<3)|level, fmt, ap);
 }
 else
 {
  if (g_conf && g_conf->verbose)
  {
   printf("[%6s] ",
    level == 7 ? "debug" :
    (level == 3 ? "error" :
    (level == 4 ? "warn" :
    (level == 6 ? "info" : ""))));
  }
  vprintf(fmt, ap);
 }
 __builtin_va_end(ap);
}

canonical_original_code:
void dolog(int level, char *fmt, ...)
{
 __builtin_va_list ap;
 if (g_conf && !g_conf->verbose && level == 7) return;
 __builtin_va_start(ap,fmt);
 if (g_conf && g_conf->daemonize)
 {
  vsyslog((23<<3)|level, fmt, ap);
 }
 else
 {
  if (g_conf && g_conf->verbose)
  {
   printf("[%6s] ",
    level == 7 ? "debug" :
    (level == 3 ? "error" :
    (level == 4 ? "warn" :
    (level == 6 ? "info" : ""))));
  }
  vprintf(fmt, ap);
 }
 __builtin_va_end(ap);
}

variable_types: level int

variable_types:
fmt
char *


cleanpid

decompiled_code:
__int64 __fastcall cleanpid(unsigned int a1)
{
__int64 result; // rax

dolog(6, "Trying to exit, got signal %d...\n", a1);
unlink("/var/run/ecmh.pid");
result = g_conf;
if ( g_conf )
*(_QWORD *)(g_conf + 64LL) = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 result; // rax

func0(6, "Trying to exit, got signal %d...\n", a1);
unlink("/var/run/ecmh.pid");
result = g_conf;
if ( g_conf )
*(_QWORD *)(g_conf + 64LL) = 1LL;
return result;
}

original_code:
void cleanpid(int i)
{
 dolog(6, "Trying to exit, got signal %d...\n", i);
 unlink("/var/run/ecmh.pid");
 if (g_conf) g_conf->quit = (!0);
}

variable_types: i int


gettimes

decompiled_code:
__time_t gettimes()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(0, &v1);
return v1.tv_sec;
}

canonical_decompiled_code:
__time_t func4()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(0, &v1);
return v1.tv_sec;
}

original_code:
uint64_t gettimes(void)
{
 struct timespec ts;
 clock_gettime(0, &ts);
 return (ts.tv_sec);
}

canonical_original_code:
unsigned long gettimes()
{
 struct timespec ts;
 clock_gettime(0, &ts);
 return (ts.tv_sec);
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }

return_type: unsigned long


decompiled_code:
void __fastcall int_destroy(__int64 a1)
{
*(_QWORD *)(a1 + 32) = 0LL;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
*(_QWORD *)(a1 + 32) = 0LL;
}

original_code:
void int_destroy(struct intnode *intn)
{
{}
 intn->mtu = 0;
}

variable_types: struct intnode { unsigned long ifindex; char name[16]; unsigned long groupcount; unsigned long mtu; unsigned long mld_version; unsigned long mld_last_v1; struct sockaddr { unsigned short sa_family; char sa_data[14]; } hwaddr; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } linklocal; struct in6_addr global; unsigned long stat_packets_received; unsigned long stat_packets_sent; unsigned long stat_bytes_received; unsigned long stat_bytes_sent; unsigned long stat_icmp_received; unsigned long stat_icmp_sent; unsigned long upstream; } *

user_defined_types: struct intnode { unsigned long ifindex; char name[16]; unsigned long groupcount; unsigned long mtu; unsigned long mld_version; unsigned long mld_last_v1; struct sockaddr hwaddr; struct in6_addr linklocal; struct in6_addr global; unsigned long stat_packets_received; unsigned long stat_packets_sent; unsigned long stat_bytes_received; unsigned long stat_bytes_sent; unsigned long stat_icmp_received; unsigned long stat_icmp_sent; unsigned long upstream; }


decompiled_code:
__int64 __fastcall int_find(unsigned int a1)
{
__int64 result; // rax

if ( (unsigned __int64)a1 >= *(_QWORD *)(g_conf + 8LL) )
return 0LL;
result = *(_QWORD *)(g_conf + 16LL) + 160LL * a1;
if ( !*(_QWORD *)(result + 32) )
result = 0LL;
return result;
}

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

if ( (unsigned __int64)a1 >= *(_QWORD *)(g_conf + 8LL) )
return 0LL;
result = *(_QWORD *)(g_conf + 16LL) + 160LL * a1;
if ( !*(_QWORD *)(result + 32) )
result = 0LL;
return result;
}

original_code:
struct intnode *int_find(unsigned int ifindex)
{
 if (ifindex >= g_conf->maxinterfaces || g_conf->ints[ifindex].mtu == 0) return ((void *)0);
 return &g_conf->ints[ifindex];
}

variable_types:
ifindex
unsigned int

return_type: struct intnode { unsigned long ifindex; char name[16]; unsigned long groupcount; unsigned long mtu; unsigned long mld_version; unsigned long mld_last_v1; struct sockaddr { unsigned short sa_family; char sa_data[14]; } hwaddr; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } linklocal; struct in6_addr global; unsigned long stat_packets_received; unsigned long stat_packets_sent; unsigned long stat_bytes_received; unsigned long stat_bytes_sent; unsigned long stat_icmp_received; unsigned long stat_icmp_sent; unsigned long upstream; } *


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

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

original_code:
void subscr_destroy(struct subscrnode *subscrn)
{
 if (!subscrn) return;
{}
 free(subscrn);
}

variable_types: struct subscrnode { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } ipv6; unsigned long mode; long refreshtime; } *

user_defined_types: struct subscrnode { struct in6_addr ipv6; unsigned long mode; long refreshtime; }


decompiled_code:
__int64 __fastcall subscr_unsub(_QWORD *a1, _DWORD *a2)
{
_QWORD *v3; // rsi
_DWORD *v4; // rbp

v3 = (_QWORD *)*a1;
if ( !*a1 )
return 0LL;
do
{
v4 = (_DWORD *)v3[2];
if ( v4 && *a2 == *v4 && a2[1] == v4[1] && a2[2] == v4[2] && a2[3] == v4[3] )
{
list_delete_node();
subscr_destroy(v4);
return 1LL;
}
v3 = (_QWORD *)*v3;
}
while ( v3 );
return 0LL;
}

original_code:
uint64_t subscr_unsub(struct list *list, const struct in6_addr *ipv6)
{
 struct subscrnode *subscrn;
 struct listnode *ln;
 for ((ln) = (list)->head; (ln); (ln) = (ln)->next) if (((subscrn) = (ln)->data) != ((void *)0))
 {
  if ((__extension__ ({ const struct in6_addr *__a = (const struct in6_addr *) (ipv6); const struct in6_addr *__b = (const struct in6_addr *) (&subscrn->ipv6); __a->__in6_u.__u6_addr32[0] == __b->__in6_u.__u6_addr32[0] && __a->__in6_u.__u6_addr32[1] == __b->__in6_u.__u6_addr32[1] && __a->__in6_u.__u6_addr32[2] == __b->__in6_u.__u6_addr32[2] && __a->__in6_u.__u6_addr32[3] == __b->__in6_u.__u6_addr32[3]; })))
  {
   list_delete_node(list, ln);
   subscr_destroy(subscrn);
   return (!0);
  }
 }
 return 0;
}

canonical_original_code:
unsigned long subscr_unsub(struct list *list, struct in6_addr *ipv6)
{
 struct subscrnode *subscrn;
 struct listnode *ln;
 for ((ln) = (list)->head; (ln); (ln) = (ln)->next) if (((subscrn) = (ln)->data) != ((void *)0))
 {
  if ((__extension__ ({ struct in6_addr *__a = (const struct in6_addr *) (ipv6); struct in6_addr *__b = (const struct in6_addr *) (&subscrn->ipv6); __a->__in6_u.__u6_addr32[0] == __b->__in6_u.__u6_addr32[0] && __a->__in6_u.__u6_addr32[1] == __b->__in6_u.__u6_addr32[1] && __a->__in6_u.__u6_addr32[2] == __b->__in6_u.__u6_addr32[2] && __a->__in6_u.__u6_addr32[3] == __b->__in6_u.__u6_addr32[3]; })))
  {
   list_delete_node(list, ln);
   subscr_destroy(subscrn);
   return (!0);
  }
 }
 return 0;
}

variable_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } *


decompiled_code:
void __fastcall grpint_destroy(void *ptr)
{
if ( ptr )
{
list_delete_all_node(*((_QWORD *)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
list_delete_all_node(*((_QWORD *)ptr + 1));
free(ptr);
}
}

original_code:
void grpint_destroy(struct grpintnode *grpintn)
{
 if (!grpintn) return;
 list_delete_all_node(grpintn->subscriptions);
 free(grpintn);
}

variable_types: struct grpintnode { unsigned long ifindex; struct list { struct listnode { struct listnode *next; struct listnode *prev; void *data; } *head; struct listnode *tail; long count; void (*del)(void *val); } *subscriptions; } *

user_defined_types: struct grpintnode { unsigned long ifindex; struct list *subscriptions; }


decompiled_code:
__int64 __fastcall grpint_refresh(__int64 a1, _DWORD *a2, unsigned int a3)
{
__int64 v4; // rbx
__int64 v5; // rdx
__int64 result; // rax

v4 = subscr_find(*(_QWORD *)(a1 + 8));
if ( a3 != 2 || *a2 || a2[1] || a2[2] || (result = 1LL, a2[3]) )
{
if ( !v4 )
{
v4 = subscr_create(a2, a3);
result = 0LL;
if ( !v4 )
return result;
listnode_add(*(_QWORD *)(a1 + 8), v4);
}
v5 = *(_QWORD *)(v4 + 16);
if ( a3 != v5 )
{
dolog(7LL, "grpint_refresh() - Mode changed from %lu to %u\n", v5, a3);
*(_QWORD *)(v4 + 16) = a3;
}
*(_QWORD *)(v4 + 24) = time(0LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _DWORD *a2, unsigned int a3)
{
__int64 v4; // rbx
__int64 v5; // rdx
__int64 result; // rax

v4 = subscr_find(*(_QWORD *)(a1 + 8));
if ( a3 != 2 || *a2 || a2[1] || a2[2] || (result = 1LL, a2[3]) )
{
if ( !v4 )
{
v4 = subscr_create(a2, a3);
result = 0LL;
if ( !v4 )
return result;
listnode_add(*(_QWORD *)(a1 + 8), v4);
}
v5 = *(_QWORD *)(v4 + 16);
if ( a3 != v5 )
{
dolog(7LL, "grpint_refresh() - Mode changed from %lu to %u\n", v5, a3);
*(_QWORD *)(v4 + 16) = a3;
}
*(_QWORD *)(v4 + 24) = time(0LL);
result = 1LL;
}
return result;
}

original_code:
uint64_t grpint_refresh(struct grpintnode *grpintn, const struct in6_addr *ipv6, unsigned int mode)
{
 struct subscrnode *subscrn;
 subscrn = subscr_find(grpintn->subscriptions, ipv6);
 if ( mode == 2 &&
  (__extension__ ({ const struct in6_addr *__a = (const struct in6_addr *) (ipv6); __a->__in6_u.__u6_addr32[0] == 0 && __a->__in6_u.__u6_addr32[1] == 0 && __a->__in6_u.__u6_addr32[2] == 0 && __a->__in6_u.__u6_addr32[3] == 0; })))
 {
  return (!0);
 }
 if (!subscrn)
 {
  subscrn = subscr_create(ipv6, mode);
  if (subscrn)
  {
   listnode_add(grpintn->subscriptions, (void *)subscrn);
  }
 }
 if (!subscrn) return 0;
 if (mode != subscrn->mode)
 {
  dolog(7, "grpint_refresh() - Mode changed from %" "l" "u" " to %u\n", subscrn->mode, mode);
  subscrn->mode = mode;
 }
 subscrn->refreshtime = time(((void *)0));
 return (!0);
}

canonical_original_code:
unsigned long grpint_refresh(struct grpintnode *grpintn, struct in6_addr *ipv6, unsigned int mode)
{
 struct subscrnode *subscrn;
 subscrn = subscr_find(grpintn->subscriptions, ipv6);
 if ( mode == 2 &&
  (__extension__ ({ struct in6_addr *__a = (const struct in6_addr *) (ipv6); __a->__in6_u.__u6_addr32[0] == 0 && __a->__in6_u.__u6_addr32[1] == 0 && __a->__in6_u.__u6_addr32[2] == 0 && __a->__in6_u.__u6_addr32[3] == 0; })))
 {
  return (!0);
 }
 if (!subscrn)
 {
  subscrn = subscr_create(ipv6, mode);
  if (subscrn)
  {
   listnode_add(grpintn->subscriptions, (void *)subscrn);
  }
 }
 if (!subscrn) return 0;
 if (mode != subscrn->mode)
 {
  dolog(7, "grpint_refresh() - Mode changed from %" "l" "u" " to %u\n", subscrn->mode, mode);
  subscrn->mode = mode;
 }
 subscrn->refreshtime = time(((void *)0));
 return (!0);
}

variable_types:
mode
unsigned int

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


repo: masterdriverz/geekcode

original_code:
static enum parse_errors_t process_line(struct answer *line, char *data)
{
 char *last, *p;
 for ((p = strtok_r(data, " ", &last)); p && line->answer;
  (p = strtok_r(((void *)0), " ", &last)), line++) {
  int i;
  const struct elem *temp;
  char c=0;
  while (!line->display)
   line++;
  for (temp = line->contents, i=0; temp[i].alias; i++) {
   char *n, buf[256];
   const char *s;
   if (line->dependant) {
    if (sscanf(p, temp[i].alias, &c))
     snprintf(buf, sizeof(buf), temp[i].alias, c);
    else
     continue;
    s = (const char *)&buf;
   } else {
    s = temp[i].alias;
   }
   n = strchr(p, '\n');
   if (n)
    *n = '\0';
   if (!strcmp(s, p))
    goto out;
  }
  return EALIAS;
out:
  line->answer = i+1;
  if (c) {
   const struct elem *temp;
   int i;
   for (temp = (line-1)->contents, i = 0; temp->alias; temp++, i++)
    if (*(temp->alias) == c)
     goto found;
   return EDEPENDANT;
found:
   (line-1)->answer = i+1;
  }
 }
 if ((p && ((*__ctype_b_loc ())[(int) (((unsigned char )*p))] & (unsigned short int) _ISalnum)) || line->answer)
  return ETRAILING;
 return SUCCESS;
}

canonical_original_code:
static enum parse_errors_t process_line(struct answer *line, char *data)
{
 char *last; char *p;
 for ((p = strtok_r(data, " ", &last)); p && line->answer;
  (p = strtok_r(((void *)0), " ", &last)), line++) {
  int i;
  struct elem *temp;
  char c = 0;
  while (!line->display)
   line++;
  for (temp = line->contents, i=0; temp[i].alias; i++) {
   char *n; char buf[256];
   char *s;
   if (line->dependant) {
    if (sscanf(p, temp[i].alias, &c))
     snprintf(buf, sizeof(buf), temp[i].alias, c);
    else
     continue;
    s = (char *)&buf;
   } else {
    s = temp[i].alias;
   }
   n = strchr(p, '\n');
   if (n)
    *n = '\0';
   if (!strcmp(s, p))
    goto out;
  }
  return EALIAS;
out:
  line->answer = i+1;
  if (c) {
   struct elem *temp;
   int i;
   for (temp = (line-1)->contents, i = 0; temp->alias; temp++, i++)
    if (*(temp->alias) == c)
     goto found;
   return EDEPENDANT;
found:
   (line-1)->answer = i+1;
  }
 }
 if ((p && ((*__ctype_b_loc ())[(int) (((unsigned char )*p))] & (unsigned short) _ISalnum)) || line->answer)
  return ETRAILING;
 return SUCCESS;
}

variable_types: struct answer { int answer; char *name; struct elem { char *alias; } *contents; } *

variable_types:
data
char *

variable_types:
last
char *

variable_types:
p
char *

variable_types:
temp
struct elem { char *alias; } *

variable_types: c char

variable_types:
n
char *

variable_types:
buf
char [256]

variable_types:
s
char *

return_type: enum parse_errors_t { SUCCESS=0, ETRAILING=1, EALIAS=2, EDEPENDANT=3, ESYNTAX=4, EEOF=5, EFERROR=6 }

user_defined_types: struct answer { int answer; char *name; struct elem *contents; }


getcontent

decompiled_code:
__int64 __fastcall getcontent(int *a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = *a1;
if ( (int)v1 <= 0 )
result = 0LL;
else
result = *((_QWORD *)a1 + 3) + 16 * v1 - 16;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = *a1;
if ( (int)v1 <= 0 )
result = 0LL;
else
result = *((_QWORD *)a1 + 3) + 16 * v1 - 16;
return result;
}

original_code:
static inline const struct elem *getcontent(const struct answer *obj)
{
 if (obj->answer <= 0)
  return ((void *)0);
 return &obj->contents[obj->answer-1];
}

canonical_original_code:
static inline struct elem *getcontent(struct answer *obj)
{
 if (obj->answer <= 0)
  return ((void *)0);
 return &obj->contents[obj->answer-1];
}

variable_types: struct answer { int answer; char *name; struct elem *contents; } *

return_type: struct elem { char *alias; } *


version

decompiled_code:
int version()
{
return puts("Geekcode version v2");
}

canonical_decompiled_code:
int func2()
{
return puts("Geekcode version v2");
}

original_code:
static inline void version(void)
{
 puts(version_str);
}

canonical_original_code:
static inline void version()
{
 puts(version_str);
}


decompiled_code:
__int64 list_sections()
{
_QWORD *v0; // rbp
unsigned int *v1; // rbx
const char *v2; // rdi
__int64 result; // rax

v0 = &lines;
v1 = (unsigned int *)lines;
if ( lines )
{
do
{
while ( 1 )
{
result = *v1;
if ( !(_DWORD)result )
break;
v2 = (const char *)*((_QWORD *)v1 + 2);
v1 += 8;
puts(v2);
}
v1 = (unsigned int *)v0[1];
++v0;
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
_QWORD *v0; // rbp
unsigned int *v1; // rbx
const char *v2; // rdi
__int64 result; // rax

v0 = &lines;
v1 = (unsigned int *)lines;
if ( lines )
{
do
{
while ( 1 )
{
result = *v1;
if ( !(_DWORD)result )
break;
v2 = (const char *)*((_QWORD *)v1 + 2);
v1 += 8;
puts(v2);
}
v1 = (unsigned int *)v0[1];
++v0;
}
while ( v1 );
}
return result;
}

original_code:
static void list_sections(void)
{
 struct answer **cur_line;
 for (cur_line = lines; *cur_line; cur_line++) {
  struct answer *cur_question;
  for (cur_question = *cur_line; cur_question->answer; cur_question++)
   puts(cur_question->name);
 }
}

canonical_original_code:
static void list_sections()
{
 struct answer **cur_line;
 for (cur_line = lines; *cur_line; cur_line++) {
  struct answer *cur_question;
  for (cur_question = *cur_line; cur_question->answer; cur_question++)
   puts(cur_question->name);
 }
}

variable_types: struct answer { int answer; char *name; struct elem { char *alias; } *contents; } **


decompiled_code:
void __fastcall __noreturn file_error(const char *a1, const char *a2)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v2, 0x100uLL, "Error while %s file \"%s\"", a2, a1);
perror(v2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(const char *a1, const char *a2)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v2, 0x100uLL, "Error while %s file \"%s\"", a2, a1);
perror(v2);
exit(1);
}

original_code:
static void file_error(const char *filename, const char *action)
{
 char error[256];
 snprintf(error, sizeof(error), "Error while %s file \"%s\"",
  action, filename);
 perror(error);
 exit(1);
}

canonical_original_code:
static void file_error(char *filename, char *action)
{
 char error[256];
 snprintf(error, sizeof(error), "Error while %s file \"%s\"",
  action, filename);
 perror(error);
 exit(1);
}

variable_types:
filename
char *

variable_types:
action
char *

variable_types:
error
char [256]


decompiled_code:
_DWORD *create_code()
{
_DWORD *result; // rax
_QWORD *v1; // r12
unsigned int v2; // ebp
int *v3; // rbx
__int64 v4; // rdx
__int64 v5; // rdi
__int64 v6; // rsi

result = (_DWORD *)lines;
if ( lines )
{
v1 = &lines;
v2 = 1;
do
{
v3 = result - 8;
if ( *result )
{
do
{
if ( v3[10] )
xgetcontent(v3, "function: %s; line %d\n", "create_code", 80LL);
v4 = *((_QWORD *)v3 + 7);
v5 = *((_QWORD *)v3 + 6);
v6 = v2;
v3 += 8;
++v2;
*v3 = getanswer(v5, v6, v4);
}
while ( v3[8] );
}
result = (_DWORD *)v1[1];
++v1;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
_DWORD *func8()
{
_DWORD *result; // rax
_QWORD *v1; // r12
unsigned int v2; // ebp
int *v3; // rbx
__int64 v4; // rdx
__int64 v5; // rdi
__int64 v6; // rsi

result = (_DWORD *)lines;
if ( lines )
{
v1 = &lines;
v2 = 1;
do
{
v3 = result - 8;
if ( *result )
{
do
{
if ( v3[10] )
func5(v3, "function: %s; line %d\n", "create_code", 80LL);
v4 = *((_QWORD *)v3 + 7);
v5 = *((_QWORD *)v3 + 6);
v6 = v2;
v3 += 8;
++v2;
*v3 = getanswer(v5, v6, v4);
}
while ( v3[8] );
}
result = (_DWORD *)v1[1];
++v1;
}
while ( result );
}
return result;
}

original_code:
static void create_code(void)
{
 struct answer **cur_line;
 int page_num=1;
 for (cur_line = lines; *cur_line; cur_line++) {
  struct answer *cur_question;
  for (cur_question = *cur_line;
    cur_question->answer;
    cur_question++, page_num++) {
   const char *aux_string=((void *)0);
   if (cur_question->dependant) {
    const struct elem *aux = xgetcontent(cur_question-1,
     "function: %s; line %d\n", __func__, 80);
    aux_string = aux->alias;
   }
   cur_question->answer =
    getanswer(cur_question->name, page_num,
     cur_question->contents, aux_string);
  }
 }
}

canonical_original_code:
static void create_code()
{
 struct answer **cur_line;
 int page_num = 1;
 for (cur_line = lines; *cur_line; cur_line++) {
  struct answer *cur_question;
  for (cur_question = *cur_line;
    cur_question->answer;
    cur_question++, page_num++) {
   char *aux_string = ((void *)0);
   if (cur_question->dependant) {
    struct elem *aux = xgetcontent(cur_question-1,
     "function: %s; line %d\n", __func__, 80);
    aux_string = aux->alias;
   }
   cur_question->answer =
    getanswer(cur_question->name, page_num,
     cur_question->contents, aux_string);
  }
 }
}

variable_types:
aux
struct elem { char *alias; } *


original_code:
static unsigned int print_page(const char *name, int page_num,
  const struct elem *objects,
  const char *additional)
{
 unsigned int i;
 printf("\nPage %i of %i: %s\n", page_num, 37, name);
 puts("===============================================================================");
 for (i = 0; objects[i].comment; i++) {
  const char *alias = objects[i].alias;
  if (additional) {
   char *s = malloc(strlen(objects[i].alias));
   if (!s) {
    perror(((void *)0));
    exit(-1);
   }
   sprintf(s, objects[i].alias, *additional);
   alias = s;
  }
  printf("%2d %-5s %s\n", i+1, alias, objects[i].comment);
  if (additional)
   free((void *)alias);
 }
 return i;
}

canonical_original_code:
static unsigned int print_page(char *name, int page_num, struct elem *objects, char *additional)
{
 unsigned int i;
 printf("\nPage %i of %i: %s\n", page_num, 37, name);
 puts("===============================================================================");
 for (i = 0; objects[i].comment; i++) {
  char *alias = objects[i].alias;
  if (additional) {
   char *s = malloc(strlen(objects[i].alias));
   if (!s) {
    perror(((void *)0));
    exit(-1);
   }
   sprintf(s, objects[i].alias, *additional);
   alias = s;
  }
  printf("%2d %-5s %s\n", i+1, alias, objects[i].comment);
  if (additional)
   free((void *)alias);
 }
 return i;
}

variable_types:
name
char *

variable_types:
objects
struct elem { char *alias; } *

variable_types:
additional
char *

variable_types:
i
unsigned int

variable_types:
alias
char *

return_type: unsigned int


getanswer

decompiled_code:
__int64 __fastcall getanswer(const char *a1, unsigned int a2, __int64 a3, char *a4)
{
int v4; // ebp
int *v5; // rax
const char *v6; // r13
int *v7; // r14
__int64 result; // rax
char *endptr; // [rsp+18h] [rbp-40h] BYREF

do
{
v4 = print_page(a1, a2, a3, a4);
putc(10, stdout);
do
{
printf("Enter your %s code number here [q to quit, 0 to repeat]: ", a1);
if ( getline(&p_1, &n_0, stdin) == -1 )
{
if ( feof(stdin) )
{
fwrite("\nGot EOF on stdin, aborting...\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
perror(0LL);
exit(1);
}
v5 = _errno_location();
v6 = p_1;
*v5 = 0;
v7 = v5;
result = strtol(v6, &endptr, 10);
if ( *v7 == 34 )
{
if ( (unsigned __int64)(result + 0x7FFFFFFFFFFFFFFFLL) > 0xFFFFFFFFFFFFFFFDLL )
goto LABEL_15;
}
else if ( !*v7 )
{
goto LABEL_5;
}
if ( !result )
{
LABEL_15:
perror("strtol");
exit(1);
}
LABEL_5:
if ( endptr == v6 )
{
fwrite("No digits were found\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
while ( *v6 == 32 )
++v6;
if ( (*v6 & 0xDF) == 81 )
exit(0);
}
while ( v4 < result );
}
while ( !result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, unsigned int a2, __int64 a3, char *a4)
{
int v4; // ebp
int *v5; // rax
const char *v6; // r13
int *v7; // r14
__int64 result; // rax
char *endptr; // [rsp+18h] [rbp-40h] BYREF

do
{
v4 = func0(a1, a2, a3, a4);
putc(10, stdout);
do
{
printf("Enter your %s code number here [q to quit, 0 to repeat]: ", a1);
if ( getline(&p_1, &n_0, stdin) == -1 )
{
if ( feof(stdin) )
{
fwrite("\nGot EOF on stdin, aborting...\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
perror(0LL);
exit(1);
}
v5 = _errno_location();
v6 = p_1;
*v5 = 0;
v7 = v5;
result = strtol(v6, &endptr, 10);
if ( *v7 == 34 )
{
if ( (unsigned __int64)(result + 0x7FFFFFFFFFFFFFFFLL) > 0xFFFFFFFFFFFFFFFDLL )
goto LABEL_15;
}
else if ( !*v7 )
{
goto LABEL_5;
}
if ( !result )
{
LABEL_15:
perror("strtol");
exit(1);
}
LABEL_5:
if ( endptr == v6 )
{
fwrite("No digits were found\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
while ( *v6 == 32 )
++v6;
if ( (*v6 & 0xDF) == 81 )
exit(0);
}
while ( v4 < result );
}
while ( !result );
return result;
}

original_code:
int getanswer(const char *name, int page_num,
  const struct elem *objects,
  const char *additional)
{
 static char *p = ((void *)0);
 static size_t n;
 int max;
 char *s;
 char *endptr;
 long val;
print:
 max = print_page(name, page_num, objects, additional);
 putc('\n', stdout);
foo:
 printf("Enter your %s code number here [q to quit, 0 to repeat]: ", name);
 if (getline(&p, &n, stdin) == -1) {
  if (feof(stdin))
   do { fputs("\nGot EOF on stdin, aborting...\n", stderr); exit(1); } while (0);;
  perror(((void *)0));
  exit(1);
 }
 s = p;
 (*__errno_location ()) = 0;
 val = strtol(s, &endptr, 10);
 if (((*__errno_location ()) == 34 && (val == 0x7fffffffffffffffL || val == (-0x7fffffffffffffffL - 1L)))
  || ((*__errno_location ()) != 0 && val == 0)) {
  perror("strtol");
  exit(1);
 }
 if (endptr == s) {
  fprintf(stderr, "No digits were found\n");
  exit(1);
 }
  while (*s == ' ')
   s++;
  if (*s == 'q' || *s == 'Q')
   exit(0);
 if (val > max)
  goto foo;
 if (val == 0)
  goto print;
 return (int)val;
}

canonical_original_code:
int getanswer(char *name, int page_num, struct elem *objects, char *additional)
{
 static char *p = ((void *)0);
 static unsigned long n;
 int max;
 char *s;
 char *endptr;
 long val;
print:
 max = print_page(name, page_num, objects, additional);
 putc('\n', stdout);
foo:
 printf("Enter your %s code number here [q to quit, 0 to repeat]: ", name);
 if (getline(&p, &n, stdin) == -1) {
  if (feof(stdin))
   do { fputs("\nGot EOF on stdin, aborting...\n", stderr); exit(1); } while (0);;
  perror(((void *)0));
  exit(1);
 }
 s = p;
 (*__errno_location ()) = 0;
 val = strtol(s, &endptr, 10);
 if (((*__errno_location ()) == 34 && (val == 0x7fffffffffffffffL || val == (-0x7fffffffffffffffL - 1L)))
  || ((*__errno_location ()) != 0 && val == 0)) {
  perror("strtol");
  exit(1);
 }
 if (endptr == s) {
  fprintf(stderr, "No digits were found\n");
  exit(1);
 }
  while (*s == ' ')
   s++;
  if (*s == 'q' || *s == 'Q')
   exit(0);
 if (val > max)
  goto foo;
 if (val == 0)
  goto print;
 return (int)val;
}

variable_types:
p
char *

variable_types:
n
unsigned long

variable_types: max int

variable_types:
endptr
char *

variable_types: val long

return_type: int


hashclear

repo: masui/LensBar

decompiled_code:
void *hashclear()
{
return memset(&statenum, 255, 0x9BD4uLL);
}

canonical_decompiled_code:
void *func0()
{
return memset(&statenum, 255, 0x9BD4uLL);
}

original_code:
static void
hashclear()
{
 register int i;
 for(i=0;i<9973;i++)
  statenum[i] = -1;
}

variable_types: i int


bcopy

original_code:
void
bcopy(char *from, char *to, register int num)
{
 while(num--){ *to++ = *from++; }
}

canonical_original_code:
void bcopy(char *from, char *to, int num)
{
 while(num--){ *to++ = *from++; }
}

variable_types:
from
char *

variable_types:
to
char *

variable_types: num int


bcmp

decompiled_code:
__int64 __fastcall bcmp(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rcx
__int64 v4; // rax
char v5; // dl

v3 = a3;
v4 = 0LL;
do
{
if ( v4 == v3 )
return 0LL;
v5 = *(_BYTE *)(a2 + v4++);
}
while ( v5 == *(_BYTE *)(a1 + v4 - 1) );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rcx
__int64 v4; // rax
char v5; // dl

v3 = a3;
v4 = 0LL;
do
{
if ( v4 == v3 )
return 0LL;
v5 = *(_BYTE *)(a2 + v4++);
}
while ( v5 == *(_BYTE *)(a1 + v4 - 1) );
return 1LL;
}

original_code:
int
bcmp(char *from, char *to, register int num)
{
 while(num--){ if(*to++ != *from++) return 1; }
 return 0;
}

canonical_original_code:
int bcmp(char *from, char *to, int num)
{
 while(num--){ if(*to++ != *from++) return 1; }
 return 0;
}


patstate

decompiled_code:
__int64 __fastcall patstate(__int64 a1, int a2)
{
__int64 v4; // rax
unsigned __int64 v5; // rsi
__int64 v6; // rdx
__int64 v7; // rax
unsigned __int64 v8; // r8
int v9; // er13
int v10; // er12
int v11; // ebx
unsigned __int64 v12; // rcx
__int64 v13; // r8
__int64 v14; // r9
unsigned __int64 v15; // r11
unsigned int v17; // er13
__int64 v18; // r8
__int64 v19; // r8

if ( a2 < 0 )
{
v8 = 0LL;
}
else
{
v4 = a2;
v5 = 0LL;
v6 = a1 + 8 * v4 + 8;
v7 = a1;
do
{
v7 += 8LL;
v5 = *(_QWORD *)(v7 - 8) ^ (v5 >> patlen);
}
while ( v6 != v7 );
v8 = v5 % 0x26F5;
}
v9 = statenum[v8];
if ( v9 < 0 )
{
v17 = nstates;
if ( nstates <= 1998 )
{
bcopy(a1, (__int64)&statepat_hash[4 * v8], 8 * a2 + 8);
statenum[v19] = v17;
hashpos[v17] = v19;
goto LABEL_12;
}
}
else
{
v10 = 8 * a2 + 8;
do
{
if ( !(unsigned int)bcmp((__int64)&statepat_hash[4 * v8], a1, v10) )
return (unsigned int)v9;
v11 = v14;
v12 = v14
+ v13
- 9973
* ((unsigned __int64)(((v15 * (unsigned __int128)(unsigned __int64)(v14 + v13)) >> 64)
+ ((unsigned __int64)(v14
+ v13
- ((v15 * (unsigned __int128)(unsigned __int64)(v14 + v13)) >> 64)) >> 1)) >> 13);
v9 = statenum[v12];
v8 = v12;
}
while ( v9 >= 0 );
v17 = nstates;
if ( nstates <= 1998 )
{
bcopy(a1, (__int64)&statepat_hash[4 * v12], v10);
mishits += v11;
statenum[v18] = v17;
hashpos[v17] = v18;
LABEL_12:
nstates = v17 + 1;
return v17;
}
}
return 0xFFFFFFFFLL;
}

original_code:
static int
patstate(unsigned long *pattern, int mismatch)
{
 register int i;
 register unsigned long *p;
 register unsigned long h = 0;
 int add = 1;
 int mishit = 0;
 p = pattern;
 for(i=0;i<=mismatch;i++){
  h = (h >> patlen) ^ *p++;
 }
 h = h % 9973;
 for(;;){
  if(statenum[h] < 0){
   if(nstates >= 2000 -1){
    return -1;
   }
   bcopy((char*)pattern,(char*)statepat_hash[h],
    sizeof(long)*(mismatch+1));
   statenum[h] = nstates;
   hashpos[nstates] = h;
   if(mishit) mishits += mishit;
   return nstates++;
  }
  if(bcmp((char*)statepat_hash[h],(char*)pattern,
   sizeof(long)*(mismatch+1)) == 0){
   return statenum[h];
  }
  else {
   h += add;
   h %= 9973;
   add++;
   mishit++;
  }
 }
}

canonical_original_code:
static int patstate(unsigned long *pattern, int mismatch)
{
 register int i;
 register unsigned long *p;
 register unsigned long h = 0;
 int add = 1;
 int mishit = 0;
 p = pattern;
 for(i=0;i<=mismatch;i++){
  h = (h >> patlen) ^ *p++;
 }
 h = h % 9973;
 for(;;){
  if(statenum[h] < 0){
   if(nstates >= 2000 -1){
    return -1;
   }
   bcopy((char *)pattern,(char *)statepat_hash[h],
    sizeof(long)*(mismatch+1));
   statenum[h] = nstates;
   hashpos[nstates] = h;
   if(mishit) mishits += mishit;
   return nstates++;
  }
  if(bcmp((char *)statepat_hash[h],(char *)pattern,
   sizeof(long)*(mismatch+1)) == 0){
   return statenum[h];
  }
  else {
   h += add;
   h %= 9973;
   add++;
   mishit++;
  }
 }
}

variable_types:
pattern
unsigned long *

variable_types: mismatch int

variable_types:
p
unsigned long *

variable_types:
h
unsigned long

variable_types: add int

variable_types: mishit int


makepat

decompiled_code:
__int64 __fastcall makepat(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // r15
unsigned __int64 v3; // r14
char v4; // cl
__int64 v5; // rax
int v6; // ebx
__int64 v7; // rbp
__int64 v8; // r12
const unsigned __int16 **v9; // rax
__int64 v10; // r13
unsigned __int16 v11; // ax
__int64 v12; // rax
__int64 v14; // rax
char v15; // [rsp+Bh] [rbp-3Dh]

v2 = a1;
v3 = 0x80000000LL;
statemask = 0x80000000LL;
memset(shiftpat, 0, sizeof(shiftpat));
v4 = 0;
epsilon = 0LL;
patlen = 0;
v5 = *a1;
if ( (_BYTE)v5 )
{
v15 = 0;
v6 = 0;
v7 = 0x80000000LL;
v8 = 0LL;
do
{
while ( (_BYTE)v5 == 32 )
{
v5 = *++v2;
v15 = 1;
v8 |= v3;
if ( !(_BYTE)v5 )
goto LABEL_8;
}
shiftpat[v5] |= v3;
v9 = _ctype_b_loc();
v10 = *v2;
v11 = (*v9)[v10];
if ( (v11 & 0x100) != 0 )
{
v12 = (*_ctype_tolower_loc())[v10];
shiftpat[v12] |= v3;
}
else if ( (v11 & 0x200) != 0 )
{
v14 = (*_ctype_toupper_loc())[v10];
shiftpat[v14] |= v3;
}
v5 = v2[1];
v3 >>= 1;
++v2;
++v6;
v7 |= v3;
v4 = 1;
}
while ( (_BYTE)v5 );
LABEL_8:
if ( v15 )
epsilon = v8;
if ( v4 )
{
statemask = v7;
patlen = v6;
}
}
acceptpat = v3;
return makedfa_isra_0(a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // r15
unsigned __int64 v3; // r14
char v4; // cl
__int64 v5; // rax
int v6; // ebx
__int64 v7; // rbp
__int64 v8; // r12
const unsigned __int16 **v9; // rax
__int64 v10; // r13
unsigned __int16 v11; // ax
__int64 v12; // rax
__int64 v14; // rax
char v15; // [rsp+Bh] [rbp-3Dh]

v2 = a1;
v3 = 0x80000000LL;
statemask = 0x80000000LL;
memset(shiftpat, 0, sizeof(shiftpat));
v4 = 0;
epsilon = 0LL;
patlen = 0;
v5 = *a1;
if ( (_BYTE)v5 )
{
v15 = 0;
v6 = 0;
v7 = 0x80000000LL;
v8 = 0LL;
do
{
while ( (_BYTE)v5 == 32 )
{
v5 = *++v2;
v15 = 1;
v8 |= v3;
if ( !(_BYTE)v5 )
goto LABEL_8;
}
shiftpat[v5] |= v3;
v9 = _ctype_b_loc();
v10 = *v2;
v11 = (*v9)[v10];
if ( (v11 & 0x100) != 0 )
{
v12 = (*_ctype_tolower_loc())[v10];
shiftpat[v12] |= v3;
}
else if ( (v11 & 0x200) != 0 )
{
v14 = (*_ctype_toupper_loc())[v10];
shiftpat[v14] |= v3;
}
v5 = v2[1];
v3 >>= 1;
++v2;
++v6;
v7 |= v3;
v4 = 1;
}
while ( (_BYTE)v5 );
LABEL_8:
if ( v15 )
epsilon = v8;
if ( v4 )
{
statemask = v7;
patlen = v6;
}
}
acceptpat = v3;
return func4(a2);
}

original_code:
void
makepat(unsigned char *s, int mismatch)
{
 int i;
 unsigned long mask = 0x80000000;
 statemask = 0x80000000;
 epsilon = 0;
 patlen = 0;
 for(i=0;i<0x100;i++) shiftpat[i] = 0;
 for(;*s;s++){
  if(*s == ' '){
   epsilon |= mask;
  }
  else {
   shiftpat[*s] |= mask;
   if(((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISupper)){
    shiftpat[tolower(*s)] |= mask;
   }
   else if(((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISlower)){
    shiftpat[toupper(*s)] |= mask;
   }
   mask >>= 1;
   statemask |= mask;
   patlen++;
  }
 }
 acceptpat = mask;
 makedfa(mismatch);
}

canonical_original_code:
void makepat(unsigned char *s, int mismatch)
{
 int i;
 unsigned long mask = 0x80000000;
 statemask = 0x80000000;
 epsilon = 0;
 patlen = 0;
 for(i=0;i<0x100;i++) shiftpat[i] = 0;
 for(;*s;s++){
  if(*s == ' '){
   epsilon |= mask;
  }
  else {
   shiftpat[*s] |= mask;
   if(((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISupper)){
    shiftpat[tolower(*s)] |= mask;
   }
   else if(((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISlower)){
    shiftpat[toupper(*s)] |= mask;
   }
   mask >>= 1;
   statemask |= mask;
   patlen++;
  }
 }
 acceptpat = mask;
 makedfa(mismatch);
}

variable_types:
s
unsigned char *

variable_types:
mask
unsigned long


match

decompiled_code:
__int64 __fastcall match(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
char *v2; // rdx

v1 = *a1;
if ( !*a1 )
return (unsigned int)acceptp[0];
v2 = (char *)&trans;
do
{
++a1;
v2 = *(char **)&v2[8 * v1];
v1 = *a1;
}
while ( *a1 );
return (unsigned int)acceptp[(v2 - (char *)&trans) >> 11];
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
char *v2; // rdx

v1 = *a1;
if ( !*a1 )
return (unsigned int)acceptp[0];
v2 = (char *)&trans;
do
{
++a1;
v2 = *(char **)&v2[8 * v1];
v1 = *a1;
}
while ( *a1 );
return (unsigned int)acceptp[(v2 - (char *)&trans) >> 11];
}

original_code:
int
match(register unsigned char *s)
{
 register Pointer *state = trans;
 for(;*s;s++){
  state = (Pointer*)(state[*s]);
 }
 return acceptp[(state-trans)>>8];
}

canonical_original_code:
int match(unsigned char *s)
{
 register unsigned char **state = trans;
 for(;*s;s++){
  state = (unsigned char **)(state[*s]);
 }
 return acceptp[(state-trans)>>8];
}

variable_types:
state
unsigned char **


main

canonical_name: main

repo: masuyama/spawner

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // edx
int v4; // ecx
int v5; // er8
int v6; // er9
int v7; // edx
int v8; // ecx
int v9; // er8
int v10; // er9

set_log_level(7LL, argv, envp);
parse_options((unsigned int)argc, argv);
set_signal(2);
set_signal(15);
set_signal(3);
set_signal(1);
if ( byte_406504 == 1 && daemon(1, 0) == -1 )
{
print_log(3, (unsigned int)"failed to launch daemon.\n", v7, v8, v9, v10);
exit(-1);
}
process_init((unsigned int)nmemb);
keepgoing = 1;
do
process_session(config, &::argv);
while ( keepgoing );
process_release();
print_log(6, (unsigned int)"spawner end\n", v3, v4, v5, v6);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // edx
int v4; // ecx
int v5; // er8
int v6; // er9
int v7; // edx
int v8; // ecx
int v9; // er8
int v10; // er9

func19(7LL, argv, envp);
func10((unsigned int)argc, argv);
func11(2);
func11(15);
func11(3);
func11(1);
if ( byte_406504 == 1 && daemon(1, 0) == -1 )
{
func20(3, (unsigned int)"failed to launch daemon.\n", v7, v8, v9, v10);
exit(-1);
}
func14((unsigned int)nmemb);
keepgoing = 1;
do
func16(config, &::argv);
while ( keepgoing );
func15();
func20(6, (unsigned int)"spawner end\n", v3, v4, v5, v6);
exit(0);
}

original_code:
int main(int argc, char *argv[])
{
    set_log_level(7);
    parse_options(argc, argv);
    set_signal(2, catch_stop);
    set_signal(15, catch_stop);
    set_signal(3, catch_stop);
    set_signal(1, catch_hup);
    if (config.daemon_mode == 1) {
        int nochdir = 1;
        int noclose = 0;
        if (daemon(nochdir, noclose) == -1) {
            print_log(3, "failed to launch daemon.\n");
            exit(-1);
        }
    }
    process_init(config.concurrency);
    keepgoing = 1;
    while (keepgoing) {
        process_session(config.command, config.args);
    }
    process_release();
    print_log(6, "spawner end\n");
    exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: nochdir int

variable_types: noclose int


decompiled_code:
void catch_hup()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
static void catch_hup(int signo)
{
}

canonical_original_code:
static void catch_hup(int signo)
{
}

variable_types: signo int


decompiled_code:
__int64 __fastcall catch_stop(int sig, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
print_log(6, (unsigned int)"catch_stop : %d\n", sig, a4, a5, a6);
keepgoing = 0;
return process_signal(sig);
}

canonical_decompiled_code:
__int64 __fastcall func8(int sig, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
func20(6, (unsigned int)"catch_stop : %d\n", sig, a4, a5, a6);
keepgoing = 0;
return func17(sig);
}

original_code:
static void catch_stop(int signo)
{
    print_log(6, "catch_stop : %d\n", signo);
    keepgoing = 0;
    process_signal(signo);
}


decompiled_code:
int __fastcall print_help(const char *a1)
{
return fprintf(_bss_start, "%s [-h] [-d] [-c concurrency] {command line}\n", a1);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
return fprintf(_bss_start, "%s [-h] [-d] [-c concurrency] {command line}\n", a1);
}

original_code:
static void print_help(const char *prg)
{
    fprintf(stdout, "%s [-h] [-d] [-c concurrency] {command line}\n",
                    prg);
}

canonical_original_code:
static void print_help(char *prg)
{
    fprintf(stdout, "%s [-h] [-d] [-c concurrency] {command line}\n",
                    prg);
}

variable_types:
prg
char *


decompiled_code:
__int64 __fastcall parse_options(int a1, const char **a2, __int64 a3, __int64 a4, int a5, int a6)
{
int v6; // ebx
const char *v7; // rdx
__int64 v8; // rcx
int v9; // eax
int v10; // ecx
__int64 v11; // r14
__int64 result; // rax
__int64 v13; // rcx

v6 = 1;
if ( a1 <= 1 )
goto LABEL_20;
while ( 1 )
{
v7 = a2[v6];
v8 = v6;
if ( *v7 != 45 )
break;
v9 = *((unsigned __int8 *)v7 + 1);
if ( v9 != 99 || v7[2] )
{
v10 = *(unsigned __int8 *)v7;
if ( v10 != 45 )
goto LABEL_8;
if ( v9 == 104 && !v7[2] )
goto LABEL_20;
if ( v9 != 100 || v7[2] )
{
LABEL_8:
print_log(3, (unsigned int)"unknown option [%s]\n", (_DWORD)v7, v10, a5, a6);
exit(0);
}
++v6;
byte_406504 = 1;
if ( a1 <= v6 )
break;
}
else
{
v6 += 2;
LODWORD(nmemb) = atoi(a2[v8 + 1]);
if ( a1 <= v6 )
break;
}
}
if ( v6 == a1 )
{
LABEL_20:
print_help(*a2);
exit(0);
}
v11 = v6;
strncpy(config, a2[v11], 0x3FFuLL);
result = (unsigned int)(v6 + 1);
argv = config;
if ( a1 <= (int)result )
{
v13 = 1LL;
}
else
{
qword_404508 = (__int64)a2[v11 + 1];
result = 2LL;
while ( 1 )
{
v13 = (int)result;
if ( result == (unsigned int)(a1 - 2 - v6) + 2LL )
break;
(&argv)[result] = (char *)(&a2[v11])[result];
if ( ++result == 1023 )
{
v13 = 1023LL;
break;
}
}
}
(&argv)[v13] = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, const char **a2, __int64 a3, __int64 a4, int a5, int a6)
{
int v6; // ebx
const char *v7; // rdx
__int64 v8; // rcx
int v9; // eax
int v10; // ecx
__int64 v11; // r14
__int64 result; // rax
__int64 v13; // rcx

v6 = 1;
if ( a1 <= 1 )
goto LABEL_20;
while ( 1 )
{
v7 = a2[v6];
v8 = v6;
if ( *v7 != 45 )
break;
v9 = *((unsigned __int8 *)v7 + 1);
if ( v9 != 99 || v7[2] )
{
v10 = *(unsigned __int8 *)v7;
if ( v10 != 45 )
goto LABEL_8;
if ( v9 == 104 && !v7[2] )
goto LABEL_20;
if ( v9 != 100 || v7[2] )
{
LABEL_8:
func20(3, (unsigned int)"unknown option [%s]\n", (_DWORD)v7, v10, a5, a6);
exit(0);
}
++v6;
byte_406504 = 1;
if ( a1 <= v6 )
break;
}
else
{
v6 += 2;
LODWORD(nmemb) = atoi(a2[v8 + 1]);
if ( a1 <= v6 )
break;
}
}
if ( v6 == a1 )
{
LABEL_20:
func9(*a2);
exit(0);
}
v11 = v6;
strncpy(config, a2[v11], 0x3FFuLL);
result = (unsigned int)(v6 + 1);
argv = config;
if ( a1 <= (int)result )
{
v13 = 1LL;
}
else
{
qword_404508 = (__int64)a2[v11 + 1];
result = 2LL;
while ( 1 )
{
v13 = (int)result;
if ( result == (unsigned int)(a1 - 2 - v6) + 2LL )
break;
(&argv)[result] = (char *)(&a2[v11])[result];
if ( ++result == 1023 )
{
v13 = 1023LL;
break;
}
}
}
(&argv)[v13] = 0LL;
return result;
}

original_code:
static void parse_options(int argc, char *argv[])
{
    if (argc < 2) {
        print_help(argv[0]);
        exit(0);
    }
    int i;
    for (i = 1 ; i < argc ; i++) {
        if (argv[i][0] == '-') {
            if (strcmp(argv[i], "-c") == 0) {
                i++;
                config.concurrency = atoi(argv[i]);
            }
            else if (strcmp(argv[i], "-h") == 0) {
                print_help(argv[0]);
                exit(0);
            }
            else if (strcmp(argv[i], "-d") == 0) {
                config.daemon_mode = 1;
            }
            else {
                print_log(3, "unknown option [%s]\n", argv[i]);
                exit(0);
            }
        }
        else {
            break;
        }
    }
    if (argc == i) {
        print_help(argv[0]);
        exit(0);
    }
    strncpy(config.command, argv[i++], sizeof(config.command)-1);
    int c = 0;
    config.args[c++] = config.command;
    for (; i < argc ; i++) {
        config.args[c++] = argv[i];
        if (c >= 1023) {
            break;
        }
    }
    config.args[c] = ((void *)0);
}

variable_types: i int

variable_types: c int


decompiled_code:
int __fastcall set_signal(int sig, void (*a2)(int))
{
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v3.sa_handler = a2;
sigemptyset(&v3.sa_mask);
sigaddset(&v3.sa_mask, sig);
v3.sa_flags = 0;
return sigaction(sig, &v3, 0LL);
}

canonical_decompiled_code:
int __fastcall func11(int sig, void (*a2)(int))
{
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v3.sa_handler = a2;
sigemptyset(&v3.sa_mask);
sigaddset(&v3.sa_mask, sig);
v3.sa_flags = 0;
return sigaction(sig, &v3, 0LL);
}

original_code:
static void set_signal(int signo, void (*func)(int signo))
{
    struct sigaction act;
    act.__sigaction_handler.sa_handler = func;
    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask, signo);
    act.sa_flags = 0;
    sigaction(signo, &act, ((void *)0));
}

variable_types:
func
void (*)(int signo)

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

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


repo: matgoebl/kogmo-rtdb

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

if ( timeidx_p )
result = kogmo_timestamp_add_secs(*(_QWORD *)((char *)timeidx_p + 60), *((float *)timeidx_p + 12));
else
result = 0LL;
return result;
}

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

if ( timeidx_p )
result = kogmo_timestamp_add_secs(*(_QWORD *)((char *)timeidx_p + 60), *((float *)timeidx_p + 12));
else
result = 0LL;
return result;
}

original_code:
kogmo_timestamp_t timeidx_next_needed (void)
{
  if ( timeidx_p == ((void *)0) )
    return 0;
  return kogmo_timestamp_add_secs ( timeidx_p->last_ts, timeidx_p->interval);
}

canonical_original_code:
long timeidx_next_needed()
{
  if ( timeidx_p == ((void *)0) )
    return 0;
  return kogmo_timestamp_add_secs ( timeidx_p->last_ts, timeidx_p->interval);
}

return_type: long


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

if ( timeidx_p )
result = *(_QWORD *)((char *)timeidx_p + 52);
else
result = 0LL;
return result;
}

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

if ( timeidx_p )
result = *(_QWORD *)((char *)timeidx_p + 52);
else
result = 0LL;
return result;
}

original_code:
kogmo_timestamp_t timeidx_get_first (void)
{
  if ( timeidx_p == ((void *)0) )
    return 0;
  return timeidx_p->first_ts;
}

canonical_original_code:
long timeidx_get_first()
{
  if ( timeidx_p == ((void *)0) )
    return 0;
  return timeidx_p->first_ts;
}


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

if ( timeidx_p )
result = *(_QWORD *)((char *)timeidx_p + 60);
else
result = 0LL;
return result;
}

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

if ( timeidx_p )
result = *(_QWORD *)((char *)timeidx_p + 60);
else
result = 0LL;
return result;
}

original_code:
kogmo_timestamp_t timeidx_get_last (void)
{
  if ( timeidx_p == ((void *)0) )
    return 0;
  return timeidx_p->last_ts;
}

canonical_original_code:
long timeidx_get_last()
{
  if ( timeidx_p == ((void *)0) )
    return 0;
  return timeidx_p->last_ts;
}


decompiled_code:
__int64 __fastcall timeidx_add(__int64 a1, __int64 a2)
{
double v3; // xmm0_8
char *v4; // rax
__int64 v5; // rdi
double v6; // xmm0_8
char *v7; // rdi
int v8; // ebp
unsigned int i; // er13
__int64 v10; // rax
char *v11; // rax
int v12; // eax
int v13; // eax
unsigned int v14; // er12
unsigned int v15; // er8
__int64 result; // rax
unsigned int v17; // eax

if ( a1 <= 0 )
return 0xFFFFFFFFLL;
if ( a2 <= 0 || !timeidx_p )
return (unsigned int)-1;
v3 = kogmo_timestamp_diff_secs(*(_QWORD *)((char *)timeidx_p + 60), a1);
v4 = (char *)timeidx_p;
*(float *)&v3 = v3;
if ( *((float *)timeidx_p + 12) > *(float *)&v3 )
{
v15 = 0;
if ( *(_QWORD *)((char *)timeidx_p + 52) )
return v15;
LABEL_15:
*(_QWORD *)((char *)timeidx_p + 52) = a1;
v15 = 0;
*(_QWORD *)(v4 + 60) = a1;
*((_DWORD *)v4 + 17) = 0;
*(_QWORD *)(v4 + 76) = a1;
*(_QWORD *)(v4 + 84) = a2;
return v15;
}
v5 = *(_QWORD *)((char *)timeidx_p + 52);
if ( !v5 )
goto LABEL_15;
v6 = kogmo_timestamp_diff_secs(v5, a1);
v7 = (char *)timeidx_p;
v8 = (int)(v6 / *((float *)timeidx_p + 12));
if ( v8 < 0 )
return (unsigned int)-1;
for ( i = *((_DWORD *)timeidx_p + 17) + 1; i <= v8; *(_QWORD *)(v11 + 84) = a2 )
{
v12 = *((_DWORD *)v7 + 18);
if ( v12 - 1 <= i )
{
v13 = v12 + 6000;
*((_DWORD *)v7 + 18) = v13;
v14 = 16 * v13 + 76;
if ( timeidx_debug )
{
printf("%% timeidx: extending index size to %i bytes", v14);
putchar(10);
v7 = (char *)timeidx_p;
}
timeidx_p = realloc(v7, (int)v14);
v7 = (char *)timeidx_p;
if ( !timeidx_p )
{
v17 = getpid();
fprintf(stderr, "%i DIED in %s line %i: ", v17, "kogmo_rtdb_timeidx.c", 180LL);
fprintf(stderr, "cannot reallocate %i bytes of memory for index", v14);
fputc(10, stderr);
exit(1);
}
}
v10 = i++;
v11 = &v7[16 * v10];
*(_QWORD *)(v11 + 76) = a1;
}
v7[6] |= 2u;
*(_QWORD *)(v7 + 60) = a1;
result = 0LL;
*((_DWORD *)v7 + 17) = v8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
double v3; // xmm0_8
char *v4; // rax
__int64 v5; // rdi
double v6; // xmm0_8
char *v7; // rdi
int v8; // ebp
unsigned int i; // er13
__int64 v10; // rax
char *v11; // rax
int v12; // eax
int v13; // eax
unsigned int v14; // er12
unsigned int v15; // er8
__int64 result; // rax
unsigned int v17; // eax

if ( a1 <= 0 )
return 0xFFFFFFFFLL;
if ( a2 <= 0 || !timeidx_p )
return (unsigned int)-1;
v3 = kogmo_timestamp_diff_secs(*(_QWORD *)((char *)timeidx_p + 60), a1);
v4 = (char *)timeidx_p;
*(float *)&v3 = v3;
if ( *((float *)timeidx_p + 12) > *(float *)&v3 )
{
v15 = 0;
if ( *(_QWORD *)((char *)timeidx_p + 52) )
return v15;
LABEL_15:
*(_QWORD *)((char *)timeidx_p + 52) = a1;
v15 = 0;
*(_QWORD *)(v4 + 60) = a1;
*((_DWORD *)v4 + 17) = 0;
*(_QWORD *)(v4 + 76) = a1;
*(_QWORD *)(v4 + 84) = a2;
return v15;
}
v5 = *(_QWORD *)((char *)timeidx_p + 52);
if ( !v5 )
goto LABEL_15;
v6 = kogmo_timestamp_diff_secs(v5, a1);
v7 = (char *)timeidx_p;
v8 = (int)(v6 / *((float *)timeidx_p + 12));
if ( v8 < 0 )
return (unsigned int)-1;
for ( i = *((_DWORD *)timeidx_p + 17) + 1; i <= v8; *(_QWORD *)(v11 + 84) = a2 )
{
v12 = *((_DWORD *)v7 + 18);
if ( v12 - 1 <= i )
{
v13 = v12 + 6000;
*((_DWORD *)v7 + 18) = v13;
v14 = 16 * v13 + 76;
if ( timeidx_debug )
{
printf("%% timeidx: extending index size to %i bytes", v14);
putchar(10);
v7 = (char *)timeidx_p;
}
timeidx_p = realloc(v7, (int)v14);
v7 = (char *)timeidx_p;
if ( !timeidx_p )
{
v17 = getpid();
fprintf(stderr, "%i DIED in %s line %i: ", v17, "kogmo_rtdb_timeidx.c", 180LL);
fprintf(stderr, "cannot reallocate %i bytes of memory for index", v14);
fputc(10, stderr);
exit(1);
}
}
v10 = i++;
v11 = &v7[16 * v10];
*(_QWORD *)(v11 + 76) = a1;
}
v7[6] |= 2u;
*(_QWORD *)(v7 + 60) = a1;
result = 0LL;
*((_DWORD *)v7 + 17) = v8;
return result;
}

original_code:
int timeidx_add (kogmo_timestamp_t ts, off_t off)
{
  float diff_to_last;
  int idx;
  unsigned i;
  if ( ts <= 0 || off <= 0 || timeidx_p == ((void *)0) )
    return -1;
  diff_to_last = kogmo_timestamp_diff_secs ( timeidx_p->last_ts, ts);
  if ( diff_to_last < timeidx_p->interval && timeidx_p->first_ts != 0 )
    return 0;
  if ( timeidx_p->first_ts == 0 )
    {
      timeidx_p->first_ts = ts;
      timeidx_p->last_ts = ts;
      timeidx_p->last_entry = 0;
      timeidx_p->entry[0].ts = ts;
      timeidx_p->entry[0].off = off;
      return 0;
    }
  idx = (int) ( kogmo_timestamp_diff_secs ( timeidx_p->first_ts, ts ) / timeidx_p->interval );
  if ( idx < 0 )
    return -1;
  for ( i = timeidx_p->last_entry + 1; i <= (unsigned)idx; i++ )
    {
      if ( i >= timeidx_p->max_entries - 1 )
        {
          int size;
          timeidx_p->max_entries += ((int)( 10 * 60 / (0.1) ));
          size = (sizeof(timeidx_info_t)) + (sizeof(timeidx_entry_t)) * timeidx_p->max_entries;
          if(timeidx_debug) do{printf("%% timeidx: ""extending index size to %i bytes",size);putchar(10);}while(0);
          timeidx_p = realloc (timeidx_p, size);
          if ( timeidx_p == ((void *)0) )
            do { fprintf(stderr,"%i DIED in %s line %i: ",getpid(),"kogmo_rtdb_timeidx.c",180); fprintf(stderr,"cannot reallocate %i bytes of memory for index", size); fprintf(stderr,"\n"); exit(1); } while (0);
        }
      timeidx_p->entry[i].ts = ts;
      timeidx_p->entry[i].off = off;
   }
  timeidx_p->last_ts = ts;
  timeidx_p->last_entry = idx;
  timeidx_p->flags.changed = 1;
  return 0;
}

canonical_original_code:
int timeidx_add(long ts, long off)
{
  float diff_to_last;
  int idx;
  unsigned int i;
  if ( ts <= 0 || off <= 0 || timeidx_p == ((void *)0) )
    return -1;
  diff_to_last = kogmo_timestamp_diff_secs ( timeidx_p->last_ts, ts);
  if ( diff_to_last < timeidx_p->interval && timeidx_p->first_ts != 0 )
    return 0;
  if ( timeidx_p->first_ts == 0 )
    {
      timeidx_p->first_ts = ts;
      timeidx_p->last_ts = ts;
      timeidx_p->last_entry = 0;
      timeidx_p->entry[0].ts = ts;
      timeidx_p->entry[0].off = off;
      return 0;
    }
  idx = (int) ( kogmo_timestamp_diff_secs ( timeidx_p->first_ts, ts ) / timeidx_p->interval );
  if ( idx < 0 )
    return -1;
  for ( i = timeidx_p->last_entry + 1; i <= (unsigned int)idx; i++ )
    {
      if ( i >= timeidx_p->max_entries - 1 )
        {
          int size;
          timeidx_p->max_entries += ((int)( 10 * 60 / (0.1) ));
          size = (sizeof(timeidx_info_t)) + (sizeof(timeidx_entry_t)) * timeidx_p->max_entries;
          if(timeidx_debug) do{printf("%% timeidx: ""extending index size to %i bytes",size);putchar(10);}while(0);
          timeidx_p = realloc (timeidx_p, size);
          if ( timeidx_p == ((void *)0) )
            do { fprintf(stderr,"%i DIED in %s line %i: ",getpid(),"kogmo_rtdb_timeidx.c",180); fprintf(stderr,"cannot reallocate %i bytes of memory for index", size); fprintf(stderr,"\n"); exit(1); } while (0);
        }
      timeidx_p->entry[i].ts = ts;
      timeidx_p->entry[i].off = off;
   }
  timeidx_p->last_ts = ts;
  timeidx_p->last_entry = idx;
  timeidx_p->flags.changed = 1;
  return 0;
}

variable_types: ts long

variable_types: off long

variable_types: idx int

variable_types:
i
unsigned int

variable_types: size int


decompiled_code:
__int64 __fastcall timeidx_lookup(__int64 a1)
{
double v1; // xmm0_8
char *v2; // rax
__int64 v3; // rsi

if ( timeidx_debug )
{
printf("%% timeidx: loopup: %lli", a1);
putchar(10);
}
if ( !timeidx_p )
return -1LL;
if ( *(_QWORD *)((char *)timeidx_p + 60) < a1 )
return -1LL;
v1 = kogmo_timestamp_diff_secs(*(_QWORD *)((char *)timeidx_p + 52), a1);
v2 = (char *)timeidx_p;
v3 = (unsigned int)(int)(v1 / *((float *)timeidx_p + 12));
if ( (int)v3 < 0 )
return -1LL;
if ( *((_DWORD *)timeidx_p + 17) <= (int)v3 )
v3 = *((unsigned int *)timeidx_p + 17);
if ( timeidx_debug )
{
printf("%% timeidx: loopup found: %i. = %lli", v3, *(_QWORD *)((char *)timeidx_p + 16 * (int)v3 + 84));
putchar(10);
v2 = (char *)timeidx_p;
}
return *(_QWORD *)&v2[16 * (int)v3 + 84];
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
double v1; // xmm0_8
char *v2; // rax
__int64 v3; // rsi

if ( timeidx_debug )
{
printf("%% timeidx: loopup: %lli", a1);
putchar(10);
}
if ( !timeidx_p )
return -1LL;
if ( *(_QWORD *)((char *)timeidx_p + 60) < a1 )
return -1LL;
v1 = kogmo_timestamp_diff_secs(*(_QWORD *)((char *)timeidx_p + 52), a1);
v2 = (char *)timeidx_p;
v3 = (unsigned int)(int)(v1 / *((float *)timeidx_p + 12));
if ( (int)v3 < 0 )
return -1LL;
if ( *((_DWORD *)timeidx_p + 17) <= (int)v3 )
v3 = *((unsigned int *)timeidx_p + 17);
if ( timeidx_debug )
{
printf("%% timeidx: loopup found: %i. = %lli", v3, *(_QWORD *)((char *)timeidx_p + 16 * (int)v3 + 84));
putchar(10);
v2 = (char *)timeidx_p;
}
return *(_QWORD *)&v2[16 * (int)v3 + 84];
}

original_code:
off_t timeidx_lookup (kogmo_timestamp_t ts)
{
  int idx;
  if(timeidx_debug) do{printf("%% timeidx: ""loopup: %lli", (long long int)ts);putchar(10);}while(0);
  if ( timeidx_p == ((void *)0) || ts > timeidx_p->last_ts )
    return -1;
  idx = (int) ( kogmo_timestamp_diff_secs ( timeidx_p->first_ts, ts ) / timeidx_p->interval );
  if ( idx < 0 )
    return -1;
  if ( idx > (int)timeidx_p->last_entry )
    idx = timeidx_p->last_entry;
  if(timeidx_debug) do{printf("%% timeidx: ""loopup found: %i. =  %lli", idx, (long long int)timeidx_p->entry[idx].off);putchar(10);}while(0);
  return timeidx_p->entry[idx].off;
}

canonical_original_code:
long timeidx_lookup(long ts)
{
  int idx;
  if(timeidx_debug) do{printf("%% timeidx: ""loopup: %lli", (long long)ts);putchar(10);}while(0);
  if ( timeidx_p == ((void *)0) || ts > timeidx_p->last_ts )
    return -1;
  idx = (int) ( kogmo_timestamp_diff_secs ( timeidx_p->first_ts, ts ) / timeidx_p->interval );
  if ( idx < 0 )
    return -1;
  if ( idx > (int)timeidx_p->last_entry )
    idx = timeidx_p->last_entry;
  if(timeidx_debug) do{printf("%% timeidx: ""loopup found: %i. =  %lli", idx, (long long)timeidx_p->entry[idx].off);putchar(10);}while(0);
  return timeidx_p->entry[idx].off;
}


decompiled_code:
__int64 __fastcall kogmo_rtdb_obj_trace_send(__int64 a1, int a2, __int64 a3, unsigned int a4, int a5, int a6)
{
__int64 v6; // rax
__int64 v13; // rdi
unsigned int v15; // eax
FILE *v16; // rdi
FILE *v17; // rdi
FILE *v18; // rsi
int v19; // [rsp+0h] [rbp-58h] BYREF
__int64 v20; // [rsp+8h] [rbp-50h]
unsigned int v21; // [rsp+10h] [rbp-48h]
int v22; // [rsp+14h] [rbp-44h]
int v23; // [rsp+18h] [rbp-40h]

v6 = *(_QWORD *)(a1 + 328);
if ( !*(_DWORD *)(v6 + 240108) || !*(_DWORD *)(v6 + 240104) )
return 4294967274LL;
if ( (kogmo_rtdb_debug & 0x100) != 0 )
{
v15 = getpid();
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v16 = stdout;
else
v16 = stderr;
fprintf(v16, "%d DBG: ", v15);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v17 = stdout;
else
v17 = stderr;
fprintf(v17, "TRACE: @%lli OID %lli: %i", a3, a2, a4);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v18 = stdout;
else
v18 = stderr;
fputc(10, v18);
}
v13 = *(unsigned int *)(a1 + 492);
v19 = a2;
v20 = a3;
v21 = a4;
v22 = a5;
v23 = a6;
kogmo_rtdb_ipc_mq_send(v13, &v19, 32LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3, unsigned int a4, int a5, int a6)
{
__int64 v6; // rax
__int64 v13; // rdi
unsigned int v15; // eax
FILE *v16; // rdi
FILE *v17; // rdi
FILE *v18; // rsi
int v19; // [rsp+0h] [rbp-58h] BYREF
__int64 v20; // [rsp+8h] [rbp-50h]
unsigned int v21; // [rsp+10h] [rbp-48h]
int v22; // [rsp+14h] [rbp-44h]
int v23; // [rsp+18h] [rbp-40h]

v6 = *(_QWORD *)(a1 + 328);
if ( !*(_DWORD *)(v6 + 240108) || !*(_DWORD *)(v6 + 240104) )
return 4294967274LL;
if ( (kogmo_rtdb_debug & 0x100) != 0 )
{
v15 = getpid();
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v16 = stdout;
else
v16 = stderr;
fprintf(v16, "%d DBG: ", v15);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v17 = stdout;
else
v17 = stderr;
fprintf(v17, "TRACE: @%lli OID %lli: %i", a3, a2, a4);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v18 = stdout;
else
v18 = stderr;
fputc(10, v18);
}
v13 = *(unsigned int *)(a1 + 492);
v19 = a2;
v20 = a3;
v21 = a4;
v22 = a5;
v23 = a6;
kogmo_rtdb_ipc_mq_send(v13, &v19, 32LL);
return 0LL;
}

original_code:
int
kogmo_rtdb_obj_trace_send (kogmo_rtdb_handle_t *db_h,
                           kogmo_rtdb_objid_t oid,
                           kogmo_timestamp_t ts,
                           enum kogmo_rtdb_trace_event event,
                           int32_t obj_slot, int32_t hist_slot)
{
  if ( db_h->localdata_p->rtdb_tracebufsize == 0 )
    return -22;
  if ( !db_h->localdata_p->rtdb_trace)
    return -22;
  struct kogmo_rtdb_trace_msg tracemsg;
  do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"TRACE: @%lli OID %lli: %i", (long long int)ts, (long long int)oid, event); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  tracemsg.oid = oid;
  tracemsg.ts = ts;
  tracemsg.event = event;
  tracemsg.obj_slot = obj_slot;
  tracemsg.hist_slot = hist_slot;
  kogmo_rtdb_ipc_mq_send(db_h->ipc_h.tracefd, &tracemsg, sizeof(tracemsg));
  return 0;
}

canonical_original_code:
int kogmo_rtdb_obj_trace_send(struct kogmo_rtdb_handle_t *db_h, int oid, long ts, enum kogmo_rtdb_trace_event event, int obj_slot, int hist_slot)
{
  if ( db_h->localdata_p->rtdb_tracebufsize == 0 )
    return -22;
  if ( !db_h->localdata_p->rtdb_trace)
    return -22;
  struct kogmo_rtdb_trace_msg tracemsg;
  do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"TRACE: @%lli OID %lli: %i", (long long)ts, (long long)oid, event); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  tracemsg.oid = oid;
  tracemsg.ts = ts;
  tracemsg.event = event;
  tracemsg.obj_slot = obj_slot;
  tracemsg.hist_slot = hist_slot;
  kogmo_rtdb_ipc_mq_send(db_h->ipc_h.tracefd, &tracemsg, sizeof(tracemsg));
  return 0;
}

variable_types: struct kogmo_rtdb_handle_t { struct kogmo_rtdb_obj_info_t { int oid; char name[32]; long created_ts; int created_proc; long lastmodified_ts; int lastmodified_proc; long deleted_ts; int deleted_proc; int parent_oid; int otype; int size_max; float history_interval; float avg_cycletime; float max_cycletime; struct { unsigned int read_deny; unsigned int write_allow; unsigned int keep_alloc; unsigned int unique; unsigned int cycle_watch; unsigned int persistent; unsigned int parent_delete; unsigned int no_notifies; unsigned int immediately_delete; unsigned int withhold_stale; } flags; int history_size; int history_slot; int buffer_idx; } procobjmeta; struct kogmo_rtdb_obj_c3_process_t { struct kogmo_rtdb_subobj_base_t { long committed_ts; int committed_proc; long data_ts; int size; } base; struct kogmo_rtdb_subobj_c3_process_t { int proc_oid; unsigned int pid; unsigned int tid; unsigned int flags; unsigned int status; char statusmsg[160]; unsigned int version; unsigned int uid; } process; } procobj; struct kogmo_rtdb_obj_local_t { unsigned long objmeta_oid_next; struct kogmo_rtdb_obj_info_t objmeta[1000]; unsigned int objmeta_free; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } objmeta_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } objmeta_changenotify; union pthread_mutex_t obj_lock[1000]; union pthread_cond_t obj_changenotify[1000]; union pthread_mutex_t obj_changenotify_lock[1000]; int rtdb_trace; int rtdb_tracebufsize; struct { unsigned int simmode; unsigned int no_notifies; } flags; long sim_ts; float default_history_interval; float default_max_cycletime; float default_keep_deleted_interval; unsigned long heap_size; unsigned long heap_free; unsigned long heap_used; union pthread_mutex_t heap_lock; char heap[1]; } *localdata_p; long localdata_size; void *heapinfo; struct kogmo_rtdb_ipc_handle_t { int shmfd; char shmid[32]; struct kogmo_rtdb_ipc_shm_t { unsigned int revision; int manager_pid; long manager_alive_ts; union pthread_mutex_t global_lock; struct kogmo_rtdb_ipc_process_t { int proc_oid; long connected_ts; long disconnected_ts; float cycletime; int pid; unsigned long tid; unsigned int flags; char name[32]; } proc[100]; unsigned int proc_free; union pthread_mutex_t proc_lock; unsigned long proc_oid_next; long data_size; } *shm_p; long shm_size; struct kogmo_rtdb_ipc_process_t this_process; int this_process_slot; int tracefd; int rxtracefd; } ipc_h; } *

variable_types: oid int

variable_types: enum kogmo_rtdb_trace_event { KOGMO_RTDB_TRACE_INSERTED=1, KOGMO_RTDB_TRACE_DELETED=2, KOGMO_RTDB_TRACE_UPDATED=3, KOGMO_RTDB_TRACE_CHANGED=4 }

variable_types: struct kogmo_rtdb_trace_msg { int oid; long ts; unsigned int event; int obj_slot; int hist_slot; }

user_defined_types: struct kogmo_rtdb_handle_t { struct kogmo_rtdb_obj_info_t procobjmeta; struct kogmo_rtdb_obj_c3_process_t procobj; struct kogmo_rtdb_obj_local_t *localdata_p; long localdata_size; void *heapinfo; struct kogmo_rtdb_ipc_handle_t ipc_h; }

user_defined_types: struct kogmo_rtdb_obj_c3_process_t { struct kogmo_rtdb_subobj_base_t base; struct kogmo_rtdb_subobj_c3_process_t process; }

user_defined_types: struct kogmo_rtdb_ipc_handle_t { int shmfd; char shmid[32]; struct kogmo_rtdb_ipc_shm_t *shm_p; long shm_size; struct kogmo_rtdb_ipc_process_t this_process; int this_process_slot; int tracefd; int rxtracefd; }

user_defined_types: struct kogmo_rtdb_obj_local_t { unsigned long objmeta_oid_next; struct kogmo_rtdb_obj_info_t objmeta[1000]; unsigned int objmeta_free; union pthread_mutex_t objmeta_lock; union pthread_cond_t objmeta_changenotify; union pthread_mutex_t obj_lock[1000]; union pthread_cond_t obj_changenotify[1000]; union pthread_mutex_t obj_changenotify_lock[1000]; int rtdb_trace; int rtdb_tracebufsize; struct { unsigned int simmode; unsigned int no_notifies; } flags; long sim_ts; float default_history_interval; float default_max_cycletime; float default_keep_deleted_interval; unsigned long heap_size; unsigned long heap_free; unsigned long heap_used; union pthread_mutex_t heap_lock; char heap[1]; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct kogmo_rtdb_ipc_shm_t { unsigned int revision; int manager_pid; long manager_alive_ts; union pthread_mutex_t global_lock; struct kogmo_rtdb_ipc_process_t proc[100]; unsigned int proc_free; union pthread_mutex_t proc_lock; unsigned long proc_oid_next; long data_size; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall kogmo_rtdb_obj_trace_activate(__int64 a1, unsigned int a2, _DWORD *a3)
{
__int64 result; // rax
__int64 v7; // rdx
FILE *v8; // rdi
FILE *v9; // rdi
FILE *v10; // rsi
int v11; // ebp
__int64 v12; // [rsp-48h] [rbp-48h] BYREF

if ( !*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240108LL) )
return 4294967274LL;
if ( (kogmo_rtdb_debug & 0x100) != 0 )
{
v7 = (unsigned int)getpid();
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v8 = stdout;
else
v8 = stderr;
fprintf(v8, "%d DBG: ", v7);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v9 = stdout;
else
v9 = stderr;
fprintf(v9, "kogmo_rtdb_obj_trace_activate := %i", a2);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v10 = stdout;
else
v10 = stderr;
fputc(10, v10);
if ( !a2 )
goto LABEL_4;
LABEL_15:
v11 = 300;
kogmo_rtdb_ipc_mq_receive_init(a1 + 496, a1 + 356);
*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240104LL) = 1;
do
{
if ( (int)kogmo_rtdb_ipc_mq_curmsgs(*(unsigned int *)(a1 + 496)) <= 0 )
break;
kogmo_rtdb_ipc_mq_receive(*(unsigned int *)(a1 + 496), &v12, 32LL);
--v11;
}
while ( v11 );
goto LABEL_5;
}
if ( a2 )
goto LABEL_15;
LABEL_4:
*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240104LL) = 0;
*(_DWORD *)(a1 + 496) = 0;
LABEL_5:
result = 0LL;
if ( a3 )
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 328) + 240108LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, _DWORD *a3)
{
__int64 result; // rax
__int64 v7; // rdx
FILE *v8; // rdi
FILE *v9; // rdi
FILE *v10; // rsi
int v11; // ebp
__int64 v12; // [rsp-48h] [rbp-48h] BYREF

if ( !*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240108LL) )
return 4294967274LL;
if ( (kogmo_rtdb_debug & 0x100) != 0 )
{
v7 = (unsigned int)getpid();
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v8 = stdout;
else
v8 = stderr;
fprintf(v8, "%d DBG: ", v7);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v9 = stdout;
else
v9 = stderr;
fprintf(v9, "kogmo_rtdb_obj_trace_activate := %i", a2);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v10 = stdout;
else
v10 = stderr;
fputc(10, v10);
if ( !a2 )
goto LABEL_4;
LABEL_15:
v11 = 300;
kogmo_rtdb_ipc_mq_receive_init(a1 + 496, a1 + 356);
*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240104LL) = 1;
do
{
if ( (int)kogmo_rtdb_ipc_mq_curmsgs(*(unsigned int *)(a1 + 496)) <= 0 )
break;
kogmo_rtdb_ipc_mq_receive(*(unsigned int *)(a1 + 496), &v12, 32LL);
--v11;
}
while ( v11 );
goto LABEL_5;
}
if ( a2 )
goto LABEL_15;
LABEL_4:
*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240104LL) = 0;
*(_DWORD *)(a1 + 496) = 0;
LABEL_5:
result = 0LL;
if ( a3 )
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 328) + 240108LL);
return result;
}

original_code:
int
kogmo_rtdb_obj_trace_activate (kogmo_rtdb_handle_t *db_h,
                           int active, int *tracebufsize)
{
  struct kogmo_rtdb_trace_msg tracemsg;
  int i;
  if ( db_h->localdata_p->rtdb_tracebufsize == 0 )
    return -22;
  do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"kogmo_rtdb_obj_trace_activate := %i", active); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  if ( active )
    {
      kogmo_rtdb_ipc_mq_receive_init(&db_h->ipc_h.rxtracefd, db_h->ipc_h.shmid);
      db_h->localdata_p->rtdb_trace = 1;
      for(i=0;i<300;i++) {
       if ( kogmo_rtdb_ipc_mq_curmsgs(db_h->ipc_h.rxtracefd) <= 0 )
        break;
       kogmo_rtdb_ipc_mq_receive(db_h->ipc_h.rxtracefd, &tracemsg, sizeof(tracemsg));
      }
    }
  else
    {
      db_h->localdata_p->rtdb_trace = 0;
      db_h->ipc_h.rxtracefd = 0;
    }
  if ( tracebufsize != ((void *)0) )
    *tracebufsize = db_h->localdata_p->rtdb_tracebufsize;
  return 0;
}

canonical_original_code:
int kogmo_rtdb_obj_trace_activate(struct kogmo_rtdb_handle_t *db_h, int active, int *tracebufsize)
{
  struct kogmo_rtdb_trace_msg tracemsg;
  int i;
  if ( db_h->localdata_p->rtdb_tracebufsize == 0 )
    return -22;
  do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"kogmo_rtdb_obj_trace_activate := %i", active); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  if ( active )
    {
      kogmo_rtdb_ipc_mq_receive_init(&db_h->ipc_h.rxtracefd, db_h->ipc_h.shmid);
      db_h->localdata_p->rtdb_trace = 1;
      for(i=0;i<300;i++) {
       if ( kogmo_rtdb_ipc_mq_curmsgs(db_h->ipc_h.rxtracefd) <= 0 )
        break;
       kogmo_rtdb_ipc_mq_receive(db_h->ipc_h.rxtracefd, &tracemsg, sizeof(tracemsg));
      }
    }
  else
    {
      db_h->localdata_p->rtdb_trace = 0;
      db_h->ipc_h.rxtracefd = 0;
    }
  if ( tracebufsize != ((void *)0) )
    *tracebufsize = db_h->localdata_p->rtdb_tracebufsize;
  return 0;
}

variable_types: active int

variable_types:
tracebufsize
int *

user_defined_types: struct kogmo_rtdb_trace_msg { int oid; long ts; unsigned int event; int obj_slot; int hist_slot; }

user_defined_types: struct kogmo_rtdb_obj_info_t { int oid; char name[32]; long created_ts; int created_proc; long lastmodified_ts; int lastmodified_proc; long deleted_ts; int deleted_proc; int parent_oid; int otype; int size_max; float history_interval; float avg_cycletime; float max_cycletime; struct { unsigned int read_deny; unsigned int write_allow; unsigned int keep_alloc; unsigned int unique; unsigned int cycle_watch; unsigned int persistent; unsigned int parent_delete; unsigned int no_notifies; unsigned int immediately_delete; unsigned int withhold_stale; } flags; int history_size; int history_slot; int buffer_idx; }

user_defined_types: struct kogmo_rtdb_subobj_base_t { long committed_ts; int committed_proc; long data_ts; int size; }

user_defined_types: struct kogmo_rtdb_subobj_c3_process_t { int proc_oid; unsigned int pid; unsigned int tid; unsigned int flags; unsigned int status; char statusmsg[160]; unsigned int version; unsigned int uid; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

user_defined_types: struct kogmo_rtdb_ipc_process_t { int proc_oid; long connected_ts; long disconnected_ts; float cycletime; int pid; unsigned long tid; unsigned int flags; char name[32]; }


decompiled_code:
__int64 __fastcall kogmo_rtdb_obj_trace_receive(__int64 a1, int *a2, _QWORD *a3, unsigned int *a4, _DWORD *a5, _DWORD *a6)
{
__int64 v6; // rax
__int64 v8; // rdi
int v11; // ebp
int v12; // er12
__int64 v14; // rdx
FILE *v15; // rdi
FILE *v16; // rdi
FILE *v17; // rsi
__int64 v18; // rdx
FILE *v19; // rdi
FILE *v20; // rdi
FILE *v21; // rsi
unsigned int v25; // [rsp+1Ch] [rbp-5Ch]
int v26; // [rsp+20h] [rbp-58h] BYREF
__int64 v27; // [rsp+28h] [rbp-50h]
unsigned int v28; // [rsp+30h] [rbp-48h]
int v29; // [rsp+34h] [rbp-44h]
int v30; // [rsp+38h] [rbp-40h]

v6 = *(_QWORD *)(a1 + 328);
if ( !*(_DWORD *)(v6 + 240108) )
return 4294967274LL;
if ( !*(_DWORD *)(v6 + 240104) )
return 4294967274LL;
v8 = *(unsigned int *)(a1 + 496);
if ( !(_DWORD)v8 )
return 4294967274LL;
v11 = kogmo_rtdb_ipc_mq_curmsgs(v8);
v25 = kogmo_rtdb_ipc_mq_receive(*(unsigned int *)(a1 + 496), &v26, 32LL);
v12 = kogmo_rtdb_ipc_mq_curmsgs(*(unsigned int *)(a1 + 496));
if ( (kogmo_rtdb_debug & 0x100) != 0 )
{
v14 = (unsigned int)getpid();
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v15 = stdout;
else
v15 = stderr;
fprintf(v15, "%d DBG: ", v14);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v16 = stdout;
else
v16 = stderr;
fprintf(v16, "* TRACE: %d bytes, @%lli OID %lli: %i", v25, v27, v26, v28);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v17 = stdout;
else
v17 = stderr;
fputc(10, v17);
}
*a2 = v26;
*a3 = v27;
*a4 = v28;
if ( a5 )
*a5 = v29;
if ( a6 )
*a6 = v30;
if ( (kogmo_rtdb_debug & 0x100) != 0 )
{
v18 = (unsigned int)getpid();
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v19 = stdout;
else
v19 = stderr;
fprintf(v19, "%d DBG: ", v18);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v20 = stdout;
else
v20 = stderr;
fprintf(v20, "GOT TRACE: @%lli OID %lli: %i", *a3, *a2, *a4);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v21 = stdout;
else
v21 = stderr;
fputc(10, v21);
}
if ( v11 < v12 )
v11 = v12;
return (unsigned int)(*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240108LL) - v11);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int *a2, _QWORD *a3, unsigned int *a4, _DWORD *a5, _DWORD *a6)
{
__int64 v6; // rax
__int64 v8; // rdi
int v11; // ebp
int v12; // er12
__int64 v14; // rdx
FILE *v15; // rdi
FILE *v16; // rdi
FILE *v17; // rsi
__int64 v18; // rdx
FILE *v19; // rdi
FILE *v20; // rdi
FILE *v21; // rsi
unsigned int v25; // [rsp+1Ch] [rbp-5Ch]
int v26; // [rsp+20h] [rbp-58h] BYREF
__int64 v27; // [rsp+28h] [rbp-50h]
unsigned int v28; // [rsp+30h] [rbp-48h]
int v29; // [rsp+34h] [rbp-44h]
int v30; // [rsp+38h] [rbp-40h]

v6 = *(_QWORD *)(a1 + 328);
if ( !*(_DWORD *)(v6 + 240108) )
return 4294967274LL;
if ( !*(_DWORD *)(v6 + 240104) )
return 4294967274LL;
v8 = *(unsigned int *)(a1 + 496);
if ( !(_DWORD)v8 )
return 4294967274LL;
v11 = kogmo_rtdb_ipc_mq_curmsgs(v8);
v25 = kogmo_rtdb_ipc_mq_receive(*(unsigned int *)(a1 + 496), &v26, 32LL);
v12 = kogmo_rtdb_ipc_mq_curmsgs(*(unsigned int *)(a1 + 496));
if ( (kogmo_rtdb_debug & 0x100) != 0 )
{
v14 = (unsigned int)getpid();
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v15 = stdout;
else
v15 = stderr;
fprintf(v15, "%d DBG: ", v14);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v16 = stdout;
else
v16 = stderr;
fprintf(v16, "* TRACE: %d bytes, @%lli OID %lli: %i", v25, v27, v26, v28);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v17 = stdout;
else
v17 = stderr;
fputc(10, v17);
}
*a2 = v26;
*a3 = v27;
*a4 = v28;
if ( a5 )
*a5 = v29;
if ( a6 )
*a6 = v30;
if ( (kogmo_rtdb_debug & 0x100) != 0 )
{
v18 = (unsigned int)getpid();
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v19 = stdout;
else
v19 = stderr;
fprintf(v19, "%d DBG: ", v18);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v20 = stdout;
else
v20 = stderr;
fprintf(v20, "GOT TRACE: @%lli OID %lli: %i", *a3, *a2, *a4);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v21 = stdout;
else
v21 = stderr;
fputc(10, v21);
}
if ( v11 < v12 )
v11 = v12;
return (unsigned int)(*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240108LL) - v11);
}

original_code:
int
kogmo_rtdb_obj_trace_receive (kogmo_rtdb_handle_t *db_h,
                           kogmo_rtdb_objid_t *oid,
                           kogmo_timestamp_t *ts,
                                                           int *event,
                           int32_t *obj_slot, int32_t *hist_slot)
{
  int ret,msgcount1,msgcount2;
  struct kogmo_rtdb_trace_msg tracemsg;
  if ( db_h->localdata_p->rtdb_tracebufsize == 0 )
    return -22;
  if ( !db_h->localdata_p->rtdb_trace || !db_h->ipc_h.rxtracefd )
    return -22;
  msgcount1 = kogmo_rtdb_ipc_mq_curmsgs(db_h->ipc_h.rxtracefd);
  ret = kogmo_rtdb_ipc_mq_receive(db_h->ipc_h.rxtracefd, &tracemsg, sizeof(tracemsg));
  msgcount2 = kogmo_rtdb_ipc_mq_curmsgs(db_h->ipc_h.rxtracefd);
  do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"* TRACE: %d bytes, @%lli OID %lli: %i", ret, (long long int)tracemsg.ts, (long long int)tracemsg.oid, tracemsg.event); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  *oid = tracemsg.oid;
  *ts = tracemsg.ts;
  *event = tracemsg.event;
  if (obj_slot)
    *obj_slot = tracemsg.obj_slot;
  if (hist_slot)
    *hist_slot = tracemsg.hist_slot;
  do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"GOT TRACE: @%lli OID %lli: %i", (long long int)*ts, (long long int)*oid, *event); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  if(msgcount2>msgcount1) msgcount1=msgcount2;
  return db_h->localdata_p->rtdb_tracebufsize - msgcount1;
}

canonical_original_code:
int kogmo_rtdb_obj_trace_receive(struct kogmo_rtdb_handle_t *db_h, int *oid, long *ts, int *event, int *obj_slot, int *hist_slot)
{
  int ret; int msgcount1; int msgcount2;
  struct kogmo_rtdb_trace_msg tracemsg;
  if ( db_h->localdata_p->rtdb_tracebufsize == 0 )
    return -22;
  if ( !db_h->localdata_p->rtdb_trace || !db_h->ipc_h.rxtracefd )
    return -22;
  msgcount1 = kogmo_rtdb_ipc_mq_curmsgs(db_h->ipc_h.rxtracefd);
  ret = kogmo_rtdb_ipc_mq_receive(db_h->ipc_h.rxtracefd, &tracemsg, sizeof(tracemsg));
  msgcount2 = kogmo_rtdb_ipc_mq_curmsgs(db_h->ipc_h.rxtracefd);
  do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"* TRACE: %d bytes, @%lli OID %lli: %i", ret, (long long)tracemsg.ts, (long long)tracemsg.oid, tracemsg.event); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  *oid = tracemsg.oid;
  *ts = tracemsg.ts;
  *event = tracemsg.event;
  if (obj_slot)
    *obj_slot = tracemsg.obj_slot;
  if (hist_slot)
    *hist_slot = tracemsg.hist_slot;
  do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"GOT TRACE: @%lli OID %lli: %i", (long long)*ts, (long long)*oid, *event); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  if(msgcount2>msgcount1) msgcount1=msgcount2;
  return db_h->localdata_p->rtdb_tracebufsize - msgcount1;
}

variable_types:
oid
int *

variable_types:
ts
long *

variable_types:
event
int *

variable_types: ret int


decompiled_code:
__int64 __fastcall kogmo_rtdb_obj_dumphex_str(__int64 a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbx
int v3; // er14
__int64 v4; // r8
int v6; // [rsp+Ch] [rbp-4Ch] BYREF
__int64 v7; // [rsp+10h] [rbp-48h] BYREF
__int64 v8[8]; // [rsp+18h] [rbp-40h] BYREF

v2 = a2;
v3 = *((_DWORD *)a2 + 5);
v6 = 0;
v7 = 0LL;
v8[0] = 0LL;
strprintf(&v7, v8, &v6, "* BINARY DATA:\n");
if ( v3 > 0 )
{
do
{
v4 = *v2++;
strprintf(&v7, v8, &v6, "%02x ", v4);
}
while ( v2 != &a2[v3 - 1 + 1] );
}
strprintf(&v7, v8, &v6, "\n");
return v7;
}

original_code:
char*
kogmo_rtdb_obj_dumphex_str (kogmo_rtdb_handle_t *db_h, void *data_p)
{
  kogmo_rtdb_objsize_t size;
  int i;
  int buf_len=0; char *buf=((void *)0), *buf_ptr=((void *)0);;
  size = ( (kogmo_rtdb_subobj_base_t*) data_p )->size;
  strprintf(&buf,&buf_ptr,&buf_len,"* BINARY DATA:\n");;
  for(i=0;i<size;i++) {
   strprintf(&buf,&buf_ptr,&buf_len,"%02x ", ((unsigned char*)data_p)[i]);;
  }
  strprintf(&buf,&buf_ptr,&buf_len,"\n");;
  return buf;
}

canonical_original_code:
char *kogmo_rtdb_obj_dumphex_str(struct kogmo_rtdb_handle_t *db_h, void *data_p)
{
  int size;
  int i;
  int buf_len = 0; char *buf = ((void *)0); char *buf_ptr = ((void *)0);;
  size = ( (struct kogmo_rtdb_subobj_base_t *) data_p )->size;
  strprintf(&buf,&buf_ptr,&buf_len,"* BINARY DATA:\n");;
  for(i=0;i<size;i++) {
   strprintf(&buf,&buf_ptr,&buf_len,"%02x ", ((unsigned char *)data_p)[i]);;
  }
  strprintf(&buf,&buf_ptr,&buf_len,"\n");;
  return buf;
}

variable_types: i int

variable_types:
buf
char *

return_type: char *


decompiled_code:
__int64 __fastcall kogmo_rtdb_obj_c3_process_searchprocessobj(__int64 a1, __int64 a2, unsigned int a3)
{
int v6; // er12
unsigned int v7; // er14
int v8; // eax
__int64 v10; // rdx
FILE *v11; // rdi
FILE *v12; // rdi
FILE *v13; // rsi

v6 = kogmo_rtdb_obj_searchinfo(a1, "processes", 12779522LL, 0LL, 0LL, a2, 0LL, 1LL);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
{
v10 = (unsigned int)getpid();
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v11 = stdout;
else
v11 = stderr;
fprintf(v11, "%d DBG: ", v10);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v12 = stdout;
else
v12 = stderr;
fprintf(v12, "%lli", v6);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v13 = stdout;
else
v13 = stderr;
fputc(10, v13);
}
v7 = 0;
if ( v6 >= 0 )
{
v8 = kogmo_rtdb_obj_searchinfo(a1, &LC6, 12779523LL, (unsigned int)v6, a3, a2, 0LL, 1LL);
if ( v8 >= 0 )
v7 = v8;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3)
{
int v6; // er12
unsigned int v7; // er14
int v8; // eax
__int64 v10; // rdx
FILE *v11; // rdi
FILE *v12; // rdi
FILE *v13; // rsi

v6 = kogmo_rtdb_obj_searchinfo(a1, "processes", 12779522LL, 0LL, 0LL, a2, 0LL, 1LL);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
{
v10 = (unsigned int)getpid();
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v11 = stdout;
else
v11 = stderr;
fprintf(v11, "%d DBG: ", v10);
if ( (kogmo_rtdb_debug & 0x100) != 0 )
v12 = stdout;
else
v12 = stderr;
fprintf(v12, "%lli", v6);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v13 = stdout;
else
v13 = stderr;
fputc(10, v13);
}
v7 = 0;
if ( v6 >= 0 )
{
v8 = kogmo_rtdb_obj_searchinfo(a1, &LC6, 12779523LL, (unsigned int)v6, a3, a2, 0LL, 1LL);
if ( v8 >= 0 )
v7 = v8;
}
return v7;
}

original_code:
kogmo_rtdb_objid_t
kogmo_rtdb_obj_c3_process_searchprocessobj (kogmo_rtdb_handle_t *db_h,
                                            kogmo_timestamp_t ts,
                                            kogmo_rtdb_objid_t proc_oid)
{
  kogmo_rtdb_objid_t proclistoid,procoid;
  proclistoid = kogmo_rtdb_obj_searchinfo (db_h, "processes",
                                           KOGMO_RTDB_OBJTYPE_C3_PROCESSLIST,
                                           0, 0, ts, ((void *)0), 1);
do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%lli",(long long)proclistoid); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  if ( proclistoid < 0 )
    return 0;
  procoid = kogmo_rtdb_obj_searchinfo (db_h, "",
                                       KOGMO_RTDB_OBJTYPE_C3_PROCESS,
                                       proclistoid, proc_oid, ts, ((void *)0), 1);
  if ( procoid < 0 )
    return 0;
  return procoid;
}

canonical_original_code:
int kogmo_rtdb_obj_c3_process_searchprocessobj(struct kogmo_rtdb_handle_t *db_h, long ts, int proc_oid)
{
  int proclistoid; int procoid;
  proclistoid = kogmo_rtdb_obj_searchinfo (db_h, "processes",
                                           KOGMO_RTDB_OBJTYPE_C3_PROCESSLIST,
                                           0, 0, ts, ((void *)0), 1);
do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%lli",(long long)proclistoid); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  if ( proclistoid < 0 )
    return 0;
  procoid = kogmo_rtdb_obj_searchinfo (db_h, "",
                                       KOGMO_RTDB_OBJTYPE_C3_PROCESS,
                                       proclistoid, proc_oid, ts, ((void *)0), 1);
  if ( procoid < 0 )
    return 0;
  return procoid;
}

variable_types: ts long

variable_types: proclistoid int

variable_types: procoid int


decompiled_code:
__int64 __fastcall kogmo_rtdb_obj_c3_process_getprocessinfo(__int64 a1, unsigned int a2, __int64 a3, __int64 a4)
{
int v6; // eax
unsigned int v7; // er12
int v8; // eax
const char *v9; // rdx
int v11; // [rsp+0h] [rbp-178h] BYREF
char v12[56]; // [rsp+4h] [rbp-174h] BYREF
__int64 v13; // [rsp+3Ch] [rbp-13Ch]
char v14[264]; // [rsp+70h] [rbp-108h] BYREF

*(_QWORD *)a4 = 0LL;
*(_QWORD *)(a4 + 124) = 0LL;
memset(
(void *)((a4 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a4 - (((_DWORD)a4 + 8) & 0xFFFFFFF8) + 132) >> 3));
*(_WORD *)a4 = 63;
v6 = kogmo_rtdb_obj_c3_process_searchprocessobj(a1, a3, a2);
v7 = v6;
if ( v6 >= 0 )
{
v8 = kogmo_rtdb_obj_readinfo(a1, (unsigned int)v6, a3, &v11);
if ( v8 < 0 || (v8 = kogmo_rtdb_obj_readdata(a1, v7, a3, v14, 212LL), v8 < 0) )
{
v7 = v8;
}
else
{
v9 = "D!";
if ( !v13 )
v9 = (const char *)&LC6;
sprintf((char *)a4, "%s%s(%lli)", v9, v12, v11);
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, __int64 a3, __int64 a4)
{
int v6; // eax
unsigned int v7; // er12
int v8; // eax
const char *v9; // rdx
int v11; // [rsp+0h] [rbp-178h] BYREF
char v12[56]; // [rsp+4h] [rbp-174h] BYREF
__int64 v13; // [rsp+3Ch] [rbp-13Ch]
char v14[264]; // [rsp+70h] [rbp-108h] BYREF

*(_QWORD *)a4 = 0LL;
*(_QWORD *)(a4 + 124) = 0LL;
memset(
(void *)((a4 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a4 - (((_DWORD)a4 + 8) & 0xFFFFFFF8) + 132) >> 3));
*(_WORD *)a4 = 63;
v6 = func1(a1, a3, a2);
v7 = v6;
if ( v6 >= 0 )
{
v8 = kogmo_rtdb_obj_readinfo(a1, (unsigned int)v6, a3, &v11);
if ( v8 < 0 || (v8 = kogmo_rtdb_obj_readdata(a1, v7, a3, v14, 212LL), v8 < 0) )
{
v7 = v8;
}
else
{
v9 = "D!";
if ( !v13 )
v9 = (const char *)&LC6;
sprintf((char *)a4, "%s%s(%lli)", v9, v12, v11);
}
}
return v7;
}

original_code:
kogmo_rtdb_objid_t
kogmo_rtdb_obj_c3_process_getprocessinfo (kogmo_rtdb_handle_t *db_h,
                                          kogmo_rtdb_objid_t proc_oid,
                                          kogmo_timestamp_t ts,
                                          kogmo_rtdb_obj_c3_process_info_t str)
{
  int err;
  kogmo_rtdb_obj_info_t om;
  kogmo_rtdb_obj_c3_process_t po;
  kogmo_rtdb_objid_t oid;
  memset(str, 0, sizeof(kogmo_rtdb_obj_c3_process_info_t));
  strcpy(str, "?");
  oid = kogmo_rtdb_obj_c3_process_searchprocessobj (db_h, ts, proc_oid);
  if ( oid < 0 )
    return oid;
  err = kogmo_rtdb_obj_readinfo ( db_h, oid, ts, &om);
  if ( err < 0 )
    return err;
  err = kogmo_rtdb_obj_readdata (db_h, oid, ts, &po, sizeof (po) );
  if ( err < 0 )
    return err;
  sprintf(str, "%s%s(%lli)", om.deleted_ts ? "D!":"", om.name,
               (long long int) om.oid);
  return oid;
}

canonical_original_code:
int kogmo_rtdb_obj_c3_process_getprocessinfo(struct kogmo_rtdb_handle_t *db_h, int proc_oid, long ts, char str[-1])
{
  int err;
  struct kogmo_rtdb_obj_info_t om;
  struct kogmo_rtdb_obj_c3_process_t po;
  int oid;
  memset(str, 0, sizeof(kogmo_rtdb_obj_c3_process_info_t));
  strcpy(str, "?");
  oid = kogmo_rtdb_obj_c3_process_searchprocessobj (db_h, ts, proc_oid);
  if ( oid < 0 )
    return oid;
  err = kogmo_rtdb_obj_readinfo ( db_h, oid, ts, &om);
  if ( err < 0 )
    return err;
  err = kogmo_rtdb_obj_readdata (db_h, oid, ts, &po, sizeof (po) );
  if ( err < 0 )
    return err;
  sprintf(str, "%s%s(%lli)", om.deleted_ts ? "D!":"", om.name,
               (long long) om.oid);
  return oid;
}

variable_types:
str
char [-1]

variable_types: err int

variable_types: struct kogmo_rtdb_obj_info_t { int oid; char name[32]; long created_ts; int created_proc; long lastmodified_ts; int lastmodified_proc; long deleted_ts; int deleted_proc; int parent_oid; int otype; int size_max; float history_interval; float avg_cycletime; float max_cycletime; struct { unsigned int read_deny; unsigned int write_allow; unsigned int keep_alloc; unsigned int unique; unsigned int cycle_watch; unsigned int persistent; unsigned int parent_delete; unsigned int no_notifies; unsigned int immediately_delete; unsigned int withhold_stale; } flags; int history_size; int history_slot; int buffer_idx; }

variable_types: struct kogmo_rtdb_obj_c3_process_t { struct kogmo_rtdb_subobj_base_t { long committed_ts; int committed_proc; long data_ts; int size; } base; struct kogmo_rtdb_subobj_c3_process_t { int proc_oid; unsigned int pid; unsigned int tid; unsigned int flags; unsigned int status; char statusmsg[160]; unsigned int version; unsigned int uid; } process; }