decompiled_code:
unsigned __int64 __fastcall buffer_read(_QWORD *a1, void *a2)
{
unsigned __int64 v2; // r12
__int64 v3; // rcx
unsigned __int64 v5; // rax
unsigned __int64 v6; // rsi

v2 = 0LL;
if ( !buffer_good(a1) )
return v2;
if ( a2 && v3 )
{
v5 = a1[1];
v6 = a1[3];
if ( v5 > v6 )
{
if ( *a1 )
{
v2 = v5 - v6;
memcpy(a2, (const void *)(*a1 + v6), v5 - v6);
}
}
return v2;
}
return 0LL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(_QWORD *a1, void *a2)
{
unsigned __int64 v2; // r12
__int64 v3; // rcx
unsigned __int64 v5; // rax
unsigned __int64 v6; // rsi

v2 = 0LL;
if ( !func3(a1) )
return v2;
if ( a2 && v3 )
{
v5 = a1[1];
v6 = a1[3];
if ( v5 > v6 )
{
if ( *a1 )
{
v2 = v5 - v6;
memcpy(a2, (const void *)(*a1 + v6), v5 - v6);
}
}
return v2;
}
return 0LL;
}

original_code:
size_t buffer_read(buffer_t* buf, uint8_t* dst, size_t length)
{
    size_t bytes_read = 0;
    uint8_t* src = ((void *)0);
    size_t src_len = 0;
    if (buffer_good(buf) && dst && length) {
        if (buf->length > buf->offset) {
            src_len = buf->length - buf->offset;
        }
        if (buf->content && src_len) {
            src = buf->content + buf->offset;
            memcpy(dst, src, src_len);
            bytes_read = src_len;
        }
    }
    return bytes_read;
}

canonical_original_code:
unsigned long buffer_read(struct _buffer *buf, unsigned char *dst, unsigned long length)
{
    unsigned long bytes_read = 0;
    unsigned char *src = ((void *)0);
    unsigned long src_len = 0;
    if (buffer_good(buf) && dst && length) {
        if (buf->length > buf->offset) {
            src_len = buf->length - buf->offset;
        }
        if (buf->content && src_len) {
            src = buf->content + buf->offset;
            memcpy(dst, src, src_len);
            bytes_read = src_len;
        }
    }
    return bytes_read;
}


repo: joeledwards/asl-station-processor

decompiled_code:
size_t __fastcall buffer_write(char **a1, const void *a2, size_t a3)
{
char *v4; // rax
size_t v5; // r14
size_t v7; // r13
char *v8; // rdi
size_t result; // rax

if ( buffer_good(a1) && a2 && a3 )
{
v4 = a1[3];
v5 = (size_t)a1[2];
v7 = (size_t)&v4[a3];
if ( a1[1] >= &v4[a3] )
v7 = (size_t)a1[1];
v8 = *a1;
if ( v5 >= v7 && v8 )
goto LABEL_8;
v8 = (char *)realloc(v8, v7);
if ( v8 )
{
v4 = a1[3];
v5 = v7;
LABEL_8:
*a1 = v8;
memcpy(&v8[(_QWORD)v4], a2, a3);
a1[3] += a3;
result = a3;
a1[1] = (char *)v7;
a1[2] = (char *)v5;
return result;
}
}
return 0LL;
}

canonical_decompiled_code:
size_t __fastcall func9(char **a1, const void *a2, size_t a3)
{
char *v4; // rax
size_t v5; // r14
size_t v7; // r13
char *v8; // rdi
size_t result; // rax

if ( func3(a1) && a2 && a3 )
{
v4 = a1[3];
v5 = (size_t)a1[2];
v7 = (size_t)&v4[a3];
if ( a1[1] >= &v4[a3] )
v7 = (size_t)a1[1];
v8 = *a1;
if ( v5 >= v7 && v8 )
goto LABEL_8;
v8 = (char *)realloc(v8, v7);
if ( v8 )
{
v4 = a1[3];
v5 = v7;
LABEL_8:
*a1 = v8;
memcpy(&v8[(_QWORD)v4], a2, a3);
a1[3] += a3;
result = a3;
a1[1] = (char *)v7;
a1[2] = (char *)v5;
return result;
}
}
return 0LL;
}

original_code:
size_t buffer_write(buffer_t* buf, const uint8_t* src, size_t length)
{
    size_t bytes_written = 0;
    uint8_t* tmp_buf = ((void *)0);
    uint8_t* dst = ((void *)0);
    size_t new_length = 0;
    size_t new_capacity = 0;
    if (buffer_good(buf) && src && length) {
        new_capacity = buf->capacity;
        new_length = buf->offset + length;
        if (new_length < buf->length) {
            new_length = buf->length;
        }
        if (buf->content && (new_length <= buf->capacity)) {
            tmp_buf = buf->content;
        } else {
            new_capacity = new_length;
            tmp_buf = (uint8_t*)realloc(buf->content, new_capacity);
        }
        if (tmp_buf) {
            buf->content = tmp_buf;
            dst = buf->content + buf->offset;
            memcpy(dst, src, length);
            bytes_written = length;
            buf->length = new_length;
            buf->offset += bytes_written;
            buf->capacity = new_capacity;
        }
    }
    return bytes_written;
}

canonical_original_code:
unsigned long buffer_write(struct _buffer *buf, unsigned char *src, unsigned long length)
{
    unsigned long bytes_written = 0;
    unsigned char *tmp_buf = ((void *)0);
    unsigned char *dst = ((void *)0);
    unsigned long new_length = 0;
    unsigned long new_capacity = 0;
    if (buffer_good(buf) && src && length) {
        new_capacity = buf->capacity;
        new_length = buf->offset + length;
        if (new_length < buf->length) {
            new_length = buf->length;
        }
        if (buf->content && (new_length <= buf->capacity)) {
            tmp_buf = buf->content;
        } else {
            new_capacity = new_length;
            tmp_buf = (unsigned char *)realloc(buf->content, new_capacity);
        }
        if (tmp_buf) {
            buf->content = tmp_buf;
            dst = buf->content + buf->offset;
            memcpy(dst, src, length);
            bytes_written = length;
            buf->length = new_length;
            buf->offset += bytes_written;
            buf->capacity = new_capacity;
        }
    }
    return bytes_written;
}

variable_types: struct _buffer { unsigned char *content; unsigned long length; unsigned long capacity; unsigned long offset; } *

variable_types:
src
unsigned char *

variable_types:
length
unsigned long

variable_types:
dst
unsigned char *

return_type: unsigned long


decompiled_code:
__int64 __fastcall buffer_size(_QWORD *a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = buffer_good(a1);
result = 0LL;
if ( v1 )
result = a1[1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = func3(a1);
result = 0LL;
if ( v1 )
result = a1[1];
return result;
}

original_code:
size_t buffer_size(const buffer_t* buf)
{
    size_t size = 0;
    if (buffer_good(buf)) {
        size = buf->length;
    }
    return size;
}

canonical_original_code:
unsigned long buffer_size(struct _buffer *buf)
{
    unsigned long size = 0;
    if (buffer_good(buf)) {
        size = buf->length;
    }
    return size;
}

variable_types:
size
unsigned long

user_defined_types: struct _buffer { unsigned char *content; unsigned long length; unsigned long capacity; unsigned long offset; }


decompiled_code:
size_t __fastcall buffer_terminate(char **a1)
{
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

v2[0] = 0;
return buffer_write(a1, v2, 1uLL);
}

canonical_decompiled_code:
size_t __fastcall func11(char **a1)
{
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

v2[0] = 0;
return func9(a1, v2, 1uLL);
}

original_code:
int buffer_terminate(buffer_t* buf) {
    int result = 0;
    uint8_t terminator = 0;
    result = (int)buffer_write(buf, &terminator, sizeof(terminator));
    return result;
}

canonical_original_code:
int buffer_terminate(struct _buffer *buf) {
    int result = 0;
    unsigned char terminator = 0;
    result = (int)buffer_write(buf, &terminator, sizeof(terminator));
    return result;
}

variable_types: result int

variable_types:
terminator
unsigned char

return_type: int


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

v1 = 0LL;
if ( buffer_good(a1) )
{
v1 = *a1;
*a1 = 0LL;
buffer_reset((__int64)a1);
}
return v1;
}

original_code:
uint8_t* buffer_detach(buffer_t* buf)
{
    uint8_t* buf_content = ((void *)0);
    if (buffer_good(buf)) {
        buf_content = buf->content;
        buf->content = ((void *)0);
        buffer_reset(buf);
    }
    return buf_content;
}

canonical_original_code:
unsigned char *buffer_detach(struct _buffer *buf)
{
    unsigned char *buf_content = ((void *)0);
    if (buffer_good(buf)) {
        buf_content = buf->content;
        buf->content = ((void *)0);
        buffer_reset(buf);
    }
    return buf_content;
}

return_type: unsigned char *


decompiled_code:
_BOOL8 __fastcall is_probably_an_url(const char *a1)
{
return strstr(a1, "://") != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
return strstr(a1, "://") != 0LL;
}

original_code:
int
is_probably_an_url(char *string)
{
    if( strstr(string, "://") )
        return 1;
    return 0;
}

variable_types:
string
char *


decompiled_code:
char *__fastcall get_service_type(char *s1, __int64 *a2)
{
char *result; // rax
int v3; // eax
__int64 v4; // r12
__int64 v5; // rax

if ( strstr(s1, "http://") )
{
*((_DWORD *)a2 + 2) = 1;
result = s1 + 7;
}
else if ( strstr(s1, "ftp://") )
{
result = s1 + 6;
*((_DWORD *)a2 + 2) = 2;
}
else if ( strstr(s1, "gopher://") )
{
result = s1 + 9;
*((_DWORD *)a2 + 2) = 3;
}
else
{
v3 = strncasecmp(s1, "www", 3uLL);
v4 = *a2;
if ( v3 )
{
if ( !strncasecmp(s1, "ftp", 3uLL) )
{
*((_DWORD *)a2 + 2) = 2;
*a2 = strconcat("ftp://", v4, 0LL);
}
else
{
v5 = strconcat("http://", v4, 0LL);
*((_DWORD *)a2 + 2) = 1;
*a2 = v5;
}
result = s1;
}
else
{
*((_DWORD *)a2 + 2) = 1;
*a2 = strconcat("http://", v4, 0LL);
result = s1;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *s1, __int64 *a2)
{
char *result; // rax
int v3; // eax
__int64 v4; // r12
__int64 v5; // rax

if ( strstr(s1, "http://") )
{
*((_DWORD *)a2 + 2) = 1;
result = s1 + 7;
}
else if ( strstr(s1, "ftp://") )
{
result = s1 + 6;
*((_DWORD *)a2 + 2) = 2;
}
else if ( strstr(s1, "gopher://") )
{
result = s1 + 9;
*((_DWORD *)a2 + 2) = 3;
}
else
{
v3 = strncasecmp(s1, "www", 3uLL);
v4 = *a2;
if ( v3 )
{
if ( !strncasecmp(s1, "ftp", 3uLL) )
{
*((_DWORD *)a2 + 2) = 2;
*a2 = strconcat("ftp://", v4, 0LL);
}
else
{
v5 = strconcat("http://", v4, 0LL);
*((_DWORD *)a2 + 2) = 1;
*a2 = v5;
}
result = s1;
}
else
{
*((_DWORD *)a2 + 2) = 1;
*a2 = strconcat("http://", v4, 0LL);
result = s1;
}
}
return result;
}

original_code:
char *
get_service_type(char *string, Url *u)
{
    if( strstr(string, "http://") ) {
        string += 7;
        u->service_type = SERVICE_HTTP;
        return string;
    }
    if( strstr(string, "ftp://") ) {
        string += 6;
        u->service_type = SERVICE_FTP;
        return string;
    }
    if( strstr(string, "gopher://") ) {
        string += 9;
        u->service_type = SERVICE_GOPHER;
        return string;
    }
    if( strncasecmp(string, "www", 3) == 0 ) {
        u->service_type = SERVICE_HTTP;
        u->full_url = strconcat("http://", u->full_url, ((void *)0));
        return string;
    }
    if( strncasecmp(string, "ftp", 3) == 0 ) {
        u->service_type = SERVICE_FTP;
        u->full_url = strconcat("ftp://", u->full_url, ((void *)0));
        return string;
    }
    u->full_url = strconcat("http://", u->full_url, ((void *)0));
    u->service_type = SERVICE_HTTP;
    return string;
}

canonical_original_code:
char *get_service_type(char *string, struct _Url *u)
{
    if( strstr(string, "http://") ) {
        string += 7;
        u->service_type = SERVICE_HTTP;
        return string;
    }
    if( strstr(string, "ftp://") ) {
        string += 6;
        u->service_type = SERVICE_FTP;
        return string;
    }
    if( strstr(string, "gopher://") ) {
        string += 9;
        u->service_type = SERVICE_GOPHER;
        return string;
    }
    if( strncasecmp(string, "www", 3) == 0 ) {
        u->service_type = SERVICE_HTTP;
        u->full_url = strconcat("http://", u->full_url, ((void *)0));
        return string;
    }
    if( strncasecmp(string, "ftp", 3) == 0 ) {
        u->service_type = SERVICE_FTP;
        u->full_url = strconcat("ftp://", u->full_url, ((void *)0));
        return string;
    }
    u->full_url = strconcat("http://", u->full_url, ((void *)0));
    u->service_type = SERVICE_HTTP;
    return string;
}

variable_types: struct _Url { char *full_url; int service_type; char *username; char *password; char *host; int port; char *path; char *file; } *

return_type: char *


decompiled_code:
char *__fastcall get_username(void *src, __int64 a2)
{
char *v2; // rax
char *v3; // rbx
char *v4; // rax
char v6; // al
bool v7; // dl
size_t v8; // rbx
int v9; // ebp
void *v10; // rax
_BYTE *v11; // rax

v2 = strchr((const char *)src, 64);
if ( !v2 )
return (char *)src;
v3 = v2;
v4 = strchr((const char *)src, 47);
if ( v4 )
{
if ( v3 >= v4 )
return (char *)src;
}
v6 = *(_BYTE *)src;
v7 = *(_BYTE *)src != 58;
if ( *(_BYTE *)src && v6 != 58 )
{
v8 = 0LL;
while ( 1 )
{
v9 = v8;
if ( v6 == 64 )
break;
if ( v6 == 47 )
return (char *)src;
++v8;
++v9;
v6 = *((_BYTE *)src + v8);
v7 = v6 != 58;
if ( !v6 || v6 == 58 )
goto LABEL_14;
}
LABEL_12:
v10 = malloc(v8);
v11 = memcpy(v10, src, v9 + 1);
v11[v8] = 0;
*(_QWORD *)(a2 + 16) = v11;
return (char *)src + v8 + 1;
}
v9 = 0;
v8 = 0LL;
LABEL_14:
if ( v6 == 64 || !v7 )
goto LABEL_12;
return (char *)src;
}

canonical_decompiled_code:
char *__fastcall func2(void *src, __int64 a2)
{
char *v2; // rax
char *v3; // rbx
char *v4; // rax
char v6; // al
bool v7; // dl
size_t v8; // rbx
int v9; // ebp
void *v10; // rax
_BYTE *v11; // rax

v2 = strchr((const char *)src, 64);
if ( !v2 )
return (char *)src;
v3 = v2;
v4 = strchr((const char *)src, 47);
if ( v4 )
{
if ( v3 >= v4 )
return (char *)src;
}
v6 = *(_BYTE *)src;
v7 = *(_BYTE *)src != 58;
if ( *(_BYTE *)src && v6 != 58 )
{
v8 = 0LL;
while ( 1 )
{
v9 = v8;
if ( v6 == 64 )
break;
if ( v6 == 47 )
return (char *)src;
++v8;
++v9;
v6 = *((_BYTE *)src + v8);
v7 = v6 != 58;
if ( !v6 || v6 == 58 )
goto LABEL_14;
}
LABEL_12:
v10 = malloc(v8);
v11 = memcpy(v10, src, v9 + 1);
v11[v8] = 0;
*(_QWORD *)(a2 + 16) = v11;
return (char *)src + v8 + 1;
}
v9 = 0;
v8 = 0LL;
LABEL_14:
if ( v6 == 64 || !v7 )
goto LABEL_12;
return (char *)src;
}

original_code:
char *
get_username(char *string, Url *u)
{
    int i;
    char *username;
    char *at;
    char *slash;
    at = strchr(string, '@');
    slash = strchr(string, '/');
    if( (!at) || (slash && (at >= slash)) )
        return string;
    for( i = 0; string[i] && string[i] != ':' &&
         string[i] != '@' && string[i] != '/'; i++);
    if( string[i] != '@' && string[i] != ':' ) {
        return string;
    }
    username = (char*)malloc(i);
    memcpy(username, string, i + 1);
    username[i] = '\0';
    string += i + 1;
    u->username = username;
    return string;
}

canonical_original_code:
char *get_username(char *string, struct _Url *u)
{
    int i;
    char *username;
    char *at;
    char *slash;
    at = strchr(string, '@');
    slash = strchr(string, '/');
    if( (!at) || (slash && (at >= slash)) )
        return string;
    for( i = 0; string[i] && string[i] != ':' &&
         string[i] != '@' && string[i] != '/'; i++);
    if( string[i] != '@' && string[i] != ':' ) {
        return string;
    }
    username = (char *)malloc(i);
    memcpy(username, string, i + 1);
    username[i] = '\0';
    string += i + 1;
    u->username = username;
    return string;
}

variable_types: i int

variable_types:
username
char *

variable_types:
at
char *

variable_types:
slash
char *

user_defined_types: struct _Url { char *full_url; int service_type; char *username; char *password; char *host; int port; char *path; char *file; }


decompiled_code:
char *__fastcall get_password(void *src, __int64 a2)
{
char *v2; // rax
char *v3; // rbx
char *v4; // rdx
char *result; // rax
__int64 v6; // rbx
size_t v7; // r12
void *v8; // rax
_BYTE *v9; // rcx

v2 = strchr((const char *)src, 64);
if ( !v2 )
return (char *)src;
v3 = v2;
v4 = strchr((const char *)src, 47);
if ( !v4 || (result = (char *)src, v3 < v4) )
{
v6 = 1LL;
if ( *(_BYTE *)src == 64 )
{
v7 = 0LL;
}
else
{
do
v7 = v6++;
while ( *((char *)src + v6 - 1) != 64 );
}
v8 = malloc(v7);
v9 = memcpy(v8, src, v7);
v9[v7] = 0;
result = (char *)src + v6;
*(_QWORD *)(a2 + 24) = v9;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(void *src, __int64 a2)
{
char *v2; // rax
char *v3; // rbx
char *v4; // rdx
char *result; // rax
__int64 v6; // rbx
size_t v7; // r12
void *v8; // rax
_BYTE *v9; // rcx

v2 = strchr((const char *)src, 64);
if ( !v2 )
return (char *)src;
v3 = v2;
v4 = strchr((const char *)src, 47);
if ( !v4 || (result = (char *)src, v3 < v4) )
{
v6 = 1LL;
if ( *(_BYTE *)src == 64 )
{
v7 = 0LL;
}
else
{
do
v7 = v6++;
while ( *((char *)src + v6 - 1) != 64 );
}
v8 = malloc(v7);
v9 = memcpy(v8, src, v7);
v9[v7] = 0;
result = (char *)src + v6;
*(_QWORD *)(a2 + 24) = v9;
}
return result;
}

original_code:
char *
get_password(char *string, Url *u)
{
    int i;
    char *password;
    char *at;
    char *slash;
    at = strchr(string, '@');
    slash = strchr(string, '/');
    if( (!at) || (slash && (at >= slash)) )
        return string;
    for(i = 0 ; string[i] != '@'; i++);
    password = (char*)malloc(i);
    memcpy(password, string, i);
    password[i] = '\0';
    string += i + 1;
    u->password = password;
    return string;
}

canonical_original_code:
char *get_password(char *string, struct _Url *u)
{
    int i;
    char *password;
    char *at;
    char *slash;
    at = strchr(string, '@');
    slash = strchr(string, '/');
    if( (!at) || (slash && (at >= slash)) )
        return string;
    for(i = 0 ; string[i] != '@'; i++);
    password = (char *)malloc(i);
    memcpy(password, string, i);
    password[i] = '\0';
    string += i + 1;
    u->password = password;
    return string;
}

variable_types:
password
char *


original_code:
char *
get_hostname(char *url, Url *u)
{
    char *hostname;
    int i;
    for( i = 0; url[i] && url[i] != '/' && url[i] != ':'; i++ );
    hostname = (char*)malloc(i + 1);
    memcpy(hostname, url, i);
    hostname[i] = '\0';
    if(url[i] == ':')
        url += i + 1;
    else
        url += i;
    u->host = hostname;
    return url;
}

canonical_original_code:
char *get_hostname(char *url, struct _Url *u)
{
    char *hostname;
    int i;
    for( i = 0; url[i] && url[i] != '/' && url[i] != ':'; i++ );
    hostname = (char *)malloc(i + 1);
    memcpy(hostname, url, i);
    hostname[i] = '\0';
    if(url[i] == ':')
        url += i + 1;
    else
        url += i;
    u->host = hostname;
    return url;
}

variable_types:
url
char *

variable_types:
hostname
char *


original_code:
char *
get_port(char *url, Url *u)
{
    char *port_string;
    int i;
    for(i = 0; ((*__ctype_b_loc ())[(int) ((url[i]))] & (unsigned short int) _ISdigit); i++);
    if(i == 0)
        return url;
    port_string = (char*)malloc(i + 1);
    memcpy(port_string, url, i + 1);
    port_string[i] = '\0';
    url += i;
    u->port = atoi(port_string);
    if(port_string) free(port_string);
    return url;
}

canonical_original_code:
char *get_port(char *url, struct _Url *u)
{
    char *port_string;
    int i;
    for(i = 0; ((*__ctype_b_loc ())[(int) ((url[i]))] & (unsigned short) _ISdigit); i++);
    if(i == 0)
        return url;
    port_string = (char *)malloc(i + 1);
    memcpy(port_string, url, i + 1);
    port_string[i] = '\0';
    url += i;
    u->port = atoi(port_string);
    if(port_string) free(port_string);
    return url;
}


decompiled_code:
char *__fastcall get_path(void *src, __int64 a2)
{
int v2; // eax
__int64 v3; // rbx
int v4; // ebp
void *v5; // rax
_BYTE *v6; // rax

v2 = strlen((const char *)src);
if ( v2 > 0 )
{
v3 = v2;
while ( 1 )
{
v4 = v3;
if ( *((_BYTE *)src + v3) == 47 )
break;
v4 = --v3;
if ( !v3 )
goto LABEL_7;
}
LABEL_5:
v5 = malloc(v4 + 2);
v6 = memcpy(v5, src, v4 + 1);
v6[v3] = 47;
v6[v3 + 1] = 0;
*(_QWORD *)(a2 + 48) = v6;
return (char *)src + v3 + 1;
}
v4 = v2;
LABEL_7:
v3 = v4;
if ( *((_BYTE *)src + v4) == 47 )
goto LABEL_5;
return (char *)src;
}

canonical_decompiled_code:
char *__fastcall func6(void *src, __int64 a2)
{
int v2; // eax
__int64 v3; // rbx
int v4; // ebp
void *v5; // rax
_BYTE *v6; // rax

v2 = strlen((const char *)src);
if ( v2 > 0 )
{
v3 = v2;
while ( 1 )
{
v4 = v3;
if ( *((_BYTE *)src + v3) == 47 )
break;
v4 = --v3;
if ( !v3 )
goto LABEL_7;
}
LABEL_5:
v5 = malloc(v4 + 2);
v6 = memcpy(v5, src, v4 + 1);
v6[v3] = 47;
v6[v3 + 1] = 0;
*(_QWORD *)(a2 + 48) = v6;
return (char *)src + v3 + 1;
}
v4 = v2;
LABEL_7:
v3 = v4;
if ( *((_BYTE *)src + v4) == 47 )
goto LABEL_5;
return (char *)src;
}

original_code:
char *
get_path(char *url, Url *u)
{
    int i;
    char *path;
    for(i = strlen(url); i > 0 && url[i] != '/'; i--);
    if(url[i] != '/')
        return url;
    path = (char*)malloc(i + 2);
    memcpy(path, url, i + 1);
    path[i] = '/';
    path[i + 1] = '\0';
    url += i + 1;
    u->path = path;
    return url;
}

canonical_original_code:
char *get_path(char *url, struct _Url *u)
{
    int i;
    char *path;
    for(i = strlen(url); i > 0 && url[i] != '/'; i--);
    if(url[i] != '/')
        return url;
    path = (char *)malloc(i + 2);
    memcpy(path, url, i + 1);
    path[i] = '/';
    path[i + 1] = '\0';
    url += i + 1;
    u->path = path;
    return url;
}

variable_types:
path
char *


decompiled_code:
void *__fastcall get_file(void *src, __int64 a2)
{
size_t v2; // r12
void *v3; // rax

if ( !*(_BYTE *)src )
return 0LL;
v2 = strlen((const char *)src) + 1;
v3 = malloc(v2);
*(_QWORD *)(a2 + 56) = memcpy(v3, src, v2);
return src;
}

canonical_decompiled_code:
void *__fastcall func7(void *src, __int64 a2)
{
size_t v2; // r12
void *v3; // rax

if ( !*(_BYTE *)src )
return 0LL;
v2 = strlen((const char *)src) + 1;
v3 = malloc(v2);
*(_QWORD *)(a2 + 56) = memcpy(v3, src, v2);
return src;
}

original_code:
char *
get_file(char *string, Url *u)
{
  char *file;
  if( !string[0] )
    return ((void *)0);
  file = (char*)malloc(strlen(string) + 1);
  memcpy(file, string, strlen(string) + 1);
  u->file = file;
  return string;
}

canonical_original_code:
char *get_file(char *string, struct _Url *u)
{
  char *file;
  if( !string[0] )
    return ((void *)0);
  file = (char *)malloc(strlen(string) + 1);
  memcpy(file, string, strlen(string) + 1);
  u->file = file;
  return string;
}

variable_types:
file
char *


decompiled_code:
_DWORD *url_new()
{
_DWORD *result; // rax

result = malloc(0x40uLL);
*(_QWORD *)result = 0LL;
result[2] = 0;
*((_QWORD *)result + 2) = 0LL;
*((_QWORD *)result + 3) = 0LL;
*((_QWORD *)result + 4) = 0LL;
result[10] = 0;
*((_QWORD *)result + 6) = 0LL;
*((_QWORD *)result + 7) = 0LL;
return result;
}

canonical_decompiled_code:
_DWORD *func8()
{
_DWORD *result; // rax

result = malloc(0x40uLL);
*(_QWORD *)result = 0LL;
result[2] = 0;
*((_QWORD *)result + 2) = 0LL;
*((_QWORD *)result + 3) = 0LL;
*((_QWORD *)result + 4) = 0LL;
result[10] = 0;
*((_QWORD *)result + 6) = 0LL;
*((_QWORD *)result + 7) = 0LL;
return result;
}

original_code:
Url *
url_new(void)
{
  Url *new_url;
  new_url = (Url*)malloc(sizeof(Url));
  new_url->full_url = ((void *)0);
  new_url->service_type = 0;
  new_url->username = ((void *)0);
  new_url->password = ((void *)0);
  new_url->host = ((void *)0);
  new_url->port = 0;
  new_url->path = ((void *)0);
  new_url->file = ((void *)0);
  return new_url;
}

canonical_original_code:
struct _Url *url_new()
{
  struct _Url *new_url;
  new_url = (struct _Url *)malloc(sizeof(Url));
  new_url->full_url = ((void *)0);
  new_url->service_type = 0;
  new_url->username = ((void *)0);
  new_url->password = ((void *)0);
  new_url->host = ((void *)0);
  new_url->port = 0;
  new_url->path = ((void *)0);
  new_url->file = ((void *)0);
  return new_url;
}

return_type: struct _Url { char *full_url; int service_type; char *username; char *password; char *host; int port; char *path; char *file; } *


decompiled_code:
void __fastcall url_destroy(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi
void *v6; // rdi
void *v7; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 3);
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 4);
if ( v5 )
free(v5);
v6 = (void *)*((_QWORD *)ptr + 6);
if ( v6 )
free(v6);
v7 = (void *)*((_QWORD *)ptr + 7);
if ( v7 )
free(v7);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi
void *v6; // rdi
void *v7; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 3);
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 4);
if ( v5 )
free(v5);
v6 = (void *)*((_QWORD *)ptr + 6);
if ( v6 )
free(v6);
v7 = (void *)*((_QWORD *)ptr + 7);
if ( v7 )
free(v7);
free(ptr);
}
}

