createServer

decompiled_code:
__int64 __fastcall createServer(__int64 a1)
{
int v1; // edx
int v2; // eax
unsigned int v3; // er12
const char *v5; // rdi
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

optval = 1;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32_constprop_0(a1, 1LL, 0LL);
*(_WORD *)addr.sa_data = _bswap_16(a1);
v2 = socket(2, 1, v1);
if ( v2 < 0 )
{
perror("socket() failed");
exit(-1);
}
v3 = v2;
if ( setsockopt(v2, 1, 2, &optval, 4u) < 0 )
{
v5 = "setsockopt() failed";
LABEL_8:
perror(v5);
close(v3);
exit(-1);
}
if ( ioctl(v3, 0x5421uLL, &optval) < 0 )
{
v5 = "ioctl() failed";
goto LABEL_8;
}
if ( bind(v3, &addr, 0x10u) < 0 )
{
v5 = "bind() failed";
goto LABEL_8;
}
listen(v3, 1);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int v1; // edx
int v2; // eax
unsigned int v3; // er12
const char *v5; // rdi
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

optval = 1;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func8(a1, 1LL, 0LL);
*(_WORD *)addr.sa_data = func1(a1);
v2 = socket(2, 1, v1);
if ( v2 < 0 )
{
perror("socket() failed");
exit(-1);
}
v3 = v2;
if ( setsockopt(v2, 1, 2, &optval, 4u) < 0 )
{
v5 = "setsockopt() failed";
LABEL_8:
perror(v5);
close(v3);
exit(-1);
}
if ( ioctl(v3, 0x5421uLL, &optval) < 0 )
{
v5 = "ioctl() failed";
goto LABEL_8;
}
if ( bind(v3, &addr, 0x10u) < 0 )
{
v5 = "bind() failed";
goto LABEL_8;
}
listen(v3, 1);
return v3;
}

original_code:
static int createServer(int port) {
    int fd;
    int rc;
    int on = 1;
    struct sockaddr_in servaddr;
    memset(&servaddr, 0, sizeof (servaddr));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    servaddr.sin_port = htons(port);
    fd = socket(2, SOCK_STREAM, 0);
    if (fd < 0) {
        perror("socket() failed");
        exit(-1);
    }
    rc = setsockopt(fd, 1, 2, (char *) &on, sizeof (on));
    if (rc < 0) {
        perror("setsockopt() failed");
        close(fd);
        exit(-1);
    }
    rc = ioctl(fd, 0x5421, (char *) &on);
    if (rc < 0) {
        perror("ioctl() failed");
        close(fd);
        exit(-1);
    }
    rc = bind(fd, (struct sockaddr *) &servaddr, sizeof (servaddr));
    if (rc < 0) {
        perror("bind() failed");
        close(fd);
        exit(-1);
    }
    listen(fd, 1);
    if (rc < 0) {
        perror("listen() failed");
        close(fd);
        exit(-1);
    }
    return fd;
}

canonical_original_code:
static int createServer(int port) {
    int fd;
    int rc;
    int on = 1;
    struct sockaddr_in servaddr;
    memset(&servaddr, 0, sizeof (servaddr));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    servaddr.sin_port = htons(port);
    fd = socket(2, SOCK_STREAM, 0);
    if (fd < 0) {
        perror("socket() failed");
        exit(-1);
    }
    rc = setsockopt(fd, 1, 2, (char *) &on, sizeof (on));
    if (rc < 0) {
        perror("setsockopt() failed");
        close(fd);
        exit(-1);
    }
    rc = ioctl(fd, 0x5421, (char *) &on);
    if (rc < 0) {
        perror("ioctl() failed");
        close(fd);
        exit(-1);
    }
    rc = bind(fd, (struct sockaddr *) &servaddr, sizeof (servaddr));
    if (rc < 0) {
        perror("bind() failed");
        close(fd);
        exit(-1);
    }
    listen(fd, 1);
    if (rc < 0) {
        perror("listen() failed");
        close(fd);
        exit(-1);
    }
    return fd;
}

variable_types: port int

variable_types: on int

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

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

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


decompiled_code:
__int64 __fastcall SCPI_Error(__int64 a1, __int16 a2)
{
const char *v2; // rax

v2 = (const char *)SCPI_ErrorTranslate((unsigned int)a2);
fprintf(stderr, "**ERROR: %d, \"%s\"\r\n", (unsigned int)a2, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int16 a2)
{
const char *v2; // rax

v2 = (const char *)SCPI_ErrorTranslate((unsigned int)a2);
fprintf(stderr, "**ERROR: %d, \"%s\"\r\n", (unsigned int)a2, v2);
return 0LL;
}

original_code:
int SCPI_Error(scpi_t * context, int_fast16_t err) {
    (void) context;
    fprintf(stderr, "**ERROR: %d, \"%s\"\r\n", (int16_t) err, SCPI_ErrorTranslate(err));
    return 0;
}

canonical_original_code:
int SCPI_Error(struct _scpi_t *context, long err) {
    (void) context;
    fprintf(stderr, "**ERROR: %d, \"%s\"\r\n", (short) err, SCPI_ErrorTranslate(err));
    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: err long

return_type: int

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:
__int64 __fastcall SCPI_Control(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
unsigned int v3; // er12
__int64 v4; // rbx
__int64 result; // rax
size_t v6; // rax
ssize_t v7; // r8
char v8[40]; // [rsp+0h] [rbp-28h] BYREF

v3 = a3;
if ( a2 == 1 )
fprintf(stderr, "**SRQ: 0x%X (%d)\r\n", a3, a3);
else
fprintf(stderr, "**CTRL %02x: 0x%X (%d)\r\n", a2, a3, a3);
v4 = *(_QWORD *)(a1 + 168);
if ( !v4
|| *(int *)(v4 + 8) < 0
|| (sprintf(v8, "SRQ%d\r\n", v3),
v6 = strlen(v8),
v7 = write(*(_DWORD *)(v4 + 8), v8, v6),
result = 0xFFFFFFFFLL,
v7 > 0) )
{
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
unsigned int v3; // er12
__int64 v4; // rbx
__int64 result; // rax
size_t v6; // rax
ssize_t v7; // r8
char v8[40]; // [rsp+0h] [rbp-28h] BYREF

v3 = a3;
if ( a2 == 1 )
fprintf(stderr, "**SRQ: 0x%X (%d)\r\n", a3, a3);
else
fprintf(stderr, "**CTRL %02x: 0x%X (%d)\r\n", a2, a3, a3);
v4 = *(_QWORD *)(a1 + 168);
if ( !v4
|| *(int *)(v4 + 8) < 0
|| (sprintf(v8, "SRQ%d\r\n", v3),
v6 = strlen(v8),
v7 = write(*(_DWORD *)(v4 + 8), v8, v6),
result = 0xFFFFFFFFLL,
v7 > 0) )
{
result = 1LL;
}
return result;
}

original_code:
scpi_result_t SCPI_Control(scpi_t * context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val) {
    (void) context;
    if (SCPI_CTRL_SRQ == ctrl) {
        fprintf(stderr, "**SRQ: 0x%X (%d)\r\n", val, val);
    } else {
        fprintf(stderr, "**CTRL %02x: 0x%X (%d)\r\n", ctrl, val, val);
    }
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_Control(struct _scpi_t *context, enum _scpi_ctrl_name_t ctrl, unsigned short val) {
    (void) context;
    if (SCPI_CTRL_SRQ == ctrl) {
        fprintf(stderr, "**SRQ: 0x%X (%d)\r\n", val, val);
    } else {
        fprintf(stderr, "**CTRL %02x: 0x%X (%d)\r\n", ctrl, val, val);
    }
    return SCPI_RES_OK;
}

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

variable_types:
val
unsigned short

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

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 }


decompiled_code:
__int64 SCPI_Reset()
{
fwrite("**Reset\r\n", 1uLL, 9uLL, stderr);
return 1LL;
}

canonical_decompiled_code:
__int64 func14()
{
fwrite("**Reset\r\n", 1uLL, 9uLL, stderr);
return 1LL;
}

original_code:
scpi_result_t SCPI_Reset(scpi_t * context) {
    (void) context;
    fprintf(stderr, "**Reset\r\n");
    return SCPI_RES_OK;
}

canonical_original_code:
enum _scpi_result_t SCPI_Reset(struct _scpi_t *context) {
    (void) context;
    fprintf(stderr, "**Reset\r\n");
    return SCPI_RES_OK;
}

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:
__int64 __fastcall DMM_MeasureVoltageDcQ(__int64 a1)
{
char v2[15]; // [rsp+11h] [rbp-4Fh] BYREF
char v3[32]; // [rsp+20h] [rbp-40h] BYREF
char v4[32]; // [rsp+40h] [rbp-20h] BYREF

fwrite("meas:volt:dc\r\n", 1uLL, 0xEuLL, stderr);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v4, 0LL);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v3, 0LL);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v4, v2, 15LL);
fprintf(stderr, "\tP1=%s\r\n", v2);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v3, v2, 15LL);
fprintf(stderr, "\tP2=%s\r\n", v2);
SCPI_ResultDouble(a1, 0.0);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char v2[15]; // [rsp+11h] [rbp-4Fh] BYREF
char v3[32]; // [rsp+20h] [rbp-40h] BYREF
char v4[32]; // [rsp+40h] [rbp-20h] BYREF

fwrite("meas:volt:dc\r\n", 1uLL, 0xEuLL, stderr);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v4, 0LL);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v3, 0LL);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v4, v2, 15LL);
fprintf(stderr, "\tP1=%s\r\n", v2);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v3, v2, 15LL);
fprintf(stderr, "\tP2=%s\r\n", v2);
SCPI_ResultDouble(a1, 0.0);
return 1LL;
}

original_code:
static scpi_result_t DMM_MeasureVoltageDcQ(scpi_t * context) {
    scpi_number_t param1, param2;
    char bf[15];
    fprintf(stderr, "meas:volt:dc\r\n");
    if (!SCPI_ParamNumber(context, scpi_special_numbers_def, &param1, 0)) {
    }
    if (!SCPI_ParamNumber(context, scpi_special_numbers_def, &param2, 0)) {
    }
    SCPI_NumberToStr(context, scpi_special_numbers_def, &param1, bf, 15);
    fprintf(stderr, "\tP1=%s\r\n", bf);
    SCPI_NumberToStr(context, scpi_special_numbers_def, &param2, bf, 15);
    fprintf(stderr, "\tP2=%s\r\n", bf);
    SCPI_ResultDouble(context, 0);
    return SCPI_RES_OK;
}

canonical_original_code:
static enum _scpi_result_t DMM_MeasureVoltageDcQ(struct _scpi_t *context) {
    struct _scpi_number_parameter_t param1; struct _scpi_number_parameter_t param2;
    char bf[15];
    fprintf(stderr, "meas:volt:dc\r\n");
    if (!SCPI_ParamNumber(context, scpi_special_numbers_def, &param1, 0)) {
    }
    if (!SCPI_ParamNumber(context, scpi_special_numbers_def, &param2, 0)) {
    }
    SCPI_NumberToStr(context, scpi_special_numbers_def, &param1, bf, 15);
    fprintf(stderr, "\tP1=%s\r\n", bf);
    SCPI_NumberToStr(context, scpi_special_numbers_def, &param2, bf, 15);
    fprintf(stderr, "\tP2=%s\r\n", bf);
    SCPI_ResultDouble(context, 0);
    return SCPI_RES_OK;
}

