decompiled_code:
void __fastcall hashtable_clear(__int64 a1)
{
if ( a1 && *(_QWORD *)(a1 + 16) )
{
if ( *(_DWORD *)(a1 + 12) )
{
hashtable_destroy(a1);
hashtable_init(a1);
}
}
}

original_code:
void hashtable_clear(hashtable_t *h){
    if (!h || !(h->table) || !(h->numItems))
        return;
    hashtable_destroy(h);
    hashtable_init(h);
}

canonical_original_code:
void hashtable_clear(struct _hashtable_t *h){
    if (!h || !(h->table) || !(h->numItems))
        return;
    hashtable_destroy(h);
    hashtable_init(h);
}


repo: vhmth/Lego-Box

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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0LL;
return result;
}

original_code:
int hashtable_size(hashtable_t *h){
    if (!h)
        return 0;
    return h->capacity;
}

canonical_original_code:
int hashtable_size(struct _hashtable_t *h){
    if (!h)
        return 0;
    return h->capacity;
}

variable_types: struct _hashtable_t { float MAX_ALPHA; float alpha; int capacity; int numItems; struct _node_t { char *key; void *value; struct _node_t *next; } **table; } *

return_type: int

user_defined_types: struct _hashtable_t { float MAX_ALPHA; float alpha; int capacity; int numItems; struct _node_t **table; }


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

if ( a1 )
result = *(unsigned int *)(a1 + 12);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 12);
else
result = 0LL;
return result;
}

original_code:
int hashtable_numelems(hashtable_t *h){
    if (!h)
        return 0;
    return h->numItems;
}

canonical_original_code:
int hashtable_numelems(struct _hashtable_t *h){
    if (!h)
        return 0;
    return h->numItems;
}

user_defined_types: struct _node_t { char *key; void *value; struct _node_t *next; }


decompiled_code:
__m64 __fastcall hashtable_loadfactor(_DWORD *a1)
{
__m64 result; // xmm0_8

if ( !a1 )
return 0LL;
*((_DWORD *)&result + 1) = 0;
*(float *)&result.m64_u64 = (float)(int)a1[3] / (float)(int)a1[2];
a1[1] = result.m64_i32[0];
return result;
}

canonical_decompiled_code:
__m64 __fastcall func16(_DWORD *a1)
{
__m64 result; // xmm0_8

if ( !a1 )
return 0LL;
*((_DWORD *)&result + 1) = 0;
*(float *)&result.m64_u64 = (float)(int)a1[3] / (float)(int)a1[2];
a1[1] = result.m64_i32[0];
return result;
}

original_code:
float hashtable_loadfactor(hashtable_t *h){
    if (!h)
        return 0;
    h->alpha = (float)h->numItems/(h->capacity);
    return h->alpha;
}

canonical_original_code:
float hashtable_loadfactor(struct _hashtable_t *h){
    if (!h)
        return 0;
    h->alpha = (float)h->numItems/(h->capacity);
    return h->alpha;
}

return_type: float


compare

decompiled_code:
_BOOL8 __fastcall compare(_DWORD *a1, _DWORD *a2)
{
return *a1 < *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_DWORD *a1, _DWORD *a2)
{
return *a1 < *a2;
}

original_code:
int compare(const void* a, const void* b){
    int* A = (int*)a;
    int* B = (int*)b;
    return *A < *B;
}

canonical_original_code:
int compare(void *a, void *b){
    int *A = (int*)a;
    int *B = (int*)b;
    return *A < *B;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
A
int *

variable_types:
B
int *


decompiled_code:
__int64 __fastcall swap_positions(__int64 a1, int a2, int a3)
{
__int64 v3; // rcx
__int64 *v4; // rax
__int64 v5; // rsi
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 8);
v4 = (__int64 *)(v3 + 8LL * a2);
v5 = *v4;
*v4 = *(_QWORD *)(v3 + 8LL * a3);
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 8LL * a3) = v5;
return result;
}

original_code:
void swap_positions(heap* h, int pos1, int pos2){
    void* temp = h->items[pos1];
    h->items[pos1] = h->items[pos2];
    h->items[pos2] = temp;
}

canonical_original_code:
void swap_positions(struct _heap *h, int pos1, int pos2){
    void *temp = h->items[pos1];
    h->items[pos1] = h->items[pos2];
    h->items[pos2] = temp;
}

variable_types: struct _heap { int (*compare)(void *, void *); void **items; int size; int capacity; } *

variable_types:
temp
void *

return_type: void


decompiled_code:
__int64 __fastcall heapify_up(__int64 a1, int a2)
{
unsigned int v2; // ebx
__int64 result; // rax

v2 = (a2 - 1) / 2;
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD))a1)(
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2),
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v2));
if ( (_DWORD)result )
{
swap_positions(a1, v2, a2);
result = heapify_up(a1, v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
unsigned int v2; // ebx
__int64 result; // rax

v2 = (a2 - 1) / 2;
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD))a1)(
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2),
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v2));
if ( (_DWORD)result )
{
func8(a1, v2, a2);
result = func9(a1, v2);
}
return result;
}

original_code:
void heapify_up(heap* h, int index){
    unsigned int parent_index = (index-1)/2;
    void* parent = h->items[parent_index];
    void* child = h->items[index];
    if(h->compare(child, parent)){
        swap_positions(h, parent_index, index);
        heapify_up(h, parent_index);
    }
}

canonical_original_code:
void heapify_up(struct _heap *h, int index){
    unsigned int parent_index = (index-1)/2;
    void *parent = h->items[parent_index];
    void *child = h->items[index];
    if(h->compare(child, parent)){
        swap_positions(h, parent_index, index);
        heapify_up(h, parent_index);
    }
}

variable_types: index int

variable_types:
parent
void *

variable_types:
child
void *

user_defined_types: struct _heap { int (*compare)(void *, void *); void **items; int size; int capacity; }


decompiled_code:
void __fastcall heapify_down(__int64 a1, int a2)
{
unsigned int v2; // er14
unsigned int v3; // ebp
unsigned int v4; // er13
__int64 v5; // rax
__int64 v6; // [rsp+8h] [rbp-50h]
__int64 v7; // [rsp+10h] [rbp-48h]
__int64 v8; // [rsp+18h] [rbp-40h]

v2 = 2 * a2 + 1;
v3 = 2 * a2 + 2;
v4 = *(_DWORD *)(a1 + 16);
if ( (v4 > v2 || v4 > v3) && v4 > v2 )
{
v5 = *(_QWORD *)(a1 + 8);
v6 = *(_QWORD *)(v5 + 8LL * v2);
v7 = *(_QWORD *)(v5 + 8LL * v3);
v8 = *(_QWORD *)(v5 + 8LL * a2);
if ( (*(unsigned int (__fastcall **)(__int64))a1)(v8) && v4 > v3 )
{
if ( !(*(unsigned int (__fastcall **)(__int64, __int64))a1)(v8, v7) )
{
LABEL_8:
if ( !(*(unsigned int (__fastcall **)(__int64, __int64))a1)(v6, v7) )
{
swap_positions(a1, a2, v3);
heapify_down(a1, v3);
return;
}
goto LABEL_14;
}
}
else
{
if ( v4 > v3 )
goto LABEL_8;
if ( (*(unsigned int (__fastcall **)(__int64, __int64))a1)(v6, v8) )
{
LABEL_14:
swap_positions(a1, a2, v2);
heapify_down(a1, v2);
return;
}
}
}
}

original_code:
void heapify_down(heap* h, int index){
    unsigned int left_index = 2*index + 1;
    unsigned int right_index = 2*index + 2;
    int has_left = left_index < h->size;
    int has_right = right_index < h->size;
    if(!has_left && !has_right)
        return;
    void* parent = h->items[index];
    void* left = h->items[left_index];
    void* right = h->items[right_index];
    if(has_left && h->compare(parent, left)
       && has_right && h->compare(parent, right)){
        return;
    }
    if(has_left && has_right){
        if(h->compare(left, right)){
            swap_positions(h, index, left_index);
            heapify_down(h, left_index);
        }
        else{
            swap_positions(h, index, right_index);
            heapify_down(h, right_index);
        }
    }
    else if(has_left){
        if(h->compare(left, parent)){
            swap_positions(h, index, left_index);
            heapify_down(h, left_index);
        }
    }
}

canonical_original_code:
void heapify_down(struct _heap *h, int index){
    unsigned int left_index = 2*index + 1;
    unsigned int right_index = 2*index + 2;
    int has_left = left_index < h->size;
    int has_right = right_index < h->size;
    if(!has_left && !has_right)
        return;
    void *parent = h->items[index];
    void *left = h->items[left_index];
    void *right = h->items[right_index];
    if(has_left && h->compare(parent, left)
       && has_right && h->compare(parent, right)){
        return;
    }
    if(has_left && has_right){
        if(h->compare(left, right)){
            swap_positions(h, index, left_index);
            heapify_down(h, left_index);
        }
        else{
            swap_positions(h, index, right_index);
            heapify_down(h, right_index);
        }
    }
    else if(has_left){
        if(h->compare(left, parent)){
            swap_positions(h, index, left_index);
            heapify_down(h, left_index);
        }
    }
}

variable_types:
left
void *

variable_types:
right
void *


decompiled_code:
void __fastcall build_heap(__int64 a1)
{
int v1; // ebx

v1 = *(_DWORD *)(a1 + 16) / 2;
if ( *(int *)(a1 + 16) >= -1 )
{
do
heapify_down(a1, v1--);
while ( v1 >= 0 );
}
}

original_code:
void build_heap(heap* h){
    int i;
    for(i=h->size/2; i >= 0; i--){
        heapify_down(h, i);
    }
}

canonical_original_code:
void build_heap(struct _heap *h){
    int i;
    for(i=h->size/2; i >= 0; i--){
        heapify_down(h, i);
    }
}

variable_types: i int


original_code:
void heap_init_with_items(heap* h, int(*compare)(const void *, const void *), void** items, int item_count){
    h->compare = compare;
    h->size = item_count;
    h->capacity = 16;
    while(h->capacity < item_count) h->capacity*=2;
    if(items != ((void *)0)) {
        h->items = malloc( h->capacity * sizeof(void*));
        int i;
        for(i=0; i < item_count; i++){
            h->items[i] = items[i];
        }
        build_heap(h);
    }
}

canonical_original_code:
void heap_init_with_items(struct _heap *h, int (*compare)(void *, void *), void **items, int item_count){
    h->compare = compare;
    h->size = item_count;
    h->capacity = 16;
    while(h->capacity < item_count) h->capacity*=2;
    if(items != ((void *)0)) {
        h->items = malloc( h->capacity * sizeof(void *));
        int i;
        for(i=0; i < item_count; i++){
            h->items[i] = items[i];
        }
        build_heap(h);
    }
}

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

variable_types:
items
void **


