adjFreq

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

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

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

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

return_type: void


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)
{
double v2; // rbx
int v3; // edx
double v5; // [rsp+0h] [rbp-20h]

v2 = diff(&ta, &tp) / (double)a2;
v5 = diff(&tb, &stru_4040B0) / (double)a2;
if ( v3 )
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, (v2 - v5) / 1000.0);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1, int a2)
{
double v2; // rbx
int v3; // edx
double v5; // [rsp+0h] [rbp-20h]

v2 = func9(&ta, &tp) / (double)a2;
v5 = func9(&tb, &stru_4040B0) / (double)a2;
if ( v3 )
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, (v2 - v5) / 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)
{
unsigned int v3; // er12
unsigned int v4; // er13
unsigned int v5; // er14

if ( argc == 4 )
{
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
LABEL_3:
v5 = atoi(argv[3]);
goto LABEL_4;
}
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");
if ( argc <= 1 )
{
v4 = 10;
v3 = 0;
v5 = 0;
goto LABEL_4;
}
v4 = 10;
v5 = 0;
v3 = atoi(argv[1]);
if ( argc != 2 )
{
v4 = atoi(argv[2]);
if ( argc != 3 )
goto LABEL_3;
}
LABEL_4:
measure(v3, v4, v5);
display(v3, v4, v5);
return 0;
}

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

if ( argc == 4 )
{
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
LABEL_3:
v5 = atoi(argv[3]);
goto LABEL_4;
}
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");
if ( argc <= 1 )
{
v4 = 10;
v3 = 0;
v5 = 0;
goto LABEL_4;
}
v4 = 10;
v5 = 0;
v3 = atoi(argv[1]);
if ( argc != 2 )
{
v4 = atoi(argv[2]);
if ( argc != 3 )
goto LABEL_3;
}
LABEL_4:
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 **

return_type: int


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
const char *v1; // rsi
__int64 v2; // rdx
__m128i v4; // [rsp+0h] [rbp-28h] BYREF
__m128i v5; // [rsp+10h] [rbp-18h] BYREF

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

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

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

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
__m128i v6; // [rsp+10h] [rbp-18h] BYREF

gettimeofday((struct timeval *)&v5, 0LL);
v6 = _mm_loadu_si128(&v5);
if ( v6.m128i_i64[1] == v5.m128i_i64[1] )
{
v0 = 0;
do
{
++v0;
gettimeofday((struct timeval *)&v5, 0LL);
}
while ( v6.m128i_i64[1] == v5.m128i_i64[1] );
v1 = diff_timeval(&v6, &v5);
v2 = v1;
if ( v0 != 1 || (v3 = (const char *)&unk_402004, v1 == 1000) )
v3 = "\tclock_gettime: %s%d ns\r\n" + 25;
}
else
{
v3 = "\tclock_gettime: %s%d ns\r\n" + 25;
v2 = (unsigned int)diff_timeval(&v6, &v5);
}
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
__m128i v6; // [rsp+10h] [rbp-18h] BYREF

gettimeofday((struct timeval *)&v5, 0LL);
v6 = _mm_loadu_si128(&v5);
if ( v6.m128i_i64[1] == v5.m128i_i64[1] )
{
v0 = 0;
do
{
++v0;
gettimeofday((struct timeval *)&v5, 0LL);
}
while ( v6.m128i_i64[1] == v5.m128i_i64[1] );
v1 = func8(&v6, &v5);
v2 = v1;
if ( v0 != 1 || (v3 = (const char *)&unk_402004, v1 == 1000) )
v3 = "\tclock_gettime: %s%d ns\r\n" + 25;
}
else
{
v3 = "\tclock_gettime: %s%d ns\r\n" + 25;
v2 = (unsigned int)func8(&v6, &v5);
}
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("granularity:\r", argv);
measure_gettimeofday();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("granularity:\r");
func9("granularity:\r", argv);
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; }


