uncle

decompiled_code:
__int64 __fastcall uncle(__int64 a1)
{
__int64 v1; // rdi

if ( !a1 )
__assert_fail("n != NULL", "bbst.c", 0x30u, "uncle");
v1 = *(_QWORD *)(a1 + 32);
if ( !v1 )
__assert_fail("n->parent != NULL", "bbst.c", 0x31u, "uncle");
if ( !*(_QWORD *)(v1 + 32) )
__assert_fail("n->parent->parent != NULL", "bbst.c", 0x32u, "uncle");
return sibling(v1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // rdi

if ( !a1 )
__assert_fail("n != NULL", "bbst.c", 0x30u, "uncle");
v1 = *(_QWORD *)(a1 + 32);
if ( !v1 )
__assert_fail("n->parent != NULL", "bbst.c", 0x31u, "uncle");
if ( !*(_QWORD *)(v1 + 32) )
__assert_fail("n->parent->parent != NULL", "bbst.c", 0x32u, "uncle");
return func10(v1);
}

original_code:
node uncle(node n){
    ((void) sizeof ((n != ((void *)0)) ? 1 : 0), __extension__ ({ if (n != ((void *)0)) ; else __assert_fail ("n != NULL", "bbst.c", 48, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (n->parent != ((void *)0)) ; else __assert_fail ("n->parent != NULL", "bbst.c", 49, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->parent->parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (n->parent->parent != ((void *)0)) ; else __assert_fail ("n->parent->parent != NULL", "bbst.c", 50, __extension__ __PRETTY_FUNCTION__); }));
    return sibling(n->parent);
}

canonical_original_code:
struct bbst_node_t *uncle(struct bbst_node_t *n){
    ((void) sizeof ((n != ((void *)0)) ? 1 : 0), __extension__ ({ if (n != ((void *)0)) ; else __assert_fail ("n != NULL", "bbst.c", 48, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (n->parent != ((void *)0)) ; else __assert_fail ("n->parent != NULL", "bbst.c", 49, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->parent->parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (n->parent->parent != ((void *)0)) ; else __assert_fail ("n->parent->parent != NULL", "bbst.c", 50, __extension__ __PRETTY_FUNCTION__); }));
    return sibling(n->parent);
}


grandparent

repo: unenemy/helios-course

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

if ( !a1 )
__assert_fail("n != NULL", "bbst.c", 0x1Fu, "grandparent");
v1 = *(_QWORD *)(a1 + 32);
if ( !v1 )
__assert_fail("n->parent != NULL", "bbst.c", 0x20u, "grandparent");
result = *(_QWORD *)(v1 + 32);
if ( !result )
__assert_fail("n->parent->parent != NULL", "bbst.c", 0x21u, "grandparent");
return result;
}

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

if ( !a1 )
__assert_fail("n != NULL", "bbst.c", 0x1Fu, "grandparent");
v1 = *(_QWORD *)(a1 + 32);
if ( !v1 )
__assert_fail("n->parent != NULL", "bbst.c", 0x20u, "grandparent");
result = *(_QWORD *)(v1 + 32);
if ( !result )
__assert_fail("n->parent->parent != NULL", "bbst.c", 0x21u, "grandparent");
return result;
}

original_code:
node grandparent(node n){
    ((void) sizeof ((n != ((void *)0)) ? 1 : 0), __extension__ ({ if (n != ((void *)0)) ; else __assert_fail ("n != NULL", "bbst.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (n->parent != ((void *)0)) ; else __assert_fail ("n->parent != NULL", "bbst.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->parent->parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (n->parent->parent != ((void *)0)) ; else __assert_fail ("n->parent->parent != NULL", "bbst.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    return n->parent->parent;
}

canonical_original_code:
struct bbst_node_t *grandparent(struct bbst_node_t *n){
    ((void) sizeof ((n != ((void *)0)) ? 1 : 0), __extension__ ({ if (n != ((void *)0)) ; else __assert_fail ("n != NULL", "bbst.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (n->parent != ((void *)0)) ; else __assert_fail ("n->parent != NULL", "bbst.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n->parent->parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (n->parent->parent != ((void *)0)) ; else __assert_fail ("n->parent->parent != NULL", "bbst.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    return n->parent->parent;
}

variable_types:
n
struct bbst_node_t *

return_type: struct bbst_node_t { void *key; void *value; struct bbst_node_t *left; struct bbst_node_t *right; struct bbst_node_t *parent; enum bbst_node_color { RED=0, BLACK=1 } color; } *

user_defined_types: struct bbst_node_t { void *key; void *value; struct bbst_node_t *left; struct bbst_node_t *right; struct bbst_node_t *parent; enum bbst_node_color color; }


decompiled_code:
__int64 __fastcall insert_case5(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rsi
__int64 v5; // rax

v2 = *(_QWORD *)(a2 + 32);
*(_DWORD *)(v2 + 40) = 1;
*(_DWORD *)(grandparent(a2) + 40) = 0;
if ( *(_QWORD *)(v2 + 16) == a2 )
{
v5 = grandparent(a2);
if ( v2 == *(_QWORD *)(v5 + 16) )
return rotate_right(a1, v5);
}
if ( *(_QWORD *)(v2 + 24) != a2 || (v3 = grandparent(a2), v2 != *(_QWORD *)(v3 + 24)) )
__assert_fail("n == n->parent->right && n->parent == grandparent(n)->right", "bbst.c", 0xD2u, "insert_case5");
return rotate_left(a1, v3);
}

original_code:
void insert_case5(bbst tree, node n) {
    n->parent->color = BLACK;
    grandparent(n)->color = RED;
    if (n == n->parent->left && n->parent == grandparent(n)->left) {
        rotate_right(tree, grandparent(n));
    } else {
        ((void) sizeof ((n == n->parent->right && n->parent == grandparent(n)->right) ? 1 : 0), __extension__ ({ if (n == n->parent->right && n->parent == grandparent(n)->right) ; else __assert_fail ("n == n->parent->right && n->parent == grandparent(n)->right", "bbst.c", 210, __extension__ __PRETTY_FUNCTION__); }));
        rotate_left(tree, grandparent(n));
    }
}

canonical_original_code:
void insert_case5(struct bbst_t *tree, struct bbst_node_t *n) {
    n->parent->color = BLACK;
    grandparent(n)->color = RED;
    if (n == n->parent->left && n->parent == grandparent(n)->left) {
        rotate_right(tree, grandparent(n));
    } else {
        ((void) sizeof ((n == n->parent->right && n->parent == grandparent(n)->right) ? 1 : 0), __extension__ ({ if (n == n->parent->right && n->parent == grandparent(n)->right) ; else __assert_fail ("n == n->parent->right && n->parent == grandparent(n)->right", "bbst.c", 210, __extension__ __PRETTY_FUNCTION__); }));
        rotate_left(tree, grandparent(n));
    }
}

variable_types: struct bbst_t { struct bbst_node_t { void *key; void *value; struct bbst_node_t *left; struct bbst_node_t *right; struct bbst_node_t *parent; enum bbst_node_color { RED=0, BLACK=1 } color; } *root; } *

return_type: void

user_defined_types: struct bbst_t { struct bbst_node_t *root; }


original_code:
void insert_case4(bbst tree, node n) {
    if (n == n->parent->right && n->parent == grandparent(n)->left) {
        rotate_left(tree, n->parent);
        n = n->left;
    } else if (n == n->parent->left && n->parent == grandparent(n)->right) {
        rotate_right(tree, n->parent);
        n = n->right;
    }
    insert_case5(tree, n);
}

canonical_original_code:
void insert_case4(struct bbst_t *tree, struct bbst_node_t *n) {
    if (n == n->parent->right && n->parent == grandparent(n)->left) {
        rotate_left(tree, n->parent);
        n = n->left;
    } else if (n == n->parent->left && n->parent == grandparent(n)->right) {
        rotate_right(tree, n->parent);
        n = n->right;
    }
    insert_case5(tree, n);
}


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

v2 = uncle((__int64)a2);
if ( (unsigned int)node_color(v2) )
return insert_case4(a1, a2);
*(_DWORD *)(a2[4] + 40LL) = 1;
*(_DWORD *)(uncle((__int64)a2) + 40) = 1;
*(_DWORD *)(grandparent((__int64)a2) + 40) = 0;
v3 = grandparent((__int64)a2);
return insert_case1(a1, v3);
}

original_code:
void insert_case3(bbst tree, node n) {
    if (node_color(uncle(n)) == RED) {
        n->parent->color = BLACK;
        uncle(n)->color = BLACK;
        grandparent(n)->color = RED;
        insert_case1(tree, grandparent(n));
    } else {
        insert_case4(tree, n);
    }
}

canonical_original_code:
void insert_case3(struct bbst_t *tree, struct bbst_node_t *n) {
    if (node_color(uncle(n)) == RED) {
        n->parent->color = BLACK;
        uncle(n)->color = BLACK;
        grandparent(n)->color = RED;
        insert_case1(tree, grandparent(n));
    } else {
        insert_case4(tree, n);
    }
}


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

result = node_color(a2[4]);
if ( (_DWORD)result != 1 )
result = insert_case3(v3, a2);
return result;
}

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

result = func6(a2[4]);
if ( (_DWORD)result != 1 )
result = func15(v3, a2);
return result;
}

original_code:
void insert_case2(bbst tree, node n){
    if (node_color(n->parent) == BLACK)
        return;
    else
        insert_case3(tree, n);
}

canonical_original_code:
void insert_case2(struct bbst_t *tree, struct bbst_node_t *n){
    if (node_color(n->parent) == BLACK)
        return;
    else
        insert_case3(tree, n);
}


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

if ( a2[4] )
return insert_case2(a1, a2);
*((_DWORD *)a2 + 10) = 1;
return result;
}

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

if ( a2[4] )
return func16(a1, a2);
*((_DWORD *)a2 + 10) = 1;
return result;
}

original_code:
void insert_case1(bbst tree, node n){
    if (n->parent == ((void *)0))
        n->color = BLACK;
    else
        insert_case2(tree, n);
}

canonical_original_code:
void insert_case1(struct bbst_t *tree, struct bbst_node_t *n){
    if (n->parent == ((void *)0))
        n->color = BLACK;
    else
        insert_case2(tree, n);
}


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

if ( !a1 )
__assert_fail("n != NULL", "bbst.c", 0xF0u, "maximum_node");
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return result;
}

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

if ( !a1 )
__assert_fail("n != NULL", "bbst.c", 0xF0u, "maximum_node");
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return result;
}

original_code:
static node maximum_node(node n) {
    ((void) sizeof ((n != ((void *)0)) ? 1 : 0), __extension__ ({ if (n != ((void *)0)) ; else __assert_fail ("n != NULL", "bbst.c", 240, __extension__ __PRETTY_FUNCTION__); }));
    while (n->right != ((void *)0)) {
        n = n->right;
    }
    return n;
}

canonical_original_code:
static struct bbst_node_t *maximum_node(struct bbst_node_t *n) {
    ((void) sizeof ((n != ((void *)0)) ? 1 : 0), __extension__ ({ if (n != ((void *)0)) ; else __assert_fail ("n != NULL", "bbst.c", 240, __extension__ __PRETTY_FUNCTION__); }));
    while (n->right != ((void *)0)) {
        n = n->right;
    }
    return n;
}


decompiled_code:
__int64 __fastcall delete_case6(_QWORD *a1, __int64 a2)
{
__int64 v2; // r12
int v3; // eax
__int64 v4; // rdx
__int64 v5; // rax
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // rax
__int64 v9; // rdx

v2 = *(_QWORD *)(a2 + 32);
sibling(a2);
v3 = node_color(v2);
*(_DWORD *)(v4 + 40) = v3;
*(_DWORD *)(v2 + 40) = 1;
if ( *(_QWORD *)(v2 + 16) == a2 )
{
v8 = sibling(a2);
if ( (unsigned int)node_color(*(_QWORD *)(v8 + 24)) )
__assert_fail("node_color(sibling(n)->right) == RED", "bbst.c", 0x13Fu, "delete_case6");
*(_DWORD *)(v9 + 40) = 1;
result = rotate_left(a1, v2);
}
else
{
v5 = sibling(a2);
if ( (unsigned int)node_color(*(_QWORD *)(v5 + 16)) )
__assert_fail("node_color(sibling(n)->left) == RED", "bbst.c", 0x145u, "delete_case6");
*(_DWORD *)(v6 + 40) = 1;
result = rotate_right(a1, v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1, __int64 a2)
{
__int64 v2; // r12
int v3; // eax
__int64 v4; // rdx
__int64 v5; // rax
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // rax
__int64 v9; // rdx

v2 = *(_QWORD *)(a2 + 32);
func10(a2);
v3 = func6(v2);
*(_DWORD *)(v4 + 40) = v3;
*(_DWORD *)(v2 + 40) = 1;
if ( *(_QWORD *)(v2 + 16) == a2 )
{
v8 = func10(a2);
if ( (unsigned int)func6(*(_QWORD *)(v8 + 24)) )
__assert_fail("node_color(sibling(n)->right) == RED", "bbst.c", 0x13Fu, "delete_case6");
*(_DWORD *)(v9 + 40) = 1;
result = func8(a1, v2);
}
else
{
v5 = func10(a2);
if ( (unsigned int)func6(*(_QWORD *)(v5 + 16)) )
__assert_fail("node_color(sibling(n)->left) == RED", "bbst.c", 0x145u, "delete_case6");
*(_DWORD *)(v6 + 40) = 1;
result = func9(a1, v2);
}
return result;
}

original_code:
void delete_case6(bbst tree, node n) {
    sibling(n)->color = node_color(n->parent);
    n->parent->color = BLACK;
    if (n == n->parent->left) {
        ((void) sizeof ((node_color(sibling(n)->right) == RED) ? 1 : 0), __extension__ ({ if (node_color(sibling(n)->right) == RED) ; else __assert_fail ("node_color(sibling(n)->right) == RED", "bbst.c", 319, __extension__ __PRETTY_FUNCTION__); }));
        sibling(n)->right->color = BLACK;
        rotate_left(tree, n->parent);
    }
    else
    {
        ((void) sizeof ((node_color(sibling(n)->left) == RED) ? 1 : 0), __extension__ ({ if (node_color(sibling(n)->left) == RED) ; else __assert_fail ("node_color(sibling(n)->left) == RED", "bbst.c", 325, __extension__ __PRETTY_FUNCTION__); }));
        sibling(n)->left->color = BLACK;
        rotate_right(tree, n->parent);
    }
}

canonical_original_code:
void delete_case6(struct bbst_t *tree, struct bbst_node_t *n) {
    sibling(n)->color = node_color(n->parent);
    n->parent->color = BLACK;
    if (n == n->parent->left) {
        ((void) sizeof ((node_color(sibling(n)->right) == RED) ? 1 : 0), __extension__ ({ if (node_color(sibling(n)->right) == RED) ; else __assert_fail ("node_color(sibling(n)->right) == RED", "bbst.c", 319, __extension__ __PRETTY_FUNCTION__); }));
        sibling(n)->right->color = BLACK;
        rotate_left(tree, n->parent);
    }
    else
    {
        ((void) sizeof ((node_color(sibling(n)->left) == RED) ? 1 : 0), __extension__ ({ if (node_color(sibling(n)->left) == RED) ; else __assert_fail ("node_color(sibling(n)->left) == RED", "bbst.c", 325, __extension__ __PRETTY_FUNCTION__); }));
        sibling(n)->left->color = BLACK;
        rotate_right(tree, n->parent);
    }
}


decompiled_code:
__int64 __fastcall delete_case5(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rdx
__int64 v11; // rdx
__int64 v12; // rdx
__int64 v13; // rax

v2 = *(_QWORD *)(a2 + 32);
if ( *(_QWORD *)(v2 + 16) == a2
&& (v4 = sibling(a2), (unsigned int)node_color(v4) == 1)
&& !(unsigned int)node_color(*(_QWORD *)(v5 + 16))
&& (unsigned int)node_color(*(_QWORD *)(v6 + 24)) == 1 )
{
*(_DWORD *)(v7 + 40) = 0;
*(_DWORD *)(*(_QWORD *)(sibling(a2) + 16) + 40LL) = 1;
v8 = sibling(a2);
rotate_right(a1, v8);
}
else if ( *(_QWORD *)(v2 + 24) == a2 )
{
v9 = sibling(a2);
if ( (unsigned int)node_color(v9) == 1
&& !(unsigned int)node_color(*(_QWORD *)(v10 + 24))
&& (unsigned int)node_color(*(_QWORD *)(v11 + 16)) == 1 )
{
*(_DWORD *)(v12 + 40) = 0;
*(_DWORD *)(*(_QWORD *)(sibling(a2) + 24) + 40LL) = 1;
v13 = sibling(a2);
rotate_left(a1, v13);
}
}
return delete_case6(a1, a2);
}

original_code:
void delete_case5(bbst tree, node n) {
    if (n == n->parent->left &&
        node_color(sibling(n)) == BLACK &&
        node_color(sibling(n)->left) == RED &&
        node_color(sibling(n)->right) == BLACK)
    {
        sibling(n)->color = RED;
        sibling(n)->left->color = BLACK;
        rotate_right(tree, sibling(n));
    }
    else if (n == n->parent->right &&
             node_color(sibling(n)) == BLACK &&
             node_color(sibling(n)->right) == RED &&
             node_color(sibling(n)->left) == BLACK)
    {
        sibling(n)->color = RED;
        sibling(n)->right->color = BLACK;
        rotate_left(tree, sibling(n));
    }
    delete_case6(tree, n);
}

canonical_original_code:
void delete_case5(struct bbst_t *tree, struct bbst_node_t *n) {
    if (n == n->parent->left &&
        node_color(sibling(n)) == BLACK &&
        node_color(sibling(n)->left) == RED &&
        node_color(sibling(n)->right) == BLACK)
    {
        sibling(n)->color = RED;
        sibling(n)->left->color = BLACK;
        rotate_right(tree, sibling(n));
    }
    else if (n == n->parent->right &&
             node_color(sibling(n)) == BLACK &&
             node_color(sibling(n)->right) == RED &&
             node_color(sibling(n)->left) == BLACK)
    {
        sibling(n)->color = RED;
        sibling(n)->right->color = BLACK;
        rotate_left(tree, sibling(n));
    }
    delete_case6(tree, n);
}


decompiled_code:
__int64 __fastcall delete_case4(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rdx
__int64 result; // rax
__int64 v6; // rdx
__int64 v7; // rdx

v2 = *(_QWORD *)(a2 + 32);
if ( (unsigned int)node_color(v2) )
return delete_case5(a1, a2);
v3 = sibling(a2);
if ( (unsigned int)node_color(v3) != 1 )
return delete_case5(a1, a2);
if ( (unsigned int)node_color(*(_QWORD *)(v4 + 16)) != 1 )
return delete_case5(a1, a2);
result = node_color(*(_QWORD *)(v6 + 24));
if ( (_DWORD)result != 1 )
return delete_case5(a1, a2);
*(_DWORD *)(v7 + 40) = 0;
*(_DWORD *)(v2 + 40) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rdx
__int64 result; // rax
__int64 v6; // rdx
__int64 v7; // rdx

v2 = *(_QWORD *)(a2 + 32);
if ( (unsigned int)func6(v2) )
return func20(a1, a2);
v3 = func10(a2);
if ( (unsigned int)func6(v3) != 1 )
return func20(a1, a2);
if ( (unsigned int)func6(*(_QWORD *)(v4 + 16)) != 1 )
return func20(a1, a2);
result = func6(*(_QWORD *)(v6 + 24));
if ( (_DWORD)result != 1 )
return func20(a1, a2);
*(_DWORD *)(v7 + 40) = 0;
*(_DWORD *)(v2 + 40) = 1;
return result;
}

original_code:
void delete_case4(bbst tree, node n) {
    if (node_color(n->parent) == RED &&
        node_color(sibling(n)) == BLACK &&
        node_color(sibling(n)->left) == BLACK &&
        node_color(sibling(n)->right) == BLACK)
    {
        sibling(n)->color = RED;
        n->parent->color = BLACK;
    }
    else
        delete_case5(tree, n);
}

canonical_original_code:
void delete_case4(struct bbst_t *tree, struct bbst_node_t *n) {
    if (node_color(n->parent) == RED &&
        node_color(sibling(n)) == BLACK &&
        node_color(sibling(n)->left) == BLACK &&
        node_color(sibling(n)->right) == BLACK)
    {
        sibling(n)->color = RED;
        n->parent->color = BLACK;
    }
    else
        delete_case5(tree, n);
}


decompiled_code:
__int64 __fastcall delete_case3(_QWORD *a1, __int64 a2)
{
__int64 v2; // r13
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx

v2 = *(_QWORD *)(a2 + 32);
if ( (unsigned int)node_color(v2) != 1 )
return delete_case4(a1, a2);
v4 = sibling(a2);
if ( (unsigned int)node_color(v4) != 1
|| (unsigned int)node_color(*(_QWORD *)(v5 + 16)) != 1
|| (unsigned int)node_color(*(_QWORD *)(v6 + 24)) != 1 )
{
return delete_case4(a1, a2);
}
*(_DWORD *)(v7 + 40) = 0;
return delete_case1(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func22(_QWORD *a1, __int64 a2)
{
__int64 v2; // r13
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx

v2 = *(_QWORD *)(a2 + 32);
if ( (unsigned int)func6(v2) != 1 )
return func21(a1, a2);
v4 = func10(a2);
if ( (unsigned int)func6(v4) != 1
|| (unsigned int)func6(*(_QWORD *)(v5 + 16)) != 1
|| (unsigned int)func6(*(_QWORD *)(v6 + 24)) != 1 )
{
return func21(a1, a2);
}
*(_DWORD *)(v7 + 40) = 0;
return func24(a1, v2);
}

original_code:
void delete_case3(bbst tree, node n) {
    if (node_color(n->parent) == BLACK &&
        node_color(sibling(n)) == BLACK &&
        node_color(sibling(n)->left) == BLACK &&
        node_color(sibling(n)->right) == BLACK)
    {
        sibling(n)->color = RED;
        delete_case1(tree, n->parent);
    }
    else
        delete_case4(tree, n);
}

canonical_original_code:
void delete_case3(struct bbst_t *tree, struct bbst_node_t *n) {
    if (node_color(n->parent) == BLACK &&
        node_color(sibling(n)) == BLACK &&
        node_color(sibling(n)->left) == BLACK &&
        node_color(sibling(n)->right) == BLACK)
    {
        sibling(n)->color = RED;
        delete_case1(tree, n->parent);
    }
    else
        delete_case4(tree, n);
}


decompiled_code:
__int64 __fastcall delete_case2(_QWORD *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v4; // r13

v2 = sibling(a2);
if ( (unsigned int)node_color(v2) )
return delete_case3(a1, a2);
v4 = *(_QWORD *)(a2 + 32);
*(_DWORD *)(v4 + 40) = 0;
*(_DWORD *)(sibling(a2) + 40) = 1;
if ( *(_QWORD *)(v4 + 16) == a2 )
{
rotate_left(a1, v4);
return delete_case3(a1, a2);
}
rotate_right(a1, v4);
return delete_case3(a1, a2);
}

original_code:
void delete_case2(bbst tree, node n) {
    if (node_color(sibling(n)) == RED) {
        n->parent->color = RED;
        sibling(n)->color = BLACK;
        if (n == n->parent->left)
            rotate_left(tree, n->parent);
        else
            rotate_right(tree, n->parent);
    }
    delete_case3(tree, n);
}

canonical_original_code:
void delete_case2(struct bbst_t *tree, struct bbst_node_t *n) {
    if (node_color(sibling(n)) == RED) {
        n->parent->color = RED;
        sibling(n)->color = BLACK;
        if (n == n->parent->left)
            rotate_left(tree, n->parent);
        else
            rotate_right(tree, n->parent);
    }
    delete_case3(tree, n);
}


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

if ( *(_QWORD *)(a2 + 32) )
result = delete_case2(a1, a2);
return result;
}

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

if ( *(_QWORD *)(a2 + 32) )
result = func23(a1, a2);
return result;
}

original_code:
void delete_case1(bbst tree, node n) {
    if (n->parent == ((void *)0))
        return;
    else
        delete_case2(tree, n);
}

canonical_original_code:
void delete_case1(struct bbst_t *tree, struct bbst_node_t *n) {
    if (n->parent == ((void *)0))
        return;
    else
        delete_case2(tree, n);
}


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

result = malloc(8uLL);
*result = 0LL;
return result;
}

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

result = malloc(8uLL);
*result = 0LL;
return result;
}

original_code:
bbst bbst_create(){
    bbst tree = malloc(sizeof(struct bbst_t));
    tree->root = ((void *)0);
    return tree;
}

canonical_original_code:
struct bbst_t *bbst_create(){
    struct bbst_t *tree = malloc(sizeof(struct bbst_t));
    tree->root = ((void *)0);
    return tree;
}

return_type: struct bbst_t { struct bbst_node_t { void *key; void *value; struct bbst_node_t *left; struct bbst_node_t *right; struct bbst_node_t *parent; enum bbst_node_color { RED=0, BLACK=1 } color; } *root; } *


decompiled_code:
void __fastcall bbst_insert(_QWORD *a1, __int64 a2, __int64 a3, __int64 (__fastcall *a4)(__int64, _QWORD))
{
_QWORD *v5; // rax
_QWORD *v6; // rbx
_QWORD *v7; // r13
_QWORD *v8; // rax
int v9; // eax

v5 = new_node_constprop_0(a2, a3);
v6 = (_QWORD *)*a1;
v7 = v5;
if ( !*a1 )
{
*a1 = v5;
goto LABEL_10;
}
while ( 1 )
{
v9 = a4(a2, *v6);
if ( !v9 )
{
free(v7);
return;
}
if ( v9 >= 0 )
break;
v8 = (_QWORD *)v6[2];
if ( !v8 )
{
v6[2] = v7;
goto LABEL_12;
}
LABEL_4:
v6 = v8;
}
v8 = (_QWORD *)v6[3];
if ( v8 )
goto LABEL_4;
v6[3] = v7;
LABEL_12:
v7[4] = v6;
LABEL_10:
insert_case1((__int64)a1, v7);
}

canonical_decompiled_code:
void __fastcall func26(_QWORD *a1, __int64 a2, __int64 a3, __int64 (__fastcall *a4)(__int64, _QWORD))
{
_QWORD *v5; // rax
_QWORD *v6; // rbx
_QWORD *v7; // r13
_QWORD *v8; // rax
int v9; // eax

v5 = new_node_constprop_0(a2, a3);
v6 = (_QWORD *)*a1;
v7 = v5;
if ( !*a1 )
{
*a1 = v5;
goto LABEL_10;
}
while ( 1 )
{
v9 = a4(a2, *v6);
if ( !v9 )
{
free(v7);
return;
}
if ( v9 >= 0 )
break;
v8 = (_QWORD *)v6[2];
if ( !v8 )
{
v6[2] = v7;
goto LABEL_12;
}
LABEL_4:
v6 = v8;
}
v8 = (_QWORD *)v6[3];
if ( v8 )
goto LABEL_4;
v6[3] = v7;
LABEL_12:
v7[4] = v6;
LABEL_10:
func17((__int64)a1, v7);
}

original_code:
void bbst_insert(bbst tree, void* key, void* value, compare_func compare){
    node inserted_node = new_node(key, value, RED, ((void *)0), ((void *)0));
    if(tree->root == ((void *)0)){
        tree->root = inserted_node;
    } else {
        node n = tree->root;
        while(1==1){
            int compare_result = compare(key, n->key);
            if(compare_result == 0){
                free(inserted_node);
                return;
            } else if (compare_result < 0) {
                if(n->left == ((void *)0)){
                    n->left = inserted_node;
                    break;
                } else
                    n = n->left;
            } else {
                if(n->right == ((void *)0)){
                    n->right = inserted_node;
                    break;
                } else
                    n = n->right;
            }
        }
        inserted_node->parent = n;
    }
    insert_case1(tree, inserted_node);
}

canonical_original_code:
void bbst_insert(struct bbst_t *tree, void *key, void *value, int (*compare)(void *left, void *right)){
    struct bbst_node_t *inserted_node = new_node(key, value, RED, ((void *)0), ((void *)0));
    if(tree->root == ((void *)0)){
        tree->root = inserted_node;
    } else {
        struct bbst_node_t *n = tree->root;
        while(1==1){
            int compare_result = compare(key, n->key);
            if(compare_result == 0){
                free(inserted_node);
                return;
            } else if (compare_result < 0) {
                if(n->left == ((void *)0)){
                    n->left = inserted_node;
                    break;
                } else
                    n = n->left;
            } else {
                if(n->right == ((void *)0)){
                    n->right = inserted_node;
                    break;
                } else
                    n = n->right;
            }
        }
        inserted_node->parent = n;
    }
    insert_case1(tree, inserted_node);
}

variable_types:
key
void *

variable_types:
value
void *

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

variable_types: struct bbst_node_t { void *key; void *value; struct bbst_node_t *left; struct bbst_node_t *right; struct bbst_node_t *parent; enum bbst_node_color { RED=0, BLACK=1 } color; } *


decompiled_code:
void __fastcall bbst_delete(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(__int64, _QWORD))
{
_QWORD *v3; // rax
__int64 v4; // r12
_QWORD *v5; // rbx
_QWORD *v6; // rbp

v3 = lookup_node_isra_0((_QWORD *)*a1, a2, a3);
if ( v3 )
{
v4 = v3[2];
v5 = v3;
if ( v4 )
{
if ( !v3[3] )
{
v6 = v3;
if ( (unsigned int)node_color((__int64)v3) != 1 )
goto LABEL_7;
goto LABEL_12;
}
v6 = (_QWORD *)maximum_node(v3[2]);
v4 = v6[2];
*v5 = *v6;
v5[1] = v6[1];
if ( v4 )
{
if ( v6[3] )
__assert_fail("n->left == NULL || n->right == NULL", "bbst.c", 0xE3u, "bbst_delete");
goto LABEL_6;
}
}
else
{
v6 = v3;
}
v4 = v6[3];
if ( !v4 )
{
if ( (unsigned int)node_color((__int64)v6) != 1 )
{
replace_node(a1, (__int64)v6, 0LL);
LABEL_10:
free(v6);
return;
}
LABEL_12:
*((_DWORD *)v6 + 10) = node_color(v4);
delete_case1(a1, (__int64)v6);
LABEL_7:
replace_node(a1, (__int64)v6, v4);
if ( !v6[4] )
{
if ( v4 )
*(_DWORD *)(v4 + 40) = 1;
}
goto LABEL_10;
}
LABEL_6:
if ( (unsigned int)node_color((__int64)v6) != 1 )
goto LABEL_7;
goto LABEL_12;
}
}

canonical_decompiled_code:
void __fastcall func27(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(__int64, _QWORD))
{
_QWORD *v3; // rax
__int64 v4; // r12
_QWORD *v5; // rbx
_QWORD *v6; // rbp

v3 = lookup_node_isra_0((_QWORD *)*a1, a2, a3);
if ( v3 )
{
v4 = v3[2];
v5 = v3;
if ( v4 )
{
if ( !v3[3] )
{
v6 = v3;
if ( (unsigned int)func6((__int64)v3) != 1 )
goto LABEL_7;
goto LABEL_12;
}
v6 = (_QWORD *)func18(v3[2]);
v4 = v6[2];
*v5 = *v6;
v5[1] = v6[1];
if ( v4 )
{
if ( v6[3] )
__assert_fail("n->left == NULL || n->right == NULL", "bbst.c", 0xE3u, "bbst_delete");
goto LABEL_6;
}
}
else
{
v6 = v3;
}
v4 = v6[3];
if ( !v4 )
{
if ( (unsigned int)func6((__int64)v6) != 1 )
{
func7(a1, (__int64)v6, 0LL);
LABEL_10:
free(v6);
return;
}
LABEL_12:
*((_DWORD *)v6 + 10) = func6(v4);
func24(a1, (__int64)v6);
LABEL_7:
func7(a1, (__int64)v6, v4);
if ( !v6[4] )
{
if ( v4 )
*(_DWORD *)(v4 + 40) = 1;
}
goto LABEL_10;
}
LABEL_6:
if ( (unsigned int)func6((__int64)v6) != 1 )
goto LABEL_7;
goto LABEL_12;
}
}

original_code:
void bbst_delete(bbst tree, void* key, compare_func compare) {
    node child;
    node n = lookup_node(tree, key, compare);
    if (n == ((void *)0)) return;
    if (n->left != ((void *)0) && n->right != ((void *)0)) {
        node predecessor = maximum_node(n->left);
        n->key = predecessor->key;
        n->value = predecessor->value;
        n = predecessor;
    }
    ((void) sizeof ((n->left == ((void *)0) || n->right == ((void *)0)) ? 1 : 0), __extension__ ({ if (n->left == ((void *)0) || n->right == ((void *)0)) ; else __assert_fail ("n->left == NULL || n->right == NULL", "bbst.c", 227, __extension__ __PRETTY_FUNCTION__); }));
    child = n->right == ((void *)0) ? n->left : n->right;
    if (node_color(n) == BLACK) {
        n->color = node_color(child);
        delete_case1(tree, n);
    }
    replace_node(tree, n, child);
    if (n->parent == ((void *)0) && child != ((void *)0))
        child->color = BLACK;
    free(n);
}

canonical_original_code:
void bbst_delete(struct bbst_t *tree, void *key, int (*compare)(void *left, void *right)) {
    struct bbst_node_t *child;
    struct bbst_node_t *n = lookup_node(tree, key, compare);
    if (n == ((void *)0)) return;
    if (n->left != ((void *)0) && n->right != ((void *)0)) {
        struct bbst_node_t *predecessor = maximum_node(n->left);
        n->key = predecessor->key;
        n->value = predecessor->value;
        n = predecessor;
    }
    ((void) sizeof ((n->left == ((void *)0) || n->right == ((void *)0)) ? 1 : 0), __extension__ ({ if (n->left == ((void *)0) || n->right == ((void *)0)) ; else __assert_fail ("n->left == NULL || n->right == NULL", "bbst.c", 227, __extension__ __PRETTY_FUNCTION__); }));
    child = n->right == ((void *)0) ? n->left : n->right;
    if (node_color(n) == BLACK) {
        n->color = node_color(child);
        delete_case1(tree, n);
    }
    replace_node(tree, n, child);
    if (n->parent == ((void *)0) && child != ((void *)0))
        child->color = BLACK;
    free(n);
}


decompiled_code:
_QWORD *list_init()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x10uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
}
else
{
puts("\n Node creation failed ");
}
return v1;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x10uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
}
else
{
puts("\n Node creation failed ");
}
return v1;
}

original_code:
struct list_t* list_init(){
    struct list_t *ptr = (struct list_t*)malloc(sizeof(struct list_t));
    if(((void *)0) == ptr)
    {
        printf("\n Node creation failed \n");
        return ((void *)0);
    }
    ptr->data = ((void *)0);
    ptr->next = ((void *)0);
    return ptr;
}

canonical_original_code:
struct list_t *list_init(){
    struct list_t *ptr = (struct list_t*)malloc(sizeof(struct list_t));
    if(((void *)0) == ptr)
    {
        printf("\n Node creation failed \n");
        return ((void *)0);
    }
    ptr->data = ((void *)0);
    ptr->next = ((void *)0);
    return ptr;
}

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


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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
{
if ( !*a1 )
break;
a1 = (_QWORD *)a1[1];
}
return result;
}

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
{
if ( !*a1 )
break;
a1 = (_QWORD *)a1[1];
}
return result;
}

original_code:
int list_size(struct list_t *head){
    int i=0;
    while(head != ((void *)0) && head->data != ((void *)0)){
        i++;
        head = head->next;
    }
    return i;
}

canonical_original_code:
int list_size(struct list_t *head){
    int i = 0;
    while(head != ((void *)0) && head->data != ((void *)0)){
        i++;
        head = head->next;
    }
    return i;
}

variable_types: i int

return_type: int

user_defined_types: struct list_t { void *data; struct list_t *next; }


decompiled_code:
int __fastcall list_print(const void **a1)
{
const void **v1; // rbx
unsigned int v2; // eax
int result; // eax
__int64 v4; // rsi

v1 = a1;
v2 = list_size(a1);
if ( !v2 )
return puts("List is empty");
result = printf("\nList with size = %d contains:\n", v2);
v4 = 0LL;
if ( a1 )
{
while ( *v1 )
{
result = printf("\t%d\t%p\n", v4, *v1);
v1 = (const void **)v1[1];
if ( !v1 )
break;
v4 = (unsigned int)(v4 + 1);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(const void **a1)
{
const void **v1; // rbx
unsigned int v2; // eax
int result; // eax
__int64 v4; // rsi

v1 = a1;
v2 = func8(a1);
if ( !v2 )
return puts("List is empty");
result = printf("\nList with size = %d contains:\n", v2);
v4 = 0LL;
if ( a1 )
{
while ( *v1 )
{
result = printf("\t%d\t%p\n", v4, *v1);
v1 = (const void **)v1[1];
if ( !v1 )
break;
v4 = (unsigned int)(v4 + 1);
}
}
return result;
}

original_code:
void list_print(struct list_t *head){
    struct list_t *ptr = head;
    int i = 0;
    if(list_size(head) == 0){
        printf("List is empty\n");
        return;
    }
    printf("\nList with size = %d contains:\n", list_size(head));
    while(((void *)0) != ptr && ((void *)0) != ptr->data){
        printf("\t%d\t%p\n", i++, ptr->data);
        ptr = ptr->next;
    }
    return;
}


decompiled_code:
int __fastcall list_insert_after(_QWORD *a1, __int64 a2, int a3)
{
_QWORD *v4; // rbx
_QWORD *v5; // rdx
int v6; // eax
__int64 v7; // rax

v4 = a1;
if ( malloc(0x10uLL) && a3 >= 0 && (int)list_size(a1) > a3 )
{
v6 = 0;
if ( a3 > 0 )
{
do
{
++v6;
v4 = (_QWORD *)v4[1];
}
while ( a3 != v6 );
}
v7 = v4[1];
*v5 = a2;
v5[1] = v7;
v4[1] = v5;
}
else
{
LODWORD(v7) = printf("\nNode adding after %d failed \n", (unsigned int)a3);
}
return v7;
}

canonical_decompiled_code:
int __fastcall func11(_QWORD *a1, __int64 a2, int a3)
{
_QWORD *v4; // rbx
_QWORD *v5; // rdx
int v6; // eax
__int64 v7; // rax

v4 = a1;
if ( malloc(0x10uLL) && a3 >= 0 && (int)func8(a1) > a3 )
{
v6 = 0;
if ( a3 > 0 )
{
do
{
++v6;
v4 = (_QWORD *)v4[1];
}
while ( a3 != v6 );
}
v7 = v4[1];
*v5 = a2;
v5[1] = v7;
v4[1] = v5;
}
else
{
LODWORD(v7) = printf("\nNode adding after %d failed \n", (unsigned int)a3);
}
return v7;
}

original_code:
void list_insert_after(struct list_t *head, void *data, int pos){
    struct list_t *ptr = (struct list_t*)malloc(sizeof(struct list_t));
    if(((void *)0) == ptr || pos < 0 || list_size(head) <= pos)
    {
        printf("\nNode adding after %d failed \n", pos);
        return;
    }
    int i;
    for(i = 0; i < pos; i++)
        head = head->next;
    ptr->data = data;
    ptr->next = head->next;
    head->next = ptr;
    return;
}

variable_types:
data
void *

variable_types: pos int


decompiled_code:
void __fastcall list_insert_rear(_QWORD **a1, __int64 a2)
{
int v2; // eax
_QWORD **v3; // r8
_QWORD *v4; // r9

v2 = list_size(*a1);
if ( v2 )
list_insert_after(v4, a2, v2 - 1);
else
list_insert_front(v3, a2);
}

canonical_decompiled_code:
void __fastcall func12(_QWORD **a1, __int64 a2)
{
int v2; // eax
_QWORD **v3; // r8
_QWORD *v4; // r9

v2 = func8(*a1);
if ( v2 )
func11(v4, a2, v2 - 1);
else
func10(v3, a2);
}

original_code:
void list_insert_rear(struct list_t* *head, void *data){
    int size = list_size(*head);
    if(size == 0){
        list_insert_front(head, data);
    } else {
        list_insert_after(*head, data, size-1);
    }
    return;
}

canonical_original_code:
void list_insert_rear(struct list_t **head, void *data){
    int size = list_size(*head);
    if(size == 0){
        list_insert_front(head, data);
    } else {
        list_insert_after(*head, data, size-1);
    }
    return;
}

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

variable_types: size int


decompiled_code:
void __fastcall list_remove_front(_QWORD **a1)
{
_QWORD *v1; // rdx
_QWORD *v2; // r8

if ( (int)list_size(*a1) > 1 )
{
*v1 = v2[1];
free(v2);
}
else
{
*v2 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func13(_QWORD **a1)
{
_QWORD *v1; // rdx
_QWORD *v2; // r8

if ( (int)func8(*a1) > 1 )
{
*v1 = v2[1];
free(v2);
}
else
{
*v2 = 0LL;
}
}

original_code:
void list_remove_front(struct list_t* *head){
    struct list_t *temp = (*head);
    if(list_size(*head) > 1){
        *head = temp->next;
        free(temp);
    } else {
        (*head)->data = ((void *)0);
    }
}

canonical_original_code:
void list_remove_front(struct list_t **head){
    struct list_t *temp = (*head);
    if(list_size(*head) > 1){
        *head = temp->next;
        free(temp);
    } else {
        (*head)->data = ((void *)0);
    }
}


decompiled_code:
void __fastcall list_remove_rear(_QWORD **a1)
{
_QWORD *v2; // rdx
_QWORD *i; // rdi

v2 = 0LL;
for ( i = *a1; i; i = (_QWORD *)i[1] )
{
if ( !i[1] )
{
if ( v2 )
{
v2[1] = 0LL;
free(i);
}
else
{
list_remove_front(a1);
}
return;
}
v2 = i;
}
}

canonical_decompiled_code:
void __fastcall func14(_QWORD **a1)
{
_QWORD *v2; // rdx
_QWORD *i; // rdi

v2 = 0LL;
for ( i = *a1; i; i = (_QWORD *)i[1] )
{
if ( !i[1] )
{
if ( v2 )
{
v2[1] = 0LL;
free(i);
}
else
{
func13(a1);
}
return;
}
v2 = i;
}
}

original_code:
void list_remove_rear(struct list_t* *head){
    struct list_t *prev = ((void *)0);
    struct list_t *temp = *head;
    while(temp != ((void *)0) && temp->next != ((void *)0)){
        prev = temp;
        temp = temp->next;
    }
    if(temp != ((void *)0)){
        if(prev == ((void *)0))
            list_remove_front(head);
        else{
            prev->next = temp->next;
            free(temp);
        }
    }
}

canonical_original_code:
void list_remove_rear(struct list_t **head){
    struct list_t *prev = ((void *)0);
    struct list_t *temp = *head;
    while(temp != ((void *)0) && temp->next != ((void *)0)){
        prev = temp;
        temp = temp->next;
    }
    if(temp != ((void *)0)){
        if(prev == ((void *)0))
            list_remove_front(head);
        else{
            prev->next = temp->next;
            free(temp);
        }
    }
}


decompiled_code:
void __fastcall list_remove_any(_QWORD **a1, __int64 a2)
{
_QWORD *v3; // rdi
_QWORD *v4; // rdx

v3 = *a1;
v4 = 0LL;
if ( v3 )
{
while ( *v3 != a2 && *v3 )
{
v4 = v3;
if ( !v3[1] )
return;
v3 = (_QWORD *)v3[1];
}
if ( v4 )
{
v4[1] = v3[1];
free(v3);
}
else
{
list_remove_front(a1);
}
}
}

original_code:
void list_remove_any(struct list_t* *head, void *data){
    struct list_t *prev = ((void *)0);
    struct list_t *temp = *head;
    while(temp != ((void *)0) && temp->data != ((void *)0) && temp->data != data){
        prev = temp;
        temp = temp->next;
    }
    if(temp != ((void *)0)){
        if(prev == ((void *)0))
            list_remove_front(head);
        else{
            prev->next = temp->next;
            free(temp);
        }
    }
}

canonical_original_code:
void list_remove_any(struct list_t **head, void *data){
    struct list_t *prev = ((void *)0);
    struct list_t *temp = *head;
    while(temp != ((void *)0) && temp->data != ((void *)0) && temp->data != data){
        prev = temp;
        temp = temp->next;
    }
    if(temp != ((void *)0)){
        if(prev == ((void *)0))
            list_remove_front(head);
        else{
            prev->next = temp->next;
            free(temp);
        }
    }
}


search

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

if ( !a1 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *a1 != a2 )
{
a1 = (_QWORD *)a1[1];
result = (unsigned int)(result + 1);
if ( !a1 )
return 0xFFFFFFFFLL;
}
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *a1 != a2 )
{
a1 = (_QWORD *)a1[1];
result = (unsigned int)(result + 1);
if ( !a1 )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int search(struct list_t *head, void *data){
    int i = 0;
    while(head != ((void *)0)){
        if(head->data == data)
            return i;
        head = head->next;
        i++;
    }
    return -1;
}


main

canonical_name: main

repo: uniquerockrz/PurgeOldVersion

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

if ( argc == 1 )
{
printf("Please enter filelist's filename : ");
__isoc99_scanf();
}
else
{
strcpy(v5, argv[1]);
}
v3 = copytobuffer(v5);
if ( v3 != -1 )
findduplicates(v3);
return 0;
}

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

if ( argc == 1 )
{
printf("Please enter filelist's filename : ");
__isoc99_scanf();
}
else
{
strcpy(v5, argv[1]);
}
v3 = func7(v5);
if ( v3 != -1 )
func12(v3);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    char filename[20];
    int lines;
    int copytobuffer(char *);
    void findduplicates(int);
    if(argc==1){
        printf("Please enter filelist\'s filename : ");
        scanf("%s", filename);
    }
    else
        strcpy(filename, argv[1]);
    lines=copytobuffer(filename);
    if(lines==-1)
        return 0;
    findduplicates(lines);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
filename
char [20]

variable_types: lines int

variable_types:
copytobuffer
int (char *)

variable_types:
findduplicates
void (int)


chop

decompiled_code:
__int64 __fastcall chop(char *src, char *dest)
{
size_t v2; // r12
size_t v3; // rbx

v2 = 0LL;
v3 = strlen(src);
while ( v3 != v2 && (src[v2] != 45 || ((*__ctype_b_loc())[src[v2 + 1]] & 0x800) == 0) )
++v2;
strncpy(dest, src, v2);
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *src, char *dest)
{
size_t v2; // r12
size_t v3; // rbx

v2 = 0LL;
v3 = strlen(src);
while ( v3 != v2 && (src[v2] != 45 || ((*__ctype_b_loc())[src[v2 + 1]] & 0x800) == 0) )
++v2;
strncpy(dest, src, v2);
return (unsigned int)v2;
}

original_code:
int chop(char fullfilename[200], char dest[100]){
    int i;
    for(i=0;i<strlen(fullfilename);i++){
        if(fullfilename[i]=='-' && ((*__ctype_b_loc ())[(int) ((fullfilename[i+1]))] & (unsigned short int) _ISdigit))
            break;
    }
    strncpy(dest, fullfilename, i);
    return i;
}

canonical_original_code:
int chop(char fullfilename[200], char dest[100]){
    int i;
    for(i=0;i<strlen(fullfilename);i++){
        if(fullfilename[i]=='-' && ((*__ctype_b_loc ())[(int) ((fullfilename[i+1]))] & (unsigned short) _ISdigit))
            break;
    }
    strncpy(dest, fullfilename, i);
    return i;
}

variable_types:
fullfilename
char [200]

variable_types:
dest
char [100]


strcompare

decompiled_code:
__int64 __fastcall strcompare(char *a1, char *a2)
{
char v2; // dl
__int64 result; // rax
char v4; // cl
__int64 i; // rax

v2 = *a1;
result = 0LL;
if ( *a1 )
{
v4 = *a2;
if ( *a2 )
{
for ( i = 1LL; ; ++i )
{
if ( v4 != v2 )
return 0LL;
v2 = a1[i];
if ( !v2 )
break;
v4 = a2[i];
}
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1, char *a2)
{
char v2; // dl
__int64 result; // rax
char v4; // cl
__int64 i; // rax

v2 = *a1;
result = 0LL;
if ( *a1 )
{
v4 = *a2;
if ( *a2 )
{
for ( i = 1LL; ; ++i )
{
if ( v4 != v2 )
return 0LL;
v2 = a1[i];
if ( !v2 )
break;
v4 = a2[i];
}
result = 1LL;
}
}
return result;
}

original_code:
int strcompare(char str1[200], char str2[200]){
    int i=0;
    if(str1[0]=='\0' || str2[0]=='\0')
        return 0;
    else{
        while(str1[i]!='\0'){
            if(str1[i]!=str2[i])
                return 0;
            i++;
        }
    }
    return 1;
}

canonical_original_code:
int strcompare(char str1[200], char str2[200]){
    int i = 0;
    if(str1[0]=='\0' || str2[0]=='\0')
        return 0;
    else{
        while(str1[i]!='\0'){
            if(str1[i]!=str2[i])
                return 0;
            i++;
        }
    }
    return 1;
}


cutslashn

decompiled_code:
size_t __fastcall cutslashn(const char *a1)
{
size_t result; // rax

result = strlen(a1);
a1[result - 1] = 0;
return result;
}

canonical_decompiled_code:
size_t __fastcall func10(const char *a1)
{
size_t result; // rax

result = strlen(a1);
a1[result - 1] = 0;
return result;
}

original_code:
void cutslashn(char str[200]){
    str[strlen(str)-1]='\0';
}

variable_types:
str
char [200]


findduplicates

decompiled_code:
int __fastcall findduplicates(int a1)
{
int v1; // er13
__int64 i; // rbp
int v4; // eax
char *v5; // rdi
int v6; // ebx
__int64 v7; // rax
char v9[248]; // [rsp+0h] [rbp-F8h] BYREF

v1 = 0;
for ( i = 0LL; a1 >= v1; choppedfilename[200 * v7 + 1 + v6] = 0 )
{
v4 = chop(&buffer[i], v9);
v5 = &choppedfilename[i];
i += 200LL;
v6 = v4;
strncpy(v5, v9, v4);
v7 = v1++;
}
return finddup(a1);
}

canonical_decompiled_code:
int __fastcall func12(int a1)
{
int v1; // er13
__int64 i; // rbp
int v4; // eax
char *v5; // rdi
int v6; // ebx
__int64 v7; // rax
char v9[248]; // [rsp+0h] [rbp-F8h] BYREF

v1 = 0;
for ( i = 0LL; a1 >= v1; choppedfilename[200 * v7 + 1 + v6] = 0 )
{
v4 = func8(&buffer[i], v9);
v5 = &choppedfilename[i];
i += 200LL;
v6 = v4;
strncpy(v5, v9, v4);
v7 = v1++;
}
return func11(a1);
}

original_code:
void findduplicates(int files){
    int i, l;
    char str[200];
    int chop(char *, char *);
    void finddup(int);
    for(i=0;i<=files;i++){
        l=chop(buffer[i], str);
        strncpy(choppedfilename[i], str, l);
        choppedfilename[i][l+1]='\0';
    }
    finddup(files);
}

canonical_original_code:
void findduplicates(int files){
    int i; int l;
    char str[200];
    int chop(char *, char *);
    void finddup(int);
    for(i=0;i<=files;i++){
        l=chop(buffer[i], str);
        strncpy(choppedfilename[i], str, l);
        choppedfilename[i][l+1]='\0';
    }
    finddup(files);
}

variable_types: files int

variable_types: l int

variable_types:
chop
int (char *, char *)

variable_types:
finddup
void (int)


start

repo: uniquerockrz/smsh

decompiled_code:
int __fastcall start(__int64 a1)
{
struct tm *v1; // rax
FILE *v2; // r12
char *v3; // rax
int result; // eax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
v2 = stdout;
v3 = asctime(v1);
fputs(v3, v2);
printf("Checking inbox now.... ");
if ( (unsigned int)get_page(a1, ".downloaded_feed") )
return puts("Could not download page.");
puts("done");
printf("Looking for any new message... ");
trimfeed();
result = analyzefeed();
if ( result )
result = puts("\nCould not analyze XML feed.");
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
struct tm *v1; // rax
FILE *v2; // r12
char *v3; // rax
int result; // eax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
v2 = stdout;
v3 = asctime(v1);
fputs(v3, v2);
printf("Checking inbox now.... ");
if ( (unsigned int)get_page(a1, ".downloaded_feed") )
return puts("Could not download page.");
puts("done");
printf("Looking for any new message... ");
trimfeed();
result = analyzefeed();
if ( result )
result = puts("\nCould not analyze XML feed.");
return result;
}

original_code:
void start (char *url)
{
 time_t currenttime;
 struct tm *loctime;
 currenttime=time(((void *)0));
 loctime= localtime(&currenttime);
 fputs(asctime(loctime), stdout);
 printf("Checking inbox now.... ");
 int pageStatus, analyzeStatus;
 pageStatus = get_page( url, ".downloaded_feed" );
 if (pageStatus == 0) {
  printf("done\n");
  printf("Looking for any new message... ");
  trimfeed();
  analyzeStatus = analyzefeed();
  if (analyzeStatus != 0)
   printf("\nCould not analyze XML feed.\n");
 } else
  printf("Could not download page.\n");
}

canonical_original_code:
void start(char *url)
{
 long currenttime;
 struct tm *loctime;
 currenttime=time(((void *)0));
 loctime= localtime(&currenttime);
 fputs(asctime(loctime), stdout);
 printf("Checking inbox now.... ");
 int pageStatus; int analyzeStatus;
 pageStatus = get_page( url, ".downloaded_feed" );
 if (pageStatus == 0) {
  printf("done\n");
  printf("Looking for any new message... ");
  trimfeed();
  analyzeStatus = analyzefeed();
  if (analyzeStatus != 0)
   printf("\nCould not analyze XML feed.\n");
 } else
  printf("Could not download page.\n");
}

variable_types:
url
char *

variable_types: currenttime long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; } *

variable_types: pageStatus int

variable_types: analyzeStatus int


substring

decompiled_code:
unsigned __int64 __fastcall substring(char *s, int a2, int a3, __int64 a4)
{
__int64 v4; // r12
unsigned __int64 v5; // rbx
__int64 v6; // r13
unsigned __int64 result; // rax

v4 = ~(__int64)a3;
v5 = a2;
v6 = a4 - a2;
while ( 1 )
{
result = v4 + strlen(s);
if ( result < v5 )
break;
*(_BYTE *)(v6 + v5) = s[v5];
++v5;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(char *s, int a2, int a3, __int64 a4)
{
__int64 v4; // r12
unsigned __int64 v5; // rbx
__int64 v6; // r13
unsigned __int64 result; // rax

v4 = ~(__int64)a3;
v5 = a2;
v6 = a4 - a2;
while ( 1 )
{
result = v4 + strlen(s);
if ( result < v5 )
break;
*(_BYTE *)(v6 + v5) = s[v5];
++v5;
}
return result;
}

original_code:
void substring(char *src, int stripFromBewb, int stripFromAss, char *dest)
{
 for (int destIndex = 0; stripFromBewb <= (strlen(src)-1-stripFromAss);
  stripFromBewb++, destIndex++)
  dest[destIndex] = src[stripFromBewb];
}

variable_types:
src
char *

variable_types: stripFromBewb int

variable_types: stripFromAss int

variable_types:
dest
char *

variable_types: destIndex int


compareTime

decompiled_code:
__int64 __fastcall compareTime(const char *a1, const char *a2)
{
time_t v2; // rbp
time_t v3; // rax
double v4; // xmm0_8
__int64 result; // rax
struct tm v6; // [rsp+0h] [rbp-88h] BYREF
struct tm tp; // [rsp+40h] [rbp-48h] BYREF

*(_OWORD *)&v6.tm_sec = 0LL;
*(_OWORD *)&v6.tm_mon = 0LL;
*(_OWORD *)&v6.tm_isdst = 0LL;
*(_OWORD *)&tp.tm_sec = 0LL;
*(_OWORD *)&tp.tm_mon = 0LL;
*(_OWORD *)&tp.tm_isdst = 0LL;
v6.tm_zone = 0LL;
tp.tm_zone = 0LL;
strptime(a1, "%d %b %Y %H:%M:%S", &v6);
strptime(a2, "%d %b %Y %H:%M:%S", &tp);
v2 = mktime(&v6);
v3 = mktime(&tp);
v4 = difftime(v2, v3);
if ( v4 == 0.0 )
result = 0LL;
else
result = 2 * (unsigned int)(v4 > 0.0) - 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
time_t v2; // rbp
time_t v3; // rax
double v4; // xmm0_8
__int64 result; // rax
struct tm v6; // [rsp+0h] [rbp-88h] BYREF
struct tm tp; // [rsp+40h] [rbp-48h] BYREF

*(_OWORD *)&v6.tm_sec = 0LL;
*(_OWORD *)&v6.tm_mon = 0LL;
*(_OWORD *)&v6.tm_isdst = 0LL;
*(_OWORD *)&tp.tm_sec = 0LL;
*(_OWORD *)&tp.tm_mon = 0LL;
*(_OWORD *)&tp.tm_isdst = 0LL;
v6.tm_zone = 0LL;
tp.tm_zone = 0LL;
strptime(a1, "%d %b %Y %H:%M:%S", &v6);
strptime(a2, "%d %b %Y %H:%M:%S", &tp);
v2 = mktime(&v6);
v3 = mktime(&tp);
v4 = difftime(v2, v3);
if ( v4 == 0.0 )
result = 0LL;
else
result = 2 * (unsigned int)(v4 > 0.0) - 1;
return result;
}

original_code:
int compareTime (char *date1, char *date2)
{
 struct tm datestruct1, datestruct2;
 time_t time1, time2;
 memset(&datestruct1, 0, sizeof(struct tm));
 memset(&datestruct2, 0, sizeof(struct tm));
 strptime(date1, "%d %b %Y %H:%M:%S", &datestruct1);
 strptime(date2, "%d %b %Y %H:%M:%S", &datestruct2);
 time1 = mktime(&datestruct1);
 time2 = mktime(&datestruct2);
 double diff;
 diff = difftime(time1, time2);
 if (diff == 0.0)
  return 0;
 else if (diff > 0)
  return 1;
 else
  return -1;
}

canonical_original_code:
int compareTime(char *date1, char *date2)
{
 struct tm datestruct1; struct tm datestruct2;
 long time1; long time2;
 memset(&datestruct1, 0, sizeof(struct tm));
 memset(&datestruct2, 0, sizeof(struct tm));
 strptime(date1, "%d %b %Y %H:%M:%S", &datestruct1);
 strptime(date2, "%d %b %Y %H:%M:%S", &datestruct2);
 time1 = mktime(&datestruct1);
 time2 = mktime(&datestruct2);
 double diff;
 diff = difftime(time1, time2);
 if (diff == 0.0)
  return 0;
 else if (diff > 0)
  return 1;
 else
  return -1;
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; }

variable_types: diff double


repo: unixo/DBIS

decompiled_code:
__int64 db_connect()
{
__int64 v0; // rax
__int64 result; // rax

v0 = mysql_init(0LL);
db_conn = v0;
if ( !v0 )
{
fwrite("[ERR] mySQL framework init failed\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
result = mysql_real_connect(v0, "localhost", "root", &unk_966, "dbis", 0LL, 0LL, 0x10000LL);
if ( !result )
{
fwrite("[ERR] unable to contact mySQL server or authentication failed\n", 1uLL, 0x3EuLL, stderr);
exit(1);
}
return result;
}

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

v0 = mysql_init(0LL);
db_conn = v0;
if ( !v0 )
{
fwrite("[ERR] mySQL framework init failed\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
result = mysql_real_connect(v0, "localhost", "root", &unk_966, "dbis", 0LL, 0LL, 0x10000LL);
if ( !result )
{
fwrite("[ERR] unable to contact mySQL server or authentication failed\n", 1uLL, 0x3EuLL, stderr);
exit(1);
}
return result;
}

original_code:
void
db_connect()
{
    db_conn = mysql_init(((void *)0));
    if (db_conn == ((void *)0)) {
        fprintf(stderr, "[ERR] mySQL framework init failed\n");
        exit(1);
    }
    if (mysql_real_connect(db_conn, "localhost", "root", "", "dbis",
                           0, ((void *)0), (1UL << 16)) == ((void *)0)) {
        fprintf(stderr, "[ERR] unable to contact mySQL server or "
                "authentication failed\n");
        exit(1);;
    }
}


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

if ( db_conn )
result = mysql_close();
db_conn = 0LL;
return result;
}

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

if ( db_conn )
result = mysql_close();
db_conn = 0LL;
return result;
}

original_code:
void
db_close()
{
    if (db_conn)
        mysql_close(db_conn);
    db_conn = ((void *)0);
}


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

if ( db_conn )
result = mysql_insert_id();
else
result = -1LL;
return result;
}

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

if ( db_conn )
result = mysql_insert_id();
else
result = -1LL;
return result;
}

original_code:
my_ulonglong
db_last_id()
{
    if (!db_conn)
        return (my_ulonglong) - 1;
    return mysql_insert_id(db_conn);
}

canonical_original_code:
unsigned long long db_last_id()
{
    if (!db_conn)
        return (my_ulonglong) - 1;
    return mysql_insert_id(db_conn);
}

return_type: unsigned long long


Log

repo: unixtools/authsrv

decompiled_code:
__int64 __fastcall Log(const char *a1, const char *a2, const char *a3, const char *a4)
{
const char *v6; // rbp
const char *v7; // rbx
__gid_t v8; // er14
__uid_t v9; // eax
__int64 v11; // [rsp-10h] [rbp-38h]

v6 = a2;
v7 = a1;
openlog("authsrv", 17, 80);
if ( !a4 )
a4 = "Null";
if ( !a3 )
a3 = "Null";
if ( !a2 )
v6 = "Null";
if ( !a1 )
v7 = "Null";
v8 = getgid();
v9 = getuid();
syslog(7, "Who(%d/%d) Action(%s) Owner(%s) User(%s) Instance(%s)", v9, v8, v7, v6, a3, a4);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2, const char *a3, const char *a4)
{
const char *v6; // rbp
const char *v7; // rbx
__gid_t v8; // er14
__uid_t v9; // eax
__int64 v11; // [rsp-10h] [rbp-38h]

v6 = a2;
v7 = a1;
openlog("authsrv", 17, 80);
if ( !a4 )
a4 = "Null";
if ( !a3 )
a3 = "Null";
if ( !a2 )
v6 = "Null";
if ( !a1 )
v7 = "Null";
v8 = getgid();
v9 = getuid();
syslog(7, "Who(%d/%d) Action(%s) Owner(%s) User(%s) Instance(%s)", v9, v8, v7, v6, a3, a4);
return v11;
}

original_code:
void Log(char *action, char *owner, char *user, char *instance)
{
 openlog("authsrv", 0x01 | 0x10, (10<<3));
 syslog(7, "Who(%d/%d) Action(%s) Owner(%s) User(%s) Instance(%s)",
        getuid(), getgid(), ((action)?(action):("Null")), ((owner)?(owner):("Null")), ((user)?(user):("Null")), ((instance)?(instance):("Null")));
}

variable_types:
action
char *

variable_types:
owner
char *

variable_types:
user
char *

variable_types:
instance
char *


decompiled_code:
const char *__fastcall check_element(const char *a1)
{
size_t v1; // rax
const char *v2; // r8
const char *v3; // rcx
__int64 v4; // rsi
int v5; // eax
unsigned __int64 v6; // rax

if ( !a1 )
return "must specify";
v1 = strlen(a1);
v2 = "too long";
if ( v1 > 0x28 )
return v2;
if ( !v1 )
return 0LL;
v3 = &a1[v1];
v4 = 0x10FFFFFFE47FEDLL;
while ( 1 )
{
v5 = *(unsigned __int8 *)a1;
if ( (unsigned __int8)(v5 - 97) > 0x19u )
{
v6 = (unsigned int)(v5 - 43);
if ( (unsigned __int8)v6 > 0x34u || !_bittest64(&v4, v6) )
break;
}
if ( ++a1 == v3 )
return 0LL;
}
return "invalid character in string";
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
size_t v1; // rax
const char *v2; // r8
const char *v3; // rcx
__int64 v4; // rsi
int v5; // eax
unsigned __int64 v6; // rax

if ( !a1 )
return "must specify";
v1 = strlen(a1);
v2 = "too long";
if ( v1 > 0x28 )
return v2;
if ( !v1 )
return 0LL;
v3 = &a1[v1];
v4 = 0x10FFFFFFE47FEDLL;
while ( 1 )
{
v5 = *(unsigned __int8 *)a1;
if ( (unsigned __int8)(v5 - 97) > 0x19u )
{
v6 = (unsigned int)(v5 - 43);
if ( (unsigned __int8)v6 > 0x34u || !_bittest64(&v4, v6) )
break;
}
if ( ++a1 == v3 )
return 0LL;
}
return "invalid character in string";
}

original_code:
char *check_element(char *str)
{
 int i;
 if (!str) {
  return "must specify";
 }
 if (strlen(str) > 40) {
  return "too long";
 }
 for (i = 0; i < strlen(str); i++) {
  char ch = str[i];
  if ((ch >= 'A' && ch <= 'Z') ||
      (ch >= 'a' && ch <= 'z') ||
      (ch >= '0' && ch <= '9') ||
      (ch == '@') || (ch == '-') || (ch == '_') || (ch == '+') || (ch == '=') || (ch == '.')) {
  } else {
   return "invalid character in string";
  }
 }
 return ((void *)0);
}

variable_types:
str
char *

variable_types: i int

variable_types: ch char

return_type: char *


decompiled_code:
const char *__fastcall check_content(const char *a1)
{
bool v1; // cc
const char *result; // rax

if ( !a1 )
return "must specify";
v1 = strlen(a1) <= 0x7D00;
result = "too long";
if ( v1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1)
{
bool v1; // cc
const char *result; // rax

if ( !a1 )
return "must specify";
v1 = strlen(a1) <= 0x7D00;
result = "too long";
if ( v1 )
result = 0LL;
return result;
}

original_code:
char *check_content(char *str)
{
 if (!str) {
  return "must specify";
 }
 if (strlen(str) > 32000) {
  return "too long";
 }
 return ((void *)0);
}


AllocDataBlock

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

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

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

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

original_code:
struct DataBlock *AllocDataBlock()
{
 struct DataBlock *tmp;
 tmp = (struct DataBlock *)malloc(sizeof(struct DataBlock));
 tmp->length = 0;
 tmp->data = 0;
 return tmp;
}

variable_types: struct DataBlock { unsigned char *data; int length; } *


FetchHostKey

decompiled_code:
_DWORD *FetchHostKey()
{
return FileToDataBlock("/usr/share/authsrv/host-key");
}

canonical_decompiled_code:
_DWORD *func5()
{
return FileToDataBlock("/usr/share/authsrv/host-key");
}

original_code:
struct DataBlock *FetchHostKey(void)
{
 struct DataBlock *key = ((void *)0);
 key = FileToDataBlock("/usr/share/authsrv" "/" "host-key");
 return key;
}

canonical_original_code:
struct DataBlock *FetchHostKey()
{
 struct DataBlock *key = ((void *)0);
 key = FileToDataBlock("/usr/share/authsrv" "/" "host-key");
 return key;
}

return_type: struct DataBlock { unsigned char *data; int length; } *


FreeDataBlock

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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void FreeDataBlock(struct DataBlock *datablock)
{
 if (datablock) {
  if (datablock->data) {
   free(datablock->data);
  }
  free(datablock);
 }
}

user_defined_types: struct DataBlock { unsigned char *data; int length; }


decompiled_code:
int __fastcall err_doit(int a1, const char *a2, void *a3)
{
int v4; // er13
size_t v5; // rax
FILE *v6; // rdi
char *v8; // r12
size_t v9; // rax
char s[2]; // [rsp+0h] [rbp-228h] BYREF

v4 = *_errno_location();
vsprintf(s, a2, a3);
if ( a1 )
{
v8 = strerror(v4);
v9 = strlen(s);
sprintf(&s[v9], ": %s", v8);
}
v5 = strlen(s);
v6 = stdout;
*(_WORD *)&s[v5] = 10;
fflush(v6);
fputs(s, stderr);
return fflush(stderr);
}

canonical_decompiled_code:
int __fastcall func0(int a1, const char *a2, void *a3)
{
int v4; // er13
size_t v5; // rax
FILE *v6; // rdi
char *v8; // r12
size_t v9; // rax
char s[2]; // [rsp+0h] [rbp-228h] BYREF

v4 = *_errno_location();
vsprintf(s, a2, a3);
if ( a1 )
{
v8 = strerror(v4);
v9 = strlen(s);
sprintf(&s[v9], ": %s", v8);
}
v5 = strlen(s);
v6 = stdout;
*(_WORD *)&s[v5] = 10;
fflush(v6);
fputs(s, stderr);
return fflush(stderr);
}

original_code:
static void err_doit(int errnoflag, const char *fmt, va_list ap) {
   int errno_save;
   char buf[512];
   errno_save = (*__errno_location ());
   vsprintf(buf, fmt, ap);
   if(errnoflag)
     sprintf(buf+strlen(buf), ": %s", strerror(errno_save));
   strcat(buf, "\n");
   fflush(stdout);
   fputs(buf, stderr);
   fflush(stderr);
   return;
}

canonical_original_code:
static void err_doit(int errnoflag, char *fmt, __builtin_va_list ap) {
   int errno_save;
   char buf[512];
   errno_save = (*__errno_location ());
   vsprintf(buf, fmt, ap);
   if(errnoflag)
     sprintf(buf+strlen(buf), ": %s", strerror(errno_save));
   strcat(buf, "\n");
   fflush(stdout);
   fputs(buf, stderr);
   fflush(stderr);
   return;
}

variable_types: errnoflag int

variable_types:
fmt
char *

variable_types:
buf
char [512]


decompiled_code:
void __noreturn err_sys(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
err_doit(1, a1, va);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(1, a1, va);
exit(1);
}

original_code:
void err_sys(const char *fmt, ...) {
   va_list ap;
   __builtin_va_start(ap,fmt);
   err_doit(1, fmt, ap);
   __builtin_va_end(ap);
   exit(1);
}

canonical_original_code:
void err_sys(char *fmt, ...) {
   __builtin_va_list ap;
   __builtin_va_start(ap,fmt);
   err_doit(1, fmt, ap);
   __builtin_va_end(ap);
   exit(1);
}


decompiled_code:
void __noreturn err_quit(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
err_doit(0, a1, va);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(0, a1, va);
exit(1);
}

original_code:
void err_quit(const char *fmt, ...) {
   va_list ap;
   __builtin_va_start(ap,fmt);
   err_doit(0, fmt, ap);
   __builtin_va_end(ap);
   exit(1);
}

canonical_original_code:
void err_quit(char *fmt, ...) {
   __builtin_va_list ap;
   __builtin_va_start(ap,fmt);
   err_doit(0, fmt, ap);
   __builtin_va_end(ap);
   exit(1);
}


writen

decompiled_code:
size_t __fastcall writen(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
v5 = n;
if ( !n )
return v3;
do
{
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
}
while ( *_errno_location() == 4 );
return -1LL;
}

canonical_decompiled_code:
size_t __fastcall func3(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
v5 = n;
if ( !n )
return v3;
do
{
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
}
while ( *_errno_location() == 4 );
return -1LL;
}

original_code:
ssize_t writen(int fd, const void *vptr, size_t n) {
   size_t nleft;
   ssize_t nwritten;
   const char *ptr;
   ptr = vptr;
   nleft = n;
   while (nleft > 0) {
   if ( (nwritten = write(fd, ptr, nleft)) <= 0) {
    if ((*__errno_location ()) == 4)
     nwritten = 0;
    else
     return(-1);
    }
    nleft -= nwritten;
    ptr += nwritten;
   }
   return(n);
}

canonical_original_code:
long writen(int fd, void *vptr, unsigned long n) {
   unsigned long nleft;
   long nwritten;
   char *ptr;
   ptr = vptr;
   nleft = n;
   while (nleft > 0) {
   if ( (nwritten = write(fd, ptr, nleft)) <= 0) {
    if ((*__errno_location ()) == 4)
     nwritten = 0;
    else
     return(-1);
    }
    nleft -= nwritten;
    ptr += nwritten;
   }
   return(n);
}

variable_types: fd int

variable_types:
vptr
void *

variable_types:
n
unsigned long

variable_types:
nleft
unsigned long

variable_types: nwritten long

variable_types:
ptr
char *

return_type: long


Writen

decompiled_code:
size_t __fastcall Writen(int a1, void *a2, size_t a3)
{
__int64 v3; // rbx
size_t result; // rax

v3 = (int)a3;
result = writen(a1, a2, a3);
if ( result != v3 )
err_sys("writen error");
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(int a1, void *a2, size_t a3)
{
__int64 v3; // rbx
size_t result; // rax

v3 = (int)a3;
result = func3(a1, a2, a3);
if ( result != v3 )
func1("writen error");
return result;
}

original_code:
void Writen(int fd, void *ptr, size_t nbytes) {
 if (writen(fd, ptr, nbytes) != (int)nbytes)
  err_sys("writen error");
}

canonical_original_code:
void Writen(int fd, void *ptr, unsigned long nbytes) {
 if (writen(fd, ptr, nbytes) != (int)nbytes)
  err_sys("writen error");
}

variable_types:
ptr
void *

variable_types:
nbytes
unsigned long


Write

decompiled_code:
ssize_t __fastcall Write(int a1, const void *a2, size_t a3)
{
ssize_t result; // rax

result = write(a1, a2, a3);
if ( result != a3 )
err_sys("write error");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func5(int a1, const void *a2, size_t a3)
{
ssize_t result; // rax

result = write(a1, a2, a3);
if ( result != a3 )
func1("write error");
return result;
}

original_code:
void Write(int fd, void *ptr, size_t nbytes)
{
 if (write(fd, ptr, nbytes) != (ssize_t)nbytes)
  err_sys("write error");
}

canonical_original_code:
void Write(int fd, void *ptr, unsigned long nbytes)
{
 if (write(fd, ptr, nbytes) != (long)nbytes)
  err_sys("write error");
}


readn

decompiled_code:
size_t __fastcall readn(int fd, void *buf, size_t nbytes)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = nbytes;
v5 = nbytes;
if ( nbytes )
{
while ( 1 )
{
while ( 1 )
{
v6 = read(fd, buf, v5);
if ( v6 >= 0 )
break;
if ( *_errno_location() != 4 )
return -1LL;
}
if ( !v6 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
v3 -= v5;
}
return v3;
}

canonical_decompiled_code:
size_t __fastcall func6(int fd, void *buf, size_t nbytes)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = nbytes;
v5 = nbytes;
if ( nbytes )
{
while ( 1 )
{
while ( 1 )
{
v6 = read(fd, buf, v5);
if ( v6 >= 0 )
break;
if ( *_errno_location() != 4 )
return -1LL;
}
if ( !v6 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
v3 -= v5;
}
return v3;
}

original_code:
ssize_t readn(int fd, void *vptr, size_t n) {
 size_t nleft;
 ssize_t nread;
 char *ptr;
 ptr = vptr;
 nleft = n;
 while(nleft > 0) {
  if( (nread = read(fd, ptr, nleft)) < 0) {
   if((*__errno_location ()) == 4)
    nread = 0;
   else
    return(-1);
  }
  else if(nread == 0)
   break;
  nleft -= nread;
  ptr += nread;
 }
 return(n - nleft);
}

canonical_original_code:
long readn(int fd, void *vptr, unsigned long n) {
 unsigned long nleft;
 long nread;
 char *ptr;
 ptr = vptr;
 nleft = n;
 while(nleft > 0) {
  if( (nread = read(fd, ptr, nleft)) < 0) {
   if((*__errno_location ()) == 4)
    nread = 0;
   else
    return(-1);
  }
  else if(nread == 0)
   break;
  nleft -= nread;
  ptr += nread;
 }
 return(n - nleft);
}

variable_types: nread long


Readn

decompiled_code:
signed __int64 __fastcall Readn(int a1, void *a2, size_t a3)
{
signed __int64 result; // rax

result = readn(a1, a2, a3);
if ( result < 0 )
err_sys("readn error");
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func7(int a1, void *a2, size_t a3)
{
signed __int64 result; // rax

result = func6(a1, a2, a3);
if ( result < 0 )
func1("readn error");
return result;
}

original_code:
ssize_t Readn(int fd, void *ptr, size_t nbytes) {
 ssize_t n;
 if ( (n = readn(fd, ptr, nbytes)) < 0)
  err_sys("readn error");
 return(n);
}

canonical_original_code:
long Readn(int fd, void *ptr, unsigned long nbytes) {
 long n;
 if ( (n = readn(fd, ptr, nbytes)) < 0)
  err_sys("readn error");
 return(n);
}

variable_types: n long


Read

decompiled_code:
ssize_t __fastcall Read(int a1, void *a2, size_t a3)
{
ssize_t result; // rax
int *v4; // rax

result = read(a1, a2, a3);
if ( result == -1 )
{
v4 = _errno_location();
err_sys("read error %d\t", (unsigned int)*v4);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func8(int a1, void *a2, size_t a3)
{
ssize_t result; // rax
int *v4; // rax

result = read(a1, a2, a3);
if ( result == -1 )
{
v4 = _errno_location();
func1("read error %d\t", (unsigned int)*v4);
}
return result;
}

original_code:
ssize_t Read(int fd, void *ptr, size_t nbytes) {
 ssize_t n;
 if ( (n = read(fd, ptr, nbytes)) == -1)
  err_sys("read error %d\t", (*__errno_location ()));
 return(n);
}

canonical_original_code:
long Read(int fd, void *ptr, unsigned long nbytes) {
 long n;
 if ( (n = read(fd, ptr, nbytes)) == -1)
  err_sys("read error %d\t", (*__errno_location ()));
 return(n);
}


decompiled_code:
void __fastcall M1(__int64 a1)
{
_BYTE *v1; // rbp
_BYTE *v2; // r12
__int64 i; // rax
void *ptr; // [rsp+18h] [rbp-30h] BYREF
char v5[40]; // [rsp+20h] [rbp-28h] BYREF

if ( !have_N )
_assert_fail("have_N", "srp.c", 0xB7u, "M1");
if ( !have_g )
_assert_fail("have_g", "srp.c", 0xB8u, "M1");
if ( !have_s )
_assert_fail("have_s", "srp.c", 0xB9u, "M1");
if ( !have_A )
_assert_fail("have_A", "srp.c", 0xBAu, "M1");
if ( !have_B )
_assert_fail("have_B", "srp.c", 0xBBu, "M1");
if ( !have_K )
_assert_fail("have_K", "srp.c", 0xBCu, "M1");
v1 = (_BYTE *)sha256_binz(&my_N);
v2 = (_BYTE *)sha256_binz(&my_g);
for ( i = 0LL; i != 32; ++i )
v1[i] ^= v2[i];
_gmpz_init(v5);
_gmpz_import(v5, 32LL, 1LL, 1LL, 0LL, 0LL, v1);
free(v1);
free(v2);
_gmp_asprintf(&ptr, "%Zx%Zx%Zx%Zx%Zx", v5, &my_s, &my_A, &my_B, &my_K);
sha256_s(ptr, a1);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
_BYTE *v1; // rbp
_BYTE *v2; // r12
__int64 i; // rax
void *ptr; // [rsp+18h] [rbp-30h] BYREF
char v5[40]; // [rsp+20h] [rbp-28h] BYREF

if ( !have_N )
_assert_fail("have_N", "srp.c", 0xB7u, "M1");
if ( !have_g )
_assert_fail("have_g", "srp.c", 0xB8u, "M1");
if ( !have_s )
_assert_fail("have_s", "srp.c", 0xB9u, "M1");
if ( !have_A )
_assert_fail("have_A", "srp.c", 0xBAu, "M1");
if ( !have_B )
_assert_fail("have_B", "srp.c", 0xBBu, "M1");
if ( !have_K )
_assert_fail("have_K", "srp.c", 0xBCu, "M1");
v1 = (_BYTE *)sha256_binz(&my_N);
v2 = (_BYTE *)sha256_binz(&my_g);
for ( i = 0LL; i != 32; ++i )
v1[i] ^= v2[i];
_gmpz_init(v5);
_gmpz_import(v5, 32LL, 1LL, 1LL, 0LL, 0LL, v1);
free(v1);
free(v2);
_gmp_asprintf(&ptr, "%Zx%Zx%Zx%Zx%Zx", v5, &my_s, &my_A, &my_B, &my_K);
sha256_s(ptr, a1);
free(ptr);
}

original_code:
static void M1( mpz_t retval )
{
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 183, __extension__ __PRETTY_FUNCTION__));
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 184, __extension__ __PRETTY_FUNCTION__));
  ((have_s) ? (void) (0) : __assert_fail ("have_s", "srp.c", 185, __extension__ __PRETTY_FUNCTION__));
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 186, __extension__ __PRETTY_FUNCTION__));
  ((have_B) ? (void) (0) : __assert_fail ("have_B", "srp.c", 187, __extension__ __PRETTY_FUNCTION__));
  ((have_K) ? (void) (0) : __assert_fail ("have_K", "srp.c", 188, __extension__ __PRETTY_FUNCTION__));
  BYTE* HN = sha256_binz( my_N );
  BYTE* Hg = sha256_binz( my_g );
  for( int i = 0; i < 32; i++ ) {
    HN[i] ^= Hg[i];
  }
  mpz_t HG; __gmpz_init( HG );
  __gmpz_import( HG, 32, 1, 1, 0, 0, HN );
  free( HN); free( Hg);
  char* pALL;
  __gmp_asprintf( &pALL, "%Zx%Zx%Zx%Zx%Zx", HG, my_s, my_A, my_B, my_K );
  sha256_s( (const unsigned char const*)pALL, retval );
  free( pALL );
}

canonical_original_code:
static void M1(struct __mpz_struct retval[1])
{
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 183, __extension__ __PRETTY_FUNCTION__));
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 184, __extension__ __PRETTY_FUNCTION__));
  ((have_s) ? (void) (0) : __assert_fail ("have_s", "srp.c", 185, __extension__ __PRETTY_FUNCTION__));
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 186, __extension__ __PRETTY_FUNCTION__));
  ((have_B) ? (void) (0) : __assert_fail ("have_B", "srp.c", 187, __extension__ __PRETTY_FUNCTION__));
  ((have_K) ? (void) (0) : __assert_fail ("have_K", "srp.c", 188, __extension__ __PRETTY_FUNCTION__));
  unsigned char *HN = sha256_binz( my_N );
  unsigned char *Hg = sha256_binz( my_g );
  for( int i = 0; i < 32; i++ ) {
    HN[i] ^= Hg[i];
  }
  struct __mpz_struct HG[1]; __gmpz_init( HG );
  __gmpz_import( HG, 32, 1, 1, 0, 0, HN );
  free( HN); free( Hg);
  char *pALL;
  __gmp_asprintf( &pALL, "%Zx%Zx%Zx%Zx%Zx", HG, my_s, my_A, my_B, my_K );
  sha256_s( (unsigned char *)pALL, retval );
  free( pALL );
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
HN
unsigned char *

variable_types:
Hg
unsigned char *

variable_types:
pALL
char *


decompiled_code:
void __fastcall M2(__int64 a1)
{
void *ptr; // [rsp+8h] [rbp-20h] BYREF
char v2[24]; // [rsp+10h] [rbp-18h] BYREF

if ( !have_A )
_assert_fail("have_A", "srp.c", 0xD4u, "M2");
if ( !have_K )
_assert_fail("have_K", "srp.c", 0xD5u, "M2");
_gmpz_init(v2);
M1((__int64)v2);
_gmp_asprintf(&ptr, "%Zx%Zx%Zx", &my_A, v2, &my_K);
sha256_s(ptr, a1);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
void *ptr; // [rsp+8h] [rbp-20h] BYREF
char v2[24]; // [rsp+10h] [rbp-18h] BYREF

if ( !have_A )
_assert_fail("have_A", "srp.c", 0xD4u, "M2");
if ( !have_K )
_assert_fail("have_K", "srp.c", 0xD5u, "M2");
_gmpz_init(v2);
func0((__int64)v2);
_gmp_asprintf(&ptr, "%Zx%Zx%Zx", &my_A, v2, &my_K);
sha256_s(ptr, a1);
free(ptr);
}

original_code:
static void M2( mpz_t retval )
{
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 212, __extension__ __PRETTY_FUNCTION__));
  ((have_K) ? (void) (0) : __assert_fail ("have_K", "srp.c", 213, __extension__ __PRETTY_FUNCTION__));
  mpz_t my_M1; __gmpz_init( my_M1 );
  M1( my_M1 );
  char* pALL;
  __gmp_asprintf( &pALL, "%Zx%Zx%Zx", my_A, my_M1, my_K );
  sha256_s( (const unsigned char const*)pALL, retval );
  free( pALL );
}

canonical_original_code:
static void M2(struct __mpz_struct retval[1])
{
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 212, __extension__ __PRETTY_FUNCTION__));
  ((have_K) ? (void) (0) : __assert_fail ("have_K", "srp.c", 213, __extension__ __PRETTY_FUNCTION__));
  struct __mpz_struct my_M1[1]; __gmpz_init( my_M1 );
  M1( my_M1 );
  char *pALL;
  __gmp_asprintf( &pALL, "%Zx%Zx%Zx", my_A, my_M1, my_K );
  sha256_s( (unsigned char *)pALL, retval );
  free( pALL );
}

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }


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

