LremoveModul

decompiled_code:
__int64 __fastcall LremoveModul(__int64 a1, __int64 a2)
{
__int64 v3; // rax
int v4; // esi
int v5; // ecx
__int64 result; // rax
int v7; // edx

v3 = 0LL;
v4 = *(_DWORD *)(a2 + 56);
while ( 1 )
{
v5 = v3;
if ( v4 <= (int)v3 )
break;
if ( *(_QWORD *)(a1 + 8 * v3 + 456) == a2 )
goto LABEL_8;
if ( ++v3 == 20 )
{
v5 = 20;
break;
}
}
if ( *(_QWORD *)(a1 + 8LL * v5 + 456) != a2 )
return lielas_log("Can't remove modul, modul not found", 1LL);
LABEL_8:
v7 = *(_DWORD *)(a1 + 452);
if ( v7 - 1 != v5 && v7 > v5 )
memmove(
(void *)(a1 + 8LL * (v5 + 57)),
(const void *)(a1 + 8LL * (v5 + 57) + 8),
8LL * (unsigned int)(v7 - 1 - v5) + 8);
result = LdeleteModul(a2);
--*(_DWORD *)(a1 + 452);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v3; // rax
int v4; // esi
int v5; // ecx
__int64 result; // rax
int v7; // edx

v3 = 0LL;
v4 = *(_DWORD *)(a2 + 56);
while ( 1 )
{
v5 = v3;
if ( v4 <= (int)v3 )
break;
if ( *(_QWORD *)(a1 + 8 * v3 + 456) == a2 )
goto LABEL_8;
if ( ++v3 == 20 )
{
v5 = 20;
break;
}
}
if ( *(_QWORD *)(a1 + 8LL * v5 + 456) != a2 )
return lielas_log("Can't remove modul, modul not found", 1LL);
LABEL_8:
v7 = *(_DWORD *)(a1 + 452);
if ( v7 - 1 != v5 && v7 > v5 )
memmove(
(void *)(a1 + 8LL * (v5 + 57)),
(const void *)(a1 + 8LL * (v5 + 57) + 8),
8LL * (unsigned int)(v7 - 1 - v5) + 8);
result = LdeleteModul(a2);
--*(_DWORD *)(a1 + 452);
return result;
}

original_code:
void LremoveModul(Ldevice *device, Lmodul *modul){
 Lmodul *m;
 int i;
 int mIndex;
 for( mIndex = 0; mIndex < 20 && mIndex < modul->channels; mIndex++){
  if(device->modul[mIndex] == modul){
   break;
  }
 }
 if(device->modul[mIndex] != modul){
  lielas_log((unsigned char*)"Can't remove modul, modul not found", 1);
  return;
 }
 m = device->modul[mIndex];
 if(mIndex != (device->moduls - 1)){
  for( i = mIndex; i < device->moduls; i++){
   device->modul[i] = device->modul[i+1];
  }
 }
 LdeleteModul(m);
 device->moduls -= 1;
}

canonical_original_code:
void LremoveModul(struct Ldevice_struct *device, struct Lmodul_struct *modul){
 struct Lmodul_struct *m;
 int i;
 int mIndex;
 for( mIndex = 0; mIndex < 20 && mIndex < modul->channels; mIndex++){
  if(device->modul[mIndex] == modul){
   break;
  }
 }
 if(device->modul[mIndex] != modul){
  lielas_log((unsigned char *)"Can't remove modul, modul not found", 1);
  return;
 }
 m = device->modul[mIndex];
 if(mIndex != (device->moduls - 1)){
  for( i = mIndex; i < device->moduls; i++){
   device->modul[i] = device->modul[i+1];
  }
 }
 LdeleteModul(m);
 device->moduls -= 1;
}

variable_types: struct Lmodul_struct { unsigned int id; char address[50]; int channels; char mint[50]; char pint[50]; char aint[50]; struct Lchannel_struct { unsigned int id; char address[50]; char type[50]; char sensor[50]; char unit[50]; char class[50]; double exponent; } *channel[20]; } *

variable_types: mIndex int


LprintDeviceStructure

repo: anre/lielas

decompiled_code:
int __fastcall LprintDeviceStructure(unsigned int *a1, char *a2, int a3, int a4)
{
int v5; // esi
unsigned int **v7; // r15
int v8; // ebx
int v9; // ebx
int v10; // ebx
int v11; // ebx
int v12; // ebx
int v13; // ebx
int result; // eax
int v15; // ebx
unsigned int v16; // er14
int v17; // ebx
int v18; // ebx
int v19; // ebx
__int64 v20; // rcx
const char *v21; // rax
int v22; // ebx
int v23; // ebx
int v24; // ebx
__int64 v25; // r13
unsigned int v26; // [rsp+8h] [rbp-40h]

v5 = a3;
if ( !a1 )
return snprintf(a2, a3, "Device is null\n");
v7 = (unsigned int **)(a1 + 114);
v8 = snprintf(a2, a3, "Device %s with id %u:\n", (const char *)a1 + 8, *a1);
v9 = snprintf(&a2[v8], v5 - v8, " name: %s\n", (const char *)a1 + 258) + v8;
v10 = snprintf(&a2[v9], v5 - v9, " software version: %s\n", (const char *)a1 + 322) + v9;
v11 = snprintf(&a2[v10], v5 - v10, " supply: %s\n", (const char *)a1 + 386) + v10;
v12 = snprintf(&a2[v11], v5 - v11, " meassurement interval: %s\n", (const char *)a1 + 108) + v11;
v13 = snprintf(&a2[v12], v5 - v12, " process interval: %s\n", (const char *)a1 + 158) + v12;
result = snprintf(&a2[v13], v5 - v13, " alarm interval: %s\n", (const char *)a1 + 208);
v26 = 0;
v15 = result + v13;
while ( *v7 )
{
v16 = 0;
snprintf(&a2[v15], a3 - v15, "*************************************************\n");
v17 = snprintf(
&a2[v15 + 50],
a3 - (v15 + 50),
" Modul %i of %u with id %u and address %s:\n",
v26,
a1[113],
**v7,
(const char *)*v7 + 4)
+ v15
+ 50;
v18 = snprintf(&a2[v17], a3 - v17, " meassurement interval: %s\n", (const char *)*v7 + 60) + v17;
v19 = snprintf(&a2[v18], a3 - v18, " process interval: %s\n", (const char *)*v7 + 110) + v18;
v15 = snprintf(&a2[v19], a3 - v19, " alarm interval: %s\n", (const char *)*v7 + 160) + v19;
while ( 1 )
{
v25 = (int)v16 + 26LL;
if ( !*(_QWORD *)&(*v7)[2 * v16 + 54] )
break;
snprintf(&a2[v15], a3 - v15, "-------------------------------------------------\n");
v20 = v16++;
v21 = *(const char **)&(*v7)[2 * v25 + 2];
v22 = snprintf(
&a2[v15 + 50],
a3 - (v15 + 50),
" Channel %i of %u with id %u and address %s:\n",
v20,
(*v7)[14],
*(unsigned int *)v21,
v21 + 4)
+ v15
+ 50;
v23 = snprintf(&a2[v22], a3 - v22, " type: %s\n", (const char *)(*(_QWORD *)&(*v7)[2 * v25 + 2] + 54LL))
+ v22;
v24 = snprintf(&a2[v23], a3 - v23, " class: %s\n", (const char *)(*(_QWORD *)&(*v7)[2 * v25 + 2] + 204LL))
+ v23;
v15 = snprintf(&a2[v24], a3 - v24, " unit: %s\n", (const char *)(*(_QWORD *)&(*v7)[2 * v25 + 2] + 154LL))
+ v24;
if ( v16 == 20 )
goto LABEL_9;
}
if ( a4 )
{
snprintf(&a2[v15], a3 - v15, "-------------------------------------------------\n");
v15 += snprintf(&a2[v15 + 50], a3 - (v15 + 50), " channel %i is null\n", v16) + 50;
}
LABEL_9:
result = ++v26;
++v7;
if ( v26 == 20 )
return result;
}
if ( a4 )
{
snprintf(&a2[v15], a3 - v15, "*************************************************\n");
result = snprintf(&a2[v15 + 50], a3 - (v15 + 50), " modul %i is null\n", v26);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(unsigned int *a1, char *a2, int a3, int a4)
{
int v5; // esi
unsigned int **v7; // r15
int v8; // ebx
int v9; // ebx
int v10; // ebx
int v11; // ebx
int v12; // ebx
int v13; // ebx
int result; // eax
int v15; // ebx
unsigned int v16; // er14
int v17; // ebx
int v18; // ebx
int v19; // ebx
__int64 v20; // rcx
const char *v21; // rax
int v22; // ebx
int v23; // ebx
int v24; // ebx
__int64 v25; // r13
unsigned int v26; // [rsp+8h] [rbp-40h]

v5 = a3;
if ( !a1 )
return snprintf(a2, a3, "Device is null\n");
v7 = (unsigned int **)(a1 + 114);
v8 = snprintf(a2, a3, "Device %s with id %u:\n", (const char *)a1 + 8, *a1);
v9 = snprintf(&a2[v8], v5 - v8, " name: %s\n", (const char *)a1 + 258) + v8;
v10 = snprintf(&a2[v9], v5 - v9, " software version: %s\n", (const char *)a1 + 322) + v9;
v11 = snprintf(&a2[v10], v5 - v10, " supply: %s\n", (const char *)a1 + 386) + v10;
v12 = snprintf(&a2[v11], v5 - v11, " meassurement interval: %s\n", (const char *)a1 + 108) + v11;
v13 = snprintf(&a2[v12], v5 - v12, " process interval: %s\n", (const char *)a1 + 158) + v12;
result = snprintf(&a2[v13], v5 - v13, " alarm interval: %s\n", (const char *)a1 + 208);
v26 = 0;
v15 = result + v13;
while ( *v7 )
{
v16 = 0;
snprintf(&a2[v15], a3 - v15, "*************************************************\n");
v17 = snprintf(
&a2[v15 + 50],
a3 - (v15 + 50),
" Modul %i of %u with id %u and address %s:\n",
v26,
a1[113],
**v7,
(const char *)*v7 + 4)
+ v15
+ 50;
v18 = snprintf(&a2[v17], a3 - v17, " meassurement interval: %s\n", (const char *)*v7 + 60) + v17;
v19 = snprintf(&a2[v18], a3 - v18, " process interval: %s\n", (const char *)*v7 + 110) + v18;
v15 = snprintf(&a2[v19], a3 - v19, " alarm interval: %s\n", (const char *)*v7 + 160) + v19;
while ( 1 )
{
v25 = (int)v16 + 26LL;
if ( !*(_QWORD *)&(*v7)[2 * v16 + 54] )
break;
snprintf(&a2[v15], a3 - v15, "-------------------------------------------------\n");
v20 = v16++;
v21 = *(const char **)&(*v7)[2 * v25 + 2];
v22 = snprintf(
&a2[v15 + 50],
a3 - (v15 + 50),
" Channel %i of %u with id %u and address %s:\n",
v20,
(*v7)[14],
*(unsigned int *)v21,
v21 + 4)
+ v15
+ 50;
v23 = snprintf(&a2[v22], a3 - v22, " type: %s\n", (const char *)(*(_QWORD *)&(*v7)[2 * v25 + 2] + 54LL))
+ v22;
v24 = snprintf(&a2[v23], a3 - v23, " class: %s\n", (const char *)(*(_QWORD *)&(*v7)[2 * v25 + 2] + 204LL))
+ v23;
v15 = snprintf(&a2[v24], a3 - v24, " unit: %s\n", (const char *)(*(_QWORD *)&(*v7)[2 * v25 + 2] + 154LL))
+ v24;
if ( v16 == 20 )
goto LABEL_9;
}
if ( a4 )
{
snprintf(&a2[v15], a3 - v15, "-------------------------------------------------\n");
v15 += snprintf(&a2[v15 + 50], a3 - (v15 + 50), " channel %i is null\n", v16) + 50;
}
LABEL_9:
result = ++v26;
++v7;
if ( v26 == 20 )
return result;
}
if ( a4 )
{
snprintf(&a2[v15], a3 - v15, "*************************************************\n");
result = snprintf(&a2[v15 + 50], a3 - (v15 + 50), " modul %i is null\n", v26);
}
return result;
}

original_code:
void LprintDeviceStructure(Ldevice *d, char *str, int size, int all){
  int pos = 0;
  int i, j;
  if(d == ((void *)0)){
    pos += snprintf(&str[pos], size - pos, "Device is null\n");
    return;
  }
  pos += snprintf(&str[pos], size - pos, "Device %s with id %u:\n", d->address, d->id);
  pos += snprintf(&str[pos], size - pos, "  name: %s\n", d->name);
  pos += snprintf(&str[pos], size - pos, "  software version: %s\n", d->sw_ver);
  pos += snprintf(&str[pos], size - pos, "  supply: %s\n", d->supply);
  pos += snprintf(&str[pos], size - pos, "  meassurement interval: %s\n", d->mint);
  pos += snprintf(&str[pos], size - pos, "  process interval: %s\n", d->pint);
  pos += snprintf(&str[pos], size - pos, "  alarm interval: %s\n", d->aint);
  for(i=0; i < 20; i++){
    if(d->modul[i] == ((void *)0)){
      if(all){
          pos += snprintf(&str[pos], size - pos, "*************************************************\n");
          pos += snprintf(&str[pos], size - pos, "      modul %i is null\n", i);
      }
      break;
    }else{
      pos += snprintf(&str[pos], size - pos, "*************************************************\n");
      pos += snprintf(&str[pos], size - pos, "  Modul %i of %u with id %u and address %s:\n", i, d->moduls, d->modul[i]->id, d->modul[i]->address);
      pos += snprintf(&str[pos], size - pos, "    meassurement interval: %s\n", d->modul[i]->mint);
      pos += snprintf(&str[pos], size - pos, "    process interval: %s\n", d->modul[i]->pint);
      pos += snprintf(&str[pos], size - pos, "    alarm interval: %s\n", d->modul[i]->aint);
      for(j=0; j < 20; j++){
        if(d->modul[i]->channel[j] == ((void *)0)){
          if(all){
            pos += snprintf(&str[pos], size - pos, "-------------------------------------------------\n");
            pos += snprintf(&str[pos], size - pos, "      channel %i is null\n", j);
          }
          break;
        }else{
          pos += snprintf(&str[pos], size - pos, "-------------------------------------------------\n");
          pos += snprintf(&str[pos], size - pos, "      Channel %i of %u with id %u and address %s:\n",
                           j, d->modul[i]->channels, d->modul[i]->channel[j]->id, d->modul[i]->channel[j]->address);
          pos += snprintf(&str[pos], size - pos, "      type: %s\n", d->modul[i]->channel[j]->type);
          pos += snprintf(&str[pos], size - pos, "      class: %s\n", d->modul[i]->channel[j]->class);
          pos += snprintf(&str[pos], size - pos, "      unit: %s\n", d->modul[i]->channel[j]->unit);
        }
      }
    }
  }
}

canonical_original_code:
void LprintDeviceStructure(struct Ldevice_struct *d, char *str, int size, int all){
  int pos = 0;
  int i; int j;
  if(d == ((void *)0)){
    pos += snprintf(&str[pos], size - pos, "Device is null\n");
    return;
  }
  pos += snprintf(&str[pos], size - pos, "Device %s with id %u:\n", d->address, d->id);
  pos += snprintf(&str[pos], size - pos, "  name: %s\n", d->name);
  pos += snprintf(&str[pos], size - pos, "  software version: %s\n", d->sw_ver);
  pos += snprintf(&str[pos], size - pos, "  supply: %s\n", d->supply);
  pos += snprintf(&str[pos], size - pos, "  meassurement interval: %s\n", d->mint);
  pos += snprintf(&str[pos], size - pos, "  process interval: %s\n", d->pint);
  pos += snprintf(&str[pos], size - pos, "  alarm interval: %s\n", d->aint);
  for(i=0; i < 20; i++){
    if(d->modul[i] == ((void *)0)){
      if(all){
          pos += snprintf(&str[pos], size - pos, "*************************************************\n");
          pos += snprintf(&str[pos], size - pos, "      modul %i is null\n", i);
      }
      break;
    }else{
      pos += snprintf(&str[pos], size - pos, "*************************************************\n");
      pos += snprintf(&str[pos], size - pos, "  Modul %i of %u with id %u and address %s:\n", i, d->moduls, d->modul[i]->id, d->modul[i]->address);
      pos += snprintf(&str[pos], size - pos, "    meassurement interval: %s\n", d->modul[i]->mint);
      pos += snprintf(&str[pos], size - pos, "    process interval: %s\n", d->modul[i]->pint);
      pos += snprintf(&str[pos], size - pos, "    alarm interval: %s\n", d->modul[i]->aint);
      for(j=0; j < 20; j++){
        if(d->modul[i]->channel[j] == ((void *)0)){
          if(all){
            pos += snprintf(&str[pos], size - pos, "-------------------------------------------------\n");
            pos += snprintf(&str[pos], size - pos, "      channel %i is null\n", j);
          }
          break;
        }else{
          pos += snprintf(&str[pos], size - pos, "-------------------------------------------------\n");
          pos += snprintf(&str[pos], size - pos, "      Channel %i of %u with id %u and address %s:\n",
                           j, d->modul[i]->channels, d->modul[i]->channel[j]->id, d->modul[i]->channel[j]->address);
          pos += snprintf(&str[pos], size - pos, "      type: %s\n", d->modul[i]->channel[j]->type);
          pos += snprintf(&str[pos], size - pos, "      class: %s\n", d->modul[i]->channel[j]->class);
          pos += snprintf(&str[pos], size - pos, "      unit: %s\n", d->modul[i]->channel[j]->unit);
        }
      }
    }
  }
}

variable_types: struct Ldevice_struct { unsigned int id; int registered; char address[50]; char mac[50]; char mint[50]; char pint[50]; char aint[50]; char name[64]; char sw_ver[64]; char supply[64]; int moduls; struct Lmodul_struct { unsigned int id; char address[50]; int channels; char mint[50]; char pint[50]; char aint[50]; struct Lchannel_struct { unsigned int id; char address[50]; char type[50]; char sensor[50]; char unit[50]; char class[50]; double exponent; } *channel[20]; } *modul[20]; 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; } lastProcessed; int hasLogger; int event; struct lwp_wkc_struct { struct lwp_resource_struct { char name[100]; int attributes; struct lwp_attr_struct { char name[100]; } attr[10]; } info; struct lwp_resource_struct device; struct lwp_resource_struct modul; struct lwp_resource_struct network; struct lwp_resource_struct database; struct lwp_resource_struct logger; struct lwp_resource_struct channel[20]; int channels; } wkc; } *

variable_types:
str
char *

variable_types: size int

variable_types: all int

variable_types: pos int

variable_types: i int

variable_types: j int

return_type: void

user_defined_types: struct Ldevice_struct { unsigned int id; int registered; char address[50]; char mac[50]; char mint[50]; char pint[50]; char aint[50]; char name[64]; char sw_ver[64]; char supply[64]; int moduls; struct Lmodul_struct *modul[20]; struct tm lastProcessed; int hasLogger; int event; struct lwp_wkc_struct wkc; }

user_defined_types: struct lwp_wkc_struct { struct lwp_resource_struct info; struct lwp_resource_struct device; struct lwp_resource_struct modul; struct lwp_resource_struct network; struct lwp_resource_struct database; struct lwp_resource_struct logger; struct lwp_resource_struct channel[20]; int channels; }

user_defined_types: struct lwp_resource_struct { char name[100]; int attributes; struct lwp_attr_struct attr[10]; }

user_defined_types: struct Lmodul_struct { unsigned int id; char address[50]; int channels; char mint[50]; char pint[50]; char aint[50]; struct Lchannel_struct *channel[20]; }


decompiled_code:
void __fastcall jsmn_parse_primitive(unsigned int *a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
__int64 v4; // rax
char v7; // cl
unsigned int v8; // er10
unsigned int v9; // eax
__int64 v10; // rdx
_DWORD *v11; // rdi
int *v12; // r9
int v13; // er10
_DWORD *v14; // r9

v4 = *a1;
v7 = *(_BYTE *)(a2 + v4);
v8 = *a1;
if ( v7 )
{
v9 = v4 + 1;
while ( v7 <= 58 )
{
if ( v7 <= 8 )
goto LABEL_4;
if ( ((1LL << v7) & 0x400100100002600LL) != 0 )
goto LABEL_8;
if ( (unsigned __int8)(v7 - 32) > 0x5Eu )
{
LABEL_12:
*a1 = v8;
return;
}
LABEL_5:
v10 = v9;
*a1 = v9++;
v7 = *(_BYTE *)(a2 + v10);
if ( !v7 )
goto LABEL_8;
}
if ( (v7 & 0xDF) == 93 )
goto LABEL_8;
LABEL_4:
if ( (unsigned __int8)(v7 - 32) > 0x5Eu )
goto LABEL_12;
goto LABEL_5;
}
LABEL_8:
v11 = (_DWORD *)jsmn_alloc_token((__int64)a1, a3, a4);
if ( v11 )
{
jsmn_fill_token(v11, 0, v13, *v12);
--*v14;
}
else
{
*v12 = v13;
}
}

original_code:
static jsmnerr_t jsmn_parse_primitive(jsmn_parser *parser, const char *js,
  jsmntok_t *tokens, size_t num_tokens) {
 jsmntok_t *token;
 int start;
 start = parser->pos;
 for (; js[parser->pos] != '\0'; parser->pos++) {
  switch (js[parser->pos]) {
   case ':':
   case '\t' : case '\r' : case '\n' : case ' ' :
   case ',' : case ']' : case '}' :
    goto found;
  }
  if (js[parser->pos] < 32 || js[parser->pos] >= 127) {
   parser->pos = start;
   return JSMN_ERROR_INVAL;
  }
 }
found:
 token = jsmn_alloc_token(parser, tokens, num_tokens);
 if (token == ((void *)0)) {
  parser->pos = start;
  return JSMN_ERROR_NOMEM;
 }
 jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
 parser->pos--;
 return JSMN_SUCCESS;
}

canonical_original_code:
static enum jsmnerr_t jsmn_parse_primitive(struct jsmn_parser *parser, char *js, struct jsmntok_t *tokens, unsigned long num_tokens) {
 struct jsmntok_t *token;
 int start;
 start = parser->pos;
 for (; js[parser->pos] != '\0'; parser->pos++) {
  switch (js[parser->pos]) {
   case ':':
   case '\t' : case '\r' : case '\n' : case ' ' :
   case ',' : case ']' : case '}' :
    goto found;
  }
  if (js[parser->pos] < 32 || js[parser->pos] >= 127) {
   parser->pos = start;
   return JSMN_ERROR_INVAL;
  }
 }
found:
 token = jsmn_alloc_token(parser, tokens, num_tokens);
 if (token == ((void *)0)) {
  parser->pos = start;
  return JSMN_ERROR_NOMEM;
 }
 jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
 parser->pos--;
 return JSMN_SUCCESS;
}

variable_types: struct jsmn_parser { unsigned int pos; int toknext; int toksuper; } *

variable_types:
js
char *

variable_types: struct jsmntok_t { enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 } type; int start; int end; int size; } *

