getanswer

decompiled_code:
__int64 __fastcall getanswer(const char *a1, unsigned int a2, __int64 a3, char *a4)
{
int v4; // er13
char i; // dl
const char *v6; // rbx
int *v7; // rbp
__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);
}
v6 = p_1;
v7 = _errno_location();
*v7 = 0;
result = strtol(v6, &endptr, 10);
if ( *v7 == 34 && (unsigned __int64)(result + 0x7FFFFFFFFFFFFFFFLL) > 0xFFFFFFFFFFFFFFFDLL || !result && *v7 )
{
perror("strtol");
exit(1);
}
if ( endptr == v6 )
{
fwrite("No digits were found\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
for ( i = *v6; *v6 == 32; i = *v6 )
++v6;
if ( (i & 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; // er13
char i; // dl
const char *v6; // rbx
int *v7; // rbp
__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);
}
v6 = p_1;
v7 = _errno_location();
*v7 = 0;
result = strtol(v6, &endptr, 10);
if ( *v7 == 34 && (unsigned __int64)(result + 0x7FFFFFFFFFFFFFFFLL) > 0xFFFFFFFFFFFFFFFDLL || !result && *v7 )
{
perror("strtol");
exit(1);
}
if ( endptr == v6 )
{
fwrite("No digits were found\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
for ( i = *v6; *v6 == 32; i = *v6 )
++v6;
if ( (i & 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


hashclear

repo: masui/LensBar

decompiled_code:
int *hashclear()
{
int *result; // rax

result = &statenum;
do
*result++ = -1;
while ( result != (int *)&unk_3F6054 );
return result;
}

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

result = &statenum;
do
*result++ = -1;
while ( result != (int *)&unk_3F6054 );
return result;
}

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

variable_types: i int

return_type: void


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;
while ( v4 != v3 )
{
v5 = *(_BYTE *)(a2 + v4++);
if ( v5 != *(_BYTE *)(a1 + v4 - 1) )
return 1LL;
}
return 0LL;
}

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;
while ( v4 != v3 )
{
v5 = *(_BYTE *)(a2 + v4++);
if ( v5 != *(_BYTE *)(a1 + v4 - 1) )
return 1LL;
}
return 0LL;
}

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

return_type: int


patstate

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

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 )
{
v2 = (char *)&trans;
do
{
v2 = *(char **)&v2[8 * v1];
v1 = *++a1;
}
while ( *a1 );
}
else
{
v2 = (char *)&trans;
}
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 )
{
v2 = (char *)&trans;
do
{
v2 = *(char **)&v2[8 * v1];
v1 = *++a1;
}
while ( *a1 );
}
else
{
v2 = (char *)&trans;
}
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 **


repo: masuyama/spawner

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, __int64 a5, int a6)
{
int v8; // ebx
bool v9; // al
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
const char *v14; // rsi
__int64 v15; // r8
const char *v16; // rdx
__int64 v17; // r14
__int64 result; // rax
int v19; // ecx

v8 = 1;
if ( a1 <= 1 )
{
print_help(*a2);
exit(0);
}
do
{
v15 = v8;
v16 = a2[v15];
if ( *v16 != 45 )
break;
if ( !strcmp(a2[v8++], "-c") )
{
++v8;
LODWORD(nmemb) = atoi(a2[v15 + 1]);
}
else
{
v9 = strcmp(a2[v8], "-h") != 0;
v10 = 0;
v11 = !v9;
if ( !v9 )
{
print_help(*a2);
exit(0);
}
v12 = "-d";
v13 = 3LL;
v14 = a2[v8];
do
{
if ( !v13 )
break;
v10 = *v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
if ( (!v10 && !v11) != v10 )
{
print_log(3, (unsigned int)"unknown option [%s]\n", (_DWORD)v16, v13, v15 * 8, a6);
exit(0);
}
byte_406504 = 1;
}
}
while ( a1 > v8 );
if ( a1 == v8 )
{
print_help(*a2);
exit(0);
}
v17 = v8;
strncpy(config, a2[v17], 0x3FFuLL);
argv = config;
result = (unsigned int)(v8 + 1);
if ( a1 <= (int)result )
{
v19 = 1;
}
else
{
qword_404508 = (__int64)a2[v17 + 1];
for ( result = 2LL; result != 1023; ++result )
{
v19 = result;
if ( result == (unsigned int)(a1 - 2 - v8) + 2LL )
break;
v19 = result + 1;
(&argv)[result] = (char *)(&a2[v17])[result];
}
}
(&argv)[v19] = 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: argc int

variable_types:
argv
char *[]

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


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
int v6; // er9
int v7; // edx
int v8; // ecx
int v9; // er8
int v10; // er9
int v11; // edx
int v12; // ecx
int v13; // er8
int v14; // er9

set_log_level(7LL, argv, envp);
parse_options(argc, argv, v3, v4, v5, v6);
set_signal(2, (void (*)(int))catch_stop);
set_signal(15, (void (*)(int))catch_stop);
set_signal(3, (void (*)(int))catch_stop);
set_signal(1, (void (*)(int))catch_hup);
if ( byte_406504 == 1 && daemon(1, 0) == -1 )
{
print_log(3, (unsigned int)"failed to launch daemon.\n", v11, v12, v13, v14);
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", v7, v8, v9, v10);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
int v6; // er9
int v7; // edx
int v8; // ecx
int v9; // er8
int v10; // er9
int v11; // edx
int v12; // ecx
int v13; // er8
int v14; // er9

func19(7LL, argv, envp);
func10(argc, argv, v3, v4, v5, v6);
func11(2, (void (*)(int))catch_stop);
func11(15, (void (*)(int))catch_stop);
func11(3, (void (*)(int))catch_stop);
func11(1, (void (*)(int))catch_hup);
if ( byte_406504 == 1 && daemon(1, 0) == -1 )
{
func20(3, (unsigned int)"failed to launch daemon.\n", v11, v12, v13, v14);
exit(-1);
}
func14((unsigned int)nmemb);
keepgoing = 1;
do
func16(config, &::argv);
while ( keepgoing );
func15();
func20(6, (unsigned int)"spawner end\n", v7, v8, v9, v10);
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: nochdir int

variable_types: noclose int


repo: matgoebl/kogmo-rtdb

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

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

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

result = 0LL;
if ( timeidx_p )
result = kogmo_timestamp_add_secs(*(_QWORD *)((char *)timeidx_p + 60), *((float *)timeidx_p + 12));
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
unsigned int v5; // edx
__int64 v7; // rdi
int v8; // er13
unsigned int i; // ebx
_DWORD *v10; // rax
char *v11; // rax
int v12; // eax
int v13; // eax
unsigned int v14; // er14
unsigned int v15; // eax

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
double v3; // xmm0_8
char *v4; // rax
unsigned int v5; // edx
__int64 v7; // rdi
int v8; // er13
unsigned int i; // ebx
_DWORD *v10; // rax
char *v11; // rax
int v12; // eax
int v13; // eax
unsigned int v14; // er14
unsigned int v15; // eax

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

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)
{
int v1; // eax
int v2; // ebx

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 = (int)(kogmo_timestamp_diff_secs(*(_QWORD *)((char *)timeidx_p + 52), a1) / *((float *)timeidx_p + 12));
if ( v1 < 0 )
return -1LL;
if ( *((_DWORD *)timeidx_p + 17) <= v1 )
v1 = *((_DWORD *)timeidx_p + 17);
v2 = v1;
if ( timeidx_debug )
{
printf("%% timeidx: loopup found: %i. = %lli", (unsigned int)v1, *(_QWORD *)((char *)timeidx_p + 16 * v1 + 84));
putchar(10);
}
return *(_QWORD *)((char *)timeidx_p + 16 * v2 + 84);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // eax
int v2; // ebx

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 = (int)(kogmo_timestamp_diff_secs(*(_QWORD *)((char *)timeidx_p + 52), a1) / *((float *)timeidx_p + 12));
if ( v1 < 0 )
return -1LL;
if ( *((_DWORD *)timeidx_p + 17) <= v1 )
v1 = *((_DWORD *)timeidx_p + 17);
v2 = v1;
if ( timeidx_debug )
{
printf("%% timeidx: loopup found: %i. = %lli", (unsigned int)v1, *(_QWORD *)((char *)timeidx_p + 16 * v1 + 84));
putchar(10);
}
return *(_QWORD *)((char *)timeidx_p + 16 * v2 + 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 v14; // rdx
FILE *v15; // rdi
FILE *v16; // rdi
FILE *v17; // rsi
int v18; // [rsp+0h] [rbp-58h] BYREF
__int64 v19; // [rsp+8h] [rbp-50h]
unsigned int v20; // [rsp+10h] [rbp-48h]
int v21; // [rsp+14h] [rbp-44h]
int v22; // [rsp+18h] [rbp-40h]

v6 = *(_QWORD *)(a1 + 328);
if ( !*(_DWORD *)(v6 + 240108) )
return 4294967274LL;
if ( !*(_DWORD *)(v6 + 240104) )
return 4294967274LL;
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
{
v14 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v15 = stdout;
else
v15 = stderr;
fprintf(v15, "%d DBG: ", v14);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v16 = stdout;
else
v16 = stderr;
fprintf(v16, "TRACE: @%lli OID %lli: %i", a3, a2, a4);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v17 = stdout;
else
v17 = stderr;
fputc(10, v17);
}
v18 = a2;
v19 = a3;
v20 = a4;
v21 = a5;
v22 = a6;
kogmo_rtdb_ipc_mq_send(*(unsigned int *)(a1 + 492), &v18, 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 v14; // rdx
FILE *v15; // rdi
FILE *v16; // rdi
FILE *v17; // rsi
int v18; // [rsp+0h] [rbp-58h] BYREF
__int64 v19; // [rsp+8h] [rbp-50h]
unsigned int v20; // [rsp+10h] [rbp-48h]
int v21; // [rsp+14h] [rbp-44h]
int v22; // [rsp+18h] [rbp-40h]

v6 = *(_QWORD *)(a1 + 328);
if ( !*(_DWORD *)(v6 + 240108) )
return 4294967274LL;
if ( !*(_DWORD *)(v6 + 240104) )
return 4294967274LL;
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
{
v14 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v15 = stdout;
else
v15 = stderr;
fprintf(v15, "%d DBG: ", v14);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v16 = stdout;
else
v16 = stderr;
fprintf(v16, "TRACE: @%lli OID %lli: %i", a3, a2, a4);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v17 = stdout;
else
v17 = stderr;
fputc(10, v17);
}
v18 = a2;
v19 = a3;
v20 = a4;
v21 = a5;
v22 = a6;
kogmo_rtdb_ipc_mq_send(*(unsigned int *)(a1 + 492), &v18, 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 + 1) & 1) != 0 )
{
v7 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v8 = stdout;
else
v8 = stderr;
fprintf(v8, "%d DBG: ", v7);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 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 )
{
kogmo_rtdb_ipc_mq_receive_init(a1 + 496, a1 + 356);
*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240104LL) = 1;
v11 = 300;
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 );
}
else
{
*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240104LL) = 0;
*(_DWORD *)(a1 + 496) = 0;
}
result = 0LL;
if ( a3 )
{
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 328) + 240108LL);
result = 0LL;
}
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 + 1) & 1) != 0 )
{
v7 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v8 = stdout;
else
v8 = stderr;
fprintf(v8, "%d DBG: ", v7);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 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 )
{
kogmo_rtdb_ipc_mq_receive_init(a1 + 496, a1 + 356);
*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240104LL) = 1;
v11 = 300;
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 );
}
else
{
*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240104LL) = 0;
*(_DWORD *)(a1 + 496) = 0;
}
result = 0LL;
if ( a3 )
{
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 328) + 240108LL);
result = 0LL;
}
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 *

