original_code:
void util_rbtree_delete(util_rbtree_t *rbtree, util_rbtree_node_t *node)
{
 int isblack;
 util_rbtree_node_t *temp, *subst;
 if((rbtree==((void *)0)) || (node==((void *)0)) || (node==(&((rbtree)->null))))
 {
  return;
 }
 rbtree->size--;
 if(node->left == (&((rbtree)->null)))
 {
  temp = node;
  subst = node->right;
 }
 else if(node->right == (&((rbtree)->null)))
 {
  temp = node;
  subst = node->left;
 }
 else
 {
  temp = util_rbsubtree_min(node->right, (&((rbtree)->null)));
  if(temp->left != (&((rbtree)->null)))
  {
   subst = temp->left;
  }
  else
  {
   subst = temp->right;
  }
 }
 if(temp == rbtree->root)
 {
  rbtree->root = subst;
  ((subst)->color = 1);
  do{ temp->left = ((void *)0); temp->right = ((void *)0); temp->parent = ((void *)0); }while(0);
  return;
 }
 isblack = ((temp)->color == 1);
    if(temp->parent == node)
    {
        subst->parent = temp;
    }
    else
    {
        subst->parent = temp->parent;
    }
 if(temp == temp->parent->left)
 {
  temp->parent->left = subst;
 }
 else
 {
  temp->parent->right = subst;
 }
 if(temp != node)
 {
  temp->parent = node->parent;
  if(node == rbtree->root)
  {
   rbtree->root = temp;
  }
  else
        {
   if(node->parent->left == node)
   {
    node->parent->left = temp;
   }
   else
   {
    node->parent->right = temp;
   }
  }
  temp->right = node->right;
  temp->left = node->left;
  if(temp->left != (&((rbtree)->null)))
  {
   temp->left->parent = temp;
  }
  if(temp->right != (&((rbtree)->null)))
  {
   temp->right->parent = temp;
  }
  temp->color = node->color;
 }
 do{ node->left = ((void *)0); node->right = ((void *)0); node->parent = ((void *)0); }while(0);
 if(isblack)
 {
  rbtree_delete_fixup(rbtree, subst);
 }
}

canonical_original_code:
void util_rbtree_delete(struct util_rbtree_s *rbtree, struct util_rbtree_node_s *node)
{
 int isblack;
 struct util_rbtree_node_s *temp; struct util_rbtree_node_s *subst;
 if((rbtree==((void *)0)) || (node==((void *)0)) || (node==(&((rbtree)->null))))
 {
  return;
 }
 rbtree->size--;
 if(node->left == (&((rbtree)->null)))
 {
  temp = node;
  subst = node->right;
 }
 else if(node->right == (&((rbtree)->null)))
 {
  temp = node;
  subst = node->left;
 }
 else
 {
  temp = util_rbsubtree_min(node->right, (&((rbtree)->null)));
  if(temp->left != (&((rbtree)->null)))
  {
   subst = temp->left;
  }
  else
  {
   subst = temp->right;
  }
 }
 if(temp == rbtree->root)
 {
  rbtree->root = subst;
  ((subst)->color = 1);
  do{ temp->left = ((void *)0); temp->right = ((void *)0); temp->parent = ((void *)0); }while(0);
  return;
 }
 isblack = ((temp)->color == 1);
    if(temp->parent == node)
    {
        subst->parent = temp;
    }
    else
    {
        subst->parent = temp->parent;
    }
 if(temp == temp->parent->left)
 {
  temp->parent->left = subst;
 }
 else
 {
  temp->parent->right = subst;
 }
 if(temp != node)
 {
  temp->parent = node->parent;
  if(node == rbtree->root)
  {
   rbtree->root = temp;
  }
  else
        {
   if(node->parent->left == node)
   {
    node->parent->left = temp;
   }
   else
   {
    node->parent->right = temp;
   }
  }
  temp->right = node->right;
  temp->left = node->left;
  if(temp->left != (&((rbtree)->null)))
  {
   temp->left->parent = temp;
  }
  if(temp->right != (&((rbtree)->null)))
  {
   temp->right->parent = temp;
  }
  temp->color = node->color;
 }
 do{ node->left = ((void *)0); node->right = ((void *)0); node->parent = ((void *)0); }while(0);
 if(isblack)
 {
  rbtree_delete_fixup(rbtree, subst);
 }
}

variable_types: isblack int


repo: umegaya/pfm

original_code:
int util_rbtree_check(const util_rbtree_t *rbtree, int *blackheight, int *maxdepth)
{
    rbtree_check_t check;
    if(rbtree->root == (&((rbtree)->null)))
    {
        return 0;
    }
    if(!((rbtree->root)->color == 1))
    {
        return 1;
    }
    check.fini = check.maxd = check.rbh = 0;
    check.null = (&((rbtree)->null));
    rbtree_check_subtree(rbtree->root, &check, 1, 0);
    if(blackheight)
    {
        *blackheight = check.rbh;
    }
    if(maxdepth)
    {
        *maxdepth = check.maxd;
    }
    return check.fini;
}

canonical_original_code:
int util_rbtree_check(struct util_rbtree_s *rbtree, int *blackheight, int *maxdepth)
{
    struct rbtree_check_s check;
    if(rbtree->root == (&((rbtree)->null)))
    {
        return 0;
    }
    if(!((rbtree->root)->color == 1))
    {
        return 1;
    }
    check.fini = check.maxd = check.rbh = 0;
    check.null = (&((rbtree)->null));
    rbtree_check_subtree(rbtree->root, &check, 1, 0);
    if(blackheight)
    {
        *blackheight = check.rbh;
    }
    if(maxdepth)
    {
        *maxdepth = check.maxd;
    }
    return check.fini;
}

variable_types: struct util_rbtree_s { struct util_rbtree_node_s { long key; struct util_rbtree_node_s *parent; struct util_rbtree_node_s *right; struct util_rbtree_node_s *left; int color; void *data; } *root; struct util_rbtree_node_s null; unsigned int size; } *

variable_types:
blackheight
int *

variable_types:
maxdepth
int *

variable_types: struct rbtree_check_s { short rbh; short maxd; int fini; struct util_rbtree_node_s { long key; struct util_rbtree_node_s *parent; struct util_rbtree_node_s *right; struct util_rbtree_node_s *left; int color; void *data; } *null; }

return_type: int

user_defined_types: struct rbtree_check_s { short rbh; short maxd; int fini; struct util_rbtree_node_s *null; }

user_defined_types: struct util_rbtree_s { struct util_rbtree_node_s *root; struct util_rbtree_node_s null; unsigned int size; }


decompiled_code:
void __fastcall util_rbtree_mid_travel(__int64 *a1, __int64 (__fastcall *a2)(__int64, __int64), __int64 a3)
{
if ( a1 )
{
if ( (__int64 *)*a1 != a1 + 1 )
rbtree_mid_travel(*a1, (__int64)(a1 + 1), a2, a3);
}
}

original_code:
void util_rbtree_mid_travel(util_rbtree_t *rbtree,
                            void(*opera)(util_rbtree_node_t *, void *), void *data)
{
    if((rbtree!=((void *)0)) && !((rbtree)->root == &(rbtree)->null))
    {
        rbtree_mid_travel(rbtree->root, (&((rbtree)->null)), opera, data);
    }
}

