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

repo: jcwynholds/mumps

decompiled_code:
__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

return_type: void


setSignal

decompiled_code:
int __fastcall setSignal(int sig, int a2)
{
void (*v2)(int); // rax
int result; // eax
int *v4; // rax
sigset_t v5; // [rsp+0h] [rbp-138h] BYREF
struct sigaction v6; // [rsp+80h] [rbp-B8h] BYREF

sigemptyset(&v5);
sigfillset(&v5);
*(__m128i *)v6.sa_mask.__val = _mm_loadu_si128((const __m128i *)&v5);
*(__m128i *)&v6.sa_mask.__val[2] = _mm_loadu_si128((const __m128i *)&v5.__val[2]);
*(__m128i *)&v6.sa_mask.__val[4] = _mm_loadu_si128((const __m128i *)&v5.__val[4]);
*(__m128i *)&v6.sa_mask.__val[6] = _mm_loadu_si128((const __m128i *)&v5.__val[6]);
*(__m128i *)&v6.sa_mask.__val[8] = _mm_loadu_si128((const __m128i *)&v5.__val[8]);
*(__m128i *)&v6.sa_mask.__val[10] = _mm_loadu_si128((const __m128i *)&v5.__val[10]);
*(__m128i *)&v6.sa_mask.__val[12] = _mm_loadu_si128((const __m128i *)&v5.__val[12]);
*(__m128i *)&v6.sa_mask.__val[14] = _mm_loadu_si128((const __m128i *)&v5.__val[14]);
v6.sa_flags = 0;
v2 = (void (*)(int))signalHandler;
if ( a2 )
v2 = (void (*)(int))(signalHandler + 1);
v6.sa_handler = v2;
result = sigaction(sig, &v6, 0LL);
if ( result == -1 )
{
v4 = _errno_location();
result = getError(0LL, (unsigned int)*v4);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int sig, int a2)
{
void (*v2)(int); // rax
int result; // eax
int *v4; // rax
sigset_t v5; // [rsp+0h] [rbp-138h] BYREF
struct sigaction v6; // [rsp+80h] [rbp-B8h] BYREF

sigemptyset(&v5);
sigfillset(&v5);
*(__m128i *)v6.sa_mask.__val = _mm_loadu_si128((const __m128i *)&v5);
*(__m128i *)&v6.sa_mask.__val[2] = _mm_loadu_si128((const __m128i *)&v5.__val[2]);
*(__m128i *)&v6.sa_mask.__val[4] = _mm_loadu_si128((const __m128i *)&v5.__val[4]);
*(__m128i *)&v6.sa_mask.__val[6] = _mm_loadu_si128((const __m128i *)&v5.__val[6]);
*(__m128i *)&v6.sa_mask.__val[8] = _mm_loadu_si128((const __m128i *)&v5.__val[8]);
*(__m128i *)&v6.sa_mask.__val[10] = _mm_loadu_si128((const __m128i *)&v5.__val[10]);
*(__m128i *)&v6.sa_mask.__val[12] = _mm_loadu_si128((const __m128i *)&v5.__val[12]);
*(__m128i *)&v6.sa_mask.__val[14] = _mm_loadu_si128((const __m128i *)&v5.__val[14]);
v6.sa_flags = 0;
v2 = (void (*)(int))signalHandler;
if ( a2 )
v2 = (void (*)(int))(signalHandler + 1);
v6.sa_handler = v2;
result = sigaction(sig, &v6, 0LL);
if ( result == -1 )
{
v4 = _errno_location();
result = getError(0LL, (unsigned int)*v4);
}
return result;
}

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()
{
int v0; // edx
__int64 result; // rax
int *v2; // rax
int *v3; // rax
sigset_t v4; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v5; // [rsp+80h] [rbp-A8h] BYREF

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

canonical_decompiled_code:
__int64 func2()
{
int v0; // edx
__int64 result; // rax
int *v2; // rax
int *v3; // rax
sigset_t v4; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v5; // [rsp+80h] [rbp-A8h] BYREF

sigemptyset(&v4);
sigfillset(&v4);
*(__m128i *)v5.sa_mask.__val = _mm_loadu_si128((const __m128i *)&v4);
*(__m128i *)&v5.sa_mask.__val[2] = _mm_loadu_si128((const __m128i *)&v4.__val[2]);
*(__m128i *)&v5.sa_mask.__val[4] = _mm_loadu_si128((const __m128i *)&v4.__val[4]);
*(__m128i *)&v5.sa_mask.__val[6] = _mm_loadu_si128((const __m128i *)&v4.__val[6]);
*(__m128i *)&v5.sa_mask.__val[8] = _mm_loadu_si128((const __m128i *)&v4.__val[8]);
*(__m128i *)&v5.sa_mask.__val[10] = _mm_loadu_si128((const __m128i *)&v4.__val[10]);
*(__m128i *)&v5.sa_mask.__val[12] = _mm_loadu_si128((const __m128i *)&v4.__val[12]);
*(__m128i *)&v5.sa_mask.__val[14] = _mm_loadu_si128((const __m128i *)&v4.__val[14]);
v5.sa_flags = 0;
v5.sa_handler = (__sighandler_t)(signalHandler + 1);
if ( sigaction(1, &v5, 0LL) == -1 )
{
v2 = _errno_location();
result = getError(0LL, (unsigned int)*v2);
}
else
{
v5.sa_handler = (__sighandler_t)signalHandler;
if ( sigaction(2, &v5, 0LL) == -1 )
goto LABEL_29;
v5.sa_flags = 0x10000000;
if ( sigaction(3, &v5, 0LL) == -1 )
goto LABEL_29;
v5.sa_flags = 0;
v5.sa_handler = 0LL;
if ( sigaction(4, &v5, 0LL) == -1 )
goto LABEL_29;
v5.sa_handler = (__sighandler_t)signalHandler;
if ( sigaction(5, &v5, 0LL) == -1 )
goto LABEL_29;
if ( sigaction(6, &v5, 0LL) == -1 )
goto LABEL_29;
v5.sa_handler = 0LL;
if ( sigaction(8, &v5, 0LL) == -1 )
goto LABEL_29;
v5.sa_handler = 0LL;
if ( sigaction(7, &v5, 0LL) == -1 )
goto LABEL_29;
v5.sa_handler = 0LL;
if ( sigaction(11, &v5, 0LL) == -1
|| (v5.sa_handler = (__sighandler_t)signalHandler, sigaction(13, &v5, 0LL) == -1)
|| sigaction(14, &v5, 0LL) == -1
|| sigaction(15, &v5, 0LL) == -1
|| sigaction(23, &v5, 0LL) == -1
|| sigaction(20, &v5, 0LL) == -1
|| (v5.sa_handler = (__sighandler_t)(signalHandler + 1), sigaction(18, &v5, 0LL) == -1)
|| (v5.sa_handler = (__sighandler_t)signalHandler, sigaction(21, &v5, 0LL) == -1)
|| sigaction(22, &v5, 0LL) == -1
|| sigaction(29, &v5, 0LL) == -1
|| sigaction(24, &v5, 0LL) == -1
|| sigaction(25, &v5, 0LL) == -1
|| sigaction(26, &v5, 0LL) == -1
|| sigaction(27, &v5, 0LL) == -1
|| (v5.sa_handler = (__sighandler_t)(signalHandler + 1), sigaction(28, &v5, 0LL) == -1)
|| (v5.sa_handler = (__sighandler_t)signalHandler, sigaction(10, &v5, 0LL) == -1)
|| (v0 = sigaction(12, &v5, 0LL), result = 0LL, v0 == -1) )
{
LABEL_29:
v3 = _errno_location();
result = getError(0LL, (unsigned int)*v3);
}
}
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; // ebx
int *v4; // rax
unsigned int v5; // eax
int *v6; // rax

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

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

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

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(int fd, __int16 a2)
{
int v2; // edx
__int64 result; // rax
int *v4; // rax
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

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

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

v5.sa_family = 2;
*(_WORD *)v5.sa_data = func0(a2);
*(_DWORD *)&v5.sa_data[2] = 0;
v2 = bind(fd, &v5, 0x10u);
result = 0LL;
if ( v2 == -1 )
{
v4 = _errno_location();
result = getError(0LL, (unsigned int)*v4);
}
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 v1; // edx
__int64 result; // rax
int *v3; // rax

v1 = listen(a1, 3);
result = 0LL;
if ( v1 == -1 )
{
v3 = _errno_location();
result = getError(0LL, (unsigned int)*v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // edx
__int64 result; // rax
int *v3; // rax

v1 = listen(a1, 3);
result = 0LL;
if ( v1 == -1 )
{
v3 = _errno_location();
result = getError(0LL, (unsigned int)*v3);
}
return result;
}

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
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF
socklen_t addr_len[3]; // [rsp+1Ch] [rbp-Ch] BYREF

result = seqioSelect(fd, 0LL, a2);
if ( result >= 0 )
{
addr_len[0] = 16;
result = accept(fd, &v4, 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
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF
socklen_t addr_len[3]; // [rsp+1Ch] [rbp-Ch] BYREF

result = seqioSelect(fd, 0LL, a2);
if ( result >= 0 )
{
addr_len[0] = 16;
result = accept(fd, &v4, 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, char *cp, __int16 a3)
{
int v3; // edx
__int64 result; // rax
__int64 v5; // rsi
struct sockaddr v6; // [rsp+0h] [rbp-38h] BYREF
struct in_addr inp; // [rsp+1Ch] [rbp-1Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func5(int fd, char *cp, __int16 a3)
{
int v3; // edx
__int64 result; // rax
__int64 v5; // rsi
struct sockaddr v6; // [rsp+0h] [rbp-38h] BYREF
struct in_addr inp; // [rsp+1Ch] [rbp-1Ch] BYREF

v6.sa_family = 2;
*(_WORD *)v6.sa_data = func0(a3);
if ( !inet_aton(cp, &inp) )
return getError(1LL, 48LL);
*(struct in_addr *)&v6.sa_data[2] = inp;
v3 = connect(fd, &v6, 0x10u);
result = (unsigned int)fd;
if ( v3 == -1 )
{
v5 = (unsigned int)*_errno_location();
if ( (_DWORD)v5 == 115 )
{
result = seqioSelect((unsigned int)fd, 1LL, 0xFFFFFFFFLL);
if ( (int)result >= 0 )
result = (unsigned int)fd;
}
else
{
result = getError(0LL, v5);
}
}
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; // edx
__int64 v4; // rsi

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

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

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

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:
ssize_t __fastcall SQ_Socket_Read(__int64 fd, void *buf, __int64 a3)
{
ssize_t result; // rax
int *v4; // rbx

if ( !(_DWORD)a3 || (result = seqioSelect(fd, 0LL, a3), (int)result >= 0) )
{
result = recv(fd, buf, 1uLL, 0);
if ( (_DWORD)result == -1 )
{
v4 = _errno_location();
if ( *v4 == 11 )
raise(14);
result = getError(0LL, (unsigned int)*v4);
}
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func7(__int64 fd, void *buf, __int64 a3)
{
ssize_t result; // rax
int *v4; // rbx

if ( !(_DWORD)a3 || (result = seqioSelect(fd, 0LL, a3), (int)result >= 0) )
{
result = recv(fd, buf, 1uLL, 0);
if ( (_DWORD)result == -1 )
{
v4 = _errno_location();
if ( *v4 == 11 )
raise(14);
result = getError(0LL, (unsigned int)*v4);
}
}
return result;
}

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)
{
unsigned int v2; // ebx
int v3; // eax

if ( a2 == 2 )
{
v3 = open(a1, 0, 0LL);
}
else
{
if ( a2 == 4 )
{
a2 = 2;
}
else if ( a2 != 1 )
{
return (unsigned int)getError(&loc_1);
}
v3 = open(a1, a2, 0LL);
}
v2 = v3;
if ( v3 == -1 && *_errno_location() != 16 )
v2 = getError(0LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, int a2)
{
unsigned int v2; // ebx
int v3; // eax

if ( a2 == 2 )
{
v3 = open(a1, 0, 0LL);
}
else
{
if ( a2 == 4 )
{
a2 = 2;
}
else if ( a2 != 1 )
{
return (unsigned int)getError(&loc_1);
}
v3 = open(a1, a2, 0LL);
}
v2 = v3;
if ( v3 == -1 && *_errno_location() != 16 )
v2 = getError(0LL);
return v2;
}

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:
__int64 __fastcall SQ_Device_Write(int a1, const void *a2, int a3)
{
unsigned int v3; // edx

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

canonical_decompiled_code:
__int64 __fastcall func1(int a1, const void *a2, int a3)
{
unsigned int v3; // edx

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

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; // ebp
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; // ebp
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:
__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:
__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:
__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; // ebx
unsigned __int16 v2; // ax
int v3; // ebp

v1 = SQ_Socket_Create(1LL);
if ( (v1 & 0x80000000) == 0 )
{
v2 = atoi(nptr);
v3 = SQ_Socket_Bind(v1, v2);
if ( v3 < 0 || (v3 = SQ_Socket_Listen(v1), v3 < 0) )
{
close(v1);
v1 = v3;
}
}
return v1;
}

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

v1 = SQ_Socket_Create(1LL);
if ( (v1 & 0x80000000) == 0 )
{
v2 = atoi(nptr);
v3 = SQ_Socket_Bind(v1, v2);
if ( v3 < 0 || (v3 = SQ_Socket_Listen(v1), v3 < 0) )
{
close(v1);
v1 = v3;
}
}
return v1;
}

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)
{
int v1; // ebx
char *v2; // rax
unsigned __int16 v3; // ax
int v4; // ebp
char v6[136]; // [rsp+0h] [rbp-88h] BYREF

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

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

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

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
__int64 v6; // r12
__int64 v7; // rbp
int v8; // ebp
__int16 v9; // ax
__int16 v10; // ax
__int16 v11; // [rsp+0h] [rbp-98h] BYREF
char v12[2]; // [rsp+2h] [rbp-96h] BYREF
char v13[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;
*((_DWORD *)&partab + 11) = v5;
v6 = **((_QWORD **)&partab + 7);
v7 = **((_QWORD **)&partab + 6);
if ( (SQ_Write(v6) & 0x8000u) == 0LL && (SQ_WriteFormat(0xFFFFFFFFLL) & 0x8000u) == 0LL )
{
v8 = v7 - (v6 + 2);
if ( v8 - 1 <= 0 || (SQ_WriteFormat((unsigned int)(v8 - 1)) & 0x8000u) == 0LL )
{
v12[0] = 94;
v12[1] = 32;
v9 = UTIL_strerror((unsigned int)a1, v13);
if ( v9 >= 0 )
{
v11 = v9 + 2;
qmemcpy(&v12[(__int16)(v9 + 2)], " - At line ", 11);
v10 = itocstring(&v13[(__int16)(v9 + 2) + 9], **((unsigned int **)&partab + 8));
if ( v10 >= 0 )
{
v11 += v10 + 11;
if ( (SQ_Write(&v11) & 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
__int64 v6; // r12
__int64 v7; // rbp
int v8; // ebp
__int16 v9; // ax
__int16 v10; // ax
__int16 v11; // [rsp+0h] [rbp-98h] BYREF
char v12[2]; // [rsp+2h] [rbp-96h] BYREF
char v13[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;
*((_DWORD *)&partab + 11) = v5;
v6 = **((_QWORD **)&partab + 7);
v7 = **((_QWORD **)&partab + 6);
if ( (SQ_Write(v6) & 0x8000u) == 0LL && (SQ_WriteFormat(0xFFFFFFFFLL) & 0x8000u) == 0LL )
{
v8 = v7 - (v6 + 2);
if ( v8 - 1 <= 0 || (SQ_WriteFormat((unsigned int)(v8 - 1)) & 0x8000u) == 0LL )
{
v12[0] = 94;
v12[1] = 32;
v9 = UTIL_strerror((unsigned int)a1, v13);
if ( v9 >= 0 )
{
v11 = v9 + 2;
qmemcpy(&v12[(__int16)(v9 + 2)], " - At line ", 11);
v10 = itocstring(&v13[(__int16)(v9 + 2) + 9], **((unsigned int **)&partab + 8));
if ( v10 >= 0 )
{
v11 += v10 + 11;
if ( (SQ_Write(&v11) & 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
char v1; // al
int v2; // ecx
__int64 result; // rax

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

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

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

decompiled_code:
__int64 eval()
{
char v0; // cl
__int64 result; // rax
_BYTE *v2; // rax
char v3; // cl
int v4; // eax
char v5; // bp
_BYTE *v6; // rax
_WORD *v7; // r15
int v8; // er14
_BOOL4 v9; // er13
unsigned __int8 *v10; // rax
unsigned __int8 *v11; // r12
unsigned __int8 v12; // bl
_BYTE *v13; // rax
_BYTE *v14; // rax
unsigned __int8 *v15; // rax
_BYTE *v16; // rax
_BYTE *v17; // rax
_BYTE *v18; // rax

atom();
v0 = *(_BYTE *)source_ptr;
result = 1LL;
if ( *(_BYTE *)source_ptr <= 0x3Au )
result = ((unsigned __int8)(0x400120100000001uLL >> v0) ^ 1) & 1;
if ( v0 != 64 && v0 != 94 && (_BYTE)result )
{
do
{
v4 = operator();
v5 = v4;
if ( !v4 )
return comperror(-212);
if ( v4 == 28 || v4 == 38 )
{
if ( *(_BYTE *)source_ptr != 64 )
{
v6 = (_BYTE *)comp_ptr++;
*v6 = 60;
v7 = (_WORD *)comp_ptr;
comp_ptr += 2LL;
v8 = 1;
v9 = 0;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v11 = (unsigned __int8 *)source_ptr++;
v12 = *v11;
if ( !v9 )
break;
v10 = (unsigned __int8 *)comp_ptr++;
*v10 = v12;
v9 = v12 != 34;
}
if ( v12 != 34 )
break;
v14 = (_BYTE *)comp_ptr++;
*v14 = 34;
v9 = 1;
}
if ( ((*_ctype_b_loc())[v12] & 8) == 0 && v12 != 46 )
break;
v15 = (unsigned __int8 *)comp_ptr++;
*v15 = v12;
}
if ( v12 != 40 )
break;
++v8;
v16 = (_BYTE *)comp_ptr++;
*v16 = 40;
}
if ( v12 != 41 || v8 <= 1 )
break;
--v8;
v17 = (_BYTE *)comp_ptr++;
*v17 = 41;
}
if ( v12 != 44 || v8 <= 1 )
break;
v18 = (_BYTE *)comp_ptr++;
*v18 = 44;
}
source_ptr = (__int64)v11;
*v7 = comp_ptr - ((_WORD)v7 + 2);
v13 = (_BYTE *)comp_ptr++;
*v13 = 0;
goto LABEL_9;
}
++source_ptr;
}
atom();
LABEL_9:
v2 = (_BYTE *)comp_ptr++;
*v2 = v5;
v3 = *(_BYTE *)source_ptr;
result = 1LL;
if ( *(_BYTE *)source_ptr <= 0x3Au )
result = ((unsigned __int8)(0x400120100000001uLL >> v3) ^ 1) & 1;
}
while ( v3 != 94 && (_BYTE)result );
}
return result;
}

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:
__int64 atom()
{
char *v0; // rbp
char v1; // bl
unsigned __int16 v2; // ax
__int64 result; // rax
_BYTE *v4; // rax
_BYTE *v5; // rax
__int16 v6; // ax
_BYTE *v7; // rax
_WORD *v8; // rdi
char v9; // cl
__int64 v10; // 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 dodollar();
if ( (v2 & 0x800) != 0 || v1 == 46 )
{
source_ptr = (__int64)v0;
v5 = (_BYTE *)comp_ptr++;
*v5 = 60;
v6 = ncopy(&source_ptr, comp_ptr + 2);
*(_WORD *)comp_ptr = v6;
result = v6 + 3LL;
comp_ptr += result;
}
else
{
switch ( v1 )
{
case '"':
v7 = (_BYTE *)comp_ptr++;
*v7 = 60;
v8 = (_WORD *)comp_ptr;
result = source_ptr;
v9 = *(_BYTE *)source_ptr;
if ( *(_BYTE *)source_ptr )
{
v10 = 2LL;
while ( v9 != 34 || *(_BYTE *)(result + 1) == 34 )
{
source_ptr = result + 1;
*((_BYTE *)v8 + v10) = *(_BYTE *)result;
if ( *(_BYTE *)(source_ptr - 1) == 34 && *(_BYTE *)source_ptr == 34 )
++source_ptr;
result = source_ptr;
v9 = *(_BYTE *)source_ptr;
++v10;
if ( !*(_BYTE *)source_ptr )
goto LABEL_30;
}
*((_BYTE *)v8 + (int)v10) = 0;
++source_ptr;
*v8 = v10 - 2;
comp_ptr += (int)v10 + 1LL;
}
else
{
LABEL_30:
--comp_ptr;
result = comperror(-212);
}
break;
case '\'':
atom();
result = comp_ptr++;
*(_BYTE *)result = 3;
break;
case '+':
atom();
result = comp_ptr++;
*(_BYTE *)result = 18;
break;
case '-':
atom();
result = comp_ptr++;
*(_BYTE *)result = 19;
break;
default:
if ( v1 != 40 || (eval(), result = source_ptr, ++source_ptr, *(_BYTE *)result != 41) )
result = comperror(-212);
break;
}
}
return result;
}
source_ptr = (__int64)v0;
result = localvar();
if ( (result & 0x8000u) == 0LL )
return result;
return comperror(result);
}
atom();
if ( *(_BYTE *)source_ptr != 64 )
{
result = comp_ptr++;
*(_BYTE *)result = 65;
return result;
}
v4 = (_BYTE *)comp_ptr++;
*v4 = 66;
result = localvar();
if ( (result & 0x8000u) != 0LL )
return comperror(result);
return result;
}

canonical_decompiled_code:
__int64 func3()
{
char *v0; // rbp
char v1; // bl
unsigned __int16 v2; // ax
__int64 result; // rax
_BYTE *v4; // rax
_BYTE *v5; // rax
__int16 v6; // ax
_BYTE *v7; // rax
_WORD *v8; // rdi
char v9; // cl
__int64 v10; // 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 dodollar();
if ( (v2 & 0x800) != 0 || v1 == 46 )
{
source_ptr = (__int64)v0;
v5 = (_BYTE *)comp_ptr++;
*v5 = 60;
v6 = ncopy(&source_ptr, comp_ptr + 2);
*(_WORD *)comp_ptr = v6;
result = v6 + 3LL;
comp_ptr += result;
}
else
{
switch ( v1 )
{
case '"':
v7 = (_BYTE *)comp_ptr++;
*v7 = 60;
v8 = (_WORD *)comp_ptr;
result = source_ptr;
v9 = *(_BYTE *)source_ptr;
if ( *(_BYTE *)source_ptr )
{
v10 = 2LL;
while ( v9 != 34 || *(_BYTE *)(result + 1) == 34 )
{
source_ptr = result + 1;
*((_BYTE *)v8 + v10) = *(_BYTE *)result;
if ( *(_BYTE *)(source_ptr - 1) == 34 && *(_BYTE *)source_ptr == 34 )
++source_ptr;
result = source_ptr;
v9 = *(_BYTE *)source_ptr;
++v10;
if ( !*(_BYTE *)source_ptr )
goto LABEL_30;
}
*((_BYTE *)v8 + (int)v10) = 0;
++source_ptr;
*v8 = v10 - 2;
comp_ptr += (int)v10 + 1LL;
}
else
{
LABEL_30:
--comp_ptr;
result = func0(-212);
}
break;
case '\'':
func3();
result = comp_ptr++;
*(_BYTE *)result = 3;
break;
case '+':
func3();
result = comp_ptr++;
*(_BYTE *)result = 18;
break;
case '-':
func3();
result = comp_ptr++;
*(_BYTE *)result = 19;
break;
default:
if ( v1 != 40 || (func2(), result = source_ptr, ++source_ptr, *(_BYTE *)result != 41) )
result = func0(-212);
break;
}
}
return result;
}
source_ptr = (__int64)v0;
result = localvar();
if ( (result & 0x8000u) == 0LL )
return result;
return func0(result);
}
func3();
if ( *(_BYTE *)source_ptr != 64 )
{
result = comp_ptr++;
*(_BYTE *)result = 65;
return result;
}
v4 = (_BYTE *)comp_ptr++;
*v4 = 66;
result = localvar();
if ( (result & 0x8000u) != 0LL )
return func0(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)
{
unsigned __int8 *v1; // rbx
unsigned __int8 v2; // al
int v3; // eax

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

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
unsigned __int8 v2; // al
int v3; // eax

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

return_type: short


decompiled_code:
__int64 Locate_next()
{
__int64 v0; // rdx
__int64 result; // rax
unsigned __int8 *v2; // rbx
unsigned __int8 v3; // al

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

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rdx
__int64 result; // rax
unsigned __int8 *v2; // rbx
unsigned __int8 v3; // al

++Index;
v0 = *(_QWORD *)(*((_QWORD *)&blk + level) + 12LL);
if ( Index <= *(unsigned __int16 *)(v0 + 8) )
goto LABEL_4;
if ( !*(_DWORD *)(v0 + 4) )
return 4294967289LL;
result = Get_block();
if ( (result & 0x8000u) == 0LL )
{
LABEL_4:
v2 = (unsigned __int8 *)(iidx + 4LL * *(unsigned __int16 *)(idx + 2LL * Index));
chunk = v2;
memmove((char *)&keybuf + v2[2] + 1, v2 + 4, v2[3]);
v3 = v2[3];
keybuf = v2[2] + v3;
record = &v2[v3 + 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; // eax
unsigned int v2; // ebx
char v4[118]; // [rsp+2h] [rbp-76h] 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;
v2 = (__int16)v1;
UTIL_strerror((unsigned int)(__int16)v1, v4);
return fprintf(stderr, "\r\nERROR occured %d\r\n%s\r\n", v2, v4);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int v1; // eax
unsigned int v2; // ebx
char v4[118]; // [rsp+2h] [rbp-76h] 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;
v2 = (__int16)v1;
UTIL_strerror((unsigned int)(__int16)v1, v4);
return fprintf(stderr, "\r\nERROR occured %d\r\n%s\r\n", v2, v4);
}

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);
v2[1] = 17246;
v3 = 0;
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);
v2[1] = 17246;
v3 = 0;
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 v2; // edx
__int64 result; // rax
int v4; // edx
int *v5; // rax

if ( close(a1) == -1
|| (v2 = open(a2, 2049, 0LL), result = 0LL, v2 == -1) && (v4 = unlink(a2), result = 0LL, v4 == -1) )
{
v5 = _errno_location();
result = getError(0LL, (unsigned int)*v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, const char *a2)
{
int v2; // edx
__int64 result; // rax
int v4; // edx
int *v5; // rax

if ( close(a1) == -1
|| (v2 = open(a2, 2049, 0LL), result = 0LL, v2 == -1) && (v4 = unlink(a2), result = 0LL, v4 == -1) )
{
v5 = _errno_location();
result = getError(0LL, (unsigned int)*v5);
}
return result;
}

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:
__int64 __fastcall SQ_Pipe_Write(int a1, const void *a2, int a3)
{
unsigned int v3; // edx
__int64 v4; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func1(int a1, const void *a2, int a3)
{
unsigned int v3; // edx
__int64 v4; // rsi

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

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; // ebx
int v6; // eax
int *v7; // rax
__int64 v8; // 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 = _errno_location();
v5 = getError(0LL, (unsigned int)*v7);
}
else
{
v5 = -1;
}
return (unsigned int)v5;
}
v8 = (unsigned int)*_errno_location();
if ( (_DWORD)v8 != 11 )
return (unsigned int)getError(0LL, v8);
sleep(1u);
}
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf, unsigned int a3)
{
int v5; // ebx
int v6; // eax
int *v7; // rax
__int64 v8; // 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 = _errno_location();
v5 = getError(0LL, (unsigned int)*v7);
}
else
{
v5 = -1;
}
return (unsigned int)v5;
}
v8 = (unsigned int)*_errno_location();
if ( (_DWORD)v8 != 11 )
return (unsigned int)getError(0LL, v8);
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; // esi
int *v4; // rax

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

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

if ( a2 == 9 )
{
v3 = 1;
LABEL_7:
result = open(file, v3, 0LL);
if ( result == -1 )
{
v4 = _errno_location();
result = getError(0LL, (unsigned int)*v4);
}
return result;
}
if ( a2 != 10 )
return getError(1LL, 21LL);
result = func3(file);
v3 = 2048;
if ( result >= 0 )
goto LABEL_7;
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


cstringtoi

original_code:
int cstringtoi(cstring *str)
{ int ret = 0;
  int i;
  int minus = 0;
  for (i=0; (i < (int)str->len)&&
            ((str->buf[i] == '-') ||
             (str->buf[i] == '+')); i++)
    if (str->buf[i] == '-') minus = !minus;
  for (i = i; i < (int)str->len; i++)
  { if ((str->buf[i] > '9')||(str->buf[i] < '0')) break;
    if (ret > 214748363) return 0x7fffffff;
    ret = (ret * 10) + ((int)str->buf[i] - 48);
  }
  if ((systab->historic & 1)
     && (i < (str->len - 1)) && (str->buf[i] == 'E'))
  { int exp = 0;
    int expsgn = 1;
    int j = 10;
    i++;
    if (str->buf[i] == '-')
    { expsgn = -1;
      i++;
    }
    else if (str->buf[i] == '+')
    { i++;
    }
    for (i = i; i < str->len; i++)
    { if ((str->buf[i] < '0') || (str->buf[i] > '9'))
      { break;
      }
      exp = (exp * 10) + (str->buf[i] - '0');
    }
    if (exp)
    { while (exp > 1)
      { j = j * 10;
        exp--;
      }
      if (expsgn > 0)
      { ret = ret * j;
      }
      else
      { ret = ret / j;
      }
    }
  }
  if (minus) ret = -ret;
  return ret;
}

canonical_original_code:
int cstringtoi(struct CSTRING *str)
{ int ret = 0;
  int i;
  int minus = 0;
  for (i=0; (i < (int)str->len)&&
            ((str->buf[i] == '-') ||
             (str->buf[i] == '+')); i++)
    if (str->buf[i] == '-') minus = !minus;
  for (i = i; i < (int)str->len; i++)
  { if ((str->buf[i] > '9')||(str->buf[i] < '0')) break;
    if (ret > 214748363) return 0x7fffffff;
    ret = (ret * 10) + ((int)str->buf[i] - 48);
  }
  if ((systab->historic & 1)
     && (i < (str->len - 1)) && (str->buf[i] == 'E'))
  { int exp = 0;
    int expsgn = 1;
    int j = 10;
    i++;
    if (str->buf[i] == '-')
    { expsgn = -1;
      i++;
    }
    else if (str->buf[i] == '+')
    { i++;
    }
    for (i = i; i < str->len; i++)
    { if ((str->buf[i] < '0') || (str->buf[i] > '9'))
      { break;
      }
      exp = (exp * 10) + (str->buf[i] - '0');
    }
    if (exp)
    { while (exp > 1)
      { j = j * 10;
        exp--;
      }
      if (expsgn > 0)
      { ret = ret * j;
      }
      else
      { ret = ret / j;
      }
    }
  }
  if (minus) ret = -ret;
  return ret;
}

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

variable_types: i int

variable_types: minus int

variable_types: exp int

variable_types: expsgn int

variable_types: j int


cstringtob

decompiled_code:
__int64 __fastcall cstringtob(__int16 *a1)
{
int v1; // esi
__int64 result; // rax
char *v3; // rdx
__int64 v4; // r8
int v5; // ecx
char v6; // al

v1 = *a1;
result = 0LL;
if ( v1 > 0 )
{
while ( ((*((_BYTE *)a1 + result + 2) - 43) & 0xFD) == 0 )
{
if ( v1 <= (int)++result )
return 0LL;
}
if ( v1 > (int)result )
{
v3 = (char *)a1 + (int)result + 2;
v4 = (__int64)a1 + (int)result + (unsigned int)(*a1 - 1 - result) + 3;
v5 = 0;
while ( 1 )
{
v6 = *v3;
if ( *v3 != 48 )
{
if ( v6 != 46 )
return (unsigned __int8)(v6 - 49) <= 8u;
if ( v5 )
return 0LL;
v5 = 1;
}
if ( ++v3 == (char *)v4 )
return 0LL;
}
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 *a1)
{
int v1; // esi
__int64 result; // rax
char *v3; // rdx
__int64 v4; // r8
int v5; // ecx
char v6; // al

v1 = *a1;
result = 0LL;
if ( v1 > 0 )
{
while ( ((*((_BYTE *)a1 + result + 2) - 43) & 0xFD) == 0 )
{
if ( v1 <= (int)++result )
return 0LL;
}
if ( v1 > (int)result )
{
v3 = (char *)a1 + (int)result + 2;
v4 = (__int64)a1 + (int)result + (unsigned int)(*a1 - 1 - result) + 3;
v5 = 0;
while ( 1 )
{
v6 = *v3;
if ( *v3 != 48 )
{
if ( v6 != 46 )
return (unsigned __int8)(v6 - 49) <= 8u;
if ( v5 )
return 0LL;
v5 = 1;
}
if ( ++v3 == (char *)v4 )
return 0LL;
}
}
result = 0LL;
}
return result;
}

original_code:
int cstringtob(cstring *str)
{ int ret = 0;
  int i;
  int dp = 0;
  for (i=0; (i < (int)str->len)&&
            ((str->buf[i] == '-') ||
            (str->buf[i] == '+')); i++);
  for (i = i; i < (int)str->len; i++)
  { if (str->buf[i] == '0') continue;
    if (str->buf[i] == '.')
    { if (dp) break;
      dp = 1;
      continue;
    }
    if ((str->buf[i] >= '1') &&
        (str->buf[i] <= '9'))
      ret = 1;
    break;
  }
  return ret;
}

canonical_original_code:
int cstringtob(struct CSTRING *str)
{ int ret = 0;
  int i;
  int dp = 0;
  for (i=0; (i < (int)str->len)&&
            ((str->buf[i] == '-') ||
            (str->buf[i] == '+')); i++);
  for (i = i; i < (int)str->len; i++)
  { if (str->buf[i] == '0') continue;
    if (str->buf[i] == '.')
    { if (dp) break;
      dp = 1;
      continue;
    }
    if ((str->buf[i] >= '1') &&
        (str->buf[i] <= '9'))
      ret = 1;
    break;
  }
  return ret;
}

variable_types: dp int


itocstring

decompiled_code:
__int64 __fastcall itocstring(_BYTE *a1, int a2)
{
__int64 result; // rax
__int64 v4; // rcx
int v5; // er9
int *v6; // rsi
_BYTE *v7; // rdx
__int64 v8; // rdi
int v9; // [rsp+0h] [rbp-34h]
int v10[12]; // [rsp+4h] [rbp-30h] BYREF

v10[0] = 0;
if ( a2 < 0 )
{
*a1 = 45;
a2 = -a2;
result = 1LL;
}
else
{
result = 0LL;
if ( !a2 )
{
LABEL_12:
*a1 = 48;
result = 1LL;
goto LABEL_10;
}
}
v4 = 1LL;
do
{
v5 = v4;
*(&v9 + v4) = a2 % 10;
a2 /= 10;
++v4;
}
while ( a2 );
if ( v5 )
{
v6 = &v10[v5];
v7 = &a1[(int)result];
v8 = (__int64)&v7[v5 - 1 + 1];
do
*v7++ = *((_BYTE *)v6-- - 4) + 48;
while ( v7 != (_BYTE *)v8 );
result = (unsigned int)(v5 + result);
}
if ( !(_DWORD)result )
goto LABEL_12;
LABEL_10:
a1[(int)result] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, int a2)
{
__int64 result; // rax
__int64 v4; // rcx
int v5; // er9
int *v6; // rsi
_BYTE *v7; // rdx
__int64 v8; // rdi
int v9; // [rsp+0h] [rbp-34h]
int v10[12]; // [rsp+4h] [rbp-30h] BYREF

v10[0] = 0;
if ( a2 < 0 )
{
*a1 = 45;
a2 = -a2;
result = 1LL;
}
else
{
result = 0LL;
if ( !a2 )
{
LABEL_12:
*a1 = 48;
result = 1LL;
goto LABEL_10;
}
}
v4 = 1LL;
do
{
v5 = v4;
*(&v9 + v4) = a2 % 10;
a2 /= 10;
++v4;
}
while ( a2 );
if ( v5 )
{
v6 = &v10[v5];
v7 = &a1[(int)result];
v8 = (__int64)&v7[v5 - 1 + 1];
do
*v7++ = *((_BYTE *)v6-- - 4) + 48;
while ( v7 != (_BYTE *)v8 );
result = (unsigned int)(v5 + result);
}
if ( !(_DWORD)result )
goto LABEL_12;
LABEL_10:
a1[(int)result] = 0;
return result;
}

canonical_original_code:
short itocstring(unsigned char *buf, int n)
{ int i = 0;
  int p = 0;
  int a[12];
  a[0] = 0;
  if (n < 0)
  { buf[p++] = '-';
    n = -n;
  }
  while (n)
  { a[i++] = n % 10;
    n = n/10;
  }
  while (i) buf[p++] = a[--i] + 48;
  if (!p) buf[p++] = '0';
  buf[p] = '\0';
  return (short) p;
}

variable_types:
buf
unsigned char *

variable_types: n int

variable_types: p int

variable_types:
a
int [12]


uitocstring

decompiled_code:
__int64 __fastcall uitocstring(_BYTE *a1, unsigned int a2)
{
__int64 v3; // rcx
__int64 result; // rax
unsigned int v5; // edi
int *v6; // rsi
_BYTE *v7; // rdx
int v8; // [rsp+0h] [rbp-34h]
int v9[12]; // [rsp+4h] [rbp-30h] BYREF

v9[0] = 0;
if ( !a2 )
goto LABEL_8;
v3 = 1LL;
do
{
result = (unsigned int)v3;
*(&v8 + v3) = a2 % 0xA;
v5 = a2;
a2 /= 0xAu;
++v3;
}
while ( v5 > 9 );
if ( (_DWORD)result )
{
v6 = &v9[(int)result];
v7 = a1;
do
*v7++ = *((_BYTE *)v6-- - 4) + 48;
while ( v7 != &a1[(unsigned int)(result - 1) + 1] );
}
else
{
LABEL_8:
*a1 = 48;
result = 1LL;
}
a1[(int)result] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1, unsigned int a2)
{
__int64 v3; // rcx
__int64 result; // rax
unsigned int v5; // edi
int *v6; // rsi
_BYTE *v7; // rdx
int v8; // [rsp+0h] [rbp-34h]
int v9[12]; // [rsp+4h] [rbp-30h] BYREF

v9[0] = 0;
if ( !a2 )
goto LABEL_8;
v3 = 1LL;
do
{
result = (unsigned int)v3;
*(&v8 + v3) = a2 % 0xA;
v5 = a2;
a2 /= 0xAu;
++v3;
}
while ( v5 > 9 );
if ( (_DWORD)result )
{
v6 = &v9[(int)result];
v7 = a1;
do
*v7++ = *((_BYTE *)v6-- - 4) + 48;
while ( v7 != &a1[(unsigned int)(result - 1) + 1] );
}
else
{
LABEL_8:
*a1 = 48;
result = 1LL;
}
a1[(int)result] = 0;
return result;
}

original_code:
short uitocstring(u_char *buf, u_int n)
{ int i = 0;
  int p = 0;
  int a[12];
  a[0] = 0;
  while (n)
  { a[i++] = n % 10;
    n = n/10;
  }
  while (i) buf[p++] = a[--i] + 48;
  if (!p) buf[p++] = '0';
  buf[p] = '\0';
  return (short) p;
}

canonical_original_code:
short uitocstring(unsigned char *buf, unsigned int n)
{ int i = 0;
  int p = 0;
  int a[12];
  a[0] = 0;
  while (n)
  { a[i++] = n % 10;
    n = n/10;
  }
  while (i) buf[p++] = a[--i] + 48;
  if (!p) buf[p++] = '0';
  buf[p] = '\0';
  return (short) p;
}

variable_types:
n
unsigned int


getvol

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

v1 = *a1;
if ( *a1 < 8 )
v1 = *a1 + 1;
v2 = **(_QWORD **)(systab + 228LL);
if ( v2 )
result = memcmp((const void *)(v2 + 16), a1 + 1, v1) == 0 ? 1 : -26;
else
result = 4294967270LL;
return result;
}

original_code:
short getvol(cstring *vol)
{ int i;
  short s;
  s = vol->len;
  if (s < 8) s++;
  for (i = 0; i < 1; i++)
  { if (systab->vol[i]->vollab == ((void *)0)) continue;
    if (bcmp(&systab->vol[i]->vollab->volnam.var_cu[0],
      vol->buf, s) != 0) continue;
    return (short) i + 1;
  }
  return (-26);
}

canonical_original_code:
short getvol(struct CSTRING *vol)
{ int i;
  short s;
  s = vol->len;
  if (s < 8) s++;
  for (i = 0; i < 1; i++)
  { if (systab->vol[i]->vollab == ((void *)0)) continue;
    if (bcmp(&systab->vol[i]->vollab->volnam.var_cu[0],
      vol->buf, s) != 0) continue;
    return (short) i + 1;
  }
  return (-26);
}

variable_types: s short


getuci

original_code:
short getuci(cstring *uci, int vol)
{ int i;
  short s;
  s = uci->len;
  if (s < 8) s++;
  if (vol == 0) vol = partab.jobtab->vol;
  vol--;
  for (i = 0; i < 64; i++)
  { if (bcmp(&systab->vol[vol]->vollab->uci[i].name.var_cu[0],
      uci->buf, s) == 0) return (short) i + 1;
  }
  return (-26);
}

canonical_original_code:
short getuci(struct CSTRING *uci, int vol)
{ int i;
  short s;
  s = uci->len;
  if (s < 8) s++;
  if (vol == 0) vol = partab.jobtab->vol;
  vol--;
  for (i = 0; i < 64; i++)
  { if (bcmp(&systab->vol[vol]->vollab->uci[i].name.var_cu[0],
      uci->buf, s) == 0) return (short) i + 1;
  }
  return (-26);
}

variable_types: vol int