decompiled_code:
int read_conf()
{
int v0; // ebx
int v1; // ebx
int result; // eax
char v3[112]; // [rsp+0h] [rbp-F8h] BYREF
char nptr[136]; // [rsp+70h] [rbp-88h] BYREF

f_config = fopen(config_name, "r");
if ( !f_config )
{
fprintf(stderr, "Cannot open config file %s, EXITING!\n", config_name);
exit(2);
}
while ( fgets(&str, 256, f_config) )
{
if ( str != 35 && (unsigned int)_isoc99_sscanf(&str, " %[^=]=%[^\n]", v3, nptr) == 2 )
{
if ( !strcmp(v3, "INTERFACE") )
{
snprintf(&interface, 0x81uLL, "%s", nptr);
b_is_iface = 1;
++i_is_configured;
}
else if ( !strcmp(v3, "DB_HOST") )
{
snprintf(&db_host, 0x81uLL, "%s", nptr);
++i_is_configured;
}
else if ( !strcmp(v3, "DB_PORT") )
{
db_port = atoi(nptr);
}
else if ( !strcmp(v3, "DB_NAME") )
{
snprintf(&db_name, 0x81uLL, "%s", nptr);
++i_is_configured;
}
else if ( !strcmp(v3, "DB_USER") )
{
snprintf(&db_user, 0x81uLL, "%s", nptr);
++i_is_configured;
}
else if ( !strcmp(v3, "DB_PASS") )
{
snprintf(&db_pass, 0x81uLL, "%s", nptr);
++i_is_configured;
}
else if ( !strcmp(v3, "LOG") )
{
snprintf(&log_name, 0x81uLL, "%s", nptr);
}
else if ( !strcmp(v3, "PROTOCOL_ETH") )
{
protocol_eth = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_8023") )
{
protocol_8023 = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_SLL") )
{
protocol_sll = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_ARP") )
{
protocol_arp = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_RARP") )
{
protocol_rarp = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_IP") )
{
protocol_ip = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_IPv6") )
{
protocol_ipv6 = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_IGMP") )
{
protocol_igmp = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_ICMP") )
{
protocol_icmp = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_IPX") )
{
protocol_ipx = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_TCP") )
{
protocol_tcp = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_UDP") )
{
protocol_udp = atoi(nptr);
}
else if ( !strcmp(v3, "TCP_PORT") )
{
v0 = i_TCP;
*((_DWORD *)&pole_TCP_portov + v0) = atoi(nptr);
i_TCP = v0 + 1;
}
else if ( !strcmp(v3, "UDP_PORT") )
{
v1 = i_UDP;
*((_DWORD *)&pole_UDP_portov + v1) = atoi(nptr);
i_UDP = v1 + 1;
}
}
}
result = fclose(f_config);
if ( i_is_configured != 5 )
{
printf("*** Incorrect configuration, check %s configuration file!\n", config_name);
exit(9);
}
return result;
}

canonical_decompiled_code:
int func0()
{
int v0; // ebx
int v1; // ebx
int result; // eax
char v3[112]; // [rsp+0h] [rbp-F8h] BYREF
char nptr[136]; // [rsp+70h] [rbp-88h] BYREF

f_config = fopen(config_name, "r");
if ( !f_config )
{
fprintf(stderr, "Cannot open config file %s, EXITING!\n", config_name);
exit(2);
}
while ( fgets(&str, 256, f_config) )
{
if ( str != 35 && (unsigned int)_isoc99_sscanf(&str, " %[^=]=%[^\n]", v3, nptr) == 2 )
{
if ( !strcmp(v3, "INTERFACE") )
{
snprintf(&interface, 0x81uLL, "%s", nptr);
b_is_iface = 1;
++i_is_configured;
}
else if ( !strcmp(v3, "DB_HOST") )
{
snprintf(&db_host, 0x81uLL, "%s", nptr);
++i_is_configured;
}
else if ( !strcmp(v3, "DB_PORT") )
{
db_port = atoi(nptr);
}
else if ( !strcmp(v3, "DB_NAME") )
{
snprintf(&db_name, 0x81uLL, "%s", nptr);
++i_is_configured;
}
else if ( !strcmp(v3, "DB_USER") )
{
snprintf(&db_user, 0x81uLL, "%s", nptr);
++i_is_configured;
}
else if ( !strcmp(v3, "DB_PASS") )
{
snprintf(&db_pass, 0x81uLL, "%s", nptr);
++i_is_configured;
}
else if ( !strcmp(v3, "LOG") )
{
snprintf(&log_name, 0x81uLL, "%s", nptr);
}
else if ( !strcmp(v3, "PROTOCOL_ETH") )
{
protocol_eth = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_8023") )
{
protocol_8023 = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_SLL") )
{
protocol_sll = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_ARP") )
{
protocol_arp = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_RARP") )
{
protocol_rarp = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_IP") )
{
protocol_ip = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_IPv6") )
{
protocol_ipv6 = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_IGMP") )
{
protocol_igmp = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_ICMP") )
{
protocol_icmp = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_IPX") )
{
protocol_ipx = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_TCP") )
{
protocol_tcp = atoi(nptr);
}
else if ( !strcmp(v3, "PROTOCOL_UDP") )
{
protocol_udp = atoi(nptr);
}
else if ( !strcmp(v3, "TCP_PORT") )
{
v0 = i_TCP;
*((_DWORD *)&pole_TCP_portov + v0) = atoi(nptr);
i_TCP = v0 + 1;
}
else if ( !strcmp(v3, "UDP_PORT") )
{
v1 = i_UDP;
*((_DWORD *)&pole_UDP_portov + v1) = atoi(nptr);
i_UDP = v1 + 1;
}
}
}
result = fclose(f_config);
if ( i_is_configured != 5 )
{
printf("*** Incorrect configuration, check %s configuration file!\n", config_name);
exit(9);
}
return result;
}

original_code:
void read_conf()
{
        f_config=fopen ( config_name, "r" );
        if ( !f_config ) {
                fprintf ( stderr,"Cannot open config file %s, EXITING!\n", config_name );
                exit ( 2 );
        }
        while ( fgets ( str, sizeof str, f_config ) ) {
                char name[100],value[128];
                if ( !strncmp ( str, "#", 1 ) ) ;
                else if ( sscanf ( str, " %[^=]=%[^\n]", name, value ) == 2 ) {
                        if ( !strcmp ( name, "INTERFACE" ) ) {
                                snprintf ( interface,sizeof interface,"%s", value );
                                b_is_iface = 1;
                                i_is_configured++;
                        } else if ( !strcmp ( name, "DB_HOST" ) ) {
                                snprintf ( db_host,sizeof db_host,"%s", value );
                                i_is_configured++;
                        } else if ( !strcmp ( name, "DB_PORT" ) ) {
                                db_port = atoi (value);
                        }else if ( !strcmp ( name, "DB_NAME" ) ) {
                                snprintf ( db_name,sizeof db_name,"%s", value );
                                i_is_configured++;
                        } else if ( !strcmp ( name, "DB_USER" ) ) {
                                snprintf ( db_user,sizeof db_user,"%s", value );
                                i_is_configured++;
                        } else if ( !strcmp ( name, "DB_PASS" ) ) {
                                snprintf ( db_pass,sizeof db_pass,"%s", value );
                                i_is_configured++;
                        } else if ( !strcmp ( name, "LOG" ) ) snprintf ( log_name,sizeof log_name,"%s", value );
                        else if ( !strcmp ( name, "PROTOCOL_ETH" ) ) protocol_eth = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_8023" ) ) protocol_8023 = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_SLL" ) ) protocol_sll = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_ARP" ) ) protocol_arp = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_RARP" ) ) protocol_rarp = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_IP" ) ) protocol_ip = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_IPv6" ) ) {
                                protocol_ipv6 = atoi ( value );
                        } else if ( !strcmp ( name, "PROTOCOL_IGMP" ) ) protocol_igmp = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_ICMP" ) ) protocol_icmp = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_IPX" ) ) protocol_ipx = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_TCP" ) ) protocol_tcp = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_UDP" ) ) protocol_udp = atoi ( value );
                        else if ( !strcmp ( name, "TCP_PORT" ) ) {
                                pole_TCP_portov[i_TCP] = atoi ( value );
                                i_TCP++;
                        } else if ( !strcmp ( name, "UDP_PORT" ) ) {
                                pole_UDP_portov[i_UDP] = atoi ( value );
                                i_UDP++;
                        }
                }
        }
        fclose ( f_config );
        if ( i_is_configured != 5 ) {
                printf ( "*** Incorrect configuration, check %s configuration file!\n",config_name );
                exit ( 9 );
        }
}

canonical_original_code:
void read_conf()
{
        f_config=fopen ( config_name, "r" );
        if ( !f_config ) {
                fprintf ( stderr,"Cannot open config file %s, EXITING!\n", config_name );
                exit ( 2 );
        }
        while ( fgets ( str, sizeof str, f_config ) ) {
                char name[100]; char value[128];
                if ( !strncmp ( str, "#", 1 ) ) ;
                else if ( sscanf ( str, " %[^=]=%[^\n]", name, value ) == 2 ) {
                        if ( !strcmp ( name, "INTERFACE" ) ) {
                                snprintf ( interface,sizeof interface,"%s", value );
                                b_is_iface = 1;
                                i_is_configured++;
                        } else if ( !strcmp ( name, "DB_HOST" ) ) {
                                snprintf ( db_host,sizeof db_host,"%s", value );
                                i_is_configured++;
                        } else if ( !strcmp ( name, "DB_PORT" ) ) {
                                db_port = atoi (value);
                        }else if ( !strcmp ( name, "DB_NAME" ) ) {
                                snprintf ( db_name,sizeof db_name,"%s", value );
                                i_is_configured++;
                        } else if ( !strcmp ( name, "DB_USER" ) ) {
                                snprintf ( db_user,sizeof db_user,"%s", value );
                                i_is_configured++;
                        } else if ( !strcmp ( name, "DB_PASS" ) ) {
                                snprintf ( db_pass,sizeof db_pass,"%s", value );
                                i_is_configured++;
                        } else if ( !strcmp ( name, "LOG" ) ) snprintf ( log_name,sizeof log_name,"%s", value );
                        else if ( !strcmp ( name, "PROTOCOL_ETH" ) ) protocol_eth = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_8023" ) ) protocol_8023 = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_SLL" ) ) protocol_sll = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_ARP" ) ) protocol_arp = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_RARP" ) ) protocol_rarp = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_IP" ) ) protocol_ip = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_IPv6" ) ) {
                                protocol_ipv6 = atoi ( value );
                        } else if ( !strcmp ( name, "PROTOCOL_IGMP" ) ) protocol_igmp = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_ICMP" ) ) protocol_icmp = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_IPX" ) ) protocol_ipx = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_TCP" ) ) protocol_tcp = atoi ( value );
                        else if ( !strcmp ( name, "PROTOCOL_UDP" ) ) protocol_udp = atoi ( value );
                        else if ( !strcmp ( name, "TCP_PORT" ) ) {
                                pole_TCP_portov[i_TCP] = atoi ( value );
                                i_TCP++;
                        } else if ( !strcmp ( name, "UDP_PORT" ) ) {
                                pole_UDP_portov[i_UDP] = atoi ( value );
                                i_UDP++;
                        }
                }
        }
        fclose ( f_config );
        if ( i_is_configured != 5 ) {
                printf ( "*** Incorrect configuration, check %s configuration file!\n",config_name );
                exit ( 9 );
        }
}

variable_types:
name
char [100]

variable_types:
value
char [128]


repo: KaTaLyzer/KaTaLyzer

decompiled_code:
_BOOL8 __fastcall get_status(__int64 a1)
{
const char *v1; // rsi
int *v3; // rax
char *v4; // rax
__int64 v5[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v6; // [rsp+10h] [rbp-28h]
__int64 v7; // [rsp+18h] [rbp-20h]
__int64 v8; // [rsp+20h] [rbp-18h]

v1 = *(const char **)(a1 + 32);
if ( !v1 )
return 0LL;
v5[0] = 0LL;
v5[1] = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
strcpy((char *)v5, v1);
if ( ioctl(*(_DWORD *)(a1 + 4), 0x8913uLL, v5) == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR get_status(): Could not retrieve the flags from the device. %s\n", v4);
exit(1);
}
return (v6 & 0x41) == 65;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
const char *v1; // rsi
int *v3; // rax
char *v4; // rax
__int64 v5[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v6; // [rsp+10h] [rbp-28h]
__int64 v7; // [rsp+18h] [rbp-20h]
__int64 v8; // [rsp+20h] [rbp-18h]

v1 = *(const char **)(a1 + 32);
if ( !v1 )
return 0LL;
v5[0] = 0LL;
v5[1] = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
strcpy((char *)v5, v1);
if ( ioctl(*(_DWORD *)(a1 + 4), 0x8913uLL, v5) == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR get_status(): Could not retrieve the flags from the device. %s\n", v4);
exit(1);
}
return (v6 & 0x41) == 65;
}

original_code:
int get_status(struct k_capture *dev)
{
    struct ifreq ifr;
    if (!dev->name)
 return 0;
    memset(&ifr, 0, sizeof(struct ifreq));
    strcpy(ifr.ifr_ifrn.ifrn_name, dev->name);
    if (ioctl(dev->socket, 0x8913, &ifr) == -1) {
     fprintf(stderr,"ERROR get_status(): Could not retrieve the flags from the device. %s\n", strerror((*__errno_location ())));
     exit(1);
    }
    if ((ifr.ifr_ifru.ifru_flags & IFF_UP) && (ifr.ifr_ifru.ifru_flags & IFF_RUNNING)) return 1;
    else return 0;
}

variable_types: struct k_capture { unsigned short interface_auto; int socket; struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; } sll; char *name; struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; } old_status; } *

return_type: int

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

user_defined_types: struct k_capture { unsigned short interface_auto; int socket; struct sockaddr_ll sll; char *name; struct ifreq old_status; }


decompiled_code:
char *find_dev()
{
struct ifaddrs *v0; // rbx
char *v1; // rbx
int *v3; // rax
char *v4; // rax
const char *v5; // rbp
size_t v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
struct ifaddrs *ifap; // [rsp+8h] [rbp-20h] BYREF

if ( getifaddrs(&ifap) == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Error getifaddrs in raw_init(): %s", v4);
exit(1);
}
v0 = ifap;
if ( ifap )
{
while ( 1 )
{
fprintf(stderr, "Interface: %s, Flag: %d\n", v0->ifa_name, v0->ifa_flags);
if ( (v0->ifa_flags & 0x49) == 65 )
break;
v0 = v0->ifa_next;
if ( !v0 )
goto LABEL_5;
}
v5 = v0->ifa_name;
v6 = strlen(v5);
v7 = (char *)malloc(v6 + 1);
v1 = v7;
if ( v7 )
{
strcpy(v7, v5);
freeifaddrs(ifap);
}
else
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(stderr, "Find_dev(): Error malloc: %s\n", v9);
}
}
else
{
LABEL_5:
freeifaddrs(ifap);
v1 = 0LL;
}
return v1;
}

canonical_decompiled_code:
char *func2()
{
struct ifaddrs *v0; // rbx
char *v1; // rbx
int *v3; // rax
char *v4; // rax
const char *v5; // rbp
size_t v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
struct ifaddrs *ifap; // [rsp+8h] [rbp-20h] BYREF

if ( getifaddrs(&ifap) == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Error getifaddrs in raw_init(): %s", v4);
exit(1);
}
v0 = ifap;
if ( ifap )
{
while ( 1 )
{
fprintf(stderr, "Interface: %s, Flag: %d\n", v0->ifa_name, v0->ifa_flags);
if ( (v0->ifa_flags & 0x49) == 65 )
break;
v0 = v0->ifa_next;
if ( !v0 )
goto LABEL_5;
}
v5 = v0->ifa_name;
v6 = strlen(v5);
v7 = (char *)malloc(v6 + 1);
v1 = v7;
if ( v7 )
{
strcpy(v7, v5);
freeifaddrs(ifap);
}
else
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(stderr, "Find_dev(): Error malloc: %s\n", v9);
}
}
else
{
LABEL_5:
freeifaddrs(ifap);
v1 = 0LL;
}
return v1;
}

original_code:
char *find_dev(char *dev_name)
{
    char *file = dev_name;
    struct ifaddrs *ifap;
    struct ifaddrs *ifa;
    if (getifaddrs(&ifap) == -1) {
     fprintf(stderr, "Error getifaddrs in raw_init(): %s",strerror((*__errno_location ())));
     exit(1);
    }
    for (ifa = ifap; ifa != ((void *)0); ifa = ifa->ifa_next) {
     fprintf(stderr, "Interface: %s, Flag: %d\n", ifa->ifa_name,ifa->ifa_flags);
     if ((ifa->ifa_flags & IFF_UP) && (ifa->ifa_flags & IFF_RUNNING) && !(ifa->ifa_flags & IFF_LOOPBACK)) {
         if ((file = (char *) malloc((strlen(ifa->ifa_name) + 1) * sizeof(char))) == ((void *)0)) {
          fprintf(stderr, "Find_dev(): Error malloc: %s\n",strerror((*__errno_location ())));
          return ((void *)0);
         }
         strcpy(file, ifa->ifa_name);
         freeifaddrs(ifap);
         return file;
     }
    }
    freeifaddrs(ifap);
    return ((void *)0);
}

variable_types:
file
char *

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

return_type: char *

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }


