repo: jukarimov/gtfinder

decompiled_code:
__int64 shutdown_file_chooser()
{
gtk_widget_destroy(window);
return gtk_main_quit();
}

canonical_decompiled_code:
__int64 func0()
{
gtk_widget_destroy(window);
return gtk_main_quit();
}

original_code:
void shutdown_file_chooser()
{
    gtk_widget_destroy(window);
    gtk_main_quit();
    return;
}


shutdown

decompiled_code:
__int64 shutdown()
{
gtk_widget_destroy(window);
return gtk_main_quit();
}

original_code:
void shutdown()
{
 gtk_widget_destroy(window);
 gtk_main_quit();
 return;
}

return_type: void


main

canonical_name: main

repo: jules-vanneste/PJE

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
int v5; // ebp
char *v6; // r14
int v7; // er12
int v8; // er15
unsigned __int16 v9; // ax
unsigned __int16 v10; // bx
unsigned __int16 v11; // ax
int v12; // [rsp+Ch] [rbp-62Ch]
__int64 v13; // [rsp+18h] [rbp-620h] BYREF
char v14[1560]; // [rsp+20h] [rbp-618h] BYREF

init_signals(argc, argv, envp);
v12 = init_terminal(&hContext, &hCard);
if ( v12 )
return -1;
if ( (unsigned int)open_tunnel(&tunnel) != -1 )
{
puts("SCARD host adapter is now ready to accept connections");
while ( 1 )
{
v4 = utun_read(&tunnel, v14, 1500LL);
v5 = v4;
if ( v4 < 0 )
break;
v13 = 0LL;
if ( v4 )
{
v6 = v14;
v7 = utun_select(&tunnel);
printf("send %d bytes\n", (unsigned int)v5);
while ( 1 )
{
v8 = 255;
if ( v5 <= 255 )
v8 = v5;
v9 = send_apdu(hContext, hCard, v6, (unsigned int)v8, &v13, (unsigned int)v7);
v10 = v9;
if ( (unsigned __int8)v9 <= 0x8Fu )
break;
v5 -= v8;
v6 += v8;
if ( v5 <= 0 )
goto LABEL_14;
}
printf("Error: %02x%02x\n", (unsigned __int8)v9, HIBYTE(v9));
LABEL_14:
if ( v7 <= 0 )
{
while ( HIBYTE(v10) )
{
v11 = recv_apdu(hContext, hCard, &tunnel, v10, &v13);
v10 = v11;
if ( (unsigned __int8)v11 <= 0x8Fu )
{
printf("Error: %02x%02x\n", (unsigned __int8)v11, HIBYTE(v11));
break;
}
}
if ( v13 )
check_terminal_status(hContext, hCard);
}
memset(v14, 0, 0x5E0uLL);
}
}
}
close_tunnel(&tunnel);
release_terminal(&hContext, &hCard);
return v12;
}

original_code:
int main(int argc, char *argv[]) {
 init_signals();
 if(init_terminal(&hContext,&hCard))
  return -1;
    else {
  if(open_tunnel(&tunnel) !=-1) {
   int output_len;
   raw_packet packet;
   short sw = 0x9000 ;
   printf("SCARD host adapter is now ready to accept connections\n");
   while((output_len = utun_read(&tunnel, packet.raw, 1500)) >= 0) {
    LONG card_status = 0;
    int select_ret;
    BYTE *packet_ptr;
    if(output_len == 0)
     continue;
    select_ret = utun_select(&tunnel);
    printf("send %d bytes\n",output_len);
    packet_ptr = packet.raw;
    do {
     unsigned char curr_len = output_len > 255 ? 255 : output_len;
     sw = send_apdu(hContext,hCard,packet_ptr,curr_len,&card_status,select_ret);
     if(((sw) & 0xFF) < 0x90) {
      printf("Error: %02x%02x\n",((sw) & 0xFF),(((sw)>>8) & 0xFF));
      break;
     }
     packet_ptr += curr_len;
     output_len -= curr_len;
    } while(output_len > 0);
    if(select_ret>0) {
     memset(&packet,0,sizeof(raw_packet));
     continue;
    }
    while((((sw)>>8) & 0xFF)) {
     sw = recv_apdu(hContext,hCard,&tunnel,sw,&card_status);
     if(((sw) & 0xFF) < 0x90 ) {
      printf("Error: %02x%02x\n",((sw) & 0xFF),(((sw)>>8) & 0xFF));
      break;
     }
    }
    if(card_status) {
     check_terminal_status(hContext,hCard);
    }
    memset(&packet,0,sizeof(raw_packet));
   }
  }
 }
 close_tunnel(&tunnel);
 release_terminal(&hContext,&hCard);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 init_signals();
 if(init_terminal(&hContext,&hCard))
  return -1;
    else {
  if(open_tunnel(&tunnel) !=-1) {
   int output_len;
   union raw_packet packet;
   short sw = 0x9000;
   printf("SCARD host adapter is now ready to accept connections\n");
   while((output_len = utun_read(&tunnel, packet.raw, 1500)) >= 0) {
    long card_status = 0;
    int select_ret;
    unsigned char *packet_ptr;
    if(output_len == 0)
     continue;
    select_ret = utun_select(&tunnel);
    printf("send %d bytes\n",output_len);
    packet_ptr = packet.raw;
    do {
     unsigned char curr_len = output_len > 255 ? 255 : output_len;
     sw = send_apdu(hContext,hCard,packet_ptr,curr_len,&card_status,select_ret);
     if(((sw) & 0xFF) < 0x90) {
      printf("Error: %02x%02x\n",((sw) & 0xFF),(((sw)>>8) & 0xFF));
      break;
     }
     packet_ptr += curr_len;
     output_len -= curr_len;
    } while(output_len > 0);
    if(select_ret>0) {
     memset(&packet,0,sizeof(raw_packet));
     continue;
    }
    while((((sw)>>8) & 0xFF)) {
     sw = recv_apdu(hContext,hCard,&tunnel,sw,&card_status);
     if(((sw) & 0xFF) < 0x90 ) {
      printf("Error: %02x%02x\n",((sw) & 0xFF),(((sw)>>8) & 0xFF));
      break;
     }
    }
    if(card_status) {
     check_terminal_status(hContext,hCard);
    }
    memset(&packet,0,sizeof(raw_packet));
   }
  }
 }
 close_tunnel(&tunnel);
 release_terminal(&hContext,&hCard);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: union raw_packet { struct { 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; } ip; } fmt; unsigned char raw[-1]; }

variable_types: sw short

return_type: int

user_defined_types: union raw_packet { struct { struct iphdr ip; } fmt; unsigned char raw[-1]; }


decompiled_code:
__int64 __fastcall utun_open(unsigned int *a1, const char *a2, const char *a3, unsigned __int64 a4)
{
int v6; // eax
unsigned int v7; // er12
int v9; // edi
__int128 v10; // [rsp+0h] [rbp-158h] BYREF
__int128 v11; // [rsp+10h] [rbp-148h]
__int64 v12; // [rsp+20h] [rbp-138h]
char s[296]; // [rsp+30h] [rbp-128h] BYREF

v6 = open("/dev/net/tun", 2);
if ( v6 < 0 )
{
v7 = -1;
printf("Unable to open %s\n", "/dev/net/tun");
}
else
{
v7 = v6;
v11 = 0LL;
v12 = 0LL;
LOWORD(v11) = 4097;
v10 = 0LL;
if ( ioctl(v6, 0x400454CAuLL, &v10) < 0 )
{
v9 = v7;
v7 = -1;
close(v9);
}
else
{
if ( a4 <= 0x64 )
a4 = 1500LL;
snprintf(s, 0x100uLL, "ifconfig %s %s pointopoint %s mtu %d", (const char *)&v10, a2, a3, a4);
system(s);
*a1 = v7;
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, const char *a2, const char *a3, unsigned __int64 a4)
{
int v6; // eax
unsigned int v7; // er12
int v9; // edi
__int128 v10; // [rsp+0h] [rbp-158h] BYREF
__int128 v11; // [rsp+10h] [rbp-148h]
__int64 v12; // [rsp+20h] [rbp-138h]
char s[296]; // [rsp+30h] [rbp-128h] BYREF

v6 = open("/dev/net/tun", 2);
if ( v6 < 0 )
{
v7 = -1;
printf("Unable to open %s\n", "/dev/net/tun");
}
else
{
v7 = v6;
v11 = 0LL;
v12 = 0LL;
LOWORD(v11) = 4097;
v10 = 0LL;
if ( ioctl(v6, 0x400454CAuLL, &v10) < 0 )
{
v9 = v7;
v7 = -1;
close(v9);
}
else
{
if ( a4 <= 0x64 )
a4 = 1500LL;
snprintf(s, 0x100uLL, "ifconfig %s %s pointopoint %s mtu %d", (const char *)&v10, a2, a3, a4);
system(s);
*a1 = v7;
}
}
return v7;
}

original_code:
int utun_open (utun *t, char *ip_src, char *ip_dest, unsigned long mtu)
{
    struct ifreq ifr;
    int fd, err;
    char buf[256] ;
    if( (fd = open("/dev/net/tun", 02)) < 0 )
    {
        printf("Unable to open %s\n","/dev/net/tun");
        return -1;
    }
    memset(&ifr, 0, sizeof(ifr));
    ifr.ifr_ifru.ifru_flags = 0x0001|0x1000 ;
    if( (err = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), (void *) &ifr)) < 0 )
    {
        close(fd);
        return -1;
    }
    snprintf(buf,256, "ifconfig %s %s pointopoint %s mtu %d", ifr.ifr_ifrn.ifrn_name, ip_src, ip_dest, mtu>100?mtu:1500);
    system(buf);
    t->fd= fd;
    return fd;
}

canonical_original_code:
int utun_open(struct tun_t *t, char *ip_src, char *ip_dest, unsigned long mtu)
{
    struct ifreq ifr;
    int fd; int err;
    char buf[256];
    if( (fd = open("/dev/net/tun", 02)) < 0 )
    {
        printf("Unable to open %s\n","/dev/net/tun");
        return -1;
    }
    memset(&ifr, 0, sizeof(ifr));
    ifr.ifr_ifru.ifru_flags = 0x0001|0x1000 ;
    if( (err = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), (void *) &ifr)) < 0 )
    {
        close(fd);
        return -1;
    }
    snprintf(buf,256, "ifconfig %s %s pointopoint %s mtu %d", ifr.ifr_ifrn.ifrn_name, ip_src, ip_dest, mtu>100?mtu:1500);
    system(buf);
    t->fd= fd;
    return fd;
}

variable_types:
t
struct tun_t { int fd; } *

variable_types:
mtu
unsigned long

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: fd int

variable_types: err int

variable_types:
buf
char [256]

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:
ssize_t __fastcall utun_write(int *a1, const void *a2, int a3)
{
return write(*a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func1(int *a1, const void *a2, int a3)
{
return write(*a1, a2, a3);
}

original_code:
int utun_write (utun *t, unsigned char *buf, int len)
{
    return write(t->fd,buf,len);
}

canonical_original_code:
int utun_write(struct tun_t *t, unsigned char *buf, int len)
{
    return write(t->fd,buf,len);
}

variable_types:
buf
unsigned char *

variable_types: len int


decompiled_code:
ssize_t __fastcall utun_read(int *a1, void *a2, int a3)
{
return read(*a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func2(int *a1, void *a2, int a3)
{
return read(*a1, a2, a3);
}

original_code:
int utun_read (utun *t, unsigned char *buf, int len)
{
    return read(t->fd,buf,len);
}

canonical_original_code:
int utun_read(struct tun_t *t, unsigned char *buf, int len)
{
    return read(t->fd,buf,len);
}


decompiled_code:
int __fastcall utun_close(int *a1)
{
int result; // eax

result = close(*a1);
*a1 = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func3(int *a1)
{
int result; // eax

result = close(*a1);
*a1 = -1;
return result;
}

original_code:
void utun_close (utun *t)
{
    close(t->fd);
    t->fd= -1;
}

canonical_original_code:
void utun_close(struct tun_t *t)
{
    close(t->fd);
    t->fd= -1;
}


decompiled_code:
int __fastcall utun_select(int *a1)
{
int v1; // eax
int v2; // edx
struct timeval v4; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v4.tv_sec = 0LL;
v4.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
v1 = *a1 + 63;
v2 = *a1;
if ( *a1 >= 0 )
v1 = *a1;
readfds.fds_bits[v1 >> 6] |= 1LL << (v2 % 64);
return select(v2 + 1, &readfds, 0LL, 0LL, &v4);
}

canonical_decompiled_code:
int __fastcall func4(int *a1)
{
int v1; // eax
int v2; // edx
struct timeval v4; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v4.tv_sec = 0LL;
v4.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
v1 = *a1 + 63;
v2 = *a1;
if ( *a1 >= 0 )
v1 = *a1;
readfds.fds_bits[v1 >> 6] |= 1LL << (v2 % 64);
return select(v2 + 1, &readfds, 0LL, 0LL, &v4);
}

original_code:
int utun_select(utun *t)
{
    struct timeval tv;
    fd_set fd_readset;
    tv.tv_sec = 0;
    tv.tv_usec = 0;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd_readset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fd_readset)->__fds_bits)[((t->fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((t->fd) % (8 * (int) sizeof (__fd_mask)))))));
    return select(t->fd + 1, &fd_readset, ((void *)0), ((void *)0), &tv);
}

canonical_original_code:
int utun_select(struct tun_t *t)
{
    struct timeval tv;
    struct fd_set fd_readset;
    tv.tv_sec = 0;
    tv.tv_usec = 0;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd_readset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fd_readset)->__fds_bits)[((t->fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((t->fd) % (8 * (int) sizeof (__fd_mask)))))));
    return select(t->fd + 1, &fd_readset, ((void *)0), ((void *)0), &tv);
}

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


