daemonize

decompiled_code:
__int64 __fastcall daemonize(int a1)
{
__pid_t v1; // eax
int v2; // ebx
int v4; // ebx
int v5; // ebp
int v6; // eax
__pid_t v7; // eax
__int64 v9; // [rsp+0h] [rbp-18h]

umask(0);
v1 = fork();
if ( v1 < 0 )
goto LABEL_16;
if ( v1 )
goto LABEL_14;
if ( chdir("/") < 0 )
{
perror("chdir()");
exit(1);
}
if ( setsid() < 0 )
{
perror("setsid()");
exit(1);
}
v2 = sysconf(4);
if ( v2 >= 0 )
{
do
{
if ( a1 != v2 )
close(v2);
}
while ( v2-- != 0 );
}
v4 = open("/dev/null", 2);
v5 = dup(v4);
v6 = dup(v4);
if ( v5 != 1 || v4 != 0 || v6 != 2 )
{
syslog(4, "Unexpected file descriptors\n");
exit(2);
}
v7 = fork();
if ( v7 < 0 )
{
LABEL_16:
perror("fork()");
exit(1);
}
if ( v7 )
LABEL_14:
exit(0);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__pid_t v1; // eax
int v2; // ebx
int v4; // ebx
int v5; // ebp
int v6; // eax
__pid_t v7; // eax
__int64 v9; // [rsp+0h] [rbp-18h]

umask(0);
v1 = fork();
if ( v1 < 0 )
goto LABEL_16;
if ( v1 )
goto LABEL_14;
if ( chdir("/") < 0 )
{
perror("chdir()");
exit(1);
}
if ( setsid() < 0 )
{
perror("setsid()");
exit(1);
}
v2 = sysconf(4);
if ( v2 >= 0 )
{
do
{
if ( a1 != v2 )
close(v2);
}
while ( v2-- != 0 );
}
v4 = open("/dev/null", 2);
v5 = dup(v4);
v6 = dup(v4);
if ( v5 != 1 || v4 != 0 || v6 != 2 )
{
syslog(4, "Unexpected file descriptors\n");
exit(2);
}
v7 = fork();
if ( v7 < 0 )
{
LABEL_16:
perror("fork()");
exit(1);
}
if ( v7 )
LABEL_14:
exit(0);
return v9;
}

original_code:
static void
daemonize(int sockfd) {
    int i, fd0, fd1, fd2;
    pid_t pid;
    umask(0);
    if ((pid = fork()) < 0) {
        perror("fork()");
        exit(1);
    } else if (pid != 0) {
        exit(0);
    }
    if (chdir("/") < 0) {
        perror("chdir()");
        exit(1);
    }
    if (setsid() < 0) {
        perror("setsid()");
        exit(1);
    }
    for (i = sysconf(_SC_OPEN_MAX); i >= 0; i--)
        if (i != sockfd)
            close(i);
    fd0 = open("/dev/null", 02);
    fd1 = dup(fd0);
    fd2 = dup(fd0);
    if (fd0 != 0 || fd1 != 1 || fd2 != 2) {
        syslog(4, "Unexpected file descriptors\n");
        exit(2);
    }
    pid = fork();
    if (pid < 0) {
        perror("fork()");
        exit(1);
    } else if (pid > 0) {
        exit(0);
    }
}

canonical_original_code:
static void daemonize(int sockfd) {
    int i; int fd0; int fd1; int fd2;
    int pid;
    umask(0);
    if ((pid = fork()) < 0) {
        perror("fork()");
        exit(1);
    } else if (pid != 0) {
        exit(0);
    }
    if (chdir("/") < 0) {
        perror("chdir()");
        exit(1);
    }
    if (setsid() < 0) {
        perror("setsid()");
        exit(1);
    }
    for (i = sysconf(_SC_OPEN_MAX); i >= 0; i--)
        if (i != sockfd)
            close(i);
    fd0 = open("/dev/null", 02);
    fd1 = dup(fd0);
    fd2 = dup(fd0);
    if (fd0 != 0 || fd1 != 1 || fd2 != 2) {
        syslog(4, "Unexpected file descriptors\n");
        exit(2);
    }
    pid = fork();
    if (pid < 0) {
        perror("fork()");
        exit(1);
    } else if (pid > 0) {
        exit(0);
    }
}

variable_types: sockfd int

variable_types: i int

variable_types: pid int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er13
int v4; // er12
int v5; // eax
fd_set *v6; // rsi
int v7; // eax
int v8; // er13
__int64 v9; // r12
__int64 v10; // rbx
__time_t v11; // rax
int v12; // edi
char *v13; // rax
struct timeval v15; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF
__int64 v17; // [rsp+90h] [rbp-38h] BYREF

v3 = 0;
v4 = 1;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "fi:");
if ( v5 == -1 )
break;
if ( v5 == 102 )
{
v4 = 0;
}
else
{
if ( v5 != 105 )
{
usage();
exit(1);
}
v3 = if_nametoindex(optarg);
}
}
v6 = (fd_set *)(&loc_21 + 1);
openlog("routeradv_listend", 34, 24);
v7 = init_icmp_socket(v3);
v8 = v7;
if ( v7 >= 0 )
{
if ( v4 )
daemonize(v7);
init_routers();
v9 = 1LL << v8;
v10 = v8 >> 6;
do
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v10] |= v9;
v15 = 0LL;
v11 = next_timeout(&v17, v6);
v6 = &readfds;
v15.tv_sec = v11;
if ( select(v8 + 1, &readfds, 0LL, 0LL, &v15) < 0 )
break;
if ( (readfds.fds_bits[v10] & v9) != 0 )
recv_icmp_msg((unsigned int)v8);
handle_routers();
}
v12 = *_errno_location();
}
while ( v12 == 4 );
v13 = strerror(v12);
syslog(2, "select: %s", v13);
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er13
int v4; // er12
int v5; // eax
fd_set *v6; // rsi
int v7; // eax
int v8; // er13
__int64 v9; // r12
__int64 v10; // rbx
__time_t v11; // rax
int v12; // edi
char *v13; // rax
struct timeval v15; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF
__int64 v17; // [rsp+90h] [rbp-38h] BYREF

v3 = 0;
v4 = 1;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "fi:");
if ( v5 == -1 )
break;
if ( v5 == 102 )
{
v4 = 0;
}
else
{
if ( v5 != 105 )
{
func0();
exit(1);
}
v3 = if_nametoindex(optarg);
}
}
v6 = (fd_set *)(&loc_21 + 1);
openlog("routeradv_listend", 34, 24);
v7 = init_icmp_socket(v3);
v8 = v7;
if ( v7 >= 0 )
{
if ( v4 )
func1(v7);
init_routers();
v9 = 1LL << v8;
v10 = v8 >> 6;
do
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v10] |= v9;
v15 = 0LL;
v11 = next_timeout(&v17, v6);
v6 = &readfds;
v15.tv_sec = v11;
if ( select(v8 + 1, &readfds, 0LL, 0LL, &v15) < 0 )
break;
if ( (readfds.fds_bits[v10] & v9) != 0 )
recv_icmp_msg((unsigned int)v8);
handle_routers();
}
v12 = *_errno_location();
}
while ( v12 == 4 );
v13 = strerror(v12);
syslog(2, "select: %s", v13);
}
return 1;
}

original_code:
int
main(int argc, char **argv) {
    int opt, sockfd;
    int background_flag = 1;
    int if_index = 0;
    fd_set rfds;
    struct timeval timeout;
    while ((opt = getopt(argc, argv, "fi:")) != -1) {
        switch (opt) {
            case 'f':
                background_flag = 0;
                break;
            case 'i':
                if_index = if_nametoindex(optarg);
                break;
            default:
                usage();
                exit(1);
        }
    }
    openlog("routeradv_listend", 0x02|0x20, (3<<3));
    sockfd = init_icmp_socket(if_index);
    if (sockfd < 0)
        return 1;
    if (background_flag)
        daemonize(sockfd);
    init_routers();
    for (;;) {
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&rfds)->fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
        memset(&timeout, 0, sizeof(timeout));
        timeout.tv_sec = next_timeout();
        if (select(sockfd + 1, &rfds, ((void *)0), ((void *)0), &timeout) < 0) {
            if ((*__errno_location ()) != 4) {
                syslog(2, "select: %s", strerror((*__errno_location ())));
                return 1;
            }
            continue;
        }
        if (((((&rfds)->fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
            recv_icmp_msg(sockfd);
        handle_routers();
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    int opt; int sockfd;
    int background_flag = 1;
    int if_index = 0;
    struct fd_set rfds;
    struct timeval timeout;
    while ((opt = getopt(argc, argv, "fi:")) != -1) {
        switch (opt) {
            case 'f':
                background_flag = 0;
                break;
            case 'i':
                if_index = if_nametoindex(optarg);
                break;
            default:
                usage();
                exit(1);
        }
    }
    openlog("routeradv_listend", 0x02|0x20, (3<<3));
    sockfd = init_icmp_socket(if_index);
    if (sockfd < 0)
        return 1;
    if (background_flag)
        daemonize(sockfd);
    init_routers();
    for (;;) {
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&rfds)->fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
        memset(&timeout, 0, sizeof(timeout));
        timeout.tv_sec = next_timeout();
        if (select(sockfd + 1, &rfds, ((void *)0), ((void *)0), &timeout) < 0) {
            if ((*__errno_location ()) != 4) {
                syslog(2, "select: %s", strerror((*__errno_location ())));
                return 1;
            }
            continue;
        }
        if (((((&rfds)->fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
            recv_icmp_msg(sockfd);
        handle_routers();
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int

variable_types:
rfds
struct fd_set { long fds_bits[-1]; }

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

return_type: int


decompiled_code:
void __fastcall apply_icmp_filter(int a1)
{
int *v1; // rax
char *v2; // rax
__int128 v3; // [rsp+0h] [rbp-28h] BYREF
__int128 v4; // [rsp+10h] [rbp-18h]

v4 = -1LL;
v3 = -1LL;
LODWORD(v4) = -65;
if ( setsockopt(a1, 58, 1, &v3, 0x20u) )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "setsockopt(): %s", v2);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
int *v1; // rax
char *v2; // rax
__int128 v3; // [rsp+0h] [rbp-28h] BYREF
__int128 v4; // [rsp+10h] [rbp-18h]

v4 = -1LL;
v3 = -1LL;
LODWORD(v4) = -65;
if ( setsockopt(a1, 58, 1, &v3, 0x20u) )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "setsockopt(): %s", v2);
}
}

original_code:
static void
apply_icmp_filter(int sockfd) {
    struct icmp6_filter filter;
    memset(&filter, 0, sizeof(filter));
    memset (&filter, 0xFF, sizeof (struct icmp6_filter));;
    ((((&filter)->icmp6_filt[(134) >> 5]) &= ~(1 << ((134) & 31))));
    if (setsockopt(sockfd, IPPROTO_ICMPV6, 1, &filter, sizeof(filter)) != 0) {
        syslog(2, "setsockopt(): %s", strerror((*__errno_location ())));
        return;
    }
}

variable_types: struct icmp6_filter { unsigned int icmp6_filt[8]; }

return_type: void


decompiled_code:
void __fastcall setup_ancillary_data(int fd)
{
int *v1; // rax
char *v2; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
if ( setsockopt(fd, 1, 29, optval, 4u) )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "setsockopt(): %s", v2);
}
if ( setsockopt(fd, 41, 51, optval, 4u) )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "setsockopt(): %s", v6);
}
if ( setsockopt(fd, 41, 49, optval, 4u) )
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "setsockopt(): %s", v4);
}
}

canonical_decompiled_code:
void __fastcall func1(int fd)
{
int *v1; // rax
char *v2; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
if ( setsockopt(fd, 1, 29, optval, 4u) )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "setsockopt(): %s", v2);
}
if ( setsockopt(fd, 41, 51, optval, 4u) )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "setsockopt(): %s", v6);
}
if ( setsockopt(fd, 41, 49, optval, 4u) )
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "setsockopt(): %s", v4);
}
}

original_code:
static void
setup_ancillary_data(int sockfd) {
    int on = 1;
    if (setsockopt(sockfd, 1, 29, &on, sizeof(on)) != 0)
        syslog(2, "setsockopt(): %s", strerror((*__errno_location ())));
    if (setsockopt(sockfd, IPPROTO_IPV6, 51, &on, sizeof(on)) != 0)
        syslog(2, "setsockopt(): %s", strerror((*__errno_location ())));
    if (setsockopt(sockfd, IPPROTO_IPV6, 49, &on, sizeof(on)) != 0)
        syslog(2, "setsockopt(): %s", strerror((*__errno_location ())));
}

variable_types: on int