variable_types: struct _scpi_number_parameter_t { _Bool special; union { double value; int tag; } content; 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; char base; }

variable_types:
bf
char [15]

user_defined_types: struct _scpi_number_parameter_t { _Bool special; union { double value; int tag; } content; enum _scpi_unit_t unit; char base; }

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 DMM_MeasureVoltageAcQ(__int64 a1)
{
char v2[15]; // [rsp+11h] [rbp-4Fh] BYREF
char v3[32]; // [rsp+20h] [rbp-40h] BYREF
char v4[32]; // [rsp+40h] [rbp-20h] BYREF

fwrite("meas:volt:ac\r\n", 1uLL, 0xEuLL, stderr);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v4, 0LL);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v3, 0LL);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v4, v2, 15LL);
fprintf(stderr, "\tP1=%s\r\n", v2);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v3, v2, 15LL);
fprintf(stderr, "\tP2=%s\r\n", v2);
SCPI_ResultDouble(a1, 0.0);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
char v2[15]; // [rsp+11h] [rbp-4Fh] BYREF
char v3[32]; // [rsp+20h] [rbp-40h] BYREF
char v4[32]; // [rsp+40h] [rbp-20h] BYREF

fwrite("meas:volt:ac\r\n", 1uLL, 0xEuLL, stderr);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v4, 0LL);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v3, 0LL);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v4, v2, 15LL);
fprintf(stderr, "\tP1=%s\r\n", v2);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v3, v2, 15LL);
fprintf(stderr, "\tP2=%s\r\n", v2);
SCPI_ResultDouble(a1, 0.0);
return 1LL;
}

original_code:
static scpi_result_t DMM_MeasureVoltageAcQ(scpi_t * context) {
    scpi_number_t param1, param2;
    char bf[15];
    fprintf(stderr, "meas:volt:ac\r\n");
    if (!SCPI_ParamNumber(context, scpi_special_numbers_def, &param1, 0)) {
    }
    if (!SCPI_ParamNumber(context, scpi_special_numbers_def, &param2, 0)) {
    }
    SCPI_NumberToStr(context, scpi_special_numbers_def, &param1, bf, 15);
    fprintf(stderr, "\tP1=%s\r\n", bf);
    SCPI_NumberToStr(context, scpi_special_numbers_def, &param2, bf, 15);
    fprintf(stderr, "\tP2=%s\r\n", bf);
    SCPI_ResultDouble(context, 0);
    return SCPI_RES_OK;
}

canonical_original_code:
static enum _scpi_result_t DMM_MeasureVoltageAcQ(struct _scpi_t *context) {
    struct _scpi_number_parameter_t param1; struct _scpi_number_parameter_t param2;
    char bf[15];
    fprintf(stderr, "meas:volt:ac\r\n");
    if (!SCPI_ParamNumber(context, scpi_special_numbers_def, &param1, 0)) {
    }
    if (!SCPI_ParamNumber(context, scpi_special_numbers_def, &param2, 0)) {
    }
    SCPI_NumberToStr(context, scpi_special_numbers_def, &param1, bf, 15);
    fprintf(stderr, "\tP1=%s\r\n", bf);
    SCPI_NumberToStr(context, scpi_special_numbers_def, &param2, bf, 15);
    fprintf(stderr, "\tP2=%s\r\n", bf);
    SCPI_ResultDouble(context, 0);
    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; }

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