original_code:
void
url_destroy(Url *u)
{
    if( u ) {
        if(u->full_url) free(u->full_url);
        if(u->username) free(u->username);
        if(u->password) free(u->password);
        if(u->host) free(u->host);
        if(u->path) free(u->path);
        if(u->file) free(u->file);
        memset(u, 0, sizeof(Url));
        if(u) free(u);
    }
}

canonical_original_code:
void url_destroy(struct _Url *u)
{
    if( u ) {
        if(u->full_url) free(u->full_url);
        if(u->username) free(u->username);
        if(u->password) free(u->password);
        if(u->host) free(u->host);
        if(u->path) free(u->path);
        if(u->file) free(u->file);
        memset(u, 0, sizeof(Url));
        if(u) free(u);
    }
}

return_type: void


decompiled_code:
_QWORD *url_resource_new()
{
_QWORD *result; // rax

result = malloc(0x40uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
*((_BYTE *)result + 40) = 0;
result[6] = 0LL;
result[7] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func10()
{
_QWORD *result; // rax

result = malloc(0x40uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
*((_BYTE *)result + 40) = 0;
result[6] = 0LL;
result[7] = 0LL;
return result;
}

original_code:
UrlResource *
url_resource_new(void)
{
    UrlResource *new_resource;
    new_resource = (UrlResource*)malloc(sizeof(UrlResource));
    new_resource->url = ((void *)0);
    new_resource->outfile = ((void *)0);
    new_resource->proxy = ((void *)0);
    new_resource->proxy_username = ((void *)0);
    new_resource->proxy_password = ((void *)0);
    new_resource->options = 0;
    new_resource->outfile_size = 0;
    new_resource->outfile_offset = 0;
    return new_resource;
}

canonical_original_code:
struct _UrlResource *url_resource_new()
{
    struct _UrlResource *new_resource;
    new_resource = (struct _UrlResource *)malloc(sizeof(UrlResource));
    new_resource->url = ((void *)0);
    new_resource->outfile = ((void *)0);
    new_resource->proxy = ((void *)0);
    new_resource->proxy_username = ((void *)0);
    new_resource->proxy_password = ((void *)0);
    new_resource->options = 0;
    new_resource->outfile_size = 0;
    new_resource->outfile_offset = 0;
    return new_resource;
}

variable_types: struct _UrlResource { struct _Url { char *full_url; int service_type; char *username; char *password; char *host; int port; char *path; char *file; } *url; char *outfile; char *proxy; char *proxy_username; char *proxy_password; unsigned char options; long outfile_size; long outfile_offset; } *

user_defined_types: struct _UrlResource { struct _Url *url; char *outfile; char *proxy; char *proxy_username; char *proxy_password; unsigned char options; long outfile_size; long outfile_offset; }


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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
url_destroy(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}
}

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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
func9(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}
}

original_code:
void
url_resource_destroy(UrlResource *rsrc)
{
    if (rsrc) {
        if (rsrc->url) {
            url_destroy(rsrc->url);
            rsrc->url = ((void *)0);
        }
        if(rsrc->outfile) free(rsrc->outfile);
        if(rsrc) free(rsrc);
    }
}

canonical_original_code:
void url_resource_destroy(struct _UrlResource *rsrc)
{
    if (rsrc) {
        if (rsrc->url) {
            url_destroy(rsrc->url);
            rsrc->url = ((void *)0);
        }
        if(rsrc->outfile) free(rsrc->outfile);
        if(rsrc) free(rsrc);
    }
}


decompiled_code:
void *alarm_line_init()
{
return calloc(1uLL, 0x28uLL);
}

canonical_decompiled_code:
void *func4()
{
return calloc(1uLL, 0x28uLL);
}

original_code:
alarm_line_t* alarm_line_init()
{
    alarm_line_t* alarm_line = ((void *)0);
    alarm_line = (alarm_line_t*)calloc(1, sizeof(alarm_line_t));
    return alarm_line;
}

canonical_original_code:
struct alarm_line_t *alarm_line_init()
{
    struct alarm_line_t *alarm_line = ((void *)0);
    alarm_line = (struct alarm_line_t *)calloc(1, sizeof(alarm_line_t));
    return alarm_line;
}

variable_types: struct alarm_line_t { char *text; unsigned int hash; unsigned char sent; long timestamp; unsigned short channel; unsigned char event; char description[9]; } *


decompiled_code:
__int64 __fastcall alarm_line_destroy(void *ptr)
{
void *v3; // rdi

if ( !ptr )
return 0LL;
v3 = *(void **)ptr;
if ( v3 )
free(v3);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *ptr)
{
void *v3; // rdi

if ( !ptr )
return 0LL;
v3 = *(void **)ptr;
if ( v3 )
free(v3);
free(ptr);
return 0LL;
}

original_code:
alarm_line_t* alarm_line_destroy( alarm_line_t* alarm_line )
{
    if (alarm_line) {
        if (alarm_line->text) {
            free(alarm_line->text);
        }
        free(alarm_line);
        alarm_line = ((void *)0);
    }
    return alarm_line;
}

canonical_original_code:
struct alarm_line_t *alarm_line_destroy(struct alarm_line_t *alarm_line)
{
    if (alarm_line) {
        if (alarm_line->text) {
            free(alarm_line->text);
        }
        free(alarm_line);
        alarm_line = ((void *)0);
    }
    return alarm_line;
}

return_type: struct alarm_line_t { char *text; unsigned int hash; unsigned char sent; long timestamp; unsigned short channel; unsigned char event; char description[9]; } *


decompiled_code:
void *alarm_context_init()
{
void *v0; // rax
void *v1; // r12

v0 = calloc(1uLL, 0x78uLL);
v1 = v0;
if ( !v0 )
return v1;
if ( (unsigned int)list_init(v0) != -1 )
{
list_attributes_comparator(v1, alarm_list_comparator);
list_attributes_seeker(v1, alarm_list_seeker);
return v1;
}
free(v1);
return 0LL;
}

canonical_decompiled_code:
void *func6()
{
void *v0; // rax
void *v1; // r12

v0 = calloc(1uLL, 0x78uLL);
v1 = v0;
if ( !v0 )
return v1;
if ( (unsigned int)list_init(v0) != -1 )
{
list_attributes_comparator(v1, alarm_list_comparator);
list_attributes_seeker(v1, alarm_list_seeker);
return v1;
}
free(v1);
return 0LL;
}

original_code:
alarm_context_t* alarm_context_init()
{
    alarm_context_t* alarm_list = ((void *)0);
    alarm_list = (alarm_context_t*)calloc(1, sizeof(alarm_context_t));
    if (alarm_list) {
        if (list_init(alarm_list) == -1) {
            free(alarm_list);
            alarm_list = ((void *)0);
        } else {
            list_attributes_comparator(alarm_list, _alarm_list_comparator);
            list_attributes_seeker(alarm_list, _alarm_list_seeker);
        }
    }
    return alarm_list;
}

canonical_original_code:
struct list_t *alarm_context_init()
{
    struct list_t *alarm_list = ((void *)0);
    alarm_list = (struct list_t *)calloc(1, sizeof(alarm_context_t));
    if (alarm_list) {
        if (list_init(alarm_list) == -1) {
            free(alarm_list);
            alarm_list = ((void *)0);
        } else {
            list_attributes_comparator(alarm_list, _alarm_list_comparator);
            list_attributes_seeker(alarm_list, _alarm_list_seeker);
        }
    }
    return alarm_list;
}

variable_types: struct list_t { struct list_entry_s { void *data; struct list_entry_s *next; struct list_entry_s *prev; } *head_sentinel; struct list_entry_s *tail_sentinel; struct list_entry_s *mid; unsigned int numels; struct list_entry_s **spareels; unsigned int spareelsnum; int iter_active; unsigned int iter_pos; struct list_entry_s *iter_curentry; struct list_attributes_s { int (*comparator)(void *a, void *b); int (*seeker)(void *el, void *indicator); unsigned long (*meter)(void *el); int copy_data; int (*hasher)(void *el); void *(*serializer)(void *el, unsigned int *serializ_len); void *(*unserializer)(void *data, unsigned int *data_len); } attrs; } *

user_defined_types: struct list_t { struct list_entry_s *head_sentinel; struct list_entry_s *tail_sentinel; struct list_entry_s *mid; unsigned int numels; struct list_entry_s **spareels; unsigned int spareelsnum; int iter_active; unsigned int iter_pos; struct list_entry_s *iter_curentry; struct list_attributes_s attrs; }


decompiled_code:
__int64 __fastcall alarm_context_destroy(void *ptr)
{
void *v2; // rax

if ( !ptr )
return 0LL;
while ( !(unsigned int)list_empty(ptr) )
{
v2 = (void *)list_fetch(ptr);
alarm_line_destroy(v2);
}
list_destroy(ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *ptr)
{
void *v2; // rax

if ( !ptr )
return 0LL;
while ( !(unsigned int)list_empty(ptr) )
{
v2 = (void *)list_fetch(ptr);
func5(v2);
}
list_destroy(ptr);
free(ptr);
return 0LL;
}

original_code:
alarm_context_t* alarm_context_destroy( alarm_context_t* alarm_list )
{
    alarm_line_t* line = ((void *)0);
    if (alarm_list) {
        while (!list_empty(alarm_list)) {
            line = (alarm_line_t*)list_fetch(alarm_list);
            alarm_line_destroy(line);
        }
        list_destroy(alarm_list);
        free(alarm_list);
        alarm_list = ((void *)0);
    }
    return alarm_list;
}

canonical_original_code:
struct list_t *alarm_context_destroy(struct list_t *alarm_list)
{
    struct alarm_line_t *line = ((void *)0);
    if (alarm_list) {
        while (!list_empty(alarm_list)) {
            line = (struct alarm_line_t *)list_fetch(alarm_list);
            alarm_line_destroy(line);
        }
        list_destroy(alarm_list);
        free(alarm_list);
        alarm_list = ((void *)0);
    }
    return alarm_list;
}

return_type: struct list_t { struct list_entry_s { void *data; struct list_entry_s *next; struct list_entry_s *prev; } *head_sentinel; struct list_entry_s *tail_sentinel; struct list_entry_s *mid; unsigned int numels; struct list_entry_s **spareels; unsigned int spareelsnum; int iter_active; unsigned int iter_pos; struct list_entry_s *iter_curentry; struct list_attributes_s { int (*comparator)(void *a, void *b); int (*seeker)(void *el, void *indicator); unsigned long (*meter)(void *el); int copy_data; int (*hasher)(void *el); void *(*serializer)(void *el, unsigned int *serializ_len); void *(*unserializer)(void *data, unsigned int *data_len); } attrs; } *

user_defined_types: struct alarm_line_t { char *text; unsigned int hash; unsigned char sent; long timestamp; unsigned short channel; unsigned char event; char description[9]; }


decompiled_code:
void *csv_context_init()
{
void *v0; // rax
void *v1; // r12

v0 = malloc(0x78uLL);
v1 = v0;
if ( !v0 )
return v1;
if ( (unsigned int)list_init(v0) != -1 )
{
list_attributes_seeker(v1, buffer_list_seeker);
list_attributes_comparator(v1, buffer_list_comparator);
return v1;
}
free(v1);
return 0LL;
}

canonical_decompiled_code:
void *func8()
{
void *v0; // rax
void *v1; // r12

v0 = malloc(0x78uLL);
v1 = v0;
if ( !v0 )
return v1;
if ( (unsigned int)list_init(v0) != -1 )
{
list_attributes_seeker(v1, buffer_list_seeker);
list_attributes_comparator(v1, buffer_list_comparator);
return v1;
}
free(v1);
return 0LL;
}

original_code:
csv_context_t* csv_context_init()
{
    csv_context_t* csv_buffer_list = ((void *)0);
    csv_buffer_list = (csv_context_t*)malloc(sizeof(csv_context_t));
    if (csv_buffer_list) {
        if (list_init(csv_buffer_list) == -1) {
            free(csv_buffer_list);
            csv_buffer_list = ((void *)0);
        } else {
            list_attributes_seeker( csv_buffer_list, _buffer_list_seeker );
            list_attributes_comparator( csv_buffer_list, _buffer_list_comparator );
        }
    }
    return csv_buffer_list;
}

canonical_original_code:
struct list_t *csv_context_init()
{
    struct list_t *csv_buffer_list = ((void *)0);
    csv_buffer_list = (struct list_t *)malloc(sizeof(csv_context_t));
    if (csv_buffer_list) {
        if (list_init(csv_buffer_list) == -1) {
            free(csv_buffer_list);
            csv_buffer_list = ((void *)0);
        } else {
            list_attributes_seeker( csv_buffer_list, _buffer_list_seeker );
            list_attributes_comparator( csv_buffer_list, _buffer_list_comparator );
        }
    }
    return csv_buffer_list;
}

user_defined_types: struct list_attributes_s { int (*comparator)(void *a, void *b); int (*seeker)(void *el, void *indicator); unsigned long (*meter)(void *el); int copy_data; int (*hasher)(void *el); void *(*serializer)(void *el, unsigned int *serializ_len); void *(*unserializer)(void *data, unsigned int *data_len); }

user_defined_types: struct list_entry_s { void *data; struct list_entry_s *next; struct list_entry_s *prev; }


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

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

original_code:
csv_header_t* csv_header_init()
{
    csv_header_t* csv_header = ((void *)0);
    csv_header = (csv_header_t*)calloc(1, sizeof(csv_header_t));
    return csv_header;
}

canonical_original_code:
struct csv_header_t *csv_header_init()
{
    struct csv_header_t *csv_header = ((void *)0);
    csv_header = (struct csv_header_t *)calloc(1, sizeof(csv_header_t));
    return csv_header;
}

variable_types: struct csv_header_t { char *name; char *description; char *unit_of_measure; unsigned short channel; } *


decompiled_code:
__int64 __fastcall csv_header_destroy(void *ptr)
{
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi

if ( !ptr )
return 0LL;
v3 = *(void **)ptr;
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 1);
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 2);
if ( v5 )
free(v5);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(void *ptr)
{
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi

if ( !ptr )
return 0LL;
v3 = *(void **)ptr;
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 1);
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 2);
if ( v5 )
free(v5);
free(ptr);
return 0LL;
}

