decompiled_code:
__int64 __fastcall pp_disabled(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 1000;
return 0LL;
}

original_code:
int pp_disabled(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
 ppi->next_delay = 1000;
 return 0;
}

variable_types: struct pp_instance { int state; int next_state; void *arch_data; void *ext_data; unsigned long flags; struct pp_globals { struct pp_instance *pp_instances; struct pp_servo { struct TimeInternal { int seconds; int nanoseconds; int phase; int correct; int raw_ahead; } m_to_s_dly; struct TimeInternal s_to_m_dly; struct TimeInternal delay_ms; struct TimeInternal delay_sm; int obs_drift; struct pp_owd_fltr { int nsec_prev; int y; int s_exp; } owd_fltr; struct pp_ofm_fltr { int nsec_prev; int y; } ofm_fltr; } *servo; struct pp_runtime_opts { struct ClockQuality { unsigned char clockClass; unsigned char clockAccuracy; unsigned short offsetScaledLogVariance; } clock_quality; struct TimeInternal inbound_latency; int max_rst; int max_dly; int ttl; unsigned int no_adjust; short ap; short s; char announce_intvl; char sync_intvl; unsigned char prio1; unsigned char prio2; unsigned char domain_number; void *arch_opts; } *rt_opts; struct DSDefault { enum Boolean { FALSE=0, TRUE=1 } twoStepFlag; struct ClockIdentity { unsigned char id[8]; } clockIdentity; unsigned short numberPorts; struct ClockQuality clockQuality; unsigned char priority1; unsigned char priority2; unsigned char domainNumber; enum Boolean { FALSE=0, TRUE=1 } slaveOnly; } *defaultDS; struct DSCurrent { unsigned short stepsRemoved; struct TimeInternal offsetFromMaster; struct TimeInternal meanPathDelay; unsigned short primarySlavePortNumber; } *currentDS; struct DSParent { struct PortIdentity { struct ClockIdentity clockIdentity; unsigned short portNumber; } parentPortIdentity; unsigned short observedParentOffsetScaledLogVariance; int observedParentClockPhaseChangeRate; struct ClockIdentity grandmasterIdentity; struct ClockQuality grandmasterClockQuality; unsigned char grandmasterPriority1; unsigned char grandmasterPriority2; } *parentDS; struct DSTimeProperties { short currentUtcOffset; enum Boolean { FALSE=0, TRUE=1 } currentUtcOffsetValid; enum Boolean { FALSE=0, TRUE=1 } leap59; enum Boolean { FALSE=0, TRUE=1 } leap61; enum Boolean { FALSE=0, TRUE=1 } timeTraceable; enum Boolean { FALSE=0, TRUE=1 } frequencyTraceable; enum Boolean { FALSE=0, TRUE=1 } ptpTimescale; unsigned char timeSource; } *timePropertiesDS; int ebest_idx; int ebest_updated; int nlinks; int max_links; struct pp_link { char link_name[16]; char iface_name[16]; int proto; int role; int ext; } *links; void *arch_data; } *glbs; struct pp_network_operations { int (*init)(struct pp_instance *ppi); int (*exit)(struct pp_instance *ppi); int (*recv)(struct pp_instance *ppi, void *pkt, int len, struct TimeInternal *t); int (*send)(struct pp_instance *ppi, void *pkt, int len, struct TimeInternal *t, int chtype, int use_pdelay_addr); } *n_ops; struct pp_time_operations { int (*get)(struct pp_instance *ppi, struct TimeInternal *t); int (*set)(struct pp_instance *ppi, struct TimeInternal *t); int (*adjust)(struct pp_instance *ppi, long offset_ns, long freq_ppm); int (*adjust_offset)(struct pp_instance *ppi, long offset_ns); int (*adjust_freq)(struct pp_instance *ppi, long freq_ppm); unsigned long (*calc_timeout)(struct pp_instance *ppi, int millisec); } *t_ops; unsigned char tx_buffer[200]; unsigned char rx_buffer[200]; void *tx_frame; struct pp_net_path { struct pp_channel { union { int fd; void *custom; }; void *arch_data; unsigned char addr[6]; unsigned char peer[6]; int pkt_present; } ch[-1]; int mcast_addr; int ptp_offset; } np; struct TimeInternal t1; struct TimeInternal cField; struct TimeInternal last_rcv_time; unsigned short frgn_rec_num; short frgn_rec_i; short frgn_rec_best; struct pp_frgn_master { struct PortIdentity port_id; struct MsgAnnounce { struct Timestamp { struct UInteger48 { unsigned int lsb; unsigned short msb; } secondsField; unsigned int nanosecondsField; } originTimestamp; short currentUtcOffset; unsigned char grandmasterPriority1; struct ClockQuality grandmasterClockQuality; unsigned char grandmasterPriority2; struct ClockIdentity grandmasterIdentity; unsigned short stepsRemoved; unsigned char timeSource; unsigned long ext_specific; } ann; struct MsgHeader { unsigned char transportSpecific; unsigned char messageType; unsigned char versionPTP; unsigned short messageLength; unsigned char domainNumber; unsigned char flagField[2]; struct Integer64 { unsigned int lsb; int msb; } correctionfield; struct PortIdentity sourcePortIdentity; unsigned short sequenceId; unsigned char controlField; char logMessageInterval; } hdr; } frgn_master[5]; struct DSPort { struct PortIdentity portIdentity; char logMinDelayReqInterval; char logAnnounceInterval; unsigned char announceReceiptTimeout; char logSyncInterval; unsigned char versionNumber; void *ext_dsport; } *portDS; unsigned long timeouts[-1]; unsigned short recv_sync_sequence_id; char log_min_delay_req_interval; unsigned short sent_seq[-1]; struct MsgHeader received_ptp_header; struct MsgHeader delay_req_hdr; unsigned int is_from_cur_par; char *iface_name; int port_idx; } *

variable_types:
pkt
unsigned char *

variable_types: plen int

user_defined_types: struct pp_net_path { struct pp_channel ch[-1]; int mcast_addr; int ptp_offset; }

user_defined_types: struct pp_globals { struct pp_instance *pp_instances; struct pp_servo *servo; struct pp_runtime_opts *rt_opts; struct DSDefault *defaultDS; struct DSCurrent *currentDS; struct DSParent *parentDS; struct DSTimeProperties *timePropertiesDS; int ebest_idx; int ebest_updated; int nlinks; int max_links; struct pp_link *links; void *arch_data; }

user_defined_types: struct pp_frgn_master { struct PortIdentity port_id; struct MsgAnnounce ann; struct MsgHeader hdr; }

user_defined_types: struct MsgHeader { unsigned char transportSpecific; unsigned char messageType; unsigned char versionPTP; unsigned short messageLength; unsigned char domainNumber; unsigned char flagField[2]; struct Integer64 correctionfield; struct PortIdentity sourcePortIdentity; unsigned short sequenceId; unsigned char controlField; char logMessageInterval; }

user_defined_types: struct pp_runtime_opts { struct ClockQuality clock_quality; struct TimeInternal inbound_latency; int max_rst; int max_dly; int ttl; unsigned int no_adjust; short ap; short s; char announce_intvl; char sync_intvl; unsigned char prio1; unsigned char prio2; unsigned char domain_number; void *arch_opts; }

user_defined_types: struct DSDefault { enum Boolean twoStepFlag; struct ClockIdentity clockIdentity; unsigned short numberPorts; struct ClockQuality clockQuality; unsigned char priority1; unsigned char priority2; unsigned char domainNumber; enum Boolean slaveOnly; }

user_defined_types: struct DSParent { struct PortIdentity parentPortIdentity; unsigned short observedParentOffsetScaledLogVariance; int observedParentClockPhaseChangeRate; struct ClockIdentity grandmasterIdentity; struct ClockQuality grandmasterClockQuality; unsigned char grandmasterPriority1; unsigned char grandmasterPriority2; }

user_defined_types: struct Timestamp { struct UInteger48 secondsField; unsigned int nanosecondsField; }


repo: tinito/ppsi-chibios

original_code:
int pp_open_globals(struct pp_globals *ppg)
{
 int i;
 struct DSDefault *def = ppg->defaultDS;
 def->twoStepFlag = TRUE;
 def->numberPorts = ppg->nlinks > 0 ? ppg->nlinks : 1;
 struct pp_runtime_opts *rt_opts;
 if (!ppg->rt_opts)
  ppg->rt_opts = &default_rt_opts;
 rt_opts = ppg->rt_opts;
 memcpy(&def->clockQuality, &rt_opts->clock_quality,
     sizeof(ClockQuality));
 if (def->numberPorts == 1)
  def->slaveOnly = ppg->pp_instances[0].slave_only;
 else
  def->slaveOnly = 1;
 def->priority1 = rt_opts->prio1;
 def->priority2 = rt_opts->prio2;
 def->domainNumber = rt_opts->domain_number;
 for (i = 0; i < def->numberPorts; i++) {
  if (def->slaveOnly && !ppg->pp_instances[i].slave_only)
   def->slaveOnly = 0;
  ppg->pp_instances[i].state = PPS_INITIALIZING;
  ppg->pp_instances[i].port_idx = i;
 }
 if (def->slaveOnly) {
  pp_printf("Slave Only, clock class set to 255\n");
  def->clockQuality.clockClass = 255;
 }
 if (pp_hooks.open)
  return pp_hooks.open(ppg, rt_opts);
 return 0;
}

variable_types: struct pp_globals { struct pp_instance { int state; int next_state; void *arch_data; void *ext_data; unsigned long flags; struct pp_globals *glbs; struct pp_network_operations { int (*init)(struct pp_instance *ppi); int (*exit)(struct pp_instance *ppi); int (*recv)(struct pp_instance *ppi, void *pkt, int len, struct TimeInternal { int seconds; int nanoseconds; int phase; int correct; int raw_ahead; } *t); int (*send)(struct pp_instance *ppi, void *pkt, int len, struct TimeInternal *t, int chtype, int use_pdelay_addr); } *n_ops; struct pp_time_operations { int (*get)(struct pp_instance *ppi, struct TimeInternal *t); int (*set)(struct pp_instance *ppi, struct TimeInternal *t); int (*adjust)(struct pp_instance *ppi, long offset_ns, long freq_ppm); int (*adjust_offset)(struct pp_instance *ppi, long offset_ns); int (*adjust_freq)(struct pp_instance *ppi, long freq_ppm); unsigned long (*calc_timeout)(struct pp_instance *ppi, int millisec); } *t_ops; unsigned char tx_buffer[200]; unsigned char rx_buffer[200]; void *tx_frame; struct pp_net_path { struct pp_channel { union { int fd; void *custom; }; void *arch_data; unsigned char addr[6]; unsigned char peer[6]; int pkt_present; } ch[-1]; int mcast_addr; int ptp_offset; } np; struct TimeInternal t1; struct TimeInternal cField; struct TimeInternal last_rcv_time; unsigned short frgn_rec_num; short frgn_rec_i; short frgn_rec_best; struct pp_frgn_master { struct PortIdentity { struct ClockIdentity { unsigned char id[8]; } clockIdentity; unsigned short portNumber; } port_id; struct MsgAnnounce { struct Timestamp { struct UInteger48 { unsigned int lsb; unsigned short msb; } secondsField; unsigned int nanosecondsField; } originTimestamp; short currentUtcOffset; unsigned char grandmasterPriority1; struct ClockQuality { unsigned char clockClass; unsigned char clockAccuracy; unsigned short offsetScaledLogVariance; } grandmasterClockQuality; unsigned char grandmasterPriority2; struct ClockIdentity grandmasterIdentity; unsigned short stepsRemoved; unsigned char timeSource; unsigned long ext_specific; } ann; struct MsgHeader { unsigned char transportSpecific; unsigned char messageType; unsigned char versionPTP; unsigned short messageLength; unsigned char domainNumber; unsigned char flagField[2]; struct Integer64 { unsigned int lsb; int msb; } correctionfield; struct PortIdentity sourcePortIdentity; unsigned short sequenceId; unsigned char controlField; char logMessageInterval; } hdr; } frgn_master[5]; struct DSPort { struct PortIdentity portIdentity; char logMinDelayReqInterval; char logAnnounceInterval; unsigned char announceReceiptTimeout; char logSyncInterval; unsigned char versionNumber; void *ext_dsport; } *portDS; unsigned long timeouts[-1]; unsigned short recv_sync_sequence_id; char log_min_delay_req_interval; unsigned short sent_seq[-1]; struct MsgHeader received_ptp_header; struct MsgHeader delay_req_hdr; unsigned int is_from_cur_par; char *iface_name; int port_idx; } *pp_instances; struct pp_servo { struct TimeInternal m_to_s_dly; struct TimeInternal s_to_m_dly; struct TimeInternal delay_ms; struct TimeInternal delay_sm; int obs_drift; struct pp_owd_fltr { int nsec_prev; int y; int s_exp; } owd_fltr; struct pp_ofm_fltr { int nsec_prev; int y; } ofm_fltr; } *servo; struct pp_runtime_opts { struct ClockQuality clock_quality; struct TimeInternal inbound_latency; int max_rst; int max_dly; int ttl; unsigned int no_adjust; short ap; short s; char announce_intvl; char sync_intvl; unsigned char prio1; unsigned char prio2; unsigned char domain_number; void *arch_opts; } *rt_opts; struct DSDefault { enum Boolean { FALSE=0, TRUE=1 } twoStepFlag; struct ClockIdentity clockIdentity; unsigned short numberPorts; struct ClockQuality clockQuality; unsigned char priority1; unsigned char priority2; unsigned char domainNumber; enum Boolean { FALSE=0, TRUE=1 } slaveOnly; } *defaultDS; struct DSCurrent { unsigned short stepsRemoved; struct TimeInternal offsetFromMaster; struct TimeInternal meanPathDelay; unsigned short primarySlavePortNumber; } *currentDS; struct DSParent { struct PortIdentity parentPortIdentity; unsigned short observedParentOffsetScaledLogVariance; int observedParentClockPhaseChangeRate; struct ClockIdentity grandmasterIdentity; struct ClockQuality grandmasterClockQuality; unsigned char grandmasterPriority1; unsigned char grandmasterPriority2; } *parentDS; struct DSTimeProperties { short currentUtcOffset; enum Boolean { FALSE=0, TRUE=1 } currentUtcOffsetValid; enum Boolean { FALSE=0, TRUE=1 } leap59; enum Boolean { FALSE=0, TRUE=1 } leap61; enum Boolean { FALSE=0, TRUE=1 } timeTraceable; enum Boolean { FALSE=0, TRUE=1 } frequencyTraceable; enum Boolean { FALSE=0, TRUE=1 } ptpTimescale; unsigned char timeSource; } *timePropertiesDS; int ebest_idx; int ebest_updated; int nlinks; int max_links; struct pp_link { char link_name[16]; char iface_name[16]; int proto; int role; int ext; } *links; void *arch_data; } *