decompiled_code:
__int64 __fastcall close_promisc(int fd, const char *a2)
{
int v2; // edx
__int64 result; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
__int64 v8[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v9; // [rsp+10h] [rbp-28h]
__int64 v10; // [rsp+18h] [rbp-20h]
__int64 v11; // [rsp+20h] [rbp-18h]

v8[0] = 0LL;
v8[1] = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
strcpy((char *)v8, a2);
if ( ioctl(fd, 0x8913uLL, v8) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "ERROR: Could not retrieve the flags from the device. %s\n", v5);
result = 1LL;
}
else
{
LOWORD(v9) = v9 ^ 0x100;
v2 = ioctl(fd, 0x8914uLL, v8);
result = 0LL;
if ( v2 == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "ERROR: Could not set flags IFF_PROMISC. %s\n", v7);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, const char *a2)
{
int v2; // edx
__int64 result; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
__int64 v8[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v9; // [rsp+10h] [rbp-28h]
__int64 v10; // [rsp+18h] [rbp-20h]
__int64 v11; // [rsp+20h] [rbp-18h]

v8[0] = 0LL;
v8[1] = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
strcpy((char *)v8, a2);
if ( ioctl(fd, 0x8913uLL, v8) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "ERROR: Could not retrieve the flags from the device. %s\n", v5);
result = 1LL;
}
else
{
LOWORD(v9) = v9 ^ 0x100;
v2 = ioctl(fd, 0x8914uLL, v8);
result = 0LL;
if ( v2 == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "ERROR: Could not set flags IFF_PROMISC. %s\n", v7);
result = 1LL;
}
}
return result;
}

original_code:
int close_promisc(int raw_socket, char *device)
{
    struct ifreq ifr;
    memset(&ifr, 0, sizeof(struct ifreq));
    strcpy(ifr.ifr_ifrn.ifrn_name, device);
    if (ioctl(raw_socket, 0x8913, &ifr) == -1) {
     fprintf(stderr,"ERROR: Could not retrieve the flags from the device. %s\n",strerror((*__errno_location ())));
     return 1;
    }
    ifr.ifr_ifru.ifru_flags ^= IFF_PROMISC;
    if (ioctl(raw_socket, 0x8914, &ifr) == -1) {
     fprintf(stderr, "ERROR: Could not set flags IFF_PROMISC. %s\n",strerror((*__errno_location ())));
     return 1;
    }
    return 0;
}

variable_types:
device
char *

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


