printusage

decompiled_code:
size_t __fastcall printusage(const char *a1)
{
fprintf(stderr, "Usage: %s [-O | --owner=username] [-T | --tag=tag] [-V | --target=tagname]\n", a1);
fwrite(" [-W | --warning=percentage] [-C | --critical=percentage]\n", 1uLL, 0x3AuLL, stderr);
return fwrite(" [-S | --cache=dir] [-P | --cmdline=path] [-H | --help]\n", 1uLL, 0x38uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
fprintf(stderr, "Usage: %s [-O | --owner=username] [-T | --tag=tag] [-V | --target=tagname]\n", a1);
fwrite(" [-W | --warning=percentage] [-C | --critical=percentage]\n", 1uLL, 0x3AuLL, stderr);
return fwrite(" [-S | --cache=dir] [-P | --cmdline=path] [-H | --help]\n", 1uLL, 0x38uLL, stderr);
}

original_code:
void printusage(const char *name){
    fprintf(stderr, "Usage: %s [-O | --owner=username] [-T | --tag=tag] [-V | --target=tagname]\n", name);
    fprintf(stderr, " [-W | --warning=percentage] [-C | --critical=percentage]\n");
    fprintf(stderr, " [-S | --cache=dir] [-P | --cmdline=path] [-H | --help]\n");
}

canonical_original_code:
void printusage(char *name){
    fprintf(stderr, "Usage: %s [-O | --owner=username] [-T | --tag=tag] [-V | --target=tagname]\n", name);
    fprintf(stderr, " [-W | --warning=percentage] [-C | --critical=percentage]\n");
    fprintf(stderr, " [-S | --cache=dir] [-P | --cmdline=path] [-H | --help]\n");
}


printmessage

repo: izak/monitortools

decompiled_code:
int __fastcall printmessage(const char *a1, const char *a2, unsigned int a3)
{
return printf("%s cpu %s: %d\n", a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, const char *a2, unsigned int a3)
{
return printf("%s cpu %s: %d\n", a1, a2, a3);
}

original_code:
void printmessage(const char *name, const char *stat, int u){
    printf("%s cpu %s: %d\n", name, stat, u);
}

canonical_original_code:
void printmessage(char *name, char *stat, int u){
    printf("%s cpu %s: %d\n", name, stat, u);
}

variable_types:
name
char *

variable_types:
stat
char *

variable_types: u int

return_type: void


repo: j-burrows/prime-number-library

decompiled_code:
int __fastcall print_list_llu(_QWORD *a1)
{
return fprint_list_llu(stdout, a1);
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1)
{
return func0(stdout, a1);
}

original_code:
void print_list_llu(list_llu* current){
 fprint_list_llu(stdout, current);
}

canonical_original_code:
void print_list_llu(struct list_llu *current){
 fprint_list_llu(stdout, current);
}

variable_types: struct list_llu { struct node_llu { unsigned long long value; struct node_llu *next; } *head; struct node_llu *tail; } *

user_defined_types: struct list_llu { struct node_llu *head; struct node_llu *tail; }


decompiled_code:
void __fastcall free_list_llu(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void free_list_llu(list_llu* list_deleting){
 node_llu* conductor, *prev;
 for( conductor = list_deleting->head; conductor != ((void *)0);){
  prev = conductor;
  conductor = conductor->next;
  free(prev);
  prev = ((void *)0);
 }
 free(list_deleting);
 list_deleting = ((void *)0);
}

canonical_original_code:
void free_list_llu(struct list_llu *list_deleting){
 struct node_llu *conductor; struct node_llu *prev;
 for( conductor = list_deleting->head; conductor != ((void *)0);){
  prev = conductor;
  conductor = conductor->next;
  free(prev);
  prev = ((void *)0);
 }
 free(list_deleting);
 list_deleting = ((void *)0);
}

variable_types: struct node_llu { unsigned long long value; struct node_llu *next; } *


decompiled_code:
__int64 __fastcall add_node_llu(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = init_node_llu(a2);
if ( !v2 )
return 0LL;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = v2;
*(_QWORD *)(a1 + 8) = v2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = init_node_llu(a2);
if ( !v2 )
return 0LL;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = v2;
*(_QWORD *)(a1 + 8) = v2;
return 1LL;
}

original_code:
int add_node_llu(list_llu* current, unsigned long long value_adding){
 node_llu* node_adding;
 if( (node_adding = init_node_llu(value_adding)) == ((void *)0)){
  return 0;
 }
 current->tail->next = node_adding;
 current->tail = node_adding;
 return 1;
}

canonical_original_code:
int add_node_llu(struct list_llu *current, unsigned long long value_adding){
 struct node_llu *node_adding;
 if( (node_adding = init_node_llu(value_adding)) == ((void *)0)){
  return 0;
 }
 current->tail->next = node_adding;
 current->tail = node_adding;
 return 1;
}

return_type: int

user_defined_types: struct node_llu { unsigned long long value; struct node_llu *next; }


decompiled_code:
__int64 __fastcall is_prime(_QWORD **a1, unsigned __int64 a2)
{
double v3; // xmm0_8
double v4; // xmm0_8
_QWORD *v5; // rsi
__int64 result; // rax

if ( (a2 & 0x8000000000000000LL) != 0LL )
v3 = (double)(int)(a2 & 1 | (a2 >> 1)) + (double)(int)(a2 & 1 | (a2 >> 1));
else
v3 = (double)(int)a2;
if ( v3 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
v5 = *a1;
result = 1LL;
if ( *a1 )
{
while ( *v5 <= (unsigned __int64)(int)v4 )
{
if ( !(a2 % *v5) )
return 0LL;
v5 = (_QWORD *)v5[1];
if ( !v5 )
return 1LL;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD **a1, unsigned __int64 a2)
{
double v3; // xmm0_8
double v4; // xmm0_8
_QWORD *v5; // rsi
__int64 result; // rax

if ( (a2 & 0x8000000000000000LL) != 0LL )
v3 = (double)(int)(a2 & 1 | (a2 >> 1)) + (double)(int)(a2 & 1 | (a2 >> 1));
else
v3 = (double)(int)a2;
if ( v3 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
v5 = *a1;
result = 1LL;
if ( *a1 )
{
while ( *v5 <= (unsigned __int64)(int)v4 )
{
if ( !(a2 % *v5) )
return 0LL;
v5 = (_QWORD *)v5[1];
if ( !v5 )
return 1LL;
}
result = 1LL;
}
return result;
}

original_code:
int is_prime(list_llu* primes, unsigned long long number){
 node_llu* conductor;
 int number_is_prime;
 int seeve;
 seeve = sqrt(number);
 number_is_prime = 1;
 for(conductor=primes->head; conductor!=((void *)0) && conductor->value <= seeve;
  conductor=conductor->next){
  if((number%(conductor->value))!=0){
   continue;
  }
  else{
   number_is_prime = 0;
   break;
  }
 }
 return number_is_prime;
}

canonical_original_code:
int is_prime(struct list_llu *primes, unsigned long long number){
 struct node_llu *conductor;
 int number_is_prime;
 int seeve;
 seeve = sqrt(number);
 number_is_prime = 1;
 for(conductor=primes->head; conductor!=((void *)0) && conductor->value <= seeve;
  conductor=conductor->next){
  if((number%(conductor->value))!=0){
   continue;
  }
  else{
   number_is_prime = 0;
   break;
  }
 }
 return number_is_prime;
}

variable_types:
number
unsigned long long

variable_types: seeve int


decompiled_code:
_BOOL8 __fastcall add_if_prime(_QWORD **a1, unsigned __int64 a2)
{
int v2; // edx
_BOOL8 result; // rax

v2 = is_prime(a1, a2);
result = 1LL;
if ( v2 )
result = (unsigned int)add_node_llu(a1, a2) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_QWORD **a1, unsigned __int64 a2)
{
int v2; // edx
_BOOL8 result; // rax

v2 = func0(a1, a2);
result = 1LL;
if ( v2 )
result = (unsigned int)add_node_llu(a1, a2) != 0;
return result;
}

original_code:
int add_if_prime(list_llu* primes, unsigned long long number){
 if(is_prime(primes,number)){
  if(add_node_llu(primes,number) == 0){
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
int add_if_prime(struct list_llu *primes, unsigned long long number){
 if(is_prime(primes,number)){
  if(add_node_llu(primes,number) == 0){
   return 0;
  }
 }
 return 1;
}


repo: j-mcnally/girara-osx

decompiled_code:
struct passwd *__fastcall girara_get_home_directory(char *name)
{
__int64 v1; // rax
__int64 v2; // rax
struct passwd *v3; // rbx
int v5; // eax
size_t v6; // rbp
char *v7; // r12
struct passwd *result; // [rsp+8h] [rbp-50h] BYREF
struct passwd resultbuf; // [rsp+10h] [rbp-48h] BYREF

if ( name && (v1 = g_get_user_name(), (unsigned int)g_strcmp0(name, v1)) )
{
v5 = sysconf(70);
if ( v5 < 0 )
v5 = 4096;
v6 = v5;
v7 = (char *)g_malloc0(v5);
getpwnam_r(name, &resultbuf, v7, v6, &result);
v3 = result;
if ( result )
v3 = (struct passwd *)g_strdup(resultbuf.pw_dir);
g_free(v7);
}
else
{
v2 = g_get_home_dir();
v3 = (struct passwd *)g_strdup(v2);
}
return v3;
}

canonical_decompiled_code:
struct passwd *__fastcall func0(char *name)
{
__int64 v1; // rax
__int64 v2; // rax
struct passwd *v3; // rbx
int v5; // eax
size_t v6; // rbp
char *v7; // r12
struct passwd *result; // [rsp+8h] [rbp-50h] BYREF
struct passwd resultbuf; // [rsp+10h] [rbp-48h] BYREF

if ( name && (v1 = g_get_user_name(), (unsigned int)g_strcmp0(name, v1)) )
{
v5 = sysconf(70);
if ( v5 < 0 )
v5 = 4096;
v6 = v5;
v7 = (char *)g_malloc0(v5);
getpwnam_r(name, &resultbuf, v7, v6, &result);
v3 = result;
if ( result )
v3 = (struct passwd *)g_strdup(resultbuf.pw_dir);
g_free(v7);
}
else
{
v2 = g_get_home_dir();
v3 = (struct passwd *)g_strdup(v2);
}
return v3;
}

original_code:
char*
girara_get_home_directory(const char* user)
{
  if (user == ((void *)0) || g_strcmp0(user, g_get_user_name()) == 0) {
    return g_strdup(g_get_home_dir());
  }
  struct passwd pwd;
  struct passwd* result;
  int bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
  if (bufsize < 0) {
    bufsize = 4096;
  }
  char* buffer = g_malloc0(sizeof(char) * bufsize);
  getpwnam_r(user, &pwd, buffer, bufsize, &result);
  if (result == ((void *)0)) {
    g_free(buffer);
    return ((void *)0);
  }
  char* dir = g_strdup(pwd.pw_dir);
  g_free(buffer);
  return dir;
}

canonical_original_code:
char *girara_get_home_directory(char *user)
{
  if (user == ((void *)0) || g_strcmp0(user, g_get_user_name()) == 0) {
    return g_strdup(g_get_home_dir());
  }
  struct passwd pwd;
  struct passwd *result;
  int bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
  if (bufsize < 0) {
    bufsize = 4096;
  }
  char *buffer = g_malloc0(sizeof(char) * bufsize);
  getpwnam_r(user, &pwd, buffer, bufsize, &result);
  if (result == ((void *)0)) {
    g_free(buffer);
    return ((void *)0);
  }
  char *dir = g_strdup(pwd.pw_dir);
  g_free(buffer);
  return dir;
}

variable_types:
user
char *

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

variable_types: bufsize int

variable_types:
buffer
char *

variable_types:
dir
char *

return_type: char *


decompiled_code:
__int64 __fastcall girara_fix_path(__int64 a1)
{
__int64 v1; // rbx
char v2; // al
__int64 v3; // rdi
__int64 v4; // rbp
char v5; // al
char *v6; // r13
struct passwd *v7; // r12

v1 = a1;
if ( a1 )
{
if ( *(_BYTE *)a1 == 126 )
{
if ( strlen((const char *)a1) <= 1 )
{
v4 = 1LL;
v6 = 0LL;
}
else
{
v2 = *(_BYTE *)(a1 + 1);
if ( v2 == 47 )
{
v4 = 1LL;
v6 = 0LL;
}
else
{
v3 = a1 + 1;
if ( v2 )
{
v4 = 1LL;
do
{
++v4;
v5 = *(_BYTE *)(v1 + v4);
}
while ( v5 && v5 != 47 );
}
else
{
v4 = 1LL;
}
v6 = (char *)g_strndup(v3, v4 - 1);
}
}
v7 = girara_get_home_directory(v6);
g_free(v6);
if ( v7 )
{
v1 = g_build_filename(v7, v1 + v4, 0LL);
g_free(v7);
}
else
{
v1 = g_strdup(v1);
}
}
else
{
v1 = g_strdup(a1);
}
}
return v1;
}

original_code:
char*
girara_fix_path(const char* path)
{
  if (path == ((void *)0)) {
    return ((void *)0);
  }
  char* rpath = ((void *)0);
  if (path[0] == '~') {
    const size_t len = strlen(path);
    char* user = ((void *)0);
    size_t idx = 1;
    if (len > 1 && path[1] != '/') {
      while (path[idx] && path[idx] != '/') {
        ++idx;
      }
      user = g_strndup(path + 1, idx - 1);
    }
    char* home_path = girara_get_home_directory(user);
    g_free(user);
    if (home_path == ((void *)0)) {
      return g_strdup(path);
    }
    rpath = g_build_filename(home_path, path + idx, ((void *)0));
    g_free(home_path);
  } else {
    rpath = g_strdup(path);
  }
  return rpath;
}

canonical_original_code:
char *girara_fix_path(char *path)
{
  if (path == ((void *)0)) {
    return ((void *)0);
  }
  char *rpath = ((void *)0);
  if (path[0] == '~') {
    unsigned long len = strlen(path);
    char *user = ((void *)0);
    unsigned long idx = 1;
    if (len > 1 && path[1] != '/') {
      while (path[idx] && path[idx] != '/') {
        ++idx;
      }
      user = g_strndup(path + 1, idx - 1);
    }
    char *home_path = girara_get_home_directory(user);
    g_free(user);
    if (home_path == ((void *)0)) {
      return g_strdup(path);
    }
    rpath = g_build_filename(home_path, path + idx, ((void *)0));
    g_free(home_path);
  } else {
    rpath = g_strdup(path);
  }
  return rpath;
}

variable_types:
path
char *

variable_types:
rpath
char *

variable_types:
len
unsigned long

variable_types:
idx
unsigned long


decompiled_code:
__int64 __fastcall girara_get_xdg_path(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rax

if ( a1 == 1 )
{
v4 = g_get_user_data_dir();
result = g_strdup(v4);
}
else if ( a1 <= 1 )
{
v5 = g_get_user_config_dir();
result = g_strdup(v5);
}
else
{
result = 0LL;
if ( a1 - 2 <= 1 )
{
v2 = g_getenv(VARS_3[a1]);
v3 = v2;
if ( v2 && (unsigned int)g_strcmp0(v2, &LC0) )
result = g_strdup(v3);
else
result = g_strdup(DEFAULTS_2[a1]);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rax

if ( a1 == 1 )
{
v4 = g_get_user_data_dir();
result = g_strdup(v4);
}
else if ( a1 <= 1 )
{
v5 = g_get_user_config_dir();
result = g_strdup(v5);
}
else
{
result = 0LL;
if ( a1 - 2 <= 1 )
{
v2 = g_getenv(VARS_3[a1]);
v3 = v2;
if ( v2 && (unsigned int)g_strcmp0(v2, &LC0) )
result = g_strdup(v3);
else
result = g_strdup(DEFAULTS_2[a1]);
}
}
return result;
}

original_code:
char*
girara_get_xdg_path(girara_xdg_path_t path)
{
  static const char* VARS[] = {
    "XDG_CONFIG_HOME",
    "XDG_DATA_HOME",
    "XDG_CONFIG_DIRS",
    "XDG_DATA_DIRS"
  };
  static const char* DEFAULTS[] = {
    "NOTUSED",
    "NOTUSED",
    "/etc/xdg",
    "/usr/local/share/:/usr/share",
  };
  switch (path) {
    case XDG_DATA:
      return g_strdup(g_get_user_data_dir());
    case XDG_CONFIG:
      return g_strdup(g_get_user_config_dir());
    case XDG_CONFIG_DIRS:
    case XDG_DATA_DIRS:
    {
      const char* tmp = g_getenv(VARS[path]);
      if (tmp == ((void *)0) || !g_strcmp0(tmp, "")) {
        return g_strdup(DEFAULTS[path]);
      }
      return g_strdup(tmp);
    }
  }
  return ((void *)0);
}

canonical_original_code:
char *girara_get_xdg_path(enum girara_xdg_path_t path)
{
  static char *VARS[] = {
    "XDG_CONFIG_HOME",
    "XDG_DATA_HOME",
    "XDG_CONFIG_DIRS",
    "XDG_DATA_DIRS"
  };
  static char *DEFAULTS[] = {
    "NOTUSED",
    "NOTUSED",
    "/etc/xdg",
    "/usr/local/share/:/usr/share",
  };
  switch (path) {
    case XDG_DATA:
      return g_strdup(g_get_user_data_dir());
    case XDG_CONFIG:
      return g_strdup(g_get_user_config_dir());
    case XDG_CONFIG_DIRS:
    case XDG_DATA_DIRS:
    {
      char *tmp = g_getenv(VARS[path]);
      if (tmp == ((void *)0) || !g_strcmp0(tmp, "")) {
        return g_strdup(DEFAULTS[path]);
      }
      return g_strdup(tmp);
    }
  }
  return ((void *)0);
}

variable_types: enum girara_xdg_path_t { XDG_CONFIG=0, XDG_DATA=1, XDG_CONFIG_DIRS=2, XDG_DATA_DIRS=3 }

variable_types:
VARS
char *[]

variable_types:
DEFAULTS
char *[]

variable_types:
tmp
char *


decompiled_code:
void __fastcall girara_clean_line(char *s)
{
char v1; // r14
int v2; // er13
unsigned int i; // ebp
const unsigned __int16 **v4; // rdx
char v5; // al

if ( s )
{
v1 = 1;
v2 = 0;
for ( i = 0; i < strlen(s); ++i )
{
v4 = _ctype_b_loc();
v5 = s[i];
if ( ((*v4)[v5] & 0x2000) != 0 )
{
if ( !v1 )
{
s[v2++] = 32;
v1 = 1;
}
}
else
{
s[v2++] = v5;
v1 = 0;
}
}
s[v2] = 0;
}
}

original_code:
void
girara_clean_line(char* line)
{
  if (line == ((void *)0)) {
    return;
  }
  unsigned int i = 0;
  unsigned int j = 0;
  _Bool ws_mode = 1;
  for(i = 0; i < strlen(line); i++) {
    if (((*__ctype_b_loc ())[(int) ((line[i]))] & (unsigned short int) _ISspace) != 0) {
      if (ws_mode) {
        continue;
      }
      line[j++] = ' ';
      ws_mode = 1;
    } else {
      line[j++] = line[i];
      ws_mode = 0;
    }
  }
  line[j] = '\0';
}

canonical_original_code:
void girara_clean_line(char *line)
{
  if (line == ((void *)0)) {
    return;
  }
  unsigned int i = 0;
  unsigned int j = 0;
  _Bool ws_mode = 1;
  for(i = 0; i < strlen(line); i++) {
    if (((*__ctype_b_loc ())[(int) ((line[i]))] & (unsigned short) _ISspace) != 0) {
      if (ws_mode) {
        continue;
      }
      line[j++] = ' ';
      ws_mode = 1;
    } else {
      line[j++] = line[i];
      ws_mode = 0;
    }
  }
  line[j] = '\0';
}

variable_types:
line
char *

variable_types:
i
unsigned int

variable_types:
j
unsigned int


decompiled_code:
void *__fastcall girara_safe_realloc(void **a1, size_t a2)
{
void *result; // rax

if ( !a1 )
return 0LL;
if ( a2 && (result = realloc(*a1, a2)) != 0LL )
{
*a1 = result;
}
else
{
free(*a1);
*a1 = 0LL;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(void **a1, size_t a2)
{
void *result; // rax

if ( !a1 )
return 0LL;
if ( a2 && (result = realloc(*a1, a2)) != 0LL )
{
*a1 = result;
}
else
{
free(*a1);
*a1 = 0LL;
result = 0LL;
}
return result;
}

original_code:
void*
girara_safe_realloc(void** ptr, size_t size)
{
  if(ptr == ((void *)0)) {
    return ((void *)0);
  }
  if (size == 0) {
    goto error_free;
  }
  void* tmp = realloc(*ptr, size);
  if(tmp == ((void *)0)) {
    goto error_free;
  }
  *ptr = tmp;
  return *ptr;
error_free:
  free(*ptr);
  *ptr = ((void *)0);
  return ((void *)0);
}

canonical_original_code:
void *girara_safe_realloc(void **ptr, unsigned long size)
{
  if(ptr == ((void *)0)) {
    return ((void *)0);
  }
  if (size == 0) {
    goto error_free;
  }
  void *tmp = realloc(*ptr, size);
  if(tmp == ((void *)0)) {
    goto error_free;
  }
  *ptr = tmp;
  return *ptr;
error_free:
  free(*ptr);
  *ptr = ((void *)0);
  return ((void *)0);
}

variable_types:
ptr
void **

variable_types:
size
unsigned long

variable_types:
tmp
void *

return_type: void *


decompiled_code:
__int64 __fastcall girara_xdg_open(_BYTE *a1)
{
unsigned int v1; // er12
_QWORD *v3; // rbp
__int64 v4; // rbx
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !a1 )
return 0;
v1 = 0;
if ( *a1 )
{
v3 = (_QWORD *)g_string_new("xdg-open ");
v4 = g_shell_quote(a1);
g_string_append(v3, v4);
g_free(v4);
v5[0] = 0LL;
LOBYTE(v1) = (unsigned int)g_spawn_command_line_async(*v3, v5) != 0;
if ( v5[0] )
{
girara_debug("girara_xdg_open", 0x55u, 2u, "Failed to execute command: %s", *(const char **)(v5[0] + 8));
g_error_free(v5[0]);
}
g_string_free(v3, 1LL);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1)
{
unsigned int v1; // er12
_QWORD *v3; // rbp
__int64 v4; // rbx
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !a1 )
return 0;
v1 = 0;
if ( *a1 )
{
v3 = (_QWORD *)g_string_new("xdg-open ");
v4 = g_shell_quote(a1);
g_string_append(v3, v4);
g_free(v4);
v5[0] = 0LL;
LOBYTE(v1) = (unsigned int)g_spawn_command_line_async(*v3, v5) != 0;
if ( v5[0] )
{
func7("girara_xdg_open", 0x55u, 2u, "Failed to execute command: %s", *(const char **)(v5[0] + 8));
g_error_free(v5[0]);
}
g_string_free(v3, 1LL);
}
return v1;
}

original_code:
_Bool
girara_xdg_open(const char* uri)
{
  if (uri == ((void *)0) || strlen(uri) == 0) {
    return 0;
  }
  GString* command = g_string_new("xdg-open ");
  char* tmp = g_shell_quote(uri);
  g_string_append(command, tmp);
  g_free(tmp);
  GError* error = ((void *)0);
  _Bool res = g_spawn_command_line_async(command->str, &error);
  if (error != ((void *)0)) {
    _girara_debug(__FUNCTION__, 85, GIRARA_WARNING, "Failed to execute command: %s", error->message);
    g_error_free(error);
  }
  g_string_free(command, (!(0)));
  return res;
}

canonical_original_code:
_Bool girara_xdg_open(char *uri)
{
  if (uri == ((void *)0) || strlen(uri) == 0) {
    return 0;
  }
  struct _GString *command = g_string_new("xdg-open ");
  char *tmp = g_shell_quote(uri);
  g_string_append(command, tmp);
  g_free(tmp);
  struct _GError *error = ((void *)0);
  _Bool res = g_spawn_command_line_async(command->str, &error);
  if (error != ((void *)0)) {
    _girara_debug(__FUNCTION__, 85, GIRARA_WARNING, "Failed to execute command: %s", error->message);
    g_error_free(error);
  }
  g_string_free(command, (!(0)));
  return res;
}

variable_types:
uri
char *

variable_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; } *

variable_types: struct _GError { unsigned int domain; int code; char *message; } *


decompiled_code:
__int64 girara_get_debug_level()
{
return (unsigned int)debug_level;
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)debug_level;
}

original_code:
girara_debug_level_t
girara_get_debug_level()
{
  return debug_level;
}

canonical_original_code:
enum girara_debug_level_e girara_get_debug_level()
{
  return debug_level;
}

return_type: enum girara_debug_level_e { GIRARA_DEBUG=0, GIRARA_INFO=1, GIRARA_WARNING=2, GIRARA_ERROR=3 }


decompiled_code:
void __fastcall girara_set_debug_level(int a1)
{
debug_level = a1;
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
debug_level = a1;
}

original_code:
void
girara_set_debug_level(girara_debug_level_t level)
{
  debug_level = level;
}

canonical_original_code:
void girara_set_debug_level(enum girara_debug_level_e level)
{
  debug_level = level;
}

variable_types: enum girara_debug_level_e { GIRARA_DEBUG=0, GIRARA_INFO=1, GIRARA_WARNING=2, GIRARA_ERROR=3 }


decompiled_code:
__int64 __fastcall girara_escape_string(char *a1)
{
char *v1; // rbp
__int64 *v2; // r12
char v3; // al
char v4; // bl

v1 = a1;
if ( !a1 )
return 0LL;
v2 = (__int64 *)g_string_new(&LC0);
v3 = *a1;
if ( *a1 )
{
do
{
++v1;
v4 = v3;
if ( strchr("\\ \t\"'", v3) )
g_string_append_c_inline(v2, 92);
g_string_append_c_inline(v2, v4);
v3 = *v1;
}
while ( *v1 );
}
return g_string_free(v2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(char *a1)
{
char *v1; // rbp
__int64 *v2; // r12
char v3; // al
char v4; // bl

v1 = a1;
if ( !a1 )
return 0LL;
v2 = (__int64 *)g_string_new(&LC0);
v3 = *a1;
if ( *a1 )
{
do
{
++v1;
v4 = v3;
if ( strchr("\\ \t\"'", v3) )
g_string_append_c_inline(v2, 92);
g_string_append_c_inline(v2, v4);
v3 = *v1;
}
while ( *v1 );
}
return g_string_free(v2, 0LL);
}

original_code:
char* girara_escape_string(const char* value)
{
  if (value == ((void *)0)) {
    return ((void *)0);
  }
  GString* str = g_string_new("");
  while (*value != '\0') {
    const char c = *value++;
    if (strchr("\\ \t\"\'", c) != ((void *)0)) {
      g_string_append_c_inline (str, '\\');
    }
    g_string_append_c_inline (str, c);
  }
  return g_string_free(str, (0));
}

canonical_original_code:
char *girara_escape_string(char *value)
{
  if (value == ((void *)0)) {
    return ((void *)0);
  }
  struct _GString *str = g_string_new("");
  while (*value != '\0') {
    char c = *value++;
    if (strchr("\\ \t\"\'", c) != ((void *)0)) {
      g_string_append_c_inline (str, '\\');
    }
    g_string_append_c_inline (str, c);
  }
  return g_string_free(str, (0));
}

variable_types:
value
char *

variable_types: c char

user_defined_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; }


decompiled_code:
__int64 girara_input_history_get_type_once()
{
__int64 v0; // rax

v0 = g_intern_static_string("GiraraInputHistory");
return g_type_register_static_simple(
80LL,
v0,
208LL,
girara_input_history_class_intern_init,
24LL,
girara_input_history_init,
0LL);
}

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

v0 = g_intern_static_string("GiraraInputHistory");
return g_type_register_static_simple(
80LL,
v0,
208LL,
girara_input_history_class_intern_init,
24LL,
girara_input_history_init,
0LL);
}

original_code: __attribute__((noinline)) static GType girara_input_history_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple (((GType) ((20) << (2))), g_intern_static_string ("GiraraInputHistory"), sizeof (GiraraInputHistoryClass), (GClassInitFunc)(void (*)(void)) girara_input_history_class_intern_init, sizeof (GiraraInputHistory), (GInstanceInitFunc)(void (*)(void)) girara_input_history_init, (GTypeFlags) 0); { {{};} } return g_define_type_id; }

canonical_original_code: static unsigned long girara_input_history_get_type_once() { unsigned long g_define_type_id = g_type_register_static_simple (((GType) ((20) << (2))), g_intern_static_string ("GiraraInputHistory"), sizeof (GiraraInputHistoryClass), (GClassInitFunc)(void (*)(void)) girara_input_history_class_intern_init, sizeof (GiraraInputHistory), (GInstanceInitFunc)(void (*)(void)) girara_input_history_init, (GTypeFlags) 0); { {{};} } return g_define_type_id; }

return_type: unsigned long


decompiled_code:
__int64 girara_input_history_get_type()
{
__int64 v1; // rax

if ( g_define_type_id__volatile_5 )
return g_define_type_id__volatile_5;
if ( (unsigned int)g_once_init_enter(&g_define_type_id__volatile_5) )
{
v1 = girara_input_history_get_type_once();
g_once_init_leave(&g_define_type_id__volatile_5, v1);
}
return g_define_type_id__volatile_5;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v1; // rax

if ( g_define_type_id__volatile_5 )
return g_define_type_id__volatile_5;
if ( (unsigned int)g_once_init_enter(&g_define_type_id__volatile_5) )
{
v1 = func0();
g_once_init_leave(&g_define_type_id__volatile_5, v1);
}
return g_define_type_id__volatile_5;
}

original_code: GType girara_input_history_get_type (void) { static volatile gsize g_define_type_id__volatile = 0; if ((__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_1[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? (gpointer) *(&g_define_type_id__volatile) : 0); (!(__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_2[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); guint64 gapg_temp = __atomic_load_8 ((&g_define_type_id__volatile), 5); (gpointer) gapg_temp; })) && g_once_init_enter (&g_define_type_id__volatile)); }))) { GType g_define_type_id = girara_input_history_get_type_once (); (__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_3[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? *(&g_define_type_id__volatile) = (g_define_type_id) : 0); g_once_init_leave ((&g_define_type_id__volatile), (gsize) (g_define_type_id)); })); } return g_define_type_id__volatile; }

canonical_original_code: unsigned long girara_input_history_get_type() { static unsigned long g_define_type_id__volatile = 0; if ((__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_1[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? (gpointer) *(&g_define_type_id__volatile) : 0); (!(__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_2[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); unsigned long gapg_temp = __atomic_load_8 ((&g_define_type_id__volatile), 5); (void *) gapg_temp; })) && g_once_init_enter (&g_define_type_id__volatile)); }))) { unsigned long g_define_type_id = girara_input_history_get_type_once (); (__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_3[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? *(&g_define_type_id__volatile) = (g_define_type_id) : 0); g_once_init_leave ((&g_define_type_id__volatile), (gsize) (g_define_type_id)); })); } return g_define_type_id__volatile; }


