original_code:
void
dio_output(rpl_instance_t *instance, struct in6_addr *uc_addr)
{
  unsigned char *buffer;
  int pos;
  rpl_dag_t *dag = instance->current_dag;
  struct in6_addr addr;
  pos = 0;
  buffer = malloc(1024);
  printf("RPL: DIO[%i] = iid %i\n", pos, instance->instance_id);
  buffer[pos++] = instance->instance_id;
  printf("RPL: DIO[%i] = v %i\n", pos, dag->version);
  buffer[pos++] = dag->version;
  printf("RPL: DIO[%i] = r %i\n", pos, dag->rank);
  set16(buffer, pos, dag->rank);
  pos += 2;
  buffer[pos] = 0;
  buffer[pos] |= 0x80;
  buffer[pos] |= instance->mop << 3;
  buffer[pos] |= dag->preference & 0x07;
  printf("RPL: DIO[%i] = f 0x%x\n", pos, buffer[pos]);
  pos++;
  printf("RPL: DIO[%i] = dtsn %i\n", pos, instance->dtsn_out);
  buffer[pos++] = instance->dtsn_out;
  ((instance->dtsn_out) > 127 ? ++(instance->dtsn_out) & 255 : ++(instance->dtsn_out) & 127);
  printf("RPL: DIO[%i] = f2 %i\n", pos, 0);
  buffer[pos++] = 0;
  printf("RPL: DIO[%i] = r %i\n", pos, 0);
  buffer[pos++] = 0;
  printf("RPL: DIO[%i] = dag_id\n", pos);
  memcpy(buffer + pos, &dag->dag_id, sizeof(dag->dag_id));
  pos += 16;
  if(instance->mc.type != 0) {
    instance->of->update_metric_container(instance);
    printf("RPL: DIO[%i] = metric\n", pos);
    buffer[pos++] = 2;
    buffer[pos++] = 6;
    buffer[pos++] = instance->mc.type;
    buffer[pos++] = instance->mc.flags >> 1;
    buffer[pos] = (instance->mc.flags & 1) << 7;
    buffer[pos++] |= (instance->mc.aggr << 4) | instance->mc.prec;
    if(instance->mc.type == 7) {
      buffer[pos++] = 2;
      set16(buffer, pos, instance->mc.obj.etx);
      pos += 2;
    } else if(instance->mc.type == 2) {
      buffer[pos++] = 2;
      buffer[pos++] = instance->mc.obj.energy.flags;
      buffer[pos++] = instance->mc.obj.energy.energy_est;
    } else {
      printf("RPL: Unable to send DIO because of unhandled DAG MC type %u\n", (unsigned)instance->mc.type);
      return;
    }
  }
  printf("RPL: DIO[%i] = DAG conf %i\n", pos, 4);
  buffer[pos++] = 4;
  buffer[pos++] = 14;
  buffer[pos++] = 0;
  buffer[pos++] = instance->dio_intdoubl;
  buffer[pos++] = instance->dio_intmin;
  buffer[pos++] = instance->dio_redundancy;
  set16(buffer, pos, instance->max_rankinc);
  pos += 2;
  set16(buffer, pos, instance->min_hoprankinc);
  pos += 2;
  set16(buffer, pos, instance->of->ocp);
  pos += 2;
  buffer[pos++] = 0;
  buffer[pos++] = instance->default_lifetime;
  set16(buffer, pos, instance->lifetime_unit);
  pos += 2;
  if(dag->prefix_info.length > 0) {
    buffer[pos++] = 8;
    buffer[pos++] = 30;
    buffer[pos++] = dag->prefix_info.length;
    buffer[pos++] = dag->prefix_info.flags;
    set32(buffer, pos, dag->prefix_info.lifetime);
    pos += 4;
    set32(buffer, pos, dag->prefix_info.lifetime);
    pos += 4;
    memset(&buffer[pos], 0, 4);
    pos += 4;
    memcpy(&buffer[pos], &dag->prefix_info.prefix, 16);
    pos += 16;
    printf("RPL: Sending prefix info in DIO for ");
    rpl_debug_ipaddr_print(&dag->prefix_info.prefix);
    printf("\n");
  } else {
    printf("RPL: No prefix to announce (len %d)\n", dag->prefix_info.length);
  }
  if(uc_addr == ((void *)0)) {
    printf("RPL: Sending a multicast-DIO with rank %u\n", (unsigned)instance->current_dag->rank);
    (&addr)->__in6_u.__u6_addr8[0] = 0xff; (&addr)->__in6_u.__u6_addr8[1] = 0x02; (&addr)->__in6_u.__u6_addr16[1] = 0; (&addr)->__in6_u.__u6_addr16[2] = 0; (&addr)->__in6_u.__u6_addr16[3] = 0; (&addr)->__in6_u.__u6_addr16[4] = 0; (&addr)->__in6_u.__u6_addr16[5] = 0; (&addr)->__in6_u.__u6_addr16[6] = 0; (&addr)->__in6_u.__u6_addr8[14] = 0; (&addr)->__in6_u.__u6_addr8[15] = 0x1a;;
    uip_icmp6_send(&addr, 155, 0x01, buffer, pos);
  } else {
    printf("RPL: Sending unicast-DIO with rank %u to ", (unsigned)instance->current_dag->rank);
    rpl_debug_ipaddr_print(uc_addr);
    printf("\n");
    uip_icmp6_send(uc_addr, 155, 0x01, pos);
  }
}

canonical_original_code:
void dio_output(struct rpl_instance *instance, struct in6_addr *uc_addr)
{
  unsigned char *buffer;
  int pos;
  struct rpl_dag *dag = instance->current_dag;
  struct in6_addr addr;
  pos = 0;
  buffer = malloc(1024);
  printf("RPL: DIO[%i] = iid %i\n", pos, instance->instance_id);
  buffer[pos++] = instance->instance_id;
  printf("RPL: DIO[%i] = v %i\n", pos, dag->version);
  buffer[pos++] = dag->version;
  printf("RPL: DIO[%i] = r %i\n", pos, dag->rank);
  set16(buffer, pos, dag->rank);
  pos += 2;
  buffer[pos] = 0;
  buffer[pos] |= 0x80;
  buffer[pos] |= instance->mop << 3;
  buffer[pos] |= dag->preference & 0x07;
  printf("RPL: DIO[%i] = f 0x%x\n", pos, buffer[pos]);
  pos++;
  printf("RPL: DIO[%i] = dtsn %i\n", pos, instance->dtsn_out);
  buffer[pos++] = instance->dtsn_out;
  ((instance->dtsn_out) > 127 ? ++(instance->dtsn_out) & 255 : ++(instance->dtsn_out) & 127);
  printf("RPL: DIO[%i] = f2 %i\n", pos, 0);
  buffer[pos++] = 0;
  printf("RPL: DIO[%i] = r %i\n", pos, 0);
  buffer[pos++] = 0;
  printf("RPL: DIO[%i] = dag_id\n", pos);
  memcpy(buffer + pos, &dag->dag_id, sizeof(dag->dag_id));
  pos += 16;
  if(instance->mc.type != 0) {
    instance->of->update_metric_container(instance);
    printf("RPL: DIO[%i] = metric\n", pos);
    buffer[pos++] = 2;
    buffer[pos++] = 6;
    buffer[pos++] = instance->mc.type;
    buffer[pos++] = instance->mc.flags >> 1;
    buffer[pos] = (instance->mc.flags & 1) << 7;
    buffer[pos++] |= (instance->mc.aggr << 4) | instance->mc.prec;
    if(instance->mc.type == 7) {
      buffer[pos++] = 2;
      set16(buffer, pos, instance->mc.obj.etx);
      pos += 2;
    } else if(instance->mc.type == 2) {
      buffer[pos++] = 2;
      buffer[pos++] = instance->mc.obj.energy.flags;
      buffer[pos++] = instance->mc.obj.energy.energy_est;
    } else {
      printf("RPL: Unable to send DIO because of unhandled DAG MC type %u\n", (unsigned int)instance->mc.type);
      return;
    }
  }
  printf("RPL: DIO[%i] = DAG conf %i\n", pos, 4);
  buffer[pos++] = 4;
  buffer[pos++] = 14;
  buffer[pos++] = 0;
  buffer[pos++] = instance->dio_intdoubl;
  buffer[pos++] = instance->dio_intmin;
  buffer[pos++] = instance->dio_redundancy;
  set16(buffer, pos, instance->max_rankinc);
  pos += 2;
  set16(buffer, pos, instance->min_hoprankinc);
  pos += 2;
  set16(buffer, pos, instance->of->ocp);
  pos += 2;
  buffer[pos++] = 0;
  buffer[pos++] = instance->default_lifetime;
  set16(buffer, pos, instance->lifetime_unit);
  pos += 2;
  if(dag->prefix_info.length > 0) {
    buffer[pos++] = 8;
    buffer[pos++] = 30;
    buffer[pos++] = dag->prefix_info.length;
    buffer[pos++] = dag->prefix_info.flags;
    set32(buffer, pos, dag->prefix_info.lifetime);
    pos += 4;
    set32(buffer, pos, dag->prefix_info.lifetime);
    pos += 4;
    memset(&buffer[pos], 0, 4);
    pos += 4;
    memcpy(&buffer[pos], &dag->prefix_info.prefix, 16);
    pos += 16;
    printf("RPL: Sending prefix info in DIO for ");
    rpl_debug_ipaddr_print(&dag->prefix_info.prefix);
    printf("\n");
  } else {
    printf("RPL: No prefix to announce (len %d)\n", dag->prefix_info.length);
  }
  if(uc_addr == ((void *)0)) {
    printf("RPL: Sending a multicast-DIO with rank %u\n", (unsigned int)instance->current_dag->rank);
    (&addr)->__in6_u.__u6_addr8[0] = 0xff; (&addr)->__in6_u.__u6_addr8[1] = 0x02; (&addr)->__in6_u.__u6_addr16[1] = 0; (&addr)->__in6_u.__u6_addr16[2] = 0; (&addr)->__in6_u.__u6_addr16[3] = 0; (&addr)->__in6_u.__u6_addr16[4] = 0; (&addr)->__in6_u.__u6_addr16[5] = 0; (&addr)->__in6_u.__u6_addr16[6] = 0; (&addr)->__in6_u.__u6_addr8[14] = 0; (&addr)->__in6_u.__u6_addr8[15] = 0x1a;;
    uip_icmp6_send(&addr, 155, 0x01, buffer, pos);
  } else {
    printf("RPL: Sending unicast-DIO with rank %u to ", (unsigned int)instance->current_dag->rank);
    rpl_debug_ipaddr_print(uc_addr);
    printf("\n");
    uip_icmp6_send(uc_addr, 155, 0x01, pos);
  }
}

variable_types:
buffer
unsigned char *

variable_types: pos int

variable_types: struct rpl_dag { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } dag_id; unsigned short min_rank; unsigned char version; unsigned char grounded; unsigned char preference; unsigned char used; unsigned char joined; struct rpl_parent { struct rpl_parent *next; struct rpl_dag *dag; struct rpl_metric_container { unsigned char type; unsigned char flags; unsigned char aggr; unsigned char prec; unsigned char length; union metric_object { struct rpl_metric_object_energy { unsigned char flags; unsigned char energy_est; } energy; unsigned short etx; } obj; } mc; struct in6_addr addr; unsigned short rank; unsigned char link_metric; unsigned char dtsn; unsigned char updated; } *preferred_parent; unsigned short rank; struct rpl_instance { struct rpl_metric_container mc; struct rpl_of { void (*reset)(struct rpl_dag *); void (*parent_state_callback)(struct rpl_parent *, int, int); struct rpl_parent *(*best_parent)(struct rpl_parent *, struct rpl_parent *); struct rpl_dag *(*best_dag)(struct rpl_dag *, struct rpl_dag *); unsigned short (*calculate_rank)(struct rpl_parent *, unsigned short); void (*update_metric_container)(struct rpl_instance *); unsigned short ocp; } *of; struct rpl_dag *current_dag; struct rpl_dag dag_table[2]; unsigned char instance_id; unsigned char used; unsigned char dtsn_out; unsigned char mop; unsigned char dio_intdoubl; unsigned char dio_intmin; unsigned char dio_redundancy; unsigned char default_lifetime; unsigned char dio_intcurrent; unsigned char dio_send; unsigned char dio_counter; unsigned short max_rankinc; unsigned short min_hoprankinc; unsigned short lifetime_unit; long dio_next_delay; void **dio_timer; void **dao_timer; } *instance; struct rpl_prefix { struct in6_addr prefix; unsigned int lifetime; unsigned char length; unsigned char flags; } prefix_info; } *

user_defined_types: struct rpl_instance { struct rpl_metric_container mc; struct rpl_of *of; struct rpl_dag *current_dag; struct rpl_dag dag_table[2]; unsigned char instance_id; unsigned char used; unsigned char dtsn_out; unsigned char mop; unsigned char dio_intdoubl; unsigned char dio_intmin; unsigned char dio_redundancy; unsigned char default_lifetime; unsigned char dio_intcurrent; unsigned char dio_send; unsigned char dio_counter; unsigned short max_rankinc; unsigned short min_hoprankinc; unsigned short lifetime_unit; long dio_next_delay; void **dio_timer; void **dao_timer; }


