decompiled_code:
__int64 init_epoll()
{
int v0; // edx
int v1; // ebp
__int64 result; // rax
unsigned int v3; // er12
char *v4; // rax
unsigned int v5; // ebp
char *v6; // rax
unsigned int v7; // er12
char *v8; // rax
unsigned int v9; // [rsp+Ch] [rbp-4Ch]
char s[72]; // [rsp+10h] [rbp-48h] BYREF

snprintf(s, 0x21uLL, "/sys/class/gpio/gpio%d/value", 25LL);
if ( epoll_fd <= 0 )
{
epoll_fd = epoll_create(1);
if ( epoll_fd <= 0 )
{
v7 = *_errno_location();
v8 = strerror(v7);
fprintf(
stderr,
"mcp23s17_wait_for_interrupt: There was a error during the epoll_create.\nError is %s (errno=%d)\n",
v8,
v7);
return 0xFFFFFFFFLL;
}
gpio_pin_fd = open(s, 2048);
v0 = gpio_pin_fd;
}
else
{
v0 = gpio_pin_fd;
}
if ( v0 <= 0 )
{
v9 = v0;
v5 = *_errno_location();
v6 = strerror(v5);
fprintf(stderr, "mcp23s17_wait_for_interrupt: Can't open fd <%s> <%d>.\nError is %s (errno=%d)\n", s, v9, v6, v5);
result = 0xFFFFFFFFLL;
}
else
{
v1 = epoll_fd;
epoll_ctl_events.events = -2147483647;
epoll_ctl_events.data.fd = v0;
if ( epoll_ctl(epoll_fd, 1, v0, &epoll_ctl_events) )
{
fwrite(
"mcp23s17_wait_for_interrupt: There was a error during the epoll_ctl EPOLL_CTL_ADD.\n",
1uLL,
0x53uLL,
stderr);
v3 = *_errno_location();
v4 = strerror(v3);
fprintf(stderr, "Error is %s (errno=%d)\n", v4, v3);
v1 = epoll_fd;
}
epoll_wait(v1, &mcp23s17_epoll_events, 1, 10);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // edx
int v1; // ebp
__int64 result; // rax
unsigned int v3; // er12
char *v4; // rax
unsigned int v5; // ebp
char *v6; // rax
unsigned int v7; // er12
char *v8; // rax
unsigned int v9; // [rsp+Ch] [rbp-4Ch]
char s[72]; // [rsp+10h] [rbp-48h] BYREF

snprintf(s, 0x21uLL, "/sys/class/gpio/gpio%d/value", 25LL);
if ( epoll_fd <= 0 )
{
epoll_fd = epoll_create(1);
if ( epoll_fd <= 0 )
{
v7 = *_errno_location();
v8 = strerror(v7);
fprintf(
stderr,
"mcp23s17_wait_for_interrupt: There was a error during the epoll_create.\nError is %s (errno=%d)\n",
v8,
v7);
return 0xFFFFFFFFLL;
}
gpio_pin_fd = open(s, 2048);
v0 = gpio_pin_fd;
}
else
{
v0 = gpio_pin_fd;
}
if ( v0 <= 0 )
{
v9 = v0;
v5 = *_errno_location();
v6 = strerror(v5);
fprintf(stderr, "mcp23s17_wait_for_interrupt: Can't open fd <%s> <%d>.\nError is %s (errno=%d)\n", s, v9, v6, v5);
result = 0xFFFFFFFFLL;
}
else
{
v1 = epoll_fd;
epoll_ctl_events.events = -2147483647;
epoll_ctl_events.data.fd = v0;
if ( epoll_ctl(epoll_fd, 1, v0, &epoll_ctl_events) )
{
fwrite(
"mcp23s17_wait_for_interrupt: There was a error during the epoll_ctl EPOLL_CTL_ADD.\n",
1uLL,
0x53uLL,
stderr);
v3 = *_errno_location();
v4 = strerror(v3);
fprintf(stderr, "Error is %s (errno=%d)\n", v4, v3);
v1 = epoll_fd;
}
epoll_wait(v1, &mcp23s17_epoll_events, 1, 10);
result = 0LL;
}
return result;
}

original_code:
static int init_epoll(void)
{
    char gpio_pin_filename[33];
    snprintf(gpio_pin_filename,
             sizeof(gpio_pin_filename),
             "/sys/class/gpio/gpio%d/value",
             25);
    if(epoll_fd <= 0) {
        epoll_fd = epoll_create(1);
        if (epoll_fd <= 0) {
            fprintf(stderr,
                    "mcp23s17_wait_for_interrupt: There was a error during "
                    "the epoll_create.\n"
                    "Error is %s (errno=%d)\n",
                    strerror((*__errno_location ())),
                    (*__errno_location ()));
            return -1;
        }
        gpio_pin_fd = open(gpio_pin_filename, 00 | 04000);
    }
    if(gpio_pin_fd <= 0) {
        fprintf(stderr,
                "mcp23s17_wait_for_interrupt: Can't open fd <%s> <%d>.\n"
                "Error is %s (errno=%d)\n",
                gpio_pin_filename,
                gpio_pin_fd,
                strerror((*__errno_location ())),
                (*__errno_location ()));
        return -1;
    } else {
        epoll_ctl_events.events = EPOLLIN | EPOLLET;
        epoll_ctl_events.data.fd = gpio_pin_fd;
        if(epoll_ctl(epoll_fd, 1, gpio_pin_fd, &epoll_ctl_events) != 0) {
            fprintf(stderr,
                    "mcp23s17_wait_for_interrupt: There was a error "
                    "during the epoll_ctl EPOLL_CTL_ADD.\n");
            fprintf(stderr,
                    "Error is %s (errno=%d)\n",
                    strerror((*__errno_location ())),
                    (*__errno_location ()));
        }
        epoll_wait(epoll_fd, &mcp23s17_epoll_events, 1, 10);
        return 0;
    }
}

canonical_original_code:
static int init_epoll()
{
    char gpio_pin_filename[33];
    snprintf(gpio_pin_filename,
             sizeof(gpio_pin_filename),
             "/sys/class/gpio/gpio%d/value",
             25);
    if(epoll_fd <= 0) {
        epoll_fd = epoll_create(1);
        if (epoll_fd <= 0) {
            fprintf(stderr,
                    "mcp23s17_wait_for_interrupt: There was a error during "
                    "the epoll_create.\n"
                    "Error is %s (errno=%d)\n",
                    strerror((*__errno_location ())),
                    (*__errno_location ()));
            return -1;
        }
        gpio_pin_fd = open(gpio_pin_filename, 00 | 04000);
    }
    if(gpio_pin_fd <= 0) {
        fprintf(stderr,
                "mcp23s17_wait_for_interrupt: Can't open fd <%s> <%d>.\n"
                "Error is %s (errno=%d)\n",
                gpio_pin_filename,
                gpio_pin_fd,
                strerror((*__errno_location ())),
                (*__errno_location ()));
        return -1;
    } else {
        epoll_ctl_events.events = EPOLLIN | EPOLLET;
        epoll_ctl_events.data.fd = gpio_pin_fd;
        if(epoll_ctl(epoll_fd, 1, gpio_pin_fd, &epoll_ctl_events) != 0) {
            fprintf(stderr,
                    "mcp23s17_wait_for_interrupt: There was a error "
                    "during the epoll_ctl EPOLL_CTL_ADD.\n");
            fprintf(stderr,
                    "Error is %s (errno=%d)\n",
                    strerror((*__errno_location ())),
                    (*__errno_location ()));
        }
        epoll_wait(epoll_fd, &mcp23s17_epoll_events, 1, 10);
        return 0;
    }
}


decompiled_code:
__int64 __fastcall mcp23s17_open(int a1, int a2)
{
const char *v2; // r13
int v3; // eax
unsigned int v4; // er12
int v6; // edi
int v7; // edi
int v8; // edi

v2 = (&spidev[2 * a1])[a2];
v3 = open(v2, 2);
if ( v3 < 0 )
{
v4 = -1;
fprintf(stderr, "mcp23s17_open: ERROR Could not open SPI device (%s).\n", v2);
}
else
{
v4 = v3;
if ( ioctl(v3, 0x40016B01uLL, &spi_mode) < 0 )
{
fwrite("mcp23s17_open: ERROR Could not set SPI mode.\n", 1uLL, 0x2DuLL, stderr);
v7 = v4;
v4 = -1;
close(v7);
}
else if ( ioctl(v4, 0x40016B03uLL, &spi_bpw) < 0 )
{
fwrite("mcp23s17_open: ERROR Could not set SPI bits per word.\n", 1uLL, 0x36uLL, stderr);
v6 = v4;
v4 = -1;
close(v6);
}
else if ( ioctl(v4, 0x40046B04uLL, &spi_speed) < 0 )
{
fwrite("mcp23s17_open: ERROR Could not set SPI speed.\n", 1uLL, 0x2EuLL, stderr);
v8 = v4;
v4 = -1;
close(v8);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
const char *v2; // r13
int v3; // eax
unsigned int v4; // er12
int v6; // edi
int v7; // edi
int v8; // edi

v2 = (&spidev[2 * a1])[a2];
v3 = open(v2, 2);
if ( v3 < 0 )
{
v4 = -1;
fprintf(stderr, "mcp23s17_open: ERROR Could not open SPI device (%s).\n", v2);
}
else
{
v4 = v3;
if ( ioctl(v3, 0x40016B01uLL, &spi_mode) < 0 )
{
fwrite("mcp23s17_open: ERROR Could not set SPI mode.\n", 1uLL, 0x2DuLL, stderr);
v7 = v4;
v4 = -1;
close(v7);
}
else if ( ioctl(v4, 0x40016B03uLL, &spi_bpw) < 0 )
{
fwrite("mcp23s17_open: ERROR Could not set SPI bits per word.\n", 1uLL, 0x36uLL, stderr);
v6 = v4;
v4 = -1;
close(v6);
}
else if ( ioctl(v4, 0x40046B04uLL, &spi_speed) < 0 )
{
fwrite("mcp23s17_open: ERROR Could not set SPI speed.\n", 1uLL, 0x2EuLL, stderr);
v8 = v4;
v4 = -1;
close(v8);
}
}
return v4;
}

original_code:
int mcp23s17_open(int bus, int chip_select)
{
    int fd;
    if ((fd = open(spidev[bus][chip_select], 02)) < 0) {
        fprintf(stderr,
                "mcp23s17_open: ERROR Could not open SPI device (%s).\n",
                spidev[bus][chip_select]);
        return -1;
    }
    if (ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((1)) << 0) | ((((sizeof(__u8)))) << ((0 +8)+8))), &spi_mode) < 0) {
        fprintf(stderr, "mcp23s17_open: ERROR Could not set SPI mode.\n");
 close(fd);
        return -1;
    }
    if (ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((3)) << 0) | ((((sizeof(__u8)))) << ((0 +8)+8))), &spi_bpw) < 0) {
        fprintf(stderr,
                "mcp23s17_open: ERROR Could not set SPI bits per word.\n");
 close(fd);
        return -1;
    }
    if (ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((4)) << 0) | ((((sizeof(__u32)))) << ((0 +8)+8))), &spi_speed) < 0) {
        fprintf(stderr, "mcp23s17_open: ERROR Could not set SPI speed.\n");
 close(fd);
        return -1;
    }
    return fd;
}

variable_types: bus int

variable_types: fd int

return_type: int


decompiled_code:
__int64 __fastcall mcp23s17_read_reg(__int64 a1, char a2)
{
char v2; // cl
int v3; // edx
int v4; // er8
__int64 result; // rax
char v6[3]; // [rsp+Ah] [rbp-2Eh] BYREF
char v7[3]; // [rsp+Dh] [rbp-2Bh] BYREF
__int64 v8[5]; // [rsp+10h] [rbp-28h] BYREF

v6[0] = get_spi_control_byte(1, a2);
v8[0] = (__int64)v6;
v8[1] = (__int64)v7;
v8[2] = 0x98968000000003LL;
v8[3] = 0x80000LL;
v6[1] = v2;
v6[2] = 0;
v4 = ioctl(v3, 0x40206B00uLL, v8);
result = (unsigned __int8)v7[2];
if ( v4 < 0 )
{
fwrite("mcp23s17_read_reg: There was a error during the SPI transaction.\n", 1uLL, 0x41uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2)
{
char v2; // cl
int v3; // edx
int v4; // er8
__int64 result; // rax
char v6[3]; // [rsp+Ah] [rbp-2Eh] BYREF
char v7[3]; // [rsp+Dh] [rbp-2Bh] BYREF
__int64 v8[5]; // [rsp+10h] [rbp-28h] BYREF

v6[0] = func0(1, a2);
v8[0] = (__int64)v6;
v8[1] = (__int64)v7;
v8[2] = 0x98968000000003LL;
v8[3] = 0x80000LL;
v6[1] = v2;
v6[2] = 0;
v4 = ioctl(v3, 0x40206B00uLL, v8);
result = (unsigned __int8)v7[2];
if ( v4 < 0 )
{
fwrite("mcp23s17_read_reg: There was a error during the SPI transaction.\n", 1uLL, 0x41uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
uint8_t mcp23s17_read_reg(uint8_t reg, uint8_t hw_addr, int fd)
{
    uint8_t control_byte = get_spi_control_byte(1, hw_addr);
    uint8_t tx_buf[3] = {control_byte, reg, 0};
    uint8_t rx_buf[sizeof tx_buf];
    struct spi_ioc_transfer spi;
    memset (&spi, 0, sizeof(spi));
    spi.tx_buf = (unsigned long) tx_buf;
    spi.rx_buf = (unsigned long) rx_buf;
    spi.len = sizeof tx_buf;
    spi.delay_usecs = spi_delay;
    spi.speed_hz = spi_speed;
    spi.bits_per_word = spi_bpw;
    if ((ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char[((((1)*(sizeof (struct spi_ioc_transfer))) < (1 << 14)) ? ((1)*(sizeof (struct spi_ioc_transfer))) : 0)])))) << ((0 +8)+8))), &spi) < 0)) {
        fprintf(stderr,
                "mcp23s17_read_reg: There was a error during the SPI "
                "transaction.\n");
        return -1;
    }
    return rx_buf[2];
}

canonical_original_code:
unsigned char mcp23s17_read_reg(unsigned char reg, unsigned char hw_addr, int fd)
{
    unsigned char control_byte = get_spi_control_byte(1, hw_addr);
    unsigned char tx_buf[3] = {control_byte, reg, 0};
    unsigned char rx_buf[-1];
    struct spi_ioc_transfer spi;
    memset (&spi, 0, sizeof(spi));
    spi.tx_buf = (unsigned long) tx_buf;
    spi.rx_buf = (unsigned long) rx_buf;
    spi.len = sizeof tx_buf;
    spi.delay_usecs = spi_delay;
    spi.speed_hz = spi_speed;
    spi.bits_per_word = spi_bpw;
    if ((ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char [-1])))) << ((0 +8)+8))), &spi) < 0)) {
        fprintf(stderr,
                "mcp23s17_read_reg: There was a error during the SPI "
                "transaction.\n");
        return -1;
    }
    return rx_buf[2];
}