canonical_original_code:
void util_rbtree_mid_travel(struct util_rbtree_s *rbtree, void (*opera)(struct util_rbtree_node_s *, void *), void *data)
{
    if((rbtree!=((void *)0)) && !((rbtree)->root == &(rbtree)->null))
    {
        rbtree_mid_travel(rbtree->root, (&((rbtree)->null)), opera, data);
    }
}

variable_types: void (*)(struct util_rbtree_node_s *, void *)

variable_types:
data
void *

return_type: void

user_defined_types: struct util_rbtree_node_s { long key; struct util_rbtree_node_s *parent; struct util_rbtree_node_s *right; struct util_rbtree_node_s *left; int color; void *data; }


decompiled_code:
void __fastcall nbr_conhash_fin(void *ptr)
{
__int64 i; // rbp

if ( ptr )
{
for ( i = *(_QWORD *)ptr; *(void **)ptr != (char *)ptr + 8; i = *(_QWORD *)ptr )
{
util_rbtree_delete(ptr, i);
_conhash_del_rbnode(ptr, i);
}
if ( *((_QWORD *)ptr + 9) )
{
nbr_array_destroy();
*((_QWORD *)ptr + 9) = 0LL;
}
if ( *((_QWORD *)ptr + 10) )
{
nbr_array_destroy();
*((_QWORD *)ptr + 10) = 0LL;
}
if ( *((_QWORD *)ptr + 12) )
nbr_rwlock_destroy();
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
__int64 i; // rbp

if ( ptr )
{
for ( i = *(_QWORD *)ptr; *(void **)ptr != (char *)ptr + 8; i = *(_QWORD *)ptr )
{
util_rbtree_delete(ptr, i);
_conhash_del_rbnode(ptr, i);
}
if ( *((_QWORD *)ptr + 9) )
{
nbr_array_destroy();
*((_QWORD *)ptr + 9) = 0LL;
}
if ( *((_QWORD *)ptr + 10) )
{
nbr_array_destroy();
*((_QWORD *)ptr + 10) = 0LL;
}
if ( *((_QWORD *)ptr + 12) )
nbr_rwlock_destroy();
free(ptr);
}
}

original_code:
extern
void nbr_conhash_fin(CONHASH ch)
{
 struct conhash_s *conhash = (struct conhash_s *)ch;
 if(conhash != ((void *)0))
 {
        while(!((&(conhash->vnode_tree))->root == &(&(conhash->vnode_tree))->null))
        {
            util_rbtree_node_t *rbnode = conhash->vnode_tree.root;
            util_rbtree_delete(&(conhash->vnode_tree), rbnode);
            __conhash_del_rbnode(conhash, rbnode);
        }
  if (conhash->vnode_a) {
   nbr_array_destroy(conhash->vnode_a);
   conhash->vnode_a = ((void *)0);
  }
  if (conhash->rbnode_a) {
   nbr_array_destroy(conhash->rbnode_a);
   conhash->rbnode_a = ((void *)0);
  }
  if (conhash->lock) {
   nbr_rwlock_destroy(conhash->lock);
   conhash->lock = ((void *)0);
  }
  free(conhash);
 }
}

canonical_original_code:
extern void nbr_conhash_fin(void *ch)
{
 struct conhash_s *conhash = (struct conhash_s *)ch;
 if(conhash != ((void *)0))
 {
        while(!((&(conhash->vnode_tree))->root == &(&(conhash->vnode_tree))->null))
        {
            struct util_rbtree_node_s *rbnode = conhash->vnode_tree.root;
            util_rbtree_delete(&(conhash->vnode_tree), rbnode);
            __conhash_del_rbnode(conhash, rbnode);
        }
  if (conhash->vnode_a) {
   nbr_array_destroy(conhash->vnode_a);
   conhash->vnode_a = ((void *)0);
  }
  if (conhash->rbnode_a) {
   nbr_array_destroy(conhash->rbnode_a);
   conhash->rbnode_a = ((void *)0);
  }
  if (conhash->lock) {
   nbr_rwlock_destroy(conhash->lock);
   conhash->lock = ((void *)0);
  }
  free(conhash);
 }
}

variable_types:
ch
void *

variable_types: struct conhash_s { struct util_rbtree_s { struct util_rbtree_node_s { long key; struct util_rbtree_node_s *parent; struct util_rbtree_node_s *right; struct util_rbtree_node_s *left; int color; void *data; } *root; struct util_rbtree_node_s null; unsigned int size; } vnode_tree; unsigned int ivnodes; void *vnode_a; void *lock; long (*cb_hashfunc)(char *, unsigned long); } *

user_defined_types: struct conhash_s { struct util_rbtree_s vnode_tree; unsigned int ivnodes; void *vnode_a; void *lock; long (*cb_hashfunc)(char *, unsigned long); }


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

result = strncpy((char *)a1, a2, 0x1BuLL);
*(_WORD *)(a1 + 28) = a3;
*(_WORD *)(a1 + 30) = 1;
return result;
}

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

result = strncpy((char *)a1, a2, 0x1BuLL);
*(_WORD *)(a1 + 28) = a3;
*(_WORD *)(a1 + 30) = 1;
return result;
}

original_code:
extern
void nbr_conhash_set_node(struct node_s *node, const char *iden, u_int replica)
{
    strncpy(node->iden, iden, sizeof(node->iden)-1);
    node->replicas = replica;
    node->flag = 0x01;
}

canonical_original_code:
extern void nbr_conhash_set_node(struct node_s *node, char *iden, unsigned int replica)
{
    strncpy(node->iden, iden, sizeof(node->iden)-1);
    node->replicas = replica;
    node->flag = 0x01;
}

variable_types: struct node_s { char iden[28]; unsigned short replicas; unsigned short flag; } *

variable_types:
iden
char *

variable_types:
replica
unsigned int


decompiled_code:
__int64 __fastcall nbr_conhash_node_registered(__int64 a1)
{
return *(_WORD *)(a1 + 30) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_WORD *)(a1 + 30) & 1;
}

original_code:
extern int
nbr_conhash_node_registered(const CHNODE *node)
{
 return (node->flag&(0x01 | 0x02)
   == (0x01 | 0x02));
}

canonical_original_code:
extern int nbr_conhash_node_registered(struct node_s *node)
{
 return (node->flag&(0x01 | 0x02)
   == (0x01 | 0x02));
}

user_defined_types: struct node_s { char iden[28]; unsigned short replicas; unsigned short flag; }


decompiled_code:
__int64 __fastcall nbr_conhash_node_fault(__int64 a1)
{
return *(_WORD *)(a1 + 30) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_WORD *)(a1 + 30) & 1;
}

original_code:
extern int
nbr_conhash_node_fault(const CHNODE *node)
{
 return (node->flag&(0x01 | 0x04)
   == (0x01 | 0x04));
}

canonical_original_code:
extern int nbr_conhash_node_fault(struct node_s *node)
{
 return (node->flag&(0x01 | 0x04)
   == (0x01 | 0x04));
}


decompiled_code:
__int64 __fastcall nbr_conhash_node_set_fault(__int64 a1)
{
if ( !(unsigned int)nbr_conhash_node_registered(a1) )
return 4294967290LL;
*(_WORD *)(a1 + 30) |= 4u;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
if ( !(unsigned int)func2(a1) )
return 4294967290LL;
*(_WORD *)(a1 + 30) |= 4u;
return 0LL;
}

original_code:
extern int
nbr_conhash_node_set_fault(CHNODE *node)
{
 if (nbr_conhash_node_registered(node)) {
  node->flag |= 0x04;
  return NBR_OK;
 }
 return NBR_EINVAL;
}