variable_types: i int

variable_types: struct DSDefault { enum Boolean { FALSE=0, TRUE=1 } twoStepFlag; struct ClockIdentity { unsigned char id[8]; } clockIdentity; unsigned short numberPorts; struct ClockQuality { unsigned char clockClass; unsigned char clockAccuracy; unsigned short offsetScaledLogVariance; } clockQuality; unsigned char priority1; unsigned char priority2; unsigned char domainNumber; enum Boolean { FALSE=0, TRUE=1 } slaveOnly; } *

variable_types: struct pp_runtime_opts { struct ClockQuality { unsigned char clockClass; unsigned char clockAccuracy; unsigned short offsetScaledLogVariance; } clock_quality; struct TimeInternal { int seconds; int nanoseconds; int phase; int correct; int raw_ahead; } inbound_latency; int max_rst; int max_dly; int ttl; unsigned int no_adjust; short ap; short s; char announce_intvl; char sync_intvl; unsigned char prio1; unsigned char prio2; unsigned char domain_number; void *arch_opts; } *

return_type: int

user_defined_types: struct pp_instance { int state; int next_state; void *arch_data; void *ext_data; unsigned long flags; struct pp_globals *glbs; struct pp_network_operations *n_ops; struct pp_time_operations *t_ops; unsigned char tx_buffer[200]; unsigned char rx_buffer[200]; void *tx_frame; struct pp_net_path np; struct TimeInternal t1; struct TimeInternal cField; struct TimeInternal last_rcv_time; unsigned short frgn_rec_num; short frgn_rec_i; short frgn_rec_best; struct pp_frgn_master frgn_master[5]; struct DSPort *portDS; unsigned long timeouts[-1]; unsigned short recv_sync_sequence_id; char log_min_delay_req_interval; unsigned short sent_seq[-1]; struct MsgHeader received_ptp_header; struct MsgHeader delay_req_hdr; unsigned int is_from_cur_par; char *iface_name; int port_idx; }

user_defined_types: struct pp_servo { struct TimeInternal m_to_s_dly; struct TimeInternal s_to_m_dly; struct TimeInternal delay_ms; struct TimeInternal delay_sm; int obs_drift; struct pp_owd_fltr owd_fltr; struct pp_ofm_fltr ofm_fltr; }

user_defined_types: struct DSTimeProperties { short currentUtcOffset; enum Boolean currentUtcOffsetValid; enum Boolean leap59; enum Boolean leap61; enum Boolean timeTraceable; enum Boolean frequencyTraceable; enum Boolean ptpTimescale; unsigned char timeSource; }

user_defined_types: struct pp_network_operations { int (*init)(struct pp_instance *ppi); int (*exit)(struct pp_instance *ppi); int (*recv)(struct pp_instance *ppi, void *pkt, int len, struct TimeInternal *t); int (*send)(struct pp_instance *ppi, void *pkt, int len, struct TimeInternal *t, int chtype, int use_pdelay_addr); }

user_defined_types: struct PortIdentity { struct ClockIdentity clockIdentity; unsigned short portNumber; }

user_defined_types: struct MsgAnnounce { struct Timestamp originTimestamp; short currentUtcOffset; unsigned char grandmasterPriority1; struct ClockQuality grandmasterClockQuality; unsigned char grandmasterPriority2; struct ClockIdentity grandmasterIdentity; unsigned short stepsRemoved; unsigned char timeSource; unsigned long ext_specific; }


decompiled_code:
__int64 pp_close_globals()
{
__int64 (*v0)(void); // rax
__int64 result; // rax

v0 = (__int64 (*)(void))pp_hooks[2];
if ( v0 )
result = v0();
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 (*v0)(void); // rax
__int64 result; // rax

v0 = (__int64 (*)(void))pp_hooks[2];
if ( v0 )
result = v0();
else
result = 0LL;
return result;
}

original_code:
int pp_close_globals(struct pp_globals *ppg)
{
 if (pp_hooks.close)
  return pp_hooks.close(ppg);
 return 0;
}

user_defined_types: struct DSCurrent { unsigned short stepsRemoved; struct TimeInternal offsetFromMaster; struct TimeInternal meanPathDelay; unsigned short primarySlavePortNumber; }

user_defined_types: struct pp_link { char link_name[16]; char iface_name[16]; int proto; int role; int ext; }

user_defined_types: struct pp_owd_fltr { int nsec_prev; int y; int s_exp; }

user_defined_types: struct pp_ofm_fltr { int nsec_prev; int y; }

user_defined_types: struct pp_time_operations { int (*get)(struct pp_instance *ppi, struct TimeInternal *t); int (*set)(struct pp_instance *ppi, struct TimeInternal *t); int (*adjust)(struct pp_instance *ppi, long offset_ns, long freq_ppm); int (*adjust_offset)(struct pp_instance *ppi, long offset_ns); int (*adjust_freq)(struct pp_instance *ppi, long freq_ppm); unsigned long (*calc_timeout)(struct pp_instance *ppi, int millisec); }

user_defined_types: struct DSPort { struct PortIdentity portIdentity; char logMinDelayReqInterval; char logAnnounceInterval; unsigned char announceReceiptTimeout; char logSyncInterval; unsigned char versionNumber; void *ext_dsport; }

user_defined_types: struct pp_channel { union { int fd; void *custom; }; void *arch_data; unsigned char addr[6]; unsigned char peer[6]; int pkt_present; }

user_defined_types: struct ClockIdentity { unsigned char id[8]; }

user_defined_types: struct ClockQuality { unsigned char clockClass; unsigned char clockAccuracy; unsigned short offsetScaledLogVariance; }

user_defined_types: struct Integer64 { unsigned int lsb; int msb; }

user_defined_types: struct UInteger48 { unsigned int lsb; unsigned short msb; }

user_defined_types: struct TimeInternal { int seconds; int nanoseconds; int phase; int correct; int raw_ahead; }


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

DSPOR_isra_0(*(_QWORD *)(a1 + 1240));
return pp_timeout_set_constprop_0(v1);
}

original_code:
static inline void pp_timeout_restart_annrec(struct pp_instance *ppi)
{
 pp_timeout_set(ppi, PP_TO_ANN_RECEIPT,
         ((DSPOR(ppi)->announceReceiptTimeout) <<
   DSPOR(ppi)->logAnnounceInterval) * 1000);
}

return_type: void

user_defined_types: struct pp_instance { int state; int next_state; void *arch_data; void *ext_data; unsigned long flags; struct pp_globals *glbs; struct pp_network_operations *n_ops; struct pp_time_operations *t_ops; unsigned char tx_buffer[200]; unsigned char rx_buffer[200]; void *tx_frame; struct pp_net_path np; struct TimeInternal t1; struct TimeInternal cField; struct TimeInternal last_rcv_time; unsigned short frgn_rec_num; short frgn_rec_i; short frgn_rec_best; struct pp_frgn_master frgn_master[5]; struct DSPort *portDS; unsigned long timeouts[-1]; unsigned short recv_sync_sequence_id; char log_min_delay_req_interval; unsigned short sent_seq[-1]; struct MsgHeader received_ptp_header; struct MsgHeader delay_req_hdr; unsigned int is_from_cur_par; char *iface_name; int port_idx; }

user_defined_types: struct pp_net_path { struct pp_channel ch[-1]; int mcast_addr; int ptp_offset; }

user_defined_types: struct pp_globals { struct pp_instance *pp_instances; struct pp_servo *servo; struct pp_runtime_opts *rt_opts; struct DSDefault *defaultDS; struct DSCurrent *currentDS; struct DSParent *parentDS; struct DSTimeProperties *timePropertiesDS; int ebest_idx; int ebest_updated; int nlinks; int max_links; struct pp_link *links; void *arch_data; }

user_defined_types: struct pp_frgn_master { struct PortIdentity port_id; struct MsgAnnounce ann; struct MsgHeader hdr; }

user_defined_types: struct MsgHeader { unsigned char transportSpecific; unsigned char messageType; unsigned char versionPTP; unsigned short messageLength; unsigned char domainNumber; unsigned char flagField[2]; struct Integer64 correctionfield; struct PortIdentity sourcePortIdentity; unsigned short sequenceId; unsigned char controlField; char logMessageInterval; }

user_defined_types: struct pp_servo { struct TimeInternal m_to_s_dly; struct TimeInternal s_to_m_dly; struct TimeInternal delay_ms; struct TimeInternal delay_sm; int obs_drift; struct pp_owd_fltr owd_fltr; struct pp_ofm_fltr ofm_fltr; }

user_defined_types: struct pp_runtime_opts { struct ClockQuality clock_quality; struct TimeInternal inbound_latency; int max_rst; int max_dly; int ttl; unsigned int no_adjust; short ap; short s; char announce_intvl; char sync_intvl; unsigned char prio1; unsigned char prio2; unsigned char domain_number; void *arch_opts; }

user_defined_types: struct DSDefault { enum Boolean twoStepFlag; struct ClockIdentity clockIdentity; unsigned short numberPorts; struct ClockQuality clockQuality; unsigned char priority1; unsigned char priority2; unsigned char domainNumber; enum Boolean slaveOnly; }

user_defined_types: struct DSParent { struct PortIdentity parentPortIdentity; unsigned short observedParentOffsetScaledLogVariance; int observedParentClockPhaseChangeRate; struct ClockIdentity grandmasterIdentity; struct ClockQuality grandmasterClockQuality; unsigned char grandmasterPriority1; unsigned char grandmasterPriority2; }

user_defined_types: struct Timestamp { struct UInteger48 secondsField; unsigned int nanosecondsField; }


decompiled_code:
__int64 __fastcall pp_listening(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int (*v3)(void); // rax
char v5; // al
int v6; // eax
int v8; // eax

v3 = (unsigned int (*)(void))pp_hooks[3];
if ( v3 && v3() )
goto LABEL_15;
if ( *(_DWORD *)(a1 + 12) )
pp_timeout_restart_annrec(a1);
if ( !a3 )
goto LABEL_8;
v5 = *(_BYTE *)(a1 + 1345);
if ( !v5 )
{
v8 = st_com_master_handle_sync(a1, a2, a3);
LABEL_14:
if ( v8 )
goto LABEL_15;
goto LABEL_8;
}
if ( v5 == 11 )
{
v8 = st_com_master_handle_announce(a1, a2, a3);
goto LABEL_14;
}
LABEL_8:
if ( !(unsigned int)st_com_execute_slave(a1) )
{
v6 = *(_DWORD *)(a1 + 4);
goto LABEL_10;
}
LABEL_15:
*(_DWORD *)(a1 + 4) = 2;
v6 = 2;
LABEL_10:
if ( *(_DWORD *)a1 != v6 )
pp_timeout_clr_constprop_0(a1);
*(_DWORD *)(a1 + 8) = pp_ms_to_timeout_constprop_0(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int (*v3)(void); // rax
char v5; // al
int v6; // eax
int v8; // eax

v3 = (unsigned int (*)(void))pp_hooks[3];
if ( v3 && v3() )
goto LABEL_15;
if ( *(_DWORD *)(a1 + 12) )
func4(a1);
if ( !a3 )
goto LABEL_8;
v5 = *(_BYTE *)(a1 + 1345);
if ( !v5 )
{
v8 = st_com_master_handle_sync(a1, a2, a3);
LABEL_14:
if ( v8 )
goto LABEL_15;
goto LABEL_8;
}
if ( v5 == 11 )
{
v8 = st_com_master_handle_announce(a1, a2, a3);
goto LABEL_14;
}
LABEL_8:
if ( !(unsigned int)st_com_execute_slave(a1) )
{
v6 = *(_DWORD *)(a1 + 4);
goto LABEL_10;
}
LABEL_15:
*(_DWORD *)(a1 + 4) = 2;
v6 = 2;
LABEL_10:
if ( *(_DWORD *)a1 != v6 )
func1(a1);
*(_DWORD *)(a1 + 8) = func0(a1);
return 0LL;
}

original_code:
int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
 int e = 0;
 if (pp_hooks.listening)
  e = pp_hooks.listening(ppi, pkt, plen);
 if (e)
  goto out;
 if (ppi->is_new_state)
  pp_timeout_restart_annrec(ppi);
 if (plen == 0)
  goto out;
 switch (ppi->received_ptp_header.messageType) {
 case PPM_ANNOUNCE:
  e = st_com_master_handle_announce(ppi, pkt, plen);
  break;
 case PPM_SYNC:
  e = st_com_master_handle_sync(ppi, pkt, plen);
  break;
 default:
  break;
 }
out:
 if (e == 0)
  e = st_com_execute_slave(ppi);
 if (e != 0)
  ppi->next_state = PPS_FAULTY;
 if (ppi->next_state != ppi->state)
  pp_timeout_clr(ppi, PP_TO_ANN_RECEIPT);
 ppi->next_delay = pp_ms_to_timeout(ppi, PP_TO_ANN_RECEIPT);
 return 0;
}

variable_types: e int

user_defined_types: struct pp_network_operations { int (*init)(struct pp_instance *ppi); int (*exit)(struct pp_instance *ppi); int (*recv)(struct pp_instance *ppi, void *pkt, int len, struct TimeInternal *t); int (*send)(struct pp_instance *ppi, void *pkt, int len, struct TimeInternal *t, int chtype, int use_pdelay_addr); }