decompiled_code:
int __fastcall raw_init(__int64 a1, const char *a2)
{
void *v3; // rdi
size_t v4; // rax
char *v5; // rdi
unsigned __int16 v6; // r12
int v7; // ebp
int result; // eax
int *v9; // rax
char *v10; // rax
char *v11; // rbp
size_t v12; // rax
char *v13; // rdi
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax
int *v20; // rax
char *v21; // rax
int *v22; // rax
char *v23; // rax
__int64 v24[2]; // [rsp+0h] [rbp-88h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-78h] BYREF
int v26; // [rsp+20h] [rbp-68h]
__int64 optval[2]; // [rsp+30h] [rbp-58h] BYREF
char dest[16]; // [rsp+40h] [rbp-48h] BYREF
__m128i v29; // [rsp+50h] [rbp-38h] BYREF
__int64 v30; // [rsp+60h] [rbp-28h]

v3 = *(void **)(a1 + 32);
if ( v3 )
{
free(v3);
*(_QWORD *)(a1 + 32) = 0LL;
}
if ( !strcmp(a2, "auto") )
{
v11 = find_dev();
result = 1;
if ( !v11 )
return result;
v12 = strlen(v11);
v13 = (char *)malloc(v12 + 1);
*(_QWORD *)(a1 + 32) = v13;
if ( !v13 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "Raw_init(): Error malloc: %s\n", v15);
return 1;
}
strcpy(v13, v11);
*(_WORD *)a1 = 1;
}
else
{
*(_WORD *)a1 = 0;
v4 = strlen(a2);
v5 = (char *)malloc(v4 + 1);
*(_QWORD *)(a1 + 32) = v5;
if ( !v5 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "Raw_init(): Error malloc p_capture->name: %s\n", v10);
return 1;
}
strcpy(v5, a2);
}
*(_QWORD *)dest = 0LL;
*(_QWORD *)&dest[8] = 0LL;
v29 = 0uLL;
v30 = 0LL;
optval[0] = 0LL;
optval[1] = 0LL;
v6 = _bswap_16(3);
v7 = socket(17, 3, v6);
if ( v7 <= 0 )
{
fwrite("ERROR: Could not open socket, Got ?\n", 1uLL, 0x24uLL, stderr);
result = 1;
}
else
{
strcpy(dest, *(const char **)(a1 + 32));
fprintf(stderr, "Interface: %s\n", dest);
if ( ioctl(v7, 0x8913uLL, dest) == -1 )
{
v16 = _errno_location();
v17 = strerror(*v16);
fprintf(stderr, "ERROR: Could not retrieve the flags from the device. %s\n", v17);
result = 1;
}
else
{
*(__m128i *)(a1 + 40) = _mm_loadu_si128((const __m128i *)dest);
*(__m128i *)(a1 + 56) = _mm_loadu_si128(&v29);
*(_QWORD *)(a1 + 72) = v30;
v29.m128i_i16[0] |= 0x100u;
if ( ioctl(v7, 0x8914uLL, dest) == -1 )
{
v18 = _errno_location();
v19 = strerror(*v18);
fprintf(stderr, "ERROR: Could not set flags IFF_PROMISC. %s\n", v19);
result = 1;
}
else
{
fprintf(stderr, "Flag: %d\n", (unsigned int)v29.m128i_i16[0]);
if ( ioctl(v7, 0x8933uLL, dest) < 0 )
{
fwrite("ERROR: Error getting the device index.\n", 1uLL, 0x27uLL, stderr);
result = 1;
}
else
{
addr.sa_family = 17;
*(_DWORD *)&addr.sa_data[2] = v29.m128i_i32[0];
*(_WORD *)addr.sa_data = v6;
bind(v7, &addr, 0x14u);
LODWORD(optval[0]) = v29.m128i_i32[0];
WORD2(optval[0]) = 1;
if ( setsockopt(v7, 263, 1, optval, 0x10u) < 0 )
{
v20 = _errno_location();
v21 = strerror(*v20);
fprintf(stderr, "ERROR: Error setsockopt. %s\n", v21);
result = 1;
}
else
{
v24[0] = 10LL;
v24[1] = 0LL;
result = setsockopt(v7, 1, 20, v24, 0x10u);
if ( result )
{
v22 = _errno_location();
v23 = strerror(*v22);
fprintf(stderr, "ERROR: Error setsockopt for time: %s\n", v23);
result = 1;
}
else
{
*(_DWORD *)(a1 + 4) = v7;
*(__m128i *)(a1 + 8) = _mm_loadu_si128((const __m128i *)&addr);
*(_DWORD *)(a1 + 24) = v26;
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, const char *a2)
{
void *v3; // rdi
size_t v4; // rax
char *v5; // rdi
unsigned __int16 v6; // r12
int v7; // ebp
int result; // eax
int *v9; // rax
char *v10; // rax
char *v11; // rbp
size_t v12; // rax
char *v13; // rdi
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax
int *v20; // rax
char *v21; // rax
int *v22; // rax
char *v23; // rax
__int64 v24[2]; // [rsp+0h] [rbp-88h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-78h] BYREF
int v26; // [rsp+20h] [rbp-68h]
__int64 optval[2]; // [rsp+30h] [rbp-58h] BYREF
char dest[16]; // [rsp+40h] [rbp-48h] BYREF
__m128i v29; // [rsp+50h] [rbp-38h] BYREF
__int64 v30; // [rsp+60h] [rbp-28h]

v3 = *(void **)(a1 + 32);
if ( v3 )
{
free(v3);
*(_QWORD *)(a1 + 32) = 0LL;
}
if ( !strcmp(a2, "auto") )
{
v11 = func2();
result = 1;
if ( !v11 )
return result;
v12 = strlen(v11);
v13 = (char *)malloc(v12 + 1);
*(_QWORD *)(a1 + 32) = v13;
if ( !v13 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "Raw_init(): Error malloc: %s\n", v15);
return 1;
}
strcpy(v13, v11);
*(_WORD *)a1 = 1;
}
else
{
*(_WORD *)a1 = 0;
v4 = strlen(a2);
v5 = (char *)malloc(v4 + 1);
*(_QWORD *)(a1 + 32) = v5;
if ( !v5 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "Raw_init(): Error malloc p_capture->name: %s\n", v10);
return 1;
}
strcpy(v5, a2);
}
*(_QWORD *)dest = 0LL;
*(_QWORD *)&dest[8] = 0LL;
v29 = 0uLL;
v30 = 0LL;
optval[0] = 0LL;
optval[1] = 0LL;
v6 = func0(3);
v7 = socket(17, 3, v6);
if ( v7 <= 0 )
{
fwrite("ERROR: Could not open socket, Got ?\n", 1uLL, 0x24uLL, stderr);
result = 1;
}
else
{
strcpy(dest, *(const char **)(a1 + 32));
fprintf(stderr, "Interface: %s\n", dest);
if ( ioctl(v7, 0x8913uLL, dest) == -1 )
{
v16 = _errno_location();
v17 = strerror(*v16);
fprintf(stderr, "ERROR: Could not retrieve the flags from the device. %s\n", v17);
result = 1;
}
else
{
*(__m128i *)(a1 + 40) = _mm_loadu_si128((const __m128i *)dest);
*(__m128i *)(a1 + 56) = _mm_loadu_si128(&v29);
*(_QWORD *)(a1 + 72) = v30;
v29.m128i_i16[0] |= 0x100u;
if ( ioctl(v7, 0x8914uLL, dest) == -1 )
{
v18 = _errno_location();
v19 = strerror(*v18);
fprintf(stderr, "ERROR: Could not set flags IFF_PROMISC. %s\n", v19);
result = 1;
}
else
{
fprintf(stderr, "Flag: %d\n", (unsigned int)v29.m128i_i16[0]);
if ( ioctl(v7, 0x8933uLL, dest) < 0 )
{
fwrite("ERROR: Error getting the device index.\n", 1uLL, 0x27uLL, stderr);
result = 1;
}
else
{
addr.sa_family = 17;
*(_DWORD *)&addr.sa_data[2] = v29.m128i_i32[0];
*(_WORD *)addr.sa_data = v6;
bind(v7, &addr, 0x14u);
LODWORD(optval[0]) = v29.m128i_i32[0];
WORD2(optval[0]) = 1;
if ( setsockopt(v7, 263, 1, optval, 0x10u) < 0 )
{
v20 = _errno_location();
v21 = strerror(*v20);
fprintf(stderr, "ERROR: Error setsockopt. %s\n", v21);
result = 1;
}
else
{
v24[0] = 10LL;
v24[1] = 0LL;
result = setsockopt(v7, 1, 20, v24, 0x10u);
if ( result )
{
v22 = _errno_location();
v23 = strerror(*v22);
fprintf(stderr, "ERROR: Error setsockopt for time: %s\n", v23);
result = 1;
}
else
{
*(_DWORD *)(a1 + 4) = v7;
*(__m128i *)(a1 + 8) = _mm_loadu_si128((const __m128i *)&addr);
*(_DWORD *)(a1 + 24) = v26;
}
}
}
}
}
}
return result;
}

original_code:
int raw_init(struct k_capture *p_capture, char *device)
{
    struct ifreq ifr;
    struct packet_mreq mr;
    struct sockaddr_ll sll;
    int raw_socket;
    int ifindex;
    if (p_capture->name) {
     free(p_capture->name);
     p_capture->name = ((void *)0);
    }
    if (strcmp(device, "auto")) {
     p_capture->interface_auto = 0;
     if ((p_capture->name = (char *) malloc(strlen(device) * sizeof(char) + 1)) == ((void *)0)) {
         fprintf(stderr,"Raw_init(): Error malloc p_capture->name: %s\n",strerror((*__errno_location ())));
         return 1;
     }
     strcpy(p_capture->name, device);
    } else {
     char *file = ((void *)0);
     if ((file = find_dev(file)) == ((void *)0)) return 1;
     if ((p_capture->name = (char *) malloc(strlen(file) * sizeof(char) + 1)) == ((void *)0)) {
         fprintf(stderr, "Raw_init(): Error malloc: %s\n",strerror((*__errno_location ())));
         return 1;
     }
     strcpy(p_capture->name, file);
     p_capture->interface_auto = 1;
     if (!file) {
         free(file);
         file = ((void *)0);
     }
    }
    memset(&ifr, 0, sizeof(struct ifreq));
    memset(&mr, 0, sizeof(struct packet_mreq));
    if ((raw_socket = socket(17, SOCK_RAW, htons(0x0003))) < 1) {
     fprintf(stderr, "ERROR: Could not open socket, Got ?\n");
     return 1;
    }
    strcpy(ifr.ifr_ifrn.ifrn_name, p_capture->name);
    fprintf(stderr, "Interface: %s\n", ifr.ifr_ifrn.ifrn_name);
    if (ioctl(raw_socket, 0x8913, &ifr) == -1) {
     fprintf(stderr,"ERROR: Could not retrieve the flags from the device. %s\n",strerror((*__errno_location ())));
     return 1;
    }
    p_capture->old_status = ifr;
    ifr.ifr_ifru.ifru_flags |= IFF_PROMISC;
    if (ioctl(raw_socket, 0x8914, &ifr) == -1) {
     fprintf(stderr, "ERROR: Could not set flags IFF_PROMISC. %s\n",strerror((*__errno_location ())));
     return 1;
    }
    fprintf(stderr, "Flag: %d\n", ifr.ifr_ifru.ifru_flags);
    if (ioctl(raw_socket, 0x8933, &ifr) < 0) {
     fprintf(stderr, "ERROR: Error getting the device index.\n");
     return 1;
    }
    sll.sll_family = 17;
    sll.sll_ifindex = ifr.ifr_ifru.ifru_ivalue;
    sll.sll_protocol = htons(0x0003);
    bind(raw_socket, (struct sockaddr_ll *) &sll, sizeof(sll));
    ifindex = ifr.ifr_ifru.ifru_ivalue;
    mr.mr_ifindex = ifindex;
    mr.mr_type = 1;
    if (setsockopt(raw_socket, 263, 1, &mr,sizeof(mr)) < 0) {
     fprintf(stderr, "ERROR: Error setsockopt. %s\n", strerror((*__errno_location ())));
     return 1;
    }
    struct timeval tv;
    tv.tv_sec = 10;
    tv.tv_usec = 0;
    if (setsockopt(raw_socket, 1, 20, (char *) &tv,sizeof(struct timeval))) {
     fprintf(stderr, "ERROR: Error setsockopt for time: %s\n", strerror((*__errno_location ())));
     return 1;
    };
    p_capture->socket = raw_socket;
    p_capture->sll = sll;
    return 0;
}

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

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

variable_types: ifindex int

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

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

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


decompiled_code:
void __fastcall __noreturn k_loop(__int64 a1, void (__fastcall *a2)(struct timeval *, _BYTE *))
{
char *v3; // r13
int i; // eax
char *v5; // rax
struct timeval *v6; // rax
struct timeval *v7; // rbp
const char *v8; // r12
size_t v9; // rax
char *v10; // rdi
size_t v11; // rax
char *v12; // rdi
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
_QWORD *v19; // rax
int *v20; // rax
char *v21; // rax
int *v22; // rax
char *v23; // rax
size_t v24; // rax
char *v25; // rax
int v26; // edi
int v27; // edi
struct timeval *v28; // rax
const char *v29; // r12
size_t v30; // rax
char *v31; // rdi
size_t v32; // rax
char *v33; // rdi
int v34; // er12
void *v35; // rdi
void *v36; // rdi
char *v37; // rbp
int *v38; // rax
char *v39; // rax
int *v40; // rax
char *v41; // rax
int *v42; // rax
char *v43; // rax
int *v44; // rax
char *v45; // rax
int *v46; // rax
char *v47; // rax
_BYTE v48[8192]; // [rsp+0h] [rbp-2058h] BYREF
struct timeval tv; // [rsp+2000h] [rbp-58h] BYREF
int v50; // [rsp+2010h] [rbp-48h]
__int16 v51; // [rsp+2014h] [rbp-44h]
void *ptr; // [rsp+2018h] [rbp-40h]

ptr = 0LL;
v3 = 0LL;
for ( i = 1; ; i = 0 )
{
v7 = 0LL;
if ( i )
{
v5 = (char *)malloc(2uLL);
v3 = v5;
if ( !v5 )
{
v13 = _errno_location();
v14 = strerror(*v13);
fprintf(stderr, "k_loop: Error malloc old_interface: %s", v14);
exit(1);
}
*(_WORD *)v5 = 45;
v6 = (struct timeval *)malloc(0x20uLL);
v7 = v6;
if ( !v6 )
{
v15 = _errno_location();
v16 = strerror(*v15);
fprintf(stderr, "k_loop(): Error malloc struct dev_time: %s", v16);
exit(1);
}
gettimeofday(v6, 0LL);
v8 = *(const char **)(a1 + 32);
if ( v8 )
{
v9 = strlen(*(const char **)(a1 + 32));
v10 = (char *)malloc(v9);
v7[1].tv_usec = (__suseconds_t)v10;
if ( !v10 )
{
v17 = _errno_location();
v18 = strerror(*v17);
fprintf(stderr, "k_loop(): Error malloc dt->name: %s", v18);
exit(1);
}
strcpy(v10, v8);
}
else
{
v19 = malloc(8uLL);
v7[1].tv_usec = (__suseconds_t)v19;
if ( !v19 )
{
v20 = _errno_location();
v21 = strerror(*v20);
fprintf(stderr, "k_loop(): Error malloc dt->name: %s", v21);
exit(1);
}
*v19 = 0x6E776F6E6B6E75LL;
}
v11 = strlen(v3);
v12 = (char *)malloc(v11);
v7[1].tv_sec = (__time_t)v12;
if ( !v12 )
{
v22 = _errno_location();
v23 = strerror(*v22);
fprintf(stderr, "k_loop(): Error malloc old_interface: %s", v23);
exit(1);
}
strcpy(v12, v3);
}
if ( *(_WORD *)a1 && !get_status(a1) )
{
v37 = *(char **)(a1 + 32);
if ( v37 )
{
if ( v3 )
free(v3);
v24 = strlen(v37);
v25 = (char *)malloc(v24);
v3 = v25;
if ( !v25 )
{
v38 = _errno_location();
v39 = strerror(*v38);
fprintf(stderr, "k_loop(): Error malloc old_interface: %s", v39);
exit(1);
}
strcpy(v25, v37);
v26 = *(_DWORD *)(a1 + 4);
if ( !v26 || (close_promisc(v26, v37), (v37 = *(char **)(a1 + 32)) != 0LL) )
{
free(v37);
*(_QWORD *)(a1 + 32) = 0LL;
}
}
v27 = *(_DWORD *)(a1 + 4);
if ( v27 )
{
close(v27);
*(_DWORD *)(a1 + 4) = 0;
}
if ( raw_init(a1, "auto") )
{
sleep(2u);
continue;
}
v28 = (struct timeval *)malloc(0x20uLL);
v7 = v28;
if ( !v28 )
{
v40 = _errno_location();
v41 = strerror(*v40);
fprintf(stderr, "k_loop(): Error malloc struct dev_time: %s", v41);
exit(1);
}
gettimeofday(v28, 0LL);
v29 = *(const char **)(a1 + 32);
v30 = strlen(v29);
v31 = (char *)malloc(v30);
v7[1].tv_usec = (__suseconds_t)v31;
if ( !v31 )
{
v42 = _errno_location();
v43 = strerror(*v42);
fprintf(stderr, "k_loop(): Error malloc dt->name: %s", v43);
exit(1);
}
strcpy(v31, v29);
v32 = strlen(v3);
v33 = (char *)malloc(v32);
v7[1].tv_sec = (__time_t)v33;
if ( !v33 )
{
v44 = _errno_location();
v45 = strerror(*v44);
fprintf(stderr, "k_loop(): Error malloc old_interface: %s", v45);
exit(1);
}
strcpy(v33, v3);
}
v34 = recvfrom(*(_DWORD *)(a1 + 4), v48, 0x2000uLL, 0, 0LL, 0LL);
if ( v34 <= 0 )
{
v46 = _errno_location();
v47 = strerror(*v46);
fprintf(stderr, "Warring recv packet. %s\n", v47);
}
else
{
gettimeofday(&tv, 0LL);
v50 = v34;
v51 = *(_WORD *)a1;
if ( v51 && !ptr )
ptr = v7;
a2(&tv, v48);
if ( ptr )
{
v35 = (void *)*((_QWORD *)ptr + 2);
if ( v35 )
{
free(v35);
*((_QWORD *)ptr + 2) = 0LL;
}
v36 = (void *)*((_QWORD *)ptr + 3);
if ( v36 )
{
free(v36);
*((_QWORD *)ptr + 3) = 0LL;
}
free(ptr);
ptr = 0LL;
}
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func5(__int64 a1, void (__fastcall *a2)(struct timeval *, _BYTE *))
{
char *v3; // r13
int i; // eax
char *v5; // rax
struct timeval *v6; // rax
struct timeval *v7; // rbp
const char *v8; // r12
size_t v9; // rax
char *v10; // rdi
size_t v11; // rax
char *v12; // rdi
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
_QWORD *v19; // rax
int *v20; // rax
char *v21; // rax
int *v22; // rax
char *v23; // rax
size_t v24; // rax
char *v25; // rax
int v26; // edi
int v27; // edi
struct timeval *v28; // rax
const char *v29; // r12
size_t v30; // rax
char *v31; // rdi
size_t v32; // rax
char *v33; // rdi
int v34; // er12
void *v35; // rdi
void *v36; // rdi
char *v37; // rbp
int *v38; // rax
char *v39; // rax
int *v40; // rax
char *v41; // rax
int *v42; // rax
char *v43; // rax
int *v44; // rax
char *v45; // rax
int *v46; // rax
char *v47; // rax
_BYTE v48[8192]; // [rsp+0h] [rbp-2058h] BYREF
struct timeval tv; // [rsp+2000h] [rbp-58h] BYREF
int v50; // [rsp+2010h] [rbp-48h]
__int16 v51; // [rsp+2014h] [rbp-44h]
void *ptr; // [rsp+2018h] [rbp-40h]

ptr = 0LL;
v3 = 0LL;
for ( i = 1; ; i = 0 )
{
v7 = 0LL;
if ( i )
{
v5 = (char *)malloc(2uLL);
v3 = v5;
if ( !v5 )
{
v13 = _errno_location();
v14 = strerror(*v13);
fprintf(stderr, "k_loop: Error malloc old_interface: %s", v14);
exit(1);
}
*(_WORD *)v5 = 45;
v6 = (struct timeval *)malloc(0x20uLL);
v7 = v6;
if ( !v6 )
{
v15 = _errno_location();
v16 = strerror(*v15);
fprintf(stderr, "k_loop(): Error malloc struct dev_time: %s", v16);
exit(1);
}
gettimeofday(v6, 0LL);
v8 = *(const char **)(a1 + 32);
if ( v8 )
{
v9 = strlen(*(const char **)(a1 + 32));
v10 = (char *)malloc(v9);
v7[1].tv_usec = (__suseconds_t)v10;
if ( !v10 )
{
v17 = _errno_location();
v18 = strerror(*v17);
fprintf(stderr, "k_loop(): Error malloc dt->name: %s", v18);
exit(1);
}
strcpy(v10, v8);
}
else
{
v19 = malloc(8uLL);
v7[1].tv_usec = (__suseconds_t)v19;
if ( !v19 )
{
v20 = _errno_location();
v21 = strerror(*v20);
fprintf(stderr, "k_loop(): Error malloc dt->name: %s", v21);
exit(1);
}
*v19 = 0x6E776F6E6B6E75LL;
}
v11 = strlen(v3);
v12 = (char *)malloc(v11);
v7[1].tv_sec = (__time_t)v12;
if ( !v12 )
{
v22 = _errno_location();
v23 = strerror(*v22);
fprintf(stderr, "k_loop(): Error malloc old_interface: %s", v23);
exit(1);
}
strcpy(v12, v3);
}
if ( *(_WORD *)a1 && !func1(a1) )
{
v37 = *(char **)(a1 + 32);
if ( v37 )
{
if ( v3 )
free(v3);
v24 = strlen(v37);
v25 = (char *)malloc(v24);
v3 = v25;
if ( !v25 )
{
v38 = _errno_location();
v39 = strerror(*v38);
fprintf(stderr, "k_loop(): Error malloc old_interface: %s", v39);
exit(1);
}
strcpy(v25, v37);
v26 = *(_DWORD *)(a1 + 4);
if ( !v26 || (func3(v26, v37), (v37 = *(char **)(a1 + 32)) != 0LL) )
{
free(v37);
*(_QWORD *)(a1 + 32) = 0LL;
}
}
v27 = *(_DWORD *)(a1 + 4);
if ( v27 )
{
close(v27);
*(_DWORD *)(a1 + 4) = 0;
}
if ( func4(a1, "auto") )
{
sleep(2u);
continue;
}
v28 = (struct timeval *)malloc(0x20uLL);
v7 = v28;
if ( !v28 )
{
v40 = _errno_location();
v41 = strerror(*v40);
fprintf(stderr, "k_loop(): Error malloc struct dev_time: %s", v41);
exit(1);
}
gettimeofday(v28, 0LL);
v29 = *(const char **)(a1 + 32);
v30 = strlen(v29);
v31 = (char *)malloc(v30);
v7[1].tv_usec = (__suseconds_t)v31;
if ( !v31 )
{
v42 = _errno_location();
v43 = strerror(*v42);
fprintf(stderr, "k_loop(): Error malloc dt->name: %s", v43);
exit(1);
}
strcpy(v31, v29);
v32 = strlen(v3);
v33 = (char *)malloc(v32);
v7[1].tv_sec = (__time_t)v33;
if ( !v33 )
{
v44 = _errno_location();
v45 = strerror(*v44);
fprintf(stderr, "k_loop(): Error malloc old_interface: %s", v45);
exit(1);
}
strcpy(v33, v3);
}
v34 = recvfrom(*(_DWORD *)(a1 + 4), v48, 0x2000uLL, 0, 0LL, 0LL);
if ( v34 <= 0 )
{
v46 = _errno_location();
v47 = strerror(*v46);
fprintf(stderr, "Warring recv packet. %s\n", v47);
}
else
{
gettimeofday(&tv, 0LL);
v50 = v34;
v51 = *(_WORD *)a1;
if ( v51 && !ptr )
ptr = v7;
a2(&tv, v48);
if ( ptr )
{
v35 = (void *)*((_QWORD *)ptr + 2);
if ( v35 )
{
free(v35);
*((_QWORD *)ptr + 2) = 0LL;
}
v36 = (void *)*((_QWORD *)ptr + 3);
if ( v36 )
{
free(v36);
*((_QWORD *)ptr + 3) = 0LL;
}
free(ptr);
ptr = 0LL;
}
}
}
}

original_code:
void k_loop(struct k_capture *p_capture, k_handler calback)
{
    struct k_header head;
    struct dev_time *dt;
    int len, start = 1;
    u_char buf[8192];
    char *old_interface;
    head.dt = ((void *)0);
    old_interface = ((void *)0);
    while (1) {
     dt = ((void *)0);
     if (start) {
         if ((old_interface = (char *) malloc(sizeof(char) * strlen("-") + sizeof(char))) == ((void *)0)) {
          fprintf(stderr, "k_loop: Error malloc old_interface: %s",strerror((*__errno_location ())));
          exit(1);
         }
         strcpy(old_interface, "-");
         if ((dt = (struct dev_time *) malloc(sizeof(struct dev_time))) == ((void *)0)) {
          fprintf(stderr,"k_loop(): Error malloc struct dev_time: %s",strerror((*__errno_location ())));
          exit(1);
         }
         gettimeofday(&dt->ts, ((void *)0));
         if (p_capture->name) {
          if ((dt->name_do = (char *) malloc(strlen(p_capture->name) * sizeof(char))) == ((void *)0)) {
              fprintf(stderr, "k_loop(): Error malloc dt->name: %s", strerror((*__errno_location ())));
              exit(1);
          }
          strcpy(dt->name_do, p_capture->name);
         } else {
          if ((dt->name_do = (char *) malloc(strlen("unknown") * sizeof(char) + sizeof(char))) == ((void *)0)) {
              fprintf(stderr, "k_loop(): Error malloc dt->name: %s", strerror((*__errno_location ())));
              exit(1);
          }
          strcpy(dt->name_do, "unknown");
         }
         if ((dt->name_z = (char *) malloc(strlen(old_interface) * sizeof(char))) == ((void *)0)) {
          fprintf(stderr, "k_loop(): Error malloc old_interface: %s", strerror((*__errno_location ())));
          exit(1);
         }
         strcpy(dt->name_z, old_interface);
         start = 0;
     }
     if (p_capture->interface_auto) {
         if (!get_status(p_capture)) {
          if (p_capture->name != ((void *)0)) {
              if (old_interface != ((void *)0)) {
               free(old_interface);
               old_interface = ((void *)0);
              }
              if ((old_interface = (char *) malloc(strlen(p_capture->name) * sizeof(char))) == ((void *)0)) {
               fprintf(stderr,"k_loop(): Error malloc old_interface: %s", strerror((*__errno_location ())));
               exit(1);
              }
              strcpy(old_interface, p_capture->name);
          }
          if (p_capture->name && p_capture->socket) close_promisc(p_capture->socket, p_capture->name);
          if (p_capture->name) {
              free(p_capture->name);
              p_capture->name = ((void *)0);
          }
          if (p_capture->socket) {
              close(p_capture->socket);
              p_capture->socket = 0;
          }
          if (raw_init(p_capture, "auto")) {
              sleep(2);
              continue;
          }
          if ((dt = (struct dev_time *) malloc(sizeof(struct dev_time))) == ((void *)0)) {
              fprintf(stderr,"k_loop(): Error malloc struct dev_time: %s", strerror((*__errno_location ())));
              exit(1);
          }
          gettimeofday(&dt->ts, ((void *)0));
          if ((dt->name_do = (char *) malloc(strlen(p_capture->name) * sizeof(char))) == ((void *)0)) {
              fprintf(stderr, "k_loop(): Error malloc dt->name: %s", strerror((*__errno_location ())));
              exit(1);
          }
          strcpy(dt->name_do, p_capture->name);
          if ((dt->name_z = (char *) malloc(strlen(old_interface) * sizeof(char))) == ((void *)0)) {
              fprintf(stderr, "k_loop(): Error malloc old_interface: %s", strerror((*__errno_location ())));
              exit(1);
          }
          strcpy(dt->name_z, old_interface);
         }
     }
     len = recvfrom(p_capture->socket, buf, sizeof(buf), 0, ((void *)0), ((void *)0));
     if (len <= 0) {
         fprintf(stderr, "Warring recv packet. %s\n", strerror((*__errno_location ())));
         continue;
     }
     gettimeofday(&head.ts, ((void *)0));
     head.len = len;
     head.interface_auto = p_capture->interface_auto;
     if (p_capture->interface_auto && (head.dt == ((void *)0))) head.dt = dt;
     calback(&head, (u_char *) & buf);
     if (head.dt != ((void *)0)) {
         if (head.dt->name_z != ((void *)0)) {
          free(head.dt->name_z);
          head.dt->name_z = ((void *)0);
         }
         if (head.dt->name_do) {
          free(head.dt->name_do);
          head.dt->name_do = ((void *)0);
         }
         free(head.dt);
         head.dt = ((void *)0);
     }
    }
}

canonical_original_code:
void k_loop(struct k_capture *p_capture, void (*calback)(struct k_header *header, unsigned char *pkt_data))
{
    struct k_header head;
    struct dev_time *dt;
    int len; int start = 1;
    unsigned char buf[8192];
    char *old_interface;
    head.dt = ((void *)0);
    old_interface = ((void *)0);
    while (1) {
     dt = ((void *)0);
     if (start) {
         if ((old_interface = (char *) malloc(sizeof(char) * strlen("-") + sizeof(char))) == ((void *)0)) {
          fprintf(stderr, "k_loop: Error malloc old_interface: %s",strerror((*__errno_location ())));
          exit(1);
         }
         strcpy(old_interface, "-");
         if ((dt = (struct dev_time *) malloc(sizeof(struct dev_time))) == ((void *)0)) {
          fprintf(stderr,"k_loop(): Error malloc struct dev_time: %s",strerror((*__errno_location ())));
          exit(1);
         }
         gettimeofday(&dt->ts, ((void *)0));
         if (p_capture->name) {
          if ((dt->name_do = (char *) malloc(strlen(p_capture->name) * sizeof(char))) == ((void *)0)) {
              fprintf(stderr, "k_loop(): Error malloc dt->name: %s", strerror((*__errno_location ())));
              exit(1);
          }
          strcpy(dt->name_do, p_capture->name);
         } else {
          if ((dt->name_do = (char *) malloc(strlen("unknown") * sizeof(char) + sizeof(char))) == ((void *)0)) {
              fprintf(stderr, "k_loop(): Error malloc dt->name: %s", strerror((*__errno_location ())));
              exit(1);
          }
          strcpy(dt->name_do, "unknown");
         }
         if ((dt->name_z = (char *) malloc(strlen(old_interface) * sizeof(char))) == ((void *)0)) {
          fprintf(stderr, "k_loop(): Error malloc old_interface: %s", strerror((*__errno_location ())));
          exit(1);
         }
         strcpy(dt->name_z, old_interface);
         start = 0;
     }
     if (p_capture->interface_auto) {
         if (!get_status(p_capture)) {
          if (p_capture->name != ((void *)0)) {
              if (old_interface != ((void *)0)) {
               free(old_interface);
               old_interface = ((void *)0);
              }
              if ((old_interface = (char *) malloc(strlen(p_capture->name) * sizeof(char))) == ((void *)0)) {
               fprintf(stderr,"k_loop(): Error malloc old_interface: %s", strerror((*__errno_location ())));
               exit(1);
              }
              strcpy(old_interface, p_capture->name);
          }
          if (p_capture->name && p_capture->socket) close_promisc(p_capture->socket, p_capture->name);
          if (p_capture->name) {
              free(p_capture->name);
              p_capture->name = ((void *)0);
          }
          if (p_capture->socket) {
              close(p_capture->socket);
              p_capture->socket = 0;
          }
          if (raw_init(p_capture, "auto")) {
              sleep(2);
              continue;
          }
          if ((dt = (struct dev_time *) malloc(sizeof(struct dev_time))) == ((void *)0)) {
              fprintf(stderr,"k_loop(): Error malloc struct dev_time: %s", strerror((*__errno_location ())));
              exit(1);
          }
          gettimeofday(&dt->ts, ((void *)0));
          if ((dt->name_do = (char *) malloc(strlen(p_capture->name) * sizeof(char))) == ((void *)0)) {
              fprintf(stderr, "k_loop(): Error malloc dt->name: %s", strerror((*__errno_location ())));
              exit(1);
          }
          strcpy(dt->name_do, p_capture->name);
          if ((dt->name_z = (char *) malloc(strlen(old_interface) * sizeof(char))) == ((void *)0)) {
              fprintf(stderr, "k_loop(): Error malloc old_interface: %s", strerror((*__errno_location ())));
              exit(1);
          }
          strcpy(dt->name_z, old_interface);
         }
     }
     len = recvfrom(p_capture->socket, buf, sizeof(buf), 0, ((void *)0), ((void *)0));
     if (len <= 0) {
         fprintf(stderr, "Warring recv packet. %s\n", strerror((*__errno_location ())));
         continue;
     }
     gettimeofday(&head.ts, ((void *)0));
     head.len = len;
     head.interface_auto = p_capture->interface_auto;
     if (p_capture->interface_auto && (head.dt == ((void *)0))) head.dt = dt;
     calback(&head, (unsigned char *) & buf);
     if (head.dt != ((void *)0)) {
         if (head.dt->name_z != ((void *)0)) {
          free(head.dt->name_z);
          head.dt->name_z = ((void *)0);
         }
         if (head.dt->name_do) {
          free(head.dt->name_do);
          head.dt->name_do = ((void *)0);
         }
         free(head.dt);
         head.dt = ((void *)0);
     }
    }
}

variable_types: void (*)(struct k_header { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int len; unsigned short interface_auto; struct dev_time { struct timeval ts; char *name_z; char *name_do; } *dt; } *header, unsigned char *pkt_data)

variable_types: struct dev_time { struct timeval { long tv_sec; long tv_usec; } ts; char *name_z; char *name_do; } *

variable_types: len int

variable_types: start int

variable_types:
buf
unsigned char [8192]

return_type: void

user_defined_types: struct k_header { struct timeval ts; unsigned int len; unsigned short interface_auto; struct dev_time *dt; }

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


repo: KailoKyra/Clay

decompiled_code:
__int64 __fastcall audio_output_init(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
if ( (int)circular_buffer_init(a1, a2, 4LL) < 0 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 32) = 0;
*(_QWORD *)(a1 + 40) = a3;
*(_QWORD *)(a1 + 48) = a4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
if ( (int)circular_buffer_init(a1, a2, 4LL) < 0 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 32) = 0;
*(_QWORD *)(a1 + 40) = a3;
*(_QWORD *)(a1 + 48) = a4;
return 0LL;
}

original_code:
int audio_output_init(t_audio_output *self, unsigned int audio_buffer_size,
                              void *sound_chip, audio_output_sample_callback sample_callback)
{
    if (circular_buffer_init(&self->circular_buffer, audio_buffer_size, sizeof(t_stereo_sample)) < 0)
        return (-1);
    self->cycle_counter = 0;
    self->_sound_chip = sound_chip;
    self->_sample_callback = sample_callback;
    return (0);
}

canonical_original_code:
int audio_output_init(struct s_audio_output *self, unsigned int audio_buffer_size, void *sound_chip, void (*sample_callback)(void *, unsigned short *, unsigned short *))
{
    if (circular_buffer_init(&self->circular_buffer, audio_buffer_size, sizeof(t_stereo_sample)) < 0)
        return (-1);
    self->cycle_counter = 0;
    self->_sound_chip = sound_chip;
    self->_sample_callback = sample_callback;
    return (0);
}

variable_types: struct s_audio_output { struct s_circular_buffer { void *buffer; unsigned int write_cursor; unsigned int read_cursor; unsigned int data_written; unsigned int data_size; unsigned int buffer_size; } circular_buffer; float cycle_counter; void *_sound_chip; void (*_sample_callback)(void *, unsigned short *, unsigned short *); } *

variable_types: void (*)(void *, unsigned short *, unsigned short *)

user_defined_types: struct s_audio_output { struct s_circular_buffer circular_buffer; float cycle_counter; void *_sound_chip; void (*_sample_callback)(void *, unsigned short *, unsigned short *); }


decompiled_code:
int __fastcall audio_output_update(__int64 a1, int a2)
{
float v2; // xmm0_4
int result; // eax
char v4[2]; // [rsp+0h] [rbp-1Ch] BYREF
char v5[26]; // [rsp+2h] [rbp-1Ah] BYREF

if ( *(_QWORD *)a1 )
{
v2 = (float)a2 + *(float *)(a1 + 32);
if ( v2 >= 83.591835 )
{
*(float *)(a1 + 32) = v2 - 83.591835;
(*(void (__fastcall **)(_QWORD, char *, char *))(a1 + 48))(*(_QWORD *)(a1 + 40), v4, v5);
pthread_mutex_lock(&circular_buffer_mutex);
circular_buffer_write(a1, v4, 1LL);
result = pthread_mutex_unlock(&circular_buffer_mutex);
}
else
{
*(float *)(a1 + 32) = v2;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2)
{
float v2; // xmm0_4
int result; // eax
char v4[2]; // [rsp+0h] [rbp-1Ch] BYREF
char v5[26]; // [rsp+2h] [rbp-1Ah] BYREF

if ( *(_QWORD *)a1 )
{
v2 = (float)a2 + *(float *)(a1 + 32);
if ( v2 >= 83.591835 )
{
*(float *)(a1 + 32) = v2 - 83.591835;
(*(void (__fastcall **)(_QWORD, char *, char *))(a1 + 48))(*(_QWORD *)(a1 + 40), v4, v5);
pthread_mutex_lock(&circular_buffer_mutex);
circular_buffer_write(a1, v4, 1LL);
result = pthread_mutex_unlock(&circular_buffer_mutex);
}
else
{
*(float *)(a1 + 32) = v2;
}
}
return result;
}

original_code:
void audio_output_update(t_audio_output *self, unsigned int elapsed_cycles)
{
    t_stereo_sample sample;
    if (self->circular_buffer.buffer)
    {
        self->cycle_counter += elapsed_cycles;
        if (self->cycle_counter >= ((3.6864f*(1000000)) / (44100.0f)))
        {
            self->cycle_counter -= ((3.6864f*(1000000)) / (44100.0f));
            self->_sample_callback(self->_sound_chip, &sample.l, &sample.r);
            pthread_mutex_lock(&_circular_buffer_mutex);
            circular_buffer_write(&self->circular_buffer, &sample, 1);
            pthread_mutex_unlock(&_circular_buffer_mutex);
        }
    }
}

canonical_original_code:
void audio_output_update(struct s_audio_output *self, unsigned int elapsed_cycles)
{
    struct s_stereo_sample sample;
    if (self->circular_buffer.buffer)
    {
        self->cycle_counter += elapsed_cycles;
        if (self->cycle_counter >= ((3.6864f*(1000000)) / (44100.0f)))
        {
            self->cycle_counter -= ((3.6864f*(1000000)) / (44100.0f));
            self->_sample_callback(self->_sound_chip, &sample.l, &sample.r);
            pthread_mutex_lock(&_circular_buffer_mutex);
            circular_buffer_write(&self->circular_buffer, &sample, 1);
            pthread_mutex_unlock(&_circular_buffer_mutex);
        }
    }
}

variable_types: struct s_stereo_sample { unsigned short l; unsigned short r; }

user_defined_types: struct s_circular_buffer { void *buffer; unsigned int write_cursor; unsigned int read_cursor; unsigned int data_written; unsigned int data_size; unsigned int buffer_size; }


decompiled_code:
__int64 __fastcall audio_output_read(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // er12

v3 = 0;
if ( a3 )
{
pthread_mutex_lock(&circular_buffer_mutex);
v3 = circular_buffer_read(a1, a2, a3);
pthread_mutex_unlock(&circular_buffer_mutex);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // er12

v3 = 0;
if ( a3 )
{
pthread_mutex_lock(&circular_buffer_mutex);
v3 = circular_buffer_read(a1, a2, a3);
pthread_mutex_unlock(&circular_buffer_mutex);
}
return v3;
}

original_code:
int audio_output_read(t_audio_output *self, t_stereo_sample *buf, unsigned int nbSamples)
{
    int ret = 0;
    if (nbSamples)
    {
        pthread_mutex_lock(&_circular_buffer_mutex);
        ret = circular_buffer_read(&self->circular_buffer, buf, nbSamples);
        pthread_mutex_unlock(&_circular_buffer_mutex);
    }
    return (ret);
}

canonical_original_code:
int audio_output_read(struct s_audio_output *self, struct s_stereo_sample *buf, unsigned int nbSamples)
{
    int ret = 0;
    if (nbSamples)
    {
        pthread_mutex_lock(&_circular_buffer_mutex);
        ret = circular_buffer_read(&self->circular_buffer, buf, nbSamples);
        pthread_mutex_unlock(&_circular_buffer_mutex);
    }
    return (ret);
}

variable_types: struct s_stereo_sample { unsigned short l; unsigned short r; } *

variable_types:
nbSamples
unsigned int

variable_types: ret int


decompiled_code:
_BOOL8 __fastcall circular_buffer_init(__int64 a1, unsigned int a2, int a3)
{
void *v3; // rax

*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
if ( !a3 || a2 <= 1 )
return 0LL;
*(_DWORD *)(a1 + 20) = a3;
*(_DWORD *)(a1 + 24) = a2;
v3 = malloc(a3 * a2);
*(_QWORD *)a1 = v3;
return v3 != 0LL;
}

original_code:
int circular_buffer_init(t_circular_buffer *self, unsigned int n, unsigned int size)
{
    memset(self, 0, sizeof(t_circular_buffer));
    if (!size || (n < 2))
        return (0);
    self->data_size = size;
    self->buffer_size = n;
    if ((self->buffer = malloc(self->buffer_size * self->data_size)) == ((void *)0))
        return (0);
    return (1);
}

canonical_original_code:
int circular_buffer_init(struct s_circular_buffer *self, unsigned int n, unsigned int size)
{
    memset(self, 0, sizeof(t_circular_buffer));
    if (!size || (n < 2))
        return (0);
    self->data_size = size;
    self->buffer_size = n;
    if ((self->buffer = malloc(self->buffer_size * self->data_size)) == ((void *)0))
        return (0);
    return (1);
}

variable_types: struct s_circular_buffer { void *buffer; unsigned int write_cursor; unsigned int read_cursor; unsigned int data_written; unsigned int data_size; unsigned int buffer_size; } *

variable_types:
n
unsigned int

variable_types:
size
unsigned int


decompiled_code:
__int64 __fastcall circular_buffer_read(__int64 a1, char *a2, unsigned int a3)
{
unsigned int v5; // esi
unsigned int v6; // er13
int v8; // eax
unsigned int v9; // er13

if ( *(_DWORD *)(a1 + 16) < a3 )
return 0xFFFFFFFFLL;
v5 = *(_DWORD *)(a1 + 12);
v6 = *(_DWORD *)(a1 + 24);
if ( v5 + a3 >= v6 )
{
v8 = *(_DWORD *)(a1 + 20);
v9 = v8 * (v6 - v5);
memcpy(a2, (const void *)(*(_QWORD *)a1 + v8 * v5), v9);
memcpy(&a2[v9], *(const void **)a1, *(_DWORD *)(a1 + 20) * a3 - v9);
}
else
{
memcpy(a2, (const void *)(*(_QWORD *)a1 + v5), *(_DWORD *)(a1 + 20) * a3);
}
*(_DWORD *)(a1 + 12) = (*(_DWORD *)(a1 + 12) + a3) % *(_DWORD *)(a1 + 24);
*(_DWORD *)(a1 + 16) -= a3;
return a3;
}

original_code:
int circular_buffer_read(t_circular_buffer *self, void *buffer, unsigned int n)
{
    if (n > self->data_written)
        return (-1);
    if ((self->read_cursor + n) < self->buffer_size)
        memcpy(buffer, ((char *)self->buffer) + self->read_cursor, (n * self->data_size));
    else
    {
        const unsigned int sub_buffer_size = (self->buffer_size - self->read_cursor) * self->data_size;
        memcpy(buffer, ((char *)self->buffer) + (self->read_cursor * self->data_size), sub_buffer_size);
        memcpy((char *)buffer + sub_buffer_size, self->buffer, (n * self->data_size) - sub_buffer_size);
    }
    self->read_cursor = (self->read_cursor + n) % self->buffer_size;
    self->data_written -= n;
    return (n);
}

canonical_original_code:
int circular_buffer_read(struct s_circular_buffer *self, void *buffer, unsigned int n)
{
    if (n > self->data_written)
        return (-1);
    if ((self->read_cursor + n) < self->buffer_size)
        memcpy(buffer, ((char *)self->buffer) + self->read_cursor, (n * self->data_size));
    else
    {
        unsigned int sub_buffer_size = (self->buffer_size - self->read_cursor) * self->data_size;
        memcpy(buffer, ((char *)self->buffer) + (self->read_cursor * self->data_size), sub_buffer_size);
        memcpy((char *)buffer + sub_buffer_size, self->buffer, (n * self->data_size) - sub_buffer_size);
    }
    self->read_cursor = (self->read_cursor + n) % self->buffer_size;
    self->data_written -= n;
    return (n);
}

variable_types:
buffer
void *


original_code:
int circular_buffer_write(t_circular_buffer *self, const void *buffer, unsigned int n)
{
    if (n > (self->buffer_size - self->data_written))
        return (-1);
    if ((self->write_cursor + n) < self->buffer_size)
        memcpy((char *)self->buffer + (self->write_cursor * self->data_size), buffer, n * self->data_size);
    else
    {
        const unsigned int sub_buffer_size = (self->buffer_size - self->write_cursor) * self->data_size;
        memcpy(((char *)self->buffer) + (self->write_cursor * self->data_size), buffer, sub_buffer_size);
        memcpy(self->buffer, (char *)buffer + sub_buffer_size, (n * self->data_size) - sub_buffer_size);
    }
    self->write_cursor = (self->write_cursor + n) % self->buffer_size;
    self->data_written += n;
    return (n);
}

canonical_original_code:
int circular_buffer_write(struct s_circular_buffer *self, void *buffer, unsigned int n)
{
    if (n > (self->buffer_size - self->data_written))
        return (-1);
    if ((self->write_cursor + n) < self->buffer_size)
        memcpy((char *)self->buffer + (self->write_cursor * self->data_size), buffer, n * self->data_size);
    else
    {
        unsigned int sub_buffer_size = (self->buffer_size - self->write_cursor) * self->data_size;
        memcpy(((char *)self->buffer) + (self->write_cursor * self->data_size), buffer, sub_buffer_size);
        memcpy(self->buffer, (char *)buffer + sub_buffer_size, (n * self->data_size) - sub_buffer_size);
    }
    self->write_cursor = (self->write_cursor + n) % self->buffer_size;
    self->data_written += n;
    return (n);
}


original_code:
int circular_buffer_write_overwrite(t_circular_buffer *self, const void *buffer, unsigned int n)
{
    if ((self->data_written + n) > self->buffer_size)
        self->read_cursor = (self->read_cursor + n - (self->buffer_size - self->data_written)) % self->buffer_size;
    while (n)
    {
        unsigned int tocopy = (n > self->buffer_size) ? self->buffer_size : n;
        if ((self->write_cursor + tocopy) < self->buffer_size)
            memcpy((char *)self->buffer + (self->write_cursor * self->data_size), buffer, tocopy * self->data_size);
        else
        {
            const unsigned int sub_buffer_size = (self->buffer_size - self->write_cursor) * self->data_size;
            memcpy(((char *)self->buffer) + (self->write_cursor * self->data_size), buffer, sub_buffer_size);
            memcpy(self->buffer, (char *)buffer + sub_buffer_size, (tocopy * self->data_size) - sub_buffer_size);
        }
        self->write_cursor = (self->write_cursor + tocopy) % self->buffer_size;
        self->data_written += tocopy;
    }
    if (self->data_written > self->buffer_size)
        self->data_written = self->buffer_size;
    return (n);
}

canonical_original_code:
int circular_buffer_write_overwrite(struct s_circular_buffer *self, void *buffer, unsigned int n)
{
    if ((self->data_written + n) > self->buffer_size)
        self->read_cursor = (self->read_cursor + n - (self->buffer_size - self->data_written)) % self->buffer_size;
    while (n)
    {
        unsigned int tocopy = (n > self->buffer_size) ? self->buffer_size : n;
        if ((self->write_cursor + tocopy) < self->buffer_size)
            memcpy((char *)self->buffer + (self->write_cursor * self->data_size), buffer, tocopy * self->data_size);
        else
        {
            unsigned int sub_buffer_size = (self->buffer_size - self->write_cursor) * self->data_size;
            memcpy(((char *)self->buffer) + (self->write_cursor * self->data_size), buffer, sub_buffer_size);
            memcpy(self->buffer, (char *)buffer + sub_buffer_size, (tocopy * self->data_size) - sub_buffer_size);
        }
        self->write_cursor = (self->write_cursor + tocopy) % self->buffer_size;
        self->data_written += tocopy;
    }
    if (self->data_written > self->buffer_size)
        self->data_written = self->buffer_size;
    return (n);
}

variable_types:
tocopy
unsigned int


decompiled_code:
void __fastcall circular_buffer_delete(void **a1)
{
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func4(void **a1)
{
free(*a1);
*a1 = 0LL;
}

original_code:
void circular_buffer_delete(t_circular_buffer *self)
{
    free(self->buffer);
    self->buffer = ((void *)0);
}

canonical_original_code:
void circular_buffer_delete(struct s_circular_buffer *self)
{
    free(self->buffer);
    self->buffer = ((void *)0);
}


original_code:
void ay_3_8912_init(t_ay_3_8912 *self)
{
    memset(self, 0, sizeof(t_ay_3_8912));
    self->elapsed_t_states = 0.f;
    self->clock_div_8 = 0x07;
    self->envel_period = 0x000001;
    self->noise_seed = 0x024000;
}

canonical_original_code:
void ay_3_8912_init(struct s_ay_3_8912 *self)
{
    memset(self, 0, sizeof(t_ay_3_8912));
    self->elapsed_t_states = 0.f;
    self->clock_div_8 = 0x07;
    self->envel_period = 0x000001;
    self->noise_seed = 0x024000;
}

variable_types: struct s_ay_3_8912 { unsigned char reg[18]; unsigned char selected_reg; unsigned short analog_out[3]; unsigned char noise_level; unsigned char envel_level; unsigned char tone_level[3]; unsigned short noise_period; unsigned short envel_period; unsigned short tone_period[3]; unsigned char clock_div_8; unsigned char envel_pos; unsigned int noise_seed; float elapsed_t_states; } *


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

result = (unsigned __int8)a1[18];
a1[result] = regMask_3[result] & a2;
if ( a1[13] )
a1[43] = 0;
return result;
}

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

result = (unsigned __int8)a1[18];
a1[result] = regMask_3[result] & a2;
if ( a1[13] )
a1[43] = 0;
return result;
}

original_code:
void ay_3_8912_write(t_ay_3_8912 *self, byte data)
{
    static const byte regMask[] = { 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0x1F, 0xFF, 0x1F, 0x1F, 0x1F, 0xFF, 0xFF, 0x0F, 0xFF, 0xFF, 0x00};
    self->reg[self->selected_reg] = data & regMask[self->selected_reg];
    if (self->reg[13])
        self->envel_pos = 0;
}

canonical_original_code:
void ay_3_8912_write(struct s_ay_3_8912 *self, unsigned char data)
{
    static unsigned char regMask[] = { 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0x1F, 0xFF, 0x1F, 0x1F, 0x1F, 0xFF, 0xFF, 0x0F, 0xFF, 0xFF, 0x00};
    self->reg[self->selected_reg] = data & regMask[self->selected_reg];
    if (self->reg[13])
        self->envel_pos = 0;
}

variable_types:
data
unsigned char

variable_types:
regMask
unsigned char []

user_defined_types: struct s_ay_3_8912 { unsigned char reg[18]; unsigned char selected_reg; unsigned short analog_out[3]; unsigned char noise_level; unsigned char envel_level; unsigned char tone_level[3]; unsigned short noise_period; unsigned short envel_period; unsigned short tone_period[3]; unsigned char clock_div_8; unsigned char envel_pos; unsigned int noise_seed; float elapsed_t_states; }


decompiled_code:
__int64 __fastcall ay_3_8912_read(__int64 a1)
{
return *(unsigned __int8 *)(*(unsigned __int8 *)(a1 + 18) + a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(unsigned __int8 *)(*(unsigned __int8 *)(a1 + 18) + a1);
}

original_code:
byte ay_3_8912_read(t_ay_3_8912 *self)
{
    return (self->reg[self->selected_reg]);
}

canonical_original_code:
unsigned char ay_3_8912_read(struct s_ay_3_8912 *self)
{
    return (self->reg[self->selected_reg]);
}

return_type: unsigned char


decompiled_code:
void __fastcall ay_3_8912_latch_address(__int64 a1, unsigned __int8 a2)
{
if ( a2 <= 0xFu )
*(_BYTE *)(a1 + 18) = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, unsigned __int8 a2)
{
if ( a2 <= 0xFu )
*(_BYTE *)(a1 + 18) = a2;
}

original_code:
void ay_3_8912_latch_address(t_ay_3_8912 *self, byte data)
{
    if ((data & 0x00) == 0x00)
        if (data <= 15)
            self->selected_reg = data;
}

canonical_original_code:
void ay_3_8912_latch_address(struct s_ay_3_8912 *self, unsigned char data)
{
    if ((data & 0x00) == 0x00)
        if (data <= 15)
            self->selected_reg = data;
}


createTask

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

v2 = (char *)malloc(0x84uLL);
*((_DWORD *)v2 + 32) = a1;
return strcpy(v2, a2);
}

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

v2 = (char *)malloc(0x84uLL);
*((_DWORD *)v2 + 32) = a1;
return strcpy(v2, a2);
}

original_code:
TaskP createTask (int priority, char *desc)
{
 TaskP newTask = (TaskP) malloc (sizeof (struct Task));
 newTask->priority = priority;
 strcpy(newTask->description, desc);
 return newTask;
}

canonical_original_code:
struct Task *createTask(int priority, char *desc)
{
 struct Task *newTask = (TaskP) malloc (sizeof (struct Task));
 newTask->priority = priority;
 strcpy(newTask->description, desc);
 return newTask;
}

variable_types: priority int

variable_types:
desc
char *

variable_types: struct Task { char description[128]; int priority; } *


compare

decompiled_code:
__int64 __fastcall compare(__int64 a1, __int64 a2)
{
int v2; // ecx
int v3; // edx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 128);
v3 = *(_DWORD *)(a2 + 128);
result = 0xFFFFFFFFLL;
if ( v2 >= v3 )
result = v2 > v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
int v2; // ecx
int v3; // edx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 128);
v3 = *(_DWORD *)(a2 + 128);
result = 0xFFFFFFFFLL;
if ( v2 >= v3 )
result = v2 > v3;
return result;
}

original_code:
int compare(void * left, void * right)
{
  TaskP l,r;
  l = (TaskP)left;
  r = (TaskP)right;
 if (l->priority < r->priority)
    return -1;
  else if (l->priority > r->priority)
    return 1;
  else
    return 0;
}

canonical_original_code:
int compare(void *left, void *right)
{
  struct Task *l; struct Task *r;
  l = (struct Task *)left;
  r = (struct Task *)right;
 if (l->priority < r->priority)
    return -1;
  else if (l->priority > r->priority)
    return 1;
  else
    return 0;
}

variable_types:
left
void *

variable_types:
right
void *

user_defined_types: struct Task { char description[128]; int priority; }


createDynArr

decompiled_code:
void *__fastcall createDynArr(int a1)
{
void *v1; // rax
void *v2; // rbx

if ( a1 <= 0 )
_assert_fail("cap > 0", "dynamicArray.c", 0x35u, "createDynArr");
v1 = malloc(0x10uLL);
v2 = v1;
if ( !v1 )
_assert_fail("r != 0", "dynamicArray.c", 0x37u, "createDynArr");
initDynArr((__int64)v1, a1);
return v2;
}

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
void *v1; // rax
void *v2; // rbx

if ( a1 <= 0 )
_assert_fail("cap > 0", "dynamicArray.c", 0x35u, "createDynArr");
v1 = malloc(0x10uLL);
v2 = v1;
if ( !v1 )
_assert_fail("r != 0", "dynamicArray.c", 0x37u, "createDynArr");
func0((__int64)v1, a1);
return v2;
}

original_code:
DynArr* createDynArr(int cap)
{
 DynArr *r;
 ((cap > 0) ? (void) (0) : __assert_fail ("cap > 0", "dynamicArray.c", 53, __extension__ __PRETTY_FUNCTION__));
 r = (DynArr *) malloc(sizeof(DynArr));
 ((r != 0) ? (void) (0) : __assert_fail ("r != 0", "dynamicArray.c", 55, __extension__ __PRETTY_FUNCTION__));
 _initDynArr(r,cap);
 return r;
}

canonical_original_code:
struct DynArr *createDynArr(int cap)
{
 struct DynArr *r;
 ((cap > 0) ? (void) (0) : __assert_fail ("cap > 0", "dynamicArray.c", 53, __extension__ __PRETTY_FUNCTION__));
 r = (struct DynArr *) malloc(sizeof(DynArr));
 ((r != 0) ? (void) (0) : __assert_fail ("r != 0", "dynamicArray.c", 55, __extension__ __PRETTY_FUNCTION__));
 _initDynArr(r,cap);
 return r;
}

variable_types: cap int

variable_types: struct DynArr { void **data; int size; int capacity; } *


freeDynArr

decompiled_code:
void __fastcall freeDynArr(__int64 a1)
{
void *v2; // rdi

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x46u, "freeDynArr");
v2 = *(void **)a1;
if ( v2 )
{
free(v2);
*(_QWORD *)a1 = 0LL;
}
*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 12) = 0;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
void *v2; // rdi

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x46u, "freeDynArr");
v2 = *(void **)a1;
if ( v2 )
{
free(v2);
*(_QWORD *)a1 = 0LL;
}
*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 12) = 0;
}

original_code:
void freeDynArr(DynArr *v)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 70, __extension__ __PRETTY_FUNCTION__));
 if(v->data != 0)
 {
  free(v->data);
  v->data = 0;
 }
 v->size = 0;
 v->capacity = 0;
}