variable_types: start int

return_type: enum jsmnerr_t { JSMN_ERROR_NOMEM=-1, JSMN_ERROR_INVAL=-2, JSMN_ERROR_PART=-3, JSMN_SUCCESS=0 }

user_defined_types: struct jsmntok_t { enum jsmntype_t type; int start; int end; int size; }


original_code:
static jsmnerr_t jsmn_parse_string(jsmn_parser *parser, const char *js,
  jsmntok_t *tokens, size_t num_tokens) {
 jsmntok_t *token;
 int start = parser->pos;
 parser->pos++;
 for (; js[parser->pos] != '\0'; parser->pos++) {
  char c = js[parser->pos];
  if (c == '\"') {
   token = jsmn_alloc_token(parser, tokens, num_tokens);
   if (token == ((void *)0)) {
    parser->pos = start;
    return JSMN_ERROR_NOMEM;
   }
   jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos);
   return JSMN_SUCCESS;
  }
  if (c == '\\') {
   parser->pos++;
   switch (js[parser->pos]) {
    case '\"': case '/' : case '\\' : case 'b' :
    case 'f' : case 'r' : case 'n' : case 't' :
     break;
    case 'u':
     break;
    default:
     parser->pos = start;
     return JSMN_ERROR_INVAL;
   }
  }
 }
 parser->pos = start;
 return JSMN_ERROR_PART;
}

canonical_original_code:
static enum jsmnerr_t jsmn_parse_string(struct jsmn_parser *parser, char *js, struct jsmntok_t *tokens, unsigned long num_tokens) {
 struct jsmntok_t *token;
 int start = parser->pos;
 parser->pos++;
 for (; js[parser->pos] != '\0'; parser->pos++) {
  char c = js[parser->pos];
  if (c == '\"') {
   token = jsmn_alloc_token(parser, tokens, num_tokens);
   if (token == ((void *)0)) {
    parser->pos = start;
    return JSMN_ERROR_NOMEM;
   }
   jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos);
   return JSMN_SUCCESS;
  }
  if (c == '\\') {
   parser->pos++;
   switch (js[parser->pos]) {
    case '\"': case '/' : case '\\' : case 'b' :
    case 'f' : case 'r' : case 'n' : case 't' :
     break;
    case 'u':
     break;
    default:
     parser->pos = start;
     return JSMN_ERROR_INVAL;
   }
  }
 }
 parser->pos = start;
 return JSMN_ERROR_PART;
}

variable_types: c char

user_defined_types: enum jsmnerr_t { JSMN_ERROR_NOMEM=-1, JSMN_ERROR_INVAL=-2, JSMN_ERROR_PART=-3, JSMN_SUCCESS=0 }

user_defined_types: struct jsmn_parser { unsigned int pos; int toknext; int toksuper; }

user_defined_types: enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 }


original_code:
jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, jsmntok_t *tokens,
  unsigned int num_tokens) {
 jsmnerr_t r;
 int i;
 jsmntok_t *token;
 for (; js[parser->pos] != '\0'; parser->pos++) {
  char c;
  jsmntype_t type;
  c = js[parser->pos];
  switch (c) {
   case '{': case '[':
    token = jsmn_alloc_token(parser, tokens, num_tokens);
    if (token == ((void *)0))
     return JSMN_ERROR_NOMEM;
    if (parser->toksuper != -1) {
     tokens[parser->toksuper].size++;
    }
    token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
    token->start = parser->pos;
    parser->toksuper = parser->toknext - 1;
    break;
   case '}': case ']':
    type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
    for (i = parser->toknext - 1; i >= 0; i--) {
     token = &tokens[i];
     if (token->start != -1 && token->end == -1) {
      if (token->type != type) {
       return JSMN_ERROR_INVAL;
      }
      parser->toksuper = -1;
      token->end = parser->pos + 1;
      break;
     }
    }
    if (i == -1) return JSMN_ERROR_INVAL;
    for (; i >= 0; i--) {
     token = &tokens[i];
     if (token->start != -1 && token->end == -1) {
      parser->toksuper = i;
      break;
     }
    }
    break;
   case '\"':
    r = jsmn_parse_string(parser, js, tokens, num_tokens);
    if (r < 0) return r;
    if (parser->toksuper != -1)
     tokens[parser->toksuper].size++;
    break;
   case '\t' : case '\r' : case '\n' : case ':' : case ',': case ' ':
    break;
   default:
    r = jsmn_parse_primitive(parser, js, tokens, num_tokens);
    if (r < 0) return r;
    if (parser->toksuper != -1)
     tokens[parser->toksuper].size++;
    break;
  }
 }
 for (i = parser->toknext - 1; i >= 0; i--) {
  if (tokens[i].start != -1 && tokens[i].end == -1) {
   return JSMN_ERROR_PART;
  }
 }
 return JSMN_SUCCESS;
}

