ParamList

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

ReadToken();
if ( !(unsigned int)is_reversed_word("integer")
&& !(unsigned int)is_reversed_word("char")
&& !(unsigned int)is_reversed_word("record")
&& !(unsigned int)is_reversed_word("array") )
{
is_reversed_word("var");
}
result = ParamDecList();
*a1 = result;
return result;
}

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

ReadToken();
if ( !(unsigned int)is_reversed_word("integer")
&& !(unsigned int)is_reversed_word("char")
&& !(unsigned int)is_reversed_word("record")
&& !(unsigned int)is_reversed_word("array") )
{
is_reversed_word("var");
}
result = func5();
*a1 = result;
return result;
}

original_code:
void ParamList(TreeNode * t){
  ReadToken();
  if(
      is_reversed_word("integer") ||
      is_reversed_word("char") ||
      is_reversed_word("record") ||
      is_reversed_word("array") ||
      is_reversed_word("var") ||
      ( tokenType == SNL_ID )
    );
    t->child[0] = ParamDecList();
}

canonical_original_code:
void ParamList(struct node *t){
  ReadToken();
  if(
      is_reversed_word("integer") ||
      is_reversed_word("char") ||
      is_reversed_word("record") ||
      is_reversed_word("array") ||
      is_reversed_word("var") ||
      ( tokenType == SNL_ID )
    );
    t->child[0] = ParamDecList();
}


ProcDecLaration

decompiled_code:
char *ProcDecLaration()
{
char *v0; // rax
char *v1; // rbx
int v3; // eax

v0 = (char *)malloc(0x1C8uLL);
v1 = v0;
if ( v0 )
{
*((_DWORD *)v0 + 9) = 4;
strcpy(v0 + 40, "ProcDecK");
ReadToken();
if ( tokenType == 5 )
{
v3 = *((_DWORD *)v1 + 26);
*((_DWORD *)v1 + 26) = v3 + 1;
strcpy(&v1[30 * v3 + 108], &tokenValueBuffer);
}
ReadToken();
if ( (unsigned int)is_not_symbol("(") )
fwrite("Procedure declare miss '('\n", 1uLL, 0x1BuLL, stderr);
ParamList((char **)v1);
ReadToken();
if ( (unsigned int)is_not_symbol(")") )
fwrite("Procedure declare miss ')'\n", 1uLL, 0x1BuLL, stderr);
ReadToken();
if ( (unsigned int)is_not_symbol(";") )
fwrite("Procedure declare miss ';'\n", 1uLL, 0x1BuLL, stderr);
*((_QWORD *)v1 + 1) = ProcDecPart();
*((_QWORD *)v1 + 2) = ProcBody();
}
return v1;
}

canonical_decompiled_code:
char *func8()
{
char *v0; // rax
char *v1; // rbx
int v3; // eax

v0 = (char *)malloc(0x1C8uLL);
v1 = v0;
if ( v0 )
{
*((_DWORD *)v0 + 9) = 4;
strcpy(v0 + 40, "ProcDecK");
ReadToken();
if ( tokenType == 5 )
{
v3 = *((_DWORD *)v1 + 26);
*((_DWORD *)v1 + 26) = v3 + 1;
strcpy(&v1[30 * v3 + 108], &tokenValueBuffer);
}
ReadToken();
if ( (unsigned int)is_not_symbol("(") )
fwrite("Procedure declare miss '('\n", 1uLL, 0x1BuLL, stderr);
func7((char **)v1);
ReadToken();
if ( (unsigned int)is_not_symbol(")") )
fwrite("Procedure declare miss ')'\n", 1uLL, 0x1BuLL, stderr);
ReadToken();
if ( (unsigned int)is_not_symbol(";") )
fwrite("Procedure declare miss ';'\n", 1uLL, 0x1BuLL, stderr);
*((_QWORD *)v1 + 1) = func1();
*((_QWORD *)v1 + 2) = func0();
}
return v1;
}

original_code:
TreeNode * ProcDecLaration(){
  TreeNode * t = ((void *)0);
  t = (TreeNode *)malloc(sizeof(TreeNode));
  if( t == ((void *)0) )
    return t;
  t->nodeKind = ProcDecK;
  strcpy(t->nodeKindStr, "ProcDecK");
  ReadToken();
  if( ( tokenType == SNL_ID ) )
    strcpy(t->name[t->idnum++], tokenValueBuffer);
  ReadToken();
  if( is_not_symbol("(") )
    fprintf(stderr, "Procedure declare miss '('\n");
  ParamList(t);
  ReadToken();
  if( is_not_symbol(")") )
    fprintf(stderr, "Procedure declare miss ')'\n");
  ReadToken();
  if( is_not_symbol(";") )
    fprintf(stderr, "Procedure declare miss ';'\n");
  t->child[1] = ProcDecPart();
  t->child[2] = ProcBody();
  return t;
}

canonical_original_code:
struct node *ProcDecLaration(){
  struct node *t = ((void *)0);
  t = (struct node *)malloc(sizeof(TreeNode));
  if( t == ((void *)0) )
    return t;
  t->nodeKind = ProcDecK;
  strcpy(t->nodeKindStr, "ProcDecK");
  ReadToken();
  if( ( tokenType == SNL_ID ) )
    strcpy(t->name[t->idnum++], tokenValueBuffer);
  ReadToken();
  if( is_not_symbol("(") )
    fprintf(stderr, "Procedure declare miss '('\n");
  ParamList(t);
  ReadToken();
  if( is_not_symbol(")") )
    fprintf(stderr, "Procedure declare miss ')'\n");
  ReadToken();
  if( is_not_symbol(";") )
    fprintf(stderr, "Procedure declare miss ';'\n");
  t->child[1] = ProcDecPart();
  t->child[2] = ProcBody();
  return t;
}

variable_types: struct node { struct node *child[3]; struct node *Sibling; int Lineno; enum NodeKind { ProK=0, PheadK=1, TypeK=2, VarK=3, ProcDecK=4, StmLK=5, DecK=6, StmtK=7, ExpK=8 } nodeKind; char nodeKindStr[30]; union k { enum dec { ArrayK=0, CharK=1, IntegerK=2, RecordK=3, IdK=4 } d; enum stmt { IfK=0, WhileK=1, AssignK=2, ReadK=3, WriteK=4, CallK=5, ReturnK=6 } s; enum exp { OpK=0, ConstK=1, IdEK=2 } e; char name[30]; } kind; int idnum; char name[10][30]; char type_name[30]; union a { struct array { int low; int up; enum dec { ArrayK=0, CharK=1, IntegerK=2, RecordK=3, IdK=4 } childType; } a_attr; struct expAttr { char op; int val; enum varKind { IdV=0, ArrayMembV=1, FieldMembV=2 } varkind; enum ExpType { Void=0, Integer=1, Boolean=2 } type; } e_attr; struct proc { enum ProcAttrType { valparamtype=0, varparamtype=1 } paramt; } p_attr; } attr; } *

user_defined_types: struct node { struct node *child[3]; struct node *Sibling; int Lineno; enum NodeKind nodeKind; char nodeKindStr[30]; union k kind; int idnum; char name[10][30]; char type_name[30]; union a attr; }

user_defined_types: union k { enum dec d; enum stmt s; enum exp e; char name[30]; }

user_defined_types: union a { struct array a_attr; struct expAttr e_attr; struct proc p_attr; }

user_defined_types: struct array { int low; int up; enum dec childType; }

user_defined_types: struct expAttr { char op; int val; enum varKind varkind; enum ExpType type; }

user_defined_types: struct proc { enum ProcAttrType paramt; }


ProcDec

decompiled_code:
char *ProcDec()
{
ReadToken();
if ( !(unsigned int)is_not_reversed_word("procedure") )
return ProcDecLaration();
UnReadToken();
return 0LL;
}

canonical_decompiled_code:
char *func9()
{
ReadToken();
if ( !(unsigned int)is_not_reversed_word("procedure") )
return func8();
UnReadToken();
return 0LL;
}

original_code:
TreeNode * ProcDec(){
  ReadToken();
  if( is_not_reversed_word("procedure") ){
    UnReadToken();
    return ((void *)0);
  }
  return ProcDecLaration();
}

canonical_original_code:
struct node *ProcDec(){
  ReadToken();
  if( is_not_reversed_word("procedure") ){
    UnReadToken();
    return ((void *)0);
  }
  return ProcDecLaration();
}

return_type: struct node { struct node *child[3]; struct node *Sibling; int Lineno; enum NodeKind { ProK=0, PheadK=1, TypeK=2, VarK=3, ProcDecK=4, StmLK=5, DecK=6, StmtK=7, ExpK=8 } nodeKind; char nodeKindStr[30]; union k { enum dec { ArrayK=0, CharK=1, IntegerK=2, RecordK=3, IdK=4 } d; enum stmt { IfK=0, WhileK=1, AssignK=2, ReadK=3, WriteK=4, CallK=5, ReturnK=6 } s; enum exp { OpK=0, ConstK=1, IdEK=2 } e; char name[30]; } kind; int idnum; char name[10][30]; char type_name[30]; union a { struct array { int low; int up; enum dec { ArrayK=0, CharK=1, IntegerK=2, RecordK=3, IdK=4 } childType; } a_attr; struct expAttr { char op; int val; enum varKind { IdV=0, ArrayMembV=1, FieldMembV=2 } varkind; enum ExpType { Void=0, Integer=1, Boolean=2 } type; } e_attr; struct proc { enum ProcAttrType { valparamtype=0, varparamtype=1 } paramt; } p_attr; } attr; } *


