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

v2 = *a1;
result = readsgffile(a2);
*a1 = result;
if ( result )
{
sgfFreeNode(v2);
a1[1] = 0LL;
result = 1LL;
}
else
{
*a1 = v2;
}
return result;
}

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

v2 = *a1;
result = readsgffile(a2);
*a1 = result;
if ( result )
{
sgfFreeNode(v2);
a1[1] = 0LL;
result = 1LL;
}
else
{
*a1 = v2;
}
return result;
}

original_code:
int
sgftree_readfile(SGFTree *tree, const char *infilename)
{
  SGFNode *savetree = tree->root;
  tree->root = readsgffile(infilename);
  if (tree->root == ((void *)0)) {
    tree->root = savetree;
    return 0;
  }
  sgfFreeNode(savetree);
  tree->lastnode = ((void *)0);
  return 1;
}

canonical_original_code:
int sgftree_readfile(struct SGFTree_t *tree, char *infilename)
{
  struct SGFNode_t *savetree = tree->root;
  tree->root = readsgffile(infilename);
  if (tree->root == ((void *)0)) {
    tree->root = savetree;
    return 0;
  }
  sgfFreeNode(savetree);
  tree->lastnode = ((void *)0);
  return 1;
}

variable_types:
infilename
char *

user_defined_types: struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; }


sgftreeForward

repo: bamboolll/goitout

decompiled_code:
__int64 __fastcall sgftreeForward(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = a1[1];
if ( v1 )
{
v2 = *(_QWORD *)(v1 + 16);
if ( v2 )
{
a1[1] = v2;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
a1[1] = *a1;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = a1[1];
if ( v1 )
{
v2 = *(_QWORD *)(v1 + 16);
if ( v2 )
{
a1[1] = v2;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
a1[1] = *a1;
result = 1LL;
}
return result;
}

original_code:
int
sgftreeForward(SGFTree *tree)
{
  if (tree->lastnode) {
    if (tree->lastnode->child)
      tree->lastnode = tree->lastnode->child;
    else
      return 0;
  }
  else
    tree->lastnode = tree->root;
  return 1;
}

canonical_original_code:
int sgftreeForward(struct SGFTree_t *tree)
{
  if (tree->lastnode) {
    if (tree->lastnode->child)
      tree->lastnode = tree->lastnode->child;
    else
      return 0;
  }
  else
    tree->lastnode = tree->root;
  return 1;
}

variable_types: struct SGFTree_t { struct SGFNode_t { struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; } *props; struct SGFNode_t *parent; struct SGFNode_t *child; struct SGFNode_t *next; } *root; struct SGFNode_t *lastnode; } *

return_type: int

user_defined_types: struct SGFTree_t { struct SGFNode_t *root; struct SGFNode_t *lastnode; }

user_defined_types: struct SGFNode_t { struct SGFProperty_t *props; struct SGFNode_t *parent; struct SGFNode_t *child; struct SGFNode_t *next; }


sgftreeBack

decompiled_code:
__int64 __fastcall sgftreeBack(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = a1[1];
if ( v1 )
{
v2 = *(_QWORD *)(v1 + 8);
if ( v2 )
{
a1[1] = v2;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
while ( (unsigned int)sgftreeForward(a1) )
;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = a1[1];
if ( v1 )
{
v2 = *(_QWORD *)(v1 + 8);
if ( v2 )
{
a1[1] = v2;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
while ( (unsigned int)func2(a1) )
;
result = 1LL;
}
return result;
}

original_code:
int
sgftreeBack(SGFTree *tree)
{
  if (tree->lastnode) {
    if (tree->lastnode->parent)
      tree->lastnode = tree->lastnode->parent;
    else
      return 0;
  }
  else
    while (sgftreeForward(tree))
      ;
  return 1;
}

canonical_original_code:
int sgftreeBack(struct SGFTree_t *tree)
{
  if (tree->lastnode) {
    if (tree->lastnode->parent)
      tree->lastnode = tree->lastnode->parent;
    else
      return 0;
  }
  else
    while (sgftreeForward(tree))
      ;
  return 1;
}


sgftreeNodeCheck

decompiled_code:
__int64 __fastcall sgftreeNodeCheck(__int64 *a1)
{
__int64 v1; // rax
__int64 v2; // rdx

v1 = *a1;
if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0x6Bu, "sgftreeNodeCheck");
v2 = a1[1];
if ( !v2 )
{
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
__int64 v1; // rax
__int64 v2; // rdx

v1 = *a1;
if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0x6Bu, "sgftreeNodeCheck");
v2 = a1[1];
if ( !v2 )
{
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return v2;
}

original_code:
SGFNode *
sgftreeNodeCheck(SGFTree *tree)
{
  SGFNode *node = ((void *)0);
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 107, __extension__ __PRETTY_FUNCTION__); }));
  if (tree->lastnode)
    node = tree->lastnode;
  else {
    node = tree->root;
    while (node->child)
      node = node->child;
  }
  return node;
}

canonical_original_code:
struct SGFNode_t *sgftreeNodeCheck(struct SGFTree_t *tree)
{
  struct SGFNode_t *node = ((void *)0);
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 107, __extension__ __PRETTY_FUNCTION__); }));
  if (tree->lastnode)
    node = tree->lastnode;
  else {
    node = tree->root;
    while (node->child)
      node = node->child;
  }
  return node;
}

variable_types: struct SGFTree_t { struct SGFNode_t *root; struct SGFNode_t *lastnode; } *

variable_types: struct SGFNode_t { struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; } *props; struct SGFNode_t *parent; struct SGFNode_t *child; struct SGFNode_t *next; } *


sgftreeAddStone

decompiled_code:
__int64 __fastcall sgftreeAddStone(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax

v6 = sgftreeNodeCheck(a1);
return sgfAddStone(v6, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax

v6 = func4(a1);
return sgfAddStone(v6, a2, a3, a4);
}

original_code:
void
sgftreeAddStone(SGFTree *tree, int color, int movex, int movey)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  sgfAddStone(node, color, movex, movey);
}

canonical_original_code:
void sgftreeAddStone(struct SGFTree_t *tree, int color, int movex, int movey)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  sgfAddStone(node, color, movex, movey);
}

variable_types: color int

variable_types: movex int

variable_types: movey int

return_type: void


sgftreeAddPlay

decompiled_code:
__int64 __fastcall sgftreeAddPlay(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax
__int64 result; // rax

v6 = sgftreeNodeCheck(a1);
result = sgfAddPlay(v6, a2, a3, a4);
a1[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax
__int64 result; // rax

v6 = func4(a1);
result = sgfAddPlay(v6, a2, a3, a4);
a1[1] = result;
return result;
}

original_code:
void
sgftreeAddPlay(SGFTree *tree, int color, int movex, int movey)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfAddPlay(node, color, movex, movey);
}

canonical_original_code:
void sgftreeAddPlay(struct SGFTree_t *tree, int color, int movex, int movey)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfAddPlay(node, color, movex, movey);
}


sgftreeAddPlayLast

decompiled_code:
__int64 __fastcall sgftreeAddPlayLast(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax
__int64 result; // rax

v6 = sgftreeNodeCheck(a1);
result = sgfAddPlayLast(v6, a2, a3, a4);
a1[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax
__int64 result; // rax

v6 = func4(a1);
result = sgfAddPlayLast(v6, a2, a3, a4);
a1[1] = result;
return result;
}

original_code:
void
sgftreeAddPlayLast(SGFTree *tree, int color, int movex, int movey)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfAddPlayLast(node, color, movex, movey);
}

canonical_original_code:
void sgftreeAddPlayLast(struct SGFTree_t *tree, int color, int movex, int movey)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfAddPlayLast(node, color, movex, movey);
}


sgftreeAddComment

decompiled_code:
__int64 __fastcall sgftreeAddComment(__int64 *a1, __int64 a2)
{
__int64 v2; // rax

if ( !a1 || !*a1 )
_assert_fail("tree && tree->root", "msgftree.c", 0xB4u, "sgftreeAddComment");
v2 = sgftreeNodeCheck(a1);
return sgfAddComment(v2, a2);
}

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

if ( !a1 || !*a1 )
_assert_fail("tree && tree->root", "msgftree.c", 0xB4u, "sgftreeAddComment");
v2 = func4(a1);
return sgfAddComment(v2, a2);
}

original_code:
void
sgftreeAddComment(SGFTree *tree, const char *comment)
{
  SGFNode *node;
  ((void) sizeof ((tree && tree->root) ? 1 : 0), __extension__ ({ if (tree && tree->root) ; else __assert_fail ("tree && tree->root", "msgftree.c", 180, __extension__ __PRETTY_FUNCTION__); }));
  node = sgftreeNodeCheck(tree);
  sgfAddComment(node, comment);
}

canonical_original_code:
void sgftreeAddComment(struct SGFTree_t *tree, char *comment)
{
  struct SGFNode_t *node;
  ((void) sizeof ((tree && tree->root) ? 1 : 0), __extension__ ({ if (tree && tree->root) ; else __assert_fail ("tree && tree->root", "msgftree.c", 180, __extension__ __PRETTY_FUNCTION__); }));
  node = sgftreeNodeCheck(tree);
  sgfAddComment(node, comment);
}

variable_types:
comment
char *


sgftreeBoardText

decompiled_code:
__int64 __fastcall sgftreeBoardText(__int64 *a1, unsigned int a2, unsigned int a3, __int64 a4)
{
__int64 v6; // rax

if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0xC3u, "sgftreeBoardText");
v6 = sgftreeNodeCheck(a1);
return sgfBoardText(v6, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1, unsigned int a2, unsigned int a3, __int64 a4)
{
__int64 v6; // rax

if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0xC3u, "sgftreeBoardText");
v6 = func4(a1);
return sgfBoardText(v6, a2, a3, a4);
}

original_code:
void
sgftreeBoardText(SGFTree *tree, int i, int j, const char *text)
{
  SGFNode *node;
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 195, __extension__ __PRETTY_FUNCTION__); }));
  node = sgftreeNodeCheck(tree);
  sgfBoardText(node, i, j, text);
}

canonical_original_code:
void sgftreeBoardText(struct SGFTree_t *tree, int i, int j, char *text)
{
  struct SGFNode_t *node;
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 195, __extension__ __PRETTY_FUNCTION__); }));
  node = sgftreeNodeCheck(tree);
  sgfBoardText(node, i, j, text);
}

variable_types: i int

variable_types: j int

variable_types:
text
char *


sgftreeBoardChar

decompiled_code:
__int64 __fastcall sgftreeBoardChar(__int64 *a1, unsigned int a2, unsigned int a3, char a4)
{
__int64 v6; // rax

if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0xD2u, "sgftreeBoardChar");
v6 = sgftreeNodeCheck(a1);
return sgfBoardChar(v6, a2, a3, (unsigned int)a4);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1, unsigned int a2, unsigned int a3, char a4)
{
__int64 v6; // rax

if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0xD2u, "sgftreeBoardChar");
v6 = func4(a1);
return sgfBoardChar(v6, a2, a3, (unsigned int)a4);
}

original_code:
void
sgftreeBoardChar(SGFTree *tree, int i, int j, char c)
{
  SGFNode *node;
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 210, __extension__ __PRETTY_FUNCTION__); }));
  node = sgftreeNodeCheck(tree);
  sgfBoardChar(node, i, j, c);
}

canonical_original_code:
void sgftreeBoardChar(struct SGFTree_t *tree, int i, int j, char c)
{
  struct SGFNode_t *node;
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 210, __extension__ __PRETTY_FUNCTION__); }));
  node = sgftreeNodeCheck(tree);
  sgfBoardChar(node, i, j, c);
}

variable_types: c char


sgftreeBoardNumber

decompiled_code:
__int64 __fastcall sgftreeBoardNumber(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax

v6 = sgftreeNodeCheck(a1);
return sgfBoardNumber(v6, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax

v6 = func4(a1);
return sgfBoardNumber(v6, a2, a3, a4);
}

original_code:
void
sgftreeBoardNumber(SGFTree *tree, int i, int j, int number)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  sgfBoardNumber(node, i, j, number);
}

canonical_original_code:
void sgftreeBoardNumber(struct SGFTree_t *tree, int i, int j, int number)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  sgfBoardNumber(node, i, j, number);
}

variable_types: number int


sgftreeTriangle

decompiled_code:
__int64 __fastcall sgftreeTriangle(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = sgftreeNodeCheck(a1);
return sgfTriangle(v4, a2, a3);
}

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

v4 = func4(a1);
return sgfTriangle(v4, a2, a3);
}

original_code:
void
sgftreeTriangle(SGFTree *tree, int i, int j)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  sgfTriangle(node, i, j);
}

canonical_original_code:
void sgftreeTriangle(struct SGFTree_t *tree, int i, int j)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  sgfTriangle(node, i, j);
}


sgftreeCircle

decompiled_code:
__int64 __fastcall sgftreeCircle(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = sgftreeNodeCheck(a1);
return sgfCircle(v4, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = func4(a1);
return sgfCircle(v4, a2, a3);
}

original_code:
void
sgftreeCircle(SGFTree *tree, int i, int j)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  sgfCircle(node, i, j);
}

