ncopy

original_code:
short ncopy(u_char **src, u_char *dst)
{ u_char c;
  u_char *p;
  int i = 0;
  int k = 0;
  int dp = 0;
  int minus = 0;
  int exp = 0;
  int expsgn = 1;
  if ( (dst >= partab.sstk_start) &&
       (dst < partab.sstk_last) &&
       (&dst[63] > partab.sstk_last))
  { return -(200 +8);
  }
  p = *src;
  while (1)
  { c = *p++;
    if ((i == 0) && (k == 0))
    { if (c == '+')
        continue;
      if (c == '-')
      { minus = !minus;
        continue;
      }
      if (minus)
      { dst[i++] = '-';
      }
    }
    if ((i == minus) && (c == '0'))
    { k = 1;
      continue;
    }
    if (c == '.')
    { if (dp != 0) break;
      dp = 1;
      dst[i++] = c;
      continue;
    }
    if ((systab->historic & 1) && (c == 'E'))
    { c = *p++;
      if (c == '-')
      { expsgn = -1;
      }
      else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
      { exp = c - '0';
      }
      else if (c != '+')
      { break;
      }
      while (1)
      { c = *p++;
        if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit) == 0) break;
 exp = (exp * 10) + (c - '0');
      }
      break;
    }
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit) == 0) break;
    dst[i++] = c;
  }
  if (dp)
  { for (k = 0; dst[i-k-1] == '0'; k++);
    i -= k;
    if (dst[i - 1] == '.') i--;
  }
  if ((i) && (dst[i - 1] == '-')) i--;
  if (i == 0) dst[i++] = '0';
  dst[i] = '\0';
  --p;
  *src = p;
  if (!exp)
  { return (short) i;
  }
  dst[i] = '0';
  dp = 0;
  for (k = 0; k < i; k++)
  { if (dst[k] == '.')
    { dp = 1;
      break;
    }
  }
  if (expsgn > 0)
  { if (dp)
    { for (; k < i; k++)
      { dst[k] = dst[k + 1];
        dst[k + 1] = '.';
        exp--;
        if (!exp)
        { goto exit;
        }
      }
    }
    if ((exp + i) > 63)
    { return -92;
    }
    while (exp)
    { dst[i++] = '0';
      exp--;
    }
    dst[i] = '\0';
    goto exit;
  }
  if (!dp)
  { k = i;
    i++;
  }
  if (k > 0)
  { for (dp = k; dp > minus; dp--)
    { dst[dp] = dst[dp - 1];
      dst[dp - 1] = '.';
      exp--;
      if (!exp)
      { goto exit;
      }
    }
  }
  if ((exp + i) > 63)
  { return -92;
  }
  bcopy(&dst[minus + 1], &dst[minus + exp + 1], i);
  for (k = minus + 1; k <= (minus + exp); dst[k++] = '0');
  i +=exp;
exit:
  dp = 0;
  for (k = 0; k < i; k++)
  { if (dst[k] == '.')
    { dp = 1;
      break;
    }
  }
  if (dp)
  { while (dst[i - 1] == '0')
    { i--;
    }
    if (dst[i - 1] == '.')
    { i--;
    }
  }
  if (!i)
  { dst[i++] = '0';
  }
  dst[i] = '\0';
  dp = (dst[0] == '-');
  if (dst[dp] == '0')
  { for (k = dp; (k < i) && (dst[k] == '0'); k++);
    bcopy(&dst[k], &dst[dp], i - k);
    i -= (k - dp);
    if (i == dp)
    { if (dp)
      { i--;
      }
      dst[i++] = '0';
    }
    dst[i] = '\0';
  }
  return (short) i;
}

canonical_original_code:
short ncopy(unsigned char **src, unsigned char *dst)
{ unsigned char c;
  unsigned char *p;
  int i = 0;
  int k = 0;
  int dp = 0;
  int minus = 0;
  int exp = 0;
  int expsgn = 1;
  if ( (dst >= partab.sstk_start) &&
       (dst < partab.sstk_last) &&
       (&dst[63] > partab.sstk_last))
  { return -(200 +8);
  }
  p = *src;
  while (1)
  { c = *p++;
    if ((i == 0) && (k == 0))
    { if (c == '+')
        continue;
      if (c == '-')
      { minus = !minus;
        continue;
      }
      if (minus)
      { dst[i++] = '-';
      }
    }
    if ((i == minus) && (c == '0'))
    { k = 1;
      continue;
    }
    if (c == '.')
    { if (dp != 0) break;
      dp = 1;
      dst[i++] = c;
      continue;
    }
    if ((systab->historic & 1) && (c == 'E'))
    { c = *p++;
      if (c == '-')
      { expsgn = -1;
      }
      else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
      { exp = c - '0';
      }
      else if (c != '+')
      { break;
      }
      while (1)
      { c = *p++;
        if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit) == 0) break;
 exp = (exp * 10) + (c - '0');
      }
      break;
    }
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit) == 0) break;
    dst[i++] = c;
  }
  if (dp)
  { for (k = 0; dst[i-k-1] == '0'; k++);
    i -= k;
    if (dst[i - 1] == '.') i--;
  }
  if ((i) && (dst[i - 1] == '-')) i--;
  if (i == 0) dst[i++] = '0';
  dst[i] = '\0';
  --p;
  *src = p;
  if (!exp)
  { return (short) i;
  }
  dst[i] = '0';
  dp = 0;
  for (k = 0; k < i; k++)
  { if (dst[k] == '.')
    { dp = 1;
      break;
    }
  }
  if (expsgn > 0)
  { if (dp)
    { for (; k < i; k++)
      { dst[k] = dst[k + 1];
        dst[k + 1] = '.';
        exp--;
        if (!exp)
        { goto exit;
        }
      }
    }
    if ((exp + i) > 63)
    { return -92;
    }
    while (exp)
    { dst[i++] = '0';
      exp--;
    }
    dst[i] = '\0';
    goto exit;
  }
  if (!dp)
  { k = i;
    i++;
  }
  if (k > 0)
  { for (dp = k; dp > minus; dp--)
    { dst[dp] = dst[dp - 1];
      dst[dp - 1] = '.';
      exp--;
      if (!exp)
      { goto exit;
      }
    }
  }
  if ((exp + i) > 63)
  { return -92;
  }
  bcopy(&dst[minus + 1], &dst[minus + exp + 1], i);
  for (k = minus + 1; k <= (minus + exp); dst[k++] = '0');
  i +=exp;
exit:
  dp = 0;
  for (k = 0; k < i; k++)
  { if (dst[k] == '.')
    { dp = 1;
      break;
    }
  }
  if (dp)
  { while (dst[i - 1] == '0')
    { i--;
    }
    if (dst[i - 1] == '.')
    { i--;
    }
  }
  if (!i)
  { dst[i++] = '0';
  }
  dst[i] = '\0';
  dp = (dst[0] == '-');
  if (dst[dp] == '0')
  { for (k = dp; (k < i) && (dst[k] == '0'); k++);
    bcopy(&dst[k], &dst[dp], i - k);
    i -= (k - dp);
    if (i == dp)
    { if (dp)
      { i--;
      }
      dst[i++] = '0';
    }
    dst[i] = '\0';
  }
  return (short) i;
}

variable_types:
src
unsigned char **

variable_types:
c
unsigned char

variable_types:
p
unsigned char *

variable_types: i int

variable_types: k int

variable_types: dp int

variable_types: minus int

variable_types: exp int

variable_types: expsgn int


repo: jcwynholds/mumps

decompiled_code:
__int64 __fastcall DB_UCIKill(int a1, int a2)
{
int v2; // ebx
int v3; // esi
unsigned int v4; // er12
_QWORD *v5; // rdx
__int64 v6; // rax
unsigned int v7; // ebp
__int64 v8; // rdx
__int64 v9; // rax
__int64 v10; // rdx
__int64 v11; // rcx
__int64 v12; // rax

if ( a1 != 1 )
return (unsigned int)-26;
v2 = a2 - 1;
if ( (unsigned int)(a2 - 1) > 0x3F )
return (unsigned int)-26;
do
{
if ( !*(_DWORD *)(*(_QWORD *)(systab + 8LL * (volnum - 1) + 228) + 16632LL) )
{
v3 = *(_DWORD *)(systab + 16LL);
volnum = 1;
writing = 1;
level = 0;
v4 = SemOp(2LL, (unsigned int)-v3);
if ( (v4 & 0x8000u) != 0 )
return v4;
v5 = *(_QWORD **)(systab + 228LL);
if ( !v5 )
{
v4 = -26;
SemOp(2LL, (unsigned int)-curr_lock);
return v4;
}
v6 = *v5 + 12LL * v2;
if ( *(_BYTE *)(v6 + 256) )
{
v7 = *(_DWORD *)(v6 + 264);
v4 = Get_block(v7);
if ( (v4 & 0x8000u) != 0 )
{
SemOp(2LL, (unsigned int)-curr_lock);
return v4;
}
v8 = level;
v9 = *((_QWORD *)&blk + level);
if ( *(_QWORD *)(v9 + 20) == 1LL )
{
*(_QWORD *)(v9 + 20) = 0LL;
v9 = *((_QWORD *)&blk + v8);
}
v10 = *(_QWORD *)(v9 + 12);
if ( *(_WORD *)(v10 + 8) > 0xAu )
{
v4 = -29;
SemOp(2LL, (unsigned int)-curr_lock);
return v4;
}
v11 = *(_QWORD *)(systab + 228LL);
v12 = *(_QWORD *)v11 + 12LL * v2;
*(_DWORD *)(v12 + 264) = 0;
*(_QWORD *)(v12 + 256) = 0LL;
*(_DWORD *)(v11 + 16628) = 1;
*(_WORD *)(v10 + 8) = 9;
Garbit(v7);
memset((void *)(systab + 236LL), 0, 4LL * *(int *)(systab + 16LL));
}
v4 = 0;
SemOp(2LL, (unsigned int)-curr_lock);
return v4;
}
sleep(5u);
}
while ( !*(_DWORD *)(partab + 28LL) );
return 4294967045LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
int v2; // ebx
int v3; // esi
unsigned int v4; // er12
_QWORD *v5; // rdx
__int64 v6; // rax
unsigned int v7; // ebp
__int64 v8; // rdx
__int64 v9; // rax
__int64 v10; // rdx
__int64 v11; // rcx
__int64 v12; // rax

if ( a1 != 1 )
return (unsigned int)-26;
v2 = a2 - 1;
if ( (unsigned int)(a2 - 1) > 0x3F )
return (unsigned int)-26;
do
{
if ( !*(_DWORD *)(*(_QWORD *)(systab + 8LL * (volnum - 1) + 228) + 16632LL) )
{
v3 = *(_DWORD *)(systab + 16LL);
volnum = 1;
writing = 1;
level = 0;
v4 = SemOp(2LL, (unsigned int)-v3);
if ( (v4 & 0x8000u) != 0 )
return v4;
v5 = *(_QWORD **)(systab + 228LL);
if ( !v5 )
{
v4 = -26;
SemOp(2LL, (unsigned int)-curr_lock);
return v4;
}
v6 = *v5 + 12LL * v2;
if ( *(_BYTE *)(v6 + 256) )
{
v7 = *(_DWORD *)(v6 + 264);
v4 = Get_block(v7);
if ( (v4 & 0x8000u) != 0 )
{
SemOp(2LL, (unsigned int)-curr_lock);
return v4;
}
v8 = level;
v9 = *((_QWORD *)&blk + level);
if ( *(_QWORD *)(v9 + 20) == 1LL )
{
*(_QWORD *)(v9 + 20) = 0LL;
v9 = *((_QWORD *)&blk + v8);
}
v10 = *(_QWORD *)(v9 + 12);
if ( *(_WORD *)(v10 + 8) > 0xAu )
{
v4 = -29;
SemOp(2LL, (unsigned int)-curr_lock);
return v4;
}
v11 = *(_QWORD *)(systab + 228LL);
v12 = *(_QWORD *)v11 + 12LL * v2;
*(_DWORD *)(v12 + 264) = 0;
*(_QWORD *)(v12 + 256) = 0LL;
*(_DWORD *)(v11 + 16628) = 1;
*(_WORD *)(v10 + 8) = 9;
Garbit(v7);
memset((void *)(systab + 236LL), 0, 4LL * *(int *)(systab + 16LL));
}
v4 = 0;
SemOp(2LL, (unsigned int)-curr_lock);
return v4;
}
sleep(5u);
}
while ( !*(_DWORD *)(partab + 28LL) );
return 4294967045LL;
}

original_code:
short DB_UCIKill(int vol, int uci)
{ short s;
  u_int gb;
  int i;
  if ((vol > 1) || (vol < 1))
  { return (-26);
  }
  if ((uci > 64) || (uci < 1))
  { return (-26);
  }
  while (systab->vol[volnum - 1]->writelock)
  { i = sleep(5);
    if (partab.jobtab->attention)
    { return -(200 +51);
    }
  }
  volnum = vol;
  writing = 1;
  level = 0;
  s = SemOp( 2, (-systab->maxjob));
  if (s < 0)
  { return s;
  }
  if (systab->vol[vol-1] == ((void *)0))
  { SemOp( 2, -curr_lock);
    return (-26);
  }
  if (systab->vol[vol-1]->vollab->
      uci[uci-1].name.var_cu[0] == '\0')
  { SemOp( 2, -curr_lock);
    return 0;
  }
  gb = systab->vol[vol-1]->vollab->uci[uci-1].global;
  s = Get_block(gb);
  if (s < 0)
  { SemOp( 2, -curr_lock);
    return s;
  }
  if (blk[level]->dirty == (gbd *) 1)
  { blk[level]->dirty = ((void *)0);
  }
  if (blk[level]->mem->last_idx > 10)
  { SemOp( 2, -curr_lock);
    return -(29);
  }
  systab->vol[vol-1]->vollab->uci[uci-1].global = 0;
  systab->vol[vol-1]->vollab->uci[uci-1].name.var_qu = 0;
  systab->vol[vol-1]->map_dirty_flag = 1;
  blk[level]->mem->last_idx = 9;
  Garbit(gb);
  bzero(&systab->last_blk_used[0], systab->maxjob * sizeof(int));
  SemOp( 2, -curr_lock);
  return 0;
}