decompiled_code:
void __fastcall SCPI_RegSet(__int64 a1, unsigned int a2, int a3)
{
unsigned int v3; // er8
unsigned int v6; // edx
char *v7; // rax
unsigned int v8; // ecx
unsigned int v9; // edi
unsigned int v10; // esi
unsigned int v11; // er9
unsigned int v12; // er15
int v13; // er11
__int64 v14; // rax
int v15; // er10
int v16; // eax
int v17; // edx
int v18; // ebp
unsigned __int16 v19; // si
__int16 v20; // ax
int v21; // eax
int v22; // er10
int v23; // edx
int v24; // ebp
int v25; // eax
int v26; // [rsp+0h] [rbp-44h]
unsigned int v27; // [rsp+0h] [rbp-44h]
unsigned int v28; // [rsp+0h] [rbp-44h]
int v29; // [rsp+0h] [rbp-44h]
int v30; // [rsp+0h] [rbp-44h]
unsigned int v31; // [rsp+0h] [rbp-44h]
unsigned int v32; // [rsp+4h] [rbp-40h]
int v33; // [rsp+4h] [rbp-40h]
unsigned int v34; // [rsp+8h] [rbp-3Ch]
int v35; // [rsp+8h] [rbp-3Ch]

if ( a2 <= 9 )
{
v3 = a2;
if ( a1 )
{
while ( 2 )
{
v6 = scpi_reg_details[2 * v3];
v7 = (char *)&scpi_reg_group_details + 28 * scpi_reg_details[2 * v3 + 1];
v8 = *(_DWORD *)v7;
v9 = *((_DWORD *)v7 + 1);
v10 = *((_DWORD *)v7 + 3);
v11 = *((_DWORD *)v7 + 4);
v12 = *((_DWORD *)v7 + 5);
v13 = *((unsigned __int16 *)v7 + 12);
v14 = v3 + 64LL;
v15 = *(unsigned __int16 *)(a1 + 2 * v14 + 8);
if ( (_WORD)a3 != (_WORD)v15 )
{
*(_WORD *)(a1 + 2 * v14 + 8) = a3;
switch ( v6 )
{
case 0u:
case 1u:
if ( (*(_WORD *)(a1 + 138) & *(_WORD *)(a1 + 136) & 0xFFBF) != 0 )
{
v19 = *(_WORD *)(a1 + 136) | 0x40;
*(_WORD *)(a1 + 136) = v19;
if ( ((unsigned __int16)a3 & (unsigned __int16)~(_WORD)v15) != 0 )
{
v28 = v3;
writeControl_constprop_0_isra_0(a1, v19);
v3 = v28;
}
goto LABEL_9;
}
*(_WORD *)(a1 + 136) &= 0xFFBFu;
if ( v12 != 11 )
continue;
return;
case 2u:
if ( v9 != 11 )
{
v29 = v13;
v20 = SCPI_RegGet(a1, v9);
v13 = v29;
LOWORD(a3) = v20 & a3;
}
v30 = v13;
v21 = SCPI_RegGet(a1, v12);
if ( (_WORD)a3 )
{
v3 = v12;
a3 = v30 | v21;
if ( v12 != 11 )
continue;
}
else
{
v3 = v12;
a3 = v21 & ~v30;
if ( v12 != 11 )
continue;
}
return;
case 3u:
case 5u:
case 6u:
return;
case 4u:
if ( v10 == 11 )
{
if ( v11 == 11 )
{
v18 = ~v15 & a3;
goto LABEL_8;
}
v22 = a3 ^ v15;
v23 = a3;
v24 = 0;
v17 = v22 & v23;
}
else
{
v34 = v11;
v32 = v8;
v26 = v15;
v16 = SCPI_RegGet(a1, v10);
v11 = v34;
v8 = v32;
v17 = a3 & ~v26;
if ( v34 == 11 )
{
v18 = v17 & v16;
LABEL_8:
v27 = v8;
a3 = SCPI_RegGet(a1, v8) | v18;
v3 = v27;
goto LABEL_9;
}
v22 = a3 ^ v26;
v24 = v17 & v16;
}
v35 = v17;
v33 = v22;
v31 = v8;
v25 = SCPI_RegGet(a1, v11);
v8 = v31;
v18 = v25 & v33 & ~v35 | v24;
goto LABEL_8;
default:
LABEL_9:
if ( v12 == 11 )
return;
continue;
}
}
break;
}
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, unsigned int a2, int a3)
{
unsigned int v3; // er8
unsigned int v6; // edx
char *v7; // rax
unsigned int v8; // ecx
unsigned int v9; // edi
unsigned int v10; // esi
unsigned int v11; // er9
unsigned int v12; // er15
int v13; // er11
__int64 v14; // rax
int v15; // er10
int v16; // eax
int v17; // edx
int v18; // ebp
unsigned __int16 v19; // si
__int16 v20; // ax
int v21; // eax
int v22; // er10
int v23; // edx
int v24; // ebp
int v25; // eax
int v26; // [rsp+0h] [rbp-44h]
unsigned int v27; // [rsp+0h] [rbp-44h]
unsigned int v28; // [rsp+0h] [rbp-44h]
int v29; // [rsp+0h] [rbp-44h]
int v30; // [rsp+0h] [rbp-44h]
unsigned int v31; // [rsp+0h] [rbp-44h]
unsigned int v32; // [rsp+4h] [rbp-40h]
int v33; // [rsp+4h] [rbp-40h]
unsigned int v34; // [rsp+8h] [rbp-3Ch]
int v35; // [rsp+8h] [rbp-3Ch]

if ( a2 <= 9 )
{
v3 = a2;
if ( a1 )
{
while ( 2 )
{
v6 = scpi_reg_details[2 * v3];
v7 = (char *)&scpi_reg_group_details + 28 * scpi_reg_details[2 * v3 + 1];
v8 = *(_DWORD *)v7;
v9 = *((_DWORD *)v7 + 1);
v10 = *((_DWORD *)v7 + 3);
v11 = *((_DWORD *)v7 + 4);
v12 = *((_DWORD *)v7 + 5);
v13 = *((unsigned __int16 *)v7 + 12);
v14 = v3 + 64LL;
v15 = *(unsigned __int16 *)(a1 + 2 * v14 + 8);
if ( (_WORD)a3 != (_WORD)v15 )
{
*(_WORD *)(a1 + 2 * v14 + 8) = a3;
switch ( v6 )
{
case 0u:
case 1u:
if ( (*(_WORD *)(a1 + 138) & *(_WORD *)(a1 + 136) & 0xFFBF) != 0 )
{
v19 = *(_WORD *)(a1 + 136) | 0x40;
*(_WORD *)(a1 + 136) = v19;
if ( ((unsigned __int16)a3 & (unsigned __int16)~(_WORD)v15) != 0 )
{
v28 = v3;
func0(a1, v19);
v3 = v28;
}
goto LABEL_9;
}
*(_WORD *)(a1 + 136) &= 0xFFBFu;
if ( v12 != 11 )
continue;
return;
case 2u:
if ( v9 != 11 )
{
v29 = v13;
v20 = func1(a1, v9);
v13 = v29;
LOWORD(a3) = v20 & a3;
}
v30 = v13;
v21 = func1(a1, v12);
if ( (_WORD)a3 )
{
v3 = v12;
a3 = v30 | v21;
if ( v12 != 11 )
continue;
}
else
{
v3 = v12;
a3 = v21 & ~v30;
if ( v12 != 11 )
continue;
}
return;
case 3u:
case 5u:
case 6u:
return;
case 4u:
if ( v10 == 11 )
{
if ( v11 == 11 )
{
v18 = ~v15 & a3;
goto LABEL_8;
}
v22 = a3 ^ v15;
v23 = a3;
v24 = 0;
v17 = v22 & v23;
}
else
{
v34 = v11;
v32 = v8;
v26 = v15;
v16 = func1(a1, v10);
v11 = v34;
v8 = v32;
v17 = a3 & ~v26;
if ( v34 == 11 )
{
v18 = v17 & v16;
LABEL_8:
v27 = v8;
a3 = func1(a1, v8) | v18;
v3 = v27;
goto LABEL_9;
}
v22 = a3 ^ v26;
v24 = v17 & v16;
}
v35 = v17;
v33 = v22;
v31 = v8;
v25 = func1(a1, v11);
v8 = v31;
v18 = v25 & v33 & ~v35 | v24;
goto LABEL_8;
default:
LABEL_9:
if ( v12 == 11 )
return;
continue;
}
}
break;
}
}
}
}

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 v3; // bx
unsigned __int16 v4; // ax

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

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

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

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
unsigned int *v2; // r12
unsigned int v3; // esi

v1 = (unsigned int *)&scpi_reg_group_details;
v2 = (unsigned int *)((char *)&scpi_reg_group_details + 112);
SCPI_ErrorClear();
while ( 1 )
{
v1 += 7;
if ( v1 == v2 )
break;
while ( 1 )
{
v3 = *v1;
if ( !*v1 )
break;
v1 += 7;
SCPI_RegSet(a1, v3, 0);
if ( v1 == v2 )
return 1LL;
}
}
return 1LL;
}

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

v1 = (unsigned int *)&scpi_reg_group_details;
v2 = (unsigned int *)((char *)&scpi_reg_group_details + 112);
SCPI_ErrorClear();
while ( 1 )
{
v1 += 7;
if ( v1 == v2 )
break;
while ( 1 )
{
v3 = *v1;
if ( !*v1 )
break;
v1 += 7;
func2(a1, v3, 0);
if ( v1 == v2 )
return 1LL;
}
}
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; // r8
__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; // r8
__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
const char *v2; // rbp
size_t v3; // rax

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

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

v1 = (const char **)(a1 + 232);
do
{
v2 = *v1;
if ( *v1 )
{
v3 = strlen(*v1);
SCPI_ResultCharacters(a1, v2, v3);
}
else
{
SCPI_ResultCharacters(a1, &LC0, 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 v1; // rax
__int64 (*v2)(void); // rax
__int64 result; // rax

if ( a1 && (v1 = *(_QWORD *)(a1 + 88)) != 0 && (v2 = *(__int64 (**)(void))(v1 + 32)) != 0LL )
result = v2();
else
result = 1LL;
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; // r8
__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; // r8
__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; }


decompiled_code:
__int64 __fastcall fifo_init(__int64 a1, __int64 a2, __int16 a3)
{
__int64 result; // rax

result = 0LL;
*(_DWORD *)a1 = 0;
*(_WORD *)(a1 + 4) = 0;
*(_QWORD *)(a1 + 8) = a2;
*(_WORD *)(a1 + 6) = a3;
return result;
}

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


decompiled_code:
__int64 __fastcall fifo_add(__int16 *a1, const __m128i *a2)
{
bool v2; // al
int v3; // ecx
int v4; // eax
int v5; // edx
__int64 result; // rax

v2 = fifo_is_full((__int64)a1);
if ( !a2 || v2 )
return 0LL;
v3 = a1[3];
v4 = *a1 + 1;
*(__m128i *)(*((_QWORD *)a1 + 1) + 16LL * *a1) = _mm_loadu_si128(a2);
++a1[2];
v5 = v4 % v3;
result = 1LL;
*a1 = v5;
return result;
}

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


decompiled_code:
__int64 __fastcall fifo_remove_last(__int16 *a1, __m128i *a2)
{
bool v2; // r8
__int64 result; // rax
int v4; // edx

v2 = fifo_is_empty((__int64)a1);
result = 0LL;
if ( !v2 )
{
v4 = (a1[3] + *a1 - 1) % a1[3];
*a1 = v4;
if ( a2 )
*a2 = _mm_loadu_si128((const __m128i *)(*((_QWORD *)a1 + 1) + 16LL * v4));
--a1[2];
result = 1LL;
}
return result;
}

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 v2; // [rsp+0h] [rbp-28h] BYREF
void *ptr; // [rsp+8h] [rbp-20h]

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

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

SCPI_ErrorPop(a1, &v2);
SCPI_ResultError(a1, &v2);
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; }


decompiled_code:
__int64 __fastcall SCPI_SystemErrorCountQ(__int64 a1)
{
unsigned int v1; // eax

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v1; // eax

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

original_code:
scpi_result_t SCPI_SystemErrorCountQ(scpi_t * context) {
    SCPI_ResultInt32(context, SCPI_ErrorCount(context));
    return SCPI_RES_OK;
}

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

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_StatusQuestionableConditionQ(__int64 a1)
{
unsigned __int16 v1; // ax

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

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

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

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

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

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


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

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

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

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

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

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

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_StatusQuestionableEnableQ(__int64 a1)
{
unsigned __int16 v1; // ax

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall SCPI_StatusQuestionableEnable(__int64 a1)
{
unsigned __int16 v2[6]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned __int8)SCPI_ParamInt32(a1, v2, 1LL) )
SCPI_RegSet(a1, 8LL, v2[0]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
unsigned __int16 v2[6]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned __int8)SCPI_ParamInt32(a1, v2, 1LL) )
SCPI_RegSet(a1, 8LL, v2[0]);
return 1LL;
}

original_code:
scpi_result_t SCPI_StatusQuestionableEnable(scpi_t * context) {
    int32_t new_QUESE;
    if (SCPI_ParamInt32(context, &new_QUESE, (!0))) {
        SCPI_RegSet(context, SCPI_REG_QUESE, (scpi_reg_val_t) new_QUESE);
    }
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_StatusQuestionableEnable(struct _scpi_t *context) {
    int new_QUESE;
    if (SCPI_ParamInt32(context, &new_QUESE, (!0))) {
        SCPI_RegSet(context, SCPI_REG_QUESE, (unsigned short) new_QUESE);
    }
    return SCPI_RES_OK;
}

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_StatusOperationConditionQ(__int64 a1)
{
unsigned __int16 v1; // ax

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

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

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

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

canonical_original_code:
enum _scpi_result_t SCPI_StatusOperationConditionQ(struct _scpi_t *context) {
    SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_OPERC));
    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_StatusOperationEventQ(__int64 a1)
{
unsigned __int16 v1; // ax

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

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

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

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

canonical_original_code:
enum _scpi_result_t SCPI_StatusOperationEventQ(struct _scpi_t *context) {
    SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_OPER));
    SCPI_RegSet(context, SCPI_REG_OPER, 0);
    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_StatusOperationEnableQ(__int64 a1)
{
unsigned __int16 v1; // ax

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

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

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

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

canonical_original_code:
enum _scpi_result_t SCPI_StatusOperationEnableQ(struct _scpi_t *context) {
    SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_OPERE));
    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_StatusOperationEnable(__int64 a1)
{
unsigned __int16 v2[6]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned __int8)SCPI_ParamInt32(a1, v2, 1LL) )
SCPI_RegSet(a1, 5LL, v2[0]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
unsigned __int16 v2[6]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned __int8)SCPI_ParamInt32(a1, v2, 1LL) )
SCPI_RegSet(a1, 5LL, v2[0]);
return 1LL;
}