canonical_original_code:
extern int nbr_conhash_node_set_fault(struct node_s *node)
{
 if (nbr_conhash_node_registered(node)) {
  node->flag |= 0x04;
  return NBR_OK;
 }
 return NBR_EINVAL;
}


decompiled_code:
__int64 __fastcall nbr_conhash_add_node(__int64 a1, __int64 a2)
{
if ( !a1 )
return 4294967290LL;
if ( !a2 )
return 4294967290LL;
if ( (*(_WORD *)(a2 + 30) & 3) != 1 )
return 4294967291LL;
*(_WORD *)(a2 + 30) |= 2u;
nbr_rwlock_wrlock(*(_QWORD *)(a1 + 96));
_conhash_add_replicas(a1, a2);
nbr_rwlock_unlock(*(_QWORD *)(a1 + 96));
return 0LL;
}

original_code:
extern
int nbr_conhash_add_node(CONHASH ch, struct node_s *node)
{
 ;
 struct conhash_s *conhash = (struct conhash_s *)ch;
    if((conhash==((void *)0)) || (node==((void *)0)))
    {
        return NBR_EINVAL;
    }
    if(!(node->flag&0x01) || (node->flag&0x02))
    {
        return NBR_EALREADY;
    }
    node->flag |= 0x02;
    nbr_rwlock_wrlock(conhash->lock);
    __conhash_add_replicas(conhash, node);
    nbr_rwlock_unlock(conhash->lock);
    return NBR_OK;
}

canonical_original_code:
extern int nbr_conhash_add_node(void *ch, struct node_s *node)
{
 ;
 struct conhash_s *conhash = (struct conhash_s *)ch;
    if((conhash==((void *)0)) || (node==((void *)0)))
    {
        return NBR_EINVAL;
    }
    if(!(node->flag&0x01) || (node->flag&0x02))
    {
        return NBR_EALREADY;
    }
    node->flag |= 0x02;
    nbr_rwlock_wrlock(conhash->lock);
    __conhash_add_replicas(conhash, node);
    nbr_rwlock_unlock(conhash->lock);
    return NBR_OK;
}


decompiled_code:
__int64 __fastcall nbr_conhash_del_node(__int64 a1, __int64 a2)
{
if ( !a1 )
return 4294967290LL;
if ( !a2 )
return 4294967290LL;
if ( (*(_WORD *)(a2 + 30) & 3) != 3 )
return 4294967291LL;
*(_WORD *)(a2 + 30) &= 0xFFFDu;
nbr_rwlock_wrlock(*(_QWORD *)(a1 + 96));
_conhash_del_replicas(a1, a2);
nbr_rwlock_unlock(*(_QWORD *)(a1 + 96));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
if ( !a1 )
return 4294967290LL;
if ( !a2 )
return 4294967290LL;
if ( (*(_WORD *)(a2 + 30) & 3) != 3 )
return 4294967291LL;
*(_WORD *)(a2 + 30) &= 0xFFFDu;
nbr_rwlock_wrlock(*(_QWORD *)(a1 + 96));
_conhash_del_replicas(a1, a2);
nbr_rwlock_unlock(*(_QWORD *)(a1 + 96));
return 0LL;
}

original_code:
extern
int nbr_conhash_del_node(CONHASH ch, struct node_s *node)
{
 ;
 struct conhash_s *conhash = (struct conhash_s *)ch;
   if((conhash==((void *)0)) || (node==((void *)0)))
    {
        return NBR_EINVAL;
    }
    if(!(node->flag&0x01) || !(node->flag&0x02))
    {
        return NBR_EALREADY;
    }
    node->flag &= (~0x02);
    nbr_rwlock_wrlock(conhash->lock);
    __conhash_del_replicas(conhash, node);
    nbr_rwlock_unlock(conhash->lock);
    return NBR_OK;
}

canonical_original_code:
extern int nbr_conhash_del_node(void *ch, struct node_s *node)
{
 ;
 struct conhash_s *conhash = (struct conhash_s *)ch;
   if((conhash==((void *)0)) || (node==((void *)0)))
    {
        return NBR_EINVAL;
    }
    if(!(node->flag&0x01) || !(node->flag&0x02))
    {
        return NBR_EALREADY;
    }
    node->flag &= (~0x02);
    nbr_rwlock_wrlock(conhash->lock);
    __conhash_del_replicas(conhash, node);
    nbr_rwlock_unlock(conhash->lock);
    return NBR_OK;
}


decompiled_code:
__int64 __fastcall nbr_conhash_lookup(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbp
__int64 v4; // rbp

if ( !a1 )
return 0LL;
if ( !*(_DWORD *)(a1 + 64) || !a2 )
return 0LL;
v3 = (*(__int64 (__fastcall **)(__int64, __int64))(a1 + 104))(a2, a3);
nbr_rwlock_rdlock(*(_QWORD *)(a1 + 96));
v4 = util_rbtree_lookup(a1, v3);
nbr_rwlock_unlock(*(_QWORD *)(a1 + 96));
if ( v4 )
v4 = *(_QWORD *)(*(_QWORD *)(v4 + 40) + 8LL);
return v4;
}

original_code:
extern
CHNODE *nbr_conhash_lookup(CONHASH ch, const char *object, size_t sz)
{
 ;
 struct conhash_s *conhash = (struct conhash_s *)ch;
    long hash;
    const util_rbtree_node_t *rbnode;
    if((conhash==((void *)0)) || (conhash->ivnodes==0) || (object==((void *)0)))
    {
        return ((void *)0);
    }
    hash = conhash->cb_hashfunc(object, sz);
    ;
    nbr_rwlock_rdlock(conhash->lock);
    rbnode = util_rbtree_lookup(&(conhash->vnode_tree), hash);
    nbr_rwlock_unlock(conhash->lock);
    if(rbnode != ((void *)0))
    {
        struct virtual_node_s *vnode = rbnode->data;
        return (CHNODE *)vnode->node;
    }
    return ((void *)0);
}

canonical_original_code:
extern struct node_s *nbr_conhash_lookup(void *ch, char *object, unsigned long sz)
{
 ;
 struct conhash_s *conhash = (struct conhash_s *)ch;
    long hash;
    struct util_rbtree_node_s *rbnode;
    if((conhash==((void *)0)) || (conhash->ivnodes==0) || (object==((void *)0)))
    {
        return ((void *)0);
    }
    hash = conhash->cb_hashfunc(object, sz);
    ;
    nbr_rwlock_rdlock(conhash->lock);
    rbnode = util_rbtree_lookup(&(conhash->vnode_tree), hash);
    nbr_rwlock_unlock(conhash->lock);
    if(rbnode != ((void *)0))
    {
        struct virtual_node_s *vnode = rbnode->data;
        return (struct node_s *)vnode->node;
    }
    return ((void *)0);
}

variable_types:
object
char *

variable_types:
sz
unsigned long

variable_types: hash long

variable_types: struct util_rbtree_node_s { long key; struct util_rbtree_node_s *parent; struct util_rbtree_node_s *right; struct util_rbtree_node_s *left; int color; void *data; } *

variable_types: struct virtual_node_s { long hash; struct node_s { char iden[28]; unsigned short replicas; unsigned short flag; } *node; } *

user_defined_types: struct virtual_node_s { long hash; struct node_s *node; }