if ( have_g )
_assert_fail("! have_g", "srp.c", 0x1Du, "set_g");
_gmpz_init(&my_g);
result = _gmpz_set(&my_g, a1);
have_g = 1;
return result;
}

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

if ( have_g )
_assert_fail("! have_g", "srp.c", 0x1Du, "set_g");
_gmpz_init(&my_g);
result = _gmpz_set(&my_g, a1);
have_g = 1;
return result;
}

original_code:
void set_g( mpz_t g )
{
  ((! have_g) ? (void) (0) : __assert_fail ("! have_g", "srp.c", 29, __extension__ __PRETTY_FUNCTION__));
  __gmpz_init( my_g );
  __gmpz_set( my_g, g );
  have_g = 1;
}

canonical_original_code:
void set_g(struct __mpz_struct g[1])
{
  ((! have_g) ? (void) (0) : __assert_fail ("! have_g", "srp.c", 29, __extension__ __PRETTY_FUNCTION__));
  __gmpz_init( my_g );
  __gmpz_set( my_g, g );
  have_g = 1;
}


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

if ( have_N )
_assert_fail("! have_N", "srp.c", 0x28u, "set_N");
_gmpz_init(&my_N);
result = _gmpz_set(&my_N, a1);
have_N = 1;
return result;
}

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