decompiled_code:
__int64 __fastcall send_apdu(__int64 a1, __int64 a2, const void *a3, unsigned int a4, __int64 *a5, char a6)
{
size_t v6; // r15
char *v10; // rax
char *v11; // r12
__int64 v12; // rax
unsigned int v13; // er12
const char *v14; // rax
__int64 v17; // [rsp+18h] [rbp-620h] BYREF
char v18[1560]; // [rsp+20h] [rbp-618h] BYREF

v6 = (int)(a4 + 5);
v17 = 1503LL;
v10 = (char *)malloc(v6);
*(_WORD *)v10 = 384;
v11 = v10;
v10[2] = 0;
v10[3] = a6;
v10[4] = a4;
memcpy(v10 + 5, a3, (int)a4);
v12 = SCardTransmit(a2, &g_rgSCardT0Pci, v11, v6, 0LL, v18, &v17);
*a5 = v12;
v13 = *(unsigned __int16 *)((char *)&v17 + v17 + 6);
v14 = (const char *)pcsc_stringify_error(v12);
printf(" %d bytes. %02x%02x. %s \n", a4, (unsigned __int8)v13, BYTE1(v13), v14);
if ( *a5 )
{
v13 = -1;
if ( (unsigned int)check_terminal_status(a1, a2) != -1 )
v13 = 144;
}
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, const void *a3, unsigned int a4, __int64 *a5, char a6)
{
size_t v6; // r15
char *v10; // rax
char *v11; // r12
__int64 v12; // rax
unsigned int v13; // er12
const char *v14; // rax
__int64 v17; // [rsp+18h] [rbp-620h] BYREF
char v18[1560]; // [rsp+20h] [rbp-618h] BYREF

v6 = (int)(a4 + 5);
v17 = 1503LL;
v10 = (char *)malloc(v6);
*(_WORD *)v10 = 384;
v11 = v10;
v10[2] = 0;
v10[3] = a6;
v10[4] = a4;
memcpy(v10 + 5, a3, (int)a4);
v12 = SCardTransmit(a2, &g_rgSCardT0Pci, v11, v6, 0LL, v18, &v17);
*a5 = v12;
v13 = *(unsigned __int16 *)((char *)&v17 + v17 + 6);
v14 = (const char *)pcsc_stringify_error(v12);
printf(" %d bytes. %02x%02x. %s \n", a4, (unsigned __int8)v13, BYTE1(v13), v14);
if ( *a5 )
{
v13 = -1;
if ( (unsigned int)check_terminal_status(a1, a2) != -1 )
v13 = 144;
}
return v13;
}

original_code:
short send_apdu(SCARDCONTEXT hContext,SCARDHANDLE hCard,char *paquet,int len,LONG *rv,int P2) {
 short sw;
 BYTE pbRecvBuffer[1500 +1+2];
 BYTE *pbSendBuffer;
 DWORD dwSendLength = len + 5;
 DWORD dwRecvLength = sizeof(pbRecvBuffer);
 pbSendBuffer = malloc(dwSendLength);
 pbSendBuffer[0] = 0x80;
 pbSendBuffer[1] = 0x01;
 pbSendBuffer[2] = 0x00;
 pbSendBuffer[3] = P2;
 pbSendBuffer[4] = len;
 memcpy(pbSendBuffer+5,paquet,len);
 *rv = SCardTransmit(hCard,
  (&g_rgSCardT0Pci),
  pbSendBuffer,
  dwSendLength,
  ((void *)0),
  pbRecvBuffer,
  &dwRecvLength);
 sw = *((short*)(pbRecvBuffer+dwRecvLength-2));
 printf("   %d bytes. %02x%02x. %s \n", len, ((sw) & 0xFF),(((sw)>>8) & 0xFF), pcsc_stringify_error(*rv));
 if(*rv) {
  if(check_terminal_status(hContext,hCard)==-1)
   return -1;
  else
   return 0x90;
 }
 return sw;
}

canonical_original_code:
short send_apdu(long hContext, long hCard, char *paquet, int len, long *rv, int P2) {
 short sw;
 unsigned char pbRecvBuffer[-1];
 unsigned char *pbSendBuffer;
 unsigned long dwSendLength = len + 5;
 unsigned long dwRecvLength = sizeof(pbRecvBuffer);
 pbSendBuffer = malloc(dwSendLength);
 pbSendBuffer[0] = 0x80;
 pbSendBuffer[1] = 0x01;
 pbSendBuffer[2] = 0x00;
 pbSendBuffer[3] = P2;
 pbSendBuffer[4] = len;
 memcpy(pbSendBuffer+5,paquet,len);
 *rv = SCardTransmit(hCard,
  (&g_rgSCardT0Pci),
  pbSendBuffer,
  dwSendLength,
  ((void *)0),
  pbRecvBuffer,
  &dwRecvLength);
 sw = *((short *)(pbRecvBuffer+dwRecvLength-2));
 printf("   %d bytes. %02x%02x. %s \n", len, ((sw) & 0xFF),(((sw)>>8) & 0xFF), pcsc_stringify_error(*rv));
 if(*rv) {
  if(check_terminal_status(hContext,hCard)==-1)
   return -1;
  else
   return 0x90;
 }
 return sw;
}

variable_types: hContext long

variable_types: hCard long

variable_types:
paquet
char *

variable_types:
rv
long *

variable_types:
pbRecvBuffer
unsigned char [-1]

variable_types:
pbSendBuffer
unsigned char *

variable_types:
dwSendLength
unsigned long

variable_types:
dwRecvLength
unsigned long

return_type: short


decompiled_code:
__int64 __fastcall recv_apdu(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 *a5)
{
char v5; // ch
int v7; // ebp
unsigned __int16 v8; // bx
char *v9; // r15
const char *v10; // rax
__int64 v11; // rax
__int64 v12; // rdi
unsigned int v13; // er14
int v17; // [rsp+13h] [rbp-635h] BYREF
char v18; // [rsp+17h] [rbp-631h]
__int64 v19; // [rsp+18h] [rbp-630h] BYREF
char v20[16]; // [rsp+20h] [rbp-628h] BYREF
char v21[1560]; // [rsp+30h] [rbp-618h] BYREF

v7 = -1;
HIBYTE(v8) = v5;
v9 = v21;
v19 = 1503LL;
v17 = 640;
while ( 1 )
{
v18 = HIBYTE(v8);
v11 = SCardTransmit(a2, &g_rgSCardT0Pci, &v17, 5LL, v20, v9, &v19);
*a5 = v11;
v12 = v11;
v8 = *(_WORD *)&v9[v19 - 2];
v13 = v8;
if ( v7 == -1 )
{
v7 = (unsigned __int8)v9[3] + ((unsigned __int8)v9[2] << 8);
printf("recv %d bytes\n", (unsigned int)v7);
v12 = *a5;
}
v10 = (const char *)pcsc_stringify_error(v12);
printf(" %d bytes. %02x%02x. %s\n", v19 - 2, (unsigned __int8)v8, HIBYTE(v8), v10);
if ( *a5 )
break;
v9 = &v9[v19 - 2];
v7 += 2 - v19;
if ( v7 <= 0 )
{
utun_write(a3, v21, v9 - v21);
return v13;
}
}
v13 = -1;
if ( (unsigned int)check_terminal_status(a1, a2) != -1 )
v13 = 144;
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 *a5)
{
char v5; // ch
int v7; // ebp
unsigned __int16 v8; // bx
char *v9; // r15
const char *v10; // rax
__int64 v11; // rax
__int64 v12; // rdi
unsigned int v13; // er14
int v17; // [rsp+13h] [rbp-635h] BYREF
char v18; // [rsp+17h] [rbp-631h]
__int64 v19; // [rsp+18h] [rbp-630h] BYREF
char v20[16]; // [rsp+20h] [rbp-628h] BYREF
char v21[1560]; // [rsp+30h] [rbp-618h] BYREF

v7 = -1;
HIBYTE(v8) = v5;
v9 = v21;
v19 = 1503LL;
v17 = 640;
while ( 1 )
{
v18 = HIBYTE(v8);
v11 = SCardTransmit(a2, &g_rgSCardT0Pci, &v17, 5LL, v20, v9, &v19);
*a5 = v11;
v12 = v11;
v8 = *(_WORD *)&v9[v19 - 2];
v13 = v8;
if ( v7 == -1 )
{
v7 = (unsigned __int8)v9[3] + ((unsigned __int8)v9[2] << 8);
printf("recv %d bytes\n", (unsigned int)v7);
v12 = *a5;
}
v10 = (const char *)pcsc_stringify_error(v12);
printf(" %d bytes. %02x%02x. %s\n", v19 - 2, (unsigned __int8)v8, HIBYTE(v8), v10);
if ( *a5 )
break;
v9 = &v9[v19 - 2];
v7 += 2 - v19;
if ( v7 <= 0 )
{
utun_write(a3, v21, v9 - v21);
return v13;
}
}
v13 = -1;
if ( (unsigned int)check_terminal_status(a1, a2) != -1 )
v13 = 144;
return v13;
}

original_code:
short recv_apdu(SCARDCONTEXT hContext,SCARDHANDLE hCard,utun *t,unsigned short sw,LONG *rv) {
 SCARD_IO_REQUEST pioRecvPci;
 BYTE pbRecvBuffer[1500 +1+2];
 BYTE pbSendBuffer[5];
 BYTE *recvBuffPtr = pbRecvBuffer;
 int packet_length = -1;
 DWORD dwSendLength = 5;
 DWORD dwRecvLength = sizeof(pbRecvBuffer);
 pbSendBuffer[0]= 0x80;
 pbSendBuffer[1]= 0x02;
 pbSendBuffer[2]= 0x00;
 pbSendBuffer[3]= 0x00;
 pbSendBuffer[4]= (((sw)>>8) & 0xFF);
 do {
  pbSendBuffer[4]= (((sw)>>8) & 0xFF);
  *rv = SCardTransmit(hCard, (&g_rgSCardT0Pci),
   pbSendBuffer,
   dwSendLength,
   &pioRecvPci,
   recvBuffPtr,
   &dwRecvLength);
  sw = *((short*)(recvBuffPtr+dwRecvLength-2));
  if(packet_length == -1) {
   packet_length = (recvBuffPtr[2] << 8) + recvBuffPtr[3];
   printf("recv %d bytes\n",packet_length);
  }
  printf("   %d bytes. %02x%02x. %s\n",dwRecvLength-2,((sw) & 0xFF),(((sw)>>8) & 0xFF),pcsc_stringify_error(*rv));
  if(*rv) {
   if(check_terminal_status(hContext,hCard)==-1)
    return -1;
   else
    return 0x90;
  }
  packet_length -= dwRecvLength -2;
  recvBuffPtr += dwRecvLength-2;
 } while(packet_length > 0);
 utun_write(t, pbRecvBuffer,recvBuffPtr-pbRecvBuffer);
 return sw;
}

canonical_original_code:
short recv_apdu(long hContext, long hCard, struct tun_t *t, unsigned short sw, long *rv) {
 struct _SCARD_IO_REQUEST pioRecvPci;
 unsigned char pbRecvBuffer[-1];
 unsigned char pbSendBuffer[5];
 unsigned char *recvBuffPtr = pbRecvBuffer;
 int packet_length = -1;
 unsigned long dwSendLength = 5;
 unsigned long dwRecvLength = sizeof(pbRecvBuffer);
 pbSendBuffer[0]= 0x80;
 pbSendBuffer[1]= 0x02;
 pbSendBuffer[2]= 0x00;
 pbSendBuffer[3]= 0x00;
 pbSendBuffer[4]= (((sw)>>8) & 0xFF);
 do {
  pbSendBuffer[4]= (((sw)>>8) & 0xFF);
  *rv = SCardTransmit(hCard, (&g_rgSCardT0Pci),
   pbSendBuffer,
   dwSendLength,
   &pioRecvPci,
   recvBuffPtr,
   &dwRecvLength);
  sw = *((short *)(recvBuffPtr+dwRecvLength-2));
  if(packet_length == -1) {
   packet_length = (recvBuffPtr[2] << 8) + recvBuffPtr[3];
   printf("recv %d bytes\n",packet_length);
  }
  printf("   %d bytes. %02x%02x. %s\n",dwRecvLength-2,((sw) & 0xFF),(((sw)>>8) & 0xFF),pcsc_stringify_error(*rv));
  if(*rv) {
   if(check_terminal_status(hContext,hCard)==-1)
    return -1;
   else
    return 0x90;
  }
  packet_length -= dwRecvLength -2;
  recvBuffPtr += dwRecvLength-2;
 } while(packet_length > 0);
 utun_write(t, pbRecvBuffer,recvBuffPtr-pbRecvBuffer);
 return sw;
}

variable_types:
t
struct tun_t { int fd; } *

variable_types:
sw
unsigned short

variable_types: struct _SCARD_IO_REQUEST { unsigned long dwProtocol; unsigned long cbPciLength; }

variable_types:
pbSendBuffer
unsigned char [5]

variable_types:
recvBuffPtr
unsigned char *