decompiled_code:
__int64 __fastcall DMM_ConfigureVoltageDc(__int64 a1)
{
double v2; // [rsp+10h] [rbp-10h] BYREF
double v3; // [rsp+18h] [rbp-8h] BYREF

fwrite("conf:volt:dc\r\n", 1uLL, 0xEuLL, stderr);
if ( (unsigned __int8)SCPI_ParamDouble(a1, &v3, 1LL) != 1 )
return 0xFFFFFFFFLL;
SCPI_ParamDouble(a1, &v2, 0LL);
fprintf(stderr, "\tP1=%lf\r\n", v3);
fprintf(stderr, "\tP2=%lf\r\n", v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
double v2; // [rsp+10h] [rbp-10h] BYREF
double v3; // [rsp+18h] [rbp-8h] BYREF

fwrite("conf:volt:dc\r\n", 1uLL, 0xEuLL, stderr);
if ( (unsigned __int8)SCPI_ParamDouble(a1, &v3, 1LL) != 1 )
return 0xFFFFFFFFLL;
SCPI_ParamDouble(a1, &v2, 0LL);
fprintf(stderr, "\tP1=%lf\r\n", v3);
fprintf(stderr, "\tP2=%lf\r\n", v2);
return 1LL;
}

original_code:
static scpi_result_t DMM_ConfigureVoltageDc(scpi_t * context) {
    double param1, param2;
    fprintf(stderr, "conf:volt:dc\r\n");
    if (!SCPI_ParamDouble(context, &param1, (!0))) {
        return SCPI_RES_ERR;
    }
    if (!SCPI_ParamDouble(context, &param2, 0)) {
    }
    fprintf(stderr, "\tP1=%lf\r\n", param1);
    fprintf(stderr, "\tP2=%lf\r\n", param2);
    return SCPI_RES_OK;
}

canonical_original_code:
static enum _scpi_result_t DMM_ConfigureVoltageDc(struct _scpi_t *context) {
    double param1; double param2;
    fprintf(stderr, "conf:volt:dc\r\n");
    if (!SCPI_ParamDouble(context, &param1, (!0))) {
        return SCPI_RES_ERR;
    }
    if (!SCPI_ParamDouble(context, &param2, 0)) {
    }
    fprintf(stderr, "\tP1=%lf\r\n", param1);
    fprintf(stderr, "\tP2=%lf\r\n", param2);
    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; }

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


decompiled_code:
__int64 __fastcall TEST_Bool(__int64 a1)
{
unsigned __int8 v2; // [rsp+1Fh] [rbp-1h] BYREF

fwrite("TEST:BOOL\r\n", 1uLL, 0xBuLL, stderr);
if ( (unsigned __int8)SCPI_ParamBool(a1, &v2, 1LL) != 1 )
return 0xFFFFFFFFLL;
fprintf(stderr, "\tP1=%d\r\n", v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned __int8 v2; // [rsp+1Fh] [rbp-1h] BYREF

fwrite("TEST:BOOL\r\n", 1uLL, 0xBuLL, stderr);
if ( (unsigned __int8)SCPI_ParamBool(a1, &v2, 1LL) != 1 )
return 0xFFFFFFFFLL;
fprintf(stderr, "\tP1=%d\r\n", v2);
return 1LL;
}

original_code:
static scpi_result_t TEST_Bool(scpi_t * context) {
    scpi_bool_t param1;
    fprintf(stderr, "TEST:BOOL\r\n");
    if (!SCPI_ParamBool(context, &param1, (!0))) {
        return SCPI_RES_ERR;
    }
    fprintf(stderr, "\tP1=%d\r\n", param1);
    return SCPI_RES_OK;
}

canonical_original_code:
static enum _scpi_result_t TEST_Bool(struct _scpi_t *context) {
    _Bool param1;
    fprintf(stderr, "TEST:BOOL\r\n");
    if (!SCPI_ParamBool(context, &param1, (!0))) {
        return SCPI_RES_ERR;
    }
    fprintf(stderr, "\tP1=%d\r\n", param1);
    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 *); }

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


decompiled_code:
__int64 __fastcall TEST_ChoiceQ(__int64 a1)
{
const char *v2; // [rsp+10h] [rbp-10h] BYREF
unsigned int v3; // [rsp+1Ch] [rbp-4h] BYREF

if ( (unsigned __int8)SCPI_ParamChoice(a1, &trigger_source, &v3, 1LL) != 1 )
return 0xFFFFFFFFLL;
SCPI_ChoiceToName(&trigger_source, v3, &v2);
fprintf(stderr, "\tP1=%s (%ld)\r\n", v2, (int)v3);
SCPI_ResultInt32(a1, v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
const char *v2; // [rsp+10h] [rbp-10h] BYREF
unsigned int v3; // [rsp+1Ch] [rbp-4h] BYREF

if ( (unsigned __int8)SCPI_ParamChoice(a1, &trigger_source, &v3, 1LL) != 1 )
return 0xFFFFFFFFLL;
SCPI_ChoiceToName(&trigger_source, v3, &v2);
fprintf(stderr, "\tP1=%s (%ld)\r\n", v2, (int)v3);
SCPI_ResultInt32(a1, v3);
return 1LL;
}

original_code:
static scpi_result_t TEST_ChoiceQ(scpi_t * context) {
    int32_t param;
    const char * name;
    if (!SCPI_ParamChoice(context, trigger_source, &param, (!0))) {
        return SCPI_RES_ERR;
    }
    SCPI_ChoiceToName(trigger_source, param, &name);
    fprintf(stderr, "\tP1=%s (%ld)\r\n", name, (long int) param);
    SCPI_ResultInt32(context, param);
    return SCPI_RES_OK;
}

canonical_original_code:
static enum _scpi_result_t TEST_ChoiceQ(struct _scpi_t *context) {
    int param;
    char *name;
    if (!SCPI_ParamChoice(context, trigger_source, &param, (!0))) {
        return SCPI_RES_ERR;
    }
    SCPI_ChoiceToName(trigger_source, param, &name);
    fprintf(stderr, "\tP1=%s (%ld)\r\n", name, (long) param);
    SCPI_ResultInt32(context, param);
    return SCPI_RES_OK;
}

variable_types: param int

variable_types:
name
char *

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

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


decompiled_code:
__int64 __fastcall TEST_Numbers(__int64 a1)
{
int v2[2]; // [rsp+18h] [rbp-8h] BYREF

SCPI_CommandNumbers(a1, v2, 2LL, 1LL);
fprintf(stderr, "TEST numbers %d %d\r\n", (unsigned int)v2[0], (unsigned int)v2[1]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v2[2]; // [rsp+18h] [rbp-8h] BYREF

SCPI_CommandNumbers(a1, v2, 2LL, 1LL);
fprintf(stderr, "TEST numbers %d %d\r\n", (unsigned int)v2[0], (unsigned int)v2[1]);
return 1LL;
}

original_code:
static scpi_result_t TEST_Numbers(scpi_t * context) {
    int32_t numbers[2];
    SCPI_CommandNumbers(context, numbers, 2, 1);
    fprintf(stderr, "TEST numbers %d %d\r\n", numbers[0], numbers[1]);
    return SCPI_RES_OK;
}

canonical_original_code:
static enum _scpi_result_t TEST_Numbers(struct _scpi_t *context) {
    int numbers[2];
    SCPI_CommandNumbers(context, numbers, 2, 1);
    fprintf(stderr, "TEST numbers %d %d\r\n", numbers[0], numbers[1]);
    return SCPI_RES_OK;
}

variable_types:
numbers
int [2]

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


decompiled_code:
__int64 __fastcall TEST_Text(__int64 a1)
{
char v2[8]; // [rsp+18h] [rbp-78h] BYREF
char v3[112]; // [rsp+20h] [rbp-70h] BYREF

if ( (unsigned __int8)SCPI_ParamCopyText(a1, v3, 100LL, v2, 0LL) != 1 )
v3[0] = 0;
fprintf(stderr, "TEXT: ***%s***\r\n", v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
char v2[8]; // [rsp+18h] [rbp-78h] BYREF
char v3[112]; // [rsp+20h] [rbp-70h] BYREF

if ( (unsigned __int8)SCPI_ParamCopyText(a1, v3, 100LL, v2, 0LL) != 1 )
v3[0] = 0;
fprintf(stderr, "TEXT: ***%s***\r\n", v3);
return 1LL;
}

original_code:
static scpi_result_t TEST_Text(scpi_t * context) {
    char buffer[100];
    size_t copy_len;
    if (!SCPI_ParamCopyText(context, buffer, sizeof (buffer), &copy_len, 0)) {
        buffer[0] = '\0';
    }
    fprintf(stderr, "TEXT: ***%s***\r\n", buffer);
    return SCPI_RES_OK;
}

canonical_original_code:
static enum _scpi_result_t TEST_Text(struct _scpi_t *context) {
    char buffer[100];
    unsigned long copy_len;
    if (!SCPI_ParamCopyText(context, buffer, sizeof (buffer), &copy_len, 0)) {
        buffer[0] = '\0';
    }
    fprintf(stderr, "TEXT: ***%s***\r\n", buffer);
    return SCPI_RES_OK;
}

variable_types:
buffer
char [100]

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


decompiled_code:
__int64 __fastcall TEST_ArbQ(__int64 a1)
{
__int64 v2; // [rsp+10h] [rbp-10h] BYREF
__int64 v3; // [rsp+18h] [rbp-8h] BYREF

if ( (unsigned __int8)SCPI_ParamArbitraryBlock(a1, &v3, &v2, 0LL) )
SCPI_ResultArbitraryBlock(a1, v3, v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v2; // [rsp+10h] [rbp-10h] BYREF
__int64 v3; // [rsp+18h] [rbp-8h] BYREF

if ( (unsigned __int8)SCPI_ParamArbitraryBlock(a1, &v3, &v2, 0LL) )
SCPI_ResultArbitraryBlock(a1, v3, v2);
return 1LL;
}

original_code:
static scpi_result_t TEST_ArbQ(scpi_t * context) {
    const char * data;
    size_t len;
    if (SCPI_ParamArbitraryBlock(context, &data, &len, 0)) {
        SCPI_ResultArbitraryBlock(context, data, len);
    }
    return SCPI_RES_OK;
}

canonical_original_code:
static enum _scpi_result_t TEST_ArbQ(struct _scpi_t *context) {
    char *data;
    unsigned long len;
    if (SCPI_ParamArbitraryBlock(context, &data, &len, 0)) {
        SCPI_ResultArbitraryBlock(context, data, len);
    }
    return SCPI_RES_OK;
}

variable_types:
data
char *

variable_types:
len
unsigned long

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 }


decompiled_code:
__int64 __fastcall TEST_Chanlst(__int64 a1)
{
__int64 v2; // [rsp+10h] [rbp-E0h] BYREF
int v3; // [rsp+1Ch] [rbp-D4h] BYREF
int v4; // [rsp+20h] [rbp-D0h]
int v5; // [rsp+24h] [rbp-CCh] BYREF
int v6; // [rsp+28h] [rbp-C8h]
char v7[97]; // [rsp+2Fh] [rbp-C1h] BYREF
char v8[36]; // [rsp+90h] [rbp-60h] BYREF
int v9; // [rsp+B4h] [rbp-3Ch]
unsigned __int64 i; // [rsp+B8h] [rbp-38h]
int v11; // [rsp+C4h] [rbp-2Ch]
int v12; // [rsp+C8h] [rbp-28h]
char v13; // [rsp+CEh] [rbp-22h]
char v14; // [rsp+CFh] [rbp-21h]
__int64 v15; // [rsp+D0h] [rbp-20h]
__int64 v16; // [rsp+D8h] [rbp-18h]
unsigned __int64 v17; // [rsp+E0h] [rbp-10h]
__int64 v18; // [rsp+E8h] [rbp-8h]

v17 = 0LL;
v15 = 1LL;
if ( (unsigned __int8)SCPI_Parameter(a1, v8, 1LL) )
{
v14 = 0;
v13 = 0;
v12 = 1;
v11 = 1;
if ( !(unsigned int)SCPI_ExprChannelListEntry(a1, v8, 0LL, v7, 0LL, 0LL, 0LL, &v2) )
{
v18 = 0LL;
v17 = 0LL;
do
{
v9 = SCPI_ExprChannelListEntry(a1, v8, (unsigned int)v18, v7, &v5, &v3, 4LL, &v2);
if ( v7[0] )
{
if ( v7[0] != 1 )
return 0xFFFFFFFFLL;
if ( v5 <= v3 )
v12 = 1;
else
v12 = -1;
v14 = 0;
v16 = v5;
while ( !v14 )
{
if ( v2 == 2 )
{
if ( v6 <= v4 )
{
if ( v6 < v4 )
v11 = 1;
}
else
{
v11 = -1;
}
v13 = 0;
v15 = v6;
while ( !v13 )
{
*(_DWORD *)&v7[8 * v17 + 1] = v16;
*(_DWORD *)&v7[8 * v17++ + 5] = v15;
if ( v17 > 0xB )
return 0xFFFFFFFFLL;
if ( v15 == v4 )
v13 = 1;
v15 += v11;
}
}
else if ( v2 == 1 )
{
*(_DWORD *)&v7[8 * v17 + 1] = v16;
*(_DWORD *)&v7[8 * v17++ + 5] = 0;
if ( v17 > 0xB )
return 0xFFFFFFFFLL;
}
if ( v16 == v3 )
v14 = 1;
v16 += v12;
}
}
else
{
if ( v2 == 1 )
{
*(_DWORD *)&v7[8 * v17 + 1] = v5;
*(_DWORD *)&v7[8 * v17 + 5] = 0;
}
else
{
if ( v2 != 2 )
return 0xFFFFFFFFLL;
*(_DWORD *)&v7[8 * v17 + 1] = v5;
*(_DWORD *)&v7[8 * v17 + 5] = v6;
}
if ( ++v17 > 0xB )
return 0xFFFFFFFFLL;
}
++v18;
}
while ( !(unsigned int)SCPI_ExprChannelListEntry(a1, v8, (unsigned int)v18, v7, &v5, &v3, 4LL, &v2) );
}
}
fwrite("TEST_Chanlst: ", 1uLL, 0xEuLL, stderr);
for ( i = 0LL; i < v17; ++i )
fprintf(stderr, "%d!%d, ", *(unsigned int *)&v7[8 * i + 1], *(unsigned int *)&v7[8 * i + 5]);
fwrite("\r\n", 1uLL, 2uLL, stderr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v2; // [rsp+10h] [rbp-E0h] BYREF
int v3; // [rsp+1Ch] [rbp-D4h] BYREF
int v4; // [rsp+20h] [rbp-D0h]
int v5; // [rsp+24h] [rbp-CCh] BYREF
int v6; // [rsp+28h] [rbp-C8h]
char v7[97]; // [rsp+2Fh] [rbp-C1h] BYREF
char v8[36]; // [rsp+90h] [rbp-60h] BYREF
int v9; // [rsp+B4h] [rbp-3Ch]
unsigned __int64 i; // [rsp+B8h] [rbp-38h]
int v11; // [rsp+C4h] [rbp-2Ch]
int v12; // [rsp+C8h] [rbp-28h]
char v13; // [rsp+CEh] [rbp-22h]
char v14; // [rsp+CFh] [rbp-21h]
__int64 v15; // [rsp+D0h] [rbp-20h]
__int64 v16; // [rsp+D8h] [rbp-18h]
unsigned __int64 v17; // [rsp+E0h] [rbp-10h]
__int64 v18; // [rsp+E8h] [rbp-8h]

v17 = 0LL;
v15 = 1LL;
if ( (unsigned __int8)SCPI_Parameter(a1, v8, 1LL) )
{
v14 = 0;
v13 = 0;
v12 = 1;
v11 = 1;
if ( !(unsigned int)SCPI_ExprChannelListEntry(a1, v8, 0LL, v7, 0LL, 0LL, 0LL, &v2) )
{
v18 = 0LL;
v17 = 0LL;
do
{
v9 = SCPI_ExprChannelListEntry(a1, v8, (unsigned int)v18, v7, &v5, &v3, 4LL, &v2);
if ( v7[0] )
{
if ( v7[0] != 1 )
return 0xFFFFFFFFLL;
if ( v5 <= v3 )
v12 = 1;
else
v12 = -1;
v14 = 0;
v16 = v5;
while ( !v14 )
{
if ( v2 == 2 )
{
if ( v6 <= v4 )
{
if ( v6 < v4 )
v11 = 1;
}
else
{
v11 = -1;
}
v13 = 0;
v15 = v6;
while ( !v13 )
{
*(_DWORD *)&v7[8 * v17 + 1] = v16;
*(_DWORD *)&v7[8 * v17++ + 5] = v15;
if ( v17 > 0xB )
return 0xFFFFFFFFLL;
if ( v15 == v4 )
v13 = 1;
v15 += v11;
}
}
else if ( v2 == 1 )
{
*(_DWORD *)&v7[8 * v17 + 1] = v16;
*(_DWORD *)&v7[8 * v17++ + 5] = 0;
if ( v17 > 0xB )
return 0xFFFFFFFFLL;
}
if ( v16 == v3 )
v14 = 1;
v16 += v12;
}
}
else
{
if ( v2 == 1 )
{
*(_DWORD *)&v7[8 * v17 + 1] = v5;
*(_DWORD *)&v7[8 * v17 + 5] = 0;
}
else
{
if ( v2 != 2 )
return 0xFFFFFFFFLL;
*(_DWORD *)&v7[8 * v17 + 1] = v5;
*(_DWORD *)&v7[8 * v17 + 5] = v6;
}
if ( ++v17 > 0xB )
return 0xFFFFFFFFLL;
}
++v18;
}
while ( !(unsigned int)SCPI_ExprChannelListEntry(a1, v8, (unsigned int)v18, v7, &v5, &v3, 4LL, &v2) );
}
}
fwrite("TEST_Chanlst: ", 1uLL, 0xEuLL, stderr);
for ( i = 0LL; i < v17; ++i )
fprintf(stderr, "%d!%d, ", *(unsigned int *)&v7[8 * i + 1], *(unsigned int *)&v7[8 * i + 5]);
fwrite("\r\n", 1uLL, 2uLL, stderr);
return 1LL;
}

original_code:
static scpi_result_t TEST_Chanlst(scpi_t *context) {
    scpi_parameter_t channel_list_param;
    scpi_channel_value_t array[2 * 6];
    size_t chanlst_idx;
    size_t arr_idx = 0;
    size_t n, m = 1;
    if (SCPI_Parameter(context, &channel_list_param, (!0))) {
        scpi_expr_result_t res;
        scpi_bool_t is_range;
        int32_t values_from[2];
        int32_t values_to[2];
        size_t dimensions;
        _Bool for_stop_row = 0;
        _Bool for_stop_col = 0;
        int32_t dir_row = 1;
        int32_t dir_col = 1;
        if (!SCPI_ExprChannelListEntry(context, &channel_list_param, 0, &is_range, ((void *)0), ((void *)0), 0, &dimensions)) {
            chanlst_idx = 0;
            arr_idx = 0;
            do {
                res = SCPI_ExprChannelListEntry(context, &channel_list_param, chanlst_idx, &is_range, values_from, values_to, 4, &dimensions);
                if (is_range == 0) {
                    if (dimensions == 1) {
                        array[arr_idx].row = values_from[0];
                        array[arr_idx].col = 0;
                    } else if (dimensions == 2) {
                        array[arr_idx].row = values_from[0];
                        array[arr_idx].col = values_from[1];
                    } else {
                        return SCPI_RES_ERR;
                    }
                    arr_idx++;
                    if (arr_idx >= 2 * 6) {
                        return SCPI_RES_ERR;
                    }
                } else if (is_range == (!0)) {
                    if (values_from[0] > values_to[0]) {
                        dir_row = -1;
                    } else {
                        dir_row = +1;
                    }
                    for_stop_row = 0;
                    for (n = values_from[0]; for_stop_row == 0; n += dir_row) {
                        if (dimensions == 2) {
                            if (values_from[1] > values_to[1]) {
                                dir_col = -1;
                            } else if (values_from[1] < values_to[1]) {
                                dir_col = +1;
                            }
                            for_stop_col = 0;
                            for (m = values_from[1]; for_stop_col == 0; m += dir_col) {
                                array[arr_idx].row = n;
                                array[arr_idx].col = m;
                                arr_idx++;
                                if (arr_idx >= 2 * 6) {
                                    return SCPI_RES_ERR;
                                }
                                if (m == (size_t)values_to[1]) {
                                    for_stop_col = (!0);
                                }
                            }
                        } else if (dimensions == 1) {
                            array[arr_idx].row = n;
                            array[arr_idx].col = 0;
                            arr_idx++;
                            if (arr_idx >= 2 * 6) {
                                return SCPI_RES_ERR;
                            }
                        }
                        if (n == (size_t)values_to[0]) {
                            for_stop_row = (!0);
                        }
                    }
                } else {
                    return SCPI_RES_ERR;
                }
                chanlst_idx++;
            } while (SCPI_EXPR_OK == SCPI_ExprChannelListEntry(context, &channel_list_param, chanlst_idx, &is_range, values_from, values_to, 4, &dimensions));
        }
    }
    {
        size_t i;
        fprintf(stderr, "TEST_Chanlst: ");
        for (i = 0; i< arr_idx; i++) {
            fprintf(stderr, "%d!%d, ", array[i].row, array[i].col);
        }
        fprintf(stderr, "\r\n");
    }
    return SCPI_RES_OK;
}

canonical_original_code:
static enum _scpi_result_t TEST_Chanlst(struct _scpi_t *context) {
    struct _scpi_token_t channel_list_param;
    struct _scpi_channel_value_t array[-1];
    unsigned long chanlst_idx;
    unsigned long arr_idx = 0;
    unsigned long n; unsigned long m = 1;
    if (SCPI_Parameter(context, &channel_list_param, (!0))) {
        enum _scpi_expr_result_t res;
        _Bool is_range;
        int values_from[2];
        int values_to[2];
        unsigned long dimensions;
        _Bool for_stop_row = 0;
        _Bool for_stop_col = 0;
        int dir_row = 1;
        int dir_col = 1;
        if (!SCPI_ExprChannelListEntry(context, &channel_list_param, 0, &is_range, ((void *)0), ((void *)0), 0, &dimensions)) {
            chanlst_idx = 0;
            arr_idx = 0;
            do {
                res = SCPI_ExprChannelListEntry(context, &channel_list_param, chanlst_idx, &is_range, values_from, values_to, 4, &dimensions);
                if (is_range == 0) {
                    if (dimensions == 1) {
                        array[arr_idx].row = values_from[0];
                        array[arr_idx].col = 0;
                    } else if (dimensions == 2) {
                        array[arr_idx].row = values_from[0];
                        array[arr_idx].col = values_from[1];
                    } else {
                        return SCPI_RES_ERR;
                    }
                    arr_idx++;
                    if (arr_idx >= 2 * 6) {
                        return SCPI_RES_ERR;
                    }
                } else if (is_range == (!0)) {
                    if (values_from[0] > values_to[0]) {
                        dir_row = -1;
                    } else {
                        dir_row = +1;
                    }
                    for_stop_row = 0;
                    for (n = values_from[0]; for_stop_row == 0; n += dir_row) {
                        if (dimensions == 2) {
                            if (values_from[1] > values_to[1]) {
                                dir_col = -1;
                            } else if (values_from[1] < values_to[1]) {
                                dir_col = +1;
                            }
                            for_stop_col = 0;
                            for (m = values_from[1]; for_stop_col == 0; m += dir_col) {
                                array[arr_idx].row = n;
                                array[arr_idx].col = m;
                                arr_idx++;
                                if (arr_idx >= 2 * 6) {
                                    return SCPI_RES_ERR;
                                }
                                if (m == (unsigned long)values_to[1]) {
                                    for_stop_col = (!0);
                                }
                            }
                        } else if (dimensions == 1) {
                            array[arr_idx].row = n;
                            array[arr_idx].col = 0;
                            arr_idx++;
                            if (arr_idx >= 2 * 6) {
                                return SCPI_RES_ERR;
                            }
                        }
                        if (n == (unsigned long)values_to[0]) {
                            for_stop_row = (!0);
                        }
                    }
                } else {
                    return SCPI_RES_ERR;
                }
                chanlst_idx++;
            } while (SCPI_EXPR_OK == SCPI_ExprChannelListEntry(context, &channel_list_param, chanlst_idx, &is_range, values_from, values_to, 4, &dimensions));
        }
    }
    {
        unsigned long i;
        fprintf(stderr, "TEST_Chanlst: ");
        for (i = 0; i< arr_idx; i++) {
            fprintf(stderr, "%d!%d, ", array[i].row, array[i].col);
        }
        fprintf(stderr, "\r\n");
    }
    return SCPI_RES_OK;
}

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

variable_types: struct _scpi_channel_value_t { int row; int col; } [-1]

variable_types:
n
unsigned long

variable_types:
m
unsigned long

variable_types: enum _scpi_expr_result_t { SCPI_EXPR_OK=0, SCPI_EXPR_ERROR=1, SCPI_EXPR_NO_MORE=2 }

variable_types:
dimensions
unsigned long

variable_types:
i
unsigned long

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:
__int64 __fastcall My_CoreTstQ(__int64 a1)
{
SCPI_ResultInt32(a1, 0LL);
return 1LL;
}

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

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

canonical_original_code:
static enum _scpi_result_t My_CoreTstQ(struct _scpi_t *context) {
    SCPI_ResultInt32(context, 0);
    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_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: enum _scpi_expr_result_t { SCPI_EXPR_OK=0, SCPI_EXPR_ERROR=1, SCPI_EXPR_NO_MORE=2 }

user_defined_types: struct _scpi_channel_value_t { int row; int col; }

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 TEST_ArbQ(__int64 a1)
{
__int64 v2; // [rsp+0h] [rbp-18h] BYREF
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned __int8)SCPI_ParamArbitraryBlock(a1, &v2, &v3, 0LL) )
SCPI_ResultArbitraryBlock(a1, v2, v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v2; // [rsp+0h] [rbp-18h] BYREF
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned __int8)SCPI_ParamArbitraryBlock(a1, &v2, &v3, 0LL) )
SCPI_ResultArbitraryBlock(a1, v2, v3);
return 1LL;
}

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 TEST_Text(__int64 a1)
{
char v2[8]; // [rsp+8h] [rbp-80h] BYREF
char v3[120]; // [rsp+10h] [rbp-78h] BYREF

if ( !(unsigned __int8)SCPI_ParamCopyText(a1, v3, 100LL, v2, 0LL) )
v3[0] = 0;
fprintf(stderr, "TEXT: ***%s***\r\n", v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
char v2[8]; // [rsp+8h] [rbp-80h] BYREF
char v3[120]; // [rsp+10h] [rbp-78h] BYREF

if ( !(unsigned __int8)SCPI_ParamCopyText(a1, v3, 100LL, v2, 0LL) )
v3[0] = 0;
fprintf(stderr, "TEXT: ***%s***\r\n", v3);
return 1LL;
}

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

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


decompiled_code:
__int64 __fastcall TEST_Numbers(__int64 a1)
{
int v2[4]; // [rsp+8h] [rbp-10h] BYREF

SCPI_CommandNumbers(a1, v2, 2LL, 1LL);
fprintf(stderr, "TEST numbers %d %d\r\n", (unsigned int)v2[0], (unsigned int)v2[1]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v2[4]; // [rsp+8h] [rbp-10h] BYREF

SCPI_CommandNumbers(a1, v2, 2LL, 1LL);
fprintf(stderr, "TEST numbers %d %d\r\n", (unsigned int)v2[0], (unsigned int)v2[1]);
return 1LL;
}

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: struct _scpi_token_t { enum _scpi_token_type_t type; char *ptr; int len; }


decompiled_code:
__int64 __fastcall TEST_ChoiceQ(__int64 a1)
{
char v1; // r8
__int64 result; // rax
unsigned int v3; // [rsp+4h] [rbp-14h] BYREF
const char *v4; // [rsp+8h] [rbp-10h] BYREF

v1 = SCPI_ParamChoice(a1, &trigger_source, &v3, 1LL);
result = 0xFFFFFFFFLL;
if ( v1 )
{
SCPI_ChoiceToName(&trigger_source, v3, &v4);
fprintf(stderr, "\tP1=%s (%ld)\r\n", v4, (int)v3);
SCPI_ResultInt32(a1, v3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
char v1; // r8
__int64 result; // rax
unsigned int v3; // [rsp+4h] [rbp-14h] BYREF
const char *v4; // [rsp+8h] [rbp-10h] BYREF

v1 = SCPI_ParamChoice(a1, &trigger_source, &v3, 1LL);
result = 0xFFFFFFFFLL;
if ( v1 )
{
SCPI_ChoiceToName(&trigger_source, v3, &v4);
fprintf(stderr, "\tP1=%s (%ld)\r\n", v4, (int)v3);
SCPI_ResultInt32(a1, v3);
result = 1LL;
}
return result;
}

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 }


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

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 }

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 TEST_Bool(__int64 a1)
{
char v1; // r8
__int64 result; // rax
char v3[9]; // [rsp+Fh] [rbp-9h] BYREF

fwrite("TEST:BOOL\r\n", 1uLL, 0xBuLL, stderr);
v1 = SCPI_ParamBool(a1, v3, 1LL);
result = 0xFFFFFFFFLL;
if ( v1 )
{
fprintf(stderr, "\tP1=%d\r\n", (unsigned __int8)v3[0]);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
char v1; // r8
__int64 result; // rax
char v3[9]; // [rsp+Fh] [rbp-9h] BYREF

fwrite("TEST:BOOL\r\n", 1uLL, 0xBuLL, stderr);
v1 = SCPI_ParamBool(a1, v3, 1LL);
result = 0xFFFFFFFFLL;
if ( v1 )
{
fprintf(stderr, "\tP1=%d\r\n", (unsigned __int8)v3[0]);
result = 1LL;
}
return result;
}

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 DMM_MeasureVoltageAcQ(__int64 a1)
{
char v2[15]; // [rsp+1h] [rbp-57h] BYREF
char v3[32]; // [rsp+10h] [rbp-48h] BYREF
char v4[40]; // [rsp+30h] [rbp-28h] BYREF

fwrite("meas:volt:ac\r\n", 1uLL, 0xEuLL, stderr);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v3, 0LL);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v4, 0LL);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v3, v2, 15LL);
fprintf(stderr, "\tP1=%s\r\n", v2);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v4, v2, 15LL);
fprintf(stderr, "\tP2=%s\r\n", v2);
SCPI_ResultDouble(a1, 0.0);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
char v2[15]; // [rsp+1h] [rbp-57h] BYREF
char v3[32]; // [rsp+10h] [rbp-48h] BYREF
char v4[40]; // [rsp+30h] [rbp-28h] BYREF

fwrite("meas:volt:ac\r\n", 1uLL, 0xEuLL, stderr);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v3, 0LL);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v4, 0LL);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v3, v2, 15LL);
fprintf(stderr, "\tP1=%s\r\n", v2);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v4, v2, 15LL);
fprintf(stderr, "\tP2=%s\r\n", v2);
SCPI_ResultDouble(a1, 0.0);
return 1LL;
}