decompiled_code:
__int64 __fastcall conhash_md5_digest(__int64 a1, unsigned int a2, __int64 a3)
{
_BYTE v5[120]; // [rsp+0h] [rbp-78h] BYREF

md5_init(v5);
md5_append(v5, a1, a2);
return md5_finish(v5, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, __int64 a3)
{
_BYTE v5[120]; // [rsp+0h] [rbp-78h] BYREF

md5_init(v5);
md5_append(v5, a1, a2);
return md5_finish(v5, a3);
}

original_code:
void conhash_md5_digest(const u_char *instr, size_t sz, u_char digest[16])
{
    md5_state_t md5state;
    md5_init(&md5state);
    md5_append(&md5state, instr, sz);
    md5_finish(&md5state, digest);
}

canonical_original_code:
void conhash_md5_digest(unsigned char *instr, unsigned long sz, unsigned char digest[16])
{
    struct md5_state_s md5state;
    md5_init(&md5state);
    md5_append(&md5state, instr, sz);
    md5_finish(&md5state, digest);
}

variable_types:
instr
unsigned char *

variable_types:
digest
unsigned char [16]

variable_types: struct md5_state_s { unsigned int count[2]; unsigned int abcd[4]; unsigned char buf[64]; }


decompiled_code:
char __fastcall nbr_conhash_get_vnodes(__int64 a1, __int64 a2, int a3)
{
char result; // al
__int64 v4[5]; // [rsp+0h] [rbp-28h] BYREF

result = a3 <= 0;
if ( a3 > 0 && a2 != 0 )
{
if ( a1 )
{
v4[0] = a2;
v4[1] = a3;
v4[2] = 0LL;
result = util_rbtree_mid_travel(a1, _get_vnodes, v4);
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func2(__int64 a1, __int64 a2, int a3)
{
char result; // al
__int64 v4[5]; // [rsp+0h] [rbp-28h] BYREF

result = a3 <= 0;
if ( a3 > 0 && a2 != 0 )
{
if ( a1 )
{
v4[0] = a2;
v4[1] = a3;
v4[2] = 0LL;
result = util_rbtree_mid_travel(a1, _get_vnodes, v4);
}
}
return result;
}

original_code:
void nbr_conhash_get_vnodes(CONHASH ch, long *values, int size)
{
    struct __get_vnodes_s vnodes;
 struct conhash_s *conhash = (struct conhash_s *)ch;
    if((conhash==((void *)0)) || (values==((void *)0)) || (size<=0))
    {
        return;
    }
    vnodes.values = values;
    vnodes.size = size;
    vnodes.cur = 0;
    util_rbtree_mid_travel((util_rbtree_t *)&(conhash->vnode_tree), __get_vnodes, &vnodes);
}

canonical_original_code:
void nbr_conhash_get_vnodes(void *ch, long *values, int size)
{
    struct __get_vnodes_s vnodes;
 struct conhash_s *conhash = (struct conhash_s *)ch;
    if((conhash==((void *)0)) || (values==((void *)0)) || (size<=0))
    {
        return;
    }
    vnodes.values = values;
    vnodes.size = size;
    vnodes.cur = 0;
    util_rbtree_mid_travel((struct util_rbtree_s *)&(conhash->vnode_tree), __get_vnodes, &vnodes);
}

variable_types:
values
long *

variable_types: size int

variable_types: struct __get_vnodes_s { long *values; long size; }


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

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

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

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

original_code:
U32 nbr_conhash_get_vnodes_num(CONHASH ch)
{
 struct conhash_s *conhash = (struct conhash_s *)ch;
    if(conhash == ((void *)0))
    {
        return 0;
    }
    return conhash->ivnodes;
}

canonical_original_code:
unsigned int nbr_conhash_get_vnodes_num(void *ch)
{
 struct conhash_s *conhash = (struct conhash_s *)ch;
    if(conhash == ((void *)0))
    {
        return 0;
    }
    return conhash->ivnodes;
}

return_type: unsigned int


original_code:
void
md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
{
    const md5_byte_t *p = data;
    int left = nbytes;
    int offset = (pms->count[0] >> 3) & 63;
    md5_word_t nbits = (md5_word_t)(nbytes << 3);
    if (nbytes <= 0)
 return;
    pms->count[1] += nbytes >> 29;
    pms->count[0] += nbits;
    if (pms->count[0] < nbits)
 pms->count[1]++;
    if (offset) {
 int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
 memcpy(pms->buf + offset, p, copy);
 if (offset + copy < 64)
     return;
 p += copy;
 left -= copy;
 md5_process(pms, pms->buf);
    }
    for (; left >= 64; p += 64, left -= 64)
 md5_process(pms, p);
    if (left)
 memcpy(pms->buf, p, left);
}

canonical_original_code:
void md5_append(struct md5_state_s *pms, unsigned char *data, int nbytes)
{
    unsigned char *p = data;
    int left = nbytes;
    int offset = (pms->count[0] >> 3) & 63;
    unsigned int nbits = (md5_word_t)(nbytes << 3);
    if (nbytes <= 0)
 return;
    pms->count[1] += nbytes >> 29;
    pms->count[0] += nbits;
    if (pms->count[0] < nbits)
 pms->count[1]++;
    if (offset) {
 int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
 memcpy(pms->buf + offset, p, copy);
 if (offset + copy < 64)
     return;
 p += copy;
 left -= copy;
 md5_process(pms, pms->buf);
    }
    for (; left >= 64; p += 64, left -= 64)
 md5_process(pms, p);
    if (left)
 memcpy(pms->buf, p, left);
}

variable_types: struct md5_state_s { unsigned int count[2]; unsigned int abcd[4]; unsigned char buf[64]; } *

variable_types:
data
unsigned char *

variable_types: nbytes int

variable_types:
p
unsigned char *

variable_types: left int

variable_types: offset int

variable_types:
nbits
unsigned int

variable_types: copy int


tstp

decompiled_code:
void tstp()
{
int v0; // ebx
int v1; // eax
int v2; // edx

v0 = lines();
v1 = cols();
mvcur(0, v1 - 1, v0 - 1, 0);
endwin();
fflush(stdout);
kill(0, 20);
signal(20, tstp);
cbreak();
noecho();
clearok(curscr, 1);
v2 = -1;
if ( cw )
v2 = cw->_maxy + 1;
wtouchln(cw, 0, v2, 1);
wrefresh(cw);
raw();
noraw();
}

canonical_decompiled_code:
void func0()
{
int v0; // ebx
int v1; // eax
int v2; // edx

v0 = lines();
v1 = cols();
mvcur(0, v1 - 1, v0 - 1, 0);
endwin();
fflush(stdout);
kill(0, 20);
signal(20, tstp);
cbreak();
noecho();
clearok(curscr, 1);
v2 = -1;
if ( cw )
v2 = cw->_maxy + 1;
wtouchln(cw, 0, v2, 1);
wrefresh(cw);
raw();
noraw();
}

original_code:
void tstp()
{
    mvcur(0, cols() - 1, lines() - 1, 0);
    endwin();
    fflush(stdout);
    kill(0, 20);
    signal(20, tstp);
    cbreak();
    noecho();
    clearok(curscr, 1);
    wtouchln((cw), 0, ((0 != (const void *)((cw))) ? ((cw)->_maxy + 1) : (-1)), 1);
    wrefresh(cw);
    raw();
    noraw();
}

canonical_original_code:
void tstp()
{
    mvcur(0, cols() - 1, lines() - 1, 0);
    endwin();
    fflush(stdout);
    kill(0, 20);
    signal(20, tstp);
    cbreak();
    noecho();
    clearok(curscr, 1);
    wtouchln((cw), 0, ((0 != (void *)((cw))) ? ((cw)->_maxy + 1) : (-1)), 1);
    wrefresh(cw);
    raw();
    noraw();
}


decompiled_code:
__int64 run_all_tests()
{
int v0; // ebp
__int64 v1; // rbx
const char *v2; // rsi

v0 = 0;
if ( test_list )
{
v1 = *(_QWORD *)(test_list + 16);
if ( v1 )
{
do
{
current_test_result = 1;
(*(void (**)(void))(v1 + 8))();
v2 = "FAIL";
if ( current_test_result )
v2 = " OK ";
printf("[%s] %s\n", v2, *(const char **)v1);
v0 += current_test_result == 0;
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
if ( v0 > 0 )
printf("%d tests failed!", (unsigned int)v0);
}
else
{
v0 = 0;
}
}
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebp
__int64 v1; // rbx
const char *v2; // rsi

v0 = 0;
if ( test_list )
{
v1 = *(_QWORD *)(test_list + 16);
if ( v1 )
{
do
{
current_test_result = 1;
(*(void (**)(void))(v1 + 8))();
v2 = "FAIL";
if ( current_test_result )
v2 = " OK ";
printf("[%s] %s\n", v2, *(const char **)v1);
v0 += current_test_result == 0;
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
if ( v0 > 0 )
printf("%d tests failed!", (unsigned int)v0);
}
else
{
v0 = 0;
}
}
return (unsigned int)v0;
}

original_code:
int run_all_tests()
{
 struct TestNode * current_test = test_list == ((void *)0) ? test_list : test_list->start;
 int failed = 0;
 while(current_test != ((void *)0)) {
  current_test_result = 1;
  current_test->test_case();
  printf("[%s] %s\n", current_test_result ? " OK " : "FAIL", current_test->test_name);
  if(!current_test_result) {
   ++failed;
  }
  current_test = current_test->next_test;
 }
 if(failed > 0) {
  printf("%d tests failed!", failed);
 }
 return failed;
}

canonical_original_code:
int run_all_tests()
{
 struct TestNode *current_test = test_list == ((void *)0) ? test_list : test_list->start;
 int failed = 0;
 while(current_test != ((void *)0)) {
  current_test_result = 1;
  current_test->test_case();
  printf("[%s] %s\n", current_test_result ? " OK " : "FAIL", current_test->test_name);
  if(!current_test_result) {
   ++failed;
  }
  current_test = current_test->next_test;
 }
 if(failed > 0) {
  printf("%d tests failed!", failed);
 }
 return failed;
}

variable_types: struct TestNode { char *test_name; void (*test_case)(); struct TestNode *start; struct TestNode *next_test; } *

variable_types: failed int


endit

decompiled_code:
void __noreturn endit()
{
fatal("Ok, if you want to exit that badly, I'll have to allow it\n");
}

canonical_decompiled_code:
void __noreturn func3()
{
func2("Ok, if you want to exit that badly, I'll have to allow it\n");
}

original_code:
void endit()
{
    fatal("Ok, if you want to exit that badly, I'll have to allow it\n");
}


addmsg

decompiled_code:
size_t addmsg(char *format, ...)
{
size_t result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vsprintf(&msgbuf[newpos], format, arg);
result = strlen(msgbuf);
newpos = result;
return result;
}

canonical_decompiled_code:
size_t func2(char *format, ...)
{
size_t result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vsprintf(&msgbuf[newpos], format, arg);
result = strlen(msgbuf);
newpos = result;
return result;
}

original_code:
void addmsg(const char * fmt, ...)
{
 va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(&msgbuf[newpos], fmt, args);
 __builtin_va_end(args);
    newpos = strlen(msgbuf);
}

canonical_original_code:
void addmsg(char *fmt, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(&msgbuf[newpos], fmt, args);
 __builtin_va_end(args);
    newpos = strlen(msgbuf);
}

variable_types:
fmt
char *


msg

decompiled_code:
int msg(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( *format )
{
va_start(arg, format);
vsprintf(&msgbuf[newpos], format, arg);
newpos = strlen(msgbuf);
result = endmsg();
}
else
{
wmove(cw, 0, 0);
result = wclrtoeol(cw);
mpos = 0;
}
return result;
}

canonical_decompiled_code:
int func8(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( *format )
{
va_start(arg, format);
vsprintf(&msgbuf[newpos], format, arg);
newpos = strlen(msgbuf);
result = func7();
}
else
{
wmove(cw, 0, 0);
result = wclrtoeol(cw);
mpos = 0;
}
return result;
}

original_code:
void msg(const char * fmt, ...)
{
    if (*fmt == '\0')
    {
 wmove(cw, 0, 0);
 wclrtoeol(cw);
 mpos = 0;
 return;
    }
 va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(&msgbuf[newpos], fmt, args);
 __builtin_va_end(args);
    newpos = strlen(msgbuf);
    endmsg();
}

canonical_original_code:
void msg(char *fmt, ...)
{
    if (*fmt == '\0')
    {
 wmove(cw, 0, 0);
 wclrtoeol(cw);
 mpos = 0;
 return;
    }
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(&msgbuf[newpos], fmt, args);
 __builtin_va_end(args);
    newpos = strlen(msgbuf);
    endmsg();
}


quit

decompiled_code:
void quit()
{
int v0; // eax

if ( signal(2, quit) )
mpos = 0;
msg("Really quit?");
wrefresh(cw);
if ( (unsigned int)readchar() == 121 )
{
wclear(stdscr);
v0 = lines();
wmove(stdscr, v0 - 1, 0);
wrefresh(stdscr);
score((unsigned int)purse, 1LL);
exit(0);
}
signal(2, quit);
wmove(cw, 0, 0);
wclrtoeol(cw);
status();
wrefresh(cw);
mpos = 0;
count = 0;
}

canonical_decompiled_code:
void func0()
{
int v0; // eax

if ( signal(2, quit) )
mpos = 0;
msg("Really quit?");
wrefresh(cw);
if ( (unsigned int)readchar() == 121 )
{
wclear(stdscr);
v0 = lines();
wmove(stdscr, v0 - 1, 0);
wrefresh(stdscr);
score((unsigned int)purse, 1LL);
exit(0);
}
signal(2, quit);
wmove(cw, 0, 0);
wclrtoeol(cw);
status();
wrefresh(cw);
mpos = 0;
count = 0;
}

original_code:
void quit()
{
    if (signal(2, quit) != quit)
 mpos = 0;
    msg("Really quit?");
    wrefresh(cw);
    if (readchar() == 'y')
    {
 wclear(stdscr);
 wmove(stdscr,(lines()-1),(0));
 wrefresh(stdscr);
 score(purse, 1);
 exit(0);
    }
    else
    {
 signal(2, quit);
 wmove(cw, 0, 0);
 wclrtoeol(cw);
 status();
 wrefresh(cw);
 mpos = 0;
 count = 0;
    }
}


decompiled_code:
char *d_slot()
{
char *result; // rax

result = (char *)&d_list;
while ( *(_DWORD *)result )
{
result += 24;
if ( result == (char *)&d_list + 480 )
{
result = 0LL;
if ( wizard )
{
msg("Ran out of fuse slots");
result = 0LL;
}
return result;
}
}
return result;
}

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

result = (char *)&d_list;
while ( *(_DWORD *)result )
{
result += 24;
if ( result == (char *)&d_list + 480 )
{
result = 0LL;
if ( wizard )
{
msg("Ran out of fuse slots");
result = 0LL;
}
return result;
}
}
return result;
}

original_code:
struct delayed_action *
d_slot()
{
    register int i;
    register struct delayed_action *dev;
    for (i = 0, dev = d_list; i < 20; i++, dev++)
 if (dev->d_type == 0)
     return dev;
    if (wizard) msg("Ran out of fuse slots");
    return ((void *)0);
}

canonical_original_code:
struct delayed_action *d_slot()
{
    register int i;
    register struct delayed_action *dev;
    for (i = 0, dev = d_list; i < 20; i++, dev++)
 if (dev->d_type == 0)
     return dev;
    if (wizard) msg("Ran out of fuse slots");
    return ((void *)0);
}

variable_types: i int

variable_types: struct delayed_action { int d_type; int (*d_func)(); int d_arg; int d_time; } *


repo: unenemy/helios-course

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

result = 0xFFFFFFFFLL;
if ( a1 >= a2 )
result = a1 > a2;
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a1 >= a2 )
result = a1 > a2;
return result;
}

original_code:
int compare_int(void* leftp, void* rightp){
    int left = (int)leftp;
    int right = (int)rightp;
    if(left < right)
        return -1;
    else if(left > right)
        return 1;
    else
        return 0;
}

canonical_original_code:
int compare_int(void *leftp, void *rightp){
    int left = (int)leftp;
    int right = (int)rightp;
    if(left < right)
        return -1;
    else if(left > right)
        return 1;
    else
        return 0;
}

variable_types:
leftp
void *

variable_types:
rightp
void *

variable_types: right int


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

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

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

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

original_code:
int get_key(bbst_node n){
    return n == ((void *)0) ? 0 : (int)n->key;
}

canonical_original_code:
int get_key(struct bbst_node_t *n){
    return n == ((void *)0) ? 0 : (int)n->key;
}

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; } *

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:
int __fastcall print_tree(__int64 a1)
{
unsigned int v1; // ebp
unsigned int v2; // eax
unsigned int v3; // ebp
unsigned int v4; // eax
int result; // eax

v1 = get_key((unsigned int *)a1);
v2 = get_key(*(unsigned int **)(a1 + 16));
printf("%d left to %d\n", v2, v1);
v3 = get_key((unsigned int *)a1);
v4 = get_key(*(unsigned int **)(a1 + 24));
result = printf("%d right to %d\n", v4, v3);
if ( *(_QWORD *)(a1 + 16) )
result = print_tree();
if ( *(_QWORD *)(a1 + 24) )
result = print_tree();
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
unsigned int v1; // ebp
unsigned int v2; // eax
unsigned int v3; // ebp
unsigned int v4; // eax
int result; // eax

v1 = func1((unsigned int *)a1);
v2 = func1(*(unsigned int **)(a1 + 16));
printf("%d left to %d\n", v2, v1);
v3 = func1((unsigned int *)a1);
v4 = func1(*(unsigned int **)(a1 + 24));
result = printf("%d right to %d\n", v4, v3);
if ( *(_QWORD *)(a1 + 16) )
result = func2();
if ( *(_QWORD *)(a1 + 24) )
result = func2();
return result;
}

original_code:
void print_tree(bbst_node n){
    printf("%d left to %d\n", get_key(n->left), get_key(n));
    printf("%d right to %d\n", get_key(n->right), get_key(n));
    if(n->left != ((void *)0)) print_tree(n->left);
    if(n->right != ((void *)0)) print_tree(n->right);
}

canonical_original_code:
void print_tree(struct bbst_node_t *n){
    printf("%d left to %d\n", get_key(n->left), get_key(n));
    printf("%d right to %d\n", get_key(n->right), get_key(n));
    if(n->left != ((void *)0)) print_tree(n->left);
    if(n->right != ((void *)0)) print_tree(n->right);
}


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

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

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

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

original_code:
int get_value(bbst_node n){
    return n == ((void *)0) ? 0 : (int)n->value;
}

canonical_original_code:
int get_value(struct bbst_node_t *n){
    return n == ((void *)0) ? 0 : (int)n->value;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbp
int v4; // er13
int v5; // er12
int v6; // ebx
int v7; // er12
int v8; // ebx

v3 = (__int64 *)bbst_create(argc, argv, envp);
v4 = 10;
do
{
v5 = rand() % 100;
v6 = rand() % 100;
bbst_insert(v3, v5, v6, compare_int);
printf("\ninsetring %d(%d)\n", (unsigned int)v5, (unsigned int)v6);
print_tree(*v3);
--v4;
}
while ( v4 );
v7 = 10;
do
{
v8 = rand() % 100;
bbst_delete(v3, v8, compare_int);
printf("\nremoving %d\n", (unsigned int)v8);
print_tree(*v3);
--v7;
}
while ( v7 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbp
int v4; // er13
int v5; // er12
int v6; // ebx
int v7; // er12
int v8; // ebx

v3 = (__int64 *)bbst_create(argc, argv, envp);
v4 = 10;
do
{
v5 = rand() % 100;
v6 = rand() % 100;
bbst_insert(v3, v5, v6, compare_int);
printf("\ninsetring %d(%d)\n", (unsigned int)v5, (unsigned int)v6);
func2(*v3);
--v4;
}
while ( v4 );
v7 = 10;
do
{
v8 = rand() % 100;
bbst_delete(v3, v8, compare_int);
printf("\nremoving %d\n", (unsigned int)v8);
func2(*v3);
--v7;
}
while ( v7 );
return 0;
}

original_code:
int main()
{
    int i;
    bbst tree = bbst_create();
    for (i = 0; i < 10; i++) {
        int x = rand() % 100;
        int y = rand() % 100;
        bbst_insert(tree, (void*)x, (void*)y, compare_int);
        printf("\ninsetring %d(%d)\n", x, y);
        print_tree(tree->root);
    }
    for (i = 0; i < 10; i++) {
        int x = rand() % 100;
        bbst_delete(tree, (void*)x, compare_int);
        printf("\nremoving %d\n", x);
        print_tree(tree->root);
    }
    return 0;
}

canonical_original_code:
int main()
{
    int i;
    struct bbst_t *tree = bbst_create();
    for (i = 0; i < 10; i++) {
        int x = rand() % 100;
        int y = rand() % 100;
        bbst_insert(tree, (void *)x, (void *)y, compare_int);
        printf("\ninsetring %d(%d)\n", x, y);
        print_tree(tree->root);
    }
    for (i = 0; i < 10; i++) {
        int x = rand() % 100;
        bbst_delete(tree, (void *)x, compare_int);
        printf("\nremoving %d\n", x);
        print_tree(tree->root);
    }
    return 0;
}

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; } *

variable_types: x int

variable_types: y int

user_defined_types: struct bbst_t { struct bbst_node_t *root; }


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

result = 1LL;
if ( a1 )
result = *(unsigned int *)(a1 + 40);
return result;
}

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

result = 1LL;
if ( a1 )
result = *(unsigned int *)(a1 + 40);
return result;
}

