decompiled_code:
__int64 lock_daemon()
{
int v0; // ebp
int v1; // ebx
unsigned int v2; // eax
size_t v3; // rax
int v5; // eax
int v6; // ebx
__int64 v7; // r12
__int64 v8[13]; // [rsp+0h] [rbp-68h] BYREF

v0 = 2;
while ( 1 )
{
v1 = open("/var/tmp/lock.falcon", 706, 432LL);
if ( v1 >= 0 )
{
v2 = getpid();
sprintf((char *)v8, "%d\n", v2);
v3 = strlen((const char *)v8);
write(v1, v8, v3);
LABEL_4:
close(v1);
return 1LL;
}
v5 = open("/var/tmp/lock.falcon", 0);
v6 = v5;
if ( v5 < 0 )
break;
v8[0] = 0LL;
v8[1] = 0LL;
v8[2] = 0LL;
v8[3] = 0LL;
v8[4] = 0LL;
v8[5] = 0LL;
v8[6] = 0LL;
v8[7] = 0LL;
v8[8] = 0LL;
v8[9] = 0LL;
read(v5, v8, 0x4FuLL);
close(v6);
v7 = (unsigned int)atoi((const char *)v8);
sprintf((char *)v8, "/proc/%d/cmdline", v7);
v1 = open((const char *)v8, 0);
if ( v1 >= 0 )
{
syslog(6, "%s daemon pid %d already running\n", "falcon", (unsigned int)v7);
close(v1);
return 0LL;
}
unlink("/var/tmp/lock.falcon");
syslog(6, "Ignoring defunct lockfile %s\n", "/var/tmp/lock.falcon");
if ( !--v0 )
goto LABEL_4;
}
syslog(3, "Unable to read existing lock file %s\n", "/var/tmp/lock.falcon");
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // ebp
int v1; // ebx
unsigned int v2; // eax
size_t v3; // rax
int v5; // eax
int v6; // ebx
__int64 v7; // r12
__int64 v8[13]; // [rsp+0h] [rbp-68h] BYREF

v0 = 2;
while ( 1 )
{
v1 = open("/var/tmp/lock.falcon", 706, 432LL);
if ( v1 >= 0 )
{
v2 = getpid();
sprintf((char *)v8, "%d\n", v2);
v3 = strlen((const char *)v8);
write(v1, v8, v3);
LABEL_4:
close(v1);
return 1LL;
}
v5 = open("/var/tmp/lock.falcon", 0);
v6 = v5;
if ( v5 < 0 )
break;
v8[0] = 0LL;
v8[1] = 0LL;
v8[2] = 0LL;
v8[3] = 0LL;
v8[4] = 0LL;
v8[5] = 0LL;
v8[6] = 0LL;
v8[7] = 0LL;
v8[8] = 0LL;
v8[9] = 0LL;
read(v5, v8, 0x4FuLL);
close(v6);
v7 = (unsigned int)atoi((const char *)v8);
sprintf((char *)v8, "/proc/%d/cmdline", v7);
v1 = open((const char *)v8, 0);
if ( v1 >= 0 )
{
syslog(6, "%s daemon pid %d already running\n", "falcon", (unsigned int)v7);
close(v1);
return 0LL;
}
unlink("/var/tmp/lock.falcon");
syslog(6, "Ignoring defunct lockfile %s\n", "/var/tmp/lock.falcon");
if ( !--v0 )
goto LABEL_4;
}
syslog(3, "Unable to read existing lock file %s\n", "/var/tmp/lock.falcon");
return 0LL;
}

original_code:
static int lock_daemon()
{
    int lfp=-1;
    int lpid = 0;
    int iTry = 0;
    char pidstr[80];
    int readcnt;
    while (lfp < 0 && iTry++ < 2)
    {
        if ( lockfile && lockfile[0] )
        {
            lfp = open(lockfile,02|0100|0200|01000,0660);
            if ( lfp < 0 )
            {
                lfp = open(lockfile,00);
                if (lfp < 0)
                {
                    syslog(3, "Unable to read existing lock file %s\n",
                         lockfile);
                    return 0;
                }
                memset(pidstr, 0, sizeof(pidstr));
                readcnt = read(lfp, pidstr, sizeof(pidstr)-1);
                close(lfp);
                lfp = -1;
                lpid = atoi(pidstr);
                sprintf(pidstr, "/proc/%d/cmdline", lpid);
                lfp = open(pidstr,00);
                if (lfp < 0)
                {
                  unlink(lockfile);
                  syslog(6, "Ignoring defunct lockfile %s\n", lockfile);
                  continue;
                }
                else
                {
                  syslog(6, "%s daemon pid %d already running\n",
                         "falcon", lpid);
                  close(lfp);
                  return 0;
                }
            }
            else
            {
              sprintf(pidstr, "%d\n", getpid());
              write(lfp, pidstr, strlen(pidstr));
            }
        }
        else
        {
            return 1;
        }
    }
    close(lfp);
    return 1;
}

canonical_original_code:
static int lock_daemon()
{
    int lfp = -1;
    int lpid = 0;
    int iTry = 0;
    char pidstr[80];
    int readcnt;
    while (lfp < 0 && iTry++ < 2)
    {
        if ( lockfile && lockfile[0] )
        {
            lfp = open(lockfile,02|0100|0200|01000,0660);
            if ( lfp < 0 )
            {
                lfp = open(lockfile,00);
                if (lfp < 0)
                {
                    syslog(3, "Unable to read existing lock file %s\n",
                         lockfile);
                    return 0;
                }
                memset(pidstr, 0, sizeof(pidstr));
                readcnt = read(lfp, pidstr, sizeof(pidstr)-1);
                close(lfp);
                lfp = -1;
                lpid = atoi(pidstr);
                sprintf(pidstr, "/proc/%d/cmdline", lpid);
                lfp = open(pidstr,00);
                if (lfp < 0)
                {
                  unlink(lockfile);
                  syslog(6, "Ignoring defunct lockfile %s\n", lockfile);
                  continue;
                }
                else
                {
                  syslog(6, "%s daemon pid %d already running\n",
                         "falcon", lpid);
                  close(lfp);
                  return 0;
                }
            }
            else
            {
              sprintf(pidstr, "%d\n", getpid());
              write(lfp, pidstr, strlen(pidstr));
            }
        }
        else
        {
            return 1;
        }
    }
    close(lfp);
    return 1;
}

variable_types: lfp int

variable_types: lpid int

variable_types: iTry int

variable_types:
pidstr
char [80]

variable_types: readcnt int

return_type: int


repo: joeledwards/asl-station-processor

decompiled_code:
void __fastcall child_handler(int a1)
{
if ( a1 == 10 )
exit(0);
if ( a1 > 9 )
{
if ( a1 == 14 )
exit(1);
if ( a1 == 17 )
exit(1);
}
}

original_code:
static void child_handler(int signum)
{
    switch(signum) {
    case 14: exit(1); break;
    case 10: exit(0); break;
    case 17: exit(1); break;
    }
}

variable_types: signum int

return_type: void


decompiled_code:
void __noreturn sigterm_handler()
{
syslog(6, "Exiting daemon falcon");
unlink("/var/tmp/lock.falcon");
closelog();
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
syslog(6, "Exiting daemon falcon");
unlink("/var/tmp/lock.falcon");
closelog();
exit(0);
}

original_code:
static void sigterm_handler()
{
  syslog(6, "Exiting daemon " "falcon");
  unlink (lockfile);
  closelog();
  exit(0);
}


daemonize

decompiled_code:
__pid_t daemonize()
{
__pid_t result; // eax
struct passwd *v1; // rbx
__pid_t v2; // eax
__pid_t v3; // ebx
int *v4; // rbx
char *v5; // rax
int *v6; // rbx
char *v7; // rax
int *v8; // rbx
char *v9; // rax

openlog("falcon", 1, 168);
syslog(6, "Starting daemon");
result = getppid();
if ( result != 1 )
{
if ( !getuid() || !geteuid() )
{
v1 = getpwnam("maint");
if ( v1 )
{
syslog(5, "setting user to maint");
setuid(v1->pw_uid);
}
}
signal(17, child_handler);
signal(10, child_handler);
signal(14, child_handler);
v2 = fork();
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
syslog(3, "unable to fork daemon, code=%d (%s)", (unsigned int)*v4, v5);
exit(1);
}
if ( v2 > 0 )
{
alarm(2u);
pause();
exit(1);
}
if ( !(unsigned int)lock_daemon() )
{
syslog(3, "Another %s daemon is already running, aborting!\n", "falcon");
exit(1);
}
syslog(6, "daemon running");
v3 = getppid();
signal(17, 0LL);
signal(20, (void (*)(int))((char *)child_handler + 1));
signal(22, (void (*)(int))((char *)child_handler + 1));
signal(21, (void (*)(int))((char *)child_handler + 1));
signal(1, (void (*)(int))((char *)child_handler + 1));
signal(15, (__sighandler_t)sigterm_handler);
umask(0);
if ( setsid() < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
syslog(3, "unable to create a new session, code %d (%s)", (unsigned int)*v6, v7);
exit(1);
}
if ( chdir("/etc/q330") < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
syslog(3, "unable to change directory to %s, code %d (%s)", "/etc/q330", (unsigned int)*v8, v9);
exit(1);
}
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
freopen("/var/tmp/falcon", "w", stderr);
chmod("/var/tmp/falcon", 0x1B0u);
result = kill(v3, 10);
}
return result;
}

canonical_decompiled_code:
__pid_t func3()
{
__pid_t result; // eax
struct passwd *v1; // rbx
__pid_t v2; // eax
__pid_t v3; // ebx
int *v4; // rbx
char *v5; // rax
int *v6; // rbx
char *v7; // rax
int *v8; // rbx
char *v9; // rax

openlog("falcon", 1, 168);
syslog(6, "Starting daemon");
result = getppid();
if ( result != 1 )
{
if ( !getuid() || !geteuid() )
{
v1 = getpwnam("maint");
if ( v1 )
{
syslog(5, "setting user to maint");
setuid(v1->pw_uid);
}
}
signal(17, child_handler);
signal(10, child_handler);
signal(14, child_handler);
v2 = fork();
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
syslog(3, "unable to fork daemon, code=%d (%s)", (unsigned int)*v4, v5);
exit(1);
}
if ( v2 > 0 )
{
alarm(2u);
pause();
exit(1);
}
if ( !(unsigned int)func2() )
{
syslog(3, "Another %s daemon is already running, aborting!\n", "falcon");
exit(1);
}
syslog(6, "daemon running");
v3 = getppid();
signal(17, 0LL);
signal(20, (void (*)(int))((char *)child_handler + 1));
signal(22, (void (*)(int))((char *)child_handler + 1));
signal(21, (void (*)(int))((char *)child_handler + 1));
signal(1, (void (*)(int))((char *)child_handler + 1));
signal(15, (__sighandler_t)sigterm_handler);
umask(0);
if ( setsid() < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
syslog(3, "unable to create a new session, code %d (%s)", (unsigned int)*v6, v7);
exit(1);
}
if ( chdir("/etc/q330") < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
syslog(3, "unable to change directory to %s, code %d (%s)", "/etc/q330", (unsigned int)*v8, v9);
exit(1);
}
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
freopen("/var/tmp/falcon", "w", stderr);
chmod("/var/tmp/falcon", 0x1B0u);
result = kill(v3, 10);
}
return result;
}