original_code:
csv_header_t* csv_header_destroy(csv_header_t* csv_header)
{
    if (csv_header) {
        if (csv_header->name) {
            free(csv_header->name);
            csv_header->name = ((void *)0);
        }
        if (csv_header->description) {
            free(csv_header->description);
            csv_header->description = ((void *)0);
        }
        if (csv_header->unit_of_measure) {
            free(csv_header->unit_of_measure);
            csv_header->unit_of_measure = ((void *)0);
        }
        free(csv_header);
        csv_header = ((void *)0);
    }
    return csv_header;
}

canonical_original_code:
struct csv_header_t *csv_header_destroy(struct csv_header_t *csv_header)
{
    if (csv_header) {
        if (csv_header->name) {
            free(csv_header->name);
            csv_header->name = ((void *)0);
        }
        if (csv_header->description) {
            free(csv_header->description);
            csv_header->description = ((void *)0);
        }
        if (csv_header->unit_of_measure) {
            free(csv_header->unit_of_measure);
            csv_header->unit_of_measure = ((void *)0);
        }
        free(csv_header);
        csv_header = ((void *)0);
    }
    return csv_header;
}

return_type: struct csv_header_t { char *name; char *description; char *unit_of_measure; unsigned short channel; } *


decompiled_code:
void *csv_list_init()
{
void *v0; // rax
void *v1; // r12
void *v3; // rdi

v0 = calloc(1uLL, 0x78uLL);
v1 = v0;
if ( v0 && (unsigned int)list_init(v0) == -1 )
{
v3 = v1;
v1 = 0LL;
free(v3);
}
return v1;
}

