NP

decompiled_code:
__int64 __fastcall NP(__int64 a1)
{
return a1 + 496;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1 + 496;
}

original_code:
static inline struct pp_net_path *NP(struct pp_instance *ppi)
{
 return &ppi->np;
}

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 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; } *

return_type: 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; } *

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 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 DSTimeProperties { short currentUtcOffset; enum Boolean currentUtcOffsetValid; enum Boolean leap59; enum Boolean leap61; enum Boolean timeTraceable; enum Boolean frequencyTraceable; enum Boolean ptpTimescale; unsigned char timeSource; }


repo: tinito/ppsi-chibios

decompiled_code:
__int64 __fastcall pp_get_header(__int64 a1, __int64 a2)
{
return a2 - *(int *)(NP(a1) + 68);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return a2 - *(int *)(func0(a1) + 68);
}

original_code:
static inline void *pp_get_header(struct pp_instance *ppi, void *ptp_payload)
{
 return ptp_payload - NP(ppi)->ptp_offset;
}

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; } *

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_frgn_master { struct PortIdentity port_id; struct MsgAnnounce ann; struct MsgHeader hdr; }

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 Timestamp { struct UInteger48 secondsField; unsigned int nanosecondsField; }


decompiled_code:
__int64 __fastcall pp_get_payload(__int64 a1, __int64 a2)
{
return a2 + *(int *)(NP(a1) + 68);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return a2 + *(int *)(func0(a1) + 68);
}

original_code:
static inline void *pp_get_payload(struct pp_instance *ppi, void *frame_ptr)
{
 return frame_ptr + NP(ppi)->ptp_offset;
}

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 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 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 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 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 ClockQuality { unsigned char clockClass; unsigned char clockAccuracy; unsigned short offsetScaledLogVariance; }

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

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

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


original_code:
static void st_com_add_foreign(struct pp_instance *ppi, unsigned char *buf)
{
 int i;
 MsgHeader *hdr = &ppi->received_ptp_header;
 for (i = 0; i < ppi->frgn_rec_num; i++) {
  if (!memcmp(&hdr->sourcePortIdentity,
       &ppi->frgn_master[i].port_id,
       sizeof(hdr->sourcePortIdentity))) {
   msg_copy_header(&ppi->frgn_master[i].hdr, hdr);
   msg_unpack_announce(buf, &ppi->frgn_master[i].ann);
   return;
  }
 }
 if (ppi->frgn_rec_num < 5)
  ppi->frgn_rec_num++;
 i = ppi->frgn_rec_i;
 memcpy(&ppi->frgn_master[i].port_id,
        &hdr->sourcePortIdentity, sizeof(hdr->sourcePortIdentity));
 msg_copy_header(&ppi->frgn_master[i].hdr, hdr);
 msg_unpack_announce(buf, &ppi->frgn_master[i].ann);
 ({ if (1) __pp_diag(ppi, pp_dt_bmc, 2, "New foreign Master added\n"); 1; });
 ppi->frgn_rec_i = (ppi->frgn_rec_i+1) %
  5;
}

canonical_original_code:
static void st_com_add_foreign(struct pp_instance *ppi, unsigned char *buf)
{
 int i;
 struct MsgHeader *hdr = &ppi->received_ptp_header;
 for (i = 0; i < ppi->frgn_rec_num; i++) {
  if (!memcmp(&hdr->sourcePortIdentity,
       &ppi->frgn_master[i].port_id,
       sizeof(hdr->sourcePortIdentity))) {
   msg_copy_header(&ppi->frgn_master[i].hdr, hdr);
   msg_unpack_announce(buf, &ppi->frgn_master[i].ann);
   return;
  }
 }
 if (ppi->frgn_rec_num < 5)
  ppi->frgn_rec_num++;
 i = ppi->frgn_rec_i;
 memcpy(&ppi->frgn_master[i].port_id,
        &hdr->sourcePortIdentity, sizeof(hdr->sourcePortIdentity));
 msg_copy_header(&ppi->frgn_master[i].hdr, hdr);
 msg_unpack_announce(buf, &ppi->frgn_master[i].ann);
 ({ if (1) __pp_diag(ppi, pp_dt_bmc, 2, "New foreign Master added\n"); 1; });
 ppi->frgn_rec_i = (ppi->frgn_rec_i+1) %
  5;
}

variable_types:
buf
unsigned char *

variable_types: i int

variable_types: 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 { struct ClockIdentity { unsigned char id[8]; } clockIdentity; unsigned short portNumber; } sourcePortIdentity; unsigned short sequenceId; unsigned char controlField; char logMessageInterval; } *

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 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_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 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 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 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 DSTimeProperties { short currentUtcOffset; enum Boolean currentUtcOffsetValid; enum Boolean leap59; enum Boolean leap61; enum Boolean timeTraceable; enum Boolean frequencyTraceable; enum Boolean ptpTimescale; unsigned char timeSource; }


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);
}

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 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 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 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 Timestamp { struct UInteger48 secondsField; unsigned int nanosecondsField; }

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; }


original_code:
void pp_prepare_pointers(struct pp_instance *ppi)
{
 ppi->tx_ptp = __align_pointer(pp_get_payload(ppi, ppi->tx_buffer));
 ppi->rx_ptp = __align_pointer(pp_get_payload(ppi, ppi->rx_buffer));
 ppi->tx_frame = pp_get_header(ppi, ppi->tx_ptp);
 ppi->rx_frame = pp_get_header(ppi, ppi->rx_ptp);
 if (0) {
  pp_printf("%p -> %p %p\n",
     ppi->tx_buffer, ppi->tx_frame, ppi->tx_ptp);
  pp_printf("%p -> %p %p\n",
     ppi->rx_buffer, ppi->rx_frame, ppi->rx_ptp);
 }
}

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 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_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 ClockQuality { unsigned char clockClass; unsigned char clockAccuracy; unsigned short offsetScaledLogVariance; }

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

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

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


decompiled_code:
__int64 __fastcall st_com_execute_slave(__int64 a1)
{
__int64 (*v1)(void); // rax
__int64 result; // rax
int v3; // eax

v1 = (__int64 (*)(void))pp_hooks[8];
if ( v1 )
{
result = v1();
if ( (_DWORD)result == 1 )
return 0LL;
if ( (int)result < 0 )
return result;
}
pp_timeout_z_constprop_0(a1);
if ( !v3 )
return 0LL;
*(_DWORD *)(a1 + 708) = 0;
if ( (*(_BYTE *)(a1 + 1416) & 4) != 0 || *(_BYTE *)(DSDEF_isra_0(*(_QWORD *)(a1 + 40)) + 14) == 0xFF )
{
*(_DWORD *)(a1 + 4) = 4;
pp_timeout_restart_annrec(a1);
return 0LL;
}
m1(a1);
*(_DWORD *)(a1 + 4) = 6;
return 0LL;
}

original_code:
int st_com_execute_slave(struct pp_instance *ppi)
{
 int ret = 0;
 if (pp_hooks.execute_slave)
  ret = pp_hooks.execute_slave(ppi);
 if (ret == 1)
  return 0;
 if (ret < 0)
  return ret;
 if (pp_timeout_z(ppi, PP_TO_ANN_RECEIPT)) {
  ppi->frgn_rec_num = 0;
  ppi->frgn_rec_i = 0;
  if (!ppi->slave_only &&
   DSDEF(ppi)->clockQuality.clockClass != 255) {
   m1(ppi);
   ppi->next_state = PPS_MASTER;
  } else {
   ppi->next_state = PPS_LISTENING;
   pp_timeout_restart_annrec(ppi);
  }
 }
 return 0;
}

variable_types: ret int

return_type: 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 pp_frgn_master { struct PortIdentity port_id; struct MsgAnnounce ann; struct MsgHeader hdr; }

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 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 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 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 DSTimeProperties { short currentUtcOffset; enum Boolean currentUtcOffsetValid; enum Boolean leap59; enum Boolean leap61; enum Boolean timeTraceable; enum Boolean frequencyTraceable; enum Boolean ptpTimescale; unsigned char timeSource; }