decompiled_code:
__int64 girara_input_history_io_get_type()
{
__int64 v1; // rax
__int64 v2; // rbx

if ( g_define_type_id__volatile_2 )
return g_define_type_id__volatile_2;
if ( (unsigned int)g_once_init_enter(&g_define_type_id__volatile_2) )
{
v1 = g_intern_static_string("GiraraInputHistoryIO");
v2 = g_type_register_static_simple(8LL, v1, 64LL, girara_input_history_io_default_init, 0LL, 0LL, 0LL);
g_type_interface_add_prerequisite(v2, 80LL);
g_once_init_leave(&g_define_type_id__volatile_2, v2);
}
return g_define_type_id__volatile_2;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v1; // rax
__int64 v2; // rbx

if ( g_define_type_id__volatile_2 )
return g_define_type_id__volatile_2;
if ( (unsigned int)g_once_init_enter(&g_define_type_id__volatile_2) )
{
v1 = g_intern_static_string("GiraraInputHistoryIO");
v2 = g_type_register_static_simple(8LL, v1, 64LL, girara_input_history_io_default_init, 0LL, 0LL, 0LL);
g_type_interface_add_prerequisite(v2, 80LL);
g_once_init_leave(&g_define_type_id__volatile_2, v2);
}
return g_define_type_id__volatile_2;
}

