decompiled_code:
__int64 __fastcall e2p_edit_mntopts(char *src, int *a2, int a3)
{
size_t v4; // rax
char *v5; // rax
char *v6; // r15
char *i; // rdi
_BYTE *v8; // rbx
int v9; // er13
char *v10; // rbp
unsigned int v11; // ebp
int v12; // eax
int v13; // eax
_BYTE *v14; // rax
char v15; // al
int v17[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v4 = strlen(src);
v5 = (char *)malloc(v4 + 1);
if ( !v5 )
return 1;
v6 = v5;
strcpy(v5, src);
for ( i = v6; ; i = v8 + 1 )
{
if ( !*i )
{
v11 = 0;
goto LABEL_25;
}
v10 = skip_over_blanks(i);
v14 = skip_over_word(v10);
v8 = v14;
if ( *v14 )
*v14 = 0;
else
v8 = 0LL;
v15 = *v10;
if ( *v10 == 45 )
{
v9 = 1;
LABEL_6:
++v10;
goto LABEL_7;
}
if ( v15 == 94 )
{
v9 = 1;
goto LABEL_6;
}
v9 = 0;
if ( v15 == 43 )
goto LABEL_6;
LABEL_7:
v11 = e2p_string2mntopt(v10, v17);
if ( v11 )
{
v11 = 1;
goto LABEL_25;
}
if ( a3 && (v17[0] & a3) == 0 )
break;
v12 = v17[0];
if ( (v17[0] & 0x60) != 0 )
*a2 &= 0xFFFFFF9F;
if ( v9 )
v13 = *a2 & ~v12;
else
v13 = *a2 | v12;
*a2 = v13;
if ( !v8 )
goto LABEL_25;
}
v11 = 1;
LABEL_25:
free(v6);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, int *a2, int a3)
{
size_t v4; // rax
char *v5; // rax
char *v6; // r15
char *i; // rdi
_BYTE *v8; // rbx
int v9; // er13
char *v10; // rbp
unsigned int v11; // ebp
int v12; // eax
int v13; // eax
_BYTE *v14; // rax
char v15; // al
int v17[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v4 = strlen(src);
v5 = (char *)malloc(v4 + 1);
if ( !v5 )
return 1;
v6 = v5;
strcpy(v5, src);
for ( i = v6; ; i = v8 + 1 )
{
if ( !*i )
{
v11 = 0;
goto LABEL_25;
}
v10 = skip_over_blanks(i);
v14 = skip_over_word(v10);
v8 = v14;
if ( *v14 )
*v14 = 0;
else
v8 = 0LL;
v15 = *v10;
if ( *v10 == 45 )
{
v9 = 1;
LABEL_6:
++v10;
goto LABEL_7;
}
if ( v15 == 94 )
{
v9 = 1;
goto LABEL_6;
}
v9 = 0;
if ( v15 == 43 )
goto LABEL_6;
LABEL_7:
v11 = func1(v10, v17);
if ( v11 )
{
v11 = 1;
goto LABEL_25;
}
if ( a3 && (v17[0] & a3) == 0 )
break;
v12 = v17[0];
if ( (v17[0] & 0x60) != 0 )
*a2 &= 0xFFFFFF9F;
if ( v9 )
v13 = *a2 & ~v12;
else
v13 = *a2 | v12;
*a2 = v13;
if ( !v8 )
goto LABEL_25;
}
v11 = 1;
LABEL_25:
free(v6);
return v11;
}

original_code:
int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok)
{
 char *cp, *buf, *next;
 int neg;
 unsigned int mask;
 int rc = 0;
 buf = malloc(strlen(str)+1);
 if (!buf)
  return 1;
 strcpy(buf, str);
 cp = buf;
 while (cp && *cp) {
  neg = 0;
  cp = skip_over_blanks(cp);
  next = skip_over_word(cp);
  if (*next == 0)
   next = 0;
  else
   *next = 0;
  switch (*cp) {
  case '-':
  case '^':
   neg++;
  case '+':
   cp++;
   break;
  }
  if (e2p_string2mntopt(cp, &mask)) {
   rc = 1;
   break;
  }
  if (ok && !(ok & mask)) {
   rc = 1;
   break;
  }
  if (mask & 0x0060)
   *mntopts &= ~0x0060;
  if (neg)
   *mntopts &= ~mask;
  else
   *mntopts |= mask;
  cp = next ? next+1 : 0;
 }
 free(buf);
 return rc;
}

canonical_original_code:
int e2p_edit_mntopts(char *str, unsigned int *mntopts, unsigned int ok)
{
 char *cp; char *buf; char *next;
 int neg;
 unsigned int mask;
 int rc = 0;
 buf = malloc(strlen(str)+1);
 if (!buf)
  return 1;
 strcpy(buf, str);
 cp = buf;
 while (cp && *cp) {
  neg = 0;
  cp = skip_over_blanks(cp);
  next = skip_over_word(cp);
  if (*next == 0)
   next = 0;
  else
   *next = 0;
  switch (*cp) {
  case '-':
  case '^':
   neg++;
  case '+':
   cp++;
   break;
  }
  if (e2p_string2mntopt(cp, &mask)) {
   rc = 1;
   break;
  }
  if (ok && !(ok & mask)) {
   rc = 1;
   break;
  }
  if (mask & 0x0060)
   *mntopts &= ~0x0060;
  if (neg)
   *mntopts &= ~mask;
  else
   *mntopts |= mask;
  cp = next ? next+1 : 0;
 }
 free(buf);
 return rc;
}

variable_types:
str
char *

variable_types:
mntopts
unsigned int *

variable_types:
ok
unsigned int

variable_types:
cp
char *

variable_types:
buf
char *

variable_types:
next
char *

variable_types: neg int

variable_types: rc int


decompiled_code:
void __fastcall free_error_table(void *ptr)
{
_QWORD *v1; // rbx
void *v2; // rdi

v1 = ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
}
}

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

v1 = ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
}
}

original_code:
void
free_error_table(struct et_list *et)
{
    while(et){
 struct et_list *p = et;
 et = et->next;
 free(p);
    }
}

variable_types: struct et_list { struct et_list *next; struct error_table { char **msgs; long base; int n_msgs; } *table; } *

return_type: void

user_defined_types: struct et_list { struct et_list *next; struct error_table *table; }


fsetversion

decompiled_code:
__int64 fsetversion()
{
errno = -7776;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
errno = -7776;
return 0xFFFFFFFFLL;
}

original_code:
int fsetversion (const char * name, unsigned long version)
{
 extern int errno;
 errno = -7776;
 return -1;
}

canonical_original_code:
int fsetversion(char *name, unsigned long version)
{
 extern int errno;
 errno = -7776;
 return -1;
}

variable_types:
name
char *

variable_types:
version
unsigned long

variable_types: errno int

return_type: int


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

result = 0LL;
if ( a1 )
{
if ( 100 % a1 )
{
if ( (a2 & 0xFF000000) != 0 )
result = a1 * (a2 / 0x64);
else
result = a2 * a1 / 0x64uLL;
}
else
{
result = a2 / (100 / a1);
}
}
return result;
}

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

result = 0LL;
if ( a1 )
{
if ( 100 % a1 )
{
if ( (a2 & 0xFF000000) != 0 )
result = a1 * (a2 / 0x64);
else
result = a2 * a1 / 0x64uLL;
}
else
{
result = a2 / (100 / a1);
}
}
return result;
}

original_code:
unsigned int e2p_percent(int percent, unsigned int base)
{
 unsigned int mask = ~((1 << (sizeof(unsigned int) - 1) * 8) - 1);
 if (!percent)
  return 0;
 if (100 % percent == 0)
  return base / (100 / percent);
 if (mask & base)
  return (base / 100) * percent;
 return base * percent / 100;
}

variable_types: percent int

variable_types:
base
unsigned int

variable_types:
mask
unsigned int

return_type: unsigned int