decompiled_code:
void __fastcall parse_ancillary_data(__int64 a1, struct msghdr *a2)
{
struct cmsghdr *i; // rsi
__int64 v4; // rax

if ( a2->msg_controllen > 0xF )
{
for ( i = (struct cmsghdr *)a2->msg_control; i; i = _cmsg_nxthdr(a2, i) )
{
while ( 1 )
{
v4 = *(_QWORD *)&i->cmsg_level;
if ( v4 == 0x1D00000001LL )
{
*(__m128i *)(a1 + 56) = _mm_loadu_si128((const __m128i *)i->__cmsg_data);
v4 = *(_QWORD *)&i->cmsg_level;
}
if ( v4 != 0x3400000029LL )
break;
*(_DWORD *)(a1 + 44) = *(_DWORD *)i->__cmsg_data;
i = _cmsg_nxthdr(a2, i);
if ( !i )
return;
}
if ( v4 == 0x3200000029LL )
{
*(_DWORD *)(a1 + 48) = *(_DWORD *)&i->__cmsg_data[16];
*(__m128i *)(a1 + 28) = _mm_loadu_si128((const __m128i *)i->__cmsg_data);
}
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, struct msghdr *a2)
{
struct cmsghdr *i; // rsi
__int64 v4; // rax

if ( a2->msg_controllen > 0xF )
{
for ( i = (struct cmsghdr *)a2->msg_control; i; i = _cmsg_nxthdr(a2, i) )
{
while ( 1 )
{
v4 = *(_QWORD *)&i->cmsg_level;
if ( v4 == 0x1D00000001LL )
{
*(__m128i *)(a1 + 56) = _mm_loadu_si128((const __m128i *)i->__cmsg_data);
v4 = *(_QWORD *)&i->cmsg_level;
}
if ( v4 != 0x3400000029LL )
break;
*(_DWORD *)(a1 + 44) = *(_DWORD *)i->__cmsg_data;
i = _cmsg_nxthdr(a2, i);
if ( !i )
return;
}
if ( v4 == 0x3200000029LL )
{
*(_DWORD *)(a1 + 48) = *(_DWORD *)&i->__cmsg_data[16];
*(__m128i *)(a1 + 28) = _mm_loadu_si128((const __m128i *)i->__cmsg_data);
}
}
}
}

original_code:
static void
parse_ancillary_data(struct RouterAdvertisment *ra, struct msghdr *m) {
    struct cmsghdr *cmsg;
    const struct in6_pktinfo *pktinfo;
    for (cmsg = ((size_t) (m)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (m)->msg_control : (struct cmsghdr *) 0); cmsg != ((void *)0); cmsg = __cmsg_nxthdr (m, cmsg)) {
        if (cmsg->cmsg_level == 1 && cmsg->cmsg_type == 29)
            memcpy(&ra->timestamp, ((cmsg)->__cmsg_data), sizeof(ra->timestamp));
        if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == 52)
            ra->hop_limit = *(int *)((cmsg)->__cmsg_data);
        if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == 50) {
            pktinfo = (const struct in6_pktinfo *)((cmsg)->__cmsg_data);
            ra->if_index = pktinfo->ipi6_ifindex;
            memcpy(&ra->dst_addr, &pktinfo->ipi6_addr, sizeof(ra->dst_addr));
        }
    }
}

canonical_original_code:
static void parse_ancillary_data(struct RouterAdvertisment *ra, struct msghdr *m) {
    struct cmsghdr *cmsg;
    struct in6_pktinfo *pktinfo;
    for (cmsg = ((unsigned long) (m)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (m)->msg_control : (struct cmsghdr *) 0); cmsg != ((void *)0); cmsg = __cmsg_nxthdr (m, cmsg)) {
        if (cmsg->cmsg_level == 1 && cmsg->cmsg_type == 29)
            memcpy(&ra->timestamp, ((cmsg)->__cmsg_data), sizeof(ra->timestamp));
        if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == 52)
            ra->hop_limit = *(int *)((cmsg)->__cmsg_data);
        if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == 50) {
            pktinfo = (struct in6_pktinfo *)((cmsg)->__cmsg_data);
            ra->if_index = pktinfo->ipi6_ifindex;
            memcpy(&ra->dst_addr, &pktinfo->ipi6_addr, sizeof(ra->dst_addr));
        }
    }
}

variable_types: struct RouterAdvertisment { struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } src_addr; struct in6_addr dst_addr; int hop_limit; int if_index; struct timeval { long tv_sec; long tv_usec; } timestamp; int lifetime; int reachable; int retransmit; } *

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; } *

variable_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; } *

variable_types: struct in6_pktinfo { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } ipi6_addr; unsigned int ipi6_ifindex; } *

user_defined_types: struct RouterAdvertisment { struct sockaddr_in6 src_addr; struct in6_addr dst_addr; int hop_limit; int if_index; struct timeval timestamp; int lifetime; int reachable; int retransmit; }

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

user_defined_types: struct in6_pktinfo { struct in6_addr ipi6_addr; unsigned int ipi6_ifindex; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }


