decompiled_code:
__int64 __fastcall unix_calc_timeout(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 result; // rax
struct timespec v4; // [rsp+0h] [rbp-18h] BYREF

v2 = a2;
if ( !a2 )
v2 = 1LL;
clock_gettime(1, &v4);
result = v2 + 1000 * v4.tv_sec + v4.tv_nsec / 1000000;
if ( !result )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 result; // rax
struct timespec v4; // [rsp+0h] [rbp-18h] BYREF

v2 = a2;
if ( !a2 )
v2 = 1LL;
clock_gettime(1, &v4);
result = v2 + 1000 * v4.tv_sec + v4.tv_nsec / 1000000;
if ( !result )
result = 1LL;
return result;
}

original_code:
static unsigned long unix_calc_timeout(struct pp_instance *ppi, int millisec)
{
 struct timespec now;
 uint64_t now_ms;
 unsigned long result;
 if (!millisec)
  millisec = 1;
 clock_gettime(1, &now);
 now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000;
 result = now_ms + millisec;
 return result ? result : 1;
}

canonical_original_code:
static unsigned long unix_calc_timeout(struct pp_instance *ppi, int millisec)
{
 struct timespec now;
 unsigned long now_ms;
 unsigned long result;
 if (!millisec)
  millisec = 1;
 clock_gettime(1, &now);
 now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000;
 result = now_ms + millisec;
 return result ? result : 1;
}

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

variable_types: millisec int

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

variable_types:
result
unsigned long

return_type: unsigned long

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

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

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

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

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


repo: tinito/ppsi-chibios

decompiled_code:
__int64 __fastcall unix_time_adjust(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbx
unsigned int v4; // er12
struct timex v6; // [rsp+0h] [rbp-F8h] BYREF

v3 = a3;
v6.modes = 0;
if ( a3 )
{
v6.modes = 2;
if ( a3 < -512000 )
v3 = -512000LL;
if ( v3 > 512000 )
v3 = 512000LL;
v6.freq = 65 * v3;
}
if ( a2 )
{
v6.modes |= 1u;
v6.offset = a2 / 1000;
}
v4 = adjtimex(&v6);
_pp_diag(a1, 6LL, 1LL, "%s: %li %li\n", "unix_time_adjust", a2, v3);
return v4;
}

original_code:
static int unix_time_adjust(struct pp_instance *ppi, long offset_ns, long freq_ppm)
{
 struct timex t;
 int ret;
 t.modes = 0;
 if (freq_ppm) {
  if (freq_ppm > 512000)
   freq_ppm = 512000;
  if (freq_ppm < -512000)
   freq_ppm = -512000;
  t.freq = freq_ppm * ((1 << 16) / 1000);
  t.modes = 0x0002;
 }
 if (offset_ns) {
  t.offset = offset_ns / 1000;
  t.modes |= 0x0001;
 }
 ret = adjtimex(&t);
 ({ if (1) __pp_diag(ppi, pp_dt_time, 1, "%s: %li %li\n", __func__, offset_ns, freq_ppm); 1; });
 return ret;
}

variable_types: struct timex { unsigned int modes; long offset; long freq; long maxerror; long esterror; int status; long constant; long precision; long tolerance; struct timeval { long tv_sec; long tv_usec; } time; long tick; long ppsfreq; long jitter; int shift; long stabil; long jitcnt; long calcnt; long errcnt; long stbcnt; int tai; int; int; int; int; int; int; int; int; int; int; int; }

variable_types: ret int

return_type: int

user_defined_types: struct timex { unsigned int modes; long offset; long freq; long maxerror; long esterror; int status; long constant; long precision; long tolerance; struct timeval time; long tick; long ppsfreq; long jitter; int shift; long stabil; long jitcnt; long calcnt; long errcnt; long stbcnt; int tai; int; int; int; int; int; int; int; int; int; int; int; }

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

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

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