variable_types:
reg
unsigned char

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

return_type: unsigned char


decompiled_code:
int __fastcall mcp23s17_write_reg(__int64 a1, __int64 a2, char a3)
{
char v3; // r10
char v4; // r9
int v5; // ecx
int result; // eax
char v7[3]; // [rsp+Ah] [rbp-2Eh] BYREF
char v8; // [rsp+Dh] [rbp-2Bh] BYREF
char *v9; // [rsp+10h] [rbp-28h]
char *v10; // [rsp+18h] [rbp-20h]
__int64 v11; // [rsp+20h] [rbp-18h]
__int64 v12; // [rsp+28h] [rbp-10h]

v12 = 0x80000LL;
v7[0] = get_spi_control_byte(0, a3);
v9 = v7;
v10 = &v8;
v11 = 0x98968000000003LL;
v7[1] = v3;
v7[2] = v4;
result = ioctl(v5, 0x40206B00uLL);
if ( result < 0 )
result = fwrite("mcp23s17_write_reg: There was a error during the SPI transaction.\n", 1uLL, 0x42uLL, stderr);
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2, char a3)
{
char v3; // r10
char v4; // r9
int v5; // ecx
int result; // eax
char v7[3]; // [rsp+Ah] [rbp-2Eh] BYREF
char v8; // [rsp+Dh] [rbp-2Bh] BYREF
char *v9; // [rsp+10h] [rbp-28h]
char *v10; // [rsp+18h] [rbp-20h]
__int64 v11; // [rsp+20h] [rbp-18h]
__int64 v12; // [rsp+28h] [rbp-10h]

v12 = 0x80000LL;
v7[0] = func0(0, a3);
v9 = v7;
v10 = &v8;
v11 = 0x98968000000003LL;
v7[1] = v3;
v7[2] = v4;
result = ioctl(v5, 0x40206B00uLL);
if ( result < 0 )
result = fwrite("mcp23s17_write_reg: There was a error during the SPI transaction.\n", 1uLL, 0x42uLL, stderr);
return result;
}

original_code:
void mcp23s17_write_reg(uint8_t data, uint8_t reg, uint8_t hw_addr, int fd)
{
    uint8_t control_byte = get_spi_control_byte(0, hw_addr);
    uint8_t tx_buf[3] = {control_byte, reg, data};
    uint8_t rx_buf[sizeof tx_buf];
    struct spi_ioc_transfer spi;
    memset (&spi, 0, sizeof(spi));
    spi.tx_buf = (unsigned long) tx_buf;
    spi.rx_buf = (unsigned long) rx_buf;
    spi.len = sizeof tx_buf;
    spi.delay_usecs = spi_delay;
    spi.speed_hz = spi_speed;
    spi.bits_per_word = spi_bpw;
    if ((ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char[((((1)*(sizeof (struct spi_ioc_transfer))) < (1 << 14)) ? ((1)*(sizeof (struct spi_ioc_transfer))) : 0)])))) << ((0 +8)+8))), &spi) < 0)) {
        fprintf(stderr,
                "mcp23s17_write_reg: There was a error during the SPI "
                "transaction.\n");
    }
}

canonical_original_code:
void mcp23s17_write_reg(unsigned char data, unsigned char reg, unsigned char hw_addr, int fd)
{
    unsigned char control_byte = get_spi_control_byte(0, hw_addr);
    unsigned char tx_buf[3] = {control_byte, reg, data};
    unsigned char rx_buf[-1];
    struct spi_ioc_transfer spi;
    memset (&spi, 0, sizeof(spi));
    spi.tx_buf = (unsigned long) tx_buf;
    spi.rx_buf = (unsigned long) rx_buf;
    spi.len = sizeof tx_buf;
    spi.delay_usecs = spi_delay;
    spi.speed_hz = spi_speed;
    spi.bits_per_word = spi_bpw;
    if ((ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char [-1])))) << ((0 +8)+8))), &spi) < 0)) {
        fprintf(stderr,
                "mcp23s17_write_reg: There was a error during the SPI "
                "transaction.\n");
    }
}

variable_types:
data
unsigned char

return_type: void

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


decompiled_code:
__int64 __fastcall mcp23s17_read_bit(char a1, unsigned __int8 a2, char a3)
{
return ((int)(unsigned __int8)mcp23s17_read_reg(a2, a3) >> a1) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, unsigned __int8 a2, char a3)
{
return ((int)(unsigned __int8)func3(a2, a3) >> a1) & 1;
}

original_code:
uint8_t mcp23s17_read_bit(uint8_t bit_num,
                          uint8_t reg,
                          uint8_t hw_addr,
                          int fd)
{
    return (mcp23s17_read_reg(reg, hw_addr, fd) >> bit_num) & 1;
}

canonical_original_code:
unsigned char mcp23s17_read_bit(unsigned char bit_num, unsigned char reg, unsigned char hw_addr, int fd)
{
    return (mcp23s17_read_reg(reg, hw_addr, fd) >> bit_num) & 1;
}


decompiled_code:
int __fastcall mcp23s17_write_bit(char a1, char a2, unsigned __int8 a3, char a4)
{
unsigned int v5; // ebp
int v6; // eax
int v7; // edx
int v8; // eax

v5 = a3;
v6 = mcp23s17_read_reg(a3, a4);
v7 = v6 & ~(1 << a2);
v8 = (1 << a2) | v6;
if ( a1 )
LOBYTE(v7) = v8;
return mcp23s17_write_reg((unsigned __int8)v7, v5, a4);
}

canonical_decompiled_code:
int __fastcall func6(char a1, char a2, unsigned __int8 a3, char a4)
{
unsigned int v5; // ebp
int v6; // eax
int v7; // edx
int v8; // eax

v5 = a3;
v6 = func3(a3, a4);
v7 = v6 & ~(1 << a2);
v8 = (1 << a2) | v6;
if ( a1 )
LOBYTE(v7) = v8;
return func4((unsigned __int8)v7, v5, a4);
}

original_code:
void mcp23s17_write_bit(uint8_t data,
                        uint8_t bit_num,
                        uint8_t reg,
                        uint8_t hw_addr,
                        int fd)
{
    uint8_t reg_data = mcp23s17_read_reg(reg, hw_addr, fd);
    if (data) {
        reg_data |= 1 << bit_num;
    } else {
        reg_data &= 0xff ^ (1 << bit_num);
    }
    return mcp23s17_write_reg(reg_data, reg, hw_addr, fd);
}

canonical_original_code:
void mcp23s17_write_bit(unsigned char data, unsigned char bit_num, unsigned char reg, unsigned char hw_addr, int fd)
{
    unsigned char reg_data = mcp23s17_read_reg(reg, hw_addr, fd);
    if (data) {
        reg_data |= 1 << bit_num;
    } else {
        reg_data &= 0xff ^ (1 << bit_num);
    }
    return mcp23s17_write_reg(reg_data, reg, hw_addr, fd);
}


decompiled_code:
__int64 mcp23s17_enable_interrupts()
{
int v0; // eax
int v1; // ebp
int v2; // eax
int v3; // ebp
int v4; // eax
int v5; // ebp
char s[3]; // [rsp+Dh] [rbp-4Bh] BYREF
char file[72]; // [rsp+10h] [rbp-48h] BYREF

v0 = open("/sys/class/gpio/export", 1);
if ( v0 < 0 )
return 0xFFFFFFFFLL;
v1 = v0;
snprintf(s, 3uLL, "%d", 25LL);
write(v1, s, 2uLL);
close(v1);
snprintf(file, 0x21uLL, "/sys/class/gpio/gpio%d/direction", 25LL);
v2 = open(file, 1);
v3 = v2;
if ( v2 < 0 )
return 0xFFFFFFFFLL;
write(v2, "in", 3uLL);
close(v3);
snprintf(file, 0x21uLL, "/sys/class/gpio/gpio%d/edge", 25LL);
v4 = open(file, 1);
v5 = v4;
if ( v4 < 0 )
return 0xFFFFFFFFLL;
write(v4, "falling", 8uLL);
close(v5);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
int v1; // ebp
int v2; // eax
int v3; // ebp
int v4; // eax
int v5; // ebp
char s[3]; // [rsp+Dh] [rbp-4Bh] BYREF
char file[72]; // [rsp+10h] [rbp-48h] BYREF

v0 = open("/sys/class/gpio/export", 1);
if ( v0 < 0 )
return 0xFFFFFFFFLL;
v1 = v0;
snprintf(s, 3uLL, "%d", 25LL);
write(v1, s, 2uLL);
close(v1);
snprintf(file, 0x21uLL, "/sys/class/gpio/gpio%d/direction", 25LL);
v2 = open(file, 1);
v3 = v2;
if ( v2 < 0 )
return 0xFFFFFFFFLL;
write(v2, "in", 3uLL);
close(v3);
snprintf(file, 0x21uLL, "/sys/class/gpio/gpio%d/edge", 25LL);
v4 = open(file, 1);
v5 = v4;
if ( v4 < 0 )
return 0xFFFFFFFFLL;
write(v4, "falling", 8uLL);
close(v5);
return 0LL;
}

original_code:
int mcp23s17_enable_interrupts()
{
    int fd, len;
    char str_gpio[3];
    char str_filenm[33];
    if ((fd = open("/sys/class/gpio/export", 01)) < 0)
        return -1;
    len = snprintf(str_gpio, sizeof(str_gpio), "%d", 25);
    write(fd, str_gpio, len);
    close(fd);
    snprintf(str_filenm, sizeof(str_filenm), "/sys/class/gpio/gpio%d/direction", 25);
    if ((fd = open(str_filenm, 01)) < 0)
        return -1;
    write(fd, "in", 3);
    close(fd);
    snprintf(str_filenm, sizeof(str_filenm), "/sys/class/gpio/gpio%d/edge", 25);
    if ((fd = open(str_filenm, 01)) < 0)
        return -1;
    write(fd, "falling", 8);
    close(fd);
    return 0;
}

canonical_original_code:
int mcp23s17_enable_interrupts()
{
    int fd; int len;
    char str_gpio[3];
    char str_filenm[33];
    if ((fd = open("/sys/class/gpio/export", 01)) < 0)
        return -1;
    len = snprintf(str_gpio, sizeof(str_gpio), "%d", 25);
    write(fd, str_gpio, len);
    close(fd);
    snprintf(str_filenm, sizeof(str_filenm), "/sys/class/gpio/gpio%d/direction", 25);
    if ((fd = open(str_filenm, 01)) < 0)
        return -1;
    write(fd, "in", 3);
    close(fd);
    snprintf(str_filenm, sizeof(str_filenm), "/sys/class/gpio/gpio%d/edge", 25);
    if ((fd = open(str_filenm, 01)) < 0)
        return -1;
    write(fd, "falling", 8);
    close(fd);
    return 0;
}

variable_types: len int


decompiled_code:
__int64 mcp23s17_disable_interrupts()
{
int v0; // eax
int v1; // ebp
char s[27]; // [rsp+Dh] [rbp-1Bh] BYREF

v0 = open("/sys/class/gpio/unexport", 1);
if ( v0 < 0 )
return 0xFFFFFFFFLL;
v1 = v0;
snprintf(s, 3uLL, "%d", 25LL);
write(v1, s, 2uLL);
close(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // eax
int v1; // ebp
char s[27]; // [rsp+Dh] [rbp-1Bh] BYREF

v0 = open("/sys/class/gpio/unexport", 1);
if ( v0 < 0 )
return 0xFFFFFFFFLL;
v1 = v0;
snprintf(s, 3uLL, "%d", 25LL);
write(v1, s, 2uLL);
close(v1);
return 0LL;
}

original_code:
int mcp23s17_disable_interrupts()
{
    int fd, len;
    char str_gpio[3];
    if ((fd = open("/sys/class/gpio/unexport", 01)) < 0)
        return -1;
    len = snprintf(str_gpio, sizeof(str_gpio), "%d", 25);
    write(fd, str_gpio, len);
    close(fd);
    return 0;
}

canonical_original_code:
int mcp23s17_disable_interrupts()
{
    int fd; int len;
    char str_gpio[3];
    if ((fd = open("/sys/class/gpio/unexport", 01)) < 0)
        return -1;
    len = snprintf(str_gpio, sizeof(str_gpio), "%d", 25);
    write(fd, str_gpio, len);
    close(fd);
    return 0;
}


decompiled_code:
int __fastcall mcp23s17_wait_for_interrupt(int timeout)
{
int v2; // edi

v2 = epoll_fd;
if ( epoll_fd > 0 )
return epoll_wait(v2, &mcp23s17_epoll_events, 1, timeout);
if ( !(unsigned int)init_epoll() )
{
v2 = epoll_fd;
return epoll_wait(v2, &mcp23s17_epoll_events, 1, timeout);
}
return -1;
}

canonical_decompiled_code:
int __fastcall func9(int timeout)
{
int v2; // edi

v2 = epoll_fd;
if ( epoll_fd > 0 )
return epoll_wait(v2, &mcp23s17_epoll_events, 1, timeout);
if ( !(unsigned int)func1() )
{
v2 = epoll_fd;
return epoll_wait(v2, &mcp23s17_epoll_events, 1, timeout);
}
return -1;
}

original_code:
int mcp23s17_wait_for_interrupt(int timeout)
{
    int num_fds = -1;
    if (epoll_fd <= 0) {
        if (init_epoll() != 0) {
            return -1;
        }
    }
    num_fds = epoll_wait(epoll_fd, &mcp23s17_epoll_events, 1, timeout);
    return num_fds;
}

variable_types: timeout int


repo: pikhq/clambda-demo

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

result = caller(pair, 2LL, churchTrue, churchTrue);
nil = result;
return result;
}

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

result = caller(pair, 2LL, churchTrue, churchTrue);
nil = result;
return result;
}

original_code:
static void __attribute__((constructor)) init_nil()
{
  nil = caller(pair, 2, churchTrue, churchTrue);
}

canonical_original_code:
static void init_nil()
{
  nil = caller(pair, 2, churchTrue, churchTrue);
}


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

result = fst;
isnil = fst;
return result;
}

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

result = fst;
isnil = fst;
return result;
}

original_code:
static void __attribute__((constructor)) init_isnil()
{
  isnil = fst;
}

canonical_original_code:
static void init_isnil()
{
  isnil = fst;
}


main

canonical_name: main

repo: pilliq/lumberjacks

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi

v3 = (unsigned int)stdin;
if ( isatty((int)stdin) == 1 )
acceptFileInput(v3, argv);
else
acceptUserInput(v3, argv);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi

v3 = (unsigned int)stdin;
if ( isatty((int)stdin) == 1 )
func10(v3, argv);
else
func9(v3, argv);
return 1;
}

original_code:
int main(int argc, char **argv)
{
 if (isatty(stdin) != 1)
 {
  acceptUserInput();
 }
 else
 {
  acceptFileInput();
 }
 return 1;
}

variable_types: argc int

variable_types:
argv
char **


run