original_code:
color node_color(node n){
    return n == ((void *)0) ? BLACK : n->color;
}

canonical_original_code:
enum bbst_node_color node_color(struct bbst_node_t *n){
    return n == ((void *)0) ? BLACK : n->color;
}

return_type: enum bbst_node_color { RED=0, BLACK=1 }


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

v2 = *(_QWORD *)(a2 + 24);
replace_node(a1, a2, v2);
result = *(_QWORD *)(v2 + 16);
*(_QWORD *)(a2 + 24) = result;
if ( result )
*(_QWORD *)(result + 32) = a2;
*(_QWORD *)(v2 + 16) = a2;
*(_QWORD *)(a2 + 32) = v2;
return result;
}

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

v2 = *(_QWORD *)(a2 + 24);
func7(a1, a2, v2);
result = *(_QWORD *)(v2 + 16);
*(_QWORD *)(a2 + 24) = result;
if ( result )
*(_QWORD *)(result + 32) = a2;
*(_QWORD *)(v2 + 16) = a2;
*(_QWORD *)(a2 + 32) = v2;
return result;
}

original_code:
void rotate_left(bbst tree, node n){
    node pivot = n->right;
    replace_node(tree, n, pivot);
    n->right = pivot->left;
    if(pivot->left != ((void *)0)){
        pivot->left->parent = n;
    }
    pivot->left = n;
    n->parent = pivot;
}

