decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
char *v4; // r12
int v5; // eax
int v6; // eax
int v7; // ebx
int v8; // eax
unsigned int v9; // eax
FILE *v10; // rbp
int v11; // eax
int v12; // eax
signed int v13; // eax
int v14; // er12
int v15; // eax
struct pollfd fds; // [rsp+8h] [rbp-10070h] BYREF
struct timeval tv; // [rsp+10h] [rbp-10068h] BYREF
int v18[4]; // [rsp+20h] [rbp-10058h] BYREF
int ptr; // [rsp+30h] [rbp-10048h] BYREF
__int16 v20; // [rsp+34h] [rbp-10044h]
__int16 v21; // [rsp+36h] [rbp-10042h]
int v22; // [rsp+38h] [rbp-10040h]
int v23; // [rsp+3Ch] [rbp-1003Ch]
int v24; // [rsp+40h] [rbp-10038h]
int v25; // [rsp+44h] [rbp-10034h]
char buf[65576]; // [rsp+50h] [rbp-10028h] BYREF

v3 = 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "i:f:h");
if ( v5 == -1 )
break;
if ( v5 == 102 )
{
v3 = optarg;
}
else
{
if ( v5 != 105 )
{
printf(
"usage: mkap [-f filename] [-i interface]\n"
"\t-i: specify a specific interface to listen. if not specified capture all ethernet traffic.\n"
"\t-f: specify a file to dump the traffic. if not specified, listen for a tcp connection from\n"
"\t port %d and dump the traffic to that connection\n",
54321LL);
exit(0);
}
v4 = optarg;
}
}
v6 = create_capture_socket(v4);
v7 = v6;
if ( v6 >= 0 )
{
ptr = -1582119980;
v20 = 2;
v21 = 4;
v22 = 0;
v23 = 0;
v24 = 0xFFFF;
v8 = get_arptype(v4, v6);
switch ( v8 )
{
case 1:
puts("linktype: ARPHRD_ETHER");
v25 = 1;
break;
case 512:
puts("linktype: ARPHRD_PPP");
v25 = 12;
break;
case -1:
puts("cannot get interface arp type");
exit(1);
default:
v9 = get_arptype(v4, v7);
printf("unsupported linktype %d\n", v9);
exit(1);
}
if ( v3 )
{
v10 = fopen(v3, "wb");
}
else
{
attach_mkap_conn_filter(v7, v25);
v11 = get_tcp_sock();
if ( v11 < 0 )
{
puts("get_tcp_sock() failed");
exit(1);
}
v10 = fdopen(v11, "wb");
}
if ( v10 )
{
if ( fwrite(&ptr, 1uLL, 0x18uLL, v10) != 24 )
{
puts("error on writing PCAP file header");
exit(1);
}
fflush(v10);
signal(2, signal_handler);
fds.fd = v7;
fds.events = 1;
while ( !signal_interrupt )
{
v12 = poll(&fds, 1uLL, 1000);
if ( v12 )
{
if ( v12 < 0 )
{
if ( *_errno_location() != 4 )
{
perror("main: poll():");
exit(1);
}
}
else
{
if ( (fds.revents & 1) == 0 )
{
fwrite("Unexpected behaviour\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
v13 = read(v7, buf, 0x10000uLL);
v14 = v13;
if ( v13 < 0 )
{
v15 = *_errno_location();
if ( v15 != 4 && v15 != 11 )
{
perror("read():");
exit(1);
}
}
else
{
if ( !v13 )
{
puts("raw socket closed");
exit(0);
}
if ( v3 || !check_mkap_conn((__int64)buf, v13, v25) )
{
if ( gettimeofday(&tv, 0LL) < 0 )
{
perror("main: gettimeofday():");
exit(1);
}
v18[0] = tv.tv_sec;
v18[1] = tv.tv_usec;
v18[3] = v14;
v18[2] = v14;
if ( fwrite(v18, 1uLL, 0x10uLL, v10) != 16 )
{
puts("error on writing packet header");
exit(1);
}
if ( v14 != fwrite(buf, 1uLL, v14, v10) )
{
puts("error on writing to capture file");
exit(1);
}
fflush(v10);
}
}
}
}
}
fwrite("SIGINT received\n", 1uLL, 0x10uLL, stderr);
exit(1);
}
puts("Cannot open specified file");
exit(1);
}
puts("cannot open specified interface");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
char *v4; // r12
int v5; // eax
int v6; // eax
int v7; // ebx
int v8; // eax
unsigned int v9; // eax
FILE *v10; // rbp
int v11; // eax
int v12; // eax
signed int v13; // eax
int v14; // er12
int v15; // eax
struct pollfd fds; // [rsp+8h] [rbp-10070h] BYREF
struct timeval tv; // [rsp+10h] [rbp-10068h] BYREF
int v18[4]; // [rsp+20h] [rbp-10058h] BYREF
int ptr; // [rsp+30h] [rbp-10048h] BYREF
__int16 v20; // [rsp+34h] [rbp-10044h]
__int16 v21; // [rsp+36h] [rbp-10042h]
int v22; // [rsp+38h] [rbp-10040h]
int v23; // [rsp+3Ch] [rbp-1003Ch]
int v24; // [rsp+40h] [rbp-10038h]
int v25; // [rsp+44h] [rbp-10034h]
char buf[65576]; // [rsp+50h] [rbp-10028h] BYREF

v3 = 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "i:f:h");
if ( v5 == -1 )
break;
if ( v5 == 102 )
{
v3 = optarg;
}
else
{
if ( v5 != 105 )
{
printf(
"usage: mkap [-f filename] [-i interface]\n"
"\t-i: specify a specific interface to listen. if not specified capture all ethernet traffic.\n"
"\t-f: specify a file to dump the traffic. if not specified, listen for a tcp connection from\n"
"\t port %d and dump the traffic to that connection\n",
54321LL);
exit(0);
}
v4 = optarg;
}
}
v6 = func3(v4);
v7 = v6;
if ( v6 >= 0 )
{
ptr = -1582119980;
v20 = 2;
v21 = 4;
v22 = 0;
v23 = 0;
v24 = 0xFFFF;
v8 = func1(v4, v6);
switch ( v8 )
{
case 1:
puts("linktype: ARPHRD_ETHER");
v25 = 1;
break;
case 512:
puts("linktype: ARPHRD_PPP");
v25 = 12;
break;
case -1:
puts("cannot get interface arp type");
exit(1);
default:
v9 = func1(v4, v7);
printf("unsupported linktype %d\n", v9);
exit(1);
}
if ( v3 )
{
v10 = fopen(v3, "wb");
}
else
{
func5(v7, v25);
v11 = func6();
if ( v11 < 0 )
{
puts("get_tcp_sock() failed");
exit(1);
}
v10 = fdopen(v11, "wb");
}
if ( v10 )
{
if ( fwrite(&ptr, 1uLL, 0x18uLL, v10) != 24 )
{
puts("error on writing PCAP file header");
exit(1);
}
fflush(v10);
signal(2, signal_handler);
fds.fd = v7;
fds.events = 1;
while ( !signal_interrupt )
{
v12 = poll(&fds, 1uLL, 1000);
if ( v12 )
{
if ( v12 < 0 )
{
if ( *_errno_location() != 4 )
{
perror("main: poll():");
exit(1);
}
}
else
{
if ( (fds.revents & 1) == 0 )
{
fwrite("Unexpected behaviour\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
v13 = read(v7, buf, 0x10000uLL);
v14 = v13;
if ( v13 < 0 )
{
v15 = *_errno_location();
if ( v15 != 4 && v15 != 11 )
{
perror("read():");
exit(1);
}
}
else
{
if ( !v13 )
{
puts("raw socket closed");
exit(0);
}
if ( v3 || !func4((__int64)buf, v13, v25) )
{
if ( gettimeofday(&tv, 0LL) < 0 )
{
perror("main: gettimeofday():");
exit(1);
}
v18[0] = tv.tv_sec;
v18[1] = tv.tv_usec;
v18[3] = v14;
v18[2] = v14;
if ( fwrite(v18, 1uLL, 0x10uLL, v10) != 16 )
{
puts("error on writing packet header");
exit(1);
}
if ( v14 != fwrite(buf, 1uLL, v14, v10) )
{
puts("error on writing to capture file");
exit(1);
}
fflush(v10);
}
}
}
}
}
fwrite("SIGINT received\n", 1uLL, 0x10uLL, stderr);
exit(1);
}
puts("Cannot open specified file");
exit(1);
}
puts("cannot open specified interface");
exit(1);
}

original_code:
int main(int argc, char *argv[])
{
 int tap_fd, swap, arp_type, n;
 struct pcap_global_header gheader;
 struct pcap_packet_header pheader;
 unsigned char pktbuf[65536];
 if (fread(&gheader, 1, sizeof(gheader), stdin) != sizeof(gheader)) {
  perror("fread(gheader)");
  return -1;
 }
 if (gheader.magic == 0xA1B2C3D4) {
  swap = 0;
 } else if (gheader.magic == __bswap_32 (0xA1B2C3D4)) {
  swap = 1;
 } else {
  printf("bad magic\n");
  return -1;
 }
 if (swap) {
  gheader.magic = __bswap_32 (gheader.magic);
  gheader.version_major = __bswap_16 (gheader.version_major);
  gheader.version_minor = __bswap_16 (gheader.version_minor);
  gheader.thiszone = __bswap_32 (gheader.thiszone);
  gheader.snaplen = __bswap_32 (gheader.snaplen);
  gheader.linktype = __bswap_32 (gheader.linktype);
 }
 if (gheader.version_major != 2 || gheader.version_minor != 4) {
  printf("pcap version does not match\n");
  return -1;
 }
 switch (gheader.linktype) {
 case 1:
  arp_type = 1;
  break;
 case 12:
  arp_type = 512;
  break;
 case 105:
  arp_type = 801;
  break;
 case 119:
  arp_type = 802;
  break;
 case 127:
  arp_type = 803;
  break;
 default:
  printf("unrecognized linktype\n");
  return -1;
 }
 tap_fd = setup_tap_dev(arp_type);
 if (tap_fd < 0) {
  perror("setup_tap_dev()");
  return -1;
 }
 printf("interface setup complete. writing packets\n");
 for (;;) {
  if (fread(&pheader, 1, sizeof(pheader), stdin) != sizeof(pheader)) {
   perror("fread(pheader)");
   break;
  }
  if (swap) {
   pheader.ts_sec = __bswap_32 (pheader.ts_sec);
   pheader.ts_usec = __bswap_32 (pheader.ts_usec);
   pheader.incl_len = __bswap_32 (pheader.incl_len);
   pheader.orig_len = __bswap_32 (pheader.orig_len);
  }
  if (fread(pktbuf, 1, pheader.incl_len, stdin) != pheader.incl_len) {
   perror("fread(pkt)");
   break;
  }
  if (pheader.incl_len != pheader.orig_len) {
   printf("skipping short packet.\n");
   continue;
  }
  if ((n = write(tap_fd, pktbuf, pheader.incl_len)) != pheader.incl_len)
   fprintf(stderr, "write(): %d-%s\n", n, strerror((*__errno_location ())));
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int tap_fd; int swap; int arp_type; int n;
 struct pcap_global_header gheader;
 struct pcap_packet_header pheader;
 unsigned char pktbuf[65536];
 if (fread(&gheader, 1, sizeof(gheader), stdin) != sizeof(gheader)) {
  perror("fread(gheader)");
  return -1;
 }
 if (gheader.magic == 0xA1B2C3D4) {
  swap = 0;
 } else if (gheader.magic == __bswap_32 (0xA1B2C3D4)) {
  swap = 1;
 } else {
  printf("bad magic\n");
  return -1;
 }
 if (swap) {
  gheader.magic = __bswap_32 (gheader.magic);
  gheader.version_major = __bswap_16 (gheader.version_major);
  gheader.version_minor = __bswap_16 (gheader.version_minor);
  gheader.thiszone = __bswap_32 (gheader.thiszone);
  gheader.snaplen = __bswap_32 (gheader.snaplen);
  gheader.linktype = __bswap_32 (gheader.linktype);
 }
 if (gheader.version_major != 2 || gheader.version_minor != 4) {
  printf("pcap version does not match\n");
  return -1;
 }
 switch (gheader.linktype) {
 case 1:
  arp_type = 1;
  break;
 case 12:
  arp_type = 512;
  break;
 case 105:
  arp_type = 801;
  break;
 case 119:
  arp_type = 802;
  break;
 case 127:
  arp_type = 803;
  break;
 default:
  printf("unrecognized linktype\n");
  return -1;
 }
 tap_fd = setup_tap_dev(arp_type);
 if (tap_fd < 0) {
  perror("setup_tap_dev()");
  return -1;
 }
 printf("interface setup complete. writing packets\n");
 for (;;) {
  if (fread(&pheader, 1, sizeof(pheader), stdin) != sizeof(pheader)) {
   perror("fread(pheader)");
   break;
  }
  if (swap) {
   pheader.ts_sec = __bswap_32 (pheader.ts_sec);
   pheader.ts_usec = __bswap_32 (pheader.ts_usec);
   pheader.incl_len = __bswap_32 (pheader.incl_len);
   pheader.orig_len = __bswap_32 (pheader.orig_len);
  }
  if (fread(pktbuf, 1, pheader.incl_len, stdin) != pheader.incl_len) {
   perror("fread(pkt)");
   break;
  }
  if (pheader.incl_len != pheader.orig_len) {
   printf("skipping short packet.\n");
   continue;
  }
  if ((n = write(tap_fd, pktbuf, pheader.incl_len)) != pheader.incl_len)
   fprintf(stderr, "write(): %d-%s\n", n, strerror((*__errno_location ())));
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: swap int

variable_types: n int

variable_types: struct pcap_global_header { unsigned int magic; unsigned int version_major; unsigned int version_minor; int thiszone; unsigned int sigfigs; unsigned int snaplen; unsigned int linktype; }

variable_types: struct pcap_packet_header { unsigned int ts_sec; unsigned int ts_usec; unsigned int incl_len; unsigned int orig_len; }

variable_types:
pktbuf
unsigned char [65536]


repo: mustafakaraca/mkap

decompiled_code:
__int64 open_tap_dev()
{
int v0; // ebx
unsigned int v2; // eax
int v3; // eax
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

system("modprobe tun");
v0 = open("/dev/net/tun", 2);
if ( v0 < 0 )
{
v2 = getpid();
snprintf(v4, 0x20uLL, "/tmp/__tmp_tap_dev_%d", v2);
v3 = makedev(10LL, 200LL);
if ( mknod(v4, 0x21A4u, v3) )
{
perror("mknod()");
v0 = -1;
}
else
{
v0 = open(v4, 2);
unlink(v4);
}
}
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebx
unsigned int v2; // eax
int v3; // eax
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

system("modprobe tun");
v0 = open("/dev/net/tun", 2);
if ( v0 < 0 )
{
v2 = getpid();
snprintf(v4, 0x20uLL, "/tmp/__tmp_tap_dev_%d", v2);
v3 = makedev(10LL, 200LL);
if ( mknod(v4, 0x21A4u, v3) )
{
perror("mknod()");
v0 = -1;
}
else
{
v0 = open(v4, 2);
unlink(v4);
}
}
return (unsigned int)v0;
}

original_code:
static int open_tap_dev()
{
 int fd;
 char tmp_dev[32];
 system("modprobe tun");
 fd = open("/dev/net/tun", 02);
 if (fd >= 0)
  return fd;
 snprintf(tmp_dev, sizeof(tmp_dev), "/tmp/__tmp_tap_dev_%d", getpid());
 if (mknod(tmp_dev, 0644|0020000, makedev(10, 200))) {
  perror("mknod()");
  return -1;
 }
 fd = open(tmp_dev, 02);
 unlink(tmp_dev);
 return fd;
}

variable_types: fd int

return_type: int


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

if ( s_0 >= 0 )
return (unsigned int)s_0;
s_0 = socket(2, 2, 0);
if ( s_0 < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)s_0;
return result;
}

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

if ( s_0 >= 0 )
return (unsigned int)s_0;
s_0 = socket(2, 2, 0);
if ( s_0 < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)s_0;
return result;
}

original_code:
static int get_ioctl_sock()
{
 static int s = -1;
 if (s < 0) {
  s = socket(2, SOCK_DGRAM, 0);
  if (s < 0)
   return -1;
 }
 return s;
}

variable_types: s int


decompiled_code:
__int64 __fastcall setup_tap_dev(unsigned int a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned __int16 v3; // ax
char v5[16]; // [rsp+0h] [rbp-58h] BYREF
char src[8]; // [rsp+10h] [rbp-48h] BYREF
__int64 v7; // [rsp+18h] [rbp-40h]
__int64 v8; // [rsp+20h] [rbp-38h]
__int64 v9; // [rsp+28h] [rbp-30h]
__int64 v10; // [rsp+30h] [rbp-28h]

v1 = open_tap_dev();
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
*(_QWORD *)src = 0LL;
v7 = 0LL;
v9 = 0LL;
v10 = 0LL;
v3 = (a1 != 512) + 1;
HIBYTE(v3) |= 0x10u;
v8 = v3;
if ( ioctl(v2, 0x400454CAuLL, src) < 0 )
{
perror("ioctl(TUNSETIFF)");
LABEL_9:
close(v2);
return (unsigned int)-1;
}
printf("tap dev: %s opened\n", src);
strncpy(v5, src, 0xFuLL);
v5[15] = 0;
if ( (unsigned int)set_unset_dev_flags(v5, 1, 0) )
{
perror("set_unset_dev_flags(unset IFF_UP)");
goto LABEL_9;
}
if ( ioctl(v2, 0x400454CDuLL, a1) )
{
perror("ioctl(TUNSETLINK)");
goto LABEL_9;
}
if ( (unsigned int)set_unset_dev_flags(v5, 1, 1) )
{
perror("set_unset_dev_flags(set IFF_UP)");
goto LABEL_9;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned __int16 v3; // ax
char v5[16]; // [rsp+0h] [rbp-58h] BYREF
char src[8]; // [rsp+10h] [rbp-48h] BYREF
__int64 v7; // [rsp+18h] [rbp-40h]
__int64 v8; // [rsp+20h] [rbp-38h]
__int64 v9; // [rsp+28h] [rbp-30h]
__int64 v10; // [rsp+30h] [rbp-28h]

v1 = func1();
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
*(_QWORD *)src = 0LL;
v7 = 0LL;
v9 = 0LL;
v10 = 0LL;
v3 = (a1 != 512) + 1;
HIBYTE(v3) |= 0x10u;
v8 = v3;
if ( ioctl(v2, 0x400454CAuLL, src) < 0 )
{
perror("ioctl(TUNSETIFF)");
LABEL_9:
close(v2);
return (unsigned int)-1;
}
printf("tap dev: %s opened\n", src);
strncpy(v5, src, 0xFuLL);
v5[15] = 0;
if ( (unsigned int)func3(v5, 1, 0) )
{
perror("set_unset_dev_flags(unset IFF_UP)");
goto LABEL_9;
}
if ( ioctl(v2, 0x400454CDuLL, a1) )
{
perror("ioctl(TUNSETLINK)");
goto LABEL_9;
}
if ( (unsigned int)func3(v5, 1, 1) )
{
perror("set_unset_dev_flags(set IFF_UP)");
goto LABEL_9;
}
return v2;
}

original_code:
static int setup_tap_dev(int linktype)
{
 int fd;
 struct ifreq ifr;
 char ifname[16];
 fd = open_tap_dev();
 if (fd < 0)
  return -1;
 memset(&ifr, 0, sizeof(ifr));
 if (linktype == 512)
  ifr.ifr_ifru.ifru_flags = 0x0001;
 else
  ifr.ifr_ifru.ifru_flags = 0x0002;
 ifr.ifr_ifru.ifru_flags |= 0x1000;
 if (ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &ifr) < 0) {
  perror("ioctl(TUNSETIFF)");
  goto err;
 }
 printf("tap dev: %s opened\n", ifr.ifr_ifrn.ifrn_name);
 strncpy(ifname, ifr.ifr_ifrn.ifrn_name, 16 - 1);
 ifname[16 - 1] = 0;
 if (set_unset_dev_flags(ifname, IFF_UP, 0)) {
  perror("set_unset_dev_flags(unset IFF_UP)");
  goto err;
 }
 if (ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((205)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), linktype)) {
  perror("ioctl(TUNSETLINK)");
  goto err;
 }
 if (set_unset_dev_flags(ifname, IFF_UP, 1)) {
  perror("set_unset_dev_flags(set IFF_UP)");
  goto err;
 }
 return fd;
err:
 close(fd);
 return -1;
}

variable_types: linktype int

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto { unsigned short encoding; unsigned short parity; } *raw_hdlc; struct cisco_proto { unsigned int interval; unsigned int timeout; } *cisco; struct fr_proto { unsigned int t391; unsigned int t392; unsigned int n391; unsigned int n392; unsigned int n393; unsigned short lmi; unsigned short dce; } *fr; struct fr_proto_pvc { unsigned int dlci; } *fr_pvc; struct fr_proto_pvc_info { unsigned int dlci; char master[16]; } *fr_pvc_info; struct sync_serial_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; } *sync; struct te1_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; unsigned int slot_map; } *te1; } ifs_ifsu; } ifru_settings; } ifr_ifru; }