decompiled_code:
__int64 __fastcall st_com_slave_handle_announce(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // er12
void (__fastcall *v4)(__int64); // rax

if ( a3 <= 63 )
return (unsigned int)-1;
v3 = 0;
st_com_add_foreign(a1, a2);
pp_timeout_restart_annrec(a1);
*(_DWORD *)(a1 + 4) = bmc(a1);
v4 = (void (__fastcall *)(__int64))pp_hooks[9];
if ( v4 )
v4(a1);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // er12
void (__fastcall *v4)(__int64); // rax

if ( a3 <= 63 )
return (unsigned int)-1;
v3 = 0;
func4(a1, a2);
func10(a1);
*(_DWORD *)(a1 + 4) = bmc(a1);
v4 = (void (__fastcall *)(__int64))pp_hooks[9];
if ( v4 )
v4(a1);
return v3;
}

original_code:
int st_com_slave_handle_announce(struct pp_instance *ppi, unsigned char *buf,
     int len)
{
 if (len < 64)
  return -1;
 st_com_add_foreign(ppi, buf);
 pp_timeout_restart_annrec(ppi);
 ppi->next_state = bmc(ppi);
 if (pp_hooks.handle_announce)
  pp_hooks.handle_announce(ppi);
 return 0;
}

variable_types: len 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_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 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 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 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 Timestamp { struct UInteger48 secondsField; unsigned int nanosecondsField; }

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; }


original_code:
int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
        int len)
{
 MsgHeader *hdr = &ppi->received_ptp_header;
 MsgSync sync;
 if (len < 44)
  return -1;
 if (!ppi->is_from_cur_par)
  return 0;
 ppi->t2 = ppi->last_rcv_time;
 cField_to_TimeInternal(&ppi->cField, hdr->correctionfield);
 if ((hdr->flagField[0] & 2) != 0) {
  ppi->waiting_for_follow = TRUE;
  ppi->recv_sync_sequence_id = hdr->sequenceId;
  return 0;
 }
 msg_unpack_sync(buf, &sync);
 ppi->waiting_for_follow = FALSE;
 to_TimeInternal(&ppi->t1,
   &sync.originTimestamp);
 pp_update_offset(ppi, &ppi->cField);
 pp_update_clock(ppi);
 return 0;
}

canonical_original_code:
int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf, int len)
{
 struct MsgHeader *hdr = &ppi->received_ptp_header;
 struct MsgSync sync;
 if (len < 44)
  return -1;
 if (!ppi->is_from_cur_par)
  return 0;
 ppi->t2 = ppi->last_rcv_time;
 cField_to_TimeInternal(&ppi->cField, hdr->correctionfield);
 if ((hdr->flagField[0] & 2) != 0) {
  ppi->waiting_for_follow = TRUE;
  ppi->recv_sync_sequence_id = hdr->sequenceId;
  return 0;
 }
 msg_unpack_sync(buf, &sync);
 ppi->waiting_for_follow = FALSE;
 to_TimeInternal(&ppi->t1,
   &sync.originTimestamp);
 pp_update_offset(ppi, &ppi->cField);
 pp_update_clock(ppi);
 return 0;
}

variable_types: struct MsgSync { struct Timestamp { struct UInteger48 { unsigned int lsb; unsigned short msb; } secondsField; unsigned int nanosecondsField; } originTimestamp; }

user_defined_types: struct MsgSync { struct Timestamp originTimestamp; }

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

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 pp_frgn_master { struct PortIdentity port_id; struct MsgAnnounce ann; struct MsgHeader hdr; }

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 ClockIdentity { unsigned char id[8]; }

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 ClockQuality { unsigned char clockClass; unsigned char clockAccuracy; unsigned short offsetScaledLogVariance; }


decompiled_code:
__int64 __fastcall st_com_slave_handle_followup(__int64 a1, __int64 a2, int a3)
{
char v3; // al
__int64 v4; // rcx
__int64 v5; // rdx
__int64 result; // rax
__int64 (__fastcall *v7)(__int64, __int64); // rax
char v8[36]; // [rsp+0h] [rbp-24h] BYREF

if ( a3 <= 43 )
return 0xFFFFFFFFLL;
v3 = *(_BYTE *)(a1 + 1416);
if ( (v3 & 1) == 0 )
{
if ( (_DWORD)pp_diag_verbosity )
{
pp_printf("ERROR: %s: Follow up message is not from current parent\n", "st_com_slave_handle_followup");
return 0LL;
}
return 0LL;
}
if ( (v3 & 2) == 0 )
{
if ( (_DWORD)pp_diag_verbosity )
{
pp_printf("ERROR: %s: Slave was not waiting a follow up message\n", "st_com_slave_handle_followup");
return 0LL;
}
return 0LL;
}
v4 = *(unsigned __int16 *)(a1 + 1312);
v5 = *(unsigned __int16 *)(a1 + 1374);
if ( (_WORD)v4 != (_WORD)v5 )
{
if ( (_DWORD)pp_diag_verbosity )
{
pp_printf("ERROR: %s: SequenceID %d doesn't match last Sync message %d\n", "st_com_slave_handle_followup", v5, v4);
return 0LL;
}
return 0LL;
}
msg_unpack_follow_up(a2, v8);
*(_BYTE *)(a1 + 1416) &= 0xFDu;
to_TimeInternal(a1 + 568, v8);
v7 = (__int64 (__fastcall *)(__int64, __int64))pp_hooks[10];
if ( !v7 )
goto LABEL_16;
result = v7(a1, a1 + 568);
if ( (_DWORD)result == 1 )
return 0LL;
if ( (int)result >= 0 )
{
LABEL_16:
pp_update_offset(a1, a1 + 648);
pp_update_clock(a1);
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2, int a3)
{
char v3; // al
__int64 v4; // rcx
__int64 v5; // rdx
__int64 result; // rax
__int64 (__fastcall *v7)(__int64, __int64); // rax
char v8[36]; // [rsp+0h] [rbp-24h] BYREF

if ( a3 <= 43 )
return 0xFFFFFFFFLL;
v3 = *(_BYTE *)(a1 + 1416);
if ( (v3 & 1) == 0 )
{
if ( (_DWORD)pp_diag_verbosity )
{
pp_printf("ERROR: %s: Follow up message is not from current parent\n", "st_com_slave_handle_followup");
return 0LL;
}
return 0LL;
}
if ( (v3 & 2) == 0 )
{
if ( (_DWORD)pp_diag_verbosity )
{
pp_printf("ERROR: %s: Slave was not waiting a follow up message\n", "st_com_slave_handle_followup");
return 0LL;
}
return 0LL;
}
v4 = *(unsigned __int16 *)(a1 + 1312);
v5 = *(unsigned __int16 *)(a1 + 1374);
if ( (_WORD)v4 != (_WORD)v5 )
{
if ( (_DWORD)pp_diag_verbosity )
{
pp_printf("ERROR: %s: SequenceID %d doesn't match last Sync message %d\n", "st_com_slave_handle_followup", v5, v4);
return 0LL;
}
return 0LL;
}
msg_unpack_follow_up(a2, v8);
*(_BYTE *)(a1 + 1416) &= 0xFDu;
to_TimeInternal(a1 + 568, v8);
v7 = (__int64 (__fastcall *)(__int64, __int64))pp_hooks[10];
if ( !v7 )
goto LABEL_16;
result = v7(a1, a1 + 568);
if ( (_DWORD)result == 1 )
return 0LL;
if ( (int)result >= 0 )
{
LABEL_16:
pp_update_offset(a1, a1 + 648);
pp_update_clock(a1);
return 0LL;
}
return result;
}

original_code:
int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
     int len)
{
 MsgFollowUp follow;
 int ret = 0;
 MsgHeader *hdr = &ppi->received_ptp_header;
 if (len < 44)
  return -1;
 if (!ppi->is_from_cur_par) {
  if (pp_diag_verbosity) pp_printf("ERROR: " "%s: Follow up message is not from current parent\n", __func__);
  return 0;
 }
 if (!ppi->waiting_for_follow) {
  if (pp_diag_verbosity) pp_printf("ERROR: " "%s: Slave was not waiting a follow up message\n", __func__);
  return 0;
 }
 if (ppi->recv_sync_sequence_id != hdr->sequenceId) {
  if (pp_diag_verbosity) pp_printf("ERROR: " "%s: SequenceID %d doesn't match last Sync message %d\n", __func__, hdr->sequenceId, ppi->recv_sync_sequence_id);
  return 0;
 }
 msg_unpack_follow_up(buf, &follow);
 ppi->waiting_for_follow = FALSE;
 to_TimeInternal(&ppi->t1, &follow.preciseOriginTimestamp);
 if (pp_hooks.handle_followup)
  ret = pp_hooks.handle_followup(ppi, &ppi->t1, &ppi->cField);
 if (ret == 1)
  return 0;
 if (ret < 0)
  return ret;
 pp_update_offset(ppi, &ppi->cField);
 pp_update_clock(ppi);
 return 0;
}