original_code:
void daemonize()
{
    pid_t pid, sid, parent;
    openlog("falcon", 0x01, (21<<3));
    syslog(6, "Starting daemon");
    if ( getppid() == 1 ) return;
    if ( getuid() == 0 || geteuid() == 0 ) {
        struct passwd *pw = getpwnam("maint");
        if ( pw ) {
            syslog( 5, "setting user to " "maint" );
            setuid( pw->pw_uid );
        }
    }
    signal(17,child_handler);
    signal(10,child_handler);
    signal(14,child_handler);
    pid = fork();
    if (pid < 0) {
        syslog( 3, "unable to fork daemon, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit(1);
    }
    if (pid > 0) {
        alarm(2);
        pause();
        exit(1);
    }
    if (!lock_daemon())
    {
        syslog(3, "Another %s daemon is already running, aborting!\n",
               "falcon");
        exit(1);
    }
    syslog(6, "daemon running");
    parent = getppid();
    signal(17,((__sighandler_t) 0));
    signal(20,((__sighandler_t) 1));
    signal(22,((__sighandler_t) 1));
    signal(21,((__sighandler_t) 1));
    signal(1, ((__sighandler_t) 1));
    signal(15,sigterm_handler);
    umask(0);
    sid = setsid();
    if (sid < 0) {
        syslog( 3, "unable to create a new session, code %d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit(1);
    }
    if ((chdir("/etc/q330")) < 0) {
        syslog( 3, "unable to change directory to %s, code %d (%s)",
                "/etc/q330", (*__errno_location ()), strerror((*__errno_location ())) );
        exit(1);
    }
    freopen( "/dev/null", "r", stdin);
    freopen( "/dev/null", "w", stdout);
    freopen( "/var/tmp/" "falcon", "w", stderr);
    chmod( "/var/tmp/" "falcon", 0660);
    kill( parent, 10 );
}

canonical_original_code:
void daemonize()
{
    int pid; int sid; int parent;
    openlog("falcon", 0x01, (21<<3));
    syslog(6, "Starting daemon");
    if ( getppid() == 1 ) return;
    if ( getuid() == 0 || geteuid() == 0 ) {
        struct passwd *pw = getpwnam("maint");
        if ( pw ) {
            syslog( 5, "setting user to " "maint" );
            setuid( pw->pw_uid );
        }
    }
    signal(17,child_handler);
    signal(10,child_handler);
    signal(14,child_handler);
    pid = fork();
    if (pid < 0) {
        syslog( 3, "unable to fork daemon, code=%d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit(1);
    }
    if (pid > 0) {
        alarm(2);
        pause();
        exit(1);
    }
    if (!lock_daemon())
    {
        syslog(3, "Another %s daemon is already running, aborting!\n",
               "falcon");
        exit(1);
    }
    syslog(6, "daemon running");
    parent = getppid();
    signal(17,((void (*)(int)) 0));
    signal(20,((void (*)(int)) 1));
    signal(22,((void (*)(int)) 1));
    signal(21,((void (*)(int)) 1));
    signal(1, ((void (*)(int)) 1));
    signal(15,sigterm_handler);
    umask(0);
    sid = setsid();
    if (sid < 0) {
        syslog( 3, "unable to create a new session, code %d (%s)",
                (*__errno_location ()), strerror((*__errno_location ())) );
        exit(1);
    }
    if ((chdir("/etc/q330")) < 0) {
        syslog( 3, "unable to change directory to %s, code %d (%s)",
                "/etc/q330", (*__errno_location ()), strerror((*__errno_location ())) );
        exit(1);
    }
    freopen( "/dev/null", "r", stdin);
    freopen( "/dev/null", "w", stdout);
    freopen( "/var/tmp/" "falcon", "w", stderr);
    chmod( "/var/tmp/" "falcon", 0660);
    kill( parent, 10 );
}

variable_types: pid int

variable_types: sid int

variable_types: parent int

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
__int64 q330Close()
{
if ( iSocket >= 0 )
close(iSocket);
iSocket = -1;
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
if ( iSocket >= 0 )
close(iSocket);
iSocket = -1;
return 0LL;
}

original_code:
char *q330Close()
{
  if (iSocket >= 0)
    close(iSocket);
  iSocket = -1;
  return ((void *)0);
}

return_type: char *


decompiled_code:
__int64 __fastcall set_options(unsigned int a1, char *a2)
{
char v2; // dl
char *v3; // rbx
unsigned int v4; // ebp

v2 = *a2;
if ( !*a2 )
return a1;
v3 = a2 + 1;
v4 = a1;
do
{
switch ( v2 )
{
case '-':
break;
case 'A':
default_opts |= 8u;
break;
case 'M':
default_opts |= 0x80u;
break;
case 'N':
v4 |= 0x10u;
goto LABEL_7;
case 'P':
default_opts |= 0x20u;
break;
case 'Q':
default_opts |= 4u;
break;
case 'R':
default_opts |= 1u;
break;
case 'V':
default_opts |= 2u;
break;
case 'Z':
default_opts |= 0x40u;
break;
case 'a':
v4 |= 8u;
break;
case 'd':
debug_enabled = debug_enabled == 0;
break;
case 'm':
v4 |= 0xFFFFFF80;
break;
case 'n':
v4 |= 0x10u;
break;
case 'p':
v4 |= 0x20u;
break;
case 'q':
v4 |= 4u;
break;
case 'r':
v4 |= 1u;
break;
case 'v':
LABEL_7:
v4 |= 2u;
break;
case 'z':
v4 |= 0x40u;
break;
default:
report(1LL, "unknown option `%c', ignoring", (unsigned int)v2);
break;
}
v2 = *v3++;
}
while ( v2 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, char *a2)
{
char v2; // dl
char *v3; // rbx
unsigned int v4; // ebp

v2 = *a2;
if ( !*a2 )
return a1;
v3 = a2 + 1;
v4 = a1;
do
{
switch ( v2 )
{
case '-':
break;
case 'A':
default_opts |= 8u;
break;
case 'M':
default_opts |= 0x80u;
break;
case 'N':
v4 |= 0x10u;
goto LABEL_7;
case 'P':
default_opts |= 0x20u;
break;
case 'Q':
default_opts |= 4u;
break;
case 'R':
default_opts |= 1u;
break;
case 'V':
default_opts |= 2u;
break;
case 'Z':
default_opts |= 0x40u;
break;
case 'a':
v4 |= 8u;
break;
case 'd':
debug_enabled = debug_enabled == 0;
break;
case 'm':
v4 |= 0xFFFFFF80;
break;
case 'n':
v4 |= 0x10u;
break;
case 'p':
v4 |= 0x20u;
break;
case 'q':
v4 |= 4u;
break;
case 'r':
v4 |= 1u;
break;
case 'v':
LABEL_7:
v4 |= 2u;
break;
case 'z':
v4 |= 0x40u;
break;
default:
report(1LL, "unknown option `%c', ignoring", (unsigned int)v2);
break;
}
v2 = *v3++;
}
while ( v2 );
return v4;
}

original_code:
unsigned char
set_options(unsigned char opts, char *optstring)
{
        int i;
        for(i = 0; optstring[i]; i++) {
                switch (optstring[i]) {
                case '-':
                        break;
                case 'r':
                        opts |= (1 << 0);
                        break;
                case 'R':
                        default_opts |= (1 << 0);
                        break;
                case 'n':
                        opts |= (1 << 4);
                        break;
                case 'N':
                        opts |= (1 << 4);
                case 'v':
                        opts |= (1 << 1);
                        break;
                case 'V':
                        default_opts |= (1 << 1);
                        break;
                case 'z':
                        opts |= (1 << 6);
                        break;
                case 'Z':
                        default_opts |= (1 << 6);
                        break;
                case 'm':
                        opts |= (1 << 7);
                        break;
                case 'M':
                        default_opts |= (1 << 7);
                        break;
                case 'a':
                        opts |= (1 << 3);
                        break;
                case 'A':
                        default_opts |= (1 << 3);
                        break;
                case 'q':
                        opts |= (1 << 2);
                        break;
                case 'Q':
                        default_opts |= (1 << 2);
                        break;
                case 'p':
                        opts |= (1 << 5);
                        break;
                case 'P':
                        default_opts |= (1 << 5);
                        break;
                case 'd':
                        debug_enabled = !debug_enabled;
                        break;
                default:
                        report(WARN, "unknown option `%c', ignoring", optstring[i]);
                }
        }
        return opts;
}

variable_types:
opts
unsigned char

variable_types:
optstring
char *

variable_types: i int

return_type: unsigned char


original_code:
VOID timenormd2(long *day, long *hour, long *minute, long *second, long *tenth_msec)
{
  long tl;
  if (abs(*tenth_msec) > 9999) {
    tl = *tenth_msec / 10000;
    *second += tl;
    *tenth_msec %= 10000;
  }
  while (*tenth_msec < 0) {
    *tenth_msec += 10000;
    (*second)--;
  }
  while (*tenth_msec > 9999) {
    *tenth_msec -= 10000;
    (*second)++;
  }
  if (abs(*second) > 59) {
    tl = *second / 60;
    *minute += tl;
    *second %= 60;
  }
  while (*second < 0) {
    *second += 60;
    (*minute)--;
  }
  while (*second > 59) {
    *second -= 60;
    (*minute)++;
  }
  if (abs(*minute) > 59) {
    tl = *minute / 60;
    *hour += tl;
    *minute %= 60;
  }
  while (*minute < 0) {
    *minute += 60;
    (*hour)--;
  }
  while (*minute > 59) {
    *minute -= 60;
    (*hour)++;
  }
  if (abs(*hour) > 23) {
    tl = *hour / 24;
    *day += tl;
    *hour %= 24;
  }
  while (*hour < 0) {
    *hour += 24;
    (*day)--;
  }
  while (*hour > 23) {
    *hour -= 24;
    (*day)++;
  }
  return;
}

canonical_original_code:
void timenormd2(long *day, long *hour, long *minute, long *second, long *tenth_msec)
{
  long tl;
  if (abs(*tenth_msec) > 9999) {
    tl = *tenth_msec / 10000;
    *second += tl;
    *tenth_msec %= 10000;
  }
  while (*tenth_msec < 0) {
    *tenth_msec += 10000;
    (*second)--;
  }
  while (*tenth_msec > 9999) {
    *tenth_msec -= 10000;
    (*second)++;
  }
  if (abs(*second) > 59) {
    tl = *second / 60;
    *minute += tl;
    *second %= 60;
  }
  while (*second < 0) {
    *second += 60;
    (*minute)--;
  }
  while (*second > 59) {
    *second -= 60;
    (*minute)++;
  }
  if (abs(*minute) > 59) {
    tl = *minute / 60;
    *hour += tl;
    *minute %= 60;
  }
  while (*minute < 0) {
    *minute += 60;
    (*hour)--;
  }
  while (*minute > 59) {
    *minute -= 60;
    (*hour)++;
  }
  if (abs(*hour) > 23) {
    tl = *hour / 24;
    *day += tl;
    *hour %= 24;
  }
  while (*hour < 0) {
    *hour += 24;
    (*day)--;
  }
  while (*hour > 23) {
    *hour -= 24;
    (*day)++;
  }
  return;
}

variable_types:
day
long *

variable_types:
hour
long *

variable_types:
minute
long *

variable_types:
second
long *

variable_types: tl long


decompiled_code:
__int64 ms_log(int a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return ms_log_main((__int64)&gMSLogParam, a1, (int *)va);
}

canonical_decompiled_code:
__int64 func1(int a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func0((__int64)&gMSLogParam, a1, (int *)va);
}

original_code:
int
ms_log (int level, ...)
{
  int retval;
  va_list varlist;
  __builtin_va_start(varlist,level);
  retval = ms_log_main (&gMSLogParam, level, &varlist);
  __builtin_va_end(varlist);
  return retval;
}

canonical_original_code:
int ms_log(int level, ...)
{
  int retval;
  __builtin_va_list varlist;
  __builtin_va_start(varlist,level);
  retval = ms_log_main (&gMSLogParam, level, &varlist);
  __builtin_va_end(varlist);
  return retval;
}

variable_types: level int

variable_types: retval int


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

if ( !a1 )
a1 = &gMSLogParam;
va_start(va, a2);
return ms_log_main((__int64)a1, a2, (int *)va);
}

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

if ( !a1 )
a1 = &gMSLogParam;
va_start(va, a2);
return func0((__int64)a1, a2, (int *)va);
}

original_code:
int
ms_log_l (MSLogParam *logp, int level, ...)
{
  int retval;
  va_list varlist;
  MSLogParam *llog;
  if ( ! logp )
    llog = &gMSLogParam;
  else
    llog = logp;
  __builtin_va_start(varlist,level);
  retval = ms_log_main (llog, level, &varlist);
  __builtin_va_end(varlist);
  return retval;
}

canonical_original_code:
int ms_log_l(struct MSLogParam_s *logp, int level, ...)
{
  int retval;
  __builtin_va_list varlist;
  struct MSLogParam_s *llog;
  if ( ! logp )
    llog = &gMSLogParam;
  else
    llog = logp;
  __builtin_va_start(varlist,level);
  retval = ms_log_main (llog, level, &varlist);
  __builtin_va_end(varlist);
  return retval;
}

variable_types: struct MSLogParam_s { void (*log_print)(); char *logprefix; void (*diag_print)(); char *errprefix; } *


decompiled_code:
void __fastcall ms_loginit_main(_QWORD *a1, __int64 a2, const char *a3, __int64 a4, const char *a5)
{
if ( a1 )
{
if ( a2 )
*a1 = a2;
if ( a3 )
{
if ( strlen(a3) > 0xC7 )
ms_log_l(a1, 2, 0LL, "log message prefix is too large\n");
else
a1[1] = a3;
}
if ( a4 )
a1[2] = a4;
if ( a5 )
{
if ( strlen(a5) > 0xC7 )
ms_log_l(a1, 2, 0LL, "error message prefix is too large\n");
else
a1[3] = a5;
}
}
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1, __int64 a2, const char *a3, __int64 a4, const char *a5)
{
if ( a1 )
{
if ( a2 )
*a1 = a2;
if ( a3 )
{
if ( strlen(a3) > 0xC7 )
func2(a1, 2, 0LL, "log message prefix is too large\n");
else
a1[1] = a3;
}
if ( a4 )
a1[2] = a4;
if ( a5 )
{
if ( strlen(a5) > 0xC7 )
func2(a1, 2, 0LL, "error message prefix is too large\n");
else
a1[3] = a5;
}
}
}

original_code:
void
ms_loginit_main (MSLogParam *logp,
   void (*log_print)(char*), const char *logprefix,
   void (*diag_print)(char*), const char *errprefix)
{
  if ( ! logp )
    return;
  if ( log_print )
    logp->log_print = log_print;
  if ( logprefix )
    {
      if ( strlen(logprefix) >= 200 )
 {
   ms_log_l (logp, 2, 0, "log message prefix is too large\n");
 }
      else
 {
   logp->logprefix = logprefix;
 }
    }
  if ( diag_print )
    logp->diag_print = diag_print;
  if ( errprefix )
    {
      if ( strlen(errprefix) >= 200 )
 {
   ms_log_l (logp, 2, 0, "error message prefix is too large\n");
 }
      else
 {
   logp->errprefix = errprefix;
 }
    }
  return;
}

canonical_original_code:
void ms_loginit_main(struct MSLogParam_s *logp, void (*log_print)(char *), char *logprefix, void (*diag_print)(char *), char *errprefix)
{
  if ( ! logp )
    return;
  if ( log_print )
    logp->log_print = log_print;
  if ( logprefix )
    {
      if ( strlen(logprefix) >= 200 )
 {
   ms_log_l (logp, 2, 0, "log message prefix is too large\n");
 }
      else
 {
   logp->logprefix = logprefix;
 }
    }
  if ( diag_print )
    logp->diag_print = diag_print;
  if ( errprefix )
    {
      if ( strlen(errprefix) >= 200 )
 {
   ms_log_l (logp, 2, 0, "error message prefix is too large\n");
 }
      else
 {
   logp->errprefix = errprefix;
 }
    }
  return;
}

variable_types:
logprefix
char *

variable_types:
errprefix
char *

user_defined_types: struct MSLogParam_s { void (*log_print)(); char *logprefix; void (*diag_print)(); char *errprefix; }


decompiled_code:
void __fastcall ms_loginit(__int64 a1, const char *a2, __int64 a3, const char *a4)
{
ms_loginit_main(gMSLogParam, a1, a2, a3, a4);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, const char *a2, __int64 a3, const char *a4)
{
func3(gMSLogParam, a1, a2, a3, a4);
}

original_code:
void
ms_loginit (void (*log_print)(char*), const char *logprefix,
     void (*diag_print)(char*), const char *errprefix)
{
  ms_loginit_main(&gMSLogParam, log_print, logprefix, diag_print, errprefix);
}

canonical_original_code:
void ms_loginit(void (*log_print)(char *), char *logprefix, void (*diag_print)(char *), char *errprefix)
{
  ms_loginit_main(&gMSLogParam, log_print, logprefix, diag_print, errprefix);
}


decompiled_code:
void __fastcall free_http_header(void *ptr)
{
__int64 *v2; // rbp
__int64 *v3; // rbx
__int64 *v4; // rdi
void *v5; // rdi
__int64 v6; // rbx

if ( !ptr )
return;
v2 = *(__int64 **)ptr;
if ( !*(_QWORD *)ptr )
goto LABEL_6;
do
{
v6 = *v2;
if ( !*v2 )
break;
if ( !*(_QWORD *)v6 )
{
v5 = *(void **)(v6 + 8);
if ( !v5 )
goto LABEL_10;
LABEL_8:
free(v5);
goto LABEL_9;
}
free(*(void **)v6);
v5 = *(void **)(v6 + 8);
if ( v5 )
goto LABEL_8;
LABEL_9:
v6 = *v2;
if ( *v2 )
LABEL_10:
free((void *)v6);
v2 = (__int64 *)v2[1];
}
while ( v2 );
v3 = *(__int64 **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v4 = v3;
v3 = (__int64 *)v3[1];
free(v4);
}
while ( v3 );
}
LABEL_6:
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
__int64 *v2; // rbp
__int64 *v3; // rbx
__int64 *v4; // rdi
void *v5; // rdi
__int64 v6; // rbx

if ( !ptr )
return;
v2 = *(__int64 **)ptr;
if ( !*(_QWORD *)ptr )
goto LABEL_6;
do
{
v6 = *v2;
if ( !*v2 )
break;
if ( !*(_QWORD *)v6 )
{
v5 = *(void **)(v6 + 8);
if ( !v5 )
goto LABEL_10;
LABEL_8:
free(v5);
goto LABEL_9;
}
free(*(void **)v6);
v5 = *(void **)(v6 + 8);
if ( v5 )
goto LABEL_8;
LABEL_9:
v6 = *v2;
if ( *v2 )
LABEL_10:
free((void *)v6);
v2 = (__int64 *)v2[1];
}
while ( v2 );
v3 = *(__int64 **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v4 = v3;
v3 = (__int64 *)v3[1];
free(v4);
}
while ( v3 );
}
LABEL_6:
free(ptr);
}