user_defined_types: struct _scpi_number_parameter_t { _Bool special; union { double value; int tag; } content; enum _scpi_unit_t unit; char base; }

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 DMM_MeasureVoltageDcQ(__int64 a1)
{
char v2[15]; // [rsp+1h] [rbp-57h] BYREF
char v3[32]; // [rsp+10h] [rbp-48h] BYREF
char v4[40]; // [rsp+30h] [rbp-28h] BYREF

fwrite("meas:volt:dc\r\n", 1uLL, 0xEuLL, stderr);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v3, 0LL);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v4, 0LL);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v3, v2, 15LL);
fprintf(stderr, "\tP1=%s\r\n", v2);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v4, v2, 15LL);
fprintf(stderr, "\tP2=%s\r\n", v2);
SCPI_ResultDouble(a1, 0.0);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
char v2[15]; // [rsp+1h] [rbp-57h] BYREF
char v3[32]; // [rsp+10h] [rbp-48h] BYREF
char v4[40]; // [rsp+30h] [rbp-28h] BYREF

fwrite("meas:volt:dc\r\n", 1uLL, 0xEuLL, stderr);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v3, 0LL);
SCPI_ParamNumber(a1, &scpi_special_numbers_def, v4, 0LL);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v3, v2, 15LL);
fprintf(stderr, "\tP1=%s\r\n", v2);
SCPI_NumberToStr(a1, &scpi_special_numbers_def, v4, v2, 15LL);
fprintf(stderr, "\tP2=%s\r\n", v2);
SCPI_ResultDouble(a1, 0.0);
return 1LL;
}

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


