decompiled_code:
__int64 __fastcall rommon_var_add(__int64 a1, char *a2, const char *a3)
{
__int64 **v4; // rax
__int64 result; // rax
_QWORD *v6; // rax
_QWORD *v7; // r12

v4 = rommon_var_find(a1, a2);
if ( v4 )
{
rommon_var_set((__int64)v4, a3);
result = rommon_var_update_file((const char **)a1);
}
else
{
v6 = rommon_var_create(a2);
v7 = v6;
if ( !v6 || (unsigned int)rommon_var_set((__int64)v6, a3) == -1 )
{
result = 0xFFFFFFFFLL;
}
else
{
*v7 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v7;
result = rommon_var_update_file((const char **)a1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, const char *a3)
{
__int64 **v4; // rax
__int64 result; // rax
_QWORD *v6; // rax
_QWORD *v7; // r12

v4 = rommon_var_find(a1, a2);
if ( v4 )
{
func0((__int64)v4, a3);
result = func1((const char **)a1);
}
else
{
v6 = rommon_var_create(a2);
v7 = v6;
if ( !v6 || (unsigned int)func0((__int64)v6, a3) == -1 )
{
result = 0xFFFFFFFFLL;
}
else
{
*v7 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v7;
result = func1((const char **)a1);
}
}
return result;
}

original_code:
int rommon_var_add(struct rommon_var_list *rvl,char *name,char *value)
{
   struct rommon_var *var;
   if (!(var = rommon_var_find(rvl,name))) {
      var = rommon_var_create(name);
      if (!var) return(-1);
      if (rommon_var_set(var,value) == -1)
         return(-1);
      var->next = rvl->var_list;
      rvl->var_list = var;
   } else {
      rommon_var_set(var,value);
   }
   return(rommon_var_update_file(rvl));
}

canonical_original_code:
int rommon_var_add(struct rommon_var_list *rvl, char *name, char *value)
{
   struct rommon_var *var;
   if (!(var = rommon_var_find(rvl,name))) {
      var = rommon_var_create(name);
      if (!var) return(-1);
      if (rommon_var_set(var,value) == -1)
         return(-1);
      var->next = rvl->var_list;
      rvl->var_list = var;
   } else {
      rommon_var_set(var,value);
   }
   return(rommon_var_update_file(rvl));
}

variable_types: struct rommon_var_list { char *filename; struct rommon_var { struct rommon_var *next; char *name; char *value; } *var_list; } *

variable_types:
name
char *

user_defined_types: struct rommon_var_list { char *filename; struct rommon_var *var_list; }


repo: Groundworkstech/dynamips-gdb-mod

decompiled_code:
__int64 __fastcall rommon_var_add_str(__int64 a1, char *a2)
{
char *v2; // rax

v2 = strchr(a2, 61);
if ( !v2 || a2 == v2 )
return 0xFFFFFFFFLL;
*v2 = 0;
return rommon_var_add(a1, a2, v2 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char *a2)
{
char *v2; // rax

v2 = strchr(a2, 61);
if ( !v2 || a2 == v2 )
return 0xFFFFFFFFLL;
*v2 = 0;
return func2(a1, a2, v2 + 1);
}

original_code:
int rommon_var_add_str(struct rommon_var_list *rvl,char *str)
{
   char *eq_sym;
   if (!(eq_sym = strchr(str,'=')))
      return(-1);
   if (str == eq_sym)
      return(-1);
   *eq_sym = 0;
   return(rommon_var_add(rvl,str,eq_sym+1));
}

canonical_original_code:
int rommon_var_add_str(struct rommon_var_list *rvl, char *str)
{
   char *eq_sym;
   if (!(eq_sym = strchr(str,'=')))
      return(-1);
   if (str == eq_sym)
      return(-1);
   *eq_sym = 0;
   return(rommon_var_add(rvl,str,eq_sym+1));
}

variable_types:
str
char *

return_type: int

user_defined_types: struct rommon_var { struct rommon_var *next; char *name; char *value; }


decompiled_code:
__int64 __fastcall rommon_var_get(__int64 a1, const char *a2, char *a3, __int64 a4)
{
__int64 **v6; // rax
const char *v7; // rsi

v6 = rommon_var_find(a1, a2);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = (const char *)v6[2];
if ( !v7 )
return 0xFFFFFFFFLL;
strncpy(a3, v7, a4 - 1);
a3[a4 - 1] = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2, char *a3, __int64 a4)
{
__int64 **v6; // rax
const char *v7; // rsi

v6 = rommon_var_find(a1, a2);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = (const char *)v6[2];
if ( !v7 )
return 0xFFFFFFFFLL;
strncpy(a3, v7, a4 - 1);
a3[a4 - 1] = 0;
return 0LL;
}

original_code:
int rommon_var_get(struct rommon_var_list *rvl,char *name,
                   char *buffer,size_t len)
{
   struct rommon_var *var;
   if (!(var = rommon_var_find(rvl,name)) || !var->value)
      return(-1);
   strncpy(buffer,var->value,len-1);
   buffer[len-1] = '\0';
   return(0);
}

canonical_original_code:
int rommon_var_get(struct rommon_var_list *rvl, char *name, char *buffer, unsigned long len)
{
   struct rommon_var *var;
   if (!(var = rommon_var_find(rvl,name)) || !var->value)
      return(-1);
   strncpy(buffer,var->value,len-1);
   buffer[len-1] = '\0';
   return(0);
}

variable_types:
buffer
char *

variable_types:
len
unsigned long

variable_types: struct rommon_var { struct rommon_var *next; char *name; char *value; } *


canonical_original_code:
int base64_decode(unsigned char *out, unsigned char *in, int maxlen)
{
   register unsigned char digit1; register unsigned char digit2; register unsigned char digit3; register unsigned char digit4;
   int len = 0;
   if (in[0] == '+' && in[1] == ' ')
      in += 2;
   if (*in == '\r')
      return(0);
   do {
      digit1 = in[0];
      if (((((digit1) & ~0x7f) == 0) ? base64val[digit1] : -1) == -1)
         return(-1);
      digit2 = in[1];
      if (((((digit2) & ~0x7f) == 0) ? base64val[digit2] : -1) == -1)
         return(-1);
      digit3 = in[2];
      if (digit3 != '=' && ((((digit3) & ~0x7f) == 0) ? base64val[digit3] : -1) == -1)
         return(-1);
      digit4 = in[3];
      if (digit4 != '=' && ((((digit4) & ~0x7f) == 0) ? base64val[digit4] : -1) == -1)
         return(-1);
      in += 4;
      ++len;
      if (maxlen && len > maxlen)
         return(-1);
      *out++ = (((((digit1) & ~0x7f) == 0) ? base64val[digit1] : -1) << 2) | (((((digit2) & ~0x7f) == 0) ? base64val[digit2] : -1) >> 4);
      if (digit3 != '=')
      {
         ++len;
         if (maxlen && (len > maxlen))
            return(-1);
         *out++ = ((((((digit2) & ~0x7f) == 0) ? base64val[digit2] : -1) << 4) & 0xf0) | (((((digit3) & ~0x7f) == 0) ? base64val[digit3] : -1) >> 2);
         if (digit4 != '=') {
            ++len;
            if (maxlen && (len > maxlen))
               return(-1);
            *out++ = ((((((digit3) & ~0x7f) == 0) ? base64val[digit3] : -1) << 6) & 0xc0) | ((((digit4) & ~0x7f) == 0) ? base64val[digit4] : -1);
         }
      }
   } while(*in && (*in != '\r') && (digit4 != '='));
   return(len);
}

variable_types:
out
unsigned char *

variable_types:
in
unsigned char *

variable_types: maxlen int

variable_types: len int


decompiled_code:
const char *__fastcall cisco_eeprom_find(const char **a1, const char *a2)
{
const char **v2; // rbx
const char *v3; // rdi

v2 = a1;
v3 = *a1;
if ( v3 )
{
while ( strcmp(v3, a2) )
{
v3 = v2[3];
v2 += 3;
if ( !v3 )
return v3;
}
v3 = (const char *)v2;
}
return v3;
}

canonical_decompiled_code:
const char *__fastcall func0(const char **a1, const char *a2)
{
const char **v2; // rbx
const char *v3; // rdi

v2 = a1;
v3 = *a1;
if ( v3 )
{
while ( strcmp(v3, a2) )
{
v3 = v2[3];
v2 += 3;
if ( !v3 )
return v3;
}
v3 = (const char *)v2;
}
return v3;
}

original_code:
const struct cisco_eeprom *
cisco_eeprom_find(const struct cisco_eeprom *eeproms,char *name)
{
   int i;
   for(i=0;eeproms[i].name;i++)
      if (!strcmp(eeproms[i].name,name))
         return(&eeproms[i]);
   return ((void *)0);
}

canonical_original_code:
struct cisco_eeprom *cisco_eeprom_find(struct cisco_eeprom *eeproms, char *name)
{
   int i;
   for(i=0;eeproms[i].name;i++)
      if (!strcmp(eeproms[i].name,name))
         return(&eeproms[i]);
   return ((void *)0);
}

variable_types:
eeproms
struct cisco_eeprom *

variable_types: i int

return_type: struct cisco_eeprom { char *name; unsigned short *data; unsigned long len; } *


decompiled_code:
const char *__fastcall cisco_eeprom_find_nm(const char *a1)
{
return cisco_eeprom_find((const char **)&eeprom_nm_array, a1);
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
return func0((const char **)&eeprom_nm_array, a1);
}

original_code:
const struct cisco_eeprom *cisco_eeprom_find_nm(char *name)
{
   return(cisco_eeprom_find(eeprom_nm_array,name));
}

user_defined_types: struct cisco_eeprom { char *name; unsigned short *data; unsigned long len; }


decompiled_code:
const char *__fastcall cisco_eeprom_find_pa(const char *a1)
{
return cisco_eeprom_find((const char **)&eeprom_pa_array, a1);
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1)
{
return func0((const char **)&eeprom_pa_array, a1);
}

original_code:
const struct cisco_eeprom *cisco_eeprom_find_pa(char *name)
{
   return(cisco_eeprom_find(eeprom_pa_array,name));
}


decompiled_code:
const char *__fastcall cisco_eeprom_find_wic(const char *a1)
{
return cisco_eeprom_find((const char **)&eeprom_wic_array, a1);
}

canonical_decompiled_code:
const char *__fastcall func3(const char *a1)
{
return func0((const char **)&eeprom_wic_array, a1);
}

original_code:
const struct cisco_eeprom *cisco_eeprom_find_wic(char *name)
{
   return(cisco_eeprom_find(eeprom_wic_array,name));
}


decompiled_code:
const char *__fastcall cisco_eeprom_find_c6k(const char *a1)
{
return cisco_eeprom_find((const char **)&eeprom_c6k_array, a1);
}

canonical_decompiled_code:
const char *__fastcall func4(const char *a1)
{
return func0((const char **)&eeprom_c6k_array, a1);
}

original_code:
const struct cisco_eeprom *cisco_eeprom_find_c6k(char *name)
{
   return(cisco_eeprom_find(eeprom_c6k_array,name));
}


decompiled_code:
void __fastcall cisco_eeprom_free(__int64 a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = *(void **)(a1 + 8);
if ( v2 )
{
free(v2);
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
}
}

original_code:
void cisco_eeprom_free(struct cisco_eeprom *eeprom)
{
   if (eeprom && eeprom->data) {
      free(eeprom->data);
      eeprom->data = ((void *)0);
      eeprom->len = 0;
   }
}

variable_types: struct cisco_eeprom { char *name; unsigned short *data; unsigned long len; } *

return_type: void


decompiled_code:
__int64 __fastcall cisco_eeprom_copy(_QWORD *a1, __int64 *a2)
{
__int64 v2; // r12
void *v3; // rax
void *v4; // rcx
__int64 v5; // rax

if ( !a2 )
return 0xFFFFFFFFLL;
cisco_eeprom_free((__int64)a1);
v2 = a2[2];
v3 = malloc(2 * v2);
if ( !v3 )
return 0xFFFFFFFFLL;
v4 = memcpy(v3, (const void *)a2[1], 2 * v2);
v5 = *a2;
a1[2] = v2;
a1[1] = v4;
*a1 = v5;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 *a2)
{
__int64 v2; // r12
void *v3; // rax
void *v4; // rcx
__int64 v5; // rax

if ( !a2 )
return 0xFFFFFFFFLL;
func5((__int64)a1);
v2 = a2[2];
v3 = malloc(2 * v2);
if ( !v3 )
return 0xFFFFFFFFLL;
v4 = memcpy(v3, (const void *)a2[1], 2 * v2);
v5 = *a2;
a1[2] = v2;
a1[1] = v4;
*a1 = v5;
return 0LL;
}

original_code:
int cisco_eeprom_copy(struct cisco_eeprom *dst,const struct cisco_eeprom *src)
{
   m_uint16_t *data;
   if (!src || !src)
      return(-1);
   cisco_eeprom_free(dst);
   if (!(data = malloc(src->len << 1)))
      return(-1);
   memcpy(data,src->data,src->len << 1);
   dst->name = src->name;
   dst->data = data;
   dst->len = src->len;
   return(0);
}

canonical_original_code:
int cisco_eeprom_copy(struct cisco_eeprom *dst, struct cisco_eeprom *src)
{
   unsigned short *data;
   if (!src || !src)
      return(-1);
   cisco_eeprom_free(dst);
   if (!(data = malloc(src->len << 1)))
      return(-1);
   memcpy(data,src->data,src->len << 1);
   dst->name = src->name;
   dst->data = data;
   dst->len = src->len;
   return(0);
}

variable_types:
src
struct cisco_eeprom *

variable_types:
data
unsigned short *


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

result = 0LL;
if ( a1 )
result = *(_QWORD *)(a1 + 8) != 0LL;
return result;
}

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

result = 0LL;
if ( a1 )
result = *(_QWORD *)(a1 + 8) != 0LL;
return result;
}

original_code:
int cisco_eeprom_valid(struct cisco_eeprom *eeprom)
{
   return((eeprom && eeprom->data) ? 1 : 0);
}


decompiled_code:
__int64 __fastcall cisco_eeprom_get_byte(__int64 a1, unsigned __int64 a2, _BYTE *a3)
{
__int16 v3; // ax
__int64 result; // rax

if ( 2LL * *(_QWORD *)(a1 + 16) <= a2 )
{
*a3 = -1;
result = 0xFFFFFFFFLL;
}
else
{
v3 = *(_WORD *)(*(_QWORD *)(a1 + 8) + 2 * (a2 >> 1));
if ( (a2 & 1) == 0 )
LOBYTE(v3) = HIBYTE(v3);
*a3 = v3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned __int64 a2, _BYTE *a3)
{
__int16 v3; // ax
__int64 result; // rax

if ( 2LL * *(_QWORD *)(a1 + 16) <= a2 )
{
*a3 = -1;
result = 0xFFFFFFFFLL;
}
else
{
v3 = *(_WORD *)(*(_QWORD *)(a1 + 8) + 2 * (a2 >> 1));
if ( (a2 & 1) == 0 )
LOBYTE(v3) = HIBYTE(v3);
*a3 = v3;
result = 0LL;
}
return result;
}

original_code:
int cisco_eeprom_get_byte(struct cisco_eeprom *eeprom,
                          size_t offset,m_uint8_t *val)
{
   m_uint16_t tmp;
   if (offset >= (eeprom->len << 1)) {
      *val = 0xFF;
      return(-1);
   }
   tmp = eeprom->data[offset >> 1];
   if (!(offset & 1))
      tmp >>= 8;
   *val = tmp & 0xFF;
   return(0);
}

canonical_original_code:
int cisco_eeprom_get_byte(struct cisco_eeprom *eeprom, unsigned long offset, unsigned char *val)
{
   unsigned short tmp;
   if (offset >= (eeprom->len << 1)) {
      *val = 0xFF;
      return(-1);
   }
   tmp = eeprom->data[offset >> 1];
   if (!(offset & 1))
      tmp >>= 8;
   *val = tmp & 0xFF;
   return(0);
}

variable_types:
offset
unsigned long

variable_types:
val
unsigned char *

variable_types:
tmp
unsigned short


decompiled_code:
__int64 __fastcall cisco_eeprom_set_byte(__int64 a1, unsigned __int64 a2, __int16 a3)
{
__int16 *v3; // rax
__int16 v4; // cx
__int16 v5; // dx

if ( 2LL * *(_QWORD *)(a1 + 16) <= a2 )
return 0xFFFFFFFFLL;
v3 = (__int16 *)(*(_QWORD *)(a1 + 8) + (a2 & 0xFFFFFFFFFFFFFFFELL));
v4 = *v3;
if ( (a2 & 1) != 0 )
{
LOBYTE(v4) = 0;
v5 = v4 | (unsigned __int8)a3;
}
else
{
v5 = (unsigned __int8)v4 | (unsigned __int16)(a3 << 8);
}
*v3 = v5;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned __int64 a2, __int16 a3)
{
__int16 *v3; // rax
__int16 v4; // cx
__int16 v5; // dx

if ( 2LL * *(_QWORD *)(a1 + 16) <= a2 )
return 0xFFFFFFFFLL;
v3 = (__int16 *)(*(_QWORD *)(a1 + 8) + (a2 & 0xFFFFFFFFFFFFFFFELL));
v4 = *v3;
if ( (a2 & 1) != 0 )
{
LOBYTE(v4) = 0;
v5 = v4 | (unsigned __int8)a3;
}
else
{
v5 = (unsigned __int8)v4 | (unsigned __int16)(a3 << 8);
}
*v3 = v5;
return 0LL;
}

original_code:
int cisco_eeprom_set_byte(struct cisco_eeprom *eeprom,
                          size_t offset,m_uint8_t val)
{
   m_uint16_t tmp;
   if (offset >= (eeprom->len << 1))
      return(-1);
   tmp = eeprom->data[offset >> 1];
   if (offset & 1)
      tmp = (tmp & 0xFF00) | val;
   else
      tmp = (tmp & 0x00FF) | (val << 8);
   eeprom->data[offset >> 1] = tmp;
   return(0);
}

canonical_original_code:
int cisco_eeprom_set_byte(struct cisco_eeprom *eeprom, unsigned long offset, unsigned char val)
{
   unsigned short tmp;
   if (offset >= (eeprom->len << 1))
      return(-1);
   tmp = eeprom->data[offset >> 1];
   if (offset & 1)
      tmp = (tmp & 0xFF00) | val;
   else
      tmp = (tmp & 0x00FF) | (val << 8);
   eeprom->data[offset >> 1] = tmp;
   return(0);
}

variable_types:
val
unsigned char


decompiled_code:
__int64 __fastcall cisco_eeprom_get_region(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // r8
__int64 v5; // r10
__int64 result; // rax
__int64 v7; // r8
__int64 v8; // r9

v4 = a2;
if ( !a4 )
return 0LL;
v5 = a3 - a2;
while ( 1 )
{
result = cisco_eeprom_get_byte(a1, v4, (_BYTE *)(v5 + v4));
if ( (_DWORD)result == -1 )
break;
v4 = v7 + 1;
if ( v4 == v8 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // r8
__int64 v5; // r10
__int64 result; // rax
__int64 v7; // r8
__int64 v8; // r9

v4 = a2;
if ( !a4 )
return 0LL;
v5 = a3 - a2;
while ( 1 )
{
result = func8(a1, v4, (_BYTE *)(v5 + v4));
if ( (_DWORD)result == -1 )
break;
v4 = v7 + 1;
if ( v4 == v8 )
return 0LL;
}
return result;
}

original_code:
int cisco_eeprom_get_region(struct cisco_eeprom *eeprom,size_t offset,
                            m_uint8_t *data,size_t data_len)
{
   size_t i;
   for(i=0;i<data_len;i++) {
      if (cisco_eeprom_get_byte(eeprom,offset+i,&data[i]) == -1)
         return(-1);
   }
   return(0);
}

canonical_original_code:
int cisco_eeprom_get_region(struct cisco_eeprom *eeprom, unsigned long offset, unsigned char *data, unsigned long data_len)
{
   unsigned long i;
   for(i=0;i<data_len;i++) {
      if (cisco_eeprom_get_byte(eeprom,offset+i,&data[i]) == -1)
         return(-1);
   }
   return(0);
}

variable_types:
data
unsigned char *

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall cisco_eeprom_set_region(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // r8
__int64 v5; // r10
__int64 result; // rax
__int64 v7; // r8
__int64 v8; // r9

v4 = a2;
if ( !a4 )
return 0LL;
v5 = a3 - a2;
while ( 1 )
{
result = cisco_eeprom_set_byte(a1, v4, *(unsigned __int8 *)(v5 + v4));
if ( (_DWORD)result == -1 )
break;
v4 = v7 + 1;
if ( v4 == v8 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // r8
__int64 v5; // r10
__int64 result; // rax
__int64 v7; // r8
__int64 v8; // r9

v4 = a2;
if ( !a4 )
return 0LL;
v5 = a3 - a2;
while ( 1 )
{
result = func9(a1, v4, *(unsigned __int8 *)(v5 + v4));
if ( (_DWORD)result == -1 )
break;
v4 = v7 + 1;
if ( v4 == v8 )
return 0LL;
}
return result;
}

original_code:
int cisco_eeprom_set_region(struct cisco_eeprom *eeprom,size_t offset,
                            m_uint8_t *data,size_t data_len)
{
   size_t i;
   for(i=0;i<data_len;i++) {
      if (cisco_eeprom_set_byte(eeprom,offset+i,data[i]) == -1)
         return(-1);
   }
   return(0);
}

canonical_original_code:
int cisco_eeprom_set_region(struct cisco_eeprom *eeprom, unsigned long offset, unsigned char *data, unsigned long data_len)
{
   unsigned long i;
   for(i=0;i<data_len;i++) {
      if (cisco_eeprom_set_byte(eeprom,offset+i,data[i]) == -1)
         return(-1);
   }
   return(0);
}


decompiled_code:
__int64 __fastcall cisco_eeprom_v4_get_field(__int64 a1, _BYTE *a2, __int64 a3, _QWORD *a4)
{
unsigned __int64 v5; // rsi
_QWORD *v6; // r8
_BYTE *v7; // r9
_BYTE *v8; // r10
__int64 result; // rax
char v10; // cl
unsigned __int64 v11; // rsi
_BYTE *v12; // r10
char v13; // [rsp+Fh] [rbp-1h] BYREF

v5 = (*a4)++;
if ( (unsigned int)cisco_eeprom_get_byte(a1, v5, a2) == -1 )
return 0xFFFFFFFFLL;
result = 0LL;
if ( *v7 == 0xFF )
return result;
v10 = *v7 >> 6;
v13 = v10;
if ( v10 == 3 )
{
v11 = (*v6)++;
if ( (unsigned int)cisco_eeprom_get_byte(a1, v11, &v13) != -1 )
{
*v12 = v13 & 0xF;
return 1LL;
}
return 0xFFFFFFFFLL;
}
*v8 = 1 << v10;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, _BYTE *a2, __int64 a3, _QWORD *a4)
{
unsigned __int64 v5; // rsi
_QWORD *v6; // r8
_BYTE *v7; // r9
_BYTE *v8; // r10
__int64 result; // rax
char v10; // cl
unsigned __int64 v11; // rsi
_BYTE *v12; // r10
char v13; // [rsp+Fh] [rbp-1h] BYREF

v5 = (*a4)++;
if ( (unsigned int)func8(a1, v5, a2) == -1 )
return 0xFFFFFFFFLL;
result = 0LL;
if ( *v7 == 0xFF )
return result;
v10 = *v7 >> 6;
v13 = v10;
if ( v10 == 3 )
{
v11 = (*v6)++;
if ( (unsigned int)func8(a1, v11, &v13) != -1 )
{
*v12 = v13 & 0xF;
return 1LL;
}
return 0xFFFFFFFFLL;
}
*v8 = 1 << v10;
return 1LL;
}

original_code:
int cisco_eeprom_v4_get_field(struct cisco_eeprom *eeprom,m_uint8_t *type,
                              m_uint8_t *len,size_t *offset)
{
   m_uint8_t tmp;
   if (cisco_eeprom_get_byte(eeprom,(*offset)++,type) == -1)
      return(-1);
   if (*type == 0xFF)
      return(0);
   tmp = (*type >> 6) & 0x03;
   if (tmp == 0x03) {
      if (cisco_eeprom_get_byte(eeprom,(*offset)++,&tmp) == -1)
         return(-1);
      *len = tmp & 0x0F;
   } else {
      *len = 1 << tmp;
   }
   return(1);
}

canonical_original_code:
int cisco_eeprom_v4_get_field(struct cisco_eeprom *eeprom, unsigned char *type, unsigned char *len, unsigned long *offset)
{
   unsigned char tmp;
   if (cisco_eeprom_get_byte(eeprom,(*offset)++,type) == -1)
      return(-1);
   if (*type == 0xFF)
      return(0);
   tmp = (*type >> 6) & 0x03;
   if (tmp == 0x03) {
      if (cisco_eeprom_get_byte(eeprom,(*offset)++,&tmp) == -1)
         return(-1);
      *len = tmp & 0x0F;
   } else {
      *len = 1 << tmp;
   }
   return(1);
}

variable_types:
type
unsigned char *

variable_types:
len
unsigned char *

variable_types:
offset
unsigned long *

variable_types:
tmp
unsigned char


decompiled_code:
unsigned __int64 __fastcall cisco_eeprom_v4_dump(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 i; // rbx
unsigned __int64 v3; // rdx
unsigned __int8 v4; // [rsp+5h] [rbp-23h] BYREF
unsigned __int8 v5; // [rsp+6h] [rbp-22h] BYREF
unsigned __int8 v6; // [rsp+7h] [rbp-21h] BYREF
unsigned __int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

v7[0] = 2LL;
puts("Dumping EEPROM contents:");
do
{
result = cisco_eeprom_v4_get_field(a1, &v4, (__int64)&v5, v7);
if ( (int)result <= 0 )
break;
printf(" Field 0x%2.2x: ", v4);
if ( v5 )
{
for ( i = 0LL; i < v5; ++i )
{
if ( (unsigned int)cisco_eeprom_get_byte(a1, i + v7[0], &v6) == -1 )
break;
printf("%2.2x ", v6);
}
}
putchar(10);
result = v7[0] + v5;
v3 = 2LL * *(_QWORD *)(a1 + 16);
v7[0] = result;
}
while ( result < v3 );
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func13(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 i; // rbx
unsigned __int64 v3; // rdx
unsigned __int8 v4; // [rsp+5h] [rbp-23h] BYREF
unsigned __int8 v5; // [rsp+6h] [rbp-22h] BYREF
unsigned __int8 v6; // [rsp+7h] [rbp-21h] BYREF
unsigned __int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

v7[0] = 2LL;
puts("Dumping EEPROM contents:");
do
{
result = func12(a1, &v4, (__int64)&v5, v7);
if ( (int)result <= 0 )
break;
printf(" Field 0x%2.2x: ", v4);
if ( v5 )
{
for ( i = 0LL; i < v5; ++i )
{
if ( (unsigned int)func8(a1, i + v7[0], &v6) == -1 )
break;
printf("%2.2x ", v6);
}
}
putchar(10);
result = v7[0] + v5;
v3 = 2LL * *(_QWORD *)(a1 + 16);
v7[0] = result;
}
while ( result < v3 );
return result;
}

original_code:
void cisco_eeprom_v4_dump(struct cisco_eeprom *eeprom)
{
   m_uint8_t type,len,tmp;
   size_t i,offset=2;
   printf("Dumping EEPROM contents:\n");
   do {
      if (cisco_eeprom_v4_get_field(eeprom,&type,&len,&offset) < 1)
         break;
      printf("  Field 0x%2.2x: ",type);
      for(i=0;i<len;i++) {
         if (cisco_eeprom_get_byte(eeprom,offset+i,&tmp) == -1)
            break;
         printf("%2.2x ",tmp);
      }
      printf("\n");
      offset += len;
   }while(offset < (eeprom->len << 1));
}

canonical_original_code:
void cisco_eeprom_v4_dump(struct cisco_eeprom *eeprom)
{
   unsigned char type; unsigned char len; unsigned char tmp;
   unsigned long i; unsigned long offset = 2;
   printf("Dumping EEPROM contents:\n");
   do {
      if (cisco_eeprom_v4_get_field(eeprom,&type,&len,&offset) < 1)
         break;
      printf("  Field 0x%2.2x: ",type);
      for(i=0;i<len;i++) {
         if (cisco_eeprom_get_byte(eeprom,offset+i,&tmp) == -1)
            break;
         printf("%2.2x ",tmp);
      }
      printf("\n");
      offset += len;
   }while(offset < (eeprom->len << 1));
}

variable_types:
type
unsigned char

variable_types:
len
unsigned char


decompiled_code:
__int64 __fastcall cisco_eeprom_v4_find_field(__int64 a1, __int64 a2, unsigned __int64 *a3)
{
unsigned __int64 v4; // rdx
char v5; // r11
char v7; // [rsp+6h] [rbp-12h] BYREF
unsigned __int8 v8; // [rsp+7h] [rbp-11h] BYREF
unsigned __int64 v9; // [rsp+8h] [rbp-10h] BYREF

v9 = 2LL;
while ( 1 )
{
if ( (int)cisco_eeprom_v4_get_field(a1, &v7, (__int64)&v8, &v9) <= 0 )
return 0xFFFFFFFFLL;
if ( v7 == v5 )
break;
v4 = 2LL * *(_QWORD *)(a1 + 16);
v9 += v8;
if ( v9 >= v4 )
return 0xFFFFFFFFLL;
}
*a3 = v9;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, unsigned __int64 *a3)
{
unsigned __int64 v4; // rdx
char v5; // r11
char v7; // [rsp+6h] [rbp-12h] BYREF
unsigned __int8 v8; // [rsp+7h] [rbp-11h] BYREF
unsigned __int64 v9; // [rsp+8h] [rbp-10h] BYREF

v9 = 2LL;
while ( 1 )
{
if ( (int)func12(a1, &v7, (__int64)&v8, &v9) <= 0 )
return 0xFFFFFFFFLL;
if ( v7 == v5 )
break;
v4 = 2LL * *(_QWORD *)(a1 + 16);
v9 += v8;
if ( v9 >= v4 )
return 0xFFFFFFFFLL;
}
*a3 = v9;
return 0LL;
}

original_code:
int cisco_eeprom_v4_find_field(struct cisco_eeprom *eeprom,
                               m_uint8_t field_type,
                               size_t *field_offset)
{
   m_uint8_t type,len;
   size_t offset=2;
   do {
      if (cisco_eeprom_v4_get_field(eeprom,&type,&len,&offset) < 1)
         break;
      if (type == field_type) {
         *field_offset = offset;
         return(0);
      }
      offset += len;
   }while(offset < (eeprom->len << 1));
   return(-1);
}

canonical_original_code:
int cisco_eeprom_v4_find_field(struct cisco_eeprom *eeprom, unsigned char field_type, unsigned long *field_offset)
{
   unsigned char type; unsigned char len;
   unsigned long offset = 2;
   do {
      if (cisco_eeprom_v4_get_field(eeprom,&type,&len,&offset) < 1)
         break;
      if (type == field_type) {
         *field_offset = offset;
         return(0);
      }
      offset += len;
   }while(offset < (eeprom->len << 1));
   return(-1);
}


decompiled_code:
// attributes: thunk
void hash_node_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func0(void *ptr)
{
free(ptr);
}

original_code:
static inline void hash_node_free(hash_node_t *node)
{
   free(node);
}

canonical_original_code:
static inline void hash_node_free(struct hash_node *node)
{
   free(node);
}

variable_types: struct hash_node { void *key; struct hash_node *next; } *


decompiled_code:
_BOOL8 __fastcall str_equal(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int str_equal(void *s1, void *s2)
{
   return(strcmp((char *)s1, (char *)s2) == 0);
}


decompiled_code:
__int64 __fastcall str_hash(_BYTE *a1)
{
int v1; // edx
__int64 result; // rax

v1 = (char)*a1;
result = 0LL;
if ( *a1 )
{
do
{
result = (unsigned int)(v1 + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = (((unsigned int)result & 0xF0000000) >> 24) ^ result & 0xFFFFFFF;
v1 = (char)*++a1;
}
while ( (_BYTE)v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
int v1; // edx
__int64 result; // rax

v1 = (char)*a1;
result = 0LL;
if ( *a1 )
{
do
{
result = (unsigned int)(v1 + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = (((unsigned int)result & 0xF0000000) >> 24) ^ result & 0xFFFFFFF;
v1 = (char)*++a1;
}
while ( (_BYTE)v1 );
}
return result;
}

canonical_original_code:
unsigned int str_hash(void *str)
{
   char *p; char *s = (char *)str;
   unsigned int h; unsigned int g;
   for(h=0,p=s;*p!='\0';p+=1)
   {
      h = (h << 4) + *p;
      if ((g = h & 0xf0000000)) {
         h = h ^ (g >> 24);
         h = h ^ g;
      }
   }
   return(h);
}

variable_types:
str
void *

variable_types:
p
char *

variable_types:
s
char *

variable_types:
h
unsigned int

variable_types:
g
unsigned int

return_type: unsigned int


decompiled_code:
_BOOL8 __fastcall int_equal(int a1, int a2)
{
return a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1, int a2)
{
return a1 == a2;
}

original_code:
int int_equal(void *i1, void *i2)
{
   return(((int)(long)i1) == (int)(long)i2);
}


decompiled_code:
__int64 __fastcall int_hash(unsigned int a1)
{
return a1 ^ HIWORD(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return a1 ^ HIWORD(a1);
}

original_code:
u_int int_hash(void *i)
{
   u_int val = (u_int)(long)i;
   return(val ^ (val >> 16));
}

canonical_original_code:
unsigned int int_hash(void *i)
{
   unsigned int val = (u_int)(long)i;
   return(val ^ (val >> 16));
}

variable_types:
i
void *

variable_types:
val
unsigned int


decompiled_code:
_BOOL8 __fastcall u64_equal(_QWORD *a1, _QWORD *a2)
{
return *a1 == *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_QWORD *a1, _QWORD *a2)
{
return *a1 == *a2;
}

original_code:
int u64_equal(void *i1, void *i2)
{
   return((*(m_uint64_t *)i1) == (*(m_uint64_t *)i2));
}

canonical_original_code:
int u64_equal(void *i1, void *i2)
{
   return((*(unsigned long long *)i1) == (*(unsigned long long *)i2));
}


decompiled_code:
__int64 __fastcall u64_hash(_QWORD *a1)
{
return (unsigned int)*a1 ^ (unsigned int)HIDWORD(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
return (unsigned int)*a1 ^ (unsigned int)HIDWORD(*a1);
}

original_code:
u_int u64_hash(void *i)
{
   m_uint64_t val = *(m_uint64_t *)i;
   return((u_int)(val ^ (val >> 32)));
}

canonical_original_code:
unsigned int u64_hash(void *i)
{
   unsigned long long val = *(m_uint64_t *)i;
   return((u_int)(val ^ (val >> 32)));
}

variable_types:
val
unsigned long long


decompiled_code:
_BOOL8 __fastcall ptr_equal(__int64 a1, __int64 a2)
{
return a2 == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1, __int64 a2)
{
return a2 == a1;
}

original_code:
int ptr_equal(void *i1,void *i2)
{
   return((int)(i1 == i2));
}

canonical_original_code:
int ptr_equal(void *i1, void *i2)
{
   return((int)(i1 == i2));
}


decompiled_code:
__int64 __fastcall ptr_hash(unsigned __int64 a1)
{
return (unsigned __int16)(a1 ^ HIWORD(a1) ^ (a1 >> 24));
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int64 a1)
{
return (unsigned __int16)(a1 ^ HIWORD(a1) ^ (a1 >> 24));
}

original_code:
u_int ptr_hash(void *i)
{
   m_uint64_t val = (m_uint64_t)(m_iptr_t)i;
   return((u_int)((val & 0xFFFF) ^ ((val >> 24) & 0xFFFF) ^
                  ((val >> 48) & 0xFFFF)));
}

canonical_original_code:
unsigned int ptr_hash(void *i)
{
   unsigned long long val = (m_uint64_t)(m_iptr_t)i;
   return((u_int)((val & 0xFFFF) ^ ((val >> 24) & 0xFFFF) ^
                  ((val >> 48) & 0xFFFF)));
}


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

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

original_code:
void hash_table_delete(hash_table_t *ht)
{
   if (ht) {
      free(ht);
   }
}

canonical_original_code:
void hash_table_delete(struct hash_table *ht)
{
   if (ht) {
      free(ht);
   }
}

variable_types: struct hash_table { int size; struct hash_node { void *key; struct hash_node *next; } **nodes; unsigned int (*hash_func)(void *key); int (*key_cmp)(void *key1, void *key2); } *

user_defined_types: struct hash_table { int size; struct hash_node **nodes; unsigned int (*hash_func)(void *key); int (*key_cmp)(void *key1, void *key2); }


decompiled_code:
__int64 __fastcall hash_table_insert(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rdx
_QWORD *v5; // rbx
__int64 v6; // r14
__int64 result; // rax
_QWORD *v8; // rdx
_QWORD *v9; // rax

if ( !a1 )
_assert_fail("ht!=NULL", "hash.c", 0x8Bu, "hash_table_insert");
v4 = (*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)a1;
v5 = *(_QWORD **)(*(_QWORD *)(a1 + 8) + 8 * v4);
v6 = 8LL * (unsigned int)v4;
if ( v5 )
{
while ( !(*(unsigned int (__fastcall **)(_QWORD, __int64))(a1 + 24))(*v5, a2) )
{
v5 = (_QWORD *)v5[2];
if ( !v5 )
goto LABEL_7;
}
v5[1] = a3;
result = 0LL;
}
else
{
LABEL_7:
v8 = hash_node_alloc_constprop_0(a2, a3);
v9 = (_QWORD *)(v6 + *(_QWORD *)(a1 + 8));
v8[2] = *v9;
*v9 = v8;
result = 0LL;
++*(_DWORD *)(a1 + 4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rdx
_QWORD *v5; // rbx
__int64 v6; // r14
__int64 result; // rax
_QWORD *v8; // rdx
_QWORD *v9; // rax

if ( !a1 )
_assert_fail("ht!=NULL", "hash.c", 0x8Bu, "hash_table_insert");
v4 = (*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)a1;
v5 = *(_QWORD **)(*(_QWORD *)(a1 + 8) + 8 * v4);
v6 = 8LL * (unsigned int)v4;
if ( v5 )
{
while ( !(*(unsigned int (__fastcall **)(_QWORD, __int64))(a1 + 24))(*v5, a2) )
{
v5 = (_QWORD *)v5[2];
if ( !v5 )
goto LABEL_7;
}
v5[1] = a3;
result = 0LL;
}
else
{
LABEL_7:
v8 = hash_node_alloc_constprop_0(a2, a3);
v9 = (_QWORD *)(v6 + *(_QWORD *)(a1 + 8));
v8[2] = *v9;
*v9 = v8;
result = 0LL;
++*(_DWORD *)(a1 + 4);
}
return result;
}

original_code:
int hash_table_insert(hash_table_t *ht,void *key,void *value)
{
   hash_node_t *node;
   u_int hash_val;
   ((void) sizeof ((ht!=((void *)0)) ? 1 : 0), __extension__ ({ if (ht!=((void *)0)) ; else __assert_fail ("ht!=NULL", "hash.c", 139, __extension__ __PRETTY_FUNCTION__); }));
   hash_val = ht->hash_func(key) % ht->size;
   for(node=ht->nodes[hash_val];node;node=node->next)
      if (ht->key_cmp(node->key,key)) {
         node->value = value;
         return(0);
      }
   node = hash_node_alloc(ht,key,value);
   node->next = ht->nodes[hash_val];
   ht->nodes[hash_val] = node;
   ht->nnodes++;
   return(0);
}

canonical_original_code:
int hash_table_insert(struct hash_table *ht, void *key, void *value)
{
   struct hash_node *node;
   unsigned int hash_val;
   ((void) sizeof ((ht!=((void *)0)) ? 1 : 0), __extension__ ({ if (ht!=((void *)0)) ; else __assert_fail ("ht!=NULL", "hash.c", 139, __extension__ __PRETTY_FUNCTION__); }));
   hash_val = ht->hash_func(key) % ht->size;
   for(node=ht->nodes[hash_val];node;node=node->next)
      if (ht->key_cmp(node->key,key)) {
         node->value = value;
         return(0);
      }
   node = hash_node_alloc(ht,key,value);
   node->next = ht->nodes[hash_val];
   ht->nodes[hash_val] = node;
   ht->nnodes++;
   return(0);
}

variable_types:
key
void *

variable_types:
value
void *

user_defined_types: struct hash_node { void *key; struct hash_node *next; }


decompiled_code:
__int64 __fastcall hash_table_foreach(__int64 a1, void (__fastcall *a2)(_QWORD, _QWORD, __int64), __int64 a3)
{
__int64 i; // r13
_QWORD *j; // rbx

if ( !a1 )
_assert_fail("ht!=NULL", "hash.c", 0xDCu, "hash_table_foreach");
for ( i = 0LL; *(_DWORD *)a1 > (int)i; ++i )
{
for ( j = *(_QWORD **)(*(_QWORD *)(a1 + 8) + 8 * i); j; j = (_QWORD *)j[2] )
a2(*j, j[1], a3);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, void (__fastcall *a2)(_QWORD, _QWORD, __int64), __int64 a3)
{
__int64 i; // r13
_QWORD *j; // rbx

if ( !a1 )
_assert_fail("ht!=NULL", "hash.c", 0xDCu, "hash_table_foreach");
for ( i = 0LL; *(_DWORD *)a1 > (int)i; ++i )
{
for ( j = *(_QWORD **)(*(_QWORD *)(a1 + 8) + 8 * i); j; j = (_QWORD *)j[2] )
a2(*j, j[1], a3);
}
return 0LL;
}

original_code:
int hash_table_foreach(hash_table_t *ht,hash_fforeach user_fn,void *opt_arg)
{
   hash_node_t *node;
   int i;
   ((void) sizeof ((ht!=((void *)0)) ? 1 : 0), __extension__ ({ if (ht!=((void *)0)) ; else __assert_fail ("ht!=NULL", "hash.c", 220, __extension__ __PRETTY_FUNCTION__); }));
   for(i=0;i<ht->size;i++)
      for(node=ht->nodes[i];node;node=node->next)
         user_fn(node->key,node->value,opt_arg);
   return(0);
}

canonical_original_code:
int hash_table_foreach(struct hash_table *ht, void (*user_fn)(void *key, void *value, void *opt_arg), void *opt_arg)
{
   struct hash_node *node;
   int i;
   ((void) sizeof ((ht!=((void *)0)) ? 1 : 0), __extension__ ({ if (ht!=((void *)0)) ; else __assert_fail ("ht!=NULL", "hash.c", 220, __extension__ __PRETTY_FUNCTION__); }));
   for(i=0;i<ht->size;i++)
      for(node=ht->nodes[i];node;node=node->next)
         user_fn(node->key,node->value,opt_arg);
   return(0);
}

variable_types: void (*)(void *key, void *value, void *opt_arg)

variable_types: i int


decompiled_code:
__int64 gen_eth_show_dev_list()
{
_QWORD *i; // rbx
const char *v1; // rdx
__int64 result; // rax
_QWORD *v3; // [rsp+8h] [rbp-120h] BYREF
char v4[280]; // [rsp+10h] [rbp-118h] BYREF

puts("Network device list:\n");
if ( (int)pcap_findalldevs(&v3, v4) < 0 )
{
fprintf(stderr, "PCAP: unable to find device list (%s)\n", v4);
result = 0xFFFFFFFFLL;
}
else
{
for ( i = v3; i; i = (_QWORD *)*i )
{
v1 = (const char *)i[2];
if ( !v1 )
v1 = "no info provided";
printf(" %s : %s\n", i[1], v1);
}
putchar(10);
pcap_freealldevs(v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
_QWORD *i; // rbx
const char *v1; // rdx
__int64 result; // rax
_QWORD *v3; // [rsp+8h] [rbp-120h] BYREF
char v4[280]; // [rsp+10h] [rbp-118h] BYREF

puts("Network device list:\n");
if ( (int)pcap_findalldevs(&v3, v4) < 0 )
{
fprintf(stderr, "PCAP: unable to find device list (%s)\n", v4);
result = 0xFFFFFFFFLL;
}
else
{
for ( i = v3; i; i = (_QWORD *)*i )
{
v1 = (const char *)i[2];
if ( !v1 )
v1 = "no info provided";
printf(" %s : %s\n", i[1], v1);
}
putchar(10);
pcap_freealldevs(v3);
result = 0LL;
}
return result;
}

original_code:
int gen_eth_show_dev_list(void)
{
   char pcap_errbuf[256];
   pcap_if_t *dev_list,*dev;
   int res;
   printf("Network device list:\n\n");
   res = pcap_findalldevs(&dev_list,pcap_errbuf);
   if (res < 0) {
      fprintf(stderr,"PCAP: unable to find device list (%s)\n",pcap_errbuf);
      return(-1);
   }
   for(dev=dev_list;dev;dev=dev->next) {
      printf("   %s : %s\n",
             dev->name,
             dev->description ? dev->description : "no info provided");
   }
   printf("\n");
   pcap_freealldevs(dev_list);
   return(0);
}

canonical_original_code:
int gen_eth_show_dev_list()
{
   char pcap_errbuf[256];
   struct pcap_if *dev_list; struct pcap_if *dev;
   int res;
   printf("Network device list:\n\n");
   res = pcap_findalldevs(&dev_list,pcap_errbuf);
   if (res < 0) {
      fprintf(stderr,"PCAP: unable to find device list (%s)\n",pcap_errbuf);
      return(-1);
   }
   for(dev=dev_list;dev;dev=dev->next) {
      printf("   %s : %s\n",
             dev->name,
             dev->description ? dev->description : "no info provided");
   }
   printf("\n");
   pcap_freealldevs(dev_list);
   return(0);
}

variable_types: struct pcap_if { struct pcap_if *next; char *name; char *description; struct pcap_addr { struct pcap_addr *next; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *addr; struct sockaddr *netmask; struct sockaddr *broadaddr; struct sockaddr *dstaddr; } *addresses; unsigned int flags; } *

variable_types: res int

user_defined_types: struct pcap_if { struct pcap_if *next; char *name; char *description; struct pcap_addr *addresses; unsigned int flags; }

user_defined_types: struct pcap_addr { struct pcap_addr *next; struct sockaddr *addr; struct sockaddr *netmask; struct sockaddr *broadaddr; struct sockaddr *dstaddr; }


decompiled_code:
int __fastcall memblock_insert(__int64 *a1, _QWORD *a2)
{
__int64 v2; // rax

pthread_mutex_lock((pthread_mutex_t *)(a1 + 1));
a1[8] += a2[1];
v2 = *a1;
++*((_DWORD *)a1 + 15);
a2[3] = 0LL;
a2[2] = v2;
if ( v2 )
*(_QWORD *)(v2 + 24) = a2;
*a1 = (__int64)a2;
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 1));
}

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

pthread_mutex_lock((pthread_mutex_t *)(a1 + 1));
a1[8] += a2[1];
v2 = *a1;
++*((_DWORD *)a1 + 15);
a2[3] = 0LL;
a2[2] = v2;
if ( v2 )
*(_QWORD *)(v2 + 24) = a2;
*a1 = (__int64)a2;
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 1));
}

original_code:
static inline void memblock_insert(mempool_t *pool,memblock_t *block)
{
   pthread_mutex_lock(&(pool)->lock);
   pool->nr_blocks++;
   pool->total_size += block->block_size;
   block->prev = ((void *)0);
   block->next = pool->block_list;
   if (block->next)
      block->next->prev = block;
   pool->block_list = block;
   pthread_mutex_unlock(&(pool)->lock);
}

canonical_original_code:
static inline void memblock_insert(struct mempool *pool, struct memblock *block)
{
   pthread_mutex_lock(&(pool)->lock);
   pool->nr_blocks++;
   pool->total_size += block->block_size;
   block->prev = ((void *)0);
   block->next = pool->block_list;
   if (block->next)
      block->next->prev = block;
   pool->block_list = block;
   pthread_mutex_unlock(&(pool)->lock);
}

variable_types: struct mempool { struct memblock { int tag; unsigned long block_size; struct memblock *next; struct mempool *pool; unsigned long long data[]; } *block_list; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; char *name; int flags; int nr_blocks; unsigned long total_size; unsigned long max_size; } *

variable_types:
block
struct memblock *

user_defined_types: struct mempool { struct memblock *block_list; union pthread_mutex_t lock; char *name; int flags; int nr_blocks; unsigned long total_size; unsigned long max_size; }

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

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


original_code:
static inline void memblock_delete(mempool_t *pool,memblock_t *block)
{
   pthread_mutex_lock(&(pool)->lock);
   pool->nr_blocks--;
   pool->total_size -= block->block_size;
   if (!block->prev)
      pool->block_list = block->next;
   else
      block->prev->next = block->next;
   if (block->next)
      block->next->prev = block->prev;
   block->next = block->prev = ((void *)0);
   pthread_mutex_unlock(&(pool)->lock);
}

canonical_original_code:
static inline void memblock_delete(struct mempool *pool, struct memblock *block)
{
   pthread_mutex_lock(&(pool)->lock);
   pool->nr_blocks--;
   pool->total_size -= block->block_size;
   if (!block->prev)
      pool->block_list = block->next;
   else
      block->prev->next = block->next;
   if (block->next)
      block->next->prev = block->prev;
   block->next = block->prev = ((void *)0);
   pthread_mutex_unlock(&(pool)->lock);
}

user_defined_types: struct memblock { int tag; unsigned long block_size; struct memblock *next; struct mempool *pool; unsigned long long data[]; }

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


decompiled_code:
char *__fastcall mp_strdup(__int64 *a1, const char *a2)
{
size_t v2; // rax
char *v3; // rax
char *v4; // r8

v2 = strlen(a2);
v3 = (char *)mp_alloc(a1, v2 + 1);
v4 = v3;
if ( v3 )
v4 = strcpy(v3, a2);
return v4;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 *a1, const char *a2)
{
size_t v2; // rax
char *v3; // rax
char *v4; // r8

v2 = strlen(a2);
v3 = (char *)mp_alloc(a1, v2 + 1);
v4 = v3;
if ( v3 )
v4 = strcpy(v3, a2);
return v4;
}

original_code:
char *mp_strdup(mempool_t *pool,char *str)
{
   char *new_str;
   if ((new_str = mp_alloc(pool,strlen(str)+1)) == ((void *)0))
      return ((void *)0);
   strcpy(new_str,str);
   return new_str;
}

canonical_original_code:
char *mp_strdup(struct mempool *pool, char *str)
{
   char *new_str;
   if ((new_str = mp_alloc(pool,strlen(str)+1)) == ((void *)0))
      return ((void *)0);
   strcpy(new_str,str);
   return new_str;
}

variable_types:
str
char *

return_type: char *


decompiled_code:
__int64 __fastcall mp_free(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)(a1 - 40) != -559038737 )
_assert_fail("block->tag == MEMBLOCK_TAG", "mempool.c", 0xA8u, "mp_free");
memblock_delete(*(_QWORD *)(a1 - 8), (_QWORD *)(a1 - 40));
*(_QWORD *)(a1 - 8) = 0LL;
*(_OWORD *)(a1 - 40) = 0LL;
*(_OWORD *)(a1 - 24) = 0LL;
free((void *)(a1 - 40));
return 0LL;
}

original_code:
int mp_free(void *addr)
{
   memblock_t *block = (memblock_t *)addr - 1;
   mempool_t *pool;
   if (addr != ((void *)0)) {
      ((void) sizeof ((block->tag == 0xdeadbeef) ? 1 : 0), __extension__ ({ if (block->tag == 0xdeadbeef) ; else __assert_fail ("block->tag == MEMBLOCK_TAG", "mempool.c", 168, __extension__ __PRETTY_FUNCTION__); }));
      pool = block->pool;
      memblock_delete(pool,block);
      memset(block,0,sizeof(memblock_t));
      free(block);
   }
   return(0);
}

canonical_original_code:
int mp_free(void *addr)
{
   struct memblock *block = (memblock_t *)addr - 1;
   struct mempool *pool;
   if (addr != ((void *)0)) {
      ((void) sizeof ((block->tag == 0xdeadbeef) ? 1 : 0), __extension__ ({ if (block->tag == 0xdeadbeef) ; else __assert_fail ("block->tag == MEMBLOCK_TAG", "mempool.c", 168, __extension__ __PRETTY_FUNCTION__); }));
      pool = block->pool;
      memblock_delete(pool,block);
      memset(block,0,sizeof(memblock_t));
      free(block);
   }
   return(0);
}

variable_types:
addr
void *

variable_types: struct memblock { int tag; unsigned long block_size; struct memblock *next; struct mempool { struct memblock *block_list; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; char *name; int flags; int nr_blocks; unsigned long total_size; unsigned long max_size; } *pool; unsigned long long data[]; } *


decompiled_code:
__int64 __fastcall mp_free_ptr(__int64 *a1)
{
__int64 v1; // r8

if ( !a1 )
_assert_fail("addr != NULL", "mempool.c", 0xB8u, "mp_free_ptr");
v1 = *a1;
*a1 = 0LL;
mp_free(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1)
{
__int64 v1; // r8

if ( !a1 )
_assert_fail("addr != NULL", "mempool.c", 0xB8u, "mp_free_ptr");
v1 = *a1;
*a1 = 0LL;
func4(v1);
return 0LL;
}

original_code:
int mp_free_ptr(void *addr)
{
   void *p;
   ((void) sizeof ((addr != ((void *)0)) ? 1 : 0), __extension__ ({ if (addr != ((void *)0)) ; else __assert_fail ("addr != NULL", "mempool.c", 184, __extension__ __PRETTY_FUNCTION__); }));
   p = *(void **)addr;
   *(void **)addr = ((void *)0);
   mp_free(p);
   return(0);
}

variable_types:
p
void *


decompiled_code:
int __fastcall mp_free_all_blocks(__int64 a1)
{
pthread_mutex_t *v1; // r12
_QWORD *v3; // rbx
void *v4; // rdi

v1 = (pthread_mutex_t *)(a1 + 8);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
v3 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
while ( v3 );
}
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 60) = 0;
*(_QWORD *)(a1 + 64) = 0LL;
return pthread_mutex_unlock(v1);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
pthread_mutex_t *v1; // r12
_QWORD *v3; // rbx
void *v4; // rdi

v1 = (pthread_mutex_t *)(a1 + 8);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
v3 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
while ( v3 );
}
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 60) = 0;
*(_QWORD *)(a1 + 64) = 0LL;
return pthread_mutex_unlock(v1);
}

original_code:
void mp_free_all_blocks(mempool_t *pool)
{
   memblock_t *block,*next;
   pthread_mutex_lock(&(pool)->lock);
   for(block=pool->block_list;block;block=next) {
      next = block->next;
      free(block);
   }
   pool->block_list = ((void *)0);
   pool->nr_blocks = 0;
   pool->total_size = 0;
   pthread_mutex_unlock(&(pool)->lock);
}

canonical_original_code:
void mp_free_all_blocks(struct mempool *pool)
{
   struct memblock *block; struct memblock *next;
   pthread_mutex_lock(&(pool)->lock);
   for(block=pool->block_list;block;block=next) {
      next = block->next;
      free(block);
   }
   pool->block_list = ((void *)0);
   pool->nr_blocks = 0;
   pool->total_size = 0;
   pthread_mutex_unlock(&(pool)->lock);
}


decompiled_code:
void __fastcall mp_free_pool(void *ptr)
{
mp_free_all_blocks((__int64)ptr);
if ( (*((_BYTE *)ptr + 56) & 1) == 0 )
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
func6((__int64)ptr);
if ( (*((_BYTE *)ptr + 56) & 1) == 0 )
free(ptr);
}

original_code:
void mp_free_pool(mempool_t *pool)
{
   mp_free_all_blocks(pool);
   if (!(pool->flags & 1))
      free(pool);
}

canonical_original_code:
void mp_free_pool(struct mempool *pool)
{
   mp_free_all_blocks(pool);
   if (!(pool->flags & 1))
      free(pool);
}


decompiled_code:
__int64 __fastcall parser_get_char_type(unsigned __int8 a1)
{
__int64 result; // rax

result = 4LL;
if ( a1 <= 0x23u )
result = (unsigned int)CSWTCH_4[a1];
return result;
}

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

result = 4LL;
if ( a1 <= 0x23u )
result = (unsigned int)CSWTCH_4[a1];
return result;
}

original_code:
static int parser_get_char_type(u_char c)
{
   switch(c) {
      case '\n':
      case '\r':
      case 0:
         return(PARSER_CHAR_NEWLINE);
      case '\t':
      case ' ':
         return(PARSER_CHAR_BLANK);
      case '!':
      case '#':
         return(PARSER_CHAR_COMMENT);
      case '"':
         return(PARSER_CHAR_QUOTE);
      default:
         return(PARSER_CHAR_OTHER);
   }
}

canonical_original_code:
static int parser_get_char_type(unsigned char c)
{
   switch(c) {
      case '\n':
      case '\r':
      case 0:
         return(PARSER_CHAR_NEWLINE);
      case '\t':
      case ' ':
         return(PARSER_CHAR_BLANK);
      case '!':
      case '#':
         return(PARSER_CHAR_COMMENT);
      case '"':
         return(PARSER_CHAR_QUOTE);
      default:
         return(PARSER_CHAR_OTHER);
   }
}

variable_types:
c
unsigned char


decompiled_code:
__int64 __fastcall parser_move_tmp_token(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
_QWORD *v3; // rax
__int64 v4; // rdx

result = 0LL;
v2 = *(_QWORD *)(a1 + 24);
if ( v2 )
{
v3 = malloc(0x10uLL);
if ( v3 )
{
v4 = *(_QWORD *)(a1 + 8);
*v3 = v2;
v3[1] = 0LL;
if ( v4 )
*(_QWORD *)(v4 + 8) = v3;
else
*(_QWORD *)a1 = v3;
++*(_DWORD *)(a1 + 16);
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 40) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 8) = v3;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
static int parser_move_tmp_token(parser_context_t *ctx)
{
   parser_token_t *tok;
   if (!ctx->tmp_tok)
      return(0);
   if (!(tok = malloc(sizeof(*tok))))
      return(-1);
   tok->value = ctx->tmp_tok;
   tok->next = ((void *)0);
   if (ctx->tok_last != ((void *)0))
      ctx->tok_last->next = tok;
   else
      ctx->tok_head = tok;
   ctx->tok_last = tok;
   ctx->tok_count++;
   ctx->tmp_tok = ((void *)0);
   ctx->tmp_tot_len = ctx->tmp_cur_len = 0;
   return(0);
}

canonical_original_code:
static int parser_move_tmp_token(struct parser_context *ctx)
{
   struct parser_token *tok;
   if (!ctx->tmp_tok)
      return(0);
   if (!(tok = malloc(sizeof(*tok))))
      return(-1);
   tok->value = ctx->tmp_tok;
   tok->next = ((void *)0);
   if (ctx->tok_last != ((void *)0))
      ctx->tok_last->next = tok;
   else
      ctx->tok_head = tok;
   ctx->tok_last = tok;
   ctx->tok_count++;
   ctx->tmp_tok = ((void *)0);
   ctx->tmp_tot_len = ctx->tmp_cur_len = 0;
   return(0);
}

variable_types: struct parser_context { struct parser_token { char *value; struct parser_token *next; } *tok_head; int tok_count; char *tmp_tok; unsigned long tmp_tot_len; int state; unsigned long consumed_len; } *

user_defined_types: struct parser_context { struct parser_token *tok_head; int tok_count; char *tmp_tok; unsigned long tmp_tot_len; int state; unsigned long consumed_len; }


original_code:
static int tmp_token_add_char(parser_context_t *ctx,char c)
{
   size_t new_size;
   char *new_str;
   if (!ctx->tmp_tok || (ctx->tmp_cur_len == (ctx->tmp_tot_len - 1))) {
      new_size = ctx->tmp_tot_len + 512;
      new_str = realloc(ctx->tmp_tok,new_size);
      if (!new_str)
         return(-1);
      ctx->tmp_tok = new_str;
      ctx->tmp_tot_len = new_size;
   }
   ctx->tmp_tok[ctx->tmp_cur_len++] = c;
   ctx->tmp_tok[ctx->tmp_cur_len] = 0;
   return(0);
}

canonical_original_code:
static int tmp_token_add_char(struct parser_context *ctx, char c)
{
   unsigned long new_size;
   char *new_str;
   if (!ctx->tmp_tok || (ctx->tmp_cur_len == (ctx->tmp_tot_len - 1))) {
      new_size = ctx->tmp_tot_len + 512;
      new_str = realloc(ctx->tmp_tok,new_size);
      if (!new_str)
         return(-1);
      ctx->tmp_tok = new_str;
      ctx->tmp_tot_len = new_size;
   }
   ctx->tmp_tok[ctx->tmp_cur_len++] = c;
   ctx->tmp_tok[ctx->tmp_cur_len] = 0;
   return(0);
}

variable_types: c char

user_defined_types: struct parser_token { char *value; struct parser_token *next; }


decompiled_code:
const char *__fastcall parser_strerror(__int64 a1)
{
__int64 v1; // rax
const char *v2; // r8

printf("error = %d\n", *(unsigned int *)(a1 + 52));
v1 = *(unsigned int *)(a1 + 52);
v2 = "unknown error";
if ( (unsigned int)v1 <= 3 )
v2 = CSWTCH_8[v1];
return v2;
}

canonical_decompiled_code:
const char *__fastcall func3(__int64 a1)
{
__int64 v1; // rax
const char *v2; // r8

printf("error = %d\n", *(unsigned int *)(a1 + 52));
v1 = *(unsigned int *)(a1 + 52);
v2 = "unknown error";
if ( (unsigned int)v1 <= 3 )
v2 = CSWTCH_8[v1];
return v2;
}

original_code:
char *parser_strerror(parser_context_t *ctx)
{
   printf("error = %d\n",ctx->error);
   switch(ctx->error) {
      case 0:
         return "no error";
      case PARSER_ERROR_NOMEM:
         return "insufficient memory";
      case PARSER_ERROR_UNEXP_QUOTE:
         return "unexpected quote";
      case PARSER_ERROR_UNEXP_EOL:
         return "unexpected end of line";
      default:
         return "unknown error";
   }
}

canonical_original_code:
char *parser_strerror(struct parser_context *ctx)
{
   printf("error = %d\n",ctx->error);
   switch(ctx->error) {
      case 0:
         return "no error";
      case PARSER_ERROR_NOMEM:
         return "insufficient memory";
      case PARSER_ERROR_UNEXP_QUOTE:
         return "unexpected quote";
      case PARSER_ERROR_UNEXP_EOL:
         return "unexpected end of line";
      default:
         return "unknown error";
   }
}


decompiled_code:
int __fastcall parser_dump_tokens(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 8) )
result = printf("\"%s\" ", *(const char **)i);
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 8) )
result = printf("\"%s\" ", *(const char **)i);
return result;
}

original_code:
void parser_dump_tokens(parser_context_t *ctx)
{
   parser_token_t *tok;
   for(tok=ctx->tok_head;tok;tok=tok->next)
      printf("\"%s\" ",tok->value);
}

canonical_original_code:
void parser_dump_tokens(struct parser_context *ctx)
{
   struct parser_token *tok;
   for(tok=ctx->tok_head;tok;tok=tok->next)
      printf("\"%s\" ",tok->value);
}

variable_types: struct parser_token { char *value; struct parser_token *next; } *


original_code:
void parser_context_init(parser_context_t *ctx)
{
   ctx->tok_head = ctx->tok_last = ((void *)0);
   ctx->tok_count = 0;
   ctx->tmp_tok = ((void *)0);
   ctx->tmp_tot_len = ctx->tmp_cur_len = 0;
   ctx->state = PARSER_STATE_BLANK;
   ctx->error = 0;
   ctx->consumed_len = 0;
}

canonical_original_code:
void parser_context_init(struct parser_context *ctx)
{
   ctx->tok_head = ctx->tok_last = ((void *)0);
   ctx->tok_count = 0;
   ctx->tmp_tok = ((void *)0);
   ctx->tmp_tot_len = ctx->tmp_cur_len = 0;
   ctx->state = PARSER_STATE_BLANK;
   ctx->error = 0;
   ctx->consumed_len = 0;
}


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

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

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

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

original_code:
void parser_free_tokens(parser_token_t *tok_list)
{
   parser_token_t *t,*next;
   for(t=tok_list;t;t=next) {
      next = t->next;
      free(t->value);
      free(t);
   }
}

canonical_original_code:
void parser_free_tokens(struct parser_token *tok_list)
{
   struct parser_token *t; struct parser_token *next;
   for(t=tok_list;t;t=next) {
      next = t->next;
      free(t->value);
      free(t);
   }
}


decompiled_code:
void __fastcall parser_context_free(__int64 a1)
{
void *v2; // rdi

parser_free_tokens(*(void **)a1);
v2 = *(void **)(a1 + 24);
if ( v2 )
free(v2);
parser_context_init(a1);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
void *v2; // rdi

func7(*(void **)a1);
v2 = *(void **)(a1 + 24);
if ( v2 )
free(v2);
func6(a1);
}

original_code:
void parser_context_free(parser_context_t *ctx)
{
   parser_free_tokens(ctx->tok_head);
   if (ctx->tmp_tok != ((void *)0))
      free(ctx->tmp_tok);
   parser_context_init(ctx);
}

canonical_original_code:
void parser_context_free(struct parser_context *ctx)
{
   parser_free_tokens(ctx->tok_head);
   if (ctx->tmp_tok != ((void *)0))
      free(ctx->tmp_tok);
   parser_context_init(ctx);
}


decompiled_code:
__int64 __fastcall parser_scan_buffer(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
int v4; // edx
unsigned __int8 *v5; // r13
unsigned __int8 *v6; // rbx
char v7; // si
int v8; // eax

v4 = *(_DWORD *)(a1 + 48);
if ( a3 )
{
v5 = a2;
v6 = &a2[a3];
LABEL_3:
if ( !v4 )
return v4 == 0;
while ( 1 )
{
while ( 1 )
{
++*(_QWORD *)(a1 + 56);
v7 = *v5;
v8 = parser_get_char_type(*v5);
if ( v4 != 3 )
break;
if ( v8 == 2 )
{
if ( (unsigned int)parser_move_tmp_token(a1) == -1 )
*(_DWORD *)(a1 + 52) = 1;
LABEL_41:
++v5;
*(_DWORD *)(a1 + 48) = 1;
if ( v6 == v5 )
return 0LL;
}
else if ( v8 > 2 )
{
if ( v8 != 3 )
goto LABEL_17;
++v5;
*(_QWORD *)(a1 + 48) = 0x200000001LL;
if ( v6 == v5 )
return 0LL;
}
else
{
if ( v8 )
{
if ( v8 == 1 )
{
if ( (unsigned int)parser_move_tmp_token(a1) == -1 )
*(_DWORD *)(a1 + 52) = 1;
LABEL_12:
*(_DWORD *)(a1 + 48) = 0;
v4 = 0;
return v4 == 0;
}
goto LABEL_17;
}
LABEL_36:
if ( (unsigned int)parser_move_tmp_token(a1) )
goto LABEL_37;
++v5;
*(_DWORD *)(a1 + 48) = 2;
v4 = 2;
if ( v6 == v5 )
return v4 == 0;
}
}
if ( v4 > 3 )
{
if ( v4 != 4 )
goto LABEL_19;
if ( v8 == 1 )
{
*(_QWORD *)(a1 + 48) = 0x300000000LL;
return 1LL;
}
if ( v8 == 3 )
goto LABEL_36;
LABEL_17:
if ( (unsigned int)tmp_token_add_char((_QWORD *)a1, v7) != -1 )
{
v4 = *(_DWORD *)(a1 + 48);
LABEL_19:
if ( v6 == ++v5 )
return v4 == 0;
goto LABEL_3;
}
LABEL_37:
++v5;
*(_QWORD *)(a1 + 48) = 0x100000001LL;
if ( v6 == v5 )
return 0LL;
}
else if ( v4 == 1 )
{
if ( v8 == 1 )
goto LABEL_12;
if ( v6 == ++v5 )
return v4 == 0;
}
else
{
if ( v4 != 2 )
goto LABEL_19;
if ( v8 == 2 )
goto LABEL_41;
if ( v8 > 2 )
{
if ( v8 != 3 )
goto LABEL_46;
++v5;
*(_DWORD *)(a1 + 48) = 4;
v4 = 4;
if ( v6 == v5 )
return v4 == 0;
}
else
{
if ( !v8 )
goto LABEL_19;
if ( v8 == 1 )
goto LABEL_12;
LABEL_46:
if ( (unsigned int)tmp_token_add_char((_QWORD *)a1, v7) )
goto LABEL_37;
++v5;
*(_DWORD *)(a1 + 48) = 3;
v4 = 3;
if ( v6 == v5 )
return v4 == 0;
}
}
}
}
return v4 == 0;
}

original_code:
int parser_scan_buffer(parser_context_t *ctx,char *buf,size_t buf_size)
{
   int i,type;
   u_char c;
   for(i=0;(i<buf_size) && (ctx->state != PARSER_STATE_DONE);i++)
   {
      ctx->consumed_len++;
      c = buf[i];
      type = parser_get_char_type(c);
      switch(ctx->state) {
         case PARSER_STATE_SKIP:
            if (type == PARSER_CHAR_NEWLINE)
               ctx->state = PARSER_STATE_DONE;
            break;
         case PARSER_STATE_BLANK:
            switch(type) {
               case PARSER_CHAR_BLANK:
                  break;
               case PARSER_CHAR_COMMENT:
                  ctx->state = PARSER_STATE_SKIP;
                  break;
               case PARSER_CHAR_NEWLINE:
                  ctx->state = PARSER_STATE_DONE;
                  break;
               case PARSER_CHAR_QUOTE:
                  ctx->state = PARSER_STATE_QUOTED_STRING;
                  break;
               default:
                  if (!tmp_token_add_char(ctx,c)) {
                     ctx->state = PARSER_STATE_STRING;
                  } else {
                     ctx->state = PARSER_STATE_SKIP;
                     ctx->error = PARSER_ERROR_NOMEM;
                  }
            }
            break;
         case PARSER_STATE_STRING:
            switch(type) {
               case PARSER_CHAR_BLANK:
                  if (!parser_move_tmp_token(ctx)) {
                     ctx->state = PARSER_STATE_BLANK;
                  } else {
                     ctx->state = PARSER_STATE_SKIP;
                     ctx->error = PARSER_ERROR_NOMEM;
                  }
                  break;
               case PARSER_CHAR_NEWLINE:
                  if (parser_move_tmp_token(ctx) == -1)
                     ctx->error = PARSER_ERROR_NOMEM;
                  ctx->state = PARSER_STATE_DONE;
                  break;
               case PARSER_CHAR_COMMENT:
                  if (parser_move_tmp_token(ctx) == -1)
                     ctx->error = PARSER_ERROR_NOMEM;
                  ctx->state = PARSER_STATE_SKIP;
                  break;
               case PARSER_CHAR_QUOTE:
                  ctx->error = PARSER_ERROR_UNEXP_QUOTE;
                  ctx->state = PARSER_STATE_SKIP;
                  break;
               default:
                  if (tmp_token_add_char(ctx,c) == -1) {
                     ctx->state = PARSER_STATE_SKIP;
                     ctx->error = PARSER_ERROR_NOMEM;
                  }
            }
            break;
         case PARSER_STATE_QUOTED_STRING:
            switch(type) {
               case PARSER_CHAR_NEWLINE:
                  ctx->error = PARSER_ERROR_UNEXP_EOL;
                  ctx->state = PARSER_STATE_DONE;
                  break;
               case PARSER_CHAR_QUOTE:
                  if (!parser_move_tmp_token(ctx)) {
                     ctx->state = PARSER_STATE_BLANK;
                  } else {
                     ctx->state = PARSER_STATE_SKIP;
                     ctx->error = PARSER_ERROR_NOMEM;
                  }
                  break;
               default:
                  if (tmp_token_add_char(ctx,c) == -1) {
                     ctx->state = PARSER_STATE_SKIP;
                     ctx->error = PARSER_ERROR_NOMEM;
                  }
            }
            break;
      }
   }
   return(ctx->state == PARSER_STATE_DONE);
}

canonical_original_code:
int parser_scan_buffer(struct parser_context *ctx, char *buf, unsigned long buf_size)
{
   int i; int type;
   unsigned char c;
   for(i=0;(i<buf_size) && (ctx->state != PARSER_STATE_DONE);i++)
   {
      ctx->consumed_len++;
      c = buf[i];
      type = parser_get_char_type(c);
      switch(ctx->state) {
         case PARSER_STATE_SKIP:
            if (type == PARSER_CHAR_NEWLINE)
               ctx->state = PARSER_STATE_DONE;
            break;
         case PARSER_STATE_BLANK:
            switch(type) {
               case PARSER_CHAR_BLANK:
                  break;
               case PARSER_CHAR_COMMENT:
                  ctx->state = PARSER_STATE_SKIP;
                  break;
               case PARSER_CHAR_NEWLINE:
                  ctx->state = PARSER_STATE_DONE;
                  break;
               case PARSER_CHAR_QUOTE:
                  ctx->state = PARSER_STATE_QUOTED_STRING;
                  break;
               default:
                  if (!tmp_token_add_char(ctx,c)) {
                     ctx->state = PARSER_STATE_STRING;
                  } else {
                     ctx->state = PARSER_STATE_SKIP;
                     ctx->error = PARSER_ERROR_NOMEM;
                  }
            }
            break;
         case PARSER_STATE_STRING:
            switch(type) {
               case PARSER_CHAR_BLANK:
                  if (!parser_move_tmp_token(ctx)) {
                     ctx->state = PARSER_STATE_BLANK;
                  } else {
                     ctx->state = PARSER_STATE_SKIP;
                     ctx->error = PARSER_ERROR_NOMEM;
                  }
                  break;
               case PARSER_CHAR_NEWLINE:
                  if (parser_move_tmp_token(ctx) == -1)
                     ctx->error = PARSER_ERROR_NOMEM;
                  ctx->state = PARSER_STATE_DONE;
                  break;
               case PARSER_CHAR_COMMENT:
                  if (parser_move_tmp_token(ctx) == -1)
                     ctx->error = PARSER_ERROR_NOMEM;
                  ctx->state = PARSER_STATE_SKIP;
                  break;
               case PARSER_CHAR_QUOTE:
                  ctx->error = PARSER_ERROR_UNEXP_QUOTE;
                  ctx->state = PARSER_STATE_SKIP;
                  break;
               default:
                  if (tmp_token_add_char(ctx,c) == -1) {
                     ctx->state = PARSER_STATE_SKIP;
                     ctx->error = PARSER_ERROR_NOMEM;
                  }
            }
            break;
         case PARSER_STATE_QUOTED_STRING:
            switch(type) {
               case PARSER_CHAR_NEWLINE:
                  ctx->error = PARSER_ERROR_UNEXP_EOL;
                  ctx->state = PARSER_STATE_DONE;
                  break;
               case PARSER_CHAR_QUOTE:
                  if (!parser_move_tmp_token(ctx)) {
                     ctx->state = PARSER_STATE_BLANK;
                  } else {
                     ctx->state = PARSER_STATE_SKIP;
                     ctx->error = PARSER_ERROR_NOMEM;
                  }
                  break;
               default:
                  if (tmp_token_add_char(ctx,c) == -1) {
                     ctx->state = PARSER_STATE_SKIP;
                     ctx->error = PARSER_ERROR_NOMEM;
                  }
            }
            break;
      }
   }
   return(ctx->state == PARSER_STATE_DONE);
}

variable_types:
buf
char *

variable_types: type int


decompiled_code:
void parser_run_tests()
{
char *v0; // r12
__int64 v1; // rbp
size_t v2; // rax
__int64 v3; // rbx
__int64 v4[6]; // [rsp+0h] [rbp-58h] BYREF
unsigned int v5; // [rsp+30h] [rbp-28h]
int v6; // [rsp+34h] [rbp-24h]

v0 = "c7200 show_hardware R1";
v1 = 0LL;
do
{
parser_context_init((__int64)v4);
v2 = strlen(v0);
v3 = (unsigned int)parser_scan_buffer((__int64)v4, (unsigned __int8 *)v0, v2 + 1);
printf("\n%d: Test string: [%s] => res=%d, state=%d\n", (unsigned int)v1, v0, v3, v5);
if ( (_DWORD)v3 && !v6 )
{
if ( v4[0] )
{
printf("Tokens: ");
parser_dump_tokens(v4);
putchar(10);
}
}
++v1;
parser_context_free((__int64)v4);
v0 = parser_test_str[v1];
}
while ( v0 );
}

canonical_decompiled_code:
void func10()
{
char *v0; // r12
__int64 v1; // rbp
size_t v2; // rax
__int64 v3; // rbx
__int64 v4[6]; // [rsp+0h] [rbp-58h] BYREF
unsigned int v5; // [rsp+30h] [rbp-28h]
int v6; // [rsp+34h] [rbp-24h]

v0 = "c7200 show_hardware R1";
v1 = 0LL;
do
{
func6((__int64)v4);
v2 = strlen(v0);
v3 = (unsigned int)func9((__int64)v4, (unsigned __int8 *)v0, v2 + 1);
printf("\n%d: Test string: [%s] => res=%d, state=%d\n", (unsigned int)v1, v0, v3, v5);
if ( (_DWORD)v3 && !v6 )
{
if ( v4[0] )
{
printf("Tokens: ");
func4(v4);
putchar(10);
}
}
++v1;
func8((__int64)v4);
v0 = parser_test_str[v1];
}
while ( v0 );
}

original_code:
void parser_run_tests(void)
{
   parser_context_t ctx;
   int i,res;
   for(i=0;parser_test_str[i];i++) {
      parser_context_init(&ctx);
      res = parser_scan_buffer(&ctx,parser_test_str[i],
                               strlen(parser_test_str[i])+1);
      printf("\n%d: Test string: [%s] => res=%d, state=%d\n",
             i,parser_test_str[i],res,ctx.state);
      if ((res != 0) && (ctx.error == 0)) {
         if (ctx.tok_head) {
            printf("Tokens: ");
            parser_dump_tokens(&ctx);
            printf("\n");
         }
      }
      parser_context_free(&ctx);
   }
}

canonical_original_code:
void parser_run_tests()
{
   struct parser_context ctx;
   int i; int res;
   for(i=0;parser_test_str[i];i++) {
      parser_context_init(&ctx);
      res = parser_scan_buffer(&ctx,parser_test_str[i],
                               strlen(parser_test_str[i])+1);
      printf("\n%d: Test string: [%s] => res=%d, state=%d\n",
             i,parser_test_str[i],res,ctx.state);
      if ((res != 0) && (ctx.error == 0)) {
         if (ctx.tok_head) {
            printf("Tokens: ");
            parser_dump_tokens(&ctx);
            printf("\n");
         }
      }
      parser_context_free(&ctx);
   }
}

variable_types: struct parser_context { struct parser_token { char *value; struct parser_token *next; } *tok_head; int tok_count; char *tmp_tok; unsigned long tmp_tot_len; int state; unsigned long consumed_len; }


decompiled_code:
__int64 __fastcall lnx_eth_get_dev_index(char *src)
{
int v1; // eax
int v2; // ebp
__int64 result; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
__int128 v8; // [rsp+0h] [rbp-48h] BYREF
__int128 v9; // [rsp+10h] [rbp-38h]
__int64 v10; // [rsp+20h] [rbp-28h]

v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "eth_get_dev_index: socket: %s\n", v5);
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
v10 = 0LL;
v8 = 0LL;
v9 = 0LL;
strcpy((char *)&v8, src);
if ( ioctl(v2, 0x8933uLL, &v8) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "eth_get_dev_index: SIOCGIFINDEX: %s\n", v7);
close(v2);
result = 0xFFFFFFFFLL;
}
else
{
close(v2);
result = (unsigned int)v9;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src)
{
int v1; // eax
int v2; // ebp
__int64 result; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
__int128 v8; // [rsp+0h] [rbp-48h] BYREF
__int128 v9; // [rsp+10h] [rbp-38h]
__int64 v10; // [rsp+20h] [rbp-28h]

v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "eth_get_dev_index: socket: %s\n", v5);
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
v10 = 0LL;
v8 = 0LL;
v9 = 0LL;
strcpy((char *)&v8, src);
if ( ioctl(v2, 0x8933uLL, &v8) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "eth_get_dev_index: SIOCGIFINDEX: %s\n", v7);
close(v2);
result = 0xFFFFFFFFLL;
}
else
{
close(v2);
result = (unsigned int)v9;
}
}
return result;
}

original_code:
int lnx_eth_get_dev_index(char *name)
{
   struct ifreq if_req;
   int fd;
   if ((fd = socket(2, SOCK_STREAM, 0)) < 0) {
      fprintf(stderr,"eth_get_dev_index: socket: %s\n",strerror((*__errno_location ())));
      return(-1);
   }
   memset((void *)&if_req,0,sizeof(if_req));
   strcpy(if_req.ifr_ifrn.ifrn_name,name);
   if (ioctl(fd,0x8933,&if_req) < 0) {
      fprintf(stderr,"eth_get_dev_index: SIOCGIFINDEX: %s\n",strerror((*__errno_location ())));
      close(fd);
      return(-1);
   }
   close(fd);
   return(if_req.ifr_ifru.ifru_ivalue);
}

variable_types:
name
char *

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto { unsigned short encoding; unsigned short parity; } *raw_hdlc; struct cisco_proto { unsigned int interval; unsigned int timeout; } *cisco; struct fr_proto { unsigned int t391; unsigned int t392; unsigned int n391; unsigned int n392; unsigned int n393; unsigned short lmi; unsigned short dce; } *fr; struct fr_proto_pvc { unsigned int dlci; } *fr_pvc; struct fr_proto_pvc_info { unsigned int dlci; char master[16]; } *fr_pvc_info; struct sync_serial_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; } *sync; struct te1_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; unsigned int slot_map; } *te1; } ifs_ifsu; } ifru_settings; } ifr_ifru; }