BaseType

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

ReadToken();
if ( (unsigned int)is_reversed_word("integer") )
{
result = 0x4B72656765746E49LL;
strcpy((char *)(a1 + 72), "IntegerK");
}
else
{
result = is_reversed_word("char");
if ( (_DWORD)result )
strcpy((char *)(a1 + 72), "CharK");
}
return result;
}

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

ReadToken();
if ( (unsigned int)is_reversed_word("integer") )
{
result = 0x4B72656765746E49LL;
strcpy((char *)(a1 + 72), "IntegerK");
}
else
{
result = is_reversed_word("char");
if ( (_DWORD)result )
strcpy((char *)(a1 + 72), "CharK");
}
return result;
}

original_code:
void BaseType(TreeNode * t){
  ReadToken();
  if( is_reversed_word("integer") ){
    t->kind.d = IntegerK;
    strcpy(t->kind.name, "IntegerK");
    return;
  }
  if( is_reversed_word("char") ){
    t->kind.d = CharK;
    strcpy(t->kind.name, "CharK");
    return;
  }
}

canonical_original_code:
void BaseType(struct node *t){
  ReadToken();
  if( is_reversed_word("integer") ){
    t->kind.d = IntegerK;
    strcpy(t->kind.name, "IntegerK");
    return;
  }
  if( is_reversed_word("char") ){
    t->kind.d = CharK;
    strcpy(t->kind.name, "CharK");
    return;
  }
}

return_type: void

user_defined_types: enum NodeKind { ProK=0, PheadK=1, TypeK=2, VarK=3, ProcDecK=4, StmLK=5, DecK=6, StmtK=7, ExpK=8 }

user_defined_types: enum dec { ArrayK=0, CharK=1, IntegerK=2, RecordK=3, IdK=4 }

user_defined_types: enum stmt { IfK=0, WhileK=1, AssignK=2, ReadK=3, WriteK=4, CallK=5, ReturnK=6 }

user_defined_types: enum varKind { IdV=0, ArrayMembV=1, FieldMembV=2 }

user_defined_types: enum ExpType { Void=0, Integer=1, Boolean=2 }

user_defined_types: enum ProcAttrType { valparamtype=0, varparamtype=1 }


ArrayType

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

ReadToken();
if ( (unsigned int)is_not_symbol("[") )
return fwrite("array declaration '[' miss! \n", 1uLL, 0x1DuLL, stderr);
if ( (unsigned int)ReadToken() )
return fwrite("array declaration 'low' miss! \n", 1uLL, 0x1FuLL, stderr);
*(_DWORD *)(a1 + 440) = i_tokenValueBuffer;
ReadToken();
if ( (unsigned int)is_not_symbol("..") )
return fwrite("array declaration '..' miss! \n", 1uLL, 0x1EuLL, stderr);
if ( (unsigned int)ReadToken() )
return fwrite("array declaration 'up' miss! \n", 1uLL, 0x1EuLL, stderr);
*(_DWORD *)(a1 + 444) = i_tokenValueBuffer;
ReadToken();
if ( (unsigned int)is_not_symbol("]") )
return fwrite("array declaration ']' miss! \n", 1uLL, 0x1DuLL, stderr);
ReadToken();
if ( (unsigned int)is_not_reversed_word("of") )
return fwrite("array declaration 'of' miss! \n", 1uLL, 0x1EuLL, stderr);
BaseType(a1);
result = *(unsigned int *)(a1 + 72);
*(_DWORD *)(a1 + 448) = result;
strcpy((char *)(a1 + 72), "ArrayK");
return result;
}

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

ReadToken();
if ( (unsigned int)is_not_symbol("[") )
return fwrite("array declaration '[' miss! \n", 1uLL, 0x1DuLL, stderr);
if ( (unsigned int)ReadToken() )
return fwrite("array declaration 'low' miss! \n", 1uLL, 0x1FuLL, stderr);
*(_DWORD *)(a1 + 440) = i_tokenValueBuffer;
ReadToken();
if ( (unsigned int)is_not_symbol("..") )
return fwrite("array declaration '..' miss! \n", 1uLL, 0x1EuLL, stderr);
if ( (unsigned int)ReadToken() )
return fwrite("array declaration 'up' miss! \n", 1uLL, 0x1EuLL, stderr);
*(_DWORD *)(a1 + 444) = i_tokenValueBuffer;
ReadToken();
if ( (unsigned int)is_not_symbol("]") )
return fwrite("array declaration ']' miss! \n", 1uLL, 0x1DuLL, stderr);
ReadToken();
if ( (unsigned int)is_not_reversed_word("of") )
return fwrite("array declaration 'of' miss! \n", 1uLL, 0x1EuLL, stderr);
func0(a1);
result = *(unsigned int *)(a1 + 72);
*(_DWORD *)(a1 + 448) = result;
strcpy((char *)(a1 + 72), "ArrayK");
return result;
}

original_code:
void ArrayType(TreeNode * t){
  ReadToken();
  if( is_not_symbol("[") ){
    fprintf(stderr, "array declaration '[' miss! \n");
    return;
  }
  if( ReadToken() != SNL_INTERGER){
    fprintf(stderr, "array declaration 'low' miss! \n");
    return;
  } else
    t->attr.a_attr.low = i_tokenValueBuffer;
  ReadToken();
  if( is_not_symbol("..") ){
    fprintf(stderr, "array declaration '..' miss! \n");
    return;
  }
  if( ReadToken() != SNL_INTERGER){
    fprintf(stderr, "array declaration 'up' miss! \n");
    return;
  } else
    t->attr.a_attr.up = i_tokenValueBuffer;
  ReadToken();
  if( is_not_symbol("]") ){
    fprintf(stderr, "array declaration ']' miss! \n");
    return;
  }
  ReadToken();
  if( is_not_reversed_word("of") ){
    fprintf(stderr, "array declaration 'of' miss! \n");
    return;
  }
  BaseType(t);
  t->attr.a_attr.childType = t->kind.d;
  t->kind.d = ArrayK;
  strcpy(t->kind.name, "ArrayK");
}

canonical_original_code:
void ArrayType(struct node *t){
  ReadToken();
  if( is_not_symbol("[") ){
    fprintf(stderr, "array declaration '[' miss! \n");
    return;
  }
  if( ReadToken() != SNL_INTERGER){
    fprintf(stderr, "array declaration 'low' miss! \n");
    return;
  } else
    t->attr.a_attr.low = i_tokenValueBuffer;
  ReadToken();
  if( is_not_symbol("..") ){
    fprintf(stderr, "array declaration '..' miss! \n");
    return;
  }
  if( ReadToken() != SNL_INTERGER){
    fprintf(stderr, "array declaration 'up' miss! \n");
    return;
  } else
    t->attr.a_attr.up = i_tokenValueBuffer;
  ReadToken();
  if( is_not_symbol("]") ){
    fprintf(stderr, "array declaration ']' miss! \n");
    return;
  }
  ReadToken();
  if( is_not_reversed_word("of") ){
    fprintf(stderr, "array declaration 'of' miss! \n");
    return;
  }
  BaseType(t);
  t->attr.a_attr.childType = t->kind.d;
  t->kind.d = ArrayK;
  strcpy(t->kind.name, "ArrayK");
}


RecType

decompiled_code:
void RecType()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void RecType(TreeNode * t){
}

canonical_original_code:
void RecType(struct node *t){
}


StrutureType

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

if ( (unsigned int)is_reversed_word("array") )
return ArrayType(a1);
result = is_reversed_word("record");
if ( (_DWORD)result )
{
result = 0x4B64726F636552LL;
*(_QWORD *)(a1 + 72) = 0x4B64726F636552LL;
}
return result;
}

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

if ( (unsigned int)is_reversed_word("array") )
return func1(a1);
result = is_reversed_word("record");
if ( (_DWORD)result )
{
result = 0x4B64726F636552LL;
*(_QWORD *)(a1 + 72) = 0x4B64726F636552LL;
}
return result;
}

original_code:
void StrutureType(TreeNode * t){
  if( is_reversed_word("array") ){
    ArrayType(t);
    return;
  }
  if( is_reversed_word("record") ){
    t->kind.d = RecordK;
    strcpy(t->kind.name, "RecordK");
    RecType(t);
    return;
  }
}

canonical_original_code:
void StrutureType(struct node *t){
  if( is_reversed_word("array") ){
    ArrayType(t);
    return;
  }
  if( is_reversed_word("record") ){
    t->kind.d = RecordK;
    strcpy(t->kind.name, "RecordK");
    RecType(t);
    return;
  }
}


TypeId