if ( have_N )
_assert_fail("! have_N", "srp.c", 0x28u, "set_N");
_gmpz_init(&my_N);
result = _gmpz_set(&my_N, a1);
have_N = 1;
return result;
}

original_code:
void set_N( mpz_t N )
{
  ((! have_N) ? (void) (0) : __assert_fail ("! have_N", "srp.c", 40, __extension__ __PRETTY_FUNCTION__));
  __gmpz_init( my_N );
  __gmpz_set( my_N, N );
  have_N = 1;
}

canonical_original_code:
void set_N(struct __mpz_struct N[1])
{
  ((! have_N) ? (void) (0) : __assert_fail ("! have_N", "srp.c", 40, __extension__ __PRETTY_FUNCTION__));
  __gmpz_init( my_N );
  __gmpz_set( my_N, N );
  have_N = 1;
}


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

if ( !have_g )
_assert_fail("have_g", "srp.c", 0x34u, "calc_k");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x35u, "calc_k");
_gmpz_init(&my_k);
result = sha256_zz(&my_N, &my_g, &my_k);
have_k = 1;
return result;
}

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

if ( !have_g )
_assert_fail("have_g", "srp.c", 0x34u, "calc_k");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x35u, "calc_k");
_gmpz_init(&my_k);
result = sha256_zz(&my_N, &my_g, &my_k);
have_k = 1;
return result;
}