canonical_original_code:
void freeDynArr(struct DynArr *v)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 70, __extension__ __PRETTY_FUNCTION__));
 if(v->data != 0)
 {
  free(v->data);
  v->data = 0;
 }
 v->size = 0;
 v->capacity = 0;
}

user_defined_types: struct DynArr { void **data; int size; int capacity; }


deleteDynArr

decompiled_code:
void __fastcall deleteDynArr(void *ptr)
{
if ( !ptr )
_assert_fail("v!= 0", "dynamicArray.c", 0x5Au, "deleteDynArr");
freeDynArr((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( !ptr )
_assert_fail("v!= 0", "dynamicArray.c", 0x5Au, "deleteDynArr");
func2((__int64)ptr);
free(ptr);
}

original_code:
void deleteDynArr(DynArr *v)
{
 ((v!= 0) ? (void) (0) : __assert_fail ("v!= 0", "dynamicArray.c", 90, __extension__ __PRETTY_FUNCTION__));
 freeDynArr(v);
 free(v);
}

canonical_original_code:
void deleteDynArr(struct DynArr *v)
{
 ((v!= 0) ? (void) (0) : __assert_fail ("v!= 0", "dynamicArray.c", 90, __extension__ __PRETTY_FUNCTION__));
 freeDynArr(v);
 free(v);
}


sizeDynArr

decompiled_code:
__int64 __fastcall sizeDynArr(__int64 a1)
{
if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x98u, "sizeDynArr");
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x98u, "sizeDynArr");
return *(unsigned int *)(a1 + 8);
}

