decompiled_code:
int sx_mgmt_ctl_wait()
{
int v0; // er12
int v1; // er13
socklen_t addr_len; // [rsp+Ch] [rbp-84h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-80h] BYREF
char v5[88]; // [rsp+20h] [rbp-70h] BYREF
int v6; // [rsp+78h] [rbp-18h]
__int16 v7; // [rsp+7Ch] [rbp-14h]

v0 = socket(1, 1, 0);
if ( v0 < 0 )
return puts("socket() failed");
unlink("./demo_socket");
memset(v5, 0, sizeof(v5));
addr.sa_family = 1;
v7 = 0;
v6 = 0;
strcpy(addr.sa_data, "./demo_socket");
if ( bind(v0, &addr, 0x6Eu) )
return puts("bind() failed");
puts("mgmt_ctl_wait(): Waiting for incoming connection...");
if ( listen(v0, 5) )
return puts("listen() failed");
puts("mgmt_ctl_wait(): Accept new connection.");
v1 = accept(v0, &addr, &addr_len);
connection_handler(v1);
close(v1);
close(v0);
return unlink("./demo_socket");
}

canonical_decompiled_code:
int func2()
{
int v0; // er12
int v1; // er13
socklen_t addr_len; // [rsp+Ch] [rbp-84h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-80h] BYREF
char v5[88]; // [rsp+20h] [rbp-70h] BYREF
int v6; // [rsp+78h] [rbp-18h]
__int16 v7; // [rsp+7Ch] [rbp-14h]

v0 = socket(1, 1, 0);
if ( v0 < 0 )
return puts("socket() failed");
unlink("./demo_socket");
memset(v5, 0, sizeof(v5));
addr.sa_family = 1;
v7 = 0;
v6 = 0;
strcpy(addr.sa_data, "./demo_socket");
if ( bind(v0, &addr, 0x6Eu) )
return puts("bind() failed");
puts("mgmt_ctl_wait(): Waiting for incoming connection...");
if ( listen(v0, 5) )
return puts("listen() failed");
puts("mgmt_ctl_wait(): Accept new connection.");
v1 = accept(v0, &addr, &addr_len);
func1(v1);
close(v1);
close(v0);
return unlink("./demo_socket");
}

original_code:
void sx_mgmt_ctl_wait(
    void
    )
{
    struct sockaddr_un address;
    int socket_fd, connection_fd;
    socklen_t address_length;
    pid_t child;
    socket_fd = socket(1, SOCK_STREAM, 0);
    if(socket_fd < 0)
    {
        printf("socket() failed\n");
        return;
    }
    unlink("./demo_socket");
    memset(&address, 0, sizeof(struct sockaddr_un));
    address.sun_family = 1;
    snprintf(address.sun_path, 108, "./demo_socket");
    if(bind(socket_fd,
            (struct sockaddr *) &address,
            sizeof(struct sockaddr_un)) != 0)
    {
        printf("bind() failed\n");
        return;
    }
    printf("mgmt_ctl_wait(): Waiting for incoming connection...\n");
    if(listen(socket_fd, 5) != 0)
    {
        printf("listen() failed\n");
        return;
    }
    printf("mgmt_ctl_wait(): Accept new connection.\n");
    connection_fd = accept(socket_fd,
                           (struct sockaddr *) &address,
                           &address_length);
    connection_handler(connection_fd);
    close(connection_fd);
    close(socket_fd);
    unlink("./demo_socket");
}

canonical_original_code:
void sx_mgmt_ctl_wait()
{
    struct sockaddr_un address;
    int socket_fd; int connection_fd;
    unsigned int address_length;
    int child;
    socket_fd = socket(1, SOCK_STREAM, 0);
    if(socket_fd < 0)
    {
        printf("socket() failed\n");
        return;
    }
    unlink("./demo_socket");
    memset(&address, 0, sizeof(struct sockaddr_un));
    address.sun_family = 1;
    snprintf(address.sun_path, 108, "./demo_socket");
    if(bind(socket_fd,
            (struct sockaddr *) &address,
            sizeof(struct sockaddr_un)) != 0)
    {
        printf("bind() failed\n");
        return;
    }
    printf("mgmt_ctl_wait(): Waiting for incoming connection...\n");
    if(listen(socket_fd, 5) != 0)
    {
        printf("listen() failed\n");
        return;
    }
    printf("mgmt_ctl_wait(): Accept new connection.\n");
    connection_fd = accept(socket_fd,
                           (struct sockaddr *) &address,
                           &address_length);
    connection_handler(connection_fd);
    close(connection_fd);
    close(socket_fd);
    unlink("./demo_socket");
}

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

variable_types: child int

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


repo: codemonkeyricky/piracast

decompiled_code:
__int64 estimated_source_time_get()
{
__int64 v0; // r12

pthread_mutex_lock(&mutex);
v0 = qword_758;
pthread_mutex_unlock(&mutex);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // r12

pthread_mutex_lock(&mutex);
v0 = qword_758;
pthread_mutex_unlock(&mutex);
return v0;
}

original_code:
static unsigned long long estimated_source_time_get(
    void
    )
{
    unsigned long long time;
    pthread_mutex_lock(&f_cblk.lock);
    time = f_cblk.curr_time;
    pthread_mutex_unlock(&f_cblk.lock);
    return time;
}

canonical_original_code:
static unsigned long long estimated_source_time_get()
{
    unsigned long long time;
    pthread_mutex_lock(&f_cblk.lock);
    time = f_cblk.curr_time;
    pthread_mutex_unlock(&f_cblk.lock);
    return time;
}

variable_types:
time
unsigned long long

return_type: unsigned long long