decompiled_code:
__int64 __fastcall DMM_ConfigureVoltageDc(__int64 a1)
{
char v1; // r8
__int64 result; // rax
double v3; // [rsp+0h] [rbp-18h] BYREF
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

fwrite("conf:volt:dc\r\n", 1uLL, 0xEuLL, stderr);
v1 = SCPI_ParamDouble(a1, &v3, 1LL);
result = 0xFFFFFFFFLL;
if ( v1 )
{
SCPI_ParamDouble(a1, v4, 0LL);
fprintf(stderr, "\tP1=%lf\r\n", v3);
fprintf(stderr, "\tP2=%lf\r\n", v4[0]);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
char v1; // r8
__int64 result; // rax
double v3; // [rsp+0h] [rbp-18h] BYREF
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

fwrite("conf:volt:dc\r\n", 1uLL, 0xEuLL, stderr);
v1 = SCPI_ParamDouble(a1, &v3, 1LL);
result = 0xFFFFFFFFLL;
if ( v1 )
{
SCPI_ParamDouble(a1, v4, 0LL);
fprintf(stderr, "\tP1=%lf\r\n", v3);
fprintf(stderr, "\tP2=%lf\r\n", v4[0]);
result = 1LL;
}
return result;
}

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

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


decompiled_code:
__int64 __fastcall SCPI_Error(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v2 = std::operator<<<std::char_traits<char>>(&std::cerr, "**ERROR: ");
v3 = std::ostream::operator<<(v2, a2);
v4 = std::operator<<<std::char_traits<char>>(v3, ", \"");
v5 = SCPI_ErrorTranslate((unsigned int)(__int16)a2);
v6 = std::operator<<<std::char_traits<char>>(v4, v5);
v7 = std::operator<<<std::char_traits<char>>(v6, "\"");
std::ostream::operator<<(v7, &std::endl<char,std::char_traits<char>>);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v2 = std::operator<<<std::char_traits<char>>(&std::cerr, "**ERROR: ");
v3 = std::ostream::operator<<(v2, a2);
v4 = std::operator<<<std::char_traits<char>>(v3, ", \"");
v5 = SCPI_ErrorTranslate((unsigned int)(__int16)a2);
v6 = std::operator<<<std::char_traits<char>>(v4, v5);
v7 = std::operator<<<std::char_traits<char>>(v6, "\"");
std::ostream::operator<<(v7, &std::endl<char,std::char_traits<char>>);
return 0LL;
}

variable_types: err long

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


decompiled_code:
__int64 __fastcall SCPI_Control(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax

if ( a2 == 1 )
{
v3 = std::operator<<<std::char_traits<char>>(&std::cerr, "**SRQ: 0x");
}
else
{
v10 = std::operator<<<std::char_traits<char>>(&std::cerr, "**CTRL: ");
v11 = std::ostream::operator<<(v10, std::hex);
v12 = std::ostream::operator<<(v11, a2);
v3 = std::operator<<<std::char_traits<char>>(v12, ": 0x");
}
v4 = std::ostream::operator<<(v3, std::hex);
v5 = std::ostream::operator<<(v4, a3);
v6 = std::operator<<<std::char_traits<char>>(v5, "(");
v7 = std::ostream::operator<<(v6, std::dec);
v8 = std::ostream::operator<<(v7, a3);
v9 = std::operator<<<std::char_traits<char>>(v8, ")");
std::ostream::operator<<(v9, &std::endl<char,std::char_traits<char>>);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax

if ( a2 == 1 )
{
v3 = std::operator<<<std::char_traits<char>>(&std::cerr, "**SRQ: 0x");
}
else
{
v10 = std::operator<<<std::char_traits<char>>(&std::cerr, "**CTRL: ");
v11 = std::ostream::operator<<(v10, std::hex);
v12 = std::ostream::operator<<(v11, a2);
v3 = std::operator<<<std::char_traits<char>>(v12, ": 0x");
}
v4 = std::ostream::operator<<(v3, std::hex);
v5 = std::ostream::operator<<(v4, a3);
v6 = std::operator<<<std::char_traits<char>>(v5, "(");
v7 = std::ostream::operator<<(v6, std::dec);
v8 = std::ostream::operator<<(v7, a3);
v9 = std::operator<<<std::char_traits<char>>(v8, ")");
std::ostream::operator<<(v9, &std::endl<char,std::char_traits<char>>);
return 1LL;
}

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

variable_types:
val
unsigned short

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


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

v0 = std::operator<<<std::char_traits<char>>(&std::cerr, "**Reset");
std::ostream::operator<<(v0, &std::endl<char,std::char_traits<char>>);
return 1LL;
}

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

v0 = std::operator<<<std::char_traits<char>>(&std::cerr, "**Reset");
std::ostream::operator<<(v0, &std::endl<char,std::char_traits<char>>);
return 1LL;
}

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

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


decompiled_code:
size_t mod_exp()
{
__gmpz_init();
fwrite(&unk_402004, 1uLL, 3uLL, _bss_start);
__gmpz_out_str();
fwrite(&unk_402008, 1uLL, 2uLL, _bss_start);
fwrite("b: ", 1uLL, 3uLL, _bss_start);
__gmpz_out_str();
fwrite(&unk_402008, 1uLL, 2uLL, _bss_start);
fwrite("c: ", 1uLL, 3uLL, _bss_start);
__gmpz_out_str();
fwrite(&unk_402008, 1uLL, 2uLL, _bss_start);
__gmpz_powm();
fwrite("(a^b)modc: ", 1uLL, 0xBuLL, _bss_start);
__gmpz_out_str();
return fwrite(&unk_402008, 1uLL, 2uLL, _bss_start);
}

canonical_decompiled_code:
size_t func7()
{
__gmpz_init();
fwrite(&unk_402004, 1uLL, 3uLL, _bss_start);
__gmpz_out_str();
fwrite(&unk_402008, 1uLL, 2uLL, _bss_start);
fwrite("b: ", 1uLL, 3uLL, _bss_start);
__gmpz_out_str();
fwrite(&unk_402008, 1uLL, 2uLL, _bss_start);
fwrite("c: ", 1uLL, 3uLL, _bss_start);
__gmpz_out_str();
fwrite(&unk_402008, 1uLL, 2uLL, _bss_start);
__gmpz_powm();
fwrite("(a^b)modc: ", 1uLL, 0xBuLL, _bss_start);
__gmpz_out_str();
return fwrite(&unk_402008, 1uLL, 2uLL, _bss_start);
}

original_code:
void mod_exp(mpz_t a, mpz_t b, mpz_t c) {
   mpz_t res;
   __gmpz_init(res);
   fprintf(stdout, "a: ");
   __gmpz_out_str(stdout, 10, a);
   fprintf(stdout, "\n\n");
   fprintf(stdout, "b: ");
   __gmpz_out_str(stdout, 10, b);
   fprintf(stdout, "\n\n");
   fprintf(stdout, "c: ");
   __gmpz_out_str(stdout, 10, c);
   fprintf(stdout, "\n\n");
   __gmpz_powm(res, a, b, c);
   fprintf(stdout, "(a^b)modc: ");
   __gmpz_out_str(stdout, 10, res);
   fprintf(stdout, "\n\n");
}