original_code:
int sizeDynArr(DynArr *v)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 152, __extension__ __PRETTY_FUNCTION__));
 return v->size;
}

canonical_original_code:
int sizeDynArr(struct DynArr *v)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 152, __extension__ __PRETTY_FUNCTION__));
 return v->size;
}


addDynArr

decompiled_code:
__int64 __fastcall addDynArr(__int64 a1, __int64 a2)
{
int v3; // esi
__int64 result; // rax

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0xA8u, "addDynArr");
v3 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) >= v3 )
dynArrSetCapacity(a1, 2 * v3);
result = *(_QWORD *)a1;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * (int)(*(_DWORD *)(a1 + 8))++) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
int v3; // esi
__int64 result; // rax

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0xA8u, "addDynArr");
v3 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) >= v3 )
func4(a1, 2 * v3);
result = *(_QWORD *)a1;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * (int)(*(_DWORD *)(a1 + 8))++) = a2;
return result;
}

original_code:
void addDynArr(DynArr *v, void * val)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 168, __extension__ __PRETTY_FUNCTION__));
 if(v->size >= v->capacity)
  _dynArrSetCapacity(v, 2 * v->capacity);
 v->data[v->size] = val;
 v->size++;
}

canonical_original_code:
void addDynArr(struct DynArr *v, void *val)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 168, __extension__ __PRETTY_FUNCTION__));
 if(v->size >= v->capacity)
  _dynArrSetCapacity(v, 2 * v->capacity);
 v->data[v->size] = val;
 v->size++;
}