canonical_decompiled_code:
void *func11()
{
void *v0; // rax
void *v1; // r12
void *v3; // rdi

v0 = calloc(1uLL, 0x78uLL);
v1 = v0;
if ( v0 && (unsigned int)list_init(v0) == -1 )
{
v3 = v1;
v1 = 0LL;
free(v3);
}
return v1;
}

original_code:
csv_list_t* csv_list_init()
{
    csv_list_t* csv_list = ((void *)0);
    csv_list = (csv_list_t*)calloc(1, sizeof(csv_list_t));
    if (csv_list && (list_init(csv_list) == -1)) {
        free(csv_list);
        csv_list = ((void *)0);
    }
    return csv_list;
}

canonical_original_code:
struct list_t *csv_list_init()
{
    struct list_t *csv_list = ((void *)0);
    csv_list = (struct list_t *)calloc(1, sizeof(csv_list_t));
    if (csv_list && (list_init(csv_list) == -1)) {
        free(csv_list);
        csv_list = ((void *)0);
    }
    return csv_list;
}


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

v0 = calloc(1uLL, 0x30uLL);
if ( v0 )
{
v0[1] = csv_header_init();
v0[2] = csv_list_init();
}
return v0;
}

original_code:
csv_buffer_t* csv_buffer_init()
{
    csv_buffer_t* csv_buffer = ((void *)0);
    csv_buffer = (csv_buffer_t*)calloc(1, sizeof(csv_buffer_t));
    if (csv_buffer) {
        csv_buffer->header = csv_header_init();
        csv_buffer->list = csv_list_init();
    }
    return csv_buffer;
}

canonical_original_code:
struct csv_buffer_t *csv_buffer_init()
{
    struct csv_buffer_t *csv_buffer = ((void *)0);
    csv_buffer = (struct csv_buffer_t *)calloc(1, sizeof(csv_buffer_t));
    if (csv_buffer) {
        csv_buffer->header = csv_header_init();
        csv_buffer->list = csv_list_init();
    }
    return csv_buffer;
}

variable_types: struct csv_buffer_t { char *file_name; struct csv_header_t { char *name; char *description; char *unit_of_measure; unsigned short channel; } *header; struct list_t { struct list_entry_s { void *data; struct list_entry_s *next; struct list_entry_s *prev; } *head_sentinel; struct list_entry_s *tail_sentinel; struct list_entry_s *mid; unsigned int numels; struct list_entry_s **spareels; unsigned int spareelsnum; int iter_active; unsigned int iter_pos; struct list_entry_s *iter_curentry; struct list_attributes_s { int (*comparator)(void *a, void *b); int (*seeker)(void *el, void *indicator); unsigned long (*meter)(void *el); int copy_data; int (*hasher)(void *el); void *(*serializer)(void *el, unsigned int *serializ_len); void *(*unserializer)(void *data, unsigned int *data_len); } attrs; } *list; long start_time; long end_time; long last_flush; } *

user_defined_types: struct csv_buffer_t { char *file_name; struct csv_header_t *header; struct list_t *list; long start_time; long end_time; long last_flush; }


decompiled_code:
void *csv_row_init()
{
return calloc(1uLL, 0x18uLL);
}

canonical_decompiled_code:
void *func13()
{
return calloc(1uLL, 0x18uLL);
}

original_code:
csv_row_t* csv_row_init()
{
    csv_row_t* csv_row = ((void *)0);
    csv_row = (csv_row_t*)calloc(1, sizeof(csv_row_t));
    return csv_row;
}

canonical_original_code:
struct csv_row_t *csv_row_init()
{
    struct csv_row_t *csv_row = ((void *)0);
    csv_row = (struct csv_row_t *)calloc(1, sizeof(csv_row_t));
    return csv_row;
}

variable_types: struct csv_row_t { long timestamp; int average; int high; int low; unsigned char empty; } *


