main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // er12
char *v5; // rbp
unsigned int v6; // er15
__int64 v7; // r13
char *v8; // rbp
unsigned int v9; // ebx
int v11; // [rsp+8h] [rbp-40h] BYREF
int v12[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v11 = 0;
v12[0] = 1;
if ( argc == 1 )
{
puts("[err]: What is the file name?");
}
else if ( argc > 2 )
{
puts("[err]: Unneccessary parameters!");
}
else
{
v3 = connectDevice("/dev/tty.usbserial-A900cbrd", argv, envp);
v4 = v3;
if ( v3 >= 0 )
{
if ( (int)sendPing((unsigned int)v3) <= 0 )
{
puts("[err]: Ping problem");
return 0;
}
puts("[dbg]: Ping OK");
v5 = (char *)argv[1];
memset(dataBuffer, 255, (size_t)&unk_10000);
parseIntelHex_constprop_0_isra_0(v5, v12, &v11);
if ( v12[0] )
{
puts("[err]: You should change the startAddress = 0 assumption");
}
else
{
if ( v11 > 30720 )
{
puts("[err]: Program size is too big!");
return 0;
}
puts("[dbg]: Erasing the memory ...");
serialport_writebyte(v4, 100LL);
if ( (int)readACK(v4) <= 0 )
goto LABEL_23;
v6 = 0;
v7 = 0LL;
puts("[dbg]: ACK OK");
if ( v11 > 0 )
{
while ( 1 )
{
putchar(10);
printf("[dbg]: Page number: %d\n", v6);
printf("[dbg]: Page base address: %d\n", (unsigned int)v7);
serialport_writebyte(v4, 98LL);
if ( (int)readACK(v4) <= 0 )
break;
v8 = &dataBuffer[v7];
v9 = 0;
puts("[dbg]: ACK OK");
printf(" ");
printf("[%3d] %2X ", 0LL, (unsigned __int8)dataBuffer[v7]);
while ( 1 )
{
++v9;
serialport_writebyte(v4, (unsigned __int8)*v8);
if ( v9 == 128 )
break;
printf("[%3d] %2X ", v9, (unsigned __int8)v8[1]);
if ( (v9 & 7) == 7 )
printf("\n ");
++v8;
}
putchar(10);
serialport_writebyte(v4, 99LL);
if ( (int)readACK(v4) <= 0 )
break;
puts("[dbg]: ACK OK");
serialport_writebyte(v4, (unsigned __int8)v7);
serialport_writebyte(v4, BYTE1(v7));
serialport_writebyte(v4, (unsigned int)((int)v7 >> 16));
serialport_writebyte(v4, 0LL);
if ( (int)readACK(v4) <= 0 )
break;
++v6;
v7 += 128LL;
puts("[dbg]: ACK OK");
if ( v11 <= (int)v7 )
goto LABEL_21;
}
LABEL_23:
puts("[dbg]: ACK problem");
return 0;
}
LABEL_21:
serialport_writebyte(v4, 120LL);
serialport_close(v4);
}
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // er12
char *v5; // rbp
unsigned int v6; // er15
__int64 v7; // r13
char *v8; // rbp
unsigned int v9; // ebx
int v11; // [rsp+8h] [rbp-40h] BYREF
int v12[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v11 = 0;
v12[0] = 1;
if ( argc == 1 )
{
puts("[err]: What is the file name?");
}
else if ( argc > 2 )
{
puts("[err]: Unneccessary parameters!");
}
else
{
v3 = func3("/dev/tty.usbserial-A900cbrd", argv, envp);
v4 = v3;
if ( v3 >= 0 )
{
if ( (int)func5((unsigned int)v3) <= 0 )
{
puts("[err]: Ping problem");
return 0;
}
puts("[dbg]: Ping OK");
v5 = (char *)argv[1];
memset(dataBuffer, 255, (size_t)&unk_10000);
func2(v5, v12, &v11);
if ( v12[0] )
{
puts("[err]: You should change the startAddress = 0 assumption");
}
else
{
if ( v11 > 30720 )
{
puts("[err]: Program size is too big!");
return 0;
}
puts("[dbg]: Erasing the memory ...");
serialport_writebyte(v4, 100LL);
if ( (int)func4(v4) <= 0 )
goto LABEL_23;
v6 = 0;
v7 = 0LL;
puts("[dbg]: ACK OK");
if ( v11 > 0 )
{
while ( 1 )
{
putchar(10);
printf("[dbg]: Page number: %d\n", v6);
printf("[dbg]: Page base address: %d\n", (unsigned int)v7);
serialport_writebyte(v4, 98LL);
if ( (int)func4(v4) <= 0 )
break;
v8 = &dataBuffer[v7];
v9 = 0;
puts("[dbg]: ACK OK");
printf(" ");
printf("[%3d] %2X ", 0LL, (unsigned __int8)dataBuffer[v7]);
while ( 1 )
{
++v9;
serialport_writebyte(v4, (unsigned __int8)*v8);
if ( v9 == 128 )
break;
printf("[%3d] %2X ", v9, (unsigned __int8)v8[1]);
if ( (v9 & 7) == 7 )
printf("\n ");
++v8;
}
putchar(10);
serialport_writebyte(v4, 99LL);
if ( (int)func4(v4) <= 0 )
break;
puts("[dbg]: ACK OK");
serialport_writebyte(v4, (unsigned __int8)v7);
serialport_writebyte(v4, BYTE1(v7));
serialport_writebyte(v4, (unsigned int)((int)v7 >> 16));
serialport_writebyte(v4, 0LL);
if ( (int)func4(v4) <= 0 )
break;
++v6;
v7 += 128LL;
puts("[dbg]: ACK OK");
if ( v11 <= (int)v7 )
goto LABEL_21;
}
LABEL_23:
puts("[dbg]: ACK problem");
return 0;
}
LABEL_21:
serialport_writebyte(v4, 120LL);
serialport_close(v4);
}
}
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int i;
    int fd;
    int offset;
    uint8_t t8;
    int pageNumber;
    int endAddress = 0;
    int startAddress = 1;
    char* fileName = ((void *)0);
    if(argc == 1)
    {
        printf("[err]: What is the file name?\n");
        return 0;
    }
    else if(argc > 2)
    {
        printf("[err]: Unneccessary parameters!\n");
        return 0;
    }
    fd = connectDevice("/dev/tty.usbserial-A900cbrd");
    if(fd < 0)
    {
        return 0;
    }
    if(sendPing(fd) > 0)
    {
        printf("[dbg]: Ping OK\n");
    }
    else
    {
        printf("[err]: Ping problem\n");
        return 0;
    }
    fileName = argv[1];
    memset(dataBuffer, 0xFF, sizeof(dataBuffer));
    parseIntelHex(fileName, dataBuffer, &startAddress, &endAddress);
    if(startAddress != 0)
    {
        printf("[err]: You should change the startAddress = 0 assumption\n");
        return 0;
    }
    if(endAddress > (32768 - 2048))
    {
        printf("[err]: Program size is too big!\n");
 return 0;
    }
    printf("[dbg]: Erasing the memory ...\n");
    serialport_writebyte(fd,'d');
    if (readACK(fd) > 0)
    {
        printf("[dbg]: ACK OK\n");
    }
    else
    {
        printf("[dbg]: ACK problem\n");
        return 0;
    }
    i = 0;
    offset = 0;
    pageNumber = 0;
    while(offset<endAddress)
    {
        printf("\n");
        printf("[dbg]: Page number: %d\n",pageNumber);
        printf("[dbg]: Page base address: %d\n",offset);
        serialport_writebyte(fd,'b');
        if (readACK(fd) > 0)
        {
            printf("[dbg]: ACK OK\n");
        }
        else
        {
            printf("[dbg]: ACK problem\n");
            return 0;
        }
        printf("    ");
        for(i=0;i<128;i++)
        {
            printf("[%3d] %2X   ",i,dataBuffer[i+offset]);
            if((i%8)==7)
            {
                printf("\n    ");
            }
            serialport_writebyte(fd,dataBuffer[i+offset]);
        }
        printf("\n");
        serialport_writebyte(fd,'c');
        if (readACK(fd) > 0)
        {
            printf("[dbg]: ACK OK\n");
        }
        else
        {
            printf("[dbg]: ACK problem\n");
            return 0;
        }
        t8 = (offset >> 0) & 0xFF;
        serialport_writebyte(fd,t8);
        t8 = (offset >> 8) & 0xFF;
        serialport_writebyte(fd,t8);
        t8 = (offset >> 16) & 0xFF;
        serialport_writebyte(fd,t8);
        t8 = (offset >> 24) & 0xFF;
        serialport_writebyte(fd,t8);
        if (readACK(fd) > 0)
        {
            printf("[dbg]: ACK OK\n");
        }
        else
        {
            printf("[dbg]: ACK problem\n");
            return 0;
        }
        offset += 128;
        pageNumber++;
    }
    serialport_writebyte(fd,'x');
    serialport_close(fd);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int i;
    int fd;
    int offset;
    unsigned char t8;
    int pageNumber;
    int endAddress = 0;
    int startAddress = 1;
    char *fileName = ((void *)0);
    if(argc == 1)
    {
        printf("[err]: What is the file name?\n");
        return 0;
    }
    else if(argc > 2)
    {
        printf("[err]: Unneccessary parameters!\n");
        return 0;
    }
    fd = connectDevice("/dev/tty.usbserial-A900cbrd");
    if(fd < 0)
    {
        return 0;
    }
    if(sendPing(fd) > 0)
    {
        printf("[dbg]: Ping OK\n");
    }
    else
    {
        printf("[err]: Ping problem\n");
        return 0;
    }
    fileName = argv[1];
    memset(dataBuffer, 0xFF, sizeof(dataBuffer));
    parseIntelHex(fileName, dataBuffer, &startAddress, &endAddress);
    if(startAddress != 0)
    {
        printf("[err]: You should change the startAddress = 0 assumption\n");
        return 0;
    }
    if(endAddress > (32768 - 2048))
    {
        printf("[err]: Program size is too big!\n");
 return 0;
    }
    printf("[dbg]: Erasing the memory ...\n");
    serialport_writebyte(fd,'d');
    if (readACK(fd) > 0)
    {
        printf("[dbg]: ACK OK\n");
    }
    else
    {
        printf("[dbg]: ACK problem\n");
        return 0;
    }
    i = 0;
    offset = 0;
    pageNumber = 0;
    while(offset<endAddress)
    {
        printf("\n");
        printf("[dbg]: Page number: %d\n",pageNumber);
        printf("[dbg]: Page base address: %d\n",offset);
        serialport_writebyte(fd,'b');
        if (readACK(fd) > 0)
        {
            printf("[dbg]: ACK OK\n");
        }
        else
        {
            printf("[dbg]: ACK problem\n");
            return 0;
        }
        printf("    ");
        for(i=0;i<128;i++)
        {
            printf("[%3d] %2X   ",i,dataBuffer[i+offset]);
            if((i%8)==7)
            {
                printf("\n    ");
            }
            serialport_writebyte(fd,dataBuffer[i+offset]);
        }
        printf("\n");
        serialport_writebyte(fd,'c');
        if (readACK(fd) > 0)
        {
            printf("[dbg]: ACK OK\n");
        }
        else
        {
            printf("[dbg]: ACK problem\n");
            return 0;
        }
        t8 = (offset >> 0) & 0xFF;
        serialport_writebyte(fd,t8);
        t8 = (offset >> 8) & 0xFF;
        serialport_writebyte(fd,t8);
        t8 = (offset >> 16) & 0xFF;
        serialport_writebyte(fd,t8);
        t8 = (offset >> 24) & 0xFF;
        serialport_writebyte(fd,t8);
        if (readACK(fd) > 0)
        {
            printf("[dbg]: ACK OK\n");
        }
        else
        {
            printf("[dbg]: ACK problem\n");
            return 0;
        }
        offset += 128;
        pageNumber++;
    }
    serialport_writebyte(fd,'x');
    serialport_close(fd);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: offset int

variable_types: pageNumber int

variable_types: endAddress int

variable_types: startAddress int

variable_types:
fileName
char *


repo: kehribar/leef-bootloader

decompiled_code:
__int64 __fastcall serialport_init(const char *a1, int a2, char a3)
{
int v4; // eax
unsigned int v5; // er12
speed_t v6; // ebp
tcflag_t v8; // eax
struct termios v9; // [rsp+0h] [rbp-68h] BYREF

v4 = open(a1, 2050);
v5 = v4;
if ( v4 == -1 )
{
perror("Unable to open port ");
return v5;
}
if ( tcgetattr(v4, &v9) < 0 )
{
v5 = -1;
perror("Couldn't get term attributes");
return v5;
}
if ( a2 == 38400 )
{
v6 = 15;
}
else
{
if ( a2 > 38400 )
{
v6 = 4097;
if ( a2 == 57600 )
goto LABEL_7;
if ( a2 == 115200 )
{
v6 = 4098;
goto LABEL_7;
}
goto LABEL_14;
}
v6 = 13;
if ( a2 != 9600 )
{
v6 = 14;
if ( a2 != 19200 )
{
v6 = 12;
if ( a2 != 4800 )
{
LABEL_14:
v6 = a2;
goto LABEL_7;
}
}
}
}
LABEL_7:
cfsetispeed(&v9, v6);
cfsetospeed(&v9, v6);
switch ( a3 )
{
case 'E':
case 'e':
v8 = v9.c_cflag;
BYTE1(v8) = BYTE1(v9.c_cflag) & 0xFD | 1;
goto LABEL_16;
case 'N':
case 'n':
v8 = v9.c_cflag;
BYTE1(v8) = BYTE1(v9.c_cflag) & 0xFE;
goto LABEL_16;
case 'O':
case 'o':
v8 = v9.c_cflag;
BYTE1(v8) = BYTE1(v9.c_cflag) | 3;
LABEL_16:
v9.c_lflag &= 0xFFFFFFE4;
v9.c_cflag = v8 & 0x7FFFFF8F | 0x8B0;
*(_QWORD *)&v9.c_iflag &= 0xFFFFFFFEFFFFE3FFLL;
*(_WORD *)&v9.c_cc[5] = 0;
tcsetattr(v5, 0, &v9);
if ( tcsetattr(v5, 2, &v9) < 0 )
{
v5 = -1;
perror(">Couldn't set term attributes");
}
break;
default:
v5 = -1;
break;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, int a2, char a3)
{
int v4; // eax
unsigned int v5; // er12
speed_t v6; // ebp
tcflag_t v8; // eax
struct termios v9; // [rsp+0h] [rbp-68h] BYREF

v4 = open(a1, 2050);
v5 = v4;
if ( v4 == -1 )
{
perror("Unable to open port ");
return v5;
}
if ( tcgetattr(v4, &v9) < 0 )
{
v5 = -1;
perror("Couldn't get term attributes");
return v5;
}
if ( a2 == 38400 )
{
v6 = 15;
}
else
{
if ( a2 > 38400 )
{
v6 = 4097;
if ( a2 == 57600 )
goto LABEL_7;
if ( a2 == 115200 )
{
v6 = 4098;
goto LABEL_7;
}
goto LABEL_14;
}
v6 = 13;
if ( a2 != 9600 )
{
v6 = 14;
if ( a2 != 19200 )
{
v6 = 12;
if ( a2 != 4800 )
{
LABEL_14:
v6 = a2;
goto LABEL_7;
}
}
}
}
LABEL_7:
cfsetispeed(&v9, v6);
cfsetospeed(&v9, v6);
switch ( a3 )
{
case 'E':
case 'e':
v8 = v9.c_cflag;
BYTE1(v8) = BYTE1(v9.c_cflag) & 0xFD | 1;
goto LABEL_16;
case 'N':
case 'n':
v8 = v9.c_cflag;
BYTE1(v8) = BYTE1(v9.c_cflag) & 0xFE;
goto LABEL_16;
case 'O':
case 'o':
v8 = v9.c_cflag;
BYTE1(v8) = BYTE1(v9.c_cflag) | 3;
LABEL_16:
v9.c_lflag &= 0xFFFFFFE4;
v9.c_cflag = v8 & 0x7FFFFF8F | 0x8B0;
*(_QWORD *)&v9.c_iflag &= 0xFFFFFFFEFFFFE3FFLL;
*(_WORD *)&v9.c_cc[5] = 0;
tcsetattr(v5, 0, &v9);
if ( tcsetattr(v5, 2, &v9) < 0 )
{
v5 = -1;
perror(">Couldn't set term attributes");
}
break;
default:
v5 = -1;
break;
}
return v5;
}

original_code:
int serialport_init(const char* serialport, int baud,char parity)
{
    struct termios toptions;
    int fd;
    fd = open(serialport, 02 | 04000 );
    if (fd == -1) {
        perror("Unable to open port ");
        return -1;
    }
    if (tcgetattr(fd, &toptions) < 0) {
        perror("Couldn't get term attributes");
        return -1;
    }
    speed_t brate = baud;
    switch(baud) {
    case 4800: brate=0000014; break;
    case 9600: brate=0000015; break;
    case 19200: brate=0000016; break;
    case 38400: brate=0000017; break;
    case 57600: brate=0010001; break;
    case 115200: brate=0010002; break;
    }
    cfsetispeed(&toptions, brate);
    cfsetospeed(&toptions, brate);
    switch (parity)
    {
        case 'n':
        case 'N':
            toptions.c_cflag &= ~0000400;
            break;
        case 'o':
        case 'O':
            toptions.c_cflag |= 0000400;
            toptions.c_cflag |= 0001000;
            break;
        case 'e':
        case 'E':
            toptions.c_cflag |= 0000400;
            toptions.c_cflag &= ~0001000;
            break;
        default:
            return -1;
    }
    toptions.c_cflag &= ~0000100;
    toptions.c_cflag &= ~0000060;
    toptions.c_cflag |= 0000060;
    toptions.c_cflag &= ~020000000000;
    toptions.c_cflag |= 0000200 | 0004000;
    toptions.c_iflag &= ~(0002000 | 0010000 | 0004000);
    toptions.c_lflag &= ~(0000002 | 0000010 | 0000020 | 0000001);
    toptions.c_oflag &= ~0000001;
    toptions.c_cc[6] = 0;
    toptions.c_cc[5] = 0;
    tcsetattr(fd, 0, &toptions);
    if( tcsetattr(fd, 2, &toptions) < 0) {
        perror(">Couldn't set term attributes");
        return -1;
    }
    return fd;
}

canonical_original_code:
int serialport_init(char *serialport, int baud, char parity)
{
    struct termios toptions;
    int fd;
    fd = open(serialport, 02 | 04000 );
    if (fd == -1) {
        perror("Unable to open port ");
        return -1;
    }
    if (tcgetattr(fd, &toptions) < 0) {
        perror("Couldn't get term attributes");
        return -1;
    }
    unsigned int brate = baud;
    switch(baud) {
    case 4800: brate=0000014; break;
    case 9600: brate=0000015; break;
    case 19200: brate=0000016; break;
    case 38400: brate=0000017; break;
    case 57600: brate=0010001; break;
    case 115200: brate=0010002; break;
    }
    cfsetispeed(&toptions, brate);
    cfsetospeed(&toptions, brate);
    switch (parity)
    {
        case 'n':
        case 'N':
            toptions.c_cflag &= ~0000400;
            break;
        case 'o':
        case 'O':
            toptions.c_cflag |= 0000400;
            toptions.c_cflag |= 0001000;
            break;
        case 'e':
        case 'E':
            toptions.c_cflag |= 0000400;
            toptions.c_cflag &= ~0001000;
            break;
        default:
            return -1;
    }
    toptions.c_cflag &= ~0000100;
    toptions.c_cflag &= ~0000060;
    toptions.c_cflag |= 0000060;
    toptions.c_cflag &= ~020000000000;
    toptions.c_cflag |= 0000200 | 0004000;
    toptions.c_iflag &= ~(0002000 | 0010000 | 0004000);
    toptions.c_lflag &= ~(0000002 | 0000010 | 0000020 | 0000001);
    toptions.c_oflag &= ~0000001;
    toptions.c_cc[6] = 0;
    toptions.c_cc[5] = 0;
    tcsetattr(fd, 0, &toptions);
    if( tcsetattr(fd, 2, &toptions) < 0) {
        perror(">Couldn't set term attributes");
        return -1;
    }
    return fd;
}

variable_types:
serialport
char *

variable_types: baud int

variable_types: parity char

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types: fd int

variable_types:
brate
unsigned int

return_type: int


decompiled_code:
// attributes: thunk
int serialport_close(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int func1(int fd)
{
return close(fd);
}

original_code:
int serialport_close( int fd )
{
    return close( fd );
}

canonical_original_code:
int serialport_close(int fd)
{
    return close( fd );
}


decompiled_code:
__int64 __fastcall serialport_writebyte(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return (unsigned int)-((unsigned int)write(a1, buf, 1uLL) != 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return (unsigned int)-((unsigned int)write(a1, buf, 1uLL) != 1);
}

original_code:
int serialport_writebyte( int fd, uint8_t b)
{
    int n = write(fd,&b,1);
    if( n!=1)
        return -1;
    return 0;
}

canonical_original_code:
int serialport_writebyte(int fd, unsigned char b)
{
    int n = write(fd,&b,1);
    if( n!=1)
        return -1;
    return 0;
}

variable_types:
b
unsigned char

variable_types: n int


decompiled_code:
__int64 __fastcall serialport_write(int fd, char *s)
{
int v2; // ebx

v2 = strlen(s);
return (unsigned int)-(v2 != (unsigned int)write(fd, s, v2));
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, char *s)
{
int v2; // ebx

v2 = strlen(s);
return (unsigned int)-(v2 != (unsigned int)write(fd, s, v2));
}

original_code:
int serialport_write(int fd, const char* str)
{
    int len = strlen(str);
    int n = write(fd, str, len);
    if( n!=len ) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int serialport_write(int fd, char *str)
{
    int len = strlen(str);
    int n = write(fd, str, len);
    if( n!=len ) {
        return -1;
    }
    return 0;
}

variable_types:
str
char *

variable_types: len int


decompiled_code:
__int64 __fastcall serialport_read_until(int fd, __int64 a2, char a3, int a4, int a5)
{
int v5; // er15
char v9; // al
__int64 v10; // rdx
unsigned int v11; // eax
unsigned int v12; // er8
char buf[57]; // [rsp+Fh] [rbp-39h] BYREF

v5 = 0;
while ( 1 )
{
v11 = read(fd, buf, 1uLL);
v12 = v11;
if ( v11 == -1 )
return v12;
if ( v11 )
{
v9 = buf[0];
v10 = v5++;
*(_BYTE *)(a2 + v10) = buf[0];
if ( a3 == v9 )
goto LABEL_8;
}
else
{
--a5;
usleep(0x3E8u);
if ( a3 == buf[0] )
goto LABEL_8;
}
if ( v5 >= a4 || a5 <= 0 )
{
LABEL_8:
v12 = 0;
*(_BYTE *)(a2 + v5) = 0;
return v12;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __int64 a2, char a3, int a4, int a5)
{
int v5; // er15
char v9; // al
__int64 v10; // rdx
unsigned int v11; // eax
unsigned int v12; // er8
char buf[57]; // [rsp+Fh] [rbp-39h] BYREF

v5 = 0;
while ( 1 )
{
v11 = read(fd, buf, 1uLL);
v12 = v11;
if ( v11 == -1 )
return v12;
if ( v11 )
{
v9 = buf[0];
v10 = v5++;
*(_BYTE *)(a2 + v10) = buf[0];
if ( a3 == v9 )
goto LABEL_8;
}
else
{
--a5;
usleep(0x3E8u);
if ( a3 == buf[0] )
goto LABEL_8;
}
if ( v5 >= a4 || a5 <= 0 )
{
LABEL_8:
v12 = 0;
*(_BYTE *)(a2 + v5) = 0;
return v12;
}
}
}

original_code:
int serialport_read_until(int fd, char* buf, char until, int buf_max, int timeout)
{
    char b[1];
    int i=0;
    do {
        int n = read(fd, b, 1);
        if( n==-1) return -1;
        if( n==0 ) {
            usleep( 1 * 1000 );
            timeout--;
            continue;
        }
        buf[i] = b[0];
        i++;
    } while( b[0] != until && i < buf_max && timeout>0 );
    buf[i] = 0;
    return 0;
}

canonical_original_code:
int serialport_read_until(int fd, char *buf, char until, int buf_max, int timeout)
{
    char b[1];
    int i = 0;
    do {
        int n = read(fd, b, 1);
        if( n==-1) return -1;
        if( n==0 ) {
            usleep( 1 * 1000 );
            timeout--;
            continue;
        }
        buf[i] = b[0];
        i++;
    } while( b[0] != until && i < buf_max && timeout>0 );
    buf[i] = 0;
    return 0;
}

variable_types:
buf
char *

variable_types: until char

variable_types: timeout int

variable_types:
b
char [1]


decompiled_code:
int __fastcall serialport_flush(int fd)
{
sleep(1u);
return tcflush(fd, 2);
}

canonical_decompiled_code:
int __fastcall func5(int fd)
{
sleep(1u);
return tcflush(fd, 2);
}

original_code:
int serialport_flush(int fd)
{
    sleep(1);
    return tcflush(fd, 2);
}


readRawBytes

decompiled_code:
__int64 __fastcall readRawBytes(int fd, __int64 a2, int a3, int a4)
{
int v4; // ebx
int v6; // er14
__int64 v7; // rax
unsigned int v8; // eax
unsigned int v9; // er15
char buf[57]; // [rsp+Fh] [rbp-39h] BYREF

v4 = a4;
if ( a3 <= 0 || a4 <= 0 )
return (unsigned int)(2 * (v4 > 0) - 2);
v6 = 0;
while ( 1 )
{
v8 = read(fd, buf, 1uLL);
v9 = v8;
if ( v8 == -1 )
break;
if ( v8 )
{
v7 = v6++;
*(_BYTE *)(a2 + v7) = buf[0];
if ( v6 >= a3 )
return (unsigned int)(2 * (v4 > 0) - 2);
}
else
{
--v4;
usleep(0x3E8u);
if ( v6 >= a3 )
return (unsigned int)(2 * (v4 > 0) - 2);
}
if ( v4 <= 0 )
return (unsigned int)(2 * (v4 > 0) - 2);
}
puts("read problem");
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd, __int64 a2, int a3, int a4)
{
int v4; // ebx
int v6; // er14
__int64 v7; // rax
unsigned int v8; // eax
unsigned int v9; // er15
char buf[57]; // [rsp+Fh] [rbp-39h] BYREF

v4 = a4;
if ( a3 <= 0 || a4 <= 0 )
return (unsigned int)(2 * (v4 > 0) - 2);
v6 = 0;
while ( 1 )
{
v8 = read(fd, buf, 1uLL);
v9 = v8;
if ( v8 == -1 )
break;
if ( v8 )
{
v7 = v6++;
*(_BYTE *)(a2 + v7) = buf[0];
if ( v6 >= a3 )
return (unsigned int)(2 * (v4 > 0) - 2);
}
else
{
--v4;
usleep(0x3E8u);
if ( v6 >= a3 )
return (unsigned int)(2 * (v4 > 0) - 2);
}
if ( v4 <= 0 )
return (unsigned int)(2 * (v4 > 0) - 2);
}
puts("read problem");
return v9;
}

original_code:
int readRawBytes(int fd,char* buffer,int desiredCount,int timeout)
{
    int n;
    int i=0;
    char b[1];
    while((i<desiredCount)&&(timeout>0))
    {
        n = read(fd, b, 1);
        if(n==-1)
        {
            printf("read problem\n");
            return -1;
        }
        else if(n==0)
        {
            usleep(1000);
            timeout--;
        }
        else
        {
            buffer[i++] = b[0];
        }
    }
    if(!(timeout>0))
    {
        return -2;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int readRawBytes(int fd, char *buffer, int desiredCount, int timeout)
{
    int n;
    int i = 0;
    char b[1];
    while((i<desiredCount)&&(timeout>0))
    {
        n = read(fd, b, 1);
        if(n==-1)
        {
            printf("read problem\n");
            return -1;
        }
        else if(n==0)
        {
            usleep(1000);
            timeout--;
        }
        else
        {
            buffer[i++] = b[0];
        }
    }
    if(!(timeout>0))
    {
        return -2;
    }
    else
    {
        return 0;
    }
}

variable_types:
buffer
char *

variable_types: desiredCount int

variable_types: i int


repo: keiichishima/tahoefs

original_code:
int
tahoe_statfs(const char *path, struct statvfs *statvfsp)
{
  memset(statvfsp, 0, sizeof(struct statvfs));
  statvfsp->f_bsize = 512;
  statvfsp->f_frsize = statvfsp->f_bsize;
  statvfsp->f_blocks = 1024 * 1024;
  statvfsp->f_bfree = statvfsp->f_blocks;
  statvfsp->f_bavail = statvfsp->f_blocks;
  statvfsp->f_flag = ST_NOSUID;
  statvfsp->f_namemax = 1024;
  return (0);
}

canonical_original_code:
int tahoe_statfs(char *path, struct statvfs *statvfsp)
{
  memset(statvfsp, 0, sizeof(struct statvfs));
  statvfsp->f_bsize = 512;
  statvfsp->f_frsize = statvfsp->f_bsize;
  statvfsp->f_blocks = 1024 * 1024;
  statvfsp->f_bfree = statvfsp->f_blocks;
  statvfsp->f_bavail = statvfsp->f_blocks;
  statvfsp->f_flag = ST_NOSUID;
  statvfsp->f_namemax = 1024;
  return (0);
}

variable_types:
path
char *

variable_types: struct statvfs { unsigned long f_bsize; unsigned long f_frsize; unsigned long f_blocks; unsigned long f_bfree; unsigned long f_bavail; unsigned long f_files; unsigned long f_ffree; unsigned long f_favail; unsigned long f_fsid; unsigned long f_flag; unsigned long f_namemax; int __f_spare[6]; } *


decompiled_code:
__int64 __fastcall tahoe_create(const char *a1)
{
int v1; // er12

v1 = filecache_create();
if ( !v1 )
return 0LL;
warnx("failed to create a file %s.", a1);
return (unsigned int)-v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v1; // er12

v1 = filecache_create();
if ( !v1 )
return 0LL;
warnx("failed to create a file %s.", a1);
return (unsigned int)-v1;
}

original_code:
static int
tahoe_create(const char *path, mode_t mode, struct fuse_file_info *fi)
{
  int errcode = 0;
  errcode = filecache_create(path, mode);
  if (errcode) {
    warnx("failed to create a file %s.", path);
    return (-errcode);
  }
  return (0);
}

canonical_original_code:
static int tahoe_create(char *path, unsigned int mode, struct fuse_file_info *fi)
{
  int errcode = 0;
  errcode = filecache_create(path, mode);
  if (errcode) {
    warnx("failed to create a file %s.", path);
    return (-errcode);
  }
  return (0);
}

variable_types:
mode
unsigned int

variable_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *

variable_types: errcode int


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

result = http_stub_terminate();
if ( (_DWORD)result == -1 )
errx(1, "failed to teminate the http_stub module.");
return result;
}

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

result = http_stub_terminate();
if ( (_DWORD)result == -1 )
errx(1, "failed to teminate the http_stub module.");
return result;
}

original_code:
static void
tahoe_destroy(void *dummy)
{
  if (http_stub_terminate() == -1) {
    errx(1, "failed to teminate the http_stub module.");
  }
}

variable_types:
dummy
void *

return_type: void


decompiled_code:
__int64 tahoe_init()
{
if ( (unsigned int)http_stub_initialize() == -1 )
errx(1, "failed to initialize the http_stub module.");
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
if ( (unsigned int)http_stub_initialize() == -1 )
errx(1, "failed to initialize the http_stub module.");
return 0LL;
}

original_code:
static void *
tahoe_init(struct fuse_conn_info *conn)
{
  if (http_stub_initialize() == -1) {
    errx(1, "failed to initialize the http_stub module.");
  }
  return (((void *)0));
}

canonical_original_code:
static void *tahoe_init(struct fuse_conn_info *conn)
{
  if (http_stub_initialize() == -1) {
    errx(1, "failed to initialize the http_stub module.");
  }
  return (((void *)0));
}

variable_types: struct fuse_conn_info { unsigned int proto_major; unsigned int proto_minor; unsigned int async_read; unsigned int max_write; unsigned int max_readahead; unsigned int capable; unsigned int want; unsigned int max_background; unsigned int congestion_threshold; unsigned int reserved[23]; } *

return_type: void *


decompiled_code:
__int64 __fastcall tahoe_readdir(const char *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
void *ptr; // [rsp+0h] [rbp-28h] BYREF
char v6[32]; // [rsp+8h] [rbp-20h] BYREF

ptr = 0LL;
if ( (unsigned int)http_stub_get_info(a1, &ptr, v6) == -1 )
{
warnx("failed to get dirnode information of %s.", a1);
result = 4294967294LL;
}
else if ( (unsigned int)json_stub_iterate_children(a2, a3, ptr, tahoe_readdir_callback) == -1 )
{
warnx("failed to iterate child nodes of %s.", a1);
free(ptr);
result = 4294967291LL;
}
else
{
free(ptr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
void *ptr; // [rsp+0h] [rbp-28h] BYREF
char v6[32]; // [rsp+8h] [rbp-20h] BYREF

ptr = 0LL;
if ( (unsigned int)http_stub_get_info(a1, &ptr, v6) == -1 )
{
warnx("failed to get dirnode information of %s.", a1);
result = 4294967294LL;
}
else if ( (unsigned int)json_stub_iterate_children(a2, a3, ptr, tahoe_readdir_callback) == -1 )
{
warnx("failed to iterate child nodes of %s.", a1);
free(ptr);
result = 4294967291LL;
}
else
{
free(ptr);
result = 0LL;
}
return result;
}

original_code:
static int
tahoe_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
       off_t offset, struct fuse_file_info *fi)
{
  char *infop = ((void *)0);
  size_t info_size;
  if (http_stub_get_info(path, &infop, &info_size) == -1) {
    warnx("failed to get dirnode information of %s.", path);
    return (-2);
  }
  if (json_stub_iterate_children(buf, filler, infop,
     tahoe_readdir_callback) == -1) {
    warnx("failed to iterate child nodes of %s.", path);
    free(infop);
    return (-5);
  }
  free(infop);
  return (0);
}

canonical_original_code:
static int tahoe_readdir(char *path, void *buf, int (*filler)(void *buf, char *name, struct stat *stbuf, long off), long offset, struct fuse_file_info *fi)
{
  char *infop = ((void *)0);
  unsigned long info_size;
  if (http_stub_get_info(path, &infop, &info_size) == -1) {
    warnx("failed to get dirnode information of %s.", path);
    return (-2);
  }
  if (json_stub_iterate_children(buf, filler, infop,
     tahoe_readdir_callback) == -1) {
    warnx("failed to iterate child nodes of %s.", path);
    free(infop);
    return (-5);
  }
  free(infop);
  return (0);
}

variable_types:
buf
void *

variable_types: int (*)(void *buf, char *name, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *stbuf, long off)

variable_types: offset long

variable_types:
infop
char *

user_defined_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


original_code:
static int
tahoefs_tstat_to_stat(const tahoefs_stat_t *tstatp, struct stat *statp)
{
  ((void) sizeof ((tstatp != ((void *)0)) ? 1 : 0), __extension__ ({ if (tstatp != ((void *)0)) ; else __assert_fail ("tstatp != NULL", "tahoefs.c", 323, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((statp != ((void *)0)) ? 1 : 0), __extension__ ({ if (statp != ((void *)0)) ; else __assert_fail ("statp != NULL", "tahoefs.c", 324, __extension__ __PRETTY_FUNCTION__); }));
  switch (tstatp->type) {
  case 2:
    statp->st_mode = (0100000|0400);
    statp->st_size = tstatp->size;
    break;
  case 1:
    statp->st_mode = (0040000|0400|0100);
    statp->st_size = 0;
    break;
  default:
    warn("unknown tahoefs stat type %d.", tstatp->type);
    return (-1);
  }
  if (tstatp->mutable) {
    statp->st_mode = (statp->st_mode|0200);
  }
  statp->st_nlink = 1;
  statp->st_uid = getuid();
  statp->st_gid = getgid();
  statp->st_blocks = 0;
  statp->st_atim.tv_sec = statp->st_ctim.tv_sec = statp->st_mtim.tv_sec
    = tstatp->link_modification_time;
  return (0);
}

canonical_original_code:
static int tahoefs_tstat_to_stat(struct tahoefs_stat *tstatp, struct stat *statp)
{
  ((void) sizeof ((tstatp != ((void *)0)) ? 1 : 0), __extension__ ({ if (tstatp != ((void *)0)) ; else __assert_fail ("tstatp != NULL", "tahoefs.c", 323, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((statp != ((void *)0)) ? 1 : 0), __extension__ ({ if (statp != ((void *)0)) ; else __assert_fail ("statp != NULL", "tahoefs.c", 324, __extension__ __PRETTY_FUNCTION__); }));
  switch (tstatp->type) {
  case 2:
    statp->st_mode = (0100000|0400);
    statp->st_size = tstatp->size;
    break;
  case 1:
    statp->st_mode = (0040000|0400|0100);
    statp->st_size = 0;
    break;
  default:
    warn("unknown tahoefs stat type %d.", tstatp->type);
    return (-1);
  }
  if (tstatp->mutable) {
    statp->st_mode = (statp->st_mode|0200);
  }
  statp->st_nlink = 1;
  statp->st_uid = getuid();
  statp->st_gid = getgid();
  statp->st_blocks = 0;
  statp->st_atim.tv_sec = statp->st_ctim.tv_sec = statp->st_mtim.tv_sec
    = tstatp->link_modification_time;
  return (0);
}

variable_types: struct tahoefs_stat { int type; char rw_uri[128]; char ro_uri[128]; char verify_uri[128]; unsigned long size; int mutable; double link_creation_time; double link_modification_time; } *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *


decompiled_code:
__int64 __fastcall tahoe_readdir_callback(__int64 a1)
{
unsigned int v1; // er12
_BYTE v3[144]; // [rsp+0h] [rbp-268h] BYREF
unsigned int v4[118]; // [rsp+90h] [rbp-1D8h] BYREF

if ( !a1 )
_assert_fail("batonp != NULL", "tahoefs.c", 0xEAu, "tahoe_readdir_callback");
memset(v4, 0, 0x1A8uLL);
v1 = json_stub_jsonstring_to_tstat(*(_QWORD *)(a1 + 8), v4);
if ( v1 == -1 )
{
warnx("failed to convert JSON stat data to tahoefs stat.");
}
else
{
memset(v3, 0, sizeof(v3));
v1 = tahoefs_tstat_to_stat(v4, (__int64)v3);
if ( v1 == -1 )
{
warnx("failed to convert tahoefs_stat_t{} to stat{}.");
}
else if ( (*(unsigned int (__fastcall **)(_QWORD, _QWORD, _BYTE *, _QWORD))(a1 + 24))(
*(_QWORD *)(a1 + 16),
*(_QWORD *)a1,
v3,
0LL) == 1 )
{
v1 = -1;
warnx("failed to fill directory list buffer.");
}
else
{
v1 = 0;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int v1; // er12
_BYTE v3[144]; // [rsp+0h] [rbp-268h] BYREF
unsigned int v4[118]; // [rsp+90h] [rbp-1D8h] BYREF

if ( !a1 )
_assert_fail("batonp != NULL", "tahoefs.c", 0xEAu, "tahoe_readdir_callback");
memset(v4, 0, 0x1A8uLL);
v1 = json_stub_jsonstring_to_tstat(*(_QWORD *)(a1 + 8), v4);
if ( v1 == -1 )
{
warnx("failed to convert JSON stat data to tahoefs stat.");
}
else
{
memset(v3, 0, sizeof(v3));
v1 = func5(v4, (__int64)v3);
if ( v1 == -1 )
{
warnx("failed to convert tahoefs_stat_t{} to stat{}.");
}
else if ( (*(unsigned int (__fastcall **)(_QWORD, _QWORD, _BYTE *, _QWORD))(a1 + 24))(
*(_QWORD *)(a1 + 16),
*(_QWORD *)a1,
v3,
0LL) == 1 )
{
v1 = -1;
warnx("failed to fill directory list buffer.");
}
else
{
v1 = 0;
}
}
return v1;
}

original_code:
static int
tahoe_readdir_callback(tahoefs_readdir_baton_t *batonp)
{
  ((void) sizeof ((batonp != ((void *)0)) ? 1 : 0), __extension__ ({ if (batonp != ((void *)0)) ; else __assert_fail ("batonp != NULL", "tahoefs.c", 234, __extension__ __PRETTY_FUNCTION__); }));
  tahoefs_stat_t tstat;
  memset(&tstat, 0, sizeof(tahoefs_stat_t));
  if (json_stub_jsonstring_to_tstat(batonp->infop, &tstat) == -1) {
    warnx("failed to convert JSON stat data to tahoefs stat.");
    return (-1);
  }
  struct stat stat;
  memset(&stat, 0, sizeof(struct stat));
  if (tahoefs_tstat_to_stat(&tstat, &stat) == -1) {
    warnx("failed to convert tahoefs_stat_t{} to stat{}.");
    return (-1);
  }
  fuse_fill_dir_t filler = (fuse_fill_dir_t)batonp->fillerp;
  if (filler(batonp->nodename_listp, batonp->nodename, &stat, 0) == 1) {
    warnx("failed to fill directory list buffer.");
    return (-1);
  };
  return (0);
}

canonical_original_code:
static int tahoe_readdir_callback(struct tahoefs_readdir_baton *batonp)
{
  ((void) sizeof ((batonp != ((void *)0)) ? 1 : 0), __extension__ ({ if (batonp != ((void *)0)) ; else __assert_fail ("batonp != NULL", "tahoefs.c", 234, __extension__ __PRETTY_FUNCTION__); }));
  struct tahoefs_stat tstat;
  memset(&tstat, 0, sizeof(tahoefs_stat_t));
  if (json_stub_jsonstring_to_tstat(batonp->infop, &tstat) == -1) {
    warnx("failed to convert JSON stat data to tahoefs stat.");
    return (-1);
  }
  struct stat stat;
  memset(&stat, 0, sizeof(struct stat));
  if (tahoefs_tstat_to_stat(&tstat, &stat) == -1) {
    warnx("failed to convert tahoefs_stat_t{} to stat{}.");
    return (-1);
  }
  int (*filler)(void *buf, char *name, struct stat *stbuf, long off) = (fuse_fill_dir_t)batonp->fillerp;
  if (filler(batonp->nodename_listp, batonp->nodename, &stat, 0) == 1) {
    warnx("failed to fill directory list buffer.");
    return (-1);
  };
  return (0);
}

variable_types: struct tahoefs_readdir_baton { char *nodename; char *infop; void *nodename_listp; void *fillerp; } *

variable_types: struct tahoefs_stat { int type; char rw_uri[128]; char ro_uri[128]; char verify_uri[128]; unsigned long size; int mutable; double link_creation_time; double link_modification_time; }

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall tahoe_flush(const char *a1, unsigned int *a2)
{
int v2; // er12

v2 = filecache_flush(a1, *a2);
if ( !v2 )
return 0LL;
warnx("failed to flush modified contents of %s", a1);
return (unsigned int)-v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, unsigned int *a2)
{
int v2; // er12

v2 = filecache_flush(a1, *a2);
if ( !v2 )
return 0LL;
warnx("failed to flush modified contents of %s", a1);
return (unsigned int)-v2;
}

original_code:
static int
tahoe_flush(const char *path, struct fuse_file_info *fi)
{
  int errcode = 0;
  errcode = filecache_flush(path, fi->flags);
  if (errcode) {
    warnx("failed to flush modified contents of %s", path);
    return (-errcode);
  }
  return (0);
}

canonical_original_code:
static int tahoe_flush(char *path, struct fuse_file_info *fi)
{
  int errcode = 0;
  errcode = filecache_flush(path, fi->flags);
  if (errcode) {
    warnx("failed to flush modified contents of %s", path);
    return (-errcode);
  }
  return (0);
}


decompiled_code:
__int64 __fastcall tahoe_write(const char *a1, __int64 a2, __int64 a3, __int64 a4, unsigned int *a5)
{
unsigned int v7; // er12

v7 = filecache_write(a1, a2, a3, a4, *a5);
if ( v7 == -1 )
warnx("write %ld bytes at %ld to %s failed", a3, a4, a1);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, __int64 a2, __int64 a3, __int64 a4, unsigned int *a5)
{
unsigned int v7; // er12

v7 = filecache_write(a1, a2, a3, a4, *a5);
if ( v7 == -1 )
warnx("write %ld bytes at %ld to %s failed", a3, a4, a1);
return v7;
}

original_code:
static int
tahoe_write(const char *path, const char *buf, size_t size, off_t offset,
     struct fuse_file_info *fi)
{
  int nwritten = filecache_write(path, buf, size, offset, fi->flags);
  if (nwritten == -1) {
    warnx("write %ld bytes at %ld to %s failed", size, offset, path);
    return (-1);
  }
  return (nwritten);
}

canonical_original_code:
static int tahoe_write(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *fi)
{
  int nwritten = filecache_write(path, buf, size, offset, fi->flags);
  if (nwritten == -1) {
    warnx("write %ld bytes at %ld to %s failed", size, offset, path);
    return (-1);
  }
  return (nwritten);
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types: nwritten int


decompiled_code:
__int64 __fastcall tahoe_read(const char *a1, __int64 a2, __int64 a3, __int64 a4, unsigned int *a5)
{
unsigned int v7; // er12

v7 = filecache_read(a1, a2, a3, a4, *a5);
if ( v7 == -1 )
warnx("read %ld bytes at %ld from %s failed.", a3, a4, a1);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, __int64 a2, __int64 a3, __int64 a4, unsigned int *a5)
{
unsigned int v7; // er12

v7 = filecache_read(a1, a2, a3, a4, *a5);
if ( v7 == -1 )
warnx("read %ld bytes at %ld from %s failed.", a3, a4, a1);
return v7;
}

original_code:
static int
tahoe_read(const char *path, char *buf, size_t size, off_t offset,
    struct fuse_file_info *fi)
{
  int nread = filecache_read(path, buf, size, offset, fi->flags);
  if (nread == -1) {
    warnx("read %ld bytes at %ld from %s failed.", size, offset, path);
    return (-1);
  }
  return (nread);
}

canonical_original_code:
static int tahoe_read(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *fi)
{
  int nread = filecache_read(path, buf, size, offset, fi->flags);
  if (nread == -1) {
    warnx("read %ld bytes at %ld from %s failed.", size, offset, path);
    return (-1);
  }
  return (nread);
}

variable_types:
path
char *

variable_types: nread int


decompiled_code:
__int64 __fastcall tahoe_open(const char *a1, unsigned int *a2)
{
int v2; // er12

v2 = filecache_open(a1, *a2);
if ( !v2 )
return 0LL;
warnx("failed to open a file %s", a1);
return (unsigned int)-v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, unsigned int *a2)
{
int v2; // er12

v2 = filecache_open(a1, *a2);
if ( !v2 )
return 0LL;
warnx("failed to open a file %s", a1);
return (unsigned int)-v2;
}

original_code:
static int
tahoe_open(const char *path, struct fuse_file_info *fi)
{
  int errcode = 0;
  errcode = filecache_open(path, fi->flags);
  if (errcode) {
    warnx("failed to open a file %s", path);
    return (-errcode);
  }
  return (0);
}

canonical_original_code:
static int tahoe_open(char *path, struct fuse_file_info *fi)
{
  int errcode = 0;
  errcode = filecache_open(path, fi->flags);
  if (errcode) {
    warnx("failed to open a file %s", path);
    return (-errcode);
  }
  return (0);
}

variable_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *

variable_types: errcode int


decompiled_code:
__int64 __fastcall tahoe_rmdir(const char *a1)
{
int v1; // er12

v1 = filecache_rmdir();
if ( !v1 )
return 0LL;
warnx("failed to remove a directory %s", a1);
return (unsigned int)-v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
int v1; // er12

v1 = filecache_rmdir();
if ( !v1 )
return 0LL;
warnx("failed to remove a directory %s", a1);
return (unsigned int)-v1;
}

original_code:
static int
tahoe_rmdir(const char *path)
{
  int errcode = 0;
  errcode = filecache_rmdir(path);
  if (errcode) {
    warnx("failed to remove a directory %s", path);
    return (-errcode);
  }
  return (0);
}

canonical_original_code:
static int tahoe_rmdir(char *path)
{
  int errcode = 0;
  errcode = filecache_rmdir(path);
  if (errcode) {
    warnx("failed to remove a directory %s", path);
    return (-errcode);
  }
  return (0);
}


decompiled_code:
__int64 __fastcall tahoe_unlink(const char *a1)
{
int v1; // er12

v1 = filecache_unlink();
if ( !v1 )
return 0LL;
warnx("failed to unlink file %s.", a1);
return (unsigned int)-v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1)
{
int v1; // er12

v1 = filecache_unlink();
if ( !v1 )
return 0LL;
warnx("failed to unlink file %s.", a1);
return (unsigned int)-v1;
}

original_code:
static int
tahoe_unlink(const char *path)
{
  int errcode = 0;
  errcode = filecache_unlink(path);
  if (errcode) {
    warnx("failed to unlink file %s.", path);
    return (-errcode);
  }
  return (0);
}

canonical_original_code:
static int tahoe_unlink(char *path)
{
  int errcode = 0;
  errcode = filecache_unlink(path);
  if (errcode) {
    warnx("failed to unlink file %s.", path);
    return (-errcode);
  }
  return (0);
}


decompiled_code:
__int64 __fastcall tahoe_mkdir(const char *a1)
{
int v1; // er12

v1 = filecache_mkdir(a1, 16832LL);
if ( !v1 )
return 0LL;
warnx("failed to create a directory %s", a1);
return (unsigned int)-v1;
}

canonical_decompiled_code:
__int64 __fastcall func13(const char *a1)
{
int v1; // er12

v1 = filecache_mkdir(a1, 16832LL);
if ( !v1 )
return 0LL;
warnx("failed to create a directory %s", a1);
return (unsigned int)-v1;
}

original_code:
static int
tahoe_mkdir(const char *path, mode_t mode)
{
  int errcode = 0;
  mode_t tahoe_mode = 0040000|(0400|0200|0100);
  errcode = filecache_mkdir(path, tahoe_mode);
  if (errcode) {
    warnx("failed to create a directory %s", path);
    return (-errcode);
  }
  return (0);
}

canonical_original_code:
static int tahoe_mkdir(char *path, unsigned int mode)
{
  int errcode = 0;
  unsigned int tahoe_mode = 0040000|(0400|0200|0100);
  errcode = filecache_mkdir(path, tahoe_mode);
  if (errcode) {
    warnx("failed to create a directory %s", path);
    return (-errcode);
  }
  return (0);
}

variable_types:
mode
unsigned int


decompiled_code:
__int64 __fastcall tahoe_getattr(const char *a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // er12
int v5; // er12
__int64 v6; // [rsp+8h] [rbp-1E0h] BYREF
unsigned int v7[118]; // [rsp+10h] [rbp-1D8h] BYREF

memset(v7, 0, 0x1A8uLL);
v2 = filecache_getattr(a1, v7);
if ( v2 )
{
v5 = v2;
warnx("failed to get file info of %s.", a1);
v3 = -v5;
}
else if ( (unsigned int)tahoefs_tstat_to_stat(v7, a2) == -1 )
{
v3 = -2;
warnx("failed to convert tahoefs_stat_t{} to stat{}.");
}
else
{
v3 = v7[100];
if ( v7[100] )
{
v3 = 0;
if ( v7[0] == 2 )
{
v3 = filecache_get_real_size(a1, &v6);
if ( v3 )
{
v3 = -v3;
warnx("failed to get the size of the mutable file %s.", a1);
}
else
{
*(_QWORD *)(a2 + 48) = v6;
}
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // er12
int v5; // er12
__int64 v6; // [rsp+8h] [rbp-1E0h] BYREF
unsigned int v7[118]; // [rsp+10h] [rbp-1D8h] BYREF

memset(v7, 0, 0x1A8uLL);
v2 = filecache_getattr(a1, v7);
if ( v2 )
{
v5 = v2;
warnx("failed to get file info of %s.", a1);
v3 = -v5;
}
else if ( (unsigned int)func5(v7, a2) == -1 )
{
v3 = -2;
warnx("failed to convert tahoefs_stat_t{} to stat{}.");
}
else
{
v3 = v7[100];
if ( v7[100] )
{
v3 = 0;
if ( v7[0] == 2 )
{
v3 = filecache_get_real_size(a1, &v6);
if ( v3 )
{
v3 = -v3;
warnx("failed to get the size of the mutable file %s.", a1);
}
else
{
*(_QWORD *)(a2 + 48) = v6;
}
}
}
}
return v3;
}

original_code:
static int
tahoe_getattr(const char *path, struct stat *statp)
{
  int errcode = 0;
  tahoefs_stat_t tstat;
  memset(&tstat, 0, sizeof(tahoefs_stat_t));
  errcode = filecache_getattr(path, &tstat);
  if (errcode) {
    warnx("failed to get file info of %s.", path);
    return (-errcode);
  }
  if (tahoefs_tstat_to_stat(&tstat, statp) == -1) {
    warnx("failed to convert tahoefs_stat_t{} to stat{}.");
    return (-2);
  }
  if (tstat.mutable && tstat.type == 2) {
    errcode = 0;
    size_t real_size;
    errcode = filecache_get_real_size(path, &real_size);
    if (errcode) {
      warnx("failed to get the size of the mutable file %s.", path);
      return (-errcode);
    }
    statp->st_size = real_size;
  }
  return (0);
}

canonical_original_code:
static int tahoe_getattr(char *path, struct stat *statp)
{
  int errcode = 0;
  struct tahoefs_stat tstat;
  memset(&tstat, 0, sizeof(tahoefs_stat_t));
  errcode = filecache_getattr(path, &tstat);
  if (errcode) {
    warnx("failed to get file info of %s.", path);
    return (-errcode);
  }
  if (tahoefs_tstat_to_stat(&tstat, statp) == -1) {
    warnx("failed to convert tahoefs_stat_t{} to stat{}.");
    return (-2);
  }
  if (tstat.mutable && tstat.type == 2) {
    errcode = 0;
    unsigned long real_size;
    errcode = filecache_get_real_size(path, &real_size);
    if (errcode) {
      warnx("failed to get the size of the mutable file %s.", path);
      return (-errcode);
    }
    statp->st_size = real_size;
  }
  return (0);
}

user_defined_types: struct tahoefs_stat { int type; char rw_uri[128]; char ro_uri[128]; char verify_uri[128]; unsigned long size; int mutable; double link_creation_time; double link_modification_time; }

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


decompiled_code:
int __fastcall tahoefs_usage(const char *a1)
{
return fprintf(
stderr,
"usage: %s mountpoint [options]\n"
"\n"
"TAHOEFS options:\n"
" -t tahoedir .tahoe directory (default: .tahoe)\n"
" --tahoe-dir=tahoedir same as '-t tahoedir'\n"
" -r rootcap root_cap URI (default: your 'tahoe:' alias)\n"
" --root-cap=rootcap same as '-r rootcap'\n"
" -s server webapi server address (default: localhost)\n"
" --server=server same as '-s server'\n"
" -p port webapi server port (default: 3456)\n"
" --port=port same as '-p port'\n"
" -c cachedir local cache directory (default: .tahoefs)\n"
" --cache-dir=cachedir same as '-c cachedir'\n"
"\n"
"FUSE options:\n"
" -d enable debug output (implies -f)\n"
" -f foreground operation\n"
"\n",
a1);
}

canonical_decompiled_code:
int __fastcall func15(const char *a1)
{
return fprintf(
stderr,
"usage: %s mountpoint [options]\n"
"\n"
"TAHOEFS options:\n"
" -t tahoedir .tahoe directory (default: .tahoe)\n"
" --tahoe-dir=tahoedir same as '-t tahoedir'\n"
" -r rootcap root_cap URI (default: your 'tahoe:' alias)\n"
" --root-cap=rootcap same as '-r rootcap'\n"
" -s server webapi server address (default: localhost)\n"
" --server=server same as '-s server'\n"
" -p port webapi server port (default: 3456)\n"
" --port=port same as '-p port'\n"
" -c cachedir local cache directory (default: .tahoefs)\n"
" --cache-dir=cachedir same as '-c cachedir'\n"
"\n"
"FUSE options:\n"
" -d enable debug output (implies -f)\n"
" -f foreground operation\n"
"\n",
a1);
}

original_code:
static void
tahoefs_usage(const char *progname)
{
  fprintf(stderr,
"usage: %s mountpoint [options]\n"
"\n"
"TAHOEFS options:\n"
"    -t tahoedir           .tahoe directory (default: .tahoe)\n"
"    --tahoe-dir=tahoedir  same as '-t tahoedir'\n"
"    -r rootcap            root_cap URI (default: your 'tahoe:' alias)\n"
"    --root-cap=rootcap    same as '-r rootcap'\n"
"    -s server             webapi server address (default: localhost)\n"
"    --server=server       same as '-s server'\n"
"    -p port               webapi server port (default: 3456)\n"
"    --port=port           same as '-p port'\n"
"    -c cachedir           local cache directory (default: .tahoefs)\n"
"    --cache-dir=cachedir  same as '-c cachedir'\n"
"\n"
"FUSE options:\n"
"    -d                    enable debug output (implies -f)\n"
"    -f                    foreground operation\n"
"\n", progname);
}

canonical_original_code:
static void tahoefs_usage(char *progname)
{
  fprintf(stderr,
"usage: %s mountpoint [options]\n"
"\n"
"TAHOEFS options:\n"
"    -t tahoedir           .tahoe directory (default: .tahoe)\n"
"    --tahoe-dir=tahoedir  same as '-t tahoedir'\n"
"    -r rootcap            root_cap URI (default: your 'tahoe:' alias)\n"
"    --root-cap=rootcap    same as '-r rootcap'\n"
"    -s server             webapi server address (default: localhost)\n"
"    --server=server       same as '-s server'\n"
"    -p port               webapi server port (default: 3456)\n"
"    --port=port           same as '-p port'\n"
"    -c cachedir           local cache directory (default: .tahoefs)\n"
"    --cache-dir=cachedir  same as '-c cachedir'\n"
"\n"
"FUSE options:\n"
"    -d                    enable debug output (implies -f)\n"
"    -f                    foreground operation\n"
"\n", progname);
}

variable_types:
progname
char *


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

if ( a3 )
{
if ( a3 == 1 )
{
tahoefs_usage(**(const char ***)(a4 + 8));
fuse_opt_add_arg(a4, "-ho");
exit(1);
}
result = 1LL;
}
else
{
*((_DWORD *)&config + 10) = 1;
result = 1LL;
}
return result;
}

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

if ( a3 )
{
if ( a3 == 1 )
{
func15(**(const char ***)(a4 + 8));
fuse_opt_add_arg(a4, "-ho");
exit(1);
}
result = 1LL;
}
else
{
*((_DWORD *)&config + 10) = 1;
result = 1LL;
}
return result;
}

original_code:
static int
tahoefs_opt_proc(void *data, const char *arg, int key,
   struct fuse_args *outargs)
{
  switch (key) {
  case OPTKEY_DEBUG:
    config.debug = 1;
    break;
  case OPTKEY_HELP:
    tahoefs_usage(outargs->argv[0]);
    fuse_opt_add_arg(outargs, "-ho");
    exit(1);
  }
  return (1);
}

canonical_original_code:
static int tahoefs_opt_proc(void *data, char *arg, int key, struct fuse_args *outargs)
{
  switch (key) {
  case OPTKEY_DEBUG:
    config.debug = 1;
    break;
  case OPTKEY_HELP:
    tahoefs_usage(outargs->argv[0]);
    fuse_opt_add_arg(outargs, "-ho");
    exit(1);
  }
  return (1);
}

variable_types:
data
void *

variable_types:
arg
char *

variable_types: key int

variable_types: struct fuse_args { int argc; char **argv; int allocated; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rax
unsigned int v5; // [rsp+0h] [rbp-28h] BYREF
const char **v6; // [rsp+8h] [rbp-20h]
int v7; // [rsp+10h] [rbp-18h]

v5 = argc;
v6 = argv;
*(_OWORD *)(&config + 1) = 0LL;
*(&config + 5) = 0LL;
config = ".tahoe";
*(&config + 2) = "localhost";
*(&config + 3) = "3456";
*(&config + 4) = ".tahoefs";
v7 = 0;
if ( (unsigned int)fuse_opt_parse(&v5, &config, &tahoefs_opts, tahoefs_opt_proc) == -1 )
errx(1, "failed to parse options.");
if ( !*(&config + 1) )
{
v4 = (char *)tahoe_default_root_cap();
*(&config + 1) = v4;
if ( !v4 )
err(1, "failed to get your ROOT_CAP information.");
}
return fuse_main_real(v5, v6, &tahoe_oper, 360LL, 0LL);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rax
unsigned int v5; // [rsp+0h] [rbp-28h] BYREF
const char **v6; // [rsp+8h] [rbp-20h]
int v7; // [rsp+10h] [rbp-18h]

v5 = argc;
v6 = argv;
*(_OWORD *)(&config + 1) = 0LL;
*(&config + 5) = 0LL;
config = ".tahoe";
*(&config + 2) = "localhost";
*(&config + 3) = "3456";
*(&config + 4) = ".tahoefs";
v7 = 0;
if ( (unsigned int)fuse_opt_parse(&v5, &config, &tahoefs_opts, tahoefs_opt_proc) == -1 )
errx(1, "failed to parse options.");
if ( !*(&config + 1) )
{
v4 = (char *)func17();
*(&config + 1) = v4;
if ( !v4 )
err(1, "failed to get your ROOT_CAP information.");
}
return fuse_main_real(v5, v6, &tahoe_oper, 360LL, 0LL);
}

original_code:
int
main(int argc, char *argv[])
{
  memset(&config, 0, sizeof(tahoefs_global_config_t));
  config.tahoe_dir = ".tahoe";
  config.webapi_server = "localhost";
  config.webapi_port = "3456";
  config.filecache_dir = ".tahoefs";
  struct fuse_args args = { argc, argv, 0 };
  if (fuse_opt_parse(&args, &config, tahoefs_opts,
       tahoefs_opt_proc) == -1) {
    errx(1, "failed to parse options.");
  }
  if (config.root_cap == ((void *)0)) {
    config.root_cap = tahoe_default_root_cap();
    if (config.root_cap == ((void *)0)) {
      err(1, "failed to get your ROOT_CAP information.");
    }
  }
  return fuse_main_real(args.argc, args.argv, &tahoe_oper, sizeof(*(&tahoe_oper)), ((void *)0));
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct fuse_args { int argc; char **argv; int allocated; }


getDomainRegexlst

repo: keikurono/haarp-viewer

decompiled_code:
char *__fastcall getDomainRegexlst(char *haystack)
{
__int64 v1; // rbx
char *v2; // r13
char *result; // rax
char *needle; // [rsp+0h] [rbp-128h]
char *src[36]; // [rsp+8h] [rbp-120h]

v1 = 0LL;
needle = "mediafire";
src[0] = "205\\.196\\.|199\\.91";
src[1] = "fbcdn";
src[2] = "fbcdn";
src[3] = "aol";
src[4] = "avideos";
src[5] = "pornhub";
src[6] = "pornhub";
src[7] = "porntube_vid";
src[8] = "video.{0,5}\\.porntube";
src[9] = "porntube_img";
src[10] = "thumbnails.{0,5}\\.porntube";
src[11] = "socialpg_dragoncity";
src[12] = "socialpointgames\\.com";
src[13] = "socialpg";
src[14] = "socialpointgames\\.com";
src[15] = "mercadolibre_img";
src[16] = "mlstatic\\.com";
src[17] = "GAMESF_wooga";
src[18] = "wooga\\.com";
src[19] = "GAMESF_popcap";
src[20] = "popcap\\.com";
src[21] = "GAMESF_llnwd";
src[22] = "llnwd\\.net";
src[23] = "GAMESF_cloudfront";
src[24] = "cloudfront\\.net";
src[25] = "GAMESF_amazonaws";
src[26] = "amazonaws\\.com";
src[27] = "GAMESF_akamaihd";
src[28] = "akamaihd\\.net";
src[29] = "FrivIntro";
src[30] = "\\.friv\\.com";
v2 = (char *)calloc(0x64uLL, 1uLL);
while ( 1 )
{
result = strstr(haystack, (&needle)[2 * v1]);
if ( result )
break;
if ( ++v1 == 16 )
return result;
}
return strcpy(v2, src[2 * (int)v1]);
}

canonical_decompiled_code:
char *__fastcall func1(char *haystack)
{
__int64 v1; // rbx
char *v2; // r13
char *result; // rax
char *needle; // [rsp+0h] [rbp-128h]
char *src[36]; // [rsp+8h] [rbp-120h]

v1 = 0LL;
needle = "mediafire";
src[0] = "205\\.196\\.|199\\.91";
src[1] = "fbcdn";
src[2] = "fbcdn";
src[3] = "aol";
src[4] = "avideos";
src[5] = "pornhub";
src[6] = "pornhub";
src[7] = "porntube_vid";
src[8] = "video.{0,5}\\.porntube";
src[9] = "porntube_img";
src[10] = "thumbnails.{0,5}\\.porntube";
src[11] = "socialpg_dragoncity";
src[12] = "socialpointgames\\.com";
src[13] = "socialpg";
src[14] = "socialpointgames\\.com";
src[15] = "mercadolibre_img";
src[16] = "mlstatic\\.com";
src[17] = "GAMESF_wooga";
src[18] = "wooga\\.com";
src[19] = "GAMESF_popcap";
src[20] = "popcap\\.com";
src[21] = "GAMESF_llnwd";
src[22] = "llnwd\\.net";
src[23] = "GAMESF_cloudfront";
src[24] = "cloudfront\\.net";
src[25] = "GAMESF_amazonaws";
src[26] = "amazonaws\\.com";
src[27] = "GAMESF_akamaihd";
src[28] = "akamaihd\\.net";
src[29] = "FrivIntro";
src[30] = "\\.friv\\.com";
v2 = (char *)calloc(0x64uLL, 1uLL);
while ( 1 )
{
result = strstr(haystack, (&needle)[2 * v1]);
if ( result )
break;
if ( ++v1 == 16 )
return result;
}
return strcpy(v2, src[2 * (int)v1]);
}

original_code:
char * getDomainRegexlst(char *domain) {
 char * domain2regex[16][2] = {
         {"mediafire", "205\\.196\\.|199\\.91"},
        {"fbcdn", "fbcdn"},
         {"aol", "avideos"},
         {"pornhub", "pornhub"},
         {"porntube_vid", "video.{0,5}\\.porntube"},
         {"porntube_img", "thumbnails.{0,5}\\.porntube"},
         {"socialpg_dragoncity", "socialpointgames\\.com"},
         {"socialpg", "socialpointgames\\.com"},
         {"mercadolibre_img", "mlstatic\\.com"},
         {"GAMESF_wooga", "wooga\\.com"},
         {"GAMESF_popcap", "popcap\\.com"},
         {"GAMESF_llnwd", "llnwd\\.net"},
         {"GAMESF_cloudfront", "cloudfront\\.net"},
         {"GAMESF_amazonaws", "amazonaws\\.com"},
         {"GAMESF_akamaihd", "akamaihd\\.net"},
         {"FrivIntro", "\\.friv\\.com"} };
 char *d = (char *)malloc(sizeof(char) * 100);
 memset(d, '\0', 100);
 int i;
 for ( i = 0; i < 16; i++ ) {
  if( strstr(domain, domain2regex[i][0]) ) {
   strcpy(d, domain2regex[i][1]);
   return d;
  }
 }
 return ((void *)0);
}

canonical_original_code:
char *getDomainRegexlst(char *domain) {
 char *domain2regex[16][2] = {
         {"mediafire", "205\\.196\\.|199\\.91"},
        {"fbcdn", "fbcdn"},
         {"aol", "avideos"},
         {"pornhub", "pornhub"},
         {"porntube_vid", "video.{0,5}\\.porntube"},
         {"porntube_img", "thumbnails.{0,5}\\.porntube"},
         {"socialpg_dragoncity", "socialpointgames\\.com"},
         {"socialpg", "socialpointgames\\.com"},
         {"mercadolibre_img", "mlstatic\\.com"},
         {"GAMESF_wooga", "wooga\\.com"},
         {"GAMESF_popcap", "popcap\\.com"},
         {"GAMESF_llnwd", "llnwd\\.net"},
         {"GAMESF_cloudfront", "cloudfront\\.net"},
         {"GAMESF_amazonaws", "amazonaws\\.com"},
         {"GAMESF_akamaihd", "akamaihd\\.net"},
         {"FrivIntro", "\\.friv\\.com"} };
 char *d = (char *)malloc(sizeof(char) * 100);
 memset(d, '\0', 100);
 int i;
 for ( i = 0; i < 16; i++ ) {
  if( strstr(domain, domain2regex[i][0]) ) {
   strcpy(d, domain2regex[i][1]);
   return d;
  }
 }
 return ((void *)0);
}

variable_types:
domain
char *

variable_types:
d
char *

variable_types: i int

return_type: char *


decompiled_code:
__int64 __fastcall es_name(const char *a1)
{
int v1; // eax
int v2; // ebp
const unsigned __int16 **v3; // rax
unsigned __int64 v4; // r8
__int64 v5; // rsi
__int64 v6; // rdx

v1 = strlen(a1);
if ( v1 <= 0 )
return 1LL;
v2 = v1;
v3 = _ctype_b_loc();
v4 = 0x8000000000006001LL;
v5 = (__int64)&a1[v2 - 1 + 1];
while ( 1 )
{
v6 = *a1;
if ( ((*v3)[v6] & 8) == 0
&& ((unsigned __int8)(v6 - 32) > 0x3Fu || !_bittest64((const __int64 *)&v4, (unsigned int)(v6 - 32))) )
{
break;
}
if ( (const char *)v5 == ++a1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
int v1; // eax
int v2; // ebp
const unsigned __int16 **v3; // rax
unsigned __int64 v4; // r8
__int64 v5; // rsi
__int64 v6; // rdx

v1 = strlen(a1);
if ( v1 <= 0 )
return 1LL;
v2 = v1;
v3 = _ctype_b_loc();
v4 = 0x8000000000006001LL;
v5 = (__int64)&a1[v2 - 1 + 1];
while ( 1 )
{
v6 = *a1;
if ( ((*v3)[v6] & 8) == 0
&& ((unsigned __int8)(v6 - 32) > 0x3Fu || !_bittest64((const __int64 *)&v4, (unsigned int)(v6 - 32))) )
{
break;
}
if ( (const char *)v5 == ++a1 )
return 1LL;
}
return 0LL;
}

original_code:
int es_name(char *name)
{
 int len = strlen(name);
 int i;
 for(i=0;i<len;i++)
 {
  int n = name[i];
  if(!((*__ctype_b_loc ())[(int) ((n))] & (unsigned short int) _ISalnum) && n != 32 && n != 45 && n != 95 && n != 46)
   return 0;
 }
 return 1;
}

canonical_original_code:
int es_name(char *name)
{
 int len = strlen(name);
 int i;
 for(i=0;i<len;i++)
 {
  int n = name[i];
  if(!((*__ctype_b_loc ())[(int) ((n))] & (unsigned short) _ISalnum) && n != 32 && n != 45 && n != 95 && n != 46)
   return 0;
 }
 return 1;
}

variable_types:
name
char *

variable_types: len int

variable_types: n int


original_code:
char * time_t2date(time_t t, int format_with_sec) {
 time_t min = 60;
 time_t hour = 3600;
 time_t day = 24*hour;
 char *re = (char *)malloc(sizeof(char)*150);
 char tmp[15];
 memset(re, '\0', 150);
 char coma[5];
 memset(coma, '\0', 5);
 if(t/day) {
  sprintf(re, "%li Da%s", t/day, (t/day == 1)?"y":"ys");
  t = t%day;
 } else
  sprintf(re, "0 Days");
 strcpy(coma, ", ");
 if(t/hour) {
  sprintf(tmp, "%s%li Hou%s", coma, t/hour, (t/hour == 1)?"r":"rs");
  strcat(re, tmp);
  t = t%hour;
  strcpy(coma, ", ");
 } else
  strcat(re, ", 0 Hours");
 if(t) {
  sprintf(tmp, "%s%.1lf Mi%s", coma, t/(min+0.0), (t/min == 1)?"n":"ns");
  strcat(re, tmp);
 } else {
  strcat(re, ", 0 Mins");
 }
 return re;
}

canonical_original_code:
char *time_t2date(long t, int format_with_sec) {
 long min = 60;
 long hour = 3600;
 long day = 24*hour;
 char *re = (char *)malloc(sizeof(char)*150);
 char tmp[15];
 memset(re, '\0', 150);
 char coma[5];
 memset(coma, '\0', 5);
 if(t/day) {
  sprintf(re, "%li Da%s", t/day, (t/day == 1)?"y":"ys");
  t = t%day;
 } else
  sprintf(re, "0 Days");
 strcpy(coma, ", ");
 if(t/hour) {
  sprintf(tmp, "%s%li Hou%s", coma, t/hour, (t/hour == 1)?"r":"rs");
  strcat(re, tmp);
  t = t%hour;
  strcpy(coma, ", ");
 } else
  strcat(re, ", 0 Hours");
 if(t) {
  sprintf(tmp, "%s%.1lf Mi%s", coma, t/(min+0.0), (t/min == 1)?"n":"ns");
  strcat(re, tmp);
 } else {
  strcat(re, ", 0 Mins");
 }
 return re;
}

variable_types: t long

variable_types: min long

variable_types: hour long

variable_types: day long

variable_types:
re
char *

variable_types:
tmp
char [15]

variable_types:
coma
char [5]


decompiled_code:
__int64 __fastcall logfile_init(char *src)
{
if ( !*src )
return 0LL;
strcpy(filelog, src);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src)
{
if ( !*src )
return 0LL;
strcpy(filelog, src);
return 1LL;
}

original_code:
int logfile_init(char *fl) {
 if(!strlen(fl))
  return 0;
 strcpy(filelog,fl);
 return 1;
}

variable_types:
fl
char *


normalize

repo: kelceyswain/convolver

original_code:
void normalize(float* buffer, int num_samps, float maxval)
{
    float loudest_sample = 0.0;
    float multiplier = 0.0;
    int i;
    for (i = 0; i < num_samps; i++)
    {
        if (fabs(buffer[i]) > loudest_sample) loudest_sample = buffer[i];
    }
    multiplier = maxval / loudest_sample;
    for (i = 0; i < num_samps; i++)
    {
        buffer[i] *= multiplier;
    }
}

canonical_original_code:
void normalize(float *buffer, int num_samps, float maxval)
{
    float loudest_sample = 0.0;
    float multiplier = 0.0;
    int i;
    for (i = 0; i < num_samps; i++)
    {
        if (fabs(buffer[i]) > loudest_sample) loudest_sample = buffer[i];
    }
    multiplier = maxval / loudest_sample;
    for (i = 0; i < num_samps; i++)
    {
        buffer[i] *= multiplier;
    }
}

variable_types:
buffer
float *

variable_types: maxval float

variable_types: multiplier float


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

v2 = *(void **)(a1 + 16);
if ( v2 )
{
free(v2);
*(_QWORD *)(a1 + 16) = 0LL;
}
}

original_code:
void node_free_code(struct node_t * n){
 if(!n->code) return;
 free(n->code);
 n->code = ((void *)0);
}

canonical_original_code:
void node_free_code(struct node_t *n){
 if(!n->code) return;
 free(n->code);
 n->code = ((void *)0);
}

variable_types: struct node_t { enum type_t { INTEGER=0, REAL=1, EMPTY=3, STR=4, NODE=5 } type; union { int i; float f; char *s; } x; char *code; char *valStr; unsigned int reg; } *

user_defined_types: struct node_t { enum type_t type; union { int i; float f; char *s; } x; char *code; char *valStr; unsigned int reg; }


autoAlloc

decompiled_code:
char *autoAlloc(char *format, ...)
{
size_t v1; // rbp
char *v2; // rax
char *v3; // r12
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
v1 = vsnprintf(0LL, 0LL, format, arg) + 1;
v2 = (char *)calloc(1uLL, v1);
v3 = v2;
if ( v2 )
vsnprintf(v2, v1, format, arg);
return v3;
}

canonical_decompiled_code:
char *func1(char *format, ...)
{
size_t v1; // rbp
char *v2; // rax
char *v3; // r12
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
v1 = vsnprintf(0LL, 0LL, format, arg) + 1;
v2 = (char *)calloc(1uLL, v1);
v3 = v2;
if ( v2 )
vsnprintf(v2, v1, format, arg);
return v3;
}

original_code:
char * autoAlloc(const char * fmt, ...) {
 char * err = ((void *)0);
 va_list args;
 __builtin_va_start(args,fmt);
 size_t size = vsnprintf(((void *)0),0,fmt,args) + 1;
 err = calloc(1,size);
 if(!err) return ((void *)0);
 vsnprintf(err,size,fmt,args);
 __builtin_va_end(args);
 return err;
}

canonical_original_code:
char *autoAlloc(char *fmt, ...) {
 char *err = ((void *)0);
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 unsigned long size = vsnprintf(((void *)0),0,fmt,args) + 1;
 err = calloc(1,size);
 if(!err) return ((void *)0);
 vsnprintf(err,size,fmt,args);
 __builtin_va_end(args);
 return err;
}

variable_types:
fmt
char *

variable_types:
err
char *

variable_types:
size
unsigned long


debugNode

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

switch ( *(_DWORD *)a1 )
{
case 0:
result = printf("INT(%d)\n", *((unsigned int *)a1 + 2));
break;
case 1:
result = printf("FLOAT(%f)\n", a1[2]);
break;
case 3:
puts("EMPTY");
result = puts("BUGGY");
break;
case 4:
result = printf("STR(%s)\n", *((const char **)a1 + 1));
break;
case 5:
result = printf("NODE(%s)\n", *((const char **)a1 + 1));
break;
default:
result = puts("BUGGY");
break;
}
return result;
}

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

switch ( *(_DWORD *)a1 )
{
case 0:
result = printf("INT(%d)\n", *((unsigned int *)a1 + 2));
break;
case 1:
result = printf("FLOAT(%f)\n", a1[2]);
break;
case 3:
puts("EMPTY");
result = puts("BUGGY");
break;
case 4:
result = printf("STR(%s)\n", *((const char **)a1 + 1));
break;
case 5:
result = printf("NODE(%s)\n", *((const char **)a1 + 1));
break;
default:
result = puts("BUGGY");
break;
}
return result;
}

original_code:
void debugNode(struct node_t * n){
  switch(n->type){
  case NODE:
  printf("NODE(%s)\n",n->x.s);
  break;
  case INTEGER:
  printf("INT(%d)\n",n->x.i);
  break;
  case REAL:
  printf("FLOAT(%f)\n",n->x.f);
  break;
  case STR:
  printf("STR(%s)\n",n->x.s);
  break;
  case EMPTY:
  printf("EMPTY\n");
  default:
  printf("BUGGY\n");
 }
}

canonical_original_code:
void debugNode(struct node_t *n){
  switch(n->type){
  case NODE:
  printf("NODE(%s)\n",n->x.s);
  break;
  case INTEGER:
  printf("INT(%d)\n",n->x.i);
  break;
  case REAL:
  printf("FLOAT(%f)\n",n->x.f);
  break;
  case STR:
  printf("STR(%s)\n",n->x.s);
  break;
  case EMPTY:
  printf("EMPTY\n");
  default:
  printf("BUGGY\n");
 }
}

user_defined_types: enum type_t { INTEGER=0, REAL=1, EMPTY=3, STR=4, NODE=5 }


printNode

decompiled_code:
void __fastcall printNode(__int64 a1, __int64 a2)
{
const char *v3; // rsi
float v4; // xmm0_4
char s1[8]; // [rsp+0h] [rbp-14h] BYREF

if ( *(_DWORD *)a1 == 4 )
{
v3 = *(const char **)(a1 + 8);
strcpy(&s1[5], "$accel");
if ( !strcmp(&s1[5], v3) )
{
if ( *(_DWORD *)a2 )
{
if ( *(_DWORD *)a2 != 1 )
{
yyerror("float or int value expected.\n");
exit(-1);
}
v4 = *(float *)(a2 + 8);
*(float *)s1 = v4;
}
else
{
v4 = (float)*(int *)(a2 + 8);
*(float *)s1 = v4;
}
if ( v4 < 0.0 || v4 > 1.0 )
{
fwrite("---------ERROR----------\n", 1uLL, 0x19uLL, output);
yyerror("$accel : Value between 0 and 1 expected.");
exit(-1);
}
fprintf(output, "store double 0x%8.8X, double* %%accelCmd\n", *(_QWORD *)s1);
}
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, __int64 a2)
{
const char *v3; // rsi
float v4; // xmm0_4
char s1[8]; // [rsp+0h] [rbp-14h] BYREF

if ( *(_DWORD *)a1 == 4 )
{
v3 = *(const char **)(a1 + 8);
strcpy(&s1[5], "$accel");
if ( !strcmp(&s1[5], v3) )
{
if ( *(_DWORD *)a2 )
{
if ( *(_DWORD *)a2 != 1 )
{
yyerror("float or int value expected.\n");
exit(-1);
}
v4 = *(float *)(a2 + 8);
*(float *)s1 = v4;
}
else
{
v4 = (float)*(int *)(a2 + 8);
*(float *)s1 = v4;
}
if ( v4 < 0.0 || v4 > 1.0 )
{
fwrite("---------ERROR----------\n", 1uLL, 0x19uLL, output);
yyerror("$accel : Value between 0 and 1 expected.");
exit(-1);
}
fprintf(output, "store double 0x%8.8X, double* %%accelCmd\n", *(_QWORD *)s1);
}
}
}

original_code:
void printNode(struct node_t * n1, struct node_t * n2){
 if(n1->type == STR){
  char accel[] = "$accel";
  char * curr = n1->x.s;
  if(!strcmp(accel,curr)){
   float tmp = 0.0;
   if(n2->type == INTEGER){
    tmp = n2->x.i;
   }
   else if(n2->type == REAL){
    tmp = n2->x.f;
   }
   else {
    yyerror("float or int value expected.\n");
    exit(-1);
   }
   if(tmp >= 0 && tmp <= 1)
    fprintf(output,"store double  0x%8.8X, double* %%accelCmd\n",*((long*)&tmp));
   else{
    fprintf(output,"---------ERROR----------\n");
    yyerror("$accel : Value between 0 and 1 expected.");
    exit(-1);
   }
  }
 }
}

canonical_original_code:
void printNode(struct node_t *n1, struct node_t *n2){
 if(n1->type == STR){
  char accel[] = "$accel";
  char *curr = n1->x.s;
  if(!strcmp(accel,curr)){
   float tmp = 0.0;
   if(n2->type == INTEGER){
    tmp = n2->x.i;
   }
   else if(n2->type == REAL){
    tmp = n2->x.f;
   }
   else {
    yyerror("float or int value expected.\n");
    exit(-1);
   }
   if(tmp >= 0 && tmp <= 1)
    fprintf(output,"store double  0x%8.8X, double* %%accelCmd\n",*((long *)&tmp));
   else{
    fprintf(output,"---------ERROR----------\n");
    yyerror("$accel : Value between 0 and 1 expected.");
    exit(-1);
   }
  }
 }
}

variable_types:
accel
char []

variable_types:
curr
char *

variable_types: tmp float


decompiled_code:
char *__fastcall update_node(unsigned int *a1, float *a2)
{
void *v3; // rdi
char *result; // rax
float v5; // xmm0_4
__int64 v6; // rsi

v3 = (void *)*((_QWORD *)a1 + 3);
if ( v3 )
free(v3);
if ( !a2 )
puts("NULL POINTEUR UPDATE !!!!!!!!!!!!!");
result = (char *)*a1;
if ( (_DWORD)result == 4 )
{
*((_QWORD *)a1 + 1) = a2;
*((_QWORD *)a1 + 3) = a2;
}
else if ( (unsigned int)result > 4 )
{
if ( (_DWORD)result != 5 )
goto LABEL_14;
*((_QWORD *)a1 + 1) = a2;
}
else
{
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
{
v5 = *a2;
a1[2] = *(_DWORD *)a2;
result = autoAlloc("%f", v5);
*((_QWORD *)a1 + 3) = result;
return result;
}
LABEL_14:
exit(-1);
}
v6 = *(unsigned int *)a2;
a1[2] = v6;
result = autoAlloc("%d", v6);
*((_QWORD *)a1 + 3) = result;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func5(unsigned int *a1, float *a2)
{
void *v3; // rdi
char *result; // rax
float v5; // xmm0_4
__int64 v6; // rsi

v3 = (void *)*((_QWORD *)a1 + 3);
if ( v3 )
free(v3);
if ( !a2 )
puts("NULL POINTEUR UPDATE !!!!!!!!!!!!!");
result = (char *)*a1;
if ( (_DWORD)result == 4 )
{
*((_QWORD *)a1 + 1) = a2;
*((_QWORD *)a1 + 3) = a2;
}
else if ( (unsigned int)result > 4 )
{
if ( (_DWORD)result != 5 )
goto LABEL_14;
*((_QWORD *)a1 + 1) = a2;
}
else
{
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
{
v5 = *a2;
a1[2] = *(_DWORD *)a2;
result = func1("%f", v5);
*((_QWORD *)a1 + 3) = result;
return result;
}
LABEL_14:
exit(-1);
}
v6 = *(unsigned int *)a2;
a1[2] = v6;
result = func1("%d", v6);
*((_QWORD *)a1 + 3) = result;
}
return result;
}

original_code:
void update_node(struct node_t * n, void * val){
 if(n->valStr)
  free(n->valStr);
 if(!val)
  printf("NULL POINTEUR UPDATE !!!!!!!!!!!!!\n");
 switch(n->type){
 case NODE:
  n->x.s = (char * )val;
  break;
 case INTEGER:
  n->x.i = *((int *)val);
  n->valStr = autoAlloc("%d",n->x.i);
 break;
  case REAL:
  n->x.f = *((float *)val);
  n->valStr = autoAlloc("%f",n->x.f);
  break;
 case STR:
  n->x.s = (char *) val;
  n->valStr = n->x.s;
  break;
 default:
  exit(-1);
 }
}

canonical_original_code:
void update_node(struct node_t *n, void *val){
 if(n->valStr)
  free(n->valStr);
 if(!val)
  printf("NULL POINTEUR UPDATE !!!!!!!!!!!!!\n");
 switch(n->type){
 case NODE:
  n->x.s = (char * )val;
  break;
 case INTEGER:
  n->x.i = *((int *)val);
  n->valStr = autoAlloc("%d",n->x.i);
 break;
  case REAL:
  n->x.f = *((float *)val);
  n->valStr = autoAlloc("%f",n->x.f);
  break;
 case STR:
  n->x.s = (char *) val;
  n->valStr = n->x.s;
  break;
 default:
  exit(-1);
 }
}

variable_types:
val
void *


decompiled_code:
char *__fastcall update_node_from_node(unsigned int *a1, __int64 a2)
{
if ( *(_DWORD *)a2 > 1u )
exit(-1);
return update_node(a1, (float *)(a2 + 8));
}

canonical_decompiled_code:
char *__fastcall func6(unsigned int *a1, __int64 a2)
{
if ( *(_DWORD *)a2 > 1u )
exit(-1);
return func5(a1, (float *)(a2 + 8));
}

original_code:
void update_node_from_node(struct node_t * n1, struct node_t * n2){
 switch(n2->type){
 case INTEGER:
  update_node(n1, &(n2->x.i));
  break;
 case REAL:
  update_node(n1, &(n2->x.f));
  break;
 default:
  exit(-1);
 }
}

canonical_original_code:
void update_node_from_node(struct node_t *n1, struct node_t *n2){
 switch(n2->type){
 case INTEGER:
  update_node(n1, &(n2->x.i));
  break;
 case REAL:
  update_node(n1, &(n2->x.f));
  break;
 default:
  exit(-1);
 }
}


getTypeResult

decompiled_code:
__int64 __fastcall getTypeResult(unsigned int *a1, unsigned int a2, unsigned int *a3)
{
unsigned int v3; // ecx
__int64 result; // rax
bool v5; // zf
bool v6; // cc

v3 = *a1;
result = *a3;
if ( a2 == 1 )
{
if ( v3 <= 1 )
{
v6 = (unsigned int)result <= 1;
result = 1LL;
if ( v6 )
return result;
}
return 3LL;
}
if ( a2 > 1 && a2 - 2 > 1 )
return 3LL;
if ( v3 != (_DWORD)result )
{
if ( v3 == 1 || (v5 = (_DWORD)result == 1, result = 3LL, v5) )
{
puts("COUCOU");
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1, unsigned int a2, unsigned int *a3)
{
unsigned int v3; // ecx
__int64 result; // rax
bool v5; // zf
bool v6; // cc

v3 = *a1;
result = *a3;
if ( a2 == 1 )
{
if ( v3 <= 1 )
{
v6 = (unsigned int)result <= 1;
result = 1LL;
if ( v6 )
return result;
}
return 3LL;
}
if ( a2 > 1 && a2 - 2 > 1 )
return 3LL;
if ( v3 != (_DWORD)result )
{
if ( v3 == 1 || (v5 = (_DWORD)result == 1, result = 3LL, v5) )
{
puts("COUCOU");
result = 1LL;
}
}
return result;
}

original_code:
type_t getTypeResult(struct node_t * n1,operator_t ope, struct node_t * n2){
 type_t t1 = n1->type;
 type_t t2 = n2->type;
 switch(ope){
  case ADD:
  case SUB:
  case MUL:
   if(t1 == t2)
    return t1;
   else if(t1 == REAL || t2 == REAL){
    printf("COUCOU\n");
    return REAL;}
   else
    return EMPTY;
   break;
  case DIV:
   if((t1 == REAL || t1 == INTEGER) && (t2 == REAL || t2 == INTEGER))
    return REAL;
   return EMPTY;
   break;
 }
 return EMPTY;
}

canonical_original_code:
enum type_t getTypeResult(struct node_t *n1, enum operator_t ope, struct node_t *n2){
 enum type_t t1 = n1->type;
 enum type_t t2 = n2->type;
 switch(ope){
  case ADD:
  case SUB:
  case MUL:
   if(t1 == t2)
    return t1;
   else if(t1 == REAL || t2 == REAL){
    printf("COUCOU\n");
    return REAL;}
   else
    return EMPTY;
   break;
  case DIV:
   if((t1 == REAL || t1 == INTEGER) && (t2 == REAL || t2 == INTEGER))
    return REAL;
   return EMPTY;
   break;
 }
 return EMPTY;
}

variable_types: enum operator_t { MUL=0, DIV=1, ADD=2, SUB=3, NO_OP=4, EQUAL=5, EQUAL_TO=6, SUP_EQ_TO=7, INF_EQ_TO=8, SUP=9, INF=10, INCREASE=11, DECREASE=12, DIFFERENT_OP=13 }

variable_types: enum type_t { INTEGER=0, REAL=1, EMPTY=3, STR=4, NODE=5 }


decompiled_code:
void __fastcall delete_node(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
node_free_code((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
func0((__int64)ptr);
free(ptr);
}

original_code:
void delete_node(struct node_t * n){
 if(n->valStr)
  free(n->valStr);
 node_free_code(n);
 free(n);
}

canonical_original_code:
void delete_node(struct node_t *n){
 if(n->valStr)
  free(n->valStr);
 node_free_code(n);
 free(n);
}


decompiled_code:
void __fastcall update_node_code(__int64 a1, __int64 a2)
{
void *v3; // rdi

v3 = *(void **)(a1 + 16);
if ( v3 )
{
if ( a2 )
{
free(v3);
*(_QWORD *)(a1 + 16) = a2;
}
}
}

original_code:
void update_node_code(struct node_t * n, char * s){
 if(!n->code || !s) return;
 free(n->code);
 n->code = s;
}

canonical_original_code:
void update_node_code(struct node_t *n, char *s){
 if(!n->code || !s) return;
 free(n->code);
 n->code = s;
}

variable_types:
s
char *


MaterialCreate

repo: kellpossible/CRayTracer

decompiled_code:
double *__fastcall MaterialCreate(__int64 a1, double a2, __m128i a3)
{
double *result; // rax

result = (double *)malloc(0x18uLL);
*(_QWORD *)result = a1;
result[1] = a2;
*((_DWORD *)result + 4) = _mm_cvtsi128_si32(a3);
return result;
}

canonical_decompiled_code:
double *__fastcall func0(__int64 a1, double a2, __m128i a3)
{
double *result; // rax

result = (double *)malloc(0x18uLL);
*(_QWORD *)result = a1;
result[1] = a2;
*((_DWORD *)result + 4) = _mm_cvtsi128_si32(a3);
return result;
}

original_code:
Material* MaterialCreate(char* name, Vector3f colour){
 Material* self = malloc(sizeof(Material));
 self->name = name;
 self->colour = colour;
 return self;
}

canonical_original_code:
struct Material *MaterialCreate(char *name, struct Vector3f colour){
 struct Material *self = malloc(sizeof(Material));
 self->name = name;
 self->colour = colour;
 return self;
}

variable_types:
name
char *

variable_types:
colour
struct Vector3f

variable_types: struct Material { char *name; struct Vector3f { float xyz[3]; } colour; } *

user_defined_types: struct Material { char *name; struct Vector3f colour; }


MaterialDefault

decompiled_code:
double *MaterialDefault()
{
return MaterialCreate((__int64)"DefaultMaterial", 0.0008789064582742867, (__m128i)0x3F4CCCCDuLL);
}

original_code:
Material* MaterialDefault(void){
 Vector3f col = {{0.8f, 0.8f, 0.8f}};
 return MaterialCreate("DefaultMaterial", col);
}

canonical_original_code:
struct Material *MaterialDefault(){
 struct Vector3f col = {{0.8f, 0.8f, 0.8f}};
 return MaterialCreate("DefaultMaterial", col);
}

variable_types:
col
struct Vector3f { float xyz[3]; }

return_type: struct Material { char *name; struct Vector3f { float xyz[3]; } colour; } *


MaterialFree

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

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

original_code:
void MaterialFree(Material* self){
 free(self);
}

canonical_original_code:
void MaterialFree(struct Material *self){
 free(self);
}


MaterialGetColour

decompiled_code:
__m128i __fastcall MaterialGetColour(__int64 a1)
{
return _mm_loadl_epi64((const __m128i *)(a1 + 8));
}

canonical_decompiled_code:
__m128i __fastcall func3(__int64 a1)
{
return _mm_loadl_epi64((const __m128i *)(a1 + 8));
}

original_code:
Vector3f MaterialGetColour(Material* self){
 return self->colour;
}

canonical_original_code:
struct Vector3f MaterialGetColour(struct Material *self){
 return self->colour;
}

variable_types: struct Material { char *name; struct Vector3f colour; } *

return_type: struct Vector3f { float xyz[3]; }


MaterialGetName

decompiled_code:
__int64 __fastcall MaterialGetName(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
char* MaterialGetName(Material* self){
 return self->name;
}

canonical_original_code:
char *MaterialGetName(struct Material *self){
 return self->name;
}


IntersectPointCreate

decompiled_code:
char *__fastcall IntersectPointCreate(int a1, double a2, __m128i a3, double a4, __m128i a5, float a6)
{
char *result; // rax

result = (char *)malloc(0x20uLL);
*((_DWORD *)result + 7) = a1;
*(double *)result = a2;
*((float *)result + 6) = a6;
*((_DWORD *)result + 2) = _mm_cvtsi128_si32(a3);
*(double *)(result + 12) = a4;
*((_DWORD *)result + 5) = _mm_cvtsi128_si32(a5);
return result;
}

canonical_decompiled_code:
char *__fastcall func0(int a1, double a2, __m128i a3, double a4, __m128i a5, float a6)
{
char *result; // rax

result = (char *)malloc(0x20uLL);
*((_DWORD *)result + 7) = a1;
*(double *)result = a2;
*((float *)result + 6) = a6;
*((_DWORD *)result + 2) = _mm_cvtsi128_si32(a3);
*(double *)(result + 12) = a4;
*((_DWORD *)result + 5) = _mm_cvtsi128_si32(a5);
return result;
}

original_code:
IntersectPoint* IntersectPointCreate( const Vector3f position,
      const Vector3f normal,
      float distance,
      int type){
 IntersectPoint* ip = malloc(sizeof(IntersectPoint));
 ip->position = position;
 ip->normal = normal;
 ip->distance = distance;
 ip->type = type;
 return ip;
}

canonical_original_code:
struct IntersectPoint *IntersectPointCreate(struct Vector3f position, struct Vector3f normal, float distance, int type){
 struct IntersectPoint *ip = malloc(sizeof(IntersectPoint));
 ip->position = position;
 ip->normal = normal;
 ip->distance = distance;
 ip->type = type;
 return ip;
}

variable_types:
position
struct Vector3f

variable_types:
normal
struct Vector3f

variable_types: distance float

variable_types: type int

variable_types: struct IntersectPoint { struct Vector3f { float xyz[3]; } position; struct Vector3f normal; float distance; int type; } *

user_defined_types: struct IntersectPoint { struct Vector3f position; struct Vector3f normal; float distance; int type; }


IntersectPointCreateMiss

decompiled_code:
char *IntersectPointCreateMiss()
{
__m128i v0; // xmm3

v0 = _mm_cvtsi32_si128(*((_DWORD *)&Vector3fZERO + 2));
return IntersectPointCreate(0, Vector3fZERO, v0, Vector3fZERO, v0, 0.0);
}

canonical_decompiled_code:
char *func1()
{
__m128i v0; // xmm3

v0 = _mm_cvtsi32_si128(*((_DWORD *)&Vector3fZERO + 2));
return func0(0, Vector3fZERO, v0, Vector3fZERO, v0, 0.0);
}

original_code:
IntersectPoint* IntersectPointCreateMiss(void){
 IntersectPoint* ip = IntersectPointCreate(Vector3fZERO, Vector3fZERO, 0.0f, 0);
 return ip;
}

canonical_original_code:
struct IntersectPoint *IntersectPointCreateMiss(){
 struct IntersectPoint *ip = IntersectPointCreate(Vector3fZERO, Vector3fZERO, 0.0f, 0);
 return ip;
}

return_type: struct IntersectPoint { struct Vector3f { float xyz[3]; } position; struct Vector3f normal; float distance; int type; } *


IntersectPointFree

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

original_code:
void IntersectPointFree(IntersectPoint* ip){
 free(ip);
}

canonical_original_code:
void IntersectPointFree(struct IntersectPoint *ip){
 free(ip);
}


IntersectPointGetPos

decompiled_code:
__int64 __fastcall IntersectPointGetPos(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return a1;
}

original_code:
Vector3f* IntersectPointGetPos(IntersectPoint* ip){
 Vector3f* retv = &(ip->position);
 return retv;
}

canonical_original_code:
struct Vector3f *IntersectPointGetPos(struct IntersectPoint *ip){
 struct Vector3f *retv = &(ip->position);
 return retv;
}

variable_types: struct IntersectPoint { struct Vector3f position; struct Vector3f normal; float distance; int type; } *

variable_types:
retv
struct Vector3f { float xyz[3]; } *

return_type: struct Vector3f { float xyz[3]; } *


IntersectPointGetNormal

decompiled_code:
__m128i __fastcall IntersectPointGetNormal(__int64 a1)
{
return _mm_loadl_epi64((const __m128i *)(a1 + 12));
}

canonical_decompiled_code:
__m128i __fastcall func4(__int64 a1)
{
return _mm_loadl_epi64((const __m128i *)(a1 + 12));
}

original_code:
Vector3f IntersectPointGetNormal(IntersectPoint* self){
 return self->normal;
}

canonical_original_code:
struct Vector3f IntersectPointGetNormal(struct IntersectPoint *self){
 return self->normal;
}


IntersectPointGetDistance

decompiled_code:
float __fastcall IntersectPointGetDistance(__int64 a1)
{
return *(float *)(a1 + 24);
}

canonical_decompiled_code:
float __fastcall func5(__int64 a1)
{
return *(float *)(a1 + 24);
}

original_code:
float IntersectPointGetDistance(IntersectPoint* self){
 return self->distance;
}

canonical_original_code:
float IntersectPointGetDistance(struct IntersectPoint *self){
 return self->distance;
}

return_type: float


IntersectPointGetType

decompiled_code:
__int64 __fastcall IntersectPointGetType(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

original_code:
int IntersectPointGetType(IntersectPoint* ip){
 return ip->type;
}

canonical_original_code:
int IntersectPointGetType(struct IntersectPoint *ip){
 return ip->type;
}


ColourRGBCreateDefault

decompiled_code:
__int64 ColourRGBCreateDefault()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
ColourRGB ColourRGBCreateDefault(void){
 ColourRGB c1;
 c1.rgb[0] = 0;
 c1.rgb[1] = 0;
 c1.rgb[2] = 0;
 return c1;
}

canonical_original_code:
struct ColourRGB ColourRGBCreateDefault(){
 struct ColourRGB c1;
 c1.rgb[0] = 0;
 c1.rgb[1] = 0;
 c1.rgb[2] = 0;
 return c1;
}

return_type: struct ColourRGB { int rgb[3]; }


ColourRGBCreate

decompiled_code:
__int64 ColourRGBCreate()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
ColourRGB ColourRGBCreate(int r, int g, int b){
 ColourRGB c1;
 c1.rgb[0] = 0;
 c1.rgb[1] = 0;
 c1.rgb[2] = 0;
 return c1;
}

canonical_original_code:
struct ColourRGB ColourRGBCreate(int r, int g, int b){
 struct ColourRGB c1;
 c1.rgb[0] = 0;
 c1.rgb[1] = 0;
 c1.rgb[2] = 0;
 return c1;
}

variable_types: r int

variable_types: g int

variable_types: b int


ColourXYZCreateDefault

decompiled_code:
__int64 ColourXYZCreateDefault()
{
return 1065353216LL;
}

original_code:
Vector3f ColourXYZCreateDefault(void){
 Vector3f c1;
 c1.xyz[0] = 1.0f;
 c1.xyz[1] = 1.0f;
 c1.xyz[2] = 1.0f;
 return c1;
}

canonical_original_code:
struct Vector3f ColourXYZCreateDefault(){
 struct Vector3f c1;
 c1.xyz[0] = 1.0f;
 c1.xyz[1] = 1.0f;
 c1.xyz[2] = 1.0f;
 return c1;
}


ColourRGBAdd

decompiled_code:
__int64 __fastcall ColourRGBAdd(_DWORD *a1, _DWORD *a2)
{
__int64 v3; // [rsp+0h] [rbp-14h]

LODWORD(v3) = *a1 + *a2;
HIDWORD(v3) = a1[1] + a2[1];
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, _DWORD *a2)
{
__int64 v3; // [rsp+0h] [rbp-14h]

LODWORD(v3) = *a1 + *a2;
HIDWORD(v3) = a1[1] + a2[1];
return v3;
}

original_code:
ColourRGB ColourRGBAdd(const ColourRGB* c1, const ColourRGB* c2){
 ColourRGB c3;
 c3.rgb[0] = c1->rgb[0] + c2->rgb[0];
 c3.rgb[1] = c1->rgb[1] + c2->rgb[1];
 c3.rgb[2] = c1->rgb[2] + c2->rgb[2];
 return c3;
}

canonical_original_code:
struct ColourRGB ColourRGBAdd(struct ColourRGB *c1, struct ColourRGB *c2){
 struct ColourRGB c3;
 c3.rgb[0] = c1->rgb[0] + c2->rgb[0];
 c3.rgb[1] = c1->rgb[1] + c2->rgb[1];
 c3.rgb[2] = c1->rgb[2] + c2->rgb[2];
 return c3;
}


ColourRGBSub

decompiled_code:
__int64 __fastcall ColourRGBSub(_DWORD *a1, _DWORD *a2)
{
__int64 v3; // [rsp+0h] [rbp-14h]

LODWORD(v3) = *a1 - *a2;
HIDWORD(v3) = a1[1] - a2[1];
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1, _DWORD *a2)
{
__int64 v3; // [rsp+0h] [rbp-14h]

LODWORD(v3) = *a1 - *a2;
HIDWORD(v3) = a1[1] - a2[1];
return v3;
}

original_code:
ColourRGB ColourRGBSub(const ColourRGB* c1, const ColourRGB* c2){
 ColourRGB c3;
 c3.rgb[0] = c1->rgb[0] - c2->rgb[0];
 c3.rgb[1] = c1->rgb[1] - c2->rgb[1];
 c3.rgb[2] = c1->rgb[2] - c2->rgb[2];
 return c3;
}

canonical_original_code:
struct ColourRGB ColourRGBSub(struct ColourRGB *c1, struct ColourRGB *c2){
 struct ColourRGB c3;
 c3.rgb[0] = c1->rgb[0] - c2->rgb[0];
 c3.rgb[1] = c1->rgb[1] - c2->rgb[1];
 c3.rgb[2] = c1->rgb[2] - c2->rgb[2];
 return c3;
}


original_code:
ColourRGB ColourRGBAverage4(ColourRGB* c1,
                            ColourRGB* c2,
                            ColourRGB* c3,
                            ColourRGB* c4){
    ColourRGB* c_array[4] = {c1, c2, c3, c4};
    int r_sum = 0, b_sum = 0, g_sum = 0;
    int i=0;
    while (i < 3){
        r_sum += (*(c_array[i])).rgb[0];
        g_sum += (*(c_array[i])).rgb[1];
        b_sum += (*(c_array[i])).rgb[2];
        i++;
    }
    ColourRGB ret_col;
    ret_col.rgb[0] = ((float)r_sum)/3.0f;
    ret_col.rgb[1] = ((float)g_sum)/3.0f;
    ret_col.rgb[2] = ((float)b_sum)/3.0f;
    return ret_col;
}

canonical_original_code:
struct ColourRGB ColourRGBAverage4(struct ColourRGB *c1, struct ColourRGB *c2, struct ColourRGB *c3, struct ColourRGB *c4){
    struct ColourRGB *c_array[4] = {c1, c2, c3, c4};
    int r_sum = 0; int b_sum = 0; int g_sum = 0;
    int i = 0;
    while (i < 3){
        r_sum += (*(c_array[i])).rgb[0];
        g_sum += (*(c_array[i])).rgb[1];
        b_sum += (*(c_array[i])).rgb[2];
        i++;
    }
    struct ColourRGB ret_col;
    ret_col.rgb[0] = ((float)r_sum)/3.0f;
    ret_col.rgb[1] = ((float)g_sum)/3.0f;
    ret_col.rgb[2] = ((float)b_sum)/3.0f;
    return ret_col;
}

variable_types: i int


ColourRGBPrint

decompiled_code:
int __fastcall ColourRGBPrint(unsigned int *a1)
{
return printf("r: %d, g: %d, b: %d\n", *a1, a1[1], a1[2]);
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1)
{
return printf("r: %d, g: %d, b: %d\n", *a1, a1[1], a1[2]);
}

original_code:
void ColourRGBPrint(const ColourRGB* c1){
 printf("r: %d, g: %d, b: %d\n",
  c1->rgb[0],
  c1->rgb[1],
  c1->rgb[2]);
}

canonical_original_code:
void ColourRGBPrint(struct ColourRGB *c1){
 printf("r: %d, g: %d, b: %d\n",
  c1->rgb[0],
  c1->rgb[1],
  c1->rgb[2]);
}


decompiled_code:
int __fastcall Colour3fPrint(float *a1)
{
return printf("r: %.3f, g: %.3f, b: %.3f\n", *a1, a1[1], a1[2]);
}

canonical_decompiled_code:
int __fastcall func7(float *a1)
{
return printf("r: %.3f, g: %.3f, b: %.3f\n", *a1, a1[1], a1[2]);
}

original_code:
void Colour3fPrint(const Vector3f* v1){
 printf("r: %.3f, g: %.3f, b: %.3f\n",
  v1->xyz[0],
  v1->xyz[1],
  v1->xyz[2]);
}

canonical_original_code:
void Colour3fPrint(struct Vector3f *v1){
 printf("r: %.3f, g: %.3f, b: %.3f\n",
  v1->xyz[0],
  v1->xyz[1],
  v1->xyz[2]);
}


original_code:
Vector3f ColourRGB2Vector3f(ColourRGB* c1){
 Vector3f v1;
 v1.xyz[0] = ((float)c1->rgb[0])/255.0f;
 v1.xyz[1] = ((float)c1->rgb[1])/255.0f;
 v1.xyz[2] = ((float)c1->rgb[2])/255.0f;
 return v1;
}

canonical_original_code:
struct Vector3f ColourRGB2Vector3f(struct ColourRGB *c1){
 struct Vector3f v1;
 v1.xyz[0] = ((float)c1->rgb[0])/255.0f;
 v1.xyz[1] = ((float)c1->rgb[1])/255.0f;
 v1.xyz[2] = ((float)c1->rgb[2])/255.0f;
 return v1;
}

user_defined_types:
struct Vector3f { float xyz[3]; }
struct ColourRGB { int rgb[3]; }


user_defined_types:
struct ColourRGB { int rgb[3]; }
struct Vector3f { float xyz[3]; }


decompiled_code:
float __fastcall Vector3fDot(float *a1, float *a2)
{
return (float)((float)(*a1 * *a2) + (float)(a1[1] * a2[1])) + (float)(a1[2] * a2[2]);
}

canonical_decompiled_code:
float __fastcall func0(float *a1, float *a2)
{
return (float)((float)(*a1 * *a2) + (float)(a1[1] * a2[1])) + (float)(a1[2] * a2[2]);
}

original_code:
float Vector3fDot(const Vector3f* v1, const Vector3f* v2){
 return (v1->xyz[0] * v2->xyz[0]) +
  (v1->xyz[1] * v2->xyz[1]) +
  (v1->xyz[2] * v2->xyz[2]);
}

canonical_original_code:
float Vector3fDot(struct Vector3f *v1, struct Vector3f *v2){
 return (v1->xyz[0] * v2->xyz[0]) +
  (v1->xyz[1] * v2->xyz[1]) +
  (v1->xyz[2] * v2->xyz[2]);
}


canonical_original_code:
struct Vector3f Vector3fCross(struct Vector3f *v1, struct Vector3f *v2){
 struct Vector3f v3;
 v3.xyz[0] = (v1->xyz[1] * v2->xyz[2]) - (v1->xyz[2] * v2->xyz[1]);
 v3.xyz[1] = (v1->xyz[2] * v2->xyz[0]) - (v1->xyz[0] * v2->xyz[2]);
 v3.xyz[2] = (v1->xyz[0] * v2->xyz[1]) - (v1->xyz[1] * v2->xyz[0]);
 return v3;
}


original_code:
Vector3f Vector3fSub(const Vector3f* v1, const Vector3f* v2){
 Vector3f v3;
 v3.xyz[0] = v1->xyz[0] - v2->xyz[0];
 v3.xyz[1] = v1->xyz[1] - v2->xyz[1];
 v3.xyz[2] = v1->xyz[2] - v2->xyz[2];
 return v3;
}

canonical_original_code:
struct Vector3f Vector3fSub(struct Vector3f *v1, struct Vector3f *v2){
 struct Vector3f v3;
 v3.xyz[0] = v1->xyz[0] - v2->xyz[0];
 v3.xyz[1] = v1->xyz[1] - v2->xyz[1];
 v3.xyz[2] = v1->xyz[2] - v2->xyz[2];
 return v3;
}


original_code:
Vector3f Vector3fAdd(const Vector3f* v1, const Vector3f* v2){
 Vector3f v3;
 v3.xyz[0] = v1->xyz[0] + v2->xyz[0];
 v3.xyz[1] = v1->xyz[1] + v2->xyz[1];
 v3.xyz[2] = v1->xyz[2] + v2->xyz[2];
 return v3;
}

canonical_original_code:
struct Vector3f Vector3fAdd(struct Vector3f *v1, struct Vector3f *v2){
 struct Vector3f v3;
 v3.xyz[0] = v1->xyz[0] + v2->xyz[0];
 v3.xyz[1] = v1->xyz[1] + v2->xyz[1];
 v3.xyz[2] = v1->xyz[2] + v2->xyz[2];
 return v3;
}


original_code:
Vector3f Vector3fNeg(const Vector3f* v1){
 Vector3f v2;
 v2.xyz[0] = v1->xyz[0] * -1.0f;
 v2.xyz[1] = v1->xyz[1] * -1.0f;
 v2.xyz[2] = v1->xyz[2] * -1.0f;
 return v2;
}

canonical_original_code:
struct Vector3f Vector3fNeg(struct Vector3f *v1){
 struct Vector3f v2;
 v2.xyz[0] = v1->xyz[0] * -1.0f;
 v2.xyz[1] = v1->xyz[1] * -1.0f;
 v2.xyz[2] = v1->xyz[2] * -1.0f;
 return v2;
}


original_code:
Vector3f Vector3fMulV(const Vector3f* v1, const Vector3f* v2){
 Vector3f v3;
 v3.xyz[0] = v1->xyz[0] * v2->xyz[0];
 v3.xyz[1] = v1->xyz[1] * v2->xyz[1];
 v3.xyz[2] = v1->xyz[2] * v2->xyz[2];
 return v3;
}

canonical_original_code:
struct Vector3f Vector3fMulV(struct Vector3f *v1, struct Vector3f *v2){
 struct Vector3f v3;
 v3.xyz[0] = v1->xyz[0] * v2->xyz[0];
 v3.xyz[1] = v1->xyz[1] * v2->xyz[1];
 v3.xyz[2] = v1->xyz[2] * v2->xyz[2];
 return v3;
}


original_code:
Vector3f Vector3fMulF(const Vector3f* v1, float f1){
 Vector3f v3;
 v3.xyz[0] = v1->xyz[0] * f1;
 v3.xyz[1] = v1->xyz[1] * f1;
 v3.xyz[2] = v1->xyz[2] * f1;
 return v3;
}

canonical_original_code:
struct Vector3f Vector3fMulF(struct Vector3f *v1, float f1){
 struct Vector3f v3;
 v3.xyz[0] = v1->xyz[0] * f1;
 v3.xyz[1] = v1->xyz[1] * f1;
 v3.xyz[2] = v1->xyz[2] * f1;
 return v3;
}


decompiled_code:
__m128i __fastcall Vector3fDivF(float *a1, double a2)
{
int v3; // [rsp+4h] [rbp-34h]
float v4; // [rsp+4h] [rbp-34h]
int v5; // [rsp+8h] [rbp-30h]
float v6; // [rsp+Ch] [rbp-2Ch]
__m128i v7; // [rsp+24h] [rbp-14h] BYREF

v3 = LODWORD(a2);
v6 = fDiv(*a1, a2);
v5 = v3;
v4 = fDiv(a1[1], COERCE_DOUBLE((unsigned __int64)v3));
v7.m128i_i32[2] = fDiv(a1[2], COERCE_DOUBLE((unsigned __int64)v5));
v7.m128i_i64[0] = __PAIR64__(LODWORD(v4), LODWORD(v6));
return _mm_loadl_epi64(&v7);
}

canonical_decompiled_code:
__m128i __fastcall func7(float *a1, double a2)
{
int v3; // [rsp+4h] [rbp-34h]
float v4; // [rsp+4h] [rbp-34h]
int v5; // [rsp+8h] [rbp-30h]
float v6; // [rsp+Ch] [rbp-2Ch]
__m128i v7; // [rsp+24h] [rbp-14h] BYREF

v3 = LODWORD(a2);
v6 = fDiv(*a1, a2);
v5 = v3;
v4 = fDiv(a1[1], COERCE_DOUBLE((unsigned __int64)v3));
v7.m128i_i32[2] = fDiv(a1[2], COERCE_DOUBLE((unsigned __int64)v5));
v7.m128i_i64[0] = __PAIR64__(LODWORD(v4), LODWORD(v6));
return _mm_loadl_epi64(&v7);
}

original_code:
Vector3f Vector3fDivF(const Vector3f* v1, float f1){
 Vector3f v2;
 v2.xyz[0] = fDiv(v1->xyz[0], f1);
 v2.xyz[1] = fDiv(v1->xyz[1], f1);
 v2.xyz[2] = fDiv(v1->xyz[2], f1);
 return v2;
}

canonical_original_code:
struct Vector3f Vector3fDivF(struct Vector3f *v1, float f1){
 struct Vector3f v2;
 v2.xyz[0] = fDiv(v1->xyz[0], f1);
 v2.xyz[1] = fDiv(v1->xyz[1], f1);
 v2.xyz[2] = fDiv(v1->xyz[2], f1);
 return v2;
}


decompiled_code:
__m128i __fastcall Vector3fNormalize(float *a1, double a2)
{
float v2; // xmm0_4

v2 = Vector3fDot(a1, a1);
if ( v2 < 0.0 )
*(float *)&a2 = sqrtf(v2);
else
*(float *)&a2 = fsqrt(v2);
return Vector3fDivF(a1, a2);
}

canonical_decompiled_code:
__m128i __fastcall func8(float *a1, double a2)
{
float v2; // xmm0_4

v2 = func0(a1, a1);
if ( v2 < 0.0 )
*(float *)&a2 = sqrtf(v2);
else
*(float *)&a2 = fsqrt(v2);
return func7(a1, a2);
}

original_code:
Vector3f Vector3fNormalize(const Vector3f* v1){
 float v1_mag = (float)sqrt((float)Vector3fDot(v1, v1));
 Vector3f v2 = Vector3fDivF(v1, v1_mag);
 return v2;
}

canonical_original_code:
struct Vector3f Vector3fNormalize(struct Vector3f *v1){
 float v1_mag = (float)sqrt((float)Vector3fDot(v1, v1));
 struct Vector3f v2 = Vector3fDivF(v1, v1_mag);
 return v2;
}


decompiled_code:
void __fastcall Vector3fMag(float *a1)
{
float v1; // xmm0_4

v1 = Vector3fDot(a1, a1);
if ( v1 < 0.0 )
sqrtf(v1);
}

canonical_decompiled_code:
void __fastcall func9(float *a1)
{
float v1; // xmm0_4

v1 = func0(a1, a1);
if ( v1 < 0.0 )
sqrtf(v1);
}

original_code:
float Vector3fMag(const Vector3f* v1){
 return (float)sqrt((float)Vector3fDot(v1, v1));
}

canonical_original_code:
float Vector3fMag(struct Vector3f *v1){
 return (float)sqrt((float)Vector3fDot(v1, v1));
}


decompiled_code:
// attributes: thunk
void __fastcall Vector3fLen(float *a1)
{
Vector3fMag(a1);
}

canonical_decompiled_code:
void __fastcall func10(float *a1)
{
func9(a1);
}

original_code:
float Vector3fLen(const Vector3f* v1){
 return (float)sqrt((float)Vector3fDot(v1, v1));
}

canonical_original_code:
float Vector3fLen(struct Vector3f *v1){
 return (float)sqrt((float)Vector3fDot(v1, v1));
}