repo: markushx/librpl

decompiled_code:
void dao_output()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void
dao_output(rpl_parent_t *n, uint8_t lifetime)
{
}

canonical_original_code:
void dao_output(struct rpl_parent *n, unsigned char lifetime)
{
}

variable_types: struct rpl_parent { struct rpl_parent *next; struct rpl_dag { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } dag_id; unsigned short min_rank; unsigned char version; unsigned char grounded; unsigned char preference; unsigned char used; unsigned char joined; struct rpl_parent *preferred_parent; unsigned short rank; struct rpl_instance { struct rpl_metric_container { unsigned char type; unsigned char flags; unsigned char aggr; unsigned char prec; unsigned char length; union metric_object { struct rpl_metric_object_energy { unsigned char flags; unsigned char energy_est; } energy; unsigned short etx; } obj; } mc; struct rpl_of { void (*reset)(struct rpl_dag *); void (*parent_state_callback)(struct rpl_parent *, int, int); struct rpl_parent *(*best_parent)(struct rpl_parent *, struct rpl_parent *); struct rpl_dag *(*best_dag)(struct rpl_dag *, struct rpl_dag *); unsigned short (*calculate_rank)(struct rpl_parent *, unsigned short); void (*update_metric_container)(struct rpl_instance *); unsigned short ocp; } *of; struct rpl_dag *current_dag; struct rpl_dag dag_table[2]; unsigned char instance_id; unsigned char used; unsigned char dtsn_out; unsigned char mop; unsigned char dio_intdoubl; unsigned char dio_intmin; unsigned char dio_redundancy; unsigned char default_lifetime; unsigned char dio_intcurrent; unsigned char dio_send; unsigned char dio_counter; unsigned short max_rankinc; unsigned short min_hoprankinc; unsigned short lifetime_unit; long dio_next_delay; void **dio_timer; void **dao_timer; } *instance; struct rpl_prefix { struct in6_addr prefix; unsigned int lifetime; unsigned char length; unsigned char flags; } prefix_info; } *dag; struct rpl_metric_container mc; struct in6_addr addr; unsigned short rank; unsigned char link_metric; unsigned char dtsn; unsigned char updated; } *

variable_types:
lifetime
unsigned char

return_type: void

user_defined_types: struct rpl_parent { struct rpl_parent *next; struct rpl_dag *dag; struct rpl_metric_container mc; struct in6_addr addr; unsigned short rank; unsigned char link_metric; unsigned char dtsn; unsigned char updated; }

user_defined_types: struct rpl_dag { struct in6_addr dag_id; unsigned short min_rank; unsigned char version; unsigned char grounded; unsigned char preference; unsigned char used; unsigned char joined; struct rpl_parent *preferred_parent; unsigned short rank; struct rpl_instance *instance; struct rpl_prefix prefix_info; }

user_defined_types: struct rpl_metric_container { unsigned char type; unsigned char flags; unsigned char aggr; unsigned char prec; unsigned char length; union metric_object obj; }

user_defined_types: union metric_object { struct rpl_metric_object_energy energy; unsigned short etx; }


decompiled_code:
void dao_ack_output()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void
dao_ack_output(rpl_instance_t *instance, struct in6_addr *dest, uint8_t sequence)
{
}

canonical_original_code:
void dao_ack_output(struct rpl_instance *instance, struct in6_addr *dest, unsigned char sequence)
{
}

variable_types: struct rpl_instance { struct rpl_metric_container { unsigned char type; unsigned char flags; unsigned char aggr; unsigned char prec; unsigned char length; union metric_object { struct rpl_metric_object_energy { unsigned char flags; unsigned char energy_est; } energy; unsigned short etx; } obj; } mc; struct rpl_of { void (*reset)(struct rpl_dag { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } dag_id; unsigned short min_rank; unsigned char version; unsigned char grounded; unsigned char preference; unsigned char used; unsigned char joined; struct rpl_parent { struct rpl_parent *next; struct rpl_dag *dag; struct rpl_metric_container mc; struct in6_addr addr; unsigned short rank; unsigned char link_metric; unsigned char dtsn; unsigned char updated; } *preferred_parent; unsigned short rank; struct rpl_instance *instance; struct rpl_prefix { struct in6_addr prefix; unsigned int lifetime; unsigned char length; unsigned char flags; } prefix_info; } *); void (*parent_state_callback)(struct rpl_parent *, int, int); struct rpl_parent *(*best_parent)(struct rpl_parent *, struct rpl_parent *); struct rpl_dag *(*best_dag)(struct rpl_dag *, struct rpl_dag *); unsigned short (*calculate_rank)(struct rpl_parent *, unsigned short); void (*update_metric_container)(struct rpl_instance *); unsigned short ocp; } *of; struct rpl_dag *current_dag; struct rpl_dag dag_table[2]; unsigned char instance_id; unsigned char used; unsigned char dtsn_out; unsigned char mop; unsigned char dio_intdoubl; unsigned char dio_intmin; unsigned char dio_redundancy; unsigned char default_lifetime; unsigned char dio_intcurrent; unsigned char dio_send; unsigned char dio_counter; unsigned short max_rankinc; unsigned short min_hoprankinc; unsigned short lifetime_unit; long dio_next_delay; void **dio_timer; void **dao_timer; } *

variable_types:
dest
struct in6_addr *

variable_types:
sequence
unsigned char

user_defined_types: struct rpl_of { void (*reset)(struct rpl_dag *); void (*parent_state_callback)(struct rpl_parent *, int, int); struct rpl_parent *(*best_parent)(struct rpl_parent *, struct rpl_parent *); struct rpl_dag *(*best_dag)(struct rpl_dag *, struct rpl_dag *); unsigned short (*calculate_rank)(struct rpl_parent *, unsigned short); void (*update_metric_container)(struct rpl_instance *); unsigned short ocp; }


decompiled_code:
int uip_rpl_input()
{
return puts("Received an RPL control message");
}

canonical_decompiled_code:
int func6()
{
return puts("Received an RPL control message");
}

original_code:
void
uip_rpl_input(void)
{
  printf("Received an RPL control message\n");
  switch(0 ) {
  case 0x01:
    dio_input();
    break;
  case 0x00:
    dis_input();
    break;
  case 0x02:
    dao_input();
    break;
  case 0x03:
    dao_ack_input();
    break;
  default:
    printf("RPL: received an unknown ICMP6 code (%u)\n", 0);
    break;
  }
}

canonical_original_code:
void uip_rpl_input()
{
  printf("Received an RPL control message\n");
  switch(0 ) {
  case 0x01:
    dio_input();
    break;
  case 0x00:
    dis_input();
    break;
  case 0x02:
    dao_input();
    break;
  case 0x03:
    dao_ack_input();
    break;
  default:
    printf("RPL: received an unknown ICMP6 code (%u)\n", 0);
    break;
  }
}


decompiled_code:
__int64 __fastcall print_addr(void *cp, char *buf)
{
__int64 result; // rax
int *v3; // rax
char *v4; // rax

result = (__int64)inet_ntop(10, cp, buf, 0x2Eu);
if ( !(_DWORD)result )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "print_addr: inet_ntop: %s", v4);
result = 0x64696C61766E695BLL;
strcpy(buf, "[invalid address]");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *cp, char *buf)
{
__int64 result; // rax
int *v3; // rax
char *v4; // rax

result = (__int64)inet_ntop(10, cp, buf, 0x2Eu);
if ( !(_DWORD)result )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "print_addr: inet_ntop: %s", v4);
result = 0x64696C61766E695BLL;
strcpy(buf, "[invalid address]");
}
return result;
}

original_code:
void
print_addr(struct in6_addr *addr, char *str)
{
 const char *res;
 res = inet_ntop(10, (void *)addr, str, 46);
 if (res == ((void *)0))
 {
   fprintf(stderr, "print_addr: inet_ntop: %s", strerror((*__errno_location ())));
  strcpy(str, "[invalid address]");
 }
}

canonical_original_code:
void print_addr(struct in6_addr *addr, char *str)
{
 char *res;
 res = inet_ntop(10, (void *)addr, str, 46);
 if (res == ((void *)0))
 {
   fprintf(stderr, "print_addr: inet_ntop: %s", strerror((*__errno_location ())));
  strcpy(str, "[invalid address]");
 }
}

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

variable_types:
str
char *

variable_types:
res
char *


decompiled_code:
__int64 __fastcall calculate_path_metric(__int64 a1)
{
int v1; // edx
__int64 result; // rax

if ( !a1 )
return 12800LL;
v1 = *(unsigned __int16 *)(a1 + 22);
if ( (_WORD)v1
|| (result = 12800LL, *(_WORD *)(a1 + 40) <= *(_WORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 40LL) + 182LL)) )
{
result = v1 + 8 * (unsigned int)*(unsigned __int8 *)(a1 + 42);
}
return result;
}

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

if ( !a1 )
return 12800LL;
v1 = *(unsigned __int16 *)(a1 + 22);
if ( (_WORD)v1
|| (result = 12800LL, *(_WORD *)(a1 + 40) <= *(_WORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 40LL) + 182LL)) )
{
result = v1 + 8 * (unsigned int)*(unsigned __int8 *)(a1 + 42);
}
return result;
}

original_code:
static rpl_path_metric_t
calculate_path_metric(rpl_parent_t *p)
{
  if(p == ((void *)0) || (p->mc.obj.etx == 0 && p->rank > (p->dag->instance)->min_hoprankinc)) {
    return 100 * 128;
  } else {
    long etx = p->link_metric;
    etx = (etx * 128) / 16;
    return p->mc.obj.etx + (uint16_t) etx;
  }
}

canonical_original_code:
static unsigned short calculate_path_metric(struct rpl_parent *p)
{
  if(p == ((void *)0) || (p->mc.obj.etx == 0 && p->rank > (p->dag->instance)->min_hoprankinc)) {
    return 100 * 128;
  } else {
    long etx = p->link_metric;
    etx = (etx * 128) / 16;
    return p->mc.obj.etx + (unsigned short) etx;
  }
}

variable_types: etx long

return_type: unsigned short

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

user_defined_types: struct rpl_prefix { struct in6_addr prefix; unsigned int lifetime; unsigned char length; unsigned char flags; }

user_defined_types: struct rpl_metric_object_energy { unsigned char flags; unsigned char energy_est; }


reset

decompiled_code:
void reset()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
static void
reset(rpl_dag_t *sag)
{
}

canonical_original_code:
static void reset(struct rpl_dag *sag)
{
}


decompiled_code:
void parent_state_callback()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
static void
parent_state_callback(rpl_parent_t *parent, int known, int etx)
{
}

canonical_original_code:
static void parent_state_callback(struct rpl_parent *parent, int known, int etx)
{
}

variable_types: known int

variable_types: etx int


decompiled_code:
__int64 __fastcall calculate_rank(__int64 a1, int a2)
{
int v2; // edx
int v3; // eax
int v4; // esi
__int64 result; // rax

v2 = a2;
if ( a1 )
{
v3 = (*(unsigned __int8 *)(a1 + 42) * *(unsigned __int16 *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 40LL) + 182LL)) >> 4;
if ( !(_WORD)a2 )
v2 = *(unsigned __int16 *)(a1 + 40);
}
else
{
result = 0xFFFFFFFFLL;
if ( !(_WORD)a2 )
return result;
v3 = 1280;
}
v4 = (unsigned __int16)v3;
result = (unsigned int)(v2 + v3);
if ( (unsigned __int16)~(_WORD)v2 < v4 )
result = 0xFFFFFFFFLL;
return result;
}

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