variable_types:
ifname
char [16]

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings ifru_settings; } ifr_ifru; }

user_defined_types: struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto *raw_hdlc; struct cisco_proto *cisco; struct fr_proto *fr; struct fr_proto_pvc *fr_pvc; struct fr_proto_pvc_info *fr_pvc_info; struct sync_serial_settings *sync; struct te1_settings *te1; } ifs_ifsu; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
int v4; // ebp
unsigned int v5; // edi
int result; // eax
int v7; // er12
size_t v8; // rcx
unsigned int v9; // ebx
int *v10; // rax
char *v11; // rax
_BYTE v12[65536]; // [rsp+0h] [rbp-10048h] BYREF
unsigned int v13; // [rsp+10000h] [rbp-48h] BYREF
unsigned int v14; // [rsp+10004h] [rbp-44h]
size_t n; // [rsp+10008h] [rbp-40h]
unsigned int ptr; // [rsp+10010h] [rbp-38h] BYREF
int v17; // [rsp+10014h] [rbp-34h]
unsigned int v18; // [rsp+10018h] [rbp-30h]
unsigned int v19; // [rsp+10020h] [rbp-28h]
unsigned int v20; // [rsp+10024h] [rbp-24h]

if ( fread(&ptr, 1uLL, 0x18uLL, stdin) != 24 )
{
perror("fread(gheader)");
return -1;
}
v3 = ptr;
if ( ptr == -1582119980 )
{
v4 = 0;
}
else
{
if ( v3 != (unsigned int)_bswap_32(0xA1B2C3D4) )
{
puts("bad magic");
return -1;
}
ptr = _bswap_32(v3);
LOWORD(v17) = _bswap_16(v17);
HIWORD(v17) = _bswap_16(SHIWORD(v17));
v18 = _bswap_32(v18);
v19 = _bswap_32(v19);
v20 = _bswap_32(v20);
v4 = 1;
}
if ( v17 != 262146 )
{
puts("pcap version does not match");
return -1;
}
if ( v20 == 105 )
{
v5 = 801;
}
else if ( v20 <= 0x69 )
{
if ( v20 == 1 )
{
v5 = 1;
}
else
{
if ( v20 != 12 )
goto LABEL_20;
v5 = 512;
}
}
else
{
if ( v20 != 119 )
{
if ( v20 == 127 )
{
v5 = 803;
goto LABEL_18;
}
LABEL_20:
puts("unrecognized linktype");
return -1;
}
v5 = 802;
}
LABEL_18:
v7 = setup_tap_dev(v5);
if ( v7 < 0 )
{
perror("setup_tap_dev()");
result = -1;
}
else
{
puts("interface setup complete. writing packets");
while ( 1 )
{
if ( fread(&v13, 1uLL, 0x10uLL, stdin) != 16 )
{
perror("fread(pheader)");
return 0;
}
if ( v4 )
{
v13 = _bswap_32(v13);
v14 = _bswap_32(v14);
LODWORD(n) = _bswap_32(n);
HIDWORD(n) = _bswap_32(HIDWORD(n));
}
v8 = fread(v12, 1uLL, (unsigned int)n, stdin);
if ( v8 != (unsigned int)n )
break;
if ( (_DWORD)n == HIDWORD(n) )
{
v9 = write(v7, v12, (unsigned int)n);
if ( (_DWORD)n != v9 )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "write(): %d-%s\n", v9, v11);
}
}
else
{
puts("skipping short packet.");
}
}
perror("fread(pkt)");
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
int v4; // ebp
unsigned int v5; // edi
int result; // eax
int v7; // er12
size_t v8; // rcx
unsigned int v9; // ebx
int *v10; // rax
char *v11; // rax
_BYTE v12[65536]; // [rsp+0h] [rbp-10048h] BYREF
unsigned int v13; // [rsp+10000h] [rbp-48h] BYREF
unsigned int v14; // [rsp+10004h] [rbp-44h]
size_t n; // [rsp+10008h] [rbp-40h]
unsigned int ptr; // [rsp+10010h] [rbp-38h] BYREF
int v17; // [rsp+10014h] [rbp-34h]
unsigned int v18; // [rsp+10018h] [rbp-30h]
unsigned int v19; // [rsp+10020h] [rbp-28h]
unsigned int v20; // [rsp+10024h] [rbp-24h]

if ( fread(&ptr, 1uLL, 0x18uLL, stdin) != 24 )
{
perror("fread(gheader)");
return -1;
}
v3 = ptr;
if ( ptr == -1582119980 )
{
v4 = 0;
}
else
{
if ( v3 != (unsigned int)func5(0xA1B2C3D4) )
{
puts("bad magic");
return -1;
}
ptr = func5(v3);
LOWORD(v17) = func0(v17);
HIWORD(v17) = func0(SHIWORD(v17));
v18 = func5(v18);
v19 = func5(v19);
v20 = func5(v20);
v4 = 1;
}
if ( v17 != 262146 )
{
puts("pcap version does not match");
return -1;
}
if ( v20 == 105 )
{
v5 = 801;
}
else if ( v20 <= 0x69 )
{
if ( v20 == 1 )
{
v5 = 1;
}
else
{
if ( v20 != 12 )
goto LABEL_20;
v5 = 512;
}
}
else
{
if ( v20 != 119 )
{
if ( v20 == 127 )
{
v5 = 803;
goto LABEL_18;
}
LABEL_20:
puts("unrecognized linktype");
return -1;
}
v5 = 802;
}
LABEL_18:
v7 = func4(v5);
if ( v7 < 0 )
{
perror("setup_tap_dev()");
result = -1;
}
else
{
puts("interface setup complete. writing packets");
while ( 1 )
{
if ( fread(&v13, 1uLL, 0x10uLL, stdin) != 16 )
{
perror("fread(pheader)");
return 0;
}
if ( v4 )
{
v13 = func5(v13);
v14 = func5(v14);
LODWORD(n) = func5(n);
HIDWORD(n) = func5(HIDWORD(n));
}
v8 = fread(v12, 1uLL, (unsigned int)n, stdin);
if ( v8 != (unsigned int)n )
break;
if ( (_DWORD)n == HIDWORD(n) )
{
v9 = write(v7, v12, (unsigned int)n);
if ( (_DWORD)n != v9 )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "write(): %d-%s\n", v9, v11);
}
}
else
{
puts("skipping short packet.");
}
}
perror("fread(pkt)");
result = 0;
}
return result;
}

user_defined_types: struct pcap_global_header { unsigned int magic; unsigned int version_major; unsigned int version_minor; int thiszone; unsigned int sigfigs; unsigned int snaplen; unsigned int linktype; }

user_defined_types: struct pcap_packet_header { unsigned int ts_sec; unsigned int ts_usec; unsigned int incl_len; unsigned int orig_len; }


height

repo: musto/Word-Counter

decompiled_code:
__int64 __fastcall height(__int64 a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 12);
return result;
}

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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 12);
return result;
}

original_code:
int height(struct avl_tree_node* node)
{
    return node ? node->height : 0;
}

canonical_original_code:
int height(struct avl_tree_node *node)
{
    return node ? node->height : 0;
}

variable_types: struct avl_tree_node { char *key; int value; int height; struct avl_tree_node *left; struct avl_tree_node *right; } *


original_code:
struct avl_tree_node* single_rotate_left(struct avl_tree_node* root)
{
    struct avl_tree_node* node = root->right;
    root->right = node->left;
    node->left = root;
    root->height = ( ((height(root->left)) > (height(root->right))) ? (height(root->left)) : (height(root->right)) ) + 1;
    node->height = ( ((height(node->left)) > (height(node->right))) ? (height(node->left)) : (height(node->right)) ) + 1;
    return node;
}

canonical_original_code:
struct avl_tree_node *single_rotate_left(struct avl_tree_node *root)
{
    struct avl_tree_node *node = root->right;
    root->right = node->left;
    node->left = root;
    root->height = ( ((height(root->left)) > (height(root->right))) ? (height(root->left)) : (height(root->right)) ) + 1;
    node->height = ( ((height(node->left)) > (height(node->right))) ? (height(node->left)) : (height(node->right)) ) + 1;
    return node;
}

variable_types:
root
struct avl_tree_node *