original_code:
static void
free_http_header(HttpHeader *h)
{
        List *l;
        List *l1;
        HttpHeaderEntry *he;
        if (h == ((void *)0)) {
                return;
        }
        l = h->header_list;
        while (l && l->data) {
                he = l->data;
                if(he->key) free(he->key);
                if(he->value) free(he->value);
                if(l->data) free(l->data);
                l = l->next;
        }
        l = h->header_list;
        while (l) {
                l1 = l->next;
                if(l) free(l);
                l = l1;
        }
        if(h) free(h);
}

canonical_original_code:
static void free_http_header(struct _HttpHeader *h)
{
        struct _List *l;
        struct _List *l1;
        struct _HttpHeaderEntry *he;
        if (h == ((void *)0)) {
                return;
        }
        l = h->header_list;
        while (l && l->data) {
                he = l->data;
                if(he->key) free(he->key);
                if(he->value) free(he->value);
                if(l->data) free(l->data);
                l = l->next;
        }
        l = h->header_list;
        while (l) {
                l1 = l->next;
                if(l) free(l);
                l = l1;
        }
        if(h) free(h);
}

variable_types: struct _HttpHeader { struct _List { void *data; struct _List *next; } *header_list; } *

variable_types: struct _HttpHeaderEntry { char *key; char *value; } *

user_defined_types: struct _HttpHeader { struct _List *header_list; }


original_code:
static char *
get_request(UrlResource *rsrc)
{
        char *request = ((void *)0);
        char *auth = ((void *)0);
        char *temp = ((void *)0);
        char buf[(5*2048)];
        Url *u;
        off_t file_size;
        u = rsrc->url;
        request = strconcat("GET ", u->path, u->file, " HTTP/1.0\r\n",
                            "Host: ", u->host, "\r\n", ((void *)0));
        if( u->username && u->password ) {
                auth = strconcat( u->username, ":", u->password, ((void *)0));
                temp = auth;
                auth = base64(auth, strlen(auth));
                if(temp) free(temp);
                temp = request;
                request = strconcat(request, "Authorization: Basic ",
                                    auth, "\r\n", ((void *)0));
                if(temp) free(temp);
                if(auth) free(auth);
        }
        if( rsrc->proxy_username && rsrc->proxy_password ) {
                auth = strconcat( rsrc->proxy_username, ":",
                                  rsrc->proxy_password, ((void *)0));
                temp = auth;
                auth = base64(auth, strlen(auth));
                if(temp) free(temp);
                temp = request;
                request = strconcat(request, "Proxy-Authorization: Basic ",
                                    auth, "\r\n", ((void *)0));
                if(temp) free(temp);
                if(auth) free(auth);
        }
        if( (rsrc->options & (1 << 0))
            && (file_size = get_file_size(rsrc->outfile)) ) {
                sprintf(buf, "%ld-", (long int )file_size);
                temp = request;
                request = strconcat(request, "Range: bytes=", buf, "\r\n",
                                    ((void *)0));
                if(temp) free(temp);
        }
        temp = request;
        request = strconcat(request, "User-Agent: ", ((void *)0));
        if(temp) free(temp);
        if (getenv("SNARF_HTTP_USER_AGENT")) {
            temp = request;
            request = strconcat(request, getenv("SNARF_HTTP_USER_AGENT"),
                                ((void *)0));
            if(temp) free(temp);
        } else if (rsrc->options & (1 << 6)) {
            temp = request;
            request = strconcat(request, "Mozilla/4.0 (X11; Unix; Hi-mom)", ((void *)0));
            if(temp) free(temp);
        } else if (rsrc->options & (1 << 7)) {
            temp = request;
            request = strconcat(request, "Mozilla/4.0 (Compatible; MSIE 4.0)", ((void *)0));
            if(temp) free(temp);
        } else {
            temp = request;
            request = strconcat(request, "snarf/" "7.0" " (http://www.xach.com/snarf)", ((void *)0));
            if(temp) free(temp);
        }
        temp = request;
        request = strconcat(request, "\r\n", ((void *)0));
        if(temp) free(temp);
        if (getenv("SNARF_HTTP_REFERER")) {
                temp = request;
                request = strconcat(request, "Referer: ",
                                    getenv("SNARF_HTTP_REFERER"),
                                    "\r\n", ((void *)0));
                if(temp) free(temp);
        }
        temp = request;
        request = strconcat(request, "\r\n", ((void *)0));
        if(temp) free(temp);
        return request;
}

canonical_original_code:
static char *get_request(struct _UrlResource *rsrc)
{
        char *request = ((void *)0);
        char *auth = ((void *)0);
        char *temp = ((void *)0);
        char buf[-1];
        struct _Url *u;
        long file_size;
        u = rsrc->url;
        request = strconcat("GET ", u->path, u->file, " HTTP/1.0\r\n",
                            "Host: ", u->host, "\r\n", ((void *)0));
        if( u->username && u->password ) {
                auth = strconcat( u->username, ":", u->password, ((void *)0));
                temp = auth;
                auth = base64(auth, strlen(auth));
                if(temp) free(temp);
                temp = request;
                request = strconcat(request, "Authorization: Basic ",
                                    auth, "\r\n", ((void *)0));
                if(temp) free(temp);
                if(auth) free(auth);
        }
        if( rsrc->proxy_username && rsrc->proxy_password ) {
                auth = strconcat( rsrc->proxy_username, ":",
                                  rsrc->proxy_password, ((void *)0));
                temp = auth;
                auth = base64(auth, strlen(auth));
                if(temp) free(temp);
                temp = request;
                request = strconcat(request, "Proxy-Authorization: Basic ",
                                    auth, "\r\n", ((void *)0));
                if(temp) free(temp);
                if(auth) free(auth);
        }
        if( (rsrc->options & (1 << 0))
            && (file_size = get_file_size(rsrc->outfile)) ) {
                sprintf(buf, "%ld-", (long )file_size);
                temp = request;
                request = strconcat(request, "Range: bytes=", buf, "\r\n",
                                    ((void *)0));
                if(temp) free(temp);
        }
        temp = request;
        request = strconcat(request, "User-Agent: ", ((void *)0));
        if(temp) free(temp);
        if (getenv("SNARF_HTTP_USER_AGENT")) {
            temp = request;
            request = strconcat(request, getenv("SNARF_HTTP_USER_AGENT"),
                                ((void *)0));
            if(temp) free(temp);
        } else if (rsrc->options & (1 << 6)) {
            temp = request;
            request = strconcat(request, "Mozilla/4.0 (X11; Unix; Hi-mom)", ((void *)0));
            if(temp) free(temp);
        } else if (rsrc->options & (1 << 7)) {
            temp = request;
            request = strconcat(request, "Mozilla/4.0 (Compatible; MSIE 4.0)", ((void *)0));
            if(temp) free(temp);
        } else {
            temp = request;
            request = strconcat(request, "snarf/" "7.0" " (http://www.xach.com/snarf)", ((void *)0));
            if(temp) free(temp);
        }
        temp = request;
        request = strconcat(request, "\r\n", ((void *)0));
        if(temp) free(temp);
        if (getenv("SNARF_HTTP_REFERER")) {
                temp = request;
                request = strconcat(request, "Referer: ",
                                    getenv("SNARF_HTTP_REFERER"),
                                    "\r\n", ((void *)0));
                if(temp) free(temp);
        }
        temp = request;
        request = strconcat(request, "\r\n", ((void *)0));
        if(temp) free(temp);
        return request;
}