canonical_original_code:
void mod_exp(struct __mpz_struct a[1], struct __mpz_struct b[1], struct __mpz_struct c[1]) {
   struct __mpz_struct res[1];
   __gmpz_init(res);
   fprintf(stdout, "a: ");
   __gmpz_out_str(stdout, 10, a);
   fprintf(stdout, "\n\n");
   fprintf(stdout, "b: ");
   __gmpz_out_str(stdout, 10, b);
   fprintf(stdout, "\n\n");
   fprintf(stdout, "c: ");
   __gmpz_out_str(stdout, 10, c);
   fprintf(stdout, "\n\n");
   __gmpz_powm(res, a, b, c);
   fprintf(stdout, "(a^b)modc: ");
   __gmpz_out_str(stdout, 10, res);
   fprintf(stdout, "\n\n");
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
b
struct __mpz_struct [1]

variable_types:
c
struct __mpz_struct [1]

return_type: void


decompiled_code:
int read_write_large_ints()
{
__gmpz_init();
read_large_int("largeint.txt");
__gmp_randinit_mt();
__gmp_randseed();
fwrite("read from file: ", 1uLL, 0x10uLL, _bss_start);
__gmpz_out_str();
fwrite(&unk_402008, 1uLL, 2uLL, _bss_start);
__gmpz_urandomb();
fwrite("writing to file: ", 1uLL, 0x11uLL, _bss_start);
__gmpz_out_str();
fwrite(&unk_402008, 1uLL, 2uLL, _bss_start);
return write_large_int("largeint.txt");
}

canonical_decompiled_code:
int func12()
{
__gmpz_init();
func10("largeint.txt");
__gmp_randinit_mt();
__gmp_randseed();
fwrite("read from file: ", 1uLL, 0x10uLL, _bss_start);
__gmpz_out_str();
fwrite(&unk_402008, 1uLL, 2uLL, _bss_start);
__gmpz_urandomb();
fwrite("writing to file: ", 1uLL, 0x11uLL, _bss_start);
__gmpz_out_str();
fwrite(&unk_402008, 1uLL, 2uLL, _bss_start);
return func11("largeint.txt");
}

original_code:
void read_write_large_ints() {
   mpz_t i;
   __gmpz_init(i);
   read_large_int("largeint.txt", i);
   gmp_randstate_t randstate;
   __gmp_randinit_mt(randstate);
   __gmp_randseed(randstate, i);
   fprintf(stdout, "read from file: ");
   __gmpz_out_str(stdout, 10, i);
   fprintf(stdout, "\n\n");
   __gmpz_urandomb(i, randstate, 512);
   fprintf(stdout, "writing to file: ");
   __gmpz_out_str(stdout, 10, i);
   fprintf(stdout, "\n\n");
   write_large_int("largeint.txt", i);
}

canonical_original_code:
void read_write_large_ints() {
   struct __mpz_struct i[1];
   __gmpz_init(i);
   read_large_int("largeint.txt", i);
   struct __gmp_randstate_struct randstate[1];
   __gmp_randinit_mt(randstate);
   __gmp_randseed(randstate, i);
   fprintf(stdout, "read from file: ");
   __gmpz_out_str(stdout, 10, i);
   fprintf(stdout, "\n\n");
   __gmpz_urandomb(i, randstate, 512);
   fprintf(stdout, "writing to file: ");
   __gmpz_out_str(stdout, 10, i);
   fprintf(stdout, "\n\n");
   write_large_int("largeint.txt", i);
}

variable_types: struct __gmp_randstate_struct { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } [1]

user_defined_types: struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t _mp_alg; union { void *_mp_lc; } _mp_algdata; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[16]; // [rsp+0h] [rbp-58h] BYREF
char v5[16]; // [rsp+10h] [rbp-48h] BYREF
char v6[16]; // [rsp+20h] [rbp-38h] BYREF
char v7[40]; // [rsp+30h] [rbp-28h] BYREF

__gmpz_init();
__gmpz_init();
__gmpz_init();
__gmp_randinit_mt();
time(0LL);
__gmp_randseed_ui();
__gmpz_urandomb();
__gmpz_urandomb();
__gmpz_urandomb();
basic_gmp(v6, v7);
fputc(10, _bss_start);
read_write_large_ints();
add_subtract_multiply(v4, v5);
mod_exp(v4, v5, v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[16]; // [rsp+0h] [rbp-58h] BYREF
char v5[16]; // [rsp+10h] [rbp-48h] BYREF
char v6[16]; // [rsp+20h] [rbp-38h] BYREF
char v7[40]; // [rsp+30h] [rbp-28h] BYREF

__gmpz_init();
__gmpz_init();
__gmpz_init();
__gmp_randinit_mt();
time(0LL);
__gmp_randseed_ui();
__gmpz_urandomb();
__gmpz_urandomb();
__gmpz_urandomb();
func9(v6, v7);
fputc(10, _bss_start);
func12();
func8(v4, v5);
func7(v4, v5, v6);
return 0;
}

original_code:
int main() {
   mpz_t a;
   mpz_t b;
   mpz_t c;
   __gmpz_init(a);
   __gmpz_init(b);
   __gmpz_init(c);
   mp_bitcnt_t num_bits = 512;
   gmp_randstate_t randstate;
   __gmp_randinit_mt(randstate);
   __gmp_randseed_ui(randstate, time(0));
   __gmpz_urandomb(a, randstate, num_bits);
   __gmpz_urandomb(b, randstate, num_bits);
   __gmpz_urandomb(c, randstate, num_bits);
   basic_gmp();
   fprintf(stdout, "\n");
   read_write_large_ints();
   add_subtract_multiply(a, b);
   mod_exp(a, b, c);
   return 0;
}

canonical_original_code:
int main() {
   struct __mpz_struct a[1];
   struct __mpz_struct b[1];
   struct __mpz_struct c[1];
   __gmpz_init(a);
   __gmpz_init(b);
   __gmpz_init(c);
   unsigned long num_bits = 512;
   struct __gmp_randstate_struct randstate[1];
   __gmp_randinit_mt(randstate);
   __gmp_randseed_ui(randstate, time(0));
   __gmpz_urandomb(a, randstate, num_bits);
   __gmpz_urandomb(b, randstate, num_bits);
   __gmpz_urandomb(c, randstate, num_bits);
   basic_gmp();
   fprintf(stdout, "\n");
   read_write_large_ints();
   add_subtract_multiply(a, b);
   mod_exp(a, b, c);
   return 0;
}

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }

user_defined_types: enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr }


gcd

original_code:
int gcd(int a, int b) {
   int a_even = (a%2 == 0);
   int b_even = (b%2 == 0);
   if (a == 0 || b == 0)
      return 0;
   if (a_even && b_even) {
      return 2*gcd(a/2, b/2);
   }
   else if (a_even && !b_even) {
      return gcd(a/2, b);
   }
   else if (!a_even && b_even) {
      return gcd(a, b/2);
   }
   else {
      if (a == b)
         return a;
      else if (a < b)
         return gcd((b-a)/2, a);
      else
         return gcd((a-b)/2, b);
   }
}

variable_types: a int

variable_types: b int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // ebp
unsigned int v5; // ebx
unsigned int v6; // eax

v3 = time(0LL);
srand(v3);
v4 = rand();
v5 = rand();
puts("my gcd function");
v6 = gcd(v4, v5);
printf("gcd of %d and %d is: %d\n\n", v4, v5, v6);
__gmpz_init();
__gmpz_init();
__gmpz_init();
__gmpz_set_ui();
__gmpz_set_ui();
__gmpz_gcd();
puts("gmp gcd function");
printf("gcd of ");
__gmpz_out_str();
printf(" and ");
__gmpz_out_str();
printf(" is: ");
__gmpz_out_str();
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // ebp
unsigned int v5; // ebx
unsigned int v6; // eax

v3 = time(0LL);
srand(v3);
v4 = rand();
v5 = rand();
puts("my gcd function");
v6 = func7(v4, v5);
printf("gcd of %d and %d is: %d\n\n", v4, v5, v6);
__gmpz_init();
__gmpz_init();
__gmpz_init();
__gmpz_set_ui();
__gmpz_set_ui();
__gmpz_gcd();
puts("gmp gcd function");
printf("gcd of ");
__gmpz_out_str();
printf(" and ");
__gmpz_out_str();
printf(" is: ");
__gmpz_out_str();
putchar(10);
return 0;
}

original_code:
int main() {
   srand(time(0));
   int a = rand();
   int b = rand();
   printf("my gcd function\n");
   printf("gcd of %d and %d is: %d\n\n", a, b, gcd(a, b));
   mpz_t mpz_a;
   mpz_t mpz_b;
   mpz_t mpz_result;
   __gmpz_init(mpz_a);
   __gmpz_init(mpz_b);
   __gmpz_init(mpz_result);
   __gmpz_set_ui(mpz_a, a);
   __gmpz_set_ui(mpz_b, b);
   __gmpz_gcd(mpz_result, mpz_a, mpz_b);
   printf("gmp gcd function\n");
   printf("gcd of ");
   __gmpz_out_str(stdout, 10, mpz_a);
   printf(" and ");
   __gmpz_out_str(stdout, 10, mpz_b);
   printf(" is: ");
   __gmpz_out_str(stdout, 10, mpz_result);
   printf("\n");
   return 0;
}

canonical_original_code:
int main() {
   srand(time(0));
   int a = rand();
   int b = rand();
   printf("my gcd function\n");
   printf("gcd of %d and %d is: %d\n\n", a, b, gcd(a, b));
   struct __mpz_struct mpz_a[1];
   struct __mpz_struct mpz_b[1];
   struct __mpz_struct mpz_result[1];
   __gmpz_init(mpz_a);
   __gmpz_init(mpz_b);
   __gmpz_init(mpz_result);
   __gmpz_set_ui(mpz_a, a);
   __gmpz_set_ui(mpz_b, b);
   __gmpz_gcd(mpz_result, mpz_a, mpz_b);
   printf("gmp gcd function\n");
   printf("gcd of ");
   __gmpz_out_str(stdout, 10, mpz_a);
   printf(" and ");
   __gmpz_out_str(stdout, 10, mpz_b);
   printf(" is: ");
   __gmpz_out_str(stdout, 10, mpz_result);
   printf("\n");
   return 0;
}


loop

repo: jabberx/snaps