v2 = a2;
if ( a1 )
{
v3 = (*(unsigned __int8 *)(a1 + 42) * *(unsigned __int16 *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 40LL) + 182LL)) >> 4;
if ( !(_WORD)a2 )
v2 = *(unsigned __int16 *)(a1 + 40);
}
else
{
result = 0xFFFFFFFFLL;
if ( !(_WORD)a2 )
return result;
v3 = 1280;
}
v4 = (unsigned __int16)v3;
result = (unsigned int)(v2 + v3);
if ( (unsigned __int16)~(_WORD)v2 < v4 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static rpl_rank_t
calculate_rank(rpl_parent_t *p, rpl_rank_t base_rank)
{
  rpl_rank_t new_rank;
  rpl_rank_t rank_increase;
  if(p == ((void *)0)) {
    if(base_rank == 0) {
      return 0xffff;
    }
    rank_increase = ((((5) * 16)) / 16) * 256;
  } else {
    rank_increase = ((p->link_metric * p->dag->instance->min_hoprankinc) / 16);
    if(base_rank == 0) {
      base_rank = p->rank;
    }
  }
  if(0xffff - base_rank < rank_increase) {
    new_rank = 0xffff;
  } else {
    new_rank = base_rank + rank_increase;
  }
  return new_rank;
}

canonical_original_code:
static unsigned short calculate_rank(struct rpl_parent *p, unsigned short base_rank)
{
  unsigned short new_rank;
  unsigned short rank_increase;
  if(p == ((void *)0)) {
    if(base_rank == 0) {
      return 0xffff;
    }
    rank_increase = ((((5) * 16)) / 16) * 256;
  } else {
    rank_increase = ((p->link_metric * p->dag->instance->min_hoprankinc) / 16);
    if(base_rank == 0) {
      base_rank = p->rank;
    }
  }
  if(0xffff - base_rank < rank_increase) {
    new_rank = 0xffff;
  } else {
    new_rank = base_rank + rank_increase;
  }
  return new_rank;
}


decompiled_code:
__int64 __fastcall best_dag(__int64 a1, __int64 a2)
{
__int64 result; // rax
char v3; // dl
unsigned __int8 v4; // cl
unsigned __int8 v5; // dl

result = a1;
v3 = *(_BYTE *)(a1 + 19);
if ( v3 == *(_BYTE *)(a2 + 19) )
{
v4 = *(_BYTE *)(a1 + 20);
v5 = *(_BYTE *)(a2 + 20);
if ( v4 == v5 )
{
if ( *(_WORD *)(a1 + 32) >= *(_WORD *)(a2 + 32) )
result = a2;
}
else if ( v4 <= v5 )
{
result = a2;
}
}
else if ( !v3 )
{
result = a2;
}
return result;
}

original_code:
static rpl_dag_t *
best_dag(rpl_dag_t *d1, rpl_dag_t *d2)
{
  if(d1->grounded != d2->grounded) {
    return d1->grounded ? d1 : d2;
  }
  if(d1->preference != d2->preference) {
    return d1->preference > d2->preference ? d1 : d2;
  }
  return d1->rank < d2->rank ? d1 : d2;
}

canonical_original_code:
static struct rpl_dag *best_dag(struct rpl_dag *d1, struct rpl_dag *d2)
{
  if(d1->grounded != d2->grounded) {
    return d1->grounded ? d1 : d2;
  }
  if(d1->preference != d2->preference) {
    return d1->preference > d2->preference ? d1 : d2;
  }
  return d1->rank < d2->rank ? d1 : d2;
}

return_type: struct rpl_dag { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } dag_id; unsigned short min_rank; unsigned char version; unsigned char grounded; unsigned char preference; unsigned char used; unsigned char joined; struct rpl_parent { struct rpl_parent *next; struct rpl_dag *dag; struct rpl_metric_container { unsigned char type; unsigned char flags; unsigned char aggr; unsigned char prec; unsigned char length; union metric_object { struct rpl_metric_object_energy { unsigned char flags; unsigned char energy_est; } energy; unsigned short etx; } obj; } mc; struct in6_addr addr; unsigned short rank; unsigned char link_metric; unsigned char dtsn; unsigned char updated; } *preferred_parent; unsigned short rank; struct rpl_instance { struct rpl_metric_container mc; struct rpl_of { void (*reset)(struct rpl_dag *); void (*parent_state_callback)(struct rpl_parent *, int, int); struct rpl_parent *(*best_parent)(struct rpl_parent *, struct rpl_parent *); struct rpl_dag *(*best_dag)(struct rpl_dag *, struct rpl_dag *); unsigned short (*calculate_rank)(struct rpl_parent *, unsigned short); void (*update_metric_container)(struct rpl_instance *); unsigned short ocp; } *of; struct rpl_dag *current_dag; struct rpl_dag dag_table[2]; unsigned char instance_id; unsigned char used; unsigned char dtsn_out; unsigned char mop; unsigned char dio_intdoubl; unsigned char dio_intmin; unsigned char dio_redundancy; unsigned char default_lifetime; unsigned char dio_intcurrent; unsigned char dio_send; unsigned char dio_counter; unsigned short max_rankinc; unsigned short min_hoprankinc; unsigned short lifetime_unit; long dio_next_delay; void **dio_timer; void **dao_timer; } *instance; struct rpl_prefix { struct in6_addr prefix; unsigned int lifetime; unsigned char length; unsigned char flags; } prefix_info; } *


original_code:
static void
update_metric_container(rpl_instance_t *instance)
{
  rpl_path_metric_t path_metric;
  rpl_dag_t *dag;
  instance->mc.flags = 0x8;
  instance->mc.aggr = 0;
  instance->mc.prec = 0;
  dag = instance->current_dag;
  if (!dag->joined) {
    return;
  }
  if(dag->rank == (instance)->min_hoprankinc) {
    path_metric = 0;
  } else {
    path_metric = calculate_path_metric(dag->preferred_parent);
  }
  instance->mc.type = 7;
  instance->mc.length = sizeof(instance->mc.obj.etx);
  instance->mc.obj.etx = path_metric;
  printf("RPL: My path ETX to the root is %u.%u\n", instance->mc.obj.etx / 128, (instance->mc.obj.etx % 128 * 100) / 128);
}

canonical_original_code:
static void update_metric_container(struct rpl_instance *instance)
{
  unsigned short path_metric;
  struct rpl_dag *dag;
  instance->mc.flags = 0x8;
  instance->mc.aggr = 0;
  instance->mc.prec = 0;
  dag = instance->current_dag;
  if (!dag->joined) {
    return;
  }
  if(dag->rank == (instance)->min_hoprankinc) {
    path_metric = 0;
  } else {
    path_metric = calculate_path_metric(dag->preferred_parent);
  }
  instance->mc.type = 7;
  instance->mc.length = sizeof(instance->mc.obj.etx);
  instance->mc.obj.etx = path_metric;
  printf("RPL: My path ETX to the root is %u.%u\n", instance->mc.obj.etx / 128, (instance->mc.obj.etx % 128 * 100) / 128);
}


decompiled_code:
__int64 __fastcall best_parent(__int64 a1, __int64 a2)
{
__int64 v3; // r13
unsigned __int16 v4; // r12
unsigned __int16 v5; // ax
__int64 v6; // rdx
bool v7; // cf
__int64 result; // rax
__int64 v9; // rcx
__int64 v10; // rsi

v3 = *(_QWORD *)(a1 + 8);
v4 = calculate_path_metric(a1);
v5 = calculate_path_metric(a2);
v6 = *(_QWORD *)(v3 + 24);
if ( (v6 == a2 || v6 == a1)
&& (v9 = (unsigned int)v5 + 64, v4 < (int)v9)
&& (v10 = (unsigned int)v5 - 64, v4 > (int)v10) )
{
printf("RPL: MRHOF hysteresis: %u <= %u <= %u\n", v10, v4, v9);
result = *(_QWORD *)(v3 + 24);
}
else
{
v7 = v4 < v5;
result = a2;
if ( v7 )
result = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v3; // r13
unsigned __int16 v4; // r12
unsigned __int16 v5; // ax
__int64 v6; // rdx
bool v7; // cf
__int64 result; // rax
__int64 v9; // rcx
__int64 v10; // rsi

v3 = *(_QWORD *)(a1 + 8);
v4 = func0(a1);
v5 = func0(a2);
v6 = *(_QWORD *)(v3 + 24);
if ( (v6 == a2 || v6 == a1)
&& (v9 = (unsigned int)v5 + 64, v4 < (int)v9)
&& (v10 = (unsigned int)v5 - 64, v4 > (int)v10) )
{
printf("RPL: MRHOF hysteresis: %u <= %u <= %u\n", v10, v4, v9);
result = *(_QWORD *)(v3 + 24);
}
else
{
v7 = v4 < v5;
result = a2;
if ( v7 )
result = a1;
}
return result;
}

original_code:
static rpl_parent_t *
best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
{
  rpl_dag_t *dag;
  rpl_path_metric_t min_diff;
  rpl_path_metric_t p1_metric;
  rpl_path_metric_t p2_metric;
  dag = p1->dag;
  min_diff = 128 /
             2;
  p1_metric = calculate_path_metric(p1);
  p2_metric = calculate_path_metric(p2);
  if(p1 == dag->preferred_parent || p2 == dag->preferred_parent) {
    if(p1_metric < p2_metric + min_diff &&
       p1_metric > p2_metric - min_diff) {
      printf("RPL: MRHOF hysteresis: %u <= %u <= %u\n", p2_metric - min_diff, p1_metric, p2_metric + min_diff);
      return dag->preferred_parent;
    }
  }
  return p1_metric < p2_metric ? p1 : p2;
}

canonical_original_code:
static struct rpl_parent *best_parent(struct rpl_parent *p1, struct rpl_parent *p2)
{
  struct rpl_dag *dag;
  unsigned short min_diff;
  unsigned short p1_metric;
  unsigned short p2_metric;
  dag = p1->dag;
  min_diff = 128 /
             2;
  p1_metric = calculate_path_metric(p1);
  p2_metric = calculate_path_metric(p2);
  if(p1 == dag->preferred_parent || p2 == dag->preferred_parent) {
    if(p1_metric < p2_metric + min_diff &&
       p1_metric > p2_metric - min_diff) {
      printf("RPL: MRHOF hysteresis: %u <= %u <= %u\n", p2_metric - min_diff, p1_metric, p2_metric + min_diff);
      return dag->preferred_parent;
    }
  }
  return p1_metric < p2_metric ? p1 : p2;
}

return_type: struct rpl_parent { struct rpl_parent *next; struct rpl_dag { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } dag_id; unsigned short min_rank; unsigned char version; unsigned char grounded; unsigned char preference; unsigned char used; unsigned char joined; struct rpl_parent *preferred_parent; unsigned short rank; struct rpl_instance { struct rpl_metric_container { unsigned char type; unsigned char flags; unsigned char aggr; unsigned char prec; unsigned char length; union metric_object { struct rpl_metric_object_energy { unsigned char flags; unsigned char energy_est; } energy; unsigned short etx; } obj; } mc; struct rpl_of { void (*reset)(struct rpl_dag *); void (*parent_state_callback)(struct rpl_parent *, int, int); struct rpl_parent *(*best_parent)(struct rpl_parent *, struct rpl_parent *); struct rpl_dag *(*best_dag)(struct rpl_dag *, struct rpl_dag *); unsigned short (*calculate_rank)(struct rpl_parent *, unsigned short); void (*update_metric_container)(struct rpl_instance *); unsigned short ocp; } *of; struct rpl_dag *current_dag; struct rpl_dag dag_table[2]; unsigned char instance_id; unsigned char used; unsigned char dtsn_out; unsigned char mop; unsigned char dio_intdoubl; unsigned char dio_intmin; unsigned char dio_redundancy; unsigned char default_lifetime; unsigned char dio_intcurrent; unsigned char dio_send; unsigned char dio_counter; unsigned short max_rankinc; unsigned short min_hoprankinc; unsigned short lifetime_unit; long dio_next_delay; void **dio_timer; void **dao_timer; } *instance; struct rpl_prefix { struct in6_addr prefix; unsigned int lifetime; unsigned char length; unsigned char flags; } prefix_info; } *dag; struct rpl_metric_container mc; struct in6_addr addr; unsigned short rank; unsigned char link_metric; unsigned char dtsn; unsigned char updated; } *


checksum

original_code:
unsigned short int
checksum (unsigned short int *addr, int len)
{
  int nleft = len;
  int sum = 0;
  unsigned short int *w = addr;
  unsigned short int answer = 0;
  while (nleft > 1) {
    sum += *w++;
    nleft -= sizeof (unsigned short int);
  }
  if (nleft == 1) {
    *(unsigned char *) (&answer) = *(unsigned char *) w;
    sum += answer;
  }
  sum = (sum >> 16) + (sum & 0xFFFF);
  sum += (sum >> 16);
  answer = ~sum;
  return (answer);
}

canonical_original_code:
unsigned short checksum(unsigned short *addr, int len)
{
  int nleft = len;
  int sum = 0;
  unsigned short *w = addr;
  unsigned short answer = 0;
  while (nleft > 1) {
    sum += *w++;
    nleft -= sizeof (unsigned short);
  }
  if (nleft == 1) {
    *(unsigned char *) (&answer) = *(unsigned char *) w;
    sum += answer;
  }
  sum = (sum >> 16) + (sum & 0xFFFF);
  sum += (sum >> 16);
  answer = ~sum;
  return (answer);
}

variable_types:
addr
unsigned short *

variable_types: len int

variable_types: nleft int

variable_types: sum int

variable_types:
w
unsigned short *

variable_types:
answer
unsigned short