variable_types: fd int

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings ifru_settings; } ifr_ifru; }

user_defined_types: struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto *raw_hdlc; struct cisco_proto *cisco; struct fr_proto *fr; struct fr_proto_pvc *fr_pvc; struct fr_proto_pvc_info *fr_pvc_info; struct sync_serial_settings *sync; struct te1_settings *te1; } ifs_ifsu; }


decompiled_code:
__int64 __fastcall lnx_eth_init_socket(char *src)
{
int v1; // ebx
unsigned int v2; // er12
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
__int128 v10; // [rsp+0h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
int v12; // [rsp+20h] [rbp-28h]

v1 = (unsigned __int16)_bswap_16_constprop_0(17LL, 3LL);
v2 = socket(17, 3, v1);
if ( v2 == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "eth_init_socket: socket: %s\n", v5);
}
else
{
addr = 0LL;
v12 = 0;
*(_WORD *)&addr.sa_data[6] = 1;
addr.sa_family = 17;
*(_WORD *)addr.sa_data = v1;
addr.sa_data[9] = 6;
v10 = 0LL;
*(_DWORD *)&addr.sa_data[2] = lnx_eth_get_dev_index(src);
LODWORD(v10) = *(_DWORD *)&addr.sa_data[2];
WORD2(v10) = 1;
if ( bind(v2, &addr, 0x14u) == -1 )
{
v6 = _errno_location();
v2 = -1;
v7 = strerror(*v6);
fprintf(stderr, "eth_init_socket: bind: %s\n", v7);
}
else if ( setsockopt(v2, 263, 1, &v10, 0x10u) == -1 )
{
v8 = _errno_location();
v2 = -1;
v9 = strerror(*v8);
fprintf(stderr, "eth_init_socket: setsockopt: %s\n", v9);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src)
{
int v1; // ebx
unsigned int v2; // er12
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
__int128 v10; // [rsp+0h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
int v12; // [rsp+20h] [rbp-28h]

v1 = (unsigned __int16)func0(17LL, 3LL);
v2 = socket(17, 3, v1);
if ( v2 == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "eth_init_socket: socket: %s\n", v5);
}
else
{
addr = 0LL;
v12 = 0;
*(_WORD *)&addr.sa_data[6] = 1;
addr.sa_family = 17;
*(_WORD *)addr.sa_data = v1;
addr.sa_data[9] = 6;
v10 = 0LL;
*(_DWORD *)&addr.sa_data[2] = func1(src);
LODWORD(v10) = *(_DWORD *)&addr.sa_data[2];
WORD2(v10) = 1;
if ( bind(v2, &addr, 0x14u) == -1 )
{
v6 = _errno_location();
v2 = -1;
v7 = strerror(*v6);
fprintf(stderr, "eth_init_socket: bind: %s\n", v7);
}
else if ( setsockopt(v2, 263, 1, &v10, 0x10u) == -1 )
{
v8 = _errno_location();
v2 = -1;
v9 = strerror(*v8);
fprintf(stderr, "eth_init_socket: setsockopt: %s\n", v9);
}
}
return v2;
}

