main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
char *v4; // rbx
pthread_t *v5; // rdi
unsigned int i; // ebx
__int64 v7; // rsi
__int64 v8; // rdi
unsigned int v10; // [rsp+Ch] [rbp-FCh] BYREF
pthread_t newthread[4]; // [rsp+10h] [rbp-F8h] BYREF
char v12[216]; // [rsp+30h] [rbp-D8h] BYREF

memset(v12, 0, 0xB8uLL);
v3 = (char *)newthread;
stack10_Constructor(v12, argv, envp);
v4 = (char *)newthread;
do
{
v5 = (pthread_t *)v4;
v4 += 8;
thrd_create_constprop_0_isra_0(v5);
}
while ( v4 != v12 );
for ( i = 0; i != 12; ++i )
{
stack10_pop(v12, &v10);
v7 = i;
printf("%d : %d\n", v7, v10);
}
do
{
v8 = *(_QWORD *)v3;
v3 += 8;
thrd_join_constprop_0_isra_0(v8);
}
while ( v3 != v12 );
stack10_Destructor(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
char *v4; // rbx
pthread_t *v5; // rdi
unsigned int i; // ebx
__int64 v7; // rsi
__int64 v8; // rdi
unsigned int v10; // [rsp+Ch] [rbp-FCh] BYREF
pthread_t newthread[4]; // [rsp+10h] [rbp-F8h] BYREF
char v12[216]; // [rsp+30h] [rbp-D8h] BYREF

memset(v12, 0, 0xB8uLL);
v3 = (char *)newthread;
func19(v12, argv, envp);
v4 = (char *)newthread;
do
{
v5 = (pthread_t *)v4;
v4 += 8;
func13(v5);
}
while ( v4 != v12 );
for ( i = 0; i != 12; ++i )
{
func23(v12, &v10);
v7 = i;
printf("%d : %d\n", v7, v10);
}
do
{
v8 = *(_QWORD *)v3;
v3 += 8;
func14(v8);
}
while ( v3 != v12 );
func20(v3);
return 0;
}

original_code:
int main()
{
 int i, n;
 Stack10 s = {{0},0};
 enum {SIZE = 4};
 thrd_t thr_s[SIZE];
 stack10_Constructor(&s);
 for(i=0; i<SIZE; i++) {
  thrd_create(&thr_s[i], func, (void*)(Stack10*)&s);
 }
 for(i=0; i<(SIZE*3); i++){
  stack10_pop(&s, &n);
  printf("%d : %d\n",i,n);
 }
 for(i=0; i<SIZE; i++) {
  thrd_join(thr_s[i], 0);
 }
 stack10_Destructor(&s);
 return 0;
}

canonical_original_code:
int main()
{
 int i; int n;
 struct Stack s = {{0},0};
 enum {SIZE = 4};
 unsigned long thr_s[-1];
 stack10_Constructor(&s);
 for(i=0; i<SIZE; i++) {
  thrd_create(&thr_s[i], func, (void *)(struct Stack *)&s);
 }
 for(i=0; i<(SIZE*3); i++){
  stack10_pop(&s, &n);
  printf("%d : %d\n",i,n);
 }
 for(i=0; i<SIZE; i++) {
  thrd_join(thr_s[i], 0);
 }
 stack10_Destructor(&s);
 return 0;
}

variable_types: struct Stack { int v_[-1]; int vused_; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mtx_; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cnd_push_; union pthread_cond_t cnd_pop_; }


run

repo: murasesyuka/misc-lang-snippet

decompiled_code:
void __fastcall __noreturn run(void *a1)
{
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
pthread_exit(0LL);
}

original_code:
void* run() {
   pthread_exit(0);
}

canonical_original_code:
void *run() {
   pthread_exit(0);
}

return_type: void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // r12
unsigned int v4; // eax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

for ( i = 0LL; ; ++i )
{
v4 = pthread_create(newthread, 0LL, run, 0LL);
if ( v4 )
break;
}
printf("ERROR, rc is %d, so far %ld threads created\n", v4, i);
perror("Fail:");
return -1;
}

original_code:
int main () {
   pthread_t thread;
   int rc;
   long count = 0;
   while(1) {
    rc = pthread_create(&thread, 0, run, 0);
      if ( rc ) {
         printf("ERROR, rc is %d, so far %ld threads created\n", rc, count);
         perror("Fail:");
         return -1;
      }
      count++;
   }
   return 0;
}

canonical_original_code:
int main() {
   unsigned long thread;
   int rc;
   long count = 0;
   while(1) {
    rc = pthread_create(&thread, 0, run, 0);
      if ( rc ) {
         printf("ERROR, rc is %d, so far %ld threads created\n", rc, count);
         perror("Fail:");
         return -1;
      }
      count++;
   }
   return 0;
}

variable_types:
thread
unsigned long

variable_types: rc int

variable_types: count long

return_type: int