return_type: struct avl_tree_node { char *key; int value; int height; struct avl_tree_node *left; struct avl_tree_node *right; } *


original_code:
struct avl_tree_node* single_rotate_right(struct avl_tree_node* root)
{
    struct avl_tree_node* node = root->left;
    root->left = node->right;
    node->right = root;
    root->height = ( ((height(root->left)) > (height(root->right))) ? (height(root->left)) : (height(root->right)) ) + 1;
    node->height = ( ((height(node->left)) > (height(node->right))) ? (height(node->left)) : (height(node->right)) ) + 1;
    return node;
}

canonical_original_code:
struct avl_tree_node *single_rotate_right(struct avl_tree_node *root)
{
    struct avl_tree_node *node = root->left;
    root->left = node->right;
    node->right = root;
    root->height = ( ((height(root->left)) > (height(root->right))) ? (height(root->left)) : (height(root->right)) ) + 1;
    node->height = ( ((height(node->left)) > (height(node->right))) ? (height(node->left)) : (height(node->right)) ) + 1;
    return node;
}

user_defined_types: struct avl_tree_node { char *key; int value; int height; struct avl_tree_node *left; struct avl_tree_node *right; }


decompiled_code:
__int64 __fastcall rotate_right_left(__int64 a1)
{
*(_QWORD *)(a1 + 24) = single_rotate_right(*(_QWORD *)(a1 + 24));
return single_rotate_left(a1);
}

original_code:
struct avl_tree_node* rotate_right_left(struct avl_tree_node* root)
{
    root->right = single_rotate_right(root->right);
    return single_rotate_left(root);
}

canonical_original_code:
struct avl_tree_node *rotate_right_left(struct avl_tree_node *root)
{
    root->right = single_rotate_right(root->right);
    return single_rotate_left(root);
}


decompiled_code:
__int64 __fastcall rotate_left_right(__int64 a1)
{
*(_QWORD *)(a1 + 16) = single_rotate_left(*(_QWORD *)(a1 + 16));
return single_rotate_right(a1);
}

original_code:
struct avl_tree_node* rotate_left_right(struct avl_tree_node* root)
{
    root->left = single_rotate_left(root->left);
    return single_rotate_right(root);
}

canonical_original_code:
struct avl_tree_node *rotate_left_right(struct avl_tree_node *root)
{
    root->left = single_rotate_left(root->left);
    return single_rotate_right(root);
}


balance

decompiled_code:
__int64 __fastcall balance(__int64 a1)
{
__int64 result; // rax
int v2; // ebx

result = 0LL;
if ( a1 )
{
v2 = height(*(_QWORD *)(a1 + 16));
result = v2 - (unsigned int)height(*(_QWORD *)(a1 + 24));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 result; // rax
int v2; // ebx

result = 0LL;
if ( a1 )
{
v2 = func0(*(_QWORD *)(a1 + 16));
result = v2 - (unsigned int)func0(*(_QWORD *)(a1 + 24));
}
return result;
}

original_code:
int balance(struct avl_tree_node* node)
{
    return node ? height(node->left) - height(node->right) : 0;
}

canonical_original_code:
int balance(struct avl_tree_node *node)
{
    return node ? height(node->left) - height(node->right) : 0;
}


invariant

decompiled_code:
__int64 __fastcall invariant(__int64 a1)
{
int v1; // er13
__int64 v2; // rbp
int v3; // er14
__int64 v4; // r12
int v5; // eax
int v6; // edx
__int64 result; // rax
unsigned int v8; // edx

if ( !a1 )
return 0LL;
if ( *(_QWORD *)a1 )
{
v1 = *(_DWORD *)(a1 + 12);
v2 = *(_QWORD *)(a1 + 16);
v3 = height(v2);
v4 = *(_QWORD *)(a1 + 24);
v5 = height(v4);
v6 = v5 + 1;
if ( v3 > v5 )
v6 = v3 + 1;
result = 0LL;
if ( v1 == v6 )
{
v8 = balance(a1) + 1;
result = 0LL;
if ( v8 <= 2 )
{
if ( !v2 || (result = invariant(v2), (_DWORD)result) )
{
result = 1LL;
if ( v4 )
result = (unsigned int)invariant(v4) != 0;
}
}
}
}
else
{
result = *(unsigned int *)(a1 + 12);
if ( (_DWORD)result )
_assert_fail("0", "sources/avl_tree.c", 0x2Fu, "invariant");
if ( !*(_QWORD *)(a1 + 16) )
result = *(_QWORD *)(a1 + 24) == 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // er13
__int64 v2; // rbp
int v3; // er14
__int64 v4; // r12
int v5; // eax
int v6; // edx
__int64 result; // rax
unsigned int v8; // edx

if ( !a1 )
return 0LL;
if ( *(_QWORD *)a1 )
{
v1 = *(_DWORD *)(a1 + 12);
v2 = *(_QWORD *)(a1 + 16);
v3 = func0(v2);
v4 = *(_QWORD *)(a1 + 24);
v5 = func0(v4);
v6 = v5 + 1;
if ( v3 > v5 )
v6 = v3 + 1;
result = 0LL;
if ( v1 == v6 )
{
v8 = func5(a1) + 1;
result = 0LL;
if ( v8 <= 2 )
{
if ( !v2 || (result = func6(v2), (_DWORD)result) )
{
result = 1LL;
if ( v4 )
result = (unsigned int)func6(v4) != 0;
}
}
}
}
else
{
result = *(unsigned int *)(a1 + 12);
if ( (_DWORD)result )
_assert_fail("0", "sources/avl_tree.c", 0x2Fu, "invariant");
if ( !*(_QWORD *)(a1 + 16) )
result = *(_QWORD *)(a1 + 24) == 0LL;
}
return result;
}

original_code:
int invariant(struct avl_tree_node* node)
{
    if(!node) {
        return 0;
    }
    if(!node->key) {
        if(node->height != 0) {
            ((0) ? (void) (0) : __assert_fail ("0", "sources/avl_tree.c", 47, __extension__ __PRETTY_FUNCTION__));
        }
        if(node->left || node->right || node->height != 0) {
            return 0;
        }
        return 1;
    }
    if(node->height != ( ((height(node->left)) > (height(node->right))) ? (height(node->left)) : (height(node->right)) ) + 1) {
        return 0;
    }
    if(balance(node) > 1 || balance(node) < -1) {
        return 0;
    }
    return (!node->left || invariant(node->left)) && (!node->right || invariant(node->right));
}

canonical_original_code:
int invariant(struct avl_tree_node *node)
{
    if(!node) {
        return 0;
    }
    if(!node->key) {
        if(node->height != 0) {
            ((0) ? (void) (0) : __assert_fail ("0", "sources/avl_tree.c", 47, __extension__ __PRETTY_FUNCTION__));
        }
        if(node->left || node->right || node->height != 0) {
            return 0;
        }
        return 1;
    }
    if(node->height != ( ((height(node->left)) > (height(node->right))) ? (height(node->left)) : (height(node->right)) ) + 1) {
        return 0;
    }
    if(balance(node) > 1 || balance(node) < -1) {
        return 0;
    }
    return (!node->left || invariant(node->left)) && (!node->right || invariant(node->right));
}


decompiled_code:
__int64 __fastcall balance_update(__int64 a1)
{
int v1; // eax
__int64 v2; // rbp
int v4; // eax
int v5; // eax

v1 = balance(a1);
if ( (unsigned int)(v1 + 2) > 4 )
_assert_fail("bal >= -2 && bal <= 2", "sources/avl_tree.c", 0x73u, "balance_update");
if ( v1 == -2 )
{
v4 = balance(*(_QWORD *)(a1 + 24));
if ( v4 == -1 )
{
v2 = single_rotate_left(a1);
}
else
{
if ( v4 != 1 )
_assert_fail("bal_right == 1", "sources/avl_tree.c", 0x7Au, "balance_update");
v2 = rotate_right_left(a1);
}
}
else
{
v2 = a1;
if ( v1 == 2 )
{
v5 = balance(*(_QWORD *)(a1 + 16));
if ( v5 == 1 )
{
v2 = single_rotate_right(a1);
}
else
{
if ( v5 != -1 )
_assert_fail("bal_left == -1", "sources/avl_tree.c", 0x82u, "balance_update");
v2 = rotate_left_right(a1);
}
}
}
if ( !(unsigned int)invariant(v2) )
_assert_fail("invariant(new_root)", "sources/avl_tree.c", 0x87u, "balance_update");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // eax
__int64 v2; // rbp
int v4; // eax
int v5; // eax

v1 = func5(a1);
if ( (unsigned int)(v1 + 2) > 4 )
_assert_fail("bal >= -2 && bal <= 2", "sources/avl_tree.c", 0x73u, "balance_update");
if ( v1 == -2 )
{
v4 = func5(*(_QWORD *)(a1 + 24));
if ( v4 == -1 )
{
v2 = func1(a1);
}
else
{
if ( v4 != 1 )
_assert_fail("bal_right == 1", "sources/avl_tree.c", 0x7Au, "balance_update");
v2 = func3(a1);
}
}
else
{
v2 = a1;
if ( v1 == 2 )
{
v5 = func5(*(_QWORD *)(a1 + 16));
if ( v5 == 1 )
{
v2 = func2(a1);
}
else
{
if ( v5 != -1 )
_assert_fail("bal_left == -1", "sources/avl_tree.c", 0x82u, "balance_update");
v2 = func4(a1);
}
}
}
if ( !(unsigned int)func6(v2) )
_assert_fail("invariant(new_root)", "sources/avl_tree.c", 0x87u, "balance_update");
return v2;
}

original_code:
struct avl_tree_node* balance_update(struct avl_tree_node* node)
{
    struct avl_tree_node* new_root = node;
    int bal = balance(node);
    ((bal >= -2 && bal <= 2) ? (void) (0) : __assert_fail ("bal >= -2 && bal <= 2", "sources/avl_tree.c", 115, __extension__ __PRETTY_FUNCTION__));
    if(bal == -2) {
        int bal_right = balance(node->right);
        if(bal_right == -1) {
            new_root = single_rotate_left(node);
        } else {
            ((bal_right == 1) ? (void) (0) : __assert_fail ("bal_right == 1", "sources/avl_tree.c", 122, __extension__ __PRETTY_FUNCTION__));
            new_root = rotate_right_left(node);
        }
    } else if(bal == 2) {
        int bal_left = balance(node->left);
        if(bal_left == 1) {
            new_root = single_rotate_right(node);
        } else {
            ((bal_left == -1) ? (void) (0) : __assert_fail ("bal_left == -1", "sources/avl_tree.c", 130, __extension__ __PRETTY_FUNCTION__));
            new_root = rotate_left_right(node);
        }
    }
    ((invariant(new_root)) ? (void) (0) : __assert_fail ("invariant(new_root)", "sources/avl_tree.c", 135, __extension__ __PRETTY_FUNCTION__));
    return new_root;
}

canonical_original_code:
struct avl_tree_node *balance_update(struct avl_tree_node *node)
{
    struct avl_tree_node *new_root = node;
    int bal = balance(node);
    ((bal >= -2 && bal <= 2) ? (void) (0) : __assert_fail ("bal >= -2 && bal <= 2", "sources/avl_tree.c", 115, __extension__ __PRETTY_FUNCTION__));
    if(bal == -2) {
        int bal_right = balance(node->right);
        if(bal_right == -1) {
            new_root = single_rotate_left(node);
        } else {
            ((bal_right == 1) ? (void) (0) : __assert_fail ("bal_right == 1", "sources/avl_tree.c", 122, __extension__ __PRETTY_FUNCTION__));
            new_root = rotate_right_left(node);
        }
    } else if(bal == 2) {
        int bal_left = balance(node->left);
        if(bal_left == 1) {
            new_root = single_rotate_right(node);
        } else {
            ((bal_left == -1) ? (void) (0) : __assert_fail ("bal_left == -1", "sources/avl_tree.c", 130, __extension__ __PRETTY_FUNCTION__));
            new_root = rotate_left_right(node);
        }
    }
    ((invariant(new_root)) ? (void) (0) : __assert_fail ("invariant(new_root)", "sources/avl_tree.c", 135, __extension__ __PRETTY_FUNCTION__));
    return new_root;
}

variable_types:
node
struct avl_tree_node *

variable_types: bal int


decompiled_code:
_DWORD *avl_tree_create()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = malloc(0x20uLL);
v1 = v0;
if ( v0 )
{
v0[3] = 0;
*(_QWORD *)v0 = 0LL;
v0[2] = 0;
*((_QWORD *)v0 + 2) = 0LL;
*((_QWORD *)v0 + 3) = 0LL;
if ( !(unsigned int)invariant((__int64)v0) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0x51u, "avl_tree_create");
}
return v1;
}

canonical_decompiled_code:
_DWORD *func8()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = malloc(0x20uLL);
v1 = v0;
if ( v0 )
{
v0[3] = 0;
*(_QWORD *)v0 = 0LL;
v0[2] = 0;
*((_QWORD *)v0 + 2) = 0LL;
*((_QWORD *)v0 + 3) = 0LL;
if ( !(unsigned int)func6((__int64)v0) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0x51u, "avl_tree_create");
}
return v1;
}

original_code:
struct avl_tree_node* avl_tree_create()
{
    struct avl_tree_node* root = malloc(sizeof(struct avl_tree_node));
    if(!root) {
        return ((void *)0);
    }
    root->height = 0;
    root->key = ((void *)0);
    root->value = 0;
    root->left = ((void *)0);
    root->right = ((void *)0);
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 81, __extension__ __PRETTY_FUNCTION__));
    return root;
}

canonical_original_code:
struct avl_tree_node *avl_tree_create()
{
    struct avl_tree_node *root = malloc(sizeof(struct avl_tree_node));
    if(!root) {
        return ((void *)0);
    }
    root->height = 0;
    root->key = ((void *)0);
    root->value = 0;
    root->left = ((void *)0);
    root->right = ((void *)0);
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 81, __extension__ __PRETTY_FUNCTION__));
    return root;
}


decompiled_code:
void __fastcall avl_tree_destroy(__int64 a1)
{
if ( !(unsigned int)invariant(a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0x58u, "avl_tree_destroy");
if ( *(_QWORD *)(a1 + 24) )
avl_tree_destroy();
if ( *(_QWORD *)(a1 + 16) )
avl_tree_destroy();
if ( *(_QWORD *)a1 )
free(*(void **)a1);
free((void *)a1);
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
if ( !(unsigned int)func6(a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0x58u, "avl_tree_destroy");
if ( *(_QWORD *)(a1 + 24) )
func9();
if ( *(_QWORD *)(a1 + 16) )
func9();
if ( *(_QWORD *)a1 )
free(*(void **)a1);
free((void *)a1);
}

original_code:
void avl_tree_destroy(struct avl_tree_node* root)
{
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 88, __extension__ __PRETTY_FUNCTION__));
    if (root->right != ((void *)0)) {
        avl_tree_destroy(root->right);
    }
    if (root->left != ((void *)0)) {
        avl_tree_destroy(root->left);
    }
    if(root->key) {
        free(root->key);
    }
    free(root);
}