canonical_original_code:
short DB_UCIKill(int vol, int uci)
{ short s;
  unsigned int gb;
  int i;
  if ((vol > 1) || (vol < 1))
  { return (-26);
  }
  if ((uci > 64) || (uci < 1))
  { return (-26);
  }
  while (systab->vol[volnum - 1]->writelock)
  { i = sleep(5);
    if (partab.jobtab->attention)
    { return -(200 +51);
    }
  }
  volnum = vol;
  writing = 1;
  level = 0;
  s = SemOp( 2, (-systab->maxjob));
  if (s < 0)
  { return s;
  }
  if (systab->vol[vol-1] == ((void *)0))
  { SemOp( 2, -curr_lock);
    return (-26);
  }
  if (systab->vol[vol-1]->vollab->
      uci[uci-1].name.var_cu[0] == '\0')
  { SemOp( 2, -curr_lock);
    return 0;
  }
  gb = systab->vol[vol-1]->vollab->uci[uci-1].global;
  s = Get_block(gb);
  if (s < 0)
  { SemOp( 2, -curr_lock);
    return s;
  }
  if (blk[level]->dirty == (struct GBD *) 1)
  { blk[level]->dirty = ((void *)0);
  }
  if (blk[level]->mem->last_idx > 10)
  { SemOp( 2, -curr_lock);
    return -(29);
  }
  systab->vol[vol-1]->vollab->uci[uci-1].global = 0;
  systab->vol[vol-1]->vollab->uci[uci-1].name.var_qu = 0;
  systab->vol[vol-1]->map_dirty_flag = 1;
  blk[level]->mem->last_idx = 9;
  Garbit(gb);
  bzero(&systab->last_blk_used[0], systab->maxjob * sizeof(int));
  SemOp( 2, -curr_lock);
  return 0;
}

variable_types: vol int

variable_types: uci int

variable_types: s short

variable_types:
gb
unsigned int

return_type: short

user_defined_types: struct GBD { unsigned int block; struct GBD *next; struct DB_BLOCK *mem; struct GBD *dirty; long last_accessed; }

user_defined_types: struct DB_BLOCK { unsigned char type; unsigned char flags; unsigned short spare; unsigned int right_ptr; unsigned short last_idx; unsigned short last_free; unsigned long long global; }


Vhorolog

decompiled_code:
int __fastcall Vhorolog(char *s)
{
struct tm *v1; // rax
time_t v2; // rsi
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
v2 = v1->tm_gmtoff + timer;
timer = v2 % 86400;
return sprintf(s, "%d,%d", (unsigned int)(v2 / 86400) + 47117, v2 % 86400);
}

canonical_decompiled_code:
int __fastcall func2(char *s)
{
struct tm *v1; // rax
time_t v2; // rsi
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
v2 = v1->tm_gmtoff + timer;
timer = v2 % 86400;
return sprintf(s, "%d,%d", (unsigned int)(v2 / 86400) + 47117, v2 % 86400);
}

original_code:
short Vhorolog(u_char *ret_buffer)
{ time_t sec = time(((void *)0));
  struct tm *buf;
  int day;
  buf = localtime(&sec);
  sec = sec + buf->tm_gmtoff;
  day = sec/86400 +47117;
  sec = sec%86400;
  return sprintf( (char *)ret_buffer, "%d,%d", day, (int) sec);
}

canonical_original_code:
short Vhorolog(unsigned char *ret_buffer)
{ long sec = time(((void *)0));
  struct tm *buf;
  int day;
  buf = localtime(&sec);
  sec = sec + buf->tm_gmtoff;
  day = sec/86400 +47117;
  sec = sec%86400;
  return sprintf( (char *)ret_buffer, "%d,%d", day, (int) sec);
}

variable_types: sec long

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

variable_types: day int


Vsystem

decompiled_code:
__int64 __fastcall Vsystem(__int64 a1)
{
__int16 v1; // ax

v1 = itocstring(a1, 50LL);
*(_BYTE *)(a1 + v1) = 44;
return v1 + 1 + (unsigned int)mumps_version(a1 + v1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int16 v1; // ax

v1 = itocstring(a1, 50LL);
*(_BYTE *)(a1 + v1) = 44;
return v1 + 1 + (unsigned int)mumps_version(a1 + v1 + 1);
}

original_code:
short Vsystem(u_char *ret_buffer)
{ int i;
  i = itocstring( ret_buffer, 50);
  ret_buffer[i++] = ',';
  i = i + mumps_version(&ret_buffer[i]);
  return i;
}

canonical_original_code:
short Vsystem(unsigned char *ret_buffer)
{ int i;
  i = itocstring( ret_buffer, 50);
  ret_buffer[i++] = ',';
  i = i + mumps_version(&ret_buffer[i]);
  return i;
}


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

dvar = 5259812LL;
*((_WORD *)&dvar + 4) = -256;
*((_BYTE *)&dvar + 10) = 0;
result = ST_Kill(&dvar);
partab[4] = 0;
return result;
}

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

dvar = 5259812LL;
*((_WORD *)&dvar + 4) = -256;
*((_BYTE *)&dvar + 10) = 0;
result = ST_Kill(&dvar);
partab[4] = 0;
return result;
}

original_code:
void Debug_off()
{ short s;
  bcopy("$BP\0\0\0\0\0", &dvar.name.var_cu[0], 8);
  dvar.volset = 0;
  dvar.uci = 255;
  dvar.slen = 0;
  s = ST_Kill(&dvar);
  partab.debug = 0;
  return;
}

return_type: void


original_code:
short Debug_on(cstring *param)
{ int i = 0;
  int j = 0;
  short s;
  int off = 1;
  cstring *ptr;
  debug = ((void *)0);
  bcopy("$BP\0\0\0\0\0", &dvar.name.var_cu[0], 8);
  dvar.volset = 0;
  dvar.uci = 255;
  dvar.slen = 0;
  dvar.key[0] = 128;
  if (param->buf[0] != ':')
  { if (param->buf[i] == '+')
    { i++;
      off = 0;
      while (((*__ctype_b_loc ())[(int) ((param->buf[i]))] & (unsigned short int) _ISdigit))
        off = (off * 10) + (param->buf[i++] - '0');
    }
    if (param->buf[i++] != '^')
      return -(9 +200);
    for (j = 0; j < 8; j++)
    { if ((((*__ctype_b_loc ())[(int) ((param->buf[j + i]))] & (unsigned short int) _ISalnum) == 0) &&
   ((param->buf[j + i] != '%') || (j != 0)))
        break;
      dvar.key[j + 1] = param->buf[j + i];
    }
    dvar.key[j + 1] = '\0';
    dvar.slen = j + 2;
    j = j + i;
    while (((*__ctype_b_loc ())[(int) ((param->buf[j]))] & (unsigned short int) _ISalnum)) j++;
    if ((param->buf[j] != ':') &&
        (param->buf[j] != '\0'))
   return -(9 +200);
    dvar.key[dvar.slen++] = 64;
    s = itocstring(&dvar.key[dvar.slen], off);
    dvar.key[dvar.slen - 1] |= s;
    dvar.slen += s;
    dvar.slen++;
  }
  if (param->buf[j++] == '\0')
    return ST_Kill(&dvar);
  partab.debug = -1;
  if (param->buf[j] == '\0')
  { ptr = (cstring *) src;
    ptr->len = 0;
    ptr->buf[0] = '\0';
    return ST_Set(&dvar, ptr);
  }
  if ((param->len - j) > 255)
    return -(9 +200);
  source_ptr = &param->buf[j];
  ptr = (cstring *) cmp;
  comp_ptr = ptr->buf;
  parse();
  *comp_ptr++ = 0;
  *comp_ptr++ = 0;
  ptr->len = (comp_ptr - ptr->buf);
  return ST_Set(&dvar, ptr);
}

canonical_original_code:
short Debug_on(struct CSTRING *param)
{ int i = 0;
  int j = 0;
  short s;
  int off = 1;
  struct CSTRING *ptr;
  debug = ((void *)0);
  bcopy("$BP\0\0\0\0\0", &dvar.name.var_cu[0], 8);
  dvar.volset = 0;
  dvar.uci = 255;
  dvar.slen = 0;
  dvar.key[0] = 128;
  if (param->buf[0] != ':')
  { if (param->buf[i] == '+')
    { i++;
      off = 0;
      while (((*__ctype_b_loc ())[(int) ((param->buf[i]))] & (unsigned short) _ISdigit))
        off = (off * 10) + (param->buf[i++] - '0');
    }
    if (param->buf[i++] != '^')
      return -(9 +200);
    for (j = 0; j < 8; j++)
    { if ((((*__ctype_b_loc ())[(int) ((param->buf[j + i]))] & (unsigned short) _ISalnum) == 0) &&
   ((param->buf[j + i] != '%') || (j != 0)))
        break;
      dvar.key[j + 1] = param->buf[j + i];
    }
    dvar.key[j + 1] = '\0';
    dvar.slen = j + 2;
    j = j + i;
    while (((*__ctype_b_loc ())[(int) ((param->buf[j]))] & (unsigned short) _ISalnum)) j++;
    if ((param->buf[j] != ':') &&
        (param->buf[j] != '\0'))
   return -(9 +200);
    dvar.key[dvar.slen++] = 64;
    s = itocstring(&dvar.key[dvar.slen], off);
    dvar.key[dvar.slen - 1] |= s;
    dvar.slen += s;
    dvar.slen++;
  }
  if (param->buf[j++] == '\0')
    return ST_Kill(&dvar);
  partab.debug = -1;
  if (param->buf[j] == '\0')
  { ptr = (struct CSTRING *) src;
    ptr->len = 0;
    ptr->buf[0] = '\0';
    return ST_Set(&dvar, ptr);
  }
  if ((param->len - j) > 255)
    return -(9 +200);
  source_ptr = &param->buf[j];
  ptr = (struct CSTRING *) cmp;
  comp_ptr = ptr->buf;
  parse();
  *comp_ptr++ = 0;
  *comp_ptr++ = 0;
  ptr->len = (comp_ptr - ptr->buf);
  return ST_Set(&dvar, ptr);
}

variable_types: struct CSTRING { short len; unsigned char buf[32768]; } *

variable_types: j int

variable_types: off int


signalHandler

decompiled_code:
// attributes: thunk
__int64 signalHandler()
{
return setSignalBitMask();
}

canonical_decompiled_code:
__int64 func0()
{
return setSignalBitMask();
}

original_code:
void signalHandler (int sig)
{ setSignalBitMask ( sig );
}

canonical_original_code:
void signalHandler(int sig)
{ setSignalBitMask ( sig );
}

variable_types: sig int


setSignal