user_defined_types: struct pp_time_operations { int (*get)(struct pp_instance *ppi, struct TimeInternal *t); int (*set)(struct pp_instance *ppi, struct TimeInternal *t); int (*adjust)(struct pp_instance *ppi, long offset_ns, long freq_ppm); int (*adjust_offset)(struct pp_instance *ppi, long offset_ns); int (*adjust_freq)(struct pp_instance *ppi, long freq_ppm); unsigned long (*calc_timeout)(struct pp_instance *ppi, int millisec); }

user_defined_types: struct DSPort { struct PortIdentity portIdentity; char logMinDelayReqInterval; char logAnnounceInterval; unsigned char announceReceiptTimeout; char logSyncInterval; unsigned char versionNumber; void *ext_dsport; }

user_defined_types: struct MsgAnnounce { struct Timestamp originTimestamp; short currentUtcOffset; unsigned char grandmasterPriority1; struct ClockQuality grandmasterClockQuality; unsigned char grandmasterPriority2; struct ClockIdentity grandmasterIdentity; unsigned short stepsRemoved; unsigned char timeSource; unsigned long ext_specific; }

user_defined_types: struct DSCurrent { unsigned short stepsRemoved; struct TimeInternal offsetFromMaster; struct TimeInternal meanPathDelay; unsigned short primarySlavePortNumber; }

user_defined_types: struct DSTimeProperties { short currentUtcOffset; enum Boolean currentUtcOffsetValid; enum Boolean leap59; enum Boolean leap61; enum Boolean timeTraceable; enum Boolean frequencyTraceable; enum Boolean ptpTimescale; unsigned char timeSource; }

user_defined_types: struct pp_link { char link_name[16]; char iface_name[16]; int proto; int role; int ext; }

user_defined_types: struct pp_owd_fltr { int nsec_prev; int y; int s_exp; }

user_defined_types: struct pp_ofm_fltr { int nsec_prev; int y; }

user_defined_types: struct PortIdentity { struct ClockIdentity clockIdentity; unsigned short portNumber; }


canonical_original_code:
static inline void pp_timeout_restart_annrec(struct pp_instance *ppi)
{
 pp_timeout_set(ppi, PP_TO_ANN_RECEIPT,
         ((DSPOR(ppi)->announceReceiptTimeout) <<
   DSPOR(ppi)->logAnnounceInterval) * 1000);
}

user_defined_types: struct pp_instance { int state; int next_state; void *arch_data; void *ext_data; unsigned long flags; struct pp_globals *glbs; struct pp_network_operations *n_ops; struct pp_time_operations *t_ops; unsigned char tx_buffer[200]; unsigned char rx_buffer[200]; void *tx_frame; struct pp_net_path np; struct TimeInternal t1; struct TimeInternal cField; struct TimeInternal last_rcv_time; unsigned short frgn_rec_num; short frgn_rec_i; short frgn_rec_best; struct pp_frgn_master frgn_master[5]; struct DSPort *portDS; unsigned long timeouts[-1]; unsigned short recv_sync_sequence_id; char log_min_delay_req_interval; unsigned short sent_seq[-1]; struct MsgHeader received_ptp_header; struct MsgHeader delay_req_hdr; unsigned int is_from_cur_par; char *iface_name; int port_idx; }

user_defined_types: struct pp_net_path { struct pp_channel ch[-1]; int mcast_addr; int ptp_offset; }

user_defined_types: struct pp_globals { struct pp_instance *pp_instances; struct pp_servo *servo; struct pp_runtime_opts *rt_opts; struct DSDefault *defaultDS; struct DSCurrent *currentDS; struct DSParent *parentDS; struct DSTimeProperties *timePropertiesDS; int ebest_idx; int ebest_updated; int nlinks; int max_links; struct pp_link *links; void *arch_data; }

user_defined_types: struct pp_frgn_master { struct PortIdentity port_id; struct MsgAnnounce ann; struct MsgHeader hdr; }

user_defined_types: struct pp_channel { union { int fd; void *custom; }; void *arch_data; unsigned char addr[6]; unsigned char peer[6]; int pkt_present; }

user_defined_types: struct Integer64 { unsigned int lsb; int msb; }

user_defined_types: struct TimeInternal { int seconds; int nanoseconds; int phase; int correct; int raw_ahead; }

user_defined_types: struct ClockQuality { unsigned char clockClass; unsigned char clockAccuracy; unsigned short offsetScaledLogVariance; }

user_defined_types: struct ClockIdentity { unsigned char id[8]; }

user_defined_types: struct UInteger48 { unsigned int lsb; unsigned short msb; }


decompiled_code:
__int64 __fastcall pp_passive(__int64 a1, __int64 a2, unsigned int a3)
{
char v4; // al
int v5; // eax
int v7; // eax

if ( *(_DWORD *)(a1 + 12) )
pp_timeout_restart_annrec(a1);
if ( a3 )
{
v4 = *(_BYTE *)(a1 + 1345);
if ( v4 )
{
if ( v4 != 11 )
goto LABEL_6;
v7 = st_com_master_handle_announce(a1, a2, a3);
}
else
{
v7 = st_com_master_handle_sync(a1, a2, a3);
}
if ( v7 )
goto LABEL_13;
}
LABEL_6:
if ( !(unsigned int)st_com_execute_slave(a1) )
{
v5 = *(_DWORD *)(a1 + 4);
goto LABEL_8;
}
LABEL_13:
*(_DWORD *)(a1 + 4) = 2;
v5 = 2;
LABEL_8:
if ( *(_DWORD *)a1 != v5 )
pp_timeout_clr_constprop_0(a1);
*(_DWORD *)(a1 + 8) = 1000;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3)
{
char v4; // al
int v5; // eax
int v7; // eax

if ( *(_DWORD *)(a1 + 12) )
func3(a1);
if ( a3 )
{
v4 = *(_BYTE *)(a1 + 1345);
if ( v4 )
{
if ( v4 != 11 )
goto LABEL_6;
v7 = st_com_master_handle_announce(a1, a2, a3);
}
else
{
v7 = st_com_master_handle_sync(a1, a2, a3);
}
if ( v7 )
goto LABEL_13;
}
LABEL_6:
if ( !(unsigned int)st_com_execute_slave(a1) )
{
v5 = *(_DWORD *)(a1 + 4);
goto LABEL_8;
}
LABEL_13:
*(_DWORD *)(a1 + 4) = 2;
v5 = 2;
LABEL_8:
if ( *(_DWORD *)a1 != v5 )
func0(a1);
*(_DWORD *)(a1 + 8) = 1000;
return 0LL;
}

original_code:
int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
 int e = 0;
 if (ppi->is_new_state)
  pp_timeout_restart_annrec(ppi);
 if (plen == 0)
  goto no_incoming_msg;
 switch (ppi->received_ptp_header.messageType) {
 case PPM_ANNOUNCE:
  e = st_com_master_handle_announce(ppi, pkt, plen);
  break;
 case PPM_SYNC:
  e = st_com_master_handle_sync(ppi, pkt, plen);
  break;
 default:
  break;
 }
no_incoming_msg:
 if (e == 0)
  e = st_com_execute_slave(ppi);
 if (e != 0)
  ppi->next_state = PPS_FAULTY;
 if (ppi->next_state != ppi->state) {
  pp_timeout_clr(ppi, PP_TO_ANN_RECEIPT);
 }
 ppi->next_delay = 1000;
 return 0;
}

user_defined_types: struct pp_network_operations { int (*init)(struct pp_instance *ppi); int (*exit)(struct pp_instance *ppi); int (*recv)(struct pp_instance *ppi, void *pkt, int len, struct TimeInternal *t); int (*send)(struct pp_instance *ppi, void *pkt, int len, struct TimeInternal *t, int chtype, int use_pdelay_addr); }

user_defined_types: struct pp_time_operations { int (*get)(struct pp_instance *ppi, struct TimeInternal *t); int (*set)(struct pp_instance *ppi, struct TimeInternal *t); int (*adjust)(struct pp_instance *ppi, long offset_ns, long freq_ppm); int (*adjust_offset)(struct pp_instance *ppi, long offset_ns); int (*adjust_freq)(struct pp_instance *ppi, long freq_ppm); unsigned long (*calc_timeout)(struct pp_instance *ppi, int millisec); }

user_defined_types: struct DSPort { struct PortIdentity portIdentity; char logMinDelayReqInterval; char logAnnounceInterval; unsigned char announceReceiptTimeout; char logSyncInterval; unsigned char versionNumber; void *ext_dsport; }

user_defined_types: struct MsgAnnounce { struct Timestamp originTimestamp; short currentUtcOffset; unsigned char grandmasterPriority1; struct ClockQuality grandmasterClockQuality; unsigned char grandmasterPriority2; struct ClockIdentity grandmasterIdentity; unsigned short stepsRemoved; unsigned char timeSource; unsigned long ext_specific; }

user_defined_types: struct MsgHeader { unsigned char transportSpecific; unsigned char messageType; unsigned char versionPTP; unsigned short messageLength; unsigned char domainNumber; unsigned char flagField[2]; struct Integer64 correctionfield; struct PortIdentity sourcePortIdentity; unsigned short sequenceId; unsigned char controlField; char logMessageInterval; }

user_defined_types: struct pp_servo { struct TimeInternal m_to_s_dly; struct TimeInternal s_to_m_dly; struct TimeInternal delay_ms; struct TimeInternal delay_sm; int obs_drift; struct pp_owd_fltr owd_fltr; struct pp_ofm_fltr ofm_fltr; }

user_defined_types: struct pp_runtime_opts { struct ClockQuality clock_quality; struct TimeInternal inbound_latency; int max_rst; int max_dly; int ttl; unsigned int no_adjust; short ap; short s; char announce_intvl; char sync_intvl; unsigned char prio1; unsigned char prio2; unsigned char domain_number; void *arch_opts; }

user_defined_types: struct DSDefault { enum Boolean twoStepFlag; struct ClockIdentity clockIdentity; unsigned short numberPorts; struct ClockQuality clockQuality; unsigned char priority1; unsigned char priority2; unsigned char domainNumber; enum Boolean slaveOnly; }

user_defined_types: struct DSParent { struct PortIdentity parentPortIdentity; unsigned short observedParentOffsetScaledLogVariance; int observedParentClockPhaseChangeRate; struct ClockIdentity grandmasterIdentity; struct ClockQuality grandmasterClockQuality; unsigned char grandmasterPriority1; unsigned char grandmasterPriority2; }

user_defined_types: struct Timestamp { struct UInteger48 secondsField; unsigned int nanosecondsField; }


original_code:
void mtp_result(struct mtp_packet *pkt)
{
 int i;
 long total, remote, rtt;
 signed long long delta;
 for (i = 0; i < 3; i++) {
  if (pkt->t[0][i].tv_sec == 0)
   continue;
  if (0) {
   int j;
   printf("Times at slot %i:\n", i);
   for (j = 0; j < 4; j++) {
    printf("   t%i: %li.%09li\n", i,
           pkt->t[j][i].tv_sec,
           pkt->t[j][i].tv_nsec);
   }
  }
  total = tsdiff(pkt->t[3] + i, pkt->t[0] + i);
  remote = tsdiff(pkt->t[2] + i, pkt->t[1] + i);
  rtt = total - remote;
  delta = tsdiff(pkt->t[1] + i, pkt->t[0] + i);
  if (0) {
   printf("total %li\n", total);
   printf("remote %li\n", remote);
   printf("rtt %li\n", rtt);
   printf("bigdelta %lli\n", delta);
  }
  delta -= rtt / 2;
  printf("%i: rtt %12.9lf   delta %13.9lf\n",
         i, (double)rtt / (1000*1000*1000),
         (double)delta / (1000*1000*1000));
 }
}

canonical_original_code:
void mtp_result(struct mtp_packet *pkt)
{
 int i;
 long total; long remote; long rtt;
 long long delta;
 for (i = 0; i < 3; i++) {
  if (pkt->t[0][i].tv_sec == 0)
   continue;
  if (0) {
   int j;
   printf("Times at slot %i:\n", i);
   for (j = 0; j < 4; j++) {
    printf("   t%i: %li.%09li\n", i,
           pkt->t[j][i].tv_sec,
           pkt->t[j][i].tv_nsec);
   }
  }
  total = tsdiff(pkt->t[3] + i, pkt->t[0] + i);
  remote = tsdiff(pkt->t[2] + i, pkt->t[1] + i);
  rtt = total - remote;
  delta = tsdiff(pkt->t[1] + i, pkt->t[0] + i);
  if (0) {
   printf("total %li\n", total);
   printf("remote %li\n", remote);
   printf("rtt %li\n", rtt);
   printf("bigdelta %lli\n", delta);
  }
  delta -= rtt / 2;
  printf("%i: rtt %12.9lf   delta %13.9lf\n",
         i, (double)rtt / (1000*1000*1000),
         (double)delta / (1000*1000*1000));
 }
}

variable_types: struct mtp_packet { unsigned int tragic; unsigned int ptype; struct timespec { long tv_sec; long tv_nsec; } t[4][3]; } *

variable_types: total long

variable_types: remote long

variable_types: rtt long

variable_types:
delta
long long

variable_types: j int

user_defined_types: struct mtp_packet { unsigned int tragic; unsigned int ptype; struct timespec t[4][3]; }


charForHexInt

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

result = a1 + 55;
if ( a1 <= 9 )
result = a1 + 48;
return result;
}

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

result = a1 + 55;
if ( a1 <= 9 )
result = a1 + 48;
return result;
}

original_code:
char charForHexInt (int n) {
    if (n >= 0 && n < 10)
        return '0' + n;
    return 'A' + n - 10;
}

canonical_original_code:
char charForHexInt(int n) {
    if (n >= 0 && n < 10)
        return '0' + n;
    return 'A' + n - 10;
}

variable_types: n int

return_type: char