decompiled_code:
int __fastcall uip_icmp6_send(__int64 a1, unsigned int a2, unsigned int a3, const void *a4, int a5)
{
char v5; // r13
char *v7; // rax
char *v8; // rbx
_WORD *v9; // rax
_WORD *v10; // r12
int v11; // eax
struct addrinfo *v12; // r15
int v13; // eax
struct addrinfo *v14; // r15
int v15; // er13
int v16; // ebp
_QWORD *v17; // rax
_DWORD *v18; // rax
__int16 v19; // ax
__int16 v20; // ax
unsigned __int16 v21; // ax
int v22; // ebx
int result; // eax
const char *v24; // rax
const char *v25; // rax
const char *v26; // rax
socklen_t len; // [rsp+Ch] [rbp-14Ch]
__int64 v29[4]; // [rsp+10h] [rbp-148h] BYREF
char v30[8]; // [rsp+30h] [rbp-128h] BYREF
__m128i v31; // [rsp+38h] [rbp-120h] BYREF
struct sockaddr dest[2]; // [rsp+50h] [rbp-108h] BYREF
struct addrinfo *pai; // [rsp+78h] [rbp-E0h] BYREF
struct addrinfo req; // [rsp+80h] [rbp-D8h] BYREF
char s[8]; // [rsp+B0h] [rbp-A8h] BYREF
__int64 v36; // [rsp+B8h] [rbp-A0h]
__int64 v37; // [rsp+C0h] [rbp-98h]
__int64 v38; // [rsp+C8h] [rbp-90h]
__int64 v39; // [rsp+D0h] [rbp-88h]
struct msghdr message; // [rsp+E0h] [rbp-78h] BYREF

v5 = a3;
fprintf(stdout, "Sending ICMPv6 type %i code %i.\n", a2, a3);
v7 = (char *)malloc(0xFFFFuLL);
if ( !v7 )
{
fwrite("ERROR: Cannot allocate memory for array 'psdhdr'.\n", 1uLL, 0x32uLL, stderr);
exit(1);
}
v8 = v7;
memset(v7, 0, 0xFFFFuLL);
v9 = malloc(0xFFD3uLL);
v10 = v9;
if ( !v9 )
{
fwrite("ERROR: Cannot allocate memory for array 'outpack'.\n", 1uLL, 0x33uLL, stderr);
exit(1);
}
memset(v9, 0, 0xFFD3uLL);
*(_QWORD *)s = 0LL;
v36 = 0LL;
v37 = 0LL;
v38 = 0LL;
v39 = 0LL;
snprintf(s, 0x10uLL, "%s", if_str);
if ( ioctl(sock, 0x8933uLL, s) < 0 )
return fwrite("ioctl() failed to find interface ", 1uLL, 0x21uLL, stderr);
printf("Index for interface %s is %i\n", if_str, (unsigned int)v37);
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 10;
req.ai_flags = 2;
v11 = getaddrinfo(ip_src_str, 0LL, &req, &pai);
if ( v11 )
{
v24 = gai_strerror(v11);
result = fprintf(stderr, "getaddrinfo() failed: %s\n", v24);
}
else
{
v12 = pai;
memcpy(dest, pai->ai_addr, pai->ai_addrlen);
len = v12->ai_addrlen;
*(__m128i *)v8 = _mm_loadu_si128((const __m128i *)&dest[0].sa_data[6]);
freeaddrinfo(v12);
v13 = getaddrinfo("ff02::1a", 0LL, &req, &pai);
if ( v13 )
{
v25 = gai_strerror(v13);
result = fprintf(stderr, "getaddrinfo() failed: %s\n", v25);
}
else
{
v14 = pai;
memcpy(v30, pai->ai_addr, pai->ai_addrlen);
*((__m128i *)v8 + 1) = _mm_loadu_si128(&v31);
freeaddrinfo(v14);
v10[1] = 0;
*(_BYTE *)v10 = a2;
*((_BYTE *)v10 + 1) = v5;
memcpy(v10 + 2, a4, a5);
v15 = a5 + 44;
*(_QWORD *)&message.msg_namelen = 28LL;
message.msg_control = 0LL;
message.msg_controllen = 0LL;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_name = v30;
v29[2] = 0LL;
v29[3] = 0LL;
v29[0] = (__int64)v10;
v16 = a5 + 4;
v29[1] = v16;
message.msg_iov = (iovec *)v29;
message.msg_iovlen = 1LL;
v17 = malloc(0x18uLL);
if ( !v17 )
{
fwrite("ERROR: Cannot allocate memory for array 'msghdr.msg_control'.\n", 1uLL, 0x3EuLL, stderr);
exit(1);
}
message.msg_control = v17;
*v17 = 0LL;
v17[1] = 0LL;
v17[2] = 0LL;
message.msg_controllen = 24LL;
fwrite("psdhdrlen.\n", 1uLL, 0xBuLL, stderr);
v18 = 0LL;
if ( message.msg_controllen > 0xF )
v18 = message.msg_control;
v18[2] = 41;
v18[3] = 52;
*(_QWORD *)v18 = 20LL;
v18[4] = 255;
v8[32] = 0;
v8[33] = 0;
v19 = v16 + 255;
if ( v16 >= 0 )
HIBYTE(v19) = BYTE1(v16);
v8[34] = HIBYTE(v19);
*(_WORD *)(v8 + 35) = (unsigned __int8)v16;
v8[37] = 0;
v8[38] = 0;
v8[39] = 58;
memcpy(v8 + 40, v10, v16);
v20 = checksum(v8, v15);
v10[1] = v20;
v21 = _bswap_16(v20);
printf("Checksum: %x\n", v21);
if ( bind(sock, dest, len) )
{
result = fwrite("Failed to bind the socket descriptor to the source address.\n", 1uLL, 0x3CuLL, stderr);
}
else if ( setsockopt(sock, 1, 25, s, 0x28u) < 0 )
{
result = fwrite("setsockopt() failed to bind to interface\n", 1uLL, 0x29uLL, stderr);
}
else
{
v22 = sendmsg(sock, &message, 0);
if ( v22 < 0 )
{
v26 = gai_strerror(0);
result = fprintf(stderr, "sendmsg() failed %i %i '%s'\n", (unsigned int)v22, 0LL, v26);
}
else
{
result = fwrite("sendmsg() success\n", 1uLL, 0x12uLL, stdout);
}
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, unsigned int a2, unsigned int a3, const void *a4, int a5)
{
char v5; // r13
char *v7; // rax
char *v8; // rbx
_WORD *v9; // rax
_WORD *v10; // r12
int v11; // eax
struct addrinfo *v12; // r15
int v13; // eax
struct addrinfo *v14; // r15
int v15; // er13
int v16; // ebp
_QWORD *v17; // rax
_DWORD *v18; // rax
__int16 v19; // ax
__int16 v20; // ax
unsigned __int16 v21; // ax
int v22; // ebx
int result; // eax
const char *v24; // rax
const char *v25; // rax
const char *v26; // rax
socklen_t len; // [rsp+Ch] [rbp-14Ch]
__int64 v29[4]; // [rsp+10h] [rbp-148h] BYREF
char v30[8]; // [rsp+30h] [rbp-128h] BYREF
__m128i v31; // [rsp+38h] [rbp-120h] BYREF
struct sockaddr dest[2]; // [rsp+50h] [rbp-108h] BYREF
struct addrinfo *pai; // [rsp+78h] [rbp-E0h] BYREF
struct addrinfo req; // [rsp+80h] [rbp-D8h] BYREF
char s[8]; // [rsp+B0h] [rbp-A8h] BYREF
__int64 v36; // [rsp+B8h] [rbp-A0h]
__int64 v37; // [rsp+C0h] [rbp-98h]
__int64 v38; // [rsp+C8h] [rbp-90h]
__int64 v39; // [rsp+D0h] [rbp-88h]
struct msghdr message; // [rsp+E0h] [rbp-78h] BYREF

v5 = a3;
fprintf(stdout, "Sending ICMPv6 type %i code %i.\n", a2, a3);
v7 = (char *)malloc(0xFFFFuLL);
if ( !v7 )
{
fwrite("ERROR: Cannot allocate memory for array 'psdhdr'.\n", 1uLL, 0x32uLL, stderr);
exit(1);
}
v8 = v7;
memset(v7, 0, 0xFFFFuLL);
v9 = malloc(0xFFD3uLL);
v10 = v9;
if ( !v9 )
{
fwrite("ERROR: Cannot allocate memory for array 'outpack'.\n", 1uLL, 0x33uLL, stderr);
exit(1);
}
memset(v9, 0, 0xFFD3uLL);
*(_QWORD *)s = 0LL;
v36 = 0LL;
v37 = 0LL;
v38 = 0LL;
v39 = 0LL;
snprintf(s, 0x10uLL, "%s", if_str);
if ( ioctl(sock, 0x8933uLL, s) < 0 )
return fwrite("ioctl() failed to find interface ", 1uLL, 0x21uLL, stderr);
printf("Index for interface %s is %i\n", if_str, (unsigned int)v37);
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 10;
req.ai_flags = 2;
v11 = getaddrinfo(ip_src_str, 0LL, &req, &pai);
if ( v11 )
{
v24 = gai_strerror(v11);
result = fprintf(stderr, "getaddrinfo() failed: %s\n", v24);
}
else
{
v12 = pai;
memcpy(dest, pai->ai_addr, pai->ai_addrlen);
len = v12->ai_addrlen;
*(__m128i *)v8 = _mm_loadu_si128((const __m128i *)&dest[0].sa_data[6]);
freeaddrinfo(v12);
v13 = getaddrinfo("ff02::1a", 0LL, &req, &pai);
if ( v13 )
{
v25 = gai_strerror(v13);
result = fprintf(stderr, "getaddrinfo() failed: %s\n", v25);
}
else
{
v14 = pai;
memcpy(v30, pai->ai_addr, pai->ai_addrlen);
*((__m128i *)v8 + 1) = _mm_loadu_si128(&v31);
freeaddrinfo(v14);
v10[1] = 0;
*(_BYTE *)v10 = a2;
*((_BYTE *)v10 + 1) = v5;
memcpy(v10 + 2, a4, a5);
v15 = a5 + 44;
*(_QWORD *)&message.msg_namelen = 28LL;
message.msg_control = 0LL;
message.msg_controllen = 0LL;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_name = v30;
v29[2] = 0LL;
v29[3] = 0LL;
v29[0] = (__int64)v10;
v16 = a5 + 4;
v29[1] = v16;
message.msg_iov = (iovec *)v29;
message.msg_iovlen = 1LL;
v17 = malloc(0x18uLL);
if ( !v17 )
{
fwrite("ERROR: Cannot allocate memory for array 'msghdr.msg_control'.\n", 1uLL, 0x3EuLL, stderr);
exit(1);
}
message.msg_control = v17;
*v17 = 0LL;
v17[1] = 0LL;
v17[2] = 0LL;
message.msg_controllen = 24LL;
fwrite("psdhdrlen.\n", 1uLL, 0xBuLL, stderr);
v18 = 0LL;
if ( message.msg_controllen > 0xF )
v18 = message.msg_control;
v18[2] = 41;
v18[3] = 52;
*(_QWORD *)v18 = 20LL;
v18[4] = 255;
v8[32] = 0;
v8[33] = 0;
v19 = v16 + 255;
if ( v16 >= 0 )
HIBYTE(v19) = BYTE1(v16);
v8[34] = HIBYTE(v19);
*(_WORD *)(v8 + 35) = (unsigned __int8)v16;
v8[37] = 0;
v8[38] = 0;
v8[39] = 58;
memcpy(v8 + 40, v10, v16);
v20 = func1(v8, v15);
v10[1] = v20;
v21 = func0(v20);
printf("Checksum: %x\n", v21);
if ( bind(sock, dest, len) )
{
result = fwrite("Failed to bind the socket descriptor to the source address.\n", 1uLL, 0x3CuLL, stderr);
}
else if ( setsockopt(sock, 1, 25, s, 0x28u) < 0 )
{
result = fwrite("setsockopt() failed to bind to interface\n", 1uLL, 0x29uLL, stderr);
}
else
{
v22 = sendmsg(sock, &message, 0);
if ( v22 < 0 )
{
v26 = gai_strerror(0);
result = fprintf(stderr, "sendmsg() failed %i %i '%s'\n", (unsigned int)v22, 0LL, v26);
}
else
{
result = fwrite("sendmsg() success\n", 1uLL, 0x12uLL, stdout);
}
}
}
}
return result;
}

original_code:
void
uip_icmp6_send(struct in6_addr *dest, int type, int code, unsigned char* data, int datalen) {
  char ipbuffer[40];
  char icmpbuffer[4];
  struct iphdr *iphdr = (struct iphdr *)ipbuffer;
  struct icmp6_hdr *icmphdr = (struct icmp6_hdr *)icmpbuffer;
  unsigned char *outpack, *psdhdr;
  struct msghdr msghdr;
  struct cmsghdr *cmsghdr;
  int status, sd, cmsglen, psdhdrlen;
  struct ifreq ifr;
  struct addrinfo hints, *res;
  struct sockaddr_in6 src, dst;
  socklen_t srclen;
  struct iovec iov[2];
  void *tmp;
  int ip_len;
  int ret;
  fprintf (stdout, "Sending ICMPv6 type %i code %i.\n", type, code);
  psdhdr = (unsigned char *) malloc (65535 * sizeof (unsigned char));
  if (psdhdr == ((void *)0)) {
    fprintf (stderr, "ERROR: Cannot allocate memory for array 'psdhdr'.\n");
    exit (1);
  }
  memset (psdhdr, 0, 65535 * sizeof (unsigned char));
  outpack = (unsigned char *) malloc ((65535 - 40 - 4) * sizeof (unsigned char));
  if (outpack == ((void *)0)) {
    fprintf (stderr, "ERROR: Cannot allocate memory for array 'outpack'.\n");
    exit (1);
  }
  memset (outpack, 0, (65535 - 40 - 4) * sizeof (unsigned char));
  memset (&ifr, 0, sizeof (ifr));
  snprintf (ifr.ifr_ifrn.ifrn_name, sizeof (ifr.ifr_ifrn.ifrn_name), "%s", if_str);
  if (ioctl (sock, 0x8933, &ifr) < 0) {
    fprintf(stderr, "ioctl() failed to find interface ");
    return;
  }
  printf ("Index for interface %s is %i\n", if_str, ifr.ifr_ifru.ifru_ivalue);
  memset (&hints, 0, sizeof (struct addrinfo));
  hints.ai_family = 10;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = hints.ai_flags | 0x0002;
  if ((status = getaddrinfo (ip_src_str, ((void *)0), &hints, &res)) != 0) {
    fprintf (stderr, "getaddrinfo() failed: %s\n", gai_strerror (status));
    return;
  }
  memcpy (&src, res->ai_addr, res->ai_addrlen);
  srclen = res->ai_addrlen;
  memcpy (psdhdr, src.sin6_addr.__in6_u.__u6_addr8, 16);
  freeaddrinfo (res);
  if ((status = getaddrinfo ("ff02::1a", ((void *)0), &hints, &res)) != 0) {
    fprintf (stderr, "getaddrinfo() failed: %s\n", gai_strerror (status));
    return;
  }
  memcpy (&dst, res->ai_addr, res->ai_addrlen);
  memcpy (psdhdr + 16, dst.sin6_addr.__in6_u.__u6_addr8, 16);
  freeaddrinfo (res);
  icmphdr = (struct icmp6_hdr *) outpack;
  memset (icmphdr, 0, 4);
  icmphdr->icmp6_type = type;
  icmphdr->icmp6_code =code;
  icmphdr->icmp6_cksum = 0;
  memcpy (outpack + 4, data, datalen);
  psdhdrlen = 16 + 16 + 4 + 3 + 1 + 4 + datalen;
  memset (&msghdr, 0, sizeof (msghdr));
  msghdr.msg_name = &dst;
  msghdr.msg_namelen = sizeof (dst);
  memset (&iov, 0, sizeof (iov));
  iov[0].iov_base = (unsigned char *) outpack;
  iov[0].iov_len = 4 + datalen;
  msghdr.msg_iov = iov;
  msghdr.msg_iovlen = 1;
  cmsglen = ((((sizeof (int)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)));
  tmp = (unsigned char *) malloc (cmsglen * sizeof (unsigned char));
  if (tmp != ((void *)0)) {
    msghdr.msg_control = tmp;}
  else {
    fprintf (stderr, "ERROR: Cannot allocate memory for array 'msghdr.msg_control'.\n");
    exit (1);
  }
  memset (msghdr.msg_control, 0, cmsglen);
  msghdr.msg_controllen = cmsglen;
  fprintf (stderr, "psdhdrlen.\n");
  cmsghdr = ((size_t) (&msghdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msghdr)->msg_control : (struct cmsghdr *) 0);
  cmsghdr->cmsg_level = IPPROTO_IPV6;
  cmsghdr->cmsg_type = 52;
  cmsghdr->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (sizeof (int)));
  *((int *) ((cmsghdr)->__cmsg_data)) = 0xff;
  psdhdr[32] = 0;
  psdhdr[33] = 0;
  psdhdr[34] = (4 + datalen) / 256;
  psdhdr[35] = (4 + datalen) % 256;
  psdhdr[36] = 0;
  psdhdr[37] = 0;
  psdhdr[38] = 0;
  psdhdr[39] = IPPROTO_ICMPV6;
  memcpy (psdhdr + 40, outpack, 4 + datalen);
  icmphdr->icmp6_cksum = checksum ((unsigned short int *) psdhdr, psdhdrlen);
  printf ("Checksum: %x\n", ntohs (icmphdr->icmp6_cksum));
  if (bind (sock, (struct sockaddr *) &src, srclen) != 0) {
    fprintf (stderr, "Failed to bind the socket descriptor to the source address.\n");
    return;
  }
  if (setsockopt (sock, 1, 25, &ifr, sizeof (ifr)) < 0) {
    fprintf(stderr, "setsockopt() failed to bind to interface\n");
    return;
  }
  ret = sendmsg (sock, &msghdr, 0);
  if (ret < 0) {
    fprintf(stderr, "sendmsg() failed %i %i '%s'\n", ret, status, gai_strerror (status));
    return;
  } else {
    fprintf(stdout, "sendmsg() success\n" );
  }
}

canonical_original_code:
void uip_icmp6_send(struct in6_addr *dest, int type, int code, unsigned char *data, int datalen) {
  char ipbuffer[40];
  char icmpbuffer[4];
  struct iphdr *iphdr = (struct iphdr *)ipbuffer;
  struct icmp6_hdr *icmphdr = (struct icmp6_hdr *)icmpbuffer;
  unsigned char *outpack; unsigned char *psdhdr;
  struct msghdr msghdr;
  struct cmsghdr *cmsghdr;
  int status; int sd; int cmsglen; int psdhdrlen;
  struct ifreq ifr;
  struct addrinfo hints; struct addrinfo *res;
  struct sockaddr_in6 src; struct sockaddr_in6 dst;
  unsigned int srclen;
  struct iovec iov[2];
  void *tmp;
  int ip_len;
  int ret;
  fprintf (stdout, "Sending ICMPv6 type %i code %i.\n", type, code);
  psdhdr = (unsigned char *) malloc (65535 * sizeof (unsigned char));
  if (psdhdr == ((void *)0)) {
    fprintf (stderr, "ERROR: Cannot allocate memory for array 'psdhdr'.\n");
    exit (1);
  }
  memset (psdhdr, 0, 65535 * sizeof (unsigned char));
  outpack = (unsigned char *) malloc ((65535 - 40 - 4) * sizeof (unsigned char));
  if (outpack == ((void *)0)) {
    fprintf (stderr, "ERROR: Cannot allocate memory for array 'outpack'.\n");
    exit (1);
  }
  memset (outpack, 0, (65535 - 40 - 4) * sizeof (unsigned char));
  memset (&ifr, 0, sizeof (ifr));
  snprintf (ifr.ifr_ifrn.ifrn_name, sizeof (ifr.ifr_ifrn.ifrn_name), "%s", if_str);
  if (ioctl (sock, 0x8933, &ifr) < 0) {
    fprintf(stderr, "ioctl() failed to find interface ");
    return;
  }
  printf ("Index for interface %s is %i\n", if_str, ifr.ifr_ifru.ifru_ivalue);
  memset (&hints, 0, sizeof (struct addrinfo));
  hints.ai_family = 10;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = hints.ai_flags | 0x0002;
  if ((status = getaddrinfo (ip_src_str, ((void *)0), &hints, &res)) != 0) {
    fprintf (stderr, "getaddrinfo() failed: %s\n", gai_strerror (status));
    return;
  }
  memcpy (&src, res->ai_addr, res->ai_addrlen);
  srclen = res->ai_addrlen;
  memcpy (psdhdr, src.sin6_addr.__in6_u.__u6_addr8, 16);
  freeaddrinfo (res);
  if ((status = getaddrinfo ("ff02::1a", ((void *)0), &hints, &res)) != 0) {
    fprintf (stderr, "getaddrinfo() failed: %s\n", gai_strerror (status));
    return;
  }
  memcpy (&dst, res->ai_addr, res->ai_addrlen);
  memcpy (psdhdr + 16, dst.sin6_addr.__in6_u.__u6_addr8, 16);
  freeaddrinfo (res);
  icmphdr = (struct icmp6_hdr *) outpack;
  memset (icmphdr, 0, 4);
  icmphdr->icmp6_type = type;
  icmphdr->icmp6_code =code;
  icmphdr->icmp6_cksum = 0;
  memcpy (outpack + 4, data, datalen);
  psdhdrlen = 16 + 16 + 4 + 3 + 1 + 4 + datalen;
  memset (&msghdr, 0, sizeof (msghdr));
  msghdr.msg_name = &dst;
  msghdr.msg_namelen = sizeof (dst);
  memset (&iov, 0, sizeof (iov));
  iov[0].iov_base = (unsigned char *) outpack;
  iov[0].iov_len = 4 + datalen;
  msghdr.msg_iov = iov;
  msghdr.msg_iovlen = 1;
  cmsglen = ((((sizeof (int)) + sizeof (unsigned long) - 1) & (unsigned long) ~(sizeof (unsigned long) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (unsigned long) - 1) & (unsigned long) ~(sizeof (unsigned long) - 1)));
  tmp = (unsigned char *) malloc (cmsglen * sizeof (unsigned char));
  if (tmp != ((void *)0)) {
    msghdr.msg_control = tmp;}
  else {
    fprintf (stderr, "ERROR: Cannot allocate memory for array 'msghdr.msg_control'.\n");
    exit (1);
  }
  memset (msghdr.msg_control, 0, cmsglen);
  msghdr.msg_controllen = cmsglen;
  fprintf (stderr, "psdhdrlen.\n");
  cmsghdr = ((unsigned long) (&msghdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msghdr)->msg_control : (struct cmsghdr *) 0);
  cmsghdr->cmsg_level = IPPROTO_IPV6;
  cmsghdr->cmsg_type = 52;
  cmsghdr->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (unsigned long) - 1) & (unsigned long) ~(sizeof (unsigned long) - 1)) + (sizeof (int)));
  *((int *) ((cmsghdr)->__cmsg_data)) = 0xff;
  psdhdr[32] = 0;
  psdhdr[33] = 0;
  psdhdr[34] = (4 + datalen) / 256;
  psdhdr[35] = (4 + datalen) % 256;
  psdhdr[36] = 0;
  psdhdr[37] = 0;
  psdhdr[38] = 0;
  psdhdr[39] = IPPROTO_ICMPV6;
  memcpy (psdhdr + 40, outpack, 4 + datalen);
  icmphdr->icmp6_cksum = checksum ((unsigned short *) psdhdr, psdhdrlen);
  printf ("Checksum: %x\n", ntohs (icmphdr->icmp6_cksum));
  if (bind (sock, (struct sockaddr *) &src, srclen) != 0) {
    fprintf (stderr, "Failed to bind the socket descriptor to the source address.\n");
    return;
  }
  if (setsockopt (sock, 1, 25, &ifr, sizeof (ifr)) < 0) {
    fprintf(stderr, "setsockopt() failed to bind to interface\n");
    return;
  }
  ret = sendmsg (sock, &msghdr, 0);
  if (ret < 0) {
    fprintf(stderr, "sendmsg() failed %i %i '%s'\n", ret, status, gai_strerror (status));
    return;
  } else {
    fprintf(stdout, "sendmsg() success\n" );
  }
}