decompiled_code:
void __noreturn video_scheduler_thread()
{
__int64 v0; // rax
__int64 v1; // r12
unsigned __int64 v2; // rbx
_QWORD *v3; // rbx
void *v4; // rdi

while ( 1 )
{
while ( 1 )
{
v0 = sx_pipe_get(3LL);
v1 = v0;
if ( v0 )
break;
usleep(0x3E8u);
}
v2 = *(_QWORD *)(*(_QWORD *)v0 + 8LL);
if ( v2 >= estimated_source_time_get() )
{
while ( 1 )
{
usleep(0x3E8u);
if ( !v1 )
break;
if ( v2 < estimated_source_time_get() )
goto LABEL_6;
}
}
else
{
LABEL_6:
v3 = *(_QWORD **)(v1 + 16);
do
{
sx_video_sink_buf_set(*v3);
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
while ( v3 );
free(*(void **)v1);
free((void *)v1);
}
}
}

canonical_decompiled_code:
void __noreturn func1()
{
__int64 v0; // rax
__int64 v1; // r12
unsigned __int64 v2; // rbx
_QWORD *v3; // rbx
void *v4; // rdi

while ( 1 )
{
while ( 1 )
{
v0 = sx_pipe_get(3LL);
v1 = v0;
if ( v0 )
break;
usleep(0x3E8u);
}
v2 = *(_QWORD *)(*(_QWORD *)v0 + 8LL);
if ( v2 >= func0() )
{
while ( 1 )
{
usleep(0x3E8u);
if ( !v1 )
break;
if ( v2 < func0() )
goto LABEL_6;
}
}
else
{
LABEL_6:
v3 = *(_QWORD **)(v1 + 16);
do
{
sx_video_sink_buf_set(*v3);
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
while ( v3 );
free(*(void **)v1);
free((void *)v1);
}
}
}

original_code:
void video_scheduler_thread(
    void * arg
    )
{
    sSX_DESC *desc;
    unsigned long long slice_present_time;
    desc = ((void *)0);
    while(1)
    {
        while(1)
        {
            if(desc == ((void *)0))
            {
                desc = sx_pipe_get(3);
                if(desc == ((void *)0))
                {
                    goto next_iter;
                }
                sSLICE_HDR *hdr = (sSLICE_HDR *) desc->data;
                slice_present_time = ((sSLICE_HDR *) desc->data)->timestamp;
            }
            unsigned long long estimated_source_time = estimated_source_time_get();
            unsigned char present = (estimated_source_time > slice_present_time) ? 1 : 0;
            if(!present)
            {
                goto next_iter;
            }
            sSX_DESC *curr = desc->next;
            sSX_DESC *next;
            do
            {
                sx_video_sink_buf_set((sDECODER_HW_BUFFER *) curr->data);
                next = curr->next;
                free(curr);
                curr = next;
            } while (curr != ((void *)0));
            free(desc->data);
            free(desc);
            desc = ((void *)0);
        }
        next_iter:
        usleep(1*1000);
    }
}

canonical_original_code:
void video_scheduler_thread(void *arg)
{
    struct sSX_DESC *desc;
    unsigned long long slice_present_time;
    desc = ((void *)0);
    while(1)
    {
        while(1)
        {
            if(desc == ((void *)0))
            {
                desc = sx_pipe_get(3);
                if(desc == ((void *)0))
                {
                    goto next_iter;
                }
                struct sSLICE_HDR *hdr = (sSLICE_HDR *) desc->data;
                slice_present_time = ((struct sSLICE_HDR *) desc->data)->timestamp;
            }
            unsigned long long estimated_source_time = estimated_source_time_get();
            unsigned char present = (estimated_source_time > slice_present_time) ? 1 : 0;
            if(!present)
            {
                goto next_iter;
            }
            struct sSX_DESC *curr = desc->next;
            struct sSX_DESC *next;
            do
            {
                sx_video_sink_buf_set((struct sDECODER_HW_BUFFER *) curr->data);
                next = curr->next;
                free(curr);
                curr = next;
            } while (curr != ((void *)0));
            free(desc->data);
            free(desc);
            desc = ((void *)0);
        }
        next_iter:
        usleep(1*1000);
    }
}

variable_types:
arg
void *

variable_types: struct sSX_DESC { unsigned char *data; unsigned int data_len; struct sSX_DESC *next; } *

variable_types: struct sSLICE_HDR { unsigned char type; unsigned char rsvd[3]; unsigned long long timestamp; } *

variable_types:
present
unsigned char

return_type: void

user_defined_types: struct sDECODER_HW_BUFFER { unsigned int reserve1; unsigned int reserved2; unsigned char *buffer; unsigned int reserved3; unsigned int buffer_len; unsigned int reserved4; unsigned int reserved5; unsigned int reserved6; unsigned int reserved7; unsigned int reserved8; unsigned int reserved9; unsigned int reserved10; unsigned int reserved11; unsigned int reserved12; unsigned int reserved13; unsigned int reserved14; unsigned int reserved15; }


decompiled_code:
__int64 __fastcall video_scheduler_slice_dump(__int64 a1)
{
__int64 v1; // r15
unsigned int v2; // er14
__int64 *v3; // rcx
unsigned int v4; // er9
__int64 v5; // r10
unsigned int v6; // er12
int v7; // ebx
unsigned __int8 *v8; // r13
int v9; // esi
size_t v10; // rdx
__int64 v11; // rdi
unsigned __int8 *v12; // rsi
__int64 *v14; // rdi
__int64 v15; // rax
__int64 *v17; // [rsp+10h] [rbp-50h]
__int64 *v18; // [rsp+18h] [rbp-48h]
__int64 *v19; // [rsp+28h] [rbp-38h]

if ( !a1 )
_assert_fail("slice_head", "./src/sx_mgmt_video_scheduler.c", 0x42u, "video_scheduler_slice_dump");
v17 = (__int64 *)sx_desc_get();
v1 = sx_video_sink_buf_get();
if ( !v1 )
_assert_fail("hw_buf != NULL", "./src/sx_mgmt_video_scheduler.c", 0x4Cu, "video_scheduler_slice_dump");
v2 = 0;
v3 = *(__int64 **)(a1 + 16);
*v17 = v1;
v19 = v17;
v18 = v3;
do
{
v4 = *((_DWORD *)v18 + 2);
v5 = *v18;
if ( v4 <= 0xC )
_assert_fail(
"bytes_left > sizeof(sRTP_HDR)",
"./src/sx_mgmt_video_scheduler.c",
0x61u,
"video_scheduler_slice_dump");
v6 = v4 - 12;
v7 = v5 + 12;
if ( __ROR4__(1736263375 * (v4 - 12), 2) > 0x15C9882u )
_assert_fail(
"(bytes_left % sizeof(sMPEG2_TS)) == 0",
"./src/sx_mgmt_video_scheduler.c",
0x6Bu,
"video_scheduler_slice_dump");
v8 = (unsigned __int8 *)(v5 + 12);
do
{
while ( (v8[2] | (v8[1] << 8) & 0x1F00) != 4113 )
{
v8 += 188;
if ( v6 + v7 == (_DWORD)v8 )
goto LABEL_16;
}
v9 = ((int)v8[3] >> 4) & 2;
if ( v9 )
v9 = (unsigned __int8)(v8[4] + 1);
if ( (v8[1] & 0x40) != 0 )
v9 += 14;
v10 = (unsigned int)(184 - v9);
if ( v2 + (unsigned int)v10 > 0x14000 )
{
*(_DWORD *)(v1 + 20) = v2;
v14 = (__int64 *)sx_desc_get();
v19[2] = (__int64)v14;
v15 = sx_video_sink_buf_get();
v10 = (unsigned int)(184 - v9);
v1 = v15;
if ( !v15 )
_assert_fail("hw_buf != NULL", "./src/sx_mgmt_video_scheduler.c", 0x92u, "video_scheduler_slice_dump");
*v14 = v15;
v2 = 184 - v9;
v19 = v14;
v11 = 0LL;
}
else
{
v11 = v2;
v2 += v10;
}
v12 = &v8[v9 + 4];
v8 += 188;
memcpy((void *)(*(_QWORD *)(v1 + 8) + v11), v12, v10);
}
while ( v6 + v7 != (_DWORD)v8 );
LABEL_16:
v18 = (__int64 *)v18[2];
}
while ( v18 );
*(_DWORD *)(v1 + 20) = v2;
sx_desc_put(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a1 + 16) = v17;
return sx_pipe_put(3LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // r15
unsigned int v2; // er14
__int64 *v3; // rcx
unsigned int v4; // er9
__int64 v5; // r10
unsigned int v6; // er12
int v7; // ebx
unsigned __int8 *v8; // r13
int v9; // esi
size_t v10; // rdx
__int64 v11; // rdi
unsigned __int8 *v12; // rsi
__int64 *v14; // rdi
__int64 v15; // rax
__int64 *v17; // [rsp+10h] [rbp-50h]
__int64 *v18; // [rsp+18h] [rbp-48h]
__int64 *v19; // [rsp+28h] [rbp-38h]

if ( !a1 )
_assert_fail("slice_head", "./src/sx_mgmt_video_scheduler.c", 0x42u, "video_scheduler_slice_dump");
v17 = (__int64 *)sx_desc_get();
v1 = sx_video_sink_buf_get();
if ( !v1 )
_assert_fail("hw_buf != NULL", "./src/sx_mgmt_video_scheduler.c", 0x4Cu, "video_scheduler_slice_dump");
v2 = 0;
v3 = *(__int64 **)(a1 + 16);
*v17 = v1;
v19 = v17;
v18 = v3;
do
{
v4 = *((_DWORD *)v18 + 2);
v5 = *v18;
if ( v4 <= 0xC )
_assert_fail(
"bytes_left > sizeof(sRTP_HDR)",
"./src/sx_mgmt_video_scheduler.c",
0x61u,
"video_scheduler_slice_dump");
v6 = v4 - 12;
v7 = v5 + 12;
if ( __ROR4__(1736263375 * (v4 - 12), 2) > 0x15C9882u )
_assert_fail(
"(bytes_left % sizeof(sMPEG2_TS)) == 0",
"./src/sx_mgmt_video_scheduler.c",
0x6Bu,
"video_scheduler_slice_dump");
v8 = (unsigned __int8 *)(v5 + 12);
do
{
while ( (v8[2] | (v8[1] << 8) & 0x1F00) != 4113 )
{
v8 += 188;
if ( v6 + v7 == (_DWORD)v8 )
goto LABEL_16;
}
v9 = ((int)v8[3] >> 4) & 2;
if ( v9 )
v9 = (unsigned __int8)(v8[4] + 1);
if ( (v8[1] & 0x40) != 0 )
v9 += 14;
v10 = (unsigned int)(184 - v9);
if ( v2 + (unsigned int)v10 > 0x14000 )
{
*(_DWORD *)(v1 + 20) = v2;
v14 = (__int64 *)sx_desc_get();
v19[2] = (__int64)v14;
v15 = sx_video_sink_buf_get();
v10 = (unsigned int)(184 - v9);
v1 = v15;
if ( !v15 )
_assert_fail("hw_buf != NULL", "./src/sx_mgmt_video_scheduler.c", 0x92u, "video_scheduler_slice_dump");
*v14 = v15;
v2 = 184 - v9;
v19 = v14;
v11 = 0LL;
}
else
{
v11 = v2;
v2 += v10;
}
v12 = &v8[v9 + 4];
v8 += 188;
memcpy((void *)(*(_QWORD *)(v1 + 8) + v11), v12, v10);
}
while ( v6 + v7 != (_DWORD)v8 );
LABEL_16:
v18 = (__int64 *)v18[2];
}
while ( v18 );
*(_DWORD *)(v1 + 20) = v2;
sx_desc_put(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a1 + 16) = v17;
return sx_pipe_put(3LL, a1);
}

original_code:
static void video_scheduler_slice_dump(
    sSX_DESC *slice_head
    )
{
    unsigned char *curr_ptr;
    unsigned int bytes_left;
    unsigned int afc;
    unsigned int pes_byte_count;
    unsigned int payload_size;
    unsigned int start_offset;
    unsigned int copy_index;
    unsigned int pid;
    sSX_DESC *curr_desc;
    sSX_DESC *head_desc;
    ((void) sizeof ((slice_head) ? 1 : 0), __extension__ ({ if (slice_head) ; else __assert_fail ("slice_head", "./src/sx_mgmt_video_scheduler.c", 66, __extension__ __PRETTY_FUNCTION__); }));
    sSX_DESC *hw_desc = sx_desc_get();
    sSX_DESC *hw_desc_head = hw_desc;
    sDECODER_HW_BUFFER * hw_buf = sx_video_sink_buf_get();
    ((void) sizeof ((hw_buf != ((void *)0)) ? 1 : 0), __extension__ ({ if (hw_buf != ((void *)0)) ; else __assert_fail ("hw_buf != NULL", "./src/sx_mgmt_video_scheduler.c", 76, __extension__ __PRETTY_FUNCTION__); }));
    hw_desc->data = (unsigned char *) hw_buf;
    curr_desc = slice_head;
    copy_index = 0;
    do
    {
        curr_desc = curr_desc->next;
        curr_ptr = curr_desc->data;
        bytes_left = curr_desc->data_len;
        ((void) sizeof ((bytes_left > sizeof(sRTP_HDR)) ? 1 : 0), __extension__ ({ if (bytes_left > sizeof(sRTP_HDR)) ; else __assert_fail ("bytes_left > sizeof(sRTP_HDR)", "./src/sx_mgmt_video_scheduler.c", 97, __extension__ __PRETTY_FUNCTION__); }));
        curr_ptr += sizeof(sRTP_HDR);
        bytes_left -= sizeof(sRTP_HDR);
        ((void) sizeof (((bytes_left % sizeof(sMPEG2_TS)) == 0) ? 1 : 0), __extension__ ({ if ((bytes_left % sizeof(sMPEG2_TS)) == 0) ; else __assert_fail ("(bytes_left % sizeof(sMPEG2_TS)) == 0", "./src/sx_mgmt_video_scheduler.c", 107, __extension__ __PRETTY_FUNCTION__); }));
        pes_byte_count = 0;
        do
        {
            sMPEG2_TS *ts = (sMPEG2_TS *) curr_ptr;
            afc = (((ts->hdr).tsc_afc_cc & 0x30) >> 4);
            pid = ((((ts->hdr).tei_pusi_tp_pid1 & 0x1F) << 8) | (ts->hdr).pid2);
            if(pid == 0x1011)
            {
                unsigned char stuffing = 0;
                if(afc & 0x02)
                {
                    stuffing = 1 + ts->payload.payload[0];
                }
                start_offset = stuffing;
                if((((ts->hdr).tei_pusi_tp_pid1 & 0x40) >> 6))
                {
                     start_offset += 14;
                }
                payload_size = sizeof(sMPEG2_TS_PAYLOAD) - start_offset;
                if((copy_index + payload_size) > 81920)
                {
                    hw_buf->buffer_len = copy_index;
                    hw_desc->next = sx_desc_get();
                    hw_desc = hw_desc->next;
                    hw_buf = sx_video_sink_buf_get();
                    ((void) sizeof ((hw_buf != ((void *)0)) ? 1 : 0), __extension__ ({ if (hw_buf != ((void *)0)) ; else __assert_fail ("hw_buf != NULL", "./src/sx_mgmt_video_scheduler.c", 146, __extension__ __PRETTY_FUNCTION__); }));
                    hw_desc->data = (unsigned char *) hw_buf;
                    copy_index = 0;
                }
                memcpy(&hw_buf->buffer[copy_index],
                        &ts->payload.payload[start_offset],
                        payload_size);
                copy_index += payload_size;
            }
            curr_ptr += sizeof(sMPEG2_TS);
            bytes_left -= sizeof(sMPEG2_TS);
        } while (bytes_left > 0);
    } while (curr_desc->next != ((void *)0));
    hw_buf->buffer_len = copy_index;
    sx_desc_put(slice_head->next);
    slice_head->next = hw_desc_head;
    sx_pipe_put(3, slice_head);
}

canonical_original_code:
static void video_scheduler_slice_dump(struct sSX_DESC *slice_head)
{
    unsigned char *curr_ptr;
    unsigned int bytes_left;
    unsigned int afc;
    unsigned int pes_byte_count;
    unsigned int payload_size;
    unsigned int start_offset;
    unsigned int copy_index;
    unsigned int pid;
    struct sSX_DESC *curr_desc;
    struct sSX_DESC *head_desc;
    ((void) sizeof ((slice_head) ? 1 : 0), __extension__ ({ if (slice_head) ; else __assert_fail ("slice_head", "./src/sx_mgmt_video_scheduler.c", 66, __extension__ __PRETTY_FUNCTION__); }));
    struct sSX_DESC *hw_desc = sx_desc_get();
    struct sSX_DESC *hw_desc_head = hw_desc;
    struct sDECODER_HW_BUFFER *hw_buf = sx_video_sink_buf_get();
    ((void) sizeof ((hw_buf != ((void *)0)) ? 1 : 0), __extension__ ({ if (hw_buf != ((void *)0)) ; else __assert_fail ("hw_buf != NULL", "./src/sx_mgmt_video_scheduler.c", 76, __extension__ __PRETTY_FUNCTION__); }));
    hw_desc->data = (unsigned char *) hw_buf;
    curr_desc = slice_head;
    copy_index = 0;
    do
    {
        curr_desc = curr_desc->next;
        curr_ptr = curr_desc->data;
        bytes_left = curr_desc->data_len;
        ((void) sizeof ((bytes_left > sizeof(sRTP_HDR)) ? 1 : 0), __extension__ ({ if (bytes_left > sizeof(sRTP_HDR)) ; else __assert_fail ("bytes_left > sizeof(sRTP_HDR)", "./src/sx_mgmt_video_scheduler.c", 97, __extension__ __PRETTY_FUNCTION__); }));
        curr_ptr += sizeof(sRTP_HDR);
        bytes_left -= sizeof(sRTP_HDR);
        ((void) sizeof (((bytes_left % sizeof(sMPEG2_TS)) == 0) ? 1 : 0), __extension__ ({ if ((bytes_left % sizeof(sMPEG2_TS)) == 0) ; else __assert_fail ("(bytes_left % sizeof(sMPEG2_TS)) == 0", "./src/sx_mgmt_video_scheduler.c", 107, __extension__ __PRETTY_FUNCTION__); }));
        pes_byte_count = 0;
        do
        {
            struct sMPEG2_TS *ts = (sMPEG2_TS *) curr_ptr;
            afc = (((ts->hdr).tsc_afc_cc & 0x30) >> 4);
            pid = ((((ts->hdr).tei_pusi_tp_pid1 & 0x1F) << 8) | (ts->hdr).pid2);
            if(pid == 0x1011)
            {
                unsigned char stuffing = 0;
                if(afc & 0x02)
                {
                    stuffing = 1 + ts->payload.payload[0];
                }
                start_offset = stuffing;
                if((((ts->hdr).tei_pusi_tp_pid1 & 0x40) >> 6))
                {
                     start_offset += 14;
                }
                payload_size = sizeof(sMPEG2_TS_PAYLOAD) - start_offset;
                if((copy_index + payload_size) > 81920)
                {
                    hw_buf->buffer_len = copy_index;
                    hw_desc->next = sx_desc_get();
                    hw_desc = hw_desc->next;
                    hw_buf = sx_video_sink_buf_get();
                    ((void) sizeof ((hw_buf != ((void *)0)) ? 1 : 0), __extension__ ({ if (hw_buf != ((void *)0)) ; else __assert_fail ("hw_buf != NULL", "./src/sx_mgmt_video_scheduler.c", 146, __extension__ __PRETTY_FUNCTION__); }));
                    hw_desc->data = (unsigned char *) hw_buf;
                    copy_index = 0;
                }
                memcpy(&hw_buf->buffer[copy_index],
                        &ts->payload.payload[start_offset],
                        payload_size);
                copy_index += payload_size;
            }
            curr_ptr += sizeof(sMPEG2_TS);
            bytes_left -= sizeof(sMPEG2_TS);
        } while (bytes_left > 0);
    } while (curr_desc->next != ((void *)0));
    hw_buf->buffer_len = copy_index;
    sx_desc_put(slice_head->next);
    slice_head->next = hw_desc_head;
    sx_pipe_put(3, slice_head);
}

variable_types:
afc
unsigned int

variable_types:
pid
unsigned int

variable_types: struct sDECODER_HW_BUFFER { unsigned int reserve1; unsigned int reserved2; unsigned char *buffer; unsigned int reserved3; unsigned int buffer_len; unsigned int reserved4; unsigned int reserved5; unsigned int reserved6; unsigned int reserved7; unsigned int reserved8; unsigned int reserved9; unsigned int reserved10; unsigned int reserved11; unsigned int reserved12; unsigned int reserved13; unsigned int reserved14; unsigned int reserved15; } *

variable_types: struct sMPEG2_TS { struct sMPEG2_TS_HDR { unsigned char sync_byte; unsigned char tei_pusi_tp_pid1; unsigned char pid2; unsigned char tsc_afc_cc; } hdr; struct sMPEG2_TS_PAYLOAD { unsigned char payload[184]; } payload; } *

variable_types:
stuffing
unsigned char

user_defined_types: struct sSX_DESC { unsigned char *data; unsigned int data_len; struct sSX_DESC *next; }

user_defined_types: struct sMPEG2_TS { struct sMPEG2_TS_HDR hdr; struct sMPEG2_TS_PAYLOAD payload; }


decompiled_code:
void __noreturn slice_packing_thread()
{
unsigned int v0; // eax
unsigned int v1; // ebx
__int64 v2; // rdi

while ( 1 )
{
v0 = sx_pipe_len_get(3LL);
if ( v0 <= 9 )
{
v1 = 10 - v0;
do
{
v2 = sx_pipe_get(2LL);
if ( !v2 )
break;
video_scheduler_slice_dump(v2);
--v1;
}
while ( v1 );
}
usleep(0x7D0u);
}
}

canonical_decompiled_code:
void __noreturn func3()
{
unsigned int v0; // eax
unsigned int v1; // ebx
__int64 v2; // rdi

while ( 1 )
{
v0 = sx_pipe_len_get(3LL);
if ( v0 <= 9 )
{
v1 = 10 - v0;
do
{
v2 = sx_pipe_get(2LL);
if ( !v2 )
break;
func2(v2);
--v1;
}
while ( v1 );
}
usleep(0x7D0u);
}
}

original_code:
void slice_packing_thread(
    void * arg
    )
{
    sSX_DESC *desc;
    desc = ((void *)0);
    while(1)
    {
        unsigned int len = sx_pipe_len_get(3);
        if(len >= 10)
        {
            goto next_iter;
        }
        unsigned int slices_to_dump = 10 - len;
        do
        {
            desc = sx_pipe_get(2);
            if(desc == ((void *)0))
            {
                goto next_iter;
            }
            video_scheduler_slice_dump(desc);
            slices_to_dump--;
        } while (slices_to_dump > 0);
        next_iter:
        usleep(2*1000);
    }
}

canonical_original_code:
void slice_packing_thread(void *arg)
{
    struct sSX_DESC *desc;
    desc = ((void *)0);
    while(1)
    {
        unsigned int len = sx_pipe_len_get(3);
        if(len >= 10)
        {
            goto next_iter;
        }
        unsigned int slices_to_dump = 10 - len;
        do
        {
            desc = sx_pipe_get(2);
            if(desc == ((void *)0))
            {
                goto next_iter;
            }
            video_scheduler_slice_dump(desc);
            slices_to_dump--;
        } while (slices_to_dump > 0);
        next_iter:
        usleep(2*1000);
    }
}

variable_types:
len
unsigned int


decompiled_code:
__time_t sink_time_get()
{
struct timeval tv; // [rsp+0h] [rbp-10h] BYREF

gettimeofday(&tv, 0LL);
return 1000 * tv.tv_sec + tv.tv_usec / 1000;
}

canonical_decompiled_code:
__time_t func4()
{
struct timeval tv; // [rsp+0h] [rbp-10h] BYREF

gettimeofday(&tv, 0LL);
return 1000 * tv.tv_sec + tv.tv_usec / 1000;
}

original_code:
static unsigned long long sink_time_get(
    void
    )
{
    struct timeval curr_time;
    gettimeofday(&curr_time, ((void *)0));
    unsigned long long temp = curr_time.tv_sec * 1000 + curr_time.tv_usec / 1000;
    return temp;
}

canonical_original_code:
static unsigned long long sink_time_get()
{
    struct timeval curr_time;
    gettimeofday(&curr_time, ((void *)0));
    unsigned long long temp = curr_time.tv_sec * 1000 + curr_time.tv_usec / 1000;
    return temp;
}

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

variable_types:
temp
unsigned long long


decompiled_code:
void __fastcall __noreturn pcr_update_thread()
{
__time_t v0; // rbx
__int64 v1; // r12
__int64 v2; // rax
__time_t v3; // r13

while ( 1 )
{
v2 = sx_pipe_get(4LL);
if ( v2 )
{
v1 = *(_QWORD *)(*(_QWORD *)v2 + 8LL);
sx_desc_put(v2);
v0 = sink_time_get();
}
v3 = sink_time_get();
pthread_mutex_lock(&mutex);
qword_758 = v1 + v3 - 500 - v0;
pthread_mutex_unlock(&mutex);
usleep(0x7D0u);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func5()
{
__time_t v0; // rbx
__int64 v1; // r12
__int64 v2; // rax
__time_t v3; // r13

while ( 1 )
{
v2 = sx_pipe_get(4LL);
if ( v2 )
{
v1 = *(_QWORD *)(*(_QWORD *)v2 + 8LL);
sx_desc_put(v2);
v0 = func4();
}
v3 = func4();
pthread_mutex_lock(&mutex);
qword_758 = v1 + v3 - 500 - v0;
pthread_mutex_unlock(&mutex);
usleep(0x7D0u);
}
}

original_code:
void pcr_update_thread(
    void * arg
    )
{
    sSX_DESC *desc;
    unsigned long long pcr_time;
    unsigned long long pcr_received_time;
    unsigned long long curr_time;
    while(1)
    {
        desc = sx_pipe_get(4);
        if(desc == ((void *)0))
        {
            goto cleanup;
        }
        sSLICE_HDR *hdr = (sSLICE_HDR *) desc->data;
        pcr_time = hdr->timestamp;
        sx_desc_put(desc);
        pcr_received_time = sink_time_get();
        cleanup:
        curr_time = sink_time_get();
        pthread_mutex_lock(&f_cblk.lock);
        f_cblk.curr_time = pcr_time + (curr_time - pcr_received_time) - (400) - (100);
        pthread_mutex_unlock(&f_cblk.lock);
        usleep(2*1000);
    }
}

canonical_original_code:
void pcr_update_thread(void *arg)
{
    struct sSX_DESC *desc;
    unsigned long long pcr_time;
    unsigned long long pcr_received_time;
    unsigned long long curr_time;
    while(1)
    {
        desc = sx_pipe_get(4);
        if(desc == ((void *)0))
        {
            goto cleanup;
        }
        struct sSLICE_HDR *hdr = (sSLICE_HDR *) desc->data;
        pcr_time = hdr->timestamp;
        sx_desc_put(desc);
        pcr_received_time = sink_time_get();
        cleanup:
        curr_time = sink_time_get();
        pthread_mutex_lock(&f_cblk.lock);
        f_cblk.curr_time = pcr_time + (curr_time - pcr_received_time) - (400) - (100);
        pthread_mutex_unlock(&f_cblk.lock);
        usleep(2*1000);
    }
}

user_defined_types: struct sSLICE_HDR { unsigned char type; unsigned char rsvd[3]; unsigned long long timestamp; }


decompiled_code:
__int64 video_scheduler_thread_create()
{
sx_thread_create(&f_cblk, video_scheduler_thread, 0LL, 70LL);
sx_thread_create(&unk_748, slice_packing_thread, 0LL, 70LL);
return sx_thread_create(&unk_750, pcr_update_thread, 0LL, 70LL);
}

canonical_decompiled_code:
__int64 func7()
{
sx_thread_create(&f_cblk, video_scheduler_thread, 0LL, 70LL);
sx_thread_create(&unk_748, slice_packing_thread, 0LL, 70LL);
return sx_thread_create(&unk_750, pcr_update_thread, 0LL, 70LL);
}

original_code:
static void video_scheduler_thread_create(
    void
    )
{
    sx_thread_create(&f_cblk.video_scheduler_thread,
                     &video_scheduler_thread,
                     ((void *)0),
                     70);
    sx_thread_create(&f_cblk.slice_packing_thread,
                     &slice_packing_thread,
                     ((void *)0),
                     70);
    sx_thread_create(&f_cblk.pcr_update_thread,
                     &pcr_update_thread,
                     ((void *)0),
                     70);
}

canonical_original_code:
static void video_scheduler_thread_create()
{
    sx_thread_create(&f_cblk.video_scheduler_thread,
                     &video_scheduler_thread,
                     ((void *)0),
                     70);
    sx_thread_create(&f_cblk.slice_packing_thread,
                     &slice_packing_thread,
                     ((void *)0),
                     70);
    sx_thread_create(&f_cblk.pcr_update_thread,
                     &pcr_update_thread,
                     ((void *)0),
                     70);
}


decompiled_code:
int sx_mgmt_video_scheduler_init()
{
return resources_init();
}

canonical_decompiled_code:
int func8()
{
return func6();
}

original_code:
void sx_mgmt_video_scheduler_init(
    void
    )
{
    resources_init();
}

canonical_original_code:
void sx_mgmt_video_scheduler_init()
{
    resources_init();
}


decompiled_code:
__int64 sx_mgmt_video_scheduler_open()
{
return video_scheduler_thread_create();
}

canonical_decompiled_code:
__int64 func9()
{
return func7();
}

original_code:
void sx_mgmt_video_scheduler_open(
    void
    )
{
    video_scheduler_thread_create();
}

canonical_original_code:
void sx_mgmt_video_scheduler_open()
{
    video_scheduler_thread_create();
}


decompiled_code:
void sx_mgmt_video_scheduler_close()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void sx_mgmt_video_scheduler_close(
    void
    )
{
}

canonical_original_code:
void sx_mgmt_video_scheduler_close()
{
}


decompiled_code:
int resources_init()
{
sx_video_sink_init();
return pthread_mutex_init(&mutex, 0LL);
}

canonical_decompiled_code:
int func6()
{
sx_video_sink_init();
return pthread_mutex_init(&mutex, 0LL);
}

original_code:
static void resources_init(
    void
    )
{
    sx_video_sink_init();
    pthread_mutex_init(&f_cblk.lock, ((void *)0));
}

canonical_original_code:
static void resources_init()
{
    sx_video_sink_init();
    pthread_mutex_init(&f_cblk.lock, ((void *)0));
}


decompiled_code:
__int64 sx_pipe_init()
{
__int64 *v0; // rbx
__int64 result; // rax

v0 = &f_cblk;
do
{
result = sx_queue_create();
*v0++ = result;
}
while ( v0 != (__int64 *)&unk_D8 );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 *v0; // rbx
__int64 result; // rax

v0 = &f_cblk;
do
{
result = sx_queue_create();
*v0++ = result;
}
while ( v0 != (__int64 *)&unk_D8 );
return result;
}

original_code:
void sx_pipe_init(
    void
    )
{
    unsigned int i;
    for(i = 0; i < 7; i++)
    {
        f_cblk.queue[i] = sx_queue_create();
    }
}

canonical_original_code:
void sx_pipe_init()
{
    unsigned int i;
    for(i = 0; i < 7; i++)
    {
        f_cblk.queue[i] = sx_queue_create();
    }
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall sx_pipe_put(int a1)
{
return sx_queue_push(f_cblk[a1]);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return sx_queue_push(f_cblk[a1]);
}

original_code:
void sx_pipe_put(
    unsigned int index,
    void *data
    )
{
    sx_queue_push(f_cblk.queue[index], data);
}

canonical_original_code:
void sx_pipe_put(unsigned int index, void *data)
{
    sx_queue_push(f_cblk.queue[index], data);
}

variable_types:
index
unsigned int

variable_types:
data
void *


decompiled_code:
__int64 __fastcall sx_pipe_get(int a1)
{
return sx_queue_pull(f_cblk[a1]);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return sx_queue_pull(f_cblk[a1]);
}

original_code:
void * sx_pipe_get(
    unsigned int index
    )
{
    return sx_queue_pull(f_cblk.queue[index]);
}

canonical_original_code:
void *sx_pipe_get(unsigned int index)
{
    return sx_queue_pull(f_cblk.queue[index]);
}

return_type: void *


decompiled_code:
__int64 __fastcall sx_pipe_len_get(int a1)
{
return sx_queue_len_get(f_cblk[a1]);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return sx_queue_len_get(f_cblk[a1]);
}

original_code:
unsigned int sx_pipe_len_get(
    unsigned int index
    )
{
    return sx_queue_len_get(f_cblk.queue[index]);
}

canonical_original_code:
unsigned int sx_pipe_len_get(unsigned int index)
{
    return sx_queue_len_get(f_cblk.queue[index]);
}

return_type: unsigned int


decompiled_code:
void sx_mgmt_env_open()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void sx_mgmt_env_open(
    void
    )
{
}

canonical_original_code:
void sx_mgmt_env_open()
{
}


decompiled_code:
__int64 __fastcall sx_mgmt_env_get(int a1)
{
printf("(sx_mgmt_env_get(): var = %u\n", (unsigned int)f_env_vars[a1]);
return (unsigned int)f_env_vars[a1];
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
printf("(sx_mgmt_env_get(): var = %u\n", (unsigned int)f_env_vars[a1]);
return (unsigned int)f_env_vars[a1];
}

original_code:
unsigned int sx_mgmt_env_get(
    eMGMT_ENV_VAR var
    )
{
    printf("(sx_mgmt_env_get(): var = %u\n", f_env_vars[var]);
    return f_env_vars[var];
}

canonical_original_code:
unsigned int sx_mgmt_env_get(enum eMGMT_ENV_VAR var)
{
    printf("(sx_mgmt_env_get(): var = %u\n", f_env_vars[var]);
    return f_env_vars[var];
}

variable_types: enum eMGMT_ENV_VAR { MGMT_ENV_VAR_WIDTH=0, MGMT_ENV_VAR_HEIGHT=1, MGMT_ENV_VAR_SESSION_WIDTH=2, MGMT_ENV_VAR_SESSION_HEIGHT=3, MGMT_ENV_VAR_MAX=4 }


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

result = malloc(0x18uLL);
if ( !result )
_assert_fail("desc != NULL", "./src/sx_desc.c", 0xFu, "sx_desc_get");
*(_QWORD *)result = 0LL;
result[2] = 0;
*((_QWORD *)result + 2) = 0LL;
return result;
}

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

result = malloc(0x18uLL);
if ( !result )
_assert_fail("desc != NULL", "./src/sx_desc.c", 0xFu, "sx_desc_get");
*(_QWORD *)result = 0LL;
result[2] = 0;
*((_QWORD *)result + 2) = 0LL;
return result;
}

original_code:
sSX_DESC * sx_desc_get(
    void
    )
{
    sSX_DESC *desc = malloc(sizeof(sSX_DESC));
    ((void) sizeof ((desc != ((void *)0)) ? 1 : 0), __extension__ ({ if (desc != ((void *)0)) ; else __assert_fail ("desc != NULL", "./src/sx_desc.c", 15, __extension__ __PRETTY_FUNCTION__); }));
    desc->data = ((void *)0);
    desc->data_len = 0;
    desc->next = ((void *)0);
    return desc;
}

canonical_original_code:
struct sSX_DESC *sx_desc_get()
{
    struct sSX_DESC *desc = malloc(sizeof(sSX_DESC));
    ((void) sizeof ((desc != ((void *)0)) ? 1 : 0), __extension__ ({ if (desc != ((void *)0)) ; else __assert_fail ("desc != NULL", "./src/sx_desc.c", 15, __extension__ __PRETTY_FUNCTION__); }));
    desc->data = ((void *)0);
    desc->data_len = 0;
    desc->next = ((void *)0);
    return desc;
}

return_type: struct sSX_DESC { unsigned char *data; unsigned int data_len; struct sSX_DESC *next; } *


decompiled_code:
void __fastcall sx_desc_put(void *ptr)
{
void **v1; // rbx
void **v2; // r12

v1 = (void **)ptr;
if ( !ptr )
_assert_fail("desc != NULL", "./src/sx_desc.c", 0x26u, "sx_desc_put");
do
{
v2 = v1;
v1 = (void **)v1[2];
free(*v2);
free(v2);
}
while ( v1 );
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void **v1; // rbx
void **v2; // r12

v1 = (void **)ptr;
if ( !ptr )
_assert_fail("desc != NULL", "./src/sx_desc.c", 0x26u, "sx_desc_put");
do
{
v2 = v1;
v1 = (void **)v1[2];
free(*v2);
free(v2);
}
while ( v1 );
}

original_code:
void sx_desc_put(
     sSX_DESC *desc
     )
{
     sSX_DESC *curr;
     sSX_DESC *next;
     ((void) sizeof ((desc != ((void *)0)) ? 1 : 0), __extension__ ({ if (desc != ((void *)0)) ; else __assert_fail ("desc != NULL", "./src/sx_desc.c", 38, __extension__ __PRETTY_FUNCTION__); }));
     curr = desc;
     while(curr != ((void *)0))
     {
         next = curr->next;
         free(curr->data);
         free(curr);
         curr = next;
     }
}

canonical_original_code:
void sx_desc_put(struct sSX_DESC *desc)
{
     struct sSX_DESC *curr;
     struct sSX_DESC *next;
     ((void) sizeof ((desc != ((void *)0)) ? 1 : 0), __extension__ ({ if (desc != ((void *)0)) ; else __assert_fail ("desc != NULL", "./src/sx_desc.c", 38, __extension__ __PRETTY_FUNCTION__); }));
     curr = desc;
     while(curr != ((void *)0))
     {
         next = curr->next;
         free(curr->data);
         free(curr);
         curr = next;
     }
}


cacheCreate

decompiled_code:
__int64 __fastcall cacheCreate(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5, _QWORD *a6)
{
__int64 result; // rax

if ( (unsigned int)memAlloc(16LL, a6) == 1 )
{
if ( (unsigned int)createHashtable(a2, a3, a4, a5, *a6) == 1 )
{
if ( (unsigned int)createLimCache(a1, *a6 + 8LL) == 1 )
{
result = 1LL;
}
else
{
fflush(stderr);
result = createLimCache(a1, *a6 + 8LL);
}
}
else
{
fflush(stderr);
result = createHashtable(a2, a3, a4, a5, *a6);
}
}
else
{
fflush(stderr);
result = memAlloc(16LL, a6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5, _QWORD *a6)
{
__int64 result; // rax

if ( (unsigned int)memAlloc(16LL, a6) == 1 )
{
if ( (unsigned int)createHashtable(a2, a3, a4, a5, *a6) == 1 )
{
if ( (unsigned int)createLimCache(a1, *a6 + 8LL) == 1 )
{
result = 1LL;
}
else
{
fflush(stderr);
result = createLimCache(a1, *a6 + 8LL);
}
}
else
{
fflush(stderr);
result = createHashtable(a2, a3, a4, a5, *a6);
}
}
else
{
fflush(stderr);
result = memAlloc(16LL, a6);
}
return result;
}

original_code:
errorCode cacheCreate(int sizeCache, int HTnumberEntries, keyCompareFunction HTcompare, deallocKeyFunction HTdeallocK, deallocDataFunction HTdeallocD, cache ** c){
  if(memAlloc(sizeof(cache), (void **)c) != 1){ fflush(stderr); return memAlloc(sizeof(cache), (void **)c); };
  if(createHashtable(HTnumberEntries, HTcompare, HTdeallocK, HTdeallocD, (&((*c) -> ht))) != 1){ fflush(stderr); return createHashtable(HTnumberEntries, HTcompare, HTdeallocK, HTdeallocD, (&((*c) -> ht))); };
  if(createLimCache(sizeCache, (&((*c) -> lsc))) != 1){ fflush(stderr); return createLimCache(sizeCache, (&((*c) -> lsc))); };
  return 1;
}

canonical_original_code:
int cacheCreate(int sizeCache, int HTnumberEntries, int (*HTcompare)(void *, void *, int *), int (*HTdeallocK)(void *), int (*HTdeallocD)(void *), struct cache_tag **c){
  if(memAlloc(sizeof(cache), (void **)c) != 1){ fflush(stderr); return memAlloc(sizeof(cache), (void **)c); };
  if(createHashtable(HTnumberEntries, HTcompare, HTdeallocK, HTdeallocD, (&((*c) -> ht))) != 1){ fflush(stderr); return createHashtable(HTnumberEntries, HTcompare, HTdeallocK, HTdeallocD, (&((*c) -> ht))); };
  if(createLimCache(sizeCache, (&((*c) -> lsc))) != 1){ fflush(stderr); return createLimCache(sizeCache, (&((*c) -> lsc))); };
  return 1;
}

variable_types: sizeCache int

variable_types: HTnumberEntries int

variable_types:
HTcompare
int (*)(void *, void *, int *)

variable_types:
HTdeallocK
int (*)(void *)

variable_types:
HTdeallocD
int (*)(void *)

variable_types: struct cache_tag { struct hashtable_tag { int size; int nr_rows; int busy; int maxsize; struct hashtableEntry_tag { unsigned int key; unsigned int data; int busy; struct hashtableEntry_tag *next; } *cur_entry; int scan_active; int cur_row; struct hashtableEntry_tag *free_pool; int next_free; struct hashtableEntry_tag **table; } *ht; struct limSizeCache_tag { int size; int pinpointed; int usage; void *dataSpace; struct accnt_tag { int used; int counter; struct timeval { long tv_sec; long tv_usec; } tv; void *key; void *data; int evict; void *bh; } *accntArray; } *lsc; } **

return_type: int

user_defined_types: struct cache_tag { struct hashtable_tag *ht; struct limSizeCache_tag *lsc; }

user_defined_types: struct hashtable_tag { int size; int nr_rows; int busy; int maxsize; struct hashtableEntry_tag *cur_entry; int scan_active; int cur_row; struct hashtableEntry_tag *free_pool; int next_free; struct hashtableEntry_tag **table; }

user_defined_types: struct limSizeCache_tag { int size; int pinpointed; int usage; void *dataSpace; struct accnt_tag *accntArray; }

user_defined_types: struct accnt_tag { int used; int counter; struct timeval tv; void *key; void *data; int evict; void *bh; }


cachePinpoint

decompiled_code:
__int64 __fastcall cachePinpoint(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v3) == 1 )
{
result = pinpoint(a1[1], (unsigned int)v3[0]);
if ( (_DWORD)result != 1 )
{
fflush(stderr);
result = pinpoint(a1[1], (unsigned int)v3[0]);
}
}
else
{
fflush(stderr);
result = HTlookup(*a1, a2, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v3) == 1 )
{
result = pinpoint(a1[1], (unsigned int)v3[0]);
if ( (_DWORD)result != 1 )
{
fflush(stderr);
result = pinpoint(a1[1], (unsigned int)v3[0]);
}
}
else
{
fflush(stderr);
result = HTlookup(*a1, a2, v3);
}
return result;
}

original_code:
errorCode cachePinpoint(cache * c, void * key){
  int slot;
  if(HTlookup(c -> ht, (void*)key, (void **)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void*)key, (void **)&slot); };
  if(pinpoint(c -> lsc, slot) != 1){ fflush(stderr); return pinpoint(c -> lsc, slot); };
  return 1;
}

canonical_original_code:
int cachePinpoint(struct cache_tag *c, void *key){
  int slot;
  if(HTlookup(c -> ht, (void *)key, (void **)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void *)key, (void **)&slot); };
  if(pinpoint(c -> lsc, slot) != 1){ fflush(stderr); return pinpoint(c -> lsc, slot); };
  return 1;
}

variable_types: struct cache_tag { struct hashtable_tag { int size; int nr_rows; int busy; int maxsize; struct hashtableEntry_tag { unsigned int key; unsigned int data; int busy; struct hashtableEntry_tag *next; } *cur_entry; int scan_active; int cur_row; struct hashtableEntry_tag *free_pool; int next_free; struct hashtableEntry_tag **table; } *ht; struct limSizeCache_tag { int size; int pinpointed; int usage; void *dataSpace; struct accnt_tag { int used; int counter; struct timeval { long tv_sec; long tv_usec; } tv; void *key; void *data; int evict; void *bh; } *accntArray; } *lsc; } *

variable_types:
key
void *

variable_types: slot int


cacheLookupFailedInsert

decompiled_code:
__int64 __fastcall cacheLookupFailedInsert(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned int v5; // [rsp+4h] [rbp-24h] BYREF
char v6[32]; // [rsp+8h] [rbp-20h] BYREF

if ( (unsigned int)findEmptySlot(a1[1], &v5) == 1
|| (findEvictionCandidate(a1[1], &v5),
(unsigned int)HTextract(*a1, *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * (int)v5 + 24), v6) == 1) )
{
result = HTinsert(*a1, a2, (int)v5);
if ( (_DWORD)result == 1 )
{
if ( (unsigned int)insertNewElementNoDataCopy(a1[1], v5, a2, a3) == 1 )
{
result = 1LL;
}
else
{
fflush(stderr);
result = insertNewElementNoDataCopy(a1[1], v5, a2, a3);
}
}
}
else
{
fflush(stderr);
result = HTextract(*a1, *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * (int)v5 + 24), v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned int v5; // [rsp+4h] [rbp-24h] BYREF
char v6[32]; // [rsp+8h] [rbp-20h] BYREF

if ( (unsigned int)findEmptySlot(a1[1], &v5) == 1
|| (findEvictionCandidate(a1[1], &v5),
(unsigned int)HTextract(*a1, *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * (int)v5 + 24), v6) == 1) )
{
result = HTinsert(*a1, a2, (int)v5);
if ( (_DWORD)result == 1 )
{
if ( (unsigned int)insertNewElementNoDataCopy(a1[1], v5, a2, a3) == 1 )
{
result = 1LL;
}
else
{
fflush(stderr);
result = insertNewElementNoDataCopy(a1[1], v5, a2, a3);
}
}
}
else
{
fflush(stderr);
result = HTextract(*a1, *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * (int)v5 + 24), v6);
}
return result;
}

