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

v2 = atoi(a2);
*(_BYTE *)GOPTS(a1) = v2;
return 1LL;
}

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

v2 = atoi(a2);
*(_BYTE *)func0(a1) = v2;
return 1LL;
}

original_code:
static int handle_clock_class(struct pp_globals *ppg, char *val)
{
 GOPTS(ppg)->clock_quality.clockClass = atoi(val);
 return 1;
}

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_net_path { struct pp_channel ch[-1]; int mcast_addr; int ptp_offset; }

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

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

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

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

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

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


repo: tinito/ppsi-chibios

decompiled_code:
__int64 __fastcall handle_iface(__int64 a1, const char *a2)
{
strcpy((char *)(*(_QWORD *)(a1 + 72) + 44LL * *(int *)(a1 + 64) + 16), a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
strcpy((char *)(*(_QWORD *)(a1 + 72) + 44LL * *(int *)(a1 + 64) + 16), a2);
return 1LL;
}

original_code:
static int handle_iface(struct pp_globals *ppg, char *val)
{
 strcpy(ppg->links[ppg->nlinks].iface_name, val);
 return 1;
}

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

variable_types:
val
char *

return_type: int

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall handle_link(__int64 a1, const char *a2)
{
int v2; // eax

v2 = *(_DWORD *)(a1 + 64) + 1;
*(_DWORD *)(a1 + 64) = v2;
strcpy((char *)(*(_QWORD *)(a1 + 72) + 44LL * v2), a2);
return 1LL;
}

original_code:
static int handle_link(struct pp_globals *ppg, char *val)
{
 ppg->nlinks++;
 strcpy(ppg->links[ppg->nlinks].link_name, val);
 return 1;
}

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_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 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 pp_link { char link_name[16]; char iface_name[16]; int proto; int role; int ext; }

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

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 UInteger48 { unsigned int lsb; unsigned short msb; }


decompiled_code:
__int64 __fastcall detect_keyword(char *s2)
{
__int64 v1; // rbx
unsigned int v2; // er12

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( !strcmp((&off_408)[3 * v1], s2) )
break;
if ( ++v1 == 14 )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2)
{
__int64 v1; // rbx
unsigned int v2; // er12

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( !strcmp((&off_408)[3 * v1], s2) )
break;
if ( ++v1 == 14 )
return (unsigned int)-1;
}
return v2;
}

original_code:
static int detect_keyword(char *kw)
{
 int i;
 for (i = 0; i < sizeof(keywords) / sizeof(keywords[0]); i++)
  if (!strcmp(keywords[i].key, kw))
   return i;
 return KW_INV;
}

variable_types:
kw
char *

variable_types: i int