variable_types: struct _UrlResource { struct _Url { char *full_url; int service_type; char *username; char *password; char *host; int port; char *path; char *file; } *url; char *outfile; char *proxy; char *proxy_username; char *proxy_password; unsigned char options; long outfile_size; long outfile_offset; } *

variable_types:
request
char *

variable_types:
auth
char *

variable_types:
temp
char *

variable_types:
buf
char [-1]

user_defined_types: struct _UrlResource { struct _Url *url; char *outfile; char *proxy; char *proxy_username; char *proxy_password; unsigned char options; long outfile_size; long outfile_offset; }


decompiled_code:
char *__fastcall get_raw_header(int fd)
{
char *v1; // r12
int v2; // ebp
int v3; // eax
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
__int64 v7; // rbx
char v9[10280]; // [rsp+0h] [rbp-2828h] BYREF

v1 = strdup(&s);
v9[2] = 0;
v9[1] = 0;
v9[0] = 0;
v2 = 0;
while ( 1 )
{
v3 = read(fd, v9, 1uLL);
if ( !v3 )
break;
v2 += v3;
v7 = ((__int64 (__fastcall *)(char *, char *, _QWORD, __int64, __int64, __int64))strconcat)(v1, v9, 0LL, v4, v5, v6);
if ( v1 )
free(v1);
if ( v2 > 1 && !strcmp((const char *)(v7 + v2 - 2), "\n\n") )
return (char *)v7;
if ( v2 <= 3 )
{
v1 = (char *)v7;
}
else
{
if ( !strcmp((const char *)(v7 + v2 - 4), "\r\n\r\n") )
return (char *)v7;
v1 = (char *)v7;
}
}
return v1;
}

original_code:
static char *
get_raw_header(int fd)
{
        char *header = ((void *)0);
        char *temp = ((void *)0);
        char buf[(5*2048)];
        int bytes_read = 0;
        int total_read = 0;
        header = ( ("") ? strdup("") : ((void *)0) );
        buf[0] = buf[1] = buf[2] = '\0';
        while( (bytes_read = read(fd, buf, 1)) ) {
                total_read += bytes_read;
                temp = header;
                header = strconcat(header, buf, ((void *)0));
                if(temp) free(temp);
                if( total_read > 1) {
                        if( strcmp(header + (total_read - 2), "\n\n") == 0 )
                                break;
                }
                if( total_read > 3 ) {
                        if( strcmp(header + (total_read - 4), "\r\n\r\n")
                            == 0 )
                                break;
                }
        }
        return header;
}

canonical_original_code:
static char *get_raw_header(int fd)
{
        char *header = ((void *)0);
        char *temp = ((void *)0);
        char buf[-1];
        int bytes_read = 0;
        int total_read = 0;
        header = ( ("") ? strdup("") : ((void *)0) );
        buf[0] = buf[1] = buf[2] = '\0';
        while( (bytes_read = read(fd, buf, 1)) ) {
                total_read += bytes_read;
                temp = header;
                header = strconcat(header, buf, ((void *)0));
                if(temp) free(temp);
                if( total_read > 1) {
                        if( strcmp(header + (total_read - 2), "\n\n") == 0 )
                                break;
                }
                if( total_read > 3 ) {
                        if( strcmp(header + (total_read - 4), "\r\n\r\n")
                            == 0 )
                                break;
                }
        }
        return header;
}

variable_types: fd int

variable_types:
header
char *


decompiled_code:
void __fastcall format_data(unsigned __int8 *a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int8 *v4; // rbx
__int64 v5; // r13
unsigned __int64 v6; // r14
__int64 v7; // rbp
char v8; // dl
__int64 v9; // r12
char *ptr; // [rsp+0h] [rbp-58h]
unsigned __int64 v11; // [rsp+8h] [rbp-50h]
__int64 v12; // [rsp+10h] [rbp-48h]

if ( a1 )
{
v4 = a1;
v5 = a3;
if ( a2 )
{
if ( !a3 )
v5 = 16LL;
v6 = (unsigned __int64)&a1[a2];
ptr = (char *)calloc(1uLL, v5 + 1);
if ( ptr )
{
if ( (unsigned __int64)a1 < v6 )
{
v12 = 0LL;
v11 = 0LL;
fprintf(stdout, "%08lx ", 0LL);
while ( 1 )
{
if ( v5 )
{
v7 = 0LL;
v9 = 0LL;
do
{
if ( v6 <= (unsigned __int64)v4 )
{
fwrite(" ", 1uLL, 3uLL, stdout);
}
else
{
fprintf(stdout, " %02lx", *v4);
v8 = *v4++;
if ( (unsigned __int8)(v8 - 32) >= 0x5Fu )
v8 = 46;
sprintf(&ptr[v9++], "%c", (unsigned int)v8);
}
++v7;
}
while ( v5 != v7 );
}
fprintf(stdout, " |%s|\n", ptr);
++v11;
if ( a4 )
{
if ( v11 >= a4 )
{
fputc(10, stdout);
v11 = 0LL;
}
}
v12 += v5;
if ( v6 <= (unsigned __int64)v4 )
break;
fprintf(stdout, "%08lx ", v12);
}
}
fputc(10, stdout);
free(ptr);
}
}
}
}

canonical_decompiled_code:
void __fastcall func0(unsigned __int8 *a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int8 *v4; // rbx
__int64 v5; // r13
unsigned __int64 v6; // r14
__int64 v7; // rbp
char v8; // dl
__int64 v9; // r12
char *ptr; // [rsp+0h] [rbp-58h]
unsigned __int64 v11; // [rsp+8h] [rbp-50h]
__int64 v12; // [rsp+10h] [rbp-48h]

if ( a1 )
{
v4 = a1;
v5 = a3;
if ( a2 )
{
if ( !a3 )
v5 = 16LL;
v6 = (unsigned __int64)&a1[a2];
ptr = (char *)calloc(1uLL, v5 + 1);
if ( ptr )
{
if ( (unsigned __int64)a1 < v6 )
{
v12 = 0LL;
v11 = 0LL;
fprintf(stdout, "%08lx ", 0LL);
while ( 1 )
{
if ( v5 )
{
v7 = 0LL;
v9 = 0LL;
do
{
if ( v6 <= (unsigned __int64)v4 )
{
fwrite(" ", 1uLL, 3uLL, stdout);
}
else
{
fprintf(stdout, " %02lx", *v4);
v8 = *v4++;
if ( (unsigned __int8)(v8 - 32) >= 0x5Fu )
v8 = 46;
sprintf(&ptr[v9++], "%c", (unsigned int)v8);
}
++v7;
}
while ( v5 != v7 );
}
fprintf(stdout, " |%s|\n", ptr);
++v11;
if ( a4 )
{
if ( v11 >= a4 )
{
fputc(10, stdout);
v11 = 0LL;
}
}
v12 += v5;
if ( v6 <= (unsigned __int64)v4 )
break;
fprintf(stdout, "%08lx ", v12);
}
}
fputc(10, stdout);
free(ptr);
}
}
}
}

original_code:
void format_data( const uint8_t *data, const size_t len, size_t bytes_per_line, size_t lines_per_section )
{
    if ( !data || !len ) {
        return;
    }
    if ( !bytes_per_line ) {
        bytes_per_line = 16;
    }
    const uint8_t *pos = ((void *)0);
    const uint8_t *pend = ((void *)0);
    char *summary = ((void *)0);
    size_t summary_count = 0;
    size_t section_lines = 0;
    size_t line_tally = 0;
    uint8_t value;
    int i;
    pos = data;
    pend = data + len;
    summary = calloc( 1, bytes_per_line + 1 );
    if ( summary ) {
        while (pos < pend) {
            fprintf( stdout, "%08lx ", (unsigned long)(line_tally * bytes_per_line) );
            line_tally++;
            for (i = 0; i < bytes_per_line; i++) {
                if ( pos < pend ) {
                    fprintf( stdout, " %02lx", (unsigned long)(*pos) );
                    value = *pos;
                    pos++;
                    if (value < 32 || value > 126 ) {
                        value = '.';
                    }
                    sprintf( (summary + summary_count), "%c", *(char *)&value );
                    summary_count++;
                } else {
                    fprintf( stdout, "   " );
                }
            }
            fprintf( stdout, "  |%s|\n", summary );
            summary_count = 0;
            section_lines++;
            if ( lines_per_section && section_lines >= lines_per_section ) {
                fprintf( stdout, "\n" );
                section_lines = 0;
            }
        }
        fprintf( stdout, "\n" );
        free(summary);
    }
}

canonical_original_code:
void format_data(unsigned char *data, unsigned long len, unsigned long bytes_per_line, unsigned long lines_per_section)
{
    if ( !data || !len ) {
        return;
    }
    if ( !bytes_per_line ) {
        bytes_per_line = 16;
    }
    unsigned char *pos = ((void *)0);
    unsigned char *pend = ((void *)0);
    char *summary = ((void *)0);
    unsigned long summary_count = 0;
    unsigned long section_lines = 0;
    unsigned long line_tally = 0;
    unsigned char value;
    int i;
    pos = data;
    pend = data + len;
    summary = calloc( 1, bytes_per_line + 1 );
    if ( summary ) {
        while (pos < pend) {
            fprintf( stdout, "%08lx ", (unsigned long)(line_tally * bytes_per_line) );
            line_tally++;
            for (i = 0; i < bytes_per_line; i++) {
                if ( pos < pend ) {
                    fprintf( stdout, " %02lx", (unsigned long)(*pos) );
                    value = *pos;
                    pos++;
                    if (value < 32 || value > 126 ) {
                        value = '.';
                    }
                    sprintf( (summary + summary_count), "%c", *(char *)&value );
                    summary_count++;
                } else {
                    fprintf( stdout, "   " );
                }
            }
            fprintf( stdout, "  |%s|\n", summary );
            summary_count = 0;
            section_lines++;
            if ( lines_per_section && section_lines >= lines_per_section ) {
                fprintf( stdout, "\n" );
                section_lines = 0;
            }
        }
        fprintf( stdout, "\n" );
        free(summary);
    }
}

variable_types:
data
unsigned char *

variable_types:
len
unsigned long

variable_types:
pos
unsigned char *

variable_types:
pend
unsigned char *

variable_types:
summary
char *

variable_types:
value
unsigned char

variable_types: i int


original_code:
STDTIME2 ST_CleanDate2(STDTIME2 indate, WORD epoch, ULONG timflgs) {
 long dy,dd,dh,dm,ds,dms;
 STDTIME2 outtime;
 dy = indate.year;
 dd = indate.day;
 dh = indate.hour;
 dm = indate.minute;
 ds = indate.second;
 dms = indate.tenth_msec;
 dy = _calyear(dy, epoch, timflgs);
 dd--;
 timenorm2(&dy, &dd, &dh, &dm, &ds, &dms);
 outtime.year = dy;
 outtime.day = dd + 1;
 outtime.hour = dh;
 outtime.minute = dm;
 outtime.second = ds;
 outtime.tenth_msec = dms;
 return(outtime);
}

canonical_original_code:
struct __sjtim2 ST_CleanDate2(struct __sjtim2 indate, short epoch, unsigned int timflgs) {
 long dy; long dd; long dh; long dm; long ds; long dms;
 struct __sjtim2 outtime;
 dy = indate.year;
 dd = indate.day;
 dh = indate.hour;
 dm = indate.minute;
 ds = indate.second;
 dms = indate.tenth_msec;
 dy = _calyear(dy, epoch, timflgs);
 dd--;
 timenorm2(&dy, &dd, &dh, &dm, &ds, &dms);
 outtime.year = dy;
 outtime.day = dd + 1;
 outtime.hour = dh;
 outtime.minute = dm;
 outtime.second = ds;
 outtime.tenth_msec = dms;
 return(outtime);
}

variable_types:
indate
struct __sjtim2

variable_types: epoch short

variable_types:
timflgs
unsigned int

variable_types: dy long

variable_types: dd long

variable_types: dh long

variable_types: dm long

variable_types: ds long

variable_types: dms long

variable_types: struct __sjtim2 { short year; short day; char hour; char minute; char second; short tenth_msec; }


decompiled_code:
int get_command_char()
{
char v1; // [rsp+0h] [rbp-108h] BYREF

do
{
printf("Command: ");
get_line(&line);
_isoc99_sscanf(&line, "%s", &v1);
}
while ( !v1 );
return toupper(v1);
}

