decompiled_code:
int __fastcall parse_opt(int argc, char **argv)
{
int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "i:s:c");
if ( result == -1 )
return result;
if ( result == 105 )
{
strcpy(local_ifname, optarg);
}
else if ( result > 105 )
{
if ( result != 115 )
goto LABEL_12;
add_ips(optarg);
}
else if ( result == 49 )
{
one_shot = 1;
}
else
{
if ( result != 99 )
{
LABEL_12:
fprintf(stderr, "Usage: %s <-i iface> [-1] [-c] [-s X.X.X.X/Y]\n\n", *argv);
fwrite(" -i iface\n", 1uLL, 0xBuLL, stderr);
fwrite(" listen and send routing advertisements on interface iface\n", 1uLL, 0x40uLL, stderr);
fwrite(" -s X.X.X.X/Y\n", 1uLL, 0xFuLL, stderr);
fwrite(" advertise the subnet X.X.X.X/Y\n", 1uLL, 0x25uLL, stderr);
fwrite(" -1\n", 1uLL, 5uLL, stderr);
fwrite(" one-shot: send one routing advertisement and die\n", 1uLL, 0x37uLL, stderr);
fwrite(" -c\n", 1uLL, 5uLL, stderr);
fwrite(" cascade: re-advertise received routes.\n", 1uLL, 0x2DuLL, stderr);
fwrite(" Handle with care: the -c option can lead to routing loops.\n", 1uLL, 0x41uLL, stderr);
exit(1);
}
cascade = 1;
puts("BEWARE! cascade (-c) option can lead to routing loops!");
}
}
}

canonical_decompiled_code:
int __fastcall func4(int argc, char **argv)
{
int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "i:s:c");
if ( result == -1 )
return result;
if ( result == 105 )
{
strcpy(local_ifname, optarg);
}
else if ( result > 105 )
{
if ( result != 115 )
goto LABEL_12;
func3(optarg);
}
else if ( result == 49 )
{
one_shot = 1;
}
else
{
if ( result != 99 )
{
LABEL_12:
fprintf(stderr, "Usage: %s <-i iface> [-1] [-c] [-s X.X.X.X/Y]\n\n", *argv);
fwrite(" -i iface\n", 1uLL, 0xBuLL, stderr);
fwrite(" listen and send routing advertisements on interface iface\n", 1uLL, 0x40uLL, stderr);
fwrite(" -s X.X.X.X/Y\n", 1uLL, 0xFuLL, stderr);
fwrite(" advertise the subnet X.X.X.X/Y\n", 1uLL, 0x25uLL, stderr);
fwrite(" -1\n", 1uLL, 5uLL, stderr);
fwrite(" one-shot: send one routing advertisement and die\n", 1uLL, 0x37uLL, stderr);
fwrite(" -c\n", 1uLL, 5uLL, stderr);
fwrite(" cascade: re-advertise received routes.\n", 1uLL, 0x2DuLL, stderr);
fwrite(" Handle with care: the -c option can lead to routing loops.\n", 1uLL, 0x41uLL, stderr);
exit(1);
}
cascade = 1;
puts("BEWARE! cascade (-c) option can lead to routing loops!");
}
}
}

original_code:
void parse_opt(int argc, char *argv[]) {
 int opt;
 while ((opt = getopt(argc, argv, "i:s:c")) != -1) {
  switch (opt) {
  case 'i':
   strcpy(local_ifname, optarg);
   break;
  case 's':
   add_ips(optarg);
   break;
  case 'c':
   cascade = 1;
   printf("BEWARE! cascade (-c) option can lead to routing loops!\n");
   break;
  case '1':
   one_shot = 1;
   break;
  default:
   fprintf(stderr, "Usage: %s <-i iface>  [-1] [-c] [-s X.X.X.X/Y]\n\n",
     argv[0]);
   fprintf(stderr, "  -i iface\n");
   fprintf(stderr, "      listen and send routing advertisements on interface iface\n");
   fprintf(stderr, "  -s X.X.X.X/Y\n");
   fprintf(stderr, "      advertise the subnet X.X.X.X/Y\n");
   fprintf(stderr, "  -1\n");
   fprintf(stderr, "      one-shot: send one routing advertisement and die\n");
   fprintf(stderr, "  -c\n");
   fprintf(stderr, "      cascade: re-advertise received routes.\n");
   fprintf(stderr, "      Handle with care: the -c option can lead to routing loops.\n");
   exit(1);
  }
 }
}

variable_types: argc int

variable_types: opt int


repo: claudyus/picobgp