original_code:
errorCode cacheLookupFailedInsert(cache * c, void * key, void ** data){
  int res;
  int slot;
  void * extractedData;
  if (findEmptySlot(c -> lsc, &slot) == 1){
    if ((res = HTinsert(c -> ht, (void *)key, (void *)slot)) != 1)
      return res;
    if(insertNewElementNoDataCopy(c -> lsc, slot, key, data) != 1){ fflush(stderr); return insertNewElementNoDataCopy(c -> lsc, slot, key, data); };
  }
  else {
    findEvictionCandidate(c -> lsc, &slot);
    if(HTextract(c -> ht, (((c -> lsc -> accntArray) + slot) -> key ), &extractedData) != 1){ fflush(stderr); return HTextract(c -> ht, (((c -> lsc -> accntArray) + slot) -> key ), &extractedData); };
    if ((res = HTinsert(c -> ht, (void*)key, (void*)slot)) != 1)
      return res;
    if(insertNewElementNoDataCopy(c -> lsc, slot, key, data) != 1){ fflush(stderr); return insertNewElementNoDataCopy(c -> lsc, slot, key, data); };
  }
  return 1;
}

canonical_original_code:
int cacheLookupFailedInsert(struct cache_tag *c, void *key, void **data){
  int res;
  int slot;
  void *extractedData;
  if (findEmptySlot(c -> lsc, &slot) == 1){
    if ((res = HTinsert(c -> ht, (void *)key, (void *)slot)) != 1)
      return res;
    if(insertNewElementNoDataCopy(c -> lsc, slot, key, data) != 1){ fflush(stderr); return insertNewElementNoDataCopy(c -> lsc, slot, key, data); };
  }
  else {
    findEvictionCandidate(c -> lsc, &slot);
    if(HTextract(c -> ht, (((c -> lsc -> accntArray) + slot) -> key ), &extractedData) != 1){ fflush(stderr); return HTextract(c -> ht, (((c -> lsc -> accntArray) + slot) -> key ), &extractedData); };
    if ((res = HTinsert(c -> ht, (void *)key, (void *)slot)) != 1)
      return res;
    if(insertNewElementNoDataCopy(c -> lsc, slot, key, data) != 1){ fflush(stderr); return insertNewElementNoDataCopy(c -> lsc, slot, key, data); };
  }
  return 1;
}