variable_types: type int

variable_types: code int

variable_types:
data
unsigned char *

variable_types: datalen int

variable_types:
ipbuffer
char [40]

variable_types:
icmpbuffer
char [4]

variable_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *

variable_types: struct icmp6_hdr { unsigned char icmp6_type; unsigned char icmp6_code; unsigned short icmp6_cksum; union { unsigned int icmp6_un_data32[1]; unsigned short icmp6_un_data16[2]; unsigned char icmp6_un_data8[4]; } icmp6_dataun; } *

variable_types:
outpack
unsigned char *

variable_types:
psdhdr
unsigned char *

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

variable_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; } *

variable_types: status int

variable_types: sd int

variable_types: cmsglen int

variable_types: psdhdrlen int

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]; char *ifru_data; } ifr_ifru; }

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; }

variable_types:
srclen
unsigned int

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [2]

variable_types:
tmp
void *

variable_types: ret int

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

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]; char *ifru_data; } ifr_ifru; }

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }


decompiled_code:
void rpl_purge_routes()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void
rpl_purge_routes(void)
{
}

canonical_original_code:
void rpl_purge_routes()
{
}


decompiled_code:
void rpl_remove_routes()
{
;
}

original_code:
void
rpl_remove_routes(rpl_dag_t *dag)
{
}

canonical_original_code:
void rpl_remove_routes(struct rpl_dag *dag)
{
}

variable_types: struct rpl_dag { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } dag_id; unsigned short min_rank; unsigned char version; unsigned char grounded; unsigned char preference; unsigned char used; unsigned char joined; struct rpl_parent { struct rpl_parent *next; struct rpl_dag *dag; struct rpl_metric_container { unsigned char type; unsigned char flags; unsigned char aggr; unsigned char prec; unsigned char length; union metric_object { struct rpl_metric_object_energy { unsigned char flags; unsigned char energy_est; } energy; unsigned short etx; } obj; } mc; struct in6_addr addr; unsigned short rank; unsigned char link_metric; unsigned char dtsn; unsigned char updated; } *preferred_parent; unsigned short rank; struct rpl_instance { struct rpl_metric_container mc; struct rpl_of { void (*reset)(struct rpl_dag *); void (*parent_state_callback)(struct rpl_parent *, int, int); struct rpl_parent *(*best_parent)(struct rpl_parent *, struct rpl_parent *); struct rpl_dag *(*best_dag)(struct rpl_dag *, struct rpl_dag *); unsigned short (*calculate_rank)(struct rpl_parent *, unsigned short); void (*update_metric_container)(struct rpl_instance *); unsigned short ocp; } *of; struct rpl_dag *current_dag; struct rpl_dag dag_table[2]; unsigned char instance_id; unsigned char used; unsigned char dtsn_out; unsigned char mop; unsigned char dio_intdoubl; unsigned char dio_intmin; unsigned char dio_redundancy; unsigned char default_lifetime; unsigned char dio_intcurrent; unsigned char dio_send; unsigned char dio_counter; unsigned short max_rankinc; unsigned short min_hoprankinc; unsigned short lifetime_unit; long dio_next_delay; void **dio_timer; void **dao_timer; } *instance; struct rpl_prefix { struct in6_addr prefix; unsigned int lifetime; unsigned char length; unsigned char flags; } prefix_info; } *