original_code:
void calc_k()
{
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 52, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 53, __extension__ __PRETTY_FUNCTION__));
  __gmpz_init( my_k );
  sha256_zz( my_N, my_g, my_k );
  have_k = 1;
}


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

_gmpz_init(&my_s);
_gmpz_set(&my_s, a1);
have_s = 1;
_gmpz_init(&my_v);
result = _gmpz_set(&my_v, a2);
have_v = 1;
return result;
}

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

_gmpz_init(&my_s);
_gmpz_set(&my_s, a1);
have_s = 1;
_gmpz_init(&my_v);
result = _gmpz_set(&my_v, a2);
have_v = 1;
return result;
}

original_code:
void server_set_v( mpz_t salt, mpz_t v )
{
  __gmpz_init( my_s );
  __gmpz_set( my_s, salt );
  have_s = 1;
  __gmpz_init( my_v );
  __gmpz_set( my_v, v );
  have_v = 1;
}

canonical_original_code:
void server_set_v(struct __mpz_struct salt[1], struct __mpz_struct v[1])
{
  __gmpz_init( my_s );
  __gmpz_set( my_s, salt );
  have_s = 1;
  __gmpz_init( my_v );
  __gmpz_set( my_v, v );
  have_v = 1;
}

variable_types:
v
struct __mpz_struct [1]