variable_types:
val
void *


getDynArr

decompiled_code:
__int64 __fastcall getDynArr(__int64 a1, int a2)
{
if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0xC0u, "getDynArr");
if ( *(_DWORD *)(a1 + 8) <= a2 )
_assert_fail("pos < v->size", "dynamicArray.c", 0xC1u, "getDynArr");
if ( a2 < 0 )
_assert_fail("pos >= 0", "dynamicArray.c", 0xC2u, "getDynArr");
return *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0xC0u, "getDynArr");
if ( *(_DWORD *)(a1 + 8) <= a2 )
_assert_fail("pos < v->size", "dynamicArray.c", 0xC1u, "getDynArr");
if ( a2 < 0 )
_assert_fail("pos >= 0", "dynamicArray.c", 0xC2u, "getDynArr");
return *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
}

original_code:
void * getDynArr(DynArr *v, int pos)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 192, __extension__ __PRETTY_FUNCTION__));
 ((pos < v->size) ? (void) (0) : __assert_fail ("pos < v->size", "dynamicArray.c", 193, __extension__ __PRETTY_FUNCTION__));
 ((pos >= 0) ? (void) (0) : __assert_fail ("pos >= 0", "dynamicArray.c", 194, __extension__ __PRETTY_FUNCTION__));
 return v->data[pos];
}

canonical_original_code:
void *getDynArr(struct DynArr *v, int pos)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 192, __extension__ __PRETTY_FUNCTION__));
 ((pos < v->size) ? (void) (0) : __assert_fail ("pos < v->size", "dynamicArray.c", 193, __extension__ __PRETTY_FUNCTION__));
 ((pos >= 0) ? (void) (0) : __assert_fail ("pos >= 0", "dynamicArray.c", 194, __extension__ __PRETTY_FUNCTION__));
 return v->data[pos];
}