original_code:
int lnx_eth_init_socket(char *device)
{
   struct sockaddr_ll sa;
   struct packet_mreq mreq;
   int sck;
   if ((sck = socket(17,SOCK_RAW,htons(0x0003))) == -1) {
      fprintf(stderr,"eth_init_socket: socket: %s\n",strerror((*__errno_location ())));
      return(-1);
   }
   memset(&sa,0,sizeof(struct sockaddr_ll));
   sa.sll_family = 17;
   sa.sll_protocol = htons(0x0003);
   sa.sll_hatype = 1;
   sa.sll_halen = 6;
   sa.sll_ifindex = lnx_eth_get_dev_index(device);
   memset(&mreq,0,sizeof(mreq));
   mreq.mr_ifindex = sa.sll_ifindex;
   mreq.mr_type = 1;
   if (bind(sck,(struct sockaddr *)&sa,sizeof(struct sockaddr_ll)) == -1) {
      fprintf(stderr,"eth_init_socket: bind: %s\n",strerror((*__errno_location ())));
      return(-1);
   }
   if (setsockopt(sck,263,1,
                  &mreq,sizeof(mreq)) == -1)
   {
      fprintf(stderr,"eth_init_socket: setsockopt: %s\n",strerror((*__errno_location ())));
      return(-1);
   }
   return(sck);
}