decompiled_code:
char *__fastcall TypeId(__int64 a1)
{
char *result; // rax
int v2; // eax

ReadToken();
if ( tokenType == 5 )
{
v2 = *(_DWORD *)(a1 + 104);
*(_DWORD *)(a1 + 104) = v2 + 1;
result = strcpy((char *)(a1 + 30LL * v2 + 108), &tokenValueBuffer);
}
else
{
fwrite("type declaration miss Id.\n", 1uLL, 0x1AuLL, stderr);
result = (char *)UnReadToken();
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1)
{
char *result; // rax
int v2; // eax

ReadToken();
if ( tokenType == 5 )
{
v2 = *(_DWORD *)(a1 + 104);
*(_DWORD *)(a1 + 104) = v2 + 1;
result = strcpy((char *)(a1 + 30LL * v2 + 108), &tokenValueBuffer);
}
else
{
fwrite("type declaration miss Id.\n", 1uLL, 0x1AuLL, stderr);
result = (char *)UnReadToken();
}
return result;
}

original_code:
void TypeId(TreeNode * t){
  ReadToken();
  if( ( tokenType == SNL_ID ) )
    strcpy(t->name[t->idnum++], tokenValueBuffer);
  else{
    fprintf(stderr, "type declaration miss Id.\n");
    UnReadToken();
  }
}

canonical_original_code:
void TypeId(struct node *t){
  ReadToken();
  if( ( tokenType == SNL_ID ) )
    strcpy(t->name[t->idnum++], tokenValueBuffer);
  else{
    fprintf(stderr, "type declaration miss Id.\n");
    UnReadToken();
  }
}


TypeDef

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

ReadToken();
if ( (unsigned int)is_reversed_word("integer") || (unsigned int)is_reversed_word("char") )
{
UnReadToken();
result = BaseType(a1);
}
else if ( (unsigned int)is_reversed_word("array") || (result = is_reversed_word("record"), (_DWORD)result) )
{
result = StrutureType(a1);
}
else if ( tokenType == 5 )
{
*(_DWORD *)(a1 + 72) = 4;
result = (__int64)strcpy((char *)(a1 + 408), &tokenValueBuffer);
}
return result;
}

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

ReadToken();
if ( (unsigned int)is_reversed_word("integer") || (unsigned int)is_reversed_word("char") )
{
UnReadToken();
result = func0(a1);
}
else if ( (unsigned int)is_reversed_word("array") || (result = is_reversed_word("record"), (_DWORD)result) )
{
result = func3(a1);
}
else if ( tokenType == 5 )
{
*(_DWORD *)(a1 + 72) = 4;
result = (__int64)strcpy((char *)(a1 + 408), &tokenValueBuffer);
}
return result;
}

original_code:
void TypeDef(TreeNode * t){
  ReadToken();
  if( is_reversed_word("integer") || is_reversed_word("char") ){
    UnReadToken();
    BaseType(t);
    return;
  }
  if( is_reversed_word("array") || is_reversed_word("record") ){
    StrutureType(t);
    return;
  }
  if( tokenType == SNL_ID ){
    t->kind.d = IdK;
    strcpy(t->type_name, tokenValueBuffer);
  }
}

canonical_original_code:
void TypeDef(struct node *t){
  ReadToken();
  if( is_reversed_word("integer") || is_reversed_word("char") ){
    UnReadToken();
    BaseType(t);
    return;
  }
  if( is_reversed_word("array") || is_reversed_word("record") ){
    StrutureType(t);
    return;
  }
  if( tokenType == SNL_ID ){
    t->kind.d = IdK;
    strcpy(t->type_name, tokenValueBuffer);
  }
}


TypeDecList

decompiled_code:
__int64 TypeDecList()
{
void *v0; // rax
__int64 v1; // rbx
__int64 v2; // rax

v0 = malloc(0x1C8uLL);
v1 = (__int64)v0;
if ( v0 )
{
TypeId((__int64)v0);
ReadToken();
if ( (unsigned int)is_not_symbol("=") )
fwrite("type declaration '=' miss! \n", 1uLL, 0x1CuLL, stderr);
TypeDef(v1);
ReadToken();
if ( (unsigned int)is_not_symbol(";") )
fwrite("type declaration ';' miss! \n", 1uLL, 0x1CuLL, stderr);
*(_DWORD *)(v1 + 36) = 6;
strcpy((char *)(v1 + 40), "DecK");
v2 = TypeDecMore();
if ( v2 )
*(_QWORD *)(v1 + 24) = v2;
}
return v1;
}

canonical_decompiled_code:
__int64 func6()
{
void *v0; // rax
__int64 v1; // rbx
__int64 v2; // rax

v0 = malloc(0x1C8uLL);
v1 = (__int64)v0;
if ( v0 )
{
func4((__int64)v0);
ReadToken();
if ( (unsigned int)is_not_symbol("=") )
fwrite("type declaration '=' miss! \n", 1uLL, 0x1CuLL, stderr);
func5(v1);
ReadToken();
if ( (unsigned int)is_not_symbol(";") )
fwrite("type declaration ';' miss! \n", 1uLL, 0x1CuLL, stderr);
*(_DWORD *)(v1 + 36) = 6;
strcpy((char *)(v1 + 40), "DecK");
v2 = func7();
if ( v2 )
*(_QWORD *)(v1 + 24) = v2;
}
return v1;
}

original_code:
TreeNode * TypeDecList(){
  TreeNode * t = (TreeNode *)malloc(sizeof(TreeNode));;
  if( t == ((void *)0) )
    return t;
  TypeId(t);
  ReadToken();
  if( is_not_symbol("=") )
    fprintf(stderr, "type declaration '=' miss! \n");
  TypeDef(t);
  ReadToken();
  if( is_not_symbol(";") )
    fprintf(stderr, "type declaration ';' miss! \n");
  t->nodeKind = DecK;
  strcpy(t->nodeKindStr, "DecK");
  TreeNode * p = ((void *)0);
  p = TypeDecMore();
  if( p )
    t->Sibling = p;
  return t;
}

canonical_original_code:
struct node *TypeDecList(){
  struct node *t = (TreeNode *)malloc(sizeof(TreeNode));;
  if( t == ((void *)0) )
    return t;
  TypeId(t);
  ReadToken();
  if( is_not_symbol("=") )
    fprintf(stderr, "type declaration '=' miss! \n");
  TypeDef(t);
  ReadToken();
  if( is_not_symbol(";") )
    fprintf(stderr, "type declaration ';' miss! \n");
  t->nodeKind = DecK;
  strcpy(t->nodeKindStr, "DecK");
  struct node *p = ((void *)0);
  p = TypeDecMore();
  if( p )
    t->Sibling = p;
  return t;
}


TypeDecMore

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

ReadToken();
if ( tokenType == 5 )
{
UnReadToken();
result = TypeDecList();
}
else
{
UnReadToken();
result = 0LL;
}
return result;
}

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

ReadToken();
if ( tokenType == 5 )
{
UnReadToken();
result = func6();
}
else
{
UnReadToken();
result = 0LL;
}
return result;
}

original_code:
TreeNode * TypeDecMore(){
  TreeNode * t = ((void *)0);
  ReadToken();
  if( ( tokenType == SNL_ID ) ){
    UnReadToken();
    t = TypeDecList();
  } else
    UnReadToken();
  return t;
}

canonical_original_code:
struct node *TypeDecMore(){
  struct node *t = ((void *)0);
  ReadToken();
  if( ( tokenType == SNL_ID ) ){
    UnReadToken();
    t = TypeDecList();
  } else
    UnReadToken();
  return t;
}


typeDeclaration

decompiled_code:
__int64 typeDeclaration()
{
__int64 v0; // rbx

v0 = TypeDecList();
if ( !v0 )
fwrite("type declaration error!\n", 1uLL, 0x18uLL, stderr);
return v0;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rbx

v0 = func6();
if ( !v0 )
fwrite("type declaration error!\n", 1uLL, 0x18uLL, stderr);
return v0;
}

original_code:
TreeNode * typeDeclaration(){
  TreeNode * t = TypeDecList();
  if( t == ((void *)0) )
    fprintf(stderr, "type declaration error!\n");
  return t;
}

canonical_original_code:
struct node *typeDeclaration(){
  struct node *t = TypeDecList();
  if( t == ((void *)0) )
    fprintf(stderr, "type declaration error!\n");
  return t;
}


TypeDec

decompiled_code:
__int64 TypeDec()
{
ReadToken();
if ( (unsigned int)is_reversed_word("type") )
return typeDeclaration();
UnReadToken();
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
ReadToken();
if ( (unsigned int)is_reversed_word("type") )
return func8();
UnReadToken();
return 0LL;
}

original_code:
TreeNode * TypeDec(){
  TreeNode * t = ((void *)0);
  ReadToken();
  if( is_reversed_word("type") ){
    t = typeDeclaration();
  } else
    UnReadToken();
  return t;
}

canonical_original_code:
struct node *TypeDec(){
  struct node *t = ((void *)0);
  ReadToken();
  if( is_reversed_word("type") ){
    t = typeDeclaration();
  } else
    UnReadToken();
  return t;
}


decompiled_code:
int __fastcall print_sym(char a1)
{
return fprintf(out, "%d: %c\n", (unsigned int)lineno, (unsigned int)a1);
}

canonical_decompiled_code:
int __fastcall func2(char a1)
{
return fprintf(out, "%d: %c\n", (unsigned int)lineno, (unsigned int)a1);
}

original_code:
void print_sym(char ch){
  fprintf(out, "%d: %c\n", lineno, ch);
}

variable_types: ch char


UnReadToken

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

strcpy(unReadTokenBuffer, tokenValueBuffer);
result = (unsigned int)tokenType;
unReadTokenType = tokenType;
hasUnReadToken = 1;
return result;
}

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

strcpy(unReadTokenBuffer, tokenValueBuffer);
result = (unsigned int)tokenType;
unReadTokenType = tokenType;
hasUnReadToken = 1;
return result;
}

original_code:
void UnReadToken(){
  strcpy(unReadTokenBuffer, tokenValueBuffer);
  unReadTokenType = tokenType;
  hasUnReadToken = 1;
}


ReadToken