canonical_decompiled_code:
int func0()
{
char v1; // [rsp+0h] [rbp-108h] BYREF

do
{
printf("Command: ");
get_line(&line);
_isoc99_sscanf(&line, "%s", &v1);
}
while ( !v1 );
return toupper(v1);
}

original_code:
char get_command_char (void)
{
  string s ;
  do {
    printf ("Command: ") ;
    get_line(line) ;
    sscanf (line, "%s", s) ;
    if (strlen(s) >= 1)

        return toupper(s[0]) ;
  } while (! 0) ;
}

canonical_original_code:
char get_command_char()
{
  char s[256];
  do {
    printf ("Command: ") ;
    get_line(line) ;
    sscanf (line, "%s", s) ;
    if (strlen(s) >= 1)

        return toupper(s[0]) ;
  } while (! 0) ;
}

variable_types:
s
char [256]

return_type: char


decompiled_code:
__int64 run_commands()
{
__int64 result; // rax
__int64 v1; // rdi
unsigned int v2; // eax
const char *v3; // rax
__int64 v4; // rdi
unsigned int v5; // eax
const char *v6; // rax
__int64 v7; // rdi
void *v8; // rax
__int64 v9; // rdi
const char *v10; // rax
unsigned __int16 v11; // ax
_BYTE v12[256]; // [rsp+0h] [rbp-118h] BYREF
__int16 v13; // [rsp+100h] [rbp-18h] BYREF
void *v14; // [rsp+108h] [rbp-10h]

while ( 2 )
{
switch ( cfgphase )
{
case 0:
show_idle_menu();
result = (unsigned __int8)(get_command_char() - 67);
switch ( (char)result )
{
case 0:
if ( !context )
cfgphase = 1;
continue;
case 1:
if ( context )
goto LABEL_6;
continue;
case 2:
cfgphase = 2;
continue;
case 3:
cfgphase = 3;
continue;
case 10:
goto LABEL_9;
case 12:
if ( context )
show_opstat();
continue;
case 13:
v1 = context;
if ( context )
{
if ( *((_WORD *)&configstruc + 507) )
*((_BYTE *)&configstruc + 496) = 0;
v2 = lib_unregistered_ping(v1, (unsigned int)((_DWORD)&configstruc + 488));
*((_DWORD *)&configstruc + 108) = v2;
if ( v2 )
{
v3 = (const char *)lib_get_errstr(v2, v12);
printf("Error Pinging Station: %s\n", v3);
}
}
continue;
case 14:
if ( poc_context )
{
puts("POC Receiver Stopped");
result = lib_poc_stop(poc_context);
}
if ( context )
result = lib_destroy_context(&context);
break;
case 16:
v4 = context;
if ( context )
{
if ( *((_WORD *)&configstruc + 507) )
*((_BYTE *)&configstruc + 496) = 0;
v5 = lib_register(v4, (unsigned int)((_DWORD)&configstruc + 488));
if ( v5 )
{
v6 = (const char *)lib_get_errstr(v5, v12);
printf("Error Starting Connection: %s\n", v6);
}
else
{
cfgphase = 4;
}
}
continue;
case 17:
v7 = context;
if ( context )
{
lib_change_state(context, 1LL, 27LL);
}
else
{
*((_QWORD *)&configstruc + 55) = &sen_state_callback;
*((_QWORD *)&configstruc + 56) = &msgs_callback;
*((_QWORD *)&configstruc + 59) = 0LL;
*((_QWORD *)&configstruc + 51) = 0LL;
fowner[0] = &sen_file_callback;
fowner[1] = 0LL;
*((_QWORD *)&configstruc + 60) = fowner;
*((_QWORD *)&configstruc + 52) = &mini_callback;
v8 = 0LL;
if ( *((_WORD *)&configstruc + 518) )
v8 = &amini_callback;
*((_QWORD *)&configstruc + 53) = v8;
if ( *((_WORD *)&configstruc + 517) )
mseed_file = lib_file_open(v7, "seneca.mseed", 9LL);
else
mseed_file = -1LL;
if ( *((_WORD *)&configstruc + 516) )
{
*((_QWORD *)&configstruc + 57) = &onesec_callback;
onesec_file = lib_file_open(0LL, "seneca.sec", 9LL);
}
else
{
*((_QWORD *)&configstruc + 57) = 0LL;
onesec_file = -1LL;
}
lib_create_context(&context, (unsigned int)((_DWORD)&configstruc + 8));
v9 = *((unsigned int *)&configstruc + 108);
if ( (_DWORD)v9 )
{
context = 0LL;
v10 = (const char *)lib_get_errstr(v9, v12);
printf("Error creating station thread: %s\n", v10);
}
else
{
puts("Station Thread Created");
cfgphase = 0;
if ( *((_WORD *)&configstruc + 520) )
{
v13 = *((_WORD *)&configstruc + 520);
v14 = &poc_handler;
poc_context = lib_poc_start(&v13);
puts("POC Receiver Started");
}
}
}
continue;
default:
continue;
}
break;
case 1:
show_create_pars();
switch ( (unsigned __int8)get_command_char() )
{
case 'A':
get_t64("Serial number: ", (unsigned int)((_DWORD)&configstruc + 8));
break;
case 'B':
*((_WORD *)&configstruc + 8) = get_word("Data port (1-4): ") - 1;
break;
case 'C':
get_string("Station name (3-5 characters): ", 5LL, (unsigned int)((_DWORD)&configstruc + 18));
lib330_upper((unsigned int)((_DWORD)&configstruc + 18));
break;
case 'D':
*((_DWORD *)&configstruc + 6) = get_integer("Timezone offset in seconds: ");
break;
case 'E':
get_string("Host software name: ", 95LL, (unsigned int)((_DWORD)&configstruc + 28));
break;
case 'F':
get_string("Continuity file name (Null to disable): ", 250LL, (unsigned int)((_DWORD)&configstruc + 124));
break;
case 'G':
*((_WORD *)&configstruc + 187) = get_verbosity();
break;
case 'H':
*((_QWORD *)&configstruc + 49) = get_frequency("Highest frequency for incremental update: ");
break;
case 'I':
*((_WORD *)&configstruc + 200) = (unsigned __int8)get_yesno("Embed blockettes (Y/n): ", 1LL);
break;
case 'J':
*((_WORD *)&configstruc + 201) = (unsigned __int8)get_yesno("Separate blockettes (y/N): ", 0LL);
break;
case 'K':
*((_WORD *)&configstruc + 188) = (unsigned __int8)get_yesno(
"Calculate host timezone automatically (Y/n): ",
1LL);
break;
case 'L':
*((_WORD *)&configstruc + 189) = get_onesec_filter();
break;
case 'M':
*((_WORD *)&configstruc + 192) = get_seed_filter("512 byte MiniSeed data filter: ");
break;
case 'N':
*((_WORD *)&configstruc + 193) = get_seed_filter("Archival MiniSeed data filter: ");
break;
case 'S':
goto LABEL_84;
case 'X':
cfgphase = 0;
break;
default:
continue;
}
continue;
case 2:
show_register_pars();
switch ( (unsigned __int8)get_command_char() )
{
case 'A':
get_t64("Authentication code: ", (unsigned int)((_DWORD)&configstruc + 488));
break;
case 'B':
get_string("Q330 IP address: ", 250LL, (unsigned int)((_DWORD)&configstruc + 496));
break;
case 'C':
*((_WORD *)&configstruc + 373) = get_word("Q330 base port: ");
break;
case 'E':
get_string("Host interface: ", 250LL, (unsigned int)((_DWORD)&configstruc + 752));
break;
case 'F':
*((_WORD *)&configstruc + 501) = get_timeout("Host minimum command timeout: ");
break;
case 'G':
*((_WORD *)&configstruc + 502) = get_timeout("Host maximum command timeout: ");
break;
case 'H':
*((_WORD *)&configstruc + 503) = get_word("Host control port (0 for automatic): ");
break;
case 'I':
*((_WORD *)&configstruc + 504) = get_word("Host data port (0 for automatic): ");
break;
case 'J':
*((_WORD *)&configstruc + 507) = (unsigned __int8)get_yesno("Q330 has dynamic IP address (y/N): ", 0LL);
break;
case 'K':
*((_WORD *)&configstruc + 508) = get_word("Hibernate time in minutes: ");
break;
case 'L':
*((_WORD *)&configstruc + 509) = get_word("Maximum connection time in minutes: ");
break;
case 'M':
*((_WORD *)&configstruc + 510) = get_word("Connection wait time in minutes: ");
break;
case 'N':
*((_WORD *)&configstruc + 511) = get_word("Maximum registration attempts before hibernation: ");
break;
case 'O':
*((_WORD *)&configstruc + 512) = get_word("Dynamic IP address expiration in minutes: ");
break;
case 'P':
*((_WORD *)&configstruc + 513) = get_word("Buffer level to stop connection: ");
break;
case 'Q':
*((_WORD *)&configstruc + 514) = get_word("Minutes before writing Q330 continuity to file: ");
break;
case 'R':
*((_WORD *)&configstruc + 515) = get_word("Maximum DSS memory in KB: ");
break;
case 'S':
goto LABEL_84;
case 'X':
cfgphase = 0;
break;
default:
continue;
}
continue;
case 3:
show_file_menu();
switch ( (unsigned __int8)get_command_char() )
{
case 'A':
*((_WORD *)&configstruc + 516) = (unsigned __int8)get_yesno(
"Enable writing one second data to seneca.sec (y/N): ",
0LL);
break;
case 'B':
*((_WORD *)&configstruc + 517) = (unsigned __int8)get_yesno(
"Enable writing 512 byte MiniSeed to seneca.mseed (y/N): ",
0LL);
break;
case 'C':
*((_WORD *)&configstruc + 518) = (unsigned __int8)get_yesno(
"Enable writing 4096 byte MiniSeed to individual files (y/N): ",
0LL);
break;
case 'D':
*((_WORD *)&configstruc + 519) = (unsigned __int8)get_yesno(
"Enable NetServer if configured in tokens (y/N): ",
0LL);
break;
case 'E':
*((_WORD *)&configstruc + 520) = get_word("POC Receiver port (zero to disable, standard is 2254): ");
break;
case 'S':
LABEL_84:
save_configuration();
break;
case 'X':
cfgphase = 0;
break;
default:
continue;
}
continue;
case 4:
show_run_menu();
result = (unsigned __int8)(get_command_char() - 65);
switch ( (char)result )
{
case 0:
arp_status();
continue;
case 2:
lib_abort_command(context);
continue;
case 3:
LABEL_6:
dump_messages();
continue;
case 5:
if ( current_state == 10 )
lib_flush_data(context);
continue;
case 6:
send_tunneled_request();
continue;
case 7:
if ( current_state == 10 )
show_detectors();
continue;
case 8:
if ( current_state == 10 )
lib_set_freeze_timer(context, 30LL);
continue;
case 11:
show_lcqs();
continue;
case 12:
LABEL_9:
show_modules();
continue;
case 14:
screen_busy = 1;
show_opstat();
screen_busy = 0;
continue;
case 15:
pingreq = 0;
*((_WORD *)&pingreq + 1) = 0;
*((_DWORD *)&pingreq + 1) = 0;
lib_ping_request(context, &pingreq);
continue;
case 16:
if ( context )
continue;
if ( poc_context )
{
puts("POC Receiver Stopped");
result = lib_poc_stop(poc_context);
}
break;
case 18:
lib_change_state(context, 0LL, 27LL);
cfgphase = 0;
continue;
case 20:
screen_busy = 1;
printf("Message: ");
get_line(&line);
lib_send_usermessage(context, &line);
screen_busy = 0;
continue;
case 21:
screen_busy = 1;
v11 = get_verbosity();
*((_WORD *)&configstruc + 187) = lib_change_verbosity(context, v11);
screen_busy = 0;
continue;
default:
continue;
}
break;
default:
continue;
}
return result;
}
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
__int64 v1; // rdi
unsigned int v2; // eax
const char *v3; // rax
__int64 v4; // rdi
unsigned int v5; // eax
const char *v6; // rax
__int64 v7; // rdi
void *v8; // rax
__int64 v9; // rdi
const char *v10; // rax
unsigned __int16 v11; // ax
_BYTE v12[256]; // [rsp+0h] [rbp-118h] BYREF
__int16 v13; // [rsp+100h] [rbp-18h] BYREF
void *v14; // [rsp+108h] [rbp-10h]

while ( 2 )
{
switch ( cfgphase )
{
case 0:
show_idle_menu();
result = (unsigned __int8)(func0() - 67);
switch ( (char)result )
{
case 0:
if ( !context )
cfgphase = 1;
continue;
case 1:
if ( context )
goto LABEL_6;
continue;
case 2:
cfgphase = 2;
continue;
case 3:
cfgphase = 3;
continue;
case 10:
goto LABEL_9;
case 12:
if ( context )
show_opstat();
continue;
case 13:
v1 = context;
if ( context )
{
if ( *((_WORD *)&configstruc + 507) )
*((_BYTE *)&configstruc + 496) = 0;
v2 = lib_unregistered_ping(v1, (unsigned int)((_DWORD)&configstruc + 488));
*((_DWORD *)&configstruc + 108) = v2;
if ( v2 )
{
v3 = (const char *)lib_get_errstr(v2, v12);
printf("Error Pinging Station: %s\n", v3);
}
}
continue;
case 14:
if ( poc_context )
{
puts("POC Receiver Stopped");
result = lib_poc_stop(poc_context);
}
if ( context )
result = lib_destroy_context(&context);
break;
case 16:
v4 = context;
if ( context )
{
if ( *((_WORD *)&configstruc + 507) )
*((_BYTE *)&configstruc + 496) = 0;
v5 = lib_register(v4, (unsigned int)((_DWORD)&configstruc + 488));
if ( v5 )
{
v6 = (const char *)lib_get_errstr(v5, v12);
printf("Error Starting Connection: %s\n", v6);
}
else
{
cfgphase = 4;
}
}
continue;
case 17:
v7 = context;
if ( context )
{
lib_change_state(context, 1LL, 27LL);
}
else
{
*((_QWORD *)&configstruc + 55) = &sen_state_callback;
*((_QWORD *)&configstruc + 56) = &msgs_callback;
*((_QWORD *)&configstruc + 59) = 0LL;
*((_QWORD *)&configstruc + 51) = 0LL;
fowner[0] = &sen_file_callback;
fowner[1] = 0LL;
*((_QWORD *)&configstruc + 60) = fowner;
*((_QWORD *)&configstruc + 52) = &mini_callback;
v8 = 0LL;
if ( *((_WORD *)&configstruc + 518) )
v8 = &amini_callback;
*((_QWORD *)&configstruc + 53) = v8;
if ( *((_WORD *)&configstruc + 517) )
mseed_file = lib_file_open(v7, "seneca.mseed", 9LL);
else
mseed_file = -1LL;
if ( *((_WORD *)&configstruc + 516) )
{
*((_QWORD *)&configstruc + 57) = &onesec_callback;
onesec_file = lib_file_open(0LL, "seneca.sec", 9LL);
}
else
{
*((_QWORD *)&configstruc + 57) = 0LL;
onesec_file = -1LL;
}
lib_create_context(&context, (unsigned int)((_DWORD)&configstruc + 8));
v9 = *((unsigned int *)&configstruc + 108);
if ( (_DWORD)v9 )
{
context = 0LL;
v10 = (const char *)lib_get_errstr(v9, v12);
printf("Error creating station thread: %s\n", v10);
}
else
{
puts("Station Thread Created");
cfgphase = 0;
if ( *((_WORD *)&configstruc + 520) )
{
v13 = *((_WORD *)&configstruc + 520);
v14 = &poc_handler;
poc_context = lib_poc_start(&v13);
puts("POC Receiver Started");
}
}
}
continue;
default:
continue;
}
break;
case 1:
show_create_pars();
switch ( (unsigned __int8)func0() )
{
case 'A':
get_t64("Serial number: ", (unsigned int)((_DWORD)&configstruc + 8));
break;
case 'B':
*((_WORD *)&configstruc + 8) = get_word("Data port (1-4): ") - 1;
break;
case 'C':
get_string("Station name (3-5 characters): ", 5LL, (unsigned int)((_DWORD)&configstruc + 18));
lib330_upper((unsigned int)((_DWORD)&configstruc + 18));
break;
case 'D':
*((_DWORD *)&configstruc + 6) = get_integer("Timezone offset in seconds: ");
break;
case 'E':
get_string("Host software name: ", 95LL, (unsigned int)((_DWORD)&configstruc + 28));
break;
case 'F':
get_string("Continuity file name (Null to disable): ", 250LL, (unsigned int)((_DWORD)&configstruc + 124));
break;
case 'G':
*((_WORD *)&configstruc + 187) = get_verbosity();
break;
case 'H':
*((_QWORD *)&configstruc + 49) = get_frequency("Highest frequency for incremental update: ");
break;
case 'I':
*((_WORD *)&configstruc + 200) = (unsigned __int8)get_yesno("Embed blockettes (Y/n): ", 1LL);
break;
case 'J':
*((_WORD *)&configstruc + 201) = (unsigned __int8)get_yesno("Separate blockettes (y/N): ", 0LL);
break;
case 'K':
*((_WORD *)&configstruc + 188) = (unsigned __int8)get_yesno(
"Calculate host timezone automatically (Y/n): ",
1LL);
break;
case 'L':
*((_WORD *)&configstruc + 189) = get_onesec_filter();
break;
case 'M':
*((_WORD *)&configstruc + 192) = get_seed_filter("512 byte MiniSeed data filter: ");
break;
case 'N':
*((_WORD *)&configstruc + 193) = get_seed_filter("Archival MiniSeed data filter: ");
break;
case 'S':
goto LABEL_84;
case 'X':
cfgphase = 0;
break;
default:
continue;
}
continue;
case 2:
show_register_pars();
switch ( (unsigned __int8)func0() )
{
case 'A':
get_t64("Authentication code: ", (unsigned int)((_DWORD)&configstruc + 488));
break;
case 'B':
get_string("Q330 IP address: ", 250LL, (unsigned int)((_DWORD)&configstruc + 496));
break;
case 'C':
*((_WORD *)&configstruc + 373) = get_word("Q330 base port: ");
break;
case 'E':
get_string("Host interface: ", 250LL, (unsigned int)((_DWORD)&configstruc + 752));
break;
case 'F':
*((_WORD *)&configstruc + 501) = get_timeout("Host minimum command timeout: ");
break;
case 'G':
*((_WORD *)&configstruc + 502) = get_timeout("Host maximum command timeout: ");
break;
case 'H':
*((_WORD *)&configstruc + 503) = get_word("Host control port (0 for automatic): ");
break;
case 'I':
*((_WORD *)&configstruc + 504) = get_word("Host data port (0 for automatic): ");
break;
case 'J':
*((_WORD *)&configstruc + 507) = (unsigned __int8)get_yesno("Q330 has dynamic IP address (y/N): ", 0LL);
break;
case 'K':
*((_WORD *)&configstruc + 508) = get_word("Hibernate time in minutes: ");
break;
case 'L':
*((_WORD *)&configstruc + 509) = get_word("Maximum connection time in minutes: ");
break;
case 'M':
*((_WORD *)&configstruc + 510) = get_word("Connection wait time in minutes: ");
break;
case 'N':
*((_WORD *)&configstruc + 511) = get_word("Maximum registration attempts before hibernation: ");
break;
case 'O':
*((_WORD *)&configstruc + 512) = get_word("Dynamic IP address expiration in minutes: ");
break;
case 'P':
*((_WORD *)&configstruc + 513) = get_word("Buffer level to stop connection: ");
break;
case 'Q':
*((_WORD *)&configstruc + 514) = get_word("Minutes before writing Q330 continuity to file: ");
break;
case 'R':
*((_WORD *)&configstruc + 515) = get_word("Maximum DSS memory in KB: ");
break;
case 'S':
goto LABEL_84;
case 'X':
cfgphase = 0;
break;
default:
continue;
}
continue;
case 3:
show_file_menu();
switch ( (unsigned __int8)func0() )
{
case 'A':
*((_WORD *)&configstruc + 516) = (unsigned __int8)get_yesno(
"Enable writing one second data to seneca.sec (y/N): ",
0LL);
break;
case 'B':
*((_WORD *)&configstruc + 517) = (unsigned __int8)get_yesno(
"Enable writing 512 byte MiniSeed to seneca.mseed (y/N): ",
0LL);
break;
case 'C':
*((_WORD *)&configstruc + 518) = (unsigned __int8)get_yesno(
"Enable writing 4096 byte MiniSeed to individual files (y/N): ",
0LL);
break;
case 'D':
*((_WORD *)&configstruc + 519) = (unsigned __int8)get_yesno(
"Enable NetServer if configured in tokens (y/N): ",
0LL);
break;
case 'E':
*((_WORD *)&configstruc + 520) = get_word("POC Receiver port (zero to disable, standard is 2254): ");
break;
case 'S':
LABEL_84:
save_configuration();
break;
case 'X':
cfgphase = 0;
break;
default:
continue;
}
continue;
case 4:
show_run_menu();
result = (unsigned __int8)(func0() - 65);
switch ( (char)result )
{
case 0:
arp_status();
continue;
case 2:
lib_abort_command(context);
continue;
case 3:
LABEL_6:
dump_messages();
continue;
case 5:
if ( current_state == 10 )
lib_flush_data(context);
continue;
case 6:
send_tunneled_request();
continue;
case 7:
if ( current_state == 10 )
show_detectors();
continue;
case 8:
if ( current_state == 10 )
lib_set_freeze_timer(context, 30LL);
continue;
case 11:
show_lcqs();
continue;
case 12:
LABEL_9:
show_modules();
continue;
case 14:
screen_busy = 1;
show_opstat();
screen_busy = 0;
continue;
case 15:
pingreq = 0;
*((_WORD *)&pingreq + 1) = 0;
*((_DWORD *)&pingreq + 1) = 0;
lib_ping_request(context, &pingreq);
continue;
case 16:
if ( context )
continue;
if ( poc_context )
{
puts("POC Receiver Stopped");
result = lib_poc_stop(poc_context);
}
break;
case 18:
lib_change_state(context, 0LL, 27LL);
cfgphase = 0;
continue;
case 20:
screen_busy = 1;
printf("Message: ");
get_line(&line);
lib_send_usermessage(context, &line);
screen_busy = 0;
continue;
case 21:
screen_busy = 1;
v11 = get_verbosity();
*((_WORD *)&configstruc + 187) = lib_change_verbosity(context, v11);
screen_busy = 0;
continue;
default:
continue;
}
break;
default:
continue;
}
return result;
}
}