decompiled_code:
__int64 calc_u()
{
_gmpz_init(&my_u);
if ( !have_A )
_assert_fail("have_A", "srp.c", 0x6Bu, "calc_u");
if ( !have_B )
_assert_fail("have_B", "srp.c", 0x6Cu, "calc_u");
return sha256_zz(&my_A, &my_B, &my_u);
}

canonical_decompiled_code:
__int64 func7()
{
_gmpz_init(&my_u);
if ( !have_A )
_assert_fail("have_A", "srp.c", 0x6Bu, "calc_u");
if ( !have_B )
_assert_fail("have_B", "srp.c", 0x6Cu, "calc_u");
return sha256_zz(&my_A, &my_B, &my_u);
}

original_code:
void calc_u()
{
  __gmpz_init( my_u );
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 107, __extension__ __PRETTY_FUNCTION__));
  ((have_B) ? (void) (0) : __assert_fail ("have_B", "srp.c", 108, __extension__ __PRETTY_FUNCTION__));
  sha256_zz( my_A, my_B, my_u );
}


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

_gmpz_init(&my_a);
set_random64(&my_a);
have_a = 1;
if ( !have_g )
_assert_fail("have_g", "srp.c", 0x7Du, "client_init");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x7Eu, "client_init");
_gmpz_powm(&my_A, &my_g, &my_a, &my_N);
result = _gmpz_set(a1, &my_A);
have_A = 1;
return result;
}

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