decompiled_code:
void __fastcall run(char **argv)
{
__pid_t v1; // eax

v1 = fork();
if ( v1 == -1 )
{
perror("fork");
exit(1);
}
if ( !v1 )
{
execvp(*argv, argv);
perror(*argv);
}
}

canonical_decompiled_code:
void __fastcall func7(char **argv)
{
__pid_t v1; // eax

v1 = fork();
if ( v1 == -1 )
{
perror("fork");
exit(1);
}
if ( !v1 )
{
execvp(*argv, argv);
perror(*argv);
}
}

original_code:
void run(char** cmd) {
    int pid;
    switch(pid = fork()) {
        case 0:
            execvp(cmd[0], cmd);
            perror(cmd[0]);
        default:
            break;
        case -1:
            perror("fork");
            exit(1);
    }
}

canonical_original_code:
void run(char **cmd) {
    int pid;
    switch(pid = fork()) {
        case 0:
            execvp(cmd[0], cmd);
            perror(cmd[0]);
        default:
            break;
        case -1:
            perror("fork");
            exit(1);
    }
}

variable_types:
cmd
char **

variable_types: pid int


execute

decompiled_code:
void __fastcall execute(__int64 *a1)
{
__int64 i; // rbp
char **v2; // r12
__int64 v3; // rbx
const char *v4; // rsi

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
{
v2 = *(char ***)i;
printf("Size = %i", *(unsigned int *)(i + 8));
if ( *(int *)(i + 8) > 0 )
{
v3 = 0LL;
do
{
v4 = v2[v3++];
printf("<<Comand>> %s <<Command>>\n", v4);
}
while ( *(_DWORD *)(i + 8) > (int)v3 );
}
run(v2);
}
}

original_code:
void execute(Commands c) {
    commandNode ptr;
    ptr = c->head;
    int i;
    while (ptr) {
        char** cmd = ptr->command;
  i = 0;
        printf("Size = %i", ptr->size);
 for (; i < ptr->size; i++)
 {
  printf("<<Comand>> %s <<Command>>\n", cmd[i]);
 }
        run(cmd);
        ptr = ptr->next;
    }
}

canonical_original_code:
void execute(struct list *c) {
    struct node *ptr;
    ptr = c->head;
    int i;
    while (ptr) {
        char **cmd = ptr->command;
  i = 0;
        printf("Size = %i", ptr->size);
 for (; i < ptr->size; i++)
 {
  printf("<<Comand>> %s <<Command>>\n", cmd[i]);
 }
        run(cmd);
        ptr = ptr->next;
    }
}

variable_types: struct list { struct node { char **command; int size; struct node *next; } *head; int size; } *

variable_types: i int

user_defined_types: struct list { struct node *head; int size; }


acceptUserInput

decompiled_code:
void acceptUserInput()
{
char *v0; // r14
char *v1; // rax
bool v2; // cf
bool v3; // zf
__int64 v4; // rcx
char *v5; // rsi
const char *v6; // rdi
int v7; // ebx
unsigned int v8; // er13
__int64 *v9; // rbp
_QWORD *v10; // r12
_BYTE *v11; // rax
__int64 v12; // rax
__int64 v13; // r15

while ( 1 )
{
v0 = (char *)malloc(0x400uLL);
fwrite("$ ", 1uLL, 2uLL, stdout);
fflush(stdout);
fgets(v0, 1024, stdin);
v1 = &v0[strlen(v0) - 1];
v2 = (unsigned __int8)*v1 < 0xAu;
v3 = *v1 == 10;
if ( *v1 == 10 )
*v1 = 0;
v4 = 5LL;
v5 = v0;
v6 = "quit";
do
{
if ( !v4 )
break;
v2 = (unsigned __int8)*v5 < (unsigned int)*v6;
v3 = *v5++ == *v6++;
--v4;
}
while ( v3 );
if ( (!v2 && !v3) == v2 )
break;
v7 = 0;
v8 = 0;
v9 = (__int64 *)initializeCommands(v6, v5);
v10 = (_QWORD *)parseWord(v0);
v11 = (_BYTE *)*v10;
if ( *v10 )
{
do
{
if ( *v11 == 124 && !v11[1] )
{
++v7;
++v8;
puts("New Command");
}
v12 = v7++;
v13 = v12;
addCommand(v9, v10[v12], v8);
puts("Print Current Commands");
printAllCommands(v9);
v11 = (_BYTE *)v10[v13 + 1];
}
while ( v11 );
}
execute(v9);
cleanCommands(v9);
cleanArray(v10);
free(v0);
}
free(v0);
}

original_code:
void acceptUserInput()
{
 Commands c;
 char* arguments;
 int index;
 int count;
 char **tokens;
 arguments = ((void *)0);
 arguments = (char*) malloc (1024 * sizeof (char));
 fputs("$ ", stdout);
 fflush(stdout);
 fgets(arguments, 1024, stdin);
 if (arguments[ (strlen(arguments) -1)] == '\n')
 {
  arguments[ (strlen(arguments) -1)] = '\0';
 }
 while (arguments != ((void *)0) && strcmp(arguments, "quit") != 0)
 {
  c = initializeCommands();
  tokens = ((void *)0);
  tokens = parseWord(arguments);
  count = 0;
  index = count;
  while (tokens[count] != ((void *)0))
  {
   if (strcmp(tokens[count], "|") == 0)
   {
    index++;
    printf("New Command\n");
    count++;
   }
   addCommand(c, tokens[count], index);
   printf("Print Current Commands\n");
   printAllCommands(c);
   count++;
  }
                execute(c);
  cleanCommands(c);
  cleanArray(tokens, 50);
  tokens = ((void *)0);
  free(arguments);
  arguments = (char*) malloc (1024 * sizeof (char));
  fputs("$ ", stdout);
  fflush(stdout);
  fgets(arguments, 1024, stdin);
  if (arguments[ (strlen(arguments) -1)] == '\n')
  {
   arguments[ (strlen(arguments) -1)] = '\0';
  }
 }
 if (arguments != ((void *)0))
 {
  free(arguments);
 }
}

canonical_original_code:
void acceptUserInput()
{
 struct list *c;
 char *arguments;
 int index;
 int count;
 char **tokens;
 arguments = ((void *)0);
 arguments = (char *) malloc (1024 * sizeof (char));
 fputs("$ ", stdout);
 fflush(stdout);
 fgets(arguments, 1024, stdin);
 if (arguments[ (strlen(arguments) -1)] == '\n')
 {
  arguments[ (strlen(arguments) -1)] = '\0';
 }
 while (arguments != ((void *)0) && strcmp(arguments, "quit") != 0)
 {
  c = initializeCommands();
  tokens = ((void *)0);
  tokens = parseWord(arguments);
  count = 0;
  index = count;
  while (tokens[count] != ((void *)0))
  {
   if (strcmp(tokens[count], "|") == 0)
   {
    index++;
    printf("New Command\n");
    count++;
   }
   addCommand(c, tokens[count], index);
   printf("Print Current Commands\n");
   printAllCommands(c);
   count++;
  }
                execute(c);
  cleanCommands(c);
  cleanArray(tokens, 50);
  tokens = ((void *)0);
  free(arguments);
  arguments = (char *) malloc (1024 * sizeof (char));
  fputs("$ ", stdout);
  fflush(stdout);
  fgets(arguments, 1024, stdin);
  if (arguments[ (strlen(arguments) -1)] == '\n')
  {
   arguments[ (strlen(arguments) -1)] = '\0';
  }
 }
 if (arguments != ((void *)0))
 {
  free(arguments);
 }
}

variable_types:
arguments
char *

variable_types: index int

variable_types: count int

variable_types:
tokens
char **

user_defined_types: struct node { char **command; int size; struct node *next; }


acceptFileInput

decompiled_code:
int acceptFileInput()
{
return puts("input is coming from a file");
}

canonical_decompiled_code:
int func10()
{
return puts("input is coming from a file");
}

original_code:
void acceptFileInput()
{
 printf("input is coming from a file\n");
}