decompiled_code:
int __fastcall print_bytes(char *a1, char *a2)
{
char *v2; // rbx
int v3; // edi
int result; // eax

if ( a1 != a2 )
{
v2 = a1;
do
{
v3 = *v2++;
result = putc(v3, stdout);
}
while ( a2 != v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *a1, char *a2)
{
char *v2; // rbx
int v3; // edi
int result; // eax

if ( a1 != a2 )
{
v2 = a1;
do
{
v3 = *v2++;
result = putc(v3, stdout);
}
while ( a2 != v2 );
}
return result;
}

original_code:
void print_bytes(char *start, char *end) {
 while (start != end) {
  putc(*start++, stdout);
 }
}

variable_types:
start
char *

variable_types:
end
char *

return_type: void


decompiled_code:
int __fastcall print_token(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, unsigned int a7, char *a8, char *a9)
{
size_t v9; // rax

switch ( a7 )
{
case 1u:
if ( first )
first = 0;
else
putc(10, stdout);
printf("%s<", indent);
goto LABEL_6;
case 2u:
if ( first )
first = 0;
else
putc(10, stdout);
printf("%s</", indent);
LABEL_6:
print_bytes(a8, a9);
putc(62, stdout);
v9 = strlen(indent);
*(_WORD *)&indent[v9] = 8224;
indent[v9 + 2] = 0;
return v9;
case 4u:
printf("\n%s", indent);
goto LABEL_11;
case 5u:
putc(61, stdout);
LABEL_11:
LODWORD(v9) = print_bytes(a8, a9);
break;
case 6u:
printf("\n%s<!-- ", indent);
print_bytes(a8, a9);
LODWORD(v9) = printf(" -->");
break;
default:
LODWORD(v9) = printf("\nhere %d, %d\n", a7, a9 - a8);
break;
}
return v9;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, unsigned int a7, char *a8, char *a9)
{
size_t v9; // rax

switch ( a7 )
{
case 1u:
if ( first )
first = 0;
else
putc(10, stdout);
printf("%s<", indent);
goto LABEL_6;
case 2u:
if ( first )
first = 0;
else
putc(10, stdout);
printf("%s</", indent);
LABEL_6:
func0(a8, a9);
putc(62, stdout);
v9 = strlen(indent);
*(_WORD *)&indent[v9] = 8224;
indent[v9 + 2] = 0;
return v9;
case 4u:
printf("\n%s", indent);
goto LABEL_11;
case 5u:
putc(61, stdout);
LABEL_11:
LODWORD(v9) = func0(a8, a9);
break;
case 6u:
printf("\n%s<!-- ", indent);
func0(a8, a9);
LODWORD(v9) = printf(" -->");
break;
default:
LODWORD(v9) = printf("\nhere %d, %d\n", a7, a9 - a8);
break;
}
return v9;
}

original_code:
void print_token(html5token token) {
 switch (token.type) {
 case 1:
  if (first) {
   first = 0;
  } else {
   putc('\n', stdout);
  }
  printf("%s<", indent);
  print_bytes(token.start, token.end);
  putc('>', stdout);
  strcat(indent, "  ");
  break;
 case 2:
  if (first) {
   first = 0;
  } else {
   putc('\n', stdout);
  }
  printf("%s</", indent);
  print_bytes(token.start, token.end);
  putc('>', stdout);
  strcat(indent, "  ");
  break;
 case 4:
  printf("\n%s", indent);
  print_bytes(token.start, token.end);
  break;
 case 5:
  putc('=', stdout);
  print_bytes(token.start, token.end);
  break;
 case 6:
  printf("\n%s<!-- ", indent);
  print_bytes(token.start, token.end);
  printf(" -->");
  break;
 default:
  printf("\nhere %d, %d\n", token.type, token.end - token.start);
  break;
 }
}

canonical_original_code:
void print_token(struct html5token token) {
 switch (token.type) {
 case 1:
  if (first) {
   first = 0;
  } else {
   putc('\n', stdout);
  }
  printf("%s<", indent);
  print_bytes(token.start, token.end);
  putc('>', stdout);
  strcat(indent, "  ");
  break;
 case 2:
  if (first) {
   first = 0;
  } else {
   putc('\n', stdout);
  }
  printf("%s</", indent);
  print_bytes(token.start, token.end);
  putc('>', stdout);
  strcat(indent, "  ");
  break;
 case 4:
  printf("\n%s", indent);
  print_bytes(token.start, token.end);
  break;
 case 5:
  putc('=', stdout);
  print_bytes(token.start, token.end);
  break;
 case 6:
  printf("\n%s<!-- ", indent);
  print_bytes(token.start, token.end);
  printf(" -->");
  break;
 default:
  printf("\nhere %d, %d\n", token.type, token.end - token.start);
  break;
 }
}

variable_types: struct html5token { int type; int complete; char *start; char *end; }


original_code:
int main(int argc, char** argv) {
 static const int BUFSIZE = 1024;
 char buffer[BUFSIZE];
 char *start;
 char *end;
 size_t count;
 rlstate s;
 html5token token;
 html5rl_init(&s);
 int done = 0;
 while (!done) {
  count = fread(buffer, sizeof(char), BUFSIZE, stdin);
  if (count <= 0) {
   html5rl_exec(&s, ((void *)0), ((void *)0));
   done = 1;
  } else {
   start = buffer;
   end = buffer + count;
   do
   {
    token = html5rl_exec(&s, start, end);
    start = s.p;
    print_token(token);
   }
   while (token.end != end);
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 static int BUFSIZE = 1024;
 char buffer[-1];
 char *start;
 char *end;
 unsigned long count;
 struct rlstate s;
 struct html5token token;
 html5rl_init(&s);
 int done = 0;
 while (!done) {
  count = fread(buffer, sizeof(char), BUFSIZE, stdin);
  if (count <= 0) {
   html5rl_exec(&s, ((void *)0), ((void *)0));
   done = 1;
  } else {
   start = buffer;
   end = buffer + count;
   do
   {
    token = html5rl_exec(&s, start, end);
    start = s.p;
    print_token(token);
   }
   while (token.end != end);
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: BUFSIZE int

variable_types:
buffer
char [-1]

variable_types:
count
unsigned long

variable_types: struct rlstate { int cs; int act; char *p; char *pe; char *eof; char *ts; char *te; }

variable_types: done int

user_defined_types: struct html5token { int type; int complete; char *start; char *end; }


repo: mustafakaraca/mkap

decompiled_code:
void __fastcall signal_handler(int a1)
{
if ( a1 == 2 )
{
signal_interrupt = 1;
signal(2, signal_handler);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 2 )
{
signal_interrupt = 1;
signal(2, signal_handler);
}
}

original_code:
static void signal_handler(int s)
{
 switch(s){
 case 2:
  signal_interrupt = 1;
  signal(2, signal_handler);
  break;
 default:
  break;
 }
 return;
}

variable_types: s int


decompiled_code:
__int64 __fastcall get_arptype(char *src, int fd)
{
__int64 result; // rax
char v3; // [rsp-8h] [rbp-38h] BYREF
__int128 v4; // [rsp+0h] [rbp-30h]
__int128 v5; // [rsp+10h] [rbp-20h]

result = 1LL;
if ( src )
{
v4 = 0LL;
v5 = 0LL;
strncpy(&v3, src, 0xFuLL);
if ( ioctl(fd, 0x8927uLL, &v3) < 0 )
{
perror("get_arptype: ioctl (SIOCGIFHWADDR):");
result = 0xFFFFFFFFLL;
}
else
{
result = WORD4(v4);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, int fd)
{
__int64 result; // rax
char v3; // [rsp-8h] [rbp-38h] BYREF
__int128 v4; // [rsp+0h] [rbp-30h]
__int128 v5; // [rsp+10h] [rbp-20h]

result = 1LL;
if ( src )
{
v4 = 0LL;
v5 = 0LL;
strncpy(&v3, src, 0xFuLL);
if ( ioctl(fd, 0x8927uLL, &v3) < 0 )
{
perror("get_arptype: ioctl (SIOCGIFHWADDR):");
result = 0xFFFFFFFFLL;
}
else
{
result = WORD4(v4);
}
}
return result;
}

original_code:
static int get_arptype(char *ifname, int sockfd)
{
 struct ifreq ifr;
 if (!ifname)
  return 1;
 memset(&ifr, 0, sizeof(ifr));
 strncpy(ifr.ifr_ifrn.ifrn_name, ifname, 16 - 1);
 if (ioctl(sockfd, 0x8927, &ifr) < 0){
  perror("get_arptype: ioctl (SIOCGIFHWADDR):");
  return -1;
 }
 return ifr.ifr_ifru.ifru_hwaddr.sa_family;
}

variable_types:
ifname
char *

variable_types: sockfd 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]; char *ifru_data; } ifr_ifru; }

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]; char *ifru_data; } ifr_ifru; }


decompiled_code:
__int64 __fastcall create_capture_socket(char *src)
{
int v1; // ebx
int v2; // eax
unsigned int v3; // er12
__int64 v4; // rcx
char *v5; // rdi
int v6; // eax
struct sockaddr v8[2]; // [rsp+0h] [rbp-68h] BYREF
char dest[8]; // [rsp+20h] [rbp-48h] BYREF
__int128 v10; // [rsp+28h] [rbp-40h]
__int128 v11; // [rsp+38h] [rbp-30h]

v1 = (unsigned __int16)_bswap_16(3);
v2 = socket(17, 3, v1);
if ( v2 < 0 )
{
v3 = -1;
perror("create_capture_socket: socket : ");
return v3;
}
v3 = v2;
if ( src )
{
v10 = 0LL;
v11 = 0LL;
strncpy(dest, src, 0xFuLL);
if ( ioctl(v3, 0x8933uLL, dest) < 0 )
{
perror("create_capture_socket: ioctl(SIOCGIFINDEX) :");
}
else
{
v4 = 3LL;
v5 = &v8[0].sa_data[6];
v8[0].sa_family = 17;
while ( v4 )
{
*(_DWORD *)v5 = 0;
v5 += 4;
--v4;
}
*(_WORD *)v8[0].sa_data = v1;
*(_DWORD *)&v8[0].sa_data[2] = DWORD2(v10);
if ( bind(v3, v8, 0x14u) < 0 )
{
perror("create_capture_socket: bind()");
}
else
{
v6 = fcntl(v3, 3);
if ( v6 >= 0 )
{
BYTE1(v6) |= 8u;
if ( fcntl(v3, 4, (unsigned int)v6) < 0 )
perror("create_capture_socket: fcntl(F_SETFL)");
return v3;
}
perror("create_capture_socket: fcntl(F_GETFL):");
}
}
while ( close(v3) <= 0 && *_errno_location() == 4 )
;
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src)
{
int v1; // ebx
int v2; // eax
unsigned int v3; // er12
__int64 v4; // rcx
char *v5; // rdi
int v6; // eax
struct sockaddr v8[2]; // [rsp+0h] [rbp-68h] BYREF
char dest[8]; // [rsp+20h] [rbp-48h] BYREF
__int128 v10; // [rsp+28h] [rbp-40h]
__int128 v11; // [rsp+38h] [rbp-30h]

v1 = (unsigned __int16)func2(3);
v2 = socket(17, 3, v1);
if ( v2 < 0 )
{
v3 = -1;
perror("create_capture_socket: socket : ");
return v3;
}
v3 = v2;
if ( src )
{
v10 = 0LL;
v11 = 0LL;
strncpy(dest, src, 0xFuLL);
if ( ioctl(v3, 0x8933uLL, dest) < 0 )
{
perror("create_capture_socket: ioctl(SIOCGIFINDEX) :");
}
else
{
v4 = 3LL;
v5 = &v8[0].sa_data[6];
v8[0].sa_family = 17;
while ( v4 )
{
*(_DWORD *)v5 = 0;
v5 += 4;
--v4;
}
*(_WORD *)v8[0].sa_data = v1;
*(_DWORD *)&v8[0].sa_data[2] = DWORD2(v10);
if ( bind(v3, v8, 0x14u) < 0 )
{
perror("create_capture_socket: bind()");
}
else
{
v6 = fcntl(v3, 3);
if ( v6 >= 0 )
{
BYTE1(v6) |= 8u;
if ( fcntl(v3, 4, (unsigned int)v6) < 0 )
perror("create_capture_socket: fcntl(F_SETFL)");
return v3;
}
perror("create_capture_socket: fcntl(F_GETFL):");
}
}
while ( close(v3) <= 0 && *_errno_location() == 4 )
;
v3 = -1;
}
return v3;
}

original_code:
static int create_capture_socket(char *ifname)
{
 int sock_raw;
 struct ifreq ifr;
 struct sockaddr_ll sll;
 struct packet_mreq mrq;
 int fdflags;
 sock_raw = socket(17, SOCK_RAW, htons(0x0003));
 if (sock_raw < 0){
  perror("create_capture_socket: socket : ");
  return -1;
 }
 if (!ifname)
  return sock_raw;
 memset(&ifr, 0, sizeof(ifr));
 strncpy(ifr.ifr_ifrn.ifrn_name, ifname, 16 - 1);
 if (ioctl(sock_raw, 0x8933, &ifr) < 0){
  perror("create_capture_socket: ioctl(SIOCGIFINDEX) :");
  goto err1;
 }
 memset(&sll, 0, sizeof(sll));
 sll.sll_family = 17;
 sll.sll_ifindex = ifr.ifr_ifru.ifru_ivalue;
 sll.sll_protocol = htons(0x0003);
 if (bind(sock_raw, (struct sockaddr *)&sll, sizeof(sll)) < 0){
  perror("create_capture_socket: bind()");
  goto err1;
 }
 fdflags = fcntl(sock_raw, 3);
 if (fdflags < 0){
  perror("create_capture_socket: fcntl(F_GETFL):");
  goto err1;
 }
 if (fcntl(sock_raw, 4, fdflags | 04000) < 0){
  perror("create_capture_socket: fcntl(F_SETFL)");
 }
 return sock_raw;
err1:
 while((close(sock_raw) < 1) && ((*__errno_location ()) == 4));
 return -1;
}

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }

variable_types: struct packet_mreq { int mr_ifindex; unsigned short mr_type; unsigned short mr_alen; unsigned char mr_address[8]; }

variable_types: fdflags int

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

user_defined_types: struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; }


original_code:
static int check_mkap_conn(unsigned char *buffer, int len, unsigned int linktype)
{
 struct ether_header *ethh;
 struct iphdr *iph;
 struct tcphdr *tcph;
 int ipoffset = 0;
 unsigned short ether_type;
 if (linktype == 1) {
  ipoffset += sizeof(*ethh);
  if (len < (ipoffset + sizeof(*iph)))
   return 0;
  ethh = (struct ether_header *)buffer;
  ether_type = ethh->ether_type;
  if (ether_type == htons(0x8100)) {
   ipoffset += 4;
   if (len < (ipoffset + sizeof(*iph)))
    return 0;
   ether_type = *(unsigned short *)(buffer + sizeof(*ethh) + 2);
  }
  if (ether_type != htons(0x0800))
   return 0;
 } else if (linktype == 12) {
  if (len < sizeof(*iph))
   return 0;
 }
 iph = (struct iphdr *)(buffer + ipoffset);
 if (iph->protocol != IPPROTO_TCP)
  return 0;
 if (len < (ipoffset + iph->ihl * 4 + sizeof(*tcph)))
  return 0;
 tcph = (struct tcphdr *)(buffer + ipoffset + iph->ihl * 4);
 if (tcph->dest != htons(54321) && tcph->source != htons(54321))
  return 0;
 return 1;
}

variable_types:
buffer
unsigned char *

variable_types: len int

variable_types:
linktype
unsigned int

variable_types: struct ether_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; } *

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

variable_types: struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; } *