decompiled_code:
__int64 __fastcall handle_key_val(__int64 a1, char *a2, const char *a3)
{
unsigned int v4; // eax
unsigned int v5; // ecx
__int64 v6; // rdx
__int64 result; // rax

v4 = detect_keyword(a2);
if ( v4 > 0xD )
return 0LL;
v5 = v4;
v6 = 1LL << v4;
result = 0LL;
if ( (v6 & 0x3227) != 0 )
result = ((__int64 (__fastcall *)(__int64, const char *))*(&funcs_12D + 3 * (int)v5))(a1, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char *a2, const char *a3)
{
unsigned int v4; // eax
unsigned int v5; // ecx
__int64 v6; // rdx
__int64 result; // rax

v4 = func5(a2);
if ( v4 > 0xD )
return 0LL;
v5 = v4;
v6 = 1LL << v4;
result = 0LL;
if ( (v6 & 0x3227) != 0 )
result = ((__int64 (__fastcall *)(__int64, const char *))*(&funcs_12D + 3 * (int)v5))(a1, a3);
return result;
}

original_code:
static int handle_key_val(struct pp_globals *ppg, char *key, char *val)
{
 int k_id;
 k_id = detect_keyword(key);
 switch(k_id) {
  case KW_LINK:
  case KW_IFACE:
  case KW_PROTO:
  case KW_ROLE:
  case KW_EXT:
  case KW_CLOCK_CLASS:
  case KW_CLOCK_ACCURACY:
   return keywords[k_id].handle_key(ppg, val);
  default:
   return 0;
 }
}

variable_types:
key
char *

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

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall handle_ext(__int64 a1, char *a2)
{
int v2; // eax
unsigned int v3; // edx

v2 = detect_keyword(a2);
v3 = 0;
if ( (unsigned int)(v2 - 10) <= 1 )
{
*(_DWORD *)(*(_QWORD *)(a1 + 72) + 44LL * *(int *)(a1 + 64) + 40) = v2 - 10;
v3 = 1;
}
return v3;
}

original_code:
static int handle_ext(struct pp_globals *ppg, char *val)
{
 int v_id;
 v_id = detect_keyword(val);
 switch(v_id) {
  case KW_NONE:
  case KW_WHITERAB:
   ppg->links[ppg->nlinks].ext = v_id - KW_NONE;
   break;
  default:
   return 0;
 }
 return 1;
}

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

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

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

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


decompiled_code:
__int64 __fastcall handle_role(__int64 a1, char *a2)
{
int v2; // eax
unsigned int v3; // edx

v2 = detect_keyword(a2);
v3 = 0;
if ( (unsigned int)(v2 - 6) <= 2 )
{
*(_DWORD *)(*(_QWORD *)(a1 + 72) + 44LL * *(int *)(a1 + 64) + 36) = v2 - 6;
v3 = 1;
}
return v3;
}

original_code:
static int handle_role(struct pp_globals *ppg, char *val)
{
 int v_id;
 v_id = detect_keyword(val);
 switch(v_id) {
  case KW_AUTO:
  case KW_MASTER:
  case KW_SLAVE:
   ppg->links[ppg->nlinks].role = v_id - KW_AUTO;
   break;
  default:
   return 0;
 }
 return 1;
}

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

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

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

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall handle_proto(__int64 a1, char *a2)
{
int v2; // eax
unsigned int v3; // edx

v2 = detect_keyword(a2);
v3 = 0;
if ( (unsigned int)(v2 - 3) <= 1 )
{
*(_DWORD *)(*(_QWORD *)(a1 + 72) + 44LL * *(int *)(a1 + 64) + 32) = v2 - 3;
v3 = 1;
}
return v3;
}

original_code:
static int handle_proto(struct pp_globals *ppg, char *val)
{
 int v_id;
 v_id = detect_keyword(val);
 switch(v_id) {
  case KW_RAW:
  case KW_UDP:
   ppg->links[ppg->nlinks].proto = v_id - KW_RAW;
   break;
  default:
   return 0;
 }
 return 1;
}

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

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

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

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


original_code:
int pp_parse_conf(struct pp_globals *ppg, char *conf, int len)
{
 int st = 0;
 char c;
 char key[16], val[16];
 int toklen = 0;
 int ln = 1;
 int newln;
 int i;
 ppg->nlinks = -1;
 memset(ppg->links, 0, ppg->max_links * sizeof(struct pp_link));
 for (i = 0; i < len; i++) {
  c = conf[i];
  newln = 0;
  if ((c == '\n') || (c == '\0')) {
   ln++;
   newln = 1;
   if (st == 2)
    goto ret_invalid_line;
  }
  switch (st) {
  case 0:
   if ((c == ' ') || (c == '\t') || (c == '\r') || (newln))
    continue;
   if (c == '#')
    st = 1;
   else {
    key[0] = c;
    toklen = 1;
    st = 2;
   }
   break;
  case 1:
   if (newln)
    st = 0;
   else
    continue;
   break;
  case 2:
   if (toklen == sizeof(key))
    goto ret_invalid_line;
   if ((c != ' ') && (c != '\t'))
    key[toklen++] = c;
   else {
    st = 3;
    key[toklen] = '\0';
    toklen = 0;
   }
   break;
  case 3:
   if (toklen == sizeof(val))
    goto ret_invalid_line;
   if ((c != ' ') && (c != '\t') && (c != '\r') && (!newln))
    val[toklen++] = c;
   else if (newln) {
    val[toklen] = '\0';
    if (!handle_key_val(ppg, key, val))
     goto ret_invalid_line;
    st = 0;
    toklen = 0;
   }
  }
 }
 ppg->nlinks++;
 return 0;
ret_invalid_line:
 ln--;
 return -ln;
}

canonical_original_code:
int pp_parse_conf(struct pp_globals *ppg, char *conf, int len)
{
 int st = 0;
 char c;
 char key[16]; char val[16];
 int toklen = 0;
 int ln = 1;
 int newln;
 int i;
 ppg->nlinks = -1;
 memset(ppg->links, 0, ppg->max_links * sizeof(struct pp_link));
 for (i = 0; i < len; i++) {
  c = conf[i];
  newln = 0;
  if ((c == '\n') || (c == '\0')) {
   ln++;
   newln = 1;
   if (st == 2)
    goto ret_invalid_line;
  }
  switch (st) {
  case 0:
   if ((c == ' ') || (c == '\t') || (c == '\r') || (newln))
    continue;
   if (c == '#')
    st = 1;
   else {
    key[0] = c;
    toklen = 1;
    st = 2;
   }
   break;
  case 1:
   if (newln)
    st = 0;
   else
    continue;
   break;
  case 2:
   if (toklen == sizeof(key))
    goto ret_invalid_line;
   if ((c != ' ') && (c != '\t'))
    key[toklen++] = c;
   else {
    st = 3;
    key[toklen] = '\0';
    toklen = 0;
   }
   break;
  case 3:
   if (toklen == sizeof(val))
    goto ret_invalid_line;
   if ((c != ' ') && (c != '\t') && (c != '\r') && (!newln))
    val[toklen++] = c;
   else if (newln) {
    val[toklen] = '\0';
    if (!handle_key_val(ppg, key, val))
     goto ret_invalid_line;
    st = 0;
    toklen = 0;
   }
  }
 }
 ppg->nlinks++;
 return 0;
ret_invalid_line:
 ln--;
 return -ln;
}

variable_types:
conf
char *

variable_types: len int

variable_types: st int

variable_types: c char

variable_types:
key
char [16]

variable_types:
val
char [16]

variable_types: toklen int

variable_types: ln int

variable_types: newln int

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

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

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

user_defined_types: struct 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; }