original_code:
scpi_result_t SCPI_StatusOperationEnable(scpi_t * context) {
    int32_t new_OPERE;
    if (SCPI_ParamInt32(context, &new_OPERE, (!0))) {
        SCPI_RegSet(context, SCPI_REG_OPERE, (scpi_reg_val_t) new_OPERE);
    }
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_StatusOperationEnable(struct _scpi_t *context) {
    int new_OPERE;
    if (SCPI_ParamInt32(context, &new_OPERE, (!0))) {
        SCPI_RegSet(context, SCPI_REG_OPERE, (unsigned short) new_OPERE);
    }
    return SCPI_RES_OK;
}

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_StatusPreset(__int64 a1)
{
SCPI_RegSet(a1, 7LL, 0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
SCPI_RegSet(a1, 7LL, 0LL);
return 1LL;
}

original_code:
scpi_result_t SCPI_StatusPreset(scpi_t * context) {
    SCPI_RegSet(context, SCPI_REG_QUES, 0);
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_StatusPreset(struct _scpi_t *context) {
    SCPI_RegSet(context, SCPI_REG_QUES, 0);
    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_ErrorAddInternal(__int64 a1, __int16 a2, const char *a3, size_t a4)
{
char *v5; // rdi
__int64 v6; // rbp
unsigned int v7; // er12
__int16 v9; // [rsp+0h] [rbp-28h] BYREF
void *ptr; // [rsp+8h] [rbp-20h]

v5 = (char *)a3;
if ( a3 )
v5 = strndup(a3, a4);
v6 = a1 + 120;
ptr = v5;
v9 = a2;
v7 = fifo_add(v6, &v9);
if ( !(_BYTE)v7 )
{
free(ptr);
fifo_remove_last(v6, &v9);
free(ptr);
v9 = -350;
ptr = 0LL;
fifo_add(v6, &v9);
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int16 a2, const char *a3, size_t a4)
{
char *v5; // rdi
__int64 v6; // rbp
unsigned int v7; // er12
__int16 v9; // [rsp+0h] [rbp-28h] BYREF
void *ptr; // [rsp+8h] [rbp-20h]

v5 = (char *)a3;
if ( a3 )
v5 = strndup(a3, a4);
v6 = a1 + 120;
ptr = v5;
v9 = a2;
v7 = fifo_add(v6, &v9);
if ( !(_BYTE)v7 )
{
free(ptr);
fifo_remove_last(v6, &v9);
free(ptr);
v9 = -350;
ptr = 0LL;
fifo_add(v6, &v9);
}
return v7;
}

original_code:
static scpi_bool_t SCPI_ErrorAddInternal(scpi_t * context, int16_t err, char * info, size_t info_len) {
    scpi_error_t error_value;
    (void) info_len;
    char * info_ptr = ((void *)0);
    if (info) {
        info_ptr = strndup((info), (info_len));
    }
    do { (&error_value)->error_code = (err); (&error_value)->device_dependent_info = (info_ptr); } while(0);
    if (!fifo_add(&context->error_queue, &error_value)) {
        free((error_value.device_dependent_info));
        fifo_remove_last(&context->error_queue, &error_value);
        free((error_value.device_dependent_info));
        do { (&error_value)->error_code = (SCPI_ERROR_QUEUE_OVERFLOW); (&error_value)->device_dependent_info = (((void *)0)); } while(0);
        fifo_add(&context->error_queue, &error_value);
        return 0;
    }
    return (!0);
}

canonical_original_code:
static _Bool SCPI_ErrorAddInternal(struct _scpi_t *context, short err, char *info, unsigned long info_len) {
    struct _scpi_error_t error_value;
    (void) info_len;
    char *info_ptr = ((void *)0);
    if (info) {
        info_ptr = strndup((info), (info_len));
    }
    do { (&error_value)->error_code = (err); (&error_value)->device_dependent_info = (info_ptr); } while(0);
    if (!fifo_add(&context->error_queue, &error_value)) {
        free((error_value.device_dependent_info));
        fifo_remove_last(&context->error_queue, &error_value);
        free((error_value.device_dependent_info));
        do { (&error_value)->error_code = (SCPI_ERROR_QUEUE_OVERFLOW); (&error_value)->device_dependent_info = (((void *)0)); } while(0);
        fifo_add(&context->error_queue, &error_value);
        return 0;
    }
    return (!0);
}

variable_types: err short

variable_types:
info
char *

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


decompiled_code:
__int64 __fastcall SCPI_ErrorInit(__int64 a1, __int64 a2, __int16 a3)
{
return fifo_init(a1 + 120, a2, (unsigned int)a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int16 a3)
{
return fifo_init(a1 + 120, a2, (unsigned int)a3);
}

original_code:
void SCPI_ErrorInit(scpi_t * context, scpi_error_t * data, int16_t size) {
    fifo_init(&context->error_queue, data, size);
}

canonical_original_code:
void SCPI_ErrorInit(struct _scpi_t *context, struct _scpi_error_t *data, short size) {
    fifo_init(&context->error_queue, data, size);
}

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 __fastcall SCPI_ErrorCount(__int64 a1)
{
__int16 v2[5]; // [rsp+Eh] [rbp-Ah] BYREF

v2[0] = 0;
fifo_count(a1 + 120, v2);
return (unsigned int)v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int16 v2[5]; // [rsp+Eh] [rbp-Ah] BYREF

v2[0] = 0;
fifo_count(a1 + 120, v2);
return (unsigned int)v2[0];
}

original_code:
int32_t SCPI_ErrorCount(scpi_t * context) {
    int16_t result = 0;
    fifo_count(&context->error_queue, &result);
    return result;
}

canonical_original_code:
int SCPI_ErrorCount(struct _scpi_t *context) {
    short result = 0;
    fifo_count(&context->error_queue, &result);
    return result;
}

variable_types: result short

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


decompiled_code:
__int64 __fastcall SCPI_ErrorEmitEmpty(__int64 a1)
{
__int64 result; // rax

result = SCPI_ErrorCount(a1);
if ( !(_DWORD)result )
{
result = SCPI_RegGet(a1, 0LL);
if ( (result & 4) != 0 )
{
SCPI_RegClearBits(a1, 0LL, 4LL);
result = *(_QWORD *)(a1 + 88);
if ( result )
{
result = *(_QWORD *)result;
if ( result )
result = ((__int64 (__fastcall *)(__int64, _QWORD))result)(a1, 0LL);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax

result = func2(a1);
if ( !(_DWORD)result )
{
result = SCPI_RegGet(a1, 0LL);
if ( (result & 4) != 0 )
{
SCPI_RegClearBits(a1, 0LL, 4LL);
result = *(_QWORD *)(a1 + 88);
if ( result )
{
result = *(_QWORD *)result;
if ( result )
result = ((__int64 (__fastcall *)(__int64, _QWORD))result)(a1, 0LL);
}
}
}
return result;
}

original_code:
static void SCPI_ErrorEmitEmpty(scpi_t * context) {
    if ((SCPI_ErrorCount(context) == 0) && (SCPI_RegGet(context, SCPI_REG_STB) & 0x04)) {
        SCPI_RegClearBits(context, SCPI_REG_STB, 0x04);
        if (context->interface && context->interface->error) {
            context->interface->error(context, 0);
        }
    }
}

canonical_original_code:
static void SCPI_ErrorEmitEmpty(struct _scpi_t *context) {
    if ((SCPI_ErrorCount(context) == 0) && (SCPI_RegGet(context, SCPI_REG_STB) & 0x04)) {
        SCPI_RegClearBits(context, SCPI_REG_STB, 0x04);
        if (context->interface && context->interface->error) {
            context->interface->error(context, 0);
        }
    }
}

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


decompiled_code:
__int64 __fastcall SCPI_ErrorClear(__int64 a1)
{
__int64 v1; // rbp
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
void *ptr; // [rsp+8h] [rbp-20h]

v1 = a1 + 120;
while ( (unsigned __int8)fifo_remove(v1, &v3) )
free(ptr);
fifo_clear(v1);
return SCPI_ErrorEmitEmpty(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbp
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
void *ptr; // [rsp+8h] [rbp-20h]

v1 = a1 + 120;
while ( (unsigned __int8)fifo_remove(v1, &v3) )
free(ptr);
fifo_clear(v1);
return func3(a1);
}

original_code:
void SCPI_ErrorClear(scpi_t * context) {
    scpi_error_t error;
    while (fifo_remove(&context->error_queue, &error)) {
        free((error.device_dependent_info));
    }
    fifo_clear(&context->error_queue);
    SCPI_ErrorEmitEmpty(context);
}

canonical_original_code:
void SCPI_ErrorClear(struct _scpi_t *context) {
    struct _scpi_error_t error;
    while (fifo_remove(&context->error_queue, &error)) {
        free((error.device_dependent_info));
    }
    fifo_clear(&context->error_queue);
    SCPI_ErrorEmitEmpty(context);
}

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


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

if ( !a2 )
return 0LL;
result = 0LL;
if ( a1 )
{
*(_QWORD *)(a2 + 8) = 0LL;
*(_WORD *)a2 = 0;
fifo_remove(a1 + 120, a2);
SCPI_ErrorEmitEmpty(a1);
result = 1LL;
}
return result;
}

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

if ( !a2 )
return 0LL;
result = 0LL;
if ( a1 )
{
*(_QWORD *)(a2 + 8) = 0LL;
*(_WORD *)a2 = 0;
fifo_remove(a1 + 120, a2);
func3(a1);
result = 1LL;
}
return result;
}

original_code:
scpi_bool_t SCPI_ErrorPop(scpi_t * context, scpi_error_t * error) {
    if (!error || !context) return 0;
    do { (error)->error_code = (0); (error)->device_dependent_info = (((void *)0)); } while(0);
    fifo_remove(&context->error_queue, error);
    SCPI_ErrorEmitEmpty(context);
    return (!0);
}

canonical_original_code:
_Bool SCPI_ErrorPop(struct _scpi_t *context, struct _scpi_error_t *error) {
    if (!error || !context) return 0;
    do { (error)->error_code = (0); (error)->device_dependent_info = (((void *)0)); } while(0);
    fifo_remove(&context->error_queue, error);
    SCPI_ErrorEmitEmpty(context);
    return (!0);
}

variable_types:
error
struct _scpi_error_t *

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