decompiled_code:
void __fastcall ll_free(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[1];
free(*v2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[1];
free(*v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void
ll_free(ll_node_ptr head)
{
  ll_node_ptr delete;
  ll_node_ptr ptr = head;
  while (ptr != ((void *)0))
  {
    delete = ptr;
    ptr = ptr->next;
    free(delete->item);
    free(delete);
  }
  return;
}

canonical_original_code:
void ll_free(struct ll_node *head)
{
  struct ll_node *delete;
  struct ll_node *ptr = head;
  while (ptr != ((void *)0))
  {
    delete = ptr;
    ptr = ptr->next;
    free(delete->item);
    free(delete);
  }
  return;
}

variable_types: struct ll_node { char **item; struct ll_node *next; } *


main

repo: pilt/spotify

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 i; // rdi

v3 = spotify_init(argc, argv, envp);
s = v3;
if ( v3 )
{
for ( i = v3; ; i = s )
{
print_playing(i);
sleep(1u);
}
}
puts("unable to initialize\n");
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 i; // rdi

v3 = func18(argc, argv, envp);
s = v3;
if ( v3 )
{
for ( i = v3; ; i = s )
{
func7(i);
sleep(1u);
}
}
puts("unable to initialize\n");
return -1;
}

original_code:
int main(int argc, char **argv)
{
    if ((s = spotify_init()) == ((void *)0)) {
        puts("unable to initialize\n");
        return -1;
    }
    for (;;) {
        print_playing(s);
        sleep(1);
    }
    spotify_free(s);
    return 0;
}


decompiled_code:
void __fastcall free_tab(void *ptr, int *a2)
{
__int64 v3; // rbx
void *v4; // rdi

if ( *a2 > 0 )
{
v3 = 0LL;
do
{
v4 = (void *)*((_QWORD *)ptr + v3++);
free(v4);
}
while ( *a2 > (int)v3 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr, int *a2)
{
__int64 v3; // rbx
void *v4; // rdi

if ( *a2 > 0 )
{
v3 = 0LL;
do
{
v4 = (void *)*((_QWORD *)ptr + v3++);
free(v4);
}
while ( *a2 > (int)v3 );
}
free(ptr);
}

original_code:
void free_tab(int **tab_aux, int *DIM){
 int i;
 for (i=0;i<(*DIM);i++) {
      free((tab_aux)[i]);
     }
    free(tab_aux);
 }

variable_types:
DIM
int *


caminho

variable_types: lim int

variable_types: j int

variable_types: n int

variable_types: s int

variable_types: e int

variable_types: o int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int v4; // [rsp+Ch] [rbp-3Ch] BYREF
int v5; // [rsp+10h] [rbp-38h] BYREF
int v6; // [rsp+14h] [rbp-34h] BYREF
__int64 v7; // [rsp+18h] [rbp-30h] BYREF
char v8[40]; // [rsp+20h] [rbp-28h] BYREF

v4 = 0;
v5 = 0;
v6 = 0;
v7 = 0LL;
inicia_GR(v8, argv, envp);
while ( 1 )
{
v3 = readline("Letrorium> ");
add_history(v3);
executa_comando(v3, &v6, &v7, &v4, &v5, v8);
putchar(10);
if ( v7 )
printTabuleiro(&v6, &v7);
putchar(10);
if ( v4 )
{
puts("Automaticas pretas:on");
if ( v5 )
goto LABEL_6;
LABEL_8:
puts("Automaticas brancas:off");
}
else
{
puts("Automaticas pretas:off");
if ( !v5 )
goto LABEL_8;
LABEL_6:
puts("Automaticas brancas:on");
}
}
}

original_code:
int main(){
 char *line;
 system("clear");
 while(1){
 line = readline ("Letrorium> ");
 add_history (line);
 system("clear");
 executa_comando(line);
 if(Tab!=((void *)0)) printTabuleiro();
 printf("\n\n");
 }
return 0;
}

variable_types:
line
char *


freeTab

decompiled_code:
void freeTab()
{
__int64 v0; // rbx
void *v1; // rdi

if ( DIM > 0 )
{
v0 = 0LL;
do
{
v1 = (void *)*((_QWORD *)Tab + v0++);
free(v1);
}
while ( DIM > (int)v0 );
}
free(Tab);
Tab = 0LL;
}

canonical_decompiled_code:
void func2()
{
__int64 v0; // rbx
void *v1; // rdi

if ( DIM > 0 )
{
v0 = 0LL;
do
{
v1 = (void *)*((_QWORD *)Tab + v0++);
free(v1);
}
while ( DIM > (int)v0 );
}
free(Tab);
Tab = 0LL;
}

original_code:
void freeTab(){
 int i;
 for (i=0;i<DIM;i++) {
  free(Tab[i]);
  }
 free(Tab);
 Tab=((void *)0);
}


jogada

decompiled_code:
__int64 __fastcall jogada(int a1, int a2, int a3)
{
__int64 result; // rax
__int64 v4; // rcx

if ( a2 <= 0 || a3 <= 0 || DIM < a2 || DIM < a3 )
{
puts(aJogouForaDosLi);
result = 0LL;
}
else if ( (unsigned __int8)(a1 - 98) <= 0xEu && (v4 = 16513LL, _bittest64(&v4, (unsigned int)(a1 - 98))) )
{
*(_BYTE *)(*((_QWORD *)Tab + a3 - 1) + 2LL * a2 - 1) = a1;
result = 1LL;
}
else
{
puts("Escolheu a cor errada.");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2, int a3)
{
__int64 result; // rax
__int64 v4; // rcx

if ( a2 <= 0 || a3 <= 0 || DIM < a2 || DIM < a3 )
{
puts(aJogouForaDosLi);
result = 0LL;
}
else if ( (unsigned __int8)(a1 - 98) <= 0xEu && (v4 = 16513LL, _bittest64(&v4, (unsigned int)(a1 - 98))) )
{
*(_BYTE *)(*((_QWORD *)Tab + a3 - 1) + 2LL * a2 - 1) = a1;
result = 1LL;
}
else
{
puts("Escolheu a cor errada.");
result = 0LL;
}
return result;
}

original_code:
int jogada(char cor,int x,int y){
 if((((x-1)<0) || ((x-1)>=DIM)) || (((y-1)<0) || ((y-1)>=DIM))) {
  printf("\nJogou fora dos limites do tabuleiro ou ainda não abriu o jogo.\n\n");
  return 0;
  }
 if(cor=='i' || cor=='b' || cor=='p'){
  Tab[y-1][x-1].cor=cor;}
 else {
  printf("Escolheu a cor errada.\n");return 0;}
return 1;
}

canonical_original_code:
int jogada(char cor, int x, int y){
 if((((x-1)<0) || ((x-1)>=DIM)) || (((y-1)<0) || ((y-1)>=DIM))) {
  printf("\nJogou fora dos limites do tabuleiro ou ainda não abriu o jogo.\n\n");
  return 0;
  }
 if(cor=='i' || cor=='b' || cor=='p'){
  Tab[y-1][x-1].cor=cor;}
 else {
  printf("Escolheu a cor errada.\n");return 0;}
return 1;
}

variable_types: cor char

variable_types: x int

variable_types: y int


printTabuleiro

decompiled_code:
int printTabuleiro()
{
__int64 v0; // r12
__int64 v1; // rbx
char *v2; // rdx
char v3; // al
int result; // eax
int v5; // ebx
__int64 v6; // rsi

if ( DIM > 0 )
{
v0 = 0LL;
while ( 1 )
{
printf("%d ", (unsigned int)(v0 + 1));
if ( DIM > 0 )
break;
LABEL_11:
++v0;
putchar(10);
if ( DIM <= (int)v0 )
goto LABEL_12;
}
v1 = 0LL;
while ( 1 )
{
while ( 1 )
{
v2 = (char *)(*((_QWORD *)Tab + v0) + 2 * v1);
v3 = v2[1];
if ( v3 != 105 )
break;
printf("\x1B[44;31m %c \x1B[0m", (unsigned int)*v2);
LABEL_7:
if ( DIM <= (int)++v1 )
goto LABEL_11;
}
if ( v3 != 112 )
{
if ( v3 == 98 )
printf("\x1B[47;31m %c \x1B[0m", (unsigned int)*v2);
goto LABEL_7;
}
++v1;
printf("\x1B[40;31m %c \x1B[0m", (unsigned int)*v2);
if ( DIM <= (int)v1 )
goto LABEL_11;
}
}
LABEL_12:
printf(" ");
result = DIM;
if ( DIM > 0 )
{
v5 = 1;
do
{
v6 = (unsigned int)v5++;
result = printf(" %d ", v6);
}
while ( DIM >= v5 );
}
return result;
}

canonical_decompiled_code:
int func6()
{
__int64 v0; // r12
__int64 v1; // rbx
char *v2; // rdx
char v3; // al
int result; // eax
int v5; // ebx
__int64 v6; // rsi

if ( DIM > 0 )
{
v0 = 0LL;
while ( 1 )
{
printf("%d ", (unsigned int)(v0 + 1));
if ( DIM > 0 )
break;
LABEL_11:
++v0;
putchar(10);
if ( DIM <= (int)v0 )
goto LABEL_12;
}
v1 = 0LL;
while ( 1 )
{
while ( 1 )
{
v2 = (char *)(*((_QWORD *)Tab + v0) + 2 * v1);
v3 = v2[1];
if ( v3 != 105 )
break;
printf("\x1B[44;31m %c \x1B[0m", (unsigned int)*v2);
LABEL_7:
if ( DIM <= (int)++v1 )
goto LABEL_11;
}
if ( v3 != 112 )
{
if ( v3 == 98 )
printf("\x1B[47;31m %c \x1B[0m", (unsigned int)*v2);
goto LABEL_7;
}
++v1;
printf("\x1B[40;31m %c \x1B[0m", (unsigned int)*v2);
if ( DIM <= (int)v1 )
goto LABEL_11;
}
}
LABEL_12:
printf(" ");
result = DIM;
if ( DIM > 0 )
{
v5 = 1;
do
{
v6 = (unsigned int)v5++;
result = printf(" %d ", v6);
}
while ( DIM >= v5 );
}
return result;
}

original_code:
void printTabuleiro(){
 int i,j;
 int linha=1;
 for(i=0;i<DIM;i++){
  printf("%d ",linha);
  for(j=0;j<DIM;j++){
   switch (Tab[i][j].cor) {
    case ('i'):
    printf("\e[44;31m %c \e[0m" ,Tab[i][j].letra);
    break;
    case ('b'):
    printf("\e[47;31m %c \e[0m",Tab[i][j].letra);
    break;
    case ('p'):
    printf("\e[40;31m %c \e[0m",Tab[i][j].letra);
    break;
   }
  }
  printf("\n");
  linha++;
 }
 printf("  ");
 for(i=1;i<=DIM;i++){
  printf(" %d ",i);}
}

canonical_original_code:
void printTabuleiro(){
 int i; int j;
 int linha = 1;
 for(i=0;i<DIM;i++){
  printf("%d ",linha);
  for(j=0;j<DIM;j++){
   switch (Tab[i][j].cor) {
    case ('i'):
    printf("\e[44;31m %c \e[0m" ,Tab[i][j].letra);
    break;
    case ('b'):
    printf("\e[47;31m %c \e[0m",Tab[i][j].letra);
    break;
    case ('p'):
    printf("\e[40;31m %c \e[0m",Tab[i][j].letra);
    break;
   }
  }
  printf("\n");
  linha++;
 }
 printf("  ");
 for(i=1;i<=DIM;i++){
  printf(" %d ",i);}
}

variable_types: i int

variable_types: linha int


executaJogada

decompiled_code:
__int64 __fastcall executaJogada(__int64 a1, char *a2)
{
__int64 result; // rax
int v3; // [rsp+8h] [rbp-410h] BYREF
int v4; // [rsp+Ch] [rbp-40Ch] BYREF
char v5; // [rsp+10h] [rbp-408h] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, "%d %d %[^\n]", &v3, &v4, &v5) == 2 )
{
jogada(*a2, v3, v4);
result = 0LL;
}
else
{
fwrite(&unk_CD0, 1uLL, 0x85uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, char *a2)
{
__int64 result; // rax
int v3; // [rsp+8h] [rbp-410h] BYREF
int v4; // [rsp+Ch] [rbp-40Ch] BYREF
char v5; // [rsp+10h] [rbp-408h] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, "%d %d %[^\n]", &v3, &v4, &v5) == 2 )
{
func5(*a2, v3, v4);
result = 0LL;
}
else
{
fwrite(&unk_CD0, 1uLL, 0x85uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int executaJogada(char *args,char *cor) {
  char buf[1024];
  int x, y;
  int nargs = sscanf(args, "%d %d %[^\n]", &x, &y, buf);
  if(nargs != 2) {
      fprintf(stderr, "Comando inválido, está a passar um número de argumentos invalido ou de forma inválida, para mais informações consulte a ajuda.\n");
      return -1;
  }
  jogada(*cor,x,y);
  return 0;
}

canonical_original_code:
int executaJogada(char *args, char *cor) {
  char buf[1024];
  int x; int y;
  int nargs = sscanf(args, "%d %d %[^\n]", &x, &y, buf);
  if(nargs != 2) {
      fprintf(stderr, "Comando inválido, está a passar um número de argumentos invalido ou de forma inválida, para mais informações consulte a ajuda.\n");
      return -1;
  }
  jogada(*cor,x,y);
  return 0;
}

variable_types:
args
char *

variable_types:
cor
char *

variable_types:
buf
char [1024]

variable_types: nargs int


executaCriaJogo

decompiled_code:
__int64 __fastcall executaCriaJogo(const char *a1)
{
__int64 result; // rax
char v2[1096]; // [rsp+0h] [rbp-448h] BYREF

if ( strlen(a1) > 0x32 )
{
fwrite(&unk_D58, 1uLL, 0x75uLL, stderr);
result = 0LL;
}
else if ( (unsigned int)_isoc99_sscanf(a1, "%s %[^\n]", v2, &v2[64]) == 1 )
{
strcat(v2, ".ltr");
criarTabuleiro(v2);
result = 0LL;
}
else
{
fwrite(&unk_DD0, 1uLL, 0x85uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
__int64 result; // rax
char v2[1096]; // [rsp+0h] [rbp-448h] BYREF

if ( strlen(a1) > 0x32 )
{
fwrite(&unk_D58, 1uLL, 0x75uLL, stderr);
result = 0LL;
}
else if ( (unsigned int)_isoc99_sscanf(a1, "%s %[^\n]", v2, &v2[64]) == 1 )
{
strcat(v2, ".ltr");
func3(v2);
result = 0LL;
}
else
{
fwrite(&unk_DD0, 1uLL, 0x85uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int executaCriaJogo(char *args) {
 char buf[1024];
 char nome[55];
 if(strlen(args)>50){
  fprintf(stderr,"Nome do ficheiro que pretende abrir é demasiado grande, apenas pode carregar ficheiros com nome até 50 caracteres.\n");
  return 0;
 }
  int nargs = sscanf(args, "%s %[^\n]", nome, buf);
  if(nargs != 1) {
      fprintf(stderr, "Comando inválido, está a passar um número de argumentos inválido ou de forma inválida, para mais informaçoes consulte a ajuda.\n");
      return -1;
  }
 strcat(nome,".ltr");
 criarTabuleiro(nome);
  return 0;
}

variable_types:
nome
char [55]


executaGravaJogo

decompiled_code:
__int64 __fastcall executaGravaJogo(const char *a1)
{
__int64 result; // rax
char v2[1096]; // [rsp+0h] [rbp-448h] BYREF

if ( strlen(a1) > 0x32 )
{
fwrite(&unk_E58, 1uLL, 0x68uLL, stderr);
result = 0LL;
}
else if ( (unsigned int)_isoc99_sscanf(a1, "%s %[^\n]", v2, &v2[64]) == 1 )
{
if ( Tab )
{
strcat(v2, ".ltr");
gravaJogo(v2);
}
else
{
puts(aAindaN);
}
result = 0LL;
}
else
{
fwrite(&unk_EC8, 1uLL, 0x6DuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
__int64 result; // rax
char v2[1096]; // [rsp+0h] [rbp-448h] BYREF

if ( strlen(a1) > 0x32 )
{
fwrite(&unk_E58, 1uLL, 0x68uLL, stderr);
result = 0LL;
}
else if ( (unsigned int)_isoc99_sscanf(a1, "%s %[^\n]", v2, &v2[64]) == 1 )
{
if ( Tab )
{
strcat(v2, ".ltr");
func7(v2);
}
else
{
puts(aAindaN);
}
result = 0LL;
}
else
{
fwrite(&unk_EC8, 1uLL, 0x6DuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int executaGravaJogo(char *args) {
 char buf[1024];
 char nome[55];
 if(strlen(args)>50){
  fprintf(stderr,"Nome que pretende gravar é demasiado grande, o nome do ficheiro apenas pode conter até 50 caracteres.\n");
  return 0;
 }
  int nargs = sscanf(args, "%s %[^\n]", nome, buf);
  if(nargs != 1) {
      fprintf(stderr, "Comando inválido, está a passar um número errado de argumentos, consulte a ajuda para mais informações.\n");
      return -1;
  }
 if(Tab){
  strcat(nome,".ltr");
  gravaJogo(nome);
 }
 else printf("Ainda não abriu nenhum jogo para poder gravar.\n");
  return 0;
}


decompiled_code:
__int64 __fastcall executa_comando(__int64 a1)
{
__int16 v2; // [rsp+0h] [rbp-828h] BYREF
char v3; // [rsp+2h] [rbp-826h]
char v4[1048]; // [rsp+410h] [rbp-418h] BYREF

_isoc99_sscanf(a1, "%s %[^\n]", &v2, v4);
if ( v2 == 98 || v2 == 112 || v2 == 105 )
return executaJogada((__int64)v4, (char *)&v2);
if ( v2 == 29283 && !v3 )
return executaCriaJogo(v4);
if ( v2 == 29287 && !v3 )
return executaGravaJogo(v4);
if ( v2 == 63 )
return ajuda();
if ( v2 == 113 )
exit(1);
fwrite(&unk_F68, 1uLL, 0x46uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int executa_comando(char *linha) {
  char cmd[1025];
  char args[1025];
 sscanf(linha, "%s %[^\n]", cmd, args);
 if(strcmp(cmd, "b") == 0 || strcmp(cmd, "p") == 0 || strcmp(cmd, "i") == 0)
  return executaJogada(args,cmd);
 if(strcmp(cmd, "cr") == 0)
  return executaCriaJogo(args);
 if(strcmp(cmd,"gr")==0)
  return executaGravaJogo(args);
 if(strcmp(cmd,"?")==0)
  return ajuda();
 if(strcmp(cmd,"q")==0)
  exit(1);
 fprintf(stderr, "Comando inválido, para saber quais os comados suportados digite:  ? \n");
 return -1;
}

variable_types:
linha
char *

variable_types:
cmd
char [1025]

variable_types:
args
char [1025]


ajuda

decompiled_code:
__int64 ajuda()
{
puts("Imprimir ficheiro de ajuda.");
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
puts("Imprimir ficheiro de ajuda.");
return 0LL;
}

original_code:
int ajuda(){
 printf("Imprimir ficheiro de ajuda.\n");
return 0;
}


decompiled_code:
__int64 __fastcall mensagem_de_erro(unsigned int a1)
{
fprintf(stderr, "%s: %s\n", erro[2 * (int)a1], off_1E8[2 * (int)a1]);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
fprintf(stderr, "%s: %s\n", erro[2 * (int)a1], off_1E8[2 * (int)a1]);
return a1;
}

original_code:
int mensagem_de_erro(int erro_num) {
        (void) fprintf(stderr, "%s: %s\n", erro[erro_num].err_code, erro[erro_num].mensagem);
        return erro_num;
}


freeTab

decompiled_code:
void __fastcall freeTab(int *a1, void **a2)
{
_QWORD *v3; // rdi
__int64 v4; // rbx
void *v5; // rdi

v3 = *a2;
if ( *a2 )
{
if ( *a1 > 0 )
{
v4 = 0LL;
do
{
v5 = (void *)v3[v4++];
free(v5);
v3 = *a2;
}
while ( *a1 > (int)v4 );
}
free(v3);
*a2 = 0LL;
}
}

canonical_original_code:
void freeTab(){
 int i;
 for (i=0;i<DIM;i++) {
  free(Tab[i]);
  }
 free(Tab);
 Tab=((void *)0);
}


printTabuleiro

decompiled_code:
int __fastcall printTabuleiro(int *a1, _QWORD *a2)
{
__int64 v3; // r13
__int64 v4; // rsi
__int64 v5; // rbx
char *v6; // rdx
char v7; // al
int result; // eax
int v9; // ebx
__int64 v10; // rsi

if ( *a1 > 0 )
{
v3 = 0LL;
while ( 1 )
{
v4 = (unsigned int)(v3 + 1);
if ( (unsigned int)v4 > 9 )
printf("%d ", v4);
else
printf("%d ", v4);
v5 = 0LL;
if ( *a1 > 0 )
break;
LABEL_13:
++v3;
putchar(10);
if ( *a1 <= (int)v3 )
goto LABEL_14;
}
while ( 1 )
{
while ( 1 )
{
v6 = (char *)(*(_QWORD *)(*a2 + 8 * v3) + 2 * v5);
v7 = v6[1];
if ( v7 != 105 )
break;
printf("\x1B[44;33m %c \x1B[0m", (unsigned int)*v6);
LABEL_9:
if ( *a1 <= (int)++v5 )
goto LABEL_13;
}
if ( v7 != 112 )
{
if ( v7 == 98 )
printf("\x1B[47;31m %c \x1B[0m", (unsigned int)*v6);
goto LABEL_9;
}
++v5;
printf("\x1B[40;31m %c \x1B[0m", (unsigned int)*v6);
if ( *a1 <= (int)v5 )
goto LABEL_13;
}
}
LABEL_14:
printf(" ");
result = *a1;
if ( *a1 > 0 )
{
v9 = 1;
do
{
while ( 1 )
{
v10 = (unsigned int)v9;
if ( v9 > 9 )
break;
++v9;
result = printf(" %d", v10);
if ( *a1 < v9 )
return result;
}
++v9;
result = printf(" %d", v10);
}
while ( *a1 >= v9 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(int *a1, _QWORD *a2)
{
__int64 v3; // r13
__int64 v4; // rsi
__int64 v5; // rbx
char *v6; // rdx
char v7; // al
int result; // eax
int v9; // ebx
__int64 v10; // rsi

if ( *a1 > 0 )
{
v3 = 0LL;
while ( 1 )
{
v4 = (unsigned int)(v3 + 1);
if ( (unsigned int)v4 > 9 )
printf("%d ", v4);
else
printf("%d ", v4);
v5 = 0LL;
if ( *a1 > 0 )
break;
LABEL_13:
++v3;
putchar(10);
if ( *a1 <= (int)v3 )
goto LABEL_14;
}
while ( 1 )
{
while ( 1 )
{
v6 = (char *)(*(_QWORD *)(*a2 + 8 * v3) + 2 * v5);
v7 = v6[1];
if ( v7 != 105 )
break;
printf("\x1B[44;33m %c \x1B[0m", (unsigned int)*v6);
LABEL_9:
if ( *a1 <= (int)++v5 )
goto LABEL_13;
}
if ( v7 != 112 )
{
if ( v7 == 98 )
printf("\x1B[47;31m %c \x1B[0m", (unsigned int)*v6);
goto LABEL_9;
}
++v5;
printf("\x1B[40;31m %c \x1B[0m", (unsigned int)*v6);
if ( *a1 <= (int)v5 )
goto LABEL_13;
}
}
LABEL_14:
printf(" ");
result = *a1;
if ( *a1 > 0 )
{
v9 = 1;
do
{
while ( 1 )
{
v10 = (unsigned int)v9;
if ( v9 > 9 )
break;
++v9;
result = printf(" %d", v10);
if ( *a1 < v9 )
return result;
}
++v9;
result = printf(" %d", v10);
}
while ( *a1 >= v9 );
}
return result;
}

variable_types: j int


repo: pimms/pang

decompiled_code:
__int64 __fastcall opcode_split(char a1, _BYTE *a2, _BYTE *a3)
{
char v3; // al
__int64 result; // rax

v3 = a1 & 0xC0;
if ( (a1 & 0xC0) != 0 )
{
if ( v3 == (char)0x80 )
{
*a2 = a1;
result = 0LL;
*a3 = 0;
}
else if ( v3 == -64 )
{
*a2 = a1 & 0xFC;
result = 0LL;
*a3 = a1 & 3;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
*a2 = a1 & 0xF0;
result = 0LL;
*a3 = a1 & 0xF;
}
return result;
}

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

v3 = a1 & 0xC0;
if ( (a1 & 0xC0) != 0 )
{
if ( v3 == (char)0x80 )
{
*a2 = a1;
result = 0LL;
*a3 = 0;
}
else if ( v3 == -64 )
{
*a2 = a1 & 0xFC;
result = 0LL;
*a3 = a1 & 3;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
*a2 = a1 & 0xF0;
result = 0LL;
*a3 = a1 & 0xF;
}
return result;
}

original_code:
int
opcode_split(uint8 op, uint8 *body, uint8 *arg)
{
 uint8 head = op & 0xC0;
 if (head == 0x00) {
  *body = op & 0xF0;
  *arg = op & 0x0F;
 } else if (head == 0x80) {
  *body = op & 0xFF;
  *arg = 0;
 } else if (head == 0xC0) {
  *body = op & 0xFC;
  *arg = op & 0x03;
 } else {
  return -1;
 }
 return 0;
}

canonical_original_code:
int opcode_split(unsigned char op, unsigned char *body, unsigned char *arg)
{
 unsigned char head = op & 0xC0;
 if (head == 0x00) {
  *body = op & 0xF0;
  *arg = op & 0x0F;
 } else if (head == 0x80) {
  *body = op & 0xFF;
  *arg = 0;
 } else if (head == 0xC0) {
  *body = op & 0xFC;
  *arg = op & 0x03;
 } else {
  return -1;
 }
 return 0;
}

variable_types:
op
unsigned char

variable_types:
body
unsigned char *

variable_types:
arg
unsigned char *

variable_types:
head
unsigned char


arglen

decompiled_code:
__int64 __fastcall arglen(char a1)
{
char v1; // cl
char v2; // r8
__int64 result; // rax
char v4; // [rsp+Eh] [rbp-2h] BYREF
char v5; // [rsp+Fh] [rbp-1h] BYREF

opcode_split(a1, &v4, &v5);
result = 0LL;
if ( v2 )
{
if ( v2 == -64 )
result = v5 == 0 ? 1 : 4;
}
else if ( (v1 & 0xE0) != 0 )
{
if ( (v1 & 0xF0) == 32 )
result = (v1 & 8) == 0 ? 1 : 4;
else
result = 4 * (unsigned int)((v1 & 0xF0) == 48);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
char v1; // cl
char v2; // r8
__int64 result; // rax
char v4; // [rsp+Eh] [rbp-2h] BYREF
char v5; // [rsp+Fh] [rbp-1h] BYREF

func1(a1, &v4, &v5);
result = 0LL;
if ( v2 )
{
if ( v2 == -64 )
result = v5 == 0 ? 1 : 4;
}
else if ( (v1 & 0xE0) != 0 )
{
if ( (v1 & 0xF0) == 32 )
result = (v1 & 8) == 0 ? 1 : 4;
else
result = 4 * (unsigned int)((v1 & 0xF0) == 48);
}
return result;
}

original_code:
uint
arglen(uint8 op)
{
 uint8 head = op & 0xC0;
 uint8 body, arg;
 opcode_split(op, &body, &arg);
 if (head == 0x00) {
  if ((op & 0xF0) == 0x00) {
   return 0;
  } else if ((op & 0xF0) == 0x10) {
   return 0;
  } else if ((op & 0xF0) == 0x20) {
   if (op & 0x08) {
    return 4;
   }
   return 1;
  } else if ((op & 0xF0) == 0x30) {
   return 4;
  }
 } else if (head == 0x80) {
  return 0;
 } else if (head == 0xC0) {
  if (arg == 0x00) {
   return 1;
  }
  return 4;
 }
 return 0;
}

canonical_original_code:
unsigned int arglen(unsigned char op)
{
 unsigned char head = op & 0xC0;
 unsigned char body; unsigned char arg;
 opcode_split(op, &body, &arg);
 if (head == 0x00) {
  if ((op & 0xF0) == 0x00) {
   return 0;
  } else if ((op & 0xF0) == 0x10) {
   return 0;
  } else if ((op & 0xF0) == 0x20) {
   if (op & 0x08) {
    return 4;
   }
   return 1;
  } else if ((op & 0xF0) == 0x30) {
   return 4;
  }
 } else if (head == 0x80) {
  return 0;
 } else if (head == 0xC0) {
  if (arg == 0x00) {
   return 1;
  }
  return 4;
 }
 return 0;
}

variable_types:
body
unsigned char

variable_types:
arg
unsigned char

return_type: unsigned int


decompiled_code:
void *regs_create()
{
return calloc(0x20uLL, 1uLL);
}

canonical_decompiled_code:
void *func3()
{
return calloc(0x20uLL, 1uLL);
}

original_code:
struct regs*
regs_create()
{
 struct regs *regs = (struct regs*)malloc(sizeof(struct regs));
 memset(regs, 0, sizeof(struct regs));
 return regs;
}

canonical_original_code:
struct regs *regs_create()
{
 struct regs *regs = (struct regs*)malloc(sizeof(struct regs));
 memset(regs, 0, sizeof(struct regs));
 return regs;
}

variable_types: struct regs { int r_ip; int r_bp; int r_sp; int r_a; int r_b; int r_c; int r_d; int r_res; } *


decompiled_code:
// attributes: thunk
void regs_destroy(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func4(void *ptr)
{
free(ptr);
}

original_code:
void
regs_destroy(struct regs *env)
{
 free(env);
}

user_defined_types: struct regs { int r_ip; int r_bp; int r_sp; int r_a; int r_b; int r_c; int r_d; int r_res; }


decompiled_code:
_DWORD *memory_create()
{
_DWORD *v0; // rax
_DWORD *v1; // r12

v0 = malloc(0x10uLL);
v0[2] = 1024;
v1 = v0;
*(_QWORD *)v0 = malloc(0x400uLL);
return v1;
}

canonical_decompiled_code:
_DWORD *func5()
{
_DWORD *v0; // rax
_DWORD *v1; // r12

v0 = malloc(0x10uLL);
v0[2] = 1024;
v1 = v0;
*(_QWORD *)v0 = malloc(0x400uLL);
return v1;
}

original_code:
struct memory*
memory_create()
{
 struct memory *memory;
 memory = (struct memory*)malloc(sizeof(struct memory));
 memory->len = 1024;
 memory->data = malloc(memory->len);
 return memory;
}

canonical_original_code:
struct memory *memory_create()
{
 struct memory *memory;
 memory = (struct memory *)malloc(sizeof(struct memory));
 memory->len = 1024;
 memory->data = malloc(memory->len);
 return memory;
}

variable_types: struct memory { void *data; unsigned int len; } *


decompiled_code:
void __fastcall memory_destroy(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void
memory_destroy(struct memory *memory)
{
 free(memory->data);
 free(memory);
}

user_defined_types: struct memory { void *data; unsigned int len; }


decompiled_code:
void *__fastcall memory_expand(__int64 a1)
{
size_t v1; // rsi
void *result; // rax

v1 = (unsigned int)(2 * *(_DWORD *)(a1 + 8));
*(_DWORD *)(a1 + 8) = v1;
result = realloc(*(void **)a1, v1);
*(_QWORD *)a1 = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1)
{
size_t v1; // rsi
void *result; // rax

v1 = (unsigned int)(2 * *(_DWORD *)(a1 + 8));
*(_DWORD *)(a1 + 8) = v1;
result = realloc(*(void **)a1, v1);
*(_QWORD *)a1 = result;
return result;
}

original_code:
void
memory_expand(struct memory *memory)
{
 memory->len *= 2;
 memory->data = realloc(memory->data, memory->len);
}


decompiled_code:
_QWORD *env_create()
{
_QWORD *v0; // r12

v0 = calloc(0x10uLL, 1uLL);
*v0 = regs_create();
v0[1] = memory_create();
return v0;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *v0; // r12

v0 = calloc(0x10uLL, 1uLL);
*v0 = func3();
v0[1] = func5();
return v0;
}

original_code:
struct env*
env_create()
{
 struct env *env;
 env = (struct env*)malloc(sizeof(struct env));
 memset(env, 0, sizeof(struct env));
 env->reg = regs_create();
 env->mem = memory_create();
 return env;
}

canonical_original_code:
struct env *env_create()
{
 struct env *env;
 env = (struct env *)malloc(sizeof(struct env));
 memset(env, 0, sizeof(struct env));
 env->reg = regs_create();
 env->mem = memory_create();
 return env;
}

variable_types: struct env { struct regs { int r_ip; int r_bp; int r_sp; int r_a; int r_b; int r_c; int r_d; int r_res; } *reg; struct memory { void *data; unsigned int len; } *mem; } *

user_defined_types: struct env { struct regs *reg; struct memory *mem; }


decompiled_code:
void __fastcall env_destroy(void *ptr)
{
regs_destroy(*(void **)ptr);
memory_destroy(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
func4(*(void **)ptr);
func6(*((void **)ptr + 1));
free(ptr);
}

original_code:
void
env_destroy(struct env *env)
{
 regs_destroy(env->reg);
 memory_destroy(env->mem);
 free(env);
}


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

switch ( a2 )
{
case 0:
result = *a1 + 12LL;
break;
case 1:
result = *a1 + 16LL;
break;
case 2:
result = *a1 + 20LL;
break;
case 3:
result = *a1 + 24LL;
break;
case 5:
result = *a1 + 8LL;
break;
case 6:
result = *a1 + 4LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a2 )
{
case 0:
result = *a1 + 12LL;
break;
case 1:
result = *a1 + 16LL;
break;
case 2:
result = *a1 + 20LL;
break;
case 3:
result = *a1 + 24LL;
break;
case 5:
result = *a1 + 8LL;
break;
case 6:
result = *a1 + 4LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int*
env_get_reg(struct env *env, uint8 reg)
{
 switch (reg) {
  case 0x00: return &env->reg->r_a;
  case 0x01: return &env->reg->r_b;
  case 0x02: return &env->reg->r_c;
  case 0x03: return &env->reg->r_d;
  case 0x06: return &env->reg->r_bp;
  case 0x05: return &env->reg->r_sp;
 }
 return ((void *)0);
}

canonical_original_code:
int *env_get_reg(struct env *env, unsigned char reg)
{
 switch (reg) {
  case 0x00: return &env->reg->r_a;
  case 0x01: return &env->reg->r_b;
  case 0x02: return &env->reg->r_c;
  case 0x03: return &env->reg->r_d;
  case 0x06: return &env->reg->r_bp;
  case 0x05: return &env->reg->r_sp;
 }
 return ((void *)0);
}

variable_types:
reg
unsigned char

return_type: int *


decompiled_code:
__int64 __fastcall env_get_int(__int64 a1, unsigned int a2)
{
__int64 v2; // rcx
char v4[136]; // [rsp-88h] [rbp-88h] BYREF

v2 = *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)(v2 + 8) + 4 > a2 )
return *(_QWORD *)v2 + 4LL * a2;
sprintf(v4, "Attempting to read address %u", a2);
panglog(0LL, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2)
{
__int64 v2; // rcx
char v4[136]; // [rsp-88h] [rbp-88h] BYREF

v2 = *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)(v2 + 8) + 4 > a2 )
return *(_QWORD *)v2 + 4LL * a2;
sprintf(v4, "Attempting to read address %u", a2);
panglog(0LL, v4);
return 0LL;
}

original_code:
int*
env_get_int(struct env *env, uint addr)
{
 if (env->mem->len + 4 > addr) {
  return (int*)env->mem->data + addr;
 }
 char str[128];
 sprintf(str, "Attempting to read address %u", addr);
 panglog(0, str);
 return ((void *)0);
}

canonical_original_code:
int *env_get_int(struct env *env, unsigned int addr)
{
 if (env->mem->len + 4 > addr) {
  return (int *)env->mem->data + addr;
 }
 char str[128];
 sprintf(str, "Attempting to read address %u", addr);
 panglog(0, str);
 return ((void *)0);
}

variable_types:
addr
unsigned int

variable_types:
str
char [128]


decompiled_code:
void op_call()
{
;
}

canonical_decompiled_code:
void func14()
{
;
}

original_code:
void op_call(struct env *env, uint8 op, const void *exarg)
{
}

canonical_original_code:
void op_call(struct env *env, unsigned char op, void *exarg)
{
}

variable_types:
exarg
void *


decompiled_code:
void op_ret()
{
;
}

canonical_decompiled_code:
void func15()
{
;
}

original_code:
void op_ret(struct env *env, uint8 op, const void *exarg)
{
}

canonical_original_code:
void op_ret(struct env *env, unsigned char op, void *exarg)
{
}


decompiled_code:
__int64 __fastcall arit_cmp_get_ext(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

if ( !a2 )
return env_get_reg(a1, *a3);
if ( a2 == 1 )
return env_get_int((__int64)a1, *(_DWORD *)a3);
result = (__int64)a3;
if ( a2 != 3 )
{
panglog(0LL, "Unable to resolve argument type for arit_cmp instruction");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

if ( !a2 )
return func10(a1, *a3);
if ( a2 == 1 )
return func11((__int64)a1, *(_DWORD *)a3);
result = (__int64)a3;
if ( a2 != 3 )
{
panglog(0LL, "Unable to resolve argument type for arit_cmp instruction");
result = 0LL;
}
return result;
}

original_code:
const int*
arit_cmp_get_ext(struct env *env, uint8 argtype, const void *arg)
{
 if (argtype == 0x00) {
  return env_get_reg(env, *(uint8*)arg);
 }
 if (argtype == 0x01) {
  return env_get_int(env, *(int*)arg);
 }
 if (argtype == 0x03) {
  return (int*)arg;
 }
 if (argtype == 0x02) {
 }
 panglog(0, "Unable to resolve argument type "
       "for arit_cmp instruction");
 return ((void *)0);
}

canonical_original_code:
int *arit_cmp_get_ext(struct env *env, unsigned char argtype, void *arg)
{
 if (argtype == 0x00) {
  return env_get_reg(env, *(unsigned char *)arg);
 }
 if (argtype == 0x01) {
  return env_get_int(env, *(int *)arg);
 }
 if (argtype == 0x03) {
  return (int *)arg;
 }
 if (argtype == 0x02) {
 }
 panglog(0, "Unable to resolve argument type "
       "for arit_cmp instruction");
 return ((void *)0);
}

variable_types:
argtype
unsigned char

variable_types:
arg
void *


decompiled_code:
__int64 __fastcall op_add(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
result = *(unsigned int *)result;
*(_DWORD *)(*a1 + 12LL) += result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = func16(a1, a2 & 3, a3);
if ( result )
{
result = *(unsigned int *)result;
*(_DWORD *)(*a1 + 12LL) += result;
}
return result;
}

original_code:
void op_add(struct env *env, uint8 op, const void *exarg)
{
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_a += *ext;
 }
}

canonical_original_code:
void op_add(struct env *env, unsigned char op, void *exarg)
{
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_a += *ext;
 }
}

variable_types:
ext
int *


decompiled_code:
__int64 __fastcall op_sub(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
result = *(unsigned int *)result;
*(_DWORD *)(*a1 + 12LL) -= result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = func16(a1, a2 & 3, a3);
if ( result )
{
result = *(unsigned int *)result;
*(_DWORD *)(*a1 + 12LL) -= result;
}
return result;
}

original_code:
void op_sub(struct env *env, uint8 op, const void *exarg)
{
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_a -= *ext;
 }
}

canonical_original_code:
void op_sub(struct env *env, unsigned char op, void *exarg)
{
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_a -= *ext;
 }
}


decompiled_code:
__int64 __fastcall op_div(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
result = (unsigned int)(*(_DWORD *)(*a1 + 12LL) / *(_DWORD *)result);
*(_DWORD *)(*a1 + 12LL) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = func16(a1, a2 & 3, a3);
if ( result )
{
result = (unsigned int)(*(_DWORD *)(*a1 + 12LL) / *(_DWORD *)result);
*(_DWORD *)(*a1 + 12LL) = result;
}
return result;
}

original_code:
void op_div(struct env *env, uint8 op, const void *exarg)
{
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_a /= *ext;
 }
}

canonical_original_code:
void op_div(struct env *env, unsigned char op, void *exarg)
{
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_a /= *ext;
 }
}


decompiled_code:
__int64 __fastcall op_mod(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax
int v4; // edx

result = arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
v4 = *(_DWORD *)(*a1 + 12LL) % *(_DWORD *)result;
result = (unsigned int)(*(_DWORD *)(*a1 + 12LL) / *(_DWORD *)result);
*(_DWORD *)(*a1 + 12LL) = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax
int v4; // edx

result = func16(a1, a2 & 3, a3);
if ( result )
{
v4 = *(_DWORD *)(*a1 + 12LL) % *(_DWORD *)result;
result = (unsigned int)(*(_DWORD *)(*a1 + 12LL) / *(_DWORD *)result);
*(_DWORD *)(*a1 + 12LL) = v4;
}
return result;
}

original_code:
void op_mod(struct env *env, uint8 op, const void *exarg)
{
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_a %= *ext;
 }
}

canonical_original_code:
void op_mod(struct env *env, unsigned char op, void *exarg)
{
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_a %= *ext;
 }
}


decompiled_code:
__int64 __fastcall op_xor(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
result = *(unsigned int *)result;
*(_DWORD *)(*a1 + 12LL) ^= result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = func16(a1, a2 & 3, a3);
if ( result )
{
result = *(unsigned int *)result;
*(_DWORD *)(*a1 + 12LL) ^= result;
}
return result;
}

original_code:
void op_xor(struct env *env, uint8 op, const void *exarg)
{
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_a ^= *ext;
 }
}

canonical_original_code:
void op_xor(struct env *env, unsigned char op, void *exarg)
{
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_a ^= *ext;
 }
}


decompiled_code:
__int64 __fastcall op_and(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
result = *(unsigned int *)result;
*(_DWORD *)(*a1 + 12LL) &= result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = func16(a1, a2 & 3, a3);
if ( result )
{
result = *(unsigned int *)result;
*(_DWORD *)(*a1 + 12LL) &= result;
}
return result;
}

original_code:
void op_and(struct env *env, uint8 op, const void *exarg)
{
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_a &= *ext;
 }
}

canonical_original_code:
void op_and(struct env *env, unsigned char op, void *exarg)
{
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_a &= *ext;
 }
}


decompiled_code:
__int64 __fastcall op_cmp(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax
__int64 v4; // rdx

*(_DWORD *)(*a1 + 28LL) = 0;
result = arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
v4 = *a1;
result = *(unsigned int *)result;
if ( *(_DWORD *)(*a1 + 12LL) >= (int)result )
{
if ( *(_DWORD *)(*a1 + 12LL) > (int)result )
{
*(_DWORD *)(v4 + 28) |= 4u;
}
else if ( *(_DWORD *)(*a1 + 12LL) == (_DWORD)result )
{
*(_DWORD *)(v4 + 28) |= 1u;
}
}
else
{
*(_DWORD *)(v4 + 28) |= 2u;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax
__int64 v4; // rdx

*(_DWORD *)(*a1 + 28LL) = 0;
result = func16(a1, a2 & 3, a3);
if ( result )
{
v4 = *a1;
result = *(unsigned int *)result;
if ( *(_DWORD *)(*a1 + 12LL) >= (int)result )
{
if ( *(_DWORD *)(*a1 + 12LL) > (int)result )
{
*(_DWORD *)(v4 + 28) |= 4u;
}
else if ( *(_DWORD *)(*a1 + 12LL) == (_DWORD)result )
{
*(_DWORD *)(v4 + 28) |= 1u;
}
}
else
{
*(_DWORD *)(v4 + 28) |= 2u;
}
}
return result;
}

original_code:
void op_cmp(struct env *env, uint8 op, const void *exarg)
{
 env->reg->r_res = 0;
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (env->reg->r_a < *ext) {
   env->reg->r_res |= 0x02;
  } else if (env->reg->r_a > *ext) {
   env->reg->r_res |= 0x04;
  } else if (env->reg->r_a == *ext) {
   env->reg->r_res |= 0x01;
  }
 }
}

canonical_original_code:
void op_cmp(struct env *env, unsigned char op, void *exarg)
{
 env->reg->r_res = 0;
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (env->reg->r_a < *ext) {
   env->reg->r_res |= 0x02;
  } else if (env->reg->r_a > *ext) {
   env->reg->r_res |= 0x04;
  } else if (env->reg->r_a == *ext) {
   env->reg->r_res |= 0x01;
  }
 }
}


decompiled_code:
int *__fastcall op_jmp(int **a1, char a2, char *a3)
{
int *result; // rax
int v4; // edx

result = (int *)arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
v4 = *result;
result = *a1;
**a1 = v4;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func24(int **a1, char a2, char *a3)
{
int *result; // rax
int v4; // edx

result = (int *)func16(a1, a2 & 3, a3);
if ( result )
{
v4 = *result;
result = *a1;
**a1 = v4;
}
return result;
}

original_code:
void op_jmp(struct env *env, uint8 op, const void *exarg)
{
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_ip = *ext;
 }
}

canonical_original_code:
void op_jmp(struct env *env, unsigned char op, void *exarg)
{
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  env->reg->r_ip = *ext;
 }
}


decompiled_code:
__int64 __fastcall op_je(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
if ( (*(_BYTE *)(*a1 + 28LL) & 1) != 0 )
{
result = *(unsigned int *)result;
*(_DWORD *)*a1 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func25(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = func16(a1, a2 & 3, a3);
if ( result )
{
if ( (*(_BYTE *)(*a1 + 28LL) & 1) != 0 )
{
result = *(unsigned int *)result;
*(_DWORD *)*a1 = result;
}
}
return result;
}

original_code:
void op_je(struct env *env, uint8 op, const void *exarg)
{
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (env->reg->r_res & 0x01) {
   env->reg->r_ip = *ext;
  }
 }
}

canonical_original_code:
void op_je(struct env *env, unsigned char op, void *exarg)
{
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (env->reg->r_res & 0x01) {
   env->reg->r_ip = *ext;
  }
 }
}


decompiled_code:
__int64 __fastcall op_jne(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
if ( (*(_BYTE *)(*a1 + 28LL) & 1) == 0 )
{
result = *(unsigned int *)result;
*(_DWORD *)*a1 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func26(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = func16(a1, a2 & 3, a3);
if ( result )
{
if ( (*(_BYTE *)(*a1 + 28LL) & 1) == 0 )
{
result = *(unsigned int *)result;
*(_DWORD *)*a1 = result;
}
}
return result;
}

original_code:
void op_jne(struct env *env, uint8 op, const void *exarg)
{
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (!(env->reg->r_res & 0x01)) {
   env->reg->r_ip = *ext;
  }
 }
}

canonical_original_code:
void op_jne(struct env *env, unsigned char op, void *exarg)
{
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (!(env->reg->r_res & 0x01)) {
   env->reg->r_ip = *ext;
  }
 }
}


decompiled_code:
__int64 __fastcall op_jl(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
if ( (*(_BYTE *)(*a1 + 28LL) & 2) != 0 )
{
result = *(unsigned int *)result;
*(_DWORD *)*a1 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func27(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = func16(a1, a2 & 3, a3);
if ( result )
{
if ( (*(_BYTE *)(*a1 + 28LL) & 2) != 0 )
{
result = *(unsigned int *)result;
*(_DWORD *)*a1 = result;
}
}
return result;
}

original_code:
void op_jl(struct env *env, uint8 op, const void *exarg)
{
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (env->reg->r_res & 0x02) {
   env->reg->r_ip = *ext;
  }
 }
}

canonical_original_code:
void op_jl(struct env *env, unsigned char op, void *exarg)
{
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (env->reg->r_res & 0x02) {
   env->reg->r_ip = *ext;
  }
 }
}


decompiled_code:
__int64 __fastcall op_jle(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
if ( (*(_BYTE *)(*a1 + 28LL) & 3) != 0 )
{
result = *(unsigned int *)result;
*(_DWORD *)*a1 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func28(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = func16(a1, a2 & 3, a3);
if ( result )
{
if ( (*(_BYTE *)(*a1 + 28LL) & 3) != 0 )
{
result = *(unsigned int *)result;
*(_DWORD *)*a1 = result;
}
}
return result;
}

original_code:
void op_jle(struct env *env, uint8 op, const void *exarg)
{
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (env->reg->r_res & (0x02|0x01)) {
   env->reg->r_ip = *ext;
  }
 }
}

canonical_original_code:
void op_jle(struct env *env, unsigned char op, void *exarg)
{
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (env->reg->r_res & (0x02|0x01)) {
   env->reg->r_ip = *ext;
  }
 }
}


decompiled_code:
__int64 __fastcall op_jg(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
if ( (*(_BYTE *)(*a1 + 28LL) & 4) != 0 )
{
result = *(unsigned int *)result;
*(_DWORD *)*a1 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func29(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = func16(a1, a2 & 3, a3);
if ( result )
{
if ( (*(_BYTE *)(*a1 + 28LL) & 4) != 0 )
{
result = *(unsigned int *)result;
*(_DWORD *)*a1 = result;
}
}
return result;
}

original_code:
void op_jg(struct env *env, uint8 op, const void *exarg)
{
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (env->reg->r_res & 0x04) {
   env->reg->r_ip = *ext;
  }
 }
}

canonical_original_code:
void op_jg(struct env *env, unsigned char op, void *exarg)
{
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (env->reg->r_res & 0x04) {
   env->reg->r_ip = *ext;
  }
 }
}


decompiled_code:
__int64 __fastcall op_jge(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = arit_cmp_get_ext(a1, a2 & 3, a3);
if ( result )
{
if ( (*(_BYTE *)(*a1 + 28LL) & 5) != 0 )
{
result = *(unsigned int *)result;
*(_DWORD *)*a1 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func30(_QWORD *a1, char a2, char *a3)
{
__int64 result; // rax

result = func16(a1, a2 & 3, a3);
if ( result )
{
if ( (*(_BYTE *)(*a1 + 28LL) & 5) != 0 )
{
result = *(unsigned int *)result;
*(_DWORD *)*a1 = result;
}
}
return result;
}

original_code:
void op_jge(struct env *env, uint8 op, const void *exarg)
{
 const int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (env->reg->r_res & (0x04|0x01)) {
   env->reg->r_ip = *ext;
  }
 }
}

canonical_original_code:
void op_jge(struct env *env, unsigned char op, void *exarg)
{
 int *ext = arit_cmp_get_ext(
  env, (op & 0x03), exarg);
 if (ext) {
  if (env->reg->r_res & (0x04|0x01)) {
   env->reg->r_ip = *ext;
  }
 }
}


decompiled_code:
__int64 __fastcall execute_op(int **a1, __int64 a2)
{
__int64 v2; // rdx
char v3; // r10
char *v4; // r9
char v5; // r10
__int64 result; // rax
unsigned __int8 v7; // [rsp+Eh] [rbp-1Ah] BYREF
char v8[25]; // [rsp+Fh] [rbp-19h] BYREF

dbg_registers(*a1);
dbg_opcode(a2, (unsigned int)**a1);
v2 = **a1;
**a1 = v2 + 1;
**a1 += arglen(*(_BYTE *)(a2 + v2));
opcode_split(v3, &v7, v8);
result = v7;
if ( v7 <= 0xF8u )
{
if ( v7 <= 0xBFu )
{
if ( v7 == 32 )
{
result = op_mov(a1, v5);
}
else if ( v7 <= 0x20u )
{
if ( v7 )
{
if ( v7 == 16 )
result = op_pop(a1, v5);
}
else
{
result = (__int64)op_push(a1, v5);
}
}
else if ( v7 == 48 )
{
result = (__int64)op_mov_l(a1, v5);
}
}
else
{
result = (unsigned __int8)(v7 + 64);
switch ( v7 )
{
case 0xC0:
result = op_add(a1, v5, v4);
break;
case 0xC4:
result = op_sub(a1, v5, v4);
break;
case 0xC8:
result = (__int64)op_mul(a1, v5, v4);
break;
case 0xCC:
result = op_div(a1, v5, v4);
break;
case 0xD0:
result = op_mod(a1, v5, v4);
break;
case 0xD4:
result = op_xor(a1, v5, v4);
break;
case 0xD8:
result = op_and(a1, v5, v4);
break;
case 0xDC:
result = op_cmp(a1, v5, v4);
break;
case 0xE0:
result = (__int64)op_jmp(a1, v5, v4);
break;
case 0xE4:
result = op_je(a1, v5, v4);
break;
case 0xE8:
result = op_jne(a1, v5, v4);
break;
case 0xEC:
result = op_jl(a1, v5, v4);
break;
case 0xF0:
result = op_jle(a1, v5, v4);
break;
case 0xF4:
result = op_jg(a1, v5, v4);
break;
case 0xF8:
result = op_jge(a1, v5, v4);
break;
default:
return result;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func31(int **a1, __int64 a2)
{
__int64 v2; // rdx
char v3; // r10
char *v4; // r9
char v5; // r10
__int64 result; // rax
unsigned __int8 v7; // [rsp+Eh] [rbp-1Ah] BYREF
char v8[25]; // [rsp+Fh] [rbp-19h] BYREF

dbg_registers(*a1);
dbg_opcode(a2, (unsigned int)**a1);
v2 = **a1;
**a1 = v2 + 1;
**a1 += func2(*(_BYTE *)(a2 + v2));
func1(v3, &v7, v8);
result = v7;
if ( v7 <= 0xF8u )
{
if ( v7 <= 0xBFu )
{
if ( v7 == 32 )
{
result = func13(a1, v5);
}
else if ( v7 <= 0x20u )
{
if ( v7 )
{
if ( v7 == 16 )
result = func12(a1, v5);
}
else
{
result = (__int64)op_push(a1, v5);
}
}
else if ( v7 == 48 )
{
result = (__int64)op_mov_l(a1, v5);
}
}
else
{
result = (unsigned __int8)(v7 + 64);
switch ( v7 )
{
case 0xC0:
result = func17(a1, v5, v4);
break;
case 0xC4:
result = func18(a1, v5, v4);
break;
case 0xC8:
result = (__int64)op_mul(a1, v5, v4);
break;
case 0xCC:
result = func19(a1, v5, v4);
break;
case 0xD0:
result = func20(a1, v5, v4);
break;
case 0xD4:
result = func21(a1, v5, v4);
break;
case 0xD8:
result = func22(a1, v5, v4);
break;
case 0xDC:
result = func23(a1, v5, v4);
break;
case 0xE0:
result = (__int64)func24(a1, v5, v4);
break;
case 0xE4:
result = func25(a1, v5, v4);
break;
case 0xE8:
result = func26(a1, v5, v4);
break;
case 0xEC:
result = func27(a1, v5, v4);
break;
case 0xF0:
result = func28(a1, v5, v4);
break;
case 0xF4:
result = func29(a1, v5, v4);
break;
case 0xF8:
result = func30(a1, v5, v4);
break;
default:
return result;
}
}
}
return result;
}

original_code:
static void
execute_op(struct env *env, const uint8 *ops)
{
 dbg_registers(env->reg);
 dbg_opcode(ops, env->reg->r_ip);
 uint8 op;
 uint8 body;
 uint8 arg;
 const void *exarg = ((void *)0);
 op = ops[env->reg->r_ip++];
 exarg = &ops[env->reg->r_ip];
 env->reg->r_ip += arglen(op);
 opcode_split(op, &body, &arg);
 switch (body) {
  case 0x00: op_push(env, op, exarg); break;
  case 0x10: op_pop(env, op, exarg); break;
  case 0x20: op_mov(env, op, exarg); break;
  case 0x30: op_mov_l(env, op, exarg); break;
  case 0x81: op_call(env, op, exarg); break;
  case 0x82: op_ret(env, op, exarg); break;
  case 0xC0: op_add(env, op, exarg); break;
  case 0xC4: op_sub(env, op, exarg); break;
  case 0xC8: op_mul(env, op, exarg); break;
  case 0xCC: op_div(env, op, exarg); break;
  case 0xD0: op_mod(env, op, exarg); break;
  case 0xD4: op_xor(env, op, exarg); break;
  case 0xD8: op_and(env, op, exarg); break;
  case 0xDC: op_cmp(env, op, exarg); break;
  case 0xE0: op_jmp(env, op, exarg); break;
  case 0xE4: op_je(env, op, exarg); break;
  case 0xE8: op_jne(env, op, exarg); break;
  case 0xEC: op_jl(env, op, exarg); break;
  case 0xF0: op_jle(env, op, exarg); break;
  case 0xF4: op_jg(env, op, exarg); break;
  case 0xF8: op_jge(env, op, exarg); break;
 }
}

canonical_original_code:
static void execute_op(struct env *env, unsigned char *ops)
{
 dbg_registers(env->reg);
 dbg_opcode(ops, env->reg->r_ip);
 unsigned char op;
 unsigned char body;
 unsigned char arg;
 void *exarg = ((void *)0);
 op = ops[env->reg->r_ip++];
 exarg = &ops[env->reg->r_ip];
 env->reg->r_ip += arglen(op);
 opcode_split(op, &body, &arg);
 switch (body) {
  case 0x00: op_push(env, op, exarg); break;
  case 0x10: op_pop(env, op, exarg); break;
  case 0x20: op_mov(env, op, exarg); break;
  case 0x30: op_mov_l(env, op, exarg); break;
  case 0x81: op_call(env, op, exarg); break;
  case 0x82: op_ret(env, op, exarg); break;
  case 0xC0: op_add(env, op, exarg); break;
  case 0xC4: op_sub(env, op, exarg); break;
  case 0xC8: op_mul(env, op, exarg); break;
  case 0xCC: op_div(env, op, exarg); break;
  case 0xD0: op_mod(env, op, exarg); break;
  case 0xD4: op_xor(env, op, exarg); break;
  case 0xD8: op_and(env, op, exarg); break;
  case 0xDC: op_cmp(env, op, exarg); break;
  case 0xE0: op_jmp(env, op, exarg); break;
  case 0xE4: op_je(env, op, exarg); break;
  case 0xE8: op_jne(env, op, exarg); break;
  case 0xEC: op_jl(env, op, exarg); break;
  case 0xF0: op_jle(env, op, exarg); break;
  case 0xF4: op_jg(env, op, exarg); break;
  case 0xF8: op_jge(env, op, exarg); break;
 }
}

variable_types:
ops
unsigned char *


execute

decompiled_code:
void __fastcall execute(unsigned int *a1, unsigned int a2)
{
int **v3; // rax
__int64 v4; // rsi
int **v5; // rbp

v3 = (int **)env_create();
v4 = *a1;
v5 = v3;
**v3 = v4;
printf("Starting at byte %u\n", v4);
while ( **v5 < a2 )
execute_op(v5, (__int64)a1);
env_destroy(v5);
}

canonical_decompiled_code:
void __fastcall func32(unsigned int *a1, unsigned int a2)
{
int **v3; // rax
__int64 v4; // rsi
int **v5; // rbp

v3 = (int **)func8();
v4 = *a1;
v5 = v3;
**v3 = v4;
printf("Starting at byte %u\n", v4);
while ( **v5 < a2 )
func31(v5, (__int64)a1);
func9(v5);
}

original_code:
void
execute(const uint8 *opcodes, uint len)
{
 struct env *env = env_create();
 env->reg->r_ip = *(uint*)opcodes;
 printf("Starting at byte %u\n", env->reg->r_ip);
 while (env->reg->r_ip < len) {
  execute_op(env, opcodes);
 }
 env_destroy(env);
}

canonical_original_code:
void execute(unsigned char *opcodes, unsigned int len)
{
 struct env *env = env_create();
 env->reg->r_ip = *(unsigned int *)opcodes;
 printf("Starting at byte %u\n", env->reg->r_ip);
 while (env->reg->r_ip < len) {
  execute_op(env, opcodes);
 }
 env_destroy(env);
}

variable_types:
opcodes
unsigned char *

variable_types:
len
unsigned int


decompiled_code:
int print_help()
{
return puts("Usage:\n\tpangvm [-pasm] <file>");
}

canonical_decompiled_code:
int func0()
{
return puts("Usage:\n\tpangvm [-pasm] <file>");
}

original_code:
void
print_help()
{
 printf("Usage:\n\tpangvm [-pasm] <file>\n");
}


decompiled_code:
int __fastcall hex_dump(__int64 a1, unsigned int a2)
{
__int64 v2; // r12
__int64 v3; // rbx
const char *v4; // rsi

if ( a2 )
{
v2 = a2;
v3 = 0LL;
while ( 1 )
{
v4 = (const char *)&unk_DC;
if ( *(_BYTE *)(a1 + v3) < 0x10u )
v4 = "0";
printf("%s%X", v4);
if ( (v3 & 3) == 3 )
{
putchar(9);
if ( (v3 & 7) == 7 )
goto LABEL_9;
LABEL_4:
if ( v2 == ++v3 )
return putchar(10);
}
else
{
putchar(32);
if ( (v3 & 7) != 7 )
goto LABEL_4;
LABEL_9:
++v3;
putchar(10);
if ( v2 == v3 )
return putchar(10);
}
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, unsigned int a2)
{
__int64 v2; // r12
__int64 v3; // rbx
const char *v4; // rsi

if ( a2 )
{
v2 = a2;
v3 = 0LL;
while ( 1 )
{
v4 = (const char *)&unk_DC;
if ( *(_BYTE *)(a1 + v3) < 0x10u )
v4 = "0";
printf("%s%X", v4);
if ( (v3 & 3) == 3 )
{
putchar(9);
if ( (v3 & 7) == 7 )
goto LABEL_9;
LABEL_4:
if ( v2 == ++v3 )
return putchar(10);
}
else
{
putchar(32);
if ( (v3 & 7) != 7 )
goto LABEL_4;
LABEL_9:
++v3;
putchar(10);
if ( v2 == v3 )
return putchar(10);
}
}
}
return putchar(10);
}

original_code:
void
hex_dump(uint8 *opcode, uint len)
{
 for (int i=0; i<len; i++) {
  printf("%s%X", opcode[i]<0x10?"0":"", opcode[i]);
  if (i%4 == 3 && i) {
   printf("\t");
  } else {
   printf(" ");
  }
  if (i%8 == 7 && i) {
   printf("\n");
  }
 }
 printf("\n");
}

canonical_original_code:
void hex_dump(unsigned char *opcode, unsigned int len)
{
 for (int i = 0; i<len; i++) {
  printf("%s%X", opcode[i]<0x10?"0":"", opcode[i]);
  if (i%4 == 3 && i) {
   printf("\t");
  } else {
   printf(" ");
  }
  if (i%8 == 7 && i) {
   printf("\n");
  }
 }
 printf("\n");
}

variable_types:
opcode
unsigned char *

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
int result; // eax
FILE *v5; // r12
size_t size[5]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( argc == 1 )
{
print_help();
result = 1;
}
else
{
if ( argc == 2 )
{
v5 = fopen(argv[1], "rb");
fseek(v5, 0LL, 2);
LODWORD(size[0]) = ftell(v5);
fseek(v5, 0LL, 0);
v3 = malloc(LODWORD(size[0]));
fread(v3, 1uLL, LODWORD(size[0]), v5);
}
else if ( argc == 3 && !strcmp(argv[1], "-pasm") )
{
v3 = (void *)pasm_compile(argv[2], size);
}
else
{
print_help();
}
if ( v3 )
{
result = 2;
if ( LODWORD(size[0]) )
{
hex_dump((__int64)v3, size[0]);
execute(v3, LODWORD(size[0]));
result = 0;
}
}
else
{
result = 2;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
int result; // eax
FILE *v5; // r12
size_t size[5]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( argc == 1 )
{
func0();
result = 1;
}
else
{
if ( argc == 2 )
{
v5 = fopen(argv[1], "rb");
fseek(v5, 0LL, 2);
LODWORD(size[0]) = ftell(v5);
fseek(v5, 0LL, 0);
v3 = malloc(LODWORD(size[0]));
fread(v3, 1uLL, LODWORD(size[0]), v5);
}
else if ( argc == 3 && !strcmp(argv[1], "-pasm") )
{
v3 = (void *)pasm_compile(argv[2], size);
}
else
{
func0();
}
if ( v3 )
{
result = 2;
if ( LODWORD(size[0]) )
{
func1((__int64)v3, size[0]);
execute(v3, LODWORD(size[0]));
result = 0;
}
}
else
{
result = 2;
}
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
char *__fastcall get_reg_name(unsigned __int8 a1)
{
return CSWTCH_2[a1];
}

canonical_decompiled_code:
char *__fastcall func0(unsigned __int8 a1)
{
return CSWTCH_2[a1];
}

original_code:
static const char*
get_reg_name(uint8 reg)
{
 switch (reg)
 {
  case 0x00 : return "REG_A";
  case 0x01 : return "REG_B";
  case 0x02 : return "REG_C";
  case 0x03 : return "REG_D";
  case 0x05: return "REG_SP";
  case 0x06: return "REG_BP";
 }
 return "??";
}

canonical_original_code:
static char *get_reg_name(unsigned char reg)
{
 switch (reg)
 {
  case 0x00 : return "REG_A";
  case 0x01 : return "REG_B";
  case 0x02 : return "REG_C";
  case 0x03 : return "REG_D";
  case 0x05: return "REG_SP";
  case 0x06: return "REG_BP";
 }
 return "??";
}

return_type: char *


decompiled_code:
char *__fastcall get_op_push_info(char a1)
{
char *v1; // rax

v1 = get_reg_name(a1 & 3);
sprintf(gstr, "OP_PUSH (%s)", v1);
return gstr;
}

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

v1 = func0(a1 & 3);
sprintf(gstr, "OP_PUSH (%s)", v1);
return gstr;
}

original_code:
static char*
get_op_push_info(uint8 op)
{
 op &= 0x03;
 sprintf(gstr, "OP_PUSH (%s)", get_reg_name(op));
 return gstr;
}

canonical_original_code:
static char *get_op_push_info(unsigned char op)
{
 op &= 0x03;
 sprintf(gstr, "OP_PUSH (%s)", get_reg_name(op));
 return gstr;
}

variable_types:
op
unsigned char


decompiled_code:
char *__fastcall get_op_pop_info(char a1)
{
char *v1; // rax

v1 = get_reg_name(a1 & 3);
sprintf(gstr, "OP_POP (%s)", v1);
return gstr;
}

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

v1 = func0(a1 & 3);
sprintf(gstr, "OP_POP (%s)", v1);
return gstr;
}

original_code:
static char*
get_op_pop_info(uint8 op)
{
 op &= 0x03;
 sprintf(gstr, "OP_POP (%s)", get_reg_name(op));
 return gstr;
}

canonical_original_code:
static char *get_op_pop_info(unsigned char op)
{
 op &= 0x03;
 sprintf(gstr, "OP_POP (%s)", get_reg_name(op));
 return gstr;
}


decompiled_code:
char *__fastcall get_op_mov_info(char a1)
{
char *v1; // rax
char v2; // cl

v1 = get_reg_name(a1 & 3);
sprintf(gstr, "OP_MOV (%s, ?) toreg:%d 32bit:%d", v1, (v2 & 4) != 0, (v2 & 4) != 0);
return gstr;
}

canonical_decompiled_code:
char *__fastcall func3(char a1)
{
char *v1; // rax
char v2; // cl

v1 = func0(a1 & 3);
sprintf(gstr, "OP_MOV (%s, ?) toreg:%d 32bit:%d", v1, (v2 & 4) != 0, (v2 & 4) != 0);
return gstr;
}

original_code:
static char*
get_op_mov_info(uint8 op)
{
 uint8 reg = op & 0x03;
 uint8 toreg = op & 0x04;
 uint8 bit32 = op & 0x04;
 sprintf(gstr, "OP_MOV (%s, ?) toreg:%d 32bit:%d",
  get_reg_name(reg), toreg!=0, bit32!=0);
 return gstr;
}

canonical_original_code:
static char *get_op_mov_info(unsigned char op)
{
 unsigned char reg = op & 0x03;
 unsigned char toreg = op & 0x04;
 unsigned char bit32 = op & 0x04;
 sprintf(gstr, "OP_MOV (%s, ?) toreg:%d 32bit:%d",
  get_reg_name(reg), toreg!=0, bit32!=0);
 return gstr;
}

variable_types:
toreg
unsigned char


decompiled_code:
const char *__fastcall get_op_info(unsigned __int8 a1, char a2)
{
const char *result; // rax

if ( a1 > 0xF8u )
return "??";
if ( a1 > 0x80u )
{
switch ( a1 )
{
case 0x81:
result = "OP_CALL";
break;
case 0x82:
result = "OP_RET";
break;
case 0xC0:
result = "OP_ADD";
break;
case 0xC4:
result = "OP_SUB";
break;
case 0xC8:
result = "OP_MUL";
break;
case 0xCC:
result = "OP_DIV";
break;
case 0xD0:
result = "OP_MOD";
break;
case 0xD4:
result = "OP_XOR";
break;
case 0xD8:
result = "OP_AND";
break;
case 0xDC:
result = "OP_CMP";
break;
case 0xE0:
result = "OP_JMP";
break;
case 0xE4:
result = "OP_JE";
break;
case 0xE8:
result = "OP_JNE";
break;
case 0xEC:
result = "OP_JL";
break;
case 0xF0:
result = "OP_JLE";
break;
case 0xF4:
result = "OP_JG";
break;
case 0xF8:
result = "OP_JGE";
break;
default:
return "??";
}
return result;
}
if ( a1 == 32 )
return get_op_mov_info(a2);
if ( a1 <= 0x20u )
{
if ( !a1 )
return get_op_push_info(a2);
if ( a1 == 16 )
return get_op_pop_info(a2);
return "??";
}
result = "??";
if ( a1 == 48 )
result = "OP_MOV_LTRL";
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(unsigned __int8 a1, char a2)
{
const char *result; // rax

if ( a1 > 0xF8u )
return "??";
if ( a1 > 0x80u )
{
switch ( a1 )
{
case 0x81:
result = "OP_CALL";
break;
case 0x82:
result = "OP_RET";
break;
case 0xC0:
result = "OP_ADD";
break;
case 0xC4:
result = "OP_SUB";
break;
case 0xC8:
result = "OP_MUL";
break;
case 0xCC:
result = "OP_DIV";
break;
case 0xD0:
result = "OP_MOD";
break;
case 0xD4:
result = "OP_XOR";
break;
case 0xD8:
result = "OP_AND";
break;
case 0xDC:
result = "OP_CMP";
break;
case 0xE0:
result = "OP_JMP";
break;
case 0xE4:
result = "OP_JE";
break;
case 0xE8:
result = "OP_JNE";
break;
case 0xEC:
result = "OP_JL";
break;
case 0xF0:
result = "OP_JLE";
break;
case 0xF4:
result = "OP_JG";
break;
case 0xF8:
result = "OP_JGE";
break;
default:
return "??";
}
return result;
}
if ( a1 == 32 )
return func3(a2);
if ( a1 <= 0x20u )
{
if ( !a1 )
return func1(a2);
if ( a1 == 16 )
return func2(a2);
return "??";
}
result = "??";
if ( a1 == 48 )
result = "OP_MOV_LTRL";
return result;
}

original_code:
static const char*
get_op_info(uint8 op, uint8 full)
{
 switch (op) {
  case 0x00: return get_op_push_info(full);
  case 0x10: return get_op_pop_info(full);
  case 0x20: return get_op_mov_info(full);
  case 0x30: return "OP_MOV_LTRL";
  case 0x81: return "OP_CALL";
  case 0x82: return "OP_RET";
  case 0xC0: return "OP_ADD";
  case 0xC4: return "OP_SUB";
  case 0xC8: return "OP_MUL";
  case 0xCC: return "OP_DIV";
  case 0xD0: return "OP_MOD";
  case 0xD4: return "OP_XOR";
  case 0xD8: return "OP_AND";
  case 0xDC: return "OP_CMP";
  case 0xE0: return "OP_JMP";
  case 0xE4: return "OP_JE";
  case 0xE8: return "OP_JNE";
  case 0xEC: return "OP_JL";
  case 0xF0: return "OP_JLE";
  case 0xF4: return "OP_JG";
  case 0xF8: return "OP_JGE";
 }
 return "??";
}

canonical_original_code:
static char *get_op_info(unsigned char op, unsigned char full)
{
 switch (op) {
  case 0x00: return get_op_push_info(full);
  case 0x10: return get_op_pop_info(full);
  case 0x20: return get_op_mov_info(full);
  case 0x30: return "OP_MOV_LTRL";
  case 0x81: return "OP_CALL";
  case 0x82: return "OP_RET";
  case 0xC0: return "OP_ADD";
  case 0xC4: return "OP_SUB";
  case 0xC8: return "OP_MUL";
  case 0xCC: return "OP_DIV";
  case 0xD0: return "OP_MOD";
  case 0xD4: return "OP_XOR";
  case 0xD8: return "OP_AND";
  case 0xDC: return "OP_CMP";
  case 0xE0: return "OP_JMP";
  case 0xE4: return "OP_JE";
  case 0xE8: return "OP_JNE";
  case 0xEC: return "OP_JL";
  case 0xF0: return "OP_JLE";
  case 0xF4: return "OP_JG";
  case 0xF8: return "OP_JGE";
 }
 return "??";
}

variable_types:
full
unsigned char


decompiled_code:
__int64 __fastcall dbg_opcode(__int64 a1, unsigned int a2)
{
unsigned __int8 v2; // bp
const char *v3; // rax
unsigned __int8 v5; // [rsp+Eh] [rbp-Ah] BYREF
char v6[9]; // [rsp+Fh] [rbp-9h] BYREF

v2 = *(_BYTE *)(a1 + a2);
opcode_split(v2, &v5, v6);
v3 = get_op_info(v5, v2);
return panglog(1LL, v3);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
unsigned __int8 v2; // bp
const char *v3; // rax
unsigned __int8 v5; // [rsp+Eh] [rbp-Ah] BYREF
char v6[9]; // [rsp+Fh] [rbp-9h] BYREF

v2 = *(_BYTE *)(a1 + a2);
opcode_split(v2, &v5, v6);
v3 = func4(v5, v2);
return panglog(1LL, v3);
}

original_code:
void
dbg_opcode(const uint8 *ops, uint idx)
{
 uint8 op = ops[idx];
 uint8 body, arg;
 opcode_split(op, &body, &arg);
 panglog(1, get_op_info(body, op));
}

canonical_original_code:
void dbg_opcode(unsigned char *ops, unsigned int idx)
{
 unsigned char op = ops[idx];
 unsigned char body; unsigned char arg;
 opcode_split(op, &body, &arg);
 panglog(1, get_op_info(body, op));
}

variable_types:
idx
unsigned int

variable_types:
body
unsigned char

variable_types:
arg
unsigned char


decompiled_code:
__int64 __fastcall dbg_registers(unsigned int *a1)
{
char s[168]; // [rsp+0h] [rbp-A8h] BYREF

sprintf(s, "ra:%x rb:%x rc:%x rd:%x ip:%x bp:%x sp:%x res:%x", a1[3], a1[4], a1[5], a1[6], *a1, a1[1], a1[2], a1[7]);
return panglog(2LL, s);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1)
{
char s[168]; // [rsp+0h] [rbp-A8h] BYREF

sprintf(s, "ra:%x rb:%x rc:%x rd:%x ip:%x bp:%x sp:%x res:%x", a1[3], a1[4], a1[5], a1[6], *a1, a1[1], a1[2], a1[7]);
return panglog(2LL, s);
}

original_code:
void
dbg_registers(struct regs *r)
{
 char str[160];
 sprintf(str, "ra:%x rb:%x rc:%x rd:%x  ip:%x bp:%x sp:%x res:%x",
  r->r_a, r->r_b, r->r_c, r->r_d, r->r_ip, r->r_bp, r->r_sp, r->r_res);
 panglog(2, str);
}

variable_types: struct regs { int r_ip; int r_bp; int r_sp; int r_a; int r_b; int r_c; int r_d; int r_res; } *

variable_types:
str
char [160]


decompiled_code:
__int64 __fastcall set_log_level(unsigned int a1)
{
__int64 result; // rax

result = 2LL;
if ( a1 > 2 )
a1 = 2;
g_log_level = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
__int64 result; // rax

result = 2LL;
if ( a1 > 2 )
a1 = 2;
g_log_level = a1;
return result;
}

original_code:
void
set_log_level(unsigned int level)
{
 if (level > 2) {
  level = 2;
 }
 g_log_level = level;
}

variable_types:
level
unsigned int


panglog

decompiled_code:
void __fastcall panglog(unsigned int a1, const char *a2)
{
const char *v2; // r13
const char *v3; // r14
size_t v4; // rax
char *v5; // r12

if ( g_log_level >= a1 )
{
v4 = strlen(a2);
v5 = (char *)malloc(v4 + 32);
if ( a1 <= 2 )
{
v3 = CSWTCH_5[a1];
v2 = CSWTCH_6[a1];
}
sprintf(v5, "[%s%s%s] %s\n", v2, v3, "\x1B[0m", a2);
if ( a1 )
fputs(v5, stdout);
else
fputs(v5, stderr);
free(v5);
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int a1, const char *a2)
{
const char *v2; // r13
const char *v3; // r14
size_t v4; // rax
char *v5; // r12

if ( g_log_level >= a1 )
{
v4 = strlen(a2);
v5 = (char *)malloc(v4 + 32);
if ( a1 <= 2 )
{
v3 = CSWTCH_5[a1];
v2 = CSWTCH_6[a1];
}
sprintf(v5, "[%s%s%s] %s\n", v2, v3, "\x1B[0m", a2);
if ( a1 )
fputs(v5, stdout);
else
fputs(v5, stderr);
free(v5);
}
}

original_code:
void
panglog(unsigned int level, const char *msg)
{
 if (level > g_log_level) {
  return;
 }
 char *lstr = malloc(strlen(msg) + 32);
 char *lvl;
 char *color;
 switch (level) {
  case 0:
   color = "\033[0;31m";
   lvl = "CRITICAL";
   break;
  case 1:
   color = "\033[0;34m";
   lvl = "DEBUG   ";
   break;
  case 2:
   color = "\033[0;32m";
   lvl = "VERBOSE ";
   break;
 }
 sprintf(lstr, "[%s%s%s] %s\n", color, lvl, "\033[0m", msg);
 if (level == 0) {
  fputs(lstr, stderr);
 } else {
  fputs(lstr, stdout);
 }
 free(lstr);
}

canonical_original_code:
void panglog(unsigned int level, char *msg)
{
 if (level > g_log_level) {
  return;
 }
 char *lstr = malloc(strlen(msg) + 32);
 char *lvl;
 char *color;
 switch (level) {
  case 0:
   color = "\033[0;31m";
   lvl = "CRITICAL";
   break;
  case 1:
   color = "\033[0;34m";
   lvl = "DEBUG   ";
   break;
  case 2:
   color = "\033[0;32m";
   lvl = "VERBOSE ";
   break;
 }
 sprintf(lstr, "[%s%s%s] %s\n", color, lvl, "\033[0m", msg);
 if (level == 0) {
  fputs(lstr, stderr);
 } else {
  fputs(lstr, stdout);
 }
 free(lstr);
}

variable_types:
msg
char *

variable_types:
lstr
char *

variable_types:
lvl
char *

variable_types:
color
char *


decompiled_code:
int cli_print_version()
{
return printf("GNU %s %s\n", "photo", "0.0.1");
}

canonical_decompiled_code:
int func8()
{
return printf("GNU %s %s\n", "photo", "0.0.1");
}

original_code:
void
cli_print_version (void)
{
  printf ("GNU %s %s\n", "photo", "0.0.1");
}

canonical_original_code:
void cli_print_version()
{
  printf ("GNU %s %s\n", "photo", "0.0.1");
}


decompiled_code:
int __fastcall cli_save_image(unsigned int a1, const char *a2)
{
test_file_name(a2);
return printf("FIX: Saving image number %i as %s\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1, const char *a2)
{
func7(a2);
return printf("FIX: Saving image number %i as %s\n", a1, a2);
}

original_code:
void
cli_save_image (int image_number, char *fname)
{
  test_file_name (fname);
  printf ("FIX: Saving image number %i as %s\n", image_number, fname);
}

canonical_original_code:
void cli_save_image(int image_number, char *fname)
{
  test_file_name (fname);
  printf ("FIX: Saving image number %i as %s\n", image_number, fname);
}

variable_types:
fname
char *


decompiled_code:
int __fastcall cli_save_thumbnail(unsigned int a1, const char *a2)
{
test_file_name(a2);
return printf("FIX Saving thumbnail %i as %s\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1, const char *a2)
{
func7(a2);
return printf("FIX Saving thumbnail %i as %s\n", a1, a2);
}

original_code:
void
cli_save_thumbnail (int thumbnail_number, char *fname)
{
  test_file_name (fname);
  printf ("FIX Saving thumbnail %i as %s\n", thumbnail_number, fname);
}

canonical_original_code:
void cli_save_thumbnail(int thumbnail_number, char *fname)
{
  test_file_name (fname);
  printf ("FIX Saving thumbnail %i as %s\n", thumbnail_number, fname);
}