user_defined_types: struct 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 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_link { char link_name[16]; char iface_name[16]; int proto; int role; int ext; }

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

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall unix_time_adjust_freq(__int64 a1, __int64 a2)
{
return unix_time_adjust(a1, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return func1(a1, 0LL, a2);
}

original_code:
static int unix_time_adjust_freq(struct pp_instance *ppi, long freq_ppm)
{
 return unix_time_adjust(ppi, 0, freq_ppm);
}

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

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall unix_time_adjust_offset(__int64 a1, __int64 a2)
{
return unix_time_adjust(a1, a2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return func1(a1, a2, 0LL);
}

original_code:
static int unix_time_adjust_offset(struct pp_instance *ppi, long offset_ns)
{
 return unix_time_adjust(ppi, offset_ns, 0);
}

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

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

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


decompiled_code:
void __fastcall __noreturn clock_fatal_error(const char *a1)
{
int *v1; // rax
char *v2; // rax

if ( pp_diag_verbosity )
{
v1 = _errno_location();
v2 = strerror(*v1);
pp_printf("ERROR: failure in \"%s\": %s\n.Exiting.\n", a1, v2);
}
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(const char *a1)
{
int *v1; // rax
char *v2; // rax

if ( pp_diag_verbosity )
{
v1 = _errno_location();
v2 = strerror(*v1);
pp_printf("ERROR: failure in \"%s\": %s\n.Exiting.\n", a1, v2);
}
exit(1);
}

original_code:
static void clock_fatal_error(char *context)
{
 if (pp_diag_verbosity) pp_printf("ERROR: " "failure in \"%s\": %s\n.Exiting.\n", context, strerror((*__errno_location ())));
 exit(1);
}

variable_types:
context
char *

return_type: void


decompiled_code:
__int64 __fastcall unix_time_set(__int64 a1, int *a2)
{
struct timespec v3; // [rsp+0h] [rbp-18h] BYREF

v3.tv_sec = *a2;
v3.tv_nsec = a2[1];
if ( clock_settime(0, &v3) < 0 )
clock_fatal_error("clock_settime");
_pp_diag(a1, 6LL, 1LL, "%s: %9li.%09li\n", "unix_time_set", v3.tv_sec, v3.tv_nsec);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int *a2)
{
struct timespec v3; // [rsp+0h] [rbp-18h] BYREF

v3.tv_sec = *a2;
v3.tv_nsec = a2[1];
if ( clock_settime(0, &v3) < 0 )
func4("clock_settime");
_pp_diag(a1, 6LL, 1LL, "%s: %9li.%09li\n", "unix_time_set", v3.tv_sec, v3.tv_nsec);
return 0LL;
}

original_code:
static int32_t unix_time_set(struct pp_instance *ppi, TimeInternal *t)
{
 struct timespec tp;
 tp.tv_sec = t->seconds;
 tp.tv_nsec = t->nanoseconds;
 if (clock_settime(0, &tp) < 0)
  clock_fatal_error("clock_settime");
 ({ if (1) __pp_diag(ppi, pp_dt_time, 1, "%s: %9li.%09li\n", __func__, tp.tv_sec, tp.tv_nsec); 1; });
 return 0;
}

canonical_original_code:
static int unix_time_set(struct pp_instance *ppi, struct TimeInternal *t)
{
 struct timespec tp;
 tp.tv_sec = t->seconds;
 tp.tv_nsec = t->nanoseconds;
 if (clock_settime(0, &tp) < 0)
  clock_fatal_error("clock_settime");
 ({ if (1) __pp_diag(ppi, pp_dt_time, 1, "%s: %9li.%09li\n", __func__, tp.tv_sec, tp.tv_nsec); 1; });
 return 0;
}

variable_types:
t
struct TimeInternal *

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

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

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

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

user_defined_types: struct pp_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_owd_fltr { int nsec_prev; int y; int s_exp; }

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

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

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

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

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


decompiled_code:
__int64 __fastcall unix_time_get(__int64 a1, _DWORD *a2)
{
__time_t v2; // r9
__syscall_slong_t v3; // rax
struct timespec v5; // [rsp+0h] [rbp-28h] BYREF

if ( clock_gettime(0, &v5) < 0 )
clock_fatal_error("clock_gettime");
v2 = v5.tv_sec;
v3 = v5.tv_nsec;
*a2 = v5.tv_sec;
a2[1] = v3;
if ( (pp_global_flags & 1) == 0 )
_pp_diag(a1, 6LL, 2LL, "%s: %9li.%09li\n", "unix_time_get", v2, v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, _DWORD *a2)
{
__time_t v2; // r9
__syscall_slong_t v3; // rax
struct timespec v5; // [rsp+0h] [rbp-28h] BYREF

if ( clock_gettime(0, &v5) < 0 )
func4("clock_gettime");
v2 = v5.tv_sec;
v3 = v5.tv_nsec;
*a2 = v5.tv_sec;
a2[1] = v3;
if ( (pp_global_flags & 1) == 0 )
_pp_diag(a1, 6LL, 2LL, "%s: %9li.%09li\n", "unix_time_get", v2, v3);
return 0LL;
}

original_code:
static int unix_time_get(struct pp_instance *ppi, TimeInternal *t)
{
 struct timespec tp;
 if (clock_gettime(0, &tp) < 0)
  clock_fatal_error("clock_gettime");
 t->seconds = tp.tv_sec;
 t->nanoseconds = tp.tv_nsec;
 if (!(pp_global_flags & 1))
  ({ if (1) __pp_diag(ppi, pp_dt_time, 2, "%s: %9li.%09li\n", __func__, tp.tv_sec, tp.tv_nsec); 1; });
 return 0;
}

canonical_original_code:
static int unix_time_get(struct pp_instance *ppi, struct TimeInternal *t)
{
 struct timespec tp;
 if (clock_gettime(0, &tp) < 0)
  clock_fatal_error("clock_gettime");
 t->seconds = tp.tv_sec;
 t->nanoseconds = tp.tv_nsec;
 if (!(pp_global_flags & 1))
  ({ if (1) __pp_diag(ppi, pp_dt_time, 2, "%s: %9li.%09li\n", __func__, tp.tv_sec, tp.tv_nsec); 1; });
 return 0;
}

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

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

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

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

user_defined_types: struct 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 do_stat(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3[38]; // [rsp+0h] [rbp-98h] BYREF

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

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

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

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

variable_types:
client
struct minipc_ch { int fd; } *

variable_types:
argv
char **

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

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


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

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

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

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

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

variable_types:
buf
char [256]


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

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

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

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

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

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

variable_types: len int


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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


decompiled_code:
__int64 __fastcall do_count(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 result; // rax
int v6[4]; // [rsp+8h] [rbp-10h] BYREF

result = minipc_call(a1, 200LL, &rpc_count, v6, a5);
if ( (int)result >= 0 )
{
printf("counts: %i %i\n", (unsigned int)v6[0], (unsigned int)v6[1]);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 result; // rax
int v6[4]; // [rsp+8h] [rbp-10h] BYREF

result = minipc_call(a1, 200LL, &rpc_count, v6, a5);
if ( (int)result >= 0 )
{
printf("counts: %i %i\n", (unsigned int)v6[0], (unsigned int)v6[1]);
result = 0LL;
}
return result;
}

original_code:
static int do_count(struct minipc_ch *client, char **argv)
{
 int ret;
 struct pty_counts c;
 ret = minipc_call(client, 200, &rpc_count, &c);
 if (ret < 0)
  return ret;
 printf("counts: %i %i\n", c.in, c.out);
 return 0;
}

variable_types:
c
struct pty_counts { int in; }

user_defined_types:
struct pty_counts { int in; }
struct minipc_ch { int fd; }


decompiled_code:
void __fastcall clear_TimeInternal(__int64 a1)
{
*(_DWORD *)(a1 + 16) = 0;
*(_OWORD *)a1 = 0LL;
}

original_code:
static inline void clear_TimeInternal(struct TimeInternal *t)
{
 memset(t, 0, sizeof(*t));
}

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


idcmp

decompiled_code:
int __fastcall idcmp(const void *a1, const void *a2)
{
return memcmp(a1, a2, 8uLL);
}

canonical_decompiled_code:
int __fastcall func1(const void *a1, const void *a2)
{
return memcmp(a1, a2, 8uLL);
}

original_code:
static int idcmp(struct ClockIdentity *a, struct ClockIdentity *b)
{
 return memcmp(a, b, sizeof(*a));
}

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

variable_types:
b
struct ClockIdentity *


decompiled_code:
__int64 __fastcall bmc_dataset_cmp(__int64 a1, __int64 a2, __int64 a3)
{
int v4; // eax
unsigned int v5; // er12
const void *v6; // rsi
const void *v7; // r8
const void *v8; // rbp
int v10; // edx
unsigned __int8 v11; // al

_pp_diag(a1, 3LL, 2LL, &unk_732, "bmc_dataset_cmp");
v4 = idcmp((const void *)(a2 + 37), (const void *)(a3 + 37));
if ( !v4 )
{
v5 = *(unsigned __int16 *)(a2 + 46) - *(unsigned __int16 *)(a3 + 46);
if ( v5 + 1 <= 2 )
{
v6 = (const void *)DSPAR_isra_0(*(_QWORD *)(a1 + 40));
if ( v5 == 1 )
{
if ( !idcmp(v7, v6) )
{
LABEL_15:
_pp_diag(a1, 3LL, 1LL, "%s:%i: Error 1\n", "bmc_dataset_cmp");
return 0LL;
}
}
else
{
v8 = (const void *)(a3 + 84);
if ( v5 != -1 )
{
v5 = idcmp(v7, v8);
if ( !v5 )
_pp_diag(a1, 3LL, 1LL, "%s:%i: Error 2\n", "bmc_dataset_cmp");
return v5;
}
if ( !idcmp(v8, v6) )
goto LABEL_15;
}
}
return v5;
}
v5 = v4;
v10 = *(unsigned __int8 *)(a3 + 30);
v11 = *(_BYTE *)(a2 + 30);
if ( v11 != (_BYTE)v10 )
return (unsigned int)v11 - v10;
v11 = *(_BYTE *)(a2 + 32);
v10 = *(unsigned __int8 *)(a3 + 32);
if ( v11 != (_BYTE)v10 )
return (unsigned int)v11 - v10;
v11 = *(_BYTE *)(a2 + 33);
v10 = *(unsigned __int8 *)(a3 + 33);
if ( v11 != (_BYTE)v10 )
return (unsigned int)v11 - v10;
if ( *(_WORD *)(a2 + 34) == *(_WORD *)(a3 + 34) )
{
v11 = *(_BYTE *)(a2 + 36);
v10 = *(unsigned __int8 *)(a3 + 36);
if ( v11 == (_BYTE)v10 )
return v5;
return (unsigned int)v11 - v10;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3)
{
int v4; // eax
unsigned int v5; // er12
const void *v6; // rsi
const void *v7; // r8
const void *v8; // rbp
int v10; // edx
unsigned __int8 v11; // al

_pp_diag(a1, 3LL, 2LL, &unk_732, "bmc_dataset_cmp");
v4 = func1((const void *)(a2 + 37), (const void *)(a3 + 37));
if ( !v4 )
{
v5 = *(unsigned __int16 *)(a2 + 46) - *(unsigned __int16 *)(a3 + 46);
if ( v5 + 1 <= 2 )
{
v6 = (const void *)func7(*(_QWORD *)(a1 + 40));
if ( v5 == 1 )
{
if ( !func1(v7, v6) )
{
LABEL_15:
_pp_diag(a1, 3LL, 1LL, "%s:%i: Error 1\n", "bmc_dataset_cmp");
return 0LL;
}
}
else
{
v8 = (const void *)(a3 + 84);
if ( v5 != -1 )
{
v5 = func1(v7, v8);
if ( !v5 )
_pp_diag(a1, 3LL, 1LL, "%s:%i: Error 2\n", "bmc_dataset_cmp");
return v5;
}
if ( !func1(v8, v6) )
goto LABEL_15;
}
}
return v5;
}
v5 = v4;
v10 = *(unsigned __int8 *)(a3 + 30);
v11 = *(_BYTE *)(a2 + 30);
if ( v11 != (_BYTE)v10 )
return (unsigned int)v11 - v10;
v11 = *(_BYTE *)(a2 + 32);
v10 = *(unsigned __int8 *)(a3 + 32);
if ( v11 != (_BYTE)v10 )
return (unsigned int)v11 - v10;
v11 = *(_BYTE *)(a2 + 33);
v10 = *(unsigned __int8 *)(a3 + 33);
if ( v11 != (_BYTE)v10 )
return (unsigned int)v11 - v10;
if ( *(_WORD *)(a2 + 34) == *(_WORD *)(a3 + 34) )
{
v11 = *(_BYTE *)(a2 + 36);
v10 = *(unsigned __int8 *)(a3 + 36);
if ( v11 == (_BYTE)v10 )
return v5;
return (unsigned int)v11 - v10;
}
return 0LL;
}

original_code:
static int bmc_dataset_cmp(struct pp_instance *ppi,
      struct pp_frgn_master *a,
      struct pp_frgn_master *b)
{
 struct ClockQuality *qa, *qb;
 struct MsgAnnounce *aa = &a->ann;
 struct MsgAnnounce *ab = &b->ann;
 struct ClockIdentity *ida = &a->hdr.sourcePortIdentity.clockIdentity;
 struct ClockIdentity *idb = &b->hdr.sourcePortIdentity.clockIdentity;
 struct ClockIdentity *idparent;
 int diff;
 ({ if (1) __pp_diag(ppi, pp_dt_bmc, 2, "%s\n", __func__); 1; });
 if (!idcmp(&aa->grandmasterIdentity, &ab->grandmasterIdentity)) {
  diff = aa->stepsRemoved - ab->stepsRemoved;
  if (diff > 1 || diff < -1)
   return diff;
  idparent = &DSPAR(ppi)->parentPortIdentity.clockIdentity;
  if (diff > 0) {
   if (!idcmp(ida, idparent)) {
    ({ if (1) __pp_diag(ppi, pp_dt_bmc, 1, "%s:%i: Error 1\n", __func__, 135); 1; });
    return 0;
   }
   return 1;
  }
  if (diff < 0) {
   if (!idcmp(idb, idparent)) {
    ({ if (1) __pp_diag(ppi, pp_dt_bmc, 1, "%s:%i: Error 1\n", __func__, 144); 1; });
    return 0;
   }
   return -1;
  }
  diff = idcmp(ida, idb);
  if (!diff) {
   ({ if (1) __pp_diag(ppi, pp_dt_bmc, 1, "%s:%i: Error 2\n", __func__, 152); 1; });
   return 0;
  }
  return diff;
 }
 qa = &aa->grandmasterClockQuality;
 qb = &ab->grandmasterClockQuality;
 if (aa->grandmasterPriority1 != ab->grandmasterPriority1)
  return aa->grandmasterPriority1 - ab->grandmasterPriority1;
 if (qa->clockClass != qb->clockClass)
  return qa->clockClass - qb->clockClass;
 if (qa->clockAccuracy != qb->clockAccuracy)
  return qa->clockAccuracy - qb->clockAccuracy;
 if (qa->offsetScaledLogVariance != qb->offsetScaledLogVariance)
  return qa->clockClass - qb->clockClass;
 if (aa->grandmasterPriority2 != ab->grandmasterPriority2)
  return aa->grandmasterPriority2 - ab->grandmasterPriority2;
 return idcmp(&aa->grandmasterIdentity, &ab->grandmasterIdentity);
}

canonical_original_code:
static int bmc_dataset_cmp(struct pp_instance *ppi, struct pp_frgn_master *a, struct pp_frgn_master *b)
{
 struct ClockQuality *qa; struct ClockQuality *qb;
 struct MsgAnnounce *aa = &a->ann;
 struct MsgAnnounce *ab = &b->ann;
 struct ClockIdentity *ida = &a->hdr.sourcePortIdentity.clockIdentity;
 struct ClockIdentity *idb = &b->hdr.sourcePortIdentity.clockIdentity;
 struct ClockIdentity *idparent;
 int diff;
 ({ if (1) __pp_diag(ppi, pp_dt_bmc, 2, "%s\n", __func__); 1; });
 if (!idcmp(&aa->grandmasterIdentity, &ab->grandmasterIdentity)) {
  diff = aa->stepsRemoved - ab->stepsRemoved;
  if (diff > 1 || diff < -1)
   return diff;
  idparent = &DSPAR(ppi)->parentPortIdentity.clockIdentity;
  if (diff > 0) {
   if (!idcmp(ida, idparent)) {
    ({ if (1) __pp_diag(ppi, pp_dt_bmc, 1, "%s:%i: Error 1\n", __func__, 135); 1; });
    return 0;
   }
   return 1;
  }
  if (diff < 0) {
   if (!idcmp(idb, idparent)) {
    ({ if (1) __pp_diag(ppi, pp_dt_bmc, 1, "%s:%i: Error 1\n", __func__, 144); 1; });
    return 0;
   }
   return -1;
  }
  diff = idcmp(ida, idb);
  if (!diff) {
   ({ if (1) __pp_diag(ppi, pp_dt_bmc, 1, "%s:%i: Error 2\n", __func__, 152); 1; });
   return 0;
  }
  return diff;
 }
 qa = &aa->grandmasterClockQuality;
 qb = &ab->grandmasterClockQuality;
 if (aa->grandmasterPriority1 != ab->grandmasterPriority1)
  return aa->grandmasterPriority1 - ab->grandmasterPriority1;
 if (qa->clockClass != qb->clockClass)
  return qa->clockClass - qb->clockClass;
 if (qa->clockAccuracy != qb->clockAccuracy)
  return qa->clockAccuracy - qb->clockAccuracy;
 if (qa->offsetScaledLogVariance != qb->offsetScaledLogVariance)
  return qa->clockClass - qb->clockClass;
 if (aa->grandmasterPriority2 != ab->grandmasterPriority2)
  return aa->grandmasterPriority2 - ab->grandmasterPriority2;
 return idcmp(&aa->grandmasterIdentity, &ab->grandmasterIdentity);
}

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

variable_types:
a
struct pp_frgn_master *

variable_types:
b
struct pp_frgn_master *

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

variable_types: 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 { unsigned char id[8]; } grandmasterIdentity; unsigned short stepsRemoved; unsigned char timeSource; unsigned long ext_specific; } *

variable_types: diff int

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

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

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

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


original_code:
void m1(struct pp_instance *ppi)
{
 struct DSParent *parent = DSPAR(ppi);
 struct DSDefault *defds = DSDEF(ppi);
 DSCUR(ppi)->stepsRemoved = 0;
 clear_TimeInternal(&DSCUR(ppi)->offsetFromMaster);
 clear_TimeInternal(&DSCUR(ppi)->meanPathDelay);
 memset(parent, 0, sizeof(*parent));
 parent->parentPortIdentity.clockIdentity = defds->clockIdentity;
 parent->grandmasterIdentity = defds->clockIdentity;
 parent->grandmasterClockQuality = defds->clockQuality;
 parent->grandmasterPriority1 = defds->priority1;
 parent->grandmasterPriority2 = defds->priority2;
 DSPRO(ppi)->timeSource = INTERNAL_OSCILLATOR;
}

variable_types: struct DSParent { struct PortIdentity { struct ClockIdentity { unsigned char id[8]; } clockIdentity; unsigned short portNumber; } parentPortIdentity; unsigned short observedParentOffsetScaledLogVariance; int observedParentClockPhaseChangeRate; struct ClockIdentity grandmasterIdentity; struct ClockQuality { unsigned char clockClass; unsigned char clockAccuracy; unsigned short offsetScaledLogVariance; } grandmasterClockQuality; unsigned char grandmasterPriority1; unsigned char grandmasterPriority2; } *

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

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

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

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

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall bmc_state_decision(unsigned int *a1, __int64 a2)
{
char v2; // al
__int64 result; // rax
__int64 v4; // rax
int v5; // edx
__int64 v6; // r8
_BYTE v7[37]; // [rsp+0h] [rbp-88h] BYREF
char v8[99]; // [rsp+25h] [rbp-63h] BYREF

v2 = *((_BYTE *)a1 + 1416);
if ( (v2 & 8) != 0 )
goto LABEL_14;
if ( (v2 & 4) != 0 )
goto LABEL_16;
if ( *((_WORD *)a1 + 354) || (result = *a1, (_DWORD)result != 4) )
{
copy_d0_isra_0(*((_QWORD *)a1 + 5), (__int64)v7);
bmc_dataset_cmp((__int64)a1, (__int64)v7, a2);
v4 = DSDEF_isra_0(*((_QWORD *)a1 + 5));
if ( *(char *)(v4 + 14) >= 0 )
{
if ( v5 >= 0 )
{
if ( !v5 )
{
LABEL_8:
_pp_diag(a1, 3LL, 1LL, "%s: error\n", "bmc_state_decision");
return 2LL;
}
goto LABEL_17;
}
goto LABEL_14;
}
if ( v5 >= 0 )
{
if ( !v5 )
goto LABEL_8;
if ( *(_WORD *)(v4 + 12) != 1 && a1[358] != *(_DWORD *)(GLBS_isra_0(v6) + 56) )
{
if ( !idcmp(v8, (const void *)(a2 + 37)) )
{
LABEL_17:
_pp_diag(a1, 3LL, 1LL, "%s: passive\n", "bmc_state_decision");
return 7LL;
}
goto LABEL_14;
}
LABEL_16:
s1((__int64)a1, a2 + 64);
_pp_diag(a1, 3LL, 1LL, "%s: slave\n", "bmc_state_decision");
return 9LL;
}
LABEL_14:
m1((__int64)a1);
_pp_diag(a1, 3LL, 1LL, "%s: master\n", "bmc_state_decision");
result = 6LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1, __int64 a2)
{
char v2; // al
__int64 result; // rax
__int64 v4; // rax
int v5; // edx
__int64 v6; // r8
_BYTE v7[37]; // [rsp+0h] [rbp-88h] BYREF
char v8[99]; // [rsp+25h] [rbp-63h] BYREF

v2 = *((_BYTE *)a1 + 1416);
if ( (v2 & 8) != 0 )
goto LABEL_14;
if ( (v2 & 4) != 0 )
goto LABEL_16;
if ( *((_WORD *)a1 + 354) || (result = *a1, (_DWORD)result != 4) )
{
func5(*((_QWORD *)a1 + 5), (__int64)v7);
func8((__int64)a1, (__int64)v7, a2);
v4 = func4(*((_QWORD *)a1 + 5));
if ( *(char *)(v4 + 14) >= 0 )
{
if ( v5 >= 0 )
{
if ( !v5 )
{
LABEL_8:
_pp_diag(a1, 3LL, 1LL, "%s: error\n", "bmc_state_decision");
return 2LL;
}
goto LABEL_17;
}
goto LABEL_14;
}
if ( v5 >= 0 )
{
if ( !v5 )
goto LABEL_8;
if ( *(_WORD *)(v4 + 12) != 1 && a1[358] != *(_DWORD *)(func3(v6) + 56) )
{
if ( !func1(v8, (const void *)(a2 + 37)) )
{
LABEL_17:
_pp_diag(a1, 3LL, 1LL, "%s: passive\n", "bmc_state_decision");
return 7LL;
}
goto LABEL_14;
}
LABEL_16:
s1((__int64)a1, a2 + 64);
_pp_diag(a1, 3LL, 1LL, "%s: slave\n", "bmc_state_decision");
return 9LL;
}
LABEL_14:
func10((__int64)a1);
_pp_diag(a1, 3LL, 1LL, "%s: master\n", "bmc_state_decision");
result = 6LL;
}
return result;
}

original_code:
static int bmc_state_decision(struct pp_instance *ppi,
         struct pp_frgn_master *m)
{
 int cmpres;
 struct pp_frgn_master myself;
 if (ppi->master_only)
  goto master;
 if (ppi->slave_only)
  goto slave;
 if ((!ppi->frgn_rec_num) && (ppi->state == PPS_LISTENING))
  return PPS_LISTENING;
 copy_d0(ppi, &myself);
 cmpres = bmc_dataset_cmp(ppi, &myself, m);
 if (DSDEF(ppi)->clockQuality.clockClass < 128) {
  if (cmpres < 0)
   goto master;
  if (cmpres > 0)
   goto passive;
 }
 if (cmpres < 0)
  goto master;
 if (cmpres > 0) {
  if (DSDEF(ppi)->numberPorts == 1)
   goto slave;
  else
   goto check_boundary_clk;
 }
 ({ if (1) __pp_diag(ppi, pp_dt_bmc, 1, "%s: error\n", __func__); 1; });
 return PPS_FAULTY;
check_boundary_clk:
 if (ppi->port_idx == GLBS(ppi)->ebest_idx)
  goto slave;
 if (!idcmp(&myself.ann.grandmasterIdentity,
   &m->ann.grandmasterIdentity))
  goto passive;
 else
  goto master;
passive:
 p1(ppi, &m->hdr, &m->ann);
 ({ if (1) __pp_diag(ppi, pp_dt_bmc, 1, "%s: passive\n", __func__); 1; });
 return PPS_PASSIVE;
master:
 m1(ppi);
 ({ if (1) __pp_diag(ppi, pp_dt_bmc, 1, "%s: master\n", __func__); 1; });
 return PPS_MASTER;
slave:
 s1(ppi, &m->hdr, &m->ann);
 ({ if (1) __pp_diag(ppi, pp_dt_bmc, 1, "%s: slave\n", __func__); 1; });
 return PPS_SLAVE;
}

variable_types:
m
struct pp_frgn_master *

variable_types: cmpres int

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

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

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_servo { struct TimeInternal m_to_s_dly; struct TimeInternal s_to_m_dly; struct TimeInternal delay_ms; struct TimeInternal delay_sm; int obs_drift; struct pp_owd_fltr owd_fltr; struct pp_ofm_fltr ofm_fltr; }

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

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

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


canonical_decompiled_code:
void func12()
{
;
}

original_code:
void p1(struct pp_instance *ppi, MsgHeader *hdr, MsgAnnounce *ann)
{
}

canonical_original_code:
void p1(struct pp_instance *ppi, struct MsgHeader *hdr, struct MsgAnnounce *ann)
{
}

variable_types:
hdr
struct MsgHeader *

variable_types:
ann
struct MsgAnnounce *

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

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

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

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

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

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


original_code:
void bmc_update_ebest(struct pp_globals *ppg)
{
 int i, best;
 struct pp_instance *ppi, *ppi_best;
 for (i = 1, best = 0; i < ppg->defaultDS->numberPorts; i++) {
  ppi_best = &ppg->pp_instances[best];
  ppi = &ppg->pp_instances[i];
  if ((ppi->frgn_rec_num > 0) &&
    (bmc_dataset_cmp(ppi,
    &ppi_best->frgn_master[ppi_best->frgn_rec_best],
    &ppi->frgn_master[ppi->frgn_rec_best])
    < 0))
    best = i;
 }
 if (ppg->ebest_idx != best) {
  ppg->ebest_idx = best;
  ppg->ebest_updated = 1;
 }
}

canonical_original_code:
void bmc_update_ebest(struct pp_globals *ppg)
{
 int i; int best;
 struct pp_instance *ppi; struct pp_instance *ppi_best;
 for (i = 1, best = 0; i < ppg->defaultDS->numberPorts; i++) {
  ppi_best = &ppg->pp_instances[best];
  ppi = &ppg->pp_instances[i];
  if ((ppi->frgn_rec_num > 0) &&
    (bmc_dataset_cmp(ppi,
    &ppi_best->frgn_master[ppi_best->frgn_rec_best],
    &ppi->frgn_master[ppi->frgn_rec_best])
    < 0))
    best = i;
 }
 if (ppg->ebest_idx != best) {
  ppg->ebest_idx = best;
  ppg->ebest_updated = 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: i int

variable_types: best int

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


bmc

original_code:
int bmc(struct pp_instance *ppi)
{
 struct pp_frgn_master *frgn_master = ppi->frgn_master;
 int i, best;
 if (!ppi->frgn_rec_num)
  if (ppi->state == PPS_MASTER) {
   m1(ppi);
   return ppi->state;
  }
 for (i = 1, best = 0; i < ppi->frgn_rec_num; i++)
  if (bmc_dataset_cmp(ppi, &frgn_master[i], &frgn_master[best])
      < 0)
   best = i;
 ({ if (1) __pp_diag(ppi, pp_dt_bmc, 1, "Best foreign master is %i\n", best); 1; });
 if (ppi->frgn_rec_best != best) {
  ppi->frgn_rec_best = best;
  bmc_update_ebest(GLBS(ppi));
 }
 return bmc_state_decision(ppi, &frgn_master[best]);
}

canonical_original_code:
int bmc(struct pp_instance *ppi)
{
 struct pp_frgn_master *frgn_master = ppi->frgn_master;
 int i; int best;
 if (!ppi->frgn_rec_num)
  if (ppi->state == PPS_MASTER) {
   m1(ppi);
   return ppi->state;
  }
 for (i = 1, best = 0; i < ppi->frgn_rec_num; i++)
  if (bmc_dataset_cmp(ppi, &frgn_master[i], &frgn_master[best])
      < 0)
   best = i;
 ({ if (1) __pp_diag(ppi, pp_dt_bmc, 1, "Best foreign master is %i\n", best); 1; });
 if (ppi->frgn_rec_best != best) {
  ppi->frgn_rec_best = best;
  bmc_update_ebest(GLBS(ppi));
 }
 return bmc_state_decision(ppi, &frgn_master[best]);
}

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

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_servo { struct TimeInternal m_to_s_dly; struct TimeInternal s_to_m_dly; struct TimeInternal delay_ms; struct TimeInternal delay_sm; int obs_drift; struct pp_owd_fltr owd_fltr; struct pp_ofm_fltr ofm_fltr; }

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

user_defined_types: struct 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 pp_owd_fltr { int nsec_prev; int y; int s_exp; }

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


decompiled_code:
__int64 __fastcall pp_faulty(__int64 a1)
{
_pp_diag(a1, 7LL, 1LL, "Faulty state detected\n");
*(_DWORD *)(a1 + 4) = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
_pp_diag(a1, 7LL, 1LL, "Faulty state detected\n");
*(_DWORD *)(a1 + 4) = 1;
return 0LL;
}

original_code:
int pp_faulty(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
 ({ if (1) __pp_diag(ppi, pp_dt_fsm, 1, "Faulty state detected\n"); 1; });
 ppi->next_state = PPS_INITIALIZING;
 return 0;
}

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

variable_types:
pkt
unsigned char *

variable_types: plen int

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

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

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

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

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


puts

decompiled_code:
__int64 puts()
{
pp_puts();
return 0LL;
}

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

original_code:
int puts(const char *s)
{
 pp_puts(s);
 return 0;
}

canonical_original_code:
int puts(char *s)
{
 pp_puts(s);
 return 0;
}

variable_types:
s
char *


memcmp

decompiled_code:
__int64 __fastcall memcmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
int v7; // edx
int v8; // ecx
unsigned int v9; // edx

v4 = 0LL;
while ( v4 != a3 )
{
v7 = *(unsigned __int8 *)(a1 + v4);
v8 = *(unsigned __int8 *)(a2 + v4++);
v9 = v7 - v8;
if ( v9 )
return v9;
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
int v7; // edx
int v8; // ecx
unsigned int v9; // edx

v4 = 0LL;
while ( v4 != a3 )
{
v7 = *(unsigned __int8 *)(a1 + v4);
v8 = *(unsigned __int8 *)(a2 + v4++);
v9 = v7 - v8;
if ( v9 )
return v9;
}
return 0;
}

original_code:
int memcmp(const void *s1, const void *s2, size_t n)
{
 register const unsigned char *r1 = s1;
 register const unsigned char *r2 = s2;
 int r = 0;
 while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0))
  ;
 return r;
}

canonical_original_code:
int memcmp(void *s1, void *s2, unsigned long n)
{
 register unsigned char *r1 = s1;
 register unsigned char *r2 = s2;
 int r = 0;
 while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0))
  ;
 return r;
}

variable_types:
n
unsigned long

variable_types: r int


strtol

decompiled_code:
__int64 __fastcall strtol(_BYTE *a1, _QWORD *a2, int a3)
{
int v3; // ecx
__int64 i; // r8
__int64 v5; // rax

v3 = a3;
if ( !a3 )
v3 = 10;
for ( i = 0LL; *a1; i = v3 * i + v5 - 48 )
{
if ( a2 )
*a2 = a1;
if ( v3 > 10 )
break;
v5 = (char)*a1;
if ( (char)v5 <= 47 )
break;
if ( v3 + 47 < (char)v5 )
break;
++a1;
}
return i;
}

original_code:
long int strtol(const char *s, char **end, int base)
{
 long res = 0;
 if (!base)
  base = 10;
 while (*s) {
  if (end)
   *end = (void *)s;
  if (base > 10 || *s < '0' || *s >= '0' + base) {
   return res;
  }
  res = res * base + *(s++) - '0';
 }
 return res;
}

canonical_original_code:
long strtol(char *s, char **end, int base)
{
 long res = 0;
 if (!base)
  base = 10;
 while (*s) {
  if (end)
   *end = (void *)s;
  if (base > 10 || *s < '0' || *s >= '0' + base) {
   return res;
  }
  res = res * base + *(s++) - '0';
 }
 return res;
}

variable_types:
end
char **

variable_types: base int

variable_types: res long

return_type: long


atoi

decompiled_code:
__int64 __fastcall atoi(_BYTE *a1)
{
return strtol(a1, 0LL, 10);
}

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1)
{
return func5(a1, 0LL, 10);
}

original_code:
int atoi(const char *s)
{
 return strtol(s, ((void *)0), 10);
}

canonical_original_code:
int atoi(char *s)
{
 return strtol(s, ((void *)0), 10);
}


decompiled_code:
void __fastcall pp_timeout_clr(__int64 a1, int a2)
{
*(_QWORD *)(a1 + 8LL * a2 + 1248) = 0LL;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
*(_QWORD *)(a1 + 8LL * a2 + 1248) = 0LL;
}

original_code:
static inline void pp_timeout_clr(struct pp_instance *ppi, int index)
{
 ppi->timeouts[index] = 0;
}

variable_types: index int

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

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

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

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall pp_ms_to_timeout(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbx

result = 0LL;
v3 = *(_QWORD *)(a1 + 8LL * a2 + 1248);
if ( v3 )
{
v4 = v3 - (*(__int64 (__fastcall **)(__int64, _QWORD))(*(_QWORD *)(a1 + 56) + 40LL))(a1, 0LL);
if ( v4 < 0 )
LODWORD(v4) = 0;
result = (unsigned int)v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbx

result = 0LL;
v3 = *(_QWORD *)(a1 + 8LL * a2 + 1248);
if ( v3 )
{
v4 = v3 - (*(__int64 (__fastcall **)(__int64, _QWORD))(*(_QWORD *)(a1 + 56) + 40LL))(a1, 0LL);
if ( v4 < 0 )
LODWORD(v4) = 0;
result = (unsigned int)v4;
}
return result;
}

original_code:
static inline int pp_ms_to_timeout(struct pp_instance *ppi, int index)
{
 signed long ret;
 if (!ppi->timeouts[index])
  return 0;
 ret = ppi->timeouts[index] - ppi->t_ops->calc_timeout(ppi, 0);
 return ret <= 0 ? 0 : ret;
}

canonical_original_code:
static inline int pp_ms_to_timeout(struct pp_instance *ppi, int index)
{
 long ret;
 if (!ppi->timeouts[index])
  return 0;
 ret = ppi->timeouts[index] - ppi->t_ops->calc_timeout(ppi, 0);
 return ret <= 0 ? 0 : ret;
}

variable_types: ret long

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

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

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

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

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

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

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


decompiled_code:
void __fastcall pp_timeout_z(__int64 a1, unsigned int a2)
{
if ( (unsigned int)pp_timeout(a1, a2) )
pp_timeout_clr(a1, a2);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, unsigned int a2)
{
if ( (unsigned int)func2(a1, a2) )
func0(a1, a2);
}

original_code:
static inline int pp_timeout_z(struct pp_instance *ppi, int index)
{
 int ret = pp_timeout(ppi, index);
 if (ret)
  pp_timeout_clr(ppi, index);
 return ret;
}

variable_types: ret int

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

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

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

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

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

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

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

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

user_defined_types: struct 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_ofm_fltr { int nsec_prev; int y; }