original_code: GType girara_input_history_io_get_type (void) { static volatile gsize g_define_type_id__volatile = 0; if ((__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_1[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? (gpointer) *(&g_define_type_id__volatile) : 0); (!(__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_2[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); guint64 gapg_temp = __atomic_load_8 ((&g_define_type_id__volatile), 5); (gpointer) gapg_temp; })) && g_once_init_enter (&g_define_type_id__volatile)); }))) { GType g_define_type_id = g_type_register_static_simple (((GType) ((2) << (2))), g_intern_static_string ("GiraraInputHistoryIO"), sizeof (GiraraInputHistoryIOInterface), (GClassInitFunc)(void (*)(void)) girara_input_history_io_default_init, 0, (GInstanceInitFunc)((void *)0), (GTypeFlags) 0); if (((GType) ((20) << (2))) != ((GType) ((0) << (2)))) g_type_interface_add_prerequisite (g_define_type_id, ((GType) ((20) << (2)))); { {;;} } (__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_3[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? *(&g_define_type_id__volatile) = (g_define_type_id) : 0); g_once_init_leave ((&g_define_type_id__volatile), (gsize) (g_define_type_id)); })); } return g_define_type_id__volatile; }

canonical_original_code: unsigned long girara_input_history_io_get_type() { static unsigned long g_define_type_id__volatile = 0; if ((__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_1[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? (gpointer) *(&g_define_type_id__volatile) : 0); (!(__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_2[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); unsigned long gapg_temp = __atomic_load_8 ((&g_define_type_id__volatile), 5); (void *) gapg_temp; })) && g_once_init_enter (&g_define_type_id__volatile)); }))) { unsigned long g_define_type_id = g_type_register_static_simple (((GType) ((2) << (2))), g_intern_static_string ("GiraraInputHistoryIO"), sizeof (GiraraInputHistoryIOInterface), (GClassInitFunc)(void (*)(void)) girara_input_history_io_default_init, 0, (GInstanceInitFunc)((void *)0), (GTypeFlags) 0); if (((GType) ((20) << (2))) != ((GType) ((0) << (2)))) g_type_interface_add_prerequisite (g_define_type_id, ((GType) ((20) << (2)))); { {;;} } (__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_3[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? *(&g_define_type_id__volatile) = (g_define_type_id) : 0); g_once_init_leave ((&g_define_type_id__volatile), (gsize) (g_define_type_id)); })); } return g_define_type_id__volatile; }


setup