decompiled_code:
__int64 __fastcall parse_icmp_data(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int16 v3; // ax
unsigned int v4; // edi
__int64 v5; // r8
int v6; // eax
unsigned int v7; // edi
__int64 v8; // r8
int v9; // eax
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // rdx
unsigned __int64 v13; // r8
__int64 v14; // rdx
unsigned __int64 v15; // rax
__int16 v16; // ax
__int64 result; // rax

if ( a3 <= 0xF )
{
syslog(5, "Did not receive complete ICMP packet");
result = 0xFFFFFFFFLL;
}
else if ( *(_BYTE *)a2 == 0x86 )
{
if ( *(_BYTE *)(a2 + 1) )
{
syslog(5, "Nonzero ICMP code, ignoring");
result = 0xFFFFFFFFLL;
}
else
{
v3 = _bswap_16(*(_WORD *)(a2 + 6));
v4 = *(_DWORD *)(a2 + 8);
*(_DWORD *)(v5 + 72) = v3;
v6 = _bswap_32(v4);
v7 = *(_DWORD *)(a2 + 12);
*(_DWORD *)(v8 + 76) = v6;
v9 = _bswap_32(v7);
*(_DWORD *)(v11 + 80) = v9;
v13 = v12 - 16;
v14 = 16LL;
if ( v13 > 1 )
{
while ( 1 )
{
v16 = *(unsigned __int8 *)(a2 + v14 + 1);
if ( !(_BYTE)v16 )
{
syslog(5, "Invalid length");
return 0xFFFFFFFFLL;
}
v15 = (8 * v16) & 0x7F8;
if ( v15 > v13 )
break;
v14 += v15;
v13 = v10 - v14;
if ( (unsigned __int64)(v10 - v14) <= 1 )
goto LABEL_10;
}
syslog(5, "Did not receive complete ICMP packet option");
result = 0xFFFFFFFFLL;
}
else
{
LABEL_10:
if ( v10 == v14 )
{
result = 0LL;
}
else
{
syslog(5, "%zd trailing bytes", v13);
result = 0xFFFFFFFFLL;
}
}
}
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int16 v3; // ax
unsigned int v4; // edi
__int64 v5; // r8
int v6; // eax
unsigned int v7; // edi
__int64 v8; // r8
int v9; // eax
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // rdx
unsigned __int64 v13; // r8
__int64 v14; // rdx
unsigned __int64 v15; // rax
__int16 v16; // ax
__int64 result; // rax

if ( a3 <= 0xF )
{
syslog(5, "Did not receive complete ICMP packet");
result = 0xFFFFFFFFLL;
}
else if ( *(_BYTE *)a2 == 0x86 )
{
if ( *(_BYTE *)(a2 + 1) )
{
syslog(5, "Nonzero ICMP code, ignoring");
result = 0xFFFFFFFFLL;
}
else
{
v3 = func4(*(_WORD *)(a2 + 6));
v4 = *(_DWORD *)(a2 + 8);
*(_DWORD *)(v5 + 72) = v3;
v6 = func3(v4);
v7 = *(_DWORD *)(a2 + 12);
*(_DWORD *)(v8 + 76) = v6;
v9 = func3(v7);
*(_DWORD *)(v11 + 80) = v9;
v13 = v12 - 16;
v14 = 16LL;
if ( v13 > 1 )
{
while ( 1 )
{
v16 = *(unsigned __int8 *)(a2 + v14 + 1);
if ( !(_BYTE)v16 )
{
syslog(5, "Invalid length");
return 0xFFFFFFFFLL;
}
v15 = (8 * v16) & 0x7F8;
if ( v15 > v13 )
break;
v14 += v15;
v13 = v10 - v14;
if ( (unsigned __int64)(v10 - v14) <= 1 )
goto LABEL_10;
}
syslog(5, "Did not receive complete ICMP packet option");
result = 0xFFFFFFFFLL;
}
else
{
LABEL_10:
if ( v10 == v14 )
{
result = 0LL;
}
else
{
syslog(5, "%zd trailing bytes", v13);
result = 0xFFFFFFFFLL;
}
}
}
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int
parse_icmp_data(struct RouterAdvertisment *adv, const void *pkt, size_t pkt_len) {
    size_t parsed_len = 0;
    if (pkt_len < sizeof(struct nd_router_advert)) {
        syslog(5, "Did not receive complete ICMP packet");
        return -1;
    }
    const struct nd_router_advert *ra = (const struct nd_router_advert *)pkt;
    if (ra->nd_ra_hdr.icmp6_type != 134) {
        return -1;
    }
    if (ra->nd_ra_hdr.icmp6_code != 0) {
        syslog(5, "Nonzero ICMP code,  ignoring");
        return -1;
    }
    adv->lifetime = ntohs(ra->nd_ra_hdr.icmp6_dataun.icmp6_un_data16[1]);
    adv->reachable = ntohl(ra->nd_ra_reachable);
    adv->retransmit = ntohl(ra->nd_ra_retransmit);
    parsed_len = sizeof(struct nd_router_advert);
    while (pkt_len - parsed_len >= sizeof(struct nd_opt_hdr)) {
        const struct nd_opt_hdr *opt = (const struct nd_opt_hdr *)((const char *)ra + parsed_len);
        if (opt->nd_opt_len == 0) {
            syslog(5, "Invalid length");
            return -1;
        }
        if (pkt_len - parsed_len < opt->nd_opt_len * 8) {
            syslog(5, "Did not receive complete ICMP packet option");
            return -1;
        }
        parsed_len += opt->nd_opt_len * 8;
    }
    if (parsed_len != pkt_len) {
        syslog(5, "%zd trailing bytes", pkt_len - parsed_len);
        return -1;
    }
    return 0;
}

canonical_original_code:
static int parse_icmp_data(struct RouterAdvertisment *adv, void *pkt, unsigned long pkt_len) {
    unsigned long parsed_len = 0;
    if (pkt_len < sizeof(struct nd_router_advert)) {
        syslog(5, "Did not receive complete ICMP packet");
        return -1;
    }
    struct nd_router_advert *ra = (const struct nd_router_advert *)pkt;
    if (ra->nd_ra_hdr.icmp6_type != 134) {
        return -1;
    }
    if (ra->nd_ra_hdr.icmp6_code != 0) {
        syslog(5, "Nonzero ICMP code,  ignoring");
        return -1;
    }
    adv->lifetime = ntohs(ra->nd_ra_hdr.icmp6_dataun.icmp6_un_data16[1]);
    adv->reachable = ntohl(ra->nd_ra_reachable);
    adv->retransmit = ntohl(ra->nd_ra_retransmit);
    parsed_len = sizeof(struct nd_router_advert);
    while (pkt_len - parsed_len >= sizeof(struct nd_opt_hdr)) {
        struct nd_opt_hdr *opt = (const struct nd_opt_hdr *)((const char *)ra + parsed_len);
        if (opt->nd_opt_len == 0) {
            syslog(5, "Invalid length");
            return -1;
        }
        if (pkt_len - parsed_len < opt->nd_opt_len * 8) {
            syslog(5, "Did not receive complete ICMP packet option");
            return -1;
        }
        parsed_len += opt->nd_opt_len * 8;
    }
    if (parsed_len != pkt_len) {
        syslog(5, "%zd trailing bytes", pkt_len - parsed_len);
        return -1;
    }
    return 0;
}

variable_types:
pkt
void *

variable_types: struct nd_router_advert { struct icmp6_hdr { unsigned char icmp6_type; unsigned char icmp6_code; unsigned short icmp6_cksum; union { unsigned int icmp6_un_data32[1]; unsigned short icmp6_un_data16[2]; unsigned char icmp6_un_data8[4]; } icmp6_dataun; } nd_ra_hdr; unsigned int nd_ra_reachable; unsigned int nd_ra_retransmit; } *

variable_types: struct nd_opt_hdr { unsigned char nd_opt_type; unsigned char nd_opt_len; } *

user_defined_types: struct nd_router_advert { struct icmp6_hdr nd_ra_hdr; unsigned int nd_ra_reachable; unsigned int nd_ra_retransmit; }

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

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
__int64 __fastcall init_icmp_socket(int a1)
{
int v1; // eax
unsigned int v2; // er12
__int64 result; // rax
int *v4; // rax
char *v5; // rax

v1 = socket(10, 3, 58);
if ( v1 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
syslog(2, "socket(): %s", v5);
result = 1LL;
}
else
{
v2 = v1;
apply_icmp_filter(v1);
selected_if_index = a1;
multicast_listen_constprop_0(v2, a1);
setup_ancillary_data(v2);
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int v1; // eax
unsigned int v2; // er12
__int64 result; // rax
int *v4; // rax
char *v5; // rax

v1 = socket(10, 3, 58);
if ( v1 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
syslog(2, "socket(): %s", v5);
result = 1LL;
}
else
{
v2 = v1;
func0(v1);
selected_if_index = a1;
func6(v2, a1);
func1(v2);
result = v2;
}
return result;
}

original_code:
int
init_icmp_socket(int if_index) {
    int sockfd;
    sockfd = socket(10, SOCK_RAW, IPPROTO_ICMPV6);
    if (sockfd < 0) {
        syslog(2, "socket(): %s", strerror((*__errno_location ())));
        return 1;
    }
    apply_icmp_filter(sockfd);
    selected_if_index = if_index;
    multicast_listen(sockfd, "ff02::1", if_index);
    setup_ancillary_data(sockfd);
    return sockfd;
}

variable_types: sockfd int


decompiled_code:
void __fastcall recv_icmp_msg(int fd)
{
ssize_t v1; // rax
unsigned __int64 v2; // r13
int v3; // eax
int v4; // edx
int *v5; // rax
char *v6; // rax
__int64 v7[2]; // [rsp+0h] [rbp-2C8h] BYREF
struct msghdr message; // [rsp+10h] [rbp-2B8h] BYREF
__int64 v9[12]; // [rsp+50h] [rbp-278h] BYREF
char v10[256]; // [rsp+B0h] [rbp-218h] BYREF
char v11[280]; // [rsp+1B0h] [rbp-118h] BYREF

*(&message.msg_namelen + 1) = 0;
*(_OWORD *)&message.msg_controllen = 0LL;
message.msg_control = v11;
memset(v10, 0, sizeof(v10));
memset(v11, 0, 0x100uLL);
v7[0] = (__int64)v10;
memset(v9, 0, 0x58uLL);
message.msg_name = v9;
message.msg_namelen = 28;
v7[1] = 256LL;
message.msg_iov = (iovec *)v7;
message.msg_iovlen = 1LL;
message.msg_controllen = 256LL;
v1 = recvmsg(fd, &message, 0);
if ( v1 < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "recvmsg(): %s", v6);
}
else
{
v2 = v1;
parse_ancillary_data((__int64)v9, &message);
_bswap_32(0xFFC00000);
v3 = _bswap_32(0xFE800000);
if ( v4 == v3 )
{
if ( HIDWORD(v9[5]) == 255 )
{
if ( selected_if_index <= 0 || selected_if_index == LODWORD(v9[6]) )
{
if ( (unsigned __int16)checksum_constprop_0_isra_0(
LOWORD(v9[1]),
WORD1(v9[1]),
WORD2(v9[1]),
HIWORD(v9[1]),
v9[2],
WORD1(v9[2]),
WORD2(v9[2]),
HIWORD(v9[2]),
WORD2(v9[3]),
HIWORD(v9[3]),
v9[4],
WORD1(v9[4]),
WORD2(v9[4]),
HIWORD(v9[4]),
v9[5],
WORD1(v9[5]),
(__int64)v10,
v2) )
{
syslog(5, "Invalid ICMP checksum, ignoring");
}
else if ( (int)parse_icmp_data((__int64)v9, (__int64)v10, v2) < 0 )
{
syslog(5, "Unable to parse ICMP packet");
}
else
{
update_router(&v9[1], LODWORD(v9[6]), v9[7] + SLODWORD(v9[9]));
}
}
else
{
syslog(4, "Packeted recevied on different interface");
}
}
else
{
syslog(5, "Hop limit is not 255, ignoring");
}
}
else
{
syslog(5, "Not link local, ignoring");
}
}
}

canonical_decompiled_code:
void __fastcall func9(int fd)
{
ssize_t v1; // rax
unsigned __int64 v2; // r13
int v3; // eax
int v4; // edx
int *v5; // rax
char *v6; // rax
__int64 v7[2]; // [rsp+0h] [rbp-2C8h] BYREF
struct msghdr message; // [rsp+10h] [rbp-2B8h] BYREF
__int64 v9[12]; // [rsp+50h] [rbp-278h] BYREF
char v10[256]; // [rsp+B0h] [rbp-218h] BYREF
char v11[280]; // [rsp+1B0h] [rbp-118h] BYREF

*(&message.msg_namelen + 1) = 0;
*(_OWORD *)&message.msg_controllen = 0LL;
message.msg_control = v11;
memset(v10, 0, sizeof(v10));
memset(v11, 0, 0x100uLL);
v7[0] = (__int64)v10;
memset(v9, 0, 0x58uLL);
message.msg_name = v9;
message.msg_namelen = 28;
v7[1] = 256LL;
message.msg_iov = (iovec *)v7;
message.msg_iovlen = 1LL;
message.msg_controllen = 256LL;
v1 = recvmsg(fd, &message, 0);
if ( v1 < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "recvmsg(): %s", v6);
}
else
{
v2 = v1;
func2((__int64)v9, &message);
func3(0xFFC00000);
v3 = func3(0xFE800000);
if ( v4 == v3 )
{
if ( HIDWORD(v9[5]) == 255 )
{
if ( selected_if_index <= 0 || selected_if_index == LODWORD(v9[6]) )
{
if ( (unsigned __int16)func7(
LOWORD(v9[1]),
WORD1(v9[1]),
WORD2(v9[1]),
HIWORD(v9[1]),
v9[2],
WORD1(v9[2]),
WORD2(v9[2]),
HIWORD(v9[2]),
WORD2(v9[3]),
HIWORD(v9[3]),
v9[4],
WORD1(v9[4]),
WORD2(v9[4]),
HIWORD(v9[4]),
v9[5],
WORD1(v9[5]),
(__int64)v10,
v2) )
{
syslog(5, "Invalid ICMP checksum, ignoring");
}
else if ( (int)func5((__int64)v9, (__int64)v10, v2) < 0 )
{
syslog(5, "Unable to parse ICMP packet");
}
else
{
update_router(&v9[1], LODWORD(v9[6]), v9[7] + SLODWORD(v9[9]));
}
}
else
{
syslog(4, "Packeted recevied on different interface");
}
}
else
{
syslog(5, "Hop limit is not 255, ignoring");
}
}
else
{
syslog(5, "Not link local, ignoring");
}
}
}

original_code:
void
recv_icmp_msg(int sockfd) {
    char data_buf[256];
    char control_buf[256];
    struct RouterAdvertisment ra;
    struct msghdr m;
    struct iovec iov;
    ssize_t len;
    memset(data_buf, 0, sizeof(data_buf));
    memset(control_buf, 0, sizeof(control_buf));
    memset(&ra, 0, sizeof(ra));
    memset(&m, 0, sizeof(m));
    memset(&iov, 0, sizeof(iov));
    m.msg_name = &ra.src_addr;
    m.msg_namelen = sizeof(ra.src_addr);
    iov.iov_base = data_buf;
    iov.iov_len = sizeof(data_buf);
    m.msg_iov = &iov;
    m.msg_iovlen = 1;
    m.msg_control = (void *)control_buf;
    m.msg_controllen = sizeof(control_buf);
    m.msg_flags = 0;
    len = recvmsg(sockfd, &m, 0);
    if (len < 0) {
        syslog(2, "recvmsg(): %s", strerror((*__errno_location ())));
        return;
    }
    parse_ancillary_data(&ra, &m);
    if (! (__extension__ ({ const struct in6_addr *__a = (const struct in6_addr *) (&ra.src_addr.sin6_addr); (__a->__in6_u.__u6_addr32[0] & htonl (0xffc00000)) == htonl (0xfe800000); }))) {
        syslog(5, "Not link local, ignoring");
        return;
    }
    if (ra.hop_limit != 255) {
        syslog(5, "Hop limit is not 255, ignoring");
        return;
    }
    if (selected_if_index > 0 && ra.if_index != selected_if_index) {
        syslog(4, "Packeted recevied on different interface");
        return;
    }
    if (checksum(&ra.src_addr.sin6_addr, &ra.dst_addr, IPPROTO_ICMPV6, data_buf, len) != 0) {
        syslog(5, "Invalid ICMP checksum, ignoring");
        return;
    }
    if (parse_icmp_data(&ra, data_buf, len) < 0) {
        syslog(5, "Unable to parse ICMP packet");
        return;
    }
    update_router(&ra.src_addr.sin6_addr, ra.if_index, ra.timestamp.tv_sec + ra.lifetime);
}

canonical_original_code:
void recv_icmp_msg(int sockfd) {
    char data_buf[256];
    char control_buf[256];
    struct RouterAdvertisment ra;
    struct msghdr m;
    struct iovec iov;
    long len;
    memset(data_buf, 0, sizeof(data_buf));
    memset(control_buf, 0, sizeof(control_buf));
    memset(&ra, 0, sizeof(ra));
    memset(&m, 0, sizeof(m));
    memset(&iov, 0, sizeof(iov));
    m.msg_name = &ra.src_addr;
    m.msg_namelen = sizeof(ra.src_addr);
    iov.iov_base = data_buf;
    iov.iov_len = sizeof(data_buf);
    m.msg_iov = &iov;
    m.msg_iovlen = 1;
    m.msg_control = (void *)control_buf;
    m.msg_controllen = sizeof(control_buf);
    m.msg_flags = 0;
    len = recvmsg(sockfd, &m, 0);
    if (len < 0) {
        syslog(2, "recvmsg(): %s", strerror((*__errno_location ())));
        return;
    }
    parse_ancillary_data(&ra, &m);
    if (! (__extension__ ({ struct in6_addr *__a = (const struct in6_addr *) (&ra.src_addr.sin6_addr); (__a->__in6_u.__u6_addr32[0] & htonl (0xffc00000)) == htonl (0xfe800000); }))) {
        syslog(5, "Not link local, ignoring");
        return;
    }
    if (ra.hop_limit != 255) {
        syslog(5, "Hop limit is not 255, ignoring");
        return;
    }
    if (selected_if_index > 0 && ra.if_index != selected_if_index) {
        syslog(4, "Packeted recevied on different interface");
        return;
    }
    if (checksum(&ra.src_addr.sin6_addr, &ra.dst_addr, IPPROTO_ICMPV6, data_buf, len) != 0) {
        syslog(5, "Invalid ICMP checksum, ignoring");
        return;
    }
    if (parse_icmp_data(&ra, data_buf, len) < 0) {
        syslog(5, "Unable to parse ICMP packet");
        return;
    }
    update_router(&ra.src_addr.sin6_addr, ra.if_index, ra.timestamp.tv_sec + ra.lifetime);
}

variable_types: struct RouterAdvertisment { struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } src_addr; struct in6_addr dst_addr; int hop_limit; int if_index; struct timeval { long tv_sec; long tv_usec; } timestamp; int lifetime; int reachable; int retransmit; }

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

variable_types: len long

variable_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } *


decompiled_code:
void __fastcall add_gateway(void *cp, unsigned int ifindex)
{
unsigned int v2; // eax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
char v7[16]; // [rsp+0h] [rbp-148h] BYREF
char buf[48]; // [rsp+10h] [rbp-138h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

if ( inet_ntop(10, cp, buf, 0x2Eu) )
{
if ( if_indextoname(ifindex, v7) )
{
syslog(6, "adding default route via %s", buf);
snprintf(s, 0x100uLL, "/sbin/ip -6 route add ::/0 via %s dev %s", buf, v7);
v2 = system(s);
if ( v2 )
syslog(2, "%s returned %d", s, v2);
}
else
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "if_indextoname: %s", v6);
}
}
else
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "inet_ntop: %s", v4);
}
}

canonical_decompiled_code:
void __fastcall func0(void *cp, unsigned int ifindex)
{
unsigned int v2; // eax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
char v7[16]; // [rsp+0h] [rbp-148h] BYREF
char buf[48]; // [rsp+10h] [rbp-138h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

if ( inet_ntop(10, cp, buf, 0x2Eu) )
{
if ( if_indextoname(ifindex, v7) )
{
syslog(6, "adding default route via %s", buf);
snprintf(s, 0x100uLL, "/sbin/ip -6 route add ::/0 via %s dev %s", buf, v7);
v2 = system(s);
if ( v2 )
syslog(2, "%s returned %d", s, v2);
}
else
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "if_indextoname: %s", v6);
}
}
else
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "inet_ntop: %s", v4);
}
}

original_code:
void add_gateway(const struct in6_addr * addr, int if_index) {
    char cmd_string[256];
    char addr_str[46];
    char if_name[16];
    int ret;
    if (inet_ntop(10, addr, addr_str, sizeof(addr_str)) == ((void *)0)) {
        syslog(2, "inet_ntop: %s", strerror((*__errno_location ())));
        return;
    }
    if (if_indextoname(if_index, if_name) == ((void *)0)) {
        syslog(2, "if_indextoname: %s", strerror((*__errno_location ())));
        return;
    }
    syslog(6, "adding default route via %s", addr_str);
    if (snprintf(cmd_string, sizeof(cmd_string), "/sbin/ip -6 route add ::/0 via %s dev %s", addr_str, if_name) >= (ssize_t)sizeof(cmd_string)) {
        syslog(2, "exceeded command string length");
        return;
    }
    ret = system(cmd_string);
    if (ret != 0) {
        syslog(2, "%s returned %d", cmd_string, ret);
    }
}

