sameform

decompiled_code:
__int64 __fastcall sameform(__int128 a1)
{
bool v1; // dl
__int64 v2; // r12
__int64 v3; // rbp
__int16 v4; // bx
const char **v5; // r13
const char **v6; // rax
__int64 v7; // rdi
const char **v9; // rax

v1 = (_QWORD)a1 == 0LL;
if ( a1 == 0 )
return 1LL;
if ( !*((_QWORD *)&a1 + 1) )
return 0LL;
v2 = *((_QWORD *)&a1 + 1);
v3 = a1;
while ( !v1 )
{
v4 = *(_WORD *)v3;
if ( *(_WORD *)v3 != *(_WORD *)v2 )
break;
v5 = *(const char ***)(v3 + 8);
if ( v5 )
{
v6 = *(const char ***)(v2 + 8);
if ( v6 )
{
if ( strcmp(*v5, *v6) )
break;
}
}
v7 = (unsigned int)v4;
switch ( v4 )
{
case 258:
case 264:
return sametrees(v7, v3, v2);
case 261:
case 266:
return 1LL;
case 263:
case 269:
v3 = *(_QWORD *)(v3 + 16);
v2 = *(_QWORD *)(v2 + 16);
v1 = v2 == 0;
if ( !(v3 | v2) )
return 1LL;
if ( !v3 )
return 0LL;
break;
case 265:
if ( !v5 || (v9 = *(const char ***)(v2 + 8)) == 0LL )
{
fatal("sameform...", 0LL);
v9 = *(const char ***)(v2 + 8);
v5 = *(const char ***)(v3 + 8);
}
return strcmp(*v5, *v9) == 0;
case 267:
case 268:
if ( !(unsigned int)sameform(*(_QWORD *)(v3 + 16), *(_QWORD *)(v2 + 16)) )
return 0LL;
return (unsigned int)sameform(*(_QWORD *)(v3 + 24), *(_QWORD *)(v2 + 24)) != 0;
default:
printf("type: %d\n", (unsigned int)v7);
fatal("cannot happen, sameform", 0LL);
return 0LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int128 a1)
{
bool v1; // dl
__int64 v2; // r12
__int64 v3; // rbp
__int16 v4; // bx
const char **v5; // r13
const char **v6; // rax
__int64 v7; // rdi
const char **v9; // rax

v1 = (_QWORD)a1 == 0LL;
if ( a1 == 0 )
return 1LL;
if ( !*((_QWORD *)&a1 + 1) )
return 0LL;
v2 = *((_QWORD *)&a1 + 1);
v3 = a1;
while ( !v1 )
{
v4 = *(_WORD *)v3;
if ( *(_WORD *)v3 != *(_WORD *)v2 )
break;
v5 = *(const char ***)(v3 + 8);
if ( v5 )
{
v6 = *(const char ***)(v2 + 8);
if ( v6 )
{
if ( strcmp(*v5, *v6) )
break;
}
}
v7 = (unsigned int)v4;
switch ( v4 )
{
case 258:
case 264:
return func10(v7, v3, v2);
case 261:
case 266:
return 1LL;
case 263:
case 269:
v3 = *(_QWORD *)(v3 + 16);
v2 = *(_QWORD *)(v2 + 16);
v1 = v2 == 0;
if ( !(v3 | v2) )
return 1LL;
if ( !v3 )
return 0LL;
break;
case 265:
if ( !v5 || (v9 = *(const char ***)(v2 + 8)) == 0LL )
{
fatal("sameform...", 0LL);
v9 = *(const char ***)(v2 + 8);
v5 = *(const char ***)(v3 + 8);
}
return strcmp(*v5, *v9) == 0;
case 267:
case 268:
if ( !(unsigned int)func7(*(_QWORD *)(v3 + 16), *(_QWORD *)(v2 + 16)) )
return 0LL;
return (unsigned int)func7(*(_QWORD *)(v3 + 24), *(_QWORD *)(v2 + 24)) != 0;
default:
printf("type: %d\n", (unsigned int)v7);
fatal("cannot happen, sameform", 0LL);
return 0LL;
}
}
return 0LL;
}

original_code:
int
sameform(Node *a, Node *b)
{
 if (!a && !b) return 1;
 if (!a || !b) return 0;
 if (a->ntyp != b->ntyp) return 0;
 if (a->sym
 && b->sym
 && strcmp(a->sym->name, b->sym->name) != 0)
  return 0;
 switch (a->ntyp) {
 case TRUE:
 case FALSE:
  return 1;
 case PREDICATE:
  if (!a->sym || !b->sym) fatal("sameform...", (char *) 0);
  return !strcmp(a->sym->name, b->sym->name);
 case NOT:
 case NEXT:
  return sameform(a->lft, b->lft);
 case U_OPER:
 case V_OPER:
  if (!sameform(a->lft, b->lft))
   return 0;
  if (!sameform(a->rgt, b->rgt))
   return 0;
  return 1;
 case AND:
 case OR:
  return sametrees(a->ntyp, a, b);
 default:
  printf("type: %d\n", a->ntyp);
  fatal("cannot happen, sameform", (char *) 0);
 }
 return 0;
}

canonical_original_code:
int sameform(struct Node *a, struct Node *b)
{
 if (!a && !b) return 1;
 if (!a || !b) return 0;
 if (a->ntyp != b->ntyp) return 0;
 if (a->sym
 && b->sym
 && strcmp(a->sym->name, b->sym->name) != 0)
  return 0;
 switch (a->ntyp) {
 case TRUE:
 case FALSE:
  return 1;
 case PREDICATE:
  if (!a->sym || !b->sym) fatal("sameform...", (char *) 0);
  return !strcmp(a->sym->name, b->sym->name);
 case NOT:
 case NEXT:
  return sameform(a->lft, b->lft);
 case U_OPER:
 case V_OPER:
  if (!sameform(a->lft, b->lft))
   return 0;
  if (!sameform(a->rgt, b->rgt))
   return 0;
  return 1;
 case AND:
 case OR:
  return sametrees(a->ntyp, a, b);
 default:
  printf("type: %d\n", a->ntyp);
  fatal("cannot happen, sameform", (char *) 0);
 }
 return 0;
}


decompiled_code:
__int64 __fastcall one_lft(unsigned int a1, __int64 a2, __int16 *a3)
{
__int16 *v5; // rbx
__int128 v6; // rdi

if ( !a2 )
return 1LL;
v5 = a3;
if ( !a3 )
return 0LL;
while ( 1 )
{
*((_QWORD *)&v6 + 1) = v5;
*(_QWORD *)&v6 = a2;
if ( (unsigned int)sameform(v6) )
break;
if ( *v5 != a1 )
return 0LL;
if ( (unsigned int)one_lft(a1, a2, *((_QWORD *)v5 + 2)) )
break;
v5 = (__int16 *)*((_QWORD *)v5 + 3);
if ( !v5 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, __int64 a2, __int16 *a3)
{
__int16 *v5; // rbx
__int128 v6; // rdi

if ( !a2 )
return 1LL;
v5 = a3;
if ( !a3 )
return 0LL;
while ( 1 )
{
*((_QWORD *)&v6 + 1) = v5;
*(_QWORD *)&v6 = a2;
if ( (unsigned int)func7(v6) )
break;
if ( *v5 != a1 )
return 0LL;
if ( (unsigned int)func8(a1, a2, *((_QWORD *)v5 + 2)) )
break;
v5 = (__int16 *)*((_QWORD *)v5 + 3);
if ( !v5 )
return 0LL;
}
return 1LL;
}

original_code:
int
one_lft(int ntyp, Node *x, Node *in)
{
 if (!x) return 1;
 if (!in) return 0;
 if (sameform(x, in))
  return 1;
 if (in->ntyp != ntyp)
  return 0;
 if (one_lft(ntyp, x, in->lft))
  return 1;
 return one_lft(ntyp, x, in->rgt);
}

canonical_original_code:
int one_lft(int ntyp, struct Node *x, struct Node *in)
{
 if (!x) return 1;
 if (!in) return 0;
 if (sameform(x, in))
  return 1;
 if (in->ntyp != ntyp)
  return 0;
 if (one_lft(ntyp, x, in->lft))
  return 1;
 return one_lft(ntyp, x, in->rgt);
}

variable_types: ntyp int

variable_types: struct Node { short ntyp; struct Symbol { char *name; struct Symbol *next; } *sym; struct Node *lft; struct Node *rgt; struct Node *nxt; } *

variable_types:
in
struct Node *

return_type: int

user_defined_types: struct Node { short ntyp; struct Symbol *sym; struct Node *lft; struct Node *rgt; struct Node *nxt; }


decompiled_code:
__int64 __fastcall all_lfts(unsigned int a1, __int16 *a2, __int16 *a3)
{
__int16 *v4; // rbp
__int64 result; // rax

if ( !a2 )
return 1LL;
v4 = a2;
do
{
if ( *v4 != a1 )
return one_lft(a1, (__int64)v4, a3);
result = one_lft(a1, *((_QWORD *)v4 + 2), a3);
if ( !(_DWORD)result )
return result;
v4 = (__int16 *)*((_QWORD *)v4 + 3);
}
while ( v4 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, __int16 *a2, __int16 *a3)
{
__int16 *v4; // rbp
__int64 result; // rax

if ( !a2 )
return 1LL;
v4 = a2;
do
{
if ( *v4 != a1 )
return func8(a1, (__int64)v4, a3);
result = func8(a1, *((_QWORD *)v4 + 2), a3);
if ( !(_DWORD)result )
return result;
v4 = (__int16 *)*((_QWORD *)v4 + 3);
}
while ( v4 );
return 1LL;
}

original_code:
int
all_lfts(int ntyp, Node *from, Node *in)
{
 if (!from) return 1;
 if (from->ntyp != ntyp)
  return one_lft(ntyp, from, in);
 if (!one_lft(ntyp, from->lft, in))
  return 0;
 return all_lfts(ntyp, from->rgt, in);
}

canonical_original_code:
int all_lfts(int ntyp, struct Node *from, struct Node *in)
{
 if (!from) return 1;
 if (from->ntyp != ntyp)
  return one_lft(ntyp, from, in);
 if (!one_lft(ntyp, from->lft, in))
  return 0;
 return all_lfts(ntyp, from->rgt, in);
}

user_defined_types: struct Symbol { char *name; struct Symbol *next; }


sametrees

decompiled_code:
__int64 __fastcall sametrees(unsigned int a1, __int16 *a2, __int16 *a3)
{
__int64 result; // rax

if ( (unsigned int)all_lfts(a1, a2, a3) )
result = all_lfts(a1, a3, a2);
else
result = 0LL;
return result;
}

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

if ( (unsigned int)func9(a1, a2, a3) )
result = func9(a1, a3, a2);
else
result = 0LL;
return result;
}

original_code:
int
sametrees(int ntyp, Node *a, Node *b)
{
 if (!all_lfts(ntyp, a, b))
  return 0;
 return all_lfts(ntyp, b, a);
}

canonical_original_code:
int sametrees(int ntyp, struct Node *a, struct Node *b)
{
 if (!all_lfts(ntyp, a, b))
  return 0;
 return all_lfts(ntyp, b, a);
}

variable_types:
b
struct Node *


isequal

decompiled_code:
__int64 __fastcall isequal(__int128 a1)
{
const char **v1; // rax
const char **v2; // rdx

if ( a1 != 0 )
{
if ( (_QWORD)a1 )
{
if ( *((_QWORD *)&a1 + 1) )
{
if ( *(_WORD *)a1 == **((_WORD **)&a1 + 1) )
{
v1 = *(const char ***)(a1 + 8);
if ( !v1 || (v2 = *(const char ***)(*((_QWORD *)&a1 + 1) + 8LL)) == 0LL || !strcmp(*v1, *v2) )
{
if ( !(unsigned int)isequal(*(_QWORD *)(a1 + 16), *(_QWORD *)(*((_QWORD *)&a1 + 1) + 16LL))
|| !(unsigned int)isequal(*(_QWORD *)(a1 + 24), *(_QWORD *)(*((_QWORD *)&a1 + 1) + 24LL)) )
{
return sameform(a1);
}
return 1LL;
}
}
return 0LL;
}
if ( *(_WORD *)a1 != 266 )
return 0LL;
}
else if ( **((_WORD **)&a1 + 1) != 266 )
{
return 0LL;
}
return 1LL;
}
return 1LL;
}

original_code:
int
isequal(Node *a, Node *b)
{
 if (!a && !b)
  return 1;
 if (!a || !b)
 { if (!a)
  { if (b->ntyp == TRUE)
    return 1;
  } else
  { if (a->ntyp == TRUE)
    return 1;
  }
  return 0;
 }
 if (a->ntyp != b->ntyp)
  return 0;
 if (a->sym
 && b->sym
 && strcmp(a->sym->name, b->sym->name) != 0)
  return 0;
 if (isequal(a->lft, b->lft)
 && isequal(a->rgt, b->rgt))
  return 1;
 return sameform(a, b);
}

canonical_original_code:
int isequal(struct Node *a, struct Node *b)
{
 if (!a && !b)
  return 1;
 if (!a || !b)
 { if (!a)
  { if (b->ntyp == TRUE)
    return 1;
  } else
  { if (a->ntyp == TRUE)
    return 1;
  }
  return 0;
 }
 if (a->ntyp != b->ntyp)
  return 0;
 if (a->sym
 && b->sym
 && strcmp(a->sym->name, b->sym->name) != 0)
  return 0;
 if (isequal(a->lft, b->lft)
 && isequal(a->rgt, b->rgt))
  return 1;
 return sameform(a, b);
}


decompiled_code:
__int64 __fastcall in_cache(__int64 a1)
{
__int64 v1; // rbx
__int128 v3; // rdi
int v4; // eax
__int128 v5; // rdi
__int64 result; // rax

v1 = stored;
if ( !stored )
return 0LL;
while ( 1 )
{
*(_QWORD *)&v3 = *(_QWORD *)v1;
*((_QWORD *)&v3 + 1) = a1;
if ( (unsigned int)isequal(v3) )
break;
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return 0LL;
}
v4 = *(_DWORD *)(v1 + 16);
++CacheHits;
if ( v4 && (*((_QWORD *)&v5 + 1) = *(_QWORD *)v1, *(_QWORD *)&v5 = a1, (unsigned int)ismatch(v5)) )
result = a1;
else
result = dupnode(*(_QWORD *)(v1 + 8));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // rbx
__int128 v3; // rdi
int v4; // eax
__int128 v5; // rdi
__int64 result; // rax

v1 = stored;
if ( !stored )
return 0LL;
while ( 1 )
{
*(_QWORD *)&v3 = *(_QWORD *)v1;
*((_QWORD *)&v3 + 1) = a1;
if ( (unsigned int)func11(v3) )
break;
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return 0LL;
}
v4 = *(_DWORD *)(v1 + 16);
++CacheHits;
if ( v4 && (*((_QWORD *)&v5 + 1) = *(_QWORD *)v1, *(_QWORD *)&v5 = a1, (unsigned int)func0(v5)) )
result = a1;
else
result = func6(*(_QWORD *)(v1 + 8));
return result;
}

original_code:
Node *
in_cache(Node *n)
{ Cache *d; int nr=0;
 for (d = stored; d; d = d->nxt, nr++)
  if (isequal(d->before, n))
  { CacheHits++;
   if (d->same && ismatch(n, d->before)) return n;
   return dupnode(d->after);
  }
 return (Node *)0;
}

canonical_original_code:
struct Node *in_cache(struct Node *n)
{ struct Cache *d; int nr = 0;
 for (d = stored; d; d = d->nxt, nr++)
  if (isequal(d->before, n))
  { CacheHits++;
   if (d->same && ismatch(n, d->before)) return n;
   return dupnode(d->after);
  }
 return (struct Node *)0;
}

variable_types:
n
struct Node *

variable_types: struct Cache { struct Node { short ntyp; struct Symbol { char *name; struct Symbol *next; } *sym; struct Node *lft; struct Node *rgt; struct Node *nxt; } *before; struct Node *after; int same; struct Cache *nxt; } *

variable_types: nr int

user_defined_types: struct Cache { struct Node *before; struct Node *after; int same; struct Cache *nxt; }


cached

decompiled_code:
__int64 __fastcall cached(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // rax
__int128 v4; // rdi
__int64 v5; // rbp
__int64 v6; // rax

if ( !a1 )
return 0LL;
result = in_cache(a1);
if ( !result )
{
++Caches;
v2 = tl_emalloc(32LL);
*(_QWORD *)v2 = dupnode(a1);
v3 = Canonical(a1);
*(_QWORD *)&v4 = *(_QWORD *)v2;
*(_QWORD *)(v2 + 8) = v3;
*((_QWORD *)&v4 + 1) = v3;
v5 = v3;
if ( (unsigned int)ismatch(v4) )
{
*(_DWORD *)(v2 + 16) = 1;
releasenode(1, v5);
v5 = *(_QWORD *)v2;
*(_QWORD *)(v2 + 8) = *(_QWORD *)v2;
}
v6 = stored;
stored = v2;
*(_QWORD *)(v2 + 24) = v6;
result = dupnode(v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // rax
__int128 v4; // rdi
__int64 v5; // rbp
__int64 v6; // rax

if ( !a1 )
return 0LL;
result = func12(a1);
if ( !result )
{
++Caches;
v2 = tl_emalloc(32LL);
*(_QWORD *)v2 = func6(a1);
v3 = Canonical(a1);
*(_QWORD *)&v4 = *(_QWORD *)v2;
*(_QWORD *)(v2 + 8) = v3;
*((_QWORD *)&v4 + 1) = v3;
v5 = v3;
if ( (unsigned int)func0(v4) )
{
*(_DWORD *)(v2 + 16) = 1;
func3(1, v5);
v5 = *(_QWORD *)v2;
*(_QWORD *)(v2 + 8) = *(_QWORD *)v2;
}
v6 = stored;
stored = v2;
*(_QWORD *)(v2 + 24) = v6;
result = func6(v5);
}
return result;
}

original_code:
Node *
cached(Node *n)
{ Cache *d;
 Node *m;
 if (!n) return n;
 if (m = in_cache(n))
  return m;
 Caches++;
 d = (Cache *) tl_emalloc(sizeof(Cache));
 d->before = dupnode(n);
 d->after = Canonical(n);
 if (ismatch(d->before, d->after))
 { d->same = 1;
  releasenode(1, d->after);
  d->after = d->before;
 }
 d->nxt = stored;
 stored = d;
 return dupnode(d->after);
}

canonical_original_code:
struct Node *cached(struct Node *n)
{ struct Cache *d;
 struct Node *m;
 if (!n) return n;
 if (m = in_cache(n))
  return m;
 Caches++;
 d = (struct Cache *) tl_emalloc(sizeof(Cache));
 d->before = dupnode(n);
 d->after = Canonical(n);
 if (ismatch(d->before, d->after))
 { d->same = 1;
  releasenode(1, d->after);
  d->after = d->before;
 }
 d->nxt = stored;
 stored = d;
 return dupnode(d->after);
}

return_type: struct Node { short ntyp; struct Symbol { char *name; struct Symbol *next; } *sym; struct Node *lft; struct Node *rgt; struct Node *nxt; } *


decompiled_code:
__int64 __fastcall any_term(__int64 a1, __int64 a2)
{
__int128 v3; // rdi
__int64 result; // rax
int v5; // er8

if ( !a2 )
return 0LL;
if ( *(_WORD *)a2 == 258 )
{
v5 = any_term(a1, *(_QWORD *)(a2 + 16));
result = 1LL;
if ( !v5 )
result = (unsigned int)any_term(a1, *(_QWORD *)(a2 + 24)) != 0;
}
else
{
*((_QWORD *)&v3 + 1) = a1;
*(_QWORD *)&v3 = a2;
result = isequal(v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
__int128 v3; // rdi
__int64 result; // rax
int v5; // er8

if ( !a2 )
return 0LL;
if ( *(_WORD *)a2 == 258 )
{
v5 = func14(a1, *(_QWORD *)(a2 + 16));
result = 1LL;
if ( !v5 )
result = (unsigned int)func14(a1, *(_QWORD *)(a2 + 24)) != 0;
}
else
{
*((_QWORD *)&v3 + 1) = a1;
*(_QWORD *)&v3 = a2;
result = func11(v3);
}
return result;
}

original_code:
int
any_term(Node *srch, Node *in)
{
 if (!in) return 0;
 if (in->ntyp == AND)
  return any_term(srch, in->lft) ||
   any_term(srch, in->rgt);
 return isequal(in, srch);
}

canonical_original_code:
int any_term(struct Node *srch, struct Node *in)
{
 if (!in) return 0;
 if (in->ntyp == AND)
  return any_term(srch, in->lft) ||
   any_term(srch, in->rgt);
 return isequal(in, srch);
}


decompiled_code:
__int64 __fastcall any_and(__int64 a1, __int64 a2)
{
if ( !a2 )
return 0LL;
if ( *(_WORD *)a1 != 258 )
return any_term(a1, a2);
if ( (unsigned int)any_and(*(_QWORD *)(a1 + 16)) )
return (unsigned int)any_and(*(_QWORD *)(a1 + 24)) != 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
if ( !a2 )
return 0LL;
if ( *(_WORD *)a1 != 258 )
return func14(a1, a2);
if ( (unsigned int)func15(*(_QWORD *)(a1 + 16)) )
return (unsigned int)func15(*(_QWORD *)(a1 + 24)) != 0;
return 0LL;
}

original_code:
int
any_and(Node *srch, Node *in)
{
 if (!in) return 0;
 if (srch->ntyp == AND)
  return any_and(srch->lft, in) &&
   any_and(srch->rgt, in);
 return any_term(srch, in);
}

canonical_original_code:
int any_and(struct Node *srch, struct Node *in)
{
 if (!in) return 0;
 if (srch->ntyp == AND)
  return any_and(srch->lft, in) &&
   any_and(srch->rgt, in);
 return any_term(srch, in);
}


decompiled_code:
__int64 __fastcall any_lor(__int64 a1, __int64 a2)
{
__int128 v3; // rdi
__int64 result; // rax
int v5; // er8

if ( !a2 )
return 0LL;
if ( *(_WORD *)a2 == 264 )
{
v5 = any_lor(a1, *(_QWORD *)(a2 + 16));
result = 1LL;
if ( !v5 )
result = (unsigned int)any_lor(a1, *(_QWORD *)(a2 + 24)) != 0;
}
else
{
*((_QWORD *)&v3 + 1) = a1;
*(_QWORD *)&v3 = a2;
result = isequal(v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2)
{
__int128 v3; // rdi
__int64 result; // rax
int v5; // er8

if ( !a2 )
return 0LL;
if ( *(_WORD *)a2 == 264 )
{
v5 = func16(a1, *(_QWORD *)(a2 + 16));
result = 1LL;
if ( !v5 )
result = (unsigned int)func16(a1, *(_QWORD *)(a2 + 24)) != 0;
}
else
{
*((_QWORD *)&v3 + 1) = a1;
*(_QWORD *)&v3 = a2;
result = func11(v3);
}
return result;
}

original_code:
int
any_lor(Node *srch, Node *in)
{
 if (!in) return 0;
 if (in->ntyp == OR)
  return any_lor(srch, in->lft) ||
   any_lor(srch, in->rgt);
 return isequal(in, srch);
}

canonical_original_code:
int any_lor(struct Node *srch, struct Node *in)
{
 if (!in) return 0;
 if (in->ntyp == OR)
  return any_lor(srch, in->lft) ||
   any_lor(srch, in->rgt);
 return isequal(in, srch);
}


anywhere

decompiled_code:
__int64 __fastcall anywhere(int a1, __int64 a2, __int64 a3)
{
if ( !a3 )
return 0LL;
switch ( a1 )
{
case 258:
return any_and(a2, a3);
case 264:
return any_lor(a2, a3);
case 0:
return any_term(a2, a3);
}
fatal("cannot happen, anywhere", 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(int a1, __int64 a2, __int64 a3)
{
if ( !a3 )
return 0LL;
switch ( a1 )
{
case 258:
return func15(a2, a3);
case 264:
return func16(a2, a3);
case 0:
return func14(a2, a3);
}
fatal("cannot happen, anywhere", 0LL);
return 0LL;
}

original_code:
int
anywhere(int tok, Node *srch, Node *in)
{
 if (!in) return 0;
 switch (tok) {
 case AND: return any_and(srch, in);
 case OR: return any_lor(srch, in);
 case 0: return any_term(srch, in);
 }
 fatal("cannot happen, anywhere", (char *) 0);
 return 0;
}

canonical_original_code:
int anywhere(int tok, struct Node *srch, struct Node *in)
{
 if (!in) return 0;
 switch (tok) {
 case AND: return any_and(srch, in);
 case OR: return any_lor(srch, in);
 case 0: return any_term(srch, in);
 }
 fatal("cannot happen, anywhere", (char *) 0);
 return 0;
}

variable_types: tok int


repo: sluchin/calc

decompiled_code:
__int64 __fastcall set_hostname(struct in_addr *a1, const char *a2)
{
struct hostent *v3; // rax
__int64 v4; // rax
struct in_addr inp; // [rsp+0h] [rbp-1Ch] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
inp.s_addr = 0;
if ( !inet_aton(a2, &inp) )
{
v3 = gethostbyname(a2);
if ( !v3 )
{
v4 = get_progname();
system_log(6LL, 1LL, v4, "net.c", 70LL, "set_hostname", "gethostbyname: host=%s", a2);
return 0xFFFFFFFFLL;
}
memcpy(&inp, *(const void **)v3->h_addr_list, v3->h_length);
}
a1[1].s_addr = inp.s_addr;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(struct in_addr *a1, const char *a2)
{
struct hostent *v3; // rax
__int64 v4; // rax
struct in_addr inp; // [rsp+0h] [rbp-1Ch] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
inp.s_addr = 0;
if ( !inet_aton(a2, &inp) )
{
v3 = gethostbyname(a2);
if ( !v3 )
{
v4 = get_progname();
system_log(6LL, 1LL, v4, "net.c", 70LL, "set_hostname", "gethostbyname: host=%s", a2);
return 0xFFFFFFFFLL;
}
memcpy(&inp, *(const void **)v3->h_addr_list, v3->h_length);
}
a1[1].s_addr = inp.s_addr;
return 0LL;
}

original_code:
int
set_hostname(struct sockaddr_in *addr, const char *host)
{
    struct hostent *hp = ((void *)0);
    struct in_addr s_addr;
    int retval = 0;
    do { } while (0);
    if (!addr || !host)
        return EX_NG;
    (void)memset(&s_addr, 0, sizeof(struct in_addr));
    retval = inet_aton(host, &s_addr);
    if (!retval) {
        do { } while (0);
        hp = gethostbyname(host);
        if (!hp) {
            system_log(6, 0x01, get_progname(), "net.c", 70, __FUNCTION__, "gethostbyname: host=%s", host);
            return EX_NG;
        }
        do { } while (0);
        (void)memcpy(&s_addr, (struct in_addr *)*hp->h_addr_list,
                     hp->h_length);
    }
    (void)memcpy(&addr->sin_addr, &s_addr, sizeof(struct in_addr));
    do { } while (0);
    return EX_OK;
}

canonical_original_code:
int set_hostname(struct sockaddr_in *addr, char *host)
{
    struct hostent *hp = ((void *)0);
    struct in_addr s_addr;
    int retval = 0;
    do { } while (0);
    if (!addr || !host)
        return EX_NG;
    (void)memset(&s_addr, 0, sizeof(struct in_addr));
    retval = inet_aton(host, &s_addr);
    if (!retval) {
        do { } while (0);
        hp = gethostbyname(host);
        if (!hp) {
            system_log(6, 0x01, get_progname(), "net.c", 70, __FUNCTION__, "gethostbyname: host=%s", host);
            return EX_NG;
        }
        do { } while (0);
        (void)memcpy(&s_addr, (struct in_addr *)*hp->h_addr_list,
                     hp->h_length);
    }
    (void)memcpy(&addr->sin_addr, &s_addr, sizeof(struct in_addr));
    do { } while (0);
    return EX_OK;
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types:
host
char *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: retval int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


decompiled_code:
__int64 __fastcall set_port(__int64 a1, const char *a2)
{
struct servent *v3; // rax
__int16 v5; // di
__int64 v6; // rax
__int64 v7; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
if ( ((*_ctype_b_loc())[*a2] & 0x800) != 0 )
{
v5 = strtol(a2, 0LL, 10);
if ( (unsigned __int16)(v5 - 1) <= 0xFFFDu )
{
*(_WORD *)(a1 + 2) = _bswap_16(v5);
return 0LL;
}
v6 = get_progname();
system_log(6LL, 1LL, v6, "net.c", 111LL, "set_port", "portno=%d");
return 0xFFFFFFFFLL;
}
v3 = getservbyname(a2, "tcp");
if ( !v3 )
{
v7 = get_progname();
system_log(6LL, 1LL, v7, "net.c", 119LL, "set_port", "getservbyname: port=%s");
return 0xFFFFFFFFLL;
}
*(_WORD *)(a1 + 2) = v3->s_port;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
struct servent *v3; // rax
__int16 v5; // di
__int64 v6; // rax
__int64 v7; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
if ( ((*_ctype_b_loc())[*a2] & 0x800) != 0 )
{
v5 = strtol(a2, 0LL, 10);
if ( (unsigned __int16)(v5 - 1) <= 0xFFFDu )
{
*(_WORD *)(a1 + 2) = func0(v5);
return 0LL;
}
v6 = get_progname();
system_log(6LL, 1LL, v6, "net.c", 111LL, "set_port", "portno=%d");
return 0xFFFFFFFFLL;
}
v3 = getservbyname(a2, "tcp");
if ( !v3 )
{
v7 = get_progname();
system_log(6LL, 1LL, v7, "net.c", 119LL, "set_port", "getservbyname: port=%s");
return 0xFFFFFFFFLL;
}
*(_WORD *)(a1 + 2) = v3->s_port;
return 0LL;
}

original_code:
int
set_port(struct sockaddr_in *addr, const char *port)
{
    struct servent *sp = ((void *)0);
    uint16_t portno = 0;
    const int base = 10;
    do { } while (0);
    if (!addr || !port)
        return EX_NG;
    if (((*__ctype_b_loc ())[(int) ((port[0]))] & (unsigned short int) _ISdigit)) {
        portno = (uint16_t)strtol(port, ((void *)0), base);
        do { } while (0);
        if (portno <= 0 || 65535 <= portno) {
            system_log(6, 0x01, get_progname(), "net.c", 111, __FUNCTION__, "portno=%d", portno);
            return EX_NG;
        }
        do { } while (0);
        addr->sin_port = (u_short)htons(portno);
    } else {
        sp = getservbyname(port, "tcp");
        if (!sp) {
            system_log(6, 0x01, get_progname(), "net.c", 119, __FUNCTION__, "getservbyname: port=%s", port);
            return EX_NG;
        }
        addr->sin_port = sp->s_port;
    }
    do { } while (0);
    return EX_OK;
}

canonical_original_code:
int set_port(struct sockaddr_in *addr, char *port)
{
    struct servent *sp = ((void *)0);
    unsigned short portno = 0;
    int base = 10;
    do { } while (0);
    if (!addr || !port)
        return EX_NG;
    if (((*__ctype_b_loc ())[(int) ((port[0]))] & (unsigned short) _ISdigit)) {
        portno = (unsigned short)strtol(port, ((void *)0), base);
        do { } while (0);
        if (portno <= 0 || 65535 <= portno) {
            system_log(6, 0x01, get_progname(), "net.c", 111, __FUNCTION__, "portno=%d", portno);
            return EX_NG;
        }
        do { } while (0);
        addr->sin_port = (unsigned short)htons(portno);
    } else {
        sp = getservbyname(port, "tcp");
        if (!sp) {
            system_log(6, 0x01, get_progname(), "net.c", 119, __FUNCTION__, "getservbyname: port=%s", port);
            return EX_NG;
        }
        addr->sin_port = sp->s_port;
    }
    do { } while (0);
    return EX_OK;
}

variable_types:
port
char *

variable_types: struct servent { char *s_name; char **s_aliases; int s_port; char *s_proto; } *

variable_types:
portno
unsigned short

variable_types: base int


decompiled_code:
__int64 __fastcall set_block(__int64 fd, int a2)
{
unsigned int v2; // eax
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v6; // rdx
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax

v2 = fcntl(fd, 3, 0LL);
v3 = v2;
if ( (v2 & 0x80000000) != 0 )
{
v10 = get_progname(fd, 3LL, v2);
system_log(6LL, 1LL, v10, "net.c", 143LL, "set_block", "fcntl=0x%x");
}
else
{
if ( !a2 )
{
BYTE1(v3) = BYTE1(v2) | 8;
if ( fcntl(fd, 4, v3) < 0 )
{
v7 = get_progname((unsigned int)fd, 4LL, v6);
system_log(6LL, 1LL, v7, "net.c", 151LL, "set_block", "fcntl=%d");
}
return 0LL;
}
if ( a2 == 1 )
{
BYTE1(v3) = BYTE1(v2) & 0xF7;
if ( fcntl(fd, 4, v3) < 0 )
{
v8 = get_progname((unsigned int)fd, 4LL, v4);
system_log(6LL, 1LL, v8, "net.c", 155LL, "set_block", "fcntl=%d");
}
return 0LL;
}
v9 = get_progname(fd, 3LL, v2);
system_log(6LL, 1LL, v9, "net.c", 157LL, "set_block", "mode=%d");
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 fd, int a2)
{
unsigned int v2; // eax
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v6; // rdx
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax

v2 = fcntl(fd, 3, 0LL);
v3 = v2;
if ( (v2 & 0x80000000) != 0 )
{
v10 = get_progname(fd, 3LL, v2);
system_log(6LL, 1LL, v10, "net.c", 143LL, "set_block", "fcntl=0x%x");
}
else
{
if ( !a2 )
{
BYTE1(v3) = BYTE1(v2) | 8;
if ( fcntl(fd, 4, v3) < 0 )
{
v7 = get_progname((unsigned int)fd, 4LL, v6);
system_log(6LL, 1LL, v7, "net.c", 151LL, "set_block", "fcntl=%d");
}
return 0LL;
}
if ( a2 == 1 )
{
BYTE1(v3) = BYTE1(v2) & 0xF7;
if ( fcntl(fd, 4, v3) < 0 )
{
v8 = get_progname((unsigned int)fd, 4LL, v4);
system_log(6LL, 1LL, v8, "net.c", 155LL, "set_block", "fcntl=%d");
}
return 0LL;
}
v9 = get_progname(fd, 3LL, v2);
system_log(6LL, 1LL, v9, "net.c", 157LL, "set_block", "mode=%d");
}
return 0xFFFFFFFFLL;
}

original_code:
int
set_block(int fd, blockmode mode)
{
    int flags = 0;
    int retval = 0;
    flags = fcntl(fd, 3, 0);
    if (flags < 0) {
        system_log(6, 0x01, get_progname(), "net.c", 143, __FUNCTION__, "fcntl=0x%x", flags);
        return EX_NG;
    }
    do { } while (0);
    if (mode == NONBLOCK) {
        retval = fcntl(fd, 4, flags | 04000);
        if (retval < 0)
            system_log(6, 0x01, get_progname(), "net.c", 151, __FUNCTION__, "fcntl=%d", retval);
    } else if (mode == BLOCKING) {
        retval = fcntl(fd, 4, flags & ~04000);
        if (retval < 0)
            system_log(6, 0x01, get_progname(), "net.c", 155, __FUNCTION__, "fcntl=%d", retval);
    } else {
        system_log(6, 0x01, get_progname(), "net.c", 157, __FUNCTION__, "mode=%d", mode);
        return EX_NG;
    }
    return EX_OK;
}

canonical_original_code:
int set_block(int fd, enum _blockmode mode)
{
    int flags = 0;
    int retval = 0;
    flags = fcntl(fd, 3, 0);
    if (flags < 0) {
        system_log(6, 0x01, get_progname(), "net.c", 143, __FUNCTION__, "fcntl=0x%x", flags);
        return EX_NG;
    }
    do { } while (0);
    if (mode == NONBLOCK) {
        retval = fcntl(fd, 4, flags | 04000);
        if (retval < 0)
            system_log(6, 0x01, get_progname(), "net.c", 151, __FUNCTION__, "fcntl=%d", retval);
    } else if (mode == BLOCKING) {
        retval = fcntl(fd, 4, flags & ~04000);
        if (retval < 0)
            system_log(6, 0x01, get_progname(), "net.c", 155, __FUNCTION__, "fcntl=%d", retval);
    } else {
        system_log(6, 0x01, get_progname(), "net.c", 157, __FUNCTION__, "mode=%d", mode);
        return EX_NG;
    }
    return EX_OK;
}

variable_types: fd int

variable_types: enum _blockmode { NONBLOCK=0, BLOCKING=1 }

variable_types: flags int


decompiled_code:
__int64 __fastcall send_data(int fd, void *buf, size_t *a3)
{
size_t v3; // rbp
void *v5; // r13
size_t v6; // rdx
char *v7; // r12
void *v8; // rsi
ssize_t v9; // rax
ssize_t v10; // rbx
int v11; // eax
__int64 v12; // rdx
size_t v13; // r13
__int64 v14; // rax

v3 = *a3;
if ( *a3 )
{
v5 = buf;
v6 = *a3;
v7 = (char *)buf;
while ( 1 )
{
v8 = v5;
v9 = send(fd, v5, v6, 0);
v10 = v9;
if ( v9 > 0 )
{
v7 += v9;
v3 -= v9;
if ( !v3 )
return 0LL;
}
else
{
v11 = *_errno_location();
if ( v11 != 4 && v11 != 11 )
{
v13 = *a3 - v3;
*a3 = v13;
v14 = get_progname((unsigned int)fd, v8, v12);
system_log(
6LL,
1LL,
v14,
"net.c",
210LL,
"send_data",
"send=%zd, sock=%d, ptr=%p, left=%zu, length=%zu",
v10,
(unsigned int)fd,
v7,
v3,
v13);
return 0xFFFFFFFFLL;
}
}
v6 = *a3;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, void *buf, size_t *a3)
{
size_t v3; // rbp
void *v5; // r13
size_t v6; // rdx
char *v7; // r12
void *v8; // rsi
ssize_t v9; // rax
ssize_t v10; // rbx
int v11; // eax
__int64 v12; // rdx
size_t v13; // r13
__int64 v14; // rax

v3 = *a3;
if ( *a3 )
{
v5 = buf;
v6 = *a3;
v7 = (char *)buf;
while ( 1 )
{
v8 = v5;
v9 = send(fd, v5, v6, 0);
v10 = v9;
if ( v9 > 0 )
{
v7 += v9;
v3 -= v9;
if ( !v3 )
return 0LL;
}
else
{
v11 = *_errno_location();
if ( v11 != 4 && v11 != 11 )
{
v13 = *a3 - v3;
*a3 = v13;
v14 = get_progname((unsigned int)fd, v8, v12);
system_log(
6LL,
1LL,
v14,
"net.c",
210LL,
"send_data",
"send=%zd, sock=%d, ptr=%p, left=%zu, length=%zu",
v10,
(unsigned int)fd,
v7,
v3,
v13);
return 0xFFFFFFFFLL;
}
}
v6 = *a3;
}
}
return 0LL;
}

original_code:
int
send_data(const int sock, const void *sdata, size_t *length)
{
    ssize_t len = 0;
    size_t left = 0;
    const unsigned char *ptr = ((void *)0);
    do { } while (0);
    ptr = (unsigned char *)sdata;
    left = *length;
    while (left > 0) {
        len = send(sock, sdata, *length, 0);
        do { } while (0);
        if (len <= 0) {
            if (((*__errno_location ()) == 4) ||
                ((*__errno_location ()) == 11) || ((*__errno_location ()) == 11))
                len = 0;
            else
                goto error_handler;
        }
        left -= len;
        ptr += len;
    }
    *length -= left;
    do { } while (0);
    return EX_OK;
error_handler:
    *length -= left;
    system_log(6, 0x01, get_progname(), "net.c", 210, __FUNCTION__, "send=%zd, sock=%d, ptr=%p, left=%zu, length=%zu", len, sock, ptr, left, *length);
    return EX_NG;
}

canonical_original_code:
int send_data(int sock, void *sdata, unsigned long *length)
{
    long len = 0;
    unsigned long left = 0;
    unsigned char *ptr = ((void *)0);
    do { } while (0);
    ptr = (unsigned char *)sdata;
    left = *length;
    while (left > 0) {
        len = send(sock, sdata, *length, 0);
        do { } while (0);
        if (len <= 0) {
            if (((*__errno_location ()) == 4) ||
                ((*__errno_location ()) == 11) || ((*__errno_location ()) == 11))
                len = 0;
            else
                goto error_handler;
        }
        left -= len;
        ptr += len;
    }
    *length -= left;
    do { } while (0);
    return EX_OK;
error_handler:
    *length -= left;
    system_log(6, 0x01, get_progname(), "net.c", 210, __FUNCTION__, "send=%zd, sock=%d, ptr=%p, left=%zu, length=%zu", len, sock, ptr, left, *length);
    return EX_NG;
}

variable_types: sock int

variable_types:
sdata
void *

variable_types:
length
unsigned long *

variable_types: len long

variable_types:
left
unsigned long

variable_types:
ptr
unsigned char *


decompiled_code:
__int64 __fastcall recv_data(int fd, void *buf, size_t *a3)
{
__int64 v4; // r13
size_t v6; // rbp
void *v7; // rsi
__int64 v8; // rdi
ssize_t v9; // rax
__int64 v10; // rdx
ssize_t v11; // rbx
int v13; // eax
__int64 v14; // rdx
size_t v15; // r15
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // [rsp-8h] [rbp-40h]

v4 = (unsigned int)fd;
v6 = *a3;
if ( !*a3 )
return 0LL;
while ( 1 )
{
while ( 1 )
{
v7 = buf;
v8 = (unsigned int)v4;
v9 = recv(v4, buf, v6, 0);
v11 = v9;
if ( v9 >= 0 )
break;
v13 = *_errno_location();
if ( v13 != 4 && v13 != 11 )
goto LABEL_8;
}
if ( !v9 )
break;
buf = (char *)buf + v9;
v6 -= v9;
if ( !v6 )
return 0LL;
}
v17 = get_progname((unsigned int)v4, buf, v10);
v7 = _bswap_16 + 1;
v8 = 6LL;
system_log(6LL, 1LL, v17, "net.c", 244LL, "recv_data", "The socket is not connected.");
v14 = v18;
LABEL_8:
v15 = *a3 - v6;
*a3 = v15;
v16 = get_progname(v8, v7, v14);
system_log(
6LL,
1LL,
v16,
"net.c",
258LL,
"recv_data",
"recv=%zd, sock=%d, ptr=%p, left=%zu, length=%zu",
v11,
v4,
buf,
v6,
v15);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, void *buf, size_t *a3)
{
__int64 v4; // r13
size_t v6; // rbp
void *v7; // rsi
__int64 v8; // rdi
ssize_t v9; // rax
__int64 v10; // rdx
ssize_t v11; // rbx
int v13; // eax
__int64 v14; // rdx
size_t v15; // r15
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // [rsp-8h] [rbp-40h]

v4 = (unsigned int)fd;
v6 = *a3;
if ( !*a3 )
return 0LL;
while ( 1 )
{
while ( 1 )
{
v7 = buf;
v8 = (unsigned int)v4;
v9 = recv(v4, buf, v6, 0);
v11 = v9;
if ( v9 >= 0 )
break;
v13 = *_errno_location();
if ( v13 != 4 && v13 != 11 )
goto LABEL_8;
}
if ( !v9 )
break;
buf = (char *)buf + v9;
v6 -= v9;
if ( !v6 )
return 0LL;
}
v17 = get_progname((unsigned int)v4, buf, v10);
v7 = _bswap_16 + 1;
v8 = 6LL;
system_log(6LL, 1LL, v17, "net.c", 244LL, "recv_data", "The socket is not connected.");
v14 = v18;
LABEL_8:
v15 = *a3 - v6;
*a3 = v15;
v16 = get_progname(v8, v7, v14);
system_log(
6LL,
1LL,
v16,
"net.c",
258LL,
"recv_data",
"recv=%zd, sock=%d, ptr=%p, left=%zu, length=%zu",
v11,
v4,
buf,
v6,
v15);
return 0xFFFFFFFFLL;
}

original_code:
int
recv_data(const int sock, void *rdata, size_t *length)
{
    ssize_t len = 0;
    size_t left = 0;
    unsigned char *ptr = ((void *)0);
    do { } while (0);
    ptr = (unsigned char *)rdata;
    left = *length;
    while (left > 0) {
        len = recv(sock, ptr, left, 0);
        do { } while (0);
        if (len < 0) {
            if (((*__errno_location ()) == 4) ||
                ((*__errno_location ()) == 11) || ((*__errno_location ()) == 11))
                len = 0;
            else
                goto error_handler;
        } else if (len == 0) {
            system_log(6, 0x01, get_progname(), "net.c", 244, __FUNCTION__, "The socket is not connected.");
            goto error_handler;
        } else {
            left -= len;
            ptr += len;
        }
    }
    *length -= left;
    do { } while (0);
    return EX_OK;
error_handler:
    *length -= left;
    system_log(6, 0x01, get_progname(), "net.c", 258, __FUNCTION__, "recv=%zd, sock=%d, ptr=%p, left=%zu, length=%zu", len, sock, ptr, left, *length);
    return EX_NG;
}

canonical_original_code:
int recv_data(int sock, void *rdata, unsigned long *length)
{
    long len = 0;
    unsigned long left = 0;
    unsigned char *ptr = ((void *)0);
    do { } while (0);
    ptr = (unsigned char *)rdata;
    left = *length;
    while (left > 0) {
        len = recv(sock, ptr, left, 0);
        do { } while (0);
        if (len < 0) {
            if (((*__errno_location ()) == 4) ||
                ((*__errno_location ()) == 11) || ((*__errno_location ()) == 11))
                len = 0;
            else
                goto error_handler;
        } else if (len == 0) {
            system_log(6, 0x01, get_progname(), "net.c", 244, __FUNCTION__, "The socket is not connected.");
            goto error_handler;
        } else {
            left -= len;
            ptr += len;
        }
    }
    *length -= left;
    do { } while (0);
    return EX_OK;
error_handler:
    *length -= left;
    system_log(6, 0x01, get_progname(), "net.c", 258, __FUNCTION__, "recv=%zd, sock=%d, ptr=%p, left=%zu, length=%zu", len, sock, ptr, left, *length);
    return EX_NG;
}

variable_types:
rdata
void *


decompiled_code:
void *__fastcall recv_data_new(int fd, size_t *a2)
{
size_t v2; // rbx
void *v3; // rax
__int64 v4; // rdx
void *v5; // r12
__int64 v7; // rax
size_t v8[6]; // [rsp+8h] [rbp-30h] BYREF

v2 = *a2;
v8[0] = v2;
v3 = calloc(v2, 1uLL);
v5 = v3;
if ( !v3 )
{
v7 = get_progname(v2, 1LL, v4);
system_log(6LL, 1LL, v7, "net.c", 285LL, "recv_data_new", "malloc: len= %zu", v2);
return v5;
}
if ( (int)recv_data(fd, v3, v8) >= 0 )
{
*a2 = v8[0];
return v5;
}
*a2 = 0LL;
return v5;
}

canonical_decompiled_code:
void *__fastcall func6(int fd, size_t *a2)
{
size_t v2; // rbx
void *v3; // rax
__int64 v4; // rdx
void *v5; // r12
__int64 v7; // rax
size_t v8[6]; // [rsp+8h] [rbp-30h] BYREF

v2 = *a2;
v8[0] = v2;
v3 = calloc(v2, 1uLL);
v5 = v3;
if ( !v3 )
{
v7 = get_progname(v2, 1LL, v4);
system_log(6LL, 1LL, v7, "net.c", 285LL, "recv_data_new", "malloc: len= %zu", v2);
return v5;
}
if ( (int)func5(fd, v3, v8) >= 0 )
{
*a2 = v8[0];
return v5;
}
*a2 = 0LL;
return v5;
}

original_code:
void *
recv_data_new(const int sock, size_t *length)
{
    size_t len = *length;
    int retval = 0;
    void *rdata = ((void *)0);
    do { } while (0);
    rdata = malloc(len);
    if (!rdata) {
        system_log(6, 0x01, get_progname(), "net.c", 285, __FUNCTION__, "malloc: len= %zu", len);
        return ((void *)0);
    }
    (void)memset(rdata, 0, len);
    retval = recv_data(sock, rdata, &len);
    if (retval < 0) {
        *length = 0;
        return rdata;
    }
    *length = len;
    return rdata;
}

canonical_original_code:
void *recv_data_new(int sock, unsigned long *length)
{
    unsigned long len = *length;
    int retval = 0;
    void *rdata = ((void *)0);
    do { } while (0);
    rdata = malloc(len);
    if (!rdata) {
        system_log(6, 0x01, get_progname(), "net.c", 285, __FUNCTION__, "malloc: len= %zu", len);
        return ((void *)0);
    }
    (void)memset(rdata, 0, len);
    retval = recv_data(sock, rdata, &len);
    if (retval < 0) {
        *length = 0;
        return rdata;
    }
    *length = len;
    return rdata;
}

variable_types:
len
unsigned long

return_type: void *


decompiled_code:
__int64 __fastcall close_sock(_DWORD *a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // rbp
__int64 v4; // rdx
__int64 v6; // rax

v2 = 0;
v3 = (unsigned int)*a1;
if ( (int)v3 >= 0 )
{
if ( close(v3) < 0 )
{
v6 = get_progname((unsigned int)v3, a2, v4);
v2 = -1;
system_log(6LL, 1LL, v6, "net.c", 321LL, "close_sock", "close: sockfd=%d", v3);
}
else
{
*a1 = -1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // rbp
__int64 v4; // rdx
__int64 v6; // rax

v2 = 0;
v3 = (unsigned int)*a1;
if ( (int)v3 >= 0 )
{
if ( close(v3) < 0 )
{
v6 = get_progname((unsigned int)v3, a2, v4);
v2 = -1;
system_log(6LL, 1LL, v6, "net.c", 321LL, "close_sock", "close: sockfd=%d", v3);
}
else
{
*a1 = -1;
}
}
return v2;
}

original_code:
int
close_sock(int *sock)
{
    int retval = 0;
    const int sockfd = *sock;
    do { } while (0);
    if (sockfd < 0)
        return EX_OK;
    retval = close(sockfd);
    if (retval < 0) {
        system_log(6, 0x01, get_progname(), "net.c", 321, __FUNCTION__, "close: sockfd=%d", sockfd);
        return EX_NG;
    }
    *sock = -1;
    return EX_OK;
}

canonical_original_code:
int close_sock(int *sock)
{
    int retval = 0;
    int sockfd = *sock;
    do { } while (0);
    if (sockfd < 0)
        return EX_OK;
    retval = close(sockfd);
    if (retval < 0) {
        system_log(6, 0x01, get_progname(), "net.c", 321, __FUNCTION__, "close: sockfd=%d", sockfd);
        return EX_NG;
    }
    *sock = -1;
    return EX_OK;
}

variable_types:
sock
int *

variable_types: sockfd int


readn

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

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

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

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

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

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

variable_types:
vptr
void *

variable_types:
n
unsigned long

variable_types:
nleft
unsigned long

variable_types: nread long

variable_types:
ptr
char *

return_type: long


writen

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

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

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

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

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

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

variable_types: fd int

variable_types: nwritten long


decompiled_code:
__int64 __fastcall pipe_fd(int fd2, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
double v9; // xmm4_8
double v10; // xmm5_8
__int64 result; // rax
__int64 v12; // rax
__int64 v13; // r8
__int64 v14; // rdx
__int64 v15; // rax
double v16; // xmm4_8
double v17; // xmm5_8
__int64 v18; // rax
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

*(_QWORD *)pipedes = -1LL;
if ( fd2 < 0 )
return 0xFFFFFFFFLL;
if ( pipe(pipedes) < 0 )
{
v12 = get_progname();
v13 = 122LL;
v14 = v12;
LABEL_8:
system_log(6LL, 1LL, v14, "fileio.c", v13, "pipe_fd");
return 0xFFFFFFFFLL;
}
if ( close(fd2) < 0 )
{
v18 = get_progname();
v13 = 128LL;
v14 = v18;
goto LABEL_8;
}
if ( dup2(pipedes[1], fd2) < 0 )
{
v15 = get_progname();
system_log(6LL, 1LL, v15, "fileio.c", 134LL, "pipe_fd");
close_fd(pipedes, a2, a3, a4, a5, v16, v17, a8, a9, &pipedes[1], 0LL);
result = 0xFFFFFFFFLL;
}
else
{
close_fd(&pipedes[1], a2, a3, a4, a5, v9, v10, a8, a9, 0LL);
result = (unsigned int)pipedes[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd2, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
double v9; // xmm4_8
double v10; // xmm5_8
__int64 result; // rax
__int64 v12; // rax
__int64 v13; // r8
__int64 v14; // rdx
__int64 v15; // rax
double v16; // xmm4_8
double v17; // xmm5_8
__int64 v18; // rax
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

*(_QWORD *)pipedes = -1LL;
if ( fd2 < 0 )
return 0xFFFFFFFFLL;
if ( pipe(pipedes) < 0 )
{
v12 = get_progname();
v13 = 122LL;
v14 = v12;
LABEL_8:
system_log(6LL, 1LL, v14, "fileio.c", v13, "pipe_fd");
return 0xFFFFFFFFLL;
}
if ( close(fd2) < 0 )
{
v18 = get_progname();
v13 = 128LL;
v14 = v18;
goto LABEL_8;
}
if ( dup2(pipedes[1], fd2) < 0 )
{
v15 = get_progname();
system_log(6LL, 1LL, v15, "fileio.c", 134LL, "pipe_fd");
func3(pipedes, a2, a3, a4, a5, v16, v17, a8, a9, &pipedes[1], 0LL);
result = 0xFFFFFFFFLL;
}
else
{
func3(&pipedes[1], a2, a3, a4, a5, v9, v10, a8, a9, 0LL);
result = (unsigned int)pipedes[0];
}
return result;
}

original_code:
int
pipe_fd(const int fd)
{
    int pfd[] = {-1, -1};
    int retval = 0;
    int newfd = 0;
    if (fd < 0)
        return EX_NG;
    retval = pipe(pfd);
    if (retval < 0) {
        system_log(6, 0x01, get_progname(), "fileio.c", 122, __FUNCTION__, "pipe: pfd=%p", pfd);
        return EX_NG;
    }
    retval = close(fd);
    if (retval < 0) {
        system_log(6, 0x01, get_progname(), "fileio.c", 128, __FUNCTION__, "close: fd=%d", fd);
        return EX_NG;
    }
    newfd = dup2(pfd[PIPE_W], fd);
    if (newfd < 0) {
        system_log(6, 0x01, get_progname(), "fileio.c", 134, __FUNCTION__, "dup2: pfd[PIPE_W]=%d, fd=%d", pfd[PIPE_W], fd);
        close_fd(&pfd[PIPE_R], &pfd[PIPE_W], ((void *)0));
        return EX_NG;
    }
    do { } while (0);
    close_fd(&pfd[PIPE_W], ((void *)0));
    return pfd[PIPE_R];
}

canonical_original_code:
int pipe_fd(int fd)
{
    int pfd[] = {-1, -1};
    int retval = 0;
    int newfd = 0;
    if (fd < 0)
        return EX_NG;
    retval = pipe(pfd);
    if (retval < 0) {
        system_log(6, 0x01, get_progname(), "fileio.c", 122, __FUNCTION__, "pipe: pfd=%p", pfd);
        return EX_NG;
    }
    retval = close(fd);
    if (retval < 0) {
        system_log(6, 0x01, get_progname(), "fileio.c", 128, __FUNCTION__, "close: fd=%d", fd);
        return EX_NG;
    }
    newfd = dup2(pfd[PIPE_W], fd);
    if (newfd < 0) {
        system_log(6, 0x01, get_progname(), "fileio.c", 134, __FUNCTION__, "dup2: pfd[PIPE_W]=%d, fd=%d", pfd[PIPE_W], fd);
        close_fd(&pfd[PIPE_R], &pfd[PIPE_W], ((void *)0));
        return EX_NG;
    }
    do { } while (0);
    close_fd(&pfd[PIPE_W], ((void *)0));
    return pfd[PIPE_R];
}

variable_types:
pfd
int []

variable_types: retval int

variable_types: newfd int


decompiled_code:
__int64 __fastcall pipe_fd2(int *a1, int *a2, int a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
int v12; // er12
double v13; // xmm4_8
double v14; // xmm5_8
__int64 v16; // rax
__int64 v17; // rax

close_fd(a1, a4, a5, a6, a7, a8, a9, a10, a11, 0LL);
if ( close(a3) < 0 )
{
v16 = get_progname();
system_log(6LL, 1LL, v16, "fileio.c", 162LL, "pipe_fd2");
}
v12 = dup2(*a2, a3);
if ( v12 < 0 )
{
v17 = get_progname();
v12 = -1;
system_log(6LL, 1LL, v17, "fileio.c", 166LL, "pipe_fd2");
}
close_fd(a2, a4, a5, a6, a7, v13, v14, a10, a11, 0LL);
return (unsigned int)v12;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, int *a2, int a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
int v12; // er12
double v13; // xmm4_8
double v14; // xmm5_8
__int64 v16; // rax
__int64 v17; // rax

func3(a1, a4, a5, a6, a7, a8, a9, a10, a11, 0LL);
if ( close(a3) < 0 )
{
v16 = get_progname();
system_log(6LL, 1LL, v16, "fileio.c", 162LL, "pipe_fd2");
}
v12 = dup2(*a2, a3);
if ( v12 < 0 )
{
v17 = get_progname();
v12 = -1;
system_log(6LL, 1LL, v17, "fileio.c", 166LL, "pipe_fd2");
}
func3(a2, a4, a5, a6, a7, v13, v14, a10, a11, 0LL);
return (unsigned int)v12;
}

original_code:
int
pipe_fd2(int *pipefd, int *oldfd, const int newfd)
{
    int retval = 0;
    int fd = 0;
    close_fd(pipefd, ((void *)0));
    retval = close(newfd);
    if (retval < 0)
        system_log(6, 0x01, get_progname(), "fileio.c", 162, __FUNCTION__, "close=%d", retval);
    fd = dup2(*oldfd, newfd);
    if (fd < 0) {
        system_log(6, 0x01, get_progname(), "fileio.c", 166, __FUNCTION__, "dup2=%d", retval);
        close_fd(oldfd, ((void *)0));
        return EX_NG;
    }
    close_fd(oldfd, ((void *)0));
    return fd;
}

canonical_original_code:
int pipe_fd2(int *pipefd, int *oldfd, int newfd)
{
    int retval = 0;
    int fd = 0;
    close_fd(pipefd, ((void *)0));
    retval = close(newfd);
    if (retval < 0)
        system_log(6, 0x01, get_progname(), "fileio.c", 162, __FUNCTION__, "close=%d", retval);
    fd = dup2(*oldfd, newfd);
    if (fd < 0) {
        system_log(6, 0x01, get_progname(), "fileio.c", 166, __FUNCTION__, "dup2=%d", retval);
        close_fd(oldfd, ((void *)0));
        return EX_NG;
    }
    close_fd(oldfd, ((void *)0));
    return fd;
}

variable_types:
pipefd
int *

variable_types:
oldfd
int *


decompiled_code:
__int64 __fastcall set_client_data(_QWORD *a1, const void *a2, size_t a3)
{
unsigned __int64 v3; // r13
void *v5; // rax
int v6; // eax
_DWORD *v7; // rdx
__int64 result; // rax
__int64 v9; // rax

if ( !a2 )
return -1LL;
v3 = (a3 + 7) & 0xFFFFFFFFFFFFFFF8LL;
v5 = calloc(v3 + 8, 1uLL);
*a1 = v5;
if ( v5 )
{
v6 = _bswap_32(v3);
*v7 = v6;
memcpy(v7 + 2, a2, a3);
result = v3 + 8;
}
else
{
v9 = get_progname();
system_log(6LL, 1LL, v9, "data.c", 66LL, "set_client_data", "malloc: length=%zu", v3 + 8);
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, const void *a2, size_t a3)
{
unsigned __int64 v3; // r13
void *v5; // rax
int v6; // eax
_DWORD *v7; // rdx
__int64 result; // rax
__int64 v9; // rax

if ( !a2 )
return -1LL;
v3 = (a3 + 7) & 0xFFFFFFFFFFFFFFF8LL;
v5 = calloc(v3 + 8, 1uLL);
*a1 = v5;
if ( v5 )
{
v6 = func0(v3);
*v7 = v6;
memcpy(v7 + 2, a2, a3);
result = v3 + 8;
}
else
{
v9 = get_progname();
system_log(6LL, 1LL, v9, "data.c", 66LL, "set_client_data", "malloc: length=%zu", v3 + 8);
result = -1LL;
}
return result;
}

original_code:
ssize_t
set_client_data(struct client_data **dt,
                const unsigned char *buf, const size_t len)
{
    size_t length = 0;
    size_t datalen = 0;
    do { } while (0);
    if (!buf)
        return EX_NG;
    datalen = (((len)+7) & ~7);
    length = sizeof(struct header) + datalen;
    do { } while (0);
    (*dt) = (struct client_data *)malloc(length);
    if (!(*dt)) {
        system_log(6, 0x01, get_progname(), "data.c", 66, __FUNCTION__, "malloc: length=%zu", length);
        return EX_NG;
    }
    (void)memset((*dt), 0, length);
    do { } while (0);
    (*dt)->hd.length = htonl((uint32_t)datalen);
    (void)memcpy((*dt)->expression, buf, len);
    do { } while (0);
    return (ssize_t)length;
}

canonical_original_code:
long set_client_data(struct client_data **dt, unsigned char *buf, unsigned long len)
{
    unsigned long length = 0;
    unsigned long datalen = 0;
    do { } while (0);
    if (!buf)
        return EX_NG;
    datalen = (((len)+7) & ~7);
    length = sizeof(struct header) + datalen;
    do { } while (0);
    (*dt) = (struct client_data *)malloc(length);
    if (!(*dt)) {
        system_log(6, 0x01, get_progname(), "data.c", 66, __FUNCTION__, "malloc: length=%zu", length);
        return EX_NG;
    }
    (void)memset((*dt), 0, length);
    do { } while (0);
    (*dt)->hd.length = htonl((unsigned int)datalen);
    (void)memcpy((*dt)->expression, buf, len);
    do { } while (0);
    return (long)length;
}

variable_types: struct client_data { struct header { unsigned int length; unsigned char padding[4]; } hd; unsigned char expression[1]; } **

variable_types:
buf
unsigned char *

variable_types:
length
unsigned long

variable_types:
datalen
unsigned long

user_defined_types: struct client_data { struct header hd; unsigned char expression[1]; }


decompiled_code:
__int64 __fastcall set_server_data(_QWORD *a1, const void *a2, size_t a3)
{
unsigned __int64 v3; // r13
void *v5; // rax
int v6; // eax
_DWORD *v7; // rdx
__int64 result; // rax
__int64 v9; // rax

if ( !a2 )
return -1LL;
v3 = (a3 + 7) & 0xFFFFFFFFFFFFFFF8LL;
v5 = calloc(v3 + 8, 1uLL);
*a1 = v5;
if ( v5 )
{
v6 = _bswap_32(v3);
*v7 = v6;
memcpy(v7 + 2, a2, a3);
result = v3 + 8;
}
else
{
v9 = get_progname();
system_log(6LL, 1LL, v9, "data.c", 106LL, "set_server_data", "malloc: length=%zu", v3 + 8);
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, const void *a2, size_t a3)
{
unsigned __int64 v3; // r13
void *v5; // rax
int v6; // eax
_DWORD *v7; // rdx
__int64 result; // rax
__int64 v9; // rax

if ( !a2 )
return -1LL;
v3 = (a3 + 7) & 0xFFFFFFFFFFFFFFF8LL;
v5 = calloc(v3 + 8, 1uLL);
*a1 = v5;
if ( v5 )
{
v6 = func0(v3);
*v7 = v6;
memcpy(v7 + 2, a2, a3);
result = v3 + 8;
}
else
{
v9 = get_progname();
system_log(6LL, 1LL, v9, "data.c", 106LL, "set_server_data", "malloc: length=%zu", v3 + 8);
result = -1LL;
}
return result;
}

original_code:
ssize_t
set_server_data(struct server_data **dt,
                const unsigned char *buf, const size_t len)
{
    size_t length = 0;
    size_t datalen = 0;
    do { } while (0);
    if (!buf)
        return EX_NG;
    datalen = (((len)+7) & ~7);
    length = sizeof(struct header) + datalen;
    do { } while (0);
    (*dt) = (struct server_data *)malloc(length);
    if (!(*dt)) {
        system_log(6, 0x01, get_progname(), "data.c", 106, __FUNCTION__, "malloc: length=%zu", length);
        return EX_NG;
    }
    (void)memset((*dt), 0, length);
    do { } while (0);
    (*dt)->hd.length = htonl((uint32_t)datalen);
    (void)memcpy((*dt)->answer, buf, len);
    do { } while (0);
    return (ssize_t)length;
}

canonical_original_code:
long set_server_data(struct server_data **dt, unsigned char *buf, unsigned long len)
{
    unsigned long length = 0;
    unsigned long datalen = 0;
    do { } while (0);
    if (!buf)
        return EX_NG;
    datalen = (((len)+7) & ~7);
    length = sizeof(struct header) + datalen;
    do { } while (0);
    (*dt) = (struct server_data *)malloc(length);
    if (!(*dt)) {
        system_log(6, 0x01, get_progname(), "data.c", 106, __FUNCTION__, "malloc: length=%zu", length);
        return EX_NG;
    }
    (void)memset((*dt), 0, length);
    do { } while (0);
    (*dt)->hd.length = htonl((unsigned int)datalen);
    (void)memcpy((*dt)->answer, buf, len);
    do { } while (0);
    return (long)length;
}

variable_types: struct server_data { struct header { unsigned int length; unsigned char padding[4]; } hd; unsigned char answer[1]; } **

variable_types:
len
unsigned long

user_defined_types: struct server_data { struct header hd; unsigned char answer[1]; }


readch

decompiled_code:
const unsigned __int16 *__fastcall readch(__int64 a1)
{
unsigned __int8 *v1; // rbp
const unsigned __int16 *result; // rax
const unsigned __int16 *v3; // rbx

v1 = *(unsigned __int8 **)(a1 + 8);
do
{
result = (const unsigned __int16 *)*v1;
*(_DWORD *)a1 = (_DWORD)result;
v3 = result;
if ( !(_DWORD)result )
break;
*(_QWORD *)(a1 + 8) = ++v1;
result = *_ctype_b_loc();
}
while ( (result[(_QWORD)v3] & 1) != 0 );
return result;
}

canonical_decompiled_code:
const unsigned __int16 *__fastcall func0(__int64 a1)
{
unsigned __int8 *v1; // rbp
const unsigned __int16 *result; // rax
const unsigned __int16 *v3; // rbx

v1 = *(unsigned __int8 **)(a1 + 8);
do
{
result = (const unsigned __int16 *)*v1;
*(_DWORD *)a1 = (_DWORD)result;
v3 = result;
if ( !(_DWORD)result )
break;
*(_QWORD *)(a1 + 8) = ++v1;
result = *_ctype_b_loc();
}
while ( (result[(_QWORD)v3] & 1) != 0 );
return result;
}

original_code:
static void
readch(calcinfo *calc)
{
    do { } while (0);
    do {
        calc->ch = (int)*calc->ptr;
        do { } while (0);
        if (calc->ch == '\0')
            break;
        calc->ptr++;
    } while (((*__ctype_b_loc ())[(int) ((calc->ch))] & (unsigned short int) _ISblank));
}

canonical_original_code:
static void readch(struct _calcinfo *calc)
{
    do { } while (0);
    do {
        calc->ch = (int)*calc->ptr;
        do { } while (0);
        if (calc->ch == '\0')
            break;
        calc->ptr++;
    } while (((*__ctype_b_loc ())[(int) ((calc->ch))] & (unsigned short) _ISblank));
}

variable_types: struct _calcinfo { int ch; unsigned char *ptr; unsigned char *answer; char fmt[-1]; enum _ER { E_NONE=0, E_DIVBYZERO=1, E_SYNTAX=2, E_NOFUNC=3, E_NAN=4, E_INFINITY=5, MAXERROR=6 } errorcode; } *

return_type: void

user_defined_types: struct _calcinfo { int ch; unsigned char *ptr; unsigned char *answer; char fmt[-1]; enum _ER errorcode; }


number

original_code:
static double
number(calcinfo *calc)
{
    double x = 0.0, y = 1.0;
    do { } while (0);
    x = calc->ch - '0';
    while (readch(calc), ((*__ctype_b_loc ())[(int) ((calc->ch))] & (unsigned short int) _ISdigit))
        x = (x * 10) + (calc->ch - '0');
    do { } while (0);
    if (calc->ch == '.') {
        while (readch(calc), ((*__ctype_b_loc ())[(int) ((calc->ch))] & (unsigned short int) _ISdigit))
            x += (y /= 10) * (calc->ch - '0');
    }
    do { } while (0);
    check_validate(calc, x);
    return x;
}

canonical_original_code:
static double number(struct _calcinfo *calc)
{
    double x = 0.0; double y = 1.0;
    do { } while (0);
    x = calc->ch - '0';
    while (readch(calc), ((*__ctype_b_loc ())[(int) ((calc->ch))] & (unsigned short) _ISdigit))
        x = (x * 10) + (calc->ch - '0');
    do { } while (0);
    if (calc->ch == '.') {
        while (readch(calc), ((*__ctype_b_loc ())[(int) ((calc->ch))] & (unsigned short) _ISdigit))
            x += (y /= 10) * (calc->ch - '0');
    }
    do { } while (0);
    check_validate(calc, x);
    return x;
}

variable_types: x double

variable_types: y double

return_type: double

user_defined_types: enum _ER { E_NONE=0, E_DIVBYZERO=1, E_SYNTAX=2, E_NOFUNC=3, E_NAN=4, E_INFINITY=5, MAXERROR=6 }


token

original_code:
static double
token(calcinfo *calc)
{
    double result = 0.0;
    int sign = '+';
    char func[4 + 1];
    int pos = 0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    (void)memset(func, 0, sizeof(func));
    if (calc->ch == '+' || calc->ch == '-') {
        sign = calc->ch;
        readch(calc);
    }
    if (((*__ctype_b_loc ())[(int) ((calc->ch))] & (unsigned short int) _ISdigit)) {
        result = number(calc);
    } else if (((*__ctype_b_loc ())[(int) ((calc->ch))] & (unsigned short int) _ISalpha)) {
        while (((*__ctype_b_loc ())[(int) ((calc->ch))] & (unsigned short int) _ISalpha) && calc->ch != '\0' &&
               pos <= 4) {
            func[pos++] = calc->ch;
            readch(calc);
        }
        do { } while (0);
        result = exec_func(calc, func);
    } else {
        do { } while (0);
        set_errorcode(calc, E_SYNTAX);
    }
    do { } while (0);
    return (sign == '+') ? result : -result;
}

canonical_original_code:
static double token(struct _calcinfo *calc)
{
    double result = 0.0;
    int sign = '+';
    char func[-1];
    int pos = 0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    (void)memset(func, 0, sizeof(func));
    if (calc->ch == '+' || calc->ch == '-') {
        sign = calc->ch;
        readch(calc);
    }
    if (((*__ctype_b_loc ())[(int) ((calc->ch))] & (unsigned short) _ISdigit)) {
        result = number(calc);
    } else if (((*__ctype_b_loc ())[(int) ((calc->ch))] & (unsigned short) _ISalpha)) {
        while (((*__ctype_b_loc ())[(int) ((calc->ch))] & (unsigned short) _ISalpha) && calc->ch != '\0' &&
               pos <= 4) {
            func[pos++] = calc->ch;
            readch(calc);
        }
        do { } while (0);
        result = exec_func(calc, func);
    } else {
        do { } while (0);
        set_errorcode(calc, E_SYNTAX);
    }
    do { } while (0);
    return (sign == '+') ? result : -result;
}

variable_types: result double

variable_types: sign int

variable_types:
func
char [-1]

variable_types: pos int


factor

decompiled_code:
double __fastcall factor(int *a1, double result)
{
if ( (unsigned __int8)is_error() )
return 0.0;
if ( *a1 == 40 )
{
readch((__int64)a1);
expression(a1);
if ( *a1 == 41 )
{
readch((__int64)a1);
}
else
{
set_errorcode(a1, 2LL, result);
result = 0.0;
}
}
else
{
*(_QWORD *)&result = *(_OWORD *)&token(a1);
}
return result;
}

canonical_decompiled_code:
double __fastcall func3(int *a1, double result)
{
if ( (unsigned __int8)is_error() )
return 0.0;
if ( *a1 == 40 )
{
func0((__int64)a1);
func5(a1);
if ( *a1 == 41 )
{
func0((__int64)a1);
}
else
{
set_errorcode(a1, 2LL, result);
result = 0.0;
}
}
else
{
*(_QWORD *)&result = *(_OWORD *)&func2(a1);
}
return result;
}

original_code:
static double
factor(calcinfo *calc)
{
    double x = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if (calc->ch != '(')
        return token(calc);
    readch(calc);
    x = expression(calc);
    if (calc->ch != ')') {
        set_errorcode(calc, E_SYNTAX);
        return EX_ERROR;
    }
    readch(calc);
    do { } while (0);
    return x;
}

canonical_original_code:
static double factor(struct _calcinfo *calc)
{
    double x = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if (calc->ch != '(')
        return token(calc);
    readch(calc);
    x = expression(calc);
    if (calc->ch != ')') {
        set_errorcode(calc, E_SYNTAX);
        return EX_ERROR;
    }
    readch(calc);
    do { } while (0);
    return x;
}


term

original_code:
static double
term(calcinfo *calc)
{
    double x = 0.0, y = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    x = factor(calc);
    do { } while (0);
    while (1) {
        if (calc->ch == '*') {
            readch(calc);
            x *= factor(calc);
        } else if (calc->ch == '/') {
            readch(calc);
            y = factor(calc);
            if (y == 0) {
                set_errorcode(calc, E_DIVBYZERO);
                return EX_ERROR;
            }
            x /= y;
        } else if (calc->ch == '^') {
            readch(calc);
            y = factor(calc);
            x = get_pow(calc, x, y);
        } else {
            break;
        }
    }
    do { } while (0);
    return x;
}

canonical_original_code:
static double term(struct _calcinfo *calc)
{
    double x = 0.0; double y = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    x = factor(calc);
    do { } while (0);
    while (1) {
        if (calc->ch == '*') {
            readch(calc);
            x *= factor(calc);
        } else if (calc->ch == '/') {
            readch(calc);
            y = factor(calc);
            if (y == 0) {
                set_errorcode(calc, E_DIVBYZERO);
                return EX_ERROR;
            }
            x /= y;
        } else if (calc->ch == '^') {
            readch(calc);
            y = factor(calc);
            x = get_pow(calc, x, y);
        } else {
            break;
        }
    }
    do { } while (0);
    return x;
}


expression

original_code:
static double
expression(calcinfo *calc)
{
    double x = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    x = term(calc);
    do { } while (0);
    while (1) {
        if (calc->ch == '+') {
            readch(calc);
            x += term(calc);
        } else if (calc->ch == '-') {
            readch(calc);
            x -= term(calc);
        } else {
            break;
        }
    }
    do { } while (0);
    return x;
}

canonical_original_code:
static double expression(struct _calcinfo *calc)
{
    double x = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    x = term(calc);
    do { } while (0);
    while (1) {
        if (calc->ch == '+') {
            readch(calc);
            x += term(calc);
        } else if (calc->ch == '-') {
            readch(calc);
            x -= term(calc);
        } else {
            break;
        }
    }
    do { } while (0);
    return x;
}


decompiled_code:
char *__fastcall create_answer(__int64 a1, __int64 a2, __m128 a3)
{
char *v3; // r13
double v4; // xmm0_8
int v5; // eax
__int64 v6; // r12
size_t v7; // rbp
char *v8; // rax
char *v9; // r12
char *result; // rax
int v11; // eax
__int64 v12; // rax
const void *v13; // rbx
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // [rsp-8h] [rbp-40h]
int v17[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = (char *)(a1 + 24);
*(_QWORD *)(a1 + 8) = a2;
v17[0] = 0;
snprintf((char *)(a1 + 24), 6uLL, "%s%ld%s", "%.", digit, "g");
readch(a1);
if ( g_tflag )
start_timer(v17);
*(_QWORD *)&v4 = expression((int *)a1, a3).m128_u64[0];
check_validate(a1, v4);
if ( *(_DWORD *)a1 )
set_errorcode(a1, 2LL, v4);
if ( g_tflag )
{
v11 = stop_timer(v17);
fprintf(stderr, "time of %s: %f[msec]\n", "calc_time", (double)v11 * 0.001);
}
if ( (unsigned __int8)is_error(a1) )
{
*(_QWORD *)(a1 + 16) = get_errormsg(a1);
clear_error(a1);
result = *(char **)(a1 + 16);
}
else
{
v5 = get_strlen(v3, v4);
v6 = v5;
if ( v5 <= 0 )
{
v12 = get_progname();
v16 = v6;
v9 = 0LL;
system_log(6LL, 1LL, v12, "calc.c", 131LL, "create_answer", "get_strlen=%d", v16);
}
else
{
v7 = v5 + 1LL;
v8 = (char *)calloc(v7, 1uLL);
*(_QWORD *)(a1 + 16) = v8;
v9 = v8;
if ( v8 )
{
if ( snprintf(v8, v7, v3, v4) < 0 )
{
v13 = *(const void **)(a1 + 16);
v9 = 0LL;
v14 = get_progname();
system_log(6LL, 1LL, v14, "calc.c", 148LL, "create_answer", "snprintf: answer=%p, length=%zu", v13, v7);
}
else
{
v9 = *(char **)(a1 + 16);
}
}
else
{
v15 = get_progname();
system_log(6LL, 1LL, v15, "calc.c", 140LL, "create_answer", "malloc: length=%zu", v7);
}
}
result = v9;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 a1, __int64 a2, __m128 a3)
{
char *v3; // r13
double v4; // xmm0_8
int v5; // eax
__int64 v6; // r12
size_t v7; // rbp
char *v8; // rax
char *v9; // r12
char *result; // rax
int v11; // eax
__int64 v12; // rax
const void *v13; // rbx
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // [rsp-8h] [rbp-40h]
int v17[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = (char *)(a1 + 24);
*(_QWORD *)(a1 + 8) = a2;
v17[0] = 0;
snprintf((char *)(a1 + 24), 6uLL, "%s%ld%s", "%.", digit, "g");
func0(a1);
if ( g_tflag )
start_timer(v17);
*(_QWORD *)&v4 = func5((int *)a1, a3).m128_u64[0];
check_validate(a1, v4);
if ( *(_DWORD *)a1 )
set_errorcode(a1, 2LL, v4);
if ( g_tflag )
{
v11 = stop_timer(v17);
fprintf(stderr, "time of %s: %f[msec]\n", "calc_time", (double)v11 * 0.001);
}
if ( (unsigned __int8)is_error(a1) )
{
*(_QWORD *)(a1 + 16) = get_errormsg(a1);
clear_error(a1);
result = *(char **)(a1 + 16);
}
else
{
v5 = func6(v3, v4);
v6 = v5;
if ( v5 <= 0 )
{
v12 = get_progname();
v16 = v6;
v9 = 0LL;
system_log(6LL, 1LL, v12, "calc.c", 131LL, "create_answer", "get_strlen=%d", v16);
}
else
{
v7 = v5 + 1LL;
v8 = (char *)calloc(v7, 1uLL);
*(_QWORD *)(a1 + 16) = v8;
v9 = v8;
if ( v8 )
{
if ( snprintf(v8, v7, v3, v4) < 0 )
{
v13 = *(const void **)(a1 + 16);
v9 = 0LL;
v14 = get_progname();
system_log(6LL, 1LL, v14, "calc.c", 148LL, "create_answer", "snprintf: answer=%p, length=%zu", v13, v7);
}
else
{
v9 = *(char **)(a1 + 16);
}
}
else
{
v15 = get_progname();
system_log(6LL, 1LL, v15, "calc.c", 140LL, "create_answer", "malloc: length=%zu", v7);
}
}
result = v9;
}
return result;
}

original_code:
unsigned char *
create_answer(calcinfo *calc, const unsigned char *expr)
{
    double val = 0.0;
    size_t length = 0;
    int retval = 0;
    unsigned int start = 0;
    do { } while (0);
    calc->ptr = (unsigned char *)expr;
    do { } while (0);
    retval = snprintf(calc->fmt, sizeof(calc->fmt),
                      "%s%ld%s", "%.", digit, "g");
    if (retval < 0) {
        system_log(6, 0x01, get_progname(), "calc.c", 98, __FUNCTION__, "snprintf");
        return ((void *)0);
    }
    do { } while (0);
    readch(calc);
    if (g_tflag)
        start_timer(&start);
    val = expression(calc);
    do { } while (0);
    do { } while (0);
    check_validate(calc, val);
    if (calc->ch != '\0')
        set_errorcode(calc, E_SYNTAX);
    if (g_tflag) {
        unsigned int calc_time = stop_timer(&start);
        { (void)fprintf(stderr, "time of %s: %f[msec]\n", "calc_time", calc_time*1.0e-3); };
    }
    if (is_error(calc)) {
        calc->answer = get_errormsg(calc);
        clear_error(calc);
        if (!calc->answer)
            return ((void *)0);
        do { } while (0);
    } else {
        retval = get_strlen(val, calc->fmt);
        if (retval <= 0) {
            system_log(6, 0x01, get_progname(), "calc.c", 131, __FUNCTION__, "get_strlen=%d", retval);
            return ((void *)0);
        }
        do { } while (0);
        length = (size_t)retval + 1;
        calc->answer = (unsigned char *)malloc(length * sizeof(unsigned char));
        if (!calc->answer) {
            system_log(6, 0x01, get_progname(), "calc.c", 140, __FUNCTION__, "malloc: length=%zu", length);
            return ((void *)0);
        }
        (void)memset(calc->answer, 0, length * sizeof(unsigned char));
        retval = snprintf((char *)calc->answer, length, calc->fmt, val);
        if (retval < 0) {
            system_log(6, 0x01, get_progname(), "calc.c", 148, __FUNCTION__, "snprintf: answer=%p, length=%zu", calc->answer, length);
            return ((void *)0);
        }
        do { } while (0);
        do { } while (0);
    }
    return calc->answer;
}

canonical_original_code:
unsigned char *create_answer(struct _calcinfo *calc, unsigned char *expr)
{
    double val = 0.0;
    unsigned long length = 0;
    int retval = 0;
    unsigned int start = 0;
    do { } while (0);
    calc->ptr = (unsigned char *)expr;
    do { } while (0);
    retval = snprintf(calc->fmt, sizeof(calc->fmt),
                      "%s%ld%s", "%.", digit, "g");
    if (retval < 0) {
        system_log(6, 0x01, get_progname(), "calc.c", 98, __FUNCTION__, "snprintf");
        return ((void *)0);
    }
    do { } while (0);
    readch(calc);
    if (g_tflag)
        start_timer(&start);
    val = expression(calc);
    do { } while (0);
    do { } while (0);
    check_validate(calc, val);
    if (calc->ch != '\0')
        set_errorcode(calc, E_SYNTAX);
    if (g_tflag) {
        unsigned int calc_time = stop_timer(&start);
        { (void)fprintf(stderr, "time of %s: %f[msec]\n", "calc_time", calc_time*1.0e-3); };
    }
    if (is_error(calc)) {
        calc->answer = get_errormsg(calc);
        clear_error(calc);
        if (!calc->answer)
            return ((void *)0);
        do { } while (0);
    } else {
        retval = get_strlen(val, calc->fmt);
        if (retval <= 0) {
            system_log(6, 0x01, get_progname(), "calc.c", 131, __FUNCTION__, "get_strlen=%d", retval);
            return ((void *)0);
        }
        do { } while (0);
        length = (unsigned long)retval + 1;
        calc->answer = (unsigned char *)malloc(length * sizeof(unsigned char));
        if (!calc->answer) {
            system_log(6, 0x01, get_progname(), "calc.c", 140, __FUNCTION__, "malloc: length=%zu", length);
            return ((void *)0);
        }
        (void)memset(calc->answer, 0, length * sizeof(unsigned char));
        retval = snprintf((char *)calc->answer, length, calc->fmt, val);
        if (retval < 0) {
            system_log(6, 0x01, get_progname(), "calc.c", 148, __FUNCTION__, "snprintf: answer=%p, length=%zu", calc->answer, length);
            return ((void *)0);
        }
        do { } while (0);
        do { } while (0);
    }
    return calc->answer;
}

variable_types:
expr
unsigned char *

variable_types: val double

variable_types: retval int

variable_types:
start
unsigned int

return_type: unsigned char *


decompiled_code:
__int64 __fastcall destroy_answer(__int64 a1)
{
return memfree(a1 + 16, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return memfree(a1 + 16, 0LL);
}

original_code:
void
destroy_answer(void *calc)
{
    calcinfo *ptr = (calcinfo *)calc;
    do { } while (0);
    memfree((void **)&ptr->answer, ((void *)0));
}

canonical_original_code:
void destroy_answer(void *calc)
{
    struct _calcinfo *ptr = (calcinfo *)calc;
    do { } while (0);
    memfree((void **)&ptr->answer, ((void *)0));
}

variable_types:
calc
void *


decompiled_code:
void __fastcall set_digit(__int64 a1)
{
digit = a1;
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
digit = a1;
}

original_code:
void
set_digit(long dgt)
{
    digit = dgt;
}

variable_types: dgt long


decompiled_code:
double __fastcall get_deg(double a1)
{
double result; // xmm0_8

result = 0.0;
if ( !(unsigned __int8)is_error() )
result = a1 * 180.0 / 3.141592653589793;
return result;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
double result; // xmm0_8

result = 0.0;
if ( !(unsigned __int8)is_error() )
result = a1 * 180.0 / 3.141592653589793;
return result;
}

original_code:
static double
get_deg(calcinfo *calc, double x)
{
    double result = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    result = x * 180 / DEF_PI;
    return result;
}

canonical_original_code:
static double get_deg(struct _calcinfo *calc, double x)
{
    double result = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    result = x * 180 / DEF_PI;
    return result;
}


decompiled_code:
double __fastcall get_rad(double a1)
{
double result; // xmm0_8

result = 0.0;
if ( !(unsigned __int8)is_error() )
result = a1 * 3.141592653589793 / 180.0;
return result;
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
double result; // xmm0_8

result = 0.0;
if ( !(unsigned __int8)is_error() )
result = a1 * 3.141592653589793 / 180.0;
return result;
}

original_code:
static double
get_rad(calcinfo *calc, double x)
{
    double result = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    result = x * DEF_PI / 180;
    return result;
}

canonical_original_code:
static double get_rad(struct _calcinfo *calc, double x)
{
    double result = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    result = x * DEF_PI / 180;
    return result;
}


decompiled_code:
double get_e()
{
double result; // xmm0_8

result = *(double *)&LC3;
if ( (unsigned __int8)is_error() )
result = 0.0;
return result;
}

canonical_decompiled_code:
double func2()
{
double result; // xmm0_8

result = *(double *)&LC3;
if ( (unsigned __int8)is_error() )
result = 0.0;
return result;
}

original_code:
static double
get_e(calcinfo *calc)
{
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    return DEF_E;
}

canonical_original_code:
static double get_e(struct _calcinfo *calc)
{
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    return DEF_E;
}


decompiled_code:
double get_pi()
{
double result; // xmm0_8

result = *(double *)&LC2;
if ( (unsigned __int8)is_error() )
result = 0.0;
return result;
}

canonical_decompiled_code:
double func3()
{
double result; // xmm0_8

result = *(double *)&LC2;
if ( (unsigned __int8)is_error() )
result = 0.0;
return result;
}

original_code:
static double
get_pi(calcinfo *calc)
{
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    return DEF_PI;
}

canonical_original_code:
static double get_pi(struct _calcinfo *calc)
{
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    return DEF_PI;
}


decompiled_code:
__m128d __fastcall get_factorial(__int64 a1, double a2)
{
__m128d v2; // xmm1
char v4; // bl
double v5; // xmm0_8
double v6; // xmm3_8
double iptr[4]; // [rsp+18h] [rbp-20h] BYREF

iptr[0] = 0.0;
if ( (unsigned __int8)is_error() )
return (__m128d)0LL;
v4 = 0;
if ( modf(a2, iptr) != 0.0 )
{
set_errorcode(a1, 4LL);
return (__m128d)0LL;
}
if ( a2 < 0.0 )
{
v4 = 1;
*(_QWORD *)&v5 = *(_QWORD *)&a2 ^ LC6;
if ( a2 >= 0.0 )
return (__m128d)(unsigned __int64)LC5;
}
else
{
v5 = a2;
v2 = (__m128d)(unsigned __int64)LC4;
if ( a2 <= 0.0 )
return v2;
}
v2 = (__m128d)(unsigned __int64)LC4;
do
{
v6 = v5;
v5 = v5 - 1.0;
v2.m128d_f64[0] = v2.m128d_f64[0] * v6;
}
while ( v5 > 0.0 );
if ( !v4 )
return v2;
return _mm_xor_pd(v2, (__m128d)LC6);
}

original_code:
static double
get_factorial(calcinfo *calc, double n)
{
    double result = 1.0;
    double decimal = 0.0;
    double integer = 0.0;
    _Bool minus = 0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    decimal = modf(n, &integer);
    do { } while (0);
    if (decimal) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    if (__builtin_isless(n, 0)) {
        n *= -1;
        minus = 1;
    }
    while (n > 0)
        result *= n--;
    if (minus)
        result *= -1;
    minus = 0;
    do { } while (0);
    return result;
}

canonical_original_code:
static double get_factorial(struct _calcinfo *calc, double n)
{
    double result = 1.0;
    double decimal = 0.0;
    double integer = 0.0;
    _Bool minus = 0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    decimal = modf(n, &integer);
    do { } while (0);
    if (decimal) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    if (__builtin_isless(n, 0)) {
        n *= -1;
        minus = 1;
    }
    while (n > 0)
        result *= n--;
    if (minus)
        result *= -1;
    minus = 0;
    do { } while (0);
    return result;
}

variable_types: n double

variable_types: decimal double

variable_types: integer double


decompiled_code:
double __fastcall get_combination(__int64 a1, double a2, double a3)
{
double result; // xmm0_8
double v4; // rbx
double v5; // xmm0_8
double v6; // xmm1_8

result = 0.0;
if ( !(unsigned __int8)is_error() )
{
if ( a3 <= a2 && a2 >= 0.0 && a3 >= 0.0 )
{
*(_QWORD *)&v4 = *(_OWORD *)&get_factorial(a1, a2);
*(_QWORD *)&v5 = *(_OWORD *)&get_factorial(a1, a3);
v6 = v5;
if ( a2 - a3 > 0.0 )
v6 = v5 * get_factorial(a1, a2 - a3).m128d_f64[0];
result = v4 / v6;
}
else
{
set_errorcode(a1, 4LL);
result = 0.0;
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func5(__int64 a1, double a2, double a3)
{
double result; // xmm0_8
double v4; // rbx
double v5; // xmm0_8
double v6; // xmm1_8

result = 0.0;
if ( !(unsigned __int8)is_error() )
{
if ( a3 <= a2 && a2 >= 0.0 && a3 >= 0.0 )
{
*(_QWORD *)&v4 = *(_OWORD *)&func4(a1, a2);
*(_QWORD *)&v5 = *(_OWORD *)&func4(a1, a3);
v6 = v5;
if ( a2 - a3 > 0.0 )
v6 = v5 * func4(a1, a2 - a3).m128d_f64[0];
result = v4 / v6;
}
else
{
set_errorcode(a1, 4LL);
result = 0.0;
}
}
return result;
}

original_code:
static double
get_combination(calcinfo *calc, double n, double r)
{
    double result = 0.0;
    double x = 0.0, y = 0.0, z = 1.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if (__builtin_isless(n, 0) || __builtin_isless(r, 0) ||
        __builtin_isless(n, r)) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    x = get_factorial(calc, n);
    y = get_factorial(calc, r);
    if (__builtin_isgreater((n - r), 0))
        z = get_factorial(calc, n - r);
    do { } while (0);
    result = x / (y * z);
    do { } while (0);
    return result;
}

canonical_original_code:
static double get_combination(struct _calcinfo *calc, double n, double r)
{
    double result = 0.0;
    double x = 0.0; double y = 0.0; double z = 1.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if (__builtin_isless(n, 0) || __builtin_isless(r, 0) ||
        __builtin_isless(n, r)) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    x = get_factorial(calc, n);
    y = get_factorial(calc, r);
    if (__builtin_isgreater((n - r), 0))
        z = get_factorial(calc, n - r);
    do { } while (0);
    result = x / (y * z);
    do { } while (0);
    return result;
}

variable_types: r double

variable_types: z double


decompiled_code:
double __fastcall get_permutation(__int64 a1, double a2, double a3)
{
double v3; // xmm1_8
double v4; // xmm0_8

v3 = 0.0;
if ( (unsigned __int8)is_error() )
return v3;
if ( a3 <= a2 && a2 >= 0.0 && a3 >= 0.0 )
{
*(_QWORD *)&v4 = *(_OWORD *)&get_factorial(a1, a2);
v3 = v4;
if ( a2 - a3 > 0.0 )
v3 = v4 / get_factorial(a1, a2 - a3).m128d_f64[0];
return v3;
}
set_errorcode(a1, 4LL);
return 0.0;
}

canonical_decompiled_code:
double __fastcall func6(__int64 a1, double a2, double a3)
{
double v3; // xmm1_8
double v4; // xmm0_8

v3 = 0.0;
if ( (unsigned __int8)is_error() )
return v3;
if ( a3 <= a2 && a2 >= 0.0 && a3 >= 0.0 )
{
*(_QWORD *)&v4 = *(_OWORD *)&func4(a1, a2);
v3 = v4;
if ( a2 - a3 > 0.0 )
v3 = v4 / func4(a1, a2 - a3).m128d_f64[0];
return v3;
}
set_errorcode(a1, 4LL);
return 0.0;
}

original_code:
static double
get_permutation(calcinfo *calc, double n, double r)
{
    double result = 0.0;
    double x = 0.0, y = 1.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if (__builtin_isless(n, 0) || __builtin_isless(r, 0) ||
        __builtin_isless(n, r)) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    x = get_factorial(calc, n);
    do { } while (0);
    if (__builtin_isgreater((n - r), 0))
        y = get_factorial(calc, n - r);
    do { } while (0);
    result = x / y;
    do { } while (0);
    return result;
}

canonical_original_code:
static double get_permutation(struct _calcinfo *calc, double n, double r)
{
    double result = 0.0;
    double x = 0.0; double y = 1.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if (__builtin_isless(n, 0) || __builtin_isless(r, 0) ||
        __builtin_isless(n, r)) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    x = get_factorial(calc, n);
    do { } while (0);
    if (__builtin_isgreater((n - r), 0))
        y = get_factorial(calc, n - r);
    do { } while (0);
    result = x / y;
    do { } while (0);
    return result;
}

variable_types: struct _calcinfo { int ch; unsigned char *ptr; unsigned char *answer; char fmt[-1]; enum _ER { E_NONE=0, E_DIVBYZERO=1, E_SYNTAX=2, E_NOFUNC=3, E_NAN=4, E_INFINITY=5, MAXERROR=6 } errorcode; } *

variable_types: x double


decompiled_code:
void __fastcall get_log(__int64 a1, double a2)
{
if ( !(unsigned __int8)is_error() )
{
if ( a2 < 0.0 )
set_errorcode(a1, 4LL);
else
log10(a2);
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, double a2)
{
if ( !(unsigned __int8)is_error() )
{
if ( a2 < 0.0 )
set_errorcode(a1, 4LL);
else
log10(a2);
}
}

original_code:
static double
get_log(calcinfo *calc, double x)
{
    double result = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if (__builtin_isless(x, 0)) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    result = log10(x);
    return result;
}

canonical_original_code:
static double get_log(struct _calcinfo *calc, double x)
{
    double result = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if (__builtin_isless(x, 0)) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    result = log10(x);
    return result;
}

variable_types: result double


decompiled_code:
void __fastcall get_ln(__int64 a1, double a2)
{
if ( !(unsigned __int8)is_error() )
{
if ( a2 < 0.0 )
set_errorcode(a1, 4LL);
else
log(a2);
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, double a2)
{
if ( !(unsigned __int8)is_error() )
{
if ( a2 < 0.0 )
set_errorcode(a1, 4LL);
else
log(a2);
}
}

original_code:
static double
get_ln(calcinfo *calc, double x)
{
    double result = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if (__builtin_isless(x, 0)) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    result = log(x);
    return result;
}

canonical_original_code:
static double get_ln(struct _calcinfo *calc, double x)
{
    double result = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if (__builtin_isless(x, 0)) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    result = log(x);
    return result;
}


decompiled_code:
double __fastcall get_sqrt(__int64 a1, double a2)
{
double result; // xmm0_8

result = 0.0;
if ( !(unsigned __int8)is_error() )
{
if ( a2 < 0.0 )
{
set_errorcode(a1, 4LL);
result = 0.0;
}
else
{
result = sqrt(a2);
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func9(__int64 a1, double a2)
{
double result; // xmm0_8

result = 0.0;
if ( !(unsigned __int8)is_error() )
{
if ( a2 < 0.0 )
{
set_errorcode(a1, 4LL);
result = 0.0;
}
else
{
result = sqrt(a2);
}
}
return result;
}

original_code:
static double
get_sqrt(calcinfo *calc, double x)
{
    double result = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if (__builtin_isless(x, 0)) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    result = sqrt(x);
    return result;
}

canonical_original_code:
static double get_sqrt(struct _calcinfo *calc, double x)
{
    double result = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if (__builtin_isless(x, 0)) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    result = sqrt(x);
    return result;
}


decompiled_code:
double __fastcall exec_func(__int64 a1, const char *a2)
{
const char *v2; // rbp
int v3; // ebx
__int64 v4; // rcx
__int64 *v5; // rbx
unsigned int v6; // eax
double result; // xmm0_8
__int64 v8; // rax
double v9; // [rsp+10h] [rbp-38h] BYREF
double v10[6]; // [rsp+18h] [rbp-30h] BYREF

v2 = s1;
v3 = 0;
v9 = 0.0;
v10[0] = 0.0;
clear_math_feexcept();
while ( strcmp(v2, a2) )
{
++v3;
v2 += 12;
if ( v3 == 18 )
{
set_errorcode(a1, 3LL);
result = 0.0;
goto LABEL_7;
}
}
v5 = &finfo[2 * *((unsigned int *)&fstring + 3 * v3)];
v6 = *(_DWORD *)v5;
if ( *(_DWORD *)v5 == 2 )
{
parse_func_args(a1, &v9, v10, 0LL);
result = v9;
((void (__fastcall *)(__int64, double, double))v5[1])(a1, v9, v10[0]);
}
else if ( v6 > 2 )
{
if ( v6 == 3 )
{
parse_func_args(a1, &v9, 0LL, v4);
result = v9;
((void (__fastcall *)(double))v5[1])(v9);
}
else
{
v8 = get_progname();
system_log(6LL, 1LL, v8, "func.c", 170LL, "exec_func", "no functype");
result = 0.0;
}
}
else if ( v6 )
{
parse_func_args(a1, &v9, 0LL, v4);
result = ((double (__fastcall *)(__int64, double))v5[1])(a1, v9);
}
else
{
((void (__fastcall *)(__int64))v5[1])(a1);
}
LABEL_7:
check_math_feexcept(a1);
return result;
}

canonical_decompiled_code:
double __fastcall func10(__int64 a1, const char *a2)
{
const char *v2; // rbp
int v3; // ebx
__int64 v4; // rcx
__int64 *v5; // rbx
unsigned int v6; // eax
double result; // xmm0_8
__int64 v8; // rax
double v9; // [rsp+10h] [rbp-38h] BYREF
double v10[6]; // [rsp+18h] [rbp-30h] BYREF

v2 = s1;
v3 = 0;
v9 = 0.0;
v10[0] = 0.0;
clear_math_feexcept();
while ( strcmp(v2, a2) )
{
++v3;
v2 += 12;
if ( v3 == 18 )
{
set_errorcode(a1, 3LL);
result = 0.0;
goto LABEL_7;
}
}
v5 = &finfo[2 * *((unsigned int *)&fstring + 3 * v3)];
v6 = *(_DWORD *)v5;
if ( *(_DWORD *)v5 == 2 )
{
parse_func_args(a1, &v9, v10, 0LL);
result = v9;
((void (__fastcall *)(__int64, double, double))v5[1])(a1, v9, v10[0]);
}
else if ( v6 > 2 )
{
if ( v6 == 3 )
{
parse_func_args(a1, &v9, 0LL, v4);
result = v9;
((void (__fastcall *)(double))v5[1])(v9);
}
else
{
v8 = get_progname();
system_log(6LL, 1LL, v8, "func.c", 170LL, "exec_func", "no functype");
result = 0.0;
}
}
else if ( v6 )
{
parse_func_args(a1, &v9, 0LL, v4);
result = ((double (__fastcall *)(__int64, double))v5[1])(a1, v9);
}
else
{
((void (__fastcall *)(__int64))v5[1])(a1);
}
LABEL_7:
check_math_feexcept(a1);
return result;
}

original_code:
double
exec_func(calcinfo *calc, const char *func)
{
    double result = 0.0;
    double x = 0.0, y = 0.0;
    _Bool exec;
    enum functype ftype;
    do { } while (0);
    clear_math_feexcept();
    int i;
    for (i = 0, exec = 0; i < MAXFUNC && !exec; i++) {
        if (!strcmp(fstring[i].funcname, func)) {
            ftype = fstring[i].type;
            do { } while (0);
            switch (finfo[ftype].type) {
                do { } while (0);
            case FUNC0:
                result = finfo[ftype].func.func0(calc);
                break;
            case FUNC1:
                parse_func_args(calc, &x, ((void *)0));
                result = finfo[ftype].func.func1(calc, x);
                break;
            case FUNC2:
                parse_func_args(calc, &x, &y, ((void *)0));
                result = finfo[ftype].func.func2(calc, x, y);
                break;
            case MATH:
                parse_func_args(calc, &x, ((void *)0));
                result = finfo[ftype].func.math(x);
                break;
            default:
                system_log(6, 0x01, get_progname(), "func.c", 170, __FUNCTION__, "no functype");
                break;
            }
            exec = 1;
        }
    }
    if (!exec)
        set_errorcode(calc, E_NOFUNC);
    check_math_feexcept(calc);
    do { } while (0);
    do { } while (0);
    return result;
}

canonical_original_code:
double exec_func(struct _calcinfo *calc, char *func)
{
    double result = 0.0;
    double x = 0.0; double y = 0.0;
    _Bool exec;
    enum functype ftype;
    do { } while (0);
    clear_math_feexcept();
    int i;
    for (i = 0, exec = 0; i < MAXFUNC && !exec; i++) {
        if (!strcmp(fstring[i].funcname, func)) {
            ftype = fstring[i].type;
            do { } while (0);
            switch (finfo[ftype].type) {
                do { } while (0);
            case FUNC0:
                result = finfo[ftype].func.func0(calc);
                break;
            case FUNC1:
                parse_func_args(calc, &x, ((void *)0));
                result = finfo[ftype].func.func1(calc, x);
                break;
            case FUNC2:
                parse_func_args(calc, &x, &y, ((void *)0));
                result = finfo[ftype].func.func2(calc, x, y);
                break;
            case MATH:
                parse_func_args(calc, &x, ((void *)0));
                result = finfo[ftype].func.math(x);
                break;
            default:
                system_log(6, 0x01, get_progname(), "func.c", 170, __FUNCTION__, "no functype");
                break;
            }
            exec = 1;
        }
    }
    if (!exec)
        set_errorcode(calc, E_NOFUNC);
    check_math_feexcept(calc);
    do { } while (0);
    do { } while (0);
    return result;
}

variable_types:
func
char *

variable_types: y double

variable_types: enum functype { FN_PI=0, FN_E=1, FN_ABS=2, FN_SQRT=3, FN_SIN=4, FN_COS=5, FN_TAN=6, FN_ASIN=7, FN_ACOS=8, FN_ATAN=9, FN_EXP=10, FN_LN=11, FN_LOG=12, FN_RAD=13, FN_DEG=14, FN_FACT=15, FN_PERM=16, FN_COMB=17, MAXFUNC=18 }

variable_types: i int


decompiled_code:
double __fastcall get_pow(__int64 a1, double a2, double a3)
{
double result; // xmm0_8
double v5; // xmm0_8
double y; // [rsp+0h] [rbp-20h]

result = 0.0;
if ( !(unsigned __int8)is_error() )
{
*(_QWORD *)&v5 = *(_QWORD *)&a2 & LC9;
if ( COERCE_DOUBLE(*(_QWORD *)&a2 & LC9) <= 1.797693134862316e308
&& v5 < 2.225073858507201e-308
&& (v5 = 0.0, a2 == 0.0)
&& a3 < 0.0 )
{
set_errorcode(a1, 4LL);
result = 0.0;
}
else
{
clear_math_feexcept(v5, a3, a2);
y = pow(a2, a3);
check_math_feexcept(a1);
result = y;
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func11(__int64 a1, double a2, double a3)
{
double result; // xmm0_8
double v5; // xmm0_8
double y; // [rsp+0h] [rbp-20h]

result = 0.0;
if ( !(unsigned __int8)is_error() )
{
*(_QWORD *)&v5 = *(_QWORD *)&a2 & LC9;
if ( COERCE_DOUBLE(*(_QWORD *)&a2 & LC9) <= 1.797693134862316e308
&& v5 < 2.225073858507201e-308
&& (v5 = 0.0, a2 == 0.0)
&& a3 < 0.0 )
{
set_errorcode(a1, 4LL);
result = 0.0;
}
else
{
clear_math_feexcept(v5, a3, a2);
y = pow(a2, a3);
check_math_feexcept(a1);
result = y;
}
}
return result;
}

original_code:
double
get_pow(calcinfo *calc, double x, double y)
{
    double result = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if ((__builtin_fpclassify (0, 1, 4, 3, 2, x) == 2) && __builtin_isless(y, 0)) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    clear_math_feexcept();
    result = pow(x, y);
    check_math_feexcept(calc);
    return result;
}

canonical_original_code:
double get_pow(struct _calcinfo *calc, double x, double y)
{
    double result = 0.0;
    do { } while (0);
    if (is_error(calc))
        return EX_ERROR;
    if ((__builtin_fpclassify (0, 1, 4, 3, 2, x) == 2) && __builtin_isless(y, 0)) {
        set_errorcode(calc, E_NAN);
        return EX_ERROR;
    }
    clear_math_feexcept();
    result = pow(x, y);
    check_math_feexcept(calc);
    return result;
}


decompiled_code:
char *__fastcall get_errormsg(__int64 a1)
{
__int64 v1; // rax
char *v2; // r12
__int64 v4; // rax

v1 = *(unsigned int *)(a1 + 32);
v2 = 0LL;
if ( (unsigned int)(v1 - 1) <= 4 )
{
v2 = strdup(*((const char **)&errormsg + v1));
if ( !v2 )
{
v4 = get_progname();
system_log(6LL, 1LL, v4, "error.c", 71LL, "get_errormsg", "strdup", v4);
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1)
{
__int64 v1; // rax
char *v2; // r12
__int64 v4; // rax

v1 = *(unsigned int *)(a1 + 32);
v2 = 0LL;
if ( (unsigned int)(v1 - 1) <= 4 )
{
v2 = strdup(*((const char **)&errormsg + v1));
if ( !v2 )
{
v4 = get_progname();
system_log(6LL, 1LL, v4, "error.c", 71LL, "get_errormsg", "strdup", v4);
}
}
return v2;
}

original_code:
unsigned char *
get_errormsg(calcinfo *calc)
{
    unsigned char *msg = ((void *)0);
    do { } while (0);
    ((void) (0));
    if (calc->errorcode <= E_NONE ||
        MAXERROR <= calc->errorcode)
        return ((void *)0);
    do { } while (0);
    msg = (unsigned char *)strdup(errormsg[calc->errorcode]);
    if (!msg) {
        system_log(6, 0x01, get_progname(), "error.c", 71, __FUNCTION__, "strdup");
        return ((void *)0);
    }
    return msg;
}

canonical_original_code:
unsigned char *get_errormsg(struct _calcinfo *calc)
{
    unsigned char *msg = ((void *)0);
    do { } while (0);
    ((void) (0));
    if (calc->errorcode <= E_NONE ||
        MAXERROR <= calc->errorcode)
        return ((void *)0);
    do { } while (0);
    msg = (unsigned char *)strdup(errormsg[calc->errorcode]);
    if (!msg) {
        system_log(6, 0x01, get_progname(), "error.c", 71, __FUNCTION__, "strdup");
        return ((void *)0);
    }
    return msg;
}

variable_types:
msg
unsigned char *


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

result = *(unsigned int *)(a1 + 32);
if ( !(_DWORD)result )
*(_DWORD *)(a1 + 32) = a2;
return result;
}

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

result = *(unsigned int *)(a1 + 32);
if ( !(_DWORD)result )
*(_DWORD *)(a1 + 32) = a2;
return result;
}

original_code:
void
set_errorcode(calcinfo *calc, ER error)
{
    do { } while (0);
    if (calc->errorcode == E_NONE)
        calc->errorcode = error;
}

canonical_original_code:
void set_errorcode(struct _calcinfo *calc, enum _ER error)
{
    do { } while (0);
    if (calc->errorcode == E_NONE)
        calc->errorcode = error;
}

variable_types: enum _ER { E_NONE=0, E_DIVBYZERO=1, E_SYNTAX=2, E_NOFUNC=3, E_NAN=4, E_INFINITY=5, MAXERROR=6 }


decompiled_code:
void __fastcall clear_error(__int64 a1)
{
*(_DWORD *)(a1 + 32) = 0;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
*(_DWORD *)(a1 + 32) = 0;
}

original_code:
void
clear_error(calcinfo *calc)
{
    do { } while (0);
    calc->errorcode = E_NONE;
}

canonical_original_code:
void clear_error(struct _calcinfo *calc)
{
    do { } while (0);
    calc->errorcode = E_NONE;
}


decompiled_code:
bool __fastcall is_error(__int64 a1)
{
return *(_DWORD *)(a1 + 32) != 0;
}

canonical_decompiled_code:
bool __fastcall func3(__int64 a1)
{
return *(_DWORD *)(a1 + 32) != 0;
}

original_code:
_Bool
is_error(calcinfo *calc)
{
    do { } while (0);
    if (calc->errorcode)
        return 1;
    return 0;
}

canonical_original_code:
_Bool is_error(struct _calcinfo *calc)
{
    do { } while (0);
    if (calc->errorcode)
        return 1;
    return 0;
}


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

if ( COERCE_DOUBLE(*(_QWORD *)&a2 & LC2) > 1.797693134862316e308 )
result = set_errorcode(a1, 5);
return result;
}

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

if ( COERCE_DOUBLE(*(_QWORD *)&a2 & LC2) > 1.797693134862316e308 )
result = func1(a1, 5);
return result;
}

original_code:
void
check_validate(calcinfo *calc, double val)
{
    do { } while (0);
    if (__builtin_isnan (val))
        set_errorcode(calc, E_NAN);
    else if (__builtin_isinf_sign (val) != 0)
        set_errorcode(calc, E_INFINITY);
    do { } while (0);
}

canonical_original_code:
void check_validate(struct _calcinfo *calc, double val)
{
    do { } while (0);
    if (__builtin_isnan (val))
        set_errorcode(calc, E_NAN);
    else if (__builtin_isinf_sign (val) != 0)
        set_errorcode(calc, E_INFINITY);
    do { } while (0);
}

variable_types: val double