canonical_original_code:
enum jsmnerr_t jsmn_parse(struct jsmn_parser *parser, char *js, struct jsmntok_t *tokens, unsigned int num_tokens) {
 enum jsmnerr_t r;
 int i;
 struct jsmntok_t *token;
 for (; js[parser->pos] != '\0'; parser->pos++) {
  char c;
  enum jsmntype_t type;
  c = js[parser->pos];
  switch (c) {
   case '{': case '[':
    token = jsmn_alloc_token(parser, tokens, num_tokens);
    if (token == ((void *)0))
     return JSMN_ERROR_NOMEM;
    if (parser->toksuper != -1) {
     tokens[parser->toksuper].size++;
    }
    token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
    token->start = parser->pos;
    parser->toksuper = parser->toknext - 1;
    break;
   case '}': case ']':
    type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
    for (i = parser->toknext - 1; i >= 0; i--) {
     token = &tokens[i];
     if (token->start != -1 && token->end == -1) {
      if (token->type != type) {
       return JSMN_ERROR_INVAL;
      }
      parser->toksuper = -1;
      token->end = parser->pos + 1;
      break;
     }
    }
    if (i == -1) return JSMN_ERROR_INVAL;
    for (; i >= 0; i--) {
     token = &tokens[i];
     if (token->start != -1 && token->end == -1) {
      parser->toksuper = i;
      break;
     }
    }
    break;
   case '\"':
    r = jsmn_parse_string(parser, js, tokens, num_tokens);
    if (r < 0) return r;
    if (parser->toksuper != -1)
     tokens[parser->toksuper].size++;
    break;
   case '\t' : case '\r' : case '\n' : case ':' : case ',': case ' ':
    break;
   default:
    r = jsmn_parse_primitive(parser, js, tokens, num_tokens);
    if (r < 0) return r;
    if (parser->toksuper != -1)
     tokens[parser->toksuper].size++;
    break;
  }
 }
 for (i = parser->toknext - 1; i >= 0; i--) {
  if (tokens[i].start != -1 && tokens[i].end == -1) {
   return JSMN_ERROR_PART;
  }
 }
 return JSMN_SUCCESS;
}

variable_types: enum jsmnerr_t { JSMN_ERROR_NOMEM=-1, JSMN_ERROR_INVAL=-2, JSMN_ERROR_PART=-3, JSMN_SUCCESS=0 }

variable_types: enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 }


LcreateModul

decompiled_code:
_BYTE *LcreateModul()
{
_BYTE *result; // rax

result = malloc(0x178uLL);
if ( result )
{
*(_DWORD *)result = 0;
result[4] = 0;
*((_DWORD *)result + 14) = 0;
*((_QWORD *)result + 27) = 0LL;
}
else
{
lielas_log("Can't allocate memory for new modul", 0LL);
result = 0LL;
}
return result;
}

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

result = malloc(0x178uLL);
if ( result )
{
*(_DWORD *)result = 0;
result[4] = 0;
*((_DWORD *)result + 14) = 0;
*((_QWORD *)result + 27) = 0LL;
}
else
{
lielas_log("Can't allocate memory for new modul", 0LL);
result = 0LL;
}
return result;
}

original_code:
Lmodul *LcreateModul(){
 Lmodul *m = malloc(sizeof(Lmodul));
 if(m == ((void *)0)){
  lielas_log((unsigned char*)"Can't allocate memory for new modul", 0);
  return ((void *)0);
 }
 m->id = 0;
 m->address[0] = 0;
 m->channels = 0;
 m->channel[0] = ((void *)0);
 return m;
}

canonical_original_code:
struct Lmodul_struct *LcreateModul(){
 struct Lmodul_struct *m = malloc(sizeof(Lmodul));
 if(m == ((void *)0)){
  lielas_log((unsigned char *)"Can't allocate memory for new modul", 0);
  return ((void *)0);
 }
 m->id = 0;
 m->address[0] = 0;
 m->channels = 0;
 m->channel[0] = ((void *)0);
 return m;
}

return_type: struct Lmodul_struct { unsigned int id; char address[50]; int channels; char mint[50]; char pint[50]; char aint[50]; struct Lchannel_struct { unsigned int id; char address[50]; char type[50]; char sensor[50]; char unit[50]; char class[50]; double exponent; } *channel[20]; } *


LdeleteModul

decompiled_code:
void __fastcall LdeleteModul(void *ptr)
{
__int64 v2; // rbx
__int64 v3; // rdi

if ( *((int *)ptr + 14) > 0 )
{
v2 = 0LL;
do
{
v3 = *((_QWORD *)ptr + v2++ + 27);
LdeleteChannel(v3);
}
while ( *((_DWORD *)ptr + 14) > (int)v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 v2; // rbx
__int64 v3; // rdi

if ( *((int *)ptr + 14) > 0 )
{
v2 = 0LL;
do
{
v3 = *((_QWORD *)ptr + v2++ + 27);
LdeleteChannel(v3);
}
while ( *((_DWORD *)ptr + 14) > (int)v2 );
}
free(ptr);
}

original_code:
void LdeleteModul(Lmodul *m){
 int i;
 for( i = 0; i < m->channels; i++){
  LdeleteChannel(m->channel[i]);
 }
 free(m);
}

canonical_original_code:
void LdeleteModul(struct Lmodul_struct *m){
 int i;
 for( i = 0; i < m->channels; i++){
  LdeleteChannel(m->channel[i]);
 }
 free(m);
}

user_defined_types: struct Lchannel_struct { unsigned int id; char address[50]; char type[50]; char sensor[50]; char unit[50]; char class[50]; double exponent; }


LaddChannel

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

result = *(unsigned int *)(a1 + 56);
if ( (_DWORD)result == 20 )
return lielas_log("Can't add channel, maximum number of channels reached", 1LL);
*(_QWORD *)(a1 + 8LL * ((int)result + 1) + 216) = a2;
*(_DWORD *)(a1 + 56) = result + 1;
if ( (int)result + 1 <= 20 )
{
result = (int)result + 2;
*(_QWORD *)(a1 + 8 * result + 216) = 0LL;
}
return result;
}

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

result = *(unsigned int *)(a1 + 56);
if ( (_DWORD)result == 20 )
return lielas_log("Can't add channel, maximum number of channels reached", 1LL);
*(_QWORD *)(a1 + 8LL * ((int)result + 1) + 216) = a2;
*(_DWORD *)(a1 + 56) = result + 1;
if ( (int)result + 1 <= 20 )
{
result = (int)result + 2;
*(_QWORD *)(a1 + 8 * result + 216) = 0LL;
}
return result;
}

original_code:
void LaddChannel(Lmodul *m, Lchannel *channel){
 if(m->channels == 20){
  lielas_log((unsigned char*)"Can't add channel, maximum number of channels reached", 1);
  return;
 }
 m->channel[m->channels+1] = channel;
  m->channels += 1;
 if(m->channels <= 20){
  m->channel[m->channels+1] = ((void *)0);
 }
}

canonical_original_code:
void LaddChannel(struct Lmodul_struct *m, struct Lchannel_struct *channel){
 if(m->channels == 20){
  lielas_log((unsigned char *)"Can't add channel, maximum number of channels reached", 1);
  return;
 }
 m->channel[m->channels+1] = channel;
  m->channels += 1;
 if(m->channels <= 20){
  m->channel[m->channels+1] = ((void *)0);
 }
}

variable_types:
channel
struct Lchannel_struct *


LremoveChannel

decompiled_code:
__int64 __fastcall LremoveChannel(__int64 a1, __int64 a2)
{
__int64 v3; // rax
int v4; // esi
int v5; // ecx
__int64 result; // rax

v3 = 0LL;
v4 = *(_DWORD *)(a1 + 56);
while ( 1 )
{
v5 = v3;
if ( v4 <= (int)v3 )
break;
if ( *(_QWORD *)(a1 + 8 * v3 + 216) == a2 )
goto LABEL_8;
if ( ++v3 == 20 )
{
v5 = 20;
break;
}
}
if ( *(_QWORD *)(a1 + 8LL * v5 + 216) != a2 )
return lielas_log("Can't remove channel, channel not found", 1LL);
LABEL_8:
if ( v4 - 1 != v5 && v4 > v5 )
memmove(
(void *)(a1 + 8LL * (v5 + 27)),
(const void *)(a1 + 8LL * (v5 + 27) + 8),
8LL * (unsigned int)(v4 - 1 - v5) + 8);
result = LdeleteChannel(a2);
--*(_DWORD *)(a1 + 56);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v3; // rax
int v4; // esi
int v5; // ecx
__int64 result; // rax

v3 = 0LL;
v4 = *(_DWORD *)(a1 + 56);
while ( 1 )
{
v5 = v3;
if ( v4 <= (int)v3 )
break;
if ( *(_QWORD *)(a1 + 8 * v3 + 216) == a2 )
goto LABEL_8;
if ( ++v3 == 20 )
{
v5 = 20;
break;
}
}
if ( *(_QWORD *)(a1 + 8LL * v5 + 216) != a2 )
return lielas_log("Can't remove channel, channel not found", 1LL);
LABEL_8:
if ( v4 - 1 != v5 && v4 > v5 )
memmove(
(void *)(a1 + 8LL * (v5 + 27)),
(const void *)(a1 + 8LL * (v5 + 27) + 8),
8LL * (unsigned int)(v4 - 1 - v5) + 8);
result = LdeleteChannel(a2);
--*(_DWORD *)(a1 + 56);
return result;
}

original_code:
void LremoveChannel(Lmodul *m, Lchannel *channel){
 Lchannel *c;
 int i;
 int cIndex;
 for( cIndex = 0; cIndex < 20 && cIndex < m->channels; cIndex++){
  if(m->channel[cIndex] == channel){
   break;
  }
 }
 if(m->channel[cIndex] != channel){
  lielas_log((unsigned char*)"Can't remove channel, channel not found", 1);
  return;
 }
 c = m->channel[cIndex];
 if(cIndex != (m->channels - 1)){
  for( i = cIndex; i < m->channels; i++){
   m->channel[i] = m->channel[i+1];
  }
 }
 LdeleteChannel(c);
 m->channels -= 1;
}

canonical_original_code:
void LremoveChannel(struct Lmodul_struct *m, struct Lchannel_struct *channel){
 struct Lchannel_struct *c;
 int i;
 int cIndex;
 for( cIndex = 0; cIndex < 20 && cIndex < m->channels; cIndex++){
  if(m->channel[cIndex] == channel){
   break;
  }
 }
 if(m->channel[cIndex] != channel){
  lielas_log((unsigned char *)"Can't remove channel, channel not found", 1);
  return;
 }
 c = m->channel[cIndex];
 if(cIndex != (m->channels - 1)){
  for( i = cIndex; i < m->channels; i++){
   m->channel[i] = m->channel[i+1];
  }
 }
 LdeleteChannel(c);
 m->channels -= 1;
}

variable_types: struct Lmodul_struct { unsigned int id; char address[50]; int channels; char mint[50]; char pint[50]; char aint[50]; struct Lchannel_struct { unsigned int id; char address[50]; char type[50]; char sensor[50]; char unit[50]; char class[50]; double exponent; } *channel[20]; } *

variable_types: cIndex int


decompiled_code:
void __fastcall i2c_init(int a1, int a2)
{
i2c_adr = a1;
i2c_nr = a2;
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2)
{
i2c_adr = a1;
i2c_nr = a2;
}

original_code:
void i2c_init(int address, int i2c){
  i2c_adr = address;
  i2c_nr = i2c;
}

variable_types: address int