decompiled_code:
int __fastcall dump_urb(int a1, int a2, int a3, int a4, int a5, int a6, __int64 a7, int a8, void *src, __int64 a10, __int64 a11, __int64 a12)
{
const char *v12; // rdi
int result; // eax
const char *v14; // rcx
const char *v15; // rdx
__int64 v16; // rbx
const char *v17; // rdx
unsigned __int8 v18; // bl
unsigned __int8 v19; // al
unsigned __int8 v20; // bl
unsigned __int8 v21; // [rsp+0h] [rbp-48h] BYREF
unsigned __int8 v22; // [rsp+1h] [rbp-47h]
unsigned __int16 v23; // [rsp+2h] [rbp-46h]
unsigned __int16 v24; // [rsp+4h] [rbp-44h]
unsigned __int16 v25; // [rsp+6h] [rbp-42h]
unsigned int v26; // [rsp+8h] [rbp-40h]

printf(" type = ");
fflush(stdout);
if ( (_BYTE)a7 == 1 )
{
v12 = "USBDEVFS_URB_TYPE_INTERRUPT";
goto LABEL_4;
}
if ( (unsigned __int8)a7 <= 1u )
{
v12 = "USBDEVFS_URB_TYPE_ISO";
LABEL_4:
puts(v12);
return fflush(stdout);
}
if ( (unsigned __int8)(a7 - 2) > 1u )
return printf("UNKNOWN %d\n", (unsigned __int8)a7);
if ( (_BYTE)a7 == 3 )
puts("USBDEVFS_URB_TYPE_BULK");
else
puts("USBDEVFS_URB_TYPE_CONTROL");
fflush(stdout);
if ( (a7 & 0x8000) != 0 )
printf(" endpoint = %d|USB_DIR_IN\n", (unsigned __int8)(BYTE1(a7) + 0x80));
else
printf(" endpoint = %d|USB_DIR_OUT\n", BYTE1(a7));
fflush(stdout);
if ( HIDWORD(a7) )
{
switch ( HIDWORD(a7) )
{
case 0xFFFFFF87:
puts(
" status = -EREMOTEIO: data read from EP didnt fill the buffer, and URB_SHORT_NOT_OK was set i"
"n urb->transfer_flags.");
break;
case 0xFFFFFF8D:
puts(" status = -EINPROGRESS: URB still pending, no results yet");
break;
case 0xFFFFFF92:
puts(" status = -ETIMEDOUT: timeout expired before the transfer completed");
break;
case 0xFFFFFF94:
puts(
" status = Device or host controller is disabled due to a problem that couldnt worked around, "
"e.g. physical disconnect");
break;
case 0xFFFFFF98:
puts(" status = -ECONNRESET: URB was asynchronously unlinked by usb_unlink_urb");
break;
case 0xFFFFFFAC:
puts(" status = -EILSEQ: CRC mismatch / no response within turn-around time / unknown error");
break;
case 0xFFFFFFB5:
puts(
" status = -EOVERFLOW: amount returned by EP greater than either the max pckt size of EP or th"
"e remaining buff size.");
break;
case 0xFFFFFFB9:
puts(" status = -EPROTO: bitstuff error / no response within turn-around time / unknown error");
break;
case 0xFFFFFFBA:
puts(
" status = -ECOMM: During IN transf, host controller received data from endpoint faster than c"
"ould writte to memory");
break;
case 0xFFFFFFC1:
puts(
" status = -ENOSR: During OUT transf, host controller couldnt get data fast enough to keep up "
"with the USB data rate");
break;
case 0xFFFFFFC2:
puts(" status = -ETIME: no response within turn-around time");
break;
case 0xFFFFFFE0:
puts(" status = -EPIPE: Endpoint stalled");
break;
case 0xFFFFFFEA:
puts(" status = -EINVAL: ISO madness, if this happens: Log off and go home");
break;
case 0xFFFFFFED:
puts(" status = -ENODEV: Device was removed");
break;
case 0xFFFFFFEE:
puts(" status = -EXDEV: ISO transfer only partially completed");
break;
case 0xFFFFFFFE:
puts(" status = -ENOENT : URB was synchronously unlinked by usb_unlink_urb");
break;
default:
puts(" status = UNKNOWN : error code is not known");
break;
}
}
else
{
puts(" status = 0 (OK)");
}
fflush(stdout);
v14 = "USBDEVFS_URB_ISO_ASAP";
v15 = "USBDEVFS_URB_SHORT_NOT_OK";
if ( (a8 & 2) == 0 )
v14 = (const char *)&unk_675;
if ( (a8 & 1) == 0 )
v15 = (const char *)&unk_675;
printf(" flags = %d (%s %s)\n", (unsigned int)a8, v15, v14);
fflush(stdout);
printf(" buffer_length = %d\n", (unsigned int)a10);
fflush(stdout);
printf(" actual_length = %d\n", HIDWORD(a10));
fflush(stdout);
if ( a1 )
{
puts(" BUFFER:");
fflush(stdout);
printf(" ");
fflush(stdout);
if ( (_DWORD)a10 )
{
v16 = 1LL;
printf("0x%02x ", *(unsigned __int8 *)src);
while ( 1 )
{
fflush(stdout);
if ( v16 == (unsigned int)a10 )
break;
printf("0x%02x ", *((unsigned __int8 *)src + v16));
if ( (v16 & 0xF) == 15 )
printf("\n ");
++v16;
}
}
putchar(10);
fflush(stdout);
}
else
{
puts(" BUFFER: (not shown)");
fflush(stdout);
}
printf(" start_frame = %d\n", (unsigned int)a11);
fflush(stdout);
printf(" number_of_packets = %d\n", HIDWORD(a11));
fflush(stdout);
printf(" error_count = %d\n", (unsigned int)a12);
fflush(stdout);
printf(" signr = %d\n", HIDWORD(a12));
fflush(stdout);
puts(" usercontext = 0x--------");
fflush(stdout);
result = fflush(stdout);
if ( (_BYTE)a7 == 2 )
{
memcpy(&v21, src, (int)a10);
puts("Control Packet Contents:");
v17 = "USB_DIR_IN";
v18 = v21;
if ( (v21 & 0x80u) == 0 )
v17 = "USB_DIR_OUT";
printf(" bRequestType = (0x%02x) : %s | ", v21, v17);
v19 = v18 & 0x60;
if ( (v18 & 0x60) == 64 )
{
printf("USB_TYPE_VENDOR | ");
}
else if ( v19 > 0x40u )
{
if ( v19 == 96 )
printf("USB_TYPE_RESERVED | ");
}
else if ( v19 )
{
if ( v19 == 32 )
printf("USB_TYPE_CLASS | ");
}
else
{
printf("USB_TYPE_STANDARD | ");
}
v20 = v18 & 0x1F;
if ( v20 == 2 )
{
puts("USB_RECIP_ENDPOINT");
}
else if ( v20 > 2u )
{
if ( v20 == 3 )
puts("USB_RECIP_OTHER");
}
else if ( v20 )
{
puts("USB_RECIP_INTERFACE");
}
else
{
puts("USB_RECIP_DEVICE");
}
printf(" bRequest = ");
switch ( v22 )
{
case 0u:
puts("USB_REQ_GET_STATUS");
break;
case 1u:
puts("USB_REQ_CLEAR_FEATURE");
break;
case 3u:
puts("USB_REQ_SET_FEATURE");
break;
case 5u:
puts("USB_REQ_SET_ADDRESS");
break;
case 6u:
puts("USB_REQ_GET_DESCRIPTOR");
break;
case 7u:
puts("USB_REQ_SET_DESCRIPTOR");
break;
case 8u:
puts("USB_REQ_GET_CONFIGURATION");
break;
case 9u:
puts("USB_REQ_SET_CONFIGURATION");
break;
case 0xAu:
puts("USB_REQ_GET_INTERFACE");
break;
case 0xBu:
puts("USB_REQ_SET_INTERFACE");
break;
case 0xCu:
puts("USB_REQ_SYNCH_FRAME");
break;
default:
printf("%d\n", v22);
break;
}
printf(" wValue = 0x%04x\n", v23);
printf(" wIndex = 0x%04x\n", v24);
printf(" wLength = %d\n", v25);
printf(" timeout = %d\n", v26);
printf(" data = 0x--------");
return fflush(stdout);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2, int a3, int a4, int a5, int a6, __int64 a7, int a8, void *src, __int64 a10, __int64 a11, __int64 a12)
{
const char *v12; // rdi
int result; // eax
const char *v14; // rcx
const char *v15; // rdx
__int64 v16; // rbx
const char *v17; // rdx
unsigned __int8 v18; // bl
unsigned __int8 v19; // al
unsigned __int8 v20; // bl
unsigned __int8 v21; // [rsp+0h] [rbp-48h] BYREF
unsigned __int8 v22; // [rsp+1h] [rbp-47h]
unsigned __int16 v23; // [rsp+2h] [rbp-46h]
unsigned __int16 v24; // [rsp+4h] [rbp-44h]
unsigned __int16 v25; // [rsp+6h] [rbp-42h]
unsigned int v26; // [rsp+8h] [rbp-40h]

printf(" type = ");
fflush(stdout);
if ( (_BYTE)a7 == 1 )
{
v12 = "USBDEVFS_URB_TYPE_INTERRUPT";
goto LABEL_4;
}
if ( (unsigned __int8)a7 <= 1u )
{
v12 = "USBDEVFS_URB_TYPE_ISO";
LABEL_4:
puts(v12);
return fflush(stdout);
}
if ( (unsigned __int8)(a7 - 2) > 1u )
return printf("UNKNOWN %d\n", (unsigned __int8)a7);
if ( (_BYTE)a7 == 3 )
puts("USBDEVFS_URB_TYPE_BULK");
else
puts("USBDEVFS_URB_TYPE_CONTROL");
fflush(stdout);
if ( (a7 & 0x8000) != 0 )
printf(" endpoint = %d|USB_DIR_IN\n", (unsigned __int8)(BYTE1(a7) + 0x80));
else
printf(" endpoint = %d|USB_DIR_OUT\n", BYTE1(a7));
fflush(stdout);
if ( HIDWORD(a7) )
{
switch ( HIDWORD(a7) )
{
case 0xFFFFFF87:
puts(
" status = -EREMOTEIO: data read from EP didnt fill the buffer, and URB_SHORT_NOT_OK was set i"
"n urb->transfer_flags.");
break;
case 0xFFFFFF8D:
puts(" status = -EINPROGRESS: URB still pending, no results yet");
break;
case 0xFFFFFF92:
puts(" status = -ETIMEDOUT: timeout expired before the transfer completed");
break;
case 0xFFFFFF94:
puts(
" status = Device or host controller is disabled due to a problem that couldnt worked around, "
"e.g. physical disconnect");
break;
case 0xFFFFFF98:
puts(" status = -ECONNRESET: URB was asynchronously unlinked by usb_unlink_urb");
break;
case 0xFFFFFFAC:
puts(" status = -EILSEQ: CRC mismatch / no response within turn-around time / unknown error");
break;
case 0xFFFFFFB5:
puts(
" status = -EOVERFLOW: amount returned by EP greater than either the max pckt size of EP or th"
"e remaining buff size.");
break;
case 0xFFFFFFB9:
puts(" status = -EPROTO: bitstuff error / no response within turn-around time / unknown error");
break;
case 0xFFFFFFBA:
puts(
" status = -ECOMM: During IN transf, host controller received data from endpoint faster than c"
"ould writte to memory");
break;
case 0xFFFFFFC1:
puts(
" status = -ENOSR: During OUT transf, host controller couldnt get data fast enough to keep up "
"with the USB data rate");
break;
case 0xFFFFFFC2:
puts(" status = -ETIME: no response within turn-around time");
break;
case 0xFFFFFFE0:
puts(" status = -EPIPE: Endpoint stalled");
break;
case 0xFFFFFFEA:
puts(" status = -EINVAL: ISO madness, if this happens: Log off and go home");
break;
case 0xFFFFFFED:
puts(" status = -ENODEV: Device was removed");
break;
case 0xFFFFFFEE:
puts(" status = -EXDEV: ISO transfer only partially completed");
break;
case 0xFFFFFFFE:
puts(" status = -ENOENT : URB was synchronously unlinked by usb_unlink_urb");
break;
default:
puts(" status = UNKNOWN : error code is not known");
break;
}
}
else
{
puts(" status = 0 (OK)");
}
fflush(stdout);
v14 = "USBDEVFS_URB_ISO_ASAP";
v15 = "USBDEVFS_URB_SHORT_NOT_OK";
if ( (a8 & 2) == 0 )
v14 = (const char *)&unk_675;
if ( (a8 & 1) == 0 )
v15 = (const char *)&unk_675;
printf(" flags = %d (%s %s)\n", (unsigned int)a8, v15, v14);
fflush(stdout);
printf(" buffer_length = %d\n", (unsigned int)a10);
fflush(stdout);
printf(" actual_length = %d\n", HIDWORD(a10));
fflush(stdout);
if ( a1 )
{
puts(" BUFFER:");
fflush(stdout);
printf(" ");
fflush(stdout);
if ( (_DWORD)a10 )
{
v16 = 1LL;
printf("0x%02x ", *(unsigned __int8 *)src);
while ( 1 )
{
fflush(stdout);
if ( v16 == (unsigned int)a10 )
break;
printf("0x%02x ", *((unsigned __int8 *)src + v16));
if ( (v16 & 0xF) == 15 )
printf("\n ");
++v16;
}
}
putchar(10);
fflush(stdout);
}
else
{
puts(" BUFFER: (not shown)");
fflush(stdout);
}
printf(" start_frame = %d\n", (unsigned int)a11);
fflush(stdout);
printf(" number_of_packets = %d\n", HIDWORD(a11));
fflush(stdout);
printf(" error_count = %d\n", (unsigned int)a12);
fflush(stdout);
printf(" signr = %d\n", HIDWORD(a12));
fflush(stdout);
puts(" usercontext = 0x--------");
fflush(stdout);
result = fflush(stdout);
if ( (_BYTE)a7 == 2 )
{
memcpy(&v21, src, (int)a10);
puts("Control Packet Contents:");
v17 = "USB_DIR_IN";
v18 = v21;
if ( (v21 & 0x80u) == 0 )
v17 = "USB_DIR_OUT";
printf(" bRequestType = (0x%02x) : %s | ", v21, v17);
v19 = v18 & 0x60;
if ( (v18 & 0x60) == 64 )
{
printf("USB_TYPE_VENDOR | ");
}
else if ( v19 > 0x40u )
{
if ( v19 == 96 )
printf("USB_TYPE_RESERVED | ");
}
else if ( v19 )
{
if ( v19 == 32 )
printf("USB_TYPE_CLASS | ");
}
else
{
printf("USB_TYPE_STANDARD | ");
}
v20 = v18 & 0x1F;
if ( v20 == 2 )
{
puts("USB_RECIP_ENDPOINT");
}
else if ( v20 > 2u )
{
if ( v20 == 3 )
puts("USB_RECIP_OTHER");
}
else if ( v20 )
{
puts("USB_RECIP_INTERFACE");
}
else
{
puts("USB_RECIP_DEVICE");
}
printf(" bRequest = ");
switch ( v22 )
{
case 0u:
puts("USB_REQ_GET_STATUS");
break;
case 1u:
puts("USB_REQ_CLEAR_FEATURE");
break;
case 3u:
puts("USB_REQ_SET_FEATURE");
break;
case 5u:
puts("USB_REQ_SET_ADDRESS");
break;
case 6u:
puts("USB_REQ_GET_DESCRIPTOR");
break;
case 7u:
puts("USB_REQ_SET_DESCRIPTOR");
break;
case 8u:
puts("USB_REQ_GET_CONFIGURATION");
break;
case 9u:
puts("USB_REQ_SET_CONFIGURATION");
break;
case 0xAu:
puts("USB_REQ_GET_INTERFACE");
break;
case 0xBu:
puts("USB_REQ_SET_INTERFACE");
break;
case 0xCu:
puts("USB_REQ_SYNCH_FRAME");
break;
default:
printf("%d\n", v22);
break;
}
printf(" wValue = 0x%04x\n", v23);
printf(" wIndex = 0x%04x\n", v24);
printf(" wLength = %d\n", v25);
printf(" timeout = %d\n", v26);
printf(" data = 0x--------");
return fflush(stdout);
}
return result;
}

original_code:
void dump_urb( struct usbdevfs_urb urb, int dumpData )
{
    unsigned int buffer_length = urb.buffer_length;
    printf("    type                 = ");
    fflush(stdout);
    switch (urb.type) {
        case 0:
            printf("USBDEVFS_URB_TYPE_ISO\n");
            fflush(stdout);
            break;
        case 1:
            printf("USBDEVFS_URB_TYPE_INTERRUPT\n");
            fflush(stdout);
            break;
        case 3:
        case 2:
            if (3==urb.type)
                printf("USBDEVFS_URB_TYPE_BULK\n");
            else
            if (2==urb.type)
                printf("USBDEVFS_URB_TYPE_CONTROL\n");
            fflush(stdout);
            if (0x80==(urb.endpoint&0x80))
                printf("    endpoint             = %d|USB_DIR_IN\n",urb.endpoint^0x80);
            else
                printf("    endpoint             = %d|USB_DIR_OUT\n",urb.endpoint);
            fflush(stdout);
            if( 0!=urb.status ){
                switch (urb.status){
                    case -2:
                        printf("    status               = -ENOENT  : URB was synchronously unlinked by usb_unlink_urb\n");
                        break;
                    case -115:
                        printf("    status               = -EINPROGRESS: URB still pending, no results yet\n");
                        break;
                    case -71:
                        printf("    status               = -EPROTO: bitstuff error / no response within turn-around time / unknown error\n");
                        break;
                    case -84:
                        printf("    status               = -EILSEQ: CRC mismatch / no response within turn-around time / unknown error\n");
                        break;
                    case -62:
                        printf("    status               = -ETIME: no response within turn-around time\n");
                        break;
                    case -110:
                        printf("    status               = -ETIMEDOUT: timeout expired before the transfer completed\n");
                        break;
                    case -32:
                        printf("    status               = -EPIPE: Endpoint stalled\n");
                        break;
                    case -70:
                        printf("    status               = -ECOMM: During IN transf, host controller received data from endpoint faster than could writte to memory\n");
                        break;
                    case -63:
                        printf("    status               = -ENOSR: During OUT transf, host controller couldnt get data fast enough to keep up with the USB data rate\n");
                        break;
                    case -75:
                        printf("    status               = -EOVERFLOW: amount returned by EP greater than either the max pckt size of EP or the remaining buff size.\n");
                        break;
                    case -121:
                        printf("    status               = -EREMOTEIO: data read from EP didnt fill the buffer, and URB_SHORT_NOT_OK was set in urb->transfer_flags.\n");
                        break;
                    case -19:
                        printf("    status               = -ENODEV: Device was removed\n");
                        break;
                    case -18:
                        printf("    status               = -EXDEV: ISO transfer only partially completed\n");
                        break;
                    case -22:
                        printf("    status               = -EINVAL: ISO madness, if this happens: Log off and go home\n");
                        break;
                    case -104:
                        printf("    status               = -ECONNRESET: URB was asynchronously unlinked by usb_unlink_urb\n");
                        break;
                    case -108:
                        printf("    status               = Device or host controller is disabled due to a problem that couldnt worked around, e.g. physical disconnect\n");
                        break;
                    default:
                        printf("    status               = UNKNOWN  : error code is not known\n");
                        break;
                }
            } else {
                printf("    status               = 0 (OK)\n");
            }
            fflush(stdout);
            printf("    flags                = %d (%s %s)\n",urb.flags,(urb.flags&0x01?"USBDEVFS_URB_SHORT_NOT_OK":""),(urb.flags&0x02?"USBDEVFS_URB_ISO_ASAP":""));
            fflush(stdout);
            printf("    buffer_length        = %d\n",urb.buffer_length);
            fflush(stdout);
            printf("    actual_length        = %d\n",urb.actual_length);
            fflush(stdout);
            if (dumpData){
                printf("    BUFFER:\n");
                fflush(stdout);
                printf("      ");
                fflush(stdout);
                for (int ii=0; ii<buffer_length; ii++ ){
                    unsigned char *cp = urb.buffer;
                    printf("0x%02x ",cp[ii]);
                    if (ii%16==15)
                        printf("\n      ");
                    fflush(stdout);
                }
                printf("\n");
                fflush(stdout);
            } else {
                printf("    BUFFER: (not shown)\n");
                fflush(stdout);
            }
            printf("    start_frame          = %d\n",urb.start_frame);
            fflush(stdout);
            printf("    number_of_packets    = %d\n",urb.number_of_packets);
            fflush(stdout);
            printf("    error_count          = %d\n",urb.error_count);
            fflush(stdout);
            printf("    signr                = %d\n",urb.signr);
            fflush(stdout);
            printf("    usercontext          = 0x--------\n");
            fflush(stdout);
         if (urb.type==0){
          printf("    iso_frame_desc[0].length:        %d\n", urb.iso_frame_desc[0].length);
          printf("    iso_frame_desc[0].actual_length: %d\n", urb.iso_frame_desc[0].actual_length);
          printf("    iso_frame_desc[0].status:        %d\n", urb.iso_frame_desc[0].status);
         }
            fflush(stdout);
            if (2==urb.type){
                struct usbdevfs_ctrltransfer txf;
                memcpy(&txf,urb.buffer,urb.buffer_length);
                printf("Control Packet Contents:\n");
                printf("        bRequestType     = (0x%02x) : %s | ", txf.bRequestType, ((txf.bRequestType&0x80)==0x80?"USB_DIR_IN":"USB_DIR_OUT"));
                switch (txf.bRequestType&(0x03 << 5)){
                    case (0x00 << 5): printf("USB_TYPE_STANDARD | "); break;
                    case (0x01 << 5): printf("USB_TYPE_CLASS | "); break;
                    case (0x02 << 5): printf("USB_TYPE_VENDOR | "); break;
                    case (0x03 << 5): printf("USB_TYPE_RESERVED | "); break;
                }
                switch (txf.bRequestType&0x1f){
                    case 0x00: printf("USB_RECIP_DEVICE\n"); break;
                    case 0x01: printf("USB_RECIP_INTERFACE\n"); break;
                    case 0x02: printf("USB_RECIP_ENDPOINT\n"); break;
                    case 0x03: printf("USB_RECIP_OTHER\n"); break;
                }
                printf("        bRequest         = ");
                switch (txf.bRequest){
                    case 0x00: printf("USB_REQ_GET_STATUS\n"); break;
                    case 0x01: printf("USB_REQ_CLEAR_FEATURE\n"); break;
                    case 0x03: printf("USB_REQ_SET_FEATURE\n"); break;
                    case 0x05: printf("USB_REQ_SET_ADDRESS\n"); break;
                    case 0x06: printf("USB_REQ_GET_DESCRIPTOR\n"); break;
                    case 0x07: printf("USB_REQ_SET_DESCRIPTOR\n"); break;
                    case 0x08: printf("USB_REQ_GET_CONFIGURATION\n"); break;
                    case 0x09: printf("USB_REQ_SET_CONFIGURATION\n"); break;
                    case 0x0A: printf("USB_REQ_GET_INTERFACE\n"); break;
                    case 0x0B: printf("USB_REQ_SET_INTERFACE\n"); break;
                    case 0x0C: printf("USB_REQ_SYNCH_FRAME\n"); break;
                    default: printf("%d\n", txf.bRequest); break;
                }
                printf("        wValue           = 0x%04x\n", txf.wValue);
                printf("        wIndex           = 0x%04x\n", txf.wIndex);
                printf("        wLength          = %d\n", txf.wLength);
                printf("        timeout          = %d\n", txf.timeout);
                printf("        data             = 0x--------");
                fflush(stdout);
            }
            break;
        default:
            printf("UNKNOWN %d\n",urb.type);
            buffer_length = 100;
            break;
    }
}

canonical_original_code:
void dump_urb(struct usbdevfs_urb urb, int dumpData)
{
    unsigned int buffer_length = urb.buffer_length;
    printf("    type                 = ");
    fflush(stdout);
    switch (urb.type) {
        case 0:
            printf("USBDEVFS_URB_TYPE_ISO\n");
            fflush(stdout);
            break;
        case 1:
            printf("USBDEVFS_URB_TYPE_INTERRUPT\n");
            fflush(stdout);
            break;
        case 3:
        case 2:
            if (3==urb.type)
                printf("USBDEVFS_URB_TYPE_BULK\n");
            else
            if (2==urb.type)
                printf("USBDEVFS_URB_TYPE_CONTROL\n");
            fflush(stdout);
            if (0x80==(urb.endpoint&0x80))
                printf("    endpoint             = %d|USB_DIR_IN\n",urb.endpoint^0x80);
            else
                printf("    endpoint             = %d|USB_DIR_OUT\n",urb.endpoint);
            fflush(stdout);
            if( 0!=urb.status ){
                switch (urb.status){
                    case -2:
                        printf("    status               = -ENOENT  : URB was synchronously unlinked by usb_unlink_urb\n");
                        break;
                    case -115:
                        printf("    status               = -EINPROGRESS: URB still pending, no results yet\n");
                        break;
                    case -71:
                        printf("    status               = -EPROTO: bitstuff error / no response within turn-around time / unknown error\n");
                        break;
                    case -84:
                        printf("    status               = -EILSEQ: CRC mismatch / no response within turn-around time / unknown error\n");
                        break;
                    case -62:
                        printf("    status               = -ETIME: no response within turn-around time\n");
                        break;
                    case -110:
                        printf("    status               = -ETIMEDOUT: timeout expired before the transfer completed\n");
                        break;
                    case -32:
                        printf("    status               = -EPIPE: Endpoint stalled\n");
                        break;
                    case -70:
                        printf("    status               = -ECOMM: During IN transf, host controller received data from endpoint faster than could writte to memory\n");
                        break;
                    case -63:
                        printf("    status               = -ENOSR: During OUT transf, host controller couldnt get data fast enough to keep up with the USB data rate\n");
                        break;
                    case -75:
                        printf("    status               = -EOVERFLOW: amount returned by EP greater than either the max pckt size of EP or the remaining buff size.\n");
                        break;
                    case -121:
                        printf("    status               = -EREMOTEIO: data read from EP didnt fill the buffer, and URB_SHORT_NOT_OK was set in urb->transfer_flags.\n");
                        break;
                    case -19:
                        printf("    status               = -ENODEV: Device was removed\n");
                        break;
                    case -18:
                        printf("    status               = -EXDEV: ISO transfer only partially completed\n");
                        break;
                    case -22:
                        printf("    status               = -EINVAL: ISO madness, if this happens: Log off and go home\n");
                        break;
                    case -104:
                        printf("    status               = -ECONNRESET: URB was asynchronously unlinked by usb_unlink_urb\n");
                        break;
                    case -108:
                        printf("    status               = Device or host controller is disabled due to a problem that couldnt worked around, e.g. physical disconnect\n");
                        break;
                    default:
                        printf("    status               = UNKNOWN  : error code is not known\n");
                        break;
                }
            } else {
                printf("    status               = 0 (OK)\n");
            }
            fflush(stdout);
            printf("    flags                = %d (%s %s)\n",urb.flags,(urb.flags&0x01?"USBDEVFS_URB_SHORT_NOT_OK":""),(urb.flags&0x02?"USBDEVFS_URB_ISO_ASAP":""));
            fflush(stdout);
            printf("    buffer_length        = %d\n",urb.buffer_length);
            fflush(stdout);
            printf("    actual_length        = %d\n",urb.actual_length);
            fflush(stdout);
            if (dumpData){
                printf("    BUFFER:\n");
                fflush(stdout);
                printf("      ");
                fflush(stdout);
                for (int ii = 0; ii<buffer_length; ii++ ){
                    unsigned char *cp = urb.buffer;
                    printf("0x%02x ",cp[ii]);
                    if (ii%16==15)
                        printf("\n      ");
                    fflush(stdout);
                }
                printf("\n");
                fflush(stdout);
            } else {
                printf("    BUFFER: (not shown)\n");
                fflush(stdout);
            }
            printf("    start_frame          = %d\n",urb.start_frame);
            fflush(stdout);
            printf("    number_of_packets    = %d\n",urb.number_of_packets);
            fflush(stdout);
            printf("    error_count          = %d\n",urb.error_count);
            fflush(stdout);
            printf("    signr                = %d\n",urb.signr);
            fflush(stdout);
            printf("    usercontext          = 0x--------\n");
            fflush(stdout);
         if (urb.type==0){
          printf("    iso_frame_desc[0].length:        %d\n", urb.iso_frame_desc[0].length);
          printf("    iso_frame_desc[0].actual_length: %d\n", urb.iso_frame_desc[0].actual_length);
          printf("    iso_frame_desc[0].status:        %d\n", urb.iso_frame_desc[0].status);
         }
            fflush(stdout);
            if (2==urb.type){
                struct usbdevfs_ctrltransfer txf;
                memcpy(&txf,urb.buffer,urb.buffer_length);
                printf("Control Packet Contents:\n");
                printf("        bRequestType     = (0x%02x) : %s | ", txf.bRequestType, ((txf.bRequestType&0x80)==0x80?"USB_DIR_IN":"USB_DIR_OUT"));
                switch (txf.bRequestType&(0x03 << 5)){
                    case (0x00 << 5): printf("USB_TYPE_STANDARD | "); break;
                    case (0x01 << 5): printf("USB_TYPE_CLASS | "); break;
                    case (0x02 << 5): printf("USB_TYPE_VENDOR | "); break;
                    case (0x03 << 5): printf("USB_TYPE_RESERVED | "); break;
                }
                switch (txf.bRequestType&0x1f){
                    case 0x00: printf("USB_RECIP_DEVICE\n"); break;
                    case 0x01: printf("USB_RECIP_INTERFACE\n"); break;
                    case 0x02: printf("USB_RECIP_ENDPOINT\n"); break;
                    case 0x03: printf("USB_RECIP_OTHER\n"); break;
                }
                printf("        bRequest         = ");
                switch (txf.bRequest){
                    case 0x00: printf("USB_REQ_GET_STATUS\n"); break;
                    case 0x01: printf("USB_REQ_CLEAR_FEATURE\n"); break;
                    case 0x03: printf("USB_REQ_SET_FEATURE\n"); break;
                    case 0x05: printf("USB_REQ_SET_ADDRESS\n"); break;
                    case 0x06: printf("USB_REQ_GET_DESCRIPTOR\n"); break;
                    case 0x07: printf("USB_REQ_SET_DESCRIPTOR\n"); break;
                    case 0x08: printf("USB_REQ_GET_CONFIGURATION\n"); break;
                    case 0x09: printf("USB_REQ_SET_CONFIGURATION\n"); break;
                    case 0x0A: printf("USB_REQ_GET_INTERFACE\n"); break;
                    case 0x0B: printf("USB_REQ_SET_INTERFACE\n"); break;
                    case 0x0C: printf("USB_REQ_SYNCH_FRAME\n"); break;
                    default: printf("%d\n", txf.bRequest); break;
                }
                printf("        wValue           = 0x%04x\n", txf.wValue);
                printf("        wIndex           = 0x%04x\n", txf.wIndex);
                printf("        wLength          = %d\n", txf.wLength);
                printf("        timeout          = %d\n", txf.timeout);
                printf("        data             = 0x--------");
                fflush(stdout);
            }
            break;
        default:
            printf("UNKNOWN %d\n",urb.type);
            buffer_length = 100;
            break;
    }
}

variable_types: struct usbdevfs_urb { unsigned char type; unsigned char endpoint; int status; unsigned int flags; void *buffer; int buffer_length; int actual_length; int start_frame; union { int number_of_packets; unsigned int stream_id; }; int error_count; unsigned int signr; void *usercontext; struct usbdevfs_iso_packet_desc { unsigned int length; unsigned int actual_length; unsigned int status; } iso_frame_desc[]; }

variable_types: dumpData int

variable_types: ii int

variable_types:
cp
unsigned char *

variable_types: struct usbdevfs_ctrltransfer { unsigned char bRequestType; unsigned char bRequest; unsigned short wValue; unsigned short wIndex; unsigned short wLength; unsigned int timeout; void *data; }

user_defined_types: struct usbdevfs_urb { unsigned char type; unsigned char endpoint; int status; unsigned int flags; void *buffer; int buffer_length; int actual_length; int start_frame; union { int number_of_packets; unsigned int stream_id; }; int error_count; unsigned int signr; void *usercontext; struct usbdevfs_iso_packet_desc iso_frame_desc[]; }


original_code:
void myset_del(myset *s, void *data)
{
 int pos = s->hash(data) % s->size;
 mylist **cl = &s->buckets[pos];
 mylist *dl;
 while(*cl){
  if(s->cmp((*cl)->data, data) == 0){
   dl = *cl;
   *cl = (*cl)->next;
   mylist_free(dl);
   s->len--;
   break;
  }
  cl = &(*cl)->next;
 }
}

canonical_original_code:
void myset_del(struct myset *s, void *data)
{
 int pos = s->hash(data) % s->size;
 struct _list **cl = &s->buckets[pos];
 struct _list *dl;
 while(*cl){
  if(s->cmp((*cl)->data, data) == 0){
   dl = *cl;
   *cl = (*cl)->next;
   mylist_free(dl);
   s->len--;
   break;
  }
  cl = &(*cl)->next;
 }
}

variable_types: struct myset { int size; struct _list { void *data; struct _list *next; } **buckets; int len; int (*cmp)(void *, void *); int (*hash)(void *); } *

variable_types:
data
void *

variable_types: pos int

user_defined_types: struct myset { int size; struct _list **buckets; int len; int (*cmp)(void *, void *); int (*hash)(void *); }


original_code:
int myset_find(myset *s, void *data)
{
 int pos = s->hash(data) % s->size;
 mylist *cl = s->buckets[pos];
 while(cl){
  if(s->cmp(cl->data, data) == 0)
   return 1;
  cl = cl->next;
 }
 return 0;
}

canonical_original_code:
int myset_find(struct myset *s, void *data)
{
 int pos = s->hash(data) % s->size;
 struct _list *cl = s->buckets[pos];
 while(cl){
  if(s->cmp(cl->data, data) == 0)
   return 1;
  cl = cl->next;
 }
 return 0;
}

variable_types: struct _list { void *data; struct _list *next; } *


decompiled_code:
__int64 __fastcall myset_add(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r12
__int64 *v4; // rdx

result = myset_find(a1, a2);
if ( !(_DWORD)result )
{
v3 = (*(int (__fastcall **)(__int64))(a1 + 32))(a2) % *(_DWORD *)a1;
result = (__int64)mylist_new(a2);
v4 = (__int64 *)(*(_QWORD *)(a1 + 8) + 8 * v3);
*(_QWORD *)(result + 8) = *v4;
*v4 = result;
++*(_DWORD *)(a1 + 16);
}
return result;
}

original_code:
void myset_add(myset *s, void *data)
{
 if(!myset_find(s, data)){
  int pos = s->hash(data) % s->size;
  mylist *l = mylist_new(data);
  l->next = s->buckets[pos];
  s->buckets[pos] = l;
  s->len++;
 }
}

canonical_original_code:
void myset_add(struct myset *s, void *data)
{
 if(!myset_find(s, data)){
  int pos = s->hash(data) % s->size;
  struct _list *l = mylist_new(data);
  l->next = s->buckets[pos];
  s->buckets[pos] = l;
  s->len++;
 }
}

user_defined_types: struct _list { void *data; struct _list *next; }


decompiled_code:
__int64 __fastcall myset_add_set(__int64 a1, unsigned int *a2)
{
__int64 result; // rax
__int64 v3; // r14
__int64 *i; // rbp

result = *a2;
if ( (int)result > 0 )
{
v3 = 0LL;
result = *((_QWORD *)a2 + 1);
do
{
for ( i = *(__int64 **)(result + 8 * v3); i; i = *(__int64 **)(result + 8 * v3) )
{
myset_add(a1, *i);
*(_QWORD *)(*((_QWORD *)a2 + 1) + 8 * v3) = i[1];
mylist_free(i);
result = *((_QWORD *)a2 + 1);
}
++v3;
}
while ( (int)*a2 > (int)v3 );
}
return result;
}

original_code:
void myset_add_set(myset *s, myset *d)
{
 mylist *l;
 int i = 0;
 for(i = 0; i < d->size; i++){
  while(d->buckets[i]){
   l = d->buckets[i];
   myset_add(s, l->data);
   d->buckets[i] = l->next;
   mylist_free(l);
  }
 }
}

canonical_original_code:
void myset_add_set(struct myset *s, struct myset *d)
{
 struct _list *l;
 int i = 0;
 for(i = 0; i < d->size; i++){
  while(d->buckets[i]){
   l = d->buckets[i];
   myset_add(s, l->data);
   d->buckets[i] = l->next;
   mylist_free(l);
  }
 }
}

variable_types:
d
struct myset *

variable_types: i int


decompiled_code:
__int64 __fastcall myset_length(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int myset_length(myset *s)
{
 return s->len;
}

canonical_original_code:
int myset_length(struct myset *s)
{
 return s->len;
}


original_code:
void myset_clear(myset *s)
{
 mylist **cl, *dl;
 int i = 0;
 for(i = 0; i < s->size; i++){
  cl = &s->buckets[i];
  while(*cl){
   dl = *cl;
   *cl = (*cl)->next;
   cl = &(*cl)->next;
   mylist_free(dl);
  }
 }
 s->len = 0;
}

canonical_original_code:
void myset_clear(struct myset *s)
{
 struct _list **cl; struct _list *dl;
 int i = 0;
 for(i = 0; i < s->size; i++){
  cl = &s->buckets[i];
  while(*cl){
   dl = *cl;
   *cl = (*cl)->next;
   cl = &(*cl)->next;
   mylist_free(dl);
  }
 }
 s->len = 0;
}

variable_types: struct _list { void *data; struct _list *next; } **


decompiled_code:
void __fastcall myset_free(__int64 a1)
{
myset_clear(a1);
free(*(void **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1)
{
func13(a1);
free(*(void **)(a1 + 8));
}

original_code:
void myset_free(myset *s)
{
 myset_clear(s);
 free(s->buckets);
}

canonical_original_code:
void myset_free(struct myset *s)
{
 myset_clear(s);
 free(s->buckets);
}


decompiled_code:
__int64 __fastcall edge_cmp(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)(*(_QWORD *)a1 + 4LL) - *(_DWORD *)(*(_QWORD *)a2 + 4LL));
}

canonical_decompiled_code:
__int64 __fastcall func15(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)(*(_QWORD *)a1 + 4LL) - *(_DWORD *)(*(_QWORD *)a2 + 4LL));
}

