decompiled_code:
__int64 __fastcall read_pkt(__int64 a1, int a2, __int64 a3, unsigned int a4, unsigned int a5)
{
__int64 v6; // rbp
int v8; // eax
unsigned int v9; // edx
__int16 v10; // ax
unsigned int v11; // er13
unsigned __int16 v12; // ax
unsigned __int16 v13; // dx
char src[23]; // [rsp+0h] [rbp-2358h] BYREF
char v16; // [rsp+17h] [rbp-2341h]

v6 = a4;
v8 = read(a2, src, *(unsigned int *)(a1 + 8));
v9 = *(_DWORD *)(a1 + 8);
if ( v9 != v8 )
__assert_fail("rbytes == rh->incl_len", "pcap.c", 0x1Cu, "read_pkt");
v10 = 4 * (src[14] & 0xF);
if ( v16 == 6 )
{
v12 = v10 + 14 + 4 * ((unsigned __int8)src[(unsigned __int16)(v10 + 14) + 12] >> 4);
}
else
{
v11 = 0;
if ( v16 != 17 )
return v11;
v12 = v10 + 22;
}
if ( v9 <= v12 )
return (unsigned int)-1;
v13 = v9 - v12;
if ( (unsigned int)v6 + v13 + 2 >= a5 )
return (unsigned int)-1;
*(_WORD *)(a3 + v6) = v13;
v11 = v13 + 2;
memcpy((void *)(a3 + v6 + 2), &src[v12], v13);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, __int64 a3, unsigned int a4, unsigned int a5)
{
__int64 v6; // rbp
int v8; // eax
unsigned int v9; // edx
__int16 v10; // ax
unsigned int v11; // er13
unsigned __int16 v12; // ax
unsigned __int16 v13; // dx
char src[23]; // [rsp+0h] [rbp-2358h] BYREF
char v16; // [rsp+17h] [rbp-2341h]

v6 = a4;
v8 = read(a2, src, *(unsigned int *)(a1 + 8));
v9 = *(_DWORD *)(a1 + 8);
if ( v9 != v8 )
__assert_fail("rbytes == rh->incl_len", "pcap.c", 0x1Cu, "read_pkt");
v10 = 4 * (src[14] & 0xF);
if ( v16 == 6 )
{
v12 = v10 + 14 + 4 * ((unsigned __int8)src[(unsigned __int16)(v10 + 14) + 12] >> 4);
}
else
{
v11 = 0;
if ( v16 != 17 )
return v11;
v12 = v10 + 22;
}
if ( v9 <= v12 )
return (unsigned int)-1;
v13 = v9 - v12;
if ( (unsigned int)v6 + v13 + 2 >= a5 )
return (unsigned int)-1;
*(_WORD *)(a3 + v6) = v13;
v11 = v13 + 2;
memcpy((void *)(a3 + v6 + 2), &src[v12], v13);
return v11;
}