decompiled_code:
__int64 __fastcall init_terminal(_QWORD *a1, _QWORD *a2)
{
char *v2; // r12
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rbx
unsigned __int64 i; // rbx
__int64 v8; // rsi
__int64 v10; // rsi
__int64 v11; // rax
const char *v12; // rax
__int64 v13; // rsi
__int64 v14; // rsi
size_t size; // [rsp+8h] [rbp-90h] BYREF
unsigned __int64 v16; // [rsp+10h] [rbp-88h] BYREF
char v17[8]; // [rsp+18h] [rbp-80h] BYREF
char v18[8]; // [rsp+20h] [rbp-78h] BYREF
char v19[8]; // [rsp+28h] [rbp-70h] BYREF
char v20[104]; // [rsp+30h] [rbp-68h] BYREF

SCardEstablishContext(2LL, 0LL, 0LL, a1);
SCardListReaders(*a1, 0LL, 0LL, &size);
v2 = (char *)malloc(size);
v3 = SCardListReaders(*a1, 0LL, v2, &size);
if ( v3 )
{
LODWORD(v5) = v3;
v13 = pcsc_stringify_error(v3);
printf("ListReader error: %s\n", v13);
goto LABEL_12;
}
printf("Reader=%s\n", v2);
v4 = SCardEstablishContext(2LL, 0LL, 0LL, a1);
LODWORD(v5) = v4;
if ( v4 )
{
v10 = pcsc_stringify_error(v4);
printf("Connect to reader error: %s\n", v10);
LABEL_12:
free(v2);
return (unsigned int)v5;
}
v6 = SCardConnect(*a1, v2, 2LL, 1LL, a2, v17);
if ( v6 != 2148532236LL && v6 != 2148532329LL )
{
if ( !v6 )
goto LABEL_6;
LABEL_17:
v12 = (const char *)pcsc_stringify_error(v6);
printf("Connect to card error: %s : err=%X\n", v12, v6);
free(v2);
return (unsigned int)v6;
}
printf("Please insert a card in terminal \"%s\"\n", v2);
do
{
do
{
usleep(0x64u);
v11 = SCardConnect(*a1, v2, 2LL, 1LL, a2, v17);
v6 = v11;
}
while ( v11 == 2148532236LL );
}
while ( v11 == 2148532329LL );
if ( v11 )
goto LABEL_17;
LABEL_6:
v16 = 33LL;
v5 = SCardStatus(*a2, 0LL, v19, v18, v17, v20, &v16);
if ( v5 )
{
v14 = pcsc_stringify_error(v5);
printf("Reading ATR error: %s\n", v14);
goto LABEL_12;
}
printf("Reading ATR: ");
if ( v16 )
{
for ( i = 0LL; i < v16; ++i )
{
v8 = (unsigned __int8)v20[i];
printf("%.2X ", v8);
}
}
putchar(10);
free(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2)
{
char *v2; // r12
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rbx
unsigned __int64 i; // rbx
__int64 v8; // rsi
__int64 v10; // rsi
__int64 v11; // rax
const char *v12; // rax
__int64 v13; // rsi
__int64 v14; // rsi
size_t size; // [rsp+8h] [rbp-90h] BYREF
unsigned __int64 v16; // [rsp+10h] [rbp-88h] BYREF
char v17[8]; // [rsp+18h] [rbp-80h] BYREF
char v18[8]; // [rsp+20h] [rbp-78h] BYREF
char v19[8]; // [rsp+28h] [rbp-70h] BYREF
char v20[104]; // [rsp+30h] [rbp-68h] BYREF

SCardEstablishContext(2LL, 0LL, 0LL, a1);
SCardListReaders(*a1, 0LL, 0LL, &size);
v2 = (char *)malloc(size);
v3 = SCardListReaders(*a1, 0LL, v2, &size);
if ( v3 )
{
LODWORD(v5) = v3;
v13 = pcsc_stringify_error(v3);
printf("ListReader error: %s\n", v13);
goto LABEL_12;
}
printf("Reader=%s\n", v2);
v4 = SCardEstablishContext(2LL, 0LL, 0LL, a1);
LODWORD(v5) = v4;
if ( v4 )
{
v10 = pcsc_stringify_error(v4);
printf("Connect to reader error: %s\n", v10);
LABEL_12:
free(v2);
return (unsigned int)v5;
}
v6 = SCardConnect(*a1, v2, 2LL, 1LL, a2, v17);
if ( v6 != 2148532236LL && v6 != 2148532329LL )
{
if ( !v6 )
goto LABEL_6;
LABEL_17:
v12 = (const char *)pcsc_stringify_error(v6);
printf("Connect to card error: %s : err=%X\n", v12, v6);
free(v2);
return (unsigned int)v6;
}
printf("Please insert a card in terminal \"%s\"\n", v2);
do
{
do
{
usleep(0x64u);
v11 = SCardConnect(*a1, v2, 2LL, 1LL, a2, v17);
v6 = v11;
}
while ( v11 == 2148532236LL );
}
while ( v11 == 2148532329LL );
if ( v11 )
goto LABEL_17;
LABEL_6:
v16 = 33LL;
v5 = SCardStatus(*a2, 0LL, v19, v18, v17, v20, &v16);
if ( v5 )
{
v14 = pcsc_stringify_error(v5);
printf("Reading ATR error: %s\n", v14);
goto LABEL_12;
}
printf("Reading ATR: ");
if ( v16 )
{
for ( i = 0LL; i < v16; ++i )
{
v8 = (unsigned __int8)v20[i];
printf("%.2X ", v8);
}
}
putchar(10);
free(v2);
return 0LL;
}

original_code:
int init_terminal(
        SCARDCONTEXT *hContext,
        SCARDHANDLE *hCard)
{
    LONG rv;
    LPSTR mszReaders;
    DWORD dwReaders;
    DWORD dwAtrLen,dwProtocol,dwState,dwReaderLen;
    BYTE pbAtr[33];
    rv = SCardEstablishContext(0x0002, ((void *)0), ((void *)0), hContext);
    rv = SCardListReaders(*hContext, ((void *)0), ((void *)0), &dwReaders);
    mszReaders = malloc(sizeof(char)*dwReaders);
    rv = SCardListReaders(*hContext, ((void *)0), mszReaders, &dwReaders);
    if(rv)
    {
        printf("ListReader error: %s\n",pcsc_stringify_error(rv));
        free(mszReaders);
        return rv;
    }
    printf("Reader=%s\n",mszReaders);
    rv = SCardEstablishContext(0x0002, ((void *)0), ((void *)0), hContext);
    if(rv)
    {
        printf("Connect to reader error: %s\n",pcsc_stringify_error(rv));
        free(mszReaders);
        return rv;
    }
    rv = SCardConnect(*hContext, mszReaders, 0x0002,
                       0x0001, hCard, &dwProtocol);
    if(rv == 0x8010000C
        || rv == 0x80100069
        )
    {
        printf("Please insert a card in terminal \"%s\"\n",mszReaders);
    }
    while(rv == 0x8010000C
        || rv == 0x80100069)
    {
        usleep(100);
        rv = SCardConnect(*hContext, mszReaders, 0x0002,
                           0x0001, hCard, &dwProtocol);
    }
    if(rv)
    {
        printf("Connect to card error: %s : err=%X\n",pcsc_stringify_error(rv),rv);
        free(mszReaders);
        return rv;
    }
    dwAtrLen = sizeof(pbAtr);
    rv=SCardStatus(*hCard, ((void *)0), &dwReaderLen, &dwState, &dwProtocol,
                   pbAtr, &dwAtrLen);
    if(rv)
    {
        printf("Reading ATR error: %s\n",pcsc_stringify_error(rv));
        free(mszReaders);
        return rv;
    }
    else
    {
        int i;
        printf("Reading ATR: ");
        for(i=0;i<dwAtrLen;i++)
            printf("%.2X ",pbAtr[i]);
        printf("\n");
    }
    free(mszReaders);
    return rv;
}

canonical_original_code:
int init_terminal(long *hContext, long *hCard)
{
    long rv;
    char *mszReaders;
    unsigned long dwReaders;
    unsigned long dwAtrLen; unsigned long dwProtocol; unsigned long dwState; unsigned long dwReaderLen;
    unsigned char pbAtr[33];
    rv = SCardEstablishContext(0x0002, ((void *)0), ((void *)0), hContext);
    rv = SCardListReaders(*hContext, ((void *)0), ((void *)0), &dwReaders);
    mszReaders = malloc(sizeof(char)*dwReaders);
    rv = SCardListReaders(*hContext, ((void *)0), mszReaders, &dwReaders);
    if(rv)
    {
        printf("ListReader error: %s\n",pcsc_stringify_error(rv));
        free(mszReaders);
        return rv;
    }
    printf("Reader=%s\n",mszReaders);
    rv = SCardEstablishContext(0x0002, ((void *)0), ((void *)0), hContext);
    if(rv)
    {
        printf("Connect to reader error: %s\n",pcsc_stringify_error(rv));
        free(mszReaders);
        return rv;
    }
    rv = SCardConnect(*hContext, mszReaders, 0x0002,
                       0x0001, hCard, &dwProtocol);
    if(rv == 0x8010000C
        || rv == 0x80100069
        )
    {
        printf("Please insert a card in terminal \"%s\"\n",mszReaders);
    }
    while(rv == 0x8010000C
        || rv == 0x80100069)
    {
        usleep(100);
        rv = SCardConnect(*hContext, mszReaders, 0x0002,
                           0x0001, hCard, &dwProtocol);
    }
    if(rv)
    {
        printf("Connect to card error: %s : err=%X\n",pcsc_stringify_error(rv),rv);
        free(mszReaders);
        return rv;
    }
    dwAtrLen = sizeof(pbAtr);
    rv=SCardStatus(*hCard, ((void *)0), &dwReaderLen, &dwState, &dwProtocol,
                   pbAtr, &dwAtrLen);
    if(rv)
    {
        printf("Reading ATR error: %s\n",pcsc_stringify_error(rv));
        free(mszReaders);
        return rv;
    }
    else
    {
        int i;
        printf("Reading ATR: ");
        for(i=0;i<dwAtrLen;i++)
            printf("%.2X ",pbAtr[i]);
        printf("\n");
    }
    free(mszReaders);
    return rv;
}

variable_types:
hContext
long *

variable_types:
hCard
long *

variable_types: rv long

variable_types:
mszReaders
char *

variable_types:
dwReaders
unsigned long

variable_types:
dwAtrLen
unsigned long

variable_types:
dwProtocol
unsigned long

variable_types:
dwState
unsigned long

variable_types:
dwReaderLen
unsigned long

variable_types:
pbAtr
unsigned char [33]

variable_types: i int


decompiled_code:
int __fastcall release_terminal(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 v3; // rax
const char *v5; // rax
const char *v6; // rax

v2 = SCardDisconnect(*a2, 2LL);
if ( v2 )
{
v5 = (const char *)pcsc_stringify_error(v2);
printf("Disconnect=%s\n", v5);
v3 = SCardReleaseContext(*a1);
if ( !v3 )
return puts("...Exiting ");
}
else
{
v3 = SCardReleaseContext(*a1);
if ( !v3 )
return puts("...Exiting ");
}
v6 = (const char *)pcsc_stringify_error(v3);
printf("Release=%s\n", v6);
return puts("...Exiting ");
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 v3; // rax
const char *v5; // rax
const char *v6; // rax

v2 = SCardDisconnect(*a2, 2LL);
if ( v2 )
{
v5 = (const char *)pcsc_stringify_error(v2);
printf("Disconnect=%s\n", v5);
v3 = SCardReleaseContext(*a1);
if ( !v3 )
return puts("...Exiting ");
}
else
{
v3 = SCardReleaseContext(*a1);
if ( !v3 )
return puts("...Exiting ");
}
v6 = (const char *)pcsc_stringify_error(v3);
printf("Release=%s\n", v6);
return puts("...Exiting ");
}

original_code:
void release_terminal(
        SCARDCONTEXT *hContext,
        SCARDHANDLE *hCard)
{
    LONG rv;
    rv = SCardDisconnect(*hCard, 0x0002);
    if(rv)printf("Disconnect=%s\n",pcsc_stringify_error(rv));
    rv = SCardReleaseContext(*hContext);
    if(rv)printf("Release=%s\n",pcsc_stringify_error(rv));
    printf("...Exiting \n");
}

canonical_original_code:
void release_terminal(long *hContext, long *hCard)
{
    long rv;
    rv = SCardDisconnect(*hCard, 0x0002);
    if(rv)printf("Disconnect=%s\n",pcsc_stringify_error(rv));
    rv = SCardReleaseContext(*hContext);
    if(rv)printf("Release=%s\n",pcsc_stringify_error(rv));
    printf("...Exiting \n");
}


decompiled_code:
__int64 __fastcall check_terminal_status(__int64 a1, __int64 a2)
{
char v3; // si
unsigned int v4; // ebp
__int64 v5; // rbx
const char *v6; // rax
__int64 v8; // [rsp+8h] [rbp-68h] BYREF
char v9[8]; // [rsp+10h] [rbp-60h] BYREF
__int64 v10; // [rsp+18h] [rbp-58h] BYREF
char v11[8]; // [rsp+20h] [rbp-50h] BYREF
char v12[72]; // [rsp+28h] [rbp-48h] BYREF

v8 = 33LL;
SCardStatus(a2, 0LL, v11, &v10, v9, v12, &v8);
v3 = v10;
if ( v10 )
{
printf("State= %X, Possible diagnostic :\n", v10);
v3 = v10;
if ( (v10 & 2) != 0 )
{
puts("There is no card in the reader.");
v3 = v10;
}
if ( (v3 & 4) != 0 )
{
puts("There is a card in the reader, but it has not been moved into position for use.");
v3 = v10;
}
if ( (v3 & 8) != 0 )
{
puts("There is a card in the reader in position for use. The card is not powered.");
v3 = v10;
}
}
if ( (v3 & 0x10) != 0 )
{
puts("Power is being provided to the card, but the reader driver is unaware of the mode of the card.");
v3 = v10;
}
if ( (v3 & 0x20) != 0 )
{
puts("The card has been reset and is awaiting PTS negotiation.");
v3 = v10;
}
if ( (v3 & 0x40) != 0 )
puts("The card has been reset and specific communication protocols have been established.");
v4 = 0;
do
{
++v4;
printf("Trying to reconnect in %ds...\n", 3LL);
sleep(3u);
printf("Trying to reconnect... %d/%d\n", v4, 100LL);
v5 = SCardReconnect(a2, 2LL, 1LL, 1LL, v9);
v6 = (const char *)pcsc_stringify_error(v5);
puts(v6);
if ( !v5 )
return 0LL;
}
while ( v4 != 100 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
char v3; // si
unsigned int v4; // ebp
__int64 v5; // rbx
const char *v6; // rax
__int64 v8; // [rsp+8h] [rbp-68h] BYREF
char v9[8]; // [rsp+10h] [rbp-60h] BYREF
__int64 v10; // [rsp+18h] [rbp-58h] BYREF
char v11[8]; // [rsp+20h] [rbp-50h] BYREF
char v12[72]; // [rsp+28h] [rbp-48h] BYREF

v8 = 33LL;
SCardStatus(a2, 0LL, v11, &v10, v9, v12, &v8);
v3 = v10;
if ( v10 )
{
printf("State= %X, Possible diagnostic :\n", v10);
v3 = v10;
if ( (v10 & 2) != 0 )
{
puts("There is no card in the reader.");
v3 = v10;
}
if ( (v3 & 4) != 0 )
{
puts("There is a card in the reader, but it has not been moved into position for use.");
v3 = v10;
}
if ( (v3 & 8) != 0 )
{
puts("There is a card in the reader in position for use. The card is not powered.");
v3 = v10;
}
}
if ( (v3 & 0x10) != 0 )
{
puts("Power is being provided to the card, but the reader driver is unaware of the mode of the card.");
v3 = v10;
}
if ( (v3 & 0x20) != 0 )
{
puts("The card has been reset and is awaiting PTS negotiation.");
v3 = v10;
}
if ( (v3 & 0x40) != 0 )
puts("The card has been reset and specific communication protocols have been established.");
v4 = 0;
do
{
++v4;
printf("Trying to reconnect in %ds...\n", 3LL);
sleep(3u);
printf("Trying to reconnect... %d/%d\n", v4, 100LL);
v5 = SCardReconnect(a2, 2LL, 1LL, 1LL, v9);
v6 = (const char *)pcsc_stringify_error(v5);
puts(v6);
if ( !v5 )
return 0LL;
}
while ( v4 != 100 );
return 0xFFFFFFFFLL;
}

original_code:
int check_terminal_status(SCARDCONTEXT hContext,SCARDHANDLE hCard)
{
    LONG rv;
    DWORD dwAtrLen,dwProtocol,dwState,dwReaderLen;
    BYTE pbAtr[33];
    int c= 0;
    dwAtrLen = sizeof(pbAtr);
    rv=SCardStatus(hCard, ((void *)0), &dwReaderLen, &dwState, &dwProtocol,
                   pbAtr, &dwAtrLen);
    if(dwState)
        printf("State= %X, Possible diagnostic :\n",dwState);
    if((dwState & 0x0002) == 0x0002 )
        printf("There is no card in the reader.\n");
    if((dwState & 0x0004) == 0x0004)
        printf("There is a card in the reader, but it has not been moved into position for use.\n");
    if((dwState & 0x0008) == 0x0008)
        printf("There is a card in the reader in position for use. The card is not powered.\n");
    if((dwState & 0x0010) == 0x0010)
        printf("Power is being provided to the card, but the reader driver is unaware of the mode of the card.\n");
    if((dwState & 0x0020) == 0x0020 )
        printf("The card has been reset and is awaiting PTS negotiation.\n");
    if((dwState & 0x0040) == 0x0040)
        printf("The card has been reset and specific communication protocols have been established.\n");
    rv= 1;
    while(rv != 0x00000000)
    {
        if(c==100)
            return -1;
        c++;
        printf("Trying to reconnect in %ds...\n",3);
        sleep(3);
        printf("Trying to reconnect... %d/%d\n",c,100);
        rv= SCardReconnect(hCard, 0x0002, 0x0001,
                           0x0001, &dwProtocol);
        printf("%s\n",pcsc_stringify_error(rv));
    }
    return 0;
}

canonical_original_code:
int check_terminal_status(long hContext, long hCard)
{
    long rv;
    unsigned long dwAtrLen; unsigned long dwProtocol; unsigned long dwState; unsigned long dwReaderLen;
    unsigned char pbAtr[33];
    int c = 0;
    dwAtrLen = sizeof(pbAtr);
    rv=SCardStatus(hCard, ((void *)0), &dwReaderLen, &dwState, &dwProtocol,
                   pbAtr, &dwAtrLen);
    if(dwState)
        printf("State= %X, Possible diagnostic :\n",dwState);
    if((dwState & 0x0002) == 0x0002 )
        printf("There is no card in the reader.\n");
    if((dwState & 0x0004) == 0x0004)
        printf("There is a card in the reader, but it has not been moved into position for use.\n");
    if((dwState & 0x0008) == 0x0008)
        printf("There is a card in the reader in position for use. The card is not powered.\n");
    if((dwState & 0x0010) == 0x0010)
        printf("Power is being provided to the card, but the reader driver is unaware of the mode of the card.\n");
    if((dwState & 0x0020) == 0x0020 )
        printf("The card has been reset and is awaiting PTS negotiation.\n");
    if((dwState & 0x0040) == 0x0040)
        printf("The card has been reset and specific communication protocols have been established.\n");
    rv= 1;
    while(rv != 0x00000000)
    {
        if(c==100)
            return -1;
        c++;
        printf("Trying to reconnect in %ds...\n",3);
        sleep(3);
        printf("Trying to reconnect... %d/%d\n",c,100);
        rv= SCardReconnect(hCard, 0x0002, 0x0001,
                           0x0001, &dwProtocol);
        printf("%s\n",pcsc_stringify_error(rv));
    }
    return 0;
}

variable_types: hContext long

variable_types: hCard long

variable_types: c int


decompiled_code:
void __fastcall __noreturn test_and_close(unsigned int a1)
{
if ( a1 == 2 || a1 == 15 )
{
fprintf(stderr, "Recv signal %d\n", a1);
fflush(stderr);
close_tunnel(&tunnel);
release_terminal(&hContext, &hCard);
}
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(unsigned int a1)
{
if ( a1 == 2 || a1 == 15 )
{
fprintf(stderr, "Recv signal %d\n", a1);
fflush(stderr);
close_tunnel(&tunnel);
release_terminal(&hContext, &hCard);
}
exit(0);
}

original_code:
static void test_and_close(int sig_ptr)
{
  switch(sig_ptr)
  {
  case 2:
  case 15:
      fprintf(stderr, "Recv signal %d\n", sig_ptr);
      fflush(stderr);
      close_tunnel(&tunnel);
      release_terminal(&hContext,&hCard);
      break;
  default:
      break;
  }
  exit(0);
}


decompiled_code:
__sighandler_t init_signals()
{
int *v0; // rbx
int v1; // edi
__sighandler_t result; // rax

v0 = (int *)&signals;
do
{
v1 = *v0++;
result = signal(v1, (__sighandler_t)test_and_close);
}
while ( v0 != (int *)((char *)&signals + 24) );
return result;
}

canonical_decompiled_code:
__sighandler_t func1()
{
int *v0; // rbx
int v1; // edi
__sighandler_t result; // rax

v0 = (int *)&signals;
do
{
v1 = *v0++;
result = signal(v1, (__sighandler_t)test_and_close);
}
while ( v0 != (int *)((char *)&signals + 24) );
return result;
}

original_code:
void init_signals(void)
{
  int i;
  for (i=0 ; i < 6 ; i++)
    signal( signals[i], test_and_close) ;
}

canonical_original_code:
void init_signals()
{
  int i;
  for (i=0 ; i < 6 ; i++)
    signal( signals[i], test_and_close) ;
}


decompiled_code:
int __fastcall print_packet(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // r12
int v3; // ebx
unsigned __int8 *v4; // r14
int v5; // er13
int v6; // er15
const unsigned __int16 **v7; // r13
__int64 v8; // r14
__int64 v9; // rdi
unsigned __int8 *v11; // [rsp+0h] [rbp-48h]
int i; // [rsp+8h] [rbp-40h]

v2 = a1;
printf("Dumping %dbytes\n", a2);
if ( (int)a2 > 0 )
{
v11 = a1;
v3 = a2;
for ( i = 0; (((_DWORD)a2 - 1) & 0xFFFFFFF0) + 16 != i; i += 16 )
{
printf("%.4X: ", (unsigned int)i);
if ( i >= (int)a2 )
{
v5 = 0;
}
else
{
v4 = v11;
v5 = 0;
while ( 1 )
{
++v5;
printf("%.2X", *v4);
if ( v3 == v5 )
break;
++v4;
if ( v5 == 16 )
goto LABEL_7;
}
if ( v3 == 16 )
{
LABEL_7:
printf(" ");
LABEL_8:
v6 = 0;
v7 = _ctype_b_loc();
v8 = (unsigned int)(i + 1);
while ( 1 )
{
v9 = v2[v8 - 1];
if ( ((*v7)[v9] & 0x8000u) == 0 )
LODWORD(v9) = 46;
++v6;
putchar(v9);
if ( (int)a2 <= (int)v8 )
goto LABEL_20;
++v8;
if ( v6 == 16 )
goto LABEL_13;
}
}
}
do
{
++v5;
printf(" ");
}
while ( v5 != 16 );
printf(" ");
if ( i < (int)a2 )
goto LABEL_8;
v6 = 0;
do
{
++v6;
putchar(32);
LABEL_20:
;
}
while ( v6 != 16 );
LABEL_13:
v3 -= 16;
putchar(10);
v11 += 16;
}
}
putchar(10);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // r12
int v3; // ebx
unsigned __int8 *v4; // r14
int v5; // er13
int v6; // er15
const unsigned __int16 **v7; // r13
__int64 v8; // r14
__int64 v9; // rdi
unsigned __int8 *v11; // [rsp+0h] [rbp-48h]
int i; // [rsp+8h] [rbp-40h]

v2 = a1;
printf("Dumping %dbytes\n", a2);
if ( (int)a2 > 0 )
{
v11 = a1;
v3 = a2;
for ( i = 0; (((_DWORD)a2 - 1) & 0xFFFFFFF0) + 16 != i; i += 16 )
{
printf("%.4X: ", (unsigned int)i);
if ( i >= (int)a2 )
{
v5 = 0;
}
else
{
v4 = v11;
v5 = 0;
while ( 1 )
{
++v5;
printf("%.2X", *v4);
if ( v3 == v5 )
break;
++v4;
if ( v5 == 16 )
goto LABEL_7;
}
if ( v3 == 16 )
{
LABEL_7:
printf(" ");
LABEL_8:
v6 = 0;
v7 = _ctype_b_loc();
v8 = (unsigned int)(i + 1);
while ( 1 )
{
v9 = v2[v8 - 1];
if ( ((*v7)[v9] & 0x8000u) == 0 )
LODWORD(v9) = 46;
++v6;
putchar(v9);
if ( (int)a2 <= (int)v8 )
goto LABEL_20;
++v8;
if ( v6 == 16 )
goto LABEL_13;
}
}
}
do
{
++v5;
printf(" ");
}
while ( v5 != 16 );
printf(" ");
if ( i < (int)a2 )
goto LABEL_8;
v6 = 0;
do
{
++v6;
putchar(32);
LABEL_20:
;
}
while ( v6 != 16 );
LABEL_13:
v3 -= 16;
putchar(10);
v11 += 16;
}
}
putchar(10);
return fflush(stdout);
}

original_code:
void print_packet(const unsigned char *ptr,int len)
{
    int i,j;
    printf("Dumping %dbytes\n",len);
    for(i=0;i<len;i++)
    {
        printf("%.4X: ",i);
        for(j=0;i+j<len && j<16;j++)
        {
            printf("%.2X",ptr[i+j]);
        }
        if(j<16)
        {
            for(;j<16;j++)
                printf("  ");
        }
        printf("  ");
        for(j=0;i+j<len && j<16;j++)
        {
            printf("%c",((*__ctype_b_loc ())[(int) ((ptr[i+j]))] & (unsigned short int) _ISgraph)?ptr[i+j]:'.');
        }
        if(j<16)
        {
            for(;j<16;j++)
                printf(" ");
        }
        printf("\n");
        i+=15;
    }
    printf("\n");
    fflush(stdout);
}

canonical_original_code:
void print_packet(unsigned char *ptr, int len)
{
    int i; int j;
    printf("Dumping %dbytes\n",len);
    for(i=0;i<len;i++)
    {
        printf("%.4X: ",i);
        for(j=0;i+j<len && j<16;j++)
        {
            printf("%.2X",ptr[i+j]);
        }
        if(j<16)
        {
            for(;j<16;j++)
                printf("  ");
        }
        printf("  ");
        for(j=0;i+j<len && j<16;j++)
        {
            printf("%c",((*__ctype_b_loc ())[(int) ((ptr[i+j]))] & (unsigned short) _ISgraph)?ptr[i+j]:'.');
        }
        if(j<16)
        {
            for(;j<16;j++)
                printf(" ");
        }
        printf("\n");
        i+=15;
    }
    printf("\n");
    fflush(stdout);
}

variable_types:
ptr
unsigned char *

variable_types: len int

variable_types: j int


original_code:
int open_tunnel(utun *tunnel)
{
    return utun_open(tunnel,"192.168.1.5", "192.168.1.6",1500);
}

canonical_original_code:
int open_tunnel(struct tun_t *tunnel)
{
    return utun_open(tunnel,"192.168.1.5", "192.168.1.6",1500);
}

variable_types:
tunnel
struct tun_t { int fd; } *


decompiled_code:
// attributes: thunk
__int64 close_tunnel()
{
return utun_close();
}

canonical_decompiled_code:
__int64 func1()
{
return utun_close();
}

original_code:
void close_tunnel(utun *tunnel)
{
    utun_close(tunnel);
}

canonical_original_code:
void close_tunnel(struct tun_t *tunnel)
{
    utun_close(tunnel);
}


repo: juliords/mycompiler

decompiled_code:
__int64 next_label()
{
return (unsigned int)++l_0;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)++l_0;
}

original_code:
int next_label()
{
 static int l = 0;
 return ++l;
}

variable_types: l int


decompiled_code:
__int64 __fastcall float_to_int(__m128i a1)
{
return (unsigned int)_mm_cvtsi128_si32(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__m128i a1)
{
return (unsigned int)_mm_cvtsi128_si32(a1);
}

original_code:
int float_to_int(float f)
{
 union
 {
  int i;
  float f;
 } v;
 v.f = f;
 return v.i;
}

variable_types: f float

variable_types:
v
union { int i; float f; }


decompiled_code:
__int64 __fastcall multiple_of_n(signed int a1, int a2)
{
int v2; // edx
__int64 result; // rax
unsigned int v4; // esi

v2 = a1 % a2;
result = (unsigned int)a1;
v4 = a1 + a2 - a1 % a2;
if ( v2 )
result = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(signed int a1, int a2)
{
int v2; // edx
__int64 result; // rax
unsigned int v4; // esi

v2 = a1 % a2;
result = (unsigned int)a1;
v4 = a1 + a2 - a1 % a2;
if ( v2 )
result = v4;
return result;
}

original_code:
int multiple_of_n(int i, int n)
{
 if(i % n == 0) return i;
 return i + (n - (i % n));
}

variable_types: n int


decompiled_code:
_BOOL8 __fastcall is_char(_DWORD *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 )
{
if ( *a1 == 1 )
result = a1[1] == 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_DWORD *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 )
{
if ( *a1 == 1 )
result = a1[1] == 0;
}
return result;
}

original_code:
int is_char(TypeNode* t)
{
 if(t && t->prim == TypeChar && t->dims == 0)
  return 1;
 return 0;
}

canonical_original_code:
int is_char(struct TypeNode *t)
{
 if(t && t->prim == TypeChar && t->dims == 0)
  return 1;
 return 0;
}

variable_types: struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *

user_defined_types: struct TypeNode { enum BaseType prim; int dims; }


original_code:
int max_esp(BlockNode *blk, int esp)
{
 ListNode *lst;
 int max = esp;
 if(!blk) return 0;
 for(lst = blk->var; lst; lst = lst->next)
 {
  DecVarNode *v = (DecVarNode*)lst->data;
  if(is_char(v->type))
  {
   max += 1;
  }
  else
  {
   max = multiple_of_n(max, 4);
   max += 4;
  }
  v->stack_offset = max;
 }
 max = multiple_of_n(max, 4);
 for(lst = blk->cmd; lst; lst = lst->next)
 {
  CmdNode *cmd = (CmdNode*)lst->data;
  if(cmd->type == CmdBlock)
  {
   int t = max_esp(cmd->u.b.block, esp);
   if(t > max) t = max;
  }
 }
 return max;
}

canonical_original_code:
int max_esp(struct BlockNode *blk, int esp)
{
 struct ListNode *lst;
 int max = esp;
 if(!blk) return 0;
 for(lst = blk->var; lst; lst = lst->next)
 {
  struct DecVarNode *v = (DecVarNode*)lst->data;
  if(is_char(v->type))
  {
   max += 1;
  }
  else
  {
   max = multiple_of_n(max, 4);
   max += 4;
  }
  v->stack_offset = max;
 }
 max = multiple_of_n(max, 4);
 for(lst = blk->cmd; lst; lst = lst->next)
 {
  struct CmdNode *cmd = (CmdNode*)lst->data;
  if(cmd->type == CmdBlock)
  {
   int t = max_esp(cmd->u.b.block, esp);
   if(t > max) t = max;
  }
 }
 return max;
}

variable_types: struct BlockNode { struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *var; struct ListNode *cmd; } *

variable_types: esp int

variable_types: max int

variable_types: struct DecVarNode { enum DecVarType { DecVarGlobal=0, DecVarParam=1, DecVarLocal=2 } context; struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *type; char *name; int nref; int stack_offset; } *

variable_types: struct CmdNode { enum CmdType { CmdIf=0, CmdWhile=1, CmdAssig=2, CmdRet=3, CmdCall=4, CmdBlock=5 } type; union { struct { struct ExpNode { enum ExpType { ExpVar=0, ExpConst=1, ExpBin=2, ExpUn=3, ExpCall=4, ExpNew=5, ExpCast=6 } type; struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *atype; union { struct { struct VarNode { enum VarType { VarId=0, VarArray=1 } type; struct TypeNode *atype; union { struct { char *id; struct DecVarNode { enum DecVarType { DecVarGlobal=0, DecVarParam=1, DecVarLocal=2 } context; struct TypeNode *type; char *name; int nref; int stack_offset; } *dec; } b; struct { struct ExpNode *exp; struct VarNode *var; } d; } u; } *var; } var; struct { enum PrimitiveType { PrimFloat=0, PrimInt=1, PrimChar=2, PrimStr=3 } type; union { int i; float f; char c; char *s; } u; } prim; struct { enum ExpBinType { ExpBinPlus=0, ExpBinMinus=1, ExpBinMult=2, ExpBinDiv=3, ExpBinEQ=4, ExpBinLE=5, ExpBinGE=6, ExpBinLT=7, ExpBinGT=8, ExpBinAnd=9, ExpBinOr=10 } type; struct ExpNode *left; struct ExpNode *right; } bin; struct { enum ExpUnType { ExpUnMinus=0, ExpUnNot=1 } type; struct ExpNode *exp; } un; struct { struct CallNode { char *id; struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *exp; struct DecFuncNode { struct TypeNode *type; char *id; struct ListNode *params; struct BlockNode { struct ListNode *var; struct ListNode *cmd; } *block; int nref; } *dec; } *call; } call; struct { struct TypeNode *type; struct ExpNode *exp; } enew; struct { struct ExpNode *exp; } cast; } u; } *cond; struct CmdNode *cmd_if; struct CmdNode *cmd_else; } i; struct { struct ExpNode *cond; struct CmdNode *cmd; } w; struct { struct VarNode *var; struct ExpNode *exp; } a; struct { struct ExpNode *exp; } r; struct { struct BlockNode *block; } b; struct { struct CallNode *call; } c; } u; } *

variable_types: t int

user_defined_types: struct DecVarNode { enum DecVarType context; struct TypeNode *type; char *name; int nref; int stack_offset; }

user_defined_types: struct CmdNode { enum CmdType type; union { struct { struct ExpNode *cond; struct CmdNode *cmd_if; struct CmdNode *cmd_else; } i; struct { struct ExpNode *cond; struct CmdNode *cmd; } w; struct { struct VarNode *var; struct ExpNode *exp; } a; struct { struct ExpNode *exp; } r; struct { struct BlockNode *block; } b; struct { struct CallNode *call; } c; } u; }

user_defined_types: struct ExpNode { enum ExpType type; struct TypeNode *atype; union { struct { struct VarNode *var; } var; struct { enum PrimitiveType type; union { int i; float f; char c; char *s; } u; } prim; struct { enum ExpBinType type; struct ExpNode *left; struct ExpNode *right; } bin; struct { enum ExpUnType type; struct ExpNode *exp; } un; struct { struct CallNode *call; } call; struct { struct TypeNode *type; struct ExpNode *exp; } enew; struct { struct ExpNode *exp; } cast; } u; }

user_defined_types: struct VarNode { enum VarType type; struct TypeNode *atype; union { struct { char *id; struct DecVarNode *dec; } b; struct { struct ExpNode *exp; struct VarNode *var; } d; } u; }

user_defined_types: struct CallNode { char *id; struct ListNode *exp; struct DecFuncNode *dec; }

user_defined_types: struct DecFuncNode { struct TypeNode *type; char *id; struct ListNode *params; struct BlockNode *block; int nref; }


asmDecVarNode

decompiled_code:
void __fastcall asmDecVarNode(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 v2; // rcx
__int64 v3; // rdx

if ( a1 )
{
v1 = a1;
do
{
if ( !*(_DWORD *)*v1 )
{
v3 = !is_char(*(_DWORD **)(*v1 + 8LL)) ? 4 : 1;
printf("\t.comm\t%s,%d,%d\n", *(const char **)(v2 + 16), v3, (unsigned int)v3);
}
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func5(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 v2; // rcx
__int64 v3; // rdx

if ( a1 )
{
v1 = a1;
do
{
if ( !*(_DWORD *)*v1 )
{
v3 = !func3(*(_DWORD **)(*v1 + 8LL)) ? 4 : 1;
printf("\t.comm\t%s,%d,%d\n", *(const char **)(v2 + 16), v3, (unsigned int)v3);
}
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
}

original_code:
void asmDecVarNode(ListNode* p)
{
 ListNode* l;
 if(!p) return;
 for(l = p; l; l = l->next)
 {
  DecVarNode *v = (DecVarNode*)l->data;
  if(v->context == DecVarGlobal)
  {
   int s;
   if(is_char(v->type)) s = 1;
   else s = 4;
   printf("\t.comm\t%s,%d,%d\n", v->name, s, s);
  }
 }
}

canonical_original_code:
void asmDecVarNode(struct ListNode *p)
{
 struct ListNode *l;
 if(!p) return;
 for(l = p; l; l = l->next)
 {
  struct DecVarNode *v = (DecVarNode*)l->data;
  if(v->context == DecVarGlobal)
  {
   int s;
   if(is_char(v->type)) s = 1;
   else s = 4;
   printf("\t.comm\t%s,%d,%d\n", v->name, s, s);
  }
 }
}

variable_types: struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *

variable_types: s int

user_defined_types: enum DecVarType { DecVarGlobal=0, DecVarParam=1, DecVarLocal=2 }

user_defined_types: enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 }


asmExpNode

decompiled_code:
__int64 __fastcall asmExpNode(unsigned int *a1)
{
unsigned int *v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = a1;
while ( 2 )
{
result = *v1;
switch ( *v1 )
{
case 0u:
return asmVarNode(*((_QWORD *)v1 + 2));
case 2u:
result = asmExpNode(*((_QWORD *)v1 + 3));
v1 = (unsigned int *)*((_QWORD *)v1 + 4);
goto LABEL_5;
case 3u:
case 5u:
v1 = (unsigned int *)*((_QWORD *)v1 + 3);
goto LABEL_5;
case 4u:
return asmCallNode(*((_QWORD *)v1 + 2));
case 6u:
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
LABEL_5:
if ( !v1 )
return result;
continue;
default:
return result;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1)
{
unsigned int *v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = a1;
while ( 2 )
{
result = *v1;
switch ( *v1 )
{
case 0u:
return func8(*((_QWORD *)v1 + 2));
case 2u:
result = func7(*((_QWORD *)v1 + 3));
v1 = (unsigned int *)*((_QWORD *)v1 + 4);
goto LABEL_5;
case 3u:
case 5u:
v1 = (unsigned int *)*((_QWORD *)v1 + 3);
goto LABEL_5;
case 4u:
return func6(*((_QWORD *)v1 + 2));
case 6u:
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
LABEL_5:
if ( !v1 )
return result;
continue;
default:
return result;
}
}
}
return result;
}

original_code:
void asmExpNode(ExpNode* p)
{
 if(!p) return;
 switch(p->type)
 {
  case ExpVar:
   asmVarNode(p->u.var.var);
   break;
  case ExpConst:
   switch(p->u.prim.type)
   {
    case PrimInt:
     break;
    case PrimFloat:
     break;
    case PrimChar:
     break;
    case PrimStr:
     break;
   }
   break;
  case ExpBin:
   asmExpNode(p->u.bin.left);
   switch(p->u.bin.type)
   {
    case ExpBinPlus: break;
    case ExpBinMinus: break;
    case ExpBinMult: break;
    case ExpBinDiv: break;
    case ExpBinEQ: break;
    case ExpBinLE: break;
    case ExpBinGE: break;
    case ExpBinLT: break;
    case ExpBinGT: break;
    case ExpBinAnd: break;
    case ExpBinOr: break;
   }
   asmExpNode(p->u.bin.right);
   break;
  case ExpUn:
   switch(p->u.un.type)
   {
    case ExpUnMinus: break;
    case ExpUnNot: break;
   }
   asmExpNode(p->u.un.exp);
   break;
  case ExpCall:
   asmCallNode(p->u.call.call);
   break;
  case ExpNew:
   asmExpNode(p->u.enew.exp);
   break;
  case ExpCast:
   asmExpNode(p->u.cast.exp);
 }
}

canonical_original_code:
void asmExpNode(struct ExpNode *p)
{
 if(!p) return;
 switch(p->type)
 {
  case ExpVar:
   asmVarNode(p->u.var.var);
   break;
  case ExpConst:
   switch(p->u.prim.type)
   {
    case PrimInt:
     break;
    case PrimFloat:
     break;
    case PrimChar:
     break;
    case PrimStr:
     break;
   }
   break;
  case ExpBin:
   asmExpNode(p->u.bin.left);
   switch(p->u.bin.type)
   {
    case ExpBinPlus: break;
    case ExpBinMinus: break;
    case ExpBinMult: break;
    case ExpBinDiv: break;
    case ExpBinEQ: break;
    case ExpBinLE: break;
    case ExpBinGE: break;
    case ExpBinLT: break;
    case ExpBinGT: break;
    case ExpBinAnd: break;
    case ExpBinOr: break;
   }
   asmExpNode(p->u.bin.right);
   break;
  case ExpUn:
   switch(p->u.un.type)
   {
    case ExpUnMinus: break;
    case ExpUnNot: break;
   }
   asmExpNode(p->u.un.exp);
   break;
  case ExpCall:
   asmCallNode(p->u.call.call);
   break;
  case ExpNew:
   asmExpNode(p->u.enew.exp);
   break;
  case ExpCast:
   asmExpNode(p->u.cast.exp);
 }
}

variable_types: struct ExpNode { enum ExpType { ExpVar=0, ExpConst=1, ExpBin=2, ExpUn=3, ExpCall=4, ExpNew=5, ExpCast=6 } type; struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *atype; union { struct { struct VarNode { enum VarType { VarId=0, VarArray=1 } type; struct TypeNode *atype; union { struct { char *id; struct DecVarNode { enum DecVarType { DecVarGlobal=0, DecVarParam=1, DecVarLocal=2 } context; struct TypeNode *type; char *name; int nref; int stack_offset; } *dec; } b; struct { struct ExpNode *exp; struct VarNode *var; } d; } u; } *var; } var; struct { enum PrimitiveType { PrimFloat=0, PrimInt=1, PrimChar=2, PrimStr=3 } type; union { int i; float f; char c; char *s; } u; } prim; struct { enum ExpBinType { ExpBinPlus=0, ExpBinMinus=1, ExpBinMult=2, ExpBinDiv=3, ExpBinEQ=4, ExpBinLE=5, ExpBinGE=6, ExpBinLT=7, ExpBinGT=8, ExpBinAnd=9, ExpBinOr=10 } type; struct ExpNode *left; struct ExpNode *right; } bin; struct { enum ExpUnType { ExpUnMinus=0, ExpUnNot=1 } type; struct ExpNode *exp; } un; struct { struct CallNode { char *id; struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *exp; struct DecFuncNode { struct TypeNode *type; char *id; struct ListNode *params; struct BlockNode { struct ListNode *var; struct ListNode *cmd; } *block; int nref; } *dec; } *call; } call; struct { struct TypeNode *type; struct ExpNode *exp; } enew; struct { struct ExpNode *exp; } cast; } u; } *


asmVarNode

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

if ( a1 )
{
if ( *(_DWORD *)a1 == 1 )
{
asmVarNode(*(_QWORD *)(a1 + 24));
result = asmExpNode(*(unsigned int **)(a1 + 16));
}
}
return result;
}

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

if ( a1 )
{
if ( *(_DWORD *)a1 == 1 )
{
func8(*(_QWORD *)(a1 + 24));
result = func7(*(unsigned int **)(a1 + 16));
}
}
return result;
}

original_code:
void asmVarNode(VarNode* p)
{
 if(!p) return;
 switch(p->type)
 {
  case VarId:
   break;
  case VarArray:
   asmVarNode(p->u.d.var);
   asmExpNode(p->u.d.exp);
   break;
 }
}

canonical_original_code:
void asmVarNode(struct VarNode *p)
{
 if(!p) return;
 switch(p->type)
 {
  case VarId:
   break;
  case VarArray:
   asmVarNode(p->u.d.var);
   asmExpNode(p->u.d.exp);
   break;
 }
}

variable_types: struct VarNode { enum VarType { VarId=0, VarArray=1 } type; struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *atype; union { struct { char *id; struct DecVarNode { enum DecVarType { DecVarGlobal=0, DecVarParam=1, DecVarLocal=2 } context; struct TypeNode *type; char *name; int nref; int stack_offset; } *dec; } b; struct { struct ExpNode { enum ExpType { ExpVar=0, ExpConst=1, ExpBin=2, ExpUn=3, ExpCall=4, ExpNew=5, ExpCast=6 } type; struct TypeNode *atype; union { struct { struct VarNode *var; } var; struct { enum PrimitiveType { PrimFloat=0, PrimInt=1, PrimChar=2, PrimStr=3 } type; union { int i; float f; char c; char *s; } u; } prim; struct { enum ExpBinType { ExpBinPlus=0, ExpBinMinus=1, ExpBinMult=2, ExpBinDiv=3, ExpBinEQ=4, ExpBinLE=5, ExpBinGE=6, ExpBinLT=7, ExpBinGT=8, ExpBinAnd=9, ExpBinOr=10 } type; struct ExpNode *left; struct ExpNode *right; } bin; struct { enum ExpUnType { ExpUnMinus=0, ExpUnNot=1 } type; struct ExpNode *exp; } un; struct { struct CallNode { char *id; struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *exp; struct DecFuncNode { struct TypeNode *type; char *id; struct ListNode *params; struct BlockNode { struct ListNode *var; struct ListNode *cmd; } *block; int nref; } *dec; } *call; } call; struct { struct TypeNode *type; struct ExpNode *exp; } enew; struct { struct ExpNode *exp; } cast; } u; } *exp; struct VarNode *var; } d; } u; } *


asmCmdNode

decompiled_code:
__int64 __fastcall asmCmdNode(unsigned int *a1)
{
unsigned int *v1; // rbx
__int64 result; // rax
unsigned int *v3; // rdi

v1 = a1;
if ( a1 )
{
while ( 2 )
{
result = *v1;
v3 = (unsigned int *)*((_QWORD *)v1 + 1);
switch ( *v1 )
{
case 0u:
asmExpNode(v3);
result = asmCmdNode(*((_QWORD *)v1 + 2));
v1 = (unsigned int *)*((_QWORD *)v1 + 3);
if ( v1 )
continue;
break;
case 1u:
result = asmExpNode(v3);
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
if ( v1 )
continue;
break;
case 2u:
asmVarNode((__int64)v3);
result = asmExpNode(*((unsigned int **)v1 + 2));
break;
case 3u:
if ( v3 )
result = asmExpNode(v3);
break;
case 4u:
result = asmCallNode((__int64)v3);
break;
case 5u:
result = asmBlockNode(v3);
break;
default:
return result;
}
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1)
{
unsigned int *v1; // rbx
__int64 result; // rax
unsigned int *v3; // rdi

v1 = a1;
if ( a1 )
{
while ( 2 )
{
result = *v1;
v3 = (unsigned int *)*((_QWORD *)v1 + 1);
switch ( *v1 )
{
case 0u:
func7(v3);
result = func9(*((_QWORD *)v1 + 2));
v1 = (unsigned int *)*((_QWORD *)v1 + 3);
if ( v1 )
continue;
break;
case 1u:
result = func7(v3);
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
if ( v1 )
continue;
break;
case 2u:
func8((__int64)v3);
result = func7(*((unsigned int **)v1 + 2));
break;
case 3u:
if ( v3 )
result = func7(v3);
break;
case 4u:
result = func6((__int64)v3);
break;
case 5u:
result = func10(v3);
break;
default:
return result;
}
break;
}
}
return result;
}

original_code:
void asmCmdNode(CmdNode* p)
{
 if(!p) return;
 switch(p->type)
 {
  case CmdIf:
   asmExpNode(p->u.i.cond);
   asmCmdNode(p->u.i.cmd_if);
   if(p->u.i.cmd_else)
   {
    asmCmdNode(p->u.i.cmd_else);
   }
   break;
  case CmdWhile:
   asmExpNode(p->u.w.cond);
   asmCmdNode(p->u.w.cmd);
   break;
  case CmdAssig:
   asmVarNode(p->u.a.var);
   asmExpNode(p->u.a.exp);
   break;
  case CmdRet:
   if(p->u.r.exp)
   {
    asmExpNode(p->u.r.exp);
   }
   break;
  case CmdCall:
   asmCallNode(p->u.c.call);
   break;
  case CmdBlock:
   asmBlockNode(p->u.b.block);
   break;
 }
}

canonical_original_code:
void asmCmdNode(struct CmdNode *p)
{
 if(!p) return;
 switch(p->type)
 {
  case CmdIf:
   asmExpNode(p->u.i.cond);
   asmCmdNode(p->u.i.cmd_if);
   if(p->u.i.cmd_else)
   {
    asmCmdNode(p->u.i.cmd_else);
   }
   break;
  case CmdWhile:
   asmExpNode(p->u.w.cond);
   asmCmdNode(p->u.w.cmd);
   break;
  case CmdAssig:
   asmVarNode(p->u.a.var);
   asmExpNode(p->u.a.exp);
   break;
  case CmdRet:
   if(p->u.r.exp)
   {
    asmExpNode(p->u.r.exp);
   }
   break;
  case CmdCall:
   asmCallNode(p->u.c.call);
   break;
  case CmdBlock:
   asmBlockNode(p->u.b.block);
   break;
 }
}

user_defined_types: enum CmdType { CmdIf=0, CmdWhile=1, CmdAssig=2, CmdRet=3, CmdCall=4, CmdBlock=5 }

user_defined_types: enum ExpType { ExpVar=0, ExpConst=1, ExpBin=2, ExpUn=3, ExpCall=4, ExpNew=5, ExpCast=6 }

user_defined_types: enum PrimitiveType { PrimFloat=0, PrimInt=1, PrimChar=2, PrimStr=3 }

user_defined_types: enum ExpBinType { ExpBinPlus=0, ExpBinMinus=1, ExpBinMult=2, ExpBinDiv=3, ExpBinEQ=4, ExpBinLE=5, ExpBinGE=6, ExpBinLT=7, ExpBinGT=8, ExpBinAnd=9, ExpBinOr=10 }

user_defined_types: enum ExpUnType { ExpUnMinus=0, ExpUnNot=1 }

user_defined_types: struct ListNode { void *data; struct ListNode *next; struct ListNode *last; }

user_defined_types: struct BlockNode { struct ListNode *var; struct ListNode *cmd; }


asmDecFuncNode

decompiled_code:
void __fastcall asmDecFuncNode(__int64 a1)
{
signed int v1; // eax
unsigned int v2; // eax
__int64 *v3; // rax
int v4; // edx
__int64 v5; // rcx

if ( a1 && *(_QWORD *)(a1 + 24) )
{
printf("\n\t.globl\t%s\n", *(const char **)(a1 + 8));
printf("\t.type\t%s, @function\n", *(const char **)(a1 + 8));
printf("%s:\n", *(const char **)(a1 + 8));
printf("\tpushq\t%%rbp\n");
printf("\tmovq\t%%rsp, %%rbp\n");
v1 = max_esp(*(__int64 **)(a1 + 24), 0);
v2 = multiple_of_n(v1, 16);
if ( v2 )
printf("\tsubq\t$%d, %%rsp\n", v2);
v3 = *(__int64 **)(a1 + 16);
if ( v3 )
{
v4 = 8;
do
{
v5 = *v3;
v3 = (__int64 *)v3[1];
*(_DWORD *)(v5 + 28) = v4;
v4 += 4;
}
while ( v3 );
}
asmBlockNode(*(_QWORD *)(a1 + 24));
puts("\tleave");
puts("\tret");
}
}

original_code:
void asmDecFuncNode(DecFuncNode* p)
{
 ListNode *l;
 int esp;
 if(!p || !p->block) return;
 printf("\n\t.globl\t%s\n", p->id);
 printf("\t.type\t%s, @function\n", p->id);
 printf("%s:\n", p->id);
 printf("\tpushq\t%%rbp\n");
 printf("\tmovq\t%%rsp, %%rbp\n");
 esp = multiple_of_n(max_esp(p->block, 0), 16);
 if(esp) printf("\tsubq\t$%d, %%rsp\n", esp);
 esp = 8;
 for(l = p->params; l; l = l->next)
 {
  DecVarNode *v = (DecVarNode*)l->data;
  v->stack_offset = esp;
  esp += 4;
 }
 asmBlockNode(p->block);
 printf("\tleave\n");
 printf("\tret\n");
}

canonical_original_code:
void asmDecFuncNode(struct DecFuncNode *p)
{
 struct ListNode *l;
 int esp;
 if(!p || !p->block) return;
 printf("\n\t.globl\t%s\n", p->id);
 printf("\t.type\t%s, @function\n", p->id);
 printf("%s:\n", p->id);
 printf("\tpushq\t%%rbp\n");
 printf("\tmovq\t%%rsp, %%rbp\n");
 esp = multiple_of_n(max_esp(p->block, 0), 16);
 if(esp) printf("\tsubq\t$%d, %%rsp\n", esp);
 esp = 8;
 for(l = p->params; l; l = l->next)
 {
  struct DecVarNode *v = (DecVarNode*)l->data;
  v->stack_offset = esp;
  esp += 4;
 }
 asmBlockNode(p->block);
 printf("\tleave\n");
 printf("\tret\n");
}

variable_types: struct DecFuncNode { struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *type; char *id; struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *params; struct BlockNode { struct ListNode *var; struct ListNode *cmd; } *block; int nref; } *


asmDeclarationNode

decompiled_code:
void __fastcall asmDeclarationNode(__int64 a1)
{
if ( a1 )
{
if ( *(_DWORD *)a1 )
{
if ( *(_DWORD *)a1 == 1 )
asmDecFuncNode(*(_QWORD *)(a1 + 8));
}
else
{
asmDecVarNode(*(_QWORD **)(a1 + 8));
}
}
}

original_code:
void asmDeclarationNode(DeclarationNode* p)
{
 if(!p) return;
 switch(p->type)
 {
  case DecVar:
   asmDecVarNode(p->u.var);
   break;
  case DecFunc:
   asmDecFuncNode(p->u.func);
 }
}

canonical_original_code:
void asmDeclarationNode(struct DeclarationNode *p)
{
 if(!p) return;
 switch(p->type)
 {
  case DecVar:
   asmDecVarNode(p->u.var);
   break;
  case DecFunc:
   asmDecFuncNode(p->u.func);
 }
}

variable_types: struct DeclarationNode { enum DeclarationType { DecVar=0, DecFunc=1 } type; union { struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *var; struct DecFuncNode { struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *type; char *id; struct ListNode *params; struct BlockNode { struct ListNode *var; struct ListNode *cmd; } *block; int nref; } *func; } u; } *

user_defined_types: struct DeclarationNode { enum DeclarationType type; union { struct ListNode *var; struct DecFuncNode *func; } u; }


catListNode

original_code:
ListNode *catListNode(ListNode *a, ListNode *b)
{
 if(!a) return b;
 if(!b) return a;
 a->last->next = b;
 a->last = b->last;
 return a;
}

canonical_original_code:
struct ListNode *catListNode(struct ListNode *a, struct ListNode *b)
{
 if(!a) return b;
 if(!b) return a;
 a->last->next = b;
 a->last = b->last;
 return a;
}

variable_types:
a
struct ListNode *

variable_types:
b
struct ListNode *

return_type: struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *


newTypeNodeTypeArray

decompiled_code:
__int64 __fastcall newTypeNodeTypeArray(__int64 a1)
{
++*(_DWORD *)(a1 + 4);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
++*(_DWORD *)(a1 + 4);
return a1;
}

original_code:
TypeNode* newTypeNodeTypeArray(TypeNode *t)
{
 t->dims++;
 return t;
}

canonical_original_code:
struct TypeNode *newTypeNodeTypeArray(struct TypeNode *t)
{
 t->dims++;
 return t;
}

variable_types:
t
struct TypeNode *

return_type: struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *

user_defined_types: struct TypeNode { enum BaseType prim; int dims; }


yyerror

decompiled_code:
// attributes: thunk
int yyerror(const char *s)
{
return puts(s);
}

canonical_decompiled_code:
int func0(const char *s)
{
return puts(s);
}

original_code:
void yyerror(char *s)
{
 printf("%s\n", s);
}

variable_types:
s
char *


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12

if ( argc > 1 )
{
*(_QWORD *)&argc = argv[1];
argv = (const char **)"r";
yyin = fopen(*(const char **)&argc, "r");
}
else
{
yyin = stdin;
}
v3 = yyparse(*(_QWORD *)&argc, argv, envp);
checkProgramNode(tree);
asmProgramNode(tree);
return v3;
}

original_code:
int main(int argc, char *argv[])
{
 int ret;
 if (argc < 2) yyin = stdin;
 else yyin = fopen(argv[1], "r");
 ret = yyparse();
 checkProgramNode(tree);
 asmProgramNode(tree);
 return ret;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ret int


printTabs

decompiled_code:
int __fastcall printTabs(int a1)
{
int v1; // ebx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
result = putchar(9);
--v1;
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int v1; // ebx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
result = putchar(9);
--v1;
}
while ( v1 );
}
return result;
}

original_code:
void printTabs(int i)
{
 while(i--)
 {
  printf("\t");
 }
}

variable_types: i int


printTypeNode

decompiled_code:
void __fastcall printTypeNode(unsigned int *a1)
{
unsigned int v1; // eax
signed int i; // ebx

if ( a1 )
{
v1 = *a1;
if ( *a1 == 2 )
{
printf("int");
}
else if ( v1 > 2 )
{
if ( v1 == 3 )
printf("float");
}
else if ( v1 )
{
printf("char");
}
else
{
printf("void");
}
for ( i = 0; (int)a1[1] > i; ++i )
printf("[]");
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int *a1)
{
unsigned int v1; // eax
signed int i; // ebx

if ( a1 )
{
v1 = *a1;
if ( *a1 == 2 )
{
printf("int");
}
else if ( v1 > 2 )
{
if ( v1 == 3 )
printf("float");
}
else if ( v1 )
{
printf("char");
}
else
{
printf("void");
}
for ( i = 0; (int)a1[1] > i; ++i )
printf("[]");
}
}

original_code:
void printTypeNode(TypeNode* p)
{
 int i;
 if(!p) return;
 switch(p->prim)
 {
  case TypeInt:
   printf("int");
   break;
  case TypeChar:
   printf("char");
   break;
  case TypeFloat:
   printf("float");
   break;
  case TypeVoid:
   printf("void");
   break;
 }
 for (i = 0; i < p->dims; i++)
 {
  printf("[]");
 }
}

canonical_original_code:
void printTypeNode(struct TypeNode *p)
{
 int i;
 if(!p) return;
 switch(p->prim)
 {
  case TypeInt:
   printf("int");
   break;
  case TypeChar:
   printf("char");
   break;
  case TypeFloat:
   printf("float");
   break;
  case TypeVoid:
   printf("void");
   break;
 }
 for (i = 0; i < p->dims; i++)
 {
  printf("[]");
 }
}

variable_types: struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *


printParamNode

decompiled_code:
int __fastcall printParamNode(__int64 a1)
{
int result; // eax

if ( a1 )
{
printTypeNode(*(unsigned int **)(a1 + 8));
result = printf(" %s", *(const char **)(a1 + 16));
}
return result;
}

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

if ( a1 )
{
func1(*(unsigned int **)(a1 + 8));
result = printf(" %s", *(const char **)(a1 + 16));
}
return result;
}

original_code:
void printParamNode(DecVarNode* p)
{
 if(!p) return;
 printTypeNode(p->type);
 printf(" %s", p->name);
}

canonical_original_code:
void printParamNode(struct DecVarNode *p)
{
 if(!p) return;
 printTypeNode(p->type);
 printf(" %s", p->name);
}

variable_types: struct DecVarNode { enum DecVarType { DecVarGlobal=0, DecVarParam=1, DecVarLocal=2 } context; struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *type; char *name; int nref; int stack_offset; } *

user_defined_types: struct DecVarNode { enum DecVarType context; struct TypeNode *type; char *name; int nref; int stack_offset; }


printCallNode

decompiled_code:
int __fastcall printCallNode(__int64 a1)
{
_QWORD *v1; // rbx
int result; // eax

if ( a1 )
{
printf("%s(", *(const char **)a1);
v1 = *(_QWORD **)(a1 + 8);
if ( v1 )
{
while ( 1 )
{
printExpNode(*v1);
v1 = (_QWORD *)v1[1];
if ( !v1 )
break;
if ( *(_QWORD **)(a1 + 8) != v1 )
{
putchar(44);
putchar(32);
}
}
}
result = putchar(41);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
_QWORD *v1; // rbx
int result; // eax

if ( a1 )
{
printf("%s(", *(const char **)a1);
v1 = *(_QWORD **)(a1 + 8);
if ( v1 )
{
while ( 1 )
{
func5(*v1);
v1 = (_QWORD *)v1[1];
if ( !v1 )
break;
if ( *(_QWORD **)(a1 + 8) != v1 )
{
putchar(44);
putchar(32);
}
}
}
result = putchar(41);
}
return result;
}

original_code:
void printCallNode(CallNode *p)
{
 ListNode *l;
 if(!p) return;
 printf("%s(", p->id);
 for(l = p->exp; l; l = l->next)
 {
  if(l != p->exp)
  {
   printf(",");
   printf(" ");
  }
  printExpNode((ExpNode*)l->data);
 }
 printf(")");
}

canonical_original_code:
void printCallNode(struct CallNode *p)
{
 struct ListNode *l;
 if(!p) return;
 printf("%s(", p->id);
 for(l = p->exp; l; l = l->next)
 {
  if(l != p->exp)
  {
   printf(",");
   printf(" ");
  }
  printExpNode((struct ExpNode *)l->data);
 }
 printf(")");
}

variable_types: struct CallNode { char *id; struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *exp; struct DecFuncNode { struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *type; char *id; struct ListNode *params; struct BlockNode { struct ListNode *var; struct ListNode *cmd; } *block; int nref; } *dec; } *


printExpNode

decompiled_code:
void __fastcall printExpNode(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // eax
int v3; // eax
_BYTE *v4; // rbx
int v5; // edi
char v6; // al

if ( a1 )
{
v1 = a1;
while ( 2 )
{
switch ( *(_DWORD *)v1 )
{
case 0:
printVarNode(*(_QWORD *)(v1 + 16));
return;
case 1:
v2 = *(_DWORD *)(v1 + 16);
if ( v2 == 2 )
{
putchar(39);
v6 = *(_BYTE *)(v1 + 24);
switch ( v6 )
{
case 10:
printf("\\n");
break;
case 39:
printf("\\'");
break;
case 9:
printf("\\t");
break;
default:
putchar(v6);
break;
}
putchar(39);
}
else if ( v2 > 2 )
{
if ( v2 == 3 )
{
putchar(34);
v4 = *(_BYTE **)(v1 + 24);
v5 = (char)*v4;
if ( *v4 )
{
do
{
switch ( (_BYTE)v5 )
{
case 0xA:
printf("\\n");
break;
case 0x22:
printf("\\\"");
break;
case 9:
printf("\\t");
break;
default:
putchar(v5);
break;
}
v5 = (char)*++v4;
}
while ( (_BYTE)v5 );
}
putchar(34);
}
}
else if ( v2 )
{
printf("%d", *(unsigned int *)(v1 + 24));
}
else
{
printf("%g", *(float *)(v1 + 24));
}
return;
case 2:
putchar(40);
printExpNode(*(_QWORD *)(v1 + 24));
putchar(32);
switch ( *(_DWORD *)(v1 + 16) )
{
case 0:
putchar(43);
break;
case 1:
putchar(45);
break;
case 2:
putchar(42);
break;
case 3:
putchar(47);
break;
case 4:
printf("==");
break;
case 5:
printf("<=");
break;
case 6:
printf(">=");
break;
case 7:
putchar(60);
break;
case 8:
putchar(62);
break;
case 9:
printf("&&");
break;
case 0xA:
printf("||");
break;
default:
break;
}
putchar(32);
printExpNode(*(_QWORD *)(v1 + 32));
putchar(41);
return;
case 3:
v3 = *(_DWORD *)(v1 + 16);
if ( v3 )
{
if ( v3 == 1 )
putchar(33);
}
else
{
putchar(45);
}
v1 = *(_QWORD *)(v1 + 24);
goto LABEL_5;
case 4:
printCallNode(*(_QWORD *)(v1 + 16));
return;
case 5:
printf("new ");
printTypeNode(*(unsigned int **)(v1 + 16));
putchar(91);
printExpNode(*(_QWORD *)(v1 + 24));
putchar(93);
return;
case 6:
putchar(40);
printTypeNode(*(unsigned int **)(v1 + 8));
putchar(41);
v1 = *(_QWORD *)(v1 + 16);
LABEL_5:
if ( !v1 )
return;
continue;
default:
return;
}
}
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // eax
int v3; // eax
_BYTE *v4; // rbx
int v5; // edi
char v6; // al

if ( a1 )
{
v1 = a1;
while ( 2 )
{
switch ( *(_DWORD *)v1 )
{
case 0:
func6(*(_QWORD *)(v1 + 16));
return;
case 1:
v2 = *(_DWORD *)(v1 + 16);
if ( v2 == 2 )
{
putchar(39);
v6 = *(_BYTE *)(v1 + 24);
switch ( v6 )
{
case 10:
printf("\\n");
break;
case 39:
printf("\\'");
break;
case 9:
printf("\\t");
break;
default:
putchar(v6);
break;
}
putchar(39);
}
else if ( v2 > 2 )
{
if ( v2 == 3 )
{
putchar(34);
v4 = *(_BYTE **)(v1 + 24);
v5 = (char)*v4;
if ( *v4 )
{
do
{
switch ( (_BYTE)v5 )
{
case 0xA:
printf("\\n");
break;
case 0x22:
printf("\\\"");
break;
case 9:
printf("\\t");
break;
default:
putchar(v5);
break;
}
v5 = (char)*++v4;
}
while ( (_BYTE)v5 );
}
putchar(34);
}
}
else if ( v2 )
{
printf("%d", *(unsigned int *)(v1 + 24));
}
else
{
printf("%g", *(float *)(v1 + 24));
}
return;
case 2:
putchar(40);
func5(*(_QWORD *)(v1 + 24));
putchar(32);
switch ( *(_DWORD *)(v1 + 16) )
{
case 0:
putchar(43);
break;
case 1:
putchar(45);
break;
case 2:
putchar(42);
break;
case 3:
putchar(47);
break;
case 4:
printf("==");
break;
case 5:
printf("<=");
break;
case 6:
printf(">=");
break;
case 7:
putchar(60);
break;
case 8:
putchar(62);
break;
case 9:
printf("&&");
break;
case 0xA:
printf("||");
break;
default:
break;
}
putchar(32);
func5(*(_QWORD *)(v1 + 32));
putchar(41);
return;
case 3:
v3 = *(_DWORD *)(v1 + 16);
if ( v3 )
{
if ( v3 == 1 )
putchar(33);
}
else
{
putchar(45);
}
v1 = *(_QWORD *)(v1 + 24);
goto LABEL_5;
case 4:
func4(*(_QWORD *)(v1 + 16));
return;
case 5:
printf("new ");
func1(*(unsigned int **)(v1 + 16));
putchar(91);
func5(*(_QWORD *)(v1 + 24));
putchar(93);
return;
case 6:
putchar(40);
func1(*(unsigned int **)(v1 + 8));
putchar(41);
v1 = *(_QWORD *)(v1 + 16);
LABEL_5:
if ( !v1 )
return;
continue;
default:
return;
}
}
}
}

original_code:
void printExpNode(ExpNode* p)
{
 if(!p) return;
 switch(p->type)
 {
  case ExpVar:
   printVarNode(p->u.var.var);
   break;
  case ExpConst:
   switch(p->u.prim.type)
   {
    case PrimInt:
     printf("%d", p->u.prim.u.i);
     break;
    case PrimFloat:
     printf("%g", p->u.prim.u.f);
     break;
    case PrimChar:
     printf("'");
     switch(p->u.prim.u.c)
     {
      case '\n':
       printf("\\n");
       break;
      case '\t':
       printf("\\t");
       break;
      case '\'':
       printf("\\'");
       break;
      default:
       printf("%c", p->u.prim.u.c);
       break;
     }
     printf("'");
     break;
    case PrimStr:
    {
     char *s;
     printf("\"");
     for(s = p->u.prim.u.s; *s; s++)
     {
      switch(*s)
      {
       case '\n':
        printf("\\n");
        break;
       case '\t':
        printf("\\t");
        break;
       case '"':
        printf("\\\"");
        break;
       default:
        printf("%c", *s);
        break;
      }
     }
     printf("\"");
     break;
    }
   }
   break;
  case ExpBin:
   printf("(");
   printExpNode(p->u.bin.left);
   printf(" ");
   switch(p->u.bin.type)
   {
    case ExpBinPlus: printf("+"); break;
    case ExpBinMinus: printf("-"); break;
    case ExpBinMult: printf("*"); break;
    case ExpBinDiv: printf("/"); break;
    case ExpBinEQ: printf("=="); break;
    case ExpBinLE: printf("<="); break;
    case ExpBinGE: printf(">="); break;
    case ExpBinLT: printf("<"); break;
    case ExpBinGT: printf(">"); break;
    case ExpBinAnd: printf("&&"); break;
    case ExpBinOr: printf("||"); break;
   }
   printf(" ");
   printExpNode(p->u.bin.right);
   printf(")");
   break;
  case ExpUn:
   switch(p->u.un.type)
   {
    case ExpUnMinus: printf("-"); break;
    case ExpUnNot: printf("!"); break;
   }
   printExpNode(p->u.un.exp);
   break;
  case ExpCall:
   printCallNode(p->u.call.call);
   break;
  case ExpNew:
   printf("new ");
   printTypeNode(p->u.enew.type);
   printf("[");
   printExpNode(p->u.enew.exp);
   printf("]");
   break;
  case ExpCast:
   printf("(");
   printTypeNode(p->atype);
   printf(")");
   printExpNode(p->u.cast.exp);
 }
}

canonical_original_code:
void printExpNode(struct ExpNode *p)
{
 if(!p) return;
 switch(p->type)
 {
  case ExpVar:
   printVarNode(p->u.var.var);
   break;
  case ExpConst:
   switch(p->u.prim.type)
   {
    case PrimInt:
     printf("%d", p->u.prim.u.i);
     break;
    case PrimFloat:
     printf("%g", p->u.prim.u.f);
     break;
    case PrimChar:
     printf("'");
     switch(p->u.prim.u.c)
     {
      case '\n':
       printf("\\n");
       break;
      case '\t':
       printf("\\t");
       break;
      case '\'':
       printf("\\'");
       break;
      default:
       printf("%c", p->u.prim.u.c);
       break;
     }
     printf("'");
     break;
    case PrimStr:
    {
     char *s;
     printf("\"");
     for(s = p->u.prim.u.s; *s; s++)
     {
      switch(*s)
      {
       case '\n':
        printf("\\n");
        break;
       case '\t':
        printf("\\t");
        break;
       case '"':
        printf("\\\"");
        break;
       default:
        printf("%c", *s);
        break;
      }
     }
     printf("\"");
     break;
    }
   }
   break;
  case ExpBin:
   printf("(");
   printExpNode(p->u.bin.left);
   printf(" ");
   switch(p->u.bin.type)
   {
    case ExpBinPlus: printf("+"); break;
    case ExpBinMinus: printf("-"); break;
    case ExpBinMult: printf("*"); break;
    case ExpBinDiv: printf("/"); break;
    case ExpBinEQ: printf("=="); break;
    case ExpBinLE: printf("<="); break;
    case ExpBinGE: printf(">="); break;
    case ExpBinLT: printf("<"); break;
    case ExpBinGT: printf(">"); break;
    case ExpBinAnd: printf("&&"); break;
    case ExpBinOr: printf("||"); break;
   }
   printf(" ");
   printExpNode(p->u.bin.right);
   printf(")");
   break;
  case ExpUn:
   switch(p->u.un.type)
   {
    case ExpUnMinus: printf("-"); break;
    case ExpUnNot: printf("!"); break;
   }
   printExpNode(p->u.un.exp);
   break;
  case ExpCall:
   printCallNode(p->u.call.call);
   break;
  case ExpNew:
   printf("new ");
   printTypeNode(p->u.enew.type);
   printf("[");
   printExpNode(p->u.enew.exp);
   printf("]");
   break;
  case ExpCast:
   printf("(");
   printTypeNode(p->atype);
   printf(")");
   printExpNode(p->u.cast.exp);
 }
}


printVarNode

decompiled_code:
void __fastcall printVarNode(__int64 a1)
{
if ( a1 )
{
if ( *(_DWORD *)a1 )
{
if ( *(_DWORD *)a1 == 1 )
{
printVarNode(*(_QWORD *)(a1 + 24));
putchar(91);
printExpNode(*(_QWORD *)(a1 + 16));
putchar(93);
}
}
else
{
printf("%s", *(const char **)(a1 + 16));
}
}
}

original_code:
void printVarNode(VarNode* p)
{
 if(!p) return;
 switch(p->type)
 {
  case VarId:
   printf("%s", p->u.b.id);
   break;
  case VarArray:
   printVarNode(p->u.d.var);
   printf("[");
   printExpNode(p->u.d.exp);
   printf("]");
   break;
 }
}

canonical_original_code:
void printVarNode(struct VarNode *p)
{
 if(!p) return;
 switch(p->type)
 {
  case VarId:
   printf("%s", p->u.b.id);
   break;
  case VarArray:
   printVarNode(p->u.d.var);
   printf("[");
   printExpNode(p->u.d.exp);
   printf("]");
   break;
 }
}


printCmdNode

decompiled_code:
int __fastcall printCmdNode(__int64 a1, unsigned int a2)
{
__int64 v2; // rbx
int result; // eax
__int64 v4; // rdi

if ( a1 )
{
v2 = a1;
while ( 2 )
{
result = *(_DWORD *)v2;
switch ( *(_DWORD *)v2 )
{
case 0:
printTabs(a2);
printf("if(");
putchar(32);
printExpNode(*(_QWORD *)(v2 + 8));
putchar(32);
putchar(41);
result = printCmdNode(*(_QWORD *)(v2 + 16), a2);
if ( *(_QWORD *)(v2 + 24) )
{
putchar(10);
printTabs(a2);
result = printf("else");
v2 = *(_QWORD *)(v2 + 24);
goto LABEL_6;
}
return result;
case 1:
printTabs(a2);
printf("while(");
putchar(32);
printExpNode(*(_QWORD *)(v2 + 8));
putchar(32);
result = putchar(41);
v2 = *(_QWORD *)(v2 + 16);
LABEL_6:
if ( v2 )
continue;
return result;
case 2:
printTabs(a2);
printVarNode(*(_QWORD *)(v2 + 8));
putchar(32);
putchar(61);
putchar(32);
v4 = *(_QWORD *)(v2 + 16);
goto LABEL_13;
case 3:
printTabs(a2);
printf("return");
if ( !*(_QWORD *)(v2 + 8) )
goto LABEL_9;
putchar(32);
v4 = *(_QWORD *)(v2 + 8);
LABEL_13:
printExpNode(v4);
result = putchar(59);
break;
case 4:
printTabs(a2);
printCallNode(*(_QWORD *)(v2 + 8));
LABEL_9:
result = putchar(59);
break;
case 5:
result = printBlockNode(*(_QWORD *)(v2 + 8), a2);
break;
default:
return result;
}
break;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, unsigned int a2)
{
__int64 v2; // rbx
int result; // eax
__int64 v4; // rdi

if ( a1 )
{
v2 = a1;
while ( 2 )
{
result = *(_DWORD *)v2;
switch ( *(_DWORD *)v2 )
{
case 0:
func0(a2);
printf("if(");
putchar(32);
func5(*(_QWORD *)(v2 + 8));
putchar(32);
putchar(41);
result = func7(*(_QWORD *)(v2 + 16), a2);
if ( *(_QWORD *)(v2 + 24) )
{
putchar(10);
func0(a2);
result = printf("else");
v2 = *(_QWORD *)(v2 + 24);
goto LABEL_6;
}
return result;
case 1:
func0(a2);
printf("while(");
putchar(32);
func5(*(_QWORD *)(v2 + 8));
putchar(32);
result = putchar(41);
v2 = *(_QWORD *)(v2 + 16);
LABEL_6:
if ( v2 )
continue;
return result;
case 2:
func0(a2);
func6(*(_QWORD *)(v2 + 8));
putchar(32);
putchar(61);
putchar(32);
v4 = *(_QWORD *)(v2 + 16);
goto LABEL_13;
case 3:
func0(a2);
printf("return");
if ( !*(_QWORD *)(v2 + 8) )
goto LABEL_9;
putchar(32);
v4 = *(_QWORD *)(v2 + 8);
LABEL_13:
func5(v4);
result = putchar(59);
break;
case 4:
func0(a2);
func4(*(_QWORD *)(v2 + 8));
LABEL_9:
result = putchar(59);
break;
case 5:
result = func8(*(_QWORD *)(v2 + 8), a2);
break;
default:
return result;
}
break;
}
}
return result;
}

original_code:
void printCmdNode(CmdNode* p, int tabs)
{
 if(!p) return;
 switch(p->type)
 {
  case CmdIf:
   printTabs(tabs);
   printf("if(");
   printf(" ");
   printExpNode(p->u.i.cond);
   printf(" ");
   printf(")");
   printCmdNode(p->u.i.cmd_if, tabs);
   if(p->u.i.cmd_else)
   {
    printf("\n");
    printTabs(tabs);
    printf("else");
    printCmdNode(p->u.i.cmd_else, tabs);
   }
   break;
  case CmdWhile:
   printTabs(tabs);
   printf("while(");
   printf(" ");
   printExpNode(p->u.w.cond);
   printf(" ");
   printf(")");
   printCmdNode(p->u.w.cmd, tabs);
   break;
  case CmdAssig:
   printTabs(tabs);
   printVarNode(p->u.a.var);
   printf(" ");
   printf("=");
   printf(" ");
   printExpNode(p->u.a.exp);
   printf(";");
   break;
  case CmdRet:
   printTabs(tabs);
   printf("return");
   if(p->u.r.exp)
   {
    printf(" ");
    printExpNode(p->u.r.exp);
   }
   printf(";");
   break;
  case CmdCall:
   printTabs(tabs);
   printCallNode(p->u.c.call);
   printf(";");
   break;
  case CmdBlock:
   printBlockNode(p->u.b.block, tabs);
   break;
 }
}

canonical_original_code:
void printCmdNode(struct CmdNode *p, int tabs)
{
 if(!p) return;
 switch(p->type)
 {
  case CmdIf:
   printTabs(tabs);
   printf("if(");
   printf(" ");
   printExpNode(p->u.i.cond);
   printf(" ");
   printf(")");
   printCmdNode(p->u.i.cmd_if, tabs);
   if(p->u.i.cmd_else)
   {
    printf("\n");
    printTabs(tabs);
    printf("else");
    printCmdNode(p->u.i.cmd_else, tabs);
   }
   break;
  case CmdWhile:
   printTabs(tabs);
   printf("while(");
   printf(" ");
   printExpNode(p->u.w.cond);
   printf(" ");
   printf(")");
   printCmdNode(p->u.w.cmd, tabs);
   break;
  case CmdAssig:
   printTabs(tabs);
   printVarNode(p->u.a.var);
   printf(" ");
   printf("=");
   printf(" ");
   printExpNode(p->u.a.exp);
   printf(";");
   break;
  case CmdRet:
   printTabs(tabs);
   printf("return");
   if(p->u.r.exp)
   {
    printf(" ");
    printExpNode(p->u.r.exp);
   }
   printf(";");
   break;
  case CmdCall:
   printTabs(tabs);
   printCallNode(p->u.c.call);
   printf(";");
   break;
  case CmdBlock:
   printBlockNode(p->u.b.block, tabs);
   break;
 }
}

variable_types: struct CmdNode { enum CmdType { CmdIf=0, CmdWhile=1, CmdAssig=2, CmdRet=3, CmdCall=4, CmdBlock=5 } type; union { struct { struct ExpNode { enum ExpType { ExpVar=0, ExpConst=1, ExpBin=2, ExpUn=3, ExpCall=4, ExpNew=5, ExpCast=6 } type; struct TypeNode { enum BaseType { TypeVoid=0, TypeChar=1, TypeInt=2, TypeFloat=3 } prim; int dims; } *atype; union { struct { struct VarNode { enum VarType { VarId=0, VarArray=1 } type; struct TypeNode *atype; union { struct { char *id; struct DecVarNode { enum DecVarType { DecVarGlobal=0, DecVarParam=1, DecVarLocal=2 } context; struct TypeNode *type; char *name; int nref; int stack_offset; } *dec; } b; struct { struct ExpNode *exp; struct VarNode *var; } d; } u; } *var; } var; struct { enum PrimitiveType { PrimFloat=0, PrimInt=1, PrimChar=2, PrimStr=3 } type; union { int i; float f; char c; char *s; } u; } prim; struct { enum ExpBinType { ExpBinPlus=0, ExpBinMinus=1, ExpBinMult=2, ExpBinDiv=3, ExpBinEQ=4, ExpBinLE=5, ExpBinGE=6, ExpBinLT=7, ExpBinGT=8, ExpBinAnd=9, ExpBinOr=10 } type; struct ExpNode *left; struct ExpNode *right; } bin; struct { enum ExpUnType { ExpUnMinus=0, ExpUnNot=1 } type; struct ExpNode *exp; } un; struct { struct CallNode { char *id; struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *exp; struct DecFuncNode { struct TypeNode *type; char *id; struct ListNode *params; struct BlockNode { struct ListNode *var; struct ListNode *cmd; } *block; int nref; } *dec; } *call; } call; struct { struct TypeNode *type; struct ExpNode *exp; } enew; struct { struct ExpNode *exp; } cast; } u; } *cond; struct CmdNode *cmd_if; struct CmdNode *cmd_else; } i; struct { struct ExpNode *cond; struct CmdNode *cmd; } w; struct { struct VarNode *var; struct ExpNode *exp; } a; struct { struct ExpNode *exp; } r; struct { struct BlockNode *block; } b; struct { struct CallNode *call; } c; } u; } *

variable_types: tabs int

user_defined_types: struct CmdNode { enum CmdType type; union { struct { struct ExpNode *cond; struct CmdNode *cmd_if; struct CmdNode *cmd_else; } i; struct { struct ExpNode *cond; struct CmdNode *cmd; } w; struct { struct VarNode *var; struct ExpNode *exp; } a; struct { struct ExpNode *exp; } r; struct { struct BlockNode *block; } b; struct { struct CallNode *call; } c; } u; }


printBlockNode

decompiled_code:
int __fastcall printBlockNode(__int64 **a1, int a2)
{
__int64 *i; // rbx

if ( !a1 )
return putchar(59);
putchar(10);
printTabs(a2);
putchar(123);
putchar(10);
printDecVarNode(*a1, a2 + 1);
for ( i = a1[1]; i; i = (__int64 *)i[1] )
{
printCmdNode(*i, a2 + 1);
putchar(10);
}
printTabs(a2);
return putchar(125);
}

canonical_decompiled_code:
int __fastcall func8(__int64 **a1, int a2)
{
__int64 *i; // rbx

if ( !a1 )
return putchar(59);
putchar(10);
func0(a2);
putchar(123);
putchar(10);
func2(*a1, a2 + 1);
for ( i = a1[1]; i; i = (__int64 *)i[1] )
{
func7(*i, a2 + 1);
putchar(10);
}
func0(a2);
return putchar(125);
}

original_code:
void printBlockNode(BlockNode* p, int tabs)
{
 ListNode* l;
 if(p)
 {
  printf("\n");
  printTabs(tabs);
  printf("{");
  printf("\n");
  printDecVarNode(p->var, tabs+1);
  for(l = p->cmd; l; l = l->next)
  {
   printCmdNode((CmdNode*)l->data, tabs+1);
   printf("\n");
  }
  printTabs(tabs);
  printf("}");
 }
 else
 {
  printf(";");
 }
}

canonical_original_code:
void printBlockNode(struct BlockNode *p, int tabs)
{
 struct ListNode *l;
 if(p)
 {
  printf("\n");
  printTabs(tabs);
  printf("{");
  printf("\n");
  printDecVarNode(p->var, tabs+1);
  for(l = p->cmd; l; l = l->next)
  {
   printCmdNode((struct CmdNode *)l->data, tabs+1);
   printf("\n");
  }
  printTabs(tabs);
  printf("}");
 }
 else
 {
  printf(";");
 }
}

variable_types: struct BlockNode { struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *var; struct ListNode *cmd; } *

user_defined_types: struct ExpNode { enum ExpType type; struct TypeNode *atype; union { struct { struct VarNode *var; } var; struct { enum PrimitiveType type; union { int i; float f; char c; char *s; } u; } prim; struct { enum ExpBinType type; struct ExpNode *left; struct ExpNode *right; } bin; struct { enum ExpUnType type; struct ExpNode *exp; } un; struct { struct CallNode *call; } call; struct { struct TypeNode *type; struct ExpNode *exp; } enew; struct { struct ExpNode *exp; } cast; } u; }


printDecFuncNode

decompiled_code:
int __fastcall printDecFuncNode(__int64 a1, int a2)
{
__int64 *v2; // rbx
int result; // eax

if ( a1 )
{
printTabs(a2);
printTypeNode(*(unsigned int **)a1);
printf(" %s(", *(const char **)(a1 + 8));
v2 = *(__int64 **)(a1 + 16);
if ( v2 )
{
while ( 1 )
{
printParamNode(*v2);
v2 = (__int64 *)v2[1];
if ( !v2 )
break;
if ( *(__int64 **)(a1 + 16) != v2 )
{
putchar(44);
putchar(32);
}
}
}
putchar(41);
result = printBlockNode(*(__int64 ***)(a1 + 24), a2);
}
return result;
}

original_code:
void printDecFuncNode(DecFuncNode* p, int tabs)
{
 ListNode *l;
 if(!p) return;
 printTabs(tabs);
 printTypeNode(p->type);
 printf(" %s(", p->id);
 for(l = p->params; l; l = l->next)
 {
  if(l != p->params)
  {
   printf(",");
   printf(" ");
  }
  printParamNode((DecVarNode*)l->data);
 }
 printf(")");
 printBlockNode(p->block, tabs);
}

canonical_original_code:
void printDecFuncNode(struct DecFuncNode *p, int tabs)
{
 struct ListNode *l;
 if(!p) return;
 printTabs(tabs);
 printTypeNode(p->type);
 printf(" %s(", p->id);
 for(l = p->params; l; l = l->next)
 {
  if(l != p->params)
  {
   printf(",");
   printf(" ");
  }
  printParamNode((struct DecVarNode *)l->data);
 }
 printf(")");
 printBlockNode(p->block, tabs);
}

variable_types: struct ListNode { void *data; struct ListNode *next; struct ListNode *last; } *


printDeclarationNode

decompiled_code:
void __fastcall printDeclarationNode(__int64 a1, int a2)
{
if ( a1 )
{
if ( *(_DWORD *)a1 )
{
if ( *(_DWORD *)a1 == 1 )
{
printDecFuncNode(*(_QWORD *)(a1 + 8), a2);
putchar(10);
}
}
else
{
printDecVarNode(*(__int64 **)(a1 + 8), a2);
}
}
}

original_code:
void printDeclarationNode(DeclarationNode* p, int tabs)
{
 if(!p) return;
 switch(p->type)
 {
  case DecVar:
   printDecVarNode(p->u.var, tabs);
   break;
  case DecFunc:
   printDecFuncNode(p->u.func, tabs);
   printf("\n");
   break;
 }
}

canonical_original_code:
void printDeclarationNode(struct DeclarationNode *p, int tabs)
{
 if(!p) return;
 switch(p->type)
 {
  case DecVar:
   printDecVarNode(p->u.var, tabs);
   break;
  case DecFunc:
   printDecFuncNode(p->u.func, tabs);
   printf("\n");
   break;
 }
}

user_defined_types: enum DeclarationType { DecVar=0, DecFunc=1 }


decompiled_code:
int fin_document()
{
return puts("Fin du document");
}

canonical_decompiled_code:
int func8()
{
return puts("Fin du document");
}

original_code:
void fin_document(void *user_data) {
    printf("Fin du document\n");
}


cdata

decompiled_code:
int __fastcall cdata(__int64 a1, const char *a2, unsigned int a3)
{
return printf("Element CDATA : (longueur = %d) %s\n", a3, a2);
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1, const char *a2, unsigned int a3)
{
return printf("Element CDATA : (longueur = %d) %s\n", a3, a2);
}

original_code:
void cdata(void *user_data, const xmlChar *ch, int len) {
    printf("Element CDATA : (longueur = %d) %s\n", len, ch);
}

canonical_original_code:
void cdata(void *user_data, unsigned char *ch, int len) {
    printf("Element CDATA : (longueur = %d) %s\n", len, ch);
}

variable_types:
ch
unsigned char *

variable_types: len int


commentaire

decompiled_code:
int __fastcall commentaire(__int64 a1, const char *a2)
{
return printf("Commentaire : %s\n", a2);
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, const char *a2)
{
return printf("Commentaire : %s\n", a2);
}

original_code:
void commentaire(void *user_data, const xmlChar *ch) {
    printf("Commentaire : %s\n", ch);
}

canonical_original_code:
void commentaire(void *user_data, unsigned char *ch) {
    printf("Commentaire : %s\n", ch);
}


blanc

decompiled_code:
int __fastcall blanc(__int64 a1, const char *a2, unsigned int a3)
{
return printf("Blancs : (longueur = %d) #%s#\n", a3, a2);
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, const char *a2, unsigned int a3)
{
return printf("Blancs : (longueur = %d) #%s#\n", a3, a2);
}

original_code:
void blanc(void *user_data, const xmlChar *ch, int len) {
    printf("Blancs : (longueur = %d) #%s#\n", len, ch);
}

canonical_original_code:
void blanc(void *user_data, unsigned char *ch, int len) {
    printf("Blancs : (longueur = %d) #%s#\n", len, ch);
}


pi

decompiled_code:
int __fastcall pi(__int64 a1, const char *a2, const char *a3)
{
return printf("PI : %s -> %s\n", a2, a3);
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, const char *a2, const char *a3)
{
return printf("PI : %s -> %s\n", a2, a3);
}

original_code:
void pi(void *user_data, const xmlChar *target, const xmlChar *data) {
    printf("PI : %s -> %s\n", target, data);
}

canonical_original_code:
void pi(void *user_data, unsigned char *target, unsigned char *data) {
    printf("PI : %s -> %s\n", target, data);
}

variable_types:
target
unsigned char *

variable_types:
data
unsigned char *


avertissement

decompiled_code:
int avertissement(__int64 a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
return vfprintf(stderr, a2, arg);
}

canonical_decompiled_code:
int func17(__int64 a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
return vfprintf(stderr, a2, arg);
}

original_code:
void avertissement(void *user_data, const char *msg, ...) {
    va_list args;
    __builtin_va_start(args,msg);
    vfprintf(stderr, msg, args);
    __builtin_va_end(args);
}

canonical_original_code:
void avertissement(void *user_data, char *msg, ...) {
    __builtin_va_list args;
    __builtin_va_start(args,msg);
    vfprintf(stderr, msg, args);
    __builtin_va_end(args);
}

variable_types:
msg
char *


erreur

decompiled_code:
int erreur(__int64 a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
return vfprintf(stderr, a2, arg);
}

canonical_decompiled_code:
int func18(__int64 a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
return vfprintf(stderr, a2, arg);
}

original_code:
void erreur(void *user_data, const char *msg, ...) {
    va_list args;
    __builtin_va_start(args,msg);
    vfprintf(stderr, msg, args);
    __builtin_va_end(args);
}

canonical_original_code:
void erreur(void *user_data, char *msg, ...) {
    __builtin_va_list args;
    __builtin_va_start(args,msg);
    vfprintf(stderr, msg, args);
    __builtin_va_end(args);
}