canonical_original_code:
void sgftreeCircle(struct SGFTree_t *tree, int i, int j)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  sgfCircle(node, i, j);
}


sgftreeSquare

decompiled_code:
__int64 __fastcall sgftreeSquare(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = sgftreeNodeCheck(a1);
return sgfSquare(v4, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = func4(a1);
return sgfSquare(v4, a2, a3);
}

original_code:
void
sgftreeSquare(SGFTree *tree, int i, int j)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  sgfSquare(node, i, j);
}

canonical_original_code:
void sgftreeSquare(struct SGFTree_t *tree, int i, int j)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  sgfSquare(node, i, j);
}


sgftreeMark

decompiled_code:
__int64 __fastcall sgftreeMark(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = sgftreeNodeCheck(a1);
return sgfMark(v4, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 *a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax

v4 = func4(a1);
return sgfMark(v4, a2, a3);
}

original_code:
void
sgftreeMark(SGFTree *tree, int i, int j)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  sgfMark(node, i, j);
}

canonical_original_code:
void sgftreeMark(struct SGFTree_t *tree, int i, int j)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  sgfMark(node, i, j);
}


sgftreeStartVariant

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

v1 = sgftreeNodeCheck(a1);
result = sgfStartVariant(v1);
a1[1] = result;
return result;
}

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

v1 = func4(a1);
result = sgfStartVariant(v1);
a1[1] = result;
return result;
}

original_code:
void
sgftreeStartVariant(SGFTree *tree)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfStartVariant(node);
}

canonical_original_code:
void sgftreeStartVariant(struct SGFTree_t *tree)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfStartVariant(node);
}


sgftreeStartVariantFirst

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

v1 = sgftreeNodeCheck(a1);
result = sgfStartVariantFirst(v1);
a1[1] = result;
return result;
}

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

v1 = func4(a1);
result = sgfStartVariantFirst(v1);
a1[1] = result;
return result;
}

original_code:
void
sgftreeStartVariantFirst(SGFTree *tree)
{
  SGFNode *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfStartVariantFirst(node);
}

canonical_original_code:
void sgftreeStartVariantFirst(struct SGFTree_t *tree)
{
  struct SGFNode_t *node = sgftreeNodeCheck(tree);
  tree->lastnode = sgfStartVariantFirst(node);
}


sgftreeWriteResult

decompiled_code:
__int64 __fastcall sgftreeWriteResult(_QWORD *a1)
{
if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0x134u, "sgftreeWriteResult");
return sgfWriteResult();
}

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1)
{
if ( !*a1 )
_assert_fail("tree->root", "msgftree.c", 0x134u, "sgftreeWriteResult");
return sgfWriteResult();
}

original_code:
void
sgftreeWriteResult(SGFTree *tree, float score, int overwrite)
{
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 308, __extension__ __PRETTY_FUNCTION__); }));
  sgfWriteResult(tree->root, score, overwrite);
}

canonical_original_code:
void sgftreeWriteResult(struct SGFTree_t *tree, float score, int overwrite)
{
  ((void) sizeof ((tree->root) ? 1 : 0), __extension__ ({ if (tree->root) ; else __assert_fail ("tree->root", "msgftree.c", 308, __extension__ __PRETTY_FUNCTION__); }));
  sgfWriteResult(tree->root, score, overwrite);
}

variable_types: score float

variable_types: overwrite int


sgftreeSetLastNode

decompiled_code:
void __fastcall sgftreeSetLastNode(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

original_code:
void
sgftreeSetLastNode(SGFTree *tree, SGFNode *last_node)
{
  tree->lastnode = last_node;
}

canonical_original_code:
void sgftreeSetLastNode(struct SGFTree_t *tree, struct SGFNode_t *last_node)
{
  tree->lastnode = last_node;
}


decompiled_code:
__int64 __fastcall get_moveX(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 16);
if ( strlen((const char *)v2) <= 1 )
return 0xFFFFFFFFLL;
result = (unsigned int)(toupper(*(char *)(v2 + 1)) - 65);
if ( (int)result >= a2 )
result = 0xFFFFFFFFLL;
return result;
}

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

v2 = *(_QWORD *)(a1 + 16);
if ( strlen((const char *)v2) <= 1 )
return 0xFFFFFFFFLL;
result = (unsigned int)(toupper(*(char *)(v2 + 1)) - 65);
if ( (int)result >= a2 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int
get_moveX(SGFProperty *property, int boardsize)
{
  int i;
  if (strlen(property->value) < 2)
    return -1;
  i = toupper((int) property->value[1]) - 'A';
  if (i >= boardsize)
    return -1;
  return i;
}

canonical_original_code:
int get_moveX(struct SGFProperty_t *property, int boardsize)
{
  int i;
  if (strlen(property->value) < 2)
    return -1;
  i = toupper((int) property->value[1]) - 'A';
  if (i >= boardsize)
    return -1;
  return i;
}

variable_types: struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; } *

variable_types: boardsize int