canonical_original_code:
int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf, int len)
{
 struct MsgFollowUp follow;
 int ret = 0;
 struct MsgHeader *hdr = &ppi->received_ptp_header;
 if (len < 44)
  return -1;
 if (!ppi->is_from_cur_par) {
  if (pp_diag_verbosity) pp_printf("ERROR: " "%s: Follow up message is not from current parent\n", __func__);
  return 0;
 }
 if (!ppi->waiting_for_follow) {
  if (pp_diag_verbosity) pp_printf("ERROR: " "%s: Slave was not waiting a follow up message\n", __func__);
  return 0;
 }
 if (ppi->recv_sync_sequence_id != hdr->sequenceId) {
  if (pp_diag_verbosity) pp_printf("ERROR: " "%s: SequenceID %d doesn't match last Sync message %d\n", __func__, hdr->sequenceId, ppi->recv_sync_sequence_id);
  return 0;
 }
 msg_unpack_follow_up(buf, &follow);
 ppi->waiting_for_follow = FALSE;
 to_TimeInternal(&ppi->t1, &follow.preciseOriginTimestamp);
 if (pp_hooks.handle_followup)
  ret = pp_hooks.handle_followup(ppi, &ppi->t1, &ppi->cField);
 if (ret == 1)
  return 0;
 if (ret < 0)
  return ret;
 pp_update_offset(ppi, &ppi->cField);
 pp_update_clock(ppi);
 return 0;
}

variable_types: struct MsgFollowUp { struct Timestamp { struct UInteger48 { unsigned int lsb; unsigned short msb; } secondsField; unsigned int nanosecondsField; } preciseOriginTimestamp; }

user_defined_types: struct MsgFollowUp { struct Timestamp preciseOriginTimestamp; }

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 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_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_channel { union { int fd; void *custom; }; void *arch_data; unsigned char addr[6]; unsigned char peer[6]; int pkt_present; }

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 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 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 DSTimeProperties { short currentUtcOffset; enum Boolean currentUtcOffsetValid; enum Boolean leap59; enum Boolean leap61; enum Boolean timeTraceable; enum Boolean frequencyTraceable; enum Boolean ptpTimescale; unsigned char timeSource; }


decompiled_code:
__int64 __fastcall st_com_master_handle_announce(__int64 a1, __int64 a2, int a3)
{
if ( a3 <= 63 )
return 0xFFFFFFFFLL;
_pp_diag(a1, 3LL, 2LL, "Announce message from another foreign master\n");
st_com_add_foreign(a1, a2);
*(_DWORD *)(a1 + 4) = bmc(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, __int64 a2, int a3)
{
if ( a3 <= 63 )
return 0xFFFFFFFFLL;
_pp_diag(a1, 3LL, 2LL, "Announce message from another foreign master\n");
func4(a1, a2);
*(_DWORD *)(a1 + 4) = bmc(a1);
return 0LL;
}

original_code:
int st_com_master_handle_announce(struct pp_instance *ppi, unsigned char *buf,
      int len)
{
 if (len < 64)
  return -1;
 ({ if (1) __pp_diag(ppi, pp_dt_bmc, 2, "Announce message from another foreign master\n"); 1; });
 st_com_add_foreign(ppi, buf);
 ppi->next_state = bmc(ppi);
 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 pp_frgn_master { struct PortIdentity port_id; struct MsgAnnounce ann; struct MsgHeader hdr; }

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 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 Timestamp { struct UInteger48 secondsField; unsigned int nanosecondsField; }

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 PortIdentity { struct ClockIdentity clockIdentity; unsigned short portNumber; }

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


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

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

original_code:
int st_com_master_handle_sync(struct pp_instance *ppi, unsigned char *buf,
         int len)
{
 return 0;
}

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 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 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_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 ClockQuality { unsigned char clockClass; unsigned char clockAccuracy; unsigned short offsetScaledLogVariance; }

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


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

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

original_code:
int pp_pre_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
 return 0;
}

variable_types:
pkt
unsigned char *

variable_types: plen 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 pp_frgn_master { struct PortIdentity port_id; struct MsgAnnounce ann; struct MsgHeader hdr; }

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 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 DSCurrent { unsigned short stepsRemoved; struct TimeInternal offsetFromMaster; struct TimeInternal meanPathDelay; unsigned short primarySlavePortNumber; }

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 DSTimeProperties { short currentUtcOffset; enum Boolean currentUtcOffsetValid; enum Boolean leap59; enum Boolean leap61; enum Boolean timeTraceable; enum Boolean frequencyTraceable; enum Boolean ptpTimescale; unsigned char timeSource; }


decompiled_code:
int __fastcall dump_time(__int64 a1, int *a2)
{
const char *v2; // rax
time_t v4; // [rsp+0h] [rbp-68h] BYREF
__int64 v5; // [rsp+8h] [rbp-60h]
struct tm tp; // [rsp+10h] [rbp-58h] BYREF

v4 = *a2;
v5 = a2[1] / 1000;
localtime_r(&v4, &tp);
v2 = " invalid";
if ( a2[3] )
v2 = (const char *)&unk_904;
return printf(
"%sTIME: (%li - 0x%lx) %02i:%02i:%02i.%06li%s\n",
a1,
v4,
v4,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec,
v5,
v2);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int *a2)
{
const char *v2; // rax
time_t v4; // [rsp+0h] [rbp-68h] BYREF
__int64 v5; // [rsp+8h] [rbp-60h]
struct tm tp; // [rsp+10h] [rbp-58h] BYREF

v4 = *a2;
v5 = a2[1] / 1000;
localtime_r(&v4, &tp);
v2 = " invalid";
if ( a2[3] )
v2 = (const char *)&unk_904;
return printf(
"%sTIME: (%li - 0x%lx) %02i:%02i:%02i.%06li%s\n",
a1,
v4,
v4,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec,
v5,
v2);
}

original_code:
static void dump_time(char *prefix, struct TimeInternal *ti)
{
 struct timeval tv;
 struct tm tm;
 tv.tv_sec = ti->seconds;
 tv.tv_usec = ti->nanoseconds / 1000;
 localtime_r(&tv.tv_sec, &tm);
 printf("%sTIME: (%li - 0x%lx) %02i:%02i:%02i.%06li%s\n", prefix,
        tv.tv_sec, tv.tv_sec,
        tm.tm_hour, tm.tm_min, tm.tm_sec, (long)tv.tv_usec,
        !ti->correct ? " invalid" : "");
}

variable_types:
prefix
char *

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

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

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


variable_types:
s
char *

variable_types:
p
unsigned char *


original_code:
static void dump_eth(char *prefix, struct ethhdr *eth)
{
 unsigned char *d = eth->h_dest;
 unsigned char *s = eth->h_source;
 printf("%sETH: %04x (%02x:%02x:%02x:%02x:%02x:%02x -> "
        "%02x:%02x:%02x:%02x:%02x:%02x)\n", prefix, ntohs(eth->h_proto),
        s[0], s[1], s[2], s[3], s[4], s[5],
        d[0], d[1], d[2], d[3], d[4], d[5]);
}

variable_types: struct ethhdr { unsigned char h_dest[6]; unsigned char h_source[6]; unsigned short h_proto; } *

variable_types:
d
unsigned char *

variable_types:
s
unsigned char *


decompiled_code:
int __fastcall dump_1stamp(__int64 a1, __int64 a2, __int16 *a3)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // rsi
unsigned int v7; // eax
__int64 v8; // rcx
const char *v9; // rdx
const char *v10; // r9

_bswap_16(*a3);
_bswap_32(*(_DWORD *)(v3 + 2));
v6 = v5 << 32;
v7 = _bswap_32(*(_DWORD *)(v4 + 6));
return printf("%s%s%lu.%09i\n", v10, v9, v6 | v8, v7);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2, __int16 *a3)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // rsi
unsigned int v7; // eax
__int64 v8; // rcx
const char *v9; // rdx
const char *v10; // r9

