decompiled_code:
__int64 __fastcall cc_process_generic_msg(__int64 a1, unsigned __int8 *a2)
{
unsigned __int8 v2; // dl
__int64 result; // rax
unsigned __int8 v4; // dl
unsigned __int8 v5; // dl
unsigned __int8 v6; // dl
char v7[536]; // [rsp+0h] [rbp-218h] BYREF

v2 = a2[5];
switch ( v2 )
{
case 0x60u:
syslog(7, "COMMAND_CLASS_MULTI_INSTANCE");
v4 = a2[6];
if ( v4 == 5 )
{
syslog(7, "Got MULTI_INSTANCE_REPORT from node %i: Command Class 0x%x, instance count: %i", a2[3], a2[7], a2[8]);
result = 0LL;
}
else
{
result = 0LL;
if ( v4 == 6 )
{
syslog(
7,
"Got MULTI_INSTANCE_CMD_ENCAP from node %i: instance %i Command Class 0x%x type 0x%x",
a2[3],
a2[7],
a2[8],
a2[9]);
v5 = a2[8];
if ( v5 == 49 )
{
syslog(
7,
"CommandSensorMultilevelReport: node=%i, inst=%i, type=%i, valuem=%i, value=%i",
a2[3],
a2[7],
a2[10],
a2[11],
a2[12]);
result = 0LL;
}
else
{
result = 0LL;
if ( v5 == 32 )
{
v6 = a2[9];
if ( v6 == 3 )
{
syslog(7, "Got basic report from node %i, instance %i, value: %i", a2[3], a2[7], a2[10]);
result = 0LL;
}
else
{
result = 0LL;
if ( v6 == 1 )
{
syslog(7, "Got basic set from node %i, instance %i, value: %i", a2[3], a2[7], a2[10]);
result = 0LL;
}
}
}
}
}
}
break;
case 0x86:
syslog(7, "\nCOMMAND_CLASS_VERSION");
result = 0LL;
if ( a2[6] == 18 )
{
syslog(
7,
"REPORT: Lib.typ: 0x%x, Prot.Ver: 0x%x, Sub: 0x%x App.Ver: 0x%x, Sub: 0x%x",
a2[7],
a2[8],
a2[9],
a2[10],
a2[11]);
result = 0LL;
}
break;
case 0x21u:
syslog(7, "COMMAND_CLASS_CONTROLLER_REPLICATION");
v7[0] = 68;
((void (__fastcall *)(__int64, char *, __int64, _QWORD, _QWORD, _QWORD))zw_send_request)(
a1,
v7,
1LL,
0LL,
0LL,
0LL);
result = 0LL;
break;
default:
syslog(7, "Function not implemented - unhandled command class: %x", v2);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int8 *a2)
{
unsigned __int8 v2; // dl
__int64 result; // rax
unsigned __int8 v4; // dl
unsigned __int8 v5; // dl
unsigned __int8 v6; // dl
char v7[536]; // [rsp+0h] [rbp-218h] BYREF

v2 = a2[5];
switch ( v2 )
{
case 0x60u:
syslog(7, "COMMAND_CLASS_MULTI_INSTANCE");
v4 = a2[6];
if ( v4 == 5 )
{
syslog(7, "Got MULTI_INSTANCE_REPORT from node %i: Command Class 0x%x, instance count: %i", a2[3], a2[7], a2[8]);
result = 0LL;
}
else
{
result = 0LL;
if ( v4 == 6 )
{
syslog(
7,
"Got MULTI_INSTANCE_CMD_ENCAP from node %i: instance %i Command Class 0x%x type 0x%x",
a2[3],
a2[7],
a2[8],
a2[9]);
v5 = a2[8];
if ( v5 == 49 )
{
syslog(
7,
"CommandSensorMultilevelReport: node=%i, inst=%i, type=%i, valuem=%i, value=%i",
a2[3],
a2[7],
a2[10],
a2[11],
a2[12]);
result = 0LL;
}
else
{
result = 0LL;
if ( v5 == 32 )
{
v6 = a2[9];
if ( v6 == 3 )
{
syslog(7, "Got basic report from node %i, instance %i, value: %i", a2[3], a2[7], a2[10]);
result = 0LL;
}
else
{
result = 0LL;
if ( v6 == 1 )
{
syslog(7, "Got basic set from node %i, instance %i, value: %i", a2[3], a2[7], a2[10]);
result = 0LL;
}
}
}
}
}
}
break;
case 0x86:
syslog(7, "\nCOMMAND_CLASS_VERSION");
result = 0LL;
if ( a2[6] == 18 )
{
syslog(
7,
"REPORT: Lib.typ: 0x%x, Prot.Ver: 0x%x, Sub: 0x%x App.Ver: 0x%x, Sub: 0x%x",
a2[7],
a2[8],
a2[9],
a2[10],
a2[11]);
result = 0LL;
}
break;
case 0x21u:
syslog(7, "COMMAND_CLASS_CONTROLLER_REPLICATION");
v7[0] = 68;
((void (__fastcall *)(__int64, char *, __int64, _QWORD, _QWORD, _QWORD))zw_send_request)(
a1,
v7,
1LL,
0LL,
0LL,
0LL);
result = 0LL;
break;
default:
syslog(7, "Function not implemented - unhandled command class: %x", v2);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
int
cc_process_generic_msg( zw_api_ctx_S *ctx, const u8* frame )
{
 u8 tempbuf[512];
 int rc = -1;
 switch ((unsigned char)frame[5]) {
  case 0x21:
   syslog( 7, "COMMAND_CLASS_CONTROLLER_REPLICATION" );;
   if (frame[6] == 0x31) {
    tempbuf[0]=0x44;
    zw_send_request( ctx, tempbuf , 1, 0, 0, 0 );
   } else {
    tempbuf[0]=0x44;
    zw_send_request( ctx, tempbuf , 1, 0, 0, 0 );
   }
   rc = 0;
   break;
  case 0x60:
   syslog( 7, "COMMAND_CLASS_MULTI_INSTANCE" );;
   if (frame[6] == 0x05) {
    int instanceCount = (unsigned char)frame[8];
    syslog( 7, "Got MULTI_INSTANCE_REPORT from node %i: Command Class 0x%x, instance count: %i",(unsigned char)frame[3],(unsigned char)frame[7], instanceCount );;
   } else if (frame[6] == 0x6) {
    syslog( 7, "Got MULTI_INSTANCE_CMD_ENCAP from node %i: instance %i Command Class 0x%x type 0x%x",(unsigned char)frame[3],(unsigned char)frame[7],(unsigned char)frame[8],(unsigned char)frame[9] );;
    if (frame[8] == 0x31) {
     syslog( 7, "CommandSensorMultilevelReport: node=%i, inst=%i, type=%i, valuem=%i, value=%i", frame[3], frame[7], frame[10], frame[11], frame[12] );;
    } else if ((frame[8] == 0x20) && (frame[9] == 0x03)) {
     syslog( 7, "Got basic report from node %i, instance %i, value: %i",(unsigned char)frame[3],(unsigned char)frame[7], (unsigned char) frame[10] );;
    } else if ((frame[8] == 0x20) && (frame[9] == 0x01)) {
     syslog( 7, "Got basic set from node %i, instance %i, value: %i",(unsigned char)frame[3],(unsigned char)frame[7], (unsigned char) frame[10] );;
    }
   }
   rc = 0;
   break;
  case 0x86:
   syslog( 7, "\nCOMMAND_CLASS_VERSION" );;
   if (frame[6] == 0x12) {
    syslog( 7, "REPORT: Lib.typ: 0x%x, Prot.Ver: 0x%x, Sub: 0x%x App.Ver: 0x%x, Sub: 0x%x", (unsigned char)frame[7], (unsigned char)frame[8], (unsigned char)frame[9], (unsigned char)frame[10], (unsigned char)frame[11] );;
   }
   rc = 0;
   break;
  default:
   syslog( 7, "Function not implemented - unhandled command class: %x",(unsigned char)frame[5] );;
   break;
  ;;
 }
 return rc;
}

canonical_original_code:
int cc_process_generic_msg(struct zw_api_ctx *ctx, unsigned char *frame)
{
 unsigned char tempbuf[512];
 int rc = -1;
 switch ((unsigned char)frame[5]) {
  case 0x21:
   syslog( 7, "COMMAND_CLASS_CONTROLLER_REPLICATION" );;
   if (frame[6] == 0x31) {
    tempbuf[0]=0x44;
    zw_send_request( ctx, tempbuf , 1, 0, 0, 0 );
   } else {
    tempbuf[0]=0x44;
    zw_send_request( ctx, tempbuf , 1, 0, 0, 0 );
   }
   rc = 0;
   break;
  case 0x60:
   syslog( 7, "COMMAND_CLASS_MULTI_INSTANCE" );;
   if (frame[6] == 0x05) {
    int instanceCount = (unsigned char)frame[8];
    syslog( 7, "Got MULTI_INSTANCE_REPORT from node %i: Command Class 0x%x, instance count: %i",(unsigned char)frame[3],(unsigned char)frame[7], instanceCount );;
   } else if (frame[6] == 0x6) {
    syslog( 7, "Got MULTI_INSTANCE_CMD_ENCAP from node %i: instance %i Command Class 0x%x type 0x%x",(unsigned char)frame[3],(unsigned char)frame[7],(unsigned char)frame[8],(unsigned char)frame[9] );;
    if (frame[8] == 0x31) {
     syslog( 7, "CommandSensorMultilevelReport: node=%i, inst=%i, type=%i, valuem=%i, value=%i", frame[3], frame[7], frame[10], frame[11], frame[12] );;
    } else if ((frame[8] == 0x20) && (frame[9] == 0x03)) {
     syslog( 7, "Got basic report from node %i, instance %i, value: %i",(unsigned char)frame[3],(unsigned char)frame[7], (unsigned char) frame[10] );;
    } else if ((frame[8] == 0x20) && (frame[9] == 0x01)) {
     syslog( 7, "Got basic set from node %i, instance %i, value: %i",(unsigned char)frame[3],(unsigned char)frame[7], (unsigned char) frame[10] );;
    }
   }
   rc = 0;
   break;
  case 0x86:
   syslog( 7, "\nCOMMAND_CLASS_VERSION" );;
   if (frame[6] == 0x12) {
    syslog( 7, "REPORT: Lib.typ: 0x%x, Prot.Ver: 0x%x, Sub: 0x%x App.Ver: 0x%x, Sub: 0x%x", (unsigned char)frame[7], (unsigned char)frame[8], (unsigned char)frame[9], (unsigned char)frame[10], (unsigned char)frame[11] );;
   }
   rc = 0;
   break;
  default:
   syslog( 7, "Function not implemented - unhandled command class: %x",(unsigned char)frame[5] );;
   break;
  ;;
 }
 return rc;
}

variable_types:
tempbuf
unsigned char [512]

variable_types: rc int

variable_types: instanceCount int


repo: pmnair/zwave-remote

decompiled_code:
__int64 __fastcall cc_process_unimplemented_msg(unsigned __int8 *a1)
{
unsigned __int8 v1; // dl
unsigned __int8 v3; // al

v1 = a1[5];
if ( v1 <= 0x46u )
{
if ( v1 > 0x1Fu )
{
switch ( v1 )
{
case ' ':
syslog(7, "\nCOMMAND_CLASS_BASIC - ");
break;
case '&':
syslog(7, "\nCOMMAND_CLASS_SWITCH_MULTILEVEL - ");
v3 = a1[6];
if ( v3 == 3 )
{
syslog(7, "Got switch multilevel report from node %i, level: %i", a1[3], a1[7]);
syslog(7, "Send light changed event");
}
else if ( v3 == 1 )
{
syslog(7, "Got switch multilevel set from node %i, level: %i", a1[3], a1[7]);
syslog(7, "Send light changed event");
}
break;
case '\'':
syslog(7, "\nCOMMAND_CLASS_SWITCH_ALL - ");
if ( a1[6] == 4 )
{
syslog(7, "Got switch all ON from node %i", a1[3]);
syslog(7, "Send light changed event");
}
if ( a1[6] == 5 )
{
syslog(7, "Got switch all OFF from node %i", a1[3]);
syslog(7, "Send light changed event");
}
break;
case '1':
syslog(7, "\nCOMMAND_CLASS_SENSOR_MULTILEVEL - ");
break;
case '2':
syslog(7, "\nCOMMAND_CLASS_METER");
break;
case '@':
syslog(7, "COMMAND_CLASS_THERMOSTAT_MODE - ");
break;
case 'C':
syslog(7, "COMMAND_CLASS_THERMOSTAT_SETPOINT - ");
break;
case 'F':
syslog(7, "\nCOMMAND_CLASS_CLIMATE_CONTROL_SCHEDULE: - ");
if ( a1[6] == 2 )
syslog(7, "Got SCHEDULE_GET from node %i for day: %i", a1[3], a1[7]);
break;
default:
goto LABEL_30;
}
return 0LL;
}
LABEL_30:
syslog(4, "Function not implemented - unhandled command class: %x", v1);
return 0LL;
}
if ( (unsigned __int8)(v1 - 113) > 0x2Bu )
goto LABEL_30;
switch ( v1 )
{
case 0x71u:
syslog(7, "\nCOMMAND_CLASS_ALARM - ");
if ( a1[6] == 5 )
{
syslog(7, "Got ALARM from node %i, type: %i, level: %i", a1[3], a1[7], a1[8]);
syslog(7, "Send sensor tripped changed event");
}
break;
case 0x72u:
syslog(7, "\nCOMMAND_CLASS_MANUFACTURER_SPECIFIC");
break;
case 0x81u:
syslog(7, "COMMAND_CLASS_CLOCK - ");
break;
case 0x84u:
syslog(7, "\nCOMMAND_CLASS_WAKE_UP - ");
break;
case 0x85u:
syslog(7, "\nCOMMAND_CLASS_ASSOCIATION - ");
break;
case 0x8Fu:
syslog(7, "COMMAND_CLASS_MULTI_CMD - ");
break;
case 0x9Cu:
syslog(7, "\nCOMMAND_CLASS_SENSOR_ALARM - ");
break;
default:
goto LABEL_30;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1)
{
unsigned __int8 v1; // dl
unsigned __int8 v3; // al

v1 = a1[5];
if ( v1 <= 0x46u )
{
if ( v1 > 0x1Fu )
{
switch ( v1 )
{
case ' ':
syslog(7, "\nCOMMAND_CLASS_BASIC - ");
break;
case '&':
syslog(7, "\nCOMMAND_CLASS_SWITCH_MULTILEVEL - ");
v3 = a1[6];
if ( v3 == 3 )
{
syslog(7, "Got switch multilevel report from node %i, level: %i", a1[3], a1[7]);
syslog(7, "Send light changed event");
}
else if ( v3 == 1 )
{
syslog(7, "Got switch multilevel set from node %i, level: %i", a1[3], a1[7]);
syslog(7, "Send light changed event");
}
break;
case '\'':
syslog(7, "\nCOMMAND_CLASS_SWITCH_ALL - ");
if ( a1[6] == 4 )
{
syslog(7, "Got switch all ON from node %i", a1[3]);
syslog(7, "Send light changed event");
}
if ( a1[6] == 5 )
{
syslog(7, "Got switch all OFF from node %i", a1[3]);
syslog(7, "Send light changed event");
}
break;
case '1':
syslog(7, "\nCOMMAND_CLASS_SENSOR_MULTILEVEL - ");
break;
case '2':
syslog(7, "\nCOMMAND_CLASS_METER");
break;
case '@':
syslog(7, "COMMAND_CLASS_THERMOSTAT_MODE - ");
break;
case 'C':
syslog(7, "COMMAND_CLASS_THERMOSTAT_SETPOINT - ");
break;
case 'F':
syslog(7, "\nCOMMAND_CLASS_CLIMATE_CONTROL_SCHEDULE: - ");
if ( a1[6] == 2 )
syslog(7, "Got SCHEDULE_GET from node %i for day: %i", a1[3], a1[7]);
break;
default:
goto LABEL_30;
}
return 0LL;
}
LABEL_30:
syslog(4, "Function not implemented - unhandled command class: %x", v1);
return 0LL;
}
if ( (unsigned __int8)(v1 - 113) > 0x2Bu )
goto LABEL_30;
switch ( v1 )
{
case 0x71u:
syslog(7, "\nCOMMAND_CLASS_ALARM - ");
if ( a1[6] == 5 )
{
syslog(7, "Got ALARM from node %i, type: %i, level: %i", a1[3], a1[7], a1[8]);
syslog(7, "Send sensor tripped changed event");
}
break;
case 0x72u:
syslog(7, "\nCOMMAND_CLASS_MANUFACTURER_SPECIFIC");
break;
case 0x81u:
syslog(7, "COMMAND_CLASS_CLOCK - ");
break;
case 0x84u:
syslog(7, "\nCOMMAND_CLASS_WAKE_UP - ");
break;
case 0x85u:
syslog(7, "\nCOMMAND_CLASS_ASSOCIATION - ");
break;
case 0x8Fu:
syslog(7, "COMMAND_CLASS_MULTI_CMD - ");
break;
case 0x9Cu:
syslog(7, "\nCOMMAND_CLASS_SENSOR_ALARM - ");
break;
default:
goto LABEL_30;
}
return 0LL;
}

original_code:
int
cc_process_unimplemented_msg( const u8 *frame )
{
 switch ((unsigned char)frame[5]) {
  case 0x32:
   syslog( 7, "\nCOMMAND_CLASS_METER" );;
   break;
  case 0x72:
   syslog( 7, "\nCOMMAND_CLASS_MANUFACTURER_SPECIFIC" );;
   break;
  case 0x84:
   syslog( 7, "\nCOMMAND_CLASS_WAKE_UP - " );;
   break;
  case 0x31:
   syslog( 7, "\nCOMMAND_CLASS_SENSOR_MULTILEVEL - " );;
   break;
  case 0x9c:
   syslog( 7, "\nCOMMAND_CLASS_SENSOR_ALARM - " );;
   break;
  case 0x26:
   syslog( 7, "\nCOMMAND_CLASS_SWITCH_MULTILEVEL - " );;
   if (frame[6] == 0x03) {
    syslog( 7, "Got switch multilevel report from node %i, level: %i",(unsigned char)frame[3],(unsigned char)frame[7] );;
    syslog( 7, "Send light changed event" );;
   } else if ((unsigned char)frame[6] == 0x01) {
    syslog( 7, "Got switch multilevel set from node %i, level: %i",(unsigned char)frame[3],(unsigned char)frame[7] );;
    syslog( 7, "Send light changed event" );;
   }
   break;
  case 0x27:
   syslog( 7, "\nCOMMAND_CLASS_SWITCH_ALL - " );;
   if (frame[6] == 0x04) {
    syslog( 7, "Got switch all ON from node %i",(unsigned char)frame[3] );;
    syslog( 7, "Send light changed event" );;
   }
   if (frame[6] == 0x05) {
    syslog( 7, "Got switch all OFF from node %i",(unsigned char)frame[3] );;
    syslog( 7, "Send light changed event" );;
   }
   break;
  case 0x71:
   syslog( 7, "\nCOMMAND_CLASS_ALARM - " );;
   if (frame[6] == 0x05) {
    syslog( 7, "Got ALARM from node %i, type: %i, level: %i",(unsigned char)frame[3],(unsigned char)frame[7],(unsigned char)frame[8] );;
    syslog( 7, "Send sensor tripped changed event" );;
   }
   break;
  case 0x20:
   syslog( 7, "\nCOMMAND_CLASS_BASIC - " );;
   break;
  case 0x46:
   syslog( 7, "\nCOMMAND_CLASS_CLIMATE_CONTROL_SCHEDULE: - " );;
   if (frame[6] == 0x02) {
    syslog( 7, "Got SCHEDULE_GET from node %i for day: %i",frame[3],frame[7] );;
   }
   break;
  case 0x85:
   syslog( 7, "\nCOMMAND_CLASS_ASSOCIATION - " );;
   break;
  case 0x43:
   syslog( 7, "COMMAND_CLASS_THERMOSTAT_SETPOINT - " );;
   break;
  case 0x81:
   syslog( 7, "COMMAND_CLASS_CLOCK - " );;
   break;
   ;;
  case 0x40:
   syslog( 7, "COMMAND_CLASS_THERMOSTAT_MODE - " );;
   break;
   ;;
  case 0x8F:
   syslog( 7, "COMMAND_CLASS_MULTI_CMD - " );;
   break;
  default:
   syslog( 4, "Function not implemented - unhandled command class: %x",(unsigned char)frame[5] );;
   break;
  ;;
 }
 return 0;
}

canonical_original_code:
int cc_process_unimplemented_msg(unsigned char *frame)
{
 switch ((unsigned char)frame[5]) {
  case 0x32:
   syslog( 7, "\nCOMMAND_CLASS_METER" );;
   break;
  case 0x72:
   syslog( 7, "\nCOMMAND_CLASS_MANUFACTURER_SPECIFIC" );;
   break;
  case 0x84:
   syslog( 7, "\nCOMMAND_CLASS_WAKE_UP - " );;
   break;
  case 0x31:
   syslog( 7, "\nCOMMAND_CLASS_SENSOR_MULTILEVEL - " );;
   break;
  case 0x9c:
   syslog( 7, "\nCOMMAND_CLASS_SENSOR_ALARM - " );;
   break;
  case 0x26:
   syslog( 7, "\nCOMMAND_CLASS_SWITCH_MULTILEVEL - " );;
   if (frame[6] == 0x03) {
    syslog( 7, "Got switch multilevel report from node %i, level: %i",(unsigned char)frame[3],(unsigned char)frame[7] );;
    syslog( 7, "Send light changed event" );;
   } else if ((unsigned char)frame[6] == 0x01) {
    syslog( 7, "Got switch multilevel set from node %i, level: %i",(unsigned char)frame[3],(unsigned char)frame[7] );;
    syslog( 7, "Send light changed event" );;
   }
   break;
  case 0x27:
   syslog( 7, "\nCOMMAND_CLASS_SWITCH_ALL - " );;
   if (frame[6] == 0x04) {
    syslog( 7, "Got switch all ON from node %i",(unsigned char)frame[3] );;
    syslog( 7, "Send light changed event" );;
   }
   if (frame[6] == 0x05) {
    syslog( 7, "Got switch all OFF from node %i",(unsigned char)frame[3] );;
    syslog( 7, "Send light changed event" );;
   }
   break;
  case 0x71:
   syslog( 7, "\nCOMMAND_CLASS_ALARM - " );;
   if (frame[6] == 0x05) {
    syslog( 7, "Got ALARM from node %i, type: %i, level: %i",(unsigned char)frame[3],(unsigned char)frame[7],(unsigned char)frame[8] );;
    syslog( 7, "Send sensor tripped changed event" );;
   }
   break;
  case 0x20:
   syslog( 7, "\nCOMMAND_CLASS_BASIC - " );;
   break;
  case 0x46:
   syslog( 7, "\nCOMMAND_CLASS_CLIMATE_CONTROL_SCHEDULE: - " );;
   if (frame[6] == 0x02) {
    syslog( 7, "Got SCHEDULE_GET from node %i for day: %i",frame[3],frame[7] );;
   }
   break;
  case 0x85:
   syslog( 7, "\nCOMMAND_CLASS_ASSOCIATION - " );;
   break;
  case 0x43:
   syslog( 7, "COMMAND_CLASS_THERMOSTAT_SETPOINT - " );;
   break;
  case 0x81:
   syslog( 7, "COMMAND_CLASS_CLOCK - " );;
   break;
   ;;
  case 0x40:
   syslog( 7, "COMMAND_CLASS_THERMOSTAT_MODE - " );;
   break;
   ;;
  case 0x8F:
   syslog( 7, "COMMAND_CLASS_MULTI_CMD - " );;
   break;
  default:
   syslog( 4, "Function not implemented - unhandled command class: %x",(unsigned char)frame[5] );;
   break;
  ;;
 }
 return 0;
}

variable_types:
frame
unsigned char *

return_type: int


decompiled_code:
__int64 __fastcall cc_process_msg(__int64 a1, unsigned __int8 *a2, unsigned __int8 a3)
{
unsigned __int8 v4; // dl
void **v5; // rax
__int64 result; // rax
__int64 (__fastcall *v7)(__int64, unsigned __int8 *, _QWORD); // r8

v4 = a2[5];
if ( v4 == 96 || v4 == 0x86 || v4 == 33 )
return cc_process_generic_msg(a1, a2);
v5 = (void **)cmd_classes;
if ( cmd_classes == &cmd_classes )
{
LABEL_7:
cc_process_unimplemented_msg(a2);
result = 0xFFFFFFFFLL;
}
else
{
while ( v4 != *((_BYTE *)v5 + 24) )
{
v5 = (void **)*v5;
if ( v5 == &cmd_classes )
goto LABEL_7;
}
v7 = (__int64 (__fastcall *)(__int64, unsigned __int8 *, _QWORD))v5[4];
if ( v7 )
{
result = v7(a1, a2, a3);
}
else
{
syslog(4, "CmdCLass: %s does not register process msg", (const char *)v5[2]);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int8 *a2, unsigned __int8 a3)
{
unsigned __int8 v4; // dl
void **v5; // rax
__int64 result; // rax
__int64 (__fastcall *v7)(__int64, unsigned __int8 *, _QWORD); // r8

v4 = a2[5];
if ( v4 == 96 || v4 == 0x86 || v4 == 33 )
return func2(a1, a2);
v5 = (void **)cmd_classes;
if ( cmd_classes == &cmd_classes )
{
LABEL_7:
func3(a2);
result = 0xFFFFFFFFLL;
}
else
{
while ( v4 != *((_BYTE *)v5 + 24) )
{
v5 = (void **)*v5;
if ( v5 == &cmd_classes )
goto LABEL_7;
}
v7 = (__int64 (__fastcall *)(__int64, unsigned __int8 *, _QWORD))v5[4];
if ( v7 )
{
result = v7(a1, a2, a3);
}
else
{
syslog(4, "CmdCLass: %s does not register process msg", (const char *)v5[2]);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int
cc_process_msg( zw_api_ctx_S *ctx, const u8* frame, u8 nodeid )
{
 list_node *node = ((void *)0);
 struct cmd_class *cmd_cls = ((void *)0);
 int rc = -1;
 int cls_found = 0;
 switch ( frame[ 5 ] ) {
  case 0x21:
  case 0x60:
  case 0x86:
   rc = cc_process_generic_msg( ctx, frame );
   goto out;
  default:
   break;
 }
 for(node = (&cmd_classes)->next; node != (&cmd_classes); node = node->next) {
  cmd_cls = (struct cmd_class *)node;
  if ( cmd_cls->type == frame[ 5 ] ) {
   if ( cmd_cls->process_msg )
    rc = cmd_cls->process_msg( ctx, frame, nodeid );
   else
    syslog( 4, "CmdCLass: %s does not register process msg", cmd_cls->name );;
   cls_found = 1;
   break;
  }
 }
 if( !cls_found ) cc_process_unimplemented_msg( frame );
out:
 return rc;
}

canonical_original_code:
int cc_process_msg(struct zw_api_ctx *ctx, unsigned char *frame, unsigned char nodeid)
{
 struct _node *node = ((void *)0);
 struct cmd_class *cmd_cls = ((void *)0);
 int rc = -1;
 int cls_found = 0;
 switch ( frame[ 5 ] ) {
  case 0x21:
  case 0x60:
  case 0x86:
   rc = cc_process_generic_msg( ctx, frame );
   goto out;
  default:
   break;
 }
 for(node = (&cmd_classes)->next; node != (&cmd_classes); node = node->next) {
  cmd_cls = (struct cmd_class *)node;
  if ( cmd_cls->type == frame[ 5 ] ) {
   if ( cmd_cls->process_msg )
    rc = cmd_cls->process_msg( ctx, frame, nodeid );
   else
    syslog( 4, "CmdCLass: %s does not register process msg", cmd_cls->name );;
   cls_found = 1;
   break;
  }
 }
 if( !cls_found ) cc_process_unimplemented_msg( frame );
out:
 return rc;
}

variable_types:
nodeid
unsigned char

variable_types: struct _node { struct _node *next; struct _node *prev; } *

variable_types: struct cmd_class { struct _node { struct _node *next; struct _node *prev; } list; char *name; unsigned char type; int (*process_msg)(struct zw_api_ctx { int port; int node_id; } *ctx, unsigned char *frame, unsigned char nodeid); int (*version)(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp); int (*get)(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp); int (*set)(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp); int (*report)(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp); } *

user_defined_types: struct cmd_class { struct _node list; char *name; unsigned char type; int (*process_msg)(struct zw_api_ctx *ctx, unsigned char *frame, unsigned char nodeid); int (*version)(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp); int (*get)(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp); int (*set)(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp); int (*report)(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp); }


decompiled_code:
__int64 __fastcall cc_version(__int64 a1, unsigned __int8 a2, char a3, __int64 a4)
{
void **v4; // rax
__int64 (__fastcall *v6)(__int64, _QWORD, __int64); // r8

v4 = (void **)cmd_classes;
if ( cmd_classes == &cmd_classes )
return 0xFFFFFFFFLL;
while ( *((_BYTE *)v4 + 24) != a3 )
{
v4 = (void **)*v4;
if ( v4 == &cmd_classes )
return 0xFFFFFFFFLL;
}
v6 = (__int64 (__fastcall *)(__int64, _QWORD, __int64))v4[5];
if ( v6 )
return v6(a1, a2, a4);
syslog(4, "CmdCLass: %s does not register version", (const char *)v4[2]);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int8 a2, char a3, __int64 a4)
{
void **v4; // rax
__int64 (__fastcall *v6)(__int64, _QWORD, __int64); // r8

v4 = (void **)cmd_classes;
if ( cmd_classes == &cmd_classes )
return 0xFFFFFFFFLL;
while ( *((_BYTE *)v4 + 24) != a3 )
{
v4 = (void **)*v4;
if ( v4 == &cmd_classes )
return 0xFFFFFFFFLL;
}
v6 = (__int64 (__fastcall *)(__int64, _QWORD, __int64))v4[5];
if ( v6 )
return v6(a1, a2, a4);
syslog(4, "CmdCLass: %s does not register version", (const char *)v4[2]);
return 0xFFFFFFFFLL;
}

original_code:
int
cc_version( zw_api_ctx_S *ctx, u8 nodeid, const u8 cls_type, void *resp )
{
 list_node *node = ((void *)0);
 struct cmd_class *cmd_cls = ((void *)0);
 int rc = -1;
 for(node = (&cmd_classes)->next; node != (&cmd_classes); node = node->next) {
  cmd_cls = (struct cmd_class *)node;
  if ( cmd_cls->type == cls_type ) {
   if ( cmd_cls->version )
    rc = cmd_cls->version( ctx, nodeid, resp );
   else
    syslog( 4, "CmdCLass: %s does not register version", cmd_cls->name );;
   break;
  }
 }
 return rc;
}

canonical_original_code:
int cc_version(struct zw_api_ctx *ctx, unsigned char nodeid, unsigned char cls_type, void *resp)
{
 struct _node *node = ((void *)0);
 struct cmd_class *cmd_cls = ((void *)0);
 int rc = -1;
 for(node = (&cmd_classes)->next; node != (&cmd_classes); node = node->next) {
  cmd_cls = (struct cmd_class *)node;
  if ( cmd_cls->type == cls_type ) {
   if ( cmd_cls->version )
    rc = cmd_cls->version( ctx, nodeid, resp );
   else
    syslog( 4, "CmdCLass: %s does not register version", cmd_cls->name );;
   break;
  }
 }
 return rc;
}

variable_types: struct zw_api_ctx { int port; int node_id; } *

variable_types:
resp
void *

user_defined_types: struct _node { struct _node *next; struct _node *prev; }


decompiled_code:
__int64 __fastcall cc_get(__int64 a1, unsigned __int8 a2, char a3, __int64 a4)
{
void **v4; // rax
__int64 (__fastcall *v6)(__int64, _QWORD, __int64); // r8

v4 = (void **)cmd_classes;
if ( cmd_classes == &cmd_classes )
return 0xFFFFFFFFLL;
while ( *((_BYTE *)v4 + 24) != a3 )
{
v4 = (void **)*v4;
if ( v4 == &cmd_classes )
return 0xFFFFFFFFLL;
}
v6 = (__int64 (__fastcall *)(__int64, _QWORD, __int64))v4[6];
if ( v6 )
return v6(a1, a2, a4);
syslog(4, "CmdCLass: %s does not register get", (const char *)v4[2]);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int8 a2, char a3, __int64 a4)
{
void **v4; // rax
__int64 (__fastcall *v6)(__int64, _QWORD, __int64); // r8

v4 = (void **)cmd_classes;
if ( cmd_classes == &cmd_classes )
return 0xFFFFFFFFLL;
while ( *((_BYTE *)v4 + 24) != a3 )
{
v4 = (void **)*v4;
if ( v4 == &cmd_classes )
return 0xFFFFFFFFLL;
}
v6 = (__int64 (__fastcall *)(__int64, _QWORD, __int64))v4[6];
if ( v6 )
return v6(a1, a2, a4);
syslog(4, "CmdCLass: %s does not register get", (const char *)v4[2]);
return 0xFFFFFFFFLL;
}

original_code:
int
cc_get( zw_api_ctx_S *ctx, u8 nodeid, const u8 cls_type, void *resp )
{
 list_node *node = ((void *)0);
 struct cmd_class *cmd_cls = ((void *)0);
 int rc = -1;
 for(node = (&cmd_classes)->next; node != (&cmd_classes); node = node->next) {
  cmd_cls = (struct cmd_class *)node;
  if ( cmd_cls->type == cls_type ) {
   if ( cmd_cls->get )
    rc = cmd_cls->get( ctx, nodeid, resp );
   else
    syslog( 4, "CmdCLass: %s does not register get", cmd_cls->name );;
   break;
  }
 }
 return rc;
}

canonical_original_code:
int cc_get(struct zw_api_ctx *ctx, unsigned char nodeid, unsigned char cls_type, void *resp)
{
 struct _node *node = ((void *)0);
 struct cmd_class *cmd_cls = ((void *)0);
 int rc = -1;
 for(node = (&cmd_classes)->next; node != (&cmd_classes); node = node->next) {
  cmd_cls = (struct cmd_class *)node;
  if ( cmd_cls->type == cls_type ) {
   if ( cmd_cls->get )
    rc = cmd_cls->get( ctx, nodeid, resp );
   else
    syslog( 4, "CmdCLass: %s does not register get", cmd_cls->name );;
   break;
  }
 }
 return rc;
}

user_defined_types: struct zw_api_ctx { int port; int node_id; }


decompiled_code:
__int64 __fastcall cc_set(__int64 a1, unsigned __int8 a2, char a3, __int64 a4)
{
void **v4; // rax
__int64 (__fastcall *v6)(__int64, _QWORD, __int64); // r8

v4 = (void **)cmd_classes;
if ( cmd_classes == &cmd_classes )
return 0xFFFFFFFFLL;
while ( *((_BYTE *)v4 + 24) != a3 )
{
v4 = (void **)*v4;
if ( v4 == &cmd_classes )
return 0xFFFFFFFFLL;
}
v6 = (__int64 (__fastcall *)(__int64, _QWORD, __int64))v4[7];
if ( v6 )
return v6(a1, a2, a4);
syslog(4, "CmdCLass: %s does not register set", (const char *)v4[2]);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int8 a2, char a3, __int64 a4)
{
void **v4; // rax
__int64 (__fastcall *v6)(__int64, _QWORD, __int64); // r8

v4 = (void **)cmd_classes;
if ( cmd_classes == &cmd_classes )
return 0xFFFFFFFFLL;
while ( *((_BYTE *)v4 + 24) != a3 )
{
v4 = (void **)*v4;
if ( v4 == &cmd_classes )
return 0xFFFFFFFFLL;
}
v6 = (__int64 (__fastcall *)(__int64, _QWORD, __int64))v4[7];
if ( v6 )
return v6(a1, a2, a4);
syslog(4, "CmdCLass: %s does not register set", (const char *)v4[2]);
return 0xFFFFFFFFLL;
}

original_code:
int
cc_set( zw_api_ctx_S *ctx, u8 nodeid, const u8 cls_type, void *val )
{
 list_node *node = ((void *)0);
 struct cmd_class *cmd_cls = ((void *)0);
 int rc = -1;
 for(node = (&cmd_classes)->next; node != (&cmd_classes); node = node->next) {
  cmd_cls = (struct cmd_class *)node;
  if ( cmd_cls->type == cls_type ) {
   if ( cmd_cls->set )
    rc = cmd_cls->set( ctx, nodeid, val );
   else
    syslog( 4, "CmdCLass: %s does not register set", cmd_cls->name );;
   break;
  }
 }
 return rc;
}

canonical_original_code:
int cc_set(struct zw_api_ctx *ctx, unsigned char nodeid, unsigned char cls_type, void *val)
{
 struct _node *node = ((void *)0);
 struct cmd_class *cmd_cls = ((void *)0);
 int rc = -1;
 for(node = (&cmd_classes)->next; node != (&cmd_classes); node = node->next) {
  cmd_cls = (struct cmd_class *)node;
  if ( cmd_cls->type == cls_type ) {
   if ( cmd_cls->set )
    rc = cmd_cls->set( ctx, nodeid, val );
   else
    syslog( 4, "CmdCLass: %s does not register set", cmd_cls->name );;
   break;
  }
 }
 return rc;
}

variable_types:
val
void *


decompiled_code:
__int64 __fastcall cc_report(__int64 a1, unsigned __int8 a2, char a3, __int64 a4)
{
void **v4; // rax
__int64 (__fastcall *v6)(__int64, _QWORD, __int64); // r8

v4 = (void **)cmd_classes;
if ( cmd_classes == &cmd_classes )
return 0xFFFFFFFFLL;
while ( *((_BYTE *)v4 + 24) != a3 )
{
v4 = (void **)*v4;
if ( v4 == &cmd_classes )
return 0xFFFFFFFFLL;
}
v6 = (__int64 (__fastcall *)(__int64, _QWORD, __int64))v4[8];
if ( v6 )
return v6(a1, a2, a4);
syslog(4, "CmdCLass: %s does not register report", (const char *)v4[2]);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned __int8 a2, char a3, __int64 a4)
{
void **v4; // rax
__int64 (__fastcall *v6)(__int64, _QWORD, __int64); // r8

v4 = (void **)cmd_classes;
if ( cmd_classes == &cmd_classes )
return 0xFFFFFFFFLL;
while ( *((_BYTE *)v4 + 24) != a3 )
{
v4 = (void **)*v4;
if ( v4 == &cmd_classes )
return 0xFFFFFFFFLL;
}
v6 = (__int64 (__fastcall *)(__int64, _QWORD, __int64))v4[8];
if ( v6 )
return v6(a1, a2, a4);
syslog(4, "CmdCLass: %s does not register report", (const char *)v4[2]);
return 0xFFFFFFFFLL;
}

original_code:
int
cc_report( zw_api_ctx_S *ctx, u8 nodeid, const u8 cls_type, void *resp )
{
 list_node *node = ((void *)0);
 struct cmd_class *cmd_cls = ((void *)0);
 int rc = -1;
 for(node = (&cmd_classes)->next; node != (&cmd_classes); node = node->next) {
  cmd_cls = (struct cmd_class *)node;
  if ( cmd_cls->type == cls_type ) {
   if ( cmd_cls->report )
    rc = cmd_cls->report( ctx, nodeid, resp );
   else
    syslog( 4, "CmdCLass: %s does not register report", cmd_cls->name );;
   break;
  }
 }
 return rc;
}

canonical_original_code:
int cc_report(struct zw_api_ctx *ctx, unsigned char nodeid, unsigned char cls_type, void *resp)
{
 struct _node *node = ((void *)0);
 struct cmd_class *cmd_cls = ((void *)0);
 int rc = -1;
 for(node = (&cmd_classes)->next; node != (&cmd_classes); node = node->next) {
  cmd_cls = (struct cmd_class *)node;
  if ( cmd_cls->type == cls_type ) {
   if ( cmd_cls->report )
    rc = cmd_cls->report( ctx, nodeid, resp );
   else
    syslog( 4, "CmdCLass: %s does not register report", cmd_cls->name );;
   break;
  }
 }
 return rc;
}


decompiled_code:
__int64 __fastcall register_cmd_class(_QWORD *a1)
{
list_add((__int64)&cmd_classes, a1);
print_cmd_classes();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
func0((__int64)&cmd_classes, a1);
func1();
return 1LL;
}

original_code:
int
register_cmd_class( struct cmd_class *ccls )
{
 int rc = 1;
 list_add((list_node *)&cmd_classes, (list_node *)ccls);
 print_cmd_classes();
 return rc;
}

canonical_original_code:
int register_cmd_class(struct cmd_class *ccls)
{
 int rc = 1;
 list_add((struct _node *)&cmd_classes, (struct _node *)ccls);
 print_cmd_classes();
 return rc;
}


decompiled_code:
__int64 __fastcall unregister_cmd_class(_QWORD *a1)
{
list_remove((_QWORD **)&cmd_classes, a1);
print_cmd_classes();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
list_remove((_QWORD **)&cmd_classes, a1);
func1();
return 1LL;
}

original_code:
int
unregister_cmd_class( struct cmd_class *ccls)
{
 int rc = 1;
 list_remove((list_node *)&cmd_classes, (list_node *)ccls);
 print_cmd_classes();
 return rc;
}

canonical_original_code:
int unregister_cmd_class(struct cmd_class *ccls)
{
 int rc = 1;
 list_remove((struct _node *)&cmd_classes, (struct _node *)ccls);
 print_cmd_classes();
 return rc;
}


original_code:
static int
batt_get( zw_api_ctx_S *ctx, u8 nodeid, void *resp )
{
 u8 buff[1024];
 int rc;
 buff[0] = 0x13;
 buff[1] = nodeid;
 buff[2] = 2;
 buff[3] = 0x80;
 buff[4] = 0x02;
 buff[5] = 0x01 | 0x04;
 buff[6] = 3;
 rc = zw_send_request( ctx, buff, 7, nodeid, 1, 0x13 );
 return rc;
}

canonical_original_code:
static int batt_get(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp)
{
 unsigned char buff[1024];
 int rc;
 buff[0] = 0x13;
 buff[1] = nodeid;
 buff[2] = 2;
 buff[3] = 0x80;
 buff[4] = 0x02;
 buff[5] = 0x01 | 0x04;
 buff[6] = 3;
 rc = zw_send_request( ctx, buff, 7, nodeid, 1, 0x13 );
 return rc;
}

variable_types:
buff
unsigned char [1024]


decompiled_code:
__int64 __fastcall batt_proc_msg(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned __int8 v5; // al
unsigned int v6; // ebx

syslog(7, "COMMAND_CLASS_BATTERY - processing message");
if ( *(_BYTE *)(a2 + 6) == 3 )
{
syslog(7, "BATTERY_REPORT: Battery level: %d", *(unsigned __int8 *)(a2 + 7));
v5 = *(_BYTE *)(a2 + 7);
v6 = v5;
if ( v5 == 0xFF )
syslog(7, "Battery low warning from node %d", a3);
if ( (unsigned int)zw_node_set_batt_level(a3, v6) )
syslog(7, "Setting node battery level failed");
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned __int8 v5; // al
unsigned int v6; // ebx

syslog(7, "COMMAND_CLASS_BATTERY - processing message");
if ( *(_BYTE *)(a2 + 6) == 3 )
{
syslog(7, "BATTERY_REPORT: Battery level: %d", *(unsigned __int8 *)(a2 + 7));
v5 = *(_BYTE *)(a2 + 7);
v6 = v5;
if ( v5 == 0xFF )
syslog(7, "Battery low warning from node %d", a3);
if ( (unsigned int)zw_node_set_batt_level(a3, v6) )
syslog(7, "Setting node battery level failed");
}
return 0LL;
}

original_code:
static int
batt_proc_msg( zw_api_ctx_S *ctx, const u8* frame, u8 nodeid )
{
 int val = -1;
 syslog( 7, "COMMAND_CLASS_BATTERY - processing message" );;
 if ((unsigned char)frame[6] == 0x03) {
  syslog( 7, "BATTERY_REPORT: Battery level: %d",(unsigned char)frame[7] );;
  val = frame[ 7 ];
  if ((unsigned char)frame[7] == 0xff) {
   syslog( 7, "Battery low warning from node %d", nodeid );;
  }
  if ( 0 != zw_node_set_batt_level( nodeid, val ) )
   syslog( 7, "Setting node battery level failed" );;
 }
 return 0;
}

canonical_original_code:
static int batt_proc_msg(struct zw_api_ctx *ctx, unsigned char *frame, unsigned char nodeid)
{
 int val = -1;
 syslog( 7, "COMMAND_CLASS_BATTERY - processing message" );;
 if ((unsigned char)frame[6] == 0x03) {
  syslog( 7, "BATTERY_REPORT: Battery level: %d",(unsigned char)frame[7] );;
  val = frame[ 7 ];
  if ((unsigned char)frame[7] == 0xff) {
   syslog( 7, "Battery low warning from node %d", nodeid );;
  }
  if ( 0 != zw_node_set_batt_level( nodeid, val ) )
   syslog( 7, "Setting node battery level failed" );;
 }
 return 0;
}

variable_types: val int


decompiled_code:
__int64 batt_init()
{
return register_cmd_class(&batt);
}

canonical_decompiled_code:
__int64 func2()
{
return register_cmd_class(&batt);
}

original_code:
static void __attribute__ ((constructor)) batt_init( void )
{
 register_cmd_class( &batt );
}

canonical_original_code:
static void batt_init()
{
 register_cmd_class( &batt );
}

return_type: void


decompiled_code:
__int64 batt_exit()
{
return unregister_cmd_class(&batt);
}

canonical_decompiled_code:
__int64 func3()
{
return unregister_cmd_class(&batt);
}

original_code:
static void __attribute__ ((destructor)) batt_exit( void )
{
 unregister_cmd_class( &batt );
}

canonical_original_code:
static void batt_exit()
{
 unregister_cmd_class( &batt );
}


callback

original_code:
static int callback( void *udata, int argc, char **argv, char **col )
{
        int i;
 db_row_S *rows = (db_row_S *)udata;
 int len = 0;
 int rowidx = rows->nrows;
 rows->row = realloc( rows->row, (++rows->nrows * sizeof(char *)) );
 if ( rows->row == ((void *)0) ) {
  perror( "rows" );
  return 1;
 }
        for(i=0; i<argc; i++){
  len += strlen( col[i] ) + (argv[i] ? strlen(argv[i]) : strlen("NULL")) + 2;
                printf("%s = %s\n", col[i], argv[i] ? argv[i] : "NULL");
        }
 len++;
 rows->row[ rowidx ] = calloc( len, sizeof( char ));
 if ( rows->row[ rowidx ] == ((void *)0) ) {
  perror( "row" );
  return 1;
 }
        for(i=0; i<argc; i++){
  int slen = strlen( rows->row[ rowidx ] );
  snprintf( rows->row[ rowidx ] + slen, len - slen, "%s=%s|", col[i], argv[i] ? argv[i] : "NULL");
                printf("%s = %s\n", col[i], argv[i] ? argv[i] : "NULL");
        }
        printf("\n");
        return 0;
}

canonical_original_code:
static int callback(void *udata, int argc, char **argv, char **col)
{
        int i;
 struct _db_row *rows = (db_row_S *)udata;
 int len = 0;
 int rowidx = rows->nrows;
 rows->row = realloc( rows->row, (++rows->nrows * sizeof(char *)) );
 if ( rows->row == ((void *)0) ) {
  perror( "rows" );
  return 1;
 }
        for(i=0; i<argc; i++){
  len += strlen( col[i] ) + (argv[i] ? strlen(argv[i]) : strlen("NULL")) + 2;
                printf("%s = %s\n", col[i], argv[i] ? argv[i] : "NULL");
        }
 len++;
 rows->row[ rowidx ] = calloc( len, sizeof( char ));
 if ( rows->row[ rowidx ] == ((void *)0) ) {
  perror( "row" );
  return 1;
 }
        for(i=0; i<argc; i++){
  int slen = strlen( rows->row[ rowidx ] );
  snprintf( rows->row[ rowidx ] + slen, len - slen, "%s=%s|", col[i], argv[i] ? argv[i] : "NULL");
                printf("%s = %s\n", col[i], argv[i] ? argv[i] : "NULL");
        }
        printf("\n");
        return 0;
}

variable_types:
udata
void *

variable_types: argc int

variable_types:
argv
char **

variable_types:
col
char **

variable_types: i int

variable_types: struct _db_row { char **row; int nrows; } *

variable_types: len int

variable_types: rowidx int

variable_types: slen int


decompiled_code:
__int64 __fastcall db_exec(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
const char *v4; // [rsp+8h] [rbp-10h] BYREF

v4 = 0LL;
v2 = sqlite3_exec(pHzrDb, a1, callback, a2, &v4);
if ( v2 )
{
syslog(2, "SQL error: %sn", v4);
sqlite3_free(v4);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
const char *v4; // [rsp+8h] [rbp-10h] BYREF

v4 = 0LL;
v2 = sqlite3_exec(pHzrDb, a1, callback, a2, &v4);
if ( v2 )
{
syslog(2, "SQL error: %sn", v4);
sqlite3_free(v4);
}
return v2;
}

original_code:
int db_exec( const char *query, db_row_S *result )
{
 char *err = 0;
 int rc;
 rc = sqlite3_exec( pHzrDb, query, callback, result, &err );
 if( 0 != rc ){
  syslog( 2, "SQL error: %sn", err );;
  sqlite3_free( err );
 }
 return rc;
}

canonical_original_code:
int db_exec(char *query, struct _db_row *result)
{
 char *err = 0;
 int rc;
 rc = sqlite3_exec( pHzrDb, query, callback, result, &err );
 if( 0 != rc ){
  syslog( 2, "SQL error: %sn", err );;
  sqlite3_free( err );
 }
 return rc;
}

variable_types:
query
char *

variable_types:
err
char *

variable_types: rc int

user_defined_types: struct _db_row { char **row; int nrows; }


decompiled_code:
__int64 db_init()
{
__int64 result; // rax
const char *v1; // rax

result = sqlite3_open("/opt/zwave/bin/hzr.db", &pHzrDb);
if ( (_DWORD)result )
{
v1 = (const char *)sqlite3_errmsg(pHzrDb);
syslog(2, "Can't open database: %s", v1);
result = sqlite3_close(pHzrDb);
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
const char *v1; // rax

result = sqlite3_open("/opt/zwave/bin/hzr.db", &pHzrDb);
if ( (_DWORD)result )
{
v1 = (const char *)sqlite3_errmsg(pHzrDb);
syslog(2, "Can't open database: %s", v1);
result = sqlite3_close(pHzrDb);
}
return result;
}

original_code:
static void __attribute__ ((constructor)) db_init( void )
{
 if( sqlite3_open( "/opt/zwave/bin/hzr.db", &pHzrDb ) ){
  syslog( 2, "Can't open database: %s", sqlite3_errmsg( pHzrDb ) );;
  sqlite3_close( pHzrDb );
 }
}

canonical_original_code:
static void db_init()
{
 if( sqlite3_open( "/opt/zwave/bin/hzr.db", &pHzrDb ) ){
  syslog( 2, "Can't open database: %s", sqlite3_errmsg( pHzrDb ) );;
  sqlite3_close( pHzrDb );
 }
}


decompiled_code:
__int64 db_exit()
{
return sqlite3_close(pHzrDb);
}

canonical_decompiled_code:
__int64 func3()
{
return sqlite3_close(pHzrDb);
}

original_code:
static void __attribute__ ((destructor)) db_exit( void )
{
 sqlite3_close( pHzrDb );
}

canonical_original_code:
static void db_exit()
{
 sqlite3_close( pHzrDb );
}


original_code:
static int
bin_sensor_get( zw_api_ctx_S *ctx, u8 nodeid, void *resp )
{
 u8 buff[1024];
 int rc;
 buff[0] = 0x13;
 buff[1] = nodeid;
 buff[2] = 2;
 buff[3] = 0x30;
 buff[4] = 0x02;
 buff[5] = 0x01 | 0x04;
 buff[6] = 3;
 rc = zw_send_request( ctx, buff, 7, nodeid, 1, 0x13 );
 return rc;
}

canonical_original_code:
static int bin_sensor_get(struct zw_api_ctx *ctx, unsigned char nodeid, void *resp)
{
 unsigned char buff[1024];
 int rc;
 buff[0] = 0x13;
 buff[1] = nodeid;
 buff[2] = 2;
 buff[3] = 0x30;
 buff[4] = 0x02;
 buff[5] = 0x01 | 0x04;
 buff[6] = 3;
 rc = zw_send_request( ctx, buff, 7, nodeid, 1, 0x13 );
 return rc;
}

variable_types: struct zw_api_ctx { int port; int node_id; } *

variable_types:
nodeid
unsigned char


decompiled_code:
__int64 __fastcall bin_sensor_proc_msg(__int64 a1, unsigned __int8 *a2, unsigned __int8 a3)
{
syslog(7, "COMMAND_CLASS_SENSOR_BINARY - processing message");
if ( a2[6] == 3 )
{
syslog(7, "Got sensor report from node %i, level: %i", a2[3], a2[7]);
if ( (unsigned int)zw_node_set_state(a3, a2[7]) )
syslog(7, "Setting node bin sensor state failed");
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int8 *a2, unsigned __int8 a3)
{
syslog(7, "COMMAND_CLASS_SENSOR_BINARY - processing message");
if ( a2[6] == 3 )
{
syslog(7, "Got sensor report from node %i, level: %i", a2[3], a2[7]);
if ( (unsigned int)zw_node_set_state(a3, a2[7]) )
syslog(7, "Setting node bin sensor state failed");
}
return 0LL;
}

original_code:
static int
bin_sensor_proc_msg( zw_api_ctx_S *ctx, const u8* frame, u8 nodeid )
{
 int val = -1;
 syslog( 7, "COMMAND_CLASS_SENSOR_BINARY - processing message" );;
 if (frame[6] == 0x03) {
  syslog( 7, "Got sensor report from node %i, level: %i",(unsigned char)frame[3],(unsigned char)frame[7] );;
  val = frame[ 7 ];
  if ( 0 != zw_node_set_state( nodeid, val ) )
   syslog( 7, "Setting node bin sensor state failed" );;
 }
 return 0;
}

canonical_original_code:
static int bin_sensor_proc_msg(struct zw_api_ctx *ctx, unsigned char *frame, unsigned char nodeid)
{
 int val = -1;
 syslog( 7, "COMMAND_CLASS_SENSOR_BINARY - processing message" );;
 if (frame[6] == 0x03) {
  syslog( 7, "Got sensor report from node %i, level: %i",(unsigned char)frame[3],(unsigned char)frame[7] );;
  val = frame[ 7 ];
  if ( 0 != zw_node_set_state( nodeid, val ) )
   syslog( 7, "Setting node bin sensor state failed" );;
 }
 return 0;
}

variable_types:
frame
unsigned char *


decompiled_code:
__int64 bin_sensor_init()
{
return register_cmd_class(&bin_sensor);
}

canonical_decompiled_code:
__int64 func2()
{
return register_cmd_class(&bin_sensor);
}

original_code:
static void __attribute__ ((constructor)) bin_sensor_init( void )
{
 register_cmd_class( &bin_sensor );
}

canonical_original_code:
static void bin_sensor_init()
{
 register_cmd_class( &bin_sensor );
}


decompiled_code:
__int64 bin_sensor_exit()
{
return unregister_cmd_class(&bin_sensor);
}

canonical_decompiled_code:
__int64 func3()
{
return unregister_cmd_class(&bin_sensor);
}

original_code:
static void __attribute__ ((destructor)) bin_sensor_exit( void )
{
 unregister_cmd_class( &bin_sensor );
}

canonical_original_code:
static void bin_sensor_exit()
{
 unregister_cmd_class( &bin_sensor );
}


calculate

original_code:
double
calculate(const struct rusage *b, const struct rusage *a)
{
    if (b == ((void *)0) || a == ((void *)0))
        return 0;
    else
        return ((((a->ru_utime.tv_sec * 1000000 + a->ru_utime.tv_usec) -
                 (b->ru_utime.tv_sec * 1000000 + b->ru_utime.tv_usec)) +
                ((a->ru_stime.tv_sec * 1000000 + a->ru_stime.tv_usec) -
                 (b->ru_stime.tv_sec * 1000000 + b->ru_stime.tv_usec)))
                / 1000000.0);
}

canonical_original_code:
double calculate(struct rusage *b, struct rusage *a)
{
    if (b == ((void *)0) || a == ((void *)0))
        return 0;
    else
        return ((((a->ru_utime.tv_sec * 1000000 + a->ru_utime.tv_usec) -
                 (b->ru_utime.tv_sec * 1000000 + b->ru_utime.tv_usec)) +
                ((a->ru_stime.tv_sec * 1000000 + a->ru_stime.tv_usec) -
                 (b->ru_stime.tv_sec * 1000000 + b->ru_stime.tv_usec)))
                / 1000000.0);
}

variable_types: struct rusage { struct timeval { long tv_sec; long tv_usec; } ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; } *

variable_types:
a
struct rusage *

return_type: double

user_defined_types: struct rusage { struct timeval ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; }


pdeckInit

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

for ( result = 0LL; result != -52; --result )
byte_4040B3[result] = result + 51;
rest = 52;
return result;
}

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

for ( result = 0LL; result != -52; --result )
byte_4040B3[result] = result + 51;
rest = 52;
return result;
}

original_code:
void pdeckInit( void ){
 pdeckCardType i;
 for( i=52 ; i-- ; deck[i] = i );
 rest = 52;
}

canonical_original_code:
void pdeckInit(){
 unsigned char i;
 for( i=52 ; i-- ; deck[i] = i );
 rest = 52;
}

variable_types:
i
unsigned char


pdeckSwap

decompiled_code:
__int64 __fastcall pdeckSwap(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax

result = (unsigned __int8)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax

result = (unsigned __int8)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void pdeckSwap( pdeckCardType *pCard1 , pdeckCardType *pCard2 ){
 pdeckCardType cardTemp = *pCard1;
 *pCard1 = *pCard2;
 *pCard2 = cardTemp;
}

canonical_original_code:
void pdeckSwap(unsigned char *pCard1, unsigned char *pCard2){
 unsigned char cardTemp = *pCard1;
 *pCard1 = *pCard2;
 *pCard2 = cardTemp;
}

variable_types:
cardTemp
unsigned char


pdeckShuffle

decompiled_code:
void __fastcall pdeckShuffle(int a1)
{
int v1; // ebp
int v2; // eax
int v3; // er12
int v4; // ebx
int v5; // eax

v1 = a1 - 1;
if ( (_WORD)a1 )
{
do
{
v2 = rand();
v3 = (unsigned __int8)rest;
v4 = v2 % (unsigned __int8)rest;
v5 = rand();
pdeckSwap((_BYTE *)((unsigned __int8)v4 + 4210816LL), &deck[(unsigned __int8)(v5 % v3)]);
--v1;
}
while ( (_WORD)v1 != 0xFFFF );
}
}

canonical_decompiled_code:
void __fastcall func9(int a1)
{
int v1; // ebp
int v2; // eax
int v3; // er12
int v4; // ebx
int v5; // eax

v1 = a1 - 1;
if ( (_WORD)a1 )
{
do
{
v2 = rand();
v3 = (unsigned __int8)rest;
v4 = v2 % (unsigned __int8)rest;
v5 = rand();
func8((_BYTE *)((unsigned __int8)v4 + 4210816LL), &deck[(unsigned __int8)(v5 % v3)]);
--v1;
}
while ( (_WORD)v1 != 0xFFFF );
}
}

original_code:
void pdeckShuffle( unsigned short shuffle ){
 pdeckCardType i , j;
 for( ; shuffle-- ; pdeckSwap( &deck[i] , &deck[j] ) ) {
  i = rand() % rest;
  j = rand() % rest;
 }
}

canonical_original_code:
void pdeckShuffle(unsigned short shuffle){
 unsigned char i; unsigned char j;
 for( ; shuffle-- ; pdeckSwap( &deck[i] , &deck[j] ) ) {
  i = rand() % rest;
  j = rand() % rest;
 }
}

variable_types:
shuffle
unsigned short

variable_types:
j
unsigned char


pdeckGet

decompiled_code:
__int64 __fastcall pdeckGet(_BYTE *a1)
{
__int64 result; // rax

result = (unsigned __int8)rest;
if ( rest )
{
--rest;
*a1 = deck[(unsigned __int8)(result - 1)];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_BYTE *a1)
{
__int64 result; // rax

result = (unsigned __int8)rest;
if ( rest )
{
--rest;
*a1 = deck[(unsigned __int8)(result - 1)];
}
return result;
}

original_code:
pdeckCardType pdeckGet( pdeckCardType *pCard ){
 pdeckCardType res = rest;
 res = rest;
 if( res ) {
  *pCard = deck[--rest];
 }
 return res;
}

canonical_original_code:
unsigned char pdeckGet(unsigned char *pCard){
 unsigned char res = rest;
 res = rest;
 if( res ) {
  *pCard = deck[--rest];
 }
 return res;
}

variable_types:
pCard
unsigned char *

variable_types:
res
unsigned char

return_type: unsigned char


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
time_t v3; // rdi
char v5[9]; // [rsp+Fh] [rbp-9h] BYREF

v3 = time(0LL);
srand(v3);
pdeckInit(v3, argv);
pdeckShuffle(520);
while ( (unsigned __int8)pdeckGet(v5) )
printf("%d\n", (unsigned __int8)v5[0]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
time_t v3; // rdi
char v5[9]; // [rsp+Fh] [rbp-9h] BYREF

v3 = time(0LL);
srand(v3);
func7(v3, argv);
func9(520);
while ( (unsigned __int8)func10(v5) )
printf("%d\n", (unsigned __int8)v5[0]);
return 0;
}

original_code:
int main ( int argc , char *argv[] ){
 pdeckCardType card;
 srand( (unsigned)time(((void *)0)) );
 pdeckInit( );
 pdeckShuffle( 52 * 10 );
 for( ; pdeckGet( &card ) ; printf( "%d\n" , (unsigned int)card ) );
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 unsigned char card;
 srand( (unsigned int)time(((void *)0)) );
 pdeckInit( );
 pdeckShuffle( 52 * 10 );
 for( ; pdeckGet( &card ) ; printf( "%d\n" , (unsigned int)card ) );
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
card
unsigned char


init

repo: pollow/Dict

decompiled_code:
__int64 init()
{
readWords();
trieInit();
layoutInit();
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
func0();
trieInit();
layoutInit();
return 0LL;
}

original_code:
int init() {
    readWords();
    trieInit();
    layoutInit();
    return 0;
}


test

decompiled_code:
unsigned int **test()
{
unsigned int **result; // rax

readWords();
trieInit();
wordsNum = 20;
lookupProcess("ap*l?");
result = (unsigned int **)trielist;
if ( trielist )
{
do
{
printf("%s %d\n", *((const char **)*result + 1), **result);
result = *(unsigned int ***)(trielist + 8LL);
trielist = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
unsigned int **func2()
{
unsigned int **result; // rax

func0();
trieInit();
wordsNum = 20;
lookupProcess("ap*l?");
result = (unsigned int **)trielist;
if ( trielist )
{
do
{
printf("%s %d\n", *((const char **)*result + 1), **result);
result = *(unsigned int ***)(trielist + 8LL);
trielist = result;
}
while ( result );
}
return result;
}

original_code:
void test() {
    readWords();
    trieInit();
    wordsNum = 20;
    lookupProcess("ap*l?");
    while(trielist) {
        int _index_ = trielist->key->index;
        printf("%s %d\n",(trielist->key)->word,_index_);
        trielist = trielist->next;
    }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
init(argc, argv, envp);
layoutProcess();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func1(argc, argv, envp);
layoutProcess();
return 0;
}

original_code:
int main() {
    if(0) {
        test();
    } else {
    init();
    layoutProcess();
    }
    return 0;
}


trieNodeInit

decompiled_code:
__int64 __fastcall trieNodeInit(__int64 a1)
{
int v1; // eax
void *v2; // rdi
unsigned int v3; // ecx
__int64 result; // rax

v1 = a1;
*(_DWORD *)a1 = -1;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 136) = 0LL;
v2 = (void *)((a1 + 24) & 0xFFFFFFFFFFFFFFF8LL);
v3 = (unsigned int)(v1 - (_DWORD)v2 + 144) >> 3;
result = 0LL;
memset(v2, 0, 8LL * v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
void *v2; // rdi
unsigned int v3; // ecx
__int64 result; // rax

v1 = a1;
*(_DWORD *)a1 = -1;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 136) = 0LL;
v2 = (void *)((a1 + 24) & 0xFFFFFFFFFFFFFFF8LL);
v3 = (unsigned int)(v1 - (_DWORD)v2 + 144) >> 3;
result = 0LL;
memset(v2, 0, 8LL * v3);
return result;
}

original_code:
void trieNodeInit(struct trieNode *a) {
    a->index = -1;
    a->word = ((void *)0);
    memset(a->son,0, sizeof(a->son));
}

variable_types: struct trieNode { int index; char *word; struct trieNode *son[16]; } *


newNode

decompiled_code:
void *newNode()
{
void *v0; // rbx

v0 = malloc(0x90uLL);
trieNodeInit((__int64)v0);
return v0;
}

canonical_decompiled_code:
void *func1()
{
void *v0; // rbx

v0 = malloc(0x90uLL);
func0((__int64)v0);
return v0;
}

original_code:
struct trieNode *newNode() {
    struct trieNode *tmp = (struct trieNode *)malloc(sizeof(struct trieNode));
    trieNodeInit(tmp);
    return tmp;
}

return_type: struct trieNode { int index; char *word; struct trieNode *son[16]; } *


trieInsert

original_code:
struct trieNode *trieInsert(struct trieNode *u, int *q, const int index) {
    while (*q != -1) {
        if(u->son[*q] == ((void *)0)) u->son[*q] = newNode();
        u = u->son[*q];
        q++;
    }
    u->index = index;
    u->word = words[index];
    return u;
}

canonical_original_code:
struct trieNode *trieInsert(struct trieNode *u, int *q, int index) {
    while (*q != -1) {
        if(u->son[*q] == ((void *)0)) u->son[*q] = newNode();
        u = u->son[*q];
        q++;
    }
    u->index = index;
    u->word = words[index];
    return u;
}

variable_types:
u
struct trieNode *

variable_types:
q
int *

variable_types: index int

user_defined_types: struct trieNode { int index; char *word; struct trieNode *son[16]; }


trieSearch

decompiled_code:
__int64 __fastcall trieSearch(__int64 a1, int *a2)
{
int v2; // edx
__int64 result; // rax

v2 = *a2;
result = a1;
if ( *a2 != -1 )
{
result = *(_QWORD *)(a1 + 8LL * v2 + 16);
if ( result )
result = trieSearch(*(_QWORD *)(a1 + 8LL * v2 + 16), a2 + 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int *a2)
{
int v2; // edx
__int64 result; // rax

v2 = *a2;
result = a1;
if ( *a2 != -1 )
{
result = *(_QWORD *)(a1 + 8LL * v2 + 16);
if ( result )
result = func4(*(_QWORD *)(a1 + 8LL * v2 + 16), a2 + 1);
}
return result;
}

original_code:
struct trieNode *trieSearch(struct trieNode *u, int *ch) {
    if(*ch == -1) {
        return u;
    } else {
        if(u->son[*ch] == ((void *)0)) {
            return ((void *)0);
        } else {
            return trieSearch(u->son[*ch],ch+1);
        }
    }
}

variable_types:
ch
int *


delTrieList

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

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

original_code:
void delTrieList(struct trieList *u) {
    if(u == ((void *)0)) {
        return;
    } else {
        delTrieList(u->next);
        free(u);
    }
}

variable_types: struct trieList { struct trieNode { int index; char *word; struct trieNode *son[16]; } *key; struct trieList *next; } *

user_defined_types: struct trieList { struct trieNode *key; struct trieList *next; }


emptyTrieList

decompiled_code:
void emptyTrieList()
{
delTrieList(trielist);
trielist = 0LL;
}

canonical_decompiled_code:
void func6()
{
func5(trielist);
trielist = 0LL;
}

original_code:
void emptyTrieList() {
    delTrieList(trielist);
    trielist = ((void *)0);
}


trieGetList

decompiled_code:
void __fastcall trieGetList(_DWORD *a1, _DWORD *a2)
{
_QWORD *v2; // rbx
_QWORD *v3; // rax
bool v4; // zf

if ( *a1 == -1 || (v3 = malloc(0x10uLL), *v3 = a1, v3[1] = trielist, trielist = v3, v4 = *a2 == 1, --*a2, !v4) )
{
v2 = a1 + 4;
do
{
if ( *v2 )
{
if ( *a2 )
trieGetList(*v2, a2);
}
++v2;
}
while ( v2 != (_QWORD *)(a1 + 36) );
}
}

original_code:
void trieGetList(struct trieNode *u, int *num) {
    if(u->index != -1) {
        struct trieList *tmp = (struct trieList *) malloc(sizeof(struct trieList));
        tmp->key = u;
        tmp->next = trielist;
        trielist = tmp;
        (*num)--;
        if(!*num) return;
    }
    for(int i=0;i<16;i++) {
            if(u->son[i] && *num) trieGetList(u->son[i],num);
    }
}

canonical_original_code:
void trieGetList(struct trieNode *u, int *num) {
    if(u->index != -1) {
        struct trieList *tmp = (struct trieList *) malloc(sizeof(struct trieList));
        tmp->key = u;
        tmp->next = trielist;
        trielist = tmp;
        (*num)--;
        if(!*num) return;
    }
    for(int i = 0;i<16;i++) {
            if(u->son[i] && *num) trieGetList(u->son[i],num);
    }
}

variable_types:
num
int *

variable_types: i int


trieInit

decompiled_code:
void trieInit()
{
__int64 i; // rbx
const char *v1; // rsi
int v2[202]; // [rsp+0h] [rbp-328h] BYREF

for ( i = 0LL; i != 91286; ++i )
{
v1 = (const char *)*((_QWORD *)&words + i);
if ( v1 )
{
hexConvert((__int64)v2, v1);
*((_QWORD *)&wordsNode + i) = trieInsert((__int64)&trieRoot, v2, i);
}
}
}

canonical_decompiled_code:
void func8()
{
__int64 i; // rbx
const char *v1; // rsi
int v2[202]; // [rsp+0h] [rbp-328h] BYREF

for ( i = 0LL; i != 91286; ++i )
{
v1 = (const char *)*((_QWORD *)&words + i);
if ( v1 )
{
func2((__int64)v2, v1);
*((_QWORD *)&wordsNode + i) = func3((__int64)&trieRoot, v2, i);
}
}
}

original_code:
void trieInit() {
    int hexStr[200];
    for(int i=0;i<91286;i++) {
        if(words[i] == ((void *)0)) {
            continue;
        }
        hexConvert(hexStr,words[i]);
        wordsNode[i] = trieInsert(&trieRoot,hexStr,i);
    }
}

canonical_original_code:
void trieInit() {
    int hexStr[200];
    for(int i = 0;i<91286;i++) {
        if(words[i] == ((void *)0)) {
            continue;
        }
        hexConvert(hexStr,words[i]);
        wordsNode[i] = trieInsert(&trieRoot,hexStr,i);
    }
}

variable_types:
hexStr
int [200]


min

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

original_code:
int min(int a, int b) {
    if ( a < b ) return a;
    else return b;
}

variable_types: a int

variable_types: b int


cleanHeap

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

result = 0LL;
memset(&heap, 0, 0x640uLL);
LODWORD(heapSize) = 1;
return result;
}

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

result = 0LL;
memset(&heap, 0, 0x640uLL);
LODWORD(heapSize) = 1;
return result;
}

original_code:
void cleanHeap() {
    memset(heap,0,sizeof(heap));
    heapSize = 1;
}


popHeap

decompiled_code:
__int64 popHeap()
{
unsigned int *v0; // rdi
unsigned int v1; // ebx
int v2; // esi
int v3; // ecx
int v4; // edx
int v5; // eax
__int64 v6; // rdx
__int64 v7; // rdi

v0 = (unsigned int *)heap[1];
v1 = *v0;
free(v0);
v2 = (_DWORD)heapSize - 1;
LODWORD(heapSize) = v2;
heap[1] = heap[v2];
if ( v2 > 2 )
{
v3 = 1;
v4 = 2;
while ( 1 )
{
v5 = v4 + 1;
if ( v2 <= v4 + 1 )
{
v5 = v4;
}
else if ( *(_DWORD *)(heap[v4] + 4LL) >= *(_DWORD *)(heap[v5] + 4LL) )
{
v5 = v4;
}
v6 = heap[v3];
v7 = heap[v5];
if ( *(_DWORD *)(v6 + 4) <= *(_DWORD *)(v7 + 4) )
{
heap[v3] = v7;
heap[v5] = v6;
}
v4 = 2 * v5;
if ( v2 <= 2 * v5 )
break;
v3 = v5;
}
}
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int *v0; // rdi
unsigned int v1; // ebx
int v2; // esi
int v3; // ecx
int v4; // edx
int v5; // eax
__int64 v6; // rdx
__int64 v7; // rdi

v0 = (unsigned int *)heap[1];
v1 = *v0;
free(v0);
v2 = (_DWORD)heapSize - 1;
LODWORD(heapSize) = v2;
heap[1] = heap[v2];
if ( v2 > 2 )
{
v3 = 1;
v4 = 2;
while ( 1 )
{
v5 = v4 + 1;
if ( v2 <= v4 + 1 )
{
v5 = v4;
}
else if ( *(_DWORD *)(heap[v4] + 4LL) >= *(_DWORD *)(heap[v5] + 4LL) )
{
v5 = v4;
}
v6 = heap[v3];
v7 = heap[v5];
if ( *(_DWORD *)(v6 + 4) <= *(_DWORD *)(v7 + 4) )
{
heap[v3] = v7;
heap[v5] = v6;
}
v4 = 2 * v5;
if ( v2 <= 2 * v5 )
break;
v3 = v5;
}
}
return v1;
}

original_code:
int popHeap() {
    int ans = heap[1]->key, t=1;
    struct heapStruct *tmp;
    free(heap[1]);
    heap[1] = heap[--heapSize];
    while( t<<1 < heapSize ) {
        int k = t << 1;
        if(( k+1 < heapSize ) && (heap[ k ]->value < heap[ k + 1 ]->value)) k++;
        if(heap[ t ]->value <= heap[ k ]->value) {
            tmp = heap[ t ];
            heap[ t ] = heap[ k ];
            heap[ k ] = tmp;
        }
        t = k;
    }
    return ans;
}

canonical_original_code:
int popHeap() {
    int ans = heap[1]->key; int t = 1;
    struct heapStruct *tmp;
    free(heap[1]);
    heap[1] = heap[--heapSize];
    while( t<<1 < heapSize ) {
        int k = t << 1;
        if(( k+1 < heapSize ) && (heap[ k ]->value < heap[ k + 1 ]->value)) k++;
        if(heap[ t ]->value <= heap[ k ]->value) {
            tmp = heap[ t ];
            heap[ t ] = heap[ k ];
            heap[ k ] = tmp;
        }
        t = k;
    }
    return ans;
}

variable_types: ans int

variable_types: t int

variable_types:
tmp
struct heapStruct { int key; } *

variable_types: k int


addHeap

decompiled_code:
__int64 __fastcall addHeap(int a1, int a2)
{
int v2; // ebx
__int64 result; // rax
_DWORD *v4; // rax
__int64 v5; // rdx
int v6; // eax
__int64 v7; // rcx

v2 = (int)heapSize;
if ( wordsNum + 1 >= (int)heapSize || (result = heap[1], *(_DWORD *)(result + 4) > a2) )
{
LODWORD(heapSize) = (_DWORD)heapSize + 1;
v4 = malloc(8uLL);
heap[v2] = v4;
*v4 = a1;
for ( v4[1] = a2; v2 > 1; heap[v2] = v5 )
{
v5 = heap[v2];
v6 = v2;
v2 >>= 1;
v7 = heap[v2];
if ( *(_DWORD *)(v5 + 4) <= *(_DWORD *)(v7 + 4) )
break;
heap[v6] = v7;
}
result = (unsigned int)(wordsNum + 2);
if ( (int)result < (int)heapSize )
result = popHeap();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
int v2; // ebx
__int64 result; // rax
_DWORD *v4; // rax
__int64 v5; // rdx
int v6; // eax
__int64 v7; // rcx

v2 = (int)heapSize;
if ( wordsNum + 1 >= (int)heapSize || (result = heap[1], *(_DWORD *)(result + 4) > a2) )
{
LODWORD(heapSize) = (_DWORD)heapSize + 1;
v4 = malloc(8uLL);
heap[v2] = v4;
*v4 = a1;
for ( v4[1] = a2; v2 > 1; heap[v2] = v5 )
{
v5 = heap[v2];
v6 = v2;
v2 >>= 1;
v7 = heap[v2];
if ( *(_DWORD *)(v5 + 4) <= *(_DWORD *)(v7 + 4) )
break;
heap[v6] = v7;
}
result = (unsigned int)(wordsNum + 2);
if ( (int)result < (int)heapSize )
result = func2();
}
return result;
}

original_code:
void addHeap(int key, int value) {
    if(heapSize > wordsNum+1 && value >= heap[1]->value) return;
    int t = heapSize++;
    struct heapStruct *tmp;
    heap[t] = (struct heapStruct *) malloc(sizeof(struct heapStruct));
    heap[t]->key = key;
    heap[t]->value = value;
    while(t > 1) {
        if(heap[ t ]->value > heap[ t >> 1 ]->value) {
            tmp = heap[t];
            heap[t] = heap[t >> 1];
            heap[t >> 1] = tmp;
        } else break;
        t = t >> 1;
    }
    if( heapSize > wordsNum+2 ) {
        popHeap();
    }
    return;
}

variable_types: key int

variable_types: value int


MED

original_code:
void MED(char *a) {
    int f[100][100];
    cleanHeap();
    for( int t = 0; t < 91286; t++ ) {
        memset(f,0,sizeof(f));
        char *b = words[t];
        if( !b ) continue;
        size_t lena = strlen(a), lenb = strlen(b);
        for(size_t i = 1; i <= lena; i++) f[i][0] = f[i-1][0]+5;
        for(size_t i = 1; i <= lenb; i++) f[0][i] = f[0][i-1]+3;
        for(size_t i = 1; i <= lena; i++)
            for(size_t j=1; j <= lenb; j++) {
                f[i][j] = min(f[i-1][j]+5,f[i][j-1]+3);
                if( toupper(a[i-1]) != toupper(b[j-1]) ) {
                    f[i][j] = min(f[i][j],f[i-1][j-1]+1);
                } else {
                    f[i][j] = min(f[i][j],f[i-1][j-1]);
                }
            }
        addHeap(t,f[lena][lenb]);
    }
    return;
}

canonical_original_code:
void MED(char *a) {
    int f[100][100];
    cleanHeap();
    for( int t = 0; t < 91286; t++ ) {
        memset(f,0,sizeof(f));
        char *b = words[t];
        if( !b ) continue;
        unsigned long lena = strlen(a); unsigned long lenb = strlen(b);
        for(unsigned long i = 1; i <= lena; i++) f[i][0] = f[i-1][0]+5;
        for(unsigned long i = 1; i <= lenb; i++) f[0][i] = f[0][i-1]+3;
        for(unsigned long i = 1; i <= lena; i++)
            for(unsigned long j = 1; j <= lenb; j++) {
                f[i][j] = min(f[i-1][j]+5,f[i][j-1]+3);
                if( toupper(a[i-1]) != toupper(b[j-1]) ) {
                    f[i][j] = min(f[i][j],f[i-1][j-1]+1);
                } else {
                    f[i][j] = min(f[i][j],f[i-1][j-1]);
                }
            }
        addHeap(t,f[lena][lenb]);
    }
    return;
}

variable_types:
a
char *

variable_types:
b
char *

variable_types:
lena
unsigned long

variable_types:
lenb
unsigned long

variable_types:
i
unsigned long

variable_types:
j
unsigned long


trieValid

decompiled_code:
__int64 __fastcall trieValid(const char *a1)
{
int v1; // ecx
__int64 v2; // rax
char v3; // dl

v1 = strlen(a1);
v2 = 0LL;
while ( v1 >= (int)v2 )
{
v3 = a1[v2++];
if ( v3 == 42 || v3 == 63 )
return 0xFFFFFFFFLL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
int v1; // ecx
__int64 v2; // rax
char v3; // dl

v1 = strlen(a1);
v2 = 0LL;
while ( v1 >= (int)v2 )
{
v3 = a1[v2++];
if ( v3 == 42 || v3 == 63 )
return 0xFFFFFFFFLL;
}
return 1LL;
}

original_code:
int trieValid(char *str) {
    for (int i = 0; i <= (int)strlen(str); i++) {
        if(str[i] == '*' || str[i] == '?') {
            return -1;
        }
    }
    return 1;
}

variable_types:
str
char *


isCapable

decompiled_code:
__int64 __fastcall isCapable(const char *a1, const char *a2)
{
unsigned int v2; // er14
unsigned int v4; // ecx
int v5; // esi
__int64 v6; // rbx
int v7; // ebp
char v8; // al
int v9; // er15
const char *v10; // r13
int v11; // ebp
__int64 v12; // rbx
unsigned int v13; // eax

if ( !a2 )
return 0;
v5 = strlen(a1);
v6 = 0LL;
v7 = 0;
while ( 1 )
{
if ( v5 < (int)v6 )
{
LOBYTE(v2) = (unsigned int)strlen(a2) + 1 == v7;
return v2;
}
v8 = a1[v6];
LOBYTE(v4) = v8 != 63 && v8 != 42;
v2 = v4;
if ( !(_BYTE)v4 )
break;
if ( a2[v7] != v8 )
return 0;
++v7;
LABEL_5:
++v6;
}
if ( v8 == 63 )
{
++v7;
goto LABEL_5;
}
if ( v8 != 42 )
goto LABEL_5;
v9 = strlen(a2);
v10 = &a2[v7];
v11 = v7 - (_DWORD)v10;
v12 = (__int64)&a1[v6 + 1];
while ( v9 >= v11 + (int)v10 )
{
v13 = isCapable(v12, v10++);
if ( (_BYTE)v13 )
return v13;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
unsigned int v2; // er14
unsigned int v4; // ecx
int v5; // esi
__int64 v6; // rbx
int v7; // ebp
char v8; // al
int v9; // er15
const char *v10; // r13
int v11; // ebp
__int64 v12; // rbx
unsigned int v13; // eax

if ( !a2 )
return 0;
v5 = strlen(a1);
v6 = 0LL;
v7 = 0;
while ( 1 )
{
if ( v5 < (int)v6 )
{
LOBYTE(v2) = (unsigned int)strlen(a2) + 1 == v7;
return v2;
}
v8 = a1[v6];
LOBYTE(v4) = v8 != 63 && v8 != 42;
v2 = v4;
if ( !(_BYTE)v4 )
break;
if ( a2[v7] != v8 )
return 0;
++v7;
LABEL_5:
++v6;
}
if ( v8 == 63 )
{
++v7;
goto LABEL_5;
}
if ( v8 != 42 )
goto LABEL_5;
v9 = strlen(a2);
v10 = &a2[v7];
v11 = v7 - (_DWORD)v10;
v12 = (__int64)&a1[v6 + 1];
while ( v9 >= v11 + (int)v10 )
{
v13 = func1(v12, v10++);
if ( (_BYTE)v13 )
return v13;
}
return v2;
}

original_code:
_Bool isCapable(char *a, char *b) {
    if(!b) return 0;
    int j = 0;
    for (int i = 0; i <= (int)strlen(a); i++) {
        if(a[i] != '*' && a[i] != '?') {
            if(a[i] != b[j]) return 0;
            j++;
        } else if(a[i] == '?') {
            j++;
        } else if(a[i] == '*') {
            for (int k = j; k <= (int)strlen(b); k++) {
                if (isCapable(a+(i+1),b+k)) return 1;
            }
            return 0;
        }
    }
    if (j == (int)strlen(b) + 1) return 1;
    else return 0;
}

variable_types: j int

variable_types: i int


layoutInit

decompiled_code:
__int64 layoutInit()
{
int v0; // eax
__int64 result; // rax

setlocale(6, &locale);
initscr();
cbreak();
keypad(stdscr, 1);
if ( stdscr )
{
max_row = stdscr->_maxy + 1;
v0 = stdscr->_maxx + 1;
}
else
{
max_row = -1;
v0 = -1;
}
max_col = v0;
noecho();
start_color();
wrefresh(stdscr);
inputBoxBorder = newwin(3, max_col, 0, 0);
wborder(
inputBoxBorder,
LODWORD(acs_map[60]),
LODWORD(acs_map[60]),
HIDWORD(acs_map[56]),
HIDWORD(acs_map[56]),
LODWORD(acs_map[54]),
HIDWORD(acs_map[53]),
LODWORD(acs_map[58]),
HIDWORD(acs_map[58]));
wrefresh(inputBoxBorder);
inputBox = newwin(1, max_col - 2, 1, 1);
wrefresh(inputBox);
wordsListBorder = newwin(max_row - 3, 20, 3, 0);
wborder(
wordsListBorder,
LODWORD(acs_map[60]),
0x20uLL,
0x20uLL,
HIDWORD(acs_map[56]),
LODWORD(acs_map[60]),
0x20uLL,
HIDWORD(acs_map[54]),
HIDWORD(acs_map[56]));
wrefresh(wordsListBorder);
wordsList = newwin(max_row - 4, 18, 3, 1);
wrefresh(wordsList);
wordDetailBorder = newwin(max_row - 3, max_col - 20, 3, 20);
wborder(
wordDetailBorder,
LODWORD(acs_map[60]),
LODWORD(acs_map[60]),
0x20uLL,
HIDWORD(acs_map[56]),
LODWORD(acs_map[60]),
LODWORD(acs_map[60]),
LODWORD(acs_map[59]),
LODWORD(acs_map[53]));
wrefresh(wordDetailBorder);
wordDetail = newpad(2000, max_col - 22);
wrefresh(stdscr);
wmove(inputBox, 0, 0);
wrefresh(inputBox);
init_pair(1, 0, 7);
init_pair(2, 7, 0);
wattr_on(wordsList, 0x200uLL, 0LL);
wattr_on(inputBox, 0x200uLL, 0LL);
wattr_on(wordDetail, 0x200uLL, 0LL);
result = (unsigned int)(max_row - 4);
wordsNum = max_row - 4;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
__int64 result; // rax

setlocale(6, &locale);
initscr();
cbreak();
keypad(stdscr, 1);
if ( stdscr )
{
max_row = stdscr->_maxy + 1;
v0 = stdscr->_maxx + 1;
}
else
{
max_row = -1;
v0 = -1;
}
max_col = v0;
noecho();
start_color();
wrefresh(stdscr);
inputBoxBorder = newwin(3, max_col, 0, 0);
wborder(
inputBoxBorder,
LODWORD(acs_map[60]),
LODWORD(acs_map[60]),
HIDWORD(acs_map[56]),
HIDWORD(acs_map[56]),
LODWORD(acs_map[54]),
HIDWORD(acs_map[53]),
LODWORD(acs_map[58]),
HIDWORD(acs_map[58]));
wrefresh(inputBoxBorder);
inputBox = newwin(1, max_col - 2, 1, 1);
wrefresh(inputBox);
wordsListBorder = newwin(max_row - 3, 20, 3, 0);
wborder(
wordsListBorder,
LODWORD(acs_map[60]),
0x20uLL,
0x20uLL,
HIDWORD(acs_map[56]),
LODWORD(acs_map[60]),
0x20uLL,
HIDWORD(acs_map[54]),
HIDWORD(acs_map[56]));
wrefresh(wordsListBorder);
wordsList = newwin(max_row - 4, 18, 3, 1);
wrefresh(wordsList);
wordDetailBorder = newwin(max_row - 3, max_col - 20, 3, 20);
wborder(
wordDetailBorder,
LODWORD(acs_map[60]),
LODWORD(acs_map[60]),
0x20uLL,
HIDWORD(acs_map[56]),
LODWORD(acs_map[60]),
LODWORD(acs_map[60]),
LODWORD(acs_map[59]),
LODWORD(acs_map[53]));
wrefresh(wordDetailBorder);
wordDetail = newpad(2000, max_col - 22);
wrefresh(stdscr);
wmove(inputBox, 0, 0);
wrefresh(inputBox);
init_pair(1, 0, 7);
init_pair(2, 7, 0);
wattr_on(wordsList, 0x200uLL, 0LL);
wattr_on(inputBox, 0x200uLL, 0LL);
wattr_on(wordDetail, 0x200uLL, 0LL);
result = (unsigned int)(max_row - 4);
wordsNum = max_row - 4;
return result;
}

original_code:
void layoutInit() {
    setlocale(6,"");
    initscr();
    cbreak();
    keypad(stdscr, 1);
    (max_row = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), max_col = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
    noecho();
    start_color();
    wrefresh(stdscr);
    inputBoxBorder = newwin(3,max_col,0,0);
    wborder(inputBoxBorder,(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('l'))]),(acs_map[(unsigned char)(('k'))]),(acs_map[(unsigned char)(('t'))]),(acs_map[(unsigned char)(('u'))]));
    wrefresh(inputBoxBorder);
    inputBox = newwin(1,max_col-2,1,1);
    wrefresh(inputBox);
    wordsListBorder = newwin(max_row-3,20,3,0);
    wborder(wordsListBorder,(acs_map[(unsigned char)(('x'))]),' ',' ',(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('x'))]),' ',(acs_map[(unsigned char)(('m'))]),(acs_map[(unsigned char)(('q'))]));
    wrefresh(wordsListBorder);
    wordsList = newwin(max_row-4,18,3,1);
    wrefresh(wordsList);
    wordDetailBorder = newwin(max_row-3,max_col-20,3,20);
    wborder(wordDetailBorder,(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('x'))]),' ',(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('v'))]),(acs_map[(unsigned char)(('j'))]));
    wrefresh(wordDetailBorder);
    wordDetail = newpad(2000,max_col-22);
    wrefresh(stdscr);
    wmove(inputBox,0,0);
    wrefresh(inputBox);
    init_pair(1,0,7);
    init_pair(2,7,0);
    wattr_on(wordsList, (attr_t)((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    wattr_on(inputBox, (attr_t)((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    wattr_on(wordDetail, (attr_t)((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    wordsNum = max_row-4;
}

canonical_original_code:
void layoutInit() {
    setlocale(6,"");
    initscr();
    cbreak();
    keypad(stdscr, 1);
    (max_row = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), max_col = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
    noecho();
    start_color();
    wrefresh(stdscr);
    inputBoxBorder = newwin(3,max_col,0,0);
    wborder(inputBoxBorder,(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('l'))]),(acs_map[(unsigned char)(('k'))]),(acs_map[(unsigned char)(('t'))]),(acs_map[(unsigned char)(('u'))]));
    wrefresh(inputBoxBorder);
    inputBox = newwin(1,max_col-2,1,1);
    wrefresh(inputBox);
    wordsListBorder = newwin(max_row-3,20,3,0);
    wborder(wordsListBorder,(acs_map[(unsigned char)(('x'))]),' ',' ',(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('x'))]),' ',(acs_map[(unsigned char)(('m'))]),(acs_map[(unsigned char)(('q'))]));
    wrefresh(wordsListBorder);
    wordsList = newwin(max_row-4,18,3,1);
    wrefresh(wordsList);
    wordDetailBorder = newwin(max_row-3,max_col-20,3,20);
    wborder(wordDetailBorder,(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('x'))]),' ',(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('v'))]),(acs_map[(unsigned char)(('j'))]));
    wrefresh(wordDetailBorder);
    wordDetail = newpad(2000,max_col-22);
    wrefresh(stdscr);
    wmove(inputBox,0,0);
    wrefresh(inputBox);
    init_pair(1,0,7);
    init_pair(2,7,0);
    wattr_on(wordsList, (attr_t)((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    wattr_on(inputBox, (attr_t)((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    wattr_on(wordDetail, (attr_t)((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    wordsNum = max_row-4;
}


printDetail

decompiled_code:
int printDetail()
{
__int64 v0; // rbx

if ( expNodetop > 0 )
{
v0 = 0LL;
do
{
if ( strcmp(*((const char **)&expNodeList + v0), "DC") )
{
if ( !strcmp(*((const char **)&expNodeList + v0), "YX") )
{
wattrset(wordDetail, 0x10000);
wprintw(wordDetail, "\n%s\n\n", *(const char **)(*((_QWORD *)&expNodeList + v0) + 8LL));
wattrset(wordDetail, 0);
}
else if ( !strcmp(*((const char **)&expNodeList + v0), "DX") )
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, &byte_F04);
wattrset(wordDetail, 0);
wprintw(wordDetail, "%s\n", *(const char **)(*((_QWORD *)&expNodeList + v0) + 8LL));
}
else if ( strcmp(*((const char **)&expNodeList + v0), "JX") )
{
if ( !strcmp(*((const char **)&expNodeList + v0), "GZ") )
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, &byte_F17);
wattrset(wordDetail, 0);
wprintw(wordDetail, "%s\n", *(const char **)(*((_QWORD *)&expNodeList + v0) + 8LL));
}
else if ( !strcmp(*((const char **)&expNodeList + v0), "LY") )
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, &byte_F23);
wattrset(wordDetail, 0);
wprintw(wordDetail, "%s\n", *(const char **)(*((_QWORD *)&expNodeList + v0) + 8LL));
}
else if ( !strcmp(*((const char **)&expNodeList + v0), "LS") )
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, &byte_F2F);
wattrset(wordDetail, 0);
wprintw(wordDetail, "%s\n", *(const char **)(*((_QWORD *)&expNodeList + v0) + 8LL));
}
}
}
++v0;
}
while ( expNodetop > (int)v0 );
}
return wrefresh(wordDetail);
}

canonical_decompiled_code:
int func1()
{
__int64 v0; // rbx

if ( expNodetop > 0 )
{
v0 = 0LL;
do
{
if ( strcmp(*((const char **)&expNodeList + v0), "DC") )
{
if ( !strcmp(*((const char **)&expNodeList + v0), "YX") )
{
wattrset(wordDetail, 0x10000);
wprintw(wordDetail, "\n%s\n\n", *(const char **)(*((_QWORD *)&expNodeList + v0) + 8LL));
wattrset(wordDetail, 0);
}
else if ( !strcmp(*((const char **)&expNodeList + v0), "DX") )
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, &byte_F04);
wattrset(wordDetail, 0);
wprintw(wordDetail, "%s\n", *(const char **)(*((_QWORD *)&expNodeList + v0) + 8LL));
}
else if ( strcmp(*((const char **)&expNodeList + v0), "JX") )
{
if ( !strcmp(*((const char **)&expNodeList + v0), "GZ") )
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, &byte_F17);
wattrset(wordDetail, 0);
wprintw(wordDetail, "%s\n", *(const char **)(*((_QWORD *)&expNodeList + v0) + 8LL));
}
else if ( !strcmp(*((const char **)&expNodeList + v0), "LY") )
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, &byte_F23);
wattrset(wordDetail, 0);
wprintw(wordDetail, "%s\n", *(const char **)(*((_QWORD *)&expNodeList + v0) + 8LL));
}
else if ( !strcmp(*((const char **)&expNodeList + v0), "LS") )
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, &byte_F2F);
wattrset(wordDetail, 0);
wprintw(wordDetail, "%s\n", *(const char **)(*((_QWORD *)&expNodeList + v0) + 8LL));
}
}
}
++v0;
}
while ( expNodetop > (int)v0 );
}
return wrefresh(wordDetail);
}

original_code:
void printDetail() {
    for(int i=0; i<expNodetop; i++) {
        if (strcmp(expNodeList[i]->name, "DC") == 0) {
        } else if (strcmp(expNodeList[i]->name, "YX") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((8) + 8)));
            wprintw(wordDetail, "\n%s\n\n", expNodeList[i]->data);
            wattrset(wordDetail, (1U - 1U));
        } else if (strcmp(expNodeList[i]->name, "DX") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "词性: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        } else if (strcmp(expNodeList[i]->name, "JX") == 0) {
        } else if (strcmp(expNodeList[i]->name, "GZ") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "释义: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        } else if (strcmp(expNodeList[i]->name, "LY") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "例句: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        } else if (strcmp(expNodeList[i]->name, "LS") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "翻译: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        }
    }
    wrefresh(wordDetail);
}

canonical_original_code:
void printDetail() {
    for(int i = 0; i<expNodetop; i++) {
        if (strcmp(expNodeList[i]->name, "DC") == 0) {
        } else if (strcmp(expNodeList[i]->name, "YX") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((8) + 8)));
            wprintw(wordDetail, "\n%s\n\n", expNodeList[i]->data);
            wattrset(wordDetail, (1U - 1U));
        } else if (strcmp(expNodeList[i]->name, "DX") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "词性: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        } else if (strcmp(expNodeList[i]->name, "JX") == 0) {
        } else if (strcmp(expNodeList[i]->name, "GZ") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "释义: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        } else if (strcmp(expNodeList[i]->name, "LY") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "例句: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        } else if (strcmp(expNodeList[i]->name, "LS") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "翻译: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        }
    }
    wrefresh(wordDetail);
}


wordSelect

decompiled_code:
int wordSelect()
{
__int64 v0; // rax
__int64 v1; // rdx
int v2; // ebx
int *v3; // rdx
__int64 v4; // rax
int v5; // ecx
int v6; // er12
int v7; // ebp
unsigned int v9[206]; // [rsp+0h] [rbp-338h] BYREF

memset(v9, 0, 0x320uLL);
v0 = trielist;
if ( trielist )
{
v1 = 0LL;
do
{
v2 = v1;
v9[v1] = **(_DWORD **)v0;
v0 = *(_QWORD *)(v0 + 8);
++v1;
}
while ( v0 );
if ( v2 > 1 )
{
v3 = (int *)&v9[v2];
v4 = 0LL;
do
{
v5 = v9[v4];
v9[v4] = *v3;
*v3 = v5;
++v4;
--v3;
}
while ( v2 / 2 > (int)v4 );
}
}
else
{
v2 = -1;
}
curs_set(0);
if ( wmove(wordsList, 0, 0) != -1 )
wchgat(wordsList, -1, 0LL, 1, 0LL);
parserProcess(v9[0]);
werase(wordDetail);
printDetail();
prefresh(wordDetail, 0, 0, 3, 21, max_row - 2, max_col - 1);
wrefresh(wordsList);
v6 = 0;
v7 = 0;
while ( 2 )
{
switch ( wgetch(stdscr) )
{
case 258:
if ( wmove(wordsList, v7, 0) != -1 )
wchgat(wordsList, -1, 0LL, 2, 0LL);
if ( v7 >= v2 )
return curs_set(1);
++v7;
goto LABEL_16;
case 259:
if ( wmove(wordsList, v7, 0) != -1 )
wchgat(wordsList, -1, 0LL, 2, 0LL);
if ( v7 > 0 )
{
--v7;
LABEL_16:
v6 = 0;
LABEL_17:
if ( wmove(wordsList, v7, 0) != -1 )
wchgat(wordsList, -1, 0LL, 1, 0LL);
wrefresh(wordsList);
parserProcess(v9[v7]);
werase(wordDetail);
printDetail();
prefresh(wordDetail, v6, 0, 3, 21, max_row - 2, max_col - 1);
continue;
}
return curs_set(1);
case 260:
--v6;
goto LABEL_28;
case 261:
++v6;
LABEL_28:
prefresh(wordDetail, v6, 0, 3, 21, max_row - 2, max_col - 1);
continue;
case 265:
endwin();
exit(0);
default:
goto LABEL_17;
}
}
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rax
__int64 v1; // rdx
int v2; // ebx
int *v3; // rdx
__int64 v4; // rax
int v5; // ecx
int v6; // er12
int v7; // ebp
unsigned int v9[206]; // [rsp+0h] [rbp-338h] BYREF

memset(v9, 0, 0x320uLL);
v0 = trielist;
if ( trielist )
{
v1 = 0LL;
do
{
v2 = v1;
v9[v1] = **(_DWORD **)v0;
v0 = *(_QWORD *)(v0 + 8);
++v1;
}
while ( v0 );
if ( v2 > 1 )
{
v3 = (int *)&v9[v2];
v4 = 0LL;
do
{
v5 = v9[v4];
v9[v4] = *v3;
*v3 = v5;
++v4;
--v3;
}
while ( v2 / 2 > (int)v4 );
}
}
else
{
v2 = -1;
}
curs_set(0);
if ( wmove(wordsList, 0, 0) != -1 )
wchgat(wordsList, -1, 0LL, 1, 0LL);
parserProcess(v9[0]);
werase(wordDetail);
func1();
prefresh(wordDetail, 0, 0, 3, 21, max_row - 2, max_col - 1);
wrefresh(wordsList);
v6 = 0;
v7 = 0;
while ( 2 )
{
switch ( wgetch(stdscr) )
{
case 258:
if ( wmove(wordsList, v7, 0) != -1 )
wchgat(wordsList, -1, 0LL, 2, 0LL);
if ( v7 >= v2 )
return curs_set(1);
++v7;
goto LABEL_16;
case 259:
if ( wmove(wordsList, v7, 0) != -1 )
wchgat(wordsList, -1, 0LL, 2, 0LL);
if ( v7 > 0 )
{
--v7;
LABEL_16:
v6 = 0;
LABEL_17:
if ( wmove(wordsList, v7, 0) != -1 )
wchgat(wordsList, -1, 0LL, 1, 0LL);
wrefresh(wordsList);
parserProcess(v9[v7]);
werase(wordDetail);
func1();
prefresh(wordDetail, v6, 0, 3, 21, max_row - 2, max_col - 1);
continue;
}
return curs_set(1);
case 260:
--v6;
goto LABEL_28;
case 261:
++v6;
LABEL_28:
prefresh(wordDetail, v6, 0, 3, 21, max_row - 2, max_col - 1);
continue;
case 265:
endwin();
exit(0);
default:
goto LABEL_17;
}
}
}

original_code:
void wordSelect() {
    int item = 0,i = 0, listlen, py = 0;
    int indexs[200];
    memset(indexs,0,sizeof(indexs));
    struct trieList *p = trielist;
    while(p) {
        indexs[i] = (p->key)->index;
        p = p->next;
        i++;
    }
    listlen = --i;
    for(int j = 0; j < i/2 ; j++) {
        int tmp = indexs[j];
        indexs[j] = indexs[i-j];
        indexs[i-j] = tmp;
    }
    curs_set(0);
    (wmove((wordsList),(0),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(1),(((void *)0))));
    parserProcess(indexs[item]);
    werase(wordDetail);
    printDetail();
    prefresh(wordDetail,0,0,3,21,max_row-2,max_col-1);
    wrefresh(wordsList);
    while(1) {
        int ch = wgetch(stdscr);
        _Bool flag = 0;
        switch(ch) {
            case (0410 +(1)) :
                endwin();
                exit(0);
            case 0403 :
                (wmove((wordsList),(item),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(2),(((void *)0))));
                if(item>0) item--;
                else {
                    curs_set(1);
                    return;
                }
                py = 0;
                break;
            case 0402 :
                (wmove((wordsList),(item),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(2),(((void *)0))));
                if(item < listlen) item++;
                else {
                    curs_set(1);
                    return;
                }
                py = 0;
                break;
            case 0404 :
                py--;
                flag = 1;
                break;
            case 0405 :
                py++;
                flag = 1;
                break;
        }
        if(flag) {
            prefresh(wordDetail,py,0,3,21,max_row-2,max_col-1);
            continue;
        }
        (wmove((wordsList),(item),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(1),(((void *)0))));
        wrefresh(wordsList);
        parserProcess(indexs[item]);
        werase(wordDetail);
        printDetail();
        prefresh(wordDetail,py,0,3,21,max_row-2,max_col-1);
    }
    curs_set(1);
}

canonical_original_code:
void wordSelect() {
    int item = 0; int i = 0; int listlen; int py = 0;
    int indexs[200];
    memset(indexs,0,sizeof(indexs));
    struct trieList *p = trielist;
    while(p) {
        indexs[i] = (p->key)->index;
        p = p->next;
        i++;
    }
    listlen = --i;
    for(int j = 0; j < i/2 ; j++) {
        int tmp = indexs[j];
        indexs[j] = indexs[i-j];
        indexs[i-j] = tmp;
    }
    curs_set(0);
    (wmove((wordsList),(0),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(1),(((void *)0))));
    parserProcess(indexs[item]);
    werase(wordDetail);
    printDetail();
    prefresh(wordDetail,0,0,3,21,max_row-2,max_col-1);
    wrefresh(wordsList);
    while(1) {
        int ch = wgetch(stdscr);
        _Bool flag = 0;
        switch(ch) {
            case (0410 +(1)) :
                endwin();
                exit(0);
            case 0403 :
                (wmove((wordsList),(item),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(2),(((void *)0))));
                if(item>0) item--;
                else {
                    curs_set(1);
                    return;
                }
                py = 0;
                break;
            case 0402 :
                (wmove((wordsList),(item),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(2),(((void *)0))));
                if(item < listlen) item++;
                else {
                    curs_set(1);
                    return;
                }
                py = 0;
                break;
            case 0404 :
                py--;
                flag = 1;
                break;
            case 0405 :
                py++;
                flag = 1;
                break;
        }
        if(flag) {
            prefresh(wordDetail,py,0,3,21,max_row-2,max_col-1);
            continue;
        }
        (wmove((wordsList),(item),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(1),(((void *)0))));
        wrefresh(wordsList);
        parserProcess(indexs[item]);
        werase(wordDetail);
        printDetail();
        prefresh(wordDetail,py,0,3,21,max_row-2,max_col-1);
    }
    curs_set(1);
}

variable_types: item int

variable_types: listlen int

variable_types: py int

variable_types:
indexs
int [200]

variable_types: struct trieList { struct trieNode { int index; char *word; struct trieNode *son[16]; } *key; struct trieList *next; } *

variable_types: tmp int

variable_types: ch int


printWords

decompiled_code:
int __fastcall printWords(_QWORD *a1)
{
int result; // eax

if ( a1 )
{
printWords(a1[1]);
result = mvwprintw(wordsList, printPos, 0, "%d %s", (unsigned int)printPos, *(const char **)(*a1 + 8LL));
++printPos;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(_QWORD *a1)
{
int result; // eax

if ( a1 )
{
func3(a1[1]);
result = mvwprintw(wordsList, printPos, 0, "%d %s", (unsigned int)printPos, *(const char **)(*a1 + 8LL));
++printPos;
}
return result;
}

original_code:
void printWords(struct trieList *tl) {
    if(tl==((void *)0)) {
        return;
    } else {
        printWords(tl->next);
        mvwprintw(wordsList,printPos,0,"%d %s",printPos,(tl->key)->word);
        printPos++;
    }
}


layoutProcess

decompiled_code:
void layoutProcess()
{
int v0; // er12
int v1; // ebp
__int64 v2; // rax
int v3; // ebx
__int64 v4; // rax

layoutInit();
memset(waitingWord, 0, sizeof(waitingWord));
v0 = 0;
v1 = 0;
while ( 1 )
{
v3 = wgetch(stdscr);
if ( v3 == 127 )
{
if ( v1 > 0 )
{
if ( v0 > --v1 )
{
v2 = v1;
do
{
waitingWord[v2] = waitingWord[v2 + 1];
++v2;
}
while ( v0 > (int)v2 );
}
waitingWord[--v0] = 0;
wclear(inputBox);
wclear(wordsList);
}
}
else if ( ((*_ctype_b_loc())[v3] & 0x4000) != 0 )
{
if ( v1 < v0 )
{
v4 = v0;
do
{
waitingWord[v4] = waitingWord[v4 - 1];
--v4;
}
while ( v1 < (int)v4 );
}
waitingWord[v1] = v3;
++v0;
++v1;
}
mvwprintw(inputBox, 0, 0, waitingWord);
lookupProcess(waitingWord);
werase(wordsList);
printPos = 0;
printWords(trielist);
wrefresh(wordsList);
wmove(inputBox, 0, v1);
wrefresh(inputBox);
}
}

canonical_decompiled_code:
void func4()
{
int v0; // er12
int v1; // ebp
__int64 v2; // rax
int v3; // ebx
__int64 v4; // rax

func0();
memset(waitingWord, 0, sizeof(waitingWord));
v0 = 0;
v1 = 0;
while ( 1 )
{
v3 = wgetch(stdscr);
if ( v3 == 127 )
{
if ( v1 > 0 )
{
if ( v0 > --v1 )
{
v2 = v1;
do
{
waitingWord[v2] = waitingWord[v2 + 1];
++v2;
}
while ( v0 > (int)v2 );
}
waitingWord[--v0] = 0;
wclear(inputBox);
wclear(wordsList);
}
}
else if ( ((*_ctype_b_loc())[v3] & 0x4000) != 0 )
{
if ( v1 < v0 )
{
v4 = v0;
do
{
waitingWord[v4] = waitingWord[v4 - 1];
--v4;
}
while ( v1 < (int)v4 );
}
waitingWord[v1] = v3;
++v0;
++v1;
}
mvwprintw(inputBox, 0, 0, waitingWord);
lookupProcess(waitingWord);
werase(wordsList);
printPos = 0;
func3(trielist);
wrefresh(wordsList);
wmove(inputBox, 0, v1);
wrefresh(inputBox);
}
}

original_code:
int layoutProcess() {
    layoutInit();
    int ch,p=0,len=0;
    memset(waitingWord,0,sizeof(waitingWord));
    while(1) {
        ch = wgetch(stdscr);
        switch(ch) {
            case (0410 +(1)) :
                endwin();
                return 0;
            case 0407 :
            case 127 :
                if(p>0) {
                    for(int i=p-1;i<len;i++) waitingWord[i]=waitingWord[i+1];
                    waitingWord[--len]='\0';
                    --p;
                    wclear(inputBox);
                    wclear(wordsList);
                }
                break;
            case 0404 :
                if(p>0) --p;
                break;
            case 0405 :
                if(p<len) ++p;
                break;
            case 0402 :
                wordSelect();
                break;
            case 0403 :
                break;
            default :
                if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISprint)) {
                    for(int i=len;i>p;i--) waitingWord[i]=waitingWord[i-1];
                    waitingWord[p]=ch;
                    len++;
                    p++;
                }
        }
        mvwprintw(inputBox,0,0,waitingWord);
        lookupProcess(waitingWord);
        werase(wordsList);
        printPos = 0;
        printWords(trielist);
        wrefresh(wordsList);
        wmove(inputBox,0,p);
        wrefresh(inputBox);
    }
    wgetch(stdscr);
    endwin();
    return 0;
}

canonical_original_code:
int layoutProcess() {
    layoutInit();
    int ch; int p = 0; int len = 0;
    memset(waitingWord,0,sizeof(waitingWord));
    while(1) {
        ch = wgetch(stdscr);
        switch(ch) {
            case (0410 +(1)) :
                endwin();
                return 0;
            case 0407 :
            case 127 :
                if(p>0) {
                    for(int i = p-1;i<len;i++) waitingWord[i]=waitingWord[i+1];
                    waitingWord[--len]='\0';
                    --p;
                    wclear(inputBox);
                    wclear(wordsList);
                }
                break;
            case 0404 :
                if(p>0) --p;
                break;
            case 0405 :
                if(p<len) ++p;
                break;
            case 0402 :
                wordSelect();
                break;
            case 0403 :
                break;
            default :
                if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISprint)) {
                    for(int i = len;i>p;i--) waitingWord[i]=waitingWord[i-1];
                    waitingWord[p]=ch;
                    len++;
                    p++;
                }
        }
        mvwprintw(inputBox,0,0,waitingWord);
        lookupProcess(waitingWord);
        werase(wordsList);
        printPos = 0;
        printWords(trielist);
        wrefresh(wordsList);
        wmove(inputBox,0,p);
        wrefresh(inputBox);
    }
    wgetch(stdscr);
    endwin();
    return 0;
}

variable_types: p int

variable_types: len int


parser

original_code:
int parser(char *str, int i) {
    while (i < (int) strlen(str)) {
        if(str[i]=='\\') i+=2;
        else if(str[i]=='<') {
            i++;
            if(str[i]=='/') {
                struct expTreeNode *node = (struct expTreeNode *) malloc(sizeof(struct expTreeNode));
                node->data = ((void *)0);
                node->name[0] = '/';node->name[1] = str[i+1];node->name[2] = str[i+2];node->name[3] = '\0';
                expNodeList[expNodetop++] = node;
                return i+3;
            } else {
                struct expTreeNode *node = (struct expTreeNode *) malloc(sizeof(struct expTreeNode));
                node->name[0] = str[i];node->name[1] = str[i+1];node->name[2] = '\0';
                node->data = ((void *)0);
                expNodeList[expNodetop++] = node;
                i+=3;
                if(str[i]=='<' && str[i+1]=='!') {
                    i++;
                    i+=8;
                    char *tmpHead = str+i,*tmpTail = str+i;
                    while(*tmpTail != '>') tmpTail++;
                    int len = tmpTail - tmpHead - 2;
                    node->data = (char *) malloc(sizeof(char)*len);
                    strncpy(node->data,tmpHead,len);
                    i+=len+7;
                } else {
                    i = parser(str,i);
                }
            }
        }
        i++;
    }
    return i;
}

canonical_original_code:
int parser(char *str, int i) {
    while (i < (int) strlen(str)) {
        if(str[i]=='\\') i+=2;
        else if(str[i]=='<') {
            i++;
            if(str[i]=='/') {
                struct expTreeNode *node = (struct expTreeNode *) malloc(sizeof(struct expTreeNode));
                node->data = ((void *)0);
                node->name[0] = '/';node->name[1] = str[i+1];node->name[2] = str[i+2];node->name[3] = '\0';
                expNodeList[expNodetop++] = node;
                return i+3;
            } else {
                struct expTreeNode *node = (struct expTreeNode *) malloc(sizeof(struct expTreeNode));
                node->name[0] = str[i];node->name[1] = str[i+1];node->name[2] = '\0';
                node->data = ((void *)0);
                expNodeList[expNodetop++] = node;
                i+=3;
                if(str[i]=='<' && str[i+1]=='!') {
                    i++;
                    i+=8;
                    char *tmpHead = str+i; char *tmpTail = str+i;
                    while(*tmpTail != '>') tmpTail++;
                    int len = tmpTail - tmpHead - 2;
                    node->data = (char *) malloc(sizeof(char)*len);
                    strncpy(node->data,tmpHead,len);
                    i+=len+7;
                } else {
                    i = parser(str,i);
                }
            }
        }
        i++;
    }
    return i;
}

variable_types: struct expTreeNode { char name[4]; char *data; } *

variable_types:
tmpHead
char *

variable_types:
tmpTail
char *


repo: poltak/Coursework

decompiled_code:
char *__fastcall get_filename(char *s, _DWORD *a2)
{
char *v2; // rbx
char *v3; // rbp
__int64 v4; // rdx

v2 = (char *)malloc(0x100uLL);
strcpy(v2, s);
*(_WORD *)&v2[strlen(v2)] = 45;
v3 = &v2[strlen(s) + 1];
v4 = (unsigned int)(*a2 + 1);
*a2 = v4;
sprintf(v3, "%04u", v4);
strcpy(&v3[strlen(v3)], ".ppm");
return v2;
}

canonical_decompiled_code:
char *__fastcall func9(char *s, _DWORD *a2)
{
char *v2; // rbx
char *v3; // rbp
__int64 v4; // rdx

v2 = (char *)malloc(0x100uLL);
strcpy(v2, s);
*(_WORD *)&v2[strlen(v2)] = 45;
v3 = &v2[strlen(s) + 1];
v4 = (unsigned int)(*a2 + 1);
*a2 = v4;
sprintf(v3, "%04u", v4);
strcpy(&v3[strlen(v3)], ".ppm");
return v2;
}

original_code:
static char *get_filename(char *ppm_prefix, unsigned int *ppm_count)
{
 char *filename = (char *) malloc(255 +1);
 strcpy(filename, ppm_prefix);
 strcat(filename, "-");
 char *filename_end = &filename[strlen(ppm_prefix)] +1;
 sprintf(filename_end, "%04u", ++(*ppm_count));
 strcat(filename_end, ".ppm");
    return filename;
}

variable_types:
filename
char *

return_type: char *