decompiled_code:
__int64 setup()
{
return gtk_init(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func0()
{
return gtk_init(0LL, 0LL);
}

original_code:
void setup(void)
{
  gtk_init(((void *)0), ((void *)0));
}

canonical_original_code:
void setup()
{
  gtk_init(((void *)0), ((void *)0));
}


adjFreq

decompiled_code:
int __fastcall adjFreq(int a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
int v4; // ebx
unsigned int v5; // ebp
__syscall_slong_t v6; // rcx
float v7; // xmm0_4
int result; // eax
int *v9; // rax
char *v10; // rax
struct timex v11; // [rsp+0h] [rbp-F8h] BYREF

memset(&v11, 0, sizeof(v11));
v2 = sysconf(2);
v3 = 1000 * v2;
v4 = -50000000;
if ( a1 >= -50000000 )
v4 = a1;
if ( v4 > 50000000 )
v4 = 50000000;
if ( !a2 )
{
v11.modes = 2;
v5 = 0;
LABEL_17:
v7 = ((double)v4 + 0.0) * 65.536;
v6 = (int)roundf(v7);
goto LABEL_18;
}
if ( a1 <= 500000 )
{
if ( a1 >= -500000 )
{
v5 = 0;
}
else
{
v5 = 0;
do
{
--v5;
v4 += v3;
}
while ( v4 < -500000 );
}
}
else
{
v5 = 0;
do
{
++v5;
v4 -= v3;
}
while ( v4 > 500000 );
}
v11.tick = (int)v5 + (unsigned __int64)(unsigned int)(int)(1000000.0 / (double)v2);
v11.modes = 16386;
v6 = 0LL;
if ( a2 != 2 )
goto LABEL_17;
LABEL_18:
v11.freq = v6;
printf("DEBUG: tickRes: %d\ttickAdj: %d\tt.freq: %ld\r\n", v3, v5, v6);
result = adjtimex(&v11);
if ( result < 0 )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf("Failed to adjtime %d ppm (%s)\r\n", (unsigned int)v4, v10);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
int v4; // ebx
unsigned int v5; // ebp
__syscall_slong_t v6; // rcx
float v7; // xmm0_4
int result; // eax
int *v9; // rax
char *v10; // rax
struct timex v11; // [rsp+0h] [rbp-F8h] BYREF

memset(&v11, 0, sizeof(v11));
v2 = sysconf(2);
v3 = 1000 * v2;
v4 = -50000000;
if ( a1 >= -50000000 )
v4 = a1;
if ( v4 > 50000000 )
v4 = 50000000;
if ( !a2 )
{
v11.modes = 2;
v5 = 0;
LABEL_17:
v7 = ((double)v4 + 0.0) * 65.536;
v6 = (int)roundf(v7);
goto LABEL_18;
}
if ( a1 <= 500000 )
{
if ( a1 >= -500000 )
{
v5 = 0;
}
else
{
v5 = 0;
do
{
--v5;
v4 += v3;
}
while ( v4 < -500000 );
}
}
else
{
v5 = 0;
do
{
++v5;
v4 -= v3;
}
while ( v4 > 500000 );
}
v11.tick = (int)v5 + (unsigned __int64)(unsigned int)(int)(1000000.0 / (double)v2);
v11.modes = 16386;
v6 = 0LL;
if ( a2 != 2 )
goto LABEL_17;
LABEL_18:
v11.freq = v6;
printf("DEBUG: tickRes: %d\ttickAdj: %d\tt.freq: %ld\r\n", v3, v5, v6);
result = adjtimex(&v11);
if ( result < 0 )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf("Failed to adjtime %d ppm (%s)\r\n", (unsigned int)v4, v10);
exit(1);
}
return result;
}

original_code:
void
adjFreq(int32_t adj, int utm)
{
    struct timex t;
    int32_t tickAdj = 0;
    int result;
    memset(&t, 0, sizeof(t));
    int32_t userHZ = sysconf(_SC_CLK_TCK);
    int32_t tickRes = userHZ * 1000;
    if (adj > (500000*100)){
        adj = (500000*100);
    } else if (adj < -(500000*100)){
        adj = -(500000*100);
    }
    if (utm) {
        if (adj > 500000){
            while (adj > 500000) {
                tickAdj++;
                adj -= tickRes;
            }
        } else if (adj < -500000){
            while (adj < -500000) {
                tickAdj--;
                adj += tickRes;
            }
        }
        t.tick = 1E6 / userHZ;
        t.tick += tickAdj;
        t.modes = 0x0002 | 0x4000;
    } else {
        t.modes = 0x0002;
    }
    if (utm == 2) {
        t.freq = 0;
    } else {
        t.freq = adj * ((1 << 16) / 1000);
        int t1 = t.freq;
        int t2;
        float f = (adj + 0.0) * (((1 << 16) + 0.0) / 1000.0);
        t2 = t1;
        t2 = (int)round(f);
        t.freq = t2;
    }
    printf("DEBUG: tickRes: %d\ttickAdj: %d\tt.freq: %ld\r\n", tickRes, tickAdj, t.freq);
    result = adjtimex(&t);
    if(result < 0) {
        printf("Failed to adjtime %d ppm (%s)\r\n", adj, strerror((*__errno_location ())));
        exit(1);
    }
}

canonical_original_code:
void adjFreq(int adj, int utm)
{
    struct timex t;
    int tickAdj = 0;
    int result;
    memset(&t, 0, sizeof(t));
    int userHZ = sysconf(_SC_CLK_TCK);
    int tickRes = userHZ * 1000;
    if (adj > (500000*100)){
        adj = (500000*100);
    } else if (adj < -(500000*100)){
        adj = -(500000*100);
    }
    if (utm) {
        if (adj > 500000){
            while (adj > 500000) {
                tickAdj++;
                adj -= tickRes;
            }
        } else if (adj < -500000){
            while (adj < -500000) {
                tickAdj--;
                adj += tickRes;
            }
        }
        t.tick = 1E6 / userHZ;
        t.tick += tickAdj;
        t.modes = 0x0002 | 0x4000;
    } else {
        t.modes = 0x0002;
    }
    if (utm == 2) {
        t.freq = 0;
    } else {
        t.freq = adj * ((1 << 16) / 1000);
        int t1 = t.freq;
        int t2;
        float f = (adj + 0.0) * (((1 << 16) + 0.0) / 1000.0);
        t2 = t1;
        t2 = (int)round(f);
        t.freq = t2;
    }
    printf("DEBUG: tickRes: %d\ttickAdj: %d\tt.freq: %ld\r\n", tickRes, tickAdj, t.freq);
    result = adjtimex(&t);
    if(result < 0) {
        printf("Failed to adjtime %d ppm (%s)\r\n", adj, strerror((*__errno_location ())));
        exit(1);
    }
}

variable_types: adj int

variable_types: utm int

variable_types: struct timex { unsigned int modes; long offset; long freq; long maxerror; long esterror; int status; long constant; long precision; long tolerance; struct timeval { long tv_sec; long tv_usec; } time; long tick; long ppsfreq; long jitter; int shift; long stabil; long jitcnt; long calcnt; long errcnt; long stbcnt; int tai; int; int; int; int; int; int; int; int; int; int; int; }

variable_types: tickAdj int

variable_types: result int

variable_types: userHZ int

variable_types: tickRes int

variable_types: f float

user_defined_types: struct timex { unsigned int modes; long offset; long freq; long maxerror; long esterror; int status; long constant; long precision; long tolerance; struct timeval time; long tick; long ppsfreq; long jitter; int shift; long stabil; long jitcnt; long calcnt; long errcnt; long stbcnt; int tai; int; int; int; int; int; int; int; int; int; int; int; }


measure

decompiled_code:
int __fastcall measure(unsigned int a1, unsigned int a2, int a3)
{
adjFreq(1000 * a1, a3);
printf("Measuring %d s with adjustment %d ppm\r\n", a2, a1);
clock_gettime(0, &ta);
clock_gettime(4, &tb);
usleep(1000000 * a2);
clock_gettime(0, &tp);
clock_gettime(4, &stru_4040B0);
return adjFreq(0, a3);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, unsigned int a2, int a3)
{
func7(1000 * a1, a3);
printf("Measuring %d s with adjustment %d ppm\r\n", a2, a1);
clock_gettime(0, &ta);
clock_gettime(4, &tb);
usleep(1000000 * a2);
clock_gettime(0, &tp);
clock_gettime(4, &stru_4040B0);
return func7(0, a3);
}

original_code:
void
measure(int adj, int slp, int utm) {
    adjFreq(adj * 1000, utm);
    printf("Measuring %d s with adjustment %d ppm\r\n", slp, adj);
    do { clock_gettime(0, &ta[0]); clock_gettime(4, &tb[0]); } while(0);
    usleep(slp * 1000000);
    do { clock_gettime(0, &ta[1]); clock_gettime(4, &tb[1]); } while(0);
    adjFreq(0, utm);
}

variable_types: slp int


diff

decompiled_code:
double __fastcall diff(_DWORD *a1, _DWORD *a2)
{
return (double)(*a2 - *a1) * 1000000000.0 + (double)(a2[2] - a1[2]);
}

canonical_decompiled_code:
double __fastcall func9(_DWORD *a1, _DWORD *a2)
{
return (double)(*a2 - *a1) * 1000000000.0 + (double)(a2[2] - a1[2]);
}

original_code:
double
diff(struct timespec * a, struct timespec * b) {
    return ((b->tv_sec - a->tv_sec)*1000000000.0 + (b->tv_nsec - a->tv_nsec));
}

canonical_original_code:
double diff(struct timespec *a, struct timespec *b) {
    return ((b->tv_sec - a->tv_sec)*1000000000.0 + (b->tv_nsec - a->tv_nsec));
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } *

variable_types:
b
struct timespec *

return_type: double


display

decompiled_code:
int __fastcall display(unsigned int a1, int a2, int a3)
{
double v4; // r12
double v6; // [rsp+8h] [rbp-20h]

v4 = diff(&ta, &tp) / (double)a2;
v6 = diff(&tb, &stru_4040B0) / (double)a2;
if ( a3 )
puts("tick and frequency adjustment\r");
else
puts("frequency adjustment only\r");
return printf("adjustment = %4d ppm -> measured drift = %8.3lf ppm\r\n", a1, (v4 - v6) / 1000.0);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1, int a2, int a3)
{
double v4; // r12
double v6; // [rsp+8h] [rbp-20h]

v4 = func9(&ta, &tp) / (double)a2;
v6 = func9(&tb, &stru_4040B0) / (double)a2;
if ( a3 )
puts("tick and frequency adjustment\r");
else
puts("frequency adjustment only\r");
return printf("adjustment = %4d ppm -> measured drift = %8.3lf ppm\r\n", a1, (v4 - v6) / 1000.0);
}

original_code:
void
display(int adj, int slp, int utm) {
    double da1, db1, da3, db3;
    da1 = diff(&ta[0], &ta[1]) / slp;
    db1 = diff(&tb[0], &tb[1]) / slp;
    if (utm ==0) {
        printf("frequency adjustment only\r\n");
    } else if (utm = 1) {
        printf("tick and frequency adjustment\r\n");
    } else {
        printf("tick adjustment only\r\n");
    }
    printf("adjustment = %4d ppm -> measured drift = %8.3lf ppm\r\n", adj, (da1-db1)/1000);
}

canonical_original_code:
void display(int adj, int slp, int utm) {
    double da1; double db1; double da3; double db3;
    da1 = diff(&ta[0], &ta[1]) / slp;
    db1 = diff(&tb[0], &tb[1]) / slp;
    if (utm ==0) {
        printf("frequency adjustment only\r\n");
    } else if (utm = 1) {
        printf("tick and frequency adjustment\r\n");
    } else {
        printf("tick adjustment only\r\n");
    }
    printf("adjustment = %4d ppm -> measured drift = %8.3lf ppm\r\n", adj, (da1-db1)/1000);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er13
int v5; // er12

if ( argc == 4 )
goto LABEL_2;
puts("usage:\r\n\tdrift [adj] [duration] [mode]\r");
puts("\t\t[adj]: adjustment in ppm (default 0ppm)\r");
puts("\t\t[duration]: duration of measurement in seconds (default 10s)\r");
puts("\t\t[mode]:\r");
puts("\t\t 0: use frequency adjustemnt only\r");
puts("\t\t 1: use frequency adjustemnt and tick adjustment\r");
puts("\t\t 2: use tick adjustment only\r");
puts("\r");
v3 = 0;
if ( argc > 1 )
LABEL_2:
v3 = atoi(argv[1]);
v4 = 10;
if ( argc > 2 )
v4 = atoi(argv[2]);
v5 = 0;
if ( argc > 3 )
v5 = atoi(argv[3]);
measure(v3, v4, v5);
display(v3, v4, v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er13
int v5; // er12

if ( argc == 4 )
goto LABEL_2;
puts("usage:\r\n\tdrift [adj] [duration] [mode]\r");
puts("\t\t[adj]: adjustment in ppm (default 0ppm)\r");
puts("\t\t[duration]: duration of measurement in seconds (default 10s)\r");
puts("\t\t[mode]:\r");
puts("\t\t 0: use frequency adjustemnt only\r");
puts("\t\t 1: use frequency adjustemnt and tick adjustment\r");
puts("\t\t 2: use tick adjustment only\r");
puts("\r");
v3 = 0;
if ( argc > 1 )
LABEL_2:
v3 = atoi(argv[1]);
v4 = 10;
if ( argc > 2 )
v4 = atoi(argv[2]);
v5 = 0;
if ( argc > 3 )
v5 = atoi(argv[3]);
func8(v3, v4, v5);
func10(v3, v4, v5);
return 0;
}

original_code:
int
main(int argc, char ** argv) {
    int adj = 0;
    int slp = 10;
    int utm = 0;
    if (argc != 4) {
        printf("usage:\r\n\tdrift [adj] [duration] [mode]\r\n");
        printf("\t\t[adj]:      adjustment in ppm (default 0ppm)\r\n");
        printf("\t\t[duration]: duration of measurement in seconds (default 10s)\r\n");
        printf("\t\t[mode]:\r\n");
        printf("\t\t            0: use frequency adjustemnt only\r\n");
        printf("\t\t            1: use frequency adjustemnt and tick adjustment\r\n");
        printf("\t\t            2: use tick adjustment only\r\n");
        printf("\r\n");
    }
    if (argc > 1) {
        adj = atoi(argv[1]);
    }
    if (argc > 2) {
        slp = atoi(argv[2]);
    }
    if (argc > 3) {
        utm = atoi(argv[3]);
    }
    measure(adj, slp, utm);
    display(adj, slp, utm);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    int adj = 0;
    int slp = 10;
    int utm = 0;
    if (argc != 4) {
        printf("usage:\r\n\tdrift [adj] [duration] [mode]\r\n");
        printf("\t\t[adj]:      adjustment in ppm (default 0ppm)\r\n");
        printf("\t\t[duration]: duration of measurement in seconds (default 10s)\r\n");
        printf("\t\t[mode]:\r\n");
        printf("\t\t            0: use frequency adjustemnt only\r\n");
        printf("\t\t            1: use frequency adjustemnt and tick adjustment\r\n");
        printf("\t\t            2: use tick adjustment only\r\n");
        printf("\r\n");
    }
    if (argc > 1) {
        adj = atoi(argv[1]);
    }
    if (argc > 2) {
        slp = atoi(argv[2]);
    }
    if (argc > 3) {
        utm = atoi(argv[3]);
    }
    measure(adj, slp, utm);
    display(adj, slp, utm);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall diff_timespec(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(a2[2] + 1000000000 * (*a2 - *a1) - a1[2]);
}

original_code:
int32_t
diff_timespec(struct timespec * a, struct timespec * b) {
 return (b->tv_sec - a->tv_sec)*1000000000 + (b->tv_nsec - a->tv_nsec);
}

canonical_original_code:
int diff_timespec(struct timespec *a, struct timespec *b) {
 return (b->tv_sec - a->tv_sec)*1000000000 + (b->tv_nsec - a->tv_nsec);
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


original_code:
int32_t
diff_timeval(struct timeval * a, struct timeval * b) {
 return (b->tv_sec - a->tv_sec)*1000000000 + (b->tv_usec - a->tv_usec)*1000;
}

canonical_original_code:
int diff_timeval(struct timeval *a, struct timeval *b) {
 return (b->tv_sec - a->tv_sec)*1000000000 + (b->tv_usec - a->tv_usec)*1000;
}

variable_types: struct timeval { long tv_sec; long tv_usec; } *

variable_types:
b
struct timeval *


decompiled_code:
int measure_clock_gettime()
{
int v0; // ebx
__int64 v1; // rdx
const char *v2; // rsi
__m128i v4; // [rsp+0h] [rbp-28h] BYREF
struct timespec tp; // [rsp+10h] [rbp-18h] BYREF

clock_gettime(0, &tp);
v4 = _mm_loadu_si128((const __m128i *)&tp);
if ( v4.m128i_i64[1] == tp.tv_nsec )
{
v0 = 0;
do
{
clock_gettime(0, &tp);
++v0;
}
while ( v4.m128i_i64[1] == tp.tv_nsec );
v1 = (unsigned int)diff_timespec(&v4, &tp);
v2 = (const char *)&unk_402004;
if ( v0 != 1 )
v2 = "";
}
else
{
v1 = (unsigned int)diff_timespec(&v4, &tp);
v2 = "\tclock_gettime: %s%d ns\r\n" + 25;
}
return printf("\tclock_gettime: %s%d ns\r\n", v2, v1);
}

canonical_decompiled_code:
int func9()
{
int v0; // ebx
__int64 v1; // rdx
const char *v2; // rsi
__m128i v4; // [rsp+0h] [rbp-28h] BYREF
struct timespec tp; // [rsp+10h] [rbp-18h] BYREF

clock_gettime(0, &tp);
v4 = _mm_loadu_si128((const __m128i *)&tp);
if ( v4.m128i_i64[1] == tp.tv_nsec )
{
v0 = 0;
do
{
clock_gettime(0, &tp);
++v0;
}
while ( v4.m128i_i64[1] == tp.tv_nsec );
v1 = (unsigned int)func7(&v4, &tp);
v2 = (const char *)&unk_402004;
if ( v0 != 1 )
v2 = "";
}
else
{
v1 = (unsigned int)func7(&v4, &tp);
v2 = "\tclock_gettime: %s%d ns\r\n" + 25;
}
return printf("\tclock_gettime: %s%d ns\r\n", v2, v1);
}

original_code:
void
measure_clock_gettime(void) {
 struct timespec ta;
 struct timespec tb;
 int32_t granularity;
 int cnt = 0;
 clock_gettime(0, &ta);
 tb = ta;
 while(tb.tv_nsec == ta.tv_nsec) {
  clock_gettime(0, &ta);
  cnt++;
 }
 granularity = diff_timespec(&tb, &ta);
 printf("\tclock_gettime: %s%d ns\r\n", cnt == 1 ? "<=" : "", granularity);
}

canonical_original_code:
void measure_clock_gettime() {
 struct timespec ta;
 struct timespec tb;
 int granularity;
 int cnt = 0;
 clock_gettime(0, &ta);
 tb = ta;
 while(tb.tv_nsec == ta.tv_nsec) {
  clock_gettime(0, &ta);
  cnt++;
 }
 granularity = diff_timespec(&tb, &ta);
 printf("\tclock_gettime: %s%d ns\r\n", cnt == 1 ? "<=" : "", granularity);
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types: granularity int

variable_types: cnt int


decompiled_code:
int measure_gettimeofday()
{
int v0; // ebx
unsigned int v1; // eax
__int64 v2; // rdx
const char *v3; // rsi
__m128i v5; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
v5 = _mm_loadu_si128((const __m128i *)&tv);
if ( v5.m128i_i64[1] == tv.tv_usec )
{
v0 = 0;
do
{
gettimeofday(&tv, 0LL);
++v0;
}
while ( v5.m128i_i64[1] == tv.tv_usec );
v1 = diff_timeval(&v5, &tv);
v2 = v1;
if ( v0 != 1 || (v3 = (const char *)&unk_402004, v1 == 1000) )
v3 = "\tclock_gettime: %s%d ns\r\n" + 25;
}
else
{
v2 = (unsigned int)diff_timeval(&v5, &tv);
v3 = "\tclock_gettime: %s%d ns\r\n" + 25;
}
return printf("\tgettimeofday: %s%d ns\r\n", v3, v2);
}

canonical_decompiled_code:
int func10()
{
int v0; // ebx
unsigned int v1; // eax
__int64 v2; // rdx
const char *v3; // rsi
__m128i v5; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
v5 = _mm_loadu_si128((const __m128i *)&tv);
if ( v5.m128i_i64[1] == tv.tv_usec )
{
v0 = 0;
do
{
gettimeofday(&tv, 0LL);
++v0;
}
while ( v5.m128i_i64[1] == tv.tv_usec );
v1 = func8(&v5, &tv);
v2 = v1;
if ( v0 != 1 || (v3 = (const char *)&unk_402004, v1 == 1000) )
v3 = "\tclock_gettime: %s%d ns\r\n" + 25;
}
else
{
v2 = (unsigned int)func8(&v5, &tv);
v3 = "\tclock_gettime: %s%d ns\r\n" + 25;
}
return printf("\tgettimeofday: %s%d ns\r\n", v3, v2);
}

original_code:
void
measure_gettimeofday(void) {
 struct timeval ta;
 struct timeval tb;
 int32_t granularity;
 int cnt = 0;
 gettimeofday(&ta, 0);
 tb = ta;
 while(tb.tv_usec == ta.tv_usec) {
  gettimeofday(&ta, 0);
  cnt++;
 }
 granularity = diff_timeval(&tb, &ta);
 printf("\tgettimeofday: %s%d ns\r\n", (cnt == 1 && granularity != 1000) ? "<=" : "", granularity);
}

canonical_original_code:
void measure_gettimeofday() {
 struct timeval ta;
 struct timeval tb;
 int granularity;
 int cnt = 0;
 gettimeofday(&ta, 0);
 tb = ta;
 while(tb.tv_usec == ta.tv_usec) {
  gettimeofday(&ta, 0);
  cnt++;
 }
 granularity = diff_timeval(&tb, &ta);
 printf("\tgettimeofday: %s%d ns\r\n", (cnt == 1 && granularity != 1000) ? "<=" : "", granularity);
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("granularity:\r");
measure_clock_gettime();
measure_gettimeofday();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("granularity:\r");
func9();
func10();
return 0;
}

original_code:
int
main(int argc, char ** argv) {
 printf("granularity:\r\n");
 measure_clock_gettime();
 measure_gettimeofday();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 printf("granularity:\r\n");
 measure_clock_gettime();
 measure_gettimeofday();
 return 0;
}


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

if ( a2 <= 9 && a1 )
result = *(unsigned __int16 *)(a1 + 2LL * a2 + 136);
else
result = 0LL;
return result;
}

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

if ( a2 <= 9 && a1 )
result = *(unsigned __int16 *)(a1 + 2LL * a2 + 136);
else
result = 0LL;
return result;
}

original_code:
scpi_reg_val_t SCPI_RegGet(scpi_t * context, scpi_reg_name_t name) {
    if ((name < SCPI_REG_COUNT) && context) {
        return context->registers[name];
    } else {
        return 0;
    }
}

canonical_original_code:
unsigned short SCPI_RegGet(struct _scpi_t *context, enum _scpi_reg_name_t name) {
    if ((name < SCPI_REG_COUNT) && context) {
        return context->registers[name];
    } else {
        return 0;
    }
}

variable_types: struct _scpi_t { struct _scpi_command_t { char *pattern; enum _scpi_result_t { SCPI_RES_OK=1, SCPI_RES_ERR=-1 } (*callback)(struct _scpi_t *); int tag; } *cmdlist; struct _scpi_buffer_t { unsigned long length; unsigned long position; char *data; } buffer; struct _scpi_param_list_t { struct _scpi_command_t *cmd; struct _lex_state_t { char *buffer; char *pos; int len; } lex_state; struct _scpi_const_buffer_t { unsigned long length; unsigned long position; char *data; } cmd_raw; } param_list; struct _scpi_interface_t { int (*error)(struct _scpi_t *context, long error); unsigned long (*write)(struct _scpi_t *context, char *data, unsigned long len); enum _scpi_result_t { SCPI_RES_OK=1, SCPI_RES_ERR=-1 } (*control)(struct _scpi_t *context, enum _scpi_ctrl_name_t { SCPI_CTRL_SRQ=1, SCPI_CTRL_GTL=2, SCPI_CTRL_SDC=3, SCPI_CTRL_PPC=4, SCPI_CTRL_GET=5, SCPI_CTRL_TCT=6, SCPI_CTRL_LLO=7, SCPI_CTRL_DCL=8, SCPI_CTRL_PPU=9, SCPI_CTRL_SPE=10, SCPI_CTRL_SPD=11, SCPI_CTRL_MLA=12, SCPI_CTRL_UNL=13, SCPI_CTRL_MTA=14, SCPI_CTRL_UNT=15, SCPI_CTRL_MSA=16 } ctrl, unsigned short val); enum _scpi_result_t { SCPI_RES_OK=1, SCPI_RES_ERR=-1 } (*flush)(struct _scpi_t *); enum _scpi_result_t { SCPI_RES_OK=1, SCPI_RES_ERR=-1 } (*reset)(struct _scpi_t *); } *interface; long output_count; long input_count; _Bool first_output; _Bool cmd_error; struct _scpi_fifo_t { short wr; short rd; short count; short size; struct _scpi_error_t { short error_code; char *device_dependent_info; } *data; } error_queue; unsigned short registers[-1]; struct _scpi_unit_def_t { char *name; enum _scpi_unit_t { SCPI_UNIT_NONE=0, SCPI_UNIT_VOLT=1, SCPI_UNIT_AMPER=2, SCPI_UNIT_OHM=3, SCPI_UNIT_HERTZ=4, SCPI_UNIT_CELSIUS=5, SCPI_UNIT_SECOND=6, SCPI_UNIT_METER=7, SCPI_UNIT_GRAY=8, SCPI_UNIT_BECQUEREL=9, SCPI_UNIT_MOLE=10, SCPI_UNIT_DEGREE=11, SCPI_UNIT_GRADE=12, SCPI_UNIT_RADIAN=13, SCPI_UNIT_REVOLUTION=14, SCPI_UNIT_STERADIAN=15, SCPI_UNIT_SIEVERT=16, SCPI_UNIT_FARAD=17, SCPI_UNIT_COULOMB=18, SCPI_UNIT_SIEMENS=19, SCPI_UNIT_ELECTRONVOLT=20, SCPI_UNIT_JOULE=21, SCPI_UNIT_NEWTON=22, SCPI_UNIT_LUX=23, SCPI_UNIT_HENRY=24, SCPI_UNIT_ASTRONOMIC_UNIT=25, SCPI_UNIT_INCH=26, SCPI_UNIT_FOOT=27, SCPI_UNIT_PARSEC=28, SCPI_UNIT_MILE=29, SCPI_UNIT_NAUTICAL_MILE=30, SCPI_UNIT_LUMEN=31, SCPI_UNIT_CANDELA=32, SCPI_UNIT_WEBER=33, SCPI_UNIT_TESLA=34, SCPI_UNIT_ATOMIC_MASS=35, SCPI_UNIT_KILOGRAM=36, SCPI_UNIT_WATT=37, SCPI_UNIT_DBM=38, SCPI_UNIT_ATMOSPHERE=39, SCPI_UNIT_INCH_OF_MERCURY=40, SCPI_UNIT_MM_OF_MERCURY=41, SCPI_UNIT_PASCAL=42, SCPI_UNIT_TORT=43, SCPI_UNIT_BAR=44, SCPI_UNIT_DECIBEL=45, SCPI_UNIT_UNITLESS=46, SCPI_UNIT_FAHRENHEIT=47, SCPI_UNIT_KELVIN=48, SCPI_UNIT_DAY=49, SCPI_UNIT_YEAR=50, SCPI_UNIT_STROKES=51, SCPI_UNIT_POISE=52, SCPI_UNIT_LITER=53 } unit; double mult; } *units; void *user_context; struct _scpi_parser_state_t { struct _scpi_token_t { enum _scpi_token_type_t { SCPI_TOKEN_COMMA=0, SCPI_TOKEN_SEMICOLON=1, SCPI_TOKEN_COLON=2, SCPI_TOKEN_SPECIFIC_CHARACTER=3, SCPI_TOKEN_QUESTION=4, SCPI_TOKEN_NL=5, SCPI_TOKEN_HEXNUM=6, SCPI_TOKEN_OCTNUM=7, SCPI_TOKEN_BINNUM=8, SCPI_TOKEN_PROGRAM_MNEMONIC=9, SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA=10, SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX=11, SCPI_TOKEN_SUFFIX_PROGRAM_DATA=12, SCPI_TOKEN_ARBITRARY_BLOCK_PROGRAM_DATA=13, SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA=14, SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA=15, SCPI_TOKEN_PROGRAM_EXPRESSION=16, SCPI_TOKEN_COMPOUND_PROGRAM_HEADER=17, SCPI_TOKEN_INCOMPLETE_COMPOUND_PROGRAM_HEADER=18, SCPI_TOKEN_COMMON_PROGRAM_HEADER=19, SCPI_TOKEN_INCOMPLETE_COMMON_PROGRAM_HEADER=20, SCPI_TOKEN_COMPOUND_QUERY_PROGRAM_HEADER=21, SCPI_TOKEN_COMMON_QUERY_PROGRAM_HEADER=22, SCPI_TOKEN_WS=23, SCPI_TOKEN_ALL_PROGRAM_DATA=24, SCPI_TOKEN_INVALID=25, SCPI_TOKEN_UNKNOWN=26 } type; char *ptr; int len; } programHeader; struct _scpi_token_t programData; int numberOfParameters; enum _message_termination_t { SCPI_MESSAGE_TERMINATION_NONE=0, SCPI_MESSAGE_TERMINATION_NL=1, SCPI_MESSAGE_TERMINATION_SEMICOLON=2 } termination; } parser_state; char *idn[4]; unsigned long arbitrary_remaining; } *

variable_types: enum _scpi_reg_name_t { SCPI_REG_STB=0, SCPI_REG_SRE=1, SCPI_REG_ESR=2, SCPI_REG_ESE=3, SCPI_REG_OPER=4, SCPI_REG_OPERE=5, SCPI_REG_OPERC=6, SCPI_REG_QUES=7, SCPI_REG_QUESE=8, SCPI_REG_QUESC=9, SCPI_REG_COUNT=10, SCPI_REG_NONE=11 }

return_type: unsigned short

user_defined_types: struct _scpi_t { struct _scpi_command_t *cmdlist; struct _scpi_buffer_t buffer; struct _scpi_param_list_t param_list; struct _scpi_interface_t *interface; long output_count; long input_count; _Bool first_output; _Bool cmd_error; struct _scpi_fifo_t error_queue; unsigned short registers[-1]; struct _scpi_unit_def_t *units; void *user_context; struct _scpi_parser_state_t parser_state; char *idn[4]; unsigned long arbitrary_remaining; }

user_defined_types: struct _scpi_param_list_t { struct _scpi_command_t *cmd; struct _lex_state_t lex_state; struct _scpi_const_buffer_t cmd_raw; }

user_defined_types: struct _scpi_fifo_t { short wr; short rd; short count; short size; struct _scpi_error_t *data; }

user_defined_types: struct _scpi_parser_state_t { struct _scpi_token_t programHeader; struct _scpi_token_t programData; int numberOfParameters; enum _message_termination_t termination; }

user_defined_types: struct _scpi_command_t { char *pattern; enum _scpi_result_t (*callback)(struct _scpi_t *); int tag; }

user_defined_types: struct _scpi_interface_t { int (*error)(struct _scpi_t *context, long error); unsigned long (*write)(struct _scpi_t *context, char *data, unsigned long len); enum _scpi_result_t (*control)(struct _scpi_t *context, enum _scpi_ctrl_name_t ctrl, unsigned short val); enum _scpi_result_t (*flush)(struct _scpi_t *); enum _scpi_result_t (*reset)(struct _scpi_t *); }

user_defined_types: struct _scpi_unit_def_t { char *name; enum _scpi_unit_t unit; double mult; }

user_defined_types: struct _scpi_token_t { enum _scpi_token_type_t type; char *ptr; int len; }


original_code:
void SCPI_RegSet(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t val) {
    if ((name >= SCPI_REG_COUNT) || (context == ((void *)0))) {
        return;
    }
    scpi_reg_group_info_t register_group;
    do {
        scpi_reg_class_t register_type = scpi_reg_details[name].type;
        register_group = scpi_reg_group_details[scpi_reg_details[name].group];
        scpi_reg_val_t ptrans;
        scpi_reg_val_t old_val = context->registers[name];
        if (old_val == val) {
            return;
        } else {
            context->registers[name] = val;
        }
        switch (register_type) {
            case SCPI_REG_CLASS_STB:
            case SCPI_REG_CLASS_SRE:
            {
                scpi_reg_val_t stb = context->registers[SCPI_REG_STB] & ~0x40;
                scpi_reg_val_t sre = context->registers[SCPI_REG_SRE] & ~0x40;
                if (stb & sre) {
                    ptrans = ((old_val ^ val) & val);
                    context->registers[SCPI_REG_STB] |= 0x40;
                    if (ptrans & val) {
                        writeControl(context, SCPI_CTRL_SRQ, context->registers[SCPI_REG_STB]);
                    }
                } else {
                    context->registers[SCPI_REG_STB] &= ~0x40;
                }
                break;
            }
            case SCPI_REG_CLASS_EVEN:
            {
                scpi_reg_val_t enable;
                if(register_group.enable != SCPI_REG_NONE) {
                    enable = SCPI_RegGet(context, register_group.enable);
                } else {
                    enable = 0xFFFF;
                }
                scpi_bool_t summary = val & enable;
                name = register_group.parent_reg;
                val = SCPI_RegGet(context, register_group.parent_reg);
                if (summary) {
                    val |= register_group.parent_bit;
                } else {
                    val &= ~(register_group.parent_bit);
                }
                break;
            }
            case SCPI_REG_CLASS_COND:
            {
                name = register_group.event;
                if(register_group.ptfilt == SCPI_REG_NONE && register_group.ntfilt == SCPI_REG_NONE) {
                    val = ((old_val ^ val) & val) | SCPI_RegGet(context, register_group.event);
                } else {
                    scpi_reg_val_t ptfilt = 0, ntfilt = 0;
                    scpi_reg_val_t transitions;
                    scpi_reg_val_t ntrans;
                    if(register_group.ptfilt != SCPI_REG_NONE) {
                        ptfilt = SCPI_RegGet(context, register_group.ptfilt);
                    }
                    if(register_group.ntfilt != SCPI_REG_NONE) {
                        ntfilt = SCPI_RegGet(context, register_group.ntfilt);
                    }
                    transitions = old_val ^ val;
                    ptrans = transitions & val;
                    ntrans = transitions & ~ptrans;
                    val = ((ptrans & ptfilt) | (ntrans & ntfilt)) | SCPI_RegGet(context, register_group.event);
                }
                break;
            }
            case SCPI_REG_CLASS_ENAB:
            case SCPI_REG_CLASS_NTR:
            case SCPI_REG_CLASS_PTR:
                return;
        }
    } while(register_group.parent_reg != SCPI_REG_NONE);
}

canonical_original_code:
void SCPI_RegSet(struct _scpi_t *context, enum _scpi_reg_name_t name, unsigned short val) {
    if ((name >= SCPI_REG_COUNT) || (context == ((void *)0))) {
        return;
    }
    struct _scpi_reg_group_info_t register_group;
    do {
        enum _scpi_reg_class_t register_type = scpi_reg_details[name].type;
        register_group = scpi_reg_group_details[scpi_reg_details[name].group];
        unsigned short ptrans;
        unsigned short old_val = context->registers[name];
        if (old_val == val) {
            return;
        } else {
            context->registers[name] = val;
        }
        switch (register_type) {
            case SCPI_REG_CLASS_STB:
            case SCPI_REG_CLASS_SRE:
            {
                unsigned short stb = context->registers[SCPI_REG_STB] & ~0x40;
                unsigned short sre = context->registers[SCPI_REG_SRE] & ~0x40;
                if (stb & sre) {
                    ptrans = ((old_val ^ val) & val);
                    context->registers[SCPI_REG_STB] |= 0x40;
                    if (ptrans & val) {
                        writeControl(context, SCPI_CTRL_SRQ, context->registers[SCPI_REG_STB]);
                    }
                } else {
                    context->registers[SCPI_REG_STB] &= ~0x40;
                }
                break;
            }
            case SCPI_REG_CLASS_EVEN:
            {
                unsigned short enable;
                if(register_group.enable != SCPI_REG_NONE) {
                    enable = SCPI_RegGet(context, register_group.enable);
                } else {
                    enable = 0xFFFF;
                }
                _Bool summary = val & enable;
                name = register_group.parent_reg;
                val = SCPI_RegGet(context, register_group.parent_reg);
                if (summary) {
                    val |= register_group.parent_bit;
                } else {
                    val &= ~(register_group.parent_bit);
                }
                break;
            }
            case SCPI_REG_CLASS_COND:
            {
                name = register_group.event;
                if(register_group.ptfilt == SCPI_REG_NONE && register_group.ntfilt == SCPI_REG_NONE) {
                    val = ((old_val ^ val) & val) | SCPI_RegGet(context, register_group.event);
                } else {
                    unsigned short ptfilt = 0; unsigned short ntfilt = 0;
                    unsigned short transitions;
                    unsigned short ntrans;
                    if(register_group.ptfilt != SCPI_REG_NONE) {
                        ptfilt = SCPI_RegGet(context, register_group.ptfilt);
                    }
                    if(register_group.ntfilt != SCPI_REG_NONE) {
                        ntfilt = SCPI_RegGet(context, register_group.ntfilt);
                    }
                    transitions = old_val ^ val;
                    ptrans = transitions & val;
                    ntrans = transitions & ~ptrans;
                    val = ((ptrans & ptfilt) | (ntrans & ntfilt)) | SCPI_RegGet(context, register_group.event);
                }
                break;
            }
            case SCPI_REG_CLASS_ENAB:
            case SCPI_REG_CLASS_NTR:
            case SCPI_REG_CLASS_PTR:
                return;
        }
    } while(register_group.parent_reg != SCPI_REG_NONE);
}

variable_types:
val
unsigned short

variable_types: struct _scpi_reg_group_info_t { enum _scpi_reg_name_t { SCPI_REG_STB=0, SCPI_REG_SRE=1, SCPI_REG_ESR=2, SCPI_REG_ESE=3, SCPI_REG_OPER=4, SCPI_REG_OPERE=5, SCPI_REG_OPERC=6, SCPI_REG_QUES=7, SCPI_REG_QUESE=8, SCPI_REG_QUESC=9, SCPI_REG_COUNT=10, SCPI_REG_NONE=11 } event; enum _scpi_reg_name_t { SCPI_REG_STB=0, SCPI_REG_SRE=1, SCPI_REG_ESR=2, SCPI_REG_ESE=3, SCPI_REG_OPER=4, SCPI_REG_OPERE=5, SCPI_REG_OPERC=6, SCPI_REG_QUES=7, SCPI_REG_QUESE=8, SCPI_REG_QUESC=9, SCPI_REG_COUNT=10, SCPI_REG_NONE=11 } enable; enum _scpi_reg_name_t { SCPI_REG_STB=0, SCPI_REG_SRE=1, SCPI_REG_ESR=2, SCPI_REG_ESE=3, SCPI_REG_OPER=4, SCPI_REG_OPERE=5, SCPI_REG_OPERC=6, SCPI_REG_QUES=7, SCPI_REG_QUESE=8, SCPI_REG_QUESC=9, SCPI_REG_COUNT=10, SCPI_REG_NONE=11 } condition; enum _scpi_reg_name_t { SCPI_REG_STB=0, SCPI_REG_SRE=1, SCPI_REG_ESR=2, SCPI_REG_ESE=3, SCPI_REG_OPER=4, SCPI_REG_OPERE=5, SCPI_REG_OPERC=6, SCPI_REG_QUES=7, SCPI_REG_QUESE=8, SCPI_REG_QUESC=9, SCPI_REG_COUNT=10, SCPI_REG_NONE=11 } ptfilt; enum _scpi_reg_name_t { SCPI_REG_STB=0, SCPI_REG_SRE=1, SCPI_REG_ESR=2, SCPI_REG_ESE=3, SCPI_REG_OPER=4, SCPI_REG_OPERE=5, SCPI_REG_OPERC=6, SCPI_REG_QUES=7, SCPI_REG_QUESE=8, SCPI_REG_QUESC=9, SCPI_REG_COUNT=10, SCPI_REG_NONE=11 } ntfilt; enum _scpi_reg_name_t { SCPI_REG_STB=0, SCPI_REG_SRE=1, SCPI_REG_ESR=2, SCPI_REG_ESE=3, SCPI_REG_OPER=4, SCPI_REG_OPERE=5, SCPI_REG_OPERC=6, SCPI_REG_QUES=7, SCPI_REG_QUESE=8, SCPI_REG_QUESC=9, SCPI_REG_COUNT=10, SCPI_REG_NONE=11 } parent_reg; unsigned short parent_bit; }

variable_types: enum _scpi_reg_class_t { SCPI_REG_CLASS_STB=0, SCPI_REG_CLASS_SRE=1, SCPI_REG_CLASS_EVEN=2, SCPI_REG_CLASS_ENAB=3, SCPI_REG_CLASS_COND=4, SCPI_REG_CLASS_NTR=5, SCPI_REG_CLASS_PTR=6 }

variable_types:
ptrans
unsigned short

variable_types:
stb
unsigned short

variable_types:
sre
unsigned short

variable_types:
enable
unsigned short

variable_types:
ptfilt
unsigned short

variable_types:
ntfilt
unsigned short

variable_types:
transitions
unsigned short

variable_types:
ntrans
unsigned short

user_defined_types: struct _scpi_reg_group_info_t { enum _scpi_reg_name_t event; enum _scpi_reg_name_t enable; enum _scpi_reg_name_t condition; enum _scpi_reg_name_t ptfilt; enum _scpi_reg_name_t ntfilt; enum _scpi_reg_name_t parent_reg; unsigned short parent_bit; }

user_defined_types: struct _scpi_buffer_t { unsigned long length; unsigned long position; char *data; }

user_defined_types: struct _lex_state_t { char *buffer; char *pos; int len; }

user_defined_types: struct _scpi_const_buffer_t { unsigned long length; unsigned long position; char *data; }

user_defined_types: enum _message_termination_t { SCPI_MESSAGE_TERMINATION_NONE=0, SCPI_MESSAGE_TERMINATION_NL=1, SCPI_MESSAGE_TERMINATION_SEMICOLON=2 }

user_defined_types: struct _scpi_error_t { short error_code; char *device_dependent_info; }

user_defined_types: enum _scpi_unit_t { SCPI_UNIT_NONE=0, SCPI_UNIT_VOLT=1, SCPI_UNIT_AMPER=2, SCPI_UNIT_OHM=3, SCPI_UNIT_HERTZ=4, SCPI_UNIT_CELSIUS=5, SCPI_UNIT_SECOND=6, SCPI_UNIT_METER=7, SCPI_UNIT_GRAY=8, SCPI_UNIT_BECQUEREL=9, SCPI_UNIT_MOLE=10, SCPI_UNIT_DEGREE=11, SCPI_UNIT_GRADE=12, SCPI_UNIT_RADIAN=13, SCPI_UNIT_REVOLUTION=14, SCPI_UNIT_STERADIAN=15, SCPI_UNIT_SIEVERT=16, SCPI_UNIT_FARAD=17, SCPI_UNIT_COULOMB=18, SCPI_UNIT_SIEMENS=19, SCPI_UNIT_ELECTRONVOLT=20, SCPI_UNIT_JOULE=21, SCPI_UNIT_NEWTON=22, SCPI_UNIT_LUX=23, SCPI_UNIT_HENRY=24, SCPI_UNIT_ASTRONOMIC_UNIT=25, SCPI_UNIT_INCH=26, SCPI_UNIT_FOOT=27, SCPI_UNIT_PARSEC=28, SCPI_UNIT_MILE=29, SCPI_UNIT_NAUTICAL_MILE=30, SCPI_UNIT_LUMEN=31, SCPI_UNIT_CANDELA=32, SCPI_UNIT_WEBER=33, SCPI_UNIT_TESLA=34, SCPI_UNIT_ATOMIC_MASS=35, SCPI_UNIT_KILOGRAM=36, SCPI_UNIT_WATT=37, SCPI_UNIT_DBM=38, SCPI_UNIT_ATMOSPHERE=39, SCPI_UNIT_INCH_OF_MERCURY=40, SCPI_UNIT_MM_OF_MERCURY=41, SCPI_UNIT_PASCAL=42, SCPI_UNIT_TORT=43, SCPI_UNIT_BAR=44, SCPI_UNIT_DECIBEL=45, SCPI_UNIT_UNITLESS=46, SCPI_UNIT_FAHRENHEIT=47, SCPI_UNIT_KELVIN=48, SCPI_UNIT_DAY=49, SCPI_UNIT_YEAR=50, SCPI_UNIT_STROKES=51, SCPI_UNIT_POISE=52, SCPI_UNIT_LITER=53 }

user_defined_types: enum _scpi_token_type_t { SCPI_TOKEN_COMMA=0, SCPI_TOKEN_SEMICOLON=1, SCPI_TOKEN_COLON=2, SCPI_TOKEN_SPECIFIC_CHARACTER=3, SCPI_TOKEN_QUESTION=4, SCPI_TOKEN_NL=5, SCPI_TOKEN_HEXNUM=6, SCPI_TOKEN_OCTNUM=7, SCPI_TOKEN_BINNUM=8, SCPI_TOKEN_PROGRAM_MNEMONIC=9, SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA=10, SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX=11, SCPI_TOKEN_SUFFIX_PROGRAM_DATA=12, SCPI_TOKEN_ARBITRARY_BLOCK_PROGRAM_DATA=13, SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA=14, SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA=15, SCPI_TOKEN_PROGRAM_EXPRESSION=16, SCPI_TOKEN_COMPOUND_PROGRAM_HEADER=17, SCPI_TOKEN_INCOMPLETE_COMPOUND_PROGRAM_HEADER=18, SCPI_TOKEN_COMMON_PROGRAM_HEADER=19, SCPI_TOKEN_INCOMPLETE_COMMON_PROGRAM_HEADER=20, SCPI_TOKEN_COMPOUND_QUERY_PROGRAM_HEADER=21, SCPI_TOKEN_COMMON_QUERY_PROGRAM_HEADER=22, SCPI_TOKEN_WS=23, SCPI_TOKEN_ALL_PROGRAM_DATA=24, SCPI_TOKEN_INVALID=25, SCPI_TOKEN_UNKNOWN=26 }

user_defined_types: enum _scpi_result_t { SCPI_RES_OK=1, SCPI_RES_ERR=-1 }

user_defined_types: enum _scpi_ctrl_name_t { SCPI_CTRL_SRQ=1, SCPI_CTRL_GTL=2, SCPI_CTRL_SDC=3, SCPI_CTRL_PPC=4, SCPI_CTRL_GET=5, SCPI_CTRL_TCT=6, SCPI_CTRL_LLO=7, SCPI_CTRL_DCL=8, SCPI_CTRL_PPU=9, SCPI_CTRL_SPE=10, SCPI_CTRL_SPD=11, SCPI_CTRL_MLA=12, SCPI_CTRL_UNL=13, SCPI_CTRL_MTA=14, SCPI_CTRL_UNT=15, SCPI_CTRL_MSA=16 }


decompiled_code:
void __fastcall SCPI_RegSetBits(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
unsigned __int16 v4; // ax

v4 = SCPI_RegGet(a1, a2);
SCPI_RegSet(a1, a2, a3 | v4);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
unsigned __int16 v4; // ax

v4 = func1(a1, a2);
func2(a1, a2, a3 | v4);
}

original_code:
void SCPI_RegSetBits(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t bits) {
    SCPI_RegSet(context, name, SCPI_RegGet(context, name) | bits);
}

canonical_original_code:
void SCPI_RegSetBits(struct _scpi_t *context, enum _scpi_reg_name_t name, unsigned short bits) {
    SCPI_RegSet(context, name, SCPI_RegGet(context, name) | bits);
}

variable_types:
bits
unsigned short

user_defined_types: enum _scpi_reg_name_t { SCPI_REG_STB=0, SCPI_REG_SRE=1, SCPI_REG_ESR=2, SCPI_REG_ESE=3, SCPI_REG_OPER=4, SCPI_REG_OPERE=5, SCPI_REG_OPERC=6, SCPI_REG_QUES=7, SCPI_REG_QUESE=8, SCPI_REG_QUESC=9, SCPI_REG_COUNT=10, SCPI_REG_NONE=11 }

user_defined_types: struct _scpi_t { struct _scpi_command_t *cmdlist; struct _scpi_buffer_t buffer; struct _scpi_param_list_t param_list; struct _scpi_interface_t *interface; long output_count; long input_count; _Bool first_output; _Bool cmd_error; struct _scpi_fifo_t error_queue; unsigned short registers[-1]; struct _scpi_unit_def_t *units; void *user_context; struct _scpi_parser_state_t parser_state; char *idn[4]; unsigned long arbitrary_remaining; }

user_defined_types: struct _scpi_param_list_t { struct _scpi_command_t *cmd; struct _lex_state_t lex_state; struct _scpi_const_buffer_t cmd_raw; }


decompiled_code:
void __fastcall SCPI_RegClearBits(__int64 a1, unsigned int a2, __int16 a3)
{
unsigned __int16 v4; // ax

v4 = SCPI_RegGet(a1, a2);
SCPI_RegSet(a1, a2, v4 & (unsigned __int16)~a3);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, unsigned int a2, __int16 a3)
{
unsigned __int16 v4; // ax

v4 = func1(a1, a2);
func2(a1, a2, v4 & (unsigned __int16)~a3);
}

original_code:
void SCPI_RegClearBits(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t bits) {
    SCPI_RegSet(context, name, SCPI_RegGet(context, name) & ~bits);
}

canonical_original_code:
void SCPI_RegClearBits(struct _scpi_t *context, enum _scpi_reg_name_t name, unsigned short bits) {
    SCPI_RegSet(context, name, SCPI_RegGet(context, name) & ~bits);
}

user_defined_types: struct _scpi_fifo_t { short wr; short rd; short count; short size; struct _scpi_error_t *data; }

user_defined_types: struct _scpi_parser_state_t { struct _scpi_token_t programHeader; struct _scpi_token_t programData; int numberOfParameters; enum _message_termination_t termination; }

user_defined_types: struct _scpi_command_t { char *pattern; enum _scpi_result_t (*callback)(struct _scpi_t *); int tag; }


decompiled_code:
__int64 __fastcall SCPI_CoreCls(__int64 a1)
{
unsigned int *v1; // rbx

SCPI_ErrorClear();
v1 = (unsigned int *)scpi_reg_group_details;
do
{
if ( *v1 )
SCPI_RegSet(a1, *v1, 0);
v1 += 7;
}
while ( v1 != (unsigned int *)&unk_590 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int *v1; // rbx

SCPI_ErrorClear();
v1 = (unsigned int *)scpi_reg_group_details;
do
{
if ( *v1 )
func2(a1, *v1, 0);
v1 += 7;
}
while ( v1 != (unsigned int *)&unk_590 );
return 1LL;
}

original_code:
scpi_result_t SCPI_CoreCls(scpi_t * context) {
    SCPI_ErrorClear(context);
    int i;
    for (i = 0; i < SCPI_REG_GROUP_COUNT; ++i) {
        scpi_reg_name_t event_reg = scpi_reg_group_details[i].event;
        if (event_reg != SCPI_REG_STB) {
            SCPI_RegSet(context, event_reg, 0);
        }
    }
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_CoreCls(struct _scpi_t *context) {
    SCPI_ErrorClear(context);
    int i;
    for (i = 0; i < SCPI_REG_GROUP_COUNT; ++i) {
        enum _scpi_reg_name_t event_reg = scpi_reg_group_details[i].event;
        if (event_reg != SCPI_REG_STB) {
            SCPI_RegSet(context, event_reg, 0);
        }
    }
    return SCPI_RES_OK;
}

variable_types: i int

return_type: enum _scpi_result_t { SCPI_RES_OK=1, SCPI_RES_ERR=-1 }

user_defined_types: struct _scpi_interface_t { int (*error)(struct _scpi_t *context, long error); unsigned long (*write)(struct _scpi_t *context, char *data, unsigned long len); enum _scpi_result_t (*control)(struct _scpi_t *context, enum _scpi_ctrl_name_t ctrl, unsigned short val); enum _scpi_result_t (*flush)(struct _scpi_t *); enum _scpi_result_t (*reset)(struct _scpi_t *); }

user_defined_types: struct _scpi_unit_def_t { char *name; enum _scpi_unit_t unit; double mult; }

user_defined_types: struct _scpi_token_t { enum _scpi_token_type_t type; char *ptr; int len; }


decompiled_code:
__int64 __fastcall SCPI_CoreEse(__int64 a1)
{
char v1; // dl
__int64 result; // rax
unsigned __int16 v3[6]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = SCPI_ParamInt32(a1, v3, 1LL);
result = 0xFFFFFFFFLL;
if ( v1 )
{
SCPI_RegSet(a1, 3u, v3[0]);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
char v1; // dl
__int64 result; // rax
unsigned __int16 v3[6]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = SCPI_ParamInt32(a1, v3, 1LL);
result = 0xFFFFFFFFLL;
if ( v1 )
{
func2(a1, 3u, v3[0]);
result = 1LL;
}
return result;
}

original_code:
scpi_result_t SCPI_CoreEse(scpi_t * context) {
    int32_t new_ESE;
    if (SCPI_ParamInt32(context, &new_ESE, (!0))) {
        SCPI_RegSet(context, SCPI_REG_ESE, (scpi_reg_val_t) new_ESE);
        return SCPI_RES_OK;
    }
    return SCPI_RES_ERR;
}

canonical_original_code:
enum _scpi_result_t SCPI_CoreEse(struct _scpi_t *context) {
    int new_ESE;
    if (SCPI_ParamInt32(context, &new_ESE, (!0))) {
        SCPI_RegSet(context, SCPI_REG_ESE, (unsigned short) new_ESE);
        return SCPI_RES_OK;
    }
    return SCPI_RES_ERR;
}

user_defined_types: struct _scpi_buffer_t { unsigned long length; unsigned long position; char *data; }

user_defined_types: struct _lex_state_t { char *buffer; char *pos; int len; }


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

v1 = SCPI_RegGet(a1, 3u);
SCPI_ResultInt32(a1, v1);
return 1LL;
}

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

v1 = func1(a1, 3u);
SCPI_ResultInt32(a1, v1);
return 1LL;
}

original_code:
scpi_result_t SCPI_CoreEseQ(scpi_t * context) {
    SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_ESE));
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_CoreEseQ(struct _scpi_t *context) {
    SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_ESE));
    return SCPI_RES_OK;
}

user_defined_types: struct _scpi_const_buffer_t { unsigned long length; unsigned long position; char *data; }

user_defined_types: enum _message_termination_t { SCPI_MESSAGE_TERMINATION_NONE=0, SCPI_MESSAGE_TERMINATION_NL=1, SCPI_MESSAGE_TERMINATION_SEMICOLON=2 }


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

v1 = SCPI_RegGet(a1, 2u);
SCPI_ResultInt32(a1, v1);
SCPI_RegSet(a1, 2u, 0);
return 1LL;
}

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