original_code:
int edge_cmp(const void *a, const void *b)
{
 return (*(edge**)a)->weight - (*(edge**)b)->weight;
}

canonical_original_code:
int edge_cmp(void *a, void *b)
{
 return (*(struct edge **)a)->weight - (*(struct edge **)b)->weight;
}

variable_types:
a
void *

variable_types:
b
void *

user_defined_types: struct edge { char start; char end; int weight; }


hash

decompiled_code:
__int64 __fastcall hash(char *a1)
{
return (unsigned int)*a1;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *a1)
{
return (unsigned int)*a1;
}

original_code:
int hash(const void *a)
{
 return *(char*)a;
}

canonical_original_code:
int hash(void *a)
{
 return *(char *)a;
}


cmp

decompiled_code:
__int64 __fastcall cmp(char *a1, char *a2)
{
return (unsigned int)(*a1 - *a2);
}

canonical_decompiled_code:
__int64 __fastcall func17(char *a1, char *a2)
{
return (unsigned int)(*a1 - *a2);
}

original_code:
int cmp(const void *a, const void *b)
{
 return *(char*)a - *(char*)b;
}

canonical_original_code:
int cmp(void *a, void *b)
{
 return *(char *)a - *(char *)b;
}


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

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

original_code:
void mylist_free(mylist *l)
{
 free(l);
}