variable_types: pos int

return_type: void *


putDynArr

decompiled_code:
__int64 __fastcall putDynArr(__int64 *a1, int a2, __int64 a3)
{
__int64 result; // rax

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0xD4u, "putDynArr");
if ( *((_DWORD *)a1 + 2) <= a2 )
_assert_fail("pos < v->size", "dynamicArray.c", 0xD5u, "putDynArr");
if ( a2 < 0 )
_assert_fail("pos >= 0", "dynamicArray.c", 0xD6u, "putDynArr");
result = *a1;
*(_QWORD *)(*a1 + 8LL * a2) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, int a2, __int64 a3)
{
__int64 result; // rax

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0xD4u, "putDynArr");
if ( *((_DWORD *)a1 + 2) <= a2 )
_assert_fail("pos < v->size", "dynamicArray.c", 0xD5u, "putDynArr");
if ( a2 < 0 )
_assert_fail("pos >= 0", "dynamicArray.c", 0xD6u, "putDynArr");
result = *a1;
*(_QWORD *)(*a1 + 8LL * a2) = a3;
return result;
}

original_code:
void putDynArr(DynArr *v, int pos, void * val)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 212, __extension__ __PRETTY_FUNCTION__));
 ((pos < v->size) ? (void) (0) : __assert_fail ("pos < v->size", "dynamicArray.c", 213, __extension__ __PRETTY_FUNCTION__));
 ((pos >= 0) ? (void) (0) : __assert_fail ("pos >= 0", "dynamicArray.c", 214, __extension__ __PRETTY_FUNCTION__));
 v->data[pos] = val;
}

canonical_original_code:
void putDynArr(struct DynArr *v, int pos, void *val)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 212, __extension__ __PRETTY_FUNCTION__));
 ((pos < v->size) ? (void) (0) : __assert_fail ("pos < v->size", "dynamicArray.c", 213, __extension__ __PRETTY_FUNCTION__));
 ((pos >= 0) ? (void) (0) : __assert_fail ("pos >= 0", "dynamicArray.c", 214, __extension__ __PRETTY_FUNCTION__));
 v->data[pos] = val;
}


swapDynArr

decompiled_code:
__int64 __fastcall swapDynArr(__int64 *a1, int a2, int a3)
{
int v3; // eax
__int64 *v4; // rax
__int64 v5; // rsi
__int64 result; // rax

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0xE6u, "swapDynArr");
v3 = *((_DWORD *)a1 + 2);
if ( v3 <= a2 )
_assert_fail("i < v->size", "dynamicArray.c", 0xE7u, "swapDynArr");
if ( v3 <= a3 )
_assert_fail("j < v->size", "dynamicArray.c", 0xE8u, "swapDynArr");
if ( a2 < 0 )
_assert_fail("i >= 0", "dynamicArray.c", 0xE9u, "swapDynArr");
if ( a3 < 0 )
_assert_fail("j >= 0", "dynamicArray.c", 0xEAu, "swapDynArr");
v4 = (__int64 *)(*a1 + 8LL * a2);
v5 = *v4;
*v4 = *(_QWORD *)(*a1 + 8LL * a3);
result = *a1;
*(_QWORD *)(*a1 + 8LL * a3) = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, int a2, int a3)
{
int v3; // eax
__int64 *v4; // rax
__int64 v5; // rsi
__int64 result; // rax

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0xE6u, "swapDynArr");
v3 = *((_DWORD *)a1 + 2);
if ( v3 <= a2 )
_assert_fail("i < v->size", "dynamicArray.c", 0xE7u, "swapDynArr");
if ( v3 <= a3 )
_assert_fail("j < v->size", "dynamicArray.c", 0xE8u, "swapDynArr");
if ( a2 < 0 )
_assert_fail("i >= 0", "dynamicArray.c", 0xE9u, "swapDynArr");
if ( a3 < 0 )
_assert_fail("j >= 0", "dynamicArray.c", 0xEAu, "swapDynArr");
v4 = (__int64 *)(*a1 + 8LL * a2);
v5 = *v4;
*v4 = *(_QWORD *)(*a1 + 8LL * a3);
result = *a1;
*(_QWORD *)(*a1 + 8LL * a3) = v5;
return result;
}

original_code:
void swapDynArr(DynArr *v, int i, int j)
{
 void * temp;
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 230, __extension__ __PRETTY_FUNCTION__));
 ((i < v->size) ? (void) (0) : __assert_fail ("i < v->size", "dynamicArray.c", 231, __extension__ __PRETTY_FUNCTION__));
 ((j < v->size) ? (void) (0) : __assert_fail ("j < v->size", "dynamicArray.c", 232, __extension__ __PRETTY_FUNCTION__));
 ((i >= 0) ? (void) (0) : __assert_fail ("i >= 0", "dynamicArray.c", 233, __extension__ __PRETTY_FUNCTION__));
 ((j >= 0) ? (void) (0) : __assert_fail ("j >= 0", "dynamicArray.c", 234, __extension__ __PRETTY_FUNCTION__));
 temp = v->data[i];
 v->data[i] = v->data[j];
 v->data[j] = temp;
}

canonical_original_code:
void swapDynArr(struct DynArr *v, int i, int j)
{
 void *temp;
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 230, __extension__ __PRETTY_FUNCTION__));
 ((i < v->size) ? (void) (0) : __assert_fail ("i < v->size", "dynamicArray.c", 231, __extension__ __PRETTY_FUNCTION__));
 ((j < v->size) ? (void) (0) : __assert_fail ("j < v->size", "dynamicArray.c", 232, __extension__ __PRETTY_FUNCTION__));
 ((i >= 0) ? (void) (0) : __assert_fail ("i >= 0", "dynamicArray.c", 233, __extension__ __PRETTY_FUNCTION__));
 ((j >= 0) ? (void) (0) : __assert_fail ("j >= 0", "dynamicArray.c", 234, __extension__ __PRETTY_FUNCTION__));
 temp = v->data[i];
 v->data[i] = v->data[j];
 v->data[j] = temp;
}

variable_types: i int

variable_types: j int

variable_types:
temp
void *


removeAtDynArr

decompiled_code:
__int64 __fastcall removeAtDynArr(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
__int64 i; // rdx

if ( !a1 )
_assert_fail("v!= 0", "dynamicArray.c", 0xFFu, "removeAtDynArr");
v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= a2 )
_assert_fail("idx < v->size", "dynamicArray.c", 0x100u, "removeAtDynArr");
if ( a2 < 0 )
_assert_fail("idx >= 0", "dynamicArray.c", 0x101u, "removeAtDynArr");
result = (unsigned int)(v2 - 1);
for ( i = 8LL * a2 + 8; (int)result > a2; i += 8LL )
{
*(_QWORD *)(*(_QWORD *)a1 + i - 8) = *(_QWORD *)(*(_QWORD *)a1 + i);
++a2;
result = (unsigned int)(*(_DWORD *)(a1 + 8) - 1);
}
*(_DWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
__int64 i; // rdx

if ( !a1 )
_assert_fail("v!= 0", "dynamicArray.c", 0xFFu, "removeAtDynArr");
v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= a2 )
_assert_fail("idx < v->size", "dynamicArray.c", 0x100u, "removeAtDynArr");
if ( a2 < 0 )
_assert_fail("idx >= 0", "dynamicArray.c", 0x101u, "removeAtDynArr");
result = (unsigned int)(v2 - 1);
for ( i = 8LL * a2 + 8; (int)result > a2; i += 8LL )
{
*(_QWORD *)(*(_QWORD *)a1 + i - 8) = *(_QWORD *)(*(_QWORD *)a1 + i);
++a2;
result = (unsigned int)(*(_DWORD *)(a1 + 8) - 1);
}
*(_DWORD *)(a1 + 8) = result;
return result;
}

original_code:
void removeAtDynArr(DynArr *v, int idx){
 int i;
 ((v!= 0) ? (void) (0) : __assert_fail ("v!= 0", "dynamicArray.c", 255, __extension__ __PRETTY_FUNCTION__));
 ((idx < v->size) ? (void) (0) : __assert_fail ("idx < v->size", "dynamicArray.c", 256, __extension__ __PRETTY_FUNCTION__));
 ((idx >= 0) ? (void) (0) : __assert_fail ("idx >= 0", "dynamicArray.c", 257, __extension__ __PRETTY_FUNCTION__));
   for(i = idx; i < v->size-1; i++){
      v->data[i] = v->data[i+1];
   }
   v->size--;
}

canonical_original_code:
void removeAtDynArr(struct DynArr *v, int idx){
 int i;
 ((v!= 0) ? (void) (0) : __assert_fail ("v!= 0", "dynamicArray.c", 255, __extension__ __PRETTY_FUNCTION__));
 ((idx < v->size) ? (void) (0) : __assert_fail ("idx < v->size", "dynamicArray.c", 256, __extension__ __PRETTY_FUNCTION__));
 ((idx >= 0) ? (void) (0) : __assert_fail ("idx >= 0", "dynamicArray.c", 257, __extension__ __PRETTY_FUNCTION__));
   for(i = idx; i < v->size-1; i++){
      v->data[i] = v->data[i+1];
   }
   v->size--;
}

variable_types: idx int


isEmptyDynArr

decompiled_code:
_BOOL8 __fastcall isEmptyDynArr(__int64 a1)
{
if ( !a1 )
_assert_fail("v!= 0", "dynamicArray.c", 0x11Bu, "isEmptyDynArr");
return *(_DWORD *)(a1 + 8) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1)
{
if ( !a1 )
_assert_fail("v!= 0", "dynamicArray.c", 0x11Bu, "isEmptyDynArr");
return *(_DWORD *)(a1 + 8) == 0;
}

original_code:
int isEmptyDynArr(DynArr *v)
{
 ((v!= 0) ? (void) (0) : __assert_fail ("v!= 0", "dynamicArray.c", 283, __extension__ __PRETTY_FUNCTION__));
 return !(v->size);
}

canonical_original_code:
int isEmptyDynArr(struct DynArr *v)
{
 ((v!= 0) ? (void) (0) : __assert_fail ("v!= 0", "dynamicArray.c", 283, __extension__ __PRETTY_FUNCTION__));
 return !(v->size);
}


pushDynArr

decompiled_code:
__int64 __fastcall pushDynArr(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x13Au, "pushDynArr");
return addDynArr(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x13Au, "pushDynArr");
return func6(a1, a2);
}

original_code:
void pushDynArr(DynArr *v, void * val)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 314, __extension__ __PRETTY_FUNCTION__));
 addDynArr(v, val);
}

canonical_original_code:
void pushDynArr(struct DynArr *v, void *val)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 314, __extension__ __PRETTY_FUNCTION__));
 addDynArr(v, val);
}


topDynArr

decompiled_code:
__int64 __fastcall topDynArr(__int64 a1)
{
if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x147u, "topDynArr");
if ( isEmptyDynArr(a1) )
_assert_fail("!isEmptyDynArr(v)", "dynamicArray.c", 0x148u, "topDynArr");
return *(_QWORD *)(*(_QWORD *)a1 + 8LL * *(int *)(a1 + 8) - 8);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x147u, "topDynArr");
if ( func11(a1) )
_assert_fail("!isEmptyDynArr(v)", "dynamicArray.c", 0x148u, "topDynArr");
return *(_QWORD *)(*(_QWORD *)a1 + 8LL * *(int *)(a1 + 8) - 8);
}

original_code:
void * topDynArr(DynArr *v)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 327, __extension__ __PRETTY_FUNCTION__));
 ((!isEmptyDynArr(v)) ? (void) (0) : __assert_fail ("!isEmptyDynArr(v)", "dynamicArray.c", 328, __extension__ __PRETTY_FUNCTION__));
 return v->data[v->size-1];
}

canonical_original_code:
void *topDynArr(struct DynArr *v)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 327, __extension__ __PRETTY_FUNCTION__));
 ((!isEmptyDynArr(v)) ? (void) (0) : __assert_fail ("!isEmptyDynArr(v)", "dynamicArray.c", 328, __extension__ __PRETTY_FUNCTION__));
 return v->data[v->size-1];
}


popDynArr

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

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x156u, "popDynArr");
result = isEmptyDynArr(a1);
if ( result )
_assert_fail("! isEmptyDynArr(v)", "dynamicArray.c", 0x157u, "popDynArr");
--*(_DWORD *)(a1 + 8);
return result;
}

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

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x156u, "popDynArr");
result = func11(a1);
if ( result )
_assert_fail("! isEmptyDynArr(v)", "dynamicArray.c", 0x157u, "popDynArr");
--*(_DWORD *)(a1 + 8);
return result;
}

original_code:
void popDynArr(DynArr *v)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 342, __extension__ __PRETTY_FUNCTION__));
 ((! isEmptyDynArr(v)) ? (void) (0) : __assert_fail ("! isEmptyDynArr(v)", "dynamicArray.c", 343, __extension__ __PRETTY_FUNCTION__));
 v->size--;
}

canonical_original_code:
void popDynArr(struct DynArr *v)
{
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 342, __extension__ __PRETTY_FUNCTION__));
 ((! isEmptyDynArr(v)) ? (void) (0) : __assert_fail ("! isEmptyDynArr(v)", "dynamicArray.c", 343, __extension__ __PRETTY_FUNCTION__));
 v->size--;
}


containsDynArr