canonical_original_code:
void avl_tree_destroy(struct avl_tree_node *root)
{
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 88, __extension__ __PRETTY_FUNCTION__));
    if (root->right != ((void *)0)) {
        avl_tree_destroy(root->right);
    }
    if (root->left != ((void *)0)) {
        avl_tree_destroy(root->left);
    }
    if(root->key) {
        free(root->key);
    }
    free(root);
}

return_type: void


decompiled_code:
__int64 __fastcall avl_tree_insert(__int64 a1, const char *a2, unsigned int a3)
{
int v4; // eax
__int64 v5; // r12
int v6; // ebp
int v7; // eax
int v8; // edx
bool v9; // cc
int v10; // eax
__int64 result; // rax
size_t v12; // rax
char *v13; // rax
__int64 v14; // rax
int v15; // ebp
int v16; // eax
int v17; // edx

if ( !(unsigned int)invariant(a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0xB7u, "avl_tree_insert");
if ( *(_QWORD *)a1 )
{
v4 = strcmp(a2, *(const char **)a1);
if ( v4 < 0 )
{
if ( !*(_QWORD *)(a1 + 16) )
*(_QWORD *)(a1 + 16) = avl_tree_create();
v14 = avl_tree_insert(*(_QWORD *)(a1 + 16), a2, a3);
*(_QWORD *)(a1 + 16) = v14;
v15 = height(v14);
v16 = height(*(_QWORD *)(a1 + 24));
v17 = v16 + 1;
v9 = v15 <= v16;
v10 = v15 + 1;
if ( v9 )
v10 = v17;
goto LABEL_9;
}
if ( v4 > 0 )
{
if ( !*(_QWORD *)(a1 + 24) )
*(_QWORD *)(a1 + 24) = avl_tree_create();
v5 = avl_tree_insert(*(_QWORD *)(a1 + 24), a2, a3);
*(_QWORD *)(a1 + 24) = v5;
v6 = height(*(_QWORD *)(a1 + 16));
v7 = height(v5);
v8 = v7 + 1;
v9 = v6 <= v7;
v10 = v6 + 1;
if ( v9 )
v10 = v8;
LABEL_9:
*(_DWORD *)(a1 + 12) = v10;
return balance_update(a1);
}
*(_DWORD *)(a1 + 8) = a3;
result = a1;
}
else
{
v12 = strlen(a2);
v13 = (char *)malloc(v12 + 1);
*(_QWORD *)a1 = v13;
strcpy(v13, a2);
*(_DWORD *)(a1 + 8) = a3;
*(_DWORD *)(a1 + 12) = 1;
if ( !(unsigned int)invariant(a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0xBFu, "avl_tree_insert");
result = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2, unsigned int a3)
{
int v4; // eax
__int64 v5; // r12
int v6; // ebp
int v7; // eax
int v8; // edx
bool v9; // cc
int v10; // eax
__int64 result; // rax
size_t v12; // rax
char *v13; // rax
__int64 v14; // rax
int v15; // ebp
int v16; // eax
int v17; // edx

if ( !(unsigned int)func6(a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0xB7u, "avl_tree_insert");
if ( *(_QWORD *)a1 )
{
v4 = strcmp(a2, *(const char **)a1);
if ( v4 < 0 )
{
if ( !*(_QWORD *)(a1 + 16) )
*(_QWORD *)(a1 + 16) = func8();
v14 = func10(*(_QWORD *)(a1 + 16), a2, a3);
*(_QWORD *)(a1 + 16) = v14;
v15 = func0(v14);
v16 = func0(*(_QWORD *)(a1 + 24));
v17 = v16 + 1;
v9 = v15 <= v16;
v10 = v15 + 1;
if ( v9 )
v10 = v17;
goto LABEL_9;
}
if ( v4 > 0 )
{
if ( !*(_QWORD *)(a1 + 24) )
*(_QWORD *)(a1 + 24) = func8();
v5 = func10(*(_QWORD *)(a1 + 24), a2, a3);
*(_QWORD *)(a1 + 24) = v5;
v6 = func0(*(_QWORD *)(a1 + 16));
v7 = func0(v5);
v8 = v7 + 1;
v9 = v6 <= v7;
v10 = v6 + 1;
if ( v9 )
v10 = v8;
LABEL_9:
*(_DWORD *)(a1 + 12) = v10;
return func7(a1);
}
*(_DWORD *)(a1 + 8) = a3;
result = a1;
}
else
{
v12 = strlen(a2);
v13 = (char *)malloc(v12 + 1);
*(_QWORD *)a1 = v13;
strcpy(v13, a2);
*(_DWORD *)(a1 + 8) = a3;
*(_DWORD *)(a1 + 12) = 1;
if ( !(unsigned int)func6(a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0xBFu, "avl_tree_insert");
result = a1;
}
return result;
}

original_code:
struct avl_tree_node* avl_tree_insert(struct avl_tree_node* root, const char* key, int value)
{
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 183, __extension__ __PRETTY_FUNCTION__));
    if (!root->key) {
        root->key = malloc(strlen(key) + 1);
        strcpy(root->key, key);
        root->value = value;
        root->height = 1;
        ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 191, __extension__ __PRETTY_FUNCTION__));
        return root;
    }
    int comparison = strcmp(key, root->key);
    if (comparison < 0) {
        if (root->left == ((void *)0)) {
            root->left = avl_tree_create();
        }
        root->left = avl_tree_insert(root->left, key, value);
        root->height = ( ((height(root->left)) > (height(root->right))) ? (height(root->left)) : (height(root->right)) ) + 1;
        return balance_update(root);
    } else if (comparison > 0) {
        if (root->right == ((void *)0)) {
            root->right = avl_tree_create();
        }
        root->right = avl_tree_insert(root->right, key, value);
        root->height = ( ((height(root->left)) > (height(root->right))) ? (height(root->left)) : (height(root->right)) ) + 1;
        return balance_update(root);
    } else {
        root->value = value;
        return root;
    }
}

canonical_original_code:
struct avl_tree_node *avl_tree_insert(struct avl_tree_node *root, char *key, int value)
{
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 183, __extension__ __PRETTY_FUNCTION__));
    if (!root->key) {
        root->key = malloc(strlen(key) + 1);
        strcpy(root->key, key);
        root->value = value;
        root->height = 1;
        ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 191, __extension__ __PRETTY_FUNCTION__));
        return root;
    }
    int comparison = strcmp(key, root->key);
    if (comparison < 0) {
        if (root->left == ((void *)0)) {
            root->left = avl_tree_create();
        }
        root->left = avl_tree_insert(root->left, key, value);
        root->height = ( ((height(root->left)) > (height(root->right))) ? (height(root->left)) : (height(root->right)) ) + 1;
        return balance_update(root);
    } else if (comparison > 0) {
        if (root->right == ((void *)0)) {
            root->right = avl_tree_create();
        }
        root->right = avl_tree_insert(root->right, key, value);
        root->height = ( ((height(root->left)) > (height(root->right))) ? (height(root->left)) : (height(root->right)) ) + 1;
        return balance_update(root);
    } else {
        root->value = value;
        return root;
    }
}

variable_types:
key
char *

variable_types: value int

variable_types: comparison int


decompiled_code:
const char *__fastcall avl_tree_find(__int64 a1, const char *a2)
{
const char *result; // rax
int v3; // eax
bool v4; // cc

if ( !(unsigned int)invariant(a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0xDCu, "avl_tree_find");
result = *(const char **)a1;
if ( *(_QWORD *)a1 )
{
v3 = strcmp(a2, *(const char **)a1);
v4 = v3 <= 0;
if ( v3 < 0 )
{
result = *(const char **)(a1 + 16);
if ( result )
result = (const char *)avl_tree_find(*(_QWORD *)(a1 + 16), a2);
}
else
{
result = (const char *)(a1 + 8);
if ( !v4 )
{
result = *(const char **)(a1 + 24);
if ( result )
result = (const char *)avl_tree_find(*(_QWORD *)(a1 + 24), a2);
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func11(__int64 a1, const char *a2)
{
const char *result; // rax
int v3; // eax
bool v4; // cc

if ( !(unsigned int)func6(a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0xDCu, "avl_tree_find");
result = *(const char **)a1;
if ( *(_QWORD *)a1 )
{
v3 = strcmp(a2, *(const char **)a1);
v4 = v3 <= 0;
if ( v3 < 0 )
{
result = *(const char **)(a1 + 16);
if ( result )
result = (const char *)func11(*(_QWORD *)(a1 + 16), a2);
}
else
{
result = (const char *)(a1 + 8);
if ( !v4 )
{
result = *(const char **)(a1 + 24);
if ( result )
result = (const char *)func11(*(_QWORD *)(a1 + 24), a2);
}
}
}
return result;
}

original_code:
int* avl_tree_find(struct avl_tree_node* root, const char* key)
{
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 220, __extension__ __PRETTY_FUNCTION__));
    if (!root->key) {
        return ((void *)0);
    }
    int comparison = strcmp(key, root->key);
    if (comparison < 0) {
        if (root->left == ((void *)0)) {
            return ((void *)0);
        } else {
            return avl_tree_find(root->left, key);
        }
    } else if (comparison > 0) {
        if (root->right == ((void *)0)) {
            return ((void *)0);
        } else {
            return avl_tree_find(root->right, key);
        }
    } else {
        return &root->value;
    }
}

canonical_original_code:
int *avl_tree_find(struct avl_tree_node *root, char *key)
{
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 220, __extension__ __PRETTY_FUNCTION__));
    if (!root->key) {
        return ((void *)0);
    }
    int comparison = strcmp(key, root->key);
    if (comparison < 0) {
        if (root->left == ((void *)0)) {
            return ((void *)0);
        } else {
            return avl_tree_find(root->left, key);
        }
    } else if (comparison > 0) {
        if (root->right == ((void *)0)) {
            return ((void *)0);
        } else {
            return avl_tree_find(root->right, key);
        }
    } else {
        return &root->value;
    }
}

return_type: int *


decompiled_code:
__int64 __fastcall avl_tree_for_each(__int64 a1, void (__fastcall *a2)(_QWORD, _QWORD))
{
__int64 v3; // rdi
__int64 v4; // rdi
__int64 result; // rax

if ( !(unsigned int)invariant(a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0xF7u, "avl_tree_for_each");
v3 = *(_QWORD *)(a1 + 16);
if ( v3 )
avl_tree_for_each(v3, a2);
if ( *(_QWORD *)a1 )
a2(*(_QWORD *)a1, *(unsigned int *)(a1 + 8));
v4 = *(_QWORD *)(a1 + 24);
if ( v4 )
avl_tree_for_each(v4, a2);
result = invariant(a1);
if ( !(_DWORD)result )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0x104u, "avl_tree_for_each");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, void (__fastcall *a2)(_QWORD, _QWORD))
{
__int64 v3; // rdi
__int64 v4; // rdi
__int64 result; // rax

if ( !(unsigned int)func6(a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0xF7u, "avl_tree_for_each");
v3 = *(_QWORD *)(a1 + 16);
if ( v3 )
func12(v3, a2);
if ( *(_QWORD *)a1 )
a2(*(_QWORD *)a1, *(unsigned int *)(a1 + 8));
v4 = *(_QWORD *)(a1 + 24);
if ( v4 )
func12(v4, a2);
result = func6(a1);
if ( !(_DWORD)result )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0x104u, "avl_tree_for_each");
return result;
}

original_code:
void avl_tree_for_each(struct avl_tree_node* root, void (*function)(const char* key, int value))
{
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 247, __extension__ __PRETTY_FUNCTION__));
    if (root->left) {
        avl_tree_for_each(root->left, function);
    }
    if(root->key) {
        function(root->key, root->value);
    }
    if (root->right) {
        avl_tree_for_each(root->right, function);
    }
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 260, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void avl_tree_for_each(struct avl_tree_node *root, void (*function)(char *key, int value))
{
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 247, __extension__ __PRETTY_FUNCTION__));
    if (root->left) {
        avl_tree_for_each(root->left, function);
    }
    if(root->key) {
        function(root->key, root->value);
    }
    if (root->right) {
        avl_tree_for_each(root->right, function);
    }
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 260, __extension__ __PRETTY_FUNCTION__));
}

variable_types:
function
void (*)(char *key, int value)


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

if ( !(unsigned int)invariant(a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0x109u, "avl_tree_increase");
v2 = avl_tree_find(a1, a2);
if ( !v2 )
return avl_tree_insert(a1, a2, 1u);
++*(_DWORD *)v2;
return a1;
}

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

if ( !(unsigned int)func6(a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0x109u, "avl_tree_increase");
v2 = func11(a1, a2);
if ( !v2 )
return func10(a1, a2, 1u);
++*(_DWORD *)v2;
return a1;
}

original_code:
struct avl_tree_node* avl_tree_increase(struct avl_tree_node* root, const char* key)
{
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 265, __extension__ __PRETTY_FUNCTION__));
    int* newvalue = avl_tree_find(root, key);
    if (!newvalue) {
        return avl_tree_insert(root, key, 1);
    } else {
        ++*newvalue;
        return root;
    }
}

canonical_original_code:
struct avl_tree_node *avl_tree_increase(struct avl_tree_node *root, char *key)
{
    ((invariant(root)) ? (void) (0) : __assert_fail ("invariant(root)", "sources/avl_tree.c", 265, __extension__ __PRETTY_FUNCTION__));
    int *newvalue = avl_tree_find(root, key);
    if (!newvalue) {
        return avl_tree_insert(root, key, 1);
    } else {
        ++*newvalue;
        return root;
    }
}

variable_types:
newvalue
int *