canonical_original_code:
void add_gateway(struct in6_addr *addr, int if_index) {
    char cmd_string[256];
    char addr_str[46];
    char if_name[16];
    int ret;
    if (inet_ntop(10, addr, addr_str, sizeof(addr_str)) == ((void *)0)) {
        syslog(2, "inet_ntop: %s", strerror((*__errno_location ())));
        return;
    }
    if (if_indextoname(if_index, if_name) == ((void *)0)) {
        syslog(2, "if_indextoname: %s", strerror((*__errno_location ())));
        return;
    }
    syslog(6, "adding default route via %s", addr_str);
    if (snprintf(cmd_string, sizeof(cmd_string), "/sbin/ip -6 route add ::/0 via %s dev %s", addr_str, if_name) >= (long)sizeof(cmd_string)) {
        syslog(2, "exceeded command string length");
        return;
    }
    ret = system(cmd_string);
    if (ret != 0) {
        syslog(2, "%s returned %d", cmd_string, ret);
    }
}

variable_types: ret int


decompiled_code:
void __fastcall remove_gateway(void *cp, unsigned int ifindex)
{
unsigned int v2; // eax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
char v7[16]; // [rsp+0h] [rbp-148h] BYREF
char buf[48]; // [rsp+10h] [rbp-138h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

if ( inet_ntop(10, cp, buf, 0x2Eu) )
{
if ( if_indextoname(ifindex, v7) )
{
syslog(6, "removing default route via %s", buf);
snprintf(s, 0x100uLL, "/sbin/ip -6 route del ::/0 via %s dev %s", buf, v7);
v2 = system(s);
if ( v2 )
syslog(2, "%s returned %d", s, v2);
}
else
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "if_indextoname: %s", v6);
}
}
else
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "inet_ntop: %s", v4);
}
}

canonical_decompiled_code:
void __fastcall func1(void *cp, unsigned int ifindex)
{
unsigned int v2; // eax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
char v7[16]; // [rsp+0h] [rbp-148h] BYREF
char buf[48]; // [rsp+10h] [rbp-138h] BYREF
char s[264]; // [rsp+40h] [rbp-108h] BYREF

if ( inet_ntop(10, cp, buf, 0x2Eu) )
{
if ( if_indextoname(ifindex, v7) )
{
syslog(6, "removing default route via %s", buf);
snprintf(s, 0x100uLL, "/sbin/ip -6 route del ::/0 via %s dev %s", buf, v7);
v2 = system(s);
if ( v2 )
syslog(2, "%s returned %d", s, v2);
}
else
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "if_indextoname: %s", v6);
}
}
else
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "inet_ntop: %s", v4);
}
}

original_code:
void remove_gateway(const struct in6_addr *addr, int if_index) {
    char cmd_string[256];
    char addr_str[46];
    char if_name[16];
    int ret;
    if (inet_ntop(10, addr, addr_str, sizeof(addr_str)) == ((void *)0)) {
        syslog(2, "inet_ntop: %s", strerror((*__errno_location ())));
        return;
    }
    if (if_indextoname(if_index, if_name) == ((void *)0)) {
        syslog(2, "if_indextoname: %s", strerror((*__errno_location ())));
        return;
    }
    syslog(6, "removing default route via %s", addr_str);
    if (snprintf(cmd_string, sizeof(cmd_string), "/sbin/ip -6 route del ::/0 via %s dev %s", addr_str, if_name) >= (ssize_t)sizeof(cmd_string)) {
        syslog(2, "exceeded command string length");
        return;
    }
    ret = system(cmd_string);
    if (ret != 0) {
        syslog(2, "%s returned %d", cmd_string, ret);
    }
}

canonical_original_code:
void remove_gateway(struct in6_addr *addr, int if_index) {
    char cmd_string[256];
    char addr_str[46];
    char if_name[16];
    int ret;
    if (inet_ntop(10, addr, addr_str, sizeof(addr_str)) == ((void *)0)) {
        syslog(2, "inet_ntop: %s", strerror((*__errno_location ())));
        return;
    }
    if (if_indextoname(if_index, if_name) == ((void *)0)) {
        syslog(2, "if_indextoname: %s", strerror((*__errno_location ())));
        return;
    }
    syslog(6, "removing default route via %s", addr_str);
    if (snprintf(cmd_string, sizeof(cmd_string), "/sbin/ip -6 route del ::/0 via %s dev %s", addr_str, if_name) >= (long)sizeof(cmd_string)) {
        syslog(2, "exceeded command string length");
        return;
    }
    ret = system(cmd_string);
    if (ret != 0) {
        syslog(2, "%s returned %d", cmd_string, ret);
    }
}


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

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

original_code:
static void
print_key (char *k, void* val)
{
   printf("%s\n", k);
}

canonical_original_code:
static void print_key(char *k, void *val)
{
   printf("%s\n", k);
}

variable_types:
k
char *

variable_types:
val
void *


decompiled_code:
unsigned __int8 *__fastcall tst_delete(unsigned __int8 *a1, char *a2)
{
unsigned __int8 *v2; // rbx
char *v3; // rdi
int v4; // esi
unsigned __int8 *result; // rax
char *v6; // rcx
char i; // r8
int v8; // edx
bool v9; // cc
int v10; // edx
_QWORD *v11; // rdi
__int64 v12; // rdx
int v13; // edx
unsigned __int8 *v14; // rdi
unsigned __int8 *v15; // rdi
unsigned __int8 *v16; // [rsp+0h] [rbp-10h]
unsigned __int8 *v17; // [rsp+0h] [rbp-10h]
unsigned __int8 *v18; // [rsp+0h] [rbp-10h]

if ( !a2 )
return 0LL;
v2 = a1;
if ( !a1 )
return 0LL;
v3 = a2;
v4 = *a2;
result = v2;
v6 = v3;
for ( i = v4; ; i = v4 )
{
v8 = *result;
v9 = v4 < v8;
if ( v4 != v8 )
{
do
{
if ( v9 )
{
result = (unsigned __int8 *)*((_QWORD *)result + 1);
if ( !*((_QWORD *)result + 1) )
goto LABEL_13;
}
else
{
result = (unsigned __int8 *)*((_QWORD *)result + 3);
if ( !*((_QWORD *)result + 1) )
{
LABEL_13:
if ( *((_QWORD *)result + 3) )
v2 = result;
goto LABEL_8;
}
}
v2 = result;
LABEL_8:
v10 = *result;
v3 = v6;
v9 = v4 < v10;
}
while ( v4 != v10 );
}
result = (unsigned __int8 *)*((_QWORD *)result + 2);
if ( !i )
break;
if ( !result )
return result;
v4 = *++v6;
}
v13 = *v3;
if ( *v2 == v13 )
{
v11 = (_QWORD *)*((_QWORD *)v2 + 2);
if ( v11 )
{
v12 = v11[3];
v16 = result;
if ( v12 )
{
*((_QWORD *)v2 + 2) = v12;
free(v11);
}
else
{
tst_cleanup_localalias(v11);
*((_QWORD *)v2 + 2) = 0LL;
}
result = v16;
}
return result;
}
v14 = (unsigned __int8 *)*((_QWORD *)v2 + 3);
if ( v14 )
{
if ( v13 == *v14 )
{
LABEL_30:
v17 = result;
tst_cleanup_localalias(v14);
*((_QWORD *)v2 + 3) = 0LL;
return v17;
}
v15 = (unsigned __int8 *)*((_QWORD *)v2 + 1);
if ( !v15 || v13 != *v15 )
goto LABEL_26;
LABEL_33:
v18 = result;
tst_cleanup_localalias(v15);
*((_QWORD *)v2 + 1) = 0LL;
return v18;
}
v15 = (unsigned __int8 *)*((_QWORD *)v2 + 1);
if ( v15 )
{
if ( v13 != *v15 )
return result;
goto LABEL_33;
}
LABEL_26:
v2 = (unsigned __int8 *)*((_QWORD *)v2 + 2);
if ( v2 )
{
if ( !*v2 )
{
v14 = (unsigned __int8 *)*((_QWORD *)v2 + 3);
if ( v14 )
{
if ( v13 == *v14 )
goto LABEL_30;
}
}
}
return result;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func10(unsigned __int8 *a1, char *a2)
{
unsigned __int8 *v2; // rbx
char *v3; // rdi
int v4; // esi
unsigned __int8 *result; // rax
char *v6; // rcx
char i; // r8
int v8; // edx
bool v9; // cc
int v10; // edx
_QWORD *v11; // rdi
__int64 v12; // rdx
int v13; // edx
unsigned __int8 *v14; // rdi
unsigned __int8 *v15; // rdi
unsigned __int8 *v16; // [rsp+0h] [rbp-10h]
unsigned __int8 *v17; // [rsp+0h] [rbp-10h]
unsigned __int8 *v18; // [rsp+0h] [rbp-10h]

if ( !a2 )
return 0LL;
v2 = a1;
if ( !a1 )
return 0LL;
v3 = a2;
v4 = *a2;
result = v2;
v6 = v3;
for ( i = v4; ; i = v4 )
{
v8 = *result;
v9 = v4 < v8;
if ( v4 != v8 )
{
do
{
if ( v9 )
{
result = (unsigned __int8 *)*((_QWORD *)result + 1);
if ( !*((_QWORD *)result + 1) )
goto LABEL_13;
}
else
{
result = (unsigned __int8 *)*((_QWORD *)result + 3);
if ( !*((_QWORD *)result + 1) )
{
LABEL_13:
if ( *((_QWORD *)result + 3) )
v2 = result;
goto LABEL_8;
}
}
v2 = result;
LABEL_8:
v10 = *result;
v3 = v6;
v9 = v4 < v10;
}
while ( v4 != v10 );
}
result = (unsigned __int8 *)*((_QWORD *)result + 2);
if ( !i )
break;
if ( !result )
return result;
v4 = *++v6;
}
v13 = *v3;
if ( *v2 == v13 )
{
v11 = (_QWORD *)*((_QWORD *)v2 + 2);
if ( v11 )
{
v12 = v11[3];
v16 = result;
if ( v12 )
{
*((_QWORD *)v2 + 2) = v12;
free(v11);
}
else
{
func8(v11);
*((_QWORD *)v2 + 2) = 0LL;
}
result = v16;
}
return result;
}
v14 = (unsigned __int8 *)*((_QWORD *)v2 + 3);
if ( v14 )
{
if ( v13 == *v14 )
{
LABEL_30:
v17 = result;
func8(v14);
*((_QWORD *)v2 + 3) = 0LL;
return v17;
}
v15 = (unsigned __int8 *)*((_QWORD *)v2 + 1);
if ( !v15 || v13 != *v15 )
goto LABEL_26;
LABEL_33:
v18 = result;
func8(v15);
*((_QWORD *)v2 + 1) = 0LL;
return v18;
}
v15 = (unsigned __int8 *)*((_QWORD *)v2 + 1);
if ( v15 )
{
if ( v13 != *v15 )
return result;
goto LABEL_33;
}
LABEL_26:
v2 = (unsigned __int8 *)*((_QWORD *)v2 + 2);
if ( v2 )
{
if ( !*v2 )
{
v14 = (unsigned __int8 *)*((_QWORD *)v2 + 3);
if ( v14 )
{
if ( v13 == *v14 )
goto LABEL_30;
}
}
}
return result;
}

original_code:
void * tst_delete(Tptr p, char *s)
{
   Tptr last_p = p;
   void * val= 0;
   char *last_s = s;
   if (!s)
   {
      return ((void *)0);
   }
   while (p)
   {
      if (*s == p->splitchar)
      {
  if (*s++ == 0)
  {
     val = (void*)(p->eqkid);
     break;
  }
  p = p->eqkid;
      }
      else
      {
  last_s = s;
  if (*s < p->splitchar)
     p = p->lokid;
  else
     p = p->hikid;
  if (p->lokid || p->hikid)
  {
     last_p = p;
  }
      }
   }
   if (last_p && p)
   {
      if (last_p->splitchar == *last_s)
      {
  if (last_p->eqkid)
  {
     if (last_p->eqkid->hikid)
     {
        Tptr tt = last_p->eqkid;
        last_p->eqkid = last_p->eqkid->hikid;
        free(tt);
     }
     else
     {
        tst_cleanup(last_p->eqkid);
        last_p->eqkid = ((void *)0);
     }
  }
      }
      else if (last_p->hikid)
      {
  if (last_p->hikid->splitchar == *last_s)
  {
     tst_cleanup(last_p->hikid);
     last_p->hikid = ((void *)0);
  }
  else if ((last_p->lokid) && (last_p->lokid->splitchar == *last_s))
  {
     tst_cleanup(last_p->lokid);
     last_p->lokid = ((void *)0);
  }
  else if (last_p->eqkid)
  {
     goto eqkid;
  }
      }
      else if (last_p->lokid)
      {
  if (last_p->lokid->splitchar == *last_s)
  {
     tst_cleanup(last_p->lokid);
     last_p->lokid = ((void *)0);
  }
      }
      else if (last_p->eqkid)
      {
  Tptr tt;
 eqkid:
  tt = last_p->eqkid;
  if (tt->splitchar == 0)
  {
     if (tt->hikid && tt->hikid->splitchar == *last_s)
     {
        tst_cleanup(tt->hikid);
        tt->hikid = ((void *)0);
     }
  }
      }
   }
   return val;
}

canonical_original_code:
void *tst_delete(struct tnode *p, char *s)
{
   struct tnode *last_p = p;
   void *val = 0;
   char *last_s = s;
   if (!s)
   {
      return ((void *)0);
   }
   while (p)
   {
      if (*s == p->splitchar)
      {
  if (*s++ == 0)
  {
     val = (void *)(p->eqkid);
     break;
  }
  p = p->eqkid;
      }
      else
      {
  last_s = s;
  if (*s < p->splitchar)
     p = p->lokid;
  else
     p = p->hikid;
  if (p->lokid || p->hikid)
  {
     last_p = p;
  }
      }
   }
   if (last_p && p)
   {
      if (last_p->splitchar == *last_s)
      {
  if (last_p->eqkid)
  {
     if (last_p->eqkid->hikid)
     {
        struct tnode *tt = last_p->eqkid;
        last_p->eqkid = last_p->eqkid->hikid;
        free(tt);
     }
     else
     {
        tst_cleanup(last_p->eqkid);
        last_p->eqkid = ((void *)0);
     }
  }
      }
      else if (last_p->hikid)
      {
  if (last_p->hikid->splitchar == *last_s)
  {
     tst_cleanup(last_p->hikid);
     last_p->hikid = ((void *)0);
  }
  else if ((last_p->lokid) && (last_p->lokid->splitchar == *last_s))
  {
     tst_cleanup(last_p->lokid);
     last_p->lokid = ((void *)0);
  }
  else if (last_p->eqkid)
  {
     goto eqkid;
  }
      }
      else if (last_p->lokid)
      {
  if (last_p->lokid->splitchar == *last_s)
  {
     tst_cleanup(last_p->lokid);
     last_p->lokid = ((void *)0);
  }
      }
      else if (last_p->eqkid)
      {
  struct tnode *tt;
 eqkid:
  tt = last_p->eqkid;
  if (tt->splitchar == 0)
  {
     if (tt->hikid && tt->hikid->splitchar == *last_s)
     {
        tst_cleanup(tt->hikid);
        tt->hikid = ((void *)0);
     }
  }
      }
   }
   return val;
}

variable_types: struct tnode { unsigned char splitchar; struct tnode *lokid; } *

variable_types:
s
char *

return_type: void *


decompiled_code:
_QWORD *tst_init()
{
return tst_insert_localalias(0LL, 0LL, 0LL);
}

canonical_decompiled_code:
_QWORD *func12()
{
return tst_insert_localalias(0LL, 0LL, 0LL);
}

original_code:
Tptr tst_init()
{
   return tst_insert(0, 0, 0);
}

canonical_original_code:
struct tnode *tst_init()
{
   return tst_insert(0, 0, 0);
}

return_type: struct tnode { unsigned char splitchar; struct tnode *lokid; } *


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

result = 1LL;
if ( !*(_BYTE *)a1 )
{
*(_QWORD *)(a1 + 16) = a2;
result = 0LL;
}
return result;
}

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