decompiled_code:
__int64 loop()
{
__int64 result; // rax
int v1; // eax
int v2; // edx
float v3; // xmm0_4
float v4; // xmm0_4
char v5[264]; // [rsp-108h] [rbp-108h] BYREF

result = exit_flag;
while ( !exit_flag )
{
if ( last_ticks_3 == -1 )
last_ticks_3 = SDL_GetTicks();
SDL_HandleEvents();
mouse_look();
if ( KEY[66] )
{
v3 = (double)delta_2 * 0.05;
fly_forward(v3);
if ( KEY[62] )
{
LABEL_17:
v4 = (double)delta_2 * -0.05;
fly_forward(v4);
goto LABEL_4;
}
}
else if ( KEY[62] )
{
goto LABEL_17;
}
LABEL_4:
if ( KEY[5] )
exit_flag = 1;
clear_zbuffer();
clear_img(3466633376LL);
if ( KEY[113] )
fill_holes();
SDL_FlipScreen();
v1 = SDL_GetTicks();
v2 = v1 - last_ticks_3;
last_ticks_3 = v1;
delta_2 = v2;
if ( v2 <= 15 )
{
SDL_Delay((unsigned int)(16 - v2));
delta_2 = 16;
}
result = (unsigned int)(fps_upd_cnt_0 + 1);
fps_upd_cnt_0 = result;
if ( (int)result > 10 )
{
fps_upd_cnt_0 = 0;
sprintf(v5, "fps: %d yaw: %.0f pit: %.0f", (unsigned int)(1000 / delta_2), yaw, pitch);
result = SDL_WM_SetCaption(v5, 0LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int v1; // eax
int v2; // edx
float v3; // xmm0_4
float v4; // xmm0_4
char v5[264]; // [rsp-108h] [rbp-108h] BYREF

result = exit_flag;
while ( !exit_flag )
{
if ( last_ticks_3 == -1 )
last_ticks_3 = SDL_GetTicks();
SDL_HandleEvents();
mouse_look();
if ( KEY[66] )
{
v3 = (double)delta_2 * 0.05;
fly_forward(v3);
if ( KEY[62] )
{
LABEL_17:
v4 = (double)delta_2 * -0.05;
fly_forward(v4);
goto LABEL_4;
}
}
else if ( KEY[62] )
{
goto LABEL_17;
}
LABEL_4:
if ( KEY[5] )
exit_flag = 1;
clear_zbuffer();
clear_img(3466633376LL);
if ( KEY[113] )
fill_holes();
SDL_FlipScreen();
v1 = SDL_GetTicks();
v2 = v1 - last_ticks_3;
last_ticks_3 = v1;
delta_2 = v2;
if ( v2 <= 15 )
{
SDL_Delay((unsigned int)(16 - v2));
delta_2 = 16;
}
result = (unsigned int)(fps_upd_cnt_0 + 1);
fps_upd_cnt_0 = result;
if ( (int)result > 10 )
{
fps_upd_cnt_0 = 0;
sprintf(v5, "fps: %d yaw: %.0f pit: %.0f", (unsigned int)(1000 / delta_2), yaw, pitch);
result = SDL_WM_SetCaption(v5, 0LL);
}
}
return result;
}

original_code:
void loop() { while(!exit_flag)
{
 static int32_t delta=16, last_ticks=-1, ticks;
 static int32_t fps_upd_cnt = 0;
 static int32_t taken = 0;
 if (last_ticks == -1) last_ticks = SDL_GetTicks();
 SDL_HandleEvents();
 mouse_look();
 if (KEY[key_w]) fly_forward(delta*0.05);
 if (KEY[key_s]) fly_forward(delta*-0.05);
 if (KEY[ESCAPE]) exit_flag=1;
 clear_zbuffer();
 clear_img(0xCEA0A0A0);
 if (KEY[CAPSLOCK]) fill_holes();
 SDL_FlipScreen();
 ticks = SDL_GetTicks();
 delta = ticks - last_ticks;
 last_ticks = ticks;
 if (delta<16){ SDL_Delay(16-delta); delta = 16; }
 fps_upd_cnt++;
 if (fps_upd_cnt>10) {
  fps_upd_cnt = 0;
  char buffer[256];
  sprintf(buffer,"fps: %d yaw: %.0f pit: %.0f", 1000/delta, yaw, pitch);
  SDL_WM_SetCaption(buffer, ((void *)0));
 }
}}

canonical_original_code:
void loop() { while(!exit_flag)
{
 static int delta = 16; static int last_ticks = -1; static int ticks;
 static int fps_upd_cnt = 0;
 static int taken = 0;
 if (last_ticks == -1) last_ticks = SDL_GetTicks();
 SDL_HandleEvents();
 mouse_look();
 if (KEY[key_w]) fly_forward(delta*0.05);
 if (KEY[key_s]) fly_forward(delta*-0.05);
 if (KEY[ESCAPE]) exit_flag=1;
 clear_zbuffer();
 clear_img(0xCEA0A0A0);
 if (KEY[CAPSLOCK]) fill_holes();
 SDL_FlipScreen();
 ticks = SDL_GetTicks();
 delta = ticks - last_ticks;
 last_ticks = ticks;
 if (delta<16){ SDL_Delay(16-delta); delta = 16; }
 fps_upd_cnt++;
 if (fps_upd_cnt>10) {
  fps_upd_cnt = 0;
  char buffer[256];
  sprintf(buffer,"fps: %d yaw: %.0f pit: %.0f", 1000/delta, yaw, pitch);
  SDL_WM_SetCaption(buffer, ((void *)0));
 }
}}

variable_types: delta int

variable_types: ticks int

variable_types: taken int

variable_types:
buffer
char [256]


main

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

SDL_Initialize(argc, argv, envp);
SDL_WM_SetCaption("test", 0LL);
v3 = WIDTH;
v4 = HEIGHT;
v5 = HEIGHT * WIDTH;
zbuffer = malloc(4 * v5);
Xbuf = malloc(4 * v5);
Ybuf = malloc(4 * v5);
Zbuf = malloc(4 * v5);
NXbuf = malloc(v5);
NYbuf = malloc(v5);
NZbuf = malloc(v5);
SHbuf = malloc(v5);
SDL_ShowCursor(0LL);
SDL_WarpMouse((unsigned __int16)(v3 / 2), (unsigned __int16)(v4 / 2));
loop();
return 0;
}

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

SDL_Initialize(argc, argv, envp);
SDL_WM_SetCaption("test", 0LL);
v3 = WIDTH;
v4 = HEIGHT;
v5 = HEIGHT * WIDTH;
zbuffer = malloc(4 * v5);
Xbuf = malloc(4 * v5);
Ybuf = malloc(4 * v5);
Zbuf = malloc(4 * v5);
NXbuf = malloc(v5);
NYbuf = malloc(v5);
NZbuf = malloc(v5);
SHbuf = malloc(v5);
SDL_ShowCursor(0LL);
SDL_WarpMouse((unsigned __int16)(v3 / 2), (unsigned __int16)(v4 / 2));
func0();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 SDL_Initialize();
 SDL_WM_SetCaption("test", ((void *)0));
 zbuffer = (float*) malloc(WIDTH*HEIGHT*sizeof(float));
 Xbuf = (int32_t*) malloc(WIDTH*HEIGHT*4);
 Ybuf = (int32_t*) malloc(WIDTH*HEIGHT*4);
 Zbuf = (int32_t*) malloc(WIDTH*HEIGHT*4);
 NXbuf = (int8_t*) malloc(WIDTH*HEIGHT);
 NYbuf = (int8_t*) malloc(WIDTH*HEIGHT);
 NZbuf = (int8_t*) malloc(WIDTH*HEIGHT);
 SHbuf = (uint8_t*) malloc(WIDTH*HEIGHT);
 SDL_ShowCursor(0);
 SDL_WarpMouse(WIDTH/2, HEIGHT/2);
 loop();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 SDL_Initialize();
 SDL_WM_SetCaption("test", ((void *)0));
 zbuffer = (float *) malloc(WIDTH*HEIGHT*sizeof(float));
 Xbuf = (int *) malloc(WIDTH*HEIGHT*4);
 Ybuf = (int *) malloc(WIDTH*HEIGHT*4);
 Zbuf = (int *) malloc(WIDTH*HEIGHT*4);
 NXbuf = (char *) malloc(WIDTH*HEIGHT);
 NYbuf = (char *) malloc(WIDTH*HEIGHT);
 NZbuf = (char *) malloc(WIDTH*HEIGHT);
 SHbuf = (unsigned char *) malloc(WIDTH*HEIGHT);
 SDL_ShowCursor(0);
 SDL_WarpMouse(WIDTH/2, HEIGHT/2);
 loop();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
float __fastcall p_d(float a1)
{
return (float)((float)((float)((float)((float)(6.0 * a1) - 15.0) * a1) + 10.0) * a1) * (float)(a1 * a1);
}

canonical_decompiled_code:
float __fastcall func0(float a1)
{
return (float)((float)((float)((float)((float)(6.0 * a1) - 15.0) * a1) + 10.0) * a1) * (float)(a1 * a1);
}

original_code: float p_d(float t){return t*t*t*(t*(t*6-15)+10);}

variable_types: t float

return_type: float


decompiled_code:
float __fastcall p_l(float a1, float a2, float a3)
{
return (float)((float)(a3 - a2) * a1) + a2;
}

canonical_decompiled_code:
float __fastcall func1(float a1, float a2, float a3)
{
return (float)((float)(a3 - a2) * a1) + a2;
}

original_code:
float p_l(float t,
float a,float b){return a+t*(b-a);}

canonical_original_code: float p_l(float t, float a, float b){return a+t*(b-a);}

variable_types: a float

variable_types: b float


decompiled_code:
__int64 noise_init()
{
__int64 v0; // rbx
int v1; // eax
__int64 v2; // rcx
__int64 result; // rax

v0 = 0LL;
p_p = (__int64)malloc(0x800uLL);
do
{
v1 = randm();
v2 = p_p;
result = (unsigned int)(v1 % 256);
*(_DWORD *)(p_p + v0) = result;
*(_DWORD *)(v2 + v0 + 1024) = result;
v0 += 4LL;
}
while ( v0 != 1024 );
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbx
int v1; // eax
__int64 v2; // rcx
__int64 result; // rax

v0 = 0LL;
p_p = (__int64)malloc(0x800uLL);
do
{
v1 = randm();
v2 = p_p;
result = (unsigned int)(v1 % 256);
*(_DWORD *)(p_p + v0) = result;
*(_DWORD *)(v2 + v0 + 1024) = result;
v0 += 4LL;
}
while ( v0 != 1024 );
return result;
}

original_code:
void noise_init(){int i;p_p=(int*)malloc(512*sizeof(int));for (i=0;i<256;i++)
p_p[256+i]=p_p[i]=randm()%256;}

canonical_original_code:
void noise_init(){int i;p_p=(int *)malloc(512*sizeof(int));for (i=0;i<256;i++)
p_p[256+i]=p_p[i]=randm()%256;}

variable_types: i int


decompiled_code:
unsigned int *__fastcall render_scene(_QWORD *a1, unsigned int *a2, float a3, float a4)
{
unsigned int v4; // er14
__int64 v5; // rbx
__int64 v6; // r15
_WORD *v7; // r13
__int16 v8; // ax
float v9; // xmm0_4
_WORD *v10; // r13
__int16 v11; // ax
float v12; // xmm0_4
_WORD *v13; // r13
_WORD *v14; // r12
unsigned int *result; // rax
__int64 v16; // [rsp+8h] [rbp-50h]

v4 = *a2;
clear_zbuffer();
clear_img(3466633376LL);
yaw = LODWORD(a3);
pitch = LODWORD(a4);
compute_yp();
render_cloud(&cloud, 0LL, 0LL, 0LL, 1LL);
if ( HEIGHT * WIDTH )
{
v5 = 0LL;
v16 = (unsigned int)(HEIGHT * WIDTH);
do
{
if ( *(_DWORD *)(img + 4 * v5) != -828333920 )
{
v6 = v4++;
v7 = (_WORD *)(2 * v6 + a1[2]);
v8 = shrink(*(unsigned int *)(Xbuf + 4 * v5), shrink_val);
v9 = shrink_val;
*v7 = v8;
v10 = (_WORD *)(2 * v6 + a1[3]);
v11 = shrink(*(unsigned int *)(Ybuf + 4 * v5), v9);
v12 = shrink_val;
*v10 = v11;
v13 = (_WORD *)(2 * v6 + a1[4]);
*v13 = shrink(*(unsigned int *)(Zbuf + 4 * v5), v12);
*(_BYTE *)(a1[6] + v6) = *(_BYTE *)(NXbuf + v5);
*(_BYTE *)(a1[7] + v6) = *(_BYTE *)(NYbuf + v5);
*(_BYTE *)(a1[8] + v6) = *(_BYTE *)(NZbuf + v5);
*(_BYTE *)(a1[9] + v6) = *(_BYTE *)(SHbuf + v5);
v14 = (_WORD *)(a1[5] + 2 * v6);
*v14 = true2high(*(unsigned int *)(img + 4 * v5));
}
++v5;
}
while ( v5 != v16 );
}
result = a2;
*a2 = v4;
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func0(_QWORD *a1, unsigned int *a2, float a3, float a4)
{
unsigned int v4; // er14
__int64 v5; // rbx
__int64 v6; // r15
_WORD *v7; // r13
__int16 v8; // ax
float v9; // xmm0_4
_WORD *v10; // r13
__int16 v11; // ax
float v12; // xmm0_4
_WORD *v13; // r13
_WORD *v14; // r12
unsigned int *result; // rax
__int64 v16; // [rsp+8h] [rbp-50h]

v4 = *a2;
clear_zbuffer();
clear_img(3466633376LL);
yaw = LODWORD(a3);
pitch = LODWORD(a4);
compute_yp();
render_cloud(&cloud, 0LL, 0LL, 0LL, 1LL);
if ( HEIGHT * WIDTH )
{
v5 = 0LL;
v16 = (unsigned int)(HEIGHT * WIDTH);
do
{
if ( *(_DWORD *)(img + 4 * v5) != -828333920 )
{
v6 = v4++;
v7 = (_WORD *)(2 * v6 + a1[2]);
v8 = shrink(*(unsigned int *)(Xbuf + 4 * v5), shrink_val);
v9 = shrink_val;
*v7 = v8;
v10 = (_WORD *)(2 * v6 + a1[3]);
v11 = shrink(*(unsigned int *)(Ybuf + 4 * v5), v9);
v12 = shrink_val;
*v10 = v11;
v13 = (_WORD *)(2 * v6 + a1[4]);
*v13 = shrink(*(unsigned int *)(Zbuf + 4 * v5), v12);
*(_BYTE *)(a1[6] + v6) = *(_BYTE *)(NXbuf + v5);
*(_BYTE *)(a1[7] + v6) = *(_BYTE *)(NYbuf + v5);
*(_BYTE *)(a1[8] + v6) = *(_BYTE *)(NZbuf + v5);
*(_BYTE *)(a1[9] + v6) = *(_BYTE *)(SHbuf + v5);
v14 = (_WORD *)(a1[5] + 2 * v6);
*v14 = true2high(*(unsigned int *)(img + 4 * v5));
}
++v5;
}
while ( v5 != v16 );
}
result = a2;
*a2 = v4;
return result;
}

original_code:
void render_scene(float y, float p, Snapshot *snap, uint32_t *counter)
{
 uint32_t i;
 uint32_t cnt = *counter;
 clear_zbuffer();
 clear_img(0xCEA0A0A0);
 yaw = y;
 pitch = p;
 compute_yp();
 render_cloud(&cloud,0,0,0,1);
 for (i=0; i<WIDTH*HEIGHT; i++) {
  if (img[i] != 0xCEA0A0A0) {
  snap->x[cnt] = shrink(Xbuf[i], shrink_val);
  snap->y[cnt] = shrink(Ybuf[i], shrink_val);
  snap->z[cnt] = shrink(Zbuf[i], shrink_val);
  snap->nx[cnt] = NXbuf[i];
  snap->ny[cnt] = NYbuf[i];
  snap->nz[cnt] = NZbuf[i];
  snap->sh[cnt] = SHbuf[i];
  snap->c[cnt] = true2high(img[i]);
  cnt++; }
 }
 *counter = cnt;
}

canonical_original_code:
void render_scene(float y, float p, struct Snapshot *snap, unsigned int *counter)
{
 unsigned int i;
 unsigned int cnt = *counter;
 clear_zbuffer();
 clear_img(0xCEA0A0A0);
 yaw = y;
 pitch = p;
 compute_yp();
 render_cloud(&cloud,0,0,0,1);
 for (i=0; i<WIDTH*HEIGHT; i++) {
  if (img[i] != 0xCEA0A0A0) {
  snap->x[cnt] = shrink(Xbuf[i], shrink_val);
  snap->y[cnt] = shrink(Ybuf[i], shrink_val);
  snap->z[cnt] = shrink(Zbuf[i], shrink_val);
  snap->nx[cnt] = NXbuf[i];
  snap->ny[cnt] = NYbuf[i];
  snap->nz[cnt] = NZbuf[i];
  snap->sh[cnt] = SHbuf[i];
  snap->c[cnt] = true2high(img[i]);
  cnt++; }
 }
 *counter = cnt;
}

variable_types: y float

variable_types: p float

variable_types: struct Snapshot { unsigned int s; int cx; short *x; unsigned short *c; char *nx; unsigned char *sh; } *

variable_types:
counter
unsigned int *

variable_types:
i
unsigned int

variable_types:
cnt
unsigned int


decompiled_code:
__int64 __fastcall draw_snapshot(unsigned int *a1, int a2)
{
__int64 result; // rax
unsigned int v3; // er14
float v4; // xmm2_4
float v5; // xmm1_4
float v6; // xmm0_4
unsigned int v7; // er12
unsigned int v8; // er13
unsigned int v9; // er15
int v10; // eax
__int64 v11; // [rsp-10h] [rbp-78h]
unsigned int v12; // [rsp+8h] [rbp-60h]
unsigned int v13; // [rsp+Ch] [rbp-5Ch]
unsigned int v14; // [rsp+10h] [rbp-58h]
unsigned int v15; // [rsp+14h] [rbp-54h]
unsigned int v16; // [rsp+18h] [rbp-50h]
unsigned int v17[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

result = *a1;
v16 = result;
if ( (_DWORD)result )
{
v3 = 0;
do
{
v17[0] = high2true(*(unsigned __int16 *)(*((_QWORD *)a1 + 5) + 2LL * v3));
v4 = (double)*(char *)(*((_QWORD *)a1 + 8) + v3) * 0.0078125;
v5 = (double)*(char *)(*((_QWORD *)a1 + 7) + v3) * 0.0078125;
v6 = (double)*(char *)(*((_QWORD *)a1 + 6) + v3) * 0.0078125;
shade_spec(v17, *(unsigned __int8 *)(*((_QWORD *)a1 + 9) + v3), v6, v5, v4, lightx, lighty, lightz);
v7 = v17[0];
v15 = *(unsigned __int8 *)(*((_QWORD *)a1 + 9) + v3);
v14 = *(char *)(*((_QWORD *)a1 + 8) + v3);
v13 = *(char *)(*((_QWORD *)a1 + 7) + v3);
v12 = *(char *)(*((_QWORD *)a1 + 6) + v3);
v8 = a1[3] + expand((unsigned int)*(__int16 *)(*((_QWORD *)a1 + 4) + 2LL * v3), shrink_val);
v9 = a1[2] + expand((unsigned int)*(__int16 *)(*((_QWORD *)a1 + 3) + 2LL * v3), shrink_val);
v10 = expand((unsigned int)*(__int16 *)(*((_QWORD *)a1 + 2) + 2LL * v3), shrink_val);
project(a1[1] + v10, v9, v8, v7, v12, v13, v14, v15);
v3 += a2;
result = v11;
}
while ( v16 > v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, int a2)
{
__int64 result; // rax
unsigned int v3; // er14
float v4; // xmm2_4
float v5; // xmm1_4
float v6; // xmm0_4
unsigned int v7; // er12
unsigned int v8; // er13
unsigned int v9; // er15
int v10; // eax
__int64 v11; // [rsp-10h] [rbp-78h]
unsigned int v12; // [rsp+8h] [rbp-60h]
unsigned int v13; // [rsp+Ch] [rbp-5Ch]
unsigned int v14; // [rsp+10h] [rbp-58h]
unsigned int v15; // [rsp+14h] [rbp-54h]
unsigned int v16; // [rsp+18h] [rbp-50h]
unsigned int v17[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

result = *a1;
v16 = result;
if ( (_DWORD)result )
{
v3 = 0;
do
{
v17[0] = high2true(*(unsigned __int16 *)(*((_QWORD *)a1 + 5) + 2LL * v3));
v4 = (double)*(char *)(*((_QWORD *)a1 + 8) + v3) * 0.0078125;
v5 = (double)*(char *)(*((_QWORD *)a1 + 7) + v3) * 0.0078125;
v6 = (double)*(char *)(*((_QWORD *)a1 + 6) + v3) * 0.0078125;
shade_spec(v17, *(unsigned __int8 *)(*((_QWORD *)a1 + 9) + v3), v6, v5, v4, lightx, lighty, lightz);
v7 = v17[0];
v15 = *(unsigned __int8 *)(*((_QWORD *)a1 + 9) + v3);
v14 = *(char *)(*((_QWORD *)a1 + 8) + v3);
v13 = *(char *)(*((_QWORD *)a1 + 7) + v3);
v12 = *(char *)(*((_QWORD *)a1 + 6) + v3);
v8 = a1[3] + expand((unsigned int)*(__int16 *)(*((_QWORD *)a1 + 4) + 2LL * v3), shrink_val);
v9 = a1[2] + expand((unsigned int)*(__int16 *)(*((_QWORD *)a1 + 3) + 2LL * v3), shrink_val);
v10 = expand((unsigned int)*(__int16 *)(*((_QWORD *)a1 + 2) + 2LL * v3), shrink_val);
project(a1[1] + v10, v9, v8, v7, v12, v13, v14, v15);
v3 += a2;
result = v11;
}
while ( v16 > v3 );
}
return result;
}

original_code:
void draw_snapshot(Snapshot *snap, const uint32_t skip)
{
 uint32_t i, len = snap->s, color; Color32 c32;
 for (i=0; i<len; i+=skip) {
  c32.col = high2true(snap->c[i]);
  shade_spec(&c32, snap->nx[i]/128.0,
       snap->ny[i]/128.0,
       snap->nz[i]/128.0,
       lightx, lighty, lightz,
       snap->sh[i]);
  project(expand(snap->x[i], shrink_val)+snap->cx,
    expand(snap->y[i], shrink_val)+snap->cy,
    expand(snap->z[i], shrink_val)+snap->cz,
    c32.col,
    snap->nx[i], snap->ny[i], snap->nz[i], snap->sh[i]);
 }
}

canonical_original_code:
void draw_snapshot(struct Snapshot *snap, unsigned int skip)
{
 unsigned int i; unsigned int len = snap->s; unsigned int color; union Color32 c32;
 for (i=0; i<len; i+=skip) {
  c32.col = high2true(snap->c[i]);
  shade_spec(&c32, snap->nx[i]/128.0,
       snap->ny[i]/128.0,
       snap->nz[i]/128.0,
       lightx, lighty, lightz,
       snap->sh[i]);
  project(expand(snap->x[i], shrink_val)+snap->cx,
    expand(snap->y[i], shrink_val)+snap->cy,
    expand(snap->z[i], shrink_val)+snap->cz,
    c32.col,
    snap->nx[i], snap->ny[i], snap->nz[i], snap->sh[i]);
 }
}

variable_types:
skip
unsigned int

variable_types:
len
unsigned int

variable_types:
color
unsigned int

variable_types: union Color32 { unsigned int col; unsigned char rgba[4]; }

user_defined_types: struct Snapshot { unsigned int s; int cx; short *x; unsigned short *c; char *nx; unsigned char *sh; }


decompiled_code:
__int64 clear_zbuffer()
{
__int64 result; // rax
_DWORD *v1; // rdx
__int64 v2; // rcx
__int64 v3; // rcx

result = (unsigned int)(HEIGHT * WIDTH);
if ( (int)result > 0 )
{
v1 = (_DWORD *)zbuffer;
v2 = (unsigned int)(result - 1);
result = zbuffer + 4LL;
v3 = zbuffer + 4LL + 4 * v2;
while ( 1 )
{
*v1 = LC0;
v1 = (_DWORD *)result;
if ( result == v3 )
break;
result += 4LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
_DWORD *v1; // rdx
__int64 v2; // rcx
__int64 v3; // rcx

result = (unsigned int)(HEIGHT * WIDTH);
if ( (int)result > 0 )
{
v1 = (_DWORD *)zbuffer;
v2 = (unsigned int)(result - 1);
result = zbuffer + 4LL;
v3 = zbuffer + 4LL + 4 * v2;
while ( 1 )
{
*v1 = LC0;
v1 = (_DWORD *)result;
if ( result == v3 )
break;
result += 4LL;
}
}
return result;
}

original_code:
void clear_zbuffer()
{
 int x, len = WIDTH*HEIGHT;
 for (x=0;x<len;x++) {
  zbuffer[x] = 100000;
 }
}

canonical_original_code:
void clear_zbuffer()
{
 int x; int len = WIDTH*HEIGHT;
 for (x=0;x<len;x++) {
  zbuffer[x] = 100000;
 }
}

variable_types: x int

variable_types: len int