variable_types: ipoffset int


decompiled_code:
__int64 get_tcp_sock()
{
int v0; // eax
int v1; // ebp
socklen_t v2; // edx
unsigned int v3; // er12
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v6; // [rsp+10h] [rbp-28h] BYREF

v0 = socket(2, 1, 6);
if ( v0 < 0 )
return (unsigned int)-1;
v1 = v0;
optval = 1;
setsockopt(v0, 1, 2, &optval, 4u);
v6 = 0LL;
v6.sa_family = 2;
*(_WORD *)v6.sa_data = _bswap_16(54321);
if ( bind(v1, &v6, v2) || listen(v1, 3) )
{
v3 = -1;
close(v1);
}
else
{
v3 = accept(v1, 0LL, 0LL);
close(v1);
}
return v3;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // eax
int v1; // ebp
socklen_t v2; // edx
unsigned int v3; // er12
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v6; // [rsp+10h] [rbp-28h] BYREF

v0 = socket(2, 1, 6);
if ( v0 < 0 )
return (unsigned int)-1;
v1 = v0;
optval = 1;
setsockopt(v0, 1, 2, &optval, 4u);
v6 = 0LL;
v6.sa_family = 2;
*(_WORD *)v6.sa_data = func2(54321);
if ( bind(v1, &v6, v2) || listen(v1, 3) )
{
v3 = -1;
close(v1);
}
else
{
v3 = accept(v1, 0LL, 0LL);
close(v1);
}
return v3;
}