variable_types:
device
char *

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }

variable_types: struct packet_mreq { int mr_ifindex; unsigned short mr_type; unsigned short mr_alen; unsigned char mr_address[8]; }

variable_types: sck int

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
ssize_t __fastcall lnx_eth_send(__int64 a1, __int64 a2, const void *a3)
{
__int16 v4; // ax
unsigned __int16 v5; // cx
int v6; // er8
size_t v7; // rdx
socklen_t v8; // er9
struct sockaddr v10; // [rsp+0h] [rbp-28h] BYREF
int v11; // [rsp+10h] [rbp-18h]

v10.sa_family = 17;
v11 = 0;
v4 = _bswap_16_constprop_0(a1, a3);
*(_QWORD *)&v10.sa_data[6] = v5;
*(_DWORD *)&v10.sa_data[2] = v6;
*(_WORD *)v10.sa_data = v4;
v10.sa_data[9] = 6;
return sendto(a1, a3, v7, 0, &v10, v8);
}

canonical_decompiled_code:
ssize_t __fastcall func3(__int64 a1, __int64 a2, const void *a3)
{
__int16 v4; // ax
unsigned __int16 v5; // cx
int v6; // er8
size_t v7; // rdx
socklen_t v8; // er9
struct sockaddr v10; // [rsp+0h] [rbp-28h] BYREF
int v11; // [rsp+10h] [rbp-18h]

v10.sa_family = 17;
v11 = 0;
v4 = func0(a1, a3);
*(_QWORD *)&v10.sa_data[6] = v5;
*(_DWORD *)&v10.sa_data[2] = v6;
*(_WORD *)v10.sa_data = v4;
v10.sa_data[9] = 6;
return sendto(a1, a3, v7, 0, &v10, v8);
}