canonical_original_code:
void mylist_free(struct _list *l)
{
 free(l);
}


decompiled_code:
__int64 __fastcall mybtree_free(__int64 a1)
{
if ( a1 )
{
mybtree_free(*(_QWORD *)(a1 + 8));
mybtree_free(*(_QWORD *)(a1 + 16));
}
return 0LL;
}

original_code:
int mybtree_free(mybtree *root)
{
 if(root == ((void *)0))
  return 0;
 mybtree_free(root->left);
 mybtree_free(root->right);
 return 0;
}

canonical_original_code:
int mybtree_free(struct _mybtree *root)
{
 if(root == ((void *)0))
  return 0;
 mybtree_free(root->left);
 mybtree_free(root->right);
 return 0;
}

variable_types: struct _mybtree { void *value; struct _mybtree *left; struct _mybtree *right; } *


original_code:
mybtree* huffman_tree(frequency **f, int len, int (*compare_fun)(void*, void*))
{
 int i = 0;
 mybtree **heap = (mybtree**)malloc(len * sizeof(mybtree*));
 for(i = 0; i < len; i++)
  heap[i] = mybtree_new(f[i]);
 int son = 0;
 int parent = 0;
 mybtree *temp;
 for(i = 0; i < len; i++){
  son = i;
  parent = (son - 1) / 2;
  while(parent >= 0 && compare_fun(heap[son]->value, heap[parent]->value) < 0){
   { temp = heap[son]; heap[son] = heap[parent]; heap[parent] = temp; };
   son = parent;
   parent = (son - 1) / 2;
  }
 }
 mybtree *root = heap[0];
 frequency *fre;
 son = 1;
 parent = 0;
 while(len > 1){
  fre = (frequency*)malloc(sizeof(frequency));
  fre->symbol = ((void *)0);
  fre->weight = 0;
  root = mybtree_new(fre);
  for(i = 0; i < 2; i++){
   { temp = heap[0]; heap[0] = heap[len - 1]; heap[len - 1] = temp; };
   len--;
   if(i == 0)
    root->right = heap[len];
   else
    root->left = heap[len];
   fre->weight += ((frequency*)heap[len]->value)->weight;
   parent = 0;
   son = parent * 2 + 1;
   while(son < len){
    if(son < len - 1 && compare_fun(heap[son]->value, heap[son + 1]->value) > 0)
     son++;
    if(compare_fun(heap[parent]->value, heap[son]->value) < 0)
     break;
    { temp = heap[parent]; heap[parent] = heap[son]; heap[son] = temp; };
    parent = son;
    son = parent * 2 + 1;
   }
  }
  heap[len] = root;
  len++;
  son = len - 1;
  parent = (son - 1) / 2;
  while(parent >= 0 && compare_fun(heap[son]->value, heap[parent]->value) < 0){
   { temp = heap[son]; heap[son] = heap[parent]; heap[parent] = temp; };
   son = parent;
   parent = (son - 1) / 2;
  }
 }
 root = heap[0];
 free(heap);
 return root;
}