decompiled_code:
void rpl_remove_routes_by_nexthop()
{
;
}

original_code:
void
rpl_remove_routes_by_nexthop(struct in6_addr *nexthop, rpl_dag_t *dag)
{
}

canonical_original_code:
void rpl_remove_routes_by_nexthop(struct in6_addr *nexthop, struct rpl_dag *dag)
{
}

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

variable_types: struct rpl_dag { struct in6_addr dag_id; unsigned short min_rank; unsigned char version; unsigned char grounded; unsigned char preference; unsigned char used; unsigned char joined; struct rpl_parent { struct rpl_parent *next; struct rpl_dag *dag; struct rpl_metric_container { unsigned char type; unsigned char flags; unsigned char aggr; unsigned char prec; unsigned char length; union metric_object { struct rpl_metric_object_energy { unsigned char flags; unsigned char energy_est; } energy; unsigned short etx; } obj; } mc; struct in6_addr addr; unsigned short rank; unsigned char link_metric; unsigned char dtsn; unsigned char updated; } *preferred_parent; unsigned short rank; struct rpl_instance { struct rpl_metric_container mc; struct rpl_of { void (*reset)(struct rpl_dag *); void (*parent_state_callback)(struct rpl_parent *, int, int); struct rpl_parent *(*best_parent)(struct rpl_parent *, struct rpl_parent *); struct rpl_dag *(*best_dag)(struct rpl_dag *, struct rpl_dag *); unsigned short (*calculate_rank)(struct rpl_parent *, unsigned short); void (*update_metric_container)(struct rpl_instance *); unsigned short ocp; } *of; struct rpl_dag *current_dag; struct rpl_dag dag_table[2]; unsigned char instance_id; unsigned char used; unsigned char dtsn_out; unsigned char mop; unsigned char dio_intdoubl; unsigned char dio_intmin; unsigned char dio_redundancy; unsigned char default_lifetime; unsigned char dio_intcurrent; unsigned char dio_send; unsigned char dio_counter; unsigned short max_rankinc; unsigned short min_hoprankinc; unsigned short lifetime_unit; long dio_next_delay; void **dio_timer; void **dao_timer; } *instance; struct rpl_prefix { struct in6_addr prefix; unsigned int lifetime; unsigned char length; unsigned char flags; } prefix_info; } *


decompiled_code:
__int64 rpl_init()
{
puts("RPL started");
default_instance = 0LL;
return rpl_reset_periodic_timer();
}

canonical_decompiled_code:
__int64 func3()
{
puts("RPL started");
default_instance = 0LL;
return rpl_reset_periodic_timer();
}

original_code:
void
rpl_init(void)
{
  printf("RPL started\n");
  default_instance = ((void *)0);
  rpl_reset_periodic_timer();
}

canonical_original_code:
void rpl_init()
{
  printf("RPL started\n");
  default_instance = ((void *)0);
  rpl_reset_periodic_timer();
}


decompiled_code:
int __fastcall rpl_debug_ipaddr_print(__int64 a1)
{
__int64 v1; // rbx
int v2; // ebp
int result; // eax
unsigned __int16 v4; // r14

v1 = 0LL;
v2 = 0;
do
{
v4 = (*(unsigned __int8 *)(a1 + v1) << 8) + *(unsigned __int8 *)(a1 + v1 + 1);
if ( v4 || v2 < 0 )
{
if ( v2 <= 0 )
{
if ( (_DWORD)v1 )
putchar(58);
}
else
{
v2 = -1;
}
result = printf("%x", v4);
}
else if ( v2 )
{
++v2;
}
else
{
result = printf("::");
v2 = 1;
}
v1 += 2LL;
}
while ( v1 != 16 );
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
int v2; // ebp
int result; // eax
unsigned __int16 v4; // r14

v1 = 0LL;
v2 = 0;
do
{
v4 = (*(unsigned __int8 *)(a1 + v1) << 8) + *(unsigned __int8 *)(a1 + v1 + 1);
if ( v4 || v2 < 0 )
{
if ( v2 <= 0 )
{
if ( (_DWORD)v1 )
putchar(58);
}
else
{
v2 = -1;
}
result = printf("%x", v4);
}
else if ( v2 )
{
++v2;
}
else
{
result = printf("::");
v2 = 1;
}
v1 += 2LL;
}
while ( v1 != 16 );
return result;
}

original_code:
void
rpl_debug_ipaddr_print(struct in6_addr *addr)
{
  uint16_t a;
  unsigned int i;
  int f;
  for(i = 0, f = 0; i < sizeof(struct in6_addr); i += 2) {
    a = (addr->__in6_u.__u6_addr8[i] << 8) + addr->__in6_u.__u6_addr8[i + 1];
    if(a == 0 && f >= 0) {
      if(f++ == 0) {
        printf("::");
      }
    } else {
      if(f > 0) {
        f = -1;
      } else if(i > 0) {
        printf(":");
      }
      printf("%x", a);
    }
  }
}

canonical_original_code:
void rpl_debug_ipaddr_print(struct in6_addr *addr)
{
  unsigned short a;
  unsigned int i;
  int f;
  for(i = 0, f = 0; i < sizeof(struct in6_addr); i += 2) {
    a = (addr->__in6_u.__u6_addr8[i] << 8) + addr->__in6_u.__u6_addr8[i + 1];
    if(a == 0 && f >= 0) {
      if(f++ == 0) {
        printf("::");
      }
    } else {
      if(f > 0) {
        f = -1;
      } else if(i > 0) {
        printf(":");
      }
      printf("%x", a);
    }
  }
}

variable_types:
a
unsigned short

variable_types:
i
unsigned int

variable_types: f int


decompiled_code:
__int64 open_icmpv6_socket()
{
int v0; // eax
unsigned int v1; // ebx
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v18[5]; // [rsp+10h] [rbp-28h] BYREF

v0 = socket(10, 3, 58);
if ( v0 < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "can't create socket(AF_INET6): %s", v4);
v1 = -1;
}
else
{
v1 = v0;
optval = 1;
if ( setsockopt(v0, 41, 49, &optval, 4u) < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "setsockopt(IPV6_RECVPKTINFO): %s", v6);
v1 = -1;
}
else
{
optval = 2;
if ( setsockopt(v1, 255, 7, &optval, 4u) < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "setsockopt(IPV6_CHECKSUM): %s", v8);
v1 = -1;
}
else
{
optval = 255;
if ( setsockopt(v1, 41, 16, &optval, 4u) < 0 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "setsockopt(IPV6_UNICAST_HOPS): %s", v10);
v1 = -1;
}
else
{
optval = 255;
if ( setsockopt(v1, 41, 18, &optval, 4u) < 0 )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "setsockopt(IPV6_MULTICAST_HOPS): %s", v12);
v1 = -1;
}
else
{
optval = 1;
if ( setsockopt(v1, 41, 51, &optval, 4u) < 0 )
{
v13 = _errno_location();
v14 = strerror(*v13);
fprintf(stderr, "setsockopt(IPV6_RECVHOPLIMIT): %s", v14);
v1 = -1;
}
else
{
v18[0] = -1LL;
v18[1] = -1LL;
v18[2] = -134217729LL;
v18[3] = -1LL;
if ( setsockopt(v1, 58, 1, v18, 0x20u) < 0 )
{
v15 = _errno_location();
v16 = strerror(*v15);
fprintf(stderr, "setsockopt(ICMPV6_FILTER): %s", v16);
v1 = -1;
}
}
}
}
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
unsigned int v1; // ebx
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v18[5]; // [rsp+10h] [rbp-28h] BYREF

v0 = socket(10, 3, 58);
if ( v0 < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "can't create socket(AF_INET6): %s", v4);
v1 = -1;
}
else
{
v1 = v0;
optval = 1;
if ( setsockopt(v0, 41, 49, &optval, 4u) < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "setsockopt(IPV6_RECVPKTINFO): %s", v6);
v1 = -1;
}
else
{
optval = 2;
if ( setsockopt(v1, 255, 7, &optval, 4u) < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "setsockopt(IPV6_CHECKSUM): %s", v8);
v1 = -1;
}
else
{
optval = 255;
if ( setsockopt(v1, 41, 16, &optval, 4u) < 0 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "setsockopt(IPV6_UNICAST_HOPS): %s", v10);
v1 = -1;
}
else
{
optval = 255;
if ( setsockopt(v1, 41, 18, &optval, 4u) < 0 )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "setsockopt(IPV6_MULTICAST_HOPS): %s", v12);
v1 = -1;
}
else
{
optval = 1;
if ( setsockopt(v1, 41, 51, &optval, 4u) < 0 )
{
v13 = _errno_location();
v14 = strerror(*v13);
fprintf(stderr, "setsockopt(IPV6_RECVHOPLIMIT): %s", v14);
v1 = -1;
}
else
{
v18[0] = -1LL;
v18[1] = -1LL;
v18[2] = -134217729LL;
v18[3] = -1LL;
if ( setsockopt(v1, 58, 1, v18, 0x20u) < 0 )
{
v15 = _errno_location();
v16 = strerror(*v15);
fprintf(stderr, "setsockopt(ICMPV6_FILTER): %s", v16);
v1 = -1;
}
}
}
}
}
}
}
return v1;
}

original_code:
int
open_icmpv6_socket(void)
{
 int sock;
 struct icmp6_filter filter;
 int err, val;
        sock = socket(10, SOCK_RAW, IPPROTO_ICMPV6);
 if (sock < 0)
 {
  fprintf(stderr, "can't create socket(AF_INET6): %s", strerror((*__errno_location ())));
  return (-1);
 }
 val = 1;
 err = setsockopt(sock, IPPROTO_IPV6, 49, &val, sizeof(val));
 if (err < 0)
 {
  fprintf(stderr, "setsockopt(IPV6_RECVPKTINFO): %s", strerror((*__errno_location ())));
  return (-1);
 }
 val = 2;
 err = setsockopt(sock, IPPROTO_RAW, 7, &val, sizeof(val));
 if (err < 0)
 {
  fprintf(stderr, "setsockopt(IPV6_CHECKSUM): %s", strerror((*__errno_location ())));
  return (-1);
 }
 val = 255;
 err = setsockopt(sock, IPPROTO_IPV6, 16, &val, sizeof(val));
 if (err < 0)
 {
  fprintf(stderr, "setsockopt(IPV6_UNICAST_HOPS): %s", strerror((*__errno_location ())));
  return (-1);
 }
 val = 255;
 err = setsockopt(sock, IPPROTO_IPV6, 18, &val, sizeof(val));
 if (err < 0)
 {
  fprintf(stderr, "setsockopt(IPV6_MULTICAST_HOPS): %s", strerror((*__errno_location ())));
  return (-1);
 }
 val = 1;
 err = setsockopt(sock, IPPROTO_IPV6, 51, &val, sizeof(val));
 if (err < 0)
 {
  fprintf(stderr, "setsockopt(IPV6_RECVHOPLIMIT): %s", strerror((*__errno_location ())));
  return (-1);
 }
 memset (&filter, 0xFF, sizeof (struct icmp6_filter));;
 ((((&filter)->icmp6_filt[(155) >> 5]) &= ~(1 << ((155) & 31))));
 err = setsockopt(sock, IPPROTO_ICMPV6, 1, &filter,
    sizeof(filter));
 if (err < 0)
 {
  fprintf(stderr, "setsockopt(ICMPV6_FILTER): %s", strerror((*__errno_location ())));
  return (-1);
 }
 return sock;
}