decompiled_code:
__int16 let_me_spam()
{
ssize_t v0; // rax
__int64 v1; // rbx
int v2; // er12
char *v3; // rbp
char *v4; // rax
__int64 v5; // rbx
int i; // ebp
char *v7; // rax
struct sockaddr v9[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&v9[0].sa_data[6] = 0LL;
v9[0].sa_family = 2;
*(_DWORD *)&v9[0].sa_data[2] = brd_ip;
LOWORD(v0) = _bswap_16(9876);
*(_WORD *)v9[0].sa_data = v0;
if ( ips_len > 0 )
{
v1 = 0LL;
v2 = 0;
do
{
v3 = inet_ntoa(*(struct in_addr *)(ips + v1 + 4));
v4 = inet_ntoa(*(struct in_addr *)(ips + v1));
fprintf(stderr, "advertising %s netmask %s\n", v4, v3);
v0 = sendto(sd, (const void *)(ips + v1), 0x18uLL, 0, v9, 0x10u);
if ( v0 == -1 )
{
perror("sendto(&(ips[i]))");
exit(1);
}
++v2;
v1 += 24LL;
}
while ( ips_len > v2 );
}
v5 = 0LL;
for ( i = 0; ann_len > i; v5 += 24LL )
{
if ( !cascade )
break;
v7 = inet_ntoa(*(struct in_addr *)(ann_ips + v5));
fprintf(stderr, "advertising cascade subnet %s\n", v7);
v0 = sendto(sd, (const void *)(ann_ips + v5), 0x18uLL, 0, v9, 0x10u);
if ( v0 == -1 )
{
perror("sendto(&(ips[i]))");
exit(1);
}
++i;
}
return v0;
}

canonical_decompiled_code:
__int16 func1()
{
ssize_t v0; // rax
__int64 v1; // rbx
int v2; // er12
char *v3; // rbp
char *v4; // rax
__int64 v5; // rbx
int i; // ebp
char *v7; // rax
struct sockaddr v9[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&v9[0].sa_data[6] = 0LL;
v9[0].sa_family = 2;
*(_DWORD *)&v9[0].sa_data[2] = brd_ip;
LOWORD(v0) = func0(9876);
*(_WORD *)v9[0].sa_data = v0;
if ( ips_len > 0 )
{
v1 = 0LL;
v2 = 0;
do
{
v3 = inet_ntoa(*(struct in_addr *)(ips + v1 + 4));
v4 = inet_ntoa(*(struct in_addr *)(ips + v1));
fprintf(stderr, "advertising %s netmask %s\n", v4, v3);
v0 = sendto(sd, (const void *)(ips + v1), 0x18uLL, 0, v9, 0x10u);
if ( v0 == -1 )
{
perror("sendto(&(ips[i]))");
exit(1);
}
++v2;
v1 += 24LL;
}
while ( ips_len > v2 );
}
v5 = 0LL;
for ( i = 0; ann_len > i; v5 += 24LL )
{
if ( !cascade )
break;
v7 = inet_ntoa(*(struct in_addr *)(ann_ips + v5));
fprintf(stderr, "advertising cascade subnet %s\n", v7);
v0 = sendto(sd, (const void *)(ann_ips + v5), 0x18uLL, 0, v9, 0x10u);
if ( v0 == -1 )
{
perror("sendto(&(ips[i]))");
exit(1);
}
++i;
}
return v0;
}

original_code:
void let_me_spam(void){
 int i;
 struct sockaddr_in raddr; memset(&raddr, 0, sizeof(struct sockaddr_in));;
 raddr.sin_family = 2;
 raddr.sin_addr.s_addr = brd_ip.s_addr;
 raddr.sin_port = htons(9876);
 for (i=0; i < ips_len; i++) {
  fprintf(stderr, "advertising %s netmask %s\n", inet_ntoa(ips[i].addr), inet_ntoa(ips[i].netmask));
  if (sendto(sd, &(ips[i]), sizeof(bgpmsg), 0,
    (struct sockaddr *) &raddr, sizeof(struct sockaddr_in)) == -1) {
   perror("sendto(&(ips[i]))");
   exit(1);
  }
 }
 for (i=0; i < ann_len && cascade; i++) {
  fprintf(stderr, "advertising cascade subnet %s\n", inet_ntoa(ann_ips[i].addr));
  if (sendto(sd, &(ann_ips[i]), sizeof(bgpmsg), 0,
    (struct sockaddr *) &raddr, sizeof(struct sockaddr_in)) == -1) {
   perror("sendto(&(ips[i]))");
   exit(1);
  }
 }
}

canonical_original_code:
void let_me_spam(){
 int i;
 struct sockaddr_in raddr; memset(&raddr, 0, sizeof(struct sockaddr_in));;
 raddr.sin_family = 2;
 raddr.sin_addr.s_addr = brd_ip.s_addr;
 raddr.sin_port = htons(9876);
 for (i=0; i < ips_len; i++) {
  fprintf(stderr, "advertising %s netmask %s\n", inet_ntoa(ips[i].addr), inet_ntoa(ips[i].netmask));
  if (sendto(sd, &(ips[i]), sizeof(bgpmsg), 0,
    (struct sockaddr *) &raddr, sizeof(struct sockaddr_in)) == -1) {
   perror("sendto(&(ips[i]))");
   exit(1);
  }
 }
 for (i=0; i < ann_len && cascade; i++) {
  fprintf(stderr, "advertising cascade subnet %s\n", inet_ntoa(ann_ips[i].addr));
  if (sendto(sd, &(ann_ips[i]), sizeof(bgpmsg), 0,
    (struct sockaddr *) &raddr, sizeof(struct sockaddr_in)) == -1) {
   perror("sendto(&(ips[i]))");
   exit(1);
  }
 }
}

variable_types: i int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

return_type: void

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
unsigned int __fastcall signal_handler(int a1)
{
unsigned int result; // eax

if ( a1 == 2 )
{
clean_rt(1LL);
puts("Exit due to SIGINT");
close(sd);
exit(0);
}
if ( a1 == 14 )
{
let_me_spam();
clean_rt(0LL);
result = alarm(3u);
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func2(int a1)
{
unsigned int result; // eax

if ( a1 == 2 )
{
clean_rt(1LL);
puts("Exit due to SIGINT");
close(sd);
exit(0);
}
if ( a1 == 14 )
{
func1();
clean_rt(0LL);
result = alarm(3u);
}
return result;
}

original_code:
void signal_handler (int type) {
 switch (type) {
  case 2:
   clean_rt(1);
   printf("Exit due to SIGINT\n");
   close(sd);
   exit(0);
   break;
  case 14:
   let_me_spam();
   clean_rt(0);
   alarm(3);
   break;
  case 10:
   break;
 }
}

canonical_original_code:
void signal_handler(int type) {
 switch (type) {
  case 2:
   clean_rt(1);
   printf("Exit due to SIGINT\n");
   close(sd);
   exit(0);
   break;
  case 14:
   let_me_spam();
   clean_rt(0);
   alarm(3);
   break;
  case 10:
   break;
 }
}

variable_types: type int


decompiled_code:
void __fastcall clean_rt(int a1)
{
__int64 v1; // rbp
_DWORD *v2; // rbx
time_t v3; // r14
time_t v4; // rax
__int64 v5[21]; // [rsp-8h] [rbp-A8h] BYREF

if ( ann_len > 0 )
{
v1 = 0LL;
do
{
v3 = *((_QWORD *)ann_ips + 3 * v1 + 2);
v4 = time(0LL);
if ( difftime(v4, v3) > 10.0 || a1 )
{
memset(v5, 0, 0x78uLL);
LOWORD(v5[5]) = 2;
LOWORD(v5[3]) = 2;
LOWORD(v5[1]) = 2;
v2 = (char *)ann_ips + 24 * v1;
HIDWORD(v5[1]) = *v2;
HIDWORD(v5[5]) = v2[1];
v5[11] = (__int64)&local_ifname;
if ( ioctl(sd, 0x890CuLL, v5) == -1 )
perror("ioctl(SIOCDELRT)");
annips_del((unsigned int)v1);
}
++v1;
}
while ( ann_len > (int)v1 );
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
__int64 v1; // rbp
_DWORD *v2; // rbx
time_t v3; // r14
time_t v4; // rax
__int64 v5[21]; // [rsp-8h] [rbp-A8h] BYREF

if ( ann_len > 0 )
{
v1 = 0LL;
do
{
v3 = *((_QWORD *)ann_ips + 3 * v1 + 2);
v4 = time(0LL);
if ( difftime(v4, v3) > 10.0 || a1 )
{
memset(v5, 0, 0x78uLL);
LOWORD(v5[5]) = 2;
LOWORD(v5[3]) = 2;
LOWORD(v5[1]) = 2;
v2 = (char *)ann_ips + 24 * v1;
HIDWORD(v5[1]) = *v2;
HIDWORD(v5[5]) = v2[1];
v5[11] = (__int64)&local_ifname;
if ( ioctl(sd, 0x890CuLL, v5) == -1 )
perror("ioctl(SIOCDELRT)");
annips_del((unsigned int)v1);
}
++v1;
}
while ( ann_len > (int)v1 );
}
}

original_code:
void clean_rt(int force) {
 int i;
 for (i = 0; i < ann_len; i++) {
  if (difftime(time(((void *)0)), ann_ips[i].l_update) > 10 || force) {
   struct rtentry rtentry; memset(&rtentry, 0, sizeof(struct rtentry));
   ((struct sockaddr_in *)&rtentry.rt_dst)->sin_family = ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_family = ((struct sockaddr_in *)&rtentry.rt_genmask)->sin_family = 2;
   ((struct sockaddr_in *)&rtentry.rt_dst)->sin_addr.s_addr = ann_ips[i].addr.s_addr;
   ((struct sockaddr_in *)&rtentry.rt_genmask)->sin_addr.s_addr = ann_ips[i].netmask.s_addr;
   ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_addr.s_addr = 0;
   rtentry.rt_dev = local_ifname;
   if(ioctl (sd, 0x890C, &rtentry) == -1) {
    perror("ioctl(SIOCDELRT)");
   }
   annips_del(i);
  }
 }
}

variable_types: force int

variable_types: struct rtentry { unsigned long rt_pad1; struct sockaddr { unsigned short sa_family; char sa_data[14]; } rt_dst; struct sockaddr rt_gateway; struct sockaddr rt_genmask; unsigned short rt_flags; short rt_pad2; unsigned long rt_pad3; unsigned char rt_tos; unsigned char rt_class; short rt_pad4[3]; short rt_metric; char *rt_dev; unsigned long rt_mtu; unsigned long rt_window; unsigned short rt_irtt; }

user_defined_types: struct rtentry { unsigned long rt_pad1; struct sockaddr rt_dst; struct sockaddr rt_gateway; struct sockaddr rt_genmask; unsigned short rt_flags; short rt_pad2; unsigned long rt_pad3; unsigned char rt_tos; unsigned char rt_class; short rt_pad4[3]; short rt_metric; char *rt_dev; unsigned long rt_mtu; unsigned long rt_window; unsigned short rt_irtt; }


decompiled_code:
__int64 __fastcall update_rt(int a1, int a2, int a3, int a4, int a5, int a6, __int64 s2, __int64 a8)
{
__int64 result; // rax
unsigned __int64 v9; // rdi
__int64 v10; // rdx
__int64 v11[17]; // [rsp+0h] [rbp-88h] BYREF

if ( ann_len <= 0 )
{
memset(v11, 0, 0x78uLL);
LOWORD(v11[5]) = 2;
LOWORD(v11[3]) = 2;
LOWORD(v11[1]) = 2;
HIDWORD(v11[5]) = HIDWORD(s2);
HIDWORD(v11[1]) = s2;
if ( HIDWORD(s2) == -1 )
{
LOWORD(v11[7]) = 1;
}
else
{
HIDWORD(v11[3]) = a8;
LOWORD(v11[7]) = 3;
}
v11[11] = (__int64)&local_ifname;
v9 = (unsigned int)sd;
if ( ioctl(sd, 0x890BuLL, v11) == -1 )
{
v9 = (unsigned __int64)"ioctl(SIOCADDRT) are you root?";
perror("ioctl(SIOCADDRT) are you root?");
}
result = annips_add(v9, 35083LL, v10);
}
else
{
if ( !memcmp(ann_ips, &s2, 0xCuLL) )
puts("update_rt: announce already in ann_ips");
time((time_t *)ann_ips + 2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3, int a4, int a5, int a6, __int64 s2, __int64 a8)
{
__int64 result; // rax
unsigned __int64 v9; // rdi
__int64 v10; // rdx
__int64 v11[17]; // [rsp+0h] [rbp-88h] BYREF

if ( ann_len <= 0 )
{
memset(v11, 0, 0x78uLL);
LOWORD(v11[5]) = 2;
LOWORD(v11[3]) = 2;
LOWORD(v11[1]) = 2;
HIDWORD(v11[5]) = HIDWORD(s2);
HIDWORD(v11[1]) = s2;
if ( HIDWORD(s2) == -1 )
{
LOWORD(v11[7]) = 1;
}
else
{
HIDWORD(v11[3]) = a8;
LOWORD(v11[7]) = 3;
}
v11[11] = (__int64)&local_ifname;
v9 = (unsigned int)sd;
if ( ioctl(sd, 0x890BuLL, v11) == -1 )
{
v9 = (unsigned __int64)"ioctl(SIOCADDRT) are you root?";
perror("ioctl(SIOCADDRT) are you root?");
}
result = annips_add(v9, 35083LL, v10);
}
else
{
if ( !memcmp(ann_ips, &s2, 0xCuLL) )
puts("update_rt: announce already in ann_ips");
time((time_t *)ann_ips + 2);
result = 0LL;
}
return result;
}

original_code:
int update_rt (bgpmsg flood_msg, int len) {
 int i;
 for (i = 0; i < ann_len; i++) {
  if (memcmp(&ann_ips[i].addr, &(flood_msg.addr), sizeof(struct in_addr)*3) == 0)
   printf ("update_rt: announce already in ann_ips\n");
   time(&ann_ips[i].l_update);
   return 0;
 }
 struct rtentry rtentry; memset(&rtentry, 0, sizeof(struct rtentry));;
 ((struct sockaddr_in *)&rtentry.rt_dst)->sin_family = ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_family = ((struct sockaddr_in *)&rtentry.rt_genmask)->sin_family = 2;
 ((struct sockaddr_in *)&rtentry.rt_dst)->sin_addr.s_addr = flood_msg.addr.s_addr;
 ((struct sockaddr_in *)&rtentry.rt_genmask)->sin_addr.s_addr = flood_msg.netmask.s_addr;
 if (flood_msg.netmask.s_addr != 0xffffffff) {
  ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_addr.s_addr =flood_msg.loc_addr.s_addr;
  rtentry.rt_flags = 0x0001 | 0x0002;
 } else {
  ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_addr.s_addr = 0;
  rtentry.rt_flags = 0x0001;
 }
 rtentry.rt_dev = local_ifname;
 if(ioctl (sd, 0x890B, &rtentry) == -1) {
  perror("ioctl(SIOCADDRT) are you root?");
 }
 annips_add(flood_msg);
}

canonical_original_code:
int update_rt(struct sbgpmsg flood_msg, int len) {
 int i;
 for (i = 0; i < ann_len; i++) {
  if (memcmp(&ann_ips[i].addr, &(flood_msg.addr), sizeof(struct in_addr)*3) == 0)
   printf ("update_rt: announce already in ann_ips\n");
   time(&ann_ips[i].l_update);
   return 0;
 }
 struct rtentry rtentry; memset(&rtentry, 0, sizeof(struct rtentry));;
 ((struct sockaddr_in *)&rtentry.rt_dst)->sin_family = ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_family = ((struct sockaddr_in *)&rtentry.rt_genmask)->sin_family = 2;
 ((struct sockaddr_in *)&rtentry.rt_dst)->sin_addr.s_addr = flood_msg.addr.s_addr;
 ((struct sockaddr_in *)&rtentry.rt_genmask)->sin_addr.s_addr = flood_msg.netmask.s_addr;
 if (flood_msg.netmask.s_addr != 0xffffffff) {
  ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_addr.s_addr =flood_msg.loc_addr.s_addr;
  rtentry.rt_flags = 0x0001 | 0x0002;
 } else {
  ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_addr.s_addr = 0;
  rtentry.rt_flags = 0x0001;
 }
 rtentry.rt_dev = local_ifname;
 if(ioctl (sd, 0x890B, &rtentry) == -1) {
  perror("ioctl(SIOCADDRT) are you root?");
 }
 annips_add(flood_msg);
}

variable_types: struct sbgpmsg { struct in_addr { unsigned int s_addr; } addr; struct in_addr netmask; struct in_addr loc_addr; long l_update; }

variable_types: len int

return_type: int

user_defined_types: struct sbgpmsg { struct in_addr addr; struct in_addr netmask; struct in_addr loc_addr; long l_update; }


wall

repo: clibs/bench

decompiled_code:
float wall()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(4, &v1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
float func7()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(4, &v1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

original_code:
float
wall(void) {
  struct timespec tp;
  clock_gettime(4, &tp);
  return tp.tv_sec + 1e-9 * tp.tv_nsec;
}

canonical_original_code:
float wall() {
  struct timespec tp;
  clock_gettime(4, &tp);
  return tp.tv_sec + 1e-9 * tp.tv_nsec;
}

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

return_type: float


cpu

decompiled_code:
float cpu()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(2, &v1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
float func8()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(2, &v1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

original_code:
float
cpu(void) {
  struct timespec tp;
  clock_gettime(2, &tp);
  return tp.tv_sec + 1e-9 * tp.tv_nsec;
}

canonical_original_code:
float cpu() {
  struct timespec tp;
  clock_gettime(2, &tp);
  return tp.tv_sec + 1e-9 * tp.tv_nsec;
}

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
float v4; // [rsp+0h] [rbp-18h]
float v5; // [rsp+4h] [rbp-14h]
float v6; // [rsp+8h] [rbp-10h]
float v7; // [rsp+Ch] [rbp-Ch]

puts("start");
v4 = wall();
v5 = cpu();
sleep(5u);
v6 = wall();
v7 = cpu();
printf(" creation time (wall): %2.2f\n", (float)(v6 - v4));
printf(" creation time (cpu): %2.2f\n", (float)(v7 - v5));
puts("end");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
float v4; // [rsp+0h] [rbp-18h]
float v5; // [rsp+4h] [rbp-14h]
float v6; // [rsp+8h] [rbp-10h]
float v7; // [rsp+Ch] [rbp-Ch]

puts("start");
v4 = func7();
v5 = func8();
sleep(5u);
v6 = func7();
v7 = func8();
printf(" creation time (wall): %2.2f\n", (float)(v6 - v4));
printf(" creation time (cpu): %2.2f\n", (float)(v7 - v5));
puts("end");
return 0;
}

original_code:
int
main(void) {
  printf("start\n");
  float t1_wall = wall();
  float t1_cpu = cpu();
  sleep(5);
  float t2_wall = wall();
  float t2_cpu = cpu();
  printf("     creation time (wall):   %2.2f\n", t2_wall - t1_wall);
  printf("     creation time (cpu):    %2.2f\n", t2_cpu - t1_cpu);
  printf("end\n");
  return 0;
}

canonical_original_code:
int main() {
  printf("start\n");
  float t1_wall = wall();
  float t1_cpu = cpu();
  sleep(5);
  float t2_wall = wall();
  float t2_cpu = cpu();
  printf("     creation time (wall):   %2.2f\n", t2_wall - t1_wall);
  printf("     creation time (cpu):    %2.2f\n", t2_cpu - t1_cpu);
  printf("end\n");
  return 0;
}


equal

repo: clibs/bytes

decompiled_code:
void __fastcall equal(const char *a1, char *a2)
{
if ( strcmp(a1, a2) )
{
fprintf(stderr, "expected: %s\n", a1);
fprintf(stderr, "actual: %s\n", a2);
free(a2);
exit(1);
}
free(a2);
}

canonical_decompiled_code:
void __fastcall func7(const char *a1, char *a2)
{
if ( strcmp(a1, a2) )
{
fprintf(stderr, "expected: %s\n", a1);
fprintf(stderr, "actual: %s\n", a2);
free(a2);
exit(1);
}
free(a2);
}

original_code:
void
equal(char *a, char *b) {
  if (strcmp(a, b)) {
    fprintf(stderr, "expected: %s\n", a);
    fprintf(stderr, "actual: %s\n", b);
    free(b);
    exit(1);
  }
  free(b);
}

variable_types:
a
char *

variable_types:
b
char *


decompiled_code:
__int64 test_string_to_bytes()
{
__int64 result; // rax

if ( string_to_bytes("100") != 100 )
__assert_fail("100 == string_to_bytes(\"100\")", "test.c", 0x15u, "test_string_to_bytes");
if ( string_to_bytes("100b") != 100 )
__assert_fail("100 == string_to_bytes(\"100b\")", "test.c", 0x16u, "test_string_to_bytes");
if ( string_to_bytes("100 bytes") != 100 )
__assert_fail("100 == string_to_bytes(\"100 bytes\")", "test.c", 0x17u, "test_string_to_bytes");
if ( string_to_bytes("1kb") != 1024 )
__assert_fail("1024 == string_to_bytes(\"1kb\")", "test.c", 0x18u, "test_string_to_bytes");
if ( string_to_bytes("1mb") != 0x100000 )
__assert_fail("1024 * 1024 == string_to_bytes(\"1mb\")", "test.c", 0x19u, "test_string_to_bytes");
if ( string_to_bytes("1gb") != 0x40000000 )
__assert_fail("1024 * 1024 * 1024 == string_to_bytes(\"1gb\")", "test.c", 0x1Au, "test_string_to_bytes");
if ( string_to_bytes("2kb") != 2048 )
__assert_fail("2 * 1024 == string_to_bytes(\"2kb\")", "test.c", 0x1Bu, "test_string_to_bytes");
result = string_to_bytes("5mb");
if ( result != 5242880 )
__assert_fail("5 * 1024 * 1024 == string_to_bytes(\"5mb\")", "test.c", 0x1Cu, "test_string_to_bytes");
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax

if ( func10("100") != 100 )
__assert_fail("100 == string_to_bytes(\"100\")", "test.c", 0x15u, "test_string_to_bytes");
if ( func10("100b") != 100 )
__assert_fail("100 == string_to_bytes(\"100b\")", "test.c", 0x16u, "test_string_to_bytes");
if ( func10("100 bytes") != 100 )
__assert_fail("100 == string_to_bytes(\"100 bytes\")", "test.c", 0x17u, "test_string_to_bytes");
if ( func10("1kb") != 1024 )
__assert_fail("1024 == string_to_bytes(\"1kb\")", "test.c", 0x18u, "test_string_to_bytes");
if ( func10("1mb") != 0x100000 )
__assert_fail("1024 * 1024 == string_to_bytes(\"1mb\")", "test.c", 0x19u, "test_string_to_bytes");
if ( func10("1gb") != 0x40000000 )
__assert_fail("1024 * 1024 * 1024 == string_to_bytes(\"1gb\")", "test.c", 0x1Au, "test_string_to_bytes");
if ( func10("2kb") != 2048 )
__assert_fail("2 * 1024 == string_to_bytes(\"2kb\")", "test.c", 0x1Bu, "test_string_to_bytes");
result = func10("5mb");
if ( result != 5242880 )
__assert_fail("5 * 1024 * 1024 == string_to_bytes(\"5mb\")", "test.c", 0x1Cu, "test_string_to_bytes");
return result;
}

original_code:
void
test_string_to_bytes(void) {
  ((100 == string_to_bytes("100")) ? (void) (0) : __assert_fail ("100 == string_to_bytes(\"100\")", "test.c", 21, __extension__ __PRETTY_FUNCTION__));
  ((100 == string_to_bytes("100b")) ? (void) (0) : __assert_fail ("100 == string_to_bytes(\"100b\")", "test.c", 22, __extension__ __PRETTY_FUNCTION__));
  ((100 == string_to_bytes("100 bytes")) ? (void) (0) : __assert_fail ("100 == string_to_bytes(\"100 bytes\")", "test.c", 23, __extension__ __PRETTY_FUNCTION__));
  ((1024 == string_to_bytes("1kb")) ? (void) (0) : __assert_fail ("1024 == string_to_bytes(\"1kb\")", "test.c", 24, __extension__ __PRETTY_FUNCTION__));
  ((1024 * 1024 == string_to_bytes("1mb")) ? (void) (0) : __assert_fail ("1024 * 1024 == string_to_bytes(\"1mb\")", "test.c", 25, __extension__ __PRETTY_FUNCTION__));
  ((1024 * 1024 * 1024 == string_to_bytes("1gb")) ? (void) (0) : __assert_fail ("1024 * 1024 * 1024 == string_to_bytes(\"1gb\")", "test.c", 26, __extension__ __PRETTY_FUNCTION__));
  ((2 * 1024 == string_to_bytes("2kb")) ? (void) (0) : __assert_fail ("2 * 1024 == string_to_bytes(\"2kb\")", "test.c", 27, __extension__ __PRETTY_FUNCTION__));
  ((5 * 1024 * 1024 == string_to_bytes("5mb")) ? (void) (0) : __assert_fail ("5 * 1024 * 1024 == string_to_bytes(\"5mb\")", "test.c", 28, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void test_string_to_bytes() {
  ((100 == string_to_bytes("100")) ? (void) (0) : __assert_fail ("100 == string_to_bytes(\"100\")", "test.c", 21, __extension__ __PRETTY_FUNCTION__));
  ((100 == string_to_bytes("100b")) ? (void) (0) : __assert_fail ("100 == string_to_bytes(\"100b\")", "test.c", 22, __extension__ __PRETTY_FUNCTION__));
  ((100 == string_to_bytes("100 bytes")) ? (void) (0) : __assert_fail ("100 == string_to_bytes(\"100 bytes\")", "test.c", 23, __extension__ __PRETTY_FUNCTION__));
  ((1024 == string_to_bytes("1kb")) ? (void) (0) : __assert_fail ("1024 == string_to_bytes(\"1kb\")", "test.c", 24, __extension__ __PRETTY_FUNCTION__));
  ((1024 * 1024 == string_to_bytes("1mb")) ? (void) (0) : __assert_fail ("1024 * 1024 == string_to_bytes(\"1mb\")", "test.c", 25, __extension__ __PRETTY_FUNCTION__));
  ((1024 * 1024 * 1024 == string_to_bytes("1gb")) ? (void) (0) : __assert_fail ("1024 * 1024 * 1024 == string_to_bytes(\"1gb\")", "test.c", 26, __extension__ __PRETTY_FUNCTION__));
  ((2 * 1024 == string_to_bytes("2kb")) ? (void) (0) : __assert_fail ("2 * 1024 == string_to_bytes(\"2kb\")", "test.c", 27, __extension__ __PRETTY_FUNCTION__));
  ((5 * 1024 * 1024 == string_to_bytes("5mb")) ? (void) (0) : __assert_fail ("5 * 1024 * 1024 == string_to_bytes(\"5mb\")", "test.c", 28, __extension__ __PRETTY_FUNCTION__));
}


decompiled_code:
void test_bytes_to_string()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rsi
char *v5; // rax

v0 = (char *)bytes_to_string(100LL);
equal("100b", v0);
v1 = (char *)bytes_to_string(1024LL);
equal("1kb", v1);
v2 = (char *)bytes_to_string(0x100000LL);
equal("1mb", v2);
v3 = (char *)bytes_to_string(5242880LL);
equal("5mb", v3);
v4 = (char *)bytes_to_string(0x40000000LL);
equal("1gb", v4);
v5 = (char *)bytes_to_string(0x140000000LL);
equal("5gb", v5);
}

original_code:
void
test_bytes_to_string(void) {
  equal("100b", bytes_to_string(100));
  equal("1kb", bytes_to_string(1024));
  equal("1mb", bytes_to_string(1024 * 1024));
  equal("5mb", bytes_to_string(1024 * 1024 * 5));
  equal("1gb", bytes_to_string(1024 * 1024 * 1024));
  equal("5gb", bytes_to_string((long long) 1024 * 1024 * 1024 * 5));
}

canonical_original_code:
void test_bytes_to_string() {
  equal("100b", bytes_to_string(100));
  equal("1kb", bytes_to_string(1024));
  equal("1mb", bytes_to_string(1024 * 1024));
  equal("5mb", bytes_to_string(1024 * 1024 * 5));
  equal("1gb", bytes_to_string(1024 * 1024 * 1024));
  equal("5gb", bytes_to_string((long long) 1024 * 1024 * 1024 * 5));
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_string_to_bytes(argc, argv, envp);
test_bytes_to_string();
puts(s);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8(argc, argv, envp);
func9();
puts(s);
return 0;
}

original_code:
int
main(void) {
  test_string_to_bytes();
  test_bytes_to_string();
  printf("\n  \e[32m\u2713 \e[90mok\e[0m\n\n");
  return 0;
}

canonical_original_code:
int main() {
  test_string_to_bytes();
  test_bytes_to_string();
  printf("\n  \e[32m\u2713 \e[90mok\e[0m\n\n");
  return 0;
}


decompiled_code:
__int64 __fastcall string_to_bytes(char *haystack)
{
__int64 v1; // rax
__int64 v2; // rbx

v1 = strtoll(haystack, 0LL, 10);
if ( !v1 )
return -1LL;
v2 = v1;
if ( strstr(haystack, "kb") )
{
v2 <<= 10;
}
else if ( strstr(haystack, "mb") )
{
v2 <<= 20;
}
else if ( strstr(haystack, "gb") )
{
v2 <<= 30;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *haystack)
{
__int64 v1; // rax
__int64 v2; // rbx

v1 = strtoll(haystack, 0LL, 10);
if ( !v1 )
return -1LL;
v2 = v1;
if ( strstr(haystack, "kb") )
{
v2 <<= 10;
}
else if ( strstr(haystack, "mb") )
{
v2 <<= 20;
}
else if ( strstr(haystack, "gb") )
{
v2 <<= 30;
}
return v2;
}

original_code:
long long
string_to_bytes(const char *str) {
  long long val = strtoll(str, ((void *)0), 10);
  if (!val) return -1;
  if (strstr(str, "kb")) return val * 1024;
  if (strstr(str, "mb")) return val * 1024 * 1024;
  if (strstr(str, "gb")) return val * 1024 * 1024 * 1024;
  return val;
}

canonical_original_code:
long long string_to_bytes(char *str) {
  long long val = strtoll(str, ((void *)0), 10);
  if (!val) return -1;
  if (strstr(str, "kb")) return val * 1024;
  if (strstr(str, "mb")) return val * 1024 * 1024;
  if (strstr(str, "gb")) return val * 1024 * 1024 * 1024;
  return val;
}

variable_types:
str
char *

variable_types:
val
long long

return_type: long long


decompiled_code:
char *__fastcall bytes_to_string(__int64 a1)
{
const char *v1; // rsi
__int64 v2; // rcx
char *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

if ( a1 <= 1023 )
{
v1 = "%lldb";
v2 = 1LL;
}
else
{
if ( a1 <= 0xFFFFF )
{
asprintf(ptr, "%lldkb", a1 / 1024);
return ptr[0];
}
v1 = "%lldmb";
if ( a1 >= 0x40000000 )
v1 = "%lldgb";
v2 = 0x100000LL;
if ( a1 >= 0x40000000 )
v2 = 0x40000000LL;
}
asprintf(ptr, v1, a1 / v2);
return ptr[0];
}

original_code:
char *
bytes_to_string(long long bytes) {
  long div = 1;
  char *str, *fmt;
  if (bytes < 1024) { fmt = "%lldb"; }
  else if (bytes < 1024 * 1024) { fmt = "%lldkb"; div = 1024; }
  else if (bytes < 1024 * 1024 * 1024) { fmt = "%lldmb"; div = 1024 * 1024; }
  else { fmt = "%lldgb"; div = 1024 * 1024 * 1024; }
  asprintf(&str, fmt, bytes / div);
  return str;
}

canonical_original_code:
char *bytes_to_string(long long bytes) {
  long div = 1;
  char *str; char *fmt;
  if (bytes < 1024) { fmt = "%lldb"; }
  else if (bytes < 1024 * 1024) { fmt = "%lldkb"; div = 1024; }
  else if (bytes < 1024 * 1024 * 1024) { fmt = "%lldmb"; div = 1024 * 1024; }
  else { fmt = "%lldgb"; div = 1024 * 1024 * 1024; }
  asprintf(&str, fmt, bytes / div);
  return str;
}

variable_types:
bytes
long long

variable_types: div long

variable_types:
fmt
char *

return_type: char *


repo: clibs/timestamp

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v4; // rdx
int v5; // eax

v3 = timestamp(argc, argv, envp);
sleep(5u);
v5 = timestamp(5LL, argv, v4) - v3;
if ( v5 <= 4999 )
__assert_fail("diff >= 5000", "test.c", 0xDu, "main");
if ( v5 > 5009 )
__assert_fail("diff < 5010", "test.c", 0xEu, "main");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v4; // rdx
int v5; // eax

v3 = func7(argc, argv, envp);
sleep(5u);
v5 = func7(5LL, argv, v4) - v3;
if ( v5 <= 4999 )
__assert_fail("diff >= 5000", "test.c", 0xDu, "main");
if ( v5 > 5009 )
__assert_fail("diff < 5010", "test.c", 0xEu, "main");
return 0;
}

original_code:
int
main(void) {
  int64_t start = timestamp();
  sleep(5);
  int64_t end = timestamp();
  int diff = end - start;
  ((diff >= 5000) ? (void) (0) : __assert_fail ("diff >= 5000", "test.c", 13, __extension__ __PRETTY_FUNCTION__));
  ((diff < 5010) ? (void) (0) : __assert_fail ("diff < 5010", "test.c", 14, __extension__ __PRETTY_FUNCTION__));
  return 0;
}

canonical_original_code:
int main() {
  long start = timestamp();
  sleep(5);
  long end = timestamp();
  int diff = end - start;
  ((diff >= 5000) ? (void) (0) : __assert_fail ("diff >= 5000", "test.c", 13, __extension__ __PRETTY_FUNCTION__));
  ((diff < 5010) ? (void) (0) : __assert_fail ("diff < 5010", "test.c", 14, __extension__ __PRETTY_FUNCTION__));
  return 0;
}

variable_types: start long

variable_types: end long

variable_types: diff int


timestamp

decompiled_code:
__time_t timestamp()
{
__time_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) == -1 )
result = -1LL;
else
result = 1000 * v1.tv_sec + v1.tv_usec / 1000;
return result;
}

canonical_decompiled_code:
__time_t func7()
{
__time_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) == -1 )
result = -1LL;
else
result = 1000 * v1.tv_sec + v1.tv_usec / 1000;
return result;
}

original_code:
int64_t
timestamp(void) {
  struct timeval tv;
  int ret = gettimeofday(&tv, ((void *)0));
  if (-1 == ret) return -1;
  return (int64_t) ((int64_t) tv.tv_sec * 1000 + (int64_t) tv.tv_usec / 1000);
}

canonical_original_code:
long timestamp() {
  struct timeval tv;
  int ret = gettimeofday(&tv, ((void *)0));
  if (-1 == ret) return -1;
  return (long) ((long) tv.tv_sec * 1000 + (long) tv.tv_usec / 1000);
}

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

variable_types: ret int

return_type: long


connectDevice

repo: clickok/iRobotInterface

decompiled_code:
__int64 __fastcall connectDevice(const char *a1)
{
int v1; // eax
unsigned int v2; // ebx
struct termios v4; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

if ( !a1 )
return (unsigned int)-1;
v1 = open(a1, 2306);
v2 = v1;
if ( v1 == -1 )
{
perror("Failed to connect to device");
}
else
{
tcgetattr(v1, &termios_p);
tcgetattr(v2, &v4);
termios_p.c_iflag = 5;
termios_p.c_lflag = 0;
termios_p.c_oflag = 0;
termios_p.c_cflag = 2224;
cfsetispeed(&termios_p, 0x1001u);
cfsetospeed(&termios_p, 0x1001u);
tcsetattr(v2, 0, &termios_p);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
int v1; // eax
unsigned int v2; // ebx
struct termios v4; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

if ( !a1 )
return (unsigned int)-1;
v1 = open(a1, 2306);
v2 = v1;
if ( v1 == -1 )
{
perror("Failed to connect to device");
}
else
{
tcgetattr(v1, &termios_p);
tcgetattr(v2, &v4);
termios_p.c_iflag = 5;
termios_p.c_lflag = 0;
termios_p.c_oflag = 0;
termios_p.c_cflag = 2224;
cfsetispeed(&termios_p, 0x1001u);
cfsetospeed(&termios_p, 0x1001u);
tcsetattr(v2, 0, &termios_p);
}
return v2;
}

original_code:
int connectDevice(char * device)
{
 int fd;
 struct termios tty, tty_check;
    if(device == ((void *)0)) return -1;
    if((fd = open(device, 02 | 0400 | 04000)) == -1)
    {
     perror("Failed to connect to device");
        return -1;
    }
    tcgetattr(fd, &tty);
    tcgetattr(fd, &tty_check);
    tty.c_iflag = 0000001 | 0000004;
    tty.c_lflag = 0;
    tty.c_oflag = 0;
    tty.c_cflag = 0000200 | 0000060 | 0004000;
    cfsetispeed(&tty, 0010001);
    cfsetospeed(&tty, 0010001);
    tcsetattr(fd, 0, &tty);
    return fd;
}

canonical_original_code:
int connectDevice(char *device)
{
 int fd;
 struct termios tty; struct termios tty_check;
    if(device == ((void *)0)) return -1;
    if((fd = open(device, 02 | 0400 | 04000)) == -1)
    {
     perror("Failed to connect to device");
        return -1;
    }
    tcgetattr(fd, &tty);
    tcgetattr(fd, &tty_check);
    tty.c_iflag = 0000001 | 0000004;
    tty.c_lflag = 0;
    tty.c_oflag = 0;
    tty.c_cflag = 0000200 | 0000060 | 0004000;
    cfsetispeed(&tty, 0010001);
    cfsetospeed(&tty, 0010001);
    tcsetattr(fd, 0, &tty);
    return fd;
}

variable_types:
device
char *

variable_types: fd int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


disconnectDevice

decompiled_code:
__int64 __fastcall disconnectDevice(int a1)
{
unsigned int v1; // ebx

if ( a1 < 0 )
return (unsigned int)-1;
v1 = close(a1);
if ( v1 != -1 )
return 0;
perror("Failed to close connection to device");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
unsigned int v1; // ebx

if ( a1 < 0 )
return (unsigned int)-1;
v1 = close(a1);
if ( v1 != -1 )
return 0;
perror("Failed to close connection to device");
return v1;
}

original_code:
int disconnectDevice(int fd)
{
    if(fd < 0) {
        return -1;
    }
    if(close(fd) == -1) {
     perror("Failed to close connection to device");
        return -1;
    }
    fd = -1;
    return 0;
}


askForSensors

decompiled_code:
__int64 __fastcall askForSensors(int fd)
{
char *v1; // rbx
unsigned int v2; // ebp
int v3; // ebx
ssize_t v4; // rax
char buf[5]; // [rsp+7h] [rbp-31h] BYREF
char v7; // [rsp+Ch] [rbp-2Ch] BYREF
char v8[41]; // [rsp+Fh] [rbp-29h] BYREF

buf[0] = -125;
buf[1] = -117;
buf[2] = 10;
buf[3] = 0;
buf[4] = 0;
v1 = buf;
do
{
v2 = write(fd, v1, 1uLL);
usleep(0x2710u);
printf("res = %d\n", v2);
++v1;
}
while ( v1 != &v7 );
v3 = 9;
do
{
v4 = read(fd, v8, 1uLL);
printf("res = %d val = %d\n", v4, (unsigned __int8)v8[0]);
--v3;
}
while ( v3 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd)
{
char *v1; // rbx
unsigned int v2; // ebp
int v3; // ebx
ssize_t v4; // rax
char buf[5]; // [rsp+7h] [rbp-31h] BYREF
char v7; // [rsp+Ch] [rbp-2Ch] BYREF
char v8[41]; // [rsp+Fh] [rbp-29h] BYREF

buf[0] = -125;
buf[1] = -117;
buf[2] = 10;
buf[3] = 0;
buf[4] = 0;
v1 = buf;
do
{
v2 = write(fd, v1, 1uLL);
usleep(0x2710u);
printf("res = %d\n", v2);
++v1;
}
while ( v1 != &v7 );
v3 = 9;
do
{
v4 = read(fd, v8, 1uLL);
printf("res = %d val = %d\n", v4, (unsigned __int8)v8[0]);
--v3;
}
while ( v3 );
return 0LL;
}

original_code:
int askForSensors(int fd, int * array)
{
 int i;
 int res,e;
 unsigned char buf;
 unsigned char cmd[8];
 int count = 0;
 cmd[count++] = 131;
 cmd[count++] = 139;
 cmd[count++] = 10;
 cmd[count++] = 0;
 cmd[count++] = 0;
 for (i = 0; i < count; ++i)
 {
  res = write(fd, cmd + i, 1);
  usleep(10000);
  printf("res = %d\n",res);
 }
 for (i = 0; i < 9; i++)
 {
  res = read(fd,&buf,1);
  printf("res = %d val = %d\n",res,(int) buf);
 }
 return 0;
}

canonical_original_code:
int askForSensors(int fd, int *array)
{
 int i;
 int res; int e;
 unsigned char buf;
 unsigned char cmd[8];
 int count = 0;
 cmd[count++] = 131;
 cmd[count++] = 139;
 cmd[count++] = 10;
 cmd[count++] = 0;
 cmd[count++] = 0;
 for (i = 0; i < count; ++i)
 {
  res = write(fd, cmd + i, 1);
  usleep(10000);
  printf("res = %d\n",res);
 }
 for (i = 0; i < 9; i++)
 {
  res = read(fd,&buf,1);
  printf("res = %d val = %d\n",res,(int) buf);
 }
 return 0;
}

variable_types:
array
int *

variable_types: i int

variable_types: res int

variable_types: e int

variable_types:
buf
unsigned char

variable_types:
cmd
unsigned char [8]

variable_types: count int


sendByte

decompiled_code:
__int64 __fastcall sendByte(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return (unsigned int)-(write(a1, buf, 1uLL) != 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return (unsigned int)-(write(a1, buf, 1uLL) != 1);
}

original_code:
int sendByte(int fd, unsigned char byte) {
 int res;
 res = (write(fd, &byte, 1) == 1 ? 0 : -1);
    return res;
}

variable_types:
byte
unsigned char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char v5[48]; // [rsp+0h] [rbp-68h] BYREF

puts("******************** iRobot Sensor Calibration **********************");
puts(
"* How this works: *\n"
"* 1) The program will attempt to connect to the device specified by *\n"
"* the command line argument... which you should've entered... *\n"
"* 2) Place Robot in the 'inner' region. The program will read the *\n"
"* infrared sensor values. When prompted, move the robot (while *\n"
"* keeping it in the same region) so it can collect an average. *\n"
"* 3) When prompted, move the robot to the 'outer' region, and *\n"
"* follow the same process as in Step (1). *\n"
"* 4) The program will then compute an average for the two regions *\n"
"* (allowing for some margin to account for variability) and save *\n"
"* the result as 'calibration.dat', or tell you if it's not *\n"
"* possible to distinguish the two regions. *\n"
"*********************************************************************");
puts("\nSTEP 1)");
v3 = connectDevice(argv[1]);
fd = v3;
if ( v3 >= 0 )
printf("Connected to device with file descriptor: %d\n", (unsigned int)v3);
puts("STEP 2)");
puts("Place Robot in region one.");
printf("Collecting sample %d of %d\n", 1LL, 1LL);
puts("When ready to sample, press <return>");
fgets(v5, 40, _bss_start);
askForSensors(fd);
puts("STEP 3)");
puts("Place Robot in region two.");
printf("Collecting sample %d of %d\n", 1LL, 1LL);
puts("When ready to sample, press <return>");
fgets(v5, 40, _bss_start);
puts("STEP 4)");
disconnectDevice(fd);
printf("Disconnected from device. File descriptor is now: %d\n", (unsigned int)fd);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char v5[48]; // [rsp+0h] [rbp-68h] BYREF

puts("******************** iRobot Sensor Calibration **********************");
puts(
"* How this works: *\n"
"* 1) The program will attempt to connect to the device specified by *\n"
"* the command line argument... which you should've entered... *\n"
"* 2) Place Robot in the 'inner' region. The program will read the *\n"
"* infrared sensor values. When prompted, move the robot (while *\n"
"* keeping it in the same region) so it can collect an average. *\n"
"* 3) When prompted, move the robot to the 'outer' region, and *\n"
"* follow the same process as in Step (1). *\n"
"* 4) The program will then compute an average for the two regions *\n"
"* (allowing for some margin to account for variability) and save *\n"
"* the result as 'calibration.dat', or tell you if it's not *\n"
"* possible to distinguish the two regions. *\n"
"*********************************************************************");
puts("\nSTEP 1)");
v3 = func7(argv[1]);
fd = v3;
if ( v3 >= 0 )
printf("Connected to device with file descriptor: %d\n", (unsigned int)v3);
puts("STEP 2)");
puts("Place Robot in region one.");
printf("Collecting sample %d of %d\n", 1LL, 1LL);
puts("When ready to sample, press <return>");
fgets(v5, 40, _bss_start);
func9(fd);
puts("STEP 3)");
puts("Place Robot in region two.");
printf("Collecting sample %d of %d\n", 1LL, 1LL);
puts("When ready to sample, press <return>");
fgets(v5, 40, _bss_start);
puts("STEP 4)");
func8(fd);
printf("Disconnected from device. File descriptor is now: %d\n", (unsigned int)fd);
return 0;
}

original_code:
int main(int argc, char * argv[])
{
 int i,ret;
 int sensors[10];
 char line[40];
 char cmd[8];
 char * p;
 printf("******************** iRobot Sensor Calibration **********************\n");
 printf( "* How this works:                                                   *\n"
   "* 1) The program will attempt to connect to the device specified by *\n"
   "*    the command line argument... which you should've entered...    *\n"
   "* 2) Place Robot in the 'inner' region. The program will read the   *\n"
   "*    infrared sensor values. When prompted, move the robot (while   *\n"
   "*    keeping it in the same region) so it can collect an average.   *\n"
   "* 3) When prompted, move the robot to the 'outer' region, and       *\n"
   "*    follow the same process as in Step (1).                        *\n"
   "* 4) The program will then compute an average for the two regions   *\n"
   "*    (allowing for some margin to account for variability) and save *\n"
   "*    the result as 'calibration.dat', or tell you if it's not       *\n"
   "*    possible to distinguish the two regions.                       *\n"
   "*********************************************************************\n"
   );
 printf("\nSTEP 1)\n");
 fd = connectDevice(argv[1]);
 if (fd > -1) printf("Connected to device with file descriptor: %d\n",fd);
 printf("STEP 2)\n");
 printf("Place Robot in region one.\n");
 for(i=0;i<1;++i)
 {
  printf("Collecting sample %d of %d\n",(i+1),1);
  printf("When ready to sample, press <return>\n");
  p = fgets(line,40,stdin);
  ret = askForSensors(fd,sensors);
 }
 printf("STEP 3)\n");
 printf("Place Robot in region two.\n");
 for(i=0;i<1;++i)
 {
  printf("Collecting sample %d of %d\n",(i+1),1);
  printf("When ready to sample, press <return>\n");
  p = fgets(line,40,stdin);
 }
 printf("STEP 4)\n");
 cmd[0] = 150;
 cmd[1] = 0;
 disconnectDevice(fd);
 printf("Disconnected from device. File descriptor is now: %d\n",fd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int i; int ret;
 int sensors[10];
 char line[40];
 char cmd[8];
 char *p;
 printf("******************** iRobot Sensor Calibration **********************\n");
 printf( "* How this works:                                                   *\n"
   "* 1) The program will attempt to connect to the device specified by *\n"
   "*    the command line argument... which you should've entered...    *\n"
   "* 2) Place Robot in the 'inner' region. The program will read the   *\n"
   "*    infrared sensor values. When prompted, move the robot (while   *\n"
   "*    keeping it in the same region) so it can collect an average.   *\n"
   "* 3) When prompted, move the robot to the 'outer' region, and       *\n"
   "*    follow the same process as in Step (1).                        *\n"
   "* 4) The program will then compute an average for the two regions   *\n"
   "*    (allowing for some margin to account for variability) and save *\n"
   "*    the result as 'calibration.dat', or tell you if it's not       *\n"
   "*    possible to distinguish the two regions.                       *\n"
   "*********************************************************************\n"
   );
 printf("\nSTEP 1)\n");
 fd = connectDevice(argv[1]);
 if (fd > -1) printf("Connected to device with file descriptor: %d\n",fd);
 printf("STEP 2)\n");
 printf("Place Robot in region one.\n");
 for(i=0;i<1;++i)
 {
  printf("Collecting sample %d of %d\n",(i+1),1);
  printf("When ready to sample, press <return>\n");
  p = fgets(line,40,stdin);
  ret = askForSensors(fd,sensors);
 }
 printf("STEP 3)\n");
 printf("Place Robot in region two.\n");
 for(i=0;i<1;++i)
 {
  printf("Collecting sample %d of %d\n",(i+1),1);
  printf("When ready to sample, press <return>\n");
  p = fgets(line,40,stdin);
 }
 printf("STEP 4)\n");
 cmd[0] = 150;
 cmd[1] = 0;
 disconnectDevice(fd);
 printf("Disconnected from device. File descriptor is now: %d\n",fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
sensors
int [10]

variable_types:
line
char [40]

variable_types:
cmd
char [8]

variable_types:
p
char *


repo: cliffeh/punky

decompiled_code:
const char *__fastcall type_to_string(int a1)
{
const char *result; // rax

if ( a1 == 64 )
return "FUN";
if ( a1 <= 64 )
{
if ( (unsigned int)(a1 - 1) > 0x1F )
{
result = "UNKNOWN";
}
else
{
switch ( a1 )
{
case 1:
result = "LIST";
break;
case 2:
result = "INTEGER";
break;
case 4:
result = "FLOAT";
break;
case 8:
result = "STRING";
break;
case 16:
result = "IDENT";
break;
case 32:
result = "OP";
break;
default:
result = "UNKNOWN";
break;
}
}
}
else if ( a1 == 2048 )
{
result = "<<EOF>>";
}
else if ( a1 <= 2048 )
{
result = "RE";
if ( a1 != 512 )
{
if ( a1 == 1024 )
{
result = "NIL";
}
else
{
result = "UNKNOWN";
if ( a1 == 128 )
result = "PORT";
}
}
}
else
{
result = "ERR";
if ( a1 != 4096 )
{
result = "UNKNOWN";
if ( a1 == 24576 )
result = "BOOL";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(int a1)
{
const char *result; // rax

if ( a1 == 64 )
return "FUN";
if ( a1 <= 64 )
{
if ( (unsigned int)(a1 - 1) > 0x1F )
{
result = "UNKNOWN";
}
else
{
switch ( a1 )
{
case 1:
result = "LIST";
break;
case 2:
result = "INTEGER";
break;
case 4:
result = "FLOAT";
break;
case 8:
result = "STRING";
break;
case 16:
result = "IDENT";
break;
case 32:
result = "OP";
break;
default:
result = "UNKNOWN";
break;
}
}
}
else if ( a1 == 2048 )
{
result = "<<EOF>>";
}
else if ( a1 <= 2048 )
{
result = "RE";
if ( a1 != 512 )
{
if ( a1 == 1024 )
{
result = "NIL";
}
else
{
result = "UNKNOWN";
if ( a1 == 128 )
result = "PORT";
}
}
}
else
{
result = "ERR";
if ( a1 != 4096 )
{
result = "UNKNOWN";
if ( a1 == 24576 )
result = "BOOL";
}
}
return result;
}

original_code:
char *type_to_string(int t)
{
  switch(t) {
  case (1<<0): return "LIST";
  case ((1<<13)|(1<<14)): return "BOOL";
  case (1<<1): return "INTEGER";
  case (1<<2): return "FLOAT";
  case (1<<3): return "STRING";
  case (1<<4): return "IDENT";
  case (1<<5): return "OP";
  case (1<<6): return "FUN";
  case (1<<7): return "PORT";
  case (1<<9): return "RE";
  case (1<<10): return "NIL";
  case (1<<12): return "ERR";
  case (1<<11): return "<<EOF>>";
  default: return "UNKNOWN";
  }
}

variable_types: t int


yywrap

decompiled_code:
__int64 yywrap()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 1LL;
}

original_code:
int yywrap()
{
  return(1);
}

canonical_original_code:
int yywrap()
{
  return(1);
}


decompiled_code:
__int64 __fastcall redir_lenth(char *a1)
{
_BOOL8 v1; // rbp
__int64 v2; // r12
char v3; // si
_BOOL8 v4; // rbp

v1 = byte_49E[my_strilen(byte_49E, (unsigned int)*a1)] != 0;
v2 = v1 + 1;
v3 = a1[v1 + 1];
if ( v3 != 38 || a1[v1] == 60 )
{
v2 -= (byte_4A2[my_strilen(byte_4A2, (unsigned int)v3)] == 0) - 1LL;
}
else if ( byte_49E[my_strilen(byte_49E, (unsigned int)a1[v1 + 2])] )
{
v4 = v1 + 3;
if ( asc_4A5[my_strilen(" \t\"'|&;()`", (unsigned int)a1[v4])] )
{
v2 = v4;
}
else if ( !a1[v4] )
{
v2 = v4;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
_BOOL8 v1; // rbp
__int64 v2; // r12
char v3; // si
_BOOL8 v4; // rbp

v1 = byte_49E[my_strilen(byte_49E, (unsigned int)*a1)] != 0;
v2 = v1 + 1;
v3 = a1[v1 + 1];
if ( v3 != 38 || a1[v1] == 60 )
{
v2 -= (byte_4A2[my_strilen(byte_4A2, (unsigned int)v3)] == 0) - 1LL;
}
else if ( byte_49E[my_strilen(byte_49E, (unsigned int)a1[v1 + 2])] )
{
v4 = v1 + 3;
if ( asc_4A5[my_strilen(" \t\"'|&;()`", (unsigned int)a1[v4])] )
{
v2 = v4;
}
else if ( !a1[v4] )
{
v2 = v4;
}
}
return v2;
}

variable_types:
s
char *

variable_types:
n
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall work_on_quote(char *a1, _QWORD *a2)
{
char v3[27]; // [rsp+Dh] [rbp-1Bh] BYREF

v3[0] = *a1;
v3[1] = 39;
v3[2] = 0;
if ( !a1[my_strilen(a1 + 1, (unsigned int)v3[0]) + 1] )
*a2 = my_strcat("(sh): unexpected EOS while looking for matching `", v3);
return my_strilen(a1 + 1, (unsigned int)v3[0]) + 2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, _QWORD *a2)
{
char v3[27]; // [rsp+Dh] [rbp-1Bh] BYREF

v3[0] = *a1;
v3[1] = 39;
v3[2] = 0;
if ( !a1[my_strilen(a1 + 1, (unsigned int)v3[0]) + 1] )
*a2 = my_strcat("(sh): unexpected EOS while looking for matching `", v3);
return my_strilen(a1 + 1, (unsigned int)v3[0]) + 2;
}

original_code:
static size_t work_on_quote(char *s, char **bad_sintax)
{
  char quote[3];
  quote[0] = s[0];
  quote[1] = '\'';
  quote[2] = 0;
  if (!((s + 1)[my_strilen(s + 1, quote[0])] != 0))
    *bad_sintax = my_strcat("(sh): unexpected EOS while looking for matching `", quote);
  return (my_strilen(s + 1, quote[0]) + 2);
}

canonical_original_code:
static unsigned long work_on_quote(char *s, char **bad_sintax)
{
  char quote[3];
  quote[0] = s[0];
  quote[1] = '\'';
  quote[2] = 0;
  if (!((s + 1)[my_strilen(s + 1, quote[0])] != 0))
    *bad_sintax = my_strcat("(sh): unexpected EOS while looking for matching `", quote);
  return (my_strilen(s + 1, quote[0]) + 2);
}

variable_types:
quote
char [3]


subdiv

decompiled_code:
__int64 __fastcall subdiv(char *a1, _QWORD *a2)
{
__int64 v3; // rax
int v4; // edx
__int64 result; // rax
__int64 v6; // rax
int v7; // edx
__int64 v8; // rax
int v9; // edx
__int64 v10; // rax
int v11; // edx
unsigned __int64 v12; // r12
char v13; // si
__int64 v14; // rdx
__int64 v15; // rax
__int64 v16; // rbp
__int64 v17; // rax
unsigned __int64 v18; // rbp

if ( !a1 )
goto LABEL_6;
v3 = my_strlen("||");
v4 = my_strncmp("||", a1, v3);
result = 2LL;
if ( v4 )
{
v6 = my_strlen("&&");
v7 = my_strncmp("&&", a1, v6);
result = 2LL;
if ( v7 )
{
v8 = my_strlen("<<");
v9 = my_strncmp("<<", a1, v8);
result = 2LL;
if ( v9 )
{
v10 = my_strlen(">>");
v11 = my_strncmp(">>", a1, v10);
result = 2LL;
if ( v11 )
{
LABEL_6:
v12 = my_sstrlen(a1, byte_4A2);
if ( v12 >= my_sstrlen(a1, " \\\t\"'|&;()`") || my_sstrlen(a1, byte_4A2) != 1 && my_sstrlen(a1, byte_4A2) )
{
v13 = *a1;
if ( *a1 == 34 || v13 == 39 )
{
result = work_on_quote(a1, a2);
}
else
{
v14 = my_strilen(";|&<>()`", (unsigned int)v13);
result = 1LL;
if ( !asc_4BF[v14] )
{
my_strilen(a1, 38LL);
v15 = my_strilen(a1, 38LL);
v16 = my_strlen(&a1[v15]);
v17 = my_strilen(a1, 38LL);
if ( (unsigned int)my_strncmp(&a1[v17], "&&", v16)
|| (v18 = my_strilen(a1, 38LL), v18 >= my_sstrlen(a1, " \\\t\"'|;<>()`")) )
{
result = my_sstrlen(a1, " \\\t\"'|&;<>()`");
}
else
{
result = my_strilen(a1, 38LL);
}
}
}
}
else
{
result = redir_lenth(a1);
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, _QWORD *a2)
{
__int64 v3; // rax
int v4; // edx
__int64 result; // rax
__int64 v6; // rax
int v7; // edx
__int64 v8; // rax
int v9; // edx
__int64 v10; // rax
int v11; // edx
unsigned __int64 v12; // r12
char v13; // si
__int64 v14; // rdx
__int64 v15; // rax
__int64 v16; // rbp
__int64 v17; // rax
unsigned __int64 v18; // rbp

if ( !a1 )
goto LABEL_6;
v3 = my_strlen("||");
v4 = my_strncmp("||", a1, v3);
result = 2LL;
if ( v4 )
{
v6 = my_strlen("&&");
v7 = my_strncmp("&&", a1, v6);
result = 2LL;
if ( v7 )
{
v8 = my_strlen("<<");
v9 = my_strncmp("<<", a1, v8);
result = 2LL;
if ( v9 )
{
v10 = my_strlen(">>");
v11 = my_strncmp(">>", a1, v10);
result = 2LL;
if ( v11 )
{
LABEL_6:
v12 = my_sstrlen(a1, byte_4A2);
if ( v12 >= my_sstrlen(a1, " \\\t\"'|&;()`") || my_sstrlen(a1, byte_4A2) != 1 && my_sstrlen(a1, byte_4A2) )
{
v13 = *a1;
if ( *a1 == 34 || v13 == 39 )
{
result = func1(a1, a2);
}
else
{
v14 = my_strilen(";|&<>()`", (unsigned int)v13);
result = 1LL;
if ( !asc_4BF[v14] )
{
my_strilen(a1, 38LL);
v15 = my_strilen(a1, 38LL);
v16 = my_strlen(&a1[v15]);
v17 = my_strilen(a1, 38LL);
if ( (unsigned int)my_strncmp(&a1[v17], "&&", v16)
|| (v18 = my_strilen(a1, 38LL), v18 >= my_sstrlen(a1, " \\\t\"'|;<>()`")) )
{
result = my_sstrlen(a1, " \\\t\"'|&;<>()`");
}
else
{
result = my_strilen(a1, 38LL);
}
}
}
}
else
{
result = func0(a1);
}
}
}
}
}
return result;
}


subdivide

decompiled_code:
__int64 __fastcall subdivide(_BYTE *a1, _QWORD *a2, _QWORD *a3)
{
_BYTE *v4; // rbx
_QWORD *v5; // rax
char *v6; // r12
__int64 v7; // rax
_QWORD *v9; // rax
__int64 v10; // rdi
__int64 v11; // rax

v4 = a2;
if ( (unsigned __int8)empty() )
return (__int64)v4;
if ( *a1 != 92 || !a2 )
{
v5 = (_QWORD *)xmalloc(32LL);
v4 = v5;
if ( !v5 )
return (__int64)v4;
v5[2] = 0LL;
*v5 = 0LL;
v5[3] = a2;
if ( !a2 )
goto LABEL_7;
goto LABEL_6;
}
if ( !asc_4EC[my_strslen("\"'|;<>()`", *a2)] )
return echappment(a1, a2, a3, 0LL);
v9 = (_QWORD *)xmalloc(32LL);
v4 = v9;
if ( v9 )
{
v9[2] = 0LL;
*v9 = 0LL;
v9[3] = a2;
LABEL_6:
a2[2] = v4;
LABEL_7:
v6 = &a1[hempty(a1)];
v4[8] = 0;
if ( *v6 == 92 )
{
v4 = (_BYTE *)echappment(v6, v4, a3, 1LL);
}
else
{
v7 = subdiv(v6, a3);
if ( *a3 || (v10 = my_strndup(v6, v7), (*(_QWORD *)v4 = v10) == 0LL) )
{
v4 = (_BYTE *)nullify_link(v4, 0, 1);
}
else
{
v11 = my_strlen(v10);
if ( !subdivide(&v6[v11], v4, a3) )
v4 = (_BYTE *)nullify_link(v4, 1, 1);
}
}
}
return (__int64)v4;
}

original_code:
t_get *subdivide(char *s, t_get *prev, char **bad_sintax)
{
  size_t l;
  t_get *link;
  if (empty(s))
    return (prev);
  if (s[0] == '\\' && prev)
    if ((!(("\"'|;<>()`")[my_strslen("\"'|;<>()`", prev->word)] != 0)))
      return (echappment(s, prev, bad_sintax, 0));
  if ((link = xmalloc(sizeof(*prev))) == ((void *)0))
    return (((void *)0));
  link->word = (void*)(link->next = ((void *)0));
  link->prev = prev;
  if (prev)
    prev->next = link;
  s += hempty(s);
  if (s[(link->inter = 0)] == '\\')
    return (echappment(s, link, bad_sintax, 1));
  l = subdiv(s, bad_sintax);
  if (*bad_sintax)
    return (nullify_link(link, 0, 1));
  if ((link->word = my_strndup(s, l)) == ((void *)0))
    return (nullify_link(link, 0, 1));
  if (subdivide(s + my_strlen(link->word), link, bad_sintax) == ((void *)0))
    return (nullify_link(link, 1, 1));
  return (link);
}

canonical_original_code:
struct s_get *subdivide(char *s, struct s_get *prev, char **bad_sintax)
{
  unsigned long l;
  struct s_get *link;
  if (empty(s))
    return (prev);
  if (s[0] == '\\' && prev)
    if ((!(("\"'|;<>()`")[my_strslen("\"'|;<>()`", prev->word)] != 0)))
      return (echappment(s, prev, bad_sintax, 0));
  if ((link = xmalloc(sizeof(*prev))) == ((void *)0))
    return (((void *)0));
  link->word = (void *)(link->next = ((void *)0));
  link->prev = prev;
  if (prev)
    prev->next = link;
  s += hempty(s);
  if (s[(link->inter = 0)] == '\\')
    return (echappment(s, link, bad_sintax, 1));
  l = subdiv(s, bad_sintax);
  if (*bad_sintax)
    return (nullify_link(link, 0, 1));
  if ((link->word = my_strndup(s, l)) == ((void *)0))
    return (nullify_link(link, 0, 1));
  if (subdivide(s + my_strlen(link->word), link, bad_sintax) == ((void *)0))
    return (nullify_link(link, 1, 1));
  return (link);
}

variable_types:
prev
struct s_get *

variable_types:
l
unsigned long

variable_types: struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *


decompiled_code:
__int64 __fastcall aff_str_cmd(unsigned int a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
result = my_putstr(a2, a1);
else
result = my_putstr(a2, 1LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
result = my_putstr(a2, a1);
else
result = my_putstr(a2, 1LL);
return result;
}

original_code:
static void aff_str_cmd(int fd, char *str)
{
  if (fd == 0)
    my_putstr(str, 1);
  else
    my_putstr(str, fd);
}

variable_types: fd int

variable_types:
str
char *


decompiled_code:
__int64 __fastcall aff_char_cmd(unsigned int a1, char a2)
{
__int64 result; // rax

if ( a1 )
result = my_putchar((unsigned int)a2, a1);
else
result = my_putchar((unsigned int)a2, 1LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, char a2)
{
__int64 result; // rax

if ( a1 )
result = my_putchar((unsigned int)a2, a1);
else
result = my_putchar((unsigned int)a2, 1LL);
return result;
}

original_code:
static void aff_char_cmd(int fd, char chr)
{
  if (fd == 0)
    my_putchar(chr, 1);
  else
    my_putchar(chr, fd);
}

variable_types: chr char


decompiled_code:
unsigned __int64 __fastcall go_up_of_cmd_high(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, __int64 a15)
{
unsigned __int64 result; // rax
unsigned __int64 v16; // rtt
int v17; // ebx
char v18[2]; // [rsp+8h] [rbp-20h] BYREF
unsigned __int16 v19; // [rsp+Ah] [rbp-1Eh]

ioctl(0, 0x5413uLL, v18);
v16 = my_strlen(a1) + a2;
result = v16 / v19;
v17 = result - 1;
if ( (int)result - 1 >= 0 )
{
do
{
result = my_putstr(a15, 1LL);
--v17;
}
while ( v17 != -1 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, __int64 a15)
{
unsigned __int64 result; // rax
unsigned __int64 v16; // rtt
int v17; // ebx
char v18[2]; // [rsp+8h] [rbp-20h] BYREF
unsigned __int16 v19; // [rsp+Ah] [rbp-1Eh]

ioctl(0, 0x5413uLL, v18);
v16 = my_strlen(a1) + a2;
result = v16 / v19;
v17 = result - 1;
if ( (int)result - 1 >= 0 )
{
do
{
result = my_putstr(a15, 1LL);
--v17;
}
while ( v17 != -1 );
}
return result;
}

original_code:
void go_up_of_cmd_high(char *cmd, int len, t_options opt)
{
  int high;
  struct winsize ws;
  ioctl(0, 0x5413, &ws);
  high = (my_strlen(cmd) + len) / ws.ws_col;
  while (--high >= 0)
    my_putstr(opt.up_cursor, 1);
}

canonical_original_code:
void go_up_of_cmd_high(char *cmd, int len, struct s_options opt)
{
  int high;
  struct winsize ws;
  ioctl(0, 0x5413, &ws);
  high = (my_strlen(cmd) + len) / ws.ws_col;
  while (--high >= 0)
    my_putstr(opt.up_cursor, 1);
}

variable_types:
cmd
char *

variable_types: len int

variable_types: struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; }

variable_types: high int

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


original_code:
void show_cmd(char key, int fd, char *cmd, int reverse_case)
{
  int i;
  t_options options;
  int len;
  i = -1;
  len = prompt(0);
  retain_struct_options(2, &options);
  while (cmd[++i] != '\0')
    {
      if (key != 10 && i == reverse_case && cmd[i] != '\t')
 aff_str_cmd(fd, options.reverse);
      aff_char_cmd(fd, cmd[i]);
 aff_str_cmd(fd, options.forward);
    }
  if (key != 10 && i == reverse_case)
    aff_str_cmd(fd, options.reverse);
  aff_char_cmd(fd, ' ');
  aff_str_cmd(fd, options.forward);
  if (key != 10)
    {
      aff_str_cmd(fd, options.clean_end);
      go_up_of_cmd_high(cmd, len, options);
    }
  aff_str_cmd(fd, "\r");
}

canonical_original_code:
void show_cmd(char key, int fd, char *cmd, int reverse_case)
{
  int i;
  struct s_options options;
  int len;
  i = -1;
  len = prompt(0);
  retain_struct_options(2, &options);
  while (cmd[++i] != '\0')
    {
      if (key != 10 && i == reverse_case && cmd[i] != '\t')
 aff_str_cmd(fd, options.reverse);
      aff_char_cmd(fd, cmd[i]);
 aff_str_cmd(fd, options.forward);
    }
  if (key != 10 && i == reverse_case)
    aff_str_cmd(fd, options.reverse);
  aff_char_cmd(fd, ' ');
  aff_str_cmd(fd, options.forward);
  if (key != 10)
    {
      aff_str_cmd(fd, options.clean_end);
      go_up_of_cmd_high(cmd, len, options);
    }
  aff_str_cmd(fd, "\r");
}

variable_types: key char

variable_types: i int

user_defined_types: struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; }


decompiled_code:
__int64 __fastcall my_strlen(_BYTE *a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( !*a1 )
return 0LL;
result = 0LL;
do
++result;
while ( a1[result] );
return result;
}

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

if ( !a1 )
return 0LL;
if ( !*a1 )
return 0LL;
result = 0LL;
do
++result;
while ( a1[result] );
return result;
}

original_code:
size_t my_strlen(const char *s)
{
  size_t i;
  i = 0;
  if (!s)
    return (0);
  while (s[i])
    i++;
  return (i);
}

canonical_original_code:
unsigned long my_strlen(char *s)
{
  unsigned long i;
  i = 0;
  if (!s)
    return (0);
  while (s[i])
    i++;
  return (i);
}

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall my_strilen(_BYTE *a1, char a2)
{
__int64 result; // rax
char v3; // dl

if ( *a1 == a2 || !*a1 )
return 0LL;
result = 0LL;
do
v3 = a1[++result];
while ( v3 != a2 && v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, char a2)
{
__int64 result; // rax
char v3; // dl

if ( *a1 == a2 || !*a1 )
return 0LL;
result = 0LL;
do
v3 = a1[++result];
while ( v3 != a2 && v3 );
return result;
}

original_code:
size_t my_strilen(const char *s, char c)
{
  size_t i;
  i = 0;
  while (s[i] && s[i] != c)
    i++;
  return (i);
}

canonical_original_code:
unsigned long my_strilen(char *s, char c)
{
  unsigned long i;
  i = 0;
  while (s[i] && s[i] != c)
    i++;
  return (i);
}

variable_types:
s
char *

variable_types: c char


decompiled_code:
__int64 __fastcall my_strslen(_BYTE *a1, _BYTE *a2)
{
_BYTE *v2; // rbx
__int64 i; // rbp
__int64 v4; // rax

v2 = a1;
for ( i = 0LL; *v2; ++v2 )
{
if ( v2 )
{
if ( a2 )
{
v4 = my_strlen(a2);
if ( !(unsigned int)my_strncmp(a2, v2, v4) )
break;
}
}
++i;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, _BYTE *a2)
{
_BYTE *v2; // rbx
__int64 i; // rbp
__int64 v4; // rax

v2 = a1;
for ( i = 0LL; *v2; ++v2 )
{
if ( v2 )
{
if ( a2 )
{
v4 = func0(a2);
if ( !(unsigned int)my_strncmp(a2, v2, v4) )
break;
}
}
++i;
}
return i;
}

original_code:
size_t my_strslen(const char *s, const char *c)
{
  size_t i;
  i = 0;
  while (s[i] && !(((c) && (s + i)) ? (!my_strncmp((c), (s + i), my_strlen(c))) : (0)))
    i++;
  return (i);
}

canonical_original_code:
unsigned long my_strslen(char *s, char *c)
{
  unsigned long i;
  i = 0;
  while (s[i] && !(((c) && (s + i)) ? (!my_strncmp((c), (s + i), my_strlen(c))) : (0)))
    i++;
  return (i);
}

variable_types:
c
char *


decompiled_code:
__int64 __fastcall my_sstrlen(char *a1, _BYTE *a2)
{
char v3; // si
__int64 i; // rbx

v3 = *a1;
for ( i = 0LL; v3; v3 = a1[i] )
{
if ( a2[my_strilen(a2, v3)] )
break;
++i;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, _BYTE *a2)
{
char v3; // si
__int64 i; // rbx

v3 = *a1;
for ( i = 0LL; v3; v3 = a1[i] )
{
if ( a2[func1(a2, v3)] )
break;
++i;
}
return i;
}

original_code:
size_t my_sstrlen(const char *s, const char *c)
{
  size_t i;
  i = 0;
  while (s[i] && !((c)[my_strilen(c, s[i])] != 0))
    i++;
  return (i);
}

canonical_original_code:
unsigned long my_sstrlen(char *s, char *c)
{
  unsigned long i;
  i = 0;
  while (s[i] && !((c)[my_strilen(c, s[i])] != 0))
    i++;
  return (i);
}


lenmatch

decompiled_code:
__int64 __fastcall lenmatch(char *a1, _BYTE *a2)
{
char v3; // si
__int64 i; // rbx

v3 = *a1;
for ( i = 0LL; v3; v3 = a1[i] )
{
if ( !a2[my_strilen(a2, v3)] )
break;
++i;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, _BYTE *a2)
{
char v3; // si
__int64 i; // rbx

v3 = *a1;
for ( i = 0LL; v3; v3 = a1[i] )
{
if ( !a2[func1(a2, v3)] )
break;
++i;
}
return i;
}

original_code:
size_t lenmatch(const char *s, const char *c)
{
  size_t i;
  i = 0;
  while (s[i] && ((c)[my_strilen(c, s[i])] != 0))
    i++;
  return (i);
}

canonical_original_code:
unsigned long lenmatch(char *s, char *c)
{
  unsigned long i;
  i = 0;
  while (s[i] && ((c)[my_strilen(c, s[i])] != 0))
    i++;
  return (i);
}


decompiled_code:
bool __fastcall move_env(__int64 a1, __int64 a2)
{
bool result; // al
__int64 v3; // rax
int v4; // edx
char *v5; // rbp

result = 0;
if ( a1 && environ[a2] )
{
v3 = ((__int64 (*)(void))my_strlen)();
v4 = my_strncmp(a1, environ[a2], v3);
result = 0;
if ( !v4 )
{
v5 = environ[a2];
result = v5[my_strlen(a1)] == 61;
}
}
return result;
}

canonical_decompiled_code:
bool __fastcall func0(__int64 a1, __int64 a2)
{
bool result; // al
__int64 v3; // rax
int v4; // edx
char *v5; // rbp

result = 0;
if ( a1 && environ[a2] )
{
v3 = ((__int64 (*)(void))my_strlen)();
v4 = my_strncmp(a1, environ[a2], v3);
result = 0;
if ( !v4 )
{
v5 = environ[a2];
result = v5[my_strlen(a1)] == 61;
}
}
return result;
}

original_code:
static unsigned char move_env(char *s, size_t i)
{
  if ((((s) && (environ[i])) ? (!my_strncmp((s), (environ[i]), my_strlen(s))) : (0)) && (environ[i][my_strlen(s)] == '='))
    return (1);
  return (0);
}

canonical_original_code:
static unsigned char move_env(char *s, unsigned long i)
{
  if ((((s) && (environ[i])) ? (!my_strncmp((s), (environ[i]), my_strlen(s))) : (0)) && (environ[i][my_strlen(s)] == '='))
    return (1);
  return (0);
}

return_type: unsigned char


decompiled_code:
char __fastcall set_env(__int64 a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v5; // r13
char **v6; // rdx
__int64 v7; // rbx
__int64 v8; // rax
__int64 v9; // rcx

v3 = 0LL;
if ( environ )
{
while ( environ[v3] )
{
if ( move_env(a1, v3) )
return fill_env(a1, a2, v3);
++v3;
}
}
v5 = xmalloc(8 * v3 + 24);
if ( !v5 )
return 0;
v6 = environ;
v7 = 0LL;
if ( environ )
{
if ( *environ )
{
v8 = 0LL;
v7 = 1LL;
do
{
v9 = v7;
*(_QWORD *)(v5 + v8 * 8) = v6[v8];
v6 = environ;
++v7;
++v8;
}
while ( environ[v9] );
}
else
{
v7 = 1LL;
}
}
*(_QWORD *)(v5 + 8 * v7 - 8) = my_stricat(a1, a2, 61LL);
*(_QWORD *)(v5 + 8 * v7) = 0LL;
return switch_env(v5, 0LL);
}

canonical_decompiled_code:
char __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v5; // r13
char **v6; // rdx
__int64 v7; // rbx
__int64 v8; // rax
__int64 v9; // rcx

v3 = 0LL;
if ( environ )
{
while ( environ[v3] )
{
if ( func0(a1, v3) )
return func1(a1, a2, v3);
++v3;
}
}
v5 = xmalloc(8 * v3 + 24);
if ( !v5 )
return 0;
v6 = environ;
v7 = 0LL;
if ( environ )
{
if ( *environ )
{
v8 = 0LL;
v7 = 1LL;
do
{
v9 = v7;
*(_QWORD *)(v5 + v8 * 8) = v6[v8];
v6 = environ;
++v7;
++v8;
}
while ( environ[v9] );
}
else
{
v7 = 1LL;
}
}
*(_QWORD *)(v5 + 8 * v7 - 8) = my_stricat(a1, a2, 61LL);
*(_QWORD *)(v5 + 8 * v7) = 0LL;
return switch_env(v5, 0LL);
}

original_code:
unsigned char set_env(char *s, char *s2)
{
  char **tab;
  size_t i;
  i = 0;
  if (environ)
    while (environ[i])
      if (move_env(s, i++))
 return (fill_env(s, s2, i - 1));
  if ((tab = xmalloc(sizeof(*tab) * (i + 3))) == ((void *)0))
    return (0);
  i = 0;
  if (environ)
    while (environ[i++])
      tab[i - 1] = environ[i - 1];
  tab[i - 1] = my_stricat(s, s2, '=');
  tab[i] = ((void *)0);
  return (switch_env(tab, 0));
}

canonical_original_code:
unsigned char set_env(char *s, char *s2)
{
  char **tab;
  unsigned long i;
  i = 0;
  if (environ)
    while (environ[i])
      if (move_env(s, i++))
 return (fill_env(s, s2, i - 1));
  if ((tab = xmalloc(sizeof(*tab) * (i + 3))) == ((void *)0))
    return (0);
  i = 0;
  if (environ)
    while (environ[i++])
      tab[i - 1] = environ[i - 1];
  tab[i - 1] = my_stricat(s, s2, '=');
  tab[i] = ((void *)0);
  return (switch_env(tab, 0));
}

variable_types:
tab
char **


decompiled_code:
char *__fastcall get_env(__int64 a1)
{
char *result; // rax
__int64 v2; // rbx
__int64 v3; // rax
char *v4; // rbx

result = (char *)environ;
if ( environ )
{
result = *environ;
if ( *environ )
{
v2 = 0LL;
while ( 1 )
{
if ( a1 )
{
v3 = my_strlen(a1);
if ( !(unsigned int)my_strncmp(a1, environ[v2], v3) )
break;
}
result = environ[++v2];
if ( !result )
return result;
}
v4 = environ[v2];
result = &v4[my_strilen(v4, 61LL) + 1];
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1)
{
char *result; // rax
__int64 v2; // rbx
__int64 v3; // rax
char *v4; // rbx

result = (char *)environ;
if ( environ )
{
result = *environ;
if ( *environ )
{
v2 = 0LL;
while ( 1 )
{
if ( a1 )
{
v3 = my_strlen(a1);
if ( !(unsigned int)my_strncmp(a1, environ[v2], v3) )
break;
}
result = environ[++v2];
if ( !result )
return result;
}
v4 = environ[v2];
result = &v4[my_strilen(v4, 61LL) + 1];
}
}
return result;
}

original_code:
char *get_env(char *s)
{
  size_t i;
  i = 0;
  if (!environ)
    return (((void *)0));
  while (environ[i])
    {
      if ((((s) && (environ[i])) ? (!my_strncmp((s), (environ[i]), my_strlen(s))) : (0)))
 return (environ[i] + my_strilen(environ[i], '=') + 1);
      i++;
    }
  return (((void *)0));
}

canonical_original_code:
char *get_env(char *s)
{
  unsigned long i;
  i = 0;
  if (!environ)
    return (((void *)0));
  while (environ[i])
    {
      if ((((s) && (environ[i])) ? (!my_strncmp((s), (environ[i]), my_strlen(s))) : (0)))
 return (environ[i] + my_strilen(environ[i], '=') + 1);
      i++;
    }
  return (((void *)0));
}


decompiled_code:
char *__fastcall get_full_env(__int64 a1)
{
char *result; // rax
__int64 v2; // rbx
__int64 v3; // rax

result = (char *)environ;
if ( environ )
{
result = *environ;
if ( *environ )
{
v2 = 0LL;
while ( 1 )
{
if ( a1 )
{
v3 = my_strlen(a1);
if ( !(unsigned int)my_strncmp(a1, environ[v2], v3) )
break;
}
result = environ[++v2];
if ( !result )
return result;
}
result = environ[v2];
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1)
{
char *result; // rax
__int64 v2; // rbx
__int64 v3; // rax

result = (char *)environ;
if ( environ )
{
result = *environ;
if ( *environ )
{
v2 = 0LL;
while ( 1 )
{
if ( a1 )
{
v3 = my_strlen(a1);
if ( !(unsigned int)my_strncmp(a1, environ[v2], v3) )
break;
}
result = environ[++v2];
if ( !result )
return result;
}
result = environ[v2];
}
}
return result;
}

original_code:
char *get_full_env(char *s)
{
  size_t i;
  i = 0;
  if (!environ)
    return (((void *)0));
  while (environ[i])
    {
      if ((((s) && (environ[i])) ? (!my_strncmp((s), (environ[i]), my_strlen(s))) : (0)))
 return (environ[i]);
      i++;
    }
  return (((void *)0));
}

canonical_original_code:
char *get_full_env(char *s)
{
  unsigned long i;
  i = 0;
  if (!environ)
    return (((void *)0));
  while (environ[i])
    {
      if ((((s) && (environ[i])) ? (!my_strncmp((s), (environ[i]), my_strlen(s))) : (0)))
 return (environ[i]);
      i++;
    }
  return (((void *)0));
}


decompiled_code:
bool __fastcall fill_env(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx
char **v4; // rbx
__int64 v5; // rax

v3 = a3;
free(environ[v3]);
v4 = &environ[v3];
v5 = my_stricat(a1, a2, 61LL);
*v4 = (char *)v5;
return v5 != 0;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx
char **v4; // rbx
__int64 v5; // rax

v3 = a3;
free(environ[v3]);
v4 = &environ[v3];
v5 = my_stricat(a1, a2, 61LL);
*v4 = (char *)v5;
return v5 != 0;
}

original_code:
static unsigned char fill_env(char *s, char *s2, int i)
{
  free(environ[i]);
  if ((environ[i] = my_stricat(s, s2, '=')) == ((void *)0))
    return (0);
  return (1);
}


decompiled_code:
__int64 __fastcall my_strcmp(char *a1, char *a2)
{
char v2; // dl
char v3; // cl
__int64 v4; // rax

if ( !a1 )
return 1LL;
if ( !a2 )
return 0xFFFFFFFFLL;
v2 = *a1;
v3 = *a2;
if ( *a1 && v2 == v3 )
{
v4 = 0LL;
do
{
v2 = a1[++v4];
v3 = a2[v4];
}
while ( v2 && v2 == v3 );
}
return (unsigned int)(v2 - v3);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char *a2)
{
char v2; // dl
char v3; // cl
__int64 v4; // rax

if ( !a1 )
return 1LL;
if ( !a2 )
return 0xFFFFFFFFLL;
v2 = *a1;
v3 = *a2;
if ( *a1 && v2 == v3 )
{
v4 = 0LL;
do
{
v2 = a1[++v4];
v3 = a2[v4];
}
while ( v2 && v2 == v3 );
}
return (unsigned int)(v2 - v3);
}

original_code:
int my_strcmp(const char *s1, const char *s2)
{
  size_t i;
  if (s1 == ((void *)0))
    return (1);
  if (s2 == ((void *)0))
    return (-1);
  i = 0;
  while (s1[i] == s2[i] && s1[i])
    i++;
  return (s1[i] - s2[i]);
}

canonical_original_code:
int my_strcmp(char *s1, char *s2)
{
  unsigned long i;
  if (s1 == ((void *)0))
    return (1);
  if (s2 == ((void *)0))
    return (-1);
  i = 0;
  while (s1[i] == s2[i] && s1[i])
    i++;
  return (s1[i] - s2[i]);
}


decompiled_code:
__int64 __fastcall my_strncmp(char *a1, char *a2, __int64 a3)
{
__int64 result; // rax
char v6; // dl
char v7; // cl
__int64 v8; // rsi
__int64 v9; // rax

result = 0LL;
if ( a3 )
{
v6 = *a1;
v7 = *a2;
if ( *a1 )
{
if ( v6 == v7 )
{
v8 = a3 - 1;
if ( v8 )
{
v9 = 0LL;
do
{
v6 = a1[++v9];
v7 = a2[v9];
}
while ( v6 && v6 == v7 && v9 != v8 );
}
}
}
result = (unsigned int)(v6 - v7);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, char *a2, __int64 a3)
{
__int64 result; // rax
char v6; // dl
char v7; // cl
__int64 v8; // rsi
__int64 v9; // rax

result = 0LL;
if ( a3 )
{
v6 = *a1;
v7 = *a2;
if ( *a1 )
{
if ( v6 == v7 )
{
v8 = a3 - 1;
if ( v8 )
{
v9 = 0LL;
do
{
v6 = a1[++v9];
v7 = a2[v9];
}
while ( v6 && v6 == v7 && v9 != v8 );
}
}
}
result = (unsigned int)(v6 - v7);
}
return result;
}

original_code:
int my_strncmp(const char *s1, const char *s2, size_t n)
{
  size_t i;
  if (!n)
    return (0);
  i = 0;
  while (s1[i] == s2[i] && s1[i] && i < n - 1)
    i++;
  return (s1[i] - s2[i]);
}

canonical_original_code:
int my_strncmp(char *s1, char *s2, unsigned long n)
{
  unsigned long i;
  if (!n)
    return (0);
  i = 0;
  while (s1[i] == s2[i] && s1[i] && i < n - 1)
    i++;
  return (s1[i] - s2[i]);
}

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall last_soccur(char *a1, char *a2)
{
char *v2; // rbx
__int64 v3; // r13
__int64 v4; // rbp
__int64 v5; // rax

if ( !*a1 )
return 0LL;
v2 = a1;
v3 = 0LL;
v4 = 0LL;
do
{
if ( v2 )
{
if ( a2 )
{
v5 = my_strlen(a2);
if ( !(unsigned int)my_strncmp(a2, v2, v5) )
v3 = v4;
}
}
++v4;
++v2;
}
while ( *v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, char *a2)
{
char *v2; // rbx
__int64 v3; // r13
__int64 v4; // rbp
__int64 v5; // rax

if ( !*a1 )
return 0LL;
v2 = a1;
v3 = 0LL;
v4 = 0LL;
do
{
if ( v2 )
{
if ( a2 )
{
v5 = my_strlen(a2);
if ( !(unsigned int)func1(a2, v2, v5) )
v3 = v4;
}
}
++v4;
++v2;
}
while ( *v2 );
return v3;
}

original_code:
size_t last_soccur(const char *s1, const char *s2)
{
  size_t i;
  size_t r;
  i = 0;
  r = 0;
  while (s1[i])
    {
      if ((((s2) && (s1 + i)) ? (!my_strncmp((s2), (s1 + i), my_strlen(s2))) : (0)))
 r = i;
      i++;
    }
  return (r);
}

canonical_original_code:
unsigned long last_soccur(char *s1, char *s2)
{
  unsigned long i;
  unsigned long r;
  i = 0;
  r = 0;
  while (s1[i])
    {
      if ((((s2) && (s1 + i)) ? (!my_strncmp((s2), (s1 + i), my_strlen(s2))) : (0)))
 r = i;
      i++;
    }
  return (r);
}

variable_types:
r
unsigned long


decompiled_code:
__int64 __fastcall date_and_time(char a1)
{
unsigned int v1; // edx
char *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v1 = 0;
if ( timer != -1 )
{
v2 = ctime(&timer);
if ( v2 )
{
if ( a1 )
v1 = write(1, v2, 0xAuLL);
else
v1 = write(1, v2 + 11, 8uLL);
}
else
{
v1 = 0;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
unsigned int v1; // edx
char *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v1 = 0;
if ( timer != -1 )
{
v2 = ctime(&timer);
if ( v2 )
{
if ( a1 )
v1 = write(1, v2, 0xAuLL);
else
v1 = write(1, v2 + 11, 8uLL);
}
else
{
v1 = 0;
}
}
return v1;
}

original_code:
static int date_and_time(unsigned char t)
{
  time_t current_time;
  char* c_time_string;
  current_time = time(((void *)0));
  if (current_time == ((time_t)-1))
    return (0);
  c_time_string = ctime(&current_time);
  if (!c_time_string)
    return (0);
  if (t)
    return (write(1, c_time_string, 10));
  return (write(1, c_time_string + 11, 8));
}

canonical_original_code:
static int date_and_time(unsigned char t)
{
  long current_time;
  char *c_time_string;
  current_time = time(((void *)0));
  if (current_time == ((time_t)-1))
    return (0);
  c_time_string = ctime(&current_time);
  if (!c_time_string)
    return (0);
  if (t)
    return (write(1, c_time_string, 10));
  return (write(1, c_time_string + 11, 8));
}

variable_types:
t
unsigned char


decompiled_code:
ssize_t put_dir()
{
char *v0; // rbx
ssize_t result; // rax
size_t v2; // rax

v0 = getcwd(0LL, 0LL);
result = 0LL;
if ( v0 )
{
v2 = my_strlen(v0);
result = write(1, v0, v2);
}
return result;
}

canonical_decompiled_code:
ssize_t func1()
{
char *v0; // rbx
ssize_t result; // rax
size_t v2; // rax

v0 = getcwd(0LL, 0LL);
result = 0LL;
if ( v0 )
{
v2 = my_strlen(v0);
result = write(1, v0, v2);
}
return result;
}

original_code:
static int put_dir()
{
  int r;
  char *apwd;
  if ((apwd = getcwd(((void *)0), 0)) == ((void *)0))
    return (0);
  r = write(1, apwd, my_strlen(apwd));
  return (r);
}

variable_types: r int

variable_types:
apwd
char *


interpret

decompiled_code:
__int64 __fastcall interpret(__int64 a1, _DWORD *a2)
{
__uid_t v3; // eax
struct passwd *v4; // r12
char v5; // al
__int64 result; // rax
size_t v7; // rdx
char *v8; // rsi

v3 = getuid();
v4 = getpwuid(v3);
v5 = *(_BYTE *)(a1 + 1);
switch ( v5 )
{
case 'd':
*a2 = date_and_time(1);
result = 2LL;
break;
case 'h':
*a2 = date_and_time(0);
result = 2LL;
break;
case 'u':
if ( v4 )
{
v7 = my_strlen(v4->pw_name);
v8 = v4->pw_name;
}
else
{
v7 = my_strlen(&unk_46E);
v8 = (char *)&unk_46E;
}
*a2 = write(1, v8, v7);
result = 2LL;
break;
case '/':
*a2 = put_dir();
result = 2LL;
break;
default:
*a2 = write(1, &unk_472, 1uLL);
result = 1LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _DWORD *a2)
{
__uid_t v3; // eax
struct passwd *v4; // r12
char v5; // al
__int64 result; // rax
size_t v7; // rdx
char *v8; // rsi

v3 = getuid();
v4 = getpwuid(v3);
v5 = *(_BYTE *)(a1 + 1);
switch ( v5 )
{
case 'd':
*a2 = func0(1);
result = 2LL;
break;
case 'h':
*a2 = func0(0);
result = 2LL;
break;
case 'u':
if ( v4 )
{
v7 = my_strlen(v4->pw_name);
v8 = v4->pw_name;
}
else
{
v7 = my_strlen(&unk_46E);
v8 = (char *)&unk_46E;
}
*a2 = write(1, v8, v7);
result = 2LL;
break;
case '/':
*a2 = func1();
result = 2LL;
break;
default:
*a2 = write(1, &unk_472, 1uLL);
result = 1LL;
break;
}
return result;
}

original_code:
static size_t interpret(char *s, int *add)
{
  register struct passwd *pw;
  register uid_t uid;
  uid = getuid();
  pw = getpwuid(uid);
  if (s[1] == 'd')
    *add = date_and_time(1);
  else if (s[1] == 'h')
    *add = date_and_time(0);
  else if (s[1] == 'u')
    *add = write(1, (pw) ? (pw->pw_name) : ("✗"),
   my_strlen((pw) ? (pw->pw_name) : ("✗")));
  else if (s[1] == '/')
    *add = put_dir();
  else
    {
      *add = write(1, "%", 1);
      return (1);
    }
  return (2);
}

canonical_original_code:
static unsigned long interpret(char *s, int *add)
{
  register struct passwd *pw;
  register unsigned int uid;
  uid = getuid();
  pw = getpwuid(uid);
  if (s[1] == 'd')
    *add = date_and_time(1);
  else if (s[1] == 'h')
    *add = date_and_time(0);
  else if (s[1] == 'u')
    *add = write(1, (pw) ? (pw->pw_name) : ("✗"),
   my_strlen((pw) ? (pw->pw_name) : ("✗")));
  else if (s[1] == '/')
    *add = put_dir();
  else
    {
      *add = write(1, "%", 1);
      return (1);
    }
  return (2);
}

variable_types:
add
int *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types:
uid
unsigned int


decompiled_code:
__int64 __fastcall inter_prompt(char *a1, unsigned __int64 a2, unsigned __int64 a3, unsigned int a4)
{
__int64 result; // rax
__int64 v8; // rax
char v9; // al
unsigned __int64 v10; // r14
unsigned __int64 v11; // r14
__int64 v12; // rdi
__int64 v13; // r14
char v14; // [rsp+Bh] [rbp-2Dh] BYREF
int v15[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( !a2 || (result = 0LL, a2 > a3) )
{
result = 0LL;
if ( *a1 )
{
v8 = my_strlen(&unk_474);
if ( !(unsigned int)my_strncmp(&unk_474, a1, v8) || *a1 == 27 )
{
v10 = my_strilen(a1, 91LL);
if ( v10 < my_strilen(a1, 109LL) )
{
v11 = my_strilen(a1, 109LL);
if ( v11 < my_strslen(a1 + 1, &unk_474) + 1 )
a4 = 1;
}
}
v9 = *a1;
if ( *a1 == 109 )
{
a4 = 0;
}
else
{
if ( v9 == 91 && a4 == 1 )
{
v15[0] = -2;
v14 = 0;
a4 = 2;
goto LABEL_20;
}
if ( a4 == 2 )
{
v15[0] = 0;
goto LABEL_19;
}
}
v15[0] = 1;
LABEL_19:
v14 = 0;
if ( v9 == 37 )
{
v12 = interpret((__int64)a1, v15);
LABEL_21:
result = 0LL;
if ( !v14 )
{
v13 = v15[0];
result = v13 + inter_prompt(&a1[v12], a2, v12 + a3, a4);
}
return result;
}
LABEL_20:
v12 = print_seq(a1, 3LL, &v14);
goto LABEL_21;
}
}
return result;
}

original_code:
static size_t inter_prompt(char *s, size_t h, size_t n, int is_color)
{
  int add;
  unsigned char end;
  size_t next;
  if ((h && n >= h) || !s[0])
    return (0);
  if ((((("\\0") && (s)) ? (!my_strncmp(("\\0"), (s), my_strlen("\\0"))) : (0)) || s[0] == 27) && my_strilen(s, '[') <
      my_strilen(s, 'm') && my_strilen(s, 'm') < 1 + my_strslen(s + 1, "\\0"))
    is_color = 1;
  if (s[0] == 'm')
    is_color = 0;
  if (is_color == 1 && s[0] == '[')
    add = -((is_color = 2));
  else if (is_color == 2)
    add = 0;
  else
    add = 1;
  end = 0;
  if (s[0] == '%')
    next = interpret(s, &add);
  else
    next = print_seq(s, 3, &end);
  if (end)
    return (0);
  return (add + inter_prompt((s + next), h, n + next, is_color));
}

canonical_original_code:
static unsigned long inter_prompt(char *s, unsigned long h, unsigned long n, int is_color)
{
  int add;
  unsigned char end;
  unsigned long next;
  if ((h && n >= h) || !s[0])
    return (0);
  if ((((("\\0") && (s)) ? (!my_strncmp(("\\0"), (s), my_strlen("\\0"))) : (0)) || s[0] == 27) && my_strilen(s, '[') <
      my_strilen(s, 'm') && my_strilen(s, 'm') < 1 + my_strslen(s + 1, "\\0"))
    is_color = 1;
  if (s[0] == 'm')
    is_color = 0;
  if (is_color == 1 && s[0] == '[')
    add = -((is_color = 2));
  else if (is_color == 2)
    add = 0;
  else
    add = 1;
  end = 0;
  if (s[0] == '%')
    next = interpret(s, &add);
  else
    next = print_seq(s, 3, &end);
  if (end)
    return (0);
  return (add + inter_prompt((s + next), h, n + next, is_color));
}

variable_types:
h
unsigned long

variable_types: add int

variable_types:
end
unsigned char

variable_types:
next
unsigned long


prompt

decompiled_code:
__int64 __fastcall prompt(char a1)
{
char *v1; // rbx
unsigned __int64 v2; // rbp
__int64 v3; // rbp
__int64 v4; // rax
__int64 result; // rax
unsigned __int64 v6; // rbp
__int64 v7; // rbp
__int64 v8; // rbp
__int64 v9; // rdx
__int64 v10; // rbp
__int64 v11; // rax

v1 = (char *)get_env("PS1");
if ( !v1 )
v1 = "------>Prompt test\n[Sla.sh] ";
if ( !a1 )
{
v6 = last_soccur(v1, "\\n");
if ( v6 >= last_occur(v1, 10LL, 0LL) )
{
v8 = last_soccur(v1, "\\n");
v1 += 2 * (v1[my_strslen(v1, "\\n")] != 0) + v8;
}
else
{
v7 = last_occur(v1, 10LL, 0LL);
v1 += v7 - ((v1[my_strilen(v1, 10LL)] == 0) - 1LL);
}
goto LABEL_5;
}
if ( v1[my_strilen(v1, 10LL)] || (v9 = my_strslen(v1, "\\n"), result = 0LL, v1[v9]) )
{
LABEL_5:
v2 = last_soccur(v1, "\\n");
if ( v2 >= last_occur(v1, 10LL, 0LL) )
{
v10 = last_soccur(v1, "\\n");
v11 = my_strslen(v1, "\\n");
result = inter_prompt(v1, v10 + 2LL * (v1[v11] != 0), 0LL, 0);
}
else
{
v3 = last_occur(v1, 10LL, 0LL);
v4 = my_strilen(v1, 10LL);
result = inter_prompt(v1, v3 - ((v1[v4] == 0) - 1LL), 0LL, 0);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
char *v1; // rbx
unsigned __int64 v2; // rbp
__int64 v3; // rbp
__int64 v4; // rax
__int64 result; // rax
unsigned __int64 v6; // rbp
__int64 v7; // rbp
__int64 v8; // rbp
__int64 v9; // rdx
__int64 v10; // rbp
__int64 v11; // rax

v1 = (char *)get_env("PS1");
if ( !v1 )
v1 = "------>Prompt test\n[Sla.sh] ";
if ( !a1 )
{
v6 = last_soccur(v1, "\\n");
if ( v6 >= last_occur(v1, 10LL, 0LL) )
{
v8 = last_soccur(v1, "\\n");
v1 += 2 * (v1[my_strslen(v1, "\\n")] != 0) + v8;
}
else
{
v7 = last_occur(v1, 10LL, 0LL);
v1 += v7 - ((v1[my_strilen(v1, 10LL)] == 0) - 1LL);
}
goto LABEL_5;
}
if ( v1[my_strilen(v1, 10LL)] || (v9 = my_strslen(v1, "\\n"), result = 0LL, v1[v9]) )
{
LABEL_5:
v2 = last_soccur(v1, "\\n");
if ( v2 >= last_occur(v1, 10LL, 0LL) )
{
v10 = last_soccur(v1, "\\n");
v11 = my_strslen(v1, "\\n");
result = func3(v1, v10 + 2LL * (v1[v11] != 0), 0LL, 0);
}
else
{
v3 = last_occur(v1, 10LL, 0LL);
v4 = my_strilen(v1, 10LL);
result = func3(v1, v3 - ((v1[v4] == 0) - 1LL), 0LL, 0);
}
}
return result;
}

original_code:
size_t prompt(unsigned char b)
{
  char *p;
  p = get_env("PS1");
  if (!p)
    p = "------>Prompt test\n[Sla.sh] ";
  if (!b)
    {
      if (last_soccur(p, "\\n") < last_occur(p, '\n', 0))
 p += last_occur(p, '\n', 0) + ((p)[my_strilen(p, '\n')] != 0);
      else
 p += last_soccur(p, "\\n") + ((p)[my_strslen(p, "\\n")] != 0) * 2;
    }
  if (b && !((p)[my_strilen(p, '\n')] != 0) && !((p)[my_strslen(p, "\\n")] != 0))
    return (0);
  if (last_soccur(p, "\\n") < last_occur(p, '\n', 0))
    return (inter_prompt(p, last_occur(p, '\n', 0) + ((p)[my_strilen(p, '\n')] != 0), 0, 0));
  else
    return (inter_prompt(p, last_soccur(p, "\\n") + ((p)[my_strslen(p, "\\n")] != 0) * 2, 0, 0));
}

canonical_original_code:
unsigned long prompt(unsigned char b)
{
  char *p;
  p = get_env("PS1");
  if (!p)
    p = "------>Prompt test\n[Sla.sh] ";
  if (!b)
    {
      if (last_soccur(p, "\\n") < last_occur(p, '\n', 0))
 p += last_occur(p, '\n', 0) + ((p)[my_strilen(p, '\n')] != 0);
      else
 p += last_soccur(p, "\\n") + ((p)[my_strslen(p, "\\n")] != 0) * 2;
    }
  if (b && !((p)[my_strilen(p, '\n')] != 0) && !((p)[my_strslen(p, "\\n")] != 0))
    return (0);
  if (last_soccur(p, "\\n") < last_occur(p, '\n', 0))
    return (inter_prompt(p, last_occur(p, '\n', 0) + ((p)[my_strilen(p, '\n')] != 0), 0, 0));
  else
    return (inter_prompt(p, last_soccur(p, "\\n") + ((p)[my_strslen(p, "\\n")] != 0) * 2, 0, 0));
}

variable_types:
b
unsigned char

variable_types:
p
char *


decompiled_code:
__int64 open_it()
{
__int64 v0; // rax
char *v1; // rbx
unsigned int v2; // ebp

v0 = get_env("HOME");
v1 = (char *)my_strcat(v0, ".Slashrc");
v2 = open(v1, 0);
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
char *v1; // rbx
unsigned int v2; // ebp

v0 = get_env("HOME");
v1 = (char *)my_strcat(v0, ".Slashrc");
v2 = open(v1, 0);
free(v1);
return v2;
}

original_code:
static int open_it(void)
{
  int file;
  char *name;
  name = my_strcat(get_env("HOME"), ".Slashrc");
  file = open(name, 00);
  free(name);
  return (file);
}

canonical_original_code:
static int open_it()
{
  int file;
  char *name;
  name = my_strcat(get_env("HOME"), ".Slashrc");
  file = open(name, 00);
  free(name);
  return (file);
}

variable_types: file int

variable_types:
name
char *


decompiled_code:
__int64 __fastcall export_env(__int64 a1, unsigned int a2)
{
__int64 result; // rax
void *v3; // [rsp+0h] [rbp-18h] BYREF
void *ptr; // [rsp+8h] [rbp-10h] BYREF

result = fill_it(a1, (const char **)&ptr, &v3, a2);
if ( (_BYTE)result )
{
set_env(ptr, v3);
free(ptr);
free(v3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
__int64 result; // rax
void *v3; // [rsp+0h] [rbp-18h] BYREF
void *ptr; // [rsp+8h] [rbp-10h] BYREF

result = func1(a1, (const char **)&ptr, &v3, a2);
if ( (_BYTE)result )
{
set_env(ptr, v3);
free(ptr);
free(v3);
result = 1LL;
}
return result;
}

original_code:
static unsigned char export_env(char *s, int no)
{
  char *s1;
  char *s2;
  if (fill_it(s, &s1, &s2, no) == 0)
    return (0);
  set_env(s1, s2);
  free(s1);
  free(s2);
  return (1);
}

variable_types:
s
char *

variable_types: no int


decompiled_code:
char __fastcall export_alias(__int64 a1, __int64 *a2, unsigned int a3)
{
char result; // al
__int64 v5; // rbx
__int64 v6; // [rsp+0h] [rbp-28h] BYREF
void *ptr; // [rsp+8h] [rbp-20h] BYREF

result = fill_it(a1, (const char **)&ptr, &v6, a3);
if ( result )
{
if ( ptr && v6 || (printf("error at line %d\n", a3), result = 0, ptr) && v6 )
{
v5 = *a2;
if ( *a2 )
{
while ( !*(_QWORD *)v5 || !ptr || (unsigned int)my_strcmp() )
{
v5 = *(_QWORD *)(v5 + 16);
if ( !v5 )
goto LABEL_5;
}
free(*(void **)(v5 + 16));
*(_QWORD *)(v5 + 8) = v6;
free(ptr);
result = 0;
}
else
{
LABEL_5:
result = (unsigned int)mod_alias(ptr, v6, a2) == 0;
}
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func3(__int64 a1, __int64 *a2, unsigned int a3)
{
char result; // al
__int64 v5; // rbx
__int64 v6; // [rsp+0h] [rbp-28h] BYREF
void *ptr; // [rsp+8h] [rbp-20h] BYREF

result = func1(a1, (const char **)&ptr, &v6, a3);
if ( result )
{
if ( ptr && v6 || (printf("error at line %d\n", a3), result = 0, ptr) && v6 )
{
v5 = *a2;
if ( *a2 )
{
while ( !*(_QWORD *)v5 || !ptr || (unsigned int)my_strcmp() )
{
v5 = *(_QWORD *)(v5 + 16);
if ( !v5 )
goto LABEL_5;
}
free(*(void **)(v5 + 16));
*(_QWORD *)(v5 + 8) = v6;
free(ptr);
result = 0;
}
else
{
LABEL_5:
result = (unsigned int)mod_alias(ptr, v6, a2) == 0;
}
}
}
return result;
}

original_code:
static unsigned char export_alias(char *s, t_alias **alias, int no)
{
  t_alias *link;
  unsigned char c;
  char *s1;
  char *s2;
  if (fill_it(s, &s1, &s2, no) == 0)
    return (0);
  if (!s1 || !s2)
    printf("error at line %d\n", no);
  if (!s1 || !s2)
    return (0);
  link = *alias + (unsigned int)(c = 0);
  while (link && !c)
    if (((link->name && s1) ? (!my_strcmp(link->name, s1)) : (0)))
      c = 1;
    else
      link = link->next;
  if (!c)
    return (!mod_alias(s1, s2, alias));
  free(link->next);
  link->fill = s2;
  free(s1);
  return (0);
}

canonical_original_code:
static unsigned char export_alias(char *s, struct s_alias **alias, int no)
{
  struct s_alias *link;
  unsigned char c;
  char *s1;
  char *s2;
  if (fill_it(s, &s1, &s2, no) == 0)
    return (0);
  if (!s1 || !s2)
    printf("error at line %d\n", no);
  if (!s1 || !s2)
    return (0);
  link = *alias + (unsigned int)(c = 0);
  while (link && !c)
    if (((link->name && s1) ? (!my_strcmp(link->name, s1)) : (0)))
      c = 1;
    else
      link = link->next;
  if (!c)
    return (!mod_alias(s1, s2, alias));
  free(link->next);
  link->fill = s2;
  free(s1);
  return (0);
}

variable_types: struct s_alias { char *name; char *fill; struct s_alias *next; struct s_alias *prev; unsigned long w; unsigned long n; } **

variable_types:
c
unsigned char


decompiled_code:
__int64 __fastcall scan_export(__int64 *a1)
{
__int64 result; // rax
unsigned int v2; // er13
char v3; // bp
unsigned int i; // er12
__int64 v5; // rax
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rbx
__int64 v10; // rax
__int64 v11; // rbp
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax

result = open_it();
if ( (_DWORD)result != -1 )
{
v2 = result;
v3 = 1;
for ( i = 0; ; ++i )
{
result = get_next_line(v2);
v9 = result;
if ( !v3 || !result )
break;
v10 = my_strlen("export");
if ( (unsigned int)my_strncmp("export", v9, v10) )
{
v5 = my_strlen("alias");
if ( (unsigned int)my_strncmp("alias", v9, v5) )
{
v14 = my_strilen(v9, 35LL);
result = nempty(v9, v14);
if ( !(_BYTE)result )
return result;
}
else
{
v6 = my_strlen("export");
v7 = my_strlen("export");
v8 = hempty(v9 + v7);
v3 = export_alias(v9 + v6 + v8, a1, i);
}
}
else
{
v11 = my_strlen("export");
v12 = my_strlen("export");
v13 = hempty(v9 + v12);
v3 = export_env(v9 + v11 + v13, i);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
__int64 result; // rax
unsigned int v2; // er13
char v3; // bp
unsigned int i; // er12
__int64 v5; // rax
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rbx
__int64 v10; // rax
__int64 v11; // rbp
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax

result = func0();
if ( (_DWORD)result != -1 )
{
v2 = result;
v3 = 1;
for ( i = 0; ; ++i )
{
result = get_next_line(v2);
v9 = result;
if ( !v3 || !result )
break;
v10 = my_strlen("export");
if ( (unsigned int)my_strncmp("export", v9, v10) )
{
v5 = my_strlen("alias");
if ( (unsigned int)my_strncmp("alias", v9, v5) )
{
v14 = my_strilen(v9, 35LL);
result = nempty(v9, v14);
if ( !(_BYTE)result )
return result;
}
else
{
v6 = my_strlen("export");
v7 = my_strlen("export");
v8 = hempty(v9 + v7);
v3 = func3(v9 + v6 + v8, a1, i);
}
}
else
{
v11 = my_strlen("export");
v12 = my_strlen("export");
v13 = hempty(v9 + v12);
v3 = func2(v9 + v11 + v13, i);
}
}
}
return result;
}

original_code:
void scan_export(t_alias **alias)
{
  int no;
  unsigned char c;
  char *s;
  int file;
  c = 1;
  no = 0;
  if ((file = open_it()) == -1)
    return ;
  while ((s = get_next_line(file)) != ((void *)0) && c)
    {
      if (((("export") && (s)) ? (!my_strncmp(("export"), (s), my_strlen("export"))) : (0)))
 c = export_env(s + my_strlen("export")
         + hempty(s + my_strlen("export")), no);
      else if (((("alias") && (s)) ? (!my_strncmp(("alias"), (s), my_strlen("alias"))) : (0)))
 c = export_alias(s + my_strlen("export")
    + hempty(s + my_strlen("export")),
    alias, no);
      else if (!nempty(s, my_strilen(s, '#')))
 return ;
      no++;
    }
}

canonical_original_code:
void scan_export(struct s_alias **alias)
{
  int no;
  unsigned char c;
  char *s;
  int file;
  c = 1;
  no = 0;
  if ((file = open_it()) == -1)
    return ;
  while ((s = get_next_line(file)) != ((void *)0) && c)
    {
      if (((("export") && (s)) ? (!my_strncmp(("export"), (s), my_strlen("export"))) : (0)))
 c = export_env(s + my_strlen("export")
         + hempty(s + my_strlen("export")), no);
      else if (((("alias") && (s)) ? (!my_strncmp(("alias"), (s), my_strlen("alias"))) : (0)))
 c = export_alias(s + my_strlen("export")
    + hempty(s + my_strlen("export")),
    alias, no);
      else if (!nempty(s, my_strilen(s, '#')))
 return ;
      no++;
    }
}

user_defined_types: struct s_alias { char *name; char *fill; struct s_alias *next; struct s_alias *prev; unsigned long w; unsigned long n; }


decompiled_code:
__int64 __fastcall fill_it(__int64 a1, const char **a2, _QWORD *a3, unsigned int a4)
{
int v6; // eax
__int64 v7; // rbp
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // r15
__int64 v12; // rdx
_BOOL4 v13; // eax
char *v14; // rbx
char v15; // r15
__int64 v16; // rax
__int64 v17; // rbp
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rdx
__int64 v21; // rbp
__int64 v22; // rax

*a2 = 0LL;
*a3 = 0LL;
v6 = ((__int64 (*)(void))empty)();
LODWORD(v7) = 0;
if ( !(_BYTE)v6 )
{
LODWORD(v7) = v6;
v9 = my_sstrlen(a1, "= \t");
v10 = my_strndup(a1, v9);
*a2 = (const char *)v10;
if ( v10 )
{
v11 = my_sstrlen(a1, "= \t");
v12 = my_strilen(a1, 61LL);
v13 = 1;
if ( !*(_BYTE *)(a1 + v12) )
{
v20 = my_strilen(a1, 32LL);
v13 = 1;
if ( !*(_BYTE *)(a1 + v20) )
v13 = *(_BYTE *)(a1 + my_strilen(a1, 9LL)) != 0;
}
v14 = (char *)(v13 + v11 + a1);
v15 = *v14;
if ( asc_511[my_strilen("\"'", (unsigned int)*v14)] && !v14[my_strilen(v14 + 1, (unsigned int)*v14) + 1] )
printf("error in conf file at line #%d, in %s definition\n", a4, *a2);
if ( !asc_511[my_strilen("\"'", (unsigned int)*v14)] || v14[my_strilen(v14 + 1, (unsigned int)*v14) + 1] )
{
if ( !asc_514[my_strilen("'\"", (unsigned int)*v14)] )
v15 = 0;
v16 = my_strilen("'\"", (unsigned int)*v14);
v17 = my_strilen(&v14[-(asc_514[v16] == 0) + 1], (unsigned int)v15);
v18 = my_strilen("'\"", (unsigned int)*v14);
*a3 = my_strndup(&v14[-(asc_514[v18] == 0) + 1], v17);
if ( asc_514[my_strilen("'\"", (unsigned int)*v14)] )
{
v21 = my_strlen(*a3);
v22 = my_strilen("'\"", (unsigned int)*v14);
if ( !(unsigned __int8)empty(&v14[2 * (asc_514[v22] != 0) + v21]) )
printf("error in conf file at line #%d, in %s definition\n", a4, *a2);
}
LODWORD(v7) = 1;
if ( asc_514[my_strilen("'\"", (unsigned int)*v14)] )
{
v7 = my_strlen(*a3);
v19 = my_strilen("'\"", (unsigned int)*v14);
LOBYTE(v7) = (unsigned __int8)empty(&v14[2 * (asc_514[v19] != 0) + v7]) != 0;
}
}
}
else
{
LODWORD(v7) = 1;
}
}
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char **a2, _QWORD *a3, unsigned int a4)
{
int v6; // eax
__int64 v7; // rbp
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // r15
__int64 v12; // rdx
_BOOL4 v13; // eax
char *v14; // rbx
char v15; // r15
__int64 v16; // rax
__int64 v17; // rbp
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rdx
__int64 v21; // rbp
__int64 v22; // rax

*a2 = 0LL;
*a3 = 0LL;
v6 = ((__int64 (*)(void))empty)();
LODWORD(v7) = 0;
if ( !(_BYTE)v6 )
{
LODWORD(v7) = v6;
v9 = my_sstrlen(a1, "= \t");
v10 = my_strndup(a1, v9);
*a2 = (const char *)v10;
if ( v10 )
{
v11 = my_sstrlen(a1, "= \t");
v12 = my_strilen(a1, 61LL);
v13 = 1;
if ( !*(_BYTE *)(a1 + v12) )
{
v20 = my_strilen(a1, 32LL);
v13 = 1;
if ( !*(_BYTE *)(a1 + v20) )
v13 = *(_BYTE *)(a1 + my_strilen(a1, 9LL)) != 0;
}
v14 = (char *)(v13 + v11 + a1);
v15 = *v14;
if ( asc_511[my_strilen("\"'", (unsigned int)*v14)] && !v14[my_strilen(v14 + 1, (unsigned int)*v14) + 1] )
printf("error in conf file at line #%d, in %s definition\n", a4, *a2);
if ( !asc_511[my_strilen("\"'", (unsigned int)*v14)] || v14[my_strilen(v14 + 1, (unsigned int)*v14) + 1] )
{
if ( !asc_514[my_strilen("'\"", (unsigned int)*v14)] )
v15 = 0;
v16 = my_strilen("'\"", (unsigned int)*v14);
v17 = my_strilen(&v14[-(asc_514[v16] == 0) + 1], (unsigned int)v15);
v18 = my_strilen("'\"", (unsigned int)*v14);
*a3 = my_strndup(&v14[-(asc_514[v18] == 0) + 1], v17);
if ( asc_514[my_strilen("'\"", (unsigned int)*v14)] )
{
v21 = my_strlen(*a3);
v22 = my_strilen("'\"", (unsigned int)*v14);
if ( !(unsigned __int8)empty(&v14[2 * (asc_514[v22] != 0) + v21]) )
printf("error in conf file at line #%d, in %s definition\n", a4, *a2);
}
LODWORD(v7) = 1;
if ( asc_514[my_strilen("'\"", (unsigned int)*v14)] )
{
v7 = my_strlen(*a3);
v19 = my_strilen("'\"", (unsigned int)*v14);
LOBYTE(v7) = (unsigned __int8)empty(&v14[2 * (asc_514[v19] != 0) + v7]) != 0;
}
}
}
else
{
LODWORD(v7) = 1;
}
}
return (unsigned int)v7;
}

variable_types: get char