decompiled_code:
__int64 __fastcall get_moveY(__int64 a1, int a2)
{
const char *v2; // rbx
__int64 result; // rax

v2 = *(const char **)(a1 + 16);
if ( strlen(v2) <= 1 )
return 0xFFFFFFFFLL;
result = (unsigned int)(toupper(*v2) - 65);
if ( (int)result >= a2 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
const char *v2; // rbx
__int64 result; // rax

v2 = *(const char **)(a1 + 16);
if ( strlen(v2) <= 1 )
return 0xFFFFFFFFLL;
result = (unsigned int)(toupper(*v2) - 65);
if ( (int)result >= a2 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int
get_moveY(SGFProperty *property, int boardsize)
{
  int j;
  if (strlen(property->value) < 2)
    return -1;
  j = toupper((int) property->value[0]) - 'A';
  if (j >= boardsize)
    return -1;
  return j;
}

canonical_original_code:
int get_moveY(struct SGFProperty_t *property, int boardsize)
{
  int j;
  if (strlen(property->value) < 2)
    return -1;
  j = toupper((int) property->value[0]) - 'A';
  if (j >= boardsize)
    return -1;
  return j;
}


decompiled_code:
_BOOL8 __fastcall get_moveXY(__int64 a1, _DWORD *a2, _DWORD *a3, int a4)
{
int v6; // eax

*a2 = get_moveX(a1, a4);
v6 = get_moveY(a1, a4);
*a3 = v6;
return (*a2 & v6) != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, _DWORD *a2, _DWORD *a3, int a4)
{
int v6; // eax

*a2 = func0(a1, a4);
v6 = func1(a1, a4);
*a3 = v6;
return (*a2 & v6) != -1;
}

original_code:
int
get_moveXY(SGFProperty *property, int *i, int *j, int boardsize)
{
  *i = get_moveX(property, boardsize);
  *j = get_moveY(property, boardsize);
  if (*i == -1 && *j == -1)
    return 0;
  return 1;
}

canonical_original_code:
int get_moveXY(struct SGFProperty_t *property, int *i, int *j, int boardsize)
{
  *i = get_moveX(property, boardsize);
  *j = get_moveY(property, boardsize);
  if (*i == -1 && *j == -1)
    return 0;
  return 1;
}

variable_types:
i
int *

variable_types:
j
int *


decompiled_code:
__int64 __fastcall show_sgf_properties(__int64 **a1)
{
__int64 *v1; // rbx
unsigned int v2; // ebp

printf("P: ");
v1 = *a1;
v2 = 0;
if ( *a1 )
{
do
{
printf("%c%c ", (unsigned __int8)*((_WORD *)v1 + 4), (unsigned __int8)HIBYTE(*((_WORD *)v1 + 4)));
v1 = (__int64 *)*v1;
++v2;
}
while ( v1 );
printf("(%d) ", v2);
if ( a1[3] )
putchar(110);
if ( a1[2] )
putchar(99);
putchar(10);
}
else
{
puts("None");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 **a1)
{
__int64 *v1; // rbx
unsigned int v2; // ebp

printf("P: ");
v1 = *a1;
v2 = 0;
if ( *a1 )
{
do
{
printf("%c%c ", (unsigned __int8)*((_WORD *)v1 + 4), (unsigned __int8)HIBYTE(*((_WORD *)v1 + 4)));
v1 = (__int64 *)*v1;
++v2;
}
while ( v1 );
printf("(%d) ", v2);
if ( a1[3] )
putchar(110);
if ( a1[2] )
putchar(99);
putchar(10);
}
else
{
puts("None");
}
return v2;
}

original_code:
int
show_sgf_properties(SGFNode *node)
{
  SGFProperty *sgf_prop;
  int propcount;
  propcount = 0;
  printf("P: ");
  if (!node->props) {
    printf("None\n");
    return propcount;
  }
  else {
    sgf_prop = node->props;
    while (sgf_prop) {
      printf("%c%c ", sgf_prop->name & 0x00FF, (sgf_prop->name & 0xFF00)>>8);
      sgf_prop = sgf_prop->next;
      propcount++;
    }
    printf("(%d) ", propcount);
    if (node->next)
      printf("n");
    if (node->child)
      printf("c");
    printf("\n");
  }
  return propcount;
}

canonical_original_code:
int show_sgf_properties(struct SGFNode_t *node)
{
  struct SGFProperty_t *sgf_prop;
  int propcount;
  propcount = 0;
  printf("P: ");
  if (!node->props) {
    printf("None\n");
    return propcount;
  }
  else {
    sgf_prop = node->props;
    while (sgf_prop) {
      printf("%c%c ", sgf_prop->name & 0x00FF, (sgf_prop->name & 0xFF00)>>8);
      sgf_prop = sgf_prop->next;
      propcount++;
    }
    printf("(%d) ", propcount);
    if (node->next)
      printf("n");
    if (node->child)
      printf("c");
    printf("\n");
  }
  return propcount;
}

variable_types: propcount int


decompiled_code:
__int64 __fastcall show_sgf_tree(__int64 a1)
{
unsigned int v1; // ebp

show_sgf_properties((__int64 **)a1);
v1 = 1;
if ( *(_QWORD *)(a1 + 16) )
v1 = show_sgf_tree() + 1;
if ( *(_QWORD *)(a1 + 24) )
v1 += show_sgf_tree();
return v1;
}

original_code:
int
show_sgf_tree(SGFNode *node)
{
  int n = 0;
  n++;
  show_sgf_properties(node);
  if (node->child)
    n += show_sgf_tree(node->child);
  if (node->next)
    n += show_sgf_tree(node->next);
  return n;
}

canonical_original_code:
int show_sgf_tree(struct SGFNode_t *node)
{
  int n = 0;
  n++;
  show_sgf_properties(node);
  if (node->child)
    n += show_sgf_tree(node->child);
  if (node->next)
    n += show_sgf_tree(node->next);
  return n;
}

variable_types: struct SGFNode_t { struct SGFProperty_t { struct SGFProperty_t *next; short name; char *value; } *props; struct SGFNode_t *parent; struct SGFNode_t *child; struct SGFNode_t *next; } *

variable_types: n int


original_code:
int
is_markup_node(SGFNode *node)
{
  SGFProperty *sgf_prop;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 21059:
    case 20819:
    case 21076:
    case 16717:
    case 19778:
    case 20292:
    case 21577:
    case 17748:
      return 1;
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}

canonical_original_code:
int is_markup_node(struct SGFNode_t *node)
{
  struct SGFProperty_t *sgf_prop;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 21059:
    case 20819:
    case 21076:
    case 16717:
    case 19778:
    case 20292:
    case 21577:
    case 17748:
      return 1;
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}


decompiled_code:
__int64 __fastcall is_move_node(__int64 *a1)
{
__int64 result; // rax
__int16 v2; // dx

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1)
{
__int64 result; // rax
__int16 v2; // dx

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

original_code:
int
is_move_node(SGFNode *node)
{
  SGFProperty *sgf_prop;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 8258:
    case 8279:
      return 1;
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}

canonical_original_code:
int is_move_node(struct SGFNode_t *node)
{
  struct SGFProperty_t *sgf_prop;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 8258:
    case 8279:
      return 1;
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}


decompiled_code:
_BOOL8 __fastcall is_pass_node(__int64 *a1, int a2)
{
__int64 v2; // rdi
__int16 v3; // ax
int v5; // [rsp+0h] [rbp-10h] BYREF
int v6[3]; // [rsp+4h] [rbp-Ch] BYREF

v2 = *a1;
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = *(_WORD *)(v2 + 8);
if ( v3 == 8258 || v3 == 8279 )
break;
v2 = *(_QWORD *)v2;
if ( !v2 )
return 0LL;
}
return !get_moveXY(v2, v6, &v5, a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 *a1, int a2)
{
__int64 v2; // rdi
__int16 v3; // ax
int v5; // [rsp+0h] [rbp-10h] BYREF
int v6[3]; // [rsp+4h] [rbp-Ch] BYREF

v2 = *a1;
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = *(_WORD *)(v2 + 8);
if ( v3 == 8258 || v3 == 8279 )
break;
v2 = *(_QWORD *)v2;
if ( !v2 )
return 0LL;
}
return !func2(v2, v6, &v5, a2);
}

original_code:
int
is_pass_node(SGFNode *node, int boardsize)
{
  SGFProperty *sgf_prop;
  int i, j;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 8258:
    case 8279:
      return !get_moveXY(sgf_prop, &i, &j, boardsize);
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}

canonical_original_code:
int is_pass_node(struct SGFNode_t *node, int boardsize)
{
  struct SGFProperty_t *sgf_prop;
  int i; int j;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 8258:
    case 8279:
      return !get_moveXY(sgf_prop, &i, &j, boardsize);
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}


decompiled_code:
__int64 __fastcall find_move(__int64 *a1)
{
__int64 result; // rax
__int16 v2; // dx

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

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1)
{
__int64 result; // rax
__int16 v2; // dx

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

original_code:
int
find_move(SGFNode *node)
{
  SGFProperty *sgf_prop;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 8258:
      return 2;
      break;
    case 8279:
      return 1;
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}

canonical_original_code:
int find_move(struct SGFNode_t *node)
{
  struct SGFProperty_t *sgf_prop;
  if (!node->props)
    return 0;
  sgf_prop = node->props;
  while (sgf_prop) {
    switch (sgf_prop->name) {
    case 8258:
      return 2;
      break;
    case 8279:
      return 1;
      break;
    default:
      break;
    }
    sgf_prop = sgf_prop->next;
  }
  return 0;
}


decompiled_code:
__int64 next_rand()
{
if ( !rand_initialized )
_assert_fail("rand_initialized", "mrandom.c", 0x5Bu, "next_rand");
if ( ++k == 25 )
{
iterate_tgfsr();
k = 0;
}
return ((x[k] ^ (x[k] << 7) & 0x2B5B2500) << 15) & 0xDB8B0000 ^ x[k] ^ (x[k] << 7) & 0x2B5B2500;
}

original_code:
static unsigned int
next_rand(void)
{
  int y;
  if (!rand_initialized) {
    ((void) sizeof ((rand_initialized) ? 1 : 0), __extension__ ({ if (rand_initialized) ; else __assert_fail ("rand_initialized", "mrandom.c", 91, __extension__ __PRETTY_FUNCTION__); }));
    gg_srand(1);
  }
  if (++k == 25) {
    iterate_tgfsr();
    k = 0;
  }
  y = x[k] ^ ((x[k] << s) & b);
  y ^= ((y << t) & c);
  return y;
}

canonical_original_code:
static unsigned int next_rand()
{
  int y;
  if (!rand_initialized) {
    ((void) sizeof ((rand_initialized) ? 1 : 0), __extension__ ({ if (rand_initialized) ; else __assert_fail ("rand_initialized", "mrandom.c", 91, __extension__ __PRETTY_FUNCTION__); }));
    gg_srand(1);
  }
  if (++k == 25) {
    iterate_tgfsr();
    k = 0;
  }
  y = x[k] ^ ((x[k] << s) & b);
  y ^= ((y << t) & c);
  return y;
}

variable_types: y int

return_type: unsigned int


decompiled_code:
char *__fastcall gg_srand(int a1)
{
char *result; // rax

result = (char *)x;
do
{
*(_DWORD *)result = a1;
a1 = 1313 * a1 + 88897;
result += 4;
}
while ( result != "mrandom.c" );
k = 24;
rand_initialized = 1;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(int a1)
{
char *result; // rax

result = (char *)x;
do
{
*(_DWORD *)result = a1;
a1 = 1313 * a1 + 88897;
result += 4;
}
while ( result != "mrandom.c" );
k = 24;
rand_initialized = 1;
return result;
}

original_code:
void
gg_srand(unsigned int seed)
{
  int i;
  for (i = 0; i < 25; i++) {
    x[i] = seed;
    seed *= 1313;
    seed += 88897;
  }
  k = 25 -1;
  rand_initialized = 1;
}

variable_types:
seed
unsigned int


decompiled_code:
__int64 gg_rand()
{
return next_rand() & 0x7FFFFFFF;
}

canonical_decompiled_code:
__int64 func3()
{
return func1() & 0x7FFFFFFF;
}

original_code:
int
gg_rand(void)
{
  return (int) (next_rand() & 0x7fffffff);
}

canonical_original_code:
int gg_rand()
{
  return (int) (next_rand() & 0x7fffffff);
}


decompiled_code:
__int64 gg_urand()
{
return next_rand();
}

canonical_decompiled_code:
__int64 func4()
{
return func1();
}

original_code:
unsigned int
gg_urand(void)
{
  return next_rand();
}

canonical_original_code:
unsigned int gg_urand()
{
  return next_rand();
}


decompiled_code:
double gg_drand()
{
return (double)(int)next_rand() * 2.328306436538696e-10;
}

original_code:
double
gg_drand(void)
{
  return next_rand() * 2.328306436538696e-10;
}

return_type: double


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

for ( i = 0LL; i != 25; ++i )
*(_DWORD *)(a1 + i * 4) = x[i];
result = (unsigned int)k;
*(_DWORD *)(a1 + 100) = k;
return result;
}

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

for ( i = 0LL; i != 25; ++i )
*(_DWORD *)(a1 + i * 4) = x[i];
result = (unsigned int)k;
*(_DWORD *)(a1 + 100) = k;
return result;
}

original_code:
void
gg_get_rand_state(struct gg_rand_state *state)
{
  int i;
  for (i = 0; i < 25; i++)
    state->x[i] = x[i];
  state->k = k;
}

variable_types: struct gg_rand_state { unsigned int x[25]; int k; } *


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

for ( i = 0LL; i != 25; ++i )
x[i] = *(_DWORD *)(a1 + i * 4);
result = *(unsigned int *)(a1 + 100);
k = *(_DWORD *)(a1 + 100);
return result;
}

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

for ( i = 0LL; i != 25; ++i )
x[i] = *(_DWORD *)(a1 + i * 4);
result = *(unsigned int *)(a1 + 100);
k = *(_DWORD *)(a1 + 100);
return result;
}

original_code:
void
gg_set_rand_state(struct gg_rand_state *state)
{
  int i;
  for (i = 0; i < 25; i++)
    x[i] = state->x[i];
  k = state->k;
}

variable_types: i int

user_defined_types: struct gg_rand_state { unsigned int x[25]; int k; }


decompiled_code:
void gg_init_color()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void
gg_init_color()
{
}

canonical_original_code:
void gg_init_color()
{
}


decompiled_code:
int __fastcall write_color_char_no_space(__int64 a1, int a2)
{
return fputc(a2, stderr);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2)
{
return fputc(a2, stderr);
}

original_code:
void
write_color_char_no_space(int c, int x)
{
  fprintf(stderr, "%c", x);
}

variable_types: c int

variable_types: x int


decompiled_code:
int __fastcall write_color_string(unsigned int a1, char *a2)
{
char *v2; // rbx
char v3; // si
int result; // eax

v2 = a2;
v3 = *a2;
if ( v3 )
{
do
{
++v2;
result = write_color_char_no_space(a1, v3);
v3 = *v2;
}
while ( *v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, char *a2)
{
char *v2; // rbx
char v3; // si
int result; // eax

v2 = a2;
v3 = *a2;
if ( v3 )
{
do
{
++v2;
result = func1(a1, v3);
v3 = *v2;
}
while ( *v2 );
}
return result;
}

original_code:
void
write_color_string(int c, const char *str)
{
  while (*str)
    write_color_char_no_space(c, *str++);
}

canonical_original_code:
void write_color_string(int c, char *str)
{
  while (*str)
    write_color_char_no_space(c, *str++);
}

variable_types:
str
char *


decompiled_code:
int __fastcall write_color_char(unsigned int a1, int a2)
{
fputc(32, stderr);
return write_color_char_no_space(a1, a2);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, int a2)
{
fputc(32, stderr);
return func1(a1, a2);
}

original_code:
void
write_color_char(int c, int x)
{
  fprintf(stderr, " ");
  write_color_char_no_space(c, x);
}


decompiled_code:
int __fastcall gg_vsnprintf(char *a1, __int64 a2, const char *a3, void *a4)
{
return vsprintf(a1, a3, a4);
}

canonical_decompiled_code:
int __fastcall func4(char *a1, __int64 a2, const char *a3, void *a4)
{
return vsprintf(a1, a3, a4);
}

original_code:
void
gg_vsnprintf(char *dest, unsigned long len, const char *fmt, va_list args)
{
  (void)len;
  vsprintf(dest, fmt, args);
}

canonical_original_code:
void gg_vsnprintf(char *dest, unsigned long len, char *fmt, __builtin_va_list args)
{
  (void)len;
  vsprintf(dest, fmt, args);
}

variable_types:
dest
char *

variable_types:
len
unsigned long

variable_types:
fmt
char *


decompiled_code:
int gg_snprintf(char *a1, __int64 a2, const char *a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return gg_vsnprintf(a1, a2, a3, va);
}

canonical_decompiled_code:
int func5(char *a1, __int64 a2, const char *a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return func4(a1, a2, a3, va);
}

original_code:
void
gg_snprintf(char *dest, unsigned long len, const char *fmt, ...)
{
  va_list args;
  __builtin_va_start(args,fmt);
  gg_vsnprintf(dest, len, fmt, args);
  __builtin_va_end(args);
}

canonical_original_code:
void gg_snprintf(char *dest, unsigned long len, char *fmt, ...)
{
  __builtin_va_list args;
  __builtin_va_start(args,fmt);
  gg_vsnprintf(dest, len, fmt, args);
  __builtin_va_end(args);
}


decompiled_code:
void *gg_version()
{
return &unk_4A4;
}

canonical_decompiled_code:
void *func6()
{
return &unk_4A4;
}

original_code:
const char *
gg_version(void)
{
  return "3.8";
}

canonical_original_code:
char *gg_version()
{
  return "3.8";
}

return_type: char *


decompiled_code:
float __fastcall gg_normalize_float(float a1, float a2)
{
return (float)(int)((float)(a1 / a2) + 0.5) * a2;
}

canonical_decompiled_code:
float __fastcall func7(float a1, float a2)
{
return (float)(int)((float)(a1 / a2) + 0.5) * a2;
}

original_code:
float
gg_normalize_float(float x, float a)
{
  return a * ((int) (0.5 + x / a));
}

variable_types: x float

variable_types: a float

return_type: float


decompiled_code:
__int64 __fastcall gg_normalize_float2int(float a1, float a2)
{
return (unsigned int)(int)((float)(a1 / a2) + 0.5);
}

canonical_decompiled_code:
__int64 __fastcall func8(float a1, float a2)
{
return (unsigned int)(int)((float)(a1 / a2) + 0.5);
}

original_code:
int
gg_normalize_float2int(float x, float a)
{
  return ((int) (0.5 + x / a));
}


original_code:
void
gg_sort(void *base, size_t nel, size_t width,
 int (*cmp)(const void *, const void *))
{
  int gap = nel;
  int swap_made;
  char *end = (char *) base + width * (nel - 1);
  do {
    char *a, *b;
    swap_made = 0;
    gap = (10 * gap + 3) / 13;
    for (a = base, b = a + gap * width; b <= end; a += width, b += width) {
      if (cmp((void *) a, (void *) b) > 0) {
 char *c = a;
 char *d = b;
 size_t size = width;
 while (size-- > 0) {
   char tmp = *c;
   *c++ = *d;
   *d++ = tmp;
 }
 swap_made = 1;
      }
    }
  } while (gap > 1 || swap_made);
}

canonical_original_code:
void gg_sort(void *base, unsigned long nel, unsigned long width, int (*cmp)(void *, void *))
{
  int gap = nel;
  int swap_made;
  char *end = (char *) base + width * (nel - 1);
  do {
    char *a; char *b;
    swap_made = 0;
    gap = (10 * gap + 3) / 13;
    for (a = base, b = a + gap * width; b <= end; a += width, b += width) {
      if (cmp((void *) a, (void *) b) > 0) {
 char *c = a;
 char *d = b;
 unsigned long size = width;
 while (size-- > 0) {
   char tmp = *c;
   *c++ = *d;
   *d++ = tmp;
 }
 swap_made = 1;
      }
    }
  } while (gap > 1 || swap_made);
}

variable_types:
base
void *

variable_types:
nel
unsigned long

variable_types:
width
unsigned long

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

variable_types: gap int

variable_types:
end
char *

variable_types:
a
char *

variable_types:
b
char *

variable_types:
c
char *

variable_types:
d
char *

variable_types:
size
unsigned long

variable_types: tmp char


decompiled_code:
float __fastcall gg_interpolate(float *a1, float a2)
{
float v2; // xmm2_4
float v3; // xmm3_4
float v5; // xmm0_4

v2 = a1[1];
if ( v2 > a2 )
return a1[3];
v3 = a1[2];
if ( a2 > v3 )
return a1[*(int *)a1 + 3];
v5 = (float)((float)(a2 - v2) * (float)*(int *)a1) / (float)(v3 - v2);
return (float)((float)(1.0 - (float)(v5 - (float)(int)v5)) * a1[(int)v5 + 3])
+ (float)((float)(v5 - (float)(int)v5) * a1[(int)v5 + 4]);
}

canonical_decompiled_code:
float __fastcall func10(float *a1, float a2)
{
float v2; // xmm2_4
float v3; // xmm3_4
float v5; // xmm0_4

v2 = a1[1];
if ( v2 > a2 )
return a1[3];
v3 = a1[2];
if ( a2 > v3 )
return a1[*(int *)a1 + 3];
v5 = (float)((float)(a2 - v2) * (float)*(int *)a1) / (float)(v3 - v2);
return (float)((float)(1.0 - (float)(v5 - (float)(int)v5)) * a1[(int)v5 + 3])
+ (float)((float)(v5 - (float)(int)v5) * a1[(int)v5 + 4]);
}

original_code:
float
gg_interpolate(struct interpolation_data *f, float x)
{
  int i;
  float ratio;
  float diff;
  if (x < f->range_lowerbound)
    return f->values[0];
  else if (x > f->range_upperbound)
    return f->values[f->sections];
  else {
    ratio = ((float) f->sections) * (x - f->range_lowerbound)
              / (f->range_upperbound - f->range_lowerbound);
    i = (int) ratio;
    diff = ratio - ((float) i);
    if (0)
      fprintf(stderr, "Floating point Ratio: %f, integer: %d, diff %f",
       ratio, i, diff);
    return ((1 - diff) * f->values[i] + diff * f->values[i+1]);
  }
}

variable_types: struct interpolation_data { int sections; float range_lowerbound; float range_upperbound; float values[-1]; } *

variable_types: i int

variable_types: ratio float

variable_types: diff float


original_code:
float
soft_cap(float a, float b)
{
  return ((a * b) / (a + b));
}

variable_types: a float

variable_types: b float


rotate

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

if ( a5 <= 0 )
_assert_fail("bs > 0", "mgg_utils.c", 0x1AFu, "rotate");
if ( !a3 || !a4 )
_assert_fail("ri != NULL && rj != NULL", "mgg_utils.c", 0x1B0u, "rotate");
if ( a6 > 7 )
_assert_fail("rot >= 0 && rot < 8", "mgg_utils.c", 0x1B1u, "rotate");
result = a2 & (unsigned int)a1;
if ( (_DWORD)result == -1 )
{
*a3 = a1;
*a4 = a2;
}
else
{
if ( a1 < 0 || a5 <= a1 )
_assert_fail("i >= 0 && i < bs", "mgg_utils.c", 0x1B9u, "rotate");
if ( a2 < 0 || a5 <= a2 )
_assert_fail("j >= 0 && j < bs", "mgg_utils.c", 0x1BAu, "rotate");
if ( a6 )
{
v7 = a5 - 1;
switch ( a6 )
{
case 1u:
*a3 = v7 - a2;
*a4 = a1;
break;
case 2u:
result = (unsigned int)(v7 - a1);
*a3 = result;
*a4 = v7 - a2;
break;
case 3u:
*a3 = a2;
*a4 = v7 - a1;
break;
case 4u:
*a3 = a2;
*a4 = a1;
break;
case 5u:
*a3 = v7 - a1;
*a4 = a2;
break;
case 6u:
result = (unsigned int)(v7 - a2);
*a3 = result;
*a4 = v7 - a1;
break;
default:
*a3 = a1;
*a4 = v7 - a2;
break;
}
}
else
{
*a3 = a1;
*a4 = a2;
}
}
return result;
}

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

if ( a5 <= 0 )
_assert_fail("bs > 0", "mgg_utils.c", 0x1AFu, "rotate");
if ( !a3 || !a4 )
_assert_fail("ri != NULL && rj != NULL", "mgg_utils.c", 0x1B0u, "rotate");
if ( a6 > 7 )
_assert_fail("rot >= 0 && rot < 8", "mgg_utils.c", 0x1B1u, "rotate");
result = a2 & (unsigned int)a1;
if ( (_DWORD)result == -1 )
{
*a3 = a1;
*a4 = a2;
}
else
{
if ( a1 < 0 || a5 <= a1 )
_assert_fail("i >= 0 && i < bs", "mgg_utils.c", 0x1B9u, "rotate");
if ( a2 < 0 || a5 <= a2 )
_assert_fail("j >= 0 && j < bs", "mgg_utils.c", 0x1BAu, "rotate");
if ( a6 )
{
v7 = a5 - 1;
switch ( a6 )
{
case 1u:
*a3 = v7 - a2;
*a4 = a1;
break;
case 2u:
result = (unsigned int)(v7 - a1);
*a3 = result;
*a4 = v7 - a2;
break;
case 3u:
*a3 = a2;
*a4 = v7 - a1;
break;
case 4u:
*a3 = a2;
*a4 = a1;
break;
case 5u:
*a3 = v7 - a1;
*a4 = a2;
break;
case 6u:
result = (unsigned int)(v7 - a2);
*a3 = result;
*a4 = v7 - a1;
break;
default:
*a3 = a1;
*a4 = v7 - a2;
break;
}
}
else
{
*a3 = a1;
*a4 = a2;
}
}
return result;
}

original_code:
void
rotate(int i, int j, int *ri, int *rj, int bs, int rot)
{
  int bs1;
  ((void) sizeof ((bs > 0) ? 1 : 0), __extension__ ({ if (bs > 0) ; else __assert_fail ("bs > 0", "mgg_utils.c", 431, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((ri != ((void *)0) && rj != ((void *)0)) ? 1 : 0), __extension__ ({ if (ri != ((void *)0) && rj != ((void *)0)) ; else __assert_fail ("ri != NULL && rj != NULL", "mgg_utils.c", 432, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((rot >= 0 && rot < 8) ? 1 : 0), __extension__ ({ if (rot >= 0 && rot < 8) ; else __assert_fail ("rot >= 0 && rot < 8", "mgg_utils.c", 433, __extension__ __PRETTY_FUNCTION__); }));
  if (i == -1 && j == -1) {
    *ri = i;
    *rj = j;
    return;
  }
  ((void) sizeof ((i >= 0 && i < bs) ? 1 : 0), __extension__ ({ if (i >= 0 && i < bs) ; else __assert_fail ("i >= 0 && i < bs", "mgg_utils.c", 441, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((j >= 0 && j < bs) ? 1 : 0), __extension__ ({ if (j >= 0 && j < bs) ; else __assert_fail ("j >= 0 && j < bs", "mgg_utils.c", 442, __extension__ __PRETTY_FUNCTION__); }));
  bs1 = bs - 1;
  if (rot == 0) {
    *ri = i;
    *rj = j;
  }
  else if (rot == 1) {
    *ri = bs1 - j;
    *rj = i;
  }
  else if (rot == 2) {
    *ri = bs1 - i;
    *rj = bs1 - j;
  }
  else if (rot == 3) {
    *ri = j;
    *rj = bs1 - i;
  }
  else if (rot == 4) {
    *ri = j;
    *rj = i;
  }
  else if (rot == 5) {
    *ri = bs1 - i;
    *rj = j;
  }
  else if (rot == 6) {
    *ri = bs1 - j;
    *rj = bs1 - i;
  }
  else if (rot == 7) {
    *ri = i;
    *rj = bs1 - j;
  }
}

variable_types: j int

variable_types:
ri
int *

variable_types:
rj
int *

variable_types: bs int

variable_types: rot int


decompiled_code:
__int64 __fastcall inv_rotate(int a1, int a2, int *a3, int *a4, int a5, unsigned int a6)
{
if ( a6 == 1 )
return rotate(a1, a2, a3, a4, a5, 3u);
if ( a6 == 3 )
return rotate(a1, a2, a3, a4, a5, 1u);
return rotate(a1, a2, a3, a4, a5, a6);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, int a2, int *a3, int *a4, int a5, unsigned int a6)
{
if ( a6 == 1 )
return func12(a1, a2, a3, a4, a5, 3u);
if ( a6 == 3 )
return func12(a1, a2, a3, a4, a5, 1u);
return func12(a1, a2, a3, a4, a5, a6);
}

original_code:
void
inv_rotate(int i, int j, int *ri, int *rj, int bs, int rot)
{
  if (rot == 1)
    rotate(i, j, ri, rj, bs, 3);
  else if (rot == 3)
    rotate(i, j, ri, rj, bs, 1);
  else
    rotate(i, j, ri, rj, bs, rot);
}


decompiled_code:
__int64 get_random_seed()
{
return (unsigned int)random_seed;
}

canonical_decompiled_code:
__int64 func14()
{
return (unsigned int)random_seed;
}

original_code:
unsigned int
get_random_seed()
{
  return random_seed;
}


decompiled_code:
__int64 __fastcall set_random_seed(int a1)
{
random_seed = a1;
return gg_srand();
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
random_seed = a1;
return gg_srand();
}

original_code:
void
set_random_seed(unsigned int seed)
{
  random_seed = seed;
  gg_srand(seed);
}

variable_types:
seed
unsigned int


decompiled_code:
__int64 update_random_seed()
{
unsigned int v0; // eax
__int64 v1; // rdi

gg_srand((unsigned int)random_seed);
v0 = gg_rand();
v1 = 1LL;
if ( v0 )
v1 = v0;
random_seed = v1;
return gg_srand(v1);
}

canonical_decompiled_code:
__int64 func16()
{
unsigned int v0; // eax
__int64 v1; // rdi

gg_srand((unsigned int)random_seed);
v0 = gg_rand();
v1 = 1LL;
if ( v0 )
v1 = v0;
random_seed = v1;
return gg_srand(v1);
}

original_code:
void
update_random_seed(void)
{
  gg_srand(random_seed);
  random_seed = gg_rand();
  if (random_seed == 0)
    random_seed = 1;
  gg_srand(random_seed);
}

canonical_original_code:
void update_random_seed()
{
  gg_srand(random_seed);
  random_seed = gg_rand();
  if (random_seed == 0)
    random_seed = 1;
  gg_srand(random_seed);
}


decompiled_code:
__int64 reuse_random_seed()
{
return gg_srand((unsigned int)random_seed);
}

canonical_decompiled_code:
__int64 func17()
{
return gg_srand((unsigned int)random_seed);
}

original_code:
void
reuse_random_seed()
{
  gg_srand(random_seed);
}


decompiled_code:
__int64 __fastcall place_fixed_handicap(int a1)
{
int v1; // er13
int v2; // er12
int v3; // ebp
int v5; // eax
int v6; // edx
__int64 v7; // rbx

v1 = (board_size > 11) + 2;
if ( a1 > 1 )
{
v2 = board_size / 2;
if ( board_size % 2 == 1 && board_size > 8 )
{
v3 = 9;
if ( a1 <= 9 )
v3 = a1;
handicap = v3;
if ( (a1 & 0xFFFFFFFD) != 5 )
goto LABEL_29;
}
else if ( board_size > 6 )
{
v3 = 4;
if ( a1 <= 4 )
v3 = a1;
handicap = v3;
if ( (a1 & 0xFFFFFFFD) != 5 )
goto LABEL_29;
}
else
{
v3 = 0;
handicap = 0;
if ( (a1 & 0xFFFFFFFD) != 5 )
return handicap;
}
add_stone((unsigned int)(21 * v2 + 21), 2LL);
if ( --v3 <= 0 )
return handicap;
LABEL_29:
v7 = 0LL;
do
{
v5 = places[2 * v7];
v6 = dword_1E4[2 * v7];
if ( v5 == 2 )
{
v5 = v1;
}
else if ( v5 )
{
if ( v5 == -2 )
v5 = board_size + ~v1;
}
else
{
v5 = v2;
}
if ( v6 == 2 )
{
v6 = v1;
}
else if ( v6 )
{
if ( v6 == -2 )
v6 = board_size + ~v1;
}
else
{
v6 = v2;
}
add_stone((unsigned int)(v6 + 20 * v5 + 21), 2LL);
++v7;
}
while ( v3 > (int)v7 );
return handicap;
}
handicap = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // er13
int v2; // er12
int v3; // ebp
int v5; // eax
int v6; // edx
__int64 v7; // rbx

v1 = (board_size > 11) + 2;
if ( a1 > 1 )
{
v2 = board_size / 2;
if ( board_size % 2 == 1 && board_size > 8 )
{
v3 = 9;
if ( a1 <= 9 )
v3 = a1;
handicap = v3;
if ( (a1 & 0xFFFFFFFD) != 5 )
goto LABEL_29;
}
else if ( board_size > 6 )
{
v3 = 4;
if ( a1 <= 4 )
v3 = a1;
handicap = v3;
if ( (a1 & 0xFFFFFFFD) != 5 )
goto LABEL_29;
}
else
{
v3 = 0;
handicap = 0;
if ( (a1 & 0xFFFFFFFD) != 5 )
return handicap;
}
add_stone((unsigned int)(21 * v2 + 21), 2LL);
if ( --v3 <= 0 )
return handicap;
LABEL_29:
v7 = 0LL;
do
{
v5 = places[2 * v7];
v6 = dword_1E4[2 * v7];
if ( v5 == 2 )
{
v5 = v1;
}
else if ( v5 )
{
if ( v5 == -2 )
v5 = board_size + ~v1;
}
else
{
v5 = v2;
}
if ( v6 == 2 )
{
v6 = v1;
}
else if ( v6 )
{
if ( v6 == -2 )
v6 = board_size + ~v1;
}
else
{
v6 = v2;
}
add_stone((unsigned int)(v6 + 20 * v5 + 21), 2LL);
++v7;
}
while ( v3 > (int)v7 );
return handicap;
}
handicap = 0;
return 0LL;
}

original_code:
int
place_fixed_handicap(int desired_handicap)
{
  int r;
  int max_handicap;
  int remaining_stones;
  int three = board_size > 11 ? 3 : 2;
  int mid = board_size/2;
  if (desired_handicap < 2) {
    handicap = 0;
    return 0;
  }
  if ((board_size % 2 == 1) && (board_size >= 9))
    max_handicap = 9;
  else if (board_size >= 7)
    max_handicap = 4;
  else
    max_handicap = 0;
  if (desired_handicap > max_handicap)
    handicap = max_handicap;
  else
    handicap = desired_handicap;
  remaining_stones = handicap;
  if (desired_handicap == 5 || desired_handicap == 7) {
    add_stone(((19 + 2) + (mid) * (19 + 1) + (mid)), BLACK);
    remaining_stones--;
  }
  for (r = 0; r < remaining_stones; r++) {
    int i = places[r][0];
    int j = places[r][1];
    if (i == 2)
      i = three;
    else if (i == 0)
      i = mid;
    else if (i == -2)
      i = board_size - 1 - three;
    if (j == 2)
      j = three;
    else if (j == 0)
      j = mid;
    else if (j == -2)
      j = board_size - 1 - three;
    add_stone(((19 + 2) + (i) * (19 + 1) + (j)), BLACK);
  }
  return handicap;
}

variable_types: r int

variable_types: three int

variable_types: mid int


decompiled_code:
__int64 free_handicap_remaining_stones()
{
abortgo("mhandicap.c", 430LL, "remaining_handicap_stones >= 0", 0LL);
return free_handicap_total_stones();
}

canonical_decompiled_code:
__int64 func1()
{
abortgo("mhandicap.c", 430LL, "remaining_handicap_stones >= 0", 0LL);
return func2();
}

original_code:
int
free_handicap_remaining_stones()
{
  if (remaining_handicap_stones >= 0) ; else abortgo("mhandicap.c", 430, "remaining_handicap_stones >= 0", 0);
  return remaining_handicap_stones;
}


decompiled_code:
void free_handicap_total_stones()
{
abortgo("mhandicap.c", 437LL, "total_handicap_stones >= 0", 0LL);
JUMPOUT(0x195LL);
}

canonical_decompiled_code:
void func2()
{
abortgo("mhandicap.c", 437LL, "total_handicap_stones >= 0", 0LL);
JUMPOUT(0x195LL);
}

original_code:
int
free_handicap_total_stones()
{
  if (total_handicap_stones >= 0) ; else abortgo("mhandicap.c", 437, "total_handicap_stones >= 0", 0);
  return total_handicap_stones;
}


repo: bambreeze/sandbox

decompiled_code:
void __fastcall __noreturn workerer_thread(void *a1)
{
int v1; // ecx
__int64 v2; // rdx
unsigned int *v3; // rbp
int v4; // eax
char *v5; // rax
char *v6; // rax
int v7; // eax
__int64 v8; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

time(&timer);
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock((pthread_mutex_t *)a1 + 5);
v7 = *((_DWORD *)a1 + 2);
if ( v7 )
break;
pthread_mutex_unlock((pthread_mutex_t *)a1 + 5);
v8 = syscall(186LL);
printf("[pid %d] no req...\n", v8);
sleep(1u);
}
v1 = *((_DWORD *)a1 + 1);
v2 = v1 + 2LL;
v3 = (unsigned int *)*((_QWORD *)a1 + v2);
*((_DWORD *)a1 + 2) = v7 - 1;
*((_QWORD *)a1 + v2) = 0LL;
v4 = v1 + 1;
if ( v1 == 15 )
v4 = 0;
*((_DWORD *)a1 + 1) = v4;
puts("\nprocessing...");
printf(" req->is_v4: %d\n", *v3);
printf(" req->is_add: %d\n", v3[1]);
printf(" req->interface: 0x%08x\n", v3[2]);
puts("processing done\n");
time(&timer);
v5 = ctime(&timer);
printf("before cond wait - %s", v5);
*((_DWORD *)a1 + 36) = 1;
pthread_cond_wait((pthread_cond_t *)((char *)a1 + 152), (pthread_mutex_t *)a1 + 5);
*((_DWORD *)a1 + 36) = 0;
time(&timer);
v6 = ctime(&timer);
printf("after cond wait - %s", v6);
printf("\n <== free req ... interface: 0x%08x\n\n", v3[2]);
free(v3);
pthread_mutex_unlock((pthread_mutex_t *)a1 + 5);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // ecx
__int64 v2; // rdx
unsigned int *v3; // rbp
int v4; // eax
char *v5; // rax
char *v6; // rax
int v7; // eax
__int64 v8; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

time(&timer);
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock((pthread_mutex_t *)a1 + 5);
v7 = *((_DWORD *)a1 + 2);
if ( v7 )
break;
pthread_mutex_unlock((pthread_mutex_t *)a1 + 5);
v8 = syscall(186LL);
printf("[pid %d] no req...\n", v8);
sleep(1u);
}
v1 = *((_DWORD *)a1 + 1);
v2 = v1 + 2LL;
v3 = (unsigned int *)*((_QWORD *)a1 + v2);
*((_DWORD *)a1 + 2) = v7 - 1;
*((_QWORD *)a1 + v2) = 0LL;
v4 = v1 + 1;
if ( v1 == 15 )
v4 = 0;
*((_DWORD *)a1 + 1) = v4;
puts("\nprocessing...");
printf(" req->is_v4: %d\n", *v3);
printf(" req->is_add: %d\n", v3[1]);
printf(" req->interface: 0x%08x\n", v3[2]);
puts("processing done\n");
time(&timer);
v5 = ctime(&timer);
printf("before cond wait - %s", v5);
*((_DWORD *)a1 + 36) = 1;
pthread_cond_wait((pthread_cond_t *)((char *)a1 + 152), (pthread_mutex_t *)a1 + 5);
*((_DWORD *)a1 + 36) = 0;
time(&timer);
v6 = ctime(&timer);
printf("after cond wait - %s", v6);
printf("\n <== free req ... interface: 0x%08x\n\n", v3[2]);
free(v3);
pthread_mutex_unlock((pthread_mutex_t *)a1 + 5);
}
}

original_code:
void *workerer_thread(void *arg)
{
    req_queue *queue = ((void *)0);
    req_entry *req = ((void *)0);
    time_t t;
    time(&t);
    queue = arg;
    while (1) {
        pthread_mutex_lock(&queue->mutex);
        if (queue->counter) {
            req = queue->entry[queue->out];
            queue->counter--;
            queue->entry[queue->out] = ((void *)0);
            queue->out++;
            if (queue->out == 16) {
                queue->out = 0;
            }
            printf("\nprocessing...\n");
            printf("  req->is_v4: %d\n", req->is_v4);
            printf("  req->is_add: %d\n", req->is_add);
            printf("  req->interface: 0x%08x\n", req->interface);
            printf("processing done\n\n");
            time(&t);
            printf("before cond wait - %s", ctime(&t));
            queue->waiting = 1;
            pthread_cond_wait(&queue->cond, &queue->mutex);
            queue->waiting = 0;
            time(&t);
            printf("after cond wait - %s", ctime(&t));
            printf("\n  <== free req ... interface: 0x%08x\n\n", req->interface);
            free(req);
            req = ((void *)0);
            pthread_mutex_unlock(&queue->mutex);
        } else {
            pthread_mutex_unlock(&queue->mutex);
            printf("[pid %d] no req...\n", (int) syscall(186));
            sleep(1);
        }
    }
}

canonical_original_code:
void *workerer_thread(void *arg)
{
    struct _req_queue *queue = ((void *)0);
    struct _req_entry *req = ((void *)0);
    long t;
    time(&t);
    queue = arg;
    while (1) {
        pthread_mutex_lock(&queue->mutex);
        if (queue->counter) {
            req = queue->entry[queue->out];
            queue->counter--;
            queue->entry[queue->out] = ((void *)0);
            queue->out++;
            if (queue->out == 16) {
                queue->out = 0;
            }
            printf("\nprocessing...\n");
            printf("  req->is_v4: %d\n", req->is_v4);
            printf("  req->is_add: %d\n", req->is_add);
            printf("  req->interface: 0x%08x\n", req->interface);
            printf("processing done\n\n");
            time(&t);
            printf("before cond wait - %s", ctime(&t));
            queue->waiting = 1;
            pthread_cond_wait(&queue->cond, &queue->mutex);
            queue->waiting = 0;
            time(&t);
            printf("after cond wait - %s", ctime(&t));
            printf("\n  <== free req ... interface: 0x%08x\n\n", req->interface);
            free(req);
            req = ((void *)0);
            pthread_mutex_unlock(&queue->mutex);
        } else {
            pthread_mutex_unlock(&queue->mutex);
            printf("[pid %d] no req...\n", (int) syscall(186));
            sleep(1);
        }
    }
}

variable_types:
arg
void *

variable_types: struct _req_queue { int in; int out; int counter; struct _req_entry { int is_v4; int is_add; int interface; } *entry[16]; int waiting; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *

variable_types: t long

return_type: void *

user_defined_types: struct _req_queue { int in; int out; int counter; struct _req_entry *entry[16]; int waiting; union pthread_cond_t cond; union pthread_mutex_t mutex; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

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

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


decompiled_code:
void __fastcall __noreturn notifier_thread(void *a1)
{
unsigned int v1; // eax
char *v2; // rax
char *v3; // rax
int v4; // eax
__int64 v5; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

v1 = time(&timer);
srand(v1);
while ( 1 )
{
v4 = rand();
sleep(v4 % 2);
pthread_mutex_lock((pthread_mutex_t *)a1 + 5);
if ( *((_DWORD *)a1 + 36) )
{
time(&timer);
v2 = ctime(&timer);
printf("before cond signal - %s", v2);
pthread_cond_signal((pthread_cond_t *)((char *)a1 + 152));
time(&timer);
v3 = ctime(&timer);
printf("after cond signal - %s", v3);
pthread_mutex_unlock((pthread_mutex_t *)a1 + 5);
}
else
{
pthread_mutex_unlock((pthread_mutex_t *)a1 + 5);
v5 = syscall(186LL);
printf("[pid %d] no pending...\n", v5);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
unsigned int v1; // eax
char *v2; // rax
char *v3; // rax
int v4; // eax
__int64 v5; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

v1 = time(&timer);
srand(v1);
while ( 1 )
{
v4 = rand();
sleep(v4 % 2);
pthread_mutex_lock((pthread_mutex_t *)a1 + 5);
if ( *((_DWORD *)a1 + 36) )
{
time(&timer);
v2 = ctime(&timer);
printf("before cond signal - %s", v2);
pthread_cond_signal((pthread_cond_t *)((char *)a1 + 152));
time(&timer);
v3 = ctime(&timer);
printf("after cond signal - %s", v3);
pthread_mutex_unlock((pthread_mutex_t *)a1 + 5);
}
else
{
pthread_mutex_unlock((pthread_mutex_t *)a1 + 5);
v5 = syscall(186LL);
printf("[pid %d] no pending...\n", v5);
}
}
}

original_code:
void *notifier_thread(void * arg)
{
    req_queue *queue = ((void *)0);
    time_t t;
    srand((unsigned) time(&t));
    queue = arg;
    while (1) {
        sleep((rand() % 2));
        pthread_mutex_lock(&queue->mutex);
        if (queue->waiting) {
            time(&t);
            printf("before cond signal - %s", ctime(&t));
            pthread_cond_signal(&queue->cond);
            time(&t);
            printf("after cond signal - %s", ctime(&t));
            pthread_mutex_unlock(&queue->mutex);
        } else {
            pthread_mutex_unlock(&queue->mutex);
            printf("[pid %d] no pending...\n", (int) syscall(186));
        }
    }
}

canonical_original_code:
void *notifier_thread(void *arg)
{
    struct _req_queue *queue = ((void *)0);
    long t;
    srand((unsigned int) time(&t));
    queue = arg;
    while (1) {
        sleep((rand() % 2));
        pthread_mutex_lock(&queue->mutex);
        if (queue->waiting) {
            time(&t);
            printf("before cond signal - %s", ctime(&t));
            pthread_cond_signal(&queue->cond);
            time(&t);
            printf("after cond signal - %s", ctime(&t));
            pthread_mutex_unlock(&queue->mutex);
        } else {
            pthread_mutex_unlock(&queue->mutex);
            printf("[pid %d] no pending...\n", (int) syscall(186));
        }
    }
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct _req_entry { int is_v4; int is_add; int interface; }

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


decompiled_code:
__int64 __fastcall add_req(pthread_mutex_t *a1, int a2, int a3, int a4)
{
_DWORD *v6; // rax
_DWORD *v7; // rbp
int v8; // edx
int v9; // eax
__int64 result; // rax

if ( a1->__owner == 16 )
{
puts("\n!!! req-queue is full, will discard req !!!");
result = 1LL;
}
else
{
v6 = malloc(0xCuLL);
v7 = v6;
if ( !v6 )
{
puts("malloc req failed");
exit(1);
}
*v6 = a2;
v6[1] = a3;
v6[2] = a4;
pthread_mutex_lock(a1 + 5);
v8 = a1->__lock;
*(_QWORD *)&a1->__size[8 * a1->__lock + 16] = v7;
++a1->__owner;
v9 = v8 + 1;
if ( v8 == 15 )
v9 = 0;
a1->__lock = v9;
pthread_mutex_unlock(a1 + 5);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(pthread_mutex_t *a1, int a2, int a3, int a4)
{
_DWORD *v6; // rax
_DWORD *v7; // rbp
int v8; // edx
int v9; // eax
__int64 result; // rax

if ( a1->__owner == 16 )
{
puts("\n!!! req-queue is full, will discard req !!!");
result = 1LL;
}
else
{
v6 = malloc(0xCuLL);
v7 = v6;
if ( !v6 )
{
puts("malloc req failed");
exit(1);
}
*v6 = a2;
v6[1] = a3;
v6[2] = a4;
pthread_mutex_lock(a1 + 5);
v8 = a1->__lock;
*(_QWORD *)&a1->__size[8 * a1->__lock + 16] = v7;
++a1->__owner;
v9 = v8 + 1;
if ( v8 == 15 )
v9 = 0;
a1->__lock = v9;
pthread_mutex_unlock(a1 + 5);
result = 0LL;
}
return result;
}

original_code:
int add_req(req_queue *queue, int is_v4, int is_add, int interface)
{
    req_entry *req = ((void *)0);
    if (queue->counter == 16) {
        printf("\n!!! req-queue is full, will discard req !!!\n");
        return 1;
    }
    req = malloc(sizeof(req_entry));
    if (!req) {
        printf("malloc req failed\n");
        exit(1);
    }
    req->is_v4 = is_v4;
    req->is_add = is_add;
    req->interface = interface;
    pthread_mutex_lock(&queue->mutex);
    queue->entry[queue->in] = req;
    queue->counter++;
    queue->in++;
    if (queue->in == 16) {
        queue->in = 0;
    }
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

canonical_original_code:
int add_req(struct _req_queue *queue, int is_v4, int is_add, int interface)
{
    struct _req_entry *req = ((void *)0);
    if (queue->counter == 16) {
        printf("\n!!! req-queue is full, will discard req !!!\n");
        return 1;
    }
    req = malloc(sizeof(req_entry));
    if (!req) {
        printf("malloc req failed\n");
        exit(1);
    }
    req->is_v4 = is_v4;
    req->is_add = is_add;
    req->interface = interface;
    pthread_mutex_lock(&queue->mutex);
    queue->entry[queue->in] = req;
    queue->counter++;
    queue->in++;
    if (queue->in == 16) {
        queue->in = 0;
    }
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

variable_types: interface int

variable_types: struct _req_entry { int is_v4; int is_add; int interface; } *


decompiled_code:
void handler2()
{
unsigned int v0; // ebx

v0 = global_interface++;
printf("\n ==> ipv4, del, interface: 0x%08x\n", v0);
add_req((pthread_mutex_t *)global_req_queue, 1, 0, v0);
}

canonical_decompiled_code:
void func11()
{
unsigned int v0; // ebx

v0 = global_interface++;
printf("\n ==> ipv4, del, interface: 0x%08x\n", v0);
func9((pthread_mutex_t *)global_req_queue, 1, 0, v0);
}

original_code:
void handler2(int signo)
{
    int interface = 0;
    interface = global_interface;
    global_interface++;
    printf("\n  ==> ipv4, del, interface: 0x%08x\n", interface);
    add_req(global_req_queue, 1, 0, interface);
}

variable_types: signo int


decompiled_code:
void handler3()
{
unsigned int v0; // ebx

v0 = global_interface++;
printf("\n ==> ipv6, add, interface: 0x%08x\n", v0);
add_req((pthread_mutex_t *)global_req_queue, 0, 1, v0);
}

canonical_decompiled_code:
void func12()
{
unsigned int v0; // ebx

v0 = global_interface++;
printf("\n ==> ipv6, add, interface: 0x%08x\n", v0);
func9((pthread_mutex_t *)global_req_queue, 0, 1, v0);
}

original_code:
void handler3(int signo)
{
    int interface = 0;
    interface = global_interface;
    global_interface++;
    printf("\n  ==> ipv6, add, interface: 0x%08x\n", interface);
    add_req(global_req_queue, 0, 1, interface);
}


decompiled_code:
void handler4()
{
unsigned int v0; // ebx

v0 = global_interface++;
printf("\n ==> ipv6, del, interface: 0x%08x\n", v0);
add_req((pthread_mutex_t *)global_req_queue, 0, 0, v0);
}

canonical_decompiled_code:
void func13()
{
unsigned int v0; // ebx

v0 = global_interface++;
printf("\n ==> ipv6, del, interface: 0x%08x\n", v0);
func9((pthread_mutex_t *)global_req_queue, 0, 0, v0);
}

original_code:
void handler4(int signo)
{
    int interface = 0;
    interface = global_interface;
    global_interface++;
    printf("\n  ==> ipv6, del, interface: 0x%08x\n", interface);
    add_req(global_req_queue, 0, 0, interface);
}


decompiled_code:
void handler1()
{
unsigned int v0; // ebx

v0 = global_interface++;
printf("\n ==> ipv4, add, interface: 0x%08x\n", v0);
add_req((pthread_mutex_t *)global_req_queue, 1, 1, v0);
}

canonical_decompiled_code:
void func10()
{
unsigned int v0; // ebx

v0 = global_interface++;
printf("\n ==> ipv4, add, interface: 0x%08x\n", v0);
func9((pthread_mutex_t *)global_req_queue, 1, 1, v0);
}

original_code:
void handler1(int signo)
{
    int interface = 0;
    interface = global_interface;
    global_interface++;
    printf("\n  ==> ipv4, add, interface: 0x%08x\n", interface);
    add_req(global_req_queue, 1, 1, interface);
}


decompiled_code:
int __fastcall init_queue(__int64 a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)(a1 + 16);
do
*v1++ = 0LL;
while ( v1 != (_QWORD *)(a1 + 144) );
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 144) = 0;
pthread_mutex_init((pthread_mutex_t *)(a1 + 200), 0LL);
return pthread_cond_init((pthread_cond_t *)(a1 + 152), 0LL);
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)(a1 + 16);
do
*v1++ = 0LL;
while ( v1 != (_QWORD *)(a1 + 144) );
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 144) = 0;
pthread_mutex_init((pthread_mutex_t *)(a1 + 200), 0LL);
return pthread_cond_init((pthread_cond_t *)(a1 + 152), 0LL);
}

original_code:
void init_queue(req_queue *queue)
{
    int i = 0;
    for (i = 0; i < 16; i++) {
        queue->entry[i] = ((void *)0);
    }
    queue->in = 0;
    queue->out = 0;
    queue->counter = 0;
    queue->waiting = 0;
    pthread_mutex_init(&queue->mutex, ((void *)0));
    pthread_cond_init(&queue->cond, ((void *)0));
}

canonical_original_code:
void init_queue(struct _req_queue *queue)
{
    int i = 0;
    for (i = 0; i < 16; i++) {
        queue->entry[i] = ((void *)0);
    }
    queue->in = 0;
    queue->out = 0;
    queue->counter = 0;
    queue->waiting = 0;
    pthread_mutex_init(&queue->mutex, ((void *)0));
    pthread_cond_init(&queue->cond, ((void *)0));
}

variable_types: i int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rdi
__int64 v4; // rax
__int64 v5; // rax
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( signal(3, (__sighandler_t)handler1) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
if ( signal(4, (__sighandler_t)handler2) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
if ( signal(5, (__sighandler_t)handler3) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
if ( signal(6, (__sighandler_t)handler4) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
v3 = malloc(0xF0uLL);
global_req_queue = v3;
if ( !v3 )
{
puts("malloc queue failed");
exit(1);
}
init_queue((__int64)v3);
if ( pthread_create(newthread, 0LL, (void *(*)(void *))workerer_thread, global_req_queue) )
{
puts("Creating worker thread failed.");
exit(1);
}
if ( pthread_create(&th, 0LL, (void *(*)(void *))notifier_thread, global_req_queue) )
{
puts("Creating notifier thread failed.");
exit(1);
}
v4 = syscall(186LL);
printf("[pid %d] main(), waiting for thread join...\n", v4);
pthread_join(newthread[0], 0LL);
pthread_join(th, 0LL);
v5 = syscall(186LL);
printf("[pid %d] main(), thread join done\n", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rdi
__int64 v4; // rax
__int64 v5; // rax
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( signal(3, (__sighandler_t)handler1) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
if ( signal(4, (__sighandler_t)handler2) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
if ( signal(5, (__sighandler_t)handler3) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
if ( signal(6, (__sighandler_t)handler4) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
v3 = malloc(0xF0uLL);
global_req_queue = v3;
if ( !v3 )
{
puts("malloc queue failed");
exit(1);
}
func14((__int64)v3);
if ( pthread_create(newthread, 0LL, (void *(*)(void *))workerer_thread, global_req_queue) )
{
puts("Creating worker thread failed.");
exit(1);
}
if ( pthread_create(&th, 0LL, (void *(*)(void *))notifier_thread, global_req_queue) )
{
puts("Creating notifier thread failed.");
exit(1);
}
v4 = syscall(186LL);
printf("[pid %d] main(), waiting for thread join...\n", v4);
pthread_join(newthread[0], 0LL);
pthread_join(th, 0LL);
v5 = syscall(186LL);
printf("[pid %d] main(), thread join done\n", v5);
return 0;
}

original_code:
int main()
{
    int rc = 0;
    if (signal(3, handler1) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    if (signal(4, handler2) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    if (signal(5, handler3) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    if (signal(6, handler4) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    global_req_queue = malloc(sizeof(req_queue));
    if (!global_req_queue) {
        printf("malloc queue failed\n");
        exit(1);
    }
    init_queue(global_req_queue);
    pthread_t worker;
    if (pthread_create(&worker, ((void *)0), workerer_thread, global_req_queue) != 0) {
        printf("Creating worker thread failed.\n");
        exit(1);
    }
    pthread_t notifier;
    if (pthread_create(&notifier, ((void *)0), notifier_thread, global_req_queue) != 0) {
        printf("Creating notifier thread failed.\n");
        exit(1);
    }
    printf("[pid %d] main(), waiting for thread join...\n", (int) syscall(186));
    pthread_join(worker, ((void *)0));
    pthread_join(notifier, ((void *)0));
    printf("[pid %d] main(), thread join done\n", (int) syscall(186));
    return 0;
}

canonical_original_code:
int main()
{
    int rc = 0;
    if (signal(3, handler1) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    if (signal(4, handler2) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    if (signal(5, handler3) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    if (signal(6, handler4) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    global_req_queue = malloc(sizeof(req_queue));
    if (!global_req_queue) {
        printf("malloc queue failed\n");
        exit(1);
    }
    init_queue(global_req_queue);
    unsigned long worker;
    if (pthread_create(&worker, ((void *)0), workerer_thread, global_req_queue) != 0) {
        printf("Creating worker thread failed.\n");
        exit(1);
    }
    unsigned long notifier;
    if (pthread_create(&notifier, ((void *)0), notifier_thread, global_req_queue) != 0) {
        printf("Creating notifier thread failed.\n");
        exit(1);
    }
    printf("[pid %d] main(), waiting for thread join...\n", (int) syscall(186));
    pthread_join(worker, ((void *)0));
    pthread_join(notifier, ((void *)0));
    printf("[pid %d] main(), thread join done\n", (int) syscall(186));
    return 0;
}

variable_types: rc int

variable_types:
worker
unsigned long

variable_types:
notifier
unsigned long


decompiled_code:
void __fastcall __noreturn worker_thread(void *a1)
{
int v1; // edx
__int64 v2; // rax
unsigned int *v3; // rbp
int v4; // eax
unsigned int v5; // eax
int v6; // ebp
__int64 v7; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

time(&timer);
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 2064));
v6 = *((_DWORD *)a1 + 2);
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 2064));
if ( v6 )
break;
v7 = syscall(186LL);
printf("[pid %d] no pending command...\n", v7);
sleep(1u);
}
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 2064));
v1 = *((_DWORD *)a1 + 1);
v2 = v1 + 2LL;
v3 = (unsigned int *)*((_QWORD *)a1 + v2);
--*((_DWORD *)a1 + 2);
*((_QWORD *)a1 + v2) = 0LL;
v4 = v1 + 1;
if ( v1 == 255 )
v4 = 0;
*((_DWORD *)a1 + 1) = v4;
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 2064));
puts("\nexecute commands...");
printf(" cmd->interface: 0x%08x\n", *v3);
printf(" cmd->cmd: %s\n", (const char *)v3 + 4);
v5 = system((const char *)v3 + 4);
printf("done, return %d\n\n", v5);
printf("\n <== free cmd ... interface: 0x%08x\n\n", *v3);
free(v3);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // edx
__int64 v2; // rax
unsigned int *v3; // rbp
int v4; // eax
unsigned int v5; // eax
int v6; // ebp
__int64 v7; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

time(&timer);
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 2064));
v6 = *((_DWORD *)a1 + 2);
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 2064));
if ( v6 )
break;
v7 = syscall(186LL);
printf("[pid %d] no pending command...\n", v7);
sleep(1u);
}
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 2064));
v1 = *((_DWORD *)a1 + 1);
v2 = v1 + 2LL;
v3 = (unsigned int *)*((_QWORD *)a1 + v2);
--*((_DWORD *)a1 + 2);
*((_QWORD *)a1 + v2) = 0LL;
v4 = v1 + 1;
if ( v1 == 255 )
v4 = 0;
*((_DWORD *)a1 + 1) = v4;
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 2064));
puts("\nexecute commands...");
printf(" cmd->interface: 0x%08x\n", *v3);
printf(" cmd->cmd: %s\n", (const char *)v3 + 4);
v5 = system((const char *)v3 + 4);
printf("done, return %d\n\n", v5);
printf("\n <== free cmd ... interface: 0x%08x\n\n", *v3);
free(v3);
}
}

original_code:
void *worker_thread(void *arg)
{
    cmd_queue *queue = ((void *)0);
    cmd_entry *cmd = ((void *)0);
    int pending_cmd = 0;
    int status = 0;
    time_t t;
    time(&t);
    queue = arg;
    while (1) {
        pthread_mutex_lock(&queue->mutex);
        pending_cmd = queue->counter;
        pthread_mutex_unlock(&queue->mutex);
        if (pending_cmd) {
            pthread_mutex_lock(&queue->mutex);
            cmd = queue->entry[queue->out];
            queue->counter--;
            queue->entry[queue->out] = ((void *)0);
            queue->out++;
            if (queue->out == 256) {
                queue->out = 0;
            }
            pthread_mutex_unlock(&queue->mutex);
            printf("\nexecute commands...\n");
            printf("  cmd->interface: 0x%08x\n", cmd->interface);
            printf("  cmd->cmd: %s\n", cmd->cmd);
            status = system(cmd->cmd);
            printf("done, return %d\n\n", status);
            printf("\n  <== free cmd ... interface: 0x%08x\n\n", cmd->interface);
            free(cmd);
            cmd = ((void *)0);
        } else {
            printf("[pid %d] no pending command...\n", (int) syscall(186));
            sleep(1);
        }
    }
}

canonical_original_code:
void *worker_thread(void *arg)
{
    struct _cmd_queue *queue = ((void *)0);
    struct _cmd_entry *cmd = ((void *)0);
    int pending_cmd = 0;
    int status = 0;
    long t;
    time(&t);
    queue = arg;
    while (1) {
        pthread_mutex_lock(&queue->mutex);
        pending_cmd = queue->counter;
        pthread_mutex_unlock(&queue->mutex);
        if (pending_cmd) {
            pthread_mutex_lock(&queue->mutex);
            cmd = queue->entry[queue->out];
            queue->counter--;
            queue->entry[queue->out] = ((void *)0);
            queue->out++;
            if (queue->out == 256) {
                queue->out = 0;
            }
            pthread_mutex_unlock(&queue->mutex);
            printf("\nexecute commands...\n");
            printf("  cmd->interface: 0x%08x\n", cmd->interface);
            printf("  cmd->cmd: %s\n", cmd->cmd);
            status = system(cmd->cmd);
            printf("done, return %d\n\n", status);
            printf("\n  <== free cmd ... interface: 0x%08x\n\n", cmd->interface);
            free(cmd);
            cmd = ((void *)0);
        } else {
            printf("[pid %d] no pending command...\n", (int) syscall(186));
            sleep(1);
        }
    }
}

variable_types: struct _cmd_queue { int in; int out; unsigned int counter; struct _cmd_entry { int interface; char cmd[256]; char fname[256]; } *entry[256]; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *

variable_types: status int

user_defined_types: struct _cmd_queue { int in; int out; unsigned int counter; struct _cmd_entry *entry[256]; union pthread_mutex_t mutex; }


decompiled_code:
__int64 __fastcall add_cmd(unsigned int *a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // rbp
const __m128i *v4; // rax
int v5; // edx
unsigned int v6; // eax
__int64 result; // rax
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

if ( a1[2] == 256 )
{
puts("\n!!! cmd-queue is full, will discard cmd !!!");
result = 1LL;
}
else
{
v2 = malloc(0x204uLL);
v3 = v2;
if ( !v2 )
{
puts("malloc cmd failed");
exit(1);
}
*v2 = a2;
v4 = (const __m128i *)"../util/sleep2to5sr1";
if ( a2 != 5 * (a2 / 5) )
v4 = (const __m128i *)"../util/sleep2to5sr0";
*(__m128i *)(v3 + 1) = _mm_loadu_si128(v4);
v3[5] = v4[1].m128i_i32[0];
*((_BYTE *)v3 + 24) = v4[1].m128i_i8[4];
system("date > cmd_file");
snprintf((char *)v3 + 260, 0x100uLL, "cmd_file.%d", *a1);
snprintf(v8, 0x100uLL, "cp cmd_file %s", (const char *)v3 + 260);
system(v8);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 516));
v5 = *a1;
*(_QWORD *)&a1[2 * *a1 + 4] = v3;
++a1[2];
v6 = v5 + 1;
if ( v5 == 255 )
v6 = 0;
*a1 = v6;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 516));
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // rbp
const __m128i *v4; // rax
int v5; // edx
unsigned int v6; // eax
__int64 result; // rax
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

if ( a1[2] == 256 )
{
puts("\n!!! cmd-queue is full, will discard cmd !!!");
result = 1LL;
}
else
{
v2 = malloc(0x204uLL);
v3 = v2;
if ( !v2 )
{
puts("malloc cmd failed");
exit(1);
}
*v2 = a2;
v4 = (const __m128i *)"../util/sleep2to5sr1";
if ( a2 != 5 * (a2 / 5) )
v4 = (const __m128i *)"../util/sleep2to5sr0";
*(__m128i *)(v3 + 1) = _mm_loadu_si128(v4);
v3[5] = v4[1].m128i_i32[0];
*((_BYTE *)v3 + 24) = v4[1].m128i_i8[4];
system("date > cmd_file");
snprintf((char *)v3 + 260, 0x100uLL, "cmd_file.%d", *a1);
snprintf(v8, 0x100uLL, "cp cmd_file %s", (const char *)v3 + 260);
system(v8);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 516));
v5 = *a1;
*(_QWORD *)&a1[2 * *a1 + 4] = v3;
++a1[2];
v6 = v5 + 1;
if ( v5 == 255 )
v6 = 0;
*a1 = v6;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 516));
result = 0LL;
}
return result;
}

original_code:
int add_cmd(cmd_queue *queue, int interface)
{
    cmd_entry *cmd = ((void *)0);
    char str[256];
    char *fbin = ((void *)0);
    char *fcfg = "cmd_file";
    if (queue->counter == 256) {
        printf("\n!!! cmd-queue is full, will discard cmd !!!\n");
        return 1;
    }
    cmd = malloc(sizeof(cmd_entry));
    if (!cmd) {
        printf("malloc cmd failed\n");
        exit(1);
    }
    cmd->interface = interface;
    if (interface % 5 == 0) {
        fbin = "../util/sleep2to5sr1";
    } else {
        fbin = "../util/sleep2to5sr0";
    }
    memcpy(cmd->cmd, fbin, strlen(fbin) + 1);
    system("date > cmd_file");
    snprintf(cmd->fname, sizeof(cmd->fname), "cmd_file.%d", queue->in);
    snprintf(str, sizeof(str), "cp cmd_file %s", cmd->fname);
    system(str);
    pthread_mutex_lock(&queue->mutex);
    queue->entry[queue->in] = cmd;
    queue->counter++;
    queue->in++;
    if (queue->in == 256) {
        queue->in = 0;
    }
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

canonical_original_code:
int add_cmd(struct _cmd_queue *queue, int interface)
{
    struct _cmd_entry *cmd = ((void *)0);
    char str[256];
    char *fbin = ((void *)0);
    char *fcfg = "cmd_file";
    if (queue->counter == 256) {
        printf("\n!!! cmd-queue is full, will discard cmd !!!\n");
        return 1;
    }
    cmd = malloc(sizeof(cmd_entry));
    if (!cmd) {
        printf("malloc cmd failed\n");
        exit(1);
    }
    cmd->interface = interface;
    if (interface % 5 == 0) {
        fbin = "../util/sleep2to5sr1";
    } else {
        fbin = "../util/sleep2to5sr0";
    }
    memcpy(cmd->cmd, fbin, strlen(fbin) + 1);
    system("date > cmd_file");
    snprintf(cmd->fname, sizeof(cmd->fname), "cmd_file.%d", queue->in);
    snprintf(str, sizeof(str), "cp cmd_file %s", cmd->fname);
    system(str);
    pthread_mutex_lock(&queue->mutex);
    queue->entry[queue->in] = cmd;
    queue->counter++;
    queue->in++;
    if (queue->in == 256) {
        queue->in = 0;
    }
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

variable_types: struct _cmd_entry { int interface; char cmd[256]; char fname[256]; } *

variable_types:
str
char [256]

variable_types:
fbin
char *

variable_types:
fcfg
char *


decompiled_code:
void handler1()
{
unsigned int v0; // ebx

v0 = global_interface++;
printf("\n ==> add command, interface: 0x%08x\n", v0);
add_cmd((unsigned int *)global_cmd_queue, v0);
}

canonical_decompiled_code:
void func9()
{
unsigned int v0; // ebx

v0 = global_interface++;
printf("\n ==> add command, interface: 0x%08x\n", v0);
func8((unsigned int *)global_cmd_queue, v0);
}

original_code:
void handler1(int signo)
{
    int interface = 0;
    interface = global_interface;
    global_interface++;
    printf("\n  ==> add command, interface: 0x%08x\n", interface);
    add_cmd(global_cmd_queue, interface);
}


decompiled_code:
int __fastcall init_queue(__int64 a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)(a1 + 16);
do
*v1++ = 0LL;
while ( v1 != (_QWORD *)(a1 + 2064) );
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = 0;
return pthread_mutex_init((pthread_mutex_t *)(a1 + 2064), 0LL);
}

original_code:
void init_queue(cmd_queue *queue)
{
    int i = 0;
    for (i = 0; i < 256; i++) {
        queue->entry[i] = ((void *)0);
    }
    queue->in = 0;
    queue->out = 0;
    queue->counter = 0;
    pthread_mutex_init(&queue->mutex, ((void *)0));
}

canonical_original_code:
void init_queue(struct _cmd_queue *queue)
{
    int i = 0;
    for (i = 0; i < 256; i++) {
        queue->entry[i] = ((void *)0);
    }
    queue->in = 0;
    queue->out = 0;
    queue->counter = 0;
    pthread_mutex_init(&queue->mutex, ((void *)0));
}

user_defined_types: struct _cmd_entry { int interface; char cmd[256]; char fname[256]; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rdi
__int64 v4; // rax
__int64 v5; // rax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( signal(1, (__sighandler_t)handler1) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
v3 = malloc(0x838uLL);
global_cmd_queue = v3;
if ( !v3 )
{
puts("malloc queue failed");
exit(1);
}
init_queue((__int64)v3);
if ( pthread_create(newthread, 0LL, (void *(*)(void *))worker_thread, global_cmd_queue) )
{
puts("Creating worker thread failed.");
exit(1);
}
v4 = syscall(186LL);
printf("[pid %d] main(), waiting for thread join...\n", v4);
pthread_join(newthread[0], 0LL);
v5 = syscall(186LL);
printf("[pid %d] main(), thread join done\n", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rdi
__int64 v4; // rax
__int64 v5; // rax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( signal(1, (__sighandler_t)handler1) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
v3 = malloc(0x838uLL);
global_cmd_queue = v3;
if ( !v3 )
{
puts("malloc queue failed");
exit(1);
}
func10((__int64)v3);
if ( pthread_create(newthread, 0LL, (void *(*)(void *))worker_thread, global_cmd_queue) )
{
puts("Creating worker thread failed.");
exit(1);
}
v4 = syscall(186LL);
printf("[pid %d] main(), waiting for thread join...\n", v4);
pthread_join(newthread[0], 0LL);
v5 = syscall(186LL);
printf("[pid %d] main(), thread join done\n", v5);
return 0;
}

original_code:
int main()
{
    int rc = 0;
    if (signal(1, handler1) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    global_cmd_queue = malloc(sizeof(cmd_queue));
    if (!global_cmd_queue) {
        printf("malloc queue failed\n");
        exit(1);
    }
    init_queue(global_cmd_queue);
    pthread_t worker;
    if (pthread_create(&worker, ((void *)0), worker_thread, global_cmd_queue) != 0) {
        printf("Creating worker thread failed.\n");
        exit(1);
    }
    printf("[pid %d] main(), waiting for thread join...\n", (int) syscall(186));
    pthread_join(worker, ((void *)0));
    printf("[pid %d] main(), thread join done\n", (int) syscall(186));
    return 0;
}

canonical_original_code:
int main()
{
    int rc = 0;
    if (signal(1, handler1) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    global_cmd_queue = malloc(sizeof(cmd_queue));
    if (!global_cmd_queue) {
        printf("malloc queue failed\n");
        exit(1);
    }
    init_queue(global_cmd_queue);
    unsigned long worker;
    if (pthread_create(&worker, ((void *)0), worker_thread, global_cmd_queue) != 0) {
        printf("Creating worker thread failed.\n");
        exit(1);
    }
    printf("[pid %d] main(), waiting for thread join...\n", (int) syscall(186));
    pthread_join(worker, ((void *)0));
    printf("[pid %d] main(), thread join done\n", (int) syscall(186));
    return 0;
}


togglePower

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

if ( powerState )
{
result = mvprintw(4, 25, "p: standard power");
powerState = 0;
}
else
{
result = mvprintw(4, 25, "p: low power ");
powerState = 1;
}
return result;
}

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

if ( powerState )
{
result = mvprintw(4, 25, "p: standard power");
powerState = 0;
}
else
{
result = mvprintw(4, 25, "p: low power ");
powerState = 1;
}
return result;
}

original_code:
void togglePower()
{
   if (powerState == 0) {
      mvprintw(4, 25, "p: low power     ");
      powerState = 1;
   } else {
      mvprintw(4, 25, "p: standard power");
      powerState = 0;
   }
}


nextAccelRange

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

switch ( accelSensitivity )
{
case 0x2000:
accelSensitivity = 4096;
result = mvprintw(2, 49, " 8g");
break;
case 0x4000:
accelSensitivity = 0x2000;
result = mvprintw(2, 49, " 4g");
break;
case 0x1000:
accelSensitivity = 2048;
result = mvprintw(2, 49, "16g");
break;
default:
accelSensitivity = 0x4000;
result = mvprintw(2, 49, " 2g");
break;
}
return result;
}

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

switch ( accelSensitivity )
{
case 0x2000:
accelSensitivity = 4096;
result = mvprintw(2, 49, " 8g");
break;
case 0x4000:
accelSensitivity = 0x2000;
result = mvprintw(2, 49, " 4g");
break;
case 0x1000:
accelSensitivity = 2048;
result = mvprintw(2, 49, "16g");
break;
default:
accelSensitivity = 0x4000;
result = mvprintw(2, 49, " 2g");
break;
}
return result;
}

original_code:
void nextAccelRange()
{
   switch(accelSensitivity) {
      case 16384:
         accelSensitivity = 8192;
         mvprintw(2, 49, " 4g");
         break;
      case 8192:
         accelSensitivity = 4096;
         mvprintw(2, 49, " 8g");
         break;
      case 4096:
         accelSensitivity = 2048;
         mvprintw(2, 49, "16g");
         break;
      case 2048:
      default:
         accelSensitivity = 16384;
         mvprintw(2, 49, " 2g");
         break;
   }
}


nextGyroRange

decompiled_code:
int nextGyroRange()
{
int v0; // eax
int result; // eax

v0 = (int)*(double *)&gyroSensitivity;
if ( (int)*(double *)&gyroSensitivity == 65 )
{
gyroSensitivity = 0x4040666666666666LL;
result = mvprintw(3, 49, "1000°/s");
}
else if ( v0 == 131 )
{
gyroSensitivity = 0x4050600000000000LL;
result = mvprintw(3, 49, " 500°/s");
}
else if ( v0 == 32 )
{
gyroSensitivity = 0x4030666666666666LL;
result = mvprintw(3, 49, "2000°/s");
}
else
{
gyroSensitivity = 0x4060600000000000LL;
result = mvprintw(3, 49, " 250°/s");
}
return result;
}

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

v0 = (int)*(double *)&gyroSensitivity;
if ( (int)*(double *)&gyroSensitivity == 65 )
{
gyroSensitivity = 0x4040666666666666LL;
result = mvprintw(3, 49, "1000°/s");
}
else if ( v0 == 131 )
{
gyroSensitivity = 0x4050600000000000LL;
result = mvprintw(3, 49, " 500°/s");
}
else if ( v0 == 32 )
{
gyroSensitivity = 0x4030666666666666LL;
result = mvprintw(3, 49, "2000°/s");
}
else
{
gyroSensitivity = 0x4060600000000000LL;
result = mvprintw(3, 49, " 250°/s");
}
return result;
}

original_code:
void nextGyroRange()
{
   switch((int)gyroSensitivity) {
      case 131:
         gyroSensitivity = 65.5;
         mvprintw(3, 49, " 500°/s");
         break;
      case 65:
         gyroSensitivity = 32.8;
         mvprintw(3, 49, "1000°/s");
         break;
      case 32:
         gyroSensitivity = 16.4;
         mvprintw(3, 49, "2000°/s");
         break;
      case 16:
      default:
         gyroSensitivity = 131;
         mvprintw(3, 49, " 250°/s");
         break;
   }
}


outputData

decompiled_code:
int __fastcall outputData(_DWORD *a1, unsigned int a2, double a3)
{
int result; // eax

result = 0;
while ( *a1 != a2 )
{
++result;
++a1;
if ( result == 10 )
return result;
}
if ( a2 - 120 > 2 )
result = mvprintw(result, 0, "%c: %8.2f °/s", a2, a3 / *(double *)&gyroSensitivity);
else
result = mvprintw(result, 0, "%c: %7.3f g", a2, a3 / (double)accelSensitivity);
return result;
}

canonical_decompiled_code:
int __fastcall func10(_DWORD *a1, unsigned int a2, double a3)
{
int result; // eax

result = 0;
while ( *a1 != a2 )
{
++result;
++a1;
if ( result == 10 )
return result;
}
if ( a2 - 120 > 2 )
result = mvprintw(result, 0, "%c: %8.2f °/s", a2, a3 / *(double *)&gyroSensitivity);
else
result = mvprintw(result, 0, "%c: %7.3f g", a2, a3 / (double)accelSensitivity);
return result;
}

original_code:
void outputData(int* position, int in, double data)
{
   int i;
   for (i = 0; i < 10; i++) {
      if (position[i] == in) {
         break;
      }
   }
   if (i == 10) {
      return;
   }
   if (in == 'x' || in == 'y' || in == 'z') {
      mvprintw(i, 0, "%c: %7.3f g", in, data/accelSensitivity);
   } else {
      mvprintw(i, 0, "%c: %8.2f °/s", in, data/gyroSensitivity);
   }
}

canonical_original_code:
void outputData(int *position, int in, double data)
{
   int i;
   for (i = 0; i < 10; i++) {
      if (position[i] == in) {
         break;
      }
   }
   if (i == 10) {
      return;
   }
   if (in == 'x' || in == 'y' || in == 'z') {
      mvprintw(i, 0, "%c: %7.3f g", in, data/accelSensitivity);
   } else {
      mvprintw(i, 0, "%c: %8.2f °/s", in, data/gyroSensitivity);
   }
}

variable_types:
position
int *

variable_types: in int

variable_types: data double


charIsWhitespace

decompiled_code:
bool __fastcall charIsWhitespace(unsigned __int8 a1)
{
bool result; // al

if ( a1 > 0x20u )
result = 0;
else
result = ((1LL << a1) & 0x100002600LL) != 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func0(unsigned __int8 a1)
{
bool result; // al

if ( a1 > 0x20u )
result = 0;
else
result = ((1LL << a1) & 0x100002600LL) != 0;
return result;
}

original_code:
static _Bool charIsWhitespace(char c)
{
 switch(c)
 {
  case ' ':
  case '\t':
  case '\n':
  case '\r':
   return 1;
  default:
   return 0;
 }
}

variable_types: c char


printPosition

decompiled_code:
int __fastcall printPosition(__int64 a1, int a2, int a3)
{
_BYTE *v4; // rax
__int64 v5; // rdx
__int64 v6; // r8
__int64 v7; // rcx
int result; // eax

if ( a2 <= 0 )
{
v6 = 1LL;
v7 = 1LL;
}
else
{
v4 = *(_BYTE **)(a1 + 8);
v5 = (__int64)&v4[a2 - 1 + 1];
LODWORD(v6) = 1;
v7 = 1LL;
do
{
if ( *v4 == 10 )
{
v7 = (unsigned int)(v7 + 1);
LODWORD(v6) = 0;
}
v6 = (unsigned int)(v6 + 1);
++v4;
}
while ( v4 != (_BYTE *)v5 );
}
if ( a3 )
result = fprintf(stderr, "%s:%i:%i-%i: ", *(const char **)(a1 + 16), v7, v6, (unsigned int)(v6 + a3));
else
result = fprintf(stderr, "%s:%i:%i: ", *(const char **)(a1 + 16), v7, v6);
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, int a2, int a3)
{
_BYTE *v4; // rax
__int64 v5; // rdx
__int64 v6; // r8
__int64 v7; // rcx
int result; // eax

if ( a2 <= 0 )
{
v6 = 1LL;
v7 = 1LL;
}
else
{
v4 = *(_BYTE **)(a1 + 8);
v5 = (__int64)&v4[a2 - 1 + 1];
LODWORD(v6) = 1;
v7 = 1LL;
do
{
if ( *v4 == 10 )
{
v7 = (unsigned int)(v7 + 1);
LODWORD(v6) = 0;
}
v6 = (unsigned int)(v6 + 1);
++v4;
}
while ( v4 != (_BYTE *)v5 );
}
if ( a3 )
result = fprintf(stderr, "%s:%i:%i-%i: ", *(const char **)(a1 + 16), v7, v6, (unsigned int)(v6 + a3));
else
result = fprintf(stderr, "%s:%i:%i: ", *(const char **)(a1 + 16), v7, v6);
return result;
}

original_code:
static void printPosition(const Stream* s, int offset, int length)
{
 int line=1;
 int column=1;
 for(int i=0;i<offset;i++)
 {
  if(s->data[i]=='\n')
  {
   line++;
   column=0;
  }
  column++;
 }
 if(length==0)
     fprintf(stderr, "%s:%i:%i: ", s->filename,line,column);
 else
     fprintf(stderr, "%s:%i:%i-%i: ", s->filename,line,column,column+length);
}

canonical_original_code:
static void printPosition(struct Stream *s, int offset, int length)
{
 int line = 1;
 int column = 1;
 for(int i = 0;i<offset;i++)
 {
  if(s->data[i]=='\n')
  {
   line++;
   column=0;
  }
  column++;
 }
 if(length==0)
     fprintf(stderr, "%s:%i:%i: ", s->filename,line,column);
 else
     fprintf(stderr, "%s:%i:%i-%i: ", s->filename,line,column,column+length);
}

variable_types: struct Stream { int length; int offset; char *data; char *filename; void (*errorHandler)(); } *

variable_types: offset int

variable_types: length int

variable_types: line int

variable_types: column int


closeStream

decompiled_code:
void __fastcall closeStream(void *ptr)
{
if ( ptr )
{
munmap(*((void **)ptr + 1), *(int *)ptr);
free(*((void **)ptr + 2));
free(ptr);
}
else
{
panic("stream.c", 55LL, "failed assertion: %s", "s!=NULL");
isEof();
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
munmap(*((void **)ptr + 1), *(int *)ptr);
free(*((void **)ptr + 2));
free(ptr);
}
else
{
panic("stream.c", 55LL, "failed assertion: %s", "s!=NULL");
func4();
}
}

original_code:
void closeStream(Stream* s)
{
 {if(!(s!=((void *)0))){panic("stream.c",55,"failed assertion: %s","s!=NULL");}};
 munmap(s->data,s->length);
 free(s->filename);
 free(s);
}

canonical_original_code:
void closeStream(struct Stream *s)
{
 {if(!(s!=((void *)0))){panic("stream.c",55,"failed assertion: %s","s!=NULL");}};
 munmap(s->data,s->length);
 free(s->filename);
 free(s);
}

user_defined_types: struct Stream { int length; int offset; char *data; char *filename; void (*errorHandler)(); }


isEof

decompiled_code:
bool __fastcall isEof(_DWORD *a1)
{
return a1[1] >= *a1;
}

canonical_decompiled_code:
bool __fastcall func4(_DWORD *a1)
{
return a1[1] >= *a1;
}

original_code:
_Bool isEof(const Stream* s)
{
 return s->offset>=s->length;
}

canonical_original_code:
_Bool isEof(struct Stream *s)
{
 return s->offset>=s->length;
}