variable_types:
data
void **

variable_types: res int

variable_types:
extractedData
void *

user_defined_types: struct hashtableEntry_tag { unsigned int key; unsigned int data; int busy; struct hashtableEntry_tag *next; }

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


cacheLookupFailedInsertSlot

decompiled_code:
__int64 __fastcall cacheLookupFailedInsertSlot(_QWORD *a1, __int64 a2, __int64 a3, unsigned int *a4)
{
__int64 result; // rax
unsigned int v7; // [rsp+4h] [rbp-34h] BYREF
char v8[48]; // [rsp+8h] [rbp-30h] BYREF

if ( (unsigned int)findEmptySlot(a1[1], &v7) == 1
|| (findEvictionCandidate(a1[1], &v7),
(unsigned int)HTextract(*a1, *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * (int)v7 + 24), v8) == 1) )
{
result = HTinsert(*a1, a2, (int)v7);
if ( (_DWORD)result == 1 )
{
if ( (unsigned int)insertNewElementNoDataCopy(a1[1], v7, a2, a3) == 1 )
{
*a4 = v7;
result = 1LL;
}
else
{
fflush(stderr);
result = insertNewElementNoDataCopy(a1[1], v7, a2, a3);
}
}
}
else
{
fflush(stderr);
result = HTextract(*a1, *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * (int)v7 + 24), v8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2, __int64 a3, unsigned int *a4)
{
__int64 result; // rax
unsigned int v7; // [rsp+4h] [rbp-34h] BYREF
char v8[48]; // [rsp+8h] [rbp-30h] BYREF

if ( (unsigned int)findEmptySlot(a1[1], &v7) == 1
|| (findEvictionCandidate(a1[1], &v7),
(unsigned int)HTextract(*a1, *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * (int)v7 + 24), v8) == 1) )
{
result = HTinsert(*a1, a2, (int)v7);
if ( (_DWORD)result == 1 )
{
if ( (unsigned int)insertNewElementNoDataCopy(a1[1], v7, a2, a3) == 1 )
{
*a4 = v7;
result = 1LL;
}
else
{
fflush(stderr);
result = insertNewElementNoDataCopy(a1[1], v7, a2, a3);
}
}
}
else
{
fflush(stderr);
result = HTextract(*a1, *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * (int)v7 + 24), v8);
}
return result;
}

original_code:
errorCode cacheLookupFailedInsertSlot(cache * c, void * key, void ** data, int * resSlot){
  int res;
  int slot;
  void * extractedData;
  if (findEmptySlot(c -> lsc, &slot) == 1){
    if ((res = HTinsert(c -> ht, (void*)key, (void*)slot)) != 1)
      return res;
    if(insertNewElementNoDataCopy(c -> lsc, slot, key, data) != 1){ fflush(stderr); return insertNewElementNoDataCopy(c -> lsc, slot, key, data); };
  }
  else {
    findEvictionCandidate(c -> lsc, &slot);
    if(HTextract(c -> ht, (void*)((((c -> lsc -> accntArray) + slot) -> key )), (void**)&extractedData) != 1){ fflush(stderr); return HTextract(c -> ht, (void*)((((c -> lsc -> accntArray) + slot) -> key )), (void**)&extractedData); };
    if ((res = HTinsert(c -> ht, (void*)key, (void*)slot)) != 1)
      return res;
    if(insertNewElementNoDataCopy(c -> lsc, slot, key, data) != 1){ fflush(stderr); return insertNewElementNoDataCopy(c -> lsc, slot, key, data); };
  }
  *resSlot = slot;
  return 1;
}

