decompiled_code:
_BOOL8 __fastcall nn_heap_empty(__int64 a1)
{
if ( !a1 )
_assert_fail("h != NULL", "src/nn_heap.c", 0x38u, "nn_heap_empty");
return *(_DWORD *)(a1 + 8) <= 1u;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
if ( !a1 )
_assert_fail("h != NULL", "src/nn_heap.c", 0x38u, "nn_heap_empty");
return *(_DWORD *)(a1 + 8) <= 1u;
}

original_code:
unsigned
nn_heap_empty(struct nn_heap *h)
{
    ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "src/nn_heap.c", 56, __extension__ __PRETTY_FUNCTION__); }));
    return h->next <= 1;
}

canonical_original_code:
unsigned int nn_heap_empty(struct nn_heap *h)
{
    ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "src/nn_heap.c", 56, __extension__ __PRETTY_FUNCTION__); }));
    return h->next <= 1;
}


repo: davidreynolds/rtree

decompiled_code:
__int64 __fastcall nn_heap_push(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
unsigned int v3; // eax
_QWORD *v4; // rbp
__int64 v5; // r13
_QWORD *v6; // rax
__int64 v7; // rax

if ( !a1 )
_assert_fail("h != NULL", "src/nn_heap.c", 0x40u, "nn_heap_push");
v2 = *(_DWORD *)(a1 + 8);
v3 = *(_DWORD *)(a1 + 12);
v4 = *(_QWORD **)a1;
if ( v2 < v3 )
goto LABEL_6;
v5 = 2 * v3;
v6 = realloc(*(void **)a1, 8 * v5);
*(_QWORD *)a1 = v6;
v4 = v6;
if ( v6 )
{
v7 = *(unsigned int *)(a1 + 12);
v2 = *(_DWORD *)(a1 + 8);
if ( (unsigned int)v5 > (unsigned int)v7 )
{
memset(&v4[v7], 0, 8LL * (unsigned int)(v5 - v7));
*(_DWORD *)(a1 + 12) = v5;
}
LABEL_6:
v4[v2] = a2;
bubble_up((_QWORD *)a1, v2);
++*(_DWORD *)(a1 + 8);
return 0LL;
}
*_errno_location() = 12;
return 4294967284LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
unsigned int v3; // eax
_QWORD *v4; // rbp
__int64 v5; // r13
_QWORD *v6; // rax
__int64 v7; // rax

if ( !a1 )
_assert_fail("h != NULL", "src/nn_heap.c", 0x40u, "nn_heap_push");
v2 = *(_DWORD *)(a1 + 8);
v3 = *(_DWORD *)(a1 + 12);
v4 = *(_QWORD **)a1;
if ( v2 < v3 )
goto LABEL_6;
v5 = 2 * v3;
v6 = realloc(*(void **)a1, 8 * v5);
*(_QWORD *)a1 = v6;
v4 = v6;
if ( v6 )
{
v7 = *(unsigned int *)(a1 + 12);
v2 = *(_DWORD *)(a1 + 8);
if ( (unsigned int)v5 > (unsigned int)v7 )
{
memset(&v4[v7], 0, 8LL * (unsigned int)(v5 - v7));
*(_DWORD *)(a1 + 12) = v5;
}
LABEL_6:
v4[v2] = a2;
func3((_QWORD *)a1, v2);
++*(_DWORD *)(a1 + 8);
return 0LL;
}
*_errno_location() = 12;
return 4294967284LL;
}

original_code:
int
nn_heap_push(struct nn_heap *h, struct nn_entry *e)
{
    unsigned u;
    ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "src/nn_heap.c", 64, __extension__ __PRETTY_FUNCTION__); }));
    if (h->next >= h->length) {
        u = h->length*2;
        h->entries = realloc(h->entries, u * sizeof *h->entries);
        if (!h->entries) {
            (*__errno_location ()) = 12;
            return -(*__errno_location ());
        }
        while (h->length < u)
            h->entries[h->length++] = ((void *)0);
    }
    h->entries[h->next] = e;
    bubble_up(h, h->next);
    h->next++;
    return 0;
}

canonical_original_code:
int nn_heap_push(struct nn_heap *h, struct nn_entry *e)
{
    unsigned int u;
    ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "src/nn_heap.c", 64, __extension__ __PRETTY_FUNCTION__); }));
    if (h->next >= h->length) {
        u = h->length*2;
        h->entries = realloc(h->entries, u * sizeof *h->entries);
        if (!h->entries) {
            (*__errno_location ()) = 12;
            return -(*__errno_location ());
        }
        while (h->length < u)
            h->entries[h->length++] = ((void *)0);
    }
    h->entries[h->next] = e;
    bubble_up(h, h->next);
    h->next++;
    return 0;
}

variable_types: struct nn_heap { struct nn_entry { struct Node { int count; int level; struct Branch { struct Rect { double boundary[-1]; } rect; struct Node *child; } branch[-1]; } *node; int hasData; double minDist; } **entries; unsigned int next; unsigned int length; } *

variable_types:
e
struct nn_entry *

variable_types:
u
unsigned int

return_type: int

user_defined_types: struct nn_heap { struct nn_entry **entries; unsigned int next; unsigned int length; }

user_defined_types: struct nn_entry { struct Node *node; int hasData; double minDist; }

user_defined_types: struct Node { int count; int level; struct Branch branch[-1]; }

user_defined_types: struct Branch { struct Rect rect; struct Node *child; }