original_code:
int setSignal (int sig, int flag)
{ struct sigaction action;
  sigset_t handlermask;
  int ret;
  sigemptyset ( &handlermask );
  sigfillset ( &handlermask );
  action.sa_mask = handlermask;
  action.sa_flags = 0;
  if ( flag == 0 ) action.__sigaction_handler.sa_handler = signalHandler;
  else action.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
  ret = sigaction ( sig, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( ret );
}

canonical_original_code:
int setSignal(int sig, int flag)
{ struct sigaction action;
  struct __sigset_t handlermask;
  int ret;
  sigemptyset ( &handlermask );
  sigfillset ( &handlermask );
  action.sa_mask = handlermask;
  action.sa_flags = 0;
  if ( flag == 0 ) action.__sigaction_handler.sa_handler = signalHandler;
  else action.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
  ret = sigaction ( sig, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( ret );
}

variable_types: flag int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: ret int

return_type: int

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


setSignals

decompiled_code:
__int64 setSignals()
{
__m128i v0; // xmm0
__m128i v1; // xmm1
__m128i v2; // xmm2
__m128i v3; // xmm3
__m128i v4; // xmm4
__m128i v5; // xmm5
__m128i v6; // xmm6
__m128i v7; // xmm7
int v8; // er8
__int64 result; // rax
int *v10; // rax
sigset_t v11; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v12; // [rsp+80h] [rbp-A8h] BYREF

sigemptyset(&v11);
sigfillset(&v11);
v0 = _mm_loadu_si128((const __m128i *)&v11);
v1 = _mm_loadu_si128((const __m128i *)&v11.__val[2]);
v2 = _mm_loadu_si128((const __m128i *)&v11.__val[4]);
v3 = _mm_loadu_si128((const __m128i *)&v11.__val[6]);
v4 = _mm_loadu_si128((const __m128i *)&v11.__val[8]);
v5 = _mm_loadu_si128((const __m128i *)&v11.__val[10]);
v12.sa_flags = 0;
v6 = _mm_loadu_si128((const __m128i *)&v11.__val[12]);
v7 = _mm_loadu_si128((const __m128i *)&v11.__val[14]);
v12.sa_handler = (__sighandler_t)(signalHandler + 1);
*(__m128i *)v12.sa_mask.__val = v0;
*(__m128i *)&v12.sa_mask.__val[2] = v1;
*(__m128i *)&v12.sa_mask.__val[4] = v2;
*(__m128i *)&v12.sa_mask.__val[6] = v3;
*(__m128i *)&v12.sa_mask.__val[8] = v4;
*(__m128i *)&v12.sa_mask.__val[10] = v5;
*(__m128i *)&v12.sa_mask.__val[12] = v6;
*(__m128i *)&v12.sa_mask.__val[14] = v7;
if ( sigaction(1, &v12, 0LL) == -1 )
goto LABEL_26;
v12.sa_handler = (__sighandler_t)signalHandler;
if ( sigaction(2, &v12, 0LL) == -1 )
goto LABEL_26;
v12.sa_flags = 0x10000000;
if ( sigaction(3, &v12, 0LL) == -1 )
goto LABEL_26;
v12.sa_flags = 0;
v12.sa_handler = 0LL;
if ( sigaction(4, &v12, 0LL) == -1 )
goto LABEL_26;
v12.sa_handler = (__sighandler_t)signalHandler;
if ( sigaction(5, &v12, 0LL) == -1 )
goto LABEL_26;
if ( sigaction(6, &v12, 0LL) == -1 )
goto LABEL_26;
v12.sa_handler = 0LL;
if ( sigaction(8, &v12, 0LL) == -1 )
goto LABEL_26;
v12.sa_handler = 0LL;
if ( sigaction(7, &v12, 0LL) == -1 )
goto LABEL_26;
v12.sa_handler = 0LL;
if ( sigaction(11, &v12, 0LL) == -1
|| (v12.sa_handler = (__sighandler_t)signalHandler, sigaction(13, &v12, 0LL) == -1)
|| sigaction(14, &v12, 0LL) == -1
|| sigaction(15, &v12, 0LL) == -1
|| sigaction(23, &v12, 0LL) == -1
|| sigaction(20, &v12, 0LL) == -1
|| (v12.sa_handler = (__sighandler_t)(signalHandler + 1), sigaction(18, &v12, 0LL) == -1)
|| (v12.sa_handler = (__sighandler_t)signalHandler, sigaction(21, &v12, 0LL) == -1)
|| sigaction(22, &v12, 0LL) == -1
|| sigaction(29, &v12, 0LL) == -1
|| sigaction(24, &v12, 0LL) == -1
|| sigaction(25, &v12, 0LL) == -1
|| sigaction(26, &v12, 0LL) == -1
|| sigaction(27, &v12, 0LL) == -1
|| (v12.sa_handler = (__sighandler_t)(signalHandler + 1), sigaction(28, &v12, 0LL) == -1)
|| (v12.sa_handler = (__sighandler_t)signalHandler, sigaction(10, &v12, 0LL) == -1)
|| (v8 = sigaction(12, &v12, 0LL), result = 0LL, v8 == -1) )
{
LABEL_26:
v10 = _errno_location();
result = getError(0LL, (unsigned int)*v10);
}
return result;
}

original_code:
int setSignals (void)
{ struct sigaction action;
  sigset_t handlermask;
  int ret;
  sigemptyset ( &handlermask );
  sigfillset ( &handlermask );
  action.sa_mask = handlermask;
  action.sa_flags = 0;
  action.__sigaction_handler.sa_handler = signalHandler;
  action.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
  ret = sigaction ( 1, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  ret = sigaction ( 2, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.sa_flags = 0x10000000;
  ret = sigaction ( 3, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.sa_flags = 0;
  action.__sigaction_handler.sa_handler = ((__sighandler_t) 0);
  ret = sigaction ( 4, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  ret = sigaction ( 5, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 6, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = ((__sighandler_t) 0);
  ret = sigaction ( 8, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  action.__sigaction_handler.sa_handler = ((__sighandler_t) 0);
  ret = sigaction ( 7, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  action.__sigaction_handler.sa_handler = ((__sighandler_t) 0);
  ret = sigaction ( 11, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  ret = sigaction ( 13, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 14, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 15, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 23, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 20, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
  ret = sigaction ( 18, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  ret = sigaction ( 21, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 22, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 29, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 24, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 25, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 26, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 27, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
  ret = sigaction ( 28, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  ret = sigaction ( 10, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 12, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( 0 );
}

canonical_original_code:
int setSignals()
{ struct sigaction action;
  struct __sigset_t handlermask;
  int ret;
  sigemptyset ( &handlermask );
  sigfillset ( &handlermask );
  action.sa_mask = handlermask;
  action.sa_flags = 0;
  action.__sigaction_handler.sa_handler = signalHandler;
  action.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
  ret = sigaction ( 1, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  ret = sigaction ( 2, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.sa_flags = 0x10000000;
  ret = sigaction ( 3, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.sa_flags = 0;
  action.__sigaction_handler.sa_handler = ((void (*)(int)) 0);
  ret = sigaction ( 4, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  ret = sigaction ( 5, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 6, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = ((void (*)(int)) 0);
  ret = sigaction ( 8, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  action.__sigaction_handler.sa_handler = ((void (*)(int)) 0);
  ret = sigaction ( 7, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  action.__sigaction_handler.sa_handler = ((void (*)(int)) 0);
  ret = sigaction ( 11, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  ret = sigaction ( 13, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 14, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 15, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 23, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 20, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
  ret = sigaction ( 18, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  ret = sigaction ( 21, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 22, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 29, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 24, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 25, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 26, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 27, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
  ret = sigaction ( 28, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  action.__sigaction_handler.sa_handler = signalHandler;
  ret = sigaction ( 10, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  ret = sigaction ( 12, &action, ((void *)0) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( 0 );
}

variable_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


original_code:
int Routine_Hash(chr_q routine)
{ int hash = 0;
  int i;
  int p[8] = {3,5,7,11,13,17,19,23};
  for (i = 0; i < 8; i++)
  { hash = (((routine & 0xFF) * p[i]) + hash);
    routine = (routine >> 8);
  }
  return (hash % 1023);
}

canonical_original_code:
int Routine_Hash(unsigned long long routine)
{ int hash = 0;
  int i;
  int p[8] = {3,5,7,11,13,17,19,23};
  for (i = 0; i < 8; i++)
  { hash = (((routine & 0xFF) * p[i]) + hash);
    routine = (routine >> 8);
  }
  return (hash % 1023);
}

variable_types:
routine
unsigned long long

variable_types: hash int

variable_types: i int

variable_types:
p
int [8]


decompiled_code:
__int64 __fastcall SQ_Socket_Create(int a1)
{
int v1; // eax
unsigned int v2; // er12
unsigned int v4; // eax
int *v5; // rax

v1 = socket(2, 1, 0);
if ( v1 != -1 )
{
v2 = v1;
if ( !a1 )
return v2;
v4 = fcntl(v1, 3, 0LL);
if ( v4 != -1 )
{
BYTE1(v4) |= 8u;
if ( fcntl(v2, 4, v4) != -1 )
return v2;
}
close(v2);
}
v5 = _errno_location();
return getError(0LL, (unsigned int)*v5);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // eax
unsigned int v2; // er12
unsigned int v4; // eax
int *v5; // rax

v1 = socket(2, 1, 0);
if ( v1 != -1 )
{
v2 = v1;
if ( !a1 )
return v2;
v4 = fcntl(v1, 3, 0LL);
if ( v4 != -1 )
{
BYTE1(v4) |= 8u;
if ( fcntl(v2, 4, v4) != -1 )
return v2;
}
close(v2);
}
v5 = _errno_location();
return getError(0LL, (unsigned int)*v5);
}

original_code:
int SQ_Socket_Create (int nonblock)
{ int sid;
  int flag;
  int ret;
  sid = socket ( 2, SOCK_STREAM, 0 );
  if ( sid == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  if (nonblock)
  { flag = fcntl ( sid, 3, 0 );
    if ( flag == -1 )
    { (void) close ( sid );
      return ( getError ( 0, (*__errno_location ()) ) );
    }
    flag |= 04000;
    ret = fcntl ( sid, 4, flag );
    if ( ret == -1 )
    { (void) close ( sid );
      return ( getError ( 0, (*__errno_location ()) ) );
    }
  }
  return ( sid );
}

canonical_original_code:
int SQ_Socket_Create(int nonblock)
{ int sid;
  int flag;
  int ret;
  sid = socket ( 2, SOCK_STREAM, 0 );
  if ( sid == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  if (nonblock)
  { flag = fcntl ( sid, 3, 0 );
    if ( flag == -1 )
    { (void) close ( sid );
      return ( getError ( 0, (*__errno_location ()) ) );
    }
    flag |= 04000;
    ret = fcntl ( sid, 4, flag );
    if ( ret == -1 )
    { (void) close ( sid );
      return ( getError ( 0, (*__errno_location ()) ) );
    }
  }
  return ( sid );
}

variable_types: nonblock int

variable_types: sid int


decompiled_code:
__int64 __fastcall SQ_Socket_Bind(__int64 a1, __int16 a2)
{
__int16 v2; // ax
socklen_t v3; // edx
int v4; // er8
int v5; // er8
__int64 result; // rax
int *v7; // rax
struct sockaddr v8; // [rsp+0h] [rbp-18h] BYREF

v8.sa_family = 2;
v2 = _bswap_16(a2);
*(_DWORD *)&v8.sa_data[2] = 0;
*(_WORD *)v8.sa_data = v2;
v5 = bind(v4, &v8, v3);
result = 0LL;
if ( v5 == -1 )
{
v7 = _errno_location();
result = getError(0LL, (unsigned int)*v7);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int16 a2)
{
__int16 v2; // ax
socklen_t v3; // edx
int v4; // er8
int v5; // er8
__int64 result; // rax
int *v7; // rax
struct sockaddr v8; // [rsp+0h] [rbp-18h] BYREF

v8.sa_family = 2;
v2 = func0(a2);
*(_DWORD *)&v8.sa_data[2] = 0;
*(_WORD *)v8.sa_data = v2;
v5 = bind(v4, &v8, v3);
result = 0LL;
if ( v5 == -1 )
{
v7 = _errno_location();
result = getError(0LL, (unsigned int)*v7);
}
return result;
}

original_code:
int SQ_Socket_Bind (int sid, u_short port)
{ int ret;
  struct sockaddr_in sin;
  sin.sin_family = 2;
  sin.sin_port = htons ( port );
  sin.sin_addr.s_addr = ((in_addr_t) 0x00000000);
  ret = bind ( sid, ( struct sockaddr * ) &sin, sizeof ( sin ) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( 0 );
}

canonical_original_code:
int SQ_Socket_Bind(int sid, unsigned short port)
{ int ret;
  struct sockaddr_in sin;
  sin.sin_family = 2;
  sin.sin_port = htons ( port );
  sin.sin_addr.s_addr = ((unsigned int) 0x00000000);
  ret = bind ( sid, ( struct sockaddr * ) &sin, sizeof ( sin ) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( 0 );
}

variable_types:
port
unsigned short

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

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

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall SQ_Socket_Listen(int a1)
{
int *v2; // rax

if ( listen(a1, 3) != -1 )
return 0LL;
v2 = _errno_location();
return getError(0LL, (unsigned int)*v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int *v2; // rax

if ( listen(a1, 3) != -1 )
return 0LL;
v2 = _errno_location();
return getError(0LL, (unsigned int)*v2);
}

original_code:
int SQ_Socket_Listen (int sid)
{ int ret;
  ret = listen ( sid, 3 );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( 0 );
}

canonical_original_code:
int SQ_Socket_Listen(int sid)
{ int ret;
  ret = listen ( sid, 3 );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( 0 );
}


decompiled_code:
int __fastcall SQ_Socket_Accept(__int64 fd, unsigned int a2)
{
int result; // eax
int *v3; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

result = seqioSelect(fd, 0LL, a2);
if ( result >= 0 )
{
addr_len = 16;
result = accept(fd, &addr, &addr_len);
if ( result == -1 )
{
v3 = _errno_location();
result = getError(0LL, (unsigned int)*v3);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 fd, unsigned int a2)
{
int result; // eax
int *v3; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

result = seqioSelect(fd, 0LL, a2);
if ( result >= 0 )
{
addr_len = 16;
result = accept(fd, &addr, &addr_len);
if ( result == -1 )
{
v3 = _errno_location();
result = getError(0LL, (unsigned int)*v3);
}
}
return result;
}

original_code:
int SQ_Socket_Accept (int sid, int tout)
{ int ret;
  int len;
  struct sockaddr_in addr;
  ret = seqioSelect ( sid, 0, tout );
  if ( ret < 0 ) return ( ret );
  len = sizeof ( struct sockaddr_in );
  ret = accept ( sid, ( struct sockaddr * ) &addr, (socklen_t *)&len );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( ret );
}

canonical_original_code:
int SQ_Socket_Accept(int sid, int tout)
{ int ret;
  int len;
  struct sockaddr_in addr;
  ret = seqioSelect ( sid, 0, tout );
  if ( ret < 0 ) return ( ret );
  len = sizeof ( struct sockaddr_in );
  ret = accept ( sid, ( struct sockaddr * ) &addr, (unsigned int *)&len );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( ret );
}

variable_types: tout int

variable_types: len int


decompiled_code:
__int64 __fastcall SQ_Socket_Connect(int fd, __int64 a2, __int16 a3)
{
const char *v3; // r8
__int64 result; // rax
__int64 v5; // rsi
struct in_addr inp; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a3);
if ( !inet_aton(v3, &inp) )
return getError(1LL, 48LL);
*(struct in_addr *)&addr.sa_data[2] = inp;
if ( connect(fd, &addr, 0x10u) != -1 )
return (unsigned int)fd;
v5 = (unsigned int)*_errno_location();
if ( (_DWORD)v5 != 115 )
return getError(0LL, v5);
result = seqioSelect((unsigned int)fd, 1LL, 0xFFFFFFFFLL);
if ( (int)result >= 0 )
return (unsigned int)fd;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, __int64 a2, __int16 a3)
{
const char *v3; // r8
__int64 result; // rax
__int64 v5; // rsi
struct in_addr inp; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(a3);
if ( !inet_aton(v3, &inp) )
return getError(1LL, 48LL);
*(struct in_addr *)&addr.sa_data[2] = inp;
if ( connect(fd, &addr, 0x10u) != -1 )
return (unsigned int)fd;
v5 = (unsigned int)*_errno_location();
if ( (_DWORD)v5 != 115 )
return getError(0LL, v5);
result = seqioSelect((unsigned int)fd, 1LL, 0xFFFFFFFFLL);
if ( (int)result >= 0 )
return (unsigned int)fd;
return result;
}

original_code:
int SQ_Socket_Connect (int sid, char *addr, u_short port)
{ int ret;
  struct in_addr inaddr;
  struct sockaddr_in sin;
  sin.sin_family = 2;
  sin.sin_port = htons ( port );
  ret = inet_aton ( addr, &inaddr );
  if ( ret == 0 ) return ( getError ( 1, 48 ) );
  sin.sin_addr.s_addr = inaddr.s_addr;
  ret = connect ( sid, ( struct sockaddr * ) &sin, sizeof ( sin ) );
  if ( ret == -1 )
  { if ( (*__errno_location ()) == 115 )
    { ret = seqioSelect ( sid, 1, -1 );
      if ( ret < 0 ) return ( ret );
      return ( sid );
    }
    return ( getError ( 0, (*__errno_location ()) ) );
  }
  return ( sid );
}

canonical_original_code:
int SQ_Socket_Connect(int sid, char *addr, unsigned short port)
{ int ret;
  struct in_addr inaddr;
  struct sockaddr_in sin;
  sin.sin_family = 2;
  sin.sin_port = htons ( port );
  ret = inet_aton ( addr, &inaddr );
  if ( ret == 0 ) return ( getError ( 1, 48 ) );
  sin.sin_addr.s_addr = inaddr.s_addr;
  ret = connect ( sid, ( struct sockaddr * ) &sin, sizeof ( sin ) );
  if ( ret == -1 )
  { if ( (*__errno_location ()) == 115 )
    { ret = seqioSelect ( sid, 1, -1 );
      if ( ret < 0 ) return ( ret );
      return ( sid );
    }
    return ( getError ( 0, (*__errno_location ()) ) );
  }
  return ( sid );
}

variable_types:
addr
char *

variable_types:
inaddr
struct in_addr { unsigned int s_addr; }


decompiled_code:
__int64 __fastcall SQ_Socket_Write(int a1, const void *a2, int a3)
{
unsigned int v3; // eax
__int64 v4; // rsi
unsigned int v5; // er8

v3 = send(a1, a2, a3, 0);
if ( v3 != -1 )
return v3;
v4 = (unsigned int)*_errno_location();
if ( (_DWORD)v4 != 32 )
{
v5 = 0;
if ( (_DWORD)v4 != 11 )
return getError(0LL, v4);
return v5;
}
return getError(1LL, 46LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, const void *a2, int a3)
{
unsigned int v3; // eax
__int64 v4; // rsi
unsigned int v5; // er8

v3 = send(a1, a2, a3, 0);
if ( v3 != -1 )
return v3;
v4 = (unsigned int)*_errno_location();
if ( (_DWORD)v4 != 32 )
{
v5 = 0;
if ( (_DWORD)v4 != 11 )
return getError(0LL, v4);
return v5;
}
return getError(1LL, 46LL);
}

original_code:
int SQ_Socket_Write (int sid, u_char *writebuf, int nbytes)
{ int ret;
  ret = send ( sid, writebuf, nbytes, 0 );
  if ( ret == -1 )
  { if ( (*__errno_location ()) == 32 ) return ( getError ( 1, 46 ) );
    else if ( (*__errno_location ()) == 11 ) return ( 0 );
    else return ( getError ( 0, (*__errno_location ()) ) );
  }
  else return ( ret );
}

canonical_original_code:
int SQ_Socket_Write(int sid, unsigned char *writebuf, int nbytes)
{ int ret;
  ret = send ( sid, writebuf, nbytes, 0 );
  if ( ret == -1 )
  { if ( (*__errno_location ()) == 32 ) return ( getError ( 1, 46 ) );
    else if ( (*__errno_location ()) == 11 ) return ( 0 );
    else return ( getError ( 0, (*__errno_location ()) ) );
  }
  else return ( ret );
}

variable_types:
writebuf
unsigned char *

variable_types: nbytes int


decompiled_code:
__int64 __fastcall SQ_Socket_Read(__int64 fd, void *buf, __int64 a3)
{
int v3; // er8
int *v5; // rax
__int64 v6; // rsi
int *v7; // rbp

if ( (_DWORD)a3 )
{
v3 = seqioSelect(fd, 0LL, a3);
if ( v3 < 0 )
return (unsigned int)v3;
}
v3 = recv(fd, buf, 1uLL, 0);
if ( v3 != -1 )
return (unsigned int)v3;
v5 = _errno_location();
v6 = (unsigned int)*v5;
v7 = v5;
if ( (_DWORD)v6 == 11 )
{
raise(14);
v6 = (unsigned int)*v7;
}
return getError(0LL, v6);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 fd, void *buf, __int64 a3)
{
int v3; // er8
int *v5; // rax
__int64 v6; // rsi
int *v7; // rbp

if ( (_DWORD)a3 )
{
v3 = seqioSelect(fd, 0LL, a3);
if ( v3 < 0 )
return (unsigned int)v3;
}
v3 = recv(fd, buf, 1uLL, 0);
if ( v3 != -1 )
return (unsigned int)v3;
v5 = _errno_location();
v6 = (unsigned int)*v5;
v7 = v5;
if ( (_DWORD)v6 == 11 )
{
raise(14);
v6 = (unsigned int)*v7;
}
return getError(0LL, v6);
}

original_code:
int SQ_Socket_Read (int sid, u_char *readbuf, int tout)
{ int ret;
  if ( tout != 0 )
  { ret = seqioSelect ( sid, 0, tout );
    if ( ret < 0 ) return ( ret );
  }
  ret = recv ( sid, readbuf, 1, 0 );
  if ( ret == -1 )
  { if ( (*__errno_location ()) == 11 )
    { ret = raise ( 14 );
      if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
    }
    return ( getError ( 0, (*__errno_location ()) ) );
  }
  else if ( ret == 0 )
    return ( ret );
  else
    return ( ret );
}

canonical_original_code:
int SQ_Socket_Read(int sid, unsigned char *readbuf, int tout)
{ int ret;
  if ( tout != 0 )
  { ret = seqioSelect ( sid, 0, tout );
    if ( ret < 0 ) return ( ret );
  }
  ret = recv ( sid, readbuf, 1, 0 );
  if ( ret == -1 )
  { if ( (*__errno_location ()) == 11 )
    { ret = raise ( 14 );
      if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
    }
    return ( getError ( 0, (*__errno_location ()) ) );
  }
  else if ( ret == 0 )
    return ( ret );
  else
    return ( ret );
}

variable_types:
readbuf
unsigned char *


decompiled_code:
__int64 __fastcall SQ_Device_Open(const char *a1, int a2)
{
__int64 result; // rax
int v3; // eax
unsigned int v4; // er12

if ( a2 == 2 )
{
v3 = open(a1, 0, 0LL);
}
else
{
if ( a2 == 4 )
{
a2 = 2;
}
else if ( a2 != 1 )
{
return getError((char *)SQ_Device_Open + 1);
}
v3 = open(a1, a2, 0LL);
}
v4 = v3;
if ( v3 != -1 || *_errno_location() == 16 )
result = v4;
else
result = getError(0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, int a2)
{
__int64 result; // rax
int v3; // eax
unsigned int v4; // er12

if ( a2 == 2 )
{
v3 = open(a1, 0, 0LL);
}
else
{
if ( a2 == 4 )
{
a2 = 2;
}
else if ( a2 != 1 )
{
return getError((char *)SQ_Device_Open + 1);
}
v3 = open(a1, a2, 0LL);
}
v4 = v3;
if ( v3 != -1 || *_errno_location() == 16 )
result = v4;
else
result = getError(0LL);
return result;
}

original_code:
int SQ_Device_Open (char *device, int op)
{ int flag;
 int did;
  switch ( op )
  {
    case 1:
      flag = 01;
      break;
    case 2:
      flag = 00;
      break;
    case 4:
      flag = 02;
      break;
    default:
      return ( getError ( 1, 21 ) );
  }
  while ( 1 )
  { did = open ( device, flag, 0 );
    if ( did == -1 )
    { if ( (*__errno_location ()) != 16 )
      { return ( getError ( 0, (*__errno_location ()) ) );
      }
      else if (partab.jobtab->trap | 16384)
      { return (-1);
      }
    }
    else
    { return ( did );
    }
  }
  return ( getError ( 1, 20 ) );
}

canonical_original_code:
int SQ_Device_Open(char *device, int op)
{ int flag;
 int did;
  switch ( op )
  {
    case 1:
      flag = 01;
      break;
    case 2:
      flag = 00;
      break;
    case 4:
      flag = 02;
      break;
    default:
      return ( getError ( 1, 21 ) );
  }
  while ( 1 )
  { did = open ( device, flag, 0 );
    if ( did == -1 )
    { if ( (*__errno_location ()) != 16 )
      { return ( getError ( 0, (*__errno_location ()) ) );
      }
      else if (partab.jobtab->trap | 16384)
      { return (-1);
      }
    }
    else
    { return ( did );
    }
  }
  return ( getError ( 1, 20 ) );
}

variable_types:
device
char *

variable_types: op int

variable_types: flag int

variable_types: did int


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

result = write(a1, a2, a3);
if ( (_DWORD)result == -1 )
{
_errno_location();
result = getError(0LL);
}
return result;
}

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

result = write(a1, a2, a3);
if ( (_DWORD)result == -1 )
{
_errno_location();
result = getError(0LL);
}
return result;
}

original_code:
int SQ_Device_Write (int did, u_char *writebuf, int nbytes)
{ int ret;
  ret = write ( did, writebuf, nbytes );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( ret );
}

canonical_original_code:
int SQ_Device_Write(int did, unsigned char *writebuf, int nbytes)
{ int ret;
  ret = write ( did, writebuf, nbytes );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( ret );
}

variable_types: ret int


decompiled_code:
ssize_t __fastcall SQ_Device_Read_TTY(int fd, void *buf, int a3)
{
unsigned int v3; // er12
ssize_t result; // rax
struct termios v5; // [rsp+0h] [rbp-58h] BYREF

if ( a3 )
{
result = read(fd, buf, 1uLL);
}
else
{
if ( tcgetattr(fd, &v5) == -1
|| (v5.c_cc[6] = 0, tcsetattr(fd, 0, &v5) == -1)
|| (v3 = read(fd, buf, 1uLL), tcgetattr(fd, &v5) == -1)
|| (v5.c_cc[6] = 1, tcsetattr(fd, 0, &v5) == -1) )
{
_errno_location();
return getError(0LL);
}
result = v3;
if ( !v3 )
{
*(_DWORD *)(partab + 24LL) |= 0x4000u;
return 0xFFFFFFFFLL;
}
}
if ( (_DWORD)result == -1 )
{
if ( *_errno_location() == 11 )
raise(14);
result = getError(0LL);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(int fd, void *buf, int a3)
{
unsigned int v3; // er12
ssize_t result; // rax
struct termios v5; // [rsp+0h] [rbp-58h] BYREF

if ( a3 )
{
result = read(fd, buf, 1uLL);
}
else
{
if ( tcgetattr(fd, &v5) == -1
|| (v5.c_cc[6] = 0, tcsetattr(fd, 0, &v5) == -1)
|| (v3 = read(fd, buf, 1uLL), tcgetattr(fd, &v5) == -1)
|| (v5.c_cc[6] = 1, tcsetattr(fd, 0, &v5) == -1) )
{
_errno_location();
return getError(0LL);
}
result = v3;
if ( !v3 )
{
*(_DWORD *)(partab + 24LL) |= 0x4000u;
return 0xFFFFFFFFLL;
}
}
if ( (_DWORD)result == -1 )
{
if ( *_errno_location() == 11 )
raise(14);
result = getError(0LL);
}
return result;
}

original_code:
int SQ_Device_Read_TTY (int did, u_char *readbuf, int tout)
{ struct termios settings;
  int ret;
  int rret;
  if ( tout == 0 )
  { ret = tcgetattr ( did, &settings );
    if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
    settings.c_cc[6] = 0;
    ret = tcsetattr ( did, 0, &settings );
    if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  }
  rret = read ( did, readbuf, 1 );
  if ( tout == 0 )
  { ret = tcgetattr ( did, &settings );
    if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
    settings.c_cc[6] = 1;
    ret = tcsetattr ( did, 0, &settings );
    if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
    if (rret == 0)
    { partab.jobtab->trap |= 16384;
      return (-1);
    }
  }
  if ( rret == -1 )
  { if ( (*__errno_location ()) == 11 )
    { ret = raise ( 14 );
      if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
    }
    return ( getError ( 0, (*__errno_location ()) ) );
  }
  else
  { return ( rret );
  }
}

canonical_original_code:
int SQ_Device_Read_TTY(int did, unsigned char *readbuf, int tout)
{ struct termios settings;
  int ret;
  int rret;
  if ( tout == 0 )
  { ret = tcgetattr ( did, &settings );
    if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
    settings.c_cc[6] = 0;
    ret = tcsetattr ( did, 0, &settings );
    if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  }
  rret = read ( did, readbuf, 1 );
  if ( tout == 0 )
  { ret = tcgetattr ( did, &settings );
    if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
    settings.c_cc[6] = 1;
    ret = tcsetattr ( did, 0, &settings );
    if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
    if (rret == 0)
    { partab.jobtab->trap |= 16384;
      return (-1);
    }
  }
  if ( rret == -1 )
  { if ( (*__errno_location ()) == 11 )
    { ret = raise ( 14 );
      if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
    }
    return ( getError ( 0, (*__errno_location ()) ) );
  }
  else
  { return ( rret );
  }
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types: rret int


decompiled_code:
ssize_t __fastcall SQ_Device_Read(int fd, void *buf, int a3)
{
ssize_t result; // rax

if ( isatty(fd) == 1 )
result = SQ_Device_Read_TTY(fd, buf, a3);
else
result = getError(1LL);
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(int fd, void *buf, int a3)
{
ssize_t result; // rax

if ( isatty(fd) == 1 )
result = func2(fd, buf, a3);
else
result = getError(1LL);
return result;
}

original_code:
int SQ_Device_Read (int did, u_char *readbuf, int tout)
{ int ret;
  ret = isatty ( did );
  if ( ret == 1 ) return ( SQ_Device_Read_TTY ( did, readbuf, tout ) );
  else return ( getError ( 1, 24 ) );
}

canonical_original_code:
int SQ_Device_Read(int did, unsigned char *readbuf, int tout)
{ int ret;
  ret = isatty ( did );
  if ( ret == 1 ) return ( SQ_Device_Read_TTY ( did, readbuf, tout ) );
  else return ( getError ( 1, 24 ) );
}


decompiled_code:
// attributes: thunk
__int64 SQ_Tcpip_Accept()
{
return SQ_Socket_Accept();
}

canonical_decompiled_code:
__int64 func0()
{
return SQ_Socket_Accept();
}

original_code:
int SQ_Tcpip_Accept (int sid, int tout)
{ return ( SQ_Socket_Accept ( sid, tout ) );
}

canonical_original_code:
int SQ_Tcpip_Accept(int sid, int tout)
{ return ( SQ_Socket_Accept ( sid, tout ) );
}

variable_types: sid int


decompiled_code:
// attributes: thunk
__int64 SQ_Tcpip_Write()
{
return SQ_Socket_Write();
}

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

original_code:
int SQ_Tcpip_Write (int sid, u_char *writebuf, int nbytes)
{ return ( SQ_Socket_Write ( sid, writebuf, nbytes ) );
}

canonical_original_code:
int SQ_Tcpip_Write(int sid, unsigned char *writebuf, int nbytes)
{ return ( SQ_Socket_Write ( sid, writebuf, nbytes ) );
}


decompiled_code:
// attributes: thunk
__int64 SQ_Tcpip_Read()
{
return SQ_Socket_Read();
}

canonical_decompiled_code:
__int64 func2()
{
return SQ_Socket_Read();
}

original_code:
int SQ_Tcpip_Read (int sid, u_char *readbuf, int tout)
{ return ( SQ_Socket_Read ( sid, readbuf, tout ) );
}

canonical_original_code:
int SQ_Tcpip_Read(int sid, unsigned char *readbuf, int tout)
{ return ( SQ_Socket_Read ( sid, readbuf, tout ) );
}


decompiled_code:
__int64 __fastcall SQ_Tcpip_Open_Server(char *nptr)
{
unsigned int v1; // er12
unsigned __int16 v2; // ax
int v3; // edi
int v4; // ebp

v1 = SQ_Socket_Create(1LL);
if ( (v1 & 0x80000000) != 0 )
return v1;
v2 = atoi(nptr);
v3 = v1;
v4 = SQ_Socket_Bind(v1, v2);
if ( v4 >= 0 )
{
v4 = SQ_Socket_Listen(v1);
if ( v4 >= 0 )
return v1;
v3 = v1;
}
close(v3);
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *nptr)
{
unsigned int v1; // er12
unsigned __int16 v2; // ax
int v3; // edi
int v4; // ebp

v1 = SQ_Socket_Create(1LL);
if ( (v1 & 0x80000000) != 0 )
return v1;
v2 = atoi(nptr);
v3 = v1;
v4 = SQ_Socket_Bind(v1, v2);
if ( v4 >= 0 )
{
v4 = SQ_Socket_Listen(v1);
if ( v4 >= 0 )
return v1;
v3 = v1;
}
close(v3);
return (unsigned int)v4;
}

original_code:
int SQ_Tcpip_Open_Server (char *bind)
{ int sid;
  int ret;
  u_short port;
  sid = SQ_Socket_Create (1);
  if ( sid < 0 ) return ( sid );
  port = atoi ( bind );
  ret = SQ_Socket_Bind ( sid, port );
  if ( ret < 0 )
  { ( void ) close ( sid );
    return ( ret );
  }
  ret = SQ_Socket_Listen ( sid );
  if ( ret < 0 )
  { ( void ) close ( sid );
    return ( ret );
  }
  return ( sid );
}

canonical_original_code:
int SQ_Tcpip_Open_Server(char *bind)
{ int sid;
  int ret;
  unsigned short port;
  sid = SQ_Socket_Create (1);
  if ( sid < 0 ) return ( sid );
  port = atoi ( bind );
  ret = SQ_Socket_Bind ( sid, port );
  if ( ret < 0 )
  { ( void ) close ( sid );
    return ( ret );
  }
  ret = SQ_Socket_Listen ( sid );
  if ( ret < 0 )
  { ( void ) close ( sid );
    return ( ret );
  }
  return ( sid );
}

variable_types:
bind
char *

variable_types:
port
unsigned short


decompiled_code:
__int64 __fastcall SQ_Tcpip_Open_Client(char *src)
{
unsigned int v1; // er12
char *v2; // rax
unsigned __int16 v3; // ax
int v4; // eax
int v6; // edi
char v7[136]; // [rsp+0h] [rbp-88h] BYREF

strcpy(v7, src);
v1 = SQ_Socket_Create(0LL);
if ( (v1 & 0x80000000) != 0 )
return v1;
v2 = strchr(v7, 32);
if ( v2 )
{
*v2 = 0;
v3 = atoi(v2 + 1);
v4 = SQ_Socket_Connect(v1, v7, v3);
if ( v4 < 0 )
{
v6 = v1;
v1 = v4;
close(v6);
}
return v1;
}
close(v1);
return (unsigned int)getError(1LL, 28LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src)
{
unsigned int v1; // er12
char *v2; // rax
unsigned __int16 v3; // ax
int v4; // eax
int v6; // edi
char v7[136]; // [rsp+0h] [rbp-88h] BYREF

strcpy(v7, src);
v1 = SQ_Socket_Create(0LL);
if ( (v1 & 0x80000000) != 0 )
return v1;
v2 = strchr(v7, 32);
if ( v2 )
{
*v2 = 0;
v3 = atoi(v2 + 1);
v4 = SQ_Socket_Connect(v1, v7, v3);
if ( v4 < 0 )
{
v6 = v1;
v1 = v4;
close(v6);
}
return v1;
}
close(v1);
return (unsigned int)getError(1LL, 28LL);
}

original_code:
int SQ_Tcpip_Open_Client (char *conn)
{ int sid;
  char *portptr;
  char *addrptr;
  u_short port;
  int ret;
  char xxxx[100];
  strcpy( xxxx, conn);
  sid = SQ_Socket_Create (0);
  if ( sid < 0 ) return ( sid );
  portptr = strpbrk ( xxxx, " " );
  if ( portptr == ((void *)0) )
  { ( void ) close ( sid );
    return ( getError ( 1, 28 ) );
  }
  *portptr = '\0';
  addrptr = xxxx;
  portptr++;
  port = atoi ( portptr );
  ret = SQ_Socket_Connect ( sid, addrptr, port );
  if ( ret < 0 )
  { ( void ) close ( sid );
    return ( ret );
  }
  return ( sid );
}

canonical_original_code:
int SQ_Tcpip_Open_Client(char *conn)
{ int sid;
  char *portptr;
  char *addrptr;
  unsigned short port;
  int ret;
  char xxxx[100];
  strcpy( xxxx, conn);
  sid = SQ_Socket_Create (0);
  if ( sid < 0 ) return ( sid );
  portptr = strpbrk ( xxxx, " " );
  if ( portptr == ((void *)0) )
  { ( void ) close ( sid );
    return ( getError ( 1, 28 ) );
  }
  *portptr = '\0';
  addrptr = xxxx;
  portptr++;
  port = atoi ( portptr );
  ret = SQ_Socket_Connect ( sid, addrptr, port );
  if ( ret < 0 )
  { ( void ) close ( sid );
    return ( ret );
  }
  return ( sid );
}

variable_types:
conn
char *

variable_types:
portptr
char *

variable_types:
addrptr
char *

variable_types:
xxxx
char [100]


decompiled_code:
__int64 __fastcall SQ_Tcpip_Open(char *a1, int a2)
{
if ( a2 == 5 )
return SQ_Tcpip_Open_Client(a1);
if ( a2 == 6 )
return SQ_Tcpip_Open_Server(a1);
return getError(1LL, 21LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, int a2)
{
if ( a2 == 5 )
return func4(a1);
if ( a2 == 6 )
return func3(a1);
return getError(1LL, 21LL);
}

original_code:
int SQ_Tcpip_Open (char *bind, int op)
{ switch ( op )
  { case 6:
      return ( SQ_Tcpip_Open_Server ( bind ) );
    case 5:
      return ( SQ_Tcpip_Open_Client ( bind ) );
    default:
      return ( getError ( 1, 21 ) );
  }
}

canonical_original_code:
int SQ_Tcpip_Open(char *bind, int op)
{ switch ( op )
  { case 6:
      return ( SQ_Tcpip_Open_Server ( bind ) );
    case 5:
      return ( SQ_Tcpip_Open_Client ( bind ) );
    default:
      return ( getError ( 1, 21 ) );
  }
}


comperror

decompiled_code:
__int64 __fastcall comperror(__int16 a1)
{
_BYTE *v1; // rax
__int64 v2; // rax
_BYTE *v3; // rax
__int64 result; // rax
int v5; // edx
_QWORD *v6; // rax
__int64 v7; // r12
__int64 v8; // rbp
int v9; // ebp
__int16 v10; // ax
__int16 v11; // ax
__int16 v12; // [rsp+0h] [rbp-98h] BYREF
__int16 v13; // [rsp+2h] [rbp-96h] BYREF
char v14[148]; // [rsp+4h] [rbp-94h] BYREF

v1 = (_BYTE *)comp_ptr++;
*v1 = 2;
*(_WORD *)comp_ptr = a1;
v2 = comp_ptr;
comp_ptr += 3LL;
*(_BYTE *)(v2 + 2) = -77;
v3 = (_BYTE *)comp_ptr++;
*v3 = -77;
result = *((unsigned int *)&partab + 11);
if ( (_DWORD)result )
{
v5 = **((_DWORD **)&partab + 8);
if ( (_DWORD)result == v5 )
return result;
v6 = (_QWORD *)*((_QWORD *)&partab + 7);
*((_DWORD *)&partab + 11) = v5;
v7 = *v6;
v8 = **((_QWORD **)&partab + 6);
if ( (SQ_Write(*v6) & 0x8000u) == 0LL && (SQ_WriteFormat(0xFFFFFFFFLL) & 0x8000u) == 0LL )
{
v9 = v8 - (v7 + 2);
if ( v9 - 1 <= 0 || (SQ_WriteFormat((unsigned int)(v9 - 1)) & 0x8000u) == 0LL )
{
v13 = 8286;
v10 = UTIL_strerror((unsigned int)a1, v14);
if ( v10 >= 0 )
{
v12 = v10 + 2;
qmemcpy((char *)&v13 + (__int16)(v10 + 2), " - At line ", 11);
v11 = itocstring(&v14[(__int16)(v10 + 2) + 9], **((unsigned int **)&partab + 8));
if ( v11 >= 0 )
{
v12 += v11 + 11;
if ( (SQ_Write(&v12) & 0x8000u) == 0LL )
SQ_WriteFormat(0xFFFFFFFFLL);
}
}
}
}
}
result = source_ptr;
if ( *(_BYTE *)source_ptr )
{
result = source_ptr + 1;
do
source_ptr = result++;
while ( *(_BYTE *)(result - 1) );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 a1)
{
_BYTE *v1; // rax
__int64 v2; // rax
_BYTE *v3; // rax
__int64 result; // rax
int v5; // edx
_QWORD *v6; // rax
__int64 v7; // r12
__int64 v8; // rbp
int v9; // ebp
__int16 v10; // ax
__int16 v11; // ax
__int16 v12; // [rsp+0h] [rbp-98h] BYREF
__int16 v13; // [rsp+2h] [rbp-96h] BYREF
char v14[148]; // [rsp+4h] [rbp-94h] BYREF

v1 = (_BYTE *)comp_ptr++;
*v1 = 2;
*(_WORD *)comp_ptr = a1;
v2 = comp_ptr;
comp_ptr += 3LL;
*(_BYTE *)(v2 + 2) = -77;
v3 = (_BYTE *)comp_ptr++;
*v3 = -77;
result = *((unsigned int *)&partab + 11);
if ( (_DWORD)result )
{
v5 = **((_DWORD **)&partab + 8);
if ( (_DWORD)result == v5 )
return result;
v6 = (_QWORD *)*((_QWORD *)&partab + 7);
*((_DWORD *)&partab + 11) = v5;
v7 = *v6;
v8 = **((_QWORD **)&partab + 6);
if ( (SQ_Write(*v6) & 0x8000u) == 0LL && (SQ_WriteFormat(0xFFFFFFFFLL) & 0x8000u) == 0LL )
{
v9 = v8 - (v7 + 2);
if ( v9 - 1 <= 0 || (SQ_WriteFormat((unsigned int)(v9 - 1)) & 0x8000u) == 0LL )
{
v13 = 8286;
v10 = UTIL_strerror((unsigned int)a1, v14);
if ( v10 >= 0 )
{
v12 = v10 + 2;
qmemcpy((char *)&v13 + (__int16)(v10 + 2), " - At line ", 11);
v11 = itocstring(&v14[(__int16)(v10 + 2) + 9], **((unsigned int **)&partab + 8));
if ( v11 >= 0 )
{
v12 += v11 + 11;
if ( (SQ_Write(&v12) & 0x8000u) == 0LL )
SQ_WriteFormat(0xFFFFFFFFLL);
}
}
}
}
}
result = source_ptr;
if ( *(_BYTE *)source_ptr )
{
result = source_ptr + 1;
do
source_ptr = result++;
while ( *(_BYTE *)(result - 1) );
}
return result;
}

original_code:
void comperror(short err)
{ short s;
  cstring *line;
  u_char *src;
  int i;
  u_char tmp[128];
  *comp_ptr++ = 2;
  bcopy(&err, comp_ptr, 2);
  comp_ptr += 2;
  *comp_ptr++ = 179;
  *comp_ptr++ = 179;
  if (!partab.checkonly) goto scan;
  if (partab.checkonly == *partab.ln) return;
  partab.checkonly = *partab.ln;
  line = *partab.lp;
  src = *partab.sp;
  s = SQ_Write(line);
  if (s < 0) goto scan;
  s = SQ_WriteFormat(-1);
  if (s < 0) goto scan;
  i = (src - line->buf) - 1;
  if (i > 0)
  { s = SQ_WriteFormat(i);
    if (s < 0) goto scan;
  }
  line = (cstring *) tmp;
  line->buf[0] = '^';
  line->buf[1] = ' ';
  s = UTIL_strerror(err, &line->buf[2]);
  if (s < 0) goto scan;
  line->len = s + 2;
  bcopy(" - At line ", &line->buf[line->len], 11);
  s = itocstring(&line->buf[line->len + 11], *partab.ln);
  if (s < 0) goto scan;
  line->len = line->len + s + 11;
  s = SQ_Write(line);
  if (s >= 0)
    s = SQ_WriteFormat(-1);
scan:
  while (*source_ptr) source_ptr++;
  return;
}

canonical_original_code:
void comperror(short err)
{ short s;
  struct CSTRING *line;
  unsigned char *src;
  int i;
  unsigned char tmp[128];
  *comp_ptr++ = 2;
  bcopy(&err, comp_ptr, 2);
  comp_ptr += 2;
  *comp_ptr++ = 179;
  *comp_ptr++ = 179;
  if (!partab.checkonly) goto scan;
  if (partab.checkonly == *partab.ln) return;
  partab.checkonly = *partab.ln;
  line = *partab.lp;
  src = *partab.sp;
  s = SQ_Write(line);
  if (s < 0) goto scan;
  s = SQ_WriteFormat(-1);
  if (s < 0) goto scan;
  i = (src - line->buf) - 1;
  if (i > 0)
  { s = SQ_WriteFormat(i);
    if (s < 0) goto scan;
  }
  line = (struct CSTRING *) tmp;
  line->buf[0] = '^';
  line->buf[1] = ' ';
  s = UTIL_strerror(err, &line->buf[2]);
  if (s < 0) goto scan;
  line->len = s + 2;
  bcopy(" - At line ", &line->buf[line->len], 11);
  s = itocstring(&line->buf[line->len + 11], *partab.ln);
  if (s < 0) goto scan;
  line->len = line->len + s + 11;
  s = SQ_Write(line);
  if (s >= 0)
    s = SQ_WriteFormat(-1);
scan:
  while (*source_ptr) source_ptr++;
  return;
}

variable_types: err short

variable_types: s short

variable_types: struct CSTRING { short len; unsigned char buf[32768]; } *

variable_types:
src
unsigned char *

variable_types: i int

variable_types:
tmp
unsigned char [128]


operator

decompiled_code:
__int64 operator()
{
char *v0; // rdx
int v1; // ecx
char v2; // al
__int64 result; // rax

v0 = (char *)source_ptr;
v1 = 0;
++source_ptr;
v2 = *v0;
if ( *v0 == 39 )
{
v1 = 1;
source_ptr = (__int64)(v0 + 2);
v2 = v0[1];
}
switch ( v2 )
{
case '!':
result = v1 == 0 ? 24 : 34;
break;
case '#':
result = v1 == 0 ? 0xF : 0;
break;
case '&':
result = v1 == 0 ? 23 : 33;
break;
case '*':
result = 0LL;
if ( !v1 )
{
result = 12LL;
if ( *(_BYTE *)source_ptr == 42 )
{
result = 16LL;
++source_ptr;
}
}
break;
case '+':
result = v1 == 0 ? 0xA : 0;
break;
case '-':
result = v1 == 0 ? 0xB : 0;
break;
case '/':
result = v1 == 0 ? 0xD : 0;
break;
case '<':
result = v1 == 0 ? 21 : 31;
break;
case '=':
result = v1 == 0 ? 20 : 30;
break;
case '>':
result = v1 == 0 ? 22 : 32;
break;
case '?':
result = v1 == 0 ? 28 : 38;
break;
case '[':
result = v1 == 0 ? 25 : 35;
break;
case '\\':
result = v1 == 0 ? 0xE : 0;
break;
case ']':
if ( *(_BYTE *)source_ptr == 93 )
{
++source_ptr;
result = v1 == 0 ? 27 : 37;
}
else
{
result = v1 == 0 ? 26 : 36;
}
break;
case '_':
result = v1 == 0 ? 0x11 : 0;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
char *v0; // rdx
int v1; // ecx
char v2; // al
__int64 result; // rax

v0 = (char *)source_ptr;
v1 = 0;
++source_ptr;
v2 = *v0;
if ( *v0 == 39 )
{
v1 = 1;
source_ptr = (__int64)(v0 + 2);
v2 = v0[1];
}
switch ( v2 )
{
case '!':
result = v1 == 0 ? 24 : 34;
break;
case '#':
result = v1 == 0 ? 0xF : 0;
break;
case '&':
result = v1 == 0 ? 23 : 33;
break;
case '*':
result = 0LL;
if ( !v1 )
{
result = 12LL;
if ( *(_BYTE *)source_ptr == 42 )
{
result = 16LL;
++source_ptr;
}
}
break;
case '+':
result = v1 == 0 ? 0xA : 0;
break;
case '-':
result = v1 == 0 ? 0xB : 0;
break;
case '/':
result = v1 == 0 ? 0xD : 0;
break;
case '<':
result = v1 == 0 ? 21 : 31;
break;
case '=':
result = v1 == 0 ? 20 : 30;
break;
case '>':
result = v1 == 0 ? 22 : 32;
break;
case '?':
result = v1 == 0 ? 28 : 38;
break;
case '[':
result = v1 == 0 ? 25 : 35;
break;
case '\\':
result = v1 == 0 ? 0xE : 0;
break;
case ']':
if ( *(_BYTE *)source_ptr == 93 )
{
++source_ptr;
result = v1 == 0 ? 27 : 37;
}
else
{
result = v1 == 0 ? 26 : 36;
}
break;
case '_':
result = v1 == 0 ? 0x11 : 0;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int operator()
{ char c;
  int not = 0;
  c = *source_ptr++;
  if (c == '\'')
  { if (not) return 0;
    not = 1;
    c = *source_ptr++;
  }
  switch(c)
  { case '+':
      if (not) return 0;
      return 10;
    case '-':
      if (not) return 0;
      return 11;
    case '*':
      if (not) return 0;
      if (*source_ptr == '*')
      { source_ptr++;
        return 16;
      }
      return 12;
    case '/':
      if (not) return 0;
      return 13;
    case '\\':
      if (not) return 0;
      return 14;
    case '#':
      if (not) return 0;
      return 15;
    case '_':
      if (not) return 0;
      return 17;
    case '=':
      return not ? 30 : 20;
    case '<':
      return not ? 31 : 21;
    case '>':
      return not ? 32 : 22;
    case '&':
      return not ? 33 : 23;
    case '!':
      return not ? 34 : 24;
    case '[':
      return not ? 35 : 25;
    case ']':
      if (*source_ptr == ']')
      { source_ptr++;
        return not ? 37 : 27;
      }
      return not ? 36 : 26;
    case '?':
      return not ? 38 : 28;
    default:
      return 0;
  }
}

variable_types: c char

variable_types: not int


eval

original_code:
void eval()
{ int op;
  int q;
  int patmat = 0;
  cstring *ptr;
  u_char c;
  atom();
  if ((*source_ptr == ')') ||
      (*source_ptr == ',') ||
      (*source_ptr == ':') ||
      (*source_ptr == '\0') ||
      (*source_ptr == '^') ||
      (*source_ptr == '@') ||
      (*source_ptr == ' '))
    return;
  while (1)
  { op = operator();
    if (op == 0)
    { comperror(-(12 +200));
      return;
    }
    patmat = ((op == 28) || (op == 38));
    if (patmat && (*source_ptr == '@'))
    { source_ptr++;
      patmat = 0;
    }
    if (patmat)
    { q = 0;
      *comp_ptr++ = 60;
      ptr = (cstring *) comp_ptr;
      comp_ptr = comp_ptr + sizeof(short);
      while (1)
      { c = *source_ptr++;
 if (q)
 { *comp_ptr++ = c;
   if (c == '"') q = 0;
   continue;
 }
 if (c == '"')
 { q = 1;
   *comp_ptr++ = c;
   continue;
 }
 if ((((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalnum) != 0) ||
     (c == '.'))
 { *comp_ptr++ = c;
   continue;
 }
 if (c == '(')
 { patmat++;
   *comp_ptr++ = c;
   continue;
 }
 if ((c == ')') && (patmat > 1))
 { --patmat;
   *comp_ptr++ = c;
   continue;
 }
 if ((patmat > 1) && (c == ','))
 { *comp_ptr++ = c;
   continue;
 }
 source_ptr--;
 break;
      }
      ptr->len = comp_ptr - ptr->buf;
      *comp_ptr++ = '\0';
    }
    else atom();
    *comp_ptr++ = (u_char) op;
    if ((*source_ptr == ')') ||
        (*source_ptr == ',') ||
        (*source_ptr == ':') ||
        (*source_ptr == '\0') ||
        (*source_ptr == '^') ||
        (*source_ptr == ' '))
      return;
  }
}

canonical_original_code:
void eval()
{ int op;
  int q;
  int patmat = 0;
  struct CSTRING *ptr;
  unsigned char c;
  atom();
  if ((*source_ptr == ')') ||
      (*source_ptr == ',') ||
      (*source_ptr == ':') ||
      (*source_ptr == '\0') ||
      (*source_ptr == '^') ||
      (*source_ptr == '@') ||
      (*source_ptr == ' '))
    return;
  while (1)
  { op = operator();
    if (op == 0)
    { comperror(-(12 +200));
      return;
    }
    patmat = ((op == 28) || (op == 38));
    if (patmat && (*source_ptr == '@'))
    { source_ptr++;
      patmat = 0;
    }
    if (patmat)
    { q = 0;
      *comp_ptr++ = 60;
      ptr = (struct CSTRING *) comp_ptr;
      comp_ptr = comp_ptr + sizeof(short);
      while (1)
      { c = *source_ptr++;
 if (q)
 { *comp_ptr++ = c;
   if (c == '"') q = 0;
   continue;
 }
 if (c == '"')
 { q = 1;
   *comp_ptr++ = c;
   continue;
 }
 if ((((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalnum) != 0) ||
     (c == '.'))
 { *comp_ptr++ = c;
   continue;
 }
 if (c == '(')
 { patmat++;
   *comp_ptr++ = c;
   continue;
 }
 if ((c == ')') && (patmat > 1))
 { --patmat;
   *comp_ptr++ = c;
   continue;
 }
 if ((patmat > 1) && (c == ','))
 { *comp_ptr++ = c;
   continue;
 }
 source_ptr--;
 break;
      }
      ptr->len = comp_ptr - ptr->buf;
      *comp_ptr++ = '\0';
    }
    else atom();
    *comp_ptr++ = (unsigned char) op;
    if ((*source_ptr == ')') ||
        (*source_ptr == ',') ||
        (*source_ptr == ':') ||
        (*source_ptr == '\0') ||
        (*source_ptr == '^') ||
        (*source_ptr == ' '))
      return;
  }
}

variable_types: op int

variable_types: q int

variable_types: patmat int

variable_types:
c
unsigned char

user_defined_types: struct CSTRING { short len; unsigned char buf[32768]; }


atom

decompiled_code:
_BYTE *atom()
{
char *v0; // rbp
char v1; // bl
unsigned __int16 v2; // ax
_BYTE *result; // rax
bool v4; // zf
_BYTE *v5; // rax
__int16 v6; // ax
__int64 v7; // rdx
_BYTE *v8; // rax
_WORD *v9; // rsi
char v10; // cl
__int64 v11; // rdx

v0 = (char *)source_ptr++;
v1 = *v0;
if ( *v0 != 64 )
{
v2 = (*_ctype_b_loc())[v1];
if ( (v2 & 0x400) == 0 && v1 != 37 && v1 != 94 )
{
if ( v1 == 36 )
return (_BYTE *)dodollar();
if ( (v2 & 0x800) != 0 || v1 == 46 )
{
v5 = (_BYTE *)comp_ptr;
source_ptr = (__int64)v0;
++comp_ptr;
*v5 = 60;
v6 = ncopy(&source_ptr, comp_ptr + 2);
v7 = comp_ptr;
*(_WORD *)comp_ptr = v6;
result = (_BYTE *)(v7 + v6 + 3);
comp_ptr = (__int64)result;
}
else
{
switch ( v1 )
{
case '"':
v8 = (_BYTE *)comp_ptr++;
*v8 = 60;
result = (_BYTE *)source_ptr;
v9 = (_WORD *)comp_ptr;
v10 = *(_BYTE *)source_ptr;
if ( *(_BYTE *)source_ptr )
{
v11 = 2LL;
do
{
if ( v10 == 34 && result[1] != 34 )
{
*((_BYTE *)v9 + (int)v11) = 0;
++source_ptr;
*v9 = v11 - 2;
comp_ptr += (int)v11 + 1LL;
return result;
}
source_ptr = (__int64)(result + 1);
*((_BYTE *)v9 + v11) = *result;
result = (_BYTE *)source_ptr;
v10 = *(_BYTE *)source_ptr;
if ( *(_BYTE *)(source_ptr - 1) == 34 && v10 == 34 )
{
++source_ptr;
v10 = *++result;
}
++v11;
}
while ( v10 );
v9 = (_WORD *)comp_ptr;
}
comp_ptr = (__int64)v9 - 1;
return (_BYTE *)comperror(-212);
case '\'':
atom();
result = (_BYTE *)comp_ptr++;
*result = 3;
break;
case '+':
atom();
result = (_BYTE *)comp_ptr++;
*result = 18;
break;
case '-':
atom();
result = (_BYTE *)comp_ptr++;
*result = 19;
break;
case '(':
eval();
result = (_BYTE *)source_ptr++;
if ( *result != 41 )
return (_BYTE *)comperror(-212);
break;
default:
return (_BYTE *)comperror(-212);
}
}
return result;
}
source_ptr = (__int64)v0;
result = (_BYTE *)localvar();
if ( (__int16)result >= 0 )
return result;
return (_BYTE *)comperror((__int16)result);
}
atom();
v4 = *(_BYTE *)source_ptr == 64;
result = (_BYTE *)comp_ptr++;
if ( !v4 )
{
*result = 65;
return result;
}
*result = 66;
result = (_BYTE *)localvar();
if ( (__int16)result < 0 )
return (_BYTE *)comperror((__int16)result);
return result;
}

canonical_decompiled_code:
_BYTE *func3()
{
char *v0; // rbp
char v1; // bl
unsigned __int16 v2; // ax
_BYTE *result; // rax
bool v4; // zf
_BYTE *v5; // rax
__int16 v6; // ax
__int64 v7; // rdx
_BYTE *v8; // rax
_WORD *v9; // rsi
char v10; // cl
__int64 v11; // rdx

v0 = (char *)source_ptr++;
v1 = *v0;
if ( *v0 != 64 )
{
v2 = (*_ctype_b_loc())[v1];
if ( (v2 & 0x400) == 0 && v1 != 37 && v1 != 94 )
{
if ( v1 == 36 )
return (_BYTE *)dodollar();
if ( (v2 & 0x800) != 0 || v1 == 46 )
{
v5 = (_BYTE *)comp_ptr;
source_ptr = (__int64)v0;
++comp_ptr;
*v5 = 60;
v6 = ncopy(&source_ptr, comp_ptr + 2);
v7 = comp_ptr;
*(_WORD *)comp_ptr = v6;
result = (_BYTE *)(v7 + v6 + 3);
comp_ptr = (__int64)result;
}
else
{
switch ( v1 )
{
case '"':
v8 = (_BYTE *)comp_ptr++;
*v8 = 60;
result = (_BYTE *)source_ptr;
v9 = (_WORD *)comp_ptr;
v10 = *(_BYTE *)source_ptr;
if ( *(_BYTE *)source_ptr )
{
v11 = 2LL;
do
{
if ( v10 == 34 && result[1] != 34 )
{
*((_BYTE *)v9 + (int)v11) = 0;
++source_ptr;
*v9 = v11 - 2;
comp_ptr += (int)v11 + 1LL;
return result;
}
source_ptr = (__int64)(result + 1);
*((_BYTE *)v9 + v11) = *result;
result = (_BYTE *)source_ptr;
v10 = *(_BYTE *)source_ptr;
if ( *(_BYTE *)(source_ptr - 1) == 34 && v10 == 34 )
{
++source_ptr;
v10 = *++result;
}
++v11;
}
while ( v10 );
v9 = (_WORD *)comp_ptr;
}
comp_ptr = (__int64)v9 - 1;
return (_BYTE *)func0(-212);
case '\'':
func3();
result = (_BYTE *)comp_ptr++;
*result = 3;
break;
case '+':
func3();
result = (_BYTE *)comp_ptr++;
*result = 18;
break;
case '-':
func3();
result = (_BYTE *)comp_ptr++;
*result = 19;
break;
case '(':
func2();
result = (_BYTE *)source_ptr++;
if ( *result != 41 )
return (_BYTE *)func0(-212);
break;
default:
return (_BYTE *)func0(-212);
}
}
return result;
}
source_ptr = (__int64)v0;
result = (_BYTE *)localvar();
if ( (__int16)result >= 0 )
return result;
return (_BYTE *)func0((__int16)result);
}
func3();
v4 = *(_BYTE *)source_ptr == 64;
result = (_BYTE *)comp_ptr++;
if ( !v4 )
{
*result = 65;
return result;
}
*result = 66;
result = (_BYTE *)localvar();
if ( (__int16)result < 0 )
return (_BYTE *)func0((__int16)result);
return result;
}

original_code:
void atom()
{ char c;
  int j;
  short s;
  u_char *p;
  c = *source_ptr++;
  if (c == '@')
  { atom();
    if (*source_ptr != '@')
    { *comp_ptr++ = 65;
      return;
    }
    *comp_ptr++ = 66;
    s = localvar();
    if (s < 0)
    { comperror(s);
      return;
    }
    return;
  }
  if ((((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha) != 0) || (c == '%') ||
      (c == '^'))
  { --source_ptr;
    s = localvar();
    if (s < 0)
    { comperror(s);
      return;
    }
    return;
  }
  if (c == '$')
  { dodollar();
    return;
  }
  if ((((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit) != 0) || (c == '.'))
  { source_ptr--;
    *comp_ptr++ = 60;
    s = ncopy(&source_ptr, comp_ptr+2);
    *((short *)comp_ptr) = s;
    comp_ptr = comp_ptr + sizeof(short) + s + 1;
    return;
  }
  if (c == '"')
  { *comp_ptr++ = 60;
    p = comp_ptr;
    j = 2;
    while (1)
    { if (*source_ptr == '\0')
      { comp_ptr--;
        comperror(-(12 +200));
        return;
      }
      if ((*source_ptr == '"') &&
          (source_ptr[1] != '"'))
      { p[j] = '\0';
        source_ptr++;
        break;
      }
      p[j++] = *source_ptr++;
      if ((*(source_ptr-1) == '"') &&
          (*source_ptr == '"'))
        source_ptr++;
    }
    *((short *)p) = (short) j-2;
    comp_ptr = comp_ptr + j + 1;
    return;
  }
  if (c == '\'')
  { atom();
    *comp_ptr++ = 3;
    return;
  }
  if (c == '+')
  { atom();
    *comp_ptr++ = 18;
    return;
  }
  if (c == '-')
  { atom();
    *comp_ptr++ = 19;
    return;
  }
  if (c == '(')
  { eval();
    if (*source_ptr++ != ')')
    { comperror(-(12 +200));
      return;
    }
    return;
  }
  comperror(-(12 +200));
  return;
}

canonical_original_code:
void atom()
{ char c;
  int j;
  short s;
  unsigned char *p;
  c = *source_ptr++;
  if (c == '@')
  { atom();
    if (*source_ptr != '@')
    { *comp_ptr++ = 65;
      return;
    }
    *comp_ptr++ = 66;
    s = localvar();
    if (s < 0)
    { comperror(s);
      return;
    }
    return;
  }
  if ((((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha) != 0) || (c == '%') ||
      (c == '^'))
  { --source_ptr;
    s = localvar();
    if (s < 0)
    { comperror(s);
      return;
    }
    return;
  }
  if (c == '$')
  { dodollar();
    return;
  }
  if ((((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit) != 0) || (c == '.'))
  { source_ptr--;
    *comp_ptr++ = 60;
    s = ncopy(&source_ptr, comp_ptr+2);
    *((short *)comp_ptr) = s;
    comp_ptr = comp_ptr + sizeof(short) + s + 1;
    return;
  }
  if (c == '"')
  { *comp_ptr++ = 60;
    p = comp_ptr;
    j = 2;
    while (1)
    { if (*source_ptr == '\0')
      { comp_ptr--;
        comperror(-(12 +200));
        return;
      }
      if ((*source_ptr == '"') &&
          (source_ptr[1] != '"'))
      { p[j] = '\0';
        source_ptr++;
        break;
      }
      p[j++] = *source_ptr++;
      if ((*(source_ptr-1) == '"') &&
          (*source_ptr == '"'))
        source_ptr++;
    }
    *((short *)p) = (short) j-2;
    comp_ptr = comp_ptr + j + 1;
    return;
  }
  if (c == '\'')
  { atom();
    *comp_ptr++ = 3;
    return;
  }
  if (c == '+')
  { atom();
    *comp_ptr++ = 18;
    return;
  }
  if (c == '-')
  { atom();
    *comp_ptr++ = 19;
    return;
  }
  if (c == '(')
  { eval();
    if (*source_ptr++ != ')')
    { comperror(-(12 +200));
      return;
    }
    return;
  }
  comperror(-(12 +200));
  return;
}

variable_types: j int

variable_types:
p
unsigned char *


Locate

decompiled_code:
__int64 __fastcall Locate(unsigned __int8 *a1)
{
__int64 v1; // rax
__int64 v2; // rdx
int v3; // eax
__int64 v4; // rcx
__int64 v5; // rdx
unsigned __int8 *v6; // rbx
__int64 v7; // rax
int v8; // eax

v1 = *((_QWORD *)&blk + level);
Index = 10;
v2 = *(_QWORD *)(v1 + 12);
v3 = 10;
idx = v2;
v4 = v2;
iidx = v2;
while ( 1 )
{
v6 = (unsigned __int8 *)(v2 + 4LL * *(unsigned __int16 *)(v4 + 2LL * v3));
chunk = v6;
memmove((char *)&keybuf + v6[2] + 1, v6 + 4, v6[3]);
v7 = v6[3];
keybuf = v7 + v6[2];
record = &v6[v7 + 4];
v8 = UTIL_Key_KeyCmp((unsigned int)((_DWORD)&keybuf + 1), a1 + 1, keybuf, *a1);
if ( !v8 )
return 0LL;
if ( v8 == 1 )
break;
v5 = *((_QWORD *)&blk + level);
v3 = Index + 1;
Index = v3;
if ( v3 > *(unsigned __int16 *)(*(_QWORD *)(v5 + 12) + 8LL) )
break;
v2 = iidx;
v4 = idx;
}
return 4294967289LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
__int64 v1; // rax
__int64 v2; // rdx
int v3; // eax
__int64 v4; // rcx
__int64 v5; // rdx
unsigned __int8 *v6; // rbx
__int64 v7; // rax
int v8; // eax

v1 = *((_QWORD *)&blk + level);
Index = 10;
v2 = *(_QWORD *)(v1 + 12);
v3 = 10;
idx = v2;
v4 = v2;
iidx = v2;
while ( 1 )
{
v6 = (unsigned __int8 *)(v2 + 4LL * *(unsigned __int16 *)(v4 + 2LL * v3));
chunk = v6;
memmove((char *)&keybuf + v6[2] + 1, v6 + 4, v6[3]);
v7 = v6[3];
keybuf = v7 + v6[2];
record = &v6[v7 + 4];
v8 = UTIL_Key_KeyCmp((unsigned int)((_DWORD)&keybuf + 1), a1 + 1, keybuf, *a1);
if ( !v8 )
return 0LL;
if ( v8 == 1 )
break;
v5 = *((_QWORD *)&blk + level);
v3 = Index + 1;
Index = v3;
if ( v3 > *(unsigned __int16 *)(*(_QWORD *)(v5 + 12) + 8LL) )
break;
v2 = iidx;
v4 = idx;
}
return 4294967289LL;
}

original_code:
short Locate(u_char *key)
{ int i;
  idx = (u_short *) blk[level]->mem;
  iidx = (int *) blk[level]->mem;
  Index = 10;
  while (1)
  { chunk = (cstring *) &iidx[idx[Index]];
    bcopy(&chunk->buf[2], &keybuf[chunk->buf[0]+1],
   chunk->buf[1]);
    keybuf[0] = chunk->buf[0] + chunk->buf[1];
    record = (cstring *) &chunk->buf[chunk->buf[1]+2];
    i = UTIL_Key_KeyCmp(&keybuf[1], &key[1], keybuf[0], key[0]);
    if (i == 0)
    { return 0;
    }
    if (i == 1)
    { return -7;
    }
    Index++;
    if (Index > blk[level]->mem->last_idx)
    { return -7;
    }
  }
}

canonical_original_code:
short Locate(unsigned char *key)
{ int i;
  idx = (unsigned short *) blk[level]->mem;
  iidx = (int *) blk[level]->mem;
  Index = 10;
  while (1)
  { chunk = (struct CSTRING *) &iidx[idx[Index]];
    bcopy(&chunk->buf[2], &keybuf[chunk->buf[0]+1],
   chunk->buf[1]);
    keybuf[0] = chunk->buf[0] + chunk->buf[1];
    record = (struct CSTRING *) &chunk->buf[chunk->buf[1]+2];
    i = UTIL_Key_KeyCmp(&keybuf[1], &key[1], keybuf[0], key[0]);
    if (i == 0)
    { return 0;
    }
    if (i == 1)
    { return -7;
    }
    Index++;
    if (Index > blk[level]->mem->last_idx)
    { return -7;
    }
  }
}

variable_types:
key
unsigned char *


decompiled_code:
__int64 Locate_next()
{
__int64 v0; // rdx
int v1; // eax
__int64 v2; // rdx
__int64 result; // rax
unsigned __int8 *v4; // rbx
__int64 v5; // rax

v0 = *((_QWORD *)&blk + level);
v1 = Index + 1;
Index = v1;
v2 = *(_QWORD *)(v0 + 12);
if ( v1 <= *(unsigned __int16 *)(v2 + 8) )
goto LABEL_5;
if ( !*(_DWORD *)(v2 + 4) )
return 4294967289LL;
result = Get_block();
if ( (result & 0x8000u) == 0LL )
{
v1 = Index;
LABEL_5:
v4 = (unsigned __int8 *)(iidx + 4LL * *(unsigned __int16 *)(idx + 2LL * v1));
chunk = v4;
memmove((char *)&keybuf + v4[2] + 1, v4 + 4, v4[3]);
v5 = v4[3];
keybuf = v5 + v4[2];
record = &v4[v5 + 4];
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rdx
int v1; // eax
__int64 v2; // rdx
__int64 result; // rax
unsigned __int8 *v4; // rbx
__int64 v5; // rax

v0 = *((_QWORD *)&blk + level);
v1 = Index + 1;
Index = v1;
v2 = *(_QWORD *)(v0 + 12);
if ( v1 <= *(unsigned __int16 *)(v2 + 8) )
goto LABEL_5;
if ( !*(_DWORD *)(v2 + 4) )
return 4294967289LL;
result = Get_block();
if ( (result & 0x8000u) == 0LL )
{
v1 = Index;
LABEL_5:
v4 = (unsigned __int8 *)(iidx + 4LL * *(unsigned __int16 *)(idx + 2LL * v1));
chunk = v4;
memmove((char *)&keybuf + v4[2] + 1, v4 + 4, v4[3]);
v5 = v4[3];
keybuf = v5 + v4[2];
record = &v4[v5 + 4];
result = 0LL;
}
return result;
}

original_code:
short Locate_next()
{ int i;
  short s;
  Index++;
  if (Index > blk[level]->mem->last_idx)
  { if (!blk[level]->mem->right_ptr)
    { return -7;
    }
    i = blk[level]->mem->right_ptr;
    s = Get_block(i);
    if (s < 0)
    { return s;
    }
  }
  chunk = (cstring *) &iidx[idx[Index]];
  bcopy(&chunk->buf[2], &keybuf[chunk->buf[0]+1],
 chunk->buf[1]);
  keybuf[0] = chunk->buf[0] + chunk->buf[1];
  record = (cstring *) &chunk->buf[chunk->buf[1]+2];
  return 0;
}

canonical_original_code:
short Locate_next()
{ int i;
  short s;
  Index++;
  if (Index > blk[level]->mem->last_idx)
  { if (!blk[level]->mem->right_ptr)
    { return -7;
    }
    i = blk[level]->mem->right_ptr;
    s = Get_block(i);
    if (s < 0)
    { return s;
    }
  }
  chunk = (struct CSTRING *) &iidx[idx[Index]];
  bcopy(&chunk->buf[2], &keybuf[chunk->buf[0]+1],
 chunk->buf[1]);
  keybuf[0] = chunk->buf[0] + chunk->buf[1];
  record = (struct CSTRING *) &chunk->buf[chunk->buf[1]+2];
  return 0;
}


ser

decompiled_code:
int __fastcall ser(int a1)
{
int v1; // er12
char v3[134]; // [rsp+2h] [rbp-86h] BYREF

if ( (_WORD)a1 == 0xFF1D )
{
panic("Chanel zero has gone away");
goto LABEL_5;
}
LOWORD(v1) = a1;
if ( (a1 & 0x8000u) != 0 )
LABEL_5:
v1 = -a1;
UTIL_strerror((unsigned int)(__int16)v1, v3);
return fprintf(stderr, "\r\nERROR occured %d\r\n%s\r\n", (unsigned int)(__int16)v1, v3);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int v1; // er12
char v3[134]; // [rsp+2h] [rbp-86h] BYREF

if ( (_WORD)a1 == 0xFF1D )
{
panic("Chanel zero has gone away");
goto LABEL_5;
}
LOWORD(v1) = a1;
if ( (a1 & 0x8000u) != 0 )
LABEL_5:
v1 = -a1;
UTIL_strerror((unsigned int)(__int16)v1, v3);
return fprintf(stderr, "\r\nERROR occured %d\r\n%s\r\n", (unsigned int)(__int16)v1, v3);
}

original_code:
void ser(short s)
{ cstring *cptr;
  short t;
  u_char junk[100];
  if (s == -(200 + 27))
  { panic("Chanel zero has gone away");
  }
  cptr = (cstring *) junk;
  if (s < 0) s = -s;
  t = UTIL_strerror(s, &cptr->buf[0]);
  fprintf( stderr, "\r\nERROR occured %d\r\n%s\r\n",
      s, &cptr->buf[0]);
  return;
}

canonical_original_code:
void ser(short s)
{ struct CSTRING *cptr;
  short t;
  unsigned char junk[100];
  if (s == -(200 + 27))
  { panic("Chanel zero has gone away");
  }
  cptr = (struct CSTRING *) junk;
  if (s < 0) s = -s;
  t = UTIL_strerror(s, &cptr->buf[0]);
  fprintf( stderr, "\r\nERROR occured %d\r\n%s\r\n",
      s, &cptr->buf[0]);
  return;
}

variable_types: t short

variable_types:
junk
unsigned char [100]


controlc

decompiled_code:
int controlc()
{
__int16 v0; // ax
int result; // eax
__int16 v2[2]; // [rsp+6h] [rbp-12h] BYREF
char v3; // [rsp+Bh] [rbp-Dh]

v0 = SQ_WriteFormat(0xFFFFFFFFLL);
if ( v0 < 0 )
ser(v0);
v3 = 0;
v2[1] = 17246;
v2[0] = 2;
result = SQ_Write(v2);
if ( (result & 0x8000u) != 0 )
result = ser((__int16)result);
return result;
}

canonical_decompiled_code:
int func1()
{
__int16 v0; // ax
int result; // eax
__int16 v2[2]; // [rsp+6h] [rbp-12h] BYREF
char v3; // [rsp+Bh] [rbp-Dh]

v0 = SQ_WriteFormat(0xFFFFFFFFLL);
if ( v0 < 0 )
func0(v0);
v3 = 0;
v2[1] = 17246;
v2[0] = 2;
result = SQ_Write(v2);
if ( (result & 0x8000u) != 0 )
result = func0((__int16)result);
return result;
}

original_code:
void controlc()
{ cstring *sptr;
  u_char junk[10];
  short s;
  sptr = (cstring *) junk;
  s = SQ_WriteFormat(-1);
  if (s < 0) ser(s);
  bcopy("^C", sptr->buf, 2);
  sptr->buf[3] = '\0';
  sptr->len = 2;
  s = SQ_Write(sptr);
  if (s < 0) ser(s);
  return;
}

canonical_original_code:
void controlc()
{ struct CSTRING *sptr;
  unsigned char junk[10];
  short s;
  sptr = (struct CSTRING *) junk;
  s = SQ_WriteFormat(-1);
  if (s < 0) ser(s);
  bcopy("^C", sptr->buf, 2);
  sptr->buf[3] = '\0';
  sptr->len = 2;
  s = SQ_Write(sptr);
  if (s < 0) ser(s);
  return;
}

variable_types:
junk
unsigned char [10]


decompiled_code:
__int64 __fastcall SQ_Pipe_Close(int a1, const char *a2)
{
int *v3; // rax

if ( close(a1) != -1 && (open(a2, 2049, 0LL) != -1 || unlink(a2) != -1) )
return 0LL;
v3 = _errno_location();
return getError(0LL, (unsigned int)*v3);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, const char *a2)
{
int *v3; // rax

if ( close(a1) != -1 && (open(a2, 2049, 0LL) != -1 || unlink(a2) != -1) )
return 0LL;
v3 = _errno_location();
return getError(0LL, (unsigned int)*v3);
}

original_code:
int SQ_Pipe_Close (int pid, char *pipe)
{ int ret;
  int oid;
  ret = close ( pid );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  oid = open ( pipe, 01|04000, 0 );
  if ( oid == -1 )
  { ret = unlink ( pipe );
    if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  };
  return ( 0 );
}

canonical_original_code:
int SQ_Pipe_Close(int pid, char *pipe)
{ int ret;
  int oid;
  ret = close ( pid );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  oid = open ( pipe, 01|04000, 0 );
  if ( oid == -1 )
  { ret = unlink ( pipe );
    if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  };
  return ( 0 );
}

variable_types: pid int

variable_types:
pipe
char *

variable_types: ret int

variable_types: oid int


decompiled_code:
ssize_t __fastcall SQ_Pipe_Write(int a1, const void *a2, int a3)
{
ssize_t result; // rax
__int64 v4; // rsi

result = write(a1, a2, a3);
if ( (_DWORD)result == -1 )
{
v4 = (unsigned int)*_errno_location();
if ( (_DWORD)v4 == 32 )
result = getError(1LL, 46LL);
else
result = getError(0LL, v4);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(int a1, const void *a2, int a3)
{
ssize_t result; // rax
__int64 v4; // rsi

result = write(a1, a2, a3);
if ( (_DWORD)result == -1 )
{
v4 = (unsigned int)*_errno_location();
if ( (_DWORD)v4 == 32 )
result = getError(1LL, 46LL);
else
result = getError(0LL, v4);
}
return result;
}

original_code:
int SQ_Pipe_Write (int pid, u_char *writebuf, int nbytes)
{ int ret;
  ret = write ( pid, writebuf, nbytes );
  if ( ret == -1 )
  { if ( (*__errno_location ()) == 32 ) return ( getError ( 1, 46 ) );
    else return ( getError ( 0, (*__errno_location ()) ) );
  }
  else return ( ret );
}

canonical_original_code:
int SQ_Pipe_Write(int pid, unsigned char *writebuf, int nbytes)
{ int ret;
  ret = write ( pid, writebuf, nbytes );
  if ( ret == -1 )
  { if ( (*__errno_location ()) == 32 ) return ( getError ( 1, 46 ) );
    else return ( getError ( 0, (*__errno_location ()) ) );
  }
  else return ( ret );
}

variable_types:
writebuf
unsigned char *

variable_types: nbytes int


decompiled_code:
__int64 __fastcall SQ_Pipe_Read(int fd, void *buf, unsigned int a3)
{
int v5; // er12
int v6; // eax
__int64 v7; // rsi

while ( 1 )
{
v5 = seqioSelect((unsigned int)fd, 0LL, a3);
if ( v5 < 0 )
break;
v6 = read(fd, buf, 1uLL);
v5 = v6;
if ( v6 != -1 )
{
if ( v6 )
{
v5 = 1;
}
else if ( a3 )
{
sleep(1u);
}
else
{
if ( raise(14) == -1 )
{
v7 = (unsigned int)*_errno_location();
return getError(0LL, v7);
}
v5 = -1;
}
return (unsigned int)v5;
}
v7 = (unsigned int)*_errno_location();
if ( (_DWORD)v7 != 11 )
return getError(0LL, v7);
sleep(1u);
}
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf, unsigned int a3)
{
int v5; // er12
int v6; // eax
__int64 v7; // rsi

while ( 1 )
{
v5 = seqioSelect((unsigned int)fd, 0LL, a3);
if ( v5 < 0 )
break;
v6 = read(fd, buf, 1uLL);
v5 = v6;
if ( v6 != -1 )
{
if ( v6 )
{
v5 = 1;
}
else if ( a3 )
{
sleep(1u);
}
else
{
if ( raise(14) == -1 )
{
v7 = (unsigned int)*_errno_location();
return getError(0LL, v7);
}
v5 = -1;
}
return (unsigned int)v5;
}
v7 = (unsigned int)*_errno_location();
if ( (_DWORD)v7 != 11 )
return getError(0LL, v7);
sleep(1u);
}
return (unsigned int)v5;
}

original_code:
int SQ_Pipe_Read (int pid, u_char *readbuf, int tout)
{ int ret;
  int bytesread;
start:
  ret = seqioSelect ( pid, 0, tout );
  if ( ret < 0 ) return ( ret );
  bytesread = read ( pid, readbuf, 1 );
  if ((bytesread == -1) && ((*__errno_location ()) == 11))
  { sleep(1);
    goto start;
  }
  if ( bytesread == -1 )
  { if ((*__errno_location ()) == 11)
    { sleep(1);
      (*__errno_location ()) = 0;
      goto start;
    }
    return ( getError ( 0, (*__errno_location ()) ) );
  }
  else if ( bytesread == 0 )
  { if ( tout == 0 )
    { ret = raise ( 14 );
      if ( ret == -1 )
      { return ( getError ( 0, (*__errno_location ()) ) );
      }
      return ( -1 );
    }
    sleep ( 1 );
    return ( 0 );
  }
  else return ( 1 );
}

canonical_original_code:
int SQ_Pipe_Read(int pid, unsigned char *readbuf, int tout)
{ int ret;
  int bytesread;
start:
  ret = seqioSelect ( pid, 0, tout );
  if ( ret < 0 ) return ( ret );
  bytesread = read ( pid, readbuf, 1 );
  if ((bytesread == -1) && ((*__errno_location ()) == 11))
  { sleep(1);
    goto start;
  }
  if ( bytesread == -1 )
  { if ((*__errno_location ()) == 11)
    { sleep(1);
      (*__errno_location ()) = 0;
      goto start;
    }
    return ( getError ( 0, (*__errno_location ()) ) );
  }
  else if ( bytesread == 0 )
  { if ( tout == 0 )
    { ret = raise ( 14 );
      if ( ret == -1 )
      { return ( getError ( 0, (*__errno_location ()) ) );
      }
      return ( -1 );
    }
    sleep ( 1 );
    return ( 0 );
  }
  else return ( 1 );
}

variable_types:
readbuf
unsigned char *

variable_types: tout int

variable_types: bytesread int


createPipe

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

result = mkfifo(a1, 0x1A4u);
if ( result == -1 )
{
v2 = _errno_location();
result = getError(0LL, (unsigned int)*v2);
}
return result;
}

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

result = mkfifo(a1, 0x1A4u);
if ( result == -1 )
{
v2 = _errno_location();
result = getError(0LL, (unsigned int)*v2);
}
return result;
}

original_code:
int createPipe (char *pipe)
{ int ret;
  ret = mkfifo ( pipe, 0400|0200|(0400 >> 3)|((0400 >> 3) >> 3) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  else return ( ret );
}

canonical_original_code:
int createPipe(char *pipe)
{ int ret;
  ret = mkfifo ( pipe, 0400|0200|(0400 >> 3)|((0400 >> 3) >> 3) );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  else return ( ret );
}


decompiled_code:
int __fastcall SQ_Pipe_Open(char *file, int a2)
{
int result; // eax
int *v3; // rax

if ( a2 == 9 )
{
result = open(file, 1, 0LL);
LABEL_5:
if ( result == -1 )
{
v3 = _errno_location();
result = getError(0LL, (unsigned int)*v3);
}
return result;
}
if ( a2 != 10 )
return getError(1LL, 21LL);
result = createPipe(file);
if ( result >= 0 )
{
result = open(file, 2048, 0LL);
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(char *file, int a2)
{
int result; // eax
int *v3; // rax

if ( a2 == 9 )
{
result = open(file, 1, 0LL);
LABEL_5:
if ( result == -1 )
{
v3 = _errno_location();
result = getError(0LL, (unsigned int)*v3);
}
return result;
}
if ( a2 != 10 )
return getError(1LL, 21LL);
result = func3(file);
if ( result >= 0 )
{
result = open(file, 2048, 0LL);
goto LABEL_5;
}
return result;
}

original_code:
int SQ_Pipe_Open (char *pipe, int op)
{ int ret;
  int flag;
  int pid;
  switch ( op )
  { case 10:
      ret = createPipe ( pipe );
      if ( ret < 0 ) return ( ret );
      flag = 00|04000;
      break;
    case 9:
      flag = 01;
      break;
    default:
      return ( getError ( 1, 21 ) );
  }
  pid = open ( pipe, flag, 0 );
  if ( pid == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( pid );
}

canonical_original_code:
int SQ_Pipe_Open(char *pipe, int op)
{ int ret;
  int flag;
  int pid;
  switch ( op )
  { case 10:
      ret = createPipe ( pipe );
      if ( ret < 0 ) return ( ret );
      flag = 00|04000;
      break;
    case 9:
      flag = 01;
      break;
    default:
      return ( getError ( 1, 21 ) );
  }
  pid = open ( pipe, flag, 0 );
  if ( pid == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( pid );
}

variable_types: op int

variable_types: flag int