SQLBulkOperations

decompiled_code:
__int64 __fastcall SQLBulkOperations(__int64 a1, __int16 a2)
{
__int64 result; // rax
char *v3; // r12
__int64 v4; // rdx

result = 4294967294LL;
if ( a1 )
{
v3 = (char *)(a1 + 136);
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLBulkOperations.c", "SQLBulkOperations.c", 26LL, 1LL, 1LL, a1 + 136);
v4 = (unsigned int)a2;
if ( (unsigned int)(v4 - 4) > 3 )
{
sprintf(v3, "SQL_ERROR Unknown nOperation=%d", v4);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLBulkOperations.c", "SQLBulkOperations.c", 41LL, 1LL, 1LL, v3);
}
else
{
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLBulkOperations.c",
"SQLBulkOperations.c",
48LL,
1LL,
1LL,
"SQL_ERROR This function not currently supported");
}
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int16 a2)
{
__int64 result; // rax
char *v3; // r12
__int64 v4; // rdx

result = 4294967294LL;
if ( a1 )
{
v3 = (char *)(a1 + 136);
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLBulkOperations.c", "SQLBulkOperations.c", 26LL, 1LL, 1LL, a1 + 136);
v4 = (unsigned int)a2;
if ( (unsigned int)(v4 - 4) > 3 )
{
sprintf(v3, "SQL_ERROR Unknown nOperation=%d", v4);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLBulkOperations.c", "SQLBulkOperations.c", 41LL, 1LL, 1LL, v3);
}
else
{
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLBulkOperations.c",
"SQLBulkOperations.c",
48LL,
1LL,
1LL,
"SQL_ERROR This function not currently supported");
}
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
SQLRETURN SQLBulkOperations(
    SQLHSTMT statement_handle,
    SQLSMALLINT operation )
{
    DMHSTMT statement = (DMHSTMT)statement_handle;
    SQLRETURN ret;
    SQLCHAR s1[ 100 + 128 ];
    if ( !__validate_stmt( statement ))
    {
        dm_log_write( "SQLBulkOperations.c",
                124,
                    0,
                    0,
                    "Error: SQL_INVALID_HANDLE" );
        return (-2);
    }
    function_entry( statement );
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg, "\n\t\tEntry:\n\t\t\tStatement = %p\n\t\t\tOption = %d",
                statement,
                operation );
        dm_log_write( "SQLBulkOperations.c",
                143,
                0,
                0,
                statement -> msg );
    }
    thread_protect( 3, statement );
    if ( statement -> state == 1 ||
            statement -> state == 2 ||
            statement -> state == 3 )
    {
        dm_log_write( "SQLBulkOperations.c",
                160,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 4 )
    {
        dm_log_write( "SQLBulkOperations.c",
                175,
                0,
                0,
                "Error: 24000" );
        __post_internal_error( &statement -> error,
                ERROR_24000, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 7 )
    {
        dm_log_write( "SQLBulkOperations.c",
                190,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 8 ||
            statement -> state == 9 ||
            statement -> state == 10 )
    {
        dm_log_write( "SQLBulkOperations.c",
                207,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 11 ||
            statement -> state == 12 )
    {
        if ( statement -> interupted_func != 24 )
        {
            dm_log_write( "SQLBulkOperations.c",
                    225,
                    0,
                    0,
                    "Error: HY010" );
            __post_internal_error( &statement -> error,
                    ERROR_HY010, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( (statement -> connection->functions[9].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[9].func)(statement -> driver_stmt,operation);
    }
    else if ( (statement -> connection->functions[68].func!=((void *)0)) &&
            statement -> connection -> driver_act_ver == 2UL &&
            operation == 4 )
    {
        ret = (statement -> connection->functions[68].func) (statement -> driver_stmt,0,4,0);
    }
    else
    {
        dm_log_write( "SQLBulkOperations.c",
                261,
                0,
                0,
                "Error: IM001" );
        __post_internal_error( &statement -> error,
                ERROR_IM001, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( ret == 2 )
    {
        statement -> interupted_func = 24;
        if ( statement -> state != 11 &&
                statement -> state != 12 )
            statement -> state = 11;
    }
    else if ( ret == 99 )
    {
        statement -> interupted_func = 24;
        statement -> interupted_state = statement -> state;
        statement -> state = 8;
    }
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg,
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s1 ));
        dm_log_write( "SQLBulkOperations.c",
                294,
                0,
                0,
                statement -> msg );
    }
    return function_return_ex(3,statement,ret,0);
}

canonical_original_code:
short SQLBulkOperations(void *statement_handle, short operation)
{
    struct statement *statement = (DMHSTMT)statement_handle;
    short ret;
    unsigned char s1[-1];
    if ( !__validate_stmt( statement ))
    {
        dm_log_write( "SQLBulkOperations.c",
                124,
                    0,
                    0,
                    "Error: SQL_INVALID_HANDLE" );
        return (-2);
    }
    function_entry( statement );
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg, "\n\t\tEntry:\n\t\t\tStatement = %p\n\t\t\tOption = %d",
                statement,
                operation );
        dm_log_write( "SQLBulkOperations.c",
                143,
                0,
                0,
                statement -> msg );
    }
    thread_protect( 3, statement );
    if ( statement -> state == 1 ||
            statement -> state == 2 ||
            statement -> state == 3 )
    {
        dm_log_write( "SQLBulkOperations.c",
                160,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 4 )
    {
        dm_log_write( "SQLBulkOperations.c",
                175,
                0,
                0,
                "Error: 24000" );
        __post_internal_error( &statement -> error,
                ERROR_24000, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 7 )
    {
        dm_log_write( "SQLBulkOperations.c",
                190,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 8 ||
            statement -> state == 9 ||
            statement -> state == 10 )
    {
        dm_log_write( "SQLBulkOperations.c",
                207,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 11 ||
            statement -> state == 12 )
    {
        if ( statement -> interupted_func != 24 )
        {
            dm_log_write( "SQLBulkOperations.c",
                    225,
                    0,
                    0,
                    "Error: HY010" );
            __post_internal_error( &statement -> error,
                    ERROR_HY010, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( (statement -> connection->functions[9].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[9].func)(statement -> driver_stmt,operation);
    }
    else if ( (statement -> connection->functions[68].func!=((void *)0)) &&
            statement -> connection -> driver_act_ver == 2UL &&
            operation == 4 )
    {
        ret = (statement -> connection->functions[68].func) (statement -> driver_stmt,0,4,0);
    }
    else
    {
        dm_log_write( "SQLBulkOperations.c",
                261,
                0,
                0,
                "Error: IM001" );
        __post_internal_error( &statement -> error,
                ERROR_IM001, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( ret == 2 )
    {
        statement -> interupted_func = 24;
        if ( statement -> state != 11 &&
                statement -> state != 12 )
            statement -> state = 11;
    }
    else if ( ret == 99 )
    {
        statement -> interupted_func = 24;
        statement -> interupted_state = statement -> state;
        statement -> state = 8;
    }
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg,
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s1 ));
        dm_log_write( "SQLBulkOperations.c",
                294,
                0,
                0,
                statement -> msg );
    }
    return function_return_ex(3,statement,ret,0);
}

variable_types: operation short

variable_types: struct statement { int type; struct statement *next_class_list; char msg[1024]; int state; struct connection { int type; struct connection *next_class_list; char msg[1024]; int state; struct environment { int type; struct environment *next_class_list; char msg[1024]; int state; long requested_version; int connection_count; int sql_driver_count; struct error_head { struct error_header { int error_count; struct error { unsigned short sqlstate[6]; unsigned short *msg; long native_error; int return_val; short diag_column_number_ret; short diag_row_number_ret; short diag_class_origin_ret; short diag_subclass_origin_ret; short diag_connection_name_ret; short diag_server_name_ret; long diag_column_number; long diag_row_number; unsigned short diag_class_origin[128]; unsigned short diag_subclass_origin[128]; unsigned short diag_connection_name[128]; unsigned short diag_server_name[128]; struct error *next; struct error *prev; } *error_list_head; struct error *error_list_tail; int internal_count; struct error *internal_list_head; struct error *internal_list_tail; } sql_error_head; struct error_header sql_diag_head; void *owning_handle; int handle_type; short return_code; long header_set; short diag_cursor_row_count_ret; short diag_dynamic_function_ret; short diag_dynamic_function_code_ret; short diag_number_ret; short diag_row_count_ret; long diag_cursor_row_count; unsigned short diag_dynamic_function[128]; long diag_dynamic_function_code; long diag_number; long diag_row_count; } error; long connection_pooling; long cp_match; int fetch_mode; int entry; void *sh; struct env_lib_struct { char *lib_name; void *env_handle; int count; struct env_lib_struct *next; } *env_lib_list; } *environment; void *dl_handle; char dl_name[256]; struct driver_func { int ordinal; char *name; void *dm_func; void *dm_funcW; short (*func)(); short (*funcW)(); short (*funcA)(); int can_supply; } *functions; struct driver_func ini_func; struct driver_func fini_func; int unicode_driver; void *driver_env; void *driver_dbc; int driver_version; int driver_act_ver; int statement_count; struct error_head error; char dsn[-1]; int access_mode; int access_mode_set; int login_timeout; int login_timeout_set; int auto_commit; int auto_commit_set; int async_enable; int async_enable_set; int auto_ipd; int auto_ipd_set; int connection_timeout; int connection_timeout_set; int metadata_id; int metadata_id_set; int packet_size; int packet_size_set; long quite_mode; int quite_mode_set; int txn_isolation; int txn_isolation_set; long cursors; void *cl_handle; int trace; char tracefile[-1]; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; int protection_level; int ex_fetch_mapping; int disable_gf; int dont_dlclose; int bookmarks_on; void *pooled_connection; int pooling_timeout; int ttl; char driver_connect_string[1024]; int dsn_length; char server[128]; int server_length; char user[128]; int user_length; char password[128]; int password_length; char cli_year[5]; struct attr_struct { int count; struct attr_set { char *keyword; char *value; int override; int attribute; int is_int_type; int int_value; struct attr_set *next; } *list; } env_attribute; struct attr_struct dbc_attribute; struct attr_struct stmt_attribute; struct save_attr { int attr_type; char *str_attr; int str_len; int int_attr; struct save_attr *next; } *save_attr; void *iconv_cd_uc_to_ascii; void *iconv_cd_ascii_to_uc; char unicode_string[64]; struct env_lib_struct *env_list_ent; char probe_sql[512]; int threading_level; int cbs_found; short ccb_value; short crb_value; } *connection; void *driver_stmt; short hascols; int prepared; int interupted_func; int interupted_state; int bookmarks_on; struct error_head error; long metadata_id; struct descriptor { int type; struct descriptor *next_class_list; char msg[1024]; int state; struct error_head error; void *driver_desc; struct connection *connection; int implicit; void *associated_with; union pthread_mutex_t mutex; } *ipd; struct descriptor *apd; struct descriptor *ird; struct descriptor *ard; struct descriptor *implicit_ipd; struct descriptor *implicit_apd; struct descriptor *implicit_ird; struct descriptor *implicit_ard; unsigned long *fetch_bm_ptr; unsigned long *row_ct_ptr; unsigned short *row_st_arr; unsigned long row_array_size; void *valueptr; union pthread_mutex_t mutex; int eod; } *

variable_types: ret short

user_defined_types: struct statement { int type; struct statement *next_class_list; char msg[1024]; int state; struct connection *connection; void *driver_stmt; short hascols; int prepared; int interupted_func; int interupted_state; int bookmarks_on; struct error_head error; long metadata_id; struct descriptor *ipd; struct descriptor *apd; struct descriptor *ird; struct descriptor *ard; struct descriptor *implicit_ipd; struct descriptor *implicit_apd; struct descriptor *implicit_ird; struct descriptor *implicit_ard; unsigned long *fetch_bm_ptr; unsigned long *row_ct_ptr; unsigned short *row_st_arr; unsigned long row_array_size; void *valueptr; union pthread_mutex_t mutex; int eod; }

user_defined_types: struct connection { int type; struct connection *next_class_list; char msg[1024]; int state; struct environment *environment; void *dl_handle; char dl_name[256]; struct driver_func *functions; struct driver_func ini_func; struct driver_func fini_func; int unicode_driver; void *driver_env; void *driver_dbc; int driver_version; int driver_act_ver; int statement_count; struct error_head error; char dsn[-1]; int access_mode; int access_mode_set; int login_timeout; int login_timeout_set; int auto_commit; int auto_commit_set; int async_enable; int async_enable_set; int auto_ipd; int auto_ipd_set; int connection_timeout; int connection_timeout_set; int metadata_id; int metadata_id_set; int packet_size; int packet_size_set; long quite_mode; int quite_mode_set; int txn_isolation; int txn_isolation_set; long cursors; void *cl_handle; int trace; char tracefile[-1]; union pthread_mutex_t mutex; int protection_level; int ex_fetch_mapping; int disable_gf; int dont_dlclose; int bookmarks_on; void *pooled_connection; int pooling_timeout; int ttl; char driver_connect_string[1024]; int dsn_length; char server[128]; int server_length; char user[128]; int user_length; char password[128]; int password_length; char cli_year[5]; struct attr_struct env_attribute; struct attr_struct dbc_attribute; struct attr_struct stmt_attribute; struct save_attr *save_attr; void *iconv_cd_uc_to_ascii; void *iconv_cd_ascii_to_uc; char unicode_string[64]; struct env_lib_struct *env_list_ent; char probe_sql[512]; int threading_level; int cbs_found; short ccb_value; short crb_value; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct attr_struct { int count; struct attr_set *list; }

user_defined_types: struct environment { int type; struct environment *next_class_list; char msg[1024]; int state; long requested_version; int connection_count; int sql_driver_count; struct error_head error; long connection_pooling; long cp_match; int fetch_mode; int entry; void *sh; struct env_lib_struct *env_lib_list; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct error_head { struct error_header sql_error_head; struct error_header sql_diag_head; void *owning_handle; int handle_type; short return_code; long header_set; short diag_cursor_row_count_ret; short diag_dynamic_function_ret; short diag_dynamic_function_code_ret; short diag_number_ret; short diag_row_count_ret; long diag_cursor_row_count; unsigned short diag_dynamic_function[128]; long diag_dynamic_function_code; long diag_number; long diag_row_count; }

user_defined_types: struct error_header { int error_count; struct error *error_list_head; struct error *error_list_tail; int internal_count; struct error *internal_list_head; struct error *internal_list_tail; }


SQLGetDescRec

repo: xiaotmiaomiao/unixODBC-SPEC

decompiled_code:
__int64 SQLGetDescRec()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0xFFFFFFFFLL;
}

original_code:
SQLRETURN SQLGetDescRec( SQLHDESC DescriptorHandle,
                             SQLSMALLINT RecordNumber,
                             SQLCHAR *Name,
                             SQLSMALLINT BufferLength,
                             SQLSMALLINT *StringLength,
                             SQLSMALLINT *Type,
                             SQLSMALLINT *SubType,
                             SQLINTEGER *Length,
                             SQLSMALLINT *Precision,
                             SQLSMALLINT *Scale,
                             SQLSMALLINT *Nullable
                        )
{
    return (-1);
}

canonical_original_code:
short SQLGetDescRec(void *DescriptorHandle, short RecordNumber, unsigned char *Name, short BufferLength, short *StringLength, short *Type, short *SubType, long *Length, short *Precision, short *Scale, short *Nullable)
{
    return (-1);
}

variable_types:
DescriptorHandle
void *

variable_types: RecordNumber short

variable_types:
Name
unsigned char *

variable_types: BufferLength short

variable_types:
StringLength
short *

variable_types:
Type
short *

variable_types:
SubType
short *

variable_types:
Length
long *

variable_types:
Precision
short *

variable_types:
Scale
short *

variable_types:
Nullable
short *

return_type: short


SQLSetConfigMode

decompiled_code:
__int64 __fastcall SQLSetConfigMode(unsigned __int16 a1)
{
inst_logClear();
_set_config_mode(a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 a1)
{
inst_logClear();
func0(a1);
return 1LL;
}

original_code:
int SQLSetConfigMode( UWORD nConfigMode )
{
    inst_logClear();
    __set_config_mode( nConfigMode );
    return 1;
}

canonical_original_code:
int SQLSetConfigMode(unsigned short nConfigMode)
{
    inst_logClear();
    __set_config_mode( nConfigMode );
    return 1;
}

variable_types:
nConfigMode
unsigned short

return_type: int


SQLNativeSql

decompiled_code:
__int64 __fastcall SQLNativeSql(__int64 a1)
{
if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLNativeSql.c", "SQLNativeSql.c", 30LL, 1LL, 1LL, a1 + 136);
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLNativeSql.c",
"SQLNativeSql.c",
35LL,
1LL,
1LL,
"SQL_ERROR This function not supported");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLNativeSql.c", "SQLNativeSql.c", 30LL, 1LL, 1LL, a1 + 136);
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLNativeSql.c",
"SQLNativeSql.c",
35LL,
1LL,
1LL,
"SQL_ERROR This function not supported");
return 0xFFFFFFFFLL;
}

original_code:
SQLRETURN SQLNativeSql(
    SQLHDBC hdbc,
    SQLCHAR *szSqlStrIn,
    SQLINTEGER cbSqlStrIn,
    SQLCHAR *szSqlStr,
    SQLINTEGER cbSqlStrMax,
    SQLINTEGER *pcbSqlStr)
{
static char* const func="SQLNativeSql";
int len = 0;
char *ptr;
ConnectionClass *conn = (ConnectionClass *) hdbc;
RETCODE result;
 mylog( "%s: entering...cbSqlStrIn=%d\n", func, cbSqlStrIn);
 ptr = (cbSqlStrIn == 0) ? "" : make_string((char*)szSqlStrIn, cbSqlStrIn, ((void *)0));
 if ( ! ptr) {
  CC_set_error(conn, 208, "No memory available to store native sql string");
  CC_log_error(func, "", conn);
  return (-1);
 }
 result = 0;
 len = strlen(ptr);
 if (szSqlStr) {
  strncpy_null((char*)szSqlStr, ptr, cbSqlStrMax);
  if (len >= cbSqlStrMax) {
   result = 1;
   CC_set_error(conn, -2, "The buffer was too small for the result.");
  }
 }
 if (pcbSqlStr)
  *pcbSqlStr = len;
 free(ptr);
    return result;
}

canonical_original_code:
short SQLNativeSql(void *hdbc, unsigned char *szSqlStrIn, long cbSqlStrIn, unsigned char *szSqlStr, long cbSqlStrMax, long *pcbSqlStr)
{
static char *func = "SQLNativeSql";
int len = 0;
char *ptr;
struct ConnectionClass_ *conn = (ConnectionClass *) hdbc;
short result;
 mylog( "%s: entering...cbSqlStrIn=%d\n", func, cbSqlStrIn);
 ptr = (cbSqlStrIn == 0) ? "" : make_string((char *)szSqlStrIn, cbSqlStrIn, ((void *)0));
 if ( ! ptr) {
  CC_set_error(conn, 208, "No memory available to store native sql string");
  CC_log_error(func, "", conn);
  return (-1);
 }
 result = 0;
 len = strlen(ptr);
 if (szSqlStr) {
  strncpy_null((char *)szSqlStr, ptr, cbSqlStrMax);
  if (len >= cbSqlStrMax) {
   result = 1;
   CC_set_error(conn, -2, "The buffer was too small for the result.");
  }
 }
 if (pcbSqlStr)
  *pcbSqlStr = len;
 free(ptr);
    return result;
}

variable_types:
hdbc
void *

variable_types:
szSqlStrIn
unsigned char *

variable_types: cbSqlStrIn long

variable_types:
szSqlStr
unsigned char *

variable_types: cbSqlStrMax long

variable_types:
pcbSqlStr
long *

variable_types:
func
char *

variable_types: len int

variable_types:
ptr
char *

variable_types: struct ConnectionClass_ { void *henv; struct StatementOptions_ { int maxRows; int maxLength; int rowset_size; int keyset_size; int cursor_type; int scroll_concurrency; int retrieve_data; int bind_size; int use_bookmarks; } stmtOptions; char *__error_message; int __error_number; enum CONN_Status { CONN_NOT_CONNECTED=0, CONN_CONNECTED=1, CONN_DOWN=2, CONN_EXECUTING=3 } status; struct ConnInfo { char dsn[256]; char desc[256]; char driver[256]; char server[256]; char database[256]; char username[256]; char password[256]; char conn_settings[4096]; char protocol[10]; char port[10]; char uds[4096]; char onlyread[10]; char fake_oid_index[10]; char show_oid_column[10]; char row_versioning[10]; char show_system_tables[10]; char translation_dll[256]; char translation_option[10]; char focus_password; } connInfo; struct StatementClass_ { struct ConnectionClass_ *hdbc; struct QResultClass_ { struct ColumnInfoClass_ { short num_fields; char **name; unsigned int *adtid; short *adtsize; short *display_size; int *atttypmod; } *fields; struct TupleListClass_ { int num_fields; int num_tuples; struct TupleNode_ { struct TupleNode_ *prev; struct TupleField_ { int len; void *value; } tuple[1]; } *list_start; int last_indexed; } *manual_tuples; struct ConnectionClass_ *conn; int fetch_count; int fcount; int currTuple; int base; int num_fields; int cache_size; int rowset_size; enum QueryResultCode_ { PGRES_EMPTY_QUERY=0, PGRES_COMMAND_OK=1, PGRES_TUPLES_OK=2, PGRES_COPY_OUT=3, PGRES_COPY_IN=4, PGRES_BAD_RESPONSE=5, PGRES_NONFATAL_ERROR=6, PGRES_FATAL_ERROR=7, PGRES_FIELDS_OK=8, PGRES_END_TUPLES=9, PGRES_INTERNAL_ERROR=10 } status; char *message; char *cursor; char *command; char *notice; struct TupleField_ *backend_tuples; struct TupleField_ *tupleField; char inTuples; char aborted; } *result; void **phstmt; struct StatementOptions_ options; enum STMT_Status { STMT_ALLOCATED=0, STMT_READY=1, STMT_PREMATURE=2, STMT_FINISHED=3, STMT_EXECUTING=4 } status; char *__error_message; int __error_number; struct BindInfoClass_ { int buflen; int data_left; char *buffer; long *used; short returntype; } *bindings; struct BindInfoClass_ bookmark; int bindings_allocated; int parameters_allocated; struct ParameterInfoClass_ { int buflen; char *buffer; long *used; short paramType; short CType; short SQLType; unsigned int precision; short scale; unsigned int lobj_oid; int *EXEC_used; char *EXEC_buffer; char data_at_exec; } *parameters; int currTuple; int save_rowset_size; int rowset_start; int bind_row; int last_fetch_count; int current_col; int lobj_fd; char *statement; struct TABLE_INFO { struct col_info { struct QResultClass_ *result; char name[-1]; } *col_info; char name[-1]; char alias[-1]; } **ti; struct FIELD_INFO { struct TABLE_INFO *ti; int precision; int display_size; int length; int type; char nullable; char func; char expr; char quote; char dquote; char numeric; char dot[-1]; char name[-1]; char alias[-1]; } **fi; int nfld; int ntab; int parse_status; int statement_type; int data_at_exec; int current_exec_param; char put_data; char errormsg_created; char manual_result; char prepare; char internal; char cursor_name[-1]; char stmt_with_params[65536]; int reexecute; } **stmts; int num_stmts; struct SocketClass_ { int buffer_filled_in; int buffer_filled_out; int buffer_read_in; unsigned char *buffer_in; unsigned char *buffer_out; int socket; char *errormsg; int errornumber; char reverse; } *sock; int lobj_type; int ntables; struct col_info **col_info; long translation_option; void *translation_handle; int (*DataSourceToDriver)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); int (*DriverToDataSource)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); short driver_version; char transact_status; char errormsg_created; char pg_version[128]; float pg_version_number; short pg_version_major; short pg_version_minor; char ms_jet; char unicode; char result_uncommitted; char schema_support; char *client_encoding; char *server_encoding; int ccsc; int be_pid; int be_key; unsigned int isolation; char *current_schema; int num_discardp; char **discardp; } *

variable_types: result short

user_defined_types: struct ConnectionClass_ { void *henv; struct StatementOptions_ stmtOptions; char *__error_message; int __error_number; enum CONN_Status status; struct ConnInfo connInfo; struct StatementClass_ **stmts; int num_stmts; struct SocketClass_ *sock; int lobj_type; int ntables; struct col_info **col_info; long translation_option; void *translation_handle; int (*DataSourceToDriver)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); int (*DriverToDataSource)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); short driver_version; char transact_status; char errormsg_created; char pg_version[128]; float pg_version_number; short pg_version_major; short pg_version_minor; char ms_jet; char unicode; char result_uncommitted; char schema_support; char *client_encoding; char *server_encoding; int ccsc; int be_pid; int be_key; unsigned int isolation; char *current_schema; int num_discardp; char **discardp; }

user_defined_types: struct StatementClass_ { struct ConnectionClass_ *hdbc; struct QResultClass_ *result; void **phstmt; struct StatementOptions_ options; enum STMT_Status status; char *__error_message; int __error_number; struct BindInfoClass_ *bindings; struct BindInfoClass_ bookmark; int bindings_allocated; int parameters_allocated; struct ParameterInfoClass_ *parameters; int currTuple; int save_rowset_size; int rowset_start; int bind_row; int last_fetch_count; int current_col; int lobj_fd; char *statement; struct TABLE_INFO **ti; struct FIELD_INFO **fi; int nfld; int ntab; int parse_status; int statement_type; int data_at_exec; int current_exec_param; char put_data; char errormsg_created; char manual_result; char prepare; char internal; char cursor_name[-1]; char stmt_with_params[65536]; int reexecute; }

user_defined_types: struct QResultClass_ { struct ColumnInfoClass_ *fields; struct TupleListClass_ *manual_tuples; struct ConnectionClass_ *conn; int fetch_count; int fcount; int currTuple; int base; int num_fields; int cache_size; int rowset_size; enum QueryResultCode_ status; char *message; char *cursor; char *command; char *notice; struct TupleField_ *backend_tuples; struct TupleField_ *tupleField; char inTuples; char aborted; }

user_defined_types: struct TABLE_INFO { struct col_info *col_info; char name[-1]; char alias[-1]; }

user_defined_types: struct TupleListClass_ { int num_fields; int num_tuples; struct TupleNode_ *list_start; int last_indexed; }

user_defined_types: struct TupleNode_ { struct TupleNode_ *prev; struct TupleField_ tuple[1]; }


SQLWritePrivateProfileStringW

decompiled_code:
__int64 __fastcall SQLWritePrivateProfileStringW(void *ptr, void *a2, void *a3, void *a4)
{
_BYTE *v4; // r14
void *v5; // r13
unsigned int v8; // er15

v4 = ptr;
v5 = a2;
if ( ptr )
v4 = (_BYTE *)((__int64 (*)(void))single_string_alloc_and_copy)();
if ( a2 )
v5 = (void *)single_string_alloc_and_copy(a2);
if ( a3 )
a3 = (void *)single_string_alloc_and_copy(a3);
if ( a4 )
a4 = (void *)single_string_alloc_and_copy(a4);
v8 = SQLWritePrivateProfileString(v4, (__int64)v5, (__int64)a3, (const char *)a4);
if ( v4 )
free(v4);
if ( v5 )
free(v5);
if ( a3 )
free(a3);
if ( a4 )
free(a4);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr, void *a2, void *a3, void *a4)
{
_BYTE *v4; // r14
void *v5; // r13
unsigned int v8; // er15

v4 = ptr;
v5 = a2;
if ( ptr )
v4 = (_BYTE *)((__int64 (*)(void))single_string_alloc_and_copy)();
if ( a2 )
v5 = (void *)single_string_alloc_and_copy(a2);
if ( a3 )
a3 = (void *)single_string_alloc_and_copy(a3);
if ( a4 )
a4 = (void *)single_string_alloc_and_copy(a4);
v8 = func0(v4, (__int64)v5, (__int64)a3, (const char *)a4);
if ( v4 )
free(v4);
if ( v5 )
free(v5);
if ( a3 )
free(a3);
if ( a4 )
free(a4);
return v8;
}

original_code:
int SQLWritePrivateProfileStringW(LPCWSTR lpszSection,
                                         LPCWSTR lpszEntry,
                                         LPCWSTR lpszString,
                                         LPCWSTR lpszFilename)
{
 char *sect;
 char *entry;
 char *string;
 char *file;
 int ret;
 sect = lpszSection ? _single_string_alloc_and_copy( lpszSection ) : (char*)((void *)0);
 entry = lpszEntry ? _single_string_alloc_and_copy( lpszEntry ) : (char*)((void *)0);
 string = lpszString ? _single_string_alloc_and_copy( lpszString ) : (char*)((void *)0);
 file = lpszFilename ? _single_string_alloc_and_copy( lpszFilename ) : (char*)((void *)0);
 ret = SQLWritePrivateProfileString( sect, entry, string, file );
 if ( sect )
  free( sect );
 if ( entry )
  free( entry );
 if ( string )
  free( string );
 if ( file )
  free( file );
 return ret;
}

canonical_original_code:
int SQLWritePrivateProfileStringW(unsigned short *lpszSection, unsigned short *lpszEntry, unsigned short *lpszString, unsigned short *lpszFilename)
{
 char *sect;
 char *entry;
 char *string;
 char *file;
 int ret;
 sect = lpszSection ? _single_string_alloc_and_copy( lpszSection ) : (char *)((void *)0);
 entry = lpszEntry ? _single_string_alloc_and_copy( lpszEntry ) : (char *)((void *)0);
 string = lpszString ? _single_string_alloc_and_copy( lpszString ) : (char *)((void *)0);
 file = lpszFilename ? _single_string_alloc_and_copy( lpszFilename ) : (char *)((void *)0);
 ret = SQLWritePrivateProfileString( sect, entry, string, file );
 if ( sect )
  free( sect );
 if ( entry )
  free( entry );
 if ( string )
  free( string );
 if ( file )
  free( file );
 return ret;
}

variable_types:
lpszSection
unsigned short *

variable_types:
lpszEntry
unsigned short *

variable_types:
lpszString
unsigned short *

variable_types:
lpszFilename
unsigned short *

variable_types:
sect
char *

variable_types:
entry
char *

variable_types:
string
char *

variable_types:
file
char *

variable_types: ret int


SQLColAttributes

decompiled_code:
__int64 __fastcall SQLColAttributes(__int64 a1, __int64 a2, unsigned __int16 a3)
{
if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLColAttributes.c", "SQLColAttributes.c", 32LL, 1LL, 1LL, a1 + 136);
sprintf((char *)(a1 + 136), "SQL_ERROR nDescType=%d", a3);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLColAttributes.c", "SQLColAttributes.c", 71LL, 1LL, 1LL, a1 + 136);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned __int16 a3)
{
if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLColAttributes.c", "SQLColAttributes.c", 32LL, 1LL, 1LL, a1 + 136);
sprintf((char *)(a1 + 136), "SQL_ERROR nDescType=%d", a3);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLColAttributes.c", "SQLColAttributes.c", 71LL, 1LL, 1LL, a1 + 136);
return 0xFFFFFFFFLL;
}

original_code:
SQLRETURN SQLColAttributes(
    SQLHSTMT hstmt,
    SQLUSMALLINT icol,
    SQLUSMALLINT fDescType,
    SQLPOINTER rgbDesc,
    SQLSMALLINT cbDescMax,
    SQLSMALLINT *pcbDesc,
    SQLINTEGER *pfDesc)
{
static char* const func = "SQLColAttributes";
StatementClass *stmt = (StatementClass *) hstmt;
int field_type = 0;
ConnInfo *ci;
int unknown_sizes;
int cols = 0;
char parse_ok;
RETCODE result;
char *p = ((void *)0);
int len = 0, value = 0;
 mylog("%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 ci = &(stmt->hdbc->connInfo);
 icol--;
 unknown_sizes = globals.unknown_sizes;
 if (unknown_sizes == 1)
  unknown_sizes = 0;
 parse_ok = (int)0;
 if (globals.parse && stmt->statement_type == STMT_TYPE_SELECT) {
  if (stmt->parse_status == STMT_PARSE_NONE) {
   mylog("SQLColAttributes: calling parse_statement\n");
   parse_statement(stmt);
  }
  cols = stmt->nfld;
  if (fDescType == 0) {
   if (pfDesc)
    *pfDesc = cols;
   return 0;
  }
  if (stmt->parse_status != STMT_PARSE_FATAL && stmt->fi && stmt->fi[icol]) {
   if (icol >= cols) {
    SC_set_error(stmt, 13, "Invalid column number in DescribeCol.");
    SC_log_error(func, "", stmt);
    return (-1);
   }
   field_type = stmt->fi[icol]->type;
   if (field_type > 0)
    parse_ok = (int)1;
  }
 }
 if ( ! parse_ok) {
  SC_pre_execute(stmt);
  mylog("**** SQLColAtt: result = %u, status = %d, numcols = %d\n", stmt->result, stmt->status, stmt->result != ((void *)0) ? (((stmt->result->fields) ? (stmt->result->fields->num_fields) : (-1))) : -1);
  if ( (((void *)0) == stmt->result) || ((stmt->status != STMT_FINISHED) && (stmt->status != STMT_PREMATURE)) ) {
   SC_set_error(stmt, 3, "Can't get column attributes: no result found.");
   SC_log_error(func, "", stmt);
   return (-1);
  }
  cols = (((stmt->result->fields) ? (stmt->result->fields->num_fields) : (-1)));
  if (fDescType == 0) {
   if (pfDesc)
    *pfDesc = cols;
   return 0;
  }
  if (icol >= cols) {
   SC_set_error(stmt, 13, "Invalid column number in DescribeCol.");
   SC_log_error(func, "", stmt);
   return (-1);
  }
  field_type = ((stmt->result->fields->adtid[icol]));
 }
 mylog("colAttr: col %d field_type = %d\n", icol, field_type);
 switch(fDescType) {
 case 11:
  value = pgtype_auto_increment(stmt, field_type);
  if (value == -1)
   value = (int)0;
  break;
 case 12:
  value = pgtype_case_sensitive(stmt, field_type);
  break;
    case 6:
  value = (parse_ok) ? stmt->fi[icol]->display_size : pgtype_display_size(stmt, field_type, icol, unknown_sizes);
  mylog("SQLColAttributes: col %d, display_size= %d\n", icol, value);
        break;
 case 18:
  if (parse_ok && stmt->fi[icol]->alias[0] != '\0') {
   p = stmt->fi[icol]->alias;
   mylog("SQLColAttr: COLUMN_LABEL = '%s'\n", p);
   break;
  }
 case 1:
  p = (parse_ok) ? stmt->fi[icol]->name : ((stmt->result->fields->name[icol]));
  mylog("SQLColAttr: COLUMN_NAME = '%s'\n", p);
  break;
 case 3:
  value = (parse_ok) ? stmt->fi[icol]->length : pgtype_length(stmt, field_type, icol, unknown_sizes);
  mylog("SQLColAttributes: col %d, length = %d\n", icol, value);
        break;
 case 9:
  value = pgtype_money(stmt, field_type);
  break;
 case 7:
  value = (parse_ok) ? stmt->fi[icol]->nullable : pgtype_nullable(stmt, field_type);
  break;
 case 16:
  p = "";
  break;
 case 4:
  value = (parse_ok) ? stmt->fi[icol]->precision : pgtype_precision(stmt, field_type, icol, unknown_sizes);
  mylog("SQLColAttributes: col %d, precision = %d\n", icol, value);
        break;
 case 17:
  p = "";
  break;
 case 5:
  value = pgtype_scale(stmt, field_type, icol);
  break;
 case 13:
  value = pgtype_searchable(stmt, field_type);
  break;
    case 15:
  p = (parse_ok && stmt->fi[icol]->ti) ? stmt->fi[icol]->ti->name : "";
  mylog("SQLColAttr: TABLE_NAME = '%s'\n", p);
        break;
 case 2:
  value = pgtype_to_sqltype(stmt, field_type);
  break;
 case 14:
  p = pgtype_to_name(stmt, field_type);
  break;
 case 8:
  value = pgtype_unsigned(stmt, field_type);
  if(value == -1)
   value = (int)1;
  break;
 case 10:
  value = 1;
  mylog("SQLColAttr: UPDATEABLE = %d\n", value);
  break;
    }
 result = 0;
 if (p) {
  len = strlen(p);
  if (rgbDesc) {
   strncpy_null((char *)rgbDesc, p, (size_t)cbDescMax);
   if (len >= cbDescMax) {
    result = 1;
    SC_set_error(stmt, -2, "The buffer was too small for the result.");
   }
  }
  if (pcbDesc)
   *pcbDesc = len;
 }
 else {
  if (pfDesc)
   *pfDesc = value;
 }
    return result;
}

canonical_original_code:
short SQLColAttributes(void *hstmt, unsigned short icol, unsigned short fDescType, void *rgbDesc, short cbDescMax, short *pcbDesc, long *pfDesc)
{
static char *func = "SQLColAttributes";
struct StatementClass_ *stmt = (StatementClass *) hstmt;
int field_type = 0;
struct ConnInfo *ci;
int unknown_sizes;
int cols = 0;
char parse_ok;
short result;
char *p = ((void *)0);
int len = 0; int value = 0;
 mylog("%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 ci = &(stmt->hdbc->connInfo);
 icol--;
 unknown_sizes = globals.unknown_sizes;
 if (unknown_sizes == 1)
  unknown_sizes = 0;
 parse_ok = (int)0;
 if (globals.parse && stmt->statement_type == STMT_TYPE_SELECT) {
  if (stmt->parse_status == STMT_PARSE_NONE) {
   mylog("SQLColAttributes: calling parse_statement\n");
   parse_statement(stmt);
  }
  cols = stmt->nfld;
  if (fDescType == 0) {
   if (pfDesc)
    *pfDesc = cols;
   return 0;
  }
  if (stmt->parse_status != STMT_PARSE_FATAL && stmt->fi && stmt->fi[icol]) {
   if (icol >= cols) {
    SC_set_error(stmt, 13, "Invalid column number in DescribeCol.");
    SC_log_error(func, "", stmt);
    return (-1);
   }
   field_type = stmt->fi[icol]->type;
   if (field_type > 0)
    parse_ok = (int)1;
  }
 }
 if ( ! parse_ok) {
  SC_pre_execute(stmt);
  mylog("**** SQLColAtt: result = %u, status = %d, numcols = %d\n", stmt->result, stmt->status, stmt->result != ((void *)0) ? (((stmt->result->fields) ? (stmt->result->fields->num_fields) : (-1))) : -1);
  if ( (((void *)0) == stmt->result) || ((stmt->status != STMT_FINISHED) && (stmt->status != STMT_PREMATURE)) ) {
   SC_set_error(stmt, 3, "Can't get column attributes: no result found.");
   SC_log_error(func, "", stmt);
   return (-1);
  }
  cols = (((stmt->result->fields) ? (stmt->result->fields->num_fields) : (-1)));
  if (fDescType == 0) {
   if (pfDesc)
    *pfDesc = cols;
   return 0;
  }
  if (icol >= cols) {
   SC_set_error(stmt, 13, "Invalid column number in DescribeCol.");
   SC_log_error(func, "", stmt);
   return (-1);
  }
  field_type = ((stmt->result->fields->adtid[icol]));
 }
 mylog("colAttr: col %d field_type = %d\n", icol, field_type);
 switch(fDescType) {
 case 11:
  value = pgtype_auto_increment(stmt, field_type);
  if (value == -1)
   value = (int)0;
  break;
 case 12:
  value = pgtype_case_sensitive(stmt, field_type);
  break;
    case 6:
  value = (parse_ok) ? stmt->fi[icol]->display_size : pgtype_display_size(stmt, field_type, icol, unknown_sizes);
  mylog("SQLColAttributes: col %d, display_size= %d\n", icol, value);
        break;
 case 18:
  if (parse_ok && stmt->fi[icol]->alias[0] != '\0') {
   p = stmt->fi[icol]->alias;
   mylog("SQLColAttr: COLUMN_LABEL = '%s'\n", p);
   break;
  }
 case 1:
  p = (parse_ok) ? stmt->fi[icol]->name : ((stmt->result->fields->name[icol]));
  mylog("SQLColAttr: COLUMN_NAME = '%s'\n", p);
  break;
 case 3:
  value = (parse_ok) ? stmt->fi[icol]->length : pgtype_length(stmt, field_type, icol, unknown_sizes);
  mylog("SQLColAttributes: col %d, length = %d\n", icol, value);
        break;
 case 9:
  value = pgtype_money(stmt, field_type);
  break;
 case 7:
  value = (parse_ok) ? stmt->fi[icol]->nullable : pgtype_nullable(stmt, field_type);
  break;
 case 16:
  p = "";
  break;
 case 4:
  value = (parse_ok) ? stmt->fi[icol]->precision : pgtype_precision(stmt, field_type, icol, unknown_sizes);
  mylog("SQLColAttributes: col %d, precision = %d\n", icol, value);
        break;
 case 17:
  p = "";
  break;
 case 5:
  value = pgtype_scale(stmt, field_type, icol);
  break;
 case 13:
  value = pgtype_searchable(stmt, field_type);
  break;
    case 15:
  p = (parse_ok && stmt->fi[icol]->ti) ? stmt->fi[icol]->ti->name : "";
  mylog("SQLColAttr: TABLE_NAME = '%s'\n", p);
        break;
 case 2:
  value = pgtype_to_sqltype(stmt, field_type);
  break;
 case 14:
  p = pgtype_to_name(stmt, field_type);
  break;
 case 8:
  value = pgtype_unsigned(stmt, field_type);
  if(value == -1)
   value = (int)1;
  break;
 case 10:
  value = 1;
  mylog("SQLColAttr: UPDATEABLE = %d\n", value);
  break;
    }
 result = 0;
 if (p) {
  len = strlen(p);
  if (rgbDesc) {
   strncpy_null((char *)rgbDesc, p, (unsigned long)cbDescMax);
   if (len >= cbDescMax) {
    result = 1;
    SC_set_error(stmt, -2, "The buffer was too small for the result.");
   }
  }
  if (pcbDesc)
   *pcbDesc = len;
 }
 else {
  if (pfDesc)
   *pfDesc = value;
 }
    return result;
}

variable_types:
hstmt
void *

variable_types:
icol
unsigned short

variable_types:
fDescType
unsigned short

variable_types:
rgbDesc
void *

variable_types: cbDescMax short

variable_types:
pcbDesc
short *

variable_types:
pfDesc
long *

variable_types: struct StatementClass_ { struct ConnectionClass_ { void *henv; struct StatementOptions_ { int maxRows; int maxLength; int rowset_size; int keyset_size; int cursor_type; int scroll_concurrency; int retrieve_data; int bind_size; int use_bookmarks; } stmtOptions; char *__error_message; int __error_number; enum CONN_Status { CONN_NOT_CONNECTED=0, CONN_CONNECTED=1, CONN_DOWN=2, CONN_EXECUTING=3 } status; struct ConnInfo { char dsn[256]; char desc[256]; char driver[256]; char server[256]; char database[256]; char username[256]; char password[256]; char conn_settings[4096]; char protocol[10]; char port[10]; char uds[4096]; char onlyread[10]; char fake_oid_index[10]; char show_oid_column[10]; char row_versioning[10]; char show_system_tables[10]; char translation_dll[256]; char translation_option[10]; char focus_password; } connInfo; struct StatementClass_ **stmts; int num_stmts; struct SocketClass_ { int buffer_filled_in; int buffer_filled_out; int buffer_read_in; unsigned char *buffer_in; unsigned char *buffer_out; int socket; char *errormsg; int errornumber; char reverse; } *sock; int lobj_type; int ntables; struct col_info { struct QResultClass_ { struct ColumnInfoClass_ { short num_fields; char **name; unsigned int *adtid; short *adtsize; short *display_size; int *atttypmod; } *fields; struct TupleListClass_ { int num_fields; int num_tuples; struct TupleNode_ { struct TupleNode_ *prev; struct TupleField_ { int len; void *value; } tuple[1]; } *list_start; int last_indexed; } *manual_tuples; struct ConnectionClass_ *conn; int fetch_count; int fcount; int currTuple; int base; int num_fields; int cache_size; int rowset_size; enum QueryResultCode_ { PGRES_EMPTY_QUERY=0, PGRES_COMMAND_OK=1, PGRES_TUPLES_OK=2, PGRES_COPY_OUT=3, PGRES_COPY_IN=4, PGRES_BAD_RESPONSE=5, PGRES_NONFATAL_ERROR=6, PGRES_FATAL_ERROR=7, PGRES_FIELDS_OK=8, PGRES_END_TUPLES=9, PGRES_INTERNAL_ERROR=10 } status; char *message; char *cursor; char *command; char *notice; struct TupleField_ *backend_tuples; struct TupleField_ *tupleField; char inTuples; char aborted; } *result; char name[-1]; } **col_info; long translation_option; void *translation_handle; int (*DataSourceToDriver)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); int (*DriverToDataSource)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); short driver_version; char transact_status; char errormsg_created; char pg_version[128]; float pg_version_number; short pg_version_major; short pg_version_minor; char ms_jet; char unicode; char result_uncommitted; char schema_support; char *client_encoding; char *server_encoding; int ccsc; int be_pid; int be_key; unsigned int isolation; char *current_schema; int num_discardp; char **discardp; } *hdbc; struct QResultClass_ *result; void **phstmt; struct StatementOptions_ options; enum STMT_Status { STMT_ALLOCATED=0, STMT_READY=1, STMT_PREMATURE=2, STMT_FINISHED=3, STMT_EXECUTING=4 } status; char *__error_message; int __error_number; struct BindInfoClass_ { int buflen; int data_left; char *buffer; long *used; short returntype; } *bindings; struct BindInfoClass_ bookmark; int bindings_allocated; int parameters_allocated; struct ParameterInfoClass_ { int buflen; char *buffer; long *used; short paramType; short CType; short SQLType; unsigned int precision; short scale; unsigned int lobj_oid; int *EXEC_used; char *EXEC_buffer; char data_at_exec; } *parameters; int currTuple; int save_rowset_size; int rowset_start; int bind_row; int last_fetch_count; int current_col; int lobj_fd; char *statement; struct TABLE_INFO { struct col_info *col_info; char name[-1]; char alias[-1]; } **ti; struct FIELD_INFO { struct TABLE_INFO *ti; int precision; int display_size; int length; int type; char nullable; char func; char expr; char quote; char dquote; char numeric; char dot[-1]; char name[-1]; char alias[-1]; } **fi; int nfld; int ntab; int parse_status; int statement_type; int data_at_exec; int current_exec_param; char put_data; char errormsg_created; char manual_result; char prepare; char internal; char cursor_name[-1]; char stmt_with_params[65536]; int reexecute; } *

variable_types: struct ConnInfo { char dsn[256]; char desc[256]; char driver[256]; char server[256]; char database[256]; char username[256]; char password[256]; char conn_settings[4096]; char protocol[10]; char port[10]; char uds[4096]; char onlyread[10]; char fake_oid_index[10]; char show_oid_column[10]; char row_versioning[10]; char show_system_tables[10]; char translation_dll[256]; char translation_option[10]; char focus_password; } *

variable_types: cols int

variable_types:
p
char *

variable_types: value int

user_defined_types: struct col_info { struct QResultClass_ *result; char name[-1]; }


SQLGetTranslatorW

decompiled_code:
// attributes: thunk
__int64 SQLGetTranslatorW()
{
return SQLGetTranslator_localalias();
}

canonical_decompiled_code:
__int64 func1()
{
return func0();
}

original_code:
int SQLGetTranslatorW (HWND hwnd,
                                      LPWSTR lpszName,
                                      WORD cbNameMax,
                                      WORD *pcbNameOut,
                                      LPWSTR lpszPath,
                                      WORD cbPathMax,
                                      WORD *pcbPathOut,
                                      DWORD *pvOption)
{
    inst_logClear();
 return 0;
}

canonical_original_code:
int SQLGetTranslatorW(void *hwnd, unsigned short *lpszName, unsigned short cbNameMax, unsigned short *pcbNameOut, unsigned short *lpszPath, unsigned short cbPathMax, unsigned short *pcbPathOut, unsigned long *pvOption)
{
    inst_logClear();
 return 0;
}

variable_types:
hwnd
void *

variable_types:
lpszName
unsigned short *

variable_types:
cbNameMax
unsigned short

variable_types:
pcbNameOut
unsigned short *

variable_types:
lpszPath
unsigned short *

variable_types:
cbPathMax
unsigned short

variable_types:
pcbPathOut
unsigned short *

variable_types:
pvOption
unsigned long *


SQLRemoveDriverManager

decompiled_code:
__int64 __fastcall SQLRemoveDriverManager(_QWORD *a1)
{
__int64 result; // rax

inst_logClear();
if ( a1 )
{
*a1 = 1LL;
result = 1LL;
}
else
{
inst_logPushMsg("SQLRemoveDriverManager.c", "SQLRemoveDriverManager.c", 20LL, 2LL, 1LL, &LC0);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 result; // rax

inst_logClear();
if ( a1 )
{
*a1 = 1LL;
result = 1LL;
}
else
{
inst_logPushMsg("SQLRemoveDriverManager.c", "SQLRemoveDriverManager.c", 20LL, 2LL, 1LL, &LC0);
result = 0LL;
}
return result;
}

original_code:
int SQLRemoveDriverManager( LPDWORD pnUsageCount )
{
    inst_logClear();
 if ( pnUsageCount == ((void *)0) )
 {
        inst_logPushMsg( "SQLRemoveDriverManager.c", "SQLRemoveDriverManager.c", 20, 2, 1, "" );
  return 0;
 }
 *pnUsageCount = 1;
 return 1;
}

canonical_original_code:
int SQLRemoveDriverManager(unsigned long *pnUsageCount)
{
    inst_logClear();
 if ( pnUsageCount == ((void *)0) )
 {
        inst_logPushMsg( "SQLRemoveDriverManager.c", "SQLRemoveDriverManager.c", 20, 2, 1, "" );
  return 0;
 }
 *pnUsageCount = 1;
 return 1;
}

variable_types:
pnUsageCount
unsigned long *


SQLGetDescField

decompiled_code:
__int64 SQLGetDescField()
{
return 0xFFFFFFFFLL;
}

original_code:
SQLRETURN SQLGetDescField( SQLHDESC DescriptorHandle,
                             SQLSMALLINT RecordNumber,
                             SQLSMALLINT FieldIdentifier,
                             SQLPOINTER Value,
                             SQLINTEGER BufferLength,
                             SQLINTEGER *StringLength
                          )
{
    return (-1);
}

canonical_original_code:
short SQLGetDescField(void *DescriptorHandle, short RecordNumber, short FieldIdentifier, void *Value, long BufferLength, long *StringLength)
{
    return (-1);
}

variable_types:
DescriptorHandle
void *

variable_types: RecordNumber short

variable_types: FieldIdentifier short

variable_types:
Value
void *

variable_types: BufferLength long

variable_types:
StringLength
long *


SQLCreateDataSourceW

decompiled_code:
__int64 __fastcall SQLCreateDataSourceW(__int64 a1, __int64 a2)
{
_BYTE *v2; // rbp
unsigned int v3; // er12

v2 = multi_string_alloc_and_copy(a2);
inst_logClear();
v3 = SQLCreateDataSource(a1, (__int64)v2);
free(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
_BYTE *v2; // rbp
unsigned int v3; // er12

v2 = multi_string_alloc_and_copy(a2);
inst_logClear();
v3 = func4(a1, (__int64)v2);
free(v2);
return v3;
}

original_code:
int SQLCreateDataSourceW( HWND hwndParent, LPCWSTR lpszDSN )
{
    int ret;
    char *ms = _multi_string_alloc_and_copy( lpszDSN );
    inst_logClear();
    ret = SQLCreateDataSource( hwndParent, ms );
    free( ms );
    return ret;
}

canonical_original_code:
int SQLCreateDataSourceW(void *hwndParent, unsigned short *lpszDSN)
{
    int ret;
    char *ms = _multi_string_alloc_and_copy( lpszDSN );
    inst_logClear();
    ret = SQLCreateDataSource( hwndParent, ms );
    free( ms );
    return ret;
}

variable_types:
hwndParent
void *

variable_types:
lpszDSN
unsigned short *

variable_types: ret int

variable_types:
ms
char *


SQLGetAvailableDrivers

decompiled_code:
__int64 __fastcall SQLGetAvailableDrivers(__int64 a1, __int64 a2, unsigned __int16 a3, __int64 a4)
{
return SQLGetInstalledDrivers(a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned __int16 a3, __int64 a4)
{
return SQLGetInstalledDrivers(a2, a3, a4);
}

original_code:
int SQLGetAvailableDrivers( LPCSTR pszInfFile,
        LPSTR pszBuf,
        WORD nBufMax,
        WORD *pnBufOut)
{
 return SQLGetInstalledDrivers( pszBuf, nBufMax, pnBufOut );
}

canonical_original_code:
int SQLGetAvailableDrivers(char *pszInfFile, char *pszBuf, unsigned short nBufMax, unsigned short *pnBufOut)
{
 return SQLGetInstalledDrivers( pszBuf, nBufMax, pnBufOut );
}

variable_types:
pszInfFile
char *

variable_types:
pszBuf
char *

variable_types:
nBufMax
unsigned short

variable_types:
pnBufOut
unsigned short *


SQLGetAvailableDriversW

decompiled_code:
__int64 __fastcall SQLGetAvailableDriversW(__int64 a1, __int64 a2, unsigned __int16 a3, __int64 a4)
{
return SQLGetInstalledDriversW(a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned __int16 a3, __int64 a4)
{
return SQLGetInstalledDriversW(a2, a3, a4);
}

original_code:
int SQLGetAvailableDriversW (LPCWSTR lpszInfFile,
                                      LPWSTR lpszBuf,
                                      WORD cbBufMax,
                                      WORD * pcbBufOut)
{
 return SQLGetInstalledDriversW( lpszBuf, cbBufMax, pcbBufOut );
}

canonical_original_code:
int SQLGetAvailableDriversW(unsigned short *lpszInfFile, unsigned short *lpszBuf, unsigned short cbBufMax, unsigned short *pcbBufOut)
{
 return SQLGetInstalledDriversW( lpszBuf, cbBufMax, pcbBufOut );
}

variable_types:
lpszInfFile
unsigned short *

variable_types:
lpszBuf
unsigned short *

variable_types:
cbBufMax
unsigned short

variable_types:
pcbBufOut
unsigned short *


SQLInstallTranslatorExW

decompiled_code:
// attributes: thunk
__int64 SQLInstallTranslatorExW()
{
return SQLInstallTranslatorEx_localalias();
}

original_code:
int SQLInstallTranslatorExW(LPCWSTR lpszTranslator,
                                  LPCWSTR lpszPathIn,
                                  LPWSTR lpszPathOut,
                                  WORD cbPathOutMax,
                                  WORD *pcbPathOut,
                                  WORD fRequest,
                                  LPDWORD lpdwUsageCount)
{
    inst_logClear();
 return 0;
}

canonical_original_code:
int SQLInstallTranslatorExW(unsigned short *lpszTranslator, unsigned short *lpszPathIn, unsigned short *lpszPathOut, unsigned short cbPathOutMax, unsigned short *pcbPathOut, unsigned short fRequest, unsigned long *lpdwUsageCount)
{
    inst_logClear();
 return 0;
}

variable_types:
lpszTranslator
unsigned short *

variable_types:
lpszPathIn
unsigned short *

variable_types:
lpszPathOut
unsigned short *

variable_types:
cbPathOutMax
unsigned short

variable_types:
pcbPathOut
unsigned short *

variable_types:
fRequest
unsigned short

variable_types:
lpdwUsageCount
unsigned long *


SQLInstallDriverExW

decompiled_code:
__int64 __fastcall SQLInstallDriverExW(void *ptr, void *a2, __int64 a3, unsigned __int16 a4, _WORD *a5, __int16 a6, __int64 a7)
{
char *v7; // r15
void *v11; // rbp
__int16 v13; // r9
char *v14; // rbx
unsigned int v15; // er12
__int16 v17; // [rsp+Ch] [rbp-4Ch]
__int16 v18[29]; // [rsp+1Eh] [rbp-3Ah] BYREF

v7 = (char *)a2;
v11 = ptr;
inst_logClear();
if ( ptr )
v11 = (void *)multi_string_alloc_and_copy(ptr);
if ( a2 )
v7 = (char *)single_string_alloc_and_copy(a2);
v13 = a6;
if ( a4 && a3 )
{
v17 = a6;
v14 = (char *)calloc(a4 + 1, 1uLL);
v15 = SQLInstallDriverEx((__int64)v11, v7, v14, a4, v18, v17, (_QWORD *)a7);
if ( v15 && v14 )
single_copy_to_wide(a3, v14, (unsigned int)(unsigned __int16)v18[0] + 1);
}
else
{
v14 = 0LL;
v15 = SQLInstallDriverEx((__int64)v11, v7, 0LL, a4, v18, v13, (_QWORD *)a7);
}
if ( a5 )
*a5 = v18[0];
if ( v11 )
free(v11);
if ( v7 )
free(v7);
if ( v14 )
free(v14);
return v15;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr, void *a2, __int64 a3, unsigned __int16 a4, _WORD *a5, __int16 a6, __int64 a7)
{
char *v7; // r15
void *v11; // rbp
__int16 v13; // r9
char *v14; // rbx
unsigned int v15; // er12
__int16 v17; // [rsp+Ch] [rbp-4Ch]
__int16 v18[29]; // [rsp+1Eh] [rbp-3Ah] BYREF

v7 = (char *)a2;
v11 = ptr;
inst_logClear();
if ( ptr )
v11 = (void *)multi_string_alloc_and_copy(ptr);
if ( a2 )
v7 = (char *)single_string_alloc_and_copy(a2);
v13 = a6;
if ( a4 && a3 )
{
v17 = a6;
v14 = (char *)calloc(a4 + 1, 1uLL);
v15 = func0((__int64)v11, v7, v14, a4, v18, v17, (_QWORD *)a7);
if ( v15 && v14 )
single_copy_to_wide(a3, v14, (unsigned int)(unsigned __int16)v18[0] + 1);
}
else
{
v14 = 0LL;
v15 = func0((__int64)v11, v7, 0LL, a4, v18, v13, (_QWORD *)a7);
}
if ( a5 )
*a5 = v18[0];
if ( v11 )
free(v11);
if ( v7 )
free(v7);
if ( v14 )
free(v14);
return v15;
}

original_code:
int SQLInstallDriverExW(LPCWSTR lpszDriver,
                             LPCWSTR lpszPathIn,
                             LPWSTR lpszPathOut,
                             WORD cbPathOutMax,
                             WORD *pcbPathOut,
                             WORD fRequest,
                             LPDWORD lpdwUsageCount)
{
 char *drv;
 char *pth;
 char *pout;
 WORD len;
 int ret;
    inst_logClear();
 drv = lpszDriver ? _multi_string_alloc_and_copy( lpszDriver ) : (char*)((void *)0);
 pth = lpszPathIn ? _single_string_alloc_and_copy( lpszPathIn ) : (char*)((void *)0);
 if ( lpszPathOut )
 {
  if ( cbPathOutMax > 0 )
  {
   pout = calloc( cbPathOutMax + 1, 1 );
  }
  else
  {
   pout = ((void *)0);
  }
 }
 else
 {
  pout = ((void *)0);
 }
 ret = SQLInstallDriverEx( drv, pth, pout, cbPathOutMax, &len, fRequest, lpdwUsageCount );
 if ( ret )
 {
  if ( pout && lpszPathOut )
  {
   _single_copy_to_wide( lpszPathOut, pout, len + 1 );
  }
 }
 if ( pcbPathOut )
 {
  *pcbPathOut = len;
 }
 if ( drv )
  free( drv );
 if ( pth )
  free( pth );
 if ( pout )
  free( pout );
 return ret;
}

canonical_original_code:
int SQLInstallDriverExW(unsigned short *lpszDriver, unsigned short *lpszPathIn, unsigned short *lpszPathOut, unsigned short cbPathOutMax, unsigned short *pcbPathOut, unsigned short fRequest, unsigned long *lpdwUsageCount)
{
 char *drv;
 char *pth;
 char *pout;
 unsigned short len;
 int ret;
    inst_logClear();
 drv = lpszDriver ? _multi_string_alloc_and_copy( lpszDriver ) : (char *)((void *)0);
 pth = lpszPathIn ? _single_string_alloc_and_copy( lpszPathIn ) : (char *)((void *)0);
 if ( lpszPathOut )
 {
  if ( cbPathOutMax > 0 )
  {
   pout = calloc( cbPathOutMax + 1, 1 );
  }
  else
  {
   pout = ((void *)0);
  }
 }
 else
 {
  pout = ((void *)0);
 }
 ret = SQLInstallDriverEx( drv, pth, pout, cbPathOutMax, &len, fRequest, lpdwUsageCount );
 if ( ret )
 {
  if ( pout && lpszPathOut )
  {
   _single_copy_to_wide( lpszPathOut, pout, len + 1 );
  }
 }
 if ( pcbPathOut )
 {
  *pcbPathOut = len;
 }
 if ( drv )
  free( drv );
 if ( pth )
  free( pth );
 if ( pout )
  free( pout );
 return ret;
}

variable_types:
lpszDriver
unsigned short *

variable_types:
drv
char *

variable_types:
pth
char *

variable_types:
pout
char *

variable_types:
len
unsigned short

variable_types: ret int


repo: xiaq/hlwm

decompiled_code:
bool __fastcall memberequals_settingspair(const char **a1, __int64 a2)
{
bool result; // al

if ( *(_DWORD *)(a2 + 20) == 1 )
result = *(_DWORD *)(a2 + 8) == atoi(*a1);
else
result = strcmp(*(const char **)(a2 + 8), *a1) == 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func0(const char **a1, __int64 a2)
{
bool result; // al

if ( *(_DWORD *)(a2 + 20) == 1 )
result = *(_DWORD *)(a2 + 8) == atoi(*a1);
else
result = strcmp(*(const char **)(a2 + 8), *a1) == 0;
return result;
}

original_code:
_Bool memberequals_settingspair(void* pmember, void* needle) {
    char* str = *(char**)pmember;
    SettingsPair* pair = needle;
    if (pair->type == HS_Int) {
        return pair->value.i == atoi(str);
    } else {
        return !strcmp(pair->value.s, str);
    }
}

canonical_original_code:
_Bool memberequals_settingspair(void *pmember, void *needle) {
    char *str = *(char**)pmember;
    struct SettingsPair *pair = needle;
    if (pair->type == HS_Int) {
        return pair->value.i == atoi(str);
    } else {
        return !strcmp(pair->value.s, str);
    }
}

variable_types:
pmember
void *

variable_types:
needle
void *

variable_types:
str
char *

variable_types: struct SettingsPair { char *name; union { int i; char *s; } value; int old_value_i; int type; void (*on_change)(); } *


decompiled_code:
__int64 settings_count()
{
return 38LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 38LL;
}

original_code:
int settings_count() {
    return (sizeof(g_settings)/sizeof(*g_settings));
}


decompiled_code:
__int64 settings_destroy()
{
__int64 v0; // rbx
__int64 result; // rax
char *v2; // rdi

v0 = (unsigned int)((_DWORD)&g_settings + 8);
do
{
while ( 1 )
{
result = *(unsigned int *)(v0 + 12);
if ( !(_DWORD)result )
break;
v0 += 32LL;
if ( (char **)v0 == &g_settings + 153 )
return result;
}
v2 = *(char **)v0;
v0 += 32LL;
result = g_free(v2);
}
while ( (char **)v0 != &g_settings + 153 );
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx
__int64 result; // rax
char *v2; // rdi

v0 = (unsigned int)((_DWORD)&g_settings + 8);
do
{
while ( 1 )
{
result = *(unsigned int *)(v0 + 12);
if ( !(_DWORD)result )
break;
v0 += 32LL;
if ( (char **)v0 == &g_settings + 153 )
return result;
}
v2 = *(char **)v0;
v0 += 32LL;
result = g_free(v2);
}
while ( (char **)v0 != &g_settings + 153 );
return result;
}

original_code:
void settings_destroy() {
    int i;
    for (i = 0; i < (sizeof(g_settings)/sizeof(*g_settings)); i++) {
        if (g_settings[i].type == HS_String) {
            g_free(g_settings[i].value.s);
        }
    }
}

variable_types: i int

return_type: void


decompiled_code:
__int64 __fastcall settings_find(__int64 a1)
{
return table_find(&g_settings, 32LL, 38LL, 0LL, &memberequals_string, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return table_find(&g_settings, 32LL, 38LL, 0LL, &memberequals_string, a1);
}

original_code:
SettingsPair* settings_find(char* name) {
    return ((SettingsPair*) table_find((g_settings), sizeof(g_settings[0]), (sizeof((g_settings))/sizeof(*(g_settings))), __builtin_offsetof (SettingsPair, name), memberequals_string, (name)));
}

canonical_original_code:
struct SettingsPair *settings_find(char *name) {
    return ((struct SettingsPair *) table_find((g_settings), sizeof(g_settings[0]), (sizeof((g_settings))/sizeof(*(g_settings))), __builtin_offsetof (SettingsPair, name), memberequals_string, (name)));
}

variable_types:
name
char *

return_type: struct SettingsPair { char *name; union { int i; char *s; } value; int old_value_i; int type; void (*on_change)(); } *


decompiled_code:
__int64 settings_init()
{
char **v0; // rbx
int v1; // eax
__int64 result; // rax

v0 = (char **)(unsigned int)((_DWORD)&g_settings + 8);
do
{
v1 = *((_DWORD *)v0 + 3);
if ( !v1 )
{
*v0 = (char *)g_strdup(*v0);
v1 = *((_DWORD *)v0 + 3);
}
if ( v1 == 1 )
*((_DWORD *)v0 + 2) = 1;
v0 += 4;
}
while ( v0 != &g_settings + 153 );
result = settings_find((__int64)"monitors_locked");
*(_DWORD *)(result + 8) = g_initial_monitors_locked;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
char **v0; // rbx
int v1; // eax
__int64 result; // rax

v0 = (char **)(unsigned int)((_DWORD)&g_settings + 8);
do
{
v1 = *((_DWORD *)v0 + 3);
if ( !v1 )
{
*v0 = (char *)g_strdup(*v0);
v1 = *((_DWORD *)v0 + 3);
}
if ( v1 == 1 )
*((_DWORD *)v0 + 2) = 1;
v0 += 4;
}
while ( v0 != &g_settings + 153 );
result = func3((__int64)"monitors_locked");
*(_DWORD *)(result + 8) = g_initial_monitors_locked;
return result;
}

original_code:
void settings_init() {
    int i;
    for (i = 0; i < (sizeof(g_settings)/sizeof(*g_settings)); i++) {
        if (g_settings[i].type == HS_String) {
            g_settings[i].value.s = g_strdup(g_settings[i].value.s);
        }
        if (g_settings[i].type == HS_Int) {
            g_settings[i].old_value_i = 1;
        }
    }
    settings_find("monitors_locked")->value.i = g_initial_monitors_locked;
}


decompiled_code:
__int64 __fastcall settings_set(__int64 a1, const char *a2)
{
const char *v2; // r12
__int64 result; // rax
void (*v4)(void); // rdx
int v5; // er8
int v6; // [rsp+Ch] [rbp-1Ch] BYREF

if ( *(_DWORD *)(a1 + 20) != 1 )
{
v2 = *(const char **)(a1 + 8);
if ( !strcmp(v2, a2) )
return 0LL;
g_free(v2);
*(_QWORD *)(a1 + 8) = g_strdup(a2);
LABEL_6:
v4 = *(void (**)(void))(a1 + 24);
if ( v4 )
v4();
return 0LL;
}
v5 = _isoc99_sscanf(a2, "%d", &v6);
result = 3LL;
if ( v5 == 1 )
{
result = 0LL;
if ( *(_DWORD *)(a1 + 8) != v6 )
{
*(_DWORD *)(a1 + 8) = v6;
goto LABEL_6;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2)
{
const char *v2; // r12
__int64 result; // rax
void (*v4)(void); // rdx
int v5; // er8
int v6; // [rsp+Ch] [rbp-1Ch] BYREF

if ( *(_DWORD *)(a1 + 20) != 1 )
{
v2 = *(const char **)(a1 + 8);
if ( !strcmp(v2, a2) )
return 0LL;
g_free(v2);
*(_QWORD *)(a1 + 8) = g_strdup(a2);
LABEL_6:
v4 = *(void (**)(void))(a1 + 24);
if ( v4 )
v4();
return 0LL;
}
v5 = _isoc99_sscanf(a2, "%d", &v6);
result = 3LL;
if ( v5 == 1 )
{
result = 0LL;
if ( *(_DWORD *)(a1 + 8) != v6 )
{
*(_DWORD *)(a1 + 8) = v6;
goto LABEL_6;
}
}
return result;
}

original_code:
int settings_set(SettingsPair* pair, char* value) {
    if (pair->type == HS_Int) {
        int new_value;
        if (1 == sscanf(value, "%d", &new_value)) {
            if (new_value == pair->value.i) {
                return 0;
            }
            pair->value.i = new_value;
        } else {
            return HERBST_INVALID_ARGUMENT;
        }
    } else {
        if (!strcmp(pair->value.s, value)) {
            return 0;
        }
        g_free(pair->value.s);
        pair->value.s = g_strdup(value);
    }
    if (pair->on_change) {
        pair->on_change();
    }
    return 0;
}

canonical_original_code:
int settings_set(struct SettingsPair *pair, char *value) {
    if (pair->type == HS_Int) {
        int new_value;
        if (1 == sscanf(value, "%d", &new_value)) {
            if (new_value == pair->value.i) {
                return 0;
            }
            pair->value.i = new_value;
        } else {
            return HERBST_INVALID_ARGUMENT;
        }
    } else {
        if (!strcmp(pair->value.s, value)) {
            return 0;
        }
        g_free(pair->value.s);
        pair->value.s = g_strdup(value);
    }
    if (pair->on_change) {
        pair->on_change();
    }
    return 0;
}

variable_types:
value
char *

user_defined_types: struct SettingsPair { char *name; union { int i; char *s; } value; int old_value_i; int type; void (*on_change)(); }


decompiled_code:
__int64 __fastcall settings_set_command(int a1, const char **a2, __int64 a3)
{
unsigned int v3; // er12
__int64 v5; // rdi

v3 = 9;
if ( a1 <= 2 )
return v3;
v5 = settings_find((__int64)a2[1]);
if ( !v5 )
{
v3 = 4;
if ( a3 )
g_string_append_printf(a3, "%s: Setting \"%s\" not found\n", *a2, a2[1]);
return v3;
}
v3 = settings_set(v5, a2[2]);
if ( v3 != 3 )
return v3;
g_string_append_printf(a3, "%s: Invalid value for setting \"%s\"\n", *a2, a2[1]);
return 3LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, const char **a2, __int64 a3)
{
unsigned int v3; // er12
__int64 v5; // rdi

v3 = 9;
if ( a1 <= 2 )
return v3;
v5 = func3((__int64)a2[1]);
if ( !v5 )
{
v3 = 4;
if ( a3 )
g_string_append_printf(a3, "%s: Setting \"%s\" not found\n", *a2, a2[1]);
return v3;
}
v3 = func5(v5, a2[2]);
if ( v3 != 3 )
return v3;
g_string_append_printf(a3, "%s: Invalid value for setting \"%s\"\n", *a2, a2[1]);
return 3LL;
}

original_code:
int settings_set_command(int argc, char** argv, GString* output) {
    if (argc < 3) {
        return HERBST_NEED_MORE_ARGS;
    }
    SettingsPair* pair = settings_find(argv[1]);
    if (!pair) {
        if (output != ((void *)0)) {
            g_string_append_printf(output,
                "%s: Setting \"%s\" not found\n", argv[0], argv[1]);
        }
        return HERBST_SETTING_NOT_FOUND;
    }
    int ret = settings_set(pair, argv[2]);
    if (ret == HERBST_INVALID_ARGUMENT) {
        g_string_append_printf(output,
            "%s: Invalid value for setting \"%s\"\n", argv[0], argv[1]);
    }
    return ret;
}

canonical_original_code:
int settings_set_command(int argc, char **argv, struct _GString *output) {
    if (argc < 3) {
        return HERBST_NEED_MORE_ARGS;
    }
    struct SettingsPair *pair = settings_find(argv[1]);
    if (!pair) {
        if (output != ((void *)0)) {
            g_string_append_printf(output,
                "%s: Setting \"%s\" not found\n", argv[0], argv[1]);
        }
        return HERBST_SETTING_NOT_FOUND;
    }
    int ret = settings_set(pair, argv[2]);
    if (ret == HERBST_INVALID_ARGUMENT) {
        g_string_append_printf(output,
            "%s: Invalid value for setting \"%s\"\n", argv[0], argv[1]);
    }
    return ret;
}

variable_types: argc int

variable_types:
argv
char **

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


decompiled_code:
__int64 __fastcall settings_get(int a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rax

result = 9LL;
if ( a1 > 1 )
{
v5 = settings_find(*(_QWORD *)(a2 + 8));
if ( v5 )
{
if ( *(_DWORD *)(v5 + 20) == 1 )
{
g_string_append_printf(a3, "%d", *(unsigned int *)(v5 + 8));
result = 0LL;
}
else
{
g_string_append(a3, *(_QWORD *)(v5 + 8));
result = 0LL;
}
}
else
{
g_string_append_printf(a3, "%s: Setting \"%s\" not found\n", *(const char **)a2, *(const char **)(a2 + 8));
result = 4LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rax

result = 9LL;
if ( a1 > 1 )
{
v5 = func3(*(_QWORD *)(a2 + 8));
if ( v5 )
{
if ( *(_DWORD *)(v5 + 20) == 1 )
{
g_string_append_printf(a3, "%d", *(unsigned int *)(v5 + 8));
result = 0LL;
}
else
{
g_string_append(a3, *(_QWORD *)(v5 + 8));
result = 0LL;
}
}
else
{
g_string_append_printf(a3, "%s: Setting \"%s\" not found\n", *(const char **)a2, *(const char **)(a2 + 8));
result = 4LL;
}
}
return result;
}

original_code:
int settings_get(int argc, char** argv, GString* output) {
    if (argc < 2) {
        return HERBST_NEED_MORE_ARGS;
    }
    SettingsPair* pair = settings_find(argv[1]);
    if (!pair) {
        g_string_append_printf(output,
            "%s: Setting \"%s\" not found\n", argv[0], argv[1]);
        return HERBST_SETTING_NOT_FOUND;
    }
    if (pair->type == HS_Int) {
        g_string_append_printf(output, "%d", pair->value.i);
    } else {
        g_string_append(output, pair->value.s);
    }
    return 0;
}

canonical_original_code:
int settings_get(int argc, char **argv, struct _GString *output) {
    if (argc < 2) {
        return HERBST_NEED_MORE_ARGS;
    }
    struct SettingsPair *pair = settings_find(argv[1]);
    if (!pair) {
        g_string_append_printf(output,
            "%s: Setting \"%s\" not found\n", argv[0], argv[1]);
        return HERBST_SETTING_NOT_FOUND;
    }
    if (pair->type == HS_Int) {
        g_string_append_printf(output, "%d", pair->value.i);
    } else {
        g_string_append(output, pair->value.s);
    }
    return 0;
}

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


decompiled_code:
__int64 __fastcall settings_toggle(int a1, const char **a2, __int64 a3)
{
unsigned int v3; // er12
__int64 v5; // rax
int v6; // edx
void (*v7)(void); // rdx

v3 = 9;
if ( a1 <= 1 )
return v3;
v5 = settings_find((__int64)a2[1]);
if ( !v5 )
{
v3 = 4;
g_string_append_printf(a3, "%s: Setting \"%s\" not found\n", *a2, a2[1]);
return v3;
}
if ( *(_DWORD *)(v5 + 20) == 1 )
{
v6 = *(_DWORD *)(v5 + 8);
if ( v6 )
{
*(_DWORD *)(v5 + 16) = v6;
*(_DWORD *)(v5 + 8) = 0;
}
else
{
*(_DWORD *)(v5 + 8) = *(_DWORD *)(v5 + 16);
}
v7 = *(void (**)(void))(v5 + 24);
v3 = 0;
if ( v7 )
v7();
return v3;
}
g_string_append_printf(a3, "%s: Only numbers can be toggled\n", *a2);
return 3LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, const char **a2, __int64 a3)
{
unsigned int v3; // er12
__int64 v5; // rax
int v6; // edx
void (*v7)(void); // rdx

v3 = 9;
if ( a1 <= 1 )
return v3;
v5 = func3((__int64)a2[1]);
if ( !v5 )
{
v3 = 4;
g_string_append_printf(a3, "%s: Setting \"%s\" not found\n", *a2, a2[1]);
return v3;
}
if ( *(_DWORD *)(v5 + 20) == 1 )
{
v6 = *(_DWORD *)(v5 + 8);
if ( v6 )
{
*(_DWORD *)(v5 + 16) = v6;
*(_DWORD *)(v5 + 8) = 0;
}
else
{
*(_DWORD *)(v5 + 8) = *(_DWORD *)(v5 + 16);
}
v7 = *(void (**)(void))(v5 + 24);
v3 = 0;
if ( v7 )
v7();
return v3;
}
g_string_append_printf(a3, "%s: Only numbers can be toggled\n", *a2);
return 3LL;
}

original_code:
int settings_toggle(int argc, char** argv, GString* output) {
    if (argc < 2) {
        return HERBST_NEED_MORE_ARGS;
    }
    SettingsPair* pair = settings_find(argv[1]);
    if (!pair) {
        g_string_append_printf(output,
            "%s: Setting \"%s\" not found\n", argv[0], argv[1]);
        return HERBST_SETTING_NOT_FOUND;
    }
    if (pair->type == HS_Int) {
        if (pair->value.i) {
            pair->old_value_i = pair->value.i;
            pair->value.i = 0;
        } else {
            pair->value.i = pair->old_value_i;
        }
    } else {
        g_string_append_printf(output,
            "%s: Only numbers can be toggled\n", argv[0]);
        return HERBST_INVALID_ARGUMENT;
    }
    if (pair->on_change) {
        pair->on_change();
    }
    return 0;
}

canonical_original_code:
int settings_toggle(int argc, char **argv, struct _GString *output) {
    if (argc < 2) {
        return HERBST_NEED_MORE_ARGS;
    }
    struct SettingsPair *pair = settings_find(argv[1]);
    if (!pair) {
        g_string_append_printf(output,
            "%s: Setting \"%s\" not found\n", argv[0], argv[1]);
        return HERBST_SETTING_NOT_FOUND;
    }
    if (pair->type == HS_Int) {
        if (pair->value.i) {
            pair->old_value_i = pair->value.i;
            pair->value.i = 0;
        } else {
            pair->value.i = pair->old_value_i;
        }
    } else {
        g_string_append_printf(output,
            "%s: Only numbers can be toggled\n", argv[0]);
        return HERBST_INVALID_ARGUMENT;
    }
    if (pair->on_change) {
        pair->on_change();
    }
    return 0;
}


decompiled_code:
__int64 __fastcall settings_cycle_value(int a1, const char **a2, __int64 a3)
{
unsigned int v3; // er15
const char *v4; // r13
const char *v5; // r14
__int64 v7; // rax
__int64 v8; // r15
const char **v9; // rbx
unsigned __int64 v10; // rbp
__int64 v11; // rax

v3 = 9;
if ( a1 > 2 )
{
v4 = a2[1];
v5 = *a2;
v7 = settings_find((__int64)v4);
v8 = v7;
if ( v7 )
{
v9 = a2 + 2;
v10 = a1 - 2;
v11 = table_find(a2 + 2, 8LL, v10, 0LL, memberequals_settingspair, v7);
if ( v11 )
v9 += (((unsigned __int64)(v11 - (_QWORD)v9) >> 3) + 1) % v10;
v3 = settings_set(v8, *v9);
if ( v3 == 3 )
g_string_append_printf(a3, "%s: Invalid value for setting \"%s\"\n", v5, v4);
}
else
{
v3 = 4;
g_string_append_printf(a3, "%s: Setting \"%s\" not found\n", *a2, a2[1]);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, const char **a2, __int64 a3)
{
unsigned int v3; // er15
const char *v4; // r13
const char *v5; // r14
__int64 v7; // rax
__int64 v8; // r15
const char **v9; // rbx
unsigned __int64 v10; // rbp
__int64 v11; // rax

v3 = 9;
if ( a1 > 2 )
{
v4 = a2[1];
v5 = *a2;
v7 = func3((__int64)v4);
v8 = v7;
if ( v7 )
{
v9 = a2 + 2;
v10 = a1 - 2;
v11 = table_find(a2 + 2, 8LL, v10, 0LL, memberequals_settingspair, v7);
if ( v11 )
v9 += (((unsigned __int64)(v11 - (_QWORD)v9) >> 3) + 1) % v10;
v3 = func5(v8, *v9);
if ( v3 == 3 )
g_string_append_printf(a3, "%s: Invalid value for setting \"%s\"\n", v5, v4);
}
else
{
v3 = 4;
g_string_append_printf(a3, "%s: Setting \"%s\" not found\n", *a2, a2[1]);
}
}
return v3;
}

original_code:
int settings_cycle_value(int argc, char** argv, GString* output) {
    if (argc < 3) {
        return HERBST_NEED_MORE_ARGS;
    }
    char* cmd_name = argv[0];
    char* setting_name = argv[1];
    SettingsPair* pair = settings_find(argv[1]);
    if (!pair) {
        g_string_append_printf(output,
            "%s: Setting \"%s\" not found\n", argv[0], argv[1]);
        return HERBST_SETTING_NOT_FOUND;
    }
    (void)(--(argc) && ++(argv));
    (void)(--(argc) && ++(argv));
    char** pcurrent = table_find(argv, sizeof(*argv), argc, 0,
                                 memberequals_settingspair, pair);
    int i = pcurrent ? (((((char*)(pcurrent) - (char*)(argv)) / (sizeof (*argv))) + 1) % argc) : 0;
    int ret = settings_set(pair, argv[i]);
    if (ret == HERBST_INVALID_ARGUMENT) {
        g_string_append_printf(output,
            "%s: Invalid value for setting \"%s\"\n", cmd_name, setting_name);
    }
    return ret;
}

canonical_original_code:
int settings_cycle_value(int argc, char **argv, struct _GString *output) {
    if (argc < 3) {
        return HERBST_NEED_MORE_ARGS;
    }
    char *cmd_name = argv[0];
    char *setting_name = argv[1];
    struct SettingsPair *pair = settings_find(argv[1]);
    if (!pair) {
        g_string_append_printf(output,
            "%s: Setting \"%s\" not found\n", argv[0], argv[1]);
        return HERBST_SETTING_NOT_FOUND;
    }
    (void)(--(argc) && ++(argv));
    (void)(--(argc) && ++(argv));
    char **pcurrent = table_find(argv, sizeof(*argv), argc, 0,
                                 memberequals_settingspair, pair);
    int i = pcurrent ? (((((char*)(pcurrent) - (char*)(argv)) / (sizeof (*argv))) + 1) % argc) : 0;
    int ret = settings_set(pair, argv[i]);
    if (ret == HERBST_INVALID_ARGUMENT) {
        g_string_append_printf(output,
            "%s: Invalid value for setting \"%s\"\n", cmd_name, setting_name);
    }
    return ret;
}

variable_types:
pcurrent
char **


decompiled_code:
__int64 hook_init()
{
XClassHint *v0; // rax
Window v1; // rsi
Display *v2; // rdi
XClassHint *v3; // rbp
Atom v4; // rax
__int64 v6; // [rsp-8h] [rbp-18h]

g_event_window = XCreateSimpleWindow(g_display, g_root, 42, 42, 0x2Au, 0x2Au, 0, 0LL, 0LL);
v0 = XAllocClassHint();
v1 = g_event_window;
v2 = g_display;
v0->res_name = "HERBST_HOOK_CLASS";
v3 = v0;
v0->res_class = "HERBST_HOOK_CLASS";
XSetClassHint(v2, v1, v0);
XFree(v3);
XSelectInput(g_display, g_event_window, 0LL);
v4 = XInternAtom(g_display, "__HERBST_HOOK_WIN_ID", 0);
XChangeProperty(g_display, g_root, v4, 4uLL, 32, 0, (const unsigned __int8 *)&g_event_window, 1);
return v6;
}

canonical_decompiled_code:
__int64 func0()
{
XClassHint *v0; // rax
Window v1; // rsi
Display *v2; // rdi
XClassHint *v3; // rbp
Atom v4; // rax
__int64 v6; // [rsp-8h] [rbp-18h]

g_event_window = XCreateSimpleWindow(g_display, g_root, 42, 42, 0x2Au, 0x2Au, 0, 0LL, 0LL);
v0 = XAllocClassHint();
v1 = g_event_window;
v2 = g_display;
v0->res_name = "HERBST_HOOK_CLASS";
v3 = v0;
v0->res_class = "HERBST_HOOK_CLASS";
XSetClassHint(v2, v1, v0);
XFree(v3);
XSelectInput(g_display, g_event_window, 0LL);
v4 = XInternAtom(g_display, "__HERBST_HOOK_WIN_ID", 0);
XChangeProperty(g_display, g_root, v4, 4uLL, 32, 0, (const unsigned __int8 *)&g_event_window, 1);
return v6;
}

original_code:
void hook_init() {
    g_event_window = XCreateSimpleWindow(g_display, g_root, 42, 42, 42, 42, 0, 0, 0);
    XClassHint *hint = XAllocClassHint();
    hint->res_name = "HERBST_HOOK_CLASS";
    hint->res_class = "HERBST_HOOK_CLASS";
    XSetClassHint(g_display, g_event_window, hint);
    XFree(hint);
    XSelectInput(g_display, g_event_window, 0l);
    XChangeProperty(g_display, g_root, XInternAtom(g_display, ("__HERBST_HOOK_WIN_ID"), 0),
        ((Atom) 4), 32, 0, (unsigned char*)&g_event_window, 1);
}

canonical_original_code:
void hook_init() {
    g_event_window = XCreateSimpleWindow(g_display, g_root, 42, 42, 42, 42, 0, 0, 0);
    struct XClassHint *hint = XAllocClassHint();
    hint->res_name = "HERBST_HOOK_CLASS";
    hint->res_class = "HERBST_HOOK_CLASS";
    XSetClassHint(g_display, g_event_window, hint);
    XFree(hint);
    XSelectInput(g_display, g_event_window, 0l);
    XChangeProperty(g_display, g_root, XInternAtom(g_display, ("__HERBST_HOOK_WIN_ID"), 0),
        ((unsigned long) 4), 32, 0, (unsigned char *)&g_event_window, 1);
}

variable_types: struct XClassHint { char *res_name; char *res_class; } *


decompiled_code:
int hook_destroy()
{
Atom v0; // rax

v0 = XInternAtom(g_display, "__HERBST_HOOK_WIN_ID", 0);
XDeleteProperty(g_display, g_root, v0);
return XDestroyWindow(g_display, g_event_window);
}

canonical_decompiled_code:
int func1()
{
Atom v0; // rax

v0 = XInternAtom(g_display, "__HERBST_HOOK_WIN_ID", 0);
XDeleteProperty(g_display, g_root, v0);
return XDestroyWindow(g_display, g_event_window);
}

original_code:
void hook_destroy() {
    XDeleteProperty(g_display, g_root, XInternAtom(g_display, ("__HERBST_HOOK_WIN_ID"), 0));
    XDestroyWindow(g_display, g_event_window);
}


decompiled_code:
void __fastcall hook_emit(int count, char **list)
{
Atom v2; // r13
XTextProperty v3; // [rsp+0h] [rbp-38h] BYREF

if ( count > 0 )
{
snprintf(atom_name_3, 0x3E8uLL, "__HERBST_HOOK_ARGUMENTS_%d", (unsigned int)last_property_number_4);
v2 = XInternAtom(g_display, atom_name_3, 0);
Xutf8TextListToTextProperty(g_display, list, count, XUTF8StringStyle, &v3);
XSetTextProperty(g_display, g_event_window, &v3, v2);
XFree(v3.value);
last_property_number_4 = (last_property_number_4 + 1) % 10;
}
}

canonical_decompiled_code:
void __fastcall func2(int count, char **list)
{
Atom v2; // r13
XTextProperty v3; // [rsp+0h] [rbp-38h] BYREF

if ( count > 0 )
{
snprintf(atom_name_3, 0x3E8uLL, "__HERBST_HOOK_ARGUMENTS_%d", (unsigned int)last_property_number_4);
v2 = XInternAtom(g_display, atom_name_3, 0);
Xutf8TextListToTextProperty(g_display, list, count, XUTF8StringStyle, &v3);
XSetTextProperty(g_display, g_event_window, &v3, v2);
XFree(v3.value);
last_property_number_4 = (last_property_number_4 + 1) % 10;
}
}

original_code:
void hook_emit(int argc, char** argv) {
    static int last_property_number = 0;
    if (argc <= 0) {
        return;
    }
    XTextProperty text_prop;
    static char atom_name[1000];
    snprintf(atom_name, 1000, "__HERBST_HOOK_ARGUMENTS_%d", last_property_number);
    Atom atom = XInternAtom(g_display, (atom_name), 0);
    Xutf8TextListToTextProperty(g_display, argv, argc, XUTF8StringStyle, &text_prop);
    XSetTextProperty(g_display, g_event_window, &text_prop, atom);
    XFree(text_prop.value);
    last_property_number += 1;
    last_property_number %= 10;
}

canonical_original_code:
void hook_emit(int argc, char **argv) {
    static int last_property_number = 0;
    if (argc <= 0) {
        return;
    }
    struct XTextProperty text_prop;
    static char atom_name[1000];
    snprintf(atom_name, 1000, "__HERBST_HOOK_ARGUMENTS_%d", last_property_number);
    unsigned long atom = XInternAtom(g_display, (atom_name), 0);
    Xutf8TextListToTextProperty(g_display, argv, argc, XUTF8StringStyle, &text_prop);
    XSetTextProperty(g_display, g_event_window, &text_prop, atom);
    XFree(text_prop.value);
    last_property_number += 1;
    last_property_number %= 10;
}

variable_types: struct XTextProperty { unsigned char *value; unsigned long encoding; int format; unsigned long nitems; }

variable_types:
atom
unsigned long


decompiled_code:
void ipc_init()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void ipc_init() {
}

canonical_original_code:
void ipc_init() {
}


decompiled_code:
void ipc_destroy()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void ipc_destroy() {
}

canonical_original_code:
void ipc_destroy() {
}


decompiled_code:
__int64 __fastcall ipc_handle_connection(Window a1)
{
Atom v1; // rax
__int64 result; // rax
const char **v3; // r12
Atom v4; // rax
const char *v5; // r14
int v6; // ebx
Atom v7; // r13
Atom v8; // rax
Atom v9; // rax
unsigned int v10; // [rsp+0h] [rbp-58h] BYREF
unsigned __int8 v11[4]; // [rsp+4h] [rbp-54h] BYREF
char **list_return; // [rsp+8h] [rbp-50h] BYREF
XTextProperty text_prop; // [rsp+10h] [rbp-48h] BYREF

v1 = XInternAtom(g_display, "_HERBST_IPC_ARGS", 0);
if ( !XGetTextProperty(g_display, a1, &text_prop, v1) )
return 0LL;
if ( Xutf8TextPropertyToTextList(g_display, &text_prop, &list_return, (int *)&v10) )
{
fprintf(
stderr,
"herbstluftwm: Warning: could not parse the %s atom of herbstclient window %d to utf8 list\n",
"_HERBST_IPC_ARGS",
(unsigned int)a1);
XFree(text_prop.value);
result = 0LL;
}
else
{
v3 = (const char **)g_string_new(&unk_2C9);
*(_DWORD *)v11 = call_command(v10, list_return, v3);
v4 = XInternAtom(g_display, "_HERBST_IPC_ARGS", 0);
XDeleteProperty(g_display, a1, v4);
v5 = *v3;
v6 = strlen(*v3);
v7 = XInternAtom(g_display, "UTF8_STRING", 0);
v8 = XInternAtom(g_display, "_HERBST_IPC_OUTPUT", 0);
XChangeProperty(g_display, a1, v8, v7, 8, 0, (const unsigned __int8 *)v5, v6 + 1);
v9 = XInternAtom(g_display, "_HERBST_IPC_EXIT_STATUS", 0);
XChangeProperty(g_display, a1, v9, 4uLL, 32, 0, v11, 1);
XFreeStringList(list_return);
XFree(text_prop.value);
g_string_free(v3, 1LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(Window a1)
{
Atom v1; // rax
__int64 result; // rax
const char **v3; // r12
Atom v4; // rax
const char *v5; // r14
int v6; // ebx
Atom v7; // r13
Atom v8; // rax
Atom v9; // rax
unsigned int v10; // [rsp+0h] [rbp-58h] BYREF
unsigned __int8 v11[4]; // [rsp+4h] [rbp-54h] BYREF
char **list_return; // [rsp+8h] [rbp-50h] BYREF
XTextProperty text_prop; // [rsp+10h] [rbp-48h] BYREF

v1 = XInternAtom(g_display, "_HERBST_IPC_ARGS", 0);
if ( !XGetTextProperty(g_display, a1, &text_prop, v1) )
return 0LL;
if ( Xutf8TextPropertyToTextList(g_display, &text_prop, &list_return, (int *)&v10) )
{
fprintf(
stderr,
"herbstluftwm: Warning: could not parse the %s atom of herbstclient window %d to utf8 list\n",
"_HERBST_IPC_ARGS",
(unsigned int)a1);
XFree(text_prop.value);
result = 0LL;
}
else
{
v3 = (const char **)g_string_new(&unk_2C9);
*(_DWORD *)v11 = call_command(v10, list_return, v3);
v4 = XInternAtom(g_display, "_HERBST_IPC_ARGS", 0);
XDeleteProperty(g_display, a1, v4);
v5 = *v3;
v6 = strlen(*v3);
v7 = XInternAtom(g_display, "UTF8_STRING", 0);
v8 = XInternAtom(g_display, "_HERBST_IPC_OUTPUT", 0);
XChangeProperty(g_display, a1, v8, v7, 8, 0, (const unsigned __int8 *)v5, v6 + 1);
v9 = XInternAtom(g_display, "_HERBST_IPC_EXIT_STATUS", 0);
XChangeProperty(g_display, a1, v9, 4uLL, 32, 0, v11, 1);
XFreeStringList(list_return);
XFree(text_prop.value);
g_string_free(v3, 1LL);
result = 1LL;
}
return result;
}

original_code:
_Bool ipc_handle_connection(Window win) {
    XTextProperty text_prop;
    if (!XGetTextProperty(g_display, win, &text_prop, XInternAtom(g_display, ("_HERBST_IPC_ARGS"), 0))) {
        return 0;
    }
    char** list_return;
    int count;
    if (0 != Xutf8TextPropertyToTextList(g_display, &text_prop, &list_return, &count)) {
        fprintf(stderr, "herbstluftwm: Warning: could not parse the %s atom of herbstclient "
                        "window %d to utf8 list\n",
                        "_HERBST_IPC_ARGS", (unsigned int)win);
        XFree(text_prop.value);
        return 0;
    }
    GString* output = g_string_new("");
    int status = call_command(count, list_return, output);
    XDeleteProperty(g_display, win, XInternAtom(g_display, ("_HERBST_IPC_ARGS"), 0));
    XChangeProperty(g_display, win, XInternAtom(g_display, ("_HERBST_IPC_OUTPUT"), 0),
        XInternAtom(g_display, ("UTF8_STRING"), 0), 8, 0,
        (unsigned char*)output->str, 1+strlen(output->str));
    XChangeProperty(g_display, win, XInternAtom(g_display, ("_HERBST_IPC_EXIT_STATUS"), 0),
        ((Atom) 4), 32, 0, (unsigned char*)&(status), 1);
    XFreeStringList(list_return);
    XFree(text_prop.value);
    g_string_free(output, 1);
    return 1;
}

canonical_original_code:
_Bool ipc_handle_connection(unsigned long win) {
    struct XTextProperty text_prop;
    if (!XGetTextProperty(g_display, win, &text_prop, XInternAtom(g_display, ("_HERBST_IPC_ARGS"), 0))) {
        return 0;
    }
    char **list_return;
    int count;
    if (0 != Xutf8TextPropertyToTextList(g_display, &text_prop, &list_return, &count)) {
        fprintf(stderr, "herbstluftwm: Warning: could not parse the %s atom of herbstclient "
                        "window %d to utf8 list\n",
                        "_HERBST_IPC_ARGS", (unsigned int)win);
        XFree(text_prop.value);
        return 0;
    }
    struct _GString *output = g_string_new("");
    int status = call_command(count, list_return, output);
    XDeleteProperty(g_display, win, XInternAtom(g_display, ("_HERBST_IPC_ARGS"), 0));
    XChangeProperty(g_display, win, XInternAtom(g_display, ("_HERBST_IPC_OUTPUT"), 0),
        XInternAtom(g_display, ("UTF8_STRING"), 0), 8, 0,
        (unsigned char *)output->str, 1+strlen(output->str));
    XChangeProperty(g_display, win, XInternAtom(g_display, ("_HERBST_IPC_EXIT_STATUS"), 0),
        ((unsigned long) 4), 32, 0, (unsigned char *)&(status), 1);
    XFreeStringList(list_return);
    XFree(text_prop.value);
    g_string_free(output, 1);
    return 1;
}

variable_types:
win
unsigned long

variable_types: count int

variable_types: status int

user_defined_types: struct XTextProperty { unsigned char *value; unsigned long encoding; int format; unsigned long nitems; }


decompiled_code:
__int64 __fastcall ipc_add_connection(Window a1)
{
XSelectInput(g_display, a1, 0x400000LL);
return ipc_handle_connection(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(Window a1)
{
XSelectInput(g_display, a1, 0x400000LL);
return func2(a1);
}

original_code:
void ipc_add_connection(Window window) {
    XSelectInput(g_display, window, (1L<<22));
    ipc_handle_connection(window);
}

canonical_original_code:
void ipc_add_connection(unsigned long window) {
    XSelectInput(g_display, window, (1L<<22));
    ipc_handle_connection(window);
}

variable_types:
window
unsigned long


decompiled_code:
__int64 __fastcall is_ipc_connectable(Window a1)
{
unsigned int v1; // er12
XClassHint v3; // [rsp+0h] [rbp-18h] BYREF

v1 = 0;
if ( XGetClassHint(g_display, a1, &v3) )
{
if ( v3.res_name )
{
if ( v3.res_class )
LOBYTE(v1) = strcmp(v3.res_class, "HERBST_IPC_CLASS") == 0;
XFree(v3.res_name);
}
if ( v3.res_class )
XFree(v3.res_class);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(Window a1)
{
unsigned int v1; // er12
XClassHint v3; // [rsp+0h] [rbp-18h] BYREF

v1 = 0;
if ( XGetClassHint(g_display, a1, &v3) )
{
if ( v3.res_name )
{
if ( v3.res_class )
LOBYTE(v1) = strcmp(v3.res_class, "HERBST_IPC_CLASS") == 0;
XFree(v3.res_name);
}
if ( v3.res_class )
XFree(v3.res_class);
}
return v1;
}

original_code:
_Bool is_ipc_connectable(Window window) {
    XClassHint hint;
    if (0 == XGetClassHint(g_display, window, &hint)) {
        return 0;
    }
    _Bool is_ipc = 0;
    if (hint.res_name && hint.res_class &&
        !strcmp(hint.res_class, "HERBST_IPC_CLASS")) {
        is_ipc = 1;
    }
    if (hint.res_name) XFree(hint.res_name);
    if (hint.res_class) XFree(hint.res_class);
    return is_ipc;
}

canonical_original_code:
_Bool is_ipc_connectable(unsigned long window) {
    struct XClassHint hint;
    if (0 == XGetClassHint(g_display, window, &hint)) {
        return 0;
    }
    _Bool is_ipc = 0;
    if (hint.res_name && hint.res_class &&
        !strcmp(hint.res_class, "HERBST_IPC_CLASS")) {
        is_ipc = 1;
    }
    if (hint.res_name) XFree(hint.res_name);
    if (hint.res_class) XFree(hint.res_class);
    return is_ipc;
}

variable_types: struct XClassHint { char *res_name; char *res_class; }


decompiled_code:
__int64 __fastcall keysym_equals(__int64 a1, __int64 a2)
{
unsigned int v2; // er8

v2 = -1;
if ( (~(numlockmask | 2) & (*(_DWORD *)(a2 + 8) ^ *(_DWORD *)(a1 + 8))) == 0 )
v2 = -(*(_QWORD *)a1 != *(_QWORD *)a2);
return v2;
}

original_code:
static gint keysym_equals(const KeyBinding* a, const KeyBinding* b) {
    _Bool equal = ((a->modifiers & ~(numlockmask|(1<<1))) == (b->modifiers & ~(numlockmask|(1<<1))));
    equal = equal && (a->keysym == b->keysym);
    return equal ? 0 : -1;
}

canonical_original_code:
static int keysym_equals(struct KeyBinding *a, struct KeyBinding *b) {
    _Bool equal = ((a->modifiers & ~(numlockmask|(1<<1))) == (b->modifiers & ~(numlockmask|(1<<1))));
    equal = equal && (a->keysym == b->keysym);
    return equal ? 0 : -1;
}

variable_types: struct KeyBinding { unsigned long keysym; unsigned int modifiers; int cmd_argc; char **cmd_argv; } *

variable_types:
b
struct KeyBinding *


decompiled_code:
__int64 __fastcall keybinding_free(__int64 a1)
{
argv_free(*(unsigned int *)(a1 + 12), *(_QWORD *)(a1 + 16));
return g_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
argv_free(*(unsigned int *)(a1 + 12), *(_QWORD *)(a1 + 16));
return g_free(a1);
}

original_code:
void keybinding_free(KeyBinding* binding) {
    argv_free(binding->cmd_argc, binding->cmd_argv);
    g_free(binding);
}

canonical_original_code:
void keybinding_free(struct KeyBinding *binding) {
    argv_free(binding->cmd_argc, binding->cmd_argv);
    g_free(binding);
}

user_defined_types: struct KeyBinding { unsigned long keysym; unsigned int modifiers; int cmd_argc; char **cmd_argv; }


decompiled_code:
KeyCode __fastcall grab_keybind(__int64 a1)
{
KeySym v1; // rsi
KeyCode result; // al
int v3; // ebp
char *v4; // rbx
int i; // edx
KeyCode v6; // [rsp-10h] [rbp-48h]
_DWORD v7[4]; // [rsp+0h] [rbp-38h] BYREF
char v8; // [rsp+10h] [rbp-28h] BYREF

v1 = *(_QWORD *)a1;
v7[1] = 2;
v7[2] = numlockmask;
v7[3] = numlockmask | 2;
result = XKeysymToKeycode(g_display, v1);
if ( result )
{
v3 = result;
v4 = (char *)v7;
for ( i = 0; ; i = *(_DWORD *)v4 )
{
v4 += 4;
XGrabKey(g_display, v3, *(_DWORD *)(a1 + 8) | i, g_root, 1, 1, 1);
result = v6;
if ( v4 == &v8 )
break;
}
}
return result;
}

canonical_decompiled_code:
KeyCode __fastcall func2(__int64 a1)
{
KeySym v1; // rsi
KeyCode result; // al
int v3; // ebp
char *v4; // rbx
int i; // edx
KeyCode v6; // [rsp-10h] [rbp-48h]
_DWORD v7[4]; // [rsp+0h] [rbp-38h] BYREF
char v8; // [rsp+10h] [rbp-28h] BYREF

v1 = *(_QWORD *)a1;
v7[1] = 2;
v7[2] = numlockmask;
v7[3] = numlockmask | 2;
result = XKeysymToKeycode(g_display, v1);
if ( result )
{
v3 = result;
v4 = (char *)v7;
for ( i = 0; ; i = *(_DWORD *)v4 )
{
v4 += 4;
XGrabKey(g_display, v3, *(_DWORD *)(a1 + 8) | i, g_root, 1, 1, 1);
result = v6;
if ( v4 == &v8 )
break;
}
}
return result;
}

original_code:
void grab_keybind(KeyBinding* binding, void* useless_pointer) {
    unsigned int modifiers[] = { 0, (1<<1), numlockmask, numlockmask|(1<<1) };
    KeyCode keycode = XKeysymToKeycode(g_display, binding->keysym);
    if (!keycode) {
        return;
    }
    for (int i = 0; i < (sizeof(modifiers)/sizeof(*modifiers)); i++) {
        XGrabKey(g_display, keycode, modifiers[i]|binding->modifiers, g_root,
                 1, 1, 1);
    }
}

canonical_original_code:
void grab_keybind(struct KeyBinding *binding, void *useless_pointer) {
    unsigned int modifiers[] = { 0, (1<<1), numlockmask, numlockmask|(1<<1) };
    unsigned char keycode = XKeysymToKeycode(g_display, binding->keysym);
    if (!keycode) {
        return;
    }
    for (int i = 0; i < (sizeof(modifiers)/sizeof(*modifiers)); i++) {
        XGrabKey(g_display, keycode, modifiers[i]|binding->modifiers, g_root,
                 1, 1, 1);
    }
}

variable_types:
modifiers
unsigned int []

variable_types:
keycode
unsigned char

variable_types: i int


canonical_decompiled_code:
int *func4()
{
return &numlockmask;
}

original_code:
unsigned int* get_numlockmask_ptr() {
    return &numlockmask;
}

canonical_original_code:
unsigned int *get_numlockmask_ptr() {
    return &numlockmask;
}

return_type: unsigned int *


decompiled_code:
__int64 __fastcall modifiername2mask(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // er8

v1 = table_find(&g_modifier_names, 16LL, 10LL, 0LL, &memberequals_string, a1);
v2 = 0;
if ( v1 )
v2 = *(_DWORD *)(v1 + 8);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // er8

v1 = table_find(&g_modifier_names, 16LL, 10LL, 0LL, &memberequals_string, a1);
v2 = 0;
if ( v1 )
v2 = *(_DWORD *)(v1 + 8);
return v2;
}

original_code:
unsigned int modifiername2mask(const char* name) {
    Name2Modifier* elem;
    elem = ((Name2Modifier*) table_find((g_modifier_names), sizeof(g_modifier_names[0]), (sizeof((g_modifier_names))/sizeof(*(g_modifier_names))), __builtin_offsetof (Name2Modifier, name), memberequals_string, ((char*)name)));
    return elem ? elem->mask : 0;
}

canonical_original_code:
unsigned int modifiername2mask(char *name) {
    struct Name2Modifier *elem;
    elem = ((struct Name2Modifier *) table_find((g_modifier_names), sizeof(g_modifier_names[0]), (sizeof((g_modifier_names))/sizeof(*(g_modifier_names))), __builtin_offsetof (Name2Modifier, name), memberequals_string, ((char *)name)));
    return elem ? elem->mask : 0;
}

variable_types:
name
char *

variable_types: struct Name2Modifier { char *name; unsigned int mask; } *

return_type: unsigned int