result = 1LL;
if ( !*(_BYTE *)a1 )
{
*(_QWORD *)(a1 + 16) = a2;
result = 0LL;
}
return result;
}

original_code:
int tst_attach(Tptr p, void *val)
{
   if (!p->splitchar)
   {
      p->eqkid = (Tptr)val;
      return 0;
   }
   return 1;
}

canonical_original_code:
int tst_attach(struct tnode *p, void *val)
{
   if (!p->splitchar)
   {
      p->eqkid = (struct tnode *)val;
      return 0;
   }
   return 1;
}

user_defined_types: struct tnode { unsigned char splitchar; struct tnode *lokid; }


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

result = 0LL;
if ( !*(_BYTE *)a1 )
result = *(_QWORD *)(a1 + 16);
return result;
}

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

result = 0LL;
if ( !*(_BYTE *)a1 )
result = *(_QWORD *)(a1 + 16);
return result;
}

original_code:
void* tst_retrieve(Tptr p)
{
   if (!p->splitchar)
   {
      return (void*)(p->eqkid);
   }
   else
   {
      return 0;
   }
}

canonical_original_code:
void *tst_retrieve(struct tnode *p)
{
   if (!p->splitchar)
   {
      return (void *)(p->eqkid);
   }
   else
   {
      return 0;
   }
}


decompiled_code:
int __fastcall nrf24_msleep(unsigned int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0x3E8;
v2.tv_nsec = 1000000LL * (a1 % 0x3E8);
return nanosleep(&v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0x3E8;
v2.tv_nsec = 1000000LL * (a1 % 0x3E8);
return nanosleep(&v2, 0LL);
}

original_code:
void nrf24_msleep(const uint32_t milliseconds)
{
 struct timespec req;
 uint32_t sec = milliseconds / 1000;
 uint32_t msec = milliseconds - (sec * 1000);
 req.tv_sec = sec;
 req.tv_nsec = msec * 1000000L;
 nanosleep(&req, (struct timespec *)((void *)0));
}

canonical_original_code:
void nrf24_msleep(unsigned int milliseconds)
{
 struct timespec req;
 unsigned int sec = milliseconds / 1000;
 unsigned int msec = milliseconds - (sec * 1000);
 req.tv_sec = sec;
 req.tv_nsec = msec * 1000000L;
 nanosleep(&req, (struct timespec *)((void *)0));
}

variable_types:
milliseconds
unsigned int

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

variable_types:
sec
unsigned int

variable_types:
msec
unsigned int


decompiled_code:
int __fastcall nrf24_usleep(unsigned int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0xF4240;
v2.tv_nsec = 1000LL * (a1 % 0xF4240);
return nanosleep(&v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0xF4240;
v2.tv_nsec = 1000LL * (a1 % 0xF4240);
return nanosleep(&v2, 0LL);
}

original_code:
void nrf24_usleep(const uint32_t microseconds)
{
 struct timespec req;
 uint32_t sec = microseconds / 1000000;
 uint32_t usec = microseconds - (sec * 1000000);
 req.tv_sec = sec;
 req.tv_nsec = usec * 1000L;
 nanosleep(&req, (struct timespec *)((void *)0));
}

canonical_original_code:
void nrf24_usleep(unsigned int microseconds)
{
 struct timespec req;
 unsigned int sec = microseconds / 1000000;
 unsigned int usec = microseconds - (sec * 1000000);
 req.tv_sec = sec;
 req.tv_nsec = usec * 1000L;
 nanosleep(&req, (struct timespec *)((void *)0));
}

variable_types:
microseconds
unsigned int

variable_types:
usec
unsigned int

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


variable_types:
controller
unsigned int

variable_types:
device
unsigned int

variable_types:
speed
unsigned int

variable_types:
bits
unsigned char

variable_types:
mode
unsigned char

variable_types: fd int

variable_types: result int

variable_types:
devicefile
char [256]


decompiled_code:
__int64 __fastcall nrf24_spi_close(int a1)
{
if ( a1 < 0 )
return 4294967195LL;
close(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
if ( a1 < 0 )
return 4294967195LL;
close(a1);
return 0LL;
}

original_code:
int32_t nrf24_spi_close(const int32_t handle)
{
 if (handle >= 0) {
  close(handle);
  return 0;
 }
 return -101;
}

canonical_original_code:
int nrf24_spi_close(int handle)
{
 if (handle >= 0) {
  close(handle);
  return 0;
 }
 return -101;
}

variable_types: handle int


decompiled_code:
int __fastcall nrf24_spi_transfer(int a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
int result; // eax
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
__int128 v6; // [rsp+10h] [rbp-18h]

v6 = 0LL;
if ( a1 < 0 )
return -101;
if ( !a2 || !a3 )
return -100;
v5[0] = a2;
v5[1] = a3;
LODWORD(v6) = a4;
BYTE11(v6) = 1;
result = ioctl(a1, 0x40206B00uLL, v5);
if ( result <= 0 )
result = -104;
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
int result; // eax
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
__int128 v6; // [rsp+10h] [rbp-18h]

v6 = 0LL;
if ( a1 < 0 )
return -101;
if ( !a2 || !a3 )
return -100;
v5[0] = a2;
v5[1] = a3;
LODWORD(v6) = a4;
BYTE11(v6) = 1;
result = ioctl(a1, 0x40206B00uLL, v5);
if ( result <= 0 )
result = -104;
return result;
}

original_code:
int32_t nrf24_spi_transfer(const int32_t handle, uint8_t *tx, uint8_t *rx, const uint16_t len)
{
 int32_t result = 0;
 struct spi_ioc_transfer tr = {
  .tx_buf = 0,
  .rx_buf = 0,
  .len = 0,
  .delay_usecs = 0,
  .cs_change = 0
 };
 if (handle < 0) {
  return -101;
 }
 if (tx == 0 || rx == 0) {
  return -100;
 }
 tr.tx_buf = (unsigned long)tx;
 tr.rx_buf = (unsigned long)rx;
 tr.len = len;
 tr.delay_usecs = 0;
 tr.cs_change = 1;
 result = ioctl(handle, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char[((((1)*(sizeof (struct spi_ioc_transfer))) < (1 << 14)) ? ((1)*(sizeof (struct spi_ioc_transfer))) : 0)])))) << ((0 +8)+8))), &tr);
 if (result < 1) {
  result = -104;
 }
 return result;
}

canonical_original_code:
int nrf24_spi_transfer(int handle, unsigned char *tx, unsigned char *rx, unsigned short len)
{
 int result = 0;
 struct spi_ioc_transfer tr = {
  .tx_buf = 0,
  .rx_buf = 0,
  .len = 0,
  .delay_usecs = 0,
  .cs_change = 0
 };
 if (handle < 0) {
  return -101;
 }
 if (tx == 0 || rx == 0) {
  return -100;
 }
 tr.tx_buf = (unsigned long)tx;
 tr.rx_buf = (unsigned long)rx;
 tr.len = len;
 tr.delay_usecs = 0;
 tr.cs_change = 1;
 result = ioctl(handle, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char [-1])))) << ((0 +8)+8))), &tr);
 if (result < 1) {
  result = -104;
 }
 return result;
}

variable_types:
tx
unsigned char *

variable_types:
rx
unsigned char *

variable_types:
len
unsigned short

variable_types: struct spi_ioc_transfer { unsigned long long tx_buf; unsigned long long rx_buf; unsigned int len; unsigned int speed_hz; unsigned short delay_usecs; unsigned char bits_per_word; unsigned char cs_change; unsigned char tx_nbits; unsigned char rx_nbits; unsigned short pad; }