canonical_original_code:
int cacheLookupFailedInsertSlot(struct cache_tag *c, void *key, void **data, int *resSlot){
  int res;
  int slot;
  void *extractedData;
  if (findEmptySlot(c -> lsc, &slot) == 1){
    if ((res = HTinsert(c -> ht, (void *)key, (void *)slot)) != 1)
      return res;
    if(insertNewElementNoDataCopy(c -> lsc, slot, key, data) != 1){ fflush(stderr); return insertNewElementNoDataCopy(c -> lsc, slot, key, data); };
  }
  else {
    findEvictionCandidate(c -> lsc, &slot);
    if(HTextract(c -> ht, (void *)((((c -> lsc -> accntArray) + slot) -> key )), (void **)&extractedData) != 1){ fflush(stderr); return HTextract(c -> ht, (void *)((((c -> lsc -> accntArray) + slot) -> key )), (void **)&extractedData); };
    if ((res = HTinsert(c -> ht, (void *)key, (void *)slot)) != 1)
      return res;
    if(insertNewElementNoDataCopy(c -> lsc, slot, key, data) != 1){ fflush(stderr); return insertNewElementNoDataCopy(c -> lsc, slot, key, data); };
  }
  *resSlot = slot;
  return 1;
}

variable_types:
resSlot
int *


cacheAllPinpointed

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

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

original_code:
errorCode cacheAllPinpointed(cache * c){
  return allPinpointed(c -> lsc);
}

canonical_original_code:
int cacheAllPinpointed(struct cache_tag *c){
  return allPinpointed(c -> lsc);
}


cacheUnPinpoint

decompiled_code:
__int64 __fastcall cacheUnPinpoint(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v3) == 1 )
{
result = unPinpoint(a1[1], (unsigned int)v3[0]);
if ( (_DWORD)result != 1 )
{
fflush(stderr);
result = unPinpoint(a1[1], (unsigned int)v3[0]);
}
}
else
{
fflush(stderr);
result = HTlookup(*a1, a2, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v3) == 1 )
{
result = unPinpoint(a1[1], (unsigned int)v3[0]);
if ( (_DWORD)result != 1 )
{
fflush(stderr);
result = unPinpoint(a1[1], (unsigned int)v3[0]);
}
}
else
{
fflush(stderr);
result = HTlookup(*a1, a2, v3);
}
return result;
}

original_code:
errorCode cacheUnPinpoint(cache * c, void * key){
  int slot;
  if(HTlookup(c -> ht, (void*)key, (void**)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void*)key, (void**)&slot); };
  if(unPinpoint(c -> lsc, slot) != 1){ fflush(stderr); return unPinpoint(c -> lsc, slot); };
  return 1;
}

canonical_original_code:
int cacheUnPinpoint(struct cache_tag *c, void *key){
  int slot;
  if(HTlookup(c -> ht, (void *)key, (void **)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void *)key, (void **)&slot); };
  if(unPinpoint(c -> lsc, slot) != 1){ fflush(stderr); return unPinpoint(c -> lsc, slot); };
  return 1;
}


cacheInsert

decompiled_code:
__int64 __fastcall cacheInsert(_QWORD *a1, __int64 a2, __int64 a3)
{
int v5; // eax
int v7; // eax
__int64 v8; // rdi
__int64 v9; // rcx
__int64 v10; // rdx
unsigned int v11; // [rsp+0h] [rbp-28h] BYREF
unsigned int v12; // [rsp+4h] [rbp-24h] BYREF
char v13[32]; // [rsp+8h] [rbp-20h] BYREF

if ( (unsigned int)findEmptySlot(a1[1], &v11) != 1 )
{
findEvictionCandidate(a1[1], &v11);
v5 = HTupdate(*a1, a2, (int)v11, &v12);
if ( v5 != -1 )
{
if ( v5 != 1 )
{
if ( v5 != -2 )
return 1LL;
v8 = a1[1];
v9 = a3;
v10 = a2;
goto LABEL_8;
}
if ( (unsigned int)HTextract(*a1, *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * (int)v11 + 24), v13) != 1 )
{
fflush(stderr);
return HTextract(*a1, *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * (int)v11 + 24), v13);
}
v8 = a1[1];
v9 = a3;
v10 = a2;
LABEL_12:
if ( (unsigned int)insertNewElement(v8, v11, v10, v9) == 1 )
return 1LL;
fflush(stderr);
return insertNewElement(a1[1], v11, a2, a3);
}
return 0xFFFFFFFFLL;
}
v7 = HTupdate(*a1, a2, (int)v11, &v12);
if ( v7 == -1 )
return 0xFFFFFFFFLL;
v8 = a1[1];
v9 = a3;
v10 = a2;
if ( v7 == 1 )
goto LABEL_12;
LABEL_8:
if ( (unsigned int)insertNewElement(v8, v12, v10, v9) == 1 )
return 1LL;
fflush(stderr);
return insertNewElement(a1[1], v12, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2, __int64 a3)
{
int v5; // eax
int v7; // eax
__int64 v8; // rdi
__int64 v9; // rcx
__int64 v10; // rdx
unsigned int v11; // [rsp+0h] [rbp-28h] BYREF
unsigned int v12; // [rsp+4h] [rbp-24h] BYREF
char v13[32]; // [rsp+8h] [rbp-20h] BYREF

if ( (unsigned int)findEmptySlot(a1[1], &v11) != 1 )
{
findEvictionCandidate(a1[1], &v11);
v5 = HTupdate(*a1, a2, (int)v11, &v12);
if ( v5 != -1 )
{
if ( v5 != 1 )
{
if ( v5 != -2 )
return 1LL;
v8 = a1[1];
v9 = a3;
v10 = a2;
goto LABEL_8;
}
if ( (unsigned int)HTextract(*a1, *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * (int)v11 + 24), v13) != 1 )
{
fflush(stderr);
return HTextract(*a1, *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * (int)v11 + 24), v13);
}
v8 = a1[1];
v9 = a3;
v10 = a2;
LABEL_12:
if ( (unsigned int)insertNewElement(v8, v11, v10, v9) == 1 )
return 1LL;
fflush(stderr);
return insertNewElement(a1[1], v11, a2, a3);
}
return 0xFFFFFFFFLL;
}
v7 = HTupdate(*a1, a2, (int)v11, &v12);
if ( v7 == -1 )
return 0xFFFFFFFFLL;
v8 = a1[1];
v9 = a3;
v10 = a2;
if ( v7 == 1 )
goto LABEL_12;
LABEL_8:
if ( (unsigned int)insertNewElement(v8, v12, v10, v9) == 1 )
return 1LL;
fflush(stderr);
return insertNewElement(a1[1], v12, a2, a3);
}

original_code:
errorCode cacheInsert(cache * c, void * key, void * data){
  int slot, old_slot;
  void * extractedData;
  int res = -1;
  if (findEmptySlot(c -> lsc, &slot) == 1){
    res = HTupdate(c -> ht, (void*)key, (void*)slot, (void**)&old_slot);
    if (res == -1)
      return res;
    if (res == 1){
      if(insertNewElement(c -> lsc, slot, key, data) != 1){ fflush(stderr); return insertNewElement(c -> lsc, slot, key, data); };
    }
    else{
      if(insertNewElement(c -> lsc, old_slot, key, data) != 1){ fflush(stderr); return insertNewElement(c -> lsc, old_slot, key, data); };
    }
  }
  else {
    findEvictionCandidate(c -> lsc, &slot);
    res = HTupdate(c -> ht, (void*)key, (void*)slot, (void**)&old_slot);
    if (res == -1)
      return res;
    if (res == 1){
      if(HTextract(c -> ht, (void*)((((c -> lsc -> accntArray) + slot) -> key )), (void**)&extractedData) != 1){ fflush(stderr); return HTextract(c -> ht, (void*)((((c -> lsc -> accntArray) + slot) -> key )), (void**)&extractedData); };
      if(insertNewElement(c -> lsc, slot, key, data) != 1){ fflush(stderr); return insertNewElement(c -> lsc, slot, key, data); };
    }
    if (res == -2){
      if(insertNewElement(c -> lsc, old_slot, key, data) != 1){ fflush(stderr); return insertNewElement(c -> lsc, old_slot, key, data); };
    }
  }
  return 1;
}

canonical_original_code:
int cacheInsert(struct cache_tag *c, void *key, void *data){
  int slot; int old_slot;
  void *extractedData;
  int res = -1;
  if (findEmptySlot(c -> lsc, &slot) == 1){
    res = HTupdate(c -> ht, (void *)key, (void *)slot, (void **)&old_slot);
    if (res == -1)
      return res;
    if (res == 1){
      if(insertNewElement(c -> lsc, slot, key, data) != 1){ fflush(stderr); return insertNewElement(c -> lsc, slot, key, data); };
    }
    else{
      if(insertNewElement(c -> lsc, old_slot, key, data) != 1){ fflush(stderr); return insertNewElement(c -> lsc, old_slot, key, data); };
    }
  }
  else {
    findEvictionCandidate(c -> lsc, &slot);
    res = HTupdate(c -> ht, (void *)key, (void *)slot, (void **)&old_slot);
    if (res == -1)
      return res;
    if (res == 1){
      if(HTextract(c -> ht, (void *)((((c -> lsc -> accntArray) + slot) -> key )), (void **)&extractedData) != 1){ fflush(stderr); return HTextract(c -> ht, (void *)((((c -> lsc -> accntArray) + slot) -> key )), (void **)&extractedData); };
      if(insertNewElement(c -> lsc, slot, key, data) != 1){ fflush(stderr); return insertNewElement(c -> lsc, slot, key, data); };
    }
    if (res == -2){
      if(insertNewElement(c -> lsc, old_slot, key, data) != 1){ fflush(stderr); return insertNewElement(c -> lsc, old_slot, key, data); };
    }
  }
  return 1;
}


cacheLookup

decompiled_code:
__int64 __fastcall cacheLookup(_QWORD *a1, __int64 a2, _QWORD *a3)
{
__int64 result; // rax
int v5[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v5) == 1 )
{
updateAccessTime(a1[1], (unsigned int)v5[0]);
*a3 = *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * v5[0] + 32);
result = 1LL;
}
else
{
fflush(stderr);
result = (unsigned int)HTlookup(*a1, a2, v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, __int64 a2, _QWORD *a3)
{
__int64 result; // rax
int v5[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v5) == 1 )
{
updateAccessTime(a1[1], (unsigned int)v5[0]);
*a3 = *(_QWORD *)(*(_QWORD *)(a1[1] + 24LL) + 56LL * v5[0] + 32);
result = 1LL;
}
else
{
fflush(stderr);
result = (unsigned int)HTlookup(*a1, a2, v5);
}
return result;
}

original_code:
errorCode cacheLookup(cache * c, void * key, void ** data){
  int slot;
  if(HTlookup(c -> ht, (void*)key, (void**)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void*)key, (void**)&slot); };
  updateAccessTime(c -> lsc, slot);
  *data = ((((c -> lsc) -> accntArray) + slot) -> data );
  return 1;
}

canonical_original_code:
int cacheLookup(struct cache_tag *c, void *key, void **data){
  int slot;
  if(HTlookup(c -> ht, (void *)key, (void **)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void *)key, (void **)&slot); };
  updateAccessTime(c -> lsc, slot);
  *data = ((((c -> lsc) -> accntArray) + slot) -> data );
  return 1;
}


cacheTouch

decompiled_code:
__int64 __fastcall cacheTouch(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v3) == 1 )
{
updateAccessTime(a1[1], (unsigned int)v3[0]);
result = 1LL;
}
else
{
fflush(stderr);
result = (unsigned int)HTlookup(*a1, a2, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v3) == 1 )
{
updateAccessTime(a1[1], (unsigned int)v3[0]);
result = 1LL;
}
else
{
fflush(stderr);
result = (unsigned int)HTlookup(*a1, a2, v3);
}
return result;
}

original_code:
errorCode cacheTouch(cache * c, void * key){
  int slot;
  if(HTlookup(c -> ht, (void*)key, (void**)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void*)key, (void**)&slot); };
  updateAccessTime(c -> lsc, slot);
  return 1;
}

canonical_original_code:
int cacheTouch(struct cache_tag *c, void *key){
  int slot;
  if(HTlookup(c -> ht, (void *)key, (void **)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void *)key, (void **)&slot); };
  updateAccessTime(c -> lsc, slot);
  return 1;
}


cacheExtract

decompiled_code:
__int64 __fastcall cacheExtract(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTextract(*a1, a2, v3) == 1 )
{
cleanAccntInfo(a1[1], (unsigned int)v3[0]);
result = 1LL;
}
else
{
fflush(stderr);
result = (unsigned int)HTextract(*a1, a2, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTextract(*a1, a2, v3) == 1 )
{
cleanAccntInfo(a1[1], (unsigned int)v3[0]);
result = 1LL;
}
else
{
fflush(stderr);
result = (unsigned int)HTextract(*a1, a2, v3);
}
return result;
}

original_code:
errorCode cacheExtract(cache * c, void * key){
  int slot;
  if(HTextract(c -> ht, (void*)key, (void**)&slot) != 1){ fflush(stderr); return HTextract(c -> ht, (void*)key, (void**)&slot); };
  cleanAccntInfo(c -> lsc, slot);
  return 1;
}

canonical_original_code:
int cacheExtract(struct cache_tag *c, void *key){
  int slot;
  if(HTextract(c -> ht, (void *)key, (void **)&slot) != 1){ fflush(stderr); return HTextract(c -> ht, (void *)key, (void **)&slot); };
  cleanAccntInfo(c -> lsc, slot);
  return 1;
}


cacheProbe

decompiled_code:
__int64 __fastcall cacheProbe(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v5) == 1 )
{
result = getAccntInfo(a1[1], (unsigned int)v5[0], a3);
if ( (_DWORD)result != 1 )
{
fflush(stderr);
result = getAccntInfo(a1[1], (unsigned int)v5[0], a3);
}
}
else
{
fflush(stderr);
result = HTlookup(*a1, a2, v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)HTlookup(*a1, a2, v5) == 1 )
{
result = getAccntInfo(a1[1], (unsigned int)v5[0], a3);
if ( (_DWORD)result != 1 )
{
fflush(stderr);
result = getAccntInfo(a1[1], (unsigned int)v5[0], a3);
}
}
else
{
fflush(stderr);
result = HTlookup(*a1, a2, v5);
}
return result;
}

original_code:
errorCode cacheProbe(cache * c, void * key, accnt ** a){
  int slot;
  if(HTlookup(c -> ht, (void*)key, (void**)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void*)key, (void**)&slot); };
  if(getAccntInfo(c -> lsc, slot, a) != 1){ fflush(stderr); return getAccntInfo(c -> lsc, slot, a); };
  return 1;
}

canonical_original_code:
int cacheProbe(struct cache_tag *c, void *key, struct accnt_tag **a){
  int slot;
  if(HTlookup(c -> ht, (void *)key, (void **)&slot) != 1){ fflush(stderr); return HTlookup(c -> ht, (void *)key, (void **)&slot); };
  if(getAccntInfo(c -> lsc, slot, a) != 1){ fflush(stderr); return getAccntInfo(c -> lsc, slot, a); };
  return 1;
}