_gmpz_init(&my_a);
set_random64(&my_a);
have_a = 1;
if ( !have_g )
_assert_fail("have_g", "srp.c", 0x7Du, "client_init");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x7Eu, "client_init");
_gmpz_powm(&my_A, &my_g, &my_a, &my_N);
result = _gmpz_set(a1, &my_A);
have_A = 1;
return result;
}

original_code:
void client_init( mpz_t A )
{
  __gmpz_init( my_a );
  set_random64( my_a );
  have_a = 1;
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 125, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 126, __extension__ __PRETTY_FUNCTION__));
  __gmpz_powm( my_A, my_g, my_a, my_N );
  __gmpz_set( A, my_A );
  have_A = 1;
}

canonical_original_code:
void client_init(struct __mpz_struct A[1])
{
  __gmpz_init( my_a );
  set_random64( my_a );
  have_a = 1;
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 125, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 126, __extension__ __PRETTY_FUNCTION__));
  __gmpz_powm( my_A, my_g, my_a, my_N );
  __gmpz_set( A, my_A );
  have_A = 1;
}


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

_gmpz_init(&my_B);
result = _gmpz_set(&my_B, a1);
have_B = 1;
return result;
}

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

_gmpz_init(&my_B);
result = _gmpz_set(&my_B, a1);
have_B = 1;
return result;
}