original_code:
void run_commands (void)
{
  tpoc_par poc_par ;
  string s ;
  uint16_t newverb ;
  enum tliberr err ;
  tpar_register *preg ;
  tpar_create *pcret ;
  uint16_t w ;
  preg = &(configstruc.par_register) ;
  pcret = &(configstruc.par_create) ;
  do {
    switch (cfgphase) {
      case CFG_IDLE :
        show_idle_menu () ;
        switch (get_command_char()) {
          case 'C' :
            if (context == 0)

                cfgphase = CFG_CREATE ;
            break ;
          case 'D' :
            if (context)

                dump_messages () ;
            break ;
          case 'E' :
            cfgphase = CFG_REG ;
            break ;
          case 'F' :
            cfgphase = CFG_FILE ;
            break ;
          case 'M' :
            show_modules () ;
            break ;
          case 'O' :
            if (context)

                show_opstat () ;
            break ;
          case 'P' :
            if (context)

                {
                  if (preg->opt_dynamic_ip)

                      preg->q330id_address[0] = 0 ;
                  pcret->resp_err = lib_unregistered_ping (context, preg) ;
                  if (pcret->resp_err != LIBERR_NOERR)

                      printf ("Error Pinging Station: %s\n", lib_get_errstr(pcret->resp_err, &(s))) ;
                }
            break ;
          case 'Q' :
            if (poc_context)

                {
                  printf ("POC Receiver Stopped\n") ;
                  lib_poc_stop (poc_context) ;
                }
            if (context)

                lib_destroy_context (&(context)) ;
            return ;
          case 'S' :
            if (context)

                {
                  if (preg->opt_dynamic_ip)

                      preg->q330id_address[0] = 0 ;
                  err = lib_register (context, preg) ;
                  if (err == LIBERR_NOERR)

                      cfgphase = CFG_RUN ;
                    else
                      printf ("Error Starting Connection: %s\n", lib_get_errstr(err, &(s))) ;
                }
            break ;
          case 'T' :
            if (context == 0)

                {
                  pcret->call_state = sen_state_callback ;
                  pcret->call_messages = msgs_callback ;
                  pcret->call_baler = 0 ;
                  pcret->mini_firchain = 0 ;
                  fowner.call_fileacc = sen_file_callback ;
                  fowner.station_ptr = 0 ;
                  pcret->file_owner = &(fowner) ;
                  pcret->call_minidata = mini_callback ;
                  if (configstruc.write_archive)

                      pcret->call_aminidata = amini_callback ;
                    else
                      pcret->call_aminidata = 0 ;
                  if (configstruc.write_mseed)

                      mseed_file = lib_file_open (0, "seneca.mseed", 1 | 8) ;
                    else
                      mseed_file = -1 ;
                  if (configstruc.write_1sec)

                      {
                        pcret->call_secdata = onesec_callback ;
                        onesec_file = lib_file_open (0, "seneca.sec", 1 | 8) ;
                      }
                    else
                      {
                        pcret->call_secdata = 0 ;
                        onesec_file = -1 ;
                      }
                  lib_create_context (&(context), pcret) ;
                  if (pcret->resp_err == LIBERR_NOERR)

                      {
                        printf ("Station Thread Created\n") ;
                        cfgphase = CFG_IDLE ;
                        if (configstruc.poc_port)

                            {
                              poc_par.poc_port = configstruc.poc_port ;
                              poc_par.poc_callback = poc_handler ;
                              poc_context = lib_poc_start (&(poc_par)) ;
                              printf ("POC Receiver Started\n") ;
                            }
                      }
                    else
                      {
                        context = 0 ;
                        printf ("Error creating station thread: %s\n", lib_get_errstr(pcret->resp_err, &(s))) ;
                      }
                }
              else
                lib_change_state (context, LIBSTATE_TERM, LIBERR_CLOSED) ;
            break ;
        }
        break ;
      case CFG_CREATE :
        show_create_pars () ;
        switch (get_command_char()) {
          case 'A' :
            get_t64 ("Serial number: ", &(pcret->q330id_serial)) ;
            break ;
          case 'B' :
            w = get_word ("Data port (1-4): ") ;
            w = w - 1 ;
            pcret->q330id_dataport = w ;
            break ;
          case 'C' :
            get_string("Station name (3-5 characters): ", 5, &(pcret->q330id_station)) ;
            lib330_upper(&(pcret->q330id_station)) ;
            break ;
          case 'D' :
            pcret->host_timezone = get_integer ("Timezone offset in seconds: ") ;
            break ;
          case 'E' :
            get_string("Host software name: ", 95, &(pcret->host_software)) ;
            break ;
          case 'F' :
            get_string("Continuity file name (Null to disable): ", 250, &(pcret->opt_contfile)) ;
            break ;
          case 'G' :
            pcret->opt_verbose = get_verbosity () ;
            break ;
          case 'H' :
            pcret->amini_512highest = get_frequency ("Highest frequency for incremental update: ") ;
            break ;
          case 'I' :
            pcret->mini_embed = get_yesno("Embed blockettes (Y/n): ", 1) ;
            break ;
          case 'J' :
            pcret->mini_separate = get_yesno("Separate blockettes (y/N): ", 0) ;
            break ;
          case 'K' :
            pcret->opt_zoneadjust = get_yesno("Calculate host timezone automatically (Y/n): ", 1) ;
            break ;
          case 'L' : pcret->opt_secfilter = get_onesec_filter () ;
            break ;
          case 'M' :
            pcret->opt_minifilter = get_seed_filter ("512 byte MiniSeed data filter: ") ;
            break ;
          case 'N' :
            pcret->opt_aminifilter = get_seed_filter ("Archival MiniSeed data filter: ") ;
            break ;
          case 'S' :
            save_configuration () ;
            break ;
          case 'X' :
            cfgphase = CFG_IDLE ;
            break ;
        }
        break ;
      case CFG_REG :
        show_register_pars () ;
        switch (get_command_char()) {
          case 'A' :
            get_t64("Authentication code: ", &(preg->q330id_auth)) ;
            break ;
          case 'B' :
            get_string("Q330 IP address: ", 250, &(preg->q330id_address)) ;
            break ;
          case 'C' :
            preg->q330id_baseport = get_word ("Q330 base port: ") ;
            break ;
          case 'E' :
            get_string("Host interface: ", 250, &(preg->host_interface)) ;
            break ;
          case 'F' :
            preg->host_mincmdretry = get_timeout("Host minimum command timeout: ") ;
            break ;
          case 'G' :
            preg->host_maxcmdretry = get_timeout("Host maximum command timeout: ") ;
            break ;
          case 'H' :
            preg->host_ctrlport = get_word("Host control port (0 for automatic): ") ;
            break ;
          case 'I' :
            preg->host_dataport = get_word("Host data port (0 for automatic): ") ;
            break ;
          case 'J' :
            preg->opt_dynamic_ip = get_yesno("Q330 has dynamic IP address (y/N): ", 0) ;
            break ;
          case 'K' :
            preg->opt_hibertime = get_word("Hibernate time in minutes: ") ;
            break ;
          case 'L' :
            preg->opt_conntime = get_word("Maximum connection time in minutes: ") ;
            break ;
          case 'M' :
            preg->opt_connwait = get_word("Connection wait time in minutes: ") ;
            break ;
          case 'N' :
            preg->opt_regattempts = get_word("Maximum registration attempts before hibernation: ") ;
            break ;
          case 'O' :
            preg->opt_ipexpire = get_word("Dynamic IP address expiration in minutes: ") ;
            break ;
          case 'P' :
            preg->opt_buflevel = get_word("Buffer level to stop connection: ") ;
            break ;
          case 'Q' :
            preg->opt_q330_cont = get_word("Minutes before writing Q330 continuity to file: ") ;
            break ;
          case 'R' :
            preg->opt_dss_memory = get_word("Maximum DSS memory in KB: ") ;
            break ;
          case 'S' :
            save_configuration () ;
            break ;
          case 'X' :
            cfgphase = CFG_IDLE ;
            break ;
        }
        break ;
      case CFG_FILE :
        show_file_menu () ;
        switch (get_command_char()) {
          case 'A' :
            configstruc.write_1sec = get_yesno("Enable writing one second data to seneca.sec (y/N): ", 0) ;
            break ;
          case 'B' :
            configstruc.write_mseed = get_yesno("Enable writing 512 byte MiniSeed to seneca.mseed (y/N): ", 0) ;
            break ;
          case 'C' :
            configstruc.write_archive = get_yesno("Enable writing 4096 byte MiniSeed to individual files (y/N): ", 0) ;
            break ;
          case 'D' :
            configstruc.run_netserver = get_yesno("Enable NetServer if configured in tokens (y/N): ", 0) ;
            break ;
          case 'E' :
            configstruc.poc_port = get_word("POC Receiver port (zero to disable, standard is 2254): ") ;
            break ;
          case 'S' :
            save_configuration () ;
            break ;
          case 'X' :
            cfgphase = CFG_IDLE ;
            break ;
        }
        break ;
      case CFG_RUN :
        show_run_menu () ;
        switch (get_command_char()) {
          case 'A' :
            arp_status () ;
            break ;
          case 'C' :
            lib_abort_command (context) ;
            break ;
          case 'D' :
            dump_messages () ;
            break ;
          case 'G' :
            send_tunneled_request () ;
            break ;
          case 'F' :
            if (current_state == LIBSTATE_RUN)

                lib_flush_data (context) ;
            break ;
          case 'H' :
            if (current_state == LIBSTATE_RUN)

                show_detectors () ;
            break ;
          case 'I' :
            if (current_state == LIBSTATE_RUN)

                lib_set_freeze_timer (context, 30) ;
            break ;
          case 'L' :
            show_lcqs () ;
            break ;
          case 'M' :
            show_modules () ;
            break ;
          case 'O' :
            screen_busy = 1 ;
            show_opstat () ;
            screen_busy = 0 ;
            break ;
          case 'P' :
            pingreq.pingtype = 0 ;
            pingreq.pingopt = 0 ;
            pingreq.pingreqmap = 0 ;
            lib_ping_request (context, &(pingreq)) ;
            break ;
          case 'Q' :
            if (context == 0)

                {
                  if (poc_context)

                      {
                        printf ("POC Receiver Stopped\n") ;
                        lib_poc_stop (poc_context) ;
                      }
                  return ;
                }
            break ;
          case 'S' :
            lib_change_state (context, LIBSTATE_IDLE, LIBERR_CLOSED) ;
            cfgphase = CFG_IDLE ;
            break ;
          case 'U' :
            screen_busy = 1 ;
            printf ("Message: ") ;
            get_line(line) ;
            lib_send_usermessage (context, &(line)) ;
            screen_busy = 0 ;
            break ;
          case 'V' :
            screen_busy = 1 ;
            newverb = get_verbosity () ;
            configstruc.par_create.opt_verbose = lib_change_verbosity (context, newverb) ;
            screen_busy = 0 ;
            break ;
        }
        break ;
    }
  } while (! 0) ;
}