original_code:
int read_pkt(pcaprec_hdr_t *rh, int fd, uint8_t *data, uint32_t cur, uint32_t max)
{
    uint8_t tmp[9000];
    struct my_ip *iph;
    struct my_udp *uh;
    struct my_tcp *th;
    uint16_t len;
    int rbytes;
    rbytes = read(fd, tmp, rh->incl_len);
    ((void) sizeof ((rbytes == rh->incl_len) ? 1 : 0), __extension__ ({ if (rbytes == rh->incl_len) ; else __assert_fail ("rbytes == rh->incl_len", "pcap.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    uint16_t start = 14;
    iph = (struct my_ip *) (tmp+start);
    start += iph->ip_hl << 2;
    if (iph->ip_p == 6) {
        th = (struct my_tcp *) (tmp + start);
        start += th->th_off << 2;
    } else if (iph->ip_p == 17) {
        uh = (struct my_udp *) (tmp + start);
        start += sizeof(struct my_udp);
    } else {
        return 0;
    }
    if (start >= rh->incl_len) goto err;
    len = rh->incl_len - start;
    if (cur + 2 + len >= max) goto err;
    memcpy(data+cur, &len, sizeof(len));
    memcpy(data+cur+2, tmp+start, len);
    return 2 + len;
err:
    return -1;
}

canonical_original_code:
int read_pkt(struct pcaprec_hdr_s *rh, int fd, unsigned char *data, unsigned int cur, unsigned int max)
{
    unsigned char tmp[9000];
    struct my_ip *iph;
    struct my_udp *uh;
    struct my_tcp *th;
    unsigned short len;
    int rbytes;
    rbytes = read(fd, tmp, rh->incl_len);
    ((void) sizeof ((rbytes == rh->incl_len) ? 1 : 0), __extension__ ({ if (rbytes == rh->incl_len) ; else __assert_fail ("rbytes == rh->incl_len", "pcap.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    unsigned short start = 14;
    iph = (struct my_ip *) (tmp+start);
    start += iph->ip_hl << 2;
    if (iph->ip_p == 6) {
        th = (struct my_tcp *) (tmp + start);
        start += th->th_off << 2;
    } else if (iph->ip_p == 17) {
        uh = (struct my_udp *) (tmp + start);
        start += sizeof(struct my_udp);
    } else {
        return 0;
    }
    if (start >= rh->incl_len) goto err;
    len = rh->incl_len - start;
    if (cur + 2 + len >= max) goto err;
    memcpy(data+cur, &len, sizeof(len));
    memcpy(data+cur+2, tmp+start, len);
    return 2 + len;
err:
    return -1;
}

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

variable_types: fd int

variable_types:
cur
unsigned int

variable_types:
max
unsigned int

variable_types:
tmp
unsigned char [9000]

variable_types: struct my_ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; unsigned int ip_src; unsigned int ip_dst; } *

variable_types: struct my_udp { unsigned short uh_sport; unsigned short uh_dport; unsigned short uh_ulen; unsigned short uh_sum; } *

variable_types: struct my_tcp { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned int th_flags2; unsigned int th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; } *

variable_types: rbytes int

variable_types:
start
unsigned short


repo: shoban/udpreplay

decompiled_code:
__int64 __fastcall read_file(const char *a1, unsigned int *a2, __int64 a3, unsigned int a4)
{
int v6; // eax
int v7; // ebx
unsigned int v8; // ebp
unsigned int v9; // er12
int v10; // eax
int v11; // eax
unsigned int v12; // er8
char v14[16]; // [rsp+10h] [rbp-68h] BYREF
char buf[88]; // [rsp+20h] [rbp-58h] BYREF

v6 = open(a1, 0);
v7 = v6;
if ( v6 < 0 )
{
fprintf(stderr, "Unable to read file: %s\n", a1);
v12 = v7;
}
else
{
if ( read(v6, buf, 0x18uLL) != 24 )
__assert_fail("read(fd, &h, sizeof(h)) == sizeof(h)", "pcap.c", 0x49u, "read_file");
v8 = 0;
v9 = 0;
while ( 1 )
{
v10 = read(v7, v14, 0x10uLL);
if ( !v10 )
break;
if ( v10 != 16 )
__assert_fail("rbytes == sizeof(rh)", "pcap.c", 0x4Bu, "read_file");
v11 = read_pkt((__int64)v14, v7, a3, v9, a4);
if ( v11 > 0 )
{
v9 += v11;
++v8;
}
}
fprintf(stdout, "data in mem: %u pkts, %u bytes.\n", v8, v9);
v12 = 0;
if ( a2 )
*a2 = v8;
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, unsigned int *a2, __int64 a3, unsigned int a4)
{
int v6; // eax
int v7; // ebx
unsigned int v8; // ebp
unsigned int v9; // er12
int v10; // eax
int v11; // eax
unsigned int v12; // er8
char v14[16]; // [rsp+10h] [rbp-68h] BYREF
char buf[88]; // [rsp+20h] [rbp-58h] BYREF

v6 = open(a1, 0);
v7 = v6;
if ( v6 < 0 )
{
fprintf(stderr, "Unable to read file: %s\n", a1);
v12 = v7;
}
else
{
if ( read(v6, buf, 0x18uLL) != 24 )
__assert_fail("read(fd, &h, sizeof(h)) == sizeof(h)", "pcap.c", 0x49u, "read_file");
v8 = 0;
v9 = 0;
while ( 1 )
{
v10 = read(v7, v14, 0x10uLL);
if ( !v10 )
break;
if ( v10 != 16 )
__assert_fail("rbytes == sizeof(rh)", "pcap.c", 0x4Bu, "read_file");
v11 = func9((__int64)v14, v7, a3, v9, a4);
if ( v11 > 0 )
{
v9 += v11;
++v8;
}
}
fprintf(stdout, "data in mem: %u pkts, %u bytes.\n", v8, v9);
v12 = 0;
if ( a2 )
*a2 = v8;
}
return v12;
}

original_code:
int read_file(const char *file, uint32_t *no_pkts, uint8_t *data, uint32_t max)
{
    int fd, rbytes;
    pcap_hdr_t h;
    pcaprec_hdr_t rh;
    uint32_t cur = 0;
    uint32_t pkts = 0;
    fd = open(file, 00);
    if (fd < 0) {
        fprintf(stderr, "Unable to read file: %s\n", file);
        return fd;
    }
    ((void) sizeof ((read(fd, &h, sizeof(h)) == sizeof(h)) ? 1 : 0), __extension__ ({ if (read(fd, &h, sizeof(h)) == sizeof(h)) ; else __assert_fail ("read(fd, &h, sizeof(h)) == sizeof(h)", "pcap.c", 73, __extension__ __PRETTY_FUNCTION__); }));
    while ((rbytes = read(fd, &rh, sizeof(rh)))) {
        ((void) sizeof ((rbytes == sizeof(rh)) ? 1 : 0), __extension__ ({ if (rbytes == sizeof(rh)) ; else __assert_fail ("rbytes == sizeof(rh)", "pcap.c", 75, __extension__ __PRETTY_FUNCTION__); }));
        rbytes = read_pkt(&rh, fd, data, cur, max);
        if (rbytes > 0) cur += rbytes, pkts++;
    }
    fprintf(stdout, "data in mem: %u pkts, %u bytes.\n", pkts, cur);
    if (no_pkts) *no_pkts = pkts;
    return 0;
}

canonical_original_code:
int read_file(char *file, unsigned int *no_pkts, unsigned char *data, unsigned int max)
{
    int fd; int rbytes;
    struct pcap_hdr_s h;
    struct pcaprec_hdr_s rh;
    unsigned int cur = 0;
    unsigned int pkts = 0;
    fd = open(file, 00);
    if (fd < 0) {
        fprintf(stderr, "Unable to read file: %s\n", file);
        return fd;
    }
    ((void) sizeof ((read(fd, &h, sizeof(h)) == sizeof(h)) ? 1 : 0), __extension__ ({ if (read(fd, &h, sizeof(h)) == sizeof(h)) ; else __assert_fail ("read(fd, &h, sizeof(h)) == sizeof(h)", "pcap.c", 73, __extension__ __PRETTY_FUNCTION__); }));
    while ((rbytes = read(fd, &rh, sizeof(rh)))) {
        ((void) sizeof ((rbytes == sizeof(rh)) ? 1 : 0), __extension__ ({ if (rbytes == sizeof(rh)) ; else __assert_fail ("rbytes == sizeof(rh)", "pcap.c", 75, __extension__ __PRETTY_FUNCTION__); }));
        rbytes = read_pkt(&rh, fd, data, cur, max);
        if (rbytes > 0) cur += rbytes, pkts++;
    }
    fprintf(stdout, "data in mem: %u pkts, %u bytes.\n", pkts, cur);
    if (no_pkts) *no_pkts = pkts;
    return 0;
}

variable_types:
file
char *

variable_types:
data
unsigned char *

variable_types: struct pcap_hdr_s { unsigned int magic_number; unsigned short version_major; unsigned short version_minor; int thiszone; unsigned int sigfigs; unsigned int snaplen; unsigned int network; }

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

variable_types:
pkts
unsigned int

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
void *v4; // r12
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc != 4 )
{
usage(*argv);
exit(1);
}
v3 = malloc(0x40000000uLL);
v4 = v3;
if ( !v3 )
{
fwrite("Unable to alloc.\n", 1uLL, 0x11uLL, stderr);
exit(1);
}
read_file(argv[1], v6, v3, 0x40000000LL);
udpreplay_dump(argv[2], argv[3], v4, v6[0]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
void *v4; // r12
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc != 4 )
{
func7(*argv);
exit(1);
}
v3 = malloc(0x40000000uLL);
v4 = v3;
if ( !v3 )
{
fwrite("Unable to alloc.\n", 1uLL, 0x11uLL, stderr);
exit(1);
}
func10(argv[1], v6, v3, 0x40000000LL);
func8(argv[2], argv[3], v4, v6[0]);
return 0;
}

original_code:
int main(int argc, const char **argv)
{
    int max;
    uint8_t *data;
    uint32_t no_pkts;
    if (argc != 4) {
        usage(argv[0]);
        exit(1);
    }
    max = 1024*1024*1024;
    data = (uint8_t *) malloc(max);
    if (!data) {
        fprintf(stderr, "Unable to alloc.\n");
        exit(1);
    }
    read_file(argv[1], &no_pkts, data, max);
    udpreplay_dump(
            argv[2], argv[3],
            data, no_pkts);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int max;
    unsigned char *data;
    unsigned int no_pkts;
    if (argc != 4) {
        usage(argv[0]);
        exit(1);
    }
    max = 1024*1024*1024;
    data = (unsigned char *) malloc(max);
    if (!data) {
        fprintf(stderr, "Unable to alloc.\n");
        exit(1);
    }
    read_file(argv[1], &no_pkts, data, max);
    udpreplay_dump(
            argv[2], argv[3],
            data, no_pkts);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: max int


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
return fprintf(stderr, "USAGE: %s <pcap-dump> <dst-ip> <dst-port>\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return fprintf(stderr, "USAGE: %s <pcap-dump> <dst-ip> <dst-port>\n", a1);
}

original_code:
void usage(const char *p)
{
    fprintf(stderr, "USAGE: %s <pcap-dump> <dst-ip> <dst-port>\n", p);
}

canonical_original_code:
void usage(char *p)
{
    fprintf(stderr, "USAGE: %s <pcap-dump> <dst-ip> <dst-port>\n", p);
}

variable_types:
p
char *

return_type: void


original_code:
void ts_add(struct timespec *a, uint32_t nanosecs)
{
    a->tv_nsec = a->tv_nsec + nanosecs;
    a->tv_sec += a->tv_nsec/1000000000;
    a->tv_nsec = a->tv_nsec%1000000000;
}

canonical_original_code:
void ts_add(struct timespec *a, unsigned int nanosecs)
{
    a->tv_nsec = a->tv_nsec + nanosecs;
    a->tv_sec += a->tv_nsec/1000000000;
    a->tv_nsec = a->tv_nsec%1000000000;
}

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

variable_types:
nanosecs
unsigned int


decompiled_code:
double __fastcall ts_diff(_DWORD *a1, _DWORD *a2)
{
return (double)(a1[2] - a2[2]) * 0.000000001 + (double)(*a1 - *a2);
}

canonical_decompiled_code:
double __fastcall func8(_DWORD *a1, _DWORD *a2)
{
return (double)(a1[2] - a2[2]) * 0.000000001 + (double)(*a1 - *a2);
}

original_code:
double ts_diff(const struct timespec *a, const struct timespec *b)
{
    double r = a->tv_sec - b->tv_sec;
    r += (a->tv_nsec - b->tv_nsec)*1E-9;
    return r;
}

canonical_original_code:
double ts_diff(struct timespec *a, struct timespec *b)
{
    double r = a->tv_sec - b->tv_sec;
    r += (a->tv_nsec - b->tv_nsec)*1E-9;
    return r;
}

variable_types:
b
struct timespec *

variable_types: r double

return_type: double

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


decompiled_code:
int __fastcall udpplay_rate(const char *a1, const char *a2, char *a3, unsigned int a4, unsigned int a5, int a6)
{
int v6; // er13
int v10; // eax
struct addrinfo *v11; // r15
unsigned int v12; // ebp
char *v13; // r14
struct timespec *v14; // rcx
unsigned int v15; // er12
double v16; // xmm0_8
const char *v18; // rax
int v20; // [rsp+14h] [rbp-A8h]
unsigned int v21; // [rsp+1Ch] [rbp-A0h]
unsigned int v22; // [rsp+20h] [rbp-9Ch]
struct addrinfo *pai; // [rsp+2Ch] [rbp-90h] BYREF
struct timespec tp; // [rsp+34h] [rbp-88h] BYREF
__m128i v25; // [rsp+44h] [rbp-78h] BYREF
struct addrinfo req; // [rsp+54h] [rbp-68h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v10 = getaddrinfo(a1, a2, &req, &pai);
if ( v10 )
{
v18 = gai_strerror(v10);
fprintf(stderr, "getaddrinfo: %s\n", v18);
}
else
{
v11 = pai;
if ( pai )
{
while ( 1 )
{
v6 = socket(v11->ai_family, v11->ai_socktype, v11->ai_protocol);
if ( v6 != -1 )
break;
perror("socket");
v11 = v11->ai_next;
if ( !v11 )
goto LABEL_19;
}
clock_gettime(1, &tp);
v25 = _mm_loadu_si128((const __m128i *)&tp);
v21 = a4 / a5;
v22 = a4 / a5;
fprintf(stdout, "size=%u, pkt_size=%u, no_pkts=%u.\n", a4, a5, a4 / a5);
if ( a4 < a5 )
{
clock_gettime(1, (struct timespec *)&v25);
}
else
{
v12 = 0;
v20 = a6;
v13 = a3;
while ( 1 )
{
ts_add(&v25, 0xF4240u);
clock_nanosleep(1, 1, (const struct timespec *)&v25, v14);
v15 = (int)((double)v20 * ts_diff(&v25, &tp) * 1024.0 * 1024.0 / (double)(int)a5);
if ( v15 > v21 )
v15 = v21;
if ( v12 < v15 )
break;
LABEL_14:
if ( v21 <= v12 )
{
clock_gettime(1, (struct timespec *)&v25);
goto LABEL_13;
}
}
while ( sendto(v6, v13, a5, 0, v11->ai_addr, v11->ai_addrlen) != -1 )
{
++v12;
v13 += a5;
if ( v12 == v15 )
goto LABEL_14;
}
perror("sendto() error");
}
}
else
{
LABEL_19:
v6 = -1;
fwrite("failed to bind socket\n", 1uLL, 0x16uLL, stderr);
}
}
LABEL_13:
freeaddrinfo(pai);
v16 = ts_diff(&v25, &tp);
fprintf(stdout, "sent %u pkts, %u size in time %f secs.\n", v22, v22 * a5, v16);
return close(v6);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1, const char *a2, char *a3, unsigned int a4, unsigned int a5, int a6)
{
int v6; // er13
int v10; // eax
struct addrinfo *v11; // r15
unsigned int v12; // ebp
char *v13; // r14
struct timespec *v14; // rcx
unsigned int v15; // er12
double v16; // xmm0_8
const char *v18; // rax
int v20; // [rsp+14h] [rbp-A8h]
unsigned int v21; // [rsp+1Ch] [rbp-A0h]
unsigned int v22; // [rsp+20h] [rbp-9Ch]
struct addrinfo *pai; // [rsp+2Ch] [rbp-90h] BYREF
struct timespec tp; // [rsp+34h] [rbp-88h] BYREF
__m128i v25; // [rsp+44h] [rbp-78h] BYREF
struct addrinfo req; // [rsp+54h] [rbp-68h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v10 = getaddrinfo(a1, a2, &req, &pai);
if ( v10 )
{
v18 = gai_strerror(v10);
fprintf(stderr, "getaddrinfo: %s\n", v18);
}
else
{
v11 = pai;
if ( pai )
{
while ( 1 )
{
v6 = socket(v11->ai_family, v11->ai_socktype, v11->ai_protocol);
if ( v6 != -1 )
break;
perror("socket");
v11 = v11->ai_next;
if ( !v11 )
goto LABEL_19;
}
clock_gettime(1, &tp);
v25 = _mm_loadu_si128((const __m128i *)&tp);
v21 = a4 / a5;
v22 = a4 / a5;
fprintf(stdout, "size=%u, pkt_size=%u, no_pkts=%u.\n", a4, a5, a4 / a5);
if ( a4 < a5 )
{
clock_gettime(1, (struct timespec *)&v25);
}
else
{
v12 = 0;
v20 = a6;
v13 = a3;
while ( 1 )
{
func7(&v25, 0xF4240u);
clock_nanosleep(1, 1, (const struct timespec *)&v25, v14);
v15 = (int)((double)v20 * func8(&v25, &tp) * 1024.0 * 1024.0 / (double)(int)a5);
if ( v15 > v21 )
v15 = v21;
if ( v12 < v15 )
break;
LABEL_14:
if ( v21 <= v12 )
{
clock_gettime(1, (struct timespec *)&v25);
goto LABEL_13;
}
}
while ( sendto(v6, v13, a5, 0, v11->ai_addr, v11->ai_addrlen) != -1 )
{
++v12;
v13 += a5;
if ( v12 == v15 )
goto LABEL_14;
}
perror("sendto() error");
}
}
else
{
LABEL_19:
v6 = -1;
fwrite("failed to bind socket\n", 1uLL, 0x16uLL, stderr);
}
}
LABEL_13:
freeaddrinfo(pai);
v16 = func8(&v25, &tp);
fprintf(stdout, "sent %u pkts, %u size in time %f secs.\n", v22, v22 * a5, v16);
return close(v6);
}

original_code:
void udpplay_rate(
        const char *dst_ip, const char *dst_port,
        uint8_t *data, uint32_t size,
        uint32_t pkt_size, uint32_t rate)
{
    int sockfd;
    struct addrinfo hints, *servinfo, *p;
    int rv, i;
    int numbytes;
    uint16_t len;
    struct timespec st, ct, slt;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_DGRAM;
    if ((rv = getaddrinfo(dst_ip, dst_port, &hints, &servinfo)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        goto end;
    }
    for(p = servinfo; p != ((void *)0); p = p->ai_next) {
        if ((sockfd = socket(p->ai_family, p->ai_socktype,
                p->ai_protocol)) == -1) {
            perror("socket");
            continue;
        }
        break;
    }
    if (p == ((void *)0)) {
        fprintf(stderr, "failed to bind socket\n");
        goto end;
    }
    clock_gettime(1, &st);
    slt = st;
    uint32_t no_pkts = size/pkt_size;
    uint32_t sent = 0;
    uint32_t must_send = 0;
    fprintf(stdout, "size=%u, pkt_size=%u, no_pkts=%u.\n", size, pkt_size, no_pkts);
    while (sent < no_pkts) {
        ts_add(&slt, 1000000);
        clock_nanosleep(1, 1, &slt, ((void *)0));
        must_send = ts_diff(&slt, &st)*rate*1024*1024/pkt_size;
        while (sent < must_send && sent < no_pkts) {
            if (sendto(sockfd, data, pkt_size, 0,
                        p->ai_addr, p->ai_addrlen) == -1) {
                perror("sendto() error");
                goto end;
            }
            data += pkt_size;
            sent++;
        }
    }
    clock_gettime(1, &slt);
end:
    freeaddrinfo(servinfo);
    fprintf(stdout, "sent %u pkts, %u size in time %f secs.\n",
            no_pkts, no_pkts*pkt_size, ts_diff(&slt, &st));
    close(sockfd);
}

canonical_original_code:
void udpplay_rate(char *dst_ip, char *dst_port, unsigned char *data, unsigned int size, unsigned int pkt_size, unsigned int rate)
{
    int sockfd;
    struct addrinfo hints; struct addrinfo *servinfo; struct addrinfo *p;
    int rv; int i;
    int numbytes;
    unsigned short len;
    struct timespec st; struct timespec ct; struct timespec slt;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_DGRAM;
    if ((rv = getaddrinfo(dst_ip, dst_port, &hints, &servinfo)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        goto end;
    }
    for(p = servinfo; p != ((void *)0); p = p->ai_next) {
        if ((sockfd = socket(p->ai_family, p->ai_socktype,
                p->ai_protocol)) == -1) {
            perror("socket");
            continue;
        }
        break;
    }
    if (p == ((void *)0)) {
        fprintf(stderr, "failed to bind socket\n");
        goto end;
    }
    clock_gettime(1, &st);
    slt = st;
    unsigned int no_pkts = size/pkt_size;
    unsigned int sent = 0;
    unsigned int must_send = 0;
    fprintf(stdout, "size=%u, pkt_size=%u, no_pkts=%u.\n", size, pkt_size, no_pkts);
    while (sent < no_pkts) {
        ts_add(&slt, 1000000);
        clock_nanosleep(1, 1, &slt, ((void *)0));
        must_send = ts_diff(&slt, &st)*rate*1024*1024/pkt_size;
        while (sent < must_send && sent < no_pkts) {
            if (sendto(sockfd, data, pkt_size, 0,
                        p->ai_addr, p->ai_addrlen) == -1) {
                perror("sendto() error");
                goto end;
            }
            data += pkt_size;
            sent++;
        }
    }
    clock_gettime(1, &slt);
end:
    freeaddrinfo(servinfo);
    fprintf(stdout, "sent %u pkts, %u size in time %f secs.\n",
            no_pkts, no_pkts*pkt_size, ts_diff(&slt, &st));
    close(sockfd);
}

variable_types:
size
unsigned int

variable_types:
rate
unsigned int

variable_types: sockfd int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: rv int

variable_types: i int

variable_types: numbytes int

variable_types:
len
unsigned short

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

variable_types:
sent
unsigned int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall read_data_file(const char *a1, __int64 a2, unsigned int a3, int *a4)
{
int v6; // er14
int v7; // ebx
__int64 v8; // rdx
int v9; // eax

v6 = open(a1, 0);
if ( v6 < 0 )
{
fprintf(stderr, "Unable to read file: %s\n", a1);
}
else
{
v7 = 0;
v8 = 0LL;
if ( a3 > 0x400 )
{
do
{
v9 = read(v6, (void *)(a2 + v7), 0x400uLL);
if ( v9 < 0 )
{
perror("read() error");
v8 = (unsigned int)(v7 >> 20);
goto LABEL_8;
}
if ( !v9 )
break;
v7 += v9;
}
while ( v7 + 1024 < a3 );
v8 = (unsigned int)(v7 >> 20);
}
LABEL_8:
v6 = 0;
fprintf(stdout, "read %u mb in memory.\n", v8);
*a4 = v7;
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, __int64 a2, unsigned int a3, int *a4)
{
int v6; // er14
int v7; // ebx
__int64 v8; // rdx
int v9; // eax

v6 = open(a1, 0);
if ( v6 < 0 )
{
fprintf(stderr, "Unable to read file: %s\n", a1);
}
else
{
v7 = 0;
v8 = 0LL;
if ( a3 > 0x400 )
{
do
{
v9 = read(v6, (void *)(a2 + v7), 0x400uLL);
if ( v9 < 0 )
{
perror("read() error");
v8 = (unsigned int)(v7 >> 20);
goto LABEL_8;
}
if ( !v9 )
break;
v7 += v9;
}
while ( v7 + 1024 < a3 );
v8 = (unsigned int)(v7 >> 20);
}
LABEL_8:
v6 = 0;
fprintf(stdout, "read %u mb in memory.\n", v8);
*a4 = v7;
}
return (unsigned int)v6;
}

original_code:
int read_data_file(const char *file, uint8_t *data, uint32_t max,
        uint32_t *read_bytes)
{
    int fd, rb, tb;
    fd = open(file, 00);
    if (fd < 0) {
        fprintf(stderr, "Unable to read file: %s\n", file);
        return fd;
    }
    rb = 0;
    while (rb + 1024 < max) {
        tb = read(fd, &data[rb], 1024);
        if (tb < 0) {
            perror("read() error");
            break;
        }
        if (tb == 0) break;
        rb += tb;
    }
    fprintf(stdout, "read %u mb in memory.\n", rb/(1024*1024));
    *read_bytes = rb;
    return 0;
}

canonical_original_code:
int read_data_file(char *file, unsigned char *data, unsigned int max, unsigned int *read_bytes)
{
    int fd; int rb; int tb;
    fd = open(file, 00);
    if (fd < 0) {
        fprintf(stderr, "Unable to read file: %s\n", file);
        return fd;
    }
    rb = 0;
    while (rb + 1024 < max) {
        tb = read(fd, &data[rb], 1024);
        if (tb < 0) {
            perror("read() error");
            break;
        }
        if (tb == 0) break;
        rb += tb;
    }
    fprintf(stdout, "read %u mb in memory.\n", rb/(1024*1024));
    *read_bytes = rb;
    return 0;
}

variable_types:
file
char *

variable_types:
data
unsigned char *

variable_types:
max
unsigned int

variable_types: fd int

variable_types: rb int

variable_types: tb int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
unsigned int v4; // ebp
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc != 5 )
{
usage(*argv);
exit(1);
}
v6[0] = 0;
v3 = malloc(0x40000000uLL);
v4 = atoi(argv[2]);
if ( !v3 )
{
fwrite("Unable to alloc.\n", 1uLL, 0x11uLL, stderr);
exit(1);
}
if ( (int)read_data_file(argv[1], v3, 0x40000000LL, v6) < 0 )
exit(1);
udpplay_rate(argv[3], argv[4], v3, v6[0], 1400LL, v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
unsigned int v4; // ebp
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc != 5 )
{
func11(*argv);
exit(1);
}
v6[0] = 0;
v3 = malloc(0x40000000uLL);
v4 = atoi(argv[2]);
if ( !v3 )
{
fwrite("Unable to alloc.\n", 1uLL, 0x11uLL, stderr);
exit(1);
}
if ( (int)func10(argv[1], v3, 0x40000000LL, v6) < 0 )
exit(1);
func9(argv[3], argv[4], v3, v6[0], 1400LL, v4);
return 0;
}

original_code:
int main(int argc, const char **argv)
{
    int max;
    uint8_t *data;
    uint32_t no_pkts;
    uint32_t rate, size;
    if (argc != 5) {
        usage(argv[0]);
        exit(1);
    }
    max = 1024*1024*1024;
    size = 0;
    data = (uint8_t *) malloc(max);
    rate = atoi(argv[2]);
    if (!data) {
        fprintf(stderr, "Unable to alloc.\n");
        exit(1);
    }
    if (read_data_file(argv[1], data, max, &size) < 0) {
        exit(1);
    }
    udpplay_rate(
            argv[3], argv[4],
            data, size, 1400, rate);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int max;
    unsigned char *data;
    unsigned int no_pkts;
    unsigned int rate; unsigned int size;
    if (argc != 5) {
        usage(argv[0]);
        exit(1);
    }
    max = 1024*1024*1024;
    size = 0;
    data = (unsigned char *) malloc(max);
    rate = atoi(argv[2]);
    if (!data) {
        fprintf(stderr, "Unable to alloc.\n");
        exit(1);
    }
    if (read_data_file(argv[1], data, max, &size) < 0) {
        exit(1);
    }
    udpplay_rate(
            argv[3], argv[4],
            data, size, 1400, rate);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: max int


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
return fprintf(stderr, "USAGE: %s <data-file> <rate-Mbps> <dst-ip> <dst-port>\n", a1);
}

canonical_decompiled_code:
int __fastcall func11(const char *a1)
{
return fprintf(stderr, "USAGE: %s <data-file> <rate-Mbps> <dst-ip> <dst-port>\n", a1);
}

original_code:
void usage(const char *p)
{
    fprintf(stderr, "USAGE: %s <data-file> <rate-Mbps> <dst-ip> <dst-port>\n", p);
}

canonical_original_code:
void usage(char *p)
{
    fprintf(stderr, "USAGE: %s <data-file> <rate-Mbps> <dst-ip> <dst-port>\n", p);
}

variable_types:
p
char *


main

repo: shockkolate/dcpumulator

original_code:
int main(int argc, char **argv)
{
    struct vm_state_s state;
    state.PC = 0;
    state.SP = 0;
    state.IA = 0;
    state.skip = 0;
    freopen(((void *)0), "rb", stdin);
    fread(state.mem, 1, 0x10000, stdin);
    for(uint32_t i=0; i<0x10000; ++i)
    {
        state.mem[i] = __bswap_16 (state.mem[i]);
    }
    for(;;)
    {
        fputc('\n', stderr);
        fprintf(stderr, "PC=0x%.*x\n", 4, state.PC);
        fprintf(stderr, "[0x2000]=0x%.*x\n", 4, state.mem[0x2000]);
        uint16_t word = *get(&state, 0x1F, 0);
        uint16_t OP = word & 0x1F;
        uint16_t B = (word >> 5) & 0x1F;
        uint16_t A = (word >> 10);
        fprintf(stderr, "OP=0x%.*x\n", 2, OP);
        fprintf(stderr, "B=0x%.*x\n", 2, B);
        fprintf(stderr, "A=0x%.*x\n", 2, A);
        uint16_t *VALA = get(&state, A, 0);
        if(OP == 0)
        {
            process_special(&state, B, VALA);
            continue;
        }
        uint16_t *VALB = get(&state, B, 1);
        process(&state, OP, VALB, VALA);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    struct vm_state_s state;
    state.PC = 0;
    state.SP = 0;
    state.IA = 0;
    state.skip = 0;
    freopen(((void *)0), "rb", stdin);
    fread(state.mem, 1, 0x10000, stdin);
    for(unsigned int i = 0; i<0x10000; ++i)
    {
        state.mem[i] = __bswap_16 (state.mem[i]);
    }
    for(;;)
    {
        fputc('\n', stderr);
        fprintf(stderr, "PC=0x%.*x\n", 4, state.PC);
        fprintf(stderr, "[0x2000]=0x%.*x\n", 4, state.mem[0x2000]);
        unsigned short word = *get(&state, 0x1F, 0);
        unsigned short OP = word & 0x1F;
        unsigned short B = (word >> 5) & 0x1F;
        unsigned short A = (word >> 10);
        fprintf(stderr, "OP=0x%.*x\n", 2, OP);
        fprintf(stderr, "B=0x%.*x\n", 2, B);
        fprintf(stderr, "A=0x%.*x\n", 2, A);
        unsigned short *VALA = get(&state, A, 0);
        if(OP == 0)
        {
            process_special(&state, B, VALA);
            continue;
        }
        unsigned short *VALB = get(&state, B, 1);
        process(&state, OP, VALB, VALA);
    }
    return 0;
}

variable_types: struct vm_state_s { unsigned short A; unsigned short B; unsigned short C; unsigned short X; unsigned short Y; unsigned short Z; unsigned short I; unsigned short J; unsigned short PC; unsigned short SP; unsigned short EX; unsigned short IA; unsigned short mem[65536]; unsigned char skip; }

variable_types:
i
unsigned int

variable_types:
word
unsigned short

variable_types:
OP
unsigned short

variable_types:
B
unsigned short

variable_types:
A
unsigned short

variable_types:
VALA
unsigned short *

variable_types:
VALB
unsigned short *


get

decompiled_code:
unsigned __int16 *__fastcall get(unsigned __int16 *a1, unsigned __int16 a2, char a3)
{
unsigned __int16 *result; // rax
int v4; // ebp
__int64 v5; // rax
unsigned __int16 v6; // ax
__int64 v7; // rax
unsigned __int16 v8; // dx
unsigned __int16 v9; // dx

switch ( a2 )
{
case 0u:
return a1;
case 1u:
return a1 + 1;
case 2u:
return a1 + 2;
case 3u:
return a1 + 3;
case 4u:
return a1 + 4;
case 5u:
return a1 + 5;
case 6u:
return a1 + 6;
case 7u:
return a1 + 7;
case 8u:
return &a1[*a1 + 12];
case 9u:
return &a1[a1[1] + 12];
case 0xAu:
return &a1[a1[2] + 12];
case 0xBu:
return &a1[a1[3] + 12];
case 0xCu:
return &a1[a1[4] + 12];
case 0xDu:
return &a1[a1[5] + 12];
case 0xEu:
return &a1[a1[6] + 12];
case 0xFu:
return &a1[a1[7] + 12];
case 0x10u:
v4 = *a1;
goto LABEL_8;
case 0x11u:
v4 = a1[1];
goto LABEL_8;
case 0x12u:
v4 = a1[2];
goto LABEL_8;
case 0x13u:
v4 = a1[3];
goto LABEL_8;
case 0x14u:
v4 = a1[4];
goto LABEL_8;
case 0x15u:
v4 = a1[5];
goto LABEL_8;
case 0x16u:
v4 = a1[6];
goto LABEL_8;
case 0x17u:
v4 = a1[7];
goto LABEL_8;
case 0x18u:
v5 = a1[9];
if ( a3 )
{
v6 = v5 - 1;
a1[9] = v6;
result = &a1[v6 + 12];
}
else
{
v9 = v5 + 1;
result = &a1[v5 + 12];
a1[9] = v9;
}
return result;
case 0x19u:
return &a1[a1[9] + 12];
case 0x1Au:
v4 = a1[9];
LABEL_8:
result = &a1[v4 + 12 + *(unsigned __int16 *)get(a1, 31LL, 0LL)];
break;
case 0x1Bu:
result = a1 + 9;
break;
case 0x1Cu:
result = a1 + 8;
break;
case 0x1Du:
result = a1 + 10;
break;
case 0x1Eu:
result = &a1[*(unsigned __int16 *)get(a1, 31LL, 0LL) + 12];
break;
case 0x1Fu:
v7 = a1[8];
v8 = v7 + 1;
result = &a1[v7 + 12];
a1[8] = v8;
break;
default:
result = (unsigned __int16 *)((char *)&literals + 2 * a2 - 64);
break;
}
return result;
}

canonical_decompiled_code:
unsigned __int16 *__fastcall func8(unsigned __int16 *a1, unsigned __int16 a2, char a3)
{
unsigned __int16 *result; // rax
int v4; // ebp
__int64 v5; // rax
unsigned __int16 v6; // ax
__int64 v7; // rax
unsigned __int16 v8; // dx
unsigned __int16 v9; // dx

switch ( a2 )
{
case 0u:
return a1;
case 1u:
return a1 + 1;
case 2u:
return a1 + 2;
case 3u:
return a1 + 3;
case 4u:
return a1 + 4;
case 5u:
return a1 + 5;
case 6u:
return a1 + 6;
case 7u:
return a1 + 7;
case 8u:
return &a1[*a1 + 12];
case 9u:
return &a1[a1[1] + 12];
case 0xAu:
return &a1[a1[2] + 12];
case 0xBu:
return &a1[a1[3] + 12];
case 0xCu:
return &a1[a1[4] + 12];
case 0xDu:
return &a1[a1[5] + 12];
case 0xEu:
return &a1[a1[6] + 12];
case 0xFu:
return &a1[a1[7] + 12];
case 0x10u:
v4 = *a1;
goto LABEL_8;
case 0x11u:
v4 = a1[1];
goto LABEL_8;
case 0x12u:
v4 = a1[2];
goto LABEL_8;
case 0x13u:
v4 = a1[3];
goto LABEL_8;
case 0x14u:
v4 = a1[4];
goto LABEL_8;
case 0x15u:
v4 = a1[5];
goto LABEL_8;
case 0x16u:
v4 = a1[6];
goto LABEL_8;
case 0x17u:
v4 = a1[7];
goto LABEL_8;
case 0x18u:
v5 = a1[9];
if ( a3 )
{
v6 = v5 - 1;
a1[9] = v6;
result = &a1[v6 + 12];
}
else
{
v9 = v5 + 1;
result = &a1[v5 + 12];
a1[9] = v9;
}
return result;
case 0x19u:
return &a1[a1[9] + 12];
case 0x1Au:
v4 = a1[9];
LABEL_8:
result = &a1[v4 + 12 + *(unsigned __int16 *)func8(a1, 31LL, 0LL)];
break;
case 0x1Bu:
result = a1 + 9;
break;
case 0x1Cu:
result = a1 + 8;
break;
case 0x1Du:
result = a1 + 10;
break;
case 0x1Eu:
result = &a1[*(unsigned __int16 *)func8(a1, 31LL, 0LL) + 12];
break;
case 0x1Fu:
v7 = a1[8];
v8 = v7 + 1;
result = &a1[v7 + 12];
a1[8] = v8;
break;
default:
result = (unsigned __int16 *)((char *)&literals + 2 * a2 - 64);
break;
}
return result;
}

original_code:
uint16_t * get(struct vm_state_s *state, uint16_t A, unsigned char is_B)
{
    switch(A)
    {
        case 0x00:
            return &state->A;
        case 0x01:
            return &state->B;
        case 0x02:
            return &state->C;
        case 0x03:
            return &state->X;
        case 0x04:
            return &state->Y;
        case 0x05:
            return &state->Z;
        case 0x06:
            return &state->I;
        case 0x07:
            return &state->J;
        case 0x08:
            return &state->mem[state->A];
        case 0x09:
            return &state->mem[state->B];
        case 0x0A:
            return &state->mem[state->C];
        case 0x0B:
            return &state->mem[state->X];
        case 0x0C:
            return &state->mem[state->Y];
        case 0x0D:
            return &state->mem[state->Z];
        case 0x0E:
            return &state->mem[state->I];
        case 0x0F:
            return &state->mem[state->J];
        case 0x10:
            return &state->mem[state->A + *get(state, 0x1F, 0)];
        case 0x11:
            return &state->mem[state->B + *get(state, 0x1F, 0)];
        case 0x12:
            return &state->mem[state->C + *get(state, 0x1F, 0)];
        case 0x13:
            return &state->mem[state->X + *get(state, 0x1F, 0)];
        case 0x14:
            return &state->mem[state->Y + *get(state, 0x1F, 0)];
        case 0x15:
            return &state->mem[state->Z + *get(state, 0x1F, 0)];
        case 0x16:
            return &state->mem[state->I + *get(state, 0x1F, 0)];
        case 0x17:
            return &state->mem[state->J + *get(state, 0x1F, 0)];
        case 0x18:
            return is_B ? &state->mem[--state->SP]
                        : &state->mem[state->SP++];
        case 0x19:
            return &state->mem[state->SP];
        case 0x1A:
            return &state->mem[state->SP + *get(state, 0x1F, 0)];
        case 0x1B:
            return &state->SP;
        case 0x1C:
            return &state->PC;
        case 0x1D:
            return &state->EX;
        case 0x1E:
            return &state->mem[*get(state, 0x1F, 0)];
        case 0x1F:
            return &state->mem[state->PC++];
        default:
            return &literals[A - 0x20];
    }
}

canonical_original_code:
unsigned short *get(struct vm_state_s *state, unsigned short A, unsigned char is_B)
{
    switch(A)
    {
        case 0x00:
            return &state->A;
        case 0x01:
            return &state->B;
        case 0x02:
            return &state->C;
        case 0x03:
            return &state->X;
        case 0x04:
            return &state->Y;
        case 0x05:
            return &state->Z;
        case 0x06:
            return &state->I;
        case 0x07:
            return &state->J;
        case 0x08:
            return &state->mem[state->A];
        case 0x09:
            return &state->mem[state->B];
        case 0x0A:
            return &state->mem[state->C];
        case 0x0B:
            return &state->mem[state->X];
        case 0x0C:
            return &state->mem[state->Y];
        case 0x0D:
            return &state->mem[state->Z];
        case 0x0E:
            return &state->mem[state->I];
        case 0x0F:
            return &state->mem[state->J];
        case 0x10:
            return &state->mem[state->A + *get(state, 0x1F, 0)];
        case 0x11:
            return &state->mem[state->B + *get(state, 0x1F, 0)];
        case 0x12:
            return &state->mem[state->C + *get(state, 0x1F, 0)];
        case 0x13:
            return &state->mem[state->X + *get(state, 0x1F, 0)];
        case 0x14:
            return &state->mem[state->Y + *get(state, 0x1F, 0)];
        case 0x15:
            return &state->mem[state->Z + *get(state, 0x1F, 0)];
        case 0x16:
            return &state->mem[state->I + *get(state, 0x1F, 0)];
        case 0x17:
            return &state->mem[state->J + *get(state, 0x1F, 0)];
        case 0x18:
            return is_B ? &state->mem[--state->SP]
                        : &state->mem[state->SP++];
        case 0x19:
            return &state->mem[state->SP];
        case 0x1A:
            return &state->mem[state->SP + *get(state, 0x1F, 0)];
        case 0x1B:
            return &state->SP;
        case 0x1C:
            return &state->PC;
        case 0x1D:
            return &state->EX;
        case 0x1E:
            return &state->mem[*get(state, 0x1F, 0)];
        case 0x1F:
            return &state->mem[state->PC++];
        default:
            return &literals[A - 0x20];
    }
}

variable_types: struct vm_state_s { unsigned short A; unsigned short B; unsigned short C; unsigned short X; unsigned short Y; unsigned short Z; unsigned short I; unsigned short J; unsigned short PC; unsigned short SP; unsigned short EX; unsigned short IA; unsigned short mem[65536]; unsigned char skip; } *

return_type: unsigned short *


original_code:
void process_special(struct vm_state_s *state, uint16_t B, uint16_t *VALA)
{
    if(state->skip) return;
    switch(B)
    {
        case 0x01:
            process(state, 0x01, get(state, 0x18, 1), get(state, 0x1B, 1));
            state->PC = *VALA;
            break;
    }
}

canonical_original_code:
void process_special(struct vm_state_s *state, unsigned short B, unsigned short *VALA)
{
    if(state->skip) return;
    switch(B)
    {
        case 0x01:
            process(state, 0x01, get(state, 0x18, 1), get(state, 0x1B, 1));
            state->PC = *VALA;
            break;
    }
}

user_defined_types: struct vm_state_s { unsigned short A; unsigned short B; unsigned short C; unsigned short X; unsigned short Y; unsigned short Z; unsigned short I; unsigned short J; unsigned short PC; unsigned short SP; unsigned short EX; unsigned short IA; unsigned short mem[65536]; unsigned char skip; }


repo: shockkolate/dcpussembler

original_code:
uint16_t get_op(char *OP_str, uint16_t *special)
{
    int32_t OP = __bswap_32 (*(int32_t *)OP_str);
    switch(OP)
    {
        case 'SET\0':
            return 0x01;
        case 'ADD\0':
            return 0x02;
        case 'SUB\0':
            return 0x03;
        case 'MUL\0':
            return 0x04;
        case 'MLI\0':
            return 0x05;
        case 'DIV\0':
            return 0x06;
        case 'DVI\0':
            return 0x07;
        case 'MOD\0':
            return 0x08;
        case 'MDI\0':
            return 0x09;
        case 'AND\0':
            return 0x0A;
        case 'BOR\0':
            return 0x0B;
        case 'XOR\0':
            return 0x0C;
        case 'SHR\0':
            return 0x0D;
        case 'ASR\0':
            return 0x0E;
        case 'SHL\0':
            return 0x0F;
        case 'IFB\0':
            return 0x10;
        case 'IFC\0':
            return 0x11;
        case 'IFE\0':
            return 0x12;
        case 'IFN\0':
            return 0x13;
        case 'IFG\0':
            return 0x14;
        case 'IFA\0':
            return 0x15;
        case 'IFL\0':
            return 0x16;
        case 'IFU\0':
            return 0x17;
        case 'ADX\0':
            return 0x1A;
        case 'SBX\0':
            return 0x1B;
        case 'STI\0':
            return 0x1E;
        case 'STD\0':
            return 0x1F;
        case 'JSR\0':
            *special = 0x01;
            return 0;
        case 'INT\0':
            *special = 0x08;
            return 0;
        case 'IAG\0':
            *special = 0x09;
            return 0;
        case 'IAS\0':
            *special = 0x0A;
            return 0;
        case 'RFI\0':
            *special = 0x0B;
            return 0;
        case 'IAQ\0':
            *special = 0x0C;
            return 0;
        case 'HWN\0':
            *special = 0x10;
            return 0;
        case 'HWQ\0':
            *special = 0x11;
            return 0;
        case 'HWI\0':
            *special = 0x12;
            return 0;
        default:
            return 0xFF;
    }
}

canonical_original_code:
unsigned short get_op(char *OP_str, unsigned short *special)
{
    int OP = __bswap_32 (*(int32_t *)OP_str);
    switch(OP)
    {
        case 'SET\0':
            return 0x01;
        case 'ADD\0':
            return 0x02;
        case 'SUB\0':
            return 0x03;
        case 'MUL\0':
            return 0x04;
        case 'MLI\0':
            return 0x05;
        case 'DIV\0':
            return 0x06;
        case 'DVI\0':
            return 0x07;
        case 'MOD\0':
            return 0x08;
        case 'MDI\0':
            return 0x09;
        case 'AND\0':
            return 0x0A;
        case 'BOR\0':
            return 0x0B;
        case 'XOR\0':
            return 0x0C;
        case 'SHR\0':
            return 0x0D;
        case 'ASR\0':
            return 0x0E;
        case 'SHL\0':
            return 0x0F;
        case 'IFB\0':
            return 0x10;
        case 'IFC\0':
            return 0x11;
        case 'IFE\0':
            return 0x12;
        case 'IFN\0':
            return 0x13;
        case 'IFG\0':
            return 0x14;
        case 'IFA\0':
            return 0x15;
        case 'IFL\0':
            return 0x16;
        case 'IFU\0':
            return 0x17;
        case 'ADX\0':
            return 0x1A;
        case 'SBX\0':
            return 0x1B;
        case 'STI\0':
            return 0x1E;
        case 'STD\0':
            return 0x1F;
        case 'JSR\0':
            *special = 0x01;
            return 0;
        case 'INT\0':
            *special = 0x08;
            return 0;
        case 'IAG\0':
            *special = 0x09;
            return 0;
        case 'IAS\0':
            *special = 0x0A;
            return 0;
        case 'RFI\0':
            *special = 0x0B;
            return 0;
        case 'IAQ\0':
            *special = 0x0C;
            return 0;
        case 'HWN\0':
            *special = 0x10;
            return 0;
        case 'HWQ\0':
            *special = 0x11;
            return 0;
        case 'HWI\0':
            *special = 0x12;
            return 0;
        default:
            return 0xFF;
    }
}

variable_types:
special
unsigned short *

variable_types: OP int

return_type: unsigned short


original_code:
uint16_t get_value(char *s, int *pos, int *num_extra, uint16_t *extra)
{
    char unused[2];
    int newpos = 0;
    int is_left_bracket = sscanf(&s[*pos], " %1[[]%n", unused, &newpos) == 1;
    *pos += newpos;
    int first_i;
    char first_s[5] = {0,0,0,0,0};
    newpos = 0;
    int first_is_integer = sscanf(&s[*pos], " %i%n", &first_i, &newpos) == 1;
    *pos += newpos;
    if(!first_is_integer)
    {
        newpos = 0;
        if(sscanf(&s[*pos], " %4[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]%n", first_s, &newpos) != 1)
        {
            return 0xFF;
        }
        *pos += newpos;
        for(unsigned char i=0; i<strlen(first_s); ++i)
        {
            first_s[i] = toupper(first_s[i]);
        }
    }
    newpos = 0;
    int is_plus = sscanf(&s[*pos], " %1[+]%n", unused, &newpos) == 1;
    *pos += newpos;
    int second_i;
    char second_s[5] = {0,0,0,0,0};
    int second_is_integer;
    if(is_plus)
    {
        newpos = 0;
        second_is_integer = sscanf(&s[*pos], " %i%n", &second_i, &newpos) == 1;
        *pos += newpos;
        if(!second_is_integer)
        {
            newpos = 0;
            if(sscanf(&s[*pos], " %4[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]%n", second_s, &newpos) != 1)
            {
                return 0xFF;
            }
            *pos += newpos;
            for(unsigned char i=0; i<strlen(second_s); ++i)
            {
                second_s[i] = toupper(second_s[i]);
            }
        }
    }
    newpos = 0;
    int is_right_bracket = sscanf(&s[*pos], " %1[]]%n", unused, &newpos) == 1;
    *pos += newpos;
    if(sscanf(&s[*pos], " %1s", unused) == 1)
    {
        return 0xFF;
    }
    if(is_left_bracket != is_right_bracket)
    {
        return 0xFF;
    }
    if(!is_left_bracket && !is_plus)
    {
        if(first_is_integer)
        {
            if(first_i >= -1 && first_i <= 30)
            {
                return (0x21 + first_i);
            }
            else
            {
                extra[(*num_extra)++] = first_i;
                return 0x1F;
            }
        }
        int32_t first = __bswap_32 (*(int32_t *)first_s);
        switch(first)
        {
            case 'A\0\0\0':
                return 0x00;
            case 'B\0\0\0':
                return 0x01;
            case 'C\0\0\0':
                return 0x02;
            case 'X\0\0\0':
                return 0x03;
            case 'Y\0\0\0':
                return 0x04;
            case 'Z\0\0\0':
                return 0x05;
            case 'I\0\0\0':
                return 0x06;
            case 'J\0\0\0':
                return 0x02;
            case 'PUSH':
            case 'POP\0':
                return 0x18;
            case 'PEEK':
                return 0x19;
            case 'SP\0\0':
                return 0x1B;
            case 'PC\0\0':
                return 0x1C;
            case 'EX\0\0':
                return 0x1D;
        }
    }
    else if(is_left_bracket && !is_plus)
    {
        if(first_is_integer)
        {
            extra[(*num_extra)++] = first_i;
            return 0x1E;
        }
        int32_t first = __bswap_32 (*(int32_t *)first_s);
        switch(first)
        {
            case 'A\0\0\0':
                return 0x08;
            case 'B\0\0\0':
                return 0x09;
            case 'C\0\0\0':
                return 0x0A;
            case 'X\0\0\0':
                return 0x0B;
            case 'Y\0\0\0':
                return 0x0C;
            case 'Z\0\0\0':
                return 0x0D;
            case 'I\0\0\0':
                return 0x0E;
            case 'J\0\0\0':
                return 0x0F;
            case 'SP\0\0':
                return 0x19;
        }
    }
    else if(is_left_bracket && is_plus && !first_is_integer && second_is_integer)
    {
        int32_t first = __bswap_32 (*(int32_t *)first_s);
        switch(first)
        {
            case 'A\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x10;
            case 'B\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x11;
            case 'C\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x12;
            case 'X\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x13;
            case 'Y\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x14;
            case 'Z\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x15;
            case 'I\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x16;
            case 'J\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x17;
            case 'SP\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x1A;
        }
    }
    return 0xFF;
}

canonical_original_code:
unsigned short get_value(char *s, int *pos, int *num_extra, unsigned short *extra)
{
    char unused[2];
    int newpos = 0;
    int is_left_bracket = sscanf(&s[*pos], " %1[[]%n", unused, &newpos) == 1;
    *pos += newpos;
    int first_i;
    char first_s[5] = {0,0,0,0,0};
    newpos = 0;
    int first_is_integer = sscanf(&s[*pos], " %i%n", &first_i, &newpos) == 1;
    *pos += newpos;
    if(!first_is_integer)
    {
        newpos = 0;
        if(sscanf(&s[*pos], " %4[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]%n", first_s, &newpos) != 1)
        {
            return 0xFF;
        }
        *pos += newpos;
        for(unsigned char i = 0; i<strlen(first_s); ++i)
        {
            first_s[i] = toupper(first_s[i]);
        }
    }
    newpos = 0;
    int is_plus = sscanf(&s[*pos], " %1[+]%n", unused, &newpos) == 1;
    *pos += newpos;
    int second_i;
    char second_s[5] = {0,0,0,0,0};
    int second_is_integer;
    if(is_plus)
    {
        newpos = 0;
        second_is_integer = sscanf(&s[*pos], " %i%n", &second_i, &newpos) == 1;
        *pos += newpos;
        if(!second_is_integer)
        {
            newpos = 0;
            if(sscanf(&s[*pos], " %4[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]%n", second_s, &newpos) != 1)
            {
                return 0xFF;
            }
            *pos += newpos;
            for(unsigned char i = 0; i<strlen(second_s); ++i)
            {
                second_s[i] = toupper(second_s[i]);
            }
        }
    }
    newpos = 0;
    int is_right_bracket = sscanf(&s[*pos], " %1[]]%n", unused, &newpos) == 1;
    *pos += newpos;
    if(sscanf(&s[*pos], " %1s", unused) == 1)
    {
        return 0xFF;
    }
    if(is_left_bracket != is_right_bracket)
    {
        return 0xFF;
    }
    if(!is_left_bracket && !is_plus)
    {
        if(first_is_integer)
        {
            if(first_i >= -1 && first_i <= 30)
            {
                return (0x21 + first_i);
            }
            else
            {
                extra[(*num_extra)++] = first_i;
                return 0x1F;
            }
        }
        int first = __bswap_32 (*(int32_t *)first_s);
        switch(first)
        {
            case 'A\0\0\0':
                return 0x00;
            case 'B\0\0\0':
                return 0x01;
            case 'C\0\0\0':
                return 0x02;
            case 'X\0\0\0':
                return 0x03;
            case 'Y\0\0\0':
                return 0x04;
            case 'Z\0\0\0':
                return 0x05;
            case 'I\0\0\0':
                return 0x06;
            case 'J\0\0\0':
                return 0x02;
            case 'PUSH':
            case 'POP\0':
                return 0x18;
            case 'PEEK':
                return 0x19;
            case 'SP\0\0':
                return 0x1B;
            case 'PC\0\0':
                return 0x1C;
            case 'EX\0\0':
                return 0x1D;
        }
    }
    else if(is_left_bracket && !is_plus)
    {
        if(first_is_integer)
        {
            extra[(*num_extra)++] = first_i;
            return 0x1E;
        }
        int first = __bswap_32 (*(int32_t *)first_s);
        switch(first)
        {
            case 'A\0\0\0':
                return 0x08;
            case 'B\0\0\0':
                return 0x09;
            case 'C\0\0\0':
                return 0x0A;
            case 'X\0\0\0':
                return 0x0B;
            case 'Y\0\0\0':
                return 0x0C;
            case 'Z\0\0\0':
                return 0x0D;
            case 'I\0\0\0':
                return 0x0E;
            case 'J\0\0\0':
                return 0x0F;
            case 'SP\0\0':
                return 0x19;
        }
    }
    else if(is_left_bracket && is_plus && !first_is_integer && second_is_integer)
    {
        int first = __bswap_32 (*(int32_t *)first_s);
        switch(first)
        {
            case 'A\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x10;
            case 'B\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x11;
            case 'C\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x12;
            case 'X\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x13;
            case 'Y\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x14;
            case 'Z\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x15;
            case 'I\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x16;
            case 'J\0\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x17;
            case 'SP\0\0':
                extra[(*num_extra)++] = second_i;
                return 0x1A;
        }
    }
    return 0xFF;
}

variable_types:
s
char *

variable_types:
pos
int *

variable_types:
extra
unsigned short *

variable_types:
unused
char [2]

variable_types: newpos int

variable_types:
i
unsigned char

variable_types: first int


repo: shoenig/YALL

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

result = 0LL;
memset(&uft_table, 0, 0x308uLL);
return result;
}

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

result = 0LL;
memset(&uft_table, 0, 0x308uLL);
return result;
}

original_code:
void
uft_init() {
  size_t idx = 0;
  while(idx < 97) {
    uft_table[idx] = ((void *)0);
    idx++;
  }
}

canonical_original_code:
void uft_init() {
  unsigned long idx = 0;
  while(idx < 97) {
    uft_table[idx] = ((void *)0);
    idx++;
  }
}

variable_types:
idx
unsigned long


decompiled_code:
__int64 __fastcall uft_lookup(char *s1)
{
__int64 i; // rbx
__int64 v2; // r12

for ( i = 0LL; i != 97; ++i )
{
v2 = uft_table[i];
if ( v2 && !strcmp(s1, *(const char **)(v2 + 16)) )
return v2;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
__int64 i; // rbx
__int64 v2; // r12

for ( i = 0LL; i != 97; ++i )
{
v2 = uft_table[i];
if ( v2 && !strcmp(s1, *(const char **)(v2 + 16)) )
return v2;
}
return 0LL;
}

original_code:
UserFunc*
uft_lookup(char* fname) {
  size_t idx = 0;
  while(idx < 97) {
    if(uft_table[idx] && strcmp(fname, uft_table[idx]->func_name) == 0)
      return uft_table[idx];
    idx++;
  }
  return ((void *)0);
}

canonical_original_code:
struct UserFunc *uft_lookup(char *fname) {
  unsigned long idx = 0;
  while(idx < 97) {
    if(uft_table[idx] && strcmp(fname, uft_table[idx]->func_name) == 0)
      return uft_table[idx];
    idx++;
  }
  return ((void *)0);
}

variable_types:
fname
char *

return_type: struct UserFunc { int argc; char **args; char *func_name; struct ast_ { enum ASTTYPE { AST_INVALID=10, AST_INT=11, AST_FLOAT=12, AST_MINUS=13, AST_BOOL=14, AST_LIST=15, AST_LIST_ELEMENT=16, AST_REFERENCE=17, AST_LIST_FUNC=18, AST_BUILTIN_FUNC=19, AST_BOOLEAN_FUNC=20, AST_CALL_USERFUNC=21, AST_AMPER=22, AST_PIPE=23, AST_EQ=24, AST_PLUS=25, AST_SUB=26, AST_MULT=27, AST_DIV=28 } nodetype; struct evaltype { enum EVALTYPE { ET_INVALID=0, ET_INT=1, ET_FLOAT=2, ET_BOOL=3, ET_LIST=4, ET_REFERENCE=5 } type; union { long long i; double f; short bool; struct List { struct ast_ *head; } *list; char *str; enum bif { B_sqrt=40, B_abs=41, B_log=42, B_log2=43, B_log10=44, B_float=45, B_int=46, B_pow=47, B_fact=48, B_negate=49, B_floor=50, B_ceil=51, B_defint=52, B_deffloat=53, B_defbool=54, B_deflist=55, B_if=56, B_with=57, B_ufunc=58, B_defufunc=59 } b; enum cmpf { T_greater_than=70, T_less_than=71, T_not_equal=72, T_equal=73, T_greater_than_equal=74, T_less_than_equal=75, T_and=76, T_or=77 } t; enum listf { L_empty=80, L_len=81, L_peek=82, L_copy=83, L_pop=84, L_push=85 } lfunc; } val; } e; struct ast_ *left; struct ast_ *right; struct ast_ *aux; } *func_body; } *

user_defined_types: struct UserFunc { int argc; char **args; char *func_name; struct ast_ *func_body; }

user_defined_types: struct ast_ { enum ASTTYPE nodetype; struct evaltype e; struct ast_ *left; struct ast_ *right; struct ast_ *aux; }

user_defined_types: struct evaltype { enum EVALTYPE type; union { long long i; double f; short bool; struct List *list; char *str; enum bif b; enum cmpf t; enum listf lfunc; } val; }


decompiled_code:
__int64 __fastcall uft_put(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 result; // rax

v1 = uft_lookup(*(char **)(a1 + 16));
if ( v1 )
{
v2 = v1;
delete_user_func(v1);
*(_DWORD *)v2 = *(_DWORD *)a1;
*(_QWORD *)(v2 + 8) = *(_QWORD *)(a1 + 8);
*(_QWORD *)(v2 + 16) = *(_QWORD *)(a1 + 16);
result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(v2 + 24) = result;
}
else
{
for ( result = 0LL; result != 97; ++result )
{
if ( !uft_table[result] )
{
uft_table[result] = a1;
return result;
}
}
result = crash("functable is out of space");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 result; // rax

v1 = func1(*(char **)(a1 + 16));
if ( v1 )
{
v2 = v1;
delete_user_func(v1);
*(_DWORD *)v2 = *(_DWORD *)a1;
*(_QWORD *)(v2 + 8) = *(_QWORD *)(a1 + 8);
*(_QWORD *)(v2 + 16) = *(_QWORD *)(a1 + 16);
result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(v2 + 24) = result;
}
else
{
for ( result = 0LL; result != 97; ++result )
{
if ( !uft_table[result] )
{
uft_table[result] = a1;
return result;
}
}
result = crash("functable is out of space");
}
return result;
}

original_code:
void
uft_put(UserFunc* uf) {
  UserFunc* temp = uft_lookup(uf->func_name);
  if(!temp) {
    size_t idx = 0;
    while(idx < 97) {
      if(!uft_table[idx]) {
        uft_table[idx] = uf;
        return;
      }
      idx++;
    }
    crash("functable is out of space");
  } else {
    delete_user_func(temp);
    temp->argc = uf->argc;
    temp->args = uf->args;
    temp->func_name = uf->func_name;
    temp->func_body = uf->func_body;
  }
}

canonical_original_code:
void uft_put(struct UserFunc *uf) {
  struct UserFunc *temp = uft_lookup(uf->func_name);
  if(!temp) {
    unsigned long idx = 0;
    while(idx < 97) {
      if(!uft_table[idx]) {
        uft_table[idx] = uf;
        return;
      }
      idx++;
    }
    crash("functable is out of space");
  } else {
    delete_user_func(temp);
    temp->argc = uf->argc;
    temp->args = uf->args;
    temp->func_name = uf->func_name;
    temp->func_body = uf->func_body;
  }
}

variable_types: struct UserFunc { int argc; char **args; char *func_name; struct ast_ { enum ASTTYPE { AST_INVALID=10, AST_INT=11, AST_FLOAT=12, AST_MINUS=13, AST_BOOL=14, AST_LIST=15, AST_LIST_ELEMENT=16, AST_REFERENCE=17, AST_LIST_FUNC=18, AST_BUILTIN_FUNC=19, AST_BOOLEAN_FUNC=20, AST_CALL_USERFUNC=21, AST_AMPER=22, AST_PIPE=23, AST_EQ=24, AST_PLUS=25, AST_SUB=26, AST_MULT=27, AST_DIV=28 } nodetype; struct evaltype { enum EVALTYPE { ET_INVALID=0, ET_INT=1, ET_FLOAT=2, ET_BOOL=3, ET_LIST=4, ET_REFERENCE=5 } type; union { long long i; double f; short bool; struct List { struct ast_ *head; } *list; char *str; enum bif { B_sqrt=40, B_abs=41, B_log=42, B_log2=43, B_log10=44, B_float=45, B_int=46, B_pow=47, B_fact=48, B_negate=49, B_floor=50, B_ceil=51, B_defint=52, B_deffloat=53, B_defbool=54, B_deflist=55, B_if=56, B_with=57, B_ufunc=58, B_defufunc=59 } b; enum cmpf { T_greater_than=70, T_less_than=71, T_not_equal=72, T_equal=73, T_greater_than_equal=74, T_less_than_equal=75, T_and=76, T_or=77 } t; enum listf { L_empty=80, L_len=81, L_peek=82, L_copy=83, L_pop=84, L_push=85 } lfunc; } val; } e; struct ast_ *left; struct ast_ *right; struct ast_ *aux; } *func_body; } *


decompiled_code:
char *__fastcall str_int(__int64 a1)
{
char *v1; // r12

v1 = (char *)malloc(0x20uLL);
sprintf(v1, "%lld", a1);
return v1;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1)
{
char *v1; // r12

v1 = (char *)malloc(0x20uLL);
sprintf(v1, "%lld", a1);
return v1;
}

original_code:
char*
str_int(int64 i) {
  char* nstr = malloc(sizeof(char) * 32);
  sprintf(nstr, "%lld", i);
  return nstr;
}

canonical_original_code:
char *str_int(long long i) {
  char *nstr = malloc(sizeof(char) * 32);
  sprintf(nstr, "%lld", i);
  return nstr;
}

variable_types:
i
long long

variable_types:
nstr
char *

return_type: char *


decompiled_code:
char *__fastcall str_float(double a1)
{
char *v1; // r12

v1 = (char *)malloc(0x20uLL);
sprintf(v1, "%4.2f", a1);
return v1;
}

canonical_decompiled_code:
char *__fastcall func1(double a1)
{
char *v1; // r12

v1 = (char *)malloc(0x20uLL);
sprintf(v1, "%4.2f", a1);
return v1;
}

original_code:
char*
str_float(float64 f) {
  char* nstr = malloc(sizeof(char) * 32);
  sprintf(nstr, "%4.2f", f);
  return nstr;
}

canonical_original_code:
char *str_float(double f) {
  char *nstr = malloc(sizeof(char) * 32);
  sprintf(nstr, "%4.2f", f);
  return nstr;
}

variable_types: f double


decompiled_code:
char *__fastcall str_bool(__int16 a1)
{
char *result; // rax

result = (char *)malloc(6uLL);
if ( a1 )
strcpy(result, "true");
else
strcpy(result, "false");
return result;
}

canonical_decompiled_code:
char *__fastcall func2(__int16 a1)
{
char *result; // rax

result = (char *)malloc(6uLL);
if ( a1 )
strcpy(result, "true");
else
strcpy(result, "false");
return result;
}

original_code:
char*
str_bool(bool b) {
  char* nstr = malloc(sizeof(char) * 6);
  if(!b)
    sprintf(nstr, "false");
  else
    sprintf(nstr, "true");
  return nstr;
}

canonical_original_code:
char *str_bool(short b) {
  char *nstr = malloc(sizeof(char) * 6);
  if(!b)
    sprintf(nstr, "false");
  else
    sprintf(nstr, "true");
  return nstr;
}

variable_types: b short


decompiled_code:
// attributes: thunk
__int64 str_ref()
{
return str_dup();
}

canonical_decompiled_code:
__int64 func3()
{
return str_dup();
}

original_code:
char*
str_ref(char* str) {
  return str_dup(str);
}

canonical_original_code:
char *str_ref(char *str) {
  return str_dup(str);
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall str_list(__int64 *a1)
{
_WORD *v1; // rax
__int64 v2; // rbx
_BYTE *i; // rdi
__int64 v4; // rbp
unsigned int v5; // eax
__int64 v6; // rdx
__int64 v7; // rax
__int64 v8; // rax

v1 = malloc(2uLL);
v2 = *a1;
*v1 = 0;
for ( i = v1; v2; i = (_BYTE *)v8 )
{
v4 = str_ezcat(i, " ");
v5 = eval(*(_QWORD *)(v2 + 24));
v7 = str_evaltype(v5, v6);
v8 = str_ezcat(v4, v7);
v2 = *(_QWORD *)(v2 + 32);
}
*i = 91;
return str_ezcat(i, "]");
}

original_code:
char*
str_list(List* list) {
  char* nstr = malloc(sizeof(char) * 2);
  nstr[0] = '\0';
  nstr[1] = '\0';
  AST* ast = list->head;
  while(ast != ((void *)0)) {
    nstr = str_ezcat(nstr, " ");
    evaltype e = eval(ast->left);
    nstr = str_ezcat(nstr, str_evaltype(e));
    ast = ast->right;
  }
  nstr[0] = '[';
  nstr = str_ezcat(nstr, "]");
  return nstr;
}

canonical_original_code:
char *str_list(struct List *list) {
  char *nstr = malloc(sizeof(char) * 2);
  nstr[0] = '\0';
  nstr[1] = '\0';
  struct ast_ *ast = list->head;
  while(ast != ((void *)0)) {
    nstr = str_ezcat(nstr, " ");
    struct evaltype e = eval(ast->left);
    nstr = str_ezcat(nstr, str_evaltype(e));
    ast = ast->right;
  }
  nstr[0] = '[';
  nstr = str_ezcat(nstr, "]");
  return nstr;
}

variable_types: struct List { struct ast_ { enum ASTTYPE { AST_INVALID=10, AST_INT=11, AST_FLOAT=12, AST_MINUS=13, AST_BOOL=14, AST_LIST=15, AST_LIST_ELEMENT=16, AST_REFERENCE=17, AST_LIST_FUNC=18, AST_BUILTIN_FUNC=19, AST_BOOLEAN_FUNC=20, AST_CALL_USERFUNC=21, AST_AMPER=22, AST_PIPE=23, AST_EQ=24, AST_PLUS=25, AST_SUB=26, AST_MULT=27, AST_DIV=28 } nodetype; struct evaltype { enum EVALTYPE { ET_INVALID=0, ET_INT=1, ET_FLOAT=2, ET_BOOL=3, ET_LIST=4, ET_REFERENCE=5 } type; union { long long i; double f; short bool; struct List *list; char *str; enum bif { B_sqrt=40, B_abs=41, B_log=42, B_log2=43, B_log10=44, B_float=45, B_int=46, B_pow=47, B_fact=48, B_negate=49, B_floor=50, B_ceil=51, B_defint=52, B_deffloat=53, B_defbool=54, B_deflist=55, B_if=56, B_with=57, B_ufunc=58, B_defufunc=59 } b; enum cmpf { T_greater_than=70, T_less_than=71, T_not_equal=72, T_equal=73, T_greater_than_equal=74, T_less_than_equal=75, T_and=76, T_or=77 } t; enum listf { L_empty=80, L_len=81, L_peek=82, L_copy=83, L_pop=84, L_push=85 } lfunc; } val; } e; struct ast_ *left; struct ast_ *right; struct ast_ *aux; } *head; } *

variable_types: struct ast_ { enum ASTTYPE { AST_INVALID=10, AST_INT=11, AST_FLOAT=12, AST_MINUS=13, AST_BOOL=14, AST_LIST=15, AST_LIST_ELEMENT=16, AST_REFERENCE=17, AST_LIST_FUNC=18, AST_BUILTIN_FUNC=19, AST_BOOLEAN_FUNC=20, AST_CALL_USERFUNC=21, AST_AMPER=22, AST_PIPE=23, AST_EQ=24, AST_PLUS=25, AST_SUB=26, AST_MULT=27, AST_DIV=28 } nodetype; struct evaltype { enum EVALTYPE { ET_INVALID=0, ET_INT=1, ET_FLOAT=2, ET_BOOL=3, ET_LIST=4, ET_REFERENCE=5 } type; union { long long i; double f; short bool; struct List { struct ast_ *head; } *list; char *str; enum bif { B_sqrt=40, B_abs=41, B_log=42, B_log2=43, B_log10=44, B_float=45, B_int=46, B_pow=47, B_fact=48, B_negate=49, B_floor=50, B_ceil=51, B_defint=52, B_deffloat=53, B_defbool=54, B_deflist=55, B_if=56, B_with=57, B_ufunc=58, B_defufunc=59 } b; enum cmpf { T_greater_than=70, T_less_than=71, T_not_equal=72, T_equal=73, T_greater_than_equal=74, T_less_than_equal=75, T_and=76, T_or=77 } t; enum listf { L_empty=80, L_len=81, L_peek=82, L_copy=83, L_pop=84, L_push=85 } lfunc; } val; } e; struct ast_ *left; struct ast_ *right; struct ast_ *aux; } *

variable_types: struct evaltype { enum EVALTYPE { ET_INVALID=0, ET_INT=1, ET_FLOAT=2, ET_BOOL=3, ET_LIST=4, ET_REFERENCE=5 } type; union { long long i; double f; short bool; struct List { struct ast_ { enum ASTTYPE { AST_INVALID=10, AST_INT=11, AST_FLOAT=12, AST_MINUS=13, AST_BOOL=14, AST_LIST=15, AST_LIST_ELEMENT=16, AST_REFERENCE=17, AST_LIST_FUNC=18, AST_BUILTIN_FUNC=19, AST_BOOLEAN_FUNC=20, AST_CALL_USERFUNC=21, AST_AMPER=22, AST_PIPE=23, AST_EQ=24, AST_PLUS=25, AST_SUB=26, AST_MULT=27, AST_DIV=28 } nodetype; struct evaltype e; struct ast_ *left; struct ast_ *right; struct ast_ *aux; } *head; } *list; char *str; enum bif { B_sqrt=40, B_abs=41, B_log=42, B_log2=43, B_log10=44, B_float=45, B_int=46, B_pow=47, B_fact=48, B_negate=49, B_floor=50, B_ceil=51, B_defint=52, B_deffloat=53, B_defbool=54, B_deflist=55, B_if=56, B_with=57, B_ufunc=58, B_defufunc=59 } b; enum cmpf { T_greater_than=70, T_less_than=71, T_not_equal=72, T_equal=73, T_greater_than_equal=74, T_less_than_equal=75, T_and=76, T_or=77 } t; enum listf { L_empty=80, L_len=81, L_peek=82, L_copy=83, L_pop=84, L_push=85 } lfunc; } val; }


decompiled_code:
__int64 __fastcall str_evaltype(unsigned int a1, __int64 *a2)
{
__int64 result; // rax
char *v3; // r12

switch ( a1 )
{
case 1u:
result = (__int64)str_int((__int64)a2);
break;
case 2u:
result = (__int64)str_float(*(double *)&a2);
break;
case 3u:
result = (__int64)str_bool((__int16)a2);
break;
case 4u:
result = str_list(a2);
break;
case 5u:
result = str_ref(a2);
break;
default:
v3 = (char *)malloc(0x80uLL);
sprintf(v3, "strERROR (%d)", a1);
result = (__int64)v3;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, __int64 *a2)
{
__int64 result; // rax
char *v3; // r12

switch ( a1 )
{
case 1u:
result = (__int64)func0((__int64)a2);
break;
case 2u:
result = (__int64)func1(*(double *)&a2);
break;
case 3u:
result = (__int64)func2((__int16)a2);
break;
case 4u:
result = func4(a2);
break;
case 5u:
result = func3(a2);
break;
default:
v3 = (char *)malloc(0x80uLL);
sprintf(v3, "strERROR (%d)", a1);
result = (__int64)v3;
break;
}
return result;
}

original_code:
char*
str_evaltype(evaltype e) {
  switch(e.type) {
  case ET_INT: return str_int(e.val.i); break;
  case ET_FLOAT: return str_float(e.val.f); break;
  case ET_BOOL: return str_bool(e.val.bool); break;
  case ET_REFERENCE: return str_ref(e.val.str); break;
  case ET_LIST: return str_list(e.val.list); break;
  default: {
    char* tmp = malloc(sizeof(char) * 128);
    sprintf(tmp, "strERROR (%d)", e.type);
    return tmp;
  }
  }
}

canonical_original_code:
char *str_evaltype(struct evaltype e) {
  switch(e.type) {
  case ET_INT: return str_int(e.val.i); break;
  case ET_FLOAT: return str_float(e.val.f); break;
  case ET_BOOL: return str_bool(e.val.bool); break;
  case ET_REFERENCE: return str_ref(e.val.str); break;
  case ET_LIST: return str_list(e.val.list); break;
  default: {
    char *tmp = malloc(sizeof(char) * 128);
    sprintf(tmp, "strERROR (%d)", e.type);
    return tmp;
  }
  }
}

variable_types:
tmp
char *

user_defined_types: enum EVALTYPE { ET_INVALID=0, ET_INT=1, ET_FLOAT=2, ET_BOOL=3, ET_LIST=4, ET_REFERENCE=5 }

user_defined_types: enum bif { B_sqrt=40, B_abs=41, B_log=42, B_log2=43, B_log10=44, B_float=45, B_int=46, B_pow=47, B_fact=48, B_negate=49, B_floor=50, B_ceil=51, B_defint=52, B_deffloat=53, B_defbool=54, B_deflist=55, B_if=56, B_with=57, B_ufunc=58, B_defufunc=59 }

user_defined_types: enum cmpf { T_greater_than=70, T_less_than=71, T_not_equal=72, T_equal=73, T_greater_than_equal=74, T_less_than_equal=75, T_and=76, T_or=77 }

user_defined_types: enum listf { L_empty=80, L_len=81, L_peek=82, L_copy=83, L_pop=84, L_push=85 }

user_defined_types: enum ASTTYPE { AST_INVALID=10, AST_INT=11, AST_FLOAT=12, AST_MINUS=13, AST_BOOL=14, AST_LIST=15, AST_LIST_ELEMENT=16, AST_REFERENCE=17, AST_LIST_FUNC=18, AST_BUILTIN_FUNC=19, AST_BOOLEAN_FUNC=20, AST_CALL_USERFUNC=21, AST_AMPER=22, AST_PIPE=23, AST_EQ=24, AST_PLUS=25, AST_SUB=26, AST_MULT=27, AST_DIV=28 }


stlen

decompiled_code:
__int64 __fastcall stlen(_BYTE *a1)
{
int v1; // edx
__int64 result; // rax

if ( !*a1 )
return 0LL;
v1 = 1 - (_DWORD)a1;
do
LODWORD(result) = v1 + (_DWORD)a1++;
while ( *a1 );
return (int)result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
int v1; // edx
__int64 result; // rax

if ( !*a1 )
return 0LL;
v1 = 1 - (_DWORD)a1;
do
LODWORD(result) = v1 + (_DWORD)a1++;
while ( *a1 );
return (int)result;
}

original_code:
size_t
stlen(char* str) {
  int len = 0;
  for(;*str!='\0';str++)
    len++;
  return len;
}

canonical_original_code:
unsigned long stlen(char *str) {
  int len = 0;
  for(;*str!='\0';str++)
    len++;
  return len;
}

variable_types: len int

return_type: unsigned long


htoi

decompiled_code:
__int64 __fastcall htoi(_BYTE *a1)
{
unsigned int v1; // eax
unsigned __int64 v2; // r8
char *v3; // rsi
int v4; // ecx
unsigned int v5; // edi
char v6; // al
int v7; // eax

v1 = stlen(a1);
v3 = (char *)(v2 + v1 - 1);
if ( v2 <= (unsigned __int64)v3 )
{
v4 = 0;
v5 = 0;
while ( 1 )
{
while ( 1 )
{
v6 = *v3;
if ( (*v3 & 0xDF) == 88 )
return v5;
if ( (unsigned __int8)(v6 - 48) > 9u )
break;
v5 += (char)(v6 - 48) << v4;
LABEL_4:
--v3;
v4 += 4;
if ( v2 > (unsigned __int64)v3 )
return v5;
}
if ( (unsigned __int8)(v6 - 97) > 5u )
{
if ( (unsigned __int8)(v6 - 65) <= 5u )
v5 += (char)(v6 - 55) << v4;
goto LABEL_4;
}
--v3;
v7 = (char)(v6 - 87) << v4;
v4 += 4;
v5 += v7;
if ( v2 > (unsigned __int64)v3 )
return v5;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
unsigned int v1; // eax
unsigned __int64 v2; // r8
char *v3; // rsi
int v4; // ecx
unsigned int v5; // edi
char v6; // al
int v7; // eax

v1 = func0(a1);
v3 = (char *)(v2 + v1 - 1);
if ( v2 <= (unsigned __int64)v3 )
{
v4 = 0;
v5 = 0;
while ( 1 )
{
while ( 1 )
{
v6 = *v3;
if ( (*v3 & 0xDF) == 88 )
return v5;
if ( (unsigned __int8)(v6 - 48) > 9u )
break;
v5 += (char)(v6 - 48) << v4;
LABEL_4:
--v3;
v4 += 4;
if ( v2 > (unsigned __int64)v3 )
return v5;
}
if ( (unsigned __int8)(v6 - 97) > 5u )
{
if ( (unsigned __int8)(v6 - 65) <= 5u )
v5 += (char)(v6 - 55) << v4;
goto LABEL_4;
}
--v3;
v7 = (char)(v6 - 87) << v4;
v4 += 4;
v5 += v7;
if ( v2 > (unsigned __int64)v3 )
return v5;
}
}
return 0LL;
}

original_code:
int
htoi(char* hex) {
  unsigned int slen = stlen(hex);
  unsigned int val = 0;
  unsigned int multi = 0;
  char* c;
  for(c = hex+slen-1;c>=hex; c--, multi++) {
    unsigned int pow = 1 << (4*multi);
    if(*c=='x' || *c=='X')
      return val;
    else if((*c>='0') && (*c<='9'))
      val += (*c-'0') * pow;
    else if((*c>='a') && (*c<='f'))
      val += ((*c-'a')+10) * pow;
    else if((*c>='A') && (*c<='F'))
      val += ((*c-'A')+10) * pow;
  }
  return val;
}

canonical_original_code:
int htoi(char *hex) {
  unsigned int slen = stlen(hex);
  unsigned int val = 0;
  unsigned int multi = 0;
  char *c;
  for(c = hex+slen-1;c>=hex; c--, multi++) {
    unsigned int pow = 1 << (4*multi);
    if(*c=='x' || *c=='X')
      return val;
    else if((*c>='0') && (*c<='9'))
      val += (*c-'0') * pow;
    else if((*c>='a') && (*c<='f'))
      val += ((*c-'a')+10) * pow;
    else if((*c>='A') && (*c<='F'))
      val += ((*c-'A')+10) * pow;
  }
  return val;
}

variable_types:
hex
char *

variable_types:
slen
unsigned int

variable_types:
val
unsigned int

variable_types:
multi
unsigned int

variable_types:
c
char *

variable_types:
pow
unsigned int


yyerror

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

va_start(arg, format);
fwrite("error: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
return fputc(10, stderr);
}

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

va_start(arg, format);
fwrite("error: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
return fputc(10, stderr);
}

original_code:
void
yyerror(char* s, ...) {
  va_list ap;
  __builtin_va_start(ap,s);
  fprintf(stderr, "error: ");
  vfprintf(stderr, s, ap);
  fprintf(stderr, "\n");
}

canonical_original_code:
void yyerror(char *s, ...) {
  __builtin_va_list ap;
  __builtin_va_start(ap,s);
  fprintf(stderr, "error: ");
  vfprintf(stderr, s, ap);
  fprintf(stderr, "\n");
}

variable_types:
s
char *


crash

decompiled_code:
void __noreturn crash(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
fwrite("FATAL ERROR: ", 1uLL, 0xDuLL, stderr);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
fwrite("FATAL ERROR: ", 1uLL, 0xDuLL, stderr);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
exit(1);
}

original_code:
void
crash(char* s, ...) {
  va_list ap;
  __builtin_va_start(ap,s);
  fprintf(stderr, "FATAL ERROR: ");
  vfprintf(stderr, s, ap);
  fprintf(stderr, "\n");
  exit(1);
}

canonical_original_code:
void crash(char *s, ...) {
  __builtin_va_list ap;
  __builtin_va_start(ap,s);
  fprintf(stderr, "FATAL ERROR: ");
  vfprintf(stderr, s, ap);
  fprintf(stderr, "\n");
  exit(1);
}


yasrt

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

if ( !a1 )
{
va_start(arg, a2);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, a2, arg);
result = fputc(10, stderr);
if ( !reading_stdin )
exit(1);
}
return result;
}

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

if ( !a1 )
{
va_start(arg, a2);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, a2, arg);
result = fputc(10, stderr);
if ( !reading_stdin )
exit(1);
}
return result;
}

original_code:
void
yasrt(bool b, char* s, ...) {
  if(!b) {
    va_list ap;
    __builtin_va_start(ap,s);
    fprintf(stderr, "ERROR: ");
    vfprintf(stderr, s, ap);
    fprintf(stderr, "\n");
    if(!reading_stdin)
      exit(1);
  }
}

canonical_original_code:
void yasrt(short b, char *s, ...) {
  if(!b) {
    __builtin_va_list ap;
    __builtin_va_start(ap,s);
    fprintf(stderr, "ERROR: ");
    vfprintf(stderr, s, ap);
    fprintf(stderr, "\n");
    if(!reading_stdin)
      exit(1);
  }
}


decompiled_code:
__int64 __fastcall list_dup(unsigned int **a1)
{
_QWORD *v1; // r12

v1 = malloc(8uLL);
*v1 = list_dup_elem(*a1);
return 4LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int **a1)
{
_QWORD *v1; // r12

v1 = malloc(8uLL);
*v1 = list_dup_elem(*a1);
return 4LL;
}

original_code:
evaltype
list_dup(List* orig) {
  evaltype ret;
  ret.type = ET_LIST;
  ret.val.list = malloc(sizeof(List));
  ret.val.list->head = _list_dup_elem(orig->head);
  return ret;
}

canonical_original_code:
struct evaltype list_dup(struct List *orig) {
  struct evaltype ret;
  ret.type = ET_LIST;
  ret.val.list = malloc(sizeof(List));
  ret.val.list->head = _list_dup_elem(orig->head);
  return ret;
}

variable_types:
orig
struct List *

return_type: struct evaltype { enum EVALTYPE { ET_INVALID=0, ET_INT=1, ET_FLOAT=2, ET_BOOL=3, ET_LIST=4, ET_REFERENCE=5 } type; union { long long i; double f; short bool; struct List { struct ast_ { enum ASTTYPE { AST_INVALID=10, AST_INT=11, AST_FLOAT=12, AST_MINUS=13, AST_BOOL=14, AST_LIST=15, AST_LIST_ELEMENT=16, AST_REFERENCE=17, AST_LIST_FUNC=18, AST_BUILTIN_FUNC=19, AST_BOOLEAN_FUNC=20, AST_CALL_USERFUNC=21, AST_AMPER=22, AST_PIPE=23, AST_EQ=24, AST_PLUS=25, AST_SUB=26, AST_MULT=27, AST_DIV=28 } nodetype; struct evaltype e; struct ast_ *left; struct ast_ *right; struct ast_ *aux; } *head; } *list; char *str; enum bif { B_sqrt=40, B_abs=41, B_log=42, B_log2=43, B_log10=44, B_float=45, B_int=46, B_pow=47, B_fact=48, B_negate=49, B_floor=50, B_ceil=51, B_defint=52, B_deffloat=53, B_defbool=54, B_deflist=55, B_if=56, B_with=57, B_ufunc=58, B_defufunc=59 } b; enum cmpf { T_greater_than=70, T_less_than=71, T_not_equal=72, T_equal=73, T_greater_than_equal=74, T_less_than_equal=75, T_and=76, T_or=77 } t; enum listf { L_empty=80, L_len=81, L_peek=82, L_copy=83, L_pop=84, L_push=85 } lfunc; } val; }


decompiled_code:
__int64 __fastcall list_length(__int64 *a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 32);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 32);
return i;
}

original_code:
int
list_length(List* list) {
  int size = 0;
  AST* elem_ptr = list->head;
  while(elem_ptr) {
    size++;
    elem_ptr = elem_ptr->right;
  }
  return size;
}

canonical_original_code:
int list_length(struct List *list) {
  int size = 0;
  struct ast_ *elem_ptr = list->head;
  while(elem_ptr) {
    size++;
    elem_ptr = elem_ptr->right;
  }
  return size;
}

variable_types: size int


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

result = 0LL;
memset(&table, 0, 0x1F28uLL);
return result;
}

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

result = 0LL;
memset(&table, 0, 0x1F28uLL);
return result;
}

original_code:
void
smt_init() {
  size_t idx = 0;
  while(idx < 997) {
    table[idx] = ((void *)0);
    idx++;
  }
}

canonical_original_code:
void smt_init() {
  unsigned long idx = 0;
  while(idx < 997) {
    table[idx] = ((void *)0);
    idx++;
  }
}

variable_types:
idx
unsigned long


decompiled_code:
__int64 __fastcall smt_lookup(char *s1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 result; // rax

v1 = 0LL;
while ( 1 )
{
v2 = table[v1];
if ( v2 )
{
if ( !strcmp(s1, *(const char **)v2) )
break;
}
if ( ++v1 == 997 )
return 0LL;
}
do
{
result = v2;
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 result; // rax

v1 = 0LL;
while ( 1 )
{
v2 = table[v1];
if ( v2 )
{
if ( !strcmp(s1, *(const char **)v2) )
break;
}
if ( ++v1 == 997 )
return 0LL;
}
do
{
result = v2;
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
return result;
}

original_code:
Symbol*
smt_lookup(char* name) {
  size_t idx = 0;
  while(idx < 997) {
    if(table[idx] && strcmp(name, table[idx]->name) == 0) {
      Symbol* sym = table[idx];
      while(sym->next)
        sym = sym->next;
      return sym;
    }
    idx++;
  }
  return ((void *)0);
}

canonical_original_code:
struct sym_ *smt_lookup(char *name) {
  unsigned long idx = 0;
  while(idx < 997) {
    if(table[idx] && strcmp(name, table[idx]->name) == 0) {
      struct sym_ *sym = table[idx];
      while(sym->next)
        sym = sym->next;
      return sym;
    }
    idx++;
  }
  return ((void *)0);
}

variable_types:
name
char *

variable_types: struct sym_ { char *name; struct ast_ { enum ASTTYPE { AST_INVALID=10, AST_INT=11, AST_FLOAT=12, AST_MINUS=13, AST_BOOL=14, AST_LIST=15, AST_LIST_ELEMENT=16, AST_REFERENCE=17, AST_LIST_FUNC=18, AST_BUILTIN_FUNC=19, AST_BOOLEAN_FUNC=20, AST_CALL_USERFUNC=21, AST_AMPER=22, AST_PIPE=23, AST_EQ=24, AST_PLUS=25, AST_SUB=26, AST_MULT=27, AST_DIV=28 } nodetype; struct evaltype { enum EVALTYPE { ET_INVALID=0, ET_INT=1, ET_FLOAT=2, ET_BOOL=3, ET_LIST=4, ET_REFERENCE=5 } type; union { long long i; double f; short bool; struct List { struct ast_ *head; } *list; char *str; enum bif { B_sqrt=40, B_abs=41, B_log=42, B_log2=43, B_log10=44, B_float=45, B_int=46, B_pow=47, B_fact=48, B_negate=49, B_floor=50, B_ceil=51, B_defint=52, B_deffloat=53, B_defbool=54, B_deflist=55, B_if=56, B_with=57, B_ufunc=58, B_defufunc=59 } b; enum cmpf { T_greater_than=70, T_less_than=71, T_not_equal=72, T_equal=73, T_greater_than_equal=74, T_less_than_equal=75, T_and=76, T_or=77 } t; enum listf { L_empty=80, L_len=81, L_peek=82, L_copy=83, L_pop=84, L_push=85 } lfunc; } val; } e; struct ast_ *left; struct ast_ *right; struct ast_ *aux; } *ast; short isFunc; struct sym_ *next; } *

user_defined_types: struct sym_ { char *name; struct ast_ *ast; short isFunc; struct sym_ *next; }


decompiled_code:
__int64 __fastcall smt_create_symbol(__int64 a1, __int64 a2)
{
__int64 i; // rbx
_QWORD *v3; // rax
__int64 result; // rax

for ( i = 0LL; i != 997; ++i )
{
if ( !table[i] )
{
v3 = malloc(0x30uLL);
*v3 = a1;
table[i] = (__int64)v3;
v3[1] = dup_ast(a2);
result = table[i];
*(_QWORD *)(result + 24) = 0LL;
return result;
}
}
return crash("Out of symbol table space");
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 i; // rbx
_QWORD *v3; // rax
__int64 result; // rax

for ( i = 0LL; i != 997; ++i )
{
if ( !table[i] )
{
v3 = malloc(0x30uLL);
*v3 = a1;
table[i] = (__int64)v3;
v3[1] = dup_ast(a2);
result = table[i];
*(_QWORD *)(result + 24) = 0LL;
return result;
}
}
return crash("Out of symbol table space");
}

original_code:
void
smt_create_symbol(char* name, AST* ast) {
  size_t idx = 0;
  while(idx < 997) {
    if(table[idx] == ((void *)0)) {
      table[idx] = malloc(sizeof(AST));
      table[idx]->name = name;
      table[idx]->ast = dup_ast(ast);
      table[idx]->next = ((void *)0);
      return;
    }
    idx++;
  }
  crash("Out of symbol table space");
}

canonical_original_code:
void smt_create_symbol(char *name, struct ast_ *ast) {
  unsigned long idx = 0;
  while(idx < 997) {
    if(table[idx] == ((void *)0)) {
      table[idx] = malloc(sizeof(AST));
      table[idx]->name = name;
      table[idx]->ast = dup_ast(ast);
      table[idx]->next = ((void *)0);
      return;
    }
    idx++;
  }
  crash("Out of symbol table space");
}


decompiled_code:
__int64 __fastcall smt_with_exit(char *s1)
{
__int64 v1; // rbx
const char **v2; // rbp
const char **v3; // r12
const char **i; // rax
__int64 result; // rax

v1 = 0LL;
while ( 1 )
{
v2 = (const char **)table[v1];
if ( v2 )
{
if ( !strcmp(s1, *v2) )
break;
}
if ( ++v1 == 997 )
{
crash("cannot delete non-existent symbol: %s", s1);
return 0LL;
}
}
v3 = v2;
for ( i = v2; i[3]; i = (const char **)i[3] )
v3 = i;
if ( i == v3 )
{
free(v2);
result = 1LL;
table[v1] = 0LL;
}
else
{
free((void *)v3[3]);
result = 0LL;
v3[3] = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s1)
{
__int64 v1; // rbx
const char **v2; // rbp
const char **v3; // r12
const char **i; // rax
__int64 result; // rax

v1 = 0LL;
while ( 1 )
{
v2 = (const char **)table[v1];
if ( v2 )
{
if ( !strcmp(s1, *v2) )
break;
}
if ( ++v1 == 997 )
{
crash("cannot delete non-existent symbol: %s", s1);
return 0LL;
}
}
v3 = v2;
for ( i = v2; i[3]; i = (const char **)i[3] )
v3 = i;
if ( i == v3 )
{
free(v2);
result = 1LL;
table[v1] = 0LL;
}
else
{
free((void *)v3[3]);
result = 0LL;
v3[3] = 0LL;
}
return result;
}

original_code:
bool
smt_with_exit(char* name) {
  size_t idx = 0;
  while(idx < 997) {
    if(table[idx] && strcmp(name, table[idx]->name) == 0) {
      Symbol* current = table[idx];
      Symbol* trailer = table[idx];
      while(current->next != ((void *)0)) {
        trailer = current;
        current = current->next;
      }
      if(current == trailer) {
        free(table[idx]);
        table[idx] = ((void *)0);
        return 1;
      }
      else {
        free(trailer->next);
        trailer->next = ((void *)0);
        return 0;
      }
    }
    idx++;
  }
  crash("cannot delete non-existent symbol: %s", name);
  return 0;
}

canonical_original_code:
short smt_with_exit(char *name) {
  unsigned long idx = 0;
  while(idx < 997) {
    if(table[idx] && strcmp(name, table[idx]->name) == 0) {
      struct sym_ *current = table[idx];
      struct sym_ *trailer = table[idx];
      while(current->next != ((void *)0)) {
        trailer = current;
        current = current->next;
      }
      if(current == trailer) {
        free(table[idx]);
        table[idx] = ((void *)0);
        return 1;
      }
      else {
        free(trailer->next);
        trailer->next = ((void *)0);
        return 0;
      }
    }
    idx++;
  }
  crash("cannot delete non-existent symbol: %s", name);
  return 0;
}

return_type: short


decompiled_code:
__int64 __fastcall smt_put(char *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 result; // rax

v2 = smt_lookup(a1);
if ( !v2 )
return smt_create_symbol((__int64)a1, a2);
v3 = v2;
result = dup_ast(a2);
*(_QWORD *)(v3 + 8) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 result; // rax

v2 = func1(a1);
if ( !v2 )
return func2((__int64)a1, a2);
v3 = v2;
result = dup_ast(a2);
*(_QWORD *)(v3 + 8) = result;
return result;
}

original_code:
void
smt_put(char* name, AST* ast) {
  Symbol* sym = smt_lookup(name);
  if(!sym)
    smt_create_symbol(name, ast);
  else
    sym->ast = dup_ast(ast);
}

canonical_original_code:
void smt_put(char *name, struct ast_ *ast) {
  struct sym_ *sym = smt_lookup(name);
  if(!sym)
    smt_create_symbol(name, ast);
  else
    sym->ast = dup_ast(ast);
}


decompiled_code:
__int64 __fastcall smt_del(char *s1)
{
__int64 result; // rax

while ( 1 )
{
result = smt_lookup(s1);
if ( !result )
break;
smt_with_exit(s1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s1)
{
__int64 result; // rax

while ( 1 )
{
result = func1(s1);
if ( !result )
break;
func3(s1);
}
return result;
}

original_code:
void
smt_del(char* name) {
  while(smt_lookup(name))
    smt_with_exit(name);
}

canonical_original_code:
void smt_del(char *name) {
  while(smt_lookup(name))
    smt_with_exit(name);
}


etdec

decompiled_code:
const char *__fastcall etdec(int a1)
{
__int64 v1; // rdi
const char *result; // rax

v1 = (unsigned int)(a1 - 1);
result = "INVALID";
if ( (unsigned int)v1 <= 4 )
result = CSWTCH_1[v1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
__int64 v1; // rdi
const char *result; // rax

v1 = (unsigned int)(a1 - 1);
result = "INVALID";
if ( (unsigned int)v1 <= 4 )
result = CSWTCH_1[v1];
return result;
}

original_code:
const char*
etdec(evaltype e) {
  switch(e.type) {
  case ET_INT: return "INT";
  case ET_FLOAT: return "FLOAT";
  case ET_BOOL: return "BOOL";
  case ET_LIST: return "LIST";
  case ET_REFERENCE: return "REF";
  case ET_INVALID:
  default:
    return "INVALID";
  }
}

canonical_original_code:
char *etdec(struct evaltype e) {
  switch(e.type) {
  case ET_INT: return "INT";
  case ET_FLOAT: return "FLOAT";
  case ET_BOOL: return "BOOL";
  case ET_LIST: return "LIST";
  case ET_REFERENCE: return "REF";
  case ET_INVALID:
  default:
    return "INVALID";
  }
}


astdec

decompiled_code:
const char *__fastcall astdec(_DWORD *a1)
{
const char *v1; // r8
__int64 v2; // rax

v1 = "INVALID";
v2 = (unsigned int)(*a1 - 11);
if ( (unsigned int)v2 <= 0x11 )
v1 = CSWTCH_3[v2];
return v1;
}

canonical_decompiled_code:
const char *__fastcall func1(_DWORD *a1)
{
const char *v1; // r8
__int64 v2; // rax

v1 = "INVALID";
v2 = (unsigned int)(*a1 - 11);
if ( (unsigned int)v2 <= 0x11 )
v1 = CSWTCH_3[v2];
return v1;
}

original_code:
const char*
astdec(AST* ast) {
  switch(ast->nodetype) {
  case AST_INT: return "INT";
  case AST_FLOAT: return "FLOAT";
  case AST_MINUS: return "ARITH-NEGATE";
  case AST_BOOL: return "BOOL";
  case AST_LIST: return "LIST";
  case AST_LIST_ELEMENT: return "LIST-ELEM";
  case AST_REFERENCE: return "REF";
  case AST_LIST_FUNC: return "LIST-FUNC";
  case AST_BUILTIN_FUNC: return "BUILTIN-FUNC";
  case AST_BOOLEAN_FUNC: return "BOOLEAN-FUNC";
  case AST_AMPER: return "&";
  case AST_PIPE: return "|";
  case AST_EQ: return "=";
  case AST_PLUS: return "+";
  case AST_SUB: return "-";
  case AST_MULT: return "*";
  case AST_DIV: return "/";
  case AST_INVALID:
  default:
    return "INVALID";
  }
}

canonical_original_code:
char *astdec(struct ast_ *ast) {
  switch(ast->nodetype) {
  case AST_INT: return "INT";
  case AST_FLOAT: return "FLOAT";
  case AST_MINUS: return "ARITH-NEGATE";
  case AST_BOOL: return "BOOL";
  case AST_LIST: return "LIST";
  case AST_LIST_ELEMENT: return "LIST-ELEM";
  case AST_REFERENCE: return "REF";
  case AST_LIST_FUNC: return "LIST-FUNC";
  case AST_BUILTIN_FUNC: return "BUILTIN-FUNC";
  case AST_BOOLEAN_FUNC: return "BOOLEAN-FUNC";
  case AST_AMPER: return "&";
  case AST_PIPE: return "|";
  case AST_EQ: return "=";
  case AST_PLUS: return "+";
  case AST_SUB: return "-";
  case AST_MULT: return "*";
  case AST_DIV: return "/";
  case AST_INVALID:
  default:
    return "INVALID";
  }
}


original_code:
void
delete_user_func(UserFunc* uf) {
  int i;
  for(i=0; i<uf->argc; i++)
    free(uf->args[i]);
  free(uf->args);
  free(uf->func_name);
  free(uf->func_body);
}

canonical_original_code:
void delete_user_func(struct UserFunc *uf) {
  int i;
  for(i=0; i<uf->argc; i++)
    free(uf->args[i]);
  free(uf->args);
  free(uf->func_name);
  free(uf->func_body);
}

variable_types: struct UserFunc { int argc; char **args; char *func_name; struct ast_ { enum ASTTYPE { AST_INVALID=10, AST_INT=11, AST_FLOAT=12, AST_MINUS=13, AST_BOOL=14, AST_LIST=15, AST_LIST_ELEMENT=16, AST_REFERENCE=17, AST_LIST_FUNC=18, AST_BUILTIN_FUNC=19, AST_BOOLEAN_FUNC=20, AST_CALL_USERFUNC=21, AST_AMPER=22, AST_PIPE=23, AST_EQ=24, AST_PLUS=25, AST_SUB=26, AST_MULT=27, AST_DIV=28 } nodetype; struct evaltype { enum EVALTYPE { ET_INVALID=0, ET_INT=1, ET_FLOAT=2, ET_BOOL=3, ET_LIST=4, ET_REFERENCE=5 } type; union { long long i; double f; short bool; struct List { struct ast_ *head; } *list; char *str; enum bif { B_sqrt=40, B_abs=41, B_log=42, B_log2=43, B_log10=44, B_float=45, B_int=46, B_pow=47, B_fact=48, B_negate=49, B_floor=50, B_ceil=51, B_defint=52, B_deffloat=53, B_defbool=54, B_deflist=55, B_if=56, B_with=57, B_ufunc=58, B_defufunc=59 } b; enum cmpf { T_greater_than=70, T_less_than=71, T_not_equal=72, T_equal=73, T_greater_than_equal=74, T_less_than_equal=75, T_and=76, T_or=77 } t; enum listf { L_empty=80, L_len=81, L_peek=82, L_copy=83, L_pop=84, L_push=85 } lfunc; } val; } e; struct ast_ *left; struct ast_ *right; struct ast_ *aux; } *func_body; } *

variable_types: i int