decompiled_code:
__int64 __fastcall csv_row_destroy(void *a1)
{
if ( a1 )
free(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(void *a1)
{
if ( a1 )
free(a1);
return 0LL;
}

original_code:
csv_row_t* csv_row_destroy(csv_row_t* csv_row)
{
    if (csv_row) {
        free(csv_row);
        csv_row = ((void *)0);
    }
    return csv_row;
}

canonical_original_code:
struct csv_row_t *csv_row_destroy(struct csv_row_t *csv_row)
{
    if (csv_row) {
        free(csv_row);
        csv_row = ((void *)0);
    }
    return csv_row;
}

return_type: struct csv_row_t { long timestamp; int average; int high; int low; unsigned char empty; } *


decompiled_code:
__int64 __fastcall csv_list_destroy(void *ptr)
{
void *v2; // rax

if ( !ptr )
return 0LL;
while ( !(unsigned int)list_empty(ptr) )
{
v2 = (void *)list_fetch(ptr);
csv_row_destroy(v2);
}
list_destroy(ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(void *ptr)
{
void *v2; // rax

if ( !ptr )
return 0LL;
while ( !(unsigned int)list_empty(ptr) )
{
v2 = (void *)list_fetch(ptr);
func14(v2);
}
list_destroy(ptr);
free(ptr);
return 0LL;
}

original_code:
csv_list_t* csv_list_destroy(csv_list_t* csv_list)
{
    csv_row_t* csv_row = ((void *)0);
    if (csv_list) {
        while(!list_empty(csv_list)) {
            csv_row = list_fetch(csv_list);
            csv_row = csv_row_destroy(csv_row);
        }
        list_destroy(csv_list);
        free(csv_list);
        csv_list = ((void *)0);
    }
    return csv_list;
}

canonical_original_code:
struct list_t *csv_list_destroy(struct list_t *csv_list)
{
    struct csv_row_t *csv_row = ((void *)0);
    if (csv_list) {
        while(!list_empty(csv_list)) {
            csv_row = list_fetch(csv_list);
            csv_row = csv_row_destroy(csv_row);
        }
        list_destroy(csv_list);
        free(csv_list);
        csv_list = ((void *)0);
    }
    return csv_list;
}

user_defined_types: struct csv_row_t { long timestamp; int average; int high; int low; unsigned char empty; }


decompiled_code:
__int64 __fastcall csv_buffer_destroy(void *ptr)
{
void *v3; // rdi
__int64 v4; // rax
void *v5; // rdi

if ( !ptr )
return 0LL;
v3 = *(void **)ptr;
if ( v3 )
{
free(v3);
*(_QWORD *)ptr = 0LL;
}
v4 = csv_header_destroy(*((void **)ptr + 1));
v5 = (void *)*((_QWORD *)ptr + 2);
*((_QWORD *)ptr + 1) = v4;
csv_list_destroy(v5);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(void *ptr)
{
void *v3; // rdi
__int64 v4; // rax
void *v5; // rdi

if ( !ptr )
return 0LL;
v3 = *(void **)ptr;
if ( v3 )
{
free(v3);
*(_QWORD *)ptr = 0LL;
}
v4 = func10(*((void **)ptr + 1));
v5 = (void *)*((_QWORD *)ptr + 2);
*((_QWORD *)ptr + 1) = v4;
func15(v5);
free(ptr);
return 0LL;
}

original_code:
csv_buffer_t* csv_buffer_destroy(csv_buffer_t* csv_buffer)
{
    if (csv_buffer) {
        if (csv_buffer->file_name) {
            free(csv_buffer->file_name);
            csv_buffer->file_name = ((void *)0);
        }
        csv_buffer->header = csv_header_destroy(csv_buffer->header);
        csv_buffer->list = csv_list_destroy(csv_buffer->list);
        free(csv_buffer);
        csv_buffer = ((void *)0);
    }
    return csv_buffer;
}

canonical_original_code:
struct csv_buffer_t *csv_buffer_destroy(struct csv_buffer_t *csv_buffer)
{
    if (csv_buffer) {
        if (csv_buffer->file_name) {
            free(csv_buffer->file_name);
            csv_buffer->file_name = ((void *)0);
        }
        csv_buffer->header = csv_header_destroy(csv_buffer->header);
        csv_buffer->list = csv_list_destroy(csv_buffer->list);
        free(csv_buffer);
        csv_buffer = ((void *)0);
    }
    return csv_buffer;
}

return_type: struct csv_buffer_t { char *file_name; struct csv_header_t { char *name; char *description; char *unit_of_measure; unsigned short channel; } *header; struct list_t { struct list_entry_s { void *data; struct list_entry_s *next; struct list_entry_s *prev; } *head_sentinel; struct list_entry_s *tail_sentinel; struct list_entry_s *mid; unsigned int numels; struct list_entry_s **spareels; unsigned int spareelsnum; int iter_active; unsigned int iter_pos; struct list_entry_s *iter_curentry; struct list_attributes_s { int (*comparator)(void *a, void *b); int (*seeker)(void *el, void *indicator); unsigned long (*meter)(void *el); int copy_data; int (*hasher)(void *el); void *(*serializer)(void *el, unsigned int *serializ_len); void *(*unserializer)(void *data, unsigned int *data_len); } attrs; } *list; long start_time; long end_time; long last_flush; } *


decompiled_code:
__int64 __fastcall csv_context_destroy(void *ptr)
{
void *v2; // rax

if ( !ptr )
return 0LL;
while ( !(unsigned int)list_empty(ptr) )
{
v2 = (void *)list_fetch(ptr);
csv_buffer_destroy(v2);
}
list_destroy(ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(void *ptr)
{
void *v2; // rax

if ( !ptr )
return 0LL;
while ( !(unsigned int)list_empty(ptr) )
{
v2 = (void *)list_fetch(ptr);
func16(v2);
}
list_destroy(ptr);
free(ptr);
return 0LL;
}

original_code:
csv_context_t* csv_context_destroy( csv_context_t* csv_buffer_list )
{
    csv_buffer_t* csv_buffer = ((void *)0);
    if (csv_buffer_list) {
        while (!list_empty(csv_buffer_list)) {
            csv_buffer = list_fetch(csv_buffer_list);
            csv_buffer = csv_buffer_destroy(csv_buffer);
        }
        list_destroy(csv_buffer_list);
        free(csv_buffer_list);
        csv_buffer_list = ((void *)0);
    }
    return csv_buffer_list;
}

canonical_original_code:
struct list_t *csv_context_destroy(struct list_t *csv_buffer_list)
{
    struct csv_buffer_t *csv_buffer = ((void *)0);
    if (csv_buffer_list) {
        while (!list_empty(csv_buffer_list)) {
            csv_buffer = list_fetch(csv_buffer_list);
            csv_buffer = csv_buffer_destroy(csv_buffer);
        }
        list_destroy(csv_buffer_list);
        free(csv_buffer_list);
        csv_buffer_list = ((void *)0);
    }
    return csv_buffer_list;
}

user_defined_types: struct csv_header_t { char *name; char *description; char *unit_of_measure; unsigned short channel; }


decompiled_code:
__int64 __fastcall int32_to_varint(int a1)
{
__int64 v2; // [rsp+0h] [rbp-28h]

if ( (unsigned int)(a1 + 16) <= 0x1F )
return 1LL;
if ( (unsigned int)(a1 + 2048) <= 0xFFF )
return 2LL;
if ( (unsigned int)(a1 + 0x40000) > 0x7FFFF )
{
if ( (unsigned int)(a1 + 0x1FFFFFF) > 0x3FFFFFE )
v2 = 5LL;
else
v2 = 4LL;
return v2;
}
return 3LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1)
{
__int64 v2; // [rsp+0h] [rbp-28h]

if ( (unsigned int)(a1 + 16) <= 0x1F )
return 1LL;
if ( (unsigned int)(a1 + 2048) <= 0xFFF )
return 2LL;
if ( (unsigned int)(a1 + 0x40000) > 0x7FFFF )
{
if ( (unsigned int)(a1 + 0x1FFFFFF) > 0x3FFFFFE )
v2 = 5LL;
else
v2 = 4LL;
return v2;
}
return 3LL;
}

canonical_original_code:
struct varint int32_to_varint(int integer)
{
    unsigned int *p_integer = ((void *)0);
    struct varint result;
    memset(&result, 0, sizeof(varint));
    p_integer = (unsigned int *)&integer;
    if ((integer < 16) && (integer > -17)) {
        result.num[0] = (*p_integer & 0x0000001f) << 2;
        result.bytes = 1;
    }
    else if ((integer < 2048) && (integer > -2049)) {
        result.num[0] = ((*p_integer & 0x0000001f) << 2) | 0x80;
        result.num[1] = ((*p_integer >> 5) & 0x0000007f);
        result.bytes = 2;
    }
    else if ((integer < 262144) && (integer > -262145)) {
        result.num[0] = ((*p_integer & 0x0000001f) << 2) | 0x80;
        result.num[1] = ((*p_integer >> 5) & 0x0000007f) | 0x80;
        result.num[2] = ((*p_integer >> 12) & 0x0000007f);
        result.bytes = 3;
    }
    else if ((integer < 33554432) && (integer > -33554432)) {
        result.num[0] = ((*p_integer & 0x0000001f) << 2) | 0x80;
        result.num[1] = ((*p_integer >> 5) & 0x0000007f) | 0x80;
        result.num[2] = ((*p_integer >> 12) & 0x0000007f) | 0x80;
        result.num[3] = ((*p_integer >> 19) & 0x0000007f);
        result.bytes = 4;
    }
    else {
        result.num[0] = ((*p_integer & 0x0000001f) << 2) | 0x80;
        result.num[1] = ((*p_integer >> 5) & 0x0000007f) | 0x80;
        result.num[2] = ((*p_integer >> 12) & 0x0000007f) | 0x80;
        result.num[3] = ((*p_integer >> 19) & 0x0000007f) | 0x80;
        result.num[4] = ((*p_integer >> 26) & 0x0000003f);
        result.bytes = 5;
    }
    return result;
}

variable_types: integer int

variable_types: struct varint { unsigned long bytes; unsigned char num[5]; }


decompiled_code:
__int64 __fastcall varint_to_int32(unsigned __int8 *a1, _QWORD *a2)
{
unsigned __int8 v2; // al
__int64 result; // rax
__int16 v4; // dx
int v5; // ecx
unsigned int v6; // ecx
char v7; // al
int v8; // eax
int v9; // edx
bool v10; // zf

*a2 = 0LL;
v2 = *a1;
*a2 = 1LL;
result = (v2 >> 2) & 0x1F;
if ( (*a1 & 0x80u) == 0 )
{
if ( (*a1 & 0x40) != 0 )
result = (unsigned __int8)result | 0xFFFFFFE0;
}
else
{
v4 = a1[1];
*a2 = 2LL;
result = (32 * v4) & 0xFE0 | (unsigned int)result;
if ( (a1[1] & 0x80u) == 0 )
{
if ( (a1[1] & 0x40) != 0 )
result = (unsigned __int16)result | 0xFFFFF000;
}
else
{
v5 = a1[2];
*a2 = 3LL;
v6 = result | (v5 << 12) & 0x7F000;
v7 = a1[2];
if ( v7 >= 0 )
{
v10 = (v7 & 0x40) == 0;
result = v6;
if ( !v10 )
result = v6 | 0xFFF80000;
}
else
{
v8 = a1[3];
*a2 = 4LL;
result = v6 | (v8 << 19) & 0x3F80000;
if ( (a1[3] & 0x80u) == 0 )
{
if ( (a1[3] & 0x40) != 0 )
result = (unsigned int)result | 0xFC000000;
}
else
{
v9 = a1[4];
*a2 = 5LL;
result = (v9 << 26) | (unsigned int)result;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned __int8 *a1, _QWORD *a2)
{
unsigned __int8 v2; // al
__int64 result; // rax
__int16 v4; // dx
int v5; // ecx
unsigned int v6; // ecx
char v7; // al
int v8; // eax
int v9; // edx
bool v10; // zf

*a2 = 0LL;
v2 = *a1;
*a2 = 1LL;
result = (v2 >> 2) & 0x1F;
if ( (*a1 & 0x80u) == 0 )
{
if ( (*a1 & 0x40) != 0 )
result = (unsigned __int8)result | 0xFFFFFFE0;
}
else
{
v4 = a1[1];
*a2 = 2LL;
result = (32 * v4) & 0xFE0 | (unsigned int)result;
if ( (a1[1] & 0x80u) == 0 )
{
if ( (a1[1] & 0x40) != 0 )
result = (unsigned __int16)result | 0xFFFFF000;
}
else
{
v5 = a1[2];
*a2 = 3LL;
v6 = result | (v5 << 12) & 0x7F000;
v7 = a1[2];
if ( v7 >= 0 )
{
v10 = (v7 & 0x40) == 0;
result = v6;
if ( !v10 )
result = v6 | 0xFFF80000;
}
else
{
v8 = a1[3];
*a2 = 4LL;
result = v6 | (v8 << 19) & 0x3F80000;
if ( (a1[3] & 0x80u) == 0 )
{
if ( (a1[3] & 0x40) != 0 )
result = (unsigned int)result | 0xFC000000;
}
else
{
v9 = a1[4];
*a2 = 5LL;
result = (v9 << 26) | (unsigned int)result;
}
}
}
}
return result;
}

original_code:
int32_t varint_to_int32( uint8_t* integer, size_t* bytes )
{
    int32_t result = 0;
    uint32_t* p_result = ((void *)0);
    uint8_t* p_num = ((void *)0);
    p_num = integer;
    p_result = (uint32_t*)(&result);
    *bytes = 0;
    *p_result |= (*p_num >> 2) & 0x0000001f;
    *bytes += 1;
    if (!(*p_num & 0x80)) {
        if (*p_num & 0x40) {
            *p_result |= 0xffffffe0;
        }
        goto complete;
    } p_num++;
    *p_result |= (*p_num & 0x0000007f) << 5;
    *bytes += 1;
    if (!(*p_num & 0x80)) {
        if (*p_num & 0x40) {
            *p_result |= 0xfffff000;
        }
        goto complete;
    } p_num++;
    *p_result |= (*p_num & 0x0000007f) << 12;
    *bytes += 1;
    if (!(*p_num & 0x80)) {
        if (*p_num & 0x40) {
            *p_result |= 0xfff80000;
        }
        goto complete;
    } p_num++;
    *p_result |= (*p_num & 0x0000007f) << 19;
    *bytes += 1;
    if (!(*p_num & 0x80)) {
        if (*p_num & 0x40) {
            *p_result |= 0xfc000000;
        }
        goto complete;
    } p_num++;
    *p_result |= (*p_num & 0x3f) << 26;
    *bytes += 1;
 complete:
    return result;
}

canonical_original_code:
int varint_to_int32(unsigned char *integer, unsigned long *bytes)
{
    int result = 0;
    unsigned int *p_result = ((void *)0);
    unsigned char *p_num = ((void *)0);
    p_num = integer;
    p_result = (unsigned int *)(&result);
    *bytes = 0;
    *p_result |= (*p_num >> 2) & 0x0000001f;
    *bytes += 1;
    if (!(*p_num & 0x80)) {
        if (*p_num & 0x40) {
            *p_result |= 0xffffffe0;
        }
        goto complete;
    } p_num++;
    *p_result |= (*p_num & 0x0000007f) << 5;
    *bytes += 1;
    if (!(*p_num & 0x80)) {
        if (*p_num & 0x40) {
            *p_result |= 0xfffff000;
        }
        goto complete;
    } p_num++;
    *p_result |= (*p_num & 0x0000007f) << 12;
    *bytes += 1;
    if (!(*p_num & 0x80)) {
        if (*p_num & 0x40) {
            *p_result |= 0xfff80000;
        }
        goto complete;
    } p_num++;
    *p_result |= (*p_num & 0x0000007f) << 19;
    *bytes += 1;
    if (!(*p_num & 0x80)) {
        if (*p_num & 0x40) {
            *p_result |= 0xfc000000;
        }
        goto complete;
    } p_num++;
    *p_result |= (*p_num & 0x3f) << 26;
    *bytes += 1;
 complete:
    return result;
}

variable_types:
integer
unsigned char *

variable_types:
bytes
unsigned long *

variable_types: result int


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

result = *(_BYTE *)(a1 + a2 / 2) & 8;
if ( (a2 & 1) != 0 )
result = (*(_BYTE *)(a1 + a2 / 2) >> 4) & 8;
return result;
}

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

result = *(_BYTE *)(a1 + a2 / 2) & 8;
if ( (a2 & 1) != 0 )
result = (*(_BYTE *)(a1 + a2 / 2) >> 4) & 8;
return result;
}

original_code:
uint8_t map_4_get( const uint8_t* map, int index )
{
    map += index / 2;
    if (index % 2)
        return ((*(map) >> 4) & 0x08);
    else
        return (*(map) & 0x08);
}

canonical_original_code:
unsigned char map_4_get(unsigned char *map, int index)
{
    map += index / 2;
    if (index % 2)
        return ((*(map) >> 4) & 0x08);
    else
        return (*(map) & 0x08);
}

variable_types:
map
unsigned char *

variable_types: index int

return_type: unsigned char


decompiled_code:
unsigned __int64 __fastcall map_3_set(__int64 a1, int a2, unsigned __int8 a3)
{
unsigned __int64 result; // rax
_BYTE *v4; // rdi
_BYTE *v5; // rsi
_BYTE *v6; // rdi
_BYTE *v7; // rdi
_BYTE *v8; // rdi
_BYTE *v9; // rcx
_BYTE *v10; // rdi

result = (unsigned int)(3 * (a2 / 8));
switch ( a2 % 8 )
{
case 0:
result = (int)result;
*(_BYTE *)((int)result + a1) = *(_BYTE *)((int)result + a1) & 0xF8 | a3 & 7;
break;
case 1:
result = (int)result;
*(_BYTE *)((int)result + a1) = *(_BYTE *)((int)result + a1) & 0xC7 | (8 * a3) & 0x38;
break;
case 2:
v5 = (_BYTE *)(a1 + (int)result);
v6 = (_BYTE *)((int)result + 1 + a1);
*v5 = (a3 << 6) | *v5 & 0x3F;
result = *v6 & 0xFE;
*v6 = *v6 & 0xFE | ((int)a3 >> 2) & 1;
break;
case 3:
v7 = (_BYTE *)((int)result + 1 + a1);
result = *v7 & 0xF1;
*v7 = *v7 & 0xF1 | (2 * a3) & 0xE;
break;
case 4:
v8 = (_BYTE *)((int)result + 1 + a1);
result = *v8 & 0x8F;
*v8 = *v8 & 0x8F | (16 * a3) & 0x70;
break;
case 5:
v9 = (_BYTE *)(a1 + (int)result + 1);
v10 = (_BYTE *)((int)result + 2 + a1);
*v9 = (a3 << 7) | *v9 & 0x7F;
result = *v10 & 0xFC;
*v10 = *v10 & 0xFC | ((int)a3 >> 1) & 3;
break;
case 6:
v4 = (_BYTE *)((int)result + 2 + a1);
result = *v4 & 0xE3;
*v4 = *v4 & 0xE3 | (4 * a3) & 0x1C;
break;
case 7:
result = a1 + (int)result + 2;
*(_BYTE *)result = *(_BYTE *)result & 0x1F | (32 * a3);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func22(__int64 a1, int a2, unsigned __int8 a3)
{
unsigned __int64 result; // rax
_BYTE *v4; // rdi
_BYTE *v5; // rsi
_BYTE *v6; // rdi
_BYTE *v7; // rdi
_BYTE *v8; // rdi
_BYTE *v9; // rcx
_BYTE *v10; // rdi

result = (unsigned int)(3 * (a2 / 8));
switch ( a2 % 8 )
{
case 0:
result = (int)result;
*(_BYTE *)((int)result + a1) = *(_BYTE *)((int)result + a1) & 0xF8 | a3 & 7;
break;
case 1:
result = (int)result;
*(_BYTE *)((int)result + a1) = *(_BYTE *)((int)result + a1) & 0xC7 | (8 * a3) & 0x38;
break;
case 2:
v5 = (_BYTE *)(a1 + (int)result);
v6 = (_BYTE *)((int)result + 1 + a1);
*v5 = (a3 << 6) | *v5 & 0x3F;
result = *v6 & 0xFE;
*v6 = *v6 & 0xFE | ((int)a3 >> 2) & 1;
break;
case 3:
v7 = (_BYTE *)((int)result + 1 + a1);
result = *v7 & 0xF1;
*v7 = *v7 & 0xF1 | (2 * a3) & 0xE;
break;
case 4:
v8 = (_BYTE *)((int)result + 1 + a1);
result = *v8 & 0x8F;
*v8 = *v8 & 0x8F | (16 * a3) & 0x70;
break;
case 5:
v9 = (_BYTE *)(a1 + (int)result + 1);
v10 = (_BYTE *)((int)result + 2 + a1);
*v9 = (a3 << 7) | *v9 & 0x7F;
result = *v10 & 0xFC;
*v10 = *v10 & 0xFC | ((int)a3 >> 1) & 3;
break;
case 6:
v4 = (_BYTE *)((int)result + 2 + a1);
result = *v4 & 0xE3;
*v4 = *v4 & 0xE3 | (4 * a3) & 0x1C;
break;
case 7:
result = a1 + (int)result + 2;
*(_BYTE *)result = *(_BYTE *)result & 0x1F | (32 * a3);
break;
default:
return result;
}
return result;
}

canonical_original_code:
void map_3_set(unsigned char *map, int index, unsigned char value)
{
    int pos = 0;
    pos = (index / 8) * 3;
    switch (index % 8) {
        case 0 :
            *(map+pos) = (*(map+pos) & 0xf8) | ((value & 0x07) ); break;
        case 1 :
            *(map+pos) = (*(map+pos) & 0xc7) | ((value & 0x07) << 3); break;
        case 2 :
            *(map+pos) = (*(map+pos) & 0x3f) | ((value & 0x03) << 6);
            *(map+pos+1) = (*(map+pos+1) & 0xfe) | ((value & 0x04) >> 2); break;
        case 3 :
            *(map+pos+1) = (*(map+pos+1) & 0xf1) | ((value & 0x07) << 1); break;
        case 4 :
            *(map+pos+1) = (*(map+pos+1) & 0x8f) | ((value & 0x07) << 4); break;
        case 5 :
            *(map+pos+1) = (*(map+pos+1) & 0x7f) | ((value & 0x01) << 7);
            *(map+pos+2) = (*(map+pos+2) & 0xfc) | ((value & 0x06) >> 1); break;
        case 6 :
            *(map+pos+2) = (*(map+pos+2) & 0xe3) | ((value & 0x07) << 2); break;
        case 7 :
            *(map+pos+2) = (*(map+pos+2) & 0x1f) | ((value & 0x07) << 5); break;
    }
}

variable_types:
value
unsigned char

variable_types: pos int


decompiled_code:
char __fastcall map_3_get(__int64 a1, int a2)
{
int v2; // edx
char result; // al

v2 = 3 * (a2 / 8);
switch ( a2 % 8 )
{
case 0:
result = *(_BYTE *)(a1 + v2) & 7;
break;
case 1:
result = (*(_BYTE *)(a1 + v2) >> 3) & 7;
break;
case 2:
result = (*(_BYTE *)(a1 + v2) >> 6) | (4 * *(_BYTE *)(a1 + v2 + 1)) & 4;
break;
case 3:
result = (*(_BYTE *)(a1 + v2 + 1) >> 1) & 7;
break;
case 4:
result = (*(_BYTE *)(a1 + v2 + 1) >> 4) & 7;
break;
case 5:
result = (*(_BYTE *)(a1 + v2 + 1) >> 7) | (2 * *(_BYTE *)(a1 + v2 + 2)) & 6;
break;
case 6:
result = (*(_BYTE *)(a1 + v2 + 2) >> 2) & 7;
break;
case 7:
result = *(_BYTE *)(a1 + v2 + 2) >> 5;
break;
default:
JUMPOUT(0xAA8LL);
}
return result;
}

canonical_decompiled_code:
char __fastcall func23(__int64 a1, int a2)
{
int v2; // edx
char result; // al

v2 = 3 * (a2 / 8);
switch ( a2 % 8 )
{
case 0:
result = *(_BYTE *)(a1 + v2) & 7;
break;
case 1:
result = (*(_BYTE *)(a1 + v2) >> 3) & 7;
break;
case 2:
result = (*(_BYTE *)(a1 + v2) >> 6) | (4 * *(_BYTE *)(a1 + v2 + 1)) & 4;
break;
case 3:
result = (*(_BYTE *)(a1 + v2 + 1) >> 1) & 7;
break;
case 4:
result = (*(_BYTE *)(a1 + v2 + 1) >> 4) & 7;
break;
case 5:
result = (*(_BYTE *)(a1 + v2 + 1) >> 7) | (2 * *(_BYTE *)(a1 + v2 + 2)) & 6;
break;
case 6:
result = (*(_BYTE *)(a1 + v2 + 2) >> 2) & 7;
break;
case 7:
result = *(_BYTE *)(a1 + v2 + 2) >> 5;
break;
default:
JUMPOUT(0xAA8LL);
}
return result;
}

original_code:
uint8_t map_3_get( const uint8_t* map, int index )
{
    int pos = 0;
    pos = (index / 8) * 3;
    switch (index % 8) {
        case 0 :
            return ((*(map+pos) ) & 0x07); break;
        case 1 :
            return ((*(map+pos) >> 3) & 0x07); break;
        case 2 :
            return ((*(map+pos) >> 6) & 0x03) |
                   ((*(map+pos+1) << 2) & 0x04); break;
        case 3 :
            return ((*(map+pos+1) >> 1) & 0x07); break;
        case 4 :
            return ((*(map+pos+1) >> 4) & 0x07); break;
        case 5 :
            return ((*(map+pos+1) >> 7) & 0x01) |
                   ((*(map+pos+2) << 1) & 0x06); break;
        case 6 :
            return ((*(map+pos+2) >> 2) & 0x07); break;
        case 7 :
            return ((*(map+pos+2) >> 5) & 0x07); break;
        default:
            return 0;
    };
}

canonical_original_code:
unsigned char map_3_get(unsigned char *map, int index)
{
    int pos = 0;
    pos = (index / 8) * 3;
    switch (index % 8) {
        case 0 :
            return ((*(map+pos) ) & 0x07); break;
        case 1 :
            return ((*(map+pos) >> 3) & 0x07); break;
        case 2 :
            return ((*(map+pos) >> 6) & 0x03) |
                   ((*(map+pos+1) << 2) & 0x04); break;
        case 3 :
            return ((*(map+pos+1) >> 1) & 0x07); break;
        case 4 :
            return ((*(map+pos+1) >> 4) & 0x07); break;
        case 5 :
            return ((*(map+pos+1) >> 7) & 0x01) |
                   ((*(map+pos+2) << 1) & 0x06); break;
        case 6 :
            return ((*(map+pos+2) >> 2) & 0x07); break;
        case 7 :
            return ((*(map+pos+2) >> 5) & 0x07); break;
        default:
            return 0;
    };
}


decompiled_code:
int __fastcall print_seed_time(const char *a1, unsigned __int16 *a2, const char *a3)
{
int result; // eax

if ( a2 )
result = printf(
"%s[%04d-%03d %02d:%02d:%02d.%04d]%s",
a1,
*a2,
a2[1],
*((unsigned __int8 *)a2 + 4),
*((unsigned __int8 *)a2 + 5),
*((unsigned __int8 *)a2 + 6),
a2[4],
a3);
return result;
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, unsigned __int16 *a2, const char *a3)
{
int result; // eax

if ( a2 )
result = printf(
"%s[%04d-%03d %02d:%02d:%02d.%04d]%s",
a1,
*a2,
a2[1],
*((unsigned __int8 *)a2 + 4),
*((unsigned __int8 *)a2 + 5),
*((unsigned __int8 *)a2 + 6),
a2[4],
a3);
return result;
}

original_code:
void print_seed_time( const char* prefix_msg, tseed_time* time,
                      const char* postfix_msg ) {
    if ( time ) {
        printf( "%s[%04d-%03d %02d:%02d:%02d.%04d]%s",
                prefix_msg,
                time->STUNION.STGREG.yr,
                time->STUNION.STGREG.jday,
                time->STUNION.STGREG.hr,
                time->STUNION.STGREG.minute,
                time->STUNION.STGREG.seconds,
                time->STUNION.STGREG.tenth_millisec,
                postfix_msg );
    }
}

canonical_original_code:
void print_seed_time(char *prefix_msg, struct tseed_time *time, char *postfix_msg) {
    if ( time ) {
        printf( "%s[%04d-%03d %02d:%02d:%02d.%04d]%s",
                prefix_msg,
                time->STUNION.STGREG.yr,
                time->STUNION.STGREG.jday,
                time->STUNION.STGREG.hr,
                time->STUNION.STGREG.minute,
                time->STUNION.STGREG.seconds,
                time->STUNION.STGREG.tenth_millisec,
                postfix_msg );
    }
}

variable_types: struct tseed_time { union { struct { unsigned short yr; unsigned short jday; unsigned char hr; unsigned char minute; unsigned char seconds; unsigned char unused; unsigned short tenth_millisec; } STGREG; double fpt; } STUNION; } *


decompiled_code:
int __fastcall print_seed_header(__int64 a1)
{
printf("SEED Record:");
printf(
" %c%c_%c%c%c%c%c %c%c-%c%c%c",
(unsigned int)*(char *)(a1 + 20),
(unsigned int)*(char *)(a1 + 21),
(unsigned int)*(char *)(a1 + 10),
(unsigned int)*(char *)(a1 + 11),
(unsigned int)*(char *)(a1 + 12),
(unsigned int)*(char *)(a1 + 13),
(unsigned int)*(char *)(a1 + 14),
(unsigned int)*(char *)(a1 + 15),
(unsigned int)*(char *)(a1 + 16),
(unsigned int)*(char *)(a1 + 17),
(unsigned int)*(char *)(a1 + 18),
(unsigned int)*(char *)(a1 + 19));
return print_seed_time(" ", (unsigned __int16 *)(a1 + 24), "\n");
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
printf("SEED Record:");
printf(
" %c%c_%c%c%c%c%c %c%c-%c%c%c",
(unsigned int)*(char *)(a1 + 20),
(unsigned int)*(char *)(a1 + 21),
(unsigned int)*(char *)(a1 + 10),
(unsigned int)*(char *)(a1 + 11),
(unsigned int)*(char *)(a1 + 12),
(unsigned int)*(char *)(a1 + 13),
(unsigned int)*(char *)(a1 + 14),
(unsigned int)*(char *)(a1 + 15),
(unsigned int)*(char *)(a1 + 16),
(unsigned int)*(char *)(a1 + 17),
(unsigned int)*(char *)(a1 + 18),
(unsigned int)*(char *)(a1 + 19));
return func1(" ", (unsigned __int16 *)(a1 + 24), "\n");
}

original_code:
void print_seed_header( seed_header* header ) {
    printf( "SEED Record:" );
    printf( " %c%c_%c%c%c%c%c %c%c-%c%c%c",
            header->seednet[0],
            header->seednet[1],
            header->station_id_call_letters[0],
            header->station_id_call_letters[1],
            header->station_id_call_letters[2],
            header->station_id_call_letters[3],
            header->station_id_call_letters[4],
            header->location_id[0],
            header->location_id[1],
            header->channel_id[0],
            header->channel_id[1],
            header->channel_id[2] );
    print_seed_time( " ", &header->starting_time, "\n" );
}

canonical_original_code:
void print_seed_header(struct seed_header *header) {
    printf( "SEED Record:" );
    printf( " %c%c_%c%c%c%c%c %c%c-%c%c%c",
            header->seednet[0],
            header->seednet[1],
            header->station_id_call_letters[0],
            header->station_id_call_letters[1],
            header->station_id_call_letters[2],
            header->station_id_call_letters[3],
            header->station_id_call_letters[4],
            header->location_id[0],
            header->location_id[1],
            header->channel_id[0],
            header->channel_id[1],
            header->channel_id[2] );
    print_seed_time( " ", &header->starting_time, "\n" );
}

variable_types: struct seed_header { struct tseed_sequence { union { char ch[6]; unsigned int num; } SSUNION; } sequence; char seed_record_type; char continuation_record; char station_id_call_letters[5]; char location_id[2]; char channel_id[3]; char seednet[2]; struct tseed_time { union { struct { unsigned short yr; unsigned short jday; unsigned char hr; unsigned char minute; unsigned char seconds; unsigned char unused; unsigned short tenth_millisec; } STGREG; double fpt; } STUNION; } starting_time; unsigned short samples_in_record; short sample_rate_factor; short sample_rate_multiplier; unsigned char activity_flags; unsigned char io_flags; unsigned char data_quality_flags; unsigned char number_of_following_blockettes; int tenth_msec_correction; unsigned short first_data_byte; unsigned short first_blockette_byte; struct data_only_blockette { unsigned short blockette_type; unsigned short next_blockette; unsigned char encoding_format; unsigned char word_order; unsigned char rec_length; unsigned char dob_reserved; } dob; struct data_extension_blockette { unsigned short blockette_type; unsigned short next_blockette; unsigned char qual; unsigned char usec99; unsigned char deb_flags; unsigned char frame_count; } deb; } *

user_defined_types: struct seed_header { struct tseed_sequence sequence; char seed_record_type; char continuation_record; char station_id_call_letters[5]; char location_id[2]; char channel_id[3]; char seednet[2]; struct tseed_time starting_time; unsigned short samples_in_record; short sample_rate_factor; short sample_rate_multiplier; unsigned char activity_flags; unsigned char io_flags; unsigned char data_quality_flags; unsigned char number_of_following_blockettes; int tenth_msec_correction; unsigned short first_data_byte; unsigned short first_blockette_byte; struct data_only_blockette dob; struct data_extension_blockette deb; }


original_code:
uint32_t murmur_32 ( const void *key, size_t length, uint32_t seed )
{
    const uint32_t m = 0x5bd1e995;
    const int r = 24;
    uint32_t h;
    uint32_t k;
    const unsigned char* data;
    h = seed ^ length;
    data = (const unsigned char*)key;
    while (length >= 4)
    {
        k = *(uint32_t*)data;
        k *= m;
        k ^= k >> r;
        k *= m;
        h *= m;
        h ^= k;
        data += 4;
        length -= 4;
    }
    switch (length)
    {
        case 3: h ^= data[2] << 16;
        case 2: h ^= data[1] << 8;
        case 1: h ^= data[0];
                h *= m;
    };
    h ^= h >> 13;
    h *= m;
    h ^= h >> 15;
    return h;
}

canonical_original_code:
unsigned int murmur_32(void *key, unsigned long length, unsigned int seed)
{
    unsigned int m = 0x5bd1e995;
    int r = 24;
    unsigned int h;
    unsigned int k;
    unsigned char *data;
    h = seed ^ length;
    data = (unsigned char *)key;
    while (length >= 4)
    {
        k = *(unsigned int *)data;
        k *= m;
        k ^= k >> r;
        k *= m;
        h *= m;
        h ^= k;
        data += 4;
        length -= 4;
    }
    switch (length)
    {
        case 3: h ^= data[2] << 16;
        case 2: h ^= data[1] << 8;
        case 1: h ^= data[0];
                h *= m;
    };
    h ^= h >> 13;
    h *= m;
    h ^= h >> 15;
    return h;
}

variable_types:
key
void *

variable_types:
length
unsigned long

variable_types:
seed
unsigned int

variable_types:
m
unsigned int

variable_types: r int

variable_types:
h
unsigned int

variable_types:
k
unsigned int

variable_types:
data
unsigned char *

return_type: unsigned int


original_code:
uint64_t murmur_64_a ( const void *key, size_t length, uint64_t seed )
{
    const uint64_t m = 0xc6a4a7935bd1e995LL;
    const int r = 47;
    uint64_t h;
    uint64_t k;
    const uint64_t* data;
    const uint64_t* end;
    const unsigned char* data2;
    h = seed ^ length;
    data = (const uint64_t*)key;
    end = data + (length / 8);
    while (data != end)
    {
        k = *data++;
        k *= m;
        k ^= k >> r;
        k *= m;
        h ^= k;
        h *= m;
    }
    data2 = (const unsigned char*)data;
    switch (length & 7)
    {
        case 7: h ^= (uint64_t)(data[6]) << 48;
        case 6: h ^= (uint64_t)(data[5]) << 40;
        case 5: h ^= (uint64_t)(data[4]) << 32;
        case 4: h ^= (uint64_t)(data[3]) << 24;
        case 3: h ^= (uint64_t)(data[2]) << 16;
        case 2: h ^= (uint64_t)(data[1]) << 8;
        case 1: h ^= (uint64_t)(data[0]);
                h *= m;
    };
    h ^= h >> r;
    h *= m;
    h ^= h >> r;
    return h;
}

canonical_original_code:
unsigned long murmur_64_a(void *key, unsigned long length, unsigned long seed)
{
    unsigned long m = 0xc6a4a7935bd1e995LL;
    int r = 47;
    unsigned long h;
    unsigned long k;
    unsigned long *data;
    unsigned long *end;
    unsigned char *data2;
    h = seed ^ length;
    data = (unsigned long *)key;
    end = data + (length / 8);
    while (data != end)
    {
        k = *data++;
        k *= m;
        k ^= k >> r;
        k *= m;
        h ^= k;
        h *= m;
    }
    data2 = (unsigned char *)data;
    switch (length & 7)
    {
        case 7: h ^= (unsigned long)(data[6]) << 48;
        case 6: h ^= (unsigned long)(data[5]) << 40;
        case 5: h ^= (unsigned long)(data[4]) << 32;
        case 4: h ^= (unsigned long)(data[3]) << 24;
        case 3: h ^= (unsigned long)(data[2]) << 16;
        case 2: h ^= (unsigned long)(data[1]) << 8;
        case 1: h ^= (unsigned long)(data[0]);
                h *= m;
    };
    h ^= h >> r;
    h *= m;
    h ^= h >> r;
    return h;
}

variable_types:
seed
unsigned long

variable_types:
m
unsigned long

variable_types:
h
unsigned long

variable_types:
k
unsigned long

variable_types:
data
unsigned long *

variable_types:
end
unsigned long *


original_code:
uint64_t murmur_64_b ( const void *key, size_t length, uint64_t seed )
{
    const uint32_t m = 0x5bd1e995;
    const int r = 24;
    uint64_t h;
    uint32_t h1;
    uint32_t h2;
    uint32_t k1;
    uint32_t k2;
    const uint32_t* data;
    h1 = seed ^ length;
    h2 = 0;
    data = (const uint32_t*)key;
    while (length >= 8)
    {
        k1 = *data++;
        k1 *= m;
        k1 ^= k1 >> r;
        k1 *= m;
        h1 *= m;
        h1 ^= k1;
        length -= 4;
        k2 = *data++;
        k2 *= m;
        k2 ^= k2 >> r;
        k2 *= m;
        h2 *= m;
        h2 ^= k2;
        length -= 4;
    }
    if (length >= 4)
    {
        k1 = *data++;
        k1 *= m;
        k1 ^= k1 >> r;
        k1 *= m;
        h1 *= m;
        h1 ^= k1;
        length -= 4;
    }
    switch (length)
    {
        case 3: h ^= ((unsigned char*)data)[2] << 16;
        case 2: h ^= ((unsigned char*)data)[1] << 8;
        case 1: h ^= ((unsigned char*)data)[0];
                h *= m;
    };
    h1 ^= h2 >> 18; h1 *=m;
    h2 ^= h1 >> 22; h2 *=m;
    h1 ^= h2 >> 17; h1 *=m;
    h2 ^= h1 >> 19; h2 *=m;
    h = h1;
    h = (h << 32) | h2;
    return h;
}

canonical_original_code:
unsigned long murmur_64_b(void *key, unsigned long length, unsigned long seed)
{
    unsigned int m = 0x5bd1e995;
    int r = 24;
    unsigned long h;
    unsigned int h1;
    unsigned int h2;
    unsigned int k1;
    unsigned int k2;
    unsigned int *data;
    h1 = seed ^ length;
    h2 = 0;
    data = (unsigned int *)key;
    while (length >= 8)
    {
        k1 = *data++;
        k1 *= m;
        k1 ^= k1 >> r;
        k1 *= m;
        h1 *= m;
        h1 ^= k1;
        length -= 4;
        k2 = *data++;
        k2 *= m;
        k2 ^= k2 >> r;
        k2 *= m;
        h2 *= m;
        h2 ^= k2;
        length -= 4;
    }
    if (length >= 4)
    {
        k1 = *data++;
        k1 *= m;
        k1 ^= k1 >> r;
        k1 *= m;
        h1 *= m;
        h1 ^= k1;
        length -= 4;
    }
    switch (length)
    {
        case 3: h ^= ((unsigned char *)data)[2] << 16;
        case 2: h ^= ((unsigned char *)data)[1] << 8;
        case 1: h ^= ((unsigned char *)data)[0];
                h *= m;
    };
    h1 ^= h2 >> 18; h1 *=m;
    h2 ^= h1 >> 22; h2 *=m;
    h1 ^= h2 >> 17; h1 *=m;
    h2 ^= h1 >> 19; h2 *=m;
    h = h1;
    h = (h << 32) | h2;
    return h;
}

variable_types:
data
unsigned int *


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

result = 1LL;
if ( (__int16)a1 <= (__int16)a3 )
{
result = 0xFFFFFFFFLL;
if ( (__int16)a1 >= (__int16)a3 )
{
result = 1LL;
if ( SWORD1(a1) <= SWORD1(a3) )
{
result = 0xFFFFFFFFLL;
if ( SWORD1(a1) >= SWORD1(a3) )
{
result = 1LL;
if ( SBYTE4(a1) <= SBYTE4(a3) )
{
result = 0xFFFFFFFFLL;
if ( SBYTE4(a1) >= SBYTE4(a3) )
{
result = 1LL;
if ( SBYTE5(a1) <= SBYTE5(a3) )
{
result = 0xFFFFFFFFLL;
if ( SBYTE5(a1) >= SBYTE5(a3) )
{
result = 1LL;
if ( SBYTE6(a1) <= SBYTE6(a3) )
{
result = 0xFFFFFFFFLL;
if ( SBYTE6(a1) >= SBYTE6(a3) )
{
result = (unsigned int)-(a2 < a4);
if ( a2 > a4 )
result = 1LL;
}
}
}
}
}
}
}
}
}
}
return result;
}

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

result = 1LL;
if ( (__int16)a1 <= (__int16)a3 )
{
result = 0xFFFFFFFFLL;
if ( (__int16)a1 >= (__int16)a3 )
{
result = 1LL;
if ( SWORD1(a1) <= SWORD1(a3) )
{
result = 0xFFFFFFFFLL;
if ( SWORD1(a1) >= SWORD1(a3) )
{
result = 1LL;
if ( SBYTE4(a1) <= SBYTE4(a3) )
{
result = 0xFFFFFFFFLL;
if ( SBYTE4(a1) >= SBYTE4(a3) )
{
result = 1LL;
if ( SBYTE5(a1) <= SBYTE5(a3) )
{
result = 0xFFFFFFFFLL;
if ( SBYTE5(a1) >= SBYTE5(a3) )
{
result = 1LL;
if ( SBYTE6(a1) <= SBYTE6(a3) )
{
result = 0xFFFFFFFFLL;
if ( SBYTE6(a1) >= SBYTE6(a3) )
{
result = (unsigned int)-(a2 < a4);
if ( a2 > a4 )
result = 1LL;
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
int ST_TimeComp2(STDTIME2 time_arg1, STDTIME2 time_arg2) {
  if (time_arg1.year > time_arg2.year)
    return(1);
  if (time_arg1.year < time_arg2.year)
    return(-1);
  if (time_arg1.day > time_arg2.day)
    return(1);
  if (time_arg1.day < time_arg2.day)
    return(-1);
  if (time_arg1.hour > time_arg2.hour)
    return(1);
  if (time_arg1.hour < time_arg2.hour)
    return(-1);
  if (time_arg1.minute > time_arg2.minute)
    return(1);
  if (time_arg1.minute < time_arg2.minute)
    return(-1);
  if (time_arg1.second > time_arg2.second)
    return(1);
  if (time_arg1.second < time_arg2.second)
    return(-1);
  if (time_arg1.tenth_msec > time_arg2.tenth_msec)
    return(1);
  if (time_arg1.tenth_msec < time_arg2.tenth_msec)
    return(-1);
  return(0);
}

canonical_original_code:
int ST_TimeComp2(struct __sjtim2 time_arg1, struct __sjtim2 time_arg2) {
  if (time_arg1.year > time_arg2.year)
    return(1);
  if (time_arg1.year < time_arg2.year)
    return(-1);
  if (time_arg1.day > time_arg2.day)
    return(1);
  if (time_arg1.day < time_arg2.day)
    return(-1);
  if (time_arg1.hour > time_arg2.hour)
    return(1);
  if (time_arg1.hour < time_arg2.hour)
    return(-1);
  if (time_arg1.minute > time_arg2.minute)
    return(1);
  if (time_arg1.minute < time_arg2.minute)
    return(-1);
  if (time_arg1.second > time_arg2.second)
    return(1);
  if (time_arg1.second < time_arg2.second)
    return(-1);
  if (time_arg1.tenth_msec > time_arg2.tenth_msec)
    return(1);
  if (time_arg1.tenth_msec < time_arg2.tenth_msec)
    return(-1);
  return(0);
}

variable_types: struct __sjtim2 { short year; short day; char hour; char minute; char second; short tenth_msec; }


decompiled_code:
_QWORD *list_new()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
List *
list_new(void)
{
  List *new_list;
  new_list = (List*)malloc(sizeof(List));
  new_list->data = ((void *)0);
  new_list->next = ((void *)0);
  return new_list;
}

canonical_original_code:
struct _List *list_new()
{
  struct _List *new_list;
  new_list = (struct _List *)malloc(sizeof(List));
  new_list->data = ((void *)0);
  new_list->next = ((void *)0);
  return new_list;
}

variable_types: struct _List { void *data; struct _List *next; } *


optiontrue

decompiled_code:
__int64 __fastcall optiontrue(char a1, int a2, __int64 a3)
{
__int64 v3; // r13
int v4; // er12
__int64 v5; // rbp
_BYTE *v6; // rbx
int v7; // edi

if ( a2 <= 1 )
return 0LL;
v3 = a3 + 8LL * (unsigned int)(a2 - 2) + 8;
v4 = a1;
v5 = a3;
do
{
v6 = *(_BYTE **)(v5 + 8);
v5 += 8LL;
if ( *v6 == 45 )
{
while ( 1 )
{
v7 = (char)*++v6;
if ( !(_BYTE)v7 )
break;
if ( toupper(v7) == v4 )
return 1LL;
}
}
}
while ( v5 != v3 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, int a2, __int64 a3)
{
__int64 v3; // r13
int v4; // er12
__int64 v5; // rbp
_BYTE *v6; // rbx
int v7; // edi

if ( a2 <= 1 )
return 0LL;
v3 = a3 + 8LL * (unsigned int)(a2 - 2) + 8;
v4 = a1;
v5 = a3;
do
{
v6 = *(_BYTE **)(v5 + 8);
v5 += 8LL;
if ( *v6 == 45 )
{
while ( 1 )
{
v7 = (char)*++v6;
if ( !(_BYTE)v7 )
break;
if ( toupper(v7) == v4 )
return 1LL;
}
}
}
while ( v5 != v3 );
return 0LL;
}

original_code:
int optiontrue (char op, int argc, char *argv[])
  {
    char *p;
    while (--argc>0)
      if(*(p=*++argv)=='-')
        while(*++p)
          if (toupper(*p) == op)
            return(1);
    return(0);
  }

canonical_original_code:
int optiontrue(char op, int argc, char *argv[])
  {
    char *p;
    while (--argc>0)
      if(*(p=*++argv)=='-')
        while(*++p)
          if (toupper(*p) == op)
            return(1);
    return(0);
  }

variable_types: op char

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
p
char *


decompiled_code:
__int64 __fastcall decode_SEED_micro_header(__int64 a1, _WORD *a2, _WORD *a3, _WORD *a4, _WORD *a5)
{
__int64 v6; // r13
__int16 v7; // r15
__int16 v8; // bp
__int16 v9; // ax
__int16 v10; // cx
char v11; // dl
__int16 v14; // [rsp+Ch] [rbp-3Ch]

*a4 = 1;
v6 = (__int16)swapb((unsigned int)*(__int16 *)(a1 + 30));
v7 = swapb((unsigned int)*(__int16 *)(a1 + 48));
v8 = swapb((unsigned int)*(__int16 *)(a1 + 50));
v9 = swapb((unsigned int)*(__int16 *)(a1 + 52));
if ( (v7 & 0x7F) != 0 )
{
fwrite("first data does not begin on frame boundary!\n", 1uLL, 0x2DuLL, stderr);
exit(0);
}
v10 = v9;
*a2 = ((unsigned __int64)v7 >> 7) - 1;
if ( (__int16)(((unsigned __int64)v7 >> 7) - 1) < 0 )
{
v14 = v9;
fprintf(stderr, "Firstframe came out negative! - hfirstdata = %d\n", (unsigned int)v7);
v10 = v14;
}
if ( v8 == 48 && v10 == 1000 )
{
v11 = *(_BYTE *)(a1 + 56);
switch ( v11 )
{
case 11:
*a3 = 2;
break;
case 20:
*a3 = 3;
break;
case 10:
*a3 = 1;
break;
default:
fprintf(stderr, "unknown encoding format %d\n");
LABEL_10:
exit(0);
}
switch ( *(_BYTE *)(a1 + 58) )
{
case 7:
*a5 = 1;
return v6;
case 8:
*a5 = 3;
return v6;
case 9:
*a5 = 7;
return v6;
case 0xA:
*a5 = 15;
return v6;
case 0xB:
*a5 = 31;
return v6;
case 0xC:
*a5 = 63;
return v6;
default:
fprintf(stderr, "unknown record length code %d\n");
goto LABEL_10;
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _WORD *a2, _WORD *a3, _WORD *a4, _WORD *a5)
{
__int64 v6; // r13
__int16 v7; // r15
__int16 v8; // bp
__int16 v9; // ax
__int16 v10; // cx
char v11; // dl
__int16 v14; // [rsp+Ch] [rbp-3Ch]

*a4 = 1;
v6 = (__int16)swapb((unsigned int)*(__int16 *)(a1 + 30));
v7 = swapb((unsigned int)*(__int16 *)(a1 + 48));
v8 = swapb((unsigned int)*(__int16 *)(a1 + 50));
v9 = swapb((unsigned int)*(__int16 *)(a1 + 52));
if ( (v7 & 0x7F) != 0 )
{
fwrite("first data does not begin on frame boundary!\n", 1uLL, 0x2DuLL, stderr);
exit(0);
}
v10 = v9;
*a2 = ((unsigned __int64)v7 >> 7) - 1;
if ( (__int16)(((unsigned __int64)v7 >> 7) - 1) < 0 )
{
v14 = v9;
fprintf(stderr, "Firstframe came out negative! - hfirstdata = %d\n", (unsigned int)v7);
v10 = v14;
}
if ( v8 == 48 && v10 == 1000 )
{
v11 = *(_BYTE *)(a1 + 56);
switch ( v11 )
{
case 11:
*a3 = 2;
break;
case 20:
*a3 = 3;
break;
case 10:
*a3 = 1;
break;
default:
fprintf(stderr, "unknown encoding format %d\n");
LABEL_10:
exit(0);
}
switch ( *(_BYTE *)(a1 + 58) )
{
case 7:
*a5 = 1;
return v6;
case 8:
*a5 = 3;
return v6;
case 9:
*a5 = 7;
return v6;
case 0xA:
*a5 = 15;
return v6;
case 0xB:
*a5 = 31;
return v6;
case 0xC:
*a5 = 63;
return v6;
default:
fprintf(stderr, "unknown record length code %d\n");
goto LABEL_10;
}
}
return v6;
}

original_code:
long decode_SEED_micro_header (SEED_data_record *sdr, short *firstframe, short *level, short *flip, short *dframes)
{
  COMPWORD ftest;
  short hfirstdata, hfirstblockette, h1000 ;
  long headertotal ;
  ftest.b[0] = 0x12 ;
  ftest.b[1] = 0x34 ;
  ftest.b[2] = 0x56 ;
  ftest.b[3] = 0x78 ;
  if (ftest.l == 0x78563412)
    *flip = 1 ;
  else
    if (ftest.l == 0x12345678)
      *flip = 0 ;
    else
      {
 fprintf (stderr, "CPU word order cannot be processed\n") ;
 exit (0) ;
      }
  if (*flip)
    {
      headertotal = swapb (sdr->Head.samples_in_record) ;
      hfirstdata = swapb (sdr->Head.first_data_byte) ;
      hfirstblockette = swapb (sdr->Head.first_blockette_byte) ;
      h1000 = swapb (sdr->Head.DOB.blockette_type) ;
    }
  else
    {
      headertotal = sdr->Head.samples_in_record ;
      hfirstdata = sdr->Head.first_data_byte ;
      hfirstblockette = sdr->Head.first_blockette_byte ;
      h1000 = sdr->Head.DOB.blockette_type ;
    }
  if ((hfirstdata % sizeof(compressed_frame)) != 0)
    {
      fprintf (stderr, "first data does not begin on frame boundary!\n") ;
      exit(0);
    }
  *firstframe = hfirstdata/sizeof(compressed_frame) - 1 ;
  if (*firstframe<0) {
    fprintf(stderr, "Firstframe came out negative! - hfirstdata = %d\n",hfirstdata);
  }
  if ((hfirstblockette == 48) && (h1000 == 1000))
    {
      switch (sdr->Head.DOB.encoding_format)
 {
 case 10 :
   *level = 1 ;
   break ;
 case 11 :
   *level = 2 ;
   break ;
 case 20 :
   *level = 3 ;
   break ;
 default :
   fprintf (stderr, "unknown encoding format %d\n",(int)sdr->Head.DOB.encoding_format) ;
   exit (0) ;
   break ;
 }
      switch (sdr->Head.DOB.rec_length)
 {
 case 12 :
   *dframes = 63 ;
   break ;
 case 11 :
   *dframes = 31 ;
   break ;
 case 10 :
   *dframes = 15 ;
   break ;
 case 9 :
   *dframes = 7 ;
   break ;
 case 8 :
   *dframes = 3 ;
   break ;
 case 7 :
   *dframes = 1 ;
   break ;
 default :
   fprintf (stderr, "unknown record length code %d\n",(int)sdr->Head.DOB.rec_length) ;
   exit (0) ;
   break ;
 }
    }
  return (headertotal) ;
}

canonical_original_code:
long decode_SEED_micro_header(struct SEED_data_record *sdr, short *firstframe, short *level, short *flip, short *dframes)
{
  union COMPWORD ftest;
  short hfirstdata; short hfirstblockette; short h1000;
  long headertotal;
  ftest.b[0] = 0x12 ;
  ftest.b[1] = 0x34 ;
  ftest.b[2] = 0x56 ;
  ftest.b[3] = 0x78 ;
  if (ftest.l == 0x78563412)
    *flip = 1 ;
  else
    if (ftest.l == 0x12345678)
      *flip = 0 ;
    else
      {
 fprintf (stderr, "CPU word order cannot be processed\n") ;
 exit (0) ;
      }
  if (*flip)
    {
      headertotal = swapb (sdr->Head.samples_in_record) ;
      hfirstdata = swapb (sdr->Head.first_data_byte) ;
      hfirstblockette = swapb (sdr->Head.first_blockette_byte) ;
      h1000 = swapb (sdr->Head.DOB.blockette_type) ;
    }
  else
    {
      headertotal = sdr->Head.samples_in_record ;
      hfirstdata = sdr->Head.first_data_byte ;
      hfirstblockette = sdr->Head.first_blockette_byte ;
      h1000 = sdr->Head.DOB.blockette_type ;
    }
  if ((hfirstdata % sizeof(compressed_frame)) != 0)
    {
      fprintf (stderr, "first data does not begin on frame boundary!\n") ;
      exit(0);
    }
  *firstframe = hfirstdata/sizeof(compressed_frame) - 1 ;
  if (*firstframe<0) {
    fprintf(stderr, "Firstframe came out negative! - hfirstdata = %d\n",hfirstdata);
  }
  if ((hfirstblockette == 48) && (h1000 == 1000))
    {
      switch (sdr->Head.DOB.encoding_format)
 {
 case 10 :
   *level = 1 ;
   break ;
 case 11 :
   *level = 2 ;
   break ;
 case 20 :
   *level = 3 ;
   break ;
 default :
   fprintf (stderr, "unknown encoding format %d\n",(int)sdr->Head.DOB.encoding_format) ;
   exit (0) ;
   break ;
 }
      switch (sdr->Head.DOB.rec_length)
 {
 case 12 :
   *dframes = 63 ;
   break ;
 case 11 :
   *dframes = 31 ;
   break ;
 case 10 :
   *dframes = 15 ;
   break ;
 case 9 :
   *dframes = 7 ;
   break ;
 case 8 :
   *dframes = 3 ;
   break ;
 case 7 :
   *dframes = 1 ;
   break ;
 default :
   fprintf (stderr, "unknown record length code %d\n",(int)sdr->Head.DOB.rec_length) ;
   exit (0) ;
   break ;
 }
    }
  return (headertotal) ;
}

variable_types: struct SEED_data_record { struct SEED_fixed_data_record_header { char sequence[6]; char seed_record_type; char continuation_record; char station_ID_call_letters[5]; char location_id[2]; char channel_ID[3]; char seednet[2]; struct SEED_time_struc { short yr; short jday; char hr; char minute; char seconds; char unused; short tenth_millisec; } starting_time; short samples_in_record; short sample_rate_factor; short sample_rate_multiplier; char activity_flags; char IO_flags; char data_quality_flags; char number_of_following_blockettes; long tenth_msec_correction; short first_data_byte; short first_blockette_byte; struct data_only_blockette { short blockette_type; short next_offset; char encoding_format; char word_order; char rec_length; char dob_reserved; } DOB; struct data_extension_blockette { short blockette_type; short next_offset; char qual; char usec99; char state_of_health; char frame_count; } DEB; } Head; union COMPWORD { char b[4]; short s[2]; long l; } Frames[-1][16]; } *

variable_types:
firstframe
short *

variable_types:
level
short *

variable_types:
flip
short *

variable_types:
dframes
short *

variable_types: hfirstdata short

variable_types: hfirstblockette short

variable_types: headertotal long

return_type: long

user_defined_types: struct SEED_data_record { struct SEED_fixed_data_record_header Head; union COMPWORD Frames[-1][16]; }

user_defined_types: struct SEED_fixed_data_record_header { char sequence[6]; char seed_record_type; char continuation_record; char station_ID_call_letters[5]; char location_id[2]; char channel_ID[3]; char seednet[2]; struct SEED_time_struc starting_time; short samples_in_record; short sample_rate_factor; short sample_rate_multiplier; char activity_flags; char IO_flags; char data_quality_flags; char number_of_following_blockettes; long tenth_msec_correction; short first_data_byte; short first_blockette_byte; struct data_only_blockette DOB; struct data_extension_blockette DEB; }


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

result = (unsigned int)(a3 - 1);
if ( (unsigned __int16)(a3 - 1) > 0x3Eu )
{
puts("illegal number of data frames specified!");
exit(0);
}
if ( a1 < 0 || (__int16)a3 < a1 )
{
printf("illegal first data frame! (firstframe=%d, dframes=%d)\n", (unsigned int)a1, (unsigned int)(__int16)a3);
exit(0);
}
if ( (unsigned __int16)(a2 - 1) > 2u )
{
puts("illegal compression level!");
exit(0);
}
return result;
}

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

result = (unsigned int)(a3 - 1);
if ( (unsigned __int16)(a3 - 1) > 0x3Eu )
{
puts("illegal number of data frames specified!");
exit(0);
}
if ( a1 < 0 || (__int16)a3 < a1 )
{
printf("illegal first data frame! (firstframe=%d, dframes=%d)\n", (unsigned int)a1, (unsigned int)(__int16)a3);
exit(0);
}
if ( (unsigned __int16)(a2 - 1) > 2u )
{
puts("illegal compression level!");
exit(0);
}
return result;
}

original_code:
void validate_frames (short firstframe, short level, short dframes)
{
  if ((dframes < 1) || (dframes >= 64))
    {
      printf("illegal number of data frames specified!\n");
      exit(0);
    }
  if ((firstframe < 0) || (firstframe > dframes))
    {
      printf("illegal first data frame! (firstframe=%d, dframes=%d)\n",
      firstframe,dframes);
      exit(0);
    }
  if ((level < 1) || (level > 3))
    {
      printf("illegal compression level!\n");
      exit(0);
    }
}

canonical_original_code:
void validate_frames(short firstframe, short level, short dframes)
{
  if ((dframes < 1) || (dframes >= 64))
    {
      printf("illegal number of data frames specified!\n");
      exit(0);
    }
  if ((firstframe < 0) || (firstframe > dframes))
    {
      printf("illegal first data frame! (firstframe=%d, dframes=%d)\n",
      firstframe,dframes);
      exit(0);
    }
  if ((level < 1) || (level > 3))
    {
      printf("illegal compression level!\n");
      exit(0);
    }
}

variable_types: firstframe short

variable_types: level short

variable_types: dframes short


decompiled_code:
__int64 __fastcall STEIM_Decode(char *a1, __int64 a2, __int64 a3, __int16 a4, _DWORD *a5)
{
__int64 v9; // rax
__int64 v10; // r12
__int64 v11; // rax
__int16 v12; // si
__int16 v13; // di
int v14; // edx
__int64 v15; // r14
__int64 v16; // r12
__int16 v18; // [rsp+6h] [rbp-32h] BYREF
__int16 v19; // [rsp+8h] [rbp-30h] BYREF
__int16 v20; // [rsp+Ah] [rbp-2Eh] BYREF
__int16 v21; // [rsp+Ch] [rbp-2Ch] BYREF
__int16 v22[21]; // [rsp+Eh] [rbp-2Ah] BYREF

v9 = init_generic_decompression();
if ( !v9 )
exit(12);
v10 = v9;
v21 = a4;
v22[0] = 63;
v11 = decode_SEED_micro_header((__int64)a1, &v19, &v21, &v20, v22);
v12 = v21;
v13 = v19;
v14 = v22[0];
v15 = v11;
*a5 = v21;
validate_frames(v13, v12, v14);
v16 = decompress_generic_record(
a1,
a2,
&v18,
v10,
(unsigned int)v19,
v15,
(unsigned int)v21,
(unsigned int)v20,
(unsigned int)v22[0]);
if ( (unsigned int)dferrorfatal((unsigned int)v18, stdout) )
{
printf("\n%c%c%c = %ld\n", (unsigned int)a1[15], (unsigned int)a1[16], (unsigned int)a1[17], v16);
puts("decompress: decompress_SEED_record reports errors!");
exit(3);
}
return v16;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, __int64 a2, __int64 a3, __int16 a4, _DWORD *a5)
{
__int64 v9; // rax
__int64 v10; // r12
__int64 v11; // rax
__int16 v12; // si
__int16 v13; // di
int v14; // edx
__int64 v15; // r14
__int64 v16; // r12
__int16 v18; // [rsp+6h] [rbp-32h] BYREF
__int16 v19; // [rsp+8h] [rbp-30h] BYREF
__int16 v20; // [rsp+Ah] [rbp-2Eh] BYREF
__int16 v21; // [rsp+Ch] [rbp-2Ch] BYREF
__int16 v22[21]; // [rsp+Eh] [rbp-2Ah] BYREF

v9 = init_generic_decompression();
if ( !v9 )
exit(12);
v10 = v9;
v21 = a4;
v22[0] = 63;
v11 = func1((__int64)a1, &v19, &v21, &v20, v22);
v12 = v21;
v13 = v19;
v14 = v22[0];
v15 = v11;
*a5 = v21;
func2(v13, v12, v14);
v16 = decompress_generic_record(
a1,
a2,
&v18,
v10,
(unsigned int)v19,
v15,
(unsigned int)v21,
(unsigned int)v20,
(unsigned int)v22[0]);
if ( (unsigned int)dferrorfatal((unsigned int)v18, stdout) )
{
printf("\n%c%c%c = %ld\n", (unsigned int)a1[15], (unsigned int)a1[16], (unsigned int)a1[17], v16);
puts("decompress: decompress_SEED_record reports errors!");
exit(3);
}
return v16;
}

original_code:
long STEIM_Decode(SEED_data_record *sdr, long *udata, int numsams, int steimlevel, int *actuallevel)
{
  long rectotal, headertotal ;
  short dstat ;
  short firstframe, flip, level ;
  dcptype dcp;
  short dframes ;
  if ((dcp = init_generic_decompression ()) == ((void *)0) )
      exit (12) ;
  level = steimlevel ;
  dframes = 63 ;
  headertotal = decode_SEED_micro_header (sdr, &firstframe, &level, &flip, &dframes) ;
  *actuallevel = level;
  validate_frames (firstframe, level, dframes) ;
  rectotal = decompress_generic_record ((generic_data_record *)sdr, udata, &dstat, dcp,
     firstframe, headertotal, level, flip, dframes) ;
  if (dferrorfatal(dstat, stdout))
    {
      printf ("\n%c%c%c = %ld\n",sdr->Head.channel_ID[0],sdr->Head.channel_ID[1],sdr->Head.channel_ID[2],rectotal);
      printf ("decompress: decompress_SEED_record reports errors!\n") ;
      exit(3) ;
    } ;
  return(rectotal);
}

canonical_original_code:
long STEIM_Decode(struct SEED_data_record *sdr, long *udata, int numsams, int steimlevel, int *actuallevel)
{
  long rectotal; long headertotal;
  short dstat;
  short firstframe; short flip; short level;
  struct decompression_continuity *dcp;
  short dframes;
  if ((dcp = init_generic_decompression ()) == ((void *)0) )
      exit (12) ;
  level = steimlevel ;
  dframes = 63 ;
  headertotal = decode_SEED_micro_header (sdr, &firstframe, &level, &flip, &dframes) ;
  *actuallevel = level;
  validate_frames (firstframe, level, dframes) ;
  rectotal = decompress_generic_record ((struct generic_data_record *)sdr, udata, &dstat, dcp,
     firstframe, headertotal, level, flip, dframes) ;
  if (dferrorfatal(dstat, stdout))
    {
      printf ("\n%c%c%c = %ld\n",sdr->Head.channel_ID[0],sdr->Head.channel_ID[1],sdr->Head.channel_ID[2],rectotal);
      printf ("decompress: decompress_SEED_record reports errors!\n") ;
      exit(3) ;
    } ;
  return(rectotal);
}

variable_types:
udata
long *

variable_types: numsams int

variable_types: steimlevel int

variable_types:
actuallevel
int *

variable_types: rectotal long

variable_types: dstat short

variable_types: flip short

variable_types: struct decompression_continuity { long samp_1; long samp_2; short numdecomp; } *

user_defined_types: struct generic_data_record { char head[64]; union COMPWORD frames[-1][16]; }

user_defined_types: struct SEED_time_struc { short yr; short jday; char hr; char minute; char seconds; char unused; short tenth_millisec; }

user_defined_types: struct data_only_blockette { short blockette_type; short next_offset; char encoding_format; char word_order; char rec_length; char dob_reserved; }

user_defined_types: struct data_extension_blockette { short blockette_type; short next_offset; char qual; char usec99; char state_of_health; char frame_count; }

user_defined_types: union COMPWORD { char b[4]; short s[2]; long l; }