variable_types: i 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 v11; // rdi
int v12; // ebp
int v13; // er12
__int64 v15; // rdx
FILE *v16; // rdi
FILE *v17; // rdi
FILE *v18; // rsi
__int64 v19; // rdx
FILE *v20; // rdi
FILE *v21; // rdi
FILE *v22; // 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;
v11 = *(unsigned int *)(a1 + 496);
if ( !(_DWORD)v11 )
return 4294967274LL;
v12 = kogmo_rtdb_ipc_mq_curmsgs(v11);
v25 = kogmo_rtdb_ipc_mq_receive(*(unsigned int *)(a1 + 496), &v26, 32LL);
v13 = kogmo_rtdb_ipc_mq_curmsgs(*(unsigned int *)(a1 + 496));
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
{
v15 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v16 = stdout;
else
v16 = stderr;
fprintf(v16, "%d DBG: ", v15);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v17 = stdout;
else
v17 = stderr;
fprintf(v17, "* TRACE: %d bytes, @%lli OID %lli: %i", v25, v27, v26, v28);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v18 = stdout;
else
v18 = stderr;
fputc(10, v18);
}
*a2 = v26;
*a3 = v27;
*a4 = v28;
if ( a5 )
*a5 = v29;
if ( a6 )
*a6 = v30;
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
{
v19 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v20 = stdout;
else
v20 = stderr;
fprintf(v20, "%d DBG: ", v19);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v21 = stdout;
else
v21 = stderr;
fprintf(v21, "GOT TRACE: @%lli OID %lli: %i", *a3, *a2, *a4);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v22 = stdout;
else
v22 = stderr;
fputc(10, v22);
}
if ( v12 < v13 )
v12 = v13;
return (unsigned int)(*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240108LL) - v12);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int *a2, _QWORD *a3, unsigned int *a4, _DWORD *a5, _DWORD *a6)
{
__int64 v6; // rax
__int64 v11; // rdi
int v12; // ebp
int v13; // er12
__int64 v15; // rdx
FILE *v16; // rdi
FILE *v17; // rdi
FILE *v18; // rsi
__int64 v19; // rdx
FILE *v20; // rdi
FILE *v21; // rdi
FILE *v22; // 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;
v11 = *(unsigned int *)(a1 + 496);
if ( !(_DWORD)v11 )
return 4294967274LL;
v12 = kogmo_rtdb_ipc_mq_curmsgs(v11);
v25 = kogmo_rtdb_ipc_mq_receive(*(unsigned int *)(a1 + 496), &v26, 32LL);
v13 = kogmo_rtdb_ipc_mq_curmsgs(*(unsigned int *)(a1 + 496));
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
{
v15 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v16 = stdout;
else
v16 = stderr;
fprintf(v16, "%d DBG: ", v15);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v17 = stdout;
else
v17 = stderr;
fprintf(v17, "* TRACE: %d bytes, @%lli OID %lli: %i", v25, v27, v26, v28);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v18 = stdout;
else
v18 = stderr;
fputc(10, v18);
}
*a2 = v26;
*a3 = v27;
*a4 = v28;
if ( a5 )
*a5 = v29;
if ( a6 )
*a6 = v30;
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
{
v19 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v20 = stdout;
else
v20 = stderr;
fprintf(v20, "%d DBG: ", v19);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v21 = stdout;
else
v21 = stderr;
fprintf(v21, "GOT TRACE: @%lli OID %lli: %i", *a3, *a2, *a4);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v22 = stdout;
else
v22 = stderr;
fputc(10, v22);
}
if ( v12 < v13 )
v12 = v13;
return (unsigned int)(*(_DWORD *)(*(_QWORD *)(a1 + 328) + 240108LL) - v12);
}

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, __int64 a2)
{
int v2; // er12
unsigned __int8 *v3; // rbx
__int64 v4; // r12
__int64 v6; // [rsp+8h] [rbp-30h] BYREF
__int64 v7; // [rsp+10h] [rbp-28h] BYREF
int v8[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
int v2; // er12
unsigned __int8 *v3; // rbx
__int64 v4; // r12
__int64 v6; // [rsp+8h] [rbp-30h] BYREF
__int64 v7; // [rsp+10h] [rbp-28h] BYREF
int v8[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v8[0] = 0;
v7 = 0LL;
v6 = 0LL;
v2 = *(_DWORD *)(a2 + 20);
strprintf(&v7, &v6, v8, "* BINARY DATA:\n");
if ( v2 > 0 )
{
v3 = (unsigned __int8 *)a2;
v4 = a2 + (unsigned int)(v2 - 1) + 1;
do
strprintf(&v7, &v6, v8, "%02x ", *v3++);
while ( v3 != (unsigned __int8 *)v4 );
}
strprintf(&v7, &v6, v8, "\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:
buf
char *

return_type: char *


decompiled_code:
__int64 __fastcall kogmo_rtdb_obj_c3_process_searchprocessobj(__int64 a1, __int64 a2, unsigned int a3)
{
int v6; // ebx
__int64 result; // rax
__int64 v8; // rdx
FILE *v9; // rdi
FILE *v10; // rdi
FILE *v11; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3)
{
int v6; // ebx
__int64 result; // rax
__int64 v8; // rdx
FILE *v9; // rdi
FILE *v10; // rdi
FILE *v11; // rsi

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

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; // er13
int v8; // eax
int v9; // eax
const char *v10; // rdx
__int64 v12; // [rsp+0h] [rbp-178h] BYREF
int v13; // [rsp+E0h] [rbp-98h] BYREF
char v14[56]; // [rsp+E4h] [rbp-94h] BYREF
__int64 v15; // [rsp+11Ch] [rbp-5Ch]

*(_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, &v13);
if ( v8 < 0 )
{
v7 = v8;
}
else
{
v9 = kogmo_rtdb_obj_readdata(a1, v7, a3, &v12, 212LL);
if ( v9 < 0 )
{
v7 = v9;
}
else
{
v10 = "D!";
if ( !v15 )
v10 = (const char *)&LC6;
sprintf((char *)a4, "%s%s(%lli)", v10, v14, v13);
}
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, __int64 a3, __int64 a4)
{
int v6; // eax
unsigned int v7; // er13
int v8; // eax
int v9; // eax
const char *v10; // rdx
__int64 v12; // [rsp+0h] [rbp-178h] BYREF
int v13; // [rsp+E0h] [rbp-98h] BYREF
char v14[56]; // [rsp+E4h] [rbp-94h] BYREF
__int64 v15; // [rsp+11Ch] [rbp-5Ch]

*(_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, &v13);
if ( v8 < 0 )
{
v7 = v8;
}
else
{
v9 = kogmo_rtdb_obj_readdata(a1, v7, a3, &v12, 212LL);
if ( v9 < 0 )
{
v7 = v9;
}
else
{
v10 = "D!";
if ( !v15 )
v10 = (const char *)&LC6;
sprintf((char *)a4, "%s%s(%lli)", v10, v14, v13);
}
}
}
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; }


decompiled_code:
__int64 __fastcall kogmo_rtdb_obj_dumpbase_str(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+18h] [rbp-120h] BYREF
__int64 v4; // [rsp+20h] [rbp-118h] BYREF
int v5; // [rsp+2Ch] [rbp-10Ch] BYREF
char v6[144]; // [rsp+30h] [rbp-108h] BYREF
char v7[32]; // [rsp+C0h] [rbp-78h] BYREF
char v8[88]; // [rsp+E0h] [rbp-58h] BYREF

v5 = 0;
v4 = 0LL;
v3 = 0LL;
if ( *(int *)(a2 + 20) <= 23 )
{
strprintf(&v4, &v3, &v5, "* NO DATA\n");
}
else
{
kogmo_timestamp_to_string(*(_QWORD *)a2, v8);
kogmo_timestamp_to_string(*(_QWORD *)(a2 + 12), v7);
kogmo_rtdb_obj_c3_process_getprocessinfo(a1, *(_DWORD *)(a2 + 8), *(_QWORD *)a2, (__int64)v6);
strprintf(&v4, &v3, &v5, "* DATA:\n");
strprintf(&v4, &v3, &v5, "Committed: %s by %s, %lli bytes\n", v8, v6, *(int *)(a2 + 20));
strprintf(&v4, &v3, &v5, "Data created: %s\n", v7);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+18h] [rbp-120h] BYREF
__int64 v4; // [rsp+20h] [rbp-118h] BYREF
int v5; // [rsp+2Ch] [rbp-10Ch] BYREF
char v6[144]; // [rsp+30h] [rbp-108h] BYREF
char v7[32]; // [rsp+C0h] [rbp-78h] BYREF
char v8[88]; // [rsp+E0h] [rbp-58h] BYREF

v5 = 0;
v4 = 0LL;
v3 = 0LL;
if ( *(int *)(a2 + 20) <= 23 )
{
strprintf(&v4, &v3, &v5, "* NO DATA\n");
}
else
{
kogmo_timestamp_to_string(*(_QWORD *)a2, v8);
kogmo_timestamp_to_string(*(_QWORD *)(a2 + 12), v7);
func2(a1, *(_DWORD *)(a2 + 8), *(_QWORD *)a2, (__int64)v6);
strprintf(&v4, &v3, &v5, "* DATA:\n");
strprintf(&v4, &v3, &v5, "Committed: %s by %s, %lli bytes\n", v8, v6, *(int *)(a2 + 20));
strprintf(&v4, &v3, &v5, "Data created: %s\n", v7);
}
return v4;
}

original_code:
char*
kogmo_rtdb_obj_dumpbase_str (kogmo_rtdb_handle_t *db_h, void *data_p)
{
  kogmo_rtdb_subobj_base_t *objbase;
  kogmo_timestamp_string_t tstr, data_tstr;
  kogmo_rtdb_obj_c3_process_info_t pi;
  int buf_len=0; char *buf=((void *)0), *buf_ptr=((void *)0);;
  objbase = (kogmo_rtdb_subobj_base_t*) data_p;
  if ( objbase->size < (int)(sizeof(kogmo_rtdb_subobj_base_t)) )
    {
      strprintf(&buf,&buf_ptr,&buf_len,"* NO DATA\n");;
      return buf;
    }
  kogmo_timestamp_to_string(objbase->committed_ts, tstr);
  kogmo_timestamp_to_string(objbase->data_ts, data_tstr);
  kogmo_rtdb_obj_c3_process_getprocessinfo (db_h, objbase->committed_proc,
                                            objbase->committed_ts, pi);
  strprintf(&buf,&buf_ptr,&buf_len,"* DATA:\n");;
  strprintf(&buf,&buf_ptr,&buf_len,"Committed: %s by %s, %lli bytes\n", tstr, pi, (long long int)objbase->size);;
  strprintf(&buf,&buf_ptr,&buf_len,"Data created: %s\n", data_tstr);;
  return buf;
}

canonical_original_code:
char *kogmo_rtdb_obj_dumpbase_str(struct kogmo_rtdb_handle_t *db_h, void *data_p)
{
  struct kogmo_rtdb_subobj_base_t *objbase;
  char tstr[30]; char data_tstr[30];
  char pi[-1];
  int buf_len = 0; char *buf = ((void *)0); char *buf_ptr = ((void *)0);;
  objbase = (struct kogmo_rtdb_subobj_base_t *) data_p;
  if ( objbase->size < (int)(sizeof(kogmo_rtdb_subobj_base_t)) )
    {
      strprintf(&buf,&buf_ptr,&buf_len,"* NO DATA\n");;
      return buf;
    }
  kogmo_timestamp_to_string(objbase->committed_ts, tstr);
  kogmo_timestamp_to_string(objbase->data_ts, data_tstr);
  kogmo_rtdb_obj_c3_process_getprocessinfo (db_h, objbase->committed_proc,
                                            objbase->committed_ts, pi);
  strprintf(&buf,&buf_ptr,&buf_len,"* DATA:\n");;
  strprintf(&buf,&buf_ptr,&buf_len,"Committed: %s by %s, %lli bytes\n", tstr, pi, (long long)objbase->size);;
  strprintf(&buf,&buf_ptr,&buf_len,"Data created: %s\n", data_tstr);;
  return buf;
}

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: struct kogmo_rtdb_subobj_base_t { long committed_ts; int committed_proc; long data_ts; int size; } *

variable_types:
tstr
char [30]

variable_types:
pi
char [-1]


decompiled_code:
__int64 __fastcall kogmo_rtdb_obj_findmeta_byid(__int64 a1, int a2)
{
__int64 v2; // rcx
_DWORD *v3; // rdx
int v4; // eax

v2 = *(_QWORD *)(a1 + 328);
v3 = (_DWORD *)(v2 + 8);
v4 = 0;
while ( *v3 != a2 )
{
++v4;
v3 += 28;
if ( v4 == 1000 )
return 0LL;
}
return v2 + 112LL * v4 + 8;
}

original_code:
kogmo_rtdb_obj_info_t *
kogmo_rtdb_obj_findmeta_byid (kogmo_rtdb_handle_t *db_h, kogmo_rtdb_objid_t oid )
{
  int i=-1;
  kogmo_rtdb_obj_info_t *scan_objmeta_p;
  do
    {
      if ( ++i >= 1000 )
        {
          return ((void *)0);
        }
      scan_objmeta_p = &db_h->localdata_p->objmeta[i];
    }
  while ( scan_objmeta_p->oid != oid );
  return scan_objmeta_p;
}

canonical_original_code:
struct kogmo_rtdb_obj_info_t *kogmo_rtdb_obj_findmeta_byid(struct kogmo_rtdb_handle_t *db_h, int oid)
{
  int i = -1;
  struct kogmo_rtdb_obj_info_t *scan_objmeta_p;
  do
    {
      if ( ++i >= 1000 )
        {
          return ((void *)0);
        }
      scan_objmeta_p = &db_h->localdata_p->objmeta[i];
    }
  while ( scan_objmeta_p->oid != oid );
  return scan_objmeta_p;
}

variable_types: struct kogmo_rtdb_handle_t { struct kogmo_rtdb_obj_info_t 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: i 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; } *


decompiled_code:
__syscall_slong_t kogmo_timestamp_now()
{
int v0; // edx
__syscall_slong_t result; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v0 = clock_gettime(0, &v2);
result = 0LL;
if ( !v0 )
result = v2.tv_nsec + 1000000000 * v2.tv_sec;
return result;
}

canonical_decompiled_code:
__syscall_slong_t func0()
{
int v0; // edx
__syscall_slong_t result; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v0 = clock_gettime(0, &v2);
result = 0LL;
if ( !v0 )
result = v2.tv_nsec + 1000000000 * v2.tv_sec;
return result;
}

original_code:
kogmo_timestamp_t
kogmo_timestamp_now (void)
{
  kogmo_timestamp_t ts;
  struct timespec tspec;
  int err;
  err = clock_gettime (0, &tspec);
  if (err != 0)
    return 0;
  ts = (kogmo_timestamp_t) tspec.tv_sec*1000000000
       + tspec.tv_nsec/(1000000000/1000000000);
  return ts;
}

canonical_original_code:
long kogmo_timestamp_now()
{
  long ts;
  struct timespec tspec;
  int err;
  err = clock_gettime (0, &tspec);
  if (err != 0)
    return 0;
  ts = (long) tspec.tv_sec*1000000000
       + tspec.tv_nsec/(1000000000/1000000000);
  return ts;
}

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


decompiled_code:
__int64 __fastcall kogmo_timestamp_diff_ns(__int64 a1, __int64 a2)
{
return a2 - a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return a2 - a1;
}

original_code:
inline int64_t
kogmo_timestamp_diff_ns (kogmo_timestamp_t ts_begin,
                         kogmo_timestamp_t ts_end)
{
  return (ts_end-ts_begin) * (1000000000/1000000000);
}

canonical_original_code:
inline long kogmo_timestamp_diff_ns(long ts_begin, long ts_end)
{
  return (ts_end-ts_begin) * (1000000000/1000000000);
}


decompiled_code:
double __fastcall kogmo_timestamp_diff_secs(int a1, int a2)
{
return (double)(a2 - a1) / 1000000000.0;
}

canonical_decompiled_code:
double __fastcall func2(int a1, int a2)
{
return (double)(a2 - a1) / 1000000000.0;
}

original_code:
inline double
kogmo_timestamp_diff_secs (kogmo_timestamp_t ts_begin,
                           kogmo_timestamp_t ts_end)
{
  return (double)(ts_end-ts_begin) / 1000000000;
}

canonical_original_code:
inline double kogmo_timestamp_diff_secs(long ts_begin, long ts_end)
{
  return (double)(ts_end-ts_begin) / 1000000000;
}

return_type: double


decompiled_code:
__int64 __fastcall kogmo_timestamp_add_ns(__int64 a1, __int64 a2)
{
return a1 + a2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return a1 + a2;
}

original_code:
inline kogmo_timestamp_t
kogmo_timestamp_add_ns (kogmo_timestamp_t ts, int64_t ns)
{
  return ts + ns / (1000000000/1000000000);
}

canonical_original_code:
inline long kogmo_timestamp_add_ns(long ts, long ns)
{
  return ts + ns / (1000000000/1000000000);
}

variable_types: ns long


decompiled_code:
__int64 __fastcall kogmo_timestamp_to_string(__int64 a1, char *a2)
{
size_t v2; // rax
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct tm tp; // [rsp+10h] [rbp-58h] BYREF

*a2 = 0;
timer = a1 / 1000000000;
if ( !localtime_r(&timer, &tp) )
return 0xFFFFFFFFLL;
if ( !strftime(a2, 0x1DuLL, "%Y-%m-%d %H:%M:%S", &tp) )
return 0xFFFFFFFFLL;
v2 = strlen(a2);
if ( snprintf(&a2[v2], 30 - v2, ".%09lli", a1 % 1000000000) < 0 )
return 0xFFFFFFFFLL;
a2[29] = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char *a2)
{
size_t v2; // rax
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct tm tp; // [rsp+10h] [rbp-58h] BYREF

*a2 = 0;
timer = a1 / 1000000000;
if ( !localtime_r(&timer, &tp) )
return 0xFFFFFFFFLL;
if ( !strftime(a2, 0x1DuLL, "%Y-%m-%d %H:%M:%S", &tp) )
return 0xFFFFFFFFLL;
v2 = strlen(a2);
if ( snprintf(&a2[v2], 30 - v2, ".%09lli", a1 % 1000000000) < 0 )
return 0xFFFFFFFFLL;
a2[29] = 0;
return 0LL;
}

original_code:
int
kogmo_timestamp_to_string (kogmo_timestamp_t ts, kogmo_timestamp_string_t str)
{
  struct tm timetm;
  time_t secs;
  str[0] = '\0';
  secs = ts / 1000000000;
  if ( localtime_r( &secs, &timetm) == ((void *)0) )
    return(-1);
  if ( strftime( str, sizeof (kogmo_timestamp_string_t) -1,
                 "%Y-%m-%d %H:%M:%S", &timetm ) == 0 )
    return(-1);
  if ( snprintf( str + strlen (str),
                 sizeof (kogmo_timestamp_string_t) - strlen (str),
                 ".%09lli",
                 (long long int) (ts % 1000000000) ) < 0 )
    return(-1);
  str[sizeof(kogmo_timestamp_string_t)-1] = '\0';
  return 0;
}

canonical_original_code:
int kogmo_timestamp_to_string(long ts, char str[30])
{
  struct tm timetm;
  long secs;
  str[0] = '\0';
  secs = ts / 1000000000;
  if ( localtime_r( &secs, &timetm) == ((void *)0) )
    return(-1);
  if ( strftime( str, sizeof (kogmo_timestamp_string_t) -1,
                 "%Y-%m-%d %H:%M:%S", &timetm ) == 0 )
    return(-1);
  if ( snprintf( str + strlen (str),
                 sizeof (kogmo_timestamp_string_t) - strlen (str),
                 ".%09lli",
                 (long long) (ts % 1000000000) ) < 0 )
    return(-1);
  str[sizeof(kogmo_timestamp_string_t)-1] = '\0';
  return 0;
}

variable_types: ts long

variable_types:
str
char [30]

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

variable_types: secs long


decompiled_code:
__int64 __fastcall kogmo_timestamp_from_string(char *s)
{
__int64 result; // rax
int v2; // edx
double v3; // rbx
int v4; // eax
int v5; // edx
time_t v6; // rbx
unsigned __int64 v7; // rax
signed int v8; // edx
double v9; // [rsp+8h] [rbp-80h] BYREF
__int64 v10; // [rsp+10h] [rbp-78h] BYREF
char *endptr; // [rsp+18h] [rbp-70h] BYREF
char nptr[8]; // [rsp+26h] [rbp-62h] BYREF
__int16 v13; // [rsp+2Eh] [rbp-5Ah]
struct tm tp; // [rsp+30h] [rbp-58h] BYREF

*(_QWORD *)nptr = 0LL;
v13 = 0;
result = 0LL;
if ( s )
{
*(_QWORD *)&tp.tm_sec = 0LL;
*(_QWORD *)&tp.tm_hour = 0LL;
*(_QWORD *)&tp.tm_mon = 0LL;
*(_QWORD *)&tp.tm_wday = 0LL;
*(_QWORD *)&tp.tm_isdst = 0LL;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 0LL;
if ( sscanf(
s,
"%d-%d-%d%*[ _tT]%d:%d:%d.%9s",
&tp.tm_year,
&tp.tm_mon,
&tp.tm_mday,
&tp.tm_hour,
&tp.tm_min,
&tp,
nptr) > 2 )
{
tp.tm_year -= 1900;
--tp.tm_mon;
tp.tm_isdst = -1;
v6 = mktime(&tp);
result = 0LL;
if ( v6 >= 0 )
{
v7 = strtoul(nptr, &endptr, 10);
v8 = (_DWORD)endptr - (unsigned int)nptr;
if ( v8 <= 8 )
{
do
{
v7 *= 10LL;
++v8;
}
while ( v8 != 9 );
}
result = 1000000000 * v6 + v7;
}
}
else if ( ((*s - 43) & 0xFD) != 0 )
{
v5 = sscanf(s, "%lli", &v10);
result = v10;
if ( v5 != 1 || v10 <= 9999 )
result = 0LL;
}
else
{
v2 = sscanf(s, "%lf", &v9);
result = 0LL;
if ( v2 == 1 )
{
v3 = v9;
v4 = kogmo_timestamp_now();
result = kogmo_timestamp_add_secs_localalias(v4, v3);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s)
{
__int64 result; // rax
int v2; // edx
double v3; // rbx
int v4; // eax
int v5; // edx
time_t v6; // rbx
unsigned __int64 v7; // rax
signed int v8; // edx
double v9; // [rsp+8h] [rbp-80h] BYREF
__int64 v10; // [rsp+10h] [rbp-78h] BYREF
char *endptr; // [rsp+18h] [rbp-70h] BYREF
char nptr[8]; // [rsp+26h] [rbp-62h] BYREF
__int16 v13; // [rsp+2Eh] [rbp-5Ah]
struct tm tp; // [rsp+30h] [rbp-58h] BYREF

*(_QWORD *)nptr = 0LL;
v13 = 0;
result = 0LL;
if ( s )
{
*(_QWORD *)&tp.tm_sec = 0LL;
*(_QWORD *)&tp.tm_hour = 0LL;
*(_QWORD *)&tp.tm_mon = 0LL;
*(_QWORD *)&tp.tm_wday = 0LL;
*(_QWORD *)&tp.tm_isdst = 0LL;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 0LL;
if ( sscanf(
s,
"%d-%d-%d%*[ _tT]%d:%d:%d.%9s",
&tp.tm_year,
&tp.tm_mon,
&tp.tm_mday,
&tp.tm_hour,
&tp.tm_min,
&tp,
nptr) > 2 )
{
tp.tm_year -= 1900;
--tp.tm_mon;
tp.tm_isdst = -1;
v6 = mktime(&tp);
result = 0LL;
if ( v6 >= 0 )
{
v7 = strtoul(nptr, &endptr, 10);
v8 = (_DWORD)endptr - (unsigned int)nptr;
if ( v8 <= 8 )
{
do
{
v7 *= 10LL;
++v8;
}
while ( v8 != 9 );
}
result = 1000000000 * v6 + v7;
}
}
else if ( ((*s - 43) & 0xFD) != 0 )
{
v5 = sscanf(s, "%lli", &v10);
result = v10;
if ( v5 != 1 || v10 <= 9999 )
result = 0LL;
}
else
{
v2 = sscanf(s, "%lf", &v9);
result = 0LL;
if ( v2 == 1 )
{
v3 = v9;
v4 = func0();
result = func4(v4, v3);
}
}
}
return result;
}

original_code:
kogmo_timestamp_t
kogmo_timestamp_from_string (char *str)
{
  kogmo_timestamp_t ts;
  int err;
  struct tm tmx;
  time_t secs;
  char ns_string[10]="";
  char *ns_string_end;
  unsigned long int ns=0;
  int i;
  long long int lli;
  if ( str == ((void *)0) )
    return 0;
  memset ( &tmx, 0, sizeof(struct tm));
  ns = 0;
  err = sscanf ( str, "%d-%d-%d%*[ _tT]%d:%d:%d.%9s",
                 &tmx.tm_year, &tmx.tm_mon , &tmx.tm_mday,
                 &tmx.tm_hour, &tmx.tm_min, &tmx.tm_sec,
                 ns_string );
  if ( err < 3 )
    {
      if ( str[0] == '+' || str[0] == '-' )
        {
          double off;
          err = sscanf ( str, "%lf", &off);
          if ( err != 1 )
            return 0;
          ts = kogmo_timestamp_add_secs ( kogmo_timestamp_now (), off);
          return ts;
        }
      err = sscanf ( str, "%lli", &lli);
      ts = (kogmo_timestamp_t) lli;
      if ( err != 1 || ts <= 9999)
        return 0;
      return ts;
    }
  tmx.tm_year -= 1900;
  tmx.tm_mon -= 1;
  tmx.tm_isdst = -1;
  secs = mktime (&tmx);
  if ( secs < 0 )
    return 0;
  ns = strtoul(ns_string, &ns_string_end, 10);
  for(i=ns_string_end-ns_string;i<9;i++)
    ns *= 10;
  ts = (kogmo_timestamp_t)ns +
       (kogmo_timestamp_t)secs * 1000000000;
  return ts;
}

canonical_original_code:
long kogmo_timestamp_from_string(char *str)
{
  long ts;
  int err;
  struct tm tmx;
  long secs;
  char ns_string[10] = "";
  char *ns_string_end;
  unsigned long ns = 0;
  int i;
  long long lli;
  if ( str == ((void *)0) )
    return 0;
  memset ( &tmx, 0, sizeof(struct tm));
  ns = 0;
  err = sscanf ( str, "%d-%d-%d%*[ _tT]%d:%d:%d.%9s",
                 &tmx.tm_year, &tmx.tm_mon , &tmx.tm_mday,
                 &tmx.tm_hour, &tmx.tm_min, &tmx.tm_sec,
                 ns_string );
  if ( err < 3 )
    {
      if ( str[0] == '+' || str[0] == '-' )
        {
          double off;
          err = sscanf ( str, "%lf", &off);
          if ( err != 1 )
            return 0;
          ts = kogmo_timestamp_add_secs ( kogmo_timestamp_now (), off);
          return ts;
        }
      err = sscanf ( str, "%lli", &lli);
      ts = (long) lli;
      if ( err != 1 || ts <= 9999)
        return 0;
      return ts;
    }
  tmx.tm_year -= 1900;
  tmx.tm_mon -= 1;
  tmx.tm_isdst = -1;
  secs = mktime (&tmx);
  if ( secs < 0 )
    return 0;
  ns = strtoul(ns_string, &ns_string_end, 10);
  for(i=ns_string_end-ns_string;i<9;i++)
    ns *= 10;
  ts = (long)ns +
       (long)secs * 1000000000;
  return ts;
}

variable_types:
str
char *

variable_types: err int

variable_types:
ns
unsigned long

variable_types:
lli
long long

variable_types: off double

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