user_defined_types: struct pp_net_path { struct pp_channel ch[-1]; int mcast_addr; int 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 PortIdentity { struct ClockIdentity clockIdentity; unsigned short portNumber; }

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


NP

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

canonical_decompiled_code:
__int64 __fastcall func4(__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 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; }


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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
return a2 - *(int *)(func4(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_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; }


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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
return a2 + *(int *)(func4(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_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 Integer64 { unsigned int lsb; int msb; }

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 UInteger48 { unsigned int lsb; unsigned short msb; }


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

v1 = DSPOR(a1);
return pp_timeout_set(a1, 2, 1000 * (*(unsigned __int8 *)(v1 + 12) << *(_BYTE *)(v1 + 11)));
}

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

return_type: void

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

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

user_defined_types: struct pp_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 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 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; }

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

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


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

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


decompiled_code:
__int64 __fastcall pp_prepare_pointers(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rbp
__int64 result; // rax

v1 = pp_get_payload((__int64)a1, (__int64)(a1 + 8));
v2 = _align_pointer(v1);
a1[60] = v2;
v3 = pp_get_payload((__int64)a1, (__int64)(a1 + 33));
v4 = _align_pointer(v3);
a1[61] = v4;
a1[58] = pp_get_header((__int64)a1, v2);
result = pp_get_header((__int64)a1, v4);
a1[59] = result;
return result;
}

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_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 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 Integer64 { unsigned int lsb; int msb; }

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 UInteger48 { unsigned int lsb; unsigned short msb; }


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

v1 = (__int64 (*)(void))pp_hooks[8];
if ( !v1 )
goto LABEL_5;
result = v1();
if ( (_DWORD)result == 1 )
return 0LL;
if ( (int)result >= 0 )
{
LABEL_5:
result = pp_timeout_z(a1, 2u);
if ( (_DWORD)result )
{
*(_WORD *)(a1 + 708) = 0;
*(_WORD *)(a1 + 710) = 0;
if ( (*(_BYTE *)(a1 + 1416) & 4) != 0 || *(_BYTE *)(DSDEF(a1) + 14) == 0xFF )
{
*(_DWORD *)(a1 + 4) = 4;
pp_timeout_restart_annrec(a1);
result = 0LL;
}
else
{
m1(a1);
*(_DWORD *)(a1 + 4) = 6;
result = 0LL;
}
}
}
return result;
}

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

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

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

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


decompiled_code:
__int64 __fastcall st_com_slave_handle_announce(__int64 a1, __int64 a2, int a3)
{
void (__fastcall *v3)(__int64); // rdx
__int64 result; // rax

if ( a3 <= 63 )
return 0xFFFFFFFFLL;
st_com_add_foreign((_WORD *)a1, a2);
pp_timeout_restart_annrec(a1);
*(_DWORD *)(a1 + 4) = bmc(a1);
v3 = (void (__fastcall *)(__int64))pp_hooks[9];
result = 0LL;
if ( v3 )
{
v3(a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2, int a3)
{
void (__fastcall *v3)(__int64); // rdx
__int64 result; // rax

if ( a3 <= 63 )
return 0xFFFFFFFFLL;
func13((_WORD *)a1, a2);
func9(a1);
*(_DWORD *)(a1 + 4) = bmc(a1);
v3 = (void (__fastcall *)(__int64))pp_hooks[9];
result = 0LL;
if ( v3 )
{
v3(a1);
result = 0LL;
}
return result;
}

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

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_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_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 MsgHeader { unsigned char transportSpecific; unsigned char messageType; unsigned char versionPTP; unsigned short messageLength; unsigned char domainNumber; unsigned char flagField[2]; struct Integer64 correctionfield; struct PortIdentity sourcePortIdentity; unsigned short sequenceId; unsigned char controlField; char logMessageInterval; }

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

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

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

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


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 Integer64 { unsigned int lsb; int msb; }

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_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
unsigned __int16 v4; // cx
unsigned __int16 v5; // dx
__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 ( (v3 & 2) != 0 )
{
v4 = *(_WORD *)(a1 + 1312);
v5 = *(_WORD *)(a1 + 1374);
if ( v4 == v5 )
{
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_15;
result = v7(a1, a1 + 568);
if ( (_DWORD)result == 1 )
return 0LL;
if ( (int)result >= 0 )
{
LABEL_15:
pp_update_offset(a1, a1 + 648);
pp_update_clock(a1);
return 0LL;
}
}
else
{
result = (unsigned int)pp_diag_verbosity;
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);
result = 0LL;
}
}
}
else
{
result = (unsigned int)pp_diag_verbosity;
if ( (_DWORD)pp_diag_verbosity )
{
pp_printf("ERROR: %s: Slave was not waiting a follow up message\n", "st_com_slave_handle_followup");
result = 0LL;
}
}
}
else
{
result = (unsigned int)pp_diag_verbosity;
if ( (_DWORD)pp_diag_verbosity )
{
pp_printf("ERROR: %s: Follow up message is not from current parent\n", "st_com_slave_handle_followup");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2, int a3)
{
char v3; // al
unsigned __int16 v4; // cx
unsigned __int16 v5; // dx
__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 ( (v3 & 2) != 0 )
{
v4 = *(_WORD *)(a1 + 1312);
v5 = *(_WORD *)(a1 + 1374);
if ( v4 == v5 )
{
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_15;
result = v7(a1, a1 + 568);
if ( (_DWORD)result == 1 )
return 0LL;
if ( (int)result >= 0 )
{
LABEL_15:
pp_update_offset(a1, a1 + 648);
pp_update_clock(a1);
return 0LL;
}
}
else
{
result = (unsigned int)pp_diag_verbosity;
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);
result = 0LL;
}
}
}
else
{
result = (unsigned int)pp_diag_verbosity;
if ( (_DWORD)pp_diag_verbosity )
{
pp_printf("ERROR: %s: Slave was not waiting a follow up message\n", "st_com_slave_handle_followup");
result = 0LL;
}
}
}
else
{
result = (unsigned int)pp_diag_verbosity;
if ( (_DWORD)pp_diag_verbosity )
{
pp_printf("ERROR: %s: Follow up message is not from current parent\n", "st_com_slave_handle_followup");
result = 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 pp_net_path { struct pp_channel ch[-1]; int mcast_addr; int ptp_offset; }

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

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

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

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


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((_WORD *)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");
func13((_WORD *)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_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_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 MsgHeader { unsigned char transportSpecific; unsigned char messageType; unsigned char versionPTP; unsigned short messageLength; unsigned char domainNumber; unsigned char flagField[2]; struct Integer64 correctionfield; struct PortIdentity sourcePortIdentity; unsigned short sequenceId; unsigned char controlField; char logMessageInterval; }

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

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

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

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


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

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

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


decompiled_code:
int __fastcall dump_time(const char *a1, int *a2)
{
const char *v2; // rax
struct tm v4; // [rsp+0h] [rbp-68h] BYREF
time_t timer; // [rsp+40h] [rbp-28h] BYREF
__int64 v6; // [rsp+48h] [rbp-20h]

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

canonical_decompiled_code:
int __fastcall func0(const char *a1, int *a2)
{
const char *v2; // rax
struct tm v4; // [rsp+0h] [rbp-68h] BYREF
time_t timer; // [rsp+40h] [rbp-28h] BYREF
__int64 v6; // [rsp+48h] [rbp-20h]

timer = *a2;
v6 = a2[1] / 1000;
localtime_r(&timer, &v4);
v2 = " invalid";
if ( a2[3] )
v2 = (const char *)&unk_906;
return printf(
"%sTIME: (%li - 0x%lx) %02i:%02i:%02i.%06li%s\n",
a1,
timer,
timer,
(unsigned int)v4.tm_hour,
(unsigned int)v4.tm_min,
(unsigned int)v4.tm_sec,
v6,
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:
__int64 __fastcall dump_tlv(const char *a1, __int64 a2, unsigned int a3)
{
unsigned __int16 v4; // r12
unsigned int v5; // ebp
unsigned __int16 v6; // ax

v4 = _bswap_16(*(_WORD *)(a2 + 2));
v5 = v4 + 4;
v6 = _bswap_16(*(_WORD *)a2);
printf(
"%sTLV: type %04x len %i oui %02x:%02x:%02x sub %02x:%02x:%02x\n",
a1,
v6,
v5,
*(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 ( (int)v5 > (int)a3 )
{
printf("%sTLV: too short (expected %i, total %i)\n", a1, v5, a3);
v5 = a3;
}
else
{
dumpstruct(a1, "TLV: ", "tlv-content", (unsigned __int8 *)(a2 + 10), (unsigned int)v4 - 6);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, __int64 a2, unsigned int a3)
{
unsigned __int16 v4; // r12
unsigned int v5; // ebp
unsigned __int16 v6; // ax

v4 = func5(*(_WORD *)(a2 + 2));
v5 = v4 + 4;
v6 = func5(*(_WORD *)a2);
printf(
"%sTLV: type %04x len %i oui %02x:%02x:%02x sub %02x:%02x:%02x\n",
a1,
v6,
v5,
*(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 ( (int)v5 > (int)a3 )
{
printf("%sTLV: too short (expected %i, total %i)\n", a1, v5, a3);
v5 = a3;
}
else
{
func4(a1, "TLV: ", "tlv-content", (unsigned __int8 *)(a2 + 10), (unsigned int)v4 - 6);
}
return v5;
}

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_1stamp(const char *a1, const char *a2, __int64 a3)
{
unsigned __int64 v4; // r14
unsigned __int64 v5; // rbx
unsigned int v6; // eax

v4 = (unsigned __int64)(unsigned __int16)_bswap_16(*(_WORD *)a3) << 32;
v5 = v4 | (unsigned int)_bswap_32(*(_DWORD *)(a3 + 2));
v6 = _bswap_32(*(_DWORD *)(a3 + 6));
return printf("%s%s%lu.%09i\n", a1, a2, v5, v6);
}

canonical_decompiled_code:
int __fastcall func11(const char *a1, const char *a2, __int64 a3)
{
unsigned __int64 v4; // r14
unsigned __int64 v5; // rbx
unsigned int v6; // eax

v4 = (unsigned __int64)(unsigned __int16)func5(*(_WORD *)a3) << 32;
v5 = v4 | (unsigned int)func9(*(_DWORD *)(a3 + 2));
v6 = func9(*(_DWORD *)(a3 + 6));
return printf("%s%s%lu.%09i\n", a1, a2, v5, v6);
}

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:
int __fastcall dump_msg_announce(const char *a1, __int64 a2)
{
dump_1stamp(a1, "MSG-ANNOUNCE: stamp ", a2);
dump_1quality(a1, "MSG-ANNOUNCE: grandmaster-quality ", (unsigned __int8 *)(a2 + 14));
printf("%sMSG-ANNOUNCE: grandmaster-prio %i %i\n", a1, *(unsigned __int8 *)(a2 + 13), *(unsigned __int8 *)(a2 + 18));
return dump_1clockid(a1, "MSG-ANNOUNCE: grandmaster-id ", *(_QWORD *)(a2 + 19));
}

canonical_decompiled_code:
int __fastcall func12(const char *a1, __int64 a2)
{
func11(a1, "MSG-ANNOUNCE: stamp ", a2);
func1(a1, "MSG-ANNOUNCE: grandmaster-quality ", (unsigned __int8 *)(a2 + 14));
printf("%sMSG-ANNOUNCE: grandmaster-prio %i %i\n", a1, *(unsigned __int8 *)(a2 + 13), *(unsigned __int8 *)(a2 + 18));
return func2(a1, "MSG-ANNOUNCE: grandmaster-id ", *(_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:
int __fastcall dump_msg_sync_etc(const char *a1, const char *a2, __int64 a3)
{
return dump_1stamp(a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func13(const char *a1, const char *a2, __int64 a3)
{
return func11(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(a1, a2, a3);
return dump_1port(a1, a2, (unsigned __int8 *)(a3 + 10));
}

canonical_decompiled_code:
int __fastcall func14(const char *a1, const char *a2, __int64 a3)
{
func11(a1, a2, a3);
return func3(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; }