decompiled_code:
int __fastcall dump_payload(const char *a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rdx
unsigned __int8 *v7; // r14
unsigned __int8 v8; // bl
unsigned __int16 v9; // ax
unsigned __int16 v10; // ax
int v11; // ebx
unsigned int v12; // edx

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

canonical_decompiled_code:
int __fastcall func15(const char *a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rdx
unsigned __int8 *v7; // r14
unsigned __int8 v8; // bl
unsigned __int16 v9; // ax
unsigned __int16 v10; // ax
int v11; // ebx
unsigned int v12; // edx

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

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

variable_types:
pl
void *

variable_types: len int

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

variable_types: donelen int

variable_types: version int

variable_types: messageType int

variable_types: n int

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


repo: tinito/ppsi-chibios

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

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

variable_types:
prefix
char *

variable_types:
buf
void *

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

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

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

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

variable_types:
payload
void *

return_type: int


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

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

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

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


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

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

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

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


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

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

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

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

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

variable_types:
client
struct minipc_ch { int fd; } *

variable_types:
argv
char **

variable_types: ret int

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

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


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

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

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

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

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

variable_types:
buf
char [256]


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

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

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

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

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

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

variable_types: len int


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

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

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

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

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

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


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

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

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

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

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


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

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

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

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

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

variable_types: a int

variable_types: b int

variable_types: sum int


decompiled_code:
__int64 __fastcall shm_server_do_stat(__int64 a1, const char *a2, __m128i *a3)
{
struct stat v5; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a2, &v5) < 0 )
return 0xFFFFFFFFLL;
*a3 = _mm_loadu_si128((const __m128i *)&v5);
a3[1] = _mm_loadu_si128((const __m128i *)&v5.st_nlink);
a3[2] = _mm_loadu_si128((const __m128i *)&v5.st_gid);
a3[3] = _mm_loadu_si128((const __m128i *)&v5.st_size);
a3[4] = _mm_loadu_si128((const __m128i *)&v5.st_blocks);
a3[5] = _mm_loadu_si128((const __m128i *)&v5.st_atim.tv_nsec);
a3[6] = _mm_loadu_si128((const __m128i *)&v5.st_mtim.tv_nsec);
a3[7] = _mm_loadu_si128((const __m128i *)&v5.st_ctim.tv_nsec);
a3[8] = _mm_loadu_si128((const __m128i *)&v5.__unused[1]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, __m128i *a3)
{
struct stat v5; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a2, &v5) < 0 )
return 0xFFFFFFFFLL;
*a3 = _mm_loadu_si128((const __m128i *)&v5);
a3[1] = _mm_loadu_si128((const __m128i *)&v5.st_nlink);
a3[2] = _mm_loadu_si128((const __m128i *)&v5.st_gid);
a3[3] = _mm_loadu_si128((const __m128i *)&v5.st_size);
a3[4] = _mm_loadu_si128((const __m128i *)&v5.st_blocks);
a3[5] = _mm_loadu_si128((const __m128i *)&v5.st_atim.tv_nsec);
a3[6] = _mm_loadu_si128((const __m128i *)&v5.st_mtim.tv_nsec);
a3[7] = _mm_loadu_si128((const __m128i *)&v5.st_ctim.tv_nsec);
a3[8] = _mm_loadu_si128((const __m128i *)&v5.__unused[1]);
return 0LL;
}

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

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

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

variable_types:
args
unsigned int *

variable_types:
ret
void *

variable_types:
fname
char *

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


decompiled_code:
__int64 __fastcall shm_server_do_add(__int64 a1, int *a2, _DWORD *a3)
{
int v3; // ebp

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int *a2, _DWORD *a3)
{
int v3; // ebp

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

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

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

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


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

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

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

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

variable_types:
s
char *


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

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

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

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

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

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

variable_types:
t
char *

variable_types:
scat
char [256]


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

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

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

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

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

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

variable_types:
envname
char *

variable_types:
envval
char *


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

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

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

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

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

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

variable_types:
res
char *


main

canonical_name: main

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

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

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

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

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

variable_types: argc int

variable_types:
argv
char **

variable_types:
ch
struct minipc_ch { int fd; } *


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

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

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

v2 = a2;
if ( !a2 )
v2 = 1;
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 pp_servo { struct TimeInternal m_to_s_dly; struct TimeInternal s_to_m_dly; struct TimeInternal delay_ms; struct TimeInternal delay_sm; int obs_drift; struct pp_owd_fltr owd_fltr; struct pp_ofm_fltr ofm_fltr; }

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

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

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

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


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 )
{
if ( a3 < -512000 )
v3 = -512000LL;
if ( v3 > 512000 )
v3 = 512000LL;
v6.freq = 65 * v3;
v6.modes = 2;
}
if ( a2 )
{
v6.offset = a2 / 1000;
v6.modes |= 1u;
}
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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall 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_network_operations { int (*init)(struct pp_instance *ppi); int (*exit)(struct pp_instance *ppi); int (*recv)(struct pp_instance *ppi, void *pkt, int len, struct TimeInternal *t); int (*send)(struct pp_instance *ppi, void *pkt, int len, struct TimeInternal *t, int chtype, int use_pdelay_addr); }

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

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

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

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

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

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

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

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

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


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

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