canonical_original_code:
struct _mybtree *huffman_tree(struct frequency **f, int len, int (*compare_fun)(void *, void *))
{
 int i = 0;
 struct _mybtree **heap = (mybtree**)malloc(len * sizeof(mybtree*));
 for(i = 0; i < len; i++)
  heap[i] = mybtree_new(f[i]);
 int son = 0;
 int parent = 0;
 struct _mybtree *temp;
 for(i = 0; i < len; i++){
  son = i;
  parent = (son - 1) / 2;
  while(parent >= 0 && compare_fun(heap[son]->value, heap[parent]->value) < 0){
   { temp = heap[son]; heap[son] = heap[parent]; heap[parent] = temp; };
   son = parent;
   parent = (son - 1) / 2;
  }
 }
 struct _mybtree *root = heap[0];
 struct frequency *fre;
 son = 1;
 parent = 0;
 while(len > 1){
  fre = (struct frequency *)malloc(sizeof(frequency));
  fre->symbol = ((void *)0);
  fre->weight = 0;
  root = mybtree_new(fre);
  for(i = 0; i < 2; i++){
   { temp = heap[0]; heap[0] = heap[len - 1]; heap[len - 1] = temp; };
   len--;
   if(i == 0)
    root->right = heap[len];
   else
    root->left = heap[len];
   fre->weight += ((struct frequency *)heap[len]->value)->weight;
   parent = 0;
   son = parent * 2 + 1;
   while(son < len){
    if(son < len - 1 && compare_fun(heap[son]->value, heap[son + 1]->value) > 0)
     son++;
    if(compare_fun(heap[parent]->value, heap[son]->value) < 0)
     break;
    { temp = heap[parent]; heap[parent] = heap[son]; heap[son] = temp; };
    parent = son;
    son = parent * 2 + 1;
   }
  }
  heap[len] = root;
  len++;
  son = len - 1;
  parent = (son - 1) / 2;
  while(parent >= 0 && compare_fun(heap[son]->value, heap[parent]->value) < 0){
   { temp = heap[son]; heap[son] = heap[parent]; heap[parent] = temp; };
   son = parent;
   parent = (son - 1) / 2;
  }
 }
 root = heap[0];
 free(heap);
 return root;
}

variable_types: struct frequency { void *symbol; int weight; } **

variable_types: len int

variable_types: struct _mybtree { void *value; struct _mybtree *left; struct _mybtree *right; } **

variable_types: son int

variable_types: parent int