canonical_original_code:
void run_commands()
{
  struct tpoc_par poc_par;
  char s[256];
  unsigned short newverb;
  enum tliberr err;
  struct tpar_register *preg;
  struct tpar_create *pcret;
  unsigned short w;
  preg = &(configstruc.par_register) ;
  pcret = &(configstruc.par_create) ;
  do {
    switch (cfgphase) {
      case CFG_IDLE :
        show_idle_menu () ;
        switch (get_command_char()) {
          case 'C' :
            if (context == 0)

                cfgphase = CFG_CREATE ;
            break ;
          case 'D' :
            if (context)

                dump_messages () ;
            break ;
          case 'E' :
            cfgphase = CFG_REG ;
            break ;
          case 'F' :
            cfgphase = CFG_FILE ;
            break ;
          case 'M' :
            show_modules () ;
            break ;
          case 'O' :
            if (context)

                show_opstat () ;
            break ;
          case 'P' :
            if (context)

                {
                  if (preg->opt_dynamic_ip)

                      preg->q330id_address[0] = 0 ;
                  pcret->resp_err = lib_unregistered_ping (context, preg) ;
                  if (pcret->resp_err != LIBERR_NOERR)

                      printf ("Error Pinging Station: %s\n", lib_get_errstr(pcret->resp_err, &(s))) ;
                }
            break ;
          case 'Q' :
            if (poc_context)

                {
                  printf ("POC Receiver Stopped\n") ;
                  lib_poc_stop (poc_context) ;
                }
            if (context)

                lib_destroy_context (&(context)) ;
            return ;
          case 'S' :
            if (context)

                {
                  if (preg->opt_dynamic_ip)

                      preg->q330id_address[0] = 0 ;
                  err = lib_register (context, preg) ;
                  if (err == LIBERR_NOERR)

                      cfgphase = CFG_RUN ;
                    else
                      printf ("Error Starting Connection: %s\n", lib_get_errstr(err, &(s))) ;
                }
            break ;
          case 'T' :
            if (context == 0)

                {
                  pcret->call_state = sen_state_callback ;
                  pcret->call_messages = msgs_callback ;
                  pcret->call_baler = 0 ;
                  pcret->mini_firchain = 0 ;
                  fowner.call_fileacc = sen_file_callback ;
                  fowner.station_ptr = 0 ;
                  pcret->file_owner = &(fowner) ;
                  pcret->call_minidata = mini_callback ;
                  if (configstruc.write_archive)

                      pcret->call_aminidata = amini_callback ;
                    else
                      pcret->call_aminidata = 0 ;
                  if (configstruc.write_mseed)

                      mseed_file = lib_file_open (0, "seneca.mseed", 1 | 8) ;
                    else
                      mseed_file = -1 ;
                  if (configstruc.write_1sec)

                      {
                        pcret->call_secdata = onesec_callback ;
                        onesec_file = lib_file_open (0, "seneca.sec", 1 | 8) ;
                      }
                    else
                      {
                        pcret->call_secdata = 0 ;
                        onesec_file = -1 ;
                      }
                  lib_create_context (&(context), pcret) ;
                  if (pcret->resp_err == LIBERR_NOERR)

                      {
                        printf ("Station Thread Created\n") ;
                        cfgphase = CFG_IDLE ;
                        if (configstruc.poc_port)

                            {
                              poc_par.poc_port = configstruc.poc_port ;
                              poc_par.poc_callback = poc_handler ;
                              poc_context = lib_poc_start (&(poc_par)) ;
                              printf ("POC Receiver Started\n") ;
                            }
                      }
                    else
                      {
                        context = 0 ;
                        printf ("Error creating station thread: %s\n", lib_get_errstr(pcret->resp_err, &(s))) ;
                      }
                }
              else
                lib_change_state (context, LIBSTATE_TERM, LIBERR_CLOSED) ;
            break ;
        }
        break ;
      case CFG_CREATE :
        show_create_pars () ;
        switch (get_command_char()) {
          case 'A' :
            get_t64 ("Serial number: ", &(pcret->q330id_serial)) ;
            break ;
          case 'B' :
            w = get_word ("Data port (1-4): ") ;
            w = w - 1 ;
            pcret->q330id_dataport = w ;
            break ;
          case 'C' :
            get_string("Station name (3-5 characters): ", 5, &(pcret->q330id_station)) ;
            lib330_upper(&(pcret->q330id_station)) ;
            break ;
          case 'D' :
            pcret->host_timezone = get_integer ("Timezone offset in seconds: ") ;
            break ;
          case 'E' :
            get_string("Host software name: ", 95, &(pcret->host_software)) ;
            break ;
          case 'F' :
            get_string("Continuity file name (Null to disable): ", 250, &(pcret->opt_contfile)) ;
            break ;
          case 'G' :
            pcret->opt_verbose = get_verbosity () ;
            break ;
          case 'H' :
            pcret->amini_512highest = get_frequency ("Highest frequency for incremental update: ") ;
            break ;
          case 'I' :
            pcret->mini_embed = get_yesno("Embed blockettes (Y/n): ", 1) ;
            break ;
          case 'J' :
            pcret->mini_separate = get_yesno("Separate blockettes (y/N): ", 0) ;
            break ;
          case 'K' :
            pcret->opt_zoneadjust = get_yesno("Calculate host timezone automatically (Y/n): ", 1) ;
            break ;
          case 'L' : pcret->opt_secfilter = get_onesec_filter () ;
            break ;
          case 'M' :
            pcret->opt_minifilter = get_seed_filter ("512 byte MiniSeed data filter: ") ;
            break ;
          case 'N' :
            pcret->opt_aminifilter = get_seed_filter ("Archival MiniSeed data filter: ") ;
            break ;
          case 'S' :
            save_configuration () ;
            break ;
          case 'X' :
            cfgphase = CFG_IDLE ;
            break ;
        }
        break ;
      case CFG_REG :
        show_register_pars () ;
        switch (get_command_char()) {
          case 'A' :
            get_t64("Authentication code: ", &(preg->q330id_auth)) ;
            break ;
          case 'B' :
            get_string("Q330 IP address: ", 250, &(preg->q330id_address)) ;
            break ;
          case 'C' :
            preg->q330id_baseport = get_word ("Q330 base port: ") ;
            break ;
          case 'E' :
            get_string("Host interface: ", 250, &(preg->host_interface)) ;
            break ;
          case 'F' :
            preg->host_mincmdretry = get_timeout("Host minimum command timeout: ") ;
            break ;
          case 'G' :
            preg->host_maxcmdretry = get_timeout("Host maximum command timeout: ") ;
            break ;
          case 'H' :
            preg->host_ctrlport = get_word("Host control port (0 for automatic): ") ;
            break ;
          case 'I' :
            preg->host_dataport = get_word("Host data port (0 for automatic): ") ;
            break ;
          case 'J' :
            preg->opt_dynamic_ip = get_yesno("Q330 has dynamic IP address (y/N): ", 0) ;
            break ;
          case 'K' :
            preg->opt_hibertime = get_word("Hibernate time in minutes: ") ;
            break ;
          case 'L' :
            preg->opt_conntime = get_word("Maximum connection time in minutes: ") ;
            break ;
          case 'M' :
            preg->opt_connwait = get_word("Connection wait time in minutes: ") ;
            break ;
          case 'N' :
            preg->opt_regattempts = get_word("Maximum registration attempts before hibernation: ") ;
            break ;
          case 'O' :
            preg->opt_ipexpire = get_word("Dynamic IP address expiration in minutes: ") ;
            break ;
          case 'P' :
            preg->opt_buflevel = get_word("Buffer level to stop connection: ") ;
            break ;
          case 'Q' :
            preg->opt_q330_cont = get_word("Minutes before writing Q330 continuity to file: ") ;
            break ;
          case 'R' :
            preg->opt_dss_memory = get_word("Maximum DSS memory in KB: ") ;
            break ;
          case 'S' :
            save_configuration () ;
            break ;
          case 'X' :
            cfgphase = CFG_IDLE ;
            break ;
        }
        break ;
      case CFG_FILE :
        show_file_menu () ;
        switch (get_command_char()) {
          case 'A' :
            configstruc.write_1sec = get_yesno("Enable writing one second data to seneca.sec (y/N): ", 0) ;
            break ;
          case 'B' :
            configstruc.write_mseed = get_yesno("Enable writing 512 byte MiniSeed to seneca.mseed (y/N): ", 0) ;
            break ;
          case 'C' :
            configstruc.write_archive = get_yesno("Enable writing 4096 byte MiniSeed to individual files (y/N): ", 0) ;
            break ;
          case 'D' :
            configstruc.run_netserver = get_yesno("Enable NetServer if configured in tokens (y/N): ", 0) ;
            break ;
          case 'E' :
            configstruc.poc_port = get_word("POC Receiver port (zero to disable, standard is 2254): ") ;
            break ;
          case 'S' :
            save_configuration () ;
            break ;
          case 'X' :
            cfgphase = CFG_IDLE ;
            break ;
        }
        break ;
      case CFG_RUN :
        show_run_menu () ;
        switch (get_command_char()) {
          case 'A' :
            arp_status () ;
            break ;
          case 'C' :
            lib_abort_command (context) ;
            break ;
          case 'D' :
            dump_messages () ;
            break ;
          case 'G' :
            send_tunneled_request () ;
            break ;
          case 'F' :
            if (current_state == LIBSTATE_RUN)

                lib_flush_data (context) ;
            break ;
          case 'H' :
            if (current_state == LIBSTATE_RUN)

                show_detectors () ;
            break ;
          case 'I' :
            if (current_state == LIBSTATE_RUN)

                lib_set_freeze_timer (context, 30) ;
            break ;
          case 'L' :
            show_lcqs () ;
            break ;
          case 'M' :
            show_modules () ;
            break ;
          case 'O' :
            screen_busy = 1 ;
            show_opstat () ;
            screen_busy = 0 ;
            break ;
          case 'P' :
            pingreq.pingtype = 0 ;
            pingreq.pingopt = 0 ;
            pingreq.pingreqmap = 0 ;
            lib_ping_request (context, &(pingreq)) ;
            break ;
          case 'Q' :
            if (context == 0)

                {
                  if (poc_context)

                      {
                        printf ("POC Receiver Stopped\n") ;
                        lib_poc_stop (poc_context) ;
                      }
                  return ;
                }
            break ;
          case 'S' :
            lib_change_state (context, LIBSTATE_IDLE, LIBERR_CLOSED) ;
            cfgphase = CFG_IDLE ;
            break ;
          case 'U' :
            screen_busy = 1 ;
            printf ("Message: ") ;
            get_line(line) ;
            lib_send_usermessage (context, &(line)) ;
            screen_busy = 0 ;
            break ;
          case 'V' :
            screen_busy = 1 ;
            newverb = get_verbosity () ;
            configstruc.par_create.opt_verbose = lib_change_verbosity (context, newverb) ;
            screen_busy = 0 ;
            break ;
        }
        break ;
    }
  } while (! 0) ;
}