original_code:
static int get_tcp_sock()
{
 int serversock, clientsock, yes;
 struct sockaddr_in addr;
 serversock = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (serversock < 0)
  return -1;
 yes = 1;
 setsockopt(serversock, 1, 2, &yes, sizeof(yes));
 memset(&addr, 0, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_port = htons(54321);
 addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 if (bind(serversock, (struct sockaddr *)&addr, sizeof(addr)))
  goto err;
 if (listen(serversock, 3))
  goto err;
 clientsock = accept(serversock, ((void *)0), ((void *)0));
 close(serversock);
 return clientsock;
err:
 close(serversock);
 return -1;
}

canonical_original_code:
static int get_tcp_sock()
{
 int serversock; int clientsock; int yes;
 struct sockaddr_in addr;
 serversock = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (serversock < 0)
  return -1;
 yes = 1;
 setsockopt(serversock, 1, 2, &yes, sizeof(yes));
 memset(&addr, 0, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_port = htons(54321);
 addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 if (bind(serversock, (struct sockaddr *)&addr, sizeof(addr)))
  goto err;
 if (listen(serversock, 3))
  goto err;
 clientsock = accept(serversock, ((void *)0), ((void *)0));
 close(serversock);
 return clientsock;
err:
 close(serversock);
 return -1;
}

variable_types: serversock int

variable_types: clientsock int

variable_types: yes int

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

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


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; // ebp
int v7; // eax
unsigned int v8; // eax
FILE *v9; // rbx
int v10; // edi
int v11; // eax
signed int v12; // eax
int v13; // er12
int v14; // eax
struct pollfd fds; // [rsp+8h] [rbp-10070h] BYREF
int v16[4]; // [rsp+10h] [rbp-10068h] BYREF
struct timeval tv; // [rsp+20h] [rbp-10058h] BYREF
__int64 ptr[2]; // [rsp+30h] [rbp-10048h] BYREF
int v19; // [rsp+40h] [rbp-10038h]
int v20; // [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);
if ( v6 >= 0 )
{
ptr[1] = 0LL;
ptr[0] = 0x40002A1B2C3D4LL;
v19 = 0xFFFF;
v7 = get_arptype(v4, v6);
switch ( v7 )
{
case 1:
puts("linktype: ARPHRD_ETHER");
v20 = 1;
break;
case 512:
puts("linktype: ARPHRD_PPP");
v20 = 12;
break;
case -1:
puts("cannot get interface arp type");
exit(1);
default:
v8 = get_arptype(v4, v6);
printf("unsupported linktype %d\n", v8);
exit(1);
}
if ( v3 )
{
v9 = fopen(v3, "wb");
}
else
{
attach_mkap_conn_filter_isra_0(v6, v20);
v10 = get_tcp_sock();
if ( v10 < 0 )
{
puts("get_tcp_sock() failed");
exit(1);
}
v9 = fdopen(v10, "wb");
}
if ( v9 )
{
if ( fwrite(ptr, 1uLL, 0x18uLL, v9) != 24 )
{
puts("error on writing PCAP file header");
exit(1);
}
fflush(v9);
signal(2, signal_handler);
fds.fd = v6;
fds.events = 1;
while ( !signal_interrupt )
{
v11 = poll(&fds, 1uLL, 1000);
if ( v11 )
{
if ( v11 < 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);
}
v12 = read(v6, buf, 0x10000uLL);
v13 = v12;
if ( v12 < 0 )
{
v14 = *_errno_location();
if ( v14 != 4 && v14 != 11 )
{
perror("read():");
exit(1);
}
}
else
{
if ( !v12 )
{
puts("raw socket closed");
exit(0);
}
if ( v3 || !check_mkap_conn(buf, v12, v20) )
{
if ( gettimeofday(&tv, 0LL) < 0 )
{
perror("main: gettimeofday():");
exit(1);
}
v16[3] = v13;
v16[0] = tv.tv_sec;
v16[2] = v13;
v16[1] = tv.tv_usec;
if ( fwrite(v16, 1uLL, 0x10uLL, v9) != 16 )
{
puts("error on writing packet header");
exit(1);
}
if ( v13 != fwrite(buf, 1uLL, v13, v9) )
{
puts("error on writing to capture file");
exit(1);
}
fflush(v9);
}
}
}
}
}
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; // ebp
int v7; // eax
unsigned int v8; // eax
FILE *v9; // rbx
int v10; // edi
int v11; // eax
signed int v12; // eax
int v13; // er12
int v14; // eax
struct pollfd fds; // [rsp+8h] [rbp-10070h] BYREF
int v16[4]; // [rsp+10h] [rbp-10068h] BYREF
struct timeval tv; // [rsp+20h] [rbp-10058h] BYREF
__int64 ptr[2]; // [rsp+30h] [rbp-10048h] BYREF
int v19; // [rsp+40h] [rbp-10038h]
int v20; // [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);
if ( v6 >= 0 )
{
ptr[1] = 0LL;
ptr[0] = 0x40002A1B2C3D4LL;
v19 = 0xFFFF;
v7 = func1(v4, v6);
switch ( v7 )
{
case 1:
puts("linktype: ARPHRD_ETHER");
v20 = 1;
break;
case 512:
puts("linktype: ARPHRD_PPP");
v20 = 12;
break;
case -1:
puts("cannot get interface arp type");
exit(1);
default:
v8 = func1(v4, v6);
printf("unsupported linktype %d\n", v8);
exit(1);
}
if ( v3 )
{
v9 = fopen(v3, "wb");
}
else
{
func6(v6, v20);
v10 = func5();
if ( v10 < 0 )
{
puts("get_tcp_sock() failed");
exit(1);
}
v9 = fdopen(v10, "wb");
}
if ( v9 )
{
if ( fwrite(ptr, 1uLL, 0x18uLL, v9) != 24 )
{
puts("error on writing PCAP file header");
exit(1);
}
fflush(v9);
signal(2, signal_handler);
fds.fd = v6;
fds.events = 1;
while ( !signal_interrupt )
{
v11 = poll(&fds, 1uLL, 1000);
if ( v11 )
{
if ( v11 < 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);
}
v12 = read(v6, buf, 0x10000uLL);
v13 = v12;
if ( v12 < 0 )
{
v14 = *_errno_location();
if ( v14 != 4 && v14 != 11 )
{
perror("read():");
exit(1);
}
}
else
{
if ( !v12 )
{
puts("raw socket closed");
exit(0);
}
if ( v3 || !func4(buf, v12, v20) )
{
if ( gettimeofday(&tv, 0LL) < 0 )
{
perror("main: gettimeofday():");
exit(1);
}
v16[3] = v13;
v16[0] = tv.tv_sec;
v16[2] = v13;
v16[1] = tv.tv_usec;
if ( fwrite(v16, 1uLL, 0x10uLL, v9) != 16 )
{
puts("error on writing packet header");
exit(1);
}
if ( v13 != fwrite(buf, 1uLL, v13, v9) )
{
puts("error on writing to capture file");
exit(1);
}
fflush(v9);
}
}
}
}
}
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]


decompiled_code:
__int64 open_tap_dev()
{
int v0; // er12
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) )
{
v0 = -1;
perror("mknod()");
}
else
{
v0 = open(v4, 2);
unlink(v4);
}
}
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // er12
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) )
{
v0 = -1;
perror("mknod()");
}
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