canonical_original_code:
void rotate_left(struct bbst_t *tree, struct bbst_node_t *n){
    struct bbst_node_t *pivot = n->right;
    replace_node(tree, n, pivot);
    n->right = pivot->left;
    if(pivot->left != ((void *)0)){
        pivot->left->parent = n;
    }
    pivot->left = n;
    n->parent = pivot;
}

variable_types:
n
struct bbst_node_t *


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

v2 = *(_QWORD *)(a2 + 16);
replace_node(a1, a2, v2);
result = *(_QWORD *)(v2 + 24);
*(_QWORD *)(a2 + 16) = result;
if ( result )
*(_QWORD *)(result + 32) = a2;
*(_QWORD *)(v2 + 24) = a2;
*(_QWORD *)(a2 + 32) = v2;
return result;
}

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

v2 = *(_QWORD *)(a2 + 16);
func7(a1, a2, v2);
result = *(_QWORD *)(v2 + 24);
*(_QWORD *)(a2 + 16) = result;
if ( result )
*(_QWORD *)(result + 32) = a2;
*(_QWORD *)(v2 + 24) = a2;
*(_QWORD *)(a2 + 32) = v2;
return result;
}

original_code:
void rotate_right(bbst tree, node n){
    node pivot = n->left;
    replace_node(tree, n, pivot);
    n->left = pivot->right;
    if(pivot->right != ((void *)0)){
        pivot->right->parent = n;
    }
    pivot->right = n;
    n->parent = pivot;
}