variable_types: struct tpoc_par { unsigned short poc_port; void (*poc_callback)(enum tpocstate { PS_NEWPOC=0, PS_CONNRESET=1 } pocstate, struct tpoc_recvd { unsigned int serial_number[2]; unsigned int ip_address; unsigned short base_port; unsigned short data_port; } *poc_recv); }

variable_types:
newverb
unsigned short

variable_types: struct tpar_register { unsigned int q330id_auth[2]; char q330id_address[250]; unsigned short q330id_baseport; enum thost_mode { HOST_ETH=0, HOST_SER=1, HOST_TCP=2 } host_mode; char host_interface[250]; unsigned short host_mincmdretry; unsigned short host_maxcmdretry; unsigned short host_ctrlport; unsigned short host_dataport; unsigned short opt_latencytarget; unsigned short opt_closedloop; unsigned short opt_dynamic_ip; unsigned short opt_hibertime; unsigned short opt_conntime; unsigned short opt_connwait; unsigned short opt_regattempts; unsigned short opt_ipexpire; unsigned short opt_buflevel; unsigned short opt_q330_cont; unsigned short opt_dss_memory; } *

variable_types: struct tpar_create { unsigned int q330id_serial[2]; unsigned short q330id_dataport; char q330id_station[6]; int host_timezone; char host_software[96]; char opt_contfile[250]; unsigned short opt_verbose; unsigned short opt_zoneadjust; unsigned short opt_secfilter; unsigned short opt_client_msgs; unsigned short opt_compat; unsigned short opt_minifilter; unsigned short opt_aminifilter; unsigned short amini_exponent; long amini_512highest; unsigned short mini_embed; unsigned short mini_separate; struct tfilter { struct tfilter *link; char fname[-1]; unsigned char fir_num; double coef[400]; int len; double gain; double dly; int dec; } *mini_firchain; void (*call_minidata)(void *p); void (*call_aminidata)(void *p); enum tliberr { LIBERR_NOERR=0, LIBERR_PERM=1, LIBERR_TMSERV=2, LIBERR_NOTR=3, LIBERR_INVREG=4, LIBERR_PAR=5, LIBERR_SNV=6, LIBERR_CTRL=7, LIBERR_SPEC=8, LIBERR_MEM=9, LIBERR_CIP=10, LIBERR_DNA=11, LIBERR_DB9=12, LIBERR_MEMEW=13, LIBERR_THREADERR=14, LIBERR_BADDIR=15, LIBERR_REGTO=16, LIBERR_STATTO=17, LIBERR_DATATO=18, LIBERR_NOSTAT=19, LIBERR_INVSTAT=20, LIBERR_CFGWAIT=21, LIBERR_INVCFG=22, LIBERR_TOKENS_CHANGE=23, LIBERR_INVAL_TOKENS=24, LIBERR_BUFSHUT=25, LIBERR_CONNSHUT=26, LIBERR_CLOSED=27, LIBERR_NETFAIL=28, LIBERR_TUNBUSY=29, LIBERR_INVCTX=30 } resp_err; void (*call_state)(void *p); void (*call_messages)(void *p); void (*call_secdata)(void *p); void (*call_lowlatency)(void *p); void (*call_baler)(void *p); struct tfile_owner { void (*call_fileacc)(void *p); void *station_ptr; } *file_owner; } *

variable_types:
w
unsigned short

user_defined_types: struct tpoc_par { unsigned short poc_port; void (*poc_callback)(enum tpocstate pocstate, struct tpoc_recvd *poc_recv); }

user_defined_types: struct tpar_register { unsigned int q330id_auth[2]; char q330id_address[250]; unsigned short q330id_baseport; enum thost_mode host_mode; char host_interface[250]; unsigned short host_mincmdretry; unsigned short host_maxcmdretry; unsigned short host_ctrlport; unsigned short host_dataport; unsigned short opt_latencytarget; unsigned short opt_closedloop; unsigned short opt_dynamic_ip; unsigned short opt_hibertime; unsigned short opt_conntime; unsigned short opt_connwait; unsigned short opt_regattempts; unsigned short opt_ipexpire; unsigned short opt_buflevel; unsigned short opt_q330_cont; unsigned short opt_dss_memory; }

user_defined_types: struct tpar_create { unsigned int q330id_serial[2]; unsigned short q330id_dataport; char q330id_station[6]; int host_timezone; char host_software[96]; char opt_contfile[250]; unsigned short opt_verbose; unsigned short opt_zoneadjust; unsigned short opt_secfilter; unsigned short opt_client_msgs; unsigned short opt_compat; unsigned short opt_minifilter; unsigned short opt_aminifilter; unsigned short amini_exponent; long amini_512highest; unsigned short mini_embed; unsigned short mini_separate; struct tfilter *mini_firchain; void (*call_minidata)(void *p); void (*call_aminidata)(void *p); enum tliberr resp_err; void (*call_state)(void *p); void (*call_messages)(void *p); void (*call_secdata)(void *p); void (*call_lowlatency)(void *p); void (*call_baler)(void *p); struct tfile_owner *file_owner; }


Upcase

decompiled_code:
void __fastcall Upcase(char *a1)
{
char *v1; // rbx
char v2; // di

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
*v1++ = toupper(v2);
v2 = *v1;
}
while ( *v1 );
}
}

canonical_decompiled_code:
void __fastcall func8(char *a1)
{
char *v1; // rbx
char v2; // di

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
*v1++ = toupper(v2);
v2 = *v1;
}
while ( *v1 );
}
}

original_code:
void Upcase(char *msg)
{
  int i;
  for (i=0; msg[i] != 0; i++)
    msg[i] = (char)toupper(msg[i]);
}

variable_types:
msg
char *

variable_types: i int