decompiled_code:
// attributes: thunk
__int64 __fastcall nrf24_decode_uint8(_BYTE *a1, _BYTE *a2, int a3)
{
return nrf24_decode_int8_localalias(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, _BYTE *a2, int a3)
{
return func0(a1, a2, a3);
}

original_code:
int32_t nrf24_decode_uint8(uint8_t *value, const uint8_t *bytes, const int32_t len)
{
 if (value == 0 || bytes == 0 || len < (int32_t)sizeof(uint8_t)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(uint8_t));
 return (int32_t)sizeof(uint8_t);
}

canonical_original_code:
int nrf24_decode_uint8(unsigned char *value, unsigned char *bytes, int len)
{
 if (value == 0 || bytes == 0 || len < (int)sizeof(unsigned char)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(unsigned char));
 return (int)sizeof(unsigned char);
}

variable_types:
value
unsigned char *

variable_types:
bytes
unsigned char *

variable_types: len int


decompiled_code:
// attributes: thunk
__int64 __fastcall nrf24_decode_uint16(_WORD *a1, _WORD *a2, int a3)
{
return nrf24_decode_int16_localalias(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(_WORD *a1, _WORD *a2, int a3)
{
return func2(a1, a2, a3);
}

original_code:
int32_t nrf24_decode_uint16(uint16_t *value, const uint8_t *bytes, const int32_t len)
{
 if (value == 0 || bytes == 0 || len < (int32_t)sizeof(uint16_t)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(uint16_t));
 return (int32_t)sizeof(uint16_t);
}

canonical_original_code:
int nrf24_decode_uint16(unsigned short *value, unsigned char *bytes, int len)
{
 if (value == 0 || bytes == 0 || len < (int)sizeof(unsigned short)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(unsigned short));
 return (int)sizeof(unsigned short);
}

variable_types:
value
unsigned short *


decompiled_code:
// attributes: thunk
__int64 __fastcall nrf24_decode_uint32(_DWORD *a1, _DWORD *a2, int a3)
{
return nrf24_decode_int32_localalias(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, _DWORD *a2, int a3)
{
return func4(a1, a2, a3);
}

original_code:
int32_t nrf24_decode_uint32(uint32_t *value, const uint8_t *bytes, const int32_t len)
{
 if (value == 0 || bytes == 0 || len < (int32_t)sizeof(uint32_t)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(uint32_t));
 return (int32_t)sizeof(uint32_t);
}

canonical_original_code:
int nrf24_decode_uint32(unsigned int *value, unsigned char *bytes, int len)
{
 if (value == 0 || bytes == 0 || len < (int)sizeof(unsigned int)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(unsigned int));
 return (int)sizeof(unsigned int);
}

variable_types:
value
unsigned int *


decompiled_code:
// attributes: thunk
__int64 __fastcall nrf24_decode_uint64(_QWORD *a1, _QWORD *a2, int a3)
{
return nrf24_decode_int64_localalias(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, _QWORD *a2, int a3)
{
return func6(a1, a2, a3);
}

original_code:
int32_t nrf24_decode_uint64(uint64_t *value, const uint8_t *bytes, const int32_t len)
{
 if (value == 0 || bytes == 0 || len < (int32_t)sizeof(uint64_t)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(uint64_t));
 return (int32_t)sizeof(uint64_t);
}

canonical_original_code:
int nrf24_decode_uint64(unsigned long *value, unsigned char *bytes, int len)
{
 if (value == 0 || bytes == 0 || len < (int)sizeof(unsigned long)) {
  return -100;
 }
 memcpy(value, bytes, sizeof(unsigned long));
 return (int)sizeof(unsigned long);
}

variable_types:
value
unsigned long *


repo: blueooh/CPerl-Chat

decompiled_code:
__int64 __fastcall cp_init_log(const char *a1)
{
log_fd = open(a1, 1090, 420LL);
return (unsigned int)-(log_fd == 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
log_fd = open(a1, 1090, 420LL);
return (unsigned int)-(log_fd == 0);
}

original_code:
int cp_init_log(const char * file)
{
    log_fd = open(file, 02| 02000 | 0100, 0644);
    if(!log_fd) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int cp_init_log(char *file)
{
    log_fd = open(file, 02| 02000 | 0100, 0644);
    if(!log_fd) {
        return -1;
    }
    return 0;
}

variable_types:
file
char *


decompiled_code:
int __fastcall cp_get_log_time(char *s, int a2)
{
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct tm tp; // [rsp+10h] [rbp-58h] BYREF

timer = time(0LL);
localtime_r(&timer, &tp);
return snprintf(
s,
a2,
"[%04d.%02d.%02d %02d:%02d:%02d] ",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec);
}

canonical_decompiled_code:
int __fastcall func1(char *s, int a2)
{
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct tm tp; // [rsp+10h] [rbp-58h] BYREF

timer = time(0LL);
localtime_r(&timer, &tp);
return snprintf(
s,
a2,
"[%04d.%02d.%02d %02d:%02d:%02d] ",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec);
}

original_code:
int cp_get_log_time(char *buf, int size)
{
    int len;
    time_t now;
    struct tm cur_time;
    now = time(((void *)0));
    localtime_r(&now, &cur_time);
    len = snprintf(buf, size, "[%04d.%02d.%02d %02d:%02d:%02d] ",
            cur_time.tm_year+1900, cur_time.tm_mon+1,cur_time.tm_mday,
            cur_time.tm_hour,cur_time.tm_min,cur_time.tm_sec);
    return len;
}

canonical_original_code:
int cp_get_log_time(char *buf, int size)
{
    int len;
    long now;
    struct tm cur_time;
    now = time(((void *)0));
    localtime_r(&now, &cur_time);
    len = snprintf(buf, size, "[%04d.%02d.%02d %02d:%02d:%02d] ",
            cur_time.tm_year+1900, cur_time.tm_mon+1,cur_time.tm_mday,
            cur_time.tm_hour,cur_time.tm_min,cur_time.tm_sec);
    return len;
}

variable_types:
buf
char *

variable_types: size int

variable_types: now long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


decompiled_code:
__int64 cp_log(char *format, ...)
{
char *v1; // r12
int v2; // ebx
size_t v3; // r13
char *v4; // rax
int v5; // eax
int v6; // eax
int v7; // er13
gcc_va_list arg; // [rsp+8h] [rbp-4F0h] BYREF
char buf[1024]; // [rsp+20h] [rbp-4D8h] BYREF

v1 = (char *)malloc(0x400uLL);
if ( !v1 )
{
LABEL_13:
cp_get_log_time(buf, 1024);
BUG();
}
v2 = 1024;
v3 = 1024LL;
while ( 1 )
{
va_start(arg, format);
v5 = vsnprintf(v1, v3, format, arg);
if ( v5 < (unsigned int)v2 )
break;
v2 *= 2;
if ( v5 >= 0 )
v2 = v5 + 1;
v3 = v2;
v4 = (char *)realloc(v1, v2);
if ( !v4 )
{
free(v1);
goto LABEL_13;
}
v1 = v4;
}
v6 = cp_get_log_time(buf, 1024);
if ( v1[7] == 10 )
v7 = v6 + snprintf(&buf[v6], v3, "%s", v1);
else
v7 = v6 + snprintf(&buf[v6], v2 + 1, "%s\n", v1);
write(log_fd, buf, v7);
free(v1);
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 func2(char *format, ...)
{
char *v1; // r12
int v2; // ebx
size_t v3; // r13
char *v4; // rax
int v5; // eax
int v6; // eax
int v7; // er13
gcc_va_list arg; // [rsp+8h] [rbp-4F0h] BYREF
char buf[1024]; // [rsp+20h] [rbp-4D8h] BYREF

v1 = (char *)malloc(0x400uLL);
if ( !v1 )
{
LABEL_13:
func1(buf, 1024);
BUG();
}
v2 = 1024;
v3 = 1024LL;
while ( 1 )
{
va_start(arg, format);
v5 = vsnprintf(v1, v3, format, arg);
if ( v5 < (unsigned int)v2 )
break;
v2 *= 2;
if ( v5 >= 0 )
v2 = v5 + 1;
v3 = v2;
v4 = (char *)realloc(v1, v2);
if ( !v4 )
{
free(v1);
goto LABEL_13;
}
v1 = v4;
}
v6 = func1(buf, 1024);
if ( v1[7] == 10 )
v7 = v6 + snprintf(&buf[v6], v3, "%s", v1);
else
v7 = v6 + snprintf(&buf[v6], v2 + 1, "%s\n", v1);
write(log_fd, buf, v7);
free(v1);
return (unsigned int)v7;
}

original_code:
int cp_log(char *buf, ...)
{
    char log_buf[1024];
    int log_size;
    va_list argptr; int vaa_size, vaa_num; char *vbuffer, *vaa_buffer2; vaa_size = 1024; vbuffer = malloc (vaa_size); if (vbuffer) { while (1) { __builtin_va_start(argptr,buf); vaa_num = vsnprintf (vbuffer, vaa_size, buf, argptr); __builtin_va_end(argptr); if ((vaa_num >= 0) && (vaa_num < vaa_size)) break; vaa_size = (vaa_num >= 0) ? vaa_num + 1 : vaa_size * 2; vaa_buffer2 = realloc (vbuffer, vaa_size); if (!vaa_buffer2) { free (vbuffer); vbuffer = ((void *)0); break; } vbuffer = vaa_buffer2; } };
    log_size = cp_get_log_time(log_buf, sizeof(log_buf));
    int vb_len = sizeof(vbuffer) - 1;
    if(vbuffer[vb_len] == '\n') {
        log_size += snprintf(log_buf + log_size, vaa_size, "%s", vbuffer);
    } else {
        log_size += snprintf(log_buf + log_size, vaa_size + 1, "%s\n", vbuffer);
    }
    write(log_fd, log_buf, log_size);
    free(vbuffer);
    return log_size;
}

canonical_original_code:
int cp_log(char *buf, ...)
{
    char log_buf[1024];
    int log_size;
    __builtin_va_list argptr; int vaa_size; int vaa_num; char *vbuffer; char *vaa_buffer2; vaa_size = 1024; vbuffer = malloc (vaa_size); if (vbuffer) { while (1) { __builtin_va_start(argptr,buf); vaa_num = vsnprintf (vbuffer, vaa_size, buf, argptr); __builtin_va_end(argptr); if ((vaa_num >= 0) && (vaa_num < vaa_size)) break; vaa_size = (vaa_num >= 0) ? vaa_num + 1 : vaa_size * 2; vaa_buffer2 = realloc (vbuffer, vaa_size); if (!vaa_buffer2) { free (vbuffer); vbuffer = ((void *)0); break; } vbuffer = vaa_buffer2; } };
    log_size = cp_get_log_time(log_buf, sizeof(log_buf));
    int vb_len = sizeof(vbuffer) - 1;
    if(vbuffer[vb_len] == '\n') {
        log_size += snprintf(log_buf + log_size, vaa_size, "%s", vbuffer);
    } else {
        log_size += snprintf(log_buf + log_size, vaa_size + 1, "%s\n", vbuffer);
    }
    write(log_fd, log_buf, log_size);
    free(vbuffer);
    return log_size;
}

variable_types:
vbuffer
char *


original_code:
void list_del(struct list_head *entry)
{
    __list_del(entry->prev, entry->next);
    entry->next = ((void *) 0x00100100);
    entry->prev = ((void *) 0x00200200);
}

variable_types: struct list_head { struct list_head *next; } *


empty

repo: bluke/relex

decompiled_code:
_BOOL8 __fastcall empty(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
return a1 == 0;
}

original_code:
int empty(Tree t)
{
 return t == ((void *)0);
}

canonical_original_code:
int empty(struct Tree *t)
{
 return t == ((void *)0);
}

variable_types: struct Tree { enum Type { REGLE=0, UNION=1, OR=2, PLUS=3, ETOILE=4, INTERROGATION=5, CARACTERE=6, ENSEMBLE=7, INTERVALLE=8 } type; char *content; struct Tree *right; struct Tree *left; } *

user_defined_types: struct Tree { enum Type type; char *content; struct Tree *right; struct Tree *left; }


left

decompiled_code:
__int64 __fastcall left(__int64 a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = empty(a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(a1 + 24);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = func0(a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(a1 + 24);
return result;
}

original_code:
Tree left(Tree t)
{
 if(empty(t))
  return ((void *)0);
 else
  return t->left;
}

canonical_original_code:
struct Tree *left(struct Tree *t)
{
 if(empty(t))
  return ((void *)0);
 else
  return t->left;
}

variable_types:
t
struct Tree *

return_type: struct Tree { enum Type { REGLE=0, UNION=1, OR=2, PLUS=3, ETOILE=4, INTERROGATION=5, CARACTERE=6, ENSEMBLE=7, INTERVALLE=8 } type; char *content; struct Tree *right; struct Tree *left; } *


right

decompiled_code:
__int64 __fastcall right(__int64 a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = empty(a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = func0(a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(a1 + 16);
return result;
}

original_code:
Tree right(Tree t)
{
        if(empty(t))
                return ((void *)0);
        else
                return t->right;
}

canonical_original_code:
struct Tree *right(struct Tree *t)
{
        if(empty(t))
                return ((void *)0);
        else
                return t->right;
}

user_defined_types: enum Type { REGLE=0, UNION=1, OR=2, PLUS=3, ETOILE=4, INTERROGATION=5, CARACTERE=6, ENSEMBLE=7, INTERVALLE=8 }


isfinal

decompiled_code:
_BOOL8 __fastcall isfinal(__int64 a1)
{
__int64 v1; // rax
_BOOL8 result; // rax
__int64 v3; // r9
__int64 v4; // rax
__int64 v5; // r9

v1 = left(a1);
result = empty(v1);
if ( result )
{
v4 = right(v3);
result = empty(v4);
if ( result )
result = !empty(v5);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
__int64 v1; // rax
_BOOL8 result; // rax
__int64 v3; // r9
__int64 v4; // rax
__int64 v5; // r9

v1 = func1(a1);
result = func0(v1);
if ( result )
{
v4 = func2(v3);
result = func0(v4);
if ( result )
result = !func0(v5);
}
return result;
}

original_code:
int isfinal(Tree t)
{
 if(empty(left(t))&&empty(right(t))&&!empty(t))
  return 1;
 else
  return 0;
}

canonical_original_code:
int isfinal(struct Tree *t)
{
 if(empty(left(t))&&empty(right(t))&&!empty(t))
  return 1;
 else
  return 0;
}


leaf

decompiled_code:
_BOOL8 __fastcall leaf(__int64 a1)
{
_BOOL4 v1; // er8
_BOOL8 result; // rax
__int64 v3; // rax
__int64 v4; // r9
__int64 v5; // rax

v1 = empty(a1);
result = 0LL;
if ( !v1 )
{
v3 = left(a1);
result = empty(v3);
if ( result )
{
v5 = right(v4);
result = empty(v5);
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
_BOOL4 v1; // er8
_BOOL8 result; // rax
__int64 v3; // rax
__int64 v4; // r9
__int64 v5; // rax

v1 = func0(a1);
result = 0LL;
if ( !v1 )
{
v3 = func1(a1);
result = func0(v3);
if ( result )
{
v5 = func2(v4);
result = func0(v5);
}
}
return result;
}

original_code:
int leaf(Tree t)
{
 if(empty(t))
  return 0;
 else if (empty(left(t))&&empty(right(t)))
  return 1;
 else
  return 0;
}

canonical_original_code:
int leaf(struct Tree *t)
{
 if(empty(t))
  return 0;
 else if (empty(left(t))&&empty(right(t)))
  return 1;
 else
  return 0;
}


type

decompiled_code:
__int64 __fastcall type(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1)
{
return *a1;
}

original_code:
Type type(Tree t)
{
 return t->type;
}

canonical_original_code:
enum Type type(struct Tree *t)
{
 return t->type;
}

return_type: enum Type { REGLE=0, UNION=1, OR=2, PLUS=3, ETOILE=4, INTERROGATION=5, CARACTERE=6, ENSEMBLE=7, INTERVALLE=8 }


content

decompiled_code:
__int64 __fastcall content(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
char* content(Tree t)
{
 return t->content;
}

canonical_original_code:
char *content(struct Tree *t)
{
 return t->content;
}

return_type: char *


show

decompiled_code:
int __fastcall show(__int64 a1)
{
unsigned int v2; // eax

if ( empty(a1) )
return puts("Arbre vide");
v2 = type((unsigned int *)a1);
return printf("Show du noeud de type : %d\ncontent : %s\n\n", v2, *(const char **)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
unsigned int v2; // eax

if ( func0(a1) )
return puts("Arbre vide");
v2 = func5((unsigned int *)a1);
return printf("Show du noeud de type : %d\ncontent : %s\n\n", v2, *(const char **)(a1 + 8));
}

original_code:
void show(Tree t)
{
 if(empty(t))
  printf("Arbre vide\n");
 else
  printf("Show du noeud de type : %d\ncontent : %s\n\n",type(t),t->content);
}

canonical_original_code:
void show(struct Tree *t)
{
 if(empty(t))
  printf("Arbre vide\n");
 else
  printf("Show du noeud de type : %d\ncontent : %s\n\n",type(t),t->content);
}


decompiled_code:
int __fastcall print_type(int *a1)
{
int v1; // eax

v1 = *a1;
if ( !*a1 )
return printf("Regle");
switch ( v1 )
{
case 1:
return printf("Union");
case 2:
return printf("Or");
case 3:
return printf("Plus");
case 4:
return printf("Etoile");
case 6:
return printf("Caractere");
case 7:
return printf("Ensemble");
case 8:
return printf("Intervalle");
case 5:
return putchar(63);
}
return printf("TYpe inconnu");
}

canonical_decompiled_code:
int __fastcall func8(int *a1)
{
int v1; // eax

v1 = *a1;
if ( !*a1 )
return printf("Regle");
switch ( v1 )
{
case 1:
return printf("Union");
case 2:
return printf("Or");
case 3:
return printf("Plus");
case 4:
return printf("Etoile");
case 6:
return printf("Caractere");
case 7:
return printf("Ensemble");
case 8:
return printf("Intervalle");
case 5:
return putchar(63);
}
return printf("TYpe inconnu");
}

original_code:
void print_type(Tree t)
{
 Type ty=t->type;
 if(ty == REGLE)
  printf("Regle");
 else if(ty==UNION)
  printf("Union");
        else if(ty==OR)
         printf("Or");
        else if(ty==PLUS)
  printf("Plus");
        else if(ty==ETOILE)
  printf("Etoile");
        else if(ty==CARACTERE)
  printf("Caractere");
        else if(ty==ENSEMBLE)
  printf("Ensemble");
        else if(ty==INTERVALLE)
  printf("Intervalle");
 else if(ty==INTERROGATION)
  printf("?");
 else
  printf("TYpe inconnu");
}

canonical_original_code:
void print_type(struct Tree *t)
{
 enum Type ty = t->type;
 if(ty == REGLE)
  printf("Regle");
 else if(ty==UNION)
  printf("Union");
        else if(ty==OR)
         printf("Or");
        else if(ty==PLUS)
  printf("Plus");
        else if(ty==ETOILE)
  printf("Etoile");
        else if(ty==CARACTERE)
  printf("Caractere");
        else if(ty==ENSEMBLE)
  printf("Ensemble");
        else if(ty==INTERVALLE)
  printf("Intervalle");
 else if(ty==INTERROGATION)
  printf("?");
 else
  printf("TYpe inconnu");
}

variable_types: enum Type { REGLE=0, UNION=1, OR=2, PLUS=3, ETOILE=4, INTERROGATION=5, CARACTERE=6, ENSEMBLE=7, INTERVALLE=8 }


decompiled_code:
int __fastcall short_show(__int64 a1)
{
putchar(40);
print_type((int *)a1);
printf(") ");
return printf("%s", *(const char **)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
putchar(40);
func8((int *)a1);
printf(") ");
return printf("%s", *(const char **)(a1 + 8));
}

original_code:
void short_show(Tree t)
{
 printf("(");
 print_type(t);
 printf(") ");
 printf("%s",t->content);
}

canonical_original_code:
void short_show(struct Tree *t)
{
 printf("(");
 print_type(t);
 printf(") ");
 printf("%s",t->content);
}


decompiled_code:
int __fastcall print_space(int a1)
{
int result; // eax
int i; // ebx

result = putchar(10);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = putchar(32);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(int a1)
{
int result; // eax
int i; // ebx

result = putchar(10);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = putchar(32);
}
return result;
}

original_code:
void print_space(int k)
{
 printf("\n");
 int i;
 for(i=0;i<k;i++)
  printf(" ");
}

variable_types: k int

variable_types: i int


decompiled_code:
int __fastcall tree_show(__int64 a1, int a2)
{
__int64 v3; // rbp
__int64 v4; // rax
int v5; // edi

v3 = a1;
if ( isfinal(a1) )
return short_show(a1);
while ( !empty(a1) )
{
print_space(a2);
short_show(v3);
print_space(a2);
printf("|- ");
v4 = left(v3);
tree_show(v4, (unsigned int)(a2 + 2));
v5 = a2;
a2 += 2;
print_space(v5);
printf("|- ");
v3 = right(v3);
a1 = v3;
if ( isfinal(v3) )
return short_show(a1);
}
return printf("(Vide)");
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1, int a2)
{
__int64 v3; // rbp
__int64 v4; // rax
int v5; // edi

v3 = a1;
if ( func3(a1) )
return func9(a1);
while ( !func0(a1) )
{
func10(a2);
func9(v3);
func10(a2);
printf("|- ");
v4 = func1(v3);
func11(v4, (unsigned int)(a2 + 2));
v5 = a2;
a2 += 2;
func10(v5);
printf("|- ");
v3 = func2(v3);
a1 = v3;
if ( func3(v3) )
return func9(a1);
}
return printf("(Vide)");
}

original_code:
void tree_show(Tree t, int p)
{
 if(isfinal(t))
 {
  short_show(t);
 }
 else if(!empty(t))
 {
  print_space(p);
  short_show(t);
  print_space(p);
  printf("|- ");
  tree_show(left(t),p+2);
         print_space(p);
  printf("|- ");
  tree_show(right(t),p+2);
 }
 else if(empty(t))
  printf("(Vide)");
}

canonical_original_code:
void tree_show(struct Tree *t, int p)
{
 if(isfinal(t))
 {
  short_show(t);
 }
 else if(!empty(t))
 {
  print_space(p);
  short_show(t);
  print_space(p);
  printf("|- ");
  tree_show(left(t),p+2);
         print_space(p);
  printf("|- ");
  tree_show(right(t),p+2);
 }
 else if(empty(t))
  printf("(Vide)");
}

variable_types: p int


decompiled_code:
void __fastcall attach_left_son(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 24) = a2;
}

original_code:
void attach_left_son(Tree father, Tree son)
{
 father->left=son;
}

canonical_original_code:
void attach_left_son(struct Tree *father, struct Tree *son)
{
 father->left=son;
}

variable_types:
son
struct Tree *


decompiled_code:
void __fastcall attach_right_son(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 16) = a2;
}

original_code:
void attach_right_son(Tree father, Tree son)
{
        father->right=son;
}

canonical_original_code:
void attach_right_son(struct Tree *father, struct Tree *son)
{
        father->right=son;
}


decale

decompiled_code:
size_t __fastcall decale(int a1, const char *a2)
{
size_t i; // rbx
size_t result; // rax

for ( i = a1; ; ++i )
{
result = strlen(a2);
if ( result <= i )
break;
a2[i] = a2[i + 1];
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(int a1, const char *a2)
{
size_t i; // rbx
size_t result; // rax

for ( i = a1; ; ++i )
{
result = strlen(a2);
if ( result <= i )
break;
a2[i] = a2[i + 1];
}
return result;
}

original_code:
void decale(int j, char* t)
{
        int i;
        for(i=j;i<strlen(t);i++)
        {
                t[i]=t[i+1];
        }
}

canonical_original_code:
void decale(int j, char *t)
{
        int i;
        for(i=j;i<strlen(t);i++)
        {
                t[i]=t[i+1];
        }
}

variable_types: j int

variable_types:
t
char *


suppr

decompiled_code:
size_t __fastcall suppr(char a1, const char *a2)
{
size_t v2; // rbx
size_t result; // rax

v2 = 0LL;
result = strlen(a2);
while ( v2 < result )
{
if ( a2[v2] == a1 )
{
decale(v2, a2);
result = strlen(a2);
}
++v2;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(char a1, const char *a2)
{
size_t v2; // rbx
size_t result; // rax

v2 = 0LL;
result = strlen(a2);
while ( v2 < result )
{
if ( a2[v2] == a1 )
{
func0(v2, a2);
result = strlen(a2);
}
++v2;
}
return result;
}

original_code:
void suppr(char c, char* text)
{
 int i;
 for(i=0;i<strlen(text);i++)
 {
  if(text[i]==c)
  {
   decale(i,text);
  }
 }
}

canonical_original_code:
void suppr(char c, char *text)
{
 int i;
 for(i=0;i<strlen(text);i++)
 {
  if(text[i]==c)
  {
   decale(i,text);
  }
 }
}

variable_types: c char

variable_types:
text
char *


test

decompiled_code:
int __fastcall test(const char *a1)
{
suppr(91, a1);
return printf("apres : %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
func1(91, a1);
return printf("apres : %s\n", a1);
}

original_code:
void test(char* t)
{
 suppr('[',t);
 printf("apres : %s\n",t);
}

canonical_original_code:
void test(char *t)
{
 suppr('[',t);
 printf("apres : %s\n",t);
}


decompiled_code:
__int64 __fastcall new_intervalle(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = new(8LL, &unk_213);
new_left_son(v2, 6LL, a1);
new_right_son(v2, 6LL, a2);
puts("Nouvel intervalle cree");
tree_show(v2, 0LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = new(8LL, &unk_213);
new_left_son(v2, 6LL, a1);
new_right_son(v2, 6LL, a2);
puts("Nouvel intervalle cree");
tree_show(v2, 0LL);
return v2;
}

original_code:
Tree new_intervalle(char* begin, char* end)
{
 Tree t = new(INTERVALLE,"");
 new_left_son(t,CARACTERE,begin);
 new_right_son(t,CARACTERE,end);
 printf("Nouvel intervalle cree\n");
 tree_show(t,0);
 return t;
}

canonical_original_code:
struct Tree *new_intervalle(char *begin, char *end)
{
 struct Tree *t = new(INTERVALLE,"");
 new_left_son(t,CARACTERE,begin);
 new_right_son(t,CARACTERE,end);
 printf("Nouvel intervalle cree\n");
 tree_show(t,0);
 return t;
}

variable_types:
begin
char *

variable_types:
end
char *


decompiled_code:
int __fastcall new_family(__int64 a1, __int64 a2, __int64 a3)
{
attach_left_son(a2, a1);
attach_right_son(a2, a3);
return puts("Nouvelle famille cree");
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
attach_left_son(a2, a1);
attach_right_son(a2, a3);
return puts("Nouvelle famille cree");
}

original_code:
void new_family(Tree left, Tree father, Tree right)
{
 attach_left_son(father,left);
 attach_right_son(father, right);
 printf("Nouvelle famille cree\n");
}

canonical_original_code:
void new_family(struct Tree *left, struct Tree *father, struct Tree *right)
{
 attach_left_son(father,left);
 attach_right_son(father, right);
 printf("Nouvelle famille cree\n");
}

variable_types:
father
struct Tree *

variable_types:
right
struct Tree *


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

v3 = new(a3, &unk_213);
attach_left_son(v3, a1);
attach_right_son(v3, a2);
printf("Nouvelle Union cree (");
print_type(v3);
puts(")");
return v3;
}

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

v3 = new(a3, &unk_213);
attach_left_son(v3, a1);
attach_right_son(v3, a2);
printf("Nouvelle Union cree (");
print_type(v3);
puts(")");
return v3;
}

original_code:
Tree new_union(Tree left, Tree right, Type type)
{
 Tree t = new(type,"");
 attach_left_son(t,left);
 attach_right_son(t, right);
 printf("Nouvelle Union cree (");
 print_type(t);
 printf(")\n");
 return t;
}

canonical_original_code:
struct Tree *new_union(struct Tree *left, struct Tree *right, enum Type type)
{
 struct Tree *t = new(type,"");
 attach_left_son(t,left);
 attach_right_son(t, right);
 printf("Nouvelle Union cree (");
 print_type(t);
 printf(")\n");
 return t;
}

variable_types:
left
struct Tree *


decompiled_code:
__int64 __fastcall empile_tree(__int64 a1, unsigned int *a2, unsigned int a3, int a4)
{
__int64 *v7; // rbp
__int64 v8; // rbp
__int64 v10; // r14
__int64 v11; // rdi

printf("Appel de la fonction empile avec cpt_ensemble=%d et begin =%d\n", *a2, (unsigned int)a4);
if ( (int)(*a2 - a4) > 1 )
{
puts("\nW00t");
v8 = new_union(*(_QWORD *)(a1 + 8LL * (int)*a2 - 16), *(_QWORD *)(a1 + 8LL * (int)*a2 - 8), a3);
LODWORD(v10) = *a2 - 3;
if ( a4 <= (int)v10 )
{
v10 = (int)v10;
do
{
v11 = *(_QWORD *)(a1 + 8 * v10--);
v8 = new_union(v11, v8, a3);
}
while ( a4 <= (int)v10 );
}
}
else
{
v7 = (__int64 *)(a1 + 8LL * a4);
if ( a3 == 7 || a3 == 2 )
{
puts("Ensemble ou Or");
v8 = new_union(*v7, 0LL, a3);
}
else
{
puts("Autre");
v8 = *v7;
}
}
*a2 = a4;
printf(aFinDeLEmpilage, (unsigned int)a4, (unsigned int)a4);
tree_show(v8, 0LL);
putchar(10);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int *a2, unsigned int a3, int a4)
{
__int64 *v7; // rbp
__int64 v8; // rbp
__int64 v10; // r14
__int64 v11; // rdi

printf("Appel de la fonction empile avec cpt_ensemble=%d et begin =%d\n", *a2, (unsigned int)a4);
if ( (int)(*a2 - a4) > 1 )
{
puts("\nW00t");
v8 = func2(*(_QWORD *)(a1 + 8LL * (int)*a2 - 16), *(_QWORD *)(a1 + 8LL * (int)*a2 - 8), a3);
LODWORD(v10) = *a2 - 3;
if ( a4 <= (int)v10 )
{
v10 = (int)v10;
do
{
v11 = *(_QWORD *)(a1 + 8 * v10--);
v8 = func2(v11, v8, a3);
}
while ( a4 <= (int)v10 );
}
}
else
{
v7 = (__int64 *)(a1 + 8LL * a4);
if ( a3 == 7 || a3 == 2 )
{
puts("Ensemble ou Or");
v8 = func2(*v7, 0LL, a3);
}
else
{
puts("Autre");
v8 = *v7;
}
}
*a2 = a4;
printf(aFinDeLEmpilage, (unsigned int)a4, (unsigned int)a4);
tree_show(v8, 0LL);
putchar(10);
return v8;
}

original_code:
Tree empile_tree(Tree ensemble_tree[], int* cpt_ensemble, Type type, int begin)
{
 int i;
 Tree tmp;
 printf("Appel de la fonction empile avec cpt_ensemble=%d et begin =%d\n",*cpt_ensemble,begin);
 if(*cpt_ensemble-begin>=2)
 {
  printf("\nW00t\n");
  tmp=new_union(ensemble_tree[*cpt_ensemble-2],ensemble_tree[*cpt_ensemble-1],type);
  for(i=*cpt_ensemble-3;i>=begin;i--)
  {
   tmp=new_union(ensemble_tree[i],tmp,type);
  }
 }
 else
 {
  if(type==ENSEMBLE||type==OR)
  {
   printf("Ensemble ou Or\n");
   tmp=new_union(ensemble_tree[begin],((void *)0),type);
  }
  else
  {
   printf("Autre\n");
   tmp=ensemble_tree[begin];
  }
 }
 *(cpt_ensemble)=begin;
 printf("Fin de l'empilage en cours, on remet cpt_ensemble a jour et on affiche l'abre ainsi créé\ncpt_ensemble=%d et begin=%d\n",*cpt_ensemble,begin);
 tree_show(tmp,0);
 printf("\n");
 return tmp;
}

canonical_original_code:
struct Tree *empile_tree(struct Tree *ensemble_tree[], int *cpt_ensemble, enum Type type, int begin)
{
 int i;
 struct Tree *tmp;
 printf("Appel de la fonction empile avec cpt_ensemble=%d et begin =%d\n",*cpt_ensemble,begin);
 if(*cpt_ensemble-begin>=2)
 {
  printf("\nW00t\n");
  tmp=new_union(ensemble_tree[*cpt_ensemble-2],ensemble_tree[*cpt_ensemble-1],type);
  for(i=*cpt_ensemble-3;i>=begin;i--)
  {
   tmp=new_union(ensemble_tree[i],tmp,type);
  }
 }
 else
 {
  if(type==ENSEMBLE||type==OR)
  {
   printf("Ensemble ou Or\n");
   tmp=new_union(ensemble_tree[begin],((void *)0),type);
  }
  else
  {
   printf("Autre\n");
   tmp=ensemble_tree[begin];
  }
 }
 *(cpt_ensemble)=begin;
 printf("Fin de l'empilage en cours, on remet cpt_ensemble a jour et on affiche l'abre ainsi créé\ncpt_ensemble=%d et begin=%d\n",*cpt_ensemble,begin);
 tree_show(tmp,0);
 printf("\n");
 return tmp;
}

variable_types: begin int


repo: blunderer/cobaye

decompiled_code:
int cobaye_stdout_get_unsafe()
{
return fflush(stdout);
}

canonical_decompiled_code:
int func0()
{
return fflush(stdout);
}

original_code:
void cobaye_stdout_get_unsafe(void)
{
 fflush(stdout);
}

canonical_original_code:
void cobaye_stdout_get_unsafe()
{
 fflush(stdout);
}


decompiled_code:
// attributes: thunk
int cobaye_stdout_put_unsafe()
{
return cobaye_stdout_get_unsafe();
}

canonical_decompiled_code:
int func1()
{
return func0();
}

original_code:
void cobaye_stdout_put_unsafe(void)
{
 fflush(stdout);
}

canonical_original_code:
void cobaye_stdout_put_unsafe()
{
 fflush(stdout);
}


decompiled_code:
__int64 cobaye_printf(char *format, ...)
{
unsigned int v1; // er12
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
pthread_mutex_lock(&print_lock);
v1 = vfprintf(stdout, format, arg);
fflush(stdout);
pthread_mutex_unlock(&print_lock);
return v1;
}

canonical_decompiled_code:
__int64 func2(char *format, ...)
{
unsigned int v1; // er12
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
pthread_mutex_lock(&print_lock);
v1 = vfprintf(stdout, format, arg);
fflush(stdout);
pthread_mutex_unlock(&print_lock);
return v1;
}

original_code:
int cobaye_printf(char *fmt, ...)
{
 int ret = 0;
 va_list list;
 __builtin_va_start(list,fmt);
 pthread_mutex_lock(&print_lock);
 ret = vfprintf(stdout, fmt, list);
 fflush(stdout);
 pthread_mutex_unlock(&print_lock);
 __builtin_va_end(list);
 return ret;
}

canonical_original_code:
int cobaye_printf(char *fmt, ...)
{
 int ret = 0;
 __builtin_va_list list;
 __builtin_va_start(list,fmt);
 pthread_mutex_lock(&print_lock);
 ret = vfprintf(stdout, fmt, list);
 fflush(stdout);
 pthread_mutex_unlock(&print_lock);
 __builtin_va_end(list);
 return ret;
}

variable_types:
fmt
char *

variable_types: ret int


decompiled_code:
__int64 cobaye_scanf(char *format, ...)
{
unsigned int v1; // er12
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
pthread_mutex_lock(&scan_lock);
v1 = vscanf(format, arg);
pthread_mutex_unlock(&scan_lock);
return v1;
}

canonical_decompiled_code:
__int64 func3(char *format, ...)
{
unsigned int v1; // er12
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
pthread_mutex_lock(&scan_lock);
v1 = vscanf(format, arg);
pthread_mutex_unlock(&scan_lock);
return v1;
}

original_code:
int cobaye_scanf(char *fmt, ...)
{
 int ret = 0;
 va_list list;
 __builtin_va_start(list,fmt);
 pthread_mutex_lock(&scan_lock);
 ret = vscanf(fmt, list);
 pthread_mutex_unlock(&scan_lock);
 __builtin_va_end(list);
 return ret;
}

canonical_original_code:
int cobaye_scanf(char *fmt, ...)
{
 int ret = 0;
 __builtin_va_list list;
 __builtin_va_start(list,fmt);
 pthread_mutex_lock(&scan_lock);
 ret = vscanf(fmt, list);
 pthread_mutex_unlock(&scan_lock);
 __builtin_va_end(list);
 return ret;
}


decompiled_code:
int __fastcall cobaye_run_command(char *command)
{
cobaye_printf(">> ");
return system(command);
}

canonical_decompiled_code:
int __fastcall func4(char *command)
{
func2(">> ");
return system(command);
}

original_code:
int cobaye_run_command(const char *command)
{
 cobaye_printf(">> ");
 return system(command);
}

canonical_original_code:
int cobaye_run_command(char *command)
{
 cobaye_printf(">> ");
 return system(command);
}

variable_types:
command
char *


decompiled_code:
__int64 __fastcall cobaye_build_list(__int64 a1)
{
unsigned int v1; // er12
const char **v2; // rbx
const char *v3; // rsi
__int64 v4; // rbp
const char *v5; // rax

v1 = 0;
v2 = (const char **)&cobaye_start_cobaye_list;
do
{
v3 = *v2;
if ( *v2 )
{
if ( a1 )
{
v4 = a1 + 96LL * (int)v1;
*(_DWORD *)v4 = 0;
strcpy((char *)(v4 + 4), v3);
v5 = *v2;
*(_QWORD *)(v4 + 80) = 0LL;
*(_DWORD *)(v4 + 88) = 1;
*(_QWORD *)(v4 + 72) = v5;
}
++v1;
}
++v2;
}
while ( v2 != (const char **)&cobaye_end_cobaye_list );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // er12
const char **v2; // rbx
const char *v3; // rsi
__int64 v4; // rbp
const char *v5; // rax

v1 = 0;
v2 = (const char **)&cobaye_start_cobaye_list;
do
{
v3 = *v2;
if ( *v2 )
{
if ( a1 )
{
v4 = a1 + 96LL * (int)v1;
*(_DWORD *)v4 = 0;
strcpy((char *)(v4 + 4), v3);
v5 = *v2;
*(_QWORD *)(v4 + 80) = 0LL;
*(_DWORD *)(v4 + 88) = 1;
*(_QWORD *)(v4 + 72) = v5;
}
++v1;
}
++v2;
}
while ( v2 != (const char **)&cobaye_end_cobaye_list );
return v1;
}

original_code:
static int cobaye_build_list(struct cobaye_entry *list)
{
 int index = 0;
 struct cobaye_test **ptr = &cobaye_start_cobaye_list;
 do {
  if (*ptr) {
   if (list) {
    list[index].type = cobaye_func;
    strcpy(list[index].name, (*ptr)->name);
    list[index].test = (*ptr);
    list[index].seq = ((void *)0);
    list[index].value = 1;
   }
   index++;
  }
  ptr++;
 } while (ptr != &cobaye_end_cobaye_list);
 return index;
}

variable_types: struct cobaye_entry { enum cobaye_type { cobaye_inval=-1, cobaye_func=0, cobaye_int=1, cobaye_str=2 } type; char name[64]; struct cobaye_test { char name[64]; char descr[256]; int result; int flags; int (*main)(); } *test; struct cobaye_entry *seq; union { int value; char *string; }; } *

variable_types: index int

variable_types: struct cobaye_test { char name[64]; char descr[256]; int result; int flags; int (*main)(); } **

user_defined_types: struct cobaye_entry { enum cobaye_type type; char name[64]; struct cobaye_test *test; struct cobaye_entry *seq; union { int value; char *string; }; }


decompiled_code:
__int64 __fastcall cobaye_test_exist(char *s1)
{
__int64 v1; // r12
__int64 v2; // rbp

if ( !cobaye_count )
return 0LL;
v1 = cobaye_list;
v2 = cobaye_list + 96LL * (unsigned int)(cobaye_count - 1) + 96;
while ( strcmp(s1, (const char *)(v1 + 4)) )
{
v1 += 96LL;
if ( v1 == v2 )
return 0LL;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
__int64 v1; // r12
__int64 v2; // rbp

if ( !cobaye_count )
return 0LL;
v1 = cobaye_list;
v2 = cobaye_list + 96LL * (unsigned int)(cobaye_count - 1) + 96;
while ( strcmp(s1, (const char *)(v1 + 4)) )
{
v1 += 96LL;
if ( v1 == v2 )
return 0LL;
}
return v1;
}

original_code:
struct cobaye_entry *cobaye_test_exist(char *name)
{
 unsigned int i;
 for (i = 0; i < cobaye_count; i++) {
  if (strcmp(name, cobaye_list[i].name) == 0)
   return &cobaye_list[i];
 }
 return ((void *)0);
}

variable_types:
name
char *

variable_types:
i
unsigned int

return_type: struct cobaye_entry { enum cobaye_type { cobaye_inval=-1, cobaye_func=0, cobaye_int=1, cobaye_str=2 } type; char name[64]; struct cobaye_test { char name[64]; char descr[256]; int result; int flags; int (*main)(); } *test; struct cobaye_entry *seq; union { int value; char *string; }; } *