decompiled_code:
int __fastcall print_word_and_count(const char *a1, unsigned int a2)
{
return fprintf(output, "%s %d\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, unsigned int a2)
{
return fprintf(output, "%s %d\n", a1, a2);
}

original_code:
static void print_word_and_count(const char* word, int count)
{
 fprintf(output, "%s %d\n", word, count);
}

canonical_original_code:
static void print_word_and_count(char *word, int count)
{
 fprintf(output, "%s %d\n", word, count);
}

variable_types:
word
char *

variable_types: count int


decompiled_code:
__int64 __fastcall process_sentence_length(unsigned int a1)
{
return int_counts_add(sentence_lengths, a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return int_counts_add(sentence_lengths, a1);
}

original_code:
static void process_sentence_length(int length)
{
 int_counts_add(sentence_lengths, length);
}

variable_types: length int


decompiled_code:
__int64 __fastcall process_word(__int64 a1)
{
__int64 result; // rax

result = avl_tree_increase(words, a1);
words = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax

result = avl_tree_increase(words, a1);
words = result;
return result;
}

original_code:
static void process_word(const char* word)
{
 words = avl_tree_increase(words, word);
}

canonical_original_code:
static void process_word(char *word)
{
 words = avl_tree_increase(words, word);
}


assertMyNull

decompiled_code:
void __fastcall assertMyNull(__int64 a1, unsigned int a2, const char *a3)
{
if ( a1 )
{
printf("Pointer was not null on %s:%d\n", a3, a2);
exit(-1);
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, unsigned int a2, const char *a3)
{
if ( a1 )
{
printf("Pointer was not null on %s:%d\n", a3, a2);
exit(-1);
}
}

original_code:
void assertMyNull(void* pointer, int line, const char* file)
{
 if(pointer)
 {
  printf("Pointer was not null on %s:%d\n", file, line);
  exit(-1);
 }
}

canonical_original_code:
void assertMyNull(void *pointer, int line, char *file)
{
 if(pointer)
 {
  printf("Pointer was not null on %s:%d\n", file, line);
  exit(-1);
 }
}

variable_types:
pointer
void *

variable_types: line int

variable_types:
file
char *


assertMyNotNull

decompiled_code:
void __fastcall assertMyNotNull(__int64 a1, unsigned int a2, const char *a3)
{
if ( !a1 )
{
printf("Pointer was null on %s:%d\n", a3, a2);
exit(-1);
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, unsigned int a2, const char *a3)
{
if ( !a1 )
{
printf("Pointer was null on %s:%d\n", a3, a2);
exit(-1);
}
}

original_code:
void assertMyNotNull(void* pointer, int line, const char* file)
{
 if(!pointer)
 {
  printf("Pointer was null on %s:%d\n", file, line);
  exit(-1);
 }
}

canonical_original_code:
void assertMyNotNull(void *pointer, int line, char *file)
{
 if(!pointer)
 {
  printf("Pointer was null on %s:%d\n", file, line);
  exit(-1);
 }
}


assertMyIntEquals

decompiled_code:
void __fastcall assertMyIntEquals(unsigned int a1, unsigned int a2, unsigned int a3, const char *a4)
{
if ( a1 != a2 )
{
printf("Expected %d, got %d on %s:%d\n", a1, a2, a4, a3);
exit(-1);
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1, unsigned int a2, unsigned int a3, const char *a4)
{
if ( a1 != a2 )
{
printf("Expected %d, got %d on %s:%d\n", a1, a2, a4, a3);
exit(-1);
}
}

original_code:
void assertMyIntEquals(int expected, int value, int line, const char* file)
{
 if(expected != value)
 {
  printf("Expected %d, got %d on %s:%d\n", expected, value, file, line);
  exit(-1);
 }
}

canonical_original_code:
void assertMyIntEquals(int expected, int value, int line, char *file)
{
 if(expected != value)
 {
  printf("Expected %d, got %d on %s:%d\n", expected, value, file, line);
  exit(-1);
 }
}

variable_types: expected int


assertMyStringEquals

decompiled_code:
int __fastcall assertMyStringEquals(const char *a1, const char *a2, unsigned int a3, const char *a4)
{
int result; // eax

result = strcmp(a1, a2);
if ( result )
{
printf("Expected \"%s\", got \"%s\" on %s:%d\n", a1, a2, a4, a3);
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(const char *a1, const char *a2, unsigned int a3, const char *a4)
{
int result; // eax

result = strcmp(a1, a2);
if ( result )
{
printf("Expected \"%s\", got \"%s\" on %s:%d\n", a1, a2, a4, a3);
exit(-1);
}
return result;
}

original_code:
void assertMyStringEquals(const char* expected, const char* value, int line, const char* file)
{
 if(strcmp(expected, value) != 0)
 {
  printf("Expected \"%s\", got \"%s\" on %s:%d\n", expected, value, file, line);
  exit(-1);
 }
}

canonical_original_code:
void assertMyStringEquals(char *expected, char *value, int line, char *file)
{
 if(strcmp(expected, value) != 0)
 {
  printf("Expected \"%s\", got \"%s\" on %s:%d\n", expected, value, file, line);
  exit(-1);
 }
}

variable_types:
expected
char *

variable_types:
value
char *


assertMyHigher

decompiled_code:
void __fastcall assertMyHigher(unsigned int a1, unsigned int a2, unsigned int a3, const char *a4)
{
if ( (int)a2 >= (int)a1 )
{
printf("Got %d > %d on %s:%d\n", a1, a2, a4, a3);
exit(-1);
}
}

canonical_decompiled_code:
void __fastcall func11(unsigned int a1, unsigned int a2, unsigned int a3, const char *a4)
{
if ( (int)a2 >= (int)a1 )
{
printf("Got %d > %d on %s:%d\n", a1, a2, a4, a3);
exit(-1);
}
}

original_code:
void assertMyHigher(int first, int second, int line, const char* file)
{
 if(second >= first)
 {
  printf("Got %d > %d on %s:%d\n", first, second, file, line);
  exit(-1);
 }
}

canonical_original_code:
void assertMyHigher(int first, int second, int line, char *file)
{
 if(second >= first)
 {
  printf("Got %d > %d on %s:%d\n", first, second, file, line);
  exit(-1);
 }
}

variable_types: first int

variable_types: second int


decompiled_code:
int __fastcall word_tester(const char *a1)
{
int result; // eax

if ( current_word < word_count )
result = assertMyStringEquals(
*(const char **)(expected_words + 8LL * current_word),
a1,
0x1Eu,
"tests/parser_test.c");
else
result = printf("Error, got word '%s', didn't expect more words\n", a1);
++current_word;
return result;
}

canonical_decompiled_code:
int __fastcall func12(const char *a1)
{
int result; // eax

if ( current_word < word_count )
result = func10(
*(const char **)(expected_words + 8LL * current_word),
a1,
0x1Eu,
"tests/parser_test.c");
else
result = printf("Error, got word '%s', didn't expect more words\n", a1);
++current_word;
return result;
}

original_code:
void word_tester(const char* word)
{
    if(current_word >= word_count) {
        printf("Error, got word '%s', didn't expect more words\n", word);
    } else {
        assertMyStringEquals(expected_words[current_word], word, 30, "tests/parser_test.c");
    }
    ++current_word;
}

canonical_original_code:
void word_tester(char *word)
{
    if(current_word >= word_count) {
        printf("Error, got word '%s', didn't expect more words\n", word);
    } else {
        assertMyStringEquals(expected_words[current_word], word, 30, "tests/parser_test.c");
    }
    ++current_word;
}


decompiled_code:
void __fastcall sentence_tester(unsigned int a1)
{
if ( current_sentence < sentence_count )
assertMyIntEquals(*(_DWORD *)(expected_sentence_lengths + 4LL * current_sentence), a1, 0x30u, "tests/parser_test.c");
else
printf("Error, got sentence length'%d', didn't expect more sentences\n", a1);
++current_sentence;
}

canonical_decompiled_code:
void __fastcall func13(unsigned int a1)
{
if ( current_sentence < sentence_count )
func9(*(_DWORD *)(expected_sentence_lengths + 4LL * current_sentence), a1, 0x30u, "tests/parser_test.c");
else
printf("Error, got sentence length'%d', didn't expect more sentences\n", a1);
++current_sentence;
}

original_code:
void sentence_tester(int length)
{
    if(current_sentence >= sentence_count) {
        printf("Error, got sentence length'%d', didn't expect more sentences\n", length);
    } else {
        assertMyIntEquals(expected_sentence_lengths[current_sentence], length, 48, "tests/parser_test.c");
    }
    ++current_sentence;
}


decompiled_code:
__int64 __fastcall is_end_of_sentence(unsigned __int8 a1)
{
char v1; // al

v1 = 1;
if ( a1 <= 0x3Fu )
v1 = ((0x8000400200000000LL >> a1) ^ 1) & 1;
return (unsigned __int8)v1 ^ 1u;
}

original_code:
static int is_end_of_sentence(char c)
{
 return c == '.' || c == '!' || c == '?';
}

variable_types: c char


decompiled_code:
__int64 __fastcall is_finnish_character(char a1)
{
return ((a1 & 0xDF) == 0xD6) | (unsigned __int8)((a1 & 0xDF) == 0xC4);
}

canonical_decompiled_code:
__int64 __fastcall func17(char a1)
{
return ((a1 & 0xDF) == 0xD6) | (unsigned __int8)((a1 & 0xDF) == 0xC4);
}

original_code:
static int is_finnish_character(char c)
{
 return c == (char)228 || c == (char)246 || c == (char)196 || c == (char)214;
}


decompiled_code:
__int64 __fastcall check_sentence_end(unsigned __int8 a1, int *a2, __int64 (*a3)(void))
{
__int64 result; // rax

result = is_end_of_sentence(a1);
if ( (_DWORD)result )
{
if ( *a2 > 0 )
{
result = a3();
*a2 = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned __int8 a1, int *a2, __int64 (*a3)(void))
{
__int64 result; // rax

result = func16(a1);
if ( (_DWORD)result )
{
if ( *a2 > 0 )
{
result = a3();
*a2 = 0;
}
}
return result;
}

original_code:
static void check_sentence_end(char c, int* word_count, void (*process_sentence)(int length))
{
 if(is_end_of_sentence(c)) {
  if(*word_count > 0) {
   process_sentence(*word_count);
   *word_count = 0;
  }
 }
}

canonical_original_code:
static void check_sentence_end(char c, int *word_count, void (*process_sentence)(int length))
{
 if(is_end_of_sentence(c)) {
  if(*word_count > 0) {
   process_sentence(*word_count);
   *word_count = 0;
  }
 }
}


decompiled_code:
_BOOL8 __fastcall is_letter(char a1)
{
const unsigned __int16 *v1; // rdx
_BOOL8 result; // rax

v1 = *__ctype_b_loc();
result = 1LL;
if ( (v1[a1] & 0x400) == 0 )
result = (unsigned int)is_finnish_character(a1) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func19(char a1)
{
const unsigned __int16 *v1; // rdx
_BOOL8 result; // rax

v1 = *__ctype_b_loc();
result = 1LL;
if ( (v1[a1] & 0x400) == 0 )
result = (unsigned int)func17(a1) != 0;
return result;
}

original_code:
static int is_letter(char c)
{
 return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha) || is_finnish_character(c);
}

canonical_original_code:
static int is_letter(char c)
{
 return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha) || is_finnish_character(c);
}


decompiled_code:
__int64 __fastcall check_word_end(char a1, __int64 a2, unsigned int *a3, _DWORD *a4, __int64 (__fastcall *a5)(__int64))
{
__int64 result; // rax

if ( is_letter(a1) )
{
result = (int)*a3;
*(_BYTE *)(a2 + result) = a1;
++*a3;
}
else
{
result = *a3;
if ( (int)result > 1 )
{
*(_BYTE *)(a2 + (int)result) = 0;
result = a5(a2);
++*a4;
}
*a3 = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(char a1, __int64 a2, unsigned int *a3, _DWORD *a4, __int64 (__fastcall *a5)(__int64))
{
__int64 result; // rax

if ( func19(a1) )
{
result = (int)*a3;
*(_BYTE *)(a2 + result) = a1;
++*a3;
}
else
{
result = *a3;
if ( (int)result > 1 )
{
*(_BYTE *)(a2 + (int)result) = 0;
result = a5(a2);
++*a4;
}
*a3 = 0;
}
return result;
}

original_code:
static void check_word_end(char c, char* word, int* word_length, int* word_count, void (*process_word)(const char* word))
{
 if(is_letter(c)) {
  word[*word_length] = c;
  ++*word_length;
 } else {
  if(*word_length >= 2) {
   word[*word_length] = '\0';
   process_word(word);
   ++*word_count;
  }
  *word_length = 0;
 }
}

canonical_original_code:
static void check_word_end(char c, char *word, int *word_length, int *word_count, void (*process_word)(char *word))
{
 if(is_letter(c)) {
  word[*word_length] = c;
  ++*word_length;
 } else {
  if(*word_length >= 2) {
   word[*word_length] = '\0';
   process_word(word);
   ++*word_count;
  }
  *word_length = 0;
 }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_hello();
test_punctuation();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func14();
func15();
return 0;
}

original_code:
int main(void)
{
    test_hello();
    test_punctuation();
    return 0;
}

canonical_original_code:
int main()
{
    test_hello();
    test_punctuation();
    return 0;
}


decompiled_code:
_DWORD *int_counts_create()
{
_DWORD *v0; // rbx
_DWORD *v1; // rax
_DWORD *v2; // rcx
_DWORD *v3; // rax

v0 = malloc(0x320uLL);
v1 = malloc(0x18uLL);
v2 = v1;
if ( v1 )
{
*(_QWORD *)v1 = v0;
v1[2] = 0x7FFFFFFF;
v1[3] = -1;
v1[4] = 0;
v3 = v0;
do
*v3++ = 0;
while ( v3 != v0 + 200 );
}
return v2;
}

original_code:
struct int_counts* int_counts_create(void)
{
 int* values = malloc(sizeof(int) * 200);
 struct int_counts* container = malloc(sizeof(struct int_counts));
 if(!container) {
  return ((void *)0);
 }
 container->pvalues = values;
 container->min = 0x7fffffff;
 container->max = -1;
 container->total = 0;
 for(int i = 0; i < 200; ++i) {
  container->pvalues[i] = 0;
 }
 return container;
}

canonical_original_code:
struct int_counts *int_counts_create()
{
 int *values = malloc(sizeof(int) * 200);
 struct int_counts *container = malloc(sizeof(struct int_counts));
 if(!container) {
  return ((void *)0);
 }
 container->pvalues = values;
 container->min = 0x7fffffff;
 container->max = -1;
 container->total = 0;
 for(int i = 0; i < 200; ++i) {
  container->pvalues[i] = 0;
 }
 return container;
}

variable_types:
values
int *

variable_types: struct int_counts { int *pvalues; int min; int max; int total; } *

variable_types: i int


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

if ( a2 > 199 )
__assert_fail("key < MAX_SIZE", "sources/int_counts.c", 0x26u, "int_counts_add");
result = a2;
++*(_DWORD *)(*(_QWORD *)a1 + 4LL * a2);
++*(_DWORD *)(a1 + 16);
if ( *(_DWORD *)(a1 + 12) < a2 )
*(_DWORD *)(a1 + 12) = a2;
if ( *(_DWORD *)(a1 + 8) > a2 )
*(_DWORD *)(a1 + 8) = a2;
return result;
}

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

if ( a2 > 199 )
__assert_fail("key < MAX_SIZE", "sources/int_counts.c", 0x26u, "int_counts_add");
result = a2;
++*(_DWORD *)(*(_QWORD *)a1 + 4LL * a2);
++*(_DWORD *)(a1 + 16);
if ( *(_DWORD *)(a1 + 12) < a2 )
*(_DWORD *)(a1 + 12) = a2;
if ( *(_DWORD *)(a1 + 8) > a2 )
*(_DWORD *)(a1 + 8) = a2;
return result;
}

original_code:
void int_counts_add(struct int_counts* container, int key)
{
 ((key < 200) ? (void) (0) : __assert_fail ("key < MAX_SIZE", "sources/int_counts.c", 38, __extension__ __PRETTY_FUNCTION__));
 ++container->pvalues[key];
 ++container->total;
 if (key > container->max)
  container->max = key;
 if (key < container->min)
  container->min = key;
}

canonical_original_code:
void int_counts_add(struct int_counts *container, int key)
{
 ((key < 200) ? (void) (0) : __assert_fail ("key < MAX_SIZE", "sources/int_counts.c", 38, __extension__ __PRETTY_FUNCTION__));
 ++container->pvalues[key];
 ++container->total;
 if (key > container->max)
  container->max = key;
 if (key < container->min)
  container->min = key;
}

variable_types: key int

user_defined_types: struct int_counts { int *pvalues; int min; int max; int total; }


decompiled_code:
__int64 __fastcall int_counts_get(_QWORD *a1, int a2)
{
if ( a2 > 199 )
__assert_fail("key < MAX_SIZE", "sources/int_counts.c", 0x33u, "int_counts_get");
return *(unsigned int *)(*a1 + 4LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func18(_QWORD *a1, int a2)
{
if ( a2 > 199 )
__assert_fail("key < MAX_SIZE", "sources/int_counts.c", 0x33u, "int_counts_get");
return *(unsigned int *)(*a1 + 4LL * a2);
}

original_code:
int int_counts_get(struct int_counts* container, int key)
{
 ((key < 200) ? (void) (0) : __assert_fail ("key < MAX_SIZE", "sources/int_counts.c", 51, __extension__ __PRETTY_FUNCTION__));
 return container->pvalues[key];
}

canonical_original_code:
int int_counts_get(struct int_counts *container, int key)
{
 ((key < 200) ? (void) (0) : __assert_fail ("key < MAX_SIZE", "sources/int_counts.c", 51, __extension__ __PRETTY_FUNCTION__));
 return container->pvalues[key];
}


decompiled_code:
__int64 __fastcall int_counts_min(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
int int_counts_min(struct int_counts* container)
{
 return container->min;
}

canonical_original_code:
int int_counts_min(struct int_counts *container)
{
 return container->min;
}


decompiled_code:
__int64 __fastcall int_counts_max(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

original_code:
int int_counts_max(struct int_counts* container)
{
 return container->max;
}

canonical_original_code:
int int_counts_max(struct int_counts *container)
{
 return container->max;
}


decompiled_code:
void __fastcall int_counts_destroy(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func21(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void int_counts_destroy(struct int_counts* container)
{
 free(container->pvalues);
 free(container);
}

canonical_original_code:
void int_counts_destroy(struct int_counts *container)
{
 free(container->pvalues);
 free(container);
}


decompiled_code:
__int64 __fastcall int_counts_total(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int int_counts_total(struct int_counts* container)
{
 return container->total;
}

canonical_original_code:
int int_counts_total(struct int_counts *container)
{
 return container->total;
}


decompiled_code:
void __fastcall test_function(__int64 a1, int a2)
{
TOTAL *= a2;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
TOTAL *= a2;
}

original_code:
void test_function(const char* key, int value)
{
 (void)key;
 TOTAL *= value;
}

canonical_original_code:
void test_function(char *key, int value)
{
 (void)key;
 TOTAL *= value;
}

variable_types:
key
char *

variable_types: value int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_creation(argc, argv, envp);
test_finding();
test_inserting();
test_inserting_and_finding();
test_that_keys_are_copied();
test_for_each();
test_increasing();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func1(argc, argv, envp);
func3();
func4();
func5();
func6();
func7();
func8();
return 0;
}

original_code:
int main(void)
{
 test_creation();
 test_finding();
 test_inserting();
 test_inserting_and_finding();
 test_that_keys_are_copied();
 test_for_each();
 test_increasing();
 return 0;
}

canonical_original_code:
int main()
{
 test_creation();
 test_finding();
 test_inserting();
 test_inserting_and_finding();
 test_that_keys_are_copied();
 test_for_each();
 test_increasing();
 return 0;
}


chkpr

repo: mutoso-mirrors/heirloom-sh

decompiled_code:
void *chkpr()
{
void *result; // rax

if ( (flags & 4) != 0 )
{
result = standin;
if ( !*((_QWORD *)standin + 7) )
result = (void *)prs(ps2nod[3]);
}
return result;
}

canonical_decompiled_code:
void *func0()
{
void *result; // rax

if ( (flags & 4) != 0 )
{
result = standin;
if ( !*((_QWORD *)standin + 7) )
result = (void *)prs(ps2nod[3]);
}
return result;
}

original_code:
void
chkpr(void)
{
 if ((flags & 04) && standin->fstak == 0)
  prs(ps2nod.namval);
}

canonical_original_code:
void chkpr()
{
 if ((flags & 04) && standin->fstak == 0)
  prs(ps2nod.namval);
}


settmp

decompiled_code:
__int64 settmp()
{
int v0; // eax
__int64 result; // rax

v0 = ltos(mypid);
serial = 0;
result = movstr((char *)&numbuf + v0, (unsigned int)((_DWORD)tmpout + 7));
tmpname = result;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
__int64 result; // rax

v0 = ltos(mypid);
serial = 0;
result = movstr((char *)&numbuf + v0, (unsigned int)((_DWORD)tmpout + 7));
tmpname = result;
return result;
}

original_code:
void
settmp(void)
{
 int i;
 i = ltos(mypid);
 serial = 0;
 tmpname = movstr(numbuf + i, &tmpout[7]);
}

canonical_original_code:
void settmp()
{
 int i;
 i = ltos(mypid);
 serial = 0;
 tmpname = movstr(numbuf + i, &tmpout[7]);
}


Ldup

decompiled_code:
__int64 __fastcall Ldup(int fd, unsigned int a2)
{
__int64 result; // rax

if ( fd >= 0 )
{
if ( fd != a2 )
{
close(a2);
fcntl64((unsigned int)fd, 0LL, a2);
close(fd);
}
result = fcntl64(a2, 2LL, 1LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, unsigned int a2)
{
__int64 result; // rax

if ( fd >= 0 )
{
if ( fd != a2 )
{
close(a2);
fcntl64((unsigned int)fd, 0LL, a2);
close(fd);
}
result = fcntl64(a2, 2LL, 1LL);
}
return result;
}

original_code:
void
Ldup(register int fa, register int fb)
{
 if (fa >= 0) {
  if (fa != fb)
  {
   close(fb);
   fcntl(fa, 0, fb);
   close(fa);
  }
  fcntl(fb, 2, 1);
 }
}

canonical_original_code:
void Ldup(int fa, int fb)
{
 if (fa >= 0) {
  if (fa != fb)
  {
   close(fb);
   fcntl(fa, 0, fb);
   close(fa);
  }
  fcntl(fb, 2, 1);
 }
}

variable_types: fa int

variable_types: fb int


chkmail

original_code:
void
chkmail(void)
{
 register unsigned char *s = mailp;
 register unsigned char *save;
 long *ptr = mod_time;
 unsigned char *start;
 BOOL flg;
 struct stat statb;
 while (*s) {
  start = s;
  save = 0;
  flg = 0;
  while (*s) {
   if (*s != ':') {
    if (*s == '%' && save == 0)
     save = s;
    s++;
   } else {
    flg = 1;
    *s = 0;
   }
  }
  if (save)
   *save = 0;
  if (*start && stat((const char *)start, &statb) >= 0) {
   if (statb.st_size && *ptr &&
       statb.st_mtim.tv_sec != *ptr) {
    if (save) {
     prs(save+1);
     prc('\n');
    }
    else
     prs(mailmsg);
   }
   *ptr = statb.st_mtim.tv_sec;
  } else if (*ptr == 0)
   *ptr = 1;
  if (save)
   *save = '%';
  if (flg)
   *s++ = ':';
  ptr++;
 }
}

canonical_original_code:
void chkmail()
{
 register unsigned char *s = mailp;
 register unsigned char *save;
 long *ptr = mod_time;
 unsigned char *start;
 short flg;
 struct stat statb;
 while (*s) {
  start = s;
  save = 0;
  flg = 0;
  while (*s) {
   if (*s != ':') {
    if (*s == '%' && save == 0)
     save = s;
    s++;
   } else {
    flg = 1;
    *s = 0;
   }
  }
  if (save)
   *save = 0;
  if (*start && stat((char *)start, &statb) >= 0) {
   if (statb.st_size && *ptr &&
       statb.st_mtim.tv_sec != *ptr) {
    if (save) {
     prs(save+1);
     prc('\n');
    }
    else
     prs(mailmsg);
   }
   *ptr = statb.st_mtim.tv_sec;
  } else if (*ptr == 0)
   *ptr = 1;
  if (save)
   *save = '%';
  if (flg)
   *s++ = ':';
  ptr++;
 }
}

variable_types:
s
unsigned char *

variable_types:
save
unsigned char *

variable_types:
ptr
long *

variable_types:
start
unsigned char *

variable_types: flg short

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

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


setwidth

decompiled_code:
size_t setwidth()
{
const char *v0; // rsi
size_t result; // rax

v0 = *(const char **)(lookup("LC_ALL") + 24);
if ( v0 && *v0
|| (v0 = *(const char **)(lookup("LC_CTYPE") + 24)) != 0LL && *v0
|| (v0 = *(const char **)(lookup("LANG") + 24)) != 0LL && *v0 )
{
setlocale(0, v0);
}
else
{
setlocale(0, "C");
}
result = _ctype_get_mb_cur_max();
mb_cur_max = result;
return result;
}

canonical_decompiled_code:
size_t func4()
{
const char *v0; // rsi
size_t result; // rax

v0 = *(const char **)(lookup("LC_ALL") + 24);
if ( v0 && *v0
|| (v0 = *(const char **)(lookup("LC_CTYPE") + 24)) != 0LL && *v0
|| (v0 = *(const char **)(lookup("LANG") + 24)) != 0LL && *v0 )
{
setlocale(0, v0);
}
else
{
setlocale(0, "C");
}
result = _ctype_get_mb_cur_max();
mb_cur_max = result;
return result;
}

original_code:
void
setwidth(void)
{
 unsigned char *name = lookup("LC_ALL")->namval;
 if (!name || !*name)
  name = lookup("LC_CTYPE")->namval;
 if (!name || !*name)
  name = lookup("LANG")->namval;
 if (!name || !*name)
  setlocale(0, "C");
 else
  setlocale(0, (const char *)name);
 mb_cur_max = (__ctype_get_mb_cur_max ());
}

canonical_original_code:
void setwidth()
{
 unsigned char *name = lookup("LC_ALL")->namval;
 if (!name || !*name)
  name = lookup("LC_CTYPE")->namval;
 if (!name || !*name)
  name = lookup("LANG")->namval;
 if (!name || !*name)
  setlocale(0, "C");
 else
  setlocale(0, (char *)name);
 mb_cur_max = (__ctype_get_mb_cur_max ());
}

variable_types:
name
unsigned char *


decompiled_code:
int __fastcall sh_setmode(int a1)
{
int result; // eax
void *v2; // rsi

result = flags;
if ( (flags & 2) != 0 || flags >= 0 && (result = isatty(output)) != 0 && (result = isatty(*(_DWORD *)standin)) != 0 )
{
v2 = &stdprompt;
if ( !geteuid() )
v2 = &supprompt;
dfault(&ps1nod, v2);
dfault(ps2nod, &readmsg);
flags |= 0x24uLL;
if ( *((_DWORD *)&mailpnod + 10) )
setmail(*((char **)&mailpnod + 3));
else
setmail(*((char **)&mailnod + 3));
result = startjobs();
}
else
{
flags = (flags | a1) & 0xFFFFFFFFFFFFFFFBLL;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1)
{
int result; // eax
void *v2; // rsi

result = flags;
if ( (flags & 2) != 0 || flags >= 0 && (result = isatty(output)) != 0 && (result = isatty(*(_DWORD *)standin)) != 0 )
{
v2 = &stdprompt;
if ( !geteuid() )
v2 = &supprompt;
dfault(&ps1nod, v2);
dfault(ps2nod, &readmsg);
flags |= 0x24uLL;
if ( *((_DWORD *)&mailpnod + 10) )
setmail(*((char **)&mailpnod + 3));
else
setmail(*((char **)&mailnod + 3));
result = startjobs();
}
else
{
flags = (flags | a1) & 0xFFFFFFFFFFFFFFFBLL;
}
return result;
}

original_code:
void
sh_setmode(int prof)
{
 if ((flags & 02) ||
     ((flags&0200) == 0 &&
     isatty(output) &&
     isatty((standin->fdes))))
 {
  dfault(&ps1nod, (geteuid() ? stdprompt : supprompt));
  dfault(&ps2nod, readmsg);
  flags |= 040 | 04;
  if (mailpnod.namflg != 0)
   setmail(mailpnod.namval);
  else
   setmail(mailnod.namval);
  startjobs();
 }
 else
 {
  flags |= prof;
  flags &= ~04;
 }
}

variable_types: prof int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
const char *v8; // rdi
int v9; // edx
__int64 v10; // rax
__int64 v12; // rax
__int64 v14; // rax
int v15; // eax
__int64 v16; // rax
_BYTE *v17; // rax
__uid_t v18; // er13
__uid_t v19; // er14
__gid_t v20; // er12
__gid_t v21; // er15
int *v22; // rbx
int v23; // eax
int *v24; // rbx
int v25; // eax
_DWORD *v26; // rbx
_BYTE *v27; // [rsp+0h] [rbp-48h]
_BOOL4 v28; // [rsp+8h] [rbp-40h]
int v29; // [rsp+Ch] [rbp-3Ch]

v29 = 32;
v28 = 1;
v27 = &flagadr;
init_sigval(argc, argv, envp);
mypid = getpid();
mypgid = getpgid(mypid);
mysid = getsid(mypid);
if ( !stakbot )
addblok(0LL);
if ( *(_BYTE *)simple(*argv) == 45 )
{
signal(24, 0LL);
signal(25, 0LL);
login_shell = -1;
}
stdsigs();
setup_env();
setlocale(0, &byte_C59);
v4 = findnam("SHELL");
if ( v4 )
{
v5 = simple(*(_QWORD *)(v4 + 24));
v28 = nullsub_1("rsh", v5) != 0;
}
if ( argc > 0 )
{
v6 = simple(*argv);
if ( (unsigned int)nullsub_1("rsh", v6) )
{
v14 = simple(*argv);
v15 = nullsub_1("-rsh", v14);
if ( v15 )
v15 = 32;
v29 = v15;
}
else
{
v29 = 0;
}
}
v7 = simple(*argv);
v8 = "jsh";
if ( !(unsigned int)nullsub_1("jsh", v7) || (v16 = simple(*argv), v8 = "-jsh", !(unsigned int)nullsub_1("-jsh", v16)) )
flags |= 0x40000uLL;
hcreate((size_t)v8);
set_dotpath();
v9 = options((unsigned int)argc, argv);
dolc = v9;
if ( v9 <= 1 )
{
flags |= 0x400uLL;
if ( flagadr )
{
v17 = &flagadr;
do
++v17;
while ( *v17 );
}
else
{
v17 = &flagadr;
}
v27 = v17 + 1;
*v17 = 115;
v17[1] = 0;
}
if ( (*(&flags + 1) & 4) == 0 )
dolc = v9 - 1;
if ( (flags & 0x100000) == 0 )
{
v18 = geteuid();
v19 = getuid();
v20 = getegid();
v21 = getgid();
if ( v18 != v19 && v18 <= 0x63 )
setuid(v19);
if ( v20 != v21 && v20 <= 0x63 && v20 != 1 )
setgid(v21);
}
dolv = &argv[argc - (__int64)dolc];
--dolc;
if ( setjmp(subshell) )
{
freejobs(subshell);
flags |= 0x200uLL;
}
replace(&cmdadr, *dolv);
assnum(&pidadr, mypid);
settmp();
assign(&ifsnod, &sptbnl);
dfault(timeoutnod, "0");
timeoutnod[10] |= 8u;
dfault(mchknod, "600");
mailchk = stoi(mchknod[3]);
v10 = lookup("OPTIND");
assign(v10, "1");
getopt_sp = 1;
setwidth();
if ( !beenhere++ )
{
if ( login_shell == -1 && (*((_BYTE *)&flags + 2) & 0x10) == 0 )
{
v22 = (int *)standin;
v23 = pathopen(&nullstr, &sysprofile);
*v22 = v23;
if ( v23 >= 0 )
exfile(v29);
v24 = (int *)standin;
v25 = pathopen(homenod[3], &profile);
*v24 = v25;
if ( v25 >= 0 )
{
exfile(v29);
flags &= 0xFFFFFFFFFFFFFFDFLL;
}
}
if ( !v28 || !v29 )
{
v12 = flags;
if ( (*(&flags + 1) & 1) == 0 )
{
for ( ; *v27; ++v27 )
;
*v27 = 114;
v27[1] = 0;
}
BYTE1(v12) |= 1u;
flags = v12;
}
if ( comdiv )
{
estabf();
*(_DWORD *)standin = -1;
}
else
{
if ( (*(&flags + 1) & 4) != 0 )
{
*(_DWORD *)standin = 0;
}
else
{
flags |= 0x200000uLL;
v26 = standin;
*v26 = chkopen(cmdadr, 0LL);
flags &= 0xFFFFFFFFFFDFFFFFLL;
}
if ( *(_DWORD *)standin )
preacct(cmdadr);
--comdiv;
}
}
exfile(0);
done(0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
const char *v8; // rdi
int v9; // edx
__int64 v10; // rax
__int64 v12; // rax
__int64 v14; // rax
int v15; // eax
__int64 v16; // rax
_BYTE *v17; // rax
__uid_t v18; // er13
__uid_t v19; // er14
__gid_t v20; // er12
__gid_t v21; // er15
int *v22; // rbx
int v23; // eax
int *v24; // rbx
int v25; // eax
_DWORD *v26; // rbx
_BYTE *v27; // [rsp+0h] [rbp-48h]
_BOOL4 v28; // [rsp+8h] [rbp-40h]
int v29; // [rsp+Ch] [rbp-3Ch]

v29 = 32;
v28 = 1;
v27 = &flagadr;
init_sigval(argc, argv, envp);
mypid = getpid();
mypgid = getpgid(mypid);
mysid = getsid(mypid);
if ( !stakbot )
addblok(0LL);
if ( *(_BYTE *)simple(*argv) == 45 )
{
signal(24, 0LL);
signal(25, 0LL);
login_shell = -1;
}
stdsigs();
setup_env();
setlocale(0, &byte_C59);
v4 = findnam("SHELL");
if ( v4 )
{
v5 = simple(*(_QWORD *)(v4 + 24));
v28 = nullsub_1("rsh", v5) != 0;
}
if ( argc > 0 )
{
v6 = simple(*argv);
if ( (unsigned int)nullsub_1("rsh", v6) )
{
v14 = simple(*argv);
v15 = nullsub_1("-rsh", v14);
if ( v15 )
v15 = 32;
v29 = v15;
}
else
{
v29 = 0;
}
}
v7 = simple(*argv);
v8 = "jsh";
if ( !(unsigned int)nullsub_1("jsh", v7) || (v16 = simple(*argv), v8 = "-jsh", !(unsigned int)nullsub_1("-jsh", v16)) )
flags |= 0x40000uLL;
hcreate((size_t)v8);
set_dotpath();
v9 = options((unsigned int)argc, argv);
dolc = v9;
if ( v9 <= 1 )
{
flags |= 0x400uLL;
if ( flagadr )
{
v17 = &flagadr;
do
++v17;
while ( *v17 );
}
else
{
v17 = &flagadr;
}
v27 = v17 + 1;
*v17 = 115;
v17[1] = 0;
}
if ( (*(&flags + 1) & 4) == 0 )
dolc = v9 - 1;
if ( (flags & 0x100000) == 0 )
{
v18 = geteuid();
v19 = getuid();
v20 = getegid();
v21 = getgid();
if ( v18 != v19 && v18 <= 0x63 )
setuid(v19);
if ( v20 != v21 && v20 <= 0x63 && v20 != 1 )
setgid(v21);
}
dolv = &argv[argc - (__int64)dolc];
--dolc;
if ( setjmp(subshell) )
{
freejobs(subshell);
flags |= 0x200uLL;
}
replace(&cmdadr, *dolv);
assnum(&pidadr, mypid);
func1();
assign(&ifsnod, &sptbnl);
dfault(timeoutnod, "0");
timeoutnod[10] |= 8u;
dfault(mchknod, "600");
mailchk = stoi(mchknod[3]);
v10 = lookup("OPTIND");
assign(v10, "1");
getopt_sp = 1;
func4();
if ( !beenhere++ )
{
if ( login_shell == -1 && (*((_BYTE *)&flags + 2) & 0x10) == 0 )
{
v22 = (int *)standin;
v23 = pathopen(&nullstr, &sysprofile);
*v22 = v23;
if ( v23 >= 0 )
func6(v29);
v24 = (int *)standin;
v25 = pathopen(homenod[3], &profile);
*v24 = v25;
if ( v25 >= 0 )
{
func6(v29);
flags &= 0xFFFFFFFFFFFFFFDFLL;
}
}
if ( !v28 || !v29 )
{
v12 = flags;
if ( (*(&flags + 1) & 1) == 0 )
{
for ( ; *v27; ++v27 )
;
*v27 = 114;
v27[1] = 0;
}
BYTE1(v12) |= 1u;
flags = v12;
}
if ( comdiv )
{
estabf();
*(_DWORD *)standin = -1;
}
else
{
if ( (*(&flags + 1) & 4) != 0 )
{
*(_DWORD *)standin = 0;
}
else
{
flags |= 0x200000uLL;
v26 = standin;
*v26 = chkopen(cmdadr, 0LL);
flags &= 0xFFFFFFFFFFDFFFFFLL;
}
if ( *(_DWORD *)standin )
preacct(cmdadr);
--comdiv;
}
}
func6(0);
done(0LL);
return 0;
}

original_code:
int
main(int c, char *v[], char *e[])
{
 int rflag = 040;
 int rsflag = 1;
 unsigned char *flagc = flagadr;
 struct namnod *n;
 (void) &rflag;
 (void) &rsflag;
 (void) &flagc;
 init_sigval();
 mypid = getpid();
 mypgid = getpgid(mypid);
 mysid = getsid(mypid);
 if (stakbot == 0) {
 addblok((unsigned)0);
 }
 if (*simple(v[0]) == '-') {
  signal(24, ((__sighandler_t) 0));
  signal(25, ((__sighandler_t) 0));
  login_shell = (-1);
 }
 stdsigs();
 setup_env();
 setlocale(0, "");
 if (n = findnam("SHELL"))
 {
  if ((cf("rsh", simple(n->namval)) == 0))
   rsflag = 0;
 }
 if (c > 0 && ((cf("rsh", simple(*v)) == 0) || (cf("-rsh", simple(*v)) == 0)))
  rflag = 0;
 if ((cf("jsh", simple(*v)) == 0) || (cf("-jsh", simple(*v)) == 0))
  flags |= 01000000;
 hcreate();
 set_dotpath();
 dolc = options(c, (unsigned char **)v);
 if (dolc < 2)
 {
  flags |= 02000;
  {
   while (*flagc)
    flagc++;
   *flagc++ = 's';
   *flagc = 0;
  }
 }
 if ((flags & 02000) == 0)
  dolc--;
 if ((flags & 04000000) == 0) {
  register uid_t euid;
  register gid_t egid;
  register uid_t ruid;
  register gid_t rgid;
  euid = geteuid();
  ruid = getuid();
  egid = getegid();
  rgid = getgid();
  if ((euid != ruid) && (euid < 100))
   setuid(ruid);
  if ((egid != rgid) && ((egid < 100) && (egid != 1)))
   setgid(rgid);
 }
 dolv = (unsigned char **)v + c - dolc;
 dolc--;
 if (_setjmp (subshell)) {
  freejobs();
  flags |= 01000;
 }
 replace(&cmdadr, dolv[0]);
 assnum(&pidadr, (long)mypid);
 settmp();
 assign(&ifsnod, sptbnl);
 dfault(&timeoutnod, "0");
 timeoutnod.namflg |= 0010;
 dfault(&mchknod, "600");
 mailchk = stoi(mchknod.namval);
 n = lookup("OPTIND");
 assign(n, "1");
 getopt_sp = 1;
 setwidth();
 if ((beenhere++) == 0)
 {
  if ((login_shell == (-1)) && (flags & 04000000) == 0) {
   if (((standin->fdes) = pathopen(nullstr, sysprofile)) >= 0)
    exfile(rflag);
   if (((standin->fdes) = pathopen(homenod.namval, profile)) >= 0)
   {
    exfile(rflag);
    flags &= ~040;
   }
  }
  if (rsflag == 0 || rflag == 0) {
   if ((flags & 0400) == 0) {
    while (*flagc)
     flagc++;
    *flagc++ = 'r';
    *flagc = '\0';
   }
   flags |= 0400;
  }
  if (comdiv)
  {
   estabf(comdiv);
   (standin->fdes) = -1;
  }
  else
  {
   if (flags & 02000) {
    (standin->fdes) = 0;
   } else {
    flags |= 010000000;
    (standin->fdes) = chkopen(cmdadr, 0);
    flags &= ~010000000;
   }
   if ((standin->fdes) != 0)
    preacct(cmdadr);
   comdiv--;
  }
 }
 exfile(0);
 done(0);
 return 0;
}

canonical_original_code:
int main(int c, char *v[], char *e[])
{
 int rflag = 040;
 int rsflag = 1;
 unsigned char *flagc = flagadr;
 struct namnod *n;
 (void) &rflag;
 (void) &rsflag;
 (void) &flagc;
 init_sigval();
 mypid = getpid();
 mypgid = getpgid(mypid);
 mysid = getsid(mypid);
 if (stakbot == 0) {
 addblok((unsigned int)0);
 }
 if (*simple(v[0]) == '-') {
  signal(24, ((void (*)(int)) 0));
  signal(25, ((void (*)(int)) 0));
  login_shell = (-1);
 }
 stdsigs();
 setup_env();
 setlocale(0, "");
 if (n = findnam("SHELL"))
 {
  if ((cf("rsh", simple(n->namval)) == 0))
   rsflag = 0;
 }
 if (c > 0 && ((cf("rsh", simple(*v)) == 0) || (cf("-rsh", simple(*v)) == 0)))
  rflag = 0;
 if ((cf("jsh", simple(*v)) == 0) || (cf("-jsh", simple(*v)) == 0))
  flags |= 01000000;
 hcreate();
 set_dotpath();
 dolc = options(c, (unsigned char **)v);
 if (dolc < 2)
 {
  flags |= 02000;
  {
   while (*flagc)
    flagc++;
   *flagc++ = 's';
   *flagc = 0;
  }
 }
 if ((flags & 02000) == 0)
  dolc--;
 if ((flags & 04000000) == 0) {
  register unsigned int euid;
  register unsigned int egid;
  register unsigned int ruid;
  register unsigned int rgid;
  euid = geteuid();
  ruid = getuid();
  egid = getegid();
  rgid = getgid();
  if ((euid != ruid) && (euid < 100))
   setuid(ruid);
  if ((egid != rgid) && ((egid < 100) && (egid != 1)))
   setgid(rgid);
 }
 dolv = (unsigned char **)v + c - dolc;
 dolc--;
 if (_setjmp (subshell)) {
  freejobs();
  flags |= 01000;
 }
 replace(&cmdadr, dolv[0]);
 assnum(&pidadr, (long)mypid);
 settmp();
 assign(&ifsnod, sptbnl);
 dfault(&timeoutnod, "0");
 timeoutnod.namflg |= 0010;
 dfault(&mchknod, "600");
 mailchk = stoi(mchknod.namval);
 n = lookup("OPTIND");
 assign(n, "1");
 getopt_sp = 1;
 setwidth();
 if ((beenhere++) == 0)
 {
  if ((login_shell == (-1)) && (flags & 04000000) == 0) {
   if (((standin->fdes) = pathopen(nullstr, sysprofile)) >= 0)
    exfile(rflag);
   if (((standin->fdes) = pathopen(homenod.namval, profile)) >= 0)
   {
    exfile(rflag);
    flags &= ~040;
   }
  }
  if (rsflag == 0 || rflag == 0) {
   if ((flags & 0400) == 0) {
    while (*flagc)
     flagc++;
    *flagc++ = 'r';
    *flagc = '\0';
   }
   flags |= 0400;
  }
  if (comdiv)
  {
   estabf(comdiv);
   (standin->fdes) = -1;
  }
  else
  {
   if (flags & 02000) {
    (standin->fdes) = 0;
   } else {
    flags |= 010000000;
    (standin->fdes) = chkopen(cmdadr, 0);
    flags &= ~010000000;
   }
   if ((standin->fdes) != 0)
    preacct(cmdadr);
   comdiv--;
  }
 }
 exfile(0);
 done(0);
 return 0;
}

variable_types: c int

variable_types:
v
char *[]

variable_types:
e
char *[]

variable_types: rflag int

variable_types: rsflag int

variable_types:
flagc
unsigned char *

variable_types: struct namnod { struct namnod *namlft; struct namnod *namrgt; unsigned char *namid; unsigned char *namval; unsigned char *namenv; int namflg; } *

variable_types:
euid
unsigned int

variable_types:
egid
unsigned int

variable_types:
ruid
unsigned int

variable_types:
rgid
unsigned int


prs

decompiled_code:
void __fastcall prs(void *buf)
{
int v1; // eax

if ( buf )
{
v1 = length();
write(output, buf, v1 - 1);
}
}

canonical_decompiled_code:
void __fastcall func0(void *buf)
{
int v1; // eax

if ( buf )
{
v1 = length();
write(output, buf, v1 - 1);
}
}

original_code:
void
prs(const unsigned char *as)
{
 const char *s;
 if ((s = (char *)as) != 0) {
  write(output, s, length(s) - 1);
 }
}

canonical_original_code:
void prs(unsigned char *as)
{
 char *s;
 if ((s = (char *)as) != 0) {
  write(output, s, length(s) - 1);
 }
}

variable_types:
as
unsigned char *

variable_types:
s
char *


prc

decompiled_code:
ssize_t __fastcall prc(char a1)
{
ssize_t result; // rax
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
if ( a1 )
result = write(output, buf, 1uLL);
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(char a1)
{
ssize_t result; // rax
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
if ( a1 )
result = write(output, buf, 1uLL);
return result;
}

original_code:
void
prc(unsigned char c)
{
 if (c) {
  write(output, &c, 1);
 }
}

variable_types:
c
unsigned char


prwc

decompiled_code:
void __fastcall prwc(wchar_t wchar)
{
int v1; // eax
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

if ( wchar )
{
if ( mb_cur_max > 1 && (wchar & 0xFFFFFF80) != 0 )
{
v1 = wctomb(v2, wchar);
if ( v1 < 0 )
{
v2[0] = wchar;
v1 = 1;
}
}
else
{
v2[0] = wchar;
v1 = 1;
}
write(output, v2, v1);
}
}

canonical_decompiled_code:
void __fastcall func2(wchar_t wchar)
{
int v1; // eax
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

if ( wchar )
{
if ( mb_cur_max > 1 && (wchar & 0xFFFFFF80) != 0 )
{
v1 = wctomb(v2, wchar);
if ( v1 < 0 )
{
v2[0] = wchar;
v1 = 1;
}
}
else
{
v2[0] = wchar;
v1 = 1;
}
write(output, v2, v1);
}
}

original_code:
void
prwc(wchar_t c)
{
 char mb[16 + 1];
 int len;
 if (c == 0) {
  return;
 }
 if ((len = (mb_cur_max > 1 && c & ~(wchar_t)0177 ? wctomb(mb, c) : (*(mb) = c, 1))) < 0) {
  mb[0] = (unsigned char)c;
  len = 1;
 }
 write(output, mb, len);
}

canonical_original_code:
void prwc(int c)
{
 char mb[-1];
 int len;
 if (c == 0) {
  return;
 }
 if ((len = (mb_cur_max > 1 && c & ~(int)0177 ? wctomb(mb, c) : (*(mb) = c, 1))) < 0) {
  mb[0] = (unsigned char)c;
  len = 1;
 }
 write(output, mb, len);
}

variable_types:
mb
char [-1]

variable_types: len int


itos

decompiled_code:
char *__fastcall itos(int a1)
{
const char *v1; // rsi
char v2; // dl
char v4; // [rsp+13h] [rbp-15h] BYREF

v4 = 0;
v1 = &v4;
do
{
v2 = a1;
a1 /= 10;
*--v1 = v2 + 48 - 10 * a1;
}
while ( a1 );
return strncpy(&numbuf, v1, 0x15uLL);
}

canonical_decompiled_code:
char *__fastcall func3(int a1)
{
const char *v1; // rsi
char v2; // dl
char v4; // [rsp+13h] [rbp-15h] BYREF

v4 = 0;
v1 = &v4;
do
{
v2 = a1;
a1 /= 10;
*--v1 = v2 + 48 - 10 * a1;
}
while ( a1 );
return strncpy(&numbuf, v1, 0x15uLL);
}

original_code:
void
itos(int n)
{
 unsigned char buf[21];
 unsigned char *abuf = &buf[20];
 int d;
 *--abuf = (unsigned char)'\0';
 do {
   *--abuf = (unsigned char)('0' + n - 10 * (d = n / 10));
 } while ((n = d) != 0);
 strncpy(numbuf, abuf, sizeof (numbuf));
}

variable_types: n int

variable_types:
buf
unsigned char [21]

variable_types:
abuf
unsigned char *

variable_types: d int


prn

decompiled_code:
void __fastcall prn(int a1)
{
itos(a1);
prs(&numbuf);
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
func3(a1);
func0(&numbuf);
}

original_code:
void
prn(int n)
{
 itos(n);
 prs(numbuf);
}


stoi

decompiled_code:
__int64 __fastcall stoi(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
char *v2; // rdx
int v3; // ebx

v1 = *a1;
v2 = (char *)a1;
v3 = 0;
if ( (*a1 & 0x80u) != 0 )
goto LABEL_9;
do
{
if ( (*((_BYTE *)&sh_ctype2 + v1) & 8) == 0 )
break;
if ( !v1 )
break;
if ( v3 < 0 )
break;
v3 = v1 + 10 * v3 - 48;
v1 = *++v2;
}
while ( *v2 >= 0 );
if ( v3 < 0 || a1 == (unsigned __int8 *)v2 )
LABEL_9:
failed(a1, &badnum, v2);
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
char *v2; // rdx
int v3; // ebx

v1 = *a1;
v2 = (char *)a1;
v3 = 0;
if ( (*a1 & 0x80u) != 0 )
goto LABEL_9;
do
{
if ( (*((_BYTE *)&sh_ctype2 + v1) & 8) == 0 )
break;
if ( !v1 )
break;
if ( v3 < 0 )
break;
v3 = v1 + 10 * v3 - 48;
v1 = *++v2;
}
while ( *v2 >= 0 );
if ( v3 < 0 || a1 == (unsigned __int8 *)v2 )
LABEL_9:
failed(a1, &badnum, v2);
return (unsigned int)v3;
}

original_code:
int
stoi(const unsigned char *icp)
{
 const unsigned char *cp = icp;
 int r = 0;
 unsigned char c;
 while ((c = *cp, ((c<0200) && sh_ctype2[c]&(010))) && c && r >= 0) {
  r = r * 10 + c - '0';
  cp++;
 }
 if (r < 0 || cp == icp)
  failed(icp, badnum);
 return (r);
}

canonical_original_code:
int stoi(unsigned char *icp)
{
 unsigned char *cp = icp;
 int r = 0;
 unsigned char c;
 while ((c = *cp, ((c<0200) && sh_ctype2[c]&(010))) && c && r >= 0) {
  r = r * 10 + c - '0';
  cp++;
 }
 if (r < 0 || cp == icp)
  failed(icp, badnum);
 return (r);
}

variable_types:
icp
unsigned char *

variable_types:
cp
unsigned char *

variable_types: r int


stoifll

original_code:
long long
stoifll(const unsigned char *icp)
{
 const unsigned char *cp;
 long long r = 0;
 int sign = 1;
 unsigned char c;
 for (cp = icp; ((*cp<0200) && sh_ctype1[*cp]&(04)); cp++);
 if (*cp == '-') {
  sign = -1;
  cp++;
 } else if (*cp == '+')
  cp++;
 while ((c = *cp, ((c<0200) && sh_ctype2[c]&(010))) && c) {
  r = r * 10 + c - '0';
  cp++;
 }
 return (r * sign);
}

canonical_original_code:
long long stoifll(unsigned char *icp)
{
 unsigned char *cp;
 long long r = 0;
 int sign = 1;
 unsigned char c;
 for (cp = icp; ((*cp<0200) && sh_ctype1[*cp]&(04)); cp++);
 if (*cp == '-') {
  sign = -1;
  cp++;
 } else if (*cp == '+')
  cp++;
 while ((c = *cp, ((c<0200) && sh_ctype2[c]&(010))) && c) {
  r = r * 10 + c - '0';
  cp++;
 }
 return (r * sign);
}

variable_types:
r
long long

variable_types: sign int

return_type: long long


ltos

variable_types: n long

variable_types: i int


ulltos

decompiled_code:
__int64 __fastcall ulltos(unsigned __int64 a1)
{
unsigned __int64 v1; // rsi
__int64 i; // rcx
unsigned int v3; // er8
unsigned __int64 v4; // rax

numbuf[20] = 0;
v1 = a1 / 0xA;
numbuf[19] = a1 % 0xA + 48;
if ( a1 <= 9 )
return 19;
for ( i = 18LL; i != -1; --i )
{
v3 = i;
numbuf[i] = v1 % 0xA + 48;
v4 = v1;
v1 /= 0xAuLL;
if ( v4 <= 9 )
break;
v3 = i - 1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int64 a1)
{
unsigned __int64 v1; // rsi
__int64 i; // rcx
unsigned int v3; // er8
unsigned __int64 v4; // rax

numbuf[20] = 0;
v1 = a1 / 0xA;
numbuf[19] = a1 % 0xA + 48;
if ( a1 <= 9 )
return 19;
for ( i = 18LL; i != -1; --i )
{
v3 = i;
numbuf[i] = v1 % 0xA + 48;
v4 = v1;
v1 /= 0xAuLL;
if ( v4 <= 9 )
break;
v3 = i - 1;
}
return v3;
}

original_code:
int
ulltos(unsigned long long n)
{
 int i;
 numbuf[20] = '\0';
 for (i = 19; i >= 0; i--) {
  numbuf[i] = n % 10 + '0';
  if ((n /= 10) == 0) {
   break;
  }
 }
 return (i);
}

variable_types:
n
unsigned long long


flushb

decompiled_code:
ssize_t flushb()
{
ssize_t result; // rax
int v1; // eax

result = (unsigned int)sh_index;
if ( sh_index )
{
*((_BYTE *)bufp + sh_index) = 0;
v1 = length();
result = write(buffd, bufp, v1 - 1);
sh_index = 0;
}
return result;
}

canonical_decompiled_code:
ssize_t func9()
{
ssize_t result; // rax
int v1; // eax

result = (unsigned int)sh_index;
if ( sh_index )
{
*((_BYTE *)bufp + sh_index) = 0;
v1 = length();
result = write(buffd, bufp, v1 - 1);
sh_index = 0;
}
return result;
}

original_code:
void
flushb(void)
{
 if (sh_index) {
  bufp[sh_index] = '\0';
  write(buffd, bufp, length(bufp) - 1);
  sh_index = 0;
 }
}

canonical_original_code:
void flushb()
{
 if (sh_index) {
  bufp[sh_index] = '\0';
  write(buffd, bufp, length(bufp) - 1);
  sh_index = 0;
 }
}


decompiled_code:
ssize_t __fastcall prc_buff(char a1)
{
ssize_t result; // rax
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
if ( a1 )
{
if ( buffd != -1 && sh_index > 254 )
flushb();
LODWORD(result) = sh_index++;
result = (int)result;
*((_BYTE *)bufp + (int)result) = buf[0];
}
else
{
flushb();
result = write(buffd, buf, 1uLL);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func10(char a1)
{
ssize_t result; // rax
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
if ( a1 )
{
if ( buffd != -1 && sh_index > 254 )
func9();
LODWORD(result) = sh_index++;
result = (int)result;
*((_BYTE *)bufp + (int)result) = buf[0];
}
else
{
func9();
result = write(buffd, buf, 1uLL);
}
return result;
}

original_code:
void
prc_buff(unsigned char c)
{
 if (c) {
  if (buffd != -1 && sh_index + 1 >= 256) {
   flushb();
  }
  bufp[sh_index++] = c;
 } else {
  flushb();
  write(buffd, &c, 1);
 }
}


decompiled_code:
ssize_t __fastcall prs_buff(void *buf)
{
int v1; // ebx
ssize_t result; // rax

v1 = length() - 1;
if ( buffd != -1 )
{
if ( sh_index + v1 > 255 )
flushb();
if ( v1 > 255 && buffd != -1 )
return write(buffd, buf, v1);
}
result = movstr(buf, (char *)bufp + sh_index);
sh_index += v1;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func11(void *buf)
{
int v1; // ebx
ssize_t result; // rax

v1 = length() - 1;
if ( buffd != -1 )
{
if ( sh_index + v1 > 255 )
func9();
if ( v1 > 255 && buffd != -1 )
return write(buffd, buf, v1);
}
result = movstr(buf, (char *)bufp + sh_index);
sh_index += v1;
return result;
}

original_code:
void
prs_buff(const unsigned char *s)
{
 int len = length((const char *)s) - 1;
 if (buffd != -1 && sh_index + len >= 256) {
  flushb();
 }
 if (buffd != -1 && len >= 256) {
  write(buffd, (const char *)s, len);
 } else {
  movstr((const char *)s, &bufp[sh_index]);
  sh_index += len;
 }
}

canonical_original_code:
void prs_buff(unsigned char *s)
{
 int len = length((const char *)s) - 1;
 if (buffd != -1 && sh_index + len >= 256) {
  flushb();
 }
 if (buffd != -1 && len >= 256) {
  write(buffd, (char *)s, len);
 } else {
  movstr((char *)s, &bufp[sh_index]);
  sh_index += len;
 }
}

variable_types:
s
unsigned char *


prl

decompiled_code:
ssize_t __fastcall prl(__int64 a1)
{
int v1; // eax

v1 = ltos(a1);
return prs_buff(&numbuf[v1]);
}

canonical_decompiled_code:
ssize_t __fastcall func12(__int64 a1)
{
int v1; // eax

v1 = func7(a1);
return func11(&numbuf[v1]);
}

original_code:
void
prl(long n)
{
 int i;
 i = ltos(n);
 prs_buff(&numbuf[i]);
}


prull

decompiled_code:
ssize_t __fastcall prull(unsigned __int64 a1)
{
int v1; // eax

v1 = ulltos(a1);
return prs_buff(&numbuf[v1]);
}

canonical_decompiled_code:
ssize_t __fastcall func13(unsigned __int64 a1)
{
int v1; // eax

v1 = func8(a1);
return func11(&numbuf[v1]);
}

original_code:
void
prull(unsigned long long n)
{
 int i;
 i = ulltos(n);
 prs_buff(&numbuf[i]);
}