v1 = func1(a1, 2u);
SCPI_ResultInt32(a1, v1);
func2(a1, 2u, 0);
return 1LL;
}

original_code:
scpi_result_t SCPI_CoreEsrQ(scpi_t * context) {
    SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_ESR));
    SCPI_RegSet(context, SCPI_REG_ESR, 0);
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_CoreEsrQ(struct _scpi_t *context) {
    SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_ESR));
    SCPI_RegSet(context, SCPI_REG_ESR, 0);
    return SCPI_RES_OK;
}

user_defined_types: struct _scpi_error_t { short error_code; char *device_dependent_info; }

user_defined_types: enum _scpi_unit_t { SCPI_UNIT_NONE=0, SCPI_UNIT_VOLT=1, SCPI_UNIT_AMPER=2, SCPI_UNIT_OHM=3, SCPI_UNIT_HERTZ=4, SCPI_UNIT_CELSIUS=5, SCPI_UNIT_SECOND=6, SCPI_UNIT_METER=7, SCPI_UNIT_GRAY=8, SCPI_UNIT_BECQUEREL=9, SCPI_UNIT_MOLE=10, SCPI_UNIT_DEGREE=11, SCPI_UNIT_GRADE=12, SCPI_UNIT_RADIAN=13, SCPI_UNIT_REVOLUTION=14, SCPI_UNIT_STERADIAN=15, SCPI_UNIT_SIEVERT=16, SCPI_UNIT_FARAD=17, SCPI_UNIT_COULOMB=18, SCPI_UNIT_SIEMENS=19, SCPI_UNIT_ELECTRONVOLT=20, SCPI_UNIT_JOULE=21, SCPI_UNIT_NEWTON=22, SCPI_UNIT_LUX=23, SCPI_UNIT_HENRY=24, SCPI_UNIT_ASTRONOMIC_UNIT=25, SCPI_UNIT_INCH=26, SCPI_UNIT_FOOT=27, SCPI_UNIT_PARSEC=28, SCPI_UNIT_MILE=29, SCPI_UNIT_NAUTICAL_MILE=30, SCPI_UNIT_LUMEN=31, SCPI_UNIT_CANDELA=32, SCPI_UNIT_WEBER=33, SCPI_UNIT_TESLA=34, SCPI_UNIT_ATOMIC_MASS=35, SCPI_UNIT_KILOGRAM=36, SCPI_UNIT_WATT=37, SCPI_UNIT_DBM=38, SCPI_UNIT_ATMOSPHERE=39, SCPI_UNIT_INCH_OF_MERCURY=40, SCPI_UNIT_MM_OF_MERCURY=41, SCPI_UNIT_PASCAL=42, SCPI_UNIT_TORT=43, SCPI_UNIT_BAR=44, SCPI_UNIT_DECIBEL=45, SCPI_UNIT_UNITLESS=46, SCPI_UNIT_FAHRENHEIT=47, SCPI_UNIT_KELVIN=48, SCPI_UNIT_DAY=49, SCPI_UNIT_YEAR=50, SCPI_UNIT_STROKES=51, SCPI_UNIT_POISE=52, SCPI_UNIT_LITER=53 }