original_code:
void client_setB( mpz_t B)
{
  __gmpz_init( my_B );
  __gmpz_set( my_B, B );
  have_B = 1;
}

canonical_original_code:
void client_setB(struct __mpz_struct B[1])
{
  __gmpz_init( my_B );
  __gmpz_set( my_B, B );
  have_B = 1;
}


decompiled_code:
__int64 __fastcall client_K(__int64 a1)
{
_BYTE v2[16]; // [rsp+0h] [rbp-68h] BYREF
char v3[16]; // [rsp+10h] [rbp-58h] BYREF
char v4[16]; // [rsp+20h] [rbp-48h] BYREF
char v5[16]; // [rsp+30h] [rbp-38h] BYREF
char v6[16]; // [rsp+40h] [rbp-28h] BYREF
char v7[24]; // [rsp+50h] [rbp-18h] BYREF

_gmpz_init(v2);
calc_u();
calc_k();
if ( !have_a )
_assert_fail("have_a", "srp.c", 0x94u, "client_K");
if ( !have_x )
_assert_fail("have_x", "srp.c", 0x95u, "client_K");
_gmpz_init(v3);
_gmpz_mul(v3, &my_u, &my_x);
_gmpz_init(v4);
_gmpz_add(v4, &my_a, v3);
_gmpz_clear(v3);
if ( !have_x )
_assert_fail("have_x", "srp.c", 0x9Cu, "client_K");
if ( !have_g )
_assert_fail("have_g", "srp.c", 0x9Du, "client_K");
if ( !have_k )
_assert_fail("have_k", "srp.c", 0x9Eu, "client_K");
if ( !have_B )
_assert_fail("have_B", "srp.c", 0x9Fu, "client_K");
_gmpz_init(v5);
_gmpz_powm(v5, &my_g, &my_x, &my_N);
_gmpz_init(v6);
_gmpz_mul(v6, &my_k, v5);
_gmpz_clear(v5);
_gmpz_init(v7);
_gmpz_sub(v7, &my_B, v6);
_gmpz_clear(v6);
_gmpz_powm(v2, v7, v4, &my_N);
_gmpz_clear(v7);
_gmpz_clear(v4);
sha256_z(v2, &my_K);
have_K = 1;
return _gmpz_set(a1, &my_K);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
_BYTE v2[16]; // [rsp+0h] [rbp-68h] BYREF
char v3[16]; // [rsp+10h] [rbp-58h] BYREF
char v4[16]; // [rsp+20h] [rbp-48h] BYREF
char v5[16]; // [rsp+30h] [rbp-38h] BYREF
char v6[16]; // [rsp+40h] [rbp-28h] BYREF
char v7[24]; // [rsp+50h] [rbp-18h] BYREF

_gmpz_init(v2);
func7();
func4();
if ( !have_a )
_assert_fail("have_a", "srp.c", 0x94u, "client_K");
if ( !have_x )
_assert_fail("have_x", "srp.c", 0x95u, "client_K");
_gmpz_init(v3);
_gmpz_mul(v3, &my_u, &my_x);
_gmpz_init(v4);
_gmpz_add(v4, &my_a, v3);
_gmpz_clear(v3);
if ( !have_x )
_assert_fail("have_x", "srp.c", 0x9Cu, "client_K");
if ( !have_g )
_assert_fail("have_g", "srp.c", 0x9Du, "client_K");
if ( !have_k )
_assert_fail("have_k", "srp.c", 0x9Eu, "client_K");
if ( !have_B )
_assert_fail("have_B", "srp.c", 0x9Fu, "client_K");
_gmpz_init(v5);
_gmpz_powm(v5, &my_g, &my_x, &my_N);
_gmpz_init(v6);
_gmpz_mul(v6, &my_k, v5);
_gmpz_clear(v5);
_gmpz_init(v7);
_gmpz_sub(v7, &my_B, v6);
_gmpz_clear(v6);
_gmpz_powm(v2, v7, v4, &my_N);
_gmpz_clear(v7);
_gmpz_clear(v4);
sha256_z(v2, &my_K);
have_K = 1;
return _gmpz_set(a1, &my_K);
}

original_code:
void client_K( mpz_t K )
{
  mpz_t S;
  __gmpz_init( S );
  calc_u();
  calc_k();
  ((have_a) ? (void) (0) : __assert_fail ("have_a", "srp.c", 148, __extension__ __PRETTY_FUNCTION__));
  ((have_x) ? (void) (0) : __assert_fail ("have_x", "srp.c", 149, __extension__ __PRETTY_FUNCTION__));
  mpz_t ux; __gmpz_init( ux );
  __gmpz_mul( ux, my_u, my_x );
  mpz_t pow; __gmpz_init( pow );
  __gmpz_add( pow, my_a, ux );
  __gmpz_clear( ux );
  ((have_x) ? (void) (0) : __assert_fail ("have_x", "srp.c", 156, __extension__ __PRETTY_FUNCTION__));
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 157, __extension__ __PRETTY_FUNCTION__));
  ((have_k) ? (void) (0) : __assert_fail ("have_k", "srp.c", 158, __extension__ __PRETTY_FUNCTION__));
  ((have_B) ? (void) (0) : __assert_fail ("have_B", "srp.c", 159, __extension__ __PRETTY_FUNCTION__));
  mpz_t a; __gmpz_init( a );
  __gmpz_powm( a, my_g, my_x, my_N );
  mpz_t b; __gmpz_init( b );
  __gmpz_mul( b, my_k, a );
  __gmpz_clear( a );
  mpz_t base; __gmpz_init( base );
  __gmpz_sub( base, my_B, b );
  __gmpz_clear( b );
  __gmpz_powm( S, base, pow, my_N );
  __gmpz_clear( base ); __gmpz_clear( pow );
  sha256_z( S, my_K );
  have_K = 1;
  __gmpz_set( K, my_K );
}

canonical_original_code:
void client_K(struct __mpz_struct K[1])
{
  struct __mpz_struct S[1];
  __gmpz_init( S );
  calc_u();
  calc_k();
  ((have_a) ? (void) (0) : __assert_fail ("have_a", "srp.c", 148, __extension__ __PRETTY_FUNCTION__));
  ((have_x) ? (void) (0) : __assert_fail ("have_x", "srp.c", 149, __extension__ __PRETTY_FUNCTION__));
  struct __mpz_struct ux[1]; __gmpz_init( ux );
  __gmpz_mul( ux, my_u, my_x );
  struct __mpz_struct pow[1]; __gmpz_init( pow );
  __gmpz_add( pow, my_a, ux );
  __gmpz_clear( ux );
  ((have_x) ? (void) (0) : __assert_fail ("have_x", "srp.c", 156, __extension__ __PRETTY_FUNCTION__));
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 157, __extension__ __PRETTY_FUNCTION__));
  ((have_k) ? (void) (0) : __assert_fail ("have_k", "srp.c", 158, __extension__ __PRETTY_FUNCTION__));
  ((have_B) ? (void) (0) : __assert_fail ("have_B", "srp.c", 159, __extension__ __PRETTY_FUNCTION__));
  struct __mpz_struct a[1]; __gmpz_init( a );
  __gmpz_powm( a, my_g, my_x, my_N );
  struct __mpz_struct b[1]; __gmpz_init( b );
  __gmpz_mul( b, my_k, a );
  __gmpz_clear( a );
  struct __mpz_struct base[1]; __gmpz_init( base );
  __gmpz_sub( base, my_B, b );
  __gmpz_clear( b );
  __gmpz_powm( S, base, pow, my_N );
  __gmpz_clear( base ); __gmpz_clear( pow );
  sha256_z( S, my_K );
  have_K = 1;
  __gmpz_set( K, my_K );
}