decompiled_code:
__int64 __fastcall read_register(unsigned __int8 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
char v5[28]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = a1;
if ( (unsigned int)i2c_writeb(a1, v5, 0LL) )
result = 0xFFFFFFFFLL;
else
result = i2c_read(a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
char v5[28]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = a1;
if ( (unsigned int)i2c_writeb(a1, v5, 0LL) )
result = 0xFFFFFFFFLL;
else
result = i2c_read(a2, a3);
return result;
}

original_code:
int read_register(uint8_t reg, uint8_t *data, int len){
  if(i2c_writeb(reg, &reg, 0))
    return -1;
  return i2c_read(data, len);
}

canonical_original_code:
int read_register(unsigned char reg, unsigned char *data, int len){
  if(i2c_writeb(reg, &reg, 0))
    return -1;
  return i2c_read(data, len);
}

variable_types:
reg
unsigned char

variable_types:
data
unsigned char *

variable_types: len int

return_type: int


decompiled_code:
__int64 __fastcall rtc4162_get(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // edx
char v3[2]; // [rsp+0h] [rbp-28h] BYREF
unsigned __int8 v4; // [rsp+2h] [rbp-26h]
unsigned __int8 v5; // [rsp+3h] [rbp-25h]
unsigned __int8 v6; // [rsp+5h] [rbp-23h]
unsigned __int8 v7; // [rsp+6h] [rbp-22h]
unsigned __int8 v8; // [rsp+7h] [rbp-21h]

v3[0] = 0;
if ( oscfailed )
{
lielas_log("rtc error: failed to read date/time, oscfailed flag is set", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
result = read_register(0, (__int64)v3, 8u);
if ( (_DWORD)result )
{
lielas_log("rtc error: failed to read date/time", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
v2 = (unsigned __int8)v3[1];
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 32) = 0;
*(_DWORD *)a1 = (v2 & 0xF) + 10 * ((v2 >> 4) & 7);
*(_DWORD *)(a1 + 4) = (v4 & 0xF) + 10 * ((v4 >> 4) & 7);
*(_DWORD *)(a1 + 8) = (v5 & 0xF) + 10 * ((v5 >> 4) & 3);
*(_DWORD *)(a1 + 12) = (v6 & 0xF) + 10 * ((v6 >> 4) & 3);
*(_DWORD *)(a1 + 16) = (v7 & 0xF) + 10 * ((v7 >> 4) & 1);
*(_DWORD *)(a1 + 20) = (v8 & 0xF) + 10 * (v8 >> 4) + 100;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // edx
char v3[2]; // [rsp+0h] [rbp-28h] BYREF
unsigned __int8 v4; // [rsp+2h] [rbp-26h]
unsigned __int8 v5; // [rsp+3h] [rbp-25h]
unsigned __int8 v6; // [rsp+5h] [rbp-23h]
unsigned __int8 v7; // [rsp+6h] [rbp-22h]
unsigned __int8 v8; // [rsp+7h] [rbp-21h]

v3[0] = 0;
if ( oscfailed )
{
lielas_log("rtc error: failed to read date/time, oscfailed flag is set", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
result = func0(0, (__int64)v3, 8u);
if ( (_DWORD)result )
{
lielas_log("rtc error: failed to read date/time", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
v2 = (unsigned __int8)v3[1];
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 32) = 0;
*(_DWORD *)a1 = (v2 & 0xF) + 10 * ((v2 >> 4) & 7);
*(_DWORD *)(a1 + 4) = (v4 & 0xF) + 10 * ((v4 >> 4) & 7);
*(_DWORD *)(a1 + 8) = (v5 & 0xF) + 10 * ((v5 >> 4) & 3);
*(_DWORD *)(a1 + 12) = (v6 & 0xF) + 10 * ((v6 >> 4) & 3);
*(_DWORD *)(a1 + 16) = (v7 & 0xF) + 10 * ((v7 >> 4) & 1);
*(_DWORD *)(a1 + 20) = (v8 & 0xF) + 10 * (v8 >> 4) + 100;
}
}
return result;
}

canonical_original_code:
int rtc4162_get(struct tm *dt){
  unsigned char buf[20];
  buf[0] = 0;
  if(oscfailed){
    lielas_log((unsigned char *)"rtc error: failed to read date/time, oscfailed flag is set", 0);
    return -1;
  }
  if(read_register(0x00, buf, 8)){
    lielas_log((unsigned char *)"rtc error: failed to read date/time", 0);
    return -1;
  }
  dt->tm_sec = ((((buf[1] & 0x7F)>>4) & 0x0F)*10 + ((buf[1] & 0x7F) & 0x0F));
  dt->tm_min = ((((buf[2] & 0x7F)>>4) & 0x0F)*10 + ((buf[2] & 0x7F) & 0x0F));
  dt->tm_hour= ((((buf[3] & 0x3F)>>4) & 0x0F)*10 + ((buf[3] & 0x3F) & 0x0F));
  dt->tm_mday= ((((buf[5] & 0x3F)>>4) & 0x0F)*10 + ((buf[5] & 0x3F) & 0x0F));
  dt->tm_mon = ((((buf[6] & 0x1F)>>4) & 0x0F)*10 + ((buf[6] & 0x1F) & 0x0F));
  dt->tm_year= ((((buf[7] & 0xFF)>>4) & 0x0F)*10 + ((buf[7] & 0xFF) & 0x0F)) + 100;
  dt->tm_wday = 0;
  dt->tm_yday = 0;
  dt->tm_isdst = 0;
  return 0;
}

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:
buf
unsigned char [20]


decompiled_code:
__int64 __fastcall write_register(unsigned __int8 a1, __int64 a2, __int64 a3)
{
if ( (int)a3 <= 16 )
return i2c_writeb(a1, a2, a3);
lielas_log("rtc write_register error: len to big", 1LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1, __int64 a2, __int64 a3)
{
if ( (int)a3 <= 16 )
return i2c_writeb(a1, a2, a3);
lielas_log("rtc write_register error: len to big", 1LL);
return 0xFFFFFFFFLL;
}

original_code:
int write_register(uint8_t reg, uint8_t *data, int len){
  if(len > 16){
    lielas_log((uint8_t *)"rtc write_register error: len to big", 1);
    return -1;
  }
  return i2c_writeb(reg, data, len);
}

canonical_original_code:
int write_register(unsigned char reg, unsigned char *data, int len){
  if(len > 16){
    lielas_log((unsigned char *)"rtc write_register error: len to big", 1);
    return -1;
  }
  return i2c_writeb(reg, data, len);
}


decompiled_code:
__int64 rtc4162_init()
{
__int64 result; // rax
unsigned __int8 v1; // bl
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

i2c_init(104LL, 1LL);
if ( (unsigned __int8)read_register(0xFu, (__int64)v2, 1u) )
{
lielas_log("rtc error: failed to read REG_FLAGS", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
oscfailed = 0;
if ( (v2[0] & 4) == 0 )
return 0LL;
oscfailed = 1;
lielas_log("rtc: oscillator failure or initial startup", 1LL);
v2[0] |= 0x80u;
v1 = write_register(1u, (__int64)v2, 1LL);
v2[0] &= 0x7Fu;
if ( (unsigned __int8)write_register(1u, (__int64)v2, 1LL) | v1 )
{
lielas_log("rtc error: failed to reset oscillator", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
sleep(5u);
if ( (unsigned __int8)read_register(4u, (__int64)v2, 1u) )
{
lielas_log("rtc error: failed to read REG_DAYOW", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
v2[0] &= 0xFu;
if ( (unsigned __int8)write_register(4u, (__int64)v2, 1LL) )
{
lielas_log("rtc error: failed to write REG_DAYOW", 0LL);
result = 0xFFFFFFFFLL;
}
else if ( (unsigned __int8)read_register(0xAu, (__int64)v2, 1u) )
{
lielas_log("rtc error: failed to read REG_MONTH_ALARM", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
v2[0] &= 0xBFu;
if ( !(unsigned __int8)write_register(0xAu, (__int64)v2, 1LL) )
return 0LL;
lielas_log("rtc error: failed to write REG_MONTH_ALARM", 0LL);
result = 0xFFFFFFFFLL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
unsigned __int8 v1; // bl
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

i2c_init(104LL, 1LL);
if ( (unsigned __int8)func0(0xFu, (__int64)v2, 1u) )
{
lielas_log("rtc error: failed to read REG_FLAGS", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
oscfailed = 0;
if ( (v2[0] & 4) == 0 )
return 0LL;
oscfailed = 1;
lielas_log("rtc: oscillator failure or initial startup", 1LL);
v2[0] |= 0x80u;
v1 = func2(1u, (__int64)v2, 1LL);
v2[0] &= 0x7Fu;
if ( (unsigned __int8)func2(1u, (__int64)v2, 1LL) | v1 )
{
lielas_log("rtc error: failed to reset oscillator", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
sleep(5u);
if ( (unsigned __int8)func0(4u, (__int64)v2, 1u) )
{
lielas_log("rtc error: failed to read REG_DAYOW", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
v2[0] &= 0xFu;
if ( (unsigned __int8)func2(4u, (__int64)v2, 1LL) )
{
lielas_log("rtc error: failed to write REG_DAYOW", 0LL);
result = 0xFFFFFFFFLL;
}
else if ( (unsigned __int8)func0(0xAu, (__int64)v2, 1u) )
{
lielas_log("rtc error: failed to read REG_MONTH_ALARM", 0LL);
result = 0xFFFFFFFFLL;
}
else
{
v2[0] &= 0xBFu;
if ( !(unsigned __int8)func2(0xAu, (__int64)v2, 1LL) )
return 0LL;
lielas_log("rtc error: failed to write REG_MONTH_ALARM", 0LL);
result = 0xFFFFFFFFLL;
}
}
}
}
return result;
}

original_code:
int rtc4162_init(){
  uint8_t byte;
  uint8_t status;
  i2c_init(0x68, 1);
  status = read_register(0x0F, &byte, 1);
  if(status){
    lielas_log((uint8_t *)"rtc error: failed to read REG_FLAGS", 0);
    return -1;
  }
  oscfailed = 0;
  if(byte & (1<<(2))){
    oscfailed = 1;
    lielas_log((uint8_t *)"rtc: oscillator failure or initial startup", 1);
    byte |= (1<<(7));
    status |= write_register(0x01, &byte, 1);
  byte &= ~(1<<(7));
  status |= write_register(0x01, &byte, 1);
    if(status){
      lielas_log((uint8_t *)"rtc error: failed to reset oscillator", 0);
      return -1;
    }
    sleep(5);
  status = read_register(0x04, &byte, 1);
    if(status){
      lielas_log((uint8_t *)"rtc error: failed to read REG_DAYOW", 0);
      return -1;
    }
  byte &= 0x0F;
  status = write_register(0x04, &byte, 1);
    if(status){
      lielas_log((uint8_t *)"rtc error: failed to write REG_DAYOW", 0);
      return -1;
    }
  status = read_register(0x0A, &byte, 1);
    if(status){
      lielas_log((uint8_t *)"rtc error: failed to read REG_MONTH_ALARM", 0);
      return -1;
    }
  byte &= ~(1<<(6));
  status = write_register(0x0A, &byte, 1);
    if(status){
      lielas_log((uint8_t *)"rtc error: failed to write REG_MONTH_ALARM", 0);
      return -1;
    }
  }
  return 0;
}

canonical_original_code:
int rtc4162_init(){
  unsigned char byte;
  unsigned char status;
  i2c_init(0x68, 1);
  status = read_register(0x0F, &byte, 1);
  if(status){
    lielas_log((unsigned char *)"rtc error: failed to read REG_FLAGS", 0);
    return -1;
  }
  oscfailed = 0;
  if(byte & (1<<(2))){
    oscfailed = 1;
    lielas_log((unsigned char *)"rtc: oscillator failure or initial startup", 1);
    byte |= (1<<(7));
    status |= write_register(0x01, &byte, 1);
  byte &= ~(1<<(7));
  status |= write_register(0x01, &byte, 1);
    if(status){
      lielas_log((unsigned char *)"rtc error: failed to reset oscillator", 0);
      return -1;
    }
    sleep(5);
  status = read_register(0x04, &byte, 1);
    if(status){
      lielas_log((unsigned char *)"rtc error: failed to read REG_DAYOW", 0);
      return -1;
    }
  byte &= 0x0F;
  status = write_register(0x04, &byte, 1);
    if(status){
      lielas_log((unsigned char *)"rtc error: failed to write REG_DAYOW", 0);
      return -1;
    }
  status = read_register(0x0A, &byte, 1);
    if(status){
      lielas_log((unsigned char *)"rtc error: failed to read REG_MONTH_ALARM", 0);
      return -1;
    }
  byte &= ~(1<<(6));
  status = write_register(0x0A, &byte, 1);
    if(status){
      lielas_log((unsigned char *)"rtc error: failed to write REG_MONTH_ALARM", 0);
      return -1;
    }
  }
  return 0;
}

variable_types:
byte
unsigned char

variable_types:
status
unsigned char


canonical_original_code:
int rtc4162_set(struct tm *dt){
  unsigned char buf[10] = {0};
  buf[1] = (buf[1] & ~0x7F) | ((((((dt->tm_sec)/10)<<4) & 0xF0) + (dt->tm_sec)%10) & 0x7F);
 buf[2] = (buf[2] & ~0x7F) | ((((((dt->tm_min)/10)<<4) & 0xF0) + (dt->tm_min)%10) & 0x7F);
 buf[3] = (buf[3] & ~0x3F) | ((((((dt->tm_hour)/10)<<4) & 0xF0) + (dt->tm_hour)%10) & 0x3F);
 buf[5] = (buf[5] & ~0x3F) | ((((((dt->tm_mday)/10)<<4) & 0xF0) + (dt->tm_mday)%10) & 0x3F);
 buf[6] = (buf[6] & ~0x1F) | ((((((dt->tm_mon)/10)<<4) & 0xF0) + (dt->tm_mon)%10) & 0x1F);
 buf[7] = (buf[7] & ~0xFF) | (((((((unsigned char)(dt->tm_year - 100))/10)<<4) & 0xF0) + ((unsigned char)(dt->tm_year - 100))%10) & 0xFF);
  if(write_register(0x00, buf, 8)){
    lielas_log((unsigned char *)"rtc error: failed to set date/time", 0);
    return -1;
  }
  if(oscfailed){
    buf[0] = 0;
    if(read_register(0x0F, buf, 1)){
      lielas_log((unsigned char *)"rtc error: failed to read REG_FLAGS", 0);
      return -1;
    }
    buf[0] &= ~(1<<(2));
    if(write_register(0x0F, buf, 1)){
      lielas_log((unsigned char *)"rtc error: failed to write REG_FLAGS", 0);
      return -1;
    }
  }
  return 0;
}

variable_types:
buf
unsigned char [10]

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


parseAttribute

decompiled_code:
__int64 __fastcall parseAttribute(__int64 a1, const char *a2, char *a3, int a4, __int64 a5)
{
unsigned int v5; // er13
__int64 v6; // rbx
__int64 v7; // r12
size_t v11; // rax
__int64 v12; // rsi
int v13; // edx
char s[5064]; // [rsp+10h] [rbp-13C8h] BYREF

v5 = 0;
v6 = 16LL * a4;
v7 = a5 + v6;
if ( *(_DWORD *)(a5 + v6) == 3 )
{
v11 = strlen(a2);
if ( !strncmp((const char *)(a1 + *(int *)(v7 + 4)), a2, v11) )
{
v12 = *(int *)(a5 + v6 + 20);
v13 = *(_DWORD *)(a5 + v6 + 24) - v12;
if ( v13 > 255 )
{
v5 = -1;
snprintf(s, 0x1388uLL, "attribute %s too big", a2);
lielas_log(s, 1LL);
}
else
{
v5 = 1;
strncpy(a3, (const char *)(a1 + v12), v13);
}
}
}
return v5;
}

original_code:
int parseAttribute(char *file, char *attr, char *val, int nt, jsmntok_t *tok){
  int attrLen;
  char log[5000];
  if( tok[nt].type == JSMN_STRING){
    if(!strncmp(&file[tok[nt].start], attr, strlen(attr))){
      nt += 1;
      attrLen = tok[nt].end - tok[nt].start;
      if(attrLen < 256){
        strncpy(val, &file[tok[nt].start], attrLen);
        printSetting(attr, val);
        return 1;
      }else{
        snprintf(log, 5000, "attribute %s too big", attr);
        lielas_log((unsigned char*)log, 1);
        return -1;
      }
    }
  }
  return 0;
}

canonical_original_code:
int parseAttribute(char *file, char *attr, char *val, int nt, struct jsmntok_t *tok){
  int attrLen;
  char log[5000];
  if( tok[nt].type == JSMN_STRING){
    if(!strncmp(&file[tok[nt].start], attr, strlen(attr))){
      nt += 1;
      attrLen = tok[nt].end - tok[nt].start;
      if(attrLen < 256){
        strncpy(val, &file[tok[nt].start], attrLen);
        printSetting(attr, val);
        return 1;
      }else{
        snprintf(log, 5000, "attribute %s too big", attr);
        lielas_log((unsigned char *)log, 1);
        return -1;
      }
    }
  }
  return 0;
}

variable_types:
file
char *

variable_types:
attr
char *

variable_types:
val
char *

variable_types: nt int

variable_types: struct jsmntok_t { enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 } type; int start; int end; int size; } *

variable_types: attrLen int

variable_types:
log
char [5000]


decompiled_code:
char *set_getSqlUser()
{
return sqlUser;
}

canonical_decompiled_code:
char *func2()
{
return sqlUser;
}

original_code:
const char *set_getSqlUser(){
 return sqlUser;
}

return_type: char *


decompiled_code:
char *set_getSqlPass()
{
return sqlPass;
}

canonical_decompiled_code:
char *func3()
{
return sqlPass;
}

original_code:
const char *set_getSqlPass(){
 return sqlPass;
}


decompiled_code:
char *set_getSqlDb()
{
return sqlDb;
}

canonical_decompiled_code:
char *func4()
{
return sqlDb;
}

original_code:
const char *set_getSqlDb(){
 return sqlDb;
}

canonical_original_code:
char *set_getSqlDb(){
 return sqlDb;
}


decompiled_code:
char *set_getSqlHost()
{
return sqlHost;
}

canonical_decompiled_code:
char *func5()
{
return sqlHost;
}

original_code:
const char *set_getSqlHost(){
 return sqlHost;
}


decompiled_code:
char *set_getSqlPort()
{
return sqlPort;
}

canonical_decompiled_code:
char *func6()
{
return sqlPort;
}

original_code:
const char *set_getSqlPort(){
 return sqlPort;
}


decompiled_code:
char *set_getCoapAddr()
{
return coapAddr;
}

canonical_decompiled_code:
char *func7()
{
return coapAddr;
}

original_code:
const char *set_getCoapAddr(){
 return coapAddr;
}


decompiled_code:
char *set_getCoapPort()
{
return coapPort;
}

canonical_decompiled_code:
char *func8()
{
return coapPort;
}

original_code:
const char *set_getCoapPort(){
 return coapPort;
}


decompiled_code:
char *set_getGatewaynodeAddr()
{
return gatewaynodeAddr;
}

canonical_decompiled_code:
char *func9()
{
return gatewaynodeAddr;
}

original_code:
const char *set_getGatewaynodeAddr(){
 return gatewaynodeAddr;
}


decompiled_code:
char *set_getGatewaynodePort()
{
return gatewaynodePort;
}

canonical_decompiled_code:
char *func10()
{
return gatewaynodePort;
}

original_code:
const char *set_getGatewaynodePort(){
 return gatewaynodePort;
}


decompiled_code:
__int64 set_getStdRegModePanid()
{
return (unsigned int)regmodePanid;
}

canonical_decompiled_code:
__int64 func11()
{
return (unsigned int)regmodePanid;
}

original_code:
int set_getStdRegModePanid(){
  return regmodePanid;
}


decompiled_code:
__int64 set_getStdNormalModePanid()
{
return (unsigned int)normalmodePanid;
}

canonical_decompiled_code:
__int64 func12()
{
return (unsigned int)normalmodePanid;
}

original_code:
int set_getStdNormalModePanid(){
  return normalmodePanid;
}


decompiled_code:
__int64 set_getRegModeLen()
{
return (unsigned int)regmodeLen;
}

canonical_decompiled_code:
__int64 func13()
{
return (unsigned int)regmodeLen;
}

original_code:
int set_getRegModeLen(){
  return regmodeLen;
}


decompiled_code:
__int64 set_getMaxRegModeLen()
{
return (unsigned int)regmodeMaxLen;
}

canonical_decompiled_code:
__int64 func14()
{
return (unsigned int)regmodeMaxLen;
}

original_code:
int set_getMaxRegModeLen(){
  return regmodeMaxLen;
}


printSetting

decompiled_code:
void printSetting()
{
;
}

canonical_decompiled_code:
void func15()
{
;
}

original_code:
void printSetting(char *s, char *v){
}

canonical_original_code:
void printSetting(char *s, char *v){
}

variable_types:
s
char *

variable_types:
v
char *


SQLclose

decompiled_code:
void SQLclose(void)
{
if ( con )
{
if ( !(unsigned int)PQstatus() )
PQfinish(con);
}
}

canonical_decompiled_code:
void func0(void)
{
if ( con )
{
if ( !(unsigned int)PQstatus() )
PQfinish(con);
}
}

original_code:
void SQLclose(){
   if(con != ((void *)0) && PQstatus(con) == CONNECTION_OK){
     PQfinish(con);
   }
}


SQLconnect

decompiled_code:
__int64 __fastcall SQLconnect(__int64 a1, __int64 a2)
{
const char *v2; // rbp
size_t v3; // rax
const char *v4; // rbp
size_t v5; // rax
const char *v6; // rbp
size_t v7; // rax
const char *v8; // rbp
size_t v9; // rax
const char *v10; // rbp
size_t v11; // rax
char dest[16]; // [rsp+0h] [rbp-208h] BYREF
char v14[480]; // [rsp+10h] [rbp-1F8h] BYREF
int v15[6]; // [rsp+1F0h] [rbp-18h] BYREF

*(_OWORD *)dest = 0LL;
memset(v14, 0, sizeof(v14));
strcpy(dest, "user=");
v15[0] = 0;
v2 = (const char *)set_getSqlUser(v15, a2);
v3 = strlen(dest);
strcpy(stpcpy(&dest[v3], v2), " password=");
v4 = (const char *)set_getSqlPass();
v5 = strlen(dest);
strcpy(stpcpy(&dest[v5], v4), " dbname=");
v6 = (const char *)set_getSqlDb();
v7 = strlen(dest);
strcpy(stpcpy(&dest[v7], v6), " host=");
v8 = (const char *)set_getSqlHost();
v9 = strlen(dest);
strcpy(stpcpy(&dest[v9], v8), " port=");
v10 = (const char *)set_getSqlPort();
v11 = strlen(dest);
strcpy(&dest[v11], v10);
con = PQconnectdb(dest);
if ( (unsigned int)PQstatus(con) )
{
lielas_log("Couldn't connect do database using:", 0LL);
lielas_log(dest, 0LL);
exit(1);
}
atexit(SQLclose);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
const char *v2; // rbp
size_t v3; // rax
const char *v4; // rbp
size_t v5; // rax
const char *v6; // rbp
size_t v7; // rax
const char *v8; // rbp
size_t v9; // rax
const char *v10; // rbp
size_t v11; // rax
char dest[16]; // [rsp+0h] [rbp-208h] BYREF
char v14[480]; // [rsp+10h] [rbp-1F8h] BYREF
int v15[6]; // [rsp+1F0h] [rbp-18h] BYREF

*(_OWORD *)dest = 0LL;
memset(v14, 0, sizeof(v14));
strcpy(dest, "user=");
v15[0] = 0;
v2 = (const char *)set_getSqlUser(v15, a2);
v3 = strlen(dest);
strcpy(stpcpy(&dest[v3], v2), " password=");
v4 = (const char *)set_getSqlPass();
v5 = strlen(dest);
strcpy(stpcpy(&dest[v5], v4), " dbname=");
v6 = (const char *)set_getSqlDb();
v7 = strlen(dest);
strcpy(stpcpy(&dest[v7], v6), " host=");
v8 = (const char *)set_getSqlHost();
v9 = strlen(dest);
strcpy(stpcpy(&dest[v9], v8), " port=");
v10 = (const char *)set_getSqlPort();
v11 = strlen(dest);
strcpy(&dest[v11], v10);
con = PQconnectdb(dest);
if ( (unsigned int)PQstatus(con) )
{
lielas_log("Couldn't connect do database using:", 0LL);
lielas_log(dest, 0LL);
exit(1);
}
atexit(SQLclose);
return 0LL;
}

original_code:
int SQLconnect(){
 char conSt[500] = { 0 };
 strcpy(conSt, "user=");
 strcpy(&conSt[strlen(conSt)], set_getSqlUser());
 strcpy(&conSt[strlen(conSt)], " password=");
 strcpy(&conSt[strlen(conSt)], set_getSqlPass());
 strcpy(&conSt[strlen(conSt)], " dbname=");
 strcpy(&conSt[strlen(conSt)], set_getSqlDb());
 strcpy(&conSt[strlen(conSt)], " host=");
 strcpy(&conSt[strlen(conSt)], set_getSqlHost());
 strcpy(&conSt[strlen(conSt)], " port=");
 strcpy(&conSt[strlen(conSt)], set_getSqlPort());
 con = PQconnectdb(conSt);
  if(PQstatus(con) != CONNECTION_OK){
  lielas_log((unsigned char*)"Couldn't connect do database using:", 0);
  lielas_log((unsigned char*)conSt, 0);
     exit(1);
  }
 atexit(SQLclose);
 return 0;
}

canonical_original_code:
int SQLconnect(){
 char conSt[500] = { 0 };
 strcpy(conSt, "user=");
 strcpy(&conSt[strlen(conSt)], set_getSqlUser());
 strcpy(&conSt[strlen(conSt)], " password=");
 strcpy(&conSt[strlen(conSt)], set_getSqlPass());
 strcpy(&conSt[strlen(conSt)], " dbname=");
 strcpy(&conSt[strlen(conSt)], set_getSqlDb());
 strcpy(&conSt[strlen(conSt)], " host=");
 strcpy(&conSt[strlen(conSt)], set_getSqlHost());
 strcpy(&conSt[strlen(conSt)], " port=");
 strcpy(&conSt[strlen(conSt)], set_getSqlPort());
 con = PQconnectdb(conSt);
  if(PQstatus(con) != CONNECTION_OK){
  lielas_log((unsigned char *)"Couldn't connect do database using:", 0);
  lielas_log((unsigned char *)conSt, 0);
     exit(1);
  }
 atexit(SQLclose);
 return 0;
}

variable_types:
conSt
char [500]


InitDeviceEvents

decompiled_code:
void InitDeviceEvents()
{
eventlist = 0LL;
}

canonical_decompiled_code:
void func0()
{
eventlist = 0LL;
}

original_code:
void InitDeviceEvents(){
 eventlist = ((void *)0);
}


LremoveEvent

decompiled_code:
void __fastcall LremoveEvent(void *ptr)
{
__int64 v1; // rdx
__int64 v2; // rax

v1 = *((_QWORD *)ptr + 3);
v2 = *((_QWORD *)ptr + 2);
*(_QWORD *)(v1 + 16) = v2;
*(_QWORD *)(v2 + 24) = v1;
free(ptr);
}

original_code:
void LremoveEvent(Levent* event){
 event->lastDeviceEvent->nextDeviceEvent = event->nextDeviceEvent;
 event->nextDeviceEvent->lastDeviceEvent = event->lastDeviceEvent;
 free(event);
}

canonical_original_code:
void LremoveEvent(struct deviceevent_struct *event){
 event->lastDeviceEvent->nextDeviceEvent = event->nextDeviceEvent;
 event->nextDeviceEvent->lastDeviceEvent = event->lastDeviceEvent;
 free(event);
}

variable_types: struct deviceevent_struct { struct Ldevice_struct { unsigned int id; int registered; char address[50]; char mac[50]; char mint[50]; char pint[50]; char aint[50]; char name[64]; char sw_ver[64]; char supply[64]; int moduls; struct Lmodul_struct { unsigned int id; char address[50]; int channels; char mint[50]; char pint[50]; char aint[50]; struct Lchannel_struct { unsigned int id; char address[50]; char type[50]; char sensor[50]; char unit[50]; char class[50]; double exponent; } *channel[20]; } *modul[20]; 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; } lastProcessed; int hasLogger; int event; struct lwp_wkc_struct { struct lwp_resource_struct { char name[100]; int attributes; struct lwp_attr_struct { char name[100]; } attr[10]; } info; struct lwp_resource_struct device; struct lwp_resource_struct modul; struct lwp_resource_struct network; struct lwp_resource_struct database; struct lwp_resource_struct logger; struct lwp_resource_struct channel[20]; int channels; } wkc; } *d; int type; struct deviceevent_struct *nextDeviceEvent; struct deviceevent_struct *lastDeviceEvent; } *

user_defined_types: struct deviceevent_struct { struct Ldevice_struct *d; int type; struct deviceevent_struct *nextDeviceEvent; struct deviceevent_struct *lastDeviceEvent; }


decompiled_code:
__int64 lielas_createTables()
{
int v0; // ebx
int v1; // ebx
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx
int v6; // ebx
int v7; // ebx
int v8; // ebx

v0 = -(int)lielas_createLbusTbl();
v1 = v0 - lielas_createUsersTbl();
v2 = v1 - lielas_createDeviceGroupsTbl();
v3 = v2 - lielas_createUserGroupsTbl();
v4 = v3 - lielas_createDevicesTbl();
v5 = v4 - lielas_createModulsTbl();
v6 = v5 - lielas_createChannelsTbl();
v7 = v6 - lielas_createDataTbl();
v8 = v7 - lielas_createSettingsTbl();
return v8 - (unsigned int)lielas_createEventsTbl();
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // ebx
int v1; // ebx
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx
int v6; // ebx
int v7; // ebx
int v8; // ebx

v0 = -(int)func1();
v1 = v0 - func2();
v2 = v1 - func3();
v3 = v2 - func4();
v4 = v3 - func5();
v5 = v4 - func6();
v6 = v5 - func7();
v7 = v6 - func8();
v8 = v7 - func9();
return v8 - (unsigned int)func10();
}

original_code:
int lielas_createTables(){
  int error = 0;
  error -= lielas_createLbusTbl();
  error -= lielas_createUsersTbl();
  error -= lielas_createDeviceGroupsTbl();
  error -= lielas_createUserGroupsTbl();
  error -= lielas_createDevicesTbl();
  error -= lielas_createModulsTbl();
  error -= lielas_createChannelsTbl();
  error -= lielas_createDataTbl();
  error -= lielas_createSettingsTbl();
  error -= lielas_createEventsTbl();
  return error;
}

variable_types: error int


decompiled_code:
__int64 __fastcall set_cloexec_or_close(int fd)
{
unsigned int v1; // er12
int v2; // eax

v1 = fd;
if ( fd != -1 )
{
v2 = fcntl(fd, 1);
if ( v2 == -1 || fcntl(fd, 2, v2 | 1) == -1 )
{
v1 = -1;
close(fd);
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
unsigned int v1; // er12
int v2; // eax

v1 = fd;
if ( fd != -1 )
{
v2 = fcntl(fd, 1);
if ( v2 == -1 || fcntl(fd, 2, v2 | 1) == -1 )
{
v1 = -1;
close(fd);
}
}
return v1;
}

original_code:
static int
set_cloexec_or_close(int fd)
{
 long flags;
 if (fd == -1)
  return -1;
 flags = fcntl(fd, 1);
 if (flags == -1)
  goto err;
 if (fcntl(fd, 2, flags | 1) == -1)
  goto err;
 return fd;
err:
 close(fd);
 return -1;
}

variable_types: fd int

variable_types: flags long


decompiled_code:
__int64 __fastcall create_tmpfile_cloexec(char *name)
{
int v1; // eax
unsigned int v2; // er12

v1 = mkstemp(name);
v2 = v1;
if ( v1 >= 0 )
{
v2 = set_cloexec_or_close(v1);
unlink(name);
}
return v2;
}

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

v1 = mkstemp(name);
v2 = v1;
if ( v1 >= 0 )
{
v2 = func0(v1);
unlink(name);
}
return v2;
}

original_code:
static int
create_tmpfile_cloexec(char *tmpname)
{
 int fd;
 fd = mkstemp(tmpname);
 if (fd >= 0) {
  fd = set_cloexec_or_close(fd);
  unlink(tmpname);
 }
 return fd;
}

variable_types:
tmpname
char *


decompiled_code:
__int64 __fastcall os_socketpair_cloexec(int domain, int type, int protocol, int fds[2])
{
int v6; // eax
unsigned int v7; // er12
int v9; // eax
int v10; // edi
int v11; // eax
int v12; // edi

v6 = socketpair(domain, type | 0x80000, protocol, fds);
if ( !v6 )
return 0LL;
v7 = v6;
if ( *_errno_location() != 22 )
return v7;
v7 = socketpair(domain, type, protocol, fds);
if ( (v7 & 0x80000000) != 0 )
return v7;
v9 = set_cloexec_or_close(*fds);
v10 = fds[1];
*fds = v9;
v11 = set_cloexec_or_close(v10);
v12 = *fds;
fds[1] = v11;
if ( v11 == -1 || v12 == -1 )
{
close(v12);
v7 = -1;
close(fds[1]);
return v7;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int domain, int type, int protocol, int fds[2])
{
int v6; // eax
unsigned int v7; // er12
int v9; // eax
int v10; // edi
int v11; // eax
int v12; // edi

v6 = socketpair(domain, type | 0x80000, protocol, fds);
if ( !v6 )
return 0LL;
v7 = v6;
if ( *_errno_location() != 22 )
return v7;
v7 = socketpair(domain, type, protocol, fds);
if ( (v7 & 0x80000000) != 0 )
return v7;
v9 = func0(*fds);
v10 = fds[1];
*fds = v9;
v11 = func0(v10);
v12 = *fds;
fds[1] = v11;
if ( v11 == -1 || v12 == -1 )
{
close(v12);
v7 = -1;
close(fds[1]);
return v7;
}
return 0LL;
}

original_code:
int
os_socketpair_cloexec(int domain, int type, int protocol, int *sv)
{
 int ret;
 ret = socketpair(domain, type | SOCK_CLOEXEC, protocol, sv);
 if (ret == 0 || (*__errno_location ()) != 22)
  return ret;
 ret = socketpair(domain, type, protocol, sv);
 if (ret < 0)
  return ret;
 sv[0] = set_cloexec_or_close(sv[0]);
 sv[1] = set_cloexec_or_close(sv[1]);
 if (sv[0] != -1 && sv[1] != -1)
  return 0;
 close(sv[0]);
 close(sv[1]);
 return -1;
}

variable_types: domain int

variable_types: type int

variable_types: protocol int

variable_types:
sv
int *

variable_types: ret int


decompiled_code:
int os_epoll_create_cloexec()
{
int result; // eax
int v1; // eax

result = epoll_create1(0x80000);
if ( result < 0 )
{
if ( *_errno_location() == 22 )
{
v1 = epoll_create(1);
result = set_cloexec_or_close(v1);
}
else
{
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax
int v1; // eax

result = epoll_create1(0x80000);
if ( result < 0 )
{
if ( *_errno_location() == 22 )
{
v1 = epoll_create(1);
result = func0(v1);
}
else
{
result = -1;
}
}
return result;
}

original_code:
int
os_epoll_create_cloexec(void)
{
 int fd;
 fd = epoll_create1(EPOLL_CLOEXEC);
 if (fd >= 0)
  return fd;
 if ((*__errno_location ()) != 22)
  return -1;
 fd = epoll_create(1);
 return set_cloexec_or_close(fd);
}

canonical_original_code:
int os_epoll_create_cloexec()
{
 int fd;
 fd = epoll_create1(EPOLL_CLOEXEC);
 if (fd >= 0)
  return fd;
 if ((*__errno_location ()) != 22)
  return -1;
 fd = epoll_create(1);
 return set_cloexec_or_close(fd);
}


decompiled_code:
__int64 __fastcall os_create_anonymous_file(__off_t length)
{
char *v1; // rax
char *v2; // r12
size_t v3; // rbx
char *v4; // rax
char *v5; // rbp
int v6; // er12

v1 = getenv("XDG_RUNTIME_DIR");
if ( !v1 )
{
v6 = -1;
*_errno_location() = 2;
return (unsigned int)v6;
}
v2 = v1;
v3 = strlen(v1);
v4 = (char *)malloc(v3 + 22);
v5 = v4;
if ( !v4 )
goto LABEL_7;
memcpy(v4, v2, v3 + 1);
strcpy(&v5[v3 + 16], "XXXXX");
*(__m128i *)&v5[v3] = _mm_load_si128((const __m128i *)&template_0);
v6 = create_tmpfile_cloexec(v5);
free(v5);
if ( v6 < 0 )
goto LABEL_7;
if ( ftruncate(v6, length) < 0 )
{
close(v6);
LABEL_7:
v6 = -1;
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__off_t length)
{
char *v1; // rax
char *v2; // r12
size_t v3; // rbx
char *v4; // rax
char *v5; // rbp
int v6; // er12

v1 = getenv("XDG_RUNTIME_DIR");
if ( !v1 )
{
v6 = -1;
*_errno_location() = 2;
return (unsigned int)v6;
}
v2 = v1;
v3 = strlen(v1);
v4 = (char *)malloc(v3 + 22);
v5 = v4;
if ( !v4 )
goto LABEL_7;
memcpy(v4, v2, v3 + 1);
strcpy(&v5[v3 + 16], "XXXXX");
*(__m128i *)&v5[v3] = _mm_load_si128((const __m128i *)&template_0);
v6 = func1(v5);
free(v5);
if ( v6 < 0 )
goto LABEL_7;
if ( ftruncate(v6, length) < 0 )
{
close(v6);
LABEL_7:
v6 = -1;
}
return (unsigned int)v6;
}

original_code:
int
os_create_anonymous_file(off_t size)
{
 static const char template[] = "/weston-shared-XXXXXX";
 const char *path;
 char *name;
 int fd;
 path = getenv("XDG_RUNTIME_DIR");
 if (!path) {
  (*__errno_location ()) = 2;
  return -1;
 }
 name = malloc(strlen(path) + sizeof(template));
 if (!name)
  return -1;
 strcpy(name, path);
 strcat(name, template);
 fd = create_tmpfile_cloexec(name);
 free(name);
 if (fd < 0)
  return -1;
 if (ftruncate(fd, size) < 0) {
  close(fd);
  return -1;
 }
 return fd;
}

canonical_original_code:
int os_create_anonymous_file(long size)
{
 static char template[] = "/weston-shared-XXXXXX";
 char *path;
 char *name;
 int fd;
 path = getenv("XDG_RUNTIME_DIR");
 if (!path) {
  (*__errno_location ()) = 2;
  return -1;
 }
 name = malloc(strlen(path) + sizeof(template));
 if (!name)
  return -1;
 strcpy(name, path);
 strcat(name, template);
 fd = create_tmpfile_cloexec(name);
 free(name);
 if (fd < 0)
  return -1;
 if (ftruncate(fd, size) < 0) {
  close(fd);
  return -1;
 }
 return fd;
}

variable_types: size long

variable_types:
template
char []

variable_types:
path
char *

variable_types:
name
char *


child

repo: antonblanchard/will-it-scale

decompiled_code:
void __fastcall __noreturn child(int *a1)
{
int *v1; // rbp
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = _errno_location();
while ( 1 )
{
while ( (unsigned int)read(*a1, buf, 1uLL) != 1 )
{
if ( *v1 != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x1Cu, "child");
}
while ( (unsigned int)write(a1[3], buf, 1uLL) != 1 )
{
if ( *v1 != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x21u, "child");
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int *a1)
{
int *v1; // rbp
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = _errno_location();
while ( 1 )
{
while ( (unsigned int)read(*a1, buf, 1uLL) != 1 )
{
if ( *v1 != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x1Cu, "child");
}
while ( (unsigned int)write(a1[3], buf, 1uLL) != 1 )
{
if ( *v1 != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x21u, "child");
}
}
}

original_code:
static void *child(void *arg)
{
 struct args *a = arg;
 char c;
 int ret;
 while (1) {
  do {
   ret = read(a->fd1[0], &c, 1);
  } while (ret != 1 && (*__errno_location ()) == 4);
  ((void) sizeof ((ret == 1) ? 1 : 0), __extension__ ({ if (ret == 1) ; else __assert_fail ("ret == 1", "tests/context_switch1.c", 28, __extension__ __PRETTY_FUNCTION__); }));
  do {
   ret = write(a->fd2[1], &c, 1);
  } while (ret != 1 && (*__errno_location ()) == 4);
  ((void) sizeof ((ret == 1) ? 1 : 0), __extension__ ({ if (ret == 1) ; else __assert_fail ("ret == 1", "tests/context_switch1.c", 33, __extension__ __PRETTY_FUNCTION__); }));
 }
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct args { int fd1[2]; int fd2[2]; } *

variable_types: c char

return_type: void *


testcase

decompiled_code:
void __fastcall __noreturn testcase(_QWORD *a1)
{
int *v1; // rbx
int *v2; // rbp
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = (int *)malloc(0x10uLL);
if ( pipe(v1) )
_assert_fail("pipe(a->fd1) == 0", "tests/context_switch1.c", 0x2Du, "testcase");
if ( !pipe(v1 + 2) )
{
new_task(child, v1);
v2 = _errno_location();
while ( 1 )
{
while ( (unsigned int)write(v1[1], buf, 1uLL) != 1 )
{
if ( *v2 != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x36u, "testcase");
}
while ( (unsigned int)read(v1[2], buf, 1uLL) != 1 )
{
if ( *v2 != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x3Bu, "testcase");
}
*a1 += 2LL;
}
}
_assert_fail("pipe(a->fd2) == 0", "tests/context_switch1.c", 0x2Eu, "testcase");
}

canonical_decompiled_code:
void __fastcall __noreturn func1(_QWORD *a1)
{
int *v1; // rbx
int *v2; // rbp
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = (int *)malloc(0x10uLL);
if ( pipe(v1) )
_assert_fail("pipe(a->fd1) == 0", "tests/context_switch1.c", 0x2Du, "testcase");
if ( !pipe(v1 + 2) )
{
new_task(child, v1);
v2 = _errno_location();
while ( 1 )
{
while ( (unsigned int)write(v1[1], buf, 1uLL) != 1 )
{
if ( *v2 != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x36u, "testcase");
}
while ( (unsigned int)read(v1[2], buf, 1uLL) != 1 )
{
if ( *v2 != 4 )
_assert_fail("ret == 1", "tests/context_switch1.c", 0x3Bu, "testcase");
}
*a1 += 2LL;
}
}
_assert_fail("pipe(a->fd2) == 0", "tests/context_switch1.c", 0x2Eu, "testcase");
}

original_code:
void testcase(unsigned long long *iterations, unsigned long nr)
{
 struct args *a;
 char c;
 int ret;
 a = malloc(sizeof(struct args));
 ((void) sizeof ((pipe(a->fd1) == 0) ? 1 : 0), __extension__ ({ if (pipe(a->fd1) == 0) ; else __assert_fail ("pipe(a->fd1) == 0", "tests/context_switch1.c", 45, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((pipe(a->fd2) == 0) ? 1 : 0), __extension__ ({ if (pipe(a->fd2) == 0) ; else __assert_fail ("pipe(a->fd2) == 0", "tests/context_switch1.c", 46, __extension__ __PRETTY_FUNCTION__); }));
 new_task(child, a);
 while (1) {
  do {
   ret = write(a->fd1[1], &c, 1);
  } while (ret != 1 && (*__errno_location ()) == 4);
  ((void) sizeof ((ret == 1) ? 1 : 0), __extension__ ({ if (ret == 1) ; else __assert_fail ("ret == 1", "tests/context_switch1.c", 54, __extension__ __PRETTY_FUNCTION__); }));
  do {
   ret = read(a->fd2[0], &c, 1);
  } while (ret != 1 && (*__errno_location ()) == 4);
  ((void) sizeof ((ret == 1) ? 1 : 0), __extension__ ({ if (ret == 1) ; else __assert_fail ("ret == 1", "tests/context_switch1.c", 59, __extension__ __PRETTY_FUNCTION__); }));
  (*iterations) += 2;
 }
 free(a);
}

variable_types:
iterations
unsigned long long *

variable_types:
nr
unsigned long


handler

decompiled_code:
void handler()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void handler(int junk)
{
}

canonical_original_code:
void handler(int junk)
{
}

variable_types: junk int


testcase

decompiled_code:
void __fastcall __noreturn testcase(_QWORD *a1)
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)handler;
memset(&v1.sa_mask, 0, 0x90uLL);
sigaction(10, &v1, 0LL);
while ( 1 )
{
raise(10);
++*a1;
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(_QWORD *a1)
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)handler;
memset(&v1.sa_mask, 0, 0x90uLL);
sigaction(10, &v1, 0LL);
while ( 1 )
{
raise(10);
++*a1;
}
}

original_code:
void testcase(unsigned long long *iterations, unsigned long nr)
{
 struct sigaction act;
 memset(&act, 0, sizeof(act));
 act.__sigaction_handler.sa_handler = handler;
 sigaction(10, &act, ((void *)0));
 while (1) {
  raise(10);
  (*iterations)++;
 }
}

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: antoniofabio/idmclib

decompiled_code:
_BOOL8 __fastcall check_points(__int64 a1, __int64 a2, int a3, double a4)
{
__int64 v5; // rax
double v6; // xmm1_8
double v7; // xmm0_8

if ( a3 <= 0 )
return a4 > 0.0;
v5 = 0LL;
v6 = 0.0;
do
{
v7 = *(double *)(a1 + 8 * v5) - *(double *)(a2 + 8 * v5);
++v5;
v6 = v6 + v7 * v7;
}
while ( a3 != v5 );
return a4 > v6;
}

original_code:
static int check_points(double *a, double *b, int dim, double eps) {
 int i;
 double dst = 0.0;
 for(i=0; i<dim; i++)
  dst += (a[i] - b[i])*(a[i] - b[i]);
 return ( dst < eps );
}

variable_types:
a
double *

variable_types:
b
double *

variable_types: dim int

variable_types: eps double

variable_types: i int

variable_types: dst double


decompiled_code:
void __fastcall idmc_attractor_point_free(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[1];
free(*v2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[1];
free(*v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void idmc_attractor_point_free(idmc_attractor_point* p) {
 idmc_attractor_point *n;
 while(p) {
  n = p->next;
  free(p->x);
  free(p);
  p = n;
 }
}

canonical_original_code:
void idmc_attractor_point_free(struct attractor_pt *p) {
 struct attractor_pt *n;
 while(p) {
  n = p->next;
  free(p->x);
  free(p);
  p = n;
 }
}

variable_types: struct attractor_pt { double *x; struct attractor_pt *next; } *


decompiled_code:
__int64 __fastcall idmc_attractor_point_add(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
return a2;
}

original_code:
idmc_attractor_point* idmc_attractor_point_add(idmc_attractor_point* last,
 idmc_attractor_point* p) {
 last->next = p;
 return p;
}

canonical_original_code:
struct attractor_pt *idmc_attractor_point_add(struct attractor_pt *last, struct attractor_pt *p) {
 last->next = p;
 return p;
}

variable_types:
last
struct attractor_pt *

variable_types:
p
struct attractor_pt *

return_type: struct attractor_pt { double *x; struct attractor_pt *next; } *


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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
idmc_attractor_point* idmc_attractor_point_last(idmc_attractor_point* head) {
 while(head->next)
  head = head->next;
 return head;
}

canonical_original_code:
struct attractor_pt *idmc_attractor_point_last(struct attractor_pt *head) {
 while(head->next)
  head = head->next;
 return head;
}

variable_types:
head
struct attractor_pt *

user_defined_types: struct attractor_pt { double *x; struct attractor_pt *next; }


decompiled_code:
void __fastcall idmc_attractor_free(void *ptr)
{
idmc_attractor_point_free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
func1(*(void **)ptr);
free(ptr);
}

original_code:
void idmc_attractor_free(idmc_attractor* p) {
 idmc_attractor_point_free(p->hd);
 free(p);
}

canonical_original_code:
void idmc_attractor_free(struct attr_lst *p) {
 idmc_attractor_point_free(p->hd);
 free(p);
}

variable_types: struct attr_lst { struct attractor_pt { double *x; struct attractor_pt *next; } *hd; int dim; struct attr_lst *next; struct attr_lst *previous; } *

user_defined_types: struct attr_lst { struct attractor_pt *hd; int dim; struct attr_lst *next; struct attr_lst *previous; }


decompiled_code:
__int64 __fastcall idmc_attractor_length(__int64 *a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 8);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 8);
return i;
}

original_code:
int idmc_attractor_length(idmc_attractor* p) {
 int i=0;
 idmc_attractor_point* hd = p->hd;
 while(hd) {
  i++;
  hd = hd->next;
 }
 return i;
}

canonical_original_code:
int idmc_attractor_length(struct attr_lst *p) {
 int i = 0;
 struct attractor_pt *hd = p->hd;
 while(hd) {
  i++;
  hd = hd->next;
 }
 return i;
}


decompiled_code:
_BOOL8 __fastcall idmc_attractor_check_point(__int64 a1, __int64 a2, double a3)
{
__int64 *v3; // rcx
int v4; // er8
_BOOL8 result; // rax
__int64 v6; // rcx

v3 = *(__int64 **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
v4 = *(_DWORD *)(a1 + 8);
while ( 1 )
{
result = check_points(*v3, a2, v4, a3);
if ( result )
break;
v3 = *(__int64 **)(v6 + 8);
if ( !v3 )
return result;
}
return 1LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, __int64 a2, double a3)
{
__int64 *v3; // rcx
int v4; // er8
_BOOL8 result; // rax
__int64 v6; // rcx

v3 = *(__int64 **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
v4 = *(_DWORD *)(a1 + 8);
while ( 1 )
{
result = func0(*v3, a2, v4, a3);
if ( result )
break;
v3 = *(__int64 **)(v6 + 8);
if ( !v3 )
return result;
}
return 1LL;
}

original_code:
int idmc_attractor_check_point(idmc_attractor* p, double* x, double eps) {
 idmc_attractor_point *ap = p->hd;
 while(ap) {
  if(check_points(ap->x, x, p->dim, eps))
   return 1;
  ap = ap->next;
 }
 return 0;
}

canonical_original_code:
int idmc_attractor_check_point(struct attr_lst *p, double *x, double eps) {
 struct attractor_pt *ap = p->hd;
 while(ap) {
  if(check_points(ap->x, x, p->dim, eps))
   return 1;
  ap = ap->next;
 }
 return 0;
}

variable_types:
x
double *


decompiled_code:
__int64 __fastcall idmc_attractor_list_free(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rdi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rdi
__int64 result; // rax

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

original_code:
void idmc_attractor_list_free(idmc_attractor* head) {
 idmc_attractor *n;
 while(head) {
  n = head->next;
  idmc_attractor_free(head);
  head = n;
 }
}

canonical_original_code:
void idmc_attractor_list_free(struct attr_lst *head) {
 struct attr_lst *n;
 while(head) {
  n = head->next;
  idmc_attractor_free(head);
  head = n;
 }
}


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

*(_QWORD *)(a2 + 24) = a1;
result = a2;
*(_QWORD *)(a1 + 16) = a2;
return result;
}

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

*(_QWORD *)(a2 + 24) = a1;
result = a2;
*(_QWORD *)(a1 + 16) = a2;
return result;
}

original_code:
idmc_attractor* idmc_attractor_list_add(idmc_attractor* last, idmc_attractor* i) {
 i->previous = last;
 last->next = i;
 return i;
}

canonical_original_code:
struct attr_lst *idmc_attractor_list_add(struct attr_lst *last, struct attr_lst *i) {
 i->previous = last;
 last->next = i;
 return i;
}

variable_types:
last
struct attr_lst *

variable_types:
i
struct attr_lst *

return_type: struct attr_lst { struct attractor_pt { double *x; struct attractor_pt *next; } *hd; int dim; struct attr_lst *next; struct attr_lst *previous; } *


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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 16);
return result;
}

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 16);
return result;
}

original_code:
int idmc_attractor_list_length(idmc_attractor* head) {
 int i=0;
 while(head) {
  i++;
  head = head->next;
 }
 return i;
}

canonical_original_code:
int idmc_attractor_list_length(struct attr_lst *head) {
 int i = 0;
 while(head) {
  i++;
  head = head->next;
 }
 return i;
}


decompiled_code:
__int64 __fastcall idmc_attractor_list_get(__int64 a1, int a2)
{
int i; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
a1 = *(_QWORD *)(a1 + 16);
}
return a1;
}

original_code:
idmc_attractor* idmc_attractor_list_get(idmc_attractor* head, int id) {
 int i;
 idmc_attractor* ans = head;
 for(i=0; i<id; i++)
  ans = ans->next;
 return ans;
}

canonical_original_code:
struct attr_lst *idmc_attractor_list_get(struct attr_lst *head, int id) {
 int i;
 struct attr_lst *ans = head;
 for(i=0; i<id; i++)
  ans = ans->next;
 return ans;
}

variable_types:
head
struct attr_lst *

variable_types: id int


decompiled_code:
__int64 __fastcall idmc_attractor_list_check_point(__int64 a1, __int64 a2, double a3)
{
__int64 v3; // rbx
int v4; // er14
unsigned int v5; // er12
int v7; // ebp
__int64 v8; // rax

v3 = a1;
srand(0);
v4 = idmc_attractor_list_length(a1);
if ( v4 > 99 )
{
v7 = 100;
while ( 1 )
{
v5 = v4 * (int)((double)rand() * 4.656612873077393e-10);
v8 = idmc_attractor_list_get(a1, v5);
if ( (unsigned int)idmc_attractor_check_point(v8, a2, a3) )
break;
if ( !--v7 )
goto LABEL_11;
}
}
else if ( a1 )
{
v5 = 0;
while ( !(unsigned int)idmc_attractor_check_point(v3, a2, a3) )
{
v3 = *(_QWORD *)(v3 + 16);
++v5;
if ( !v3 )
goto LABEL_11;
}
}
else
{
LABEL_11:
v5 = v4;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, double a3)
{
__int64 v3; // rbx
int v4; // er14
unsigned int v5; // er12
int v7; // ebp
__int64 v8; // rax

v3 = a1;
srand(0);
v4 = func2(a1);
if ( v4 > 99 )
{
v7 = 100;
while ( 1 )
{
v5 = v4 * (int)((double)rand() * 4.656612873077393e-10);
v8 = func3(a1, v5);
if ( (unsigned int)idmc_attractor_check_point(v8, a2, a3) )
break;
if ( !--v7 )
goto LABEL_11;
}
}
else if ( a1 )
{
v5 = 0;
while ( !(unsigned int)idmc_attractor_check_point(v3, a2, a3) )
{
v3 = *(_QWORD *)(v3 + 16);
++v5;
if ( !v3 )
goto LABEL_11;
}
}
else
{
LABEL_11:
v5 = v4;
}
return v5;
}

original_code:
int idmc_attractor_list_check_point(idmc_attractor* head, double* x, double eps) {
 int i;
 srand(0);
 int N = idmc_attractor_list_length(head);
 if(N < 100) {
  int i=0;
  while(head) {
   if( idmc_attractor_check_point(head, x, eps) )
    return i;
   head = head->next;
   i++;
  }
  } else {
  for(int j = 100; j; j--) {
   i = (int) ( (double)rand() / ((double)(2147483647)+(double)(1)) ) * N;
   if( idmc_attractor_check_point( idmc_attractor_list_get(head, i), x, eps ) ) {
    return i;
   }
  }
 }
 return N;
}

canonical_original_code:
int idmc_attractor_list_check_point(struct attr_lst *head, double *x, double eps) {
 int i;
 srand(0);
 int N = idmc_attractor_list_length(head);
 if(N < 100) {
  int i = 0;
  while(head) {
   if( idmc_attractor_check_point(head, x, eps) )
    return i;
   head = head->next;
   i++;
  }
  } else {
  for(int j = 100; j; j--) {
   i = (int) ( (double)rand() / ((double)(2147483647)+(double)(1)) ) * N;
   if( idmc_attractor_check_point( idmc_attractor_list_get(head, i), x, eps ) ) {
    return i;
   }
  }
 }
 return N;
}

variable_types: N int

variable_types: j int


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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

original_code:
idmc_attractor* idmc_attractor_list_last(idmc_attractor* head) {
 while(head->next)
  head = head->next;
 return head;
}

canonical_original_code:
struct attr_lst *idmc_attractor_list_last(struct attr_lst *head) {
 while(head->next)
  head = head->next;
 return head;
}


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

result = idmc_attractor_list_last(a1);
*(_QWORD *)(result + 16) = a2;
*(_QWORD *)(a2 + 24) = result;
return result;
}

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

result = func5(a1);
*(_QWORD *)(result + 16) = a2;
*(_QWORD *)(a2 + 24) = result;
return result;
}

original_code:
void idmc_attractor_list_append(idmc_attractor* head, idmc_attractor* i) {
 idmc_attractor* last = idmc_attractor_list_last(head);
 last->next = i;
 i->previous = last;
}

canonical_original_code:
void idmc_attractor_list_append(struct attr_lst *head, struct attr_lst *i) {
 struct attr_lst *last = idmc_attractor_list_last(head);
 last->next = i;
 i->previous = last;
}


decompiled_code:
__int64 __fastcall idmc_attractor_list_drop(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdx

v1 = *(_QWORD *)(a1 + 24);
if ( v1 )
*(_QWORD *)(v1 + 16) = *(_QWORD *)(a1 + 16);
v2 = *(_QWORD *)(a1 + 16);
if ( v2 )
*(_QWORD *)(v2 + 24) = v1;
return idmc_attractor_free(a1);
}

original_code:
void idmc_attractor_list_drop(idmc_attractor* p) {
 if(p->previous)
  (p->previous)->next = p->next;
 if(p->next)
  (p->next)->previous = p->previous;
 idmc_attractor_free(p);
}

canonical_original_code:
void idmc_attractor_list_drop(struct attr_lst *p) {
 if(p->previous)
  (p->previous)->next = p->next;
 if(p->next)
  (p->next)->previous = p->previous;
 idmc_attractor_free(p);
}


decompiled_code:
__int64 __fastcall idmc_attractor_list_merge(__int64 a1, int a2, int a3)
{
int v3; // er9
_QWORD *v4; // rdx
_QWORD *v5; // rbp
__int64 v6; // r12

if ( a2 > a3 )
a2 = a3;
idmc_attractor_list_get(a1, a2);
v5 = (_QWORD *)idmc_attractor_list_get(a1, v3);
v6 = idmc_attractor_point_last(*v4);
*(_QWORD *)(v6 + 8) = idmc_attractor_point_clone(*v5, *(unsigned int *)(a1 + 8));
return idmc_attractor_list_drop((__int64)v5);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, int a3)
{
int v3; // er9
_QWORD *v4; // rdx
_QWORD *v5; // rbp
__int64 v6; // r12

if ( a2 > a3 )
a2 = a3;
func3(a1, a2);
v5 = (_QWORD *)func3(a1, v3);
v6 = idmc_attractor_point_last(*v4);
*(_QWORD *)(v6 + 8) = idmc_attractor_point_clone(*v5, *(unsigned int *)(a1 + 8));
return func7((__int64)v5);
}

original_code:
void idmc_attractor_list_merge(idmc_attractor* head, int a, int b) {
 int tmp;
 if(a>b) {
  tmp=a;
  a=b;
  b=tmp;
 }
 idmc_attractor* a1 = idmc_attractor_list_get(head, a);
 idmc_attractor* a2 = idmc_attractor_list_get(head, b);
 idmc_attractor_point* tail1 = idmc_attractor_point_last( a1->hd );
 idmc_attractor_point* head2 = a2->hd;
 tail1->next = idmc_attractor_point_clone(head2, head->dim);
 idmc_attractor_list_drop(a2);
}

canonical_original_code:
void idmc_attractor_list_merge(struct attr_lst *head, int a, int b) {
 int tmp;
 if(a>b) {
  tmp=a;
  a=b;
  b=tmp;
 }
 struct attr_lst *a1 = idmc_attractor_list_get(head, a);
 struct attr_lst *a2 = idmc_attractor_list_get(head, b);
 struct attractor_pt *tail1 = idmc_attractor_point_last( a1->hd );
 struct attractor_pt *head2 = a2->hd;
 tail1->next = idmc_attractor_point_clone(head2, head->dim);
 idmc_attractor_list_drop(a2);
}

variable_types: a int

variable_types: b int

variable_types: tmp int


decompiled_code:
void __fastcall idmc_raster_free(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void idmc_raster_free(idmc_raster* p)
{
 if(p->data!=((void *)0))
  free(p->data);
 free(p);
}

canonical_original_code:
void idmc_raster_free(struct idmc_raster *p)
{
 if(p->data!=((void *)0))
  free(p->data);
 free(p);
}

variable_types: struct idmc_raster { void *g_data; int *data; double xmin; double xrange; double xeps; int xres; double ymin; double yrange; double yeps; int yres; } *


decompiled_code:
__int64 __fastcall idmc_raster_alloc(int a1, int a2, _QWORD *a3, double a4, double a5, double a6, double a7)
{
_QWORD *v8; // rax
_QWORD *v9; // rbp
void *v10; // rax
__int64 result; // rax

v8 = malloc(0x50uLL);
if ( !v8 )
return 1LL;
v9 = v8;
v10 = malloc(4LL * a2 * a1);
v9[1] = v10;
if ( v10 )
{
result = 0LL;
*((_DWORD *)v9 + 10) = a1;
*((_DWORD *)v9 + 18) = a2;
*a3 = v9;
*((double *)v9 + 2) = a4;
*((double *)v9 + 3) = a5 - a4;
*((double *)v9 + 7) = a7 - a6;
*((double *)v9 + 6) = a6;
*((double *)v9 + 4) = (a5 - a4) / (double)a1;
*((double *)v9 + 8) = (a7 - a6) / (double)a2;
}
else
{
idmc_raster_free(v9);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, _QWORD *a3, double a4, double a5, double a6, double a7)
{
_QWORD *v8; // rax
_QWORD *v9; // rbp
void *v10; // rax
__int64 result; // rax

v8 = malloc(0x50uLL);
if ( !v8 )
return 1LL;
v9 = v8;
v10 = malloc(4LL * a2 * a1);
v9[1] = v10;
if ( v10 )
{
result = 0LL;
*((_DWORD *)v9 + 10) = a1;
*((_DWORD *)v9 + 18) = a2;
*a3 = v9;
*((double *)v9 + 2) = a4;
*((double *)v9 + 3) = a5 - a4;
*((double *)v9 + 7) = a7 - a6;
*((double *)v9 + 6) = a6;
*((double *)v9 + 4) = (a5 - a4) / (double)a1;
*((double *)v9 + 8) = (a7 - a6) / (double)a2;
}
else
{
func0(v9);
result = 1LL;
}
return result;
}

original_code:
int idmc_raster_alloc(double xmin, double xmax, int xres,
 double ymin, double ymax, int yres,
 idmc_raster** out_raster)
{
 idmc_raster *ans = (idmc_raster*) malloc( sizeof(idmc_raster) );
 if(ans==((void *)0))
  return 1;
 ans->data = (int*) malloc(xres * yres * sizeof(int));
 if(ans->data==((void *)0)) {
  idmc_raster_free(ans);
  return 1;
 }
 ans->xmin = xmin;
 ans->xrange = xmax - xmin;
 ans->xeps = ans->xrange / (double) xres;
 ans->xres = xres;
 ans->ymin = ymin;
 ans->yrange = ymax - ymin;
 ans->yeps = ans->yrange / (double) yres;
 ans->yres = yres;
 *out_raster = ans;
 return 0;
}

canonical_original_code:
int idmc_raster_alloc(double xmin, double xmax, int xres, double ymin, double ymax, int yres, struct idmc_raster **out_raster)
{
 struct idmc_raster *ans = (idmc_raster*) malloc( sizeof(idmc_raster) );
 if(ans==((void *)0))
  return 1;
 ans->data = (int *) malloc(xres * yres * sizeof(int));
 if(ans->data==((void *)0)) {
  idmc_raster_free(ans);
  return 1;
 }
 ans->xmin = xmin;
 ans->xrange = xmax - xmin;
 ans->xeps = ans->xrange / (double) xres;
 ans->xres = xres;
 ans->ymin = ymin;
 ans->yrange = ymax - ymin;
 ans->yeps = ans->yrange / (double) yres;
 ans->yres = yres;
 *out_raster = ans;
 return 0;
}

variable_types: xmin double

variable_types: xmax double

variable_types: xres int

variable_types: ymin double

variable_types: ymax double

variable_types: yres int

variable_types: struct idmc_raster { void *g_data; int *data; double xmin; double xrange; double xeps; int xres; double ymin; double yrange; double yeps; int yres; } **


decompiled_code:
__int64 __fastcall idmc_raster_setxy(__int64 a1, int a2, double a3, double a4)
{
__int64 result; // rax

result = (int)((a3 - *(double *)(a1 + 16)) / *(double *)(a1 + 32))
+ *(_DWORD *)(a1 + 40) * (*(_DWORD *)(a1 + 72) + ~(int)((a4 - *(double *)(a1 + 48)) / *(double *)(a1 + 64)));
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4 * result) = a2;
return result;
}

original_code:
void idmc_raster_setxy(idmc_raster* p, double x, double y, int value)
{
 p->data[ ( ((p)->yres - ((int)( ((y) - (p)->ymin)/(p)->yeps )) - 1) * ((p)->xres) + ((int)( ((x) - (p)->xmin)/(p)->xeps )) ) ] = value;
}

canonical_original_code:
void idmc_raster_setxy(struct idmc_raster *p, double x, double y, int value)
{
 p->data[ ( ((p)->yres - ((int)( ((y) - (p)->ymin)/(p)->yeps )) - 1) * ((p)->xres) + ((int)( ((x) - (p)->xmin)/(p)->xeps )) ) ] = value;
}

variable_types: x double

variable_types: y double

variable_types: value int

user_defined_types: struct idmc_raster { void *g_data; int *data; double xmin; double xrange; double xeps; int xres; double ymin; double yrange; double yeps; int yres; }


original_code:
int idmc_raster_getxy(idmc_raster* p, double x, double y)
{
 return p->data[ ( ((p)->yres - ((int)( ((y) - (p)->ymin)/(p)->yeps )) - 1) * ((p)->xres) + ((int)( ((x) - (p)->xmin)/(p)->xeps )) ) ];
}

canonical_original_code:
int idmc_raster_getxy(struct idmc_raster *p, double x, double y)
{
 return p->data[ ( ((p)->yres - ((int)( ((y) - (p)->ymin)/(p)->yeps )) - 1) * ((p)->xres) + ((int)( ((x) - (p)->xmin)/(p)->xeps )) ) ];
}


decompiled_code:
__int64 __fastcall idmc_raster_setXY(__int64 a1, int a2, int a3, int a4)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8);
*(_DWORD *)(result + 4LL * (a2 + *(_DWORD *)(a1 + 40) * (*(_DWORD *)(a1 + 72) + ~a3))) = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, int a3, int a4)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8);
*(_DWORD *)(result + 4LL * (a2 + *(_DWORD *)(a1 + 40) * (*(_DWORD *)(a1 + 72) + ~a3))) = a4;
return result;
}

original_code:
void idmc_raster_setXY(idmc_raster* p, int x, int y, int value)
{
 p->data[ ( ((p)->yres - (y) - 1) * ((p)->xres) + (x) ) ] = value;
}

canonical_original_code:
void idmc_raster_setXY(struct idmc_raster *p, int x, int y, int value)
{
 p->data[ ( ((p)->yres - (y) - 1) * ((p)->xres) + (x) ) ] = value;
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall idmc_raster_getXY(__int64 a1, int a2, int a3)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * (a2 + *(_DWORD *)(a1 + 40) * (*(_DWORD *)(a1 + 72) + ~a3)));
}

original_code:
int idmc_raster_getXY(idmc_raster* p, int x, int y)
{
 return p->data[ ( ((p)->yres - (y) - 1) * ((p)->xres) + (x) ) ];
}

canonical_original_code:
int idmc_raster_getXY(struct idmc_raster *p, int x, int y)
{
 return p->data[ ( ((p)->yres - (y) - 1) * ((p)->xres) + (x) ) ];
}


decompiled_code:
void *__fastcall idmc_raster_set(__int64 a1, int a2)
{
return memset(*(void **)(a1 + 8), a2, 4LL * *(_DWORD *)(a1 + 72) * *(_DWORD *)(a1 + 40));
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, int a2)
{
return memset(*(void **)(a1 + 8), a2, 4LL * *(_DWORD *)(a1 + 72) * *(_DWORD *)(a1 + 40));
}

original_code:
void idmc_raster_set(idmc_raster* p, int value)
{
 memset(p->data, value, (p->xres * p->yres) * sizeof(int));
}

canonical_original_code:
void idmc_raster_set(struct idmc_raster *p, int value)
{
 memset(p->data, value, (p->xres * p->yres) * sizeof(int));
}


decompiled_code:
_BOOL8 __fastcall idmc_raster_isXYInsideBounds(__int64 a1, int a2, int a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 >= 0 && a3 >= 0 && *(_DWORD *)(a1 + 40) > a2 )
result = *(_DWORD *)(a1 + 72) > a3;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1, int a2, int a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 >= 0 && a3 >= 0 && *(_DWORD *)(a1 + 40) > a2 )
result = *(_DWORD *)(a1 + 72) > a3;
return result;
}

original_code:
int idmc_raster_isXYInsideBounds(idmc_raster *p, int x, int y)
{
 return (x>=0 && y>=0 && x<(p->xres) && y<(p->yres));
}

canonical_original_code:
int idmc_raster_isXYInsideBounds(struct idmc_raster *p, int x, int y)
{
 return (x>=0 && y>=0 && x<(p->xres) && y<(p->yres));
}


decompiled_code:
_BOOL8 __fastcall idmc_raster_isxyInsideBounds(double *a1, double a2, double a3)
{
return idmc_raster_isXYInsideBounds((__int64)a1, (int)((a2 - a1[2]) / a1[4]), (int)((a3 - a1[6]) / a1[8]));
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(double *a1, double a2, double a3)
{
return func7((__int64)a1, (int)((a2 - a1[2]) / a1[4]), (int)((a3 - a1[6]) / a1[8]));
}

original_code:
int idmc_raster_isxyInsideBounds(idmc_raster *p, double x, double y)
{
 return idmc_raster_isXYInsideBounds( p, (int)( ((x) - (p)->xmin)/(p)->xeps ), (int)( ((y) - (p)->ymin)/(p)->yeps ) );
}

canonical_original_code:
int idmc_raster_isxyInsideBounds(struct idmc_raster *p, double x, double y)
{
 return idmc_raster_isXYInsideBounds( p, (int)( ((x) - (p)->xmin)/(p)->xeps ), (int)( ((y) - (p)->ymin)/(p)->yeps ) );
}


decompiled_code:
int __fastcall vector_out(__int64 *a1, double a2)
{
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rbx
__int64 v5; // rax

v2 = *a1;
putchar(40);
if ( (int)v2 > 0 )
{
v3 = (unsigned int)(v2 - 1);
v4 = 0LL;
do
{
gsl_vector_get(a1, v4);
printf("%.5e ", a2);
v5 = v4++;
}
while ( v5 != v3 );
}
return puts(")");
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1, double a2)
{
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rbx
__int64 v5; // rax

v2 = *a1;
putchar(40);
if ( (int)v2 > 0 )
{
v3 = (unsigned int)(v2 - 1);
v4 = 0LL;
do
{
gsl_vector_get(a1, v4);
printf("%.5e ", a2);
v5 = v4++;
}
while ( v5 != v3 );
}
return puts(")");
}

original_code:
void vector_out(gsl_vector* v){
 int i;
 int d=(*v).size;
 printf("(");
 for (i=0;i<d;i++){
  printf("%.5e ",gsl_vector_get(v,i));
 }
 printf(")\n");
}

canonical_original_code:
void vector_out(struct gsl_vector *v){
 int i;
 int d = (*v).size;
 printf("(");
 for (i=0;i<d;i++){
  printf("%.5e ",gsl_vector_get(v,i));
 }
 printf(")\n");
}

variable_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: i int

variable_types: d int

user_defined_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; }


decompiled_code:
__int64 __fastcall matrix_out(__int64 *a1, double a2)
{
__int64 v2; // r13
__int64 result; // rax
int v4; // er14
__int64 v5; // r12
__int64 v6; // rbx
int v7; // er13
__int64 v8; // r15
__int64 v9; // rax
__int64 v10; // [rsp+8h] [rbp-40h]

putchar(91);
v2 = *a1;
result = a1[1];
if ( (int)*a1 > 0 )
{
v4 = a1[1];
v5 = (unsigned int)(result - 1);
v6 = 0LL;
v10 = (unsigned int)(v2 - 1);
v7 = v2 - 1;
while ( 1 )
{
v8 = 0LL;
if ( v4 > 0 )
{
do
{
gsl_matrix_get(a1, v6, v8);
printf("%.5e ", a2);
v9 = v8++;
}
while ( v5 != v9 );
}
if ( v7 <= (int)v6 )
{
puts("]");
result = v6 + 1;
if ( v6 == v10 )
return result;
}
else
{
putchar(10);
result = v6 + 1;
if ( v6 == v10 )
return result;
}
v6 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, double a2)
{
__int64 v2; // r13
__int64 result; // rax
int v4; // er14
__int64 v5; // r12
__int64 v6; // rbx
int v7; // er13
__int64 v8; // r15
__int64 v9; // rax
__int64 v10; // [rsp+8h] [rbp-40h]

putchar(91);
v2 = *a1;
result = a1[1];
if ( (int)*a1 > 0 )
{
v4 = a1[1];
v5 = (unsigned int)(result - 1);
v6 = 0LL;
v10 = (unsigned int)(v2 - 1);
v7 = v2 - 1;
while ( 1 )
{
v8 = 0LL;
if ( v4 > 0 )
{
do
{
gsl_matrix_get(a1, v6, v8);
printf("%.5e ", a2);
v9 = v8++;
}
while ( v5 != v9 );
}
if ( v7 <= (int)v6 )
{
puts("]");
result = v6 + 1;
if ( v6 == v10 )
return result;
}
else
{
putchar(10);
result = v6 + 1;
if ( v6 == v10 )
return result;
}
v6 = result;
}
}
return result;
}

original_code:
void matrix_out(gsl_matrix* m){
 printf("[");
 int i,j;
 int d1=(*m).size1;
 int d2=(*m).size2;
 for (i=0;i<d1;i++){
  for (j=0;j<d2;j++){
   printf("%.5e ",gsl_matrix_get(m,i,j));
  }
  if (i<d1-1)
   printf("\n");
  else
   printf("]\n");
 }
}

canonical_original_code:
void matrix_out(struct gsl_matrix *m){
 printf("[");
 int i; int j;
 int d1 = (*m).size1;
 int d2 = (*m).size2;
 for (i=0;i<d1;i++){
  for (j=0;j<d2;j++){
   printf("%.5e ",gsl_matrix_get(m,i,j));
  }
  if (i<d1-1)
   printf("\n");
  else
   printf("]\n");
 }
}

variable_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: j int

user_defined_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; }