decompiled_code:
__int64 __fastcall SCPI_CoreIdnQ(__int64 a1)
{
const char **v1; // rbx
size_t v2; // rax
const char *v3; // rbp

v1 = (const char **)(a1 + 232);
do
{
v3 = *v1;
if ( *v1 )
{
v2 = strlen(*v1);
SCPI_ResultCharacters(a1, v3, v2);
}
else
{
SCPI_ResultCharacters(a1, &unk_5F0, 1LL);
}
++v1;
}
while ( v1 != (const char **)(a1 + 264) );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
const char **v1; // rbx
size_t v2; // rax
const char *v3; // rbp

v1 = (const char **)(a1 + 232);
do
{
v3 = *v1;
if ( *v1 )
{
v2 = strlen(*v1);
SCPI_ResultCharacters(a1, v3, v2);
}
else
{
SCPI_ResultCharacters(a1, &unk_5F0, 1LL);
}
++v1;
}
while ( v1 != (const char **)(a1 + 264) );
return 1LL;
}

original_code:
scpi_result_t SCPI_CoreIdnQ(scpi_t * context) {
    int i;
    for (i = 0; i < 4; i++) {
        if (context->idn[i]) {
            SCPI_ResultCharacters((context), (context->idn[i]), strlen(context->idn[i]));
        } else {
            SCPI_ResultCharacters((context), ("0"), strlen("0"));
        }
    }
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_CoreIdnQ(struct _scpi_t *context) {
    int i;
    for (i = 0; i < 4; i++) {
        if (context->idn[i]) {
            SCPI_ResultCharacters((context), (context->idn[i]), strlen(context->idn[i]));
        } else {
            SCPI_ResultCharacters((context), ("0"), strlen("0"));
        }
    }
    return SCPI_RES_OK;
}

user_defined_types: enum _scpi_result_t { SCPI_RES_OK=1, SCPI_RES_ERR=-1 }

user_defined_types: enum _scpi_token_type_t { SCPI_TOKEN_COMMA=0, SCPI_TOKEN_SEMICOLON=1, SCPI_TOKEN_COLON=2, SCPI_TOKEN_SPECIFIC_CHARACTER=3, SCPI_TOKEN_QUESTION=4, SCPI_TOKEN_NL=5, SCPI_TOKEN_HEXNUM=6, SCPI_TOKEN_OCTNUM=7, SCPI_TOKEN_BINNUM=8, SCPI_TOKEN_PROGRAM_MNEMONIC=9, SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA=10, SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX=11, SCPI_TOKEN_SUFFIX_PROGRAM_DATA=12, SCPI_TOKEN_ARBITRARY_BLOCK_PROGRAM_DATA=13, SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA=14, SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA=15, SCPI_TOKEN_PROGRAM_EXPRESSION=16, SCPI_TOKEN_COMPOUND_PROGRAM_HEADER=17, SCPI_TOKEN_INCOMPLETE_COMPOUND_PROGRAM_HEADER=18, SCPI_TOKEN_COMMON_PROGRAM_HEADER=19, SCPI_TOKEN_INCOMPLETE_COMMON_PROGRAM_HEADER=20, SCPI_TOKEN_COMPOUND_QUERY_PROGRAM_HEADER=21, SCPI_TOKEN_COMMON_QUERY_PROGRAM_HEADER=22, SCPI_TOKEN_WS=23, SCPI_TOKEN_ALL_PROGRAM_DATA=24, SCPI_TOKEN_INVALID=25, SCPI_TOKEN_UNKNOWN=26 }


decompiled_code:
__int64 __fastcall SCPI_CoreOpc(__int64 a1)
{
SCPI_RegSetBits(a1, 2u, 1u);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
func3(a1, 2u, 1u);
return 1LL;
}

original_code:
scpi_result_t SCPI_CoreOpc(scpi_t * context) {
    SCPI_RegSetBits(context, SCPI_REG_ESR, 0x01);
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_CoreOpc(struct _scpi_t *context) {
    SCPI_RegSetBits(context, SCPI_REG_ESR, 0x01);
    return SCPI_RES_OK;
}

user_defined_types: enum _scpi_ctrl_name_t { SCPI_CTRL_SRQ=1, SCPI_CTRL_GTL=2, SCPI_CTRL_SDC=3, SCPI_CTRL_PPC=4, SCPI_CTRL_GET=5, SCPI_CTRL_TCT=6, SCPI_CTRL_LLO=7, SCPI_CTRL_DCL=8, SCPI_CTRL_PPU=9, SCPI_CTRL_SPE=10, SCPI_CTRL_SPD=11, SCPI_CTRL_MLA=12, SCPI_CTRL_UNL=13, SCPI_CTRL_MTA=14, SCPI_CTRL_UNT=15, SCPI_CTRL_MSA=16 }


decompiled_code:
__int64 __fastcall SCPI_CoreOpcQ(__int64 a1)
{
SCPI_ResultInt32(a1, 1LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
SCPI_ResultInt32(a1, 1LL);
return 1LL;
}

original_code:
scpi_result_t SCPI_CoreOpcQ(scpi_t * context) {
    SCPI_ResultInt32(context, 1);
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_CoreOpcQ(struct _scpi_t *context) {
    SCPI_ResultInt32(context, 1);
    return SCPI_RES_OK;
}

user_defined_types: struct _scpi_t { struct _scpi_command_t *cmdlist; struct _scpi_buffer_t buffer; struct _scpi_param_list_t param_list; struct _scpi_interface_t *interface; long output_count; long input_count; _Bool first_output; _Bool cmd_error; struct _scpi_fifo_t error_queue; unsigned short registers[-1]; struct _scpi_unit_def_t *units; void *user_context; struct _scpi_parser_state_t parser_state; char *idn[4]; unsigned long arbitrary_remaining; }


decompiled_code:
__int64 __fastcall SCPI_CoreRst(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx
__int64 (*v3)(void); // rdx

result = 1LL;
if ( a1 )
{
v2 = *(_QWORD *)(a1 + 88);
if ( v2 )
{
v3 = *(__int64 (**)(void))(v2 + 32);
if ( v3 )
result = v3();
}
}
return result;
}

original_code:
scpi_result_t SCPI_CoreRst(scpi_t * context) {
    if (context && context->interface && context->interface->reset) {
        return context->interface->reset(context);
    }
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_CoreRst(struct _scpi_t *context) {
    if (context && context->interface && context->interface->reset) {
        return context->interface->reset(context);
    }
    return SCPI_RES_OK;
}

user_defined_types: struct _scpi_param_list_t { struct _scpi_command_t *cmd; struct _lex_state_t lex_state; struct _scpi_const_buffer_t cmd_raw; }


decompiled_code:
__int64 __fastcall SCPI_CoreSre(__int64 a1)
{
char v1; // dl
__int64 result; // rax
unsigned __int16 v3[6]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = SCPI_ParamInt32(a1, v3, 1LL);
result = 0xFFFFFFFFLL;
if ( v1 )
{
SCPI_RegSet(a1, 1u, v3[0]);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
char v1; // dl
__int64 result; // rax
unsigned __int16 v3[6]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = SCPI_ParamInt32(a1, v3, 1LL);
result = 0xFFFFFFFFLL;
if ( v1 )
{
func2(a1, 1u, v3[0]);
result = 1LL;
}
return result;
}

original_code:
scpi_result_t SCPI_CoreSre(scpi_t * context) {
    int32_t new_SRE;
    if (SCPI_ParamInt32(context, &new_SRE, (!0))) {
        SCPI_RegSet(context, SCPI_REG_SRE, (scpi_reg_val_t) new_SRE);
        return SCPI_RES_OK;
    }
    return SCPI_RES_ERR;
}

canonical_original_code:
enum _scpi_result_t SCPI_CoreSre(struct _scpi_t *context) {
    int new_SRE;
    if (SCPI_ParamInt32(context, &new_SRE, (!0))) {
        SCPI_RegSet(context, SCPI_REG_SRE, (unsigned short) new_SRE);
        return SCPI_RES_OK;
    }
    return SCPI_RES_ERR;
}

user_defined_types: struct _scpi_fifo_t { short wr; short rd; short count; short size; struct _scpi_error_t *data; }


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

v1 = SCPI_RegGet(a1, 1u);
SCPI_ResultInt32(a1, v1);
return 1LL;
}

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

v1 = func1(a1, 1u);
SCPI_ResultInt32(a1, v1);
return 1LL;
}

original_code:
scpi_result_t SCPI_CoreSreQ(scpi_t * context) {
    SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_SRE));
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_CoreSreQ(struct _scpi_t *context) {
    SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_SRE));
    return SCPI_RES_OK;
}

user_defined_types: struct _scpi_parser_state_t { struct _scpi_token_t programHeader; struct _scpi_token_t programData; int numberOfParameters; enum _message_termination_t termination; }


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

v1 = SCPI_RegGet(a1, 0);
SCPI_ResultInt32(a1, v1);
return 1LL;
}

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