decompiled_code:
// attributes: thunk
void __fastcall client_M1(__int64 a1)
{
M1(a1);
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
func0(a1);
}

original_code:
void client_M1( mpz_t retval )
{
  M1( retval );
}

canonical_original_code:
void client_M1(struct __mpz_struct retval[1])
{
  M1( retval );
}


decompiled_code:
bool __fastcall client_verifyM2(__int64 a1)
{
_BYTE v2[24]; // [rsp+0h] [rbp-18h] BYREF

_gmpz_init(v2);
M2((__int64)v2);
return (unsigned int)_gmpz_cmp(v2, a1) == 0;
}

canonical_decompiled_code:
bool __fastcall func12(__int64 a1)
{
_BYTE v2[24]; // [rsp+0h] [rbp-18h] BYREF

_gmpz_init(v2);
func1((__int64)v2);
return (unsigned int)_gmpz_cmp(v2, a1) == 0;
}

original_code:
_Bool client_verifyM2( mpz_t other_M2 )
{
  mpz_t my_M2; __gmpz_init( my_M2 );
  M2( my_M2 );
  if( __gmpz_cmp( my_M2, other_M2 ) == 0 ) {
    return 1;
  } else {
    return 0;
  }
}

canonical_original_code:
_Bool client_verifyM2(struct __mpz_struct other_M2[1])
{
  struct __mpz_struct my_M2[1]; __gmpz_init( my_M2 );
  M2( my_M2 );
  if( __gmpz_cmp( my_M2, other_M2 ) == 0 ) {
    return 1;
  } else {
    return 0;
  }
}


decompiled_code:
__int64 __fastcall server_init(__int64 a1)
{
_BYTE v2[16]; // [rsp+0h] [rbp-28h] BYREF
char v3[24]; // [rsp+10h] [rbp-18h] BYREF

calc_k();
_gmpz_init(&my_b);
set_random64(&my_b);
have_b = 1;
if ( !have_v )
_assert_fail("have_v", "srp.c", 0x103u, "server_init");
if ( !have_k )
_assert_fail("have_k", "srp.c", 0x104u, "server_init");
if ( !have_g )
_assert_fail("have_g", "srp.c", 0x105u, "server_init");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x106u, "server_init");
_gmpz_init(v2);
_gmpz_powm(v2, &my_g, &my_b, &my_N);
_gmpz_init(v3);
_gmpz_mul(v3, &my_k, &my_v);
_gmpz_add(&my_B, v3, v2);
_gmpz_mod(&my_B, &my_B, &my_N);
have_B = 1;
_gmpz_clear(v3);
_gmpz_clear(v2);
return _gmpz_set(a1, &my_B);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
_BYTE v2[16]; // [rsp+0h] [rbp-28h] BYREF
char v3[24]; // [rsp+10h] [rbp-18h] BYREF

func4();
_gmpz_init(&my_b);
set_random64(&my_b);
have_b = 1;
if ( !have_v )
_assert_fail("have_v", "srp.c", 0x103u, "server_init");
if ( !have_k )
_assert_fail("have_k", "srp.c", 0x104u, "server_init");
if ( !have_g )
_assert_fail("have_g", "srp.c", 0x105u, "server_init");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x106u, "server_init");
_gmpz_init(v2);
_gmpz_powm(v2, &my_g, &my_b, &my_N);
_gmpz_init(v3);
_gmpz_mul(v3, &my_k, &my_v);
_gmpz_add(&my_B, v3, v2);
_gmpz_mod(&my_B, &my_B, &my_N);
have_B = 1;
_gmpz_clear(v3);
_gmpz_clear(v2);
return _gmpz_set(a1, &my_B);
}

original_code:
void server_init( mpz_t B )
{
  calc_k();
  __gmpz_init( my_b );
  set_random64( my_b );
  have_b = 1;
  ((have_v) ? (void) (0) : __assert_fail ("have_v", "srp.c", 259, __extension__ __PRETTY_FUNCTION__));
  ((have_k) ? (void) (0) : __assert_fail ("have_k", "srp.c", 260, __extension__ __PRETTY_FUNCTION__));
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 261, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 262, __extension__ __PRETTY_FUNCTION__));
  mpz_t pow; __gmpz_init( pow );
  __gmpz_powm( pow, my_g, my_b, my_N );
  mpz_t kv; __gmpz_init( kv );
  __gmpz_mul( kv, my_k, my_v );
  __gmpz_add( my_B, kv, pow );
  __gmpz_mod( my_B, my_B, my_N );
  have_B = 1;
  __gmpz_clear( kv ); __gmpz_clear( pow );
  __gmpz_set( B, my_B );
}

canonical_original_code:
void server_init(struct __mpz_struct B[1])
{
  calc_k();
  __gmpz_init( my_b );
  set_random64( my_b );
  have_b = 1;
  ((have_v) ? (void) (0) : __assert_fail ("have_v", "srp.c", 259, __extension__ __PRETTY_FUNCTION__));
  ((have_k) ? (void) (0) : __assert_fail ("have_k", "srp.c", 260, __extension__ __PRETTY_FUNCTION__));
  ((have_g) ? (void) (0) : __assert_fail ("have_g", "srp.c", 261, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 262, __extension__ __PRETTY_FUNCTION__));
  struct __mpz_struct pow[1]; __gmpz_init( pow );
  __gmpz_powm( pow, my_g, my_b, my_N );
  struct __mpz_struct kv[1]; __gmpz_init( kv );
  __gmpz_mul( kv, my_k, my_v );
  __gmpz_add( my_B, kv, pow );
  __gmpz_mod( my_B, my_B, my_N );
  have_B = 1;
  __gmpz_clear( kv ); __gmpz_clear( pow );
  __gmpz_set( B, my_B );
}


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

result = _gmpz_set(&my_A, a1);
have_A = 1;
return result;
}

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

result = _gmpz_set(&my_A, a1);
have_A = 1;
return result;
}

original_code:
void server_setA( mpz_t A )
{
  __gmpz_set( my_A, A );
  have_A = 1;
}

canonical_original_code:
void server_setA(struct __mpz_struct A[1])
{
  __gmpz_set( my_A, A );
  have_A = 1;
}


decompiled_code:
__int64 __fastcall server_K(__int64 a1)
{
__int64 result; // rax
_BYTE v2[16]; // [rsp+0h] [rbp-38h] BYREF
char v3[16]; // [rsp+10h] [rbp-28h] BYREF
char v4[24]; // [rsp+20h] [rbp-18h] BYREF

_gmpz_init(v2);
calc_u();
if ( !have_v )
_assert_fail("have_v", "srp.c", 0x121u, "server_K");
if ( !have_b )
_assert_fail("have_b", "srp.c", 0x122u, "server_K");
if ( !have_A )
_assert_fail("have_A", "srp.c", 0x123u, "server_K");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x124u, "server_K");
_gmpz_init(v3);
_gmpz_powm(v3, &my_v, &my_u, &my_N);
_gmpz_init(v4);
_gmpz_mul(v4, &my_A, v3);
_gmpz_clear(v3);
_gmpz_powm(v2, v4, &my_b, &my_N);
_gmpz_clear(v4);
sha256_z(v2, &my_K);
result = _gmpz_set(a1, &my_K);
have_K = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 result; // rax
_BYTE v2[16]; // [rsp+0h] [rbp-38h] BYREF
char v3[16]; // [rsp+10h] [rbp-28h] BYREF
char v4[24]; // [rsp+20h] [rbp-18h] BYREF

_gmpz_init(v2);
func7();
if ( !have_v )
_assert_fail("have_v", "srp.c", 0x121u, "server_K");
if ( !have_b )
_assert_fail("have_b", "srp.c", 0x122u, "server_K");
if ( !have_A )
_assert_fail("have_A", "srp.c", 0x123u, "server_K");
if ( !have_N )
_assert_fail("have_N", "srp.c", 0x124u, "server_K");
_gmpz_init(v3);
_gmpz_powm(v3, &my_v, &my_u, &my_N);
_gmpz_init(v4);
_gmpz_mul(v4, &my_A, v3);
_gmpz_clear(v3);
_gmpz_powm(v2, v4, &my_b, &my_N);
_gmpz_clear(v4);
sha256_z(v2, &my_K);
result = _gmpz_set(a1, &my_K);
have_K = 1;
return result;
}

original_code:
void server_K( mpz_t K )
{
  mpz_t S;
  __gmpz_init( S );
  calc_u();
  ((have_v) ? (void) (0) : __assert_fail ("have_v", "srp.c", 289, __extension__ __PRETTY_FUNCTION__));
  ((have_b) ? (void) (0) : __assert_fail ("have_b", "srp.c", 290, __extension__ __PRETTY_FUNCTION__));
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 291, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 292, __extension__ __PRETTY_FUNCTION__));
  mpz_t pow; __gmpz_init( pow );
  __gmpz_powm( pow, my_v, my_u, my_N );
  mpz_t Avu; __gmpz_init( Avu );
  __gmpz_mul( Avu, my_A, pow );
  __gmpz_clear(pow);
  __gmpz_powm( S, Avu, my_b, my_N );
  __gmpz_clear( Avu );
  sha256_z( S, my_K );
  __gmpz_set( K, my_K );
  have_K = 1;
}

canonical_original_code:
void server_K(struct __mpz_struct K[1])
{
  struct __mpz_struct S[1];
  __gmpz_init( S );
  calc_u();
  ((have_v) ? (void) (0) : __assert_fail ("have_v", "srp.c", 289, __extension__ __PRETTY_FUNCTION__));
  ((have_b) ? (void) (0) : __assert_fail ("have_b", "srp.c", 290, __extension__ __PRETTY_FUNCTION__));
  ((have_A) ? (void) (0) : __assert_fail ("have_A", "srp.c", 291, __extension__ __PRETTY_FUNCTION__));
  ((have_N) ? (void) (0) : __assert_fail ("have_N", "srp.c", 292, __extension__ __PRETTY_FUNCTION__));
  struct __mpz_struct pow[1]; __gmpz_init( pow );
  __gmpz_powm( pow, my_v, my_u, my_N );
  struct __mpz_struct Avu[1]; __gmpz_init( Avu );
  __gmpz_mul( Avu, my_A, pow );
  __gmpz_clear(pow);
  __gmpz_powm( S, Avu, my_b, my_N );
  __gmpz_clear( Avu );
  sha256_z( S, my_K );
  __gmpz_set( K, my_K );
  have_K = 1;
}


decompiled_code:
// attributes: thunk
void __fastcall server_M2(__int64 a1)
{
M2(a1);
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1)
{
func1(a1);
}

original_code:
void server_M2( mpz_t retval )
{
  M2( retval );
}

canonical_original_code:
void server_M2(struct __mpz_struct retval[1])
{
  M2( retval );
}


decompiled_code:
bool __fastcall server_verifyM1(__int64 a1)
{
_BYTE v2[24]; // [rsp+0h] [rbp-18h] BYREF

_gmpz_init(v2);
M1((__int64)v2);
return (unsigned int)_gmpz_cmp(v2, a1) == 0;
}

canonical_decompiled_code:
bool __fastcall func17(__int64 a1)
{
_BYTE v2[24]; // [rsp+0h] [rbp-18h] BYREF

_gmpz_init(v2);
func0((__int64)v2);
return (unsigned int)_gmpz_cmp(v2, a1) == 0;
}

original_code:
_Bool server_verifyM1( mpz_t other_M1 )
{
  mpz_t my_M1; __gmpz_init( my_M1 );
  M1( my_M1 );
  if( __gmpz_cmp( my_M1, other_M1 ) == 0 ) {
    return 1;
  } else {
    return 0;
  }
}

canonical_original_code:
_Bool server_verifyM1(struct __mpz_struct other_M1[1])
{
  struct __mpz_struct my_M1[1]; __gmpz_init( my_M1 );
  M1( my_M1 );
  if( __gmpz_cmp( my_M1, other_M1 ) == 0 ) {
    return 1;
  } else {
    return 0;
  }
}


decompiled_code:
void *__fastcall my_strdup(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

canonical_decompiled_code:
void *__fastcall func0(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

original_code:
inline char *my_strdup(const char *s) {
 char *p = malloc(strlen(s) + 1);
 if(p)
  strcpy(p, s);
 else
  return ((void *)0);
 return p;
}

canonical_original_code:
inline char *my_strdup(char *s) {
 char *p = malloc(strlen(s) + 1);
 if(p)
  strcpy(p, s);
 else
  return ((void *)0);
 return p;
}

variable_types:
s
char *

variable_types:
p
char *


decompiled_code:
void __fastcall __noreturn print_usage(FILE *stream, int status, const char *a3)
{
fprintf(stream, "Usage: %s OPTIONS\n", a3);
fprintf(
stream,
" -i --input file\tMandatory argument. Input file containing transactions.\n"
" -s --support N\tMinimum support threshold (%%).\n"
" -h --help\t\tPrint this usage information.\n");
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(FILE *stream, int status, const char *a3)
{
fprintf(stream, "Usage: %s OPTIONS\n", a3);
fprintf(
stream,
" -i --input file\tMandatory argument. Input file containing transactions.\n"
" -s --support N\tMinimum support threshold (%%).\n"
" -h --help\t\tPrint this usage information.\n");
exit(status);
}

original_code:
void print_usage(const char* program_name) {
 fprintf(stdout, "Usage: %s OPTIONS\n", program_name);
 fprintf(stdout,
     "	-o	--palvelin N		Palvelimen ip osoite.\n"
     "	-p	--portti P		Palvelimen portti.\n"
     "	-t	--tunnus K		Käyttäjätunnus.\n"
     "	-s	--salasana S		Salasana.\n"
     "	-k	--kysely PPPP-NNNNNN	Palvelimelta kysyttävä puhelinnumero (Prefix ja Numero).\n");
 exit(0);
}

canonical_original_code:
void print_usage(char *program_name) {
 fprintf(stdout, "Usage: %s OPTIONS\n", program_name);
 fprintf(stdout,
     "	-o	--palvelin N		Palvelimen ip osoite.\n"
     "	-p	--portti P		Palvelimen portti.\n"
     "	-t	--tunnus K		Käyttäjätunnus.\n"
     "	-s	--salasana S		Salasana.\n"
     "	-k	--kysely PPPP-NNNNNN	Palvelimelta kysyttävä puhelinnumero (Prefix ja Numero).\n");
 exit(0);
}