func2(*a3);
func4(*(_DWORD *)(v3 + 2));
v6 = v5 << 32;
v7 = func4(*(_DWORD *)(v4 + 6));
return printf("%s%s%lu.%09i\n", v10, v9, v6 | v8, v7);
}

original_code:
static void dump_1stamp(char *prefix, char *s, struct stamp *t)
{
 uint64_t sec = (uint64_t)(ntohs(t->sec.msb)) << 32;
 sec |= (uint64_t)(ntohl(t->sec.lsb));
 printf("%s%s%lu.%09i\n", prefix,
        s, (unsigned long)sec, (int)ntohl(t->nsec));
}

canonical_original_code:
static void dump_1stamp(char *prefix, char *s, struct stamp *t)
{
 unsigned long sec = (uint64_t)(ntohs(t->sec.msb)) << 32;
 sec |= (unsigned long)(ntohl(t->sec.lsb));
 printf("%s%s%lu.%09i\n", prefix,
        s, (unsigned long)sec, (int)ntohl(t->nsec));
}

variable_types: struct stamp { struct int48 { unsigned short msb; unsigned int lsb; } sec; unsigned int nsec; } *

variable_types:
sec
unsigned long

user_defined_types: struct stamp { struct int48 sec; unsigned int nsec; }


decompiled_code:
// attributes: thunk
int __fastcall dump_msg_sync_etc(__int64 a1, __int64 a2, __int16 *a3)
{
return dump_1stamp(a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2, __int16 *a3)
{
return func5(a1, a2, a3);
}

original_code:
static void dump_msg_sync_etc(char *prefix, char *s, struct ptp_sync_etc *p)
{
 dump_1stamp(prefix, s, &p->stamp);
}

variable_types: struct ptp_sync_etc { struct stamp { struct int48 { unsigned short msb; unsigned int lsb; } sec; unsigned int nsec; } stamp; unsigned char port[10]; } *

user_defined_types: struct ptp_sync_etc { struct stamp stamp; unsigned char port[10]; }


decompiled_code:
int __fastcall dump_msg_resp_etc(const char *a1, const char *a2, __int64 a3)
{
dump_1stamp((__int64)a1, (__int64)a2, (__int16 *)a3);
return dump_1port(a1, a2, (unsigned __int8 *)(a3 + 10));
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, const char *a2, __int64 a3)
{
func5((__int64)a1, (__int64)a2, (__int16 *)a3);
return func1(a1, a2, (unsigned __int8 *)(a3 + 10));
}

original_code:
static void dump_msg_resp_etc(char *prefix, char *s, struct ptp_sync_etc *p)
{
 dump_1stamp(prefix, s, &p->stamp);
 dump_1port(prefix, s, p->port);
}

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


decompiled_code:
int __fastcall dump_msg_announce(const char *a1, __int64 a2)
{
dump_1stamp((__int64)a1, (__int64)"MSG-ANNOUNCE: stamp ", (__int16 *)a2);
dump_1quality_constprop_0_isra_0(a1, *(_BYTE *)(a2 + 14), *(_BYTE *)(a2 + 15), *(_WORD *)(a2 + 16));
printf("%sMSG-ANNOUNCE: grandmaster-prio %i %i\n", a1, *(unsigned __int8 *)(a2 + 13), *(unsigned __int8 *)(a2 + 18));
return dump_1clockid_constprop_0(a1, *(_QWORD *)(a2 + 19));
}

canonical_decompiled_code:
int __fastcall func10(const char *a1, __int64 a2)
{
func5((__int64)a1, (__int64)"MSG-ANNOUNCE: stamp ", (__int16 *)a2);
func9(a1, *(_BYTE *)(a2 + 14), *(_BYTE *)(a2 + 15), *(_WORD *)(a2 + 16));
printf("%sMSG-ANNOUNCE: grandmaster-prio %i %i\n", a1, *(unsigned __int8 *)(a2 + 13), *(unsigned __int8 *)(a2 + 18));
return func8(a1, *(_QWORD *)(a2 + 19));
}

original_code:
static void dump_msg_announce(char *prefix, struct ptp_announce *p)
{
 dump_1stamp(prefix, "MSG-ANNOUNCE: stamp ",
      &p->originTimestamp);
 dump_1quality(prefix, "MSG-ANNOUNCE: grandmaster-quality ",
        &p->grandmasterClockQuality);
 printf("%sMSG-ANNOUNCE: grandmaster-prio %i %i\n", prefix,
        p->grandmasterPriority1, p->grandmasterPriority2);
 dump_1clockid(prefix, "MSG-ANNOUNCE: grandmaster-id ",
        p->grandmasterIdentity);
}

variable_types: struct ptp_announce { struct stamp { struct int48 { unsigned short msb; unsigned int lsb; } sec; unsigned int nsec; } originTimestamp; short currentUtcOffset; unsigned char reserved46; unsigned char grandmasterPriority1; struct ClockQuality { unsigned char clockClass; unsigned char clockAccuracy; unsigned short offsetScaledLogVariance; } grandmasterClockQuality; unsigned char grandmasterPriority2; struct ClockIdentity { unsigned char id[8]; } grandmasterIdentity; unsigned short stepsRemoved; unsigned char timeSource; } *

user_defined_types: struct ptp_announce { struct stamp originTimestamp; short currentUtcOffset; unsigned char reserved46; unsigned char grandmasterPriority1; struct ClockQuality grandmasterClockQuality; unsigned char grandmasterPriority2; struct ClockIdentity grandmasterIdentity; unsigned short stepsRemoved; unsigned char timeSource; }


decompiled_code:
__int64 __fastcall dump_tlv(const char *a1, __int64 a2, unsigned int a3)
{
int v4; // er14
unsigned __int16 v5; // ax
unsigned int v6; // er12
__int64 result; // rax

v4 = (unsigned __int16)_bswap_16(*(_WORD *)(a2 + 2));
v5 = _bswap_16(*(_WORD *)a2);
v6 = v4 + 4;
printf(
"%sTLV: type %04x len %i oui %02x:%02x:%02x sub %02x:%02x:%02x\n",
a1,
v5,
(unsigned int)(v4 + 4),
*(unsigned __int8 *)(a2 + 4),
*(unsigned __int8 *)(a2 + 5),
*(unsigned __int8 *)(a2 + 6),
*(unsigned __int8 *)(a2 + 7),
*(unsigned __int8 *)(a2 + 8),
*(unsigned __int8 *)(a2 + 9));
if ( v4 + 4 > (int)a3 )
{
printf("%sTLV: too short (expected %i, total %i)\n", a1, v6, a3);
result = a3;
}
else
{
dumpstruct_isra_0(a1, "TLV: ", "tlv-content", (unsigned __int8 *)(a2 + 10), (unsigned int)(v4 - 6));
result = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1, __int64 a2, unsigned int a3)
{
int v4; // er14
unsigned __int16 v5; // ax
unsigned int v6; // er12
__int64 result; // rax

v4 = (unsigned __int16)func2(*(_WORD *)(a2 + 2));
v5 = func2(*(_WORD *)a2);
v6 = v4 + 4;
printf(
"%sTLV: type %04x len %i oui %02x:%02x:%02x sub %02x:%02x:%02x\n",
a1,
v5,
(unsigned int)(v4 + 4),
*(unsigned __int8 *)(a2 + 4),
*(unsigned __int8 *)(a2 + 5),
*(unsigned __int8 *)(a2 + 6),
*(unsigned __int8 *)(a2 + 7),
*(unsigned __int8 *)(a2 + 8),
*(unsigned __int8 *)(a2 + 9));
if ( v4 + 4 > (int)a3 )
{
printf("%sTLV: too short (expected %i, total %i)\n", a1, v6, a3);
result = a3;
}
else
{
func13(a1, "TLV: ", "tlv-content", (unsigned __int8 *)(a2 + 10), (unsigned int)(v4 - 6));
result = v6;
}
return result;
}

original_code:
static int dump_tlv(char *prefix, struct ptp_tlv *tlv, int totallen)
{
 int explen = ntohs(tlv->len) + 4;
 printf("%sTLV: type %04x len %i oui %02x:%02x:%02x "
        "sub %02x:%02x:%02x\n", prefix, ntohs(tlv->type), explen,
        tlv->oui[0], tlv->oui[1], tlv->oui[2],
        tlv->subtype[0], tlv->subtype[1], tlv->subtype[2]);
 if (explen > totallen) {
  printf("%sTLV: too short (expected %i, total %i)\n", prefix,
         explen, totallen);
  return totallen;
 }
 dumpstruct(prefix, "TLV: ", "tlv-content", tlv->data,
     explen - sizeof(*tlv));
 return explen;
}

variable_types: struct ptp_tlv { unsigned short type; unsigned short len; unsigned char oui[3]; unsigned char subtype[3]; unsigned char data[]; } *

variable_types: totallen int

variable_types: explen int


decompiled_code:
int __fastcall dump_payload(const char *a1, __int64 a2, unsigned int a3)
{
unsigned __int8 v4; // dl
unsigned __int8 v6; // r12
__int16 *v8; // r14
unsigned __int16 v9; // ax
__int64 v10; // rdx
unsigned __int16 v11; // ax
int v12; // er12
unsigned int v13; // edx

v4 = *(_BYTE *)(a2 + 1) & 0xF;
if ( v4 != 2 )
return printf("%sVERSION: unsupported (%i)\n", a1, v4);
v6 = *(_BYTE *)a2;
v8 = (__int16 *)(a2 + 34);
v9 = _bswap_16(*(_WORD *)(a2 + 2));
v6 &= 0xFu;
printf("%sVERSION: %i (type %i, len %i, domain %i)\n", a1, v10, v6, v9, *(unsigned __int8 *)(a2 + 4));
printf("%sFLAGS: 0x%04x (correction %08lu)\n", a1, *(unsigned __int16 *)(a2 + 6), *(_QWORD *)(a2 + 8));
dump_1port(a1, "PORT: ", (unsigned __int8 *)(a2 + 20));
v11 = _bswap_16(*(_WORD *)(a2 + 30));
printf(
"%sREST: seq %i, ctrl %i, log-interval %i\n",
a1,
v11,
*(unsigned __int8 *)(a2 + 32),
*(unsigned __int8 *)(a2 + 33));
switch ( v6 )
{
case 0u:
v12 = 44;
printf("%sMESSAGE: (E) SYNC\n", a1);
dump_msg_sync_etc((__int64)a1, (__int64)"MSG-SYNC: ", v8);
break;
case 1u:
v12 = 44;
printf("%sMESSAGE: (E) DELAY_REQ\n", a1);
dump_msg_sync_etc((__int64)a1, (__int64)"MSG-DELAY_REQ: ", v8);
break;
case 2u:
v12 = 54;
printf("%sMESSAGE: (E) PDELAY_REQ\n", a1);
dump_msg_sync_etc((__int64)a1, (__int64)"MSG-PDELAY_REQ: ", v8);
break;
case 3u:
v12 = 54;
printf("%sMESSAGE: (E) PDELAY_RESP\n", a1);
dump_msg_resp_etc(a1, "MSG-PDELAY_RESP: ", (__int64)v8);
break;
case 8u:
v12 = 44;
printf("%sMESSAGE: (G) FOLLOW_UP\n", a1);
dump_msg_sync_etc((__int64)a1, (__int64)"MSG-FOLLOW_UP: ", v8);
break;
case 9u:
v12 = 54;
printf("%sMESSAGE: (G) DELAY_RESP\n", a1);
dump_msg_resp_etc(a1, "MSG-DELAY_RESP: ", (__int64)v8);
break;
case 0xAu:
v12 = 54;
printf("%sMESSAGE: (G) PDELAY_RESP_FOLLOW_UP\n", a1);
dump_msg_resp_etc(a1, "MSG-PDELAY_RESP_FOLLOWUP: ", (__int64)v8);
break;
case 0xBu:
v12 = 64;
printf("%sMESSAGE: (G) ANNOUNCE\n", a1);
dump_msg_announce(a1, (__int64)v8);
break;
case 0xCu:
v12 = 44;
printf("%sMESSAGE: (G) SIGNALING\n", a1);
dump_1port(a1, "MSG-SIGNALING: target-port ", (unsigned __int8 *)v8);
break;
case 0xDu:
printf("%sMESSAGE: (G) MANAGEMENT\n", a1);
goto LABEL_5;
default:
LABEL_5:
v12 = 34;
break;
}
while ( (int)a3 > v12 )
{
v13 = a3 - v12;
if ( (int)(a3 - v12) <= 9 )
{
printf("%sTLV: too short (%i - %i = %i)\n", a1, a3, (unsigned int)v12, v13);
return dumpstruct_isra_0(a1, "DUMP: ", "payload", (unsigned __int8 *)a2, a3);
}
v12 += dump_tlv(a1, a2 + v12, v13);
}
return dumpstruct_isra_0(a1, "DUMP: ", "payload", (unsigned __int8 *)a2, a3);
}

canonical_decompiled_code:
int __fastcall func15(const char *a1, __int64 a2, unsigned int a3)
{
unsigned __int8 v4; // dl
unsigned __int8 v6; // r12
__int16 *v8; // r14
unsigned __int16 v9; // ax
__int64 v10; // rdx
unsigned __int16 v11; // ax
int v12; // er12
unsigned int v13; // edx

v4 = *(_BYTE *)(a2 + 1) & 0xF;
if ( v4 != 2 )
return printf("%sVERSION: unsupported (%i)\n", a1, v4);
v6 = *(_BYTE *)a2;
v8 = (__int16 *)(a2 + 34);
v9 = func2(*(_WORD *)(a2 + 2));
v6 &= 0xFu;
printf("%sVERSION: %i (type %i, len %i, domain %i)\n", a1, v10, v6, v9, *(unsigned __int8 *)(a2 + 4));
printf("%sFLAGS: 0x%04x (correction %08lu)\n", a1, *(unsigned __int16 *)(a2 + 6), *(_QWORD *)(a2 + 8));
func1(a1, "PORT: ", (unsigned __int8 *)(a2 + 20));
v11 = func2(*(_WORD *)(a2 + 30));
printf(
"%sREST: seq %i, ctrl %i, log-interval %i\n",
a1,
v11,
*(unsigned __int8 *)(a2 + 32),
*(unsigned __int8 *)(a2 + 33));
switch ( v6 )
{
case 0u:
v12 = 44;
printf("%sMESSAGE: (E) SYNC\n", a1);
func6((__int64)a1, (__int64)"MSG-SYNC: ", v8);
break;
case 1u:
v12 = 44;
printf("%sMESSAGE: (E) DELAY_REQ\n", a1);
func6((__int64)a1, (__int64)"MSG-DELAY_REQ: ", v8);
break;
case 2u:
v12 = 54;
printf("%sMESSAGE: (E) PDELAY_REQ\n", a1);
func6((__int64)a1, (__int64)"MSG-PDELAY_REQ: ", v8);
break;
case 3u:
v12 = 54;
printf("%sMESSAGE: (E) PDELAY_RESP\n", a1);
func7(a1, "MSG-PDELAY_RESP: ", (__int64)v8);
break;
case 8u:
v12 = 44;
printf("%sMESSAGE: (G) FOLLOW_UP\n", a1);
func6((__int64)a1, (__int64)"MSG-FOLLOW_UP: ", v8);
break;
case 9u:
v12 = 54;
printf("%sMESSAGE: (G) DELAY_RESP\n", a1);
func7(a1, "MSG-DELAY_RESP: ", (__int64)v8);
break;
case 0xAu:
v12 = 54;
printf("%sMESSAGE: (G) PDELAY_RESP_FOLLOW_UP\n", a1);
func7(a1, "MSG-PDELAY_RESP_FOLLOWUP: ", (__int64)v8);
break;
case 0xBu:
v12 = 64;
printf("%sMESSAGE: (G) ANNOUNCE\n", a1);
func10(a1, (__int64)v8);
break;
case 0xCu:
v12 = 44;
printf("%sMESSAGE: (G) SIGNALING\n", a1);
func1(a1, "MSG-SIGNALING: target-port ", (unsigned __int8 *)v8);
break;
case 0xDu:
printf("%sMESSAGE: (G) MANAGEMENT\n", a1);
goto LABEL_5;
default:
LABEL_5:
v12 = 34;
break;
}
while ( (int)a3 > v12 )
{
v13 = a3 - v12;
if ( (int)(a3 - v12) <= 9 )
{
printf("%sTLV: too short (%i - %i = %i)\n", a1, a3, (unsigned int)v12, v13);
return func13(a1, "DUMP: ", "payload", (unsigned __int8 *)a2, a3);
}
v12 += func14(a1, a2 + v12, v13);
}
return func13(a1, "DUMP: ", "payload", (unsigned __int8 *)a2, a3);
}

original_code:
static void dump_payload(char *prefix, void *pl, int len)
{
 struct ptp_header *h = pl;
 void *msg_specific = (void *)(h + 1);
 int donelen = 34;
 int version = h->versionPTP_and_reserved & 0xf;
 int messageType = h->type_and_transport_specific & 0xf;
 if (version != 2) {
  printf("%sVERSION: unsupported (%i)\n", prefix, version);
  return;
 }
 printf("%sVERSION: %i (type %i, len %i, domain %i)\n", prefix,
        version, messageType,
        ntohs(h->messageLength), h->domainNumber);
 printf("%sFLAGS: 0x%04x (correction %08lu)\n", prefix, h->flagField,
        (unsigned long)h->correctionField);
 dump_1port(prefix, "PORT: ", h->sourcePortIdentity);
 printf("%sREST: seq %i, ctrl %i, log-interval %i\n", prefix,
        ntohs(h->sequenceId), h->controlField, h->logMessageInterval);
 switch(messageType) {
  case PPM_SYNC: printf("%sMESSAGE: (" "E" ") " "SYNC" "\n", prefix);
  dump_msg_sync_etc(prefix, "MSG-SYNC: ", msg_specific);
  donelen = 44;
  break;
  case PPM_DELAY_REQ: printf("%sMESSAGE: (" "E" ") " "DELAY_REQ" "\n", prefix);
  dump_msg_sync_etc(prefix, "MSG-DELAY_REQ: ", msg_specific);
  donelen = 44;
  break;
  case PPM_FOLLOW_UP: printf("%sMESSAGE: (" "G" ") " "FOLLOW_UP" "\n", prefix);
  dump_msg_sync_etc(prefix, "MSG-FOLLOW_UP: ", msg_specific);
  donelen = 44;
  break;
  case PPM_DELAY_RESP: printf("%sMESSAGE: (" "G" ") " "DELAY_RESP" "\n", prefix);
  dump_msg_resp_etc(prefix, "MSG-DELAY_RESP: ", msg_specific);
  donelen = 54;
  break;
  case PPM_ANNOUNCE: printf("%sMESSAGE: (" "G" ") " "ANNOUNCE" "\n", prefix);
  dump_msg_announce(prefix, msg_specific);
  donelen = 64;
  break;
  case PPM_SIGNALING: printf("%sMESSAGE: (" "G" ") " "SIGNALING" "\n", prefix);
  dump_1port(prefix, "MSG-SIGNALING: target-port ", msg_specific);
  donelen = 44;
  break;
  case PPM_PDELAY_REQ: printf("%sMESSAGE: (" "E" ") " "PDELAY_REQ" "\n", prefix);
  dump_msg_sync_etc(prefix, "MSG-PDELAY_REQ: ", msg_specific);
  donelen = 54;
  break;
  case PPM_PDELAY_RESP: printf("%sMESSAGE: (" "E" ") " "PDELAY_RESP" "\n", prefix);
  dump_msg_resp_etc(prefix, "MSG-PDELAY_RESP: ", msg_specific);
  donelen = 54;
  break;
  case PPM_PDELAY_RESP_FOLLOW_UP: printf("%sMESSAGE: (" "G" ") " "PDELAY_RESP_FOLLOW_UP" "\n", prefix);
  dump_msg_resp_etc(prefix, "MSG-PDELAY_RESP_FOLLOWUP: ",
      msg_specific);
  donelen = 54;
  break;
  case PPM_MANAGEMENT: printf("%sMESSAGE: (" "G" ") " "MANAGEMENT" "\n", prefix);
  break;
 }
 while (donelen < len) {
  int n = len - donelen;
  if (n < sizeof(struct ptp_tlv)) {
   printf("%sTLV: too short (%i - %i = %i)\n", prefix,
          len, donelen, n);
   break;
  }
  donelen += dump_tlv(prefix, pl + donelen, n);
 }
 dumpstruct(prefix, "DUMP: ", "payload", pl, len);
}

variable_types:
pl
void *

variable_types: len int

variable_types: struct ptp_header { unsigned char type_and_transport_specific; unsigned char versionPTP_and_reserved; unsigned short messageLength; unsigned char domainNumber; unsigned char reserved5; unsigned short flagField; unsigned long correctionField; unsigned int reserved16; unsigned char sourcePortIdentity[10]; unsigned short sequenceId; unsigned char controlField; unsigned char logMessageInterval; } *

variable_types: donelen int

variable_types: version int

variable_types: messageType int

variable_types: n int

user_defined_types: struct ptp_tlv { unsigned short type; unsigned short len; unsigned char oui[3]; unsigned char subtype[3]; unsigned char data[]; }


original_code:
int dump_udppkt(char *prefix, void *buf, int len, struct TimeInternal *ti)
{
 struct ethhdr *eth = buf;
 struct iphdr *ip = buf + 14;
 struct udphdr *udp = (void *)(ip + 1);
 void *payload = (void *)(udp + 1);
 if (ti)
  dump_time(prefix, ti);
 dump_eth(prefix, eth);
 dump_ip(prefix, ip);
 dump_udp(prefix, udp);
 dump_payload(prefix, payload, len - (payload - buf));
 return 0;
}

variable_types:
prefix
char *

variable_types:
buf
void *

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

variable_types: struct ethhdr { unsigned char h_dest[6]; unsigned char h_source[6]; unsigned short h_proto; } *

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

variable_types: struct udphdr { union { struct { unsigned short uh_sport; unsigned short uh_dport; unsigned short uh_ulen; unsigned short uh_sum; }; struct { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; }; }; } *

variable_types:
payload
void *


decompiled_code:
__int64 __fastcall dump_payloadpkt(const char *a1, __int64 a2, unsigned int a3, int *a4)
{
if ( a4 )
dump_time((__int64)a1, a4);
dump_payload(a1, a2, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(const char *a1, __int64 a2, unsigned int a3, int *a4)
{
if ( a4 )
func0((__int64)a1, a4);
func15(a1, a2, a3);
return 0LL;
}

original_code:
int dump_payloadpkt(char *prefix, void *buf, int len, struct TimeInternal *ti)
{
 if (ti)
  dump_time(prefix, ti);
 dump_payload(prefix, buf, len);
 return 0;
}

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


decompiled_code:
__int64 __fastcall dump_1588pkt(const char *a1, unsigned __int8 *a2, int a3, int *a4)
{
if ( a4 )
dump_time((__int64)a1, a4);
dump_eth((__int64)a1, a2);
dump_payload(a1, (__int64)(a2 + 14), a3 - 14);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(const char *a1, unsigned __int8 *a2, int a3, int *a4)
{
if ( a4 )
func0((__int64)a1, a4);
func3((__int64)a1, a2);
func15(a1, (__int64)(a2 + 14), a3 - 14);
return 0LL;
}

original_code:
int dump_1588pkt(char *prefix, void *buf, int len, struct TimeInternal *ti)
{
 struct ethhdr *eth = buf;
 void *payload = (void *)(eth + 1);
 if (ti)
  dump_time(prefix, ti);
 dump_eth(prefix, eth);
 dump_payload(prefix, payload, len - (payload - buf));
 return 0;
}

user_defined_types: struct ethhdr { unsigned char h_dest[6]; unsigned char h_source[6]; unsigned short h_proto; }


decompiled_code:
__int64 __fastcall do_stat(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3[38]; // [rsp+0h] [rbp-98h] BYREF

result = minipc_call(a1, 200LL, &rpc_stat, v3, *(_QWORD *)(a2 + 16));
if ( (int)result >= 0 )
{
printf("stat(\"%s\"):\n", *(const char **)(a2 + 16));
printf(
"dev %04x, inode %i, mode %o (rdev %04x), size %i\n",
(unsigned int)v3[0],
(unsigned int)v3[2],
(unsigned int)v3[6],
(unsigned int)v3[10],
(unsigned int)v3[12]);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3[38]; // [rsp+0h] [rbp-98h] BYREF

result = minipc_call(a1, 200LL, &rpc_stat, v3, *(_QWORD *)(a2 + 16));
if ( (int)result >= 0 )
{
printf("stat(\"%s\"):\n", *(const char **)(a2 + 16));
printf(
"dev %04x, inode %i, mode %o (rdev %04x), size %i\n",
(unsigned int)v3[0],
(unsigned int)v3[2],
(unsigned int)v3[6],
(unsigned int)v3[10],
(unsigned int)v3[12]);
result = 0LL;
}
return result;
}

original_code:
static int do_stat(struct minipc_ch *client, char **argv)
{
 int ret;
 struct stat stbuf;
 ret = minipc_call(client, 200, &rpc_stat, &stbuf,
     argv[2]);
 if (ret < 0)
  return ret;
 printf("stat(\"%s\"):\n", argv[2]);
 printf("dev %04x, inode %i, mode %o (rdev %04x), size %i\n",
        (int)stbuf.st_dev, (int)stbuf.st_ino, stbuf.st_mode,
        (int)stbuf.st_rdev, (int)stbuf.st_size);
 return 0;
}

variable_types:
client
struct minipc_ch { int fd; } *

variable_types:
argv
char **

variable_types: ret int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall do_strcat(__int64 a1, __int64 a2)
{
__int64 result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

result = minipc_call(a1, 200LL, &rpc_strcat, v3, *(_QWORD *)(a2 + 16));
if ( (int)result >= 0 )
{
printf("strcat(%s,%s) = %s\n", *(const char **)(a2 + 16), *(const char **)(a2 + 24), v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

result = minipc_call(a1, 200LL, &rpc_strcat, v3, *(_QWORD *)(a2 + 16));
if ( (int)result >= 0 )
{
printf("strcat(%s,%s) = %s\n", *(const char **)(a2 + 16), *(const char **)(a2 + 24), v3);
result = 0LL;
}
return result;
}

original_code:
static int do_strcat(struct minipc_ch *client, char **argv)
{
 int ret;
 char buf[256];
 ret = minipc_call(client, 200, &rpc_strcat, buf,
     argv[2], argv[3]);
 if (ret < 0)
  return ret;
 printf("strcat(%s,%s) = %s\n", argv[2], argv[3], buf);
 return 0;
}

variable_types:
buf
char [256]


decompiled_code:
__int64 __fastcall do_strlen(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

result = minipc_call(a1, 200LL, &rpc_strlen, v3, *(_QWORD *)(a2 + 16));
if ( (int)result >= 0 )
{
printf("strlen(%s) = %i\n", *(const char **)(a2 + 16), v3[0]);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

result = minipc_call(a1, 200LL, &rpc_strlen, v3, *(_QWORD *)(a2 + 16));
if ( (int)result >= 0 )
{
printf("strlen(%s) = %i\n", *(const char **)(a2 + 16), v3[0]);
result = 0LL;
}
return result;
}

original_code:
static int do_strlen(struct minipc_ch *client, char **argv)
{
 int ret, len;
 ret = minipc_call(client, 200, &rpc_strlen, &len, argv[2]);
 if (ret < 0)
  return ret;
 printf("strlen(%s) = %i\n", argv[2], len);
 return 0;
}

canonical_original_code:
static int do_strlen(struct minipc_ch *client, char **argv)
{
 int ret; int len;
 ret = minipc_call(client, 200, &rpc_strlen, &len, argv[2]);
 if (ret < 0)
  return ret;
 printf("strlen(%s) = %i\n", argv[2], len);
 return 0;
}

variable_types: len int


decompiled_code:
__int64 __fastcall do_setenv(__int64 a1, __int64 a2)
{
__int64 result; // rax
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

result = minipc_call(a1, 200LL, &rpc_setenv, v3, *(_QWORD *)(a2 + 16));
if ( (int)result >= 0 )
{
printf("setenv %s = %s : success\n", *(const char **)(a2 + 16), *(const char **)(a2 + 24));
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 result; // rax
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

result = minipc_call(a1, 200LL, &rpc_setenv, v3, *(_QWORD *)(a2 + 16));
if ( (int)result >= 0 )
{
printf("setenv %s = %s : success\n", *(const char **)(a2 + 16), *(const char **)(a2 + 24));
result = 0LL;
}
return result;
}

original_code:
static int do_setenv(struct minipc_ch *client, char **argv)
{
 int ret, ret2;
 ret = minipc_call(client, 200, &rpc_setenv, &ret2, argv[2],
     argv[3]);
 if (ret < 0)
  return ret;
 printf("setenv %s = %s : success\n", argv[2], argv[3]);
 return 0;
}

canonical_original_code:
static int do_setenv(struct minipc_ch *client, char **argv)
{
 int ret; int ret2;
 ret = minipc_call(client, 200, &rpc_setenv, &ret2, argv[2],
     argv[3]);
 if (ret < 0)
  return ret;
 printf("setenv %s = %s : success\n", argv[2], argv[3]);
 return 0;
}


decompiled_code:
__int64 __fastcall do_getenv(__int64 a1, __int64 a2)
{
__int64 result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

result = minipc_call(a1, 200LL, &rpc_getenv, v3, *(_QWORD *)(a2 + 16));
if ( (int)result >= 0 )
{
printf("getenv(%s) = %s\n", *(const char **)(a2 + 16), v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

result = minipc_call(a1, 200LL, &rpc_getenv, v3, *(_QWORD *)(a2 + 16));
if ( (int)result >= 0 )
{
printf("getenv(%s) = %s\n", *(const char **)(a2 + 16), v3);
result = 0LL;
}
return result;
}

original_code:
static int do_getenv(struct minipc_ch *client, char **argv)
{
 int ret;
 char buf[256];
 ret = minipc_call(client, 200, &rpc_getenv, buf, argv[2]);
 if (ret < 0)
  return ret;
 printf("getenv(%s) = %s\n", argv[2], buf);
 return 0;
}


decompiled_code:
__int64 __fastcall do_add(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // er12
__int64 result; // rax
unsigned int v5[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = atoi(*(const char **)(a2 + 16));
v3 = atoi(*(const char **)(a2 + 24));
result = minipc_call(a1, 200LL, &rpc_add, v5, v2);
if ( (int)result >= 0 )
{
printf("add %i + %i = %i : success\n", v2, v3, v5[0]);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // er12
__int64 result; // rax
unsigned int v5[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = atoi(*(const char **)(a2 + 16));
v3 = atoi(*(const char **)(a2 + 24));
result = minipc_call(a1, 200LL, &rpc_add, v5, v2);
if ( (int)result >= 0 )
{
printf("add %i + %i = %i : success\n", v2, v3, v5[0]);
result = 0LL;
}
return result;
}

original_code:
static int do_add(struct minipc_ch *client, char **argv)
{
 int ret;
 int a = atoi(argv[2]);
 int b = atoi(argv[3]);
 int sum;
 ret = minipc_call(client, 200, &rpc_add, &sum, a, b);
 if (ret < 0)
  return ret;
 printf("add %i + %i = %i : success\n", a, b, sum);
 return 0;
}

variable_types: a int

variable_types: b int

variable_types: sum int


original_code:
static int shm_server_do_stat(const struct minipc_pd *pd,
          uint32_t *args, void *ret)
{
 struct stat stbuf;
 char *fname = (void *)args;
 if (stat(fname, &stbuf) < 0)
  return -1;
 memcpy(ret, &stbuf, sizeof(stbuf));
 return 0;
}

canonical_original_code:
static int shm_server_do_stat(struct minipc_pd *pd, unsigned int *args, void *ret)
{
 struct stat stbuf;
 char *fname = (void *)args;
 if (stat(fname, &stbuf) < 0)
  return -1;
 memcpy(ret, &stbuf, sizeof(stbuf));
 return 0;
}

variable_types: struct minipc_pd { int (*f)(struct minipc_pd *, unsigned int *args, void *retval); char name[20]; unsigned int flags; unsigned int retval; unsigned int args[]; } *

variable_types:
args
unsigned int *

variable_types:
ret
void *

variable_types:
fname
char *

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


decompiled_code:
__int64 __fastcall shm_server_do_add(__int64 a1, int *a2, _DWORD *a3)
{
int v4; // ebp
int v5; // ebp
__int64 result; // rax

v4 = *a2;
v5 = *(_DWORD *)minipc_get_next_arg(a2, *(unsigned int *)(a1 + 36)) + v4;
result = 0LL;
*a3 = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int *a2, _DWORD *a3)
{
int v4; // ebp
int v5; // ebp
__int64 result; // rax

v4 = *a2;
v5 = *(_DWORD *)minipc_get_next_arg(a2, *(unsigned int *)(a1 + 36)) + v4;
result = 0LL;
*a3 = v5;
return result;
}

original_code:
static int shm_server_do_add(const struct minipc_pd *pd,
          uint32_t *args, void *ret)
{
 int a, b, sum;
 a = args[0];
 args = minipc_get_next_arg(args, pd->args[0]);
 b = args[0];
 sum = a + b;
 *(int *)ret = sum;
 return 0;
}

canonical_original_code:
static int shm_server_do_add(struct minipc_pd *pd, unsigned int *args, void *ret)
{
 int a; int b; int sum;
 a = args[0];
 args = minipc_get_next_arg(args, pd->args[0]);
 b = args[0];
 sum = a + b;
 *(int *)ret = sum;
 return 0;
}

user_defined_types: struct minipc_pd { int (*f)(struct minipc_pd *, unsigned int *args, void *retval); char name[20]; unsigned int flags; unsigned int retval; unsigned int args[]; }


decompiled_code:
__int64 __fastcall shm_server_do_strlen(__int64 a1, const char *a2, _DWORD *a3)
{
*a3 = strlen(a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, _DWORD *a3)
{
*a3 = strlen(a2);
return 0LL;
}

original_code:
static int shm_server_do_strlen(const struct minipc_pd *pd,
          uint32_t *args, void *ret)
{
 char *s = (void *)args;
 *(int *)ret = strlen(s);
 return 0;
}

canonical_original_code:
static int shm_server_do_strlen(struct minipc_pd *pd, unsigned int *args, void *ret)
{
 char *s = (void *)args;
 *(int *)ret = strlen(s);
 return 0;
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall shm_server_do_strcat(__int64 a1, const char *a2, char *a3)
{
const char *v4; // r13
size_t v5; // rax
char v7[280]; // [rsp+0h] [rbp-118h] BYREF

v4 = (const char *)minipc_get_next_arg(a2, *(unsigned int *)(a1 + 36));
strncpy(v7, a2, 0x100uLL);
v5 = strlen(a2);
strncat(v7, v4, 256 - v5);
strcpy(a3, v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, char *a3)
{
const char *v4; // r13
size_t v5; // rax
char v7[280]; // [rsp+0h] [rbp-118h] BYREF

v4 = (const char *)minipc_get_next_arg(a2, *(unsigned int *)(a1 + 36));
strncpy(v7, a2, 0x100uLL);
v5 = strlen(a2);
strncat(v7, v4, 256 - v5);
strcpy(a3, v7);
return 0LL;
}

original_code:
static int shm_server_do_strcat(const struct minipc_pd *pd,
          uint32_t *args, void *ret)
{
 char *s, *t;
 char scat[256];
 s = (void *)args;
 args = minipc_get_next_arg(args, pd->args[0]);
 t = (void *)args;
 strncpy(scat, s, sizeof(scat));
 strncat(scat, t, sizeof(scat) - strlen(s));
 strcpy(ret, scat);
 return 0;
}

canonical_original_code:
static int shm_server_do_strcat(struct minipc_pd *pd, unsigned int *args, void *ret)
{
 char *s; char *t;
 char scat[256];
 s = (void *)args;
 args = minipc_get_next_arg(args, pd->args[0]);
 t = (void *)args;
 strncpy(scat, s, sizeof(scat));
 strncat(scat, t, sizeof(scat) - strlen(s));
 strcpy(ret, scat);
 return 0;
}

variable_types:
t
char *

variable_types:
scat
char [256]


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

v2 = (const char *)minipc_get_next_arg(a2, *(unsigned int *)(a1 + 36));
setenv(a2, v2, 1);
return 0LL;
}

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

v2 = (const char *)minipc_get_next_arg(a2, *(unsigned int *)(a1 + 36));
setenv(a2, v2, 1);
return 0LL;
}

original_code:
static int shm_server_do_setenv(const struct minipc_pd *pd,
          uint32_t *args, void *ret)
{
 char *envname = (void *)args;
 char *envval;
 args = minipc_get_next_arg(args, pd->args[0]);
 envval = (void *)args;
 setenv(envname, envval, 1);
 return 0;
}

canonical_original_code:
static int shm_server_do_setenv(struct minipc_pd *pd, unsigned int *args, void *ret)
{
 char *envname = (void *)args;
 char *envval;
 args = minipc_get_next_arg(args, pd->args[0]);
 envval = (void *)args;
 setenv(envname, envval, 1);
 return 0;
}

variable_types:
envname
char *

variable_types:
envval
char *


decompiled_code:
__int64 __fastcall shm_server_do_getenv(__int64 a1, const char *a2, char *a3)
{
char *v4; // rax

v4 = getenv(a2);
strcpy(a3, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2, char *a3)
{
char *v4; // rax

v4 = getenv(a2);
strcpy(a3, v4);
return 0LL;
}

original_code:
static int shm_server_do_getenv(const struct minipc_pd *pd,
          uint32_t *args, void *ret)
{
 char *envname = (void *)args;
 char *res = getenv(envname);
 strcpy(ret, res);
 return 0;
}

canonical_original_code:
static int shm_server_do_getenv(struct minipc_pd *pd, unsigned int *args, void *ret)
{
 char *envname = (void *)args;
 char *res = getenv(envname);
 strcpy(ret, res);
 return 0;
}

variable_types:
res
char *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax

if ( argc == 2 )
{
v3 = minipc_server_create(argv[1], 0LL, envp);
v4 = v3;
if ( !v3 )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "%s: rpc_open(%s): %s\n", *argv, argv[1], v8);
exit(1);
}
minipc_set_logfile(v3, stderr);
if ( !(unsigned int)shm_export_functions(v4) )
{
while ( 1 )
{
minipc_server_action(v4, 1000LL);
minipc_server_action(v4, 1000LL);
}
}
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "%s: exporting RPC functions: %s\n", *argv, v6);
}
else
{
fprintf(stderr, "%s: use \"%s <shmid>\n", *argv, *argv);
}
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax

if ( argc == 2 )
{
v3 = minipc_server_create(argv[1], 0LL, envp);
v4 = v3;
if ( !v3 )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "%s: rpc_open(%s): %s\n", *argv, argv[1], v8);
exit(1);
}
minipc_set_logfile(v3, stderr);
if ( !(unsigned int)func6(v4) )
{
while ( 1 )
{
minipc_server_action(v4, 1000LL);
minipc_server_action(v4, 1000LL);
}
}
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "%s: exporting RPC functions: %s\n", *argv, v6);
}
else
{
fprintf(stderr, "%s: use \"%s <shmid>\n", *argv, *argv);
}
exit(1);
}

original_code:
int main(int argc, char **argv)
{
 struct minipc_ch *ch;
 if (argc != 2) {
  fprintf(stderr, "%s: use \"%s <shmid>\n", argv[0], argv[0]);
  exit(1);
 }
 ch = minipc_server_create(argv[1], 0);
 if (!ch) {
  fprintf(stderr, "%s: rpc_open(%s): %s\n", argv[0], argv[1],
   strerror((*__errno_location ())));
  exit(1);
 }
 minipc_set_logfile(ch, stderr);
 if (shm_export_functions(ch)) {
  fprintf(stderr, "%s: exporting RPC functions: %s\n", argv[0],
   strerror((*__errno_location ())));
  exit(1);
 }
 while (1) {
  minipc_server_action(ch, 1000);
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
ch
struct minipc_ch { int fd; } *