decompiled_code:
__int64 ReadToken()
{
__int64 result; // rax
char v1[32]; // [rsp+0h] [rbp-58h] BYREF
char src[40]; // [rsp+20h] [rbp-38h] BYREF
int v3; // [rsp+48h] [rbp-10h] BYREF
char v4; // [rsp+4Ch] [rbp-Ch] BYREF

if ( hasUnReadToken )
{
strcpy(tokenValueBuffer, unReadTokenBuffer);
result = (unsigned int)unReadTokenType;
tokenType = unReadTokenType;
hasUnReadToken = 0;
}
else
{
_isoc99_fscanf(fp, "%d: %s", &v4, src);
if ( !strcmp(src, "reserved") )
{
_isoc99_fscanf(fp, " word: %s", v1);
tokenType = 4;
strcpy(tokenValueBuffer, v1);
}
else if ( !strcmp(src, "ID,") )
{
_isoc99_fscanf(fp, " name = %s", v1);
tokenType = 5;
strcpy(tokenValueBuffer, v1);
}
else if ( !strcmp(src, "INTEGER,") )
{
_isoc99_fscanf(fp, " var = %d", &v3);
tokenType = 0;
i_tokenValueBuffer = v3;
}
else if ( src[0] )
{
tokenType = 6;
strcpy(tokenValueBuffer, src);
}
result = (unsigned int)tokenType;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
char v1[32]; // [rsp+0h] [rbp-58h] BYREF
char src[40]; // [rsp+20h] [rbp-38h] BYREF
int v3; // [rsp+48h] [rbp-10h] BYREF
char v4; // [rsp+4Ch] [rbp-Ch] BYREF

if ( hasUnReadToken )
{
strcpy(tokenValueBuffer, unReadTokenBuffer);
result = (unsigned int)unReadTokenType;
tokenType = unReadTokenType;
hasUnReadToken = 0;
}
else
{
_isoc99_fscanf(fp, "%d: %s", &v4, src);
if ( !strcmp(src, "reserved") )
{
_isoc99_fscanf(fp, " word: %s", v1);
tokenType = 4;
strcpy(tokenValueBuffer, v1);
}
else if ( !strcmp(src, "ID,") )
{
_isoc99_fscanf(fp, " name = %s", v1);
tokenType = 5;
strcpy(tokenValueBuffer, v1);
}
else if ( !strcmp(src, "INTEGER,") )
{
_isoc99_fscanf(fp, " var = %d", &v3);
tokenType = 0;
i_tokenValueBuffer = v3;
}
else if ( src[0] )
{
tokenType = 6;
strcpy(tokenValueBuffer, src);
}
result = (unsigned int)tokenType;
}
return result;
}

original_code:
SNL_TYPE ReadToken(){
  if(hasUnReadToken){
    strcpy(tokenValueBuffer, unReadTokenBuffer);
    tokenType = unReadTokenType;
    hasUnReadToken = 0;
    return tokenType;
  }
  int lineno, i;
  char type[30], chs[30];
  fscanf(fp, "%d: %s", &lineno, type);
  if( strcmp(type, "reserved") == 0 ){
    fscanf(fp, " word: %s", chs);
    tokenType = SNL_REVERSE_WORD;
    strcpy(tokenValueBuffer, chs);
  } else if ( strcmp(type, "ID,") == 0 ){
    fscanf(fp, " name = %s", chs);
    tokenType = SNL_ID;
    strcpy(tokenValueBuffer, chs);
  } else if ( strcmp(type, "INTEGER,") == 0 ){
    fscanf(fp, " var = %d", &i);
    tokenType = SNL_INTERGER;
    i_tokenValueBuffer = i;
  } else if (type[0] == '\0'){
    ;
  } else {
    tokenType = SNL_SYMBOL;
    strcpy(tokenValueBuffer, type);
  }
  type[0] = '\0';
  return tokenType;
}

canonical_original_code:
enum SNL_TYPE ReadToken(){
  if(hasUnReadToken){
    strcpy(tokenValueBuffer, unReadTokenBuffer);
    tokenType = unReadTokenType;
    hasUnReadToken = 0;
    return tokenType;
  }
  int lineno; int i;
  char type[30]; char chs[30];
  fscanf(fp, "%d: %s", &lineno, type);
  if( strcmp(type, "reserved") == 0 ){
    fscanf(fp, " word: %s", chs);
    tokenType = SNL_REVERSE_WORD;
    strcpy(tokenValueBuffer, chs);
  } else if ( strcmp(type, "ID,") == 0 ){
    fscanf(fp, " name = %s", chs);
    tokenType = SNL_ID;
    strcpy(tokenValueBuffer, chs);
  } else if ( strcmp(type, "INTEGER,") == 0 ){
    fscanf(fp, " var = %d", &i);
    tokenType = SNL_INTERGER;
    i_tokenValueBuffer = i;
  } else if (type[0] == '\0'){
    ;
  } else {
    tokenType = SNL_SYMBOL;
    strcpy(tokenValueBuffer, type);
  }
  type[0] = '\0';
  return tokenType;
}

variable_types: lineno int

variable_types: i int

variable_types:
type
char [30]

variable_types:
chs
char [30]

return_type: enum SNL_TYPE { SNL_INTERGER=0, SNL_CHAR=1, SNL_ARRAY=2, SNL_RECORD=3, SNL_REVERSE_WORD=4, SNL_ID=5, SNL_SYMBOL=6 }


decompiled_code:
_BOOL8 __fastcall is_reversed_word(const char *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( tokenType == 4 )
result = strcmp(a1, &tokenValueBuffer) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( tokenType == 4 )
result = strcmp(a1, &tokenValueBuffer) == 0;
return result;
}

original_code:
int is_reversed_word(const char * chs){
  return (tokenType == SNL_REVERSE_WORD && strcmp(chs, tokenValueBuffer) == 0) ? 1 : 0;
}

canonical_original_code:
int is_reversed_word(char *chs){
  return (tokenType == SNL_REVERSE_WORD && strcmp(chs, tokenValueBuffer) == 0) ? 1 : 0;
}

variable_types:
chs
char *

return_type: int


decompiled_code:
_BOOL8 __fastcall is_not_reversed_word(const char *a1)
{
return !is_reversed_word(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
return !func0(a1);
}

original_code:
int is_not_reversed_word(const char * chs){
  return is_reversed_word(chs) ? 0 : 1;
}

canonical_original_code:
int is_not_reversed_word(char *chs){
  return is_reversed_word(chs) ? 0 : 1;
}


decompiled_code:
_BOOL8 __fastcall is_symbol(const char *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( tokenType == 6 )
result = strcmp(a1, &tokenValueBuffer) == 0;
return result;
}

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

result = 0LL;
if ( tokenType == 6 )
result = strcmp(a1, &tokenValueBuffer) == 0;
return result;
}

original_code:
int is_symbol(const char * chs){
  return (tokenType == SNL_SYMBOL && strcmp(chs, tokenValueBuffer) == 0) ? 1 : 0;
}

canonical_original_code:
int is_symbol(char *chs){
  return (tokenType == SNL_SYMBOL && strcmp(chs, tokenValueBuffer) == 0) ? 1 : 0;
}


decompiled_code:
_BOOL8 __fastcall is_not_symbol(const char *a1)
{
return !is_symbol(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1)
{
return !func2(a1);
}

original_code:
int is_not_symbol(const char * chs){
  return is_symbol(chs) ? 0 : 1;
}

canonical_original_code:
int is_not_symbol(char *chs){
  return is_symbol(chs) ? 0 : 1;
}


decompiled_code:
int __fastcall printf_syntax_tree(__int64 a1, unsigned int a2)
{
int v2; // ebx
const char *v3; // rbp
int v4; // ebx
int result; // eax
_QWORD *v6; // rbx
__int64 v7; // rdi

if ( (int)(4 * a2) > 0 )
{
v2 = 0;
do
{
putchar(32);
++v2;
}
while ( v2 != 4 * a2 );
}
printf("%s", (const char *)(a1 + 40));
printf(" %s", (const char *)(a1 + 72));
if ( *(int *)(a1 + 104) > 0 )
{
v3 = (const char *)(a1 + 108);
v4 = 0;
do
{
printf(" %s", v3);
++v4;
v3 += 30;
}
while ( *(_DWORD *)(a1 + 104) > v4 );
}
result = putchar(10);
v6 = (_QWORD *)a1;
do
{
if ( *v6 )
result = printf_syntax_tree(*v6, a2 + 1);
++v6;
}
while ( v6 != (_QWORD *)(a1 + 24) );
v7 = *(_QWORD *)(a1 + 24);
if ( v7 )
result = printf_syntax_tree(v7, a2);
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, unsigned int a2)
{
int v2; // ebx
const char *v3; // rbp
int v4; // ebx
int result; // eax
_QWORD *v6; // rbx
__int64 v7; // rdi

if ( (int)(4 * a2) > 0 )
{
v2 = 0;
do
{
putchar(32);
++v2;
}
while ( v2 != 4 * a2 );
}
printf("%s", (const char *)(a1 + 40));
printf(" %s", (const char *)(a1 + 72));
if ( *(int *)(a1 + 104) > 0 )
{
v3 = (const char *)(a1 + 108);
v4 = 0;
do
{
printf(" %s", v3);
++v4;
v3 += 30;
}
while ( *(_DWORD *)(a1 + 104) > v4 );
}
result = putchar(10);
v6 = (_QWORD *)a1;
do
{
if ( *v6 )
result = func4(*v6, a2 + 1);
++v6;
}
while ( v6 != (_QWORD *)(a1 + 24) );
v7 = *(_QWORD *)(a1 + 24);
if ( v7 )
result = func4(v7, a2);
return result;
}

original_code:
void printf_syntax_tree(TreeNode * root, int dep){
  int i;
  for(i = 0; i < dep * 4; ++i)putchar(' ');
  printf("%s", root->nodeKindStr);
  printf(" %s", root->kind.name);
  for(i = 0; i < root->idnum; ++i)
    printf(" %s", root->name[i]);
  printf("\n");
  for(i = 0; i < 3; ++i){
    if( root->child[i] ){
      printf_syntax_tree(root->child[i], dep + 1);
    }
  }
  if( root->Sibling ){
    printf_syntax_tree(root->Sibling, dep);
  }
}

canonical_original_code:
void printf_syntax_tree(struct node *root, int dep){
  int i;
  for(i = 0; i < dep * 4; ++i)putchar(' ');
  printf("%s", root->nodeKindStr);
  printf(" %s", root->kind.name);
  for(i = 0; i < root->idnum; ++i)
    printf(" %s", root->name[i]);
  printf("\n");
  for(i = 0; i < 3; ++i){
    if( root->child[i] ){
      printf_syntax_tree(root->child[i], dep + 1);
    }
  }
  if( root->Sibling ){
    printf_syntax_tree(root->Sibling, dep);
  }
}

variable_types: dep int


ProgramHead

decompiled_code:
void *ProgramHead()
{
void *v0; // rbx
int v1; // eax

ReadToken();
if ( (unsigned int)is_not_reversed_word("program") )
fwrite("Bad Begin(No reserved word program)\n", 1uLL, 0x24uLL, stderr);
if ( (unsigned int)ReadToken() != 5 )
fwrite("Bad program name\n", 1uLL, 0x11uLL, stderr);
v0 = malloc(0x1C8uLL);
*((_DWORD *)v0 + 9) = 1;
strcpy((char *)v0 + 40, "PheadK");
v1 = *((_DWORD *)v0 + 26);
*((_DWORD *)v0 + 26) = v1 + 1;
strcpy((char *)v0 + 30 * v1 + 108, &tokenValueBuffer);
return v0;
}

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

ReadToken();
if ( (unsigned int)is_not_reversed_word("program") )
fwrite("Bad Begin(No reserved word program)\n", 1uLL, 0x24uLL, stderr);
if ( (unsigned int)ReadToken() != 5 )
fwrite("Bad program name\n", 1uLL, 0x11uLL, stderr);
v0 = malloc(0x1C8uLL);
*((_DWORD *)v0 + 9) = 1;
strcpy((char *)v0 + 40, "PheadK");
v1 = *((_DWORD *)v0 + 26);
*((_DWORD *)v0 + 26) = v1 + 1;
strcpy((char *)v0 + 30 * v1 + 108, &tokenValueBuffer);
return v0;
}

original_code:
TreeNode * ProgramHead(){
  ReadToken();
  if( is_not_reversed_word("program") ){
    fprintf(stderr, "Bad Begin(No reserved word program)\n");
  }
  if( ReadToken() != SNL_ID ){
    fprintf(stderr, "Bad program name\n");
  }
  TreeNode * t = (TreeNode *)malloc(sizeof(TreeNode));
  t->nodeKind = PheadK;
  strcpy(t->nodeKindStr, "PheadK");
  strcpy(t->name[t->idnum++], tokenValueBuffer);
  return t;
}

canonical_original_code:
struct node *ProgramHead(){
  ReadToken();
  if( is_not_reversed_word("program") ){
    fprintf(stderr, "Bad Begin(No reserved word program)\n");
  }
  if( ReadToken() != SNL_ID ){
    fprintf(stderr, "Bad program name\n");
  }
  struct node *t = (TreeNode *)malloc(sizeof(TreeNode));
  t->nodeKind = PheadK;
  strcpy(t->nodeKindStr, "PheadK");
  strcpy(t->name[t->idnum++], tokenValueBuffer);
  return t;
}


Program

decompiled_code:
char *Program()
{
void *v0; // rbp
__int64 v1; // r13
__int64 v2; // r12
char *v3; // rax
char *v4; // rbx

v0 = ProgramHead();
v1 = DeclarePart();
v2 = ProgramBody();
v3 = (char *)malloc(0x1C8uLL);
v4 = v3;
*((_DWORD *)v3 + 9) = 0;
strcpy(v3 + 40, "ProK");
if ( v0 )
*(_QWORD *)v3 = v0;
else
fwrite("No Program Head\n", 1uLL, 0x10uLL, stderr);
*((_QWORD *)v4 + 1) = v1;
if ( v2 )
*((_QWORD *)v4 + 2) = v2;
else
fwrite("No Program Body\n", 1uLL, 0x10uLL, stderr);
ReadToken();
if ( (unsigned int)is_not_symbol(".") )
fwrite("No Program End Symbol(Dot) \n", 1uLL, 0x1CuLL, stderr);
return v4;
}

canonical_decompiled_code:
char *func1()
{
void *v0; // rbp
__int64 v1; // r13
__int64 v2; // r12
char *v3; // rax
char *v4; // rbx

v0 = func0();
v1 = DeclarePart();
v2 = ProgramBody();
v3 = (char *)malloc(0x1C8uLL);
v4 = v3;
*((_DWORD *)v3 + 9) = 0;
strcpy(v3 + 40, "ProK");
if ( v0 )
*(_QWORD *)v3 = v0;
else
fwrite("No Program Head\n", 1uLL, 0x10uLL, stderr);
*((_QWORD *)v4 + 1) = v1;
if ( v2 )
*((_QWORD *)v4 + 2) = v2;
else
fwrite("No Program Body\n", 1uLL, 0x10uLL, stderr);
ReadToken();
if ( (unsigned int)is_not_symbol(".") )
fwrite("No Program End Symbol(Dot) \n", 1uLL, 0x1CuLL, stderr);
return v4;
}

original_code:
TreeNode * Program(){
  TreeNode *t = ((void *)0), *q = ((void *)0), *s = ((void *)0), *root = ((void *)0);
  t = ProgramHead();
  q = DeclarePart();
  s = ProgramBody();
  root = (TreeNode *)malloc(sizeof(TreeNode));
  root->nodeKind = ProK;
  strcpy(root->nodeKindStr, "ProK");
  if( root == ((void *)0))
    return ((void *)0);
  if(t == ((void *)0)){
    fprintf(stderr, "No Program Head\n");
  }
  else
    root->child[0] = t;
  if(q != ((void *)0))
    root->child[1] = q;
  else
    root->child[1] = ((void *)0);
  if(s == ((void *)0)){
    fprintf(stderr, "No Program Body\n");
  }
  else
    root->child[2] = s;
  ReadToken();
  if( is_not_symbol(".") )
    fprintf(stderr, "No Program End Symbol(Dot) \n");;
  return root;
}

canonical_original_code:
struct node *Program(){
  struct node *t = ((void *)0); struct node *q = ((void *)0); struct node *s = ((void *)0); struct node *root = ((void *)0);
  t = ProgramHead();
  q = DeclarePart();
  s = ProgramBody();
  root = (struct node *)malloc(sizeof(TreeNode));
  root->nodeKind = ProK;
  strcpy(root->nodeKindStr, "ProK");
  if( root == ((void *)0))
    return ((void *)0);
  if(t == ((void *)0)){
    fprintf(stderr, "No Program Head\n");
  }
  else
    root->child[0] = t;
  if(q != ((void *)0))
    root->child[1] = q;
  else
    root->child[1] = ((void *)0);
  if(s == ((void *)0)){
    fprintf(stderr, "No Program Body\n");
  }
  else
    root->child[2] = s;
  ReadToken();
  if( is_not_symbol(".") )
    fprintf(stderr, "No Program End Symbol(Dot) \n");;
  return root;
}


parse

decompiled_code:
char *parse()
{
char *v0; // rbx

v0 = Program();
ReadToken();
if ( strcmp("EOF", &tokenValueBuffer) )
{
fwrite("Bad END\n", 1uLL, 8uLL, stderr);
v0 = 0LL;
}
return v0;
}

canonical_decompiled_code:
char *func2()
{
char *v0; // rbx

v0 = func1();
ReadToken();
if ( strcmp("EOF", &tokenValueBuffer) )
{
fwrite("Bad END\n", 1uLL, 8uLL, stderr);
v0 = 0LL;
}
return v0;
}

original_code:
TreeNode * parse(){
  int i = 0;
  TreeNode * t = Program();
  ReadToken();
  if( !( strcmp("EOF", tokenValueBuffer) == 0 ) ){
    fprintf(stderr, "Bad END\n");
    return ((void *)0);
  }
  return t;
}

canonical_original_code:
struct node *parse(){
  int i = 0;
  struct node *t = Program();
  ReadToken();
  if( !( strcmp("EOF", tokenValueBuffer) == 0 ) ){
    fprintf(stderr, "Bad END\n");
    return ((void *)0);
  }
  return t;
}


RTreeInitBranch

repo: davidreynolds/rtree

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

result = RTreeInitRect();
*(_QWORD *)(a1 + 32) = 0LL;
return result;
}

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