decompiled_code:
__int64 __fastcall nn_heap_first(__int64 a1)
{
if ( !a1 )
_assert_fail("h != NULL", "src/nn_heap.c", 0x54u, "nn_heap_first");
return *(_QWORD *)(*(_QWORD *)a1 + 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
if ( !a1 )
_assert_fail("h != NULL", "src/nn_heap.c", 0x54u, "nn_heap_first");
return *(_QWORD *)(*(_QWORD *)a1 + 8LL);
}

original_code:
struct nn_entry *
nn_heap_first(struct nn_heap *h)
{
    ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "src/nn_heap.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    return h->entries[1];
}

canonical_original_code:
struct nn_entry *nn_heap_first(struct nn_heap *h)
{
    ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "src/nn_heap.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    return h->entries[1];
}

variable_types: struct nn_heap { struct nn_entry **entries; unsigned int next; unsigned int length; } *

return_type: struct nn_entry { struct Node { int count; int level; struct Branch { struct Rect { double boundary[-1]; } rect; struct Node *child; } branch[-1]; } *node; int hasData; double minDist; } *


decompiled_code:
__int64 __fastcall nn_heap_pop(_DWORD *a1)
{
unsigned int v1; // eax
__int64 v2; // r12
__int64 v3; // rdx
unsigned int v4; // eax

v1 = a1[2];
v2 = 0LL;
if ( v1 > 1 )
{
v3 = *(_QWORD *)a1;
v4 = v1 - 1;
v2 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
a1[2] = v4;
*(_QWORD *)(v3 + 8) = *(_QWORD *)(v3 + 8LL * v4);
bubble_down_constprop_0((__int64)a1);
}
return v2;
}

original_code:
struct nn_entry *
nn_heap_pop(struct nn_heap *h)
{
    struct nn_entry *e = ((void *)0);
    if (h->next > 1) {
        e = h->entries[1];
        h->entries[1] = h->entries[--h->next];
        bubble_down(h, 1);
    }
    return e;
}

canonical_original_code:
struct nn_entry *nn_heap_pop(struct nn_heap *h)
{
    struct nn_entry *e = ((void *)0);
    if (h->next > 1) {
        e = h->entries[1];
        h->entries[1] = h->entries[--h->next];
        bubble_down(h, 1);
    }
    return e;
}

variable_types: struct nn_entry { struct Node { int count; int level; struct Branch { struct Rect { double boundary[-1]; } rect; struct Node *child; } branch[-1]; } *node; int hasData; double minDist; } *


RTreeFreeListNode

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

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

original_code:
static void RTreeFreeListNode(struct ListNode *p)
{
    free(p);
}

variable_types: struct ListNode { struct ListNode *next; struct Node { int count; int level; struct Branch { struct Rect { double boundary[-1]; } rect; struct Node *child; } branch[-1]; } *node; } *

return_type: void

user_defined_types: struct ListNode { struct ListNode *next; struct Node *node; }


original_code:
static int RTreeInsertRect2(
        struct Rect *r,
        long tid,
        struct Node *n,
        struct Node **new_node,
        int level
    )
{
    register int i;
    struct Branch b;
    struct Node *n2;
    ((void) sizeof ((r && n && new_node) ? 1 : 0), __extension__ ({ if (r && n && new_node) ; else __assert_fail ("r && n && new_node", "src/index.c", 166, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((level >= 0 && level <= n->level) ? 1 : 0), __extension__ ({ if (level >= 0 && level <= n->level) ; else __assert_fail ("level >= 0 && level <= n->level", "src/index.c", 167, __extension__ __PRETTY_FUNCTION__); }));
    if (n->level > level)
    {
        i = RTreePickBranch(r, n);
        if (!RTreeInsertRect2(r, tid, n->branch[i].child, &n2, level))
        {
            n->branch[i].rect =
                RTreeCombineRect(r,&(n->branch[i].rect));
            return 0;
        }
        else
        {
            n->branch[i].rect = RTreeNodeCover(n->branch[i].child);
            b.child = n2;
            b.rect = RTreeNodeCover(n2);
            return RTreeAddBranch(&b, n, new_node);
        }
    }
    else if (n->level == level)
    {
        b.rect = *r;
        b.child = (struct Node *) tid;
        return RTreeAddBranch(&b, n, new_node);
    }
    else
    {
        ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/index.c", 200, __extension__ __PRETTY_FUNCTION__); }));
        return 0;
    }
}

canonical_original_code:
static int RTreeInsertRect2(struct Rect *r, long tid, struct Node *n, struct Node **new_node, int level)
{
    register int i;
    struct Branch b;
    struct Node *n2;
    ((void) sizeof ((r && n && new_node) ? 1 : 0), __extension__ ({ if (r && n && new_node) ; else __assert_fail ("r && n && new_node", "src/index.c", 166, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((level >= 0 && level <= n->level) ? 1 : 0), __extension__ ({ if (level >= 0 && level <= n->level) ; else __assert_fail ("level >= 0 && level <= n->level", "src/index.c", 167, __extension__ __PRETTY_FUNCTION__); }));
    if (n->level > level)
    {
        i = RTreePickBranch(r, n);
        if (!RTreeInsertRect2(r, tid, n->branch[i].child, &n2, level))
        {
            n->branch[i].rect =
                RTreeCombineRect(r,&(n->branch[i].rect));
            return 0;
        }
        else
        {
            n->branch[i].rect = RTreeNodeCover(n->branch[i].child);
            b.child = n2;
            b.rect = RTreeNodeCover(n2);
            return RTreeAddBranch(&b, n, new_node);
        }
    }
    else if (n->level == level)
    {
        b.rect = *r;
        b.child = (struct Node *) tid;
        return RTreeAddBranch(&b, n, new_node);
    }
    else
    {
        ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/index.c", 200, __extension__ __PRETTY_FUNCTION__); }));
        return 0;
    }
}

variable_types:
r
struct Rect { double boundary[-1]; } *

variable_types: tid long

variable_types: struct Node { int count; int level; struct Branch { struct Rect rect; struct Node *child; } branch[-1]; } *

variable_types: level int

variable_types: i int

variable_types: struct Branch { struct Rect { double boundary[-1]; } rect; struct Node { int count; int level; struct Branch branch[-1]; } *child; }

variable_types: struct Node { int count; int level; struct Branch { struct Rect { double boundary[-1]; } rect; struct Node *child; } branch[-1]; } *


RTreeNewListNode

decompiled_code:
void *RTreeNewListNode()
{
return malloc(0x10uLL);
}

canonical_decompiled_code:
void *func2()
{
return malloc(0x10uLL);
}

original_code:
static struct ListNode * RTreeNewListNode()
{
    return (struct ListNode *) malloc(sizeof(struct ListNode));
}

canonical_original_code:
static struct ListNode *RTreeNewListNode()
{
    return (struct ListNode *) malloc(sizeof(struct ListNode));
}

return_type: struct ListNode { struct ListNode *next; struct Node { int count; int level; struct Branch { struct Rect { double boundary[-1]; } rect; struct Node *child; } branch[-1]; } *node; } *


decompiled_code:
__int64 __fastcall RTreeDeleteRect2(__int64 a1, __int64 a2, __int64 a3, __int64 *a4)
{
int v5; // er8
__int64 v8; // rbx
int v9; // ebp
__int64 v10; // rbx
int *v11; // rdi
unsigned int v12; // er8
_QWORD *v13; // rax
__int64 v14; // rsi
__m128i v16; // [rsp+10h] [rbp-58h] BYREF
__m128i v17[4]; // [rsp+20h] [rbp-48h] BYREF

if ( !a1 || !a3 )
_assert_fail("r && n && ee", "src/index.c", 0x135u, "RTreeDeleteRect2");
v5 = *(_DWORD *)(a3 + 4);
if ( v5 < 0 )
_assert_fail("n->level >= 0", "src/index.c", 0x137u, "RTreeDeleteRect2");
if ( v5 )
{
if ( NODECARD > 0 )
{
v8 = a3 + 8;
v9 = 0;
while ( !*(_QWORD *)(v8 + 32)
|| !(unsigned int)RTreeOverlap(a1, v8)
|| (unsigned int)RTreeDeleteRect2(a1, a2, *(_QWORD *)(v8 + 32), a4) )
{
++v9;
v8 += 40LL;
if ( NODECARD <= v9 )
return 1;
}
v10 = a3 + 40LL * v9;
v11 = *(int **)(v10 + 40);
if ( *v11 < NODECARD / 2 )
{
RTreeReInsert((__int64)v11, a4);
RTreeDisconnectBranch(a3, (unsigned int)v9);
v12 = 0;
}
else
{
RTreeNodeCover(&v16, *(_QWORD *)(v10 + 40));
v12 = 0;
*(__m128i *)(v10 + 8) = _mm_loadu_si128(&v16);
*(__m128i *)(v10 + 24) = _mm_loadu_si128(v17);
}
return v12;
}
return 1;
}
v13 = (_QWORD *)(a3 + 40);
v14 = 0LL;
if ( LEAFCARD <= 0 )
return 1;
while ( !*v13 || *v13 != a2 )
{
v14 = (unsigned int)(v14 + 1);
v13 += 5;
if ( (_DWORD)v14 == LEAFCARD )
return 1;
}
RTreeDisconnectBranch(a3, v14);
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 *a4)
{
int v5; // er8
__int64 v8; // rbx
int v9; // ebp
__int64 v10; // rbx
int *v11; // rdi
unsigned int v12; // er8
_QWORD *v13; // rax
__int64 v14; // rsi
__m128i v16; // [rsp+10h] [rbp-58h] BYREF
__m128i v17[4]; // [rsp+20h] [rbp-48h] BYREF

if ( !a1 || !a3 )
_assert_fail("r && n && ee", "src/index.c", 0x135u, "RTreeDeleteRect2");
v5 = *(_DWORD *)(a3 + 4);
if ( v5 < 0 )
_assert_fail("n->level >= 0", "src/index.c", 0x137u, "RTreeDeleteRect2");
if ( v5 )
{
if ( NODECARD > 0 )
{
v8 = a3 + 8;
v9 = 0;
while ( !*(_QWORD *)(v8 + 32)
|| !(unsigned int)RTreeOverlap(a1, v8)
|| (unsigned int)func3(a1, a2, *(_QWORD *)(v8 + 32), a4) )
{
++v9;
v8 += 40LL;
if ( NODECARD <= v9 )
return 1;
}
v10 = a3 + 40LL * v9;
v11 = *(int **)(v10 + 40);
if ( *v11 < NODECARD / 2 )
{
RTreeReInsert((__int64)v11, a4);
RTreeDisconnectBranch(a3, (unsigned int)v9);
v12 = 0;
}
else
{
RTreeNodeCover(&v16, *(_QWORD *)(v10 + 40));
v12 = 0;
*(__m128i *)(v10 + 8) = _mm_loadu_si128(&v16);
*(__m128i *)(v10 + 24) = _mm_loadu_si128(v17);
}
return v12;
}
return 1;
}
v13 = (_QWORD *)(a3 + 40);
v14 = 0LL;
if ( LEAFCARD <= 0 )
return 1;
while ( !*v13 || *v13 != a2 )
{
v14 = (unsigned int)(v14 + 1);
v13 += 5;
if ( (_DWORD)v14 == LEAFCARD )
return 1;
}
RTreeDisconnectBranch(a3, v14);
return 0;
}

original_code:
static int
RTreeDeleteRect2(
        struct Rect *R,
        long Tid,
        struct Node *N,
        struct ListNode **Ee
    )
{
    register struct Rect *r = R;
    register long tid = Tid;
    register struct Node *n = N;
    register struct ListNode **ee = Ee;
    register int i;
    ((void) sizeof ((r && n && ee) ? 1 : 0), __extension__ ({ if (r && n && ee) ; else __assert_fail ("r && n && ee", "src/index.c", 309, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((tid >= 0) ? 1 : 0), __extension__ ({ if (tid >= 0) ; else __assert_fail ("tid >= 0", "src/index.c", 310, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->level >= 0) ? 1 : 0), __extension__ ({ if (n->level >= 0) ; else __assert_fail ("n->level >= 0", "src/index.c", 311, __extension__ __PRETTY_FUNCTION__); }));
    if (n->level > 0)
    {
        for (i = 0; i < NODECARD; i++)
        {
        if (n->branch[i].child && RTreeOverlap(r, &(n->branch[i].rect)))
        {
            if (!RTreeDeleteRect2(r, tid, n->branch[i].child, ee))
            {
                if (n->branch[i].child->count >= (NODECARD / 2))
                    n->branch[i].rect = RTreeNodeCover(
                        n->branch[i].child);
                else
                {
                    RTreeReInsert(n->branch[i].child, ee);
                    RTreeDisconnectBranch(n, i);
                }
                return 0;
            }
        }
        }
        return 1;
    }
    else
    {
        for (i = 0; i < LEAFCARD; i++)
        {
            if (n->branch[i].child &&
                n->branch[i].child == (struct Node *) tid)
            {
                RTreeDisconnectBranch(n, i);
                return 0;
            }
        }
        return 1;
    }
}

canonical_original_code:
static int RTreeDeleteRect2(struct Rect *R, long Tid, struct Node *N, struct ListNode **Ee)
{
    register struct Rect *r = R;
    register long tid = Tid;
    register struct Node *n = N;
    register struct ListNode **ee = Ee;
    register int i;
    ((void) sizeof ((r && n && ee) ? 1 : 0), __extension__ ({ if (r && n && ee) ; else __assert_fail ("r && n && ee", "src/index.c", 309, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((tid >= 0) ? 1 : 0), __extension__ ({ if (tid >= 0) ; else __assert_fail ("tid >= 0", "src/index.c", 310, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->level >= 0) ? 1 : 0), __extension__ ({ if (n->level >= 0) ; else __assert_fail ("n->level >= 0", "src/index.c", 311, __extension__ __PRETTY_FUNCTION__); }));
    if (n->level > 0)
    {
        for (i = 0; i < NODECARD; i++)
        {
        if (n->branch[i].child && RTreeOverlap(r, &(n->branch[i].rect)))
        {
            if (!RTreeDeleteRect2(r, tid, n->branch[i].child, ee))
            {
                if (n->branch[i].child->count >= (NODECARD / 2))
                    n->branch[i].rect = RTreeNodeCover(
                        n->branch[i].child);
                else
                {
                    RTreeReInsert(n->branch[i].child, ee);
                    RTreeDisconnectBranch(n, i);
                }
                return 0;
            }
        }
        }
        return 1;
    }
    else
    {
        for (i = 0; i < LEAFCARD; i++)
        {
            if (n->branch[i].child &&
                n->branch[i].child == (struct Node *) tid)
            {
                RTreeDisconnectBranch(n, i);
                return 0;
            }
        }
        return 1;
    }
}

variable_types:
R
struct Rect { double boundary[-1]; } *

variable_types: Tid long

variable_types: struct ListNode { struct ListNode *next; struct Node *node; } **

variable_types: struct ListNode { struct ListNode *next; struct Node { int count; int level; struct Branch { struct Rect { double boundary[-1]; } rect; struct Node *child; } branch[-1]; } *node; } **


RTreeNewIndex

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

result = RTreeNewNode();
*(_DWORD *)(result + 4) = 0;
return result;
}

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

result = RTreeNewNode();
*(_DWORD *)(result + 4) = 0;
return result;
}

original_code:
struct Node * RTreeNewIndex()
{
    struct Node *x;
    x = RTreeNewNode();
    x->level = 0;
    return x;
}

canonical_original_code:
struct Node *RTreeNewIndex()
{
    struct Node *x;
    x = RTreeNewNode();
    x->level = 0;
    return x;
}

return_type: struct Node { int count; int level; struct Branch { struct Rect { double boundary[-1]; } rect; struct Node *child; } branch[-1]; } *


RTreeSearch

decompiled_code:
__int64 __fastcall RTreeSearch(__int64 a1, __int64 a2, unsigned int (__fastcall *a3)(_QWORD, __int64), __int64 a4)
{
int v4; // er12
__int64 v7; // rbx
int i; // er15
__int64 v10; // rbx
int v11; // er15

if ( !a1 )
_assert_fail("n", "src/index.c", 0x6Bu, "RTreeSearch");
v4 = *(_DWORD *)(a1 + 4);
if ( v4 < 0 )
_assert_fail("n->level >= 0", "src/index.c", 0x6Cu, "RTreeSearch");
if ( !a2 )
_assert_fail("r", "src/index.c", 0x6Du, "RTreeSearch");
if ( v4 )
{
v4 = 0;
if ( NODECARD > 0 )
{
v10 = a1 + 8;
v11 = 0;
do
{
if ( *(_QWORD *)(v10 + 32) && (unsigned int)RTreeOverlap(a2, v10) )
v4 += RTreeSearch(*(_QWORD *)(v10 + 32), a2, a3, a4);
++v11;
v10 += 40LL;
}
while ( NODECARD > v11 );
}
}
else
{
v7 = a1 + 8;
for ( i = 0; LEAFCARD > i; v7 += 40LL )
{
if ( *(_QWORD *)(v7 + 32) )
{
if ( (unsigned int)RTreeOverlap(a2, v7) )
{
++v4;
if ( a3 )
{
if ( !a3(*(unsigned int *)(v7 + 32), a4) )
break;
}
}
}
++i;
}
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int (__fastcall *a3)(_QWORD, __int64), __int64 a4)
{
int v4; // er12
__int64 v7; // rbx
int i; // er15
__int64 v10; // rbx
int v11; // er15

if ( !a1 )
_assert_fail("n", "src/index.c", 0x6Bu, "RTreeSearch");
v4 = *(_DWORD *)(a1 + 4);
if ( v4 < 0 )
_assert_fail("n->level >= 0", "src/index.c", 0x6Cu, "RTreeSearch");
if ( !a2 )
_assert_fail("r", "src/index.c", 0x6Du, "RTreeSearch");
if ( v4 )
{
v4 = 0;
if ( NODECARD > 0 )
{
v10 = a1 + 8;
v11 = 0;
do
{
if ( *(_QWORD *)(v10 + 32) && (unsigned int)RTreeOverlap(a2, v10) )
v4 += func6(*(_QWORD *)(v10 + 32), a2, a3, a4);
++v11;
v10 += 40LL;
}
while ( NODECARD > v11 );
}
}
else
{
v7 = a1 + 8;
for ( i = 0; LEAFCARD > i; v7 += 40LL )
{
if ( *(_QWORD *)(v7 + 32) )
{
if ( (unsigned int)RTreeOverlap(a2, v7) )
{
++v4;
if ( a3 )
{
if ( !a3(*(unsigned int *)(v7 + 32), a4) )
break;
}
}
}
++i;
}
}
return (unsigned int)v4;
}

original_code:
int RTreeSearch(
        struct Node *N,
        struct Rect *R,
        SearchHitCallback shcb,
        void* cbarg
    )
{
    register struct Node *n = N;
    register struct Rect *r = R;
    register int hitCount = 0;
    register int i;
    ((void) sizeof ((n) ? 1 : 0), __extension__ ({ if (n) ; else __assert_fail ("n", "src/index.c", 107, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->level >= 0) ? 1 : 0), __extension__ ({ if (n->level >= 0) ; else __assert_fail ("n->level >= 0", "src/index.c", 108, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "src/index.c", 109, __extension__ __PRETTY_FUNCTION__); }));
    if (n->level > 0)
    {
        for (i=0; i<NODECARD; i++) {
            if (n->branch[i].child &&
                RTreeOverlap(r,&n->branch[i].rect))
            {
                hitCount += RTreeSearch(n->branch[i].child,
                                R, shcb, cbarg);
            }
        }
    }
    else
    {
        for (i=0; i<LEAFCARD; i++)
            if (n->branch[i].child &&
                    RTreeOverlap(r,&n->branch[i].rect))
            {
                hitCount++;
                if(shcb) {
                    if( ! shcb((long)n->branch[i].child, cbarg)) {
                        return hitCount;
                    }
                }
            }
    }
    return hitCount;
}

canonical_original_code:
int RTreeSearch(struct Node *N, struct Rect *R, int (*shcb)(int id, void *arg), void *cbarg)
{
    register struct Node *n = N;
    register struct Rect *r = R;
    register int hitCount = 0;
    register int i;
    ((void) sizeof ((n) ? 1 : 0), __extension__ ({ if (n) ; else __assert_fail ("n", "src/index.c", 107, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->level >= 0) ? 1 : 0), __extension__ ({ if (n->level >= 0) ; else __assert_fail ("n->level >= 0", "src/index.c", 108, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "src/index.c", 109, __extension__ __PRETTY_FUNCTION__); }));
    if (n->level > 0)
    {
        for (i=0; i<NODECARD; i++) {
            if (n->branch[i].child &&
                RTreeOverlap(r,&n->branch[i].rect))
            {
                hitCount += RTreeSearch(n->branch[i].child,
                                R, shcb, cbarg);
            }
        }
    }
    else
    {
        for (i=0; i<LEAFCARD; i++)
            if (n->branch[i].child &&
                    RTreeOverlap(r,&n->branch[i].rect))
            {
                hitCount++;
                if(shcb) {
                    if( ! shcb((long)n->branch[i].child, cbarg)) {
                        return hitCount;
                    }
                }
            }
    }
    return hitCount;
}

variable_types:
R
struct Rect *

variable_types:
shcb
int (*)(int id, void *arg)

variable_types:
cbarg
void *

variable_types: hitCount int


RTreeInsertRect

decompiled_code:
__int64 __fastcall RTreeInsertRect(__int64 a1, int a2, __int64 *a3, int a4)
{
__int64 v5; // rdx
__int64 result; // rax
__int64 v7; // rax
__int64 v8; // rsi
__int64 v9; // rbp
__int64 v10; // rax
__m128i v11; // xmm2
__m128i v12; // xmm4
__m128i v13; // [rsp+0h] [rbp-78h] BYREF
__m128i v14; // [rsp+10h] [rbp-68h] BYREF
__int64 v15; // [rsp+28h] [rbp-50h] BYREF
__m128i v16; // [rsp+30h] [rbp-48h] BYREF
__m128i v17; // [rsp+40h] [rbp-38h]
__int64 v18; // [rsp+50h] [rbp-28h]

if ( !a1 || !a3 )
_assert_fail("r && root", "src/index.c", 0xE8u, "RTreeInsertRect");
if ( a4 < 0 || (v5 = *a3, *(_DWORD *)(v5 + 4) < a4) )
_assert_fail("level >= 0 && level <= (*root)->level", "src/index.c", 0xE9u, "RTreeInsertRect");
if ( *(double *)(a1 + 16) < *(double *)a1 || *(double *)(a1 + 24) < *(double *)(a1 + 8) )
_assert_fail("r->boundary[i] <= r->boundary[NUMDIMS+i]", "src/index.c", 0xEBu, "RTreeInsertRect");
result = RTreeInsertRect2((const __m128i *)a1, a2, v5, (__int64)&v15, a4);
if ( (_DWORD)result )
{
v7 = RTreeNewNode();
v8 = *a3;
v9 = v7;
*(_DWORD *)(v7 + 4) = *(_DWORD *)(*a3 + 4) + 1;
RTreeNodeCover(&v13, v8);
v10 = *a3;
v11 = _mm_loadu_si128(&v14);
v16 = _mm_loadu_si128(&v13);
v17 = v11;
v18 = v10;
RTreeAddBranch(&v16, v9, 0LL);
RTreeNodeCover(&v13, v15);
v12 = _mm_loadu_si128(&v14);
v16 = _mm_loadu_si128(&v13);
v18 = v15;
v17 = v12;
RTreeAddBranch(&v16, v9, 0LL);
*a3 = v9;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, __int64 *a3, int a4)
{
__int64 v5; // rdx
__int64 result; // rax
__int64 v7; // rax
__int64 v8; // rsi
__int64 v9; // rbp
__int64 v10; // rax
__m128i v11; // xmm2
__m128i v12; // xmm4
__m128i v13; // [rsp+0h] [rbp-78h] BYREF
__m128i v14; // [rsp+10h] [rbp-68h] BYREF
__int64 v15; // [rsp+28h] [rbp-50h] BYREF
__m128i v16; // [rsp+30h] [rbp-48h] BYREF
__m128i v17; // [rsp+40h] [rbp-38h]
__int64 v18; // [rsp+50h] [rbp-28h]

if ( !a1 || !a3 )
_assert_fail("r && root", "src/index.c", 0xE8u, "RTreeInsertRect");
if ( a4 < 0 || (v5 = *a3, *(_DWORD *)(v5 + 4) < a4) )
_assert_fail("level >= 0 && level <= (*root)->level", "src/index.c", 0xE9u, "RTreeInsertRect");
if ( *(double *)(a1 + 16) < *(double *)a1 || *(double *)(a1 + 24) < *(double *)(a1 + 8) )
_assert_fail("r->boundary[i] <= r->boundary[NUMDIMS+i]", "src/index.c", 0xEBu, "RTreeInsertRect");
result = func1((const __m128i *)a1, a2, v5, (__int64)&v15, a4);
if ( (_DWORD)result )
{
v7 = RTreeNewNode();
v8 = *a3;
v9 = v7;
*(_DWORD *)(v7 + 4) = *(_DWORD *)(*a3 + 4) + 1;
RTreeNodeCover(&v13, v8);
v10 = *a3;
v11 = _mm_loadu_si128(&v14);
v16 = _mm_loadu_si128(&v13);
v17 = v11;
v18 = v10;
RTreeAddBranch(&v16, v9, 0LL);
RTreeNodeCover(&v13, v15);
v12 = _mm_loadu_si128(&v14);
v16 = _mm_loadu_si128(&v13);
v18 = v15;
v17 = v12;
RTreeAddBranch(&v16, v9, 0LL);
*a3 = v9;
result = 1LL;
}
return result;
}

original_code:
int RTreeInsertRect(
        struct Rect *R,
        int Tid,
        struct Node **Root,
        int Level
    )
{
    register struct Rect *r = R;
    register int tid = Tid;
    register struct Node **root = Root;
    register int level = Level;
    register int i;
    register struct Node *newroot;
    struct Node *newnode;
    struct Branch b;
    int result;
    ((void) sizeof ((r && root) ? 1 : 0), __extension__ ({ if (r && root) ; else __assert_fail ("r && root", "src/index.c", 232, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((level >= 0 && level <= (*root)->level) ? 1 : 0), __extension__ ({ if (level >= 0 && level <= (*root)->level) ; else __assert_fail ("level >= 0 && level <= (*root)->level", "src/index.c", 233, __extension__ __PRETTY_FUNCTION__); }));
    for (i=0; i<2; i++) {
        ((void) sizeof ((r->boundary[i] <= r->boundary[2 +i]) ? 1 : 0), __extension__ ({ if (r->boundary[i] <= r->boundary[2 +i]) ; else __assert_fail ("r->boundary[i] <= r->boundary[NUMDIMS+i]", "src/index.c", 235, __extension__ __PRETTY_FUNCTION__); }));
    }
    if (RTreeInsertRect2(r, tid, *root, &newnode, level)) {
        newroot = RTreeNewNode();
        newroot->level = (*root)->level + 1;
        b.rect = RTreeNodeCover(*root);
        b.child = *root;
        RTreeAddBranch(&b, newroot, ((void *)0));
        b.rect = RTreeNodeCover(newnode);
        b.child = newnode;
        RTreeAddBranch(&b, newroot, ((void *)0));
        *root = newroot;
        result = 1;
    } else {
        result = 0;
    }
    return result;
}

canonical_original_code:
int RTreeInsertRect(struct Rect *R, int Tid, struct Node **Root, int Level)
{
    register struct Rect *r = R;
    register int tid = Tid;
    register struct Node **root = Root;
    register int level = Level;
    register int i;
    register struct Node *newroot;
    struct Node *newnode;
    struct Branch b;
    int result;
    ((void) sizeof ((r && root) ? 1 : 0), __extension__ ({ if (r && root) ; else __assert_fail ("r && root", "src/index.c", 232, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((level >= 0 && level <= (*root)->level) ? 1 : 0), __extension__ ({ if (level >= 0 && level <= (*root)->level) ; else __assert_fail ("level >= 0 && level <= (*root)->level", "src/index.c", 233, __extension__ __PRETTY_FUNCTION__); }));
    for (i=0; i<2; i++) {
        ((void) sizeof ((r->boundary[i] <= r->boundary[2 +i]) ? 1 : 0), __extension__ ({ if (r->boundary[i] <= r->boundary[2 +i]) ; else __assert_fail ("r->boundary[i] <= r->boundary[NUMDIMS+i]", "src/index.c", 235, __extension__ __PRETTY_FUNCTION__); }));
    }
    if (RTreeInsertRect2(r, tid, *root, &newnode, level)) {
        newroot = RTreeNewNode();
        newroot->level = (*root)->level + 1;
        b.rect = RTreeNodeCover(*root);
        b.child = *root;
        RTreeAddBranch(&b, newroot, ((void *)0));
        b.rect = RTreeNodeCover(newnode);
        b.child = newnode;
        RTreeAddBranch(&b, newroot, ((void *)0));
        *root = newroot;
        result = 1;
    } else {
        result = 0;
    }
    return result;
}

variable_types: Tid int

variable_types: struct Node { int count; int level; struct Branch { struct Rect rect; struct Node *child; } branch[-1]; } **

variable_types: Level int

variable_types: tid int

variable_types: struct Node { int count; int level; struct Branch { struct Rect { double boundary[-1]; } rect; struct Node *child; } branch[-1]; } **

variable_types: result int


RTreeDeleteRect

decompiled_code:
__int64 __fastcall RTreeDeleteRect(__int64 a1, int a2, __int64 *a3)
{
__int64 v4; // rdx
unsigned int v5; // er13
_QWORD *v6; // rax
__int64 v7; // rbp
int v8; // er14
int v9; // ecx
__int64 i; // rbx
__int64 v11; // rsi
int v12; // eax
void *v13; // r14
__int64 v14; // rdi
__int64 v15; // rdi
__int64 *v16; // rax
void *ptr; // [rsp+8h] [rbp-30h] BYREF

ptr = 0LL;
if ( !a1 || !a3 )
_assert_fail("r && nn", "src/index.c", 0x175u, "RTreeDeleteRect");
v4 = *a3;
if ( !v4 )
_assert_fail("*nn", "src/index.c", 0x176u, "RTreeDeleteRect");
if ( a2 < 0 )
_assert_fail("tid >= 0", "src/index.c", 0x177u, "RTreeDeleteRect");
v5 = RTreeDeleteRect2(a1, a2, v4, (__int64 *)&ptr);
if ( v5 )
return 1LL;
v6 = ptr;
if ( ptr )
{
do
{
v7 = v6[1];
v8 = 0;
v9 = *(_DWORD *)(v7 + 4);
for ( i = v7 + 8; ; i += 40LL )
{
v12 = NODECARD;
if ( v9 <= 0 )
v12 = LEAFCARD;
if ( v8 >= v12 )
break;
v11 = *(_QWORD *)(i + 32);
if ( v11 )
{
RTreeInsertRect(i, v11, a3, v9);
v9 = *(_DWORD *)(v7 + 4);
}
++v8;
}
v13 = ptr;
v14 = *((_QWORD *)ptr + 1);
ptr = *(void **)ptr;
RTreeFreeNode(v14);
RTreeFreeListNode(v13);
v6 = ptr;
}
while ( ptr );
}
else
{
v7 = 0LL;
}
v15 = *a3;
if ( *(_DWORD *)*a3 == 1 && *(int *)(v15 + 4) > 0 )
{
if ( NODECARD <= 0 )
{
if ( !v7 )
LABEL_25:
_assert_fail("tmp_nptr", "src/index.c", 0x19Du, "RTreeDeleteRect");
}
else
{
v16 = (__int64 *)(v15 + 40);
while ( 1 )
{
v7 = *v16;
if ( *v16 )
break;
v16 += 5;
if ( v16 == (__int64 *)(v15 + 40LL * (unsigned int)(NODECARD - 1) + 80) )
goto LABEL_25;
}
}
RTreeFreeNode(v15);
*a3 = v7;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, __int64 *a3)
{
__int64 v4; // rdx
unsigned int v5; // er13
_QWORD *v6; // rax
__int64 v7; // rbp
int v8; // er14
int v9; // ecx
__int64 i; // rbx
__int64 v11; // rsi
int v12; // eax
void *v13; // r14
__int64 v14; // rdi
__int64 v15; // rdi
__int64 *v16; // rax
void *ptr; // [rsp+8h] [rbp-30h] BYREF

ptr = 0LL;
if ( !a1 || !a3 )
_assert_fail("r && nn", "src/index.c", 0x175u, "RTreeDeleteRect");
v4 = *a3;
if ( !v4 )
_assert_fail("*nn", "src/index.c", 0x176u, "RTreeDeleteRect");
if ( a2 < 0 )
_assert_fail("tid >= 0", "src/index.c", 0x177u, "RTreeDeleteRect");
v5 = func3(a1, a2, v4, (__int64 *)&ptr);
if ( v5 )
return 1LL;
v6 = ptr;
if ( ptr )
{
do
{
v7 = v6[1];
v8 = 0;
v9 = *(_DWORD *)(v7 + 4);
for ( i = v7 + 8; ; i += 40LL )
{
v12 = NODECARD;
if ( v9 <= 0 )
v12 = LEAFCARD;
if ( v8 >= v12 )
break;
v11 = *(_QWORD *)(i + 32);
if ( v11 )
{
func7(i, v11, a3, v9);
v9 = *(_DWORD *)(v7 + 4);
}
++v8;
}
v13 = ptr;
v14 = *((_QWORD *)ptr + 1);
ptr = *(void **)ptr;
RTreeFreeNode(v14);
func0(v13);
v6 = ptr;
}
while ( ptr );
}
else
{
v7 = 0LL;
}
v15 = *a3;
if ( *(_DWORD *)*a3 == 1 && *(int *)(v15 + 4) > 0 )
{
if ( NODECARD <= 0 )
{
if ( !v7 )
LABEL_25:
_assert_fail("tmp_nptr", "src/index.c", 0x19Du, "RTreeDeleteRect");
}
else
{
v16 = (__int64 *)(v15 + 40);
while ( 1 )
{
v7 = *v16;
if ( *v16 )
break;
v16 += 5;
if ( v16 == (__int64 *)(v15 + 40LL * (unsigned int)(NODECARD - 1) + 80) )
goto LABEL_25;
}
}
RTreeFreeNode(v15);
*a3 = v7;
}
return v5;
}

original_code:
int RTreeDeleteRect(struct Rect *R, int Tid, struct Node**Nn)
{
    register struct Rect *r = R;
    register int tid = Tid;
    register struct Node **nn = Nn;
    register int i;
    register struct Node *tmp_nptr = ((void *)0);
    struct ListNode *reInsertList = ((void *)0);
    register struct ListNode *e;
    ((void) sizeof ((r && nn) ? 1 : 0), __extension__ ({ if (r && nn) ; else __assert_fail ("r && nn", "src/index.c", 373, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((*nn) ? 1 : 0), __extension__ ({ if (*nn) ; else __assert_fail ("*nn", "src/index.c", 374, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((tid >= 0) ? 1 : 0), __extension__ ({ if (tid >= 0) ; else __assert_fail ("tid >= 0", "src/index.c", 375, __extension__ __PRETTY_FUNCTION__); }));
    if (!RTreeDeleteRect2(r, tid, *nn, &reInsertList))
    {
        while (reInsertList)
        {
            tmp_nptr = reInsertList->node;
            for (i = 0; i < ((tmp_nptr)->level > 0 ? NODECARD : LEAFCARD); i++)
            {
                if (tmp_nptr->branch[i].child)
                {
                    RTreeInsertRect(
                        &(tmp_nptr->branch[i].rect),
                        (long)tmp_nptr->branch[i].child,
                        nn,
                        tmp_nptr->level);
                }
            }
            e = reInsertList;
            reInsertList = reInsertList->next;
            RTreeFreeNode(e->node);
            RTreeFreeListNode(e);
        }
        if ((*nn)->count == 1 && (*nn)->level > 0)
        {
            for (i = 0; i < NODECARD; i++)
            {
                tmp_nptr = (*nn)->branch[i].child;
                if(tmp_nptr)
                    break;
            }
            ((void) sizeof ((tmp_nptr) ? 1 : 0), __extension__ ({ if (tmp_nptr) ; else __assert_fail ("tmp_nptr", "src/index.c", 413, __extension__ __PRETTY_FUNCTION__); }));
            RTreeFreeNode(*nn);
            *nn = tmp_nptr;
        }
        return 0;
    }
    else
    {
        return 1;
    }
}

canonical_original_code:
int RTreeDeleteRect(struct Rect *R, int Tid, struct Node **Nn)
{
    register struct Rect *r = R;
    register int tid = Tid;
    register struct Node **nn = Nn;
    register int i;
    register struct Node *tmp_nptr = ((void *)0);
    struct ListNode *reInsertList = ((void *)0);
    register struct ListNode *e;
    ((void) sizeof ((r && nn) ? 1 : 0), __extension__ ({ if (r && nn) ; else __assert_fail ("r && nn", "src/index.c", 373, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((*nn) ? 1 : 0), __extension__ ({ if (*nn) ; else __assert_fail ("*nn", "src/index.c", 374, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((tid >= 0) ? 1 : 0), __extension__ ({ if (tid >= 0) ; else __assert_fail ("tid >= 0", "src/index.c", 375, __extension__ __PRETTY_FUNCTION__); }));
    if (!RTreeDeleteRect2(r, tid, *nn, &reInsertList))
    {
        while (reInsertList)
        {
            tmp_nptr = reInsertList->node;
            for (i = 0; i < ((tmp_nptr)->level > 0 ? NODECARD : LEAFCARD); i++)
            {
                if (tmp_nptr->branch[i].child)
                {
                    RTreeInsertRect(
                        &(tmp_nptr->branch[i].rect),
                        (long)tmp_nptr->branch[i].child,
                        nn,
                        tmp_nptr->level);
                }
            }
            e = reInsertList;
            reInsertList = reInsertList->next;
            RTreeFreeNode(e->node);
            RTreeFreeListNode(e);
        }
        if ((*nn)->count == 1 && (*nn)->level > 0)
        {
            for (i = 0; i < NODECARD; i++)
            {
                tmp_nptr = (*nn)->branch[i].child;
                if(tmp_nptr)
                    break;
            }
            ((void) sizeof ((tmp_nptr) ? 1 : 0), __extension__ ({ if (tmp_nptr) ; else __assert_fail ("tmp_nptr", "src/index.c", 413, __extension__ __PRETTY_FUNCTION__); }));
            RTreeFreeNode(*nn);
            *nn = tmp_nptr;
        }
        return 0;
    }
    else
    {
        return 1;
    }
}

variable_types:
r
struct Rect { double boundary[-1]; } *

variable_types: i int

variable_types: struct ListNode { struct ListNode *next; struct Node { int count; int level; struct Branch { struct Rect { double boundary[-1]; } rect; struct Node *child; } branch[-1]; } *node; } *


RTreeRectMinDistance

original_code:
RectReal RTreeRectMinDistance(struct Rect *R, RectReal pt[2])
{
    int i;
    RectReal ret = 0.0;
    for (i = 0; i < 2; i++) {
        if (pt[i] < R->boundary[i])
            ret += pow(R->boundary[i] - pt[i], 2.0);
        else if (pt[i] > R->boundary[i+2])
            ret += pow(pt[i] - R->boundary[i+2], 2.0);
    }
    return sqrt(ret);
}

canonical_original_code:
double RTreeRectMinDistance(struct Rect *R, double pt[2])
{
    int i;
    double ret = 0.0;
    for (i = 0; i < 2; i++) {
        if (pt[i] < R->boundary[i])
            ret += pow(R->boundary[i] - pt[i], 2.0);
        else if (pt[i] > R->boundary[i+2])
            ret += pow(pt[i] - R->boundary[i+2], 2.0);
    }
    return sqrt(ret);
}

variable_types:
R
struct Rect { double boundary[-1]; } *

variable_types:
pt
double [2]

variable_types: ret double

return_type: double


RTreeInitRect

decompiled_code:
void __fastcall RTreeInitRect(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 0LL;
}

original_code:
void RTreeInitRect(struct Rect *R)
{
    register struct Rect *r = R;
    register int i;
    for (i=0; i<2*2; i++)
        r->boundary[i] = (RectReal)0;
}

canonical_original_code:
void RTreeInitRect(struct Rect *R)
{
    register struct Rect *r = R;
    register int i;
    for (i=0; i<2*2; i++)
        r->boundary[i] = (double)0;
}


RTreePrintRect

decompiled_code:
int __fastcall RTreePrintRect(double *a1, unsigned int a2)
{
if ( !a1 )
_assert_fail("r", "src/rectangle.c", 0x87u, "RTreePrintRect");
RTreeTabIn(a2);
puts("rect:");
RTreeTabIn(a2 + 1);
printf("%f\t%f\n", *a1, a1[2]);
RTreeTabIn(a2 + 1);
return printf("%f\t%f\n", a1[1], a1[3]);
}

canonical_decompiled_code:
int __fastcall func3(double *a1, unsigned int a2)
{
if ( !a1 )
_assert_fail("r", "src/rectangle.c", 0x87u, "RTreePrintRect");
RTreeTabIn(a2);
puts("rect:");
RTreeTabIn(a2 + 1);
printf("%f\t%f\n", *a1, a1[2]);
RTreeTabIn(a2 + 1);
return printf("%f\t%f\n", a1[1], a1[3]);
}

original_code:
void RTreePrintRect(struct Rect *R, int depth)
{
    register struct Rect *r = R;
    register int i;
    ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "src/rectangle.c", 135, __extension__ __PRETTY_FUNCTION__); }));
    RTreeTabIn(depth);
    printf("rect:\n");
    for (i = 0; i < 2; i++) {
        RTreeTabIn(depth+1);
        printf("%f\t%f\n", r->boundary[i], r->boundary[i + 2]);
    }
}

variable_types: depth int


RTreeRectVolume

decompiled_code:
double __fastcall RTreeRectVolume(double *a1)
{
double v1; // xmm1_8
double result; // xmm0_8

if ( !a1 )
_assert_fail("r", "src/rectangle.c", 0x9Au, "RTreeRectVolume");
v1 = a1[2];
if ( *a1 > v1 )
return 0.0;
result = (a1[3] - a1[1]) * (v1 - *a1);
if ( result < 0.0 )
_assert_fail("volume >= 0.0", "src/rectangle.c", 0xA0u, "RTreeRectVolume");
return result;
}

canonical_decompiled_code:
double __fastcall func4(double *a1)
{
double v1; // xmm1_8
double result; // xmm0_8

if ( !a1 )
_assert_fail("r", "src/rectangle.c", 0x9Au, "RTreeRectVolume");
v1 = a1[2];
if ( *a1 > v1 )
return 0.0;
result = (a1[3] - a1[1]) * (v1 - *a1);
if ( result < 0.0 )
_assert_fail("volume >= 0.0", "src/rectangle.c", 0xA0u, "RTreeRectVolume");
return result;
}

original_code:
RectReal RTreeRectVolume(struct Rect *R)
{
    register struct Rect *r = R;
    register int i;
    register RectReal volume = (RectReal)1;
    ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "src/rectangle.c", 154, __extension__ __PRETTY_FUNCTION__); }));
    if (((r)->boundary[0] > (r)->boundary[2]))
        return (RectReal)0;
    for(i=0; i<2; i++)
        volume *= r->boundary[i+2] - r->boundary[i];
    ((void) sizeof ((volume >= 0.0) ? 1 : 0), __extension__ ({ if (volume >= 0.0) ; else __assert_fail ("volume >= 0.0", "src/rectangle.c", 160, __extension__ __PRETTY_FUNCTION__); }));
    return volume;
}

canonical_original_code:
double RTreeRectVolume(struct Rect *R)
{
    register struct Rect *r = R;
    register int i;
    register double volume = (RectReal)1;
    ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "src/rectangle.c", 154, __extension__ __PRETTY_FUNCTION__); }));
    if (((r)->boundary[0] > (r)->boundary[2]))
        return (double)0;
    for(i=0; i<2; i++)
        volume *= r->boundary[i+2] - r->boundary[i];
    ((void) sizeof ((volume >= 0.0) ? 1 : 0), __extension__ ({ if (volume >= 0.0) ; else __assert_fail ("volume >= 0.0", "src/rectangle.c", 160, __extension__ __PRETTY_FUNCTION__); }));
    return volume;
}

variable_types: volume double


RTreeRectSurfaceArea

decompiled_code:
double __fastcall RTreeRectSurfaceArea(double *a1)
{
double v1; // xmm1_8
double result; // xmm0_8
double v3; // xmm2_8

if ( !a1 )
_assert_fail("r", "src/rectangle.c", 0x120u, "RTreeRectSurfaceArea");
v1 = a1[2];
result = 0.0;
if ( *a1 <= v1 )
{
v3 = a1[3] - a1[1] + 0.0;
result = v1 - *a1 + v3 + v1 - *a1 + v3;
}
return result;
}

canonical_decompiled_code:
double __fastcall func6(double *a1)
{
double v1; // xmm1_8
double result; // xmm0_8
double v3; // xmm2_8

if ( !a1 )
_assert_fail("r", "src/rectangle.c", 0x120u, "RTreeRectSurfaceArea");
v1 = a1[2];
result = 0.0;
if ( *a1 <= v1 )
{
v3 = a1[3] - a1[1] + 0.0;
result = v1 - *a1 + v3 + v1 - *a1 + v3;
}
return result;
}

original_code:
RectReal RTreeRectSurfaceArea(struct Rect *R)
{
    register struct Rect *r = R;
    register int i, j;
    register RectReal sum = (RectReal)0;
    ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "src/rectangle.c", 288, __extension__ __PRETTY_FUNCTION__); }));
    if (((r)->boundary[0] > (r)->boundary[2]))
        return (RectReal)0;
    for (i=0; i<2; i++) {
        RectReal face_area = (RectReal)1;
        for (j=0; j<2; j++)
            if(i != j) {
                RectReal j_extent =
                    r->boundary[j+2] - r->boundary[j];
                face_area *= j_extent;
            }
        sum += face_area;
    }
    return 2 * sum;
}

canonical_original_code:
double RTreeRectSurfaceArea(struct Rect *R)
{
    register struct Rect *r = R;
    register int i; register int j;
    register double sum = (RectReal)0;
    ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "src/rectangle.c", 288, __extension__ __PRETTY_FUNCTION__); }));
    if (((r)->boundary[0] > (r)->boundary[2]))
        return (double)0;
    for (i=0; i<2; i++) {
        double face_area = (RectReal)1;
        for (j=0; j<2; j++)
            if(i != j) {
                double j_extent = r->boundary[j+2] - r->boundary[j];
                face_area *= j_extent;
            }
        sum += face_area;
    }
    return 2 * sum;
}

variable_types: j int

variable_types: sum double


RTreeOverlap

decompiled_code:
_BOOL8 __fastcall RTreeOverlap(double *a1, double *a2)
{
_BOOL8 result; // rax

if ( !a1 || !a2 )
_assert_fail("r && s", "src/rectangle.c", 0x155u, "RTreeOverlap");
if ( *a1 > a2[2] || *a2 > a1[2] || a1[1] > a2[3] )
result = 0LL;
else
result = a2[1] <= a1[3];
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(double *a1, double *a2)
{
_BOOL8 result; // rax

if ( !a1 || !a2 )
_assert_fail("r && s", "src/rectangle.c", 0x155u, "RTreeOverlap");
if ( *a1 > a2[2] || *a2 > a1[2] || a1[1] > a2[3] )
result = 0LL;
else
result = a2[1] <= a1[3];
return result;
}

original_code:
int RTreeOverlap(struct Rect *R, struct Rect *S)
{
    register struct Rect *r = R, *s = S;
    register int i, j;
    ((void) sizeof ((r && s) ? 1 : 0), __extension__ ({ if (r && s) ; else __assert_fail ("r && s", "src/rectangle.c", 341, __extension__ __PRETTY_FUNCTION__); }));
    for (i=0; i<2; i++)
    {
        j = i + 2;
        if (r->boundary[i] > s->boundary[j] ||
            s->boundary[i] > r->boundary[j])
        {
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
int RTreeOverlap(struct Rect *R, struct Rect *S)
{
    register struct Rect *r = R; register struct Rect *s = S;
    register int i; register int j;
    ((void) sizeof ((r && s) ? 1 : 0), __extension__ ({ if (r && s) ; else __assert_fail ("r && s", "src/rectangle.c", 341, __extension__ __PRETTY_FUNCTION__); }));
    for (i=0; i<2; i++)
    {
        j = i + 2;
        if (r->boundary[i] > s->boundary[j] ||
            s->boundary[i] > r->boundary[j])
        {
            return 0;
        }
    }
    return 1;
}

variable_types:
S
struct Rect *

variable_types:
s
struct Rect { double boundary[-1]; } *


RTreeContained

decompiled_code:
_BOOL8 __fastcall RTreeContained(double *a1, double *a2)
{
double v2; // xmm1_8
_BOOL8 result; // rax
double v4; // xmm3_8

if ( !a1 || !a2 )
_assert_fail("(long)r && (long)s", "src/rectangle.c", 0x16Bu, "RTreeContained");
v2 = a1[2];
result = 1LL;
if ( *a1 <= v2 )
{
v4 = a2[2];
result = 0LL;
if ( *a2 <= v4 && *a1 >= *a2 && v4 >= v2 && a1[1] >= a2[1] )
result = a2[3] >= a1[3];
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(double *a1, double *a2)
{
double v2; // xmm1_8
_BOOL8 result; // rax
double v4; // xmm3_8

if ( !a1 || !a2 )
_assert_fail("(long)r && (long)s", "src/rectangle.c", 0x16Bu, "RTreeContained");
v2 = a1[2];
result = 1LL;
if ( *a1 <= v2 )
{
v4 = a2[2];
result = 0LL;
if ( *a2 <= v4 && *a1 >= *a2 && v4 >= v2 && a1[1] >= a2[1] )
result = a2[3] >= a1[3];
}
return result;
}

original_code:
int RTreeContained(struct Rect *R, struct Rect *S)
{
    register struct Rect *r = R, *s = S;
    register int i, j, result;
    ((void) sizeof (((long)r && (long)s) ? 1 : 0), __extension__ ({ if ((long)r && (long)s) ; else __assert_fail ("(long)r && (long)s", "src/rectangle.c", 363, __extension__ __PRETTY_FUNCTION__); }));
    if (((r)->boundary[0] > (r)->boundary[2]))
        return 1;
    if (((s)->boundary[0] > (s)->boundary[2]))
        return 0;
    result = 1;
    for (i = 0; i < 2; i++)
    {
        j = i + 2;
        result = result
            && r->boundary[i] >= s->boundary[i]
            && r->boundary[j] <= s->boundary[j];
    }
    return result;
}

canonical_original_code:
int RTreeContained(struct Rect *R, struct Rect *S)
{
    register struct Rect *r = R; register struct Rect *s = S;
    register int i; register int j; register int result;
    ((void) sizeof (((long)r && (long)s) ? 1 : 0), __extension__ ({ if ((long)r && (long)s) ; else __assert_fail ("(long)r && (long)s", "src/rectangle.c", 363, __extension__ __PRETTY_FUNCTION__); }));
    if (((r)->boundary[0] > (r)->boundary[2]))
        return 1;
    if (((s)->boundary[0] > (s)->boundary[2]))
        return 0;
    result = 1;
    for (i = 0; i < 2; i++)
    {
        j = i + 2;
        result = result
            && r->boundary[i] >= s->boundary[i]
            && r->boundary[j] <= s->boundary[j];
    }
    return result;
}


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

result = 0LL;
if ( (unsigned int)(a2 - 2) <= 0x64 )
{
*a1 = a2;
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( (unsigned int)(a2 - 2) <= 0x64 )
{
*a1 = a2;
result = 1LL;
}
return result;
}

original_code:
static int set_max(int *which, int new_max)
{
    if(2 > new_max || new_max > (int)((4096 -(2*sizeof(int))) / sizeof(struct Branch)))
        return 0;
    *which = new_max;
    return 1;
}

variable_types:
which
int *


RTreeSetNodeMax

decompiled_code:
__int64 __fastcall RTreeSetNodeMax(int a1)
{
return set_max(&NODECARD, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return func0(&NODECARD, a1);
}

original_code:
int RTreeSetNodeMax(int new_max)
{
    return set_max(&NODECARD, new_max);
}


RTreeSetLeafMax

decompiled_code:
__int64 __fastcall RTreeSetLeafMax(int a1)
{
return set_max(&LEAFCARD, a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return func0(&LEAFCARD, a1);
}

original_code:
int RTreeSetLeafMax(int new_max)
{
    return set_max(&LEAFCARD, new_max);
}


RTreeGetNodeMax

decompiled_code:
__int64 RTreeGetNodeMax()
{
return (unsigned int)NODECARD;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)NODECARD;
}

original_code:
int RTreeGetNodeMax()
{
    return NODECARD;
}


RTreeGetLeafMax

decompiled_code:
__int64 RTreeGetLeafMax()
{
return (unsigned int)LEAFCARD;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)LEAFCARD;
}

original_code:
int RTreeGetLeafMax()
{
    return LEAFCARD;
}


repo: dayne/zunkfs

decompiled_code:
void __fastcall list_add_tail(_QWORD *a1, __int64 *a2)
{
_list_add(a1, *a2, a2);
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1, __int64 *a2)
{
func1(a1, *a2, a2);
}

original_code:
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
 __list_add(new, head->prev, head);
}

variable_types: struct list_head { struct list_head *prev; } *

variable_types:
head
struct list_head *


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

result = list_del(a1);
*a1 = (__int64)a1;
a1[1] = (__int64)a1;
return result;
}

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

result = func3(a1);
*a1 = (__int64)a1;
a1[1] = (__int64)a1;
return result;
}

original_code:
static inline void list_del_init(struct list_head *item)
{
 list_del(item);
 do { (item)->next = (item)->prev = (item); } while(0);
}

user_defined_types: struct list_head { struct list_head *prev; }


decompiled_code:
_BOOL8 __fastcall list_empty(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == a1;
}

original_code:
static inline int list_empty(const struct list_head *item)
{
 return item->next == item;
}

canonical_original_code:
static inline int list_empty(struct list_head *item)
{
 return item->next == item;
}


decompiled_code:
void __fastcall list_move_tail(_QWORD *a1, __int64 *a2)
{
list_del(a1);
list_add_tail(a1, a2);
}

canonical_decompiled_code:
void __fastcall func6(_QWORD *a1, __int64 *a2)
{
func3(a1);
func2(a1, a2);
}

original_code:
static inline void list_move_tail(struct list_head *item,
  struct list_head *head)
{
 list_del(item);
 list_add_tail(item, head);
}


decompiled_code:
_BOOL8 __fastcall is_cnode_dirty(__int64 a1)
{
return !list_empty(a1 + 65560);
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1)
{
return !func5(a1 + 65560);
}

original_code:
static inline int is_cnode_dirty(const struct chunk_node *cnode)
{
 return !list_empty(&cnode->dirty_entry);
}

canonical_original_code:
static inline int is_cnode_dirty(struct chunk_node *cnode)
{
 return !list_empty(&cnode->dirty_entry);
}

variable_types: struct chunk_node { unsigned char chunk_data[-1]; unsigned char *chunk_digest; struct chunk_node *parent; struct chunk_tree { struct chunk_node *root; unsigned int nr_leafs; unsigned int height; struct chunk_tree_operations { void (*free_private)(void *); int (*read_chunk)(unsigned char *chunk, unsigned char *digest); int (*write_chunk)(unsigned char *chunk, unsigned char *digest); } *ops; struct list_head { struct list_head *prev; } dirty_list; } *ctree; struct list_head dirty_entry; unsigned int ref_count; void *_private; } *

user_defined_types: struct chunk_node { unsigned char chunk_data[-1]; unsigned char *chunk_digest; struct chunk_node *parent; struct chunk_tree *ctree; struct list_head dirty_entry; unsigned int ref_count; void *_private; }

user_defined_types: struct chunk_tree { struct chunk_node *root; unsigned int nr_leafs; unsigned int height; struct chunk_tree_operations *ops; struct list_head dirty_list; }


decompiled_code:
void __fastcall mark_cnode_dirty(__int64 a1)
{
list_move_tail((_QWORD *)(a1 + 65560), (__int64 *)(*(_QWORD *)(a1 + 65552) + 24LL));
}

original_code:
static inline void mark_cnode_dirty(struct chunk_node *cnode)
{
 list_move_tail(&cnode->dirty_entry, &cnode->ctree->dirty_list);
}

user_defined_types: struct chunk_tree_operations { void (*free_private)(void *); int (*read_chunk)(unsigned char *chunk, unsigned char *digest); int (*write_chunk)(unsigned char *chunk, unsigned char *digest); }


decompiled_code:
_BOOL8 __fastcall IS_ERR(unsigned __int64 a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( _errptr <= a1 )
result = a1 < _errptr + 256LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(unsigned __int64 a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( _errptr <= a1 )
result = a1 < _errptr + 256LL;
return result;
}

original_code:
static inline int IS_ERR(const void *ptr)
{
 return ptr >= __errptr && ptr < __errptr + 256;
}

canonical_original_code:
static inline int IS_ERR(void *ptr)
{
 return ptr >= __errptr && ptr < __errptr + 256;
}

variable_types:
ptr
void *


decompiled_code:
__int64 __fastcall flush_chunk_node(_QWORD *a1)
{
__int64 result; // rax
__int64 v3; // rdi

result = is_cnode_dirty((__int64)a1);
if ( (_DWORD)result )
{
result = (*(__int64 (__fastcall **)(_QWORD *, _QWORD))(*(_QWORD *)(a1[8194] + 16LL) + 16LL))(a1, a1[0x2000]);
if ( (int)result >= 0 )
{
v3 = a1[8193];
if ( v3 )
mark_cnode_dirty(v3);
list_del_init(a1 + 8195);
result = 0LL;
}
}
return result;
}

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

result = func7((__int64)a1);
if ( (_DWORD)result )
{
result = (*(__int64 (__fastcall **)(_QWORD *, _QWORD))(*(_QWORD *)(a1[8194] + 16LL) + 16LL))(a1, a1[0x2000]);
if ( (int)result >= 0 )
{
v3 = a1[8193];
if ( v3 )
func8(v3);
func4(a1 + 8195);
result = 0LL;
}
}
return result;
}

original_code:
static int flush_chunk_node(struct chunk_node *cnode)
{
 int err;
 if (is_cnode_dirty(cnode)) {
  err = cnode->ctree->ops->write_chunk(cnode->chunk_data,
    cnode->chunk_digest);
  if (err < 0)
   return err;
  if (cnode->parent)
   mark_cnode_dirty(cnode->parent);
  list_del_init(&cnode->dirty_entry);
 }
 return 0;
}

variable_types: err int


decompiled_code:
void __fastcall new_chunk_node(__int64 a1, __int64 a2, int a3)
{
_QWORD *v4; // rax
_QWORD *v5; // r12
void *v6; // rax
unsigned int v7; // edx

if ( !a2 )
_assert_fail("chunk_digest != NULL", "chunk-tree.c", 0x19u, "new_chunk_node");
v4 = malloc(0x10038uLL);
v5 = v4;
if ( v4 )
{
v4[8198] = 0LL;
if ( a3 || (v6 = calloc(0xCCCuLL, 8uLL), (v5[8198] = v6) != 0LL) )
{
v5[8194] = a1;
v5[0x2000] = a2;
v5[8193] = 0LL;
list_head_init(v5 + 8195);
*((_DWORD *)v5 + 16394) = 0;
return;
}
free(v5);
v7 = 48;
}
else
{
v7 = 29;
}
_ERR_PTR(12, (__int64)"new_chunk_node", v7);
}

original_code:
static struct chunk_node *new_chunk_node(struct chunk_tree *ctree,
  unsigned char *chunk_digest, int leaf)
{
 struct chunk_node *cnode;
 int err;
 ((void) sizeof ((chunk_digest != ((void *)0)) ? 1 : 0), __extension__ ({ if (chunk_digest != ((void *)0)) ; else __assert_fail ("chunk_digest != NULL", "chunk-tree.c", 25, __extension__ __PRETTY_FUNCTION__); }));
 cnode = malloc(sizeof(struct chunk_node));
 if (!cnode)
  return __ERR_PTR(12, __FUNCTION__, 29);
 err = -12;
 cnode->_private = ((void *)0);
 if (!leaf) {
  cnode->_private = calloc(((1UL << 16) / 20), sizeof(void *));
  if (!cnode->_private)
   goto error;
 }
 cnode->ctree = ctree;
 cnode->chunk_digest = chunk_digest;
 cnode->parent = ((void *)0);
 list_head_init(&cnode->dirty_entry);
 cnode->ref_count = 0;
 return cnode;
error:
 free(cnode);
 return __ERR_PTR(-err, __FUNCTION__, 48);
}

variable_types:
ctree
struct chunk_tree *

variable_types: leaf int

return_type: struct chunk_node { unsigned char chunk_data[-1]; unsigned char *chunk_digest; struct chunk_node *parent; struct chunk_tree { struct chunk_node *root; unsigned int nr_leafs; unsigned int height; struct chunk_tree_operations { void (*free_private)(void *); int (*read_chunk)(unsigned char *chunk, unsigned char *digest); int (*write_chunk)(unsigned char *chunk, unsigned char *digest); } *ops; struct list_head { struct list_head *prev; } dirty_list; } *ctree; struct list_head dirty_entry; unsigned int ref_count; void *_private; } *


original_code:
static int grow_chunk_tree(struct chunk_tree *ctree)
{
 struct chunk_node *new_root;
 struct chunk_node *old_root;
 old_root = ctree->root;
 new_root = new_chunk_node(ctree, old_root->chunk_digest, 0);
 if (IS_ERR(new_root))
  return -__PTR_ERR(new_root, __FUNCTION__, 62);
 memset(new_root->chunk_data, 0, (1UL << 16));
 old_root->parent = new_root;
 old_root->chunk_digest = new_root->chunk_data;
 memcpy(old_root->chunk_digest, new_root->chunk_digest,
   20);
 mark_cnode_dirty(new_root);
 new_root->ref_count = 2;
 ((struct chunk_node **)(new_root)->_private)[0] = old_root;
 ctree->height ++;
 ctree->root = new_root;
 __put_chunk_node(old_root, ctree->height == 1);
 return 0;
}

variable_types: struct chunk_tree { struct chunk_node { unsigned char chunk_data[-1]; unsigned char *chunk_digest; struct chunk_node *parent; struct chunk_tree *ctree; struct list_head { struct list_head *prev; } dirty_entry; unsigned int ref_count; void *_private; } *root; unsigned int nr_leafs; unsigned int height; struct chunk_tree_operations { void (*free_private)(void *); int (*read_chunk)(unsigned char *chunk, unsigned char *digest); int (*write_chunk)(unsigned char *chunk, unsigned char *digest); } *ops; struct list_head dirty_list; } *


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

if ( **(_QWORD **)(a1 + 65552) == a1 )
return 0LL;
v1 = chunk_nr(*(_QWORD *)(a1 + 65544));
return (unsigned int)_chunk_nr(a1) + 3276 * v1;
}

original_code:
unsigned chunk_nr(const struct chunk_node *cnode)
{
 if (cnode == cnode->ctree->root)
  return 0;
 return ((1UL << 16) / 20) * chunk_nr(cnode->parent) +
  __chunk_nr(cnode);
}

canonical_original_code:
unsigned int chunk_nr(struct chunk_node *cnode)
{
 if (cnode == cnode->ctree->root)
  return 0;
 return ((1UL << 16) / 20) * chunk_nr(cnode->parent) +
  __chunk_nr(cnode);
}

return_type: unsigned int


decompiled_code:
void __fastcall put_chunk_node(void *a1)
{
_put_chunk_node(a1, 1);
}

canonical_decompiled_code:
void __fastcall func19(void *a1)
{
func13(a1, 1);
}

original_code:
void put_chunk_node(struct chunk_node *cnode)
{
 __put_chunk_node(cnode, 1);
}


original_code:
int init_chunk_tree(struct chunk_tree *ctree, unsigned nr_leafs,
  unsigned char *root_digest, struct chunk_tree_operations *ops)
{
 struct chunk_node *root;
 int err;
 if (!root_digest)
  return -22;
 list_head_init(&ctree->dirty_list);
 ctree->ops = ops;
 ctree->nr_leafs = nr_leafs;
 ctree->height = 0;
 nr_leafs -= !!nr_leafs;
 ctree->height = (fls(nr_leafs) - 1) / (fls(((1UL << 16) / 20)) - 1);
 ctree->height += !!nr_leafs;
 root = new_chunk_node(ctree, root_digest, !ctree->height);
 if (IS_ERR(root))
  return -__PTR_ERR(root, __FUNCTION__, 259);
 err = ctree->ops->read_chunk(root->chunk_data, root_digest);
 if (err < 0) {
  free(root);
  return err;
 }
 root->ref_count ++;
 ctree->root = root;
 return 0;
}

canonical_original_code:
int init_chunk_tree(struct chunk_tree *ctree, unsigned int nr_leafs, unsigned char *root_digest, struct chunk_tree_operations *ops)
{
 struct chunk_node *root;
 int err;
 if (!root_digest)
  return -22;
 list_head_init(&ctree->dirty_list);
 ctree->ops = ops;
 ctree->nr_leafs = nr_leafs;
 ctree->height = 0;
 nr_leafs -= !!nr_leafs;
 ctree->height = (fls(nr_leafs) - 1) / (fls(((1UL << 16) / 20)) - 1);
 ctree->height += !!nr_leafs;
 root = new_chunk_node(ctree, root_digest, !ctree->height);
 if (IS_ERR(root))
  return -__PTR_ERR(root, __FUNCTION__, 259);
 err = ctree->ops->read_chunk(root->chunk_data, root_digest);
 if (err < 0) {
  free(root);
  return err;
 }
 root->ref_count ++;
 ctree->root = root;
 return 0;
}

variable_types:
ops
struct chunk_tree_operations *


decompiled_code:
void __fastcall free_chunk_tree(__int64 *a1)
{
_QWORD *v1; // rbp
void *v2; // rdi

v1 = (_QWORD *)*a1;
if ( *(_DWORD *)(*a1 + 65576) != 1 )
_assert_fail("croot->ref_count == 1", "chunk-tree.c", 0x115u, "free_chunk_tree");
if ( is_cnode_dirty(*a1) )
flush_chunk_node(v1);
v2 = (void *)v1[8198];
if ( v2 )
free(v2);
free(v1);
}

canonical_decompiled_code:
void __fastcall func21(__int64 *a1)
{
_QWORD *v1; // rbp
void *v2; // rdi

v1 = (_QWORD *)*a1;
if ( *(_DWORD *)(*a1 + 65576) != 1 )
_assert_fail("croot->ref_count == 1", "chunk-tree.c", 0x115u, "free_chunk_tree");
if ( func7(*a1) )
func10(v1);
v2 = (void *)v1[8198];
if ( v2 )
free(v2);
free(v1);
}

original_code:
void free_chunk_tree(struct chunk_tree *ctree)
{
 struct chunk_node *croot = ctree->root;
 ((void) sizeof ((croot->ref_count == 1) ? 1 : 0), __extension__ ({ if (croot->ref_count == 1) ; else __assert_fail ("croot->ref_count == 1", "chunk-tree.c", 277, __extension__ __PRETTY_FUNCTION__); }));
 if (is_cnode_dirty(croot))
  flush_chunk_node(croot);
 if (croot->_private)
  free(croot->_private);
 free(croot);
}


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

while ( !list_empty(a1 + 24) )
{
result = flush_chunk_node((_QWORD *)(*(_QWORD *)(a1 + 32) - 65560LL));
if ( (_DWORD)result )
return result;
}
return 0LL;
}

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

while ( !func5(a1 + 24) )
{
result = func10((_QWORD *)(*(_QWORD *)(a1 + 32) - 65560LL));
if ( (_DWORD)result )
return result;
}
return 0LL;
}

original_code:
int flush_chunk_tree(struct chunk_tree *ctree)
{
 struct chunk_node *cnode;
 int error;
 while (!list_empty(&ctree->dirty_list)) {
  cnode = ((struct chunk_node *)((unsigned long)(ctree->dirty_list.next) - (unsigned long)&((struct chunk_node *)0)->dirty_entry));
  error = flush_chunk_node(cnode);
  if (error)
   return error;
 }
 return 0;
}

variable_types: error int


canonical_decompiled_code:
void __fastcall func1(_QWORD *a1, __int64 *a2)
{
func0(a1, *a2, a2);
}

canonical_original_code:
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
 __list_add(new, head->prev, head);
}


canonical_decompiled_code:
void __fastcall func3(_QWORD *a1, __int64 *a2)
{
func2(a1);
func1(a1, a2);
}

canonical_original_code:
static inline void list_move_tail(struct list_head *item, struct list_head *head)
{
 list_del(item);
 list_add_tail(item, head);
}


canonical_original_code:
static inline void mark_cnode_dirty(struct chunk_node *cnode)
{
 list_move_tail(&cnode->dirty_entry, &cnode->ctree->dirty_list);
}


canonical_decompiled_code:
_BOOL8 __fastcall func5(unsigned __int64 a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( _errptr <= a1 )
result = a1 < _errptr + 256LL;
return result;
}


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

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

original_code: static inline uint64_t le64toh(le64_t x) { return x.v; }

canonical_original_code: static inline unsigned long le64toh(struct le64_t x) { return x.v; }

variable_types:
x
struct le64_t { unsigned long v; }

return_type: unsigned long


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

result = 4042322160LL;
if ( *(_QWORD *)(a1 + 65584) != 4042322160LL )
_assert_fail("cnode->_private == CACHED_CHUNK_MAGIC", "file.c", 0x39u, "clear_cached");
*(_QWORD *)(a1 + 65584) = 0LL;
return result;
}

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

result = 4042322160LL;
if ( *(_QWORD *)(a1 + 65584) != 4042322160LL )
_assert_fail("cnode->_private == CACHED_CHUNK_MAGIC", "file.c", 0x39u, "clear_cached");
*(_QWORD *)(a1 + 65584) = 0LL;
return result;
}

original_code:
static inline void clear_cached(struct chunk_node *cnode)
{
 ((void) sizeof ((cnode->_private == ((void *)0xf0f0f0f0)) ? 1 : 0), __extension__ ({ if (cnode->_private == ((void *)0xf0f0f0f0)) ; else __assert_fail ("cnode->_private == CACHED_CHUNK_MAGIC", "file.c", 57, __extension__ __PRETTY_FUNCTION__); }));
 cnode->_private = ((void *)0);
}


decompiled_code:
__int64 __fastcall is_cached(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 65584);
LOBYTE(result) = v1 == 4042322160LL;
if ( v1 && v1 != 4042322160LL )
_assert_fail("cnode->_private == CACHED_CHUNK_MAGIC || cnode->_private == NULL", "file.c", 0x3Fu, "is_cached");
return (unsigned __int8)result;
}

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

v1 = *(_QWORD *)(a1 + 65584);
LOBYTE(result) = v1 == 4042322160LL;
if ( v1 && v1 != 4042322160LL )
_assert_fail("cnode->_private == CACHED_CHUNK_MAGIC || cnode->_private == NULL", "file.c", 0x3Fu, "is_cached");
return (unsigned __int8)result;
}

original_code:
static inline int is_cached(struct chunk_node *cnode)
{
 ((void) sizeof ((cnode->_private == ((void *)0xf0f0f0f0) || cnode->_private == ((void *)0)) ? 1 : 0), __extension__ ({ if (cnode->_private == ((void *)0xf0f0f0f0) || cnode->_private == ((void *)0)) ; else __assert_fail ("cnode->_private == CACHED_CHUNK_MAGIC || cnode->_private == NULL", "file.c", 63, __extension__ __PRETTY_FUNCTION__); }));
 return cnode->_private == ((void *)0xf0f0f0f0);
}


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

if ( *(_QWORD *)(a1 + 65584) )
_assert_fail("cnode->_private == NULL", "file.c", 0x33u, "set_cached");
result = 4042322160LL;
*(_QWORD *)(a1 + 65584) = 4042322160LL;
return result;
}

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

if ( *(_QWORD *)(a1 + 65584) )
_assert_fail("cnode->_private == NULL", "file.c", 0x33u, "set_cached");
result = 4042322160LL;
*(_QWORD *)(a1 + 65584) = 4042322160LL;
return result;
}

original_code:
static inline void set_cached(struct chunk_node *cnode)
{
 ((void) sizeof ((cnode->_private == ((void *)0)) ? 1 : 0), __extension__ ({ if (cnode->_private == ((void *)0)) ; else __assert_fail ("cnode->_private == NULL", "file.c", 51, __extension__ __PRETTY_FUNCTION__); }));
 cnode->_private = ((void *)0xf0f0f0f0);
}


decompiled_code:
__int64 __fastcall write_dir(_QWORD *a1, __int64 a2, unsigned __int64 a3, __int64 a4)
{
unsigned __int64 v7; // r12
__int64 result; // rax
int *v9; // r15
const char *v10; // rax
int *v11; // r15
__int64 v12; // [rsp-Eh] [rbp-C0h] BYREF
__int64 v13; // [rsp+32h] [rbp-80h] BYREF
int v14; // [rsp+76h] [rbp-3Ch]
const char *v15; // [rsp+7Ah] [rbp-38h]

if ( zunkfs_log_fp && zunkfs_log_level > 1 )
{
v11 = _errno_location();
LODWORD(v15) = *v11;
_zprintf(2LL, "write_dir", 261LL, "len=%zu off=%zu\n", a3, a4);
*v11 = (int)v15;
}
if ( a3 > 0xFF )
{
v7 = (unsigned __int8)(a3 | a4);
if ( !(_DWORD)v7 )
{
while ( le64toh(*(_QWORD *)(a2 + 44)) )
{
result = dup_disk_dentry(*a1, a2);
if ( (_DWORD)result )
return result;
if ( zunkfs_log_fp )
{
if ( zunkfs_log_level > 1 )
{
v9 = _errno_location();
v14 = *v9;
v15 = (const char *)_digest_string(a2 + 20, &v13);
v10 = (const char *)_digest_string(a2, &v12);
_zprintf(2LL, "write_dir", 279LL, "%s %s %s\n", (const char *)(a2 + 60), v10, v15);
*v9 = v14;
}
}
v7 += 256LL;
a2 += 256LL;
if ( a3 <= v7 )
return (unsigned int)v7;
}
}
}
return 4294967274LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, __int64 a2, unsigned __int64 a3, __int64 a4)
{
unsigned __int64 v7; // r12
__int64 result; // rax
int *v9; // r15
const char *v10; // rax
int *v11; // r15
__int64 v12; // [rsp-Eh] [rbp-C0h] BYREF
__int64 v13; // [rsp+32h] [rbp-80h] BYREF
int v14; // [rsp+76h] [rbp-3Ch]
const char *v15; // [rsp+7Ah] [rbp-38h]

if ( zunkfs_log_fp && zunkfs_log_level > 1 )
{
v11 = _errno_location();
LODWORD(v15) = *v11;
_zprintf(2LL, "write_dir", 261LL, "len=%zu off=%zu\n", a3, a4);
*v11 = (int)v15;
}
if ( a3 > 0xFF )
{
v7 = (unsigned __int8)(a3 | a4);
if ( !(_DWORD)v7 )
{
while ( func6(*(_QWORD *)(a2 + 44)) )
{
result = dup_disk_dentry(*a1, a2);
if ( (_DWORD)result )
return result;
if ( zunkfs_log_fp )
{
if ( zunkfs_log_level > 1 )
{
v9 = _errno_location();
v14 = *v9;
v15 = (const char *)_digest_string(a2 + 20, &v13);
v10 = (const char *)_digest_string(a2, &v12);
_zprintf(2LL, "write_dir", 279LL, "%s %s %s\n", (const char *)(a2 + 60), v10, v15);
*v9 = v14;
}
}
v7 += 256LL;
a2 += 256LL;
if ( a3 <= v7 )
return (unsigned int)v7;
}
}
}
return 4294967274LL;
}

original_code:
static int write_dir(struct open_file *ofile, const char *buf, size_t len,
  off_t offset)
{
 const struct disk_dentry *ddent;
 size_t total = 0;
 int err;
 ({ int ___ret = 0; if (zunkfs_log_fp && (2) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(2, __FUNCTION__, 261, "len=%zu off=%zu\n", len, (size_t)offset); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
 if (len < sizeof(struct disk_dentry))
  return -22;
 if (len % sizeof(struct disk_dentry))
  return -22;
 if (offset % sizeof(struct disk_dentry))
  return -22;
 while (total < len) {
  ddent = (struct disk_dentry *)(buf + total);
  if (!le64toh(ddent->size))
   return -22;
  err = dup_disk_dentry(ofile->dentry, ddent);
  if (err)
   return err;
  ({ int ___ret = 0; if (zunkfs_log_fp && (2) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(2, __FUNCTION__, 279, "%s %s %s\n", (char *)ddent->name, __digest_string(ddent->digest, __builtin_alloca ((20 * 2) + 1)), __digest_string(ddent->secret_digest, __builtin_alloca ((20 * 2) + 1))); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
  total += sizeof(struct disk_dentry);
 }
 return total;
}

canonical_original_code:
static int write_dir(struct open_file *ofile, char *buf, unsigned long len, long offset)
{
 struct disk_dentry *ddent;
 unsigned long total = 0;
 int err;
 ({ int ___ret = 0; if (zunkfs_log_fp && (2) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(2, __FUNCTION__, 261, "len=%zu off=%zu\n", len, (unsigned long)offset); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
 if (len < sizeof(struct disk_dentry))
  return -22;
 if (len % sizeof(struct disk_dentry))
  return -22;
 if (offset % sizeof(struct disk_dentry))
  return -22;
 while (total < len) {
  ddent = (struct disk_dentry *)(buf + total);
  if (!le64toh(ddent->size))
   return -22;
  err = dup_disk_dentry(ofile->dentry, ddent);
  if (err)
   return err;
  ({ int ___ret = 0; if (zunkfs_log_fp && (2) <= zunkfs_log_level) { int ___saved_errno = (*__errno_location ()); __zprintf(2, __FUNCTION__, 279, "%s %s %s\n", (char *)ddent->name, __digest_string(ddent->digest, __builtin_alloca ((20 * 2) + 1)), __digest_string(ddent->secret_digest, __builtin_alloca ((20 * 2) + 1))); (*__errno_location ()) = ___saved_errno; ___ret = 1; } ___ret; });
  total += sizeof(struct disk_dentry);
 }
 return total;
}

variable_types: struct open_file { struct dentry { struct disk_dentry { unsigned char digest[20]; unsigned char secret_digest[20]; struct le16_t { unsigned short v; } mode; unsigned char flags; unsigned char mtime_csec; struct le64_t { unsigned long v; } size; struct le32_t { unsigned int v; } ctime; struct le32_t mtime; unsigned char name[-1]; } *ddent; struct chunk_node { unsigned char chunk_data[-1]; unsigned char *chunk_digest; struct chunk_node *parent; struct chunk_tree { struct chunk_node *root; unsigned int nr_leafs; unsigned int height; struct chunk_tree_operations { void (*free_private)(void *); int (*read_chunk)(unsigned char *chunk, unsigned char *digest); int (*write_chunk)(unsigned char *chunk, unsigned char *digest); } *ops; struct list_head { struct list_head *prev; } dirty_list; } *ctree; struct list_head dirty_entry; unsigned int ref_count; void *_private; } *ddent_cnode; struct mutex { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned long owner; } *ddent_mutex; struct dentry *parent; struct mutex mutex; unsigned int ref_count; struct chunk_tree chunk_tree; unsigned char *secret_chunk; unsigned int dirty; unsigned long size; struct timeval { long tv_sec; long tv_usec; } mtime; unsigned int mode; } *dentry; struct chunk_node *ccache[-1]; unsigned int ccache_index; } *

variable_types:
buf
char *

variable_types:
len
unsigned long

variable_types: offset long

variable_types:
total
unsigned long

user_defined_types: struct disk_dentry { unsigned char digest[20]; unsigned char secret_digest[20]; struct le16_t mode; unsigned char flags; unsigned char mtime_csec; struct le64_t size; struct le32_t ctime; struct le32_t mtime; unsigned char name[-1]; }

user_defined_types: struct open_file { struct dentry *dentry; struct chunk_node *ccache[-1]; unsigned int ccache_index; }

user_defined_types: struct dentry { struct disk_dentry *ddent; struct chunk_node *ddent_cnode; struct mutex *ddent_mutex; struct dentry *parent; struct mutex mutex; unsigned int ref_count; struct chunk_tree chunk_tree; unsigned char *secret_chunk; unsigned int dirty; unsigned long size; struct timeval mtime; unsigned int mode; }

user_defined_types: struct mutex { union pthread_mutex_t mutex; unsigned long owner; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


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

if ( cachable_isra_0(*(_QWORD *)a1) && !(unsigned int)is_cached(a2) )
result = _cache_file_chunk(a1, a2);
else
result = put_chunk_node(a2);
return result;
}

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

if ( func13(*(_QWORD *)a1) && !(unsigned int)func8(a2) )
result = func15(a1, a2);
else
result = put_chunk_node(a2);
return result;
}

original_code:
static inline void cache_file_chunk(struct open_file *ofile,
  struct chunk_node *cnode)
{
 if (cachable(ofile) && !is_cached(cnode))
  __cache_file_chunk(ofile, cnode);
 else
  put_chunk_node(cnode);
}

variable_types:
cnode
struct chunk_node *

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

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


original_code:
static int rw_file(struct open_file *ofile, char *buf, size_t bufsz,
  off_t offset, int read)
{
 struct chunk_node *cnode;
 unsigned chunk_nr;
 unsigned chunk_off;
 uint64_t file_size;
 int len, cplen;
 file_size = ofile->dentry->size;
 if (((((ofile->dentry->mode)) & 0170000) == (0040000)))
  file_size *= sizeof(struct disk_dentry);
 if (offset > file_size)
  return -22;
 if (read && offset == file_size)
  return 0;
 if (bufsz > 0x7fffffff)
  return -22;
 if (read && (bufsz + offset) > file_size)
  bufsz = file_size - offset;
 chunk_nr = offset / (1UL << 16);
 chunk_off = offset % (1UL << 16);
 len = 0;
 while (len < bufsz) {
  cnode = get_dentry_chunk(ofile->dentry, chunk_nr);
  if (IS_ERR(cnode))
   return __PTR_ERR(cnode, __FUNCTION__, 219);
  cplen = bufsz - len;
  if (cplen > (1UL << 16) - chunk_off)
   cplen = (1UL << 16) - chunk_off;
  if (read) {
   if (cplen > file_size - len)
    cplen = file_size - len;
   memcpy(buf + len, cnode->chunk_data + chunk_off, cplen);
  } else {
   memcpy(cnode->chunk_data + chunk_off, buf + len, cplen);
   mark_cnode_dirty(cnode);
  }
  len += cplen;
  cache_file_chunk(ofile, cnode);
  chunk_nr ++;
  chunk_off = 0;
 }
 if (!read) {
  ((void) sizeof ((!((((ofile->dentry->mode)) & 0170000) == (0040000))) ? 1 : 0), __extension__ ({ if (!((((ofile->dentry->mode)) & 0170000) == (0040000))) ; else __assert_fail ("!S_ISDIR(ofile->dentry->mode)", "file.c", 241, __extension__ __PRETTY_FUNCTION__); }));
  if ((len + offset) > file_size)
   ofile->dentry->size = len + offset;
  gettimeofday(&ofile->dentry->mtime, ((void *)0));
  ofile->dentry->dirty = 1;
 }
 return len;
}

canonical_original_code:
static int rw_file(struct open_file *ofile, char *buf, unsigned long bufsz, long offset, int read)
{
 struct chunk_node *cnode;
 unsigned int chunk_nr;
 unsigned int chunk_off;
 unsigned long file_size;
 int len; int cplen;
 file_size = ofile->dentry->size;
 if (((((ofile->dentry->mode)) & 0170000) == (0040000)))
  file_size *= sizeof(struct disk_dentry);
 if (offset > file_size)
  return -22;
 if (read && offset == file_size)
  return 0;
 if (bufsz > 0x7fffffff)
  return -22;
 if (read && (bufsz + offset) > file_size)
  bufsz = file_size - offset;
 chunk_nr = offset / (1UL << 16);
 chunk_off = offset % (1UL << 16);
 len = 0;
 while (len < bufsz) {
  cnode = get_dentry_chunk(ofile->dentry, chunk_nr);
  if (IS_ERR(cnode))
   return __PTR_ERR(cnode, __FUNCTION__, 219);
  cplen = bufsz - len;
  if (cplen > (1UL << 16) - chunk_off)
   cplen = (1UL << 16) - chunk_off;
  if (read) {
   if (cplen > file_size - len)
    cplen = file_size - len;
   memcpy(buf + len, cnode->chunk_data + chunk_off, cplen);
  } else {
   memcpy(cnode->chunk_data + chunk_off, buf + len, cplen);
   mark_cnode_dirty(cnode);
  }
  len += cplen;
  cache_file_chunk(ofile, cnode);
  chunk_nr ++;
  chunk_off = 0;
 }
 if (!read) {
  ((void) sizeof ((!((((ofile->dentry->mode)) & 0170000) == (0040000))) ? 1 : 0), __extension__ ({ if (!((((ofile->dentry->mode)) & 0170000) == (0040000))) ; else __assert_fail ("!S_ISDIR(ofile->dentry->mode)", "file.c", 241, __extension__ __PRETTY_FUNCTION__); }));
  if ((len + offset) > file_size)
   ofile->dentry->size = len + offset;
  gettimeofday(&ofile->dentry->mtime, ((void *)0));
  ofile->dentry->dirty = 1;
 }
 return len;
}

variable_types:
bufsz
unsigned long

variable_types: read int

variable_types: len int

variable_types: cplen int


decompiled_code:
__int64 __fastcall release_cached_chunks(__int64 *a1)
{
__int64 result; // rax
__int64 *v2; // rbx
__int64 v3; // rbp

result = have_mutex_isra_0(*(_QWORD *)(*a1 + 72));
if ( !(_DWORD)result )
_assert_fail("have_mutex(&(ofile)->dentry->mutex)", "file.c", 0x79u, "release_cached_chunks");
v2 = a1 + 1;
do
{
v3 = *v2;
if ( *v2 )
{
clear_cached(*v2);
*v2 = 0LL;
result = put_chunk_node(v3);
}
++v2;
}
while ( v2 != a1 + 257 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 *a1)
{
__int64 result; // rax
__int64 *v2; // rbx
__int64 v3; // rbp

result = func14(*(_QWORD *)(*a1 + 72));
if ( !(_DWORD)result )
_assert_fail("have_mutex(&(ofile)->dentry->mutex)", "file.c", 0x79u, "release_cached_chunks");
v2 = a1 + 1;
do
{
v3 = *v2;
if ( *v2 )
{
func7(*v2);
*v2 = 0LL;
result = put_chunk_node(v3);
}
++v2;
}
while ( v2 != a1 + 257 );
return result;
}

original_code:
static void release_cached_chunks(struct open_file *ofile)
{
 struct chunk_node *cnode;
 int i;
 ((void) sizeof ((have_mutex(&(ofile)->dentry->mutex)) ? 1 : 0), __extension__ ({ if (have_mutex(&(ofile)->dentry->mutex)) ; else __assert_fail ("have_mutex(&(ofile)->dentry->mutex)", "file.c", 121, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < (16 * (1UL << 16) / 4096); i ++) {
  cnode = ofile->ccache[i];
  if (cnode) {
   clear_cached(cnode);
   ofile->ccache[i] = ((void *)0);
   put_chunk_node(cnode);
  }
 }
}

variable_types: struct chunk_node { unsigned char chunk_data[-1]; unsigned char *chunk_digest; struct chunk_node *parent; struct chunk_tree { struct chunk_node *root; unsigned int nr_leafs; unsigned int height; struct chunk_tree_operations { void (*free_private)(void *); int (*read_chunk)(unsigned char *chunk, unsigned char *digest); int (*write_chunk)(unsigned char *chunk, unsigned char *digest); } *ops; struct list_head { struct list_head *prev; } dirty_list; } *ctree; struct list_head dirty_entry; unsigned int ref_count; void *_private; } *

variable_types: i int


decompiled_code:
__int64 __fastcall close_file(void *ptr)
{
unsigned int v1; // er12
__int64 v3; // rdi
unsigned int v4; // eax

v1 = 0;
lock(*(_QWORD *)ptr + 32LL);
release_cached_chunks((__int64 *)ptr);
v3 = *(_QWORD *)ptr;
if ( *(_QWORD *)(v3 + 88) )
{
v4 = flush_chunk_tree(v3 + 88);
v3 = *(_QWORD *)ptr;
v1 = v4;
}
unlock(v3 + 32);
put_dentry(*(_QWORD *)ptr);
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func19(void *ptr)
{
unsigned int v1; // er12
__int64 v3; // rdi
unsigned int v4; // eax

v1 = 0;
lock(*(_QWORD *)ptr + 32LL);
func18((__int64 *)ptr);
v3 = *(_QWORD *)ptr;
if ( *(_QWORD *)(v3 + 88) )
{
v4 = flush_chunk_tree(v3 + 88);
v3 = *(_QWORD *)ptr;
v1 = v4;
}
unlock(v3 + 32);
put_dentry(*(_QWORD *)ptr);
free(ptr);
return v1;
}

original_code:
int close_file(struct open_file *ofile)
{
 unsigned retv = 0;
 lock(&(ofile)->dentry->mutex);
 release_cached_chunks(ofile);
 if (ofile->dentry->chunk_tree.root)
  retv = flush_chunk_tree(&ofile->dentry->chunk_tree);
 unlock(&(ofile)->dentry->mutex);
 put_dentry(ofile->dentry);
 memset(ofile, 0xcc, sizeof(struct open_file));
 free(ofile);
 return retv;
}

canonical_original_code:
int close_file(struct open_file *ofile)
{
 unsigned int retv = 0;
 lock(&(ofile)->dentry->mutex);
 release_cached_chunks(ofile);
 if (ofile->dentry->chunk_tree.root)
  retv = flush_chunk_tree(&ofile->dentry->chunk_tree);
 unlock(&(ofile)->dentry->mutex);
 put_dentry(ofile->dentry);
 memset(ofile, 0xcc, sizeof(struct open_file));
 free(ofile);
 return retv;
}

variable_types:
retv
unsigned int


decompiled_code:
__int64 __fastcall flush_file(__int64 *a1)
{
unsigned int v1; // er12
__int64 v3; // rdi
unsigned int v4; // eax

v1 = 0;
lock(*a1 + 32);
release_cached_chunks(a1);
v3 = *a1;
if ( *(_QWORD *)(*a1 + 88) )
{
v4 = flush_chunk_tree(v3 + 88);
v3 = *a1;
v1 = v4;
}
unlock(v3 + 32);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 *a1)
{
unsigned int v1; // er12
__int64 v3; // rdi
unsigned int v4; // eax

v1 = 0;
lock(*a1 + 32);
func18(a1);
v3 = *a1;
if ( *(_QWORD *)(*a1 + 88) )
{
v4 = flush_chunk_tree(v3 + 88);
v3 = *a1;
v1 = v4;
}
unlock(v3 + 32);
return v1;
}

original_code:
int flush_file(struct open_file *ofile)
{
 unsigned retv = 0;
 lock(&(ofile)->dentry->mutex);
 release_cached_chunks(ofile);
 if (ofile->dentry->chunk_tree.root)
  retv = flush_chunk_tree(&ofile->dentry->chunk_tree);
 unlock(&(ofile)->dentry->mutex);
 return retv;
}

canonical_original_code:
int flush_file(struct open_file *ofile)
{
 unsigned int retv = 0;
 lock(&(ofile)->dentry->mutex);
 release_cached_chunks(ofile);
 if (ofile->dentry->chunk_tree.root)
  retv = flush_chunk_tree(&ofile->dentry->chunk_tree);
 unlock(&(ofile)->dentry->mutex);
 return retv;
}


decompiled_code:
__int64 __fastcall read_file(_DWORD *a1, __int64 a2, unsigned __int64 a3, unsigned __int64 a4)
{
unsigned int v6; // er12

lock(*(_QWORD *)a1 + 32LL);
v6 = rw_file(a1, a2, a3, a4, 1);
unlock(*(_QWORD *)a1 + 32LL);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func21(_DWORD *a1, __int64 a2, unsigned __int64 a3, unsigned __int64 a4)
{
unsigned int v6; // er12

lock(*(_QWORD *)a1 + 32LL);
v6 = func17(a1, a2, a3, a4, 1);
unlock(*(_QWORD *)a1 + 32LL);
return v6;
}

original_code:
int read_file(struct open_file *ofile, char *buf, size_t bufsz, off_t offset)
{
 int len;
 lock(&(ofile)->dentry->mutex);
 len = rw_file(ofile, buf, bufsz, offset, 1);
 unlock(&(ofile)->dentry->mutex);
 return len;
}

canonical_original_code:
int read_file(struct open_file *ofile, char *buf, unsigned long bufsz, long offset)
{
 int len;
 lock(&(ofile)->dentry->mutex);
 len = rw_file(ofile, buf, bufsz, offset, 1);
 unlock(&(ofile)->dentry->mutex);
 return len;
}


decompiled_code:
__int64 __fastcall write_file(_QWORD *a1, __int64 a2, unsigned __int64 a3, unsigned __int64 a4)
{
unsigned int v6; // er12

lock(*a1 + 32LL);
if ( (*(_DWORD *)(*a1 + 168LL) & 0xF000) == 0x4000 )
v6 = write_dir(a1, a2, a3, a4);
else
v6 = rw_file(a1, a2, a3, a4, 0);
unlock(*a1 + 32LL);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func22(_QWORD *a1, __int64 a2, unsigned __int64 a3, unsigned __int64 a4)
{
unsigned int v6; // er12

lock(*a1 + 32LL);
if ( (*(_DWORD *)(*a1 + 168LL) & 0xF000) == 0x4000 )
v6 = func10(a1, a2, a3, a4);
else
v6 = func17(a1, a2, a3, a4, 0);
unlock(*a1 + 32LL);
return v6;
}

original_code:
int write_file(struct open_file *ofile, const char *buf, size_t len, off_t off)
{
 int retv;
 lock(&(ofile)->dentry->mutex);
 if (((((ofile->dentry->mode)) & 0170000) == (0040000)))
  retv = write_dir(ofile, buf, len, off);
 else
  retv = rw_file(ofile, (char *)buf, len, off, 0);
 unlock(&(ofile)->dentry->mutex);
 return retv;
}

canonical_original_code:
int write_file(struct open_file *ofile, char *buf, unsigned long len, long off)
{
 int retv;
 lock(&(ofile)->dentry->mutex);
 if (((((ofile->dentry->mode)) & 0170000) == (0040000)))
  retv = write_dir(ofile, buf, len, off);
 else
  retv = rw_file(ofile, (char *)buf, len, off, 0);
 unlock(&(ofile)->dentry->mutex);
 return retv;
}

variable_types: off long

variable_types: retv int


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

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

original_code:
struct dentry *file_dentry(struct open_file *ofile)
{
 return ofile->dentry;
}

variable_types: struct open_file { struct dentry *dentry; struct chunk_node *ccache[-1]; unsigned int ccache_index; } *

return_type: struct dentry { struct disk_dentry { unsigned char digest[20]; unsigned char secret_digest[20]; struct le16_t { unsigned short v; } mode; unsigned char flags; unsigned char mtime_csec; struct le64_t { unsigned long v; } size; struct le32_t { unsigned int v; } ctime; struct le32_t mtime; unsigned char name[-1]; } *ddent; struct chunk_node { unsigned char chunk_data[-1]; unsigned char *chunk_digest; struct chunk_node *parent; struct chunk_tree { struct chunk_node *root; unsigned int nr_leafs; unsigned int height; struct chunk_tree_operations { void (*free_private)(void *); int (*read_chunk)(unsigned char *chunk, unsigned char *digest); int (*write_chunk)(unsigned char *chunk, unsigned char *digest); } *ops; struct list_head { struct list_head *prev; } dirty_list; } *ctree; struct list_head dirty_entry; unsigned int ref_count; void *_private; } *ddent_cnode; struct mutex { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned long owner; } *ddent_mutex; struct dentry *parent; struct mutex mutex; unsigned int ref_count; struct chunk_tree chunk_tree; unsigned char *secret_chunk; unsigned int dirty; unsigned long size; struct timeval { long tv_sec; long tv_usec; } mtime; unsigned int mode; } *


decompiled_code:
_BOOL8 __fastcall IS_ERR(unsigned __int64 a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( _errptr <= a1 )
result = a1 < _errptr + 256LL;
return result;
}

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

result = 0LL;
if ( _errptr <= a1 )
result = a1 < _errptr + 256LL;
return result;
}

original_code:
static inline int IS_ERR(const void *ptr)
{
 return ptr >= __errptr && ptr < __errptr + 256;
}

variable_types:
ptr
void *


decompiled_code:
__int64 __fastcall le16toh(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return a1;
}

original_code: static inline uint16_t le16toh(le16_t x) { return x.v; }

canonical_original_code: static inline unsigned short le16toh(struct le16_t x) { return x.v; }

variable_types:
x
struct le16_t { unsigned short v; }

return_type: unsigned short


decompiled_code:
__int64 __fastcall le32toh(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return a1;
}

original_code: static inline uint32_t le32toh(le32_t x) { return x.v; }

canonical_original_code: static inline unsigned int le32toh(struct le32_t x) { return x.v; }

variable_types:
x
struct le32_t { unsigned int v; }


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

variable_types:
x
struct le64_t { unsigned long v; }


decompiled_code:
__int64 __fastcall read_dentry(int fd, __int64 a2)
{
__int64 v2; // r14
int v3; // er12
int v4; // eax
int v5; // eax

v2 = 0LL;
v3 = 0;
do
{
while ( 1 )
{
v4 = read(fd, (void *)(a2 + v2), 256 - v2);
if ( v4 < 0 )
break;
if ( !v4 )
return (unsigned int)v3;
v3 += v4;
if ( v3 > 255 )
return (unsigned int)v3;
v2 = v3;
}
v5 = *_errno_location();
}
while ( v5 == 4 );
return (unsigned int)-v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, __int64 a2)
{
__int64 v2; // r14
int v3; // er12
int v4; // eax
int v5; // eax

v2 = 0LL;
v3 = 0;
do
{
while ( 1 )
{
v4 = read(fd, (void *)(a2 + v2), 256 - v2);
if ( v4 < 0 )
break;
if ( !v4 )
return (unsigned int)v3;
v3 += v4;
if ( v3 > 255 )
return (unsigned int)v3;
v2 = v3;
}
v5 = *_errno_location();
}
while ( v5 == 4 );
return (unsigned int)-v5;
}

original_code:
static int read_dentry(int fd, struct disk_dentry *de)
{
 void *ptr = de;
 int len;
 for (len = 0; len < sizeof(struct disk_dentry); ) {
  int n = read(fd, ptr + len, sizeof(struct disk_dentry) - len);
  if (n < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   return -(*__errno_location ());
  }
  if (!n)
   break;
  len += n;
 }
 return len;
}

variable_types: fd int

variable_types: struct disk_dentry { unsigned char digest[20]; unsigned char secret_digest[20]; struct le16_t { unsigned short v; } mode; unsigned char flags; unsigned char mtime_csec; struct le64_t { unsigned long v; } size; struct le32_t { unsigned int v; } ctime; struct le32_t mtime; unsigned char name[-1]; } *

variable_types: n int


decompiled_code:
_BOOL8 __fastcall list_empty(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == a1;
}

original_code:
static inline int list_empty(const struct list_head *item)
{
 return item->next == item;
}

canonical_original_code:
static inline int list_empty(struct list_head *item)
{
 return item->next == item;
}

variable_types: struct list_head { struct list_head *prev; } *


decompiled_code:
_BOOL8 __fastcall is_cnode_dirty(__int64 a1)
{
return !list_empty(a1 + 65560);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return !func0(a1 + 65560);
}

original_code:
static inline int is_cnode_dirty(const struct chunk_node *cnode)
{
 return !list_empty(&cnode->dirty_entry);
}

canonical_original_code:
static inline int is_cnode_dirty(struct chunk_node *cnode)
{
 return !list_empty(&cnode->dirty_entry);
}


decompiled_code:
__int64 __fastcall verify_chunk(__int64 a1, __int64 a2)
{
return verify_digest(a2, a1, 0x10000LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return verify_digest(a2, a1, 0x10000LL);
}

original_code:
static inline int verify_chunk(const unsigned char *chunk,
  const unsigned char *digest)
{
 return verify_digest(digest, chunk, (1UL << 16));
}

canonical_original_code:
static inline int verify_chunk(unsigned char *chunk, unsigned char *digest)
{
 return verify_digest(digest, chunk, (1UL << 16));
}

variable_types:
chunk
unsigned char *

variable_types:
digest
unsigned char *


decompiled_code:
void __fastcall dump_cnode(__int64 a1, const char *a2, int a3, void (__fastcall *a4)(__int64, const char *))
{
const char *v7; // rax
const void *v8; // rcx
__int64 v9; // rdx
unsigned int v10; // er13
__int64 i; // rbx
__int64 v12; // rdi
__int64 v13; // rdi
__int64 v14; // [rsp-Eh] [rbp-78h] BYREF

if ( a1 )
{
v7 = (const char *)_digest_string(*(_QWORD *)(a1 + 0x10000), &v14);
printf("%s%p:%p: %s", a2, (const void *)a1, *(const void **)(a1 + 0x10000), v7);
if ( is_cnode_dirty(a1) )
{
printf(" [dirty]");
}
else if ( !(unsigned int)verify_chunk(a1, *(_QWORD *)(a1 + 0x10000)) )
{
printf(" [ERR]");
}
v8 = *(const void **)(a1 + 65584);
v9 = *(unsigned int *)(a1 + 65576);
if ( a3 )
{
v10 = a3 - 1;
printf(" [%s] refcount=%d %p\n", "internal", v9, v8);
for ( i = 0LL; i != 26208; i += 8LL )
{
v12 = *(_QWORD *)(*(_QWORD *)(a1 + 65584) + i);
dump_cnode(v12, a2 - 1, v10, a4);
}
}
else
{
printf(" [%s] refcount=%d %p\n", "leaf", v9, v8);
if ( a4 )
{
v13 = *(_QWORD *)(a1 + 65584);
if ( v13 )
a4(v13, a2);
}
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, const char *a2, int a3, void (__fastcall *a4)(__int64, const char *))
{
const char *v7; // rax
const void *v8; // rcx
__int64 v9; // rdx
unsigned int v10; // er13
__int64 i; // rbx
__int64 v12; // rdi
__int64 v13; // rdi
__int64 v14; // [rsp-Eh] [rbp-78h] BYREF

if ( a1 )
{
v7 = (const char *)_digest_string(*(_QWORD *)(a1 + 0x10000), &v14);
printf("%s%p:%p: %s", a2, (const void *)a1, *(const void **)(a1 + 0x10000), v7);
if ( func1(a1) )
{
printf(" [dirty]");
}
else if ( !(unsigned int)func2(a1, *(_QWORD *)(a1 + 0x10000)) )
{
printf(" [ERR]");
}
v8 = *(const void **)(a1 + 65584);
v9 = *(unsigned int *)(a1 + 65576);
if ( a3 )
{
v10 = a3 - 1;
printf(" [%s] refcount=%d %p\n", "internal", v9, v8);
for ( i = 0LL; i != 26208; i += 8LL )
{
v12 = *(_QWORD *)(*(_QWORD *)(a1 + 65584) + i);
func3(v12, a2 - 1, v10, a4);
}
}
else
{
printf(" [%s] refcount=%d %p\n", "leaf", v9, v8);
if ( a4 )
{
v13 = *(_QWORD *)(a1 + 65584);
if ( v13 )
a4(v13, a2);
}
}
}
}

original_code:
void dump_cnode(struct chunk_node *cnode, const char *indent, int height,
  void (*dump_leaf)(void **, const char *))
{
 int i;
 if (!cnode)
  return;
 printf("%s%p:%p: %s", indent, cnode, cnode->chunk_digest,
   __digest_string(cnode->chunk_digest, __builtin_alloca ((20 * 2) + 1)));
 if (is_cnode_dirty(cnode))
  printf(" [dirty]");
 else if (!verify_chunk(cnode->chunk_data, cnode->chunk_digest))
  printf(" [ERR]");
 printf(" [%s] refcount=%d %p\n", height ? "internal" : "leaf",
   cnode->ref_count, cnode->_private);
 if (!height) {
  if (dump_leaf && cnode->_private)
   dump_leaf(cnode->_private, indent);
 } else {
  for (i = 0; i < ((1UL << 16) / 20); i ++) {
   dump_cnode(((struct chunk_node **)(cnode)->_private)[i], indent - 1,
     height - 1, dump_leaf);
  }
 }
}

canonical_original_code:
void dump_cnode(struct chunk_node *cnode, char *indent, int height, void (*dump_leaf)(void **, char *))
{
 int i;
 if (!cnode)
  return;
 printf("%s%p:%p: %s", indent, cnode, cnode->chunk_digest,
   __digest_string(cnode->chunk_digest, __builtin_alloca ((20 * 2) + 1)));
 if (is_cnode_dirty(cnode))
  printf(" [dirty]");
 else if (!verify_chunk(cnode->chunk_data, cnode->chunk_digest))
  printf(" [ERR]");
 printf(" [%s] refcount=%d %p\n", height ? "internal" : "leaf",
   cnode->ref_count, cnode->_private);
 if (!height) {
  if (dump_leaf && cnode->_private)
   dump_leaf(cnode->_private, indent);
 } else {
  for (i = 0; i < ((1UL << 16) / 20); i ++) {
   dump_cnode(((struct chunk_node **)(cnode)->_private)[i], indent - 1,
     height - 1, dump_leaf);
  }
 }
}

variable_types:
indent
char *

variable_types: height int


decompiled_code:
void __fastcall dump_ctree(__int64 *a1, const char *a2, void (__fastcall *a3)(__int64, const char *))
{
__int64 v5; // rdi

printf("%sCTREE %p nr_leafs=%d height=%d\n", a2, a1, *((unsigned int *)a1 + 2), *((unsigned int *)a1 + 3));
v5 = *a1;
if ( v5 )
dump_cnode(v5, a2 - 1, *((_DWORD *)a1 + 3), a3);
}

canonical_decompiled_code:
void __fastcall func4(__int64 *a1, const char *a2, void (__fastcall *a3)(__int64, const char *))
{
__int64 v5; // rdi

printf("%sCTREE %p nr_leafs=%d height=%d\n", a2, a1, *((unsigned int *)a1 + 2), *((unsigned int *)a1 + 3));
v5 = *a1;
if ( v5 )
func3(v5, a2 - 1, *((_DWORD *)a1 + 3), a3);
}

original_code:
void dump_ctree(struct chunk_tree *ctree, const char *indent,
  void (*dump_leaf)(void **child, const char *indent))
{
 printf("%sCTREE %p nr_leafs=%d height=%d\n", indent, ctree,
   ctree->nr_leafs, ctree->height);
 if (ctree->root)
  dump_cnode(ctree->root, indent - 1, ctree->height, dump_leaf);
}

canonical_original_code:
void dump_ctree(struct chunk_tree *ctree, char *indent, void (*dump_leaf)(void **child, char *indent))
{
 printf("%sCTREE %p nr_leafs=%d height=%d\n", indent, ctree,
   ctree->nr_leafs, ctree->height);
 if (ctree->root)
  dump_cnode(ctree->root, indent - 1, ctree->height, dump_leaf);
}

variable_types: struct chunk_tree { struct chunk_node { unsigned char chunk_data[-1]; unsigned char *chunk_digest; struct chunk_node *parent; struct chunk_tree *ctree; struct list_head { struct list_head *prev; } dirty_entry; unsigned int ref_count; void *_private; } *root; unsigned int nr_leafs; unsigned int height; struct chunk_tree_operations { void (*free_private)(void *); int (*read_chunk)(unsigned char *chunk, unsigned char *digest); int (*write_chunk)(unsigned char *chunk, unsigned char *digest); } *ops; struct list_head dirty_list; } *