decompiled_code:
_BOOL8 __fastcall containsDynArr(_QWORD *a1, __int64 a2)
{
_BOOL4 v2; // er13
__int64 v3; // rbx
__int64 v4; // rax

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x16Eu, "containsDynArr");
v2 = isEmptyDynArr((__int64)a1);
if ( v2 )
_assert_fail("!isEmptyDynArr(v)", "dynamicArray.c", 0x16Fu, "containsDynArr");
v3 = 0LL;
while ( (int)sizeDynArr((__int64)a1) > (int)v3 )
{
v4 = *(_QWORD *)(*a1 + 8 * v3++);
if ( v4 == a2 )
return 1;
}
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(_QWORD *a1, __int64 a2)
{
_BOOL4 v2; // er13
__int64 v3; // rbx
__int64 v4; // rax

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x16Eu, "containsDynArr");
v2 = func11((__int64)a1);
if ( v2 )
_assert_fail("!isEmptyDynArr(v)", "dynamicArray.c", 0x16Fu, "containsDynArr");
v3 = 0LL;
while ( (int)func5((__int64)a1) > (int)v3 )
{
v4 = *(_QWORD *)(*a1 + 8 * v3++);
if ( v4 == a2 )
return 1;
}
return v2;
}

original_code:
int containsDynArr(DynArr *v, void * val)
{
 int i = 0;
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 366, __extension__ __PRETTY_FUNCTION__));
 ((!isEmptyDynArr(v)) ? (void) (0) : __assert_fail ("!isEmptyDynArr(v)", "dynamicArray.c", 367, __extension__ __PRETTY_FUNCTION__));
 for(i = 0; i < sizeDynArr(v); i++)
      if(((v->data[i]) == (val)) )
         return 1;
      return 0;
}

canonical_original_code:
int containsDynArr(struct DynArr *v, void *val)
{
 int i = 0;
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 366, __extension__ __PRETTY_FUNCTION__));
 ((!isEmptyDynArr(v)) ? (void) (0) : __assert_fail ("!isEmptyDynArr(v)", "dynamicArray.c", 367, __extension__ __PRETTY_FUNCTION__));
 for(i = 0; i < sizeDynArr(v); i++)
      if(((v->data[i]) == (val)) )
         return 1;
      return 0;
}


removeDynArr

decompiled_code:
__int64 __fastcall removeDynArr(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // er13
__int64 result; // rax
__int64 v5; // rax

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x185u, "removeDynArr");
if ( isEmptyDynArr((__int64)a1) )
_assert_fail("!isEmptyDynArr(v)", "dynamicArray.c", 0x186u, "removeDynArr");
if ( !containsDynArr(a1, a2) )
_assert_fail("containsDynArr(v,val)", "dynamicArray.c", 0x187u, "removeDynArr");
v2 = 0LL;
while ( 1 )
{
v3 = v2;
result = sizeDynArr((__int64)a1);
if ( (int)result <= (int)v2 )
break;
v5 = *(_QWORD *)(*a1 + 8 * v2++);
if ( v5 == a2 )
return removeAtDynArr((__int64)a1, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // er13
__int64 result; // rax
__int64 v5; // rax

if ( !a1 )
_assert_fail("v!=0", "dynamicArray.c", 0x185u, "removeDynArr");
if ( func11((__int64)a1) )
_assert_fail("!isEmptyDynArr(v)", "dynamicArray.c", 0x186u, "removeDynArr");
if ( !func15(a1, a2) )
_assert_fail("containsDynArr(v,val)", "dynamicArray.c", 0x187u, "removeDynArr");
v2 = 0LL;
while ( 1 )
{
v3 = v2;
result = func5((__int64)a1);
if ( (int)result <= (int)v2 )
break;
v5 = *(_QWORD *)(*a1 + 8 * v2++);
if ( v5 == a2 )
return func10((__int64)a1, v3);
}
return result;
}

original_code:
void removeDynArr(DynArr *v, void * val)
{
 int i = 0;
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 389, __extension__ __PRETTY_FUNCTION__));
 ((!isEmptyDynArr(v)) ? (void) (0) : __assert_fail ("!isEmptyDynArr(v)", "dynamicArray.c", 390, __extension__ __PRETTY_FUNCTION__));
 ((containsDynArr(v,val)) ? (void) (0) : __assert_fail ("containsDynArr(v,val)", "dynamicArray.c", 391, __extension__ __PRETTY_FUNCTION__));
 for(i = 0; i < sizeDynArr(v); i++)
      if(((v->data[i]) == (val)))
      {
           removeAtDynArr(v,i);
           break;
      }
}

canonical_original_code:
void removeDynArr(struct DynArr *v, void *val)
{
 int i = 0;
 ((v!=0) ? (void) (0) : __assert_fail ("v!=0", "dynamicArray.c", 389, __extension__ __PRETTY_FUNCTION__));
 ((!isEmptyDynArr(v)) ? (void) (0) : __assert_fail ("!isEmptyDynArr(v)", "dynamicArray.c", 390, __extension__ __PRETTY_FUNCTION__));
 ((containsDynArr(v,val)) ? (void) (0) : __assert_fail ("containsDynArr(v,val)", "dynamicArray.c", 391, __extension__ __PRETTY_FUNCTION__));
 for(i = 0; i < sizeDynArr(v); i++)
      if(((v->data[i]) == (val)))
      {
           removeAtDynArr(v,i);
           break;
      }
}


copyDynArr

decompiled_code:
void *__fastcall copyDynArr(__int64 a1, __int64 a2)
{
void *result; // rax
int v3; // edx

if ( *(int *)(a1 + 8) <= 0 )
_assert_fail("source->size > 0", "dynamicArray.c", 0x19Du, "copyDynArr");
result = initDynArr(a2, *(_DWORD *)(a1 + 12));
v3 = *(_DWORD *)(a1 + 8);
if ( v3 > 0 )
{
result = 0LL;
do
{
*(_QWORD *)(*(_QWORD *)a2 + 8LL * (_QWORD)result) = *(_QWORD *)(*(_QWORD *)a1 + 8LL * (_QWORD)result);
v3 = *(_DWORD *)(a1 + 8);
result = (char *)result + 1;
}
while ( v3 > (int)result );
}
*(_DWORD *)(a2 + 8) = v3;
return result;
}

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

if ( *(int *)(a1 + 8) <= 0 )
_assert_fail("source->size > 0", "dynamicArray.c", 0x19Du, "copyDynArr");
result = func0(a2, *(_DWORD *)(a1 + 12));
v3 = *(_DWORD *)(a1 + 8);
if ( v3 > 0 )
{
result = 0LL;
do
{
*(_QWORD *)(*(_QWORD *)a2 + 8LL * (_QWORD)result) = *(_QWORD *)(*(_QWORD *)a1 + 8LL * (_QWORD)result);
v3 = *(_DWORD *)(a1 + 8);
result = (char *)result + 1;
}
while ( v3 > (int)result );
}
*(_DWORD *)(a2 + 8) = v3;
return result;
}

original_code:
void copyDynArr(DynArr *source, DynArr *destination)
{
   int i;
 ((source->size > 0) ? (void) (0) : __assert_fail ("source->size > 0", "dynamicArray.c", 413, __extension__ __PRETTY_FUNCTION__));
 _initDynArr(destination, source->capacity);
 for(i = 0; i < source->size; i++)
  destination->data[i] = source->data[i];
 destination->size = source->size;
}

canonical_original_code:
void copyDynArr(struct DynArr *source, struct DynArr *destination)
{
   int i;
 ((source->size > 0) ? (void) (0) : __assert_fail ("source->size > 0", "dynamicArray.c", 413, __extension__ __PRETTY_FUNCTION__));
 _initDynArr(destination, source->capacity);
 for(i = 0; i < source->size; i++)
  destination->data[i] = source->data[i];
 destination->size = source->size;
}

variable_types:
destination
struct DynArr *


getMinHeap

decompiled_code:
__int64 __fastcall getMinHeap(__int64 a1)
{
if ( !a1 )
_assert_fail("heap != NULL", "dynamicArray.c", 0x1C9u, "getMinHeap");
return getDynArr(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
if ( !a1 )
_assert_fail("heap != NULL", "dynamicArray.c", 0x1C9u, "getMinHeap");
return func7(a1, 0);
}

original_code:
void * getMinHeap(DynArr *heap)
{
 ((heap != ((void *)0)) ? (void) (0) : __assert_fail ("heap != NULL", "dynamicArray.c", 457, __extension__ __PRETTY_FUNCTION__));
 return getDynArr(heap, 0);
}

canonical_original_code:
void *getMinHeap(struct DynArr *heap)
{
 ((heap != ((void *)0)) ? (void) (0) : __assert_fail ("heap != NULL", "dynamicArray.c", 457, __extension__ __PRETTY_FUNCTION__));
 return getDynArr(heap, 0);
}


addHeap

decompiled_code:
__int64 __fastcall addHeap(__int64 *a1, __int64 a2)
{
int v2; // ebp
__int64 result; // rax
int v4; // er14
int v5; // ebx
__int64 v6; // r12
__int64 v7; // rax

if ( !a1 )
_assert_fail("heap != NULL", "dynamicArray.c", 0x1D7u, "addHeap");
v2 = sizeDynArr((__int64)a1);
result = addDynArr((__int64)a1, a2);
if ( v2 )
{
do
{
v4 = v2;
v5 = (v2 - 1) / 2;
v2 = v5;
v6 = getDynArr((__int64)a1, v5);
v7 = getDynArr((__int64)a1, v4);
result = compare(v7, v6);
if ( (_DWORD)result != -1 )
break;
result = swapDynArr(a1, v4, v5);
}
while ( v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 *a1, __int64 a2)
{
int v2; // ebp
__int64 result; // rax
int v4; // er14
int v5; // ebx
__int64 v6; // r12
__int64 v7; // rax

if ( !a1 )
_assert_fail("heap != NULL", "dynamicArray.c", 0x1D7u, "addHeap");
v2 = func5((__int64)a1);
result = func6((__int64)a1, a2);
if ( v2 )
{
do
{
v4 = v2;
v5 = (v2 - 1) / 2;
v2 = v5;
v6 = func7((__int64)a1, v5);
v7 = func7((__int64)a1, v4);
result = compare(v7, v6);
if ( (_DWORD)result != -1 )
break;
result = func9(a1, v4, v5);
}
while ( v5 );
}
return result;
}

original_code:
void addHeap(DynArr *heap, void * val)
{
 int parent, cur;
 ((heap != ((void *)0)) ? (void) (0) : __assert_fail ("heap != NULL", "dynamicArray.c", 471, __extension__ __PRETTY_FUNCTION__));
 cur = sizeDynArr(heap);
 addDynArr(heap, val);
 while (cur != 0) {
  parent = ((cur-1)/2);
  if (compare(getDynArr(heap, cur), getDynArr(heap, parent)) == -1) {
   swapDynArr(heap, cur, parent);
   cur = parent;
  }
  else
   return;
 }
}

canonical_original_code:
void addHeap(struct DynArr *heap, void *val)
{
 int parent; int cur;
 ((heap != ((void *)0)) ? (void) (0) : __assert_fail ("heap != NULL", "dynamicArray.c", 471, __extension__ __PRETTY_FUNCTION__));
 cur = sizeDynArr(heap);
 addDynArr(heap, val);
 while (cur != 0) {
  parent = ((cur-1)/2);
  if (compare(getDynArr(heap, cur), getDynArr(heap, parent)) == -1) {
   swapDynArr(heap, cur, parent);
   cur = parent;
  }
  else
   return;
 }
}

variable_types: parent int

variable_types: cur int


removeMinHeap

decompiled_code:
__int64 __fastcall removeMinHeap(__int64 *a1)
{
int v1; // eax
__int64 v2; // rax
int v3; // eax
int v4; // eax

if ( !a1 )
_assert_fail("heap != NULL", "dynamicArray.c", 0x217u, "removeMinHeap");
if ( isEmptyDynArr((__int64)a1) )
_assert_fail("!isEmptyDynArr(heap)", "dynamicArray.c", 0x218u, "removeMinHeap");
v1 = sizeDynArr((__int64)a1);
v2 = getDynArr((__int64)a1, v1 - 1);
putDynArr(a1, 0, v2);
v3 = sizeDynArr((__int64)a1);
removeAtDynArr((__int64)a1, v3 - 1);
v4 = sizeDynArr((__int64)a1);
return adjustHeap(a1, v4 - 1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 *a1)
{
int v1; // eax
__int64 v2; // rax
int v3; // eax
int v4; // eax

if ( !a1 )
_assert_fail("heap != NULL", "dynamicArray.c", 0x217u, "removeMinHeap");
if ( func11((__int64)a1) )
_assert_fail("!isEmptyDynArr(heap)", "dynamicArray.c", 0x218u, "removeMinHeap");
v1 = func5((__int64)a1);
v2 = func7((__int64)a1, v1 - 1);
func8(a1, 0, v2);
v3 = func5((__int64)a1);
func10((__int64)a1, v3 - 1);
v4 = func5((__int64)a1);
return func21(a1, v4 - 1, 0);
}

original_code:
void removeMinHeap(DynArr *heap)
{
 ((heap != ((void *)0)) ? (void) (0) : __assert_fail ("heap != NULL", "dynamicArray.c", 535, __extension__ __PRETTY_FUNCTION__));
 ((!isEmptyDynArr(heap)) ? (void) (0) : __assert_fail ("!isEmptyDynArr(heap)", "dynamicArray.c", 536, __extension__ __PRETTY_FUNCTION__));
 putDynArr(heap, 0, getDynArr(heap, sizeDynArr(heap) - 1));
 removeAtDynArr(heap, sizeDynArr(heap) - 1);
 _adjustHeap(heap, sizeDynArr(heap) - 1, 0);
}

canonical_original_code:
void removeMinHeap(struct DynArr *heap)
{
 ((heap != ((void *)0)) ? (void) (0) : __assert_fail ("heap != NULL", "dynamicArray.c", 535, __extension__ __PRETTY_FUNCTION__));
 ((!isEmptyDynArr(heap)) ? (void) (0) : __assert_fail ("!isEmptyDynArr(heap)", "dynamicArray.c", 536, __extension__ __PRETTY_FUNCTION__));
 putDynArr(heap, 0, getDynArr(heap, sizeDynArr(heap) - 1));
 removeAtDynArr(heap, sizeDynArr(heap) - 1);
 _adjustHeap(heap, sizeDynArr(heap) - 1, 0);
}