result = RTreeInitRect();
*(_QWORD *)(a1 + 32) = 0LL;
return result;
}

original_code:
static void RTreeInitBranch(struct Branch *b)
{
    RTreeInitRect(&(b->rect));
    b->child = ((void *)0);
}

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

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


RTreeInitNode

decompiled_code:
__int64 __fastcall RTreeInitNode(_DWORD *a1)
{
__int64 v1; // rbx
__int64 result; // rax

*a1 = 0;
a1[1] = -1;
v1 = (__int64)(a1 + 2);
do
{
result = RTreeInitBranch(v1);
v1 += 40LL;
}
while ( (_DWORD *)v1 != a1 + 1022 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
__int64 v1; // rbx
__int64 result; // rax

*a1 = 0;
a1[1] = -1;
v1 = (__int64)(a1 + 2);
do
{
result = func0(v1);
v1 += 40LL;
}
while ( (_DWORD *)v1 != a1 + 1022 );
return result;
}

original_code:
void RTreeInitNode(struct Node *N)
{
    register struct Node *n = N;
    register int i;
    n->count = 0;
    n->level = -1;
    for (i = 0; i < (int)((4096 -(2*sizeof(int))) / sizeof(struct Branch)); i++)
        RTreeInitBranch(&(n->branch[i]));
}

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

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


RTreeNewNode

decompiled_code:
_DWORD *RTreeNewNode()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = malloc(0xFF8uLL);
if ( !v0 )
_assert_fail("n", "src/node.c", 0x29u, "RTreeNewNode");
v1 = v0;
RTreeInitNode(v0);
return v1;
}