decompiled_code:
_BOOL8 __fastcall search_symbol(__int64 a1, char a2, _BYTE *a3, __int64 a4, __int64 a5)
{
char *v6; // rax
char v7; // al
_BOOL8 result; // rax
_BYTE *v9; // r13
__int64 v10; // rcx
__int64 v11; // r8

if ( !a1 )
return 0LL;
v6 = **(char ***)a1;
if ( v6 )
{
v7 = *v6;
*a3 = 0;
result = v7 == a2;
}
else
{
v9 = a3 + 1;
if ( (unsigned int)search_symbol(*(_QWORD *)(a1 + 8), (unsigned int)a2, a3 + 1, a4, a5) )
{
*a3 = 48;
result = 1LL;
}
else if ( (unsigned int)search_symbol(*(_QWORD *)(a1 + 16), (unsigned int)a2, v9, v10, v11) )
{
*a3 = 49;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1, char a2, _BYTE *a3, __int64 a4, __int64 a5)
{
char *v6; // rax
char v7; // al
_BOOL8 result; // rax
_BYTE *v9; // r13
__int64 v10; // rcx
__int64 v11; // r8

if ( !a1 )
return 0LL;
v6 = **(char ***)a1;
if ( v6 )
{
v7 = *v6;
*a3 = 0;
result = v7 == a2;
}
else
{
v9 = a3 + 1;
if ( (unsigned int)func10(*(_QWORD *)(a1 + 8), (unsigned int)a2, a3 + 1, a4, a5) )
{
*a3 = 48;
result = 1LL;
}
else if ( (unsigned int)func10(*(_QWORD *)(a1 + 16), (unsigned int)a2, v9, v10, v11) )
{
*a3 = 49;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int search_symbol(mybtree *huff, char c, char *s)
{
 if(huff == ((void *)0))
  return 0;
 frequency *f = huff->value;
 if(f->symbol == ((void *)0)){
  if(search_symbol(huff->left, c, s + 1))
   *s = '0';
  else if(search_symbol(huff->right, c, s + 1))
   *s = '1';
  else
   return 0;
  return 1;
 }
 char val = *(char*)f->symbol;
 *s = '\0';
 return (val == c);
}

canonical_original_code:
int search_symbol(struct _mybtree *huff, char c, char *s)
{
 if(huff == ((void *)0))
  return 0;
 struct frequency *f = huff->value;
 if(f->symbol == ((void *)0)){
  if(search_symbol(huff->left, c, s + 1))
   *s = '0';
  else if(search_symbol(huff->right, c, s + 1))
   *s = '1';
  else
   return 0;
  return 1;
 }
 char val = *(char*)f->symbol;
 *s = '\0';
 return (val == c);
}

variable_types: c char

variable_types:
s
char *

variable_types: struct frequency { void *symbol; int weight; } *

variable_types: val char

user_defined_types: struct _mybtree { void *value; struct _mybtree *left; struct _mybtree *right; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
size_t v4; // r14
const char *v5; // r12
char *v6; // r13
int v8; // [rsp+Ch] [rbp-43Ch]
char s[1064]; // [rsp+20h] [rbp-428h] BYREF

puts("input how many symbol");
__isoc99_scanf();
malloc(1uLL);
v3 = malloc(0LL);
puts("input the string need to encode");
__isoc99_scanf();
v4 = strlen(s);
huffman_tree(v3, 0LL, compare);
malloc(0LL);
v8 = (int)(log2((double)0) + 2.0);
v5 = (const char *)malloc((int)v4 * v8);
if ( v4 )
{
v6 = s;
do
++v6;
while ( v6 != &s[(unsigned int)(v4 - 1) + 1] );
}
printf("%s: %s\n", s, v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
size_t v4; // r14
const char *v5; // r12
char *v6; // r13
int v8; // [rsp+Ch] [rbp-43Ch]
char s[1064]; // [rsp+20h] [rbp-428h] BYREF

puts("input how many symbol");
__isoc99_scanf();
malloc(1uLL);
v3 = malloc(0LL);
puts("input the string need to encode");
__isoc99_scanf();
v4 = strlen(s);
func9(v3, 0LL, compare);
malloc(0LL);
v8 = (int)(log2((double)0) + 2.0);
v5 = (const char *)malloc((int)v4 * v8);
if ( v4 )
{
v6 = s;
do
++v6;
while ( v6 != &s[(unsigned int)(v4 - 1) + 1] );
}
printf("%s: %s\n", s, v5);
return 0;
}

original_code:
int main(){
 char s[1000];
 int len = 0;
 printf("input how many symbol\n");
 scanf("%d", &len);
 char *sym = (char*)malloc((len + 1) * sizeof(char));
 frequency **f = (frequency**)malloc(len * sizeof(frequency*));
 int i = 0, j = 0;
 for(i = 0; i < len; i++){
  f[i] = (frequency*)malloc(sizeof(frequency));
  scanf("%s %d", &sym[i], &f[i]->weight);
  f[i]->symbol = &sym[i];
 }
 printf("input the string need to encode\n");
 scanf("%s", s);
 int slen = strlen(s);
 mybtree *huffman = huffman_tree(f, len, compare);
 char **table = (char**)malloc(len * sizeof(char*));
 int l = log2(len) + 2;
 for(i = 0; i < len; i++){
  table[i] = (char*)malloc(l * sizeof(char));
  search_symbol(huffman, sym[i], table[i]);
  printf("%c: %s\n", sym[i], table[i]);
 }
 char *encode = (char*)malloc(l * slen * sizeof(char));
 char *ptr = encode;
 for(i = 0; i < slen; i++){
  for(j = 0; j < len; j++){
   if(s[i] == sym[j]){
    ptr += sprintf(ptr, table[j]);
    break;
   }
  }
 }
 printf("%s: %s\n", s, encode);
 return 0;
}

canonical_original_code:
int main(){
 char s[1000];
 int len = 0;
 printf("input how many symbol\n");
 scanf("%d", &len);
 char *sym = (char*)malloc((len + 1) * sizeof(char));
 struct frequency **f = (frequency**)malloc(len * sizeof(frequency*));
 int i = 0; int j = 0;
 for(i = 0; i < len; i++){
  f[i] = (struct frequency *)malloc(sizeof(frequency));
  scanf("%s %d", &sym[i], &f[i]->weight);
  f[i]->symbol = &sym[i];
 }
 printf("input the string need to encode\n");
 scanf("%s", s);
 int slen = strlen(s);
 struct _mybtree *huffman = huffman_tree(f, len, compare);
 char **table = (char**)malloc(len * sizeof(char*));
 int l = log2(len) + 2;
 for(i = 0; i < len; i++){
  table[i] = (char *)malloc(l * sizeof(char));
  search_symbol(huffman, sym[i], table[i]);
  printf("%c: %s\n", sym[i], table[i]);
 }
 char *encode = (char*)malloc(l * slen * sizeof(char));
 char *ptr = encode;
 for(i = 0; i < slen; i++){
  for(j = 0; j < len; j++){
   if(s[i] == sym[j]){
    ptr += sprintf(ptr, table[j]);
    break;
   }
  }
 }
 printf("%s: %s\n", s, encode);
 return 0;
}

variable_types:
sym
char *

variable_types: j int

variable_types: slen int

variable_types:
table
char **

variable_types: l int

variable_types:
encode
char *

variable_types:
ptr
char *

user_defined_types: struct frequency { void *symbol; int weight; }


compare

decompiled_code:
__int64 __fastcall compare(__int64 a1, __int64 a2)
{
return (unsigned int)(*(_DWORD *)(a1 + 8) - *(_DWORD *)(a2 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
return (unsigned int)(*(_DWORD *)(a1 + 8) - *(_DWORD *)(a2 + 8));
}

original_code:
int compare(void *a, void *b)
{
 return (((frequency*)a)->weight - ((frequency*)b)->weight);
}

canonical_original_code:
int compare(void *a, void *b)
{
 return (((struct frequency *)a)->weight - ((struct frequency *)b)->weight);
}

variable_types:
a
void *

variable_types:
b
void *


original_code:
int mystack_push(mystack *s, void *val)
{
 mylist *list;
 int pos = s->length % s->size;
 if(pos == 0){
  list = mylist_new(s->size);
  list->next = s->head;
  s->head = list;
 }
 list = s->head;
 list->value[pos] = val;
 s->length++;
 return 0;
}

canonical_original_code:
int mystack_push(struct mystack *s, void *val)
{
 struct _list *list;
 int pos = s->length % s->size;
 if(pos == 0){
  list = mylist_new(s->size);
  list->next = s->head;
  s->head = list;
 }
 list = s->head;
 list->value[pos] = val;
 s->length++;
 return 0;
}

variable_types: struct mystack { int length; int size; struct _list { void **value; struct _list *next; } *head; } *

variable_types:
val
void *

variable_types: pos int

user_defined_types: struct mystack { int length; int size; struct _list *head; }


original_code:
void* mystack_pop(mystack *s)
{
 if(s->length == 0)
  return ((void *)0);
 s->length--;
 mylist *list = s->head;
 int pos = s->length % s->size;
 void *rtn = list->value[pos];
 list->value[pos] = ((void *)0);
 if(pos == 0){
  s->head = list->next;
  mylist_free(list);
 }
 return rtn;
}

canonical_original_code:
void *mystack_pop(struct mystack *s)
{
 if(s->length == 0)
  return ((void *)0);
 s->length--;
 struct _list *list = s->head;
 int pos = s->length % s->size;
 void *rtn = list->value[pos];
 list->value[pos] = ((void *)0);
 if(pos == 0){
  s->head = list->next;
  mylist_free(list);
 }
 return rtn;
}

variable_types: struct _list { void **value; struct _list *next; } *

variable_types:
rtn
void *

return_type: void *


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

if ( *(_DWORD *)a1 )
result = *(_QWORD *)(**(_QWORD **)(a1 + 8) + 8LL * ((*(_DWORD *)a1 - 1) % *(_DWORD *)(a1 + 4)));
else
result = 0LL;
return result;
}

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

if ( *(_DWORD *)a1 )
result = *(_QWORD *)(**(_QWORD **)(a1 + 8) + 8LL * ((*(_DWORD *)a1 - 1) % *(_DWORD *)(a1 + 4)));
else
result = 0LL;
return result;
}

original_code:
void* mystack_top(mystack *s)
{
 if(s->length == 0)
  return ((void *)0);
 mylist *list = s->head;
 int pos = (s->length - 1) % s->size;
 return list->value[pos];
}

canonical_original_code:
void *mystack_top(struct mystack *s)
{
 if(s->length == 0)
  return ((void *)0);
 struct _list *list = s->head;
 int pos = (s->length - 1) % s->size;
 return list->value[pos];
}

user_defined_types: struct _list { void **value; struct _list *next; }


decompiled_code:
_BOOL8 __fastcall mystack_empty(_DWORD *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(_DWORD *a1)
{
return *a1 == 0;
}

original_code:
int mystack_empty(mystack *s)
{
 return s->length == 0;
}

canonical_original_code:
int mystack_empty(struct mystack *s)
{
 return s->length == 0;
}


decompiled_code:
__int64 __fastcall mystack_flush(__int64 a1)
{
_QWORD *i; // rdi

for ( i = *(_QWORD **)(a1 + 8); i; i = *(_QWORD **)(a1 + 8) )
{
*(_QWORD *)(a1 + 8) = i[1];
mylist_free_isra_0(i);
}
return 0LL;
}

original_code:
int mystack_flush(mystack *s)
{
 mylist *list;
 while(s->head != ((void *)0)){
  list = s->head;
  s->head = s->head->next;
  mylist_free(list);
 }
 return 0;
}

canonical_original_code:
int mystack_flush(struct mystack *s)
{
 struct _list *list;
 while(s->head != ((void *)0)){
  list = s->head;
  s->head = s->head->next;
  mylist_free(list);
 }
 return 0;
}


decompiled_code:
__int64 __fastcall mystack_free(void *ptr)
{
mystack_flush((__int64)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(void *ptr)
{
func12((__int64)ptr);
free(ptr);
return 0LL;
}

original_code:
int mystack_free(mystack *s)
{
 mystack_flush(s);
 free(s);
 return 0;
}

canonical_original_code:
int mystack_free(struct mystack *s)
{
 mystack_flush(s);
 free(s);
 return 0;
}


priority

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

switch ( a1 )
{
case '(':
result = 0LL;
break;
case '*':
case '/':
result = 3LL;
break;
case '+':
case '-':
result = 2LL;
break;
default:
return result;
}
return result;
}

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

switch ( a1 )
{
case '(':
result = 0LL;
break;
case '*':
case '/':
result = 3LL;
break;
case '+':
case '-':
result = 2LL;
break;
default:
return result;
}
return result;
}

original_code:
int priority(char a)
{
 switch(a){
  case '*':
  case '/':
   return 3;
  case '+':
  case '-':
   return 2;
  case '(':
   return 0;
 }
}

variable_types: a char


decompiled_code:
void __fastcall combine_rule(char a1, char a2)
{
char v2; // cl
__int64 v3; // rax

v2 = a1 - 40;
if ( (unsigned __int8)(a1 - 40) <= 0x36u )
{
if ( ((1LL << v2) & 0xAD) != 0 )
{
priority(a1);
priority(a2);
}
else
{
v3 = 1LL << v2;
if ( _bittest64(&v3, 0x36u) )
{
priority(94);
priority(a2);
}
}
}
}

original_code:
int combine_rule(char a, char b)
{
 switch(a){
  case '+':
  case '-':
  case '*':
  case '/':
  case '(':
   return priority(a) >= priority(b);
  case '^':
   return priority(a) > priority(b);
 }
}

variable_types: b char


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

if ( a3 == 45 )
return (unsigned int)(a1 - a2);
if ( a3 > 45 )
{
if ( a3 == 47 )
result = (unsigned int)(a1 / a2);
}
else if ( a3 == 42 )
{
result = (unsigned int)(a2 * a1);
}
else if ( a3 == 43 )
{
result = (unsigned int)(a1 + a2);
}
return result;
}

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

if ( a3 == 45 )
return (unsigned int)(a1 - a2);
if ( a3 > 45 )
{
if ( a3 == 47 )
result = (unsigned int)(a1 / a2);
}
else if ( a3 == 42 )
{
result = (unsigned int)(a2 * a1);
}
else if ( a3 == 43 )
{
result = (unsigned int)(a1 + a2);
}
return result;
}

original_code:
int eval_operator(int a, int b, int op)
{
 switch(op){
  case '*':
   return a * b;
  case '/':
   return a / b;
  case '+':
   return a + b;
  case '-':
   return a - b;
 }
}

variable_types: a int

variable_types: b int

variable_types: op int


decompiled_code:
__int64 __fastcall eval_posfix(const char *a1)
{
const char *v1; // rbx
int v2; // er12
int *v3; // rbp
__int64 v4; // r12
unsigned __int8 v5; // si
int v6; // er13
int v7; // eax
int v8; // eax
unsigned int v9; // ebx

v1 = a1;
v2 = strlen(a1);
v3 = mystack_new(10);
if ( v2 > 0 )
{
v4 = (__int64)&a1[v2 - 1 + 1];
do
{
while ( 1 )
{
v5 = *v1 - 48;
if ( v5 > 9u )
break;
++v1;
mystack_push(v3, (char)v5);
if ( v1 == (const char *)v4 )
goto LABEL_6;
}
++v1;
v6 = mystack_pop((__int64)v3);
v7 = mystack_pop((__int64)v3);
v8 = eval_operator(v7, v6, *(v1 - 1));
mystack_push(v3, v8);
}
while ( v1 != (const char *)v4 );
}
LABEL_6:
v9 = mystack_pop((__int64)v3);
mystack_free(v3);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func18(const char *a1)
{
const char *v1; // rbx
int v2; // er12
int *v3; // rbp
__int64 v4; // r12
unsigned __int8 v5; // si
int v6; // er13
int v7; // eax
int v8; // eax
unsigned int v9; // ebx

v1 = a1;
v2 = strlen(a1);
v3 = mystack_new(10);
if ( v2 > 0 )
{
v4 = (__int64)&a1[v2 - 1 + 1];
do
{
while ( 1 )
{
v5 = *v1 - 48;
if ( v5 > 9u )
break;
++v1;
func8(v3, (char)v5);
if ( v1 == (const char *)v4 )
goto LABEL_6;
}
++v1;
v6 = func9((__int64)v3);
v7 = func9((__int64)v3);
v8 = func17(v7, v6, *(v1 - 1));
func8(v3, v8);
}
while ( v1 != (const char *)v4 );
}
LABEL_6:
v9 = func9((__int64)v3);
func13(v3);
return v9;
}

original_code:
int eval_posfix(char *expr)
{
 int ans = 0;
 int len = strlen(expr);
 mystack *s = mystack_new(10);
 int i = 0;
 for(i = 0; i < len; i++){
  if('0' <= expr[i] && expr[i] <= '9')
   mystack_push(s, expr[i] - '0');
  else{
   int b = mystack_pop(s);
   int a = mystack_pop(s);
   mystack_push(s, eval_operator(a, b, expr[i]));
  }
 }
 ans = mystack_pop(s);
 mystack_free(s);
 return ans;
}

canonical_original_code:
int eval_posfix(char *expr)
{
 int ans = 0;
 int len = strlen(expr);
 struct mystack *s = mystack_new(10);
 int i = 0;
 for(i = 0; i < len; i++){
  if('0' <= expr[i] && expr[i] <= '9')
   mystack_push(s, expr[i] - '0');
  else{
   int b = mystack_pop(s);
   int a = mystack_pop(s);
   mystack_push(s, eval_operator(a, b, expr[i]));
  }
 }
 ans = mystack_pop(s);
 mystack_free(s);
 return ans;
}

variable_types:
expr
char *

variable_types: ans int

variable_types: len int

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
unsigned int v4; // eax
_BYTE v6[120]; // [rsp+0h] [rbp-78h] BYREF

__isoc99_scanf();
v3 = (const char *)infix_to_posfix(v6, v6);
puts(v3);
v4 = eval_posfix(v3);
printf("ans:%d\n", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
unsigned int v4; // eax
_BYTE v6[120]; // [rsp+0h] [rbp-78h] BYREF

__isoc99_scanf();
v3 = (const char *)func16(v6, v6);
puts(v3);
v4 = func18(v3);
printf("ans:%d\n", v4);
return 0;
}

original_code:
int main(){
 char expr[100];
 scanf("%s", expr);
 char *postfix = infix_to_posfix(expr);
 printf("%s\n", postfix);
 printf("ans:%d\n", eval_posfix(postfix));
 return 0;
}

variable_types:
expr
char [100]

variable_types:
postfix
char *


variable_types: struct _mybtree { void *value; struct _mybtree *left; struct _mybtree *right; } *


decompiled_code:
int __fastcall inorder_travel(char *a1)
{
char *v1; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
inorder_travel(*((_QWORD *)v1 + 1));
result = putchar(**(char **)v1);
v1 = (char *)*((_QWORD *)v1 + 2);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(char *a1)
{
char *v1; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
func15(*((_QWORD *)v1 + 1));
result = putchar(**(char **)v1);
v1 = (char *)*((_QWORD *)v1 + 2);
}
while ( v1 );
}
return result;
}

original_code:
void inorder_travel(mybtree *root)
{
 if(root != ((void *)0)){
  inorder_travel(root->left);
  printf("%c", *(char*)(root->value));
  inorder_travel(root->right);
 }
}

canonical_original_code:
void inorder_travel(struct _mybtree *root)
{
 if(root != ((void *)0)){
  inorder_travel(root->left);
  printf("%c", *(char *)(root->value));
  inorder_travel(root->right);
 }
}


decompiled_code:
__int64 __fastcall inorder_travel_stack(__int64 a1)
{
int *v2; // rbp
char **v3; // rbx

v2 = mystack_new(10);
while ( 1 )
{
for ( ; a1; a1 = *(_QWORD *)(a1 + 8) )
mystack_push(v2, a1);
if ( mystack_empty(v2) )
break;
v3 = (char **)mystack_pop((__int64)v2);
putchar(**v3);
a1 = (__int64)v3[2];
}
return mystack_free(v2);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
int *v2; // rbp
char **v3; // rbx

v2 = mystack_new(10);
while ( 1 )
{
for ( ; a1; a1 = *(_QWORD *)(a1 + 8) )
func8(v2, a1);
if ( func11(v2) )
break;
v3 = (char **)func9((__int64)v2);
putchar(**v3);
a1 = (__int64)v3[2];
}
return func13(v2);
}

original_code:
void inorder_travel_stack(mybtree *root)
{
 mybtree *current = root;
 mystack *s = mystack_new(10);
 while(current != ((void *)0) || !mystack_empty(s)){
  if(current != ((void *)0)){
   mystack_push(s, current);
   current = current->left;
  }
  else{
   current = (mybtree*)mystack_pop(s);
   printf("%c", *(char*)(current->value));
   current = current->right;
  }
 }
 mystack_free(s);
}

canonical_original_code:
void inorder_travel_stack(struct _mybtree *root)
{
 struct _mybtree *current = root;
 struct mystack *s = mystack_new(10);
 while(current != ((void *)0) || !mystack_empty(s)){
  if(current != ((void *)0)){
   mystack_push(s, current);
   current = current->left;
  }
  else{
   current = (struct _mybtree *)mystack_pop(s);
   printf("%c", *(char *)(current->value));
   current = current->right;
  }
 }
 mystack_free(s);
}

variable_types: struct mystack { int length; int size; struct _list { void **value; struct _list *next; } *head; } *


repo: tjordanchat/eag

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

if ( !*(_DWORD *)(a1 + 16) )
{
result = *(unsigned int *)(a1 + 28);
if ( !(_DWORD)result )
*(_DWORD *)(a1 + 28) = 2;
}
return result;
}

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

if ( !*(_DWORD *)(a1 + 16) )
{
result = *(unsigned int *)(a1 + 28);
if ( !(_DWORD)result )
*(_DWORD *)(a1 + 28) = 2;
}
return result;
}

original_code:
static void finish_meta_rule_nullability (meta_rule mrule)
 { if (mrule -> ext) return;
   if (mrule -> empty == 0)
      mrule -> empty = 2;
 }

canonical_original_code:
static void finish_meta_rule_nullability(struct meta_rule_rec *mrule)
 { if (mrule -> ext) return;
   if (mrule -> empty == 0)
      mrule -> empty = 2;
 }

variable_types: struct meta_rule_rec { char *nonterminal; struct meta_alt_list_rec { int size; int room; struct meta_alt_rec { struct expr_rec { int tag; union { struct affix_rec { char *name; int type; struct affix_rec *next; struct value_rec { int admin_nr; int ref_count; void *dptr; int tag; union { char *str; int inum; double rnum; struct value_list_rec { int size; int room; struct value_rec **array; } *tuple; int slat; struct int_list_rec { int size; int room; int *array; } *elat; struct value_rec *free; } u; } *val; int ref_count; int reachable; int tag; union { struct variable_rec { char *nonterminal; char *suffix; struct meta_rule_rec *def; } var; char *str; int inum; double rnum; struct cset_rec { int kind; char *str; } *semi; struct element_rec { char *eltnm; struct element_def_rec { char *eltnm; int number; int eltnr; struct element_set_rec { int number; struct element_def_list_rec { int size; int room; struct element_def_rec **array; } *defs; } *set; } *def; } elt; struct expr_rec *cexpr; } u; } *single; struct affix_list_rec { int size; int room; struct affix_rec **array; } *compos; struct affix_list_rec *concat; struct affix_list_rec *uni; } u; } *e; int number; } **array; } *alts; int ext; int type; int kind; int empty; int number; struct value_rec *mvalue; int reachable; struct element_def_rec *lat_repr; int needs_rec; int needs_recbup; } *

user_defined_types: struct meta_rule_rec { char *nonterminal; struct meta_alt_list_rec *alts; int ext; int type; int kind; int empty; int number; struct value_rec *mvalue; int reachable; struct element_def_rec *lat_repr; int needs_rec; int needs_recbup; }

user_defined_types: struct meta_alt_list_rec { int size; int room; struct meta_alt_rec **array; }

user_defined_types: struct meta_alt_rec { struct expr_rec *e; int number; }

user_defined_types: struct expr_rec { int tag; union { struct affix_rec *single; struct affix_list_rec *compos; struct affix_list_rec *concat; struct affix_list_rec *uni; } u; }

user_defined_types: struct affix_rec { char *name; int type; struct affix_rec *next; struct value_rec *val; int ref_count; int reachable; int tag; union { struct variable_rec var; char *str; int inum; double rnum; struct cset_rec *semi; struct element_rec elt; struct expr_rec *cexpr; } u; }

user_defined_types: struct value_rec { int admin_nr; int ref_count; void *dptr; int tag; union { char *str; int inum; double rnum; struct value_list_rec *tuple; int slat; struct int_list_rec *elat; struct value_rec *free; } u; }

user_defined_types: struct element_rec { char *eltnm; struct element_def_rec *def; }

user_defined_types: struct element_def_rec { char *eltnm; int number; int eltnr; struct element_set_rec *set; }

user_defined_types: struct element_set_rec { int number; struct element_def_list_rec *defs; }