variable_types:
a
struct accnt_tag **


cacheCopy

decompiled_code:
__int64 __fastcall cacheCopy(_QWORD *a1, _QWORD *a2)
{
unsigned int v4; // er12
int v5; // eax
__int64 v6; // r13
__int64 v7; // rdi
__int64 v8; // rsi
__int64 v9; // r13
__int64 v10; // r8
__int64 result; // rax
__int64 v12; // rax
int v13; // [rsp+0h] [rbp-38h] BYREF
int v14; // [rsp+4h] [rbp-34h] BYREF
int v15[12]; // [rsp+8h] [rbp-30h] BYREF

if ( a1 && a2 )
{
createHTscan(*a1);
while ( (unsigned int)HTadvanceScan(*a1, &v13) != -1 )
{
while ( 1 )
{
if ( (unsigned int)HTextract(*a1, v13, v15) != 1 )
{
fprintf(stderr, "%s\n", "Can not extract key in cacheCopy");
fflush(stderr);
}
v4 = v15[0];
v5 = HTlookup(*a2, v13, v15);
v14 = v15[0];
v6 = 56LL * (int)v4;
if ( v5 == 1 )
{
pageFree(*(_QWORD *)(*(_QWORD *)(a2[1] + 24LL) + 56LL * v15[0] + 32));
v7 = a1[1];
v8 = a2[1];
v10 = v14;
v12 = v6 + *(_QWORD *)(v7 + 24);
*(_QWORD *)(*(_QWORD *)(v8 + 24) + 56LL * v14 + 32) = *(_QWORD *)(v12 + 32);
*(_QWORD *)(v12 + 32) = 0LL;
}
else
{
if ( (unsigned int)cacheLookupFailedInsertSlot(a2, v13, (__int64)v15, (unsigned int *)&v14) != 1 )
{
fprintf(stderr, "%s\n", "Error update in cacheCopy\n");
fflush(stderr);
}
v7 = a1[1];
v8 = a2[1];
v9 = *(_QWORD *)(v7 + 24) + v6;
v10 = v14;
*(_QWORD *)(*(_QWORD *)(v8 + 24) + 56LL * v14 + 32) = *(_QWORD *)(v9 + 32);
*(_QWORD *)(v9 + 32) = 0LL;
}
if ( (unsigned int)moveAttrib(v7, v8, v13, v4, v10) == 1 )
break;
fprintf(stderr, "%s\n", "Error transferring attributes");
fflush(stderr);
if ( (unsigned int)HTadvanceScan(*a1, &v13) == -1 )
goto LABEL_13;
}
}
LABEL_13:
destroyHTscan(*a1);
result = 1LL;
}
else
{
puts("Source or destination cache are null");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1, _QWORD *a2)
{
unsigned int v4; // er12
int v5; // eax
__int64 v6; // r13
__int64 v7; // rdi
__int64 v8; // rsi
__int64 v9; // r13
__int64 v10; // r8
__int64 result; // rax
__int64 v12; // rax
int v13; // [rsp+0h] [rbp-38h] BYREF
int v14; // [rsp+4h] [rbp-34h] BYREF
int v15[12]; // [rsp+8h] [rbp-30h] BYREF

if ( a1 && a2 )
{
createHTscan(*a1);
while ( (unsigned int)HTadvanceScan(*a1, &v13) != -1 )
{
while ( 1 )
{
if ( (unsigned int)HTextract(*a1, v13, v15) != 1 )
{
fprintf(stderr, "%s\n", "Can not extract key in cacheCopy");
fflush(stderr);
}
v4 = v15[0];
v5 = HTlookup(*a2, v13, v15);
v14 = v15[0];
v6 = 56LL * (int)v4;
if ( v5 == 1 )
{
pageFree(*(_QWORD *)(*(_QWORD *)(a2[1] + 24LL) + 56LL * v15[0] + 32));
v7 = a1[1];
v8 = a2[1];
v10 = v14;
v12 = v6 + *(_QWORD *)(v7 + 24);
*(_QWORD *)(*(_QWORD *)(v8 + 24) + 56LL * v14 + 32) = *(_QWORD *)(v12 + 32);
*(_QWORD *)(v12 + 32) = 0LL;
}
else
{
if ( (unsigned int)func3(a2, v13, (__int64)v15, (unsigned int *)&v14) != 1 )
{
fprintf(stderr, "%s\n", "Error update in cacheCopy\n");
fflush(stderr);
}
v7 = a1[1];
v8 = a2[1];
v9 = *(_QWORD *)(v7 + 24) + v6;
v10 = v14;
*(_QWORD *)(*(_QWORD *)(v8 + 24) + 56LL * v14 + 32) = *(_QWORD *)(v9 + 32);
*(_QWORD *)(v9 + 32) = 0LL;
}
if ( (unsigned int)moveAttrib(v7, v8, v13, v4, v10) == 1 )
break;
fprintf(stderr, "%s\n", "Error transferring attributes");
fflush(stderr);
if ( (unsigned int)HTadvanceScan(*a1, &v13) == -1 )
goto LABEL_13;
}
}
LABEL_13:
destroyHTscan(*a1);
result = 1LL;
}
else
{
puts("Source or destination cache are null");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
errorCode cacheCopy(cache * src, cache * dest){
  int key;
  void * data;
  int res;
  int slotSrc, slotDest;
  if (!src || !dest){
    printf("Source or destination cache are null\n");
    return -1;
  }
  createHTscan(src -> ht);
  while (HTadvanceScan(src -> ht, (void *)&key) != -1){
    if(HTextract(src -> ht, (void*)key, (void **)&data) != 1){ fprintf(stderr, "%s\n", "Can not extract key in cacheCopy"); fflush(stderr); };
    slotSrc = (int)data;
    res = HTlookup(dest -> ht, (void*)key, (void **)&data);
    slotDest = (int)data;
    if (res == 1){
      pageFree((((dest -> lsc -> accntArray) + slotDest) -> data ));
      (((dest -> lsc -> accntArray) + slotDest) -> data ) = (((src -> lsc -> accntArray) + slotSrc) -> data );
      (((src -> lsc -> accntArray) + slotSrc) -> data ) = ((void *)0);
      if(moveAttrib(src -> lsc, dest -> lsc, (void*)key, slotSrc, slotDest) != 1){ fprintf(stderr, "%s\n", "Error transferring attributes"); fflush(stderr); };
    }
    else{
      if(cacheLookupFailedInsertSlot(dest, (void*)key, (void **)&data, &slotDest) != 1){ fprintf(stderr, "%s\n", "Error update in cacheCopy\n"); fflush(stderr); };
      (((dest -> lsc -> accntArray) + slotDest) -> data ) = (((src -> lsc -> accntArray) + slotSrc) -> data );
      (((src -> lsc -> accntArray) + slotSrc) -> data ) = ((void *)0);
      if(moveAttrib(src -> lsc, dest -> lsc, (void*)key, slotSrc, slotDest) != 1){ fprintf(stderr, "%s\n", "Error transferring attributes"); fflush(stderr); };
    }
  }
  destroyHTscan(src -> ht);
  return 1;
}

canonical_original_code:
int cacheCopy(struct cache_tag *src, struct cache_tag *dest){
  int key;
  void *data;
  int res;
  int slotSrc; int slotDest;
  if (!src || !dest){
    printf("Source or destination cache are null\n");
    return -1;
  }
  createHTscan(src -> ht);
  while (HTadvanceScan(src -> ht, (void *)&key) != -1){
    if(HTextract(src -> ht, (void *)key, (void **)&data) != 1){ fprintf(stderr, "%s\n", "Can not extract key in cacheCopy"); fflush(stderr); };
    slotSrc = (int)data;
    res = HTlookup(dest -> ht, (void *)key, (void **)&data);
    slotDest = (int)data;
    if (res == 1){
      pageFree((((dest -> lsc -> accntArray) + slotDest) -> data ));
      (((dest -> lsc -> accntArray) + slotDest) -> data ) = (((src -> lsc -> accntArray) + slotSrc) -> data );
      (((src -> lsc -> accntArray) + slotSrc) -> data ) = ((void *)0);
      if(moveAttrib(src -> lsc, dest -> lsc, (void *)key, slotSrc, slotDest) != 1){ fprintf(stderr, "%s\n", "Error transferring attributes"); fflush(stderr); };
    }
    else{
      if(cacheLookupFailedInsertSlot(dest, (void *)key, (void **)&data, &slotDest) != 1){ fprintf(stderr, "%s\n", "Error update in cacheCopy\n"); fflush(stderr); };
      (((dest -> lsc -> accntArray) + slotDest) -> data ) = (((src -> lsc -> accntArray) + slotSrc) -> data );
      (((src -> lsc -> accntArray) + slotSrc) -> data ) = ((void *)0);
      if(moveAttrib(src -> lsc, dest -> lsc, (void *)key, slotSrc, slotDest) != 1){ fprintf(stderr, "%s\n", "Error transferring attributes"); fflush(stderr); };
    }
  }
  destroyHTscan(src -> ht);
  return 1;
}

variable_types:
dest
struct cache_tag *

variable_types: key int

variable_types: slotSrc int

variable_types: slotDest int


cacheDestroy

decompiled_code:
__int64 __fastcall cacheDestroy(_QWORD *a1)
{
destroyCache(*a1 + 8LL);
deleteHashtable(*a1);
memFree(*a1);
*a1 = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
destroyCache(*a1 + 8LL);
deleteHashtable(*a1);
memFree(*a1);
*a1 = 0LL;
return 1LL;
}

original_code:
errorCode cacheDestroy(cache ** c){
  destroyCache(& ((*c) -> lsc));
  deleteHashtable(& ((*c) -> ht ));
  memFree(*c);
  *c = ((void *)0);
  return 1;
}

canonical_original_code:
int cacheDestroy(struct cache_tag **c){
  destroyCache(& ((*c) -> lsc));
  deleteHashtable(& ((*c) -> ht ));
  memFree(*c);
  *c = ((void *)0);
  return 1;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rbp
__int64 i; // rbx
const char *v7; // rdx
char v8[4]; // [rsp+4h] [rbp-24h] BYREF
__int64 v9[4]; // [rsp+8h] [rbp-20h] BYREF

v9[0] = 0LL;
if ( (unsigned int)createHashtable(1024LL, &compareBlockNumberNoPointer, 0LL, 0LL, v9) == -1 )
{
v7 = "Error allocating hashtable";
LABEL_12:
fprintf(stderr, "%s\n", v7);
fflush(stderr);
exit(1);
}
if ( (unsigned int)HTinsert(v9[0], 100LL, 0LL) == -1 )
{
LABEL_11:
v7 = "Error inserting";
goto LABEL_12;
}
printHashtableContent(stdout, v9[0], &unk_32);
if ( (unsigned int)HTextract(v9[0], 100LL, v8) == -1 )
{
LABEL_13:
v7 = "Error deleting";
goto LABEL_12;
}
v3 = 0LL;
v4 = 0LL;
do
{
if ( (unsigned int)HTinsert(v9[0], v4, v3) == -1 )
goto LABEL_11;
v3 += 10LL;
v4 += 100LL;
}
while ( v3 != 50000 );
for ( i = 0LL; i != 500000; i += 100LL )
{
if ( (unsigned int)HTextract(v9[0], i, v8) == -1 )
goto LABEL_13;
}
return 0;
}

original_code:
int main(void){
  hashtable * ht = ((void *)0);
  int numberEntries = 1024;
  errorCode result;
  int values = 100;
  int i = 0;
  int data;
  int key, empty;
  result = createHashtable(numberEntries, compareBlockNumberNoPointer, ((void *)0), ((void *)0), &ht);
  if(result == -1){ fprintf(stderr, "%s\n", "Error allocating hashtable"); fflush(stderr); exit(1); };
  result = HTinsert(ht, 100, i * 10);
  if(result == -1){ fprintf(stderr, "%s\n", "Error inserting"); fflush(stderr); exit(1); };
  printHashtableContent(stdout, ht, "");
  result = HTextract(ht, 100, &data);
  if(result == -1){ fprintf(stderr, "%s\n", "Error deleting"); fflush(stderr); exit(1); };
  for (i = 0 ; i < 5000; i++){
    result = HTinsert(ht, i * 100, i * 10);
    if(result == -1){ fprintf(stderr, "%s\n", "Error inserting"); fflush(stderr); exit(1); };
  }
  for (i = 0 ; i < 5000; i++){
    result = HTextract(ht, i * 100, &data);
    if(result == -1){ fprintf(stderr, "%s\n", "Error deleting"); fflush(stderr); exit(1); };
  }
  return 0;
  printf("Data extracted %d\n", data);
  printHashtableContent(stdout, ht, "");
  result = HTlookup(ht, 100, &data);
  printf("return of lookup %d\n", result);
  fflush(stdout);
  createHTscan(ht);
  while (HTadvanceScan(ht, &key) != -1){
    HTlookup(ht, key, &data);
    printf("Lookup %d\n", data);
    HTextract(ht, key, &data);
    printf("Extracted %d\n", data);
  }
  printHashtableContent(stdout, ht, "");
  destroyHTscan(ht);
  HTempty(ht, &empty);
  printf("creating scan again %d\n", empty);
  createHTscan(ht);
  while (HTadvanceScan(ht, &key) != -1){
    result = HTlookup(ht, key, &data);
    printf("Lookup %d %d\n", data, result);
    fflush(stdout);
    result = HTextract(ht, key, &data);
    printf("Extracted %d %d\n", data, result);
    fflush(stdout);
  }
  destroyHTscan(ht);
  printf("destroying scan again\n");
  fflush(stdout);
  if (ht == ((void *)0)){
    printf("ht null \n");
    fflush(stdout);
  }
  deleteHashtable(&ht);
  return 0;
}

canonical_original_code:
int main(){
  struct hashtable_tag *ht = ((void *)0);
  int numberEntries = 1024;
  int result;
  int values = 100;
  int i = 0;
  int data;
  int key; int empty;
  result = createHashtable(numberEntries, compareBlockNumberNoPointer, ((void *)0), ((void *)0), &ht);
  if(result == -1){ fprintf(stderr, "%s\n", "Error allocating hashtable"); fflush(stderr); exit(1); };
  result = HTinsert(ht, 100, i * 10);
  if(result == -1){ fprintf(stderr, "%s\n", "Error inserting"); fflush(stderr); exit(1); };
  printHashtableContent(stdout, ht, "");
  result = HTextract(ht, 100, &data);
  if(result == -1){ fprintf(stderr, "%s\n", "Error deleting"); fflush(stderr); exit(1); };
  for (i = 0 ; i < 5000; i++){
    result = HTinsert(ht, i * 100, i * 10);
    if(result == -1){ fprintf(stderr, "%s\n", "Error inserting"); fflush(stderr); exit(1); };
  }
  for (i = 0 ; i < 5000; i++){
    result = HTextract(ht, i * 100, &data);
    if(result == -1){ fprintf(stderr, "%s\n", "Error deleting"); fflush(stderr); exit(1); };
  }
  return 0;
  printf("Data extracted %d\n", data);
  printHashtableContent(stdout, ht, "");
  result = HTlookup(ht, 100, &data);
  printf("return of lookup %d\n", result);
  fflush(stdout);
  createHTscan(ht);
  while (HTadvanceScan(ht, &key) != -1){
    HTlookup(ht, key, &data);
    printf("Lookup %d\n", data);
    HTextract(ht, key, &data);
    printf("Extracted %d\n", data);
  }
  printHashtableContent(stdout, ht, "");
  destroyHTscan(ht);
  HTempty(ht, &empty);
  printf("creating scan again %d\n", empty);
  createHTscan(ht);
  while (HTadvanceScan(ht, &key) != -1){
    result = HTlookup(ht, key, &data);
    printf("Lookup %d %d\n", data, result);
    fflush(stdout);
    result = HTextract(ht, key, &data);
    printf("Extracted %d %d\n", data, result);
    fflush(stdout);
  }
  destroyHTscan(ht);
  printf("destroying scan again\n");
  fflush(stdout);
  if (ht == ((void *)0)){
    printf("ht null \n");
    fflush(stdout);
  }
  deleteHashtable(&ht);
  return 0;
}

variable_types: struct hashtable_tag { int size; int numberEntries; struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; } *table; int (*compare)(void *, void *, int *); int (*deallocKey)(void *); int (*deallocData)(void *); int scanActive; int crtEntryNr; struct hashtableEntry_tag *crtEntry; int advance; } *

variable_types: numberEntries int

variable_types: result int

variable_types: values int

variable_types: i int

variable_types: data int

variable_types: empty int

user_defined_types: struct hashtable_tag { int size; int numberEntries; struct hashtableEntry_tag *table; int (*compare)(void *, void *, int *); int (*deallocKey)(void *); int (*deallocData)(void *); int scanActive; int crtEntryNr; struct hashtableEntry_tag *crtEntry; int advance; }


allocHashtableEntry

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

*(_QWORD *)a3 = 0LL;
if ( (unsigned int)memAlloc(24LL, a3) == 1 )
{
**(_QWORD **)a3 = a1;
*(_QWORD *)(*(_QWORD *)a3 + 8LL) = a2;
*(_QWORD *)(*(_QWORD *)a3 + 16LL) = 0LL;
result = 1LL;
}
else
{
fflush(stderr);
result = memAlloc(24LL, a3);
}
return result;
}

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

*(_QWORD *)a3 = 0LL;
if ( (unsigned int)memAlloc(24LL, a3) == 1 )
{
**(_QWORD **)a3 = a1;
*(_QWORD *)(*(_QWORD *)a3 + 8LL) = a2;
*(_QWORD *)(*(_QWORD *)a3 + 16LL) = 0LL;
result = 1LL;
}
else
{
fflush(stderr);
result = memAlloc(24LL, a3);
}
return result;
}