canonical_original_code:
int open_icmpv6_socket()
{
 int sock;
 struct icmp6_filter filter;
 int err; int val;
        sock = socket(10, SOCK_RAW, IPPROTO_ICMPV6);
 if (sock < 0)
 {
  fprintf(stderr, "can't create socket(AF_INET6): %s", strerror((*__errno_location ())));
  return (-1);
 }
 val = 1;
 err = setsockopt(sock, IPPROTO_IPV6, 49, &val, sizeof(val));
 if (err < 0)
 {
  fprintf(stderr, "setsockopt(IPV6_RECVPKTINFO): %s", strerror((*__errno_location ())));
  return (-1);
 }
 val = 2;
 err = setsockopt(sock, IPPROTO_RAW, 7, &val, sizeof(val));
 if (err < 0)
 {
  fprintf(stderr, "setsockopt(IPV6_CHECKSUM): %s", strerror((*__errno_location ())));
  return (-1);
 }
 val = 255;
 err = setsockopt(sock, IPPROTO_IPV6, 16, &val, sizeof(val));
 if (err < 0)
 {
  fprintf(stderr, "setsockopt(IPV6_UNICAST_HOPS): %s", strerror((*__errno_location ())));
  return (-1);
 }
 val = 255;
 err = setsockopt(sock, IPPROTO_IPV6, 18, &val, sizeof(val));
 if (err < 0)
 {
  fprintf(stderr, "setsockopt(IPV6_MULTICAST_HOPS): %s", strerror((*__errno_location ())));
  return (-1);
 }
 val = 1;
 err = setsockopt(sock, IPPROTO_IPV6, 51, &val, sizeof(val));
 if (err < 0)
 {
  fprintf(stderr, "setsockopt(IPV6_RECVHOPLIMIT): %s", strerror((*__errno_location ())));
  return (-1);
 }
 memset (&filter, 0xFF, sizeof (struct icmp6_filter));;
 ((((&filter)->icmp6_filt[(155) >> 5]) &= ~(1 << ((155) & 31))));
 err = setsockopt(sock, IPPROTO_ICMPV6, 1, &filter,
    sizeof(filter));
 if (err < 0)
 {
  fprintf(stderr, "setsockopt(ICMPV6_FILTER): %s", strerror((*__errno_location ())));
  return (-1);
 }
 return sock;
}

variable_types: sock int

variable_types: struct icmp6_filter { unsigned int icmp6_filt[8]; }

variable_types: err int

variable_types: val int

return_type: int


repo: markwkm/quicksort

decompiled_code:
int get_lock()
{
unsigned int v1; // eax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = -1;
sops.sem_flg = 0;
if ( semop(sem_id, &sops, 1uLL) == -1 )
{
v1 = getpid();
fprintf(stderr, "[%d] ", v1);
perror("semop");
shmdt(shm_degree);
shmctl(shm_id1, 0, 0LL);
shmctl(shm_id2, 0, 0LL);
semctl(sem_id, 0, 0);
exit(1);
}
return printf(" %d", *(unsigned int *)shm_degree);
}

canonical_decompiled_code:
int func7()
{
unsigned int v1; // eax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = -1;
sops.sem_flg = 0;
if ( semop(sem_id, &sops, 1uLL) == -1 )
{
v1 = getpid();
fprintf(stderr, "[%d] ", v1);
perror("semop");
shmdt(shm_degree);
shmctl(shm_id1, 0, 0LL);
shmctl(shm_id2, 0, 0LL);
semctl(sem_id, 0, 0);
exit(1);
}
return printf(" %d", *(unsigned int *)shm_degree);
}

original_code:
void get_lock()
{
 struct sembuf operations[1];
 operations[0].sem_num = 0;
 operations[0].sem_op = -1;
 operations[0].sem_flg = 0;
 if (semop(sem_id, operations, 1) == -1) {
  fprintf(stderr, "[%d] ", getpid());
  perror("semop");
  shmdt(shm_degree);
  shmctl(shm_id1, 0, ((void *)0));
  shmctl(shm_id2, 0, ((void *)0));
  semctl(sem_id, 0, 0);
  exit(1);
 }
 printf(" %d", *shm_degree);
}

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; } [1]


decompiled_code:
int release_lock()
{
unsigned int v1; // eax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = 1;
sops.sem_flg = 0;
if ( semop(sem_id, &sops, 1uLL) == -1 )
{
v1 = getpid();
fprintf(stderr, "[%d] ", v1);
perror("semop");
shmdt(shm_degree);
shmctl(shm_id1, 0, 0LL);
shmctl(shm_id2, 0, 0LL);
semctl(sem_id, 0, 0);
exit(1);
}
return printf(" %d", *(unsigned int *)shm_degree);
}

canonical_decompiled_code:
int func8()
{
unsigned int v1; // eax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = 1;
sops.sem_flg = 0;
if ( semop(sem_id, &sops, 1uLL) == -1 )
{
v1 = getpid();
fprintf(stderr, "[%d] ", v1);
perror("semop");
shmdt(shm_degree);
shmctl(shm_id1, 0, 0LL);
shmctl(shm_id2, 0, 0LL);
semctl(sem_id, 0, 0);
exit(1);
}
return printf(" %d", *(unsigned int *)shm_degree);
}

original_code:
void release_lock()
{
 struct sembuf operations[1];
 operations[0].sem_num = 0;
 operations[0].sem_op = 1;
 operations[0].sem_flg = 0;
 if (semop(sem_id, operations, 1) == -1) {
  fprintf(stderr, "[%d] ", getpid());
  perror("semop");
  shmdt(shm_degree);
  shmctl(shm_id1, 0, ((void *)0));
  shmctl(shm_id2, 0, ((void *)0));
  semctl(sem_id, 0, 0);
  exit(1);
 }
 printf(" %d", *shm_degree);
}

user_defined_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


display

decompiled_code:
int __fastcall display(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

putchar(62);
if ( a2 > 0 )
{
v2 = a1;
do
printf(" %d", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

putchar(62);
if ( a2 > 0 )
{
v2 = a1;
do
printf(" %d", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return putchar(10);
}

original_code:
void display(int array[], int length)
{
 int i;
 printf(">");
 for (i = 0; i < length; i++)
  printf(" %d", array[i]);
 printf("\n");
}

variable_types:
array
int []

variable_types: length int

variable_types: i int


swap

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

v3 = (int *)(a1 + 4LL * a2);
v4 = *v3;
result = (int *)(a1 + 4LL * a3);
*v3 = *result;
*result = v4;
return result;
}

canonical_decompiled_code:
int *__fastcall func10(__int64 a1, int a2, int a3)
{
int *v3; // rcx
int v4; // esi
int *result; // rax

v3 = (int *)(a1 + 4LL * a2);
v4 = *v3;
result = (int *)(a1 + 4LL * a3);
*v3 = *result;
*result = v4;
return result;
}

original_code:
void swap(int array[], int left, int right)
{
 int temp;
 temp = array[left];
 array[left] = array[right];
 array[right] = temp;
}

variable_types: left int

variable_types: right int

variable_types: temp int


main

canonical_name: main

repo: marlonsd/EDII-Trie

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
char v4; // al
char v6; // bl
_BYTE *v7; // rbp
char v8; // al
__int64 i; // rbx
char v10; // [rsp+Eh] [rbp-1Ah]
char v11; // [rsp+Fh] [rbp-19h]

v3 = Trie(argc, argv, envp);
__isoc99_scanf();
v4 = v10;
if ( v10 != 64 )
{
while ( (v4 & 0xEF) != 98 && v4 != 105 )
{
LABEL_11:
__isoc99_scanf();
v4 = v10;
}
__isoc99_scanf();
v7 = malloc(0x88B9uLL);
if ( !v7 )
{
puts(s);
exit(1);
}
__isoc99_scanf();
v8 = v11;
if ( v11 != 10 )
{
for ( i = 0LL; ; ++i )
{
v7[i] = v8;
__isoc99_scanf();
v8 = v11;
}
}
*v7 = 0;
switch ( v10 )
{
case 'i':
v6 = insert(v3, v7);
break;
case 'r':
v6 = delete(v3, v7);
break;
case 'b':
v6 = find(v3, v7);
break;
default:
free(v7);
goto LABEL_9;
}
free(v7);
if ( !v6 )
{
putchar(102);
LABEL_10:
putchar(10);
goto LABEL_11;
}
LABEL_9:
putchar(118);
goto LABEL_10;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
char v4; // al
char v6; // bl
_BYTE *v7; // rbp
char v8; // al
__int64 i; // rbx
char v10; // [rsp+Eh] [rbp-1Ah]
char v11; // [rsp+Fh] [rbp-19h]

v3 = func7(argc, argv, envp);
__isoc99_scanf();
v4 = v10;
if ( v10 != 64 )
{
while ( (v4 & 0xEF) != 98 && v4 != 105 )
{
LABEL_11:
__isoc99_scanf();
v4 = v10;
}
__isoc99_scanf();
v7 = malloc(0x88B9uLL);
if ( !v7 )
{
puts(s);
exit(1);
}
__isoc99_scanf();
v8 = v11;
if ( v11 != 10 )
{
for ( i = 0LL; ; ++i )
{
v7[i] = v8;
__isoc99_scanf();
v8 = v11;
}
}
*v7 = 0;
switch ( v10 )
{
case 'i':
v6 = func8(v3, v7);
break;
case 'r':
v6 = func11(v3, v7);
break;
case 'b':
v6 = func10(v3, v7);
break;
default:
free(v7);
goto LABEL_9;
}
free(v7);
if ( !v6 )
{
putchar(102);
LABEL_10:
putchar(10);
goto LABEL_11;
}
LABEL_9:
putchar(118);
goto LABEL_10;
}
return 0;
}

original_code:
int main(){
 unsigned long int i;
 node *raiz;
 char aux, op, sel, *palavra;
 raiz = Trie();
 scanf("%c", &sel);
 while(sel != '@'){
  if ((sel == 'b') || (sel == 'i') || (sel == 'r')){
   scanf("%c", &aux);
   if (!(palavra = malloc(sizeof(char)*(35000 + 1)))){
    printf("Falha a alocar memória.\n");
    exit(1);
   }
   scanf("%c", &aux);
   i = 0;
   while((aux != '\n')){
    palavra[i] = aux;
    i++;
    scanf("%c", &aux);
   }
   palavra[i] = '\0';
   op = 1;
   switch(sel){
    case 'b': op = find(raiz, palavra);
     break;
    case 'i': op = insert(raiz, palavra);
     break;
    case 'r': op = delete(raiz, palavra);
     break;
   }
   free(palavra);
   if (op){
    printf("v");
   } else {
    printf("f");
   }
   printf("\n");
  }
  scanf("%c", &sel);
 }
 return 0;
}

canonical_original_code:
int main(){
 unsigned long i;
 struct no *raiz;
 char aux; char op; char sel; char *palavra;
 raiz = Trie();
 scanf("%c", &sel);
 while(sel != '@'){
  if ((sel == 'b') || (sel == 'i') || (sel == 'r')){
   scanf("%c", &aux);
   if (!(palavra = malloc(sizeof(char)*(35000 + 1)))){
    printf("Falha a alocar memória.\n");
    exit(1);
   }
   scanf("%c", &aux);
   i = 0;
   while((aux != '\n')){
    palavra[i] = aux;
    i++;
    scanf("%c", &aux);
   }
   palavra[i] = '\0';
   op = 1;
   switch(sel){
    case 'b': op = find(raiz, palavra);
     break;
    case 'i': op = insert(raiz, palavra);
     break;
    case 'r': op = delete(raiz, palavra);
     break;
   }
   free(palavra);
   if (op){
    printf("v");
   } else {
    printf("f");
   }
   printf("\n");
  }
  scanf("%c", &sel);
 }
 return 0;
}

variable_types:
i
unsigned long

variable_types: struct no { struct no *key[27]; struct no *father; int kids; } *

variable_types: aux char

variable_types: op char

variable_types: sel char

variable_types:
palavra
char *


Trie

original_code:
node *Trie(){
 node *T;
 int i;
 if (!(T = malloc(sizeof(node)))){
  return ((void *)0);
 }
 T->father = ((void *)0);
 for (i = 0; i < 27; i++){
  T->key[i] = ((void *)0);
 }
 T->kids = 0;
 return T;
}

canonical_original_code:
struct no *Trie(){
 struct no *T;
 int i;
 if (!(T = malloc(sizeof(node)))){
  return ((void *)0);
 }
 T->father = ((void *)0);
 for (i = 0; i < 27; i++){
  T->key[i] = ((void *)0);
 }
 T->kids = 0;
 return T;
}

return_type: struct no { struct no *key[27]; struct no *father; int kids; } *


insert

original_code:
int insert(node *T, char *word){
 int i, pos;
 node *aux, *pointer;
 pointer = T;
 for (i = 0; word[i] != '\0'; i++){
  pos = word[i] - 'a';
  if (pointer->key[pos]){
   pointer = pointer->key[pos];
  } else {
   aux = Trie();
   if (!aux) {
    return 0;
   }
   pointer->key[pos] = aux;
   aux->father = pointer;
   pointer->kids++;
   pointer = aux;
  }
 }
 if (!pointer->key[26]){
  pointer->key[26] = (node *) 1;
  pointer->kids++;
 }
 return 1;
}

canonical_original_code:
int insert(struct no *T, char *word){
 int i; int pos;
 struct no *aux; struct no *pointer;
 pointer = T;
 for (i = 0; word[i] != '\0'; i++){
  pos = word[i] - 'a';
  if (pointer->key[pos]){
   pointer = pointer->key[pos];
  } else {
   aux = Trie();
   if (!aux) {
    return 0;
   }
   pointer->key[pos] = aux;
   aux->father = pointer;
   pointer->kids++;
   pointer = aux;
  }
 }
 if (!pointer->key[26]){
  pointer->key[26] = (struct no *) 1;
  pointer->kids++;
 }
 return 1;
}

variable_types:
word
char *

variable_types: pos int

user_defined_types: struct no { struct no *key[27]; struct no *father; int kids; }


get

original_code:
node *get(node *T, char *word){
 int i, pos;
 node *pointer;
 i = 0;
 pointer = T;
 if (word[i] == '\0'){
  return ((void *)0);
 } else {
  while((word[i] != '\0') && (pointer)){
   pos = word[i] - 'a';
   pointer = pointer->key[pos];
   i++;
  }
 }
 return pointer;
}

canonical_original_code:
struct no *get(struct no *T, char *word){
 int i; int pos;
 struct no *pointer;
 i = 0;
 pointer = T;
 if (word[i] == '\0'){
  return ((void *)0);
 } else {
  while((word[i] != '\0') && (pointer)){
   pos = word[i] - 'a';
   pointer = pointer->key[pos];
   i++;
  }
 }
 return pointer;
}

variable_types:
T
struct no *


find

decompiled_code:
_BOOL8 __fastcall find(__int64 a1, char *a2)
{
__int64 v2; // rax
_BOOL4 v3; // edx

v2 = get(a1, a2);
v3 = 0;
if ( v2 )
v3 = *(_QWORD *)(v2 + 208) != 0LL;
return v3;
}

original_code:
int find(node *T, char *word){
 node *aux;
 aux = get(T, word);
 if ((aux) && (aux->key[26])){
  return 1;
 }
 return 0;
}

canonical_original_code:
int find(struct no *T, char *word){
 struct no *aux;
 aux = get(T, word);
 if ((aux) && (aux->key[26])){
  return 1;
 }
 return 0;
}


delete

original_code:
int delete(node *T, char *word){
 int i;
 node *aux, *father;
 aux = get(T, word);
 if (aux && aux->key[26]){
  aux->key[26] = ((void *)0);
  aux->kids--;
  while (aux->father && (!aux->kids)){
   father = aux->father;
   i = 0;
   while((father->key[i] != aux) && (i < 26)){
    i++;
   }
   father->key[i] = ((void *)0);
   father->kids--;
   if (aux->father){
    free(aux);
   }
   aux = father;
  }
 } else {
  return 0;
 }
 return 1;
}

canonical_original_code:
int delete(struct no *T, char *word){
 int i;
 struct no *aux; struct no *father;
 aux = get(T, word);
 if (aux && aux->key[26]){
  aux->key[26] = ((void *)0);
  aux->kids--;
  while (aux->father && (!aux->kids)){
   father = aux->father;
   i = 0;
   while((father->key[i] != aux) && (i < 26)){
    i++;
   }
   father->key[i] = ((void *)0);
   father->kids--;
   if (aux->father){
    free(aux);
   }
   aux = father;
  }
 } else {
  return 0;
 }
 return 1;
}


main

repo: marlonsd/PCI-VirtualMachine

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // al
int v4; // ebp
int v5; // ebx
int v6; // ebx
char v8[25]; // [rsp+Fh] [rbp-19h] BYREF

initMem(argc, argv, envp);
initReg();
_isoc99_scanf(&unk_320, v8);
v3 = v8[0];
if ( v8[0] != 64 )
{
v4 = 0;
v5 = 0;
do
{
if ( v3 == 10 )
{
v5 = 0;
}
else
{
ram[2 * v4 + v5++] = v3;
if ( v5 == 2 )
{
++v4;
v5 = 0;
}
}
_isoc99_scanf(&unk_320, v8);
v3 = v8[0];
}
while ( v8[0] != 64 );
}
v6 = execucao();
printRegistradores();
if ( v6 )
puts(s);
else
puts(aAlgumProblemaF);
return 0;
}

original_code:
int main(){
 int i, j, aux, mem;
 char word[4], c;
 initMem();
 initReg();
 i = 0;
 j = 0;
 scanf("%c", &c);
 while(c != '@'){
  if (c != '\n'){
   ram[j].valor[i] = c;
   i++;
   if (i == 2){
    j++;
    i = 0;
   }
  } else {
   i = 0;
  }
  scanf("%c", &c);
 }
 i = execucao();
 printRegistradores();
 if (i){
  printf("Execução finalizada com sucesso.\n");
 } else {
  printf("Algum problema foi encontrado na execução.\n");
 }
 return 0;
}

canonical_original_code:
int main(){
 int i; int j; int aux; int mem;
 char word[4]; char c;
 initMem();
 initReg();
 i = 0;
 j = 0;
 scanf("%c", &c);
 while(c != '@'){
  if (c != '\n'){
   ram[j].valor[i] = c;
   i++;
   if (i == 2){
    j++;
    i = 0;
   }
  } else {
   i = 0;
  }
  scanf("%c", &c);
 }
 i = execucao();
 printRegistradores();
 if (i){
  printf("Execução finalizada com sucesso.\n");
 } else {
  printf("Algum problema foi encontrado na execução.\n");
 }
 return 0;
}

variable_types: j int

variable_types: aux int

variable_types: mem int

variable_types:
word
char [4]

variable_types: c char


initMem

decompiled_code:
char *initMem()
{
char *result; // rax

result = &ram;
do
{
*result = 0;
result[1] = 0;
result += 2;
}
while ( result != (char *)(unsigned int)((_DWORD)&ram + 512) );
return result;
}

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

result = &ram;
do
{
*result = 0;
result[1] = 0;
result += 2;
}
while ( result != (char *)(unsigned int)((_DWORD)&ram + 512) );
return result;
}

variable_types: i int


initReg

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

result = &variavel;
do
*result++ = 0;
while ( result != (int *)(unsigned int)((_DWORD)&variavel + 64) );
return result;
}

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