canonical_decompiled_code:
_DWORD *func2()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = malloc(0xFF8uLL);
if ( !v0 )
_assert_fail("n", "src/node.c", 0x29u, "RTreeNewNode");
v1 = v0;
func1(v0);
return v1;
}

original_code:
struct Node * RTreeNewNode()
{
    register struct Node *n;
    n = (struct Node*) malloc(sizeof(struct Node));
    ((void) sizeof ((n) ? 1 : 0), __extension__ ({ if (n) ; else __assert_fail ("n", "src/node.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    RTreeInitNode(n);
    return n;
}

canonical_original_code:
struct Node *RTreeNewNode()
{
    register struct Node *n;
    n = (struct Node *) malloc(sizeof(struct Node));
    ((void) sizeof ((n) ? 1 : 0), __extension__ ({ if (n) ; else __assert_fail ("n", "src/node.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    RTreeInitNode(n);
    return n;
}

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


RTreeFreeNode

decompiled_code:
void __fastcall RTreeFreeNode(void *a1)
{
if ( !a1 )
_assert_fail("p", "src/node.c", 0x31u, "RTreeFreeNode");
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
if ( !a1 )
_assert_fail("p", "src/node.c", 0x31u, "RTreeFreeNode");
free(a1);
}

original_code:
void RTreeFreeNode(struct Node *p)
{
    ((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail ("p", "src/node.c", 49, __extension__ __PRETTY_FUNCTION__); }));
    free(p);
}


RTreeTabIn

decompiled_code:
int __fastcall RTreeTabIn(int a1)
{
int i; // ebx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = putchar(9);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
int i; // ebx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = putchar(9);
}
return result;
}

original_code:
extern void RTreeTabIn(int depth)
{
    int i;
    for(i=0; i<depth; i++)
        putchar('\t');
}

variable_types: depth int


RTreeDeleteIndex

decompiled_code:
void __fastcall RTreeDeleteIndex(int *a1)
{
__int64 v1; // rbp

if ( a1 )
{
if ( a1[1] > 0 && *a1 > 0 )
{
v1 = 0LL;
do
RTreeDeleteIndex(*(_QWORD *)&a1[10 * v1++ + 10]);
while ( *a1 > (int)v1 );
}
RTreeFreeNode(a1);
}
else
{
fwrite("NULL node\n", 1uLL, 0xAuLL, stderr);
}
}

canonical_decompiled_code:
void __fastcall func5(int *a1)
{
__int64 v1; // rbp

if ( a1 )
{
if ( a1[1] > 0 && *a1 > 0 )
{
v1 = 0LL;
do
func5(*(_QWORD *)&a1[10 * v1++ + 10]);
while ( *a1 > (int)v1 );
}
func3(a1);
}
else
{
fwrite("NULL node\n", 1uLL, 0xAuLL, stderr);
}
}

original_code:
void RTreeDeleteIndex(struct Node *n)
{
    int i;
    if (n == ((void *)0)) {
        fprintf(stderr, "NULL node\n");
        return;
    }
    if (n->level > 0) {
 for (i=0; i<n->count; i++) {
     RTreeDeleteIndex(n->branch[i].child);
 }
    }
    RTreeFreeNode(n);
}


RTreePrintNode

decompiled_code:
int __fastcall RTreePrintNode(unsigned int *a1, int a2)
{
int v2; // eax
int result; // eax
unsigned int *v4; // r12
signed int v5; // ebx

RTreeTabIn(a2);
if ( !a1 )
return puts("NULL node");
printf("node");
v2 = a1[1];
if ( v2 )
{
if ( v2 <= 0 )
printf(" TYPE=?");
else
printf(" NONLEAF");
}
else
{
printf(" LEAF");
}
result = printf(" level=%d count=%d address=%p\n", a1[1], *a1, a1);
if ( (int)*a1 > 0 )
{
v4 = a1 + 2;
v5 = 0;
do
{
if ( a1[1] )
{
RTreeTabIn(a2);
printf("branch %d\n", (unsigned int)v5);
result = RTreePrintBranch(v4, (unsigned int)(a2 + 1));
}
++v5;
v4 += 10;
}
while ( (int)*a1 > v5 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1, int a2)
{
int v2; // eax
int result; // eax
unsigned int *v4; // r12
signed int v5; // ebx

func4(a2);
if ( !a1 )
return puts("NULL node");
printf("node");
v2 = a1[1];
if ( v2 )
{
if ( v2 <= 0 )
printf(" TYPE=?");
else
printf(" NONLEAF");
}
else
{
printf(" LEAF");
}
result = printf(" level=%d count=%d address=%p\n", a1[1], *a1, a1);
if ( (int)*a1 > 0 )
{
v4 = a1 + 2;
v5 = 0;
do
{
if ( a1[1] )
{
func4(a2);
printf("branch %d\n", (unsigned int)v5);
result = func7(v4, (unsigned int)(a2 + 1));
}
++v5;
v4 += 10;
}
while ( (int)*a1 > v5 );
}
return result;
}

original_code:
void RTreePrintNode(struct Node *n, int depth)
{
    int i;
    RTreeTabIn(depth);
    if (n == ((void *)0)) {
        printf("NULL node\n");
        return;
    }
    printf("node");
    if (n->level == 0)
        printf(" LEAF");
    else if (n->level > 0)
        printf(" NONLEAF");
    else
        printf(" TYPE=?");
    printf("  level=%d  count=%d  address=%p\n", n->level, n->count, (void *)n);
    for (i=0; i<n->count; i++)
    {
        if(n->level == 0) {
        }
        else {
            RTreeTabIn(depth);
            printf("branch %d\n", i);
            RTreePrintBranch(&n->branch[i], depth+1);
        }
    }
}


RTreePrintBranch

decompiled_code:
int __fastcall RTreePrintBranch(__int64 a1, int a2)
{
RTreePrintRect();
return RTreePrintNode(*(unsigned int **)(a1 + 32), a2);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, int a2)
{
RTreePrintRect();
return func6(*(unsigned int **)(a1 + 32), a2);
}

original_code:
static void RTreePrintBranch(struct Branch *b, int depth)
{
    RTreePrintRect(&(b->rect), depth);
    RTreePrintNode(b->child, depth);
}


RTreePickBranch

decompiled_code:
__int64 __fastcall RTreePickBranch(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
double v3; // r13
int v4; // er15
int i; // ebp
int v6; // eax
double v7; // xmm0_8
double v9; // [rsp+8h] [rbp-90h]
unsigned int v10; // [rsp+14h] [rbp-84h]
double v11; // [rsp+18h] [rbp-80h]
__m128i v12; // [rsp+20h] [rbp-78h] BYREF
__m128i v13; // [rsp+30h] [rbp-68h] BYREF
__int128 v14[5]; // [rsp+40h] [rbp-58h] BYREF

if ( !a1 || !a2 )
_assert_fail("r && n", "src/node.c", 0xACu, "RTreePickBranch");
v2 = a2 + 8;
v3 = *(double *)&LC11;
v4 = 1;
for ( i = 0; ; ++i )
{
v6 = LEAFCARD;
if ( *(int *)(a2 + 4) > 0 )
v6 = NODECARD;
if ( i >= v6 )
break;
if ( *(_QWORD *)(v2 + 32) )
{
v9 = RTreeRectSphericalVolume(v2);
RTreeCombineRect(&v12, a1);
v14[0] = (__int128)_mm_loadu_si128(&v12);
v14[1] = (__int128)_mm_loadu_si128(&v13);
v7 = RTreeRectSphericalVolume(v14) - v9;
if ( v3 > v7 )
{
v10 = i;
v11 = v9;
v3 = v7;
v4 = 0;
}
else if ( v4 )
{
v10 = i;
v11 = v9;
v3 = v7;
v4 = 0;
}
else if ( v3 == v7 && v11 > v9 )
{
v10 = i;
v11 = v9;
v3 = v7;
}
}
v2 += 40LL;
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
double v3; // r13
int v4; // er15
int i; // ebp
int v6; // eax
double v7; // xmm0_8
double v9; // [rsp+8h] [rbp-90h]
unsigned int v10; // [rsp+14h] [rbp-84h]
double v11; // [rsp+18h] [rbp-80h]
__m128i v12; // [rsp+20h] [rbp-78h] BYREF
__m128i v13; // [rsp+30h] [rbp-68h] BYREF
__int128 v14[5]; // [rsp+40h] [rbp-58h] BYREF

if ( !a1 || !a2 )
_assert_fail("r && n", "src/node.c", 0xACu, "RTreePickBranch");
v2 = a2 + 8;
v3 = *(double *)&LC11;
v4 = 1;
for ( i = 0; ; ++i )
{
v6 = LEAFCARD;
if ( *(int *)(a2 + 4) > 0 )
v6 = NODECARD;
if ( i >= v6 )
break;
if ( *(_QWORD *)(v2 + 32) )
{
v9 = RTreeRectSphericalVolume(v2);
RTreeCombineRect(&v12, a1);
v14[0] = (__int128)_mm_loadu_si128(&v12);
v14[1] = (__int128)_mm_loadu_si128(&v13);
v7 = RTreeRectSphericalVolume(v14) - v9;
if ( v3 > v7 )
{
v10 = i;
v11 = v9;
v3 = v7;
v4 = 0;
}
else if ( v4 )
{
v10 = i;
v11 = v9;
v3 = v7;
v4 = 0;
}
else if ( v3 == v7 && v11 > v9 )
{
v10 = i;
v11 = v9;
v3 = v7;
}
}
v2 += 40LL;
}
return v10;
}

original_code:
int RTreePickBranch(struct Rect *R, struct Node *N)
{
    register struct Rect *r = R;
    register struct Node *n = N;
    register struct Rect *rr;
    register int i, first_time=1;
    RectReal increase, bestIncr=(RectReal)-1, area, bestArea;
    int best;
    struct Rect tmp_rect;
    ((void) sizeof ((r && n) ? 1 : 0), __extension__ ({ if (r && n) ; else __assert_fail ("r && n", "src/node.c", 172, __extension__ __PRETTY_FUNCTION__); }));
    for (i=0; i<((n)->level > 0 ? NODECARD : LEAFCARD); i++)
    {
        if (n->branch[i].child)
        {
            rr = &n->branch[i].rect;
            area = RTreeRectSphericalVolume(rr);
            tmp_rect = RTreeCombineRect(r, rr);
            increase = RTreeRectSphericalVolume(&tmp_rect) - area;
            if (increase < bestIncr || first_time)
            {
                best = i;
                bestArea = area;
                bestIncr = increase;
                first_time = 0;
            }
            else if (increase == bestIncr && area < bestArea)
            {
                best = i;
                bestArea = area;
                bestIncr = increase;
            }
        }
    }
    return best;
}

canonical_original_code:
int RTreePickBranch(struct Rect *R, struct Node *N)
{
    register struct Rect *r = R;
    register struct Node *n = N;
    register struct Rect *rr;
    register int i; register int first_time = 1;
    double increase; double bestIncr = (RectReal)-1; double area; double bestArea;
    int best;
    struct Rect tmp_rect;
    ((void) sizeof ((r && n) ? 1 : 0), __extension__ ({ if (r && n) ; else __assert_fail ("r && n", "src/node.c", 172, __extension__ __PRETTY_FUNCTION__); }));
    for (i=0; i<((n)->level > 0 ? NODECARD : LEAFCARD); i++)
    {
        if (n->branch[i].child)
        {
            rr = &n->branch[i].rect;
            area = RTreeRectSphericalVolume(rr);
            tmp_rect = RTreeCombineRect(r, rr);
            increase = RTreeRectSphericalVolume(&tmp_rect) - area;
            if (increase < bestIncr || first_time)
            {
                best = i;
                bestArea = area;
                bestIncr = increase;
                first_time = 0;
            }
            else if (increase == bestIncr && area < bestArea)
            {
                best = i;
                bestArea = area;
                bestIncr = increase;
            }
        }
    }
    return best;
}

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

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

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

variable_types: increase double

variable_types: bestIncr double

variable_types: area double

variable_types: bestArea double

variable_types: best int


RTreeAddBranch

decompiled_code:
__int64 __fastcall RTreeAddBranch(const __m128i *a1, _DWORD *a2, __int64 a3)
{
int v5; // esi
int v6; // er9
int v7; // ecx
_QWORD *v8; // rdx
int v9; // eax
_DWORD *v10; // rax
int v11; // eax
int v12; // edx
__int64 result; // rax

if ( !a1 )
_assert_fail("b", "src/node.c", 0xDAu, "RTreeAddBranch");
if ( !a2 )
_assert_fail("n", "src/node.c", 0xDBu, "RTreeAddBranch");
v5 = *a2;
v6 = a2[1];
v7 = NODECARD;
if ( v6 <= 0 )
v7 = LEAFCARD;
if ( v5 >= v7 )
{
if ( !a3 )
_assert_fail("new_node", "src/node.c", 0xF3u, "RTreeAddBranch");
RTreeSplitNode(a2, a1);
result = 1LL;
}
else
{
if ( v7 > 0 )
{
v8 = a2 + 10;
v9 = 0;
while ( *v8 )
{
++v9;
v8 += 5;
if ( v7 == v9 )
goto LABEL_14;
}
v10 = &a2[10 * v9];
*(__m128i *)(v10 + 2) = _mm_loadu_si128(a1);
*(__m128i *)(v10 + 6) = _mm_loadu_si128(a1 + 1);
*((_QWORD *)v10 + 5) = a1[2].m128i_i64[0];
*a2 = v5 + 1;
}
LABEL_14:
v11 = *a2;
v12 = NODECARD;
if ( v6 <= 0 )
v12 = LEAFCARD;
if ( v11 >= v12 )
{
result = 0LL;
}
else
{
if ( *(_QWORD *)&a2[10 * v11 + 10] )
_assert_fail(
"(n->count < MAXKIDS(n)) ? (n->branch[n->count].child == NULL) : 1",
"src/node.c",
0xECu,
"RTreeAddBranch");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const __m128i *a1, _DWORD *a2, __int64 a3)
{
int v5; // esi
int v6; // er9
int v7; // ecx
_QWORD *v8; // rdx
int v9; // eax
_DWORD *v10; // rax
int v11; // eax
int v12; // edx
__int64 result; // rax

if ( !a1 )
_assert_fail("b", "src/node.c", 0xDAu, "RTreeAddBranch");
if ( !a2 )
_assert_fail("n", "src/node.c", 0xDBu, "RTreeAddBranch");
v5 = *a2;
v6 = a2[1];
v7 = NODECARD;
if ( v6 <= 0 )
v7 = LEAFCARD;
if ( v5 >= v7 )
{
if ( !a3 )
_assert_fail("new_node", "src/node.c", 0xF3u, "RTreeAddBranch");
RTreeSplitNode(a2, a1);
result = 1LL;
}
else
{
if ( v7 > 0 )
{
v8 = a2 + 10;
v9 = 0;
while ( *v8 )
{
++v9;
v8 += 5;
if ( v7 == v9 )
goto LABEL_14;
}
v10 = &a2[10 * v9];
*(__m128i *)(v10 + 2) = _mm_loadu_si128(a1);
*(__m128i *)(v10 + 6) = _mm_loadu_si128(a1 + 1);
*((_QWORD *)v10 + 5) = a1[2].m128i_i64[0];
*a2 = v5 + 1;
}
LABEL_14:
v11 = *a2;
v12 = NODECARD;
if ( v6 <= 0 )
v12 = LEAFCARD;
if ( v11 >= v12 )
{
result = 0LL;
}
else
{
if ( *(_QWORD *)&a2[10 * v11 + 10] )
_assert_fail(
"(n->count < MAXKIDS(n)) ? (n->branch[n->count].child == NULL) : 1",
"src/node.c",
0xECu,
"RTreeAddBranch");
result = 0LL;
}
}
return result;
}

original_code:
int RTreeAddBranch(
        struct Branch *B,
        struct Node *N,
        struct Node **New_node
    )
{
    register struct Branch *b = B;
    register struct Node *n = N;
    register struct Node **new_node = New_node;
    register int i;
    ((void) sizeof ((b) ? 1 : 0), __extension__ ({ if (b) ; else __assert_fail ("b", "src/node.c", 218, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n) ? 1 : 0), __extension__ ({ if (n) ; else __assert_fail ("n", "src/node.c", 219, __extension__ __PRETTY_FUNCTION__); }));
    if (n->count < ((n)->level > 0 ? NODECARD : LEAFCARD))
    {
        for (i = 0; i < ((n)->level > 0 ? NODECARD : LEAFCARD); i++)
        {
            if (n->branch[i].child == ((void *)0))
            {
                n->branch[i] = *b;
                n->count++;
                break;
            }
        }
        ((void) sizeof (((n->count < ((n)->level > 0 ? NODECARD : LEAFCARD)) ? (n->branch[n->count].child == ((void *)0)) : 1) ? 1 : 0), __extension__ ({ if ((n->count < ((n)->level > 0 ? NODECARD : LEAFCARD)) ? (n->branch[n->count].child == ((void *)0)) : 1) ; else __assert_fail ("(n->count < MAXKIDS(n)) ? (n->branch[n->count].child == NULL) : 1", "src/node.c", 236, __extension__ __PRETTY_FUNCTION__); }));
        return 0;
    }
    else
    {
        ((void) sizeof ((new_node) ? 1 : 0), __extension__ ({ if (new_node) ; else __assert_fail ("new_node", "src/node.c", 243, __extension__ __PRETTY_FUNCTION__); }));
        RTreeSplitNode(n, b, new_node);
        return 1;
    }
}

canonical_original_code:
int RTreeAddBranch(struct Branch *B, struct Node *N, struct Node **New_node)
{
    register struct Branch *b = B;
    register struct Node *n = N;
    register struct Node **new_node = New_node;
    register int i;
    ((void) sizeof ((b) ? 1 : 0), __extension__ ({ if (b) ; else __assert_fail ("b", "src/node.c", 218, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((n) ? 1 : 0), __extension__ ({ if (n) ; else __assert_fail ("n", "src/node.c", 219, __extension__ __PRETTY_FUNCTION__); }));
    if (n->count < ((n)->level > 0 ? NODECARD : LEAFCARD))
    {
        for (i = 0; i < ((n)->level > 0 ? NODECARD : LEAFCARD); i++)
        {
            if (n->branch[i].child == ((void *)0))
            {
                n->branch[i] = *b;
                n->count++;
                break;
            }
        }
        ((void) sizeof (((n->count < ((n)->level > 0 ? NODECARD : LEAFCARD)) ? (n->branch[n->count].child == ((void *)0)) : 1) ? 1 : 0), __extension__ ({ if ((n->count < ((n)->level > 0 ? NODECARD : LEAFCARD)) ? (n->branch[n->count].child == ((void *)0)) : 1) ; else __assert_fail ("(n->count < MAXKIDS(n)) ? (n->branch[n->count].child == NULL) : 1", "src/node.c", 236, __extension__ __PRETTY_FUNCTION__); }));
        return 0;
    }
    else
    {
        ((void) sizeof ((new_node) ? 1 : 0), __extension__ ({ if (new_node) ; else __assert_fail ("new_node", "src/node.c", 243, __extension__ __PRETTY_FUNCTION__); }));
        RTreeSplitNode(n, b, new_node);
        return 1;
    }
}

variable_types:
N
struct Node *

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


decompiled_code:
__int64 __fastcall nn_heap_parent(unsigned int a1)
{
return a1 >> 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return a1 >> 1;
}

original_code:
static unsigned
nn_heap_parent(unsigned u)
{
    return u / 2;
}

canonical_original_code:
static unsigned int nn_heap_parent(unsigned int u)
{
    return u / 2;
}

variable_types:
u
unsigned int

return_type: unsigned int


decompiled_code:
_BOOL8 __fastcall nn_heap_cmp(_QWORD *a1, unsigned int a2, unsigned int a3)
{
if ( !a1 )
_assert_fail("h != NULL", "src/nn_heap.c", 0x67u, "nn_heap_cmp");
return *(double *)(*(_QWORD *)(*a1 + 8LL * a3) + 16LL) > *(double *)(*(_QWORD *)(*a1 + 8LL * a2) + 16LL);
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD *a1, unsigned int a2, unsigned int a3)
{
if ( !a1 )
_assert_fail("h != NULL", "src/nn_heap.c", 0x67u, "nn_heap_cmp");
return *(double *)(*(_QWORD *)(*a1 + 8LL * a3) + 16LL) > *(double *)(*(_QWORD *)(*a1 + 8LL * a2) + 16LL);
}

original_code:
static int
nn_heap_cmp(struct nn_heap *h, unsigned u, unsigned v)
{
    ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "src/nn_heap.c", 103, __extension__ __PRETTY_FUNCTION__); }));
    return h->entries[u]->minDist < h->entries[v]->minDist;
}

canonical_original_code:
static int nn_heap_cmp(struct nn_heap *h, unsigned int u, unsigned int v)
{
    ((void) sizeof ((h != ((void *)0)) ? 1 : 0), __extension__ ({ if (h != ((void *)0)) ; else __assert_fail ("h != NULL", "src/nn_heap.c", 103, __extension__ __PRETTY_FUNCTION__); }));
    return h->entries[u]->minDist < h->entries[v]->minDist;
}

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

variable_types:
v
unsigned int

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

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


decompiled_code:
void __fastcall bubble_up(__int64 *a1, unsigned int a2)
{
unsigned int i; // ebx
unsigned int v3; // ebp

for ( i = a2; i > 1; nn_heap_swap(a1, v3, i) )
{
v3 = i;
i = nn_heap_parent(i);
if ( !nn_heap_cmp(a1, v3, i) )
break;
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 *a1, unsigned int a2)
{
unsigned int i; // ebx
unsigned int v3; // ebp

for ( i = a2; i > 1; func3(a1, v3, i) )
{
v3 = i;
i = func0(i);
if ( !func2(a1, v3, i) )
break;
}
}

original_code:
static void
bubble_up(struct nn_heap *h, unsigned u)
{
    unsigned v;
    while (u > 1) {
        v = nn_heap_parent(u);
        if (!nn_heap_cmp(h, u, v))
            break;
        nn_heap_swap(h, u, v);
        u = v;
    }
}

canonical_original_code:
static void bubble_up(struct nn_heap *h, unsigned int u)
{
    unsigned int v;
    while (u > 1) {
        v = nn_heap_parent(u);
        if (!nn_heap_cmp(h, u, v))
            break;
        nn_heap_swap(h, u, v);
        u = v;
    }
}


decompiled_code:
void __fastcall nn_heap_free(void *ptr)
{
unsigned int v1; // ebx

if ( *((_DWORD *)ptr + 2) > 1u )
{
v1 = 1;
do
free(*(void **)(*(_QWORD *)ptr + 8LL * v1++));
while ( *((_DWORD *)ptr + 2) > v1 );
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
unsigned int v1; // ebx

if ( *((_DWORD *)ptr + 2) > 1u )
{
v1 = 1;
do
free(*(void **)(*(_QWORD *)ptr + 8LL * v1++));
while ( *((_DWORD *)ptr + 2) > v1 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void
nn_heap_free(struct nn_heap *h)
{
    unsigned u;
    for (u = 1; u < h->next; u++) {
        free(h->entries[u]);
    }
    free(h->entries);
    free(h);
}

canonical_original_code:
void nn_heap_free(struct nn_heap *h)
{
    unsigned int u;
    for (u = 1; u < h->next; u++) {
        free(h->entries[u]);
    }
    free(h->entries);
    free(h);
}


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

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

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

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


decompiled_code:
__int64 __fastcall nn_heap_push(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // ebp
void *v4; // rax
unsigned int i; // eax
_QWORD *v6; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // ebp
void *v4; // rax
unsigned int i; // eax
_QWORD *v6; // rdx

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

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

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

variable_types:
e
struct nn_entry *


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

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

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

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

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

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


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

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

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

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

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


RTreeFreeListNode

decompiled_code:
void __fastcall RTreeFreeListNode(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
free(a1);
}

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

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

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


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

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

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

variable_types: tid long

variable_types: level int

variable_types: i int

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

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


RTreeNewListNode

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

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

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

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

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


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

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

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

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

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

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

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

variable_types: Tid long

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

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

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


RTreeNewIndex

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

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

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

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

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

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


RTreeSearch

decompiled_code:
__int64 __fastcall RTreeSearch(__int64 a1, __int64 a2, unsigned int (__fastcall *a3)(_QWORD, __int64), __int64 a4)
{
int v5; // eax
unsigned int i; // er13
__int64 v7; // rbx
int v8; // ebp
__int64 v9; // rbx
int v10; // ebp

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int (__fastcall *a3)(_QWORD, __int64), __int64 a4)
{
int v5; // eax
unsigned int i; // er13
__int64 v7; // rbx
int v8; // ebp
__int64 v9; // rbx
int v10; // ebp

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

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

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

variable_types:
R
struct Rect *

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

variable_types:
cbarg
void *

variable_types: hitCount int


RTreeInsertRect

decompiled_code:
__int64 __fastcall RTreeInsertRect(__int64 a1, int a2, __int64 *a3, int a4)
{
__int64 v5; // rdx
__int64 result; // rax
__int64 v7; // rbp
__m128i v8; // [rsp+0h] [rbp-68h] BYREF
__m128i v9; // [rsp+10h] [rbp-58h] BYREF
__m128i v10; // [rsp+20h] [rbp-48h] BYREF
__m128i v11; // [rsp+30h] [rbp-38h]
__int64 v12; // [rsp+40h] [rbp-28h]
__int64 v13[4]; // [rsp+48h] [rbp-20h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, __int64 *a3, int a4)
{
__int64 v5; // rdx
__int64 result; // rax
__int64 v7; // rbp
__m128i v8; // [rsp+0h] [rbp-68h] BYREF
__m128i v9; // [rsp+10h] [rbp-58h] BYREF
__m128i v10; // [rsp+20h] [rbp-48h] BYREF
__m128i v11; // [rsp+30h] [rbp-38h]
__int64 v12; // [rsp+40h] [rbp-28h]
__int64 v13[4]; // [rsp+48h] [rbp-20h] BYREF

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

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

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

variable_types: Tid int

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

variable_types: Level int

variable_types: tid int

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

variable_types: result int


RTreeDeleteRect

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

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

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

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

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

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

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

variable_types: i int

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


RTreeRectMinDistance

decompiled_code:
double __fastcall RTreeRectMinDistance(double *a1, double *a2)
{
double v2; // xmm1_8
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm2_8
double v7; // xmm2_8
double result; // xmm0_8

v2 = *a2;
if ( *a1 > *a2 )
{
v4 = (*a1 - v2) * (*a1 - v2) + 0.0;
}
else
{
v3 = a1[2];
if ( v2 > v3 )
v4 = (v2 - v3) * (v2 - v3) + 0.0;
else
v4 = 0.0;
}
v5 = a2[1];
v6 = a1[1];
if ( v6 > v5 )
{
v4 = v4 + (v6 - v5) * (v6 - v5);
}
else
{
v7 = a1[3];
if ( v5 > v7 )
v4 = v4 + (v5 - v7) * (v5 - v7);
}
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
return result;
}

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

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

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

variable_types:
pt
double [2]

variable_types: ret double

return_type: double


RTreeInitRect

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

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

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


RTreePrintRect

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

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

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

variable_types: depth int