v1 = func1(a1, 0);
SCPI_ResultInt32(a1, v1);
return 1LL;
}

original_code:
scpi_result_t SCPI_CoreStbQ(scpi_t * context) {
    SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_STB));
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_CoreStbQ(struct _scpi_t *context) {
    SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_STB));
    return SCPI_RES_OK;
}

user_defined_types: struct _scpi_command_t { char *pattern; enum _scpi_result_t (*callback)(struct _scpi_t *); int tag; }


decompiled_code:
__int64 __fastcall SCPI_CoreTstQ(__int64 a1)
{
SCPI_ResultInt32(a1, 0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
SCPI_ResultInt32(a1, 0LL);
return 1LL;
}

original_code:
scpi_result_t SCPI_CoreTstQ(scpi_t * context) {
    (void) context;
    SCPI_ResultInt32(context, 0);
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_CoreTstQ(struct _scpi_t *context) {
    (void) context;
    SCPI_ResultInt32(context, 0);
    return SCPI_RES_OK;
}

user_defined_types: struct _scpi_interface_t { int (*error)(struct _scpi_t *context, long error); unsigned long (*write)(struct _scpi_t *context, char *data, unsigned long len); enum _scpi_result_t (*control)(struct _scpi_t *context, enum _scpi_ctrl_name_t ctrl, unsigned short val); enum _scpi_result_t (*flush)(struct _scpi_t *); enum _scpi_result_t (*reset)(struct _scpi_t *); }


decompiled_code:
__int64 SCPI_CoreWai()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func17()
{
return 1LL;
}

original_code:
scpi_result_t SCPI_CoreWai(scpi_t * context) {
    (void) context;
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_CoreWai(struct _scpi_t *context) {
    (void) context;
    return SCPI_RES_OK;
}

user_defined_types: struct _scpi_unit_def_t { char *name; enum _scpi_unit_t unit; double mult; }


original_code:
void fifo_init(scpi_fifo_t * fifo, scpi_error_t * data, int16_t size) {
    fifo->wr = 0;
    fifo->rd = 0;
    fifo->count = 0;
    fifo->data = data;
    fifo->size = size;
}

canonical_original_code:
void fifo_init(struct _scpi_fifo_t *fifo, struct _scpi_error_t *data, short size) {
    fifo->wr = 0;
    fifo->rd = 0;
    fifo->count = 0;
    fifo->data = data;
    fifo->size = size;
}

variable_types: struct _scpi_fifo_t { short wr; short rd; short count; short size; struct _scpi_error_t { short error_code; char *device_dependent_info; } *data; } *

variable_types:
data
struct _scpi_error_t *

variable_types: size short


decompiled_code:
bool __fastcall fifo_is_empty(__int64 a1)
{
return *(_WORD *)(a1 + 4) == 0;
}

canonical_decompiled_code:
bool __fastcall func2(__int64 a1)
{
return *(_WORD *)(a1 + 4) == 0;
}

original_code:
scpi_bool_t fifo_is_empty(scpi_fifo_t * fifo) {
    return fifo->count == 0;
}

canonical_original_code:
_Bool fifo_is_empty(struct _scpi_fifo_t *fifo) {
    return fifo->count == 0;
}


decompiled_code:
bool __fastcall fifo_is_full(__int64 a1)
{
return *(_WORD *)(a1 + 4) == *(_WORD *)(a1 + 6);
}

canonical_decompiled_code:
bool __fastcall func3(__int64 a1)
{
return *(_WORD *)(a1 + 4) == *(_WORD *)(a1 + 6);
}

original_code:
scpi_bool_t fifo_is_full(scpi_fifo_t * fifo) {
    return fifo->count == fifo->size;
}

canonical_original_code:
_Bool fifo_is_full(struct _scpi_fifo_t *fifo) {
    return fifo->count == fifo->size;
}


original_code:
scpi_bool_t fifo_add(scpi_fifo_t * fifo, const scpi_error_t * value) {
    if (fifo_is_full(fifo)) {
        return 0;
    }
    if (!value) {
        return 0;
    }
    fifo->data[fifo->wr] = *value;
    fifo->wr = (fifo->wr + 1) % (fifo->size);
    fifo->count += 1;
    return (!0);
}

canonical_original_code:
_Bool fifo_add(struct _scpi_fifo_t *fifo, struct _scpi_error_t *value) {
    if (fifo_is_full(fifo)) {
        return 0;
    }
    if (!value) {
        return 0;
    }
    fifo->data[fifo->wr] = *value;
    fifo->wr = (fifo->wr + 1) % (fifo->size);
    fifo->count += 1;
    return (!0);
}

variable_types:
value
struct _scpi_error_t *


original_code:
scpi_bool_t fifo_remove(scpi_fifo_t * fifo, scpi_error_t * value) {
    if (fifo_is_empty(fifo)) {
        return 0;
    }
    if (value) {
        *value = fifo->data[fifo->rd];
    }
    fifo->rd = (fifo->rd + 1) % (fifo->size);
    fifo->count -= 1;
    return (!0);
}

canonical_original_code:
_Bool fifo_remove(struct _scpi_fifo_t *fifo, struct _scpi_error_t *value) {
    if (fifo_is_empty(fifo)) {
        return 0;
    }
    if (value) {
        *value = fifo->data[fifo->rd];
    }
    fifo->rd = (fifo->rd + 1) % (fifo->size);
    fifo->count -= 1;
    return (!0);
}


original_code:
scpi_bool_t fifo_remove_last(scpi_fifo_t * fifo, scpi_error_t * value) {
    if (fifo_is_empty(fifo)) {
        return 0;
    }
    fifo->wr = (fifo->wr + fifo->size - 1) % (fifo->size);
    if (value) {
        *value = fifo->data[fifo->wr];
    }
    fifo->count -= 1;
    return (!0);
}

canonical_original_code:
_Bool fifo_remove_last(struct _scpi_fifo_t *fifo, struct _scpi_error_t *value) {
    if (fifo_is_empty(fifo)) {
        return 0;
    }
    fifo->wr = (fifo->wr + fifo->size - 1) % (fifo->size);
    if (value) {
        *value = fifo->data[fifo->wr];
    }
    fifo->count -= 1;
    return (!0);
}


decompiled_code:
__int64 __fastcall fifo_count(__int64 a1, _WORD *a2)
{
*a2 = *(_WORD *)(a1 + 4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _WORD *a2)
{
*a2 = *(_WORD *)(a1 + 4);
return 1LL;
}

original_code:
scpi_bool_t fifo_count(scpi_fifo_t * fifo, int16_t * value) {
    *value = fifo->count;
    return (!0);
}

canonical_original_code:
_Bool fifo_count(struct _scpi_fifo_t *fifo, short *value) {
    *value = fifo->count;
    return (!0);
}

variable_types:
value
short *


decompiled_code:
__int64 SCPI_Stub()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
scpi_result_t SCPI_Stub(scpi_t * context) {
    (void) context;
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_Stub(struct _scpi_t *context) {
    (void) context;
    return SCPI_RES_OK;
}

variable_types: struct _scpi_t { struct _scpi_command_t { char *pattern; enum _scpi_result_t { SCPI_RES_OK=1, SCPI_RES_ERR=-1 } (*callback)(struct _scpi_t *); int tag; } *cmdlist; struct _scpi_buffer_t { unsigned long length; unsigned long position; char *data; } buffer; struct _scpi_param_list_t { struct _scpi_command_t *cmd; struct _lex_state_t { char *buffer; char *pos; int len; } lex_state; struct _scpi_const_buffer_t { unsigned long length; unsigned long position; char *data; } cmd_raw; } param_list; struct _scpi_interface_t { int (*error)(struct _scpi_t *context, long error); unsigned long (*write)(struct _scpi_t *context, char *data, unsigned long len); enum _scpi_result_t { SCPI_RES_OK=1, SCPI_RES_ERR=-1 } (*control)(struct _scpi_t *context, enum _scpi_ctrl_name_t { SCPI_CTRL_SRQ=1, SCPI_CTRL_GTL=2, SCPI_CTRL_SDC=3, SCPI_CTRL_PPC=4, SCPI_CTRL_GET=5, SCPI_CTRL_TCT=6, SCPI_CTRL_LLO=7, SCPI_CTRL_DCL=8, SCPI_CTRL_PPU=9, SCPI_CTRL_SPE=10, SCPI_CTRL_SPD=11, SCPI_CTRL_MLA=12, SCPI_CTRL_UNL=13, SCPI_CTRL_MTA=14, SCPI_CTRL_UNT=15, SCPI_CTRL_MSA=16 } ctrl, unsigned short val); enum _scpi_result_t { SCPI_RES_OK=1, SCPI_RES_ERR=-1 } (*flush)(struct _scpi_t *); enum _scpi_result_t { SCPI_RES_OK=1, SCPI_RES_ERR=-1 } (*reset)(struct _scpi_t *); } *interface; long output_count; long input_count; _Bool first_output; _Bool cmd_error; struct _scpi_fifo_t { short wr; short rd; short count; short size; struct _scpi_error_t { short error_code; char *device_dependent_info; } *data; } error_queue; unsigned short registers[-1]; struct _scpi_unit_def_t { char *name; enum _scpi_unit_t { SCPI_UNIT_NONE=0, SCPI_UNIT_VOLT=1, SCPI_UNIT_AMPER=2, SCPI_UNIT_OHM=3, SCPI_UNIT_HERTZ=4, SCPI_UNIT_CELSIUS=5, SCPI_UNIT_SECOND=6, SCPI_UNIT_METER=7, SCPI_UNIT_GRAY=8, SCPI_UNIT_BECQUEREL=9, SCPI_UNIT_MOLE=10, SCPI_UNIT_DEGREE=11, SCPI_UNIT_GRADE=12, SCPI_UNIT_RADIAN=13, SCPI_UNIT_REVOLUTION=14, SCPI_UNIT_STERADIAN=15, SCPI_UNIT_SIEVERT=16, SCPI_UNIT_FARAD=17, SCPI_UNIT_COULOMB=18, SCPI_UNIT_SIEMENS=19, SCPI_UNIT_ELECTRONVOLT=20, SCPI_UNIT_JOULE=21, SCPI_UNIT_NEWTON=22, SCPI_UNIT_LUX=23, SCPI_UNIT_HENRY=24, SCPI_UNIT_ASTRONOMIC_UNIT=25, SCPI_UNIT_INCH=26, SCPI_UNIT_FOOT=27, SCPI_UNIT_PARSEC=28, SCPI_UNIT_MILE=29, SCPI_UNIT_NAUTICAL_MILE=30, SCPI_UNIT_LUMEN=31, SCPI_UNIT_CANDELA=32, SCPI_UNIT_WEBER=33, SCPI_UNIT_TESLA=34, SCPI_UNIT_ATOMIC_MASS=35, SCPI_UNIT_KILOGRAM=36, SCPI_UNIT_WATT=37, SCPI_UNIT_DBM=38, SCPI_UNIT_ATMOSPHERE=39, SCPI_UNIT_INCH_OF_MERCURY=40, SCPI_UNIT_MM_OF_MERCURY=41, SCPI_UNIT_PASCAL=42, SCPI_UNIT_TORT=43, SCPI_UNIT_BAR=44, SCPI_UNIT_DECIBEL=45, SCPI_UNIT_UNITLESS=46, SCPI_UNIT_FAHRENHEIT=47, SCPI_UNIT_KELVIN=48, SCPI_UNIT_DAY=49, SCPI_UNIT_YEAR=50, SCPI_UNIT_STROKES=51, SCPI_UNIT_POISE=52, SCPI_UNIT_LITER=53 } unit; double mult; } *units; void *user_context; struct _scpi_parser_state_t { struct _scpi_token_t { enum _scpi_token_type_t { SCPI_TOKEN_COMMA=0, SCPI_TOKEN_SEMICOLON=1, SCPI_TOKEN_COLON=2, SCPI_TOKEN_SPECIFIC_CHARACTER=3, SCPI_TOKEN_QUESTION=4, SCPI_TOKEN_NL=5, SCPI_TOKEN_HEXNUM=6, SCPI_TOKEN_OCTNUM=7, SCPI_TOKEN_BINNUM=8, SCPI_TOKEN_PROGRAM_MNEMONIC=9, SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA=10, SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX=11, SCPI_TOKEN_SUFFIX_PROGRAM_DATA=12, SCPI_TOKEN_ARBITRARY_BLOCK_PROGRAM_DATA=13, SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA=14, SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA=15, SCPI_TOKEN_PROGRAM_EXPRESSION=16, SCPI_TOKEN_COMPOUND_PROGRAM_HEADER=17, SCPI_TOKEN_INCOMPLETE_COMPOUND_PROGRAM_HEADER=18, SCPI_TOKEN_COMMON_PROGRAM_HEADER=19, SCPI_TOKEN_INCOMPLETE_COMMON_PROGRAM_HEADER=20, SCPI_TOKEN_COMPOUND_QUERY_PROGRAM_HEADER=21, SCPI_TOKEN_COMMON_QUERY_PROGRAM_HEADER=22, SCPI_TOKEN_WS=23, SCPI_TOKEN_ALL_PROGRAM_DATA=24, SCPI_TOKEN_INVALID=25, SCPI_TOKEN_UNKNOWN=26 } type; char *ptr; int len; } programHeader; struct _scpi_token_t programData; int numberOfParameters; enum _message_termination_t { SCPI_MESSAGE_TERMINATION_NONE=0, SCPI_MESSAGE_TERMINATION_NL=1, SCPI_MESSAGE_TERMINATION_SEMICOLON=2 } termination; } parser_state; char *idn[4]; unsigned long arbitrary_remaining; } *

user_defined_types: struct _scpi_token_t { enum _scpi_token_type_t type; char *ptr; int len; }


decompiled_code:
__int64 __fastcall SCPI_StubQ(__int64 a1)
{
SCPI_ResultInt32(a1, 0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
SCPI_ResultInt32(a1, 0LL);
return 1LL;
}

original_code:
scpi_result_t SCPI_StubQ(scpi_t * context) {
    SCPI_ResultInt32(context, 0);
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_StubQ(struct _scpi_t *context) {
    SCPI_ResultInt32(context, 0);
    return SCPI_RES_OK;
}

user_defined_types: struct _scpi_buffer_t { unsigned long length; unsigned long position; char *data; }


decompiled_code:
__int64 __fastcall SCPI_SystemVersionQ(__int64 a1)
{
SCPI_ResultCharacters(a1, "1999.0", 6LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
SCPI_ResultCharacters(a1, "1999.0", 6LL);
return 1LL;
}

original_code:
scpi_result_t SCPI_SystemVersionQ(scpi_t * context) {
    SCPI_ResultCharacters((context), ("1999.0"), strlen("1999.0"));
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_SystemVersionQ(struct _scpi_t *context) {
    SCPI_ResultCharacters((context), ("1999.0"), strlen("1999.0"));
    return SCPI_RES_OK;
}

user_defined_types: struct _lex_state_t { char *buffer; char *pos; int len; }


decompiled_code:
__int64 __fastcall SCPI_SystemErrorNextQ(__int64 a1)
{
__int64 _0; // [rsp+0h] [rbp+0h] BYREF
void *ptr; // [rsp+8h] [rbp+8h]

SCPI_ErrorPop(a1, &_0);
SCPI_ResultError(a1, &_0);
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 _0; // [rsp+0h] [rbp+0h] BYREF
void *ptr; // [rsp+8h] [rbp+8h]

SCPI_ErrorPop(a1, &_0);
SCPI_ResultError(a1, &_0);
free(ptr);
return 1LL;
}

original_code:
scpi_result_t SCPI_SystemErrorNextQ(scpi_t * context) {
    scpi_error_t error;
    SCPI_ErrorPop(context, &error);
    SCPI_ResultError(context, &error);
    free((error.device_dependent_info));
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_SystemErrorNextQ(struct _scpi_t *context) {
    struct _scpi_error_t error;
    SCPI_ErrorPop(context, &error);
    SCPI_ResultError(context, &error);
    free((error.device_dependent_info));
    return SCPI_RES_OK;
}

variable_types: struct _scpi_error_t { short error_code; char *device_dependent_info; }

user_defined_types: struct _scpi_const_buffer_t { unsigned long length; unsigned long position; char *data; }