decompiled_code:
void *__fastcall heap_resize(__int64 a1)
{
int v1; // eax
void *result; // rax

v1 = *(_DWORD *)(a1 + 20);
*(_DWORD *)(a1 + 20) = 2 * v1;
result = realloc(*(void **)(a1 + 8), 16LL * v1);
*(_QWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func14(__int64 a1)
{
int v1; // eax
void *result; // rax

v1 = *(_DWORD *)(a1 + 20);
*(_DWORD *)(a1 + 20) = 2 * v1;
result = realloc(*(void **)(a1 + 8), 16LL * v1);
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
void heap_resize(heap* h){
    h->capacity *= 2;
    h->items = realloc(h->items, h->capacity * sizeof(void*));
}

canonical_original_code:
void heap_resize(struct _heap *h){
    h->capacity *= 2;
    h->items = realloc(h->items, h->capacity * sizeof(void *));
}


original_code:
void heap_insert(heap* h, void* item){
    if(h->size == h->capacity) heap_resize(h);
    h->size++;
    h->items[h->size-1] = item;
    heapify_up(h, h->size-1);
}

canonical_original_code:
void heap_insert(struct _heap *h, void *item){
    if(h->size == h->capacity) heap_resize(h);
    h->size++;
    h->items[h->size-1] = item;
    heapify_up(h, h->size-1);
}

variable_types:
item
void *


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

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

original_code:
void* heap_peek(heap* h){
    return h->items[0];
}

canonical_original_code:
void *heap_peek(struct _heap *h){
    return h->items[0];
}

return_type: void *


original_code:
void* heap_remove(heap* h){
    if(h->size == 0) return ((void *)0);
    void* top = h->items[0];
    h->size--;
    if(h->size > 0){
        h->items[0] = h->items[h->size];
        heapify_down(h, 0);
    }
    return top;
}

canonical_original_code:
void *heap_remove(struct _heap *h){
    if(h->size == 0) return ((void *)0);
    void *top = h->items[0];
    h->size--;
    if(h->size > 0){
        h->items[0] = h->items[h->size];
        heapify_down(h, 0);
    }
    return top;
}

variable_types:
top
void *


decompiled_code:
__int64 __fastcall heap_size(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int heap_size(heap* h){
    return h->size;
}

canonical_original_code:
int heap_size(struct _heap *h){
    return h->size;
}


decompiled_code:
void __fastcall heap_destroy(__int64 a1)
{
free(*(void **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func19(__int64 a1)
{
free(*(void **)(a1 + 8));
}

original_code:
void heap_destroy(heap* h){
    free(h->items);
}

canonical_original_code:
void heap_destroy(struct _heap *h){
    free(h->items);
}


original_code:
void heap_print(heap* h){
    int i;
    int nodes_for_level = 1;
    int node_at = 0;
    for(i=0; i < h->size; i++){
        printf("%d  ", *(int*)h->items[i]);
        node_at++;
        if(node_at == nodes_for_level){
            printf("\n");
            nodes_for_level *= 2;
            node_at = 0;
        }
    }
    if(node_at != 0) printf("\n");
    printf("\n");
}

canonical_original_code:
void heap_print(struct _heap *h){
    int i;
    int nodes_for_level = 1;
    int node_at = 0;
    for(i=0; i < h->size; i++){
        printf("%d  ", *(int *)h->items[i]);
        node_at++;
        if(node_at == nodes_for_level){
            printf("\n");
            nodes_for_level *= 2;
            node_at = 0;
        }
    }
    if(node_at != 0) printf("\n");
    printf("\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbp
__int64 i; // rbx
_DWORD *v5; // rax
int v6; // ebx
unsigned int *v7; // rax
unsigned int *v8; // rax
_QWORD *v9; // rbx
_QWORD *v10; // rbp
_BYTE v12[32]; // [rsp+0h] [rbp-78h] BYREF
int v13[22]; // [rsp+20h] [rbp-58h]

v13[0] = 20;
v13[1] = 15;
v13[2] = 12;
v13[3] = 22;
v13[4] = 30;
v13[5] = 10;
v13[6] = 8;
v13[7] = 42;
v13[8] = 50;
v13[9] = 19;
v13[10] = 1;
v13[11] = 0;
v13[12] = 45;
v3 = malloc(0x68uLL);
puts("Building heap of size 13 \n");
for ( i = 0LL; i != 13; ++i )
{
v5 = malloc(4uLL);
v3[i] = v5;
*v5 = v13[i];
}
heap_init_with_items(v12, compare, v3, 13LL);
heap_print(v12);
v6 = 4;
do
{
v7 = (unsigned int *)heap_remove(v12);
printf("Removed %d\n", *v7);
--v6;
}
while ( v6 );
putchar(10);
heap_print(v12);
while ( (int)heap_size(v12) > 0 )
{
v8 = (unsigned int *)heap_remove(v12);
printf("Removed %d\n", *v8);
}
heap_print(v12);
v9 = v3;
v10 = v3 + 13;
do
heap_insert(v12, *v9++);
while ( v9 != v10 );
heap_print(v12);
heap_destroy(v12);
return 0;
}

original_code:
int main(){
    int numbers[] = {20, 15, 12, 22, 30, 10, 8, 42, 50 , 19, 1, 0, 45};
    void** items = malloc(13*sizeof(int*));
    printf("Building heap of size 13 \n\n");
    int i;
    for(i=0; i < 13; i++){
        items[i] = malloc(sizeof(int));
        *(int*)items[i] = numbers[i];
    }
    heap h;
    heap_init_with_items(&h, compare, items, 13);
    heap_print(&h);
    int* top;
    for(i=0; i<4; i++){
        top = heap_remove(&h);
        printf("Removed %d\n", *top);
    }
    printf("\n");
    heap_print(&h);
    while(heap_size(&h) > 0){
        top = heap_remove(&h);
        printf("Removed %d\n", *top);
    }
    heap_print(&h);
    for(i=0; i<13; i++){
        heap_insert(&h, items[i]);
    }
    heap_print(&h);
    heap_destroy(&h);
 return 0;
}

canonical_original_code:
int main(){
    int numbers[] = {20, 15, 12, 22, 30, 10, 8, 42, 50 , 19, 1, 0, 45};
    void **items = malloc(13*sizeof(int*));
    printf("Building heap of size 13 \n\n");
    int i;
    for(i=0; i < 13; i++){
        items[i] = malloc(sizeof(int));
        *(int *)items[i] = numbers[i];
    }
    struct _heap h;
    heap_init_with_items(&h, compare, items, 13);
    heap_print(&h);
    int *top;
    for(i=0; i<4; i++){
        top = heap_remove(&h);
        printf("Removed %d\n", *top);
    }
    printf("\n");
    heap_print(&h);
    while(heap_size(&h) > 0){
        top = heap_remove(&h);
        printf("Removed %d\n", *top);
    }
    heap_print(&h);
    for(i=0; i<13; i++){
        heap_insert(&h, items[i]);
    }
    heap_print(&h);
    heap_destroy(&h);
 return 0;
}

variable_types:
numbers
int []

variable_types: struct _heap { int (*compare)(void *, void *); void **items; int size; int capacity; }

variable_types:
top
int *


decompiled_code:
void __fastcall single_ll_init(__int64 a1)
{
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void single_ll_init(single_ll *l){
    l->size = 0;
    l->head = ((void *)0);
}

canonical_original_code:
void single_ll_init(struct _single_ll *l){
    l->size = 0;
    l->head = ((void *)0);
}

variable_types: struct _single_ll { int size; struct _node_t { void *key; void *data; struct _node_t *next; } *head; } *

user_defined_types: struct _single_ll { int size; struct _node_t *head; }


original_code:
int single_ll_add(single_ll *l, void *key, void *data){
    if (!l || !key || !data)
        return 0;
    if (!(l->head)){
        l->head = (node_t*)malloc(sizeof(node_t));
        l->head->key = key;
        l->head->data = data;
        l->head->next = ((void *)0);
        (l->size)++;
        return 1;
    }
    node_t *stepper = l->head;
    while (stepper){
        if (stepper->key == key)
            return 0;
        if (!(stepper->next)){
            stepper->next = (node_t*)malloc(sizeof(node_t));
            stepper->next->key = key;
            stepper->next->data = data;
            (l->size)++;
            return 1;
        }
        stepper = stepper->next;
    }
    return 0;
}

canonical_original_code:
int single_ll_add(struct _single_ll *l, void *key, void *data){
    if (!l || !key || !data)
        return 0;
    if (!(l->head)){
        l->head = (struct _node_t *)malloc(sizeof(node_t));
        l->head->key = key;
        l->head->data = data;
        l->head->next = ((void *)0);
        (l->size)++;
        return 1;
    }
    struct _node_t *stepper = l->head;
    while (stepper){
        if (stepper->key == key)
            return 0;
        if (!(stepper->next)){
            stepper->next = (struct _node_t *)malloc(sizeof(node_t));
            stepper->next->key = key;
            stepper->next->data = data;
            (l->size)++;
            return 1;
        }
        stepper = stepper->next;
    }
    return 0;
}

variable_types:
key
void *

variable_types:
data
void *

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


decompiled_code:
__int64 __fastcall single_ll_get_at(__int64 a1, int a2)
{
__int64 v2; // rdx
int i; // eax

if ( !a1 || a2 < 0 )
return 0LL;
if ( *(_DWORD *)a1 <= a2 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
v2 = *(_QWORD *)(v2 + 16);
}
return *(_QWORD *)(v2 + 8);
}

original_code:
const void *single_ll_get_at(single_ll *l, int index){
    if (!l || (index < 0) || (index >= l->size))
        return ((void *)0);
    node_t *stepper = l->head;
    int i = 0;
    while (i < index){
        stepper = stepper->next;
        i++;
    }
    return stepper->data;
}

canonical_original_code:
void *single_ll_get_at(struct _single_ll *l, int index){
    if (!l || (index < 0) || (index >= l->size))
        return ((void *)0);
    struct _node_t *stepper = l->head;
    int i = 0;
    while (i < index){
        stepper = stepper->next;
        i++;
    }
    return stepper->data;
}

variable_types: index int

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


decompiled_code:
__int64 __fastcall single_ll_remove(__int64 a1, __int64 a2)
{
_QWORD *v3; // rdi
_QWORD *v4; // rax
__int64 result; // rax

if ( !a1 )
return 0LL;
v3 = *(_QWORD **)(a1 + 8);
if ( !a2 || !v3 )
return 0LL;
if ( *v3 == a2 )
{
*(_QWORD *)(a1 + 8) = v3[2];
--*(_DWORD *)a1;
free(v3);
result = 1LL;
}
else
{
while ( 1 )
{
v4 = v3;
v3 = (_QWORD *)v3[2];
if ( !v3 )
break;
if ( *v3 == a2 )
{
v4[2] = v3[2];
free(v3);
--*(_DWORD *)a1;
return 1LL;
}
}
result = 0LL;
}
return result;
}

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

if ( !a1 )
return 0LL;
v3 = *(_QWORD **)(a1 + 8);
if ( !a2 || !v3 )
return 0LL;
if ( *v3 == a2 )
{
*(_QWORD *)(a1 + 8) = v3[2];
--*(_DWORD *)a1;
free(v3);
result = 1LL;
}
else
{
while ( 1 )
{
v4 = v3;
v3 = (_QWORD *)v3[2];
if ( !v3 )
break;
if ( *v3 == a2 )
{
v4[2] = v3[2];
free(v3);
--*(_DWORD *)a1;
return 1LL;
}
}
result = 0LL;
}
return result;
}

original_code:
int single_ll_remove(single_ll *l, const void *key){
    if (!l || !(l->head) || !key)
        return 0;
    if (l->head->key == key){
        node_t *tmp = l->head;
        l->head = l->head->next;
        (l->size)--;
        free(tmp);
        return 1;
    }
    node_t *stepper = l->head;
    while (stepper->next){
        if (stepper->next->key == key){
            node_t *tmp = stepper->next;
            stepper->next = stepper->next->next;
            free(tmp);
            (l->size)--;
            return 1;
        }
        stepper = stepper->next;
    }
    return 0;
}

canonical_original_code:
int single_ll_remove(struct _single_ll *l, void *key){
    if (!l || !(l->head) || !key)
        return 0;
    if (l->head->key == key){
        struct _node_t *tmp = l->head;
        l->head = l->head->next;
        (l->size)--;
        free(tmp);
        return 1;
    }
    struct _node_t *stepper = l->head;
    while (stepper->next){
        if (stepper->next->key == key){
            struct _node_t *tmp = stepper->next;
            stepper->next = stepper->next->next;
            free(tmp);
            (l->size)--;
            return 1;
        }
        stepper = stepper->next;
    }
    return 0;
}


original_code:
int single_ll_remove_at(single_ll *l, int index){
    if (!l || (index < 0) || (index >= l->size))
        return 0;
    if (index == 0){
        node_t *tmp = l->head;
        l->head = l->head->next;
        free(tmp);
        (l->size)--;
        return 1;
    }
    node_t *stepper = l->head;
    int i = 0;
    while (i < (index-1)){
        stepper = stepper->next;
        i++;
    }
    node_t *tmp = stepper->next;
    stepper->next = stepper->next->next;
    free(tmp);
    (l->size)--;
    return 1;
}

canonical_original_code:
int single_ll_remove_at(struct _single_ll *l, int index){
    if (!l || (index < 0) || (index >= l->size))
        return 0;
    if (index == 0){
        struct _node_t *tmp = l->head;
        l->head = l->head->next;
        free(tmp);
        (l->size)--;
        return 1;
    }
    struct _node_t *stepper = l->head;
    int i = 0;
    while (i < (index-1)){
        stepper = stepper->next;
        i++;
    }
    struct _node_t *tmp = stepper->next;
    stepper->next = stepper->next->next;
    free(tmp);
    (l->size)--;
    return 1;
}


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

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

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

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

original_code:
int single_ll_size(single_ll *l){
    if (!l)
        return 0;
    return l->size;
}

canonical_original_code:
int single_ll_size(struct _single_ll *l){
    if (!l)
        return 0;
    return l->size;
}


decompiled_code:
_BOOL8 __fastcall single_ll_empty(_DWORD *a1)
{
_BOOL8 result; // rax

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

canonical_decompiled_code:
_BOOL8 __fastcall func13(_DWORD *a1)
{
_BOOL8 result; // rax

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

original_code:
int single_ll_empty(single_ll *l){
    if (!l)
        return 1;
    return (l->size == 0);
}

canonical_original_code:
int single_ll_empty(struct _single_ll *l){
    if (!l)
        return 1;
    return (l->size == 0);
}


original_code:
void single_ll_print(single_ll *l){
    if (!l)
        return;
    int i;
    node_t *stepper = l->head;
    for (i = 0; i < l->size; i++){
        if (i != (l->size -1))
            printf("(%s, %s)  ", (char *)stepper->key, (char *)stepper->data);
        else
            printf("(%s, %s)\n", (char *)stepper->key, (char *)stepper->data);
        stepper = stepper->next;
    }
}

canonical_original_code:
void single_ll_print(struct _single_ll *l){
    if (!l)
        return;
    int i;
    struct _node_t *stepper = l->head;
    for (i = 0; i < l->size; i++){
        if (i != (l->size -1))
            printf("(%s, %s)  ", (char *)stepper->key, (char *)stepper->data);
        else
            printf("(%s, %s)\n", (char *)stepper->key, (char *)stepper->data);
        stepper = stepper->next;
    }
}


decompiled_code:
void __fastcall single_ll_destroy(__int64 a1)
{
_QWORD *v2; // rbx
void *v3; // rdi

if ( a1 )
{
v2 = *(_QWORD **)(a1 + 8);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)a1 = 0;
}
}

original_code:
void single_ll_destroy(single_ll *l){
    if (!l)
        return;
    node_t *stepper = l->head;
    while(stepper){
        node_t *tmp = stepper->next;
        free(stepper);
        stepper = tmp;
    }
    l->head = ((void *)0);
    l->size = 0;
}

canonical_original_code:
void single_ll_destroy(struct _single_ll *l){
    if (!l)
        return;
    struct _node_t *stepper = l->head;
    while(stepper){
        struct _node_t *tmp = stepper->next;
        free(stepper);
        stepper = tmp;
    }
    l->head = ((void *)0);
    l->size = 0;
}


decompiled_code:
void __fastcall bintree_makenode(_QWORD *a1, __int64 a2, __int64 a3)
{
if ( a2 && a3 )
{
if ( !a1 )
a1 = malloc(0x20uLL);
*a1 = a2;
a1[1] = a3;
a1[3] = 0LL;
a1[2] = 0LL;
}
}

original_code:
void bintree_makenode(tree_node_t *n, void *key, void *value){
    if (!key || !value)
        return;
    if (!n)
        n = (tree_node_t *)malloc(sizeof(tree_node_t));
    n->key = key;
    n->value = value;
    n->right = ((void *)0);
    n->left = ((void *)0);
}

canonical_original_code:
void bintree_makenode(struct _tree_node_t *n, void *key, void *value){
    if (!key || !value)
        return;
    if (!n)
        n = (struct _tree_node_t *)malloc(sizeof(tree_node_t));
    n->key = key;
    n->value = value;
    n->right = ((void *)0);
    n->left = ((void *)0);
}

variable_types: struct _tree_node_t { void *key; void *value; struct _tree_node_t *left; struct _tree_node_t *right; } *

variable_types:
value
void *


decompiled_code:
__int64 __fastcall bintree_getrealheight(__int64 a1)
{
int v1; // ebp
int v2; // eax
unsigned int v3; // edx
bool v4; // cc
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = bintree_getrealheight(*(_QWORD *)(a1 + 16));
v2 = bintree_getrealheight(*(_QWORD *)(a1 + 24));
v3 = v2 + 1;
v4 = v1 <= v2;
result = (unsigned int)(v1 + 1);
if ( v4 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // ebp
int v2; // eax
unsigned int v3; // edx
bool v4; // cc
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = func1(*(_QWORD *)(a1 + 16));
v2 = func1(*(_QWORD *)(a1 + 24));
v3 = v2 + 1;
v4 = v1 <= v2;
result = (unsigned int)(v1 + 1);
if ( v4 )
result = v3;
return result;
}

original_code:
int bintree_getrealheight(tree_node_t *n){
    if (!n)
        return -1;
    int left = bintree_getrealheight(n->left);
    int right = bintree_getrealheight(n->right);
    if (left > right)
        return left + 1;
    return right + 1;
}

canonical_original_code:
int bintree_getrealheight(struct _tree_node_t *n){
    if (!n)
        return -1;
    int left = bintree_getrealheight(n->left);
    int right = bintree_getrealheight(n->right);
    if (left > right)
        return left + 1;
    return right + 1;
}

variable_types: left int

variable_types: right int

user_defined_types: struct _tree_node_t { void *key; void *value; struct _tree_node_t *left; struct _tree_node_t *right; }


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

result = a1;
if ( a1 )
{
if ( *(_QWORD *)(a1 + 24) )
result = bintree_inorderpred();
}
return result;
}

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

result = a1;
if ( a1 )
{
if ( *(_QWORD *)(a1 + 24) )
result = func2();
}
return result;
}

original_code:
tree_node_t *bintree_inorderpred(tree_node_t *n){
    if (!n || !(n->right))
        return n;
    return bintree_inorderpred(n->right);
}

canonical_original_code:
struct _tree_node_t *bintree_inorderpred(struct _tree_node_t *n){
    if (!n || !(n->right))
        return n;
    return bintree_inorderpred(n->right);
}

variable_types:
n
struct _tree_node_t *

return_type: struct _tree_node_t { void *key; void *value; struct _tree_node_t *left; struct _tree_node_t *right; } *


original_code:
void bintree_init(bintree_t *b, int(*comparer)(const void *, const void *)){
    if (!b || !comparer)
        return;
    b->root = ((void *)0);
    b->height = -1;
    b->compare = comparer;
}

canonical_original_code:
void bintree_init(struct _bintree_t *b, int (*comparer)(void *, void *)){
    if (!b || !comparer)
        return;
    b->root = ((void *)0);
    b->height = -1;
    b->compare = comparer;
}

variable_types: struct _bintree_t { struct _tree_node_t { void *key; void *value; struct _tree_node_t *left; struct _tree_node_t *right; } *root; int height; int (*compare)(void *, void *); } *

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

user_defined_types: struct _bintree_t { struct _tree_node_t *root; int height; int (*compare)(void *, void *); }


decompiled_code:
__int64 __fastcall bintree_insert(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rbx
int v5; // ebp
_QWORD *v6; // rax
__int64 result; // rax
_QWORD *v8; // rax
_QWORD *v9; // rcx
_QWORD *v10; // rax

if ( a3 == 0 || a2 == 0 || !a1 )
return 0LL;
v4 = *(_QWORD **)a1;
v5 = 0;
if ( *(_QWORD *)a1 )
{
while ( 1 )
{
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(a1 + 16))(a2, *v4);
if ( !(_DWORD)result )
break;
if ( (int)result < 0 && !v4[2] )
{
v8 = malloc(0x20uLL);
v4[2] = v8;
bintree_makenode(v8, a2, a3);
result = 1LL;
if ( *(_DWORD *)(a1 + 8) == v5 )
*(_DWORD *)(a1 + 8) = v5 + 1;
return result;
}
v9 = (_QWORD *)v4[3];
if ( (int)result > 0 && !v9 )
{
v10 = malloc(0x20uLL);
v4[3] = v10;
bintree_makenode(v10, a2, a3);
result = 1LL;
if ( *(_DWORD *)(a1 + 8) == v5 )
*(_DWORD *)(a1 + 8) = v5 + 1;
return result;
}
if ( (int)result < 0 )
v9 = (_QWORD *)v4[2];
v4 = v9;
++v5;
if ( !v9 )
return 0LL;
}
}
else
{
v6 = malloc(0x20uLL);
*(_QWORD *)a1 = v6;
bintree_makenode(v6, a2, a3);
*(_DWORD *)(a1 + 8) = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rbx
int v5; // ebp
_QWORD *v6; // rax
__int64 result; // rax
_QWORD *v8; // rax
_QWORD *v9; // rcx
_QWORD *v10; // rax

if ( a3 == 0 || a2 == 0 || !a1 )
return 0LL;
v4 = *(_QWORD **)a1;
v5 = 0;
if ( *(_QWORD *)a1 )
{
while ( 1 )
{
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(a1 + 16))(a2, *v4);
if ( !(_DWORD)result )
break;
if ( (int)result < 0 && !v4[2] )
{
v8 = malloc(0x20uLL);
v4[2] = v8;
func0(v8, a2, a3);
result = 1LL;
if ( *(_DWORD *)(a1 + 8) == v5 )
*(_DWORD *)(a1 + 8) = v5 + 1;
return result;
}
v9 = (_QWORD *)v4[3];
if ( (int)result > 0 && !v9 )
{
v10 = malloc(0x20uLL);
v4[3] = v10;
func0(v10, a2, a3);
result = 1LL;
if ( *(_DWORD *)(a1 + 8) == v5 )
*(_DWORD *)(a1 + 8) = v5 + 1;
return result;
}
if ( (int)result < 0 )
v9 = (_QWORD *)v4[2];
v4 = v9;
++v5;
if ( !v9 )
return 0LL;
}
}
else
{
v6 = malloc(0x20uLL);
*(_QWORD *)a1 = v6;
func0(v6, a2, a3);
*(_DWORD *)(a1 + 8) = 0;
result = 1LL;
}
return result;
}

original_code:
int bintree_insert(bintree_t *b, void *key, void *value){
    if (!b || !key || !value)
        return 0;
    if (!(b->root)){
        b->root = (tree_node_t *)malloc(sizeof(tree_node_t));
        bintree_makenode(b->root, key, value);
        b->height = 0;
        return 1;
    }
    int currHeight = 0;
    tree_node_t *stepper = b->root;
    while (stepper){
        int comp = b->compare(key, stepper->key);
        if (comp == 0)
            return 0;
        if (!(stepper->left) && (comp < 0)){
            stepper->left = (tree_node_t *)malloc(sizeof(tree_node_t));
            bintree_makenode(stepper->left, key, value);
            if (currHeight == b->height)
                (b->height)++;
            return 1;
        }
        if (!(stepper->right) && (comp > 0)){
            stepper->right = (tree_node_t *)malloc(sizeof(tree_node_t));
            bintree_makenode(stepper->right, key, value);
            if (currHeight == b->height)
                (b->height)++;
            return 1;
        }
        if (comp < 0)
            stepper = stepper->left;
        else
            stepper = stepper->right;
        currHeight++;
    }
    return 0;
}

canonical_original_code:
int bintree_insert(struct _bintree_t *b, void *key, void *value){
    if (!b || !key || !value)
        return 0;
    if (!(b->root)){
        b->root = (struct _tree_node_t *)malloc(sizeof(tree_node_t));
        bintree_makenode(b->root, key, value);
        b->height = 0;
        return 1;
    }
    int currHeight = 0;
    struct _tree_node_t *stepper = b->root;
    while (stepper){
        int comp = b->compare(key, stepper->key);
        if (comp == 0)
            return 0;
        if (!(stepper->left) && (comp < 0)){
            stepper->left = (struct _tree_node_t *)malloc(sizeof(tree_node_t));
            bintree_makenode(stepper->left, key, value);
            if (currHeight == b->height)
                (b->height)++;
            return 1;
        }
        if (!(stepper->right) && (comp > 0)){
            stepper->right = (struct _tree_node_t *)malloc(sizeof(tree_node_t));
            bintree_makenode(stepper->right, key, value);
            if (currHeight == b->height)
                (b->height)++;
            return 1;
        }
        if (comp < 0)
            stepper = stepper->left;
        else
            stepper = stepper->right;
        currHeight++;
    }
    return 0;
}

variable_types: currHeight int

variable_types: comp int


original_code:
int bintree_remove(bintree_t *b, const void *key){
    if (!b || !key)
        return 0;
    tree_node_t *stepper = b->root;
    while (stepper) {
        int comp = b->compare(key, stepper->key);
        if (comp == 0){
            if ( (!(stepper->left) && stepper->right) ||
                 (stepper->left && !(stepper->right)) ){
                if (stepper->left){
                    tree_node_t *tmp = stepper->left;
                    stepper->key = stepper->left->key;
                    stepper->value = stepper->left->value;
                    stepper->right = stepper->left->right;
                    stepper->left = stepper->left->left;
                    free(tmp);
                } else {
                    tree_node_t *tmp = stepper->right;
                    stepper->key = stepper->right->key;
                    stepper->value = stepper->right->value;
                    stepper->left = stepper->right->left;
                    stepper->right = stepper->right->right;
                    free(tmp);
                }
            } else if (!(stepper->left) && !(stepper->right)) {
                tree_node_t *parent = bintree_getparent(b, stepper);
                if (!parent)
                    b->root = ((void *)0);
                else {
                    if (parent->left == stepper)
                        parent->left = ((void *)0);
                    else
                        parent->right = ((void *)0);
                }
                free(stepper);
            } else {
                tree_node_t *iop = bintree_inorderpred(stepper->left);
                if (iop == stepper->left){
                    stepper->key = iop->key;
                    stepper->value = iop->value;
                    stepper->left = iop->left;
                    free(iop);
                } else {
                    stepper->key = iop->key;
                    stepper->value = iop->value;
                    if (iop->left){
                        tree_node_t *tmp = iop->left;
                        iop->key = iop->left->key;
                        iop->value = iop->left->value;
                        iop->right = iop->left->right;
                        iop->left = iop->left->left;
                        free(tmp);
                    } else {
                        tree_node_t *iopparent = bintree_getparent(b, iop);
                        iopparent->right = ((void *)0);
                        free(iop);
                    }
                }
            }
            b->height = bintree_getrealheight(b->root);
            return 1;
        }
        if (comp < 0)
            stepper = stepper->left;
        else
            stepper = stepper->right;
    }
    return 0;
}

canonical_original_code:
int bintree_remove(struct _bintree_t *b, void *key){
    if (!b || !key)
        return 0;
    struct _tree_node_t *stepper = b->root;
    while (stepper) {
        int comp = b->compare(key, stepper->key);
        if (comp == 0){
            if ( (!(stepper->left) && stepper->right) ||
                 (stepper->left && !(stepper->right)) ){
                if (stepper->left){
                    struct _tree_node_t *tmp = stepper->left;
                    stepper->key = stepper->left->key;
                    stepper->value = stepper->left->value;
                    stepper->right = stepper->left->right;
                    stepper->left = stepper->left->left;
                    free(tmp);
                } else {
                    struct _tree_node_t *tmp = stepper->right;
                    stepper->key = stepper->right->key;
                    stepper->value = stepper->right->value;
                    stepper->left = stepper->right->left;
                    stepper->right = stepper->right->right;
                    free(tmp);
                }
            } else if (!(stepper->left) && !(stepper->right)) {
                struct _tree_node_t *parent = bintree_getparent(b, stepper);
                if (!parent)
                    b->root = ((void *)0);
                else {
                    if (parent->left == stepper)
                        parent->left = ((void *)0);
                    else
                        parent->right = ((void *)0);
                }
                free(stepper);
            } else {
                struct _tree_node_t *iop = bintree_inorderpred(stepper->left);
                if (iop == stepper->left){
                    stepper->key = iop->key;
                    stepper->value = iop->value;
                    stepper->left = iop->left;
                    free(iop);
                } else {
                    stepper->key = iop->key;
                    stepper->value = iop->value;
                    if (iop->left){
                        struct _tree_node_t *tmp = iop->left;
                        iop->key = iop->left->key;
                        iop->value = iop->left->value;
                        iop->right = iop->left->right;
                        iop->left = iop->left->left;
                        free(tmp);
                    } else {
                        struct _tree_node_t *iopparent = bintree_getparent(b, iop);
                        iopparent->right = ((void *)0);
                        free(iop);
                    }
                }
            }
            b->height = bintree_getrealheight(b->root);
            return 1;
        }
        if (comp < 0)
            stepper = stepper->left;
        else
            stepper = stepper->right;
    }
    return 0;
}


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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int bintree_height(bintree_t *b){
    if (!b)
        return -1;
    return b->height;
}

canonical_original_code:
int bintree_height(struct _bintree_t *b){
    if (!b)
        return -1;
    return b->height;
}


decompiled_code:
void __fastcall bintree_print(_QWORD *a1)
{
unsigned int v1; // ebp
const char **v2; // rbx
const char *v3; // rsi
const char *v4; // rsi
const char **v5; // rbx
const char *v6; // rsi
const char *v7; // rsi
_BYTE v8[48]; // [rsp-30h] [rbp-78h] BYREF
char v9[72]; // [rsp+0h] [rbp-48h] BYREF

if ( a1 && *a1 )
{
queue_init(v9);
queue_init(v8);
queue_enqueue(v9, *a1);
v1 = 0;
while ( !(unsigned int)queue_empty(v9) || !(unsigned int)queue_empty(v8) )
{
if ( !(unsigned int)queue_empty(v9) )
printf("Level %d: ", v1);
while ( !(unsigned int)queue_empty(v9) )
{
v2 = (const char **)queue_dequeue(v9);
v3 = v2[2];
if ( v3 )
queue_enqueue(v8, v3);
v4 = v2[3];
if ( v4 )
queue_enqueue(v8, v4);
if ( (unsigned int)queue_empty(v9) )
{
++v1;
printf("(%s, %s)\n", *v2, v2[1]);
}
else
{
printf("(%s, %s) ", *v2, v2[1]);
}
}
if ( !(unsigned int)queue_empty(v8) )
printf("Level %d: ", v1);
while ( !(unsigned int)queue_empty(v8) )
{
v5 = (const char **)queue_dequeue(v8);
v6 = v5[2];
if ( v6 )
queue_enqueue(v9, v6);
v7 = v5[3];
if ( v7 )
queue_enqueue(v9, v7);
if ( (unsigned int)queue_empty(v8) )
{
++v1;
printf("(%s, %s)\n", *v5, v5[1]);
}
else
{
printf("(%s, %s) ", *v5, v5[1]);
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func7(_QWORD *a1)
{
unsigned int v1; // ebp
const char **v2; // rbx
const char *v3; // rsi
const char *v4; // rsi
const char **v5; // rbx
const char *v6; // rsi
const char *v7; // rsi
_BYTE v8[48]; // [rsp-30h] [rbp-78h] BYREF
char v9[72]; // [rsp+0h] [rbp-48h] BYREF

if ( a1 && *a1 )
{
queue_init(v9);
queue_init(v8);
queue_enqueue(v9, *a1);
v1 = 0;
while ( !(unsigned int)queue_empty(v9) || !(unsigned int)queue_empty(v8) )
{
if ( !(unsigned int)queue_empty(v9) )
printf("Level %d: ", v1);
while ( !(unsigned int)queue_empty(v9) )
{
v2 = (const char **)queue_dequeue(v9);
v3 = v2[2];
if ( v3 )
queue_enqueue(v8, v3);
v4 = v2[3];
if ( v4 )
queue_enqueue(v8, v4);
if ( (unsigned int)queue_empty(v9) )
{
++v1;
printf("(%s, %s)\n", *v2, v2[1]);
}
else
{
printf("(%s, %s) ", *v2, v2[1]);
}
}
if ( !(unsigned int)queue_empty(v8) )
printf("Level %d: ", v1);
while ( !(unsigned int)queue_empty(v8) )
{
v5 = (const char **)queue_dequeue(v8);
v6 = v5[2];
if ( v6 )
queue_enqueue(v9, v6);
v7 = v5[3];
if ( v7 )
queue_enqueue(v9, v7);
if ( (unsigned int)queue_empty(v8) )
{
++v1;
printf("(%s, %s)\n", *v5, v5[1]);
}
else
{
printf("(%s, %s) ", *v5, v5[1]);
}
}
}
}
}

original_code:
void bintree_print(bintree_t *b){
    if (!b || !(b->root))
        return;
    queue_t q1, q2;
    queue_init(&q1);
    queue_init(&q2);
    int level = 0;
    queue_enqueue(&q1, b->root);
    while (!queue_empty(&q1) || !queue_empty(&q2)){
        if (!queue_empty(&q1))
            printf("Level %d: ", level);
        while (!queue_empty(&q1)){
            tree_node_t *tmp = queue_dequeue(&q1);
            if (tmp->left)
                queue_enqueue(&q2, tmp->left);
            if (tmp->right)
                queue_enqueue(&q2, tmp->right);
            if (queue_empty(&q1)){
                level++;
                printf("(%s, %s)\n", (char *)tmp->key, (char *)tmp->value);
            } else
                printf("(%s, %s) ", (char *)tmp->key, (char *)tmp->value);
        }
        if (!queue_empty(&q2))
            printf("Level %d: ", level);
        while (!queue_empty(&q2)){
            tree_node_t *tmp = queue_dequeue(&q2);
            if (tmp->left)
                queue_enqueue(&q1, tmp->left);
            if (tmp->right)
                queue_enqueue(&q1, tmp->right);
            if (queue_empty(&q2)){
                level++;
                printf("(%s, %s)\n", (char *)tmp->key, (char *)tmp->value);
            } else
                printf("(%s, %s) ", (char *)tmp->key, (char *)tmp->value);
        }
    }
}

canonical_original_code:
void bintree_print(struct _bintree_t *b){
    if (!b || !(b->root))
        return;
    struct _queue_t q1; struct _queue_t q2;
    queue_init(&q1);
    queue_init(&q2);
    int level = 0;
    queue_enqueue(&q1, b->root);
    while (!queue_empty(&q1) || !queue_empty(&q2)){
        if (!queue_empty(&q1))
            printf("Level %d: ", level);
        while (!queue_empty(&q1)){
            struct _tree_node_t *tmp = queue_dequeue(&q1);
            if (tmp->left)
                queue_enqueue(&q2, tmp->left);
            if (tmp->right)
                queue_enqueue(&q2, tmp->right);
            if (queue_empty(&q1)){
                level++;
                printf("(%s, %s)\n", (char *)tmp->key, (char *)tmp->value);
            } else
                printf("(%s, %s) ", (char *)tmp->key, (char *)tmp->value);
        }
        if (!queue_empty(&q2))
            printf("Level %d: ", level);
        while (!queue_empty(&q2)){
            struct _tree_node_t *tmp = queue_dequeue(&q2);
            if (tmp->left)
                queue_enqueue(&q1, tmp->left);
            if (tmp->right)
                queue_enqueue(&q1, tmp->right);
            if (queue_empty(&q2)){
                level++;
                printf("(%s, %s)\n", (char *)tmp->key, (char *)tmp->value);
            } else
                printf("(%s, %s) ", (char *)tmp->key, (char *)tmp->value);
        }
    }
}

variable_types: struct _queue_t { struct _stack { void **items; int size; int capacity; } in; int size; }

variable_types: level int

user_defined_types: struct _queue_t { struct _stack in; int size; }


decompiled_code:
void __fastcall bintree_destroy_helper(_QWORD *a1)
{
if ( a1 )
{
if ( a1[2] )
bintree_destroy_helper();
if ( a1[3] )
bintree_destroy_helper();
free(a1);
}
}

canonical_decompiled_code:
void __fastcall func8(_QWORD *a1)
{
if ( a1 )
{
if ( a1[2] )
func8();
if ( a1[3] )
func8();
free(a1);
}
}

original_code:
void bintree_destroy_helper(tree_node_t *curr){
    if (!curr)
        return;
    if (curr->left)
        bintree_destroy_helper(curr->left);
    if (curr->right)
        bintree_destroy_helper(curr->right);
    free(curr);
}

canonical_original_code:
void bintree_destroy_helper(struct _tree_node_t *curr){
    if (!curr)
        return;
    if (curr->left)
        bintree_destroy_helper(curr->left);
    if (curr->right)
        bintree_destroy_helper(curr->right);
    free(curr);
}


decompiled_code:
void __fastcall bintree_destroy(_QWORD **a1)
{
_QWORD *v1; // rdi

if ( a1 )
{
v1 = *a1;
if ( v1 )
bintree_destroy_helper(v1);
}
}

canonical_decompiled_code:
void __fastcall func9(_QWORD **a1)
{
_QWORD *v1; // rdi

if ( a1 )
{
v1 = *a1;
if ( v1 )
func8(v1);
}
}

original_code:
void bintree_destroy(bintree_t *b){
    if (!b || !(b->root))
        return;
    bintree_destroy_helper(b->root);
}

canonical_original_code:
void bintree_destroy(struct _bintree_t *b){
    if (!b || !(b->root))
        return;
    bintree_destroy_helper(b->root);
}


comparer

decompiled_code:
int __fastcall comparer(const char *a1, const char *a2)
{
return strcmp(a1, a2);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, const char *a2)
{
return strcmp(a1, a2);
}

original_code:
int comparer(const void *a, const void *b){
    return strcmp((char *)a, (char *)b);
}

canonical_original_code:
int comparer(void *a, void *b){
    return strcmp((char *)a, (char *)b);
}

variable_types:
a
void *

variable_types:
b
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
_BYTE v8[40]; // [rsp+0h] [rbp-28h] BYREF

bintree_init(v8, comparer, envp);
bintree_insert(v8, "key 2", "value 1");
bintree_insert(v8, "key 1", "value 2");
bintree_insert(v8, "key 3", "value 3");
bintree_insert(v8, "key 4", "value 4");
bintree_insert(v8, "key 0", "value 5");
bintree_insert(v8, "key 9", "value 6");
bintree_print(v8);
bintree_remove(v8, "key 9");
bintree_remove(v8, "key 0");
puts("After removing 'key 9' and 'key 0':");
bintree_print(v8);
bintree_remove(v8, "key 2");
puts("After removing the root (key 2):");
bintree_print(v8);
v3 = bintree_height(v8);
printf("Height of tree: %d\n", v3);
v4 = (const char *)bintree_find(v8, "key 1");
printf("value of 'key 1': %s\n", v4);
v5 = (const char *)bintree_find(v8, "key 3");
printf("value of 'key 3': %s\n", v5);
v6 = (const char *)bintree_find(v8, "key 4");
printf("value of 'key 4': %s\n", v6);
bintree_destroy(v8);
return 0;
}

original_code:
int main() {
    bintree_t testBT;
    bintree_init(&testBT, &comparer);
    bintree_insert(&testBT, "key 2", "value 1");
    bintree_insert(&testBT, "key 1", "value 2");
    bintree_insert(&testBT, "key 3", "value 3");
    bintree_insert(&testBT, "key 4", "value 4");
    bintree_insert(&testBT, "key 0", "value 5");
    bintree_insert(&testBT, "key 9", "value 6");
    bintree_print(&testBT);
    bintree_remove(&testBT, "key 9");
    bintree_remove(&testBT, "key 0");
    printf("After removing 'key 9' and 'key 0':\n");
    bintree_print(&testBT);
    bintree_remove(&testBT, "key 2");
    printf("After removing the root (key 2):\n");
    bintree_print(&testBT);
    printf("Height of tree: %d\n", bintree_height(&testBT));
    printf("value of 'key 1': %s\n", (char *)bintree_find(&testBT, "key 1"));
    printf("value of 'key 3': %s\n", (char *)bintree_find(&testBT, "key 3"));
    printf("value of 'key 4': %s\n", (char *)bintree_find(&testBT, "key 4"));
    bintree_destroy(&testBT);
    return 0;
}

canonical_original_code:
int main() {
    struct _bintree_t testBT;
    bintree_init(&testBT, &comparer);
    bintree_insert(&testBT, "key 2", "value 1");
    bintree_insert(&testBT, "key 1", "value 2");
    bintree_insert(&testBT, "key 3", "value 3");
    bintree_insert(&testBT, "key 4", "value 4");
    bintree_insert(&testBT, "key 0", "value 5");
    bintree_insert(&testBT, "key 9", "value 6");
    bintree_print(&testBT);
    bintree_remove(&testBT, "key 9");
    bintree_remove(&testBT, "key 0");
    printf("After removing 'key 9' and 'key 0':\n");
    bintree_print(&testBT);
    bintree_remove(&testBT, "key 2");
    printf("After removing the root (key 2):\n");
    bintree_print(&testBT);
    printf("Height of tree: %d\n", bintree_height(&testBT));
    printf("value of 'key 1': %s\n", (char *)bintree_find(&testBT, "key 1"));
    printf("value of 'key 3': %s\n", (char *)bintree_find(&testBT, "key 3"));
    printf("value of 'key 4': %s\n", (char *)bintree_find(&testBT, "key 4"));
    bintree_destroy(&testBT);
    return 0;
}

variable_types: struct _bintree_t { struct _tree_node_t { void *key; void *value; struct _tree_node_t *left; struct _tree_node_t *right; } *root; int height; int (*compare)(void *, void *); }


repo: vianney/tmux-applet

decompiled_code:
int __fastcall print_size(unsigned __int64 a1, unsigned int a2)
{
__int64 v2; // rdx

if ( a2 > 4 )
__assert_fail("magnitude >= 0 && magnitude <= 4", "tmux-applet.c", 0x4Du, "print_size");
if ( a2 == 4 || a1 <= 0x3FF )
return printf("#[bright]%llu#[nobright]%c", a1, (unsigned int)SIZE_SUFFIXES[a2]);
if ( a1 > 0x27FF )
return print_size(a1 >> 10, a2 + 1);
v2 = (0x3E22CBCE4A9027C5LL * (unsigned __int128)(a1 & 0x3FF)) >> 64;
return printf(
"#[bright]%llu.%llu#[nobright]%c",
a1 >> 10,
((((a1 & 0x3FF) - v2) >> 1) + v2) >> 6,
(unsigned int)SIZE_SUFFIXES[a2 + 1]);
}

canonical_decompiled_code:
int __fastcall func7(unsigned __int64 a1, unsigned int a2)
{
__int64 v2; // rdx

if ( a2 > 4 )
__assert_fail("magnitude >= 0 && magnitude <= 4", "tmux-applet.c", 0x4Du, "print_size");
if ( a2 == 4 || a1 <= 0x3FF )
return printf("#[bright]%llu#[nobright]%c", a1, (unsigned int)SIZE_SUFFIXES[a2]);
if ( a1 > 0x27FF )
return func7(a1 >> 10, a2 + 1);
v2 = (0x3E22CBCE4A9027C5LL * (unsigned __int128)(a1 & 0x3FF)) >> 64;
return printf(
"#[bright]%llu.%llu#[nobright]%c",
a1 >> 10,
((((a1 & 0x3FF) - v2) >> 1) + v2) >> 6,
(unsigned int)SIZE_SUFFIXES[a2 + 1]);
}

original_code:
void print_size(unsigned long long size, int magnitude) {
    ((void) sizeof ((magnitude >= 0 && magnitude <= 4) ? 1 : 0), __extension__ ({ if (magnitude >= 0 && magnitude <= 4) ; else __assert_fail ("magnitude >= 0 && magnitude <= 4", "tmux-applet.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    if(magnitude == 4 || size < 1024) {
        printf("#[bright]%llu#[nobright]%c", size, SIZE_SUFFIXES[magnitude]);
    } else if(size < 10*1024) {
        printf("#[bright]%llu.%llu#[nobright]%c", size >> 10, (size & 1023) / 103,
                              SIZE_SUFFIXES[magnitude+1]);
    } else {
        print_size(size >> 10, magnitude + 1);
    }
}

variable_types:
size
unsigned long long

variable_types: magnitude int


decompiled_code:
int __fastcall begin_applet(const char *a1, const char *a2)
{
const char *v2; // rbx

v2 = a1;
if ( !*a1 )
v2 = a2;
if ( nbApplets )
printf(" ");
return printf("#[bright,%s]", v2);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, const char *a2)
{
const char *v2; // rbx

v2 = a1;
if ( !*a1 )
v2 = a2;
if ( nbApplets )
printf(" ");
return printf("#[bright,%s]", v2);
}

original_code:
void begin_applet(const char* attr, const char* defattr) {
    if(attr[0] == '\0')
        attr = defattr;
    if(nbApplets != 0)
        printf("  ");
    printf("#[bright,%s]", attr);
}

canonical_original_code:
void begin_applet(char *attr, char *defattr) {
    if(attr[0] == '\0')
        attr = defattr;
    if(nbApplets != 0)
        printf("  ");
    printf("#[bright,%s]", attr);
}

variable_types:
attr
char *

variable_types:
defattr
char *


decompiled_code:
int end_applet()
{
int result; // eax

result = printf("#[default]");
++nbApplets;
return result;
}

canonical_decompiled_code:
int func9()
{
int result; // eax

result = printf("#[default]");
++nbApplets;
return result;
}

original_code:
void end_applet() {
    printf("#[default]");
    nbApplets++;
}


rpcbufInit

repo: vicamo/cndrvcups-common

original_code:
static int rpcbufInit(RPCBuf *bp)
{
    if ((bp->body = malloc(1024)) == ((void *)0)) {
 return -1;
    }
    bp->size = 1024;
    bp->rIndex = bp->wIndex = 0;
    bp->pktTop = bp->pktIndex = 0;
    return 0;
}

canonical_original_code:
static int rpcbufInit(struct RPCBuf *bp)
{
    if ((bp->body = malloc(1024)) == ((void *)0)) {
 return -1;
    }
    bp->size = 1024;
    bp->rIndex = bp->wIndex = 0;
    bp->pktTop = bp->pktIndex = 0;
    return 0;
}

variable_types: struct RPCBuf { char *body; int size; int rIndex; int wIndex; int pktTop; int pktIndex; } *


original_code:
static int oprpc_flushBuffer(RPCHandle *hp, int len)
{
    int wlen = hp->outBuf.wIndex-hp->outBuf.rIndex;
    int mlen;
    while (wlen > 0) {
 int r;
 if ((r = write(hp->outFd,
    hp->outBuf.body+hp->outBuf.rIndex,wlen)) < 0) {
     if ((*__errno_location ()) == 4 || (*__errno_location ()) == 11) continue;
     return -1;
 }
 wlen -= r;
 hp->outBuf.rIndex += r;
    }
    hp->outBuf.rIndex = hp->outBuf.wIndex = 0;
    mlen = len + hp->outBuf.pktIndex - hp->outBuf.pktTop;
    if (hp->outBuf.size < mlen) {
 char *p;
 if ((p = malloc(mlen)) == ((void *)0)) {
     return -1;
 }
 memcpy(p, hp->outBuf.body+hp->outBuf.pktTop,
   hp->outBuf.pktIndex-hp->outBuf.pktTop);
 free(hp->outBuf.body);
 hp->outBuf.size = mlen;
 hp->outBuf.body = p;
    } else {
 memmove(hp->outBuf.body, hp->outBuf.body+hp->outBuf.pktTop,
   hp->outBuf.pktIndex-hp->outBuf.pktTop);
    }
    hp->outBuf.pktIndex -= hp->outBuf.pktTop;
    hp->outBuf.pktTop = 0;
    return 0;
}

canonical_original_code:
static int oprpc_flushBuffer(struct RPCHandle *hp, int len)
{
    int wlen = hp->outBuf.wIndex-hp->outBuf.rIndex;
    int mlen;
    while (wlen > 0) {
 int r;
 if ((r = write(hp->outFd,
    hp->outBuf.body+hp->outBuf.rIndex,wlen)) < 0) {
     if ((*__errno_location ()) == 4 || (*__errno_location ()) == 11) continue;
     return -1;
 }
 wlen -= r;
 hp->outBuf.rIndex += r;
    }
    hp->outBuf.rIndex = hp->outBuf.wIndex = 0;
    mlen = len + hp->outBuf.pktIndex - hp->outBuf.pktTop;
    if (hp->outBuf.size < mlen) {
 char *p;
 if ((p = malloc(mlen)) == ((void *)0)) {
     return -1;
 }
 memcpy(p, hp->outBuf.body+hp->outBuf.pktTop,
   hp->outBuf.pktIndex-hp->outBuf.pktTop);
 free(hp->outBuf.body);
 hp->outBuf.size = mlen;
 hp->outBuf.body = p;
    } else {
 memmove(hp->outBuf.body, hp->outBuf.body+hp->outBuf.pktTop,
   hp->outBuf.pktIndex-hp->outBuf.pktTop);
    }
    hp->outBuf.pktIndex -= hp->outBuf.pktTop;
    hp->outBuf.pktTop = 0;
    return 0;
}

variable_types: struct RPCHandle { int inFd; int outFd; struct RPCBuf { char *body; int size; int rIndex; int wIndex; int pktTop; int pktIndex; } inBuf; struct RPCBuf outBuf; int seqNo; void **shmemStack; int shmemStackSize; int shmemStackPointer; int lastPushSeqNo; } *

variable_types: len int

variable_types: wlen int

variable_types: mlen int

variable_types: r int

variable_types:
p
char *

user_defined_types: struct RPCHandle { int inFd; int outFd; struct RPCBuf inBuf; struct RPCBuf outBuf; int seqNo; void **shmemStack; int shmemStackSize; int shmemStackPointer; int lastPushSeqNo; }


original_code:
static int oprpc_fillBuffer(RPCHandle *hp, int len, int block)
{
    int mlen = hp->inBuf.wIndex - hp->inBuf.pktTop + len;
    if (hp->inBuf.size < mlen) {
 char *p;
 if ((p = malloc(mlen)) == ((void *)0)) {
     return -1;
 }
 memcpy(p, hp->inBuf.body+hp->inBuf.pktTop,
   hp->inBuf.wIndex-hp->inBuf.pktTop);
 free(hp->inBuf.body);
 hp->inBuf.size = mlen;
 hp->inBuf.body = p;
 hp->inBuf.pktIndex -= hp->inBuf.pktTop;
 hp->inBuf.rIndex -= hp->inBuf.pktTop;
 hp->inBuf.wIndex -= hp->inBuf.pktTop;
 hp->inBuf.pktTop = 0;
    } else if (hp->inBuf.size - hp->inBuf.wIndex < len) {
 memmove(hp->inBuf.body, hp->inBuf.body+hp->inBuf.pktTop,
   hp->inBuf.wIndex-hp->inBuf.pktTop);
 hp->inBuf.pktIndex -= hp->inBuf.pktTop;
 hp->inBuf.rIndex -= hp->inBuf.pktTop;
 hp->inBuf.wIndex -= hp->inBuf.pktTop;
 hp->inBuf.pktTop = 0;
    }
    while (len > 0) {
 int r;
 struct pollfd pfd;
 int rlen;
 pfd.fd = hp->inFd;
 pfd.events = 0x001 | 0x008;
 if ((r = poll(&pfd,1,block ? -1 : 0)) <= 0) {
     if (r < 0 && (*__errno_location ()) == 4) continue;
     return r;
 }
 if ((pfd.revents & 0x001) == 0) {
     return -1;
 }
 rlen = hp->inBuf.size - hp->inBuf.wIndex;
 if ((r = read(hp->inFd,
    hp->inBuf.body+hp->inBuf.wIndex,rlen)) <= 0) {
     if (r < 0 && ((*__errno_location ()) == 4|| (*__errno_location ()) == 11)) continue;
     return -1;
 }
 len -= r;
 hp->inBuf.wIndex += r;
    }
    return 1;
}

canonical_original_code:
static int oprpc_fillBuffer(struct RPCHandle *hp, int len, int block)
{
    int mlen = hp->inBuf.wIndex - hp->inBuf.pktTop + len;
    if (hp->inBuf.size < mlen) {
 char *p;
 if ((p = malloc(mlen)) == ((void *)0)) {
     return -1;
 }
 memcpy(p, hp->inBuf.body+hp->inBuf.pktTop,
   hp->inBuf.wIndex-hp->inBuf.pktTop);
 free(hp->inBuf.body);
 hp->inBuf.size = mlen;
 hp->inBuf.body = p;
 hp->inBuf.pktIndex -= hp->inBuf.pktTop;
 hp->inBuf.rIndex -= hp->inBuf.pktTop;
 hp->inBuf.wIndex -= hp->inBuf.pktTop;
 hp->inBuf.pktTop = 0;
    } else if (hp->inBuf.size - hp->inBuf.wIndex < len) {
 memmove(hp->inBuf.body, hp->inBuf.body+hp->inBuf.pktTop,
   hp->inBuf.wIndex-hp->inBuf.pktTop);
 hp->inBuf.pktIndex -= hp->inBuf.pktTop;
 hp->inBuf.rIndex -= hp->inBuf.pktTop;
 hp->inBuf.wIndex -= hp->inBuf.pktTop;
 hp->inBuf.pktTop = 0;
    }
    while (len > 0) {
 int r;
 struct pollfd pfd;
 int rlen;
 pfd.fd = hp->inFd;
 pfd.events = 0x001 | 0x008;
 if ((r = poll(&pfd,1,block ? -1 : 0)) <= 0) {
     if (r < 0 && (*__errno_location ()) == 4) continue;
     return r;
 }
 if ((pfd.revents & 0x001) == 0) {
     return -1;
 }
 rlen = hp->inBuf.size - hp->inBuf.wIndex;
 if ((r = read(hp->inFd,
    hp->inBuf.body+hp->inBuf.wIndex,rlen)) <= 0) {
     if (r < 0 && ((*__errno_location ()) == 4|| (*__errno_location ()) == 11)) continue;
     return -1;
 }
 len -= r;
 hp->inBuf.wIndex += r;
    }
    return 1;
}

variable_types: block int

variable_types: struct pollfd { int fd; short events; short revents; }

variable_types: rlen int

user_defined_types: struct RPCBuf { char *body; int size; int rIndex; int wIndex; int pktTop; int pktIndex; }


decompiled_code:
__int64 __fastcall oprpc_destroy(void *ptr)
{
rpcBufClean((__int64)ptr + 8);
rpcBufClean((__int64)ptr + 40);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *ptr)
{
func1((__int64)ptr + 8);
func1((__int64)ptr + 40);
free(ptr);
return 0LL;
}

original_code:
int oprpc_destroy(void *ap)
{
    RPCHandle *hp = ap;
    rpcBufClean(&hp->inBuf);
    rpcBufClean(&hp->outBuf);
    free(hp);
    return 0;
}

canonical_original_code:
int oprpc_destroy(void *ap)
{
    struct RPCHandle *hp = ap;
    rpcBufClean(&hp->inBuf);
    rpcBufClean(&hp->outBuf);
    free(hp);
    return 0;
}

variable_types:
ap
void *


decompiled_code:
__int64 __fastcall oprpc_putPkt(__int64 a1, const void *a2, int a3)
{
if ( *(_DWORD *)(a1 + 48) - *(_DWORD *)(a1 + 64) < a3 && (int)oprpc_flushBuffer(a1, a3) < 0 )
return 0xFFFFFFFFLL;
memcpy((void *)(*(_QWORD *)(a1 + 40) + *(int *)(a1 + 64)), a2, a3);
*(_DWORD *)(a1 + 64) += a3;
return 0LL;
}

original_code:
int oprpc_putPkt(void *ap, const char *buf, int len)
{
    RPCHandle *hp = ap;
    if (hp->outBuf.size - hp->outBuf.pktIndex < len) {
 if (oprpc_flushBuffer(hp, len) < 0) {
     return -1;
 }
    }
    memcpy(hp->outBuf.body+hp->outBuf.pktIndex,buf,len);
    hp->outBuf.pktIndex += len;
    return 0;
}

canonical_original_code:
int oprpc_putPkt(void *ap, char *buf, int len)
{
    struct RPCHandle *hp = ap;
    if (hp->outBuf.size - hp->outBuf.pktIndex < len) {
 if (oprpc_flushBuffer(hp, len) < 0) {
     return -1;
 }
    }
    memcpy(hp->outBuf.body+hp->outBuf.pktIndex,buf,len);
    hp->outBuf.pktIndex += len;
    return 0;
}

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall oprpc_putPktPointer(__int64 a1, const void *a2, int a3)
{
int v4; // eax
int v5; // edx
int v6; // eax
__int64 result; // rax
char v8[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( a2 )
{
v8[0] = 0;
if ( (int)oprpc_putPkt(a1, v8, 1) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v4 = *(_DWORD *)(a1 + 64);
v5 = v4 + 6;
v6 = v4 + 3;
if ( v6 < 0 )
v6 = v5;
*(_DWORD *)(a1 + 64) = v6 & 0xFFFFFFFC;
result = (unsigned int)((int)oprpc_putPkt(a1, a2, a3) >> 31);
}
}
else
{
v8[0] = 2;
result = (unsigned int)((int)oprpc_putPkt(a1, v8, 1) >> 31);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const void *a2, int a3)
{
int v4; // eax
int v5; // edx
int v6; // eax
__int64 result; // rax
char v8[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( a2 )
{
v8[0] = 0;
if ( (int)func6(a1, v8, 1) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v4 = *(_DWORD *)(a1 + 64);
v5 = v4 + 6;
v6 = v4 + 3;
if ( v6 < 0 )
v6 = v5;
*(_DWORD *)(a1 + 64) = v6 & 0xFFFFFFFC;
result = (unsigned int)((int)func6(a1, a2, a3) >> 31);
}
}
else
{
v8[0] = 2;
result = (unsigned int)((int)func6(a1, v8, 1) >> 31);
}
return result;
}

original_code:
int oprpc_putPktPointer(void *ap, const void *p, int len)
{
    RPCHandle *hp = ap;
    char f;
    if (p == ((void *)0)) {
 f = 2;
 if (oprpc_putPkt(ap,&f,1) < 0) {
     return -1;
 }
 return 0;
    }
 f = 0;
 if (oprpc_putPkt(ap,&f,1) < 0) {
     return -1;
 }
 hp->outBuf.pktIndex = ((hp->outBuf.pktIndex+3)/4)*4;
 if (oprpc_putPkt(ap,p,len) < 0) {
     return -1;
 }
    return 0;
}

canonical_original_code:
int oprpc_putPktPointer(void *ap, void *p, int len)
{
    struct RPCHandle *hp = ap;
    char f;
    if (p == ((void *)0)) {
 f = 2;
 if (oprpc_putPkt(ap,&f,1) < 0) {
     return -1;
 }
 return 0;
    }
 f = 0;
 if (oprpc_putPkt(ap,&f,1) < 0) {
     return -1;
 }
 hp->outBuf.pktIndex = ((hp->outBuf.pktIndex+3)/4)*4;
 if (oprpc_putPkt(ap,p,len) < 0) {
     return -1;
 }
    return 0;
}

variable_types:
p
void *

variable_types: f char


decompiled_code:
__int64 __fastcall oprpc_putPktStart(_DWORD *a1, unsigned int a2, int a3)
{
int v3; // eax
unsigned int v5; // eax
int v6; // [rsp+8h] [rbp-20h] BYREF
unsigned int v7[4]; // [rsp+Ch] [rbp-1Ch] BYREF
int v8[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v7[0] = a2;
v6 = a3;
v8[0] = 0;
v3 = a1[14];
a1[16] = v3;
a1[15] = v3;
if ( (int)oprpc_putPkt((__int64)a1, v8, 4) < 0 )
return 0xFFFFFFFFLL;
if ( (v7[0] & 0x80000000) != 0 )
{
v5 = a1[18];
a1[18] = v5 + 1;
v7[0] = v5;
}
if ( (int)oprpc_putPkt((__int64)a1, v7, 4) < 0 )
return 0xFFFFFFFFLL;
if ( (int)oprpc_putPkt((__int64)a1, &v6, 4) < 0 )
return 0xFFFFFFFFLL;
return v7[0];
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, unsigned int a2, int a3)
{
int v3; // eax
unsigned int v5; // eax
int v6; // [rsp+8h] [rbp-20h] BYREF
unsigned int v7[4]; // [rsp+Ch] [rbp-1Ch] BYREF
int v8[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v7[0] = a2;
v6 = a3;
v8[0] = 0;
v3 = a1[14];
a1[16] = v3;
a1[15] = v3;
if ( (int)func6((__int64)a1, v8, 4) < 0 )
return 0xFFFFFFFFLL;
if ( (v7[0] & 0x80000000) != 0 )
{
v5 = a1[18];
a1[18] = v5 + 1;
v7[0] = v5;
}
if ( (int)func6((__int64)a1, v7, 4) < 0 )
return 0xFFFFFFFFLL;
if ( (int)func6((__int64)a1, &v6, 4) < 0 )
return 0xFFFFFFFFLL;
return v7[0];
}

original_code:
int oprpc_putPktStart(void *ap, int sendSeqNo, int reqNo)
{
    RPCHandle *hp = ap;
    int dmy = 0;
    hp->outBuf.pktTop = hp->outBuf.pktIndex = hp->outBuf.wIndex;
    if (oprpc_putPkt(hp,(char *)&dmy,sizeof(dmy)) < 0) {
 return -1;
    }
    if (sendSeqNo < 0) {
 sendSeqNo = hp->seqNo++;
    }
    if (oprpc_putPkt(hp,(char *)&sendSeqNo,sizeof(sendSeqNo)) < 0) {
 return -1;
    }
    if (oprpc_putPkt(hp,(char *)&reqNo,sizeof(reqNo)) < 0) {
 return -1;
    }
    return sendSeqNo;
}

canonical_original_code:
int oprpc_putPktStart(void *ap, int sendSeqNo, int reqNo)
{
    struct RPCHandle *hp = ap;
    int dmy = 0;
    hp->outBuf.pktTop = hp->outBuf.pktIndex = hp->outBuf.wIndex;
    if (oprpc_putPkt(hp,(char *)&dmy,sizeof(dmy)) < 0) {
 return -1;
    }
    if (sendSeqNo < 0) {
 sendSeqNo = hp->seqNo++;
    }
    if (oprpc_putPkt(hp,(char *)&sendSeqNo,sizeof(sendSeqNo)) < 0) {
 return -1;
    }
    if (oprpc_putPkt(hp,(char *)&reqNo,sizeof(reqNo)) < 0) {
 return -1;
    }
    return sendSeqNo;
}

variable_types: sendSeqNo int

variable_types: reqNo int

variable_types: dmy int


original_code:
int oprpc_putPktEnd(void *ap)
{
    int len;
    RPCHandle *hp = ap;
    len = hp->outBuf.pktIndex - hp->outBuf.pktTop - sizeof(int);
    len = ((len+3)/4)*4;
    *((int *)(hp->outBuf.body+hp->outBuf.pktTop)) = len;
    hp->outBuf.wIndex = hp->outBuf.pktIndex
       = hp->outBuf.pktTop+len+sizeof(int);
    return 0;
}

canonical_original_code:
int oprpc_putPktEnd(void *ap)
{
    int len;
    struct RPCHandle *hp = ap;
    len = hp->outBuf.pktIndex - hp->outBuf.pktTop - sizeof(int);
    len = ((len+3)/4)*4;
    *((int *)(hp->outBuf.body+hp->outBuf.pktTop)) = len;
    hp->outBuf.wIndex = hp->outBuf.pktIndex
       = hp->outBuf.pktTop+len+sizeof(int);
    return 0;
}


decompiled_code:
__int64 __fastcall oprpc_flush(__int64 a1)
{
return oprpc_flushBuffer(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return func2(a1, 0);
}

original_code:
int oprpc_flush(void *hp)
{
    return oprpc_flushBuffer(hp,0);
}

variable_types:
hp
void *


decompiled_code:
__int64 __fastcall oprpc_getPkt(__int64 a1, void *a2, int a3)
{
int v4; // eax

v4 = *(_DWORD *)(a1 + 24) - *(_DWORD *)(a1 + 32);
if ( v4 < a3 && (int)oprpc_fillBuffer(a1, a3 - v4, 1) < 0 )
return 0xFFFFFFFFLL;
memcpy(a2, (const void *)(*(_QWORD *)(a1 + 8) + *(int *)(a1 + 32)), a3);
*(_DWORD *)(a1 + 32) += a3;
return 0LL;
}

original_code:
int oprpc_getPkt(void *ap, char *buf, int len)
{
    RPCHandle *hp = ap;
    if (hp->inBuf.wIndex - hp->inBuf.pktIndex < len) {
 if (oprpc_fillBuffer(hp,
      len-(hp->inBuf.wIndex - hp->inBuf.pktIndex),1) < 0) {
     return -1;
 }
    }
    memcpy(buf,hp->inBuf.body+hp->inBuf.pktIndex,len);
    hp->inBuf.pktIndex += len;
    return 0;
}

canonical_original_code:
int oprpc_getPkt(void *ap, char *buf, int len)
{
    struct RPCHandle *hp = ap;
    if (hp->inBuf.wIndex - hp->inBuf.pktIndex < len) {
 if (oprpc_fillBuffer(hp,
      len-(hp->inBuf.wIndex - hp->inBuf.pktIndex),1) < 0) {
     return -1;
 }
    }
    memcpy(buf,hp->inBuf.body+hp->inBuf.pktIndex,len);
    hp->inBuf.pktIndex += len;
    return 0;
}

variable_types: struct RPCHandle { int inFd; int outFd; struct RPCBuf { char *body; int size; int rIndex; int wIndex; int pktTop; int pktIndex; } inBuf; struct RPCBuf outBuf; int seqNo; void **shmemStack; int shmemStackSize; int shmemStackPointer; int lastPushSeqNo; } *


decompiled_code:
__int64 __fastcall oprpc_getPktNonBlock(__int64 a1, void *a2, int a3)
{
int v4; // eax
__int64 result; // rax

v4 = *(_DWORD *)(a1 + 24) - *(_DWORD *)(a1 + 32);
if ( v4 >= a3 || (result = oprpc_fillBuffer(a1, a3 - v4, 0), (int)result > 0) )
{
memcpy(a2, (const void *)(*(_QWORD *)(a1 + 8) + *(int *)(a1 + 32)), a3);
*(_DWORD *)(a1 + 32) += a3;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, void *a2, int a3)
{
int v4; // eax
__int64 result; // rax

v4 = *(_DWORD *)(a1 + 24) - *(_DWORD *)(a1 + 32);
if ( v4 >= a3 || (result = func3(a1, a3 - v4, 0), (int)result > 0) )
{
memcpy(a2, (const void *)(*(_QWORD *)(a1 + 8) + *(int *)(a1 + 32)), a3);
*(_DWORD *)(a1 + 32) += a3;
result = 1LL;
}
return result;
}

original_code:
int oprpc_getPktNonBlock(void *ap, char *buf, int len)
{
    RPCHandle *hp = ap;
    if (hp->inBuf.wIndex - hp->inBuf.pktIndex < len) {
 int r;
 if ((r = oprpc_fillBuffer(hp,
      len-(hp->inBuf.wIndex - hp->inBuf.pktIndex),0)) <= 0) {
     return r;
 }
    }
    memcpy(buf,hp->inBuf.body+hp->inBuf.pktIndex,len);
    hp->inBuf.pktIndex += len;
    return 1;
}

canonical_original_code:
int oprpc_getPktNonBlock(void *ap, char *buf, int len)
{
    struct RPCHandle *hp = ap;
    if (hp->inBuf.wIndex - hp->inBuf.pktIndex < len) {
 int r;
 if ((r = oprpc_fillBuffer(hp,
      len-(hp->inBuf.wIndex - hp->inBuf.pktIndex),0)) <= 0) {
     return r;
 }
    }
    memcpy(buf,hp->inBuf.body+hp->inBuf.pktIndex,len);
    hp->inBuf.pktIndex += len;
    return 1;
}

variable_types: len int


decompiled_code:
__int64 __fastcall oprpc_getPktPointer(__int64 a1, _QWORD *a2, int a3)
{
__int64 result; // rax
int v5; // eax
int v6; // edx
int v7; // eax
signed int v8; // eax
char v9[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( (int)oprpc_getPkt(a1, v9, 1) < 0 )
return 0xFFFFFFFFLL;
if ( v9[0] )
{
if ( v9[0] == 2 )
{
*a2 = 0LL;
result = 2LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
v5 = *(_DWORD *)(a1 + 32);
v6 = v5 + 6;
v7 = v5 + 3;
if ( v7 < 0 )
v7 = v6;
v8 = v7 & 0xFFFFFFFC;
*(_DWORD *)(a1 + 32) = v8;
if ( a3 < 0 )
{
*a2 = *(_QWORD *)(a1 + 8) + v8;
result = 0LL;
}
else if ( *(_DWORD *)(a1 + 24) - v8 < a3 )
{
result = 0xFFFFFFFFLL;
}
else
{
*a2 = *(_QWORD *)(a1 + 8) + v8;
*(_DWORD *)(a1 + 32) += a3;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, _QWORD *a2, int a3)
{
__int64 result; // rax
int v5; // eax
int v6; // edx
int v7; // eax
signed int v8; // eax
char v9[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( (int)func11(a1, v9, 1) < 0 )
return 0xFFFFFFFFLL;
if ( v9[0] )
{
if ( v9[0] == 2 )
{
*a2 = 0LL;
result = 2LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
v5 = *(_DWORD *)(a1 + 32);
v6 = v5 + 6;
v7 = v5 + 3;
if ( v7 < 0 )
v7 = v6;
v8 = v7 & 0xFFFFFFFC;
*(_DWORD *)(a1 + 32) = v8;
if ( a3 < 0 )
{
*a2 = *(_QWORD *)(a1 + 8) + v8;
result = 0LL;
}
else if ( *(_DWORD *)(a1 + 24) - v8 < a3 )
{
result = 0xFFFFFFFFLL;
}
else
{
*a2 = *(_QWORD *)(a1 + 8) + v8;
*(_DWORD *)(a1 + 32) += a3;
result = 0LL;
}
}
return result;
}

original_code:
int oprpc_getPktPointer(void *ap, void **p, int len)
{
    RPCHandle *hp = ap;
    char f;
    if (oprpc_getPkt(ap,&f,1) < 0) {
 return -1;
    }
    switch (f) {
    case 0:
 hp->inBuf.pktIndex = ((hp->inBuf.pktIndex+3)/4)*4;
 if (len >= 0 && hp->inBuf.wIndex - hp->inBuf.pktIndex < len) {
     return -1;
 }
 *p = hp->inBuf.body+hp->inBuf.pktIndex;
 if (len >= 0) hp->inBuf.pktIndex += len;
 break;
    case 1:
 return -1;
 break;
    case 2:
 *p = ((void *)0);
 break;
    default:
 return -1;
 break;
    }
    return f;
}

canonical_original_code:
int oprpc_getPktPointer(void *ap, void **p, int len)
{
    struct RPCHandle *hp = ap;
    char f;
    if (oprpc_getPkt(ap,&f,1) < 0) {
 return -1;
    }
    switch (f) {
    case 0:
 hp->inBuf.pktIndex = ((hp->inBuf.pktIndex+3)/4)*4;
 if (len >= 0 && hp->inBuf.wIndex - hp->inBuf.pktIndex < len) {
     return -1;
 }
 *p = hp->inBuf.body+hp->inBuf.pktIndex;
 if (len >= 0) hp->inBuf.pktIndex += len;
 break;
    case 1:
 return -1;
 break;
    case 2:
 *p = ((void *)0);
 break;
    default:
 return -1;
 break;
    }
    return f;
}

variable_types:
p
void **


decompiled_code:
__int64 __fastcall oprpc_addInPktIndex(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 32) += a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 32) += a2;
return 0LL;
}

original_code:
int oprpc_addInPktIndex(void *ap, int len)
{
    RPCHandle *hp = ap;
    hp->inBuf.pktIndex += len;
    return 0;
}

canonical_original_code:
int oprpc_addInPktIndex(void *ap, int len)
{
    struct RPCHandle *hp = ap;
    hp->inBuf.pktIndex += len;
    return 0;
}


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

if ( (int)oprpc_getPktPointer(a1, a2, -1) < 0 )
return 0xFFFFFFFFLL;
result = 0LL;
if ( *a2 )
{
*(_DWORD *)(a1 + 32) += strlen(*a2) + 1;
result = 0LL;
}
return result;
}

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

if ( (int)func13(a1, a2, -1) < 0 )
return 0xFFFFFFFFLL;
result = 0LL;
if ( *a2 )
{
*(_DWORD *)(a1 + 32) += strlen(*a2) + 1;
result = 0LL;
}
return result;
}

original_code:
int oprpc_getStr(void *ap, void **sp)
{
    RPCHandle *hp = ap;
    int len;
    if (oprpc_getPktPointer(ap,sp,-1) < 0) {
 return -1;
    }
    if (*sp != ((void *)0)) {
 len = strlen(*sp);
 hp->inBuf.pktIndex += len + 1;
    }
    return 0;
}

canonical_original_code:
int oprpc_getStr(void *ap, void **sp)
{
    struct RPCHandle *hp = ap;
    int len;
    if (oprpc_getPktPointer(ap,sp,-1) < 0) {
 return -1;
    }
    if (*sp != ((void *)0)) {
 len = strlen(*sp);
 hp->inBuf.pktIndex += len + 1;
    }
    return 0;
}

variable_types:
sp
void **


decompiled_code:
__int64 __fastcall oprpc_getPktStart(_DWORD *a1)
{
int v1; // eax
int v2; // eax
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (int)oprpc_flush((__int64)a1) < 0 )
return 0xFFFFFFFFLL;
v1 = a1[5];
a1[8] = v1;
a1[7] = v1;
if ( (int)oprpc_getPkt((__int64)a1, v5, 4) < 0 )
return 0xFFFFFFFFLL;
v2 = a1[6] - a1[8];
if ( v2 < v5[0] && (int)oprpc_fillBuffer((__int64)a1, v5[0] - v2, 1) < 0 )
return 0xFFFFFFFFLL;
if ( (int)oprpc_getPkt((__int64)a1, &v4, 4) < 0 )
return 0xFFFFFFFFLL;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func16(_DWORD *a1)
{
int v1; // eax
int v2; // eax
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (int)func10((__int64)a1) < 0 )
return 0xFFFFFFFFLL;
v1 = a1[5];
a1[8] = v1;
a1[7] = v1;
if ( (int)func11((__int64)a1, v5, 4) < 0 )
return 0xFFFFFFFFLL;
v2 = a1[6] - a1[8];
if ( v2 < v5[0] && (int)func3((__int64)a1, v5[0] - v2, 1) < 0 )
return 0xFFFFFFFFLL;
if ( (int)func11((__int64)a1, &v4, 4) < 0 )
return 0xFFFFFFFFLL;
return v4;
}

original_code:
int oprpc_getPktStart(void *ap)
{
    RPCHandle *hp = ap;
    int size;
    int gSeqNo;
    if (oprpc_flush(hp) < 0) {
 return -1;
    }
    hp->inBuf.pktTop = hp->inBuf.pktIndex = hp->inBuf.rIndex;
    if (oprpc_getPkt(hp,(char *)&size,sizeof(size)) < 0) {
 return -1;
    }
    if (hp->inBuf.wIndex - hp->inBuf.pktIndex < size) {
 if (oprpc_fillBuffer(hp,
      size - (hp->inBuf.wIndex - hp->inBuf.pktIndex),1) < 0) {
     return -1;
 }
    }
    if (oprpc_getPkt(hp,(char *)&gSeqNo,sizeof(gSeqNo)) < 0) {
 return -1;
    }
    return gSeqNo;
}

canonical_original_code:
int oprpc_getPktStart(void *ap)
{
    struct RPCHandle *hp = ap;
    int size;
    int gSeqNo;
    if (oprpc_flush(hp) < 0) {
 return -1;
    }
    hp->inBuf.pktTop = hp->inBuf.pktIndex = hp->inBuf.rIndex;
    if (oprpc_getPkt(hp,(char *)&size,sizeof(size)) < 0) {
 return -1;
    }
    if (hp->inBuf.wIndex - hp->inBuf.pktIndex < size) {
 if (oprpc_fillBuffer(hp,
      size - (hp->inBuf.wIndex - hp->inBuf.pktIndex),1) < 0) {
     return -1;
 }
    }
    if (oprpc_getPkt(hp,(char *)&gSeqNo,sizeof(gSeqNo)) < 0) {
 return -1;
    }
    return gSeqNo;
}

variable_types: size int

variable_types: gSeqNo int


decompiled_code:
__int64 __fastcall oprpc_getPktStartNonBlock(_DWORD *a1)
{
int v1; // eax
__int64 result; // rax
int v3; // eax
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (int)oprpc_flush((__int64)a1) < 0 )
return 0xFFFFFFFFLL;
v1 = a1[5];
a1[8] = v1;
a1[7] = v1;
result = oprpc_getPktNonBlock((__int64)a1, v5, 4);
if ( (int)result > 0 )
{
v3 = a1[6] - a1[8];
if ( v3 >= v5[0] || (result = oprpc_fillBuffer((__int64)a1, v5[0] - v3, 0), (int)result > 0) )
{
if ( (int)oprpc_getPkt((__int64)a1, &v4, 4) < 0 )
result = 0xFFFFFFFFLL;
else
result = v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(_DWORD *a1)
{
int v1; // eax
__int64 result; // rax
int v3; // eax
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (int)func10((__int64)a1) < 0 )
return 0xFFFFFFFFLL;
v1 = a1[5];
a1[8] = v1;
a1[7] = v1;
result = func12((__int64)a1, v5, 4);
if ( (int)result > 0 )
{
v3 = a1[6] - a1[8];
if ( v3 >= v5[0] || (result = func3((__int64)a1, v5[0] - v3, 0), (int)result > 0) )
{
if ( (int)func11((__int64)a1, &v4, 4) < 0 )
result = 0xFFFFFFFFLL;
else
result = v4;
}
}
return result;
}

original_code:
int oprpc_getPktStartNonBlock(void *ap)
{
    RPCHandle *hp = ap;
    int size;
    int gSeqNo;
    int r;
    if (oprpc_flush(hp) < 0) {
 return -1;
    }
    hp->inBuf.pktTop = hp->inBuf.pktIndex = hp->inBuf.rIndex;
    if ((r = oprpc_getPktNonBlock(hp,(char *)&size,sizeof(size))) <= 0) {
 return r;
    }
    if (hp->inBuf.wIndex - hp->inBuf.pktIndex < size) {
 if ((r = oprpc_fillBuffer(hp,
      size - (hp->inBuf.wIndex - hp->inBuf.pktIndex),0)) <= 0) {
     return r;
 }
    }
    if (oprpc_getPkt(hp,(char *)&gSeqNo,sizeof(gSeqNo)) < 0) {
 return -1;
    }
    return gSeqNo;
}

canonical_original_code:
int oprpc_getPktStartNonBlock(void *ap)
{
    struct RPCHandle *hp = ap;
    int size;
    int gSeqNo;
    int r;
    if (oprpc_flush(hp) < 0) {
 return -1;
    }
    hp->inBuf.pktTop = hp->inBuf.pktIndex = hp->inBuf.rIndex;
    if ((r = oprpc_getPktNonBlock(hp,(char *)&size,sizeof(size))) <= 0) {
 return r;
    }
    if (hp->inBuf.wIndex - hp->inBuf.pktIndex < size) {
 if ((r = oprpc_fillBuffer(hp,
      size - (hp->inBuf.wIndex - hp->inBuf.pktIndex),0)) <= 0) {
     return r;
 }
    }
    if (oprpc_getPkt(hp,(char *)&gSeqNo,sizeof(gSeqNo)) < 0) {
 return -1;
    }
    return gSeqNo;
}

variable_types: r int


original_code:
int oprpc_getPktEnd(void *ap)
{
    RPCHandle *hp = ap;
    hp->inBuf.rIndex +=
      *((int *)(hp->inBuf.body+hp->inBuf.pktTop))+sizeof(int);
    return 0;
}

canonical_original_code:
int oprpc_getPktEnd(void *ap)
{
    struct RPCHandle *hp = ap;
    hp->inBuf.rIndex +=
      *((int *)(hp->inBuf.body+hp->inBuf.pktTop))+sizeof(int);
    return 0;
}


decompiled_code:
__int64 __fastcall oprpc_putError(_DWORD *a1, unsigned int a2, int a3, int a4)
{
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = a4;
if ( (int)oprpc_putPktStart(a1, a2, a3) < 0 )
return 0xFFFFFFFFLL;
if ( (int)oprpc_putPkt((__int64)a1, v5, 4) < 0 )
return 0xFFFFFFFFLL;
return oprpc_putPktEnd((__int64)a1);
}

canonical_decompiled_code:
__int64 __fastcall func19(_DWORD *a1, unsigned int a2, int a3, int a4)
{
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = a4;
if ( (int)func8(a1, a2, a3) < 0 )
return 0xFFFFFFFFLL;
if ( (int)func6((__int64)a1, v5, 4) < 0 )
return 0xFFFFFFFFLL;
return func9((__int64)a1);
}

original_code:
int oprpc_putError(void *ap, int seqNo, int errNo, int reqNo)
{
    if (oprpc_putPktStart(ap, seqNo, errNo) < 0) {
 return -1;
    }
    if (oprpc_putPkt((ap), (const char *)(&reqNo),sizeof(int)) < 0) {
 return -1;
    }
    return oprpc_putPktEnd(ap);
}

canonical_original_code:
int oprpc_putError(void *ap, int seqNo, int errNo, int reqNo)
{
    if (oprpc_putPktStart(ap, seqNo, errNo) < 0) {
 return -1;
    }
    if (oprpc_putPkt((ap), (char *)(&reqNo),sizeof(int)) < 0) {
 return -1;
    }
    return oprpc_putPktEnd(ap);
}

variable_types: seqNo int

variable_types: errNo int


printList

repo: vichargrave/rlist

decompiled_code:
int __fastcall printList(unsigned int *a1)
{
unsigned int *i; // rbx

for ( i = a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf("%d ", *i);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1)
{
unsigned int *i; // rbx

for ( i = a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf("%d ", *i);
return putchar(10);
}

original_code:
void printList(node_t* list)
{
    while (list)
    {
        printf("%d  ", list->m_value);
        list = list->m_next;
    }
    printf("\n");
}

canonical_original_code:
void printList(struct node_t *list)
{
    while (list)
    {
        printf("%d  ", list->m_value);
        list = list->m_next;
    }
    printf("\n");
}

variable_types: struct node_t { int m_value; struct node_t *m_next; } *


reverseList

decompiled_code:
__int64 __fastcall reverseList(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx

result = a1;
if ( a1 )
{
v2 = 0LL;
while ( 1 )
{
v3 = *(_QWORD *)(result + 8);
*(_QWORD *)(result + 8) = v2;
v2 = result;
if ( !v3 )
break;
result = v3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx

result = a1;
if ( a1 )
{
v2 = 0LL;
while ( 1 )
{
v3 = *(_QWORD *)(result + 8);
*(_QWORD *)(result + 8) = v2;
v2 = result;
if ( !v3 )
break;
result = v3;
}
}
return result;
}

original_code:
node_t* reverseList(node_t* head)
{
    node_t* cursor = ((void *)0);
    node_t* next;
    while (head)
    {
        next = head->m_next;
        head->m_next = cursor;
        cursor = head;
        head = next;
    }
    return cursor;
}

canonical_original_code:
struct node_t *reverseList(struct node_t *head)
{
    struct node_t *cursor = ((void *)0);
    struct node_t *next;
    while (head)
    {
        next = head->m_next;
        head->m_next = cursor;
        cursor = head;
        head = next;
    }
    return cursor;
}

variable_types:
head
struct node_t *

return_type: struct node_t { int m_value; struct node_t *m_next; } *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int i; // ebx
unsigned int *v4; // [rsp+8h] [rbp-10h] BYREF

v4 = 0LL;
for ( i = 0; i != 20; ++i )
addNode((__int64 *)&v4, i);
printList(v4);
v4 = (unsigned int *)reverseList((__int64)v4);
printList(v4);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int i; // ebx
unsigned int *v4; // [rsp+8h] [rbp-10h] BYREF

v4 = 0LL;
for ( i = 0; i != 20; ++i )
addNode((__int64 *)&v4, i);
func7(v4);
v4 = (unsigned int *)func8((__int64)v4);
func7(v4);
exit(0);
}

original_code:
int main(int argc, char** argv)
{
    int i;
    node_t* head = ((void *)0);
    for (i = 0; i < 20; i++) {
        addNode(&head, i);
    }
    printList(head);
    head = reverseList(head);
    printList(head);
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    int i;
    struct node_t *head = ((void *)0);
    for (i = 0; i < 20; i++) {
        addNode(&head, i);
    }
    printList(head);
    head = reverseList(head);
    printList(head);
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

user_defined_types: struct node_t { int m_value; struct node_t *m_next; }


repo: vichargrave/sniffer

original_code:
void packet_handler(u_char *user, const struct pcap_pkthdr *packethdr, const u_char *packetptr)
{
    struct ip* iphdr;
    struct icmp* icmphdr;
    struct tcphdr* tcphdr;
    struct udphdr* udphdr;
    char iphdrInfo[256];
    char srcip[256];
    char dstip[256];
    packetptr += linkhdrlen;
    iphdr = (struct ip*)packetptr;
    strcpy(srcip, inet_ntoa(iphdr->ip_src));
    strcpy(dstip, inet_ntoa(iphdr->ip_dst));
    sprintf(iphdrInfo, "ID:%d TOS:0x%x, TTL:%d IpLen:%d DgLen:%d",
            ntohs(iphdr->ip_id), iphdr->ip_tos, iphdr->ip_ttl,
            4*iphdr->ip_hl, ntohs(iphdr->ip_len));
    packetptr += 4*iphdr->ip_hl;
    switch (iphdr->ip_p)
    {
    case IPPROTO_TCP:
        tcphdr = (struct tcphdr*)packetptr;
        printf("TCP  %s:%d -> %s:%d\n", srcip, ntohs(tcphdr->th_sport),
               dstip, ntohs(tcphdr->th_dport));
        printf("%s\n", iphdrInfo);
        printf("%c%c%c%c%c%c Seq: 0x%x Ack: 0x%x Win: 0x%x TcpLen: %d\n",
               (tcphdr->th_flags & 0x20 ? 'U' : '*'),
               (tcphdr->th_flags & 0x10 ? 'A' : '*'),
               (tcphdr->th_flags & 0x08 ? 'P' : '*'),
               (tcphdr->th_flags & 0x04 ? 'R' : '*'),
               (tcphdr->th_flags & 0x02 ? 'S' : '*'),
               (tcphdr->th_flags & 0x02 ? 'F' : '*'),
               ntohl(tcphdr->th_seq), ntohl(tcphdr->th_ack),
               ntohs(tcphdr->th_win), 4*tcphdr->th_off);
        printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n");
        packets += 1;
        break;
    case IPPROTO_UDP:
        udphdr = (struct udphdr*)packetptr;
        printf("UDP  %s:%d -> %s:%d\n", srcip, ntohs(udphdr->uh_sport),
               dstip, ntohs(udphdr->uh_dport));
        printf("%s\n", iphdrInfo);
     printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n");
        packets += 1;
        break;
    case IPPROTO_ICMP:
        icmphdr = (struct icmp*)packetptr;
        printf("ICMP %s -> %s\n", srcip, dstip);
        printf("%s\n", iphdrInfo);
        printf("Type:%d Code:%d ID:%d Seq:%d\n", icmphdr->icmp_type, icmphdr->icmp_code,
               ntohs(icmphdr->icmp_hun.ih_idseq.icd_id), ntohs(icmphdr->icmp_hun.ih_idseq.icd_seq));
     printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n");
        packets += 1;
        break;
    }
}

canonical_original_code:
void packet_handler(unsigned char *user, struct pcap_pkthdr *packethdr, unsigned char *packetptr)
{
    struct ip *iphdr;
    struct icmp *icmphdr;
    struct tcphdr *tcphdr;
    struct udphdr *udphdr;
    char iphdrInfo[256];
    char srcip[256];
    char dstip[256];
    packetptr += linkhdrlen;
    iphdr = (struct ip *)packetptr;
    strcpy(srcip, inet_ntoa(iphdr->ip_src));
    strcpy(dstip, inet_ntoa(iphdr->ip_dst));
    sprintf(iphdrInfo, "ID:%d TOS:0x%x, TTL:%d IpLen:%d DgLen:%d",
            ntohs(iphdr->ip_id), iphdr->ip_tos, iphdr->ip_ttl,
            4*iphdr->ip_hl, ntohs(iphdr->ip_len));
    packetptr += 4*iphdr->ip_hl;
    switch (iphdr->ip_p)
    {
    case IPPROTO_TCP:
        tcphdr = (struct tcphdr *)packetptr;
        printf("TCP  %s:%d -> %s:%d\n", srcip, ntohs(tcphdr->th_sport),
               dstip, ntohs(tcphdr->th_dport));
        printf("%s\n", iphdrInfo);
        printf("%c%c%c%c%c%c Seq: 0x%x Ack: 0x%x Win: 0x%x TcpLen: %d\n",
               (tcphdr->th_flags & 0x20 ? 'U' : '*'),
               (tcphdr->th_flags & 0x10 ? 'A' : '*'),
               (tcphdr->th_flags & 0x08 ? 'P' : '*'),
               (tcphdr->th_flags & 0x04 ? 'R' : '*'),
               (tcphdr->th_flags & 0x02 ? 'S' : '*'),
               (tcphdr->th_flags & 0x02 ? 'F' : '*'),
               ntohl(tcphdr->th_seq), ntohl(tcphdr->th_ack),
               ntohs(tcphdr->th_win), 4*tcphdr->th_off);
        printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n");
        packets += 1;
        break;
    case IPPROTO_UDP:
        udphdr = (struct udphdr *)packetptr;
        printf("UDP  %s:%d -> %s:%d\n", srcip, ntohs(udphdr->uh_sport),
               dstip, ntohs(udphdr->uh_dport));
        printf("%s\n", iphdrInfo);
     printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n");
        packets += 1;
        break;
    case IPPROTO_ICMP:
        icmphdr = (struct icmp *)packetptr;
        printf("ICMP %s -> %s\n", srcip, dstip);
        printf("%s\n", iphdrInfo);
        printf("Type:%d Code:%d ID:%d Seq:%d\n", icmphdr->icmp_type, icmphdr->icmp_code,
               ntohs(icmphdr->icmp_hun.ih_idseq.icd_id), ntohs(icmphdr->icmp_hun.ih_idseq.icd_seq));
     printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n");
        packets += 1;
        break;
    }
}

variable_types:
user
unsigned char *

variable_types: struct pcap_pkthdr { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int caplen; unsigned int len; } *

variable_types:
packetptr
unsigned char *

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

variable_types: struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr { unsigned int s_addr; } ih_gwaddr; struct ih_idseq { unsigned short icd_id; unsigned short icd_seq; } ih_idseq; unsigned int ih_void; struct ih_pmtu { unsigned short ipm_void; unsigned short ipm_nextmtu; } ih_pmtu; struct ih_rtradv { unsigned char irt_num_addrs; unsigned char irt_wpa; unsigned short irt_lifetime; } ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; } idi_ip; } id_ip; struct icmp_ra_addr { unsigned int ira_addr; unsigned int ira_preference; } id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; } *

variable_types: struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; } *

variable_types: struct udphdr { union { struct { unsigned short uh_sport; unsigned short uh_dport; unsigned short uh_ulen; unsigned short uh_sum; }; struct { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; }; }; } *

variable_types:
iphdrInfo
char [256]

variable_types:
srcip
char [256]

variable_types:
dstip
char [256]

user_defined_types: struct pcap_pkthdr { struct timeval ts; unsigned int caplen; unsigned int len; }

user_defined_types: struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr ih_gwaddr; struct ih_idseq ih_idseq; unsigned int ih_void; struct ih_pmtu ih_pmtu; struct ih_rtradv ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip idi_ip; } id_ip; struct icmp_ra_addr id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; }


decompiled_code:
void __noreturn stop_capture()
{
unsigned int v0; // [rsp+4h] [rbp-14h]
unsigned int v1; // [rsp+8h] [rbp-10h]

if ( (int)pcap_stats() >= 0 )
{
printf("\n%d packets captured\n", (unsigned int)packets);
printf("%d packets received by filter\n", v0);
printf("%d packets dropped\n\n", v1);
}
pcap_close();
exit(0);
}

canonical_decompiled_code:
void __noreturn func10()
{
unsigned int v0; // [rsp+4h] [rbp-14h]
unsigned int v1; // [rsp+8h] [rbp-10h]

if ( (int)pcap_stats() >= 0 )
{
printf("\n%d packets captured\n", (unsigned int)packets);
printf("%d packets received by filter\n", v0);
printf("%d packets dropped\n\n", v1);
}
pcap_close();
exit(0);
}

original_code:
void stop_capture(int signo)
{
    struct pcap_stat stats;
    if (pcap_stats(handle, &stats) >= 0) {
        printf("\n%d packets captured\n", packets);
        printf("%d packets received by filter\n", stats.ps_recv);
        printf("%d packets dropped\n\n", stats.ps_drop);
    }
    pcap_close(handle);
    exit(0);
}

variable_types: signo int

variable_types: struct pcap_stat { unsigned int ps_recv; unsigned int ps_drop; unsigned int ps_ifdrop; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char **v4; // r12
const char **v5; // rbx
const char *v7; // rax
char v8[256]; // [rsp+0h] [rbp-228h] BYREF
char dest[296]; // [rsp+100h] [rbp-128h] BYREF

dest[0] = 0;
v8[0] = 0;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "hi:n:");
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'i':
strcpy(dest, optarg);
break;
case 'n':
atoi(optarg);
break;
case 'h':
printf("usage: %s [-h] [-i interface] [-n count] [BPF expression]\n", *argv);
exit(0);
}
}
if ( argc > optind )
{
v4 = &argv[optind];
v5 = &(&argv[optind])[(unsigned __int64)(unsigned int)(argc + ~optind) + 1];
do
{
strcat(v8, *v4);
*(_WORD *)&v8[strlen(v8)] = 32;
++v4;
}
while ( v4 != v5 );
}
signal(2, (__sighandler_t)stop_capture);
signal(15, (__sighandler_t)stop_capture);
signal(3, (__sighandler_t)stop_capture);
handle = create_pcap_handle(dest);
if ( handle )
{
get_link_header_len();
if ( linkhdrlen )
{
if ( (unsigned int)pcap_loop() != -1 )
stop_capture();
v7 = (const char *)pcap_geterr();
fprintf(stderr, "pcap_loop failed: %s\n", v7);
}
}
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char **v4; // r12
const char **v5; // rbx
const char *v7; // rax
char v8[256]; // [rsp+0h] [rbp-228h] BYREF
char dest[296]; // [rsp+100h] [rbp-128h] BYREF

dest[0] = 0;
v8[0] = 0;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "hi:n:");
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'i':
strcpy(dest, optarg);
break;
case 'n':
atoi(optarg);
break;
case 'h':
printf("usage: %s [-h] [-i interface] [-n count] [BPF expression]\n", *argv);
exit(0);
}
}
if ( argc > optind )
{
v4 = &argv[optind];
v5 = &(&argv[optind])[(unsigned __int64)(unsigned int)(argc + ~optind) + 1];
do
{
strcat(v8, *v4);
*(_WORD *)&v8[strlen(v8)] = 32;
++v4;
}
while ( v4 != v5 );
}
signal(2, (__sighandler_t)stop_capture);
signal(15, (__sighandler_t)stop_capture);
signal(3, (__sighandler_t)stop_capture);
handle = func11(dest);
if ( handle )
{
func12();
if ( linkhdrlen )
{
if ( (unsigned int)pcap_loop() != -1 )
func10();
v7 = (const char *)pcap_geterr();
fprintf(stderr, "pcap_loop failed: %s\n", v7);
}
}
return -1;
}

original_code:
int main(int argc, char *argv[])
{
    char device[256];
    char filter[256];
    int count = 0;
    int opt;
    *device = 0;
    *filter = 0;
    while ((opt = getopt(argc, argv, "hi:n:")) != -1)
    {
        switch (opt)
        {
        case 'h':
            printf("usage: %s [-h] [-i interface] [-n count] [BPF expression]\n", argv[0]);
            exit(0);
            break;
        case 'i':
            strcpy(device, optarg);
            break;
        case 'n':
            count = atoi(optarg);
            break;
        }
    }
    for (int i = optind; i < argc; i++) {
        strcat(filter, argv[i]);
        strcat(filter, " ");
    }
    signal(2, stop_capture);
    signal(15, stop_capture);
    signal(3, stop_capture);
    handle = create_pcap_handle(device, filter);
    if (handle == ((void *)0)) {
        return -1;
    }
    get_link_header_len(handle);
    if (linkhdrlen == 0) {
        return -1;
    }
    if (pcap_loop(handle, count, packet_handler, (u_char*)((void *)0)) == -1) {
        fprintf(stderr, "pcap_loop failed: %s\n", pcap_geterr(handle));
        return -1;
    }
    stop_capture(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char device[256];
    char filter[256];
    int count = 0;
    int opt;
    *device = 0;
    *filter = 0;
    while ((opt = getopt(argc, argv, "hi:n:")) != -1)
    {
        switch (opt)
        {
        case 'h':
            printf("usage: %s [-h] [-i interface] [-n count] [BPF expression]\n", argv[0]);
            exit(0);
            break;
        case 'i':
            strcpy(device, optarg);
            break;
        case 'n':
            count = atoi(optarg);
            break;
        }
    }
    for (int i = optind; i < argc; i++) {
        strcat(filter, argv[i]);
        strcat(filter, " ");
    }
    signal(2, stop_capture);
    signal(15, stop_capture);
    signal(3, stop_capture);
    handle = create_pcap_handle(device, filter);
    if (handle == ((void *)0)) {
        return -1;
    }
    get_link_header_len(handle);
    if (linkhdrlen == 0) {
        return -1;
    }
    if (pcap_loop(handle, count, packet_handler, (unsigned char *)((void *)0)) == -1) {
        fprintf(stderr, "pcap_loop failed: %s\n", pcap_geterr(handle));
        return -1;
    }
    stop_capture(0);
}

variable_types:
argv
char *[]

variable_types:
device
char [256]

variable_types:
filter
char [256]

variable_types: count int

variable_types: opt int