original_code:
ssize_t lnx_eth_send(int sck,int dev_id,char *buffer,size_t len)
{
   struct sockaddr_ll sa;
   memset(&sa,0,sizeof(struct sockaddr_ll));
   sa.sll_family = 17;
   sa.sll_protocol = htons(0x0003);
   sa.sll_hatype = 1;
   sa.sll_halen = 6;
   sa.sll_ifindex = dev_id;
   return(sendto(sck,buffer,len,0,(struct sockaddr *)&sa,sizeof(sa)));
}

canonical_original_code:
long lnx_eth_send(int sck, int dev_id, char *buffer, unsigned long len)
{
   struct sockaddr_ll sa;
   memset(&sa,0,sizeof(struct sockaddr_ll));
   sa.sll_family = 17;
   sa.sll_protocol = htons(0x0003);
   sa.sll_hatype = 1;
   sa.sll_halen = 6;
   sa.sll_ifindex = dev_id;
   return(sendto(sck,buffer,len,0,(struct sockaddr *)&sa,sizeof(sa)));
}

variable_types:
buffer
char *

variable_types:
len
unsigned long

return_type: long

user_defined_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }


decompiled_code:
ssize_t __fastcall lnx_eth_recv(int a1, void *a2, size_t a3)
{
return recv(a1, a2, a3, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func4(int a1, void *a2, size_t a3)
{
return recv(a1, a2, a3, 0);
}

original_code:
ssize_t lnx_eth_recv(int sck,char *buffer,size_t len)
{
   return(recv(sck,buffer,len,0));
}

canonical_original_code:
long lnx_eth_recv(int sck, char *buffer, unsigned long len)
{
   return(recv(sck,buffer,len,0));
}


decompiled_code:
__suseconds_t m_gettime_usec()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
static inline m_tmcnt_t m_gettime_usec(void)
{
   struct timeval tvp;
   gettimeofday(&tvp,((void *)0));
   return(((m_tmcnt_t)tvp.tv_sec * 1000000) + (m_tmcnt_t)tvp.tv_usec);
}

canonical_original_code:
static inline unsigned long long m_gettime_usec()
{
   struct timeval tvp;
   gettimeofday(&tvp,((void *)0));
   return(((unsigned long long)tvp.tv_sec * 1000000) + (unsigned long long)tvp.tv_usec);
}

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

return_type: unsigned long long


decompiled_code:
void __fastcall __noreturn ptask_run(void *a1)
{
_QWORD *v1; // rbx
unsigned __int64 v2; // rbx
struct timespec v3; // [rsp+0h] [rbp-88h] BYREF
pthread_mutex_t mutex; // [rsp+10h] [rbp-78h] BYREF
pthread_cond_t cond; // [rsp+40h] [rbp-48h] BYREF

mutex.__list.__next = 0LL;
*(_OWORD *)&mutex.__lock = 0LL;
*((_OWORD *)&mutex.__align + 1) = 0LL;
*(_OWORD *)&cond.__lock = 0LL;
*((_OWORD *)&cond.__align + 1) = 0LL;
*((_OWORD *)&cond.__align + 2) = 0LL;
while ( 1 )
{
pthread_mutex_lock(&ptask_mutex);
v1 = ptask_list;
if ( ptask_list )
{
do
{
((void (__fastcall *)(_QWORD, _QWORD))v1[2])(v1[3], v1[4]);
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
pthread_mutex_unlock(&ptask_mutex);
v2 = m_gettime_usec() + 2000;
pthread_mutex_lock(&mutex);
v3.tv_sec = v2 / 0xF4240;
v3.tv_nsec = 1000 * (v2 % 0xF4240);
pthread_cond_timedwait(&cond, &mutex, &v3);
pthread_mutex_unlock(&mutex);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
_QWORD *v1; // rbx
unsigned __int64 v2; // rbx
struct timespec v3; // [rsp+0h] [rbp-88h] BYREF
pthread_mutex_t mutex; // [rsp+10h] [rbp-78h] BYREF
pthread_cond_t cond; // [rsp+40h] [rbp-48h] BYREF

mutex.__list.__next = 0LL;
*(_OWORD *)&mutex.__lock = 0LL;
*((_OWORD *)&mutex.__align + 1) = 0LL;
*(_OWORD *)&cond.__lock = 0LL;
*((_OWORD *)&cond.__align + 1) = 0LL;
*((_OWORD *)&cond.__align + 2) = 0LL;
while ( 1 )
{
pthread_mutex_lock(&ptask_mutex);
v1 = ptask_list;
if ( ptask_list )
{
do
{
((void (__fastcall *)(_QWORD, _QWORD))v1[2])(v1[3], v1[4]);
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
pthread_mutex_unlock(&ptask_mutex);
v2 = func0() + 2000;
pthread_mutex_lock(&mutex);
v3.tv_sec = v2 / 0xF4240;
v3.tv_nsec = 1000 * (v2 % 0xF4240);
pthread_cond_timedwait(&cond, &mutex, &v3);
pthread_mutex_unlock(&mutex);
}
}

original_code:
static void *ptask_run(void *arg)
{
   pthread_mutex_t umutex = { { 0, 0, 0, 0, 0, 0, 0, { 0, 0 } } };
   pthread_cond_t ucond = { { {0}, {0}, {0, 0}, {0, 0}, 0, 0, {0, 0} } };
   ptask_t *task;
   for(;;) {
      pthread_mutex_lock(&ptask_mutex);
      for(task=ptask_list;task;task=task->next)
         task->cbk(task->object,task->arg);
      pthread_mutex_unlock(&ptask_mutex);
      {
         struct timespec t_spc;
         m_tmcnt_t expire;
         expire = m_gettime_usec() + 2000;
         pthread_mutex_lock(&umutex);
         t_spc.tv_sec = expire / 1000000;
         t_spc.tv_nsec = (expire % 1000000) * 1000;
         pthread_cond_timedwait(&ucond,&umutex,&t_spc);
         pthread_mutex_unlock(&umutex);
      }
   }
   return ((void *)0);
}

canonical_original_code:
static void *ptask_run(void *arg)
{
   union pthread_mutex_t umutex = { { 0, 0, 0, 0, 0, 0, 0, { 0, 0 } } };
   union pthread_cond_t ucond = { { {0}, {0}, {0, 0}, {0, 0}, 0, 0, {0, 0} } };
   struct ptask *task;
   for(;;) {
      pthread_mutex_lock(&ptask_mutex);
      for(task=ptask_list;task;task=task->next)
         task->cbk(task->object,task->arg);
      pthread_mutex_unlock(&ptask_mutex);
      {
         struct timespec t_spc;
         unsigned long long expire;
         expire = m_gettime_usec() + 2000;
         pthread_mutex_lock(&umutex);
         t_spc.tv_sec = expire / 1000000;
         t_spc.tv_nsec = (expire % 1000000) * 1000;
         pthread_cond_timedwait(&ucond,&umutex,&t_spc);
         pthread_mutex_unlock(&umutex);
      }
   }
   return ((void *)0);
}

variable_types:
arg
void *

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; }

variable_types: union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; }

variable_types: struct ptask { long long id; struct ptask *next; int (*cbk)(void *object, void *arg); void *object; } *

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

variable_types:
expire
unsigned long long

return_type: void *

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


decompiled_code:
__int64 __fastcall ptask_add(__int64 a1, __int64 a2, __int64 a3)
{
__int64 *v4; // rax
__int64 *v5; // rbx
__int64 v6; // r12
void *v7; // rax

v4 = (__int64 *)calloc(0x28uLL, 1uLL);
if ( v4 )
{
v4[4] = a3;
v5 = v4;
v4[2] = a1;
v4[3] = a2;
pthread_mutex_lock(&ptask_mutex);
v6 = ptask_current_id + 1;
ptask_current_id = v6;
if ( !v6 )
_assert_fail("id != 0", "ptask.c", 0x57u, "ptask_add");
v7 = ptask_list;
*v5 = v6;
ptask_list = v5;
v5[1] = (__int64)v7;
pthread_mutex_unlock(&ptask_mutex);
}
else
{
v6 = -1LL;
fwrite("ptask_add: unable to add new task.\n", 1uLL, 0x23uLL, stderr);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 *v4; // rax
__int64 *v5; // rbx
__int64 v6; // r12
void *v7; // rax

v4 = (__int64 *)calloc(0x28uLL, 1uLL);
if ( v4 )
{
v4[4] = a3;
v5 = v4;
v4[2] = a1;
v4[3] = a2;
pthread_mutex_lock(&ptask_mutex);
v6 = ptask_current_id + 1;
ptask_current_id = v6;
if ( !v6 )
_assert_fail("id != 0", "ptask.c", 0x57u, "ptask_add");
v7 = ptask_list;
*v5 = v6;
ptask_list = v5;
v5[1] = (__int64)v7;
pthread_mutex_unlock(&ptask_mutex);
}
else
{
v6 = -1LL;
fwrite("ptask_add: unable to add new task.\n", 1uLL, 0x23uLL, stderr);
}
return v6;
}

original_code:
ptask_id_t ptask_add(ptask_callback cbk,void *object,void *arg)
{
   ptask_t *task;
   ptask_id_t id;
   if (!(task = malloc(sizeof(*task)))) {
      fprintf(stderr,"ptask_add: unable to add new task.\n");
      return(-1);
   }
   memset(task,0,sizeof(*task));
   task->cbk = cbk;
   task->object = object;
   task->arg = arg;
   pthread_mutex_lock(&ptask_mutex);
   id = ++ptask_current_id;
   ((void) sizeof ((id != 0) ? 1 : 0), __extension__ ({ if (id != 0) ; else __assert_fail ("id != 0", "ptask.c", 87, __extension__ __PRETTY_FUNCTION__); }));
   task->id = id;
   task->next = ptask_list;
   ptask_list = task;
   pthread_mutex_unlock(&ptask_mutex);
   return(id);
}

canonical_original_code:
long long ptask_add(int (*cbk)(void *object, void *arg), void *object, void *arg)
{
   struct ptask *task;
   long long id;
   if (!(task = malloc(sizeof(*task)))) {
      fprintf(stderr,"ptask_add: unable to add new task.\n");
      return(-1);
   }
   memset(task,0,sizeof(*task));
   task->cbk = cbk;
   task->object = object;
   task->arg = arg;
   pthread_mutex_lock(&ptask_mutex);
   id = ++ptask_current_id;
   ((void) sizeof ((id != 0) ? 1 : 0), __extension__ ({ if (id != 0) ; else __assert_fail ("id != 0", "ptask.c", 87, __extension__ __PRETTY_FUNCTION__); }));
   task->id = id;
   task->next = ptask_list;
   ptask_list = task;
   pthread_mutex_unlock(&ptask_mutex);
   return(id);
}

variable_types:
cbk
int (*)(void *object, void *arg)

variable_types:
object
void *

variable_types:
id
long long

return_type: long long

user_defined_types: struct ptask { long long id; struct ptask *next; int (*cbk)(void *object, void *arg); void *object; }


decompiled_code:
__int64 __fastcall ptask_remove(void *a1)
{
void **v2; // rax
void **v3; // rcx
void *v4; // rdx
void **v5; // rdi
unsigned int v6; // er12

pthread_mutex_lock(&ptask_mutex);
v2 = (void **)ptask_list;
if ( ptask_list )
{
v3 = &ptask_list;
while ( 1 )
{
v4 = *v2;
v5 = v2;
v2 = (void **)v2[1];
if ( v4 == a1 )
break;
v3 = v5 + 1;
if ( !v2 )
goto LABEL_6;
}
*v3 = v2;
v6 = 0;
free(v5);
}
else
{
LABEL_6:
v6 = -1;
}
pthread_mutex_unlock(&ptask_mutex);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *a1)
{
void **v2; // rax
void **v3; // rcx
void *v4; // rdx
void **v5; // rdi
unsigned int v6; // er12

pthread_mutex_lock(&ptask_mutex);
v2 = (void **)ptask_list;
if ( ptask_list )
{
v3 = &ptask_list;
while ( 1 )
{
v4 = *v2;
v5 = v2;
v2 = (void **)v2[1];
if ( v4 == a1 )
break;
v3 = v5 + 1;
if ( !v2 )
goto LABEL_6;
}
*v3 = v2;
v6 = 0;
free(v5);
}
else
{
LABEL_6:
v6 = -1;
}
pthread_mutex_unlock(&ptask_mutex);
return v6;
}

original_code:
int ptask_remove(ptask_id_t id)
{
   ptask_t **task,*p;
   int res = -1;
   pthread_mutex_lock(&ptask_mutex);
   for(task=&ptask_list;*task;task=&(*task)->next)
      if ((*task)->id == id) {
         p = *task;
         *task = (*task)->next;
         free(p);
         res = 0;
         break;
      }
   pthread_mutex_unlock(&ptask_mutex);
   return(res);
}

canonical_original_code:
int ptask_remove(long long id)
{
   struct ptask **task; struct ptask *p;
   int res = -1;
   pthread_mutex_lock(&ptask_mutex);
   for(task=&ptask_list;*task;task=&(*task)->next)
      if ((*task)->id == id) {
         p = *task;
         *task = (*task)->next;
         free(p);
         res = 0;
         break;
      }
   pthread_mutex_unlock(&ptask_mutex);
   return(res);
}

variable_types: struct ptask { long long id; struct ptask *next; int (*cbk)(void *object, void *arg); void *object; } **

variable_types: res int


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

result = pthread_create(&ptask_thread, 0LL, (void *(*)(void *))ptask_run, 0LL);
if ( result )
{
fwrite("ptask_init: unable to create thread.\n", 1uLL, 0x25uLL, stderr);
result = -1;
}
return result;
}

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

result = pthread_create(&ptask_thread, 0LL, (void *(*)(void *))ptask_run, 0LL);
if ( result )
{
fwrite("ptask_init: unable to create thread.\n", 1uLL, 0x25uLL, stderr);
result = -1;
}
return result;
}

original_code:
int ptask_init(u_int sleep_time)
{
   if (sleep_time)
      ptask_sleep_time = sleep_time;
   if (pthread_create(&ptask_thread,((void *)0),ptask_run,((void *)0)) != 0) {
      fprintf(stderr,"ptask_init: unable to create thread.\n");
      return(-1);
   }
   return(0);
}

canonical_original_code:
int ptask_init(unsigned int sleep_time)
{
   if (sleep_time)
      ptask_sleep_time = sleep_time;
   if (pthread_create(&ptask_thread,((void *)0),ptask_run,((void *)0)) != 0) {
      fprintf(stderr,"ptask_init: unable to create thread.\n");
      return(-1);
   }
   return(0);
}


decompiled_code:
__int64 __fastcall u8_to_bcd(int a1)
{
int v1; // eax

v1 = 205 * (unsigned __int8)a1;
LOWORD(v1) = (unsigned __int8)a1 / 0xAu;
return (unsigned int)(16 * v1 + a1 - 10 * v1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // eax

v1 = 205 * (unsigned __int8)a1;
LOWORD(v1) = (unsigned __int8)a1 / 0xAu;
return (unsigned int)(16 * v1 + a1 - 10 * v1);
}

original_code:
static m_uint8_t u8_to_bcd(m_uint8_t val)
{
   return(((val / 10) << 4) + (val % 10));
}

canonical_original_code:
static unsigned char u8_to_bcd(unsigned char val)
{
   return(((val / 10) << 4) + (val % 10));
}

variable_types:
val
unsigned char

return_type: unsigned char


decompiled_code:
char **__fastcall flash_model_find(char *s2)
{
const char *v2; // rdi
char **v3; // r12

v2 = flash_models;
if ( !flash_models )
return 0LL;
v3 = &flash_models;
while ( strcmp(v2, s2) )
{
v2 = v3[4];
v3 += 4;
if ( !v2 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
char **__fastcall func2(char *s2)
{
const char *v2; // rdi
char **v3; // r12

v2 = flash_models;
if ( !flash_models )
return 0LL;
v3 = &flash_models;
while ( strcmp(v2, s2) )
{
v2 = v3[4];
v3 += 4;
if ( !v2 )
return 0LL;
}
return v3;
}

original_code:
static struct flash_model *flash_model_find(char *name)
{
   struct flash_model *fm;
   for(fm=&flash_models[0];fm->name!=((void *)0);fm++)
      if (!strcmp(fm->name,name))
         return fm;
   return ((void *)0);
}

variable_types:
name
char *

variable_types: struct flash_model { char *name; unsigned int total_size; unsigned int mode; unsigned int nr_flash_bits; unsigned int blk_size; unsigned int id_manufacturer; unsigned int id_device; } *


decompiled_code:
__int16 __fastcall m_ntoh16(_WORD *a1)
{
return __ROL2__(*a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func0(_WORD *a1)
{
return __ROL2__(*a1, 8);
}

original_code:
static inline m_uint16_t m_ntoh16(m_uint8_t *ptr)
{
   m_uint16_t val = (ptr[0] << 8) | ptr[1];
   return(val);
}

canonical_original_code:
static inline unsigned short m_ntoh16(unsigned char *ptr)
{
   unsigned short val = (ptr[0] << 8) | ptr[1];
   return(val);
}

variable_types:
ptr
unsigned char *

variable_types:
val
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall m_ntoh32(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

original_code:
static inline m_uint32_t m_ntoh32(m_uint8_t *ptr)
{
   m_uint32_t val = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
   return(val);
}

canonical_original_code:
static inline unsigned int m_ntoh32(unsigned char *ptr)
{
   unsigned int val = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
   return(val);
}

variable_types:
val
unsigned int


original_code:
void atm_aal5_recv_reset(struct atm_reas_context *arc)
{
   arc->buf_pos = 0;
   arc->len = 0;
}

variable_types: struct atm_reas_context { unsigned char buffer[16384]; unsigned long buf_pos; unsigned long len; } *


original_code:
int atm_aal5_recv(struct atm_reas_context *arc,m_uint8_t *cell)
{
   m_uint32_t atm_hdr;
   if ((arc->buf_pos + 48) > 16384) {
      atm_aal5_recv_reset(arc);
      return(-1);
   }
   atm_hdr = m_ntoh32(cell);
   if (atm_hdr & 0x00000008)
      return(2);
   memcpy(&arc->buffer[arc->buf_pos],&cell[5],48);
   arc->buf_pos += 48;
   if (atm_hdr & 0x00000002) {
      arc->len = m_ntoh16(&cell[((5 + 48) - 8)+2]);
      return((arc->len <= arc->buf_pos) ? 1 : -2);
   }
   return(0);
}

canonical_original_code:
int atm_aal5_recv(struct atm_reas_context *arc, unsigned char *cell)
{
   unsigned int atm_hdr;
   if ((arc->buf_pos + 48) > 16384) {
      atm_aal5_recv_reset(arc);
      return(-1);
   }
   atm_hdr = m_ntoh32(cell);
   if (atm_hdr & 0x00000008)
      return(2);
   memcpy(&arc->buffer[arc->buf_pos],&cell[5],48);
   arc->buf_pos += 48;
   if (atm_hdr & 0x00000002) {
      arc->len = m_ntoh16(&cell[((5 + 48) - 8)+2]);
      return((arc->len <= arc->buf_pos) ? 1 : -2);
   }
   return(0);
}

variable_types:
cell
unsigned char *

user_defined_types: struct atm_reas_context { unsigned char buffer[16384]; unsigned long buf_pos; unsigned long len; }


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

puts("GDB Server: closing control sockets.");
result = fd_count;
if ( fd_count > 0 && fd_array != -1 )
{
shutdown(fd_array, 2);
result = close(fd_array);
}
return result;
}

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

puts("GDB Server: closing control sockets.");
result = fd_count;
if ( fd_count > 0 && fd_array != -1 )
{
shutdown(fd_array, 2);
result = close(fd_array);
}
return result;
}

original_code:
void gdb_server_close_control_sockets()
{
   int i;
   printf("GDB Server: closing control sockets.\n");
   for(i=0; i<fd_count; i++)
   {
      if (fd_array[i] != -1)
      {
         shutdown(fd_array[i],2);
         close(fd_array[i]);
      }
   }
}

variable_types: i int


waittoread

decompiled_code:
__int64 __fastcall waittoread(int a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
int v3; // eax
__int64 result; // rax
struct timeval timeout; // [rsp+10h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-98h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 100LL;
memset(&readfds, 0, sizeof(readfds));
v1 = a1 / 64;
v2 = 1LL << (a1 % 64);
readfds.fds_bits[v1] |= v2;
v3 = select(1024, &readfds, 0LL, 0LL, &timeout);
if ( v3 == -1 )
{
perror("select failed");
result = 0xFFFFFFFFLL;
}
else if ( v3 <= 0 )
{
result = 0LL;
}
else
{
result = (readfds.fds_bits[v1] & v2) != 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
int v3; // eax
__int64 result; // rax
struct timeval timeout; // [rsp+10h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-98h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 100LL;
memset(&readfds, 0, sizeof(readfds));
v1 = a1 / 64;
v2 = 1LL << (a1 % 64);
readfds.fds_bits[v1] |= v2;
v3 = select(1024, &readfds, 0LL, 0LL, &timeout);
if ( v3 == -1 )
{
perror("select failed");
result = 0xFFFFFFFFLL;
}
else if ( v3 <= 0 )
{
result = 0LL;
}
else
{
result = (readfds.fds_bits[v1] & v2) != 0;
}
return result;
}

original_code:
int waittoread(int s1)
{
   fd_set fds;
   struct timeval timeout;
   int rc, result;
   timeout.tv_sec = 0;
   timeout.tv_usec = 100;
   do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
   ((void) (((&fds)->__fds_bits)[((s1) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s1) % (8 * (int) sizeof (__fd_mask)))))));
   rc = select(sizeof(fds)*8, &fds, ((void *)0), ((void *)0), &timeout);
   if (rc==-1) {
      perror("select failed");
      return -1;
   }
   result = 0;
   if (rc > 0)
   {
      if (((((&fds)->__fds_bits)[((s1) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s1) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        result = 1;
   }
   return result;
}

canonical_original_code:
int waittoread(int s1)
{
   struct fd_set fds;
   struct timeval timeout;
   int rc; int result;
   timeout.tv_sec = 0;
   timeout.tv_usec = 100;
   do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
   ((void) (((&fds)->__fds_bits)[((s1) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s1) % (8 * (int) sizeof (__fd_mask)))))));
   rc = select(sizeof(fds)*8, &fds, ((void *)0), ((void *)0), &timeout);
   if (rc==-1) {
      perror("select failed");
      return -1;
   }
   result = 0;
   if (rc > 0)
   {
      if (((((&fds)->__fds_bits)[((s1) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s1) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        result = 1;
   }
   return result;
}

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

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

variable_types: rc int

variable_types: result int


decompiled_code:
__int64 ppc32_vmtest_platform_register()
{
return vm_platform_register(ppc32_vmtest_platform);
}

canonical_decompiled_code:
__int64 func8()
{
return vm_platform_register(ppc32_vmtest_platform);
}

original_code:
int ppc32_vmtest_platform_register(void)
{
   return(vm_platform_register(&ppc32_vmtest_platform));
}

canonical_original_code:
int ppc32_vmtest_platform_register()
{
   return(vm_platform_register(&ppc32_vmtest_platform));
}