original_code:
errorCode allocHashtableEntry(void * key, void * data, hashtableEntry ** hte){
  * hte = ((void *)0);
  if(memAlloc(sizeof(hashtableEntry), (void **)hte) != 1){ fflush(stderr); return memAlloc(sizeof(hashtableEntry), (void **)hte); };
  (*hte) -> key = key;
  (*hte) -> data = data;
  (*hte) -> next = ((void *)0);
  return 1;
}

canonical_original_code:
int allocHashtableEntry(void *key, void *data, struct hashtableEntry_tag **hte){
  * hte = ((void *)0);
  if(memAlloc(sizeof(hashtableEntry), (void **)hte) != 1){ fflush(stderr); return memAlloc(sizeof(hashtableEntry), (void **)hte); };
  (*hte) -> key = key;
  (*hte) -> data = data;
  (*hte) -> next = ((void *)0);
  return 1;
}

variable_types:
key
void *

variable_types:
data
void *

variable_types: struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; } **


deallocHashtableEntry

decompiled_code:
__int64 __fastcall deallocHashtableEntry(__int64 a1)
{
if ( a1 )
memFree();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( a1 )
memFree();
return 1LL;
}

original_code:
errorCode deallocHashtableEntry(void * entry){
  if (entry == ((void *)0))
    return 1;
  memFree(entry);
  return 1;
}

canonical_original_code:
int deallocHashtableEntry(void *entry){
  if (entry == ((void *)0))
    return 1;
  memFree(entry);
  return 1;
}

variable_types:
entry
void *


deallocHashtableEntryFreeKeyAndData

decompiled_code:
__int64 __fastcall deallocHashtableEntryFreeKeyAndData(__int64 a1, _QWORD *a2)
{
void (*v2)(void); // rax
void (__fastcall *v3)(_QWORD); // rax

if ( !a2 )
return 1LL;
if ( *a2 )
{
v2 = *(void (**)(void))(a1 + 24);
if ( !v2 || (v2(), *a2) )
{
v3 = *(void (__fastcall **)(_QWORD))(a1 + 32);
if ( v3 )
v3(a2[1]);
}
}
memFree(a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2)
{
void (*v2)(void); // rax
void (__fastcall *v3)(_QWORD); // rax

if ( !a2 )
return 1LL;
if ( *a2 )
{
v2 = *(void (**)(void))(a1 + 24);
if ( !v2 || (v2(), *a2) )
{
v3 = *(void (__fastcall **)(_QWORD))(a1 + 32);
if ( v3 )
v3(a2[1]);
}
}
memFree(a2);
return 1LL;
}

original_code:
errorCode deallocHashtableEntryFreeKeyAndData(hashtable * ht, void * entry){
  hashtableEntry * hte = (hashtableEntry *) entry;
  if (entry == ((void *)0))
    return 1;
  if (hte -> key != ((void *)0) && ht -> deallocKey)
    (ht -> deallocKey)(hte -> key);
  if (hte -> key != ((void *)0) && ht -> deallocData)
    (ht -> deallocData)(hte -> data);
  memFree(entry);
  return 1;
}

canonical_original_code:
int deallocHashtableEntryFreeKeyAndData(struct hashtable_tag *ht, void *entry){
  struct hashtableEntry_tag *hte = (hashtableEntry *) entry;
  if (entry == ((void *)0))
    return 1;
  if (hte -> key != ((void *)0) && ht -> deallocKey)
    (ht -> deallocKey)(hte -> key);
  if (hte -> key != ((void *)0) && ht -> deallocData)
    (ht -> deallocData)(hte -> data);
  memFree(entry);
  return 1;
}

variable_types: struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; } *


HTempty

decompiled_code:
__int64 __fastcall HTempty(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( a1 )
{
*a2 = *a1 == 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( a1 )
{
*a2 = *a1 == 0;
result = 1LL;
}
return result;
}

original_code:
errorCode HTempty(hashtable * ht, int * res){
  if (ht == ((void *)0))
    return -1;
  else {
    *res = (ht -> size == 0);
    return 1;
  }
}

canonical_original_code:
int HTempty(struct hashtable_tag *ht, int *res){
  if (ht == ((void *)0))
    return -1;
  else {
    *res = (ht -> size == 0);
    return 1;
  }
}

variable_types:
res
int *

user_defined_types: struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; }


HTsize

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

if ( a1 )
result = *a1;
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int HTsize(hashtable * ht)
{
  if (ht == ((void *)0))
    return -1;
  else
    return ht->size;
}

canonical_original_code:
int HTsize(struct hashtable_tag *ht)
{
  if (ht == ((void *)0))
    return -1;
  else
    return ht->size;
}


scanForNonNullEntry

original_code:
errorCode scanForNonNullEntry(hashtable * ht){
  int notFound = 1;
  if (ht -> advance ||
      (!(ht -> advance) &&
       (ht -> crtEntry == ((void *)0)))){
    while (notFound){
      if (ht -> crtEntry == ((void *)0)){
 ht -> crtEntryNr ++;
 if (ht -> crtEntryNr >= ht -> numberEntries){
   return -1;
 }
 ht -> crtEntry = ht -> table[ht-> crtEntryNr].next;
      }
      else
 ht -> crtEntry = ht -> crtEntry -> next;
      notFound = (ht -> crtEntry == ((void *)0));
    }
    ht -> advance = 1;
    return 1;
  }
  else{
    ht -> advance = 1;
    if(ht -> crtEntry == ((void *)0))
      return -1;
    else
      return 1;
  }
}

canonical_original_code:
int scanForNonNullEntry(struct hashtable_tag *ht){
  int notFound = 1;
  if (ht -> advance ||
      (!(ht -> advance) &&
       (ht -> crtEntry == ((void *)0)))){
    while (notFound){
      if (ht -> crtEntry == ((void *)0)){
 ht -> crtEntryNr ++;
 if (ht -> crtEntryNr >= ht -> numberEntries){
   return -1;
 }
 ht -> crtEntry = ht -> table[ht-> crtEntryNr].next;
      }
      else
 ht -> crtEntry = ht -> crtEntry -> next;
      notFound = (ht -> crtEntry == ((void *)0));
    }
    ht -> advance = 1;
    return 1;
  }
  else{
    ht -> advance = 1;
    if(ht -> crtEntry == ((void *)0))
      return -1;
    else
      return 1;
  }
}

variable_types: notFound int


createHTscan

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

*(_QWORD *)(a1 + 48) = 0LL;
*(_QWORD *)(a1 + 40) = 0xFFFFFFFF00000001LL;
result = 1LL;
*(_DWORD *)(a1 + 56) = 1;
return result;
}

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

*(_QWORD *)(a1 + 48) = 0LL;
*(_QWORD *)(a1 + 40) = 0xFFFFFFFF00000001LL;
result = 1LL;
*(_DWORD *)(a1 + 56) = 1;
return result;
}

original_code:
errorCode createHTscan(hashtable * ht){
  (ht) -> scanActive = 1;
  (ht) -> crtEntryNr = -1;
  (ht) -> crtEntry = ((void *)0);
  (ht) -> advance = 1;
  return 1;
}

canonical_original_code:
int createHTscan(struct hashtable_tag *ht){
  (ht) -> scanActive = 1;
  (ht) -> crtEntryNr = -1;
  (ht) -> crtEntry = ((void *)0);
  (ht) -> advance = 1;
  return 1;
}


HTadvanceScan

decompiled_code:
__int64 __fastcall HTadvanceScan(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = scanForNonNullEntry(a1);
v3 = 0LL;
if ( (_DWORD)result == 1 )
v3 = **(_QWORD **)(a1 + 48);
*a2 = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = func5(a1);
v3 = 0LL;
if ( (_DWORD)result == 1 )
v3 = **(_QWORD **)(a1 + 48);
*a2 = v3;
return result;
}

original_code:
errorCode HTadvanceScan(hashtable * ht, void ** key){
  int res = -1;
  res = scanForNonNullEntry(ht);
  if (res == 1)
    *key = ht -> crtEntry -> key;
  else
    *key = ((void *)0);
  return res;
}

canonical_original_code:
int HTadvanceScan(struct hashtable_tag *ht, void **key){
  int res = -1;
  res = scanForNonNullEntry(ht);
  if (res == 1)
    *key = ht -> crtEntry -> key;
  else
    *key = ((void *)0);
  return res;
}

variable_types:
key
void **

variable_types: res int


destroyHTscan

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

*(_QWORD *)(a1 + 48) = 0LL;
*(_QWORD *)(a1 + 40) = 0xFFFFFFFF00000000LL;
result = 1LL;
*(_DWORD *)(a1 + 56) = 1;
return result;
}

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

*(_QWORD *)(a1 + 48) = 0LL;
*(_QWORD *)(a1 + 40) = 0xFFFFFFFF00000000LL;
result = 1LL;
*(_DWORD *)(a1 + 56) = 1;
return result;
}

original_code:
errorCode destroyHTscan(hashtable * ht){
  (ht) -> scanActive = 0;
  (ht) -> crtEntryNr = -1;
  (ht) -> crtEntry = ((void *)0);
  (ht) -> advance = 1;
  return 1;
}

canonical_original_code:
int destroyHTscan(struct hashtable_tag *ht){
  (ht) -> scanActive = 0;
  (ht) -> crtEntryNr = -1;
  (ht) -> crtEntry = ((void *)0);
  (ht) -> advance = 1;
  return 1;
}


compareBlockNumberNoPointer

decompiled_code:
__int64 __fastcall compareBlockNumberNoPointer(int a1, int a2, _DWORD *a3)
{
*a3 = a1 != a2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2, _DWORD *a3)
{
*a3 = a1 != a2;
return 1LL;
}

original_code:
errorCode compareBlockNumberNoPointer(void * k1, void * k2, int * result){
  unsigned int key1 = (int)k1;
  unsigned int key2 = (int)k2;
  if (key1 == key2)
    *result = 0;
  else
    *result = 1;
  return 1;
}

canonical_original_code:
int compareBlockNumberNoPointer(void *k1, void *k2, int *result){
  unsigned int key1 = (int)k1;
  unsigned int key2 = (int)k2;
  if (key1 == key2)
    *result = 0;
  else
    *result = 1;
  return 1;
}

variable_types:
result
int *


createHashtable

decompiled_code:
__int64 __fastcall createHashtable(int a1, __int64 a2, __int64 a3, __int64 a4, _QWORD *a5)
{
__int64 result; // rax
_QWORD *v10; // rsi
_QWORD *v11; // rcx
__int64 v12; // rdx
_QWORD *v13; // rax
__int64 v14; // rdx

if ( (unsigned int)memAlloc(64LL, a5) == 1 )
{
v10 = (_QWORD *)*a5;
v10[5] = 0xFFFFFFFF00000000LL;
++v10;
v10[5] = 0LL;
*((_DWORD *)v10 + 12) = 1;
*((_DWORD *)v10 - 2) = 0;
*((_DWORD *)v10 - 1) = a1;
if ( (unsigned int)memAlloc((unsigned int)(24 * a1), v10) == 1 )
{
v11 = (_QWORD *)*a5;
if ( a1 > 0 )
{
v12 = v11[1];
v13 = (_QWORD *)(v12 + 16);
v14 = v12 + 24LL * (unsigned int)(a1 - 1) + 40;
do
{
*v13 = 0LL;
v13 += 3;
}
while ( v13 != (_QWORD *)v14 );
}
v11[2] = a2;
result = 1LL;
v11[3] = a3;
v11[4] = a4;
}
else
{
fflush(stderr);
result = memAlloc((unsigned int)(24 * a1), *a5 + 8LL);
}
}
else
{
fflush(stderr);
result = memAlloc(64LL, a5);
}
return result;
}