decompiled_code:
int get_ioctl_sock()
{
int result; // eax

result = s_0;
if ( s_0 < 0 )
{
result = socket(2, 2, 0);
s_0 = result;
if ( result < 0 )
result = -1;
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax

result = s_0;
if ( s_0 < 0 )
{
result = socket(2, 2, 0);
s_0 = result;
if ( result < 0 )
result = -1;
}
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 v2; // eax
unsigned int v3; // er12
int v4; // edi
__int16 v5; // ax
int v7; // edi
char v8[16]; // [rsp+0h] [rbp-58h] BYREF
char src[16]; // [rsp+10h] [rbp-48h] BYREF
__int128 v10; // [rsp+20h] [rbp-38h]
__int64 v11; // [rsp+30h] [rbp-28h]

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

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
int v2; // eax
unsigned int v3; // er12
int v4; // edi
__int16 v5; // ax
int v7; // edi
char v8[16]; // [rsp+0h] [rbp-58h] BYREF
char src[16]; // [rsp+10h] [rbp-48h] BYREF
__int128 v10; // [rsp+20h] [rbp-38h]
__int64 v11; // [rsp+30h] [rbp-28h]

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

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


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // er8
int v5; // ebx
unsigned int v6; // edi
int v7; // ebp
unsigned int v8; // er8
unsigned int v9; // er8
size_t v10; // rax
unsigned int v11; // er12
int *v12; // rax
char *v13; // rax
int result; // eax
unsigned int v15; // [rsp+0h] [rbp-10048h] BYREF
unsigned int v16; // [rsp+4h] [rbp-10044h]
size_t n; // [rsp+8h] [rbp-10040h]
int ptr; // [rsp+10h] [rbp-10038h] BYREF
int v19; // [rsp+14h] [rbp-10034h]
unsigned int v20; // [rsp+18h] [rbp-10030h]
unsigned int v21; // [rsp+20h] [rbp-10028h]
unsigned int v22; // [rsp+24h] [rbp-10024h]
char buf[65560]; // [rsp+30h] [rbp-10018h] BYREF

if ( fread(&ptr, 1uLL, 0x18uLL, stdin) != 24 )
{
perror("fread(gheader)");
return -1;
}
if ( ptr == -1582119980 )
{
v5 = 0;
}
else
{
v3 = _bswap_32(0xA1B2C3D4);
if ( v4 != v3 )
{
puts("bad magic");
return -1;
}
v5 = 1;
ptr = _bswap_32(v4);
LOWORD(v19) = _bswap_16(v19);
HIWORD(v19) = _bswap_16(SHIWORD(v19));
v20 = _bswap_32(v20);
v21 = _bswap_32(v21);
v22 = _bswap_32(v22);
}
if ( v19 != 262146 )
{
puts("pcap version does not match");
return -1;
}
if ( v22 == 105 )
{
v6 = 801;
}
else if ( v22 <= 0x69 )
{
if ( v22 == 1 )
{
v6 = 1;
}
else
{
if ( v22 != 12 )
goto LABEL_30;
v6 = 512;
}
}
else
{
if ( v22 != 119 )
{
if ( v22 == 127 )
{
v6 = 803;
goto LABEL_11;
}
LABEL_30:
puts("unrecognized linktype");
return -1;
}
v6 = 802;
}
LABEL_11:
v7 = setup_tap_dev(v6);
if ( v7 < 0 )
{
perror("setup_tap_dev()");
result = -1;
}
else
{
puts("interface setup complete. writing packets");
while ( 1 )
{
if ( fread(&v15, 1uLL, 0x10uLL, stdin) != 16 )
{
perror("fread(pheader)");
return 0;
}
v8 = n;
if ( v5 )
{
v15 = _bswap_32(v15);
v16 = _bswap_32(v16);
LODWORD(n) = _bswap_32(v9);
HIDWORD(n) = _bswap_32(HIDWORD(n));
}
v10 = fread(buf, 1uLL, v8, stdin);
if ( v10 != (unsigned int)n )
break;
if ( (_DWORD)n == HIDWORD(n) )
{
v11 = write(v7, buf, v10);
if ( (_DWORD)n != v11 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(stderr, "write(): %d-%s\n", v11, v13);
}
}
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)
{
int v3; // eax
unsigned int v4; // er8
int v5; // ebx
unsigned int v6; // edi
int v7; // ebp
unsigned int v8; // er8
unsigned int v9; // er8
size_t v10; // rax
unsigned int v11; // er12
int *v12; // rax
char *v13; // rax
int result; // eax
unsigned int v15; // [rsp+0h] [rbp-10048h] BYREF
unsigned int v16; // [rsp+4h] [rbp-10044h]
size_t n; // [rsp+8h] [rbp-10040h]
int ptr; // [rsp+10h] [rbp-10038h] BYREF
int v19; // [rsp+14h] [rbp-10034h]
unsigned int v20; // [rsp+18h] [rbp-10030h]
unsigned int v21; // [rsp+20h] [rbp-10028h]
unsigned int v22; // [rsp+24h] [rbp-10024h]
char buf[65560]; // [rsp+30h] [rbp-10018h] BYREF

if ( fread(&ptr, 1uLL, 0x18uLL, stdin) != 24 )
{
perror("fread(gheader)");
return -1;
}
if ( ptr == -1582119980 )
{
v5 = 0;
}
else
{
v3 = func3(0xA1B2C3D4);
if ( v4 != v3 )
{
puts("bad magic");
return -1;
}
v5 = 1;
ptr = func3(v4);
LOWORD(v19) = func0(v19);
HIWORD(v19) = func0(SHIWORD(v19));
v20 = func3(v20);
v21 = func3(v21);
v22 = func3(v22);
}
if ( v19 != 262146 )
{
puts("pcap version does not match");
return -1;
}
if ( v22 == 105 )
{
v6 = 801;
}
else if ( v22 <= 0x69 )
{
if ( v22 == 1 )
{
v6 = 1;
}
else
{
if ( v22 != 12 )
goto LABEL_30;
v6 = 512;
}
}
else
{
if ( v22 != 119 )
{
if ( v22 == 127 )
{
v6 = 803;
goto LABEL_11;
}
LABEL_30:
puts("unrecognized linktype");
return -1;
}
v6 = 802;
}
LABEL_11:
v7 = func5(v6);
if ( v7 < 0 )
{
perror("setup_tap_dev()");
result = -1;
}
else
{
puts("interface setup complete. writing packets");
while ( 1 )
{
if ( fread(&v15, 1uLL, 0x10uLL, stdin) != 16 )
{
perror("fread(pheader)");
return 0;
}
v8 = n;
if ( v5 )
{
v15 = func3(v15);
v16 = func3(v16);
LODWORD(n) = func3(v9);
HIDWORD(n) = func3(HIDWORD(n));
}
v10 = fread(buf, 1uLL, v8, stdin);
if ( v10 != (unsigned int)n )
break;
if ( (_DWORD)n == HIDWORD(n) )
{
v11 = write(v7, buf, v10);
if ( (_DWORD)n != v11 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(stderr, "write(): %d-%s\n", v11, v13);
}
}
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)
{
__int64 v1; // rax
__int64 v2; // r10

v1 = single_rotate_right(*(_QWORD *)(a1 + 24));
*(_QWORD *)(v2 + 24) = v1;
return single_rotate_left(v2);
}

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)
{
__int64 v1; // rax
__int64 v2; // r11

v1 = single_rotate_left(*(_QWORD *)(a1 + 16));
*(_QWORD *)(v2 + 16) = v1;
return single_rotate_right(v2);
}

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
__int64 v2; // rcx
int v3; // eax
int v4; // edx

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
int v3; // eax
int v4; // edx

result = 0LL;
if ( a1 )
{
func0(*(_QWORD *)(a1 + 16));
v3 = func0(*(_QWORD *)(v2 + 24));
result = (unsigned int)(v4 - v3);
}
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)
{
unsigned int v1; // er9
int v2; // eax
__int64 v3; // r8
__int64 v4; // rbp
int v5; // esi
int v6; // eax
__int64 v7; // r8
int v8; // er9
int v9; // ecx
int v10; // edx
bool v11; // cc
int v12; // eax
__int64 v14; // r10

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

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)
{
__int64 v1; // r12
int v2; // eax
int v4; // eax
int v5; // eax

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

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

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

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:
_QWORD *avl_tree_create()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x20uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
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:
_QWORD *func8()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x20uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
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);
}


decompiled_code:
__int64 __fastcall avl_tree_insert(__int64 a1, const char *a2, unsigned int a3)
{
int v5; // eax
_QWORD *v6; // rdi
__int64 v7; // rax
__int64 v8; // rdi
__int64 v9; // r8
__int64 v10; // rdi
int v11; // eax
int v12; // ecx
int v13; // edx
bool v14; // cc
int v15; // eax
_QWORD *v17; // rdi
__int64 v18; // rax
size_t v19; // rax
char *v20; // rax
_QWORD *v21; // rax
_QWORD *v22; // rax

if ( !(unsigned int)invariant(a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0xB7u, "avl_tree_insert");
if ( !*(_QWORD *)a1 )
{
v19 = strlen(a2);
v20 = (char *)malloc(v19 + 1);
*(_QWORD *)a1 = v20;
strcpy(v20, 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");
return a1;
}
v5 = strcmp(a2, *(const char **)a1);
if ( v5 < 0 )
{
v17 = *(_QWORD **)(a1 + 16);
if ( !v17 )
{
v22 = avl_tree_create();
*(_QWORD *)(a1 + 16) = v22;
v17 = v22;
}
v18 = avl_tree_insert(v17, a2, a3);
*(_QWORD *)(a1 + 16) = v18;
height(v18);
v10 = *(_QWORD *)(a1 + 24);
goto LABEL_8;
}
if ( !v5 )
{
*(_DWORD *)(a1 + 8) = a3;
return a1;
}
v6 = *(_QWORD **)(a1 + 24);
if ( !v6 )
{
v21 = avl_tree_create();
*(_QWORD *)(a1 + 24) = v21;
v6 = v21;
}
v7 = avl_tree_insert(v6, a2, a3);
v8 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 24) = v7;
height(v8);
v10 = v9;
LABEL_8:
v11 = height(v10);
v12 = v11 + 1;
v14 = v13 <= v11;
v15 = v13 + 1;
if ( v14 )
v15 = v12;
*(_DWORD *)(a1 + 12) = v15;
return balance_update(a1);
}

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(const char **a1, const char *a2)
{
const char *v4; // rsi
int v5; // eax

while ( 1 )
{
while ( 1 )
{
if ( !(unsigned int)invariant((__int64)a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0xDCu, "avl_tree_find");
v4 = *a1;
if ( !*a1 )
return v4;
v5 = strcmp(a2, v4);
if ( v5 >= 0 )
break;
a1 = (const char **)a1[2];
if ( !a1 )
return 0LL;
}
if ( !v5 )
break;
a1 = (const char **)a1[3];
if ( !a1 )
return 0LL;
}
return (const char *)(a1 + 1);
}

canonical_decompiled_code:
const char *__fastcall func11(const char **a1, const char *a2)
{
const char *v4; // rsi
int v5; // eax

while ( 1 )
{
while ( 1 )
{
if ( !(unsigned int)func6((__int64)a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0xDCu, "avl_tree_find");
v4 = *a1;
if ( !*a1 )
return v4;
v5 = strcmp(a2, v4);
if ( v5 >= 0 )
break;
a1 = (const char **)a1[2];
if ( !a1 )
return 0LL;
}
if ( !v5 )
break;
a1 = (const char **)a1[3];
if ( !a1 )
return 0LL;
}
return (const char *)(a1 + 1);
}

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(const char **a1, const char *a2)
{
const char *v2; // rax

if ( !(unsigned int)invariant((__int64)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((__int64)a1, a2, 1u);
++*(_DWORD *)v2;
return (__int64)a1;
}

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

if ( !(unsigned int)func6((__int64)a1) )
_assert_fail("invariant(root)", "sources/avl_tree.c", 0x109u, "avl_tree_increase");
v2 = func11(a1, a2);
if ( !v2 )
return func10((__int64)a1, a2, 1u);
++*(_DWORD *)v2;
return (__int64)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:
unsigned __int64 __fastcall is_end_of_sentence(unsigned __int8 a1)
{
unsigned __int64 result; // rax

result = 0LL;
if ( a1 <= 0x3Fu )
result = (0x8000400200000000LL >> a1) & 1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func16(unsigned __int8 a1)
{
unsigned __int64 result; // rax

result = 0LL;
if ( a1 <= 0x3Fu )
result = (0x8000400200000000LL >> a1) & 1;
return result;
}

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:
unsigned __int64 __fastcall check_sentence_end(unsigned __int8 a1, int *a2)
{
unsigned __int64 result; // rax
__int64 (*v3)(void); // rdx

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

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

result = func16(a1);
if ( (_DWORD)result )
{
if ( *a2 > 0 )
{
result = v3();
*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, int *a3, _DWORD *a4, __int64 (__fastcall *a5)(__int64))
{
_BOOL4 v8; // er8
__int64 result; // rax

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

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

v8 = func19(a1);
result = *a3;
if ( v8 )
{
*(_BYTE *)(a2 + result) = a1;
++*a3;
}
else
{
if ( (int)result > 1 )
{
*(_BYTE *)(a2 + 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(argc, argv, envp);
test_punctuation();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func14(argc, argv, envp);
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:
_QWORD *int_counts_create()
{
void *v0; // rbx
_QWORD *result; // rax

v0 = calloc(0x320uLL, 1uLL);
result = malloc(0x18uLL);
if ( result )
{
*result = v0;
result[1] = 0xFFFFFFFF7FFFFFFFLL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

canonical_decompiled_code:
_QWORD *func16()
{
void *v0; // rbx
_QWORD *result; // rax

v0 = calloc(0x320uLL, 1uLL);
result = malloc(0x18uLL);
if ( result )
{
*result = v0;
result[1] = 0xFFFFFFFF7FFFFFFFLL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

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

decompiled_code:
__int64 chkmail()
{
const char *v0; // rdi
__time_t *v1; // r13
__int64 result; // rax
char *v3; // rbx
char *v4; // rbp
__int16 v5; // r12
__time_t v6; // rax
struct stat64 v7; // [rsp+0h] [rbp-B8h] BYREF

v0 = (const char *)mailp;
v1 = (__time_t *)mod_time;
for ( result = *(unsigned __int8 *)mailp; (_BYTE)result; ++v1 )
{
v3 = (char *)v0;
v4 = 0LL;
do
{
if ( (_BYTE)result == 58 )
{
*v3 = 0;
v5 = 1;
goto LABEL_9;
}
if ( (_BYTE)result == 37 && !v4 )
v4 = v3;
LOBYTE(result) = *++v3;
}
while ( (_BYTE)result );
v5 = 0;
LABEL_9:
if ( v4 )
*v4 = 0;
if ( *v0 && stat64(v0, &v7) >= 0 )
{
v6 = v7.st_mtim.tv_sec;
if ( v7.st_size && *v1 && *v1 != v7.st_mtim.tv_sec )
{
if ( v4 )
{
prs(v4 + 1);
prc(10LL);
}
else
{
prs(&mailmsg);
}
v6 = v7.st_mtim.tv_sec;
}
*v1 = v6;
}
else if ( !*v1 )
{
*v1 = 1LL;
}
if ( v4 )
*v4 = 37;
v0 = v3;
if ( v5 )
{
*v3 = 58;
v0 = v3 + 1;
}
result = *(unsigned __int8 *)v0;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
const char *v0; // rdi
__time_t *v1; // r13
__int64 result; // rax
char *v3; // rbx
char *v4; // rbp
__int16 v5; // r12
__time_t v6; // rax
struct stat64 v7; // [rsp+0h] [rbp-B8h] BYREF

v0 = (const char *)mailp;
v1 = (__time_t *)mod_time;
for ( result = *(unsigned __int8 *)mailp; (_BYTE)result; ++v1 )
{
v3 = (char *)v0;
v4 = 0LL;
do
{
if ( (_BYTE)result == 58 )
{
*v3 = 0;
v5 = 1;
goto LABEL_9;
}
if ( (_BYTE)result == 37 && !v4 )
v4 = v3;
LOBYTE(result) = *++v3;
}
while ( (_BYTE)result );
v5 = 0;
LABEL_9:
if ( v4 )
*v4 = 0;
if ( *v0 && stat64(v0, &v7) >= 0 )
{
v6 = v7.st_mtim.tv_sec;
if ( v7.st_size && *v1 && *v1 != v7.st_mtim.tv_sec )
{
if ( v4 )
{
prs(v4 + 1);
prc(10LL);
}
else
{
prs(&mailmsg);
}
v6 = v7.st_mtim.tv_sec;
}
*v1 = v6;
}
else if ( !*v1 )
{
*v1 = 1LL;
}
if ( v4 )
*v4 = 37;
v0 = v3;
if ( v5 )
{
*v3 = 58;
v0 = v3 + 1;
}
result = *(unsigned __int8 *)v0;
}
return result;
}

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);
result = _ctype_get_mb_cur_max();
mb_cur_max = result;
}
else
{
setlocale(0, "C");
result = _ctype_get_mb_cur_max();
mb_cur_max = result;
}
return result;
}

canonical_decompiled_code:
size_t func5()
{
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);
result = _ctype_get_mb_cur_max();
mb_cur_max = result;
}
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:
__int64 __fastcall sh_setmode(int a1)
{
__int64 result; // rax
void *v2; // rsi
int v3; // eax

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

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 result; // rax
void *v2; // rsi
int v3; // eax

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

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