result = &variavel;
do
*result++ = 0;
while ( result != (int *)(unsigned int)((_DWORD)&variavel + 64) );
return result;
}

original_code:
void initReg(){
 int i;
 i = 0;
 while (i < 16){
  variavel.valor[i] = 0;
  i++;
 }
}


conversaoHexa

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

switch ( a1 )
{
case 0:
case 48:
result = 0LL;
break;
case 49:
result = 1LL;
break;
case 50:
result = 2LL;
break;
case 51:
result = 3LL;
break;
case 52:
result = 4LL;
break;
case 53:
result = 5LL;
break;
case 54:
result = 6LL;
break;
case 55:
result = 7LL;
break;
case 56:
result = 8LL;
break;
case 57:
result = 9LL;
break;
case 65:
result = 10LL;
break;
case 66:
result = 11LL;
break;
case 67:
result = 12LL;
break;
case 68:
result = 13LL;
break;
case 69:
result = 14LL;
break;
case 70:
result = 15LL;
break;
default:
result = 16LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 0:
case 48:
result = 0LL;
break;
case 49:
result = 1LL;
break;
case 50:
result = 2LL;
break;
case 51:
result = 3LL;
break;
case 52:
result = 4LL;
break;
case 53:
result = 5LL;
break;
case 54:
result = 6LL;
break;
case 55:
result = 7LL;
break;
case 56:
result = 8LL;
break;
case 57:
result = 9LL;
break;
case 65:
result = 10LL;
break;
case 66:
result = 11LL;
break;
case 67:
result = 12LL;
break;
case 68:
result = 13LL;
break;
case 69:
result = 14LL;
break;
case 70:
result = 15LL;
break;
default:
result = 16LL;
break;
}
return result;
}

original_code:
int conversaoHexa(char c){
 switch(c){
  case '0': return 0;
   break;
  case '1': return 1;
   break;
  case '2': return 2;
   break;
  case '3': return 3;
   break;
  case '4': return 4;
   break;
  case '5': return 5;
   break;
  case '6': return 6;
   break;
  case '7': return 7;
   break;
  case '8': return 8;
   break;
  case '9': return 9;
   break;
  case 'A': return 10;
   break;
  case 'B': return 11;
   break;
  case 'C': return 12;
   break;
  case 'D': return 13;
   break;
  case 'E': return 14;
   break;
  case 'F': return 15;
   break;
  case '\0': return 0;
   break;
  default: return 16;
 }
}


conversao

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

result = conversaoHexa(a1);
if ( (unsigned int)(result - 1) >= 0xC )
result = 0LL;
return result;
}

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

result = func2(a1);
if ( (unsigned int)(result - 1) >= 0xC )
result = 0LL;
return result;
}

original_code:
int conversao(char word){
 int aux;
 aux = conversaoHexa(word);
 if ((aux <= 0) || (aux >= 13)){
  return 0;
 }
 return aux;
}

variable_types: word char


getEndreco

decompiled_code:
__int64 __fastcall getEndreco(char a1, char a2)
{
int v2; // ebx

v2 = conversaoHexa(a1);
return (16 * v2) | (unsigned int)conversaoHexa(a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1, char a2)
{
int v2; // ebx

v2 = func2(a1);
return (16 * v2) | (unsigned int)func2(a2);
}

original_code:
char getEndreco(char most, char least){
 char i, aux;
 i = conversaoHexa(most);
 aux = conversaoHexa(least);
 i = i << 4;
 i = i | aux;
 return i;
}

canonical_original_code:
char getEndreco(char most, char least){
 char i; char aux;
 i = conversaoHexa(most);
 aux = conversaoHexa(least);
 i = i << 4;
 i = i | aux;
 return i;
}

variable_types: most char

variable_types: least char

variable_types: i char

return_type: char


leituraMem

decompiled_code:
__int64 __fastcall leituraMem(int a1)
{
int v1; // ebx

v1 = 16 * (char)conversaoHexa(ram[2 * a1]);
return v1 | (unsigned int)conversaoHexa(ram[2 * a1 + 1]);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v1; // ebx

v1 = 16 * (char)func2(ram[2 * a1]);
return v1 | (unsigned int)func2(ram[2 * a1 + 1]);
}

original_code:
char leituraMem(int endereco){
 char i, valor, aux;
 valor = conversaoHexa(ram[endereco].valor[0]);
 valor = valor << 4;
 aux = conversaoHexa(ram[endereco].valor[1]);
 valor = valor | aux;
 return valor;
}

canonical_original_code:
char leituraMem(int endereco){
 char i; char valor; char aux;
 valor = conversaoHexa(ram[endereco].valor[0]);
 valor = valor << 4;
 aux = conversaoHexa(ram[endereco].valor[1]);
 valor = valor | aux;
 return valor;
}

variable_types: endereco int

variable_types: valor char

variable_types: aux char


conversaoChar

decompiled_code:
__int64 __fastcall conversaoChar(unsigned int a1)
{
__int64 result; // rax
unsigned int v2; // eax
unsigned int v3; // edi
bool v4; // cf

if ( a1 <= 9 )
return a1 + 48;
v2 = a1 - 10;
v3 = a1 + 55;
v4 = v2 < 6;
result = 0LL;
if ( v4 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
__int64 result; // rax
unsigned int v2; // eax
unsigned int v3; // edi
bool v4; // cf

if ( a1 <= 9 )
return a1 + 48;
v2 = a1 - 10;
v3 = a1 + 55;
v4 = v2 < 6;
result = 0LL;
if ( v4 )
result = v3;
return result;
}

original_code:
char conversaoChar(int x){
 char aux;
 aux = '\0';
 if ((x >= 0) && (x < 10)){
  aux = x + '0';
 } else {
  if ((x >= 10) && (x < 16)){
   aux = x + 'A' - 10;
  }
 }
 return aux;
}

variable_types: x int


conversaoHToChar

decompiled_code:
__int64 __fastcall conversaoHToChar(int a1, int a2)
{
char v2; // al
__int64 result; // rax

v2 = conversaoChar(a1 >> 4);
if ( !v2 )
{
puts("ERRO!");
exit(1);
}
ram[2 * a2] = v2;
result = conversaoChar(a1 & 0xF);
if ( !(_BYTE)result )
{
puts("ERRO!");
exit(1);
}
ram[2 * a2 + 1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
char v2; // al
__int64 result; // rax

v2 = func6(a1 >> 4);
if ( !v2 )
{
puts("ERRO!");
exit(1);
}
ram[2 * a2] = v2;
result = func6(a1 & 0xF);
if ( !(_BYTE)result )
{
puts("ERRO!");
exit(1);
}
ram[2 * a2 + 1] = result;
return result;
}

original_code:
void conversaoHToChar (int x, int pos){
 int aux;
 char c;
 aux = x & 15;
 x = x >> 4;
 c = conversaoChar(x);
 if (c == '\0'){
  printf("ERRO!\n");
  exit(1);
 }
 ram[pos].valor[0] = conversaoChar(x);
 c = conversaoChar(aux);
 if (c == '\0'){
  printf("ERRO!\n");
  exit(1);
 }
 ram[pos].valor[1] = conversaoChar(aux);
}

canonical_original_code:
void conversaoHToChar(int x, int pos){
 int aux;
 char c;
 aux = x & 15;
 x = x >> 4;
 c = conversaoChar(x);
 if (c == '\0'){
  printf("ERRO!\n");
  exit(1);
 }
 ram[pos].valor[0] = conversaoChar(x);
 c = conversaoChar(aux);
 if (c == '\0'){
  printf("ERRO!\n");
  exit(1);
 }
 ram[pos].valor[1] = conversaoChar(aux);
}