user_defined_types: struct pp_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;
*a2 = v5.tv_sec;
v3 = v5.tv_nsec;
a2[1] = v5.tv_nsec;
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;
*a2 = v5.tv_sec;
v3 = v5.tv_nsec;
a2[1] = v5.tv_nsec;
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_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 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 DSParent { struct PortIdentity parentPortIdentity; unsigned short observedParentOffsetScaledLogVariance; int observedParentClockPhaseChangeRate; struct ClockIdentity grandmasterIdentity; struct ClockQuality grandmasterClockQuality; unsigned char grandmasterPriority1; unsigned char grandmasterPriority2; }

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


decompiled_code:
__int64 __fastcall 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: 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;
}

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


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)
{
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 0;
}

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 func8(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 v5; // eax
int v6; // ebx
const void *v7; // rbp
const void *v8; // rsi
unsigned __int8 v9; // al
unsigned __int8 v10; // dl
unsigned __int8 v12; // al
unsigned __int8 v13; // dl
unsigned __int8 v14; // si
unsigned __int8 v15; // cl
unsigned __int8 v16; // al
unsigned __int8 v17; // dl

_pp_diag(a1, 3LL, 2LL, &unk_723, "bmc_dataset_cmp");
v5 = idcmp((const void *)(a2 + 37), (const void *)(a3 + 37));
if ( v5 )
{
v6 = v5;
v9 = *(_BYTE *)(a2 + 30);
v10 = *(_BYTE *)(a3 + 30);
if ( v9 == v10 )
{
v12 = *(_BYTE *)(a2 + 32);
v13 = *(_BYTE *)(a3 + 32);
if ( v12 == v13 )
{
v14 = *(_BYTE *)(a2 + 33);
v15 = *(_BYTE *)(a3 + 33);
if ( v14 == v15 )
{
if ( *(_WORD *)(a2 + 34) == *(_WORD *)(a3 + 34) )
{
v16 = *(_BYTE *)(a2 + 36);
v17 = *(_BYTE *)(a3 + 36);
if ( v16 != v17 )
v6 = v16 - v17;
}
else
{
v6 = v12 - v13;
}
}
else
{
v6 = v14 - v15;
}
}
else
{
v6 = v12 - v13;
}
}
else
{
v6 = v9 - v10;
}
}
else
{
v6 = *(unsigned __int16 *)(a2 + 46) - *(unsigned __int16 *)(a3 + 46);
if ( (unsigned int)(v6 + 1) <= 2 )
{
v7 = (const void *)(a2 + 84);
v8 = (const void *)DSPAR(a1);
if ( v6 > 0 )
{
v6 = idcmp(v7, v8);
if ( v6 )
return 1;
LABEL_11:
_pp_diag(a1, 3LL, 1LL, "%s:%i: Error 1\n", "bmc_dataset_cmp");
return (unsigned int)v6;
}
if ( v6 < 0 )
{
v6 = idcmp((const void *)(a3 + 84), v8);
if ( v6 )
return (unsigned int)-1;
goto LABEL_11;
}
v6 = idcmp(v7, (const void *)(a3 + 84));
if ( !v6 )
_pp_diag(a1, 3LL, 1LL, "%s:%i: Error 2\n", "bmc_dataset_cmp");
}
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // eax
int v6; // ebx
const void *v7; // rbp
const void *v8; // rsi
unsigned __int8 v9; // al
unsigned __int8 v10; // dl
unsigned __int8 v12; // al
unsigned __int8 v13; // dl
unsigned __int8 v14; // si
unsigned __int8 v15; // cl
unsigned __int8 v16; // al
unsigned __int8 v17; // dl

_pp_diag(a1, 3LL, 2LL, &unk_723, "bmc_dataset_cmp");
v5 = func8((const void *)(a2 + 37), (const void *)(a3 + 37));
if ( v5 )
{
v6 = v5;
v9 = *(_BYTE *)(a2 + 30);
v10 = *(_BYTE *)(a3 + 30);
if ( v9 == v10 )
{
v12 = *(_BYTE *)(a2 + 32);
v13 = *(_BYTE *)(a3 + 32);
if ( v12 == v13 )
{
v14 = *(_BYTE *)(a2 + 33);
v15 = *(_BYTE *)(a3 + 33);
if ( v14 == v15 )
{
if ( *(_WORD *)(a2 + 34) == *(_WORD *)(a3 + 34) )
{
v16 = *(_BYTE *)(a2 + 36);
v17 = *(_BYTE *)(a3 + 36);
if ( v16 != v17 )
v6 = v16 - v17;
}
else
{
v6 = v12 - v13;
}
}
else
{
v6 = v14 - v15;
}
}
else
{
v6 = v12 - v13;
}
}
else
{
v6 = v9 - v10;
}
}
else
{
v6 = *(unsigned __int16 *)(a2 + 46) - *(unsigned __int16 *)(a3 + 46);
if ( (unsigned int)(v6 + 1) <= 2 )
{
v7 = (const void *)(a2 + 84);
v8 = (const void *)func4(a1);
if ( v6 > 0 )
{
v6 = func8(v7, v8);
if ( v6 )
return 1;
LABEL_11:
_pp_diag(a1, 3LL, 1LL, "%s:%i: Error 1\n", "bmc_dataset_cmp");
return (unsigned int)v6;
}
if ( v6 < 0 )
{
v6 = func8((const void *)(a3 + 84), v8);
if ( v6 )
return (unsigned int)-1;
goto LABEL_11;
}
v6 = func8(v7, (const void *)(a3 + 84));
if ( !v6 )
_pp_diag(a1, 3LL, 1LL, "%s:%i: Error 2\n", "bmc_dataset_cmp");
}
}
return (unsigned int)v6;
}

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:
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 MsgAnnounce { struct Timestamp originTimestamp; short currentUtcOffset; unsigned char grandmasterPriority1; struct ClockQuality grandmasterClockQuality; unsigned char grandmasterPriority2; struct ClockIdentity grandmasterIdentity; unsigned short stepsRemoved; unsigned char timeSource; unsigned long ext_specific; }

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

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

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

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

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


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


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

v2 = *((_BYTE *)a1 + 1416);
if ( (v2 & 8) != 0 )
goto LABEL_15;
if ( (v2 & 4) != 0 )
goto LABEL_17;
if ( *((_WORD *)a1 + 354) || (result = *a1, (_DWORD)result != 4) )
{
copy_d0((__int64)a1, (__int64)v6);
v4 = bmc_dataset_cmp((__int64)a1, (__int64)v6, a2);
v5 = DSDEF((__int64)a1);
if ( *(char *)(v5 + 14) >= 0 )
{
if ( v4 >= 0 )
{
if ( v4 <= 0 )
{
LABEL_8:
_pp_diag(a1, 3LL, 1LL, "%s: error\n", "bmc_state_decision");
return 2LL;
}
goto LABEL_14;
}
goto LABEL_15;
}
if ( v4 >= 0 )
{
if ( v4 <= 0 )
goto LABEL_8;
if ( *(_WORD *)(v5 + 12) != 1 && a1[358] != *(_DWORD *)(GLBS((__int64)a1) + 56) )
{
if ( !idcmp(v7, (const void *)(a2 + 37)) )
{
LABEL_14:
_pp_diag(a1, 3LL, 1LL, "%s: passive\n", "bmc_state_decision");
return 7LL;
}
goto LABEL_15;
}
LABEL_17:
s1((__int64)a1, a2 + 64, a2 + 16);
_pp_diag(a1, 3LL, 1LL, "%s: slave\n", "bmc_state_decision");
return 9LL;
}
LABEL_15:
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
int v4; // er12
__int64 v5; // rax
_BYTE v6[37]; // [rsp+0h] [rbp-88h] BYREF
char v7[99]; // [rsp+25h] [rbp-63h] BYREF

v2 = *((_BYTE *)a1 + 1416);
if ( (v2 & 8) != 0 )
goto LABEL_15;
if ( (v2 & 4) != 0 )
goto LABEL_17;
if ( *((_WORD *)a1 + 354) || (result = *a1, (_DWORD)result != 4) )
{
func6((__int64)a1, (__int64)v6);
v4 = func9((__int64)a1, (__int64)v6, a2);
v5 = func2((__int64)a1);
if ( *(char *)(v5 + 14) >= 0 )
{
if ( v4 >= 0 )
{
if ( v4 <= 0 )
{
LABEL_8:
_pp_diag(a1, 3LL, 1LL, "%s: error\n", "bmc_state_decision");
return 2LL;
}
goto LABEL_14;
}
goto LABEL_15;
}
if ( v4 >= 0 )
{
if ( v4 <= 0 )
goto LABEL_8;
if ( *(_WORD *)(v5 + 12) != 1 && a1[358] != *(_DWORD *)(func0((__int64)a1) + 56) )
{
if ( !func8(v7, (const void *)(a2 + 37)) )
{
LABEL_14:
_pp_diag(a1, 3LL, 1LL, "%s: passive\n", "bmc_state_decision");
return 7LL;
}
goto LABEL_15;
}
LABEL_17:
s1((__int64)a1, a2 + 64, a2 + 16);
_pp_diag(a1, 3LL, 1LL, "%s: slave\n", "bmc_state_decision");
return 9LL;
}
LABEL_15:
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 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 DSPort { struct PortIdentity portIdentity; char logMinDelayReqInterval; char logAnnounceInterval; unsigned char announceReceiptTimeout; char logSyncInterval; unsigned char versionNumber; void *ext_dsport; }

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

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

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


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

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

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

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

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