decompiled_code:
char *__fastcall e2p_feature2string(int a1, unsigned int a2)
{
char *v2; // rdx
char *v3; // rax
char *result; // rax
char v5; // dl
unsigned int v6; // esi
__int64 v7; // rcx

v2 = s2;
if ( s2 )
{
v3 = (char *)&feature_list;
while ( *(_DWORD *)v3 != a1 || *((_DWORD *)v3 + 1) != a2 )
{
v3 += 16;
v2 = (char *)*((_QWORD *)v3 + 1);
if ( !v2 )
goto LABEL_7;
}
result = v2;
}
else
{
LABEL_7:
v5 = 73;
if ( a1 != 1 )
{
v5 = 82;
if ( a1 != 2 )
v5 = a1 == 0 ? 67 : 63;
}
v6 = a2 >> 1;
if ( v6 )
{
LODWORD(v7) = 0;
do
{
v7 = (unsigned int)(v7 + 1);
v6 >>= 1;
}
while ( v6 );
}
else
{
v7 = 0LL;
}
sprintf(buf_0, "FEATURE_%c%d", (unsigned int)v5, v7);
result = buf_0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(int a1, unsigned int a2)
{
char *v2; // rdx
char *v3; // rax
char *result; // rax
char v5; // dl
unsigned int v6; // esi
__int64 v7; // rcx

v2 = s2;
if ( s2 )
{
v3 = (char *)&feature_list;
while ( *(_DWORD *)v3 != a1 || *((_DWORD *)v3 + 1) != a2 )
{
v3 += 16;
v2 = (char *)*((_QWORD *)v3 + 1);
if ( !v2 )
goto LABEL_7;
}
result = v2;
}
else
{
LABEL_7:
v5 = 73;
if ( a1 != 1 )
{
v5 = 82;
if ( a1 != 2 )
v5 = a1 == 0 ? 67 : 63;
}
v6 = a2 >> 1;
if ( v6 )
{
LODWORD(v7) = 0;
do
{
v7 = (unsigned int)(v7 + 1);
v6 >>= 1;
}
while ( v6 );
}
else
{
v7 = 0LL;
}
sprintf(buf_0, "FEATURE_%c%d", (unsigned int)v5, v7);
result = buf_0;
}
return result;
}

original_code:
const char *e2p_feature2string(int compat, unsigned int mask)
{
 struct feature *f;
 static char buf[20];
 char fchar;
 int fnum;
 for (f = feature_list; f->string; f++) {
  if ((compat == f->compat) &&
      (mask == f->mask))
   return f->string;
 }
 switch (compat) {
 case 0:
  fchar = 'C';
  break;
 case 1:
  fchar = 'I';
  break;
 case 2:
  fchar = 'R';
  break;
 default:
  fchar = '?';
  break;
 }
 for (fnum = 0; mask >>= 1; fnum++);
 sprintf(buf, "FEATURE_%c%d", fchar, fnum);
 return buf;
}

variable_types: compat int

variable_types: struct feature { int compat; unsigned int mask; char *string; } *

variable_types:
buf
char [20]

variable_types: fchar char

variable_types: fnum int

return_type: char *


decompiled_code:
__int64 __fastcall e2p_string2feature(char *s1, _DWORD *a2, _DWORD *a3)
{
const char *v5; // rsi
char *v6; // rbp
unsigned int v7; // ebx
unsigned int v9; // eax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v5 = s2;
if ( s2 )
{
v6 = (char *)&feature_list;
while ( 1 )
{
v7 = strcasecmp(s1, v5);
if ( !v7 )
break;
v6 += 16;
v5 = (const char *)*((_QWORD *)v6 + 1);
if ( !v5 )
goto LABEL_5;
}
*a2 = *(_DWORD *)v6;
*a3 = *((_DWORD *)v6 + 1);
}
else
{
LABEL_5:
v7 = strncasecmp(s1, "FEATURE_", 8uLL);
if ( v7 )
{
v7 = 1;
}
else
{
switch ( s1[8] )
{
case 'C':
case 'c':
*a2 = 0;
goto LABEL_10;
case 'I':
case 'i':
*a2 = 1;
goto LABEL_10;
case 'R':
case 'r':
*a2 = 2;
LABEL_10:
if ( s1[9] )
{
v9 = strtol(s1 + 9, &endptr, 10);
if ( v9 > 0x20 )
{
v7 = 1;
}
else if ( *endptr )
{
v7 = 1;
}
else
{
*a3 = 1 << v9;
}
}
else
{
v7 = 1;
}
break;
default:
v7 = 1;
break;
}
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1, _DWORD *a2, _DWORD *a3)
{
const char *v5; // rsi
char *v6; // rbp
unsigned int v7; // ebx
unsigned int v9; // eax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v5 = s2;
if ( s2 )
{
v6 = (char *)&feature_list;
while ( 1 )
{
v7 = strcasecmp(s1, v5);
if ( !v7 )
break;
v6 += 16;
v5 = (const char *)*((_QWORD *)v6 + 1);
if ( !v5 )
goto LABEL_5;
}
*a2 = *(_DWORD *)v6;
*a3 = *((_DWORD *)v6 + 1);
}
else
{
LABEL_5:
v7 = strncasecmp(s1, "FEATURE_", 8uLL);
if ( v7 )
{
v7 = 1;
}
else
{
switch ( s1[8] )
{
case 'C':
case 'c':
*a2 = 0;
goto LABEL_10;
case 'I':
case 'i':
*a2 = 1;
goto LABEL_10;
case 'R':
case 'r':
*a2 = 2;
LABEL_10:
if ( s1[9] )
{
v9 = strtol(s1 + 9, &endptr, 10);
if ( v9 > 0x20 )
{
v7 = 1;
}
else if ( *endptr )
{
v7 = 1;
}
else
{
*a3 = 1 << v9;
}
}
else
{
v7 = 1;
}
break;
default:
v7 = 1;
break;
}
}
}
return v7;
}

original_code:
int e2p_string2feature(char *string, int *compat_type, unsigned int *mask)
{
 struct feature *f;
 char *eptr;
 int num;
 for (f = feature_list; f->string; f++) {
  if (!strcasecmp(string, f->string)) {
   *compat_type = f->compat;
   *mask = f->mask;
   return 0;
  }
 }
 if (strncasecmp(string, "FEATURE_", 8))
  return 1;
 switch (string[8]) {
 case 'c':
 case 'C':
  *compat_type = 0;
  break;
 case 'i':
 case 'I':
  *compat_type = 1;
  break;
 case 'r':
 case 'R':
  *compat_type = 2;
  break;
 default:
  return 1;
 }
 if (string[9] == 0)
  return 1;
 num = strtol(string+9, &eptr, 10);
 if (num > 32 || num < 0)
  return 1;
 if (*eptr)
  return 1;
 *mask = 1 << num;
 return 0;
}

variable_types:
string
char *

variable_types:
mask
unsigned int *

variable_types:
eptr
char *

variable_types: num int

user_defined_types: struct feature { int compat; unsigned int mask; char *string; }


decompiled_code:
__int64 __fastcall e2p_edit_feature(char *src, _DWORD *a2, __int64 a3)
{
size_t v4; // rax
char *v5; // rax
char *v6; // rbx
char *i; // rdi
_BYTE *v8; // rbx
char *v9; // rbp
_BYTE *v10; // rax
char v11; // al
int v12; // er13
unsigned int v13; // ebx
char *ptr; // [rsp+8h] [rbp-50h]
int v16; // [rsp+18h] [rbp-40h] BYREF
int v17[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v4 = strlen(src);
v5 = (char *)malloc(v4 + 1);
ptr = v5;
if ( !v5 )
return 1;
v6 = v5;
strcpy(v5, src);
for ( i = v6; ; i = v8 + 1 )
{
if ( !*i )
{
v13 = 0;
goto LABEL_25;
}
v9 = skip_over_blanks(i);
v10 = skip_over_word(v9);
v8 = v10;
if ( *v10 )
*v10 = 0;
else
v8 = 0LL;
if ( !strcasecmp(v9, "none") || !strcasecmp(v9, "clear") )
{
*a2 = 0;
a2[1] = 0;
a2[2] = 0;
goto LABEL_5;
}
v11 = *v9;
if ( *v9 == 45 )
{
v12 = 1;
LABEL_15:
++v9;
goto LABEL_16;
}
if ( v11 == 94 )
{
v12 = 1;
goto LABEL_15;
}
v12 = 0;
if ( v11 == 43 )
goto LABEL_15;
LABEL_16:
if ( (unsigned int)e2p_string2feature(v9, &v16, v17) )
{
v13 = 1;
goto LABEL_25;
}
if ( a3 && (v17[0] & *(_DWORD *)(a3 + 4LL * v16)) == 0 )
{
v13 = 1;
goto LABEL_25;
}
if ( v12 )
a2[v16] &= ~v17[0];
else
a2[v16] |= v17[0];
LABEL_5:
if ( !v8 )
break;
}
v13 = 0;
LABEL_25:
free(ptr);
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, _DWORD *a2, __int64 a3)
{
size_t v4; // rax
char *v5; // rax
char *v6; // rbx
char *i; // rdi
_BYTE *v8; // rbx
char *v9; // rbp
_BYTE *v10; // rax
char v11; // al
int v12; // er13
unsigned int v13; // ebx
char *ptr; // [rsp+8h] [rbp-50h]
int v16; // [rsp+18h] [rbp-40h] BYREF
int v17[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v4 = strlen(src);
v5 = (char *)malloc(v4 + 1);
ptr = v5;
if ( !v5 )
return 1;
v6 = v5;
strcpy(v5, src);
for ( i = v6; ; i = v8 + 1 )
{
if ( !*i )
{
v13 = 0;
goto LABEL_25;
}
v9 = skip_over_blanks(i);
v10 = skip_over_word(v9);
v8 = v10;
if ( *v10 )
*v10 = 0;
else
v8 = 0LL;
if ( !strcasecmp(v9, "none") || !strcasecmp(v9, "clear") )
{
*a2 = 0;
a2[1] = 0;
a2[2] = 0;
goto LABEL_5;
}
v11 = *v9;
if ( *v9 == 45 )
{
v12 = 1;
LABEL_15:
++v9;
goto LABEL_16;
}
if ( v11 == 94 )
{
v12 = 1;
goto LABEL_15;
}
v12 = 0;
if ( v11 == 43 )
goto LABEL_15;
LABEL_16:
if ( (unsigned int)func1(v9, &v16, v17) )
{
v13 = 1;
goto LABEL_25;
}
if ( a3 && (v17[0] & *(_DWORD *)(a3 + 4LL * v16)) == 0 )
{
v13 = 1;
goto LABEL_25;
}
if ( v12 )
a2[v16] &= ~v17[0];
else
a2[v16] |= v17[0];
LABEL_5:
if ( !v8 )
break;
}
v13 = 0;
LABEL_25:
free(ptr);
return v13;
}

original_code:
int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array)
{
 char *cp, *buf, *next;
 int neg;
 unsigned int mask;
 int compat_type;
 int rc = 0;
 buf = malloc(strlen(str)+1);
 if (!buf)
  return 1;
 strcpy(buf, str);
 for (cp = buf; cp && *cp; cp = next ? next+1 : 0) {
  neg = 0;
  cp = skip_over_blanks(cp);
  next = skip_over_word(cp);
  if (*next == 0)
   next = 0;
  else
   *next = 0;
  if ((strcasecmp(cp, "none") == 0) ||
      (strcasecmp(cp, "clear") == 0)) {
   compat_array[0] = 0;
   compat_array[1] = 0;
   compat_array[2] = 0;
   continue;
  }
  switch (*cp) {
  case '-':
  case '^':
   neg++;
  case '+':
   cp++;
   break;
  }
  if (e2p_string2feature(cp, &compat_type, &mask)) {
   rc = 1;
   break;
  }
  if (ok_array && !(ok_array[compat_type] & mask)) {
   rc = 1;
   break;
  }
  if (neg)
   compat_array[compat_type] &= ~mask;
  else
   compat_array[compat_type] |= mask;
 }
 free(buf);
 return rc;
}

canonical_original_code:
int e2p_edit_feature(char *str, unsigned int *compat_array, unsigned int *ok_array)
{
 char *cp; char *buf; char *next;
 int neg;
 unsigned int mask;
 int compat_type;
 int rc = 0;
 buf = malloc(strlen(str)+1);
 if (!buf)
  return 1;
 strcpy(buf, str);
 for (cp = buf; cp && *cp; cp = next ? next+1 : 0) {
  neg = 0;
  cp = skip_over_blanks(cp);
  next = skip_over_word(cp);
  if (*next == 0)
   next = 0;
  else
   *next = 0;
  if ((strcasecmp(cp, "none") == 0) ||
      (strcasecmp(cp, "clear") == 0)) {
   compat_array[0] = 0;
   compat_array[1] = 0;
   compat_array[2] = 0;
   continue;
  }
  switch (*cp) {
  case '-':
  case '^':
   neg++;
  case '+':
   cp++;
   break;
  }
  if (e2p_string2feature(cp, &compat_type, &mask)) {
   rc = 1;
   break;
  }
  if (ok_array && !(ok_array[compat_type] & mask)) {
   rc = 1;
   break;
  }
  if (neg)
   compat_array[compat_type] &= ~mask;
  else
   compat_array[compat_type] |= mask;
 }
 free(buf);
 return rc;
}

variable_types:
str
char *

variable_types:
cp
char *

variable_types:
buf
char *

variable_types:
next
char *

variable_types: neg int

variable_types: rc int


decompiled_code:
__int64 ext2fs_native_flag()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func46()
{
return 0LL;
}

original_code:
int ext2fs_native_flag(void)
{
 return 0;
}

canonical_original_code:
int ext2fs_native_flag()
{
 return 0;
}


decompiled_code:
__int64 __fastcall ext2fs_find_first_bit_set(_BYTE *a1, unsigned int a2)
{
__int64 result; // rax
int v4; // edx

result = 0LL;
if ( a2 )
{
do
{
if ( *a1 )
break;
++a1;
LODWORD(result) = result + 8;
}
while ( a2 > (unsigned int)result );
if ( !_BitScanForward((unsigned int *)&v4, (char)*a1) )
v4 = -1;
result = (unsigned int)(result + v4);
if ( v4 == -1 )
result = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, unsigned int a2)
{
__int64 result; // rax
int v4; // edx

result = 0LL;
if ( a2 )
{
do
{
if ( *a1 )
break;
++a1;
LODWORD(result) = result + 8;
}
while ( a2 > (unsigned int)result );
if ( !_BitScanForward((unsigned int *)&v4, (char)*a1) )
v4 = -1;
result = (unsigned int)(result + v4);
if ( v4 == -1 )
result = a2;
}
return result;
}

original_code:
extern __inline__ int ext2fs_find_first_bit_set(void * addr, unsigned size)
{
 char *cp = (char *) addr;
 int res = 0, d0;
 if (!size)
  return 0;
 while ((size > res) && (*cp == 0)) {
  cp++;
  res += 8;
 }
 d0 = ffs(*cp);
 if (d0 == 0)
  return size;
 return res + d0 - 1;
}

canonical_original_code:
extern __inline__ int ext2fs_find_first_bit_set(void *addr, unsigned int size)
{
 char *cp = (char *) addr;
 int res = 0; int d0;
 if (!size)
  return 0;
 while ((size > res) && (*cp == 0)) {
  cp++;
  res += 8;
 }
 d0 = ffs(*cp);
 if (d0 == 0)
  return size;
 return res + d0 - 1;
}

variable_types:
addr
void *

variable_types:
size
unsigned int

variable_types: res int


decompiled_code:
__int64 __fastcall ext2fs_find_next_bit_set(__int64 a1, int a2, int a3)
{
int v3; // er8
int v4; // eax
_BYTE *v5; // rdi
bool v6; // zf
int v7; // edx
int v8; // edx
__int64 result; // rax

v3 = a3;
v4 = a3 >> 3;
v5 = (_BYTE *)((a3 >> 3) + a1);
if ( (a3 & 7) != 0 )
{
v6 = !_BitScanForward((unsigned int *)&a3, (unsigned __int8)*v5 & (-1 << (a3 & 7)));
if ( v6 )
a3 = -1;
++v5;
v4 += 8;
v7 = a3 + 1;
if ( v7 )
return v7 + (v3 & 0xFFFFFFF8) - 1;
}
for ( ; a2 > v4; v4 += 8 )
{
if ( *v5 )
break;
++v5;
}
v6 = !_BitScanForward((unsigned int *)&v8, (unsigned __int8)*v5);
if ( v6 )
v8 = -1;
result = (unsigned int)(v4 + v8);
if ( v8 == -1 )
result = (unsigned int)a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3)
{
int v3; // er8
int v4; // eax
_BYTE *v5; // rdi
bool v6; // zf
int v7; // edx
int v8; // edx
__int64 result; // rax

v3 = a3;
v4 = a3 >> 3;
v5 = (_BYTE *)((a3 >> 3) + a1);
if ( (a3 & 7) != 0 )
{
v6 = !_BitScanForward((unsigned int *)&a3, (unsigned __int8)*v5 & (-1 << (a3 & 7)));
if ( v6 )
a3 = -1;
++v5;
v4 += 8;
v7 = a3 + 1;
if ( v7 )
return v7 + (v3 & 0xFFFFFFF8) - 1;
}
for ( ; a2 > v4; v4 += 8 )
{
if ( *v5 )
break;
++v5;
}
v6 = !_BitScanForward((unsigned int *)&v8, (unsigned __int8)*v5);
if ( v6 )
v8 = -1;
result = (unsigned int)(v4 + v8);
if ( v8 == -1 )
result = (unsigned int)a2;
return result;
}

original_code:
extern __inline__ int ext2fs_find_next_bit_set (void * addr, int size, int offset)
{
 unsigned char * p;
 int set = 0, bit = offset & 7, res = 0, d0;
 res = offset >> 3;
 p = ((unsigned char *) addr) + res;
 if (bit) {
  set = ffs(*p & ~((1 << bit) - 1));
  if (set)
   return (offset & ~7) + set - 1;
  p++;
  res += 8;
 }
 while ((size > res) && (*p == 0)) {
  p++;
  res += 8;
 }
 d0 = ffs(*p);
 if (d0 == 0)
  return size;
 return (res + d0 - 1);
}

canonical_original_code:
extern __inline__ int ext2fs_find_next_bit_set(void *addr, int size, int offset)
{
 unsigned char *p;
 int set = 0; int bit = offset & 7; int res = 0; int d0;
 res = offset >> 3;
 p = ((unsigned char *) addr) + res;
 if (bit) {
  set = ffs(*p & ~((1 << bit) - 1));
  if (set)
   return (offset & ~7) + set - 1;
  p++;
  res += 8;
 }
 while ((size > res) && (*p == 0)) {
  p++;
  res += 8;
 }
 d0 = ffs(*p);
 if (d0 == 0)
  return size;
 return (res + d0 - 1);
}

variable_types: size int

variable_types: offset int

variable_types:
p
unsigned char *

variable_types: set int

variable_types: bit int


decompiled_code:
__int64 __fastcall ext2fs_get_mem(size_t a1, _QWORD *a2)
{
void *v2; // rax

v2 = malloc(a1);
if ( !v2 )
return 2133571398LL;
*a2 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func27(size_t a1, _QWORD *a2)
{
void *v2; // rax

v2 = malloc(a1);
if ( !v2 )
return 2133571398LL;
*a2 = v2;
return 0LL;
}

original_code:
extern __inline__ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
{
 void *pp;
 pp = malloc(size);
 if (!pp)
  return (2133571398L);
 memcpy(ptr, &pp, sizeof (pp));
 return 0;
}

canonical_original_code:
extern __inline__ long ext2fs_get_mem(unsigned long size, void *ptr)
{
 void *pp;
 pp = malloc(size);
 if (!pp)
  return (2133571398L);
 memcpy(ptr, &pp, sizeof (pp));
 return 0;
}

variable_types:
size
unsigned long

variable_types:
ptr
void *

variable_types:
pp
void *

return_type: long


decompiled_code:
__int64 __fastcall ext2fs_free_mem(void **a1)
{
free(*a1);
*a1 = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func28(void **a1)
{
free(*a1);
*a1 = 0LL;
return 0LL;
}

original_code:
extern __inline__ errcode_t ext2fs_free_mem(void *ptr)
{
 void *p;
 memcpy(&p, ptr, sizeof(p));
 free(p);
 p = 0;
 memcpy(ptr, &p, sizeof(p));
 return 0;
}

canonical_original_code:
extern __inline__ long ext2fs_free_mem(void *ptr)
{
 void *p;
 memcpy(&p, ptr, sizeof(p));
 free(p);
 p = 0;
 memcpy(ptr, &p, sizeof(p));
 return 0;
}

variable_types:
p
void *


decompiled_code:
__int64 __fastcall ext2fs_resize_mem(__int64 a1, size_t a2, void **a3)
{
void *v4; // rax

v4 = realloc(*a3, a2);
if ( !v4 )
return 2133571398LL;
*a3 = v4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func29(__int64 a1, size_t a2, void **a3)
{
void *v4; // rax

v4 = realloc(*a3, a2);
if ( !v4 )
return 2133571398LL;
*a3 = v4;
return 0LL;
}

original_code:
extern __inline__ errcode_t ext2fs_resize_mem(unsigned long __attribute__((unused)) old_size,
         unsigned long size, void *ptr)
{
 void *p;
 memcpy(&p, ptr, sizeof(p));
 p = realloc(p, size);
 if (!p)
  return (2133571398L);
 memcpy(ptr, &p, sizeof(p));
 return 0;
}

canonical_original_code:
extern __inline__ long ext2fs_resize_mem(unsigned long old_size, unsigned long size, void *ptr)
{
 void *p;
 memcpy(&p, ptr, sizeof(p));
 p = realloc(p, size);
 if (!p)
  return (2133571398L);
 memcpy(ptr, &p, sizeof(p));
 return 0;
}


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

result = a1;
if ( a1 )
result = (a1 - 1) / a2 + 1;
return result;
}

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

result = a1;
if ( a1 )
result = (a1 - 1) / a2 + 1;
return result;
}

original_code:
extern __inline__ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)
{
 if (!a)
  return 0;
 return ((a - 1) / b) + 1;
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int


decompiled_code:
char *__fastcall e2p_os2string(int a1)
{
const char *v1; // rbp
size_t v2; // rax
char *v3; // rax
char *v4; // rbx

v1 = "(unknown os)";
if ( a1 <= 4 )
v1 = (&os_tab)[a1];
v2 = strlen(v1);
v3 = (char *)malloc(v2 + 1);
v4 = v3;
if ( v3 )
strcpy(v3, v1);
return v4;
}

canonical_decompiled_code:
char *__fastcall func0(int a1)
{
const char *v1; // rbp
size_t v2; // rax
char *v3; // rax
char *v4; // rbx

v1 = "(unknown os)";
if ( a1 <= 4 )
v1 = (&os_tab)[a1];
v2 = strlen(v1);
v3 = (char *)malloc(v2 + 1);
v4 = v3;
if ( v3 )
strcpy(v3, v1);
return v4;
}

original_code:
char *e2p_os2string(int os_type)
{
        const char *os;
 char *ret;
 if (os_type <= 4)
  os = os_tab[os_type];
 else
  os = "(unknown os)";
        ret = malloc(strlen(os)+1);
 if (ret)
  strcpy(ret, os);
        return ret;
}

canonical_original_code:
char *e2p_os2string(int os_type)
{
        char *os;
 char *ret;
 if (os_type <= 4)
  os = os_tab[os_type];
 else
  os = "(unknown os)";
        ret = malloc(strlen(os)+1);
 if (ret)
  strcpy(ret, os);
        return ret;
}

variable_types:
os
char *

variable_types:
ret
char *


decompiled_code:
__int64 __fastcall e2p_string2os(char *s1)
{
const char *v1; // rsi
__int64 v2; // rbx
unsigned int v3; // er12

v1 = os_tab;
if ( !os_tab )
return (unsigned int)-1;
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( !strcasecmp(s1, v1) )
break;
v1 = (&os_tab)[++v2];
if ( !v1 )
return (unsigned int)-1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
const char *v1; // rsi
__int64 v2; // rbx
unsigned int v3; // er12

v1 = os_tab;
if ( !os_tab )
return (unsigned int)-1;
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( !strcasecmp(s1, v1) )
break;
v1 = (&os_tab)[++v2];
if ( !v1 )
return (unsigned int)-1;
}
return v3;
}

original_code:
int e2p_string2os(char *str)
{
 const char **cpp;
 int i = 0;
 for (cpp = os_tab; *cpp; cpp++, i++) {
  if (!strcasecmp(str, *cpp))
   return i;
 }
 return -1;
}

canonical_original_code:
int e2p_string2os(char *str)
{
 char **cpp;
 int i = 0;
 for (cpp = os_tab; *cpp; cpp++, i++) {
  if (!strcasecmp(str, *cpp))
   return i;
 }
 return -1;
}

variable_types:
str
char *

variable_types:
cpp
char **

variable_types: i int


decompiled_code:
__int64 __fastcall init_error_table(__int64 a1, __int64 a2, int a3)
{
_QWORD *v4; // rax

if ( a1 == 0 || a3 == 0 || !a2 )
return 0LL;
v4 = malloc(0x28uLL);
if ( !v4 )
return 12LL;
v4[1] = v4 + 2;
v4[2] = a1;
v4[3] = a2;
*((_DWORD *)v4 + 8) = a3;
*v4 = et_dynamic_list;
et_dynamic_list = v4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3)
{
_QWORD *v4; // rax

if ( a1 == 0 || a3 == 0 || !a2 )
return 0LL;
v4 = malloc(0x28uLL);
if ( !v4 )
return 12LL;
v4[1] = v4 + 2;
v4[2] = a1;
v4[3] = a2;
*((_DWORD *)v4 + 8) = a3;
*v4 = et_dynamic_list;
et_dynamic_list = v4;
return 0LL;
}

original_code:
int init_error_table(const char * const *msgs, long base, int count)
{
    struct foobar * new_et;
    if (!base || !count || !msgs)
 return 0;
    new_et = (struct foobar *) malloc(sizeof(struct foobar));
    if (!new_et)
 return 12;
    new_et->etl.table = &new_et->et;
    new_et->et.msgs = msgs;
    new_et->et.base = base;
    new_et->et.n_msgs= count;
    new_et->etl.next = _et_dynamic_list;
    _et_dynamic_list = &new_et->etl;
    return 0;
}

canonical_original_code:
int init_error_table(char **msgs, long base, int count)
{
    struct foobar *new_et;
    if (!base || !count || !msgs)
 return 0;
    new_et = (struct foobar *) malloc(sizeof(struct foobar));
    if (!new_et)
 return 12;
    new_et->etl.table = &new_et->et;
    new_et->et.msgs = msgs;
    new_et->et.base = base;
    new_et->et.n_msgs= count;
    new_et->etl.next = _et_dynamic_list;
    _et_dynamic_list = &new_et->etl;
    return 0;
}

variable_types:
msgs
char **

variable_types: base long

variable_types: count int

variable_types: struct foobar { struct et_list { struct et_list *next; struct error_table { char **msgs; long base; int n_msgs; } *table; } etl; struct error_table et; } *

user_defined_types: struct foobar { struct et_list etl; struct error_table et; }


decompiled_code:
unsigned __int64 __fastcall parse_num_blocks(const char *a1, char a2)
{
unsigned __int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtoull(a1, &endptr, 0);
if ( *endptr )
{
if ( endptr[1] )
{
result = 0LL;
}
else
{
switch ( *endptr )
{
case 'G':
case 'g':
goto LABEL_5;
case 'H':
case 'I':
case 'J':
case 'L':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '[':
case '\\':
case ']':
case '^':
case '_':
case '`':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'h':
case 'i':
case 'j':
case 'l':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
return 0LL;
case 'K':
case 'k':
goto LABEL_7;
case 'M':
case 'm':
goto LABEL_6;
case 'T':
case 't':
result <<= 10;
LABEL_5:
result <<= 10;
LABEL_6:
result <<= 10;
LABEL_7:
result >>= a2;
break;
case 's':
result >>= a2 + 1;
break;
default:
result = 0LL;
break;
}
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(const char *a1, char a2)
{
unsigned __int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtoull(a1, &endptr, 0);
if ( *endptr )
{
if ( endptr[1] )
{
result = 0LL;
}
else
{
switch ( *endptr )
{
case 'G':
case 'g':
goto LABEL_5;
case 'H':
case 'I':
case 'J':
case 'L':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '[':
case '\\':
case ']':
case '^':
case '_':
case '`':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'h':
case 'i':
case 'j':
case 'l':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
return 0LL;
case 'K':
case 'k':
goto LABEL_7;
case 'M':
case 'm':
goto LABEL_6;
case 'T':
case 't':
result <<= 10;
LABEL_5:
result <<= 10;
LABEL_6:
result <<= 10;
LABEL_7:
result >>= a2;
break;
case 's':
result >>= a2 + 1;
break;
default:
result = 0LL;
break;
}
}
}
return result;
}

original_code:
unsigned long parse_num_blocks(const char *arg, int log_block_size)
{
 char *p;
 unsigned long long num;
 num = strtoull(arg, &p, 0);
 if (p[0] && p[1])
  return 0;
 switch (*p) {
 case 'T': case 't':
  num <<= 10;
 case 'G': case 'g':
  num <<= 10;
 case 'M': case 'm':
  num <<= 10;
 case 'K': case 'k':
  num >>= log_block_size;
  break;
 case 's':
  num >>= (1+log_block_size);
  break;
 case '\0':
  break;
 default:
  return 0;
 }
 return num;
}

canonical_original_code:
unsigned long parse_num_blocks(char *arg, int log_block_size)
{
 char *p;
 unsigned long long num;
 num = strtoull(arg, &p, 0);
 if (p[0] && p[1])
  return 0;
 switch (*p) {
 case 'T': case 't':
  num <<= 10;
 case 'G': case 'g':
  num <<= 10;
 case 'M': case 'm':
  num <<= 10;
 case 'K': case 'k':
  num >>= log_block_size;
  break;
 case 's':
  num >>= (1+log_block_size);
  break;
 case '\0':
  break;
 default:
  return 0;
 }
 return num;
}

variable_types:
arg
char *

variable_types:
p
char *

variable_types:
num
unsigned long long

return_type: unsigned long


setversion

decompiled_code:
__int64 setversion()
{
errno = -7776;
return 0xFFFFFFFFLL;
}

original_code:
int setversion (int fd, unsigned long version)
{
 extern int errno;
 errno = -7776;
 return -1;
}

canonical_original_code:
int setversion(int fd, unsigned long version)
{
 extern int errno;
 errno = -7776;
 return -1;
}

variable_types: fd int

variable_types:
version
unsigned long

variable_types: errno int


decompiled_code:
void __fastcall __noreturn e2_err(const char *a1, unsigned int a2)
{
__int64 v2; // rax

v2 = 0LL;
while ( LODWORD(errors[2 * v2]) != a2 )
{
if ( ++v2 == 10 )
{
fprintf(stderr, "%s: Error number %d\n", a1, a2);
exit(1);
}
}
fprintf(stderr, "%s: %s\n", a1, (const char *)errors[2 * (int)v2 + 1]);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1, unsigned int a2)
{
__int64 v2; // rax

v2 = 0LL;
while ( LODWORD(errors[2 * v2]) != a2 )
{
if ( ++v2 == 10 )
{
fprintf(stderr, "%s: Error number %d\n", a1, a2);
exit(1);
}
}
fprintf(stderr, "%s: %s\n", a1, (const char *)errors[2 * (int)v2 + 1]);
exit(1);
}

original_code:
void
e2_err(char * text, int err)
{
 int i;
 for (i=0; i<(sizeof(errors)/sizeof(errors[0])); i++) {
  if (errors[i].value == err) {
   fprintf(stderr,"%s: %s\n",text,errors[i].text);
   exit(1);
  }
 }
 fprintf(stderr,"%s: Error number %d\n",text,err);
 exit(1);
}

canonical_original_code:
void e2_err(char *text, int err)
{
 int i;
 for (i=0; i<(sizeof(errors)/sizeof(errors[0])); i++) {
  if (errors[i].value == err) {
   fprintf(stderr,"%s: %s\n",text,errors[i].text);
   exit(1);
  }
 }
 fprintf(stderr,"%s: Error number %d\n",text,err);
 exit(1);
}

variable_types:
text
char *

variable_types: err int


decompiled_code:
__int64 __fastcall ext2fs_get_device_sectsize(const char *a1, _DWORD *a2)
{
int v2; // eax

v2 = open(a1, 0);
if ( v2 < 0 )
return *_errno_location();
*a2 = 0;
close(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func46(const char *a1, _DWORD *a2)
{
int v2; // eax

v2 = open(a1, 0);
if ( v2 < 0 )
return *_errno_location();
*a2 = 0;
close(v2);
return 0LL;
}

original_code:
errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize)
{
 int fd;
 fd = open(file, 00);
 if (fd < 0)
  return (*__errno_location ());
 *sectsize = 0;
 close(fd);
 return 0;
}

canonical_original_code:
long ext2fs_get_device_sectsize(char *file, int *sectsize)
{
 int fd;
 fd = open(file, 00);
 if (fd < 0)
  return (*__errno_location ());
 *sectsize = 0;
 close(fd);
 return 0;
}

variable_types:
file
char *

variable_types:
sectsize
int *


canonical_original_code:
extern __inline__ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)
{
 if (!a)
  return 0;
 return ((a - 1) / b) + 1;
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int


fgetversion

decompiled_code:
__int64 fgetversion()
{
errno = -7776;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
errno = -7776;
return 0xFFFFFFFFLL;
}

original_code:
int fgetversion (const char * name, unsigned long * version)
{
 extern int errno;
 errno = -7776;
 return -1;
}

canonical_original_code:
int fgetversion(char *name, unsigned long *version)
{
 extern int errno;
 errno = -7776;
 return -1;
}

variable_types:
name
char *

variable_types:
version
unsigned long *


decompiled_code:
__int64 __fastcall ext2fs_sync_device(int fd, int a2)
{
__int64 result; // rax
unsigned int v3; // eax
int v4; // edx
unsigned int v5; // eax

if ( fsync(fd) == -1 )
return *_errno_location();
result = 0LL;
if ( a2 )
{
v3 = IO(18LL, 97LL);
v4 = ioctl(fd, v3, 0LL);
result = 0LL;
if ( v4 )
{
v5 = IO(2LL, 75LL);
ioctl(fd, v5, 0LL);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func46(int fd, int a2)
{
__int64 result; // rax
unsigned int v3; // eax
int v4; // edx
unsigned int v5; // eax

if ( fsync(fd) == -1 )
return *_errno_location();
result = 0LL;
if ( a2 )
{
v3 = IO(18LL, 97LL);
v4 = ioctl(fd, v3, 0LL);
result = 0LL;
if ( v4 )
{
v5 = IO(2LL, 75LL);
ioctl(fd, v5, 0LL);
result = 0LL;
}
}
return result;
}

original_code:
errcode_t ext2fs_sync_device(int fd, int flushb)
{
 if (fsync (fd) == -1)
  return (*__errno_location ());
 if (flushb) {
  if (ioctl (fd, _IO(0x12,97), 0) == 0)
   return 0;
  ioctl (fd, _IO(2,0x4b), 0);
 }
 return 0;
}

canonical_original_code:
long ext2fs_sync_device(int fd, int flushb)
{
 if (fsync (fd) == -1)
  return (*__errno_location ());
 if (flushb) {
  if (ioctl (fd, _IO(0x12,97), 0) == 0)
   return 0;
  ioctl (fd, _IO(2,0x4b), 0);
 }
 return 0;
}

variable_types: flushb int


decompiled_code:
char *__fastcall interval_string(unsigned int a1)
{
char *result; // rax
unsigned int v2; // ebx
unsigned __int64 v3; // rdx
const char *v4; // rcx
unsigned __int64 v5; // rcx
const char *v6; // r8
const char *v7; // rdx
unsigned __int64 v8; // rcx
const char *v9; // r8
const char *v10; // rdx
const char *v11; // rdx

buf_1 = 0;
result = "<none>";
if ( a1 )
{
v2 = a1;
if ( a1 > 0x278CFF )
{
v3 = a1 / 0x278D00uLL;
v2 = a1 % 0x278D00;
v4 = "s";
if ( (int)v3 <= 1 )
v4 = (const char *)&unk_DD5;
sprintf(&buf_1, "%d month%s", v3, v4);
}
if ( v2 > 0x93A7F )
{
v5 = v2 / 0x93A80uLL;
v2 %= 0x93A80u;
v6 = "s";
if ( (int)v5 <= 1 )
v6 = (const char *)&unk_DD5;
v7 = ", ";
if ( !buf_1 )
v7 = (const char *)&unk_DD5;
sprintf(tmp_0, "%s%d week%s", v7, v5, v6);
strcat(&buf_1, tmp_0);
}
if ( v2 > 0x1517F )
{
v8 = v2 / 0x15180uLL;
v2 %= 0x15180u;
v9 = "s";
if ( (int)v8 <= 1 )
v9 = (const char *)&unk_DD5;
v10 = ", ";
if ( !buf_1 )
v10 = (const char *)&unk_DD5;
sprintf(tmp_0, "%s%d day%s", v10, v8, v9);
strcat(&buf_1, tmp_0);
}
result = &buf_1;
if ( v2 )
{
v11 = ", ";
if ( !buf_1 )
v11 = (const char *)&unk_DD5;
sprintf(tmp_0, "%s%d:%02d:%02d", v11, v2 / 0xE10uLL, v2 % 0xE10 / 0x3CuLL, v2 % 0xE10 % 0x3C);
strcat(&buf_1, tmp_0);
result = &buf_1;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(unsigned int a1)
{
char *result; // rax
unsigned int v2; // ebx
unsigned __int64 v3; // rdx
const char *v4; // rcx
unsigned __int64 v5; // rcx
const char *v6; // r8
const char *v7; // rdx
unsigned __int64 v8; // rcx
const char *v9; // r8
const char *v10; // rdx
const char *v11; // rdx

buf_1 = 0;
result = "<none>";
if ( a1 )
{
v2 = a1;
if ( a1 > 0x278CFF )
{
v3 = a1 / 0x278D00uLL;
v2 = a1 % 0x278D00;
v4 = "s";
if ( (int)v3 <= 1 )
v4 = (const char *)&unk_DD5;
sprintf(&buf_1, "%d month%s", v3, v4);
}
if ( v2 > 0x93A7F )
{
v5 = v2 / 0x93A80uLL;
v2 %= 0x93A80u;
v6 = "s";
if ( (int)v5 <= 1 )
v6 = (const char *)&unk_DD5;
v7 = ", ";
if ( !buf_1 )
v7 = (const char *)&unk_DD5;
sprintf(tmp_0, "%s%d week%s", v7, v5, v6);
strcat(&buf_1, tmp_0);
}
if ( v2 > 0x1517F )
{
v8 = v2 / 0x15180uLL;
v2 %= 0x15180u;
v9 = "s";
if ( (int)v8 <= 1 )
v9 = (const char *)&unk_DD5;
v10 = ", ";
if ( !buf_1 )
v10 = (const char *)&unk_DD5;
sprintf(tmp_0, "%s%d day%s", v10, v8, v9);
strcat(&buf_1, tmp_0);
}
result = &buf_1;
if ( v2 )
{
v11 = ", ";
if ( !buf_1 )
v11 = (const char *)&unk_DD5;
sprintf(tmp_0, "%s%d:%02d:%02d", v11, v2 / 0xE10uLL, v2 % 0xE10 / 0x3CuLL, v2 % 0xE10 % 0x3C);
strcat(&buf_1, tmp_0);
result = &buf_1;
}
}
return result;
}

original_code:
static const char *interval_string(unsigned int secs)
{
 static char buf[256], tmp[80];
 int hr, min, num;
 buf[0] = 0;
 if (secs == 0)
  return "<none>";
 if (secs >= (86400 * 30)) {
  num = secs / (86400 * 30);
  secs -= num*(86400 * 30);
  sprintf(buf, "%d month%s", num, (num>1) ? "s" : "");
 }
 if (secs >= (86400 * 7)) {
  num = secs / (86400 * 7);
  secs -= num*(86400 * 7);
  sprintf(tmp, "%s%d week%s", buf[0] ? ", " : "",
   num, (num>1) ? "s" : "");
  strcat(buf, tmp);
 }
 if (secs >= (86400)) {
  num = secs / (86400);
  secs -= num*(86400);
  sprintf(tmp, "%s%d day%s", buf[0] ? ", " : "",
   num, (num>1) ? "s" : "");
  strcat(buf, tmp);
 }
 if (secs > 0) {
  hr = secs / (60 * 60);
  secs -= hr*(60 * 60);
  min = secs / (60);
  secs -= min*(60);
  sprintf(tmp, "%s%d:%02d:%02d", buf[0] ? ", " : "",
   hr, min, secs);
  strcat(buf, tmp);
 }
 return buf;
}

canonical_original_code:
static char *interval_string(unsigned int secs)
{
 static char buf[256]; static char tmp[80];
 int hr; int min; int num;
 buf[0] = 0;
 if (secs == 0)
  return "<none>";
 if (secs >= (86400 * 30)) {
  num = secs / (86400 * 30);
  secs -= num*(86400 * 30);
  sprintf(buf, "%d month%s", num, (num>1) ? "s" : "");
 }
 if (secs >= (86400 * 7)) {
  num = secs / (86400 * 7);
  secs -= num*(86400 * 7);
  sprintf(tmp, "%s%d week%s", buf[0] ? ", " : "",
   num, (num>1) ? "s" : "");
  strcat(buf, tmp);
 }
 if (secs >= (86400)) {
  num = secs / (86400);
  secs -= num*(86400);
  sprintf(tmp, "%s%d day%s", buf[0] ? ", " : "",
   num, (num>1) ? "s" : "");
  strcat(buf, tmp);
 }
 if (secs > 0) {
  hr = secs / (60 * 60);
  secs -= hr*(60 * 60);
  min = secs / (60);
  secs -= min*(60);
  sprintf(tmp, "%s%d:%02d:%02d", buf[0] ? ", " : "",
   hr, min, secs);
  strcat(buf, tmp);
 }
 return buf;
}

variable_types:
secs
unsigned int

variable_types:
buf
char [256]

variable_types:
tmp
char [80]

variable_types: hr int

variable_types: min int

variable_types: num int


statistics

repo: mmgaggle/sslsqueeze

decompiled_code:
int __fastcall statistics(int a1)
{
time_t v1; // rax

++stats_1[a1];
v1 = time(0LL);
if ( old_time_0 != v1 )
{
old_time_0 = v1;
printf("Succeeded: %-10dFailed: %-10d\r", (unsigned int)stats_1[0], (unsigned int)dword_4043E4);
LODWORD(v1) = fflush(stdout);
dword_4043E4 = 0;
stats_1[0] = 0;
}
return v1;
}

canonical_decompiled_code:
int __fastcall func10(int a1)
{
time_t v1; // rax

++stats_1[a1];
v1 = time(0LL);
if ( old_time_0 != v1 )
{
old_time_0 = v1;
printf("Succeeded: %-10dFailed: %-10d\r", (unsigned int)stats_1[0], (unsigned int)dword_4043E4);
LODWORD(v1) = fflush(stdout);
dword_4043E4 = 0;
stats_1[0] = 0;
}
return v1;
}

original_code:
static void statistics(const int err) {
    static time_t old_time;
    time_t new_time;
    static int stats[2]={0, 0};
    ++stats[err];
    new_time=time(((void *)0));
    if(new_time==old_time)
        return;
    old_time=new_time;
    printf("Succeeded: %-10dFailed: %-10d\r", stats[0], stats[1]);
    fflush(stdout);
    stats[0]=stats[1]=0;
}

canonical_original_code:
static void statistics(int err) {
    static long old_time;
    long new_time;
    static int stats[2] = {0, 0};
    ++stats[err];
    new_time=time(((void *)0));
    if(new_time==old_time)
        return;
    old_time=new_time;
    printf("Succeeded: %-10dFailed: %-10d\r", stats[0], stats[1]);
    fflush(stdout);
    stats[0]=stats[1]=0;
}

variable_types:
stats
int [2]


repo: mmhl/euler

decompiled_code:
__int64 __fastcall digits_in_number(int a1)
{
unsigned int v1; // esi
int v2; // ecx

if ( !a1 )
return 0;
v1 = 0;
v2 = 1;
do
{
v2 *= 10;
++v1;
}
while ( a1 % v2 != a1 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
unsigned int v1; // esi
int v2; // ecx

if ( !a1 )
return 0;
v1 = 0;
v2 = 1;
do
{
v2 *= 10;
++v1;
}
while ( a1 % v2 != a1 );
return v1;
}

original_code:
static int digits_in_number(int number)
{
 int divisor = 1;
 int i;
 int digits= 0;
 while(number % divisor != number)
 {
  divisor *= 10;
  digits++;
 }
 return digits;
}

canonical_original_code:
static int digits_in_number(int number)
{
 int divisor = 1;
 int i;
 int digits = 0;
 while(number % divisor != number)
 {
  divisor *= 10;
  digits++;
 }
 return digits;
}

variable_types: number int

variable_types: divisor int

variable_types: i int

variable_types: digits int


original_code:
static int is_palindrome(int number, int digits)
{
 int i, divisor;
 divisor = 1;
 int ret;
 int *number_digits= calloc(digits, sizeof(int));
 for(i = 0; i < digits; i++)
 {
  number_digits[i] = (number / divisor) % 10;
  divisor *= 10;
 }
 for(i = 0; i < digits; i++)
 {
  if(number_digits[i] == number_digits[digits-i-1])
  {
   ret = 1;
   continue;
  }
  else
  {
   ret = 0;
   break;
  }
 }
 free(number_digits);
 return ret;
}

canonical_original_code:
static int is_palindrome(int number, int digits)
{
 int i; int divisor;
 divisor = 1;
 int ret;
 int *number_digits = calloc(digits, sizeof(int));
 for(i = 0; i < digits; i++)
 {
  number_digits[i] = (number / divisor) % 10;
  divisor *= 10;
 }
 for(i = 0; i < digits; i++)
 {
  if(number_digits[i] == number_digits[digits-i-1])
  {
   ret = 1;
   continue;
  }
  else
  {
   ret = 0;
   break;
  }
 }
 free(number_digits);
 return ret;
}

variable_types: ret int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v4; // r13
int v5; // er15
int i; // ebx
int v7; // ebp
int v8; // eax

v3 = 999;
v4 = 0LL;
v5 = 0;
do
{
for ( i = v3; i > 100; --i )
{
v7 = i * v3;
if ( v7 == 11 * (v7 / 11LL) )
{
++v4;
v8 = digits_in_number(v7);
if ( (unsigned int)is_palindrome(v7, v8) )
{
if ( v5 < v7 )
v5 = i * v3;
}
}
}
--v3;
}
while ( v3 != 100 );
printf("Got max palindrome %d\n", (unsigned int)v5);
printf("%ld\n", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v4; // r13
int v5; // er15
int i; // ebx
int v7; // ebp
int v8; // eax

v3 = 999;
v4 = 0LL;
v5 = 0;
do
{
for ( i = v3; i > 100; --i )
{
v7 = i * v3;
if ( v7 == 11 * (v7 / 11LL) )
{
++v4;
v8 = func7(v7);
if ( (unsigned int)func8(v7, v8) )
{
if ( v5 < v7 )
v5 = i * v3;
}
}
}
--v3;
}
while ( v3 != 100 );
printf("Got max palindrome %d\n", (unsigned int)v5);
printf("%ld\n", v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 long int number;
 int digits;
 int palindrome, max_palindrome;
 long int multiples= 0;
 palindrome = max_palindrome = 0;
 int i, j;
 for(i = 999; i > 100; i--)
 {
  for(j = i; j > 100; j--)
  {
   number = i*j;
   if(number % 11 != 0)
    continue;
   multiples++;
   digits = digits_in_number(number);
   if(is_palindrome(number, digits))
   {
    palindrome = number;
    if(palindrome > max_palindrome)
     max_palindrome = palindrome;
   }
  }
 }
out:
 printf("Got max palindrome %d\n", max_palindrome);
 printf("%ld\n", multiples);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 long number;
 int digits;
 int palindrome; int max_palindrome;
 long multiples = 0;
 palindrome = max_palindrome = 0;
 int i; int j;
 for(i = 999; i > 100; i--)
 {
  for(j = i; j > 100; j--)
  {
   number = i*j;
   if(number % 11 != 0)
    continue;
   multiples++;
   digits = digits_in_number(number);
   if(is_palindrome(number, digits))
   {
    palindrome = number;
    if(palindrome > max_palindrome)
     max_palindrome = palindrome;
   }
  }
 }
out:
 printf("Got max palindrome %d\n", max_palindrome);
 printf("%ld\n", multiples);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: number long

variable_types: palindrome int

variable_types: multiples long

variable_types: j int


Pop

repo: mmiotk/Teoria-graf-w-i-sieci

decompiled_code:
__int64 __fastcall Pop(__int64 a1)
{
if ( stack_empty((_DWORD *)a1) )
perror("Niedomiar");
else
--*(_DWORD *)a1;
return *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * (unsigned int)(*(_DWORD *)a1 + 1));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( func0((_DWORD *)a1) )
perror("Niedomiar");
else
--*(_DWORD *)a1;
return *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * (unsigned int)(*(_DWORD *)a1 + 1));
}

original_code:
unsigned int Pop(stack *s){
  if(stack_empty(s) == TRUE)
    perror("Niedomiar");
  else
    s->top = s->top-1;
    return s->vertex[s->top+1];
}

canonical_original_code:
unsigned int Pop(struct stack *s){
  if(stack_empty(s) == TRUE)
    perror("Niedomiar");
  else
    s->top = s->top-1;
    return s->vertex[s->top+1];
}

variable_types: struct stack { unsigned int top; unsigned int *vertex; unsigned int size; } *


decompiled_code:
void __fastcall free_stack(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void free_stack(stack *s){
  free(s->vertex);
  free(s);
}

canonical_original_code:
void free_stack(struct stack *s){
  free(s->vertex);
  free(s);
}

user_defined_types: struct stack { unsigned int top; unsigned int *vertex; unsigned int size; }


decompiled_code:
__int64 __fastcall get_size(_DWORD *a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

do
_isoc99_scanf(&unk_6D8, v2);
while ( !v2[0] );
*a1 = v2[0];
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

do
_isoc99_scanf(&unk_6D8, v2);
while ( !v2[0] );
*a1 = v2[0];
return 1LL;
}

original_code:
int get_size(unsigned int *a){
 unsigned int temp;
 while(1){
  scanf("%d",&temp);
  if(temp>0){
  *a=temp;
  return TRUE;
  }
 }
}

variable_types:
a
unsigned int *

variable_types:
temp
unsigned int


decompiled_code:
__int64 __fastcall free_segments(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
return 1LL;
}

original_code:
int free_segments(int **tab,unsigned int size){
 unsigned int i;
 for(i=0;i<size;i++){
  free(tab[i]);
 }
 free(tab);
 return TRUE;
}

canonical_original_code:
int free_segments(int **tab, unsigned int size){
 unsigned int i;
 for(i=0;i<size;i++){
  free(tab[i]);
 }
 free(tab);
 return TRUE;
}

variable_types:
tab
int **

variable_types:
size
unsigned int

variable_types:
i
unsigned int


decompiled_code:
double __fastcall oblicz_czas(int a1, int a2, int a3, int a4)
{
return (double)a4 / 1000000000.0 + (double)a3 - ((double)a2 / 1000000000.0 + (double)a1);
}

canonical_decompiled_code:
double __fastcall func8(int a1, int a2, int a3, int a4)
{
return (double)a4 / 1000000000.0 + (double)a3 - ((double)a2 / 1000000000.0 + (double)a1);
}

original_code:
double oblicz_czas(struct timespec kon,struct timespec pocz){
  double wynik;
  wynik=(pocz.tv_sec+pocz.tv_nsec/1000000000.0)-(kon.tv_sec+kon.tv_nsec/1000000000.0);
  return wynik;
}

canonical_original_code:
double oblicz_czas(struct timespec kon, struct timespec pocz){
  double wynik;
  wynik=(pocz.tv_sec+pocz.tv_nsec/1000000000.0)-(kon.tv_sec+kon.tv_nsec/1000000000.0);
  return wynik;
}

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

variable_types:
pocz
struct timespec

variable_types: wynik double

return_type: double


repo: mmishkov/Shell

decompiled_code:
void sig_handler()
{
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

waitpid(-1, stat_loc, 1);
}

canonical_decompiled_code:
void func0()
{
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

waitpid(-1, stat_loc, 1);
}

original_code:
void sig_handler()
{
    int status;
    waitpid(-1, &status, 1);
}

variable_types: status int


decompiled_code:
void kill_sig()
{
if ( saved_pid )
{
kill(saved_pid, 9);
saved_pid = 0;
}
}

canonical_decompiled_code:
void func1()
{
if ( saved_pid )
{
kill(saved_pid, 9);
saved_pid = 0;
}
}

original_code:
void kill_sig()
{
    if (saved_pid != 0) {
        kill (saved_pid,9);
        saved_pid = 0;
    }
}


decompiled_code:
int __fastcall print_error(const char *a1)
{
error = 1;
return fprintf(stderr, "myshell: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
error = 1;
return fprintf(stderr, "myshell: %s\n", a1);
}

original_code:
void print_error (char *string)
{
    error = 1;
    fprintf (stderr,"myshell: %s\n",string);
}

canonical_original_code:
void print_error(char *string)
{
    error = 1;
    fprintf (stderr,"myshell: %s\n",string);
}

variable_types:
string
char *


decompiled_code:
int __fastcall set_path(int *a1, __int64 a2, __int64 *a3)
{
__int64 *v3; // rcx
__int64 v4; // rax

v3 = (__int64 *)(a2 + 8LL * *a1 + 8);
if ( *v3 )
{
++*a1;
v4 = *v3;
*a3 = *v3;
}
else
{
LODWORD(v4) = print_error("syntax error");
}
return v4;
}

original_code:
void set_path (int *i, char **args, char **path)
{
    if (args[*i+1] != ((void *)0))
        *path = args[++(*i)];
    else
        print_error ("syntax error");
}

canonical_original_code:
void set_path(int *i, char **args, char **path)
{
    if (args[*i+1] != ((void *)0))
        *path = args[++(*i)];
    else
        print_error ("syntax error");
}

variable_types:
i
int *

variable_types:
args
char **

variable_types:
path
char **


original_code:
void separate_args (int *i, char **args, int has_paren)
{
    if (!has_paren) {
        int j = *i + 1;
        int count = 0;
        for (; args[j] != ((void *)0); j++) {
            count++;
        }
        args[(*i)++] = ((void *)0);
        savedargs = calloc (j + 1, sizeof (char *));
        ((void) sizeof ((savedargs != ((void *)0)) ? 1 : 0), __extension__ ({ if (savedargs != ((void *)0)) ; else __assert_fail ("savedargs != NULL", "myshell.c", 93, __extension__ __PRETTY_FUNCTION__); }));
        int k;
        for (k = 0; k < count; k++) {
            savedargs[k] = args[*i];
            args[(*i)++] = ((void *)0);
        }
        savedargs[k] = ((void *)0);
    }
}

canonical_original_code:
void separate_args(int *i, char **args, int has_paren)
{
    if (!has_paren) {
        int j = *i + 1;
        int count = 0;
        for (; args[j] != ((void *)0); j++) {
            count++;
        }
        args[(*i)++] = ((void *)0);
        savedargs = calloc (j + 1, sizeof (char *));
        ((void) sizeof ((savedargs != ((void *)0)) ? 1 : 0), __extension__ ({ if (savedargs != ((void *)0)) ; else __assert_fail ("savedargs != NULL", "myshell.c", 93, __extension__ __PRETTY_FUNCTION__); }));
        int k;
        for (k = 0; k < count; k++) {
            savedargs[k] = args[*i];
            args[(*i)++] = ((void *)0);
        }
        savedargs[k] = ((void *)0);
    }
}

variable_types: count int

variable_types: k int


decompiled_code:
const char *__fastcall remove_paren(int *a1, __int64 a2)
{
__int64 v2; // rdx
const char **v3; // r9
const char *result; // rax
const char **v5; // r8

v2 = 8LL * *a1;
v3 = (const char **)(a2 + v2);
result = *(const char **)(a2 + v2);
if ( result )
{
v5 = (const char **)(a2 + v2 + 8);
do
{
if ( !strcmp(result, "(") )
{
*v3 = " ";
}
else if ( !strcmp(result, ")") )
{
if ( *v5 )
*v3 = *v5;
else
*v3 = 0LL;
}
result = *v5++;
++v3;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func5(int *a1, __int64 a2)
{
__int64 v2; // rdx
const char **v3; // r9
const char *result; // rax
const char **v5; // r8

v2 = 8LL * *a1;
v3 = (const char **)(a2 + v2);
result = *(const char **)(a2 + v2);
if ( result )
{
v5 = (const char **)(a2 + v2 + 8);
do
{
if ( !strcmp(result, "(") )
{
*v3 = " ";
}
else if ( !strcmp(result, ")") )
{
if ( *v5 )
*v3 = *v5;
else
*v3 = 0LL;
}
result = *v5++;
++v3;
}
while ( result );
}
return result;
}

original_code:
void remove_paren (int *i, char **args)
{
    int j = *i;
    for (; args[j] != ((void *)0); j++) {
        if (strcmp (args[j], "(") == 0) {
            args[j] = " ";
        } else if (strcmp (args[j], ")") == 0) {
            if (args[j + 1] != ((void *)0)) {
                args[j] = args[j + 1];
            } else {
                args[j] = ((void *)0);
            }
        }
    }
}

canonical_original_code:
void remove_paren(int *i, char **args)
{
    int j = *i;
    for (; args[j] != ((void *)0); j++) {
        if (strcmp (args[j], "(") == 0) {
            args[j] = " ";
        } else if (strcmp (args[j], ")") == 0) {
            if (args[j + 1] != ((void *)0)) {
                args[j] = args[j + 1];
            } else {
                args[j] = ((void *)0);
            }
        }
    }
}

variable_types: j int


decompiled_code:
__int64 __fastcall special_char(int *a1, __int64 a2, int *a3, __int64 *a4)
{
char v4; // al
__int64 result; // rax

v4 = **(_BYTE **)(a2 + 8LL * *a1);
if ( v4 > 62 )
{
if ( v4 == 124 )
{
a3[4] = 1;
set_path(a1, a2, a4 + 2);
result = 1LL;
}
else
{
result = 0LL;
}
}
else if ( v4 <= 37 )
{
result = 0LL;
}
else
{
switch ( v4 )
{
case '&':
a3[5] = 1;
result = 1LL;
break;
case '(':
*a3 = 1;
remove_paren(a1, a2);
result = 1LL;
break;
case ')':
a3[1] = 1;
result = 1LL;
break;
case ';':
a3[6] = 1;
separate_args(a1, a2, *a3);
result = 1LL;
break;
case '<':
a3[2] = 1;
set_path(a1, a2, a4);
result = 1LL;
break;
case '>':
a3[3] = 1;
set_path(a1, a2, a4 + 1);
result = 1LL;
break;
default:
result = 0LL;
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int *a1, __int64 a2, int *a3, __int64 *a4)
{
char v4; // al
__int64 result; // rax

v4 = **(_BYTE **)(a2 + 8LL * *a1);
if ( v4 > 62 )
{
if ( v4 == 124 )
{
a3[4] = 1;
func3(a1, a2, a4 + 2);
result = 1LL;
}
else
{
result = 0LL;
}
}
else if ( v4 <= 37 )
{
result = 0LL;
}
else
{
switch ( v4 )
{
case '&':
a3[5] = 1;
result = 1LL;
break;
case '(':
*a3 = 1;
func5(a1, a2);
result = 1LL;
break;
case ')':
a3[1] = 1;
result = 1LL;
break;
case ';':
a3[6] = 1;
func4(a1, a2, *a3);
result = 1LL;
break;
case '<':
a3[2] = 1;
func3(a1, a2, a4);
result = 1LL;
break;
case '>':
a3[3] = 1;
func3(a1, a2, a4 + 1);
result = 1LL;
break;
default:
result = 0LL;
break;
}
}
return result;
}

original_code:
int special_char (int *i, char **args, specialflags *flags,
        specialpaths *paths)
{
    switch (args[*i][0]){
        case '(' : flags->left_paren = 1;
                   remove_paren (i, args); break;
        case ')' : flags->right_paren = 1; break;
                   remove_paren (i, args); break;
        case '<' : flags->file_in = 1;
                   set_path(i, args, &paths->path_in); break;
        case '>' : flags->file_out = 1;
                   set_path(i, args, &paths->path_out); break;
        case '|' : flags->pipe = 1;
                   set_path(i, args, &paths->path_pipe); break;
        case '&' : flags->background = 1; break;
        case ';' : flags->semi = 1;
                   separate_args (i, args, (int) flags->left_paren);
                   break;
        default : return 0;
    }
    return 1;
}

canonical_original_code:
int special_char(int *i, char **args, struct specialflags *flags, struct specialpaths *paths)
{
    switch (args[*i][0]){
        case '(' : flags->left_paren = 1;
                   remove_paren (i, args); break;
        case ')' : flags->right_paren = 1; break;
                   remove_paren (i, args); break;
        case '<' : flags->file_in = 1;
                   set_path(i, args, &paths->path_in); break;
        case '>' : flags->file_out = 1;
                   set_path(i, args, &paths->path_out); break;
        case '|' : flags->pipe = 1;
                   set_path(i, args, &paths->path_pipe); break;
        case '&' : flags->background = 1; break;
        case ';' : flags->semi = 1;
                   separate_args (i, args, (int) flags->left_paren);
                   break;
        default : return 0;
    }
    return 1;
}

variable_types: struct specialflags { int left_paren; int right_paren; int file_in; int file_out; int pipe; int background; int semi; } *

variable_types: struct specialpaths { char *path_in; char *path_out; char *path_pipe; } *


execute

decompiled_code:
int __fastcall execute(_DWORD *a1, const char **a2, const char **a3)
{
char *v4; // rdi
int result; // eax
unsigned int v6; // eax
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( !strcmp(*a3, "cd") )
{
v4 = (char *)a3[1];
if ( !v4 )
v4 = getenv("HOME");
result = chdir(v4);
if ( result == -1 )
result = printf("%s: %s: no such file or directory\n", *a3, a3[1]);
}
else
{
v6 = fork();
if ( v6 )
{
saved_pid = v6;
if ( a1[5] )
result = printf("Process %d in background.\n", v6);
else
result = waitpid(-1, stat_loc, 0);
}
else
{
if ( a1[5] )
setpgid(0, 0);
if ( a1[3] )
freopen(a2[1], "w", stdout);
if ( a1[2] )
freopen(*a2, "r", stdin);
result = execvp(*a3, (char *const *)a3);
if ( result )
{
printf("Command: %s not found\n", *a3);
exit(1);
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(_DWORD *a1, const char **a2, const char **a3)
{
char *v4; // rdi
int result; // eax
unsigned int v6; // eax
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( !strcmp(*a3, "cd") )
{
v4 = (char *)a3[1];
if ( !v4 )
v4 = getenv("HOME");
result = chdir(v4);
if ( result == -1 )
result = printf("%s: %s: no such file or directory\n", *a3, a3[1]);
}
else
{
v6 = fork();
if ( v6 )
{
saved_pid = v6;
if ( a1[5] )
result = printf("Process %d in background.\n", v6);
else
result = waitpid(-1, stat_loc, 0);
}
else
{
if ( a1[5] )
setpgid(0, 0);
if ( a1[3] )
freopen(a2[1], "w", stdout);
if ( a1[2] )
freopen(*a2, "r", stdin);
result = execvp(*a3, (char *const *)a3);
if ( result )
{
printf("Command: %s not found\n", *a3);
exit(1);
}
}
}
return result;
}

original_code:
void execute (specialflags *special_flags, specialpaths *special_paths,
        char **child_args)
{
    if (strcmp (child_args[0],"cd") == 0) {
        if (chdir((child_args[1] == ((void *)0)) ? getenv("HOME") :
                child_args[1]) == -1) {
            printf ("%s: %s: no such file or directory\n",
                    child_args[0], child_args[1]);
        }
    } else {
        pid_t pid = fork();
        if (pid == 0) {
            if (special_flags->background)
                setpgid (0, 0);
            if (special_flags->file_out) {
                freopen (special_paths->path_out, "w", stdout);
            }
            if (special_flags->file_in) {
                freopen (special_paths->path_in,"r",stdin);
            }
            if(execvp (child_args[0], child_args) != 0) {
                printf ("Command: %s not found\n", child_args[0]);
                exit(1);
            }
        } else {
            int status;
            saved_pid = pid;
            if (!special_flags->background)
                waitpid (-1, &status, 0);
            else {
                printf ("Process %d in background.\n", (int) pid);
            }
        }
    }
}

canonical_original_code:
void execute(struct specialflags *special_flags, struct specialpaths *special_paths, char **child_args)
{
    if (strcmp (child_args[0],"cd") == 0) {
        if (chdir((child_args[1] == ((void *)0)) ? getenv("HOME") :
                child_args[1]) == -1) {
            printf ("%s: %s: no such file or directory\n",
                    child_args[0], child_args[1]);
        }
    } else {
        int pid = fork();
        if (pid == 0) {
            if (special_flags->background)
                setpgid (0, 0);
            if (special_flags->file_out) {
                freopen (special_paths->path_out, "w", stdout);
            }
            if (special_flags->file_in) {
                freopen (special_paths->path_in,"r",stdin);
            }
            if(execvp (child_args[0], child_args) != 0) {
                printf ("Command: %s not found\n", child_args[0]);
                exit(1);
            }
        } else {
            int status;
            saved_pid = pid;
            if (!special_flags->background)
                waitpid (-1, &status, 0);
            else {
                printf ("Process %d in background.\n", (int) pid);
            }
        }
    }
}

variable_types: pid int

user_defined_types: struct specialflags { int left_paren; int right_paren; int file_in; int file_out; int pipe; int background; int semi; }

user_defined_types: struct specialpaths { char *path_in; char *path_out; char *path_pipe; }


decompiled_code:
__int64 __fastcall shell_cmd(const char **a1)
{
unsigned int v1; // edx

if ( !*a1 )
return 1;
v1 = 0;
if ( !strcmp(*a1, "exit") )
exit(0);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char **a1)
{
unsigned int v1; // edx

if ( !*a1 )
return 1;
v1 = 0;
if ( !strcmp(*a1, "exit") )
exit(0);
return v1;
}

original_code:
int shell_cmd (char **args)
{
    if (args[0] == ((void *)0)) return 1;
    if (strcmp (args[0],"exit") == 0) exit(0);
    return 0;
}

canonical_original_code:
int shell_cmd(char **args)
{
    if (args[0] == ((void *)0)) return 1;
    if (strcmp (args[0],"exit") == 0) exit(0);
    return 0;
}


decompiled_code:
void __fastcall exec_shell(int a1)
{
int v1; // er12
int v2; // er13
const char **v3; // rbx
const char *v4; // rdx
__int64 i; // rax
const char **v6; // rbp
int v7; // ebp
const char **v8; // rax
const char **v9; // r14
char v10[1024]; // [rsp+0h] [rbp-468h] BYREF
const char *v11[4]; // [rsp+400h] [rbp-68h] BYREF
__int64 v12[3]; // [rsp+420h] [rbp-48h] BYREF
int v13; // [rsp+438h] [rbp-30h]

v1 = a1;
v12[0] = 0LL;
v12[1] = 0LL;
v12[2] = 0LL;
v13 = 0;
v11[0] = 0LL;
v11[1] = 0LL;
v11[2] = 0LL;
error = 0;
v2 = 0;
if ( !a1 )
{
v2 = 1;
v1 = 1;
}
do
{
getcwd(v10, 0x400uLL);
v6 = (const char **)savedargs;
if ( savedargs )
{
v3 = (const char **)malloc(0x40uLL);
if ( !v3 )
_assert_fail("args != NULL", "myshell.c", 0x13Au, "exec_shell");
v4 = *v6;
for ( i = 0LL; v4; v4 = v6[i] )
v3[i++] = v4;
v3[i] = 0LL;
savedargs = 0LL;
free_args = 1;
}
else
{
printf("\n$ ");
v3 = (const char **)get_line();
}
v7 = shell_cmd(v3);
if ( !v7 )
{
v8 = (const char **)malloc(0x40uLL);
v9 = v8;
if ( !v8 )
_assert_fail("child_args != NULL", "myshell.c", 0x14Au, "exec_shell");
parse_args((int *)v12, (__int64 *)v11, v3, (__int64)v8);
if ( LODWORD(v12[0]) )
{
savedargs = (__int64)v9;
exec_shell(0LL);
chdir(v10);
v2 = v7;
}
else
{
execute(v12, v11, v9);
if ( v2 && !v13 )
v1 = 0;
}
reset_flags(v12);
error = 0;
if ( free_args )
free_args = 0;
}
}
while ( v1 );
}

canonical_decompiled_code:
void __fastcall func11(int a1)
{
int v1; // er12
int v2; // er13
const char **v3; // rbx
const char *v4; // rdx
__int64 i; // rax
const char **v6; // rbp
int v7; // ebp
const char **v8; // rax
const char **v9; // r14
char v10[1024]; // [rsp+0h] [rbp-468h] BYREF
const char *v11[4]; // [rsp+400h] [rbp-68h] BYREF
__int64 v12[3]; // [rsp+420h] [rbp-48h] BYREF
int v13; // [rsp+438h] [rbp-30h]

v1 = a1;
v12[0] = 0LL;
v12[1] = 0LL;
v12[2] = 0LL;
v13 = 0;
v11[0] = 0LL;
v11[1] = 0LL;
v11[2] = 0LL;
error = 0;
v2 = 0;
if ( !a1 )
{
v2 = 1;
v1 = 1;
}
do
{
getcwd(v10, 0x400uLL);
v6 = (const char **)savedargs;
if ( savedargs )
{
v3 = (const char **)malloc(0x40uLL);
if ( !v3 )
_assert_fail("args != NULL", "myshell.c", 0x13Au, "exec_shell");
v4 = *v6;
for ( i = 0LL; v4; v4 = v6[i] )
v3[i++] = v4;
v3[i] = 0LL;
savedargs = 0LL;
free_args = 1;
}
else
{
printf("\n$ ");
v3 = (const char **)get_line();
}
v7 = func10(v3);
if ( !v7 )
{
v8 = (const char **)malloc(0x40uLL);
v9 = v8;
if ( !v8 )
_assert_fail("child_args != NULL", "myshell.c", 0x14Au, "exec_shell");
func8((int *)v12, (__int64 *)v11, v3, (__int64)v8);
if ( LODWORD(v12[0]) )
{
savedargs = (__int64)v9;
func11(0LL);
chdir(v10);
v2 = v7;
}
else
{
func9(v12, v11, v9);
if ( v2 && !v13 )
v1 = 0;
}
func7(v12);
error = 0;
if ( free_args )
free_args = 0;
}
}
while ( v1 );
}

original_code:
void exec_shell (int loop)
{
    int terminate = 0;
    char **args;
    char *prompt = "\n$ ";
    specialflags special_flags = {0,0,0,0,0,0,0};
    specialpaths special_paths = {((void *)0),((void *)0),((void *)0)};
    error = 0;
    if (loop == 0) {
        terminate = 1;
        loop = 1;
    }
    while (loop) {
        char cwd[1024];
        getcwd(cwd, sizeof (cwd));
        if (savedargs == ((void *)0)) {
            printf (prompt);
            args = get_line();
        } else {
            args = malloc (sizeof (savedargs) * sizeof (char *));
            ((void) sizeof ((args != ((void *)0)) ? 1 : 0), __extension__ ({ if (args != ((void *)0)) ; else __assert_fail ("args != NULL", "myshell.c", 314, __extension__ __PRETTY_FUNCTION__); }));
            int i;
            for(i = 0; savedargs[i] != ((void *)0); i++) {
                args[i] = savedargs[i];
            }
            args[i] = ((void *)0);
            savedargs = ((void *)0);
            free_args = 1;
        }
        if (shell_cmd (args)) continue;
        char **child_args = malloc (sizeof (args) * sizeof (char *));
        ((void) sizeof ((child_args != ((void *)0)) ? 1 : 0), __extension__ ({ if (child_args != ((void *)0)) ; else __assert_fail ("child_args != NULL", "myshell.c", 330, __extension__ __PRETTY_FUNCTION__); }));
        parse_args (&special_flags, &special_paths, args, child_args);
        if (special_flags.left_paren) {
            int one_loop = 0;
            savedargs = child_args;
            exec_shell (one_loop);
            chdir (cwd);
            terminate = 0;
        } else {
            execute (&special_flags, &special_paths, child_args);
        }
        if (terminate && !special_flags.semi) {
            loop = 0;
        }
        reset_flags (&special_flags);
        error = 0;
        if (free_args) {
            free_args = 0;
            args = ((void *)0);
        }
        child_args = ((void *)0);
    }
}

canonical_original_code:
void exec_shell(int loop)
{
    int terminate = 0;
    char **args;
    char *prompt = "\n$ ";
    struct specialflags special_flags = {0,0,0,0,0,0,0};
    struct specialpaths special_paths = {((void *)0),((void *)0),((void *)0)};
    error = 0;
    if (loop == 0) {
        terminate = 1;
        loop = 1;
    }
    while (loop) {
        char cwd[1024];
        getcwd(cwd, sizeof (cwd));
        if (savedargs == ((void *)0)) {
            printf (prompt);
            args = get_line();
        } else {
            args = malloc (sizeof (savedargs) * sizeof (char *));
            ((void) sizeof ((args != ((void *)0)) ? 1 : 0), __extension__ ({ if (args != ((void *)0)) ; else __assert_fail ("args != NULL", "myshell.c", 314, __extension__ __PRETTY_FUNCTION__); }));
            int i;
            for(i = 0; savedargs[i] != ((void *)0); i++) {
                args[i] = savedargs[i];
            }
            args[i] = ((void *)0);
            savedargs = ((void *)0);
            free_args = 1;
        }
        if (shell_cmd (args)) continue;
        char **child_args = malloc (sizeof (args) * sizeof (char *));
        ((void) sizeof ((child_args != ((void *)0)) ? 1 : 0), __extension__ ({ if (child_args != ((void *)0)) ; else __assert_fail ("child_args != NULL", "myshell.c", 330, __extension__ __PRETTY_FUNCTION__); }));
        parse_args (&special_flags, &special_paths, args, child_args);
        if (special_flags.left_paren) {
            int one_loop = 0;
            savedargs = child_args;
            exec_shell (one_loop);
            chdir (cwd);
            terminate = 0;
        } else {
            execute (&special_flags, &special_paths, child_args);
        }
        if (terminate && !special_flags.semi) {
            loop = 0;
        }
        reset_flags (&special_flags);
        error = 0;
        if (free_args) {
            free_args = 0;
            args = ((void *)0);
        }
        child_args = ((void *)0);
    }
}

variable_types: loop int

variable_types: terminate int

variable_types:
prompt
char *

variable_types: struct specialflags { int left_paren; int right_paren; int file_in; int file_out; int pipe; int background; int semi; }

variable_types: struct specialpaths { char *path_in; char *path_out; char *path_pipe; }

variable_types:
cwd
char [1024]

variable_types: i int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
signal(2, (__sighandler_t)kill_sig);
signal(17, (__sighandler_t)sig_handler);
exec_shell(1);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
signal(2, (__sighandler_t)kill_sig);
signal(17, (__sighandler_t)sig_handler);
func11(1);
exit(0);
}

original_code:
int main()
{
    int loop = 1;
    signal (2, kill_sig);
    signal (17, sig_handler);
    exec_shell (loop);
    exit (0);
}


Elections

repo: mmsi/dbes

decompiled_code:
__int64 Elections()
{
Driver(0LL, &e_message_array, &e_msg_id);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
Driver(0LL, &e_message_array, &e_msg_id);
return 0LL;
}

original_code:
int Elections()
{
 int ret;
 ret = Driver(0, e_message_array, &e_msg_id);
 return 0;
}

variable_types: ret int


JackDatabase

decompiled_code:
__int64 JackDatabase()
{
__int64 v0; // rax
int v1; // edx
__int64 v2; // rbx

jack_lookup_table = local_id;
++active;
printf("local id = %i\n", (unsigned int)local_id);
do
{
if ( (unsigned int)Driver(1LL, &e_message_array, &e_msg_id) )
puts("CAN error...");
if ( e_msg_id == 2 )
{
v0 = 1LL;
do
{
v1 = v0 - 1;
if ( (unsigned __int8)e_message_array == *((_DWORD *)&jack_lookup_table + v0 - 1) )
break;
v1 = v0++;
}
while ( *((_DWORD *)&jack_lookup_table + v0 - 1) );
v2 = v1;
printf("found jack #%i", *((unsigned int *)&jack_lookup_table + v1));
printf(" jack address: %i\n", (unsigned __int8)e_message_array);
*((_DWORD *)&jack_lookup_table + v2) = (unsigned __int8)e_message_array;
++active;
e_msg_id = 11LL;
Driver(2LL, &e_message_array, &e_msg_id);
}
else if ( e_msg_id == 7 )
{
master_flag = 1;
}
}
while ( e_message_array );
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
int v1; // edx
__int64 v2; // rbx

jack_lookup_table = local_id;
++active;
printf("local id = %i\n", (unsigned int)local_id);
do
{
if ( (unsigned int)Driver(1LL, &e_message_array, &e_msg_id) )
puts("CAN error...");
if ( e_msg_id == 2 )
{
v0 = 1LL;
do
{
v1 = v0 - 1;
if ( (unsigned __int8)e_message_array == *((_DWORD *)&jack_lookup_table + v0 - 1) )
break;
v1 = v0++;
}
while ( *((_DWORD *)&jack_lookup_table + v0 - 1) );
v2 = v1;
printf("found jack #%i", *((unsigned int *)&jack_lookup_table + v1));
printf(" jack address: %i\n", (unsigned __int8)e_message_array);
*((_DWORD *)&jack_lookup_table + v2) = (unsigned __int8)e_message_array;
++active;
e_msg_id = 11LL;
Driver(2LL, &e_message_array, &e_msg_id);
}
else if ( e_msg_id == 7 )
{
master_flag = 1;
}
}
while ( e_message_array );
return 0LL;
}

original_code:
int JackDatabase()
{
 int i;
 int ret;
 jack_lookup_table[0] = local_id;
 active++;
 printf("local id = %i\n", local_id);
 do {
  ret = Driver(1, &e_message_array[0], &e_msg_id);
  if (ret != 0)
   printf("CAN error...\n");
  switch (e_msg_id) {
   case 7:
    master_flag = 1;
    break;
   case 2:
    i = 0;
    do {
     if (e_message_array[0] == jack_lookup_table[i]) {
      break;
     }
     i++;
    } while(jack_lookup_table[i] != 0);
    printf("found jack #%i", jack_lookup_table[i]);
    printf("   jack address: %i\n", e_message_array[0]);
    jack_lookup_table[i] = e_message_array[0];
    active++;
    e_msg_id = 11;
    Driver(2, &e_message_array[0], &e_msg_id);
  }
 } while(e_message_array[0] != 0);
 return 0;
}


Broadcast

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

do
{
e_message_array = local_id;
e_msg_id = 2LL;
Driver(2LL, &e_message_array, &e_msg_id);
sleep(1u);
result = Driver(1LL, &e_message_array, &e_msg_id);
if ( e_msg_id == 11 )
break;
result = (unsigned int)local_id;
}
while ( (unsigned __int8)e_message_array != (_DWORD)result );
return result;
}

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

do
{
e_message_array = local_id;
e_msg_id = 2LL;
Driver(2LL, &e_message_array, &e_msg_id);
sleep(1u);
result = Driver(1LL, &e_message_array, &e_msg_id);
if ( e_msg_id == 11 )
break;
result = (unsigned int)local_id;
}
while ( (unsigned __int8)e_message_array != (_DWORD)result );
return result;
}

original_code:
int Broadcast(void)
{
 do {
  e_message_array[0] = local_id;
  e_msg_id = 2;
  Driver(2, &e_message_array[0], &e_msg_id);
  sleep(1);
  Driver(1, &e_message_array[0], &e_msg_id);
 } while ((e_msg_id != 11) && (e_message_array[0] != local_id));
}

canonical_original_code:
int Broadcast()
{
 do {
  e_message_array[0] = local_id;
  e_msg_id = 2;
  Driver(2, &e_message_array[0], &e_msg_id);
  sleep(1);
  Driver(1, &e_message_array[0], &e_msg_id);
 } while ((e_msg_id != 11) && (e_message_array[0] != local_id));
}


decompiled_code:
__int64 __fastcall Hyd_Control(unsigned __int64 a1)
{
char v1; // al
unsigned __int64 v2; // rdi
char v3; // al

v1 = a1;
v2 = HIDWORD(a1);
if ( v1 < 0 )
{
Dout(0LL, 0LL);
PWM(0LL, 0LL);
Dout(16LL, 1LL);
}
else
{
v3 = v1 & 6;
switch ( v3 )
{
case 2:
Dout(4LL, 1LL);
Dout(2LL, 0LL);
Dout(1LL, 1LL);
Dout(8LL, 1LL);
PWM((unsigned __int8)v2, 2LL);
break;
case 4:
Dout(4LL, 1LL);
Dout(2LL, 1LL);
Dout(1LL, 0LL);
Dout(8LL, 1LL);
PWM((unsigned __int8)v2, 2LL);
break;
case 0:
Dout(4LL, 0LL);
Dout(2LL, 0LL);
Dout(8LL, 0LL);
PWM(0LL, 1LL);
break;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1)
{
char v1; // al
unsigned __int64 v2; // rdi
char v3; // al

v1 = a1;
v2 = HIDWORD(a1);
if ( v1 < 0 )
{
Dout(0LL, 0LL);
PWM(0LL, 0LL);
Dout(16LL, 1LL);
}
else
{
v3 = v1 & 6;
switch ( v3 )
{
case 2:
Dout(4LL, 1LL);
Dout(2LL, 0LL);
Dout(1LL, 1LL);
Dout(8LL, 1LL);
PWM((unsigned __int8)v2, 2LL);
break;
case 4:
Dout(4LL, 1LL);
Dout(2LL, 1LL);
Dout(1LL, 0LL);
Dout(8LL, 1LL);
PWM((unsigned __int8)v2, 2LL);
break;
case 0:
Dout(4LL, 0LL);
Dout(2LL, 0LL);
Dout(8LL, 0LL);
PWM(0LL, 1LL);
break;
}
}
return 0LL;
}

original_code:
int Hyd_Control(struct cnt_template_t control)
{
 if ((control.function & 0x0080) == 0x80) {
  Dout(0, 0);
  PWM(0, 0);
  Dout(16, 1);
  return 0;
 }
 switch (control.function & 0x0006) {
  case 0x0:
   Dout(4, 0);
   Dout(2, 0);
   Dout(8, 0);
   PWM(0, 1);
   break;
  case 0x2:
   Dout(4, 1);
   Dout(2, 0);
   Dout(1, 1);
   Dout(8, 1);
   PWM(control.rate, 2);
   break;
  case 0x4:
   Dout(4, 1);
   Dout(2, 1);
   Dout(1, 0);
   Dout(8, 1);
   PWM(control.rate, 2);
 }
 return 0;
}

variable_types: struct cnt_template_t { unsigned char function; unsigned char id; short dest; unsigned char rate; }


kbhit

decompiled_code:
__int64 kbhit()
{
fd_set v1; // [rsp+0h] [rbp-98h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-18h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
memset(&v1, 0, sizeof(v1));
v1.fds_bits[0] |= 1uLL;
select(1, &v1, 0LL, 0LL, &timeout);
return v1.fds_bits[0] & 1;
}

canonical_decompiled_code:
__int64 func0()
{
fd_set v1; // [rsp+0h] [rbp-98h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-18h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
memset(&v1, 0, sizeof(v1));
v1.fds_bits[0] |= 1uLL;
select(1, &v1, 0LL, 0LL, &timeout);
return v1.fds_bits[0] & 1;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
fds
struct fd_set { long __fds_bits[-1]; }


Nonblock

decompiled_code:
int __fastcall Nonblock(int a1)
{
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, &v2);
if ( a1 == 1 )
{
v2.c_lflag &= 0xFFFFFFFD;
v2.c_cc[6] = 1;
v2.c_cc[5] = 2;
}
else if ( a1 == 2 )
{
v2.c_lflag |= 2u;
}
return tcsetattr(0, 0, &v2);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, &v2);
if ( a1 == 1 )
{
v2.c_lflag &= 0xFFFFFFFD;
v2.c_cc[6] = 1;
v2.c_cc[5] = 2;
}
else if ( a1 == 2 )
{
v2.c_lflag |= 2u;
}
return tcsetattr(0, 0, &v2);
}

original_code:
void Nonblock(int state)
{
    struct termios ttystate;
 tcgetattr(0, &ttystate);
    if (state==1)
    {
  ttystate.c_lflag &= ~0000002;
        ttystate.c_cc[6] = 1;
  ttystate.c_cc[5] = 2;
    } else if (state==2) {
        ttystate.c_lflag |= 0000002;
    }
    tcsetattr(0, 0, &ttystate);
}

variable_types: state int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


UI

decompiled_code:
__int64 __fastcall UI(int a1, __int64 a2, __int16 *a3)
{
time_t v4; // rbx
time_t v5; // rdi
int v6; // eax
char v7; // al
__int16 *v8; // rbx
unsigned __int16 *v9; // rbx
unsigned __int16 *v10; // r14
unsigned __int16 *v11; // r13
float v12; // xmm2_4
char v13; // al
char v15; // al
float v16; // [rsp+0h] [rbp-2Ch]

if ( a1 != 1 )
{
if ( !block_status_3 )
{
Nonblock(1);
block_status_3 = 1;
}
v4 = updatetv_2;
v5 = time(0LL);
if ( difftime(v5, v4) > 2.0 )
{
system("clear");
puts("\t\t| 1\t| 2\t| 3\t| 4\t| 5\t| 6\t| 7\t| 8\t| 9\t| 10\t|");
printf(" height (in)\t|");
v8 = a3;
do
{
printf(" %5.2f\t|", (float)((float)((float)*v8 - (float)v8[1]) / 100.0));
v8 += 4;
}
while ( a3 + 40 != v8 );
printf("\n pressure\t|");
v9 = (unsigned __int16 *)(a3 + 2);
v10 = (unsigned __int16 *)(a3 + 42);
v11 = (unsigned __int16 *)(a3 + 2);
do
{
printf(" %i\t|", *v11);
v11 += 4;
}
while ( v10 != v11 );
printf("\n weight (lbs)\t|");
do
{
printf(" %6.2f\t|", (double)*v9 * 12.5664);
v9 += 4;
}
while ( v10 != v9 );
if ( !active )
{
v12 = (double)(unsigned __int16)a3[2] * 12.5664 + 0.0;
v16 = v12;
}
printf("\n\n Total Weight: %5.1f\t\tLift Rate: %u", v16, *(unsigned __int8 *)(a2 + 4));
printf(" raw\tDestination:%5.2f inches", (float)((float)*(__int16 *)(a2 + 2) / 100.0));
time(&updatetv_2);
updated_1 = 1;
if ( (*(_BYTE *)a2 & 8) != 0 )
{
puts("\n\n\n------MANUAL CONTROL------");
puts("\nsetting zero postion:");
puts("jacks must not be moving. press <z> then follow instructions");
puts("to return to automatic control press <space>");
LABEL_6:
if ( (unsigned int)kbhit() )
{
v6 = fgetc(stdin);
if ( v6 == 32 )
{
LABEL_13:
ui = 0;
}
else if ( v6 == 122 )
{
Nonblock(2);
puts("set system to zero? <y/n>");
while ( 1 )
{
v7 = getchar();
if ( v7 == 121 )
break;
if ( v7 == 110 )
{
Nonblock(1);
goto LABEL_13;
}
}
Nonblock(1);
ui |= 0x20u;
}
}
return 0LL;
}
puts("\n\n\n_Key Commands________________________________");
puts("| START/STOP ------------------ spacebar");
puts("| change [D]irection ------------ d");
puts("| adjust destination (.01) ---- q: up a: down");
puts("| adjust destination (.1) ----- w: up s: down");
puts("| [R]eset destination ----------- r");
puts("| adjust [L]ift rate ------------ l <rate> enter");
puts("| enter [M]anual control -------- m");
puts("| setup jack layo[U]t ----------- u\n");
if ( lift_flag_0 )
puts(" Lifting mode active\n");
else
puts(" Lowering mode active\n");
v13 = *(_BYTE *)a2 & 6;
switch ( v13 )
{
case 2:
puts(" Status: ...lifting");
break;
case 4:
puts(" Status: ...lowering");
break;
case 0:
puts(" Status: ...holding load");
break;
}
}
else
{
updated_1 = 0;
if ( (*(_BYTE *)a2 & 8) != 0 )
goto LABEL_6;
}
if ( (unsigned int)kbhit() && getchar() == 32 )
{
v15 = *(_BYTE *)a2 & 6;
switch ( v15 )
{
case 2:
ui &= 0xFDu;
lift_flag_0 = 1;
break;
case 4:
ui &= 0xFBu;
lift_flag_0 = 0;
break;
case 0:
if ( lift_flag_0 == 1 )
ui |= 2u;
else
ui |= 4u;
break;
}
}
return 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2, __int16 *a3)
{
time_t v4; // rbx
time_t v5; // rdi
int v6; // eax
char v7; // al
__int16 *v8; // rbx
unsigned __int16 *v9; // rbx
unsigned __int16 *v10; // r14
unsigned __int16 *v11; // r13
float v12; // xmm2_4
char v13; // al
char v15; // al
float v16; // [rsp+0h] [rbp-2Ch]

if ( a1 != 1 )
{
if ( !block_status_3 )
{
func1(1);
block_status_3 = 1;
}
v4 = updatetv_2;
v5 = time(0LL);
if ( difftime(v5, v4) > 2.0 )
{
system("clear");
puts("\t\t| 1\t| 2\t| 3\t| 4\t| 5\t| 6\t| 7\t| 8\t| 9\t| 10\t|");
printf(" height (in)\t|");
v8 = a3;
do
{
printf(" %5.2f\t|", (float)((float)((float)*v8 - (float)v8[1]) / 100.0));
v8 += 4;
}
while ( a3 + 40 != v8 );
printf("\n pressure\t|");
v9 = (unsigned __int16 *)(a3 + 2);
v10 = (unsigned __int16 *)(a3 + 42);
v11 = (unsigned __int16 *)(a3 + 2);
do
{
printf(" %i\t|", *v11);
v11 += 4;
}
while ( v10 != v11 );
printf("\n weight (lbs)\t|");
do
{
printf(" %6.2f\t|", (double)*v9 * 12.5664);
v9 += 4;
}
while ( v10 != v9 );
if ( !active )
{
v12 = (double)(unsigned __int16)a3[2] * 12.5664 + 0.0;
v16 = v12;
}
printf("\n\n Total Weight: %5.1f\t\tLift Rate: %u", v16, *(unsigned __int8 *)(a2 + 4));
printf(" raw\tDestination:%5.2f inches", (float)((float)*(__int16 *)(a2 + 2) / 100.0));
time(&updatetv_2);
updated_1 = 1;
if ( (*(_BYTE *)a2 & 8) != 0 )
{
puts("\n\n\n------MANUAL CONTROL------");
puts("\nsetting zero postion:");
puts("jacks must not be moving. press <z> then follow instructions");
puts("to return to automatic control press <space>");
LABEL_6:
if ( (unsigned int)func0() )
{
v6 = fgetc(stdin);
if ( v6 == 32 )
{
LABEL_13:
ui = 0;
}
else if ( v6 == 122 )
{
func1(2);
puts("set system to zero? <y/n>");
while ( 1 )
{
v7 = getchar();
if ( v7 == 121 )
break;
if ( v7 == 110 )
{
func1(1);
goto LABEL_13;
}
}
func1(1);
ui |= 0x20u;
}
}
return 0LL;
}
puts("\n\n\n_Key Commands________________________________");
puts("| START/STOP ------------------ spacebar");
puts("| change [D]irection ------------ d");
puts("| adjust destination (.01) ---- q: up a: down");
puts("| adjust destination (.1) ----- w: up s: down");
puts("| [R]eset destination ----------- r");
puts("| adjust [L]ift rate ------------ l <rate> enter");
puts("| enter [M]anual control -------- m");
puts("| setup jack layo[U]t ----------- u\n");
if ( lift_flag_0 )
puts(" Lifting mode active\n");
else
puts(" Lowering mode active\n");
v13 = *(_BYTE *)a2 & 6;
switch ( v13 )
{
case 2:
puts(" Status: ...lifting");
break;
case 4:
puts(" Status: ...lowering");
break;
case 0:
puts(" Status: ...holding load");
break;
}
}
else
{
updated_1 = 0;
if ( (*(_BYTE *)a2 & 8) != 0 )
goto LABEL_6;
}
if ( (unsigned int)func0() && getchar() == 32 )
{
v15 = *(_BYTE *)a2 & 6;
switch ( v15 )
{
case 2:
ui &= 0xFDu;
lift_flag_0 = 1;
break;
case 4:
ui &= 0xFBu;
lift_flag_0 = 0;
break;
case 0:
if ( lift_flag_0 == 1 )
ui |= 2u;
else
ui |= 4u;
break;
}
}
return 0LL;
}
return 0LL;
}

original_code:
int UI(int mode, struct cnt_template_t *control, struct status_t *status_table)
{
 char c;
 int i;
 static int lift_flag;
 static int block_status, updated;
 float total_weight;
 static time_t updatetv;
 if (mode == 1)
  return 0;
 if (block_status == 0) {
  Nonblock(1);
  block_status = 1;
 }
 if ((difftime(time(((void *)0)), updatetv)) > 2) {
  system("clear");
  printf("\t\t|   1\t|   2\t|   3\t|   4\t|   5\t|   6\t|   7\t|   8\t|   9\t|   10\t|\n");
  printf(" height (in)\t|");
  for (i=0; i<10; i++) {
   printf(" %5.2f\t|", (((float)status_table[i].elevation)-(float)status_table[i].offset)/100);
  }
  printf("\n pressure\t|");
  for (i=0; i<10; i++) {
   printf(" %i\t|", status_table[i].pressure);
  }
  printf("\n weight (lbs)\t|");
  for (i=0; i<10; i++) {
   printf(" %6.2f\t|", ((status_table[i].pressure) * 12.5664));
  }
  for (i = 0; i == active; i++) {
   total_weight = (total_weight + (status_table[i].pressure * 12.5664));
  }
  printf("\n\n Total Weight: %5.1f\t\tLift Rate: %u", total_weight, control->rate);
  printf(" raw\tDestination:%5.2f inches", ((float)control->dest)/100);
  time(&updatetv);
  updated = 1;
 } else
  updated = 0;
 if ((control->function & 0x8) == 0x8) {
  if (updated == 1) {
   printf("\n\n\n------MANUAL CONTROL------\n");
   printf("\nsetting zero postion:\n");
   printf("jacks must not be moving. press <z> then follow instructions\n");
   printf("to return to automatic control press <space>\n");
  }
  if (1) {
   if (kbhit() != 0) {
    switch (fgetc(stdin)) {
     case 'z':
      Nonblock(2);
      printf("set system to zero? <y/n>\n");
      do {
       c = getchar();
       if (c == 'y') {
        Nonblock(1);
        ui.function |= 0x20;
        return 0;
       } else if (c == 'n') {
        Nonblock(1);
        break;
       }
      } while ((c != 'y') && (c != 'n'));
     case '\x20':
      ui.function = 0;
    }
   }
  }
 return 0;
 }
 if (updated == 1) {
  printf("\n\n\n_Key Commands________________________________\n");
  printf("| START/STOP ------------------ spacebar\n");
  printf("| change [D]irection ------------ d\n");
  printf("| adjust destination (.01) ---- q: up    a: down\n");
  printf("| adjust destination (.1) ----- w: up    s: down\n");
  printf("| [R]eset destination ----------- r\n");
  printf("| adjust [L]ift rate ------------ l <rate> enter\n");
  printf("| enter [M]anual control -------- m\n");
  printf("| setup jack layo[U]t ----------- u\n\n");
  if (lift_flag == 0)
   printf(" Lowering mode active\n\n");
  else
   printf(" Lifting mode active\n\n");
  switch (control->function & 0x6) {
   case 0x0:
    printf(" Status: ...holding load\n");
    break;
   case 0x2:
    printf(" Status: ...lifting\n");
    break;
   case 0x4:
    printf(" Status: ...lowering\n");
  }
 }
 if (kbhit() != 0) {
  switch (getchar()) {
   case '\x20':
    switch (control->function & 0x6) {
     case 0x0:
      if (lift_flag == 1)
       ui.function |= 0x2;
      else
       ui.function |= 0x4;
      break;
     case 0x2:
      ui.function &= ~0x2;
      lift_flag = 1;
      break;
     case 0x4:
      ui.function &= ~0x4;
      lift_flag = 0;
    }
    break;
   case 'd':
    lift_flag = ((~lift_flag) & 0x1);
    if ((control->function & 0x6)== 0x2) {
     ui.function = 0x4;
     lift_flag = 0;
    } else if ((control->function & 0x6) == 0x4) {
     ui.function = 0x2;
     lift_flag = 1;
    } else
     break;
   case 'l':
    break;
   case 'm':
    ui.function = 0x8;
    break;
   case 'q':
    ui.dest++;
    break;
   case 'a':
    ui.dest--;
    break;
   case 'w':
    ui.dest += 10;
    break;
   case 's':
    ui.dest -= 10;
    break;
   case 'r':
    ui.dest = 0;
    break;
   case 'u':
    ui.function = 0x40;
    Nonblock(2);
    block_status = 0;
    break;
  }
 }
 return 0;
}

canonical_original_code:
int UI(int mode, struct cnt_template_t *control, struct status_t *status_table)
{
 char c;
 int i;
 static int lift_flag;
 static int block_status; static int updated;
 float total_weight;
 static long updatetv;
 if (mode == 1)
  return 0;
 if (block_status == 0) {
  Nonblock(1);
  block_status = 1;
 }
 if ((difftime(time(((void *)0)), updatetv)) > 2) {
  system("clear");
  printf("\t\t|   1\t|   2\t|   3\t|   4\t|   5\t|   6\t|   7\t|   8\t|   9\t|   10\t|\n");
  printf(" height (in)\t|");
  for (i=0; i<10; i++) {
   printf(" %5.2f\t|", (((float)status_table[i].elevation)-(float)status_table[i].offset)/100);
  }
  printf("\n pressure\t|");
  for (i=0; i<10; i++) {
   printf(" %i\t|", status_table[i].pressure);
  }
  printf("\n weight (lbs)\t|");
  for (i=0; i<10; i++) {
   printf(" %6.2f\t|", ((status_table[i].pressure) * 12.5664));
  }
  for (i = 0; i == active; i++) {
   total_weight = (total_weight + (status_table[i].pressure * 12.5664));
  }
  printf("\n\n Total Weight: %5.1f\t\tLift Rate: %u", total_weight, control->rate);
  printf(" raw\tDestination:%5.2f inches", ((float)control->dest)/100);
  time(&updatetv);
  updated = 1;
 } else
  updated = 0;
 if ((control->function & 0x8) == 0x8) {
  if (updated == 1) {
   printf("\n\n\n------MANUAL CONTROL------\n");
   printf("\nsetting zero postion:\n");
   printf("jacks must not be moving. press <z> then follow instructions\n");
   printf("to return to automatic control press <space>\n");
  }
  if (1) {
   if (kbhit() != 0) {
    switch (fgetc(stdin)) {
     case 'z':
      Nonblock(2);
      printf("set system to zero? <y/n>\n");
      do {
       c = getchar();
       if (c == 'y') {
        Nonblock(1);
        ui.function |= 0x20;
        return 0;
       } else if (c == 'n') {
        Nonblock(1);
        break;
       }
      } while ((c != 'y') && (c != 'n'));
     case '\x20':
      ui.function = 0;
    }
   }
  }
 return 0;
 }
 if (updated == 1) {
  printf("\n\n\n_Key Commands________________________________\n");
  printf("| START/STOP ------------------ spacebar\n");
  printf("| change [D]irection ------------ d\n");
  printf("| adjust destination (.01) ---- q: up    a: down\n");
  printf("| adjust destination (.1) ----- w: up    s: down\n");
  printf("| [R]eset destination ----------- r\n");
  printf("| adjust [L]ift rate ------------ l <rate> enter\n");
  printf("| enter [M]anual control -------- m\n");
  printf("| setup jack layo[U]t ----------- u\n\n");
  if (lift_flag == 0)
   printf(" Lowering mode active\n\n");
  else
   printf(" Lifting mode active\n\n");
  switch (control->function & 0x6) {
   case 0x0:
    printf(" Status: ...holding load\n");
    break;
   case 0x2:
    printf(" Status: ...lifting\n");
    break;
   case 0x4:
    printf(" Status: ...lowering\n");
  }
 }
 if (kbhit() != 0) {
  switch (getchar()) {
   case '\x20':
    switch (control->function & 0x6) {
     case 0x0:
      if (lift_flag == 1)
       ui.function |= 0x2;
      else
       ui.function |= 0x4;
      break;
     case 0x2:
      ui.function &= ~0x2;
      lift_flag = 1;
      break;
     case 0x4:
      ui.function &= ~0x4;
      lift_flag = 0;
    }
    break;
   case 'd':
    lift_flag = ((~lift_flag) & 0x1);
    if ((control->function & 0x6)== 0x2) {
     ui.function = 0x4;
     lift_flag = 0;
    } else if ((control->function & 0x6) == 0x4) {
     ui.function = 0x2;
     lift_flag = 1;
    } else
     break;
   case 'l':
    break;
   case 'm':
    ui.function = 0x8;
    break;
   case 'q':
    ui.dest++;
    break;
   case 'a':
    ui.dest--;
    break;
   case 'w':
    ui.dest += 10;
    break;
   case 's':
    ui.dest -= 10;
    break;
   case 'r':
    ui.dest = 0;
    break;
   case 'u':
    ui.function = 0x40;
    Nonblock(2);
    block_status = 0;
    break;
  }
 }
 return 0;
}

variable_types: mode int

variable_types: struct cnt_template_t { unsigned char function; unsigned char id; short dest; unsigned char rate; } *

variable_types: struct status_t { short elevation; short offset; unsigned short pressure; unsigned char d_input; } *

variable_types: c char

variable_types: updated int

variable_types: updatetv long


decompiled_code:
int __fastcall can_fd_wait(int a1, int a2)
{
fd_set v3; // [rsp+0h] [rbp-98h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-18h] BYREF

memset(&v3, 0, sizeof(v3));
v3.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
timeout.tv_sec = 0LL;
timeout.tv_usec = a2;
return select(1024, &v3, 0LL, 0LL, &timeout);
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2)
{
fd_set v3; // [rsp+0h] [rbp-98h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-18h] BYREF

memset(&v3, 0, sizeof(v3));
v3.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
timeout.tv_sec = 0LL;
timeout.tv_usec = a2;
return select(1024, &v3, 0LL, 0LL, &timeout);
}

original_code:
int can_fd_wait(int fd, int wait_usec)
{
 struct timeval timeout;
 fd_set set;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&set)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 timeout.tv_sec = 0;
 timeout.tv_usec = wait_usec;
 return (select(1024, &set, ((void *)0), ((void *)0), &timeout));
}

canonical_original_code:
int can_fd_wait(int fd, int wait_usec)
{
 struct timeval timeout;
 struct fd_set set;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&set)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 timeout.tv_sec = 0;
 timeout.tv_usec = wait_usec;
 return (select(1024, &set, ((void *)0), ((void *)0), &timeout));
}

variable_types: fd int

variable_types:
set
struct fd_set { long __fds_bits[-1]; }

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


Driver

decompiled_code:
int __fastcall Driver(unsigned __int8 a1, __int64 a2, __int64 *a3)
{
int result; // eax
__int64 j; // rax
__int64 i; // rax
int v7; // [rsp+0h] [rbp-58h] BYREF
__int64 v8; // [rsp+8h] [rbp-50h]
__int16 v9; // [rsp+20h] [rbp-38h]
char v10[20]; // [rsp+22h] [rbp-36h]
char file[34]; // [rsp+36h] [rbp-22h] BYREF

strcpy(file, "/dev/can0");
if ( a1 == 2 )
{
v7 = 0;
v8 = *a3;
v9 = 8;
for ( i = 0LL; i != 7; ++i )
v10[i] = *(_BYTE *)(a2 + i);
result = (int)write(fd_0, &v7, 0x30uLL) >> 31;
}
else if ( a1 > 2u )
{
result = -1;
if ( a1 == 3 )
{
close(fd_0);
result = 0;
}
}
else if ( a1 )
{
result = can_fd_wait(fd_0, 5);
*a3 = 0LL;
if ( result )
{
if ( (int)read(fd_0, &v7, 0x30uLL) < 0 )
{
result = -1;
}
else
{
*a3 = v8;
for ( j = 0LL; j != 7; ++j )
*(_BYTE *)(a2 + j) = v10[j];
result = 0;
}
}
}
else
{
fd_0 = open(file, 1052674);
if ( fd_0 < 0 )
{
printf("Error opening %s\n", file);
result = -1;
}
else
{
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int8 a1, __int64 a2, __int64 *a3)
{
int result; // eax
__int64 j; // rax
__int64 i; // rax
int v7; // [rsp+0h] [rbp-58h] BYREF
__int64 v8; // [rsp+8h] [rbp-50h]
__int16 v9; // [rsp+20h] [rbp-38h]
char v10[20]; // [rsp+22h] [rbp-36h]
char file[34]; // [rsp+36h] [rbp-22h] BYREF

strcpy(file, "/dev/can0");
if ( a1 == 2 )
{
v7 = 0;
v8 = *a3;
v9 = 8;
for ( i = 0LL; i != 7; ++i )
v10[i] = *(_BYTE *)(a2 + i);
result = (int)write(fd_0, &v7, 0x30uLL) >> 31;
}
else if ( a1 > 2u )
{
result = -1;
if ( a1 == 3 )
{
close(fd_0);
result = 0;
}
}
else if ( a1 )
{
result = func0(fd_0, 5);
*a3 = 0LL;
if ( result )
{
if ( (int)read(fd_0, &v7, 0x30uLL) < 0 )
{
result = -1;
}
else
{
*a3 = v8;
for ( j = 0LL; j != 7; ++j )
*(_BYTE *)(a2 + j) = v10[j];
result = 0;
}
}
}
else
{
fd_0 = open(file, 1052674);
if ( fd_0 < 0 )
{
printf("Error opening %s\n", file);
result = -1;
}
else
{
result = 0;
}
}
return result;
}

original_code:
int Driver(unsigned char com, unsigned char *msg_data, unsigned long *msg_id)
{
 static int fd=0;
 int ret=0, i=0;
 char specialfile[]="/dev/can0";
 struct canmsg_t message;
 switch (com) {
  case 0:
   fd = open(specialfile, 02|04010000);
   if (fd<0) {
    printf("Error opening %s\n", specialfile);
    return -1;
   }
   return 0;
  case 1:
   ret = can_fd_wait(fd, 5);
   *msg_id = 0;
   if (ret != 0) {
    ret = read(fd, &message, sizeof(struct canmsg_t));
    if (ret<0)
     return -1;
    else {
     *msg_id = message.id;
     for (i=0; i<7; i++) {
      *(msg_data + i) = message.data[i];
     }
    }
   }
   return 0;
  case 2:
      message.flags = 0;
   message.id = *msg_id;
   message.length = 8;
   for (i=0; i<7; i++) {
    message.data[i] = *(msg_data + i);
   }
   ret = write(fd, &message, sizeof(struct canmsg_t));
   if (ret<0)
    return -1;
   else
    return 0;
  case 3:
      close(fd);
      return 0;
  default:
   return -1;
 }
}

canonical_original_code:
int Driver(unsigned char com, unsigned char *msg_data, unsigned long *msg_id)
{
 static int fd = 0;
 int ret = 0; int i = 0;
 char specialfile[] = "/dev/can0";
 struct canmsg_t message;
 switch (com) {
  case 0:
   fd = open(specialfile, 02|04010000);
   if (fd<0) {
    printf("Error opening %s\n", specialfile);
    return -1;
   }
   return 0;
  case 1:
   ret = can_fd_wait(fd, 5);
   *msg_id = 0;
   if (ret != 0) {
    ret = read(fd, &message, sizeof(struct canmsg_t));
    if (ret<0)
     return -1;
    else {
     *msg_id = message.id;
     for (i=0; i<7; i++) {
      *(msg_data + i) = message.data[i];
     }
    }
   }
   return 0;
  case 2:
      message.flags = 0;
   message.id = *msg_id;
   message.length = 8;
   for (i=0; i<7; i++) {
    message.data[i] = *(msg_data + i);
   }
   ret = write(fd, &message, sizeof(struct canmsg_t));
   if (ret<0)
    return -1;
   else
    return 0;
  case 3:
      close(fd);
      return 0;
  default:
   return -1;
 }
}

variable_types:
com
unsigned char

variable_types:
specialfile
char []

variable_types: struct canmsg_t { int flags; int cob; unsigned long id; struct timeval { long tv_sec; long tv_usec; } timestamp; unsigned short length; unsigned char data[8]; }

user_defined_types: struct canmsg_t { int flags; int cob; unsigned long id; struct timeval timestamp; unsigned short length; unsigned char data[8]; }


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

if ( a1 )
{
if ( a1 == 1 )
{
ADC(1600LL, &adc_result);
result = (unsigned int)adc_result;
}
else
{
result = nullsub_1(1LL);
}
}
else
{
ADC(1552LL, &adc_result);
result = (unsigned int)adc_result;
}
return result;
}

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

if ( a1 )
{
if ( a1 == 1 )
{
ADC(1600LL, &adc_result);
result = (unsigned int)adc_result;
}
else
{
result = nullsub_1(1LL);
}
}
else
{
ADC(1552LL, &adc_result);
result = (unsigned int)adc_result;
}
return result;
}

original_code:
int Sensor_cal(int mode)
{
 if (mode == 0) {
  ADC(0x0610, &adc_result);
  return (int)adc_result;
 } else if (mode == 1) {
  ADC(0x0640, &adc_result);
  return (int)adc_result;
 } else
  return (DI(1));
}


decompiled_code:
float __fastcall sensor_convdata(__int64 a1, int a2, float a3)
{
float v4; // xmm0_4
float result; // xmm0_4

if ( a3 == 0.0 || !a2 )
{
if ( a1 < 0 )
result = (float)(a1 & 1 | (unsigned int)((unsigned __int64)a1 >> 1))
+ (float)(a1 & 1 | (unsigned int)((unsigned __int64)a1 >> 1));
else
result = (float)(int)a1;
}
else
{
if ( a1 < 0 )
v4 = (float)(a1 & 1 | (unsigned int)((unsigned __int64)a1 >> 1))
+ (float)(a1 & 1 | (unsigned int)((unsigned __int64)a1 >> 1));
else
v4 = (float)(int)a1;
result = (float)((float)(v4 - (float)a2) / a3) * 100.0;
}
return result;
}

canonical_decompiled_code:
float __fastcall func1(__int64 a1, int a2, float a3)
{
float v4; // xmm0_4
float result; // xmm0_4

if ( a3 == 0.0 || !a2 )
{
if ( a1 < 0 )
result = (float)(a1 & 1 | (unsigned int)((unsigned __int64)a1 >> 1))
+ (float)(a1 & 1 | (unsigned int)((unsigned __int64)a1 >> 1));
else
result = (float)(int)a1;
}
else
{
if ( a1 < 0 )
v4 = (float)(a1 & 1 | (unsigned int)((unsigned __int64)a1 >> 1))
+ (float)(a1 & 1 | (unsigned int)((unsigned __int64)a1 >> 1));
else
v4 = (float)(int)a1;
result = (float)((float)(v4 - (float)a2) / a3) * 100.0;
}
return result;
}

original_code:
float sensor_convdata(unsigned long adc_data, float scale, int offset)
{
 float ret_var = 0;
 if ((scale !=0) && (offset != 0)) {
  ret_var = (((float)adc_data - (float)offset) / scale)*100;
 } else
  return (float)adc_data;
 return ret_var;
}

variable_types: scale float

variable_types: offset int

return_type: float