canonical_original_code:
void rotate_right(struct bbst_t *tree, struct bbst_node_t *n){
    struct bbst_node_t *pivot = n->left;
    replace_node(tree, n, pivot);
    n->left = pivot->right;
    if(pivot->right != ((void *)0)){
        pivot->right->parent = n;
    }
    pivot->right = n;
    n->parent = pivot;
}


sibling

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

if ( !a1 )
__assert_fail("n != NULL", "bbst.c", 0x26u, "sibling");
v1 = *(_QWORD *)(a1 + 32);
if ( !v1 )
__assert_fail("n->parent != NULL", "bbst.c", 0x27u, "sibling");
result = *(_QWORD *)(v1 + 16);
if ( result == a1 )
result = *(_QWORD *)(v1 + 24);
return result;
}

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

if ( !a1 )
__assert_fail("n != NULL", "bbst.c", 0x26u, "sibling");
v1 = *(_QWORD *)(a1 + 32);
if ( !v1 )
__assert_fail("n->parent != NULL", "bbst.c", 0x27u, "sibling");
result = *(_QWORD *)(v1 + 16);
if ( result == a1 )
result = *(_QWORD *)(v1 + 24);
return result;
}

original_code:
node sibling(node n){
    ((void) sizeof ((n != ((void *)0)) ? 1 : 0), __extension__ ({ if (n != ((void *)0)) ; else __assert_fail ("n != NULL", "bbst.c", 38, __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", 39, __extension__ __PRETTY_FUNCTION__); }));
    if(n->parent->left == n){
        return n->parent->right;
    }else {
        return n->parent->left;
    }
}

canonical_original_code:
struct bbst_node_t *sibling(struct bbst_node_t *n){
    ((void) sizeof ((n != ((void *)0)) ? 1 : 0), __extension__ ({ if (n != ((void *)0)) ; else __assert_fail ("n != NULL", "bbst.c", 38, __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", 39, __extension__ __PRETTY_FUNCTION__); }));
    if(n->parent->left == n){
        return n->parent->right;
    }else {
        return n->parent->left;
    }
}

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; } *


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

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;
}


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

*(_DWORD *)(*(_QWORD *)(a2 + 32) + 40LL) = 1;
*(_DWORD *)(grandparent(a2) + 40) = 0;
v2 = *(_QWORD *)(a2 + 32);
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));
    }
}


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(_QWORD *a1, _QWORD *a2)
{
__int64 result; // rax

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

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

result = func6(a2[4]);
if ( (_DWORD)result != 1 )
result = func15(a1, 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(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( *(_QWORD *)(a2 + 32) )
return insert_case2(a1, (_QWORD *)a2);
*(_DWORD *)(a2 + 40) = 1;
return result;
}

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

if ( *(_QWORD *)(a2 + 32) )
return func16(a1, (_QWORD *)a2);
*(_DWORD *)(a2 + 40) = 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; // rbp
__int64 v3; // rbp
__int64 result; // rax
__int64 v5; // rbp

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

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rbp
__int64 result; // rax
__int64 v5; // rbp

v2 = func10(a2);
*(_DWORD *)(v2 + 40) = func6(*(_QWORD *)(a2 + 32));
*(_DWORD *)(*(_QWORD *)(a2 + 32) + 40LL) = 1;
if ( *(_QWORD *)(*(_QWORD *)(a2 + 32) + 16LL) == a2 )
{
v5 = *(_QWORD *)(func10(a2) + 24);
if ( (unsigned int)func6(v5) )
__assert_fail("node_color(sibling(n)->right) == RED", "bbst.c", 0x13Fu, "delete_case6");
*(_DWORD *)(v5 + 40) = 1;
result = func8(a1, *(_QWORD *)(a2 + 32));
}
else
{
v3 = *(_QWORD *)(func10(a2) + 16);
if ( (unsigned int)func6(v3) )
__assert_fail("node_color(sibling(n)->left) == RED", "bbst.c", 0x145u, "delete_case6");
*(_DWORD *)(v3 + 40) = 1;
result = func9(a1, *(_QWORD *)(a2 + 32));
}
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; // rbp
__int64 v4; // r13
__int64 v5; // rax
__int64 v6; // rbp
__int64 v7; // rax

v2 = *(_QWORD *)(a2 + 32);
if ( *(_QWORD *)(v2 + 16) == a2
&& (v4 = sibling(a2), (unsigned int)node_color(v4) == 1)
&& !(unsigned int)node_color(*(_QWORD *)(v4 + 16))
&& (unsigned int)node_color(*(_QWORD *)(v4 + 24)) == 1 )
{
*(_DWORD *)(v4 + 40) = 0;
*(_DWORD *)(*(_QWORD *)(sibling(a2) + 16) + 40LL) = 1;
v5 = sibling(a2);
rotate_right(a1, v5);
}
else if ( *(_QWORD *)(v2 + 24) == a2 )
{
v6 = sibling(a2);
if ( (unsigned int)node_color(v6) == 1
&& !(unsigned int)node_color(*(_QWORD *)(v6 + 24))
&& (unsigned int)node_color(*(_QWORD *)(v6 + 16)) == 1 )
{
*(_DWORD *)(v6 + 40) = 0;
*(_DWORD *)(*(_QWORD *)(sibling(a2) + 24) + 40LL) = 1;
v7 = sibling(a2);
rotate_left(a1, v7);
}
}
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; // rbp
__int64 result; // rax

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

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

if ( (unsigned int)func6(*(_QWORD *)(a2 + 32)) )
return func20(a1, a2);
v2 = func10(a2);
if ( (unsigned int)func6(v2) != 1
|| (unsigned int)func6(*(_QWORD *)(v2 + 16)) != 1
|| (unsigned int)func6(*(_QWORD *)(v2 + 24)) != 1 )
{
return func20(a1, a2);
}
*(_DWORD *)(v2 + 40) = 0;
result = *(_QWORD *)(a2 + 32);
*(_DWORD *)(result + 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 v3; // r12

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

canonical_decompiled_code:
__int64 __fastcall func22(_QWORD *a1, __int64 a2)
{
__int64 v3; // r12

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

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 v3; // rax
__int64 v5; // rsi

v3 = sibling(a2);
if ( !(unsigned int)node_color(v3) )
{
*(_DWORD *)(*(_QWORD *)(a2 + 32) + 40LL) = 0;
*(_DWORD *)(sibling(a2) + 40) = 1;
v5 = *(_QWORD *)(a2 + 32);
if ( *(_QWORD *)(v5 + 16) == a2 )
rotate_left(a1, v5);
else
rotate_right(a1, v5);
}
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; // r13
_QWORD *v7; // rbx
_QWORD *v8; // rax
int v9; // eax

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

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)


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

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

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; // rbx

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; // rbx

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; a1 = (_QWORD *)a1[1] )
{
if ( !*a1 )
break;
result = (unsigned int)(result + 1);
}
return result;
}

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

for ( result = 0LL; a1; a1 = (_QWORD *)a1[1] )
{
if ( !*a1 )
break;
result = (unsigned int)(result + 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;
}

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 *v3; // rbx
_QWORD *v5; // rax
_QWORD *v6; // r12
int v7; // eax
__int64 v8; // rax

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

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

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

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)
{
_QWORD *v2; // r12
int v3; // eax

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

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

v2 = *a1;
v3 = func8(*a1);
if ( v3 )
func11(v2, a2, v3 - 1);
else
func10(a1, 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; // rbp

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

canonical_decompiled_code:
void __fastcall func13(_QWORD **a1)
{
_QWORD *v1; // rbp

v1 = *a1;
if ( (int)func8(*a1) > 1 )
{
*a1 = (_QWORD *)v1[1];
free(v1);
}
else
{
*v1 = 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; // rdi
_QWORD *v3; // rdx

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

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

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

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;
}

variable_types: i int


chop

repo: uniquerockrz/PurgeOldVersion

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

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

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

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

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, _BYTE *a2)
{
char v2; // dl
__int64 result; // rax
__int64 v4; // rax

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

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

v2 = *a1;
result = 0LL;
if ( *a1 && *a2 )
{
v4 = 0LL;
while ( a2[v4] == v2 )
{
v2 = a1[++v4];
if ( !v2 )
return 1LL;
}
result = 0LL;
}
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)
{
__int64 v1; // r12
int i; // ebp
int v3; // ebx
char v5[248]; // [rsp+0h] [rbp-F8h] BYREF

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

canonical_decompiled_code:
int __fastcall func12(int a1)
{
__int64 v1; // r12
int i; // ebp
int v3; // ebx
char v5[248]; // [rsp+0h] [rbp-F8h] BYREF

if ( a1 >= 0 )
{
v1 = 0LL;
for ( i = 0; i <= a1; ++i )
{
v3 = func8(&buffer[v1], v5);
strncpy(&choppedfilename[v1], v5, v3);
choppedfilename[200 * i + 1 + v3] = 0;
v1 += 200LL;
}
}
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)


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
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)
{
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)


start

repo: uniquerockrz/smsh

decompiled_code:
int __fastcall start(__int64 a1)
{
struct tm *v1; // rax
FILE *v2; // rbp
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; // rbp
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)
{
unsigned __int64 v4; // rbx
__int64 v5; // r12
__int64 v6; // r13
unsigned __int64 result; // rax

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

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

v4 = a2;
v5 = ~(__int64)a3;
v6 = a4 - a2;
while ( 1 )
{
result = v5 + strlen(s);
if ( result < v4 )
break;
*(_BYTE *)(v6 + v4) = s[v4];
++v4;
}
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; // rbx
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

*(_QWORD *)&tp.tm_sec = 0LL;
*(_QWORD *)&tp.tm_hour = 0LL;
*(_QWORD *)&tp.tm_mon = 0LL;
*(_QWORD *)&tp.tm_wday = 0LL;
*(_QWORD *)&tp.tm_isdst = 0LL;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 0LL;
*(_QWORD *)&v6.tm_sec = 0LL;
*(_QWORD *)&v6.tm_hour = 0LL;
*(_QWORD *)&v6.tm_mon = 0LL;
*(_QWORD *)&v6.tm_wday = 0LL;
*(_QWORD *)&v6.tm_isdst = 0LL;
v6.tm_gmtoff = 0LL;
v6.tm_zone = 0LL;
strptime(a1, "%d %b %Y %H:%M:%S", &tp);
strptime(a2, "%d %b %Y %H:%M:%S", &v6);
v2 = mktime(&tp);
v3 = mktime(&v6);
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; // rbx
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

*(_QWORD *)&tp.tm_sec = 0LL;
*(_QWORD *)&tp.tm_hour = 0LL;
*(_QWORD *)&tp.tm_mon = 0LL;
*(_QWORD *)&tp.tm_wday = 0LL;
*(_QWORD *)&tp.tm_isdst = 0LL;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 0LL;
*(_QWORD *)&v6.tm_sec = 0LL;
*(_QWORD *)&v6.tm_hour = 0LL;
*(_QWORD *)&v6.tm_mon = 0LL;
*(_QWORD *)&v6.tm_wday = 0LL;
*(_QWORD *)&v6.tm_isdst = 0LL;
v6.tm_gmtoff = 0LL;
v6.tm_zone = 0LL;
strptime(a1, "%d %b %Y %H:%M:%S", &tp);
strptime(a2, "%d %b %Y %H:%M:%S", &v6);
v2 = mktime(&tp);
v3 = mktime(&v6);
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_8AE, "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_8AE, "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:
void __fastcall Log(const char *a1, const char *a2, const char *a3, const char *a4)
{
const char *v4; // rbx
const char *v5; // rbp
__gid_t v8; // er14
__uid_t v9; // eax

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

canonical_decompiled_code:
void __fastcall func0(const char *a1, const char *a2, const char *a3, const char *a4)
{
const char *v4; // rbx
const char *v5; // rbp
__gid_t v8; // er14
__uid_t v9; // eax

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

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; // rsi
const char *result; // rax
const char *v3; // rax
unsigned __int8 *v4; // rsi
__int64 v5; // rdi
int v6; // edx
unsigned __int64 v7; // rdx

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

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
size_t v1; // rsi
const char *result; // rax
const char *v3; // rax
unsigned __int8 *v4; // rsi
__int64 v5; // rdi
int v6; // edx
unsigned __int64 v7; // rdx

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