original_code:
errorCode createHashtable(int numberEntries, keyCompareFunction compare, deallocKeyFunction deallocK, deallocDataFunction deallocD, hashtable ** ht ){
  int i = 0;
  if(memAlloc(sizeof(hashtable), (void**)ht) != 1){ fflush(stderr); return memAlloc(sizeof(hashtable), (void**)ht); };
  (*ht) -> scanActive = 0;
  (*ht) -> crtEntry = ((void *)0);
  (*ht) -> crtEntryNr = -1;
  (*ht) -> advance = 1;
  (*ht) -> size = 0;
  (*ht) -> numberEntries = numberEntries;
  if(memAlloc(numberEntries * sizeof(hashtableEntry), (void **)&((*ht) -> table)) != 1){ fflush(stderr); return memAlloc(numberEntries * sizeof(hashtableEntry), (void **)&((*ht) -> table)); };
  for(i = 0; i < numberEntries; i++){
    (((*ht) -> table)[i]).next = ((void *)0);
  }
  (*ht) -> compare = compare;
  (*ht) -> deallocKey = deallocK;
  (*ht) -> deallocData = deallocD;
  return 1;
}

canonical_original_code:
int createHashtable(int numberEntries, int (*compare)(void *, void *, int *), int (*deallocK)(void *), int (*deallocD)(void *), struct hashtable_tag **ht){
  int i = 0;
  if(memAlloc(sizeof(hashtable), (void **)ht) != 1){ fflush(stderr); return memAlloc(sizeof(hashtable), (void **)ht); };
  (*ht) -> scanActive = 0;
  (*ht) -> crtEntry = ((void *)0);
  (*ht) -> crtEntryNr = -1;
  (*ht) -> advance = 1;
  (*ht) -> size = 0;
  (*ht) -> numberEntries = numberEntries;
  if(memAlloc(numberEntries * sizeof(hashtableEntry), (void **)&((*ht) -> table)) != 1){ fflush(stderr); return memAlloc(numberEntries * sizeof(hashtableEntry), (void **)&((*ht) -> table)); };
  for(i = 0; i < numberEntries; i++){
    (((*ht) -> table)[i]).next = ((void *)0);
  }
  (*ht) -> compare = compare;
  (*ht) -> deallocKey = deallocK;
  (*ht) -> deallocData = deallocD;
  return 1;
}

variable_types:
compare
int (*)(void *, void *, int *)

variable_types:
deallocK
int (*)(void *)

variable_types:
deallocD
int (*)(void *)

variable_types: struct hashtable_tag { int size; int numberEntries; struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; } *table; int (*compare)(void *, void *, int *); int (*deallocKey)(void *); int (*deallocData)(void *); int scanActive; int crtEntryNr; struct hashtableEntry_tag *crtEntry; int advance; } **


deleteHashtable

decompiled_code:
__int64 __fastcall deleteHashtable(_QWORD *a1)
{
__int64 v2; // rdx
__int64 v3; // rbp
__int64 v4; // rbx
__int64 v5; // rdi
__int64 result; // rax

printf("%d\n", *(unsigned int *)(*a1 + 4LL));
v2 = *a1;
if ( *(int *)(*a1 + 4LL) > 0 )
{
v3 = 0LL;
do
{
printf("Deallocating %d\n", (unsigned int)v3);
v2 = *a1;
v4 = *(_QWORD *)(*(_QWORD *)(*a1 + 8LL) + 24 * v3 + 16);
if ( v4 )
{
do
{
v5 = v4;
v4 = *(_QWORD *)(v4 + 16);
deallocHashtableEntry(v5);
}
while ( v4 );
v2 = *a1;
}
++v3;
}
while ( *(_DWORD *)(v2 + 4) > (int)v3 );
}
memFree(*(_QWORD *)(v2 + 8));
memFree(*a1);
result = 1LL;
*a1 = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1)
{
__int64 v2; // rdx
__int64 v3; // rbp
__int64 v4; // rbx
__int64 v5; // rdi
__int64 result; // rax

printf("%d\n", *(unsigned int *)(*a1 + 4LL));
v2 = *a1;
if ( *(int *)(*a1 + 4LL) > 0 )
{
v3 = 0LL;
do
{
printf("Deallocating %d\n", (unsigned int)v3);
v2 = *a1;
v4 = *(_QWORD *)(*(_QWORD *)(*a1 + 8LL) + 24 * v3 + 16);
if ( v4 )
{
do
{
v5 = v4;
v4 = *(_QWORD *)(v4 + 16);
func1(v5);
}
while ( v4 );
v2 = *a1;
}
++v3;
}
while ( *(_DWORD *)(v2 + 4) > (int)v3 );
}
memFree(*(_QWORD *)(v2 + 8));
memFree(*a1);
result = 1LL;
*a1 = 0LL;
return result;
}

original_code:
errorCode deleteHashtable(hashtable ** ht){
  int i;
  hashtableEntry * temp, *successor;;
  printf("%d\n", (*ht) -> numberEntries);
  for(i = 0; i < (*ht) -> numberEntries; i++){
    printf("Deallocating %d\n", i);
    temp = (((*ht) -> table)[i]).next;
    successor = ((void *)0);
    while(temp != ((void *)0)){
      successor = temp -> next;
      deallocHashtableEntry(temp);
      temp = successor;
    }
  }
  memFree((*ht) -> table);
  memFree(*ht);
  *ht = ((void *)0);
  return 1;
}

canonical_original_code:
int deleteHashtable(struct hashtable_tag **ht){
  int i;
  struct hashtableEntry_tag *temp; struct hashtableEntry_tag *successor;;
  printf("%d\n", (*ht) -> numberEntries);
  for(i = 0; i < (*ht) -> numberEntries; i++){
    printf("Deallocating %d\n", i);
    temp = (((*ht) -> table)[i]).next;
    successor = ((void *)0);
    while(temp != ((void *)0)){
      successor = temp -> next;
      deallocHashtableEntry(temp);
      temp = successor;
    }
  }
  memFree((*ht) -> table);
  memFree(*ht);
  *ht = ((void *)0);
  return 1;
}

variable_types: i int


deleteHashtableAndData

decompiled_code:
__int64 __fastcall deleteHashtableAndData(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // r12
_QWORD *v4; // rsi
_QWORD *v5; // rbx
__int64 result; // rax

v2 = *a1;
if ( *(int *)(v2 + 4) > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD **)(*(_QWORD *)(v2 + 8) + 24 * v3 + 16);
if ( v4 )
{
while ( 1 )
{
v5 = (_QWORD *)v4[2];
deallocHashtableEntryFreeKeyAndData(v2, v4);
v2 = *a1;
if ( !v5 )
break;
v4 = v5;
}
}
++v3;
}
while ( *(_DWORD *)(v2 + 4) > (int)v3 );
}
memFree(*(_QWORD *)(v2 + 8));
memFree(*a1);
result = 1LL;
*a1 = 0LL;
return result;
}

original_code:
errorCode deleteHashtableAndData(hashtable ** ht){
  int i;
  for(i = 0; i < (*ht) -> numberEntries; i++){
    hashtableEntry * temp = (((*ht) -> table)[i]).next, * successor = ((void *)0);
    while(temp != ((void *)0)){
      successor = temp -> next;
      deallocHashtableEntryFreeKeyAndData(*ht, temp);
      temp = successor;
    }
  }
  memFree((*ht) -> table);
  memFree(*ht);
  *ht = ((void *)0);
  return 1;
}

canonical_original_code:
int deleteHashtableAndData(struct hashtable_tag **ht){
  int i;
  for(i = 0; i < (*ht) -> numberEntries; i++){
    struct hashtableEntry_tag *temp = (((*ht) -> table)[i]).next; struct hashtableEntry_tag *successor = ((void *)0);
    while(temp != ((void *)0)){
      successor = temp -> next;
      deallocHashtableEntryFreeKeyAndData(*ht, temp);
      temp = successor;
    }
  }
  memFree((*ht) -> table);
  memFree(*ht);
  *ht = ((void *)0);
  return 1;
}


hashFunction

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

result = 1LL;
*a3 = a2 % *(_DWORD *)(a1 + 4);
return result;
}

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

result = 1LL;
*a3 = a2 % *(_DWORD *)(a1 + 4);
return result;
}

original_code:
errorCode hashFunction(hashtable * ht, void * key, int * entry){
  *entry = (((int)key) % (ht -> numberEntries));
 return 1;
}

canonical_original_code:
int hashFunction(struct hashtable_tag *ht, void *key, int *entry){
  *entry = (((int)key) % (ht -> numberEntries));
 return 1;
}

variable_types: struct hashtable_tag { int size; int numberEntries; struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; } *table; int (*compare)(void *, void *, int *); int (*deallocKey)(void *); int (*deallocData)(void *); int scanActive; int crtEntryNr; struct hashtableEntry_tag *crtEntry; int advance; } *

variable_types:
entry
int *


listLookup

decompiled_code:
__int64 __fastcall listLookup(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(__int64, _QWORD, int *), _QWORD *a4)
{
_QWORD *v4; // rbx
__int64 result; // rax
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

*a4 = a1;
v4 = *(_QWORD **)(a1 + 16);
if ( !v4 )
return 0xFFFFFFFFLL;
for ( result = a3(a2, *v4, v8); (_DWORD)result == 1; result = a3(a2, *v4, v8) )
{
if ( !v8[0] )
return result;
*a4 = v4;
v4 = (_QWORD *)v4[2];
if ( !v4 )
return 0xFFFFFFFFLL;
}
fflush(stderr);
return a3(a2, *v4, v8);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(__int64, _QWORD, int *), _QWORD *a4)
{
_QWORD *v4; // rbx
__int64 result; // rax
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

*a4 = a1;
v4 = *(_QWORD **)(a1 + 16);
if ( !v4 )
return 0xFFFFFFFFLL;
for ( result = a3(a2, *v4, v8); (_DWORD)result == 1; result = a3(a2, *v4, v8) )
{
if ( !v8[0] )
return result;
*a4 = v4;
v4 = (_QWORD *)v4[2];
if ( !v4 )
return 0xFFFFFFFFLL;
}
fflush(stderr);
return a3(a2, *v4, v8);
}

original_code:
errorCode listLookup(hashtableEntry * start, void * key, keyCompareFunction
    compare, hashtableEntry ** predecessor){
  errorCode result = -1;
  int resultCompare;
  *predecessor = start;
  start = start -> next;
  while(start != ((void *)0)){
    if(compare(key, start -> key, &resultCompare) != 1){ fflush(stderr); return compare(key, start -> key, &resultCompare); };
    if (resultCompare == 0){
      result = 1;
      return result;
    }
    *predecessor = start;
    start = start -> next;
  }
  return -1;
}

canonical_original_code:
int listLookup(struct hashtableEntry_tag *start, void *key, int (*compare)(void *, void *, int *), struct hashtableEntry_tag **predecessor){
  int result = -1;
  int resultCompare;
  *predecessor = start;
  start = start -> next;
  while(start != ((void *)0)){
    if(compare(key, start -> key, &resultCompare) != 1){ fflush(stderr); return compare(key, start -> key, &resultCompare); };
    if (resultCompare == 0){
      result = 1;
      return result;
    }
    *predecessor = start;
    start = start -> next;
  }
  return -1;
}

variable_types:
key
void *

variable_types:
predecessor
struct hashtableEntry_tag **

variable_types: result int

variable_types: resultCompare int


HTupdate

decompiled_code:
__int64 __fastcall HTupdate(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
unsigned int v5; // er12
__int64 result; // rax
__int64 v7; // rax
__int64 *v8; // rdx
__int64 v9; // rdi
int v10; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v11; // [rsp+10h] [rbp-28h] BYREF
__int64 *v12; // [rsp+18h] [rbp-20h] BYREF

v11 = 0LL;
allocHashtableEntry(a2, a3, (__int64)&v12);
v5 = hashFunction(a1, *v12, &v10);
if ( v5 != 1 )
{
fflush(stderr);
return v5;
}
if ( (unsigned int)listLookup(
*(_QWORD *)(a1 + 8) + 24LL * v10,
*v12,
*(__int64 (__fastcall **)(__int64, _QWORD, int *))(a1 + 16),
&v11) == 1 )
{
v9 = (__int64)v12;
v5 = -2;
*a4 = *(_QWORD *)(*(_QWORD *)(v11 + 16) + 8LL);
deallocHashtableEntry(v9);
return v5;
}
v7 = *(_QWORD *)(a1 + 8) + 24LL * v10;
v8 = v12;
v12[2] = *(_QWORD *)(v7 + 16);
*(_QWORD *)(v7 + 16) = v8;
result = 1LL;
++*(_DWORD *)a1;
return result;
}

original_code:
errorCode HTupdate(hashtable * ht, void * key, void * data, void ** old_data){
  errorCode result = -1;
  hashtableEntry * predecessor = ((void *)0);
  hashtableEntry * hte;
  int position;
  allocHashtableEntry(key, data, &hte);
  result = hashFunction(ht, hte -> key, &position);
  if(result != 1){ fflush(stderr); return result; };
  result = listLookup((ht -> table) + position, hte -> key, ht -> compare, &predecessor);
  if (result == 1){
    * old_data = predecessor -> next -> data;
    deallocHashtableEntry(hte);
    return -2;
  }
  hte -> next = (ht -> table)[position].next;
  (ht -> table)[position].next = hte;
  (ht -> size) ++;
  return 1;
}

canonical_original_code:
int HTupdate(struct hashtable_tag *ht, void *key, void *data, void **old_data){
  int result = -1;
  struct hashtableEntry_tag *predecessor = ((void *)0);
  struct hashtableEntry_tag *hte;
  int position;
  allocHashtableEntry(key, data, &hte);
  result = hashFunction(ht, hte -> key, &position);
  if(result != 1){ fflush(stderr); return result; };
  result = listLookup((ht -> table) + position, hte -> key, ht -> compare, &predecessor);
  if (result == 1){
    * old_data = predecessor -> next -> data;
    deallocHashtableEntry(hte);
    return -2;
  }
  hte -> next = (ht -> table)[position].next;
  (ht -> table)[position].next = hte;
  (ht -> size) ++;
  return 1;
}

variable_types:
data
void *

variable_types: struct hashtableEntry_tag { void *key; void *data; struct hashtableEntry_tag *next; } *

variable_types: position int